fix(libc): preserve path services through process exit #4994

Merged
krishalivaibhav merged 1 commit from upstream-pr/4994 into main 2026-10-14 17:52:40 +00:00
krishalivaibhav commented 2026-10-13 07:34:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by krishalivaibhav on 2026-10-13T07:34:15Z.


What

Keep the working-directory and path-alias services alive through host process exit. Detached guest file workers and exit callbacks can still call ResolvePath after C++ function-static destructors have run. Their mutexes and path/alias storage currently disappear during that interval.

A local Don’t Starve Together (PPSA02070) crash on macOS shows a guest thread in mutex::lock → ResolvePath → sceKernelOpen concurrently with the exit thread in __cxa_finalize_ranges → exit → LibcExit. This patch preserves both process-owned services; it does not change normal path mapping, join all guest threads, fix other teardown services, or claim stable game playback.

The new Unix subprocess regression registers its native exit probe before first use of these services, then resolves root/relative/alias paths, updates an alias and reads getcwd from a joined worker during exit. OS process teardown reclaims the intentionally retained objects.

Tested

  • Mac M2, macOS 27.2, Release x86-64 under Rosetta, modified local integration: the regression with the original two function statics fails with mutex lock failed: Invalid argument. A working-directory-only fix also fails; keeping both services alive passes.
  • Final guest_path_lifetime, guest_working_directory and guest_exit_order each passed three consecutive runs (nine successful executions).
  • Existing guest_path_case case-distinct-file assertion fails identically with original and candidate source on this case-insensitive Mac filesystem; no test was weakened.
  • The new test compiles against this clean branch’s headers. Local conventions and whitespace checks pass. Parent and independent agent reviewed the isolated patch.
  • This branch is based on main 30caf2b2a5641764312a5586eebe888e4074a209. The local runtime tests above include other unpublished macOS integration patches; they do not establish a clean-main full build. The new focused clean-Linux evidence is recorded below; full Linux/Windows suites remain unverified. The Unix exit regression is not registered on Windows; Linux may expose the destroyed storage differently from Darwin’s mutex error.
  • No FPS improvement, stable title session or full macOS game support is claimed. Our broader three-game status is reported separately.

#4927 also edits General.cpp but only the allocated-buffer getcwd behavior; this patch changes the two service accessors and does not depend on it.

Additional verified Linux evidence

Clean Linux execution on the exact head 99ae2e812b20d9f3d6f84685948d07de3ee45dbe: built the actual runtime and guest_path_lifetime, guest_working_directory, and guest_exit_order targets; all three passed three consecutive runs. A production-only negative control restored parent General.cpp while keeping the new fixture and CMake registration; guest_path_lifetime failed. Restoring the candidate and rebuilding passed all three tests three times again. Hosted logs. This is a focused clean-head Linux result, not a full project suite or Windows exit-lifetime coverage.

