* cygthread.cc (cygthread::stub): Revert previous change and again subsume
cygthread::stub2. Just return from function now since ExitThread is guaranteed by automatic _threadinfo wrapper. Define as per ThreadProc convention. (cygthread::stub2): Remove. (cygthread::simplestub): Perform similar operations to cygthread::stub. (cygthread::simplestub2): Remove. * cygthread.h (cygthread::stub): Declare as per ThreadProc convention. (cygthread::stub2): Remove declaration. (cygthread::simplestub): Declare as per ThreadProc convention. (cygthread::simplestub2): Remove declaration. * cygtls.h (_threadinfo::call): Define first argument as per ThreadProc convention. (_threadinfo::call2): Ditto. (_tlsbase): Define as char * pointer. (_tlstop): New definition. (_main_tls): Define here. * dcrt0.cc (alloc_stack): Revert previous change which called init_thread since information would be overwritten by fork later anyway. (dll_crt0_1): Use _tlsbase and _tlstop for setting stack bottom, top. * exceptions.cc: Move _main_tls declaration to cygtls.h. (_threadinfo::call): Define first argument as per ThreadProc convention. (_threadinfo::call2): Call ExitThread with thread function return value. (_threadinfo::init_thread): Don't initialize cygtls to zero if input arg is NULL. * fork.cc (fork_child): Reset _main_tls here. Reinitialize parts of _my_tls after copying data from parent. * init.cc (threadfunc_fe): New function. Front-end for all threads created in cygwin processes. (munge_threadfunc): New function. (dll_entry): Call munge_threadfunc to force the call of a thread wrapper. * thread.cc (pthread::thread_init_wrapper): Perform similar operations to cygthread::stub. (pthread::thread_init_wrapper2): Remove. * thread.h (pthread::thread_init_wrapper): Declare as per ThreadProc convention. (pthread::thread_init_wrapper2): Remove declaration. * window.cc (Winmain): Just return from function now since ExitThread is guaranteed by automatic _threadinfo wrapper.
This commit is contained in:
@ -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;
|
||||
|
Reference in New Issue
Block a user