fix(runtime): run converted SDK samples through clean C++ shutdown #98

Merged
SamG-Coder merged 7 commits from upstream-pr/98 into main 2026-10-01 09:08:10 +00:00
SamG-Coder commented 2026-09-28 19:17:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by SamG-Coder on 2026-09-28T19:17:29Z.


What

Public SDK samples could not receive command-line arguments, load their declared guest shared libraries or initialize their C++ runtime. After those blockers were addressed, the C++ sample still crashed during shutdown because registered guest destructors were invoked with the Windows calling convention.

This change supplies the missing converter/runtime behavior and preserves the SysV calling convention when invoking guest exit callbacks. The community SDK hello_cxx source now prints its greeting, sorts a vector on a worker thread, catches exception 42, joins and exits with status 0. The sample source is unchanged; its build uses the native-title CRT adaptation described below.

The PR contains focused commits for:

  • Windows command-line decoding and UTF-8 arguments passed to guest startup.
  • Exact guest SONAME matching, dependency ordering, entryless shared modules, and validated constructor/destructor arrays.
  • C/POSIX single-byte conversion, wide integer/extended-precision conversion, collation, bzero and condition-variable destruction.
  • Wide-stream input/pushback for the supported C locale, with conversion errors preserved until clearerr or reopen.
  • Guest-heap allocated formatting and SysV argument translation for scanning/wide formatting, including 64-bit guest long values.
  • Correct calling conventions for __cxa_atexit destructors and atexit callbacks. The host callback wrapper preserves Windows registers across SysV guest calls.

The inconclusive vblank timing change has been removed from this PR. No graphics-performance improvement is claimed. Shader PR #96 and notification PR #97 remain separate.

Tested

Rebased onto upstream 49a7819. The following checks were rerun on head 9e3b3c8, Windows Release, with the explicit NID-patched libs build:

Check Result
Release build and patched runtime libraries Pass
Existing repository CTests 54/54 pass
External C++ regression programs 4/4 pass: application heap, character conversion, condition-variable destruction, strings
External converter regression scripts 3/3 pass: arguments, guest dependencies, lifecycle arrays
Converted PS5-target probes 7/7 positive runs pass
Deliberate wrong-result controls Seven expected failing exit codes plus one rejected shutdown output
Original C++ sample with native-title CRT adaptation 5/5 consecutive runs complete, exit 0, expected output, no fatal diagnostic
Whitespace/error check Pass

The converted probes exercise:

  • 64-bit numeric limits, end pointers, overflow and extended precision beyond double.
  • Replacement allocator callbacks, allocation failure, empty output and embedded NUL characters.
  • All 256 single-byte values, SDK state-size assertions, state/output guards, partial buffers and source-pointer updates.
  • Wide stream EOF, pushback, invalid values, error persistence, clearerr and reopen.
  • Register/stack-passed formatting/scanning arguments, scansets, suppression, %ln, width/precision, wide Unicode output and truncation guards.
  • C++ destructor arguments and LIFO order. The guest deliberately clobbers registers that Windows callers must preserve, exercising the callback bridge. Its wrong-result control produces EXIT_ABI_BAD, which the output oracle rejects despite exit 0.

All five final C++ sample runs printed:

Hello, libcxx!
... sorted vec: 1 2 3 4 5
Caught exception: 42

and exited normally with status 0. Before the destructor ABI fix the same sample reached that output, then faulted and exited 0xc0000409. No exception or shutdown bypass was added.

Review notes and limits

  • Public community SDK headers/static libraries are used. This is not Sony SDK validation, physical-console validation, or unchanged exploited-console payload execution. The original C++ sample source uses an external native-title startup/link adaptation.
  • Windows runtime validation only. Linux lifecycle-array metadata has structural conversion coverage; Linux execution was not tested.
  • Character conversion supports the runtime's existing C/POSIX single-byte locale. Additional locales and a complete wide-stream orientation interface are not implemented.
  • Positional dollar formats and nonstandard format extensions are unsupported and use NotImplemented_nid_no_patch. Invalid/incomplete formats return errors. This is not complete libc conformance.
  • PR #81 implements related vswprintf/wprintf functionality using another helper. It does not replace these swprintf/scanning/exit-ABI fixes, but the helpers should be reconciled if both land. The file overlap found with that PR is libc's CMake source list. Relevant relinker/library PRs #85, #12, #30, #28 and #86 have no changed-file overlap with this diff.
  • No new tests, demos, investigation documents, images or binaries are added to Git. Test programs and reports remain in the external validation workspace. Reviewer-facing results are recorded above.

