Commit Graph

451 Commits

Author SHA1 Message Date
Jon TURNEY bccc0e83e8 Set mcontext.cr2 to the faulting address
* exceptions.cc (call_signal_handler): Set mcontext.cr2 to the
	faulting address.

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
2015-04-23 21:58:33 +02:00
Jon TURNEY 9043956ce8 Only construct ucontext for SA_SIGINFO signal handlers
* exceptions.cc (call_signal_handler): Only bother to construct
	the ucontext for signal handlers with SA_SIGINFO set.  Set
	mcontext.oldmask.

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
2015-04-23 21:58:32 +02:00
Jon TURNEY 65c071bc4d Initialize context before RtlContextCapture
* exceptions.cc (call_signal_handler): Zero initialize context and set
	context flags, as RlCaptureContext doesn't.

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
2015-04-23 21:58:32 +02:00
Jon TURNEY 9e8932d6da Provide ucontext to signal handlers
Add ucontext.h header, defining ucontext_t and mcontext_t types.

Provide sigaction sighandlers with a ucontext_t parameter, containing stack and
context information.

	* include/sys/ucontext.h : New header.
	* include/ucontext.h : Ditto.
	* exceptions.cc (call_signal_handler): Provide ucontext_t
	parameter to signal handler function.

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
2015-04-23 21:57:10 +02:00
Corinna Vinschen 3fb21f9143 Prepare to rename/reuse struct ucontext.
* cygtls.h (struct _cygtls): Convert thread_context to type CONTEXT.
	* exceptions.cc (_cygtls::signal_debugger): Use sizeof (CONTEXT) for
	size of CONTEXT copied for GDB's digestion.
	* include/cygwin/signal.h: Add a preliminary comment.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-04-23 21:57:07 +02:00
Jon TURNEY e9e47b8ce6 Teach stackinfo::walk() how to virtually unwind the tls sigstack
This improves how stackinfo::dumpstack() dumps _sigbe and sigdelayed frames

	* exceptions.cc (stack_info): Add sigstackptr member.
	(walk): Unwind sigstackptr inside _sigbe and sigdelayed.
	* gendef (_sigdelayed_end): Add symbol to mark end of sigdelayed.

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
2015-03-13 13:05:52 +00:00
Corinna Vinschen 26158dc3e9 * cygheap.cc (init_cygheap::init_tls_list): Accommodate threadlist
having a new type threadlist_t *.  Convert commented out code into an
	#if 0.  Create thread mutex.  Explain why.
	(init_cygheap::remove_tls): Drop timeout value.  Always wait infinitely
	for tls_sentry.  Return mutex HANDLE of just deleted threadlist entry.
	(init_cygheap::find_tls): New implementation taking tls pointer as
	search parameter.  Return threadlist_t *.
	(init_cygheap::find_tls): Return threadlist_t *.  Define ix as auto
	variable.  Drop exception handling since crash must be made impossible
	due to correct synchronization.  Return with locked mutex.
	* cygheap.h (struct threadlist_t): Define.
	(struct init_cygheap): Convert threadlist to threadlist_t type.
	(init_cygheap::remove_tls): Align declaration to above change.
	(init_cygheap::find_tls): Ditto.
	(init_cygheap::unlock_tls): Define.
	* cygtls.cc (_cygtls::remove): Unlock and close mutex when finishing.
	* exceptions.cc (sigpacket::process): Lock _cygtls area of thread before
	accessing it.
	* fhandler_termios.cc (fhandler_termios::bg_check): Ditto.
	* sigproc.cc (sig_send): Ditto.
	* thread.cc (pthread::exit): Ditto.  Add comment.
	(pthread::cancel): Ditto.
