blob: b68d704b065ae0cfd62279a0737249927f6d1161 [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];
62
Elliott Hughes4e72fcc2014-01-29 17:53:59 -080063#include <asm/sigcontext.h>
64typedef struct sigcontext mcontext_t;
65
66typedef struct ucontext {
67 unsigned long uc_flags;
68 struct ucontext* uc_link;
69 stack_t uc_stack;
70 mcontext_t uc_mcontext;
Elliott Hughes26a8eb52014-09-12 20:04:40 -070071 sigset_t uc_sigmask;
Calin Juravlebdca3802014-05-28 15:56:46 +010072 // Android has a wrong (smaller) sigset_t on ARM.
Elliott Hughes26a8eb52014-09-12 20:04:40 -070073 uint32_t __padding_rt_sigset;
Calin Juravlebdca3802014-05-28 15:56:46 +010074 // The kernel adds extra padding after uc_sigmask to match glibc sigset_t on ARM.
75 char __padding[120];
Calin Juravle0e85fb62014-05-19 19:14:03 +010076 unsigned long uc_regspace[128] __attribute__((__aligned__(8)));
Elliott Hughes4e72fcc2014-01-29 17:53:59 -080077} ucontext_t;
Elliott Hughes677a07c2014-01-29 16:46:00 -080078
Ross McIlroy7b958072014-01-31 04:45:53 +000079#elif defined(__aarch64__)
Elliott Hughes677a07c2014-01-29 16:46:00 -080080
Elliott Hughes8e4d3712014-09-19 10:31:49 -070081#define NGREG 34 /* x0..x30 + sp + pc + pstate */
82typedef unsigned long greg_t;
83typedef greg_t gregset_t[NGREG];
84
Ross McIlroy7b958072014-01-31 04:45:53 +000085#include <asm/sigcontext.h>
86typedef struct sigcontext mcontext_t;
87
88typedef struct ucontext {
89 unsigned long uc_flags;
90 struct ucontext *uc_link;
91 stack_t uc_stack;
92 sigset_t uc_sigmask;
Calin Juravlebdca3802014-05-28 15:56:46 +010093 // The kernel adds extra padding after uc_sigmask to match glibc sigset_t on ARM64.
Elliott Hughes50249bc2014-04-07 14:36:59 -070094 char __padding[128 - sizeof(sigset_t)];
Ross McIlroy7b958072014-01-31 04:45:53 +000095 mcontext_t uc_mcontext;
96} ucontext_t;
Elliott Hughes677a07c2014-01-29 16:46:00 -080097
98#elif defined(__i386__)
99
100enum {
101 REG_GS = 0,
102 REG_FS,
103 REG_ES,
104 REG_DS,
105 REG_EDI,
106 REG_ESI,
107 REG_EBP,
108 REG_ESP,
109 REG_EBX,
110 REG_EDX,
111 REG_ECX,
112 REG_EAX,
113 REG_TRAPNO,
114 REG_ERR,
115 REG_EIP,
116 REG_CS,
117 REG_EFL,
118 REG_UESP,
119 REG_SS,
120 NGREG
121};
122
123typedef int greg_t;
124typedef greg_t gregset_t[NGREG];
125
126struct _libc_fpreg {
127 unsigned short significand[4];
128 unsigned short exponent;
129};
130
131struct _libc_fpstate {
132 unsigned long cw;
133 unsigned long sw;
134 unsigned long tag;
135 unsigned long ipoff;
136 unsigned long cssel;
137 unsigned long dataoff;
138 unsigned long datasel;
139 struct _libc_fpreg _st[8];
140 unsigned long status;
141};
142
143typedef struct _libc_fpstate* fpregset_t;
144
145typedef struct {
146 gregset_t gregs;
147 fpregset_t fpregs;
148 unsigned long oldmask;
149 unsigned long cr2;
150} mcontext_t;
151
152typedef struct ucontext {
153 unsigned long uc_flags;
154 struct ucontext* uc_link;
155 stack_t uc_stack;
156 mcontext_t uc_mcontext;
Elliott Hughes26a8eb52014-09-12 20:04:40 -0700157 sigset_t uc_sigmask;
Calin Juravlebdca3802014-05-28 15:56:46 +0100158 // Android has a wrong (smaller) sigset_t on x86.
Elliott Hughes26a8eb52014-09-12 20:04:40 -0700159 uint32_t __padding_rt_sigset;
Calin Juravlea6ab9682014-05-13 20:29:01 +0100160 struct _libc_fpstate __fpregs_mem;
Elliott Hughes677a07c2014-01-29 16:46:00 -0800161} ucontext_t;
162
163#elif defined(__mips__)
164
Elliott Hughes02c661b2014-01-29 18:37:15 -0800165/* glibc doesn't have names for MIPS registers. */
166
167#define NGREG 32
168#define NFPREG 32
169
170typedef unsigned long long greg_t;
171typedef greg_t gregset_t[NGREG];
172
173typedef 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
Faraz Shahbazkere247e1c2015-01-05 13:27:30 -0800183#ifdef __LP64__
184typedef struct {
185 gregset_t gregs;
186 fpregset_t fpregs;
187 greg_t mdhi;
188 greg_t hi1;
189 greg_t hi2;
190 greg_t hi3;
191 greg_t mdlo;
192 greg_t lo1;
193 greg_t lo2;
194 greg_t lo3;
195 greg_t pc;
196 uint32_t fpc_csr;
197 uint32_t used_math;
198 uint32_t dsp;
199 uint32_t reserved;
200} mcontext_t;
201#else
Elliott Hughes02c661b2014-01-29 18:37:15 -0800202typedef struct {
203 unsigned regmask;
204 unsigned status;
205 greg_t pc;
206 gregset_t gregs;
207 fpregset_t fpregs;
208 unsigned fp_owned;
209 unsigned fpc_csr;
210 unsigned fpc_eir;
211 unsigned used_math;
212 unsigned dsp;
213 greg_t mdhi;
214 greg_t mdlo;
215 unsigned long hi1;
216 unsigned long lo1;
217 unsigned long hi2;
218 unsigned long lo2;
219 unsigned long hi3;
220 unsigned long lo3;
221} mcontext_t;
Faraz Shahbazkere247e1c2015-01-05 13:27:30 -0800222#endif
Elliott Hughes02c661b2014-01-29 18:37:15 -0800223
224typedef struct ucontext {
225 unsigned long uc_flags;
226 struct ucontext* uc_link;
227 stack_t uc_stack;
228 mcontext_t uc_mcontext;
229 sigset_t uc_sigmask;
230} ucontext_t;
Elliott Hughes677a07c2014-01-29 16:46:00 -0800231
Elliott Hughes677a07c2014-01-29 16:46:00 -0800232#elif defined(__x86_64__)
Pavel Chupine61d1062014-01-27 17:56:43 +0400233
234enum {
235 REG_R8 = 0,
236 REG_R9,
237 REG_R10,
238 REG_R11,
239 REG_R12,
240 REG_R13,
241 REG_R14,
242 REG_R15,
243 REG_RDI,
244 REG_RSI,
245 REG_RBP,
246 REG_RBX,
247 REG_RDX,
248 REG_RAX,
249 REG_RCX,
250 REG_RSP,
251 REG_RIP,
252 REG_EFL,
253 REG_CSGSFS,
254 REG_ERR,
255 REG_TRAPNO,
256 REG_OLDMASK,
257 REG_CR2,
258 NGREG
259};
260
261typedef long greg_t;
262typedef greg_t gregset_t[NGREG];
263
Calin Juravlea6ab9682014-05-13 20:29:01 +0100264struct _libc_fpxreg {
265 unsigned short significand[4];
266 unsigned short exponent;
267 unsigned short padding[3];
268};
269
270struct _libc_xmmreg {
271 uint32_t element[4];
272};
273
274struct _libc_fpstate {
275 uint16_t cwd;
276 uint16_t swd;
277 uint16_t ftw;
278 uint16_t fop;
279 uint64_t rip;
280 uint64_t rdp;
281 uint32_t mxcsr;
282 uint32_t mxcr_mask;
283 struct _libc_fpxreg _st[8];
284 struct _libc_xmmreg _xmm[16];
285 uint32_t padding[24];
286};
287
288typedef struct _libc_fpstate* fpregset_t;
Pavel Chupine61d1062014-01-27 17:56:43 +0400289
290typedef struct {
291 gregset_t gregs;
292 fpregset_t fpregs;
Elliott Hughesc5992a02014-04-09 13:27:48 -0700293 unsigned long __reserved1[8];
Pavel Chupine61d1062014-01-27 17:56:43 +0400294} mcontext_t;
295
296typedef struct ucontext {
297 unsigned long uc_flags;
298 struct ucontext* uc_link;
299 stack_t uc_stack;
300 mcontext_t uc_mcontext;
301 sigset_t uc_sigmask;
Calin Juravlea6ab9682014-05-13 20:29:01 +0100302 struct _libc_fpstate __fpregs_mem;
Pavel Chupine61d1062014-01-27 17:56:43 +0400303} ucontext_t;
304
Elliott Hughes677a07c2014-01-29 16:46:00 -0800305#endif
Pavel Chupine61d1062014-01-27 17:56:43 +0400306
307__END_DECLS
308
309#endif /* _SYS_UCONTEXT_H_ */