Module: wine Branch: master Commit: 4f8ede8e7665328a2a3ccd303875e239bf443512 URL: https://source.winehq.org/git/wine.git/?a=commit;h=4f8ede8e7665328a2a3ccd303...
Author: Alexandre Julliard julliard@winehq.org Date: Thu Apr 29 17:15:15 2021 +0200
ntdll: Implement RtlWow64IsWowGuestMachineSupported().
Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/ntdll/ntdll.spec | 1 + dlls/ntdll/process.c | 22 ++++++++++++++++++++++ dlls/ntdll/tests/info.c | 26 ++++++++++++++++++++++++++ include/winternl.h | 1 + 4 files changed, 50 insertions(+)
diff --git a/dlls/ntdll/ntdll.spec b/dlls/ntdll/ntdll.spec index 431ab7c6db7..4da9ea5a0b1 100644 --- a/dlls/ntdll/ntdll.spec +++ b/dlls/ntdll/ntdll.spec @@ -1071,6 +1071,7 @@ @ stdcall RtlWow64GetCurrentMachine() @ stdcall RtlWow64GetProcessMachines(long ptr ptr) @ stdcall -arch=x86_64 RtlWow64GetThreadContext(long ptr) +@ stdcall RtlWow64IsWowGuestMachineSupported(long ptr) @ stdcall -arch=x86_64 RtlWow64SetThreadContext(long ptr) @ stub RtlWriteMemoryStream @ stdcall RtlWriteRegistryValue(long ptr ptr long ptr long) diff --git a/dlls/ntdll/process.c b/dlls/ntdll/process.c index f42dc6d8201..dbb94cfb8b7 100644 --- a/dlls/ntdll/process.c +++ b/dlls/ntdll/process.c @@ -86,6 +86,28 @@ NTSTATUS WINAPI RtlWow64GetProcessMachines( HANDLE process, USHORT *current_ret, }
+/********************************************************************** + * RtlWow64IsWowGuestMachineSupported (NTDLL.@) + */ +NTSTATUS WINAPI RtlWow64IsWowGuestMachineSupported( USHORT machine, BOOLEAN *supported ) +{ + ULONG i, machines[8]; + HANDLE process = 0; + NTSTATUS status; + + status = NtQuerySystemInformationEx( SystemSupportedProcessorArchitectures, &process, sizeof(process), + machines, sizeof(machines), NULL ); + if (status) return status; + *supported = FALSE; + for (i = 0; machines[i]; i++) + { + if (HIWORD(machines[i]) & 4 /* native machine */) continue; + if (machine == LOWORD(machines[i])) *supported = TRUE; + } + return status; +} + + /********************************************************************** * RtlCreateUserProcess (NTDLL.@) */ diff --git a/dlls/ntdll/tests/info.c b/dlls/ntdll/tests/info.c index af53c696cdf..d27ec576637 100644 --- a/dlls/ntdll/tests/info.c +++ b/dlls/ntdll/tests/info.c @@ -27,6 +27,7 @@ static NTSTATUS (WINAPI * pNtSetSystemInformation)(SYSTEM_INFORMATION_CLASS, PVO static NTSTATUS (WINAPI * pRtlGetNativeSystemInformation)(SYSTEM_INFORMATION_CLASS, PVOID, ULONG, PULONG); static USHORT (WINAPI * pRtlWow64GetCurrentMachine)(void); static NTSTATUS (WINAPI * pRtlWow64GetProcessMachines)(HANDLE,WORD*,WORD*); +static NTSTATUS (WINAPI * pRtlWow64IsWowGuestMachineSupported)(USHORT,BOOLEAN*); static NTSTATUS (WINAPI * pNtQuerySystemInformationEx)(SYSTEM_INFORMATION_CLASS, void*, ULONG, void*, ULONG, ULONG*); static NTSTATUS (WINAPI * pNtPowerInformation)(POWER_INFORMATION_LEVEL, PVOID, ULONG, PVOID, ULONG); static NTSTATUS (WINAPI * pNtQueryInformationProcess)(HANDLE, PROCESSINFOCLASS, PVOID, ULONG, PULONG); @@ -86,6 +87,7 @@ static BOOL InitFunctionPtrs(void) NTDLL_GET_PROC(RtlGetNativeSystemInformation); NTDLL_GET_PROC(RtlWow64GetCurrentMachine); NTDLL_GET_PROC(RtlWow64GetProcessMachines); + NTDLL_GET_PROC(RtlWow64IsWowGuestMachineSupported); NTDLL_GET_PROC(NtPowerInformation); NTDLL_GET_PROC(NtQueryInformationProcess); NTDLL_GET_PROC(NtQueryInformationThread); @@ -3017,6 +3019,30 @@ static void test_query_architectures(void) USHORT machine = pRtlWow64GetCurrentMachine(); ok( machine == current_machine, "wrong machine %x / %x\n", machine, current_machine ); } + if (pRtlWow64IsWowGuestMachineSupported) + { + BOOLEAN ret = 0xcc; + status = pRtlWow64IsWowGuestMachineSupported( IMAGE_FILE_MACHINE_I386, &ret ); + ok( !status, "failed %x\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 %x\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 %x\n", status ); + ok( !ret, "wrong result %u\n", ret ); + ret = 0xcc; + status = pRtlWow64IsWowGuestMachineSupported( IMAGE_FILE_MACHINE_ARM64, &ret ); + ok( !status, "failed %x\n", status ); + ok( !ret, "wrong result %u\n", ret ); + ret = 0xcc; + status = pRtlWow64IsWowGuestMachineSupported( 0xdead, &ret ); + ok( !status, "failed %x\n", status ); + ok( !ret, "wrong result %u\n", ret ); + } }
static void test_thread_lookup(void) diff --git a/include/winternl.h b/include/winternl.h index 5067fa8ae34..82014d7fb11 100644 --- a/include/winternl.h +++ b/include/winternl.h @@ -4258,6 +4258,7 @@ NTSYSAPI NTSTATUS WINAPI RtlWow64GetProcessMachines(HANDLE,USHORT*,USHORT*); NTSYSAPI NTSTATUS WINAPI RtlWow64GetThreadContext(HANDLE, WOW64_CONTEXT *); NTSYSAPI NTSTATUS WINAPI RtlWow64SetThreadContext(HANDLE, const WOW64_CONTEXT *); #endif +NTSYSAPI NTSTATUS WINAPI RtlWow64IsWowGuestMachineSupported(USHORT,BOOLEAN*); NTSYSAPI NTSTATUS WINAPI RtlWriteRegistryValue(ULONG,PCWSTR,PCWSTR,ULONG,PVOID,ULONG); NTSYSAPI NTSTATUS WINAPI RtlZombifyActivationContext(HANDLE); NTSYSAPI NTSTATUS WINAPI RtlpNtCreateKey(PHANDLE,ACCESS_MASK,const OBJECT_ATTRIBUTES*,ULONG,const UNICODE_STRING*,ULONG,PULONG);