Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GC stress fix for reverse pinvoke stubs #37432

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/coreclr/src/vm/gccover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1411,6 +1411,32 @@ BOOL OnGcCoverageInterrupt(PCONTEXT regs)
return TRUE;
}

// If the thread is in preemptive mode then we must be in a
// PInvoke stub with an inlined frame, or be in a reverse PInvoke
// stub that's about to return.
//
// A PInvoke stub should should properly report GC refs if we
// trigger GC here. But a reverse PInvoke stub may over-report
// leading to spurious failures, as we would not normally report
// anything for this method.
//
// So, suppress GC for the reverse PInvoke stubs.
if (!pThread->PreemptiveGCDisabled())
{
_ASSERTE(pMD->IsILStub());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_ASSERTE(pMD->IsILStub());
_ASSERTE(pMD->HasUnmanagedCallersOnlyAttribute());

The method does not have to be IL stub.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scratch that. It can be any method. PInvoke stub with an inlined frame can appear in any method.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. That was just some extra paranoia.

PTR_DynamicMethodDesc pDynamicMD = pMD->AsDynamicMethodDesc();

if (pDynamicMD->IsReverseStub())
{
RemoveGcCoverageInterrupt(instrPtr, savedInstrPtr);
return TRUE;
}
else
{
_ASSERTE(pDynamicMD->IsPInvokeStub());
}
}

#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