Commit 3d06d20b authored by Alexandre Julliard's avatar Alexandre Julliard

Moved all signal support to a new platform-specific file.

Make use of the per-thread signal stack (Juergen Lock). Fixed %fs in signal handler for non FS_sig case (Ulrich Weigand).
parent 55c2d900
......@@ -16,6 +16,7 @@ C_SRCS = \
rtl.c \
rtlstr.c \
sec.c \
signal_i386.c \
sync.c \
time.c
......
......@@ -3516,7 +3516,7 @@ static HRESULT WINAPI DGA_IDirectDrawImpl_SetDisplayMode(
TSXF86DGASetViewPort(display,DefaultScreen(display),0,0);
#ifdef RESTORE_SIGNALS
EXC_InitHandlers();
SIGNAL_Init();
#endif
return DD_OK;
}
......@@ -3918,7 +3918,7 @@ static HRESULT WINAPI DGA_IDirectDraw2Impl_RestoreDisplayMode(LPDIRECTDRAW2 ifac
Sleep(1000);
TSXF86DGADirectVideo(display,DefaultScreen(display),0);
#ifdef RESTORE_SIGNALS
EXC_InitHandlers();
SIGNAL_Init();
#endif
return DD_OK;
}
......@@ -3969,7 +3969,7 @@ static ULONG WINAPI DGA_IDirectDraw2Impl_Release(LPDIRECTDRAW2 iface) {
#endif
#ifdef RESTORE_SIGNALS
EXC_InitHandlers();
SIGNAL_Init();
#endif
HeapFree(GetProcessHeap(),0,This);
return 0;
......@@ -4958,7 +4958,7 @@ static HRESULT WINAPI DGA_DirectDrawCreate( LPDIRECTDRAW *lplpDD, LPUNKNOWN pUnk
depth = DefaultDepthOfScreen(X11DRV_GetXScreen());
_common_depth_to_pixelformat(depth, &((*ilplpDD)->d.directdraw_pixelformat), &((*ilplpDD)->d.screen_pixelformat), NULL);
#ifdef RESTORE_SIGNALS
EXC_InitHandlers();
SIGNAL_Init();
#endif
return DD_OK;
......
......@@ -9,7 +9,6 @@
#include <sys/types.h> /* u_long ... */
#include "windef.h"
#include "sig_context.h"
#include "miscemu.h"
#define STEP_FLAG 0x100 /* single step flag */
......
......@@ -10,7 +10,6 @@
#include <sys/types.h> /* pid_t */
#include "winbase.h" /* for LPSTARTUPINFO32A */
#include "winnt.h" /* for PCONTEXT */
#include "sig_context.h"
typedef struct _DOSSYSTEM {
int id;
......
......@@ -184,10 +184,6 @@ extern int DPMI_CallRMProc(CONTEXT86*,LPWORD,int,int);
/* msdos/xms.c */
extern void WINAPI XMS_Handler(CONTEXT86*);
/* loader/signal.c */
extern BOOL SIGNAL_Init(void);
extern void SIGNAL_SetHandler( int sig, void (*func)() );
/* misc/aspi.c */
extern void ASPI_DOS_HandleInt(CONTEXT86 *context);
......
/*
* Signal context definitions
*
* Copyright 1995 Alexandre Julliard
*/
#ifndef __WINE_SIG_CONTEXT_H
#define __WINE_SIG_CONTEXT_H
#ifdef __i386__
#ifdef linux
typedef struct
{
unsigned short sc_gs, __gsh;
unsigned short sc_fs, __fsh;
unsigned short sc_es, __esh;
unsigned short sc_ds, __dsh;
unsigned long sc_edi;
unsigned long sc_esi;
unsigned long sc_ebp;
unsigned long sc_esp;
unsigned long sc_ebx;
unsigned long sc_edx;
unsigned long sc_ecx;
unsigned long sc_eax;
unsigned long sc_trapno;
unsigned long sc_err;
unsigned long sc_eip;
unsigned short sc_cs, __csh;
unsigned long sc_eflags;
unsigned long esp_at_signal;
unsigned short sc_ss, __ssh;
unsigned long i387;
unsigned long oldmask;
unsigned long cr2;
} SIGCONTEXT;
#define __HAVE_SIGCONTEXT
#define HANDLER_DEF(name) void name (int signal, SIGCONTEXT __context)
#define HANDLER_CONTEXT (&__context)
#endif /* linux */
#ifdef BSDI
#define EAX_sig(context) ((context)->tf_eax)
#define EBX_sig(context) ((context)->tf_ebx)
#define ECX_sig(context) ((context)->tf_ecx)
#define EDX_sig(context) ((context)->tf_edx)
#define ESI_sig(context) ((context)->tf_esi)
#define EDI_sig(context) ((context)->tf_edi)
#define EBP_sig(context) ((context)->tf_ebp)
#define CS_sig(context) ((context)->tf_cs)
#define DS_sig(context) ((context)->tf_ds)
#define ES_sig(context) ((context)->tf_es)
#define SS_sig(context) ((context)->tf_ss)
#include <machine/frame.h>
typedef struct trapframe SIGCONTEXT;
#define __HAVE_SIGCONTEXT
#define HANDLER_DEF(name) void name(int signal, int code, SIGCONTEXT *__context)
#define HANDLER_CONTEXT __context
#define EFL_sig(context) ((context)->tf_eflags)
#define EIP_sig(context) (*((unsigned long*)&(context)->tf_eip))
#define ESP_sig(context) (*((unsigned long*)&(context)->tf_esp))
#endif /* bsdi */
#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
#include <signal.h>
typedef struct sigcontext SIGCONTEXT;
#define __HAVE_SIGCONTEXT
#define HANDLER_DEF(name) void name(int signal, int code, SIGCONTEXT *__context)
#define HANDLER_CONTEXT __context
#endif /* FreeBSD */
#if defined(__svr4__) || defined(_SCO_DS) || defined(__sun)
#include <signal.h>
#ifdef _SCO_DS
#include <sys/regset.h>
#endif
/* Solaris kludge */
#undef ERR
#include <sys/ucontext.h>
#undef ERR
typedef struct ucontext SIGCONTEXT;
#define __HAVE_SIGCONTEXT
#define HANDLER_DEF(name) void name(int signal, void *siginfo, SIGCONTEXT *__context)
#define HANDLER_CONTEXT __context
#endif /* svr4 || SCO_DS */
#ifdef __EMX__
typedef struct _fpreg /* Note 1 */
{
ULONG losig;
ULONG hisig;
USHORT signexp;
} FPREG;
typedef FPREG *PFPREG;
typedef struct _CONTEXT /* Note 1 */
{
ULONG ContextFlags;
ULONG ctx_env[7];
FPREG ctx_stack[8];
ULONG ctx_SegGs;
ULONG ctx_SegFs;
ULONG ctx_SegEs;
ULONG ctx_SegDs;
ULONG ctx_RegEdi;
ULONG ctx_RegEsi;
ULONG ctx_RegEax;
ULONG ctx_RegEbx;
ULONG ctx_RegEcx;
ULONG ctx_RegEdx;
ULONG ctx_RegEbp;
ULONG ctx_RegEip;
ULONG ctx_SegCs;
ULONG ctx_EFlags;
ULONG ctx_RegEsp;
ULONG ctx_SegSs;
} SIGCONTEXT;
#define __HAVE_SIGCONTEXT
/*typedef CONTEXTRECORD *PCONTEXTRECORD;*/
#endif /* __EMX__ */
#if defined(linux) || defined(__NetBSD__) || defined(__FreeBSD__) \
|| defined(__OpenBSD__)
#define EAX_sig(context) ((context)->sc_eax)
#define EBX_sig(context) ((context)->sc_ebx)
#define ECX_sig(context) ((context)->sc_ecx)
#define EDX_sig(context) ((context)->sc_edx)
#define ESI_sig(context) ((context)->sc_esi)
#define EDI_sig(context) ((context)->sc_edi)
#define EBP_sig(context) ((context)->sc_ebp)
#define CS_sig(context) ((context)->sc_cs)
#define DS_sig(context) ((context)->sc_ds)
#define ES_sig(context) ((context)->sc_es)
#define SS_sig(context) ((context)->sc_ss)
#ifdef linux
/* FS and GS are now in the sigcontext struct of FreeBSD, but not
* saved by the exception handling. duh.
*/
#define FS_sig(context) ((context)->sc_fs)
#define GS_sig(context) ((context)->sc_gs)
#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__
#define EFL_sig(context) ((context)->sc_eflags)
#else
#define EFL_sig(context) ((context)->sc_efl)
/* FreeBSD, see i386/i386/traps.c::trap_pfault va->err kludge */
#define CR2_sig(context) ((context)->sc_err)
#endif
#define EIP_sig(context) (*((unsigned long*)&(context)->sc_eip))
#define ESP_sig(context) (*((unsigned long*)&(context)->sc_esp))
#endif /* linux || __NetBSD__ || __FreeBSD__ || __OpenBSD__ */
#if defined(__svr4__) || defined(_SCO_DS) || defined(__sun)
#ifdef _SCO_DS
#define gregs regs
#endif
#define EAX_sig(context) ((context)->uc_mcontext.gregs[EAX])
#define EBX_sig(context) ((context)->uc_mcontext.gregs[EBX])
#define ECX_sig(context) ((context)->uc_mcontext.gregs[ECX])
#define EDX_sig(context) ((context)->uc_mcontext.gregs[EDX])
#define ESI_sig(context) ((context)->uc_mcontext.gregs[ESI])
#define EDI_sig(context) ((context)->uc_mcontext.gregs[EDI])
#define EBP_sig(context) ((context)->uc_mcontext.gregs[EBP])
#define CS_sig(context) ((context)->uc_mcontext.gregs[CS])
#define DS_sig(context) ((context)->uc_mcontext.gregs[DS])
#define ES_sig(context) ((context)->uc_mcontext.gregs[ES])
#define SS_sig(context) ((context)->uc_mcontext.gregs[SS])
#define FS_sig(context) ((context)->uc_mcontext.gregs[FS])
#define GS_sig(context) ((context)->uc_mcontext.gregs[GS])
#define EFL_sig(context) ((context)->uc_mcontext.gregs[EFL])
#define EIP_sig(context) ((context)->uc_mcontext.gregs[EIP])
#ifdef R_ESP
#define ESP_sig(context) ((context)->uc_mcontext.gregs[R_ESP])
#else
#define ESP_sig(context) ((context)->uc_mcontext.gregs[ESP])
#endif
#ifdef TRAPNO
#define TRAP_sig(context) ((context)->uc_mcontext.gregs[TRAPNO])
#endif
#endif /* svr4 || SCO_DS */
#ifdef __EMX__
#define EAX_sig(context) ((context)->ctx_RegEax)
#define EBX_sig(context) ((context)->ctx_RegEbx)
#define ECX_sig(context) ((context)->ctx_RegEcx)
#define EDX_sig(context) ((context)->ctx_RegEdx)
#define ESI_sig(context) ((context)->ctx_RegEsi)
#define EDI_sig(context) ((context)->ctx_RegEdi)
#define EBP_sig(context) ((context)->ctx_RegEbp)
#define ESP_sig(context) ((context)->ctx_RegEsp)
#define CS_sig(context) ((context)->ctx_SegCs)
#define DS_sig(context) ((context)->ctx_SegDs)
#define ES_sig(context) ((context)->ctx_SegEs)
#define SS_sig(context) ((context)->ctx_SegSs)
#define FS_sig(context) ((context)->ctx_SegFs)
#define GS_sig(context) ((context)->ctx_SegGs)
#define EFL_sig(context) ((context)->ctx_EFlags)
#define EIP_sig(context) ((context)->ctx_RegEip)
#endif /* __EMX__ */
#ifdef FS_sig
#include "syslevel.h"
#define HANDLER_INIT() \
do { int fs = IS_SELECTOR_SYSTEM(CS_sig(HANDLER_CONTEXT)) ? \
FS_sig(HANDLER_CONTEXT) : SYSLEVEL_Win16CurrentTeb; \
if (!fs) fs = SYSLEVEL_EmergencyTeb; \
SET_FS(fs); } while (0)
#else
#define HANDLER_INIT() \
do { int fs; GET_FS(fs); fs &= 0xffff; \
if (!IS_SELECTOR_SYSTEM(CS_sig(HANDLER_CONTEXT))) \
fs = SYSLEVEL_Win16CurrentTeb; \
if (!fs) fs = SYSLEVEL_EmergencyTeb; \
SET_FS(fs); } while (0)
#endif
#else /* __i386__ */
#define HANDLER_DEF(name) void name (int signal)
#define HANDLER_INIT() /* nothing */
#endif /* __i386__ */
#ifndef __HAVE_SIGCONTEXT
/* empty entry for non x86 architectures mostly. */
typedef DWORD SIGCONTEXT;
#define HANDLER_CONTEXT 0
#endif
#endif /* __WINE_SIG_CONTEXT_H */
......@@ -169,7 +169,7 @@ static inline EXCEPTION_FRAME * WINE_UNUSED EXC_pop_frame( EXCEPTION_FRAME *fram
typedef DWORD (*DEBUGHOOK)( EXCEPTION_RECORD *, CONTEXT *, BOOL );
extern void EXC_SetDebugEventHook( DEBUGHOOK hook );
extern DEBUGHOOK EXC_GetDebugEventHook(void);
extern void EXC_InitHandlers(void);
extern BOOL SIGNAL_Init(void);
#endif
#endif /* __WINE_WINE_EXCEPTION_H */
......@@ -15,7 +15,6 @@ C_SRCS = \
pe_image.c \
pe_resource.c \
resource.c \
signal.c \
task.c
GLUE = task.c
......
......@@ -65,9 +65,6 @@ BOOL MAIN_MainInit(void)
/* Initialize syslevel handling */
SYSLEVEL_Init();
/* Initialize signal handling */
if (!SIGNAL_Init()) return FALSE;
/* Load the configuration file */
if (!PROFILE_LoadWineIni()) return FALSE;
......
/*
* Wine signal handling
*
* Copyright 1995 Alexandre Julliard
*/
#include "config.h"
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <signal.h>
#include <errno.h>
#include <time.h>
#include <setjmp.h>
#include <sys/time.h>
#include <sys/timeb.h>
#include <sys/types.h>
#include <sys/wait.h>
#ifdef HAVE_SYS_PARAM_H
# include <sys/param.h>
#endif
#ifdef HAVE_SYSCALL_H
# include <syscall.h>
#else
# ifdef HAVE_SYS_SYSCALL_H
# include <sys/syscall.h>
# endif
#endif
#include "winsock.h"
#include "global.h"
#include "options.h"
#include "miscemu.h"
#include "dosexe.h"
#include "thread.h"
#include "wine/exception.h"
#include "debugtools.h"
/* Linux sigaction function */
#if defined(linux) && defined(__i386__)
/* This is the sigaction structure from the Linux 2.1.20 kernel. */
#undef sa_handler
struct kernel_sigaction
{
void (*sa_handler)();
unsigned long sa_mask;
unsigned long sa_flags;
void (*sa_restorer)();
};
/* Similar to the sigaction function in libc, except it leaves alone the
restorer field, which is used to specify the signal stack address */
static inline int wine_sigaction( int sig, struct kernel_sigaction *new,
struct kernel_sigaction *old )
{
#ifdef __PIC__
__asm__ __volatile__( "pushl %%ebx\n\t"
"movl %2,%%ebx\n\t"
"int $0x80\n\t"
"popl %%ebx"
: "=a" (sig)
: "0" (SYS_sigaction),
"r" (sig),
"c" (new),
"d" (old) );
#else
__asm__ __volatile__( "int $0x80"
: "=a" (sig)
: "0" (SYS_sigaction),
"b" (sig),
"c" (new),
"d" (old) );
#endif /* __PIC__ */
if (sig>=0)
return 0;
errno = -sig;
return -1;
}
#endif /* linux && __i386__ */
/* Signal stack */
static char SIGNAL_Stack[16384];
/**********************************************************************
* SIGNAL_SetHandler
*/
void SIGNAL_SetHandler( int sig, void (*func)() )
{
int ret;
#if defined(linux) && defined(__i386__)
struct kernel_sigaction sig_act;
sig_act.sa_handler = func;
sig_act.sa_flags = SA_RESTART | SA_NOMASK;
sig_act.sa_mask = 0;
/* Point to the top of the stack, minus 4 just in case, and make
it aligned */
sig_act.sa_restorer =
(void (*)())((int)(SIGNAL_Stack + sizeof(SIGNAL_Stack) - 4) & ~3);
ret = wine_sigaction( sig, &sig_act, NULL );
#else /* linux && __i386__ */
struct sigaction sig_act;
sig_act.sa_handler = func;
sigemptyset( &sig_act.sa_mask );
# if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
sig_act.sa_flags = SA_ONSTACK;
# elif defined (__svr4__) || defined(_SCO_DS)
sig_act.sa_flags = SA_SIGINFO | SA_ONSTACK | SA_RESTART;
# elif defined(__EMX__)
sig_act.sa_flags = 0; /* FIXME: EMX has only SA_ACK and SA_SYSV */
# else
sig_act.sa_flags = 0;
# endif
ret = sigaction( sig, &sig_act, NULL );
#endif /* linux && __i386__ */
if (ret < 0)
{
perror( "sigaction" );
exit(1);
}
}
/**********************************************************************
* SIGNAL_Init
*/
BOOL SIGNAL_Init(void)
{
#ifdef HAVE_WORKING_SIGALTSTACK
struct sigaltstack ss;
ss.ss_sp = SIGNAL_Stack;
ss.ss_size = sizeof(SIGNAL_Stack);
ss.ss_flags = 0;
if (sigaltstack(&ss, NULL) < 0)
{
perror("sigaltstack");
/* fall through on error and try it differently */
}
#endif /* HAVE_SIGALTSTACK */
/* ignore SIGPIPE so that WINSOCK can get a EPIPE error instead */
signal (SIGPIPE, SIG_IGN);
/* automatic child reaping to avoid zombies */
signal (SIGCHLD, SIG_IGN);
EXC_InitHandlers();
return TRUE;
}
......@@ -362,6 +362,9 @@ BOOL PROCESS_Init(void)
if (!(SystemHeap = HeapCreate( HEAP_GROWABLE, 0x10000, 0 ))) return FALSE;
initial_pdb.system_heap = initial_pdb.heap = SystemHeap;
/* Initialize signal handling */
if (!SIGNAL_Init()) return FALSE;
/* Create the environment DB of the first process */
if (!PROCESS_CreateEnvDB()) return FALSE;
......
......@@ -28,6 +28,7 @@ static int *ph_errno = &h_errno;
#include "thread.h"
#include "server.h"
#include "winbase.h"
#include "wine/exception.h"
#include "debugtools.h"
DEFAULT_DEBUG_CHANNEL(thread)
......@@ -130,7 +131,16 @@ static void SYSDEPS_StartThread( TEB *teb )
{
SYSDEPS_SetCurThread( teb );
CLIENT_InitThread();
teb->startup();
SIGNAL_Init();
__TRY
{
teb->startup();
}
__EXCEPT(UnhandledExceptionFilter)
{
TerminateThread( GetCurrentThread(), GetExceptionCode() );
}
__ENDTRY
SYSDEPS_ExitThread(); /* should never get here */
}
......
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