aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Molnar <mingo@kernel.org>2015-09-05 03:32:31 -0400
committerIngo Molnar <mingo@kernel.org>2015-09-08 04:03:55 -0400
commitcbf5f4fbf435e871e59d49653d555266b8796efc (patch)
treed2be6f3c318d41ab05c6975b7c31068eca19bf3b
parentc3f4986fb0774bb13feb4bade1276bed2ba8a3db (diff)
x86/headers: Clean up and better document uapi/asm/sigcontext.h
Clean up sigcontext.h: - the explanations were full of typos and were hard to read in general - use consistent and readable vertical spacing - fix, harmonize and extend comments No field name has been changed, user-space might be relying on them. Acked-by: Mikko Rapeli <mikko.rapeli@iki.fi> Cc: Andy Lutomirski <luto@amacapital.net> Cc: Borislav Petkov <bp@alien8.de> Cc: Brian Gerst <brgerst@gmail.com> Cc: Denys Vlasenko <dvlasenk@redhat.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: linux-kernel@vger.kernel.org Link: http://lkml.kernel.org/r/1441438363-9999-4-git-send-email-mingo@kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r--arch/x86/include/uapi/asm/sigcontext.h330
1 files changed, 182 insertions, 148 deletions
diff --git a/arch/x86/include/uapi/asm/sigcontext.h b/arch/x86/include/uapi/asm/sigcontext.h
index 40836a9a7250..f89b2f1abe7c 100644
--- a/arch/x86/include/uapi/asm/sigcontext.h
+++ b/arch/x86/include/uapi/asm/sigcontext.h
@@ -1,221 +1,255 @@
1#ifndef _UAPI_ASM_X86_SIGCONTEXT_H 1#ifndef _UAPI_ASM_X86_SIGCONTEXT_H
2#define _UAPI_ASM_X86_SIGCONTEXT_H 2#define _UAPI_ASM_X86_SIGCONTEXT_H
3 3
4/*
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
4#include <linux/compiler.h> 17#include <linux/compiler.h>
5#include <linux/types.h> 18#include <linux/types.h>
6 19
7#define FP_XSTATE_MAGIC1 0x46505853U 20#define FP_XSTATE_MAGIC1 0x46505853U
8#define FP_XSTATE_MAGIC2 0x46505845U 21#define FP_XSTATE_MAGIC2 0x46505845U
9#define FP_XSTATE_MAGIC2_SIZE sizeof(FP_XSTATE_MAGIC2) 22#define FP_XSTATE_MAGIC2_SIZE sizeof(FP_XSTATE_MAGIC2)
10 23
11/* 24/*
12 * bytes 464..511 in the current 512byte layout of fxsave/fxrstor frame 25 * Bytes 464..511 in the current 512-byte layout of the FXSAVE/FXRSTOR frame
13 * are reserved for SW usage. On cpu's supporting xsave/xrstor, these bytes 26 * are reserved for SW usage. On CPUs supporting XSAVE/XRSTOR, these bytes
14 * are used to extended the fpstate pointer in the sigcontext, which now 27 * are used to extend the fpstate pointer in the sigcontext, which now
15 * includes the extended state information along with fpstate information. 28 * includes the extended state information along with fpstate information.
16 * 29 *
17 * Presence of FP_XSTATE_MAGIC1 at the beginning of this SW reserved 30 * If sw_reserved.magic1 == FP_XSTATE_MAGIC1 then there's a sw_reserved.extended_size
18 * area and FP_XSTATE_MAGIC2 at the end of memory layout 31 * bytes large extended context area present. (The last 32-bit word of this extended
19 * (extended_size - FP_XSTATE_MAGIC2_SIZE) indicates the presence of the 32 * area (at the fpstate+extended_size-FP_XSTATE_MAGIC2_SIZE address) is set to
20 * extended state information in the memory layout pointed by the fpstate 33 * FP_XSTATE_MAGIC2 so that you can sanity check your size calculations.)
21 * pointer in sigcontext. 34 *
35 * This extended area typically grows with newer CPUs that have larger and larger
36 * XSAVE areas.
22 */ 37 */
23struct _fpx_sw_bytes { 38struct _fpx_sw_bytes {
24 __u32 magic1; /* FP_XSTATE_MAGIC1 */ 39 /* If set to FP_XSTATE_MAGIC1 then this is an xstate context. 0 if a legacy frame. */
25 __u32 extended_size; /* total size of the layout referred by 40 __u32 magic1;
26 * fpstate pointer in the sigcontext. 41
27 */ 42 /*
28 __u64 xfeatures; 43 * Total size of the fpstate area:
29 /* feature bit mask (including fp/sse/extended 44 *
30 * state) that is present in the memory 45 * - if magic1 == 0 then it's sizeof(struct _fpstate)
31 * layout. 46 * - if magic1 == FP_XSTATE_MAGIC1 then it's sizeof(struct _xstate) plus extensions (if any)
32 */ 47 */
33 __u32 xstate_size; /* actual xsave state size, based on the 48 __u32 extended_size;
34 * features saved in the layout. 49
35 * 'extended_size' will be greater than 50 /*
36 * 'xstate_size'. 51 * Feature bit mask (including FP/SSE/extended state) that is present
37 */ 52 * in the memory layout:
38 __u32 padding[7]; /* for future use. */ 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];
39}; 64};
40 65
41#ifdef __i386__ 66#ifdef __i386__
42/* 67/*
43 * As documented in the iBCS2 standard.. 68 * As documented in the iBCS2 standard:
44 * 69 *
45 * The first part of "struct _fpstate" is just the normal i387 70 * The first part of "struct _fpstate" is just the normal i387
46 * hardware setup, the extra "status" word is used to save the 71 * hardware setup, the extra "status" word is used to save the
47 * coprocessor status word before entering the handler. 72 * coprocessor status word before entering the handler.
48 * 73 *
49 * Pentium III FXSR, SSE support
50 * Gareth Hughes <gareth@valinux.com>, May 2000
51 *
52 * The FPU state data structure has had to grow to accommodate the 74 * The FPU state data structure has had to grow to accommodate the
53 * extended FPU state required by the Streaming SIMD Extensions. 75 * extended FPU state required by the Streaming SIMD Extensions.
54 * There is no documented standard to accomplish this at the moment. 76 * There is no documented standard to accomplish this at the moment.
55 */ 77 */
78
79/* 10-byte legacy floating point register: */
56struct _fpreg { 80struct _fpreg {
57 unsigned short significand[4]; 81 unsigned short significand[4];
58 unsigned short exponent; 82 unsigned short exponent;
59}; 83};
60 84
85/* 16-byte floating point register: */
61struct _fpxreg { 86struct _fpxreg {
62 unsigned short significand[4]; 87 unsigned short significand[4];
63 unsigned short exponent; 88 unsigned short exponent;
64 unsigned short padding[3]; 89 unsigned short padding[3];
65}; 90};
66 91
92/* 16-byte XMM register: */
67struct _xmmreg { 93struct _xmmreg {
68 unsigned long element[4]; 94 unsigned long element[4];
69}; 95};
70 96
97#define X86_FXSR_MAGIC 0x0000
98
71struct _fpstate { 99struct _fpstate {
72 /* Regular FPU environment */ 100 /* Legacy FPU environment: */
73 unsigned long cw; 101 unsigned long cw;
74 unsigned long sw; 102 unsigned long sw;
75 unsigned long tag; 103 unsigned long tag;
76 unsigned long ipoff; 104 unsigned long ipoff;
77 unsigned long cssel; 105 unsigned long cssel;
78 unsigned long dataoff; 106 unsigned long dataoff;
79 unsigned long datasel; 107 unsigned long datasel;
80 struct _fpreg _st[8]; 108 struct _fpreg _st[8];
81 unsigned short status; 109 unsigned short status;
82 unsigned short magic; /* 0xffff = regular FPU data only */ 110 unsigned short magic; /* 0xffff: regular FPU data only */
111 /* 0x0000: FXSR FPU data */
83 112
84 /* FXSR FPU environment */ 113 /* FXSR FPU environment */
85 unsigned long _fxsr_env[6]; /* FXSR FPU env is ignored */ 114 unsigned long _fxsr_env[6]; /* FXSR FPU env is ignored */
86 unsigned long mxcsr; 115 unsigned long mxcsr;
87 unsigned long reserved; 116 unsigned long reserved;
88 struct _fpxreg _fxsr_st[8]; /* FXSR FPU reg data is ignored */ 117 struct _fpxreg _fxsr_st[8]; /* FXSR FPU reg data is ignored */
89 struct _xmmreg _xmm[8]; 118 struct _xmmreg _xmm[8]; /* First 8 XMM registers */
90 unsigned long padding1[44]; 119 unsigned long padding1[44]; /* Second 8 XMM registers plus padding */
91 120
92 union { 121 union {
93 unsigned long padding2[12]; 122 unsigned long padding2[12];
94 struct _fpx_sw_bytes sw_reserved; /* represents the extended 123 struct _fpx_sw_bytes sw_reserved; /* Potential extended state is encoded here */
95 * state info */
96 }; 124 };
97}; 125};
98 126
99#define X86_FXSR_MAGIC 0x0000 127# ifndef __KERNEL__
100
101#ifndef __KERNEL__
102/* 128/*
103 * User-space might still rely on the old definition: 129 * User-space might still rely on the old definition:
104 */ 130 */
105struct sigcontext { 131struct sigcontext {
106 unsigned short gs, __gsh; 132 unsigned short gs, __gsh;
107 unsigned short fs, __fsh; 133 unsigned short fs, __fsh;
108 unsigned short es, __esh; 134 unsigned short es, __esh;
109 unsigned short ds, __dsh; 135 unsigned short ds, __dsh;
110 unsigned long edi; 136 unsigned long edi;
111 unsigned long esi; 137 unsigned long esi;
112 unsigned long ebp; 138 unsigned long ebp;
113 unsigned long esp; 139 unsigned long esp;
114 unsigned long ebx; 140 unsigned long ebx;
115 unsigned long edx; 141 unsigned long edx;
116 unsigned long ecx; 142 unsigned long ecx;
117 unsigned long eax; 143 unsigned long eax;
118 unsigned long trapno; 144 unsigned long trapno;
119 unsigned long err; 145 unsigned long err;
120 unsigned long eip; 146 unsigned long eip;
121 unsigned short cs, __csh; 147 unsigned short cs, __csh;
122 unsigned long eflags; 148 unsigned long eflags;
123 unsigned long esp_at_signal; 149 unsigned long esp_at_signal;
124 unsigned short ss, __ssh; 150 unsigned short ss, __ssh;
125 struct _fpstate __user *fpstate; 151 struct _fpstate __user *fpstate;
126 unsigned long oldmask; 152 unsigned long oldmask;
127 unsigned long cr2; 153 unsigned long cr2;
128}; 154};
129#endif /* !__KERNEL__ */ 155# endif /* !__KERNEL__ */
130 156
131#else /* __i386__ */ 157#else /* __x86_64__: */
132 158
133/* FXSAVE frame */ 159/*
134/* Note: reserved1/2 may someday contain valuable data. Always save/restore 160 * The FXSAVE frame.
135 them when you change signal frames. */ 161 *
162 * Note1: If sw_reserved.magic1 == FP_XSTATE_MAGIC1 then the structure is
163 * larger: 'struct _xstate'. Note that 'struct _xstate' embedds
164 * 'struct _fpstate' so that you can always assume the _fpstate portion
165 * exists so that you can check the magic value.
166 *
167 * Note2: Reserved fields may someday contain valuable data. Always save/restore
168 * them when you change signal frames.
169 */
136struct _fpstate { 170struct _fpstate {
137 __u16 cwd; 171 __u16 cwd;
138 __u16 swd; 172 __u16 swd;
139 __u16 twd; /* Note this is not the same as the 173 /* Note this is not the same as the 32-bit/x87/FSAVE twd: */
140 32bit/x87/FSAVE twd */ 174 __u16 twd;
141 __u16 fop; 175 __u16 fop;
142 __u64 rip; 176 __u64 rip;
143 __u64 rdp; 177 __u64 rdp;
144 __u32 mxcsr; 178 __u32 mxcsr;
145 __u32 mxcsr_mask; 179 __u32 mxcsr_mask;
146 __u32 st_space[32]; /* 8*16 bytes for each FP-reg */ 180 __u32 st_space[32]; /* 8x FP registers, 16 bytes each */
147 __u32 xmm_space[64]; /* 16*16 bytes for each XMM-reg */ 181 __u32 xmm_space[64]; /* 16x XMM registers, 16 bytes each */
148 __u32 reserved2[12]; 182 __u32 reserved2[12];
149 union { 183 union {
150 __u32 reserved3[12]; 184 __u32 reserved3[12];
151 struct _fpx_sw_bytes sw_reserved; /* represents the extended 185 struct _fpx_sw_bytes sw_reserved; /* Potential extended state is encoded here */
152 * state information */
153 }; 186 };
154}; 187};
155 188
156#ifndef __KERNEL__ 189# ifndef __KERNEL__
157/* 190/*
158 * User-space might still rely on the old definition: 191 * User-space might still rely on the old definition:
159 */ 192 */
160struct sigcontext { 193struct sigcontext {
161 __u64 r8; 194 __u64 r8;
162 __u64 r9; 195 __u64 r9;
163 __u64 r10; 196 __u64 r10;
164 __u64 r11; 197 __u64 r11;
165 __u64 r12; 198 __u64 r12;
166 __u64 r13; 199 __u64 r13;
167 __u64 r14; 200 __u64 r14;
168 __u64 r15; 201 __u64 r15;
169 __u64 rdi; 202 __u64 rdi;
170 __u64 rsi; 203 __u64 rsi;
171 __u64 rbp; 204 __u64 rbp;
172 __u64 rbx; 205 __u64 rbx;
173 __u64 rdx; 206 __u64 rdx;
174 __u64 rax; 207 __u64 rax;
175 __u64 rcx; 208 __u64 rcx;
176 __u64 rsp; 209 __u64 rsp;
177 __u64 rip; 210 __u64 rip;
178 __u64 eflags; /* RFLAGS */ 211 __u64 eflags; /* RFLAGS */
179 __u16 cs; 212 __u16 cs;
180 __u16 gs; 213 __u16 gs;
181 __u16 fs; 214 __u16 fs;
182 __u16 __pad0; 215 __u16 __pad0;
183 __u64 err; 216 __u64 err;
184 __u64 trapno; 217 __u64 trapno;
185 __u64 oldmask; 218 __u64 oldmask;
186 __u64 cr2; 219 __u64 cr2;
187 struct _fpstate __user *fpstate; /* zero when no FPU context */ 220 struct _fpstate __user *fpstate; /* Zero when no FPU context */
188#ifdef __ILP32__ 221# ifdef __ILP32__
189 __u32 __fpstate_pad; 222 __u32 __fpstate_pad;
190#endif 223# endif
191 __u64 reserved1[8]; 224 __u64 reserved1[8];
192}; 225};
193#endif /* !__KERNEL__ */ 226# endif /* !__KERNEL__ */
194 227
195#endif /* !__i386__ */ 228#endif /* __x86_64__ */
196 229
197struct _header { 230struct _header {
198 __u64 xfeatures; 231 __u64 xfeatures;
199 __u64 reserved1[2]; 232 __u64 reserved1[2];
200 __u64 reserved2[5]; 233 __u64 reserved2[5];
201}; 234};
202 235
203struct _ymmh_state { 236struct _ymmh_state {
204 /* 16 * 16 bytes for each YMMH-reg */ 237 /* 16x YMM registers, 16 bytes each: */
205 __u32 ymmh_space[64]; 238 __u32 ymmh_space[64];
206}; 239};
207 240
208/* 241/*
209 * Extended state pointed by the fpstate pointer in the sigcontext. 242 * Extended state pointed to by sigcontext::fpstate.
210 * In addition to the fpstate, information encoded in the xstate_hdr 243 *
211 * indicates the presence of other extended state information 244 * In addition to the fpstate, information encoded in _xstate::xstate_hdr
212 * supported by the processor and OS. 245 * indicates the presence of other extended state information supported
246 * by the CPU and kernel:
213 */ 247 */
214struct _xstate { 248struct _xstate {
215 struct _fpstate fpstate; 249 struct _fpstate fpstate;
216 struct _header xstate_hdr; 250 struct _header xstate_hdr;
217 struct _ymmh_state ymmh; 251 struct _ymmh_state ymmh;
218 /* new processor state extensions go here */ 252 /* New processor state extensions go here: */
219}; 253};
220 254
221#endif /* _UAPI_ASM_X86_SIGCONTEXT_H */ 255#endif /* _UAPI_ASM_X86_SIGCONTEXT_H */