runtime: test the GameInput ordinal 1 caller with a recording provider #1069

Merged
lukaslw-lab merged 2 commits from upstream-pr/1076 into main 2026-11-24 01:02:17 +00:00
lukaslw-lab commented 2026-11-24 00:25:35 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-24T00:25:35Z.


Change

Basis. The call shapes come from static disassembly of the main executable's GameInput caller, recorded in #1056 (ABI shapes and counts only). The method was pefile + capstone scripts over the file (import table, .pdata-bounded disassembly, exhaustive reference scans), with IDA for orientation. Nothing was executed. What was read:

  • the import is ordinal 1, called with one argument, and its failure is fatal;
  • the 11 vtable slots the caller uses and their argument counts;
  • the struct sizes: 28-byte gamepad state, 12-byte key states, 32-byte device ID at +0x20, 16-byte rumble block with a zero trigger half;
  • the constants: kinds, status filter, blocking enumeration, timeouts;
  • the keyboard registration is made while the caller holds a lock its callback takes again.

The public v0 header only names these slots and structures, and each name was checked against the observed shape. The fixture reproduces the shapes; it does not take them from the header.

Adds a source-built check of the GameInput call contract recorded in #1056. A source-built caller imports GameInput.dll ordinal 1 with no name, as the console caller does, and drives the v0 objects with its call shapes. A test-only recording provider exports GameInputCreate at ordinal 1 (NONAME). It runs under the Windows loader and pe_map. No production GameInput.dll export is added. Refs #1056, #870.

  • Caller (tests/cpu/gameinput_caller.asm, via exe_startup.asm + cpu_exe_io, as in #1047), 8 steps:
    • ordinal-1 create with one argument;
    • keyboard and gamepad device callbacks with blocking enumeration. The keyboard one is registered while the caller holds a recursive lock that the callback takes again;
    • an unsupported kind;
    • current/previous gamepad readings into the 28-byte state;
    • keyboard key states in 12-byte entries, including an E0-prefixed scan code;
    • FindDeviceFromId on the device's own ID, then SetRumbleState with zero trigger values;
    • unregister with 5000 µs and infinite timeouts, then release.
  • Provider (tests/cpu/gameinput_provider.cpp): v0 declarations restated from the public Windows SDK um/GameInput.h (10.0.26100.0), with sizes and offsets pinned by static_assert. Everything about runtime behaviour is fixture policy and labelled as such: synthetic devices and IDs, the three-entry history, synchronous callbacks for blocking enumeration, refusal codes.
  • Check (tests/cpu/gameinput_check.py, CTest cpu_native_gameinput) and a docs/experiments.md section.

Verification

Commit f3aebeb4 (on main 110e1860), Windows 10 Pro 22H2 (build 19045), Visual Studio 2026 18.12 (MSVC 19.52), Windows SDK 10.0.26100, CMake 4.3.1, Python 3.13.7.

ctest --preset dev --no-tests=error -R '^cpu_native_(gameinput|acphal_hal|apu_address|apu_alloc_caller)$'
100% tests passed, 0 tests failed out of 4
ctest --preset release --no-tests=error -R '^cpu_native_(gameinput|acphal_hal|apu_address|apu_alloc_caller)$'
100% tests passed, 0 tests failed out of 4

ctest --preset dev --no-tests=error -R '^cpu_native_gameinput$' -V (provider records shortened):

caller imports: {'gameinput.dll': ['#1', 'get_gameinput_outstanding_refs'], 'cpu_exe_io.dll': ['finish_exe']}
native and mapped exit 0x6a1; provider records {... 'get_gameinput_outstanding_refs': 0}
create fails: native and mapped exit 0xf01
callback on another thread: native and mapped exit 0xf02
gamepad state 4 bytes late: native and mapped exit 0xf05
before entry: unresolved import GameInput.dll!#1
ordinal 2 provider: pe_map unresolved import GameInput.dll!#1; Windows loader exit 0xc0000138
missing provider, before entry: unresolved import GameInput.dll!get_gameinput_outstanding_refs
missing provider, Windows loader: exit 0xc0000139 (loader fell back to the system GameInput.dll, which lacks the test export)

All 20 provider records matched after the pe_map run: no calls to unused slots, no outstanding references, and one rumble call with zero trigger values. No capability skips. The full suite was left to CI.

Local mutations, not committed. Each one was caught:

Mutation Caught by
no callback during blocking enumeration Step 2, 0xF02
E0 prefix dropped from the arrow key's scan code Step 6, 0xF06
FindDeviceFromId returns the keyboard instead Step 7, 0xF07
one reading reference leaked Step 8, 0xF08
unregister of a removed token returns true Step 8, 0xF08
caller sends non-zero trigger rumble checker's provider records

Evidence and follow-up

  • Source: all inputs are source-built (MIT). Interface declarations come from the public Windows SDK v0 header and Microsoft Learn. No game files, SDK binaries or console headers are used.
  • Negative controls: three faulty provider builds (failed create, callback on another thread that waits, gamepad state written 4 bytes late), a withheld ordinal, a provider with the function at ordinal 2, and no provider. The cross-thread case is caught by the caller's bounded lock spin, so it fails instead of hanging.
  • Not established: what the console runtime does on the callback thread, history depth, scan-code encoding and refusal codes. Production binding (forward to the desktop runtime or implement the subset) is the open question in #1056. Today, with no provider, the Windows loader picks up System32\GameInput.dll, as the last line above shows.
  • Review: Holastor offered an independent Windows 11 run and review in #1056. A run with a second gamepad family would also be useful.

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: prepared with Claude Code; the commands and results above were run on the author's PC.

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6571747814 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1076). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-11-24T00:25:35Z. --- ## Change **Basis.** The call shapes come from static disassembly of the main executable's GameInput caller, recorded in #1056 (ABI shapes and counts only). The method was pefile + capstone scripts over the file (import table, `.pdata`-bounded disassembly, exhaustive reference scans), with IDA for orientation. Nothing was executed. What was read: - the import is ordinal 1, called with one argument, and its failure is fatal; - the 11 vtable slots the caller uses and their argument counts; - the struct sizes: 28-byte gamepad state, 12-byte key states, 32-byte device ID at +0x20, 16-byte rumble block with a zero trigger half; - the constants: kinds, status filter, blocking enumeration, timeouts; - the keyboard registration is made while the caller holds a lock its callback takes again. The public v0 header only names these slots and structures, and each name was checked against the observed shape. The fixture reproduces the shapes; it does not take them from the header. Adds a source-built check of the GameInput call contract recorded in #1056. A source-built caller imports `GameInput.dll` ordinal 1 with no name, as the console caller does, and drives the v0 objects with its call shapes. A test-only recording provider exports `GameInputCreate` at ordinal 1 (`NONAME`). It runs under the Windows loader and `pe_map`. No production `GameInput.dll` export is added. Refs #1056, #870. - **Caller** (`tests/cpu/gameinput_caller.asm`, via `exe_startup.asm` + `cpu_exe_io`, as in #1047), 8 steps: - ordinal-1 create with one argument; - keyboard and gamepad device callbacks with blocking enumeration. The keyboard one is registered while the caller holds a recursive lock that the callback takes again; - an unsupported kind; - current/previous gamepad readings into the 28-byte state; - keyboard key states in 12-byte entries, including an E0-prefixed scan code; - `FindDeviceFromId` on the device's own ID, then `SetRumbleState` with zero trigger values; - unregister with 5000 µs and infinite timeouts, then release. - **Provider** (`tests/cpu/gameinput_provider.cpp`): v0 declarations restated from the public Windows SDK `um/GameInput.h` (10.0.26100.0), with sizes and offsets pinned by `static_assert`. Everything about runtime behaviour is fixture policy and labelled as such: synthetic devices and IDs, the three-entry history, synchronous callbacks for blocking enumeration, refusal codes. - **Check** (`tests/cpu/gameinput_check.py`, CTest `cpu_native_gameinput`) and a `docs/experiments.md` section. ## Verification Commit `f3aebeb4` (on `main` `110e1860`), Windows 10 Pro 22H2 (build 19045), Visual Studio 2026 18.12 (MSVC 19.52), Windows SDK 10.0.26100, CMake 4.3.1, Python 3.13.7. ctest --preset dev --no-tests=error -R '^cpu_native_(gameinput|acphal_hal|apu_address|apu_alloc_caller)$' 100% tests passed, 0 tests failed out of 4 ctest --preset release --no-tests=error -R '^cpu_native_(gameinput|acphal_hal|apu_address|apu_alloc_caller)$' 100% tests passed, 0 tests failed out of 4 `ctest --preset dev --no-tests=error -R '^cpu_native_gameinput$' -V` (provider records shortened): caller imports: {'gameinput.dll': ['#1', 'get_gameinput_outstanding_refs'], 'cpu_exe_io.dll': ['finish_exe']} native and mapped exit 0x6a1; provider records {... 'get_gameinput_outstanding_refs': 0} create fails: native and mapped exit 0xf01 callback on another thread: native and mapped exit 0xf02 gamepad state 4 bytes late: native and mapped exit 0xf05 before entry: unresolved import GameInput.dll!#1 ordinal 2 provider: pe_map unresolved import GameInput.dll!#1; Windows loader exit 0xc0000138 missing provider, before entry: unresolved import GameInput.dll!get_gameinput_outstanding_refs missing provider, Windows loader: exit 0xc0000139 (loader fell back to the system GameInput.dll, which lacks the test export) All 20 provider records matched after the `pe_map` run: no calls to unused slots, no outstanding references, and one rumble call with zero trigger values. No capability skips. The full suite was left to CI. Local mutations, not committed. Each one was caught: | Mutation | Caught by | |---|---| | no callback during blocking enumeration | Step 2, `0xF02` | | E0 prefix dropped from the arrow key's scan code | Step 6, `0xF06` | | `FindDeviceFromId` returns the keyboard instead | Step 7, `0xF07` | | one reading reference leaked | Step 8, `0xF08` | | unregister of a removed token returns `true` | Step 8, `0xF08` | | caller sends non-zero trigger rumble | checker's provider records | ## Evidence and follow-up - **Source:** all inputs are source-built (MIT). Interface declarations come from the public Windows SDK v0 header and Microsoft Learn. No game files, SDK binaries or console headers are used. - **Negative controls:** three faulty provider builds (failed create, callback on another thread that waits, gamepad state written 4 bytes late), a withheld ordinal, a provider with the function at ordinal 2, and no provider. The cross-thread case is caught by the caller's bounded lock spin, so it fails instead of hanging. - **Not established:** what the console runtime does on the callback thread, history depth, scan-code encoding and refusal codes. Production binding (forward to the desktop runtime or implement the subset) is the open question in #1056. Today, with no provider, the Windows loader picks up `System32\GameInput.dll`, as the last line above shows. - **Review:** Holastor offered an independent Windows 11 run and review in #1056. A run with a second gamepad family would also be useful. ## 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: prepared with Claude Code; the commands and results above were run on the author's PC._ 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-24 06:46:10 +00:00
Holastor commented 2026-11-24 06:46:11 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-24T00:32:35Z.

