aboutsummaryrefslogtreecommitdiff
path: root/winsup/cygwin/exceptions.cc
AgeCommit message (Collapse)AuthorFilesLines
2020-08-30Cygwin: Remove waitloop argument from try_to_debug()Jon Turney1-6/+8
Currently, when using CYGWIN's error_start facility, the faulting process isn't stopped while the error_start process is started when the fault is caused by an exception. (it even seems possible in theory that the faulting process could have exited before the error_start process attaches). This leads to e.g. the core dump written by CYGWIN='error_start=dumper' in response to an exception being non-deterministic. Remove the waitloop argument from try_to_debug(), only used in the exception case, so the faulting process busy-waits until the error_start process attaches. Code archaeology to determine why the code is this way didn't really turn up any answers, but this seems a low-risk change, as this only changes the behaviour when: - a debugger isn't already attached - an error_start is specified in CYGWIN env var - an exception has occurred which will be translated to a signal If error_start invokes something which doesn't attach using DebugActiveProcess(), we will spin indefinitely, but that will also currently occur for any of the existing other uses of try_to_debug(), which default to waitloop=TRUE.
2020-08-20Cygwin: add header defining GCC exception codesKen Brown1-9/+1
Include it in exceptions.cc instead of defining the exception codes there.
2020-08-18Cygwin: main exception handler (64-bit): continue GCC exceptionsKen Brown1-0/+19
This is necessary in order to be consistent with the following comment in the definition of _Unwind_RaiseException() in the GCC source file libgcc/unwind-seh.c: The exception handler installed in crt0 will continue any GCC exception that reaches there (and isn't marked non-continuable). Previously we failed to do this and, as a consequence, the C++ runtime didn't call std::terminate after an unhandled exception. This fixes the problem reported here: https://cygwin.com/pipermail/cygwin/2019-October/242795.html https://sourceware.org/pipermail/cygwin/2020-August/245897.html
2020-08-05Cygwin: Add 'fallthrough' pseudo keyword for switch/case useCorinna Vinschen1-1/+1
This patch has been inspired by the Linux kernel patch 294f69e662d1 compiler_attributes.h: Add 'fallthrough' pseudo keyword for switch/case use written by Joe Perches <joe AT perches DOT com> based on an idea from Dan Carpenter <dan DOT carpenter AT oracle DOT com>. The following text is from the original log message: Reserve the pseudo keyword 'fallthrough' for the ability to convert the various case block /* fallthrough */ style comments to appear to be an actual reserved word with the same gcc case block missing fallthrough warning capability. All switch/case blocks now should end in one of: break; fallthrough; goto <label>; return [expression]; continue; In C mode, GCC supports the __fallthrough__ attribute since 7.1, the same time the warning and the comment parsing were introduced. Cygwin-only: add an explicit -Wimplicit-fallthrough=5 to the build flags.
2020-03-11Cygwin: fix formatting: drop trailing whitespaceCorinna Vinschen1-1/+1
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-03-11Cygwin: fix formatting: collapse whitespace-only linesCorinna Vinschen1-1/+1
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-02-18Cygwin: rename NSIG to _NSIG, change visibility of NSIG to MISCCorinna Vinschen1-3/+3
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-11-08Cygwin: Raise dumpstack frame limit to 32Mark Geisert1-2/+4
Create a #define for the limit and raise it from 16 to 32.
2019-10-03Cygwin: Fix signal handling issue introduced by PTY related change.Takashi Yano1-1/+1
- After commit 41864091014b63b0cb72ae98281fa53349b6ef77, there is a regression in signal handling reported in https://www.cygwin.com/ml/cygwin/2019-10/msg00010.html. This patch fixes the issue.
2019-09-20Cygwin: Fix incorrect TTY for non-cygwin process.Takashi Yano1-1/+1
- After commit d4045fdbef60d8e7e0d11dfe38b048ea2cb8708b, the TTY displayed by ps command is incorrect if the process is non-cygwin process. This patch fixes this issue.
2019-08-18Cygwin: select: revamp non-polling code for signalfdCorinna Vinschen1-8/+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-08-17Revert "Cygwin: fix potential SEGV in sigwaitinfo/signalfd scenario"Corinna Vinschen1-14/+3
This reverts commit 92115a83a4579635e253be2887d3706d28b477fd. This was utterly wrong.
2019-08-13Cygwin: fix potential SEGV in sigwaitinfo/signalfd scenarioCorinna Vinschen1-3/+14
On sigwaitinfo or reading from a signalfd, signal processing sets up signal handling via sigdelayed even if the handler address is NULL. This doesn't have any impact on sigwaitinfo scenarios (or at least, I wasn't able to come up with a reproducer) but it breaks signalfd scenarios, where eventually a call to call_signal_handler from sigdelayed will try to call the NULL function. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-04-05Cygwin: signals: setcontext: fix setting sigmaskCorinna Vinschen1-1/+1
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-04-05Cygwin: follow context if changed inside SA_SIGINFO signal handlerCorinna Vinschen1-1/+10
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-04-04Cygwin: signals: make setcontext work from signal handlersCorinna Vinschen1-0/+1
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-04-03Cygwin: signals: restore sigmask from context given to signal handlerCorinna Vinschen1-1/+2
In case SA_SIGINFO flag is given, the signal handler may change the context and the application is supposed to pick up from the changed context. So far we don't do that, so the context given to the signal handler is basically read-only, unless the signal handler calls setcontext or swapcontext. For a start, restore the thread's signal mask from the uc_sigmask value of the context given to the signal handler. If that's feasible for Cygwin, we restore the entire context from the context changed by the signal handler in a followup patch. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-03-24Cygwin: ctrl_c_handler: Use 64 bit timerCorinna Vinschen1-3/+3
Just don't use GetTickCount for obvious reasons Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-22Cygwin: posix timers: reimplement using OS timerCorinna Vinschen1-4/+4
- 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-14Cygwin: signalfd: implement non-polling selectCorinna Vinschen1-0/+8
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-12Cygwin: posix timers: implement timer_getoverrunCorinna Vinschen1-0/+12
- 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>
2018-06-26Cygwin: exceptions: fix FPE exception flagsCorinna Vinschen1-1/+7
The FPE flags for divisions by zero were not implemented Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-03-25Cygwin: delete /dev/kmsg and thus fhandler_mailslot without substitutionCorinna Vinschen1-20/+0
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-01-24Define internal function mythreadname() -- revisedMark Geisert1-2/+2
This new function returns the name of the calling thread; works for both cygthreads and pthreads. All calls to cygthread::name(/*void*/) replaced by calls to mythreadname(/*void*/).
2017-11-27cygwin: convert most #ifndef __x86_64__ to #ifdef __i386__Corinna Vinschen1-2/+2
Address the real offender Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2017-10-09cygwin: initialize variable for stack unwindingMichael Haubenwallner1-1/+1
The third argument of RtlLookupFunctionEntry actually is documented as _Inout_opt_ for both x64 and ARM, although generic doc says _Out_ only. * exceptions.cc (__unwind_single_frame): Initialize hist variable.
2016-11-24Remove redundant check for NULL pointer in cygwin_exception::dump_exceptionCorinna Vinschen1-7/+4
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2016-08-23Send thread names to debuggerJon Turney1-1/+1
GDB since commit 24cdb46e [1] can report and use these names. Add utility function SetThreadName(), which sends a thread name to the debugger. Use that: - to set the default thread name for main thread and newly created pthreads. - in pthread_setname_np() for user thread names. - for helper thread names in cygthread::create() - for helper threads which are created directly with CreateThread. Note that there can still be anonymous threads, created by system or injected DLLs. [1] https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=24cdb46e9f0a694b4fbc11085e094857f08c0419
2016-06-24Drop has_set_thread_stack_guarantee flagCorinna Vinschen1-4/+3
2016-06-23Drop has_restricted_stack_args flagCorinna Vinschen1-6/+0
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-03-24Throughout Cygwin, use u_intN_t or uintN_tCorinna Vinschen1-2/+2
Don't use u_char, u_short, u_int or u_long in Cygwin, unless it refers to the Winsock types. Use u_intN_t in BSD-based sources, unsigned char where strings are concerned, uintN_t otherwise. Also: * net.cc: Fix comment, we're not using u_long anymore. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2016-02-12cygwin: fix errors with GCC 5Yaakov Selkowitz1-2/+2
GCC 5 switched from C89 to C11 by default. This implies a change from GNU to C99 inline by default, which have very different meanings of extern inline vs. static inline: https://gcc.gnu.org/onlinedocs/gcc/Inline.html Marking these as gnu_inline retains the previous behaviour. winsup/cygwin/ * exceptions.cc (exception::handle): Change debugging to int to fix an always-true boolean comparison warning. * include/cygwin/config.h (__getreent): Mark gnu_inline. * winbase.h (ilockcmpexch, ilockcmpexch64): Ditto. Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2015-11-27Fix race condition when waiting for a signalCorinna Vinschen1-2/+2
* cygtls.h (_cygtls::wait_signal_arrived): Renamed from set_signal_arrived. (_cygtls::set_signal_arrived): New function signalling signal_arrived. (_cygtls::reset_signal_arrived): Don't reset will_wait_for_signal. (_cygtls::unwait_signal_arrived): New function only resetting will_wait_for_signal. (class wait_signal_arrived): Rename from set_signal_arrived. Accommodate name change throughout Cygwin. (wait_signal_arrived::~wait_signal_arrived): Call _cygtls::unwait_signal_arrived. Add comment. * cygserver_ipc.h (ipc_set_proc_info): Fetch signal_arrived handle via call to _cygtls::get_signal_arrived. * exceptions.cc (_cygtls::interrupt_setup): Signal signal_arrived via call to _cygtls::set_signal_arrived. (_cygtls::handle_SIGCONT): Ditto. * fhandler_socket.cc (fhandler_socket::wait_for_events): Generate WSAEVENT array prior to entering wait loop. Add cancel event object if available. Remove calls to pthread_testcancel and just call pthread::static_cancel_self if the cancel event object is signalled. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-10-30Avoid double unlock of TLS mutexCorinna Vinschen1-4/+1
* exceptions.cc (sigpacket::process): Avoid potentially double unlocking the TLS mutex. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-08-18exceptions.cc: Drop including ucontext.h.Corinna Vinschen1-1/+0
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-07-23Fix potential buffer overflow in makecontext trampolineCorinna Vinschen1-1/+7
glibc's tst-makecontext2 testcase uncovered a bug in __cont_link_context. If the function misses to reserve shadow space for the calls to setcontext/cygwin_exit, both functions could overwrite memory beyond the stack configured in uc_stack. * exceptions.cc (__cont_link_context): x86_64: align stack and reserve shadow space for subsequent function calls, otherwise suffer potential buffer overflow. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-07-19Reduce stack pressure throughout CygwinCorinna Vinschen1-19/+19
* dcrt0.cc (initial_env): Reduce size of local path buffers to PATH_MAX. Allocate debugger_command from process heap. (init_windows_system_directory): Very early initialize new global variable global_progname. * dll_init.cc (dll_list::alloc): Make path buffer static. Explain why. (dll_list::populate_deps): Use tmp_pathbuf for local path buffer. * exceptions.cc (debugger_command): Convert to PWCHAR. (error_start_init): Allocate debugger_command and fill with wide char strings. Only allocate if NULL. (try_to_debug): Just check if debugger_command is a NULL pointer to return. Drop conversion from char to WCHAR and drop local variable dbg_cmd. * globals.cc (global_progname): New global variable to store Windows application path. * pinfo.cc (pinfo_basic::pinfo_basic): Just copy progname over from global_progname. (pinfo::status_exit): Let path_conv create the POSIX path to avoid local buffer. * pseudo_reloc.cc (__report_error): Utilize global_progname, drop local buffer. * smallprint.cc (__small_vsprintf): Just utilize global_progname for %P format specifier. (__small_vswprintf): Ditto. * strace.cc (PROTECT): Change to reflect x being a pointer. Reformat. (CHECK): Ditto. Reformat. (strace::activate): Utilize global_progname, drop local buffer. Fix formatting. (strace::vsprntf): Reduce size of local progname buffer to NAME_MAX. Copy and, if necessary, convert only the last path component to progname. (strace_buf_guard): New muto. (buf): New static pointer. (strace::vprntf): Use buf under strace_buf_guard lock only. Allocate buffer space for buf on Windows heap. * wow64.cc (wow64_respawn_process): Utilize global_progname, drop local path buffer. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-07-18Rearrange makecontext and add lots of commentsCorinna Vinschen1-12/+37
* exceptions.cc (makecontext): Rearrange order of initialization and document at great length. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-07-17Fix ucontext creation in call_signal handlerCorinna Vinschen1-4/+15
* exceptions.cc (__unwind_single_frame): Define empty macro on i686. (_cygtls::call_signal_handler): Try to make sure signal context makes sense in case we're generating context here. Add comment to explain. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-07-17Comment fixupCorinna Vinschen1-6/+6
* exceptions.cc (getcontext/x86_64): Drop comment on RtlCaptureContext. (swapcontext/x86_64): Fix comment yet again. (getcontext/i686): Move comment from x86_64 getcontext, slightly rearranged, to preceeding comment. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-07-17Reuse __unwind_single_frame where appropriateCorinna Vinschen1-58/+32
* exceptions.cc (__unwind_single_frame): Move up in file to be accessible from other places. Move comment to getcontext. (stack_info::walk): Call __unwind_single_frame in 64 bit case. Fix preceeding comment. (myfault_altstack_handler): Call __unwind_single_frame. (getcontext): Give comment from __unwind_single_frame a new home. (swapcontext): Fix comment. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-07-17Implement getcontext, setcontext, makecontext, swapcontextCorinna Vinschen1-0/+224
* common.din (getcontext): Export. (makecontext): Export. (setcontext): Export. (swapcontext): Export. * exceptions.cc (__unwind_single_frame): New static functions, 64 bit only. (setcontext): New function. (getcontext): New function. (swapcontext): New function. (__cont_link_context): New function. (makecontext): New function. * include/cygwin/version.h (CYGWIN_VERSION_DLL_MAJOR): Bump to 2002. (CYGWIN_VERSION_API_MINOR): Bump. * include/ucontext.h (getcontext): Add prototype. (setcontext): Ditto. (swapcontext): Ditto. (makecontext): Ditto. * ntdll.h (NtContinue): Ditto. * new-features.xml (ov-new2.2): Add new section. Document getcontext, setcontext, makecontext, swapcontext. * posix.xml (std-deprec): Add getcontext, setcontext, makecontext, swapcontext. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-07-13exceptions.cc: Reenable code only disabled for debug purposesCorinna Vinschen1-2/+0
* exceptions.cc (exception::handle): Reenable code only disabled for debug purposes. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-07-07x86_64: Handle myfault exceptions when running on alternate signal stackCorinna Vinschen1-0/+46
x86_64 only: * cygtls.cc (san::leave): Restore _my_tls.andreas. * cygtls.h (class san): Add _clemente as in 32 bit case. Add ret and frame members. (san::san): Handle _my_tls.andreas as on 32 bit. Take parameter and write it to new member ret. Store current stack pointer in frame. (san::~san): New destructor to restore _my_tls.andreas. (__try): Use __l_except address as parameter to san::san. * dcrt0.cc (dll_crt0_0): Add myfault_altstack_handler as vectored continuation handler. * exception.h (myfault_altstack_handler): Declare. * exceptions.cc (myfault_altstack_handler): New function. Explain what it's good for. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-07-04Fix original stack when running signal handler on alternate stackCorinna Vinschen1-21/+121
* autoload.cc (SetThreadStackGuarantee): Import. * cygtls.h (struct _cygtls): Replace thread_context with a ucontext_t called context. * exceptions.cc (exception::handle): Exit from process via signal_exit in case sig_send returns from handling a stack overflow SIGSEGV. Explain why. (dumpstack_overflow_wrapper): Thread wrapper to create a stackdump from another thread. (signal_exit): Fix argument list to reflect three-arg signal handler. In case we have to create a stackdump for a stack overflow condition, do so from a separate thread. Explain why. (sigpacket::process): Don't run signal_exit on alternate stack. (altstack_wrapper): Wrapper function to do stack correction when calling the signal handler on an alternate stack to handle a stack overflow. Make sure to have lots of comments. (_cygtls::call_signal_handler): Drop local context variable to reduce stack pressure. Use this->context instead. Change inline assembler to call altstack_wrapper. (_cygtls::signal_debugger): Accommodate aforementioned change to struct _cygtls. * tlsoffset.h: Regenerate. * tlsoffset64.h: Regenerate. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-06-27Handle ss_flags value longjmp safe.Corinna Vinschen1-4/+0
* 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-22Don't push on original stack during alternate signal stack setupCorinna Vinschen1-56/+49
* exceptions.cc (_cygtls::call_signal_handler): Drop pushing a register on the original stack, it confuses GCC. Rearrange the assembler code so that $rax/$eax is not used by GCC to prepare an argument value. Use $rax/$eax without saving. Drop clearing $rbp/$epb. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-06-21Safe all clobbered volatile registers when using alternate stackCorinna Vinschen1-22/+47
* exceptions.cc (_cygtls::call_signal_handler): Drop subtracting 16 bytes from the alternate stack, it's not necessary. Safe all clobbered registers. Safe one on the orignal stack, the others on the alternate stack on both platforms. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-06-20Fix commentsCorinna Vinschen1-2/+2
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>