Commit 7e9f1878 authored by Alexandre Julliard's avatar Alexandre Julliard

ntdll: Run the thread/process detach code on the thread stack.

parent c170a483
...@@ -69,6 +69,8 @@ extern void signal_init_thread( TEB *teb ) DECLSPEC_HIDDEN; ...@@ -69,6 +69,8 @@ extern void signal_init_thread( TEB *teb ) DECLSPEC_HIDDEN;
extern void signal_init_process(void) DECLSPEC_HIDDEN; extern void signal_init_process(void) DECLSPEC_HIDDEN;
extern void signal_start_thread( LPTHREAD_START_ROUTINE entry, void *arg, BOOL suspend ) DECLSPEC_HIDDEN; extern void signal_start_thread( LPTHREAD_START_ROUTINE entry, void *arg, BOOL suspend ) DECLSPEC_HIDDEN;
extern void signal_start_process( LPTHREAD_START_ROUTINE entry, BOOL suspend ) DECLSPEC_HIDDEN; extern void signal_start_process( LPTHREAD_START_ROUTINE entry, BOOL suspend ) DECLSPEC_HIDDEN;
extern void DECLSPEC_NORETURN signal_exit_thread( int status ) DECLSPEC_HIDDEN;
extern void DECLSPEC_NORETURN signal_exit_process( int status ) DECLSPEC_HIDDEN;
extern void version_init( const WCHAR *appname ) DECLSPEC_HIDDEN; extern void version_init( const WCHAR *appname ) DECLSPEC_HIDDEN;
extern void debug_init(void) DECLSPEC_HIDDEN; extern void debug_init(void) DECLSPEC_HIDDEN;
extern HANDLE thread_init(void) DECLSPEC_HIDDEN; extern HANDLE thread_init(void) DECLSPEC_HIDDEN;
...@@ -86,7 +88,6 @@ extern void server_init_process(void) DECLSPEC_HIDDEN; ...@@ -86,7 +88,6 @@ extern void server_init_process(void) DECLSPEC_HIDDEN;
extern void server_init_process_done(void) DECLSPEC_HIDDEN; extern void server_init_process_done(void) DECLSPEC_HIDDEN;
extern size_t server_init_thread( void *entry_point, BOOL *suspend ) DECLSPEC_HIDDEN; extern size_t server_init_thread( void *entry_point, BOOL *suspend ) DECLSPEC_HIDDEN;
extern void DECLSPEC_NORETURN abort_thread( int status ) DECLSPEC_HIDDEN; extern void DECLSPEC_NORETURN abort_thread( int status ) DECLSPEC_HIDDEN;
extern void DECLSPEC_NORETURN terminate_thread( int status ) DECLSPEC_HIDDEN;
extern void DECLSPEC_NORETURN exit_thread( int status ) DECLSPEC_HIDDEN; extern void DECLSPEC_NORETURN exit_thread( int status ) DECLSPEC_HIDDEN;
extern sigset_t server_block_set DECLSPEC_HIDDEN; extern sigset_t server_block_set DECLSPEC_HIDDEN;
extern unsigned int server_call_unlocked( void *req_ptr ) DECLSPEC_HIDDEN; extern unsigned int server_call_unlocked( void *req_ptr ) DECLSPEC_HIDDEN;
......
...@@ -1233,7 +1233,7 @@ static void call_thread_entry_point( LPTHREAD_START_ROUTINE entry, void *arg ) ...@@ -1233,7 +1233,7 @@ static void call_thread_entry_point( LPTHREAD_START_ROUTINE entry, void *arg )
__TRY __TRY
{ {
TRACE_(relay)( "\1Starting thread proc %p (arg=%p)\n", entry, arg ); TRACE_(relay)( "\1Starting thread proc %p (arg=%p)\n", entry, arg );
exit_thread( entry( arg )); RtlExitUserThread( entry( arg ));
} }
__EXCEPT(unhandled_exception_filter) __EXCEPT(unhandled_exception_filter)
{ {
...@@ -1302,19 +1302,19 @@ void signal_start_process( LPTHREAD_START_ROUTINE entry, BOOL suspend ) ...@@ -1302,19 +1302,19 @@ void signal_start_process( LPTHREAD_START_ROUTINE entry, BOOL suspend )
} }
/*********************************************************************** /***********************************************************************
* RtlExitUserThread (NTDLL.@) * signal_exit_thread
*/ */
void WINAPI RtlExitUserThread( ULONG status ) void signal_exit_thread( int status )
{ {
exit_thread( status ); exit_thread( status );
} }
/*********************************************************************** /***********************************************************************
* abort_thread * signal_exit_process
*/ */
void abort_thread( int status ) void signal_exit_process( int status )
{ {
terminate_thread( status ); exit( status );
} }
/********************************************************************** /**********************************************************************
......
...@@ -965,7 +965,7 @@ static void WINAPI call_thread_entry_point( LPTHREAD_START_ROUTINE entry, void * ...@@ -965,7 +965,7 @@ static void WINAPI call_thread_entry_point( LPTHREAD_START_ROUTINE entry, void *
__TRY __TRY
{ {
TRACE_(relay)( "\1Starting thread proc %p (arg=%p)\n", entry, arg ); TRACE_(relay)( "\1Starting thread proc %p (arg=%p)\n", entry, arg );
exit_thread( entry( arg )); RtlExitUserThread( entry( arg ));
} }
__EXCEPT(unhandled_exception_filter) __EXCEPT(unhandled_exception_filter)
{ {
...@@ -1034,19 +1034,19 @@ void signal_start_process( LPTHREAD_START_ROUTINE entry, BOOL suspend ) ...@@ -1034,19 +1034,19 @@ void signal_start_process( LPTHREAD_START_ROUTINE entry, BOOL suspend )
} }
/*********************************************************************** /***********************************************************************
* RtlExitUserThread (NTDLL.@) * signal_exit_thread
*/ */
void WINAPI RtlExitUserThread( ULONG status ) void signal_exit_thread( int status )
{ {
exit_thread( status ); exit_thread( status );
} }
/*********************************************************************** /***********************************************************************
* abort_thread * signal_exit_process
*/ */
void abort_thread( int status ) void signal_exit_process( int status )
{ {
terminate_thread( status ); exit( status );
} }
/********************************************************************** /**********************************************************************
......
...@@ -2989,21 +2989,21 @@ void signal_start_process( LPTHREAD_START_ROUTINE entry, BOOL suspend ) ...@@ -2989,21 +2989,21 @@ void signal_start_process( LPTHREAD_START_ROUTINE entry, BOOL suspend )
/*********************************************************************** /***********************************************************************
* RtlExitUserThread (NTDLL.@) * signal_exit_thread
*/ */
void WINAPI RtlExitUserThread( ULONG status ) void signal_exit_thread( int status )
{ {
if (!x86_thread_data()->exit_frame) exit_thread( status ); if (!x86_thread_data()->exit_frame) exit_thread( status );
call_thread_exit_func( status, exit_thread, x86_thread_data()->exit_frame ); call_thread_exit_func( status, exit_thread, x86_thread_data()->exit_frame );
} }
/*********************************************************************** /***********************************************************************
* abort_thread * signal_exit_process
*/ */
void abort_thread( int status ) void signal_exit_process( int status )
{ {
if (!x86_thread_data()->exit_frame) terminate_thread( status ); if (!x86_thread_data()->exit_frame) exit( status );
call_thread_exit_func( status, terminate_thread, x86_thread_data()->exit_frame ); call_thread_exit_func( status, exit, x86_thread_data()->exit_frame );
} }
/********************************************************************** /**********************************************************************
......
...@@ -1143,7 +1143,7 @@ static void WINAPI call_thread_entry_point( LPTHREAD_START_ROUTINE entry, void * ...@@ -1143,7 +1143,7 @@ static void WINAPI call_thread_entry_point( LPTHREAD_START_ROUTINE entry, void *
__TRY __TRY
{ {
TRACE_(relay)( "\1Starting thread proc %p (arg=%p)\n", entry, arg ); TRACE_(relay)( "\1Starting thread proc %p (arg=%p)\n", entry, arg );
exit_thread( entry( arg )); RtlExitUserThread( entry( arg ));
} }
__EXCEPT(unhandled_exception_filter) __EXCEPT(unhandled_exception_filter)
{ {
...@@ -1212,19 +1212,19 @@ void signal_start_process( LPTHREAD_START_ROUTINE entry, BOOL suspend ) ...@@ -1212,19 +1212,19 @@ void signal_start_process( LPTHREAD_START_ROUTINE entry, BOOL suspend )
} }
/*********************************************************************** /***********************************************************************
* RtlExitUserThread (NTDLL.@) * signal_exit_thread
*/ */
void WINAPI RtlExitUserThread( ULONG status ) void signal_exit_thread( int status )
{ {
exit_thread( status ); exit_thread( status );
} }
/*********************************************************************** /***********************************************************************
* abort_thread * signal_exit_process
*/ */
void abort_thread( int status ) void signal_exit_process( int status )
{ {
terminate_thread( status ); exit( status );
} }
/********************************************************************** /**********************************************************************
......
...@@ -4160,21 +4160,21 @@ void signal_start_process( LPTHREAD_START_ROUTINE entry, BOOL suspend ) ...@@ -4160,21 +4160,21 @@ void signal_start_process( LPTHREAD_START_ROUTINE entry, BOOL suspend )
/*********************************************************************** /***********************************************************************
* RtlExitUserThread (NTDLL.@) * signal_exit_thread
*/ */
void WINAPI RtlExitUserThread( ULONG status ) void signal_exit_thread( int status )
{ {
if (!amd64_thread_data()->exit_frame) exit_thread( status ); if (!amd64_thread_data()->exit_frame) exit_thread( status );
call_thread_exit_func( status, exit_thread, amd64_thread_data()->exit_frame ); call_thread_exit_func( status, exit_thread, amd64_thread_data()->exit_frame );
} }
/*********************************************************************** /***********************************************************************
* abort_thread * signal_exit_process
*/ */
void abort_thread( int status ) void signal_exit_process( int status )
{ {
if (!amd64_thread_data()->exit_frame) terminate_thread( status ); if (!amd64_thread_data()->exit_frame) exit( status );
call_thread_exit_func( status, terminate_thread, amd64_thread_data()->exit_frame ); call_thread_exit_func( status, exit, amd64_thread_data()->exit_frame );
} }
/********************************************************************** /**********************************************************************
......
...@@ -426,13 +426,21 @@ static void free_thread_data( TEB *teb ) ...@@ -426,13 +426,21 @@ static void free_thread_data( TEB *teb )
/*********************************************************************** /***********************************************************************
* terminate_thread * abort_thread
*/ */
void terminate_thread( int status ) void abort_thread( int status )
{ {
pthread_sigmask( SIG_BLOCK, &server_block_set, NULL ); pthread_sigmask( SIG_BLOCK, &server_block_set, NULL );
if (interlocked_xchg_add( &nb_threads, -1 ) <= 1) _exit( status ); if (interlocked_xchg_add( &nb_threads, -1 ) <= 1) _exit( status );
signal_exit_thread( status );
}
/***********************************************************************
* exit_thread
*/
void exit_thread( int status )
{
close( ntdll_get_thread_data()->wait_fd[0] ); close( ntdll_get_thread_data()->wait_fd[0] );
close( ntdll_get_thread_data()->wait_fd[1] ); close( ntdll_get_thread_data()->wait_fd[1] );
close( ntdll_get_thread_data()->reply_fd ); close( ntdll_get_thread_data()->reply_fd );
...@@ -442,9 +450,9 @@ void terminate_thread( int status ) ...@@ -442,9 +450,9 @@ void terminate_thread( int status )
/*********************************************************************** /***********************************************************************
* exit_thread * RtlExitUserThread (NTDLL.@)
*/ */
void exit_thread( int status ) void WINAPI RtlExitUserThread( ULONG status )
{ {
static void *prev_teb; static void *prev_teb;
TEB *teb; TEB *teb;
...@@ -463,7 +471,7 @@ void exit_thread( int status ) ...@@ -463,7 +471,7 @@ void exit_thread( int status )
if (interlocked_xchg_add( &nb_threads, -1 ) <= 1) if (interlocked_xchg_add( &nb_threads, -1 ) <= 1)
{ {
LdrShutdownProcess(); LdrShutdownProcess();
exit( status ); signal_exit_process( status );
} }
LdrShutdownThread(); LdrShutdownThread();
...@@ -482,11 +490,7 @@ void exit_thread( int status ) ...@@ -482,11 +490,7 @@ void exit_thread( int status )
} }
} }
close( ntdll_get_thread_data()->wait_fd[0] ); signal_exit_thread( status );
close( ntdll_get_thread_data()->wait_fd[1] );
close( ntdll_get_thread_data()->reply_fd );
close( ntdll_get_thread_data()->request_fd );
pthread_exit( UIntToPtr(status) );
} }
......
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