startup: check the stand-in switch and trap-log contract #1475
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1482"
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 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.cppandd3d12_xs_device.cppinclude it but use their own logger.The header's documented contracts:
env_onandlogfleave the caller's last error unchanged. An absent variable setsERROR_ENVVAR_NOT_FOUND, and shim callers observeGetLastError.1is on.%X2W_TRAP_LOG%when the path fitsMAX_PATH.first_callslimits 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_logincludes the header, points its own stderr (SetStdHandle) andX2W_TRAP_LOGat files in a fresh%TEMP%folder, and removes that folder at the end. It checks:first_callsat its limit.The change is test, CMake and
docs/startup-runtime.mdonly. The CMake block followsstartup_launch_probe, apart from the other open #1149 PRs.One observation, deliberately not pinned:
env_onreads into a 4-byte buffer. A value of four or more characters does not fit and therefore reads as off:100is on,1000is 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,devpreset (Debug), Windows 11 Pro build 26300.9974, MSVC 19.51.36260, Windows SDK 10.0.26100.0. No GPU is needed.On the unmodified source, the 24 existing tests below passed.
tests/docs_links_check.py,tests/bidi_controls_check.pyandgit diff --checkpassed.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;xmem_shim_*group,xmem_commit_protection,xmem_page_statsandxmem_page_runs_device_warp;startup_xg_bc*checks, the GPU ones as_warp.startup_local_logenv_ondropsSetLastError(saved)logfdrops the last-error restorestartup_xg_bc7_layoutsetsX2W_D3D12_RENDER=0)CREATE_ALWAYSstartup_stubs)length < MAX_PATHcheck droppedfirst_callswith<instead of<=length < MAX_PATH - 1(too strict)The
MAX_PATHmutant cannot be observed on Windows 11 build 26300: when the buffer is too small,GetEnvironmentVariableWleaves 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
AI-assisted (Claude Code).
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).