feat(libkernel): maintain per-thread guest GS bases on Windows #11624
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11624"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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
a0cea872942f2da087f8f8074ce9721ad408491cmerges main1e658521a0a599872612bb91949311e2956b5283through 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
e0576a2c1cmerged ontob28bb77217: 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
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)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.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 dedicatedHostThreadSlotand 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.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_sysarchtest fails againstmain'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,mainba5b5330b37724bca4b99f30faab504653635a04, merged with--no-ffin a clean worktree (Release, GCC 16.2.1, Ninja). Host: Arch Linux 7.2.11-zen, Intel Core i9-14900KF.Results
maingit diff --checkcheck_conventions.pyAll conventions checks passed.libsand the four test targetsguest_sysarch,guest_thread_self,guest_pthread_frame_chain,guest_pthread_join_detachguest_sysarchrepeated 50 timesguest_sysarchfails (SEGFAULT)ctest, merged tree
Negative control
I reverted only the production files (
Process.cpp,Thread.cppand the libcCMakeLists.txttomain, and removedGuestGs.hpp/GuestGs.cpp), kept the new test, and rebuilt.guest_sysarchthen fails with a SEGFAULT:maincopies withmemcpy, so the newsysarch(131/130/9, (void*)1)checks crash where they should returnEFAULT. With the merged files restored, it passes again.ctest, production files from main
Findings
Blocking
None.
Non-blocking
The debt rewrite drops sources and detail that are still accurate. The single
sysarchentry onmain(docs/dev/debt/libkernel.md#L220) becomes three entries (L213-L215 at the head). The rewrite loses:copy_threadlink, which backs the statement that Linux guest threads inherit the creator's GS base;sysarchdefault case, which backs theEINVALbehaviour for numbers it does not handle;I386_VM86;(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.The debt text says Windows FS reads throw, but a null argument returns
EFAULT. The new entry sayssysarch"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)andsysarch(7, nullptr)return-1/EFAULT, and only a non-null argument throws. That matches the console's measuredEFAULTfor a null argument to operation 7, so the code is fine. The debt sentence should say that only a non-null argument throws.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. SinceThrownwas removed,<stdexcept>and<string>(L8-L9) are no longer used.Not verified
GuestGs.cppand the_WIN32branches inThread.cppandProcess.cpp. I have no Windows or MinGW toolchain, so I did not compile or run them. ThewindowsCI 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.To get this to a good state
windowsCI job finish green on this head; it buildslibsand runs the selected tests, includingguest_sysarch.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:b9bcb27fb9restores the debt sources and clarifies the Windows FS debt.3a30abf703registers the write-watch cases once; it is now absorbed bymainand is no longer in the PR diff.e32141a3d8keeps the EFAULT fallback qualification in the debt entry.5b93739daalimits thesysarch(7|128, bad)and Linux FS read assertions to__linux__.main, including5d736ad55b, which onmainmovedsysarchtoGuestCopyIn/Out_nid_no_patch.What I ran
Head
e0576a2c1c4453e0e4f633f56af48da51c620638,main9090972b7e91fd266819cbd77a8b058e177b5682, merged with--no-ff(tree772f201dd4). The machine was Debian 13 (32 vCPU Xeon Gold 6136) with GCC 14.2.0, Release, Ninja.git diff --checkcheck_conventions.pyAll conventions checks passed.mainguest_sysarchpasses withmain's production files (see below)Negative control. On Linux the test no longer fails against
main. That is expected now:main(5d736ad55b) already returnsEFAULTfor bad pointers, and Linux GS inheritance already comes from the kernel. What the test adds overmainonly takes effect on Windows. B-Howell reports that on native Windows (Ryzen 7 7800X3D, WinLibs GCC 15.2)guest_sysarchaborts withsysarch: segment bases on this host not implementedwhenmain'sProcess.cppandThread.cppare used. That is a third-party report; I did not reproduce it.Previous findings
copy_threadlink, the FreeBSD default-case link,I386_VM86and the(libkernel)tags.GET_FSBASE/I386_GET_FSBASE"return EFAULT for null arguments and throw for non-null arguments". That matchesProcess.cpp:1025-1028and:1048.RequireLowHalf(9, base)now runs once (GuestSysarch.cpp:72), and<stdexcept>/<string>are gone.New findings
Blocking
None.
Non-blocking
The merge resolution undoes
main's switch to the shared copy helpers.main's5d736ad55bmadesysarchuseGuestCopyIn_nid_no_patch/GuestCopyOut_nid_no_patch(main Process.cpp#L1030, #L1046, #L1052). The PR puts back the file-localReadGuest/WriteGuestinstead (head Process.cpp#L1031, #L1056, #L1062).EFAULTfailure now throws an unrelatedcredentials: process_vm_readv failedmessage (#L138).WriteProcessMemory, notmain'sVirtualQuery-checked copy.main.Suggested fix: keep
main'sGuestCopyIn/Out_nid_no_patchcalls and add only the_WIN32branches.Not verified
GuestGs.cppand the_WIN32branches inThread.cppandProcess.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.To get this to a good state
guest_sysarch). With B-Howell's native run, that would cover what I cannot check here.main'sGuestCopyIn/Out_nid_no_patchcalls insysarch(new finding 1).Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T17:52:05Z.
Review: COMMENTED
Re-checked — comments
The new commit
a0cea87294makessysarchusemain'sGuestCopyIn/Out_nid_no_patchagain, 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:41bbc32070merges currentmain.a0cea87294replaces the three file-localReadGuest/WriteGuestcalls insysarchwithGuestCopyIn_nid_no_patch/GuestCopyOut_nid_no_patch. It changes onlyProcess.cpp, with 3 insertions and 3 deletions.What I ran
Head
a0cea872942f2da087f8f8074ce9721ad408491c,main1e658521a0a599872612bb91949311e2956b5283, merged with--no-ff(treec2b6934675). Debian 13, GCC 14.2.0, Release, Ninja.git diff --checkcheck_conventions.pyAll conventions checks passed.main.guest_net_ctlskipped, as onmainmainNegative 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
main's switch to the shared copy helpers (non-blocking): Resolved.sysarchnow callsGuestCopyIn_nid_no_patchforAMD64_SET_GSBASE(core/libs/prx/libkernel/System/src/Process.cpp:1031) andGuestCopyOut_nid_no_patchfor theGEToperations (:1056,:1062).main,sysarchnow differs only in the_WIN32GS branches, the widened#if, and the operation number in the fallback diagnostic.VirtualQuery-checked copy incore/libs/prx/libc/src/General.cpp:829-838again, notWriteProcessMemory.ReadGuest/WriteGuestare still used elsewhere inProcess.cpp, as onmain.New findings
Blocking
None.
Non-blocking
None.
Not verified
GuestGs.cppand the_WIN32branches inThread.cppandProcess.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 heade0576a2c1c, not this head. The author's results at this head are author-reported, from translated and relinker-only hosts.To get this to a good state
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.