Skip to content

xgameruntime: measure XPersistentLocalStorageImpl in the retail executable - #8441

Open
autogenes-sudo wants to merge 2 commits into
ProjectLeonida:mainfrom
autogenes-sudo:measure-pls-exe
Open

autogenes-sudo wants to merge 2 commits into
ProjectLeonida:mainfrom
autogenes-sudo:measure-pls-exe

Conversation

@autogenes-sudo

@autogenes-sudo autogenes-sudo commented Nov 23, 2026 •

Copy link
Copy Markdown

Claimed in the coordination issue: #8186 (comment)

Depends on: #7987 (conflicts in runtime/test/xgameruntime_test.cpp only; both add checks to the PLS block. Complementary: #7987 changes the short-buffer answer of XPersistentLocalStorageGetPath, this PR records that the executable passes a fixed 256-byte buffer to it.)

What and why

docs/runtime_imports.md marked XPersistentLocalStorageImpl as "none called (the table of ids only)" and unmeasured in a caller because only the bundled DLLs had been checked. Static measurement of the retail executable (game_scarlett_master.exe, 120,181,760 bytes) reveals how it actually uses the class:

  1. Interface and linked slots: The executable requests IXPersistentLocalStorageImpl3 (41a4e10c-5a7e-41d9-8c37-37bde62a07d6) and links thunks for exactly two slots:

    • Slot 4: XPersistentLocalStorageGetPath (2 call sites in .text, both referenced)
    • Slot 5: XPersistentLocalStorageGetSpaceInfo (1 call site in .text, referenced)
      Slots 3 (GetPathSize), 6-7 (PromptUserForSpace*), and 8 (MountForPackage) have no thunks linked (0 thunks in the image).
  2. Call shapes and layouts:

    • XPersistentLocalStorageGetPath is invoked from two sites: both pass a fixed buffer size of 256 bytes (0x100) to static buffers in .bss / .data guarded by 1-byte initialization flags. One passes path_used = nullptr while the other provides a local stack pointer for path_used.
    • XPersistentLocalStorageGetSpaceInfo is called from the save subsystem with a pointer to stack storage, checks for success, and directly compares available_free_bytes (the 64-bit field at offset +0x00 of XPersistentLocalStorageSpaceInfo) against the save payload size.

