From ccd964049334df285e5caba54fea42c031bdec5a Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Wed, 22 Mar 2023 13:19:43 +0100 Subject: [PATCH] kernelbase: Use RtlGetNativeSystemInformation() to implement GetNativeSystemInfo(). --- dlls/kernel32/tests/process.c | 18 +++-- dlls/kernelbase/memory.c | 136 +++++++++++++++++----------------- 2 files changed, 80 insertions(+), 74 deletions(-) diff --git a/dlls/kernel32/tests/process.c b/dlls/kernel32/tests/process.c index 1e30ba73bbf..3c4a02e7cc8 100644 --- a/dlls/kernel32/tests/process.c +++ b/dlls/kernel32/tests/process.c @@ -2202,12 +2202,12 @@ static void test_IsWow64Process2(void) #if defined(__i386__) || defined(__x86_64__) ok(machine == IMAGE_FILE_MACHINE_I386, "got %#x\n", machine); - expect_native = IMAGE_FILE_MACHINE_AMD64; + ok( native_machine == IMAGE_FILE_MACHINE_AMD64 || + native_machine == IMAGE_FILE_MACHINE_ARM64, "got %#x\n", native_machine); + expect_native = native_machine; #else skip("not supported architecture\n"); #endif - ok(native_machine == expect_native, "got %#x\n", native_machine); - ret = TerminateProcess(pi.hProcess, 0); ok(ret, "TerminateProcess error\n"); @@ -2279,6 +2279,7 @@ static void test_SystemInfo(void) { SYSTEM_INFO si, nsi; BOOL is_wow64; + USHORT machine, native_machine; if (!pGetNativeSystemInfo) { @@ -2297,9 +2298,14 @@ static void test_SystemInfo(void) ok(S(U(nsi)).wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64, "Expected PROCESSOR_ARCHITECTURE_AMD64, got %d\n", S(U(nsi)).wProcessorArchitecture); - ok(nsi.dwProcessorType == PROCESSOR_AMD_X8664, - "Expected PROCESSOR_AMD_X8664, got %ld\n", - nsi.dwProcessorType); + if (pIsWow64Process2 && pIsWow64Process2(GetCurrentProcess(), &machine, &native_machine) && + native_machine == IMAGE_FILE_MACHINE_ARM64) + { + ok(nsi.dwProcessorType == PROCESSOR_INTEL_PENTIUM, "got %ld\n", nsi.dwProcessorType); + ok(nsi.wProcessorLevel == 15, "got %d\n", nsi.wProcessorLevel); + ok(nsi.wProcessorRevision == 0x40a, "got %d\n", nsi.wProcessorRevision); + } + else ok(nsi.dwProcessorType == PROCESSOR_AMD_X8664, "got %ld\n", nsi.dwProcessorType); } } else diff --git a/dlls/kernelbase/memory.c b/dlls/kernelbase/memory.c index 094556eaba2..c4a484b5a30 100644 --- a/dlls/kernelbase/memory.c +++ b/dlls/kernelbase/memory.c @@ -83,29 +83,81 @@ SIZE_T WINAPI GetLargePageMinimum(void) } +static void fill_system_info( SYSTEM_INFO *si, const SYSTEM_BASIC_INFORMATION *basic_info, + const SYSTEM_CPU_INFORMATION *cpu_info ) +{ + si->u.s.wProcessorArchitecture = cpu_info->ProcessorArchitecture; + si->u.s.wReserved = 0; + si->dwPageSize = basic_info->PageSize; + si->lpMinimumApplicationAddress = basic_info->LowestUserAddress; + si->lpMaximumApplicationAddress = basic_info->HighestUserAddress; + si->dwActiveProcessorMask = basic_info->ActiveProcessorsAffinityMask; + si->dwNumberOfProcessors = basic_info->NumberOfProcessors; + si->dwAllocationGranularity = basic_info->AllocationGranularity; + si->wProcessorLevel = cpu_info->ProcessorLevel; + si->wProcessorRevision = cpu_info->ProcessorRevision; + + switch (cpu_info->ProcessorArchitecture) + { + case PROCESSOR_ARCHITECTURE_INTEL: + switch (cpu_info->ProcessorLevel) + { + case 3: si->dwProcessorType = PROCESSOR_INTEL_386; break; + case 4: si->dwProcessorType = PROCESSOR_INTEL_486; break; + case 5: + case 6: si->dwProcessorType = PROCESSOR_INTEL_PENTIUM; break; + default: si->dwProcessorType = PROCESSOR_INTEL_PENTIUM; break; + } + break; + case PROCESSOR_ARCHITECTURE_AMD64: + si->dwProcessorType = PROCESSOR_AMD_X8664; + break; + case PROCESSOR_ARCHITECTURE_ARM: + switch (cpu_info->ProcessorLevel) + { + case 4: si->dwProcessorType = PROCESSOR_ARM_7TDMI; break; + default: si->dwProcessorType = PROCESSOR_ARM920; + } + break; + case PROCESSOR_ARCHITECTURE_ARM64: + si->dwProcessorType = 0; + break; + default: + FIXME( "Unknown processor architecture %x\n", cpu_info->ProcessorArchitecture ); + si->dwProcessorType = 0; + break; + } +} + + /*********************************************************************** * GetNativeSystemInfo (kernelbase.@) */ void WINAPI DECLSPEC_HOTPATCH GetNativeSystemInfo( SYSTEM_INFO *si ) { - USHORT current_machine, native_machine; + SYSTEM_BASIC_INFORMATION basic_info; + SYSTEM_CPU_INFORMATION cpu_info; - GetSystemInfo( si ); - RtlWow64GetProcessMachines( GetCurrentProcess(), ¤t_machine, &native_machine ); - if (!current_machine) return; - switch (native_machine) + if (is_wow64) { - case IMAGE_FILE_MACHINE_AMD64: - si->u.s.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_AMD64; - si->dwProcessorType = PROCESSOR_AMD_X8664; - break; - case IMAGE_FILE_MACHINE_ARM64: - si->u.s.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_ARM64; - si->dwProcessorType = 0; - break; - default: - FIXME( "Add the proper information for %x in wow64 mode\n", native_machine ); + USHORT current_machine, native_machine; + + RtlWow64GetProcessMachines( 0, ¤t_machine, &native_machine ); + if (native_machine != IMAGE_FILE_MACHINE_AMD64) + { + GetSystemInfo( si ); + si->u.s.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_AMD64; + return; + } } + + if (!set_ntstatus( RtlGetNativeSystemInformation( SystemBasicInformation, + &basic_info, sizeof(basic_info), NULL )) || + !set_ntstatus( RtlGetNativeSystemInformation( SystemCpuInformation, + &cpu_info, sizeof(cpu_info), NULL ))) + return; + + fill_system_info( si, &basic_info, &cpu_info ); } @@ -123,59 +175,7 @@ void WINAPI DECLSPEC_HOTPATCH GetSystemInfo( SYSTEM_INFO *si ) &cpu_info, sizeof(cpu_info), NULL ))) return; - si->u.s.wProcessorArchitecture = cpu_info.ProcessorArchitecture; - si->u.s.wReserved = 0; - si->dwPageSize = basic_info.PageSize; - si->lpMinimumApplicationAddress = basic_info.LowestUserAddress; - si->lpMaximumApplicationAddress = basic_info.HighestUserAddress; - si->dwActiveProcessorMask = basic_info.ActiveProcessorsAffinityMask; - si->dwNumberOfProcessors = basic_info.NumberOfProcessors; - si->dwAllocationGranularity = basic_info.AllocationGranularity; - si->wProcessorLevel = cpu_info.ProcessorLevel; - si->wProcessorRevision = cpu_info.ProcessorRevision; - - switch (cpu_info.ProcessorArchitecture) - { - case PROCESSOR_ARCHITECTURE_INTEL: - switch (cpu_info.ProcessorLevel) - { - case 3: si->dwProcessorType = PROCESSOR_INTEL_386; break; - case 4: si->dwProcessorType = PROCESSOR_INTEL_486; break; - case 5: - case 6: si->dwProcessorType = PROCESSOR_INTEL_PENTIUM; break; - default: si->dwProcessorType = PROCESSOR_INTEL_PENTIUM; break; - } - break; - case PROCESSOR_ARCHITECTURE_PPC: - switch (cpu_info.ProcessorLevel) - { - case 1: si->dwProcessorType = PROCESSOR_PPC_601; break; - case 3: - case 6: si->dwProcessorType = PROCESSOR_PPC_603; break; - case 4: si->dwProcessorType = PROCESSOR_PPC_604; break; - case 9: si->dwProcessorType = PROCESSOR_PPC_604; break; - case 20: si->dwProcessorType = PROCESSOR_PPC_620; break; - default: si->dwProcessorType = 0; - } - break; - case PROCESSOR_ARCHITECTURE_AMD64: - si->dwProcessorType = PROCESSOR_AMD_X8664; - break; - case PROCESSOR_ARCHITECTURE_ARM: - switch (cpu_info.ProcessorLevel) - { - case 4: si->dwProcessorType = PROCESSOR_ARM_7TDMI; break; - default: si->dwProcessorType = PROCESSOR_ARM920; - } - break; - case PROCESSOR_ARCHITECTURE_ARM64: - si->dwProcessorType = 0; - break; - default: - FIXME( "Unknown processor architecture %x\n", cpu_info.ProcessorArchitecture ); - si->dwProcessorType = 0; - break; - } + fill_system_info( si, &basic_info, &cpu_info ); }