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: |
|
Tested
No game files. AI-assisted (Claude Code). |
|
Tested c68e5d8 (merged onto main 867d922) on RTX 5070, NVIDIA 621.24, Windows 11 (build 26200), Vulkan validation layer on (
Ran the tests that belong to the test files this PR changes (ctest entries, or the test program directly when it is not registered), with no game files ( |
|
thanks @egexon @optinium51-bot |
…otRexed#8262 ItsNotRexed#8405 ItsNotRexed#8462 ItsNotRexed#8469 ItsNotRexed#8489 ItsNotRexed#8051 ItsNotRexed#8059 ItsNotRexed#8064 ItsNotRexed#8090 ItsNotRexed#8150 ItsNotRexed#8207 ItsNotRexed#8227 ItsNotRexed#8315 ItsNotRexed#8291 ItsNotRexed#8919 fork integration. Each parent after the first is an exact reviewed PR head. ItsNotRexed#4366 441ccbe ItsNotRexed#4366 (comment) ItsNotRexed#8024 2b3c7ad ItsNotRexed#8024 (comment) ItsNotRexed#8262 a1cf055 ItsNotRexed#8262 (comment) ItsNotRexed#8405 98166db ItsNotRexed#8405 (comment) ItsNotRexed#8462 e697679 ItsNotRexed#8462 (comment) ItsNotRexed#8469 0704ae2 ItsNotRexed#8469 (comment) ItsNotRexed#8489 5093619 ItsNotRexed#8489 (comment) ItsNotRexed#8051 c68e5d8 ItsNotRexed#8051 (comment) ItsNotRexed#8059 a2a88a9 ItsNotRexed#8059 (comment) ItsNotRexed#8064 451c04b ItsNotRexed#8064 (comment) ItsNotRexed#8090 14c715c ItsNotRexed#8090 (comment) ItsNotRexed#8150 63beabb ItsNotRexed#8150 (comment) ItsNotRexed#8207 7699b2d ItsNotRexed#8207 (comment) ItsNotRexed#8227 66bfb52 ItsNotRexed#8227 (comment) ItsNotRexed#8315 aa24da7 ItsNotRexed#8315 (comment) ItsNotRexed#8291 a664ebf ItsNotRexed#8291 (comment) AI-assisted integration.
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.