2014-11-28 20:46:13 +00:00
Corinna Vinschen 3f3bd10104 * Throughout, use __try/__except/__endtry blocks, rather than myfault
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-22 09:21:33 +00:00
Corinna Vinschen 3dab1e488a * exceptions.cc (exception::myfault_handle): Rephrase comment. 2014-07-09 10:41:11 +00:00
Corinna Vinschen 64cfc4ac5a * exceptions.cc (exception::myfault_handle): Fix typo in comment. 2014-07-09 10:21:05 +00:00
Corinna Vinschen e1d158a04f * exceptions.cc (exception::myfault_handle): Disable handling
STATUS_STACK_OVERFLOW.  Explain why.
2014-07-07 19:58:16 +00:00
Corinna Vinschen 4337e28e62 * exceptions.cc (try_to_debug): Free environment pointer when not used
anymore (CID 59968).
2014-06-23 13:23:14 +00:00
Corinna Vinschen f2e040ce76 * exceptions.cc (try_to_debug): Fix size of dbg_cmd (CID 59929). 2014-05-19 10:28:54 +00:00
Corinna Vinschen 09a7cdcc4b * exceptions.cc (exception::myfault_handle): Only handle the minimum
amount of exceptions the myfault handler was designed for.
2014-04-09 19:20:01 +00:00
Christopher Faylor c6eaf1f3f7 * DevNotes: Add entry cgf-000025.
* exceptions.cc (_cygtls::signal_debugger): Reorganize to avoid contacting the
debugger if we have already done so via the exception handler.  Eliminate need
for goto.  Remove an ifdef in favor of just allocating a larger buffer.
2014-03-29 21:16:09 +00:00
Corinna Vinschen 20738749f6 * dcrt0.cc (dll_crt0_0): Install myfault exception handler on x86_64.
* exception.h (exception_list): Typedef as void on x86_64.
	(exception::handler_installed): Remove.
	(exception::handle_while_being_debugged): Remove.
	(exception::myfault_handle): Declare for x86_64.
	(exception::handle): Declare as ordinary exception handler on x86_64
	as well.
	(exception::exception): Drop previous code (again).  Install
	exception::handle as SEH handler.
	(exception::install_myfault_handler): New x86_64-only method to
	install exception::myfault_handle as VEH handler.  Explain why.
	(exception::~exception): For x86_64, define frame end label (again).
	* exceptions.cc (CYG_EXC_CONTINUE_EXECUTION): Drop definition.
	(CYG_EXC_CONTINUE_SEARCH): Ditto.
	(exception::myfault_handle): New x86_64-only method, VEH handler to
	handle myfault exceptions.
	(exception::handle): Define as ordinary exception handler on x86_64
	as well.  Use ExceptionContinueExecution and ExceptionContinueSearch
	throughout instead of deleted Cygwin macros.  Don't handle myfault
	exceptions on x86_64.
2014-03-28 22:31:53 +00:00
Corinna Vinschen c16097ed26 * exceptions.cc (_cygtls::signal_debugger): Move memcpy to copy context
from incoming siginfo_t to thread_context, too.
2014-03-28 16:56:03 +00:00
Corinna Vinschen 2c1e724ba4 * exception.h (exception::handle_while_being_debugged): Declare.
(exception::exception): Install unhandled exception filter.
	* exceptions.cc (exception::handle_while_being_debugged): New method.
2014-03-19 16:08:21 +00:00
Corinna Vinschen 8c0389d330 Partially revert patch from 2014-03-04.
* exception.h (exception::handler_installed): Declare.
	(exception::exception): Install vectored exception handler on x86_64.
	(exception::~exception): Remove for x86_64.
	* exceptions.cc (exception::handler_installed): Define.
2014-03-18 13:51:18 +00:00
Corinna Vinschen 4e3c8d9425 * exception.h (exception::handler_installed): Remove.
(exception::exception): Remove old code.  Manually install SEH handler
	instead.
	(exception::~exception): For x86_64, define frame end label.
	* exceptions.cc (exception::handler_installed): Remove.
