runtime: verify startup_stubs trap header switches and exit codes #1548

Merged
Ammmae0x merged 3 commits from upstream-pr/1555 into main 2026-11-24 20:43:13 +00:00
Ammmae0x commented 2026-11-24 13:53:08 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-24T13:53:08Z.


Change

Adds a standalone, device-free C++17 test executable (tests/startup_trap_header_check.cpp) verifying src/startup_stubs/trap.h (Refs #1149):

  • x2w_trap::exit_code: 8-bit module ID and export index bit-masking (0xE2570000 | ...).
  • x2w_trap::listed: unset/empty environment variables, wildcard * vs literal *alpha, comma-separated exact matching (first/middle/last/empty items, case sensitivity, superstring/prefix rejection), and 2047-byte accepted vs 2048-byte rejected buffer boundaries.
  • X2W_TRAP_EXPORT: X2W_TRAP_CONTINUE returning 0 with x2w-continue, X2W_TRAP_FAIL returning E_FAIL (0x80004005) with x2w-fail, continue-over-fail precedence when listed in both, x2w_trap::write_all null/invalid handle safety, and a child-process default trap check verifying TerminateProcess exit code and matching x2w-trap lines on stderr and X2W_TRAP_LOG.
  • Registers startup_trap_header_check, startup_trap_header, and WILL_FAIL negative controls startup_trap_header_prefix_control (--mutate prefix-match) and startup_trap_header_precedence_control (--mutate fail-first) in CMakeLists.txt, and documents the check in docs/startup-runtime.md.

Verification

Verified on commit e451c80d (rebased onto upstream/main 8f438025):

  • & .\tools\dev.ps1; ctest --preset dev -N -> Total Tests: 983
  • cmake --build --preset dev --target startup_trap_header_check -> exit 0 (0 errors, 0 warnings)
  • cmake --build --preset release --target startup_trap_header_check -> exit 0 (0 errors, 0 warnings)
  • ctest --preset dev --no-tests=error -R "^startup_trap_header(_prefix_control|_precedence_control)?$" -E "cpu_native_archive_" -V -> 3 passed, 0 skipped, 0 failed (startup_trap_header: 38 cases; startup_trap_header_prefix_control and startup_trap_header_precedence_control: WILL_FAIL passed)
  • ctest --preset release --no-tests=error -R "^startup_trap_header(_prefix_control|_precedence_control)?$" -E "cpu_native_archive_" -V -> 3 passed, 0 skipped, 0 failed (startup_trap_header: 38 cases; startup_trap_header_prefix_control and startup_trap_header_precedence_control: WILL_FAIL passed)
  • .\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py -> form coverage checks passed (exit 0)
  • .\out\pe-env\Scripts\python.exe -B tests/docs_links_check.py -> Checked 16 Markdown files and 342 links. (exit 0)
  • .\out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py -> Checked 1245 tracked source, script and build/CI files: no bidirectional controls. (exit 0)

Evidence and follow-up

  • tests/startup_trap_header_check.cpp is an original test written for this repository against src/startup_stubs/trap.h and requires no GPU or title files.
  • See the startup runtime notes for the reproduction command.

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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6583341923 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1555). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-24T13:53:08Z. --- ## Change Adds a standalone, device-free C++17 test executable (`tests/startup_trap_header_check.cpp`) verifying `src/startup_stubs/trap.h` (`Refs #1149`): - `x2w_trap::exit_code`: 8-bit module ID and export index bit-masking (`0xE2570000 | ...`). - `x2w_trap::listed`: unset/empty environment variables, wildcard `*` vs literal `*alpha`, comma-separated exact matching (first/middle/last/empty items, case sensitivity, superstring/prefix rejection), and 2047-byte accepted vs 2048-byte rejected buffer boundaries. - `X2W_TRAP_EXPORT`: `X2W_TRAP_CONTINUE` returning `0` with `x2w-continue`, `X2W_TRAP_FAIL` returning `E_FAIL` (`0x80004005`) with `x2w-fail`, continue-over-fail precedence when listed in both, `x2w_trap::write_all` null/invalid handle safety, and a child-process default trap check verifying `TerminateProcess` exit code and matching `x2w-trap` lines on `stderr` and `X2W_TRAP_LOG`. - Registers `startup_trap_header_check`, `startup_trap_header`, and `WILL_FAIL` negative controls `startup_trap_header_prefix_control` (`--mutate prefix-match`) and `startup_trap_header_precedence_control` (`--mutate fail-first`) in `CMakeLists.txt`, and documents the check in `docs/startup-runtime.md`. ## Verification Verified on commit `e451c80d` (rebased onto `upstream/main` `8f438025`): - `& .\tools\dev.ps1; ctest --preset dev -N` -> `Total Tests: 983` - `cmake --build --preset dev --target startup_trap_header_check` -> exit 0 (0 errors, 0 warnings) - `cmake --build --preset release --target startup_trap_header_check` -> exit 0 (0 errors, 0 warnings) - `ctest --preset dev --no-tests=error -R "^startup_trap_header(_prefix_control|_precedence_control)?$" -E "cpu_native_archive_" -V` -> **3 passed, 0 skipped, 0 failed** (`startup_trap_header`: 38 cases; `startup_trap_header_prefix_control` and `startup_trap_header_precedence_control`: `WILL_FAIL` passed) - `ctest --preset release --no-tests=error -R "^startup_trap_header(_prefix_control|_precedence_control)?$" -E "cpu_native_archive_" -V` -> **3 passed, 0 skipped, 0 failed** (`startup_trap_header`: 38 cases; `startup_trap_header_prefix_control` and `startup_trap_header_precedence_control`: `WILL_FAIL` passed) - `.\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py` -> `form coverage checks passed` (exit 0) - `.\out\pe-env\Scripts\python.exe -B tests/docs_links_check.py` -> `Checked 16 Markdown files and 342 links.` (exit 0) - `.\out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py` -> `Checked 1245 tracked source, script and build/CI files: no bidirectional controls.` (exit 0) ## Evidence and follow-up - `tests/startup_trap_header_check.cpp` is an original test written for this repository against `src/startup_stubs/trap.h` and requires no GPU or title files. - See [the startup runtime notes](docs/startup-runtime.md) for the reproduction command. ## 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.
tedin7 commented 2026-11-24 16:03:05 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T16:00:58Z.

