Skip to content

Commit

Permalink
Mitigation for a GC Stress race after an inline pinvoke (#38246)
Browse files Browse the repository at this point in the history
In the post-call part of a pinvoke inline call frame, it's not safe
to start a stress mode GC in the window between checking
`g_TrapReturningThreads` and the call to `CORINFO_HELP_STOP_FOR_GC`.

The call instruction is already getting special treatement, but there may
be other instructions between the check and call. Instead of trying
to pattern match them all, suppress GC stress if `g_TrapReturningThreads`
is true, the thread is in cooperative mode, and there's an active inline
call frame.

Closes #37236.
  • Loading branch information
AndyAyersMS authored Jun 23, 2020
1 parent 3052acc commit d6b8109
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/coreclr/src/vm/gccover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1425,6 +1425,18 @@ BOOL OnGcCoverageInterrupt(PCONTEXT regs)
return TRUE;
}

// If we're in cooperative mode, we're supposed to stop for GC,
// and there's an active ICF, don't initiate a stress GC.
if (g_TrapReturningThreads && pThread->PreemptiveGCDisabled())
{
Frame* pFrame = pThread->GetFrame();
if (InlinedCallFrame::FrameHasActiveCall(pFrame))
{
RemoveGcCoverageInterrupt(instrPtr, savedInstrPtr);
return TRUE;
}
}

#if defined(USE_REDIRECT_FOR_GCSTRESS) && !defined(TARGET_UNIX)
// If we're unable to redirect, then we simply won't test GC at this
// location.
Expand Down

0 comments on commit d6b8109

Please sign in to comment.