2014-03-04 11:56:42 +00:00
Christopher Faylor 8aca67421d * exceptions.h (cygwin_exception::open_stackdumpfile): Move old function into
class.
(cygwin_exception::h): New member.
(cygwin_exception::cygwin_exception): Initialize h to NULL.
* exceptions.cc (cygwin_exception::open_stackdumpfile): Move into
cygwin_exception class.  Use 'h' class member.
(cygwin_exception::dumpstack): Close stack dump file handle if opened.
2014-01-08 16:51:20 +00:00
Christopher Faylor ae8456bdf2 * globals.cc (hntdll): Define/declare.
* exceptions.cc (inside_kernel): Don't call GetModuleFileName if we know we're
in ntdll.
* sigproc.cc (wait_sig): Initialize hntdll.
2013-12-09 20:32:24 +00:00
Corinna Vinschen d2a88d9792 Throughout, drop unnecessary explicit includes of windows header files
included by default.
	* winlean.h: Add long comment to explain why we have to define certain
	symbols.
	(_NORMALIZE_): Define.
	(_WINNLS_): Drop definition and subsequent undef.
	(_WINNETWK_): Ditto.
	(_WINSVC_): Ditto.

2013-11-23  Eric Blake  <eblake@redhat.com>
2013-11-24 12:13:36 +00:00
Christopher Faylor d31805a14c * exceptions.cc (signal_exit): Remove comment. Use __builtin_frame_address. 2013-07-20 17:11:44 +00:00
Christopher Faylor 5ce53ae0ea * exceptions.cc (signal_exit): Nope. Nevermind. Dump core unconditionally. 2013-07-20 16:19:51 +00:00
Christopher Faylor efe8407eca reword comment 2013-07-19 23:19:27 +00:00
Christopher Faylor fb6cf945f9 * exceptions.cc (signal_exit): Add a FIXME comment. 2013-07-19 23:13:58 +00:00
Christopher Faylor 3a4dab46c3 * exceptions.cc (signal_exit): Only dump core when it's a "kernel" signal.
Only use RtlCaptureContext on x86_64.  It doesn't seem to do what's expected on
x86.
2013-07-19 23:04:32 +00:00
Christopher Faylor 62003f180a * exceptions.cc (try_to_debug): Don't use yield() when waiting for another
process.
(sigpacket::setup_handler): Fix long-standing problem where loop could exit
with lock held.
2013-06-08 16:54:41 +00:00
Christopher Faylor 5d35299e51 * cygwait.cc (cygwait): Remove lock around sig retrieval since this code is
essentially guarded by thread-specific signal_arrived.
* exceptions.cc (_cygtls::handle_SIGCONT): Simplify.  Eliminate lock/unlock
since code is guarded by signal_arrived.
2013-06-08 14:38:20 +00:00
Christopher Faylor da6461a4d5 * exceptions.cc (_cygtls::handle_SIGCONT): Reinstate previous behavior but make
sure that yield() isn't called when signal stack is locked.
2013-06-07 17:09:56 +00:00
Christopher Faylor 0f38043d8b * exceptions.cc (exception::handle): Add comment explaining si_addr behavior. 2013-06-07 16:05:12 +00:00
Corinna Vinschen b3f0fb6baa * exceptions.cc (_cygtls::handle_SIGCONT): Simplify loop waiting for
sig_handle_tty_stop to wake up.  Make sure to unlock before calling
	yield to avoid starvation of sig_handle_tty_stop.  Add comments.
	* miscfuncs.cc (yield): Explain why yield should never be called under
	_cygtls::lock conditions.  Call SleepEx with 1ms timeout.  Explain why.
