winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 5cfc9daa5c33bcc8469d1b0ae1c05e9cb59cc8eb
parent d8819d08d77b4e8490ad6e441191038d5e14619c
Author: yao-msft <50888816+yao-msft@users.noreply.github.com>
Date:   Fri, 10 Jan 2025 13:15:27 -0800

Use IsWow64Process2 to determine system architecture (#5125)

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.
Diffstat:
Msrc/AppInstallerCommonCore/Architecture.cpp | 20++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/AppInstallerCommonCore/Architecture.cpp b/src/AppInstallerCommonCore/Architecture.cpp @@ -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; } @@ -276,4 +277,4 @@ namespace AppInstaller::Utility return InapplicableArchitecture; } } -}- \ No newline at end of file +}