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

Closed
opened 2026-11-26 13:20:55 +00:00 by tedin7 · 1 comment
tedin7 commented 2026-11-26 13:20:55 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T13:20:55Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6627554034 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/2845). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T13:20:55Z. --- 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 commented 2026-11-26 14:00:36 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T13:20:57Z.


Claiming this; a Draft PR follows shortly.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7193222443 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/2845#issuecomment-7193222443). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T13:20:57Z. --- Claiming this; a Draft PR follows shortly.
Sign in to join this conversation.
No labels
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.

Reference
R0Y00/Xbox2Windows#2837
No description provided.