feat(libkernel): maintain per-thread guest GS bases on Windows #11624

Merged
Felipebmaitan merged 14 commits from upstream-pr/11624 into main 2026-11-04 17:35:53 +00:00
Felipebmaitan commented 2026-10-26 23:19:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Felipebmaitan on 2026-10-26T23:19:30Z.


What

Maintain a libc-owned software GS base per Windows guest thread without changing the host GS/TEB. Implement sysarch GS operations 9, 130 and 131 with guest-pointer/error handling, and capture the creator's base for pthread_create/scePthreadCreate. Windows FS operations remain explicit NotImplemented paths; initial console GS state and native host-created thread inheritance remain unverified as recorded in libkernel debt.

Nov 3 refresh at a0cea872942f2da087f8f8074ce9721ad408491c merges main 1e658521a0a599872612bb91949311e2956b5283 through the existing stack, retaining every fetched maintainer commit. Restore main's shared GuestCopyIn/Out calls in sysarch; this removes the unintended local-copy diagnostic/Windows-write divergence. GS branches, EFAULT/EINVAL handling, four-byte i386 output, FS NotImplemented behavior and operation diagnostics remain. This addresses XairRrR's optional, nonblocking suggestion, not a new blocking review demand.

Entry-stub bounds/RVA checks, #11090 guards, cached metadata registration/unload behavior, borrowed-span fallback and the VEX OS-enabled-AVX policy/--no-avx regression survive. Both GS continuation and main call-tracing debt entries are preserved.

Tested

Fresh Nov 3 checks: macOS arm64 Release relinker-only passes at each exact dependent head (scalar 42/42; short, SSE and VEX 43/43), including GS, entry-root/bounds, TLS and load regressions. Production libc/libkernel components are built separately on Linux amd64 under macOS translation with an external CMake harness; all five exact heads pass six production tests each: guest_sysarch, guest_thread_self, guest_pthread_frame_chain, guest_pthread_join_detach, guest_pthread_start and guest_pthread_attr. Relinker-only checks are not production Windows execution.

The prior heads' completed executable checks passed; cancelled metadata runs are not new failures. B-Howell's independent native Windows report covers old state head e0576a2c1c merged onto b28bb77217: six tests x3, plus a failing main-production control. It is third-party prior-head evidence, not a rerun of the refreshed heads. The old sysarch failure is addressed. Previous translated-Windows red-zone/DLL-lock limits and physical non-AVX-host limits remain; no new hardware, console/title or performance claim is made.

Conventions and diff whitespace checks pass against pinned current main. Overlap scan rerun remains fail-closed for conflicting peer branches; no overlap-clear claim or repeated no-change overlap comment is made. #10518 remains open and declared; #10861 is owned separately and its branch was not modified. Fresh upstream native Windows/full production checks and re-review remain required after this push.

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

