Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/coreclr/vm/excep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7504,7 +7504,7 @@ VOID DECLSPEC_NORETURN UnwindAndContinueRethrowHelperAfterCatch(Frame* pEntryFra
}
else
{
DispatchManagedException(orThrowable, /* preserveStackTrace */ false);
DispatchManagedException(orThrowable);
}
}
else
Expand Down
17 changes: 5 additions & 12 deletions src/coreclr/vm/exceptionhandling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,7 @@ ProcessCLRExceptionNew(IN PEXCEPTION_RECORD pExceptionRecord,
else
{
OBJECTREF oref = ExceptionTracker::CreateThrowable(pExceptionRecord, FALSE);
DispatchManagedException(oref, pContextRecord, /* preserveStackTrace */ false);
DispatchManagedException(oref, pContextRecord);
}
}
#endif // !HOST_UNIX
Expand Down Expand Up @@ -5649,7 +5649,7 @@ void FirstChanceExceptionNotification()
#endif // TARGET_UNIX
}

VOID DECLSPEC_NORETURN DispatchManagedException(OBJECTREF throwable, CONTEXT* pExceptionContext, bool preserveStackTrace)
VOID DECLSPEC_NORETURN DispatchManagedException(OBJECTREF throwable, CONTEXT* pExceptionContext)
{
STATIC_CONTRACT_THROWS;
STATIC_CONTRACT_GC_TRIGGERS;
Expand All @@ -5661,19 +5661,12 @@ VOID DECLSPEC_NORETURN DispatchManagedException(OBJECTREF throwable, CONTEXT* pE

Thread *pThread = GetThread();

if (preserveStackTrace)
{
pThread->IncPreventAbort();
ExceptionPreserveStackTrace(throwable);
Copy link
Member

@jkotas jkotas Aug 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering whether the one remaining use of ExceptionPreserveStackTrace in the VM is actually necessary. It is wrapped in very confusing logic that does not look right and we seem to be getting lucky that it never kicks in practice.

It is fine to clean it up in a separate PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, I'll look into it separately.

pThread->DecPreventAbort();
}

ULONG_PTR hr = GetHRFromThrowable(throwable);

EXCEPTION_RECORD exceptionRecord;
exceptionRecord.ExceptionCode = EXCEPTION_COMPLUS;
exceptionRecord.ExceptionFlags = EXCEPTION_NONCONTINUABLE | EXCEPTION_SOFTWARE_ORIGINATE;
exceptionRecord.ExceptionAddress = (void *)(void (*)(OBJECTREF, bool))&DispatchManagedException;
exceptionRecord.ExceptionAddress = (void *)(void (*)(OBJECTREF))&DispatchManagedException;
exceptionRecord.NumberParameters = MarkAsThrownByUs(exceptionRecord.ExceptionInformation, hr);
exceptionRecord.ExceptionRecord = NULL;

Expand Down Expand Up @@ -5709,7 +5702,7 @@ VOID DECLSPEC_NORETURN DispatchManagedException(OBJECTREF throwable, CONTEXT* pE
UNREACHABLE();
}

VOID DECLSPEC_NORETURN DispatchManagedException(OBJECTREF throwable, bool preserveStackTrace)
VOID DECLSPEC_NORETURN DispatchManagedException(OBJECTREF throwable)
{
STATIC_CONTRACT_THROWS;
STATIC_CONTRACT_GC_TRIGGERS;
Expand All @@ -5718,7 +5711,7 @@ VOID DECLSPEC_NORETURN DispatchManagedException(OBJECTREF throwable, bool preser
CONTEXT exceptionContext;
RtlCaptureContext(&exceptionContext);

DispatchManagedException(throwable, &exceptionContext, preserveStackTrace);
DispatchManagedException(throwable, &exceptionContext);
UNREACHABLE();
}

Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/vm/exceptionhandling.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ ProcessCLRException(IN PEXCEPTION_RECORD pExceptionRecord,
IN OUT PT_CONTEXT pContextRecord,
IN OUT PT_DISPATCHER_CONTEXT pDispatcherContext);

VOID DECLSPEC_NORETURN DispatchManagedException(OBJECTREF throwable, CONTEXT *pExceptionContext, bool preserveStackTrace = true);
VOID DECLSPEC_NORETURN DispatchManagedException(OBJECTREF throwable, bool preserveStackTrace = true);
VOID DECLSPEC_NORETURN DispatchManagedException(OBJECTREF throwable, CONTEXT *pExceptionContext);
VOID DECLSPEC_NORETURN DispatchManagedException(OBJECTREF throwable);
VOID DECLSPEC_NORETURN DispatchManagedException(RuntimeExceptionKind reKind);

enum CLRUnwindStatus { UnwindPending, FirstPassComplete, SecondPassComplete };
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/jithelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3031,7 +3031,7 @@ void ThrowNew(OBJECTREF oref)
}
}

DispatchManagedException(oref, /* preserveStackTrace */ false);
DispatchManagedException(oref);
}
#endif // FEATURE_EH_FUNCLETS

Expand Down