Skip to content

Commit

Permalink
Merge branch 'main' into kcm-scalar-convert-math-helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
khushal1996 authored Mar 6, 2024
2 parents afc1b54 + b48a797 commit 2446b93
Show file tree
Hide file tree
Showing 53 changed files with 645 additions and 1,027 deletions.
2 changes: 1 addition & 1 deletion docs/workflow/debugging/coreclr/debugging-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ It might also be the case that you would need the latest changes in SOS, or you'
**NOTE**: Only `lldb` is supported to use with SOS. You can also use `gdb`, `cgdb`, or other debuggers, but you might not have access to SOS.

1. Perform a build of the _clr_ subset of the runtime repo.
2. Start lldb passing `corerun`, the app to run (e.g. `HelloWorld.dll`), and any arguments this app might need: `lldb /path/to/corerun /path/to/app.dll <app args go here>`
2. Start lldb passing `corerun`, the app to run (e.g. `HelloWorld.dll`), and any arguments this app might need: `lldb -- /path/to/corerun /path/to/app.dll <app args go here>`
3. If you're using the installed version of SOS, you can skip this step. If you built SOS manually, you have to load it before starting the debugging session: `plugin load /path/to/built/sos/libsosplugin.so`. Note that `.so` is for Linux, and `.dylib` is for macOS. You can find more information in the diagnostics repo [private sos build doc](https://github.com/dotnet/diagnostics/blob/main/documentation/using-sos-private-build.md).
4. Launch program: `process launch -s`
5. To stop breaks on _SIGUSR1_ signals used by the runtime run the following command: `process handle -s false SIGUSR1`
Expand Down
5 changes: 4 additions & 1 deletion eng/native/functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,12 @@ function(preprocess_file inputFilename outputFilename)
COMMENT "Preprocessing ${inputFilename}. Outputting to ${outputFilename}"
)
else()
if (CMAKE_CXX_COMPILER_TARGET AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(_LOCAL_CROSS_TARGET "--target=${CMAKE_CXX_COMPILER_TARGET}")
endif()
add_custom_command(
OUTPUT ${outputFilename}
COMMAND ${CMAKE_CXX_COMPILER} -E -P ${PREPROCESS_DEFINITIONS} ${PREPROCESS_INCLUDE_DIRECTORIES} -o ${outputFilename} -x c ${inputFilename}
COMMAND ${CMAKE_CXX_COMPILER} ${_LOCAL_CROSS_TARGET} -E -P ${PREPROCESS_DEFINITIONS} ${PREPROCESS_INCLUDE_DIRECTORIES} -o ${outputFilename} -x c ${inputFilename}
DEPENDS ${inputFilename}
COMMENT "Preprocessing ${inputFilename}. Outputting to ${outputFilename}"
)
Expand Down
6 changes: 3 additions & 3 deletions eng/pipelines/common/evaluate-default-paths.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ parameters:
src/mono/nuget/Microsoft.NET.Runtime.wasm.Sample.Mono/*
src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/*
src/mono/nuget/Microsoft.NETCore.BrowserDebugHost.Transport/*
src/mono/nuget/Microsoft.NET.Runtime.WorkloadTesting.Internal/*
src/mono/nuget/Microsoft.NET.Runtime.WorkloadTesting.Internal/**/*
src/mono/nuget/Microsoft.NET.Workload*
src/mono/sample/wasm/*
src/mono/browser/*
Expand Down Expand Up @@ -213,7 +213,7 @@ jobs:
- eng/testing/scenarios/BuildWasmAppsJobsList.txt
- eng/testing/tests.browser.targets
- eng/testing/tests.was*.targets
- src/mono/nuget/Microsoft.NET.Runtime.WorkloadTesting.Internal/WorkloadTesting.Core.targets
- src/mono/nuget/Microsoft.NET.Runtime.WorkloadTesting.Internal/Sdk/WorkloadTesting.Core.targets
- eng/testing/workloads-browser.targets
- eng/testing/workloads-testing.targets
- eng/testing/workloads-wasi.targets
Expand Down Expand Up @@ -303,7 +303,7 @@ jobs:
exclude:
- eng/testing/scenarios/BuildWasiAppsJobsList.txt
- eng/testing/scenarios/BuildWasmAppsJobsList.txt
src/mono/nuget/Microsoft.NET.Runtime.WorkloadTesting.Internal/WorkloadTesting.Core.targets
src/mono/nuget/Microsoft.NET.Runtime.WorkloadTesting.Internal/Sdk/WorkloadTesting.Core.targets
- eng/testing/workloads-browser.targets
- eng/testing/workloads-testing.targets
- eng/testing/workloads-wasi.targets
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ internal static void FailFast(string? message, Exception? exception, string? err
[DoesNotReturn]
private static void FailFast(ref StackCrawlMark mark, string? message, Exception? exception, string? errorMessage)
{
FailFast(new StackCrawlMarkHandle(ref mark), new StringHandleOnStack(ref message), ObjectHandleOnStack.Create(ref exception), new StringHandleOnStack(ref errorMessage));
FailFast(new StackCrawlMarkHandle(ref mark), message, ObjectHandleOnStack.Create(ref exception), errorMessage);
}

[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "Environment_FailFast")]
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "Environment_FailFast", StringMarshalling = StringMarshalling.Utf16)]
[DoesNotReturn]
private static partial void FailFast(StackCrawlMarkHandle mark, StringHandleOnStack message, ObjectHandleOnStack exception, StringHandleOnStack errorMessage);
private static partial void FailFast(StackCrawlMarkHandle mark, string? message, ObjectHandleOnStack exception, string? errorMessage);

private static unsafe string[] InitializeCommandLineArgs(char* exePath, int argc, char** argv) // invoked from VM
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ class AsmOffsets

#if TARGET_64BIT
public const int OFFSETOF__REGDISPLAY__m_pCurrentContext = 0x8;
public const int SIZEOF__StackFrameIterator = 0x370;
public const int OFFSETOF__StackFrameIterator__m_isRuntimeWrappedExceptions = 0x352;
public const int OFFSETOF__StackFrameIterator__m_AdjustedControlPC = 0x368;
public const int SIZEOF__StackFrameIterator = 0x358;
public const int OFFSETOF__StackFrameIterator__m_isRuntimeWrappedExceptions = 0x33A;
public const int OFFSETOF__StackFrameIterator__m_AdjustedControlPC = 0x350;
#else // TARGET_64BIT
public const int OFFSETOF__REGDISPLAY__m_pCurrentContext = 0x4;
public const int SIZEOF__StackFrameIterator = 0x2d8;
public const int OFFSETOF__StackFrameIterator__m_isRuntimeWrappedExceptions = 0x2c2;
public const int OFFSETOF__StackFrameIterator__m_AdjustedControlPC = 0x2d0;
public const int SIZEOF__StackFrameIterator = 0x2c8;
public const int OFFSETOF__StackFrameIterator__m_isRuntimeWrappedExceptions = 0x2b6;
public const int OFFSETOF__StackFrameIterator__m_AdjustedControlPC = 0x2c4;
#endif // TARGET_64BIT

#else // DEBUG
Expand Down Expand Up @@ -94,14 +94,14 @@ class AsmOffsets

#if TARGET_64BIT
public const int OFFSETOF__REGDISPLAY__m_pCurrentContext = 0x8;
public const int SIZEOF__StackFrameIterator = 0x370;
public const int OFFSETOF__StackFrameIterator__m_isRuntimeWrappedExceptions = 0x34a;
public const int OFFSETOF__StackFrameIterator__m_AdjustedControlPC = 0x360;
public const int SIZEOF__StackFrameIterator = 0x350;
public const int OFFSETOF__StackFrameIterator__m_isRuntimeWrappedExceptions = 0x332;
public const int OFFSETOF__StackFrameIterator__m_AdjustedControlPC = 0x348;
#else // TARGET_64BIT
public const int OFFSETOF__REGDISPLAY__m_pCurrentContext = 0x4;
public const int SIZEOF__StackFrameIterator = 0x2d0;
public const int OFFSETOF__StackFrameIterator__m_isRuntimeWrappedExceptions = 0x2ba;
public const int OFFSETOF__StackFrameIterator__m_AdjustedControlPC = 0x2c8;
public const int SIZEOF__StackFrameIterator = 0x2c0;
public const int OFFSETOF__StackFrameIterator__m_isRuntimeWrappedExceptions = 0x2ae;
public const int OFFSETOF__StackFrameIterator__m_AdjustedControlPC = 0x2bc;
#endif // TARGET_64BIT

#endif // DEBUG
Expand Down Expand Up @@ -155,7 +155,7 @@ class AsmOffsets
public const int OFFSETOF__ExInfo__m_kind = 0xd0;
public const int OFFSETOF__ExInfo__m_passNumber = 0xd1;
public const int OFFSETOF__ExInfo__m_idxCurClause = 0xd4;
public const int OFFSETOF__ExInfo__m_frameIter = 0xe0;
public const int OFFSETOF__ExInfo__m_frameIter = 0xd8;
public const int OFFSETOF__ExInfo__m_notifyDebuggerSP = OFFSETOF__ExInfo__m_frameIter + SIZEOF__StackFrameIterator;
#else // TARGET_64BIT
public const int SIZEOF__EHEnum = 0x10;
Expand Down
143 changes: 15 additions & 128 deletions src/coreclr/classlibnative/bcltype/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,130 +165,35 @@ static StackWalkAction FindFailFastCallerCallback(CrawlFrame* frame, VOID* data)
return SWA_ABORT;
}

// FailFast is supported in BCL.small as internal to support failing fast in places where EEE used to be thrown.
//
// Static message buffer used by SystemNative::FailFast to avoid reliance on a
// managed string object buffer. This buffer is not always used, see comments in
// the method below.
WCHAR g_szFailFastBuffer[256];
WCHAR *g_pFailFastBuffer = g_szFailFastBuffer;

#define FAIL_FAST_STATIC_BUFFER_LENGTH (sizeof(g_szFailFastBuffer) / sizeof(WCHAR))


// This is the common code for FailFast processing that is wrapped by the
// FailFast FCalls below.
void SystemNative::GenericFailFast(STRINGREF refMesgString, EXCEPTIONREF refExceptionForWatsonBucketing, StackCrawlMark* stackMark, STRINGREF refErrorSourceString)
extern "C" void QCALLTYPE Environment_FailFast(QCall::StackCrawlMarkHandle mark, PCWSTR message, QCall::ObjectHandleOnStack exception, PCWSTR errorSource)
{
CONTRACTL
{
THROWS;
GC_TRIGGERS;
MODE_COOPERATIVE;
}CONTRACTL_END;
QCALL_CONTRACT;

struct
{
STRINGREF refMesgString;
EXCEPTIONREF refExceptionForWatsonBucketing;
STRINGREF refErrorSourceString;
} gc;
gc.refMesgString = refMesgString;
gc.refExceptionForWatsonBucketing = refExceptionForWatsonBucketing;
gc.refErrorSourceString = refErrorSourceString;
BEGIN_QCALL;

GCPROTECT_BEGIN(gc);
GCX_COOP();

FindFailFastCallerStruct findCallerData;
findCallerData.pStackMark = stackMark;
findCallerData.pStackMark = mark;
findCallerData.retAddress = 0;
StackWalkFunctions(GetThread(), FindFailFastCallerCallback, &findCallerData);

// Managed code injected FailFast maps onto the unmanaged version
// (EEPolicy::HandleFatalError) in the following manner: the exit code is
// always set to COR_E_FAILFAST and the address passed (usually a failing
// EIP) is in fact the address of a unicode message buffer (explaining the
// reason for the fault).
// The message string comes from a managed string object so we can't rely on
// the buffer remaining in place below our feet. But equally we don't want
// to inject failure points (by, for example, allocating a heap buffer or a
// pinning handle) when we have a much higher chance than usual of actually
// tripping those failure points and eradicating useful debugging info.
// We employ various strategies to deal with this:
// o If the message is small enough we copy it into a static buffer
// (g_szFailFastBuffer).
// o Otherwise we try to allocate a buffer of the required size on the
// heap. This buffer will be leaked.
// o If the allocation above fails we return to the static buffer and
// truncate the message.
//
// Another option would seem to be to implement a new frame type that
// protects object references as pinned, but that seems like overkill for
// just this problem.
WCHAR *pszMessageBuffer = NULL;
DWORD cchMessage = (gc.refMesgString == NULL) ? 0 : gc.refMesgString->GetStringLength();

WCHAR * errorSourceString = NULL;

if (gc.refErrorSourceString != NULL)
{
DWORD cchErrorSource = gc.refErrorSourceString->GetStringLength();
errorSourceString = new (nothrow) WCHAR[cchErrorSource + 1];

if (errorSourceString != NULL)
{
memcpyNoGCRefs(errorSourceString, gc.refErrorSourceString->GetBuffer(), cchErrorSource * sizeof(WCHAR));
errorSourceString[cchErrorSource] = W('\0');
}
}

if (cchMessage < FAIL_FAST_STATIC_BUFFER_LENGTH)
{
// The static buffer can be used only once to avoid race condition with other threads
pszMessageBuffer = InterlockedExchangeT(&g_pFailFastBuffer, NULL);
}

if (pszMessageBuffer == NULL)
{
// We can fail here, but we can handle the fault.
CONTRACT_VIOLATION(FaultViolation);
pszMessageBuffer = new (nothrow) WCHAR[cchMessage + 1];
if (pszMessageBuffer == NULL)
{
// Truncate the message to what will fit in the static buffer.
cchMessage = FAIL_FAST_STATIC_BUFFER_LENGTH - 1;
pszMessageBuffer = InterlockedExchangeT(&g_pFailFastBuffer, NULL);
}
}
GetThread()->StackWalkFrames(FindFailFastCallerCallback, &findCallerData, FUNCTIONSONLY | QUICKUNWIND);

const WCHAR *pszMessage;
if (pszMessageBuffer != NULL)
if (message == NULL || message[0] == W('\0'))
{
if (cchMessage > 0)
memcpyNoGCRefs(pszMessageBuffer, gc.refMesgString->GetBuffer(), cchMessage * sizeof(WCHAR));
pszMessageBuffer[cchMessage] = W('\0');
pszMessage = pszMessageBuffer;
WszOutputDebugString(W("CLR: Managed code called FailFast without specifying a reason.\r\n"));
}
else
{
pszMessage = W("There is not enough memory to print the supplied FailFast message.");
cchMessage = (DWORD)u16_strlen(pszMessage);
}

if (cchMessage == 0) {
WszOutputDebugString(W("CLR: Managed code called FailFast without specifying a reason.\r\n"));
}
else {
WszOutputDebugString(W("CLR: Managed code called FailFast.\r\n"));
WszOutputDebugString(pszMessage);
WszOutputDebugString(message);
WszOutputDebugString(W("\r\n"));
}

LPCWSTR argExceptionString = NULL;
StackSString msg;
if (gc.refExceptionForWatsonBucketing != NULL)
if (exception.Get() != NULL)
{
GetExceptionMessage(gc.refExceptionForWatsonBucketing, msg);
GetExceptionMessage(exception.Get(), msg);
argExceptionString = msg.GetUnicode();
}

Expand All @@ -301,7 +206,7 @@ void SystemNative::GenericFailFast(STRINGREF refMesgString, EXCEPTIONREF refExce
// skip this, if required.
if (IsWatsonEnabled())
{
if ((gc.refExceptionForWatsonBucketing == NULL) || !SetupWatsonBucketsForFailFast(gc.refExceptionForWatsonBucketing))
if ((exception.Get() == NULL) || !SetupWatsonBucketsForFailFast((EXCEPTIONREF)exception.Get()))
{
PTR_EHWatsonBucketTracker pUEWatsonBucketTracker = pThread->GetExceptionState()->GetUEWatsonBucketTracker();
_ASSERTE(pUEWatsonBucketTracker != NULL);
Expand All @@ -317,28 +222,10 @@ void SystemNative::GenericFailFast(STRINGREF refMesgString, EXCEPTIONREF refExce

// stash the user-provided exception object. this will be used as
// the inner exception object to the FatalExecutionEngineException.
if (gc.refExceptionForWatsonBucketing != NULL)
pThread->SetLastThrownObject(gc.refExceptionForWatsonBucketing);

EEPolicy::HandleFatalError(COR_E_FAILFAST, findCallerData.retAddress, pszMessage, NULL, errorSourceString, argExceptionString);

GCPROTECT_END();
}

extern "C" void QCALLTYPE Environment_FailFast(QCall::StackCrawlMarkHandle mark, QCall::StringHandleOnStack message, QCall::ObjectHandleOnStack exception, QCall::StringHandleOnStack errorSource)
{
QCALL_CONTRACT;

BEGIN_QCALL;

GCX_COOP();

STRINGREF refMessage = message.Get();
EXCEPTIONREF refException = (EXCEPTIONREF)exception.Get();
STRINGREF refErrorSource = errorSource.Get();
if (exception.Get() != NULL)
pThread->SetLastThrownObject(exception.Get());

// Call the actual worker to perform failfast
SystemNative::GenericFailFast(refMessage, refException, mark, refErrorSource);
EEPolicy::HandleFatalError(COR_E_FAILFAST, findCallerData.retAddress, message, NULL, errorSource, argExceptionString);

END_QCALL;
}
Expand Down
5 changes: 1 addition & 4 deletions src/coreclr/classlibnative/bcltype/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,11 @@ class SystemNative

// Return a method info for the method were the exception was thrown
static FCDECL1(ReflectMethodObject*, GetMethodFromStackTrace, ArrayBase* pStackTraceUNSAFE);

// Common processing code for FailFast
static void GenericFailFast(STRINGREF refMesgString, EXCEPTIONREF refExceptionForWatsonBucketing, StackCrawlMark* stackCrawlMark, STRINGREF errorSource);
};

extern "C" void QCALLTYPE Environment_Exit(INT32 exitcode);

extern "C" void QCALLTYPE Environment_FailFast(QCall::StackCrawlMarkHandle mark, QCall::StringHandleOnStack message, QCall::ObjectHandleOnStack exception, QCall::StringHandleOnStack errorSource);
extern "C" void QCALLTYPE Environment_FailFast(QCall::StackCrawlMarkHandle mark, PCWSTR message, QCall::ObjectHandleOnStack exception, PCWSTR errorSource);

// Returns the number of logical processors that can be used by managed code
extern "C" INT32 QCALLTYPE Environment_GetProcessorCount();
Expand Down
5 changes: 1 addition & 4 deletions src/coreclr/inc/CrstTypes.def
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ Crst PendingTypeLoadEntry
DomainLocalBlock Exception ExecuteManRangeLock FuncPtrStubs
FusionAppCtx GlobalStrLiteralMap HandleTable IbcProfile
IJWFixupData IJWHash ISymUnmanagedReader Jit JumpStubCache LoaderHeap
Module ModuleLookupTable PEImage SecurityStackwalkCache
Module ModuleLookupTable PEImage
SigConvert SingleUseLock StubDispatchCache StubUnwindInfoHeapSegments
SyncBlockCache SystemDomain ThreadIdDispenser ThreadStore TypeIDMap UnresolvedClassLock
SameLevelAs PendingTypeLoadEntry
Expand Down Expand Up @@ -426,9 +426,6 @@ End
Crst SaveModuleProfileData
End

Crst SecurityStackwalkCache
End

Crst SigConvert
AcquiredBefore LoaderHeap
End
Expand Down
Loading

0 comments on commit 2446b93

Please sign in to comment.