Review: COMMENTED


Review: trap header switches and exit codes

Verified

  • PR is open, not a draft, no earlier reviews or comments.
  • Built tests/startup_trap_header_check.cpp with a MinGW-w64 cross compiler (-std=c++17 -O1 -static -I src) and ran it under Wine: startup_trap_header: PASS (38 cases), exit 0. The 38 matches the count in docs/startup-runtime.md. Local shim: _ReturnAddress() was replaced with __builtin_return_address(0) because MinGW has no such intrinsic. Header semantics are otherwise untouched.
  • python tests/docs_links_check.py: self-test passed, 16 files / 342 links OK.
  • CMake: registration follows the neighbouring startup_local_log pattern (include dir, C++17, two WILL_FAIL controls). No new dependencies.
  • Mutation testing of a copy of src/startup_stubs/trap.h (one change at a time, test rebuilt and run each time). Detected (test fails): exit-code base constant changed; module shift 8 -> 16; wildcard * branch removed; wildcard treated as prefix; case-insensitive compare; item length check removed (prefix match); list buffer 2048 -> 4096; E_FAIL value changed; CONTINUE return value 0 -> 1; continues() reading the FAIL variable; continue/fail precedence swapped (test process is killed by its own trap, rc != 0); X2W_TRAP_LOG write removed; stderr write removed; log file opened with CREATE_ALWAYS instead of append; CRLF -> LF; x2w-continue tag renamed; TerminateProcess code with index forced to 0 / literal 1 / ExitProcess(3) instead of terminating.
  • Equivalent mutants (not findings): n >= sizeof(list) -> n > cannot differ, because GetEnvironmentVariableA returns length+1 when the buffer is too small; exit=0x%08lx -> 0x%lx is invisible because every code has 8 hex digits.

Findings

P2 - the "masks to 8 bits" exit-code case cannot detect removal of either mask (tests/startup_trap_header_check.cpp:64)

  • Input: exit_code(0x1ABu, 0x2CDu) expected 0xE257ABCDu.
  • The overflow bits (0x100 from the module id, 0x200 from the index) land on bits that are already set in the other OR operands (0xE257 already has bit 16 set; 0xAB00 already has bit 9 set). So the unmasked result is still 0xE257ABCD.
  • Reproduced: in trap.h:28 change ((module_id & 0xFFu) << 8) | (index & 0xFFu) to (module_id << 8) | index (and separately drop only one mask): test still prints PASS (38 cases), exit 0. Expected: FAIL.
  • Suggested inputs that cannot collide: e.g. module 0x100, index 0 (expect 0xE2570000) and module 0, index 0x100 (expect 0xE2570000), or module 0x1FF / index 0x200 checked separately. The two 8-bit-masking clauses in the documentation (docs/startup-runtime.md, "8-bit module/index bit-masking") are therefore unguarded.

