startup: check the stand-in switch and trap-log contract #1475

Merged
Asimmimx merged 2 commits from upstream-pr/1482 into main 2026-11-24 13:32:20 +00:00
Asimmimx commented 2026-11-24 12:43:52 +00:00 (Migrated from github.com)

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


Change

Refs #1149. This adds a source-built check for src/startup_stubs/local_log.h, the switch reader and line logger that the permissive stand-in DLLs share. It is included by acphal, chad, gameinput, runtime_proxy, xapu, xg_xs, xmem_shim and xmem_mapped_pages. xcrdapi.cpp and d3d12_xs_device.cpp include it but use their own logger.

The header's documented contracts:

  • env_on and logf leave the caller's last error unchanged. An absent variable sets ERROR_ENVVAR_NOT_FOUND, and shim callers observe GetLastError.
  • A value starting with 1 is on.
  • A line is cut to fit the 1,536-byte buffer, ends in CRLF, is written to stderr, and is appended to %X2W_TRAP_LOG% when the path fits MAX_PATH.
  • first_calls limits repeated log lines.

Only 2 of 12 single-point mutants failed any of the 24 non-hardware tests that load these binaries (table below). The other 10, including dropping either last-error restore, LF-only lines, the truncation off by one or removed, no trap-log append and no stderr write, left all 24 passing.

startup_local_log includes the header, points its own stderr (SetStdHandle) and X2W_TRAP_LOG at files in a fresh %TEMP% folder, and removes that folder at the end. It checks:

  • which switch values are on, and that the caller's last error is kept after each read and each log call;
  • the exact stderr and log bytes, with two lines appended after an existing log line and a line with no log set;
  • lines of 1,532, 1,533, 1,534 and 1,933 bytes: the cut is at 1,533 with CRLF intact;
  • a 259-character log path, a longer one, and a folder used as the log;
  • first_calls at its limit.

The change is test, CMake and docs/startup-runtime.md only. The CMake block follows startup_launch_probe, apart from the other open #1149 PRs.

One observation, deliberately not pinned: env_on reads into a 4-byte buffer. A value of four or more characters does not fit and therefore reads as off: 100 is on, 1000 is off. I did not make the test depend on this, because it may not be intended. Tell me whether to pin it as the contract or treat it as a bug.

Verification

Commit 93672b99 (main) plus this change, dev preset (Debug), Windows 11 Pro build 26300.9974, MSVC 19.51.36260, Windows SDK 10.0.26100.0. No GPU is needed.

ctest --preset dev --no-tests=error -R '^(startup_local_log|startup_stubs|startup_xg_bc7_layout)$' -V
#   startup_local_log ... Passed (startup_local_log: ok); startup_stubs ... Passed; startup_xg_bc7_layout ... Passed

On the unmodified source, the 24 existing tests below passed. tests/docs_links_check.py, tests/bidi_controls_check.py and git diff --check passed.

Mutation probe

I applied each mutation to the header alone, rebuilt the affected binaries, ran the tests, then reverted. None of this is committed. "Existing" means the 24 non-hardware tests that load binaries including the header:

  • startup_stubs, startup_acphal_apu_free, startup_heartbeat_commit, startup_storage_directory_batch;
  • the xmem_shim_* group, xmem_commit_protection, xmem_page_stats and xmem_page_runs_device_warp;
  • the startup_xg_bc* checks, the GPU ones as _warp.
Mutant Existing startup_local_log
env_on drops SetLastError(saved) survived fails
logf drops the last-error restore survived fails
any non-empty value is on killed (startup_xg_bc7_layout sets X2W_D3D12_RENDER=0) fails
LF only, no CR survived fails
truncation clamp off by one (NUL before CRLF) survived fails
no truncation clamp (overflow) survived fails
no trap-log append survived fails
trap log opened with CREATE_ALWAYS killed (startup_stubs) fails
length < MAX_PATH check dropped survived survived
no stderr write survived fails
first_calls with < instead of <= survived fails
length < MAX_PATH - 1 (too strict) survived fails

