aboutsummaryrefslogtreecommitdiff
path: root/winsup/cygwin/signal.cc
AgeCommit message (Collapse)AuthorFilesLines
2022-05-29Cygwin: remove regparm.hKen Brown1-4/+4
This file defines the macros __reg1, __reg2, and __reg3, which are defined to be empty on 64-bit Cygwin. Remove all occurrences of these macros.
2022-05-13Add stdio_exit_handler()Matt Joyce1-2/+3
Add a dedicated stdio exit handler to avoid using _GLOBAL_REENT in exit().
2022-05-12Cygwin: signal.cc: Include <unistd.h>Sebastian Huber1-1/+2
Include <unistd.h> for sleep() and usleep() declarations. Fix return type of usleep().
2022-03-01Cygwin: handle_sigprocmask: If new signal set is NULL, ignore "how"Corinna Vinschen1-3/+3
The "how" value only makes sense if a new set is given. If we only read the current signal set, ignore the value of "how" per POSIX: "If set is a null pointer, the value of the argument how is not significant" Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-11-22Cygwin: raise: align return value and error checking to LinuxCorinna Vinschen1-1/+6
raise(2) on Linux returns the same values and sets errno independent of calling kill(2) or pthread_kill(3). Align code to behave the same. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-11-22Cygwin: raise: fix check for multithreaded processCorinna Vinschen1-1/+1
The check for the pthread self pointer in TLS is misleading, given the main thread has this pointer initialized as well. Check for the global __isthreaded flag as well. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-02-18Cygwin: rename NSIG to _NSIG, change visibility of NSIG to MISCCorinna Vinschen1-7/+7
NSIG is a deprecated symbol only visible under MISC visibility. _NSIG is used widely instead, and on most systems NSIG is defined in terms of _NSIG. Follow suit: Change NSIG to _NSIG throughout and change visiblity of NSIG to be defined only in __MISC_VISIBLE case. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-08-18Cygwin: select: revamp non-polling code for signalfdCorinna Vinschen1-1/+0
Rather than waiting for signalfd_select_wait in a thread, which is racy, create a global event "my_pendingsigs_evt" which is set and reset by wait_sig depending only on the fact if blocked signals are pending or not. This in turn allows to WFMO on this event in select as soon as signalfds are present in the read descriptor set. Select's peek and verify will then check if one of the present signalfds is affected. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-07-12Cygwin: return full sigset_t from sig_sendCorinna Vinschen1-2/+2
So far sig_send's return type is int. The problem with this is that sig_send returns a sigset_t on __SIGPENDING, and sigset_t is defined as long type. So the function only returns the lower 32 bit of sigset_t, which is fine on 32 bit, but casts away the pending RT signals on 64 bit. Fix this by changing the return type of sig_send to sigset_t, so as not to narrow down the sigset when returning from handling __SIGPENDING. Make sure to cast correctly in all invocations of sig_send. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-30Cygwin: raise: change to call pthread_killCorinna Vinschen1-1/+4
POSIX requires that raise(3) is equivalent to pthread_kill(pthread_self(), sig); in multi-threaded applications. Our raise just called kill(sig). Fix that. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-22Cygwin: posix timers: reimplement using OS timerCorinna Vinschen1-2/+2
- Rename files timer.* to posix_timer.*. - Reimplement using an OS timer rather than a handcrafted wait loop. - Use a Slim R/W Lock for synchronization. - Drop timer chaining. It doesn't server a purpose since all timers are local only. - Rename ttstart to itimer_tracker to better reflect its purpose. It's not the anchor for a timer chain anymore anyway. - Drop fixup_timers_after_fork. Everything is process-local, nothing gets inherited. - Rename timer_tracker::disarm_event to disarm_overrun_event for better readability. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-18Cygwin: clock.h: add valid_timespec() to check timespec for validityCorinna Vinschen1-3/+2
Use throughout, drop local timespec_bad() in timer.cc. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-14Cygwin: signalfd: implement non-polling selectCorinna Vinschen1-1/+3
Allow the signal thread to recognize we're called in consequence of select on a signalfd. If the signal is part of the wait mask, don't call any signal handler and don't remove the signal from the queue, so a subsequent read (or sigwaitinfo/sigtimedwait) still gets the signal. Instead, just signal the event object at _cygtls::signalfd_select_wait for the thread running select. The addition of signalfd_select_wait to _cygtls unearthed the alignment problem of the context member again. To make sure this doesn't get lost, improve the related comment in the header file so that this (hopefully) doesn't get lost (again). Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-13Cygwin: signal: implement signalfdCorinna Vinschen1-1/+61
First cut of a signalfd implementation. Still TODO: Non-polling select. This should mostly work as on Linux except for missing support for some members of struct signalfd_siginfo, namely ssi_fd, ssi_band (both SIGIO/SIGPOLL, not fully implemented) and ssi_trapno (HW exception, required HW support). Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-13Cygwin: minor cleanupsCorinna Vinschen1-3/+4
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-12Cygwin: posix timers: implement timer_getoverrunCorinna Vinschen1-0/+7
- set DELAYTIMER_MAX to INT_MAX - make sure to set siginfo_t::si_overrun, as on Linux Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-11Cygwin: clock_nanosleep is not supposed to crash, return EFAULT insteadCorinna Vinschen1-5/+21
...in case rqtp or rmtp specified invalid addresses. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-11-29Cygwin: implement extensible clock interfaceCorinna Vinschen1-13/+10
- Drop hires_[nm]s clocks, rename hires.h to clock.h. - Implement clk_t class as an extensible clock class in new file clock.cc. - Introduce get_clock(clock_id) returning a pointer to the clk_t instance for clock_id. Provide the following methods along the lines of the former hires classes: void clk_t::nsecs (struct timespec *); ULONGLONG clk_t::nsecs (); LONGLONG clk_t::usecs (); LONGLONG clk_t::msecs (); void clk_t::resolution (struct timespec *); - Add CLOCK_REALTIME_COARSE, CLOCK_MONOTONIC_RAW, CLOCK_MONOTONIC_COARSE and CLOCK_BOOTTIME clocks. - Allow clock_nanosleep, pthread_condattr_setclock and timer_create to use all new clocks (both clocks should be usable with a small tweak, though). - Bump DLL major version to 2.12. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-07-19fix duration handling in sigtimedwaitMark Geisert1-0/+2
2018-02-07Cygwin: Cleanup time handlingCorinna Vinschen1-11/+15
* Redefine NSPERSEC to NS100PERSEC * Define NSPERSEC as nanosecs per second * Define USPERSEC as microsecs per second * Use above constants throughout where appropriate * Rename to_us to timespec_to_us and inline * Rename it_bad to timespec_bad and inline Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2017-12-18Cygwin: rearrange sigwait functions, convert sigwait_common to inlineCorinna Vinschen1-45/+43
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2017-12-18Cygwin: Implement sigtimedwaitMark Geisert1-2/+34
Abstract out common code from sigwait/sigwaitinfo/sigtimedwait to implement the latter.
2017-10-09cygwin: Remove comparison of 'this' to NULL in _pinfo::existsKen Brown1-1/+1
Fix all callers.
2017-10-09cygwin: Remove comparison of 'this' to 'NULL' in _pinfo::killKen Brown1-3/+12
Fix all callers.
2017-08-03Revert "cygwin/signal.h: Remove SI_QUEUE unimplemented comment"Corinna Vinschen1-16/+9
This reverts commit 54ed68a781fe8a36d08352503524e61534a25e07.
2017-08-03cygwin/signal.h: Remove SI_QUEUE unimplemented commentCorinna Vinschen1-9/+16
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2017-06-14Export XSI sigpauseYaakov Selkowitz1-0/+12
There are two common sigpause variants, both of which take an int argument. If you request _XOPEN_SOURCE or _GNU_SOURCE, you get the System V version, which removes the given signal from the process's signal mask; otherwise you get the BSD version, which sets the process's signal mask to the given value. Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2016-11-24Don't allow sending invalid signals from user spaceCorinna Vinschen1-12/+22
Don't allow signal 0 in signal(2), sigaction(2), siginterrupt(3). Don't allow any signal in sigqueue(3) but explicitely handle signal 0 as in kill(2). Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2016-11-24raise: Add missing extern "C"Corinna Vinschen1-1/+1
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2016-08-11kill(pid, sig) before waitpid() returns -1 for sig != 0Erik Bray1-1/+1
This is a followup to a report back in 2011 about essentially the same issue: https://cygwin.com/ml/cygwin/2011-04/msg00031.html The same test program in that report demonstrates the issue, but with kill sending any non-zero signal. To reiterate, the problem here is POSIX compliance with respect to sending signals to zombie processes. http://pubs.opengroup.org/onlinepubs/9699919799/functions/kill.html claims: Existing implementations vary on the result of a kill() with pid indicating an inactive process (a terminated process that has not been waited for by its parent). Some indicate success on such a call (subject to permission checking), while others give an error of [ESRCH]. Since the definition of process lifetime in this volume of POSIX.1-2008 covers inactive processes, the [ESRCH] error as described is inappropriate in this case. In particular, this means that an application cannot have a parent process check for termination of a particular child with kill(). (Usually this is done with the null signal; this can be done reliably with waitpid().) In response to the originally issue, this was fixed *specifically* for the case of kill(pid, 0). But my reading of the above is that kill() should return 0 in this case regardless of the signal (modulo permissions, etc.). On Linux, for example, when calling kill with pid of a zombie process the kernel will happily deliver the signal to the relevant task_struct; it will just never be acted on since the task will never run again. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2016-06-23Switching the Cygwin DLL to LGPLv3+, dropping commercial buyout optioncygwin-2_5_2-releaseCorinna Vinschen1-3/+0
Bump GPLv2+ to GPLv3+ for some files, clarify BSD 2-clause. Everything else stays under GPLv3+. New Linking Exception exempts resulting executables from LGPLv3 section 4. Add CONTRIBUTORS file to keep track of licensing. Remove 'Copyright Red Hat Inc' comments. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2016-04-05Revert "Refactor to avoid nonnull checks on "this" pointer."Corinna Vinschen1-8/+4
This reverts commit 0008bdea02b690ab19ffe997499cb9a96ee5a66d. This patch introduced a regression. Calling FOO=$(...) in zsh hangs indefinitely and has to be killed forcefully. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2016-04-04Refactor to avoid nonnull checks on "this" pointer.Peter Foley1-4/+8
G++ 6.0 asserts that the "this" pointer is non-null for member functions. Refactor methods that check if "this" is non-null to resolve this. winsup/cygwin/ChangeLog: external.cc (cygwin_internal): Check for a null pinfo before calling cmdline. fhandler_dsp.cc (Audio::blockSize): Make static. fhandler_dsp.cc (Audio_in): add default_buf_info. fhandler_dsp.cc (Audio_out): Ditto. fhandler_dsp.cc (Audio_out::buf_info): Refactor method to call default_buf_info if dev_ is null. fhandler_dsp.cc (Audio_in::buf_info): Ditto. fhandler_dsp.cc (fhandler_dev_dsp::_ioctl): Call Audio_out::default_buf_info if audio_out_ is null. fhandler_dsp.cc (fhandler_dev_dsp::_ioctl): Call Audio_in::default_buf_info if audio_in_ is null. fhandler_process.cc (format_process_fd): Check if pinfo is null. fhandler_process.cc (format_process_root): Ditto. fhandler_process.cc (format_process_cwd): Ditto. fhandler_process.cc (format_process_cmdline): Ditto. signal.cc (tty_min::kill_pgrp): Ditto. signal.cc (_pinfo::kill0): Ditto. sigproc.cc (pid_exists): Ditto. sigproc.cc (remove_proc): Ditto. times.cc (clock_gettime): Ditto. times.cc (clock_getcpuclockid): Ditto. path.cc (cwdstuff::override_win32_cwd): Check if old_cwd is null. path.cc (fcwd_access_t::Free): Factor null check of "this" out to caller(s). pinfo.cc (_pinfo::exists): Ditto. pinfo.cc (_pinfo::fd): Ditto. pinfo.cc (_pinfo::fds): Ditto. pinfo.cc (_pinfo::root): Ditto. pinfo.cc (_pinfo::cwd): Ditto. pinfo.cc (_pinfo::cmdline): Ditto. signal.cc (_pinfo::kill): Ditto. pinfo.cc (_pinfo::commune_request): remove non-null check on "this", as this method is only called from pinfo.cc after null checks pinfo.cc (_pinfo::pipe_fhandler): remove non-null check on "this", as this method is only called from pipe.cc (fhandler_pipe::open) after a null check. Signed-off-by: Peter Foley <pefoley2@pefoley.com>
2015-10-30Fix sigwait and pthread_kill return values in case of errorCorinna Vinschen1-2/+8
* signal.cc (sigwait): Fix return value to reflect errno in case of error according to POSIX. Never return EINTR. * thread.cc (pthread_kill): Return errno if sig_send failed. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-07-29cygwin: Fix copyright datesCorinna Vinschen1-1/+1
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-06-30Add comment to sigaltstack to explain setting ss_flags hereCorinna Vinschen1-0/+4
* signal.cc (sigaltstack): Add comment. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-06-27Handle ss_flags value longjmp safe.Corinna Vinschen1-1/+11
* exceptions.cc (_cygtls::call_signal_handler): Drop manipulating thread's ss_flags here. It's not safe against longjmp. * signal.cc (sigaltstack): Check if we're running on the alternate stack and set ss_flags returned in oss to SS_ONSTACK. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-06-20Handle exceptions in sigaltstackCorinna Vinschen1-21/+35
* signal.cc (sigaltstack): Add fault handler. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-06-19Preliminary infrastructure to implement alternate stackCorinna Vinschen1-1/+39
* libc/include/sys/signal.h: Define SS_ONSTACK and SS_DISABLE unconditionally. (sigaltstack): Enable prototype on Cygwin. * common.din (sigaltstack): Export. * cygtls.cc (_cygtls::init_thread): Initialize altstack. * cygtls.h (__tlsstack_t): Rename from __stack_t to distinguish more clearly from stack_t. Accommodate throughout. (_cygtls): Add altstack member. * exceptions.cc (exception::handle): Set SIGSEGV handler to SIG_DFL if we encounter a stack overflow, and no alternate stack has been defined. * include/cygwin/signal.h (MINSIGSTKSZ): Define (SIGSTKSZ): Define. (SA_ONSTACK): Define. * signal.cc (sigaltstack): New function. * tlsoffset.h: Regenerate. * tlsoffset64.h: Ditto. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2014-08-22 * Throughout, use __try/__except/__endtry blocks, rather than myfaultCorinna Vinschen1-60/+66
handler. * cygtls.cc (_cygtls::remove): Accommodate the fact that pathbufs has been moved from _local_storage to _cygtls. * cygtls.h (class tls_pathbuf): Add comment to hint to gendef usage of counters. Change type of counters to uint32_t for clarity. Remove _cygtls as friend class. (struct _local_storage): Move pathbufs from here... (struct _cygtls): ...to here, allowing to access it from _sigbe. (class san): Only define on 32 bit. Remove errno, _c_cnt and _w_cnt members. (san::setup): Drop parameter. Don't initialize removed members. (san::leave): Don't set removed members. (class myfault): Only define on 32 bit. (myfault::faulted): Only keep implementation not taking any parameter. Drop argument in call to sebastian.setup. (__try/__leave/__except/__endtry): Implement to support real SEH. For now stick to SJLJ on 32 bit. * dcrt0.cc (dll_crt0_0): Drop 64 bit call to exception::install_myfault_handler. * exception.h (exception_handler): Define with EXCEPTION_DISPOSITION as return type. (PDISPATCHER_CONTEXT): Define as void * on 32 bit. Define as pointer to _DISPATCHER_CONTEXT on 64 bit. (class exception): Define separately for 32 and 64 bit. (exception::myfault): Add handler for myfault SEH handling on 64 bit. (exception::exception): Fix mangled method name to account for change in type of last parameter. (exception::install_myfault_handler): Remove. * exceptions.cc (exception::myfault_handle): Remove. (exception::myfault): New SEH handler for 64 bit. * gendef (_sigbe): Set tls_pathbuf counters to 0 explicitely when returning to the caller. * ntdll.h: Move a comment to a better place. (struct _SCOPE_TABLE): Define on 64 bit. * thread.cc (verifyable_object_isvalid): Remove gcc 4.7 workaround. * tls_pbuf.cc (tls_pbuf): Fix to accommodate new place of pathbufs. (tls_pathbuf::destroy): Change type of loop variables to uint32_t. * tls_pbuf.h (class tmp_pathbuf): Change type of buffer counters to uint32_t. Accommodate new place of pathbufs. * tlsoffsets.h: Regenerate. * tlsoffsets64.h: Regenerate.
2014-08-19 * dir.cc (dirfd): Per POSIX, return EINVAL on invalid directory stream.Corinna Vinschen1-1/+1
(telldir): Per POSIX, return -1 and set errno to EBADF, rather than just returning 0, on invalid directory stream. * signal.cc (sigwaitinfo): Return -1, not EFAULT, when SEGV was catched.
2014-05-09* signal.cc (sigprocmask): Fix strace output to include "how".Christopher Faylor1-1/+1
* fhandler_console.cc (dev_console::save_restore): Only current dwEnd line rather than the one after that.
2013-05-01Throughout, (mainly in fhandler*) fix remaining gcc 4.7 mismatchYaakov Selkowitz1-2/+2
warnings between regparm definitions and declarations. * smallprint.cc (__small_vswprintf): Conditionalize declaration and setting of l_opt for only x86_64. * spawn.cc (child_info_spawn::worker): Remove unused 'pid' variable. * thread.cc (verifyable_object_isvalid): Temporarily define as non-inline with gcc 4.7+, regardless of target.
2013-04-23 * Merge in cygwin-64bit-branch.Corinna Vinschen1-3/+3
2013-01-31* DevNotes: Add entry cgf-000022.Christopher Faylor1-9/+0
* cygtls.h (_cygtls::func): Define as a sa_sigaction style function. * exceptions.cc (sig_handle_tty_stop): Ditto. (_cygtls::interrupt_setup): Fix coercion to accommodate 'func' change. (ctrl_c_handler): Use tty kill_pgrp to send a signal. (sigpacket::process): Don't process sigflush here. (_cygtls::call_signal_handler): Reorganize to avoid a race. Always call sa_sigaction style function. * fhandler_termios.cc (is_flush_sig): Define new function. (tty_min::kill_pgrp): Handle tty flush when signal detected. (fhandler_termios::bg_check): Be slightly more paranoid about checking for valid tty. (fhandler_termios::sigflush): Don't flush unless tty owner. * fhandler_tty.cc (fhandler_pty_slave::ioctl): Use tty kill_pgrp to send signal. (fhandler_pty_master::ioctl): Ditto. * signal.cc (killsys): Delete definition. * sigproc.h (killsys): Delete declaration. * include/cygwin/signal.h (siginfo_t): Simplify union/struct nesting slightly. Implement mechanism to allow cygwin data passing.
2013-01-21Throughout, change __attribute__ ((regparm (N))) to just __regN. Throughout,Christopher Faylor1-5/+4
(mainly in fhandler*) start fixing gcc 4.7.2 mismatch between regparm definitions and declarations. * gendef: Define some functions to take @ declaration to accommodate _regN defines which use __stdcall. * gentls_offsets: Define __regN macros as empty. * autoload.cc (wsock_init): Remove unneeded regparm attribute. * winsup.h (__reg1): Define. (__reg2): Define. (__reg3): Define. * advapi32.cc (DuplicateTokenEx): Coerce some initializers to avoid warnings from gcc 4.7.2. * exceptions.cc (status_info): Declare struct to use NTSTATUS. (cygwin_exception::dump_exception): Coerce e->ExceptionCode to NTSTATUS. * fhandler_clipboard.cc (cygnativeformat): Redefine as UINT to avoid gcc 4.7.2 warnings. (fhandler_dev_clipboard::read): Ditto.
2012-08-15Rename cancelable_wait -> cygwait throughout.Christopher Faylor1-2/+2
* DevNotes: Add entry cgf-000015. * cygwait.h (cygwait): Don't allow an optional PLARGE_INTERGER argument.
2012-08-15* exceptions.cc (sigdelayed): Move declaration to sigproc.h.Christopher Faylor1-1/+5
* sigproc.h (sigdelayed): Make symbol globally available. * gendef (sigdelayed): Specifically zero incyg and stacklock. * signal.cc (sigwaitinfo): Lock _my_tls and try harder to clean up signal information.
2012-08-07* signal.cc (sigwaitinfo): Change cw_sig to the correct cw_sig_eintr.Christopher Faylor1-2/+1
2012-07-30* cygwait.cc (cancelable_wait): Add some debugging-only output.Christopher Faylor1-3/+9
* exceptions.cc (sig_handle_tty_stop): Make sure that incyg is cleared when exiting if we have no parent process. Only wait for signal_arrived. (sigpacket::process): Make continue_now a bool. Delay sending signal_arrived until the end. Make code more defensive to avoid calling signal handler when stopped. Only set signal_arrived when stopped. * sigproc.cc (sig_hold): Rename from sigCONT. Make static. (sig_send): Accommodate sigCONT -> sig_hold rename. (wait_sig): Ditto. * sigproc.h (sigCONT): Delete declaration. * fhandler_console.cc (fhandler_console::write): Use new '%0c' facility to print characters. Change to paranoid to avoid excessive strace output. * fhandler_tty.cc (fhandler_pty_master::accept_input): Make frequent strace printf "paranoid" to help cut down on strace output size. * signal.cc (sigsuspend): Add standard syscall strace output. (sigpause): Ditto. (pause): Ditto. * cygtls.h (_cygtls::reset_signal_arrived): New function.