cpu: translate RIP-relative data against an explicitly bound image mapping #410
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/416"
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 bosseurdinternet on 2026-11-22T01:01:26Z.
Change
Refs #317 (RIP-relative data). Builds on #285 and #309 (both merged), and is independent of #321 and #343.
In
tools/cpu_switch_aot.pya RIP-relative memory operand is refused, and the result of a RIP-relativeLEAis a guest address that may only feed a jump table. A function that reads or writes a global, stores the address of a table or returns the address of a static object is therefore not translated. This adds an opt-in mode in which such data is addressed in a live mapping of the input image that the host supplies.--image-dataon the CLI,image_data=Trueonlift,translate_peandtranslate,IMAGE_DATAincpu_translation(). Without it, the same functions translate, their generated C++ is identical to main's and the refusal messages are unchanged. Translated signatures are the same in both modes.int lifted_bind_image(word base)andvoid lifted_unbind_image(). Bind accepts the base of a live mapping of the input image, made by Windows or bype_map, and returns 0 when accepted, 1 for a null base, 2 when the headers differ and 3 when read-only contents differ. A refused bind keeps the current binding.TimeDateStamp,SizeOfImage,CheckSum, the section table;ImageBaseexcluded because loaders rewrite it) and a hash of the file-backed bytes of readable, non-writable sections, excluding DIR64 relocation slots and the import address table. Bind recomputes both on the mapping; the contents are read only after the headers match. The hash is FNV-1a: it detects a different or altered image, not a crafted one. Writable data is not part of the identity.LEAperforms no access and is checked against the image extent only, since MSVC'slea r, __ImageBasetargets the headers. Each refusal has a named message.LEAyields base + RVA, a fully defined value that can be stored, compared, used as a base and returned. ALEAthat loads a recognised jump-table base keeps today's treatment and needs no mapping.0xE0494D47as noncontinuable before any access. I chose this overstd::abort()because a Debug CRT abort can show a dialog; that reason is from documented CRT behaviour, not measured here.docs/experiments.md: an address a translated function returns or stores is valid only while that mapping stays bound and mapped; bind before use, with no concurrent rebind. This is stated, not enforced.Verification
Local runs used the same compiler build as CI (MSVC 14.52.37025:
cl,link,ml64) under Wine 11.0 on Linux, at1ad9c0con maine5e0079. I reran the items below on this head unless a line says otherwise.ctest --no-tests=error -R '^cpu_aot_image_data$' -V: passed. The original runs in onepe_mapmapping of the fixture and the translation is bound to a second mapping of the same file, each starting from the image's initial data. After each of 29 calls the test compares return values, the guarded trace, RBX and RSI, and the writable data of the two mappings (1,048 bytes).address - basebetween the two mappings. Which values are addresses comes from the fixture's known behaviour, not from the values.LEA; the test writes through the address each side returned and both sides read it back; on one mapping, the original and the translation read each other's writes.TimeDateStamp(2), in a read-only constant (3), in a jump-table entry in.text(3), each leaving the binding unchanged; a copy with one altered byte in writable data is accepted (0); the system loader's own mapping is accepted; after unbind and a bind to a third mapping, results follow the new mapping.LEA), outside every section, an access crossing the end of.data, a write to.rdata; four exports refused without the option, each with today's message; an export namedbind_imagerejected.0xE0494D47before bind and leave the caller's object unchanged; two that need no mapping run; after bind a read returns the initial value; after unbind the exception is raised again.cpu_aot_jump_tables,cpu_aot_entry_order,cpu_aot_narrow_returnsandcpu_aot_fourth_argumentpass. Othercpu_*tests: same results as main. Under Wine,cpu_aot_import_call,cpu_aot_ordinal_import,cpu_native_reloc_freeandcpu_native_tlsfail on main too because Wine's loader differs from Windows, andcpu_native_exe_starttimes out intermittently (#281). The Windows job is the reference for those.8ed1ca7, whose translator is identical): the same 642, 639 and 15 functions translate at/O2,/O1and/Od, and all 1,296 have identical C++./O2and at/O1and 7 at/Od(16, 16 and 7 not STL). This is an upper bound that assumes a correct mapping is bound. Of the 32 at/O2, 23 read aLEAresult as data, 8 return one and 1 uses a RIP-relative operand;/O2, 32 of 32 at/O1and 7 of 7 at/Odwith no mismatch, on 32 or more inputs each. What it does not show: no corpus function changed image data on those inputs, restoration hides effects that build up across calls, and with one mapping the comparison by RVA is not exercised. It is evidence on a few inputs, not a proof of equivalence;LEAstill treated as a guest address; a table base treated as data; DIR64 slots not excluded; and others).pyflakes,tests/docs_links_check.pyandtests/form_coverage_check.pypassed.Not run locally: Windows itself, the D3D12 tests and anything that needs Windows loader behaviour.
Evidence and follow-up
tests/cpu/image_data.asmis original MASM assembled in the build. No binaries were added.image_datais classified intools/form_coverage.py.pe_map, because it gives a fresh mapping on demand under Windows and Wine alike andLoadLibraryof one path twice returns the same module; liveness of the supplied base cannot be checked and is the host's responsibility; the defined failure is a structured exception.CMakeLists.txt,docs/experiments.md,tools/form_coverage.pyand the CLI of the translator. I will rebase as they land.AI-assisted (Claude Code).
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-22T04:19:13Z.
I integrated your image binding into the current Program/call-graph translator and retained the fixed-frame and bound-range paths. The image-data, direct-call, fixed-frame and bound-callee Windows CTests all pass together locally. I am adding a separate end-to-end EXE fixture that uses this binding in a nested leaf. Thank you for building the mapping and differential checks.