Skip to content
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
Prev Previous commit
Marek's feedback
  • Loading branch information
Steve Pfister committed Jun 22, 2022
commit 5521f8befe36605ddc379299ba3cd4fcc303da98
53 changes: 23 additions & 30 deletions src/mono/System.Private.CoreLib/src/System/Exception.Mono.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,46 +68,39 @@ internal DispatchState CaptureDispatchState()
{
MonoStackFrame[]? stackFrames;

// Make sure foreignExceptionFrames does not change at this point.
// Otherwise, the Array.Copy into combinedStackFrames can fail due to size differences
//
// See https://github.com/dotnet/runtime/issues/70081
lock(frameLock)
if (_traceIPs != null)
{
if (_traceIPs != null)
{
stackFrames = Diagnostics.StackTrace.get_trace(this, 0, true);
if (stackFrames.Length > 0)
stackFrames[stackFrames.Length - 1].isLastFrameFromForeignException = true;

if (foreignExceptionsFrames != null)
{
var combinedStackFrames = new MonoStackFrame[stackFrames.Length + foreignExceptionsFrames.Length];
Array.Copy(foreignExceptionsFrames, 0, combinedStackFrames, 0, foreignExceptionsFrames.Length);
Array.Copy(stackFrames, 0, combinedStackFrames, foreignExceptionsFrames.Length, stackFrames.Length);

stackFrames = combinedStackFrames;
}
}
else
stackFrames = Diagnostics.StackTrace.get_trace(this, 0, true);
if (stackFrames.Length > 0)
stackFrames[stackFrames.Length - 1].isLastFrameFromForeignException = true;

// Make sure foreignExceptionsFrames does not change at this point.
// Otherwise, the Array.Copy into combinedStackFrames can fail due to size differences
//
// See https://github.com/dotnet/runtime/issues/70081
MonoStackFrame[]? feFrames = foreignExceptionsFrames;

if (feFrames != null)
{
stackFrames = foreignExceptionsFrames;
var combinedStackFrames = new MonoStackFrame[stackFrames.Length + feFrames.Length];
Array.Copy(feFrames, 0, combinedStackFrames, 0, feFrames.Length);
Array.Copy(stackFrames, 0, combinedStackFrames, feFrames.Length, stackFrames.Length);

stackFrames = combinedStackFrames;
}
}
else
{
stackFrames = foreignExceptionsFrames;
}

return new DispatchState(stackFrames);
}

internal void RestoreDispatchState(in DispatchState state)
{
// Isolate so we can safely update foreignExceptionFrames and CaptureDispatchState can read the correct values
//
// See https://github.com/dotnet/runtime/issues/70081
lock(frameLock)
{
foreignExceptionsFrames = state.StackFrames;
_stackTraceString = null;
}
foreignExceptionsFrames = state.StackFrames;
_stackTraceString = null;
}

// Returns true if setting the _remoteStackTraceString field is legal, false if not (immutable exception).
Expand Down