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
Next Next commit
Lock all of CaptureDispatchState
  • Loading branch information
Steve Pfister committed Jun 21, 2022
commit 5fe7d36573257cb9cde5beea60602610c8361be2
44 changes: 19 additions & 25 deletions src/mono/System.Private.CoreLib/src/System/Exception.Mono.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,37 +68,31 @@ internal DispatchState CaptureDispatchState()
{
MonoStackFrame[]? stackFrames;

if (_traceIPs != null)
// 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)
{
stackFrames = Diagnostics.StackTrace.get_trace(this, 0, true);
if (stackFrames.Length > 0)
stackFrames[stackFrames.Length - 1].isLastFrameFromForeignException = true;

if (foreignExceptionsFrames != null)
if (_traceIPs != null)
{
MonoStackFrame[] combinedStackFrames;
int fefLength;

// 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)
stackFrames = Diagnostics.StackTrace.get_trace(this, 0, true);
if (stackFrames.Length > 0)
stackFrames[stackFrames.Length - 1].isLastFrameFromForeignException = true;

if (foreignExceptionsFrames != null)
{
fefLength = foreignExceptionsFrames.Length;
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);

combinedStackFrames = new MonoStackFrame[stackFrames.Length + fefLength];
Array.Copy(foreignExceptionsFrames, 0, combinedStackFrames, 0, fefLength);
stackFrames = combinedStackFrames;
}

Array.Copy(stackFrames, 0, combinedStackFrames, fefLength, stackFrames.Length);

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

return new DispatchState(stackFrames);
Expand Down