feat(libc): implement at_quick_exit and quick_exit #405

Merged
Pouare514 merged 4 commits from upstream-pr/405 into main 2026-10-04 23:44:52 +00:00
Pouare514 commented 2026-10-02 20:10:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Pouare514 on 2026-10-02T20:10:05Z.


What

Our libc had no quick_exit/at_quick_exit. Cyberpunk 2077 (PPSA04029) imports quick_exit (NID qdGFBoLVNKI, hash-verified) and calls it during startup; without it the game cannot terminate cleanly.

Change: at_quick_exit registers handlers (LIFO); quick_exit runs them then terminates via _Exit, mirroring the existing atexit machinery with a separate handler list as the standard requires. Covered by a new guest_quick_exit test (handler order enforced via exit codes plus output match).

Tested

  • Full Release Ninja build OK; ctest -E agc_driver_graphics|guest_rendering_wait --timeout 120: 106/106 pass (incl. new guest_quick_exit).
  • Manual: Cyberpunk 2077 startup quick_exit(0) path terminates cleanly instead of failing resolution.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4720961093 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/405). Originally posted by [Pouare514](https://github.com/Pouare514) on 2026-10-02T20:10:05Z. --- ### What Our libc had no quick_exit/at_quick_exit. Cyberpunk 2077 (PPSA04029) imports quick_exit (NID qdGFBoLVNKI, hash-verified) and calls it during startup; without it the game cannot terminate cleanly. Change: at_quick_exit registers handlers (LIFO); quick_exit runs them then terminates via _Exit, mirroring the existing atexit machinery with a separate handler list as the standard requires. Covered by a new guest_quick_exit test (handler order enforced via exit codes plus output match). ### Tested - Full Release Ninja build OK; ctest -E agc_driver_graphics|guest_rendering_wait --timeout 120: 106/106 pass (incl. new guest_quick_exit). - Manual: Cyberpunk 2077 startup quick_exit(0) path terminates cleanly instead of failing resolution. ### Checklist - [x] Based on current main; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt - [x] No notes, investigation .md files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [ ] Depends on: none - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-02 20:11:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-02T20:11:26Z.


Progress report (33a870d → 9e70325)

📈 System libraries: 78.88% (+0.04%, +2 implemented, -1 removed functions)

✅ 2 implemented
Library Name
libc at_quick_exit_nid_postfix
libc quick_exit_nid_postfix
🗑️ 1 removed
Library Name
libc libcCyberUnknown15
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5960674342 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/405#issuecomment-5960674342). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-02T20:11:26Z. --- <!-- progress-report --> ### Progress report (33a870d → 9e70325) 📈 **System libraries**: 78.88% (+0.04%, +2 implemented, -1 removed functions) <details> <summary>✅ 2 implemented</summary> | Library | Name | | - | - | | libc | `at_quick_exit_nid_postfix` | | libc | `quick_exit_nid_postfix` | </details> <details> <summary>🗑️ 1 removed</summary> | Library | Name | | - | - | | libc | `libcCyberUnknown15` | </details>
oneandonlydean commented 2026-10-04 05:44:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T05:44:21Z.


Thanks, the handler order and the separate list match C11 and FreeBSD's quick_exit.c. The Linux job fails on the new guest_quick_exit test: quick_exit ends in _Exit, which doesn't flush stdio, and under ctest stdout is a pipe, so the puts from the handler never reaches the output. The implementation is correct to not flush; adding std::fflush(stdout); after the puts in QuickFirst should make the test pass on both platforms.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5977030916 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/405#issuecomment-5977030916). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-04T05:44:21Z. --- Thanks, the handler order and the separate list match C11 and FreeBSD's `quick_exit.c`. The Linux job fails on the new `guest_quick_exit` test: `quick_exit` ends in `_Exit`, which doesn't flush stdio, and under ctest stdout is a pipe, so the `puts` from the handler never reaches the output. The implementation is correct to not flush; adding `std::fflush(stdout);` after the `puts` in `QuickFirst` should make the test pass on both platforms.
Pouare514 commented 2026-10-04 13:26:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Pouare514 on 2026-10-04T13:26:02Z.


Done: added std::fflush(stdout) after the puts in QuickFirst. guest_quick_exit passes now (also guest_system_exit + parameters, 3/3 green locally).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5980449523 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/405#issuecomment-5980449523). Originally posted by [Pouare514](https://github.com/Pouare514) on 2026-10-04T13:26:02Z. --- Done: added std::fflush(stdout) after the puts in QuickFirst. guest_quick_exit passes now (also guest_system_exit + parameters, 3/3 green locally).
oneandonlydean commented 2026-10-04 21:07:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T21:07:50Z.


Thanks, guest_quick_exit passes on Linux now. The Windows job fails earlier, in the build: nid_patcher stops with duplicate patched export name: qdGFBoLVNKI for libc. qdGFBoLVNKI is the NID of quick_exit, and main already exports it as the stub libcCyberUnknown15 in libc/Export.cpp (from #358). Removing that stub should fix it. at_quick_exit (HC8vbJStYVY) isn't on main, so it doesn't clash.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5984394726 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/405#issuecomment-5984394726). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-04T21:07:50Z. --- Thanks, `guest_quick_exit` passes on Linux now. The Windows job fails earlier, in the build: `nid_patcher` stops with `duplicate patched export name: qdGFBoLVNKI` for libc. qdGFBoLVNKI is the NID of `quick_exit`, and main already exports it as the stub `libcCyberUnknown15` in `libc/Export.cpp` (from #358). Removing that stub should fix it. `at_quick_exit` (HC8vbJStYVY) isn't on main, so it doesn't clash.
Pouare514 commented 2026-10-04 22:54:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Pouare514 on 2026-10-04T22:54:18Z.


Done: removed the libcCyberUnknown15 stub for qdGFBoLVNKI, so quick_exit_nid_postfix is the only export of that NID. Windows build is green locally (libs target) and guest_quick_exit passes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5985339373 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/405#issuecomment-5985339373). Originally posted by [Pouare514](https://github.com/Pouare514) on 2026-10-04T22:54:18Z. --- Done: removed the libcCyberUnknown15 stub for qdGFBoLVNKI, so quick_exit_nid_postfix is the only export of that NID. Windows build is green locally (libs target) and guest_quick_exit passes.
github-actions[bot] commented 2026-10-04 23:10:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-04T23:10:09Z.


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
#492 core/libs/prx/libc/Export.cpp L115-173
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5985456447 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/405#issuecomment-5985456447). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-04T23:10:09Z. --- <!-- 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 | |---|---|---|---| | #492 | `core/libs/prx/libc/Export.cpp` [L115-173](https://github.com/boykopovar/AnyPS5/blob/d22014954265c33cefc8ab0fe5864cc15d71fcd0/core/libs/prx/libc/Export.cpp#L115-L173) | | |
oneandonlydean commented 2026-10-04 23:43:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T23:43:42Z.


Thanks, with libcCyberUnknown15 gone quick_exit is the only export of qdGFBoLVNKI, and both CI jobs are green now, including guest_quick_exit on Windows. It also passes here on this head merged with current main. Ready to merge from my side.

For whoever lands second: #492 also edits libc/Export.cpp near this stub (the overlap bot lists it), so that one may need a small rebase.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5985700397 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/405#issuecomment-5985700397). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-04T23:43:42Z. --- Thanks, with `libcCyberUnknown15` gone `quick_exit` is the only export of qdGFBoLVNKI, and both CI jobs are green now, including `guest_quick_exit` on Windows. It also passes here on this head merged with current main. Ready to merge from my side. For whoever lands second: #492 also edits `libc/Export.cpp` near this stub (the overlap bot lists it), so that one may need a small rebase.
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!405
No description provided.