startup: check the API trace's declared contracts and second-output reports #1727

Merged
Asimmimx merged 1 commit from upstream-pr/1734 into main 2026-11-24 21:10:11 +00:00
Asimmimx commented 2026-11-24 17:57:29 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Asimmimx on 2026-11-24T17:57:29Z.


Refs #1149.

Change

src/startup_stubs/api_trace.h serves the opt-in API trace (X2W_TRACE_API) in runtime_proxy.cpp. It holds three things:

  • a 15-entry table of the outputs the trace may read for each provider slot: argument index, width or capacity argument, and an optional second output;
  • decide, which compares the snapshots;
  • format, which writes the out= text (?, unreadable, same, changed:<args>, with ,partial appended).

The table is what keeps the trace from reading an argument as if it were a pointer.

The one test, api_trace, checks decide and format for index 0, two changed outputs, exact and short buffers, the same value, and partial or no comparison. For the table it checks only that five slots have some contract. 35 of 42 single-point mutants of the header passed it:

  • every argument index, width and capacity argument in the table;
  • two entries dropped;
  • a lookup that ignores the provider;
  • a change of the second output alone, reported under the first output's index;
  • a partial change reported without ,partial.

New cases in tests/api_trace_check.cpp:

Case What it pins
XUserCheckPrivilege, only the deny reason changes changed:4, changed[0] == 1
same, the first output not compared changed:4,partial
each of the 15 declarations provider, slot, first index and width, capacity argument, second index and width. Each matches the argument and width the stand-in writes in user_call, the GetGamertag answer and area_call in runtime_proxy.cpp (for example XUserGetGamertag(handle, component, size, buffer, &used) is first 3, capacity 2, second 4 of 8 bytes)
cef4fac0 slot 15, 0dd112ac slot 20, 37e56907 slot 3 a slot declared for one provider has no contract for another

The existing cases are unchanged. The five presence checks now go through the same lookup helper.

Negative control: api_trace_slot_only_control runs the check with --mutate slot-only. In that mode the lookup matches the slot number alone, so the first provider in table order that declares the slot answers for all providers. The control is registered WILL_FAIL and reports 6 MISMATCH lines.

The change touches tests/api_trace_check.cpp and adds two CMake lines (plus one more comment line) next to api_trace. The header is unchanged. No docs section lists this check's coverage, so there is no docs change.

Mutation probe

I applied each mutation to the header alone, rebuilt api_trace_check, ran api_trace, then reverted. None of this is committed.

Mutant existing api_trace with the new cases
format: single change always lists the first index survived killed
format: second of two changes always the second index survived survived (equivalent)
format: single change drops ,partial survived killed
format: two changes drop ,partial survived survived (unreachable)
format: same drops ,partial killed killed
format: second index taken from first killed killed
decide: zero-byte output counted as compared survived survived (unreachable)
decide: always two outputs / always one killed / killed killed / killed
decide: compare all 64 bytes killed killed
decide: a change hides partial survived killed
decide: partial is unreadable killed killed
declared: provider ignored survived killed
declared: slot ignored killed killed
table, 01acd177: slot 3/10/12/40 width 4; slot 8/11 index 0; slot 9 entry dropped; slot 13 width 4; slot 14 width 8; slot 19 width 1; slot 40 renumbered 41 survived (11) killed (11)
table, 01acd177 slot 15: buffer arg 2; capacity arg 3; fixed width 16; used width 4; no used survived (5) killed (5)
table, 01acd177 slot 20: has arg 2; has width 4; deny width 8; deny arg 5 survived (4) killed (4)
table, cef4fac0 slot 3: capacity arg 3; used width 4 survived (2) killed (2)
table, 37e56907 slot 15: width 8; index 1 survived (2) killed (2)
table, 0dd112ac slot 3: index 0; width 4; entry dropped survived (3) killed (3)
max_snapshot 64 to 16 survived survived (not pinned)

Killed: 7 of 42 before, 38 of 42 after.

Not pinned

  • Second of two changes always the second index. This mutant is equivalent: decide records changes in ascending order, so when two change, changed[1] is always the second output.
  • ,partial on a two-output change. Not reachable: two changes need both outputs compared, so the report cannot be partial.
  • A compared output with zero bytes. runtime_proxy.cpp sets current[i] only when compared_bytes[i] is non-zero, so a compared output with zero bytes never reaches decide.
  • max_snapshot. It is a bound, not a contract. Every fixed width (at most 16) fits under it. Lowering it only shortens the comparison of a caller-sized gamertag buffer, and the right bound is a policy choice.

Verification

Commit 669282ec on origin/main bfe9158d, dev preset (Debug), Windows 11 Pro build 26300.9974, MSVC 19.51.36260 (Visual Studio), Windows SDK 10.0.26100.0. No GPU and no debug layer involved.

