feat(libc): implement swprintf_s #5454

Merged
mohammad-alosta merged 1 commit from upstream-pr/5454 into main 2026-10-14 07:12:15 +00:00
mohammad-alosta commented 2026-10-13 20:07:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by mohammad-alosta on 2026-10-13T20:07:48Z.


What

Add the missing wide secure formatting exports required by PPSA15552 (Dead Cells),
whose load failed with undefined symbol: Im55VJ-Bekc:
swprintf_s and its va_list counterpart follow C11 Annex K.3.9.1.4
(the complete output, including the terminator, must fit), while vsnwprintf_s is
the va_list counterpart of snwprintf_s (K.3.9.1.3, truncation with full length).
The export names produce NIDs Im55VJ-Bekc, oDoV9tyHTbA and 8SKVXgeK1wY
respectively. Document the new functions in docs/dev/debt/libc.md.

Tested

Linux. Rebuilt libc.prx; verified the new exports resolve (Im55VJ-Bekc,
oDoV9tyHTbA, 8SKVXgeK1wY) and the PPSA15552 (Dead Cells) executable no
longer fails at startup with undefined symbol: Im55VJ-Bekc. python3 tools/check_conventions.py --base origin/main passed. Guest-wide-formatting
behaviour exercised through the existing implementation patterns; no new code
comments added.

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 under Silent stubs in their library's technical debt file
  • 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
  • Unblocks: PPSA15552 Dead Cells
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4848827558 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5454). Originally posted by [mohammad-alosta](https://github.com/mohammad-alosta) on 2026-10-13T20:07:48Z. --- ### What Add the missing wide secure formatting exports required by PPSA15552 (Dead Cells), whose load failed with `undefined symbol: Im55VJ-Bekc`: swprintf_s and its va_list counterpart follow C11 Annex K.3.9.1.4 (the complete output, including the terminator, must fit), while vsnwprintf_s is the va_list counterpart of snwprintf_s (K.3.9.1.3, truncation with full length). The export names produce NIDs Im55VJ-Bekc, oDoV9tyHTbA and 8SKVXgeK1wY respectively. Document the new functions in docs/dev/debt/libc.md. ### Tested Linux. Rebuilt libc.prx; verified the new exports resolve (`Im55VJ-Bekc`, `oDoV9tyHTbA`, `8SKVXgeK1wY`) and the PPSA15552 (Dead Cells) executable no longer fails at startup with `undefined symbol: Im55VJ-Bekc`. `python3 tools/check_conventions.py --base origin/main` passed. Guest-wide-formatting behaviour exercised through the existing implementation patterns; no new code comments added. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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 - [x] Depends on: none - [x] Unblocks: PPSA15552 Dead Cells - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-13 21:54:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T21:54:31Z.


Heads up: GitHub currently reports this PR as DIRTY against main. The overlap report points to the shared docs/dev/debt/libc.md entries; please rebase before merge and resolve the debt split during the stopped rebase (python3 tools/debt_split.py resolve) if applicable. The existing conventions and intake checks pass.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6156009046 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5454#issuecomment-6156009046). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-13T21:54:31Z. --- Heads up: GitHub currently reports this PR as `DIRTY` against `main`. The overlap report points to the shared `docs/dev/debt/libc.md` entries; please rebase before merge and resolve the debt split during the stopped rebase (`python3 tools/debt_split.py resolve`) if applicable. The existing conventions and intake checks pass.
MarcZX10 commented 2026-10-13 23:32:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T23:32:56Z.


One bounds detail to check in the three new functions: the size <= RsizeMax guard treats RsizeMax as a count of 16-bit wide characters. Annex K's wide formatting constraints bound n by RSIZE_MAX / sizeof(wchar_t) (see WG14 N3220, K.3.9.2.8); for the guest's 16-bit wide characters, that is half the byte-sized RSIZE_MAX value used here. The failure-path buffer clearing condition should use the same valid-size bound. Could the new swprintf_s, vswprintf_s and vsnwprintf_s use a character-count limit derived from the guest wide-character size, with a regression for the oversized-size constraint?

AI-assisted: yes; reviewed by MarcZX100.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6157429893 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5454#issuecomment-6157429893). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-13T23:32:56Z. --- One bounds detail to check in the three new functions: the `size <= RsizeMax` guard treats `RsizeMax` as a count of 16-bit wide characters. Annex K's wide formatting constraints bound `n` by `RSIZE_MAX / sizeof(wchar_t)` (see [WG14 N3220, K.3.9.2.8](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3220.pdf)); for the guest's 16-bit wide characters, that is half the byte-sized `RSIZE_MAX` value used here. The failure-path buffer clearing condition should use the same valid-size bound. Could the new `swprintf_s`, `vswprintf_s` and `vsnwprintf_s` use a character-count limit derived from the guest wide-character size, with a regression for the oversized-size constraint? AI-assisted: yes; reviewed by MarcZX100.
github-actions[bot] commented 2026-10-13 23:39:30 +00:00 (Migrated from github.com)

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


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
#5303 core/libs/tests/GuestWideFormatting.cpp L150, L245-246
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6157510990 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5454#issuecomment-6157510990). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T23:39:30Z. --- <!-- 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 | |---|---|---|---| | #5303 | `core/libs/tests/GuestWideFormatting.cpp` [L150](https://github.com/boykopovar/AnyPS5/blob/78f1aea706e93b109da7180bf76718f545ef0e43/core/libs/tests/GuestWideFormatting.cpp#L150), [L245-246](https://github.com/boykopovar/AnyPS5/blob/78f1aea706e93b109da7180bf76718f545ef0e43/core/libs/tests/GuestWideFormatting.cpp#L245-L246) | | |
MarcZX10 commented 2026-10-13 23:42:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T23:42:35Z.


One remaining boundary case after the bounds update: all three failure cleanup conditions still use size < RsizeMax, while the entry guard accepts size <= RsizeMax. Annex K's cleanup condition is inclusive (0 < n <= RSIZE_MAX / sizeof(wchar_t); WG14 N3220 K.3.9.2.4 and K.3.9.2.8). Thus a runtime-constraint failure at exactly RsizeMax leaves buffer[0] unchanged. Could these cleanup checks use size <= RsizeMax (and ideally cover the boundary predicate in a focused test)?

AI-assisted: yes; reviewed by MarcZX100.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6157548530 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5454#issuecomment-6157548530). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-13T23:42:35Z. --- One remaining boundary case after the bounds update: all three failure cleanup conditions still use `size < RsizeMax`, while the entry guard accepts `size <= RsizeMax`. Annex K's cleanup condition is inclusive (`0 < n <= RSIZE_MAX / sizeof(wchar_t)`; WG14 N3220 K.3.9.2.4 and K.3.9.2.8). Thus a runtime-constraint failure at exactly `RsizeMax` leaves `buffer[0]` unchanged. Could these cleanup checks use `size <= RsizeMax` (and ideally cover the boundary predicate in a focused test)? AI-assisted: yes; reviewed by MarcZX100.
mohammad-alosta commented 2026-10-13 23:46:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by mohammad-alosta on 2026-10-13T23:46:32Z.


Implemented the requested bound change in the three new functions: guest wide characters are 16-bit, so their character-count limit is now (SIZE_MAX >> 1) / sizeof(char16_t) instead of the byte-oriented count.

Updated and rebuilt libc.prx, amended the PR commit, and passed tools/check_conventions.py --base origin/main. The oversized-size regression test returns -1 without touching the buffer, matching the project’s existing clearing convention.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6157595949 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5454#issuecomment-6157595949). Originally posted by [mohammad-alosta](https://github.com/mohammad-alosta) on 2026-10-13T23:46:32Z. --- Implemented the requested bound change in the three new functions: guest wide characters are 16-bit, so their character-count limit is now (SIZE_MAX >> 1) / sizeof(char16_t) instead of the byte-oriented count. Updated and rebuilt libc.prx, amended the PR commit, and passed tools/check_conventions.py --base origin/main. The oversized-size regression test returns -1 without touching the buffer, matching the project’s existing clearing convention. AI-assisted: yes
MarcZX10 commented 2026-10-13 23:48:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T23:48:27Z.


Thanks for adding the oversized-size regression. I meant the inclusive valid boundary, rather than a size above it: size == RsizeMax passes the entry guard, and Annex K says a constraint failure must clear buffer[0] for that value. A small safe regression is to use a one-element buffer, size == RsizeMax, and a null format (the invalid-argument path returns before reading or writing output); then assert the first element was cleared. For size > RsizeMax, leaving the buffer untouched is correct. The three cleanup predicates still use < RsizeMax, so the == case remains open.

AI-assisted: yes; reviewed by MarcZX100.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6157619268 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5454#issuecomment-6157619268). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-13T23:48:27Z. --- Thanks for adding the oversized-size regression. I meant the inclusive *valid* boundary, rather than a size above it: `size == RsizeMax` passes the entry guard, and Annex K says a constraint failure must clear `buffer[0]` for that value. A small safe regression is to use a one-element buffer, `size == RsizeMax`, and a null format (the invalid-argument path returns before reading or writing output); then assert the first element was cleared. For `size > RsizeMax`, leaving the buffer untouched is correct. The three cleanup predicates still use `< RsizeMax`, so the `==` case remains open. AI-assisted: yes; reviewed by MarcZX100.
MarcZX10 commented 2026-10-13 23:49:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T23:49:44Z.

Review: CHANGES_REQUESTED


The three new secure wide-format functions accept size == RsizeMax but their failure cleanup only clears the buffer when size < RsizeMax. Annex K's constraint-clearing condition includes the maximum valid size (0 < n <= RSIZE_MAX / sizeof(wchar_t)), so a failure at exactly that boundary leaves buffer[0] unchanged. Please change all three predicates to include size == RsizeMax and add a regression for that accepted-boundary failure. The above-limit untouched-buffer case is separate and should remain covered.

AI-assisted: yes; reviewed by MarcZX100.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5511415053 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5454#pullrequestreview-5511415053). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-13T23:49:44Z. **Review:** CHANGES_REQUESTED --- The three new secure wide-format functions accept `size == RsizeMax` but their failure cleanup only clears the buffer when `size < RsizeMax`. Annex K's constraint-clearing condition includes the maximum valid size (`0 < n <= RSIZE_MAX / sizeof(wchar_t)`), so a failure at exactly that boundary leaves `buffer[0]` unchanged. Please change all three predicates to include `size == RsizeMax` and add a regression for that accepted-boundary failure. The above-limit untouched-buffer case is separate and should remain covered. AI-assisted: yes; reviewed by MarcZX100.
mohammad-alosta commented 2026-10-14 00:03:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by mohammad-alosta on 2026-10-14T00:03:53Z.


Addressed, thanks for the detail. The three functions now behave as requested:

  • RsizeMax uses a character-count limit for the guest’s 16-bit wide characters:
    (SIZE_MAX >> 1) / sizeof(char16_t).
  • Failure cleanup now includes the accepted boundary:
    size <= RsizeMax, so a failure at size == RsizeMax clears buffer[0].
  • The oversized case (size > RsizeMax) still never clears the buffer.
  • Added regressions in GuestWideFormatting.cpp covering, for each function:
    • a failure at wideRsizeMax clears the first unit, and
    • an oversized size leaves the buffer untouched.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6157809505 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5454#issuecomment-6157809505). Originally posted by [mohammad-alosta](https://github.com/mohammad-alosta) on 2026-10-14T00:03:53Z. --- Addressed, thanks for the detail. The three functions now behave as requested: - `RsizeMax` uses a character-count limit for the guest’s 16-bit wide characters: `(SIZE_MAX >> 1) / sizeof(char16_t)`. - Failure cleanup now includes the accepted boundary: `size <= RsizeMax`, so a failure at `size == RsizeMax` clears `buffer[0]`. - The oversized case (`size > RsizeMax`) still never clears the buffer. - Added regressions in `GuestWideFormatting.cpp` covering, for each function: - a failure at `wideRsizeMax` clears the first unit, and - an oversized size leaves the buffer untouched. AI-assisted: yes
MarcZX10 commented 2026-10-14 00:25:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-14T00:25:41Z.

Review: APPROVED


The updated code now uses the guest-character RsizeMax, clears on the inclusive size == RsizeMax failure boundary in all three functions, and covers both the accepted boundary and above-limit untouched-buffer behavior. This resolves my requested change. I did not execute the new Linux regression locally because the workspace filesystem is full; the current GitHub check I can see is conventions.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5511641563 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5454#pullrequestreview-5511641563). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-14T00:25:41Z. **Review:** APPROVED --- The updated code now uses the guest-character `RsizeMax`, clears on the inclusive `size == RsizeMax` failure boundary in all three functions, and covers both the accepted boundary and above-limit untouched-buffer behavior. This resolves my requested change. I did not execute the new Linux regression locally because the workspace filesystem is full; the current GitHub check I can see is conventions.
github-actions[bot] commented 2026-10-14 05:10:36 +00:00 (Migrated from github.com)

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


Progress report (d167000 → a0bd257)

📈 System libraries: 88.19% (+0.01%, +3 implemented functions)

✅ 3 implemented
Library Name
libc swprintf_s_nid_postfix
libc vsnwprintf_s_nid_postfix
libc vswprintf_s_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6161390231 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5454#issuecomment-6161390231). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-14T05:10:36Z. --- <!-- progress-report --> ### Progress report (d167000 → a0bd257) 📈 **System libraries**: 88.19% (+0.01%, +3 implemented functions) <details> <summary>✅ 3 implemented</summary> | Library | Name | | - | - | | libc | `swprintf_s_nid_postfix` | | libc | `vsnwprintf_s_nid_postfix` | | libc | `vswprintf_s_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!5454
No description provided.