Repository navigation
cpu_emulation: replace per-#UD VirtualQuery with MSVC SEH helpers - #1499
Open
huangzhuoyue wants to merge 1 commit into
Open
huangzhuoyue wants to merge 1 commit into
huangzhuoyue wants to merge 1 commit into
Conversation
Contributor
|
[KEEP]
|
clquwu
added a commit
to clquwu/leonida-ultimate
that referenced
this pull request
Nov 25, 2026
…h commit (#1707), MSVC SEH helpers (#1499) Wave 9A (GPL-3.0 direct adaptations from ubiquitarianism/leonida): - ProjectLeonida/mandy#742 (madhyn): coalesce contiguous physical-page runs into single MapViewOfFile3 views in XMemMapPhysicalPages and copy_page_mappings, splitting multi-page views on partial unmap/remap, coalescing split placeholders on remap, and avoiding O(N^2) splits during TitleVirtualFree window teardown. Preserves GPU-only <-> CPU-view pair mirroring, PageTrack write tracking, and pre/post unmap remap_epoch bumps. - ProjectLeonida/mandy#1707 (Tortoche): 64-page-aligned (4 MiB) fault-ahead batch commit in commit_mapped_page with view-end clamping, single-page VirtualAlloc fallback, PageTrack committed/change propagation across every newly committed page in the batch, and PAGE_READONLY/PAGE_GUARD preservation (keeping tiny 1..3-page views demand-committed per page so sparse shadow/stamp tests do not over-commit neighbors). - ProjectLeonida/mandy#1499 (huangzhuoyue): replace per-#UD VirtualQuery kernel transitions in rt::cpu_emulation::handler and apply(Op::clzero) with MSVC SEH helpers (read_code_seh / zero_line_seh) while retaining writable()/readable() for try_clzero_loop and non-MSVC/clang-cl builds. - Tests: added test_coalesced_run_partial_unmap, test_fault_batch_commit, and test_page_edge_faults. Verified xmem (500 checks), cpu_emulation, d3d12_xmem_placed, and d3d12_xmem_shadow (4/4 CTest passed) + gta6rt build + check_no_game_data.py.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Claimed in the coordination issue as: #14 (comment)
What and why
Replaces per-
#UDVirtualQuerykernel transitions in thert::cpu_emulationexception handler and single-lineCLZEROemulation with structured MSVC SEH helpers when built with MSVC (keeping clang-cl and non-MSVC builds on the existingwritable()/readable()path):read_code_seh()+__declspec(noinline)read_u8_volatile()under#if defined(_MSC_VER) && !defined(__clang__)to fetch up to 15 instruction bytes fromc->Ripand stop cleanly at unreadable/unmapped page boundaries without callingVirtualQueryper instruction fault.zero_line_seh()+__declspec(noinline)zero_64_volatile()+capture_exception_record()soapply(Op::clzero)writes the aligned 64-byte line directly under__try/__except, preservingSTATUS_ACCESS_VIOLATION/STATUS_GUARD_PAGE_VIOLATIONreporting while letting XMem's VEH handle first-touch physical backing without a redundantVirtualQuery.writable()andreadable()defined unconditionally fortry_clzero_loop()and non-MSVC/clang-cl builds, avoiding conflicts with open PRs#826and#1472.runtime/test/cpu_emulation_test.cpp(test_page_edge_faults()) exercisingapply(Op::clzero)on read-only andPAGE_GUARDpages as well as instruction fetches ending right at an unmapped page boundary (MEM_RESERVE).Tested
cpu_emulation_testandgta6rt(RelWithDebInfo, MSVC 19.44.35216.0 / Ninja / Windows SDK 10.0.26100) cleanly onfeat/cpu-emulation-msvc-seh(rebased cleanly ontoorigin/main3ff2a2adcasafdbcbf33):ctest --test-dir ... -C RelWithDebInfo --output-on-failure -R "^cpu_emulation$"->1/1 passed(0.10 s; Intel hostSSE4a 0, MONITORX 0, CLZERO 0, CLWB 1, all checks passed)..tlssize ongta6rt.exe:1681bytes (<= 16384),0newthread_local,python -I scripts/check_no_game_data.pypassed (exit 0).#984integration runtime build (100b2952e+034391e10):cpu_emulationCTest passed and181 soffline retail boot (run18,LEONIDA_DEVICE_TYPE=6,LEONIDA_ARENA_MB=2048) ran cleanly togame=3 session=3withPresentX ok 1642, failed 0,28/28non-black captures,faults: none, and0guest exceptions.GPUs tested: NVIDIA GeForce RTX 4060 Laptop GPU, driver 616.92, Windows 11 (Intel Core i7-14650HX, non-SSE4a/CLZERO host exercising emulated paths)
AI-assisted: yes
Checklist
mainand merges cleanly (git merge-tree --write-tree origin/main HEADexits 0).docs/design.md, with how it was confirmed. (n/a — runtime-only change)