runtime: LEONIDA_TITLE_PATCH, checked byte patches of the title from the environment (RT-TITLE-PATCH-ENV) #2554
Closed
leonida/mandy
4ld0-vito wants to merge 0 commits from
leonida/title-patch into main
pull from: leonida/title-patch
merge into: leonida:main
leonida:main
leonida:github-pr/3295
leonida:beta
leonida:docs/changelog-3483-3500
leonida:github-pr/3294
leonida:github-pr/2975
leonida:github-pr/2815
leonida:feat/gate-driver-start
leonida:feat/skip-pipelines-release
leonida:perf/lazy-compare
leonida:perf/mwaitx-wait
leonida:test/prio-ceiling-main
leonida:fix/ab-cpu-stdout
leonida:fix/gate-old-crashes
leonida:diag/ab-cpu
leonida:test/main-0312
leonida:github-pr/3291
leonida:diag/indirect-clamp-census
leonida:feat/barrier-enhanced
leonida:perf/texture-frame-ceiling
leonida:perf/dstorage-threads
leonida:fix/console-queue-dma-tables
leonida:fix/port-descriptors-record-parts
leonida:fix/frame-waits-fence
leonida:fix/console-sampler-words
leonida:fix/graphics-userdata-spill
leonida:fix/xg-reserved-layout-rotation
leonida:fix/barrier-console-flags
leonida:fix/switches-wait-test-child
leonida:test/list-value-waits
leonida:test/lot-gxdk-0412
leonida:fix/bvh-compacted-size
leonida:docs/i18n-quickstarts
leonida:feat/native-pipeline-slots
leonida:fix/clippy-leonida-gpu
leonida:fix/list-value-producers
leonida:fix/descriptor-page-straddle
leonida:fix/xmem-low-window
leonida:fix/ffx-jitter-never-zero
leonida:fix/run-stdout-closed
leonida:github-pr/2892
leonida:github-pr/2896
leonida:feat/warm-save-every
leonida:github-pr/2980
leonida:github-pr/2994
leonida:github-pr/3005
leonida:github-pr/3010
leonida:github-pr/3136
leonida:github-pr/3303
leonida:github-pr/3220
leonida:github-pr/3143
leonida:github-pr/3330
leonida:github-pr/3226
leonida:github-pr/3187
leonida:carry/3395
leonida:github-pr/2946
leonida:github-pr/2947
leonida:github-pr/2945
leonida:github-pr/2983
leonida:github-pr/3001
leonida:github-pr/3372
leonida:github-pr/3128
leonida:github-pr/3296
leonida:github-pr/2588
leonida:github-pr/3119
leonida:github-pr/3378
leonida:fix/crash-diagnostics
leonida:feat/dlss-mip-bias
leonida:fix/retired-out-of-order
leonida:fix/dxr-postbuild-barrier
leonida:fix/amd-relay-default
leonida:fix/removed-report-wait
leonida:feat/heap-twin
leonida:feat/vram-margin
leonida:github-pr/2472
leonida:github-pr/3123
leonida:github-pr/3088
leonida:assets/annonce-v1
leonida:github-pr/2794
leonida:github-pr/3300
leonida:github-pr/3304
leonida:github-pr/3308
leonida:github-pr/3367
leonida:github-pr/3369
leonida:fix/launcher-dlss-diagnostics
leonida:github-pr/3269
leonida:github-pr/2957
leonida:github-pr/3205
leonida:fix/crash-zero-guard
leonida:github-pr/3185
leonida:github-pr/3099
leonida:github-pr/3104
leonida:github-pr/3348
leonida:github-pr/3379
leonida:github-pr/3377
leonida:perf/darner-title-priority-ceiling
leonida:github-pr/3376
leonida:gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
leonida:gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
leonida:gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
leonida:github-pr/3373
leonida:github-pr/3368
leonida:github-pr/3198
leonida:gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
leonida:gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
leonida:gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
leonida:gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
leonida:github-pr/3346
leonida:github-pr/3375
leonida:github-pr/2958
leonida:github-pr/3151
leonida:github-pr/3307
leonida:github-pr/3278
leonida:github-pr/3374
leonida:fix/runtime-test-conservative-fixtures
leonida:github-pr/3366
leonida:ci/shard-semantic-linux
leonida:github-pr/3354
leonida:docs/fg-limit-fps-switch
leonida:github-pr/3365
leonida:fix/read-file-hard-link
leonida:github-pr/3364
leonida:fix/book-slot-heap-never-read
leonida:github-pr/3361
leonida:github-pr/3263
leonida:github-pr/3360
leonida:github-pr/3353
leonida:github-pr/3331
leonida:fix/alias-later-queued-submissions
leonida:github-pr/3352
leonida:github-pr/3228
leonida:github-pr/3349
leonida:claude/gallant-sagan-aamatr
leonida:github-pr/3200
leonida:github-pr/3132
leonida:github-pr/3323
leonida:github-pr/3332
leonida:github-pr/3340
leonida:github-pr/3311
leonida:github-pr/3334
leonida:github-pr/3297
leonida:github-pr/3256
leonida:github-pr/2567
leonida:github-pr/2851
leonida:d3d12/agility-sdk-621
leonida:github-pr/3164
leonida:github-pr/3114
leonida:github-pr/3050
leonida:github-pr/3113
leonida:github-pr/3326
leonida:github-pr/3144
leonida:github-pr/2642
leonida:github-pr/3072
leonida:github-pr/2789
leonida:github-pr/2643
leonida:github-pr/3009
leonida:github-pr/3035
leonida:github-pr/3031
leonida:github-pr/2686
leonida:github-pr/2834
leonida:github-pr/3321
leonida:github-pr/3325
leonida:github-pr/3290
leonida:github-pr/3324
leonida:github-pr/3130
leonida:claude/fervent-curie-m19lnr
leonida:github-pr/3309
leonida:github-pr/3305
leonida:github-pr/3306
leonida:github-pr/3302
leonida:github-pr/3301
leonida:github-pr/3345
leonida:github-pr/3211
leonida:github-pr/3027
leonida:github-pr/3286
leonida:github-pr/3235
leonida:github-pr/3265
leonida:github-pr/3275
leonida:codex/skip-no-hit-ray-passes
leonida:github-pr/2823
leonida:github-pr/2911
leonida:github-pr/3262
leonida:github-pr/3125
leonida:github-pr/3206
leonida:github-pr/3250
leonida:github-pr/3238
leonida:github-pr/3188
leonida:github-pr/2952
leonida:github-pr/3217
leonida:github-pr/3168
leonida:t3/preserve-fsr-sdk-restart-path
leonida:t3/propagate-host-failure-hresult
leonida:github-pr/3209
leonida:t3/launcher-custom-parameters
leonida:github-pr/3207
leonida:github-pr/3183
leonida:github-pr/3160
leonida:github-pr/3201
leonida:ci/less-to-run
leonida:github-pr/2930
leonida:github-pr/2797
leonida:github-pr/2999
leonida:perf/native-compute-shader-forms
leonida:github-pr/3191
leonida:github-pr/3011
leonida:github-pr/3019
leonida:github-pr/2996
leonida:gh-readonly-queue/main/pr-2789-45dc41f95c1cd0dcc29c2c50582e0e9af8a77259
leonida:claude/blissful-franklin-ukp7ag
leonida:github-pr/3141
leonida:github-pr/3156
leonida:github-pr/3150
leonida:github-pr/3153
leonida:github-pr/3163
leonida:github-pr/3142
leonida:github-pr/3139
leonida:github-pr/2841
leonida:github-pr/3069
leonida:github-pr/3098
leonida:github-pr/3107
leonida:github-pr/3071
leonida:github-pr/2774
leonida:github-pr/2889
leonida:github-pr/3075
leonida:github-pr/2661
leonida:github-pr/3064
leonida:github-pr/3054
leonida:github-pr/3049
leonida:github-pr/2855
leonida:github-pr/2943
leonida:github-pr/3016
leonida:github-pr/2887
leonida:github-pr/3006
leonida:github-pr/3003
leonida:github-pr/2993
leonida:notes/card-time-and-plant-flicker
leonida:github-pr/2989
leonida:feat/vulkan-rs
leonida:github-pr/2985
leonida:github-pr/2951
leonida:github-pr/2982
leonida:github-pr/752
leonida:github-pr/792
leonida:github-pr/2877
leonida:github-pr/2654
leonida:github-pr/2893
leonida:github-pr/2948
leonida:github-pr/2944
leonida:github-pr/2919
leonida:github-pr/2915
leonida:archive/ci/less-to-run/20261202T1121Z
leonida:github-pr/2800
leonida:github-pr/2822
leonida:github-pr/2833
leonida:github-pr/2840
leonida:github-pr/2831
leonida:github-pr/2832
leonida:github-pr/2801
leonida:github-pr/2890
leonida:github-pr/2891
leonida:github-pr/2664
leonida:github-pr/2807
leonida:rt-call-trace
leonida:github-pr/2755
leonida:perf/ahead-split
leonida:github-pr/2587
leonida:github-pr/2698
leonida:github-pr/2609
leonida:github-pr/3219
leonida:docs/readme-runtime-proposal
leonida:github-pr/2017
leonida:github-pr/1741
leonida:github-pr/1667
leonida:codex/coord-claim-check-20261124-7e48
No reviewers
Assignees
Clear assignees
No assignees
Labels
Clear labels
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
enhancement
New feature or request
missing claim
Needs a claim in #14
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
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
Projects
Clear projects
No items
No project
Milestone
Clear milestone
No items
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Reference
leonida/mandy!2554
Loading…
Reference in a new issue
No description provided.
Delete branch "leonida/title-patch"
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?
Pull request closed
This pull request cannot be reopened because the branch was deleted.
Claimed in the coordination issue as: RT-TITLE-PATCH-ENV (https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7232261469)
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)#2554 | head 5039a8dd1740f13d992fb4421b810c963ce49ad6 (merged cleanly with main 02f71ccfe78160997a02950607be583af87e1180) |
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().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).
@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). c556144d8 checks 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).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.
Run of #2554 (
title_patch), red then green.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).
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.
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.
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.
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).
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.