Review: APPROVED


Independent Windows 11 run and review.

Environment

  • OS: Windows 11 Pro x64 (build 26100.3037)
  • Compiler: Visual Studio 2026 Developer PowerShell v18.11.4 (MSVC 19.51.36263.0)
  • CMake 4.3.1 / Ninja 1.13.0
  • Python 3.11 (out/pe-env)
  • Tested Commit: f3aebeb4 (branch runtime/gameinput-caller-fixture)

Test Commands & Results

Dev Preset:

cmake --build --preset dev --target pe_map cpu_gameinput_caller cpu_gameinput_provider cpu_gameinput_provider_create_fail cpu_gameinput_provider_other_thread cpu_gameinput_provider_shifted_layout cpu_gameinput_provider_wrong cpu_exe_io cpu_apu_alloc_caller cpu_apu_alloc_provider cpu_apu_alloc_provider_lenient cpu_acphal_hal_caller cpu_acphal_hal_provider cpu_acphal_hal_provider_faulty cpu_apu_address_caller cpu_apu_address_provider cpu_apu_address_provider_faulty
ctest --preset dev --no-tests=error -R '^cpu_native_(gameinput|acphal_hal|apu_address|apu_alloc_caller)$' -V
  • 4/4 passed (100% pass):
    • cpu_native_apu_alloc_caller (Passed 0.18 sec)
    • cpu_native_apu_address (Passed 0.17 sec)
    • cpu_native_acphal_hal (Passed 0.18 sec)
    • cpu_native_gameinput (Passed 0.97 sec)

