1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Runtime.InteropServices;
internal partial class Interop
{
internal enum Constants : uint
{
WaitObject0 = 0x0u,
FailFastGenerateExceptionAddress = 0x1u,
ExceptionNonContinuable = 0x1u,
CreateMutexInitialOwner = 0x1u,
CreateEventManualReset = 0x1u,
CreateEventInitialSet = 0x2u,
SemaphoreModifyState = 0x2u,
EventModifyState = 0x2u,
DuplicateSameAccess = 0x2u,
CreateSuspended = 0x4u,
WaitAbandoned0 = 0x80u,
WaitTimeout = 0x102u,
StackSizeParamIsAReservation = 0x10000u,
WaitFailed = 0xFFFFFFFFu,
}
// MCG doesn't currently support constants that are not uint.
internal static IntPtr InvalidHandleValue => new IntPtr(-1);
#pragma warning disable 649
internal unsafe struct _EXCEPTION_RECORD
{
internal uint ExceptionCode;
internal uint ExceptionFlags;
internal IntPtr ExceptionRecord;
internal IntPtr ExceptionAddress;
internal uint NumberParameters;
#if BIT64
internal fixed ulong ExceptionInformation[15];
#else
internal fixed uint ExceptionInformation[15];
#endif
}
#pragma warning restore 649
internal partial class mincore
{
[DllImport("api-ms-win-core-debug-l1-1-0.dll", EntryPoint = "IsDebuggerPresent", CharSet = CharSet.Unicode)]
internal extern static bool IsDebuggerPresent();
[DllImport("api-ms-win-core-debug-l1-1-0.dll", EntryPoint = "OutputDebugStringW", CharSet = CharSet.Unicode)]
internal extern static void OutputDebugString(string lpOutputString);
//
// Wrapper for calling RaiseFailFastException
//
internal static unsafe void ExitProcess(uint exitCode)
{
_EXCEPTION_RECORD exceptionRecord;
exceptionRecord.ExceptionCode = exitCode;
exceptionRecord.ExceptionFlags = (uint)Constants.ExceptionNonContinuable;
exceptionRecord.ExceptionRecord = IntPtr.Zero;
exceptionRecord.ExceptionAddress = IntPtr.Zero;
exceptionRecord.NumberParameters = 0;
// don't care about exceptionRecord.ExceptionInformation as we set exceptionRecord.NumberParameters to zero
PInvoke_RaiseFailFastException(
&exceptionRecord,
IntPtr.Zero,
(uint)Constants.FailFastGenerateExceptionAddress);
}
//
// Wrapper for calling RaiseFailFastException
//
internal static unsafe void RaiseFailFastException(uint faultCode, IntPtr pExAddress, IntPtr pExContext)
{
_EXCEPTION_RECORD exceptionRecord;
exceptionRecord.ExceptionCode = faultCode;
exceptionRecord.ExceptionFlags = (uint)Constants.ExceptionNonContinuable;
exceptionRecord.ExceptionRecord = IntPtr.Zero;
exceptionRecord.ExceptionAddress = pExAddress;
exceptionRecord.NumberParameters = 0;
// don't care about exceptionRecord.ExceptionInformation as we set exceptionRecord.NumberParameters to zero
PInvoke_RaiseFailFastException(
&exceptionRecord,
pExContext,
pExAddress == IntPtr.Zero ? (uint)Constants.FailFastGenerateExceptionAddress : 0);
}
[DllImport("api-ms-win-core-kernel32-legacy-l1-1-0.dll", EntryPoint = "RaiseFailFastException")]
private extern static unsafe void PInvoke_RaiseFailFastException(
_EXCEPTION_RECORD* pExceptionRecord,
IntPtr pContextRecord,
uint dwFlags);
}
}
|