feat(libc): implement _Vacopy #8593

Merged
priyanshrv-netizen merged 2 commits from upstream-pr/8593 into main 2026-10-23 14:26:42 +00:00
priyanshrv-netizen commented 2026-10-20 17:43:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by priyanshrv-netizen on 2026-10-20T17:43:25Z.


What

Implements _Vacopy (NID xRycekLYXdc), the Dinkumware helper behind va_copy, which the system libc.prx (build J03093718) exports and no source in core/libs/prx or open pull request defines yet.

core/libs/prx/libc/src/RuntimeSupport.cpp follows that module's disassembly (0x3950), which copies the 24-byte System V va_list in two steps and in this order:

mov  rax, [rsi+16]      ; overflow_arg_area and reg_save_area
mov  [rdi+16], rax
vmovups xmm0, [rsi]     ; gp_offset, fp_offset, overflow_arg_area
vmovups [rdi], xmm0

The order matters when the two lists overlap: the console writes the last 8 bytes first, then the first 16. The implementation copies in the same order, so an overlapping copy gives the same result, and returns the same value in rax as the console's _Vacopy, which the Dinkumware header ignores.

CheckVacopy in core/libs/tests/GuestStdioVariadic.cpp copies a 9-argument list, reads every argument through the copy, checks that the source is untouched and still readable afterwards, and checks the byte order of an overlapping copy.

Tested