Release Preset:

cmake --build --preset release --target pe_map cpu_gameinput_caller cpu_gameinput_provider cpu_gameinput_provider_create_fail cpu_gameinput_provider_other_thread cpu_gameinput_provider_shifted_layout cpu_gameinput_provider_wrong cpu_exe_io cpu_apu_alloc_caller cpu_apu_alloc_provider cpu_apu_alloc_provider_lenient cpu_acphal_hal_caller cpu_acphal_hal_provider cpu_acphal_hal_provider_faulty cpu_apu_address_caller cpu_apu_address_provider cpu_apu_address_provider_faulty
ctest --preset release --no-tests=error -R '^cpu_native_(gameinput|acphal_hal|apu_address|apu_alloc_caller)$' -V
  • 4/4 passed (100% pass):
    • cpu_native_gameinput (Passed 0.97 sec)
    • All 20 provider records matched expectations identically to dev.

Linters & Documentation:

./out/pe-env/Scripts/python.exe -B tests/docs_links_check.py
# Self-test passed. Checked 15 Markdown files and 245 links.

./out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py
# Self-test passed. Checked 918 tracked source, script and build/CI files: no bidirectional controls.

./out/pe-env/Scripts/python.exe -B tests/hardware_reports_check.py
# Ran 11 tests: OK

