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