Skip to content

gameinput: serve the ordinal import (gameinput.dll!#1), and serve it without SDL3 - #7896

Closed
Spacecer2 wants to merge 1 commit into
ProjectLeonida:mainfrom
Spacecer2:gameinput-ordinal-no-sdl
Closed

Spacecer2 wants to merge 1 commit into
ProjectLeonida:mainfrom
Spacecer2:gameinput-ordinal-no-sdl

Conversation

@Spacecer2

Copy link
Copy Markdown

Claimed in the coordination issue as a new RT-5 item.

What was wrong

The retail executable imports GameInput.dll by ordinal 1. runtime/shims/gameinput.cpp registers only the name:

{"gameinput.dll", "GameInputCreate", reinterpret_cast<void*>(&GameInputCreate)},

so the registry lookup for the key "#1" misses, the loader falls through to the host's gameinput.dll, and on wine that host answers GameInputCreate with a null interface. The title ignores the HRESULT, stores the null in its lazy singleton and calls AddRef/Release through it:

game+0x59258a0   rax = [singleton]; if (rax) return rax;
                 call GameInputCreate        ; *out = null
game+0x5925903   mov (%rsi),%rax             ; rsi == 0  <- page fault at address 0
                 call *0x10(%rax)

Second half of the same gap: gameinput.cpp is only compiled when SDL3 is available, so a CPU-only build serves nothing for that import and every consumer falls through to the host.

What this changes

  • The SDL shim registers the ordinal alias {"gameinput.dll", "#1", …} next to the name.
  • New runtime/shims/gameinput_no_sdl.cpp, compiled only when the SDL3 shim is not: one static object whose slots 0/1/2 are QueryInterface/AddRef/Release and every other slot returns E_NOTIMPL, so a caller that only holds and releases the interface survives and one that asks for devices gets a clean refusal instead of a null dereference. It carries a one-time stderr note that it is serving without SDL and therefore has no devices.
  • runtime/test/gameinput_no_sdl_test.cpp + ctest gameinput_no_sdl: the ordinal resolves, the object is non-null, AddRef/Release are callable, an unserved slot returns E_NOTIMPL and writes nothing to its out-parameter, and a null out-parameter is E_POINTER.

Testing

$ wine build/gameinput_no_sdl_test.exe
ok    the ordinal import gameinput.dll!#1 is served
ok    the name GameInputCreate is served
ok    GameInputCreate returns S_OK
ok    GameInputCreate hands back a non-null interface
ok    slot 1 (AddRef) is callable and counts
ok    slot 2 (Release) is callable and does not underflow
ok    an unserved slot returns E_NOTIMPL
ok    an unserved slot writes nothing to its out-parameter
ok    a null out parameter is E_POINTER
0 failure(s)

--dry-run on the retail executable at this commit, before and after: the executable's import split moves from shim=62 host=431 to host=430 shim=63 — one import that used to resolve to the host's module now resolves to the shim, and the total unimplemented count is unchanged.

On a real --run with the boot-path PRs applied, the guest stop at game+0x5925903 (read at address 0) is gone, the trace prints [rt] gameinput: served without SDL3 (no devices; E_NOTIMPL for every other slot), and the boot continues to the next stop. That measurement is what makes this a fix rather than a tidy-up; the Windows table never had this gap because the console executable's import table is what it is on both hosts, but only the ordinal key was ever registered.

No game data: symbol names, counts and one guest mnemonic sequence. AI-assisted.

The retail executable imports GameInput.dll by ordinal 1, and only the name
GameInputCreate was registered, so the loader fell through to the host's gameinput.dll.
That host answers GameInputCreate with a null interface; the title ignores the HRESULT,
stores the null and calls AddRef/Release through it, which is a page fault at address 0.

Register the "ProjectLeonida#1" alias, and add a no-SDL provider compiled only when the SDL3 shim is
not: one static object, real QueryInterface/AddRef/Release, E_NOTIMPL (writing nothing)
for every other slot. A ctest covers the ordinal, the object and the refusal.

@al3xar al3xar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested 4d964643f on Windows 11 x64, MSVC 19.44.35230.0 (VS 2022 Build Tools), CMake + Ninja RelWithDebInfo, Windows SDK 10.0.26100.0 (no SDL3 installed): pass on build & tests, with one small review note below.

Verification

  • Merges cleanly onto upstream/main (dde82f27e).
  • Built gta6rt and gameinput_no_sdl_test cleanly with zero warnings in the added/modified files.
  • gameinput_no_sdl_test.exe and ctest -R gameinput_no_sdl: 9/9 checks OK (exit 0).
  • python -I tests/test_ctest_registration.py -v: 4/4 OK.
  • python -I scripts/check_no_game_data.py runtime/CMakeLists.txt runtime/shims/gameinput.cpp runtime/shims/gameinput_no_sdl.cpp runtime/test/gameinput_no_sdl_test.cpp: clean (exit 0).
  • Local gta6rt.exe --dry-run against the retail 1.0.2.1 executable (counts only): GameInput.dll!#1 moves from host to shim (shim=61 host=432 on main -> shim=62 host=431 on 4d964643f; unimplemented=22 unchanged; exit 0).

Code review note

  • runtime/test/gameinput_no_sdl_test.cpp:35: check(release(object) >= 0, "slot 2 (Release) is callable and does not underflow") is tautologically true because ULONG is unsigned (an underflow to 0xFFFFFFFF still satisfies >= 0). Meanwhile stub_release in runtime/shims/gameinput_no_sdl.cpp:67 does g_refs.fetch_sub(1) - 1 unconditionally, so extra Release() calls will wrap g_refs to UINT32_MAX. Checking release(object) == before - 1 (or clamping g_refs against underflow in stub_release) would actually test the underflow claim.
  • Minor: gameinput.cpp also registers xgameruntime.dll!GameInputCreate; gameinput_no_sdl.cpp omits that alias (fine if intentional, just noting for parity).

AI-assisted.

@HansBullet

Copy link
Copy Markdown
Contributor

Independent CPU-only review of 4d96464 (AI-assisted).

Finding: QueryInterface advertises unsupported interfaces.

In runtime/shims/gameinput_no_sdl.cpp, stub_qi() ignores riid, always returns S_OK, increments the reference count and provides the global GameInput object.

An isolated C++ reproduction confirms that querying IID_NULL returns S_OK with a non-null interface pointer instead of E_NOINTERFACE with a null output.

This differs from the existing SDL-backed gameinput.cpp, which accepts only IID_IUnknown and IID_IGameInput for the main interface.

Suggested correction: Accept only supported interface IDs, return E_NOINTERFACE and set *out = nullptr for unsupported IDs, and add a regression test covering IID_NULL.

The ordinal-import registration and no-SDL fallback are useful changes. This finding concerns COM interface correctness, not the import-resolution fix.

Verification limitation: I compiled and executed an isolated transcription of the relevant logic using GCC on Linux. I did not independently build or execute Leonida's Windows runtime.

rndrmu added a commit to rndrmu/Leonida that referenced this pull request Nov 23, 2026
@FJKiXfaR

Copy link
Copy Markdown

checked: no-SDL3 path under Wine, retail 1.0.2.1 package | base: base-stack@57b88dec1 + #6964 + #6954 + #2490 + #7216 + #6943, plus this PR's diff applied (no SDL3 in the build, so gameinput_no_sdl.cpp is the one compiled in) | on: Linux, Wine 10.0, RTX 5000 (Turing, 32-wide subgroups, LEONIDA_D3D12=vulkan, __NV_PRIME_RENDER_OFFLOAD=1), clang-cl 23.1.5 + xwin SDK 10.0.26100, CPU-side build | result: before this PR the run died in the title's GameInput lazy-singleton path (int3 right after the xmem reservations, zero D3D12 calls). With it, --dry-run and --init pass and --run reaches the graphics device: 1,181 D3D12 calls (device, queues, fences, allocators, 581 command lists created+closed), XboxIDXGIDevice::GetAdapter, device slot 78 SetFrameIntervalX, device slot 79 ScheduleFrameEventX, slot 15 forwarded; then it stops in the title's view-protection/unmap int3, which is the expected stop before #7492 on this older stack. So the no-SDL3 shim is what unblocks --run in a build without SDL3; the registry needs the "#1" alias either way.
agent: yes

@tupacfan04 tupacfan04 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The #1 ordinal alias is correct, but the no-SDL fallback and its test have real defects.

  1. Missing xgameruntime.dll!GameInputCreate. The SDL shim registers three pairs (gameinput.cpp:2647-2650): gameinput.dll GameInputCreate, gameinput.dll #1, and xgameruntime.dll GameInputCreate. The no-SDL table (gameinput_no_sdl.cpp:81-86) omits the third, while docs/gameinput.md:475-476 says both modules are served. Because xgameruntime.dll is owned by the shim, a caller using that documented path gets null instead of the fallback; the no-SDL test checks only gameinput.dll. Add the pair and assert it in the test.

  2. The Release test is vacuous. gameinput_no_sdl_test.cpp:35 checks release(object) >= 0 on a ULONG, which is always true. The fallback (gameinput_no_sdl.cpp:67) also lacks the SDL shim’s release_floor, so an extra release wraps the refcount. Floor the fallback and assert exact counts / non-UINT_MAX.

  3. The device-query test uses the wrong slot/signature. IGameInput v0 slot 9 is RegisterDeviceCallback (seven arguments; the callback token out-parameter is the seventh), not a three-argument GetDevices. The current call passes &devices as statusFilter and never supplies the token pointer, so the “unserved slot writes nothing” claim is not tested. Use the full seven-argument signature with a sentinel token, or GetCurrentReading at slot 4.

Additional: stub_qi ignores riid and returns S_OK for any IID, unlike the SDL QueryInterface (E_NOINTERFACE); the SDL path’s new #1 alias is not checked by gameinput_test.cpp:1474-1477; docs/gameinput.md, runtime/CMakeLists.txt:372-373, and the else() message at :427-433 still say a no-SDL build has no GameInputCreate.

Correct: the #-ordinal convention, both tables’ gameinput.dll/#1 entries, mutual exclusivity, and the no-SDL target registration. No game files; code read only. AI-assisted (OpenCode).

@MartinIndra02

Copy link
Copy Markdown
Contributor

Independent build + test: builds and the new test passes, but this replaces the documented host GameInput path on Windows (BUG / design conflict)

AI-assisted (Claude Code). Windows 11 x64, MSVC 19.44.35220, Ninja RelWithDebInfo. GPU (not used): NVIDIA GeForce RTX 3080 driver 621.24 / 32.0.16.2124.

Head 4d964643f, based on current main (dde82f27e). This build dir has no SDL3 (SDL3_DIR-NOTFOUND, LEONIDA_SDL3_FETCH=OFF), so it takes the PR's no-SDL branch.

Build / test Result
reconfigure + gameinput_no_sdl_test, gta6rt built. gta6rt.exe links with both shim tables, so there's no duplicate registration
gameinput_no_sdl_test.exe exit 0, 0 failure(s) (9 checks ok)
ctest -R "^gameinput_host$" (built gameinput_host_test + fixture) Passed: this machine's C:\Windows\System32\GameInput.dll binds from mapped code and answers GameInputCreate/GetCurrentReading

Problem: the loader checks shims before host DLLs (pe_loader.cpp:1525 / :1570 shims::find before LoadLibraryExA). So with this PR, every Windows build without SDL3 serves gameinput.dll!GameInputCreate and #1 from the device-less stub. Before, it used the host's GameInput.dll. docs/gameinput.md:9-15 and :31-34, and the comment at runtime/CMakeLists.txt:371-372, describe that host path as the intended no-SDL behaviour (#279: "That works for Xbox pads"), and gameinput_host tests it. Concretely, on a Windows 11 machine without SDL3 but with GameInput.dll, an Xbox pad that used to work through the host DLL now sees no devices (E_NOTIMPL from every slot past Release). gameinput_host still passes, because it doesn't link gta6rt, so CI won't catch this.

The crash the PR describes (a null interface from the host's DLL) is a Wine problem. One option is to serve the stub only when the host GameInput.dll can't be loaded, or only under Wine (hostwine::host_is_wine() already exists in the tests). The other is to update docs/gameinput.md and the CMake comment to say the host path is gone.

Other notes:

  • The stub's E_NOTIMPL is returned through slots that don't return HRESULT in IGameInput v0. Slot 3 GetCurrentTimestamp returns uint64_t, so a title gets 0x80004001 as a timestamp. UnregisterCallback returns bool, so it gets "true". StopCallback/SetFocusPolicy return void. Returning 0 for the non-HRESULT slots (or at least for slot 3) would be safer.
  • gameinput_no_sdl_test.cpp: check(release(object) >= 0, ...) is always true because ULONG is unsigned, so the "does not underflow" check tests nothing. The vtable[9] comment says "device query", but v0 slot 9 is RegisterDeviceCallback.
  • stub_qi returns the object for any IID, including ones it doesn't implement. That's deliberate per the comment, but it means a QueryInterface for a newer IGameInput version gets a v0-shaped table.

zneel added a commit to zneel/Leonida that referenced this pull request Nov 23, 2026
…tLeonida#7896)

The retail executable imports GameInput.dll by ordinal 1 only, so the name-only
shim entry was never bound and the loader fell through to the host's GameInput.
Applied from upstream PR ProjectLeonida#7896 (diff applied; the PR branch conflicts in an
unrelated file). Measured on build-boot configured with the local static SDL3
(-DSDL3_DIR): the boot logs the shim's SDL line, the thread dumps have no host
gameinputredist threads, and 6,000+ PresentX in 110 s as before. The title's
nine accessor callers use IGameInput slots 4, 5, 6, 9, 13 and 16, all v0 slots
the shim serves. gameinput_test: 341 checks pass.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
FJKiXfaR pushed a commit to FJKiXfaR/Leonida that referenced this pull request Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants