feat(libkernel): read and set the GS base through sysarch #7095

Merged
milescoviello merged 2 commits from upstream-pr/7095 into main 2026-10-17 22:18:15 +00:00
milescoviello commented 2026-10-17 11:16:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-17T11:16:38Z.


What

#6028 exports sysarch as a throwing declaration so modules that import it load. Forever Launcher's Wine (PPSA99030) now calls it: amd64_set_gsbase (sysarch(AMD64_SET_GSBASE, &base)) to point GS at its TEB. This PR implements the three operations that are safe here, following FreeBSD 11's amd64 sysarch, on Linux x86-64 hosts through the host's arch_prctl:

  • AMD64_SET_GSBASE (131) sets the calling thread's GS base. A base at or above 0x800000000000 (VM_MAXUSER_ADDRESS) returns EINVAL, and a null argument returns EFAULT. Nothing on the host side uses GS on Linux x86-64.
  • AMD64_GET_GSBASE (130) and AMD64_GET_FSBASE (128) copy the base out, with the same EFAULT.
  • Still throws:
    • AMD64_SET_FSBASE: guest and host code share the thread's FS base for their TLS.
    • The other operations.
    • Any operation on other hosts (Windows keeps its TEB in GS).

The implementation moves from Unimplemented.cpp to System/src/Process.cpp, and docs/dev/debt/libkernel.md gets an entry.

Tested

Ubuntu 24.04, GCC 13.3, Release, on #6028's head fb0f83ddf5.

  • guest_sysarch now checks the operations on Linux x86-64:
    • Setting GS to a buffer reads back through AMD64_GET_GSBASE and through %gs:0. The FS base read back equals %fs:0's self pointer.
    • A base of 0x800000000000 returns EINVAL and leaves the base unchanged, and null arguments return EFAULT.
    • Operation 129 (AMD64_SET_FSBASE) and operation 7 throw.
    • With #6028's sources it aborts, because the old declaration throws for every operation. It passes 3 of 3.
  • ctest -R '^guest_|libc': 383 of 383 pass, on #6028's base.
  • Forever Launcher (PPSA99030, 01.000.012), 60 s with pad input. I ran it on main with the PRs for its earlier stops merged locally: #6915, #6028, #6939, #6787, #7070, #6469, #7090 and #7092.
    • In gdb, the call is operation 131 with base 0x7ffc0000; the host GS base was 0 before it.
    • Without this PR it stops 1 s in on sysarch not implemented, 2 of 2.
    • With it, it runs to the limit 2 of 2 with no stop. Wine's in-process wineserver starts and runs the program until Wine reports failed to open "C:\\windows\\system32\\wineboot.exe" and exits with STATUS_DLL_NOT_FOUND. The launcher says the prefix "must be initialized by payload Wine", a separate payload that isn't part of the title, and its UI keeps running.

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: #6028 (this branch is stacked on it; its first commit is #6028's)
  • Fixes: none
  • Unblocks: PPSA99030 (Forever Launcher), with the PRs listed under Tested; no bring-up discussion exists yet
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4899602859 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7095). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-17T11:16:38Z. --- ### What #6028 exports `sysarch` as a throwing declaration so modules that import it load. Forever Launcher's Wine (PPSA99030) now calls it: `amd64_set_gsbase` (`sysarch(AMD64_SET_GSBASE, &base)`) to point GS at its TEB. This PR implements the three operations that are safe here, following FreeBSD 11's amd64 [`sysarch`](https://github.com/freebsd/freebsd-src/blob/release/11.0.0/sys/amd64/amd64/sys_machdep.c), on Linux x86-64 hosts through the host's `arch_prctl`: - **`AMD64_SET_GSBASE` (131)** sets the calling thread's GS base. A base at or above `0x800000000000` (`VM_MAXUSER_ADDRESS`) returns `EINVAL`, and a null argument returns `EFAULT`. Nothing on the host side uses GS on Linux x86-64. - **`AMD64_GET_GSBASE` (130)** and **`AMD64_GET_FSBASE` (128)** copy the base out, with the same `EFAULT`. - **Still throws:** - `AMD64_SET_FSBASE`: guest and host code share the thread's FS base for their TLS. - The other operations. - Any operation on other hosts (Windows keeps its TEB in GS). The implementation moves from `Unimplemented.cpp` to `System/src/Process.cpp`, and `docs/dev/debt/libkernel.md` gets an entry. ### Tested Ubuntu 24.04, GCC 13.3, Release, on #6028's head fb0f83ddf5. - **`guest_sysarch` now checks the operations on Linux x86-64:** - Setting GS to a buffer reads back through `AMD64_GET_GSBASE` and through `%gs:0`. The FS base read back equals `%fs:0`'s self pointer. - A base of `0x800000000000` returns `EINVAL` and leaves the base unchanged, and null arguments return `EFAULT`. - Operation 129 (`AMD64_SET_FSBASE`) and operation 7 throw. - With #6028's sources it aborts, because the old declaration throws for every operation. It passes 3 of 3. - `ctest -R '^guest_|libc'`: 383 of 383 pass, on #6028's base. - **Forever Launcher (PPSA99030, 01.000.012)**, 60 s with pad input. I ran it on `main` with the PRs for its earlier stops merged locally: #6915, #6028, #6939, #6787, #7070, #6469, #7090 and #7092. - In gdb, the call is operation 131 with base 0x7ffc0000; the host GS base was 0 before it. - Without this PR it stops 1 s in on `sysarch not implemented`, 2 of 2. - With it, it runs to the limit 2 of 2 with no stop. Wine's in-process wineserver starts and runs the program until Wine reports `failed to open "C:\\windows\\system32\\wineboot.exe"` and exits with `STATUS_DLL_NOT_FOUND`. The launcher says the prefix "must be initialized by payload Wine", a separate payload that isn't part of the title, and its UI keeps running. ### 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: #6028 (this branch is stacked on it; its first commit is #6028's) - [x] Fixes: none - [x] Unblocks: PPSA99030 (Forever Launcher), with the PRs listed under Tested; no bring-up discussion exists yet - [x] GPUs tested: n/a - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-17 11:17:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-17T11:17:21Z.


