Map source-built images without LoadLibrary and compare with the lifted calls #49
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/49"
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 R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-21T13:53:24Z.
Change
Items 1–3 of #46. Item 4 (SEH) is left open for a separate fixture, as requested.
tools/pe_map.cppmaps an x64 PE32+ image into its own allocation, away from the preferred base. It applies DIR64 relocations, binds ordinary imports by name or ordinal through a resolver supplied by the host, sets section protections, writes the actual base into the mapped headers and registers.pdata. Images with TLS, delay imports or an entry point are rejected. Header fields are bounds-checked before use.tests/cpu/reloc_route.asmis a new fixture with the samecall_mixcontract asdirect.asm. It calls through an absolute code pointer in.data, so the image has exactly one DIR64 relocation. The existing import fixtures have none.cpu_native_map(tests/cpu/native_map_check.py) reuses thedirect_checkhelpers. The new section indocs/experiments.mdis linked from the README CPU row.Verification
At
b102794rebased on7c175f2: Windows 11 build 26300, VS Build Tools 17.14, Python 3.14.10.The full suite gives 71 tests and 0 failures; only
bvh_wave64_hardwareandbvh_wave64_warpare skipped (lane range 32..32 / 4..4).For the named and ordinal cases, the same 249 inputs go through three paths: the Windows-loaded original, the mapped image and the recompiled DLL. Each comparison covers the return value, the three words written by the callee through the guarded trace buffer, and the RBX/RSI sentinels. The unresolved-import case is part of the CTest run.
As a one-off manual check (not in CI), I broke the loader four ways: skipped relocations, skipped the IAT write, skipped
.pdataregistration and left the preferredImageBasein the headers. The test failed with a specific assertion in each case.Evidence and follow-up
All fixtures are built from this repository; there is no game data. Open points:
Refs #46
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T14:01:49Z.
Thanks, @Leyukaka! Comparing the Windows-loaded, manually mapped, and recompiled functions on the same inputs gives us a practical way to narrow down future discrepancies. I especially appreciate the altered-provider checks.
Could you make two small fixes in
tools/pe_map.cppand cover them in the regression suite?pe_map_image, reject a nonempty import directory whose declared size is smaller than oneIMAGE_IMPORT_DESCRIPTOR. Currently the descriptor count rounds down to zero and the image can be accepted with its imports silently skipped. Please add a fixture that expects mapping to return null withMAP_FORMATbefore invoking the resolver.pe_map_export, returnnullptrwhen the matched export address table slot contains RVA zero. The current bounds check returns the image base for that slot. Please cover a named export pointing to an empty slot and retain a positive lookup for a valid export.Once those cases are covered and CI passes on the updated commit, we’re happy to merge. Thanks again for the contribution!
Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-21T14:39:57Z.
Thanks for the review. Both fixes are in, and the branch is rebased on
bbdaba7.pe_map_imagenow fails withMAP_FORMAT("import directory smaller than one descriptor") when the import directory is nonempty but smaller than oneIMAGE_IMPORT_DESCRIPTOR. In CTest, a copy of each import fixture with the directory size set to 19 bytes must return null with that status, and the resolver must not be called.pe_map_exportreturnsnullptrwhen the matched slot holds RVA 0. The test maps a copy ofcpu_register_probe.dllwith theclobber_controlslot zeroed. That name now returns null, whileprobein the same mapped image still resolves to its RVA.Without either fix the test fails: the undersized directory maps with its imports skipped, and the empty slot returns the image base. Locally
cpu_native_mappasses and the full suite has 72 tests with 0 failures (wave64 skipped on the RTX 5080 and WARP).