2013-06-06 15:29:41 +00:00
Corinna Vinschen fa35814af1 * exceptions.cc (exception::handle): Resurrect accidentally lost
patch from 2009-07-22: Set si_addr according to POSIX for SIGSEGV.
2013-06-02 09:11:09 +00:00
Christopher Faylor cc5bdf003f * exceptions.cc (cygwin_exception::dumpstack): Guard against wild pointer
dereference.
(CYG_EXC_CONTINUE_EXECUTION): Define based on standard Windows definition.
(CYG_EXC_CONTINUE_SEARCH): Ditto.
(exception::handle): Move andreas detection earlier.  Make comment clearer.
(signal_exit): Set core-dumped flag.
2013-04-30 23:47:01 +00:00
Corinna Vinschen 61522196c7 * Merge in cygwin-64bit-branch. 2013-04-23 09:44:36 +00:00
Christopher Faylor 9d2155089e * cygtls.h (_cygtls::reset_signal_arrived): Actually reset the signal_arrived
event.
(_cygtls::handle_SIGCONT): Declare ew function.
* cygwait.cc (is_cw_sig_handle): Delete.
(is_cw_sig_cont): New convenience define.
(cygwait): Clear signal if is_cw_sig_cont and we got a SIGCONT.
* cygwait.h (cw_wait_mask): Add cw_sig_cont.
* exceptions.cc (sig_handle_tty_stop): Tighten "incyg" region.  Use cw_sig_cont
param for cygwait.  Don't zero signal here outside of lock.
(sigpacket::setup_handler): Don't check for in_forkee since we will now never
get here in that state.
(_cygtls::handle_SIGCONT): Define new function.
(sigpacket::process): Call handle_SIGCONT early to deal with SIGCONT.  Nuke
continue_now handling.  Allow SIGKILL to kill a suspended process.  Delete a
couple of now-unneeded labels.
(_cygtls::call_signal_handler): Reorganize setting of incyg within lock.
* sigproc.cc (pending_signals): Simplify.
(pending_signals::clear): New method.
(_cygtls::remove_wq): Reorganize to always close wq.thread_ev if it exists to
avoid handle leaks.
(sig_clear): Simplify by just calling sigq.clear().
(sig_dispatch_pending): Always call sigq.pending even in signal thread to force
another loop in wait_sig.
(sig_send): Remove a "goto out" just before out: label.
(pending_signals::add): Simplify.
(pending_signals::del): Delete.
(pending_signals::next): Delete.
(wait_sig): Define variable q to be the start of the signal queue.  Just
iterate through sigq queue, deleting processed or zeroed signals.  Only set
clearwait when the current signal is SIGCHLD.
* sigproc.h: Add a comment about an unused enum.
2013-04-09 01:01:19 +00:00
Christopher Faylor 8f8eeb70ba * child_info.h (cygheap_exec_info::sigmask): Declare new field.
* cygheap.cc (init_cygheap::find_tls): Rename threadlist_ix -> ix.  Only take
one pass through thread list, looking for eligible threads to signal.  Set a
new param indicating that function has found a sigwait* mask.
* cygheap.h (init_cygheap::find_tls): Reflect new parameter.
* dcrt0.cc (parent_sigmask): New variable.
(child_info_spawn::handle_spawn): Save parent's signal mask here.
(dll_crt0_1): Restore parent's signal mask to tls sigmask as appropriate.  Call
sig_dispatch_pending to flush signal queue when we can finally do something
with signals.
* exceptions.cc (sigpacket::process): Avoid attempting to handle signals if we
haven't finished initializing.  Rely on the fact that find_tls will do mask
checking and don't do it again.  Delete ill-named 'dummy' variable.
* sigproc.cc (cygheap_exec_info::alloc): Save calling thread's signal mask in
new sigmask field.
(wait_sig): Try to debug when WFSO fails and DEBUGGING is defined.
* thread.cc (pthread::set_tls_self_pointer): Make this a true automatic method
rather than inexplicably relying on a thread parameter.
(pthread::thread_init_wrapper): Accommodate set_tls_self_pointer change to
non-static.  Initialize sigmask before setting tid or suffer signal races.
* ehread.h (pthread::set_tls_self_pointer): Make non-static, delete parameter.
2013-03-31 12:35:44 +00:00
Christopher Faylor 1a863e04b3 * exceptions.cc (exception::handle): Generalize comment. 2013-03-28 16:14:53 +00:00
Christopher Faylor 56bc657ce4 * cygtls.h (_cygtls::signal_debugger): Change argument type.
(_cygtls::copy_context): Delete declaration.
* exceptions.cc (exception::handle): Don't call copy_context() here.  Move
signal_handler call earlier and always call it.
(_cygtls::copy_context): Delete definition.
(_cygtls::signal_debugger): Move copy_context logic here.  Suspend thread
receiving signal before gathering context information.
2013-03-09 21:55:18 +00:00
Christopher Faylor 4afefdec51 Remove now-inappropriate comment. 2013-03-01 16:28:09 +00:00
Christopher Faylor aad4a3c932 * exceptions.cc (exception::handle): Eliminate buggy recursed value and just
check if we're exiting.
2013-03-01 15:48:14 +00:00
Christopher Faylor 118e51be1d * DevNotes: Add entry cgf-000022.
* 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-31 05:26:47 +00:00
Christopher Faylor df37bdc5b7 * exceptions.cc (exception::handle): Make attempt to recursively dump stack
fatal.
2013-01-23 05:27:36 +00:00
Christopher Faylor 93ff4bbee0 * dcrt0.cc (dll_crt0_1): Comment assumption.
* exceptions.cc (sigpacket::setup_handler): Avoid sending signals during fork
processing.
2013-01-21 17:17:44 +00:00
Christopher Faylor 6e75c72b89 Throughout, change __attribute__ ((regparm (N))) to just __regN. Throughout,
(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.
2013-01-21 04:34:52 +00:00
Christopher Faylor d5c977948b * exceptions.cc (ctrl_c_handler): Remove special-case handler for
"cygwin_finished_initializing".
* sigproc.cc (exit_thread): Undefine ExitThread earlier to avoid recursion on
error return.
2013-01-19 05:57:06 +00:00
Christopher Faylor b712b4408a * exceptions.cc (signal_exit): Move captive process termintation...
(_cygtls::interrupt_setup): ...into here.
(sigpacket::process): Simplify setting of handler when have_execed.
(_cygtls::interrupt_setup): Don't call proc_subproc when we've execed.
* globals.cc (exit_states): Delete unneeded ES_EXEC_EXIT.
* pinfo.cc (pinfo::exit): Change debugging output.  Call proc_terminate rather
than the now-obsolete sigproc_terminate.  Don't set exit_state to ES_EXEC_EXIT.
Set exit_state to ES_FINAL later.
* sigproc.cc (sigproc_terminate): Delete function.
(wait_sig): Don't call proc_subproc if have_execed.
* sigproc.h (sigproc_terminate): Delete declaration.
* sync.h (lock_process::lock_process): Don't set exit_state to
ES_PROCESS_LOCKED.
(lock_process::operator LONG): Define.
2013-01-14 06:03:59 +00:00
Corinna Vinschen 2b814a1937 * cygerrno.h: Fix copyright.
* exceptions.cc: Drop comment explaining removed variable.
2013-01-09 16:25:15 +00:00
Christopher Faylor ca77b848e7 * cygtls.h (_cygtls::signal_exit): Delete from class.
* exception.h (cygwin_exception): New class.
(cygwin_exception::dumpstack): Declare new function.
(cygwin_exception::context): Ditto.
(cygwin_exception::dump_exception): Ditto.
* exceptions.cc (cygwin_exception::dump_exception): Move into cygwin_exception
class.  Accommodate new variable names.
(cygwin_exception::dumpstack): Ditto stackdump -> dumpstack.
(exception::handle): Move andreas processing earlier.  Defer signal processing
decisions to the signal thread where they belong.  Pass exception information
to sig_send via new siginfo_t si_cyg field.
(ctrl_c_handler): Wait for SIGHUP signal to be processed since it could cause a
process exit and we don't want races with thread exit lock.
(signal_exit): Move back here from sigproc.cc.  Modify arguments and remove
from sigpacket class.  Decide when to dump core based on signal type.
(sigpacket::process): Handle exiting signals in context of threads rather than
in the signal thread.  Signal debugger on non-Windows signals.  Remove
setup_signal_exit call.
* sigproc.cc (no_signals_available): Remove argument.
(signal_exit_code): Delete.
(close_my_readsig): Ditto.
(_cygtls::signal_exit): Move to exceptions.cc.
(sigproc_terminate): Don't attempt to terminate signal thread.
(setup_signal_exit): Delete.
(exit_thread): Use new si_cyg entry in siginfo_t.
(sig_send): Just use empty initializer for si.  Accommodate change in
no_signals_available argument.
(wait_sig): Remove attempt to "go asynchronous" on process exit.  Delete
__SIGEXIT handling.  Don't ever exit.
* sigproc.h: Remove __SIGEXIT from signal enum.  Renumber.
* include/cygwin/signal.h (siginfo_t): Add si_cyg entry.
2013-01-02 18:34:06 +00:00