feat(libc): implement swscanf #4467

Merged
arcwiser merged 1 commit from upstream-pr/4467 into main 2026-10-13 22:27:58 +00:00
arcwiser commented 2026-10-12 12:40:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by arcwiser on 2026-10-12T12:40:49Z.


What

Implement the missing 16-bit guest swscanf export by sharing the existing swscanf_s scanner without consuming the secure buffer-size arguments after string, character and scanset conversions. Keep the existing refusal behavior for unsupported conversions and widen the documented scanner limitations to cover both entry points.

Add regression coverage for integer, floating-point, string, character, scanset, %n, suppression, width, partial-match, EOF, null-input and unsupported-format behavior.

This carries screamm's offered commit from issue #4464 unchanged and preserves its authorship.

Closes #4464.

Tested

  • Windows 11 build 26200, WinLibs MinGW-w64 GCC 15.2.0 r7, Release, BUILD_TESTING=ON
  • Built guest_wide_conversion_tests and its 52-step libc dependency target successfully
  • ctest --test-dir build -R '^guest_wide_conversion$' --output-on-failure (3/3 passed)
  • python tools/check_conventions.py --base origin/main
  • git diff --check origin/main
  • python tools/check_test_registration.py build (705 executables, none unregistered)
  • Project overlap checker: no overlap with open pull requests
  • Original author additionally reported 606/606 non-GPU full tests on Windows; not rerun in this carry checkout

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; unsupported scanner behavior remains rejected
  • No notes, investigation .md files or images added to the repository
  • No third-party code added
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none (PPSA99360 imports this function, but the stop is predicted rather than runtime-observed)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4829547784 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4467). Originally posted by [arcwiser](https://github.com/arcwiser) on 2026-10-12T12:40:49Z. --- ### What Implement the missing 16-bit guest `swscanf` export by sharing the existing `swscanf_s` scanner without consuming the secure buffer-size arguments after string, character and scanset conversions. Keep the existing refusal behavior for unsupported conversions and widen the documented scanner limitations to cover both entry points. Add regression coverage for integer, floating-point, string, character, scanset, `%n`, suppression, width, partial-match, EOF, null-input and unsupported-format behavior. This carries screamm's offered commit from issue #4464 unchanged and preserves its authorship. Closes #4464. ### Tested - Windows 11 build 26200, WinLibs MinGW-w64 GCC 15.2.0 r7, Release, `BUILD_TESTING=ON` - Built `guest_wide_conversion_tests` and its 52-step libc dependency target successfully - `ctest --test-dir build -R '^guest_wide_conversion$' --output-on-failure` (3/3 passed) - `python tools/check_conventions.py --base origin/main` - `git diff --check origin/main` - `python tools/check_test_registration.py build` (705 executables, none unregistered) - Project overlap checker: no overlap with open pull requests - Original author additionally reported 606/606 non-GPU full tests on Windows; not rerun in this carry checkout ### 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; unsupported scanner behavior remains rejected - [x] No notes, investigation `.md` files or images added to the repository - [x] No third-party code added - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none (PPSA99360 imports this function, but the stop is predicted rather than runtime-observed) - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-12 12:41:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T12:41:19Z.


Progress report (bf8dc61 → 8aa0d42)

➖ System libraries: 88.18% (+0.0%, +1 implemented functions)

✅ 1 implemented
Library Name
libc swscanf_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6124461956 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4467#issuecomment-6124461956). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-12T12:41:19Z. --- <!-- progress-report --> ### Progress report (bf8dc61 → 8aa0d42) ➖ **System libraries**: 88.18% (+0.0%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libc | `swscanf_nid_postfix` | </details>
LeandroLP23 commented 2026-10-12 13:56:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-12T13:56:41Z.


The swscanf stop is now observed at runtime, not just predicted. PS5CEMU-HAR (PPSA99360, catalog 3.5.0) on Windows 11 (26300), WinLibs GCC 15.2.0, Release, relinked with --windows --trap-sdk-syscall-stubs. Each step adds one change onto main f8dee0595:

Build Stop
main unresolved ELF import avvJ3J0H0EY from libkernel.prx (sceKernelJitCreateSharedMemory, #3787)
+ #3787 (its two File/src conflicts with main resolved by keeping both sides) unresolved ELF import 5KWrg7-ZqvE from libkernel.prx (pthread_setaffinity_np)
+ screamm's feat/libkernel-setaffinity-siglist (827a8c87) unresolved ELF import HNnWdT43ues from libSceLibcInternal.prx (swscanf)
+ screamm's feat/libc-swscanf (569cb122, the same patch as this PR's 462830939 per git range-diff) unresolved ELF import ELSr5qm4K1M from libSceLibcInternal.prx (__umodti3, #4462)

So with #3787 and pthread_setaffinity_np in, this PR moves the title from swscanf to __umodti3. The Unblocks line could name PPSA99360 (with Depends on: #3787), if you agree. I'm opening a PR that carries screamm's pthread_setaffinity_np commit, the one part of #4463 not carried yet.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6125744655 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4467#issuecomment-6125744655). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-10-12T13:56:41Z. --- The `swscanf` stop is now observed at runtime, not just predicted. PS5CEMU-HAR (PPSA99360, catalog 3.5.0) on Windows 11 (26300), WinLibs GCC 15.2.0, Release, relinked with `--windows --trap-sdk-syscall-stubs`. Each step adds one change onto `main` `f8dee0595`: | Build | Stop | |---|---| | `main` | `unresolved ELF import avvJ3J0H0EY from libkernel.prx` (`sceKernelJitCreateSharedMemory`, #3787) | | + #3787 (its two `File/src` conflicts with `main` resolved by keeping both sides) | `unresolved ELF import 5KWrg7-ZqvE from libkernel.prx` (`pthread_setaffinity_np`) | | + screamm's `feat/libkernel-setaffinity-siglist` (`827a8c87`) | `unresolved ELF import HNnWdT43ues from libSceLibcInternal.prx` (`swscanf`) | | + screamm's `feat/libc-swscanf` (`569cb122`, the same patch as this PR's `462830939` per `git range-diff`) | `unresolved ELF import ELSr5qm4K1M from libSceLibcInternal.prx` (`__umodti3`, #4462) | So with #3787 and `pthread_setaffinity_np` in, this PR moves the title from `swscanf` to `__umodti3`. The `Unblocks` line could name PPSA99360 (with `Depends on: #3787`), if you agree. I'm opening a PR that carries screamm's `pthread_setaffinity_np` commit, the one part of #4463 not carried yet. AI-assisted: yes (Claude Code)
screamm commented 2026-10-13 10:55:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-13T10:55:50Z.


Windows validation with title evidence (Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, BUILD_TESTING=ON, full build including libs; base main d379bfd0 with #5025 applied for the title runs (without it current main cannot load libkernel_sys.prx on Windows, #4877)): 46283093 merged onto d379bfd0 (one trivial conflict: the bullet now belongs in docs/dev/debt/libc.md). Same lines as my 569cb122. guest_wide_conversion 3/3; suite 686/688 (guest_sce_net passes serially, patched_libraries is main's #4877 failure); conventions and git diff --check pass.

PS5CEMU-HAR (PPSA99360): with #4514 in, the title's stop is FAIL: unresolved ELF import HNnWdT43ues from libSceLibcInternal.prx (this export); with #4514 + #4469 + this PR it runs the whole minute at PS5CEMU-HAR | FPS: 59.93 (3483), launcher [ui] frames=3001 avg=16.68 ms.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6143992626 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4467#issuecomment-6143992626). Originally posted by [screamm](https://github.com/screamm) on 2026-10-13T10:55:50Z. --- Windows validation with title evidence (Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, `BUILD_TESTING=ON`, full build including `libs`; base `main` `d379bfd0` with #5025 applied for the title runs (without it current `main` cannot load `libkernel_sys.prx` on Windows, #4877)): `46283093` merged onto `d379bfd0` (one trivial conflict: the bullet now belongs in `docs/dev/debt/libc.md`). Same lines as my `569cb122`. `guest_wide_conversion` 3/3; suite 686/688 (`guest_sce_net` passes serially, `patched_libraries` is `main`'s #4877 failure); conventions and `git diff --check` pass. PS5CEMU-HAR (PPSA99360): with #4514 in, the title's stop is `FAIL: unresolved ELF import HNnWdT43ues from libSceLibcInternal.prx` (this export); with #4514 + #4469 + this PR it runs the whole minute at `PS5CEMU-HAR | FPS: 59.93 (3483)`, launcher `[ui] frames=3001 avg=16.68 ms`.
p3n1cillin commented 2026-10-13 14:38:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by p3n1cillin on 2026-10-13T14:38:35Z.


Title run with this PR: Windows 11, MinGW GCC 15.2.0 (WinLibs), Release, on main 3faa9cb40 merged with this PR and the other open PRs the catalog titles need; PS5CEMU-HAR (PPSA99360) from its catalog release, converted with --trap-sdk-syscall-stubs (it has a forbidden inline syscall otherwise), eboot.bin kept in app0.

  • With this PR, #4469 and #4514, tools/import_audit.py lists no absent import for PS5CEMU-HAR (on main swscanf, sys_siglist, sys_nsig and pthread_setaffinity_np are absent) and it runs the whole 60 s with no exception.
  • This head conflicts with main only in docs/dev/TechnicalDebt.md: main now keeps debt in docs/dev/debt/<library>.md (python tools/debt_split.py resolve moves the entry).

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6148068805 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4467#issuecomment-6148068805). Originally posted by [p3n1cillin](https://github.com/p3n1cillin) on 2026-10-13T14:38:35Z. --- Title run with this PR: Windows 11, MinGW GCC 15.2.0 (WinLibs), Release, on `main` `3faa9cb40` merged with this PR and the other open PRs the catalog titles need; PS5CEMU-HAR (PPSA99360) from its catalog release, converted with `--trap-sdk-syscall-stubs` (it has a forbidden inline syscall otherwise), `eboot.bin` kept in `app0`. - With this PR, #4469 and #4514, `tools/import_audit.py` lists no absent import for PS5CEMU-HAR (on `main` `swscanf`, `sys_siglist`, `sys_nsig` and `pthread_setaffinity_np` are absent) and it runs the whole 60 s with no exception. - This head conflicts with `main` only in `docs/dev/TechnicalDebt.md`: `main` now keeps debt in `docs/dev/debt/<library>.md` (`python tools/debt_split.py resolve` moves the entry). AI-assisted (Claude Code).
blawesom commented 2026-10-13 19:17:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-13T19:17:04Z.


Rebase handoff — rebased onto current main, authorship unchanged. This one needed the full per-library routing: the PR's TechnicalDebt.md conflict carried 107 debt entries from before the ledger restructure (#4411) — each is routed to its docs/dev/debt/<name>.md by first core/ link, with relative links adjusted for the deeper directory.

Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, BUILD_TESTING=ON, AMD RX 9070 XT / RADV):

  • builds; tools/check_conventions.py --base origin/main passes
  • full suite: 1070/1071 — the only failure is the known main regression (agc_driver_tessellation segfault, #4727)

To pick it up:

git fetch https://github.com/blawesom/AnyPS5 rebase/4467
git checkout <your branch>
git merge --ff-only FETCH_HEAD

Head is 1818ddb38.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6153269762 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4467#issuecomment-6153269762). Originally posted by [blawesom](https://github.com/blawesom) on 2026-10-13T19:17:04Z. --- **Rebase handoff** — rebased onto current `main`, authorship unchanged. This one needed the full per-library routing: the PR's `TechnicalDebt.md` conflict carried 107 debt entries from before the ledger restructure (#4411) — each is routed to its `docs/dev/debt/<name>.md` by first `core/` link, with relative links adjusted for the deeper directory. Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, `BUILD_TESTING=ON`, AMD RX 9070 XT / RADV): - builds; `tools/check_conventions.py --base origin/main` passes - **full suite: 1070/1071** — the only failure is the known `main` regression (`agc_driver_tessellation` segfault, #4727) **To pick it up:** ``` git fetch https://github.com/blawesom/AnyPS5 rebase/4467 git checkout <your branch> git merge --ff-only FETCH_HEAD ``` Head is `1818ddb38`.
oneandonlydean commented 2026-10-13 21:05:04 +00:00 (Migrated from github.com)

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


Conflicts with main in docs/dev/TechnicalDebt.md; the swscanf entry now goes in docs/dev/debt/libc.md, please rebase. Also list #4514 under Depends on and PPSA99360 under Unblocks, since screamm's run shows the title stops at HNnWdT43ues once #4514 is in.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6155177584 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4467#issuecomment-6155177584). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-13T21:05:04Z. --- Conflicts with main in `docs/dev/TechnicalDebt.md`; the swscanf entry now goes in `docs/dev/debt/libc.md`, please rebase. Also list #4514 under Depends on and PPSA99360 under Unblocks, since screamm's run shows the title stops at `HNnWdT43ues` once #4514 is in.
oneandonlydean commented 2026-10-13 22:20:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T22:20:03Z.


Rebased onto main (bf8dc610e6) and force-pushed: the swscanf debt entry now sits in docs/dev/debt/libc.md with main's other entries, and docs/dev/TechnicalDebt.md is as on main. The commit and its author are unchanged.
Please update the description: #4514 (merged) under Depends on, PPSA99360 under Unblocks.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6156433915 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4467#issuecomment-6156433915). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-13T22:20:03Z. --- Rebased onto main (bf8dc610e6) and force-pushed: the swscanf debt entry now sits in `docs/dev/debt/libc.md` with main's other entries, and `docs/dev/TechnicalDebt.md` is as on main. The commit and its author are unchanged. Please update the description: #4514 (merged) under Depends on, PPSA99360 under Unblocks.
github-actions[bot] commented 2026-10-13 22:26:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T22:26:06Z.


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
#4958 docs/dev/debt/libc.md L65-66
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6156534305 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4467#issuecomment-6156534305). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T22:26:06Z. --- <!-- 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 | |---|---|---|---| | #4958 | `docs/dev/debt/libc.md` [L65-66](https://github.com/boykopovar/AnyPS5/blob/bf8dc610e665a7547d027418e31ddcbb3261b3e0/docs/dev/debt/libc.md#L65-L66) | | |
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!4467
No description provided.