From 6a26e3f7acc8fbb838b3c838a2a5cf224382f653 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Fri, 21 Mar 2003 23:45:26 +0000 Subject: [PATCH] Split signal blocking code out of SIGNAL_Reset into SIGNAL_Block. Added SIGTERM handler. --- dlls/ntdll/exception.c | 2 -- dlls/ntdll/signal_i386.c | 61 +++++++++++++++++++++++++------------ dlls/ntdll/signal_powerpc.c | 58 +++++++++++++++++++++++++---------- dlls/ntdll/signal_sparc.c | 58 ++++++++++++++++++++++++----------- include/thread.h | 2 ++ scheduler/sysdeps.c | 2 ++ 6 files changed, 129 insertions(+), 54 deletions(-) diff --git a/dlls/ntdll/exception.c b/dlls/ntdll/exception.c index 6c2335e6951..05aec881bf6 100644 --- a/dlls/ntdll/exception.c +++ b/dlls/ntdll/exception.c @@ -54,8 +54,6 @@ typedef struct # error You must define GET_IP for this CPU #endif -extern void SIGNAL_Unblock(void); - void WINAPI EXC_RtlRaiseException( PEXCEPTION_RECORD, PCONTEXT ); void WINAPI EXC_RtlUnwind( PEXCEPTION_FRAME, LPVOID, PEXCEPTION_RECORD, DWORD, PCONTEXT ); diff --git a/dlls/ntdll/signal_i386.c b/dlls/ntdll/signal_i386.c index fd80bd2f1fb..5ad70a60237 100644 --- a/dlls/ntdll/signal_i386.c +++ b/dlls/ntdll/signal_i386.c @@ -422,8 +422,6 @@ typedef int (*wine_signal_handler)(unsigned int sig); static wine_signal_handler handlers[256]; -static sigset_t all_sigs; - extern void WINAPI EXC_RtlRaiseException( PEXCEPTION_RECORD, PCONTEXT ); /*********************************************************************** @@ -752,17 +750,6 @@ static inline DWORD get_fpu_code( const CONTEXT *context ) } -/*********************************************************************** - * SIGNAL_Unblock - * - * Unblock signals. Called from EXC_RtlRaiseException. - */ -void SIGNAL_Unblock( void ) -{ - sigprocmask( SIG_UNBLOCK, &all_sigs, NULL ); -} - - /********************************************************************** * do_segv * @@ -1105,6 +1092,18 @@ static HANDLER_DEF(abrt_handler) } +/********************************************************************** + * term_handler + * + * Handler for SIGTERM. + */ +static HANDLER_DEF(term_handler) +{ + init_handler( HANDLER_CONTEXT ); + SYSDEPS_AbortThread(0); +} + + /********************************************************************** * usr1_handler * @@ -1197,13 +1196,12 @@ BOOL SIGNAL_Init(void) } #endif /* HAVE_SIGALTSTACK */ - sigfillset( &all_sigs ); - if (set_handler( SIGINT, have_sigaltstack, (void (*)())int_handler ) == -1) goto error; if (set_handler( SIGFPE, have_sigaltstack, (void (*)())fpe_handler ) == -1) goto error; if (set_handler( SIGSEGV, have_sigaltstack, (void (*)())segv_handler ) == -1) goto error; if (set_handler( SIGILL, have_sigaltstack, (void (*)())segv_handler ) == -1) goto error; if (set_handler( SIGABRT, have_sigaltstack, (void (*)())abrt_handler ) == -1) goto error; + if (set_handler( SIGTERM, have_sigaltstack, (void (*)())term_handler ) == -1) goto error; if (set_handler( SIGUSR1, have_sigaltstack, (void (*)())usr1_handler ) == -1) goto error; #ifdef SIGBUS if (set_handler( SIGBUS, have_sigaltstack, (void (*)())segv_handler ) == -1) goto error; @@ -1226,13 +1224,14 @@ BOOL SIGNAL_Init(void) /********************************************************************** - * SIGNAL_Reset + * SIGNAL_Block + * + * Block the async signals. */ -void SIGNAL_Reset(void) +void SIGNAL_Block(void) { sigset_t block_set; - /* block the async signals */ sigemptyset( &block_set ); sigaddset( &block_set, SIGALRM ); sigaddset( &block_set, SIGIO ); @@ -1240,12 +1239,36 @@ void SIGNAL_Reset(void) sigaddset( &block_set, SIGUSR1 ); sigaddset( &block_set, SIGUSR2 ); sigprocmask( SIG_BLOCK, &block_set, NULL ); +} - /* restore default handlers */ + +/*********************************************************************** + * SIGNAL_Unblock + * + * Unblock signals. Called from EXC_RtlRaiseException. + */ +void SIGNAL_Unblock(void) +{ + sigset_t all_sigs; + + sigfillset( &all_sigs ); + sigprocmask( SIG_UNBLOCK, &all_sigs, NULL ); +} + + +/********************************************************************** + * SIGNAL_Reset + * + * Restore the default handlers. + */ +void SIGNAL_Reset(void) +{ signal( SIGINT, SIG_DFL ); signal( SIGFPE, SIG_DFL ); signal( SIGSEGV, SIG_DFL ); signal( SIGILL, SIG_DFL ); + signal( SIGABRT, SIG_DFL ); + signal( SIGTERM, SIG_DFL ); #ifdef SIGBUS signal( SIGBUS, SIG_DFL ); #endif diff --git a/dlls/ntdll/signal_powerpc.c b/dlls/ntdll/signal_powerpc.c index b3d279ae6a7..ee3a52c39c7 100644 --- a/dlls/ntdll/signal_powerpc.c +++ b/dlls/ntdll/signal_powerpc.c @@ -76,8 +76,6 @@ typedef int (*wine_signal_handler)(unsigned int sig); static wine_signal_handler handlers[256]; -static sigset_t all_sigs; - extern void WINAPI EXC_RtlRaiseException( PEXCEPTION_RECORD, PCONTEXT ); /*********************************************************************** @@ -190,16 +188,6 @@ static inline DWORD get_fpu_code( const CONTEXT *context ) } -/*********************************************************************** - * SIGNAL_Unblock - * - * Unblock signals. Called from EXC_RtlRaiseException. - */ -void SIGNAL_Unblock( void ) -{ - sigprocmask( SIG_UNBLOCK, &all_sigs, NULL ); -} - /********************************************************************** * segv_handler * @@ -403,6 +391,17 @@ static HANDLER_DEF(abrt_handler) } +/********************************************************************** + * term_handler + * + * Handler for SIGTERM. + */ +static HANDLER_DEF(term_handler) +{ + SYSDEPS_AbortThread(0); +} + + /********************************************************************** * usr1_handler * @@ -474,6 +473,7 @@ BOOL SIGNAL_Init(void) if (set_handler( SIGSEGV, have_sigaltstack, (void (*)())segv_handler ) == -1) goto error; if (set_handler( SIGILL, have_sigaltstack, (void (*)())segv_handler ) == -1) goto error; if (set_handler( SIGABRT, have_sigaltstack, (void (*)())abrt_handler ) == -1) goto error; + if (set_handler( SIGTERM, have_sigaltstack, (void (*)())term_handler ) == -1) goto error; if (set_handler( SIGUSR1, have_sigaltstack, (void (*)())usr1_handler ) == -1) goto error; #ifdef SIGBUS if (set_handler( SIGBUS, have_sigaltstack, (void (*)())segv_handler ) == -1) goto error; @@ -491,13 +491,14 @@ BOOL SIGNAL_Init(void) /********************************************************************** - * SIGNAL_Reset + * SIGNAL_Block + * + * Block the async signals. */ -void SIGNAL_Reset(void) +void SIGNAL_Block(void) { sigset_t block_set; - /* block the async signals */ sigemptyset( &block_set ); sigaddset( &block_set, SIGALRM ); sigaddset( &block_set, SIGIO ); @@ -505,12 +506,36 @@ void SIGNAL_Reset(void) sigaddset( &block_set, SIGUSR1 ); sigaddset( &block_set, SIGUSR2 ); sigprocmask( SIG_BLOCK, &block_set, NULL ); +} - /* restore default handlers */ + +/*********************************************************************** + * SIGNAL_Unblock + * + * Unblock signals. Called from EXC_RtlRaiseException. + */ +void SIGNAL_Unblock(void) +{ + sigset_t all_sigs; + + sigfillset( &all_sigs ); + sigprocmask( SIG_UNBLOCK, &all_sigs, NULL ); +} + + +/********************************************************************** + * SIGNAL_Reset + * + * Restore the default handlers. + */ +void SIGNAL_Reset(void) +{ signal( SIGINT, SIG_DFL ); signal( SIGFPE, SIG_DFL ); signal( SIGSEGV, SIG_DFL ); signal( SIGILL, SIG_DFL ); + signal( SIGABRT, SIG_DFL ); + signal( SIGTERM, SIG_DFL ); #ifdef SIGBUS signal( SIGBUS, SIG_DFL ); #endif @@ -519,6 +544,7 @@ void SIGNAL_Reset(void) #endif } + /********************************************************************** * __wine_enter_vm86 (NTDLL.@) */ diff --git a/dlls/ntdll/signal_sparc.c b/dlls/ntdll/signal_sparc.c index 1ba4038681c..3019e8b1463 100644 --- a/dlls/ntdll/signal_sparc.c +++ b/dlls/ntdll/signal_sparc.c @@ -49,8 +49,6 @@ typedef int (*wine_signal_handler)(unsigned int sig); static wine_signal_handler handlers[256]; -static sigset_t all_sigs; - extern void WINAPI EXC_RtlRaiseException( PEXCEPTION_RECORD, PCONTEXT ); /*********************************************************************** @@ -368,6 +366,17 @@ static HANDLER_DEF(abrt_handler) } +/********************************************************************** + * term_handler + * + * Handler for SIGTERM. + */ +static HANDLER_DEF(term_handler) +{ + SYSDEPS_AbortThread(0); +} + + /********************************************************************** * usr1_handler * @@ -410,17 +419,6 @@ int __wine_set_signal_handler(unsigned int sig, wine_signal_handler wsh) } -/*********************************************************************** - * SIGNAL_Unblock - * - * Unblock signals. Called from EXC_RtlRaiseException. - */ -void SIGNAL_Unblock( void ) -{ - sigprocmask( SIG_UNBLOCK, &all_sigs, NULL ); -} - - /********************************************************************** * SIGNAL_Init */ @@ -435,6 +433,7 @@ BOOL SIGNAL_Init(void) if (set_handler( SIGBUS, (void (*)())bus_handler ) == -1) goto error; if (set_handler( SIGTRAP, (void (*)())trap_handler ) == -1) goto error; if (set_handler( SIGABRT, (void (*)())abrt_handler ) == -1) goto error; + if (set_handler( SIGTERM, (void (*)())term_handler ) == -1) goto error; if (set_handler( SIGUSR1, (void (*)())usr1_handler ) == -1) goto error; return TRUE; @@ -445,13 +444,14 @@ BOOL SIGNAL_Init(void) /********************************************************************** - * SIGNAL_Reset + * SIGNAL_Block + * + * Block the async signals. */ -void SIGNAL_Reset(void) +void SIGNAL_Block(void) { sigset_t block_set; - /* block the async signals */ sigemptyset( &block_set ); sigaddset( &block_set, SIGALRM ); sigaddset( &block_set, SIGIO ); @@ -459,14 +459,38 @@ void SIGNAL_Reset(void) sigaddset( &block_set, SIGUSR1 ); sigaddset( &block_set, SIGUSR2 ); sigprocmask( SIG_BLOCK, &block_set, NULL ); +} - /* restore default handlers */ + +/*********************************************************************** + * SIGNAL_Unblock + * + * Unblock signals. Called from EXC_RtlRaiseException. + */ +void SIGNAL_Unblock(void) +{ + sigset_t all_sigs; + + sigfillset( &all_sigs ); + sigprocmask( SIG_UNBLOCK, &all_sigs, NULL ); +} + + +/********************************************************************** + * SIGNAL_Reset + * + * Restore the default handlers. + */ +void SIGNAL_Reset(void) +{ signal( SIGINT, SIG_DFL ); signal( SIGFPE, SIG_DFL ); signal( SIGSEGV, SIG_DFL ); signal( SIGILL, SIG_DFL ); signal( SIGBUS, SIG_DFL ); signal( SIGTRAP, SIG_DFL ); + signal( SIGABRT, SIG_DFL ); + signal( SIGTERM, SIG_DFL ); } diff --git a/include/thread.h b/include/thread.h index a04cb9b4928..5dab1a6bdf7 100644 --- a/include/thread.h +++ b/include/thread.h @@ -153,6 +153,8 @@ extern void DECLSPEC_NORETURN SYSDEPS_SwitchToThreadStack( void (*func)(void) ); /* signal handling */ extern BOOL SIGNAL_Init(void); +extern void SIGNAL_Block(void); +extern void SIGNAL_Unblock(void); extern void SIGNAL_Reset(void); #endif /* __WINE_THREAD_H */ diff --git a/scheduler/sysdeps.c b/scheduler/sysdeps.c index b1408537c15..a02a0dc29a6 100644 --- a/scheduler/sysdeps.c +++ b/scheduler/sysdeps.c @@ -284,6 +284,7 @@ void SYSDEPS_ExitThread( int status ) info.stack_size = meminfo.RegionSize + ((char *)teb->stack_top - (char *)meminfo.AllocationBase); info.status = status; + SIGNAL_Block(); SIGNAL_Reset(); VirtualFree( teb->stack_base, 0, MEM_RELEASE | MEM_SYSTEM ); @@ -304,6 +305,7 @@ void SYSDEPS_ExitThread( int status ) */ void SYSDEPS_AbortThread( int status ) { + SIGNAL_Block(); SIGNAL_Reset(); close( NtCurrentTeb()->wait_fd[0] ); close( NtCurrentTeb()->wait_fd[1] );