Module: wine Branch: master Commit: cf7c48e0366ec27dd946f2fcec12cb66f2e0cb23 URL: https://gitlab.winehq.org/wine/wine/-/commit/cf7c48e0366ec27dd946f2fcec12cb6...
Author: Alexandre Julliard julliard@winehq.org Date: Thu Feb 8 16:30:24 2024 +0100
ntdll: Fix RtlWow64GetCurrentMachine() result on ARM64EC.
---
dlls/ntdll/loader.c | 5 ----- dlls/ntdll/ntdll_misc.h | 12 ++++++++++++ dlls/ntdll/process.c | 9 +++++---- dlls/ntdll/tests/wow64.c | 38 ++++++++++++++++---------------------- 4 files changed, 33 insertions(+), 31 deletions(-)
diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c index 4fc8af2662e..55065117a01 100644 --- a/dlls/ntdll/loader.c +++ b/dlls/ntdll/loader.c @@ -51,19 +51,14 @@ WINE_DECLARE_DEBUG_CHANNEL(imports);
#ifdef __i386__ static const WCHAR pe_dir[] = L"\i386-windows"; -static const USHORT current_machine = IMAGE_FILE_MACHINE_I386; #elif defined __x86_64__ static const WCHAR pe_dir[] = L"\x86_64-windows"; -static const USHORT current_machine = IMAGE_FILE_MACHINE_AMD64; #elif defined __arm__ static const WCHAR pe_dir[] = L"\arm-windows"; -static const USHORT current_machine = IMAGE_FILE_MACHINE_ARMNT; #elif defined __aarch64__ static const WCHAR pe_dir[] = L"\aarch64-windows"; -static const USHORT current_machine = IMAGE_FILE_MACHINE_ARM64; #else static const WCHAR pe_dir[] = L""; -static const USHORT current_machine = IMAGE_FILE_MACHINE_UNKNOWN; #endif
/* we don't want to include winuser.h */ diff --git a/dlls/ntdll/ntdll_misc.h b/dlls/ntdll/ntdll_misc.h index e4094d341d8..58e29837cd0 100644 --- a/dlls/ntdll/ntdll_misc.h +++ b/dlls/ntdll/ntdll_misc.h @@ -41,6 +41,18 @@
#define NTDLL_TLS_ERRNO 16 /* TLS slot for _errno() */
+#ifdef __i386__ +static const USHORT current_machine = IMAGE_FILE_MACHINE_I386; +#elif defined(__x86_64__) +static const USHORT current_machine = IMAGE_FILE_MACHINE_AMD64; +#elif defined(__arm__) +static const USHORT current_machine = IMAGE_FILE_MACHINE_ARMNT; +#elif defined(__aarch64__) +static const USHORT current_machine = IMAGE_FILE_MACHINE_ARM64; +#else +static const USHORT current_machine = IMAGE_FILE_MACHINE_UNKNOWN; +#endif + #if defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__aarch64__) static const UINT_PTR page_size = 0x1000; #else diff --git a/dlls/ntdll/process.c b/dlls/ntdll/process.c index dcdb26f81d1..102e0c930a9 100644 --- a/dlls/ntdll/process.c +++ b/dlls/ntdll/process.c @@ -94,10 +94,11 @@ NTSTATUS WINAPI RtlWow64EnableFsRedirectionEx( ULONG disable, ULONG *old_value ) */ USHORT WINAPI RtlWow64GetCurrentMachine(void) { - USHORT current, native; - - RtlWow64GetProcessMachines( GetCurrentProcess(), ¤t, &native ); - return current ? current : native; + USHORT machine = current_machine; +#ifdef _WIN64 + if (NtCurrentTeb()->WowTebOffset) RtlWow64GetCurrentCpuArea( &machine, NULL, NULL ); +#endif + return machine; }
diff --git a/dlls/ntdll/tests/wow64.c b/dlls/ntdll/tests/wow64.c index a1beb9a4997..aebff700940 100644 --- a/dlls/ntdll/tests/wow64.c +++ b/dlls/ntdll/tests/wow64.c @@ -289,7 +289,7 @@ static void test_query_architectures(void) STARTUPINFOA si = { sizeof(si) }; NTSTATUS status; HANDLE process; - ULONG len; + ULONG i, len; #ifdef __arm64ec__ BOOL is_arm64ec = TRUE; #else @@ -383,27 +383,21 @@ static void test_query_architectures(void) } if (pRtlWow64IsWowGuestMachineSupported) { - BOOLEAN ret = 0xcc; - status = pRtlWow64IsWowGuestMachineSupported( IMAGE_FILE_MACHINE_I386, &ret ); - ok( !status, "failed %lx\n", status ); - ok( ret == (native_machine == IMAGE_FILE_MACHINE_AMD64 || - native_machine == IMAGE_FILE_MACHINE_ARM64), "wrong result %u\n", ret ); - ret = 0xcc; - status = pRtlWow64IsWowGuestMachineSupported( IMAGE_FILE_MACHINE_ARMNT, &ret ); - ok( !status, "failed %lx\n", status ); - ok( !ret || native_machine == IMAGE_FILE_MACHINE_ARM64, "wrong result %u\n", ret ); - ret = 0xcc; - status = pRtlWow64IsWowGuestMachineSupported( IMAGE_FILE_MACHINE_AMD64, &ret ); - ok( !status, "failed %lx\n", status ); - ok( !ret || native_machine == IMAGE_FILE_MACHINE_ARM64, "wrong result %u\n", ret ); - ret = 0xcc; - status = pRtlWow64IsWowGuestMachineSupported( IMAGE_FILE_MACHINE_ARM64, &ret ); - ok( !status, "failed %lx\n", status ); - ok( !ret, "wrong result %u\n", ret ); - ret = 0xcc; - status = pRtlWow64IsWowGuestMachineSupported( 0xdead, &ret ); - ok( !status, "failed %lx\n", status ); - ok( !ret, "wrong result %u\n", ret ); + static const WORD machines[] = { IMAGE_FILE_MACHINE_I386, IMAGE_FILE_MACHINE_ARMNT, + IMAGE_FILE_MACHINE_AMD64, IMAGE_FILE_MACHINE_ARM64, 0xdead }; + + for (i = 0; i < ARRAY_SIZE(machines); i++) + { + BOOLEAN ret = 0xcc; + status = pRtlWow64IsWowGuestMachineSupported( machines[i], &ret ); + ok( !status, "failed %lx\n", status ); + if (is_machine_32bit( machines[i] ) && !is_machine_32bit( native_machine )) + ok( ret || machines[i] == IMAGE_FILE_MACHINE_ARMNT || + broken(current_machine == IMAGE_FILE_MACHINE_I386), /* win10-1607 wow64 */ + "%04x: got %u\n", machines[i], ret ); + else + ok( !ret, "%04x: got %u\n", machines[i], ret ); + } } }