Commit 1eeed685 authored by Alexandre Julliard's avatar Alexandre Julliard

Moved signal handling to exception.c, generate exceptions on signals.

Added hook for debugger in exception handling (temporary).
parent 66f53a8a
......@@ -54,7 +54,7 @@ typedef int INT32;
#include "heap.h"
#include "dc.h"
#include "win.h"
#include "miscemu.h"
#include "wine/exception.h"
#include "ddraw.h"
#include "d3d.h"
#include "debug.h"
......@@ -3384,7 +3384,7 @@ static HRESULT WINAPI DGA_IDirectDrawImpl_SetDisplayMode(
TSXF86DGASetViewPort(display,DefaultScreen(display),0,0);
#ifdef RESTORE_SIGNALS
SIGNAL_InitHandlers();
EXC_InitHandlers();
#endif
return DD_OK;
#else /* defined(HAVE_LIBXXF86DGA) */
......@@ -3816,7 +3816,7 @@ static HRESULT WINAPI DGA_IDirectDraw2Impl_RestoreDisplayMode(LPDIRECTDRAW2 ifac
Sleep(1000);
TSXF86DGADirectVideo(display,DefaultScreen(display),0);
#ifdef RESTORE_SIGNALS
SIGNAL_InitHandlers();
EXC_InitHandlers();
#endif
return DD_OK;
#else /* defined(HAVE_LIBXXF86DGA) */
......@@ -3869,7 +3869,7 @@ static ULONG WINAPI DGA_IDirectDraw2Impl_Release(LPDIRECTDRAW2 iface) {
#endif
#ifdef RESTORE_SIGNALS
SIGNAL_InitHandlers();
EXC_InitHandlers();
#endif
HeapFree(GetProcessHeap(),0,This);
return 0;
......@@ -4765,7 +4765,7 @@ HRESULT WINAPI DGA_DirectDrawCreate( LPDIRECTDRAW *lplpDD, LPUNKNOWN pUnkOuter)
depth = DefaultDepthOfScreen(X11DRV_GetXScreen());
_common_depth_to_pixelformat(depth, &((*ilplpDD)->d.directdraw_pixelformat), &((*ilplpDD)->d.screen_pixelformat), NULL);
#ifdef RESTORE_SIGNALS
SIGNAL_InitHandlers();
EXC_InitHandlers();
#endif
return DD_OK;
......
......@@ -185,7 +185,6 @@ extern void WINAPI XMS_Handler(CONTEXT*);
extern BOOL SIGNAL_Init(void);
extern void SIGNAL_SetHandler( int sig, void (*func)(), int flags );
extern void SIGNAL_MaskAsyncEvents( BOOL flag );
extern void SIGNAL_InitHandlers(void);
/* misc/aspi.c */
extern void ASPI_DOS_HandleInt(CONTEXT *context);
......
......@@ -159,6 +159,7 @@ typedef struct _CONTEXT /* Note 1 */
#define CR2_sig(context) ((context)->cr2)
#define TRAP_sig(context) ((context)->sc_trapno)
#define ERROR_sig(context) ((context)->sc_err)
#define FPU_sig(context) ((FLOATING_SAVE_AREA*)((context)->i387))
#endif
#ifndef __FreeBSD__
......@@ -280,4 +281,7 @@ typedef DWORD SIGCONTEXT;
#define HANDLER_CONTEXT 0
#endif
/* memory/instr.c */
extern BOOL INSTR_EmulateInstruction( SIGCONTEXT * );
#endif /* __WINE_SIG_CONTEXT_H */
......@@ -10,7 +10,6 @@
#include <unistd.h>
#include <string.h>
#include <signal.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#include <setjmp.h>
......@@ -34,44 +33,12 @@
#include "winsock.h"
#include "global.h"
#include "options.h"
#include "debugger.h"
#include "miscemu.h"
#include "dosexe.h"
#include "thread.h"
#include "wine/exception.h"
#include "debugtools.h"
void (*fnWINE_Debugger)(int,SIGCONTEXT*) = NULL;
void (*ctx_debug_call)(int sig,CONTEXT*ctx)=NULL;
BOOL (*fnINSTR_EmulateInstruction)(SIGCONTEXT*ctx)=NULL;
#ifdef __i386__
/* i386 specific faults */
static const char * const SIGNAL_traps[] =
{
"Division by zero exception", /* 0 */
"Debug exception", /* 1 */
"NMI interrupt", /* 2 */
"Breakpoint exception", /* 3 */
"Overflow exception", /* 4 */
"Bound range exception", /* 5 */
"Invalid opcode exception", /* 6 */
"Device not available exception", /* 7 */
"Double fault exception", /* 8 */
"Coprocessor segment overrun", /* 9 */
"Invalid TSS exception", /* 10 */
"Segment not present exception", /* 11 */
"Stack fault", /* 12 */
"General protection fault", /* 13 */
"Page fault", /* 14 */
"Unknown exception", /* 15 */
"Floating point exception", /* 16 */
"Alignment check exception", /* 17 */
"Machine check exception" /* 18 */
};
#define NB_TRAPS (sizeof(SIGNAL_traps) / sizeof(SIGNAL_traps[0]))
#endif
/* Linux sigaction function */
......@@ -199,114 +166,6 @@ void SIGNAL_MaskAsyncEvents( BOOL flag )
sigprocmask( (flag) ? SIG_BLOCK : SIG_UNBLOCK , &async_signal_set, NULL);
}
extern void SIGNAL_SetHandler( int sig, void (*func)(), int flags );
/**********************************************************************
* SIGNAL_break
*
* Handle Ctrl-C and such
*/
static HANDLER_DEF(SIGNAL_break)
{
HANDLER_INIT();
if (Options.debug && fnWINE_Debugger)
fnWINE_Debugger( signal, HANDLER_CONTEXT ); /* Enter our debugger */
else exit(0);
}
/**********************************************************************
* SIGNAL_trap
*
* SIGTRAP handler.
*/
static HANDLER_DEF(SIGNAL_trap)
{
HANDLER_INIT();
if (fnWINE_Debugger)
fnWINE_Debugger( signal, HANDLER_CONTEXT ); /* Enter our debugger */
}
/**********************************************************************
* SIGNAL_fault
*
* Segfault handler.
*/
static HANDLER_DEF(SIGNAL_fault)
{
const char *fault = "Segmentation fault";
HANDLER_INIT();
#ifdef __i386__
#if defined(TRAP_sig) && defined(CR2_sig)
if (TRAP_sig(HANDLER_CONTEXT) == 0x0e
&& VIRTUAL_HandleFault( (LPVOID)CR2_sig(HANDLER_CONTEXT) ))
return;
#endif
#if defined(TRAP_sig)
/* We don't do alignment checks */
/* FIXME: if we get SEHs, pass the fault through them first? */
if (TRAP_sig(HANDLER_CONTEXT) == 0x11) {
if (EFL_sig(HANDLER_CONTEXT) & 0x00040000) {
/* Disable AC flag, return */
EFL_sig(HANDLER_CONTEXT) &= ~0x00040000;
return;
}
}
#endif
if (fnINSTR_EmulateInstruction &&
fnINSTR_EmulateInstruction( HANDLER_CONTEXT )
)
return;
#ifdef TRAP_sig
if (TRAP_sig( HANDLER_CONTEXT ) < NB_TRAPS)
fault = SIGNAL_traps[TRAP_sig( HANDLER_CONTEXT )];
#endif
if (IS_SELECTOR_SYSTEM(CS_sig(HANDLER_CONTEXT)))
{
MESSAGE("%s in 32-bit code (0x%08lx).\n", fault, EIP_sig(HANDLER_CONTEXT));
}
else
{
MESSAGE("%s in 16-bit code (%04x:%04lx).\n", fault,
(WORD)CS_sig(HANDLER_CONTEXT), EIP_sig(HANDLER_CONTEXT) );
}
#ifdef CR2_sig
MESSAGE("Fault address is 0x%08lx\n",CR2_sig(HANDLER_CONTEXT));
#endif
#endif
if (fnWINE_Debugger)
fnWINE_Debugger( signal, HANDLER_CONTEXT );
else {
MESSAGE("stopping pid %d due to unhandled %s.\n",getpid(),fault);
kill(getpid(),SIGSTOP);
}
}
/**********************************************************************
* SIGNAL_InitHandlers
*/
void SIGNAL_InitHandlers(void)
{
SIGNAL_SetHandler( SIGINT, (void (*)())SIGNAL_break, 1);
SIGNAL_SetHandler( SIGSEGV, (void (*)())SIGNAL_fault, 1);
SIGNAL_SetHandler( SIGILL, (void (*)())SIGNAL_fault, 1);
SIGNAL_SetHandler( SIGFPE, (void (*)())SIGNAL_fault, 1);
#ifdef SIGTRAP
SIGNAL_SetHandler( SIGTRAP, (void (*)())SIGNAL_trap, 1); /* debugger */
#endif
SIGNAL_SetHandler( SIGHUP, (void (*)())SIGNAL_trap, 1); /* forced break*/
#ifdef SIGBUS
SIGNAL_SetHandler( SIGBUS, (void (*)())SIGNAL_fault, 1);
#endif
return;
}
/**********************************************************************
* SIGNAL_Init
......@@ -341,6 +200,6 @@ BOOL SIGNAL_Init(void)
/* ignore SIGPIPE so that WINSOCK can get a EPIPE error instead */
signal (SIGPIPE, SIG_IGN);
SIGNAL_InitHandlers();
EXC_InitHandlers();
return TRUE;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment