From e2bc5017fa996b7de73821db61b14c2d552bfc06 Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Thu, 28 Aug 2003 02:04:16 +0000 Subject: [PATCH] * syscalls.cc (mount): Don't check win32_path when doing cygdrive mount. --- winsup/cygwin/ChangeLog | 5 +++++ winsup/cygwin/autoload.cc | 1 + winsup/cygwin/cygthread.h | 2 +- winsup/cygwin/exceptions.cc | 34 ++++++++++++++-------------------- winsup/cygwin/miscfuncs.cc | 30 +++++++++++++++++++++++------- winsup/cygwin/path.cc | 5 ++--- winsup/cygwin/sigproc.cc | 1 - winsup/cygwin/wincap.cc | 36 ++++++++++++++++++++++++------------ winsup/cygwin/wincap.h | 2 ++ 9 files changed, 72 insertions(+), 44 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index e9263631e..a73e5f0c3 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,8 @@ +2003-08-27 Christopher Faylor + + * syscalls.cc (mount): Don't check win32_path when doing cygdrive + mount. + 2003-08-27 Christopher Faylor * specdir: Correctly remove temporary directory prior to use. diff --git a/winsup/cygwin/autoload.cc b/winsup/cygwin/autoload.cc index f5cc250fa..c2c7ae352 100644 --- a/winsup/cygwin/autoload.cc +++ b/winsup/cygwin/autoload.cc @@ -510,6 +510,7 @@ LoadDLLfunc (IsProcessorFeaturePresent, 4, kernel32); LoadDLLfuncEx (Process32First, 8, kernel32, 1) LoadDLLfuncEx (Process32Next, 8, kernel32, 1) LoadDLLfuncEx (SignalObjectAndWait, 16, kernel32, 1) +LoadDLLfuncEx (SwitchToThread, 0, kernel32, 1) LoadDLLfunc (TryEnterCriticalSection, 4, kernel32) LoadDLLfuncEx (waveOutGetNumDevs, 0, winmm, 1) diff --git a/winsup/cygwin/cygthread.h b/winsup/cygwin/cygthread.h index 57b50e20a..b8566d4c7 100644 --- a/winsup/cygwin/cygthread.h +++ b/winsup/cygwin/cygthread.h @@ -18,12 +18,12 @@ class cygthread LPTHREAD_START_ROUTINE func; VOID *arg; bool is_freerange; - static DWORD main_thread_id; static bool exiting; static DWORD WINAPI stub (VOID *); static DWORD WINAPI simplestub (VOID *); void terminate_thread (); public: + static DWORD main_thread_id; static const char * name (DWORD = 0); cygthread (LPTHREAD_START_ROUTINE, LPVOID, const char *); cygthread () {}; diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc index 173216525..ae2c400a6 100644 --- a/winsup/cygwin/exceptions.cc +++ b/winsup/cygwin/exceptions.cc @@ -785,10 +785,9 @@ setup_handler (int sig, void *handler, struct sigaction& siga) CONTEXT cx; bool interrupted = false; sigthread *th = NULL; // Initialization needed to shut up gcc - int prio = INFINITE; if (sigsave.sig) - goto set_pending; + goto out; for (int i = 0; i < CALL_HANDLER_RETRY; i++) { @@ -823,7 +822,18 @@ setup_handler (int sig, void *handler, struct sigaction& siga) SuspendThread on itself then just queue the signal. */ EnterCriticalSection (&mainthread.lock); +#ifndef DEBUGGING sigproc_printf ("suspending mainthread"); +#else + cx.ContextFlags = CONTEXT_CONTROL | CONTEXT_INTEGER; + if (!GetThreadContext (hth, &cx)) + memset (&cx, 0, sizeof cx); +#if 0 + if ((cx.Eip & 0xff000000) == 0x77000000) + try_to_debug (); +#endif + sigproc_printf ("suspending mainthread PC %p", cx.Eip); +#endif res = SuspendThread (hth); /* Just release the lock now since we hav suspended the main thread and it definitely can't be grabbing it now. This will have to change, of course, @@ -866,13 +876,6 @@ setup_handler (int sig, void *handler, struct sigaction& siga) } } - if ((DWORD) prio != INFINITE) - { - /* Reset the priority so we can finish this off quickly. */ - SetThreadPriority (GetCurrentThread (), WAIT_SIG_PRIORITY); - prio = INFINITE; - } - if (th) { interrupted = interrupt_on_return (th, sig, handler, siga); @@ -888,20 +891,11 @@ setup_handler (int sig, void *handler, struct sigaction& siga) if (interrupted) break; - if ((DWORD) prio != INFINITE && !mainthread.frame) - prio = low_priority_sleep (SLEEP_0_STAY_LOW); sigproc_printf ("couldn't interrupt. trying again."); } - set_pending: - if (interrupted) - { - if ((DWORD) prio != INFINITE) - SetThreadPriority (GetCurrentThread (), WAIT_SIG_PRIORITY); - sigproc_printf ("signal successfully delivered"); - } - - sigproc_printf ("returning %d", interrupted); +out: + sigproc_printf ("signal %d %sdelivered", sig, interrupted ? "" : "not "); return interrupted; } #endif /* i386 */ diff --git a/winsup/cygwin/miscfuncs.cc b/winsup/cygwin/miscfuncs.cc index fea1b1249..d9e4a7adb 100644 --- a/winsup/cygwin/miscfuncs.cc +++ b/winsup/cygwin/miscfuncs.cc @@ -8,6 +8,7 @@ This software is a copyrighted work licensed under the terms of the Cygwin license. Please consult the file "CYGWIN_LICENSE" for details. */ +#define _WIN32_WINNT 0x400 #include "winsup.h" #include "cygerrno.h" #include @@ -16,6 +17,7 @@ details. */ #include #include #include +#include "cygthread.h" long tls_ix = -1; @@ -306,13 +308,27 @@ low_priority_sleep (DWORD secs) staylow = true; } - int main_prio = GetThreadPriority (hMainThread); - if (curr_prio != main_prio) - /* Force any threads in normal priority to be scheduled */ - SetThreadPriority (thisthread, main_prio); - Sleep (secs); + if (!secs && wincap.has_switch_to_thread ()) + { + for (int i = 0; i < 10; i++) + SwitchToThread (); + } + else + { + int new_prio; + if (GetCurrentThreadId () == cygthread::main_thread_id) + new_prio = THREAD_PRIORITY_LOWEST; + else + new_prio = GetThreadPriority (hMainThread); + + if (curr_prio != new_prio) + /* Force any threads in normal priority to be scheduled */ + SetThreadPriority (thisthread, new_prio); + Sleep (secs); + + if (!staylow || curr_prio == new_prio) + SetThreadPriority (thisthread, curr_prio); + } - if (!staylow || curr_prio == main_prio) - SetThreadPriority (thisthread, curr_prio); return curr_prio; } diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc index 15b3f861e..26b6aa82f 100644 --- a/winsup/cygwin/path.cc +++ b/winsup/cygwin/path.cc @@ -2592,8 +2592,7 @@ mount (const char *win32_path, const char *posix_path, unsigned flags) { int res = -1; - if (check_null_empty_str_errno (win32_path) - || check_null_empty_str_errno (posix_path)) + if (check_null_empty_str_errno (posix_path)) /* errno set */; else if (strpbrk (posix_path, "\\:")) set_errno (EINVAL); @@ -2605,7 +2604,7 @@ mount (const char *win32_path, const char *posix_path, unsigned flags) res = mount_table->write_cygdrive_info_to_registry (posix_path, flags); win32_path = NULL; } - else + else if (!check_null_empty_str_errno (win32_path)) res = mount_table->add_item (win32_path, posix_path, flags, TRUE); syscall_printf ("%d = mount (%s, %s, %p)", res, win32_path, posix_path, flags); diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc index 5821a09e2..4d2ce8070 100644 --- a/winsup/cygwin/sigproc.cc +++ b/winsup/cygwin/sigproc.cc @@ -1218,7 +1218,6 @@ wait_sig (VOID *self) if (!sig_handle (sig)) { saw_failed_interrupt = true; - sigproc_printf ("couldn't send signal %d", sig); x = InterlockedIncrement (myself->getsigtodo (sig)); pending_signals = true; } diff --git a/winsup/cygwin/wincap.cc b/winsup/cygwin/wincap.cc index dbc39132d..33676ee6f 100644 --- a/winsup/cygwin/wincap.cc +++ b/winsup/cygwin/wincap.cc @@ -49,7 +49,8 @@ static NO_COPY wincaps wincap_unknown = { supports_reading_modem_output_lines:false, needs_memory_protection:false, pty_needs_alloc_console:false, - has_terminal_services:false + has_terminal_services:false, + has_switch_to_thread:false }; static NO_COPY wincaps wincap_95 = { @@ -90,7 +91,8 @@ static NO_COPY wincaps wincap_95 = { supports_reading_modem_output_lines:false, needs_memory_protection:false, pty_needs_alloc_console:false, - has_terminal_services:false + has_terminal_services:false, + has_switch_to_thread:false }; static NO_COPY wincaps wincap_95osr2 = { @@ -131,7 +133,8 @@ static NO_COPY wincaps wincap_95osr2 = { supports_reading_modem_output_lines:false, needs_memory_protection:false, pty_needs_alloc_console:false, - has_terminal_services:false + has_terminal_services:false, + has_switch_to_thread:false }; static NO_COPY wincaps wincap_98 = { @@ -172,7 +175,8 @@ static NO_COPY wincaps wincap_98 = { supports_reading_modem_output_lines:false, needs_memory_protection:false, pty_needs_alloc_console:false, - has_terminal_services:false + has_terminal_services:false, + has_switch_to_thread:false }; static NO_COPY wincaps wincap_98se = { @@ -213,7 +217,8 @@ static NO_COPY wincaps wincap_98se = { supports_reading_modem_output_lines:false, needs_memory_protection:false, pty_needs_alloc_console:false, - has_terminal_services:false + has_terminal_services:false, + has_switch_to_thread:false }; static NO_COPY wincaps wincap_me = { @@ -254,7 +259,8 @@ static NO_COPY wincaps wincap_me = { supports_reading_modem_output_lines:false, needs_memory_protection:false, pty_needs_alloc_console:false, - has_terminal_services:false + has_terminal_services:false, + has_switch_to_thread:false }; static NO_COPY wincaps wincap_nt3 = { @@ -295,7 +301,8 @@ static NO_COPY wincaps wincap_nt3 = { supports_reading_modem_output_lines:true, needs_memory_protection:true, pty_needs_alloc_console:true, - has_terminal_services:false + has_terminal_services:false, + has_switch_to_thread:false }; static NO_COPY wincaps wincap_nt4 = { @@ -336,7 +343,8 @@ static NO_COPY wincaps wincap_nt4 = { supports_reading_modem_output_lines:true, needs_memory_protection:true, pty_needs_alloc_console:true, - has_terminal_services:false + has_terminal_services:false, + has_switch_to_thread:true }; static NO_COPY wincaps wincap_nt4sp4 = { @@ -377,7 +385,8 @@ static NO_COPY wincaps wincap_nt4sp4 = { supports_reading_modem_output_lines:true, needs_memory_protection:true, pty_needs_alloc_console:true, - has_terminal_services:false + has_terminal_services:false, + has_switch_to_thread:true }; static NO_COPY wincaps wincap_2000 = { @@ -418,7 +427,8 @@ static NO_COPY wincaps wincap_2000 = { supports_reading_modem_output_lines:true, needs_memory_protection:true, pty_needs_alloc_console:true, - has_terminal_services:true + has_terminal_services:true, + has_switch_to_thread:true }; static NO_COPY wincaps wincap_xp = { @@ -459,7 +469,8 @@ static NO_COPY wincaps wincap_xp = { supports_reading_modem_output_lines:true, needs_memory_protection:true, pty_needs_alloc_console:true, - has_terminal_services:true + has_terminal_services:true, + has_switch_to_thread:true }; static NO_COPY wincaps wincap_2003 = { @@ -500,7 +511,8 @@ static NO_COPY wincaps wincap_2003 = { supports_reading_modem_output_lines:true, needs_memory_protection:true, pty_needs_alloc_console:true, - has_terminal_services:true + has_terminal_services:true, + has_switch_to_thread:true }; wincapc wincap; diff --git a/winsup/cygwin/wincap.h b/winsup/cygwin/wincap.h index b1f43d6ef..faf246906 100644 --- a/winsup/cygwin/wincap.h +++ b/winsup/cygwin/wincap.h @@ -51,6 +51,7 @@ struct wincaps unsigned needs_memory_protection : 1; unsigned pty_needs_alloc_console : 1; unsigned has_terminal_services : 1; + unsigned has_switch_to_thread : 1; }; class wincapc @@ -106,6 +107,7 @@ public: bool IMPLEMENT (needs_memory_protection) bool IMPLEMENT (pty_needs_alloc_console) bool IMPLEMENT (has_terminal_services) + bool IMPLEMENT (has_switch_to_thread) #undef IMPLEMENT };