cpu: reproduce load-config dispatch callback behavior #907
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/914"
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 triggered02 on 2026-11-23T16:59:00Z.
Refs #903 and #870. Source-built fixtures only; no production
pe_mapor loader change.Change
Two source-built cases:
cpu_native_load_dispatchuses a hand-written 0x138-byte_load_config_used. The +0x78 field is treated as the fixture's own direct callback pointer, not the real Windows guard-dispatch ABI. It is in read-only.rdatawith a DIR64 relocation; present/absent/alternate callbacks exercise the count, argument and return.cpu_native_load_config_callbackbuilds a C++ caller with/guard:cf. The linker supplies the guard slots, function table and flags; the caller calls a read-only relocated callback table through__guard_dispatch_icall_fptr.record,other(different callback) andinvalid(target inside a function) link without CFG;cfg_recordandcfg_invalidlink with it. The fixture is based on denn0x'spe/load-config-callbackreference branch.The hand-built fixture inspects its PE for the load-config directory/structure sizes, slot RVA/value, read-only
.rdata, and DIR64 relocation. The CFG fixture checks the guard slots, function table, flags, slot page protection and dispatch-call sites. Both run under Windows andpe_mapwithcpu_exe_io.dll.Verification
Windows 11 Pro 26200, MSVC 19.52, CMake/Ninja, Ryzen 5 5500. CPU-only; no adapter or debug layer.
Dev: hand-built present/absent/alternate native and mapped
0xb111/0xb211/0xb151. Linker fixture:record/other/invalidmatch;cfg_recordWindows0x30055(both slots replaced) vspe_map0x55(own slots kept);cfg_invalidWindows ends before output (0xc0000409locally) vspe_map0x77(unchecked target). 2.07 s.Release: same results, 2.03 s.
python -B tests/docs_links_check.py(13 files, 179 links),python -B tests/bidi_controls_check.py(748 files) andgit diff --checkpass.Evidence and follow-up
GuardFlags=0x100image (no check pointer or function table) is not part of the test or an acceptance condition. It was locally refused and hung the CI runner; a specific refusal code is not portable. The docs mention it separately.pe_mapsupport boundary. The fast-fail code is printed but not asserted.Checklist
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by denn0x on 2026-11-23T17:05:00Z.
Review: COMMENTED
Independent review of
ff3c29f, as requested in #903.Environment: Windows 11 build 26300.9974, AMD Ryzen 7 7700, MSVC 19.50.35720 (link 14.50), Python 3.13. CPU only.
Reproduction. In a fresh worktree, I ran
ctest --preset dev --no-tests=error -R '^cpu_native_load_dispatch$' -Vand the same with--preset release. Both pass, with the PR's numbers exactly:0xb1110xb1110xb2110xb2110xb1510xb1510xc000003e0xb111PE fields, read with my own pefile script rather than the PR's checker. These agree with the test output.
0x81600x81600x81600xc160(GUARD_CF)Size/ directory size0x138/0x138+0x78field RVA0x20880x20880x20880x2098+0x78value (preferred base)0x140001000(.text)0x140001014(.text)0x140001000(.text)GuardCFCheckFunctionPointerGuardFlags0x00x00x00x100The call count and the argument (
0x1234) matched on both loaders. The alternate control changes the result bits (0x40) and the return value as intended.Where the CFG refusal comes from. I patched copies of the
cfgimage:+0x78set to 0,GuardFlagskept at0x100: still0xc000003e.GuardFlagsset to 0,+0x78kept: runs,0xb111.So the refusal comes from
GuardFlags = 0x100on aGUARD_CFimage that has no check pointer and no function table. It does not depend on the dispatch field. The docs could say that, so it isn't read as Windows validating the callback.One design point.
GuardCFDispatchFunctionPointeris the VA of a pointer slot,__guard_dispatch_icall_fptr. The loader writes its dispatcher into that slot, and/guard:cfcode puts the target in RAX and doescall [slot]. Without CFG, the slot holds ajmp raxstub. In this fixture the field itself holds the callback's address in.text, and the entry calls that value directly. The fixture therefore tests "a callback pointer stored in the load-config field", which both loaders handle the same way. It does not test the dispatch path:Two options: a short note in the docs and PR body naming what the fixture models, or the compiled shape. In the compiled shape, a separate read-only, relocated slot holds a
jmp raxstub and the field points at it; the callback address comes from a read-only table, and a C++ caller built with/guard:cfmakes the call. I have a tested local version of that shape and can share it as a branch if useful, but I'd leave the choice to you and the maintainer.Your open question. I'd keep the linker-emitted CFG build separate, as the maintainer asked. For reference, on link 14.50 MASM-only objects never get
IMAGE_GUARD_CF_INSTRUMENTED. At least one object compiled with/guard:cfis needed before Windows applies the guard slots. Details are in #903.AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-23T16:59:12Z.
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
ff3c29fℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T17:02:02Z.
Thanks for the first source-built comparison. The three synthetic callback traces give us useful absent/present/alternate controls. Please describe the hand-written field as the fixture's own callback convention. It does not establish the ABI of the real Windows guard-dispatch slot. The new CFG case only measures how the loaders handle this hand-written image, and a specific refusal code on one Windows build is not a portable acceptance condition. Please add a separate, ordinary compiler/linker-produced CFG-enabled source fixture that Windows accepts, with an intended callback and a native trace. Keep normal CFG validation enabled and report the mapper outcome as a support boundary. The malformed-image observation can remain documented separately.
Imported from R0Y00/Xbox2Windows. Originally posted by denn0x on 2026-11-23T17:05:38Z.
@triggered02, on the maintainer's request for a separate compiler/linker-produced CFG fixture: the local version I mentioned is now on my fork as a reference branch, not a PR. It's
denn0x:pe/load-config-callback, onmainatd172f0a. Reuse any of it in #914. I won't open a competing PR.What it has:
tests/cpu/load_config_callback.{asm,cpp}andtests/cpu/load_config_callback_check.py, plus a CMake block that builds five variants from the same objects./guard:cfcalls a read-only, relocated callback table through__guard_dispatch_icall_fptr. The table's null entry is skipped./guard:cf. The CFG link uses the linker's own function table and flags (__guard_fids_table,__guard_fids_count,__guard_flags), and Windows accepts it.cpu_exe_io!emit_trace. The exit code also reports whether the loader replaced the check and dispatch slots.pe_mapruns it. The test records thepe_mapresult as the current support boundary.SEM_NOGPFAULTERRORBOXbefore the expected fast fail.0xC0000409exactly, which isn't portable; checking "the process ended before writing output" would be safer.GuardFlagsonly for the table-present bit.AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-23T17:30:04Z.
Addressed the review:
0xc000003eassertion; its 20 s native timeout caused both Windows CI failures./guard:cffixture ascpu_native_load_config_callback. Non-CFGrecord/other/invalidmatch;cfg_recordWindows0x30055vs pe_map0x55;cfg_invalidWindows ends before output (0xc0000409locally) vs pe_map0x77. The test asserts the pe_map boundary and no longer asserts an exact fast-fail code.pe/load-config-callbackreference branch.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T17:33:25Z.
The valid linker-produced CFG case now separates the Windows loader result from the mapper's current behavior. One assertion still makes unchecked dispatch a requirement: cfg_invalid must reach the interior target under pe_map. Please retain the current output as an observation and let this test also pass if the mapper explicitly rejects unsupported CFG before dispatch, or enforces CFG and rejects the invalid target with no entry result. Keep the native refusal, valid-config layout, and non-CFG variant assertions unchanged. This gives a later loader fix room to tighten the boundary without rewriting what the fixture is meant to establish.
Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-23T17:46:05Z.
Applied the cfg_invalid change in
dc491dd.ecord/other/invalid assertions are unchanged.
On the review points: the malformed hand-built cfg variant seen at f3c29f is gone. The remaining hand-built present/absent/alternate fixture and the docs call +0x78 the fixture's own callback convention, not the guard-dispatch ABI, and the hand-built GuardFlags=0x100 refusal is documented as a property of that malformed image rather than Windows validating the callback. The linker-produced CFG build is the separate cpu_native_load_config_callback test based on denn0x's reference branch.
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T18:02:35Z.
The revised fixture records the current unchecked outcome. I tightened the alternative to require status unsupported, a CFG diagnostic and no guest output. A generic mapping error or missing trace can no longer appear to establish a CFG result. Both source-built load-config tests passed in Windows x64 Release. This changes only the test and docs.
Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-23T18:06:02Z.
Synced
53561daand reran the fixture. Dev and release both pass. The extra acceptance is now the explicit unsupported/CFG diagnostic before dispatch; an unrelated load failure or missing output no longer counts. docs_links_check.py, idi_controls_check.py and git diff --check pass.AI-assisted.