1 /* Copyright (C) 2001, 2002 Free Software Foundation, Inc. 2 This file is part of the GNU C Library. 3 4 The GNU C Library is free software; you can redistribute it and/or 5 modify it under the terms of the GNU Lesser General Public 6 License as published by the Free Software Foundation; either 7 version 2.1 of the License, or (at your option) any later version. 8 9 The GNU C Library is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Lesser General Public License for more details. 13 14 You should have received a copy of the GNU Lesser General Public 15 License along with the GNU C Library; if not, see 16 <http://www.gnu.org/licenses/>. */ 17 18 #ifndef _SYS_UCONTEXT_H 19 #define _SYS_UCONTEXT_H 1 20 21 #include <features.h> 22 #include <signal.h> 23 #include <bits/wordsize.h> 24 25 /* We need the signal context definitions even if they are not used 26 included in <signal.h>. */ 27 #include <bits/sigcontext.h> 28 29 #if __WORDSIZE == 64 30 31 /* Type for general register. */ 32 typedef long int greg_t; 33 34 /* Number of general registers. */ 35 #define NGREG 23 36 37 /* Container for all general registers. */ 38 typedef greg_t gregset_t[NGREG]; 39 40 #ifdef __USE_GNU 41 /* Number of each register in the `gregset_t' array. */ 42 enum 43 { 44 REG_R8 = 0, 45 # define REG_R8 REG_R8 46 REG_R9, 47 # define REG_R9 REG_R9 48 REG_R10, 49 # define REG_R10 REG_R10 50 REG_R11, 51 # define REG_R11 REG_R11 52 REG_R12, 53 # define REG_R12 REG_R12 54 REG_R13, 55 # define REG_R13 REG_R13 56 REG_R14, 57 # define REG_R14 REG_R14 58 REG_R15, 59 # define REG_R15 REG_R15 60 REG_RDI, 61 # define REG_RDI REG_RDI 62 REG_RSI, 63 # define REG_RSI REG_RSI 64 REG_RBP, 65 # define REG_RBP REG_RBP 66 REG_RBX, 67 # define REG_RBX REG_RBX 68 REG_RDX, 69 # define REG_RDX REG_RDX 70 REG_RAX, 71 # define REG_RAX REG_RAX 72 REG_RCX, 73 # define REG_RCX REG_RCX 74 REG_RSP, 75 # define REG_RSP REG_RSP 76 REG_RIP, 77 # define REG_RIP REG_RIP 78 REG_EFL, 79 # define REG_EFL REG_EFL 80 REG_CSGSFS, /* Actually short cs, gs, fs, __pad0. */ 81 # define REG_CSGSFS REG_CSGSFS 82 REG_ERR, 83 # define REG_ERR REG_ERR 84 REG_TRAPNO, 85 # define REG_TRAPNO REG_TRAPNO 86 REG_OLDMASK, 87 # define REG_OLDMASK REG_OLDMASK 88 REG_CR2 89 # define REG_CR2 REG_CR2 90 }; 91 #endif 92 93 struct _libc_fpxreg 94 { 95 unsigned short int significand[4]; 96 unsigned short int exponent; 97 unsigned short int padding[3]; 98 }; 99 100 struct _libc_xmmreg 101 { 102 __uint32_t element[4]; 103 }; 104 105 struct _libc_fpstate 106 { 107 /* 64-bit FXSAVE format. */ 108 __uint16_t cwd; 109 __uint16_t swd; 110 __uint16_t ftw; 111 __uint16_t fop; 112 __uint64_t rip; 113 __uint64_t rdp; 114 __uint32_t mxcsr; 115 __uint32_t mxcr_mask; 116 struct _libc_fpxreg _st[8]; 117 struct _libc_xmmreg _xmm[16]; 118 __uint32_t padding[24]; 119 }; 120 121 /* Structure to describe FPU registers. */ 122 typedef struct _libc_fpstate *fpregset_t; 123 124 /* Context to describe whole processor state. */ 125 typedef struct 126 { 127 gregset_t gregs; 128 /* Note that fpregs is a pointer. */ 129 fpregset_t fpregs; 130 unsigned long __reserved1 [8]; 131 } mcontext_t; 132 133 /* Userlevel context. */ 134 typedef struct ucontext 135 { 136 unsigned long int uc_flags; 137 struct ucontext *uc_link; 138 stack_t uc_stack; 139 mcontext_t uc_mcontext; 140 __sigset_t uc_sigmask; 141 struct _libc_fpstate __fpregs_mem; 142 } ucontext_t; 143 144 #else /* __WORDSIZE == 32 */ 145 146 /* Type for general register. */ 147 typedef int greg_t; 148 149 /* Number of general registers. */ 150 #define NGREG 19 151 152 /* Container for all general registers. */ 153 typedef greg_t gregset_t[NGREG]; 154 155 #ifdef __USE_GNU 156 /* Number of each register is the `gregset_t' array. */ 157 enum 158 { 159 REG_GS = 0, 160 # define REG_GS REG_GS 161 REG_FS, 162 # define REG_FS REG_FS 163 REG_ES, 164 # define REG_ES REG_ES 165 REG_DS, 166 # define REG_DS REG_DS 167 REG_EDI, 168 # define REG_EDI REG_EDI 169 REG_ESI, 170 # define REG_ESI REG_ESI 171 REG_EBP, 172 # define REG_EBP REG_EBP 173 REG_ESP, 174 # define REG_ESP REG_ESP 175 REG_EBX, 176 # define REG_EBX REG_EBX 177 REG_EDX, 178 # define REG_EDX REG_EDX 179 REG_ECX, 180 # define REG_ECX REG_ECX 181 REG_EAX, 182 # define REG_EAX REG_EAX 183 REG_TRAPNO, 184 # define REG_TRAPNO REG_TRAPNO 185 REG_ERR, 186 # define REG_ERR REG_ERR 187 REG_EIP, 188 # define REG_EIP REG_EIP 189 REG_CS, 190 # define REG_CS REG_CS 191 REG_EFL, 192 # define REG_EFL REG_EFL 193 REG_UESP, 194 # define REG_UESP REG_UESP 195 REG_SS 196 # define REG_SS REG_SS 197 }; 198 #endif 199 200 /* Definitions taken from the kernel headers. */ 201 struct _libc_fpreg 202 { 203 unsigned short int significand[4]; 204 unsigned short int exponent; 205 }; 206 207 struct _libc_fpstate 208 { 209 unsigned long int cw; 210 unsigned long int sw; 211 unsigned long int tag; 212 unsigned long int ipoff; 213 unsigned long int cssel; 214 unsigned long int dataoff; 215 unsigned long int datasel; 216 struct _libc_fpreg _st[8]; 217 unsigned long int status; 218 }; 219 220 /* Structure to describe FPU registers. */ 221 typedef struct _libc_fpstate *fpregset_t; 222 223 /* Context to describe whole processor state. */ 224 typedef struct 225 { 226 gregset_t gregs; 227 /* Due to Linux's history we have to use a pointer here. The SysV/i386 228 ABI requires a struct with the values. */ 229 fpregset_t fpregs; 230 unsigned long int oldmask; 231 unsigned long int cr2; 232 } mcontext_t; 233 234 /* Userlevel context. */ 235 typedef struct ucontext 236 { 237 unsigned long int uc_flags; 238 struct ucontext *uc_link; 239 stack_t uc_stack; 240 mcontext_t uc_mcontext; 241 __sigset_t uc_sigmask; 242 struct _libc_fpstate __fpregs_mem; 243 } ucontext_t; 244 245 #endif /* __WORDSIZE == 32 */ 246 247 #endif /* sys/ucontext.h */ 248