blob: dd2a0bba61955c804d2d416a4475a9f1fa66d6a7 [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 Hughesab4d5cf2014-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 Hughesab4d5cf2014-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 Hughesd0fb6a22014-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 Hughesab4d5cf2014-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 Hughesab4d5cf2014-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
183typedef 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
204typedef 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;
Elliott Hughes677a07c2014-01-29 16:46:00 -0800211
212#elif defined(__mips64__)
213
214#error TODO
215
216#elif defined(__x86_64__)
Pavel Chupine61d1062014-01-27 17:56:43 +0400217
218enum {
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
245typedef long greg_t;
246typedef greg_t gregset_t[NGREG];
247
Calin Juravlea6ab9682014-05-13 20:29:01 +0100248struct _libc_fpxreg {
249 unsigned short significand[4];
250 unsigned short exponent;
251 unsigned short padding[3];
252};
253
254struct _libc_xmmreg {
255 uint32_t element[4];
256};
257
258struct _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
272typedef struct _libc_fpstate* fpregset_t;
Pavel Chupine61d1062014-01-27 17:56:43 +0400273
274typedef struct {
275 gregset_t gregs;
276 fpregset_t fpregs;
Elliott Hughesc5992a02014-04-09 13:27:48 -0700277 unsigned long __reserved1[8];
Pavel Chupine61d1062014-01-27 17:56:43 +0400278} mcontext_t;
279
280typedef 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;
Calin Juravlea6ab9682014-05-13 20:29:01 +0100286 struct _libc_fpstate __fpregs_mem;
Pavel Chupine61d1062014-01-27 17:56:43 +0400287} ucontext_t;
288
Elliott Hughes677a07c2014-01-29 16:46:00 -0800289#endif
Pavel Chupine61d1062014-01-27 17:56:43 +0400290
291__END_DECLS
292
293#endif /* _SYS_UCONTEXT_H_ */