P2 - the child process can be left running when it does not exit (tests/startup_trap_header_check.cpp:230-235)

  • WaitForSingleObject(pi.hProcess, 10000) is followed by CloseHandle with no TerminateProcess on WAIT_TIMEOUT.
  • Reproduced by mutating fire() to Sleep(INFINITE) instead of TerminateProcess: the test reports FAIL child trap terminates promptly and exits 1, but the --child-fire process stayed alive (still running 4+ minutes later, and it kept the stdout pipe open so the parent shell/ctest output pipe never closed). Expected: the test kills the child on timeout.
  • Fix: if wait != WAIT_OBJECT_0, call TerminateProcess(pi.hProcess, 1) before closing the handle (or use a job object with kill-on-close).

nit - an aborted or failed run leaves a temp folder that can poison later runs (tests/startup_trap_header_check.cpp:132)

  • The folder name is x2w_trap_hdr_<pid> and is created with CREATE_NEW semantics. When the test dies mid-run (for example the precedence mutant is killed by its own trap, or the timeout case above leaves files open), the folder stays. A later run with the same PID fails at "create temporary trap folder" (GetLastError=183) before testing anything. This was easy to hit under Wine (deterministic PIDs); on Windows it needs PID reuse, so it is rare. Consider a unique suffix (tick count / GUID) or removing a stale folder first.

nit - the child exit code is compared with the code under test (tests/startup_trap_header_check.cpp:236)

  • child_exit == x2w_trap::exit_code(0x42u, 0x07u) recomputes the expectation with the header. It is covered independently by the literal checks at lines 61-64 and the exit=0xe2574207 log literal, so no regression is missed today, but a literal 0xE2574207u would be self-contained.

nit - whitespace and unmatched-case behaviour is not pinned (tests/startup_trap_header_check.cpp:67-119)

  • A mutation that trims leading spaces in list items ("Alpha, Beta" matching Beta) passes. The header currently treats items literally; if that is intended, one case such as "Alpha, Beta" must not match Beta would document it.

nit - docs (docs/startup-runtime.md, Switches table)

  • The new section documents X2W_TRAP_FAIL, but the Switches table still lists only X2W_TRAP_CONTINUE. Optional.

nit - controls are redundant with the main run

  • startup_trap_header_prefix_control and startup_trap_header_precedence_control flip the test's own expectation, so they fail on the correct header and pass WILL_FAIL only if the main run's assertion would also fail. They are consistent with the existing startup_local_log_guard_drop_control pattern; I found no defect, only duplication.

