diff --git a/dlls/kernel/thread.c b/dlls/kernel/thread.c index f85a07b97de..7800a66a8f2 100644 --- a/dlls/kernel/thread.c +++ b/dlls/kernel/thread.c @@ -24,7 +24,6 @@ #include #include #include -#include #include #ifdef HAVE_SYS_TIMES_H #include @@ -238,45 +237,8 @@ void WINAPI ExitThread( DWORD code ) /* [in] Exit code for this thread */ } else { - struct wine_pthread_thread_info info; - sigset_t block_set; - ULONG size; - LdrShutdownThread(); - RtlAcquirePebLock(); - RemoveEntryList( &NtCurrentTeb()->TlsLinks ); - RtlReleasePebLock(); - - info.stack_base = NtCurrentTeb()->DeallocationStack; - info.teb_base = NtCurrentTeb(); - info.teb_sel = wine_get_fs(); - info.exit_status = code; - - size = 0; - NtFreeVirtualMemory( GetCurrentProcess(), &info.stack_base, &size, MEM_RELEASE | MEM_SYSTEM ); - info.stack_size = size; - - size = 0; - NtFreeVirtualMemory( GetCurrentProcess(), &info.teb_base, &size, MEM_RELEASE | MEM_SYSTEM ); - info.teb_size = size; - - /* block the async signals */ - sigemptyset( &block_set ); - sigaddset( &block_set, SIGALRM ); - sigaddset( &block_set, SIGIO ); - sigaddset( &block_set, SIGINT ); - sigaddset( &block_set, SIGHUP ); - sigaddset( &block_set, SIGUSR1 ); - sigaddset( &block_set, SIGUSR2 ); - sigaddset( &block_set, SIGTERM ); - 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_exit_thread( &info ); + wine_server_exit_thread( code ); } } diff --git a/dlls/ntdll/ntdll.spec b/dlls/ntdll/ntdll.spec index 3c35c8656a3..5e86d064d1d 100644 --- a/dlls/ntdll/ntdll.spec +++ b/dlls/ntdll/ntdll.spec @@ -1027,6 +1027,7 @@ @ cdecl wine_server_handle_to_fd(long long ptr ptr) @ cdecl wine_server_release_fd(long long) @ cdecl wine_server_send_fd(long) +@ cdecl wine_server_exit_thread(long) # Codepages @ cdecl __wine_init_codepages(ptr ptr ptr) diff --git a/dlls/ntdll/server.c b/dlls/ntdll/server.c index b0f098b3b1b..f0746f8cb5a 100644 --- a/dlls/ntdll/server.c +++ b/dlls/ntdll/server.c @@ -118,6 +118,40 @@ static void fatal_perror( const char *err, ... ) } +/*********************************************************************** + * wine_server_exit_thread (NTDLL.@) + */ +void wine_server_exit_thread( int status ) +{ + struct wine_pthread_thread_info info; + ULONG size; + + RtlAcquirePebLock(); + RemoveEntryList( &NtCurrentTeb()->TlsLinks ); + RtlReleasePebLock(); + + info.stack_base = NtCurrentTeb()->DeallocationStack; + info.teb_base = NtCurrentTeb(); + info.teb_sel = wine_get_fs(); + info.exit_status = status; + + size = 0; + NtFreeVirtualMemory( GetCurrentProcess(), &info.stack_base, &size, MEM_RELEASE | MEM_SYSTEM ); + info.stack_size = size; + + size = 0; + NtFreeVirtualMemory( GetCurrentProcess(), &info.teb_base, &size, MEM_RELEASE | MEM_SYSTEM ); + info.teb_size = size; + + 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_exit_thread( &info ); +} + + /*********************************************************************** * server_abort_thread */ diff --git a/include/wine/server.h b/include/wine/server.h index fefc6c221a3..3456f93427c 100644 --- a/include/wine/server.h +++ b/include/wine/server.h @@ -55,6 +55,7 @@ extern void wine_server_send_fd( int fd ); extern int wine_server_fd_to_handle( int fd, unsigned int access, int inherit, obj_handle_t *handle ); extern int wine_server_handle_to_fd( obj_handle_t handle, unsigned int access, int *unix_fd, int *flags ); extern void wine_server_release_fd( obj_handle_t handle, int unix_fd ); +extern void DECLSPEC_NORETURN wine_server_exit_thread( int status ); /* do a server call and set the last error code */ inline static unsigned int wine_server_call_err( void *req_ptr )