cpu: reproduce load-config callback dispatch during EXE startup #896

Closed
opened 2026-11-23 16:36:07 +00:00 by R0Y00 · 7 comments
R0Y00 commented 2026-11-23 16:36:07 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T16:36:07Z.


Refs #870 and #317. Available to claim. Please post the test environment and any overlapping PR when claiming.

Build a source-only x64 Windows fixture that calls a typed startup callback through a load-config dispatch slot. Put both an absent callback and a callback from a relocated, read-only slot in the fixture. Keep the input image and provider identical when comparing Windows and pe_map.

Acceptance:

  • Show the absent callback makes zero calls, and the present callback sees the same arguments and call count on both loaders. Record the relocation, callback slot permissions and load-config fields using the fixture's own PE.
  • Include a negative control with a different callback or argument so the trace distinguishes an incorrect binding.
  • Add a separate CFG-enabled build and report how Windows validates the callback. Record what pe_map supports and report any refusal. Keep the CFG-enabled path subject to its original checks.

The first contribution can be the fixture and results. The shared AOT binding and loader policy can be reviewed against it separately. Use source-built inputs and share the commands, commit and Windows build.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6564001655 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/903). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T16:36:07Z. --- Refs #870 and #317. Available to claim. Please post the test environment and any overlapping PR when claiming. Build a source-only x64 Windows fixture that calls a typed startup callback through a load-config dispatch slot. Put both an absent callback and a callback from a relocated, read-only slot in the fixture. Keep the input image and provider identical when comparing Windows and `pe_map`. Acceptance: - Show the absent callback makes zero calls, and the present callback sees the same arguments and call count on both loaders. Record the relocation, callback slot permissions and load-config fields using the fixture's own PE. - Include a negative control with a different callback or argument so the trace distinguishes an incorrect binding. - Add a separate CFG-enabled build and report how Windows validates the callback. Record what `pe_map` supports and report any refusal. Keep the CFG-enabled path subject to its original checks. The first contribution can be the fixture and results. The shared AOT binding and loader policy can be reviewed against it separately. Use source-built inputs and share the commands, commit and Windows build.
triggered02 commented 2026-11-24 06:49:19 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-23T16:47:03Z.


Claiming this.

Environment: Windows 11 Pro 26200, AMD Ryzen 5 5500, MSVC 19.52 (VS 2026 Build Tools), Windows SDK 10.0.26100 (DXC 1.9.2602.17), CMake/Ninja, Python 3.12, dev and release presets.

First pass is the source-built fixture and results, not a production loader or shim change. I plan to build a MASM caller that invokes a typed startup callback through a load-config dispatch slot, with:

  • the absent-callback case (zero calls);
  • a present callback in a relocated, read-only slot;
  • the same image and provider under Windows and pe_map;
  • a different-callback/argument negative control;
  • a separate CFG-enabled build, recording how Windows validates the callback and what pe_map does.

I will record the load-config fields, relocation and slot permissions from the fixture's own PE, and use the existing exe_startup/finish_exe wrapper and live-worker control. Refs #870 and #317. Overlaps: #165 (source-built startup), #896 (tools-memory fixture), #902 (mapping); none changes the load-config dispatch path. If the fixture exposes a loader gap, I will report it separately rather than fold it into this slice.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7107664584 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/903#issuecomment-7107664584). Originally posted by [triggered02](https://github.com/triggered02) on 2026-11-23T16:47:03Z. --- Claiming this. Environment: Windows 11 Pro 26200, AMD Ryzen 5 5500, MSVC 19.52 (VS 2026 Build Tools), Windows SDK 10.0.26100 (DXC 1.9.2602.17), CMake/Ninja, Python 3.12, `dev` and `release` presets. First pass is the source-built fixture and results, not a production loader or shim change. I plan to build a MASM caller that invokes a typed startup callback through a load-config dispatch slot, with: - the absent-callback case (zero calls); - a present callback in a relocated, read-only slot; - the same image and provider under Windows and `pe_map`; - a different-callback/argument negative control; - a separate CFG-enabled build, recording how Windows validates the callback and what `pe_map` does. I will record the load-config fields, relocation and slot permissions from the fixture's own PE, and use the existing `exe_startup`/`finish_exe` wrapper and live-worker control. Refs #870 and #317. Overlaps: #165 (source-built startup), #896 (tools-memory fixture), #902 (mapping); none changes the load-config dispatch path. If the fixture exposes a loader gap, I will report it separately rather than fold it into this slice. AI-assisted.
denn0x commented 2026-11-24 06:49:19 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by denn0x on 2026-11-23T16:47:24Z.


