Repository navigation
Refresh stale callee-saved registers in ProcessCLRException's second pass - #138244
pcshrosbree wants to merge 3 commits into
Conversation
|
Azure Pipelines: Successfully started running 3 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Tagging subscribers to this area: @agocke |
On Windows x64 and arm64, when a thread abort, or an exception raised in the runtime's native code, reaches ProcessCLRException's second pass, the SoftwareExceptionFrame is filled from the OS unwinder's copy of the context. A compacting GC before the fill updates the explicit Frame, not that copy, so the next GC can report stale object references. The second pass now looks for a register-reporting explicit Frame below the target whose SP and IP equal the target's, and copies the callee-saved registers through its context pointers. If none matches, it unwinds managed frames from the nearest such Frame up to the target's SP and refreshes only on an exact landing; otherwise it logs a miss. Adds regression tests for the abort, interface-cast and prestub routes. Fixes dotnet#137606
This changes comments only; the code is the same as in the previous commit.
dotnet#138306 asserts that, when the thread's innermost explicit Frame is a RedirectedThreadFrame below the second pass's target, the OS dispatched the interrupted frame itself, so the context's SP and IP equal the interrupted ones. The OS can dispatch a caller instead: for a thread abort redirected onto an epilog start, the OS unwinder finds no handler there and goes one frame up. On Checked builds the SP assert then fails in test137606 on x64 and arm64, and not only in AbortAtEpilogStart; the other cases were not investigated. With the flag set on a caller's context, the managed exception stack walk would use the caller's return address without adjusting it back into the call (inferred; not tested). Replace the asserts with a check: set the flag only when both the SP and the IP match the interrupted context.
4cb9723 to
dc8646b
Compare
I rebased this onto main at b31d004, which includes #138306. The first commit needed only a context fix in After the rebase, What the diagnostic runs show. On x64, during
The new commit replaces the two asserts with a check:
Main with this check, and without the first commit, still crashes with @janvorli, I kept this as a separate commit so it is easy to drop, or to move to its own PR if you would rather fix it another way, for example in the stub; on arm64 the stub has no handler, so padding it would not be enough there. If the flag is set on a caller's context, the managed exception stack walk ( |
| // points to the interrupted instruction, not a return address, unless the OS | ||
| // dispatched a caller instead, as after an interruption at an epilog start. | ||
| T_CONTEXT* pInterruptedContext = static_cast<RedirectedThreadFrame*>(pFrame)->GetContext(); | ||
| if ((GetSP(pInterruptedContext) == GetSP(pContextRecord)) && (GetIP(pInterruptedContext) == GetIP(pContextRecord))) |
There was a problem hiding this comment.
The fact that it sometimes doesn't match (happens on arm64) is a bug caused by the fact that the pContextRecord doesn't point at the interrupted frame, but at its caller instead. This is a difference on Windows arm64 relative to x64 that I've missed. So this conditional just hides the issue. I am working on figuring out solution, this manifested itself as #138392.
In general, creating the SoftwareExceptionFrame from the pContextRecord on arm64 here is wrong.
There was a problem hiding this comment.
TL;DR: From what I measured, the caller is dispatched on Windows x64 as well as arm64 when an abort lands on the first instruction of an epilog. Would your fix also cover x64? And should I drop the gate now and mark the affected tests
[ActiveIssue], or wait for your fix?
Thanks, that makes sense: the gate doesn't fix the context problem. I added it because the new asserts fired in this PR's tests on Checked x64 and arm64.
Some data that may help with #138392. #138306's asserts assume that, in this branch, the OS hands ProcessCLRException the interrupted frame's context. From what I measured, that doesn't hold when an APC abort lands on the first instruction of an epilog, on x64 as well as arm64: the unwinder unwinds the epilog itself, gets no handler for that frame, and dispatches the caller.
- x64 Checked: this PR's
AbortAtEpilogStartlands there on purpose and hits the assert in 3 of 3 runs on both main and this PR's fix build (without the nop below). The diagnostics showPopSpin/PopSpin2interrupted and its callerSpinAtEpilogStartdispatched. - arm64 Checked, in 7 runs without the gate:
AbortThroughRedirect(20 aborts per run) never hit it.AbortAtEpilogStarthit it in 5 of the runs, and the one mismatch I captured with diagnostics there was againPopSpin2interrupted andSpinAtEpilogStartdispatched.AbortThroughHijack, which uses the loop of test135530'sCancelInGenericFrames, hit it in the other 2 runs (1 of 3 on main, 1 of 3 with the fix), without jitstress. - Assert failure: GetSP(static_cast<RedirectedThreadFrame*>(pFrame)->GetContext()) == GetSP(pContextRecord) #138392 looks consistent with this, though its log doesn't show where the abort landed.
CancelInGenericFrames(False)had finished and printed its line before the assert; the other theory case,CancelInGenericFrames(True), runs the sameGenericFrame<T>loop and never printed its line. (TestEntryPointprints nothing, so I can't rule it out.)
On x64, ApcActivationCallbackStub names FixRedirectContextHandler as its personality routine, and FixupDispatcherContext has a prolog/epilog fallback that dispatches the interrupted frame. But the call to ApcActivationCallback is followed directly by add rsp, 30h; pop rbp; ret, so when unwinding out of ApcActivationCallback the OS takes the return address as being in an epilog and never calls FixRedirectContextHandler. With a nop after the call it is called, and the assert went away (0 of 10 runs). That layout dates from 2021 and I haven't validated the path the nop wakes, so I'm not proposing it. Even with the nop, main still crashed in AbortAtEpilogStart in 2 of 5 runs (a corrupted OBJECTREF assert and an AV), against 5 of 5 passes with this PR's refresh. The arm64 stub has no personality routine.
One coupling with this PR: its UnwindRegDisplayToSp fallback is there for exactly this case, where the second pass runs for the caller and the explicit Frame describes a frame below it, and AbortAtEpilogStart is the test that covers it. If your fix always dispatches the interrupted frame, that fallback may no longer be needed here, and I'd drop it if nothing else reaches it.
Without the gate, this PR's tests hit the assert on Checked builds: AbortAtEpilogStart on x64 and arm64, and AbortThroughHijack on arm64. Would your fix also cover x64? And would you prefer that I:
- drop the gate now and mark those tests
[ActiveIssue]against Assert failure: GetSP(static_cast<RedirectedThreadFrame*>(pFrame)->GetContext()) == GetSP(pContextRecord) #138392, so this PR can be reviewed and merged on its own (the fallback above would then have no active test); or - leave the PR until your fix lands, then rebase, drop the gate, and keep or drop the fallback depending on what your fix does?
Could you also look at the main change, the callee-saved register refresh in the second pass? You know this code far better than I do, and I'd value your view on whether it belongs there.
There was a problem hiding this comment.
Hmm, it seems to be the case only for the case when EH unwinds through the APC callback.
There was a problem hiding this comment.
So, the issue with the context being the context of the caller was actually an unwinding issue through the ApcActivationCallback on arm64. Adding nop after the call fixed that. Without it, the OS unwinds the ApcActivationCallback incorrectly and somehow the unwinding ends up skipping the interrupted frame. Even though there is no FixRedirectContext personality routine for arm64.
Will look more into it after the weekend.
There was a problem hiding this comment.
I've found the problem. It is actually very similar to the amd64 issue with the ApcActivationCallbackStub not calling the personality routine. In this case, it is the ProcessCLRException, which is a personality routine for all managed frames, that is not being called. The interrupted managed method is interrupted at the first epilog instruction. Then we throw the thread abort from the APC callback and expect that the OS would call ProcessCLRException for the first managed frame it hits. But due to the issue, it skips the first managed frame's personality routine call.
As a quick check, I've added skipping the thread abort generation in the HandleSuspensionForInterruptedThread when the interruption happened in epilog and the issue is gone.
There was a problem hiding this comment.
Thanks, that matches what I measured: all the mismatches I captured were aborts on an epilog's first instruction. Does your change cover x64 too? This PR's AbortAtEpilogStart hits the same case there. When you have it, I'm happy to run it on x64 and arm64 Checked with test137606: AbortAtEpilogStart passes an epilog start on every iteration, with up to 200 aborts per run, so it should show quickly whether the case is gone. With it in, that test may no longer reach this PR's UnwindRegDisplayToSp fallback, so I'd revisit the fallback then.
There was a problem hiding this comment.
I have created a PR for the fix (#138532).
I will review the refresh of callee saved registers in this PR later today.
There was a problem hiding this comment.
Thanks! I ran #138532 on Windows x64 Checked, on this PR's fix commit with #138306's asserts left in (without the gate commit):
test137606passes in 3 of 3 runs with no assert, andAbortAtEpilogStarttakes 200 aborts in each. In the runs I posted on 11-27, this tree without Fix ThreadAbort from APC callback #138532 hit the SP assert in 3 of 3.- With
DOTNET_GCStress=0x3, it passes in the one run I did (AbortAtEpilogStart: 200 aborts, about 157,000 GCs). - In one run of a build with a local diagnostic that prints when the frame's context and the dispatched context differ in SP or IP, nothing was printed in 200 aborts. So
AbortAtEpilogStartshould no longer reach this PR'sUnwindRegDisplayToSpfallback, though I didn't instrument the fallback itself. - Main with Fix ThreadAbort from APC callback #138532 and without this PR's fix passes 3 of 3 at default settings. Under
GCStress=0x3it still failspMT->Validate()inAbortThroughRedirect(1 run), as main did on 11-27.
So on x64, #138532 removes the epilog-start case in these runs. The arm64 run is next; I'll post it here. Once #138532 is in, I'll rebase, drop the gate commit, and drop the fallback unless you'd rather keep it.
There was a problem hiding this comment.
The arm64 run gives the same picture. On Windows arm64 Checked, with this PR's fix commit and #138306's asserts left in:
- Without Fix ThreadAbort from APC callback #138532,
test137606hit the SP assert inAbortAtEpilogStartin 3 of 3 runs. - With Fix ThreadAbort from APC callback #138532, it passes in 3 of 3 runs with no assert, and in the one
GCStress=0x3run (AbortAtEpilogStart: 200 aborts, about 158,000 GCs). - The context diagnostic again printed nothing.
- Main with Fix ThreadAbort from APC callback #138532 and without this PR's fix passes 3 of 3 at default settings, but fails
pMT->Validate()inAbortThroughRedirectunderGCStress=0x3(1 run).
So #138532 removes the epilog-start case on arm64 in these runs as well.
Three evidence words are used: "measured" means seen in a run, "read" means read from source or a listing, and "inferred" means reasoned from what was measured or read, without being seen directly.
Cause and origin
The second pass pops the explicit Frames below the target and fills a
SoftwareExceptionFramefrompContextRecord, the OS unwinder's copy of the context. A compacting GC before the fill updates the Frame, not that copy. My diagnosis comment on #137606 gives the sequence.Three routes reach this code: the abort route (an asynchronous abort) and two call routes, the interface-cast route and the prestub route. The table under Tests names them.
First seen in 11.0. The fill is traced to #130321 (read), which first shipped in 11.0 preview 7; no .NET 10 release contains it (read from the release tags: no v10 tag contains its commit).
Fix
In the second pass, the handler first looks for a register-reporting explicit Frame below the target whose SP and IP (stack and instruction pointers) equal the target's, skipping active
InlinedCallFrames. If one matches, it copies the callee-saved registers through that Frame's context pointers. That covers both call routes and most aborts. No Frame matches when an abort is redirected onto an epilog's first instruction: the OS gives that frame no handler and dispatches its caller. The evidence for each platform is under "The miss condition" below. If no Frame matches, the handler unwinds managed frames from the nearest register-reporting explicit Frame up to the target's SP, and refreshes only on an exact landing. Otherwise it logs a miss and changes nothing. The change is one file in the runtime, exceptionhandling.cpp, for Windows x64 and arm64 only.The refresh runs on every second-pass call of
ProcessCLRExceptionthat reaches managed exception dispatch. Each such call zeroes a register display, and for each register-reporting Frame it checks, copies the context into the register display and makes a virtual call to the Frame. The register display takes about 3 KB of stack on x64 and about 2.4 KB on arm64, in a function kept out ofProcessCLRException's own frame. Its performance was not measured.Tests
The tests are in the GitHub_137606 regression test folder. Fails-before is on main
8fef9c34678bwithout the fix. Main's failures are confirmed on clean Release builds of that commit on both platforms. The source of each of the "Results, per test and platform" table's own main builds is given under "How this was produced" (on x64, that build has no recorded commit). A test that never fails on main is not included.AbortThroughRedirect,AbortThroughHijack(detect by crash only, by design);AbortAtEpilogStartIDynamicInterfaceCastableresolutionDynamicInterfaceCastableThrows(validates twelve references after the throw)FailingJitWithForcedCollections(validates after the throw)On main, each test fails under at least one of three conditions: run alone, four at once, or a Release build under
GCStress=0x3. With this change, no counted run failed on either platform. The tables, the stress-leg analysis and the runs of existing tests are in the collapsed sections below.The three CI pipelines are
runtime-coreclr gcstress0x3-gcstress0xc,runtime-coreclr gcstress-extraandruntime-coreclr outerloop, each on its Windows x64 and arm64 legs. The new tests are priority 1, and the default PR checks run only priority-0 tests (read), so the default checks do not run them on any platform; the outerloop pipeline does.Limits
FuncEvalFramewithout a hijack leaves the register display unchanged, which gives a logged miss (read, not end to end; not run).RedirectedThreadFrame,ResumableFrame,PrestubMethodFrameandStubDispatchFrame, andHijackFrameon arm64 and on Windows x64 with shadow stacks off (measured; on Windows x64 with shadow stacks off, read from its off-machine summary). In the runs that logged the source of each refresh, no other type appeared. Two runs on x64 that logged a source could not be read in full, and four runs on arm64 have incomplete logs; no other type appeared in the parts read. That the GC's own stack walk uses and writes back the register slots of every type the fix's filter accepts is read from source only, at the base commit. A comparison of the register locations against the GC's own stack walk was made on both machines; it is not cited because its review is not finished.ResumableFrame(on x64 only) andHijackFramewere each a source only in the two abort tests (counts measured; attribution read from the runs' test lists). That statement aboutResumableFrameandHijackFrameuses only runs whose refresh sources can be attributed to one test, or to a run of only the two abort tests. Those two tests detect by crash (read), so for those refreshes a pass shows only that no crash followed. For the other types, and for how long each Frame's storage stays valid, I rely on inference from reading the source, which does not cover every case.AbortAtEpilogStartunderGCStress=0x3on this change's build, 4,000 refreshes were examined: 1,257 changed at least one of x19-x28, and none changed x29 (measured). This covers one test, on arm64, underGCStress=0x3. It shows that x29 was not changed in those refreshes, not that a refresh can never change it.DynamicHelperFrame,ExternalMethodFrame) were read only, not run.AbortAtEpilogStartneeds fast tail calls.DOTNET_FastTailCalls=0declines them (read); the test then still runs but, by inference, tests an ordinary abort, not the epilog start.ExecutionManager::GetScanFlags) while the context is set takes the code-range reader-lock path. Main already makes such a lookup at the handler's entry on every call that reaches this code, and in its exception stack walk (read); the fallback adds lookups of the same kind earlier in the same dispatch. How a thread can be in that state was not determined: one possible way, not shown to be reachable, is a profiler resuming a runtime suspension while another of its threads is taking a stack snapshot (inferred; not run).Alternatives considered
StackFrameIteratorwalk as the fallback. It would cover what this change covers without listing Frame types, at the cost of a full stack walk inside the OS's second pass.ApcActivationCallbackStub's call sits directly before its epilog, so its exception handler is never called #138240): on x64, onenopafterApcActivationCallbackStub's call lets its existing handler run, which removed the misses on one test (0 of 14,400 aborts missed with thenop, against 1,139 of 14,200 without it, measured), but it does nothing on arm64 and does not close the defect (inferred). Whether thenopalone stops the abort route failing on main was not measured.Results, per test and platform
Each entry gives failed runs of counted runs, first on main and then on this change. Test sizing describes the default-settings conditions. Intervals are 95 % Wilson score intervals.
GCStress=0x3: main / fixAbortThroughRedirectAbortThroughRedirectAbortThroughHijackAbortThroughHijackAbortAtEpilogStartAbortAtEpilogStartDynamicInterfaceCastableThrowsDynamicInterfaceCastableThrowsFailingJitWithForcedCollectionsFailingJitWithForcedCollectionsWork is the number of iterations or aborts a test reports. A cell is a set of runs of one test on one platform and build, with the same settings. A run is void, and not counted, if it passed with work below its floor. The floor is 10 % of the median work of quiet runs (run alone, no GC stress) of the same test DLL (the compiled test) on the same build and side, rounded down, with a minimum of 1. The median is taken over the quiet cell's passing runs; failed and timed-out runs are excluded. The floor applies to passes only. Every run's raw work count stays in its record. Timeouts are their own class, counted separately from failures: not passes, not failures, not dropped. A timeout is a run that reached the 600 s limit; it was then stopped, or it ended by itself while it was being dumped. A run whose outcome was not recorded ended on its own after the time limit without being killed, with no exit code and no pass, failure or crash shown. Entries that stopped at 20 failures have approximate intervals, because the stopping point depends on the count.
A failure counts as "by validation" only where the run's own console output shows the failure message of the test's check of the objects it holds. Any other exit with code 101 is an "other test failure", and any other failing exit is "by crash".
Every entry ran on test DLLs compiled from this PR's test sources, unchanged (hash-checked before each build). Each DLL holds one test: it was built with the test build's standard
TestFilterproperty set to that test, so its generated entry point runs only that one. The DLLs were built in a separate local source tree, not in a checkout of this PR's commit, so the test library and the wrapper generator came from that tree: a local working commit on arm64, and a tree whose commit is not recorded on x64. The DLL's hash was recorded at the copy step and in every run. The confirmation runs and the runs in the Checked table used the same DLLs: this is read from the run records on x64 and for the arm64 Checked runs; for the arm64 confirmation runs it is read for two of the five tests on the base side and inferred for the rest. Before every run, a check confirmed that no build or test host was running other than these runs; Test sizing gives each machine's check.Can the upstream stress legs catch a regression?
Every run in the "Results, per test and platform" table, including the
GCStress=0x3runs, used a Release runtime with tiered compilation at its default (read); the upstreamgcstress0x3andgcstress0xclegs run on Checked builds with tiered compilation off (read).The table below shows whether those legs can catch a regression in each test, judged from main's runs under GC stress. Each figure is main's failed runs of counted runs: the table's Release
GCStress=0x3entry, then runs on a Checked build of main with tiered compilation off, as in the legs, underGCStress=0x3and thenGCStress=0xC(measured). The Checked runs were one to three per test and setting, so they are not rates.0x3; Checked0x3; Checked0xCAbortThroughRedirectGCStress=0x3, on both platformsAbortThroughHijackGCStress=0x3, on both platformsAbortAtEpilogStartGCStress=0x3, on both platformsDynamicInterfaceCastableThrowsFailingJitWithForcedCollectionsOn arm64, main's floor for those Checked
FailingJitWithForcedCollectionsruns is the minimum of 1, because main's own quiet run failed validation (measured).Under
GCStress=0xC, main did not fail any of these tests on either machine in the runs made, so a pass under0xCdoes not show that the fix works. These tests carry noGCStressIncompatiblemarker; if you would rather the stress legs skip the ones not shown to fail on main under GC stress, I can add it.Existing tests and the default build of the new tests
The extended set is the existing exception-handling tests (
baseservices/exceptions, the Methodical EH tests,GitHub_135530,nestedfinallycallandthrowisfirstinstruction), seven other test trees (Interop/IDynamicInterfaceCastable,GitHub_76531,InlineArray, an explicit-layout overlap tree,ByRefLike, binder tracing andInvalidFriendAssemblyName), and this PR's three test projects. On x64, the items of the extended set were each run once, in a plain pass, on a clean Checked build of this PR's commit. Of the 101 existing items, 94 exited 100 (measured). The other 7, which are 5 distinct tests in the InlineArray and explicit-layout class loader groups, did not start: each exited with a MissingMethodException ("Entry point not found") before any test code ran (measured). I take this to be a fault in my local build of those two test trees (inferred). Two of those five,case13andInlineArrayInvalid, passed on arm64. On arm64, the 84 existing test items of the extended set, which includecase13andInlineArrayInvalidbuilt as standalone programs, were each run twice on a clean Checked build of this PR's commit. All exited 100 in both passes: a plain pass and a pass with the runtime's stress log recording each refresh (measured). The testBinderTracingTest.DefaultProbingwas not run: its project is disabled for all CoreCLR builds (#57786).On x64, the three test projects in GitHub_137606 (
test137606,test137606noabortandtest137606prestub) were also built the default way, with noTestFilter, from this PR's commit, and each was run 5 times alone with plain corerun and no GC stress on a clean Release build of the same commit: all 15 runs exited 100, and eachtest137606run printed the lines of all three of its tests (AbortThroughRedirect,AbortThroughHijackandAbortAtEpilogStart) in one process (measured). On arm64, the unfilteredtest137606ran in both passes of the extended set, on the clean Checked build of this PR's commit, and exited 100 each time; its output was not kept, so that all three tests ran is not shown.How this was produced
What was run: the tests above and the reproducers, on self-built main, on stock 11.0.0 and on a pre-release 11.0.2 daily build, on Windows x64 and arm64, plus the crash-dump readings.
The "Results, per test and platform" table's entries come from the original builds of main and of this change. Their records show this about the source of each:
exceptionhandling.cppwas copied into a source tree whose commit is not recorded (read). The copy differs from this PR's file only in two comment lines (read).src/coreclr, differs from it only in the same version ofexceptionhandling.cpp(read). The worktree had no uncommitted changes when that commit was made (read).The Checked builds of this PR's commit, one per platform, were each built at that commit with no uncommitted changes before or after the build (read). On x64 the build was made in a new clone; on arm64, in a worktree with no earlier Checked output (read). Earlier Checked builds of this change were made in trees that had held other builds (read); the x64 one was incremental (read). On x64, that build followed the same copy of
exceptionhandling.cppas the x64 Release build, and the tree's commit is not recorded (read). On arm64, it was built at the same commit as the arm64 Release build of this change, with no uncommitted changes before or after (read).The stress-legs table's Checked runs of main used the following builds. On x64, the Checked build of main was built in a fresh clone at
8fef9c34678bon 23 Nov, with its tree clean before and after (read). Every quoted run recorded that build'scoreclr.dll,clrjit.dllandSystem.Private.CoreLib.dllhashes before and after the run (measured from the run records). On arm64, the Checked build of main was made in a worktree with no earlier Checked output and no uncommitted changes before or after the build (read). Its build log records that the worktree was at the base commit when the build was made (read).On arm64, two clean Release builds of the base commit, made one after the other in two worktrees with no uncommitted changes, were not byte-identical (measured). In
clrjit.dllandSystem.Private.CoreLib.dllevery difference was a path, a timestamp or build identity, butcoreclr.dllalso differed in code and layout, including one function placed in a different order (measured). On x64, two clean Release builds of the base commit were also not byte-identical. Neither were two clean builds of this PR's commit: one a Release build, the other a build whose configuration was not recorded. Each was made in a new clone with no uncommitted changes (read), and in both pairscoreclr.dlldiffered in code and layout (measured). So comparing binaries could not show which commit a runtime was built from, and that comparison was abandoned. In its place, the three abort tests (underGCStress=0x3) and the two call-route tests (at default settings) were run again on clean Release builds of the base and of this PR's commit (measured):AbortThroughRedirectfailed in 25 of 30 runs,AbortThroughHijackin 29 of 30 andAbortAtEpilogStartin 30 of 30;DynamicInterfaceCastableThrowsandFailingJitWithForcedCollectionsfailed in all 23 of their runs each, which ran to a stop at 20 failures.AbortThroughHijackreached its 30 counted passes with no failure (32 passes in 44 runs), andDynamicInterfaceCastableThrowsandFailingJitWithForcedCollectionspassed 100 of 100 runs each. On arm64, on a clean Release build of this PR's commit underGCStress=0x3,AbortThroughRedirectreached 20 counted passes in 39 runs andAbortAtEpilogStart21 in 47, short of the 30 planned in the 60-minute window. No run failed; the other runs did too little work to count, timed out, or were cut at the window's end. In those two sets, 9 runs timed out (measured). Of those, 4 ended by themselves, with the test's pass exit, while their dumps were being taken (measured). The other 5 were dumped: four have two dumps each, and one has a single dump because its second was never written (measured). Each of those 9 dumps shows 8 or 9 threads, and in none is either of the fix's refresh functions (UpdateNonvolatileRegistersFromExplicitFrame,UnwindRegDisplayToSp) on any stack (measured). Between each run's two dumps, the thread doing the GC had moved on (measured). So the four runs with two dumps were slow runs under GC stress, not hangs (inferred), and for the run with a single dump, progress was not observed.AbortThroughRedirectfailed in 29 of 30 runs,AbortThroughHijackin 29 of 30 andAbortAtEpilogStartin 30 of 30;DynamicInterfaceCastableThrowsfailed in 9 of 455 andFailingJitWithForcedCollectionsin 20 of 449.AbortThroughRedirect,AbortThroughHijackandAbortAtEpilogStartunderGCStress=0x3each passed 30 of 30 runs, andDynamicInterfaceCastableThrowsandFailingJitWithForcedCollectionspassed 100 of 100 runs each; no run failed.I did not run the ReadyToRun-only routes or the path used when the special user-mode APC is unavailable. Statements marked "read" or "inferred" were not checked in a run. The OS unwinder's behaviour could be neither run in isolation nor read, because its source is not in the tree.
In the sections below, the figures come from runs that recorded the hashes of the runtime binaries they loaded; any figure from an earlier run without that record is marked "earlier run".
The miss condition
The exact match fails only when a special-APC redirect interrupts a thread at the first instruction of an epilog, and nothing makes the OS dispatch that frame anyway. The rude-abort and
FuncEvalFramelimits above give a logged miss for a different reason.AbortAtEpilogStart, which did not yet catch each abort to validate after it.RtlVirtualUnwind, which is not in the tree; the GC's walk calls it on the same frame (read).Engagement counts, by mechanism
AbortAtEpilogStartAbortAtEpilogStart,GCStress=0x3AbortAtEpilogStartMeasured on this change with logging on, per abort or throw; "Throws" counts aborts and other throws; where two counts appear, they are the throws examined and the throws the test reports. In the prestub row, the 88 extra throws are one dependency-check raise per run (read from source). The two abort-route rows split one run set's 18,160 aborts, of 18,160 the test reports, by the Frame the refresh used, not by test:
RedirectedThreadFramefor the redirect,ResumableFramefor the hijack. That hijack is inferred to be a CET (Control-flow Enforcement Technology) hijack, because user-mode shadow stacks are on for the test host on the x64 machine. In theGCStress=0x3row, the 30 prestub refreshes are all aborts, since the 25,200 throws are the 200 aborts of each of 126 runs; an abort reached a thread while it was inside the prestub (inferred from the Frame type,PrestubMethodFrame). The runs record the runtime's hashes; the test DLL's hash is recorded once per run set on both platforms, not per run; on arm64, that this DLL was built from the tests under review is inferred. The arm64 abort-route and call-route rows were not measured. "Special-APC redirect" is inferred from the Frame,RedirectedThreadFrame(measured), and the runtime's probe for the special APC.On x64 at
GCStress=0x3, 1,737 of the 2,826 refreshes after unwinding changed a register. The test holds an object in each of eight callee-saved registers and compares all of them after every abort (read from the method listing). Among the 1,737 refreshes, 1,703 changed r12, 1,718 changed r13 and 1,667 changed r15; these counts overlap (measured). Validation failed in 0 of 126 runs (0 of 25,200 aborts; measured). Every run recorded collections, at least 98,628 each (measured). That the listing, taken at default settings, matches the code that ran underGCStress=0x3is inferred.Reproduction, versions run, and 11.0.0 versus the pre-release 11.0.2 daily build
On stock 11.0.0 the abort route reproduces on x64 (under GC stress, and at default settings with a concurrent collector). On arm64 it failed in 80 of 84 runs under GC stress in an earlier run, and the other 4 hung (no control).
Stock 11.0.0, one row per route per platform. "Validation inferred": the app exited with the code its source gives for a failed check of the objects it holds; the source copy read is not tied by hash to the binary that ran.
GCStress=0x3, tiering off; 176 / 1,826 with no GCStress, default tiering and a collector threadGCStress=0x3, tiering off; the other 4 hungFor the x64 prestub row, that the runs loaded the published release files is inferred from the runtime path each run used, and the app's hash was recorded once per start of the run driver, not per run.
How the controls differ, in full:
REPRO_MIN_COMPACTINGcompacting collections. (2) The dependency is present, so nothing throws. (3)REPRO_MIN_COMPACTING=33, the stock runs' exposure, so the control has matched GC exposure (gen0 median 33 against 32).REPRO_MIN_COMPACTING=61296, the median compacting count of the completed runs of an earlier failing run set, which keeps its collections high (61,295 to 67,543 gen0, a higher median than in the 34 stock runs that recorded a count; not matched run by run).The ReadyToRun-only routes (
DynamicHelperFrame,ExternalMethodFrame) were read only. TheIDynamicInterfaceCastablecast path was read as not exposed to this defect, and running it did not reproduce the defect.Versions run: main
8fef9c34678b, and 11.0.0 and the pre-release 11.0.2 daily build on x64 and arm64. Earlier releases, on x64 with the abort reproducer underGCStress=0x3:Under
GCStress=0x3, the abort reproducer used for the bisect, not the all-registers one, fails on the pre-release 11.0.2 daily build on x64 but not on 11.0.0 (earlier runs). That bisects to43955593de5f, a profile-data update that changedControlledExecution.Run's register saves. It changes exposure, not the defect: the all-registers reproducer fails on 11.0.0 x64 too.The stock counts are by exit status, with controls where available; how each differs is listed above. Dump readings exist for the abort route on x64 and arm64. Stock 11.0.0 was checked against the release's published sha512 hashes on both platforms.
Delivery mechanisms, per OS
AbortThroughRedirect,AbortThroughHijackAbortAtEpilogStartDynamicInterfaceCastableThrowsFailingJitWithForcedCollectionsIn this table, "special-APC redirect" is inferred from the Frame and the runtime's probe for the special APC; "CET hijack" is inferred from the shadow-stack setting.
My arm64 machine runs Windows 11 build 26300 and exports
QueueUserAPC2; its aborts arrive asRedirectedThreadFrameorHijackFrame. My x64 machine and upstream's x64 and arm64 queues use build 26100; from the build and the runtime's probe for the special APC, I infer they use the special APC too. So, by that inference, the path used when the special user-mode APC is unavailable, which reachesThread::ThrowControlForThread, runs on none of them. x86 is untouched.Test sizing
At default settings, how often a test catches a regression varies with the test, the platform and the load (see "Results, per test and platform"); run alone, some do not fail at all (named below).
Run alone is one copy of the test on an otherwise idle machine. Four at once is four copies of the same test running together, each under the load of the other three. A run set counts as four at once only if its median number of runs in flight is at least 4, from the counts logged at each run's start and end. A run set below that is reported and not quoted. Every
GCStress=0x3entry in the table also ran four at once, on both machines: each of those run sets had a median of 4 runs in flight (measured). Rates at default settings vary with load.Run alone at default settings,
AbortThroughRedirectandAbortThroughHijackdid not fail on main on either platform (455 runs on x64, 100 on arm64), and neither didAbortAtEpilogStarton arm64 (100 runs). These cases need GC stress or the load of four at once to fail on main;AbortAtEpilogStarton x64 and the other two tests also fail on main run alone (see "Results, per test and platform").AbortThroughRedirect,AbortThroughHijackAbortThroughRedirect: x64 0.8 s / 0.8 s, arm64 0.8 s / 0.8 s;AbortThroughHijack: x64 0.8 s / 0.8 s, arm64 0.8 s / 0.8 sAbortAtEpilogStartDynamicInterfaceCastableThrowsFailingJitWithForcedCollectionsFailingJitWithForcedCollections: median iterations per passing run, with the number of passing runs in brackets (measured).GCStress=0x3: mainGCStress=0x3: fixOn arm64 under
GCStress=0x3, no passing run reached its floor (12 on main, 32 on this change). Why the two platforms differ was not determined.On x64, a check ran before every run in the "Results, per test and platform" table, including the stress runs. It confirmed that the machine's CI runners were paused with no job running or pending, that no build or test host was running other than these runs, and that WSL was idle. The WSL part did not apply to the first run of each run-alone cell.
The x64 test drivers left their own WSL monitoring processes running after each run, so these accumulated. They were counted only for the later x64 runs (from 23 Nov): the confirmation runs on clean builds and the Checked runs of main and of this change. Of these, 59 were already running when the first of those runs ended, so they were left by earlier x64 runs (inferred). For the results table's x64 runs, how many were alive, and how often the check held a run, was not recorded.
During the later runs at least 91 were alive at the peak. Each run started only after the WSL check read under its limit. The check held runs for WSL activity 30 times in the confirmation runs on the clean base build, 5 times in the Checked runs of main and not at all in the Checked runs of this change, for up to 26 s. Only the first failed check of each hold was logged, so these counts are of holds whose first logged reason was WSL activity. Four other holds were logged on the runner or process checks, and the first run of each cell was held for up to 46 s, before the check had its first WSL reading.
The processes matched to these runs' own launches were then stopped. The confirmation runs on the clean Release build of this PR's commit ran after that. The check did not hold any of them for WSL activity; each cell's first run waited up to 20 s for the check's first WSL reading. At least 38 of the earlier monitoring processes were still alive during each cell of those runs (measured, a lower bound); their effect on the results was not measured.
On arm64, a check ran before every run in the "Results, per test and platform" table, including the stress runs. It confirmed that no build or test host was running other than these runs. From the run-alone main runs of
FailingJitWithForcedCollectionson, it also confirmed that the machine's CI runners were paused and that WSL was idle (read from the run records). The run-alone runs before them were made before those two checks were added (read from the run records). Neither check looks at other processes, at CPU load, or at anything during a run. Their WSL busy readings use different sampling windows, each with its own controls: on arm64 1-s readings, and on x64 a form that depends on the driver version. On x64, the run-alone cells' driver took a single WSL reading at each check (for one of them, the driver is inferred from the fields its records carry); the four-at-once andGCStress=0x3cells' drivers took a rate over 20 s from a background sampler. On that single-reading driver, the first run of a cell could start before any WSL reading was taken; it ran the run-alone cells of all five tests, main and fix. The later x64 runs took a rate over 2 s in the Checked runs and over 20 s in the confirmation runs on clean builds.Each run's identity was checked differently on the two machines. On x64, each run's hashes were taken before and after the run and compared with the copy step. On arm64, each run's hashes were taken at its start only, and no hash was taken after the run. The hashes were compared with the cell's start hashes and the recorded build's
coreclr.dllhash; the test DLL's hash was compared with its hash at the copy step.The GC stress runs show the contrast with main; the fix's failure rate is bounded by the default-settings runs. For
DynamicInterfaceCastableThrowson x64 and arm64 andFailingJitWithForcedCollectionson x64, the GC stress runs did not fail on main in 30 runs each, so they do not show the contrast. For these, the fix's failure rate rests on the default-settings runs alone. ForFailingJitWithForcedCollectionson arm64, no main or fix run of the Release build underGCStress=0x3did enough work to count.In the x64
AbortAtEpilogStartfour-at-once runs on the fix, collections per run, from the test's own count: minimum 4,755 and median 5,377 over its 538 passing runs; on main, 4,771 and 5,252 over 510 passing runs (measured).In the arm64
AbortAtEpilogStartfour-at-once runs, every run's test DLL hash equalled the copy step's (measured). On the fix, collections per run, from the test's own count: minimum 7,233 and median 8,352 over all 455 runs (measured). On main, 418 of the 455 runs recorded the count, with a minimum of 7,396 and a median of 8,486 (measured). Collections in those runs come from the test's own collector thread, which runs when GCStress is off (inferred from source).Each test holds movable references in callee-saved registers. It detects corruption by validation where it can observe the register, and by a crash otherwise.
AbortThroughRedirectandAbortThroughHijackdetect by crash only, by design:ControlledExecution.Runnever returns normally after an abort, so the holder cannot check its objects afterwards. The prestub-route test uses a dependency that is never deployed, and setsCrossGenTest=false.DynamicInterfaceCastableThrowsruns its throwing path once before its collector thread starts, so the first throw's one-time costs are paid without collections running. With a PDB (debug symbols file) beside the test DLL, as in a local build, that first throw otherwise waits behind forced collections for minutes. Upstream CI strips test PDBs from its payloads by default (read), so CI would not hit it.AbortAtEpilogStarthas two methods tail-call each other with ILtail. call, so an abort can land on a framed epilog's first instruction. The methodRunAndCatch, between the holder andControlledExecution.Run, catches the exceptionControlledExecution.Runthrows after each abort, so the holder runs on and validates its objects after every abort.HoldAcrossCatchingRun(the holder) andRunAndCatchare both markedAggressiveOptimization(read). At default settings, four at once,AbortAtEpilogStartfailed on main in 60 of 570 runs on x64, 56 by crash and 4 by validation, and in 51 of 455 runs on arm64, 37 by crash and 14 by validation. The test reaches an epilog start only if the JIT emits thosetail.calls as fast tail calls, and for their signatures, with every argument in a register and no return buffer, onlyDOTNET_FastTailCalls=0prevents that (read).Resolves #137606
Note
This analysis and fix was prepared with AI assistance (Anthropic Claude, OpenAI Codex, Google Gemini) at my request. I reviewed the fix and tests before opening.