Skip to content

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

Closed
LAKSHYA-cmd-tech wants to merge 1 commit into
Marvisak:mainfrom
LAKSHYA-cmd-tech:fix/xuser-get-max-users
Closed

LAKSHYA-cmd-tech wants to merge 1 commit into
Marvisak:mainfrom
LAKSHYA-cmd-tech:fix/xuser-get-max-users

Conversation

@LAKSHYA-cmd-tech

Copy link
Copy Markdown

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.

@dpalacios69

Copy link
Copy Markdown
Contributor

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.

@molodayamama

Copy link
Copy Markdown

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.

@Marvisak

Copy link
Copy Markdown
Owner

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 Marvisak closed this Nov 25, 2026
Callimann8 pushed a commit to Callimann8/VIctory-fork that referenced this pull request Nov 25, 2026
…c, draw-table slots left to their draws, no failing write-watch calls; card fetches inside their flights (off by default)

- Descriptor sync: a multiply-and-fold fingerprint of a record in place of
  BLAKE3 (35 to 42 ms a frame over 250,000 to 300,000 records), and slots
  that draws read through tables lately are left to their draws
  (VICTORY_HEAP_SYNC_TABLES=1 mirrors them too): the pass over the heap
  went from 70-220 ms a frame to about 3.
- Write watch: no kernel asking for memory the guards already hold as view
  memory (pull request Marvisak#670 by Jonirulah).
- Card copies' flagged pieces can come down inside their own flights
  (pull request Marvisak#648 by Jonirulah; VICTORY_CARD_FETCH_INFLIGHT=1, off by
  default). One game run with it on: no device loss, the copy-back
  thread's fetch wait 181 -> 0 ms a frame, the card busier; no frame-time
  gain claimed.
- Logging: the heap pass's texture part and buffer slots; indirect compute
  dispatches over 65,535 groups.
- README: what was measured, and that pull request Marvisak#220 with
  VICTORY_INDIRECT_WINDOW=1 lost the device twice here and is not in.

One five-minute game run of this tree's source on an RTX 4070: no device
loss; the frame is still 250 to 380 ms (the card is the limit). This
merged tree was built; its test suites were not run.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
PastiiJay pushed a commit to PastiiJay/klbf-lab-beta that referenced this pull request Nov 25, 2026
…c, draw-table slots left to their draws, no failing write-watch calls; card fetches inside their flights (off by default)

- Descriptor sync: a multiply-and-fold fingerprint of a record in place of
  BLAKE3 (35 to 42 ms a frame over 250,000 to 300,000 records), and slots
  that draws read through tables lately are left to their draws
  (VICTORY_HEAP_SYNC_TABLES=1 mirrors them too): the pass over the heap
  went from 70-220 ms a frame to about 3.
- Write watch: no kernel asking for memory the guards already hold as view
  memory (pull request Marvisak#670 by Jonirulah).
- Card copies' flagged pieces can come down inside their own flights
  (pull request Marvisak#648 by Jonirulah; VICTORY_CARD_FETCH_INFLIGHT=1, off by
  default). One game run with it on: no device loss, the copy-back
  thread's fetch wait 181 -> 0 ms a frame, the card busier; no frame-time
  gain claimed.
- Logging: the heap pass's texture part and buffer slots; indirect compute
  dispatches over 65,535 groups.
- README: what was measured, and that pull request Marvisak#220 with
  VICTORY_INDIRECT_WINDOW=1 lost the device twice here and is not in.

One five-minute game run of this tree's source on an RTX 4070: no device
loss; the frame is still 250 to 380 ms (the card is the limit). This
merged tree was built; its test suites were not run.
Biskwit added a commit to Biskwit/VIctory-reloaded that referenced this pull request Nov 26, 2026
The pass over descriptor records copied in as bytes took a BLAKE3 hash
of every record on a changed page; the fork's author measured 35 to 42
ms a frame over 250,000 to 300,000 records. It now takes a
multiply-and-fold fingerprint of the record's words (records are our
own; equal records print alike, a changed one otherwise about always,
unit-tested bit by bit).

Slots that draws read through tables lately are left to their draws, as
the passes over slots picked by index leave them: the title writes its
per-draw tables into the same heap every frame, and each draw makes
what its table shows in a slot of its own. They were most of the
records mirrored, each then made and brought up to date once more by
the pass over buffer views. VICTORY_HEAP_SYNC_TABLES=1 mirrors them
too; the sync's frame line counts them. The fork's author reports the
pass over the heap going from 70-220 ms a frame to about 3.

Ported from fxceless/victory-fork 9376fd6, these two parts only. Its
write-watch part (pull request Marvisak#670: no kernel asking for view memory
the guards hold) is ours already (watch::known_view); the in-flight
card fetches (pull request Marvisak#648, off by default) and the logging are
not taken.
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.

4 participants