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