ntdll: Moved exit_thread and abort_thread functions to thread.c.

This commit is contained in:
Alexandre Julliard 2009-02-20 11:23:08 +01:00
parent 36334a1b5a
commit cc933f586a
8 changed files with 71 additions and 74 deletions

View File

@ -73,8 +73,7 @@ extern NTSTATUS server_init_process_done(void);
extern size_t server_init_thread( void *entry_point ); extern size_t server_init_thread( void *entry_point );
extern void DECLSPEC_NORETURN server_protocol_error( const char *err, ... ); 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_protocol_perror( const char *err );
extern void DECLSPEC_NORETURN server_exit_thread( int status ); extern void DECLSPEC_NORETURN abort_thread( int status );
extern void DECLSPEC_NORETURN server_abort_thread( int status );
extern sigset_t server_block_set; extern sigset_t server_block_set;
extern void server_enter_uninterrupted_section( RTL_CRITICAL_SECTION *cs, sigset_t *sigset ); extern void server_enter_uninterrupted_section( RTL_CRITICAL_SECTION *cs, sigset_t *sigset );
extern void server_leave_uninterrupted_section( RTL_CRITICAL_SECTION *cs, sigset_t *sigset ); extern void server_leave_uninterrupted_section( RTL_CRITICAL_SECTION *cs, sigset_t *sigset );

View File

@ -62,7 +62,6 @@
#include "ntstatus.h" #include "ntstatus.h"
#define WIN32_NO_STATUS #define WIN32_NO_STATUS
#include "wine/library.h" #include "wine/library.h"
#include "wine/pthread.h"
#include "wine/server.h" #include "wine/server.h"
#include "wine/debug.h" #include "wine/debug.h"
#include "ntdll_misc.h" #include "ntdll_misc.h"
@ -93,8 +92,6 @@ struct cmsg_fd
timeout_t server_start_time = 0; /* time of server startup */ timeout_t server_start_time = 0; /* time of server startup */
extern struct wine_pthread_functions pthread_functions;
sigset_t server_block_set; /* signals to block during server calls */ sigset_t server_block_set; /* signals to block during server calls */
static int fd_socket = -1; /* socket to exchange file descriptors with the server */ static int fd_socket = -1; /* socket to exchange file descriptors with the server */
@ -140,56 +137,6 @@ static void fatal_perror( const char *err, ... )
} }
/***********************************************************************
* server_exit_thread
*/
void server_exit_thread( int status )
{
struct wine_pthread_thread_info info;
int fds[4];
RtlAcquirePebLock();
RemoveEntryList( &NtCurrentTeb()->TlsLinks );
RtlReleasePebLock();
RtlFreeHeap( GetProcessHeap(), 0, NtCurrentTeb()->FlsSlots );
RtlFreeHeap( GetProcessHeap(), 0, NtCurrentTeb()->TlsExpansionSlots );
info.stack_base = NtCurrentTeb()->DeallocationStack;
info.teb_base = NtCurrentTeb();
info.teb_sel = wine_get_fs();
info.exit_status = status;
fds[0] = ntdll_get_thread_data()->wait_fd[0];
fds[1] = ntdll_get_thread_data()->wait_fd[1];
fds[2] = ntdll_get_thread_data()->reply_fd;
fds[3] = ntdll_get_thread_data()->request_fd;
pthread_sigmask( SIG_BLOCK, &server_block_set, NULL );
info.stack_size = virtual_free_system_view( &info.stack_base );
info.teb_size = virtual_free_system_view( &info.teb_base );
close( fds[0] );
close( fds[1] );
close( fds[2] );
close( fds[3] );
pthread_functions.exit_thread( &info );
}
/***********************************************************************
* server_abort_thread
*/
void server_abort_thread( int status )
{
pthread_sigmask( SIG_BLOCK, &server_block_set, NULL );
close( ntdll_get_thread_data()->wait_fd[0] );
close( ntdll_get_thread_data()->wait_fd[1] );
close( ntdll_get_thread_data()->reply_fd );
close( ntdll_get_thread_data()->request_fd );
pthread_functions.abort_thread( status );
}
/*********************************************************************** /***********************************************************************
* server_protocol_error * server_protocol_error
*/ */
@ -201,7 +148,7 @@ void server_protocol_error( const char *err, ... )
fprintf( stderr, "wine client error:%x: ", GetCurrentThreadId() ); fprintf( stderr, "wine client error:%x: ", GetCurrentThreadId() );
vfprintf( stderr, err, args ); vfprintf( stderr, err, args );
va_end( args ); va_end( args );
server_abort_thread(1); abort_thread(1);
} }
@ -212,7 +159,7 @@ void server_protocol_perror( const char *err )
{ {
fprintf( stderr, "wine client error:%x: ", GetCurrentThreadId() ); fprintf( stderr, "wine client error:%x: ", GetCurrentThreadId() );
perror( err ); perror( err );
server_abort_thread(1); abort_thread(1);
} }
@ -248,7 +195,7 @@ static unsigned int send_request( const struct __server_request_info *req )
} }
if (ret >= 0) server_protocol_error( "partial write %d\n", ret ); if (ret >= 0) server_protocol_error( "partial write %d\n", ret );
if (errno == EPIPE) server_abort_thread(0); if (errno == EPIPE) abort_thread(0);
if (errno == EFAULT) return STATUS_ACCESS_VIOLATION; if (errno == EFAULT) return STATUS_ACCESS_VIOLATION;
server_protocol_perror( "write" ); server_protocol_perror( "write" );
} }
@ -277,7 +224,7 @@ static void read_reply_data( void *buffer, size_t size )
server_protocol_perror("read"); server_protocol_perror("read");
} }
/* the server closed the connection; time to die... */ /* the server closed the connection; time to die... */
server_abort_thread(0); abort_thread(0);
} }
@ -401,7 +348,7 @@ void CDECL wine_server_send_fd( int fd )
if ((ret = sendmsg( fd_socket, &msghdr, 0 )) == sizeof(data)) return; if ((ret = sendmsg( fd_socket, &msghdr, 0 )) == sizeof(data)) return;
if (ret >= 0) server_protocol_error( "partial write %d\n", ret ); if (ret >= 0) server_protocol_error( "partial write %d\n", ret );
if (errno == EINTR) continue; if (errno == EINTR) continue;
if (errno == EPIPE) server_abort_thread(0); if (errno == EPIPE) abort_thread(0);
server_protocol_perror( "sendmsg" ); server_protocol_perror( "sendmsg" );
} }
} }
@ -459,7 +406,7 @@ static int receive_fd( obj_handle_t *handle )
server_protocol_perror("recvmsg"); server_protocol_perror("recvmsg");
} }
/* the server closed the connection; time to die... */ /* the server closed the connection; time to die... */
server_abort_thread(0); abort_thread(0);
} }

