Path: blob/master/arch/x86/include/uapi/asm/sigcontext.h
26495 views
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */1#ifndef _UAPI_ASM_X86_SIGCONTEXT_H2#define _UAPI_ASM_X86_SIGCONTEXT_H34/*5* Linux signal context definitions. The sigcontext includes a complex6* hierarchy of CPU and FPU state, available to user-space (on the stack) when7* a signal handler is executed.8*9* As over the years this ABI grew from its very simple roots towards10* supporting more and more CPU state organically, some of the details (which11* were rather clever hacks back in the days) became a bit quirky by today.12*13* The current ABI includes flexible provisions for future extensions, so we14* won't have to grow new quirks for quite some time. Promise!15*/1617#include <linux/compiler.h>18#include <linux/types.h>1920#define FP_XSTATE_MAGIC1 0x46505853U21#define FP_XSTATE_MAGIC2 0x46505845U22#define FP_XSTATE_MAGIC2_SIZE sizeof(FP_XSTATE_MAGIC2)2324/*25* Bytes 464..511 in the current 512-byte layout of the FXSAVE/FXRSTOR frame26* are reserved for SW usage. On CPUs supporting XSAVE/XRSTOR, these bytes are27* used to extend the fpstate pointer in the sigcontext, which now includes the28* extended state information along with fpstate information.29*30* If sw_reserved.magic1 == FP_XSTATE_MAGIC1 then there's a31* sw_reserved.extended_size bytes large extended context area present. (The32* last 32-bit word of this extended area (at the33* fpstate+extended_size-FP_XSTATE_MAGIC2_SIZE address) is set to34* FP_XSTATE_MAGIC2 so that you can sanity check your size calculations.)35*36* This extended area typically grows with newer CPUs that have larger and37* larger XSAVE areas.38*/39struct _fpx_sw_bytes {40/*41* If set to FP_XSTATE_MAGIC1 then this is an xstate context.42* 0 if a legacy frame.43*/44__u32 magic1;4546/*47* Total size of the fpstate area:48*49* - if magic1 == 0 then it's sizeof(struct _fpstate)50* - if magic1 == FP_XSTATE_MAGIC1 then it's sizeof(struct _xstate)51* plus extensions (if any)52*/53__u32 extended_size;5455/*56* Feature bit mask (including FP/SSE/extended state) that is present57* in the memory layout:58*/59__u64 xfeatures;6061/*62* Actual XSAVE state size, based on the xfeatures saved in the layout.63* 'extended_size' is greater than 'xstate_size':64*/65__u32 xstate_size;6667/* For future use: */68__u32 padding[7];69};7071/*72* As documented in the iBCS2 standard:73*74* The first part of "struct _fpstate" is just the normal i387 hardware setup,75* the extra "status" word is used to save the coprocessor status word before76* entering the handler.77*78* The FPU state data structure has had to grow to accommodate the extended FPU79* state required by the Streaming SIMD Extensions. There is no documented80* standard to accomplish this at the moment.81*/8283/* 10-byte legacy floating point register: */84struct _fpreg {85__u16 significand[4];86__u16 exponent;87};8889/* 16-byte floating point register: */90struct _fpxreg {91__u16 significand[4];92__u16 exponent;93__u16 padding[3];94};9596/* 16-byte XMM register: */97struct _xmmreg {98__u32 element[4];99};100101#define X86_FXSR_MAGIC 0x0000102103/*104* The 32-bit FPU frame:105*/106struct _fpstate_32 {107/* Legacy FPU environment: */108__u32 cw;109__u32 sw;110__u32 tag;111__u32 ipoff;112__u32 cssel;113__u32 dataoff;114__u32 datasel;115struct _fpreg _st[8];116__u16 status;117__u16 magic; /* 0xffff: regular FPU data only */118/* 0x0000: FXSR FPU data */119120/* FXSR FPU environment */121__u32 _fxsr_env[6]; /* FXSR FPU env is ignored */122__u32 mxcsr;123__u32 reserved;124struct _fpxreg _fxsr_st[8]; /* FXSR FPU reg data is ignored */125struct _xmmreg _xmm[8]; /* First 8 XMM registers */126union {127__u32 padding1[44]; /* Second 8 XMM registers plus padding */128__u32 padding[44]; /* Alias name for old user-space */129};130131union {132__u32 padding2[12];133struct _fpx_sw_bytes sw_reserved; /* Potential extended state is encoded here */134};135};136137/*138* The 64-bit FPU frame. (FXSAVE format and later)139*140* Note1: If sw_reserved.magic1 == FP_XSTATE_MAGIC1 then the structure is141* larger: 'struct _xstate'. Note that 'struct _xstate' embeds142* 'struct _fpstate' so that you can always assume the _fpstate portion143* exists so that you can check the magic value.144*145* Note2: Reserved fields may someday contain valuable data. Always146* save/restore them when you change signal frames.147*/148struct _fpstate_64 {149__u16 cwd;150__u16 swd;151/* Note this is not the same as the 32-bit/x87/FSAVE twd: */152__u16 twd;153__u16 fop;154__u64 rip;155__u64 rdp;156__u32 mxcsr;157__u32 mxcsr_mask;158__u32 st_space[32]; /* 8x FP registers, 16 bytes each */159__u32 xmm_space[64]; /* 16x XMM registers, 16 bytes each */160__u32 reserved2[12];161union {162__u32 reserved3[12];163struct _fpx_sw_bytes sw_reserved; /* Potential extended state is encoded here */164};165};166167#ifdef __i386__168# define _fpstate _fpstate_32169#else170# define _fpstate _fpstate_64171#endif172173struct _header {174__u64 xfeatures;175__u64 reserved1[2];176__u64 reserved2[5];177};178179struct _ymmh_state {180/* 16x YMM registers, 16 bytes each: */181__u32 ymmh_space[64];182};183184/*185* Extended state pointed to by sigcontext::fpstate.186*187* In addition to the fpstate, information encoded in _xstate::xstate_hdr188* indicates the presence of other extended state information supported189* by the CPU and kernel:190*/191struct _xstate {192struct _fpstate fpstate;193struct _header xstate_hdr;194struct _ymmh_state ymmh;195/* New processor state extensions go here: */196};197198/*199* The 32-bit signal frame:200*/201struct sigcontext_32 {202__u16 gs, __gsh;203__u16 fs, __fsh;204__u16 es, __esh;205__u16 ds, __dsh;206__u32 di;207__u32 si;208__u32 bp;209__u32 sp;210__u32 bx;211__u32 dx;212__u32 cx;213__u32 ax;214__u32 trapno;215__u32 err;216__u32 ip;217__u16 cs, __csh;218__u32 flags;219__u32 sp_at_signal;220__u16 ss, __ssh;221222/*223* fpstate is really (struct _fpstate *) or (struct _xstate *)224* depending on the FP_XSTATE_MAGIC1 encoded in the SW reserved225* bytes of (struct _fpstate) and FP_XSTATE_MAGIC2 present at the end226* of extended memory layout. See comments at the definition of227* (struct _fpx_sw_bytes)228*/229__u32 fpstate; /* Zero when no FPU/extended context */230__u32 oldmask;231__u32 cr2;232};233234/*235* The 64-bit signal frame:236*/237struct sigcontext_64 {238__u64 r8;239__u64 r9;240__u64 r10;241__u64 r11;242__u64 r12;243__u64 r13;244__u64 r14;245__u64 r15;246__u64 di;247__u64 si;248__u64 bp;249__u64 bx;250__u64 dx;251__u64 ax;252__u64 cx;253__u64 sp;254__u64 ip;255__u64 flags;256__u16 cs;257__u16 gs;258__u16 fs;259__u16 ss;260__u64 err;261__u64 trapno;262__u64 oldmask;263__u64 cr2;264265/*266* fpstate is really (struct _fpstate *) or (struct _xstate *)267* depending on the FP_XSTATE_MAGIC1 encoded in the SW reserved268* bytes of (struct _fpstate) and FP_XSTATE_MAGIC2 present at the end269* of extended memory layout. See comments at the definition of270* (struct _fpx_sw_bytes)271*/272__u64 fpstate; /* Zero when no FPU/extended context */273__u64 reserved1[8];274};275276/*277* Create the real 'struct sigcontext' type:278*/279#ifdef __KERNEL__280# ifdef __i386__281# define sigcontext sigcontext_32282# else283# define sigcontext sigcontext_64284# endif285#endif286287/*288* The old user-space sigcontext definition, just in case user-space still289* relies on it. The kernel definition (in asm/sigcontext.h) has unified290* field names but otherwise the same layout.291*/292#ifndef __KERNEL__293294#define _fpstate_ia32 _fpstate_32295#define sigcontext_ia32 sigcontext_32296297298# ifdef __i386__299struct sigcontext {300__u16 gs, __gsh;301__u16 fs, __fsh;302__u16 es, __esh;303__u16 ds, __dsh;304__u32 edi;305__u32 esi;306__u32 ebp;307__u32 esp;308__u32 ebx;309__u32 edx;310__u32 ecx;311__u32 eax;312__u32 trapno;313__u32 err;314__u32 eip;315__u16 cs, __csh;316__u32 eflags;317__u32 esp_at_signal;318__u16 ss, __ssh;319struct _fpstate __user *fpstate;320__u32 oldmask;321__u32 cr2;322};323# else /* __x86_64__: */324struct sigcontext {325__u64 r8;326__u64 r9;327__u64 r10;328__u64 r11;329__u64 r12;330__u64 r13;331__u64 r14;332__u64 r15;333__u64 rdi;334__u64 rsi;335__u64 rbp;336__u64 rbx;337__u64 rdx;338__u64 rax;339__u64 rcx;340__u64 rsp;341__u64 rip;342__u64 eflags; /* RFLAGS */343__u16 cs;344345/*346* Prior to 2.5.64 ("[PATCH] x86-64 updates for 2.5.64-bk3"),347* Linux saved and restored fs and gs in these slots. This348* was counterproductive, as fsbase and gsbase were never349* saved, so arch_prctl was presumably unreliable.350*351* These slots should never be reused without extreme caution:352*353* - Some DOSEMU versions stash fs and gs in these slots manually,354* thus overwriting anything the kernel expects to be preserved355* in these slots.356*357* - If these slots are ever needed for any other purpose,358* there is some risk that very old 64-bit binaries could get359* confused. I doubt that many such binaries still work,360* though, since the same patch in 2.5.64 also removed the361* 64-bit set_thread_area syscall, so it appears that there362* is no TLS API beyond modify_ldt that works in both pre-363* and post-2.5.64 kernels.364*365* If the kernel ever adds explicit fs, gs, fsbase, and gsbase366* save/restore, it will most likely need to be opt-in and use367* different context slots.368*/369__u16 gs;370__u16 fs;371union {372__u16 ss; /* If UC_SIGCONTEXT_SS */373__u16 __pad0; /* Alias name for old (!UC_SIGCONTEXT_SS) user-space */374};375__u64 err;376__u64 trapno;377__u64 oldmask;378__u64 cr2;379struct _fpstate __user *fpstate; /* Zero when no FPU context */380# ifdef __ILP32__381__u32 __fpstate_pad;382# endif383__u64 reserved1[8];384};385# endif /* __x86_64__ */386#endif /* !__KERNEL__ */387388#endif /* _UAPI_ASM_X86_SIGCONTEXT_H */389390391