Windows 10, MSYS2 MinGW-w64 GCC 15.2.0 (mingw64, not the WinLibs UCRT toolchain from BUILD.md). I did not configure the full CMake build. RuntimeSupport.cpp builds with -Wall -Wextra -Werror -fno-asynchronous-unwind-tables. CheckVacopy (copied unchanged from GuestStdioVariadic.cpp, with stubs for the two unrelated helpers that file's object needs) passes; against main's RuntimeSupport.cpp it fails to link on _Vacopy_nid_postfix. The first commit defined CheckVacopy but never called it from main, so in the Release build the checks were dropped and guest_stdio_variadic passed without them (found in review); main now calls it. Built with the CI flags (-O3 -DNDEBUG -Wall), the test object now references _Vacopy_nid_postfix and has no unused-function warning, and an implementation that copies bytes 0-15 before bytes 16-23 makes CheckVacopy abort.

Against the console code itself: I mapped that libc.prx's segments into memory, applied its relocations and called its _Vacopy through a System V function pointer beside this one. For 200,000 random 24-byte lists, half at a random alignment, with the destination 8 bytes above the source, 8 bytes below it, or clear of it, the destination and the surrounding bytes were identical in every case.

tools/check_conventions.py --base origin/main passes. tools/pr_overlap.py --branch feat/libc-vacopy reports no overlap. It could not compare #5021, #7201 and #7648 (each conflicts with main); I checked them by hand: all three change RuntimeSupport.cpp at line 112 or later, where this inserts at line 94, and none adds this export. Not tested on Linux; no title was run.

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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4939913538 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8593). Originally posted by [priyanshrv-netizen](https://github.com/priyanshrv-netizen) on 2026-10-20T17:43:25Z. --- ### What Implements `_Vacopy` (NID `xRycekLYXdc`), the Dinkumware helper behind `va_copy`, which the system `libc.prx` (build `J03093718`) exports and no source in `core/libs/prx` or open pull request defines yet. `core/libs/prx/libc/src/RuntimeSupport.cpp` follows that module's disassembly (0x3950), which copies the 24-byte System V `va_list` in two steps and in this order: ``` mov rax, [rsi+16] ; overflow_arg_area and reg_save_area mov [rdi+16], rax vmovups xmm0, [rsi] ; gp_offset, fp_offset, overflow_arg_area vmovups [rdi], xmm0 ``` The order matters when the two lists overlap: the console writes the last 8 bytes first, then the first 16. The implementation copies in the same order, so an overlapping copy gives the same result, and returns the same value in `rax` as the console's `_Vacopy`, which the Dinkumware header ignores. `CheckVacopy` in `core/libs/tests/GuestStdioVariadic.cpp` copies a 9-argument list, reads every argument through the copy, checks that the source is untouched and still readable afterwards, and checks the byte order of an overlapping copy. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows 10, MSYS2 MinGW-w64 GCC 15.2.0 (`mingw64`, not the WinLibs UCRT toolchain from BUILD.md). I did not configure the full CMake build. `RuntimeSupport.cpp` builds with `-Wall -Wextra -Werror -fno-asynchronous-unwind-tables`. `CheckVacopy` (copied unchanged from `GuestStdioVariadic.cpp`, with stubs for the two unrelated helpers that file's object needs) passes; against `main`'s `RuntimeSupport.cpp` it fails to link on `_Vacopy_nid_postfix`. The first commit defined `CheckVacopy` but never called it from `main`, so in the Release build the checks were dropped and `guest_stdio_variadic` passed without them (found in review); `main` now calls it. Built with the CI flags (`-O3 -DNDEBUG -Wall`), the test object now references `_Vacopy_nid_postfix` and has no unused-function warning, and an implementation that copies bytes 0-15 before bytes 16-23 makes `CheckVacopy` abort. Against the console code itself: I mapped that `libc.prx`'s segments into memory, applied its relocations and called its `_Vacopy` through a System V function pointer beside this one. For 200,000 random 24-byte lists, half at a random alignment, with the destination 8 bytes above the source, 8 bytes below it, or clear of it, the destination and the surrounding bytes were identical in every case. `tools/check_conventions.py --base origin/main` passes. `tools/pr_overlap.py --branch feat/libc-vacopy` reports no overlap. It could not compare #5021, #7201 and #7648 (each conflicts with `main`); I checked them by hand: all three change `RuntimeSupport.cpp` at line 112 or later, where this inserts at line 94, and none adds this export. Not tested on Linux; no title was run. ### 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] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-20 17:44:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-20T17:44:15Z.


Progress report (2abfb1b → 3b426ed)

📈 System libraries: 49.67% (+0.01%, +1 implemented functions)

✅ 1 implemented
Library Name
libc _Vacopy_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6297302037 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8593#issuecomment-6297302037). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-20T17:44:15Z. --- <!-- progress-report --> ### Progress report (2abfb1b → 3b426ed) 📈 **System libraries**: 49.67% (+0.01%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libc | `_Vacopy_nid_postfix` | </details>
nikowolf123 commented 2026-10-20 19:04:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by nikowolf123 on 2026-10-20T19:04:29Z.


CheckVacopy() is defined at core/libs/tests/GuestStdioVariadic.cpp#L90, but main() never calls it, so none of the three _Vacopy checks run. guest_stdio_variadic passes whether _Vacopy_nid_postfix is right or wrong. For example, an implementation that copies bytes 0-15 before bytes 16-23 would still pass.

CI builds in the Release configuration (build.yml#L40). There, GCC drops the unused static functions, so the test binary doesn't reference _Vacopy_nid_postfix at all and would link and pass even without it. With g++ 15.2 (MinGW-w64) at -O3 -DNDEBUG -Wall I get warning: 'void CheckVacopy()' defined but not used [-Wunused-function], and nm on the object lists no _Vacopy_nid_postfix, CheckVacopy or SumThroughCopy.

Calling it before return 0; at L144 fixes this:

    Require(ScanWideSized(u"abcdef", u"%ls", letters, 4u) == 0 && letters[0] == 0, "vswscanf_s rejects a too small buffer");
    CheckVacopy();
    return 0;
}

The checks themselves look right. I built a small harness that only calls CheckVacopy(). Your implementation passes. With the two copies swapped, it aborts with failed: _Vacopy copies the overflow area before the offsets.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6298902624 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8593#issuecomment-6298902624). Originally posted by [nikowolf123](https://github.com/nikowolf123) on 2026-10-20T19:04:29Z. --- `CheckVacopy()` is defined at [core/libs/tests/GuestStdioVariadic.cpp#L90](https://github.com/boykopovar/AnyPS5/blob/abc07a1192c0bed708fc71a4e1f68f309dbffb2b/core/libs/tests/GuestStdioVariadic.cpp#L90), but `main()` never calls it, so none of the three `_Vacopy` checks run. `guest_stdio_variadic` passes whether `_Vacopy_nid_postfix` is right or wrong. For example, an implementation that copies bytes 0-15 before bytes 16-23 would still pass. CI builds in the Release configuration ([build.yml#L40](https://github.com/boykopovar/AnyPS5/blob/abc07a1192c0bed708fc71a4e1f68f309dbffb2b/.github/workflows/build.yml#L40)). There, GCC drops the unused static functions, so the test binary doesn't reference `_Vacopy_nid_postfix` at all and would link and pass even without it. With g++ 15.2 (MinGW-w64) at `-O3 -DNDEBUG -Wall` I get `warning: 'void CheckVacopy()' defined but not used [-Wunused-function]`, and `nm` on the object lists no `_Vacopy_nid_postfix`, `CheckVacopy` or `SumThroughCopy`. Calling it before `return 0;` at [L144](https://github.com/boykopovar/AnyPS5/blob/abc07a1192c0bed708fc71a4e1f68f309dbffb2b/core/libs/tests/GuestStdioVariadic.cpp#L144) fixes this: ```cpp Require(ScanWideSized(u"abcdef", u"%ls", letters, 4u) == 0 && letters[0] == 0, "vswscanf_s rejects a too small buffer"); CheckVacopy(); return 0; } ``` The checks themselves look right. I built a small harness that only calls `CheckVacopy()`. Your implementation passes. With the two copies swapped, it aborts with `failed: _Vacopy copies the overflow area before the offsets`.
priyanshrv-netizen commented 2026-10-21 10:20:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by priyanshrv-netizen on 2026-10-21T10:20:09Z.


You're right, thanks. I wrote CheckVacopy() but never added the call to main(), and my local check ran it from a separate driver, so I missed that the test binary never used it. I reproduced what you saw: with -O3 -DNDEBUG -Wall the object warns 'void CheckVacopy()' defined but not used and has no _Vacopy_nid_postfix reference.

Fixed in 3b426ed: main() calls CheckVacopy() before return 0;, as you suggested. With the same flags the warning is gone and the object references _Vacopy_nid_postfix. With the two copies swapped, it aborts with failed: _Vacopy copies the overflow area before the offsets, and with this implementation it passes. I also corrected the Tested section of the description.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6313612825 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8593#issuecomment-6313612825). Originally posted by [priyanshrv-netizen](https://github.com/priyanshrv-netizen) on 2026-10-21T10:20:09Z. --- You're right, thanks. I wrote `CheckVacopy()` but never added the call to `main()`, and my local check ran it from a separate driver, so I missed that the test binary never used it. I reproduced what you saw: with `-O3 -DNDEBUG -Wall` the object warns `'void CheckVacopy()' defined but not used` and has no `_Vacopy_nid_postfix` reference. Fixed in 3b426ed: `main()` calls `CheckVacopy()` before `return 0;`, as you suggested. With the same flags the warning is gone and the object references `_Vacopy_nid_postfix`. With the two copies swapped, it aborts with `failed: _Vacopy copies the overflow area before the offsets`, and with this implementation it passes. I also corrected the Tested section of the description.
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!8593
No description provided.