The MAX_PATH mutant cannot be observed on Windows 11 build 26300: when the buffer is too small, GetEnvironmentVariableW leaves only an empty string in it, so the long path opens nothing either way. The test still checks the 259-character boundary and the over-long path.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6582056555 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1482). Originally posted by [Asimmimx](https://github.com/Asimmimx) on 2026-11-24T12:43:52Z. --- ## Change Refs #1149. This adds a source-built check for `src/startup_stubs/local_log.h`, the switch reader and line logger that the permissive stand-in DLLs share. It is included by acphal, chad, gameinput, runtime_proxy, xapu, xg_xs, xmem_shim and xmem_mapped_pages. `xcrdapi.cpp` and `d3d12_xs_device.cpp` include it but use their own logger. The header's documented contracts: - `env_on` and `logf` leave the caller's last error unchanged. An absent variable sets `ERROR_ENVVAR_NOT_FOUND`, and shim callers observe `GetLastError`. - A value starting with `1` is on. - A line is cut to fit the 1,536-byte buffer, ends in CRLF, is written to stderr, and is appended to `%X2W_TRAP_LOG%` when the path fits `MAX_PATH`. - `first_calls` limits repeated log lines. Only 2 of 12 single-point mutants failed any of the 24 non-hardware tests that load these binaries (table below). The other 10, including dropping either last-error restore, LF-only lines, the truncation off by one or removed, no trap-log append and no stderr write, left all 24 passing. `startup_local_log` includes the header, points its own stderr (`SetStdHandle`) and `X2W_TRAP_LOG` at files in a fresh `%TEMP%` folder, and removes that folder at the end. It checks: - which switch values are on, and that the caller's last error is kept after each read and each log call; - the exact stderr and log bytes, with two lines appended after an existing log line and a line with no log set; - lines of 1,532, 1,533, 1,534 and 1,933 bytes: the cut is at 1,533 with CRLF intact; - a 259-character log path, a longer one, and a folder used as the log; - `first_calls` at its limit. The change is test, CMake and `docs/startup-runtime.md` only. The CMake block follows `startup_launch_probe`, apart from the other open #1149 PRs. **One observation, deliberately not pinned:** `env_on` reads into a 4-byte buffer. A value of four or more characters does not fit and therefore reads as off: `100` is on, `1000` is off. I did not make the test depend on this, because it may not be intended. Tell me whether to pin it as the contract or treat it as a bug. ## Verification Commit `93672b99` (`main`) plus this change, `dev` preset (Debug), Windows 11 Pro build 26300.9974, MSVC 19.51.36260, Windows SDK 10.0.26100.0. No GPU is needed. ```powershell ctest --preset dev --no-tests=error -R '^(startup_local_log|startup_stubs|startup_xg_bc7_layout)$' -V # startup_local_log ... Passed (startup_local_log: ok); startup_stubs ... Passed; startup_xg_bc7_layout ... Passed ``` On the unmodified source, the 24 existing tests below passed. `tests/docs_links_check.py`, `tests/bidi_controls_check.py` and `git diff --check` passed. ## Mutation probe I applied each mutation to the header alone, rebuilt the affected binaries, ran the tests, then reverted. None of this is committed. "Existing" means the 24 non-hardware tests that load binaries including the header: - `startup_stubs`, `startup_acphal_apu_free`, `startup_heartbeat_commit`, `startup_storage_directory_batch`; - the `xmem_shim_*` group, `xmem_commit_protection`, `xmem_page_stats` and `xmem_page_runs_device_warp`; - the `startup_xg_bc*` checks, the GPU ones as `_warp`. | Mutant | Existing | `startup_local_log` | |---|---|---| | `env_on` drops `SetLastError(saved)` | survived | fails | | `logf` drops the last-error restore | survived | fails | | any non-empty value is on | killed (`startup_xg_bc7_layout` sets `X2W_D3D12_RENDER=0`) | fails | | LF only, no CR | survived | fails | | truncation clamp off by one (NUL before CRLF) | survived | fails | | no truncation clamp (overflow) | survived | fails | | no trap-log append | survived | fails | | trap log opened with `CREATE_ALWAYS` | killed (`startup_stubs`) | fails | | `length < MAX_PATH` check dropped | survived | **survived** | | no stderr write | survived | fails | | `first_calls` with `<` instead of `<=` | survived | fails | | `length < MAX_PATH - 1` (too strict) | survived | fails | The `MAX_PATH` mutant cannot be observed on Windows 11 build 26300: when the buffer is too small, `GetEnvironmentVariableW` leaves only an empty string in it, so the long path opens nothing either way. The test still checks the 259-character boundary and the over-long path. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-24 14:02:51 +00:00
R0Y00 commented 2026-11-24 14:03:23 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T13:14:15Z.


Resolved the overlapping test with #1477 at 1fd9d20f. One CTest registration now covers switch prefixes, stderr/trap-log byte equality, truncation, exact MAX_PATH cutoff, failed log open, concurrent first_calls and the original page probes. Release startup_local_log and the guard-drop control passed (2/2).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7132542355 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1482#issuecomment-7132542355). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T13:14:15Z. --- Resolved the overlapping test with #1477 at 1fd9d20f. One CTest registration now covers switch prefixes, stderr/trap-log byte equality, truncation, exact MAX_PATH cutoff, failed log open, concurrent first_calls and the original page probes. Release startup_local_log and the guard-drop control passed (2/2).
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!1475
No description provided.