blob: f86d9f4c9840c41db7980f4eb940fb994f815f39 [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
63/* TODO: fpregset_t. */
64
65#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;
73 sigset_t uc_sigmask;
Calin Juravle0e85fb62014-05-19 19:14:03 +010074 char __padding[128 - sizeof(sigset_t)];
75 unsigned long uc_regspace[128] __attribute__((__aligned__(8)));
Elliott Hughes4e72fcc2014-01-29 17:53:59 -080076} ucontext_t;
Elliott Hughes677a07c2014-01-29 16:46:00 -080077
Ross McIlroy7b958072014-01-31 04:45:53 +000078#elif defined(__aarch64__)
Elliott Hughes677a07c2014-01-29 16:46:00 -080079
Ross McIlroy7b958072014-01-31 04:45:53 +000080/* TODO: gregset_t and fpregset_t. */
81
82#include <asm/sigcontext.h>
83typedef struct sigcontext mcontext_t;
84
85typedef struct ucontext {
86 unsigned long uc_flags;
87 struct ucontext *uc_link;
88 stack_t uc_stack;
89 sigset_t uc_sigmask;
Elliott Hughes50249bc2014-04-07 14:36:59 -070090 char __padding[128 - sizeof(sigset_t)];
Ross McIlroy7b958072014-01-31 04:45:53 +000091 mcontext_t uc_mcontext;
92} ucontext_t;
Elliott Hughes677a07c2014-01-29 16:46:00 -080093
94#elif defined(__i386__)
95
96enum {
97 REG_GS = 0,
98 REG_FS,
99 REG_ES,
100 REG_DS,
101 REG_EDI,
102 REG_ESI,
103 REG_EBP,
104 REG_ESP,
105 REG_EBX,
106 REG_EDX,
107 REG_ECX,
108 REG_EAX,
109 REG_TRAPNO,
110 REG_ERR,
111 REG_EIP,
112 REG_CS,
113 REG_EFL,
114 REG_UESP,
115 REG_SS,
116 NGREG
117};
118
119typedef int greg_t;
120typedef greg_t gregset_t[NGREG];
121
122struct _libc_fpreg {
123 unsigned short significand[4];
124 unsigned short exponent;
125};
126
127struct _libc_fpstate {
128 unsigned long cw;
129 unsigned long sw;
130 unsigned long tag;
131 unsigned long ipoff;
132 unsigned long cssel;
133 unsigned long dataoff;
134 unsigned long datasel;
135 struct _libc_fpreg _st[8];
136 unsigned long status;
137};
138
139typedef struct _libc_fpstate* fpregset_t;
140
141typedef struct {
142 gregset_t gregs;
143 fpregset_t fpregs;
144 unsigned long oldmask;
145 unsigned long cr2;
146} mcontext_t;
147
148typedef struct ucontext {
149 unsigned long uc_flags;
150 struct ucontext* uc_link;
151 stack_t uc_stack;
152 mcontext_t uc_mcontext;
153 sigset_t uc_sigmask;
Calin Juravlea6ab9682014-05-13 20:29:01 +0100154 char __padding[128 - sizeof(sigset_t)];
155 struct _libc_fpstate __fpregs_mem;
Elliott Hughes677a07c2014-01-29 16:46:00 -0800156} ucontext_t;
157
158#elif defined(__mips__)
159
Elliott Hughes02c661b2014-01-29 18:37:15 -0800160/* glibc doesn't have names for MIPS registers. */
161
162#define NGREG 32
163#define NFPREG 32
164
165typedef unsigned long long greg_t;
166typedef greg_t gregset_t[NGREG];
167
168typedef struct fpregset {
169 union {
170 double fp_dregs[NFPREG];
171 struct {
172 float _fp_fregs;
173 unsigned _fp_pad;
174 } fp_fregs[NFPREG];
175 } fp_r;
176} fpregset_t;
177
178typedef struct {
179 unsigned regmask;
180 unsigned status;
181 greg_t pc;
182 gregset_t gregs;
183 fpregset_t fpregs;
184 unsigned fp_owned;
185 unsigned fpc_csr;
186 unsigned fpc_eir;
187 unsigned used_math;
188 unsigned dsp;
189 greg_t mdhi;
190 greg_t mdlo;
191 unsigned long hi1;
192 unsigned long lo1;
193 unsigned long hi2;
194 unsigned long lo2;
195 unsigned long hi3;
196 unsigned long lo3;
197} mcontext_t;
198
199typedef struct ucontext {
200 unsigned long uc_flags;
201 struct ucontext* uc_link;
202 stack_t uc_stack;
203 mcontext_t uc_mcontext;
204 sigset_t uc_sigmask;
205} ucontext_t;
Elliott Hughes677a07c2014-01-29 16:46:00 -0800206
207#elif defined(__mips64__)
208
209#error TODO
210
211#elif defined(__x86_64__)
Pavel Chupine61d1062014-01-27 17:56:43 +0400212
213enum {
214 REG_R8 = 0,
215 REG_R9,
216 REG_R10,
217 REG_R11,
218 REG_R12,
219 REG_R13,
220 REG_R14,
221 REG_R15,
222 REG_RDI,
223 REG_RSI,
224 REG_RBP,
225 REG_RBX,
226 REG_RDX,
227 REG_RAX,
228 REG_RCX,
229 REG_RSP,
230 REG_RIP,
231 REG_EFL,
232 REG_CSGSFS,
233 REG_ERR,
234 REG_TRAPNO,
235 REG_OLDMASK,
236 REG_CR2,
237 NGREG
238};
239
240typedef long greg_t;
241typedef greg_t gregset_t[NGREG];
242
Calin Juravlea6ab9682014-05-13 20:29:01 +0100243struct _libc_fpxreg {
244 unsigned short significand[4];
245 unsigned short exponent;
246 unsigned short padding[3];
247};
248
249struct _libc_xmmreg {
250 uint32_t element[4];
251};
252
253struct _libc_fpstate {
254 uint16_t cwd;
255 uint16_t swd;
256 uint16_t ftw;
257 uint16_t fop;
258 uint64_t rip;
259 uint64_t rdp;
260 uint32_t mxcsr;
261 uint32_t mxcr_mask;
262 struct _libc_fpxreg _st[8];
263 struct _libc_xmmreg _xmm[16];
264 uint32_t padding[24];
265};
266
267typedef struct _libc_fpstate* fpregset_t;
Pavel Chupine61d1062014-01-27 17:56:43 +0400268
269typedef struct {
270 gregset_t gregs;
271 fpregset_t fpregs;
Elliott Hughesc5992a02014-04-09 13:27:48 -0700272 unsigned long __reserved1[8];
Pavel Chupine61d1062014-01-27 17:56:43 +0400273} mcontext_t;
274
275typedef struct ucontext {
276 unsigned long uc_flags;
277 struct ucontext* uc_link;
278 stack_t uc_stack;
279 mcontext_t uc_mcontext;
280 sigset_t uc_sigmask;
Calin Juravlea6ab9682014-05-13 20:29:01 +0100281 char __padding[128 - sizeof(sigset_t)];
282 struct _libc_fpstate __fpregs_mem;
Pavel Chupine61d1062014-01-27 17:56:43 +0400283} ucontext_t;
284
Elliott Hughes677a07c2014-01-29 16:46:00 -0800285#endif
Pavel Chupine61d1062014-01-27 17:56:43 +0400286
287__END_DECLS
288
289#endif /* _SYS_UCONTEXT_H_ */