Claiming this.

  • Environment: Windows 11 build 26300.9974, AMD Ryzen 7 7700, MSVC 19.50.35720 x64 (ML64 and link 14.50), dev preset.
  • Overlap: I found no open PR that touches the load config's guard fields, __guard_dispatch_icall_fptr or CFG. #899 is the closest landed work. It seeds the /GS cookie from the same directory, and I'd reuse its CRT-free exe_startup.asm pattern.
  • Plan for the first PR (fixture and results only):
    • Fixture: a CRT-free EXE with a hand-written _load_config_used whose GuardCFDispatchFunctionPointer names a read-only, relocated slot holding a jmp rax dispatcher.
    • Callbacks: the entry calls a typed callback, (int, int, int, void*) returning an int, through that slot for two read-only, relocated pointers. One pointer is null and is tested and skipped. The other names a callback that records its arguments and the number of calls.
    • Control: a variant that binds a different callback with a different argument, so the trace must change.
    • Comparison: the Windows launch and pe_map_run of the same image and provider, on exit code, recorded arguments and call count. It also records the relocation entries covering both slots, their section permissions and the load-config fields, read from the fixture's own PE.
    • CFG build: a separate /guard:cf link of the same source. I'll report what Windows writes into the check and dispatch slots, whether a valid target runs, and what an invalid target does natively. For pe_map I'll record what it currently does with that image, without relaxing any check. Any refusal or divergence is reported rather than worked around, so the loader policy can be reviewed separately.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7107673708 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/903#issuecomment-7107673708). Originally posted by [denn0x](https://github.com/denn0x) on 2026-11-23T16:47:24Z. --- Claiming this. - **Environment:** Windows 11 build 26300.9974, AMD Ryzen 7 7700, MSVC 19.50.35720 x64 (ML64 and link 14.50), `dev` preset. - **Overlap:** I found no open PR that touches the load config's guard fields, `__guard_dispatch_icall_fptr` or CFG. #899 is the closest landed work. It seeds the `/GS` cookie from the same directory, and I'd reuse its CRT-free `exe_startup.asm` pattern. - **Plan for the first PR (fixture and results only):** - **Fixture:** a CRT-free EXE with a hand-written `_load_config_used` whose `GuardCFDispatchFunctionPointer` names a read-only, relocated slot holding a `jmp rax` dispatcher. - **Callbacks:** the entry calls a typed callback, `(int, int, int, void*)` returning an int, through that slot for two read-only, relocated pointers. One pointer is null and is tested and skipped. The other names a callback that records its arguments and the number of calls. - **Control:** a variant that binds a different callback with a different argument, so the trace must change. - **Comparison:** the Windows launch and `pe_map_run` of the same image and provider, on exit code, recorded arguments and call count. It also records the relocation entries covering both slots, their section permissions and the load-config fields, read from the fixture's own PE. - **CFG build:** a separate `/guard:cf` link of the same source. I'll report what Windows writes into the check and dispatch slots, whether a valid target runs, and what an invalid target does natively. For `pe_map` I'll record what it currently does with that image, without relaxing any check. Any refusal or divergence is reported rather than worked around, so the loader policy can be reviewed separately. _AI-assisted (Claude Code)._
R0Y00 commented 2026-11-24 06:49:19 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T16:49:43Z.


