From 29d52c8a27ec621dea1c8229c26b60fe12bc3e16 Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Tue, 23 Dec 2003 16:26:31 +0000 Subject: * exceptions.cc (set_signal_mask): Redefine to not pass by address. Report calculated mask in debugging output. * sigproc.h (set_signal_mask): Reflect above change in declaration. * path.cc (mount_item::build_win32): Take path apart before feeding it to fnmunge. Throughout, change use of _reent_winsup()-> to _my_tls.locals. instead. Throughout, remove obsolete MT_SAFE/_CYG_THREAD_FAILSAFE considerations. Througout, add cygtls.h include. * Makefile.in (DLL_OFILES): Add cygtls.o. Add some more objects to the -fomit-frame-pointer list. * acconfig.h: Remove obsolete settings. * config.h.in: Ditto. * bsdlib.cc: Add cygtls.h include. * configure.in: Remove --enable-extra-threadsafe-checking. * configure: Regenerate. * cygtls.h (_local_storage): New struct renamed from _winsup_t (sic). (_threadinfo:local_clib): Add new field. (_threadinfo::locals): Ditto. (_threadinfo::init_thread): Accept second _reent * argument. (_threadinfo::call): Define as regparm. (CYGTLS_PADSIZE): Remove unnecessary slop. (_getreent): Define as a macro. * thread.h: Remove _CYG_THREAD_FAILSAFE and MT_SAFE stuff. (_winsup_t): Move to cygtls.h. (ResourceLocks::ResourceLocks): Eliminate empty constructor. (MTinterface::reents): Eliminate. (MTinterface::thread_self_key): Eliminate. (MTinterface::MTinterface): Eliminate. * dcrt0.cc: Include stdio.h for _impure_ptr initialization. (do_global_ctors): Remove run_ctors_p (sic) considerations. Don't call atexit here. (__main): Initialize destructors for user here. (dll_crt0_1): Accept a dummy argument. Don't call init_thread here. Don't set _impure_ptr here. Call do_global_ctors after more things have been initialized. (_dll_crt0): Define zeros buffer as max of needed size of CYGTLS_PADSIZE so that it can be used for two purposes while minimizing stack usage. Initialize _impure_ptr specifically, for speed. Call dll_crt0_1 with buffer argument. (cygwin_dll_init): Call dll_crt0_1 with dummy argument. * dtable.cc (dtable::find_unused_handle): Remove call to AssertResourceOwner. * exceptions.cc: Move _threadinfo stuff to new file. * cygtls.cc: New file. * gentls_offsets: Accommodate increasing complexity of cygtls.h. * hires.h (hires_base::~hires_base): Remove. * init.cc (dll_entry): Remove setting of reents. * thread.cc: Remove syslog.h include. (__getreent): Simplify to use _my_tls. (_reent_winsup): Delete. (AssertResourceOwner): Delete. (MTinterface::Init): Remove setting of _clib and _winsup, with all that entails. (MTinterface::fixup_after_fork): Ditto. (pthread::thread_init_wrapper): Ditto. Also remove call to set_tls_self_pointer. (pthread::set_tls_self_pointer): Eliminate. (pthread::get_tls_self_pointer): Just return _my_tls.tid; (__reent_t::init_clib): Eliminate. * tlsoffsets.h: Regenerate. --- winsup/cygwin/dcrt0.cc | 66 +++++++++++++++++++++++++++----------------------- 1 file changed, 36 insertions(+), 30 deletions(-) (limited to 'winsup/cygwin/dcrt0.cc') diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc index 72161f91e..63148061b 100644 --- a/winsup/cygwin/dcrt0.cc +++ b/winsup/cygwin/dcrt0.cc @@ -10,6 +10,7 @@ details. */ #include "winsup.h" #include +#include #include #include "glob.h" #include "exceptions.h" @@ -89,7 +90,6 @@ extern "C" char ***main_environ; /* __progname used in getopt error message */ char *__progname; - struct _reent reent_data = _REENT_INIT(reent_data); struct per_process __cygwin_user_data = {/* initial_sp */ 0, /* magic_biscuit */ 0, /* dll_major */ CYGWIN_VERSION_DLL_MAJOR, @@ -110,7 +110,7 @@ extern "C" /* api_minor */ CYGWIN_VERSION_API_MINOR, /* unused2 */ {0, 0, 0, 0, 0}, /* resourcelocks */ &_reslock, /* threadinterface */ &_mtinterf, - /* impure_ptr */ &reent_data, + /* impure_ptr */ NULL, }; bool ignore_case_with_glob; int __declspec (dllexport) _check_for_executable = true; @@ -136,25 +136,18 @@ do_global_dtors (void) static void __stdcall do_global_ctors (void (**in_pfunc)(), int force) { - if (!force) - { - if (user_data->forkee || user_data->run_ctors_p) - return; // inherit constructed stuff from parent pid - user_data->run_ctors_p = 1; - } + if (!force && user_data->forkee) + return; // inherit constructed stuff from parent pid /* Run ctors backwards, so skip the first entry and find how many there are, then run them. */ - void (**pfunc)() = in_pfunc; + void (**pfunc) () = in_pfunc; while (*++pfunc) ; while (--pfunc > in_pfunc) (*pfunc) (); - - if (user_data->magic_biscuit == SIZEOF_PER_PROCESS) - atexit (do_global_dtors); } /* @@ -530,12 +523,8 @@ alloc_stack (child_info_fork *ci) opposed to being link-time loaded by Cygwin apps) from a non cygwin app via LoadLibrary. */ static void -dll_crt0_1 () +dll_crt0_1 (char *) { - char padding[CYGTLS_PADSIZE]; - _main_tls = &_my_tls; - _main_tls->init_thread (padding); - /* According to onno@stack.urc.tue.nl, the exception handler record must be on the stack. */ /* FIXME: Verify forked children get their exception handler set up ok. */ @@ -557,8 +546,6 @@ dll_crt0_1 () fork copy code doesn't copy the data in libccrt0.cc (that's why we pass in the per_process struct into the .dll from libccrt0). */ - _impure_ptr = &reent_data; - user_data->resourcelocks->Init (); user_data->threadinterface->Init (); @@ -771,15 +758,16 @@ dll_crt0_1 () /* Disable case-insensitive globbing */ ignore_case_with_glob = false; - /* Flush signals and ensure that signal thread is up and running. Can't - do this for noncygwin case since the signal thread is blocked due to - LoadLibrary serialization. */ - wait_for_sigthread (); set_errno (0); MALLOC_CHECK; cygbench (__progname); + + /* Flush signals and ensure that signal thread is up and running. Can't + do this for noncygwin case since the signal thread is blocked due to + LoadLibrary serialization. */ + wait_for_sigthread (); if (user_data->main) exit (user_data->main (__argc, __argv, *user_data->envptr)); } @@ -830,6 +818,21 @@ initial_env () _cygwin_testing = 1; } +struct _reent * +initialize_main_tls (char *padding) +{ + if (!_main_tls) + { + _threadinfo::init (); + _main_tls = &_my_tls; + _main_tls->init_thread (padding); + _main_tls->local_clib._stdin = &_main_tls->local_clib.__sf[0]; + _main_tls->local_clib._stdout = &_main_tls->local_clib.__sf[1]; + _main_tls->local_clib._stderr = &_main_tls->local_clib.__sf[2]; + } + return &_main_tls->local_clib; +} + /* Wrap the real one, otherwise gdb gets confused about two symbols with the same name, but different addresses. @@ -840,7 +843,7 @@ extern "C" void __stdcall _dll_crt0 () { initial_env (); - char zeros[sizeof (fork_info->zero)] = {0}; + char zeros[max (CYGTLS_PADSIZE, sizeof (child_proc_info->zero))] = {0}; static NO_COPY STARTUPINFO si; main_environ = user_data->envptr; @@ -859,7 +862,8 @@ _dll_crt0 () GetStartupInfo (&si); child_proc_info = (child_info *) si.lpReserved2; if (si.cbReserved2 < EXEC_MAGIC_SIZE || !child_proc_info - || memcmp (child_proc_info->zero, zeros, sizeof (zeros)) != 0) + || memcmp (child_proc_info->zero, zeros, + sizeof (child_proc_info->zero)) != 0) child_proc_info = NULL; else { @@ -901,19 +905,20 @@ _dll_crt0 () break; } } - - _threadinfo::init (); - dll_crt0_1 (); + + user_data->impure_ptr = _impure_ptr = initialize_main_tls (zeros); + dll_crt0_1 (zeros); } void dll_crt0 (per_process *uptr) { + char padding[CYGTLS_PADSIZE]; /* Set the local copy of the pointer into the user space. */ if (uptr && uptr != user_data) { memcpy (user_data, uptr, per_process_overwrite); - *(user_data->impure_ptr_ptr) = &reent_data; + *(user_data->impure_ptr_ptr) = initialize_main_tls (padding); } _dll_crt0 (); } @@ -937,13 +942,14 @@ cygwin_dll_init () user_data->envptr = &envp; user_data->fmode_ptr = &_fmode; - dll_crt0_1 (); + dll_crt0_1 (NULL); } extern "C" void __main (void) { do_global_ctors (user_data->ctors, false); + atexit (do_global_dtors); } exit_states NO_COPY exit_state; -- cgit v1.2.3