Alexandre Julliard : ntdll: Allow using the .fake files from the build tree as PE mapping placeholders.

Alexandre Julliard julliard at winehq.org
Tue Mar 30 15:19:49 CDT 2021


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

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Tue Mar 30 10:06:44 2021 +0200

ntdll: Allow using the .fake files from the build tree as PE mapping placeholders.

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

---

 dlls/ntdll/unix/loader.c       | 49 +++++++++++++++++-------------------------
 dlls/ntdll/unix/unix_private.h |  2 +-
 2 files changed, 21 insertions(+), 30 deletions(-)

diff --git a/dlls/ntdll/unix/loader.c b/dlls/ntdll/unix/loader.c
index 9aab5102b8a..7c4572e6b0e 100644
--- a/dlls/ntdll/unix/loader.c
+++ b/dlls/ntdll/unix/loader.c
@@ -1395,7 +1395,7 @@ static NTSTATUS CDECL load_builtin_dll( UNICODE_STRING *nt_name, void **module,
  * Load the builtin dll if specified by load order configuration.
  * Return STATUS_IMAGE_ALREADY_LOADED if we should keep the native one that we have found.
  */
-NTSTATUS load_builtin( const pe_image_info_t *image_info, const WCHAR *filename,
+NTSTATUS load_builtin( const pe_image_info_t *image_info, WCHAR *filename,
                        void **module, SIZE_T *size )
 {
     WORD machine = image_info->machine;  /* request same machine as the native one */
@@ -1404,38 +1404,32 @@ NTSTATUS load_builtin( const pe_image_info_t *image_info, const WCHAR *filename,
     SECTION_IMAGE_INFORMATION info;
     enum loadorder loadorder;
 
+    /* remove .fake extension if present */
+    if (image_info->image_flags & IMAGE_FLAGS_WineFakeDll)
+    {
+        static const WCHAR fakeW[] = {'.','f','a','k','e',0};
+        WCHAR *ext = wcsrchr( filename, '.' );
+
+        TRACE( "%s is a fake Wine dll\n", debugstr_w(filename) );
+        if (ext && !wcsicmp( ext, fakeW )) *ext = 0;
+    }
+
     init_unicode_string( &nt_name, filename );
     loadorder = get_load_order( &nt_name );
 
+    if (loadorder == LO_DISABLED) return STATUS_DLL_NOT_FOUND;
+
     if (image_info->image_flags & IMAGE_FLAGS_WineBuiltin)
     {
-        switch (loadorder)
-        {
-        case LO_NATIVE_BUILTIN:
-        case LO_BUILTIN:
-        case LO_BUILTIN_NATIVE:
-        case LO_DEFAULT:
-            status = find_builtin_dll( &nt_name, module, size, &info, machine, FALSE );
-            if (status == STATUS_DLL_NOT_FOUND) return STATUS_IMAGE_ALREADY_LOADED;
-            return status;
-        default:
-            return STATUS_DLL_NOT_FOUND;
-        }
+        if (loadorder == LO_NATIVE) return STATUS_DLL_NOT_FOUND;
+        loadorder = LO_BUILTIN_NATIVE;  /* load builtin, then fallback to the file we found */
     }
-    if (image_info->image_flags & IMAGE_FLAGS_WineFakeDll)
+    else if (image_info->image_flags & IMAGE_FLAGS_WineFakeDll)
     {
-        TRACE( "%s is a fake Wine dll\n", debugstr_us(&nt_name) );
-        switch (loadorder)
-        {
-        case LO_NATIVE_BUILTIN:
-        case LO_BUILTIN:
-        case LO_BUILTIN_NATIVE:
-        case LO_DEFAULT:
-            return find_builtin_dll( &nt_name, module, size, &info, machine, FALSE );
-        default:
-            return STATUS_DLL_NOT_FOUND;
-        }
+        if (loadorder == LO_NATIVE) return STATUS_DLL_NOT_FOUND;
+        loadorder = LO_BUILTIN;  /* builtin with no fallback since mapping a fake dll is not useful */
     }
+
     switch (loadorder)
     {
     case LO_NATIVE:
@@ -1443,13 +1437,10 @@ NTSTATUS load_builtin( const pe_image_info_t *image_info, const WCHAR *filename,
         return STATUS_IMAGE_ALREADY_LOADED;
     case LO_BUILTIN:
         return find_builtin_dll( &nt_name, module, size, &info, machine, FALSE );
-    case LO_BUILTIN_NATIVE:
-    case LO_DEFAULT:
+    default:
         status = find_builtin_dll( &nt_name, module, size, &info, machine, (loadorder == LO_DEFAULT) );
         if (status == STATUS_DLL_NOT_FOUND) return STATUS_IMAGE_ALREADY_LOADED;
         return status;
-    default:
-        return STATUS_DLL_NOT_FOUND;
     }
 }
 
diff --git a/dlls/ntdll/unix/unix_private.h b/dlls/ntdll/unix/unix_private.h
index 1557aa2371a..05ba8202ee7 100644
--- a/dlls/ntdll/unix/unix_private.h
+++ b/dlls/ntdll/unix/unix_private.h
@@ -143,7 +143,7 @@ extern DWORD ntdll_umbstowcs( const char *src, DWORD srclen, WCHAR *dst, DWORD d
 extern int ntdll_wcstoumbs( const WCHAR *src, DWORD srclen, char *dst, DWORD dstlen, BOOL strict ) DECLSPEC_HIDDEN;
 extern char **build_envp( const WCHAR *envW ) DECLSPEC_HIDDEN;
 extern NTSTATUS exec_wineloader( char **argv, int socketfd, const pe_image_info_t *pe_info ) DECLSPEC_HIDDEN;
-extern NTSTATUS load_builtin( const pe_image_info_t *image_info, const WCHAR *filename,
+extern NTSTATUS load_builtin( const pe_image_info_t *image_info, WCHAR *filename,
                               void **addr_ptr, SIZE_T *size_ptr ) DECLSPEC_HIDDEN;
 extern BOOL is_builtin_path( const UNICODE_STRING *path, WORD *machine ) DECLSPEC_HIDDEN;
 extern NTSTATUS load_main_exe( const WCHAR *name, const char *unix_name, const WCHAR *curdir, WCHAR **image,




More information about the wine-cvs mailing list