Repository navigation
runtime: synthetic multi-callback TLS callback-table regression tests - #8051
NethminaYasas wants to merge 2 commits into
Conversation
Add hand-built synthetic PE fixtures to loader_tls_test for three zero-terminated callbacks (order, reasons, base, dry-run) and for a missing terminator (bounded failure, no OOB read). Document the callback-table contract in runtime/README.md. No production changes.
tupacfan04
left a comment
There was a problem hiding this comment.
The successful three-callback path is correct, but the failure coverage misses the case that matters and the hand-written stub has a real ABI bug.
-
Failure case only covers “no terminator after all three.” The fixture places
[cb1, cb2, cb3]in the last 24 bytes and omits the zero terminator; all three run, thenrequire_range()throws (runtime/src/pe_loader.cpp:482-488). That never exercises the per-entryrva_in(m, fn, "a TLS callback")check. A table of[cb1, image_base + SizeOfImage + 0x100, cb3, 0]must run onlycb1and throw the bounds error; a regression that caught the per-entry error and continued would still pass the new test. Add that fixture (assertorder == {1},count == 1, controlledstd::runtime_error). A callback that faults is a separate case:run_callbackshas no exception guard aroundcallback(...). -
Reasonis read as 64-bit.emit_callback_stub()storesrdx(48 89 90 disp32) andCallbackState.reasonisuint64_t;PIMAGE_TLS_CALLBACK's second parameter is a 32-bitDWORD, so onlyEDXis defined in the x64 ABI. It passes on MSVC only because the loader zero-extendsEDX; another compiler/optimization can leave garbage in the upper half. Storeedx(89 90 disp32) and makereason/the comparison 32-bit. -
Relocation is claimed but not tested. The fixture has no
.relocandfree_image_base()returns the preferred base on Windows, so neitherAddressOfCallBacksnor the entries are relocated. Either add a relocatable/forced-relocation variant asserting the callbacks run atm.base, or drop “relocated” from the README claim. -
Minor:
catch (const std::exception&)is too broad; check thestd::runtime_errormessage (“runs past the image”) so an unrelated failure cannot pass.
Correct: successful order/count 1,2,3 once, mapped base, null reserved, attach/detach reasons; load() runs no callbacks; the zero terminator stops the table; the missing-terminator-after-three case throws cleanly; detach order is consistent with PE/Wine. Synthetic only; no game files. AI-assisted (OpenCode).
Extend loader_tls with a synthetic table containing an out-of-image callback entry, asserting rva_in() rejects it after the first callback. Store the callback reason as 32-bit EDX to match PIMAGE_TLS_CALLBACK, and narrow failure catches to std::runtime_error.
|
Addressed the three approved findings in
On 3: the README wording describes the loader contract (entries are relocated virtual addresses), not test coverage; relocation itself is not exercised by these fixtures and is recorded as a limitation in the PR body. Re-run: |
Extends the existing Windows-only
loader_tlsCTest with three hand-built, fully synthetic PE images: (1) three distinguishable TLS callbacks in a zero-terminated table (asserting no execution onload()/dry-run, exact 1-2-3 order with mapped base, correct reason and null reserved for attach and detach); (2) the same image with the terminator removed (controlledstd::runtime_errorafter all three entries, no out-of-bounds read); (3) a table with an out-of-image entry value (base + SizeOfImage + 0x100), asserting only the first callback runs andrva_in()rejects the second. One README sentence documents the contract. No production, CMake, TLS-slot or clone-management changes.Fixture bytes are built from layout constants and hand-written x64 stubs by the test itself. The callback stubs store the 32-bit reason via EDX to match
PIMAGE_TLS_CALLBACK. No game data, shaders, disassembly, strings or traces; no game binary opened or run; no REA used.Tested on Windows x64, MSVC 19.44 (VS 2022), SDK 10.0.26100.0, CPU-only (GTX 1650 present but unused):
loader_tls1/1 passed, standalone 98 checks; full CTest 104 passed / 7 game-gated skips / 0 failed of 111 considered;python -I scripts/check_no_game_data.pyexit 0; CodeRabbit deep review 0 findings. Not tested: GPU/Vulkan/D3D12 (no Vulkan headers), Wine, Linux/macOS, AMD RDNA. The fixtures do not exercise image relocation itself.Overlap checked against #3790, #7503, #5233, #7423 — none adds this coverage. #3790 is a draft; re-check before merge. Claim: new item posted on #7599 (ID pending).
AI-assisted.