blob: c65e2b615453848bac97dba787b5c1dc5a06d2c0 [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;
74 /* TODO: uc_regspace */
75} ucontext_t;
Elliott Hughes677a07c2014-01-29 16:46:00 -080076
77#elif defined(__arm64__)
78
79#error TODO
80
81#elif defined(__i386__)
82
83enum {
84 REG_GS = 0,
85 REG_FS,
86 REG_ES,
87 REG_DS,
88 REG_EDI,
89 REG_ESI,
90 REG_EBP,
91 REG_ESP,
92 REG_EBX,
93 REG_EDX,
94 REG_ECX,
95 REG_EAX,
96 REG_TRAPNO,
97 REG_ERR,
98 REG_EIP,
99 REG_CS,
100 REG_EFL,
101 REG_UESP,
102 REG_SS,
103 NGREG
104};
105
106typedef int greg_t;
107typedef greg_t gregset_t[NGREG];
108
109struct _libc_fpreg {
110 unsigned short significand[4];
111 unsigned short exponent;
112};
113
114struct _libc_fpstate {
115 unsigned long cw;
116 unsigned long sw;
117 unsigned long tag;
118 unsigned long ipoff;
119 unsigned long cssel;
120 unsigned long dataoff;
121 unsigned long datasel;
122 struct _libc_fpreg _st[8];
123 unsigned long status;
124};
125
126typedef struct _libc_fpstate* fpregset_t;
127
128typedef struct {
129 gregset_t gregs;
130 fpregset_t fpregs;
131 unsigned long oldmask;
132 unsigned long cr2;
133} mcontext_t;
134
135typedef struct ucontext {
136 unsigned long uc_flags;
137 struct ucontext* uc_link;
138 stack_t uc_stack;
139 mcontext_t uc_mcontext;
140 sigset_t uc_sigmask;
141 /* TODO: __fpregs_mem? */
142} ucontext_t;
143
144#elif defined(__mips__)
145
Elliott Hughes02c661b2014-01-29 18:37:15 -0800146/* glibc doesn't have names for MIPS registers. */
147
148#define NGREG 32
149#define NFPREG 32
150
151typedef unsigned long long greg_t;
152typedef greg_t gregset_t[NGREG];
153
154typedef struct fpregset {
155 union {
156 double fp_dregs[NFPREG];
157 struct {
158 float _fp_fregs;
159 unsigned _fp_pad;
160 } fp_fregs[NFPREG];
161 } fp_r;
162} fpregset_t;
163
164typedef struct {
165 unsigned regmask;
166 unsigned status;
167 greg_t pc;
168 gregset_t gregs;
169 fpregset_t fpregs;
170 unsigned fp_owned;
171 unsigned fpc_csr;
172 unsigned fpc_eir;
173 unsigned used_math;
174 unsigned dsp;
175 greg_t mdhi;
176 greg_t mdlo;
177 unsigned long hi1;
178 unsigned long lo1;
179 unsigned long hi2;
180 unsigned long lo2;
181 unsigned long hi3;
182 unsigned long lo3;
183} mcontext_t;
184
185typedef struct ucontext {
186 unsigned long uc_flags;
187 struct ucontext* uc_link;
188 stack_t uc_stack;
189 mcontext_t uc_mcontext;
190 sigset_t uc_sigmask;
191} ucontext_t;
Elliott Hughes677a07c2014-01-29 16:46:00 -0800192
193#elif defined(__mips64__)
194
195#error TODO
196
197#elif defined(__x86_64__)
Pavel Chupine61d1062014-01-27 17:56:43 +0400198
199enum {
200 REG_R8 = 0,
201 REG_R9,
202 REG_R10,
203 REG_R11,
204 REG_R12,
205 REG_R13,
206 REG_R14,
207 REG_R15,
208 REG_RDI,
209 REG_RSI,
210 REG_RBP,
211 REG_RBX,
212 REG_RDX,
213 REG_RAX,
214 REG_RCX,
215 REG_RSP,
216 REG_RIP,
217 REG_EFL,
218 REG_CSGSFS,
219 REG_ERR,
220 REG_TRAPNO,
221 REG_OLDMASK,
222 REG_CR2,
223 NGREG
224};
225
226typedef long greg_t;
227typedef greg_t gregset_t[NGREG];
228
229typedef struct user_i387_struct* fpregset_t;
230
231typedef struct {
232 gregset_t gregs;
233 fpregset_t fpregs;
234 /* TODO: reserved space? */
235} mcontext_t;
236
237typedef struct ucontext {
238 unsigned long uc_flags;
239 struct ucontext* uc_link;
240 stack_t uc_stack;
241 mcontext_t uc_mcontext;
242 sigset_t uc_sigmask;
243 /* TODO: __fpregs_mem? */
244} ucontext_t;
245
Elliott Hughes677a07c2014-01-29 16:46:00 -0800246#endif
Pavel Chupine61d1062014-01-27 17:56:43 +0400247
248__END_DECLS
249
250#endif /* _SYS_UCONTEXT_H_ */