loader: enable Windows red zone protection by default (GTA V car-entry crash, #829) #1421
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!1421
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1421/head"
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?
@overlordxrz-source on GitHub · 2026-10-11 15:21 UTC · original
overlordxrz-source:fix/windows-redzone-default→main· +9 −6 · 4 files · 1 commits · closed without mergingPorts TheCruZ's 840a5442 from TheCruZ/KytyPS5-GTA (with his permission on #1241, 2026-10-10). Authorship kept.
Bug: GTA V (PPSA04264/04263) on Windows crashes in the "[RAGE] HDD Streamer" thread, e.g. when getting into a car (#829). The game keeps temporaries below its stack pointer, and Windows overwrites that area while handling the emulator's memory-tracking faults, so the thread later reads 0xffffffffffffffff.
--redzonealready fixes it, but it is off by default. TheCruZ on #829 (2026-10-02):--redzoneis needed "to prevent a crash when you get into the car".Change: red zone protection is on by default on Windows.
--no-redzoneturns it off. Linux and macOS are unchanged.Same flag is reported as required for: Stray (#595, #1368), Sifu (#575, #739), Borderlands 3 (#1002), Viewfinder (#1064). On #1096: "Should be most of the time ON for Unreal Engine games."
Trade-off: guest instruction patching and an 8 MiB trampoline are now active by default on Windows. Existing saved launcher configs keep their stored value.
Fixes the car-entry crash in #829.
AI-assisted: yes (port and description; code is TheCruZ's commit unchanged).
@coderabbitai[bot] on GitHub · 2026-10-11 15:23 UTC · original
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
7aba0a5c-169a-478b-b8ad-8d4197f9ce35📥 Commits
Reviewing files that changed from the base of the PR and between
16a7fe689aand8c984301cd.📒 Files selected for processing (4)
src/common/emulatorConfig.hsrc/launcher/include/configuration.hsrc/launcher/src/mainDialog.cppsrc/main.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
📝 Walkthrough
Walkthrough
On Windows, red-zone protection now defaults to enabled in the emulator and launcher configurations. The launcher emits
--redzonewhen protection is enabled and--no-redzonewhen it is disabled. Command-line help documents both options, and parsing--no-redzonedisables protection.Suggested reviewers:
nmzikPriority: ⬆️ High
Change: Bug fix
Merge Risk: ⚪ Minimal · up to
8c984Windows red-zone protection defaults to enabled, and the launcher’s enable and disable options match the CLI behavior.
Pre-merge checks |
4 |
1
❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
#829.Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share
Comment
@coderabbitai helpto get the list of available commands.@theantipopau on GitHub · 2026-10-12 11:03 UTC · original · approved these changes
Verified the single PR commit
8c984301(cherry-picked from TheCruZ's 840a5442) against current main:ConfigOptions.red_zone_protection_enabled(emulatorConfig.h) and the launcher'sConfigurationdefault flip totrue, soConfig::RedZoneProtectionEnabled()(read byruntimeLinker.cpp:1675on the guest-instruction-patch path) now defaults on, matchingpatch_guest_instructions = protect_memory_faults || emulate_amd.--no-redzoneinverse-flag is symmetric with--redzone, usage text updated, andCreateEmulatorArgsnow always passes one of the two flags explicitly instead of only-on — that fixes the latent launcher bug where a storedfalseconfig silently booted with protection on after this change.configuration.cppreadsred_zone_protection_enabledwith the (new) default only as fallback for older keys.CI green on Windows/Linux/macOS (5/5). Fixes #829.
@Nawid3333 on GitHub · 2026-10-18 21:58 UTC · original
Another game that looks like it needs this: Demon's Souls (PPSA01341) on Windows, RX 6700 XT and Ryzen 7 5700X (#821), on a build of
099de8dwith #1152 and #1630 (f3996a4).BPE JobWorkerThread CPU4:mov rax, [rsp-0x10]followed bymov [rax+0x18], ebpwith rax = 0, so the function reloaded a pointer from 16 bytes below rsp and got 0 (log).Written with Claude Code (AI): it read the crash log and found this PR; I read this before posting.
@Nawid3333 on GitHub · 2026-10-19 15:43 UTC · original · edited 2026-10-19 16:13 UTC
Follow-up to my Demon's Souls comment above: I measured what Windows writes below rsp on a handled access violation, and what the protection costs.
1. What Windows writes below rsp (standalone probe; the vectored handler reads where Windows put each XSAVE feature with
LocateXStateFeature; Ryzen 5 7600X = Zen 4, Windows 11 26200; one run, the offsets shift by up to 0x30 with rsp alignment)A feature's bytes are written only when it is in the context mask. So the 128-byte red zone is overwritten when the highest feature in the frame is in use at the fault. On this Zen 4 that is zmm16-31 (nearest overwritten slot rsp-0x20 to rsp-0x40 across runs), which guest code built for Zen 2 never uses; AVX alone stops at about rsp-0x650. Prediction, not yet measured: on a CPU without AVX-512, AVX is the top feature, so any fault with live ymm upper halves overwrites the red zone.
vzeroupperclears that state; a VEX.128 instruction after AVX code does not (the context mask still has AVX).2. CPUs named in these reports (#1421's list, plus Demon's Souls)
mov [rax+0x18], ebpwith rax = 0 as #821; not yet tried with the option)All of these are CPUs without AVX-512, which fits the prediction. That alone would not make a CPU-based default safe: host code that leaves zmm16-31 live on a guest thread would expose AVX-512 hosts too, and I have not checked for that.
Edit: an earlier version of this comment listed #1512's reporter (Ryzen 9 9950X3D) here. That log ends in a failed Vulkan call (
result != vk::Result::eSuccess,masterSemaphore.cpp:53) with red-zone protection already on, so it is a different crash; the row now lists the two #1512 commenters whose crash matches.3. Cost (lab harness that loads SysV x86-64 ELF code - Ubuntu's libLLVM, and zstd built with clang -O2 -march=znver2 - and runs Kyty's
PatchGuestInstructionsas--redzonedoes; same 7600X, Release build)Results were identical in every row. The load cost is the one-time decode of all guest code (
--amd-cpucosts about the same, 3.64 s); EmK530 measured 7.46 s -> 8.74 s for Tetris Effect's eboot in #1510. The run-time cost depends on whether hot loops keep data in the red zone: 0% for zstd's decompression, +54% for compression plus decompression, because each relocated access becomes jmp ->lea rsp,[rsp-128]-> access ->lea rsp,[rsp+128]-> jmp. What a game pays is unknown.4. Could a tester run an FPS A/B with and without the option in a scene that does not crash? That would show the real run-time cost before the default is chosen.
Written with Claude Code (AI): it wrote the probe and the benchmark harness and ran them; I checked the numbers before posting.
@Nawid3333 on GitHub · 2026-10-19 19:48 UTC · original
Update to my measurement above: the prediction is now measured on a CPU without AVX-512. volan3 ran the same probe on his Ryzen 7 5700X (Zen 3, XCR0 0x7) with Windows 10 build 19045 (output):
vpcmpeqd ymm0)vzeroupperFrame layout in that run: CONTEXT at rsp-0x728, AVX (feature 2) at rsp-0x128 .. rsp-0x28, i.e. AVX is the top feature there. So on CPUs without AVX-512 every fault inside 256-bit AVX code overwrites the guest red zone, on Windows 10 as well as 11. That matches the Demon's Souls fog crash on that machine (#821: a pointer reloaded from [rsp-0x10] came back 0, fixed by the protection). Difference to my Zen 4 run: after a VEX.128 instruction his Windows did not save AVX (mask 0x3), mine did (0x7).
Written with Claude Code (AI): it wrote the probe and compared the runs; I checked the numbers before posting.
@Nmzik on GitHub · 2026-10-21 19:00 UTC · original
Same it doesnt make sense to auto turn on (it is not 100% reliable)
Pull request closed