Browse Source

libobs/util: Add function to get Windows x64 emulation status

Tommy Vercetti 3 years ago
parent
commit
41efdc498c

+ 5 - 4
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.

+ 17 - 0
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,

+ 1 - 0
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);