From b64733135ad678a80e14a64a54af0b8538fb8fcf Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Sun, 19 Sep 2010 20:18:36 +0000 Subject: [PATCH] * wincap.h (wincaps::has_buggy_thread_startup): Declare. (wincapc::has_buggy_thread_startup): Ditto. * wincap.cc::wincap_*): Accommodate has_buggy_thread_startup. (wincapc::init): Explicitly turn off has_buggy_thread_startup if not WOW64. * cygthread.h (cygthread::thread_handle): Declare/define new method. * dcrt0.cc (_dll_crt0): Don't call __sinit here. (dll_crt0_0): Don't call sigproc_init during initialization if wincap.has_buggy_thread_startup(). (dll_crt0_1): Defer sigproc_init to here when wincap.has_buggy_thread_startup(). Call __sinit after we've determined that we're not forking. (__main): Rework comments. Add potential future reminder. --- winsup/cygwin/ChangeLog | 16 ++++++++++++++++ winsup/cygwin/cygthread.h | 1 + winsup/cygwin/dcrt0.cc | 27 +++++++++++++-------------- winsup/cygwin/wincap.cc | 13 +++++++++++++ winsup/cygwin/wincap.h | 2 ++ 5 files changed, 45 insertions(+), 14 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 6a07da9d4..e25cd553f 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,19 @@ +2010-09-19 Christopher Faylor + + * wincap.h (wincaps::has_buggy_thread_startup): Declare. + (wincapc::has_buggy_thread_startup): Ditto. + * wincap.cc::wincap_*): Accommodate has_buggy_thread_startup. + (wincapc::init): Explicitly turn off has_buggy_thread_startup if not + WOW64. + * cygthread.h (cygthread::thread_handle): Declare/define new method. + * dcrt0.cc (_dll_crt0): Don't call __sinit here. + (dll_crt0_0): Don't call sigproc_init during initialization + if wincap.has_buggy_thread_startup(). + (dll_crt0_1): Defer sigproc_init to here when + wincap.has_buggy_thread_startup(). Call __sinit after we've determined + that we're not forking. + (__main): Rework comments. Add potential future reminder. + 2010-09-15 Corinna Vinschen * fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Fetch number diff --git a/winsup/cygwin/cygthread.h b/winsup/cygwin/cygthread.h index e9dba0d5c..7f3869220 100644 --- a/winsup/cygwin/cygthread.h +++ b/winsup/cygwin/cygthread.h @@ -79,6 +79,7 @@ class cygthread void * operator new (size_t); static cygthread *freerange (); static void terminate (); + HANDLE thread_handle () const {return h;} bool SetThreadPriority (int nPriority) {return ::SetThreadPriority (h, nPriority);} void zap_h () { diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc index b539e4b7f..2d848ec19 100644 --- a/winsup/cygwin/dcrt0.cc +++ b/winsup/cygwin/dcrt0.cc @@ -774,7 +774,7 @@ dll_crt0_0 () /* Initialize signal processing here, early, in the hopes that the creation of a thread early in the process will cause more predictability in memory layout for the main thread. */ - if (!dynamically_loaded) + if (!wincap.has_buggy_thread_startup () && !dynamically_loaded) sigproc_init (); debug_printf ("finished dll_crt0_0 initialization"); @@ -789,7 +789,7 @@ dll_crt0_1 (void *) { extern void initial_setlocale (); - if (dynamically_loaded) + if (wincap.has_buggy_thread_startup () || dynamically_loaded) sigproc_init (); check_sanity_and_sync (user_data); @@ -853,6 +853,8 @@ dll_crt0_1 (void *) longjmp (fork_info->jmp, true); } + __sinit (_impure_ptr); + #ifdef DEBUGGING { extern void fork_init (); @@ -968,16 +970,9 @@ _dll_crt0 () { main_environ = user_data->envptr; if (in_forkee) - { - fork_info->alloc_stack (); - _main_tls = &_my_tls; - } - else - { - _main_tls = &_my_tls; - __sinit (_impure_ptr); - } + fork_info->alloc_stack (); + _main_tls = &_my_tls; _main_tls->call ((DWORD (*) (void *, void *)) dll_crt0_1, NULL); } @@ -1023,12 +1018,16 @@ __main (void) queued call to DLL dtors now. */ atexit (dll_global_dtors); do_global_ctors (user_data->ctors, false); - /* Now we have run global ctors, register their dtors. */ - atexit (do_global_dtors); - /* At exit, global dtors will run first, so the app can still + /* Now we have run global ctors, register their dtors. + + At exit, global dtors will run first, so the app can still use shared library functions while terminating; then the DLLs will be destroyed; finally newlib will shut down stdio and terminate itself. */ + atexit (do_global_dtors); +#if 0 /* Don't enable for now. See if we really need this. */ + sig_dispatch_pending (true); +#endif } void __stdcall diff --git a/winsup/cygwin/wincap.cc b/winsup/cygwin/wincap.cc index 39b1c7548..3d5bee99b 100644 --- a/winsup/cygwin/wincap.cc +++ b/winsup/cygwin/wincap.cc @@ -60,6 +60,7 @@ wincaps wincap_unknown __attribute__((section (".cygwin_dll_common"), shared)) = has_always_all_codepages:false, has_localenames:false, has_mwmo_inputavailable:false, + has_buggy_thread_startup:false, }; wincaps wincap_nt4 __attribute__((section (".cygwin_dll_common"), shared)) = { @@ -101,6 +102,7 @@ wincaps wincap_nt4 __attribute__((section (".cygwin_dll_common"), shared)) = { has_always_all_codepages:false, has_localenames:false, has_mwmo_inputavailable:false, + has_buggy_thread_startup:false, }; wincaps wincap_nt4sp4 __attribute__((section (".cygwin_dll_common"), shared)) = { @@ -142,6 +144,7 @@ wincaps wincap_nt4sp4 __attribute__((section (".cygwin_dll_common"), shared)) = has_always_all_codepages:false, has_localenames:false, has_mwmo_inputavailable:false, + has_buggy_thread_startup:false, }; wincaps wincap_2000 __attribute__((section (".cygwin_dll_common"), shared)) = { @@ -183,6 +186,7 @@ wincaps wincap_2000 __attribute__((section (".cygwin_dll_common"), shared)) = { has_always_all_codepages:false, has_localenames:false, has_mwmo_inputavailable:true, + has_buggy_thread_startup:false, }; wincaps wincap_2000sp4 __attribute__((section (".cygwin_dll_common"), shared)) = { @@ -224,6 +228,7 @@ wincaps wincap_2000sp4 __attribute__((section (".cygwin_dll_common"), shared)) = has_always_all_codepages:false, has_localenames:false, has_mwmo_inputavailable:true, + has_buggy_thread_startup:false, }; wincaps wincap_xp __attribute__((section (".cygwin_dll_common"), shared)) = { @@ -265,6 +270,7 @@ wincaps wincap_xp __attribute__((section (".cygwin_dll_common"), shared)) = { has_always_all_codepages:false, has_localenames:false, has_mwmo_inputavailable:true, + has_buggy_thread_startup:false, }; wincaps wincap_xpsp1 __attribute__((section (".cygwin_dll_common"), shared)) = { @@ -306,6 +312,7 @@ wincaps wincap_xpsp1 __attribute__((section (".cygwin_dll_common"), shared)) = { has_always_all_codepages:false, has_localenames:false, has_mwmo_inputavailable:true, + has_buggy_thread_startup:false, }; wincaps wincap_xpsp2 __attribute__((section (".cygwin_dll_common"), shared)) = { @@ -347,6 +354,7 @@ wincaps wincap_xpsp2 __attribute__((section (".cygwin_dll_common"), shared)) = { has_always_all_codepages:false, has_localenames:false, has_mwmo_inputavailable:true, + has_buggy_thread_startup:false, }; wincaps wincap_2003 __attribute__((section (".cygwin_dll_common"), shared)) = { @@ -388,6 +396,7 @@ wincaps wincap_2003 __attribute__((section (".cygwin_dll_common"), shared)) = { has_always_all_codepages:false, has_localenames:false, has_mwmo_inputavailable:true, + has_buggy_thread_startup:false, }; wincaps wincap_vista __attribute__((section (".cygwin_dll_common"), shared)) = { @@ -429,6 +438,7 @@ wincaps wincap_vista __attribute__((section (".cygwin_dll_common"), shared)) = { has_always_all_codepages:true, has_localenames:true, has_mwmo_inputavailable:true, + has_buggy_thread_startup:true, }; wincaps wincap_7 __attribute__((section (".cygwin_dll_common"), shared)) = { @@ -470,6 +480,7 @@ wincaps wincap_7 __attribute__((section (".cygwin_dll_common"), shared)) = { has_always_all_codepages:true, has_localenames:true, has_mwmo_inputavailable:true, + has_buggy_thread_startup:false, }; wincapc wincap __attribute__((section (".cygwin_dll_common"), shared)); @@ -576,6 +587,8 @@ wincapc::init () ((wincaps *)caps)->has_restricted_stack_args = false; } + if (!wow64) + ((wincaps *) caps)->has_buggy_thread_startup = false; __small_sprintf (osnam, "NT-%d.%d", version.dwMajorVersion, version.dwMinorVersion); } diff --git a/winsup/cygwin/wincap.h b/winsup/cygwin/wincap.h index 8f027d089..b8809b0f9 100644 --- a/winsup/cygwin/wincap.h +++ b/winsup/cygwin/wincap.h @@ -52,6 +52,7 @@ struct wincaps unsigned has_always_all_codepages : 1; unsigned has_localenames : 1; unsigned has_mwmo_inputavailable : 1; + unsigned has_buggy_thread_startup : 1; }; class wincapc @@ -109,6 +110,7 @@ public: bool IMPLEMENT (has_always_all_codepages) bool IMPLEMENT (has_localenames) bool IMPLEMENT (has_mwmo_inputavailable) + bool IMPLEMENT (has_buggy_thread_startup) #undef IMPLEMENT };