You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@jkotas or @janvorli Any suggestions here on how to address this for Windows would be helpful. I have a fix for #33612, but this one seems related to the exception handling side of things that I am less knowledgable about how to mitigate.
Bah. I think this is my bad. @jkotas If I recall a conversation about exceptions and the NativeCallableAttribute, the expectation here is that they don't mix at all and we shouldn't even be trying to validate them right? If so I will disable those tests since I added them just to have a set of scenarios I could validate fail. Looks like on GCStress they really don't work due to the stack walking logic in
On Windows, the managed exception should get converted to SEH exception on the NativeCallable boundary.
On Unix, the managed exception should become unhanded on the NativeCallable boundary.
And even stranger, how come Aaron's fix doesn't help, as the OnGcCoverageInterrupt with his fix is checking for NULL Thread and if it is the case, it should just silently remove the hlt and go without ever going into the ProcessCLRException. I'm stepping through the code to see if I can find a clue.
@janvorli That is because this is the PrepareMethod() scenario where the function is JITed from a thread that is initialized and only called on a thread that is external.
@janvorli Nope. I misunderstood why this was happening. Looks like the COOP transition is happening before the call to IsGcMarker() which would handle the case I fixed.
{
GCX_COOP();
// Update the current establisher frameif (dwExceptionFlags & EXCEPTION_UNWINDING)
{
ExceptionTracker *pCurrentTracker = pThread->GetExceptionState()->GetCurrentExceptionTracker();
if (pCurrentTracker != NULL)
{
pCurrentTracker->SetCurrentEstablisherFrame(sf);
}
}
#ifdef _DEBUG
Thread::ObjectRefFlush(pThread);
#endif// _DEBUG
}
//// begin Early Processing//
{
#ifndef USE_REDIRECT_FOR_GCSTRESS
if (IsGcMarker(pContextRecord, pExceptionRecord))
{
returnDisposition = ExceptionContinueExecution;
goto lExit;
}
#endif// !USE_REDIRECT_FOR_GCSTRESS
Can we just create the Thread when we are doing GC stress and hit the GC stress exception handler?
@jkotas Can you elaborate on this? @AndyAyersMS suggested I could update bool emitter::emitNoGChelper(CorInfoHelpFunc helpFunc) to have the Enter/Exit - the CORINFO_HELP_INIT_PINVOKE_FRAME is already present. Is that what you mean here?
It seems that the call to ProcessCLRException stems from something else than the GC coverage interrupt. I can see that the CLRVectoredExceptionHandlerShim correctly detects that the Thread is null and just removes the instrumentation and returns. And then a bit later, without any other CLRVectoredExceptionHandlerShim call, the ProcessCLRException is called and crash due to the Thread being NULL. There are hundreds of CLRVectoredExceptionHandlerShim calls to handle previous GC coverage interrupts before that and none of them results in a call to ProcessCLRException. So there is something happening that causes the call to occur (with error code 0xc0000096, which represents the coverage privileged instruction). I wonder if the CLRVectoredExceptionHandlerShim returns wrong return value or something like that. I keep looking...
Yes, I was right. The problem is that the fix @AaronRobinsonMSFT did in OnGcCoverageInterrupt in #33615 was insufficient. We also need to make sure that the CLRVectoredExceptionHandlerShim returns EXCEPTION_CONTINUE_EXECUTION when bIsGCMarker is true and pThread is NULL. We were currently returning EXCEPTION_CONTINUE_SEARCH, which resulted in the incorrect call to ProcessCLRException.
@janvorli I just tested that very scenario. My plan was to update if (pThread || fExceptionInEE) to if (pThread || fExceptionInEE || bIsGCMarker) in excep.cpp@7982?
Activity
AaronRobinsonMSFT commentedon Mar 16, 2020
@jkotas or @janvorli Any suggestions here on how to address this for Windows would be helpful. I have a fix for #33612, but this one seems related to the exception handling side of things that I am less knowledgable about how to mitigate.
AaronRobinsonMSFT commentedon Mar 16, 2020
This is easy to reproduce locally. Looks like an issue with
TestNativeCallableValid_ThrowException()test.runtime/src/coreclr/tests/src/Interop/NativeCallable/NativeCallableTest.cs
Lines 210 to 255 in a1af0f2
AaronRobinsonMSFT commentedon Mar 16, 2020
Bah. I think this is my bad. @jkotas If I recall a conversation about exceptions and the
NativeCallableAttribute, the expectation here is that they don't mix at all and we shouldn't even be trying to validate them right? If so I will disable those tests since I added them just to have a set of scenarios I could validate fail. Looks like on GCStress they really don't work due to the stack walking logic inruntime/src/coreclr/src/vm/exceptionhandling.cpp
Line 6392 in 4ceccbb
jkotas commentedon Mar 16, 2020
On Windows, the managed exception should get converted to SEH exception on the NativeCallable boundary.
On Unix, the managed exception should become unhanded on the NativeCallable boundary.
jkotas commentedon Mar 16, 2020
I think we are missing "unwind and continue" on the NativeCallable boundary. @janvorli Do you have thoughts about the best way to fix that?
15 remaining items
AaronRobinsonMSFT commentedon Mar 16, 2020
@janvorli That is because this is the
PrepareMethod()scenario where the function is JITed from a thread that is initialized and only called on a thread that is external.AaronRobinsonMSFT commentedon Mar 16, 2020
@janvorli But you just pointed out to me how I think we can fix this.
AaronRobinsonMSFT commentedon Mar 16, 2020
@janvorli Nope. I misunderstood why this was happening. Looks like the COOP transition is happening before the call to
IsGcMarker()which would handle the case I fixed.{ GCX_COOP(); // Update the current establisher frame if (dwExceptionFlags & EXCEPTION_UNWINDING) { ExceptionTracker *pCurrentTracker = pThread->GetExceptionState()->GetCurrentExceptionTracker(); if (pCurrentTracker != NULL) { pCurrentTracker->SetCurrentEstablisherFrame(sf); } } #ifdef _DEBUG Thread::ObjectRefFlush(pThread); #endif // _DEBUG } // // begin Early Processing // { #ifndef USE_REDIRECT_FOR_GCSTRESS if (IsGcMarker(pContextRecord, pExceptionRecord)) { returnDisposition = ExceptionContinueExecution; goto lExit; } #endif // !USE_REDIRECT_FOR_GCSTRESSAaronRobinsonMSFT commentedon Mar 16, 2020
@jkotas Can you elaborate on this? @AndyAyersMS suggested I could update
bool emitter::emitNoGChelper(CorInfoHelpFunc helpFunc)to have the Enter/Exit - theCORINFO_HELP_INIT_PINVOKE_FRAMEis already present. Is that what you mean here?janvorli commentedon Mar 16, 2020
It seems that the call to ProcessCLRException stems from something else than the GC coverage interrupt. I can see that the CLRVectoredExceptionHandlerShim correctly detects that the Thread is null and just removes the instrumentation and returns. And then a bit later, without any other CLRVectoredExceptionHandlerShim call, the ProcessCLRException is called and crash due to the Thread being NULL. There are hundreds of CLRVectoredExceptionHandlerShim calls to handle previous GC coverage interrupts before that and none of them results in a call to ProcessCLRException. So there is something happening that causes the call to occur (with error code 0xc0000096, which represents the coverage privileged instruction). I wonder if the CLRVectoredExceptionHandlerShim returns wrong return value or something like that. I keep looking...
AaronRobinsonMSFT commentedon Mar 16, 2020
Yep the call to
CLRVectoredExceptionHandlerShim()is returningEXCEPTION_CONTINUE_SEARCHduring thathltfor GC cover. What should it be returning?janvorli commentedon Mar 16, 2020
I think I've found the culprit - testing now ...
janvorli commentedon Mar 16, 2020
Yes, I was right. The problem is that the fix @AaronRobinsonMSFT did in OnGcCoverageInterrupt in #33615 was insufficient. We also need to make sure that the CLRVectoredExceptionHandlerShim returns EXCEPTION_CONTINUE_EXECUTION when bIsGCMarker is true and pThread is NULL. We were currently returning EXCEPTION_CONTINUE_SEARCH, which resulted in the incorrect call to ProcessCLRException.
AaronRobinsonMSFT commentedon Mar 16, 2020
@janvorli I just tested that very scenario. My plan was to update
if (pThread || fExceptionInEE)toif (pThread || fExceptionInEE || bIsGCMarker)inexcep.cpp@7982?janvorli commentedon Mar 16, 2020
I would put the following at line 7967. That is sufficient. I believe we don't need anything from the body of the
ifyou've mentioned.janvorli commentedon Mar 16, 2020
I also have a fix for the other issue, I will create a PR soon.
AaronRobinsonMSFT commentedon Mar 16, 2020
I will fold the above into the previous PR so it is complete.
AaronRobinsonMSFT commentedon Mar 17, 2020
Fixed with #33653 and #33615