1 /*
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 #pragma once
30 
31 #include <sys/cdefs.h>
32 #include <stddef.h> /* For size_t. */
33 #include <stdint.h>
34 
35 #include <bits/page_size.h>
36 
37 __BEGIN_DECLS
38 
39 #if defined(__i386__)
40 
41 struct user_fpregs_struct {
42   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 };
51 struct user_fpxregs_struct {
52   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 };
66 struct user_regs_struct {
67   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;
84 };
85 struct user {
86   struct user_regs_struct regs;
87   int u_fpvalid;
88   struct user_fpregs_struct i387;
89   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;
96   struct user_regs_struct* u_ar0;
97   struct user_fpregs_struct* u_fpstate;
98   unsigned long magic;
99   char u_comm[32];
100   int u_debugreg[8];
101 };
102 
103 #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 
107 #elif defined(__x86_64__)
108 
109 struct user_fpregs_struct {
110   unsigned short cwd;
111   unsigned short swd;
112   unsigned short ftw;
113   unsigned short fop;
114   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];
121 };
122 struct user_regs_struct {
123   unsigned long r15;
124   unsigned long r14;
125   unsigned long r13;
126   unsigned long r12;
127   unsigned long rbp;
128   unsigned long rbx;
129   unsigned long r11;
130   unsigned long r10;
131   unsigned long r9;
132   unsigned long r8;
133   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;
140   unsigned long cs;
141   unsigned long eflags;
142   unsigned long rsp;
143   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 };
151 struct user {
152   struct user_regs_struct regs;
153   int u_fpvalid;
154   int pad0;
155   struct user_fpregs_struct i387;
156   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;
164   struct user_regs_struct* u_ar0;
165   struct user_fpregs_struct* u_fpstate;
166   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 
173 #elif defined(__arm__)
174 
175 struct user_fpregs {
176   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 };
190 struct user_regs {
191   unsigned long uregs[18];
192 };
193 struct user_vfp {
194   unsigned long long fpregs[32];
195   unsigned long fpscr;
196 };
197 struct user_vfp_exc {
198   unsigned long fpexc;
199   unsigned long fpinst;
200   unsigned long fpinst2;
201 };
202 struct user {
203   struct user_regs regs;
204   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;
212   struct user_regs* u_ar0;
213   unsigned long magic;
214   char u_comm[32];
215   int u_debugreg[8];
216   struct user_fpregs u_fp;
217   struct user_fpregs* u_fp0;
218 };
219 
220 #elif defined(__aarch64__)
221 
222 struct user_regs_struct {
223   uint64_t regs[31];
224   uint64_t sp;
225   uint64_t pc;
226   uint64_t pstate;
227 };
228 struct user_fpsimd_struct {
229   __uint128_t vregs[32];
230   uint32_t fpsr;
231   uint32_t fpcr;
232 };
233 
234 #elif defined(__riscv)
235 
236 // This space deliberately left blank for now.
237 // No other libcs have any riscv64-specific structs.
238 
239 #else
240 
241 #error "Unsupported architecture."
242 
243 #endif
244 
245 __END_DECLS
246