blob: 8bd8c3bf1c833cd94d7e6751752c1317a6b08a58 [file] [log] [blame]
Pavel Chupine61d1062014-01-27 17:56:43 +04001/*
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
Elliott Hughes677a07c2014-01-29 16:46:00 -080037#if defined(__arm__)
38
Elliott Hughes4e72fcc2014-01-29 17:53:59 -080039enum {
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
60typedef int greg_t;
61typedef greg_t gregset_t[NGREG];
Dan Albertbf18c612015-03-04 10:31:29 -080062typedef struct user_fpregs fpregset_t;
Elliott Hughes4e72fcc2014-01-29 17:53:59 -080063
Elliott Hughes4e72fcc2014-01-29 17:53:59 -080064#include <asm/sigcontext.h>
65typedef struct sigcontext mcontext_t;
66
67typedef struct ucontext {
68 unsigned long uc_flags;
69 struct ucontext* uc_link;
70 stack_t uc_stack;
71 mcontext_t uc_mcontext;
Elliott Hughes26a8eb52014-09-12 20:04:40 -070072 sigset_t uc_sigmask;
Calin Juravlebdca3802014-05-28 15:56:46 +010073 // Android has a wrong (smaller) sigset_t on ARM.
Elliott Hughes26a8eb52014-09-12 20:04:40 -070074 uint32_t __padding_rt_sigset;
Calin Juravlebdca3802014-05-28 15:56:46 +010075 // The kernel adds extra padding after uc_sigmask to match glibc sigset_t on ARM.
76 char __padding[120];
Calin Juravle0e85fb62014-05-19 19:14:03 +010077 unsigned long uc_regspace[128] __attribute__((__aligned__(8)));
Elliott Hughes4e72fcc2014-01-29 17:53:59 -080078} ucontext_t;
Elliott Hughes677a07c2014-01-29 16:46:00 -080079
Ross McIlroy7b958072014-01-31 04:45:53 +000080#elif defined(__aarch64__)
Elliott Hughes677a07c2014-01-29 16:46:00 -080081
Elliott Hughes8e4d3712014-09-19 10:31:49 -070082#define NGREG 34 /* x0..x30 + sp + pc + pstate */
83typedef unsigned long greg_t;
84typedef greg_t gregset_t[NGREG];
85
Dan Albertbf18c612015-03-04 10:31:29 -080086struct user_fpsimd_state {
87 long double vregs[32];
88 uint32_t fpsr;
89 uint32_t fpcr;
90};
91typedef struct user_fpsimd_state fpregset_t;
92
Ross McIlroy7b958072014-01-31 04:45:53 +000093#include <asm/sigcontext.h>
94typedef struct sigcontext mcontext_t;
95
96typedef struct ucontext {
97 unsigned long uc_flags;
98 struct ucontext *uc_link;
99 stack_t uc_stack;
100 sigset_t uc_sigmask;
Calin Juravlebdca3802014-05-28 15:56:46 +0100101 // The kernel adds extra padding after uc_sigmask to match glibc sigset_t on ARM64.
Elliott Hughes50249bc2014-04-07 14:36:59 -0700102 char __padding[128 - sizeof(sigset_t)];
Ross McIlroy7b958072014-01-31 04:45:53 +0000103 mcontext_t uc_mcontext;
104} ucontext_t;
Elliott Hughes677a07c2014-01-29 16:46:00 -0800105
106#elif defined(__i386__)
107
108enum {
109 REG_GS = 0,
110 REG_FS,
111 REG_ES,
112 REG_DS,
113 REG_EDI,
114 REG_ESI,
115 REG_EBP,
116 REG_ESP,
117 REG_EBX,
118 REG_EDX,
119 REG_ECX,
120 REG_EAX,
121 REG_TRAPNO,
122 REG_ERR,
123 REG_EIP,
124 REG_CS,
125 REG_EFL,
126 REG_UESP,
127 REG_SS,
128 NGREG
129};
130
131typedef int greg_t;
132typedef greg_t gregset_t[NGREG];
133
134struct _libc_fpreg {
135 unsigned short significand[4];
136 unsigned short exponent;
137};
138
139struct _libc_fpstate {
140 unsigned long cw;
141 unsigned long sw;
142 unsigned long tag;
143 unsigned long ipoff;
144 unsigned long cssel;
145 unsigned long dataoff;
146 unsigned long datasel;
147 struct _libc_fpreg _st[8];
148 unsigned long status;
149};
150
151typedef struct _libc_fpstate* fpregset_t;
152
153typedef struct {
154 gregset_t gregs;
155 fpregset_t fpregs;
156 unsigned long oldmask;
157 unsigned long cr2;
158} mcontext_t;
159
160typedef struct ucontext {
161 unsigned long uc_flags;
162 struct ucontext* uc_link;
163 stack_t uc_stack;
164 mcontext_t uc_mcontext;
Elliott Hughes26a8eb52014-09-12 20:04:40 -0700165 sigset_t uc_sigmask;
Calin Juravlebdca3802014-05-28 15:56:46 +0100166 // Android has a wrong (smaller) sigset_t on x86.
Elliott Hughes26a8eb52014-09-12 20:04:40 -0700167 uint32_t __padding_rt_sigset;
Calin Juravlea6ab9682014-05-13 20:29:01 +0100168 struct _libc_fpstate __fpregs_mem;
Elliott Hughes677a07c2014-01-29 16:46:00 -0800169} ucontext_t;
170
171#elif defined(__mips__)
172
Elliott Hughes02c661b2014-01-29 18:37:15 -0800173/* glibc doesn't have names for MIPS registers. */
174
175#define NGREG 32
176#define NFPREG 32
177
178typedef unsigned long long greg_t;
179typedef greg_t gregset_t[NGREG];
180
181typedef struct fpregset {
182 union {
183 double fp_dregs[NFPREG];
184 struct {
185 float _fp_fregs;
186 unsigned _fp_pad;
187 } fp_fregs[NFPREG];
188 } fp_r;
189} fpregset_t;
190
Faraz Shahbazkere247e1c2015-01-05 13:27:30 -0800191#ifdef __LP64__
192typedef struct {
193 gregset_t gregs;
194 fpregset_t fpregs;
195 greg_t mdhi;
196 greg_t hi1;
197 greg_t hi2;
198 greg_t hi3;
199 greg_t mdlo;
200 greg_t lo1;
201 greg_t lo2;
202 greg_t lo3;
203 greg_t pc;
204 uint32_t fpc_csr;
205 uint32_t used_math;
206 uint32_t dsp;
207 uint32_t reserved;
208} mcontext_t;
209#else
Elliott Hughes02c661b2014-01-29 18:37:15 -0800210typedef struct {
211 unsigned regmask;
212 unsigned status;
213 greg_t pc;
214 gregset_t gregs;
215 fpregset_t fpregs;
216 unsigned fp_owned;
217 unsigned fpc_csr;
218 unsigned fpc_eir;
219 unsigned used_math;
220 unsigned dsp;
221 greg_t mdhi;
222 greg_t mdlo;
223 unsigned long hi1;
224 unsigned long lo1;
225 unsigned long hi2;
226 unsigned long lo2;
227 unsigned long hi3;
228 unsigned long lo3;
229} mcontext_t;
Faraz Shahbazkere247e1c2015-01-05 13:27:30 -0800230#endif
Elliott Hughes02c661b2014-01-29 18:37:15 -0800231
232typedef struct ucontext {
233 unsigned long uc_flags;
234 struct ucontext* uc_link;
235 stack_t uc_stack;
236 mcontext_t uc_mcontext;
237 sigset_t uc_sigmask;
238} ucontext_t;
Elliott Hughes677a07c2014-01-29 16:46:00 -0800239
Elliott Hughes677a07c2014-01-29 16:46:00 -0800240#elif defined(__x86_64__)
Pavel Chupine61d1062014-01-27 17:56:43 +0400241
242enum {
243 REG_R8 = 0,
244 REG_R9,
245 REG_R10,
246 REG_R11,
247 REG_R12,
248 REG_R13,
249 REG_R14,
250 REG_R15,
251 REG_RDI,
252 REG_RSI,
253 REG_RBP,
254 REG_RBX,
255 REG_RDX,
256 REG_RAX,
257 REG_RCX,
258 REG_RSP,
259 REG_RIP,
260 REG_EFL,
261 REG_CSGSFS,
262 REG_ERR,
263 REG_TRAPNO,
264 REG_OLDMASK,
265 REG_CR2,
266 NGREG
267};
268
269typedef long greg_t;
270typedef greg_t gregset_t[NGREG];
271
Calin Juravlea6ab9682014-05-13 20:29:01 +0100272struct _libc_fpxreg {
273 unsigned short significand[4];
274 unsigned short exponent;
275 unsigned short padding[3];
276};
277
278struct _libc_xmmreg {
279 uint32_t element[4];
280};
281
282struct _libc_fpstate {
283 uint16_t cwd;
284 uint16_t swd;
285 uint16_t ftw;
286 uint16_t fop;
287 uint64_t rip;
288 uint64_t rdp;
289 uint32_t mxcsr;
290 uint32_t mxcr_mask;
291 struct _libc_fpxreg _st[8];
292 struct _libc_xmmreg _xmm[16];
293 uint32_t padding[24];
294};
295
296typedef struct _libc_fpstate* fpregset_t;
Pavel Chupine61d1062014-01-27 17:56:43 +0400297
298typedef struct {
299 gregset_t gregs;
300 fpregset_t fpregs;
Elliott Hughesc5992a02014-04-09 13:27:48 -0700301 unsigned long __reserved1[8];
Pavel Chupine61d1062014-01-27 17:56:43 +0400302} mcontext_t;
303
304typedef struct ucontext {
305 unsigned long uc_flags;
306 struct ucontext* uc_link;
307 stack_t uc_stack;
308 mcontext_t uc_mcontext;
309 sigset_t uc_sigmask;
Calin Juravlea6ab9682014-05-13 20:29:01 +0100310 struct _libc_fpstate __fpregs_mem;
Pavel Chupine61d1062014-01-27 17:56:43 +0400311} ucontext_t;
312
Elliott Hughes677a07c2014-01-29 16:46:00 -0800313#endif
Pavel Chupine61d1062014-01-27 17:56:43 +0400314
315__END_DECLS
316
317#endif /* _SYS_UCONTEXT_H_ */