From e2137c63f516ccaac3f6f2e403ba9af4d1b36624 Mon Sep 17 00:00:00 2001 From: Nicolas Williams Date: Sat, 16 Apr 2016 16:45:26 -0500 Subject: [PATCH] Fix Windows build --- lib/base/dll.c | 32 ++++---------------------------- lib/base/heimbase.h | 10 ++++++++++ lib/base/heimbasepriv.h | 4 +++- lib/krb5/dll.c | 3 +++ 4 files changed, 20 insertions(+), 29 deletions(-) diff --git a/lib/base/dll.c b/lib/base/dll.c index da8512af5..31017a011 100644 --- a/lib/base/dll.c +++ b/lib/base/dll.c @@ -85,8 +85,8 @@ static HEIMDAL_THREAD_LOCAL struct tls_values values; #define DEAD_KEY ((void *)8) -static void -del_tls_for_thread(void *unused) +void +heim_w32_service_thread_detach(void *unused) { tls_keys *key_defs; void (*dtor)(void*); @@ -124,7 +124,7 @@ pthread_once_t pt_once = PTHREAD_ONCE_INIT; static void atexit_del_tls_for_thread(void) { - del_tls_for_thread(NULL); + heim_w32_service_thread_detach(NULL); } static void @@ -134,7 +134,7 @@ create_pt_key(void) /* The main thread may not execute TLS destructors */ atexit(atexit_del_tls_for_thread); - ret = pthread_key_create(&pt_key, del_tls_for_thread); + ret = pthread_key_create(&pt_key, heim_w32_service_thread_detach); if (ret != 0) err(1, "pthread_key_create() failed"); } @@ -319,30 +319,6 @@ heim_w32_getspecific(HEIM_PRIV_thread_key key) return values.values[key]; } -#ifdef WIN32 -BOOL WINAPI DllMain(HINSTANCE hinstDLL, - DWORD fdwReason, - LPVOID lpvReserved) -{ - switch (fdwReason) { - case DLL_PROCESS_ATTACH: - return TRUE; - - case DLL_PROCESS_DETACH: - return FALSE; - - case DLL_THREAD_ATTACH: - return FALSE; - - case DLL_THREAD_DETACH: - del_tls_for_thread(NULL); - return FALSE; - } - - return FALSE; -} -#endif /* WIN32 */ - #else static char dummy; #endif /* HEIM_WIN32_TLS */ diff --git a/lib/base/heimbase.h b/lib/base/heimbase.h index 473ab440e..32f457ff8 100644 --- a/lib/base/heimbase.h +++ b/lib/base/heimbase.h @@ -418,4 +418,14 @@ void _bsearch_file_info(bsearch_file_handle bfh, size_t *page_sz, size_t *max_sz, int *blockwise); void _bsearch_file_close(bsearch_file_handle *bfh); +/* + * Thread-specific keys + */ + +int heim_w32_key_create(unsigned long *, void (*)(void *)); +int heim_w32_delete_key(unsigned long); +int heim_w32_setspecific(unsigned long, void *); +void *heim_w32_getspecific(unsigned long); +void heim_w32_service_thread_detach(void *); + #endif /* HEIM_BASE_H */ diff --git a/lib/base/heimbasepriv.h b/lib/base/heimbasepriv.h index a92a5a35d..eb155006f 100644 --- a/lib/base/heimbasepriv.h +++ b/lib/base/heimbasepriv.h @@ -33,7 +33,9 @@ * SUCH DAMAGE. */ -#if defined(HEIM_BASE_MAINTAINER) && !defined(WIN33) && defined(ENABLE_PTHREAD_SUPPORT) +#if defined(HEIM_BASE_MAINTAINER) && defined(ENABLE_PTHREAD_SUPPORT) +#define HEIM_WIN32_TLS +#elif defined(WIN32) #define HEIM_WIN32_TLS #endif diff --git a/lib/krb5/dll.c b/lib/krb5/dll.c index a47487816..80d9fa444 100644 --- a/lib/krb5/dll.c +++ b/lib/krb5/dll.c @@ -31,6 +31,8 @@ #include +extern void heim_w32_service_thread_detach(void *); + HINSTANCE _krb5_hInstance = NULL; #if NTDDI_VERSION >= NTDDI_VISTA @@ -65,6 +67,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, return FALSE; case DLL_THREAD_DETACH: + heim_w32_service_thread_detach(NULL); return FALSE; }