Observations on Negative Controls

  • Failed create: native and mapped exit 0xF01 at Step 1.
  • Cross-thread callback: native and mapped exit 0xF02 at Step 2 (bounded lock spin cleanly handles thread mismatch without hanging).
  • Shifted layout: native and mapped exit 0xF05 at Step 5.
  • Withheld / Wrong ordinal: pe_map catches unresolved ordinal 1 before entry; Windows loader exits 0xC0000138 (STATUS_ORDINAL_NOT_FOUND).
  • Missing provider: Windows loader falls back to in-box System32 GameInput.dll (missing the test query export) and exits 0xC0000139 (STATUS_ENTRYPOINT_NOT_FOUND).
  • Reference counts: get_gameinput_outstanding_refs == 0, no leaked readings or device handles.

Everything is reproducible and clean-room compliant. Looks great to merge!

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6031780184 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1076#pullrequestreview-6031780184). Originally posted by [Holastor](https://github.com/Holastor) on 2026-11-24T00:32:35Z. **Review:** APPROVED --- Independent Windows 11 run and review. ### Environment - OS: Windows 11 Pro x64 (build 26100.3037) - Compiler: Visual Studio 2026 Developer PowerShell v18.11.4 (MSVC 19.51.36263.0) - CMake 4.3.1 / Ninja 1.13.0 - Python 3.11 (`out/pe-env`) - Tested Commit: `f3aebeb4` (branch `runtime/gameinput-caller-fixture`) ### Test Commands & Results **Dev Preset:** ```powershell cmake --build --preset dev --target pe_map cpu_gameinput_caller cpu_gameinput_provider cpu_gameinput_provider_create_fail cpu_gameinput_provider_other_thread cpu_gameinput_provider_shifted_layout cpu_gameinput_provider_wrong cpu_exe_io cpu_apu_alloc_caller cpu_apu_alloc_provider cpu_apu_alloc_provider_lenient cpu_acphal_hal_caller cpu_acphal_hal_provider cpu_acphal_hal_provider_faulty cpu_apu_address_caller cpu_apu_address_provider cpu_apu_address_provider_faulty ctest --preset dev --no-tests=error -R '^cpu_native_(gameinput|acphal_hal|apu_address|apu_alloc_caller)$' -V ``` - 4/4 passed (100% pass): - `cpu_native_apu_alloc_caller` (Passed 0.18 sec) - `cpu_native_apu_address` (Passed 0.17 sec) - `cpu_native_acphal_hal` (Passed 0.18 sec) - `cpu_native_gameinput` (Passed 0.97 sec) **Release Preset:** ```powershell cmake --build --preset release --target pe_map cpu_gameinput_caller cpu_gameinput_provider cpu_gameinput_provider_create_fail cpu_gameinput_provider_other_thread cpu_gameinput_provider_shifted_layout cpu_gameinput_provider_wrong cpu_exe_io cpu_apu_alloc_caller cpu_apu_alloc_provider cpu_apu_alloc_provider_lenient cpu_acphal_hal_caller cpu_acphal_hal_provider cpu_acphal_hal_provider_faulty cpu_apu_address_caller cpu_apu_address_provider cpu_apu_address_provider_faulty ctest --preset release --no-tests=error -R '^cpu_native_(gameinput|acphal_hal|apu_address|apu_alloc_caller)$' -V ``` - 4/4 passed (100% pass): - `cpu_native_gameinput` (Passed 0.97 sec) - All 20 provider records matched expectations identically to `dev`. **Linters & Documentation:** ```powershell ./out/pe-env/Scripts/python.exe -B tests/docs_links_check.py # Self-test passed. Checked 15 Markdown files and 245 links. ./out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py # Self-test passed. Checked 918 tracked source, script and build/CI files: no bidirectional controls. ./out/pe-env/Scripts/python.exe -B tests/hardware_reports_check.py # Ran 11 tests: OK ``` ### Observations on Negative Controls - **Failed create:** native and mapped exit `0xF01` at Step 1. - **Cross-thread callback:** native and mapped exit `0xF02` at Step 2 (bounded lock spin cleanly handles thread mismatch without hanging). - **Shifted layout:** native and mapped exit `0xF05` at Step 5. - **Withheld / Wrong ordinal:** `pe_map` catches unresolved ordinal 1 before entry; Windows loader exits `0xC0000138` (`STATUS_ORDINAL_NOT_FOUND`). - **Missing provider:** Windows loader falls back to in-box System32 `GameInput.dll` (missing the test query export) and exits `0xC0000139` (`STATUS_ENTRYPOINT_NOT_FOUND`). - Reference counts: `get_gameinput_outstanding_refs == 0`, no leaked readings or device handles. Everything is reproducible and clean-room compliant. Looks great to merge!
Holastor commented 2026-11-24 06:46:11 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-24T00:56:14Z.

