Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix exception leaking from filter in nativeAOT #85366

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -850,8 +850,17 @@ private static bool FindFirstPassHandler(object exception, uint idxStart,
else
{
byte* pFilterFunclet = ehClause._filterAddress;
bool shouldInvokeHandler =
InternalCalls.RhpCallFilterFunclet(exception, pFilterFunclet, frameIter.RegisterSet);

bool shouldInvokeHandler = false;
try
{
shouldInvokeHandler =
InternalCalls.RhpCallFilterFunclet(exception, pFilterFunclet, frameIter.RegisterSet);
}
catch when (true)
janvorli marked this conversation as resolved.
Show resolved Hide resolved
{
// Prevent leaking any exception from the filter funclet
}

if (shouldInvokeHandler)
{
Expand Down
39 changes: 30 additions & 9 deletions src/coreclr/nativeaot/Runtime/StackFrameIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,8 @@ void StackFrameIterator::UnwindFuncletInvokeThunk()
#if defined(USE_PORTABLE_HELPERS) // @TODO: Currently no funclet invoke defined in a portable way
return;
#else // defined(USE_PORTABLE_HELPERS)
ASSERT(CategorizeUnadjustedReturnAddress(m_ControlPC) == InFuncletInvokeThunk);
ASSERT((CategorizeUnadjustedReturnAddress(m_ControlPC) == InFuncletInvokeThunk) ||
(CategorizeUnadjustedReturnAddress(m_ControlPC) == InFilterFuncletInvokeThunk));

PTR_UIntNative SP;

Expand Down Expand Up @@ -1512,6 +1513,12 @@ void StackFrameIterator::NextInternal()
exCollide = true;
}
}
else if (category == InFilterFuncletInvokeThunk)
{
// Unwind through the funclet invoke assembly thunk to reach the topmost managed frame in
// the exception dispatch code.
UnwindFuncletInvokeThunk();
}
else if (category == InManagedCode)
{
// Non-exceptionally invoked funclet case. The caller is processed as a normal managed
Expand Down Expand Up @@ -1932,19 +1939,33 @@ StackFrameIterator::ReturnAddressCategory StackFrameIterator::CategorizeUnadjust
return InThrowSiteThunk;
}

if (
#ifdef TARGET_X86
EQUALS_RETURN_ADDRESS(returnAddress, RhpCallFunclet2)
#else
EQUALS_RETURN_ADDRESS(returnAddress, RhpCallCatchFunclet2) ||
EQUALS_RETURN_ADDRESS(returnAddress, RhpCallFinallyFunclet2) ||
EQUALS_RETURN_ADDRESS(returnAddress, RhpCallFilterFunclet2)
#endif
)
if (EQUALS_RETURN_ADDRESS(returnAddress, RhpCallFunclet2))
{
// See if it is a filter funclet based on the caller of RhpCallFunclet
PTR_UIntNative SP = (PTR_UIntNative)(m_RegDisplay.SP + 0x4); // skip the saved assembly-routine-EBP
PTR_UIntNative ControlPC = *SP++;
if (EQUALS_RETURN_ADDRESS(ControlPC, RhpCallFilterFunclet2))
{
return InFilterFuncletInvokeThunk;
}
else
{
return InFuncletInvokeThunk;
}
}
#else // TARGET_X86
if (EQUALS_RETURN_ADDRESS(returnAddress, RhpCallCatchFunclet2) ||
EQUALS_RETURN_ADDRESS(returnAddress, RhpCallFinallyFunclet2))
{
return InFuncletInvokeThunk;
}

if (EQUALS_RETURN_ADDRESS(returnAddress, RhpCallFilterFunclet2))
{
return InFilterFuncletInvokeThunk;
}
#endif // TARGET_X86
return InManagedCode;
#endif // defined(USE_PORTABLE_HELPERS)
}
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/nativeaot/Runtime/StackFrameIterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class StackFrameIterator
InManagedCode,
InThrowSiteThunk,
InFuncletInvokeThunk,
InFilterFuncletInvokeThunk,
InCallDescrThunk,
InUniversalTransitionThunk,
};
Expand Down
12 changes: 0 additions & 12 deletions src/tests/issues.targets
Original file line number Diff line number Diff line change
Expand Up @@ -1150,12 +1150,6 @@
<ExcludeList Include="$(XunitTestBinBase)/JIT/Methodical/Arrays/misc/initializearray_il_r/*">
<Issue>https://github.com/dotnet/runtimelab/issues/155: RuntimeHelpers.InitializeArray</Issue>
</ExcludeList>
<ExcludeList Include="$(XunitTestBinBase)/JIT/Methodical/eh/basics/throwinfilter_il_d/*">
<Issue>https://github.com/dotnet/runtimelab/issues/188</Issue>
</ExcludeList>
<ExcludeList Include="$(XunitTestBinBase)/JIT/Methodical/eh/basics/throwinfilter_il_r/*">
<Issue>https://github.com/dotnet/runtimelab/issues/188</Issue>
</ExcludeList>
<ExcludeList Include="$(XunitTestBinBase)/JIT/Methodical/eh/interactions/throw1dimarray_il_d/*">
<Issue>https://github.com/dotnet/runtimelab/issues/155: Non-exception throw</Issue>
</ExcludeList>
Expand Down Expand Up @@ -1201,9 +1195,6 @@
<ExcludeList Include="$(XunitTestBinBase)/JIT/Performance/CodeQuality/Serialization/Serialize/*">
<Issue>Needs xunit.performance</Issue>
</ExcludeList>
<ExcludeList Include="$(XunitTestBinBase)/JIT/Regression/CLR-x86-JIT/V1-M12-Beta2/b68872/b68872/*">
<Issue>https://github.com/dotnet/runtimelab/issues/188</Issue>
</ExcludeList>
<ExcludeList Include = "$(XunitTestBinBase)/JIT/Regression/CLR-x86-JIT/V1-M12-Beta2/b71120/b71120/**">
<Issue>https://github.com/dotnet/runtimelab/issues/155: Varargs</Issue>
</ExcludeList>
Expand All @@ -1228,9 +1219,6 @@
<ExcludeList Include="$(XunitTestBinBase)/JIT/Regression/JitBlue/GitHub_35384/GitHub_35384/*">
<Issue>https://github.com/dotnet/runtimelab/issues/198</Issue>
</ExcludeList>
<ExcludeList Include="$(XunitTestBinBase)/JIT/Regression/JitBlue/GitHub_4044/GitHub_4044/*">
<Issue>https://github.com/dotnet/runtimelab/issues/188</Issue>
</ExcludeList>
<ExcludeList Include="$(XunitTestBinBase)/JIT/Regression/JitBlue/Runtime_71375/*">
<Issue>https://github.com/dotnet/runtimelab/issues/155: Varargs</Issue>
</ExcludeList>
Expand Down