kernelbase: Use RtlGetNativeSystemInformation() to implement GetNativeSystemInfo().

This commit is contained in:
Alexandre Julliard 2023-03-22 13:19:43 +01:00
parent 687068e7d6
commit ccd9640493
2 changed files with 80 additions and 74 deletions

View file

@ -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

View file

@ -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(), &current_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, &current_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 );
}