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 | |
| 77 | #elif defined(__arm64__) |
| 78 | |
| 79 | #error TODO |
| 80 | |
| 81 | #elif defined(__i386__) |
| 82 | |
| 83 | enum { |
| 84 | REG_GS = 0, |
| 85 | REG_FS, |
| 86 | REG_ES, |
| 87 | REG_DS, |
| 88 | REG_EDI, |
| 89 | REG_ESI, |
| 90 | REG_EBP, |
| 91 | REG_ESP, |
| 92 | REG_EBX, |
| 93 | REG_EDX, |
| 94 | REG_ECX, |
| 95 | REG_EAX, |
| 96 | REG_TRAPNO, |
| 97 | REG_ERR, |
| 98 | REG_EIP, |
| 99 | REG_CS, |
| 100 | REG_EFL, |
| 101 | REG_UESP, |
| 102 | REG_SS, |
| 103 | NGREG |
| 104 | }; |
| 105 | |
| 106 | typedef int greg_t; |
| 107 | typedef greg_t gregset_t[NGREG]; |
| 108 | |
| 109 | struct _libc_fpreg { |
| 110 | unsigned short significand[4]; |
| 111 | unsigned short exponent; |
| 112 | }; |
| 113 | |
| 114 | struct _libc_fpstate { |
| 115 | unsigned long cw; |
| 116 | unsigned long sw; |
| 117 | unsigned long tag; |
| 118 | unsigned long ipoff; |
| 119 | unsigned long cssel; |
| 120 | unsigned long dataoff; |
| 121 | unsigned long datasel; |
| 122 | struct _libc_fpreg _st[8]; |
| 123 | unsigned long status; |
| 124 | }; |
| 125 | |
| 126 | typedef struct _libc_fpstate* fpregset_t; |
| 127 | |
| 128 | typedef struct { |
| 129 | gregset_t gregs; |
| 130 | fpregset_t fpregs; |
| 131 | unsigned long oldmask; |
| 132 | unsigned long cr2; |
| 133 | } mcontext_t; |
| 134 | |
| 135 | typedef struct ucontext { |
| 136 | unsigned long uc_flags; |
| 137 | struct ucontext* uc_link; |
| 138 | stack_t uc_stack; |
| 139 | mcontext_t uc_mcontext; |
| 140 | sigset_t uc_sigmask; |
| 141 | /* TODO: __fpregs_mem? */ |
| 142 | } ucontext_t; |
| 143 | |
| 144 | #elif defined(__mips__) |
| 145 | |
| 146 | #error TODO |
| 147 | |
| 148 | #elif defined(__mips64__) |
| 149 | |
| 150 | #error TODO |
| 151 | |
| 152 | #elif defined(__x86_64__) |
Pavel Chupin | e61d106 | 2014-01-27 17:56:43 +0400 | [diff] [blame] | 153 | |
| 154 | enum { |
| 155 | REG_R8 = 0, |
| 156 | REG_R9, |
| 157 | REG_R10, |
| 158 | REG_R11, |
| 159 | REG_R12, |
| 160 | REG_R13, |
| 161 | REG_R14, |
| 162 | REG_R15, |
| 163 | REG_RDI, |
| 164 | REG_RSI, |
| 165 | REG_RBP, |
| 166 | REG_RBX, |
| 167 | REG_RDX, |
| 168 | REG_RAX, |
| 169 | REG_RCX, |
| 170 | REG_RSP, |
| 171 | REG_RIP, |
| 172 | REG_EFL, |
| 173 | REG_CSGSFS, |
| 174 | REG_ERR, |
| 175 | REG_TRAPNO, |
| 176 | REG_OLDMASK, |
| 177 | REG_CR2, |
| 178 | NGREG |
| 179 | }; |
| 180 | |
| 181 | typedef long greg_t; |
| 182 | typedef greg_t gregset_t[NGREG]; |
| 183 | |
| 184 | typedef struct user_i387_struct* fpregset_t; |
| 185 | |
| 186 | typedef struct { |
| 187 | gregset_t gregs; |
| 188 | fpregset_t fpregs; |
| 189 | /* TODO: reserved space? */ |
| 190 | } mcontext_t; |
| 191 | |
| 192 | typedef struct ucontext { |
| 193 | unsigned long uc_flags; |
| 194 | struct ucontext* uc_link; |
| 195 | stack_t uc_stack; |
| 196 | mcontext_t uc_mcontext; |
| 197 | sigset_t uc_sigmask; |
| 198 | /* TODO: __fpregs_mem? */ |
| 199 | } ucontext_t; |
| 200 | |
Elliott Hughes | 677a07c | 2014-01-29 16:46:00 -0800 | [diff] [blame] | 201 | #endif |
Pavel Chupin | e61d106 | 2014-01-27 17:56:43 +0400 | [diff] [blame] | 202 | |
| 203 | __END_DECLS |
| 204 | |
| 205 | #endif /* _SYS_UCONTEXT_H_ */ |