From 3b64e7466006f183b8fac2f0187760a95a4f59cc Mon Sep 17 00:00:00 2001 From: Tommy Vercetti <7903172+tommyvct@users.noreply.github.com> Date: Fri, 17 Jun 2022 16:50:56 -0500 Subject: [PATCH 1/2] libobs/util: Add function to get Rosetta translation status --- docs/sphinx/reference-libobs-util-platform.rst | 9 +++++++++ libobs/util/platform-cocoa.m | 15 +++++++++++++++ libobs/util/platform-nix.c | 5 +++++ libobs/util/platform-windows.c | 5 +++++ libobs/util/platform.h | 2 ++ 5 files changed, 36 insertions(+) diff --git a/docs/sphinx/reference-libobs-util-platform.rst b/docs/sphinx/reference-libobs-util-platform.rst index 54103fd2f..ca87a5523 100644 --- a/docs/sphinx/reference-libobs-util-platform.rst +++ b/docs/sphinx/reference-libobs-util-platform.rst @@ -478,3 +478,12 @@ Other Functions .. function:: uint64_t os_get_proc_virtual_size(void) Returns the virtual memory size of the current process. + +--------------------- + +.. 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. diff --git a/libobs/util/platform-cocoa.m b/libobs/util/platform-cocoa.m index e0ec41cd0..1b1ef41f1 100644 --- a/libobs/util/platform-cocoa.m +++ b/libobs/util/platform-cocoa.m @@ -319,6 +319,21 @@ static int physical_cores = 0; static int logical_cores = 0; static bool core_count_initialized = false; +bool os_get_emulation_status(void) +{ +#ifdef __aarch64__ + return false; +#else + int rosettaTranslated = 0; + size_t size = sizeof(rosettaTranslated); + if (sysctlbyname("sysctl.proc_translated", &rosettaTranslated, &size, + NULL, 0) == -1) + return false; + + return rosettaTranslated == 1; +#endif +} + static void os_get_cores_internal(void) { if (core_count_initialized) diff --git a/libobs/util/platform-nix.c b/libobs/util/platform-nix.c index 764629994..75634d69d 100644 --- a/libobs/util/platform-nix.c +++ b/libobs/util/platform-nix.c @@ -401,6 +401,11 @@ char *os_get_executable_path_ptr(const char *name) return path.array; } +bool os_get_emulation_status(void) +{ + return false; +} + #endif bool os_file_exists(const char *path) diff --git a/libobs/util/platform-windows.c b/libobs/util/platform-windows.c index bc61c307c..c2078e5cb 100644 --- a/libobs/util/platform-windows.c +++ b/libobs/util/platform-windows.c @@ -992,6 +992,11 @@ bool is_64_bit_windows(void) #endif } +bool os_get_emulation_status(void) +{ + return false; +} + void get_reg_dword(HKEY hkey, LPCWSTR sub_key, LPCWSTR value_name, struct reg_dword *info) { diff --git a/libobs/util/platform.h b/libobs/util/platform.h index 9e5328de9..d4cb890c0 100644 --- a/libobs/util/platform.h +++ b/libobs/util/platform.h @@ -123,6 +123,8 @@ EXPORT char *os_get_abs_path_ptr(const char *path); EXPORT const char *os_get_path_extension(const char *path); +EXPORT bool os_get_emulation_status(void); + struct os_dir; typedef struct os_dir os_dir_t; From 0fa7834bfc90afbafae64bc36eb9139f1d2aaadf Mon Sep 17 00:00:00 2001 From: gxalpha Date: Sat, 18 Jun 2022 15:32:00 +0200 Subject: [PATCH 2/2] UI: Use libobs rosetta detection --- UI/obs-app.cpp | 2 +- UI/platform-osx.mm | 13 ------------- UI/platform.hpp | 1 - 3 files changed, 1 insertion(+), 15 deletions(-) diff --git a/UI/obs-app.cpp b/UI/obs-app.cpp index a3bc5dfb6..e84ae9e02 100644 --- a/UI/obs-app.cpp +++ b/UI/obs-app.cpp @@ -2173,7 +2173,7 @@ static int run_program(fstream &logFile, int argc, char *argv[]) } #ifdef __APPLE__ - bool rosettaTranslated = ProcessIsRosettaTranslated(); + bool rosettaTranslated = os_get_emulation_status(); blog(LOG_INFO, "Rosetta translation used: %s", rosettaTranslated ? "true" : "false"); #endif diff --git a/UI/platform-osx.mm b/UI/platform-osx.mm index bab4018b5..af66ab723 100644 --- a/UI/platform-osx.mm +++ b/UI/platform-osx.mm @@ -202,19 +202,6 @@ void EnableOSXDockIcon(bool enable) NSApplicationActivationPolicyProhibited]; } -bool ProcessIsRosettaTranslated() -{ -#ifdef __aarch64__ - return false; -#else - int ret = 0; - size_t size = sizeof(ret); - if (sysctlbyname("sysctl.proc_translated", &ret, &size, NULL, 0) == -1) - return false; - return ret == 1; -#endif -} - // Not implemented yet void TaskbarOverlayInit() {} void TaskbarOverlaySetStatus(TaskbarOverlayStatus) {} diff --git a/UI/platform.hpp b/UI/platform.hpp index 745273151..cef63d300 100644 --- a/UI/platform.hpp +++ b/UI/platform.hpp @@ -85,5 +85,4 @@ void EnableOSXDockIcon(bool enable); bool isInBundle(); void InstallNSApplicationSubclass(); void disableColorSpaceConversion(QWidget *window); -bool ProcessIsRosettaTranslated(); #endif