• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 The Android Open Source Project
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *  * Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  *  * Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in
12  *    the documentation and/or other materials provided with the
13  *    distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 #ifndef _SYS_UCONTEXT_H_
30 #define _SYS_UCONTEXT_H_
31 
32 #include <sys/cdefs.h>
33 
34 #include <signal.h>
35 #include <sys/user.h>
36 
37 __BEGIN_DECLS
38 
39 #if defined(__arm__)
40 
41 enum {
42   REG_R0 = 0,
43 #define REG_R0 REG_R0
44   REG_R1,
45 #define REG_R1 REG_R1
46   REG_R2,
47 #define REG_R2 REG_R2
48   REG_R3,
49 #define REG_R3 REG_R3
50   REG_R4,
51 #define REG_R4 REG_R4
52   REG_R5,
53 #define REG_R5 REG_R5
54   REG_R6,
55 #define REG_R6 REG_R6
56   REG_R7,
57 #define REG_R7 REG_R7
58   REG_R8,
59 #define REG_R8 REG_R8
60   REG_R9,
61 #define REG_R9 REG_R9
62   REG_R10,
63 #define REG_R10 REG_R10
64   REG_R11,
65 #define REG_R11 REG_R11
66   REG_R12,
67 #define REG_R12 REG_R12
68   REG_R13,
69 #define REG_R13 REG_R13
70   REG_R14,
71 #define REG_R14 REG_R14
72   REG_R15,
73 #define REG_R15 REG_R15
74 };
75 
76 #define NGREG 18 /* Like glibc. */
77 
78 typedef int greg_t;
79 typedef greg_t gregset_t[NGREG];
80 typedef struct user_fpregs fpregset_t;
81 
82 #include <asm/sigcontext.h>
83 typedef struct sigcontext mcontext_t;
84 
85 typedef struct ucontext {
86   unsigned long uc_flags;
87   struct ucontext* uc_link;
88   stack_t uc_stack;
89   mcontext_t uc_mcontext;
90   sigset_t uc_sigmask;
91   /* Android has a wrong (smaller) sigset_t on ARM. */
92   uint32_t __padding_rt_sigset;
93   /* The kernel adds extra padding after uc_sigmask to match glibc sigset_t on ARM. */
94   char __padding[120];
95   unsigned long uc_regspace[128] __attribute__((__aligned__(8)));
96 } ucontext_t;
97 
98 #elif defined(__aarch64__)
99 
100 #define NGREG 34 /* x0..x30 + sp + pc + pstate */
101 typedef unsigned long greg_t;
102 typedef greg_t gregset_t[NGREG];
103 typedef struct user_fpsimd_struct fpregset_t;
104 
105 #include <asm/sigcontext.h>
106 typedef struct sigcontext mcontext_t;
107 
108 typedef struct ucontext {
109   unsigned long uc_flags;
110   struct ucontext *uc_link;
111   stack_t uc_stack;
112   sigset_t uc_sigmask;
113   /* The kernel adds extra padding after uc_sigmask to match glibc sigset_t on ARM64. */
114   char __padding[128 - sizeof(sigset_t)];
115   mcontext_t uc_mcontext;
116 } ucontext_t;
117 
118 #elif defined(__i386__)
119 
120 enum {
121   REG_GS = 0,
122 #define REG_GS REG_GS
123   REG_FS,
124 #define REG_FS REG_FS
125   REG_ES,
126 #define REG_ES REG_ES
127   REG_DS,
128 #define REG_DS REG_DS
129   REG_EDI,
130 #define REG_EDI REG_EDI
131   REG_ESI,
132 #define REG_ESI REG_ESI
133   REG_EBP,
134 #define REG_EBP REG_EBP
135   REG_ESP,
136 #define REG_ESP REG_ESP
137   REG_EBX,
138 #define REG_EBX REG_EBX
139   REG_EDX,
140 #define REG_EDX REG_EDX
141   REG_ECX,
142 #define REG_ECX REG_ECX
143   REG_EAX,
144 #define REG_EAX REG_EAX
145   REG_TRAPNO,
146 #define REG_TRAPNO REG_TRAPNO
147   REG_ERR,
148 #define REG_ERR REG_ERR
149   REG_EIP,
150 #define REG_EIP REG_EIP
151   REG_CS,
152 #define REG_CS REG_CS
153   REG_EFL,
154 #define REG_EFL REG_EFL
155   REG_UESP,
156 #define REG_UESP REG_UESP
157   REG_SS,
158 #define REG_SS REG_SS
159   NGREG
160 #define NGREG NGREG
161 };
162 
163 typedef int greg_t;
164 typedef greg_t gregset_t[NGREG];
165 
166 struct _libc_fpreg {
167   unsigned short significand[4];
168   unsigned short exponent;
169 };
170 
171 struct _libc_fpstate {
172   unsigned long cw;
173   unsigned long sw;
174   unsigned long tag;
175   unsigned long ipoff;
176   unsigned long cssel;
177   unsigned long dataoff;
178   unsigned long datasel;
179   struct _libc_fpreg _st[8];
180   unsigned long status;
181 };
182 
183 typedef struct _libc_fpstate* fpregset_t;
184 
185 typedef struct {
186   gregset_t gregs;
187   fpregset_t fpregs;
188   unsigned long oldmask;
189   unsigned long cr2;
190 } mcontext_t;
191 
192 typedef struct ucontext {
193   unsigned long uc_flags;
194   struct ucontext* uc_link;
195   stack_t uc_stack;
196   mcontext_t uc_mcontext;
197   sigset_t uc_sigmask;
198   /* Android has a wrong (smaller) sigset_t on x86. */
199   uint32_t __padding_rt_sigset;
200   struct _libc_fpstate __fpregs_mem;
201 } ucontext_t;
202 
203 #elif defined(__mips__)
204 
205 /* glibc doesn't have names for MIPS registers. */
206 
207 #define NGREG 32
208 #define NFPREG 32
209 
210 typedef unsigned long long greg_t;
211 typedef greg_t gregset_t[NGREG];
212 
213 typedef struct fpregset {
214   union {
215     double fp_dregs[NFPREG];
216     struct {
217       float _fp_fregs;
218       unsigned _fp_pad;
219     } fp_fregs[NFPREG];
220   } fp_r;
221 } fpregset_t;
222 
223 #ifdef __LP64__
224 typedef struct {
225   gregset_t gregs;
226   fpregset_t fpregs;
227   greg_t mdhi;
228   greg_t hi1;
229   greg_t hi2;
230   greg_t hi3;
231   greg_t mdlo;
232   greg_t lo1;
233   greg_t lo2;
234   greg_t lo3;
235   greg_t pc;
236   uint32_t fpc_csr;
237   uint32_t used_math;
238   uint32_t dsp;
239   uint32_t reserved;
240 } mcontext_t;
241 #else
242 typedef struct {
243   unsigned regmask;
244   unsigned status;
245   greg_t pc;
246   gregset_t gregs;
247   fpregset_t fpregs;
248   unsigned fp_owned;
249   unsigned fpc_csr;
250   unsigned fpc_eir;
251   unsigned used_math;
252   unsigned dsp;
253   greg_t mdhi;
254   greg_t mdlo;
255   unsigned long hi1;
256   unsigned long lo1;
257   unsigned long hi2;
258   unsigned long lo2;
259   unsigned long hi3;
260   unsigned long lo3;
261 } mcontext_t;
262 #endif
263 
264 typedef struct ucontext {
265   unsigned long uc_flags;
266   struct ucontext* uc_link;
267   stack_t uc_stack;
268   mcontext_t uc_mcontext;
269   sigset_t uc_sigmask;
270 } ucontext_t;
271 
272 #elif defined(__x86_64__)
273 
274 enum {
275   REG_R8 = 0,
276 #define REG_R8 REG_R8
277   REG_R9,
278 #define REG_R9 REG_R9
279   REG_R10,
280 #define REG_R10 REG_R10
281   REG_R11,
282 #define REG_R11 REG_R11
283   REG_R12,
284 #define REG_R12 REG_R12
285   REG_R13,
286 #define REG_R13 REG_R13
287   REG_R14,
288 #define REG_R14 REG_R14
289   REG_R15,
290 #define REG_R15 REG_R15
291   REG_RDI,
292 #define REG_RDI REG_RDI
293   REG_RSI,
294 #define REG_RSI REG_RSI
295   REG_RBP,
296 #define REG_RBP REG_RBP
297   REG_RBX,
298 #define REG_RBX REG_RBX
299   REG_RDX,
300 #define REG_RDX REG_RDX
301   REG_RAX,
302 #define REG_RAX REG_RAX
303   REG_RCX,
304 #define REG_RCX REG_RCX
305   REG_RSP,
306 #define REG_RSP REG_RSP
307   REG_RIP,
308 #define REG_RIP REG_RIP
309   REG_EFL,
310 #define REG_EFL REG_EFL
311   REG_CSGSFS,
312 #define REG_CSGSFS REG_CSGSFS
313   REG_ERR,
314 #define REG_ERR REG_ERR
315   REG_TRAPNO,
316 #define REG_TRAPNO REG_TRAPNO
317   REG_OLDMASK,
318 #define REG_OLDMASK REG_OLDMASK
319   REG_CR2,
320 #define REG_CR2 REG_CR2
321   NGREG
322 #define NGREG NGREG
323 };
324 
325 typedef long greg_t;
326 typedef greg_t gregset_t[NGREG];
327 
328 struct _libc_fpxreg {
329   unsigned short significand[4];
330   unsigned short exponent;
331   unsigned short padding[3];
332 };
333 
334 struct _libc_xmmreg {
335   uint32_t element[4];
336 };
337 
338 struct _libc_fpstate {
339   uint16_t cwd;
340   uint16_t swd;
341   uint16_t ftw;
342   uint16_t fop;
343   uint64_t rip;
344   uint64_t rdp;
345   uint32_t mxcsr;
346   uint32_t mxcr_mask;
347   struct _libc_fpxreg _st[8];
348   struct _libc_xmmreg _xmm[16];
349   uint32_t padding[24];
350 };
351 
352 typedef struct _libc_fpstate* fpregset_t;
353 
354 typedef struct {
355   gregset_t gregs;
356   fpregset_t fpregs;
357   unsigned long __reserved1[8];
358 } mcontext_t;
359 
360 typedef struct ucontext {
361   unsigned long uc_flags;
362   struct ucontext* uc_link;
363   stack_t uc_stack;
364   mcontext_t uc_mcontext;
365   sigset_t uc_sigmask;
366   struct _libc_fpstate __fpregs_mem;
367 } ucontext_t;
368 
369 #endif
370 
371 __END_DECLS
372 
373 #endif /* _SYS_UCONTEXT_H_ */
374