xref: /reactos/sdk/include/vcruntime/excpt.h (revision d6eebaa4)
1 /**
2  * This file has no copyright assigned and is placed in the Public Domain.
3  * This file is part of the w64 mingw-runtime package.
4  * No warranty is given; refer to the file DISCLAIMER within this package.
5  */
6 #ifndef _INC_EXCPT
7 #define _INC_EXCPT
8 
9 #include <vcruntime.h>
10 
11 #pragma pack(push,_CRT_PACKING)
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
17 typedef enum _EXCEPTION_DISPOSITION
18 {
19     ExceptionContinueExecution,
20     ExceptionContinueSearch,
21     ExceptionNestedException,
22     ExceptionCollidedUnwind,
23 } EXCEPTION_DISPOSITION;
24 
25 #if (defined(_X86_) && !defined(__x86_64))
26   struct _EXCEPTION_RECORD;
27   struct _CONTEXT;
28 
29   EXCEPTION_DISPOSITION
30   __cdecl
31   _except_handler(
32     _In_ struct _EXCEPTION_RECORD *_ExceptionRecord,
33     _In_ void *_EstablisherFrame,
34     _Inout_ struct _CONTEXT *_ContextRecord,
35     _Inout_ void *_DispatcherContext);
36 
37 #elif defined(__ia64__)
38 
39   typedef struct _EXCEPTION_POINTERS *Exception_info_ptr;
40   struct _EXCEPTION_RECORD;
41   struct _CONTEXT;
42   struct _DISPATCHER_CONTEXT;
43 
44   __MINGW_EXTENSION
45   _CRTIMP
46   EXCEPTION_DISPOSITION
47   __cdecl
48   __C_specific_handler(
49     _In_ struct _EXCEPTION_RECORD *_ExceptionRecord,
50     _In_ unsigned __int64 _MemoryStackFp,
51     _In_ unsigned __int64 _BackingStoreFp,
52     _Inout_ struct _CONTEXT *_ContextRecord,
53     _Inout_ struct _DISPATCHER_CONTEXT *_DispatcherContext,
54     _In_ unsigned __int64 _GlobalPointer);
55 
56 #elif defined(__x86_64) || defined(_M_ARM) || defined(_M_ARM64)
57 
58   struct _EXCEPTION_RECORD;
59   struct _CONTEXT;
60   struct _DISPATCHER_CONTEXT;
61 
62   _CRTIMP
63   EXCEPTION_DISPOSITION
64   __cdecl
65   __C_specific_handler(
66     _In_ struct _EXCEPTION_RECORD *_ExceptionRecord,
67     _In_ void *_EstablisherFrame,
68     _Inout_ struct _CONTEXT *_ContextRecord,
69     _Inout_ struct _DISPATCHER_CONTEXT *_DispatcherContext);
70 
71 #endif
72 
73 #if defined(_MSC_VER) || (defined(__clang__) && defined(__SEH__))
74 #define GetExceptionCode _exception_code
75 #define exception_code _exception_code
76 #define GetExceptionInformation (struct _EXCEPTION_POINTERS *)_exception_info
77 #define exception_info (struct _EXCEPTION_POINTERS *)_exception_info
78 #define AbnormalTermination _abnormal_termination
79 #define abnormal_termination _abnormal_termination
80   unsigned long __cdecl _exception_code(void);
81   void *__cdecl _exception_info(void);
82   int __cdecl _abnormal_termination(void);
83 #endif
84 
85 #define EXCEPTION_EXECUTE_HANDLER 1
86 #define EXCEPTION_CONTINUE_SEARCH 0
87 #define EXCEPTION_CONTINUE_EXECUTION -1
88 
89 #if 0
90   /* CRT stuff */
91   typedef void (__cdecl * _PHNDLR)(int);
92 
93   struct _XCPT_ACTION {
94     unsigned long XcptNum;
95     int SigNum;
96     _PHNDLR XcptAction;
97   };
98 
99   extern struct _XCPT_ACTION _XcptActTab[];
100   extern int _XcptActTabCount;
101   extern int _XcptActTabSize;
102   extern int _First_FPE_Indx;
103   extern int _Num_FPE;
104 
105   int __cdecl __CppXcptFilter(unsigned long _ExceptionNum,struct _EXCEPTION_POINTERS * _ExceptionPtr);
106   int __cdecl _XcptFilter(unsigned long _ExceptionNum,struct _EXCEPTION_POINTERS * _ExceptionPtr);
107 
108   /*
109   * The type of function that is expected as an exception handler to be
110   * installed with _try1.
111   */
112   typedef EXCEPTION_DISPOSITION (*PEXCEPTION_HANDLER)(struct _EXCEPTION_RECORD*, void*, struct _CONTEXT*, void*);
113 
114 #ifndef HAVE_NO_SEH
115   /*
116   * This is not entirely necessary, but it is the structure installed by
117   * the _try1 primitive below.
118   */
119   typedef struct _EXCEPTION_REGISTRATION {
120     struct _EXCEPTION_REGISTRATION *prev;
121     EXCEPTION_DISPOSITION (*handler)(struct _EXCEPTION_RECORD*, void*, struct _CONTEXT*, void*);
122   } EXCEPTION_REGISTRATION, *PEXCEPTION_REGISTRATION;
123 
124   typedef EXCEPTION_REGISTRATION EXCEPTION_REGISTRATION_RECORD;
125   typedef PEXCEPTION_REGISTRATION PEXCEPTION_REGISTRATION_RECORD;
126 #endif
127 
128 #if (defined(_X86_) && !defined(__x86_64))
129 #define __try1(pHandler) \
130   __asm__ ("pushl %0;pushl %%fs:0;movl %%esp,%%fs:0;" : : "g" (pHandler));
131 
132 #define	__except1	\
133   __asm__ ("movl (%%esp),%%eax;movl %%eax,%%fs:0;addl $8,%%esp;" \
134   : : : "%eax");
135 #elif defined(__x86_64)
136 #define __try1(pHandler) \
137   __asm__ ("pushq %0;pushq %%gs:0;movq %%rsp,%%gs:0;" : : "g" (pHandler));
138 
139 #define	__except1	\
140   __asm__ ("movq (%%rsp),%%rax;movq %%rax,%%gs:0;addq $16,%%rsp;" \
141   : : : "%rax");
142 #else
143 #define __try1(pHandler)
144 #define __except1
145 #endif
146 
147 #endif // 0
148 
149 #ifdef __cplusplus
150 }
151 #endif
152 
153 #pragma pack(pop)
154 #endif
155