In order to reduce the amount of duplicates across the codebase.
From: Davide Beatrici git@davidebeatrici.dev
In order to reduce the amount of duplicates across the codebase. --- include/Makefile.in | 1 + include/wine/dir.h | 69 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 include/wine/dir.h
diff --git a/include/Makefile.in b/include/Makefile.in index 1c04f9a298b..561ad2d1285 100644 --- a/include/Makefile.in +++ b/include/Makefile.in @@ -821,6 +821,7 @@ SOURCES = \ wine/condrv.h \ wine/dcetypes.idl \ wine/debug.h \ + wine/dir.h \ wine/dplaysp.h \ wine/epm.idl \ wine/exception.h \ diff --git a/include/wine/dir.h b/include/wine/dir.h new file mode 100644 index 00000000000..dac9c52a604 --- /dev/null +++ b/include/wine/dir.h @@ -0,0 +1,69 @@ +/* + * Definitions for internal dirs + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef __WINE_WINE_DIR_H +#define __WINE_WINE_DIR_H + +#define SO_DIR_I386 "i386-unix" +#define PE_DIR_I386 "i386-windows" + +#define SO_DIR_X86_64 "x86_64-unix" +#define PE_DIR_X86_64 "x86_64-windows" + +#define SO_DIR_ARM "arm-unix" +#define PE_DIR_ARM "arm-windows" + +#define SO_DIR_AARCH64 "aarch64-unix" +#define PE_DIR_AARCH64 "aarch64-windows" + +#define SO_DIR_MAXLEN (sizeof(SO_DIR_AARCH64) - 1) +#define PE_DIR_MAXLEN (sizeof(PE_DIR_AARCH64) - 1) + +#if defined(__i386__) +#define SO_DIR SO_DIR_I386 +#define PE_DIR PE_DIR_I386 +#elif defined(__x86_64__) +#define SO_DIR SO_DIR_X86_64 +#define PE_DIR PE_DIR_X86_64 +#elif defined(__arm__) +#define SO_DIR SO_DIR_ARM +#define PE_DIR PE_DIR_ARM +#elif defined(__aarch64__) +#define SO_DIR SO_DIR_AARCH64 +#define PE_DIR PE_DIR_AARCH64 +#else +#define SO_DIR "" +#define PE_DIR "" +#endif + +static inline const char *get_pe_dir( const unsigned short machine ) +{ + switch (machine) + { + case 0x0000: return ""; /* IMAGE_FILE_MACHINE_UNKNOWN */ + case 0x0001: return PE_DIR; /* IMAGE_FILE_MACHINE_TARGET_HOST */ + case 0x014c: return PE_DIR_I386; /* IMAGE_FILE_MACHINE_I386 */ + case 0x8664: return PE_DIR_X86_64; /* IMAGE_FILE_MACHINE_AMD64 */ + case 0x01c4: return PE_DIR_ARM; /* IMAGE_FILE_MACHINE_ARMNT */ + case 0xaa64: return PE_DIR_AARCH64; /* IMAGE_FILE_MACHINE_ARM64 */ + } + + return NULL; +} + +#endif /* __WINE_WINE_DIR_H */
From: Davide Beatrici git@davidebeatrici.dev
--- dlls/dbghelp/path.c | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-)
diff --git a/dlls/dbghelp/path.c b/dlls/dbghelp/path.c index 5b4172e4001..bf824a8c1a8 100644 --- a/dlls/dbghelp/path.c +++ b/dlls/dbghelp/path.c @@ -26,28 +26,13 @@ #include "image_private.h" #include "winnls.h" #include "winternl.h" + #include "wine/debug.h" +#include "wine/dir.h" #include "wine/heap.h"
WINE_DEFAULT_DEBUG_CHANNEL(dbghelp);
-#ifdef __i386__ -static const WCHAR pe_dir[] = L"\i386-windows"; -static const WCHAR so_dir[] = L"\i386-unix"; -#elif defined __x86_64__ -static const WCHAR pe_dir[] = L"\x86_64-windows"; -static const WCHAR so_dir[] = L"\x86_64-unix"; -#elif defined __arm__ -static const WCHAR pe_dir[] = L"\arm-windows"; -static const WCHAR so_dir[] = L"\arm-unix"; -#elif defined __aarch64__ -static const WCHAR pe_dir[] = L"\aarch64-windows"; -static const WCHAR so_dir[] = L"\aarch64-unix"; -#else -static const WCHAR pe_dir[] = L""; -static const WCHAR so_dir[] = L""; -#endif - static inline BOOL is_sepA(char ch) {return ch == '/' || ch == '\';} static inline BOOL is_sep(WCHAR ch) {return ch == '/' || ch == '\';}
@@ -765,12 +750,12 @@ BOOL search_dll_path(const struct process *process, const WCHAR *name, BOOL (*ma WCHAR env_name[64]; swprintf(env_name, ARRAY_SIZE(env_name), L"WINEDLLDIR%u", i); if (!(env = process_getenv(process, env_name))) return FALSE; - len = wcslen(env) + wcslen(pe_dir) + wcslen(name) + 2; + len = wcslen(env) + sizeof(PE_DIR) + wcslen(name) + 2; if (!(buf = heap_alloc(len * sizeof(WCHAR)))) return FALSE; if ((p = wcsrchr(name, '.')) && !lstrcmpW(p, L".so")) - swprintf(buf, len, L"%s%s\%s", env, so_dir, name); + swprintf(buf, len, L"%s\%s\%s", env, L"" SO_DIR, name); else - swprintf(buf, len, L"%s%s\%s", env, pe_dir, name); + swprintf(buf, len, L"%s\%s\%s", env, L"" PE_DIR, name); file = CreateFileW(buf, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (file != INVALID_HANDLE_VALUE) {
Hi,
It looks like your patch introduced the new failures shown below. Please investigate and fix them before resubmitting your patch. If they are not new, fixing them anyway would help a lot. Otherwise please ask for the known failures list to be updated.
The tests also ran into some preexisting test failures. If you know how to fix them that would be helpful. See the TestBot job for the details:
The full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=124757
Your paranoid android.
=== debian11 (32 bit report) ===
ntoskrnl.exe: ntoskrnl.c:1707: Test succeeded inside todo block: got error 997 driver_pnp.c:737: Test failed: expected IRP_MN_REMOVE_DEVICE
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;
From: Davide Beatrici git@davidebeatrici.dev
--- dlls/setupapi/fakedll.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/dlls/setupapi/fakedll.c b/dlls/setupapi/fakedll.c index 075e12f5629..c905fd83a1e 100644 --- a/dlls/setupapi/fakedll.c +++ b/dlls/setupapi/fakedll.c @@ -33,27 +33,25 @@ #include "winuser.h" #include "winnt.h" #include "winternl.h" + #include "wine/debug.h" +#include "wine/dir.h" #include "wine/list.h" + #include "ole2.h" #include "atliface.h"
WINE_DEFAULT_DEBUG_CHANNEL(setupapi);
#ifdef __i386__ -static const WCHAR pe_dir[] = L"\i386-windows"; static const char current_arch[] = "x86"; #elif defined __x86_64__ -static const WCHAR pe_dir[] = L"\x86_64-windows"; static const char current_arch[] = "amd64"; #elif defined __arm__ -static const WCHAR pe_dir[] = L"\arm-windows"; static const char current_arch[] = "arm"; #elif defined __aarch64__ -static const WCHAR pe_dir[] = L"\aarch64-windows"; static const char current_arch[] = "arm64"; #else -static const WCHAR pe_dir[] = L""; static const char current_arch[] = "none"; #endif
@@ -418,6 +416,7 @@ static const WCHAR *enum_load_path( unsigned int idx ) static void *load_fake_dll( const WCHAR *name, SIZE_T *size ) { const WCHAR *build_dir = _wgetenv( L"WINEBUILDDIR" ); + const WCHAR pe_dir[] = L"\" PE_DIR; const WCHAR *path; WCHAR *file, *ptr; void *data = NULL; @@ -997,6 +996,7 @@ static void install_lib_dir( WCHAR *dest, WCHAR *file, const WCHAR *wildcard, static BOOL create_wildcard_dlls( const WCHAR *dirname, const WCHAR *wildcard, BOOL delete ) { const WCHAR *build_dir = _wgetenv( L"WINEBUILDDIR" ); + const WCHAR pe_dir[] = L"\" PE_DIR; const WCHAR *path; unsigned int i, maxlen = 0; WCHAR *file, *dest, *p;
From: Davide Beatrici git@davidebeatrici.dev
--- loader/main.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-)
diff --git a/loader/main.c b/loader/main.c index 242ff15accd..e53ee5c2c8b 100644 --- a/loader/main.c +++ b/loader/main.c @@ -34,6 +34,8 @@ # include <sys/sysctl.h> #endif
+#include "wine/dir.h" + #include "main.h"
extern char **environ; @@ -126,17 +128,6 @@ static void *try_dlopen( const char *dir, const char *name )
static void *load_ntdll( char *argv0 ) { -#ifdef __i386__ -#define SO_DIR "i386-unix/" -#elif defined(__x86_64__) -#define SO_DIR "x86_64-unix/" -#elif defined(__arm__) -#define SO_DIR "arm-unix/" -#elif defined(__aarch64__) -#define SO_DIR "aarch64-unix/" -#else -#define SO_DIR "" -#endif const char *self = get_self_exe( argv0 ); char *path, *p; void *handle = NULL; @@ -148,7 +139,7 @@ static void *load_ntdll( char *argv0 ) handle = try_dlopen( p, "dlls/ntdll/ntdll.so" ); free( p ); } - else handle = try_dlopen( path, BIN_TO_DLLDIR "/" SO_DIR "ntdll.so" ); + else handle = try_dlopen( path, BIN_TO_DLLDIR "/" SO_DIR "/ntdll.so" ); free( path ); }
@@ -157,14 +148,14 @@ static void *load_ntdll( char *argv0 ) path = strdup( path ); for (p = strtok( path, ":" ); p; p = strtok( NULL, ":" )) { - handle = try_dlopen( p, SO_DIR "ntdll.so" ); + handle = try_dlopen( p, SO_DIR "/ntdll.so" ); if (!handle) handle = try_dlopen( p, "ntdll.so" ); if (handle) break; } free( path ); }
- if (!handle && !self) handle = try_dlopen( DLLDIR, SO_DIR "ntdll.so" ); + if (!handle && !self) handle = try_dlopen( DLLDIR, SO_DIR "/ntdll.so" );
return handle; }
From: Davide Beatrici git@davidebeatrici.dev
--- programs/winecfg/libraries.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-)
diff --git a/programs/winecfg/libraries.c b/programs/winecfg/libraries.c index 7beb905188f..a27d75ea1e1 100644 --- a/programs/winecfg/libraries.c +++ b/programs/winecfg/libraries.c @@ -29,22 +29,12 @@
#include "winecfg.h" #include "resource.h" + #include "wine/debug.h" +#include "wine/dir.h"
WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
-#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 - /* dlls that shouldn't be configured anything other than builtin; list must be sorted*/ static const WCHAR * const builtin_only[] = { @@ -332,7 +322,7 @@ static void load_library_list( HWND dialog ) swprintf( var, ARRAY_SIZE(var), L"WINEDLLDIR%u", i++ ); if (!GetEnvironmentVariableW( var, path, MAX_PATH )) break; load_library_list_from_dir( dialog, path, FALSE ); - wcscat( path, pe_dir ); + wcscat( path, L"\" PE_DIR ); load_library_list_from_dir( dialog, path, FALSE ); }
This merge request was closed by Alexandre Julliard.
In order to reduce the amount of duplicates across the codebase.
I don't think that a few duplicated strings justify adding a new global header.
On Mon Oct 10 18:27:03 2022 +0000, Alexandre Julliard wrote:
In order to reduce the amount of duplicates across the codebase.
I don't think that a few duplicated strings justify adding a new global header.
Well, the global header would also be used for related functions in the future. I can see it becoming especially useful with WoW64.
In any case, I can move the content into an already existing global header or a new internal one, if you wish.
In any case, I can move the content into an already existing global header or a new internal one, if you wish.
I don't think that this would be an improvement either.
On Mon Oct 10 19:18:42 2022 +0000, Alexandre Julliard wrote:
In any case, I can move the content into an already existing global
header or a new internal one, if you wish. I don't think that this would be an improvement either.
I mean, I understand that the directory names are not going to change anytime soon (as far as I know), but redefining them for each source file in which they are required feels kind of "hacky" to me.