• 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 #pragma once
30 
31 #include <sys/cdefs.h>
32 
33 #include <signal.h>
34 #include <sys/user.h>
35 
36 __BEGIN_DECLS
37 
38 #if defined(__arm__)
39 
40 enum {
41   REG_R0 = 0,
42 #define REG_R0 REG_R0
43   REG_R1,
44 #define REG_R1 REG_R1
45   REG_R2,
46 #define REG_R2 REG_R2
47   REG_R3,
48 #define REG_R3 REG_R3
49   REG_R4,
50 #define REG_R4 REG_R4
51   REG_R5,
52 #define REG_R5 REG_R5
53   REG_R6,
54 #define REG_R6 REG_R6
55   REG_R7,
56 #define REG_R7 REG_R7
57   REG_R8,
58 #define REG_R8 REG_R8
59   REG_R9,
60 #define REG_R9 REG_R9
61   REG_R10,
62 #define REG_R10 REG_R10
63   REG_R11,
64 #define REG_R11 REG_R11
65   REG_R12,
66 #define REG_R12 REG_R12
67   REG_R13,
68 #define REG_R13 REG_R13
69   REG_R14,
70 #define REG_R14 REG_R14
71   REG_R15,
72 #define REG_R15 REG_R15
73 };
74 
75 #define NGREG 18 /* Like glibc. */
76 
77 typedef int greg_t;
78 typedef greg_t gregset_t[NGREG];
79 typedef struct user_fpregs fpregset_t;
80 
81 #include <asm/sigcontext.h>
82 typedef struct sigcontext mcontext_t;
83 
84 typedef struct ucontext {
85   unsigned long uc_flags;
86   struct ucontext* uc_link;
87   stack_t uc_stack;
88   mcontext_t uc_mcontext;
89   union {
90     struct {
91       sigset_t uc_sigmask;
92       /* Android has a wrong (smaller) sigset_t on ARM. */
93       uint32_t __padding_rt_sigset;
94     };
95     sigset64_t uc_sigmask64;
96   };
97   /* The kernel adds extra padding after uc_sigmask to match glibc sigset_t on ARM. */
98   char __padding[120];
99   unsigned long uc_regspace[128] __attribute__((__aligned__(8)));
100 } ucontext_t;
101 
102 #elif defined(__aarch64__)
103 
104 #define NGREG 34 /* x0..x30 + sp + pc + pstate */
105 typedef unsigned long greg_t;
106 typedef greg_t gregset_t[NGREG];
107 typedef struct user_fpsimd_struct fpregset_t;
108 
109 #include <asm/sigcontext.h>
110 typedef struct sigcontext mcontext_t;
111 
112 typedef struct ucontext {
113   unsigned long uc_flags;
114   struct ucontext *uc_link;
115   stack_t uc_stack;
116   union {
117     sigset_t uc_sigmask;
118     sigset64_t uc_sigmask64;
119   };
120   /* The kernel adds extra padding after uc_sigmask to match glibc sigset_t on ARM64. */
121   char __padding[128 - sizeof(sigset_t)];
122   mcontext_t uc_mcontext;
123 } ucontext_t;
124 
125 #elif defined(__i386__)
126 
127 enum {
128   REG_GS = 0,
129 #define REG_GS REG_GS
130   REG_FS,
131 #define REG_FS REG_FS
132   REG_ES,
133 #define REG_ES REG_ES
134   REG_DS,
135 #define REG_DS REG_DS
136   REG_EDI,
137 #define REG_EDI REG_EDI
138   REG_ESI,
139 #define REG_ESI REG_ESI
140   REG_EBP,
141 #define REG_EBP REG_EBP
142   REG_ESP,
143 #define REG_ESP REG_ESP
144   REG_EBX,
145 #define REG_EBX REG_EBX
146   REG_EDX,
147 #define REG_EDX REG_EDX
148   REG_ECX,
149 #define REG_ECX REG_ECX
150   REG_EAX,
151 #define REG_EAX REG_EAX
152   REG_TRAPNO,
153 #define REG_TRAPNO REG_TRAPNO
154   REG_ERR,
155 #define REG_ERR REG_ERR
156   REG_EIP,
157 #define REG_EIP REG_EIP
158   REG_CS,
159 #define REG_CS REG_CS
160   REG_EFL,
161 #define REG_EFL REG_EFL
162   REG_UESP,
163 #define REG_UESP REG_UESP
164   REG_SS,
165 #define REG_SS REG_SS
166   NGREG
167 #define NGREG NGREG
168 };
169 
170 typedef int greg_t;
171 typedef greg_t gregset_t[NGREG];
172 
173 struct _libc_fpreg {
174   unsigned short significand[4];
175   unsigned short exponent;
176 };
177 
178 struct _libc_fpstate {
179   unsigned long cw;
180   unsigned long sw;
181   unsigned long tag;
182   unsigned long ipoff;
183   unsigned long cssel;
184   unsigned long dataoff;
185   unsigned long datasel;
186   struct _libc_fpreg _st[8];
187   unsigned long status;
188 };
189 
190 typedef struct _libc_fpstate* fpregset_t;
191 
192 typedef struct {
193   gregset_t gregs;
194   fpregset_t fpregs;
195   unsigned long oldmask;
196   unsigned long cr2;
197 } mcontext_t;
198 
199 typedef struct ucontext {
200   unsigned long uc_flags;
201   struct ucontext* uc_link;
202   stack_t uc_stack;
203   mcontext_t uc_mcontext;
204   union {
205     struct {
206       sigset_t uc_sigmask;
207       /* Android has a wrong (smaller) sigset_t on x86. */
208       uint32_t __padding_rt_sigset;
209     };
210     sigset64_t uc_sigmask64;
211   };
212   struct _libc_fpstate __fpregs_mem;
213 } ucontext_t;
214 
215 #elif defined(__x86_64__)
216 
217 enum {
218   REG_R8 = 0,
219 #define REG_R8 REG_R8
220   REG_R9,
221 #define REG_R9 REG_R9
222   REG_R10,
223 #define REG_R10 REG_R10
224   REG_R11,
225 #define REG_R11 REG_R11
226   REG_R12,
227 #define REG_R12 REG_R12
228   REG_R13,
229 #define REG_R13 REG_R13
230   REG_R14,
231 #define REG_R14 REG_R14
232   REG_R15,
233 #define REG_R15 REG_R15
234   REG_RDI,
235 #define REG_RDI REG_RDI
236   REG_RSI,
237 #define REG_RSI REG_RSI
238   REG_RBP,
239 #define REG_RBP REG_RBP
240   REG_RBX,
241 #define REG_RBX REG_RBX
242   REG_RDX,
243 #define REG_RDX REG_RDX
244   REG_RAX,
245 #define REG_RAX REG_RAX
246   REG_RCX,
247 #define REG_RCX REG_RCX
248   REG_RSP,
249 #define REG_RSP REG_RSP
250   REG_RIP,
251 #define REG_RIP REG_RIP
252   REG_EFL,
253 #define REG_EFL REG_EFL
254   REG_CSGSFS,
255 #define REG_CSGSFS REG_CSGSFS
256   REG_ERR,
257 #define REG_ERR REG_ERR
258   REG_TRAPNO,
259 #define REG_TRAPNO REG_TRAPNO
260   REG_OLDMASK,
261 #define REG_OLDMASK REG_OLDMASK
262   REG_CR2,
263 #define REG_CR2 REG_CR2
264   NGREG
265 #define NGREG NGREG
266 };
267 
268 typedef long greg_t;
269 typedef greg_t gregset_t[NGREG];
270 
271 struct _libc_fpxreg {
272   unsigned short significand[4];
273   unsigned short exponent;
274   unsigned short padding[3];
275 };
276 
277 struct _libc_xmmreg {
278   uint32_t element[4];
279 };
280 
281 struct _libc_fpstate {
282   uint16_t cwd;
283   uint16_t swd;
284   uint16_t ftw;
285   uint16_t fop;
286   uint64_t rip;
287   uint64_t rdp;
288   uint32_t mxcsr;
289   uint32_t mxcr_mask;
290   struct _libc_fpxreg _st[8];
291   struct _libc_xmmreg _xmm[16];
292   uint32_t padding[24];
293 };
294 
295 typedef struct _libc_fpstate* fpregset_t;
296 
297 typedef struct {
298   gregset_t gregs;
299   fpregset_t fpregs;
300   unsigned long __reserved1[8];
301 } mcontext_t;
302 
303 typedef struct ucontext {
304   unsigned long uc_flags;
305   struct ucontext* uc_link;
306   stack_t uc_stack;
307   mcontext_t uc_mcontext;
308   union {
309     sigset_t uc_sigmask;
310     sigset64_t uc_sigmask64;
311   };
312   struct _libc_fpstate __fpregs_mem;
313 } ucontext_t;
314 
315 #elif defined(__riscv)
316 
317 #define NGREG 32
318 
319 #if defined(__USE_GNU)
320 
321 #define REG_PC 0
322 #define REG_RA 1
323 #define REG_SP 2
324 #define REG_TP 4
325 #define REG_S0 8
326 #define REG_A0 10
327 
328 #endif // defined(__USE_GNU)
329 
330 typedef unsigned long __riscv_mc_gp_state[NGREG];
331 
332 typedef unsigned long greg_t;
333 typedef unsigned long gregset_t[NGREG];
334 typedef union __riscv_mc_fp_state fpregset_t;
335 
336 /* These match the kernel <asm/ptrace.h> types but with different names. */
337 
338 struct __riscv_mc_f_ext_state {
339   uint32_t __f[32];
340   uint32_t __fcsr;
341 };
342 
343 struct __riscv_mc_d_ext_state {
344   uint64_t __f[32];
345   uint32_t __fcsr;
346 };
347 
348 struct __riscv_mc_q_ext_state {
349   uint64_t __f[64] __attribute__((__aligned__(16)));
350   uint32_t __fcsr;
351   uint32_t __reserved[3];
352 };
353 
354 union __riscv_mc_fp_state {
355   struct __riscv_mc_f_ext_state __f;
356   struct __riscv_mc_d_ext_state __d;
357   struct __riscv_mc_q_ext_state __q;
358 };
359 
360 /* This matches the kernel <asm/sigcontext.h> but with different names. */
361 
362 typedef struct mcontext_t {
363   __riscv_mc_gp_state __gregs;
364   union __riscv_mc_fp_state __fpregs;
365 } mcontext_t;
366 
367 /* This matches the kernel <asm/ucontext.h> but using mcontext_t. */
368 
369 typedef struct ucontext {
370   unsigned long uc_flags;
371   struct ucontext* uc_link;
372   stack_t uc_stack;
373   union {
374     sigset_t uc_sigmask;
375     sigset64_t uc_sigmask64;
376   };
377   /* The kernel adds extra padding here to allow sigset_t to grow. */
378   char __padding[128 - sizeof(sigset_t)];
379   mcontext_t uc_mcontext;
380 } ucontext_t;
381 
382 #endif
383 
384 __END_DECLS
385