Progress report (3e83446 → d7c83db)

📉 System libraries: 89.62% (-0.03%, +1 declared functions)

🆕 1 declared as stubs
Library Name
libkernel sysarch
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6233257454 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7095#issuecomment-6233257454). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-17T11:17:21Z. --- <!-- progress-report --> ### Progress report (3e83446 → d7c83db) 📉 **System libraries**: 89.62% (-0.03%, +1 declared functions) <details> <summary>🆕 1 declared as stubs</summary> | Library | Name | | - | - | | libkernel | `sysarch` | </details>
github-actions[bot] commented 2026-10-17 11:27:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-17T11:27:34Z.


Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 4630 docs/dev/debt/libkernel.md
PR 4972 core/libs/prx/libkernel/CMakeLists.txt
PR 5021 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/System/src/Process.cpp
docs/dev/debt/libkernel.md
PR 6044 core/libs/prx/libkernel/CMakeLists.txt
PR 6222 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/System/src/Process.cpp
docs/dev/debt/libkernel.md
PR 6287 core/libs/prx/libkernel/CMakeLists.txt
PR 6447 core/libs/prx/libkernel/System/src/Process.cpp
PR 6510 docs/dev/debt/libkernel.md
PR 6710 docs/dev/debt/libkernel.md
PR 6836 docs/dev/debt/libkernel.md
PR 6908 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 6942 core/libs/prx/libkernel/CMakeLists.txt
PR 6962 docs/dev/debt/libkernel.md
PR 7049 docs/dev/debt/libkernel.md
PR 7075 docs/dev/debt/libkernel.md
PR 7088 docs/dev/debt/libkernel.md
PR 7121 docs/dev/debt/libkernel.md
PR 7129 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 7135 docs/dev/debt/libkernel.md
PR 7139 docs/dev/debt/libkernel.md
PR 7201 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/System/src/Process.cpp
PR 7248 docs/dev/debt/libkernel.md
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6233344262 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7095#issuecomment-6233344262). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-17T11:27:34Z. --- <!-- pr-overlap --> Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 4630](https://www.github.com/boykopovar/AnyPS5/pull/4630) | `docs/dev/debt/libkernel.md` | | [PR 4972](https://www.github.com/boykopovar/AnyPS5/pull/4972) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/prx/libkernel/CMakeLists.txt`<br>`core/libs/prx/libkernel/System/src/Process.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 6222](https://www.github.com/boykopovar/AnyPS5/pull/6222) | `core/libs/prx/libkernel/CMakeLists.txt`<br>`core/libs/prx/libkernel/System/src/Process.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 6287](https://www.github.com/boykopovar/AnyPS5/pull/6287) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 6447](https://www.github.com/boykopovar/AnyPS5/pull/6447) | `core/libs/prx/libkernel/System/src/Process.cpp` | | [PR 6510](https://www.github.com/boykopovar/AnyPS5/pull/6510) | `docs/dev/debt/libkernel.md` | | [PR 6710](https://www.github.com/boykopovar/AnyPS5/pull/6710) | `docs/dev/debt/libkernel.md` | | [PR 6836](https://www.github.com/boykopovar/AnyPS5/pull/6836) | `docs/dev/debt/libkernel.md` | | [PR 6908](https://www.github.com/boykopovar/AnyPS5/pull/6908) | `core/libs/prx/libkernel/CMakeLists.txt`<br>`docs/dev/debt/libkernel.md` | | [PR 6942](https://www.github.com/boykopovar/AnyPS5/pull/6942) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 6962](https://www.github.com/boykopovar/AnyPS5/pull/6962) | `docs/dev/debt/libkernel.md` | | [PR 7049](https://www.github.com/boykopovar/AnyPS5/pull/7049) | `docs/dev/debt/libkernel.md` | | [PR 7075](https://www.github.com/boykopovar/AnyPS5/pull/7075) | `docs/dev/debt/libkernel.md` | | [PR 7088](https://www.github.com/boykopovar/AnyPS5/pull/7088) | `docs/dev/debt/libkernel.md` | | [PR 7121](https://www.github.com/boykopovar/AnyPS5/pull/7121) | `docs/dev/debt/libkernel.md` | | [PR 7129](https://www.github.com/boykopovar/AnyPS5/pull/7129) | `core/libs/prx/libkernel/CMakeLists.txt`<br>`docs/dev/debt/libkernel.md` | | [PR 7135](https://www.github.com/boykopovar/AnyPS5/pull/7135) | `docs/dev/debt/libkernel.md` | | [PR 7139](https://www.github.com/boykopovar/AnyPS5/pull/7139) | `docs/dev/debt/libkernel.md` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libkernel/CMakeLists.txt`<br>`core/libs/prx/libkernel/System/src/Process.cpp` | | [PR 7248](https://www.github.com/boykopovar/AnyPS5/pull/7248) | `docs/dev/debt/libkernel.md` |
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!7095
No description provided.