startup: skip unmapped ranges in guarded title-memory reads (VirtualQuery before __try) #2845

Closed
opened 2026-11-27 01:26:21 +00:00 by github-bot · 1 comment
Owner

@⁠tedin7 on GitHub · 2026-11-26 13:20 UTC · original

Part of #870

Problem

The startup runtime reads title memory through probe_readable(), readable() and the guarded copy helpers (guarded_copy, copy_title_bytes). When a source range is not mapped at all (free address space), the read raises an access violation that the __try guard catches. The copy result is correct, but each such fault is a first-chance exception. A debugger attached to the runtime stops on every one, and each costs a kernel round trip. Reads of stale or never-mapped pointers are common, so these faults add up.

Wanted

  • Ask VirtualQuery first and refuse a range that is MEM_FREE, without touching it. Reserved-but-uncommitted pages stay accessible, because the lazy-commit memory relies on first-touch faults.
  • Keep the __try copy as the last guard for ranges that change after the query.
  • Count refused reads (faults_avoided) and show the count in the render totals log line.

Test

startup_local_log releases its own address range, verifies it is free before and after, and requires zero first-chance exceptions on the checking thread, four counted refusals per round, and one control fault when the range is touched directly.

Source: Microsoft documentation, VirtualQuery and Structured Exception Handling.

**@⁠tedin7** on GitHub · 2026-11-26 13:20 UTC · [original](https://github.com/R0Y00/Xbox2Windows/issues/2845) Part of #870 ## Problem The startup runtime reads title memory through `probe_readable()`, `readable()` and the guarded copy helpers (`guarded_copy`, `copy_title_bytes`). When a source range is not mapped at all (free address space), the read raises an access violation that the `__try` guard catches. The copy result is correct, but each such fault is a first-chance exception. A debugger attached to the runtime stops on every one, and each costs a kernel round trip. Reads of stale or never-mapped pointers are common, so these faults add up. ## Wanted - Ask `VirtualQuery` first and refuse a range that is `MEM_FREE`, without touching it. Reserved-but-uncommitted pages stay accessible, because the lazy-commit memory relies on first-touch faults. - Keep the `__try` copy as the last guard for ranges that change after the query. - Count refused reads (`faults_avoided`) and show the count in the render totals log line. ## Test `startup_local_log` releases its own address range, verifies it is free before and after, and requires zero first-chance exceptions on the checking thread, four counted refusals per round, and one control fault when the range is touched directly. Source: Microsoft documentation, VirtualQuery and Structured Exception Handling.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 01:26:21 +00:00
Author
Owner

@⁠tedin7 on GitHub · 2026-11-26 13:20 UTC · original

Claiming this; a Draft PR follows shortly.

**@⁠tedin7** on GitHub · 2026-11-26 13:20 UTC · [original](https://github.com/R0Y00/Xbox2Windows/issues/2845#issuecomment-7193222443) Claiming this; a Draft PR follows shortly.
This discussion has been locked. Commenting is limited to contributors.
No milestone
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/R0Y00--Xbox2Windows#2845
No description provided.