From 214f688f4547732da76bf70e61509ecfc86110ce Mon Sep 17 00:00:00 2001 From: cgf Date: Fri, 26 Dec 2003 04:40:51 +0000 Subject: [PATCH] * dcrt0.cc (reent_data): Reluctantly resurrect. (__cygwin_user_data::impure_ptr): Ditto. (_dll_crt0): Reluctantly initialize _impure_ptr here. (initialize_main_tls): Eliminate local_clib initialization since it now happens in init_thread. * init.cc (dll_entry): Reluctantly remove code which set _impure_ptr to the main thread's local_clib. * perthread.h (reent_data): Remove obsolete declaration. * sigproc.cc (proc_subproc): Add more debugging output. (get_proc_lock): Ditto. *dcrt0.cc (dll_crt0_1): Allocate argv[0] via malloc since main thread could exit. --- winsup/cygwin/ChangeLog | 17 +++++++++++++++++ winsup/cygwin/dcrt0.cc | 17 ++++++++++------- winsup/cygwin/fhandler_process.cc | 5 ++++- winsup/cygwin/init.cc | 4 +++- winsup/cygwin/perthread.h | 3 --- winsup/cygwin/sigproc.cc | 20 ++++++++++++-------- 6 files changed, 46 insertions(+), 20 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 4d285d955d..6a24494f8c 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,20 @@ +2003-12-25 Christopher Faylor + + * dcrt0.cc (reent_data): Reluctantly resurrect. + (__cygwin_user_data::impure_ptr): Ditto. + (_dll_crt0): Reluctantly initialize _impure_ptr here. + (initialize_main_tls): Eliminate local_clib initialization since it now + happens in init_thread. + * init.cc (dll_entry): Reluctantly remove code which set _impure_ptr to + the main thread's local_clib. + * perthread.h (reent_data): Remove obsolete declaration. + + * sigproc.cc (proc_subproc): Add more debugging output. + (get_proc_lock): Ditto. + + *dcrt0.cc (dll_crt0_1): Allocate argv[0] via malloc since main thread + could exit. + 2003-12-23 Christopher Faylor * fork.cc (fork_child): After a pthread/fork, ensure that impure diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc index 63148061b1..1922cc5fb4 100644 --- a/winsup/cygwin/dcrt0.cc +++ b/winsup/cygwin/dcrt0.cc @@ -90,6 +90,7 @@ extern "C" char ***main_environ; /* __progname used in getopt error message */ char *__progname; + static struct _reent reent_data; struct per_process __cygwin_user_data = {/* initial_sp */ 0, /* magic_biscuit */ 0, /* dll_major */ CYGWIN_VERSION_DLL_MAJOR, @@ -110,7 +111,7 @@ extern "C" /* api_minor */ CYGWIN_VERSION_API_MINOR, /* unused2 */ {0, 0, 0, 0, 0}, /* resourcelocks */ &_reslock, /* threadinterface */ &_mtinterf, - /* impure_ptr */ NULL, + /* impure_ptr */ &reent_data, }; bool ignore_case_with_glob; int __declspec (dllexport) _check_for_executable = true; @@ -700,9 +701,9 @@ dll_crt0_1 (char *) win32 style. */ if ((strchr (__argv[0], ':')) || (strchr (__argv[0], '\\'))) { - char *new_argv0 = (char *) alloca (CYG_MAX_PATH); + char *new_argv0 = (char *) malloc (CYG_MAX_PATH); cygwin_conv_to_posix_path (__argv[0], new_argv0); - __argv[0] = new_argv0; + __argv[0] = (char *) realloc (new_argv0, strlen (new_argv0) + 1); } } @@ -826,9 +827,6 @@ initialize_main_tls (char *padding) _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; } @@ -906,7 +904,12 @@ _dll_crt0 () } } - user_data->impure_ptr = _impure_ptr = initialize_main_tls (zeros); + _impure_ptr = &reent_data; + _impure_ptr->_stdin = &_impure_ptr->__sf[0]; + _impure_ptr->_stdout = &_impure_ptr->__sf[1]; + _impure_ptr->_stderr = &_impure_ptr->__sf[2]; + _impure_ptr->_current_locale = "C"; + initialize_main_tls (zeros); dll_crt0_1 (zeros); } diff --git a/winsup/cygwin/fhandler_process.cc b/winsup/cygwin/fhandler_process.cc index 28dc78ff51..a65bcf6124 100644 --- a/winsup/cygwin/fhandler_process.cc +++ b/winsup/cygwin/fhandler_process.cc @@ -300,7 +300,10 @@ fhandler_process::fill_filebuf () filebuf = p->cmdline (fs); filesize = fs; if (!filebuf || !*filebuf) - filebuf = strdup (""); + { + filebuf = strdup (""); + filesize = strlen (filebuf) + 1; + } break; } case PROCESS_EXENAME: diff --git a/winsup/cygwin/init.cc b/winsup/cygwin/init.cc index 9b7201c6a2..61da81fb65 100644 --- a/winsup/cygwin/init.cc +++ b/winsup/cygwin/init.cc @@ -52,7 +52,7 @@ dll_entry (HANDLE h, DWORD reason, void *static_load) { case DLL_PROCESS_ATTACH: dynamically_loaded = (static_load == NULL); - __cygwin_user_data.impure_ptr = &_my_tls.local_clib; + // __cygwin_user_data.impure_ptr = &_my_tls.local_clib; _my_tls.stackptr = _my_tls.stack; break; case DLL_PROCESS_DETACH: @@ -60,6 +60,8 @@ dll_entry (HANDLE h, DWORD reason, void *static_load) case DLL_THREAD_ATTACH: munge_threadfunc (h); break; + case DLL_THREAD_DETACH: + break; } return 1; } diff --git a/winsup/cygwin/perthread.h b/winsup/cygwin/perthread.h index a7095dc536..217fc7a74d 100644 --- a/winsup/cygwin/perthread.h +++ b/winsup/cygwin/perthread.h @@ -12,9 +12,6 @@ details. */ #define PTMAGIC 0x77366377 -struct _reent; -extern struct _reent reent_data; - #define PER_THREAD_FORK_CLEAR ((void *)UINT32_MAX) class per_thread { diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc index 227a25b001..ae536aa048 100644 --- a/winsup/cygwin/sigproc.cc +++ b/winsup/cygwin/sigproc.cc @@ -226,14 +226,20 @@ get_proc_lock (DWORD what, DWORD val) { Static int lastwhat = -1; if (!sync_proc_subproc) - return false; + { + sigproc_printf ("sync_proc_subproc is NULL (1)"); + return false; + } if (sync_proc_subproc->acquire (WPSP)) { lastwhat = what; return true; } if (!sync_proc_subproc) - return false; + { + sigproc_printf ("sync_proc_subproc is NULL (2)"); + return false; + } system_printf ("Couldn't aquire sync_proc_subproc for(%d,%d), %E, last %d", what, val, lastwhat); return true; @@ -312,7 +318,7 @@ proc_subproc (DWORD what, DWORD val) if (!get_proc_lock (what, val)) // Serialize access to this function { - system_printf ("couldn't get proc lock. Something is wrong."); + system_printf ("couldn't get proc lock. what %d, val %d", what, val); goto out1; } @@ -546,9 +552,7 @@ proc_terminate (void) pchildren[i].release (); } nchildren = nzombies = 0; - /* Just zero sync_proc_subproc as the delete below seems to cause - problems for older gccs. */ - sync_proc_subproc = NULL; + sync_proc_subproc = NULL; } sigproc_printf ("leaving"); } @@ -1167,9 +1171,9 @@ wait_sig (VOID *self) int sigres = sig_handle (pack.sig, *pack.mask, pack.pid, pack.tls); if (sigres <= 0) { -#ifdef DEBUGGING +#ifdef DEBUGGING2 if (!sigres) - system_printf ("Failed to arm signal %d from pid %d"); + system_printf ("Failed to arm signal %d from pid %d", pack.sig, pack.pid); #endif sigqueue.add (pack.sig, pack.pid, pack.tls);// FIXME: Shouldn't add this in !sh condition } -- 2.11.0