ucontext.h revision eb454522da53759ef74180b9c623206040b17df0
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 39enum { 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 60typedef int greg_t; 61typedef greg_t gregset_t[NGREG]; 62 63#include <asm/sigcontext.h> 64typedef struct sigcontext mcontext_t; 65 66typedef 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 char __padding[128 - sizeof(sigset_t)]; 73 unsigned long uc_regspace[128] __attribute__((__aligned__(8))); 74} ucontext_t; 75 76#elif defined(__aarch64__) 77 78#include <asm/sigcontext.h> 79typedef struct sigcontext mcontext_t; 80 81typedef struct ucontext { 82 unsigned long uc_flags; 83 struct ucontext *uc_link; 84 stack_t uc_stack; 85 sigset_t uc_sigmask; 86 char __padding[128 - sizeof(sigset_t)]; 87 mcontext_t uc_mcontext; 88} ucontext_t; 89 90#elif defined(__i386__) 91 92enum { 93 REG_GS = 0, 94 REG_FS, 95 REG_ES, 96 REG_DS, 97 REG_EDI, 98 REG_ESI, 99 REG_EBP, 100 REG_ESP, 101 REG_EBX, 102 REG_EDX, 103 REG_ECX, 104 REG_EAX, 105 REG_TRAPNO, 106 REG_ERR, 107 REG_EIP, 108 REG_CS, 109 REG_EFL, 110 REG_UESP, 111 REG_SS, 112 NGREG 113}; 114 115typedef int greg_t; 116typedef greg_t gregset_t[NGREG]; 117 118struct _libc_fpreg { 119 unsigned short significand[4]; 120 unsigned short exponent; 121}; 122 123struct _libc_fpstate { 124 unsigned long cw; 125 unsigned long sw; 126 unsigned long tag; 127 unsigned long ipoff; 128 unsigned long cssel; 129 unsigned long dataoff; 130 unsigned long datasel; 131 struct _libc_fpreg _st[8]; 132 unsigned long status; 133}; 134 135typedef struct _libc_fpstate* fpregset_t; 136 137typedef struct { 138 gregset_t gregs; 139 fpregset_t fpregs; 140 unsigned long oldmask; 141 unsigned long cr2; 142} mcontext_t; 143 144typedef struct ucontext { 145 unsigned long uc_flags; 146 struct ucontext* uc_link; 147 stack_t uc_stack; 148 mcontext_t uc_mcontext; 149 sigset_t uc_sigmask; 150 char __padding[128 - sizeof(sigset_t)]; 151 struct _libc_fpstate __fpregs_mem; 152} ucontext_t; 153 154#elif defined(__mips__) 155 156/* glibc doesn't have names for MIPS registers. */ 157 158#define NGREG 32 159#define NFPREG 32 160 161typedef unsigned long long greg_t; 162typedef greg_t gregset_t[NGREG]; 163 164typedef struct fpregset { 165 union { 166 double fp_dregs[NFPREG]; 167 struct { 168 float _fp_fregs; 169 unsigned _fp_pad; 170 } fp_fregs[NFPREG]; 171 } fp_r; 172} fpregset_t; 173 174typedef struct { 175 unsigned regmask; 176 unsigned status; 177 greg_t pc; 178 gregset_t gregs; 179 fpregset_t fpregs; 180 unsigned fp_owned; 181 unsigned fpc_csr; 182 unsigned fpc_eir; 183 unsigned used_math; 184 unsigned dsp; 185 greg_t mdhi; 186 greg_t mdlo; 187 unsigned long hi1; 188 unsigned long lo1; 189 unsigned long hi2; 190 unsigned long lo2; 191 unsigned long hi3; 192 unsigned long lo3; 193} mcontext_t; 194 195typedef struct ucontext { 196 unsigned long uc_flags; 197 struct ucontext* uc_link; 198 stack_t uc_stack; 199 mcontext_t uc_mcontext; 200 sigset_t uc_sigmask; 201} ucontext_t; 202 203#elif defined(__mips64__) 204 205#error TODO 206 207#elif defined(__x86_64__) 208 209enum { 210 REG_R8 = 0, 211 REG_R9, 212 REG_R10, 213 REG_R11, 214 REG_R12, 215 REG_R13, 216 REG_R14, 217 REG_R15, 218 REG_RDI, 219 REG_RSI, 220 REG_RBP, 221 REG_RBX, 222 REG_RDX, 223 REG_RAX, 224 REG_RCX, 225 REG_RSP, 226 REG_RIP, 227 REG_EFL, 228 REG_CSGSFS, 229 REG_ERR, 230 REG_TRAPNO, 231 REG_OLDMASK, 232 REG_CR2, 233 NGREG 234}; 235 236typedef long greg_t; 237typedef greg_t gregset_t[NGREG]; 238 239struct _libc_fpxreg { 240 unsigned short significand[4]; 241 unsigned short exponent; 242 unsigned short padding[3]; 243}; 244 245struct _libc_xmmreg { 246 uint32_t element[4]; 247}; 248 249struct _libc_fpstate { 250 uint16_t cwd; 251 uint16_t swd; 252 uint16_t ftw; 253 uint16_t fop; 254 uint64_t rip; 255 uint64_t rdp; 256 uint32_t mxcsr; 257 uint32_t mxcr_mask; 258 struct _libc_fpxreg _st[8]; 259 struct _libc_xmmreg _xmm[16]; 260 uint32_t padding[24]; 261}; 262 263typedef struct _libc_fpstate* fpregset_t; 264 265typedef struct { 266 gregset_t gregs; 267 fpregset_t fpregs; 268 unsigned long __reserved1[8]; 269} mcontext_t; 270 271typedef struct ucontext { 272 unsigned long uc_flags; 273 struct ucontext* uc_link; 274 stack_t uc_stack; 275 mcontext_t uc_mcontext; 276 sigset_t uc_sigmask; 277 char __padding[128 - sizeof(sigset_t)]; 278 struct _libc_fpstate __fpregs_mem; 279} ucontext_t; 280 281#endif 282 283__END_DECLS 284 285#endif /* _SYS_UCONTEXT_H_ */ 286