Not verified

  • Linux only: cross-compiled with MinGW-w64 and run under Wine, not with MSVC on Windows. _ReturnAddress / __fastfail / MSVC codegen of the real header were not exercised (shimmed as described above).
  • The dev / pr CMake presets and the actual ctest invocation were not run; test names and regex in the docs were checked by reading only.
  • Exit-code portability: the 32-bit Windows exit code (0xE2574207) is checked only as a Wine/Windows value; no POSIX 8-bit truncation case applies because the test is Win32-only.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6042805357 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1555#pullrequestreview-6042805357). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T16:00:58Z. **Review:** COMMENTED --- ## Review: trap header switches and exit codes ### Verified - PR is open, not a draft, no earlier reviews or comments. - Built `tests/startup_trap_header_check.cpp` with a MinGW-w64 cross compiler (`-std=c++17 -O1 -static -I src`) and ran it under Wine: `startup_trap_header: PASS (38 cases)`, exit 0. The 38 matches the count in `docs/startup-runtime.md`. Local shim: `_ReturnAddress()` was replaced with `__builtin_return_address(0)` because MinGW has no such intrinsic. Header semantics are otherwise untouched. - `python tests/docs_links_check.py`: self-test passed, 16 files / 342 links OK. - CMake: registration follows the neighbouring `startup_local_log` pattern (include dir, C++17, two `WILL_FAIL` controls). No new dependencies. - Mutation testing of a copy of `src/startup_stubs/trap.h` (one change at a time, test rebuilt and run each time). **Detected (test fails):** exit-code base constant changed; module shift 8 -> 16; wildcard `*` branch removed; wildcard treated as prefix; case-insensitive compare; item length check removed (prefix match); list buffer 2048 -> 4096; E_FAIL value changed; CONTINUE return value 0 -> 1; `continues()` reading the FAIL variable; continue/fail precedence swapped (test process is killed by its own trap, rc != 0); X2W_TRAP_LOG write removed; stderr write removed; log file opened with CREATE_ALWAYS instead of append; CRLF -> LF; `x2w-continue` tag renamed; `TerminateProcess` code with index forced to 0 / literal 1 / `ExitProcess(3)` instead of terminating. - Equivalent mutants (not findings): `n >= sizeof(list)` -> `n >` cannot differ, because `GetEnvironmentVariableA` returns length+1 when the buffer is too small; `exit=0x%08lx` -> `0x%lx` is invisible because every code has 8 hex digits. ### Findings **P2 - the "masks to 8 bits" exit-code case cannot detect removal of either mask** (`tests/startup_trap_header_check.cpp:64`) - Input: `exit_code(0x1ABu, 0x2CDu)` expected `0xE257ABCDu`. - The overflow bits (0x100 from the module id, 0x200 from the index) land on bits that are already set in the other OR operands (`0xE257` already has bit 16 set; `0xAB00` already has bit 9 set). So the unmasked result is still `0xE257ABCD`. - Reproduced: in `trap.h:28` change `((module_id & 0xFFu) << 8) | (index & 0xFFu)` to `(module_id << 8) | index` (and separately drop only one mask): test still prints PASS (38 cases), exit 0. Expected: FAIL. - Suggested inputs that cannot collide: e.g. module `0x100`, index `0` (expect `0xE2570000`) and module `0`, index `0x100` (expect `0xE2570000`), or module `0x1FF` / index `0x200` checked separately. The two 8-bit-masking clauses in the documentation (`docs/startup-runtime.md`, "8-bit module/index bit-masking") are therefore unguarded. **P2 - the child process can be left running when it does not exit** (`tests/startup_trap_header_check.cpp:230-235`) - `WaitForSingleObject(pi.hProcess, 10000)` is followed by `CloseHandle` with no `TerminateProcess` on `WAIT_TIMEOUT`. - Reproduced by mutating `fire()` to `Sleep(INFINITE)` instead of `TerminateProcess`: the test reports `FAIL child trap terminates promptly` and exits 1, but the `--child-fire` process stayed alive (still running 4+ minutes later, and it kept the stdout pipe open so the parent shell/ctest output pipe never closed). Expected: the test kills the child on timeout. - Fix: if `wait != WAIT_OBJECT_0`, call `TerminateProcess(pi.hProcess, 1)` before closing the handle (or use a job object with kill-on-close). **nit - an aborted or failed run leaves a temp folder that can poison later runs** (`tests/startup_trap_header_check.cpp:132`) - The folder name is `x2w_trap_hdr_<pid>` and is created with `CREATE_NEW` semantics. When the test dies mid-run (for example the precedence mutant is killed by its own trap, or the timeout case above leaves files open), the folder stays. A later run with the same PID fails at "create temporary trap folder" (GetLastError=183) before testing anything. This was easy to hit under Wine (deterministic PIDs); on Windows it needs PID reuse, so it is rare. Consider a unique suffix (tick count / GUID) or removing a stale folder first. **nit - the child exit code is compared with the code under test** (`tests/startup_trap_header_check.cpp:236`) - `child_exit == x2w_trap::exit_code(0x42u, 0x07u)` recomputes the expectation with the header. It is covered independently by the literal checks at lines 61-64 and the `exit=0xe2574207` log literal, so no regression is missed today, but a literal `0xE2574207u` would be self-contained. **nit - whitespace and unmatched-case behaviour is not pinned** (`tests/startup_trap_header_check.cpp:67-119`) - A mutation that trims leading spaces in list items (`"Alpha, Beta"` matching `Beta`) passes. The header currently treats items literally; if that is intended, one case such as `"Alpha, Beta"` must not match `Beta` would document it. **nit - docs** (`docs/startup-runtime.md`, Switches table) - The new section documents `X2W_TRAP_FAIL`, but the Switches table still lists only `X2W_TRAP_CONTINUE`. Optional. **nit - controls are redundant with the main run** - `startup_trap_header_prefix_control` and `startup_trap_header_precedence_control` flip the test's own expectation, so they fail on the correct header and pass `WILL_FAIL` only if the main run's assertion would also fail. They are consistent with the existing `startup_local_log_guard_drop_control` pattern; I found no defect, only duplication. ### Not verified - Linux only: cross-compiled with MinGW-w64 and run under Wine, not with MSVC on Windows. `_ReturnAddress` / `__fastfail` / MSVC codegen of the real header were not exercised (shimmed as described above). - The `dev` / `pr` CMake presets and the actual `ctest` invocation were not run; test names and regex in the docs were checked by reading only. - Exit-code portability: the 32-bit Windows exit code (`0xE2574207`) is checked only as a Wine/Windows value; no POSIX 8-bit truncation case applies because the test is Win32-only. AI-assisted; commands listed were executed locally.
