Skip to content

Diagnostics: the return-address scan tests an image's code sections before VirtualQuery - #51

Merged
ThatRecompDev merged 1 commit into
ThatRecompDev:mainfrom
Sr-0w:diagnostics/wait-history-cheap
Nov 25, 2026
Merged

ThatRecompDev merged 1 commit into
ThatRecompDev:mainfrom
Sr-0w:diagnostics/wait-history-cheap

Conversation

@Sr-0w

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

Copy link
Copy Markdown
Contributor

What

ReturnAddresses.Scan, used by the --watch-hang wait-object history (#47) on every wait of the game, now drops a stack value unless its six call bytes lie in an executable section of the image. The test uses the section headers (LoadedImage.InCode) and runs before the VirtualQuery readable-code check. Pointers into an image's data are rejected without a system call. Return addresses still get the same checks as before.

Why

The scan walks up to 64 KB of stack and called VirtualQuery for each value inside an image's range. Game stacks hold many pointers into the image's data sections.

In a managed profile (--profile-managed, 30 s during a world load), WaitObjects.Waiting → ReturnAddresses.Scan → GameHangWatch.IsReadable was 66% of the shims' samples on the game's threads.

In game

All runs below are on an RX 7800 XT and were recorded:

  • With --watch-hang --sample-threads 10: the short animation right after the "press A" title screen stutters, with frame drops and visible tearing in every recorded run.
  • The same build without those two options: no stutter on that animation.

This change removes the scan's system calls on the wait path. The periodic stack captures of --sample-threads (ThreadSnapshot, "stack capture stuck" about every 10 s) are a separate cost and are not touched here.

Tests

  • New Only_a_value_after_six_bytes_of_an_executable_section_is_checked_as_code test, built on a two-section image.
  • Loader tests: 398 passed.

🤖 Generated with Claude Code

…efore VirtualQuery

With --watch-hang, every wait of the game records its caller frames. The scan behind that walks 64 KB of stack and
called VirtualQuery for each value inside an image's range, and stacks hold many pointers into an image's data. In a
managed profile of a world load, that was 66% of the shims' time on the game's threads, and the animation after the
title screen stuttered with --watch-hang and not without it. A value now needs its six call bytes inside an
executable section of the image, per its headers, before the readable-code check: data pointers are dropped without
a system call.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ThatRecompDev
ThatRecompDev merged commit 0a2db0b into ThatRecompDev:main Nov 25, 2026
1 of 2 checks passed
@ThatRecompDev

Copy link
Copy Markdown
Owner

nice find, 66% of the shims' time on the game's threads is a lot to lose to VirtualQuery on data pointers.

checking the section headers first is the right order, and the readable-code check still runs after it, so nothing gets less safe. the test with a two-section image covers the boundaries nicely.

merged into main (0a2db0b), thanks!

the --sample-threads stack captures you mention are on our list too, they're a separate cost from this

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