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 | |
| 39 | #error TODO |
| 40 | |
| 41 | #elif defined(__arm64__) |
| 42 | |
| 43 | #error TODO |
| 44 | |
| 45 | #elif defined(__i386__) |
| 46 | |
| 47 | enum { |
| 48 | REG_GS = 0, |
| 49 | REG_FS, |
| 50 | REG_ES, |
| 51 | REG_DS, |
| 52 | REG_EDI, |
| 53 | REG_ESI, |
| 54 | REG_EBP, |
| 55 | REG_ESP, |
| 56 | REG_EBX, |
| 57 | REG_EDX, |
| 58 | REG_ECX, |
| 59 | REG_EAX, |
| 60 | REG_TRAPNO, |
| 61 | REG_ERR, |
| 62 | REG_EIP, |
| 63 | REG_CS, |
| 64 | REG_EFL, |
| 65 | REG_UESP, |
| 66 | REG_SS, |
| 67 | NGREG |
| 68 | }; |
| 69 | |
| 70 | typedef int greg_t; |
| 71 | typedef greg_t gregset_t[NGREG]; |
| 72 | |
| 73 | struct _libc_fpreg { |
| 74 | unsigned short significand[4]; |
| 75 | unsigned short exponent; |
| 76 | }; |
| 77 | |
| 78 | struct _libc_fpstate { |
| 79 | unsigned long cw; |
| 80 | unsigned long sw; |
| 81 | unsigned long tag; |
| 82 | unsigned long ipoff; |
| 83 | unsigned long cssel; |
| 84 | unsigned long dataoff; |
| 85 | unsigned long datasel; |
| 86 | struct _libc_fpreg _st[8]; |
| 87 | unsigned long status; |
| 88 | }; |
| 89 | |
| 90 | typedef struct _libc_fpstate* fpregset_t; |
| 91 | |
| 92 | typedef struct { |
| 93 | gregset_t gregs; |
| 94 | fpregset_t fpregs; |
| 95 | unsigned long oldmask; |
| 96 | unsigned long cr2; |
| 97 | } mcontext_t; |
| 98 | |
| 99 | typedef struct ucontext { |
| 100 | unsigned long uc_flags; |
| 101 | struct ucontext* uc_link; |
| 102 | stack_t uc_stack; |
| 103 | mcontext_t uc_mcontext; |
| 104 | sigset_t uc_sigmask; |
| 105 | /* TODO: __fpregs_mem? */ |
| 106 | } ucontext_t; |
| 107 | |
| 108 | #elif defined(__mips__) |
| 109 | |
| 110 | #error TODO |
| 111 | |
| 112 | #elif defined(__mips64__) |
| 113 | |
| 114 | #error TODO |
| 115 | |
| 116 | #elif defined(__x86_64__) |
Pavel Chupin | e61d106 | 2014-01-27 17:56:43 +0400 | [diff] [blame] | 117 | |
| 118 | enum { |
| 119 | REG_R8 = 0, |
| 120 | REG_R9, |
| 121 | REG_R10, |
| 122 | REG_R11, |
| 123 | REG_R12, |
| 124 | REG_R13, |
| 125 | REG_R14, |
| 126 | REG_R15, |
| 127 | REG_RDI, |
| 128 | REG_RSI, |
| 129 | REG_RBP, |
| 130 | REG_RBX, |
| 131 | REG_RDX, |
| 132 | REG_RAX, |
| 133 | REG_RCX, |
| 134 | REG_RSP, |
| 135 | REG_RIP, |
| 136 | REG_EFL, |
| 137 | REG_CSGSFS, |
| 138 | REG_ERR, |
| 139 | REG_TRAPNO, |
| 140 | REG_OLDMASK, |
| 141 | REG_CR2, |
| 142 | NGREG |
| 143 | }; |
| 144 | |
| 145 | typedef long greg_t; |
| 146 | typedef greg_t gregset_t[NGREG]; |
| 147 | |
| 148 | typedef struct user_i387_struct* fpregset_t; |
| 149 | |
| 150 | typedef struct { |
| 151 | gregset_t gregs; |
| 152 | fpregset_t fpregs; |
| 153 | /* TODO: reserved space? */ |
| 154 | } mcontext_t; |
| 155 | |
| 156 | typedef struct ucontext { |
| 157 | unsigned long uc_flags; |
| 158 | struct ucontext* uc_link; |
| 159 | stack_t uc_stack; |
| 160 | mcontext_t uc_mcontext; |
| 161 | sigset_t uc_sigmask; |
| 162 | /* TODO: __fpregs_mem? */ |
| 163 | } ucontext_t; |
| 164 | |
Elliott Hughes | 677a07c | 2014-01-29 16:46:00 -0800 | [diff] [blame^] | 165 | #endif |
Pavel Chupin | e61d106 | 2014-01-27 17:56:43 +0400 | [diff] [blame] | 166 | |
| 167 | __END_DECLS |
| 168 | |
| 169 | #endif /* _SYS_UCONTEXT_H_ */ |