Ammmae0x commented 2026-11-24 17:02:10 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-24T16:53:12Z.


Updated tests/startup_trap_header_check.cpp and docs/startup-runtime.md (commit 950c0578) with distinct 8-bit overflow mask checks (module and index separately verified against 0xE2570000u), child process termination on timeout, and updated case count to 40, and verified in dev and release. AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7138359221 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1555#issuecomment-7138359221). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-24T16:53:12Z. --- Updated `tests/startup_trap_header_check.cpp` and `docs/startup-runtime.md` (commit 950c0578) with distinct 8-bit overflow mask checks (module and index separately verified against `0xE2570000u`), child process termination on timeout, and updated case count to 40, and verified in dev and release. AI-assisted.
tedin7 commented 2026-11-24 18:02:12 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T17:03:51Z.

Review: COMMENTED


Re-review at head_sha: 950c057885270b968735a32d5c8b4787b240d1ee (new commit 950c0578 on top of e451c80d).

Findings

P2 still open, half fixed: the module mask is still unguarded (tests/startup_trap_header_check.cpp:64)

  • The new case exit_code(0x100u, 0u) == 0xE2570000u ("masks module overflow bits") cannot fail. Without the mask the module's bit 8 lands on bit 16 of the result, and 0xE257 already has bit 16 set (0x57 = 0101 0111). So the unmasked value is still 0xE2570000.
  • Reproduced: in a copy of src/startup_stubs/trap.h:28 I changed (module_id & 0xFFu) << 8 to (module_id) << 8. The test still prints startup_trap_header: PASS (40 cases), exit 0. Expected: FAIL.
  • The index case is fixed: dropping (index & 0xFFu) now gives FAIL exit_code masks index overflow bits, 1 of 40 FAILED, exit 1.
  • Fix: use a module value whose shifted overflow bit hits a clear bit of 0xE257. Bit 19 is clear (bit 3 of 0x57), so exit_code(0x800u, 0u) == 0xE2570000u. I added that one line to a local copy: with the module mask removed it fails (1 of 41 FAILED), and with the unmodified header it passes (PASS (41 cases)). docs/startup-runtime.md would then say 41 instead of 40.

P2 resolved: child process left running on timeout. fire() is now followed by if (wait != WAIT_OBJECT_0) TerminateProcess(pi.hProcess, 1); before the handles are closed. Reproduced the old failure scenario: I changed fire() in a copy of the header to Sleep(INFINITE). The test now reports FAIL child trap terminates promptly and FAIL child trap exits with encoded module/index exit code (2 of 40 FAILED) and returns, and pgrep afterwards shows no leftover --child-fire process.

Other changes in the commit, no issue: the temp folder name now has GetTickCount64() appended (avoids a reused-PID collision); the child exit code is checked against the literal 0xE2574207u instead of calling exit_code() again, so the check no longer shares code with the thing it tests; docs count changed 38 -> 40, which matches the test output.

Verified

