Alexandre Julliard : ntdll: Open the per-application key for load order at startup.

Alexandre Julliard julliard at winehq.org
Wed May 5 16:09:00 CDT 2021


Module: wine
Branch: master
Commit: d47a711e986342a0f6b9fe520f2a34378877cd61
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=d47a711e986342a0f6b9fe520f2a34378877cd61

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Wed May  5 10:55:36 2021 +0200

ntdll: Open the per-application key for load order at startup.

It avoids accessing process parameters after startup.

Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/ntdll/unix/loader.c       |  1 +
 dlls/ntdll/unix/loadorder.c    | 55 ++++++++++++++++--------------------------
 dlls/ntdll/unix/unix_private.h |  1 +
 3 files changed, 23 insertions(+), 34 deletions(-)

diff --git a/dlls/ntdll/unix/loader.c b/dlls/ntdll/unix/loader.c
index 42bcb6f14b8..8431ad0d6b1 100644
--- a/dlls/ntdll/unix/loader.c
+++ b/dlls/ntdll/unix/loader.c
@@ -1870,6 +1870,7 @@ static void start_main_thread(void)
     if (p___wine_main_argc) *p___wine_main_argc = main_argc;
     if (p___wine_main_argv) *p___wine_main_argv = main_argv;
     if (p___wine_main_wargv) *p___wine_main_wargv = main_wargv;
+    set_load_order_app_name( main_wargv[0] );
     virtual_alloc_thread_stack( &stack, 0, 0, NULL );
     teb->Tib.StackBase = stack.StackBase;
     teb->Tib.StackLimit = stack.StackLimit;
diff --git a/dlls/ntdll/unix/loadorder.c b/dlls/ntdll/unix/loadorder.c
index 5285bb58007..4d7ad24d2b7 100644
--- a/dlls/ntdll/unix/loadorder.c
+++ b/dlls/ntdll/unix/loadorder.c
@@ -55,6 +55,8 @@ static struct
 
 static const WCHAR separatorsW[] = {',',' ','\t',0};
 
+static HANDLE std_key;
+static HANDLE app_key;
 static BOOL init_done;
 
 
@@ -221,6 +223,9 @@ static void init_load_order(void)
     WCHAR *entry, *next, *order;
     const char *overrides = getenv( "WINEDLLOVERRIDES" );
 
+    /* @@ Wine registry key: HKCU\Software\Wine\DllOverrides */
+    open_hkcu_key( "Software\\Wine\\DllOverrides", &std_key );
+
     init_done = TRUE;
 
     if (!overrides) return;
@@ -264,37 +269,16 @@ static inline enum loadorder get_env_load_order( const WCHAR *module )
 
 
 /***************************************************************************
- *	get_standard_key
- *
- * Return a handle to the standard DllOverrides registry section.
- */
-static HANDLE get_standard_key(void)
-{
-    static HANDLE std_key = (HANDLE)-1;
-
-    if (std_key == (HANDLE)-1)
-    {
-        /* @@ Wine registry key: HKCU\Software\Wine\DllOverrides */
-        if (open_hkcu_key( "Software\\Wine\\DllOverrides", &std_key )) std_key = 0;
-    }
-    return std_key;
-}
-
-
-/***************************************************************************
- *	get_app_key
+ *	open_app_key
  *
  * Get the registry key for the app-specific DllOverrides list.
  */
-static HANDLE get_app_key( const WCHAR *app_name )
+static HANDLE open_app_key( const WCHAR *app_name )
 {
     static const WCHAR dlloverridesW[] = {'\\','D','l','l','O','v','e','r','r','i','d','e','s',0};
     OBJECT_ATTRIBUTES attr;
     UNICODE_STRING nameW;
-    HANDLE root;
-    static HANDLE app_key = (HANDLE)-1;
-
-    if (app_key != (HANDLE)-1) return app_key;
+    HANDLE root, app_key = 0;
 
     if (!open_hkcu_key( "Software\\Wine\\AppDefaults", &root ))
     {
@@ -306,7 +290,7 @@ static HANDLE get_app_key( const WCHAR *app_name )
         InitializeObjectAttributes( &attr, &nameW, 0, root, NULL );
 
         /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\DllOverrides */
-        if (NtOpenKey( &app_key, KEY_ALL_ACCESS, &attr )) app_key = 0;
+        NtOpenKey( &app_key, KEY_ALL_ACCESS, &attr );
         NtClose( root );
         free( nameW.Buffer );
     }
@@ -372,6 +356,18 @@ static enum loadorder get_load_order_value( HANDLE std_key, HANDLE app_key, WCHA
 }
 
 
+/***************************************************************************
+ *	set_load_order_app_name
+ */
+void set_load_order_app_name( const WCHAR *app_name )
+{
+    const WCHAR *p;
+
+    if ((p = wcsrchr( app_name, '\\' ))) app_name = p + 1;
+    app_key = open_app_key( app_name );
+}
+
+
 /***************************************************************************
  *	get_load_order   (internal)
  *
@@ -382,21 +378,12 @@ enum loadorder get_load_order( const UNICODE_STRING *nt_name )
 {
     static const WCHAR prefixW[] = {'\\','?','?','\\'};
     enum loadorder ret = LO_INVALID;
-    HANDLE std_key, app_key = 0;
     const WCHAR *path = nt_name->Buffer;
     const WCHAR *p, *app_name = NULL;
     WCHAR *module, *basename;
     int len;
 
     if (!init_done) init_load_order();
-    std_key = get_standard_key();
-
-    if (NtCurrentTeb()->Peb->ImageBaseAddress)
-    {
-        app_name = NtCurrentTeb()->Peb->ProcessParameters->ImagePathName.Buffer;
-        if ((p = wcsrchr( app_name, '\\' ))) app_name = p + 1;
-        app_key = get_app_key( app_name );
-    }
 
     if (!wcsncmp( path, prefixW, 4 )) path += 4;
 
diff --git a/dlls/ntdll/unix/unix_private.h b/dlls/ntdll/unix/unix_private.h
index c47695c408c..d3398fed258 100644
--- a/dlls/ntdll/unix/unix_private.h
+++ b/dlls/ntdll/unix/unix_private.h
@@ -410,6 +410,7 @@ enum loadorder
     LO_DEFAULT          /* nothing specified, use default strategy */
 };
 
+extern void set_load_order_app_name( const WCHAR *app_name ) DECLSPEC_HIDDEN;
 extern enum loadorder get_load_order( const UNICODE_STRING *nt_name ) DECLSPEC_HIDDEN;
 
 static inline size_t ntdll_wcslen( const WCHAR *str )




More information about the wine-cvs mailing list