feat(relinker): load the fs:[0] thread pointer into any register in Windows guest code #222
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/222"
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 YossiYad on 2026-10-01T16:29:25Z.
What
The Windows TLS builder accepted the thread pointer load only into RAX (
64 48 8b 04 25 00 00 00 00). The same instruction with another destination (mov rcx, fs:[0],mov r9, fs:[0], ...) failed the relink with "Unsupported Windows guest TLS instruction".WindowsTlsBuildernow takesmov r64, fs:[0]for every destination except RSP (REX48or4c, any ModRM reg field). The stub computes the pointer in RAX as before, moves it into the destination and restores RAX and RCX; the destination is the only register that changes. The bytes emitted for the RAX load and for thefs:[0x28]store are unchanged.test_tls_function_coverage.pyrelinks one image per destination register. Each body sets EAX and ECX, loads the thread pointer, returns 0 if either register changed and otherwise the TLS value 42. The RSP form is checked to still fail.Possibly the cause of #217, not confirmed: the report has the offset but not the instruction bytes.
Tested
ctestpasses, 89 tests. Disassembled the generated.gtcodestubs for RAX, RCX, RDX, R9 and R12.Buildworkflow on the fork branch, wheretls_function_coverageexecutes the 15 relinked executables: https://github.com/YossiYad/AnyPS5/actions/runs/36886340037Checklist
main; no other open PR implements the same functions.mdfiles or images added to the repositoryImported from boykopovar/AnyPS5. Originally posted by QDarkRex on 2026-10-02T04:14:42Z.
Tested this independently on Linux: same 28 synthetic
fs:/gs:instruction forms through the relinker built frommain(709d7fe) and from this branch (53d4ef4),--windows --skip-sce-module.Newly accepted with this PR, as described:
mov rcx/rdx/r8/r14, fs:0andraxwith REX.R.mov rsp, fs:0still fails, as intended, and the previously supported forms still pass.Still rejected, in case one of these turns out to be what #217 hits:
mov rax, fs:0x28,mov rax, fs:0x10,mov eax, fs:-4,mov rax, fs:-8,cmp rax, fs:0x28mov eax, fs:0fs:[rax],fs:[rax+rcx],fs:[rax+0x10],fs:[rax+disp32],fs:[rip+disp]fs:0x28:mov fs:0, rax, REX.Wmov fs:0x28, imm32,mov fs:0x30, imm32add rax, fs:0,xchg rax, fs:0,mov rax, gs:0x58I've asked the #217 reporter for the bytes at the failing offset and whether
--skip-sce-modulechanges the result (the same check also runs onsce_modulefiles, so the failure may not be ineboot.bin).