From f124c7cc38e7edf0823347afa5f8e7126143080d Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Thu, 18 Jun 2009 16:38:30 +0200 Subject: [PATCH] ntdll: Simplify the thread startup routine and make it CPU-specific. --- dlls/ntdll/ntdll_misc.h | 1 + dlls/ntdll/signal_i386.c | 31 ++++++++++++++ dlls/ntdll/signal_powerpc.c | 17 ++++++++ dlls/ntdll/signal_sparc.c | 17 ++++++++ dlls/ntdll/signal_x86_64.c | 18 ++++++++ dlls/ntdll/thread.c | 82 +++---------------------------------- 6 files changed, 90 insertions(+), 76 deletions(-) diff --git a/dlls/ntdll/ntdll_misc.h b/dlls/ntdll/ntdll_misc.h index 3e54250da01..61299627562 100644 --- a/dlls/ntdll/ntdll_misc.h +++ b/dlls/ntdll/ntdll_misc.h @@ -48,6 +48,7 @@ extern void set_cpu_context( const CONTEXT *context ); extern void copy_context( CONTEXT *to, const CONTEXT *from, DWORD flags ); extern NTSTATUS context_to_server( context_t *to, const CONTEXT *from ); extern NTSTATUS context_from_server( CONTEXT *to, const context_t *from ); +extern void call_thread_entry_point( LPTHREAD_START_ROUTINE entry, void *arg ) DECLSPEC_NORETURN; /* debug helpers */ extern LPCSTR debugstr_us( const UNICODE_STRING *str ); diff --git a/dlls/ntdll/signal_i386.c b/dlls/ntdll/signal_i386.c index dc1f12c5516..0efce897121 100644 --- a/dlls/ntdll/signal_i386.c +++ b/dlls/ntdll/signal_i386.c @@ -2264,6 +2264,37 @@ void WINAPI __regs_RtlRaiseException( EXCEPTION_RECORD *rec, CONTEXT *context ) DEFINE_REGS_ENTRYPOINT( RtlRaiseException, 1 ) +/* wrapper for apps that don't declare the thread function correctly */ +extern void DECLSPEC_NORETURN call_thread_func( LPTHREAD_START_ROUTINE entry, void *arg ); +__ASM_GLOBAL_FUNC(call_thread_func, + "pushl %ebp\n\t" + "movl %esp,%ebp\n\t" + "subl $4,%esp\n\t" + "pushl 12(%ebp)\n\t" + "call *8(%ebp)\n\t" + "leal -4(%ebp),%esp\n\t" + "pushl %eax\n\t" + "call " __ASM_NAME("RtlExitUserThread") "\n\t" + "int $3" ) + +/*********************************************************************** + * call_thread_entry_point + */ +void call_thread_entry_point( LPTHREAD_START_ROUTINE entry, void *arg ) +{ + __TRY + { + call_thread_func( entry, arg ); + } + __EXCEPT(unhandled_exception_filter) + { + NtTerminateThread( GetCurrentThread(), GetExceptionCode() ); + } + __ENDTRY + abort(); /* should not be reached */ +} + + /********************************************************************** * DbgBreakPoint (NTDLL.@) */ diff --git a/dlls/ntdll/signal_powerpc.c b/dlls/ntdll/signal_powerpc.c index 40b80619c14..4401006edc4 100644 --- a/dlls/ntdll/signal_powerpc.c +++ b/dlls/ntdll/signal_powerpc.c @@ -1086,6 +1086,23 @@ void WINAPI RtlRaiseException( EXCEPTION_RECORD *rec ) if (status) raise_status( status, rec ); } +/*********************************************************************** + * call_thread_entry_point + */ +void call_thread_entry_point( LPTHREAD_START_ROUTINE entry, void *arg ) +{ + __TRY + { + RtlExitUserThread( entry( arg )); + } + __EXCEPT(unhandled_exception_filter) + { + NtTerminateThread( GetCurrentThread(), GetExceptionCode() ); + } + __ENDTRY + abort(); /* should not be reached */ +} + /********************************************************************** * DbgBreakPoint (NTDLL.@) */ diff --git a/dlls/ntdll/signal_sparc.c b/dlls/ntdll/signal_sparc.c index a024d2e196e..17bfc542f4a 100644 --- a/dlls/ntdll/signal_sparc.c +++ b/dlls/ntdll/signal_sparc.c @@ -828,6 +828,23 @@ void WINAPI RtlRaiseException( EXCEPTION_RECORD *rec ) if (status) raise_status( status, rec ); } +/*********************************************************************** + * call_thread_entry_point + */ +void call_thread_entry_point( LPTHREAD_START_ROUTINE entry, void *arg ) +{ + __TRY + { + RtlExitUserThread( entry( arg )); + } + __EXCEPT(unhandled_exception_filter) + { + NtTerminateThread( GetCurrentThread(), GetExceptionCode() ); + } + __ENDTRY + abort(); /* should not be reached */ +} + /********************************************************************** * DbgBreakPoint (NTDLL.@) */ diff --git a/dlls/ntdll/signal_x86_64.c b/dlls/ntdll/signal_x86_64.c index 83b84dc1df1..7ff38aff4d1 100644 --- a/dlls/ntdll/signal_x86_64.c +++ b/dlls/ntdll/signal_x86_64.c @@ -2551,6 +2551,24 @@ void WINAPI __regs_RtlRaiseException( EXCEPTION_RECORD *rec, CONTEXT *context ) DEFINE_REGS_ENTRYPOINT( RtlRaiseException, 1 ) +/*********************************************************************** + * call_thread_entry_point + */ +void call_thread_entry_point( LPTHREAD_START_ROUTINE entry, void *arg ) +{ + __TRY + { + RtlExitUserThread( entry( arg )); + } + __EXCEPT(unhandled_exception_filter) + { + NtTerminateThread( GetCurrentThread(), GetExceptionCode() ); + } + __ENDTRY + abort(); /* should not be reached */ +} + + /********************************************************************** * __wine_enter_vm86 (NTDLL.@) */ diff --git a/dlls/ntdll/thread.c b/dlls/ntdll/thread.c index 1a5017ebb6e..cd54b31e251 100644 --- a/dlls/ntdll/thread.c +++ b/dlls/ntdll/thread.c @@ -388,66 +388,6 @@ static void DECLSPEC_NORETURN exit_thread( int status ) } -#ifdef __i386__ -/* wrapper for apps that don't declare the thread function correctly */ -extern DWORD call_thread_entry_point( PRTL_THREAD_START_ROUTINE entry, void *arg ); -__ASM_GLOBAL_FUNC(call_thread_entry_point, - "pushl %ebp\n\t" - "movl %esp,%ebp\n\t" - "subl $4,%esp\n\t" - "pushl 12(%ebp)\n\t" - "movl 8(%ebp),%eax\n\t" - "call *%eax\n\t" - "leave\n\t" - "ret" ) -#else -static inline DWORD call_thread_entry_point( PRTL_THREAD_START_ROUTINE entry, void *arg ) -{ - LPTHREAD_START_ROUTINE func = (LPTHREAD_START_ROUTINE)entry; - return func( arg ); -} -#endif - -/*********************************************************************** - * call_thread_func - * - * Hack to make things compatible with the thread procedures used by kernel32.CreateThread. - */ -static void DECLSPEC_NORETURN call_thread_func( PRTL_THREAD_START_ROUTINE rtl_func, void *arg ) -{ - DWORD exit_code; - BOOL last; - - MODULE_DllThreadAttach( NULL ); - - if (TRACE_ON(relay)) - DPRINTF( "%04x:Starting thread proc %p (arg=%p)\n", GetCurrentThreadId(), rtl_func, arg ); - - exit_code = call_thread_entry_point( rtl_func, arg ); - - /* send the exit code to the server */ - SERVER_START_REQ( terminate_thread ) - { - req->handle = wine_server_obj_handle( GetCurrentThread() ); - req->exit_code = exit_code; - wine_server_call( req ); - last = reply->last; - } - SERVER_END_REQ; - - if (last) - { - LdrShutdownProcess(); - exit( exit_code ); - } - else - { - LdrShutdownThread(); - exit_thread( exit_code ); - } -} - - /*********************************************************************** * start_thread * @@ -474,22 +414,12 @@ static void start_thread( struct startup_info *info ) InsertHeadList( &tls_links, &teb->TlsLinks ); RtlReleasePebLock(); - /* NOTE: Windows does not have an exception handler around the call to - * the thread attach. We do for ease of debugging */ - if (unhandled_exception_filter) - { - __TRY - { - call_thread_func( func, arg ); - } - __EXCEPT(unhandled_exception_filter) - { - NtTerminateThread( GetCurrentThread(), GetExceptionCode() ); - } - __ENDTRY - } - else - call_thread_func( func, arg ); + MODULE_DllThreadAttach( NULL ); + + if (TRACE_ON(relay)) + DPRINTF( "%04x:Starting thread proc %p (arg=%p)\n", GetCurrentThreadId(), func, arg ); + + call_thread_entry_point( (LPTHREAD_START_ROUTINE)func, arg ); }