From: Jacek Caban Subject: [PATCH 1/2] user32: Introduced ThreadDetach driver entry point. Message-Id: <67832c7b-6901-0f20-ecd7-106013cb9cae@codeweavers.com> Date: Thu, 25 Aug 2016 14:33:45 +0200 The problem was diagnosed by Ken Thomases. Currently drivers use DllMain(DLL_THREAD_DETACH) to release thread data. The problem is that DLLs (like native urlmon.dll, esp. reproducible in IE8) may still do user32 calls after driver detaches thread. Loader ensures that since user32.dll was loaded before dependent DLLs, user32's DllMain will be called in the right moment. Due to lazy loading of drivers, we have no control over them. We may use a new entry point to make sure that we detach user32 and driver at the same time. It's especially useful for Mac driver, which currently attempts to recreate thread data, but fails with ExitProcess(), but X11 driver can also benefit from this (it leaks ATM). Signed-off-by: Jacek Caban --- dlls/user32/driver.c | 13 +++++++++++-- dlls/user32/user_main.c | 1 + dlls/user32/user_private.h | 2 ++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/dlls/user32/driver.c b/dlls/user32/driver.c index 201988c..32acf28 100644 --- a/dlls/user32/driver.c +++ b/dlls/user32/driver.c @@ -155,6 +155,7 @@ static const USER_DRIVER *load_driver(void) GET_USER_FUNC(WindowPosChanging); GET_USER_FUNC(WindowPosChanged); GET_USER_FUNC(SystemParametersInfo); + GET_USER_FUNC(ThreadDetach); #undef GET_USER_FUNC } @@ -512,6 +513,10 @@ static BOOL CDECL nulldrv_SystemParametersInfo( UINT action, UINT int_param, voi return FALSE; } +static void CDECL nulldrv_ThreadDetach( void ) +{ +} + static USER_DRIVER null_driver = { /* keyboard functions */ @@ -572,7 +577,9 @@ static USER_DRIVER null_driver = nulldrv_WindowPosChanging, nulldrv_WindowPosChanged, /* system parameters */ - nulldrv_SystemParametersInfo + nulldrv_SystemParametersInfo, + /* thread management */ + nulldrv_ThreadDetach }; @@ -827,5 +834,7 @@ static USER_DRIVER lazy_load_driver = nulldrv_WindowPosChanging, nulldrv_WindowPosChanged, /* system parameters */ - nulldrv_SystemParametersInfo + nulldrv_SystemParametersInfo, + /* thread management */ + nulldrv_ThreadDetach }; diff --git a/dlls/user32/user_main.c b/dlls/user32/user_main.c index 45aea81..74a7617 100644 --- a/dlls/user32/user_main.c +++ b/dlls/user32/user_main.c @@ -303,6 +303,7 @@ static void thread_detach(void) exiting_thread_id = GetCurrentThreadId(); WDML_NotifyThreadDetach(); + USER_Driver->pThreadDetach(); if (thread_info->top_window) WIN_DestroyThreadWindows( thread_info->top_window ); if (thread_info->msg_window) WIN_DestroyThreadWindows( thread_info->msg_window ); diff --git a/dlls/user32/user_private.h b/dlls/user32/user_private.h index e4a2ed1..efad519 100644 --- a/dlls/user32/user_private.h +++ b/dlls/user32/user_private.h @@ -117,6 +117,8 @@ typedef struct tagUSER_DRIVER { void (CDECL *pWindowPosChanged)(HWND,HWND,UINT,const RECT *,const RECT *,const RECT *,const RECT *,struct window_surface*); /* system parameters */ BOOL (CDECL *pSystemParametersInfo)(UINT,UINT,void*,UINT); + /* thread management */ + void (CDECL *pThreadDetach)(void); } USER_DRIVER; extern const USER_DRIVER *USER_Driver DECLSPEC_HIDDEN;