From 1691311a617c8f513ae1b8ccd6425a7075fcbdc6 Mon Sep 17 00:00:00 2001 From: cgf Date: Tue, 16 May 2006 03:14:23 +0000 Subject: [PATCH] * sigproc.cc (no_signals_available): Detect hwait_sig == INVALID_HANDLE_VALUE. (wait_sig): Set hwait_sig to INVALID_HANDLE_VALUE on __SIGEXIT. * cygtls.cc (_cygtls::init_thread): Zero entire _my_tls structure and no more. * cygtls.h (_my_tls::padding): Delete. (CYGTLS_PADSIZE): Redefine concept of padding to mean padding at the end of the stack. * dcrt0.cc (initialize_main_tls): Change return to void. * gentls_offsets: Treat const specially, too. Keep going after a '}' is found. Change negative offset calculation to use CYGTLS_PADSIZE. * init.cc (_my_oldfunc): New variable. (threadfunc_fe): Use stored tls value for oldfunc rather than blindly writing to the stack. (munge_threadfunc): Set oldfunc in tls. (dll_entry): Initialize tls allocation. * tlsoffsets.h: Regenerate. --- winsup/cygwin/ChangeLog | 23 ++++++++ winsup/cygwin/cygtls.cc | 2 +- winsup/cygwin/cygtls.h | 11 ++-- winsup/cygwin/dcrt0.cc | 4 +- winsup/cygwin/gentls_offsets | 11 ++-- winsup/cygwin/init.cc | 7 ++- winsup/cygwin/sigproc.cc | 4 +- winsup/cygwin/tlsoffsets.h | 128 +++++++++++++++++++++---------------------- 8 files changed, 105 insertions(+), 85 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index f8ff92e3ae..0d419e55b8 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,26 @@ +2006-05-15 Christopher Faylor + + * sigproc.cc (no_signals_available): Detect hwait_sig == + INVALID_HANDLE_VALUE. + (wait_sig): Set hwait_sig to INVALID_HANDLE_VALUE on __SIGEXIT. + +2006-05-14 Christopher Faylor + + * cygtls.cc (_cygtls::init_thread): Zero entire _my_tls structure and + no more. + * cygtls.h (_my_tls::padding): Delete. + (CYGTLS_PADSIZE): Redefine concept of padding to mean padding at the + end of the stack. + * dcrt0.cc (initialize_main_tls): Change return to void. + * gentls_offsets: Treat const specially, too. Keep going after a '}' + is found. Change negative offset calculation to use CYGTLS_PADSIZE. + * init.cc (_my_oldfunc): New variable. + (threadfunc_fe): Use stored tls value for oldfunc rather than blindly + writing to the stack. + (munge_threadfunc): Set oldfunc in tls. + (dll_entry): Initialize tls allocation. + * tlsoffsets.h: Regenerate. + 2006-05-13 Christopher Faylor * ntdll.h (STATUS_INVALID_INFO_CLASS): Conditionalize. diff --git a/winsup/cygwin/cygtls.cc b/winsup/cygwin/cygtls.cc index 70f5a56d89..f897ca53f0 100644 --- a/winsup/cygwin/cygtls.cc +++ b/winsup/cygwin/cygtls.cc @@ -81,7 +81,7 @@ _cygtls::init_thread (void *x, DWORD (*func) (void *, void *)) { if (x) { - memset (this, 0, CYGTLS_PADSIZE); + memset (this, 0, sizeof (*this)); stackptr = stack; if (_GLOBAL_REENT) { diff --git a/winsup/cygwin/cygtls.h b/winsup/cygwin/cygtls.h index 030680be08..fb34df2d74 100644 --- a/winsup/cygwin/cygtls.h +++ b/winsup/cygwin/cygtls.h @@ -170,7 +170,6 @@ struct _cygtls __stack_t *stackptr; __stack_t stack[TLS_STACK_SIZE]; unsigned initialized; - unsigned padding[0]; /*gentls_offsets*/ static CRITICAL_SECTION protect_linked_list; @@ -235,13 +234,15 @@ struct _cygtls }; #pragma pack(pop) +const int CYGTLS_PADSIZE = 3 * sizeof (_cygtls); +/*gentls_offsets*/ + extern char *_tlsbase __asm__ ("%fs:4"); extern char *_tlstop __asm__ ("%fs:8"); -#define _my_tls (((_cygtls *) _tlsbase)[-1]) +#define _my_tls (*((_cygtls *) (_tlsbase - CYGTLS_PADSIZE))) extern _cygtls *_main_tls; extern _cygtls *_sig_tls; -/*gentls_offsets*/ class myfault { jmp_buf buf; @@ -253,9 +254,7 @@ public: return _my_tls.setup_fault (buf, sebastian, myerrno); } }; -/*gentls_offsets*/ #define __getreent() (&_my_tls.local_clib) -const int CYGTLS_PADSIZE = (((char *) _main_tls->padding) - ((char *) _main_tls)); -#endif /*_CYGTLS_H*/ +#endif /*_CYGTLS_H*/ /*gentls_offsets*/ diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc index dcc13d528c..667699dd7e 100644 --- a/winsup/cygwin/dcrt0.cc +++ b/winsup/cygwin/dcrt0.cc @@ -953,7 +953,7 @@ dll_crt0_1 (char *) cygwin_exit (user_data->main (__argc, __argv, *user_data->envptr)); } -struct _reent * +static void initialize_main_tls (char *padding) { if (!_main_tls) @@ -961,7 +961,7 @@ initialize_main_tls (char *padding) _main_tls = &_my_tls; _main_tls->init_thread (padding, NULL); } - return &_main_tls->local_clib; + return; } /* Wrap the real one, otherwise gdb gets confused about diff --git a/winsup/cygwin/gentls_offsets b/winsup/cygwin/gentls_offsets index 21c9d1e7ac..0ab6b64ab3 100755 --- a/winsup/cygwin/gentls_offsets +++ b/winsup/cygwin/gentls_offsets @@ -21,12 +21,11 @@ $pre =~ s/\n#ifndef _[^\n]+\n/\n/os; $pre .= "\n//*/"; $tls =~ s%/\*\s*gentls_offsets.*?/\*\s*gentls_offsets\s*\*/%%ogs; foreach ($tls =~ /^.*\n/mg) { - $def .= $_ if $struct; - last if /^};/o; - /^\s*typedef/o and do { + /^}|\s*(?:typedef|const)/o and do { $def .= $_ ; next; }; + $def .= $_ if $struct; if (!s/;.*$//o) { if (!$struct && /^\s*(?:struct|class)\s*([a-z_0-9]+)/o) { $def .= $_; @@ -55,9 +54,9 @@ $def int main(int argc, char **argv) { - $struct foo[1]; -# define foo_end ((char *) (foo + 1)) -# define offset(f) (((char *) &(foo->f)) - foo_end) + $struct *foo; +# define foo_beg ((char *) foo) +# define offset(f) (-CYGTLS_PADSIZE + ((char *) &(foo->f)) - foo_beg) # define poffset(f) (((char *) &(foo->f)) - ((char *) foo)) EOF print TMP 'puts ("//;# autogenerated: Do not edit.\n");', "\n\n"; diff --git a/winsup/cygwin/init.cc b/winsup/cygwin/init.cc index f8b6cd6522..f73be7236b 100644 --- a/winsup/cygwin/init.cc +++ b/winsup/cygwin/init.cc @@ -18,6 +18,8 @@ details. */ #include #include "ntdll.h" +static DWORD _my_oldfunc; + int NO_COPY dynamically_loaded; static char NO_COPY *search_for = (char *) cygthread::stub; unsigned threadfunc_ix[8] __attribute__((section (".cygwin_dll_common"), shared)); @@ -30,7 +32,7 @@ threadfunc_fe (VOID *arg) { (void)__builtin_return_address(1); asm volatile ("andl $-16,%%esp" ::: "%esp"); - _cygtls::call ((DWORD (*) (void *, void *)) (((char **) _tlsbase)[OLDFUNC_OFFSET]), arg); + _cygtls::call ((DWORD (*) (void *, void *)) TlsGetValue (_my_oldfunc), arg); } /* If possible, redirect the thread entry point to a cygwin routine which @@ -62,7 +64,7 @@ munge_threadfunc () search_for = NULL; for (i = 0; threadfunc_ix[i]; i++) ebp[threadfunc_ix[i]] = (char *) threadfunc_fe; - ((char **) _tlsbase)[OLDFUNC_OFFSET] = threadfunc; + TlsSetValue (_my_oldfunc, threadfunc); } } } @@ -145,6 +147,7 @@ dll_entry (HANDLE h, DWORD reason, void *static_load) respawn_wow64_process (); dll_crt0_0 (); + _my_oldfunc = TlsAlloc (); break; case DLL_PROCESS_DETACH: break; diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc index 10ff3cefcd..9eb918dc15 100644 --- a/winsup/cygwin/sigproc.cc +++ b/winsup/cygwin/sigproc.cc @@ -39,7 +39,7 @@ details. */ #define WSSC 60000 // Wait for signal completion #define WPSP 40000 // Wait for proc_subproc mutex -#define no_signals_available(x) (!hwait_sig || ((x) && myself->exitcode & EXITCODE_SET) || &_my_tls == _sig_tls || in_dllentry) +#define no_signals_available(x) (!hwait_sig || hwait_sig == INVALID_HANDLE_VALUE || ((x) && myself->exitcode & EXITCODE_SET) || &_my_tls == _sig_tls || in_dllentry) #define NPROCS 256 @@ -1209,7 +1209,7 @@ wait_sig (VOID *) } break; case __SIGEXIT: - hwait_sig = NULL; + hwait_sig = (cygthread *) INVALID_HANDLE_VALUE; sigproc_printf ("saw __SIGEXIT"); break; /* handle below */ default: diff --git a/winsup/cygwin/tlsoffsets.h b/winsup/cygwin/tlsoffsets.h index 9002abfce8..08702dadce 100644 --- a/winsup/cygwin/tlsoffsets.h +++ b/winsup/cygwin/tlsoffsets.h @@ -1,133 +1,129 @@ //;# autogenerated: Do not edit. //; $tls::sizeof__cygtls = 4212; -//; $tls::func = -4212; +//; $tls::func = -12636; //; $tls::pfunc = 0; -//; $tls::saved_errno = -4208; +//; $tls::saved_errno = -12632; //; $tls::psaved_errno = 4; -//; $tls::sa_flags = -4204; +//; $tls::sa_flags = -12628; //; $tls::psa_flags = 8; -//; $tls::oldmask = -4200; +//; $tls::oldmask = -12624; //; $tls::poldmask = 12; -//; $tls::deltamask = -4196; +//; $tls::deltamask = -12620; //; $tls::pdeltamask = 16; -//; $tls::event = -4192; +//; $tls::event = -12616; //; $tls::pevent = 20; -//; $tls::errno_addr = -4188; +//; $tls::errno_addr = -12612; //; $tls::perrno_addr = 24; -//; $tls::sigmask = -4184; +//; $tls::sigmask = -12608; //; $tls::psigmask = 28; -//; $tls::sigwait_mask = -4180; +//; $tls::sigwait_mask = -12604; //; $tls::psigwait_mask = 32; -//; $tls::sigwait_info = -4176; +//; $tls::sigwait_info = -12600; //; $tls::psigwait_info = 36; -//; $tls::thread_context = -4172; +//; $tls::thread_context = -12596; //; $tls::pthread_context = 40; -//; $tls::thread_id = -3960; +//; $tls::thread_id = -12384; //; $tls::pthread_id = 252; -//; $tls::threadkill = -3956; +//; $tls::threadkill = -12380; //; $tls::pthreadkill = 256; -//; $tls::infodata = -3952; +//; $tls::infodata = -12376; //; $tls::pinfodata = 260; -//; $tls::tid = -3804; +//; $tls::tid = -12228; //; $tls::ptid = 408; -//; $tls::local_clib = -3800; +//; $tls::local_clib = -12224; //; $tls::plocal_clib = 412; -//; $tls::__dontuse = -3800; +//; $tls::__dontuse = -12224; //; $tls::p__dontuse = 412; -//; $tls::locals = -2736; +//; $tls::locals = -11160; //; $tls::plocals = 1476; -//; $tls::_ctinfo = -1104; +//; $tls::_ctinfo = -9528; //; $tls::p_ctinfo = 3108; -//; $tls::el = -1100; +//; $tls::el = -9524; //; $tls::pel = 3112; -//; $tls::andreas = -1092; +//; $tls::andreas = -9516; //; $tls::pandreas = 3120; -//; $tls::wq = -1084; +//; $tls::wq = -9508; //; $tls::pwq = 3128; -//; $tls::prev = -1056; +//; $tls::prev = -9480; //; $tls::pprev = 3156; -//; $tls::next = -1052; +//; $tls::next = -9476; //; $tls::pnext = 3160; -//; $tls::sig = -1048; +//; $tls::sig = -9472; //; $tls::psig = 3164; -//; $tls::incyg = -1044; +//; $tls::incyg = -9468; //; $tls::pincyg = 3168; -//; $tls::spinning = -1040; +//; $tls::spinning = -9464; //; $tls::pspinning = 3172; -//; $tls::stacklock = -1036; +//; $tls::stacklock = -9460; //; $tls::pstacklock = 3176; -//; $tls::stackptr = -1032; +//; $tls::stackptr = -9456; //; $tls::pstackptr = 3180; -//; $tls::stack = -1028; +//; $tls::stack = -9452; //; $tls::pstack = 3184; -//; $tls::initialized = -4; +//; $tls::initialized = -8428; //; $tls::pinitialized = 4208; -//; $tls::padding = 0; -//; $tls::ppadding = 4212; //; __DATA__ -#define tls_func (-4212) +#define tls_func (-12636) #define tls_pfunc (0) -#define tls_saved_errno (-4208) +#define tls_saved_errno (-12632) #define tls_psaved_errno (4) -#define tls_sa_flags (-4204) +#define tls_sa_flags (-12628) #define tls_psa_flags (8) -#define tls_oldmask (-4200) +#define tls_oldmask (-12624) #define tls_poldmask (12) -#define tls_deltamask (-4196) +#define tls_deltamask (-12620) #define tls_pdeltamask (16) -#define tls_event (-4192) +#define tls_event (-12616) #define tls_pevent (20) -#define tls_errno_addr (-4188) +#define tls_errno_addr (-12612) #define tls_perrno_addr (24) -#define tls_sigmask (-4184) +#define tls_sigmask (-12608) #define tls_psigmask (28) -#define tls_sigwait_mask (-4180) +#define tls_sigwait_mask (-12604) #define tls_psigwait_mask (32) -#define tls_sigwait_info (-4176) +#define tls_sigwait_info (-12600) #define tls_psigwait_info (36) -#define tls_thread_context (-4172) +#define tls_thread_context (-12596) #define tls_pthread_context (40) -#define tls_thread_id (-3960) +#define tls_thread_id (-12384) #define tls_pthread_id (252) -#define tls_threadkill (-3956) +#define tls_threadkill (-12380) #define tls_pthreadkill (256) -#define tls_infodata (-3952) +#define tls_infodata (-12376) #define tls_pinfodata (260) -#define tls_tid (-3804) +#define tls_tid (-12228) #define tls_ptid (408) -#define tls_local_clib (-3800) +#define tls_local_clib (-12224) #define tls_plocal_clib (412) -#define tls___dontuse (-3800) +#define tls___dontuse (-12224) #define tls_p__dontuse (412) -#define tls_locals (-2736) +#define tls_locals (-11160) #define tls_plocals (1476) -#define tls__ctinfo (-1104) +#define tls__ctinfo (-9528) #define tls_p_ctinfo (3108) -#define tls_el (-1100) +#define tls_el (-9524) #define tls_pel (3112) -#define tls_andreas (-1092) +#define tls_andreas (-9516) #define tls_pandreas (3120) -#define tls_wq (-1084) +#define tls_wq (-9508) #define tls_pwq (3128) -#define tls_prev (-1056) +#define tls_prev (-9480) #define tls_pprev (3156) -#define tls_next (-1052) +#define tls_next (-9476) #define tls_pnext (3160) -#define tls_sig (-1048) +#define tls_sig (-9472) #define tls_psig (3164) -#define tls_incyg (-1044) +#define tls_incyg (-9468) #define tls_pincyg (3168) -#define tls_spinning (-1040) +#define tls_spinning (-9464) #define tls_pspinning (3172) -#define tls_stacklock (-1036) +#define tls_stacklock (-9460) #define tls_pstacklock (3176) -#define tls_stackptr (-1032) +#define tls_stackptr (-9456) #define tls_pstackptr (3180) -#define tls_stack (-1028) +#define tls_stack (-9452) #define tls_pstack (3184) -#define tls_initialized (-4) +#define tls_initialized (-8428) #define tls_pinitialized (4208) -#define tls_padding (0) -#define tls_ppadding (4212) -- 2.11.0