feat(relinker): load Windows guest TLS values through register addresses #1233
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1233"
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 hashaam1217 on 2026-10-07T18:49:07Z.
What
#217: NHL 27 (PPSA34063) relinked for Windows on
main(cea1ef13) now stops atUnsupported Windows guest TLS instruction (bytes: 64 48 8b 03) (offset 0x747c663), which ismov rax, fs:[rbx]. #340 and #767 handlefs:[disp32]; this adds loads through a register address.mov r64andmov r32fromfs:[mem], wherememhas a base or an index register (ModRM/SIB with no displacement, disp8 or disp32), now relink. The stub savesraxandrcx, computes the offset withlea rax, [mem]from the original addressing bytes, loads the thread pointer as the existing stubs do and runsmov dst, [rax+rcx]. A 32-bit load zero-extends, as on hardware. Onlymov,lea,pushandpoprun, so flags are kept.TPOFF64values are written against inWindowsGuestModuleWriter. Sofs:[reg]reads the same bytes asfs:[disp32]with that value.patchAccesswrote the jump anyway, over the next instruction; every form supported so far was at least 7 bytes, so it never happened. A short site now moves the following sequential instructions into its stub, with RIP-relative displacements recomputed. A branch, call, return or another TLS access after it fails the relink with "Short guest TLS instruction is followed by an instruction that cannot move" and its offset.patchAccessthrows for a site shorter than the jump.rspdestination or base, RIP-relative, 16-bit, stores and ALU forms through a register address, and absolute 32-bit loads.rex-x-load(64 4a 8b 04 25 28 00 00 00) leaves the rejected list: REX.X makes the SIB indexr12, so it ismov rax, fs:[r12+0x28], a register-addressed load.The register's value is not range-checked: unlike a
disp32, it is only known at run time.#1117 also edits
test_tls_function_coverage.py; the two merge without conflict.Tested
Ubuntu 24.04.5, GCC 13.3.0. Full build and
ctest: 399/399 passed.tls_function_coverage: 22 new execution cases over 11 addressing forms (NHL 27's64 48 8b 03, base equal to the destination, base + index + disp8,r12/r13/rbpbases, scaled index with disp32, index only, 32-bit loads intoedxandr9d), each with flags 0x202 and 0xad7, plus a RIP-relative follower and a 3-byte load that needs two followers. Each case checks the loaded value, every other register and RFLAGS, and returns 42. On Linux the test checks the stub bytes; whereos.name == "nt"it runs the cases. New rejections:rspbase and destination, RIP-relative, 16-bit, a store and an ALU read through a register, and short loads followed byret,callor another TLS access, with the follower's offset. With the relinker frommainthe test fails with NHL 27's message.GSat a hand-made TEB whose TLS slot holds a block copied from the template, ran the TLS callback for process attach and called the case. All 26 new cases and the 201 existing ALU and displacement cases return 42; a case that loads from the wrong offset returns 1. This is what found the short-site overwrite: the first version passed the byte checks and crashed on the 3- and 4-byte forms. The harness is not part of this PR.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T09:11:07Z.
Checked on main + this PR: build and full ctest green (430/430);
tls_function_coveragefails without theWindowsTlsBuilder.cppchange. Read the stub (save/restore ofrax/rcxfor every destination, flags untouched, 32-bit zero-extension), the rejected forms and the short-site move with RIP-relative fix-up; all consistent with the description. Linux and Windows CI green; merging.