1 /***
2 *setjmp.h - definitions/declarations for setjmp/longjmp routines
3 *
4 *           Copyright (c) Microsoft Corporation. All rights reserved.
5 *
6 *Purpose:
7 *           This file defines the machine-dependent buffer used by
8 *           setjmp/longjmp to save and restore the program state, and
9 *           declarations for those routines.
10 *           [ANSI/System V]
11 *
12 *           [Public]
13 *
14 ****/
15
16 #if        _MSC_VER > 1000
17 #pragma once
18 #endif
19
20 #ifndef _INC_SETJMP
21 #define _INC_SETJMP
22
23 #include <crtdefs.h>
24
25 #if defined(_M_CEE)
26 /*
27  * The reason why simple setjmp won't work here is that there may
28  * be case when CLR stubs are on the stack e.g. function call just
29  * after jitting, and not unwinding CLR will result in bad state of
30  * CLR which then can AV or do something very bad.
31  */
32 #include <setjmpex.h>
33 #endif  /* defined(_M_CEE) */
34
35 #ifdef  _MSC_VER
36 /*
37  * Currently, all MS C compilers for Win32 platforms default to 8 byte
38  * alignment.
39  */
40 #pragma pack(push,_CRT_PACKING)
41 #endif  /* _MSC_VER */
42
43 #ifdef  __cplusplus
44 extern "C" {
45 #endif
46
47 /*
48  * Definitions specific to particular setjmp implementations.
49  */
50
51 #if        defined(_M_IX86)
52
53 /*
54  * MS compiler for x86
55  */
56
57 #ifndef _INC_SETJMPEX
58 #define setjmp  _setjmp
59 #endif
60
61 #define _JBLEN  16
62 #define _JBTYPE int
63
64 /*
65  * Define jump buffer layout for x86 setjmp/longjmp.
66  */
67 typedef struct __JUMP_BUFFER {
68       unsigned long Ebp;
69       unsigned long Ebx;
70       unsigned long Edi;
71       unsigned long Esi;
72       unsigned long Esp;
73       unsigned long Eip;
74       unsigned long Registration;
75       unsigned long TryLevel;
76       unsigned long Cookie;
77       unsigned long UnwindFunc;
78       unsigned long UnwindData[6];
79 } _JUMP_BUFFER;
80
81
82 #elif defined(_M_IA64)
83
84 /*
85  * Minimum length is 528 bytes
86  * Since this is allocated as an array of "SETJMP_FLOAT128", the
87  * number of entries required is 33 (16-byte aligned).
88  */
89
90 /* Avoid conflicts with winnt.h FLOAT128 by giving the typedef another name. */
91 typedef _CRT_ALIGN(16) struct _SETJMP_FLOAT128 {
92       __int64 LowPart;
93       __int64 HighPart;
94 } SETJMP_FLOAT128;
95                                                         
96 #define _JBLEN  33
97 typedef SETJMP_FLOAT128 _JBTYPE;
98 #ifndef _INC_SETJMPEX
99 #define setjmp  _setjmp
100 #endif
101 /*
102  * Define jump buffer layout for IA64 setjmp/longjmp.
103  */
104
105 typedef struct __JUMP_BUFFER {
106
107       /*
108         * x86 reserved.
109         */
110
111       unsigned long iAReserved[6];
112
113       /*
114         * x86 C9.0 compatibility
115         */
116
117       unsigned long Registration;  /* point to the UnwindData field. */
118       unsigned long TryLevel;          /* ignored by setjmp */
119       unsigned long Cookie;             /* set to "VC20" by setjmp */
120       unsigned long UnwindFunc;      /* set to EM longjmp() by setjmp */
121
122       /*
123         * First dword is zero to indicate it's an exception registration
124         * record prepared by EM setjmp function.
125         * Second dword is set to 0 for unsafe EM setjmp, and 1 for safe
126         * EM setjmp.
127         * Third dword is set to the setjmp site memory stack frame pointer.
128         * Fourth dword is set to the setjmp site backing store frame pointer.
129         */
130
131       unsigned long UnwindData[6];
132
133       /*
134         * floating point status register,
135         * and preserved floating point registers fs0 - fs19
136         */
137
138       SETJMP_FLOAT128 FltS0;
139       SETJMP_FLOAT128 FltS1;
140       SETJMP_FLOAT128 FltS2;
141       SETJMP_FLOAT128 FltS3;
Lines 142 ... 151 are skipped.
152       SETJMP_FLOAT128 FltS14;
153       SETJMP_FLOAT128 FltS15;
154       SETJMP_FLOAT128 FltS16;
155       SETJMP_FLOAT128 FltS17;
156       SETJMP_FLOAT128 FltS18;
157       SETJMP_FLOAT128 FltS19;
158
159       __int64 FPSR;
160
161       /*
162         * return link and preserved branch registers bs0 - bs4
163         */
164
165       __int64 StIIP;        /* continuation address */
166       __int64 BrS0;
167       __int64 BrS1;
168       __int64 BrS2;
169       __int64 BrS3;
170       __int64 BrS4;
171
172       /*
173         * preserved general registers s0 - s3, sp, nats
174         */
175
176       __int64 IntS0;
177       __int64 IntS1;
178       __int64 IntS2;
179       __int64 IntS3;
180
181       /*
182         * bsp, pfs, unat, lc
183         */
184
185       __int64 RsBSP;
186       __int64 RsPFS;        /* previous frame marker (cfm of setjmp's caller) */
187       __int64 ApUNAT;      /* User Nat collection register (preserved) */
188       __int64 ApLC;          /* loop counter */
189
190       __int64 IntSp;        /* memory stack pointer */
191       __int64 IntNats;     /* Nat bits of preserved integer regs s0 - s3 */
192       __int64 Preds;        /* predicates */
193
194 } _JUMP_BUFFER;
195 #elif defined(_M_AMD64)
196
197 typedef _CRT_ALIGN(16) struct _SETJMP_FLOAT128 {
198       unsigned __int64 Part[2];
199 } SETJMP_FLOAT128;
200
201 #define _JBLEN  16
202 typedef SETJMP_FLOAT128 _JBTYPE;
203
204 #ifndef _INC_SETJMPEX
205 #define setjmp  _setjmp
206 #endif
207
208 typedef struct _JUMP_BUFFER {
209       unsigned __int64 Frame;
210       unsigned __int64 Rbx;
211       unsigned __int64 Rsp;
212       unsigned __int64 Rbp;
213       unsigned __int64 Rsi;
214       unsigned __int64 Rdi;
215       unsigned __int64 R12;
216       unsigned __int64 R13;
217       unsigned __int64 R14;
218       unsigned __int64 R15;
219       unsigned __int64 Rip;
220       unsigned __int64 Spare;
221       
222       SETJMP_FLOAT128 Xmm6;
223       SETJMP_FLOAT128 Xmm7;
224       SETJMP_FLOAT128 Xmm8;
225       SETJMP_FLOAT128 Xmm9;
226       SETJMP_FLOAT128 Xmm10;
227       SETJMP_FLOAT128 Xmm11;
228       SETJMP_FLOAT128 Xmm12;
229       SETJMP_FLOAT128 Xmm13;
230       SETJMP_FLOAT128 Xmm14;
231       SETJMP_FLOAT128 Xmm15;
232 } _JUMP_BUFFER;
233
234 #endif
235
236
237 /* Define the buffer type for holding the state information */
238
239 #ifndef _JMP_BUF_DEFINED
240 typedef _JBTYPE jmp_buf[_JBLEN];
241 #define _JMP_BUF_DEFINED
242 #endif
243
244
245 /* Function prototypes */
246
247 int __cdecl setjmp(_Out_ jmp_buf _Buf);
248
249 #ifdef  __cplusplus
250 }
251 #endif
252
253 #ifdef  __cplusplus
254 extern "C"
255 {
256 _CRTIMP __declspec(noreturn) void __cdecl longjmp(_In_ jmp_buf _Buf, _In_ int _Value) throw(...);
257 }
258 #else
259 _CRTIMP __declspec(noreturn) void __cdecl longjmp(_In_ jmp_buf _Buf, _In_ int _Value);
260 #endif
261
262 #ifdef  _MSC_VER
263 #pragma pack(pop)
264 #endif  /* _MSC_VER */
265
266 #endif  /* _INC_SETJMP */
267