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