Thanks to both of you for claiming this. @triggered02, please take the first source-built caller and trace, since you posted first. @denn0x, if willing, please review that candidate on your separate Windows environment and independently check the PE fields, observed call count and the negative control. Keep the CFG-enabled build separate and record observed behavior or a refusal using the original validation rules. This keeps the two contributions on one fixture.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7107733697 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/903#issuecomment-7107733697). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T16:49:43Z. --- Thanks to both of you for claiming this. @triggered02, please take the first source-built caller and trace, since you posted first. @denn0x, if willing, please review that candidate on your separate Windows environment and independently check the PE fields, observed call count and the negative control. Keep the CFG-enabled build separate and record observed behavior or a refusal using the original validation rules. This keeps the two contributions on one fixture.
denn0x commented 2026-11-24 06:49:20 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by denn0x on 2026-11-23T16:58:06Z.


Understood. @triggered02 has the caller and trace, and I won't open a competing PR. I'll review the candidate on this machine (Windows 11 build 26300.9974, Ryzen 7 7700, MSVC 19.50.35720) and check the PE fields, call count and negative control independently.

I had already built a local source-only prototype before the assignment, so here are its results as independent data points for the review and for the separate CFG build. Setup: a C++ caller compiled with /guard:cf calls through __guard_dispatch_icall_fptr, using a hand-written _load_config_used (size 0x138). The callback table and both guard slots are in .rdata, each with a DIR64 relocation. Every function starts on a 16-byte boundary. Results are the same on the dev and release presets.

Build Windows pe_map_run
Linked without /guard:cf (GuardFlags 0x100, no GUARD_CF) Both slots keep the image's own jmp rax, one call, expected args, absent entry zero calls Same result and trace
Linked with /guard:cf (GuardFlags 0x17500, GUARD_CF set), valid callback Both slots replaced before entry; callback runs with the same trace Image's own slots kept; callback runs, same trace
Linked with /guard:cf, target inside a function (absent from the function table) Fast fail, 0xC0000409, before any output No refusal and no validation; the call runs

The GuardFlags values are as measured on link 14.50 and may differ on other MSVC versions. A target inside a function also runs under both loaders when the image is linked without /guard:cf.

Two things that may help the review:

  • MASM-only objects do not get IMAGE_GUARD_CF_INSTRUMENTED. Even with /guard:cf at link time, Windows then left both slots untouched here, so a CFG build needs at least one object compiled with /guard:cf before the loader applies the guard slots.
  • The CFG bitmap marks a whole 16-byte block valid when an unaligned function starts in it. With unaligned functions, my inside-function target was accepted natively until I aligned every function to 16 bytes.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7107948654 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/903#issuecomment-7107948654). Originally posted by [denn0x](https://github.com/denn0x) on 2026-11-23T16:58:06Z. --- Understood. @triggered02 has the caller and trace, and I won't open a competing PR. I'll review the candidate on this machine (Windows 11 build 26300.9974, Ryzen 7 7700, MSVC 19.50.35720) and check the PE fields, call count and negative control independently. I had already built a local source-only prototype before the assignment, so here are its results as independent data points for the review and for the separate CFG build. Setup: a C++ caller compiled with `/guard:cf` calls through `__guard_dispatch_icall_fptr`, using a hand-written `_load_config_used` (size `0x138`). The callback table and both guard slots are in `.rdata`, each with a DIR64 relocation. Every function starts on a 16-byte boundary. Results are the same on the `dev` and `release` presets. | Build | Windows | `pe_map_run` | | --- | --- | --- | | Linked without `/guard:cf` (GuardFlags `0x100`, no `GUARD_CF`) | Both slots keep the image's own `jmp rax`, one call, expected args, absent entry zero calls | Same result and trace | | Linked with `/guard:cf` (GuardFlags `0x17500`, `GUARD_CF` set), valid callback | Both slots replaced before entry; callback runs with the same trace | Image's own slots kept; callback runs, same trace | | Linked with `/guard:cf`, target inside a function (absent from the function table) | Fast fail, `0xC0000409`, before any output | No refusal and no validation; the call runs | The GuardFlags values are as measured on link 14.50 and may differ on other MSVC versions. A target inside a function also runs under both loaders when the image is linked without `/guard:cf`. Two things that may help the review: - MASM-only objects do not get `IMAGE_GUARD_CF_INSTRUMENTED`. Even with `/guard:cf` at link time, Windows then left both slots untouched here, so a CFG build needs at least one object compiled with `/guard:cf` before the loader applies the guard slots. - The CFG bitmap marks a whole 16-byte block valid when an unaligned function starts in it. With unaligned functions, my inside-function target was accepted natively until I aligned every function to 16 bytes. _AI-assisted (Claude Code)._
