Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ EXTERN_C void QCALLTYPE NativeRuntimeEventSource_LogThreadPoolIOPack(void * Nati
{
}

EXTERN_C void QCALLTYPE NativeRuntimeEventSource_LogExceptionThrown(const WCHAR* exceptionTypeName, const WCHAR* exceptionMessage, void* faultingIP, HRESULT hresult)
EXTERN_C void QCALLTYPE NativeRuntimeEventSource_LogExceptionThrown(const WCHAR* exceptionTypeName, const WCHAR* exceptionMessage, void* faultingIP, HRESULT hresult, uint16_t flags, uint16_t ClrInstanceID)
{
}

Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/nativeaot/Runtime/runtimeeventinternal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ EXTERN_C void QCALLTYPE NativeRuntimeEventSource_LogThreadPoolIOPack(void * Nati
FireEtwThreadPoolIOPack(NativeOverlapped, Overlapped, ClrInstanceID);
}

EXTERN_C void QCALLTYPE NativeRuntimeEventSource_LogExceptionThrown(const WCHAR* exceptionTypeName, const WCHAR* exceptionMessage, void* faultingIP, HRESULT hresult)
EXTERN_C void QCALLTYPE NativeRuntimeEventSource_LogExceptionThrown(const WCHAR* exceptionTypeName, const WCHAR* exceptionMessage, void* faultingIP, HRESULT hresult, uint16_t flags, uint16_t ClrInstanceID)
{
FireEtwExceptionThrown_V1(exceptionTypeName,
exceptionMessage,
faultingIP,
hresult,
0,
GetClrInstanceId());
flags,
ClrInstanceID);
}

EXTERN_C void QCALLTYPE NativeRuntimeEventSource_LogWaitHandleWaitStart(uint8_t WaitSource, intptr_t AssociatedObjectID, uint16_t ClrInstanceID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Tracing;
using System.Runtime;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -136,17 +137,13 @@ private static void AppendExceptionStackFrame(object exceptionObj, IntPtr IP, in
ex.AppendStackIP(IP, isFirstRethrowFrame);

#if FEATURE_PERFTRACING
if (isFirstFrame)
if (isFirstFrame && NativeRuntimeEventSource.Log.IsEnabled())
{
string typeName = !fatalOutOfMemory ? ex.GetType().ToString() : "System.OutOfMemoryException";
string message = !fatalOutOfMemory ? ex.Message :
"Insufficient memory to continue the execution of the program.";

unsafe
{
fixed (char* exceptionTypeName = typeName, exceptionMessage = message)
RuntimeImports.NativeRuntimeEventSource_LogExceptionThrown(exceptionTypeName, exceptionMessage, IP, ex.HResult);
}
NativeRuntimeEventSource.Log.ExceptionThrown_V1(typeName, message, IP, (uint)ex.HResult, 0);
}
#endif
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -673,11 +673,6 @@ internal static IntPtr RhGetModuleSection(TypeManagerHandle module, ReadyToRunSe
[RuntimeImport(RuntimeLibrary, "RhUnregisterForGCReporting")]
internal static extern unsafe void RhUnregisterForGCReporting(GCFrameRegistration* pRegistration);

#if FEATURE_PERFTRACING
[LibraryImport(RuntimeLibrary)]
internal static unsafe partial void NativeRuntimeEventSource_LogExceptionThrown(char* exceptionTypeName, char* exceptionMessage, IntPtr faultingIP, int hresult);
#endif // FEATURE_PERFTRACING

//
// Interlocked helpers
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,10 @@ private static bool IsEventManuallyHandled(string eventName)
// Some threading events are defined manually in NativeRuntimeEventSource.Threading.cs
"ThreadPool",
"Contention",
"WaitHandle"
"WaitHandle",

// Exception event defined manually in NativeRuntimeEventSource.Exceptions.cs
"ExceptionThrown_V1",
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1585,6 +1585,8 @@
<Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\IncrementingEventCounter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\IncrementingPollingCounter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\NativeRuntimeEventSource.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\NativeRuntimeEventSource.Exceptions.NativeSinks.cs" Condition="'$(FeaturePerfTracing)' == 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\NativeRuntimeEventSource.Exceptions.NativeSinks.Internal.cs" Condition="'$(FeaturePerfTracing)' == 'true' and '$(FeatureNativeAot)' == 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\NativeRuntimeEventSource.Threading.cs" Condition="'$(FeaturePerfTracing)' != 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\NativeRuntimeEventSource.Threading.NativeSinks.cs" Condition="'$(FeaturePerfTracing)' == 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\NativeRuntimeEventSource.Threading.NativeSinks.Internal.cs" Condition="'$(FeaturePerfTracing)' == 'true' and '$(FeatureMono)' != 'true'" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace System.Diagnostics.Tracing
{
// This is part of the NativeRuntimeEventsource, which is the managed version of the Microsoft-Windows-DotNETRuntime provider.
// It contains the runtime specific interop to native event sinks.
internal sealed partial class NativeRuntimeEventSource : EventSource
{
[NonEvent]
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "NativeRuntimeEventSource_LogExceptionThrown", StringMarshalling = StringMarshalling.Utf16)]
private static unsafe partial void LogExceptionThrown(string exceptionTypeName, string exceptionMessage, IntPtr faultingIP, uint hresult, ushort flags, ushort ClrInstanceID);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Threading;

namespace System.Diagnostics.Tracing
{
// This is part of the NativeRuntimeEventsource, which is the managed version of the Microsoft-Windows-DotNETRuntime provider.
// It contains the handwritten implementation of exception events.
// The events here do not call into the typical WriteEvent* APIs unlike most EventSources because that results in the
// events to be forwarded to EventListeners twice, once directly from the managed WriteEvent API, and another time
// from the mechanism in NativeRuntimeEventSource.ProcessEvents that forwards native runtime events to EventListeners.
// To prevent this, these events call directly into QCalls provided by the runtime (refer to NativeRuntimeEventSource.cs) which call
// FireEtw* methods auto-generated from ClrEtwAll.man. This ensures that corresponding event sinks are being used
// for the native platform.
[SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "NativeRuntimeEventSource is a special case where event methods don't use WriteEvent/WriteEventCore but still need to be instance methods.")]
internal sealed partial class NativeRuntimeEventSource : EventSource
{
[Event(80, Version = 1, Level = EventLevel.Error, Keywords = Keywords.ExceptionKeyword | Keywords.MonitoringKeyword)]
public void ExceptionThrown_V1(string ExceptionType, string ExceptionMessage, IntPtr ExceptionEIP, uint ExceptionHRESULT, ushort ExceptionFlags, ushort ClrInstanceID = DefaultClrInstanceId)
{
#if NATIVEAOT
if (!IsEnabled(EventLevel.Error, Keywords.ExceptionKeyword | Keywords.MonitoringKeyword))
{
return;
}
LogExceptionThrown(ExceptionType, ExceptionMessage, ExceptionEIP, ExceptionHRESULT, ExceptionFlags, ClrInstanceID);
#else
// QCall not implemented elsewhere
throw new NotImplementedException();
#endif
}
}
}
Loading