feat(libc): implement swprintf_s #5454
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5454"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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 nolonger fails at startup with
undefined symbol: Im55VJ-Bekc.python3 tools/check_conventions.py --base origin/mainpassed. Guest-wide-formattingbehaviour exercised through the existing implementation patterns; no new code
comments added.
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)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T21:54:31Z.
Heads up: GitHub currently reports this PR as
DIRTYagainstmain. The overlap report points to the shareddocs/dev/debt/libc.mdentries; 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.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 <= RsizeMaxguard treatsRsizeMaxas a count of 16-bit wide characters. Annex K's wide formatting constraints boundnbyRSIZE_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-sizedRSIZE_MAXvalue used here. The failure-path buffer clearing condition should use the same valid-size bound. Could the newswprintf_s,vswprintf_sandvsnwprintf_suse 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.
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.
main)core/libs/tests/GuestWideFormatting.cppL150, L245-246Imported 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 acceptssize <= 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 exactlyRsizeMaxleavesbuffer[0]unchanged. Could these cleanup checks usesize <= RsizeMax(and ideally cover the boundary predicate in a focused test)?AI-assisted: yes; reviewed by MarcZX100.
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
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 == RsizeMaxpasses the entry guard, and Annex K says a constraint failure must clearbuffer[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. Forsize > 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.
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 == RsizeMaxbut their failure cleanup only clears the buffer whensize < 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 leavesbuffer[0]unchanged. Please change all three predicates to includesize == RsizeMaxand 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.
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:
RsizeMaxuses a character-count limit for the guest’s 16-bit wide characters:(SIZE_MAX >> 1) / sizeof(char16_t).size <= RsizeMax, so a failure atsize == RsizeMaxclearsbuffer[0].size > RsizeMax) still never clears the buffer.GuestWideFormatting.cppcovering, for each function:wideRsizeMaxclears the first unit, andAI-assisted: yes
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 inclusivesize == RsizeMaxfailure 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.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
swprintf_s_nid_postfixvsnwprintf_s_nid_postfixvswprintf_s_nid_postfix