mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-27 00:50:52 +01:00
[PR #1499] cpu_emulation: replace per-#UD VirtualQuery with MSVC SEH helpers #1528
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#1528
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/1499
Author: @huangzhuoyue
Created: 11/25/2026
Status: 🔄 Open
Base:
main← Head:feat/cpu-emulation-msvc-seh📝 Commits (1)
afdbcbfcpu_emulation: replace per-#UD VirtualQuery with MSVC SEH helpers📊 Changes
2 files changed (+116 additions, -0 deletions)
View changed files
📝
runtime/src/cpu_emulation.h(+50 -0)📝
runtime/test/cpu_emulation_test.cpp(+66 -0)📄 Description
Claimed in the coordination issue as: https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7150481062
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)🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.