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 #ifndef _SYS_USER_H_ 30 #define _SYS_USER_H_ 31 32 #include <sys/cdefs.h> 33 #include <stddef.h> /* For size_t. */ 34 #include <stdint.h> 35 36 __BEGIN_DECLS 37 38 #define PAGE_SIZE 4096 39 #define PAGE_MASK (~(PAGE_SIZE - 1)) 40 41 #if defined(__i386__) 42 43 struct user_fpregs_struct { 44 long cwd; 45 long swd; 46 long twd; 47 long fip; 48 long fcs; 49 long foo; 50 long fos; 51 long st_space[20]; 52 }; 53 struct user_fpxregs_struct { 54 unsigned short cwd; 55 unsigned short swd; 56 unsigned short twd; 57 unsigned short fop; 58 long fip; 59 long fcs; 60 long foo; 61 long fos; 62 long mxcsr; 63 long reserved; 64 long st_space[32]; 65 long xmm_space[32]; 66 long padding[56]; 67 }; 68 struct user_regs_struct { 69 long ebx; 70 long ecx; 71 long edx; 72 long esi; 73 long edi; 74 long ebp; 75 long eax; 76 long xds; 77 long xes; 78 long xfs; 79 long xgs; 80 long orig_eax; 81 long eip; 82 long xcs; 83 long eflags; 84 long esp; 85 long xss; 86 }; 87 struct user { 88 struct user_regs_struct regs; 89 int u_fpvalid; 90 struct user_fpregs_struct i387; 91 unsigned long int u_tsize; 92 unsigned long int u_dsize; 93 unsigned long int u_ssize; 94 unsigned long start_code; 95 unsigned long start_stack; 96 long int signal; 97 int reserved; 98 struct user_regs_struct* u_ar0; 99 struct user_fpregs_struct* u_fpstate; 100 unsigned long magic; 101 char u_comm[32]; 102 int u_debugreg[8]; 103 }; 104 105 #define UPAGES 1 106 #define HOST_TEXT_START_ADDR (u.start_code) 107 #define HOST_STACK_END_ADDR (u.start_stack + u.u_ssize * PAGE_SIZE) 108 109 #elif defined(__x86_64__) 110 111 struct user_fpregs_struct { 112 unsigned short cwd; 113 unsigned short swd; 114 unsigned short ftw; 115 unsigned short fop; 116 unsigned long rip; 117 unsigned long rdp; 118 unsigned int mxcsr; 119 unsigned int mxcr_mask; 120 unsigned int st_space[32]; 121 unsigned int xmm_space[64]; 122 unsigned int padding[24]; 123 }; 124 struct user_regs_struct { 125 unsigned long r15; 126 unsigned long r14; 127 unsigned long r13; 128 unsigned long r12; 129 unsigned long rbp; 130 unsigned long rbx; 131 unsigned long r11; 132 unsigned long r10; 133 unsigned long r9; 134 unsigned long r8; 135 unsigned long rax; 136 unsigned long rcx; 137 unsigned long rdx; 138 unsigned long rsi; 139 unsigned long rdi; 140 unsigned long orig_rax; 141 unsigned long rip; 142 unsigned long cs; 143 unsigned long eflags; 144 unsigned long rsp; 145 unsigned long ss; 146 unsigned long fs_base; 147 unsigned long gs_base; 148 unsigned long ds; 149 unsigned long es; 150 unsigned long fs; 151 unsigned long gs; 152 }; 153 struct user { 154 struct user_regs_struct regs; 155 int u_fpvalid; 156 int pad0; 157 struct user_fpregs_struct i387; 158 unsigned long int u_tsize; 159 unsigned long int u_dsize; 160 unsigned long int u_ssize; 161 unsigned long start_code; 162 unsigned long start_stack; 163 long int signal; 164 int reserved; 165 int pad1; 166 struct user_regs_struct* u_ar0; 167 struct user_fpregs_struct* u_fpstate; 168 unsigned long magic; 169 char u_comm[32]; 170 unsigned long u_debugreg[8]; 171 unsigned long error_code; 172 unsigned long fault_address; 173 }; 174 175 #elif defined(__mips__) 176 177 struct user { 178 unsigned long regs[180 / sizeof(unsigned long) + 64]; 179 size_t u_tsize; 180 size_t u_dsize; 181 size_t u_ssize; 182 unsigned long start_code; 183 unsigned long start_data; 184 unsigned long start_stack; 185 long int signal; 186 void* u_ar0; 187 unsigned long magic; 188 char u_comm[32]; 189 }; 190 191 #elif defined(__arm__) 192 193 struct user_fpregs { 194 struct fp_reg { 195 unsigned int sign1:1; 196 unsigned int unused:15; 197 unsigned int sign2:1; 198 unsigned int exponent:14; 199 unsigned int j:1; 200 unsigned int mantissa1:31; 201 unsigned int mantissa0:32; 202 } fpregs[8]; 203 unsigned int fpsr:32; 204 unsigned int fpcr:32; 205 unsigned char ftype[8]; 206 unsigned int init_flag; 207 }; 208 struct user_regs { 209 unsigned long uregs[18]; 210 }; 211 struct user_vfp { 212 unsigned long long fpregs[32]; 213 unsigned long fpscr; 214 }; 215 struct user_vfp_exc { 216 unsigned long fpexc; 217 unsigned long fpinst; 218 unsigned long fpinst2; 219 }; 220 struct user { 221 struct user_regs regs; 222 int u_fpvalid; 223 unsigned long int u_tsize; 224 unsigned long int u_dsize; 225 unsigned long int u_ssize; 226 unsigned long start_code; 227 unsigned long start_stack; 228 long int signal; 229 int reserved; 230 struct user_regs* u_ar0; 231 unsigned long magic; 232 char u_comm[32]; 233 int u_debugreg[8]; 234 struct user_fpregs u_fp; 235 struct user_fpregs* u_fp0; 236 }; 237 238 #elif defined(__aarch64__) 239 240 struct user_regs_struct { 241 uint64_t regs[31]; 242 uint64_t sp; 243 uint64_t pc; 244 uint64_t pstate; 245 }; 246 struct user_fpsimd_struct { 247 __uint128_t vregs[32]; 248 uint32_t fpsr; 249 uint32_t fpcr; 250 }; 251 252 #else 253 254 #error "Unsupported architecture." 255 256 #endif 257 258 __END_DECLS 259 260 #endif /* _SYS_USER_H_ */ 261