HLE: implement XUser maximum-users slot 0x30 (#348, #622) #648

Closed
github-bot wants to merge 1 commit from gh-pr/648/head into gh-pr/648/base
Owner

@⁠LAKSHYA-cmd-tech on GitHub · 2026-11-24 06:09 UTC · original
LAKSHYA-cmd-tech:fix/xuser-get-max-users → main · +33 −2 · 1 files · 1 commits · closed without merging

## Summary
Fixes the crash at +0xb5a5f8 (read of uninitialized object at offset x68) right after XUserAddAsync during account init (#348, #622, #630).

Root Cause

During account initialization right after XUserAddAsync, the title's auth subsystem calls slot 0x30 (GetMaxUsers) on the user provider interface (IXUserProvider). Previously, slot 0x30 was mapped to missing::<6>, which returned E_NOTIMPL without writing to the caller's output pointer. The title dereferenced the uninitialized pointer, causing an immediate xc0000005 access violation at +0xb5a5f8.

Fix

  • Implemented get_max_users(_: This, _: Handle, out: *mut u32) -> HRESULT at slot 0x30 in crates/victory-hle/src/modules/xuser.rs. Writes 1 (one local offline user supported) and returns S_OK.
  • Added unit test get_max_users_reports_one_user verifying slot 0x30 returns S_OK, writes 1, and guards against null output pointers with E_INVALIDARG.
  • Preserved existing oken_async offline error reporting and existing startup_adds_the_user_and_reads_its_id assertions.

Verification

  • cargo test -p victory-hle: all 87 tests passed (0 failed).
  • cargo clippy -p victory-hle --all-targets -- -D warnings: clean (0 warnings, 0 errors).

ustfmt --edition 2024 --check crates/victory-hle/src/modules/xuser.rs: clean.

  • cargo xtask policy: 151 files ok.
**@⁠LAKSHYA-cmd-tech** on GitHub · 2026-11-24 06:09 UTC · [original](https://github.com/Marvisak/VIctory/pull/648) `LAKSHYA-cmd-tech:fix/xuser-get-max-users` → `main` · +33 −2 · 1 files · 1 commits · closed without merging ## Summary Fixes the crash at +0xb5a5f8 (read of uninitialized object at offset x68) right after XUserAddAsync during account init (#348, #622, #630). ### Root Cause During account initialization right after XUserAddAsync, the title's auth subsystem calls slot 0x30 (GetMaxUsers) on the user provider interface (IXUserProvider). Previously, slot 0x30 was mapped to missing::<6>, which returned E_NOTIMPL without writing to the caller's output pointer. The title dereferenced the uninitialized pointer, causing an immediate xc0000005 access violation at +0xb5a5f8. ### Fix - Implemented get_max_users(_: This, _: Handle, out: *mut u32) -> HRESULT at slot 0x30 in crates/victory-hle/src/modules/xuser.rs. Writes 1 (one local offline user supported) and returns S_OK. - Added unit test get_max_users_reports_one_user verifying slot 0x30 returns S_OK, writes 1, and guards against null output pointers with E_INVALIDARG. - Preserved existing oken_async offline error reporting and existing startup_adds_the_user_and_reads_its_id assertions. ### Verification - cargo test -p victory-hle: all 87 tests passed (0 failed). - cargo clippy -p victory-hle --all-targets -- -D warnings: clean (0 warnings, 0 errors). - ustfmt --edition 2024 --check crates/victory-hle/src/modules/xuser.rs: clean. - cargo xtask policy: 151 files ok.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:11:27 +00:00
github-bot closed this pull request 2026-11-26 04:11:27 +00:00
Author
Owner

@⁠dpalacios69 on GitHub · 2026-11-24 09:53 UTC · original

Thanks for picking this up! There's an ABI bug in get_max_users that needs to be fixed before merging:

1. Extra Handle parameter shifts out from rdx to r8

In the public GDK C API (from the documented signature, not from a disassembly of the title), XUserGetMaxUsers takes only the output pointer — no XUserHandle:

HRESULT XUserGetMaxUsers(uint32_t* maxUsers);

Every other slot in xuser.rs mirrors the C API 1:1 with This prepended (none of the non-handle slots like add_async, find_by_id, register, etc. take a dummy Handle).

With the current signature:

extern "system" fn get_max_users(_: This, _: Handle, out: *mut u32) -> HRESULT

under the Windows x64 ABI, the caller passes maxUsers in rdx, which is ignored, while put(out, 1) writes 1 through whatever stale value happens to be in r8 (leaving *maxUsers unwritten, and either returning E_INVALIDARG if r8 == 0, silently corrupting 4 bytes if r8 happens to be writable, or crashing with an access violation). The unit test didn't catch this because slot::<GetMaxUsers> transmutes the raw vtable pointer to the same 3-arg signature.

It should be:

extern "system" fn get_max_users(_: This, out: *mut u32) -> HRESULT {
    put(out, 1)
}

And get_max_users_reports_one_user should be updated to match (type GetMaxUsers = extern "system" fn(This, *mut u32) -> HRESULT;). (If you have a capture/disassembly of the call site in #622 showing otherwise, please share!)

2. Minor: misplaced VTABLE comment

Inserting get_max_users between // Unset slots (no title seen calls them): ... and static VTABLE detaches that comment from VTABLE. Moving get_max_users above the // Unset slots comment (or next to compare / add_async) keeps the comment attached to the table.

Reviewed against the diff and the code on main; not run on hardware. AI-assisted.

**@⁠dpalacios69** on GitHub · 2026-11-24 09:53 UTC · [original](https://github.com/Marvisak/VIctory/pull/648#issuecomment-7128036080) Thanks for picking this up! There's an ABI bug in `get_max_users` that needs to be fixed before merging: ### 1. Extra `Handle` parameter shifts `out` from `rdx` to `r8` In the public GDK C API (from the documented signature, not from a disassembly of the title), `XUserGetMaxUsers` takes only the output pointer — no `XUserHandle`: ```cpp HRESULT XUserGetMaxUsers(uint32_t* maxUsers); ``` Every other slot in `xuser.rs` mirrors the C API 1:1 with `This` prepended (none of the non-handle slots like `add_async`, `find_by_id`, `register`, etc. take a dummy `Handle`). With the current signature: ```rust extern "system" fn get_max_users(_: This, _: Handle, out: *mut u32) -> HRESULT ``` under the Windows x64 ABI, the caller passes `maxUsers` in `rdx`, which is ignored, while `put(out, 1)` writes `1` through whatever stale value happens to be in `r8` (leaving `*maxUsers` unwritten, and either returning `E_INVALIDARG` if `r8 == 0`, silently corrupting 4 bytes if `r8` happens to be writable, or crashing with an access violation). The unit test didn't catch this because `slot::<GetMaxUsers>` transmutes the raw vtable pointer to the same 3-arg signature. It should be: ```rust extern "system" fn get_max_users(_: This, out: *mut u32) -> HRESULT { put(out, 1) } ``` And `get_max_users_reports_one_user` should be updated to match (`type GetMaxUsers = extern "system" fn(This, *mut u32) -> HRESULT;`). (If you have a capture/disassembly of the call site in `#622` showing otherwise, please share!) ### 2. Minor: misplaced `VTABLE` comment Inserting `get_max_users` between `// Unset slots (no title seen calls them): ...` and `static VTABLE` detaches that comment from `VTABLE`. Moving `get_max_users` above the `// Unset slots` comment (or next to `compare` / `add_async`) keeps the comment attached to the table. _Reviewed against the diff and the code on `main`; not run on hardware. AI-assisted._
Author
Owner

@⁠molodayamama on GitHub · 2026-11-24 14:05 UTC · original

Independent Windows check of 241b08f4943973800de7c867d332b32d14436cf5 (Windows 10 22H2 19045, Rust 1.98.1, MSVC x64).

  • cargo test -p victory-hle --locked --lib get_max_users_reports_one_user -- --test-threads=1 --nocapture: 1 passed.

The offline XUser fixture confirms the max-users slot reports one supported user. The test invokes the shim with synthetic arguments.

Only source-built synthetic fixtures were used. AI-assisted verification.

**@⁠molodayamama** on GitHub · 2026-11-24 14:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/648#issuecomment-7133814924) Independent Windows check of `241b08f4943973800de7c867d332b32d14436cf5` (Windows 10 22H2 19045, Rust 1.98.1, MSVC x64). - `cargo test -p victory-hle --locked --lib get_max_users_reports_one_user -- --test-threads=1 --nocapture`: 1 passed. The offline XUser fixture confirms the max-users slot reports one supported user. The test invokes the shim with synthetic arguments. Only source-built synthetic fixtures were used. AI-assisted verification.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:26 UTC · original

Automated triage for the maintainers. Closing because another open pull request covers the same change.

See #398. Same slot as #398 with a wrong signature: it adds a handle argument the public call does not have, so a real call would write through whatever is in the third argument register. Its crash explanation (the title calling slot 0x30 at account init) is unsupported.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

**@⁠Marvisak** on GitHub · 2026-11-25 00:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/648#issuecomment-7148518867) Automated triage for the maintainers. Closing because another open pull request covers the same change. See #398. Same slot as #398 with a wrong signature: it adds a handle argument the public call does not have, so a real call would write through whatever is in the third argument register. Its crash explanation (the title calling slot 0x30 at account init) is unsupported. If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!648
No description provided.