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(__arm__) 176 177 struct user_fpregs { 178 struct fp_reg { 179 unsigned int sign1:1; 180 unsigned int unused:15; 181 unsigned int sign2:1; 182 unsigned int exponent:14; 183 unsigned int j:1; 184 unsigned int mantissa1:31; 185 unsigned int mantissa0:32; 186 } fpregs[8]; 187 unsigned int fpsr:32; 188 unsigned int fpcr:32; 189 unsigned char ftype[8]; 190 unsigned int init_flag; 191 }; 192 struct user_regs { 193 unsigned long uregs[18]; 194 }; 195 struct user_vfp { 196 unsigned long long fpregs[32]; 197 unsigned long fpscr; 198 }; 199 struct user_vfp_exc { 200 unsigned long fpexc; 201 unsigned long fpinst; 202 unsigned long fpinst2; 203 }; 204 struct user { 205 struct user_regs regs; 206 int u_fpvalid; 207 unsigned long int u_tsize; 208 unsigned long int u_dsize; 209 unsigned long int u_ssize; 210 unsigned long start_code; 211 unsigned long start_stack; 212 long int signal; 213 int reserved; 214 struct user_regs* u_ar0; 215 unsigned long magic; 216 char u_comm[32]; 217 int u_debugreg[8]; 218 struct user_fpregs u_fp; 219 struct user_fpregs* u_fp0; 220 }; 221 222 #elif defined(__aarch64__) 223 224 struct user_regs_struct { 225 uint64_t regs[31]; 226 uint64_t sp; 227 uint64_t pc; 228 uint64_t pstate; 229 }; 230 struct user_fpsimd_struct { 231 __uint128_t vregs[32]; 232 uint32_t fpsr; 233 uint32_t fpcr; 234 }; 235 236 #else 237 238 #error "Unsupported architecture." 239 240 #endif 241 242 __END_DECLS 243 244 #endif /* _SYS_USER_H_ */ 245