blob: ed3e10a1fa9ff95c6ccaca840dfeade2b1c40bbf [file] [log] [blame]
Elliott Hughese888de82013-11-19 15:32:31 -08001/*
2 * Copyright (C) 2013 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_USER_H_
30#define _SYS_USER_H_
31
32#include <sys/cdefs.h>
David 'Digit' Turneraad1a392014-11-18 12:21:55 +010033#include <stddef.h> /* For size_t. */
Josh Gaod8ca92c2016-04-25 17:04:56 -070034#include <stdint.h>
Elliott Hughese888de82013-11-19 15:32:31 -080035
36__BEGIN_DECLS
37
Elliott Hughesafab3ff2015-07-28 14:58:37 -070038#define PAGE_SIZE 4096
39#define PAGE_MASK (~(PAGE_SIZE - 1))
40
Josh Gaocb728e62016-09-15 13:56:37 -070041#if defined(__i386__)
Elliott Hughese888de82013-11-19 15:32:31 -080042
Elliott Hughes93e19072014-04-09 16:35:36 -070043struct user_fpregs_struct {
Elliott Hughese888de82013-11-19 15:32:31 -080044 long cwd;
45 long swd;
46 long twd;
47 long fip;
48 long fcs;
49 long foo;
50 long fos;
51 long st_space[20];
52};
Elliott Hughesfef58352015-06-24 17:31:24 -070053struct user_fpxregs_struct {
Elliott Hughese888de82013-11-19 15:32:31 -080054 unsigned short cwd;
55 unsigned short swd;
56 unsigned short twd;
57 unsigned short fop;
58 long fip;
59 long fcs;
60 long foo;
61 long fos;
62 long mxcsr;
63 long reserved;
64 long st_space[32];
65 long xmm_space[32];
66 long padding[56];
67};
68struct user_regs_struct {
Elliott Hughesf8b2b3c2014-01-09 14:01:18 -080069 long ebx;
70 long ecx;
71 long edx;
72 long esi;
73 long edi;
74 long ebp;
75 long eax;
76 long xds;
77 long xes;
78 long xfs;
79 long xgs;
80 long orig_eax;
81 long eip;
82 long xcs;
83 long eflags;
84 long esp;
85 long xss;
Elliott Hughese888de82013-11-19 15:32:31 -080086};
Elliott Hughesab797cb2013-11-26 17:57:31 -080087struct user {
Elliott Hughese888de82013-11-19 15:32:31 -080088 struct user_regs_struct regs;
89 int u_fpvalid;
Elliott Hughes93e19072014-04-09 16:35:36 -070090 struct user_fpregs_struct i387;
Elliott Hughese888de82013-11-19 15:32:31 -080091 unsigned long int u_tsize;
92 unsigned long int u_dsize;
93 unsigned long int u_ssize;
94 unsigned long start_code;
95 unsigned long start_stack;
96 long int signal;
97 int reserved;
Elliott Hughese03950f2014-10-24 20:57:09 -070098 struct user_regs_struct* u_ar0;
Elliott Hughes93e19072014-04-09 16:35:36 -070099 struct user_fpregs_struct* u_fpstate;
Elliott Hughese888de82013-11-19 15:32:31 -0800100 unsigned long magic;
101 char u_comm[32];
102 int u_debugreg[8];
103};
104
Elliott Hughes8d307c92017-07-06 11:04:15 -0700105#define UPAGES 1
106#define HOST_TEXT_START_ADDR (u.start_code)
107#define HOST_STACK_END_ADDR (u.start_stack + u.u_ssize * PAGE_SIZE)
108
Elliott Hughese888de82013-11-19 15:32:31 -0800109#elif defined(__x86_64__)
110
Elliott Hughes93e19072014-04-09 16:35:36 -0700111struct user_fpregs_struct {
Elliott Hughese888de82013-11-19 15:32:31 -0800112 unsigned short cwd;
113 unsigned short swd;
Ross McIlroy0c8a5f82014-05-14 13:29:19 +0100114 unsigned short ftw;
Elliott Hughese888de82013-11-19 15:32:31 -0800115 unsigned short fop;
Josh Gaobb129212016-05-25 15:18:14 -0700116 unsigned long rip;
117 unsigned long rdp;
118 unsigned int mxcsr;
119 unsigned int mxcr_mask;
120 unsigned int st_space[32];
121 unsigned int xmm_space[64];
122 unsigned int padding[24];
Elliott Hughese888de82013-11-19 15:32:31 -0800123};
124struct user_regs_struct {
125 unsigned long r15;
126 unsigned long r14;
127 unsigned long r13;
128 unsigned long r12;
Elliott Hugheseddc8ec2014-01-08 15:54:19 -0800129 unsigned long rbp;
130 unsigned long rbx;
Elliott Hughese888de82013-11-19 15:32:31 -0800131 unsigned long r11;
132 unsigned long r10;
133 unsigned long r9;
134 unsigned long r8;
Elliott Hugheseddc8ec2014-01-08 15:54:19 -0800135 unsigned long rax;
136 unsigned long rcx;
137 unsigned long rdx;
138 unsigned long rsi;
139 unsigned long rdi;
140 unsigned long orig_rax;
141 unsigned long rip;
Elliott Hughese888de82013-11-19 15:32:31 -0800142 unsigned long cs;
Elliott Hugheseddc8ec2014-01-08 15:54:19 -0800143 unsigned long eflags;
144 unsigned long rsp;
Elliott Hughese888de82013-11-19 15:32:31 -0800145 unsigned long ss;
146 unsigned long fs_base;
147 unsigned long gs_base;
148 unsigned long ds;
149 unsigned long es;
150 unsigned long fs;
151 unsigned long gs;
152};
153struct user {
154 struct user_regs_struct regs;
155 int u_fpvalid;
156 int pad0;
Elliott Hughes93e19072014-04-09 16:35:36 -0700157 struct user_fpregs_struct i387;
Elliott Hughese888de82013-11-19 15:32:31 -0800158 unsigned long int u_tsize;
159 unsigned long int u_dsize;
160 unsigned long int u_ssize;
161 unsigned long start_code;
162 unsigned long start_stack;
163 long int signal;
164 int reserved;
165 int pad1;
Elliott Hughese03950f2014-10-24 20:57:09 -0700166 struct user_regs_struct* u_ar0;
Elliott Hughes93e19072014-04-09 16:35:36 -0700167 struct user_fpregs_struct* u_fpstate;
Elliott Hughese888de82013-11-19 15:32:31 -0800168 unsigned long magic;
169 char u_comm[32];
170 unsigned long u_debugreg[8];
171 unsigned long error_code;
172 unsigned long fault_address;
173};
174
175#elif defined(__mips__)
176
177struct user {
178 unsigned long regs[180 / sizeof(unsigned long) + 64];
179 size_t u_tsize;
180 size_t u_dsize;
181 size_t u_ssize;
182 unsigned long start_code;
183 unsigned long start_data;
184 unsigned long start_stack;
185 long int signal;
Elliott Hughese03950f2014-10-24 20:57:09 -0700186 void* u_ar0;
Elliott Hughese888de82013-11-19 15:32:31 -0800187 unsigned long magic;
188 char u_comm[32];
189};
190
Christopher Ferris363390e2013-11-22 18:00:09 -0800191#elif defined(__arm__)
192
Elliott Hughes36144242014-01-30 10:39:02 -0800193struct user_fpregs {
Christopher Ferris363390e2013-11-22 18:00:09 -0800194 struct fp_reg {
195 unsigned int sign1:1;
196 unsigned int unused:15;
197 unsigned int sign2:1;
198 unsigned int exponent:14;
199 unsigned int j:1;
200 unsigned int mantissa1:31;
201 unsigned int mantissa0:32;
202 } fpregs[8];
203 unsigned int fpsr:32;
204 unsigned int fpcr:32;
205 unsigned char ftype[8];
206 unsigned int init_flag;
207};
Elliott Hughes36144242014-01-30 10:39:02 -0800208struct user_regs {
209 unsigned long uregs[18];
210};
Elliott Hughesab797cb2013-11-26 17:57:31 -0800211struct user_vfp {
212 unsigned long long fpregs[32];
213 unsigned long fpscr;
214};
215struct user_vfp_exc {
216 unsigned long fpexc;
217 unsigned long fpinst;
218 unsigned long fpinst2;
219};
220struct user {
Elliott Hughes36144242014-01-30 10:39:02 -0800221 struct user_regs regs;
Christopher Ferris363390e2013-11-22 18:00:09 -0800222 int u_fpvalid;
223 unsigned long int u_tsize;
224 unsigned long int u_dsize;
225 unsigned long int u_ssize;
226 unsigned long start_code;
227 unsigned long start_stack;
228 long int signal;
229 int reserved;
Elliott Hughes36144242014-01-30 10:39:02 -0800230 struct user_regs* u_ar0;
Christopher Ferris363390e2013-11-22 18:00:09 -0800231 unsigned long magic;
232 char u_comm[32];
233 int u_debugreg[8];
Elliott Hughes36144242014-01-30 10:39:02 -0800234 struct user_fpregs u_fp;
235 struct user_fpregs* u_fp0;
Christopher Ferris363390e2013-11-22 18:00:09 -0800236};
237
238#elif defined(__aarch64__)
239
Elliott Hughes03f22462015-08-25 14:18:26 -0700240struct user_regs_struct {
241 uint64_t regs[31];
242 uint64_t sp;
243 uint64_t pc;
244 uint64_t pstate;
245};
246struct user_fpsimd_struct {
247 __uint128_t vregs[32];
248 uint32_t fpsr;
249 uint32_t fpcr;
250};
Christopher Ferris363390e2013-11-22 18:00:09 -0800251
Elliott Hughese888de82013-11-19 15:32:31 -0800252#else
253
Christopher Ferris363390e2013-11-22 18:00:09 -0800254#error "Unsupported architecture."
Elliott Hughese888de82013-11-19 15:32:31 -0800255
256#endif
257
258__END_DECLS
259
260#endif /* _SYS_USER_H_ */