Skip to content

Commit

Permalink
Use IsWow64Process2 to determine system architecture (microsoft#5125)
Browse files Browse the repository at this point in the history
Due to legacy reasons, GetNativeSystemInfo() will return x64 when x86
binaries running on arm64 machines. IsWow64Process2 is the new api
that'll correctly report host machine architecture.
  • Loading branch information
yao-msft authored Jan 10, 2025
1 parent d8819d0 commit 5cfc9da
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/AppInstallerCommonCore/Architecture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,22 +229,23 @@ namespace AppInstaller::Utility
{
Architecture systemArchitecture = Architecture::Unknown;

SYSTEM_INFO systemInfo;
ZeroMemory(&systemInfo, sizeof(SYSTEM_INFO));
GetNativeSystemInfo(&systemInfo);
USHORT processArchitecture = IMAGE_FILE_MACHINE_UNKNOWN;
USHORT machineArchitecture = IMAGE_FILE_MACHINE_UNKNOWN;
// Just log the error if failed and return architecture Unknown.
LOG_IF_WIN32_BOOL_FALSE(IsWow64Process2(GetCurrentProcess(), &processArchitecture, &machineArchitecture));

switch (systemInfo.wProcessorArchitecture)
switch (machineArchitecture)
{
case PROCESSOR_ARCHITECTURE_AMD64:
case IMAGE_FILE_MACHINE_AMD64:
systemArchitecture = Architecture::X64;
break;
case PROCESSOR_ARCHITECTURE_ARM:
case IMAGE_FILE_MACHINE_ARM:
systemArchitecture = Architecture::Arm;
break;
case PROCESSOR_ARCHITECTURE_ARM64:
case IMAGE_FILE_MACHINE_ARM64:
systemArchitecture = Architecture::Arm64;
break;
case PROCESSOR_ARCHITECTURE_INTEL:
case IMAGE_FILE_MACHINE_I386:
systemArchitecture = Architecture::X86;
break;
}
Expand Down Expand Up @@ -276,4 +277,4 @@ namespace AppInstaller::Utility
return InapplicableArchitecture;
}
}
}
}

0 comments on commit 5cfc9da

Please sign in to comment.