Repository navigation
tools: skip the step window for ntdll stub hooks and last returns - #3463
Merged
Merged
Conversation
This was referenced Nov 29, 2026
lukaslw-lab
approved these changes
Nov 30, 2026
lukaslw-lab
left a comment
Contributor
There was a problem hiding this comment.
Reviewed bb207dbd by reading the diff; not built or run.
Verdict: approve. Both shortcuts are confined to cases where skipping the step cannot lose a call. No MUST.
- Emulation scope:
syscall_hooks = set(hooks)is taken right after theNt*file/ALPC andX2W_VALLOC_MINhooks (debug_launch.py:505), before the count, runtime and bink hooks are added (:973-:1007). So only ntdll stubs can be emulated, andarg not in ("count", "runtime", "bink")is a backstop.argis bound wheneveraddr in hooks(:673), and the condition tests that first. - Register write: in the x64
CONTEXT, R10 is at 0xC8 and RIP at 0xF8, andmov r10, rcxleaves the flags alone, so writing R10 and RIP is the whole effect. The 3-byte check runs before the INT3 is written, so it reads the real instruction, and a stub that is already patched (jmp, EDR) keeps the step. - Return disarm: since entries now always trap, a thread's entry event (which calls
arm(ret)and records the pending return) is handled before its return hit.not returns.pending(addr)therefore covers every other thread in flight, and the next entry re-arms.rewind_sourcerewinds only when the byte is no longer0xcc, so a re-armed site goes through normal handling. UNLOAD_DLL:lpBaseOfDllis at offset 16 ofDEBUG_EVENT.forget_moduledrops sites byAllocationBase, so a different module later loaded at that address is not rewound by mistake, which the oldretiredset allowed.
Tests: startup_hook_check.py covers LateBreakpoints directly, plus emulated/disarmed > 0 by default and == 0 with --suspend-others 0. The four mutations show the counts and the R10 target are checked. CI did not run startup_hook_window / startup_hook_overlap: they are Windows ctests outside the pr preset, and the Linux job does not run this file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3461.
A hook is one INT3 byte that is restored for a single step; a thread entering the function during that step runs untraced (#1281), so #1408 holds every other thread around each step. With many live threads that hold dominates the cost of a traced call. #3332 added
--suspend-others 0, which removes the hold but loses calls again. This change removes the step itself on the two common paths of the default mode, so there is nothing to hold for.What changes
tools/startup/debug_launch.py, default path only (--suspend-others 0is unchanged):Nt*hooks (file, directory, symbolic link, ALPC and, withX2W_VALLOC_MIN, the allocation hooks), when the first instruction read at arm time ismov r10, rcx(4C 8B D1), the debugger sets R10 = RCX and RIP = entry + 3 and continues. The INT3 byte is never restored, so no other thread can pass the entry untraced and no step window opens.X2W_LOG_ATpoint and the original byte is not itself an INT3, the original byte is written back and the breakpoint is dropped. The next call re-arms it on its entry event. An INT3 already executed by another thread before the byte was restored is rewound to the restored instruction, as for retiredX2W_LOG_ATpoints. A return still pending for another thread keeps the hold and step.hook emulated: N disarmed: Mnext tohook windows:.tests/startup_launch_probe.cpp: new modeidle_opens(96 threads blocked on an event, one thread doing 500 opens, prints ms/open).tests/startup_hook_check.py: the overlap check now requireswindows + emulated >= 64,emulated > 0anddisarmed > 0under the default, andemulated == 0 and disarmed == 0with--suspend-others 0.Measurements
idle_opens, 96 idle threads, 500 opens, 3 runs each,--timeout 300 --console 0 --trace-files 1 --continue-asserts 0. Main has noidle_opensmode, so all legs run the probe built from this branch; onlydebug_launch.pydiffers.windows=1004 unprotected=0--suspend-others 0windows=1004 unprotected=1004windows=0 unprotected=0,hook emulated: 502 disarmed: 502Every run reported 500 of 500 opens.
Overlap mode (4 threads, 64 opens), same arguments as the test:
Under the default all 66 entries are emulated; the 48 remaining windows are return breakpoints that were stepped rather than disarmed (18 disarmed + 48 stepped = 66).
Tests
startup_hook_windowandstartup_hook_overlappass twice (64 of 64 opens traced with protection; control lost 30, thenlost 28).Mutations of
debug_launch.py, each restored afterwards; all makestartup_hook_overlapfail:armattempt 0: no hook entries were emulatedoverlap opens 0 of 64attempt 0: 16 of 64 opens tracedattempt 0: no return breakpoints were disarmedNot covered
mov r10, rcx, and the hit-counter, runtime-call and movie-player hooks, keep the restore, hold and step.idle_opensis a manual probe mode, not a ctest; the timings above are not checked by any test.--suspend-others 0behaves as before.