1 /* 2 * Copyright (C) 2014 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_UCONTEXT_H_ 30 #define _SYS_UCONTEXT_H_ 31 32 #include <signal.h> 33 #include <sys/user.h> 34 35 __BEGIN_DECLS 36 37 #if defined(__arm__) 38 39 enum { 40 REG_R0 = 0, 41 REG_R1, 42 REG_R2, 43 REG_R3, 44 REG_R4, 45 REG_R5, 46 REG_R6, 47 REG_R7, 48 REG_R8, 49 REG_R9, 50 REG_R10, 51 REG_R11, 52 REG_R12, 53 REG_R13, 54 REG_R14, 55 REG_R15, 56 }; 57 58 #define NGREG 18 /* Like glibc. */ 59 60 typedef int greg_t; 61 typedef greg_t gregset_t[NGREG]; 62 63 #include <asm/sigcontext.h> 64 typedef struct sigcontext mcontext_t; 65 66 typedef struct ucontext { 67 unsigned long uc_flags; 68 struct ucontext* uc_link; 69 stack_t uc_stack; 70 mcontext_t uc_mcontext; 71 sigset_t uc_sigmask; 72 // Android has a wrong (smaller) sigset_t on ARM. 73 uint32_t __padding_rt_sigset; 74 // The kernel adds extra padding after uc_sigmask to match glibc sigset_t on ARM. 75 char __padding[120]; 76 unsigned long uc_regspace[128] __attribute__((__aligned__(8))); 77 } ucontext_t; 78 79 #elif defined(__aarch64__) 80 81 #define NGREG 34 /* x0..x30 + sp + pc + pstate */ 82 typedef unsigned long greg_t; 83 typedef greg_t gregset_t[NGREG]; 84 85 #include <asm/sigcontext.h> 86 typedef struct sigcontext mcontext_t; 87 88 typedef struct ucontext { 89 unsigned long uc_flags; 90 struct ucontext *uc_link; 91 stack_t uc_stack; 92 sigset_t uc_sigmask; 93 // The kernel adds extra padding after uc_sigmask to match glibc sigset_t on ARM64. 94 char __padding[128 - sizeof(sigset_t)]; 95 mcontext_t uc_mcontext; 96 } ucontext_t; 97 98 #elif defined(__i386__) 99 100 enum { 101 REG_GS = 0, 102 REG_FS, 103 REG_ES, 104 REG_DS, 105 REG_EDI, 106 REG_ESI, 107 REG_EBP, 108 REG_ESP, 109 REG_EBX, 110 REG_EDX, 111 REG_ECX, 112 REG_EAX, 113 REG_TRAPNO, 114 REG_ERR, 115 REG_EIP, 116 REG_CS, 117 REG_EFL, 118 REG_UESP, 119 REG_SS, 120 NGREG 121 }; 122 123 typedef int greg_t; 124 typedef greg_t gregset_t[NGREG]; 125 126 struct _libc_fpreg { 127 unsigned short significand[4]; 128 unsigned short exponent; 129 }; 130 131 struct _libc_fpstate { 132 unsigned long cw; 133 unsigned long sw; 134 unsigned long tag; 135 unsigned long ipoff; 136 unsigned long cssel; 137 unsigned long dataoff; 138 unsigned long datasel; 139 struct _libc_fpreg _st[8]; 140 unsigned long status; 141 }; 142 143 typedef struct _libc_fpstate* fpregset_t; 144 145 typedef struct { 146 gregset_t gregs; 147 fpregset_t fpregs; 148 unsigned long oldmask; 149 unsigned long cr2; 150 } mcontext_t; 151 152 typedef struct ucontext { 153 unsigned long uc_flags; 154 struct ucontext* uc_link; 155 stack_t uc_stack; 156 mcontext_t uc_mcontext; 157 sigset_t uc_sigmask; 158 // Android has a wrong (smaller) sigset_t on x86. 159 uint32_t __padding_rt_sigset; 160 struct _libc_fpstate __fpregs_mem; 161 } ucontext_t; 162 163 #elif defined(__mips__) 164 165 /* glibc doesn't have names for MIPS registers. */ 166 167 #define NGREG 32 168 #define NFPREG 32 169 170 typedef unsigned long long greg_t; 171 typedef greg_t gregset_t[NGREG]; 172 173 typedef struct fpregset { 174 union { 175 double fp_dregs[NFPREG]; 176 struct { 177 float _fp_fregs; 178 unsigned _fp_pad; 179 } fp_fregs[NFPREG]; 180 } fp_r; 181 } fpregset_t; 182 183 #ifdef __LP64__ 184 typedef struct { 185 gregset_t gregs; 186 fpregset_t fpregs; 187 greg_t mdhi; 188 greg_t hi1; 189 greg_t hi2; 190 greg_t hi3; 191 greg_t mdlo; 192 greg_t lo1; 193 greg_t lo2; 194 greg_t lo3; 195 greg_t pc; 196 uint32_t fpc_csr; 197 uint32_t used_math; 198 uint32_t dsp; 199 uint32_t reserved; 200 } mcontext_t; 201 #else 202 typedef struct { 203 unsigned regmask; 204 unsigned status; 205 greg_t pc; 206 gregset_t gregs; 207 fpregset_t fpregs; 208 unsigned fp_owned; 209 unsigned fpc_csr; 210 unsigned fpc_eir; 211 unsigned used_math; 212 unsigned dsp; 213 greg_t mdhi; 214 greg_t mdlo; 215 unsigned long hi1; 216 unsigned long lo1; 217 unsigned long hi2; 218 unsigned long lo2; 219 unsigned long hi3; 220 unsigned long lo3; 221 } mcontext_t; 222 #endif 223 224 typedef struct ucontext { 225 unsigned long uc_flags; 226 struct ucontext* uc_link; 227 stack_t uc_stack; 228 mcontext_t uc_mcontext; 229 sigset_t uc_sigmask; 230 } ucontext_t; 231 232 #elif defined(__x86_64__) 233 234 enum { 235 REG_R8 = 0, 236 REG_R9, 237 REG_R10, 238 REG_R11, 239 REG_R12, 240 REG_R13, 241 REG_R14, 242 REG_R15, 243 REG_RDI, 244 REG_RSI, 245 REG_RBP, 246 REG_RBX, 247 REG_RDX, 248 REG_RAX, 249 REG_RCX, 250 REG_RSP, 251 REG_RIP, 252 REG_EFL, 253 REG_CSGSFS, 254 REG_ERR, 255 REG_TRAPNO, 256 REG_OLDMASK, 257 REG_CR2, 258 NGREG 259 }; 260 261 typedef long greg_t; 262 typedef greg_t gregset_t[NGREG]; 263 264 struct _libc_fpxreg { 265 unsigned short significand[4]; 266 unsigned short exponent; 267 unsigned short padding[3]; 268 }; 269 270 struct _libc_xmmreg { 271 uint32_t element[4]; 272 }; 273 274 struct _libc_fpstate { 275 uint16_t cwd; 276 uint16_t swd; 277 uint16_t ftw; 278 uint16_t fop; 279 uint64_t rip; 280 uint64_t rdp; 281 uint32_t mxcsr; 282 uint32_t mxcr_mask; 283 struct _libc_fpxreg _st[8]; 284 struct _libc_xmmreg _xmm[16]; 285 uint32_t padding[24]; 286 }; 287 288 typedef struct _libc_fpstate* fpregset_t; 289 290 typedef struct { 291 gregset_t gregs; 292 fpregset_t fpregs; 293 unsigned long __reserved1[8]; 294 } mcontext_t; 295 296 typedef struct ucontext { 297 unsigned long uc_flags; 298 struct ucontext* uc_link; 299 stack_t uc_stack; 300 mcontext_t uc_mcontext; 301 sigset_t uc_sigmask; 302 struct _libc_fpstate __fpregs_mem; 303 } ucontext_t; 304 305 #endif 306 307 __END_DECLS 308 309 #endif /* _SYS_UCONTEXT_H_ */ 310