Limits: Linux x86-64 only. This file is Windows code, so I cross-built it with MinGW-w64 (x86_64-w64-mingw32-g++ -std=c++17 -O1 -static -I src) and ran it under Wine. Not MSVC, not real Windows, no ctest. Local shim: _ReturnAddress() replaced by __builtin_return_address(0) in both the test and a copy of trap.h (MinGW has no such intrinsic); the semantics of the header are otherwise untouched.

  • Unmodified head: startup_trap_header: PASS (40 cases), exit 0.
  • Mutation (index mask removed): detected, as above.
  • Mutation (module mask removed): escapes, as above.
  • Mutation (TerminateProcess -> Sleep(INFINITE) in fire()): detected, child is killed, no leftover process.
  • All mutations were made on a copy of trap.h outside the PR worktree.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6043805933 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1555#pullrequestreview-6043805933). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T17:03:51Z. **Review:** COMMENTED --- Re-review at `head_sha`: `950c057885270b968735a32d5c8b4787b240d1ee` (new commit `950c0578` on top of `e451c80d`). ### Findings **P2 still open, half fixed: the module mask is still unguarded** (`tests/startup_trap_header_check.cpp:64`) - The new case `exit_code(0x100u, 0u) == 0xE2570000u` ("masks module overflow bits") cannot fail. Without the mask the module's bit 8 lands on bit 16 of the result, and `0xE257` already has bit 16 set (`0x57` = `0101 0111`). So the unmasked value is still `0xE2570000`. - Reproduced: in a copy of `src/startup_stubs/trap.h:28` I changed `(module_id & 0xFFu) << 8` to `(module_id) << 8`. The test still prints `startup_trap_header: PASS (40 cases)`, exit 0. Expected: FAIL. - The index case is fixed: dropping `(index & 0xFFu)` now gives `FAIL exit_code masks index overflow bits`, `1 of 40 FAILED`, exit 1. - Fix: use a module value whose shifted overflow bit hits a clear bit of `0xE257`. Bit 19 is clear (bit 3 of `0x57`), so `exit_code(0x800u, 0u) == 0xE2570000u`. I added that one line to a local copy: with the module mask removed it fails (`1 of 41 FAILED`), and with the unmodified header it passes (`PASS (41 cases)`). `docs/startup-runtime.md` would then say 41 instead of 40. **P2 resolved: child process left running on timeout.** `fire()` is now followed by `if (wait != WAIT_OBJECT_0) TerminateProcess(pi.hProcess, 1);` before the handles are closed. Reproduced the old failure scenario: I changed `fire()` in a copy of the header to `Sleep(INFINITE)`. The test now reports `FAIL child trap terminates promptly` and `FAIL child trap exits with encoded module/index exit code` (2 of 40 FAILED) and returns, and `pgrep` afterwards shows no leftover `--child-fire` process. **Other changes in the commit, no issue:** the temp folder name now has `GetTickCount64()` appended (avoids a reused-PID collision); the child exit code is checked against the literal `0xE2574207u` instead of calling `exit_code()` again, so the check no longer shares code with the thing it tests; docs count changed 38 -> 40, which matches the test output. ### Verified Limits: Linux x86-64 only. This file is Windows code, so I cross-built it with MinGW-w64 (`x86_64-w64-mingw32-g++ -std=c++17 -O1 -static -I src`) and ran it under Wine. Not MSVC, not real Windows, no ctest. Local shim: `_ReturnAddress()` replaced by `__builtin_return_address(0)` in both the test and a copy of `trap.h` (MinGW has no such intrinsic); the semantics of the header are otherwise untouched. - Unmodified head: `startup_trap_header: PASS (40 cases)`, exit 0. - Mutation (index mask removed): detected, as above. - Mutation (module mask removed): **escapes**, as above. - Mutation (`TerminateProcess` -> `Sleep(INFINITE)` in `fire()`): detected, child is killed, no leftover process. - All mutations were made on a copy of `trap.h` outside the PR worktree. AI-assisted; commands listed were executed locally.
Ammmae0x commented 2026-11-24 18:02:58 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-24T17:12:17Z.


Updated tests/startup_trap_header_check.cpp (added the bit 19 module-overflow assertion exit_code(0x800u, 0u) == 0xE2570000u) and docs/startup-runtime.md (updated case count to 41) in commit 0a0dbf82, and verified in dev and release. AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7138842788 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1555#issuecomment-7138842788). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-24T17:12:17Z. --- Updated `tests/startup_trap_header_check.cpp` (added the bit 19 module-overflow assertion `exit_code(0x800u, 0u) == 0xE2570000u`) and `docs/startup-runtime.md` (updated case count to 41) in commit 0a0dbf82, and verified in dev and release. AI-assisted.
tedin7 commented 2026-11-24 20:00:21 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T19:28:36Z.

Review: COMMENTED


