pe: add a --trap-callable diagnostic mode to pe_run_package #1068
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1075"
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 mumba17 on 2026-11-24T00:23:05Z.
Change
Startup checkpoints on #870 need to name the last stage a package reaches while some externals are still missing. So far each checkpoint has bound the missing externals to process-ending stubs in a private harness. This PR adds that diagnostic to
tools/pe_run_package.pyas an opt-in--trap-callable DLL!SYMBOL(orDLL!#ORDINAL, repeatable).--preflight-onlyare unchanged. Unresolved externals are still refused before any image is mapped, andplan(report, allow_external=False)still refuses as before.--trap-callableis bound to a numbered ctypes trap. Any unlisted unresolved external is still refused before mapping:1 unresolved external symbol(s) not listed with --trap-callable, first <image>: <dll>!<symbol>--trap-callable <dll>!<symbol> is not an unresolved externaldll!symbolorder, with their exit codes:trap N: <importers>: <dll>!<symbol>with an unbufferedos.write, but that report is best effort. Termination runs in afinallyblock (TerminateProcesswith0xE7A00000 | N, thenos._exitas a backstop), so a failing diagnostic stream cannot return control to the guest. The trap thunks are kept for the life of the process."unhit_traps".--trap-callableand--preflight-onlyare mutually exclusive.Fixtures and test
tests/trap_missing_exe.cpp, CRT-free and built twice:trap_missing_exeimportstrap_fixture_alpha(six arguments) andtrap_fixture_betafromtrap_fixture.dll, pluskernel32!GetEnvironmentVariableA.TRAP_FIXTURE_MODEselectsalpha(also the default),betaornone. A call that returns makes the EXE exit with0xBAD.trap_missing_data_exe(TRAP_DATA_IMPORT) also importstrap_fixture_dataas data and reads it in modedata.tests/trap_missing_import.def: an import-only library, withtrap_fixture_data DATA. Nothing builds or copiestrap_fixture.dll.tests/trap_missing_check.py, registered aspe_run_package_trap_missing:2 unresolved external symbol(s), first trap_missing_exe.exe: trap_fixture.dll!trap_fixture_alpha, no stdoutalpha0xe7a00001, stderr exactly the listing plustrap 1: trap_missing_exe.exe: trap_fixture.dll!trap_fixture_alphabeta0xe7a00002, trap 2's linenoneexit_code1952 (0x7a0) andunhit_traps[alpha, beta]trap_fixture.dll!absent--trap-callable trap_fixture_alphadatatrap_fixture.dll!trap_fixture_datanot listed--preflight-onlybind_traps, thenos.close(2),sys.stderr = io.StringIO(), call the thunk0xe7a00001, nothing printed after the callMutation controls (local, not committed):
os.write, then terminate)failed-report exit: expected 3886022657, got 0partial list exit: expected 1, got 3886022657Verification
Environment: Windows 11 Pro build 26300, MSVC 19.44.35207.1 x64, Python 3.13.1 (
out/pe-env), branch ond33845b.pe_run_package_trap_missingpasses indevandrelease.cpu_native_startup,cpu_package_shim_lifetime,pe_package_ordinal_plan,cpu_native_acphal_hal,static_exe_intake,pe_package_import_closure,xgameruntime_preflight_stub_refusedand this test. The review revision changes only the opt-in path.pe_package_preflight_check.py,docs_links_check.py,bidi_controls_check.pyandgit diff --checkare clean.Local use (no image or log attached): I ran the main executable from the #870 checkpoints with the two shims, its System32 providers and each of its 22 missing externals listed. No trap was reached, and the process ended with
0x80000003at the refused reserve+commitXMemVirtualAlloc, the stage I reported under the Windows loader. That run used the first revision, which trapped every unresolved name; the same 22 names are now passed explicitly. The 22 are function imports by their call sites in the earlier checkpoints, which is the caller's responsibility under this option. Reaching the later DirectStorage stage underpe_mapalso needs #1085.docs/experiments.mddocuments the option next to the otherpe_run_package.pyoptions.Refs #870.
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T00:28:53Z.
Review: CHANGES_REQUESTED
The source-built Windows trap test passes with normal stderr. I reproduced a missing failure-path control on this candidate. In an isolated Python child, bind a synthetic callable trap, close fd 2, direct Python's stderr to a StringIO, and call the thunk. os.write raises inside ctypes; ctypes returns to the caller, which then exits 0. Ensure the trap terminates even if reporting fails, and add a child-process regression with a failing diagnostic stream.
There is also a resolution boundary to make explicit. A missing PE IAT entry names a symbol or ordinal; it does not say whether the caller invokes it or reads it as data. Binding every unresolved name to a code pointer can let ordinary data reads proceed without taking a trap. Restrict diagnostic bindings to explicitly identified callable imports and keep unclassified imports as preflight failures. Please add a synthetic unresolved data import or an equivalent refusal control. Keep the existing default strict path and same-image fixture.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T00:50:54Z.
Review: APPROVED
Windows Release passed on
80d11300. With fd 2 closed the child now exits through the trap. The unlisted DATA import is refused before mapping, and partial, stale and malformed callable lists also reject. Default and preflight remain strict. This clears my earlier findings. Recheck against #1085 if the two runner branches conflict.Imported from R0Y00/Xbox2Windows. Originally posted by mumba17 on 2026-11-24T00:38:12Z.
Thanks. Both points are addressed in
80d1130.Trap termination when the report fails. I reproduced your case: the previous body (
os.write, thenTerminateProcess) let the child exit 0. The report is now best effort, and termination runs in afinallyblock:TerminateProcess(..., 0xE7A00000 | N), thenos._exitas a backstop. The new child-process regression binds one trap withbind_traps, callsos.close(2), setssys.stderr = io.StringIO()and calls the thunk. It exits0xe7a00001and prints nothing after the call. With the old body restored locally, the check fails withfailed-report exit: expected 3886022657, got 0.Resolution boundary.
--trap-missingis replaced by a repeatable--trap-callable DLL!SYMBOL(orDLL!#ORDINAL). Only listed names get a trap. Any unlisted unresolved external stays a preflight refusal (N unresolved external symbol(s) not listed with --trap-callable, first ...). A listed name that is not an unresolved external and a malformed name are refused too.trap_missing_data_exebuilds the same fixture withtrap_fixture_datadeclaredDATAand read in modedata. With the two callables listed, it is refused before mapping in both modes, namingtrap_fixture.dll!trap_fixture_data. With "trap every unresolved name" restored locally, the check fails at the partial-list refusal.The default strict path, the
--preflight-onlyexclusion and the original same-image fixture cases are unchanged.pe_run_package_trap_missingpasses indevandrelease. The PR body is updated with the full case table.AI-assisted (Claude Code).