Checklist

  • Based on current upstream main; overlapping PR #81 explicitly identified for review
  • Scoped to converted SDK sample startup, runtime and shutdown compatibility; timing experiment removed
  • No explanatory comments added to code
  • Unsupported format extensions throw via NotImplemented_nid_no_patch; no new silent success stubs
  • No notes, investigation documents, images or new tests added to the repository
  • No new third-party runtime sources or binaries
  • Generic behavior, not title-specific code
  • Depends on: none of #96 or #97
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4668194309 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/98). Originally posted by [SamG-Coder](https://github.com/SamG-Coder) on 2026-09-28T19:17:29Z. --- ### What Public SDK samples could not receive command-line arguments, load their declared guest shared libraries or initialize their C++ runtime. After those blockers were addressed, the C++ sample still crashed during shutdown because registered guest destructors were invoked with the Windows calling convention. This change supplies the missing converter/runtime behavior and preserves the SysV calling convention when invoking guest exit callbacks. The community SDK `hello_cxx` source now prints its greeting, sorts a vector on a worker thread, catches exception `42`, joins and exits with status 0. The sample source is unchanged; its build uses the native-title CRT adaptation described below. The PR contains focused commits for: - Windows command-line decoding and UTF-8 arguments passed to guest startup. - Exact guest SONAME matching, dependency ordering, entryless shared modules, and validated constructor/destructor arrays. - C/POSIX single-byte conversion, wide integer/extended-precision conversion, collation, bzero and condition-variable destruction. - Wide-stream input/pushback for the supported C locale, with conversion errors preserved until clearerr or reopen. - Guest-heap allocated formatting and SysV argument translation for scanning/wide formatting, including 64-bit guest long values. - Correct calling conventions for `__cxa_atexit` destructors and `atexit` callbacks. The host callback wrapper preserves Windows registers across SysV guest calls. **The inconclusive vblank timing change has been removed from this PR.** No graphics-performance improvement is claimed. Shader PR #96 and notification PR #97 remain separate. ### Tested Rebased onto upstream `49a7819`. The following checks were rerun on head `9e3b3c8`, Windows Release, with the explicit NID-patched `libs` build: | Check | Result | |---|---| | Release build and patched runtime libraries | Pass | | Existing repository CTests | 54/54 pass | | External C++ regression programs | 4/4 pass: application heap, character conversion, condition-variable destruction, strings | | External converter regression scripts | 3/3 pass: arguments, guest dependencies, lifecycle arrays | | Converted PS5-target probes | 7/7 positive runs pass | | Deliberate wrong-result controls | Seven expected failing exit codes plus one rejected shutdown output | | Original C++ sample with native-title CRT adaptation | 5/5 consecutive runs complete, exit 0, expected output, no fatal diagnostic | | Whitespace/error check | Pass | The converted probes exercise: - 64-bit numeric limits, end pointers, overflow and extended precision beyond double. - Replacement allocator callbacks, allocation failure, empty output and embedded NUL characters. - All 256 single-byte values, SDK state-size assertions, state/output guards, partial buffers and source-pointer updates. - Wide stream EOF, pushback, invalid values, error persistence, clearerr and reopen. - Register/stack-passed formatting/scanning arguments, scansets, suppression, `%ln`, width/precision, wide Unicode output and truncation guards. - C++ destructor arguments and LIFO order. The guest deliberately clobbers registers that Windows callers must preserve, exercising the callback bridge. Its wrong-result control produces `EXIT_ABI_BAD`, which the output oracle rejects despite exit 0. All five final C++ sample runs printed: ```text Hello, libcxx! ... sorted vec: 1 2 3 4 5 Caught exception: 42 ``` and exited normally with status 0. Before the destructor ABI fix the same sample reached that output, then faulted and exited `0xc0000409`. No exception or shutdown bypass was added. ### Review notes and limits - Public community SDK headers/static libraries are used. This is not Sony SDK validation, physical-console validation, or unchanged exploited-console payload execution. The original C++ sample source uses an external native-title startup/link adaptation. - Windows runtime validation only. Linux lifecycle-array metadata has structural conversion coverage; Linux execution was not tested. - Character conversion supports the runtime's existing C/POSIX single-byte locale. Additional locales and a complete wide-stream orientation interface are not implemented. - Positional dollar formats and nonstandard format extensions are unsupported and use `NotImplemented_nid_no_patch`. Invalid/incomplete formats return errors. This is not complete libc conformance. - PR #81 implements related `vswprintf`/`wprintf` functionality using another helper. It does not replace these `swprintf`/scanning/exit-ABI fixes, but the helpers should be reconciled if both land. The file overlap found with that PR is libc's CMake source list. Relevant relinker/library PRs #85, #12, #30, #28 and #86 have no changed-file overlap with this diff. - No new tests, demos, investigation documents, images or binaries are added to Git. Test programs and reports remain in the external validation workspace. Reviewer-facing results are recorded above. ### Checklist - [x] Based on current upstream main; overlapping PR #81 explicitly identified for review - [x] Scoped to converted SDK sample startup, runtime and shutdown compatibility; timing experiment removed - [x] No explanatory comments added to code - [x] Unsupported format extensions throw via `NotImplemented_nid_no_patch`; no new silent success stubs - [x] No notes, investigation documents, images or new tests added to the repository - [x] No new third-party runtime sources or binaries - [x] Generic behavior, not title-specific code - [x] Depends on: none of #96 or #97 - [x] AI-assisted: yes
github-actions[bot] commented 2026-09-28 20:33:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-09-28T20:33:40Z.


Progress report (8cc16ec → a6ea90b)

📈 System libraries: 76.5% (+0.16%, +20 implemented functions)

✅ 20 implemented
Library Name
libc ___mb_cur_max_nid_postfix
libc bzero_nid_postfix
libc fgetwc_nid_postfix
libc mbrlen_nid_postfix
libc mbrtowc_nid_postfix
libc mbsinit_nid_postfix
libc mbsrtowcs_nid_postfix
libc mbtowc_nid_postfix
libc strxfrm_nid_postfix
libc swprintf_nid_postfix
libc ungetwc_nid_postfix
libc vasprintf_nid_postfix
libc vsscanf_nid_postfix
libc wcrtomb_nid_postfix
libc wcscoll_nid_postfix
libc wcstold_nid_postfix
libc wcstoul_nid_postfix
libc wcstoull_nid_postfix
libc wcsxfrm_nid_postfix
libkernel pthread_cond_destroy_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5877990832 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/98#issuecomment-5877990832). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-09-28T20:33:40Z. --- <!-- progress-report --> ### Progress report (8cc16ec → a6ea90b) 📈 **System libraries**: 76.5% (+0.16%, +20 implemented functions) <details> <summary>✅ 20 implemented</summary> | Library | Name | | - | - | | libc | `___mb_cur_max_nid_postfix` | | libc | `bzero_nid_postfix` | | libc | `fgetwc_nid_postfix` | | libc | `mbrlen_nid_postfix` | | libc | `mbrtowc_nid_postfix` | | libc | `mbsinit_nid_postfix` | | libc | `mbsrtowcs_nid_postfix` | | libc | `mbtowc_nid_postfix` | | libc | `strxfrm_nid_postfix` | | libc | `swprintf_nid_postfix` | | libc | `ungetwc_nid_postfix` | | libc | `vasprintf_nid_postfix` | | libc | `vsscanf_nid_postfix` | | libc | `wcrtomb_nid_postfix` | | libc | `wcscoll_nid_postfix` | | libc | `wcstold_nid_postfix` | | libc | `wcstoul_nid_postfix` | | libc | `wcstoull_nid_postfix` | | libc | `wcsxfrm_nid_postfix` | | libkernel | `pthread_cond_destroy_nid_postfix` | </details>
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!98
No description provided.