cpu: translate ordinary calls of a bound import #566
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/572"
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-22T13:14:15Z.
Change
Translate ordinary calls of the import bound with
--bindintools/cpu_switch_aot.py. Until now the explicit binding resolved onlyjmp qword ptr [rip+slot](#343); calls of an import were translated only when a whole-program tool passed its ownimportstable.Forms now resolved through the binding, each only when its slot is an IAT slot of the ordinary import directory and holds the bound import (
resolve_import, as for tail jumps), one slot per run, callees included:call qword ptr [rip+slot];CALLof the linker's import thunk (FF 25 disp32, asFunction.thunk_slotrecognises it, outside every unwind interval and bound range);JMPto such a thunk, as the bound tail jump through the thunk's slot.The call is a host call under #425's rules, with no new model: RSP 8 mod 16 with the home space below the return address; each register of the binding's argument count fully defined; afterwards RAX holds the binding's guaranteed bytes, RCX, RDX, R8 to R11, the flags and the 32 bytes at RSP are undefined. Nonvolatile registers and the rest of the frame are kept, which is a term of the binding: the translator cannot check a provider.
The slot read (#437's rule). The original reads the slot; the translation calls the named import and does not read it. The resolver therefore requires the slot to be 8 bytes of one section with
IMAGE_SCN_MEM_READ, so the original's read cannot fault while the image's code runs. This check sits in the shared resolver, so it also applies to #343's tail jumps: that is the only behaviour change to the existing tail path. A slot changed at run time (a hook) is not followed; the module docstring says so.Program.tail_resolveris renamedimport_resolver. One control ofcpu_aot_import_tail_jumpexpects the new text "no call or tail jump uses it"; it rejects the same case as before. Follows #343 (40fb465) and #425. Refs #317.Verification
Commit
33c863aonmainatd896867, MSVC 14.52cl/link/ml64under Wine. Not run locally: Windows itself, so the CI is the first native run.cpu_aot_import_calls(fixturetests/cpu/import_calls.asm, linked against the named and the altered provider ofcpu_aot_import_tail_jump): passes.cl /O2build of the named translations.guarded_call, 9 fault cases give the same exception code, return value and trace for the original and both builds of the translation: a guest read that faults before the call, one that faults after the call has written the trace, and a fault inside the import.cpu_*tests: same results asmain. Under Wine these fail onmaintoo:cpu_aot_import_call,cpu_aot_ordinal_import,cpu_native_reloc_free,cpu_native_tls,cpu_aot_mul_div(Wine reports the divide overflow with another code),cpu_native_exe_start(intermittent timeout, #281). Not built locally for lack of tools:cpu_native_archive_reader,cpu_native_archive_blast,cpu_native_shim_startup,cpu_shim_compute_warp,cpu_shim_compute_hardware.tests/cpu/archive/translate_blast.py, which subclassesLifter, was run by hand on the same input with both trees: identical output./O2,/O1,/Od), no binding, againstmain: the same 655, 651 and 400 functions translate, no regression, 1,706 translations identical, identical prelude. Refusal messages change for 143, 150 and 98 functions, all to "no binding ...".Evidence and follow-up
tests/cpu/import_calls.asmis original MASM assembled in the build; no binaries were added.memset,free,memcpy,memcmp,strlen). As generated, only 11, 11 and 5 of them compile: a C runtime name declared withwordparameters clashes with the prelude's headers (C2733). Declaring the import library's slot pointer instead (extern "C" word (*__imp_memset)(word, word, word);) compiled and linked all of them in a trial; that is not in this PR.mainaccepts66 FF 25as the bound tail jump, and this PR accepts66 FF 15the same way, for consistency. Intel processors ignore the prefix on a near branch in 64-bit mode; AMD processors use a 16-bit operand (iced decodes the patched bytes ascall qword ptrwith Intel rules andcall word ptrwith AMD rules, and the translator accepts them). If you want these refused, I would do it in a separate PR for all near-branch forms.__imp_declaration.Checklist
AI-assisted (Claude Code).
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-22T14:25:43Z.
I updated the explicit binding documentation and CLI at
7da8d9b. Throughout execution the image and bound target must stay valid, and the original IAT slot must remain readable and hold the declared target. The generated call directly uses that binding. I also kept thunk probing off the old direct path when there is no import table or supplied import map. On Windows x64,ctest --preset dev --no-tests=error -R '^cpu_aot_(import_calls|import_tail_jump|direct_calls|import_call|direct_call|call_entries)$'passed 6/6, including the existing wrong-slot and missing-binding controls.