• 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 <signal.h>
33 #include <sys/user.h>
34 
35 __BEGIN_DECLS
36 
37 #if defined(__arm__)
38 
39 enum {
40   REG_R0 = 0,
41   REG_R1,
42   REG_R2,
43   REG_R3,
44   REG_R4,
45   REG_R5,
46   REG_R6,
47   REG_R7,
48   REG_R8,
49   REG_R9,
50   REG_R10,
51   REG_R11,
52   REG_R12,
53   REG_R13,
54   REG_R14,
55   REG_R15,
56 };
57 
58 #define NGREG 18 /* Like glibc. */
59 
60 typedef int greg_t;
61 typedef greg_t gregset_t[NGREG];
62 
63 #include <asm/sigcontext.h>
64 typedef struct sigcontext mcontext_t;
65 
66 typedef struct ucontext {
67   unsigned long uc_flags;
68   struct ucontext* uc_link;
69   stack_t uc_stack;
70   mcontext_t uc_mcontext;
71   // Android has a wrong (smaller) sigset_t on ARM.
72   union {
73     sigset_t bionic;
74     uint32_t kernel[2];
75   } uc_sigmask;
76   // The kernel adds extra padding after uc_sigmask to match glibc sigset_t on ARM.
77   char __padding[120];
78   unsigned long uc_regspace[128] __attribute__((__aligned__(8)));
79 } ucontext_t;
80 
81 #elif defined(__aarch64__)
82 
83 #include <asm/sigcontext.h>
84 typedef struct sigcontext mcontext_t;
85 
86 typedef struct ucontext {
87   unsigned long uc_flags;
88   struct ucontext *uc_link;
89   stack_t uc_stack;
90   sigset_t uc_sigmask;
91   // The kernel adds extra padding after uc_sigmask to match glibc sigset_t on ARM64.
92   char __padding[128 - sizeof(sigset_t)];
93   mcontext_t uc_mcontext;
94 } ucontext_t;
95 
96 #elif defined(__i386__)
97 
98 enum {
99   REG_GS = 0,
100   REG_FS,
101   REG_ES,
102   REG_DS,
103   REG_EDI,
104   REG_ESI,
105   REG_EBP,
106   REG_ESP,
107   REG_EBX,
108   REG_EDX,
109   REG_ECX,
110   REG_EAX,
111   REG_TRAPNO,
112   REG_ERR,
113   REG_EIP,
114   REG_CS,
115   REG_EFL,
116   REG_UESP,
117   REG_SS,
118   NGREG
119 };
120 
121 typedef int greg_t;
122 typedef greg_t gregset_t[NGREG];
123 
124 struct _libc_fpreg {
125   unsigned short significand[4];
126   unsigned short exponent;
127 };
128 
129 struct _libc_fpstate {
130   unsigned long cw;
131   unsigned long sw;
132   unsigned long tag;
133   unsigned long ipoff;
134   unsigned long cssel;
135   unsigned long dataoff;
136   unsigned long datasel;
137   struct _libc_fpreg _st[8];
138   unsigned long status;
139 };
140 
141 typedef struct _libc_fpstate* fpregset_t;
142 
143 typedef struct {
144   gregset_t gregs;
145   fpregset_t fpregs;
146   unsigned long oldmask;
147   unsigned long cr2;
148 } mcontext_t;
149 
150 typedef struct ucontext {
151   unsigned long uc_flags;
152   struct ucontext* uc_link;
153   stack_t uc_stack;
154   mcontext_t uc_mcontext;
155   // Android has a wrong (smaller) sigset_t on x86.
156   union {
157     sigset_t bionic;
158     uint32_t kernel[2];
159   } uc_sigmask;
160   struct _libc_fpstate __fpregs_mem;
161 } ucontext_t;
162 
163 #elif defined(__mips__)
164 
165 /* glibc doesn't have names for MIPS registers. */
166 
167 #define NGREG 32
168 #define NFPREG 32
169 
170 typedef unsigned long long greg_t;
171 typedef greg_t gregset_t[NGREG];
172 
173 typedef struct fpregset {
174   union {
175     double fp_dregs[NFPREG];
176     struct {
177       float _fp_fregs;
178       unsigned _fp_pad;
179     } fp_fregs[NFPREG];
180   } fp_r;
181 } fpregset_t;
182 
183 typedef struct {
184   unsigned regmask;
185   unsigned status;
186   greg_t pc;
187   gregset_t gregs;
188   fpregset_t fpregs;
189   unsigned fp_owned;
190   unsigned fpc_csr;
191   unsigned fpc_eir;
192   unsigned used_math;
193   unsigned dsp;
194   greg_t mdhi;
195   greg_t mdlo;
196   unsigned long hi1;
197   unsigned long lo1;
198   unsigned long hi2;
199   unsigned long lo2;
200   unsigned long hi3;
201   unsigned long lo3;
202 } mcontext_t;
203 
204 typedef struct ucontext {
205   unsigned long uc_flags;
206   struct ucontext* uc_link;
207   stack_t uc_stack;
208   mcontext_t uc_mcontext;
209   sigset_t uc_sigmask;
210 } ucontext_t;
211 
212 #elif defined(__mips64__)
213 
214 #error TODO
215 
216 #elif defined(__x86_64__)
217 
218 enum {
219   REG_R8 = 0,
220   REG_R9,
221   REG_R10,
222   REG_R11,
223   REG_R12,
224   REG_R13,
225   REG_R14,
226   REG_R15,
227   REG_RDI,
228   REG_RSI,
229   REG_RBP,
230   REG_RBX,
231   REG_RDX,
232   REG_RAX,
233   REG_RCX,
234   REG_RSP,
235   REG_RIP,
236   REG_EFL,
237   REG_CSGSFS,
238   REG_ERR,
239   REG_TRAPNO,
240   REG_OLDMASK,
241   REG_CR2,
242   NGREG
243 };
244 
245 typedef long greg_t;
246 typedef greg_t gregset_t[NGREG];
247 
248 struct _libc_fpxreg {
249   unsigned short significand[4];
250   unsigned short exponent;
251   unsigned short padding[3];
252 };
253 
254 struct _libc_xmmreg {
255   uint32_t element[4];
256 };
257 
258 struct _libc_fpstate {
259   uint16_t cwd;
260   uint16_t swd;
261   uint16_t ftw;
262   uint16_t fop;
263   uint64_t rip;
264   uint64_t rdp;
265   uint32_t mxcsr;
266   uint32_t mxcr_mask;
267   struct _libc_fpxreg _st[8];
268   struct _libc_xmmreg _xmm[16];
269   uint32_t padding[24];
270 };
271 
272 typedef struct _libc_fpstate* fpregset_t;
273 
274 typedef struct {
275   gregset_t gregs;
276   fpregset_t fpregs;
277   unsigned long __reserved1[8];
278 } mcontext_t;
279 
280 typedef struct ucontext {
281   unsigned long uc_flags;
282   struct ucontext* uc_link;
283   stack_t uc_stack;
284   mcontext_t uc_mcontext;
285   sigset_t uc_sigmask;
286   struct _libc_fpstate __fpregs_mem;
287 } ucontext_t;
288 
289 #endif
290 
291 __END_DECLS
292 
293 #endif /* _SYS_UCONTEXT_H_ */
294