From: Davide Beatrici git@davidebeatrici.dev
--- dlls/ntdll/loader.c | 21 +++++-------------- dlls/ntdll/unix/loader.c | 44 ++++++++++------------------------------ 2 files changed, 16 insertions(+), 49 deletions(-)
diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c index 043bce67ea9..3f3a5d4fd00 100644 --- a/dlls/ntdll/loader.c +++ b/dlls/ntdll/loader.c @@ -33,9 +33,11 @@ #include "winternl.h" #include "delayloadhandler.h"
-#include "wine/exception.h" #include "wine/debug.h" +#include "wine/dir.h" +#include "wine/exception.h" #include "wine/list.h" + #include "ntdll_misc.h" #include "ddk/wdm.h"
@@ -51,18 +53,6 @@ WINE_DECLARE_DEBUG_CHANNEL(imports); #define DEFAULT_SECURITY_COOKIE_32 0xbb40e64e #define DEFAULT_SECURITY_COOKIE_16 (DEFAULT_SECURITY_COOKIE_32 >> 16)
-#ifdef __i386__ -static const WCHAR pe_dir[] = L"\i386-windows"; -#elif defined __x86_64__ -static const WCHAR pe_dir[] = L"\x86_64-windows"; -#elif defined __arm__ -static const WCHAR pe_dir[] = L"\arm-windows"; -#elif defined __aarch64__ -static const WCHAR pe_dir[] = L"\aarch64-windows"; -#else -static const WCHAR pe_dir[] = L""; -#endif - /* we don't want to include winuser.h */ #define RT_MANIFEST ((ULONG_PTR)24) #define ISOLATIONAWARE_MANIFEST_RESOURCE_ID ((ULONG_PTR)2) @@ -2954,10 +2944,9 @@ static NTSTATUS find_builtin_without_file( const WCHAR *name, UNICODE_STRING *ne for (i = 0; ; i++) { swprintf( dllpath, ARRAY_SIZE(dllpath), L"WINEDLLDIR%u", i ); - if (get_env_var( dllpath, wcslen(pe_dir) + wcslen(name) + 1, new_name )) break; + if (get_env_var( dllpath, sizeof(PE_DIR) + wcslen(name) + 1, new_name )) break; len = new_name->Length; - RtlAppendUnicodeToString( new_name, pe_dir ); - RtlAppendUnicodeToString( new_name, L"\" ); + RtlAppendUnicodeToString( new_name, L"\" PE_DIR "\" ); RtlAppendUnicodeToString( new_name, name ); status = open_dll_file( new_name, pwm, mapping, image_info, id ); if (status != STATUS_DLL_NOT_FOUND) goto done; diff --git a/dlls/ntdll/unix/loader.c b/dlls/ntdll/unix/loader.c index b78efddee1f..bcfa85a28d1 100644 --- a/dlls/ntdll/unix/loader.c +++ b/dlls/ntdll/unix/loader.c @@ -89,23 +89,13 @@ #include "winioctl.h" #include "winternl.h" #include "unix_private.h" -#include "wine/list.h" + #include "wine/debug.h" +#include "wine/dir.h" +#include "wine/list.h"
WINE_DEFAULT_DEBUG_CHANNEL(module);
-#ifdef __i386__ -static const char so_dir[] = "/i386-unix"; -#elif defined(__x86_64__) -static const char so_dir[] = "/x86_64-unix"; -#elif defined(__arm__) -static const char so_dir[] = "/arm-unix"; -#elif defined(__aarch64__) -static const char so_dir[] = "/aarch64-unix"; -#else -static const char so_dir[] = ""; -#endif - void (WINAPI *pDbgUiRemoteBreakin)( void *arg ) = NULL; NTSTATUS (WINAPI *pKiRaiseUserExceptionDispatcher)(void) = NULL; NTSTATUS (WINAPI *pKiUserExceptionDispatcher)(EXCEPTION_RECORD*,CONTEXT*) = NULL; @@ -512,21 +502,6 @@ static char *build_path( const char *dir, const char *name ) }
-static const char *get_pe_dir( WORD machine ) -{ - if (!machine) machine = current_machine; - - switch(machine) - { - case IMAGE_FILE_MACHINE_I386: return "/i386-windows"; - case IMAGE_FILE_MACHINE_AMD64: return "/x86_64-windows"; - case IMAGE_FILE_MACHINE_ARMNT: return "/arm-windows"; - case IMAGE_FILE_MACHINE_ARM64: return "/aarch64-windows"; - default: return ""; - } -} - - static void set_dll_path(void) { char *p, *path = getenv( "WINEDLLPATH" ); @@ -626,7 +601,7 @@ static void init_paths( char *argv[] )
if (!(build_dir = remove_tail( ntdll_dir, "/dlls/ntdll" ))) { - if (!(dll_dir = remove_tail( ntdll_dir, so_dir ))) dll_dir = ntdll_dir; + if (!(dll_dir = remove_tail( ntdll_dir, "/" SO_DIR ))) dll_dir = ntdll_dir; #if (defined(__linux__) && !defined(__ANDROID__)) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) bin_dir = realpath_dirname( "/proc/self/exe" ); #elif defined (__FreeBSD__) || defined(__DragonFly__) @@ -1538,11 +1513,14 @@ static NTSTATUS find_builtin_dll( UNICODE_STRING *nt_name, void **module, SIZE_T unsigned int i, pos, namepos, namelen, maxlen = 0; unsigned int len = nt_name->Length / sizeof(WCHAR); char *ptr = NULL, *file, *ext = NULL; - const char *pe_dir = get_pe_dir( machine ); + char pe_dir[PE_DIR_MAXLEN + 2] = "/"; + char so_dir[] = "/" SO_DIR; OBJECT_ATTRIBUTES attr; NTSTATUS status = STATUS_DLL_NOT_FOUND; BOOL found_image = FALSE;
+ strcat(pe_dir, machine ? get_pe_dir(machine) : PE_DIR); + for (i = namepos = 0; i < len; i++) if (nt_name->Buffer[i] == '/' || nt_name->Buffer[i] == '\') namepos = i + 1; len -= namepos; @@ -1550,7 +1528,7 @@ static NTSTATUS find_builtin_dll( UNICODE_STRING *nt_name, void **module, SIZE_T InitializeObjectAttributes( &attr, nt_name, 0, 0, NULL );
if (build_dir) maxlen = strlen(build_dir) + sizeof("/programs/") + len; - maxlen = max( maxlen, dll_path_maxlen + 1 ) + len + sizeof("/aarch64-windows") + sizeof(".so"); + maxlen = max( maxlen, dll_path_maxlen + 1 ) + len + sizeof(pe_dir) + sizeof(".so");
if (!(file = malloc( maxlen ))) return STATUS_NO_MEMORY;
@@ -1969,7 +1947,7 @@ static void load_ntdll(void) { static WCHAR path[] = {'\','?','?','\','C',':','\','w','i','n','d','o','w','s','\', 's','y','s','t','e','m','3','2','\','n','t','d','l','l','.','d','l','l',0}; - const char *pe_dir = get_pe_dir( current_machine ); + const char pe_dir[] = "/" PE_DIR; NTSTATUS status; SECTION_IMAGE_INFORMATION info; OBJECT_ATTRIBUTES attr; @@ -2006,7 +1984,7 @@ static void load_apiset_dll(void) static WCHAR path[] = {'\','?','?','\','C',':','\','w','i','n','d','o','w','s','\', 's','y','s','t','e','m','3','2','\', 'a','p','i','s','e','t','s','c','h','e','m','a','.','d','l','l',0}; - const char *pe_dir = get_pe_dir( current_machine ); + const char pe_dir[] = "/" PE_DIR; const IMAGE_NT_HEADERS *nt; const IMAGE_SECTION_HEADER *sec; API_SET_NAMESPACE *map;