startup: check the API trace's declared contracts and second-output reports #1727
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1734"
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-24T17:57:29Z.
Refs #1149.
Change
src/startup_stubs/api_trace.hserves the opt-in API trace (X2W_TRACE_API) inruntime_proxy.cpp. It holds three things:decide, which compares the snapshots;format, which writes theout=text (?,unreadable,same,changed:<args>, with,partialappended).The table is what keeps the trace from reading an argument as if it were a pointer.
The one test,
api_trace, checksdecideandformatfor 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:,partial.New cases in
tests/api_trace_check.cpp:changed:4,changed[0] == 1changed:4,partialuser_call, the GetGamertag answer andarea_callinruntime_proxy.cpp(for exampleXUserGetGamertag(handle, component, size, buffer, &used)is first 3, capacity 2, second 4 of 8 bytes)cef4fac0slot 15,0dd112acslot 20,37e56907slot 3The existing cases are unchanged. The five presence checks now go through the same lookup helper.
Negative control:
api_trace_slot_only_controlruns 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 registeredWILL_FAILand reports 6 MISMATCH lines.The change touches
tests/api_trace_check.cppand adds two CMake lines (plus one more comment line) next toapi_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, ranapi_trace, then reverted. None of this is committed.api_traceformat: single change always lists the first indexformat: second of two changes always the second indexformat: single change drops,partialformat: two changes drop,partialformat:samedrops,partialformat: second index taken fromfirstdecide: zero-byte output counted as compareddecide: always two outputs / always onedecide: compare all 64 bytesdecide: a change hidespartialdecide: partial is unreadabledeclared: provider ignoreddeclared: slot ignoredusedwidth 4; nousedhasarg 2;haswidth 4; deny width 8; deny arg 5usedwidth 4max_snapshot64 to 16Killed: 7 of 42 before, 38 of 42 after.
Not pinned
deciderecords changes in ascending order, so when two change,changed[1]is always the second output.,partialon a two-output change. Not reachable: two changes need both outputs compared, so the report cannot be partial.runtime_proxy.cppsetscurrent[i]only whencompared_bytes[i]is non-zero, so a compared output with zero bytes never reachesdecide.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
669282econorigin/mainbfe9158d,devpreset (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.tests/docs_links_check.py(17 files, 364 links),tests/bidi_controls_check.pyandgit diff --checkpassed.Checklist
AI-assisted (Claude Code).
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).CMakeLists.txtnegative control registration +tests/api_trace_check.cpp), clean-room and title-neutral.second_output_only()exercisesx2w_api_trace::decide/formatfor second-output-only changes (changed:4) and partial comparison (changed:4,partial), anddeclared_contracts()+--mutate slot-onlyverify all 15 declared contracts and provider/slot isolation.Local verification
git diff --check,docs_links_check.py,bidi_controls_check.py): PASSg++ -std=c++17 -Wall -Wextra -Isrc tests/api_trace_check.cpp-> normal run PASS,--mutate slot-onlyFAIL as expected)--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)/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)--patchmutatingsrc/startup_stubs/api_trace.h:107fromreport.changed[0] == 0 ? first : secondtofirst):api_tracefailed on both newsecond_output_only()assertions (MISMATCH) while pre-existing checks stayedok; automatically restored afterward.AI-assisted; commands listed were executed locally.