runtime: check Windows commit budget before mapped EXE startup #1474

Merged
Joacoorandom merged 2 commits from upstream-pr/1481 into main 2026-11-24 13:10:02 +00:00
Joacoorandom commented 2026-11-24 12:42:25 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Joacoorandom on 2026-11-24T12:42:25Z.


Summary

Add an optional Windows system commit-headroom preflight to tools/pe_run_package.py, before it parses a package, loads shim DLLs, maps an EXE or enters guest code.

On Windows a large source-built package can fail at startup because the system commit limit (RAM + paging-file backing) is exhausted even when free physical RAM exists. A documented example is Windows error 1455 in VIctory's public README at ffe310e. This PR does not copy or adapt VIctory's GPL code: it uses the public Microsoft GetPerformanceInfo API and a separately authored, read-only implementation.

  • New opt-in --min-commit-mib N: read CommitLimit and CommitTotal from system psapi.dll, multiply by PageSize, and refuse when headroom is below the caller's chosen threshold. No guessed default is imposed.
  • --min-commit-mib 0: report current commit figures without imposing a threshold. If present, both execution and --preflight-only JSON add a host_commit object. Without the flag the existing behavior and JSON shape stay unchanged.
  • Load psapi.dll from System32 only (LOAD_LIBRARY_SEARCH_SYSTEM32) to avoid local DLL planting. Counts are converted in Python integers; a counter over the limit floors headroom to zero instead of wrapping; zero page sizes/limits are rejected; the operating-system error surfaces if the call fails.
  • Budget is checked before even inspecting the package, so a low-budget failure cannot run a guest initializer or load a provider. The reading is a snapshot, not a reservation or a claim that the executable will boot.

Usage

python -B tools/pe_run_package.py pe_map.dll out/source-built-package app.exe --preflight-only --min-commit-mib 0
python -B tools/pe_run_package.py pe_map.dll out/source-built-package app.exe --min-commit-mib 4096 --system kernel32.dll

Verification

Locally on Linux:

python -B tests/host_commit_check.py -v
python -B tests/pe_package_ordinal_plan_check.py
python -B tests/pe_package_preflight_check.py
python -B tests/dependency_paths_check.py
python -B tests/intake/paths_check.py
python -B tests/intake/routing_check.py
python -B tests/docs_links_check.py
python -B tests/bidi_controls_check.py
git diff --check origin/main...HEAD

Observed: 6/6 new portable tests passed, the 7th (live Windows API smoke) skipped on Linux by design; 3/3 ordinal-planning and 13/13 existing preflight tests passed; dependency/path/routing, docs (16 files/334 links) and bidi (1,217 tracked files) checks passed. The native Windows smoke is registered in CTest and will run on CI; no native Windows success is claimed yet.

The tests cover exact-budget and one-MiB-short thresholds, total >= limit, fractional MiB, invalid counters/requirements, correct 32-bit DWORD / pointer-sized SIZE_T API structure, call errors, preflight rejection before inspect()/run(), and opt-in vs unchanged JSON output. No game files or actual allocations are used.

Limits

This addresses an observable host resource precondition, not title-specific requirements, console memory contracts, render pipeline behavior or GTA VI playability. Actual commit demand is unknown and can fluctuate; a passing snapshot is never a guarantee. No binary/data from VIctory or a title is included. MIT-compatible original code only.

