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
11 changes: 11 additions & 0 deletions src/coreclr/vm/exceptionhandling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,17 @@ ProcessCLRException(IN PEXCEPTION_RECORD pExceptionRecord,
else
{
void *sp = (void*)GetSP(pContextRecord);
#ifdef FEATURE_HIJACK
Frame* pFrame = pThread->GetFrame();
if ((pFrame < sp) && (pFrame->GetFrameIdentifier() == FrameIdentifier::RedirectedThreadFrame))
{
// The exception came from a thread interrupted in managed code, so this context
// points to the interrupted instruction, not a return address.
_ASSERTE(GetSP(static_cast<RedirectedThreadFrame*>(pFrame)->GetContext()) == GetSP(pContextRecord));
_ASSERTE(GetIP(static_cast<RedirectedThreadFrame*>(pFrame)->GetContext()) == GetIP(pContextRecord));
pContextRecord->ContextFlags |= CONTEXT_EXCEPTION_ACTIVE;
}
#endif
PopExplicitFrames(pThread, sp, NULL /* targetCallerSp */, false /* popGCFrames */);
ExInfo::PopExInfos(pThread, sp);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// 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.Threading;
using System.Threading.Tasks;
using Microsoft.DotNet.RemoteExecutor;
Expand Down Expand Up @@ -98,6 +99,41 @@ public void CancelRepeatedlyOnSameThread()
}).Dispose();
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsCoreCLR), nameof(PlatformDetection.IsX64Process))]
[PlatformSpecific(TestPlatforms.Windows)]
public void CancelAtStartOfTryRunsHandlers()
{
using var cts = new CancellationTokenSource();
RunTest(() => SpinInTry(cts), cts.Token);

Assert.IsType<OperationCanceledException>(_exception);
Assert.True(_finishedExecution);
Assert.True(_caughtException);

[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
void SpinInTry(CancellationTokenSource source)
{
source.CancelAfter(100);
try
{
try
{
// The loop is a single backward branch at the start of the inner try.
while (true) { }
}
finally
{
_finishedExecution = true;
}
}
catch (ThreadAbortException)
{
_caughtException = true;
throw;
}
}
}

// Tests that an infinite loop may be aborted, that the ThreadAbortException is automatically rethrown,
// and that it is eventually translated to an OperationCanceledException.
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotMonoRuntime), nameof(PlatformDetection.IsNotNativeAot), nameof(PlatformDetection.IsMultithreadingSupported))]
Expand Down
Loading