pe: load pe_run_package providers without a critical-error dialog #2829
No reviewers
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows!2829
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2829"
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?
@alvaroolt on GitHub · 2026-11-26 12:31 UTC · original
alvaroolt:pe/run-package-quiet-provider-load→main· +122 −3 · 3 files · 4 commits · merged 2026-11-27 18:51 UTCChange
tools/pe_run_package.pyloads each external provider (--shim,--system) withLoadLibraryExW. When a provider is not a loadable image, the loader raises a critical error. The process had noSEM_FAILCRITICALERRORS, so in an interactive session Windows showed a modal "Bad Image" dialog (status0xc0000020) and the load blocked until someone closed it.pe_run_package_cli_checkhits this on every local run:test_positive_preflight_in_process_and_subprocesspasses an emptykernel32_shim.dllin--preflight-onlymode. On this machine the ctest case blocked on the dialog and finished after 227 s.The provider loads now add
SEM_FAILCRITICALERRORSto the calling thread's error mode (SetThreadErrorMode) and restore the previous mode after each load, so the guest still runs with the host's setting. A provider that cannot be loaded keeps the current result: its symbols are reported as missing. Loading the mapper DLL in execution mode is unchanged.docs/experiments.mdgains one paragraph next to the--pin-shimdescription.Verification
Base
8c9f168f(upstreammain), commitab08094d. Windows 11 build 26300.9974, MSVC 14.52, Python 3.12.10. No GPU is involved.New test
test_provider_load_has_no_critical_error_dialog. It wraps theLoadLibraryExWthat the runner uses, recordsGetThreadErrorMode()at each provider load, and checks that the mode after the run equals the mode before it. It passes the systemkernel32.dllas the--shim, so the test does not need a bad image to reach the load, and so it never shows the dialog.Before the change (test only):
Negative control: a mutant that sets the flag but does not restore the previous mode fails with
AssertionError: 1 != 0 : the thread error mode was not restored after the run.After the change:
Result: 14/14 passed on the rebased commit.
pe_run_package_cli_checktook 0.36 s, against 227 s on the dialog before the change.Full suites on the change before the rebase onto
8c9f168f(base02075500):ctest --preset dev --no-tests=error -j 8: 2415/2417 passed.ctest --preset release --no-tests=error -j 8: 2415/2417 passed.linear_buffer_backing_copy_hardwareandcompute_store_aot_lds_shared_hardwareon an NVIDIA GeForce RTX 5080. Both also failed on upstream700522efwithout this change, and neither uses this tool.The CI
Run Python checkscommand passed every check.startup_run_sh_check.pyreturned 77 (capability skip), and that skip is why the runner exits 1.docs_links_check.pypasses on the rebased commit.Evidence and follow-up
No fixture or data file is added. The test writes only a temporary minimal PE32+ executable, as the existing tests in the file already do.
Assumptions:
This change was AI-assisted (Claude Code); I reviewed the diff and the test results.
Checklist
@tedin7 on GitHub · 2026-11-26 12:37 UTC · original · reviewed
Review of head
ab08094d(comment only, not an approval).What is good
quiet_loadersetsSEM_FAILCRITICALERRORSfor the providerLoadLibraryExWcall only. The call sites changed to the 2-argument form consistently (tools/pe_run_package.pyaround lines 192-193). Mapper loading is untouched.LoadLibraryExWcall, so it checks the real Windows state and not a string.One gap in the test (please fix before merge)
set_mode(get_mode(), ...)instead ofget_mode() | SEM_FAILCRITICALERRORS).tests/pe_run_package_cli_check.pyFAILS (rc=1). Good.set_mode(previous.value, None)replaced bypass). The test still PASSES (rc=0). So the "mode is restored after the run" assertion attests/pe_run_package_cli_check.py:149guards nothing on the Win2025 runner. Most likely the thread already has the flag set before the run, sobefore == aftereither way.SetThreadErrorMode(0, ...)first, recordbefore, and restore the original mode in afinally. Then the restore check can fail.Commands run locally
python3 -m py_compile tools/pe_run_package.py tests/pe_run_package_cli_check.py: okpython3 tests/docs_links_check.py: ok;python3 tests/bidi_controls_check.py: ok;git diff --check origin/main...HEAD: okx2w_pipe.py win2025 2829 --py-checks tests/pe_run_package_cli_check.py(dev + release):PYCHECK name=tests/pe_run_package_cli_check.py rc=0--wtand mutation 1: rc=1. With mutation 2: rc=0.AI-assisted; commands listed were executed locally.
@alvaroolt on GitHub · 2026-11-26 12:48 UTC · original
Thanks, @tedin7. Agreed: the restore assertion was vacuous on a thread that already has
SEM_FAILCRITICALERRORS. I reproduced it locally by setting the flag on the thread before running the test: with the no-restore mutant the test passed.Fixed in
3468adbbas you suggested. The test now sets the thread error mode to 0 before recordingbefore, asserts that it starts at 0, and restores the original mode in afinally.tools/pe_run_package.pyis unchanged.Results on
3468adbb. Each case ran with the thread starting at mode 0 and again withSEM_FAILCRITICALERRORSalready set:1 != 0 : the thread error mode was not restored after the run)After the test, the thread is back at the mode it started with (1 in the second column).
AI-assisted (Claude Code); the commands above were run locally on Windows 11 build 26300.9974.
@tedin7 on GitHub · 2026-11-27 18:12 UTC · original · reviewed
Review of
3398fd0cc1(the change from3468adbb, updated with main; the PR's own diff is unchanged). Comment only.quiet_loadersetsSEM_FAILCRITICALERRORSaround the providerLoadLibraryExWcall only and restores the previous thread mode infinally, only when the set succeeded. Both call sites use the new two-argument form. The test now starts the run with thread mode 0, so the restore check fails if the runner forgets to restore the mode; that answers the earlier point about the restore assertion being vacuous.Windows results are in the comment below.
Commands:
git diff origin/main...pull/2829/head(read), plus the Windows commands listed in the comment.AI-assisted; commands listed were executed locally.
@tedin7 on GitHub · 2026-11-27 18:12 UTC · original
Windows Server 2025 verification of
3398fd0cc159f36dbe910a70ccc550bf8e50f45a(MSVC 14.44.35207):cmake --build --preset dev --target trap_missing_data_exe trap_missing_exe;ctest --preset dev -R '^pe_': 19/19 passed, includingpe_run_package_cli_checktests/host_commit_check.pyok,tests/intake/import_forms_check.pyok,tests/pe_package_ordinal_plan_check.pyok,tests/pe_package_preflight_check.pyokAI-assisted; commands listed were executed locally.
@tedin7 on GitHub · 2026-11-27 18:47 UTC · original
Windows Server 2025 re-verification of
c9ff2e8f1f61098d8b914a0199f78e2db7fef0d6(the same change, updated with main again; MSVC 14.44.35207):cmake --build --preset dev --target trap_missing_data_exe trap_missing_exe;ctest --preset dev -R '^pe_': 18/18 passed, includingpe_run_package_cli_checktests/host_commit_check.pyok,tests/intake/import_forms_check.pyok,tests/pe_package_ordinal_plan_check.pyok,tests/pe_package_preflight_check.pyokAI-assisted; commands listed were executed locally.
@pigalot on GitHub · 2026-11-27 18:51 UTC · original · approved these changes
Independently reviewed
c9ff2e8fintegrated overmain7832b98b(treebda46353, clean merge).What I traced.
quiet_loaderORsSEM_FAILCRITICALERRORSinto the thread's error mode for each providerLoadLibraryExWcall. It restores the previous mode infinally, and only if the set succeeded. Both provider call sites use the two-argument form, and the mapper load is untouched.What I ran. I ran this in an interactive desktop session, the case the PR fixes; the Win2025 host and CI have no desktop.
python -B tests/pe_run_package_cli_check.pypassed 4/4 in all 3 runs, in 0.46–0.51 s wall time. That includestest_positive_preflight_in_process_and_subprocess, whose 0-byte--shimis the input that used to block.MZ-only header and a PE cut in half, each passed as--shim kernel32.dll <image>totools/pe_run_package.py <mapper> <pkg> app.exe --preflight-onlyin a subprocess:missing=['app.exe: kernel32.dll!ExitProcess'];pe_map,trap_missing_exeandtrap_missing_data_exeindevandrelease, then ranctest --test-dir out/build/<preset> --no-tests=error -j 4 --output-on-failure -R '^pe_': 19/19 in Debug and Release/O2, with no skips.Mutant. I dropped the flag (
set_mode(get_mode(), ...)). That failstest_provider_load_has_no_critical_error_dialogwithLoadLibraryExW(C:\Windows\System32\kernel32.dll) ran with thread error mode 0x0. The no-restore mutant is covered by the test's mode-0 start, as shown in the earlier rounds.I did not run
mainon purpose, because there the empty-shim case puts up a blocking modal dialog.git diff --checkis clean.Verdict: approve on
c9ff2e8f.Environment: Windows 11 25H2 build 26200.9974, interactive desktop session; MSVC 19.52.37029; Python 3.12.10.
CI:
Build and test on Windowspasses onc9ff2e8f. There are no review threads.This reply was AI-assisted.