1//
2// Copyright (c) Microsoft. All rights reserved.
3// Licensed under the MIT license. See LICENSE file in the project root for full license information.
4//
5
6//----------------------------------------------------------
7// ErrorHandling.h - Helpers & whatnot for using SEH for errors
8//----------------------------------------------------------
9#ifndef _ErrorHandling
10#define _ErrorHandling
11
12#include "logging.h"
13
14// EXCEPTIONCODE_DebugBreakorAV is just the base exception number; calls to DebugBreakorAV()
15// pass a unique number to add to this. EXCEPTIONCODE_DebugBreakorAV_MAX is the maximum number
16// of this exception range.
17#define EXCEPTIONCODE_DebugBreakorAV 0xe0421000
18#define EXCEPTIONCODE_DebugBreakorAV_MAX 0xe0422000
19
20#define EXCEPTIONCODE_MC 0xe0422000
21#define EXCEPTIONCODE_LWM 0xe0423000
22#define EXCEPTIONCODE_CALLUTILS 0xe0426000
23#define EXCEPTIONCODE_TYPEUTILS 0xe0427000
24#define EXCEPTIONCODE_ASSERT 0xe0440000
25
26// RaiseException wrappers
27void MSC_ONLY(__declspec(noreturn)) ThrowException(DWORD exceptionCode);
28void MSC_ONLY(__declspec(noreturn)) ThrowException(DWORD exceptionCode, const char* message, ...);
29
30// Assert stuff
31#define AssertCodeMsg(expr, exCode, msg, ...) \
32 do \
33 { \
34 if (!(expr)) \
35 LogException(exCode, "SuperPMI assertion '%s' failed (" #msg ")", #expr, ##__VA_ARGS__); \
36 } while (0)
37
38#define AssertCode(expr, exCode) \
39 do \
40 { \
41 if (!(expr)) \
42 LogException(exCode, "SuperPMI assertion '%s' failed", #expr); \
43 } while (0)
44
45#define AssertMsg(expr, msg, ...) AssertCodeMsg(expr, EXCEPTIONCODE_ASSERT, msg, ##__VA_ARGS__)
46#define Assert(expr) AssertCode(expr, EXCEPTIONCODE_ASSERT)
47
48class SpmiException
49{
50private:
51 DWORD exCode;
52 char* exMessage;
53
54public:
55 SpmiException(PEXCEPTION_POINTERS exp);
56 SpmiException(DWORD exceptionCode, char* exceptionMessage);
57#if 0
58 ~SpmiException();
59#endif
60
61 char* GetExceptionMessage();
62 DWORD GetCode();
63
64 void ShowAndDeleteMessage();
65 void DeleteMessage();
66};
67
68//
69// Functions and types used by PAL_TRY-related macros.
70//
71
72extern LONG FilterSuperPMIExceptions_CatchMC(PEXCEPTION_POINTERS pExceptionPointers, LPVOID lpvParam);
73
74struct FilterSuperPMIExceptionsParam_CaptureException
75{
76 EXCEPTION_POINTERS exceptionPointers;
77 DWORD exceptionCode;
78
79 FilterSuperPMIExceptionsParam_CaptureException() : exceptionCode(0)
80 {
81 exceptionPointers.ExceptionRecord = nullptr;
82 exceptionPointers.ContextRecord = nullptr;
83 }
84};
85
86extern LONG FilterSuperPMIExceptions_CaptureExceptionAndContinue(PEXCEPTION_POINTERS pExceptionPointers,
87 LPVOID lpvParam);
88extern LONG FilterSuperPMIExceptions_CaptureExceptionAndStop(PEXCEPTION_POINTERS pExceptionPointers, LPVOID lpvParam);
89
90extern bool RunWithErrorTrap(void (*function)(void*), void* param);
91
92#endif
93