Re-review at 0a0dbf8222a4fcbe4dcaa874de080103cbe2d34c (new commit 0a0dbf82 on top of 950c0578). Comment only, not an approval.

The earlier P2 is fixed

My previous review said the module-mask case could not fail, because bit 8 of the module id lands on a bit of 0xE257 that is already set. The new line exit_code(0x800u, 0u) == 0xE2570000u (tests/startup_trap_header_check.cpp, "masks module overflow bit 19") uses bit 19, which is clear in 0xE257, so it can fail. Confirmed on this head:

Run (copy of trap.h) Result
unmodified PASS (41 cases), exit 0
module mask removed 1 of 41 FAILED: "exit_code masks module overflow bit 19", exit 1
index mask removed 1 of 41 FAILED: "exit_code masks index overflow bits", exit 1
module mask narrowed to 0x7F 2 of 41 FAILED ("max 8-bit fields", "masks module and index to 8 bits")
E_FAIL value changed to 0x80004006 1 of 41 FAILED: "X2W_TRAP_FAIL export returns E_FAIL"

The case count in docs/startup-runtime.md now says 41 and matches the output. The child-process timeout kill and the unique temp folder name from the previous commit are still in place.

Commands run

  • x86_64-w64-mingw32-g++ -std=c++17 -O1 -static on the test, run under wine, with the same two shims as before applied to a copy of trap.h outside the worktree: _ReturnAddress() to __builtin_return_address(0), and __fastfail to __builtin_trap after TerminateProcess.
  • The four mutations above, each on a copy of the header; the PR worktree is unchanged.
  • git diff --check origin/main...HEAD: clean. docs_links_check.py (16 files, 342 links) and bidi_controls_check.py (1245 files): pass.

Still open, all nits

  • Whitespace in list items ("Alpha, Beta" and Beta) is still not pinned by a case.
  • docs/startup-runtime.md Switches table (line 290) lists X2W_TRAP_CONTINUE but not X2W_TRAP_FAIL.
  • The two WILL_FAIL controls flip the test's own expectation, so they add no detection beyond the main run; they match the existing startup_local_log_guard_drop_control style.

Not verified

Linux only: cross-built with MinGW-w64 and run under wine, not with MSVC on Windows. _ReturnAddress and __fastfail were shimmed as above. The ctest presets were not run.

Verdict

No P1 or P2 left on this head. The test now guards both masks, and the case count and docs agree.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6045928950 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1555#pullrequestreview-6045928950). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T19:28:36Z. **Review:** COMMENTED --- Re-review at `0a0dbf8222a4fcbe4dcaa874de080103cbe2d34c` (new commit `0a0dbf82` on top of `950c0578`). Comment only, not an approval. ## The earlier P2 is fixed My previous review said the module-mask case could not fail, because bit 8 of the module id lands on a bit of `0xE257` that is already set. The new line `exit_code(0x800u, 0u) == 0xE2570000u` (`tests/startup_trap_header_check.cpp`, "masks module overflow bit 19") uses bit 19, which is clear in `0xE257`, so it can fail. Confirmed on this head: | Run (copy of `trap.h`) | Result | |---|---| | unmodified | `PASS (41 cases)`, exit 0 | | module mask removed | `1 of 41 FAILED`: "exit_code masks module overflow bit 19", exit 1 | | index mask removed | `1 of 41 FAILED`: "exit_code masks index overflow bits", exit 1 | | module mask narrowed to 0x7F | `2 of 41 FAILED` ("max 8-bit fields", "masks module and index to 8 bits") | | E_FAIL value changed to 0x80004006 | `1 of 41 FAILED`: "X2W_TRAP_FAIL export returns E_FAIL" | The case count in `docs/startup-runtime.md` now says 41 and matches the output. The child-process timeout kill and the unique temp folder name from the previous commit are still in place. ## Commands run - `x86_64-w64-mingw32-g++ -std=c++17 -O1 -static` on the test, run under wine, with the same two shims as before applied to a copy of `trap.h` outside the worktree: `_ReturnAddress()` to `__builtin_return_address(0)`, and `__fastfail` to `__builtin_trap` after `TerminateProcess`. - The four mutations above, each on a copy of the header; the PR worktree is unchanged. - `git diff --check origin/main...HEAD`: clean. `docs_links_check.py` (16 files, 342 links) and `bidi_controls_check.py` (1245 files): pass. ## Still open, all nits - Whitespace in list items (`"Alpha, Beta"` and `Beta`) is still not pinned by a case. - `docs/startup-runtime.md` Switches table (line 290) lists `X2W_TRAP_CONTINUE` but not `X2W_TRAP_FAIL`. - The two `WILL_FAIL` controls flip the test's own expectation, so they add no detection beyond the main run; they match the existing `startup_local_log_guard_drop_control` style. ## Not verified Linux only: cross-built with MinGW-w64 and run under wine, not with MSVC on Windows. `_ReturnAddress` and `__fastfail` were shimmed as above. The `ctest` presets were not run. ## Verdict No P1 or P2 left on this head. The test now guards both masks, and the case count and docs agree. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-24 21:00:43 +00:00
tedin7 commented 2026-11-24 21:00:43 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T20:33:31Z.

