[PATCH 2/3] ntdll: Call DllInitialize() when attaching native subsystem DLLs if present.

Zebediah Figura z.figura12 at gmail.com
Wed Jan 30 22:54:45 CST 2019


Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
---
 dlls/ntdll/loader.c | 37 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)

diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c
index 782e1d28af..abff126832 100644
--- a/dlls/ntdll/loader.c
+++ b/dlls/ntdll/loader.c
@@ -1242,6 +1242,38 @@ static NTSTATUS MODULE_InitDLL( WINE_MODREF *wm, UINT reason, LPVOID lpReserved
     return status;
 }
 
+static NTSTATUS attach_native_subsystem_dll( WINE_MODREF *wm )
+{
+    static const WCHAR key_base[] = {'\\','R','E','G','I','S','T','R','Y',
+                                     '\\','M','A','C','H','I','N','E',
+                                     '\\','C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t',
+                                     '\\','S','e','r','v','i','c','e','s','\\',0};
+    NTSTATUS (WINAPI *initfunc)(UNICODE_STRING *);
+    UNICODE_STRING keyname;
+    ANSI_STRING procname;
+    WCHAR *buffer;
+    NTSTATUS ret;
+
+    RtlInitAnsiString( &procname, "DllInitialize" );
+    if (LdrGetProcedureAddress( wm->ldr.BaseAddress, &procname, 0, (void **)&initfunc))
+        return STATUS_SUCCESS;
+
+    buffer = RtlAllocateHeap( GetProcessHeap(), 0, sizeof(key_base) + wm->ldr.BaseDllName.Length );
+    if (!buffer)
+        return STATUS_NO_MEMORY;
+
+    strcpyW( buffer, key_base );
+    strcatW( buffer, wm->ldr.BaseDllName.Buffer );
+    RtlInitUnicodeString( &keyname, buffer );
+    TRACE_(relay)( "\1Call DllInitialize %p (%s)\n",
+        initfunc, debugstr_us(&keyname) );
+    ret = initfunc( &keyname );
+    TRACE_(relay)( "\1Ret DllInitialize %p (%s) retval=%08x\n",
+        initfunc, debugstr_us(&keyname), ret );
+    RtlFreeHeap( GetProcessHeap(), 0, buffer );
+
+    return ret;
+}
 
 /*************************************************************************
  *		process_attach
@@ -1312,7 +1344,10 @@ static NTSTATUS process_attach( WINE_MODREF *wm, LPVOID lpReserved )
         current_modref = wm;
 
         call_ldr_notifications( LDR_DLL_NOTIFICATION_REASON_LOADED, &wm->ldr );
-        status = MODULE_InitDLL( wm, DLL_PROCESS_ATTACH, lpReserved );
+        if (is_dll_native_subsystem( wm ))
+            status = attach_native_subsystem_dll( wm );
+        else
+            status = MODULE_InitDLL( wm, DLL_PROCESS_ATTACH, lpReserved );
         if (status == STATUS_SUCCESS)
         {
             wm->ldr.Flags |= LDR_PROCESS_ATTACHED;
-- 
2.20.1




More information about the wine-devel mailing list