Repository navigation
feat(libSceSystemService): LoadExec on macOS hosts - #6248
Conversation
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
|
A heads-up on ordering with #6237. It changes LoadExec's shutdown on Linux and Windows from The macOS AI-assisted: yes |
sceSystemServiceLoadExec found its own executable through /proc/self/exe and replaced the process with fexecve after close_range, none of which macOS has, so on macOS every call except "exit" threw. On macOS: - the running executable's path comes from _NSGetExecutablePath, resolved with std::filesystem::canonical, as libSceNpEntitlementAccess and libSceFont already do; - the target must be an x86-64 Mach-O executable (MH_MAGIC_64, CPU_TYPE_X86_64, MH_EXECUTE) that the user may run; - macOS has no fexecve, so the process is replaced by path with posix_spawn and POSIX_SPAWN_SETEXEC; POSIX_SPAWN_CLOEXEC_DEFAULT closes every descriptor but the standard streams, as close_range does on Linux; - before the replacement the exit starts and the shutdown callbacks run (LibcStartExit, then LibcRunShutdown), as on Linux, so guest threads that call a stopped library wait instead of unwinding; - descriptor 2 gets the host standard error back before the replacement, as on Linux, and guest_system_load_exec_standard_error runs on macOS. A launch without arguments keeps the Linux execv path, which macOS has. guest_system_exit finds its own executable the same way on macOS.
cc846af to
f347461
Compare
What
sceSystemServiceLoadExecon macOS hosts. It found the running executable through/proc/self/exeand replaced the process withfexecveafterclose_range, none of which macOS has, so on macOS every call other than"exit"threw. Part of the macOS series announced on #1 (#1 (comment))._NSGetExecutablePath, resolved withstd::filesystem::canonical, aslibSceNpEntitlementAccessandlibSceFontalready do on macOS. The rest ofPrepareLaunchis the Linux code.MH_MAGIC_64,CPU_TYPE_X86_64,MH_EXECUTE) that the user may run, as Linux requires an x86-64 ELF.fexecve, so the process is replaced by path withposix_spawnandPOSIX_SPAWN_SETEXEC.POSIX_SPAWN_CLOEXEC_DEFAULTcloses every descriptor except the standard streams, which is whatclose_rangedoes on Linux. The PID stays and the working directory becomes the executable's, as on Linux.LibcStartExit_nid_postfix, thenLibcRunShutdown_nid_postfix), as the Linux and WindowsReplacedo since fix(libSceSystemService): park guest threads during LoadExec's shutdown as exit does #6237.execvpath, which macOS has and which already does this.guest_system_exitfinds its own executable the same way on macOS, andguest_system_load_exec_standard_errorfrom fix(libSceSystemService): give LoadExec's next executable the host standard error #5699 now runs on macOS too. Indocs/dev/debt/libSceSystemService.mdthesceSystemServiceLoadExecentry describes macOS instead of listing it as a host that throws, and the LoadExec descriptors entry says how macOS closes the descriptors.Tested
main385ed71 with the other macOS branches of the series and the open macOS fixes fix(libkernel): create the JIT shared memory backing on macOS hosts #6928, fix(libkernel_sys): build and check fchdir search permission on macOS #6667, fix(libSceLibcInternal): read statvfs by path on macOS #6668, fix(tests): keep generic category vtable entries castable to functions #6969, fix(libc): keep errno when strtol converts nothing on macOS #6853, fix(libkernel): set the open file limit at load on macOS #6836, perf(libc): add steady_clock fast path in PreciseSleepUntil #6620 and fix(tests): compare the Bessel exports with fixed reference values #7524 (the libraries do not link on macOS without the series):guest_system_exit_parameters,guest_system_relaunchandguest_nested_exit, which failed before, pass, and so doesguest_system_load_exec_standard_error; the four passed 10 runs in a row;guest_system_exit,guest_requested_exit,guest_quick_exit,guest_immediate_exit,guest_return_from_main,guest_exit_finalizers_before_shutdown,guest_system_serviceandguest_system_service_languagepass.guest_system_relaunchreplaces the process twice, into a copy namedpicker.picker.binand back to the main executable throughAPS5_EBOOT, and checks the arguments and shutdown handlers of each step.__APPLE__exceptOwnExecutable, which moves the Linux/proc/self/exelookup into a function without changing it.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)