* 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.
This commit is contained in:
Christopher Faylor 2013-04-30 23:47:01 +00:00
parent 9379e877da
commit cc5bdf003f
2 changed files with 40 additions and 22 deletions

View File

@ -1,3 +1,14 @@
2013-04-30 Christopher Faylor <me.cygwin2013@cgf.cx>
* 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 Christopher Faylor <me.cygwin2013@cgf.cx> 2013-04-30 Christopher Faylor <me.cygwin2013@cgf.cx>
* i686.din: New file. * i686.din: New file.

View File

@ -344,6 +344,9 @@ void
cygwin_exception::dumpstack () cygwin_exception::dumpstack ()
{ {
static bool already_dumped; static bool already_dumped;
myfault efault;
if (efault.faulted ())
return;
if (already_dumped || cygheap->rlim_core == 0Ul) if (already_dumped || cygheap->rlim_core == 0Ul)
return; return;
@ -553,8 +556,8 @@ bool exception::handler_installed NO_COPY;
int int
exception::handle (LPEXCEPTION_POINTERS ep) exception::handle (LPEXCEPTION_POINTERS ep)
#else #else
#define CYG_EXC_CONTINUE_EXECUTION 0 #define CYG_EXC_CONTINUE_EXECUTION ExceptionContinueExecution
#define CYG_EXC_CONTINUE_SEARCH 1 #define CYG_EXC_CONTINUE_SEARCH ExceptionContinueSearch
int int
exception::handle (EXCEPTION_RECORD *e, exception_list *frame, CONTEXT *in, void *) exception::handle (EXCEPTION_RECORD *e, exception_list *frame, CONTEXT *in, void *)
@ -563,6 +566,9 @@ exception::handle (EXCEPTION_RECORD *e, exception_list *frame, CONTEXT *in, void
static bool NO_COPY debugging; static bool NO_COPY debugging;
_cygtls& me = _my_tls; _cygtls& me = _my_tls;
if (me.andreas)
me.andreas->leave (); /* Return from a "san" caught fault */
#ifdef __x86_64__ #ifdef __x86_64__
EXCEPTION_RECORD *e = ep->ExceptionRecord; EXCEPTION_RECORD *e = ep->ExceptionRecord;
CONTEXT *in = ep->ContextRecord; CONTEXT *in = ep->ContextRecord;
@ -574,8 +580,8 @@ exception::handle (EXCEPTION_RECORD *e, exception_list *frame, CONTEXT *in, void
return CYG_EXC_CONTINUE_EXECUTION; return CYG_EXC_CONTINUE_EXECUTION;
} }
/* If we're exiting, don't do anything here. Returning 1 /* If we're exiting, tell Windows to keep looking for an
tells Windows to keep looking for an exception handler. */ exception handler. */
if (exit_state || e->ExceptionFlags) if (exit_state || e->ExceptionFlags)
return CYG_EXC_CONTINUE_SEARCH; return CYG_EXC_CONTINUE_SEARCH;
@ -689,9 +695,6 @@ exception::handle (EXCEPTION_RECORD *e, exception_list *frame, CONTEXT *in, void
return CYG_EXC_CONTINUE_SEARCH; return CYG_EXC_CONTINUE_SEARCH;
} }
if (me.andreas)
me.andreas->leave (); /* Return from a "san" caught fault */
debug_printf ("In cygwin_except_handler exception %y at %p sp %p", e->ExceptionCode, in->_GR(ip), in->_GR(sp)); debug_printf ("In cygwin_except_handler exception %y at %p sp %p", e->ExceptionCode, in->_GR(ip), in->_GR(sp));
debug_printf ("In cygwin_except_handler signal %d at %p", si.si_signo, in->_GR(ip)); debug_printf ("In cygwin_except_handler signal %d at %p", si.si_signo, in->_GR(ip));
@ -1204,29 +1207,33 @@ signal_exit (int sig, siginfo_t *si)
case SIGTRAP: case SIGTRAP:
case SIGXCPU: case SIGXCPU:
case SIGXFSZ: case SIGXFSZ:
if (try_to_debug ()) sig |= 0x80; /* Flag that we've "dumped core" */
break; if (try_to_debug ())
if (si->si_code != SI_USER && si->si_cyg) break;
((cygwin_exception *) si->si_cyg)->dumpstack (); if (si->si_code != SI_USER && si->si_cyg)
else ((cygwin_exception *) si->si_cyg)->dumpstack ();
{ else
CONTEXT c; {
c.ContextFlags = CONTEXT_FULL; CONTEXT c;
RtlCaptureContext (&c); c.ContextFlags = CONTEXT_FULL;
RtlCaptureContext (&c);
#ifdef __x86_64__ #ifdef __x86_64__
cygwin_exception exc ((PUINT_PTR) _my_tls.thread_context.rbp, &c); cygwin_exception exc ((PUINT_PTR) _my_tls.thread_context.rbp, &c);
#else #else
cygwin_exception exc ((PUINT_PTR) _my_tls.thread_context.ebp, &c); cygwin_exception exc ((PUINT_PTR) _my_tls.thread_context.ebp, &c);
#endif #endif
exc.dumpstack (); exc.dumpstack ();
} }
break; break;
} }
lock_process until_exit (true); lock_process until_exit (true);
if (have_execed || exit_state > ES_PROCESS_LOCKED) if (have_execed || exit_state > ES_PROCESS_LOCKED)
myself.exit (sig); {
debug_printf ("recursive exit?");
myself.exit (sig);
}
/* Starve other threads in a vain attempt to stop them from doing something /* Starve other threads in a vain attempt to stop them from doing something
stupid. */ stupid. */