blob: 432c7cbb97ece8500293cc174e2c88d95ef9a55c [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
Elliott Hughescf123812022-10-07 20:49:07 +000029#pragma once
Elliott Hughese888de82013-11-19 15:32:31 -080030
31#include <sys/cdefs.h>
David 'Digit' Turneraad1a392014-11-18 12:21:55 +010032#include <stddef.h> /* For size_t. */
Josh Gaod8ca92c2016-04-25 17:04:56 -070033#include <stdint.h>
Elliott Hughese888de82013-11-19 15:32:31 -080034
35__BEGIN_DECLS
36
Elliott Hughesafab3ff2015-07-28 14:58:37 -070037#define PAGE_SIZE 4096
38#define PAGE_MASK (~(PAGE_SIZE - 1))
39
Josh Gaocb728e62016-09-15 13:56:37 -070040#if defined(__i386__)
Elliott Hughese888de82013-11-19 15:32:31 -080041
Elliott Hughes93e19072014-04-09 16:35:36 -070042struct user_fpregs_struct {
Elliott Hughese888de82013-11-19 15:32:31 -080043 long cwd;
44 long swd;
45 long twd;
46 long fip;
47 long fcs;
48 long foo;
49 long fos;
50 long st_space[20];
51};
Elliott Hughesfef58352015-06-24 17:31:24 -070052struct user_fpxregs_struct {
Elliott Hughese888de82013-11-19 15:32:31 -080053 unsigned short cwd;
54 unsigned short swd;
55 unsigned short twd;
56 unsigned short fop;
57 long fip;
58 long fcs;
59 long foo;
60 long fos;
61 long mxcsr;
62 long reserved;
63 long st_space[32];
64 long xmm_space[32];
65 long padding[56];
66};
67struct user_regs_struct {
Elliott Hughesf8b2b3c2014-01-09 14:01:18 -080068 long ebx;
69 long ecx;
70 long edx;
71 long esi;
72 long edi;
73 long ebp;
74 long eax;
75 long xds;
76 long xes;
77 long xfs;
78 long xgs;
79 long orig_eax;
80 long eip;
81 long xcs;
82 long eflags;
83 long esp;
84 long xss;
Elliott Hughese888de82013-11-19 15:32:31 -080085};
Elliott Hughesab797cb2013-11-26 17:57:31 -080086struct user {
Elliott Hughese888de82013-11-19 15:32:31 -080087 struct user_regs_struct regs;
88 int u_fpvalid;
Elliott Hughes93e19072014-04-09 16:35:36 -070089 struct user_fpregs_struct i387;
Elliott Hughese888de82013-11-19 15:32:31 -080090 unsigned long int u_tsize;
91 unsigned long int u_dsize;
92 unsigned long int u_ssize;
93 unsigned long start_code;
94 unsigned long start_stack;
95 long int signal;
96 int reserved;
Elliott Hughese03950f2014-10-24 20:57:09 -070097 struct user_regs_struct* u_ar0;
Elliott Hughes93e19072014-04-09 16:35:36 -070098 struct user_fpregs_struct* u_fpstate;
Elliott Hughese888de82013-11-19 15:32:31 -080099 unsigned long magic;
100 char u_comm[32];
101 int u_debugreg[8];
102};
103
Elliott Hughes8d307c92017-07-06 11:04:15 -0700104#define UPAGES 1
105#define HOST_TEXT_START_ADDR (u.start_code)
106#define HOST_STACK_END_ADDR (u.start_stack + u.u_ssize * PAGE_SIZE)
107
Elliott Hughese888de82013-11-19 15:32:31 -0800108#elif defined(__x86_64__)
109
Elliott Hughes93e19072014-04-09 16:35:36 -0700110struct user_fpregs_struct {
Elliott Hughese888de82013-11-19 15:32:31 -0800111 unsigned short cwd;
112 unsigned short swd;
Ross McIlroy0c8a5f82014-05-14 13:29:19 +0100113 unsigned short ftw;
Elliott Hughese888de82013-11-19 15:32:31 -0800114 unsigned short fop;
Josh Gaobb129212016-05-25 15:18:14 -0700115 unsigned long rip;
116 unsigned long rdp;
117 unsigned int mxcsr;
118 unsigned int mxcr_mask;
119 unsigned int st_space[32];
120 unsigned int xmm_space[64];
121 unsigned int padding[24];
Elliott Hughese888de82013-11-19 15:32:31 -0800122};
123struct user_regs_struct {
124 unsigned long r15;
125 unsigned long r14;
126 unsigned long r13;
127 unsigned long r12;
Elliott Hugheseddc8ec2014-01-08 15:54:19 -0800128 unsigned long rbp;
129 unsigned long rbx;
Elliott Hughese888de82013-11-19 15:32:31 -0800130 unsigned long r11;
131 unsigned long r10;
132 unsigned long r9;
133 unsigned long r8;
Elliott Hugheseddc8ec2014-01-08 15:54:19 -0800134 unsigned long rax;
135 unsigned long rcx;
136 unsigned long rdx;
137 unsigned long rsi;
138 unsigned long rdi;
139 unsigned long orig_rax;
140 unsigned long rip;
Elliott Hughese888de82013-11-19 15:32:31 -0800141 unsigned long cs;
Elliott Hugheseddc8ec2014-01-08 15:54:19 -0800142 unsigned long eflags;
143 unsigned long rsp;
Elliott Hughese888de82013-11-19 15:32:31 -0800144 unsigned long ss;
145 unsigned long fs_base;
146 unsigned long gs_base;
147 unsigned long ds;
148 unsigned long es;
149 unsigned long fs;
150 unsigned long gs;
151};
152struct user {
153 struct user_regs_struct regs;
154 int u_fpvalid;
155 int pad0;
Elliott Hughes93e19072014-04-09 16:35:36 -0700156 struct user_fpregs_struct i387;
Elliott Hughese888de82013-11-19 15:32:31 -0800157 unsigned long int u_tsize;
158 unsigned long int u_dsize;
159 unsigned long int u_ssize;
160 unsigned long start_code;
161 unsigned long start_stack;
162 long int signal;
163 int reserved;
164 int pad1;
Elliott Hughese03950f2014-10-24 20:57:09 -0700165 struct user_regs_struct* u_ar0;
Elliott Hughes93e19072014-04-09 16:35:36 -0700166 struct user_fpregs_struct* u_fpstate;
Elliott Hughese888de82013-11-19 15:32:31 -0800167 unsigned long magic;
168 char u_comm[32];
169 unsigned long u_debugreg[8];
170 unsigned long error_code;
171 unsigned long fault_address;
172};
173
Christopher Ferris363390e2013-11-22 18:00:09 -0800174#elif defined(__arm__)
175
Elliott Hughes36144242014-01-30 10:39:02 -0800176struct user_fpregs {
Christopher Ferris363390e2013-11-22 18:00:09 -0800177 struct fp_reg {
178 unsigned int sign1:1;
179 unsigned int unused:15;
180 unsigned int sign2:1;
181 unsigned int exponent:14;
182 unsigned int j:1;
183 unsigned int mantissa1:31;
184 unsigned int mantissa0:32;
185 } fpregs[8];
186 unsigned int fpsr:32;
187 unsigned int fpcr:32;
188 unsigned char ftype[8];
189 unsigned int init_flag;
190};
Elliott Hughes36144242014-01-30 10:39:02 -0800191struct user_regs {
192 unsigned long uregs[18];
193};
Elliott Hughesab797cb2013-11-26 17:57:31 -0800194struct user_vfp {
195 unsigned long long fpregs[32];
196 unsigned long fpscr;
197};
198struct user_vfp_exc {
199 unsigned long fpexc;
200 unsigned long fpinst;
201 unsigned long fpinst2;
202};
203struct user {
Elliott Hughes36144242014-01-30 10:39:02 -0800204 struct user_regs regs;
Christopher Ferris363390e2013-11-22 18:00:09 -0800205 int u_fpvalid;
206 unsigned long int u_tsize;
207 unsigned long int u_dsize;
208 unsigned long int u_ssize;
209 unsigned long start_code;
210 unsigned long start_stack;
211 long int signal;
212 int reserved;
Elliott Hughes36144242014-01-30 10:39:02 -0800213 struct user_regs* u_ar0;
Christopher Ferris363390e2013-11-22 18:00:09 -0800214 unsigned long magic;
215 char u_comm[32];
216 int u_debugreg[8];
Elliott Hughes36144242014-01-30 10:39:02 -0800217 struct user_fpregs u_fp;
218 struct user_fpregs* u_fp0;
Christopher Ferris363390e2013-11-22 18:00:09 -0800219};
220
221#elif defined(__aarch64__)
222
Elliott Hughes03f22462015-08-25 14:18:26 -0700223struct user_regs_struct {
224 uint64_t regs[31];
225 uint64_t sp;
226 uint64_t pc;
227 uint64_t pstate;
228};
229struct user_fpsimd_struct {
230 __uint128_t vregs[32];
231 uint32_t fpsr;
232 uint32_t fpcr;
233};
Christopher Ferris363390e2013-11-22 18:00:09 -0800234
Elliott Hughescf123812022-10-07 20:49:07 +0000235#elif defined(__riscv)
236
237// This space deliberately left blank for now.
238// No other libcs have any riscv64-specific structs.
239
Elliott Hughese888de82013-11-19 15:32:31 -0800240#else
241
Christopher Ferris363390e2013-11-22 18:00:09 -0800242#error "Unsupported architecture."
Elliott Hughese888de82013-11-19 15:32:31 -0800243
244#endif
245
246__END_DECLS