diff options
-rw-r--r-- | common/library.c | 3 | ||||
-rw-r--r-- | common/library.h | 3 | ||||
-rw-r--r-- | p11-kit/util.c | 5 | ||||
-rw-r--r-- | p11-kit/virtual-fixed.h | 3 | ||||
-rw-r--r-- | p11-kit/virtual.c | 27 |
5 files changed, 11 insertions, 30 deletions
diff --git a/common/library.c b/common/library.c index 502ea98..39a9c46 100644 --- a/common/library.c +++ b/common/library.c @@ -59,6 +59,8 @@ static p11_local * _p11_library_get_thread_local (void); p11_mutex_t p11_library_mutex; +p11_mutex_t p11_virtual_mutex; + #ifdef OS_UNIX pthread_once_t p11_library_once = PTHREAD_ONCE_INIT; #endif @@ -118,6 +120,7 @@ p11_library_init_impl (void) p11_debug_init (); p11_debug ("initializing library"); p11_mutex_init (&p11_library_mutex); + p11_mutex_init (&p11_virtual_mutex); pthread_key_create (&thread_local, free); p11_message_storage = thread_local_message; diff --git a/common/library.h b/common/library.h index f87494d..c3840f8 100644 --- a/common/library.h +++ b/common/library.h @@ -44,6 +44,9 @@ extern p11_mutex_t p11_library_mutex; +/* Used in virtual.c to maintain the global list of precompiled closures */ +extern p11_mutex_t p11_virtual_mutex; + extern unsigned int p11_forkid; #define p11_lock() p11_mutex_lock (&p11_library_mutex); diff --git a/p11-kit/util.c b/p11-kit/util.c index e51223e..325d669 100644 --- a/p11-kit/util.c +++ b/p11-kit/util.c @@ -45,7 +45,6 @@ #include "p11-kit.h" #include "private.h" #include "proxy.h" -#include "virtual-fixed.h" #include <assert.h> #include <stdarg.h> @@ -252,7 +251,6 @@ void _p11_kit_init (void) { p11_library_init_once (); - p11_virtual_fixed_init (); } #ifdef __GNUC__ @@ -262,7 +260,6 @@ void _p11_kit_fini (void) { p11_proxy_module_cleanup (); - p11_virtual_fixed_uninit (); p11_library_uninit (); } @@ -280,14 +277,12 @@ DllMain (HINSTANCE instance, switch (reason) { case DLL_PROCESS_ATTACH: p11_library_init (); - p11_virtual_fixed_init (); break; case DLL_THREAD_DETACH: p11_library_thread_cleanup (); break; case DLL_PROCESS_DETACH: p11_proxy_module_cleanup (); - p11_virtual_fixed_uninit (); p11_library_uninit (); break; default: diff --git a/p11-kit/virtual-fixed.h b/p11-kit/virtual-fixed.h index cc3b2c0..1357522 100644 --- a/p11-kit/virtual-fixed.h +++ b/p11-kit/virtual-fixed.h @@ -1138,7 +1138,4 @@ fixed ## fixed_index ## _C_GetFunctionList (CK_FUNCTION_LIST_PTR_PTR list) \ fixed ## fixed_index ## _C_WaitForSlotEvent \ } -void p11_virtual_fixed_init (void); -void p11_virtual_fixed_uninit (void); - #endif /* __P11_VIRTUAL_FIXED_H__ */ diff --git a/p11-kit/virtual.c b/p11-kit/virtual.c index b066b4b..a2853bb 100644 --- a/p11-kit/virtual.c +++ b/p11-kit/virtual.c @@ -88,7 +88,6 @@ typedef struct { int fixed_index; } Wrapper; -static p11_mutex_t fixed_mutex; static CK_FUNCTION_LIST *fixed_closures[P11_VIRTUAL_MAX_FIXED]; static Wrapper *create_fixed_wrapper (p11_virtual *virt, @@ -101,23 +100,6 @@ static void p11_virtual_unwrap_fixed (CK_FUNCTION_LIST_PTR module); -void -p11_virtual_fixed_init (void) -{ - p11_lock (); - p11_mutex_init (&fixed_mutex); - memset (fixed_closures, 0, sizeof (fixed_closures)); - p11_unlock (); -} - -void -p11_virtual_fixed_uninit (void) -{ - p11_lock (); - p11_mutex_uninit (&fixed_mutex); - p11_unlock (); -} - static CK_RV short_C_GetFunctionStatus (CK_SESSION_HANDLE handle) { @@ -2860,6 +2842,7 @@ p11_virtual_wrap (p11_virtual *virt, wrapper->destroyer = destroyer; wrapper->bound.version.major = CRYPTOKI_VERSION_MAJOR; wrapper->bound.version.minor = CRYPTOKI_VERSION_MINOR; + wrapper->fixed_index = -1; if (!init_wrapper_funcs (wrapper)) return p11_virtual_wrap_fixed (virt, destroyer); @@ -3266,7 +3249,7 @@ p11_virtual_wrap_fixed (p11_virtual *virt, CK_FUNCTION_LIST *result = NULL; size_t i; - p11_mutex_lock (&fixed_mutex); + p11_mutex_lock (&p11_virtual_mutex); for (i = 0; i < P11_VIRTUAL_MAX_FIXED; i++) { if (fixed_closures[i] == NULL) { Wrapper *wrapper; @@ -3276,7 +3259,7 @@ p11_virtual_wrap_fixed (p11_virtual *virt, break; } } - p11_mutex_unlock (&fixed_mutex); + p11_mutex_unlock (&p11_virtual_mutex); return result; } @@ -3286,14 +3269,14 @@ p11_virtual_unwrap_fixed (CK_FUNCTION_LIST_PTR module) { size_t i; - p11_mutex_lock (&fixed_mutex); + p11_mutex_lock (&p11_virtual_mutex); for (i = 0; i < P11_VIRTUAL_MAX_FIXED; i++) { if (fixed_closures[i] == module) { fixed_closures[i] = NULL; break; } } - p11_mutex_unlock (&fixed_mutex); + p11_mutex_unlock (&p11_virtual_mutex); } static bool |