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