diff --git a/dlls/ntdll/ntdll_misc.h b/dlls/ntdll/ntdll_misc.h index 73e830bdaba..2878b6e3b41 100644 --- a/dlls/ntdll/ntdll_misc.h +++ b/dlls/ntdll/ntdll_misc.h @@ -47,10 +47,16 @@ extern NTSTATUS NTDLL_wait_for_multiple_objects( UINT count, const HANDLE *handl const LARGE_INTEGER *timeout ); /* init routines */ -extern void wine_server_init_process(void); -extern void wine_server_init_thread(void); +extern BOOL SIGNAL_Init(void); extern void thread_init(void); +/* server support */ +extern void server_init_process(void); +extern void server_init_thread(void); +extern void DECLSPEC_NORETURN server_protocol_error( const char *err, ... ); +extern void DECLSPEC_NORETURN server_protocol_perror( const char *err ); +extern void DECLSPEC_NORETURN server_abort_thread( int status ); + /* module handling */ extern BOOL MODULE_GetSystemDirectory( UNICODE_STRING *sysdir ); extern void RELAY_InitDebugLists(void); diff --git a/dlls/ntdll/server.c b/dlls/ntdll/server.c index 54f6966077d..f68eea699d1 100644 --- a/dlls/ntdll/server.c +++ b/dlls/ntdll/server.c @@ -53,6 +53,7 @@ #include "ntstatus.h" #include "thread.h" #include "wine/library.h" +#include "wine/pthread.h" #include "wine/server.h" #include "winerror.h" #include "ntdll_misc.h" @@ -110,6 +111,21 @@ static void fatal_perror( const char *err, ... ) exit(1); } + +/*********************************************************************** + * server_abort_thread + */ +void server_abort_thread( int status ) +{ + sigprocmask( SIG_BLOCK, &block_set, NULL ); + close( NtCurrentTeb()->wait_fd[0] ); + close( NtCurrentTeb()->wait_fd[1] ); + close( NtCurrentTeb()->reply_fd ); + close( NtCurrentTeb()->request_fd ); + wine_pthread_abort_thread( status ); +} + + /*********************************************************************** * server_protocol_error */ @@ -121,7 +137,7 @@ void server_protocol_error( const char *err, ... ) fprintf( stderr, "wine client error:%lx: ", GetCurrentThreadId() ); vfprintf( stderr, err, args ); va_end( args ); - SYSDEPS_AbortThread(1); + server_abort_thread(1); } @@ -132,7 +148,7 @@ void server_protocol_perror( const char *err ) { fprintf( stderr, "wine client error:%lx: ", GetCurrentThreadId() ); perror( err ); - SYSDEPS_AbortThread(1); + server_abort_thread(1); } @@ -167,7 +183,7 @@ static void send_request( const struct __server_request_info *req ) } if (ret >= 0) server_protocol_error( "partial write %d\n", ret ); - if (errno == EPIPE) SYSDEPS_AbortThread(0); + if (errno == EPIPE) server_abort_thread(0); server_protocol_perror( "sendmsg" ); } @@ -195,7 +211,7 @@ static void read_reply_data( void *buffer, size_t size ) server_protocol_perror("read"); } /* the server closed the connection; time to die... */ - SYSDEPS_AbortThread(0); + server_abort_thread(0); } @@ -274,7 +290,7 @@ void wine_server_send_fd( int fd ) if ((ret = sendmsg( fd_socket, &msghdr, 0 )) == sizeof(data)) return; if (ret >= 0) server_protocol_error( "partial write %d\n", ret ); if (errno == EINTR) continue; - if (errno == EPIPE) SYSDEPS_AbortThread(0); + if (errno == EPIPE) server_abort_thread(0); server_protocol_perror( "sendmsg" ); } } @@ -333,7 +349,7 @@ static int receive_fd( obj_handle_t *handle ) server_protocol_perror("recvmsg"); } /* the server closed the connection; time to die... */ - SYSDEPS_AbortThread(0); + server_abort_thread(0); } @@ -600,11 +616,11 @@ static int server_connect( const char *oldcwd, const char *serverdir ) /*********************************************************************** - * wine_server_init_process + * server_init_process * * Start the server and create the initial socket pair. */ -void wine_server_init_process(void) +void server_init_process(void) { int size; char *oldcwd; @@ -646,11 +662,11 @@ void wine_server_init_process(void) /*********************************************************************** - * wine_server_init_thread + * server_init_thread * * Send an init thread request. Return 0 if OK. */ -void wine_server_init_thread(void) +void server_init_thread(void) { TEB *teb = NtCurrentTeb(); int version, ret; diff --git a/dlls/ntdll/signal_i386.c b/dlls/ntdll/signal_i386.c index b3e90a41a3f..0696c9752ca 100644 --- a/dlls/ntdll/signal_i386.c +++ b/dlls/ntdll/signal_i386.c @@ -663,7 +663,7 @@ static EXCEPTION_RECORD *setup_exception( SIGCONTEXT *sigcontext, raise_func fun ERR( "nested exception on signal stack in thread %04lx eip %08lx esp %08lx stack %p-%p\n", GetCurrentThreadId(), EIP_sig(sigcontext), ESP_sig(sigcontext), NtCurrentTeb()->Tib.StackLimit, NtCurrentTeb()->Tib.StackBase ); - SYSDEPS_AbortThread(1); + server_abort_thread(1); } if ((char *)(stack - 1) < (char *)NtCurrentTeb()->Tib.StackLimit + 4096 || @@ -675,7 +675,7 @@ static EXCEPTION_RECORD *setup_exception( SIGCONTEXT *sigcontext, raise_func fun ERR( "stack overflow %u bytes in thread %04lx eip %08lx esp %08lx stack %p-%p\n", diff, GetCurrentThreadId(), EIP_sig(sigcontext), ESP_sig(sigcontext), NtCurrentTeb()->Tib.StackLimit, NtCurrentTeb()->Tib.StackBase ); - SYSDEPS_AbortThread(1); + server_abort_thread(1); } else WARN( "exception outside of stack limits in thread %04lx eip %08lx esp %08lx stack %p-%p\n", GetCurrentThreadId(), EIP_sig(sigcontext), ESP_sig(sigcontext), @@ -1057,7 +1057,7 @@ static HANDLER_DEF(abrt_handler) static HANDLER_DEF(term_handler) { init_handler( HANDLER_CONTEXT ); - SYSDEPS_AbortThread(0); + server_abort_thread(0); } @@ -1178,46 +1178,6 @@ BOOL SIGNAL_Init(void) } -/********************************************************************** - * SIGNAL_Block - * - * Block the async signals. - */ -void SIGNAL_Block(void) -{ - sigset_t block_set; - - sigemptyset( &block_set ); - sigaddset( &block_set, SIGIO ); - sigaddset( &block_set, SIGHUP ); - sigaddset( &block_set, SIGUSR1 ); - sigaddset( &block_set, SIGUSR2 ); - sigprocmask( SIG_BLOCK, &block_set, 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 -#ifdef SIGTRAP - signal( SIGTRAP, SIG_DFL ); -#endif -} - - #ifdef __HAVE_VM86 /********************************************************************** * __wine_enter_vm86 (NTDLL.@) diff --git a/dlls/ntdll/signal_powerpc.c b/dlls/ntdll/signal_powerpc.c index 291a42a085d..9760840a3c3 100644 --- a/dlls/ntdll/signal_powerpc.c +++ b/dlls/ntdll/signal_powerpc.c @@ -572,7 +572,7 @@ static HANDLER_DEF(abrt_handler) */ static HANDLER_DEF(term_handler) { - SYSDEPS_AbortThread(0); + server_abort_thread(0); } @@ -649,47 +649,6 @@ BOOL SIGNAL_Init(void) } -/********************************************************************** - * SIGNAL_Block - * - * Block the async signals. - */ -void SIGNAL_Block(void) -{ - sigset_t block_set; - - sigemptyset( &block_set ); - sigaddset( &block_set, SIGALRM ); - sigaddset( &block_set, SIGIO ); - sigaddset( &block_set, SIGHUP ); - sigaddset( &block_set, SIGUSR1 ); - sigaddset( &block_set, SIGUSR2 ); - sigprocmask( SIG_BLOCK, &block_set, 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 -#ifdef SIGTRAP - signal( SIGTRAP, SIG_DFL ); -#endif -} - - /********************************************************************** * __wine_enter_vm86 (NTDLL.@) */ diff --git a/dlls/ntdll/signal_sparc.c b/dlls/ntdll/signal_sparc.c index e4ac7407862..fd4affe6d90 100644 --- a/dlls/ntdll/signal_sparc.c +++ b/dlls/ntdll/signal_sparc.c @@ -376,7 +376,7 @@ static HANDLER_DEF(abrt_handler) */ static HANDLER_DEF(term_handler) { - SYSDEPS_AbortThread(0); + server_abort_thread(0); } @@ -447,43 +447,6 @@ BOOL SIGNAL_Init(void) } -/********************************************************************** - * SIGNAL_Block - * - * Block the async signals. - */ -void SIGNAL_Block(void) -{ - sigset_t block_set; - - sigemptyset( &block_set ); - sigaddset( &block_set, SIGALRM ); - sigaddset( &block_set, SIGIO ); - sigaddset( &block_set, SIGHUP ); - sigaddset( &block_set, SIGUSR1 ); - sigaddset( &block_set, SIGUSR2 ); - sigprocmask( SIG_BLOCK, &block_set, 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 ); -} - - /********************************************************************** * __wine_enter_vm86 */ diff --git a/dlls/ntdll/sync.c b/dlls/ntdll/sync.c index 5a0383d3fde..8a9b111a8a7 100644 --- a/dlls/ntdll/sync.c +++ b/dlls/ntdll/sync.c @@ -496,7 +496,7 @@ static int wait_reply( void *cookie ) server_protocol_perror("wakeup read"); } /* the server closed the connection; time to die... */ - SYSDEPS_AbortThread(0); + server_abort_thread(0); } diff --git a/dlls/ntdll/sysdeps.c b/dlls/ntdll/sysdeps.c index 4bb0830e544..466e45039e8 100644 --- a/dlls/ntdll/sysdeps.c +++ b/dlls/ntdll/sysdeps.c @@ -86,21 +86,6 @@ void SYSDEPS_SetCurThread( TEB *teb ) } -/*********************************************************************** - * SYSDEPS_AbortThread - * - * Same as SYSDEPS_ExitThread, but must not do anything that requires a server call. - */ -void SYSDEPS_AbortThread( int status ) -{ - SIGNAL_Block(); - close( NtCurrentTeb()->wait_fd[0] ); - close( NtCurrentTeb()->wait_fd[1] ); - close( NtCurrentTeb()->reply_fd ); - close( NtCurrentTeb()->request_fd ); - wine_pthread_abort_thread( status ); -} - /*********************************************************************** * SYSDEPS_GetUnixTid * diff --git a/dlls/ntdll/thread.c b/dlls/ntdll/thread.c index f64b1f3525f..2b08024f6d2 100644 --- a/dlls/ntdll/thread.c +++ b/dlls/ntdll/thread.c @@ -42,7 +42,6 @@ static PEB_LDR_DATA ldr; static RTL_USER_PROCESS_PARAMETERS params; /* default parameters if no parent */ static RTL_BITMAP tls_bitmap; static LIST_ENTRY tls_links; -static struct debug_info info; /* debug info for initial thread */ /*********************************************************************** @@ -96,9 +95,10 @@ void thread_init(void) TEB *teb; void *addr; ULONG size; + static struct debug_info debug_info; /* debug info for initial thread */ - info.str_pos = info.strings; - info.out_pos = info.output; + debug_info.str_pos = debug_info.strings; + debug_info.out_pos = debug_info.output; peb.ProcessParameters = ¶ms; peb.TlsBitmap = &tls_bitmap; @@ -115,14 +115,14 @@ void thread_init(void) teb->reply_fd = -1; teb->wait_fd[0] = -1; teb->wait_fd[1] = -1; - teb->debug_info = &info; + teb->debug_info = &debug_info; InsertHeadList( &tls_links, &teb->TlsLinks ); SYSDEPS_SetCurThread( teb ); /* setup the server connection */ - wine_server_init_process(); - wine_server_init_thread(); + server_init_process(); + server_init_thread(); /* create a memory view for the TEB */ NtAllocateVirtualMemory( GetCurrentProcess(), &addr, teb, &size, @@ -155,7 +155,7 @@ static void start_thread( struct wine_pthread_thread_info *info ) SYSDEPS_SetCurThread( teb ); SIGNAL_Init(); - wine_server_init_thread(); + server_init_thread(); /* allocate a memory view for the stack */ size = info->stack_size; @@ -359,7 +359,7 @@ NTSTATUS WINAPI NtTerminateThread( HANDLE handle, LONG exit_code ) if (self) { if (last) exit( exit_code ); - else SYSDEPS_AbortThread( exit_code ); + else server_abort_thread( exit_code ); } return ret; } diff --git a/include/thread.h b/include/thread.h index 2d07b254ade..4cfd79c0d81 100644 --- a/include/thread.h +++ b/include/thread.h @@ -144,15 +144,7 @@ typedef struct _TEB extern TEB *THREAD_InitStack( TEB *teb, DWORD stack_size ); /* scheduler/sysdeps.c */ -extern int SYSDEPS_SpawnThread( void (*func)(TEB *), TEB *teb ); extern void SYSDEPS_SetCurThread( TEB *teb ); extern int SYSDEPS_GetUnixTid(void); -extern void DECLSPEC_NORETURN SYSDEPS_ExitThread( int status ); -extern void DECLSPEC_NORETURN SYSDEPS_AbortThread( int status ); - -/* signal handling */ -extern BOOL SIGNAL_Init(void); -extern void SIGNAL_Block(void); -extern void SIGNAL_Reset(void); #endif /* __WINE_THREAD_H */ diff --git a/include/wine/server.h b/include/wine/server.h index 7da6faa1d1f..e9f3d6d8a04 100644 --- a/include/wine/server.h +++ b/include/wine/server.h @@ -110,8 +110,4 @@ inline static void wine_server_set_reply( void *req_ptr, void *ptr, unsigned int } while(0) -/* non-exported functions */ -extern void DECLSPEC_NORETURN server_protocol_error( const char *err, ... ); -extern void DECLSPEC_NORETURN server_protocol_perror( const char *err ); - #endif /* __WINE_WINE_SERVER_H */