View File

@ -1109,7 +1109,7 @@ static EXCEPTION_RECORD *setup_exception_record( SIGCONTEXT *sigcontext, void *s
GetCurrentThreadId(), (unsigned int) EIP_sig(sigcontext), GetCurrentThreadId(), (unsigned int) EIP_sig(sigcontext),
(unsigned int) ESP_sig(sigcontext), NtCurrentTeb()->Tib.StackLimit, (unsigned int) ESP_sig(sigcontext), NtCurrentTeb()->Tib.StackLimit,
NtCurrentTeb()->Tib.StackBase ); NtCurrentTeb()->Tib.StackBase );
server_abort_thread(1); abort_thread(1);
} }
if (stack - 1 > stack || /* check for overflow in subtraction */ if (stack - 1 > stack || /* check for overflow in subtraction */
@ -1129,7 +1129,7 @@ static EXCEPTION_RECORD *setup_exception_record( SIGCONTEXT *sigcontext, void *s
diff, GetCurrentThreadId(), (unsigned int) EIP_sig(sigcontext), diff, GetCurrentThreadId(), (unsigned int) EIP_sig(sigcontext),
(unsigned int) ESP_sig(sigcontext), NtCurrentTeb()->DeallocationStack, (unsigned int) ESP_sig(sigcontext), NtCurrentTeb()->DeallocationStack,
NtCurrentTeb()->Tib.StackLimit, NtCurrentTeb()->Tib.StackBase ); NtCurrentTeb()->Tib.StackLimit, NtCurrentTeb()->Tib.StackBase );
server_abort_thread(1); abort_thread(1);
} }
else if ((char *)(stack - 1) < (char *)NtCurrentTeb()->Tib.StackLimit) else if ((char *)(stack - 1) < (char *)NtCurrentTeb()->Tib.StackLimit)
{ {
@ -1142,7 +1142,7 @@ static EXCEPTION_RECORD *setup_exception_record( SIGCONTEXT *sigcontext, void *s
diff, GetCurrentThreadId(), (unsigned int) EIP_sig(sigcontext), diff, GetCurrentThreadId(), (unsigned int) EIP_sig(sigcontext),
(unsigned int) ESP_sig(sigcontext), NtCurrentTeb()->DeallocationStack, (unsigned int) ESP_sig(sigcontext), NtCurrentTeb()->DeallocationStack,
NtCurrentTeb()->Tib.StackLimit, NtCurrentTeb()->Tib.StackBase ); NtCurrentTeb()->Tib.StackLimit, NtCurrentTeb()->Tib.StackBase );
server_abort_thread(1); abort_thread(1);
} }
} }
@ -1550,7 +1550,7 @@ static void quit_handler( int signal, siginfo_t *siginfo, void *sigcontext )
{ {
WORD fs, gs; WORD fs, gs;
init_handler( sigcontext, &fs, &gs ); init_handler( sigcontext, &fs, &gs );
server_abort_thread(0); abort_thread(0);
} }

