1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 #ifndef _UAPI_ASM_X86_SIGCONTEXT_H
3 #define _UAPI_ASM_X86_SIGCONTEXT_H
6 * Linux signal context definitions. The sigcontext includes a complex
7 * hierarchy of CPU and FPU state, available to user-space (on the stack) when
8 * a signal handler is executed.
10 * As over the years this ABI grew from its very simple roots towards
11 * supporting more and more CPU state organically, some of the details (which
12 * were rather clever hacks back in the days) became a bit quirky by today.
14 * The current ABI includes flexible provisions for future extensions, so we
15 * won't have to grow new quirks for quite some time. Promise!
18 #include <linux/compiler.h>
19 #include <linux/types.h>
21 #define FP_XSTATE_MAGIC1 0x46505853U
22 #define FP_XSTATE_MAGIC2 0x46505845U
23 #define FP_XSTATE_MAGIC2_SIZE sizeof(FP_XSTATE_MAGIC2)
26 * Bytes 464..511 in the current 512-byte layout of the FXSAVE/FXRSTOR frame
27 * are reserved for SW usage. On CPUs supporting XSAVE/XRSTOR, these bytes are
28 * used to extend the fpstate pointer in the sigcontext, which now includes the
29 * extended state information along with fpstate information.
31 * If sw_reserved.magic1 == FP_XSTATE_MAGIC1 then there's a
32 * sw_reserved.extended_size bytes large extended context area present. (The
33 * last 32-bit word of this extended area (at the
34 * fpstate+extended_size-FP_XSTATE_MAGIC2_SIZE address) is set to
35 * FP_XSTATE_MAGIC2 so that you can sanity check your size calculations.)
37 * This extended area typically grows with newer CPUs that have larger and
40 struct _fpx_sw_bytes
{
42 * If set to FP_XSTATE_MAGIC1 then this is an xstate context.
43 * 0 if a legacy frame.
48 * Total size of the fpstate area:
50 * - if magic1 == 0 then it's sizeof(struct _fpstate)
51 * - if magic1 == FP_XSTATE_MAGIC1 then it's sizeof(struct _xstate)
52 * plus extensions (if any)
57 * Feature bit mask (including FP/SSE/extended state) that is present
58 * in the memory layout:
63 * Actual XSAVE state size, based on the xfeatures saved in the layout.
64 * 'extended_size' is greater than 'xstate_size':
73 * As documented in the iBCS2 standard:
75 * The first part of "struct _fpstate" is just the normal i387 hardware setup,
76 * the extra "status" word is used to save the coprocessor status word before
77 * entering the handler.
79 * The FPU state data structure has had to grow to accommodate the extended FPU
80 * state required by the Streaming SIMD Extensions. There is no documented
81 * standard to accomplish this at the moment.
84 /* 10-byte legacy floating point register: */
90 /* 16-byte floating point register: */
97 /* 16-byte XMM register: */
102 #define X86_FXSR_MAGIC 0x0000
105 * The 32-bit FPU frame:
108 /* Legacy FPU environment: */
116 struct _fpreg _st
[8];
118 __u16 magic
; /* 0xffff: regular FPU data only */
119 /* 0x0000: FXSR FPU data */
121 /* FXSR FPU environment */
122 __u32 _fxsr_env
[6]; /* FXSR FPU env is ignored */
125 struct _fpxreg _fxsr_st
[8]; /* FXSR FPU reg data is ignored */
126 struct _xmmreg _xmm
[8]; /* First 8 XMM registers */
128 __u32 padding1
[44]; /* Second 8 XMM registers plus padding */
129 __u32 padding
[44]; /* Alias name for old user-space */
134 struct _fpx_sw_bytes sw_reserved
; /* Potential extended state is encoded here */
139 * The 64-bit FPU frame. (FXSAVE format and later)
141 * Note1: If sw_reserved.magic1 == FP_XSTATE_MAGIC1 then the structure is
142 * larger: 'struct _xstate'. Note that 'struct _xstate' embeds
143 * 'struct _fpstate' so that you can always assume the _fpstate portion
144 * exists so that you can check the magic value.
146 * Note2: Reserved fields may someday contain valuable data. Always
147 * save/restore them when you change signal frames.
152 /* Note this is not the same as the 32-bit/x87/FSAVE twd: */
159 __u32 st_space
[32]; /* 8x FP registers, 16 bytes each */
160 __u32 xmm_space
[64]; /* 16x XMM registers, 16 bytes each */
164 struct _fpx_sw_bytes sw_reserved
; /* Potential extended state is encoded here */
169 # define _fpstate _fpstate_32
171 # define _fpstate _fpstate_64
181 /* 16x YMM registers, 16 bytes each: */
182 __u32 ymmh_space
[64];
186 * Extended state pointed to by sigcontext::fpstate.
188 * In addition to the fpstate, information encoded in _xstate::xstate_hdr
189 * indicates the presence of other extended state information supported
190 * by the CPU and kernel:
193 struct _fpstate fpstate
;
194 struct _header xstate_hdr
;
195 struct _ymmh_state ymmh
;
196 /* New processor state extensions go here: */
200 * The 32-bit signal frame:
202 struct sigcontext_32
{
224 * fpstate is really (struct _fpstate *) or (struct _xstate *)
225 * depending on the FP_XSTATE_MAGIC1 encoded in the SW reserved
226 * bytes of (struct _fpstate) and FP_XSTATE_MAGIC2 present at the end
227 * of extended memory layout. See comments at the definition of
228 * (struct _fpx_sw_bytes)
230 __u32 fpstate
; /* Zero when no FPU/extended context */
236 * The 64-bit signal frame:
238 struct sigcontext_64
{
267 * fpstate is really (struct _fpstate *) or (struct _xstate *)
268 * depending on the FP_XSTATE_MAGIC1 encoded in the SW reserved
269 * bytes of (struct _fpstate) and FP_XSTATE_MAGIC2 present at the end
270 * of extended memory layout. See comments at the definition of
271 * (struct _fpx_sw_bytes)
273 __u64 fpstate
; /* Zero when no FPU/extended context */
278 * Create the real 'struct sigcontext' type:
282 # define sigcontext sigcontext_32
284 # define sigcontext sigcontext_64
289 * The old user-space sigcontext definition, just in case user-space still
290 * relies on it. The kernel definition (in asm/sigcontext.h) has unified
291 * field names but otherwise the same layout.
295 #define _fpstate_ia32 _fpstate_32
296 #define sigcontext_ia32 sigcontext_32
320 struct _fpstate __user
*fpstate
;
324 # else /* __x86_64__: */
343 __u64 eflags
; /* RFLAGS */
347 * Prior to 2.5.64 ("[PATCH] x86-64 updates for 2.5.64-bk3"),
348 * Linux saved and restored fs and gs in these slots. This
349 * was counterproductive, as fsbase and gsbase were never
350 * saved, so arch_prctl was presumably unreliable.
352 * These slots should never be reused without extreme caution:
354 * - Some DOSEMU versions stash fs and gs in these slots manually,
355 * thus overwriting anything the kernel expects to be preserved
358 * - If these slots are ever needed for any other purpose,
359 * there is some risk that very old 64-bit binaries could get
360 * confused. I doubt that many such binaries still work,
361 * though, since the same patch in 2.5.64 also removed the
362 * 64-bit set_thread_area syscall, so it appears that there
363 * is no TLS API beyond modify_ldt that works in both pre-
364 * and post-2.5.64 kernels.
366 * If the kernel ever adds explicit fs, gs, fsbase, and gsbase
367 * save/restore, it will most likely need to be opt-in and use
368 * different context slots.
373 __u16 ss
; /* If UC_SIGCONTEXT_SS */
374 __u16 __pad0
; /* Alias name for old (!UC_SIGCONTEXT_SS) user-space */
380 struct _fpstate __user
*fpstate
; /* Zero when no FPU context */
386 # endif /* __x86_64__ */
387 #endif /* !__KERNEL__ */
389 #endif /* _UAPI_ASM_X86_SIGCONTEXT_H */