triggered02 commented 2026-11-24 06:49:21 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-23T16:59:02Z.


Fixture is in #914. Present/absent/alternate native and pe_map both return 0xb111 / 0xb211 / 0xb151; the PE check records the 0x138 load config, slot at directory+0x78, read-only .rdata and the DIR64 relocation. CFG: Windows refuses the hand-built GuardFlags=0x100 config before entry with STATUS_DATA_ERROR (0xc000003e), while pe_map ignores GuardFlags and returns 0xb111. That is recorded as a refusal/gap, not a pass; a linker-emitted valid CFG config is an open follow-up. No production pe_map change.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7107972433 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/903#issuecomment-7107972433). Originally posted by [triggered02](https://github.com/triggered02) on 2026-11-23T16:59:02Z. --- Fixture is in #914. Present/absent/alternate native and pe_map both return `0xb111` / `0xb211` / `0xb151`; the PE check records the 0x138 load config, slot at directory+0x78, read-only `.rdata` and the DIR64 relocation. CFG: Windows refuses the hand-built `GuardFlags=0x100` config before entry with `STATUS_DATA_ERROR` (`0xc000003e`), while pe_map ignores GuardFlags and returns `0xb111`. That is recorded as a refusal/gap, not a pass; a linker-emitted valid CFG config is an open follow-up. No production `pe_map` change. AI-assisted.
triggered02 commented 2026-11-24 06:49:21 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-23T16:59:22Z.


Thanks @denn0x - #914 is up. The absent/present/alternate cases are the native-vs-pe_map matches; the CFG variant is the hand-built GuardFlags=0x100 config, which Windows refuses before entry with STATUS_DATA_ERROR (0xc000003e) while pe_map ignores GuardFlags and returns 0xb111. A PE-field/call-count review is exactly what I want, especially if you think the CFG case should use a linker-emitted config instead of this hand-built one.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7107981184 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/903#issuecomment-7107981184). Originally posted by [triggered02](https://github.com/triggered02) on 2026-11-23T16:59:22Z. --- Thanks @denn0x - #914 is up. The absent/present/alternate cases are the native-vs-`pe_map` matches; the CFG variant is the hand-built `GuardFlags=0x100` config, which Windows refuses before entry with `STATUS_DATA_ERROR` (`0xc000003e`) while `pe_map` ignores `GuardFlags` and returns `0xb111`. A PE-field/call-count review is exactly what I want, especially if you think the CFG case should use a linker-emitted config instead of this hand-built one.
R0Y00 commented 2026-11-24 06:49:27 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T18:23:17Z.


Completed by #914. The merged source-built fixtures cover absent, present, and alternate callbacks, verify the read-only relocated slot, and compare the same inputs under Windows and pe_map. The separate linker-generated CFG build records the observed boundary: Windows rejects the invalid target, while pe_map currently executes it. Thanks @triggered02 and @denn0x for the fixture and independent evidence. Loader enforcement remains separate from this fixture.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7110090955 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/903#issuecomment-7110090955). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T18:23:17Z. --- Completed by #914. The merged source-built fixtures cover absent, present, and alternate callbacks, verify the read-only relocated slot, and compare the same inputs under Windows and pe_map. The separate linker-generated CFG build records the observed boundary: Windows rejects the invalid target, while pe_map currently executes it. Thanks @triggered02 and @denn0x for the fixture and independent evidence. Loader enforcement remains separate from this fixture.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows#896
No description provided.