From 41efdc498c77efc1985ffa5df26232940d2baf24 Mon Sep 17 00:00:00 2001 From: Tommy Vercetti <7903172+tommyvct@users.noreply.github.com> Date: Wed, 13 Jul 2022 02:16:16 -0500 Subject: [PATCH] libobs/util: Add function to get Windows x64 emulation status --- docs/sphinx/reference-libobs-util-platform.rst | 9 +++++---- libobs/util/platform-windows.c | 17 +++++++++++++++++ libobs/util/windows/win-version.h | 1 + 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/docs/sphinx/reference-libobs-util-platform.rst b/docs/sphinx/reference-libobs-util-platform.rst index 7b1141dac..0cca76d7b 100644 --- a/docs/sphinx/reference-libobs-util-platform.rst +++ b/docs/sphinx/reference-libobs-util-platform.rst @@ -489,7 +489,8 @@ Other Functions .. function:: bool os_get_emulation_status(void) - Returns true if the current process is a x64 binary and is being emulated or translated - by the host operating system. On macOS, it returns true when a x64 binary is - being translated by Rosetta and running on Apple Silicon Macs. This function is not yet - implemented on Windows and Linux and will always return false on those platforms. + Returns true if the current process is an x64 binary and is being emulated or translated + by the host operating system. On macOS, it returns true when an x64 binary is + being translated by Rosetta and running on Apple Silicon Macs. On Windows, it + returns true when an x64 binary is being emulated on Windows ARM64 PCs. On all other + platforms, it will always returns false. diff --git a/libobs/util/platform-windows.c b/libobs/util/platform-windows.c index ac7897016..7a0dd7539 100644 --- a/libobs/util/platform-windows.c +++ b/libobs/util/platform-windows.c @@ -1088,9 +1088,26 @@ bool is_64_bit_windows(void) #endif } +bool is_arm64_windows(void) +{ +#if defined(_M_ARM64) || defined(_M_ARM64EC) + return true; +#else + USHORT processMachine; + USHORT nativeMachine; + bool result = IsWow64Process2(GetCurrentProcess(), &processMachine, + &nativeMachine); + return (result && (nativeMachine == IMAGE_FILE_MACHINE_ARM64)); +#endif +} + bool os_get_emulation_status(void) { +#if defined(_M_ARM64) || defined(_M_ARM64EC) return false; +#else + return is_arm64_windows(); +#endif } void get_reg_dword(HKEY hkey, LPCWSTR sub_key, LPCWSTR value_name, diff --git a/libobs/util/windows/win-version.h b/libobs/util/windows/win-version.h index 5e010d7d1..3f99e8b18 100644 --- a/libobs/util/windows/win-version.h +++ b/libobs/util/windows/win-version.h @@ -48,6 +48,7 @@ static inline int win_version_compare(const struct win_version_info *dst, } EXPORT bool is_64_bit_windows(void); +EXPORT bool is_arm64_windows(void); EXPORT bool get_dll_ver(const wchar_t *lib, struct win_version_info *info); EXPORT void get_win_ver(struct win_version_info *info); EXPORT uint32_t get_win_ver_int(void);