blob: 4411e6a8f8e70816b44eb92dd41ac3615582ad8b [file] [log] [blame]
David Howellsaf170c52012-12-14 22:37:13 +00001#ifndef _UAPI_ASM_X86_SIGCONTEXT_H
2#define _UAPI_ASM_X86_SIGCONTEXT_H
3
Ingo Molnarcbf5f4f2015-09-05 09:32:31 +02004/*
5 * Linux signal context definitions. The sigcontext includes a complex hierarchy of CPU
6 * and FPU state, available to user-space (on the stack) when a signal handler is
7 * executed.
8 *
9 * As over the years this ABI grew from its very simple roots towards supporting more and
10 * more CPU state organically, some of the details (which were rather clever hacks back
11 * in the days) became a bit quirky by today.
12 *
13 * The current ABI includes flexible provisions for future extensions, so we won't have
14 * to grow new quirks for quite some time. Promise!
15 */
16
David Howellsaf170c52012-12-14 22:37:13 +000017#include <linux/compiler.h>
18#include <linux/types.h>
19
Ingo Molnarcbf5f4f2015-09-05 09:32:31 +020020#define FP_XSTATE_MAGIC1 0x46505853U
21#define FP_XSTATE_MAGIC2 0x46505845U
22#define FP_XSTATE_MAGIC2_SIZE sizeof(FP_XSTATE_MAGIC2)
David Howellsaf170c52012-12-14 22:37:13 +000023
24/*
Ingo Molnarcbf5f4f2015-09-05 09:32:31 +020025 * Bytes 464..511 in the current 512-byte layout of the FXSAVE/FXRSTOR frame
26 * are reserved for SW usage. On CPUs supporting XSAVE/XRSTOR, these bytes
27 * are used to extend the fpstate pointer in the sigcontext, which now
David Howellsaf170c52012-12-14 22:37:13 +000028 * includes the extended state information along with fpstate information.
29 *
Ingo Molnarcbf5f4f2015-09-05 09:32:31 +020030 * If sw_reserved.magic1 == FP_XSTATE_MAGIC1 then there's a sw_reserved.extended_size
31 * bytes large extended context area present. (The last 32-bit word of this extended
32 * area (at the fpstate+extended_size-FP_XSTATE_MAGIC2_SIZE address) is set to
33 * FP_XSTATE_MAGIC2 so that you can sanity check your size calculations.)
34 *
35 * This extended area typically grows with newer CPUs that have larger and larger
36 * XSAVE areas.
David Howellsaf170c52012-12-14 22:37:13 +000037 */
38struct _fpx_sw_bytes {
Ingo Molnarcbf5f4f2015-09-05 09:32:31 +020039 /* If set to FP_XSTATE_MAGIC1 then this is an xstate context. 0 if a legacy frame. */
40 __u32 magic1;
41
42 /*
43 * Total size of the fpstate area:
44 *
45 * - if magic1 == 0 then it's sizeof(struct _fpstate)
46 * - if magic1 == FP_XSTATE_MAGIC1 then it's sizeof(struct _xstate) plus extensions (if any)
47 */
48 __u32 extended_size;
49
50 /*
51 * Feature bit mask (including FP/SSE/extended state) that is present
52 * in the memory layout:
53 */
54 __u64 xfeatures;
55
56 /*
57 * Actual XSAVE state size, based on the xfeatures saved in the layout.
58 * 'extended_size' is greater than 'xstate_size':
59 */
60 __u32 xstate_size;
61
62 /* For future use: */
63 __u32 padding[7];
David Howellsaf170c52012-12-14 22:37:13 +000064};
65
David Howellsaf170c52012-12-14 22:37:13 +000066/*
Ingo Molnarcbf5f4f2015-09-05 09:32:31 +020067 * As documented in the iBCS2 standard:
David Howellsaf170c52012-12-14 22:37:13 +000068 *
69 * The first part of "struct _fpstate" is just the normal i387
70 * hardware setup, the extra "status" word is used to save the
71 * coprocessor status word before entering the handler.
72 *
David Howellsaf170c52012-12-14 22:37:13 +000073 * The FPU state data structure has had to grow to accommodate the
74 * extended FPU state required by the Streaming SIMD Extensions.
75 * There is no documented standard to accomplish this at the moment.
76 */
Ingo Molnarcbf5f4f2015-09-05 09:32:31 +020077
78/* 10-byte legacy floating point register: */
David Howellsaf170c52012-12-14 22:37:13 +000079struct _fpreg {
Ingo Molnar3f623a52015-09-05 09:32:33 +020080 __u16 significand[4];
81 __u16 exponent;
David Howellsaf170c52012-12-14 22:37:13 +000082};
83
Ingo Molnarcbf5f4f2015-09-05 09:32:31 +020084/* 16-byte floating point register: */
David Howellsaf170c52012-12-14 22:37:13 +000085struct _fpxreg {
Ingo Molnar3f623a52015-09-05 09:32:33 +020086 __u16 significand[4];
87 __u16 exponent;
88 __u16 padding[3];
David Howellsaf170c52012-12-14 22:37:13 +000089};
90
Ingo Molnarcbf5f4f2015-09-05 09:32:31 +020091/* 16-byte XMM register: */
David Howellsaf170c52012-12-14 22:37:13 +000092struct _xmmreg {
Ingo Molnar3f623a52015-09-05 09:32:33 +020093 __u32 element[4];
David Howellsaf170c52012-12-14 22:37:13 +000094};
95
Ingo Molnarcbf5f4f2015-09-05 09:32:31 +020096#define X86_FXSR_MAGIC 0x0000
97
Ingo Molnar7bb0dc22015-09-05 09:32:35 +020098/*
99 * The 32-bit FPU frame:
100 */
101struct _fpstate_32 {
Ingo Molnarcbf5f4f2015-09-05 09:32:31 +0200102 /* Legacy FPU environment: */
Ingo Molnar3f623a52015-09-05 09:32:33 +0200103 __u32 cw;
104 __u32 sw;
105 __u32 tag;
106 __u32 ipoff;
107 __u32 cssel;
108 __u32 dataoff;
109 __u32 datasel;
Ingo Molnarcbf5f4f2015-09-05 09:32:31 +0200110 struct _fpreg _st[8];
Ingo Molnar3f623a52015-09-05 09:32:33 +0200111 __u16 status;
112 __u16 magic; /* 0xffff: regular FPU data only */
Ingo Molnarcbf5f4f2015-09-05 09:32:31 +0200113 /* 0x0000: FXSR FPU data */
David Howellsaf170c52012-12-14 22:37:13 +0000114
115 /* FXSR FPU environment */
Ingo Molnar3f623a52015-09-05 09:32:33 +0200116 __u32 _fxsr_env[6]; /* FXSR FPU env is ignored */
117 __u32 mxcsr;
118 __u32 reserved;
Ingo Molnarcbf5f4f2015-09-05 09:32:31 +0200119 struct _fpxreg _fxsr_st[8]; /* FXSR FPU reg data is ignored */
120 struct _xmmreg _xmm[8]; /* First 8 XMM registers */
Ingo Molnar7bb0dc22015-09-05 09:32:35 +0200121 union {
122 __u32 padding1[44]; /* Second 8 XMM registers plus padding */
123 __u32 padding[44]; /* Alias name for old user-space */
124 };
David Howellsaf170c52012-12-14 22:37:13 +0000125
126 union {
Ingo Molnar3f623a52015-09-05 09:32:33 +0200127 __u32 padding2[12];
Ingo Molnarcbf5f4f2015-09-05 09:32:31 +0200128 struct _fpx_sw_bytes sw_reserved; /* Potential extended state is encoded here */
David Howellsaf170c52012-12-14 22:37:13 +0000129 };
130};
131
Ingo Molnarcbf5f4f2015-09-05 09:32:31 +0200132/*
Ingo Molnar7bb0dc22015-09-05 09:32:35 +0200133 * The 64-bit FPU frame. (FXSAVE format and later)
Ingo Molnarcbf5f4f2015-09-05 09:32:31 +0200134 *
135 * Note1: If sw_reserved.magic1 == FP_XSTATE_MAGIC1 then the structure is
136 * larger: 'struct _xstate'. Note that 'struct _xstate' embedds
137 * 'struct _fpstate' so that you can always assume the _fpstate portion
138 * exists so that you can check the magic value.
139 *
140 * Note2: Reserved fields may someday contain valuable data. Always save/restore
141 * them when you change signal frames.
142 */
Ingo Molnar7bb0dc22015-09-05 09:32:35 +0200143struct _fpstate_64 {
Ingo Molnarcbf5f4f2015-09-05 09:32:31 +0200144 __u16 cwd;
145 __u16 swd;
146 /* Note this is not the same as the 32-bit/x87/FSAVE twd: */
147 __u16 twd;
148 __u16 fop;
149 __u64 rip;
150 __u64 rdp;
151 __u32 mxcsr;
152 __u32 mxcsr_mask;
153 __u32 st_space[32]; /* 8x FP registers, 16 bytes each */
154 __u32 xmm_space[64]; /* 16x XMM registers, 16 bytes each */
155 __u32 reserved2[12];
David Howellsaf170c52012-12-14 22:37:13 +0000156 union {
Ingo Molnarcbf5f4f2015-09-05 09:32:31 +0200157 __u32 reserved3[12];
158 struct _fpx_sw_bytes sw_reserved; /* Potential extended state is encoded here */
David Howellsaf170c52012-12-14 22:37:13 +0000159 };
160};
161
Ingo Molnar7bb0dc22015-09-05 09:32:35 +0200162#ifdef __i386__
163# define _fpstate _fpstate_32
164#else
165# define _fpstate _fpstate_64
166#endif
167
Ingo Molnar128f8252015-09-05 09:32:32 +0200168struct _header {
169 __u64 xfeatures;
170 __u64 reserved1[2];
171 __u64 reserved2[5];
172};
173
174struct _ymmh_state {
175 /* 16x YMM registers, 16 bytes each: */
176 __u32 ymmh_space[64];
177};
178
David Howellsaf170c52012-12-14 22:37:13 +0000179/*
Ingo Molnar128f8252015-09-05 09:32:32 +0200180 * Extended state pointed to by sigcontext::fpstate.
181 *
182 * In addition to the fpstate, information encoded in _xstate::xstate_hdr
183 * indicates the presence of other extended state information supported
184 * by the CPU and kernel:
David Howellsaf170c52012-12-14 22:37:13 +0000185 */
Ingo Molnar128f8252015-09-05 09:32:32 +0200186struct _xstate {
187 struct _fpstate fpstate;
188 struct _header xstate_hdr;
189 struct _ymmh_state ymmh;
190 /* New processor state extensions go here: */
191};
192
Ingo Molnar8fcb3462015-09-05 09:32:41 +0200193/*
194 * The 32-bit signal frame:
195 */
Ingo Molnarf2c609b2015-09-05 09:32:38 +0200196struct sigcontext_32 {
197 __u16 gs, __gsh;
198 __u16 fs, __fsh;
199 __u16 es, __esh;
200 __u16 ds, __dsh;
201 __u32 di;
202 __u32 si;
203 __u32 bp;
204 __u32 sp;
205 __u32 bx;
206 __u32 dx;
207 __u32 cx;
208 __u32 ax;
209 __u32 trapno;
210 __u32 err;
211 __u32 ip;
212 __u16 cs, __csh;
213 __u32 flags;
214 __u32 sp_at_signal;
215 __u16 ss, __ssh;
216
217 /*
218 * fpstate is really (struct _fpstate *) or (struct _xstate *)
219 * depending on the FP_XSTATE_MAGIC1 encoded in the SW reserved
220 * bytes of (struct _fpstate) and FP_XSTATE_MAGIC2 present at the end
221 * of extended memory layout. See comments at the definition of
222 * (struct _fpx_sw_bytes)
223 */
Ingo Molnar530e5c82015-09-05 09:32:39 +0200224 __u32 fpstate; /* Zero when no FPU/extended context */
Ingo Molnarf2c609b2015-09-05 09:32:38 +0200225 __u32 oldmask;
226 __u32 cr2;
227};
228
Ingo Molnar8fcb3462015-09-05 09:32:41 +0200229/*
230 * The 64-bit signal frame:
231 */
Ingo Molnarf2c609b2015-09-05 09:32:38 +0200232struct sigcontext_64 {
233 __u64 r8;
234 __u64 r9;
235 __u64 r10;
236 __u64 r11;
237 __u64 r12;
238 __u64 r13;
239 __u64 r14;
240 __u64 r15;
241 __u64 di;
242 __u64 si;
243 __u64 bp;
244 __u64 bx;
245 __u64 dx;
246 __u64 ax;
247 __u64 cx;
248 __u64 sp;
249 __u64 ip;
250 __u64 flags;
251 __u16 cs;
252 __u16 gs;
253 __u16 fs;
254 __u16 __pad0;
255 __u64 err;
256 __u64 trapno;
257 __u64 oldmask;
258 __u64 cr2;
259
260 /*
261 * fpstate is really (struct _fpstate *) or (struct _xstate *)
262 * depending on the FP_XSTATE_MAGIC1 encoded in the SW reserved
263 * bytes of (struct _fpstate) and FP_XSTATE_MAGIC2 present at the end
264 * of extended memory layout. See comments at the definition of
265 * (struct _fpx_sw_bytes)
266 */
Ingo Molnar530e5c82015-09-05 09:32:39 +0200267 __u64 fpstate; /* Zero when no FPU/extended context */
Ingo Molnarf2c609b2015-09-05 09:32:38 +0200268 __u64 reserved1[8];
269};
270
271/*
272 * Create the real 'struct sigcontext' type:
273 */
274#ifdef __KERNEL__
275# ifdef __i386__
276# define sigcontext sigcontext_32
277# else
278# define sigcontext sigcontext_64
279# endif
280#endif
281
Ingo Molnar128f8252015-09-05 09:32:32 +0200282/*
283 * The old user-space sigcontext definition, just in case user-space still
284 * relies on it. The kernel definition (in asm/sigcontext.h) has unified
285 * field names but otherwise the same layout.
286 */
287#ifndef __KERNEL__
Ingo Molnar86e9fc32015-09-05 09:32:36 +0200288
Ingo Molnar8fcb3462015-09-05 09:32:41 +0200289#define _fpstate_ia32 _fpstate_32
290#define sigcontext_ia32 sigcontext_32
291
Ingo Molnar86e9fc32015-09-05 09:32:36 +0200292
Ingo Molnar128f8252015-09-05 09:32:32 +0200293# ifdef __i386__
294struct sigcontext {
Ingo Molnar3f623a52015-09-05 09:32:33 +0200295 __u16 gs, __gsh;
296 __u16 fs, __fsh;
297 __u16 es, __esh;
298 __u16 ds, __dsh;
299 __u32 edi;
300 __u32 esi;
301 __u32 ebp;
302 __u32 esp;
303 __u32 ebx;
304 __u32 edx;
305 __u32 ecx;
306 __u32 eax;
307 __u32 trapno;
308 __u32 err;
309 __u32 eip;
310 __u16 cs, __csh;
311 __u32 eflags;
312 __u32 esp_at_signal;
313 __u16 ss, __ssh;
Ingo Molnar128f8252015-09-05 09:32:32 +0200314 struct _fpstate __user *fpstate;
Ingo Molnar3f623a52015-09-05 09:32:33 +0200315 __u32 oldmask;
316 __u32 cr2;
Ingo Molnar128f8252015-09-05 09:32:32 +0200317};
318# else /* __x86_64__: */
David Howellsaf170c52012-12-14 22:37:13 +0000319struct sigcontext {
Ingo Molnarcbf5f4f2015-09-05 09:32:31 +0200320 __u64 r8;
321 __u64 r9;
322 __u64 r10;
323 __u64 r11;
324 __u64 r12;
325 __u64 r13;
326 __u64 r14;
327 __u64 r15;
328 __u64 rdi;
329 __u64 rsi;
330 __u64 rbp;
331 __u64 rbx;
332 __u64 rdx;
333 __u64 rax;
334 __u64 rcx;
335 __u64 rsp;
336 __u64 rip;
337 __u64 eflags; /* RFLAGS */
338 __u16 cs;
339 __u16 gs;
340 __u16 fs;
341 __u16 __pad0;
342 __u64 err;
343 __u64 trapno;
344 __u64 oldmask;
345 __u64 cr2;
346 struct _fpstate __user *fpstate; /* Zero when no FPU context */
347# ifdef __ILP32__
348 __u32 __fpstate_pad;
349# endif
350 __u64 reserved1[8];
David Howellsaf170c52012-12-14 22:37:13 +0000351};
Ingo Molnar128f8252015-09-05 09:32:32 +0200352# endif /* __x86_64__ */
353#endif /* !__KERNEL__ */
David Howellsaf170c52012-12-14 22:37:13 +0000354
355#endif /* _UAPI_ASM_X86_SIGCONTEXT_H */