Skip to content

Commit

Permalink
Add a test for handling SEH exceptions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Esme Povirk committed Sep 4, 2021
1 parent bc7c994 commit 24c54fd
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions tools/run-tests/windows-passing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75574,6 +75574,7 @@ unmanaged-configpath
dllimport-preload
dllimport-cctor
valist
seh
# unreliable:
x86.thread-exit
MonoTests.System.Threading.Tasks.TaskTests:DoubleWaitTest
Expand Down
1 change: 1 addition & 0 deletions tools/run-tests/wine-failing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1752,6 +1752,7 @@ mixedmode-dllimport-usedlldirectory
MonoTests.System.ServiceModel.CallbackBehaviorAttributeTest:CallbackExample2
MonoTests.System.ServiceModel.CallbackBehaviorAttributeTest:ConcurrencyModeSingleAndCallbackInsideServiceMethod
unmanaged-configpath
seh
# definitely unreliable:
delegate2
x86_64.MonoTests.System.Threading.ThreadLocalTests:DisposeOnThreadExit
Expand Down
57 changes: 57 additions & 0 deletions tools/tests/seh.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;
using System.Text;

static class TestSeh
{
[DllImport("kernel32")]
extern static void RaiseException(uint code, int flags, int argc, [In] IntPtr[] arguments);

[DllImport("msvcrt", CallingConvention=CallingConvention.Cdecl)]
extern static IntPtr memcpy(IntPtr dest, IntPtr src, IntPtr count);

[HandleProcessCorruptedStateExceptions]
public static int Main()
{
bool got_exception = false;
try
{
RaiseException(0x88888888, 0, 0, null);
}
catch (SEHException)
{
Console.WriteLine("1");
got_exception = true;
}
if (!got_exception)
return 1;

got_exception = false;
try
{
RaiseException(0xc0000017, 0, 0, null);
}
catch (OutOfMemoryException)
{
Console.WriteLine("2");
got_exception = true;
}
if (!got_exception)
return 2;

got_exception = false;
try
{
memcpy(IntPtr.Zero, IntPtr.Zero, new IntPtr(1));
}
catch (AccessViolationException)
{
Console.WriteLine("3");
got_exception = true;
}
if (!got_exception)
return 3;
return 0;
}
}
1 change: 1 addition & 0 deletions tools/tests/tests.make
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ TEST_CS_EXE_SRCS = \
rcw-visible.cs \
releasebadptr.cs \
runtimeinterface.cs \
seh.cs \
thread-exit-bk.cs \
unmanaged-configpath.cs \
valist.cs \
Expand Down

0 comments on commit 24c54fd

Please sign in to comment.