cmake --build --preset dev --target api_trace_check
ctest --preset dev --no-tests=error -R '^api_trace' -V
#   2/2 passed
#   api_trace: 33 checks ok, PASS
#   api_trace_slot_only_control: 6 MISMATCH, FAIL (WILL_FAIL)

tests/docs_links_check.py (17 files, 364 links), tests/bidi_controls_check.py and git diff --check passed.

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. (No capability or requirement changed.)
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6588121099 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1734). Originally posted by [Asimmimx](https://github.com/Asimmimx) on 2026-11-24T17:57:29Z. --- Refs #1149. ## Change `src/startup_stubs/api_trace.h` serves the opt-in API trace (`X2W_TRACE_API`) in `runtime_proxy.cpp`. It holds three things: - a 15-entry table of the outputs the trace may read for each provider slot: argument index, width or capacity argument, and an optional second output; - `decide`, which compares the snapshots; - `format`, which writes the `out=` text (`?`, `unreadable`, `same`, `changed:<args>`, with `,partial` appended). The table is what keeps the trace from reading an argument as if it were a pointer. The one test, `api_trace`, checks `decide` and `format` for index 0, two changed outputs, exact and short buffers, the same value, and partial or no comparison. For the table it checks only that five slots have *some* contract. 35 of 42 single-point mutants of the header passed it: - every argument index, width and capacity argument in the table; - two entries dropped; - a lookup that ignores the provider; - a change of the second output alone, reported under the first output's index; - a partial change reported without `,partial`. New cases in `tests/api_trace_check.cpp`: | Case | What it pins | |---|---| | XUserCheckPrivilege, only the deny reason changes | `changed:4`, `changed[0] == 1` | | same, the first output not compared | `changed:4,partial` | | each of the 15 declarations | provider, slot, first index and width, capacity argument, second index and width. Each matches the argument and width the stand-in writes in `user_call`, the GetGamertag answer and `area_call` in `runtime_proxy.cpp` (for example `XUserGetGamertag(handle, component, size, buffer, &used)` is first 3, capacity 2, second 4 of 8 bytes) | | `cef4fac0` slot 15, `0dd112ac` slot 20, `37e56907` slot 3 | a slot declared for one provider has no contract for another | The existing cases are unchanged. The five presence checks now go through the same lookup helper. Negative control: `api_trace_slot_only_control` runs the check with `--mutate slot-only`. In that mode the lookup matches the slot number alone, so the first provider in table order that declares the slot answers for all providers. The control is registered `WILL_FAIL` and reports 6 MISMATCH lines. The change touches `tests/api_trace_check.cpp` and adds two CMake lines (plus one more comment line) next to `api_trace`. The header is unchanged. No docs section lists this check's coverage, so there is no docs change. ## Mutation probe I applied each mutation to the header alone, rebuilt `api_trace_check`, ran `api_trace`, then reverted. None of this is committed. | Mutant | existing `api_trace` | with the new cases | |---|---|---| | `format`: single change always lists the first index | **survived** | killed | | `format`: second of two changes always the second index | survived | survived (equivalent) | | `format`: single change drops `,partial` | **survived** | killed | | `format`: two changes drop `,partial` | survived | survived (unreachable) | | `format`: `same` drops `,partial` | killed | killed | | `format`: second index taken from `first` | killed | killed | | `decide`: zero-byte output counted as compared | survived | survived (unreachable) | | `decide`: always two outputs / always one | killed / killed | killed / killed | | `decide`: compare all 64 bytes | killed | killed | | `decide`: a change hides `partial` | **survived** | killed | | `decide`: partial is unreadable | killed | killed | | `declared`: provider ignored | **survived** | killed | | `declared`: slot ignored | killed | killed | | table, 01acd177: slot 3/10/12/40 width 4; slot 8/11 index 0; slot 9 entry dropped; slot 13 width 4; slot 14 width 8; slot 19 width 1; slot 40 renumbered 41 | **survived** (11) | killed (11) | | table, 01acd177 slot 15: buffer arg 2; capacity arg 3; fixed width 16; `used` width 4; no `used` | **survived** (5) | killed (5) | | table, 01acd177 slot 20: `has` arg 2; `has` width 4; deny width 8; deny arg 5 | **survived** (4) | killed (4) | | table, cef4fac0 slot 3: capacity arg 3; `used` width 4 | **survived** (2) | killed (2) | | table, 37e56907 slot 15: width 8; index 1 | **survived** (2) | killed (2) | | table, 0dd112ac slot 3: index 0; width 4; entry dropped | **survived** (3) | killed (3) | | `max_snapshot` 64 to 16 | survived | survived (not pinned) | Killed: 7 of 42 before, 38 of 42 after. ## Not pinned - **Second of two changes always the second index.** This mutant is equivalent: `decide` records changes in ascending order, so when two change, `changed[1]` is always the second output. - **`,partial` on a two-output change.** Not reachable: two changes need both outputs compared, so the report cannot be partial. - **A compared output with zero bytes.** `runtime_proxy.cpp` sets `current[i]` only when `compared_bytes[i]` is non-zero, so a compared output with zero bytes never reaches `decide`. - **`max_snapshot`.** It is a bound, not a contract. Every fixed width (at most 16) fits under it. Lowering it only shortens the comparison of a caller-sized gamertag buffer, and the right bound is a policy choice. ## Verification Commit `669282ec` on `origin/main` `bfe9158d`, `dev` preset (Debug), Windows 11 Pro build 26300.9974, MSVC 19.51.36260 (Visual Studio), Windows SDK 10.0.26100.0. No GPU and no debug layer involved. ```powershell cmake --build --preset dev --target api_trace_check ctest --preset dev --no-tests=error -R '^api_trace' -V # 2/2 passed # api_trace: 33 checks ok, PASS # api_trace_slot_only_control: 6 MISMATCH, FAIL (WILL_FAIL) ``` `tests/docs_links_check.py` (17 files, 364 links), `tests/bidi_controls_check.py` and `git diff --check` passed. ## 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. - [ ] I updated README/docs when a capability or build requirement changed. (No capability or requirement changed.) - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted (Claude Code).
tedin7 commented 2026-11-24 19:01:10 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T18:08:35Z.

Review: COMMENTED


Verified commit 669282ec82d20ade0bfe8b23c672b9d140521115 — clean, no findings (0 P1, 0 P2).

  • Scope is test-only (CMakeLists.txt negative control registration + tests/api_trace_check.cpp), clean-room and title-neutral.
  • second_output_only() exercises x2w_api_trace::decide / format for second-output-only changes (changed:4) and partial comparison (changed:4,partial), and declared_contracts() + --mutate slot-only verify all 15 declared contracts and provider/slot isolation.

Local verification

  • Linux checks (git diff --check, docs_links_check.py, bidi_controls_check.py): PASS
  • Portable Linux build/run (g++ -std=c++17 -Wall -Wextra -Isrc tests/api_trace_check.cpp -> normal run PASS, --mutate slot-only FAIL as expected)
  • Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP):
    • Debug (--preset dev): cmake --build --preset dev --target api_trace_check -- -j 6 + ctest --preset dev -R '^(api_trace|api_trace_slot_only_control)$' --parallel 4 --no-tests=error --output-on-failure -> 2/2 passed (0.10s)
    • Release /O2 (--preset release): cmake --build --preset release --target api_trace_check -- -j 6 + ctest --preset release -R '^(api_trace|api_trace_slot_only_control)$' --parallel 4 --no-tests=error --output-on-failure -> 2/2 passed (0.10s)
  • Mutation check on Windows Server 2025 (--patch mutating src/startup_stubs/api_trace.h:107 from report.changed[0] == 0 ? first : second to first): api_trace failed on both new second_output_only() assertions (MISMATCH) while pre-existing checks stayed ok; automatically restored afterward.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6044762798 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1734#pullrequestreview-6044762798). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T18:08:35Z. **Review:** COMMENTED --- Verified commit `669282ec82d20ade0bfe8b23c672b9d140521115` — clean, no findings (0 P1, 0 P2). - Scope is test-only (`CMakeLists.txt` negative control registration + `tests/api_trace_check.cpp`), clean-room and title-neutral. - `second_output_only()` exercises `x2w_api_trace::decide` / `format` for second-output-only changes (`changed:4`) and partial comparison (`changed:4,partial`), and `declared_contracts()` + `--mutate slot-only` verify all 15 declared contracts and provider/slot isolation. ### Local verification - Linux checks (`git diff --check`, `docs_links_check.py`, `bidi_controls_check.py`): PASS - Portable Linux build/run (`g++ -std=c++17 -Wall -Wextra -Isrc tests/api_trace_check.cpp` -> normal run PASS, `--mutate slot-only` FAIL as expected) - Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP): - Debug (`--preset dev`): `cmake --build --preset dev --target api_trace_check -- -j 6` + `ctest --preset dev -R '^(api_trace|api_trace_slot_only_control)$' --parallel 4 --no-tests=error --output-on-failure` -> **2/2 passed** (`0.10s`) - Release `/O2` (`--preset release`): `cmake --build --preset release --target api_trace_check -- -j 6` + `ctest --preset release -R '^(api_trace|api_trace_slot_only_control)$' --parallel 4 --no-tests=error --output-on-failure` -> **2/2 passed** (`0.10s`) - Mutation check on Windows Server 2025 (`--patch` mutating `src/startup_stubs/api_trace.h:107` from `report.changed[0] == 0 ? first : second` to `first`): `api_trace` failed on both new `second_output_only()` assertions (`MISMATCH`) while pre-existing checks stayed `ok`; automatically restored afterward. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-24 21:27:20 +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!1727
No description provided.