From 005b02cbe3546deb6caa32fc6c92a283256f207f Mon Sep 17 00:00:00 2001 From: Martin Willi Date: Wed, 7 Dec 2011 11:29:13 +0100 Subject: [PATCH] Create a dummy pthread key for value "0", as some buggy PKCS#11 libraries mangle it --- src/libstrongswan/threading/thread.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/libstrongswan/threading/thread.c b/src/libstrongswan/threading/thread.c index 5b6f0d2ce..d3da1e379 100644 --- a/src/libstrongswan/threading/thread.c +++ b/src/libstrongswan/threading/thread.c @@ -413,6 +413,12 @@ void thread_exit(void *val) pthread_exit(val); } +/** + * A dummy thread value that reserved pthread_key_t value "0". A buggy PKCS#11 + * library mangles this key, without owning it, so we allocate it for them. + */ +static thread_value_t *dummy1; + /** * Described in header. */ @@ -420,6 +426,8 @@ void threads_init() { private_thread_t *main_thread = thread_create_internal(); + dummy1 = thread_value_create(NULL); + main_thread->id = 0; main_thread->thread_id = pthread_self(); current_thread = thread_value_create(NULL); @@ -443,6 +451,8 @@ void threads_deinit() { private_thread_t *main_thread = (private_thread_t*)thread_current(); + dummy1->destroy(dummy1); + main_thread->mutex->lock(main_thread->mutex); thread_destroy(main_thread); current_thread->destroy(current_thread);