View File

@ -584,7 +584,7 @@ static HANDLER_DEF(abrt_handler)
*/ */
static HANDLER_DEF(quit_handler) static HANDLER_DEF(quit_handler)
{ {
server_abort_thread(0); abort_thread(0);
} }

View File

@ -397,7 +397,7 @@ static HANDLER_DEF(abrt_handler)
*/ */
static HANDLER_DEF(quit_handler) static HANDLER_DEF(quit_handler)
{ {
server_abort_thread(0); abort_thread(0);
} }

View File

@ -472,7 +472,7 @@ static HANDLER_DEF(abrt_handler)
*/ */
static HANDLER_DEF(quit_handler) static HANDLER_DEF(quit_handler)
{ {
server_abort_thread(0); abort_thread(0);
} }

View File

@ -831,7 +831,7 @@ static int wait_reply( void *cookie )
server_protocol_perror("wakeup read"); server_protocol_perror("wakeup read");
} }
/* the server closed the connection; time to die... */ /* the server closed the connection; time to die... */
server_abort_thread(0); abort_thread(0);
} }

View File

@ -68,7 +68,7 @@ static LIST_ENTRY tls_links;
static size_t sigstack_total_size; static size_t sigstack_total_size;
static ULONG sigstack_zero_bits; static ULONG sigstack_zero_bits;
struct wine_pthread_functions pthread_functions = { NULL }; static struct wine_pthread_functions pthread_functions;
static RTL_CRITICAL_SECTION ldt_section; static RTL_CRITICAL_SECTION ldt_section;
@ -346,6 +346,57 @@ HANDLE thread_init(void)
return exe_file; return exe_file;
} }
/***********************************************************************
* abort_thread
*/
void abort_thread( int status )
{
pthread_sigmask( SIG_BLOCK, &server_block_set, NULL );
close( ntdll_get_thread_data()->wait_fd[0] );
close( ntdll_get_thread_data()->wait_fd[1] );
close( ntdll_get_thread_data()->reply_fd );
close( ntdll_get_thread_data()->request_fd );
pthread_functions.abort_thread( status );
}
/***********************************************************************
* exit_thread
*/
static void DECLSPEC_NORETURN exit_thread( int status )
{
struct wine_pthread_thread_info info;
int fds[4];
RtlAcquirePebLock();
RemoveEntryList( &NtCurrentTeb()->TlsLinks );
RtlReleasePebLock();
RtlFreeHeap( GetProcessHeap(), 0, NtCurrentTeb()->FlsSlots );
RtlFreeHeap( GetProcessHeap(), 0, NtCurrentTeb()->TlsExpansionSlots );
info.stack_base = NtCurrentTeb()->DeallocationStack;
info.teb_base = NtCurrentTeb();
info.teb_sel = wine_get_fs();
info.exit_status = status;
fds[0] = ntdll_get_thread_data()->wait_fd[0];
fds[1] = ntdll_get_thread_data()->wait_fd[1];
fds[2] = ntdll_get_thread_data()->reply_fd;
fds[3] = ntdll_get_thread_data()->request_fd;
pthread_sigmask( SIG_BLOCK, &server_block_set, NULL );
info.stack_size = virtual_free_system_view( &info.stack_base );
info.teb_size = virtual_free_system_view( &info.teb_base );
close( fds[0] );
close( fds[1] );
close( fds[2] );
close( fds[3] );
pthread_functions.exit_thread( &info );
}
#ifdef __i386__ #ifdef __i386__
/* wrapper for apps that don't declare the thread function correctly */ /* wrapper for apps that don't declare the thread function correctly */
extern DWORD call_thread_entry_point( PRTL_THREAD_START_ROUTINE entry, void *arg ); extern DWORD call_thread_entry_point( PRTL_THREAD_START_ROUTINE entry, void *arg );
@ -401,7 +452,7 @@ static void DECLSPEC_NORETURN call_thread_func( PRTL_THREAD_START_ROUTINE rtl_fu
else else
{ {
LdrShutdownThread(); LdrShutdownThread();
server_exit_thread( exit_code ); exit_thread( exit_code );
} }
} }
@ -624,7 +675,7 @@ void WINAPI RtlExitUserThread( ULONG status )
else else
{ {
LdrShutdownThread(); LdrShutdownThread();
server_exit_thread( status ); exit_thread( status );
} }
} }
@ -730,8 +781,8 @@ NTSTATUS WINAPI NtTerminateThread( HANDLE handle, LONG exit_code )
if (self) if (self)
{ {
if (last) exit( exit_code ); if (last) _exit( exit_code );
else server_abort_thread( exit_code ); else abort_thread( exit_code );
} }
return ret; return ret;
} }