blob: fdb3015f75ff41dec8bd238ce44ec0a2fe2273da [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>
Elliott Hughes203e13d2016-07-22 14:56:18 -070033#include <sys/cdefs.h>
Pavel Chupine61d1062014-01-27 17:56:43 +040034#include <sys/user.h>
35
36__BEGIN_DECLS
37
Elliott Hughes677a07c2014-01-29 16:46:00 -080038#if defined(__arm__)
39
Elliott Hughes4e72fcc2014-01-29 17:53:59 -080040enum {
41 REG_R0 = 0,
42 REG_R1,
43 REG_R2,
44 REG_R3,
45 REG_R4,
46 REG_R5,
47 REG_R6,
48 REG_R7,
49 REG_R8,
50 REG_R9,
51 REG_R10,
52 REG_R11,
53 REG_R12,
54 REG_R13,
55 REG_R14,
56 REG_R15,
57};
58
59#define NGREG 18 /* Like glibc. */
60
61typedef int greg_t;
62typedef greg_t gregset_t[NGREG];
Dan Albertbf18c612015-03-04 10:31:29 -080063typedef struct user_fpregs fpregset_t;
Elliott Hughes4e72fcc2014-01-29 17:53:59 -080064
Elliott Hughes4e72fcc2014-01-29 17:53:59 -080065#include <asm/sigcontext.h>
66typedef struct sigcontext mcontext_t;
67
68typedef struct ucontext {
69 unsigned long uc_flags;
70 struct ucontext* uc_link;
71 stack_t uc_stack;
72 mcontext_t uc_mcontext;
Elliott Hughes26a8eb52014-09-12 20:04:40 -070073 sigset_t uc_sigmask;
Elliott Hughes3ba55f82016-06-08 18:11:23 -070074 /* Android has a wrong (smaller) sigset_t on ARM. */
Elliott Hughes26a8eb52014-09-12 20:04:40 -070075 uint32_t __padding_rt_sigset;
Elliott Hughes3ba55f82016-06-08 18:11:23 -070076 /* The kernel adds extra padding after uc_sigmask to match glibc sigset_t on ARM. */
Calin Juravlebdca3802014-05-28 15:56:46 +010077 char __padding[120];
Calin Juravle0e85fb62014-05-19 19:14:03 +010078 unsigned long uc_regspace[128] __attribute__((__aligned__(8)));
Elliott Hughes4e72fcc2014-01-29 17:53:59 -080079} ucontext_t;
Elliott Hughes677a07c2014-01-29 16:46:00 -080080
Ross McIlroy7b958072014-01-31 04:45:53 +000081#elif defined(__aarch64__)
Elliott Hughes677a07c2014-01-29 16:46:00 -080082
Elliott Hughes8e4d3712014-09-19 10:31:49 -070083#define NGREG 34 /* x0..x30 + sp + pc + pstate */
84typedef unsigned long greg_t;
85typedef greg_t gregset_t[NGREG];
Elliott Hughes05777332015-06-15 18:47:39 -070086typedef struct user_fpsimd_struct fpregset_t;
Dan Albertbf18c612015-03-04 10:31:29 -080087
Ross McIlroy7b958072014-01-31 04:45:53 +000088#include <asm/sigcontext.h>
89typedef struct sigcontext mcontext_t;
90
91typedef struct ucontext {
92 unsigned long uc_flags;
93 struct ucontext *uc_link;
94 stack_t uc_stack;
95 sigset_t uc_sigmask;
Elliott Hughes3ba55f82016-06-08 18:11:23 -070096 /* The kernel adds extra padding after uc_sigmask to match glibc sigset_t on ARM64. */
Elliott Hughes50249bc2014-04-07 14:36:59 -070097 char __padding[128 - sizeof(sigset_t)];
Ross McIlroy7b958072014-01-31 04:45:53 +000098 mcontext_t uc_mcontext;
99} ucontext_t;
Elliott Hughes677a07c2014-01-29 16:46:00 -0800100
101#elif defined(__i386__)
102
103enum {
104 REG_GS = 0,
105 REG_FS,
106 REG_ES,
107 REG_DS,
108 REG_EDI,
109 REG_ESI,
110 REG_EBP,
111 REG_ESP,
112 REG_EBX,
113 REG_EDX,
114 REG_ECX,
115 REG_EAX,
116 REG_TRAPNO,
117 REG_ERR,
118 REG_EIP,
119 REG_CS,
120 REG_EFL,
121 REG_UESP,
122 REG_SS,
123 NGREG
124};
125
126typedef int greg_t;
127typedef greg_t gregset_t[NGREG];
128
129struct _libc_fpreg {
130 unsigned short significand[4];
131 unsigned short exponent;
132};
133
134struct _libc_fpstate {
135 unsigned long cw;
136 unsigned long sw;
137 unsigned long tag;
138 unsigned long ipoff;
139 unsigned long cssel;
140 unsigned long dataoff;
141 unsigned long datasel;
142 struct _libc_fpreg _st[8];
143 unsigned long status;
144};
145
146typedef struct _libc_fpstate* fpregset_t;
147
148typedef struct {
149 gregset_t gregs;
150 fpregset_t fpregs;
151 unsigned long oldmask;
152 unsigned long cr2;
153} mcontext_t;
154
155typedef struct ucontext {
156 unsigned long uc_flags;
157 struct ucontext* uc_link;
158 stack_t uc_stack;
159 mcontext_t uc_mcontext;
Elliott Hughes26a8eb52014-09-12 20:04:40 -0700160 sigset_t uc_sigmask;
Elliott Hughes3ba55f82016-06-08 18:11:23 -0700161 /* Android has a wrong (smaller) sigset_t on x86. */
Elliott Hughes26a8eb52014-09-12 20:04:40 -0700162 uint32_t __padding_rt_sigset;
Calin Juravlea6ab9682014-05-13 20:29:01 +0100163 struct _libc_fpstate __fpregs_mem;
Elliott Hughes677a07c2014-01-29 16:46:00 -0800164} ucontext_t;
165
166#elif defined(__mips__)
167
Elliott Hughes02c661b2014-01-29 18:37:15 -0800168/* glibc doesn't have names for MIPS registers. */
169
170#define NGREG 32
171#define NFPREG 32
172
173typedef unsigned long long greg_t;
174typedef greg_t gregset_t[NGREG];
175
176typedef struct fpregset {
177 union {
178 double fp_dregs[NFPREG];
179 struct {
180 float _fp_fregs;
181 unsigned _fp_pad;
182 } fp_fregs[NFPREG];
183 } fp_r;
184} fpregset_t;
185
Faraz Shahbazkere247e1c2015-01-05 13:27:30 -0800186#ifdef __LP64__
187typedef struct {
188 gregset_t gregs;
189 fpregset_t fpregs;
190 greg_t mdhi;
191 greg_t hi1;
192 greg_t hi2;
193 greg_t hi3;
194 greg_t mdlo;
195 greg_t lo1;
196 greg_t lo2;
197 greg_t lo3;
198 greg_t pc;
199 uint32_t fpc_csr;
200 uint32_t used_math;
201 uint32_t dsp;
202 uint32_t reserved;
203} mcontext_t;
204#else
Elliott Hughes02c661b2014-01-29 18:37:15 -0800205typedef struct {
206 unsigned regmask;
207 unsigned status;
208 greg_t pc;
209 gregset_t gregs;
210 fpregset_t fpregs;
211 unsigned fp_owned;
212 unsigned fpc_csr;
213 unsigned fpc_eir;
214 unsigned used_math;
215 unsigned dsp;
216 greg_t mdhi;
217 greg_t mdlo;
218 unsigned long hi1;
219 unsigned long lo1;
220 unsigned long hi2;
221 unsigned long lo2;
222 unsigned long hi3;
223 unsigned long lo3;
224} mcontext_t;
Faraz Shahbazkere247e1c2015-01-05 13:27:30 -0800225#endif
Elliott Hughes02c661b2014-01-29 18:37:15 -0800226
227typedef struct ucontext {
228 unsigned long uc_flags;
229 struct ucontext* uc_link;
230 stack_t uc_stack;
231 mcontext_t uc_mcontext;
232 sigset_t uc_sigmask;
233} ucontext_t;
Elliott Hughes677a07c2014-01-29 16:46:00 -0800234
Elliott Hughes677a07c2014-01-29 16:46:00 -0800235#elif defined(__x86_64__)
Pavel Chupine61d1062014-01-27 17:56:43 +0400236
237enum {
238 REG_R8 = 0,
239 REG_R9,
240 REG_R10,
241 REG_R11,
242 REG_R12,
243 REG_R13,
244 REG_R14,
245 REG_R15,
246 REG_RDI,
247 REG_RSI,
248 REG_RBP,
249 REG_RBX,
250 REG_RDX,
251 REG_RAX,
252 REG_RCX,
253 REG_RSP,
254 REG_RIP,
255 REG_EFL,
256 REG_CSGSFS,
257 REG_ERR,
258 REG_TRAPNO,
259 REG_OLDMASK,
260 REG_CR2,
261 NGREG
262};
263
264typedef long greg_t;
265typedef greg_t gregset_t[NGREG];
266
Calin Juravlea6ab9682014-05-13 20:29:01 +0100267struct _libc_fpxreg {
268 unsigned short significand[4];
269 unsigned short exponent;
270 unsigned short padding[3];
271};
272
273struct _libc_xmmreg {
274 uint32_t element[4];
275};
276
277struct _libc_fpstate {
278 uint16_t cwd;
279 uint16_t swd;
280 uint16_t ftw;
281 uint16_t fop;
282 uint64_t rip;
283 uint64_t rdp;
284 uint32_t mxcsr;
285 uint32_t mxcr_mask;
286 struct _libc_fpxreg _st[8];
287 struct _libc_xmmreg _xmm[16];
288 uint32_t padding[24];
289};
290
291typedef struct _libc_fpstate* fpregset_t;
Pavel Chupine61d1062014-01-27 17:56:43 +0400292
293typedef struct {
294 gregset_t gregs;
295 fpregset_t fpregs;
Elliott Hughesc5992a02014-04-09 13:27:48 -0700296 unsigned long __reserved1[8];
Pavel Chupine61d1062014-01-27 17:56:43 +0400297} mcontext_t;
298
299typedef struct ucontext {
300 unsigned long uc_flags;
301 struct ucontext* uc_link;
302 stack_t uc_stack;
303 mcontext_t uc_mcontext;
304 sigset_t uc_sigmask;
Calin Juravlea6ab9682014-05-13 20:29:01 +0100305 struct _libc_fpstate __fpregs_mem;
Pavel Chupine61d1062014-01-27 17:56:43 +0400306} ucontext_t;
307
Elliott Hughes677a07c2014-01-29 16:46:00 -0800308#endif
Pavel Chupine61d1062014-01-27 17:56:43 +0400309
310__END_DECLS
311
312#endif /* _SYS_UCONTEXT_H_ */