Alexandre Julliard : ntdll: Store the unhandled exception filter at startup to avoid race conditions.
Alexandre Julliard
julliard at winehq.org
Tue Feb 12 16:46:13 CST 2008
Module: wine
Branch: master
Commit: 78fba54ab791f8ed6d68305869b18403d08011e0
URL: http://source.winehq.org/git/wine.git/?a=commit;h=78fba54ab791f8ed6d68305869b18403d08011e0
Author: Alexandre Julliard <julliard at winehq.org>
Date: Tue Feb 12 22:39:19 2008 +0100
ntdll: Store the unhandled exception filter at startup to avoid race conditions.
---
dlls/ntdll/loader.c | 3 +++
dlls/ntdll/ntdll_misc.h | 3 +++
dlls/ntdll/thread.c | 27 ++++-----------------------
3 files changed, 10 insertions(+), 23 deletions(-)
diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c
index 05538a0..0fbf604 100644
--- a/dlls/ntdll/loader.c
+++ b/dlls/ntdll/loader.c
@@ -2533,6 +2533,9 @@ void __wine_process_init(void)
MESSAGE( "wine: could not load kernel32.dll, status %x\n", status );
exit(1);
}
+ RtlInitAnsiString( &func_name, "UnhandledExceptionFilter" );
+ LdrGetProcedureAddress( wm->ldr.BaseAddress, &func_name, 0, (void **)&unhandled_exception_filter );
+
RtlInitAnsiString( &func_name, "__wine_kernel_init" );
if ((status = LdrGetProcedureAddress( wm->ldr.BaseAddress, &func_name,
0, (void **)&init_func )) != STATUS_SUCCESS)
diff --git a/dlls/ntdll/ntdll_misc.h b/dlls/ntdll/ntdll_misc.h
index c283e1e..8c04557 100644
--- a/dlls/ntdll/ntdll_misc.h
+++ b/dlls/ntdll/ntdll_misc.h
@@ -94,6 +94,9 @@ extern void SNOOP_SetupDLL( HMODULE hmod );
extern UNICODE_STRING windows_dir;
extern UNICODE_STRING system_dir;
+typedef LONG (WINAPI *PUNHANDLED_EXCEPTION_FILTER)(PEXCEPTION_POINTERS);
+extern PUNHANDLED_EXCEPTION_FILTER unhandled_exception_filter;
+
/* redefine these to make sure we don't reference kernel symbols */
#define GetProcessHeap() (NtCurrentTeb()->Peb->ProcessHeap)
#define GetCurrentProcessId() (HandleToULong(NtCurrentTeb()->ClientId.UniqueProcess))
diff --git a/dlls/ntdll/thread.c b/dlls/ntdll/thread.c
index 8944b6a..55cedc7 100644
--- a/dlls/ntdll/thread.c
+++ b/dlls/ntdll/thread.c
@@ -48,6 +48,8 @@ WINE_DECLARE_DEBUG_CHANNEL(relay);
struct _KUSER_SHARED_DATA *user_shared_data = NULL;
+PUNHANDLED_EXCEPTION_FILTER unhandled_exception_filter = NULL;
+
/* info passed to a starting thread */
struct startup_info
{
@@ -339,27 +341,6 @@ HANDLE thread_init(void)
return exe_file;
}
-typedef LONG (WINAPI *PUNHANDLED_EXCEPTION_FILTER)(PEXCEPTION_POINTERS);
-static PUNHANDLED_EXCEPTION_FILTER get_unhandled_exception_filter(void)
-{
- static PUNHANDLED_EXCEPTION_FILTER unhandled_exception_filter;
- static const WCHAR kernel32W[] = {'k','e','r','n','e','l','3','2','.','d','l','l',0};
- UNICODE_STRING module_name;
- ANSI_STRING func_name;
- HMODULE kernel32_handle;
-
- if (unhandled_exception_filter) return unhandled_exception_filter;
-
- RtlInitUnicodeString(&module_name, kernel32W);
- RtlInitAnsiString( &func_name, "UnhandledExceptionFilter" );
-
- if (LdrGetDllHandle( 0, 0, &module_name, &kernel32_handle ) == STATUS_SUCCESS)
- LdrGetProcedureAddress( kernel32_handle, &func_name, 0,
- (void **)&unhandled_exception_filter );
-
- return unhandled_exception_filter;
-}
-
#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 );
@@ -465,13 +446,13 @@ static void start_thread( struct wine_pthread_thread_info *info )
/* NOTE: Windows does not have an exception handler around the call to
* the thread attach. We do for ease of debugging */
- if (get_unhandled_exception_filter())
+ if (unhandled_exception_filter)
{
__TRY
{
call_thread_func( func, arg );
}
- __EXCEPT(get_unhandled_exception_filter())
+ __EXCEPT(unhandled_exception_filter)
{
NtTerminateThread( GetCurrentThread(), GetExceptionCode() );
}
More information about the wine-cvs
mailing list