1 #ifndef __MONO_MONO_SIGCONTEXT_H__
2 #define __MONO_MONO_SIGCONTEXT_H__
5 #if defined(PLATFORM_ANDROID)
6 #include <asm/sigcontext.h>
21 #if defined(TARGET_X86)
23 #if defined(__APPLE__)
24 #include <AvailabilityMacros.h>
27 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
28 #define UCONTEXT_REG_EAX(ctx) (((ucontext_t*)(ctx))->uc_mcontext.mc_eax)
29 #define UCONTEXT_REG_EBX(ctx) (((ucontext_t*)(ctx))->uc_mcontext.mc_ebx)
30 #define UCONTEXT_REG_ECX(ctx) (((ucontext_t*)(ctx))->uc_mcontext.mc_ecx)
31 #define UCONTEXT_REG_EDX(ctx) (((ucontext_t*)(ctx))->uc_mcontext.mc_edx)
32 #define UCONTEXT_REG_EBP(ctx) (((ucontext_t*)(ctx))->uc_mcontext.mc_ebp)
33 #define UCONTEXT_REG_ESP(ctx) (((ucontext_t*)(ctx))->uc_mcontext.mc_esp)
34 #define UCONTEXT_REG_ESI(ctx) (((ucontext_t*)(ctx))->uc_mcontext.mc_esi)
35 #define UCONTEXT_REG_EDI(ctx) (((ucontext_t*)(ctx))->uc_mcontext.mc_edi)
36 #define UCONTEXT_REG_EIP(ctx) (((ucontext_t*)(ctx))->uc_mcontext.mc_eip)
37 #elif defined(__APPLE__)
38 # if defined (TARGET_IOS) || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
39 #define UCONTEXT_REG_EAX(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__eax)
40 #define UCONTEXT_REG_EBX(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__ebx)
41 #define UCONTEXT_REG_ECX(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__ecx)
42 #define UCONTEXT_REG_EDX(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__edx)
43 #define UCONTEXT_REG_EBP(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__ebp)
44 #define UCONTEXT_REG_ESP(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__esp)
45 #define UCONTEXT_REG_ESI(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__esi)
46 #define UCONTEXT_REG_EDI(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__edi)
47 #define UCONTEXT_REG_EIP(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__eip)
49 #define UCONTEXT_REG_EAX(ctx) (((ucontext_t*)(ctx))->uc_mcontext->ss.eax)
50 #define UCONTEXT_REG_EBX(ctx) (((ucontext_t*)(ctx))->uc_mcontext->ss.ebx)
51 #define UCONTEXT_REG_ECX(ctx) (((ucontext_t*)(ctx))->uc_mcontext->ss.ecx)
52 #define UCONTEXT_REG_EDX(ctx) (((ucontext_t*)(ctx))->uc_mcontext->ss.edx)
53 #define UCONTEXT_REG_EBP(ctx) (((ucontext_t*)(ctx))->uc_mcontext->ss.ebp)
54 #define UCONTEXT_REG_ESP(ctx) (((ucontext_t*)(ctx))->uc_mcontext->ss.esp)
55 #define UCONTEXT_REG_ESI(ctx) (((ucontext_t*)(ctx))->uc_mcontext->ss.esi)
56 #define UCONTEXT_REG_EDI(ctx) (((ucontext_t*)(ctx))->uc_mcontext->ss.edi)
57 #define UCONTEXT_REG_EIP(ctx) (((ucontext_t*)(ctx))->uc_mcontext->ss.eip)
59 #elif defined(__NetBSD__)
60 #define UCONTEXT_REG_EAX(ctx) (((ucontext_t*)(ctx))->uc_mcontext.__gregs [_REG_EAX])
61 #define UCONTEXT_REG_EBX(ctx) (((ucontext_t*)(ctx))->uc_mcontext.__gregs [_REG_EBX])
62 #define UCONTEXT_REG_ECX(ctx) (((ucontext_t*)(ctx))->uc_mcontext.__gregs [_REG_ECX])
63 #define UCONTEXT_REG_EDX(ctx) (((ucontext_t*)(ctx))->uc_mcontext.__gregs [_REG_EDX])
64 #define UCONTEXT_REG_EBP(ctx) (((ucontext_t*)(ctx))->uc_mcontext.__gregs [_REG_EBP])
65 #define UCONTEXT_REG_ESP(ctx) (((ucontext_t*)(ctx))->uc_mcontext.__gregs [_REG_ESP])
66 #define UCONTEXT_REG_ESI(ctx) (((ucontext_t*)(ctx))->uc_mcontext.__gregs [_REG_ESI])
67 #define UCONTEXT_REG_EDI(ctx) (((ucontext_t*)(ctx))->uc_mcontext.__gregs [_REG_EDI])
68 #define UCONTEXT_REG_EIP(ctx) (((ucontext_t*)(ctx))->uc_mcontext.__gregs [_REG_EIP])
69 #elif defined(__OpenBSD__)
70 #define UCONTEXT_REG_EAX(ctx) (((ucontext_t*)(ctx))->sc_eax)
71 #define UCONTEXT_REG_EBX(ctx) (((ucontext_t*)(ctx))->sc_ebx)
72 #define UCONTEXT_REG_ECX(ctx) (((ucontext_t*)(ctx))->sc_ecx)
73 #define UCONTEXT_REG_EDX(ctx) (((ucontext_t*)(ctx))->sc_edx)
74 #define UCONTEXT_REG_EBP(ctx) (((ucontext_t*)(ctx))->sc_ebp)
75 #define UCONTEXT_REG_ESP(ctx) (((ucontext_t*)(ctx))->sc_esp)
76 #define UCONTEXT_REG_ESI(ctx) (((ucontext_t*)(ctx))->sc_esi)
77 #define UCONTEXT_REG_EDI(ctx) (((ucontext_t*)(ctx))->sc_edi)
78 #define UCONTEXT_REG_EIP(ctx) (((ucontext_t*)(ctx))->sc_eip)
79 #elif defined(PLATFORM_SOLARIS)
80 #define UCONTEXT_REG_EAX(ctx) (((ucontext_t*)(ctx))->uc_mcontext.gregs [EAX])
81 #define UCONTEXT_REG_EBX(ctx) (((ucontext_t*)(ctx))->uc_mcontext.gregs [EBX])
82 #define UCONTEXT_REG_ECX(ctx) (((ucontext_t*)(ctx))->uc_mcontext.gregs [ECX])
83 #define UCONTEXT_REG_EDX(ctx) (((ucontext_t*)(ctx))->uc_mcontext.gregs [EDX])
84 #define UCONTEXT_REG_EBP(ctx) (((ucontext_t*)(ctx))->uc_mcontext.gregs [EBP])
85 #define UCONTEXT_REG_ESP(ctx) (((ucontext_t*)(ctx))->uc_mcontext.gregs [ESP])
86 #define UCONTEXT_REG_ESI(ctx) (((ucontext_t*)(ctx))->uc_mcontext.gregs [ESI])
87 #define UCONTEXT_REG_EDI(ctx) (((ucontext_t*)(ctx))->uc_mcontext.gregs [EDI])
88 #define UCONTEXT_REG_EIP(ctx) (((ucontext_t*)(ctx))->uc_mcontext.gregs [EIP])
91 #if defined(PLATFORM_ANDROID) && !defined(HAVE_UCONTEXT_H)
92 /* No ucontext.h as of NDK v6b */
95 typedef greg_t gregset_t [NGREG];
99 # define REG_GS REG_GS
101 # define REG_FS REG_FS
103 # define REG_ES REG_ES
105 # define REG_DS REG_DS
107 # define REG_EDI REG_EDI
109 # define REG_ESI REG_ESI
111 # define REG_EBP REG_EBP
113 # define REG_ESP REG_ESP
115 # define REG_EBX REG_EBX
117 # define REG_EDX REG_EDX
119 # define REG_ECX REG_ECX
121 # define REG_EAX REG_EAX
123 # define REG_TRAPNO REG_TRAPNO
125 # define REG_ERR REG_ERR
127 # define REG_EIP REG_EIP
132 /* Many missing fields */
135 typedef struct ucontext {
136 unsigned long int uc_flags;
137 struct ucontext *uc_link;
139 mcontext_t uc_mcontext;
140 /* Many missing fields */
145 #define UCONTEXT_REG_EAX(ctx) (((ucontext_t*)(ctx))->uc_mcontext.gregs [REG_EAX])
146 #define UCONTEXT_REG_EBX(ctx) (((ucontext_t*)(ctx))->uc_mcontext.gregs [REG_EBX])
147 #define UCONTEXT_REG_ECX(ctx) (((ucontext_t*)(ctx))->uc_mcontext.gregs [REG_ECX])
148 #define UCONTEXT_REG_EDX(ctx) (((ucontext_t*)(ctx))->uc_mcontext.gregs [REG_EDX])
149 #define UCONTEXT_REG_EBP(ctx) (((ucontext_t*)(ctx))->uc_mcontext.gregs [REG_EBP])
150 #define UCONTEXT_REG_ESP(ctx) (((ucontext_t*)(ctx))->uc_mcontext.gregs [REG_ESP])
151 #define UCONTEXT_REG_ESI(ctx) (((ucontext_t*)(ctx))->uc_mcontext.gregs [REG_ESI])
152 #define UCONTEXT_REG_EDI(ctx) (((ucontext_t*)(ctx))->uc_mcontext.gregs [REG_EDI])
153 #define UCONTEXT_REG_EIP(ctx) (((ucontext_t*)(ctx))->uc_mcontext.gregs [REG_EIP])
156 #elif defined(TARGET_AMD64)
158 #if defined(__APPLE__)
159 #define UCONTEXT_REG_RAX(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__rax)
160 #define UCONTEXT_REG_RBX(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__rbx)
161 #define UCONTEXT_REG_RCX(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__rcx)
162 #define UCONTEXT_REG_RDX(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__rdx)
163 #define UCONTEXT_REG_RBP(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__rbp)
164 #define UCONTEXT_REG_RSP(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__rsp)
165 #define UCONTEXT_REG_RSI(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__rsi)
166 #define UCONTEXT_REG_RDI(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__rdi)
167 #define UCONTEXT_REG_RIP(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__rip)
168 #define UCONTEXT_REG_R8(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__r8)
169 #define UCONTEXT_REG_R9(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__r9)
170 #define UCONTEXT_REG_R10(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__r10)
171 #define UCONTEXT_REG_R11(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__r11)
172 #define UCONTEXT_REG_R12(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__r12)
173 #define UCONTEXT_REG_R13(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__r13)
174 #define UCONTEXT_REG_R14(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__r14)
175 #define UCONTEXT_REG_R15(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__r15)
176 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
177 #define UCONTEXT_REG_RAX(ctx) (((ucontext_t*)(ctx))->uc_mcontext.mc_rax)
178 #define UCONTEXT_REG_RBX(ctx) (((ucontext_t*)(ctx))->uc_mcontext.mc_rbx)
179 #define UCONTEXT_REG_RCX(ctx) (((ucontext_t*)(ctx))->uc_mcontext.mc_rcx)
180 #define UCONTEXT_REG_RDX(ctx) (((ucontext_t*)(ctx))->uc_mcontext.mc_rdx)
181 #define UCONTEXT_REG_RBP(ctx) (((ucontext_t*)(ctx))->uc_mcontext.mc_rbp)
182 #define UCONTEXT_REG_RSP(ctx) (((ucontext_t*)(ctx))->uc_mcontext.mc_rsp)
183 #define UCONTEXT_REG_RSI(ctx) (((ucontext_t*)(ctx))->uc_mcontext.mc_rsi)
184 #define UCONTEXT_REG_RDI(ctx) (((ucontext_t*)(ctx))->uc_mcontext.mc_rdi)
185 #define UCONTEXT_REG_RIP(ctx) (((ucontext_t*)(ctx))->uc_mcontext.mc_rip)
186 #define UCONTEXT_REG_R8(ctx) (((ucontext_t*)(ctx))->uc_mcontext.mc_r8)
187 #define UCONTEXT_REG_R9(ctx) (((ucontext_t*)(ctx))->uc_mcontext.mc_r9)
188 #define UCONTEXT_REG_R10(ctx) (((ucontext_t*)(ctx))->uc_mcontext.mc_r10)
189 #define UCONTEXT_REG_R11(ctx) (((ucontext_t*)(ctx))->uc_mcontext.mc_r11)
190 #define UCONTEXT_REG_R12(ctx) (((ucontext_t*)(ctx))->uc_mcontext.mc_r12)
191 #define UCONTEXT_REG_R13(ctx) (((ucontext_t*)(ctx))->uc_mcontext.mc_r13)
192 #define UCONTEXT_REG_R14(ctx) (((ucontext_t*)(ctx))->uc_mcontext.mc_r14)
193 #define UCONTEXT_REG_R15(ctx) (((ucontext_t*)(ctx))->uc_mcontext.mc_r15)
194 #elif defined(__NetBSD__)
195 #define UCONTEXT_REG_RAX(ctx) (((ucontext_t*)(ctx))->uc_mcontext.__gregs [_REG_RAX])
196 #define UCONTEXT_REG_RBX(ctx) (((ucontext_t*)(ctx))->uc_mcontext.__gregs [_REG_RBX])
197 #define UCONTEXT_REG_RCX(ctx) (((ucontext_t*)(ctx))->uc_mcontext.__gregs [_REG_RCX])
198 #define UCONTEXT_REG_RDX(ctx) (((ucontext_t*)(ctx))->uc_mcontext.__gregs [_REG_RDX])
199 #define UCONTEXT_REG_RBP(ctx) (((ucontext_t*)(ctx))->uc_mcontext.__gregs [_REG_RBP])
200 #define UCONTEXT_REG_RSP(ctx) (((ucontext_t*)(ctx))->uc_mcontext.__gregs [_REG_RSP])
201 #define UCONTEXT_REG_RSI(ctx) (((ucontext_t*)(ctx))->uc_mcontext.__gregs [_REG_RSI])
202 #define UCONTEXT_REG_RDI(ctx) (((ucontext_t*)(ctx))->uc_mcontext.__gregs [_REG_RDI])
203 #define UCONTEXT_REG_RIP(ctx) (((ucontext_t*)(ctx))->uc_mcontext.__gregs [_REG_RIP])
204 #define UCONTEXT_REG_R12(ctx) (((ucontext_t*)(ctx))->uc_mcontext.__gregs [_REG_R12])
205 #define UCONTEXT_REG_R13(ctx) (((ucontext_t*)(ctx))->uc_mcontext.__gregs [_REG_R13])
206 #define UCONTEXT_REG_R14(ctx) (((ucontext_t*)(ctx))->uc_mcontext.__gregs [_REG_R14])
207 #define UCONTEXT_REG_R15(ctx) (((ucontext_t*)(ctx))->uc_mcontext.__gregs [_REG_R15])
208 #elif defined(__OpenBSD__)
209 /* OpenBSD/amd64 has no gregs array, ucontext_t == sigcontext */
210 #define UCONTEXT_REG_RAX(ctx) (((ucontext_t*)(ctx))->sc_rax)
211 #define UCONTEXT_REG_RBX(ctx) (((ucontext_t*)(ctx))->sc_rbx)
212 #define UCONTEXT_REG_RCX(ctx) (((ucontext_t*)(ctx))->sc_rcx)
213 #define UCONTEXT_REG_RDX(ctx) (((ucontext_t*)(ctx))->sc_rdx)
214 #define UCONTEXT_REG_RBP(ctx) (((ucontext_t*)(ctx))->sc_rbp)
215 #define UCONTEXT_REG_RSP(ctx) (((ucontext_t*)(ctx))->sc_rsp)
216 #define UCONTEXT_REG_RSI(ctx) (((ucontext_t*)(ctx))->sc_rsi)
217 #define UCONTEXT_REG_RDI(ctx) (((ucontext_t*)(ctx))->sc_rdi)
218 #define UCONTEXT_REG_RIP(ctx) (((ucontext_t*)(ctx))->sc_rip)
219 #define UCONTEXT_REG_R8(ctx) (((ucontext_t*)(ctx))->sc_r8)
220 #define UCONTEXT_REG_R9(ctx) (((ucontext_t*)(ctx))->sc_r9)
221 #define UCONTEXT_REG_R10(ctx) (((ucontext_t*)(ctx))->sc_r10)
222 #define UCONTEXT_REG_R11(ctx) (((ucontext_t*)(ctx))->sc_r11)
223 #define UCONTEXT_REG_R12(ctx) (((ucontext_t*)(ctx))->sc_r12)
224 #define UCONTEXT_REG_R13(ctx) (((ucontext_t*)(ctx))->sc_r13)
225 #define UCONTEXT_REG_R14(ctx) (((ucontext_t*)(ctx))->sc_r14)
226 #define UCONTEXT_REG_R15(ctx) (((ucontext_t*)(ctx))->sc_r15)
228 #define UCONTEXT_GREGS(ctx) ((guint64*)&(((ucontext_t*)(ctx))->uc_mcontext.gregs))
231 #ifdef UCONTEXT_GREGS
232 #define UCONTEXT_REG_RAX(ctx) (UCONTEXT_GREGS ((ctx)) [REG_RAX])
233 #define UCONTEXT_REG_RBX(ctx) (UCONTEXT_GREGS ((ctx)) [REG_RBX])
234 #define UCONTEXT_REG_RCX(ctx) (UCONTEXT_GREGS ((ctx)) [REG_RCX])
235 #define UCONTEXT_REG_RDX(ctx) (UCONTEXT_GREGS ((ctx)) [REG_RDX])
236 #define UCONTEXT_REG_RBP(ctx) (UCONTEXT_GREGS ((ctx)) [REG_RBP])
237 #define UCONTEXT_REG_RSP(ctx) (UCONTEXT_GREGS ((ctx)) [REG_RSP])
238 #define UCONTEXT_REG_RSI(ctx) (UCONTEXT_GREGS ((ctx)) [REG_RSI])
239 #define UCONTEXT_REG_RDI(ctx) (UCONTEXT_GREGS ((ctx)) [REG_RDI])
240 #define UCONTEXT_REG_RIP(ctx) (UCONTEXT_GREGS ((ctx)) [REG_RIP])
241 #define UCONTEXT_REG_R8(ctx) (UCONTEXT_GREGS ((ctx)) [REG_R8])
242 #define UCONTEXT_REG_R9(ctx) (UCONTEXT_GREGS ((ctx)) [REG_R9])
243 #define UCONTEXT_REG_R10(ctx) (UCONTEXT_GREGS ((ctx)) [REG_R10])
244 #define UCONTEXT_REG_R11(ctx) (UCONTEXT_GREGS ((ctx)) [REG_R11])
245 #define UCONTEXT_REG_R12(ctx) (UCONTEXT_GREGS ((ctx)) [REG_R12])
246 #define UCONTEXT_REG_R13(ctx) (UCONTEXT_GREGS ((ctx)) [REG_R13])
247 #define UCONTEXT_REG_R14(ctx) (UCONTEXT_GREGS ((ctx)) [REG_R14])
248 #define UCONTEXT_REG_R15(ctx) (UCONTEXT_GREGS ((ctx)) [REG_R15])
251 #elif defined(__mono_ppc__)
254 #include <ucontext.h>
257 #if defined(__linux__)
258 typedef struct ucontext os_ucontext;
260 #ifdef __mono_ppc64__
261 #define UCONTEXT_REG_Rn(ctx, n) (((os_ucontext*)(ctx))->uc_mcontext.gp_regs [(n)])
262 #define UCONTEXT_REG_FPRn(ctx, n) (((os_ucontext*)(ctx))->uc_mcontext.fp_regs [(n)])
263 #define UCONTEXT_REG_NIP(ctx) (((os_ucontext*)(ctx))->uc_mcontext.gp_regs [PT_NIP])
264 #define UCONTEXT_REG_LNK(ctx) (((os_ucontext*)(ctx))->uc_mcontext.gp_regs [PT_LNK])
266 #define UCONTEXT_REG_Rn(ctx, n) (((os_ucontext*)(ctx))->uc_mcontext.uc_regs->gregs [(n)])
267 #define UCONTEXT_REG_FPRn(ctx, n) (((os_ucontext*)(ctx))->uc_mcontext.uc_regs->fpregs.fpregs [(n)])
268 #define UCONTEXT_REG_NIP(ctx) (((os_ucontext*)(ctx))->uc_mcontext.uc_regs->gregs [PT_NIP])
269 #define UCONTEXT_REG_LNK(ctx) (((os_ucontext*)(ctx))->uc_mcontext.uc_regs->gregs [PT_LNK])
271 #elif defined (__APPLE__) && defined (_STRUCT_MCONTEXT)
272 typedef struct __darwin_ucontext os_ucontext;
274 #define UCONTEXT_REG_Rn(ctx, n) ((&((os_ucontext*)(ctx))->uc_mcontext->__ss.__r0) [(n)])
275 #define UCONTEXT_REG_FPRn(ctx, n) (((os_ucontext*)(ctx))->uc_mcontext->__fs.__fpregs [(n)])
276 #define UCONTEXT_REG_NIP(ctx) (((os_ucontext*)(ctx))->uc_mcontext->__ss.__srr0)
277 #define UCONTEXT_REG_LNK(ctx) (((os_ucontext*)(ctx))->uc_mcontext->__ss.__lr)
278 #elif defined (__APPLE__) && !defined (_STRUCT_MCONTEXT)
279 typedef struct ucontext os_ucontext;
281 #define UCONTEXT_REG_Rn(ctx, n) ((&((os_ucontext*)(ctx))->uc_mcontext->ss.r0) [(n)])
282 #define UCONTEXT_REG_FPRn(ctx, n) (((os_ucontext*)(ctx))->uc_mcontext->fs.fpregs [(n)])
283 #define UCONTEXT_REG_NIP(ctx) (((os_ucontext*)(ctx))->uc_mcontext->ss.srr0)
284 #define UCONTEXT_REG_LNK(ctx) (((os_ucontext*)(ctx))->uc_mcontext->ss.lr)
285 #elif defined(__NetBSD__)
286 typedef ucontext_t os_ucontext;
288 #define UCONTEXT_REG_Rn(ctx, n) (((os_ucontext*)(ctx))->uc_mcontext.__gregs [(n)])
289 #define UCONTEXT_REG_FPRn(ctx, n) (((os_ucontext*)(ctx))->uc_mcontext.__fpregs.__fpu_regs [(n)])
290 #define UCONTEXT_REG_NIP(ctx) _UC_MACHINE_PC(ctx)
291 #define UCONTEXT_REG_LNK(ctx) (((os_ucontext*)(ctx))->uc_mcontext.__gregs [_REG_LR])
292 #elif defined(__FreeBSD__)
293 typedef ucontext_t os_ucontext;
295 #define UCONTEXT_REG_Rn(ctx, n) ((ctx)->uc_mcontext.mc_gpr [(n)])
296 #define UCONTEXT_REG_FPRn(ctx, n) ((ctx)->uc_mcontext.mc_fpreg [(n)])
297 #define UCONTEXT_REG_NIP(ctx) ((ctx)->uc_mcontext.mc_srr0)
298 #define UCONTEXT_REG_LNK(ctx) ((ctx)->uc_mcontext.mc_lr)
301 #elif defined(TARGET_ARM)
302 #if defined(__APPLE__)
303 typedef ucontext_t arm_ucontext;
305 #define UCONTEXT_REG_PC(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__pc)
306 #define UCONTEXT_REG_SP(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__sp)
307 #define UCONTEXT_REG_LR(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__lr)
308 #define UCONTEXT_REG_R0(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__r[0])
309 #define UCONTEXT_REG_R1(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__r[1])
310 #define UCONTEXT_REG_R2(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__r[2])
311 #define UCONTEXT_REG_R3(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__r[3])
312 #define UCONTEXT_REG_R4(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__r[4])
313 #define UCONTEXT_REG_R5(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__r[5])
314 #define UCONTEXT_REG_R6(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__r[6])
315 #define UCONTEXT_REG_R7(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__r[7])
316 #define UCONTEXT_REG_R8(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__r[8])
317 #define UCONTEXT_REG_R9(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__r[9])
318 #define UCONTEXT_REG_R10(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__r[10])
319 #define UCONTEXT_REG_R11(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__r[11])
320 #define UCONTEXT_REG_R12(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__r[12])
321 #define UCONTEXT_REG_CPSR(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__cpsr)
322 #define UCONTEXT_REG_VFPREGS(ctx) (double*)(((ucontext_t*)(ctx))->uc_mcontext->__fs.__r)
323 #elif defined(__linux__)
324 typedef struct arm_ucontext {
325 unsigned long uc_flags;
326 struct arm_ucontext *uc_link;
332 struct sigcontext sig_ctx;
333 /* some 2.6.x kernel has fp data here after a few other fields
334 * we don't use them for now...
337 #define UCONTEXT_REG_PC(ctx) (((arm_ucontext*)(ctx))->sig_ctx.arm_pc)
338 #define UCONTEXT_REG_SP(ctx) (((arm_ucontext*)(ctx))->sig_ctx.arm_sp)
339 #define UCONTEXT_REG_LR(ctx) (((arm_ucontext*)(ctx))->sig_ctx.arm_lr)
340 #define UCONTEXT_REG_R0(ctx) (((arm_ucontext*)(ctx))->sig_ctx.arm_r0)
341 #define UCONTEXT_REG_R1(ctx) (((arm_ucontext*)(ctx))->sig_ctx.arm_r1)
342 #define UCONTEXT_REG_R2(ctx) (((arm_ucontext*)(ctx))->sig_ctx.arm_r2)
343 #define UCONTEXT_REG_R3(ctx) (((arm_ucontext*)(ctx))->sig_ctx.arm_r3)
344 #define UCONTEXT_REG_R4(ctx) (((arm_ucontext*)(ctx))->sig_ctx.arm_r4)
345 #define UCONTEXT_REG_R5(ctx) (((arm_ucontext*)(ctx))->sig_ctx.arm_r5)
346 #define UCONTEXT_REG_R6(ctx) (((arm_ucontext*)(ctx))->sig_ctx.arm_r6)
347 #define UCONTEXT_REG_R7(ctx) (((arm_ucontext*)(ctx))->sig_ctx.arm_r7)
348 #define UCONTEXT_REG_R8(ctx) (((arm_ucontext*)(ctx))->sig_ctx.arm_r8)
349 #define UCONTEXT_REG_R9(ctx) (((arm_ucontext*)(ctx))->sig_ctx.arm_r9)
350 #define UCONTEXT_REG_R10(ctx) (((arm_ucontext*)(ctx))->sig_ctx.arm_r10)
351 #define UCONTEXT_REG_R11(ctx) (((arm_ucontext*)(ctx))->sig_ctx.arm_fp)
352 #define UCONTEXT_REG_R12(ctx) (((arm_ucontext*)(ctx))->sig_ctx.arm_ip)
353 #define UCONTEXT_REG_CPSR(ctx) (((arm_ucontext*)(ctx))->sig_ctx.arm_cpsr)
356 #elif defined(TARGET_ARM64)
358 #if defined(MONO_CROSS_COMPILE)
359 #define UCONTEXT_REG_PC(ctx) NULL
360 #define UCONTEXT_REG_SP(ctx) NULL
361 #define UCONTEXT_REG_R0(ctx) NULL
362 #define UCONTEXT_GREGS(ctx) NULL
363 #elif defined(__APPLE__)
364 #include <machine/_mcontext.h>
365 #include <sys/_types/_ucontext64.h>
366 /* mach/arm/_structs.h */
367 #define UCONTEXT_REG_PC(ctx) (((ucontext64_t*)(ctx))->uc_mcontext64->__ss.__pc)
368 #define UCONTEXT_REG_SP(ctx) (((ucontext64_t*)(ctx))->uc_mcontext64->__ss.__sp)
369 #define UCONTEXT_REG_R0(ctx) (((ucontext64_t*)(ctx))->uc_mcontext64->__ss.__x [ARMREG_R0])
370 #define UCONTEXT_GREGS(ctx) (&(((ucontext64_t*)(ctx))->uc_mcontext64->__ss.__x))
372 #include <ucontext.h>
373 #define UCONTEXT_REG_PC(ctx) (((ucontext_t*)(ctx))->uc_mcontext.pc)
374 #define UCONTEXT_REG_SP(ctx) (((ucontext_t*)(ctx))->uc_mcontext.sp)
375 #define UCONTEXT_REG_R0(ctx) (((ucontext_t*)(ctx))->uc_mcontext.regs [ARMREG_R0])
376 #define UCONTEXT_GREGS(ctx) (&(((ucontext_t*)(ctx))->uc_mcontext.regs))
379 #elif defined(__mips__)
382 # include <ucontext.h>
386 #if defined(TARGET_ANDROID)
391 typedef unsigned long gregset_t[NGREG];
393 typedef struct fpregset {
395 double fp_dregs[NFPREG];
398 unsigned int _fp_pad;
405 unsigned int regmask;
410 /* missing fields follow */
413 typedef struct ucontext
415 unsigned long int uc_flags;
416 struct ucontext *uc_link;
418 mcontext_t uc_mcontext;
419 /* missing fields follow */
424 # define UCONTEXT_GREGS(ctx) (((ucontext_t *)(ctx))->uc_mcontext.gregs)
425 # define UCONTEXT_FPREGS(ctx) (((ucontext_t *)(ctx))->uc_mcontext.fpregs.fp_r.fp_dregs)
426 # define UCONTEXT_REG_PC(ctx) (((ucontext_t *)(ctx))->uc_mcontext.pc)
428 #elif defined(__s390x__)
431 # include <ucontext.h>
434 # define UCONTEXT_GREGS(ctx) (((ucontext_t *)(ctx))->uc_mcontext.gregs)