Review: APPROVED


Re-reviewed changes since f3aebeb4 (commit e6361ca2):

  • Diff Inspection: Merge of upstream/main (e5bfa0c9) into runtime/gameinput-caller-fixture. Reconciled CMakeLists.txt and docs/experiments.md to preserve both the GameInput ordinal 1 fixture and the upstream XApu queue fixture. No changes were made to the GameInput test code (tests/cpu/gameinput_*).
  • Dev Preset Verification:
    cmake --build --preset dev --target pe_map cpu_gameinput_caller cpu_gameinput_provider cpu_gameinput_provider_create_fail cpu_gameinput_provider_other_thread cpu_gameinput_provider_shifted_layout cpu_gameinput_provider_wrong cpu_xapu_queue_caller cpu_xapu_queue_provider cpu_xapu_queue_provider_lenient cpu_xapu_queue_provider_lifo cpu_exe_io
    ctest --preset dev --no-tests=error -R '^(cpu_native_gameinput|cpu_native_xapu_queue)$' -V
    
    Both cpu_native_gameinput (0.99s) and cpu_native_xapu_queue (0.16s) passed 100%. All negative controls behaved as expected.
  • Release Preset Verification:
    cmake --build --preset release --target pe_map cpu_gameinput_caller cpu_gameinput_provider cpu_gameinput_provider_create_fail cpu_gameinput_provider_other_thread cpu_gameinput_provider_shifted_layout cpu_gameinput_provider_wrong cpu_xapu_queue_caller cpu_xapu_queue_provider cpu_xapu_queue_provider_lenient cpu_xapu_queue_provider_lifo cpu_exe_io
    ctest --preset release --no-tests=error -R '^(cpu_native_gameinput|cpu_native_xapu_queue)$' -V
    
    Both passed 100%.
  • Linters:
    • tests/docs_links_check.py: Passed (15 Markdown files, 245 links).
    • tests/bidi_controls_check.py: Passed (922 tracked files).

