aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2004-01-17 04:13:21 +0000
committerChristopher Faylor <me@cgf.cx>2004-01-17 04:13:21 +0000
commit80a2f7b116869e2c3428d679294d0a401e77e977 (patch)
treeef5541ea9556fa1da0c468bf7d2a4f5b9af4e64f
parent528874e24ea81be8a827b25d6446828aafd8b84e (diff)
downloadnewlib-80a2f7b116869e2c3428d679294d0a401e77e977.zip
newlib-80a2f7b116869e2c3428d679294d0a401e77e977.tar.gz
newlib-80a2f7b116869e2c3428d679294d0a401e77e977.tar.bz2
* cygtls.h (_threadinfo::threadkill): New element.
(_threadinfo::set_threadkill): Declare new function. (_threadinfo::reset_threadkill): Declare new function. * dcrt0.cc (dcrt0_1): Call here so that it will be possible to attach to running process with #(*& Windows Me/9x. (initial_env): Try to initialize strace if uninitialized. * gendef: Don't zero signal if threadkill is set since that will happen in the called function. * signal.cc (sigwait): Ensure cleanup in error conditions. * sigproc.cc (sig_send): Clear packet mask storage. (wait_subproc): Fill in child exit code in siginfo_t structure. * thread.cc (pthread_kill): Set threadkill flag. * tlsoffsets.h: Regenerate. Throughout, use siginfo_t to fill out all signal information for "kernel" signals. * cygtls.h (_threadinfo::set_siginfo): Declare new function. * cygtls.cc (_threadinfo::set_siginfo): Define new function. * dcrt0.cc (do_exit): Accommodate siginfo_t considerations. * exceptions.cc (handle_exceptions): Ditto. (sig_handle_tty_stop): Ditto. (ctrl_c_handler): Use killsys() to send signal. (sigpacket::process): Rename from sig_handle. Use siginfo_t field from sigpacket for everything. (tty_min::kill_pgrp): Accommodate siginfo_t considerations. (fhandler_termios::bg_check): Ditto. * fhandler_tty.cc (fhandler_tty_slave::ioctl): Use killsys() to send signal. * signal.cc (kill_worker): Rewrite to use siginfo_t second argument. (kill_pgrp): Ditto. (kill0): Define new function pulled from kill(). (kill): Rewrite as frontend to kill0. (killsys): Define new function. * sigproc.cc (sigelem): Eliminate. (sigpacket): Move to sigproc.h. Subsume sigelem. (pending_signals): Use sigpacket rather than sigelem for everything. (sig_clear): Ditto. (wait_sig): Ditto. (sig_send): Rewrite to use siginfo_t argument. (sig_send): New function wratpper to sig_send with siginfo_t argument. (wait_subproc): Accommodate siginfo_t considerations. * thread.cc (pthread_kill): Ditto. * sigproc.h (sigpacket): Move here. (sigpacket::process): Declare "new" function. (sig_handle): Eliminate declaration. (sig_send): Declare with new paramaters. (killsys): Declare new function. (kill_pgrp): Declare. * winsup.h: Move some signal-specific stuff to sigproc.h. * include/cygwin/signal.h: Tweak some siginfo_t stuff. * fhandler_console.cc (fhandler_console::close): Remove obsolete test for vfork_cleanup. * pipe.cc (fhandler_pipe::close): Add comment. * cygheap.cc (init_cygheap::close_ctty): Don't NULL ctty if it is still active. * dtable.cc (dtable::vfork_parent_restore): Store ctty_on_hold prior to calling close_all_files since it will be zeroed.
-rw-r--r--winsup/cygwin/ChangeLog70
-rw-r--r--winsup/cygwin/cygheap.cc7
-rw-r--r--winsup/cygwin/cygtls.h3
-rw-r--r--winsup/cygwin/dcrt0.cc10
-rw-r--r--winsup/cygwin/dtable.cc4
-rw-r--r--winsup/cygwin/dtable.h3
-rw-r--r--winsup/cygwin/exceptions.cc1
-rw-r--r--winsup/cygwin/fhandler_console.cc3
-rwxr-xr-xwinsup/cygwin/gendef4
-rw-r--r--winsup/cygwin/include/cygwin/signal.h2
-rw-r--r--winsup/cygwin/pipe.cc3
-rw-r--r--winsup/cygwin/signal.cc15
-rw-r--r--winsup/cygwin/sigproc.cc10
-rw-r--r--winsup/cygwin/syscalls.cc2
-rw-r--r--winsup/cygwin/thread.cc1
-rw-r--r--winsup/cygwin/tlsoffsets.h50
-rw-r--r--winsup/cygwin/winsup.h2
17 files changed, 146 insertions, 44 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 16aa73f..bb39a3d 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,3 +1,73 @@
+2004-01-16 Christopher Faylor <cgf@redhat.com>
+
+ * cygtls.h (_threadinfo::threadkill): New element.
+ (_threadinfo::set_threadkill): Declare new function.
+ (_threadinfo::reset_threadkill): Declare new function.
+ * dcrt0.cc (dcrt0_1): Call here so that it will be possible to attach
+ to running process with #(*& Windows Me/9x.
+ (initial_env): Try to initialize strace if uninitialized.
+ * gendef: Don't zero signal if threadkill is set since that will happen
+ in the called function.
+ * signal.cc (sigwait): Ensure cleanup in error conditions.
+ * sigproc.cc (sig_send): Clear packet mask storage.
+ (wait_subproc): Fill in child exit code in siginfo_t structure.
+ * thread.cc (pthread_kill): Set threadkill flag.
+ * tlsoffsets.h: Regenerate.
+
+2004-01-16 Christopher Faylor <cgf@redhat.com>
+
+ Throughout, use siginfo_t to fill out all signal information for
+ "kernel" signals.
+ * cygtls.h (_threadinfo::set_siginfo): Declare new function.
+ * cygtls.cc (_threadinfo::set_siginfo): Define new function.
+ * dcrt0.cc (do_exit): Accommodate siginfo_t considerations.
+ * exceptions.cc (handle_exceptions): Ditto.
+ (sig_handle_tty_stop): Ditto.
+ (ctrl_c_handler): Use killsys() to send signal.
+ (sigpacket::process): Rename from sig_handle. Use siginfo_t field from
+ sigpacket for everything.
+ (tty_min::kill_pgrp): Accommodate siginfo_t considerations.
+ (fhandler_termios::bg_check): Ditto.
+ * fhandler_tty.cc (fhandler_tty_slave::ioctl): Use killsys() to send signal.
+ * signal.cc (kill_worker): Rewrite to use siginfo_t second argument.
+ (kill_pgrp): Ditto.
+ (kill0): Define new function pulled from kill().
+ (kill): Rewrite as frontend to kill0.
+ (killsys): Define new function.
+ * sigproc.cc (sigelem): Eliminate.
+ (sigpacket): Move to sigproc.h. Subsume sigelem.
+ (pending_signals): Use sigpacket rather than sigelem for everything.
+ (sig_clear): Ditto.
+ (wait_sig): Ditto.
+ (sig_send): Rewrite to use siginfo_t argument.
+ (sig_send): New function wratpper to sig_send with siginfo_t argument.
+ (wait_subproc): Accommodate siginfo_t considerations.
+ * thread.cc (pthread_kill): Ditto.
+ * sigproc.h (sigpacket): Move here.
+ (sigpacket::process): Declare "new" function.
+ (sig_handle): Eliminate declaration.
+ (sig_send): Declare with new paramaters.
+ (killsys): Declare new function.
+ (kill_pgrp): Declare.
+ * winsup.h: Move some signal-specific stuff to sigproc.h.
+ * include/cygwin/signal.h: Tweak some siginfo_t stuff.
+
+2004-01-16 Christopher Faylor <cgf@redhat.com>
+
+ * fhandler_console.cc (fhandler_console::close): Remove obsolete test
+ for vfork_cleanup.
+ * pipe.cc (fhandler_pipe::close): Add comment.
+
+2004-01-16 Christopher Faylor <cgf@redhat.com>
+
+ * cygheap.cc (init_cygheap::close_ctty): Don't NULL ctty if it is still
+ active.
+
+2004-01-16 Christopher Faylor <cgf@redhat.com>
+
+ * dtable.cc (dtable::vfork_parent_restore): Store ctty_on_hold prior to
+ calling close_all_files since it will be zeroed.
+
2004-01-15 Christopher Faylor <cgf@redhat.com>
* gentls_offsets: Reinstate unlink of temp files.
diff --git a/winsup/cygwin/cygheap.cc b/winsup/cygwin/cygheap.cc
index 0171f99..0e46c73 100644
--- a/winsup/cygwin/cygheap.cc
+++ b/winsup/cygwin/cygheap.cc
@@ -176,10 +176,15 @@ void
init_cygheap::close_ctty ()
{
debug_printf ("closing cygheap->ctty %p", cygheap->ctty);
+ int usecount = cygheap->ctty->usecount;
cygheap->ctty->close ();
if (cygheap->ctty_on_hold == cygheap->ctty)
cygheap->ctty_on_hold = NULL;
- cygheap->ctty = NULL;
+ if (usecount == 1)
+ {
+ cygheap->ctty = NULL;
+ debug_printf ("setting cygheap->ctty to NULL");
+ }
}
#define pagetrunc(x) ((void *) (((DWORD) (x)) & ~(4096 - 1)))
diff --git a/winsup/cygwin/cygtls.h b/winsup/cygwin/cygtls.h
index ab82bac..0fa1b1b 100644
--- a/winsup/cygwin/cygtls.h
+++ b/winsup/cygwin/cygtls.h
@@ -102,6 +102,7 @@ struct _threadinfo
sigset_t sigmask;
sigset_t sigwait_mask;
siginfo_t *sigwait_info;
+ unsigned threadkill;
siginfo_t infodata;
struct pthread *tid;
struct _reent local_clib;
@@ -132,6 +133,8 @@ struct _threadinfo
void init_threadlist_exceptions (struct _exception_list *);
operator HANDLE () const {return tid->win32_obj_id;}
void set_siginfo (struct sigpacket *) __attribute__ ((regparm (3)));
+ void set_threadkill () {threadkill = true;}
+ void reset_threadkill () {threadkill = false;}
/*gentls_offsets*/
};
#pragma pack(pop)
diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc
index 4b905b7..29d11f8 100644
--- a/winsup/cygwin/dcrt0.cc
+++ b/winsup/cygwin/dcrt0.cc
@@ -542,8 +542,12 @@ initial_env ()
buf[0] = '\0';
len = GetModuleFileName (NULL, buf, CYG_MAX_PATH);
console_printf ("Sleeping %d, pid %u %s\n", ms, GetCurrentProcessId (), buf);
- while (ms--)
- Sleep (1);
+ Sleep (ms);
+ if (!strace.active)
+ {
+ strace.inited = 0;
+ strace.hello ();
+ }
}
if (GetEnvironmentVariable ("CYGWIN_DEBUG", buf, sizeof (buf) - 1))
{
@@ -573,7 +577,6 @@ void __stdcall
dll_crt0_0 ()
{
wincap.init ();
- initial_env ();
char zeros[sizeof (child_proc_info->zero)] = {0};
@@ -719,6 +722,7 @@ dll_crt0_1 (char *)
/* FIXME: Verify forked children get their exception handler set up ok. */
exception_list cygwin_except_entry;
+ initial_env ();
check_sanity_and_sync (user_data);
malloc_init ();
diff --git a/winsup/cygwin/dtable.cc b/winsup/cygwin/dtable.cc
index ac9146c..c8d80e0 100644
--- a/winsup/cygwin/dtable.cc
+++ b/winsup/cygwin/dtable.cc
@@ -63,7 +63,6 @@ void
dtable::init_lock ()
{
new_muto (lock_cs);
- // InitializeCriticalSection (&lock_cs);
}
int
@@ -751,6 +750,7 @@ dtable::vfork_parent_restore ()
{
lock ();
+ fhandler_tty_slave *ctty_on_hold = cygheap->ctty_on_hold;
close_all_files ();
fhandler_base **deleteme = fds;
fds = fds_on_hold;
@@ -758,7 +758,7 @@ dtable::vfork_parent_restore ()
cfree (deleteme);
unlock ();
- cygheap->ctty = cygheap->ctty_on_hold; // revert
+ cygheap->ctty = ctty_on_hold; // revert
if (cygheap->ctty)
cygheap->ctty->close (); // Undo previous bump of this archetype
cygheap->ctty_on_hold = NULL;
diff --git a/winsup/cygwin/dtable.h b/winsup/cygwin/dtable.h
index 45de441..8f3cbea 100644
--- a/winsup/cygwin/dtable.h
+++ b/winsup/cygwin/dtable.h
@@ -1,6 +1,6 @@
/* dtable.h: fd table definition.
- Copyright 2000, 2001, 2003 Red Hat, Inc.
+ Copyright 2000, 2001, 2003, 2004 Red Hat, Inc.
This file is part of Cygwin.
@@ -21,7 +21,6 @@ class fhandler_fifo;
class dtable
{
muto *lock_cs;
- //CRITICAL_SECTION lock_cs;
fhandler_base **fds;
fhandler_base **fds_on_hold;
fhandler_base **archetypes;
diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc
index 1fea4cd..cdb20f2 100644
--- a/winsup/cygwin/exceptions.cc
+++ b/winsup/cygwin/exceptions.cc
@@ -559,6 +559,7 @@ handle_exceptions (EXCEPTION_RECORD *e0, void *frame, CONTEXT *in0, void *)
si.si_addr = ebp;
si.si_code = SI_KERNEL;
si.si_errno = si.si_pid = si.si_uid = 0;
+ _my_tls.push ((__stack_t) ebp, true);
sig_send (NULL, si, &_my_tls); // Signal myself
return 1;
}
diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc
index af825de..c1d8c93 100644
--- a/winsup/cygwin/fhandler_console.cc
+++ b/winsup/cygwin/fhandler_console.cc
@@ -677,8 +677,7 @@ fhandler_console::close (void)
CloseHandle (get_output_handle ());
set_io_handle (NULL);
set_output_handle (NULL);
- if (!cygheap->fdtab.in_vfork_cleanup () && --(cygheap->open_fhs) <= 0
- && myself->ctty != TTY_CONSOLE)
+ if (--(cygheap->open_fhs) <= 0 && myself->ctty != TTY_CONSOLE)
{
syscall_printf ("open_fhs %d", cygheap->open_fhs);
FreeConsole ();
diff --git a/winsup/cygwin/gendef b/winsup/cygwin/gendef
index df810cb..5addf91 100755
--- a/winsup/cygwin/gendef
+++ b/winsup/cygwin/gendef
@@ -169,10 +169,12 @@ _sigdelayed:
pushl $tls::newmask(%ebx) # newmask - eaten by set_process_mask
call _set_process_mask\@4
+ cmpl \$0,$tls::threadkill(%ebx)#pthread_kill signal?
+ jnz 4f #yes. Callee clears signal number
movl \$0,$tls::sig(%ebx) # zero the signal number as a
# flag to the signal handler thread
# that it is ok to set up sigsave
- popl %ebx
+4: popl %ebx
jmp *%ebx
EOF
diff --git a/winsup/cygwin/include/cygwin/signal.h b/winsup/cygwin/include/cygwin/signal.h
index 5e26bf4..767f86b 100644
--- a/winsup/cygwin/include/cygwin/signal.h
+++ b/winsup/cygwin/include/cygwin/signal.h
@@ -29,7 +29,7 @@ typedef struct
union
{
- __uint32_t __pad[120]; /* plan for future growth */
+ __uint32_t __pad[32]; /* plan for future growth */
union
{
/* timers */
diff --git a/winsup/cygwin/pipe.cc b/winsup/cygwin/pipe.cc
index 242556a..abc9a81 100644
--- a/winsup/cygwin/pipe.cc
+++ b/winsup/cygwin/pipe.cc
@@ -89,6 +89,9 @@ fhandler_pipe::close ()
CloseHandle (guard);
if (writepipe_exists)
CloseHandle (writepipe_exists);
+ // FIXME is this vfork_cleanup test right? Is it responsible for some of
+ // the strange pipe behavior that has been reported in the cygwin mailing
+ // list?
if (read_state && !cygheap->fdtab.in_vfork_cleanup ())
CloseHandle (read_state);
if (get_handle ())
diff --git a/winsup/cygwin/signal.cc b/winsup/cygwin/signal.cc
index 492ca3b..72664b1 100644
--- a/winsup/cygwin/signal.cc
+++ b/winsup/cygwin/signal.cc
@@ -483,7 +483,8 @@ extern "C" int
sigwait (const sigset_t *set, int *sig)
{
pthread_testcancel ();
- _my_tls.event = CreateEvent (&sec_none_nih, FALSE, FALSE, NULL);
+ HANDLE h;
+ h = _my_tls.event = CreateEvent (&sec_none_nih, FALSE, FALSE, NULL);
if (!_my_tls.event)
{
__seterrno ();
@@ -492,16 +493,20 @@ sigwait (const sigset_t *set, int *sig)
_my_tls.sigwait_mask = *set;
+ int res;
switch (WaitForSingleObject (_my_tls.event, INFINITE))
{
case WAIT_OBJECT_0:
- CloseHandle (_my_tls.event);
- _my_tls.event = NULL;
*sig = InterlockedExchange ((LONG *) &_my_tls.sig, (LONG) 0);
+ res = 0;
break;
default:
__seterrno ();
- return -1;
+ res = -1;
}
- return 0;
+ _my_tls.event = NULL;
+ _my_tls.sig = 0;
+ CloseHandle (h);
+ sig_dispatch_pending ();
+ return res;
}
diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc
index 70129f6..a1c2d30 100644
--- a/winsup/cygwin/sigproc.cc
+++ b/winsup/cygwin/sigproc.cc
@@ -744,6 +744,7 @@ sig_send (_pinfo *p, siginfo_t& si, _threadinfo *tls)
pack.si.si_uid = myself->uid;
pack.pid = myself->pid;
pack.tls = (_threadinfo *) tls;
+ pack.mask_storage = 0;
DWORD nb;
if (!WriteFile (sendsig, &pack, sizeof (pack), &nb, NULL) || nb != sizeof (pack))
{
@@ -1246,7 +1247,14 @@ wait_subproc (VOID *)
si.si_pid = pchildren[rc]->pid;
si.si_uid = pchildren[rc]->uid;
si.si_errno = 0;
- si.si_status = si.si_utime = si.si_stime = 0; // FIXME fill these in someday
+ GetExitCodeProcess (hchildren[rc], (DWORD *) &si.si_status);
+#if 0 // FIXME: This is tricky to get right
+ si.si_utime = pchildren[rc]->rusage_self.ru_utime;
+ si.si_stime = pchildren[rc].rusage_self.ru_stime;
+#else
+ si.si_utime = 0;
+ si.si_stime = 0;
+#endif
rc = proc_subproc (PROC_CHILDTERMINATED, rc);
if (!proc_loop_wait) // Don't bother if wait_subproc is
break; // exiting
diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc
index 5abe0ca..e704d14 100644
--- a/winsup/cygwin/syscalls.cc
+++ b/winsup/cygwin/syscalls.cc
@@ -85,7 +85,7 @@ static int __stdcall stat_worker (const char *name, struct __stat64 *buf,
ensure we don't leave any such files lying around. */
void __stdcall
-close_all_files (void)
+close_all_files ()
{
cygheap->fdtab.lock ();
diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc
index 0b17825..b04dfa1 100644
--- a/winsup/cygwin/thread.cc
+++ b/winsup/cygwin/thread.cc
@@ -2740,6 +2740,7 @@ pthread_kill (pthread_t thread, int sig)
si.si_signo = sig;
si.si_code = SI_USER;
si.si_pid = si.si_uid = si.si_errno = 0;
+ thread->cygtls->set_threadkill ();
int rval = sig ? sig_send (NULL, si, thread->cygtls) : 0;
// unlock myself
diff --git a/winsup/cygwin/tlsoffsets.h b/winsup/cygwin/tlsoffsets.h
index 6aeea68..51c7956 100644
--- a/winsup/cygwin/tlsoffsets.h
+++ b/winsup/cygwin/tlsoffsets.h
@@ -1,17 +1,18 @@
//;# autogenerated: Do not edit.
-//; $tls::func = -4076;
-//; $tls::saved_errno = -4072;
-//; $tls::sa_flags = -4068;
-//; $tls::oldmask = -4064;
-//; $tls::newmask = -4060;
-//; $tls::event = -4056;
-//; $tls::errno_addr = -4052;
-//; $tls::initialized = -4048;
-//; $tls::sigmask = -4044;
-//; $tls::sigwait_mask = -4040;
-//; $tls::sigwait_info = -4036;
-//; $tls::infodata = -4032;
+//; $tls::func = -3704;
+//; $tls::saved_errno = -3700;
+//; $tls::sa_flags = -3696;
+//; $tls::oldmask = -3692;
+//; $tls::newmask = -3688;
+//; $tls::event = -3684;
+//; $tls::errno_addr = -3680;
+//; $tls::initialized = -3676;
+//; $tls::sigmask = -3672;
+//; $tls::sigwait_mask = -3668;
+//; $tls::sigwait_info = -3664;
+//; $tls::threadkill = -3660;
+//; $tls::infodata = -3656;
//; $tls::tid = -3508;
//; $tls::local_clib = -3504;
//; $tls::locals = -2576;
@@ -23,18 +24,19 @@
//; $tls::padding = 0;
//; __DATA__
-#define tls_func (-4076)
-#define tls_saved_errno (-4072)
-#define tls_sa_flags (-4068)
-#define tls_oldmask (-4064)
-#define tls_newmask (-4060)
-#define tls_event (-4056)
-#define tls_errno_addr (-4052)
-#define tls_initialized (-4048)
-#define tls_sigmask (-4044)
-#define tls_sigwait_mask (-4040)
-#define tls_sigwait_info (-4036)
-#define tls_infodata (-4032)
+#define tls_func (-3704)
+#define tls_saved_errno (-3700)
+#define tls_sa_flags (-3696)
+#define tls_oldmask (-3692)
+#define tls_newmask (-3688)
+#define tls_event (-3684)
+#define tls_errno_addr (-3680)
+#define tls_initialized (-3676)
+#define tls_sigmask (-3672)
+#define tls_sigwait_mask (-3668)
+#define tls_sigwait_info (-3664)
+#define tls_threadkill (-3660)
+#define tls_infodata (-3656)
#define tls_tid (-3508)
#define tls_local_clib (-3504)
#define tls_locals (-2576)
diff --git a/winsup/cygwin/winsup.h b/winsup/cygwin/winsup.h
index f8bb9ec..980f661 100644
--- a/winsup/cygwin/winsup.h
+++ b/winsup/cygwin/winsup.h
@@ -219,7 +219,7 @@ void uinfo_init (void);
void events_init (void);
void events_terminate (void);
-void __stdcall close_all_files (void);
+void __stdcall close_all_files ();
/* Invisible window initialization/termination. */
HWND __stdcall gethwnd (void);