Diagnostics: the return-address scan reads call bytes only from readable code #48

Manually merged
github merged 1 commit from gh-pr/48/head into gh-pr/48/base 2026-11-27 03:15:19 +00:00
Owner

@⁠Sr-0w on GitHub · 2026-11-25 17:36 UTC · original
Sr-0w:diagnostics/return-address-scan-executable → main · +29 −12 · 5 files · 1 commits · merged 2026-11-25 22:11 UTC

Rebased on main's fix (98d9727) and reduced to the protection mask, as asked:

  • CallBytesReadable requires the call bytes' page to be committed readable code: PAGE_EXECUTE_READ, PAGE_EXECUTE_READWRITE or PAGE_EXECUTE_WRITECOPY. PAGE_EXECUTE alone is refused, since execute-only sections fault on read.
  • No cache: the page is queried on every scan, as on main.
  • GameHangWatch.IsReadable takes an optional mask of accepted protections. Win32Constants gains PageExecuteWriteCopy (0x80).
  • The test now covers each case: execute-read and execute-readwrite are read; execute-only and read-write are not.

Tests: WaitObjectsTests 12/12. docs/debugging.md updated.

🤖 Generated with Claude Code

**@⁠Sr-0w** on GitHub · 2026-11-25 17:36 UTC · [original](https://github.com/ThatRecompDev/five-star-recomp/pull/48) `Sr-0w:diagnostics/return-address-scan-executable` → `main` · +29 −12 · 5 files · 1 commits · merged 2026-11-25 22:11 UTC Rebased on main's fix (98d9727) and reduced to the protection mask, as asked: - `CallBytesReadable` requires the call bytes' page to be committed **readable code**: `PAGE_EXECUTE_READ`, `PAGE_EXECUTE_READWRITE` or `PAGE_EXECUTE_WRITECOPY`. `PAGE_EXECUTE` alone is refused, since execute-only sections fault on read. - No cache: the page is queried on every scan, as on main. - `GameHangWatch.IsReadable` takes an optional mask of accepted protections. `Win32Constants` gains `PageExecuteWriteCopy` (0x80). - The test now covers each case: execute-read and execute-readwrite are read; execute-only and read-write are not. Tests: `WaitObjectsTests` 12/12. `docs/debugging.md` updated. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A page inside an image's range can be execute-only (the loader maps sections that way), and reading its call
bytes faults like an uncommitted page. CallBytesReadable now also requires PAGE_EXECUTE_READ, _READWRITE or
_WRITECOPY (GameHangWatch.IsReadable takes the accepted protections); the page is queried on every scan, no cache.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 03:15:18 +00:00
github manually merged commit a122adcf7f into gh-pr/48/base 2026-11-27 03:15:19 +00:00
Author
Owner

@⁠ThatRecompDev on GitHub · 2026-11-25 19:08 UTC · original · edited 2026-11-25 19:09 UTC

hey, thanks for this!

main picked up a fix for the same crash last night (98d9727). it queries the page of the 6 call bytes on every scan, so this conflicts in ReturnAddresses now.

i'd rather not cache the ranges per image though. pages inside an image can get decommitted later, and then the cache says readable when it isn't, which is the exact fault we're dodging.

the part of yours i really like is requiring a readable execute protection. main's IsReadable lets PAGE_EXECUTE through, and we do map execute-only sections that way.

could you rebase and turn this into just that mask inside CallBytesReadable (no cache)? maybe also reuse Win32Constants for commit/guard and add a named const for 0x80. happy to merge that

**@⁠ThatRecompDev** on GitHub · 2026-11-25 19:08 UTC · [original](https://github.com/ThatRecompDev/five-star-recomp/pull/48#issuecomment-7171871717) · edited 2026-11-25 19:09 UTC hey, thanks for this! main picked up a fix for the same crash last night (98d9727). it queries the page of the 6 call bytes on every scan, so this conflicts in ReturnAddresses now. i'd rather not cache the ranges per image though. pages inside an image can get decommitted later, and then the cache says readable when it isn't, which is the exact fault we're dodging. the part of yours i really like is requiring a readable execute protection. main's IsReadable lets PAGE_EXECUTE through, and we do map execute-only sections that way. could you rebase and turn this into just that mask inside CallBytesReadable (no cache)? maybe also reuse Win32Constants for commit/guard and add a named const for 0x80. happy to merge that
Author
Owner

@⁠Sr-0w on GitHub · 2026-11-25 21:15 UTC · original

Done: rebased on 98d9727 and reduced to the readable-code mask inside CallBytesReadable, with no cache. It reuses Win32Constants (commit, guard, and a new PageExecuteWriteCopy = 0x80). The test now covers execute-only and read-write pages, which are refused.

**@⁠Sr-0w** on GitHub · 2026-11-25 21:15 UTC · [original](https://github.com/ThatRecompDev/five-star-recomp/pull/48#issuecomment-7174824252) Done: rebased on 98d9727 and reduced to the readable-code mask inside `CallBytesReadable`, with no cache. It reuses Win32Constants (commit, guard, and a new `PageExecuteWriteCopy` = 0x80). The test now covers execute-only and read-write pages, which are refused.
Author
Owner

@⁠Sr-0w on GitHub · 2026-11-25 21:58 UTC · original

In game: without this fix, a run crashed the .NET host with an AccessViolation in the return-address scan, which read an unmapped page of an image. With it, the next run went on to about 375 s, where the hang watch could name the stalled job (fixed by #49). Since then, runs reach the opening cinematic and last the full 600 s.

**@⁠Sr-0w** on GitHub · 2026-11-25 21:58 UTC · [original](https://github.com/ThatRecompDev/five-star-recomp/pull/48#issuecomment-7175766384) **In game:** without this fix, a run crashed the .NET host with an AccessViolation in the return-address scan, which read an unmapped page of an image. With it, the next run went on to about 375 s, where the hang watch could name the stalled job (fixed by #49). Since then, runs reach the opening cinematic and last the full 600 s.
Author
Owner

@⁠ThatRecompDev on GitHub · 2026-11-25 22:11 UTC · original

thanks for turning this around so fast!

rebased onto 98d9727 and keeping the readable-execute mask inside CallBytesReadable is exactly what i was after, the rest of IsReadable stays the same.

nice touch naming 0x80 in Win32Constants and making the test a theory over the page protections, that covers the execute-only case nicely.

merged 👍

**@⁠ThatRecompDev** on GitHub · 2026-11-25 22:11 UTC · [original](https://github.com/ThatRecompDev/five-star-recomp/pull/48#issuecomment-7176054781) thanks for turning this around so fast! rebased onto 98d9727 and keeping the readable-execute mask inside CallBytesReadable is exactly what i was after, the rest of IsReadable stays the same. nice touch naming 0x80 in Win32Constants and making the test a theory over the page protections, that covers the execute-only case nicely. merged 👍
github-bot referenced this pull request from a commit 2026-11-28 08:54:00 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.