AI-assisted. Commit 0400187a.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6582031285 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1481). Originally posted by [Joacoorandom](https://github.com/Joacoorandom) on 2026-11-24T12:42:25Z. --- ## Summary Add an **optional Windows system commit-headroom preflight** to `tools/pe_run_package.py`, before it parses a package, loads shim DLLs, maps an EXE or enters guest code. On Windows a large source-built package can fail at startup because the system **commit limit** (RAM + paging-file backing) is exhausted even when free physical RAM exists. A documented example is Windows error 1455 in [VIctory's public README at `ffe310e`](https://github.com/Marvisak/VIctory/blob/ffe310eb2098e52169f4c44db5ffdabf43a72622/README.md). This PR does not copy or adapt VIctory's GPL code: it uses the public Microsoft `GetPerformanceInfo` API and a separately authored, read-only implementation. - New opt-in `--min-commit-mib N`: read `CommitLimit` and `CommitTotal` from system `psapi.dll`, multiply by `PageSize`, and refuse when headroom is below the caller's chosen threshold. No guessed default is imposed. - `--min-commit-mib 0`: report current commit figures without imposing a threshold. If present, both execution and `--preflight-only` JSON add a `host_commit` object. Without the flag the existing behavior and JSON shape stay unchanged. - Load `psapi.dll` **from System32 only** (`LOAD_LIBRARY_SEARCH_SYSTEM32`) to avoid local DLL planting. Counts are converted in Python integers; a counter over the limit floors headroom to zero instead of wrapping; zero page sizes/limits are rejected; the operating-system error surfaces if the call fails. - Budget is checked **before even inspecting the package**, so a low-budget failure cannot run a guest initializer or load a provider. The reading is a snapshot, not a reservation or a claim that the executable will boot. ## Usage ```powershell python -B tools/pe_run_package.py pe_map.dll out/source-built-package app.exe --preflight-only --min-commit-mib 0 python -B tools/pe_run_package.py pe_map.dll out/source-built-package app.exe --min-commit-mib 4096 --system kernel32.dll ``` ## Verification **Locally on Linux:** ```sh python -B tests/host_commit_check.py -v python -B tests/pe_package_ordinal_plan_check.py python -B tests/pe_package_preflight_check.py python -B tests/dependency_paths_check.py python -B tests/intake/paths_check.py python -B tests/intake/routing_check.py python -B tests/docs_links_check.py python -B tests/bidi_controls_check.py git diff --check origin/main...HEAD ``` Observed: **6/6 new portable tests passed**, the 7th (live Windows API smoke) skipped on Linux by design; 3/3 ordinal-planning and 13/13 existing preflight tests passed; dependency/path/routing, docs (16 files/334 links) and bidi (1,217 tracked files) checks passed. The native Windows smoke is registered in CTest and will run on CI; **no native Windows success is claimed yet**. The tests cover exact-budget and one-MiB-short thresholds, total >= limit, fractional MiB, invalid counters/requirements, correct 32-bit DWORD / pointer-sized `SIZE_T` API structure, call errors, preflight rejection **before** `inspect()`/`run()`, and opt-in vs unchanged JSON output. No game files or actual allocations are used. ## Limits This addresses an observable **host resource precondition**, not title-specific requirements, console memory contracts, render pipeline behavior or GTA VI playability. Actual commit demand is unknown and can fluctuate; a passing snapshot is never a guarantee. No binary/data from VIctory or a title is included. MIT-compatible original code only. AI-assisted. Commit `0400187a`.
tedin7 commented 2026-11-24 13:00:45 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T12:57:38Z.

Review: COMMENTED


Reviewed at commit 0400187aa71257e5d9953779af8aceef789a74b9:

Code & Diff Audit

  • tools/host_commit.py: PerformanceInformation matches Windows PERFORMANCE_INFORMATION layout (DWORD cb, 10 SIZE_T fields, 3 DWORD counts), loads psapi.dll with winmode=0x800 (LOAD_LIBRARY_SEARCH_SYSTEM32), guards against zero PageSize/CommitLimit and CommitTotal > CommitLimit underflow, and checks --min-commit-mib before package resolution, inspect(), or run(). (Minor nit: isinstance(minimum_mib, int) in require_commit_budget() accepts bool if called directly as a library function, though argparse type=int prevents that on the CLI.)
  • P1 test bug on Windows (tests/host_commit_check.py:80): HostCommitChecks.test_winapi_failure_and_unsupported_host calls read_host_commit() without patching host_commit.sys.platform to a non-Windows platform. On Windows (sys.platform == "win32"), read_host_commit() calls GetPerformanceInfo and succeeds instead of raising OSError, causing pe_host_commit_preflight to fail on Windows. Wrapping that assertion in with patch("host_commit.sys.platform", "linux"): will fix it.

Verification

  • Linux checks: tests/docs_links_check.py (16 files, 334 links), tests/bidi_controls_check.py (1,219 files), and git diff --check origin/main..HEAD passed; clean merge with origin/main.
  • Windows Server 2025 (Build 26100, MSVC 14.44.35207):
    • Debug (--preset dev): pe_package_import_closure passed (0.41s), pe_host_commit_preflight FAILED (0.29s) in test_winapi_failure_and_unsupported_host (AssertionError: OSError not raised at tests/host_commit_check.py:80). Release was not run after the Debug CTest failure.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6039587130 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1481#pullrequestreview-6039587130). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T12:57:38Z. **Review:** COMMENTED --- Reviewed at commit `0400187aa71257e5d9953779af8aceef789a74b9`: ### Code & Diff Audit - `tools/host_commit.py`: `PerformanceInformation` matches Windows `PERFORMANCE_INFORMATION` layout (`DWORD cb`, 10 `SIZE_T` fields, 3 `DWORD` counts), loads `psapi.dll` with `winmode=0x800` (`LOAD_LIBRARY_SEARCH_SYSTEM32`), guards against zero `PageSize`/`CommitLimit` and `CommitTotal > CommitLimit` underflow, and checks `--min-commit-mib` before package resolution, `inspect()`, or `run()`. (Minor nit: `isinstance(minimum_mib, int)` in `require_commit_budget()` accepts `bool` if called directly as a library function, though `argparse` `type=int` prevents that on the CLI.) - **P1 test bug on Windows (`tests/host_commit_check.py:80`)**: `HostCommitChecks.test_winapi_failure_and_unsupported_host` calls `read_host_commit()` without patching `host_commit.sys.platform` to a non-Windows platform. On Windows (`sys.platform == "win32"`), `read_host_commit()` calls `GetPerformanceInfo` and succeeds instead of raising `OSError`, causing `pe_host_commit_preflight` to fail on Windows. Wrapping that assertion in `with patch("host_commit.sys.platform", "linux"):` will fix it. ### Verification - **Linux checks**: `tests/docs_links_check.py` (16 files, 334 links), `tests/bidi_controls_check.py` (1,219 files), and `git diff --check origin/main..HEAD` passed; clean merge with `origin/main`. - **Windows Server 2025 (Build 26100, MSVC 14.44.35207)**: - Debug (`--preset dev`): `pe_package_import_closure` passed (`0.41s`), **`pe_host_commit_preflight` FAILED (`0.29s`)** in `test_winapi_failure_and_unsupported_host` (`AssertionError: OSError not raised` at `tests/host_commit_check.py:80`). Release was not run after the Debug CTest failure.
R0Y00 commented 2026-11-24 13:00:55 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T12:58:43Z.


Maintainer update at c0ade401 makes the unsupported-host assertion independent of the test runner OS. On Windows all seven checks passed, including the real System32 GetPerformanceInfo smoke. The real CLI also rejected an excessive budget before resolving the deliberately missing package. Ordinal and preflight checks passed (16/16), as did dependency paths and Markdown links.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7132177443 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1481#issuecomment-7132177443). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T12:58:43Z. --- Maintainer update at c0ade401 makes the unsupported-host assertion independent of the test runner OS. On Windows all seven checks passed, including the real System32 GetPerformanceInfo smoke. The real CLI also rejected an excessive budget before resolving the deliberately missing package. Ordinal and preflight checks passed (16/16), as did dependency paths and Markdown links.
upstream-sync closed this pull request 2026-11-24 14:02:51 +00:00
Sign in to join this conversation.
No reviewers
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!1474
No description provided.