diff --git a/CHANGELOG.md b/CHANGELOG.md index 94a34ad5..96eae9f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ Guest execution uses original, purpose-built test programs. Commercial Xbox game remains unsupported. ### Added +- Implemented the `IGameInput` v0 device-callback lifecycle (`RegisterDeviceCallback`, `StopCallback`, `UnregisterCallback`) and `SetFocusPolicy` in `shims/gameinput/gameinput.cpp` (#481). `RegisterDeviceCallback` validates `callbackFunc`, `inputKind`, `statusFilter`, and `enumerationKind` (`0..=2`), allocates unique monotonic `GameInputCallbackToken` handles under `SRWLOCK`, and supports optional null `callbackToken` output pointers; `StopCallback` marks active registrations stopped while keeping them unregisterable once via `UnregisterCallback`; `SetFocusPolicy` records focus-policy flags without stub noise. Expanded `test_audio_input.exe` to cover validation, token uniqueness, stop/unregister idempotence, and focus-policy calls. - `dxbc-accc` now reaches Windows guests as `bx_shader_bridge.dll`, the x86-64 Windows build of the same crate (#445). It exports exactly the three `bx_shader_bridge.h` entry points and needs no MinGW runtime DLL. `shader-transpiler/crates/dxbc-accc/guest/build.sh` builds the DLL and checks its exports and imports. It also builds `check_bridge.exe`, a C guest program compiled against the frozen header, which sends a real DXC SM 6.6 blob and eight synthetic containers (DXIL with and without trailing bytes, `ACCC`/`FSPX` v1 and v0, dual, legacy `SHEX`, malformed) through the DLL loaded by full path. It checks classification (exact chunk sizes, root signature flag, header digest, declared size), prepare (only the declared container is copied), free, and prints a DXIL vs. `ACCC` count. The build script always uses `/target` and rustup's toolchain, and checks the whole Export Address Table and an import allowlist. On one Apple M5 Pro with CrossOver 26.3, in a prefix and a D3DMetal bottle, it reported `dxil=3 accc_only=2 dual=1 legacy=1 invalid=2` and passed. Synthetic containers only. Staging the DLL in `build-shims`, an `abi/defs` export list, and the `d3d12_xs` PSO hook (#466) are separate changes. - `xgameruntime.dll!QueryApiImpl` now serves offline `XGameSave` and `XPackage` as COM `IUnknown` objects under BetterXen synthetic keys (#468, not yet closed). A title linked against Microsoft's `xgameruntime.lib` does not request these keys. Every synthetic key and COM slot order now lives in `shims/xgameruntime/synthetic_keys.h`, the single place to find or replace them. Signatures, structure layouts, `E_GS_*` values and container-name rules follow the public Microsoft Learn reference. - **XGameSave:** provider init, containers, updates, blob writes, submit and read (both asynchronous), enumeration and the close calls. Saves are separated by SCID: each container is one file under `C:\bx_pls\\saves\\`, replaced atomically on submit. A named mutex per SCID directory serializes access across threads and processes. Damaged files (truncated, trailing bytes, duplicate or NUL-bearing names) read as `ERROR_FILE_CORRUPT`, and enumeration skips them and unreadable files with a log line. Offline choices where the reference is silent (16 MiB including blob names, 256-byte blob names, no sync, retry after a failed submit) are listed in `game_save.cpp`. @@ -109,7 +110,7 @@ remains unsupported. - Extended the read-only RDNA2 planning CLI (`python3 -m qa rdna2`) with family/status filters, compact summaries, Codex-ready manifests under `artifacts/`, active-claim exclusion (family claims exclude those families; path-only claims block overlapping permitted files), coverage reconcile against `semantic_coverage` without inflating counts, and inventory diffs. Covered by `tests/qa/test_rdna2_plan.py`; planning only, no GPU production edits. ### Fixed -- `d3dmetal-harness` runner tests no longer give a freshly written script only 300–500 ms to start (#479); both use a 2 s deadline. The kill test now also checks that the probe ran until the deadline and that its process is gone, which catches a timeout path that neither kills nor waits for the probe. Test-only change. Slow script start-up as the cause of the earlier failures is inferred, not measured. `output_complete` is not asserted for the killed probe, because a child spawned by a parallel test may inherit its pipe. +- `bx-cli run` now stages `GameInput.dll` into `system32` alongside `xgameruntime.dll` and safely replaces Wine's `"Wine builtin DLL"` placeholder stub after saving a one-time backup (`.gameinput.dll.wine-builtin.bak`), while continuing to refuse modifying any non-Wine foreign DLL or symbolic link (#482). Wine pre-populates `drive_c/windows/system32/gameinput.dll` with a fake builtin PE stub whose `GameInputCreate` returns `E_NOTIMPL`, shadowing `WINEPATH` and `LOAD_LIBRARY_SEARCH_SYSTEM32` loads even when `WINEDLLOVERRIDES` specifies native-first (`=n,b`). Also added lowercase aliases (`gameinput`, `xcrdapi`, `acphal`) to `SHIM_DLL_OVERRIDES` and expanded `test_system32_staging.exe` and `stage.rs` unit tests to cover `GameInput.dll` staging and Wine stub backup/refusal rules. - `bx-cli run` system32 shim staging (#474). Staging now records what it wrote in a `.bx-staged` manifest in the prefix's `system32` (one SHA-256 per file) and replaces only regular files that are listed there and still have the recorded hash. Any other same-named entry the bottle already had, including a symbolic link that points nowhere, or one changed since it was staged, is never modified or deleted: staging stops with an error naming it before anything is written. New files are installed without replacing anything, so an entry that appears after the checks is protected too. All temporary copies are written before the first file is put in place, and each installed file is recorded in the manifest before the next one is touched, so a failure part-way leaves the earlier files owned rather than orphaned. A byte-identical existing file is left alone and not claimed. For a named bottle, the prefix is resolved again after the run; if CrossOver launched the bottle elsewhere, the run fails only when the staged shims cannot be found with the same contents in that prefix's `system32` (a private stub of a managed bottle that links back to the managed prefix is accepted and reported). When prefix initialization uses the whole `--timeout`, the guest is no longer started and the message names initialization (exit 124). Copies staged by an earlier `bx-cli` have no manifest entry and are treated as the bottle's own, so after upgrading a changed shim needs that stale copy removed by hand once. Staged files are still not removed after a run. Covered by 15 new unit tests (32 `bx-cli` tests pass); twelve deliberate breakages each failed a test. A reviewer ran the first revision on CrossOver 26.3 with a managed-only bottle and found the false failure, dangling-link and partial-failure cases fixed here; this revision has not itself been run under CrossOver. - Fixed `bx-cli run --bottle` losing the shim DLL overrides: CrossOver's `bin/wine` discards `WINEDLLOVERRIDES`, so they are now passed with `--dll` (found by jelly013) (#408). - `test_integration_boot.exe` now creates a real texture address computer, checks a two-mip layout against hand-computed values and requires the final `Release` to return 0, instead of reporting that stage as pending after a null-descriptor probe (#446). @@ -123,6 +124,7 @@ remains unsupported. - An instruction longer than 15 bytes now stops both engines with a general-protection fault instead of an illegal-instruction exit (#384; Intel SDM Vol. 3A, 7.15). The decoder still stops before fetching a 16th byte, and the DBT translates the faulting instruction on its own so the instructions before it in a block complete first. The `defect_overlong_instruction` known answer from #155 is now verified, with three more cases. - Made the native semantic-review timeout in `scripts/test-gpu.sh` configurable with `XENORA_SEMANTIC_TIMEOUT` and raised its default from 120 to 300 seconds, so cold Apple Silicon runs do not fail while the expanded Metal known-answer suite is still progressing. - Added a Python 3 fallback for `timeout` in `scripts/test-gpu.sh`, so the native Metal suite runs on stock macOS without GNU coreutils while preserving bounded execution and the usual timeout exit status. +- `d3dmetal-harness` runner tests no longer give a freshly written script only 300–500 ms to start (#479); both use a 2 s deadline. The kill test now also checks that the probe ran until the deadline and that its process is gone, which catches a timeout path that neither kills nor waits for the probe. Test-only change. Slow script start-up as the cause of the earlier failures is inferred, not measured. `output_complete` is not asserted for the killed probe, because a child spawned by a parallel test may inherit its pipe. ### Added - Added opt-in `betterxen run --startup-report ` JSON diagnostics with the last observed startup stage, fixture verification outcome and preserved failure or termination detail (#255). diff --git a/launcher/crates/bx-cli/src/main.rs b/launcher/crates/bx-cli/src/main.rs index f285c503..36edabd0 100644 --- a/launcher/crates/bx-cli/src/main.rs +++ b/launcher/crates/bx-cli/src/main.rs @@ -16,7 +16,7 @@ use bx_telemetry::summarize_jsonl; use dxbc_accc::inspect_dxbc; use supervise::{Outcome, Stop}; -const SHIM_DLL_OVERRIDES: &str = "bx_runtime_veh,d3d12_xs,xg_xs,xmem,XCRDAPI,xgameruntime,AcpHal,xapu,chad,GameInput,\ +const SHIM_DLL_OVERRIDES: &str = "bx_runtime_veh,d3d12_xs,xg_xs,xmem,xcrdapi,XCRDAPI,xgameruntime,acphal,AcpHal,xapu,chad,gameinput,GameInput,\ api-ms-win-core-psm-appnotify-l1-1-0,api-ms-win-core-psm-appnotify-l1-1-1,\ ext-ms-win-rtcore-ntuser-message-l1-1-0,ext-ms-win-rtcore-ntuser-message-ansi-l1-1-0,\ ext-ms-win-rtcore-ntuser-window-l1-1-0,ext-ms-win-rtcore-ntuser-window-ansi-l1-1-0=n,b"; @@ -627,6 +627,7 @@ fn cmd_run(args: &[String]) -> ExitCode { for item in &staged { if let stage::Staged::Copied(path) | stage::Staged::Replaced(path) + | stage::Staged::ReplacedWineStub(path) | stage::Staged::Unchanged(path) = item && let Some(name) = path.file_name() { diff --git a/launcher/crates/bx-cli/src/stage.rs b/launcher/crates/bx-cli/src/stage.rs index f2464df4..354a2aea 100644 --- a/launcher/crates/bx-cli/src/stage.rs +++ b/launcher/crates/bx-cli/src/stage.rs @@ -19,8 +19,32 @@ use std::fs; use std::io; use std::path::{Path, PathBuf}; -/// Shims loaded with `LOAD_LIBRARY_SEARCH_SYSTEM32`. -pub const SYSTEM32_SHIMS: &[&str] = &["xgameruntime.dll"]; +/// Shims loaded with `LOAD_LIBRARY_SEARCH_SYSTEM32` (or shadowed by Wine builtin stubs in +/// `system32`, which Windows searches before `WINEPATH`). +pub const SYSTEM32_SHIMS: &[&str] = &["xgameruntime.dll", "GameInput.dll"]; + +/// Returns true when `bytes` is a Wine `winebuild` fake-DLL placeholder stub in `system32` +/// (`"MZ"` header, `"Wine builtin DLL\0"` at DOS offset `0x40`, and `"PE\0\0"` at `e_lfanew`). +/// +/// Wine populates `drive_c/windows/system32/` with fake PE stubs for built-in modules such as +/// `gameinput.dll`. Unlike user- or installer-provided native DLLs (#474), these placeholders are +/// created by Wine itself and would otherwise shadow BetterXen shims on `LOAD_LIBRARY_SEARCH_SYSTEM32` +/// loads (`fixme:ginput:GameInputCreate ... stub!`). +pub fn is_wine_builtin_dll(bytes: &[u8]) -> bool { + const WINE_SIG_OFFSET: usize = 0x40; + const WINE_SIG: &[u8] = b"Wine builtin DLL\0"; + if bytes.len() < WINE_SIG_OFFSET + WINE_SIG.len() + 4 { + return false; + } + if &bytes[0..2] != b"MZ" { + return false; + } + if &bytes[WINE_SIG_OFFSET..WINE_SIG_OFFSET + WINE_SIG.len()] != WINE_SIG { + return false; + } + let pe_off = u32::from_le_bytes([bytes[0x3c], bytes[0x3d], bytes[0x3e], bytes[0x3f]]) as usize; + pe_off >= WINE_SIG_OFFSET + WINE_SIG.len() && bytes.get(pe_off..pe_off + 4) == Some(b"PE\0\0") +} /// `roots` plus, transitively, every import that is itself a file in the shim folder /// (`is_shim`). Names are compared case-insensitively, as the Windows loader does, and returned @@ -220,6 +244,8 @@ pub enum Staged { Copied(PathBuf), /// An earlier copy staged by this tool, refreshed because the shim changed. Replaced(PathBuf), + /// A Wine `"Wine builtin DLL"` placeholder stub in `system32`, backed up once and replaced. + ReplacedWineStub(PathBuf), Unchanged(PathBuf), /// A [`SYSTEM32_SHIMS`] file the shim folder does not have. Absent(PathBuf), @@ -230,6 +256,9 @@ impl Staged { match self { Staged::Copied(p) => format!("staged {}", p.display()), Staged::Replaced(p) => format!("refreshed own earlier copy {}", p.display()), + Staged::ReplacedWineStub(p) => { + format!("replaced Wine builtin stub {} (backup saved)", p.display()) + } Staged::Unchanged(p) => format!("already current {}", p.display()), Staged::Absent(p) => format!("not staged, {} not found", p.display()), } @@ -365,6 +394,8 @@ where )); } else if existing.as_deref().map(sha256_hex).as_ref() == owned.get(name) { Staged::Replaced(dst.clone()) + } else if existing.as_deref().is_some_and(is_wine_builtin_dll) { + Staged::ReplacedWineStub(dst.clone()) } else { return Err(foreign( &dst, @@ -415,6 +446,41 @@ where format!("cannot install {}: {e}", dst.display()) } }), + // Wine fake-DLL placeholder stub: verify it is still a regular Wine builtin stub, + // preserve a one-time backup `..wine-builtin.bak`, then atomically replace. + Staged::ReplacedWineStub(_) => match fs::symlink_metadata(&dst) { + Ok(meta) if meta.is_file() => match fs::read(&dst) { + Ok(now) if is_wine_builtin_dll(&now) => { + let bak = system32.join(format!(".{name}.wine-builtin.bak")); + if fs::symlink_metadata(&bak).is_err() { + let bak_tmp = system32.join(format!( + ".{name}.wine-builtin.bak.{}.bx-staging", + std::process::id() + )); + fs::write(&bak_tmp, &now).map_err(|e| { + let _ = fs::remove_file(&bak_tmp); + format!("cannot write backup {}: {e}", bak_tmp.display()) + })?; + let bak_res = install_new(&bak_tmp, &bak, &now); + let _ = fs::remove_file(&bak_tmp); + match bak_res { + Ok(()) => {} + Err(e) if e.kind() == io::ErrorKind::AlreadyExists => {} + Err(e) => { + return Err(format!( + "cannot save Wine stub backup {}: {e}", + bak.display() + )); + } + } + } + fs::rename(&tmp, &dst) + .map_err(|e| format!("cannot replace {}: {e}", dst.display())) + } + _ => Err(foreign(&dst, name, "changed while staging")), + }, + _ => Err(foreign(&dst, name, "changed while staging")), + }, // Still our own earlier copy? Then the rename replaces it in one step. _ => match fs::read(&dst) { Ok(now) if owned.get(name) == Some(&sha256_hex(&now)) => fs::rename(&tmp, &dst) @@ -511,11 +577,12 @@ mod tests { let (_t, shims, prefix) = setup("deps"); let sys = system32_dir(&prefix); let staged = stage(&shims, &sys).unwrap(); - assert_eq!(staged.len(), 2, "{staged:?}"); + assert_eq!(staged.len(), 3, "{staged:?}"); assert_eq!(fs::read(sys.join("bx_runtime_veh.dll")).unwrap(), b"veh v1"); + assert_eq!(fs::read(sys.join("gameinput.dll")).unwrap(), b"shim v1"); assert!( !sys.join("unrelated.dll").exists(), - "only imported shims are staged" + "only SYSTEM32_SHIMS and imported shims are staged" ); } @@ -867,10 +934,15 @@ mod tests { #[test] fn missing_shim_is_reported_and_nothing_is_staged() { let (t, shims, prefix) = setup("missing"); - fs::remove_file(shims.join("xgameruntime.dll")).unwrap(); + for name in SYSTEM32_SHIMS { + fs::remove_file(shims.join(name)).unwrap(); + } assert!(!has_system32_shims(&shims)); let sys = system32_dir(&prefix); - let expected = vec![Staged::Absent(shims.join("xgameruntime.dll"))]; + let expected: Vec = SYSTEM32_SHIMS + .iter() + .map(|name| Staged::Absent(shims.join(name))) + .collect(); assert_eq!(stage(&shims, &sys).unwrap(), expected); assert_eq!(fs::read_dir(&sys).unwrap().count(), 0); // With nothing to stage, a prefix without system32 is not an error either. @@ -879,6 +951,71 @@ mod tests { assert!(!fresh.exists()); } + fn make_fake_wine_builtin_pe() -> Vec { + let mut pe = vec![0u8; 0x100]; + pe[0..2].copy_from_slice(b"MZ"); + pe[0x3c..0x40].copy_from_slice(&(0x80u32).to_le_bytes()); + pe[0x40..0x51].copy_from_slice(b"Wine builtin DLL\0"); + pe[0x80..0x84].copy_from_slice(b"PE\0\0"); + pe + } + + #[test] + fn replaces_a_wine_builtin_stub_after_saving_a_backup() { + let (_t, shims, prefix) = setup("wine-stub"); + let sys = system32_dir(&prefix); + let wine_stub = make_fake_wine_builtin_pe(); + assert!(is_wine_builtin_dll(&wine_stub)); + fs::write(sys.join("gameinput.dll"), &wine_stub).unwrap(); + + let first = stage(&shims, &sys).unwrap(); + assert!(first.contains(&Staged::ReplacedWineStub(sys.join("gameinput.dll")))); + assert_eq!(fs::read(sys.join("gameinput.dll")).unwrap(), b"shim v1"); + assert_eq!( + fs::read(sys.join(".gameinput.dll.wine-builtin.bak")).unwrap(), + wine_stub + ); + let owned = read_manifest(&sys).unwrap(); + assert_eq!(owned.get("gameinput.dll"), Some(&sha256_hex(b"shim v1"))); + + // Subsequent rebuilds refresh our owned copy while keeping the original Wine backup intact. + fs::write(shims.join("GameInput.dll"), b"shim v2").unwrap(); + let second = stage(&shims, &sys).unwrap(); + assert!(second.contains(&Staged::Replaced(sys.join("gameinput.dll")))); + assert_eq!(fs::read(sys.join("gameinput.dll")).unwrap(), b"shim v2"); + assert_eq!( + fs::read(sys.join(".gameinput.dll.wine-builtin.bak")).unwrap(), + wine_stub + ); + } + + #[test] + fn non_wine_pe_and_symlinks_to_wine_stubs_are_still_refused() { + let (t, shims, prefix) = setup("non-wine-pe"); + let sys = system32_dir(&prefix); + // A regular native PE (standard DOS stub, no "Wine builtin DLL" marker) is foreign. + let mut native_pe = make_fake_wine_builtin_pe(); + native_pe[0x40..0x51].copy_from_slice(b"This program can!"); + assert!(!is_wine_builtin_dll(&native_pe)); + fs::write(sys.join("gameinput.dll"), &native_pe).unwrap(); + assert!(stage(&shims, &sys).is_err()); + assert_eq!(fs::read(sys.join("gameinput.dll")).unwrap(), native_pe); + + // A symlink pointing to a real Wine builtin stub is ALSO refused (never follow links). + fs::remove_file(sys.join("gameinput.dll")).unwrap(); + let wine_target = t.0.join("wine_gameinput.dll"); + fs::write(&wine_target, make_fake_wine_builtin_pe()).unwrap(); + std::os::unix::fs::symlink(&wine_target, sys.join("gameinput.dll")).unwrap(); + let err = stage(&shims, &sys).unwrap_err(); + assert!(err.contains("symbolic link"), "{err}"); + assert!( + fs::symlink_metadata(sys.join("gameinput.dll")) + .unwrap() + .file_type() + .is_symlink() + ); + } + #[test] fn uninitialized_prefix_is_an_error_not_a_skip() { let (t, shims, _prefix) = setup("uninit"); diff --git a/shims/gameinput/gameinput.cpp b/shims/gameinput/gameinput.cpp index dea10417..b2f860c0 100644 --- a/shims/gameinput/gameinput.cpp +++ b/shims/gameinput/gameinput.cpp @@ -1,6 +1,8 @@ #include #include +#include #include +#include #include "bx_log.h" @@ -10,6 +12,30 @@ constexpr GUID game_input_v0 = {0x11be2a7e, 0x4254, 0x445a, {0x9c, 0x09, 0xff, 0xc4, 0x0f, 0x00, 0x69, 0x18}}; using Callback = void (WINAPI*)(); +// GameInputEnumerationKind values from Microsoft's public GDK GameInput (v0) reference: +// 0 = GameInputNoEnumeration, 1 = GameInputAsyncEnumeration, 2 = GameInputBlockingEnumeration. +constexpr uint32_t kMaxEnumerationKind = 2; + +struct SrwExclusiveLock { + explicit SrwExclusiveLock(SRWLOCK& lock) : lock_(lock) { AcquireSRWLockExclusive(&lock_); } + ~SrwExclusiveLock() { ReleaseSRWLockExclusive(&lock_); } + SrwExclusiveLock(const SrwExclusiveLock&) = delete; + SrwExclusiveLock& operator=(const SrwExclusiveLock&) = delete; + +private: + SRWLOCK& lock_; +}; + +struct RegisteredDeviceCallback { + void* device = nullptr; + uint32_t input_kind = 0; + uint32_t status_filter = 0; + uint32_t enumeration_kind = 0; + void* context = nullptr; + Callback callback = nullptr; + bool stopped = false; +}; + template HRESULT unavailable(T* out) { if (!out) return E_POINTER; @@ -19,6 +45,11 @@ HRESULT unavailable(T* out) { class GameInput final : public IUnknown { LONG refs = 0; + SRWLOCK callback_lock_ = SRWLOCK_INIT; + uint64_t next_token_ = 1; + std::unordered_map callbacks_; + std::atomic focus_policy_{0}; + public: HRESULT WINAPI QueryInterface(REFIID iid, void** out) override { if (!out) return E_POINTER; @@ -54,9 +85,32 @@ public: BX_VTABLE_STUB_LOG("IGameInput", 8, "RegisterReadingCallback"); return unavailable(out); } - virtual HRESULT WINAPI RegisterDeviceCallback(void*, uint32_t, uint32_t, uint32_t, void*, Callback, uint64_t* out) { - BX_VTABLE_STUB_LOG("IGameInput", 9, "RegisterDeviceCallback"); - return unavailable(out); + virtual HRESULT WINAPI RegisterDeviceCallback( + void* device, + uint32_t input_kind, + uint32_t status_filter, + uint32_t enumeration_kind, + void* context, + Callback callback, + uint64_t* out_token + ) { + if (out_token) *out_token = 0; + if (!callback || input_kind == 0 || status_filter == 0 || enumeration_kind > kMaxEnumerationKind) { + return E_INVALIDARG; + } + SrwExclusiveLock guard(callback_lock_); + const uint64_t token = next_token_++; + callbacks_.emplace(token, RegisteredDeviceCallback{ + device, + input_kind, + status_filter, + enumeration_kind, + context, + callback, + false, + }); + if (out_token) *out_token = token; + return S_OK; } virtual HRESULT WINAPI RegisterSystemButtonCallback(void*, uint32_t, void*, Callback, uint64_t* out) { BX_VTABLE_STUB_LOG("IGameInput", 10, "RegisterSystemButtonCallback"); @@ -66,12 +120,18 @@ public: BX_VTABLE_STUB_LOG("IGameInput", 11, "RegisterKeyboardLayoutCallback"); return unavailable(out); } - virtual void WINAPI StopCallback(uint64_t) { - BX_VTABLE_STUB_LOG("IGameInput", 12, "StopCallback"); + virtual void WINAPI StopCallback(uint64_t token) { + if (token == 0) return; + SrwExclusiveLock guard(callback_lock_); + auto it = callbacks_.find(token); + if (it != callbacks_.end()) { + it->second.stopped = true; + } } - virtual bool WINAPI UnregisterCallback(uint64_t, uint64_t) { - BX_VTABLE_STUB_LOG("IGameInput", 13, "UnregisterCallback"); - return false; + virtual bool WINAPI UnregisterCallback(uint64_t token, uint64_t /*timeout_us*/) { + if (token == 0) return false; + SrwExclusiveLock guard(callback_lock_); + return callbacks_.erase(token) > 0; } virtual HRESULT WINAPI CreateDispatcher(void** out) { BX_VTABLE_STUB_LOG("IGameInput", 14, "CreateDispatcher"); @@ -101,8 +161,8 @@ public: BX_VTABLE_STUB_LOG("IGameInput", 20, "EnableOemDeviceSupport"); return E_NOTIMPL; } - virtual void WINAPI SetFocusPolicy(uint32_t) { - BX_VTABLE_STUB_LOG("IGameInput", 21, "SetFocusPolicy"); + virtual void WINAPI SetFocusPolicy(uint32_t policy) { + focus_policy_.store(policy, std::memory_order_relaxed); } }; diff --git a/tests/conformance/test_audio_input/main.cpp b/tests/conformance/test_audio_input/main.cpp index f2550155..ae094ff0 100644 --- a/tests/conformance/test_audio_input/main.cpp +++ b/tests/conformance/test_audio_input/main.cpp @@ -27,6 +27,10 @@ HRESULT WINAPI XDspDisconnect(void*); #define CHECK(expr) do { if (!(expr)) { std::fprintf(stderr, "line %d: %s\n", __LINE__, #expr); return 1; } } while (0) +namespace { +void WINAPI dummy_device_callback(uint64_t, void*, void*, uint64_t, uint32_t, uint32_t) {} +} // namespace + int main() { void* object = nullptr; CHECK(AcpHalCreate(&object) == S_OK && object); @@ -148,8 +152,42 @@ int main() { using Reading = HRESULT (WINAPI*)(IUnknown*, uint32_t, void*, void**); void* reading = reinterpret_cast(uintptr_t{1}); CHECK(reinterpret_cast(table[4])(v0, 0, nullptr, &reading) == E_NOTIMPL && !reading); + + using RegisterDeviceCb = HRESULT (WINAPI*)( + IUnknown*, void*, uint32_t, uint32_t, uint32_t, void*, void*, uint64_t*); + using StopCb = void (WINAPI*)(IUnknown*, uint64_t); + using UnregisterCb = bool (WINAPI*)(IUnknown*, uint64_t, uint64_t); + using SetFocusPolicyFn = void (WINAPI*)(IUnknown*, uint32_t); + auto reg_dev = reinterpret_cast(table[9]); + auto stop_cb = reinterpret_cast(table[12]); + auto unreg_cb = reinterpret_cast(table[13]); + auto set_focus = reinterpret_cast(table[21]); + void* cb_fn = reinterpret_cast(&dummy_device_callback); + + uint64_t tok1 = 99, tok2 = 0; + CHECK(reg_dev(v0, nullptr, 1, 1, 0, nullptr, nullptr, &tok1) == E_INVALIDARG && tok1 == 0); + tok1 = 99; + CHECK(reg_dev(v0, nullptr, 0, 1, 0, nullptr, cb_fn, &tok1) == E_INVALIDARG && tok1 == 0); + tok1 = 99; + CHECK(reg_dev(v0, nullptr, 1, 0, 0, nullptr, cb_fn, &tok1) == E_INVALIDARG && tok1 == 0); + tok1 = 99; + CHECK(reg_dev(v0, nullptr, 1, 1, 3, nullptr, cb_fn, &tok1) == E_INVALIDARG && tok1 == 0); + + CHECK(reg_dev(v0, nullptr, 0x10000, 0x1, 2, &tok1, cb_fn, &tok1) == S_OK && tok1 != 0); + CHECK(reg_dev(v0, nullptr, 0x10000, 0x1, 1, nullptr, cb_fn, &tok2) == S_OK && tok2 > tok1); + CHECK(reg_dev(v0, nullptr, 0x10000, 0x1, 0, nullptr, cb_fn, nullptr) == S_OK); + + CHECK(!unreg_cb(v0, 0, 5000)); + CHECK(!unreg_cb(v0, 0xdeadbeefULL, 5000)); + stop_cb(v0, tok1); + CHECK(unreg_cb(v0, tok1, 5000)); + CHECK(!unreg_cb(v0, tok1, 5000)); + CHECK(unreg_cb(v0, tok2, 0)); + CHECK(!unreg_cb(v0, tok2, 0)); + set_focus(v0, 0x2); + CHECK(v0->Release() == 1); CHECK(input->Release() == 0); FreeLibrary(dll); - std::puts("PASS: audio mappings, APU and DSP queues, GameInput ordinal 1"); + std::puts("PASS: audio mappings, APU and DSP queues, GameInput ordinal 1 and device callbacks"); } diff --git a/tests/conformance/test_system32_staging/main.cpp b/tests/conformance/test_system32_staging/main.cpp index 1ba1b7f1..7a13fd01 100644 --- a/tests/conformance/test_system32_staging/main.cpp +++ b/tests/conformance/test_system32_staging/main.cpp @@ -1,17 +1,23 @@ /* - * #457: clean-room synthetic test for system32 shim staging by `bx-cli run`. + * #457 / #482: clean-room synthetic test for system32 shim staging by `bx-cli run`. * - * GDK titles load the runtime with LoadLibraryExW(L"xgameruntime.dll", NULL, + * GDK titles load `xgameruntime.dll` and `GameInput.dll` with LoadLibraryExW(..., * LOAD_LIBRARY_SEARCH_SYSTEM32), which does not search WINEPATH or the executable's folder. - * This test makes that load and requires that BetterXen's shim answers it: - * - the module loads, from a path under system32; - * - it exports QueryApiImpl (a BetterXen xgameruntime export, absent from Wine builtins); - * - LOAD_LIBRARY_SEARCH_SYSTEM32 | LOAD_LIBRARY_SEARCH_APPLICATION_DIR gives the same module. + * In addition, Wine pre-populates `system32\gameinput.dll` with a builtin stub whose + * `GameInputCreate` returns E_NOTIMPL. * - * `--expect-missing` is the negative control for an unstaged prefix: the load must fail. + * This test makes both loads and requires that BetterXen's shims answer them: + * - xgameruntime.dll loads from system32, exports QueryApiImpl, and matches + * LOAD_LIBRARY_SEARCH_SYSTEM32 | LOAD_LIBRARY_SEARCH_APPLICATION_DIR; + * - GameInput.dll loads from system32, exports GameInputCreate (@1 and by name), and + * GameInputCreate(&input) returns S_OK with a valid IUnknown pointer. + * + * `--expect-missing` is the negative control for an unstaged prefix: xgameruntime.dll must + * fail to load, and GameInput.dll must either fail to load or fail GameInputCreate (Wine stub). * Exit 0 on pass, 1 on failure. */ #include +#include #include #include @@ -33,13 +39,13 @@ bool check(bool ok, const char* what) { return ok; } -bool path_in_system32(HMODULE m) { +bool path_in_system32(HMODULE m, const wchar_t* needle) { wchar_t path[MAX_PATH * 2] = {}; const DWORD n = GetModuleFileNameW(m, path, MAX_PATH * 2); if (n == 0 || n >= MAX_PATH * 2) return false; for (DWORD i = 0; i < n; ++i) path[i] = static_cast(towlower(path[i])); std::printf("INFO: loaded from %ls\n", path); - return std::wcsstr(path, L"\\windows\\system32\\xgameruntime.dll") != nullptr; + return std::wcsstr(path, needle) != nullptr; } } // namespace @@ -49,16 +55,57 @@ int main(int argc, char** argv) { HMODULE sys = LoadLibraryExW(L"xgameruntime.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32); if (expect_missing) { - check(sys == nullptr, "unstaged: LOAD_LIBRARY_SEARCH_SYSTEM32 load fails"); + check(sys == nullptr, "unstaged: LOAD_LIBRARY_SEARCH_SYSTEM32 xgameruntime.dll load fails"); if (sys) FreeLibrary(sys); - } else if (check(sys != nullptr, "LOAD_LIBRARY_SEARCH_SYSTEM32 loads xgameruntime.dll")) { - check(path_in_system32(sys), "module path is under system32"); - check(GetProcAddress(sys, "QueryApiImpl") != nullptr, "module exports QueryApiImpl (BetterXen shim)"); - HMODULE both = LoadLibraryExW(L"xgameruntime.dll", nullptr, - LOAD_LIBRARY_SEARCH_SYSTEM32 | LOAD_LIBRARY_SEARCH_APPLICATION_DIR); - check(both == sys, "SYSTEM32 | APPLICATION_DIR search returns the same module"); - if (both) FreeLibrary(both); - FreeLibrary(sys); + + HMODULE gi = LoadLibraryExW(L"GameInput.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32); + bool gi_unusable = (gi == nullptr); + if (gi) { + using CreateFn = HRESULT (WINAPI*)(void**); + auto fn = reinterpret_cast( + reinterpret_cast(GetProcAddress(gi, "GameInputCreate"))); + void* obj = nullptr; + HRESULT hr = fn ? fn(&obj) : E_FAIL; + if (SUCCEEDED(hr) && obj) { + static_cast(obj)->Release(); + } else { + gi_unusable = true; + } + FreeLibrary(gi); + } + check(gi_unusable, "unstaged: GameInput.dll is absent or Wine stub returns failure"); + } else { + if (check(sys != nullptr, "LOAD_LIBRARY_SEARCH_SYSTEM32 loads xgameruntime.dll")) { + check(path_in_system32(sys, L"\\windows\\system32\\xgameruntime.dll"), + "xgameruntime.dll module path is under system32"); + check(GetProcAddress(sys, "QueryApiImpl") != nullptr, + "module exports QueryApiImpl (BetterXen shim)"); + HMODULE both = LoadLibraryExW( + L"xgameruntime.dll", nullptr, + LOAD_LIBRARY_SEARCH_SYSTEM32 | LOAD_LIBRARY_SEARCH_APPLICATION_DIR); + check(both == sys, "SYSTEM32 | APPLICATION_DIR search returns the same module"); + if (both) FreeLibrary(both); + FreeLibrary(sys); + } + + HMODULE gi = LoadLibraryExW(L"GameInput.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32); + if (check(gi != nullptr, "LOAD_LIBRARY_SEARCH_SYSTEM32 loads GameInput.dll")) { + check(path_in_system32(gi, L"\\windows\\system32\\gameinput.dll"), + "GameInput.dll module path is under system32"); + FARPROC ord1 = GetProcAddress(gi, MAKEINTRESOURCEA(1)); + FARPROC named = GetProcAddress(gi, "GameInputCreate"); + check(ord1 != nullptr && ord1 == named, + "GameInput.dll exports GameInputCreate at ordinal 1"); + using CreateFn = HRESULT (WINAPI*)(void**); + auto create = reinterpret_cast(reinterpret_cast(named)); + void* input = nullptr; + HRESULT hr = create ? create(&input) : E_FAIL; + if (check(hr == S_OK && input != nullptr, + "GameInputCreate returns S_OK (BetterXen shim, not Wine builtin stub)")) { + static_cast(input)->Release(); + } + FreeLibrary(gi); + } } std::printf("SUMMARY: %d checks, %d failed\n", g_checks, g_failures); return g_failures == 0 ? 0 : 1;