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

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2017-12-14 10:54:56 +01:00
parent c170a48323
commit 7e9f1878db
7 changed files with 46 additions and 41 deletions

View File

@ -69,6 +69,8 @@ extern void signal_init_thread( TEB *teb ) 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_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 debug_init(void) DECLSPEC_HIDDEN;
extern HANDLE thread_init(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 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 terminate_thread( int status ) DECLSPEC_HIDDEN;
extern void DECLSPEC_NORETURN exit_thread( int status ) DECLSPEC_HIDDEN;
extern sigset_t server_block_set DECLSPEC_HIDDEN;
extern unsigned int server_call_unlocked( void *req_ptr ) DECLSPEC_HIDDEN;

View File

@ -1233,7 +1233,7 @@ static void call_thread_entry_point( LPTHREAD_START_ROUTINE entry, void *arg )
__TRY
{
TRACE_(relay)( "\1Starting thread proc %p (arg=%p)\n", entry, arg );
exit_thread( entry( arg ));
RtlExitUserThread( entry( arg ));
}
__EXCEPT(unhandled_exception_filter)
{
@ -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 );
}
/***********************************************************************
* abort_thread
* signal_exit_process
*/
void abort_thread( int status )
void signal_exit_process( int status )
{
terminate_thread( status );
exit( status );
}
/**********************************************************************

View File

@ -965,7 +965,7 @@ static void WINAPI call_thread_entry_point( LPTHREAD_START_ROUTINE entry, void *
__TRY
{
TRACE_(relay)( "\1Starting thread proc %p (arg=%p)\n", entry, arg );
exit_thread( entry( arg ));
RtlExitUserThread( entry( arg ));
}
__EXCEPT(unhandled_exception_filter)
{
@ -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 );
}
/***********************************************************************
* abort_thread
* signal_exit_process
*/
void abort_thread( int status )
void signal_exit_process( int status )
{
terminate_thread( status );
exit( status );
}
/**********************************************************************

View File

@ -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 );
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 );
call_thread_exit_func( status, terminate_thread, x86_thread_data()->exit_frame );
if (!x86_thread_data()->exit_frame) exit( status );
call_thread_exit_func( status, exit, x86_thread_data()->exit_frame );
}
/**********************************************************************

View File

@ -1143,7 +1143,7 @@ static void WINAPI call_thread_entry_point( LPTHREAD_START_ROUTINE entry, void *
__TRY
{
TRACE_(relay)( "\1Starting thread proc %p (arg=%p)\n", entry, arg );
exit_thread( entry( arg ));
RtlExitUserThread( entry( arg ));
}
__EXCEPT(unhandled_exception_filter)
{
@ -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 );
}
/***********************************************************************
* abort_thread
* signal_exit_process
*/
void abort_thread( int status )
void signal_exit_process( int status )
{
terminate_thread( status );
exit( status );
}
/**********************************************************************

View File

@ -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 );
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 );
call_thread_exit_func( status, terminate_thread, amd64_thread_data()->exit_frame );
if (!amd64_thread_data()->exit_frame) exit( status );
call_thread_exit_func( status, exit, amd64_thread_data()->exit_frame );
}
/**********************************************************************

View File

@ -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 );
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[1] );
close( ntdll_get_thread_data()->reply_fd );
@ -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;
TEB *teb;
@ -463,7 +471,7 @@ void exit_thread( int status )
if (interlocked_xchg_add( &nb_threads, -1 ) <= 1)
{
LdrShutdownProcess();
exit( status );
signal_exit_process( status );
}
LdrShutdownThread();
@ -482,11 +490,7 @@ void exit_thread( int status )
}
}
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_exit( UIntToPtr(status) );
signal_exit_thread( status );
}