Checklist

  • Based on current main; no other open PR found implementing these accessor lifetime changes
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw; no silent stubs added
  • No notes, investigation Markdown files or images added to the repository
  • No new third-party code
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none (shutdown crash evidence; no stable title claim)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4839936465 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4994). Originally posted by [krishalivaibhav](https://github.com/krishalivaibhav) on 2026-10-13T07:34:15Z. --- ### What Keep the working-directory and path-alias services alive through host process exit. Detached guest file workers and exit callbacks can still call `ResolvePath` after C++ function-static destructors have run. Their mutexes and path/alias storage currently disappear during that interval. A local Don’t Starve Together (PPSA02070) crash on macOS shows a guest thread in `mutex::lock → ResolvePath → sceKernelOpen` concurrently with the exit thread in `__cxa_finalize_ranges → exit → LibcExit`. This patch preserves both process-owned services; it does not change normal path mapping, join all guest threads, fix other teardown services, or claim stable game playback. The new Unix subprocess regression registers its native exit probe before first use of these services, then resolves root/relative/alias paths, updates an alias and reads `getcwd` from a joined worker during exit. OS process teardown reclaims the intentionally retained objects. ### Tested - Mac M2, macOS 27.2, Release x86-64 under Rosetta, **modified local integration**: the regression with the original two function statics fails with `mutex lock failed: Invalid argument`. A working-directory-only fix also fails; keeping both services alive passes. - Final `guest_path_lifetime`, `guest_working_directory` and `guest_exit_order` each passed three consecutive runs (nine successful executions). - Existing `guest_path_case` case-distinct-file assertion fails identically with original and candidate source on this case-insensitive Mac filesystem; no test was weakened. - The new test compiles against this clean branch’s headers. Local conventions and whitespace checks pass. Parent and independent agent reviewed the isolated patch. - This branch is based on main `30caf2b2a5641764312a5586eebe888e4074a209`. The local runtime tests above include other unpublished macOS integration patches; they do **not** establish a clean-main full build. The new focused clean-Linux evidence is recorded below; full Linux/Windows suites remain unverified. The Unix exit regression is not registered on Windows; Linux may expose the destroyed storage differently from Darwin’s mutex error. - No FPS improvement, stable title session or full macOS game support is claimed. Our broader three-game status is [reported separately](https://github.com/boykopovar/AnyPS5/issues/1#issuecomment-6140534450). #4927 also edits `General.cpp` but only the allocated-buffer `getcwd` behavior; this patch changes the two service accessors and does not depend on it. ### Additional verified Linux evidence Clean Linux execution on the exact head `99ae2e812b20d9f3d6f84685948d07de3ee45dbe`: built the actual runtime and `guest_path_lifetime`, `guest_working_directory`, and `guest_exit_order` targets; all three passed three consecutive runs. A production-only negative control restored parent `General.cpp` while keeping the new fixture and CMake registration; `guest_path_lifetime` failed. Restoring the candidate and rebuilding passed all three tests three times again. [Hosted logs](https://github.com/krishalivaibhav/AnyPS5/actions/runs/38458117014/job/115505978315). This is a focused clean-head Linux result, not a full project suite or Windows exit-lifetime coverage. ### Checklist - [x] Based on current `main`; no other open PR found implementing these accessor lifetime changes - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw; no silent stubs added - [x] No notes, investigation Markdown files or images added to the repository - [x] No new third-party code - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none (shutdown crash evidence; no stable title claim) - [x] AI-assisted: yes
krishalivaibhav commented 2026-10-13 07:34:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by krishalivaibhav on 2026-10-13T07:34:56Z.


Maintainer CI request: could someone dispatch build.yml from main with pr=4994 to run the Linux and Windows builds/tests? The API rejects my dispatch with HTTP 403 (repository admin rights required).

The Unix regression reproduces the original mutex error in our modified local Mac runtime and passes with both path services retained; the PR description states that limitation explicitly. The draft is awaiting clean-main CI, not claiming a full Mac build or stable title playback.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6140663184 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4994#issuecomment-6140663184). Originally posted by [krishalivaibhav](https://github.com/krishalivaibhav) on 2026-10-13T07:34:56Z. --- Maintainer CI request: could someone dispatch `build.yml` from `main` with `pr=4994` to run the Linux and Windows builds/tests? The API rejects my dispatch with HTTP 403 (repository admin rights required). The Unix regression reproduces the original mutex error in our modified local Mac runtime and passes with both path services retained; the PR description states that limitation explicitly. The draft is awaiting clean-main CI, not claiming a full Mac build or stable title playback. AI-assisted: yes.
krishalivaibhav commented 2026-10-13 07:36:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by krishalivaibhav on 2026-10-13T07:36:51Z.


Additional bounded title check, with the updated local runtime: a normal exit request at 30 seconds was followed by a different crash at 36 seconds. Its faulting guest thread is in DirectMemoryAlloc while the exit thread is again in __cxa_finalize_ranges → exit → LibcExit. The path regression passes, but this is not a complete game-shutdown fix. Other runtime services can still be accessed by live guest threads during host teardown; lifecycle coordination remains separate work.

Discriminating local regression evidence (same repaired fixture throughout):

  • Original working-directory + aliases: fails with mutex lock failed: Invalid argument.
  • Retaining working directory alone: fails with the same error when reaching aliases.
  • Retaining both: guest_path_lifetime, guest_working_directory, guest_exit_order each pass three runs.

This supports the narrow lifetime change in this PR. It does not establish stable Don’t Starve Together playback, a frame-rate gain, or clean-main platform test success. The shared validation-cache optimization is separate local work and is not included here.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6140692290 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4994#issuecomment-6140692290). Originally posted by [krishalivaibhav](https://github.com/krishalivaibhav) on 2026-10-13T07:36:51Z. --- Additional bounded title check, with the updated local runtime: a normal exit request at 30 seconds was followed by a **different** crash at 36 seconds. Its faulting guest thread is in `DirectMemoryAlloc` while the exit thread is again in `__cxa_finalize_ranges → exit → LibcExit`. The path regression passes, but this is not a complete game-shutdown fix. Other runtime services can still be accessed by live guest threads during host teardown; lifecycle coordination remains separate work. Discriminating local regression evidence (same repaired fixture throughout): - Original working-directory + aliases: fails with `mutex lock failed: Invalid argument`. - Retaining working directory alone: fails with the same error when reaching aliases. - Retaining both: `guest_path_lifetime`, `guest_working_directory`, `guest_exit_order` each pass three runs. This supports the narrow lifetime change in this PR. It does not establish stable Don’t Starve Together playback, a frame-rate gain, or clean-main platform test success. The shared validation-cache optimization is separate local work and is not included here. AI-assisted: yes.
github-actions[bot] commented 2026-10-13 11:25:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T11:25:14Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#5280 core/libs/prx/libc/src/General.cpp L123
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6144472954 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4994#issuecomment-6144472954). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T11:25:14Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #5280 | `core/libs/prx/libc/src/General.cpp` [L123](https://github.com/boykopovar/AnyPS5/blob/e442f4c2e17681a327c581d13448a462dbe862e6/core/libs/prx/libc/src/General.cpp#L123) | | |
adriadam10 commented 2026-10-14 17:27:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T17:27:32Z.


Checked on Linux (this PR merged onto current main): guest_path_lifetime passes and fails with General.cpp reverted; the libs/libc test scope (104 tests) is green, including all application_heap* tests. The application_heap_replacement abort reported above does not reproduce with this PR alone (it concerns getcwd(NULL, size), i.e. #4927). Windows exit-lifetime is not covered by the test; merging once the full build is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6174275533 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4994#issuecomment-6174275533). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-14T17:27:32Z. --- Checked on Linux (this PR merged onto current main): `guest_path_lifetime` passes and fails with `General.cpp` reverted; the libs/libc test scope (104 tests) is green, including all `application_heap*` tests. The `application_heap_replacement` abort reported above does not reproduce with this PR alone (it concerns `getcwd(NULL, size)`, i.e. #4927). Windows exit-lifetime is not covered by the test; merging once the full build is green.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!4994
No description provided.