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
Starting: Interop.UnmanagedCallersOnly.XUnitWrapper
Interop/UnmanagedCallersOnly/UnmanagedCallersOnlyTest/UnmanagedCallersOnlyTest.sh [FAIL]
corerun(40162,0x7000034a6000) malloc: *** error for object 0x7ff51f42ac90: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
/private/tmp/helix/working/AB440946/w/B9E409AE/e/Interop/UnmanagedCallersOnly/UnmanagedCallersOnlyTest/UnmanagedCallersOnlyTest.sh: line 317: 40162 Illegal instruction: 4 $LAUNCHER $ExePath "${CLRTestExecutionArguments[@]}"
Return code: 1
Raw output file: /private/tmp/helix/working/AB440946/w/B9E409AE/e/Interop/UnmanagedCallersOnly/Reports/Interop.UnmanagedCallersOnly/UnmanagedCallersOnlyTest/UnmanagedCallersOnlyTest.output.txt
Raw output:
@sandreenko This seems to be an issue with a native thread created via std::thread entering the runtime and then begin destroyed.
The test is as follows:
namespace
{
structProxyCallContext
{
CALLBACKPROC CallbackProc;
int N;
int Result;
};
voidProxyCall(ProxyCallContext* cxt)
{
cxt->Result = CallManagedProc(cxt->CallbackProc, cxt->N);
} // A/V is upon the exiting of the thread. The cxt is properly updated.
}
extern"C"DLL_EXPORTintSTDMETHODCALLTYPECallManagedProcOnNewThread(CALLBACKPROC pCallbackProc, int n)
{
ProxyCallContext cxt{ pCallbackProc, n, 0 };
std::thread newThreadToRuntime{ ProxyCall, &cxt };
// Wait for new thread to complete
newThreadToRuntime.join();
return cxt.Result;
}
I think the new native thread entering the runtime is the issue here, but I don't know why as of yet.
I honestly have no idea why this is failing, but is (a) recent and (b) doesn't happen when I use pthreads manually. Therefore I am going to use pthreads manually on non-Windows platforms.
@janvorli If you are feeling bored and interested in picking at some weird behavior, this is something for you :)
I finally found the issue. It is because during the std::thread constructor call, there is an inner data structure that is allocated using the call stack below - which uses the new provided by coreclr. During the cleanup, a different delete is used that uses the system free. This inner data structure is merely for convenience in with the std::thread API. I am confident with fix since it is now explicit instead of implied and also since I know the underlying cause.
Does this mean that a 3rd party code that happens to use std::thread is going to hit the same problem?
We are supposed to link the CoreCLR overridden operator new with private visibility, so that it is used just by the CoreCLR code and nothing else. Maybe this got broken again?
Does this mean that a 3rd party code that happens to use std::thread is going to hit the same problem?
Probably since the test doesn't link against anything special here.
We are supposed to link the CoreCLR overridden operator new with private visibility, so that it is used just by the CoreCLR code and nothing else. Maybe this got broken again?
Boo. That is unfortunate. Let me look into this some more then. If that is indeed the case it might make sense to leave this code as is since it is helpful finding that regression.
Activity
AaronRobinsonMSFT commentedon Jun 22, 2020
@sandreenko This seems to be an issue with a native thread created via
std::threadentering the runtime and then begin destroyed.The test is as follows:
I think the new native thread entering the runtime is the issue here, but I don't know why as of yet.
AaronRobinsonMSFT commentedon Jun 23, 2020
I honestly have no idea why this is failing, but is (a) recent and (b) doesn't happen when I use pthreads manually. Therefore I am going to use pthreads manually on non-Windows platforms.
@janvorli If you are feeling bored and interested in picking at some weird behavior, this is something for you :)
AaronRobinsonMSFT commentedon Jun 23, 2020
I finally found the issue. It is because during the
std::threadconstructor call, there is an inner data structure that is allocated using the call stack below - which uses thenewprovided by coreclr. During the cleanup, a differentdeleteis used that uses the systemfree. This inner data structure is merely for convenience in with thestd::threadAPI. I am confident with fix since it is now explicit instead of implied and also since I know the underlying cause.Allocation:
Deallocation:
jkotas commentedon Jun 23, 2020
Does this mean that a 3rd party code that happens to use std::thread is going to hit the same problem?
We are supposed to link the CoreCLR overridden operator new with private visibility, so that it is used just by the CoreCLR code and nothing else. Maybe this got broken again?
AaronRobinsonMSFT commentedon Jun 23, 2020
Probably since the test doesn't link against anything special here.
Boo. That is unfortunate. Let me look into this some more then. If that is indeed the case it might make sense to leave this code as is since it is helpful finding that regression.