Full selected-chain CI dispatch was attempted after pushing and returned HTTP 403: admin rights required. A collaborator can dispatch build.yml on main with pr=11624 11628 11661 11689 11698, full=true, select=true. Fresh hosted checks are distinct from prior-head successful checks.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5026105095 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11624). Originally posted by [Felipebmaitan](https://github.com/Felipebmaitan) on 2026-10-26T23:19:30Z. --- ### What Maintain a libc-owned software GS base per Windows guest thread without changing the host GS/TEB. Implement sysarch GS operations 9, 130 and 131 with guest-pointer/error handling, and capture the creator's base for pthread_create/scePthreadCreate. Windows FS operations remain explicit NotImplemented paths; initial console GS state and native host-created thread inheritance remain unverified as recorded in libkernel debt. Nov 3 refresh at `a0cea872942f2da087f8f8074ce9721ad408491c` merges main `1e658521a0a599872612bb91949311e2956b5283` through the existing stack, retaining every fetched maintainer commit. Restore main's shared GuestCopyIn/Out calls in sysarch; this removes the unintended local-copy diagnostic/Windows-write divergence. GS branches, EFAULT/EINVAL handling, four-byte i386 output, FS NotImplemented behavior and operation diagnostics remain. This addresses XairRrR's optional, nonblocking suggestion, not a new blocking review demand. Entry-stub bounds/RVA checks, #11090 guards, cached metadata registration/unload behavior, borrowed-span fallback and the VEX OS-enabled-AVX policy/--no-avx regression survive. Both GS continuation and main call-tracing debt entries are preserved. ### 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. --> Fresh Nov 3 checks: macOS arm64 Release relinker-only passes at each exact dependent head (scalar 42/42; short, SSE and VEX 43/43), including GS, entry-root/bounds, TLS and load regressions. Production libc/libkernel components are built separately on Linux amd64 under macOS translation with an external CMake harness; all five exact heads pass six production tests each: guest_sysarch, guest_thread_self, guest_pthread_frame_chain, guest_pthread_join_detach, guest_pthread_start and guest_pthread_attr. Relinker-only checks are not production Windows execution. The prior heads' completed executable checks passed; cancelled metadata runs are not new failures. [B-Howell's independent native Windows report](https://github.com/boykopovar/AnyPS5/pull/11624#issuecomment-6586779919) covers old state head e0576a2c1c merged onto b28bb77217: six tests x3, plus a failing main-production control. It is third-party prior-head evidence, not a rerun of the refreshed heads. The old sysarch failure is addressed. Previous translated-Windows red-zone/DLL-lock limits and physical non-AVX-host limits remain; no new hardware, console/title or performance claim is made. Conventions and diff whitespace checks pass against pinned current main. Overlap scan rerun remains fail-closed for conflicting peer branches; no overlap-clear claim or repeated no-change overlap comment is made. #10518 remains open and declared; #10861 is owned separately and its branch was not modified. Fresh upstream native Windows/full production checks and re-review remain required after this push. ### 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: <!-- #PR, or none --> none - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes Full selected-chain CI dispatch was attempted after pushing and returned HTTP 403: admin rights required. A collaborator can dispatch build.yml on main with `pr=11624 11628 11661 11689 11698`, `full=true`, `select=true`. Fresh hosted checks are distinct from prior-head successful checks.
MarcZX10 commented 2026-10-26 23:35:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T23:35:23Z.

Review: APPROVED


Reviewed exact head 3effed87cbc5135fcc392db3c4a60b856b4d387f. Windows GS values are stored in a dedicated HostThreadSlot and never replace the host TEB/GS base; both guest pthread creation paths snapshot and install the creator’s value. The sysarch paths validate guest pointers and address bounds, keep FS unsupported on Windows, and write only four bytes for operation 9. The tests cover error paths, inheritance, thread-local mutation and nested inheritance. Hosted conventions, eligibility, intake, labels, register-context, relinker, ASan and write-watch checks pass; product build jobs are path-skipped. The author reports fresh Windows and WSL component builds and four runtime tests on each host; I did not independently rerun those local tests. I found no blocking issue.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5660512153 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11624#pullrequestreview-5660512153). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-26T23:35:23Z. **Review:** APPROVED --- Reviewed exact head `3effed87cbc5135fcc392db3c4a60b856b4d387f`. Windows GS values are stored in a dedicated `HostThreadSlot` and never replace the host TEB/GS base; both guest pthread creation paths snapshot and install the creator’s value. The sysarch paths validate guest pointers and address bounds, keep FS unsupported on Windows, and write only four bytes for operation 9. The tests cover error paths, inheritance, thread-local mutation and nested inheritance. Hosted conventions, eligibility, intake, labels, register-context, relinker, ASan and write-watch checks pass; product build jobs are path-skipped. The author reports fresh Windows and WSL component builds and four runtime tests on each host; I did not independently rerun those local tests. I found no blocking issue.
XairRrR commented 2026-10-29 12:07:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-29T12:07:36Z.

Review: COMMENTED


Reviewed — comments

The merged tree builds and the sysarch and pthread tests pass on Linux, and the updated guest_sysarch test fails against main's production code. I could not build or run the Windows code, which is what this PR adds, so I am leaving a comment rather than an approval; I found nothing blocking.

What I ran

Head fa743e6e99f1a3f9ce6ba5d66a0a5638c0d62b5d, main ba5b5330b37724bca4b99f30faab504653635a04, merged with --no-ff in a clean worktree (Release, GCC 16.2.1, Ninja). Host: Arch Linux 7.2.11-zen, Intel Core i9-14900KF.

git merge --no-ff --no-edit refs/review/11624            # clean
git diff --check origin/main...refs/review/11624
python3 tools/check_conventions.py --base origin/main
cmake --build build -j10 --target libs guest_sysarch_tests guest_thread_self_tests \
    guest_pthread_frame_chain_tests guest_pthread_join_detach_tests
ctest --test-dir build -j4 --output-on-failure \
    -R '^(guest_sysarch|guest_thread_self|guest_pthread_frame_chain|guest_pthread_join_detach)$'
ctest --test-dir build --repeat until-fail:50 -R '^guest_sysarch$'
# negative control
git checkout origin/main -- core/libs/prx/libkernel/System/src/Process.cpp \
    core/libs/prx/libkernel/Pthread/src/Thread.cpp core/libs/prx/libc/CMakeLists.txt
git rm core/libs/prx/libc/include/GuestGs.hpp core/libs/prx/libc/src/specifics/windows/GuestGs.cpp
cmake --build build -j10 --target guest_sysarch_tests
ctest --test-dir build --output-on-failure -R '^guest_sysarch$'

Results

Check Result
Merge into main clean
git diff --check no output
check_conventions.py All conventions checks passed.
Build of libs and the four test targets OK
guest_sysarch, guest_thread_self, guest_pthread_frame_chain, guest_pthread_join_detach 4/4 passed, each under 0.1 s
guest_sysarch repeated 50 times 50/50 passed, 0.42 s in total
Negative control guest_sysarch fails (SEGFAULT)
ctest, merged tree
1/4 Test #2442: guest_pthread_frame_chain ........   Passed    0.00 sec
2/4 Test #2434: guest_thread_self ................   Passed    0.00 sec
3/4 Test #2537: guest_sysarch ....................   Passed    0.00 sec
4/4 Test #2447: guest_pthread_join_detach ........   Passed    0.06 sec

100% tests passed out of 4

Negative control

I reverted only the production files (Process.cpp, Thread.cpp and the libc CMakeLists.txt to main, and removed GuestGs.hpp/GuestGs.cpp), kept the new test, and rebuilt. guest_sysarch then fails with a SEGFAULT: main copies with memcpy, so the new sysarch(131/130/9, (void*)1) checks crash where they should return EFAULT. With the merged files restored, it passes again.

ctest, production files from main
0% tests passed, 1 tests failed out of 1
The following tests FAILED:
	2537 - guest_sysarch (SEGFAULT)

Findings

Blocking

None.

Non-blocking

  1. The debt rewrite drops sources and detail that are still accurate. The single sysarch entry on main (docs/dev/debt/libkernel.md#L220) becomes three entries (L213-L215 at the head). The rewrite loses:

    • the Linux copy_thread link, which backs the statement that Linux guest threads inherit the creator's GS base;
    • the link to FreeBSD's sysarch default case, which backs the EINVAL behaviour for numbers it does not handle;
    • the note that 6 is I386_VM86;
    • the (libkernel) tag that the other entries in the file carry.

    CONTRIBUTING.md asks PRs to cut an entry to what is still open instead of rewriting it. Suggested fix: keep main's entry and edit only the clauses that change on Windows (GS get/set, operation 9 and inheritance through both pthread APIs). Put the Windows-only gaps (initial base of zero, threads created natively by the host, GS memory instructions still trapping) in a separate entry.

  2. The debt text says Windows FS reads throw, but a null argument returns EFAULT. The new entry says sysarch "throws for SET_FSBASE and Windows GET_FSBASE/I386_GET_FSBASE". In Process.cpp#L1000-L1003, however, the null check runs before the Windows FS refusal at L1023. So on Windows, sysarch(128, nullptr) and sysarch(7, nullptr) return -1/EFAULT, and only a non-null argument throws. That matches the console's measured EFAULT for a null argument to operation 7, so the code is fine. The debt sentence should say that only a non-null argument throws.

  3. Test leftovers. In GuestSysarch.cpp, Linux runs RequireLowHalf(9, base) twice: at line 71 inside the #ifdef __linux__ block and again at line 75. Line 71 can go. Since Thrown was removed, <stdexcept> and <string> (L8-L9) are no longer used.

Not verified

  • The Windows half: GuestGs.cpp and the _WIN32 branches in Thread.cpp and Process.cpp. I have no Windows or MinGW toolchain, so I did not compile or run them. The windows CI job for this head was still running when I wrote this. The author reports Windows component builds and test runs, which I did not reproduce.
  • macOS, which this change does not touch beyond the shared code path.
  • Console behaviour and any title. Neither is claimed.

To get this to a good state

  • Let the windows CI job finish green on this head; it builds libs and runs the selected tests, including guest_sysarch.
  • Optionally, apply the debt-entry edits (1, 2) and the test cleanup (3).
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5697396202 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11624#pullrequestreview-5697396202). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-10-29T12:07:36Z. **Review:** COMMENTED --- # Reviewed — comments The merged tree builds and the sysarch and pthread tests pass on Linux, and the updated `guest_sysarch` test fails against `main`'s production code. I could not build or run the Windows code, which is what this PR adds, so I am leaving a comment rather than an approval; I found nothing blocking. ## What I ran Head `fa743e6e99f1a3f9ce6ba5d66a0a5638c0d62b5d`, `main` `ba5b5330b37724bca4b99f30faab504653635a04`, merged with `--no-ff` in a clean worktree (Release, GCC 16.2.1, Ninja). Host: Arch Linux 7.2.11-zen, Intel Core i9-14900KF. ```sh git merge --no-ff --no-edit refs/review/11624 # clean git diff --check origin/main...refs/review/11624 python3 tools/check_conventions.py --base origin/main cmake --build build -j10 --target libs guest_sysarch_tests guest_thread_self_tests \ guest_pthread_frame_chain_tests guest_pthread_join_detach_tests ctest --test-dir build -j4 --output-on-failure \ -R '^(guest_sysarch|guest_thread_self|guest_pthread_frame_chain|guest_pthread_join_detach)$' ctest --test-dir build --repeat until-fail:50 -R '^guest_sysarch$' # negative control git checkout origin/main -- core/libs/prx/libkernel/System/src/Process.cpp \ core/libs/prx/libkernel/Pthread/src/Thread.cpp core/libs/prx/libc/CMakeLists.txt git rm core/libs/prx/libc/include/GuestGs.hpp core/libs/prx/libc/src/specifics/windows/GuestGs.cpp cmake --build build -j10 --target guest_sysarch_tests ctest --test-dir build --output-on-failure -R '^guest_sysarch$' ``` ## Results | Check | Result | |---|---| | Merge into `main` | clean | | `git diff --check` | no output | | `check_conventions.py` | `All conventions checks passed.` | | Build of `libs` and the four test targets | OK | | `guest_sysarch`, `guest_thread_self`, `guest_pthread_frame_chain`, `guest_pthread_join_detach` | 4/4 passed, each under 0.1 s | | `guest_sysarch` repeated 50 times | 50/50 passed, 0.42 s in total | | Negative control | `guest_sysarch` fails (SEGFAULT) | <details><summary>ctest, merged tree</summary> ``` 1/4 Test #2442: guest_pthread_frame_chain ........ Passed 0.00 sec 2/4 Test #2434: guest_thread_self ................ Passed 0.00 sec 3/4 Test #2537: guest_sysarch .................... Passed 0.00 sec 4/4 Test #2447: guest_pthread_join_detach ........ Passed 0.06 sec 100% tests passed out of 4 ``` </details> ## Negative control I reverted only the production files (`Process.cpp`, `Thread.cpp` and the libc `CMakeLists.txt` to `main`, and removed `GuestGs.hpp`/`GuestGs.cpp`), kept the new test, and rebuilt. `guest_sysarch` then fails with a SEGFAULT: `main` copies with `memcpy`, so the new `sysarch(131/130/9, (void*)1)` checks crash where they should return `EFAULT`. With the merged files restored, it passes again. <details><summary>ctest, production files from main</summary> ``` 0% tests passed, 1 tests failed out of 1 The following tests FAILED: 2537 - guest_sysarch (SEGFAULT) ``` </details> ## Findings ### Blocking None. ### Non-blocking 1. **The debt rewrite drops sources and detail that are still accurate.** The single `sysarch` entry on `main` ([docs/dev/debt/libkernel.md#L220](https://github.com/boykopovar/AnyPS5/blob/ba5b5330b37724bca4b99f30faab504653635a04/docs/dev/debt/libkernel.md#L220)) becomes three entries ([L213-L215 at the head](https://github.com/boykopovar/AnyPS5/blob/fa743e6e99f1a3f9ce6ba5d66a0a5638c0d62b5d/docs/dev/debt/libkernel.md#L213-L215)). The rewrite loses: - the Linux [`copy_thread`](https://github.com/torvalds/linux/blob/v6.6/arch/x86/kernel/process.c#L182-L186) link, which backs the statement that Linux guest threads inherit the creator's GS base; - the link to FreeBSD's `sysarch` default case, which backs the `EINVAL` behaviour for numbers it does not handle; - the note that 6 is `I386_VM86`; - the `(libkernel)` tag that the other entries in the file carry. [CONTRIBUTING.md](https://github.com/boykopovar/AnyPS5/blob/ba5b5330b37724bca4b99f30faab504653635a04/CONTRIBUTING.md#L78) asks PRs to cut an entry to what is still open instead of rewriting it. Suggested fix: keep `main`'s entry and edit only the clauses that change on Windows (GS get/set, operation 9 and inheritance through both pthread APIs). Put the Windows-only gaps (initial base of zero, threads created natively by the host, GS memory instructions still trapping) in a separate entry. 2. **The debt text says Windows FS reads throw, but a null argument returns `EFAULT`.** The new entry says `sysarch` "throws for SET_FSBASE and Windows GET_FSBASE/I386_GET_FSBASE". In [Process.cpp#L1000-L1003](https://github.com/boykopovar/AnyPS5/blob/fa743e6e99f1a3f9ce6ba5d66a0a5638c0d62b5d/core/libs/prx/libkernel/System/src/Process.cpp#L1000-L1003), however, the null check runs before the Windows FS refusal at [L1023](https://github.com/boykopovar/AnyPS5/blob/fa743e6e99f1a3f9ce6ba5d66a0a5638c0d62b5d/core/libs/prx/libkernel/System/src/Process.cpp#L1021-L1024). So on Windows, `sysarch(128, nullptr)` and `sysarch(7, nullptr)` return `-1`/`EFAULT`, and only a non-null argument throws. That matches the console's measured `EFAULT` for a null argument to operation 7, so the code is fine. The debt sentence should say that only a non-null argument throws. 3. **Test leftovers.** In [GuestSysarch.cpp](https://github.com/boykopovar/AnyPS5/blob/fa743e6e99f1a3f9ce6ba5d66a0a5638c0d62b5d/core/libs/tests/GuestSysarch.cpp#L71-L75), Linux runs `RequireLowHalf(9, base)` twice: at line 71 inside the `#ifdef __linux__` block and again at line 75. Line 71 can go. Since `Thrown` was removed, `<stdexcept>` and `<string>` ([L8-L9](https://github.com/boykopovar/AnyPS5/blob/fa743e6e99f1a3f9ce6ba5d66a0a5638c0d62b5d/core/libs/tests/GuestSysarch.cpp#L8-L9)) are no longer used. ## Not verified - The Windows half: `GuestGs.cpp` and the `_WIN32` branches in `Thread.cpp` and `Process.cpp`. I have no Windows or MinGW toolchain, so I did not compile or run them. The `windows` CI job for this head was still running when I wrote this. The author reports Windows component builds and test runs, which I did not reproduce. - macOS, which this change does not touch beyond the shared code path. - Console behaviour and any title. Neither is claimed. ## To get this to a good state - Let the `windows` CI job finish green on this head; it builds `libs` and runs the selected tests, including `guest_sysarch`. - Optionally, apply the debt-entry edits (1, 2) and the test cleanup (3).
XairRrR commented 2026-11-02 20:42:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-02T20:42:12Z.

Review: COMMENTED


Re-checked — comments

The new commits fix all three of my earlier non-blocking points and limit the implemented-FS pointer checks to Linux. The merged tree builds and the focused Linux tests pass. The PR's production change is Windows-only, though, and I still cannot compile or run that code, so this stays a comment. I found nothing blocking.

What changed since my last review

I last reviewed fa743e6e99. Since then:

  • b9bcb27fb9 restores the debt sources and clarifies the Windows FS debt.
  • 3a30abf703 registers the write-watch cases once; it is now absorbed by main and is no longer in the PR diff.
  • e32141a3d8 keeps the EFAULT fallback qualification in the debt entry.
  • 5b93739daa limits the sysarch(7|128, bad) and Linux FS read assertions to __linux__.
  • There are also several merges of main, including 5d736ad55b, which on main moved sysarch to GuestCopyIn/Out_nid_no_patch.
  • In discussion, B-Howell posted a native Windows x86-64 run with a control.

What I ran

Head e0576a2c1c4453e0e4f633f56af48da51c620638, main 9090972b7e91fd266819cbd77a8b058e177b5682, merged with --no-ff (tree 772f201dd4). The machine was Debian 13 (32 vCPU Xeon Gold 6136) with GCC 14.2.0, Release, Ninja.

git diff --check 9090972b7e91fd266819cbd77a8b058e177b5682...e0576a2c1c4453e0e4f633f56af48da51c620638
python3 tools/check_conventions.py --base 9090972b7e91fd266819cbd77a8b058e177b5682
ctest --test-dir build -j8 --test-load 32 --output-on-failure \
  -R '^(guest_sysarch|guest_thread_self|guest_pthread_frame_chain|guest_pthread_join_detach|guest_pthread_start|guest_pthread_attr)$'
# negative control: Process.cpp and Thread.cpp from main; libkernel objects recompiled
# and relinked with the commands from `ninja -t commands guest_sysarch_tests`
# (CMake regeneration is not possible in the sandbox)
git show 9090972b7e:core/libs/prx/libkernel/System/src/Process.cpp > core/libs/prx/libkernel/System/src/Process.cpp
git show 9090972b7e:core/libs/prx/libkernel/Pthread/src/Thread.cpp > core/libs/prx/libkernel/Pthread/src/Thread.cpp
ctest --test-dir build --output-on-failure -R '^guest_sysarch$'
# restored from 772f201dd4, recompiled, git status --porcelain empty, tests rerun
Check Result
git diff --check no output
check_conventions.py All conventions checks passed.
Script build and tests (build.json) build OK; 0 new failures, 0 timeouts; 9 known failures that also fail on main
Focused sysarch and pthread tests 6/6 passed, 1.64 s in total
Negative control on Linux guest_sysarch passes with main's production files (see below)

Negative control. On Linux the test no longer fails against main. That is expected now: main (5d736ad55b) already returns EFAULT for bad pointers, and Linux GS inheritance already comes from the kernel. What the test adds over main only takes effect on Windows. B-Howell reports that on native Windows (Ryzen 7 7800X3D, WinLibs GCC 15.2) guest_sysarch aborts with sysarch: segment bases on this host not implemented when main's Process.cpp and Thread.cpp are used. That is a third-party report; I did not reproduce it.

Previous findings

  1. Debt rewrite dropped sources — Resolved. The entries at libkernel.md#L242-L244 again carry the copy_thread link, the FreeBSD default-case link, I386_VM86 and the (libkernel) tags.
  2. Windows FS null-argument wording — Resolved. The entry now says Windows GET_FSBASE/I386_GET_FSBASE "return EFAULT for null arguments and throw for non-null arguments". That matches Process.cpp:1025-1028 and :1048.
  3. Test leftovers — Resolved. RequireLowHalf(9, base) now runs once (GuestSysarch.cpp:72), and <stdexcept>/<string> are gone.

New findings

Blocking

None.

Non-blocking

  1. The merge resolution undoes main's switch to the shared copy helpers. main's 5d736ad55b made sysarch use GuestCopyIn_nid_no_patch/GuestCopyOut_nid_no_patch (main Process.cpp#L1030, #L1046, #L1052). The PR puts back the file-local ReadGuest/WriteGuest instead (head Process.cpp#L1031, #L1056, #L1062).

    • Both pairs return false for null, overflowing and unmapped pointers, so the tests do not tell them apart.
    • On Linux, though, a non-EFAULT failure now throws an unrelated credentials: process_vm_readv failed message (#L138).
    • On Windows, writes go through WriteProcessMemory, not main's VirtualQuery-checked copy.
    • None of this is needed for the GS feature, and it adds diff against main.

    Suggested fix: keep main's GuestCopyIn/Out_nid_no_patch calls and add only the _WIN32 branches.

Not verified

  • The Windows code this PR adds: GuestGs.cpp and the _WIN32 branches in Thread.cpp and Process.cpp. I have no MinGW toolchain or Windows host, so I did not compile or run them. The native Windows pass and control come from B-Howell's report; the ARM64-VM and translated-host results come from the author's reports.
  • Hosted Windows CI on this head: its result is not in the context.
  • macOS, console behaviour and any title. None of these is claimed.

To get this to a good state

  • Get a green hosted Windows job on this head (a collaborator-dispatched full build with guest_sysarch). With B-Howell's native run, that would cover what I cannot check here.
  • Optionally, keep main's GuestCopyIn/Out_nid_no_patch calls in sysarch (new finding 1).
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5743035432 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11624#pullrequestreview-5743035432). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-11-02T20:42:12Z. **Review:** COMMENTED --- # Re-checked — comments The new commits fix all three of my earlier non-blocking points and limit the implemented-FS pointer checks to Linux. The merged tree builds and the focused Linux tests pass. The PR's production change is Windows-only, though, and I still cannot compile or run that code, so this stays a comment. I found nothing blocking. ## What changed since my last review I last reviewed `fa743e6e99`. Since then: - `b9bcb27fb9` restores the debt sources and clarifies the Windows FS debt. - `3a30abf703` registers the write-watch cases once; it is now absorbed by `main` and is no longer in the PR diff. - `e32141a3d8` keeps the EFAULT fallback qualification in the debt entry. - `5b93739daa` limits the `sysarch(7|128, bad)` and Linux FS read assertions to `__linux__`. - There are also several merges of `main`, including `5d736ad55b`, which on `main` moved `sysarch` to `GuestCopyIn/Out_nid_no_patch`. - In discussion, B-Howell posted a native Windows x86-64 run with a control. ## What I ran Head `e0576a2c1c4453e0e4f633f56af48da51c620638`, `main` `9090972b7e91fd266819cbd77a8b058e177b5682`, merged with `--no-ff` (tree `772f201dd4`). The machine was Debian 13 (32 vCPU Xeon Gold 6136) with GCC 14.2.0, Release, Ninja. ```sh git diff --check 9090972b7e91fd266819cbd77a8b058e177b5682...e0576a2c1c4453e0e4f633f56af48da51c620638 python3 tools/check_conventions.py --base 9090972b7e91fd266819cbd77a8b058e177b5682 ctest --test-dir build -j8 --test-load 32 --output-on-failure \ -R '^(guest_sysarch|guest_thread_self|guest_pthread_frame_chain|guest_pthread_join_detach|guest_pthread_start|guest_pthread_attr)$' # negative control: Process.cpp and Thread.cpp from main; libkernel objects recompiled # and relinked with the commands from `ninja -t commands guest_sysarch_tests` # (CMake regeneration is not possible in the sandbox) git show 9090972b7e:core/libs/prx/libkernel/System/src/Process.cpp > core/libs/prx/libkernel/System/src/Process.cpp git show 9090972b7e:core/libs/prx/libkernel/Pthread/src/Thread.cpp > core/libs/prx/libkernel/Pthread/src/Thread.cpp ctest --test-dir build --output-on-failure -R '^guest_sysarch$' # restored from 772f201dd4, recompiled, git status --porcelain empty, tests rerun ``` | Check | Result | |---|---| | `git diff --check` | no output | | `check_conventions.py` | `All conventions checks passed.` | | Script build and tests (build.json) | build OK; 0 new failures, 0 timeouts; 9 known failures that also fail on `main` | | Focused sysarch and pthread tests | 6/6 passed, 1.64 s in total | | Negative control on Linux | `guest_sysarch` **passes** with `main`'s production files (see below) | **Negative control.** On Linux the test no longer fails against `main`. That is expected now: `main` (`5d736ad55b`) already returns `EFAULT` for bad pointers, and Linux GS inheritance already comes from the kernel. What the test adds over `main` only takes effect on Windows. B-Howell reports that on native Windows (Ryzen 7 7800X3D, WinLibs GCC 15.2) `guest_sysarch` aborts with `sysarch: segment bases on this host not implemented` when `main`'s `Process.cpp` and `Thread.cpp` are used. That is a third-party report; I did not reproduce it. ## Previous findings 1. **Debt rewrite dropped sources** — Resolved. The entries at [libkernel.md#L242-L244](https://github.com/boykopovar/AnyPS5/blob/e0576a2c1c4453e0e4f633f56af48da51c620638/docs/dev/debt/libkernel.md#L242-L244) again carry the `copy_thread` link, the FreeBSD default-case link, `I386_VM86` and the `(libkernel)` tags. 2. **Windows FS null-argument wording** — Resolved. The entry now says Windows `GET_FSBASE`/`I386_GET_FSBASE` "return EFAULT for null arguments and throw for non-null arguments". That matches `Process.cpp:1025-1028` and `:1048`. 3. **Test leftovers** — Resolved. `RequireLowHalf(9, base)` now runs once (`GuestSysarch.cpp:72`), and `<stdexcept>`/`<string>` are gone. ## New findings ### Blocking None. ### Non-blocking 1. **The merge resolution undoes `main`'s switch to the shared copy helpers.** `main`'s `5d736ad55b` made `sysarch` use `GuestCopyIn_nid_no_patch`/`GuestCopyOut_nid_no_patch` ([main Process.cpp#L1030](https://github.com/boykopovar/AnyPS5/blob/9090972b7e91fd266819cbd77a8b058e177b5682/core/libs/prx/libkernel/System/src/Process.cpp#L1030), [#L1046](https://github.com/boykopovar/AnyPS5/blob/9090972b7e91fd266819cbd77a8b058e177b5682/core/libs/prx/libkernel/System/src/Process.cpp#L1046), [#L1052](https://github.com/boykopovar/AnyPS5/blob/9090972b7e91fd266819cbd77a8b058e177b5682/core/libs/prx/libkernel/System/src/Process.cpp#L1052)). The PR puts back the file-local `ReadGuest`/`WriteGuest` instead ([head Process.cpp#L1031](https://github.com/boykopovar/AnyPS5/blob/e0576a2c1c4453e0e4f633f56af48da51c620638/core/libs/prx/libkernel/System/src/Process.cpp#L1031), [#L1056](https://github.com/boykopovar/AnyPS5/blob/e0576a2c1c4453e0e4f633f56af48da51c620638/core/libs/prx/libkernel/System/src/Process.cpp#L1056), [#L1062](https://github.com/boykopovar/AnyPS5/blob/e0576a2c1c4453e0e4f633f56af48da51c620638/core/libs/prx/libkernel/System/src/Process.cpp#L1062)). - Both pairs return false for null, overflowing and unmapped pointers, so the tests do not tell them apart. - On Linux, though, a non-`EFAULT` failure now throws an unrelated `credentials: process_vm_readv failed` message ([#L138](https://github.com/boykopovar/AnyPS5/blob/e0576a2c1c4453e0e4f633f56af48da51c620638/core/libs/prx/libkernel/System/src/Process.cpp#L138)). - On Windows, writes go through `WriteProcessMemory`, not `main`'s `VirtualQuery`-checked copy. - None of this is needed for the GS feature, and it adds diff against `main`. Suggested fix: keep `main`'s `GuestCopyIn/Out_nid_no_patch` calls and add only the `_WIN32` branches. ## Not verified - The Windows code this PR adds: `GuestGs.cpp` and the `_WIN32` branches in `Thread.cpp` and `Process.cpp`. I have no MinGW toolchain or Windows host, so I did not compile or run them. The native Windows pass and control come from B-Howell's report; the ARM64-VM and translated-host results come from the author's reports. - Hosted Windows CI on this head: its result is not in the context. - macOS, console behaviour and any title. None of these is claimed. ## To get this to a good state - Get a green hosted Windows job on this head (a collaborator-dispatched full build with `guest_sysarch`). With B-Howell's native run, that would cover what I cannot check here. - Optionally, keep `main`'s `GuestCopyIn/Out_nid_no_patch` calls in `sysarch` (new finding 1). <!-- anyps5-bots job=1910 head=e0576a2c1c4453e0e4f633f56af48da51c620638 -->
XairRrR commented 2026-11-03 17:52:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T17:52:05Z.

Review: COMMENTED


Re-checked — comments

The new commit a0cea87294 makes sysarch use main's GuestCopyIn/Out_nid_no_patch again, which resolves my one open finding. The checks and the focused Linux tests pass. The production change still only takes effect on Windows, and I cannot compile or run it, so this stays a comment. I found nothing blocking.

What changed since my last review

I last reviewed e0576a2c1c. Since then:

  • 41bbc32070 merges current main.
  • a0cea87294 replaces the three file-local ReadGuest/WriteGuest calls in sysarch with GuestCopyIn_nid_no_patch/GuestCopyOut_nid_no_patch. It changes only Process.cpp, with 3 insertions and 3 deletions.
  • The test file and the debt entry have not changed since my last review.
  • The description was refreshed. The author's new results come from translated and relinker-only hosts, and the description labels them that way.

What I ran

Head a0cea872942f2da087f8f8074ce9721ad408491c, main 1e658521a0a599872612bb91949311e2956b5283, merged with --no-ff (tree c2b6934675). Debian 13, GCC 14.2.0, Release, Ninja.

git show a0cea87294
git diff --check 1e658521a0a599872612bb91949311e2956b5283...a0cea872942f2da087f8f8074ce9721ad408491c
python3 tools/check_conventions.py --base 1e658521a0a599872612bb91949311e2956b5283
ctest --test-dir build -j8 --test-load 32 --output-on-failure \
  -R '^(guest_sysarch|guest_thread_self|guest_pthread_frame_chain|guest_pthread_join_detach|guest_pthread_start|guest_pthread_attr)$'
git diff 1e658521a0a599872612bb91949311e2956b5283 c2b6934675468d3693fc3bfdfb61243bb8955137 --stat
Check Result
git diff --check no output
check_conventions.py All conventions checks passed.
Script build and tests (build.json) build OK; 0 new failures, 0 timeouts; 9 known failures that also fail on main. guest_net_ctl skipped, as on main
Focused sysarch and pthread tests 6/6 passed, 1.62 s
Merged tree vs main only the PR's 7 files differ (+84 −23)

Negative control. I did not rerun it, because no test changed since my last review. Last time the test passed on Linux with main's production files, as expected: the new behaviour only takes effect under _WIN32. B-Howell's native Windows control (on an earlier head) is still the only evidence that the test fails without the PR.

Previous findings

  1. The merge resolution undid main's switch to the shared copy helpers (non-blocking): Resolved.
    • sysarch now calls GuestCopyIn_nid_no_patch for AMD64_SET_GSBASE (core/libs/prx/libkernel/System/src/Process.cpp:1031) and GuestCopyOut_nid_no_patch for the GET operations (:1056, :1062).
    • Compared with main, sysarch now differs only in the _WIN32 GS branches, the widened #if, and the operation number in the fallback diagnostic.
    • On Windows, writes go through the VirtualQuery-checked copy in core/libs/prx/libc/src/General.cpp:829-838 again, not WriteProcessMemory.
    • ReadGuest/WriteGuest are still used elsewhere in Process.cpp, as on main.

New findings

Blocking

None.

Non-blocking

None.

Not verified

  • The Windows code: GuestGs.cpp and the _WIN32 branches in Thread.cpp and Process.cpp. I have no MinGW toolchain or Windows host, so I did not compile or run them. B-Howell's native Windows pass and control covered head e0576a2c1c, not this head. The author's results at this head are author-reported, from translated and relinker-only hosts.
  • Hosted Windows CI on this head: no result is in the context.
  • macOS, console behaviour and any title. None of these is claimed.

To get this to a good state

  • A green hosted Windows job on this head that runs guest_sysarch, or a fresh native Windows run. The full build has to be dispatched by a collaborator. With that, I have nothing left open.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5757038780 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11624#pullrequestreview-5757038780). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-11-03T17:52:05Z. **Review:** COMMENTED --- # Re-checked — comments The new commit `a0cea87294` makes `sysarch` use `main`'s `GuestCopyIn/Out_nid_no_patch` again, which resolves my one open finding. The checks and the focused Linux tests pass. The production change still only takes effect on Windows, and I cannot compile or run it, so this stays a comment. I found nothing blocking. ## What changed since my last review I last reviewed `e0576a2c1c`. Since then: - `41bbc32070` merges current `main`. - `a0cea87294` replaces the three file-local `ReadGuest`/`WriteGuest` calls in `sysarch` with `GuestCopyIn_nid_no_patch`/`GuestCopyOut_nid_no_patch`. It changes only `Process.cpp`, with 3 insertions and 3 deletions. - The test file and the debt entry have not changed since my last review. - The description was refreshed. The author's new results come from translated and relinker-only hosts, and the description labels them that way. ## What I ran Head `a0cea872942f2da087f8f8074ce9721ad408491c`, `main` `1e658521a0a599872612bb91949311e2956b5283`, merged with `--no-ff` (tree `c2b6934675`). Debian 13, GCC 14.2.0, Release, Ninja. ```sh git show a0cea87294 git diff --check 1e658521a0a599872612bb91949311e2956b5283...a0cea872942f2da087f8f8074ce9721ad408491c python3 tools/check_conventions.py --base 1e658521a0a599872612bb91949311e2956b5283 ctest --test-dir build -j8 --test-load 32 --output-on-failure \ -R '^(guest_sysarch|guest_thread_self|guest_pthread_frame_chain|guest_pthread_join_detach|guest_pthread_start|guest_pthread_attr)$' git diff 1e658521a0a599872612bb91949311e2956b5283 c2b6934675468d3693fc3bfdfb61243bb8955137 --stat ``` | Check | Result | |---|---| | `git diff --check` | no output | | `check_conventions.py` | `All conventions checks passed.` | | Script build and tests (build.json) | build OK; 0 new failures, 0 timeouts; 9 known failures that also fail on `main`. `guest_net_ctl` skipped, as on `main` | | Focused sysarch and pthread tests | 6/6 passed, 1.62 s | | Merged tree vs `main` | only the PR's 7 files differ (+84 −23) | **Negative control.** I did not rerun it, because no test changed since my last review. Last time the test passed on Linux with `main`'s production files, as expected: the new behaviour only takes effect under `_WIN32`. B-Howell's native Windows control (on an earlier head) is still the only evidence that the test fails without the PR. ## Previous findings 1. **The merge resolution undid `main`'s switch to the shared copy helpers** (non-blocking): Resolved. - `sysarch` now calls `GuestCopyIn_nid_no_patch` for `AMD64_SET_GSBASE` (`core/libs/prx/libkernel/System/src/Process.cpp:1031`) and `GuestCopyOut_nid_no_patch` for the `GET` operations (`:1056`, `:1062`). - Compared with `main`, `sysarch` now differs only in the `_WIN32` GS branches, the widened `#if`, and the operation number in the fallback diagnostic. - On Windows, writes go through the `VirtualQuery`-checked copy in `core/libs/prx/libc/src/General.cpp:829-838` again, not `WriteProcessMemory`. - `ReadGuest`/`WriteGuest` are still used elsewhere in `Process.cpp`, as on `main`. ## New findings ### Blocking None. ### Non-blocking None. ## Not verified - The Windows code: `GuestGs.cpp` and the `_WIN32` branches in `Thread.cpp` and `Process.cpp`. I have no MinGW toolchain or Windows host, so I did not compile or run them. B-Howell's native Windows pass and control covered head `e0576a2c1c`, not this head. The author's results at this head are author-reported, from translated and relinker-only hosts. - Hosted Windows CI on this head: no result is in the context. - macOS, console behaviour and any title. None of these is claimed. ## To get this to a good state - A green hosted Windows job on this head that runs `guest_sysarch`, or a fresh native Windows run. The full build has to be dispatched by a collaborator. With that, I have nothing left open. <!-- anyps5-bots job=3483 head=a0cea872942f2da087f8f8074ce9721ad408491c -->
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!11624
No description provided.