![]() |
|
|||
0001 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 0002 #ifndef _UAPI_ASM_X86_SIGCONTEXT_H 0003 #define _UAPI_ASM_X86_SIGCONTEXT_H 0004 0005 /* 0006 * Linux signal context definitions. The sigcontext includes a complex 0007 * hierarchy of CPU and FPU state, available to user-space (on the stack) when 0008 * a signal handler is executed. 0009 * 0010 * As over the years this ABI grew from its very simple roots towards 0011 * supporting more and more CPU state organically, some of the details (which 0012 * were rather clever hacks back in the days) became a bit quirky by today. 0013 * 0014 * The current ABI includes flexible provisions for future extensions, so we 0015 * won't have to grow new quirks for quite some time. Promise! 0016 */ 0017 0018 #include <linux/compiler.h> 0019 #include <linux/types.h> 0020 0021 #define FP_XSTATE_MAGIC1 0x46505853U 0022 #define FP_XSTATE_MAGIC2 0x46505845U 0023 #define FP_XSTATE_MAGIC2_SIZE sizeof(FP_XSTATE_MAGIC2) 0024 0025 /* 0026 * Bytes 464..511 in the current 512-byte layout of the FXSAVE/FXRSTOR frame 0027 * are reserved for SW usage. On CPUs supporting XSAVE/XRSTOR, these bytes are 0028 * used to extend the fpstate pointer in the sigcontext, which now includes the 0029 * extended state information along with fpstate information. 0030 * 0031 * If sw_reserved.magic1 == FP_XSTATE_MAGIC1 then there's a 0032 * sw_reserved.extended_size bytes large extended context area present. (The 0033 * last 32-bit word of this extended area (at the 0034 * fpstate+extended_size-FP_XSTATE_MAGIC2_SIZE address) is set to 0035 * FP_XSTATE_MAGIC2 so that you can sanity check your size calculations.) 0036 * 0037 * This extended area typically grows with newer CPUs that have larger and 0038 * larger XSAVE areas. 0039 */ 0040 struct _fpx_sw_bytes { 0041 /* 0042 * If set to FP_XSTATE_MAGIC1 then this is an xstate context. 0043 * 0 if a legacy frame. 0044 */ 0045 __u32 magic1; 0046 0047 /* 0048 * Total size of the fpstate area: 0049 * 0050 * - if magic1 == 0 then it's sizeof(struct _fpstate) 0051 * - if magic1 == FP_XSTATE_MAGIC1 then it's sizeof(struct _xstate) 0052 * plus extensions (if any) 0053 */ 0054 __u32 extended_size; 0055 0056 /* 0057 * Feature bit mask (including FP/SSE/extended state) that is present 0058 * in the memory layout: 0059 */ 0060 __u64 xfeatures; 0061 0062 /* 0063 * Actual XSAVE state size, based on the xfeatures saved in the layout. 0064 * 'extended_size' is greater than 'xstate_size': 0065 */ 0066 __u32 xstate_size; 0067 0068 /* For future use: */ 0069 __u32 padding[7]; 0070 }; 0071 0072 /* 0073 * As documented in the iBCS2 standard: 0074 * 0075 * The first part of "struct _fpstate" is just the normal i387 hardware setup, 0076 * the extra "status" word is used to save the coprocessor status word before 0077 * entering the handler. 0078 * 0079 * The FPU state data structure has had to grow to accommodate the extended FPU 0080 * state required by the Streaming SIMD Extensions. There is no documented 0081 * standard to accomplish this at the moment. 0082 */ 0083 0084 /* 10-byte legacy floating point register: */ 0085 struct _fpreg { 0086 __u16 significand[4]; 0087 __u16 exponent; 0088 }; 0089 0090 /* 16-byte floating point register: */ 0091 struct _fpxreg { 0092 __u16 significand[4]; 0093 __u16 exponent; 0094 __u16 padding[3]; 0095 }; 0096 0097 /* 16-byte XMM register: */ 0098 struct _xmmreg { 0099 __u32 element[4]; 0100 }; 0101 0102 #define X86_FXSR_MAGIC 0x0000 0103 0104 /* 0105 * The 32-bit FPU frame: 0106 */ 0107 struct _fpstate_32 { 0108 /* Legacy FPU environment: */ 0109 __u32 cw; 0110 __u32 sw; 0111 __u32 tag; 0112 __u32 ipoff; 0113 __u32 cssel; 0114 __u32 dataoff; 0115 __u32 datasel; 0116 struct _fpreg _st[8]; 0117 __u16 status; 0118 __u16 magic; /* 0xffff: regular FPU data only */ 0119 /* 0x0000: FXSR FPU data */ 0120 0121 /* FXSR FPU environment */ 0122 __u32 _fxsr_env[6]; /* FXSR FPU env is ignored */ 0123 __u32 mxcsr; 0124 __u32 reserved; 0125 struct _fpxreg _fxsr_st[8]; /* FXSR FPU reg data is ignored */ 0126 struct _xmmreg _xmm[8]; /* First 8 XMM registers */ 0127 union { 0128 __u32 padding1[44]; /* Second 8 XMM registers plus padding */ 0129 __u32 padding[44]; /* Alias name for old user-space */ 0130 }; 0131 0132 union { 0133 __u32 padding2[12]; 0134 struct _fpx_sw_bytes sw_reserved; /* Potential extended state is encoded here */ 0135 }; 0136 }; 0137 0138 /* 0139 * The 64-bit FPU frame. (FXSAVE format and later) 0140 * 0141 * Note1: If sw_reserved.magic1 == FP_XSTATE_MAGIC1 then the structure is 0142 * larger: 'struct _xstate'. Note that 'struct _xstate' embeds 0143 * 'struct _fpstate' so that you can always assume the _fpstate portion 0144 * exists so that you can check the magic value. 0145 * 0146 * Note2: Reserved fields may someday contain valuable data. Always 0147 * save/restore them when you change signal frames. 0148 */ 0149 struct _fpstate_64 { 0150 __u16 cwd; 0151 __u16 swd; 0152 /* Note this is not the same as the 32-bit/x87/FSAVE twd: */ 0153 __u16 twd; 0154 __u16 fop; 0155 __u64 rip; 0156 __u64 rdp; 0157 __u32 mxcsr; 0158 __u32 mxcsr_mask; 0159 __u32 st_space[32]; /* 8x FP registers, 16 bytes each */ 0160 __u32 xmm_space[64]; /* 16x XMM registers, 16 bytes each */ 0161 __u32 reserved2[12]; 0162 union { 0163 __u32 reserved3[12]; 0164 struct _fpx_sw_bytes sw_reserved; /* Potential extended state is encoded here */ 0165 }; 0166 }; 0167 0168 #ifdef __i386__ 0169 # define _fpstate _fpstate_32 0170 #else 0171 # define _fpstate _fpstate_64 0172 #endif 0173 0174 struct _header { 0175 __u64 xfeatures; 0176 __u64 reserved1[2]; 0177 __u64 reserved2[5]; 0178 }; 0179 0180 struct _ymmh_state { 0181 /* 16x YMM registers, 16 bytes each: */ 0182 __u32 ymmh_space[64]; 0183 }; 0184 0185 /* 0186 * Extended state pointed to by sigcontext::fpstate. 0187 * 0188 * In addition to the fpstate, information encoded in _xstate::xstate_hdr 0189 * indicates the presence of other extended state information supported 0190 * by the CPU and kernel: 0191 */ 0192 struct _xstate { 0193 struct _fpstate fpstate; 0194 struct _header xstate_hdr; 0195 struct _ymmh_state ymmh; 0196 /* New processor state extensions go here: */ 0197 }; 0198 0199 /* 0200 * The 32-bit signal frame: 0201 */ 0202 struct sigcontext_32 { 0203 __u16 gs, __gsh; 0204 __u16 fs, __fsh; 0205 __u16 es, __esh; 0206 __u16 ds, __dsh; 0207 __u32 di; 0208 __u32 si; 0209 __u32 bp; 0210 __u32 sp; 0211 __u32 bx; 0212 __u32 dx; 0213 __u32 cx; 0214 __u32 ax; 0215 __u32 trapno; 0216 __u32 err; 0217 __u32 ip; 0218 __u16 cs, __csh; 0219 __u32 flags; 0220 __u32 sp_at_signal; 0221 __u16 ss, __ssh; 0222 0223 /* 0224 * fpstate is really (struct _fpstate *) or (struct _xstate *) 0225 * depending on the FP_XSTATE_MAGIC1 encoded in the SW reserved 0226 * bytes of (struct _fpstate) and FP_XSTATE_MAGIC2 present at the end 0227 * of extended memory layout. See comments at the definition of 0228 * (struct _fpx_sw_bytes) 0229 */ 0230 __u32 fpstate; /* Zero when no FPU/extended context */ 0231 __u32 oldmask; 0232 __u32 cr2; 0233 }; 0234 0235 /* 0236 * The 64-bit signal frame: 0237 */ 0238 struct sigcontext_64 { 0239 __u64 r8; 0240 __u64 r9; 0241 __u64 r10; 0242 __u64 r11; 0243 __u64 r12; 0244 __u64 r13; 0245 __u64 r14; 0246 __u64 r15; 0247 __u64 di; 0248 __u64 si; 0249 __u64 bp; 0250 __u64 bx; 0251 __u64 dx; 0252 __u64 ax; 0253 __u64 cx; 0254 __u64 sp; 0255 __u64 ip; 0256 __u64 flags; 0257 __u16 cs; 0258 __u16 gs; 0259 __u16 fs; 0260 __u16 ss; 0261 __u64 err; 0262 __u64 trapno; 0263 __u64 oldmask; 0264 __u64 cr2; 0265 0266 /* 0267 * fpstate is really (struct _fpstate *) or (struct _xstate *) 0268 * depending on the FP_XSTATE_MAGIC1 encoded in the SW reserved 0269 * bytes of (struct _fpstate) and FP_XSTATE_MAGIC2 present at the end 0270 * of extended memory layout. See comments at the definition of 0271 * (struct _fpx_sw_bytes) 0272 */ 0273 __u64 fpstate; /* Zero when no FPU/extended context */ 0274 __u64 reserved1[8]; 0275 }; 0276 0277 /* 0278 * Create the real 'struct sigcontext' type: 0279 */ 0280 #ifdef __KERNEL__ 0281 # ifdef __i386__ 0282 # define sigcontext sigcontext_32 0283 # else 0284 # define sigcontext sigcontext_64 0285 # endif 0286 #endif 0287 0288 /* 0289 * The old user-space sigcontext definition, just in case user-space still 0290 * relies on it. The kernel definition (in asm/sigcontext.h) has unified 0291 * field names but otherwise the same layout. 0292 */ 0293 #ifndef __KERNEL__ 0294 0295 #define _fpstate_ia32 _fpstate_32 0296 #define sigcontext_ia32 sigcontext_32 0297 0298 0299 # ifdef __i386__ 0300 struct sigcontext { 0301 __u16 gs, __gsh; 0302 __u16 fs, __fsh; 0303 __u16 es, __esh; 0304 __u16 ds, __dsh; 0305 __u32 edi; 0306 __u32 esi; 0307 __u32 ebp; 0308 __u32 esp; 0309 __u32 ebx; 0310 __u32 edx; 0311 __u32 ecx; 0312 __u32 eax; 0313 __u32 trapno; 0314 __u32 err; 0315 __u32 eip; 0316 __u16 cs, __csh; 0317 __u32 eflags; 0318 __u32 esp_at_signal; 0319 __u16 ss, __ssh; 0320 struct _fpstate __user *fpstate; 0321 __u32 oldmask; 0322 __u32 cr2; 0323 }; 0324 # else /* __x86_64__: */ 0325 struct sigcontext { 0326 __u64 r8; 0327 __u64 r9; 0328 __u64 r10; 0329 __u64 r11; 0330 __u64 r12; 0331 __u64 r13; 0332 __u64 r14; 0333 __u64 r15; 0334 __u64 rdi; 0335 __u64 rsi; 0336 __u64 rbp; 0337 __u64 rbx; 0338 __u64 rdx; 0339 __u64 rax; 0340 __u64 rcx; 0341 __u64 rsp; 0342 __u64 rip; 0343 __u64 eflags; /* RFLAGS */ 0344 __u16 cs; 0345 0346 /* 0347 * Prior to 2.5.64 ("[PATCH] x86-64 updates for 2.5.64-bk3"), 0348 * Linux saved and restored fs and gs in these slots. This 0349 * was counterproductive, as fsbase and gsbase were never 0350 * saved, so arch_prctl was presumably unreliable. 0351 * 0352 * These slots should never be reused without extreme caution: 0353 * 0354 * - Some DOSEMU versions stash fs and gs in these slots manually, 0355 * thus overwriting anything the kernel expects to be preserved 0356 * in these slots. 0357 * 0358 * - If these slots are ever needed for any other purpose, 0359 * there is some risk that very old 64-bit binaries could get 0360 * confused. I doubt that many such binaries still work, 0361 * though, since the same patch in 2.5.64 also removed the 0362 * 64-bit set_thread_area syscall, so it appears that there 0363 * is no TLS API beyond modify_ldt that works in both pre- 0364 * and post-2.5.64 kernels. 0365 * 0366 * If the kernel ever adds explicit fs, gs, fsbase, and gsbase 0367 * save/restore, it will most likely need to be opt-in and use 0368 * different context slots. 0369 */ 0370 __u16 gs; 0371 __u16 fs; 0372 union { 0373 __u16 ss; /* If UC_SIGCONTEXT_SS */ 0374 __u16 __pad0; /* Alias name for old (!UC_SIGCONTEXT_SS) user-space */ 0375 }; 0376 __u64 err; 0377 __u64 trapno; 0378 __u64 oldmask; 0379 __u64 cr2; 0380 struct _fpstate __user *fpstate; /* Zero when no FPU context */ 0381 # ifdef __ILP32__ 0382 __u32 __fpstate_pad; 0383 # endif 0384 __u64 reserved1[8]; 0385 }; 0386 # endif /* __x86_64__ */ 0387 #endif /* !__KERNEL__ */ 0388 0389 #endif /* _UAPI_ASM_X86_SIGCONTEXT_H */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |