blob: 1d20034344cc520bde5c5e8c0f1aefcec2b36bba [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
Elliott Hughes1245abf2023-08-22 15:31:51 +000035#include <bits/page_size.h>
Elliott Hughese888de82013-11-19 15:32:31 -080036
Elliott Hughes1245abf2023-08-22 15:31:51 +000037__BEGIN_DECLS
Elliott Hughesafab3ff2015-07-28 14:58:37 -070038
Josh Gaocb728e62016-09-15 13:56:37 -070039#if defined(__i386__)
Elliott Hughese888de82013-11-19 15:32:31 -080040
Elliott Hughes93e19072014-04-09 16:35:36 -070041struct user_fpregs_struct {
Elliott Hughese888de82013-11-19 15:32:31 -080042 long cwd;
43 long swd;
44 long twd;
45 long fip;
46 long fcs;
47 long foo;
48 long fos;
49 long st_space[20];
50};
Elliott Hughesfef58352015-06-24 17:31:24 -070051struct user_fpxregs_struct {
Elliott Hughese888de82013-11-19 15:32:31 -080052 unsigned short cwd;
53 unsigned short swd;
54 unsigned short twd;
55 unsigned short fop;
56 long fip;
57 long fcs;
58 long foo;
59 long fos;
60 long mxcsr;
61 long reserved;
62 long st_space[32];
63 long xmm_space[32];
64 long padding[56];
65};
66struct user_regs_struct {
Elliott Hughesf8b2b3c2014-01-09 14:01:18 -080067 long ebx;
68 long ecx;
69 long edx;
70 long esi;
71 long edi;
72 long ebp;
73 long eax;
74 long xds;
75 long xes;
76 long xfs;
77 long xgs;
78 long orig_eax;
79 long eip;
80 long xcs;
81 long eflags;
82 long esp;
83 long xss;
Elliott Hughese888de82013-11-19 15:32:31 -080084};
Elliott Hughesab797cb2013-11-26 17:57:31 -080085struct user {
Elliott Hughese888de82013-11-19 15:32:31 -080086 struct user_regs_struct regs;
87 int u_fpvalid;
Elliott Hughes93e19072014-04-09 16:35:36 -070088 struct user_fpregs_struct i387;
Elliott Hughese888de82013-11-19 15:32:31 -080089 unsigned long int u_tsize;
90 unsigned long int u_dsize;
91 unsigned long int u_ssize;
92 unsigned long start_code;
93 unsigned long start_stack;
94 long int signal;
95 int reserved;
Elliott Hughese03950f2014-10-24 20:57:09 -070096 struct user_regs_struct* u_ar0;
Elliott Hughes93e19072014-04-09 16:35:36 -070097 struct user_fpregs_struct* u_fpstate;
Elliott Hughese888de82013-11-19 15:32:31 -080098 unsigned long magic;
99 char u_comm[32];
100 int u_debugreg[8];
101};
102
Elliott Hughes8d307c92017-07-06 11:04:15 -0700103#define UPAGES 1
104#define HOST_TEXT_START_ADDR (u.start_code)
105#define HOST_STACK_END_ADDR (u.start_stack + u.u_ssize * PAGE_SIZE)
106
Elliott Hughese888de82013-11-19 15:32:31 -0800107#elif defined(__x86_64__)
108
Elliott Hughes93e19072014-04-09 16:35:36 -0700109struct user_fpregs_struct {
Elliott Hughese888de82013-11-19 15:32:31 -0800110 unsigned short cwd;
111 unsigned short swd;
Ross McIlroy0c8a5f82014-05-14 13:29:19 +0100112 unsigned short ftw;
Elliott Hughese888de82013-11-19 15:32:31 -0800113 unsigned short fop;
Josh Gaobb129212016-05-25 15:18:14 -0700114 unsigned long rip;
115 unsigned long rdp;
116 unsigned int mxcsr;
117 unsigned int mxcr_mask;
118 unsigned int st_space[32];
119 unsigned int xmm_space[64];
120 unsigned int padding[24];
Elliott Hughese888de82013-11-19 15:32:31 -0800121};
122struct user_regs_struct {
123 unsigned long r15;
124 unsigned long r14;
125 unsigned long r13;
126 unsigned long r12;
Elliott Hugheseddc8ec2014-01-08 15:54:19 -0800127 unsigned long rbp;
128 unsigned long rbx;
Elliott Hughese888de82013-11-19 15:32:31 -0800129 unsigned long r11;
130 unsigned long r10;
131 unsigned long r9;
132 unsigned long r8;
Elliott Hugheseddc8ec2014-01-08 15:54:19 -0800133 unsigned long rax;
134 unsigned long rcx;
135 unsigned long rdx;
136 unsigned long rsi;
137 unsigned long rdi;
138 unsigned long orig_rax;
139 unsigned long rip;
Elliott Hughese888de82013-11-19 15:32:31 -0800140 unsigned long cs;
Elliott Hugheseddc8ec2014-01-08 15:54:19 -0800141 unsigned long eflags;
142 unsigned long rsp;
Elliott Hughese888de82013-11-19 15:32:31 -0800143 unsigned long ss;
144 unsigned long fs_base;
145 unsigned long gs_base;
146 unsigned long ds;
147 unsigned long es;
148 unsigned long fs;
149 unsigned long gs;
150};
151struct user {
152 struct user_regs_struct regs;
153 int u_fpvalid;
154 int pad0;
Elliott Hughes93e19072014-04-09 16:35:36 -0700155 struct user_fpregs_struct i387;
Elliott Hughese888de82013-11-19 15:32:31 -0800156 unsigned long int u_tsize;
157 unsigned long int u_dsize;
158 unsigned long int u_ssize;
159 unsigned long start_code;
160 unsigned long start_stack;
161 long int signal;
162 int reserved;
163 int pad1;
Elliott Hughese03950f2014-10-24 20:57:09 -0700164 struct user_regs_struct* u_ar0;
Elliott Hughes93e19072014-04-09 16:35:36 -0700165 struct user_fpregs_struct* u_fpstate;
Elliott Hughese888de82013-11-19 15:32:31 -0800166 unsigned long magic;
167 char u_comm[32];
168 unsigned long u_debugreg[8];
169 unsigned long error_code;
170 unsigned long fault_address;
171};
172
Christopher Ferris363390e2013-11-22 18:00:09 -0800173#elif defined(__arm__)
174
Elliott Hughes36144242014-01-30 10:39:02 -0800175struct user_fpregs {
Christopher Ferris363390e2013-11-22 18:00:09 -0800176 struct fp_reg {
177 unsigned int sign1:1;
178 unsigned int unused:15;
179 unsigned int sign2:1;
180 unsigned int exponent:14;
181 unsigned int j:1;
182 unsigned int mantissa1:31;
183 unsigned int mantissa0:32;
184 } fpregs[8];
185 unsigned int fpsr:32;
186 unsigned int fpcr:32;
187 unsigned char ftype[8];
188 unsigned int init_flag;
189};
Elliott Hughes36144242014-01-30 10:39:02 -0800190struct user_regs {
191 unsigned long uregs[18];
192};
Elliott Hughesab797cb2013-11-26 17:57:31 -0800193struct user_vfp {
194 unsigned long long fpregs[32];
195 unsigned long fpscr;
196};
197struct user_vfp_exc {
198 unsigned long fpexc;
199 unsigned long fpinst;
200 unsigned long fpinst2;
201};
202struct user {
Elliott Hughes36144242014-01-30 10:39:02 -0800203 struct user_regs regs;
Christopher Ferris363390e2013-11-22 18:00:09 -0800204 int u_fpvalid;
205 unsigned long int u_tsize;
206 unsigned long int u_dsize;
207 unsigned long int u_ssize;
208 unsigned long start_code;
209 unsigned long start_stack;
210 long int signal;
211 int reserved;
Elliott Hughes36144242014-01-30 10:39:02 -0800212 struct user_regs* u_ar0;
Christopher Ferris363390e2013-11-22 18:00:09 -0800213 unsigned long magic;
214 char u_comm[32];
215 int u_debugreg[8];
Elliott Hughes36144242014-01-30 10:39:02 -0800216 struct user_fpregs u_fp;
217 struct user_fpregs* u_fp0;
Christopher Ferris363390e2013-11-22 18:00:09 -0800218};
219
220#elif defined(__aarch64__)
221
Elliott Hughes03f22462015-08-25 14:18:26 -0700222struct user_regs_struct {
223 uint64_t regs[31];
224 uint64_t sp;
225 uint64_t pc;
226 uint64_t pstate;
227};
228struct user_fpsimd_struct {
229 __uint128_t vregs[32];
230 uint32_t fpsr;
231 uint32_t fpcr;
232};
Christopher Ferris363390e2013-11-22 18:00:09 -0800233
Elliott Hughescf123812022-10-07 20:49:07 +0000234#elif defined(__riscv)
235
236// This space deliberately left blank for now.
237// No other libcs have any riscv64-specific structs.
238
Elliott Hughese888de82013-11-19 15:32:31 -0800239#else
240
Christopher Ferris363390e2013-11-22 18:00:09 -0800241#error "Unsupported architecture."
Elliott Hughese888de82013-11-19 15:32:31 -0800242
243#endif
244
245__END_DECLS