-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a test for handling SEH exceptions.
- Loading branch information
Esme Povirk
committed
Sep 4, 2021
1 parent
bc7c994
commit 24c54fd
Showing
4 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters