From f6f45dda0a9711b53e0603ffbb6a5f764a4981dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 2 May 2024 20:41:56 +0200 Subject: [PATCH] Disable the JIT hackery in app store builds --- CMakeLists.txt | 2 +- Core/Config.cpp | 8 ++++++++ UI/GameSettingsScreen.cpp | 3 ++- b-appstore.sh | 4 +++- ios/main.mm | 33 ++++++++++++++++++++------------- 5 files changed, 34 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 07950f8598..ee3a6e2b78 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2850,7 +2850,7 @@ if(IOS AND NOT LIBRETRO) XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY "iPhone/iPad" XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC YES XCODE_ATTRIBUTE_ENABLE_BITCODE NO - XCODE_ATTRIBUTE_DEVELOPMENT_TEAM "97NS59EENG" + XCODE_ATTRIBUTE_DEVELOPMENT_TEAM ${DEVELOPMENT_TEAM_ID} XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "Apple Development" XCODE_ATTRIBUTE_CODE_SIGN_STYLE "Automatic" ) diff --git a/Core/Config.cpp b/Core/Config.cpp index 6bdbf8e06c..6f259b6eb5 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -1168,6 +1168,14 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename) { if (iMaxRecent == 0) iMaxRecent = 60; + // Fix JIT setting if no longer available. + if (!System_GetPropertyBool(SYSPROP_CAN_JIT)) { + if (iCpuCore == (int)CPUCore::JIT || iCpuCore == (int)CPUCore::JIT_IR) { + WARN_LOG(LOADER, "Forcing JIT off due to unavailablility"); + iCpuCore = (int)CPUCore::IR_INTERPRETER; + } + } + if (iMaxRecent > 0) { private_->ResetRecentIsosThread(); std::lock_guard guard(private_->recentIsosLock); diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index 5dc9404dd7..d048e64cdf 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -1770,6 +1770,7 @@ void DeveloperToolsScreen::CreateViews() { bool canUseJit = System_GetPropertyBool(SYSPROP_CAN_JIT); // iOS can now use JIT on all modes, apparently. // The bool may come in handy for future non-jit platforms though (UWP XB1?) + // In iOS App Store builds, we disable the JIT. static const char *cpuCores[] = {"Interpreter", "Dynarec/JIT (recommended)", "IR Interpreter", "JIT using IR"}; PopupMultiChoice *core = list->Add(new PopupMultiChoice(&g_Config.iCpuCore, sy->T("CPU Core"), cpuCores, 0, ARRAY_SIZE(cpuCores), I18NCat::SYSTEM, screenManager())); @@ -1782,7 +1783,7 @@ void DeveloperToolsScreen::CreateViews() { core->HideChoice(1); core->HideChoice(3); } - // TODO: Enable on more architectures. + // TODO: Enable "JIT using IR" on more architectures. #if !PPSSPP_ARCH(X86) && !PPSSPP_ARCH(AMD64) && !PPSSPP_ARCH(ARM64) core->HideChoice(3); #endif diff --git a/b-appstore.sh b/b-appstore.sh index 4a525cf152..6da7cc9869 100755 --- a/b-appstore.sh +++ b/b-appstore.sh @@ -1,9 +1,11 @@ # Build script for iOS app store +# Set the development team ID as a DEVTEAM env variable. + mkdir build-ios pushd build-ios -cmake .. -DIOS_APP_STORE=ON -DCMAKE_TOOLCHAIN_FILE=cmake/Toolchains/ios.cmake -DDEVELOPMENT_TEAM_ID=97NS59EENG -DIOS_PLATFORM=OS -GXcode +cmake .. -DIOS_APP_STORE=ON -DCMAKE_TOOLCHAIN_FILE=cmake/Toolchains/ios.cmake -DDEVELOPMENT_TEAM_ID=$(DEVTEAM) -DIOS_PLATFORM=OS -GXcode # TODO: Get a MoltenVK somewhere. #cp ../MoltenVK/iOS/Frameworks/libMoltenVK.dylib PPSSPP.app/Frameworks popd diff --git a/ios/main.mm b/ios/main.mm index 0389d3452e..4c1151185a 100644 --- a/ios/main.mm +++ b/ios/main.mm @@ -29,6 +29,9 @@ #include "Common/Log.h" #include "UI/DarwinFileSystemServices.h" +// Compile out all the hackery in app store builds. +#if !PPSSPP_PLATFORM(IOS_APP_STORE) + struct cs_blob_index { uint32_t type; uint32_t offset; @@ -269,6 +272,7 @@ bool jb_enable_ptrace_hack(void) { return true; } +#endif float g_safeInsetLeft = 0.0; float g_safeInsetRight = 0.0; @@ -473,23 +477,21 @@ void System_Vibrate(int mode) { int main(int argc, char *argv[]) { - // Hacky hacks to try to enable JIT by pretending to be a debugger. - csops = reinterpret_cast(dlsym(dlopen(nullptr, RTLD_LAZY), "csops")); - exc_server = reinterpret_cast(dlsym(dlopen(NULL, RTLD_LAZY), "exc_server")); - ptrace = reinterpret_cast(dlsym(dlopen(NULL, RTLD_LAZY), "ptrace")); - // see https://github.com/hrydgard/ppsspp/issues/11905 - - // Tried checking for JIT support here with AllocateExecutableMemory and ProtectMemoryPages, - // but it just succeeds, and then fails when you try to execute from it. - - // So, we'll just resort to a version check. - version = [[[UIDevice currentDevice] systemVersion] UTF8String]; if (2 != sscanf(version.c_str(), "%d", &g_iosVersionMajor)) { // Just set it to 14.0 if the parsing fails for whatever reason. g_iosVersionMajor = 14; } +#if PPSSPP_PLATFORM(IOS_APP_STORE) + g_jitAvailable = false; +#else + // Hacky hacks to try to enable JIT by pretending to be a debugger. + csops = reinterpret_cast(dlsym(dlopen(nullptr, RTLD_LAZY), "csops")); + exc_server = reinterpret_cast(dlsym(dlopen(NULL, RTLD_LAZY), "exc_server")); + ptrace = reinterpret_cast(dlsym(dlopen(NULL, RTLD_LAZY), "ptrace")); + // see https://github.com/hrydgard/ppsspp/issues/11905 + if (jb_spawn_ptrace_child(argc, argv)) { INFO_LOG(SYSTEM, "JIT: ptrace() child spawn trick\n"); } else if (jb_has_jit_entitlement()) { @@ -505,6 +507,11 @@ int main(int argc, char *argv[]) g_jitAvailable = false; } + // Tried checking for JIT support here with AllocateExecutableMemory and ProtectMemoryPages, + // but it just succeeds, and then fails when you try to execute from it. + + // So, we'll just resort to a version check. + // TODO: This seems outdated. /* if (g_iosVersionMajor > 14 || (g_iosVersionMajor == 14 && g_iosVersionMinor >= 4)) { g_jitAvailable = false; @@ -512,13 +519,13 @@ int main(int argc, char *argv[]) g_jitAvailable = true; } */ - - PROFILE_INIT(); +#endif // Ignore sigpipe. if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) { perror("Unable to ignore SIGPIPE"); } + PROFILE_INIT(); @autoreleasepool { return UIApplicationMain(argc, argv, NSStringFromClass([PPSSPPUIApplication class]), NSStringFromClass([AppDelegate class]));