Still clean, verified, and ready to merge.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6031980520 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1076#pullrequestreview-6031980520). Originally posted by [Holastor](https://github.com/Holastor) on 2026-11-24T00:56:14Z. **Review:** APPROVED --- Re-reviewed changes since `f3aebeb4` (commit `e6361ca2`): - **Diff Inspection:** Merge of `upstream/main` (`e5bfa0c9`) into `runtime/gameinput-caller-fixture`. Reconciled `CMakeLists.txt` and `docs/experiments.md` to preserve both the GameInput ordinal 1 fixture and the upstream XApu queue fixture. No changes were made to the GameInput test code (`tests/cpu/gameinput_*`). - **Dev Preset Verification:** ```powershell cmake --build --preset dev --target pe_map cpu_gameinput_caller cpu_gameinput_provider cpu_gameinput_provider_create_fail cpu_gameinput_provider_other_thread cpu_gameinput_provider_shifted_layout cpu_gameinput_provider_wrong cpu_xapu_queue_caller cpu_xapu_queue_provider cpu_xapu_queue_provider_lenient cpu_xapu_queue_provider_lifo cpu_exe_io ctest --preset dev --no-tests=error -R '^(cpu_native_gameinput|cpu_native_xapu_queue)$' -V ``` Both `cpu_native_gameinput` (0.99s) and `cpu_native_xapu_queue` (0.16s) passed 100%. All negative controls behaved as expected. - **Release Preset Verification:** ```powershell cmake --build --preset release --target pe_map cpu_gameinput_caller cpu_gameinput_provider cpu_gameinput_provider_create_fail cpu_gameinput_provider_other_thread cpu_gameinput_provider_shifted_layout cpu_gameinput_provider_wrong cpu_xapu_queue_caller cpu_xapu_queue_provider cpu_xapu_queue_provider_lenient cpu_xapu_queue_provider_lifo cpu_exe_io ctest --preset release --no-tests=error -R '^(cpu_native_gameinput|cpu_native_xapu_queue)$' -V ``` Both passed 100%. - **Linters:** - `tests/docs_links_check.py`: Passed (15 Markdown files, 245 links). - `tests/bidi_controls_check.py`: Passed (922 tracked files). Still clean, verified, and ready to merge.
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!1069
No description provided.