Changes

  • docs/runtime_imports.md: update the XPersistentLocalStorageImpl row to record the 2 linked and referenced slots (4 and 5) in the retail executable, their call shapes, and the unlinked slots.
  • runtime/shims/xgameruntime.cpp: update the preamble comment to reflect that PLS is measured from the executable; add static_assert confirming offsetof(PersistentSpaceInfo, available_free_bytes) == 0x00; add a slot summary above kPersistentStorageVtable.
  • runtime/test/xgameruntime_test.cpp: add a test verifying that XPersistentLocalStorageGetPath accepts path_used = nullptr (the calling shape of the executable's static caller).

Tested

  • Windows 11 + NVIDIA RTX 5060 (driver 621.14), MSVC 19.44.35230, RelWithDebInfo:
    • built C:\leonida-work\agy-wt\runtime\build\gta6rt.exe
    • runtime\build\xgameruntime_test.exe: PASS all 144 checks (including the new path_used = nullptr check)
  • python -I scripts/check_no_game_data.py: clean (0 violations)
  • python -m compileall -q make_game.py tools tests: OK
  • python -I tests/test_docs_table_rows.py, python -I tests/test_docs_table_ids.py, python -I tests/test_exe_checklist.py: OK

No game data: counts, aggregates, public SDK names, struct offsets and call shapes only. Read-only static analysis; the executable was never run.

AI-assisted (agy)

@RAINighty

Copy link
Copy Markdown

Tested 5770027a4 merged with main 867d922f0 (clean merge) on Windows 11 (10.0.26300), Intel Core i7-14650HX, MSVC 19.44.35228, RelWithDebInfo (Ninja), CPU-only tests: pass.

  • xgameruntime, xgameruntime_gamesave, xgameruntime_store, xgameruntime_user, xgameruntime_offline and the three _gamertag/_hdr variants all pass (8 of 8).
  • Control: with main's runtime/shims/xgameruntime.cpp the same 8 also pass, so this PR's test additions do not fail without its xgameruntime.cpp change; I did not look into which checks the change affects. The PR description says it depends on xgameruntime: XPersistentLocalStorageGetPath reports the required size on a short buffer #7987 for the xgameruntime_test.cpp overlap; I tested it on main alone.
  • Code not reviewed beyond running it. No GPU or game files.

AI-assisted (Claude Code).

@Pierrot1398

Copy link
Copy Markdown

Tested 5770027 on NVIDIA GeForce RTX 5060 Ti, driver 621.24, Windows 11 Pro build 26300, VS 18 Build Tools (MSVC), Ninja, RelWithDebInfo: pass.

  • xgameruntime: passed 3/3 with ctest --repeat until-fail:3, including slot 4 with path_used = nullptr.
  • Only the synthetic test was run; the measurements of the retail executable in the docs were not checked.

Built the PR head, not merged onto main. Synthetic only, no game files. AI-assisted (Claude Code).

@sayak-brm sayak-brm left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Tested at PR head 5770027a4 merged onto main 867d922f0 (clean merge): runtime build (Visual Studio 2022 Build Tools, RelWithDebInfo) and ctest -R xgameruntime: 8 of 8 pass, including xgameruntime_test, which now has the path_used == nullptr call on slot 4, and the static_assert compiles. Windows 11, RTX 3090, no game files. I did not run the test without the PR's shim change, and I did not check the measured facts in docs/runtime_imports.md against the executable.

I read the three changed files. The path_used == nullptr check matches the shim, which guards both writes to path_used (lines 517 and 523). The docs row only holds facts about the retail executable (slot numbers, sizes, one field offset), with no game bytes. I found no problems in the code. Small points:

  • runtime/shims/xgameruntime.cpp: offsetof is used without #include <cstddef>. It compiles here, so it comes in indirectly; an explicit include would be safer.
  • The comment block near line 60 has a break in the middle of the sentence "...the other xgameruntime_*.cpp files through their / query functions" after the rewrap.
  • AGENTS.md asks for the item ID in the pull request. The description links the coordination comment but does not state the ID.
  • This depends on #7987 (still open), which changes the same test block. Land it first or rebase after it.

Review prepared with Claude Code.

@BatSmacker84

Copy link
Copy Markdown

Checked 5770027a4 (merges cleanly onto main 5d74c2723) against the retail executable on Windows 11 26200. Static reads and CPU tests only.

Pass

  • IXPersistentLocalStorageImpl3, with referenced thunks only for slots 4 and 5; one direct GetSpaceInfo call, and one direct GetPath call passing 256.
  • Table rows/IDs and the executable checklist 18/18.

Needs changes

  • The reference scan finds one GetPath reference, so the second site couldn't be confirmed, nor the buffer locations, the path_used variants or the save-size comparison. Suggested: "One direct GetPath call passing 256 bytes was confirmed. A second site needs separate attribution."

AI-assisted: Codex GPT-6.2 Sol ran the checks, Claude Opus 5.5 reviewed the report. The retail executable (SHA-256 e95020b2…8993) and package PE images were read in place; static reads and CPU tests only, and only names, counts and constants the PR uses are given.

…XPersistentLocalStorageImpl

A second check on ProjectLeonida#8441 confirmed one direct GetPath call passing 256 bytes but could not attribute a second call site.
Recounted: the GetPath thunk has one direct call and one jmp rel32 tail call; GetSpaceInfo has one direct call. The
docs row and the slot comment now say exactly that. Dropped what was not confirmed: the static buffers, the path_used
variants, the save-size comparison, the static_assert labelled as a measured offset and the path_used = nullptr test
that leaned on an unconfirmed calling shape.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

5 participants