From d1eb7a4615a95da05f4bbc2e93e167b8afe6f0dc Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Wed, 3 Dec 2003 05:21:55 +0000 Subject: [PATCH] * cygthread.cc (cygthread::stub): Properly establish _threadinfo environment. (cygthread::stub2): New function. (cygthread::simplestub): Ditto. (cygthread::simplestub2): New function. * cygthread.h (cygthread::stub2): Declare new function. (cygthread::simplestub2): Ditto. * cygtls.h (_threadinfo::call): Declare new function. (_threadinfo::call2): Ditto. * dcrt0.cc (dll_crt0_1): Accommodate new _threadinfo::init which doesn't return pointer to tls. (_dll_crt0): Remove obsolete DECLARE_TLS_STORAGE. (dll_crt0): Ditto. * exceptions.cc (_threadinfo::call): New function. (_threadinfo::call2): Ditto. (_threadinfo::init): Don't return pointer. * thread.cc (pthread::thread_init_wrapper): Properly establish _threadinfo environment. (pthread::thread_init_wrapper2): New function. * thread.h (pthread::thread_init_wrapper): Remove noreturn attribute (pthread::thread_init_wrapper2): Declare new function. * winbase.h: Remove obsolete code. --- winsup/cygwin/ChangeLog | 25 +++++++++++++++++++++ winsup/cygwin/cygthread.cc | 19 ++++++++++++++-- winsup/cygwin/cygthread.h | 2 ++ winsup/cygwin/cygtls.h | 4 +++- winsup/cygwin/dcrt0.cc | 7 +++--- winsup/cygwin/exceptions.cc | 19 +++++++++++++--- winsup/cygwin/thread.cc | 20 ++++++++++------- winsup/cygwin/thread.h | 3 ++- winsup/cygwin/winbase.h | 45 ------------------------------------- 9 files changed, 80 insertions(+), 64 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 3d2a5dcac..5f77fb3d9 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,28 @@ +2003-12-03 Christopher Faylor + + * cygthread.cc (cygthread::stub): Properly establish _threadinfo + environment. + (cygthread::stub2): New function. + (cygthread::simplestub): Ditto. + (cygthread::simplestub2): New function. + * cygthread.h (cygthread::stub2): Declare new function. + (cygthread::simplestub2): Ditto. + * cygtls.h (_threadinfo::call): Declare new function. + (_threadinfo::call2): Ditto. + * dcrt0.cc (dll_crt0_1): Accommodate new _threadinfo::init which + doesn't return pointer to tls. + (_dll_crt0): Remove obsolete DECLARE_TLS_STORAGE. + (dll_crt0): Ditto. + * exceptions.cc (_threadinfo::call): New function. + (_threadinfo::call2): Ditto. + (_threadinfo::init): Don't return pointer. + * thread.cc (pthread::thread_init_wrapper): Properly establish + _threadinfo environment. + (pthread::thread_init_wrapper2): New function. + * thread.h (pthread::thread_init_wrapper): Remove noreturn attribute + (pthread::thread_init_wrapper2): Declare new function. + * winbase.h: Remove obsolete code. + 2003-12-02 Christopher Faylor * Makefile.in: Change the way that -f options are appended to CFLAGS, diff --git a/winsup/cygwin/cygthread.cc b/winsup/cygwin/cygthread.cc index fa9781e8d..34111fd67 100644 --- a/winsup/cygwin/cygthread.cc +++ b/winsup/cygwin/cygthread.cc @@ -15,6 +15,8 @@ details. */ #include "sync.h" #include "cygerrno.h" #include "sigproc.h" +#include "thread.h" +#include "cygtls.h" #undef CloseHandle @@ -30,13 +32,20 @@ bool NO_COPY cygthread::exiting; DWORD WINAPI cygthread::stub (VOID *arg) { - DECLARE_TLS_STORAGE; + _threadinfo::call (stub2, arg); + return 0; +} + +void +cygthread::stub2 (void *arg, void *) +{ exception_list except_entry; /* Initialize this thread's ability to respond to things like SIGSEGV or SIGFPE. */ init_exceptions (&except_entry); + cygthread *info = (cygthread *) arg; if (info->arg == cygself) { @@ -91,7 +100,13 @@ cygthread::stub (VOID *arg) DWORD WINAPI cygthread::simplestub (VOID *arg) { - DECLARE_TLS_STORAGE; + _threadinfo::call (simplestub2, arg); + return 0; +} + +void +cygthread::simplestub2 (void *arg, void *) +{ exception_list except_entry; /* Initialize this thread's ability to respond to things like diff --git a/winsup/cygwin/cygthread.h b/winsup/cygwin/cygthread.h index b8566d4c7..a01719b7e 100644 --- a/winsup/cygwin/cygthread.h +++ b/winsup/cygwin/cygthread.h @@ -20,7 +20,9 @@ class cygthread bool is_freerange; static bool exiting; static DWORD WINAPI stub (VOID *); + static void stub2 (void *, void *); static DWORD WINAPI simplestub (VOID *); + static void simplestub2 (void *, void *); void terminate_thread (); public: static DWORD main_thread_id; diff --git a/winsup/cygwin/cygtls.h b/winsup/cygwin/cygtls.h index c0ab189b9..ec6087af8 100644 --- a/winsup/cygwin/cygtls.h +++ b/winsup/cygwin/cygtls.h @@ -40,7 +40,9 @@ struct _threadinfo int sig; __stack_t *stackptr; - struct _threadinfo *init (void *, void * = NULL); + void init (void *); + static void call (void (*) (void *, void *), void *); + void call2 (void (*) (void *, void *), void *, void *); void remove (); void push (__stack_t, bool = false); __stack_t pop (); diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc index 1ca549ec2..a0af0231b 100644 --- a/winsup/cygwin/dcrt0.cc +++ b/winsup/cygwin/dcrt0.cc @@ -532,8 +532,9 @@ _threadinfo NO_COPY *_main_tls; static void dll_crt0_1 () { - __uint64_t padding[CYGTLS_PADSIZE]; - _main_tls = _my_tls.init (padding); + char padding[CYGTLS_PADSIZE]; + _main_tls = &_my_tls; + _main_tls->init (padding); /* According to onno@stack.urc.tue.nl, the exception handler record must be on the stack. */ @@ -838,7 +839,6 @@ initial_env () extern "C" void __stdcall _dll_crt0 () { - DECLARE_TLS_STORAGE; initial_env (); char zeros[sizeof (fork_info->zero)] = {0}; static NO_COPY STARTUPINFO si; @@ -907,7 +907,6 @@ _dll_crt0 () void dll_crt0 (per_process *uptr) { - DECLARE_TLS_STORAGE; /* Set the local copy of the pointer into the user space. */ if (uptr && uptr != user_data) { diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc index 6e5aa3059..15a9eb117 100644 --- a/winsup/cygwin/exceptions.cc +++ b/winsup/cygwin/exceptions.cc @@ -147,8 +147,22 @@ _threadinfo::reset_exception () } } -_threadinfo * -_threadinfo::init (void *, void *thread) +void +_threadinfo::call (void (*func) (void *, void *), void *arg) +{ + char buf[CYGTLS_PADSIZE]; + _my_tls.call2 (func, arg, buf); +} + +void +_threadinfo::call2 (void (*func) (void *, void *), void *arg, void *buf) +{ + init (buf); + func (arg, buf); +} + +void +_threadinfo::init (void *) { memset (this, 0, sizeof (*this)); stackptr = stack; @@ -157,7 +171,6 @@ _threadinfo::init (void *, void *thread) _last_thread = this; set_state (false); errno_addr = &errno; - return this; } void diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc index cb99be031..a34cd8497 100644 --- a/winsup/cygwin/thread.cc +++ b/winsup/cygwin/thread.cc @@ -1885,14 +1885,10 @@ __reent_t::init_clib (struct _reent& var) _clib = &var; }; -/* Pthreads */ -void * -pthread::thread_init_wrapper (void *_arg) +void +pthread::thread_init_wrapper2 (void *arg, void *) { - // Setup the local/global storage of this thread - __uint64_t padding[CYGTLS_PADSIZE]; - pthread *thread = (pthread *) _arg; - thread->cygtls = _my_tls.init (padding, &thread); + pthread *thread = (pthread *) arg; _my_tls.tid = thread; exception_list cygwin_except_entry; @@ -1923,7 +1919,7 @@ pthread::thread_init_wrapper (void *_arg) system_printf ("local storage for thread isn't setup correctly"); #endif - thread_printf ("started thread %p %p %p %p %p %p", _arg, &local_clib, + thread_printf ("started thread %p %p %p %p %p %p", arg, &local_clib, _impure_ptr, thread, thread->function, thread->arg); // call the user's thread @@ -1932,6 +1928,14 @@ pthread::thread_init_wrapper (void *_arg) thread->exit (ret); } +/* Pthreads */ +void +pthread::thread_init_wrapper (void *arg) +{ + // calls thread_init_wrapper2. Never returns. + _threadinfo::call (thread_init_wrapper2, arg); +} + bool pthread::is_good_object (pthread_t const *thread) { diff --git a/winsup/cygwin/thread.h b/winsup/cygwin/thread.h index b924957e4..ef0e59ac2 100644 --- a/winsup/cygwin/thread.h +++ b/winsup/cygwin/thread.h @@ -502,7 +502,8 @@ public: virtual void pop_cleanup_handler (int const execute); static pthread* self (); - static void *thread_init_wrapper (void *) __attribute__ ((noreturn)); + static void thread_init_wrapper (void *); + static void thread_init_wrapper2 (void *, void *); virtual unsigned long getsequence_np(); diff --git a/winsup/cygwin/winbase.h b/winsup/cygwin/winbase.h index 3cbdb183d..3dbf116ea 100644 --- a/winsup/cygwin/winbase.h +++ b/winsup/cygwin/winbase.h @@ -56,49 +56,4 @@ ilockcmpexch (long *t, long v, long c) #define InterlockedExchange ilockexch #undef InterlockedCompareExchange #define InterlockedCompareExchange ilockcmpexch - -// extern char * volatile *__stackbase __asm__ ("%fs:4"); -#ifndef EXPCGf -#define DECLARE_TLS_STORAGE do {} while (0) -#else -#define DECLARE_TLS_STORAGE char **tls[4096] __attribute__ ((unused)) -extern long tls_ix; - -extern __inline__ DWORD -my_tlsalloc () -{ - DWORD n = ilockdecr (&tls_ix); - __stackbase[tls_ix] = NULL; - return n; -} - -extern __inline__ BOOL -my_tlssetvalue (DWORD ix, void *val) -{ - __stackbase[ix] = (char *) val; - return 1; -} - -extern __inline__ void * -my_tlsgetvalue (DWORD ix) -{ - return __stackbase[ix]; -} - -extern __inline__ BOOL -my_tlsfree (DWORD ix) -{ - /* nothing for now */ - return 1; -} - -#undef TlsAlloc -#define TlsAlloc my_tlsalloc -#undef TlsGetValue -#define TlsGetValue my_tlsgetvalue -#undef TlsSetValue -#define TlsSetValue my_tlssetvalue -#undef TlsFree -#define TlsFree my_tlsfree -#endif /*EXPCGF*/ #endif /*_WINBASE2_H*/