Skip to content

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

Merged
ThatRecompDev merged 1 commit into
ThatRecompDev:mainfrom
Sr-0w:diagnostics/return-address-scan-executable
Nov 25, 2026
Merged

ThatRecompDev merged 1 commit into
ThatRecompDev:mainfrom
Sr-0w:diagnostics/return-address-scan-executable

Conversation

@Sr-0w

@Sr-0w Sr-0w commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

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

@ThatRecompDev

ThatRecompDev commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

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

…ble 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 <noreply@anthropic.com>
@Sr-0w
Sr-0w force-pushed the diagnostics/return-address-scan-executable branch from f5b1d81 to a122adc Compare November 25, 2026 21:15
@Sr-0w Sr-0w changed the title Diagnostics: the return-address scan reads only an image's readable code Diagnostics: the return-address scan reads call bytes only from readable code Nov 25, 2026
@Sr-0w

Sr-0w commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

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

Sr-0w commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

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.

@ThatRecompDev
ThatRecompDev merged commit 3c159a4 into ThatRecompDev:main Nov 25, 2026
1 of 2 checks passed
@ThatRecompDev

Copy link
Copy Markdown
Owner

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 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants