aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2004-12-28 01:27:26 +0000
committerChristopher Faylor <me@cgf.cx>2004-12-28 01:27:26 +0000
commit57ba174fa0fd038154f5f24a32cad566796ee2a6 (patch)
tree2ec65739c0f0ddbf83d1a22d7b1ca635c65c594d
parent432524c16251a6d40716978ac4d0eb1188b1256a (diff)
downloadnewlib-57ba174fa0fd038154f5f24a32cad566796ee2a6.zip
newlib-57ba174fa0fd038154f5f24a32cad566796ee2a6.tar.gz
newlib-57ba174fa0fd038154f5f24a32cad566796ee2a6.tar.bz2
* cygthread.cc (cygthread::stub): Add better debug output.
(cygthread::cygthread): Ditto. (cygthread::terminate_thread): Ditto. Move inuse test earlier or suffer infinite loop. * pinfo.cc (_pinfo::dup_proc_pipe): Close handle if DuplicateHandle fails and process no longer exists. * spawn.cc (spawn_guts): Create process in suspended state if OS demands it. * wincap.cc: Add "start_proc_suspended" throughout. * wincap.h (wincaps): Ditto. (wincapc): Ditto.
-rw-r--r--winsup/cygwin/ChangeLog14
-rw-r--r--winsup/cygwin/cygthread.cc16
-rw-r--r--winsup/cygwin/pinfo.cc8
-rw-r--r--winsup/cygwin/spawn.cc3
-rw-r--r--winsup/cygwin/wincap.cc36
-rw-r--r--winsup/cygwin/wincap.h2
6 files changed, 58 insertions, 21 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 0a483f1..f8136b1 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,5 +1,19 @@
2004-12-27 Christopher Faylor <cgf@timesys.com>
+ * cygthread.cc (cygthread::stub): Add better debug output.
+ (cygthread::cygthread): Ditto.
+ (cygthread::terminate_thread): Ditto. Move inuse test earlier or
+ suffer infinite loop.
+ * pinfo.cc (_pinfo::dup_proc_pipe): Close handle if DuplicateHandle
+ fails and process no longer exists.
+ * spawn.cc (spawn_guts): Create process in suspended state if OS
+ demands it.
+ * wincap.cc: Add "start_proc_suspended" throughout.
+ * wincap.h (wincaps): Ditto.
+ (wincapc): Ditto.
+
+2004-12-27 Christopher Faylor <cgf@timesys.com>
+
* pinfo.cc (_pinfo::exit): Beef up debugging output.
* sigproc.cc (proc_subproc): Detached children apparently need a ppid
of 1.
diff --git a/winsup/cygwin/cygthread.cc b/winsup/cygwin/cygthread.cc
index 20f51d5..55022f3 100644
--- a/winsup/cygwin/cygthread.cc
+++ b/winsup/cygwin/cygthread.cc
@@ -45,6 +45,7 @@ cygthread::stub (VOID *arg)
else
{
info->stack_ptr = &arg;
+ debug_printf ("thread '%s', id %p, stack_ptr %p", info->name (), info->id, info->stack_ptr);
if (!info->ev)
{
info->ev = CreateEvent (&sec_none_nih, TRUE, FALSE, NULL);
@@ -166,7 +167,7 @@ cygthread::cygthread (LPTHREAD_START_ROUTINE start, LPVOID param,
while (!thread_sync)
low_priority_sleep (0);
SetEvent (thread_sync);
- thread_printf ("activated thread_sync %p", thread_sync);
+ thread_printf ("activated name '%s', thread_sync %p for thread %p", thread_sync, id);
}
else
{
@@ -179,7 +180,7 @@ cygthread::cygthread (LPTHREAD_START_ROUTINE start, LPVOID param,
this, 0, &id);
if (!h)
api_fatal ("thread handle not set - %p<%p>, %E", h, id);
- thread_printf ("created thread %p", h);
+ thread_printf ("created name '%s', thread %p, id %p", __name, h, id);
#ifdef DEBUGGING
terminated = false;
#endif
@@ -268,18 +269,21 @@ cygthread::terminate_thread ()
ResetEvent (*this);
ResetEvent (thread_sync);
}
+
+ debug_printf ("thread '%s', id %p, inuse %d, stack_ptr %p", name (), id, inuse, stack_ptr);
+ while (inuse && !stack_ptr)
+ low_priority_sleep (0);
+
if (!inuse)
return;
+
(void) TerminateThread (h, 0);
(void) WaitForSingleObject (h, INFINITE);
- if (!inuse)
+ if (!inuse || exiting)
return;
CloseHandle (h);
- while (inuse && !stack_ptr)
- low_priority_sleep (0);
-
if (!inuse)
return;
diff --git a/winsup/cygwin/pinfo.cc b/winsup/cygwin/pinfo.cc
index 1137575..edeb35e 100644
--- a/winsup/cygwin/pinfo.cc
+++ b/winsup/cygwin/pinfo.cc
@@ -128,7 +128,7 @@ _pinfo::exit (UINT n, bool norecord)
}
}
- sigproc_printf ("Calling ExitProcess norecord %d, n %d, exitcode %d",
+ sigproc_printf ("Calling ExitProcess norecord %d, n %p, exitcode %p",
norecord, n, exitcode);
_my_tls.stacklock = 0;
_my_tls.stackptr = _my_tls.stack;
@@ -768,7 +768,11 @@ _pinfo::dup_proc_pipe (HANDLE hProcess)
0, FALSE,
DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
if (!res)
- sigproc_printf ("DuplicateHandle failed, pid %d, hProcess %p, %E", pid, hProcess);
+ {
+ if (WaitForSingleObject (hProcess, 0) == WAIT_OBJECT_0)
+ CloseHandle (wr_proc_pipe);
+ sigproc_printf ("DuplicateHandle failed, pid %d, hProcess %p, %E", pid, hProcess);
+ }
else
{
wr_proc_pipe_owner = dwProcessId;
diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc
index 3fcf92c..e18b3e2 100644
--- a/winsup/cygwin/spawn.cc
+++ b/winsup/cygwin/spawn.cc
@@ -645,7 +645,8 @@ spawn_guts (const char * prog_arg, const char *const *argv,
after CreateProcess and before copying the datastructures to the child.
So we have to start the child in suspend state, unfortunately, to avoid
a race condition. */
- if (mode != _P_OVERLAY || cygheap->fdtab.need_fixup_before ())
+ if (wincap.start_proc_suspended() || mode != _P_OVERLAY
+ || cygheap->fdtab.need_fixup_before ())
flags |= CREATE_SUSPENDED;
const char *runpath = null_app_name ? NULL : (const char *) real_path;
diff --git a/winsup/cygwin/wincap.cc b/winsup/cygwin/wincap.cc
index 0a93070..eb49812 100644
--- a/winsup/cygwin/wincap.cc
+++ b/winsup/cygwin/wincap.cc
@@ -53,7 +53,8 @@ static NO_COPY wincaps wincap_unknown = {
has_terminal_services:false,
has_switch_to_thread:false,
cant_debug_dll_entry:false,
- has_ioctl_storage_get_media_types_ex:false
+ has_ioctl_storage_get_media_types_ex:false,
+ start_proc_suspended:true
};
static NO_COPY wincaps wincap_95 = {
@@ -98,7 +99,8 @@ static NO_COPY wincaps wincap_95 = {
has_terminal_services:false,
has_switch_to_thread:false,
cant_debug_dll_entry:true,
- has_ioctl_storage_get_media_types_ex:false
+ has_ioctl_storage_get_media_types_ex:false,
+ start_proc_suspended:true
};
static NO_COPY wincaps wincap_95osr2 = {
@@ -143,7 +145,8 @@ static NO_COPY wincaps wincap_95osr2 = {
has_terminal_services:false,
has_switch_to_thread:false,
cant_debug_dll_entry:true,
- has_ioctl_storage_get_media_types_ex:false
+ has_ioctl_storage_get_media_types_ex:false,
+ start_proc_suspended:true
};
static NO_COPY wincaps wincap_98 = {
@@ -188,7 +191,8 @@ static NO_COPY wincaps wincap_98 = {
has_terminal_services:false,
has_switch_to_thread:false,
cant_debug_dll_entry:true,
- has_ioctl_storage_get_media_types_ex:false
+ has_ioctl_storage_get_media_types_ex:false,
+ start_proc_suspended:true
};
static NO_COPY wincaps wincap_98se = {
@@ -233,7 +237,8 @@ static NO_COPY wincaps wincap_98se = {
has_terminal_services:false,
has_switch_to_thread:false,
cant_debug_dll_entry:true,
- has_ioctl_storage_get_media_types_ex:false
+ has_ioctl_storage_get_media_types_ex:false,
+ start_proc_suspended:true
};
static NO_COPY wincaps wincap_me = {
@@ -278,7 +283,8 @@ static NO_COPY wincaps wincap_me = {
has_terminal_services:false,
has_switch_to_thread:false,
cant_debug_dll_entry:true,
- has_ioctl_storage_get_media_types_ex:false
+ has_ioctl_storage_get_media_types_ex:false,
+ start_proc_suspended:true
};
static NO_COPY wincaps wincap_nt3 = {
@@ -323,7 +329,8 @@ static NO_COPY wincaps wincap_nt3 = {
has_terminal_services:false,
has_switch_to_thread:false,
cant_debug_dll_entry:false,
- has_ioctl_storage_get_media_types_ex:false
+ has_ioctl_storage_get_media_types_ex:false,
+ start_proc_suspended:false
};
static NO_COPY wincaps wincap_nt4 = {
@@ -368,7 +375,8 @@ static NO_COPY wincaps wincap_nt4 = {
has_terminal_services:false,
has_switch_to_thread:true,
cant_debug_dll_entry:false,
- has_ioctl_storage_get_media_types_ex:false
+ has_ioctl_storage_get_media_types_ex:false,
+ start_proc_suspended:false
};
static NO_COPY wincaps wincap_nt4sp4 = {
@@ -413,7 +421,8 @@ static NO_COPY wincaps wincap_nt4sp4 = {
has_terminal_services:false,
has_switch_to_thread:true,
cant_debug_dll_entry:false,
- has_ioctl_storage_get_media_types_ex:false
+ has_ioctl_storage_get_media_types_ex:false,
+ start_proc_suspended:false
};
static NO_COPY wincaps wincap_2000 = {
@@ -458,7 +467,8 @@ static NO_COPY wincaps wincap_2000 = {
has_terminal_services:true,
has_switch_to_thread:true,
cant_debug_dll_entry:false,
- has_ioctl_storage_get_media_types_ex:false
+ has_ioctl_storage_get_media_types_ex:false,
+ start_proc_suspended:false
};
static NO_COPY wincaps wincap_xp = {
@@ -503,7 +513,8 @@ static NO_COPY wincaps wincap_xp = {
has_terminal_services:true,
has_switch_to_thread:true,
cant_debug_dll_entry:false,
- has_ioctl_storage_get_media_types_ex:true
+ has_ioctl_storage_get_media_types_ex:true,
+ start_proc_suspended:false
};
static NO_COPY wincaps wincap_2003 = {
@@ -548,7 +559,8 @@ static NO_COPY wincaps wincap_2003 = {
has_terminal_services:true,
has_switch_to_thread:true,
cant_debug_dll_entry:false,
- has_ioctl_storage_get_media_types_ex:true
+ has_ioctl_storage_get_media_types_ex:true,
+ start_proc_suspended:false
};
wincapc wincap;
diff --git a/winsup/cygwin/wincap.h b/winsup/cygwin/wincap.h
index cdda1d8..eb9c5ba 100644
--- a/winsup/cygwin/wincap.h
+++ b/winsup/cygwin/wincap.h
@@ -55,6 +55,7 @@ struct wincaps
unsigned has_switch_to_thread : 1;
unsigned cant_debug_dll_entry : 1;
unsigned has_ioctl_storage_get_media_types_ex : 1;
+ unsigned start_proc_suspended : 1;
};
class wincapc
@@ -114,6 +115,7 @@ public:
bool IMPLEMENT (has_switch_to_thread)
bool IMPLEMENT (cant_debug_dll_entry)
bool IMPLEMENT (has_ioctl_storage_get_media_types_ex)
+ bool IMPLEMENT (start_proc_suspended)
#undef IMPLEMENT
};