blob: 0ea0285d5c41bac1aa49a473a4f0b08420f7018f [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
Juan Yescas7de20122023-08-09 15:53:28 -070037#if !defined(__BIONIC_NO_PAGE_SIZE_MACRO)
Elliott Hughesafab3ff2015-07-28 14:58:37 -070038#define PAGE_SIZE 4096
39#define PAGE_MASK (~(PAGE_SIZE - 1))
Juan Yescas7de20122023-08-09 15:53:28 -070040#endif
Elliott Hughesafab3ff2015-07-28 14:58:37 -070041
Josh Gaocb728e62016-09-15 13:56:37 -070042#if defined(__i386__)
Elliott Hughese888de82013-11-19 15:32:31 -080043
Elliott Hughes93e19072014-04-09 16:35:36 -070044struct user_fpregs_struct {
Elliott Hughese888de82013-11-19 15:32:31 -080045 long cwd;
46 long swd;
47 long twd;
48 long fip;
49 long fcs;
50 long foo;
51 long fos;
52 long st_space[20];
53};
Elliott Hughesfef58352015-06-24 17:31:24 -070054struct user_fpxregs_struct {
Elliott Hughese888de82013-11-19 15:32:31 -080055 unsigned short cwd;
56 unsigned short swd;
57 unsigned short twd;
58 unsigned short fop;
59 long fip;
60 long fcs;
61 long foo;
62 long fos;
63 long mxcsr;
64 long reserved;
65 long st_space[32];
66 long xmm_space[32];
67 long padding[56];
68};
69struct user_regs_struct {
Elliott Hughesf8b2b3c2014-01-09 14:01:18 -080070 long ebx;
71 long ecx;
72 long edx;
73 long esi;
74 long edi;
75 long ebp;
76 long eax;
77 long xds;
78 long xes;
79 long xfs;
80 long xgs;
81 long orig_eax;
82 long eip;
83 long xcs;
84 long eflags;
85 long esp;
86 long xss;
Elliott Hughese888de82013-11-19 15:32:31 -080087};
Elliott Hughesab797cb2013-11-26 17:57:31 -080088struct user {
Elliott Hughese888de82013-11-19 15:32:31 -080089 struct user_regs_struct regs;
90 int u_fpvalid;
Elliott Hughes93e19072014-04-09 16:35:36 -070091 struct user_fpregs_struct i387;
Elliott Hughese888de82013-11-19 15:32:31 -080092 unsigned long int u_tsize;
93 unsigned long int u_dsize;
94 unsigned long int u_ssize;
95 unsigned long start_code;
96 unsigned long start_stack;
97 long int signal;
98 int reserved;
Elliott Hughese03950f2014-10-24 20:57:09 -070099 struct user_regs_struct* u_ar0;
Elliott Hughes93e19072014-04-09 16:35:36 -0700100 struct user_fpregs_struct* u_fpstate;
Elliott Hughese888de82013-11-19 15:32:31 -0800101 unsigned long magic;
102 char u_comm[32];
103 int u_debugreg[8];
104};
105
Elliott Hughes8d307c92017-07-06 11:04:15 -0700106#define UPAGES 1
107#define HOST_TEXT_START_ADDR (u.start_code)
108#define HOST_STACK_END_ADDR (u.start_stack + u.u_ssize * PAGE_SIZE)
109
Elliott Hughese888de82013-11-19 15:32:31 -0800110#elif defined(__x86_64__)
111
Elliott Hughes93e19072014-04-09 16:35:36 -0700112struct user_fpregs_struct {
Elliott Hughese888de82013-11-19 15:32:31 -0800113 unsigned short cwd;
114 unsigned short swd;
Ross McIlroy0c8a5f82014-05-14 13:29:19 +0100115 unsigned short ftw;
Elliott Hughese888de82013-11-19 15:32:31 -0800116 unsigned short fop;
Josh Gaobb129212016-05-25 15:18:14 -0700117 unsigned long rip;
118 unsigned long rdp;
119 unsigned int mxcsr;
120 unsigned int mxcr_mask;
121 unsigned int st_space[32];
122 unsigned int xmm_space[64];
123 unsigned int padding[24];
Elliott Hughese888de82013-11-19 15:32:31 -0800124};
125struct user_regs_struct {
126 unsigned long r15;
127 unsigned long r14;
128 unsigned long r13;
129 unsigned long r12;
Elliott Hugheseddc8ec2014-01-08 15:54:19 -0800130 unsigned long rbp;
131 unsigned long rbx;
Elliott Hughese888de82013-11-19 15:32:31 -0800132 unsigned long r11;
133 unsigned long r10;
134 unsigned long r9;
135 unsigned long r8;
Elliott Hugheseddc8ec2014-01-08 15:54:19 -0800136 unsigned long rax;
137 unsigned long rcx;
138 unsigned long rdx;
139 unsigned long rsi;
140 unsigned long rdi;
141 unsigned long orig_rax;
142 unsigned long rip;
Elliott Hughese888de82013-11-19 15:32:31 -0800143 unsigned long cs;
Elliott Hugheseddc8ec2014-01-08 15:54:19 -0800144 unsigned long eflags;
145 unsigned long rsp;
Elliott Hughese888de82013-11-19 15:32:31 -0800146 unsigned long ss;
147 unsigned long fs_base;
148 unsigned long gs_base;
149 unsigned long ds;
150 unsigned long es;
151 unsigned long fs;
152 unsigned long gs;
153};
154struct user {
155 struct user_regs_struct regs;
156 int u_fpvalid;
157 int pad0;
Elliott Hughes93e19072014-04-09 16:35:36 -0700158 struct user_fpregs_struct i387;
Elliott Hughese888de82013-11-19 15:32:31 -0800159 unsigned long int u_tsize;
160 unsigned long int u_dsize;
161 unsigned long int u_ssize;
162 unsigned long start_code;
163 unsigned long start_stack;
164 long int signal;
165 int reserved;
166 int pad1;
Elliott Hughese03950f2014-10-24 20:57:09 -0700167 struct user_regs_struct* u_ar0;
Elliott Hughes93e19072014-04-09 16:35:36 -0700168 struct user_fpregs_struct* u_fpstate;
Elliott Hughese888de82013-11-19 15:32:31 -0800169 unsigned long magic;
170 char u_comm[32];
171 unsigned long u_debugreg[8];
172 unsigned long error_code;
173 unsigned long fault_address;
174};
175
Christopher Ferris363390e2013-11-22 18:00:09 -0800176#elif defined(__arm__)
177
Elliott Hughes36144242014-01-30 10:39:02 -0800178struct user_fpregs {
Christopher Ferris363390e2013-11-22 18:00:09 -0800179 struct fp_reg {
180 unsigned int sign1:1;
181 unsigned int unused:15;
182 unsigned int sign2:1;
183 unsigned int exponent:14;
184 unsigned int j:1;
185 unsigned int mantissa1:31;
186 unsigned int mantissa0:32;
187 } fpregs[8];
188 unsigned int fpsr:32;
189 unsigned int fpcr:32;
190 unsigned char ftype[8];
191 unsigned int init_flag;
192};
Elliott Hughes36144242014-01-30 10:39:02 -0800193struct user_regs {
194 unsigned long uregs[18];
195};
Elliott Hughesab797cb2013-11-26 17:57:31 -0800196struct user_vfp {
197 unsigned long long fpregs[32];
198 unsigned long fpscr;
199};
200struct user_vfp_exc {
201 unsigned long fpexc;
202 unsigned long fpinst;
203 unsigned long fpinst2;
204};
205struct user {
Elliott Hughes36144242014-01-30 10:39:02 -0800206 struct user_regs regs;
Christopher Ferris363390e2013-11-22 18:00:09 -0800207 int u_fpvalid;
208 unsigned long int u_tsize;
209 unsigned long int u_dsize;
210 unsigned long int u_ssize;
211 unsigned long start_code;
212 unsigned long start_stack;
213 long int signal;
214 int reserved;
Elliott Hughes36144242014-01-30 10:39:02 -0800215 struct user_regs* u_ar0;
Christopher Ferris363390e2013-11-22 18:00:09 -0800216 unsigned long magic;
217 char u_comm[32];
218 int u_debugreg[8];
Elliott Hughes36144242014-01-30 10:39:02 -0800219 struct user_fpregs u_fp;
220 struct user_fpregs* u_fp0;
Christopher Ferris363390e2013-11-22 18:00:09 -0800221};
222
223#elif defined(__aarch64__)
224
Elliott Hughes03f22462015-08-25 14:18:26 -0700225struct user_regs_struct {
226 uint64_t regs[31];
227 uint64_t sp;
228 uint64_t pc;
229 uint64_t pstate;
230};
231struct user_fpsimd_struct {
232 __uint128_t vregs[32];
233 uint32_t fpsr;
234 uint32_t fpcr;
235};
Christopher Ferris363390e2013-11-22 18:00:09 -0800236
Elliott Hughescf123812022-10-07 20:49:07 +0000237#elif defined(__riscv)
238
239// This space deliberately left blank for now.
240// No other libcs have any riscv64-specific structs.
241
Elliott Hughese888de82013-11-19 15:32:31 -0800242#else
243
Christopher Ferris363390e2013-11-22 18:00:09 -0800244#error "Unsupported architecture."
Elliott Hughese888de82013-11-19 15:32:31 -0800245
246#endif
247
248__END_DECLS