feat(libc): read guest va_lists portably in lifted builds #15801

Closed
oberonlift wants to merge 20 commits from upstream-pr/15801 into main
oberonlift commented 2026-11-04 16:23:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oberonlift on 2026-11-04T16:23:58Z.


Merge after #15800. Until the PRs before it merge, this PR also shows their changes; oberonlift/AnyPS5#11 shows only its own.

ps5lift is a static recompiler for PS5 executables: it lifts a game's x86-64 code to LLVM IR and compiles it ahead of time to aarch64, which runs on Linux against AnyPS5's own libraries with no interpreter or JIT. It runs AnyPS5's PS5-style test programs and a homebrew media player to its home screen; commercial games are not playable yet. Branch ps5lift-preview merges all of its PRs (how to try it); native Apple Silicon support is coming along fast. It is a separate approach from the ARM64 compiler in #5021; #1835 has an introduction.

This is 5 of 8 PRs that let AnyPS5's libraries run a lifted program; the lifter itself follows them.

x86-64: behaviour unchanged. The shared APS5_VA_BEGIN macro expands to the code it replaces, Audio3d's delivery loop moved into a helper, and the host-list handling in FormatArguments, the AudioPropagation change and AvPlayer's log printer are compiled only in lifted builds.

What

  • In a lifted build every VaList is a SysV va_list built by the guest or by a bridge, so libc formats and scans through FormatArguments and its in-process scanner instead of the host's vprintf and vsscanf.
  • libc's own variadic functions wrap the host va_list in a tagged VaList through the shared APS5_VA_BEGIN macro, which libSceLibcInternal's err and warn and the formatting and scanning tests now use as well.
  • libSceAudio3d hands a report handler, which is guest code, a SysV va_list built around the call's values. It copied its own host va_list, which has that layout only on an x86-64 host.
  • In lifted builds libSceAudioPropagation's sceAudioPropagationReportApi, which copies its own host va_list into the report, stops as not implemented when host code calls it; guest calls stop at the bridge. The debt file lists it, and the library's test checks the rejection in lifted builds in place of its report checks, which read the report's va_list as the host's.
  • libSceAvPlayer.native's sceAvPlayerPrintf starts its va_list with APS5_VA_BEGIN, and without a registered callback a lifted build prints the log through the libc's vprintf, which reads a guest va_list. It copied the VaList as a host va_list, which has that layout only on an x86-64 host.
  • In lifted builds vasprintf formats through FormatWindows, as Windows builds do, so it reads only the guest's 24-byte VaList; and printf_s orients stdout for bytes, as the other builds' printf_s does.

#5021 also changes some of the same files: Formatting.cpp, WindowsFormatting.hpp.

Tested

Compiled for x86-64 Linux before and after this PR (GCC 13, same flags): 19 of the 24 objects it reaches on both sides are byte-identical; the others are libSceAudio3d's Export.cpp, whose delivery loop moved into a helper, the two libc tests that gained checks, and AudioPropagation's Export.cpp and libSceLibcInternal's Err.cpp, which differ only in line-number constants.

On a DGX Spark (aarch64 Linux, NVIDIA GB10, LLVM 18), with all eight PRs and ps5lift on top: every library builds for a lifted program, 2,285 of AnyPS5's own tests pass in that build on lavapipe, and ps5lift's 69 tests pass, among them its libc, exceptions, kernel, fiber and module-loading fixtures and upstream's libc test programs.

The conventions check passes on this branch.

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

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5157734849 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15801). Originally posted by [oberonlift](https://github.com/oberonlift) on 2026-11-04T16:23:58Z. --- **Merge after #15800.** Until the PRs before it merge, this PR also shows their changes; oberonlift/AnyPS5#11 shows only its own. **ps5lift** is a static recompiler for PS5 executables: it lifts a game's x86-64 code to LLVM IR and compiles it ahead of time to aarch64, which runs on Linux against AnyPS5's own libraries with no interpreter or JIT. It runs AnyPS5's PS5-style test programs and a homebrew media player to its home screen; commercial games are not playable yet. Branch [`ps5lift-preview`](https://github.com/oberonlift/AnyPS5/tree/ps5lift-preview) merges all of its PRs ([how to try it](https://github.com/oberonlift/AnyPS5/blob/ps5lift-preview/PS5LIFT_PREVIEW.md)); native Apple Silicon support is coming along fast. It is a separate approach from the ARM64 compiler in #5021; #1835 has an introduction. This is 5 of 8 PRs that let AnyPS5's libraries run a lifted program; the lifter itself follows them. **x86-64:** behaviour unchanged. The shared `APS5_VA_BEGIN` macro expands to the code it replaces, Audio3d's delivery loop moved into a helper, and the host-list handling in `FormatArguments`, the AudioPropagation change and AvPlayer's log printer are compiled only in lifted builds. ### What - In a lifted build every `VaList` is a SysV `va_list` built by the guest or by a bridge, so libc formats and scans through `FormatArguments` and its in-process scanner instead of the host's `vprintf` and `vsscanf`. - libc's own variadic functions wrap the host `va_list` in a tagged `VaList` through the shared `APS5_VA_BEGIN` macro, which libSceLibcInternal's `err` and `warn` and the formatting and scanning tests now use as well. - libSceAudio3d hands a report handler, which is guest code, a SysV `va_list` built around the call's values. It copied its own host `va_list`, which has that layout only on an x86-64 host. - In lifted builds libSceAudioPropagation's `sceAudioPropagationReportApi`, which copies its own host `va_list` into the report, stops as not implemented when host code calls it; guest calls stop at the bridge. The debt file lists it, and the library's test checks the rejection in lifted builds in place of its report checks, which read the report's `va_list` as the host's. - libSceAvPlayer.native's `sceAvPlayerPrintf` starts its `va_list` with `APS5_VA_BEGIN`, and without a registered callback a lifted build prints the log through the libc's `vprintf`, which reads a guest `va_list`. It copied the `VaList` as a host `va_list`, which has that layout only on an x86-64 host. - In lifted builds `vasprintf` formats through `FormatWindows`, as Windows builds do, so it reads only the guest's 24-byte `VaList`; and `printf_s` orients stdout for bytes, as the other builds' `printf_s` does. #5021 also changes some of the same files: `Formatting.cpp`, `WindowsFormatting.hpp`. ### Tested Compiled for x86-64 Linux before and after this PR (GCC 13, same flags): 19 of the 24 objects it reaches on both sides are byte-identical; the others are libSceAudio3d's `Export.cpp`, whose delivery loop moved into a helper, the two libc tests that gained checks, and AudioPropagation's `Export.cpp` and libSceLibcInternal's `Err.cpp`, which differ only in line-number constants. On a DGX Spark (aarch64 Linux, NVIDIA GB10, LLVM 18), with all eight PRs and ps5lift on top: every library builds for a lifted program, 2,285 of AnyPS5's own tests pass in that build on lavapipe, and ps5lift's 69 tests pass, among them its libc, exceptions, kernel, fiber and module-loading fixtures and upstream's libc test programs. The conventions check passes on this branch. ### 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](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: #15800 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)

Pull request closed

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!15801
No description provided.