summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin/init.cc
diff options
context:
space:
mode:
Diffstat (limited to 'winsup/cygwin/init.cc')
-rw-r--r--winsup/cygwin/init.cc35
1 files changed, 32 insertions, 3 deletions
diff --git a/winsup/cygwin/init.cc b/winsup/cygwin/init.cc
index dc2b1a717..94453f602 100644
--- a/winsup/cygwin/init.cc
+++ b/winsup/cygwin/init.cc
@@ -12,12 +12,41 @@ details. */
#include <stdlib.h>
#include "thread.h"
#include "perprocess.h"
+#include "cygthread.h"
#include "cygtls.h"
int NO_COPY dynamically_loaded;
-extern "C" int
-WINAPI dll_entry (HANDLE h, DWORD reason, void *static_load)
+static void WINAPI
+threadfunc_fe (VOID *arg)
+{
+ _threadinfo::call ((DWORD (*) (void *, void *)) (((char **) _tlsbase)[-1]), arg);
+}
+
+static void
+munge_threadfunc (HANDLE cygwin_hmodule)
+{
+ char **ebp = (char **) __builtin_frame_address (0);
+ static unsigned threadfunc_ix;
+ if (!threadfunc_ix)
+ {
+ for (char **peb = ebp; peb < (char **) _tlsbase; peb++)
+ if (*peb == (char *) cygthread::stub)
+ {
+ threadfunc_ix = peb - ebp;
+ goto foundit;
+ }
+ return;
+ }
+
+foundit:
+ char *threadfunc = ebp[threadfunc_ix];
+ ebp[threadfunc_ix] = (char *) threadfunc_fe;
+ ((char **) _tlsbase)[-1] = threadfunc;
+}
+
+extern "C" int WINAPI
+dll_entry (HANDLE h, DWORD reason, void *static_load)
{
switch (reason)
{
@@ -28,9 +57,9 @@ WINAPI dll_entry (HANDLE h, DWORD reason, void *static_load)
case DLL_PROCESS_DETACH:
break;
case DLL_THREAD_ATTACH:
- _my_tls.stackptr = _my_tls.stack;
if (MT_INTERFACE->reent_key.set (&MT_INTERFACE->reents))
api_fatal ("thread initialization failed");
+ munge_threadfunc (h);
break;
}
return 1;