[PATCH 3/3] ntdll: Call DllUnload() when detaching native subsystem DLLs if present.
Zebediah Figura
z.figura12 at gmail.com
Wed Jan 30 22:54:46 CST 2019
Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
---
dlls/ntdll/loader.c | 24 ++++++++++++++++++++++--
1 file changed, 22 insertions(+), 2 deletions(-)
diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c
index abff126832..5c877c2e47 100644
--- a/dlls/ntdll/loader.c
+++ b/dlls/ntdll/loader.c
@@ -1275,6 +1275,21 @@ static NTSTATUS attach_native_subsystem_dll( WINE_MODREF *wm )
return ret;
}
+static void detach_native_subsystem_dll( WINE_MODREF *wm )
+{
+ NTSTATUS (WINAPI *unloadfunc)(void);
+ ANSI_STRING procname;
+ NTSTATUS ret;
+
+ RtlInitAnsiString( &procname, "DllUnload" );
+ if (!LdrGetProcedureAddress( wm->ldr.BaseAddress, &procname, 0, (void **)&unloadfunc))
+ {
+ TRACE_(relay)( "\1Call DllUnload %p\n", unloadfunc );
+ ret = unloadfunc();
+ TRACE_(relay)( "\1Ret DllUnload %p retval=%08x\n", unloadfunc, ret );
+ }
+}
+
/*************************************************************************
* process_attach
*
@@ -1411,6 +1426,7 @@ static void process_detach(void)
{
PLIST_ENTRY mark, entry;
PLDR_MODULE mod;
+ WINE_MODREF *wm;
mark = &NtCurrentTeb()->Peb->LdrData->InInitializationOrderModuleList;
do
@@ -1419,6 +1435,8 @@ static void process_detach(void)
{
mod = CONTAINING_RECORD(entry, LDR_MODULE,
InInitializationOrderModuleList);
+ wm = CONTAINING_RECORD( mod, WINE_MODREF, ldr );
+
/* Check whether to detach this DLL */
if ( !(mod->Flags & LDR_PROCESS_ATTACHED) )
continue;
@@ -1427,8 +1445,10 @@ static void process_detach(void)
/* Call detach notification */
mod->Flags &= ~LDR_PROCESS_ATTACHED;
- MODULE_InitDLL( CONTAINING_RECORD(mod, WINE_MODREF, ldr),
- DLL_PROCESS_DETACH, ULongToPtr(process_detaching) );
+ if (is_dll_native_subsystem( wm ))
+ detach_native_subsystem_dll( wm );
+ else
+ MODULE_InitDLL( wm, DLL_PROCESS_DETACH, ULongToPtr(process_detaching) );
call_ldr_notifications( LDR_DLL_NOTIFICATION_REASON_UNLOADED, mod );
/* Restart at head of WINE_MODREF list, as entries might have
--
2.20.1
More information about the wine-devel
mailing list