From d795119cbe7e421ef84df059d5cd26ddc73c31b3 Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Mon, 19 Jan 2004 23:03:43 +0000 Subject: [PATCH] * sigproc.cc (sigproc_terminate): Don't close sendsig handle when execing since we're not closing what we think we're closing. (sig_send): Improve debugging when exiting due to no_signals_available. * wincap.h (wincaps::cant_debug_dll_entry): New element. * wincap.cc: Implement above element throughout. * dcrt0.cc (initial_env): Accommodate changes necessary to allow initial debugging for systems which do not allow debugging in dll_entry. (dll_crt0_0): Add initial_env call back here. * Makefile.in (install-man): Use mandir as target for installation. * include/cygwin/version.h: Bump DLL minor number to 7 (should have been done earlier). --- winsup/cygwin/ChangeLog | 20 ++++++++++++++ winsup/cygwin/Makefile.in | 9 ++++--- winsup/cygwin/dcrt0.cc | 16 ++++++++--- winsup/cygwin/include/cygwin/version.h | 2 +- winsup/cygwin/init.cc | 37 +++++++++++++------------- winsup/cygwin/sigproc.cc | 22 ++++++++++----- winsup/cygwin/wincap.cc | 36 ++++++++++++++++--------- winsup/cygwin/wincap.h | 2 ++ 8 files changed, 99 insertions(+), 45 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index b8100186a..9309d10bc 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,23 @@ +2004-01-19 Christopher Faylor + + * sigproc.cc (sigproc_terminate): Don't close sendsig handle when + execing since we're not closing what we think we're closing. + (sig_send): Improve debugging when exiting due to no_signals_available. + + * wincap.h (wincaps::cant_debug_dll_entry): New element. + * wincap.cc: Implement above element throughout. + * dcrt0.cc (initial_env): Accommodate changes necessary to allow + initial debugging for systems which do not allow debugging in + dll_entry. + (dll_crt0_0): Add initial_env call back here. + + * Makefile.in (install-man): Use mandir as target for installation. + +2004-01-19 Christopher Faylor + + * include/cygwin/version.h: Bump DLL minor number to 7 (should have been + done earlier). + 2004-01-19 Christopher Faylor * cygwin/include/signal.h: Add copyright notice. diff --git a/winsup/cygwin/Makefile.in b/winsup/cygwin/Makefile.in index 5cd0938f4..8eba20951 100644 --- a/winsup/cygwin/Makefile.in +++ b/winsup/cygwin/Makefile.in @@ -25,6 +25,7 @@ program_transform_name:=@program_transform_name@ exec_prefix:=@exec_prefix@ bindir:=@bindir@ libdir:=@libdir@ +mandir:=@mandir@ ifeq ($(target_alias),$(host_alias)) ifeq ($(build_alias),$(host_alias)) tooldir:=$(exec_prefix) @@ -298,16 +299,16 @@ install-headers: install-man: cd $(srcdir); \ for i in `find . -type f -name '*.2'`; do \ - $(INSTALL_DATA) $$i $(tooldir)/man/man2/`basename $$i` ; \ + $(INSTALL_DATA) $$i $(mandir)/man2/`basename $$i` ; \ done; \ for i in `find . -type f -name '*.3'`; do \ - $(INSTALL_DATA) $$i $(tooldir)/man/man3/`basename $$i` ; \ + $(INSTALL_DATA) $$i $(mandir)/man3/`basename $$i` ; \ done; \ for i in `find . -type f -name '*.5'`; do \ - $(INSTALL_DATA) $$i $(tooldir)/man/man5/`basename $$i` ; \ + $(INSTALL_DATA) $$i $(mandir)/man5/`basename $$i` ; \ done; \ for i in `find . -type f -name '*.7'`; do \ - $(INSTALL_DATA) $$i $(tooldir)/man/man7/`basename $$i` ; \ + $(INSTALL_DATA) $$i $(mandir)/man7/`basename $$i` ; \ done install_target: diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc index 29d11f8e4..96b712c17 100644 --- a/winsup/cygwin/dcrt0.cc +++ b/winsup/cygwin/dcrt0.cc @@ -531,11 +531,20 @@ break_here () #endif static void -initial_env () +initial_env (bool first) { char buf[CYG_MAX_PATH + 1]; + if (!first) + /* nothing */; + else if (GetEnvironmentVariable ("CYGWIN_TESTING", buf, sizeof (buf) - 1)) + _cygwin_testing = 1; #ifdef DEBUGGING DWORD len; + static bool NO_COPY did_debugging_stuff; + if (did_debugging_stuff || (first && wincap.cant_debug_dll_entry ())) + return; + + did_debugging_stuff = true; if (GetEnvironmentVariable ("CYGWIN_SLEEP", buf, sizeof (buf) - 1)) { DWORD ms = atoi (buf); @@ -569,14 +578,13 @@ initial_env () } #endif - if (GetEnvironmentVariable ("CYGWIN_TESTING", buf, sizeof (buf) - 1)) - _cygwin_testing = 1; } void __stdcall dll_crt0_0 () { wincap.init (); + initial_env (true); char zeros[sizeof (child_proc_info->zero)] = {0}; @@ -722,7 +730,7 @@ dll_crt0_1 (char *) /* FIXME: Verify forked children get their exception handler set up ok. */ exception_list cygwin_except_entry; - initial_env (); + initial_env (false); check_sanity_and_sync (user_data); malloc_init (); diff --git a/winsup/cygwin/include/cygwin/version.h b/winsup/cygwin/include/cygwin/version.h index e8b557797..adb992432 100644 --- a/winsup/cygwin/include/cygwin/version.h +++ b/winsup/cygwin/include/cygwin/version.h @@ -42,7 +42,7 @@ details. */ changes to the DLL and is mainly informative in nature. */ #define CYGWIN_VERSION_DLL_MAJOR 1005 -#define CYGWIN_VERSION_DLL_MINOR 6 +#define CYGWIN_VERSION_DLL_MINOR 7 /* Major numbers before CYGWIN_VERSION_DLL_EPOCH are incompatible. */ diff --git a/winsup/cygwin/init.cc b/winsup/cygwin/init.cc index a85a8a270..7ad38f11b 100644 --- a/winsup/cygwin/init.cc +++ b/winsup/cygwin/init.cc @@ -28,9 +28,6 @@ static void WINAPI threadfunc_fe (VOID *arg) { _threadinfo::call ((DWORD (*) (void *, void *)) (((char **) _tlsbase)[OLDFUNC_OFFSET]), arg); - // void *threadfunc = (void *) TlsGetValue (tls_func); - // TlsFree (tls_func); - // _threadinfo::call ((DWORD (*) (void *, void *)) (threadfunc), arg); } static DWORD WINAPI @@ -39,6 +36,25 @@ calibration_thread (VOID *arg) ExitThread (0); } +/* We need to know where the OS stores the address of the thread function + on the stack so that we can intercept the call and insert some tls + stuff on the stack. This function starts a known calibration thread. + When it starts, a call will be made to dll_entry which will call munge_threadfunc + looking for the calibration thread offset on the stack. This offset will + be stored and used by all executing cygwin processes. */ +void +prime_threads () +{ + if (!threadfunc_ix) + { + DWORD id; + search_for = (char *) calibration_thread; + sync_startup = CreateThread (NULL, 0, calibration_thread, 0, 0, &id); + } +} + +/* If possible, redirect the thread entry point to a cygwin routine which + adds tls stuff to the stack. */ static void munge_threadfunc (HANDLE cygwin_hmodule) { @@ -71,18 +87,6 @@ foundit: } } -void -prime_threads () -{ - // tls_func = TlsAlloc (); - if (!threadfunc_ix) - { - DWORD id; - search_for = (char *) calibration_thread; - sync_startup = CreateThread (NULL, 0, calibration_thread, 0, 0, &id); - } -} - extern void __stdcall dll_crt0_0 (); extern "C" int WINAPI @@ -93,15 +97,12 @@ dll_entry (HANDLE h, DWORD reason, void *static_load) case DLL_PROCESS_ATTACH: prime_threads (); dynamically_loaded = (static_load == NULL); - // __cygwin_user_data.impure_ptr = &_my_tls.local_clib; dll_crt0_0 (); - // small_printf ("%u, %p, %p\n", cygwin_pid (GetCurrentProcessId ()), _tlstop, _tlsbase); break; case DLL_PROCESS_DETACH: break; case DLL_THREAD_ATTACH: munge_threadfunc (h); - // small_printf ("%u, %p, %p\n", cygwin_pid (GetCurrentProcessId ()), _tlstop, _tlsbase); break; case DLL_THREAD_DETACH: _my_tls.remove (0); diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc index a1c2d305d..56aa2805b 100644 --- a/winsup/cygwin/sigproc.cc +++ b/winsup/cygwin/sigproc.cc @@ -633,6 +633,7 @@ sigproc_init () void __stdcall sigproc_terminate (void) { + extern HANDLE hExeced; hwait_sig = NULL; if (myself->sendsig == INVALID_HANDLE_VALUE) @@ -642,9 +643,12 @@ sigproc_terminate (void) sigproc_printf ("entering"); // finished with anything it is doing ForceCloseHandle (sigcomplete_main); - HANDLE sendsig = myself->sendsig; - myself->sendsig = INVALID_HANDLE_VALUE; - CloseHandle (sendsig); + if (!hExeced) + { + HANDLE sendsig = myself->sendsig; + myself->sendsig = INVALID_HANDLE_VALUE; + CloseHandle (sendsig); + } } proc_terminate (); // Terminate process handling thread @@ -680,7 +684,11 @@ sig_send (_pinfo *p, siginfo_t& si, _threadinfo *tls) else { if (no_signals_available ()) - goto out; // Either exiting or not yet initializing + { + sigproc_printf ("hwait_sig %p, myself->sendsig %p, exit_state %d", + hwait_sig, myself->sendsig, exit_state); + goto out; // Either exiting or not yet initializing + } if (wait_sig_inited) wait_for_sigthread (); wait_for_completion = p != myself_nowait && _my_tls.isinitialized (); @@ -697,8 +705,6 @@ sig_send (_pinfo *p, siginfo_t& si, _threadinfo *tls) goto out; } - sigproc_printf ("pid %d, signal %d, its_me %d", p->pid, si.si_signo, its_me); - if (its_me) { sendsig = myself->sendsig; @@ -727,6 +733,8 @@ sig_send (_pinfo *p, siginfo_t& si, _threadinfo *tls) pack.wakeup = NULL; } + sigproc_printf ("sendsig %p, pid %d, signal %d, its_me %d", sendsig, p->pid, si.si_signo, its_me); + sigset_t pending; if (!its_me) pack.mask = NULL; @@ -1104,6 +1112,8 @@ wait_sig (VOID *self) exception_list el; _my_tls.init_threadlist_exceptions (&el); + debug_printf ("entering ReadFile loop, readsig %p, myself->sendsig %p", + readsig, myself->sendsig); for (;;) { diff --git a/winsup/cygwin/wincap.cc b/winsup/cygwin/wincap.cc index 379b6343c..8b720cbc6 100644 --- a/winsup/cygwin/wincap.cc +++ b/winsup/cygwin/wincap.cc @@ -51,7 +51,8 @@ static NO_COPY wincaps wincap_unknown = { needs_memory_protection:false, pty_needs_alloc_console:false, has_terminal_services:false, - has_switch_to_thread:false + has_switch_to_thread:false, + cant_debug_dll_entry:false }; static NO_COPY wincaps wincap_95 = { @@ -94,7 +95,8 @@ static NO_COPY wincaps wincap_95 = { needs_memory_protection:false, pty_needs_alloc_console:false, has_terminal_services:false, - has_switch_to_thread:false + has_switch_to_thread:false, + cant_debug_dll_entry:true }; static NO_COPY wincaps wincap_95osr2 = { @@ -137,7 +139,8 @@ static NO_COPY wincaps wincap_95osr2 = { needs_memory_protection:false, pty_needs_alloc_console:false, has_terminal_services:false, - has_switch_to_thread:false + has_switch_to_thread:false, + cant_debug_dll_entry:true }; static NO_COPY wincaps wincap_98 = { @@ -180,7 +183,8 @@ static NO_COPY wincaps wincap_98 = { needs_memory_protection:false, pty_needs_alloc_console:false, has_terminal_services:false, - has_switch_to_thread:false + has_switch_to_thread:false, + cant_debug_dll_entry:true }; static NO_COPY wincaps wincap_98se = { @@ -223,7 +227,8 @@ static NO_COPY wincaps wincap_98se = { needs_memory_protection:false, pty_needs_alloc_console:false, has_terminal_services:false, - has_switch_to_thread:false + has_switch_to_thread:false, + cant_debug_dll_entry:true }; static NO_COPY wincaps wincap_me = { @@ -266,7 +271,8 @@ static NO_COPY wincaps wincap_me = { needs_memory_protection:false, pty_needs_alloc_console:false, has_terminal_services:false, - has_switch_to_thread:false + has_switch_to_thread:false, + cant_debug_dll_entry:true }; static NO_COPY wincaps wincap_nt3 = { @@ -309,7 +315,8 @@ static NO_COPY wincaps wincap_nt3 = { needs_memory_protection:true, pty_needs_alloc_console:true, has_terminal_services:false, - has_switch_to_thread:false + has_switch_to_thread:false, + cant_debug_dll_entry:false }; static NO_COPY wincaps wincap_nt4 = { @@ -352,7 +359,8 @@ static NO_COPY wincaps wincap_nt4 = { needs_memory_protection:true, pty_needs_alloc_console:true, has_terminal_services:false, - has_switch_to_thread:true + has_switch_to_thread:true, + cant_debug_dll_entry:false }; static NO_COPY wincaps wincap_nt4sp4 = { @@ -395,7 +403,8 @@ static NO_COPY wincaps wincap_nt4sp4 = { needs_memory_protection:true, pty_needs_alloc_console:true, has_terminal_services:false, - has_switch_to_thread:true + has_switch_to_thread:true, + cant_debug_dll_entry:false }; static NO_COPY wincaps wincap_2000 = { @@ -438,7 +447,8 @@ static NO_COPY wincaps wincap_2000 = { needs_memory_protection:true, pty_needs_alloc_console:true, has_terminal_services:true, - has_switch_to_thread:true + has_switch_to_thread:true, + cant_debug_dll_entry:false }; static NO_COPY wincaps wincap_xp = { @@ -481,7 +491,8 @@ static NO_COPY wincaps wincap_xp = { needs_memory_protection:true, pty_needs_alloc_console:true, has_terminal_services:true, - has_switch_to_thread:true + has_switch_to_thread:true, + cant_debug_dll_entry:false }; static NO_COPY wincaps wincap_2003 = { @@ -524,7 +535,8 @@ static NO_COPY wincaps wincap_2003 = { needs_memory_protection:true, pty_needs_alloc_console:true, has_terminal_services:true, - has_switch_to_thread:true + has_switch_to_thread:true, + cant_debug_dll_entry:false }; wincapc wincap; diff --git a/winsup/cygwin/wincap.h b/winsup/cygwin/wincap.h index 320b75916..66ab87e27 100644 --- a/winsup/cygwin/wincap.h +++ b/winsup/cygwin/wincap.h @@ -53,6 +53,7 @@ struct wincaps unsigned pty_needs_alloc_console : 1; unsigned has_terminal_services : 1; unsigned has_switch_to_thread : 1; + unsigned cant_debug_dll_entry : 1; }; class wincapc @@ -110,6 +111,7 @@ public: bool IMPLEMENT (pty_needs_alloc_console) bool IMPLEMENT (has_terminal_services) bool IMPLEMENT (has_switch_to_thread) + bool IMPLEMENT (cant_debug_dll_entry) #undef IMPLEMENT };