Callbacks defined via PIMAGE_TLS_CALLBACK are not called on Win9x systems,
and also they are not called on all pre-Vista systems when DLL library is
loaded at runtime by LoadLibrary() call.
---
 mingw-w64-libraries/winpthreads/src/thread.c | 21 ++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/mingw-w64-libraries/winpthreads/src/thread.c 
b/mingw-w64-libraries/winpthreads/src/thread.c
index ceac61d864ef..6075b8aef348 100644
--- a/mingw-w64-libraries/winpthreads/src/thread.c
+++ b/mingw-w64-libraries/winpthreads/src/thread.c
@@ -526,6 +526,25 @@ __dyn_tls_pthread (HANDLE hDllHandle, DWORD dwReason, 
LPVOID lpreserved)
     }
 }
 
+#ifdef DLL_EXPORT
+
+/* For DLL builds register TLS hook via DllMain(). Entrypoint DllMain()
+ * works on all Windows versions (Win32s, Win9x, WinNT) for all cases.
+ *
+ * Callbacks defined via PIMAGE_TLS_CALLBACK are not called on Win9x
+ * systems, and also they are not called on pre-Vista systems when
+ * DLL library is loaded at runtime by LoadLibrary() call.
+ */
+
+BOOL WINAPI
+DllMain (HANDLE hDllHandle, DWORD dwReason, LPVOID lpReserved)
+{
+  __dyn_tls_pthread (hDllHandle, dwReason, lpReserved);
+  return TRUE;
+}
+
+#else
+
 /* TLS-runtime section variable.  */
 
 /* Force a reference to _tls_used to make the linker create the TLS
@@ -565,6 +584,8 @@ static __attribute__((used))
 WINPTHREADS_ATTRIBUTE((WINPTHREADS_SECTION(".CRT$XLF")))
 const PIMAGE_TLS_CALLBACK __xl_f = __dyn_tls_pthread;
 
+#endif
+
 /* Internal collect-once structure.  */
 typedef struct collect_once_t {
   pthread_once_t *o;
-- 
2.20.1



_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to