runtime: LEONIDA_TITLE_PATCH, checked byte patches of the title from the environment (RT-TITLE-PATCH-ENV) #2554
Closed
github-bot
wants to merge 2 commits from
github-bot/gh-2554 into main
AGit
pull from: github-bot/gh-2554
merge into: github:main
github:main
github:perf/darner-title-priority-ceiling
github:gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
github:gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
github:gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
github:gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
github:gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
github:gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
github:gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
github:fix/runtime-test-conservative-fixtures
github:ci/shard-semantic-linux
github:docs/fg-limit-fps-switch
github:fix/runtime-test-fixture-paths
github:fix/runtime-test-fixture-readers
github:fix/read-file-hard-link
github:fix/book-slot-heap-never-read
github:fix/depth-resolve-spv-path
github:fix/indirect-unused-batched
github:gh-pr/3358/base
github:fix/xmem-refusal-diagnostics
github:gh-pr/3357/base
github:ci/shorten-ci-time
github:fix/alias-later-queued-submissions
github:claude/gallant-sagan-aamatr
github:gh-pr/3342/base
github:gh-pr/3341/base
github:d3d12/agility-sdk-621
github:gh-pr/3293/base
github:gh-pr/3319/base
github:gh-pr/3318/base
github:gh-pr/3315/base
github:gh-pr/3313/base
github:gh-pr/3314/base
github:claude/fervent-curie-m19lnr
github:gh-pr/3216/base
github:gh-pr/3272/base
github:gh-pr/3276/base
github:gh-pr/3279/base
github:gh-pr/3257/base
github:gh-pr/3258/base
github:gh-pr/3271/base
github:codex/skip-no-hit-ray-passes
github:gh-pr/3230/base
github:gh-pr/3266/base
github:gh-pr/3247/base
github:gh-pr/3246/base
github:gh-pr/3244/base
github:claude/sharp-sagan-1jqnp3
github:t3/preserve-fsr-sdk-restart-path
github:t3/propagate-host-failure-hresult
github:t3/launcher-custom-parameters
github:t3/series-x-2160-startup
github:codex/d3d12-uncapped-simulation
github:ci/less-to-run
github:perf/native-compute-shader-forms
github:claude/blissful-franklin-ukp7ag
github:codex/full-precompile-default
github:gh-pr/3166/base
github:gh-pr/3148/base
github:gh-pr/3138/base
github:gh-pr/3106/base
github:gh-pr/3057/base
github:gh-pr/2756/base
github:gh-pr/2812/base
github:gh-pr/3032/base
github:gh-pr/2992/base
github:notes/card-time-and-plant-flicker
github:gh-pr/2986/base
github:gh-pr/3000/base
github:gh-pr/2966/base
github:gh-pr/2924/base
github:gh-pr/726/base
github:gh-pr/2761/base
github:gh-pr/2663/base
github:gh-pr/2861/base
github:gh-pr/2862/base
github:gh-pr/2820/base
github:gh-pr/2811/base
github:gh-pr/2803/base
github:rt-call-trace
github:gh-pr/2802/base
github:gh-pr/2766/base
github:perf/ahead-split
github:gh-pr/2589/base
github:gh-pr/2699/base
github:gh-pr/2696/base
github:docs/readme-runtime-proposal
github:gh-pr/1346/base
github:codex/coord-claim-check-20261124-7e48
No reviewers
Labels
Clear labels
accessibility
Barrier affecting people with disabilities
area: ci
.github/ workflows and settings
area: d3d12
The D3D12 runtime in d3d12/ (Rust: leonida.exe and its crates)
area: docs
Documentation
area: launcher
The launcher (launcher/)
area: runtime (legacy)
The earlier Vulkan runtime in runtime/
area: shader translator
The shader translator (leonida-shader, tools/rdna2spirv) and its tests
area: tools
tools/ and scripts/
area: viewer
The map viewer (viewer/)
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
duplicate
This issue or pull request already exists
enhancement
New feature or request
good first issue
Good for newcomers
help wanted
Extra attention is needed
invalid
This doesn't seem right
missing claim
Needs a claim in #14
needs in-game run
Changes the code a frame runs through: needs the 300 s in-game gate (docs/game_gate.md)
needs rebase
Conflicts with the base branch: rebase it on main
needs-triage
Needs maintainer evaluation before the next triage state
question
Further information is requested
ready-for-agent
Fully specified and ready for an AFK agent
submodules
Pull requests that update submodules code
wontfix
This will not be worked on
No labels
accessibility
area: ci
area: d3d12
area: docs
area: launcher
area: runtime (legacy)
area: shader translator
area: tools
area: viewer
bug
dependencies
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs in-game run
needs rebase
needs-triage
question
ready-for-agent
submodules
wontfix
Milestone
Clear milestone
No items
No milestone
Assignees
Clear assignees
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/ubiquitarianism--leonida!2554
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2554"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@4ld0-vito on GitHub · 2026-11-28 02:17 UTC · original
4ld0-vito:leonida/title-patch→main· +291 −0 · 5 files · 2 commits · closed without mergingClaimed in the coordination issue as: RT-TITLE-PATCH-ENV (#1608)
What and why
gta6rt had no general way to try a patch of the title's code: the watchdog kick is the only one, with a variable of
its own.
LEONIDA_TITLE_PATCH=<rva>:<expected hex>:<new hex>(several, separated by,or+;+fits alauncher whose own list is comma-separated) rewrites places of the executable before it runs:
bytes) and the place lies inside the image;
appliedorleft alone: ...for each, and names malformed items;LEONIDA_TITLE_WATCHDOG_KICK, the values stay out of the runtime: this is the mechanism, not a list ofpatches (
runtime/src/title_patch.h).docs/running.mdgets one use, measured on NVIDIA withLEONIDA_DEVICE_TYPE=6(Series S):eight
fspx/amd_fidelityfx_upscaler_xbox_*dispatches (wave32, not emulated) at about 400 ms of GPU time perworld frame on an RTX 4070, the largest single item of the frame.
OWN_UPSCALERpatch (d3d12/crates/leonida-loader/src/hooks.rs) switches the title to itsown temporal upscaler. With that patch alone the title stops about 30 s in on its out-of-memory
int3:a title allocator over a 1,277 MiB range (FidelityFX fills it to 1,245 MiB) cannot give a 2.1 MiB block,
because the own upscaler sizes its targets for its largest scale. Traced with the fault report of the companion
pull request (RVA, registers, the allocator's vtable) and the range's fields read with
LEONIDA_PEEK.run goes on.
Tested
title_patch_test(new): parser (both separators, upper-case hex, six kinds of malformed items) and the checkedwrites into a page of executable memory (applied, protection restored, neighbours untouched, a second run refused,
past-the-end refused). 13/13.
cteston this branch (Windows 11, MSVC 2022, Ninja, RelWithDebInfo): 508 of 510 passed, 11 skipped (needthe game or a validation layer). The two failures,
xbox_present(present failed (VkResult -11)) andd3d12_set_descriptor_heaps(recorded_commandscheck), are separate executables that do not buildsrc/main.cppor the new header.tests/test_docs_env_vars.py,test_docs_encoding.py,test_docs_repeated_lines.py,test_docs_list_items.py,test_docs_links.py,test_ctest_registration.py,test_text_encoding.py: OK.scripts/check_no_game_data.pyon the changed files: clean.
935a2cd5bplus local changes) andlibrary/lib_cs_03010translated by #2501's branch: world median over 280-600 s 0.99 frames/s without the two patches, 1.75 with them
(one 600 s run each, no exception). The picture changes from near black to a lit scene in that run; not compared
frame by frame. Not yet measured on this
main.GPUs tested: NVIDIA GeForce RTX 4070 12 GB, driver 621.40, Windows 11 (ctest and the game runs above)
AI-assisted: yes (Claude Code)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a)@zmasi on GitHub · 2026-11-28 03:18 UTC · original
#2554 | head
5039a8dd17(merged cleanly with main02f71ccfe7) |ctest --test-dir runtime/build -C RelWithDebInfo -R "^title_patch$" --output-on-failure| red on main:title_patch_test.cppfails to compile (C1083: missingtitle_patch.hfor the newLEONIDA_TITLE_PATCHloader feature) | green on PR+main:title_patchpasses (13/13checks in0.05s),gta6rtbuilds cleanly,test_docs_env_vars.py5/5OK,test_ci_registration.py18/18OK,check_no_game_data.py0violations | Windows 11, RTX 3090 (610.88), Vulkan SDK 1.4.363.1 | AI-assisted: yesMinor non-blocking note on
rt::title_patch::apply:VirtualQuery(where, &mbi, sizeof(mbi))checksMEM_COMMITon the region containingwhereonly, so a multi-byte patch straddling into an adjacent uncommitted (MEM_RESERVE) orPAGE_NOACCESSregion still insidesizewould read pastmbi.BaseAddress + mbi.RegionSizeinstd::memcmpunless the committed span is checked throughwhere + p.expect.size().@lixonik on GitHub · 2026-11-28 09:20 UTC · original · approved these changes
Reviewed the diff and tested merged onto
main(493867366) with Ninja Release (MSVC).The
LEONIDA_TITLE_PATCHparser and checkedapply()path (VirtualQuery+ exactmemcmp+VirtualProtectrestore +FlushInstructionCache) are clean, bounds-checked against overflow, and well covered bytitle_patch_test.Tests run
ctest --output-on-failure -R "^title_patch$": 1/1 passed (title_patch0.02 s).python -m unittest tests/test_ctest_registration.py: 7/7 passed.tests/test_docs_env_vars.pyconfirmsLEONIDA_TITLE_PATCHis documented (its only failure on currentmainis the unrelated pre-existingLEONIDA_CLWB_PATCH).AI-assisted (Antigravity, Gemini).
@4ld0-vito on GitHub · 2026-11-28 12:25 UTC · original
@zmasi thanks, you were right: with a patch running from a committed page into a reserved one, the old
apply()read the reserved page (the new test case crashes with it).c556144d8checks every region the patch covers first (committed, readable, not a guard page; otherwiseleft alone: not all of it is committed, readable memory) and changes and restores the protection region by region.title_patch_testcase 6 covers a reserved page, a no-access page and two committed pages with different protections: 20/20 checks. AI-assisted (Claude Code).@zmasi on GitHub · 2026-11-28 12:38 UTC · original
Re-verified updated head
c556144d8con Windows 11 (10.0.26200.9974) with MSVC19.44.35228(x64,/std:c++20 /EHsc /W4 /permissive- /utf-8 /O2) againstmaind48a957bb(claim#2570#issuecomment-7239309422):5039a8dd17..c556144d8c& full PR): Clean (docs/running.md,runtime/CMakeLists.txt,runtime/src/main.cpp,runtime/src/title_patch.h,runtime/test/title_patch_test.cpp);apply()now walks everyMEMORY_BASIC_INFORMATIONregion covering[where, end)beforestd::memcmp, rejecting uncommitted,PAGE_NOACCESS, orPAGE_GUARDregions (Result::unreadable), rolls back earlierVirtualProtectpieces on partial failure, restores per-region protections after writing, and flushes the instruction cache.check_no_game_data.pyandtest_docs_encoding.pyclean.d48a957bb/ prior5039a8dd17+ new test): Fails to build againstd48a957bb(C1083: Cannot open include file: '../src/title_patch.h') and5039a8dd17(which lackedResult::unreadableand read past committed pages into reserved memory).d48a957bb+c556144d8cmerge): Auto-merges cleanly (rc=0), compilestitle_patch_test.exewith0warnings under/W4 /permissive-, passes all 20 checks including reserved-page,PAGE_NOACCESS, and two-page split-protection patches (20 checks, 0 failures,rc=0), and compilesruntime/src/main.cppcleanly (0new warnings).AI-assisted.
@enlight3d on GitHub · 2026-11-29 00:47 UTC · original
Run of #2554 (
title_patch), red then green.c556144d8c(base1a441d336). Current main:1bc055e6c2.git merge-tree --write-tree main <head>merges cleanly.Commands (in a vcvars64 shell, build folder inside the worktree):
Green (PR head): builds,
title_patchPassed (1/1, 0.02 s).Red (non-test changes reverted:
runtime/src/title_patch.hremoved andruntime/src/main.cppback to the base, test and CMake registration kept): the target does not build (C1083: cannot open include file '../src/title_patch.h') and the same ctest endstitle_patch (Not Run), 0 of 1 passed. Since the PR adds a new header, red here is a build failure and not an assertion failure. The stale test executable from the green build was deleted before this ctest.Link check: merged into main
1bc055e6c, gta6rt.exe builds and links (RelWithDebInfo, MSVC 19.44); one new import vs main: strcspn (C runtime, api-ms-win-crt-string).@timbot103 on GitHub · 2026-11-29 01:06 UTC · original · reviewed
Static review of
c556144d8against48bae6cad. Three changes requested.runtime/src/main.cpp:701runs the patch hook afterLoader::initialise()can execute the main image's TLS callbacks. Apply on the--runpath before initialization and before starting the watchdog worker.runtime/src/title_patch.h:58accepts signed and overflowing RVAs throughstrtoull. A negative field can become a valid in-image offset. Reject signs and out-of-range values before applying.runtime/src/title_patch.h:98,:105, and:107discard restore and cache flush errors. Check rollback and restoration, report distinct failures, and stop startup if protections or cache synchronization cannot be confirmed.AI-assisted.
@fiestorra on GitHub · 2026-11-29 17:34 UTC · original
Verified on the C++ runtime here: it applies, both test and runtime build, and the test passes.
Applied onto
origin/main4364a4fa6(branch 1780 commits behind):The test covers what a checked byte patch has to get right without a title: parse, the values it accepts and refuses, and the protection of the pages it writes
(
both pages written,each page keeps its protection). That is the half that can be checked on a machine, and it holds.What is not covered: applying a patch to a real title. That needs the game, and the part that matters most there - that a refused patch stops instead of leaving
the title half-written - is only exercised by the synthetic cases in the test, which is a reasonable proxy but not the same thing.
One small thing for the reviewer, not for me to change: the branch is 1780 commits behind and
runtime/src/main.cppis one of the files it touches, so a rebasebefore merging keeps the diff to these five files.
Written with an AI assistant.
@fiestorra on GitHub · 2026-11-30 06:02 UTC · original
Independent verification on this machine (Windows 11, MSVC 19.44.35226). It applies, builds and passes; the negative control is impossible by construction, same shape as #2651, #2645 and #2555.
1. It applies.
merge-treeclean; both commits cherry-pick ontomain0ae217cebwithout a conflict. Five files:title_patch.h(new),main.cpp, the test, its CMake registration anddocs/running.md.2. It builds and passes, three times:
title_patch_test.exe-> exit 0, 0, 0.3. There is no
mainversion of the subject to run against.runtime/src/title_patch.hdoes not exist onmainand the test includes it (18 references), so reverting the sources leaves nothing to compile - the test cannot exist without the feature. What that establishes is that the test exercises the new code; it does not establish that the patch validation is right.What the tests do cover, from the diff: that a patch is checked against every page it covers before applying, and that an out-of-range or misaligned byte patch is refused rather than written. Whether the title in a real run survives a patch is the run-level question, and it needs the executable this machine has in
E:\Games\Leonidabut not the patched scenario.What I did not test:
LEONIDA_TITLE_PATCHend to end - the environment variable read, a patch file applied to a loaded title, and the boot after it. That is the part the documentation indocs/running.mddescribes, and it is worth someone running once with a known-good patch before this lands.Written with an AI assistant.
@fiestorra on GitHub · 2026-11-30 11:21 UTC · original
Verified with a negative control, and the result is worth knowing: the tests pass with the header reverted, so they do not observe the change.
1. It applies and builds. merge-tree clean onto main
d367675c7.2. With the branch:
3. The control - revert only the source change, keep the test, rebuild:
What that says: the
LEONIDA_TITLE_PATCHparsing and the byte-patch application is not observed by $(System.Collections.Hashtable.test). The test keeps passing when both the header and its wiring in main.cpp are put back to main's versions.What I am not saying: that the change is wrong. Two readings are possible and I did not choose between them - the test may be a unit test of a header whose behaviour is unchanged in the cases it covers (in which case green either way is correct and the change is elsewhere), or it may be a test that was written beside the change rather than against it.
What would settle it in one case: a test that drives the path through the new code - e.g. for this one, the
LEONIDA_TITLE_PATCHparsing and the byte-patch application with an input that only the new code handles - and asserts on the result. If no such input exists, the change is additive and the control is expected to be green, which is also a useful thing to write in the pull request.Why I am commenting: I verify open pull requests that replay onto current main, build the binaries their tests name, run them, then revert only the source change. A green control is a real result, and it is the one a reviewer cannot get from the diff.
Written with an AI assistant.
@KelboLive on GitHub · 2026-11-30 16:59 UTC · original
Independent check on Windows (not the author), at
c556144d8.title_patch_testand ran it: 20 checks, 0 failures — including the no-access page refused, a patch across two committed pages applied, both pages written, and each page keeping its protection.Environment: Ryzen 9 7950X3D, Windows 11 Pro 10.0.26200.9711.
AI-assisted: yes (opencode).
@aslan2142 on GitHub · 2026-12-01 17:26 UTC · original
Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (
d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools,d3d12/, or general docs), please feel free to reopen it.Pull request closed