diff options
author | Christopher Faylor <me@cgf.cx> | 2003-11-28 20:55:59 +0000 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2003-11-28 20:55:59 +0000 |
commit | 9a4d574b8d4550f53036dced342022b64e508abf (patch) | |
tree | 79d7ab65654ff5cb2fd2c0c035ac2b98deb1fcc2 /winsup/cygwin/signal.cc | |
parent | ffe006384344b5d2a86e6bedad96725391cfe88e (diff) | |
download | newlib-9a4d574b8d4550f53036dced342022b64e508abf.zip newlib-9a4d574b8d4550f53036dced342022b64e508abf.tar.gz newlib-9a4d574b8d4550f53036dced342022b64e508abf.tar.bz2 |
Eliminate use of sigframe and sigthread throughout.
* Makefile.in (DLL_OFILES): Add sigfe.o. Remove reliance on cygwin.def from
cygwin0.dll dependency since dependence on sigfe.o implies that. Generate def
file on the fly using 'gendef'.
* configure.in: Don't auto-generate cygwin.def.
* configure: Regenerate.
* cygwin.din: Add SIGFE stuff where appropriate.
* dcrt0.cc (dll_crt0_1): Initialize cygwin tls early in process startup. Set
_main_tls to address of the main thread's cygwin tls.
* debug.h: Remove now unneeded WFSO and WFMO declarations.
* exceptions.cc (_last_thread): Define.
(set_thread_state_for_signals): New function.
(reset_thread_exception_for_signals): Ditto.
(init_thread_for_signals): Ditto.
(delete_thread_for_signals): Ditto.
(capture_thread_for_signals): Ditto.
(handle_exceptions): Set return address explicitly for exceptions prior to
calling sig_send.
(interrupt_on_return): Eliminate.
(setup_handler): Add preliminary implementation for dealing with
thread-specific signals by querying _main_tls.
(signal_exit): Use cygthread::main_thread_id instead of mainthread.id.
(call_signal_handler_now): For now, just handle the main thread.
* fork.cc (vfork): Save and restore main _my_tls.
* gendef: New file. Generates def file and sigfe.s file.
* gentls_offsets: New file. Generates offsets for perl to use in sigfe.s.
* how-signals-work.txt: Mention that info is obsolete.
* init.cc (dll_entry): Initialize cygwin tls storage here.
* miscfuncs.cc (low_priority_sleep): Make a C function for easier calling from
asm.
* perthread.h (vfork_save::tls): New element.
* signal.cc (nanosleep): Replace previous use of
sigframe.call_signal_handler_now with straight call to call_signal_handler_now.
(abort): Ditto.
* syscalls.cc (readv): Ditto.
* termios.cc (tcsetattr): Ditto.
* wait.cc (wait4): Ditto.
* sigproc.cc (sig_dispatch_pending): Ditto.
(sig_send): Ditto.
* sigproc.h: Declare call_signal_handler_now.
* thread.cc (pthread::thread_init_wrapper): Initialize cygwin tls. Remove
obsolete and unworking signal stuff.
* thread.h (verifyable_object::sigs): Eliminate.
(verifyable_object::sigmask): Eliminate.
(verifyable_object::sigtodo): Eliminate.
(verifyable_object::exit): Make attribute noreturn.
(verifyable_object::thread_init_wrapper): Ditto.
(pthread_null::exit): Ditto.
* winbase.h (__stackbase): Always define.
* winsup.h (low_priority_sleep): Declare as a "C" function.
* include/cygwin/version.h: Bump API version to reflect sigwait export.
* include/sys/queue.h: Protect SLIST_ENTRY from previous declaration.
* signal.cc (sigwait): Implement.
* select.cc (fhandler_base::ready_for_read): Add debugging output.
* devices.h: Define more device pointers via their storage.
* devices.in: Don't parse things like /dev/inet/tcp, as they really have no
meaning.
* devices.cc: Regenerate.
* gendevices: Set proper protection for output file.
* cygtls.h: New file.
* gendef: New file.
* gentls_offsets: New file.
* tlsoffsets.h: New file. Autogenerated.
* config/i386/longjmp.c: Remove. File subsumed by gendef output.
* config/i386/makefrag: Remove obsolete file.
* fhandler.cc: Remove spurious access_worker declaration.
* spawn.cc (spawnve): Make debugging output more accurate.
* cygwin-gperf: Remove.
* devices.cc: Remove.
Diffstat (limited to 'winsup/cygwin/signal.cc')
-rw-r--r-- | winsup/cygwin/signal.cc | 73 |
1 files changed, 54 insertions, 19 deletions
diff --git a/winsup/cygwin/signal.cc b/winsup/cygwin/signal.cc index 7f6fcbe..9bf9eb0 100644 --- a/winsup/cygwin/signal.cc +++ b/winsup/cygwin/signal.cc @@ -15,9 +15,11 @@ details. */ #include <stdlib.h> #include "cygerrno.h" #include <sys/cygwin.h> -#include "sigproc.h" #include "pinfo.h" +#include "sigproc.h" #include "hires.h" +#include "security.h" +#include "cygtls.h" int sigcatchers; /* FIXME: Not thread safe. */ @@ -71,7 +73,6 @@ nanosleep (const struct timespec *rqtp, struct timespec *rmtp) { int res = 0; sig_dispatch_pending (); - sigframe thisframe (mainthread); pthread_testcancel (); if ((unsigned int) rqtp->tv_sec > (HIRES_DELAY_MAX / 1000 - 1) @@ -92,7 +93,7 @@ nanosleep (const struct timespec *rqtp, struct timespec *rmtp) rem = 0; if (rc == WAIT_OBJECT_0) { - (void) thisframe.call_signal_handler (); + (void) call_signal_handler_now (); set_errno (EINTR); res = -1; } @@ -130,20 +131,33 @@ usleep (unsigned int useconds) extern "C" int sigprocmask (int sig, const sigset_t *set, sigset_t *oldset) { + return handle_sigprocmask (sig, set, oldset, myself->getsigmask ()); +} + +int __stdcall +handle_sigprocmask (int sig, const sigset_t *set, sigset_t *oldset, sigset_t& opmask) +{ sig_dispatch_pending (); /* check that sig is in right range */ if (sig < 0 || sig >= NSIG) { - set_errno (EINVAL); + set_errno (ESRCH); syscall_printf ("SIG_ERR = sigprocmask signal %d out of range", sig); return -1; } if (oldset) - *oldset = myself->getsigmask (); + { + if (check_null_invalid_struct_errno (oldset)) + return -1; + *oldset = opmask; + } + if (set) { - sigset_t newmask = myself->getsigmask (); + if (check_invalid_read_struct_errno (set)) + return -1; + sigset_t newmask = opmask; switch (sig) { case SIG_BLOCK: @@ -162,7 +176,7 @@ sigprocmask (int sig, const sigset_t *set, sigset_t *oldset) set_errno (EINVAL); return -1; } - (void) set_process_mask (newmask); + (void) set_signal_mask (newmask, opmask); } return 0; } @@ -185,10 +199,7 @@ kill_worker (pid_t pid, int sig) if ((sendSIGCONT = (sig < 0))) sig = -sig; -#if 0 - if (dest == myself && !sendSIGCONT) - dest = myself_nowait_nonmain; -#endif + DWORD process_state = dest->process_state; if (sig == 0) { res = proc_exists (dest) ? 0 : -1; @@ -203,7 +214,7 @@ kill_worker (pid_t pid, int sig) else if (sendSIGCONT) (void) sig_send (dest, SIGCONT); - syscall_printf ("%d = kill_worker (%d, %d)", res, pid, sig); + syscall_printf ("%d = kill_worker (%d, %d), process_state %p", res, pid, sig, process_state); return res; } @@ -216,7 +227,6 @@ raise (int sig) int kill (pid_t pid, int sig) { - sigframe thisframe (mainthread); syscall_printf ("kill (%d, %d)", pid, sig); /* check that sig is in right range */ if (sig < 0 || sig >= NSIG) @@ -241,7 +251,6 @@ kill_pgrp (pid_t pid, int sig) int res = 0; int found = 0; int killself = 0; - sigframe thisframe (mainthread); sigproc_printf ("pid %d, signal %d", pid, sig); @@ -289,7 +298,6 @@ extern "C" void abort (void) { sig_dispatch_pending (); - sigframe thisframe (mainthread); /* Flush all streams as per SUSv2. From my reading of this document, this isn't strictly correct. The streams are supposed to be flushed prior to exit. However, @@ -304,10 +312,10 @@ abort (void) sigset_t sig_mask; sigfillset (&sig_mask); sigdelset (&sig_mask, SIGABRT); - set_process_mask (sig_mask); + set_signal_mask (sig_mask); raise (SIGABRT); - (void) thisframe.call_signal_handler (); /* Call any signal handler */ + (void) call_signal_handler_now (); /* Call any signal handler */ do_exit (1); /* signal handler didn't exit. Goodbye. */ } @@ -436,11 +444,38 @@ extern "C" int siginterrupt (int sig, int flag) { struct sigaction act; - (void)sigaction(sig, NULL, &act); + (void) sigaction(sig, NULL, &act); if (flag) act.sa_flags &= ~SA_RESTART; else act.sa_flags |= SA_RESTART; - return sigaction(sig, &act, NULL); + return sigaction (sig, &act, NULL); } + +extern "C" int +sigwait (const sigset_t *set, int *sig) +{ + pthread_testcancel (); + _my_tls.event = CreateEvent (&sec_none_nih, FALSE, FALSE, NULL); + if (!_my_tls.event) + { + __seterrno (); + return -1; + } + + _my_tls.sigwait_mask = *set; + + 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); + break; + default: + __seterrno (); + return -1; + } + return 0; +} |