Review: COMMENTED


Review of 0a0dbf8222a4fcbe4dcaa874de080103cbe2d34c (startup_trap_header_check, TIER_B_TESTS), checked out at exactly that SHA. No P1, no P2 found. Delta read of the earlier reviews: the earlier P2 (module mask bit 19 unguarded) is fixed by the new exit_code(0x800u, 0u) case.

Commands executed locally (Linux):

  • git diff --check origin/main...HEAD: rc 0
  • python3 tests/docs_links_check.py: rc 0 (16 files, 342 links)
  • python3 tests/bidi_controls_check.py: rc 0 (1245 files)
  • Cross-built the test with x86_64-w64-mingw32-g++ (-std=c++17 -O1 -static -I src) and ran under wine: default run PASS (41 cases); --mutate prefix-match rc 1; --mutate fail-first rc 1 (both negative controls fail as designed).

Windows Server 2025 (win2025 1555 --wait 900, target startup_trap_header_check, regex startup_trap_header):

  • Debug (preset dev): build ok, 3/3 passed
  • Release /O2 (preset release): build ok, 3/3 passed

Mutations on src/startup_stubs/trap.h (each reverted with git checkout -- .):

  1. Module mask 0xFFu widened to 0xFFFu: test fails ("exit_code masks module overflow bit 19"), rc 1 (killed).
  2. Index mask 0xFFu widened to 0x1FFu: test fails ("exit_code masks index overflow bits"), rc 1 (killed).
  3. Continue-over-fail precedence broken (continue only when not in the fail list): test fails (precedence case and log line), rc 1 (killed).
    (A narrower module mask 0x7FFu survives: it still clears bit 19. That is a gap in the 0x100 case only, not a defect.)

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6046933334 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1555#pullrequestreview-6046933334). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T20:33:31Z. **Review:** COMMENTED --- Review of `0a0dbf8222a4fcbe4dcaa874de080103cbe2d34c` (startup_trap_header_check, TIER_B_TESTS), checked out at exactly that SHA. No P1, no P2 found. Delta read of the earlier reviews: the earlier P2 (module mask bit 19 unguarded) is fixed by the new `exit_code(0x800u, 0u)` case. Commands executed locally (Linux): - `git diff --check origin/main...HEAD`: rc 0 - `python3 tests/docs_links_check.py`: rc 0 (16 files, 342 links) - `python3 tests/bidi_controls_check.py`: rc 0 (1245 files) - Cross-built the test with x86_64-w64-mingw32-g++ (-std=c++17 -O1 -static -I src) and ran under wine: default run PASS (41 cases); `--mutate prefix-match` rc 1; `--mutate fail-first` rc 1 (both negative controls fail as designed). Windows Server 2025 (`win2025 1555 --wait 900`, target startup_trap_header_check, regex startup_trap_header): - Debug (preset dev): build ok, 3/3 passed - Release /O2 (preset release): build ok, 3/3 passed Mutations on src/startup_stubs/trap.h (each reverted with git checkout -- .): 1. Module mask 0xFFu widened to 0xFFFu: test fails ("exit_code masks module overflow bit 19"), rc 1 (killed). 2. Index mask 0xFFu widened to 0x1FFu: test fails ("exit_code masks index overflow bits"), rc 1 (killed). 3. Continue-over-fail precedence broken (continue only when not in the fail list): test fails (precedence case and log line), rc 1 (killed). (A narrower module mask 0x7FFu survives: it still clears bit 19. That is a gap in the 0x100 case only, not a defect.) AI-assisted; commands listed were executed locally.
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!1548
No description provided.