sigcontext.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. #ifndef _ASM_X86_SIGCONTEXT_H
  2. #define _ASM_X86_SIGCONTEXT_H
  3. /*
  4. * Linux signal context definitions. The sigcontext includes a complex
  5. * hierarchy of CPU and FPU state, available to user-space (on the stack) when
  6. * a signal handler is executed.
  7. *
  8. * As over the years this ABI grew from its very simple roots towards
  9. * supporting more and more CPU state organically, some of the details (which
  10. * were rather clever hacks back in the days) became a bit quirky by today.
  11. *
  12. * The current ABI includes flexible provisions for future extensions, so we
  13. * won't have to grow new quirks for quite some time. Promise!
  14. */
  15. #include <linux/types.h>
  16. #define FP_XSTATE_MAGIC1 0x46505853U
  17. #define FP_XSTATE_MAGIC2 0x46505845U
  18. #define FP_XSTATE_MAGIC2_SIZE sizeof(FP_XSTATE_MAGIC2)
  19. /*
  20. * Bytes 464..511 in the current 512-byte layout of the FXSAVE/FXRSTOR frame
  21. * are reserved for SW usage. On CPUs supporting XSAVE/XRSTOR, these bytes are
  22. * used to extend the fpstate pointer in the sigcontext, which now includes the
  23. * extended state information along with fpstate information.
  24. *
  25. * If sw_reserved.magic1 == FP_XSTATE_MAGIC1 then there's a
  26. * sw_reserved.extended_size bytes large extended context area present. (The
  27. * last 32-bit word of this extended area (at the
  28. * fpstate+extended_size-FP_XSTATE_MAGIC2_SIZE address) is set to
  29. * FP_XSTATE_MAGIC2 so that you can sanity check your size calculations.)
  30. *
  31. * This extended area typically grows with newer CPUs that have larger and
  32. * larger XSAVE areas.
  33. */
  34. struct _fpx_sw_bytes {
  35. /*
  36. * If set to FP_XSTATE_MAGIC1 then this is an xstate context.
  37. * 0 if a legacy frame.
  38. */
  39. __u32 magic1;
  40. /*
  41. * Total size of the fpstate area:
  42. *
  43. * - if magic1 == 0 then it's sizeof(struct _fpstate)
  44. * - if magic1 == FP_XSTATE_MAGIC1 then it's sizeof(struct _xstate)
  45. * plus extensions (if any)
  46. */
  47. __u32 extended_size;
  48. /*
  49. * Feature bit mask (including FP/SSE/extended state) that is present
  50. * in the memory layout:
  51. */
  52. __u64 xfeatures;
  53. /*
  54. * Actual XSAVE state size, based on the xfeatures saved in the layout.
  55. * 'extended_size' is greater than 'xstate_size':
  56. */
  57. __u32 xstate_size;
  58. /* For future use: */
  59. __u32 padding[7];
  60. };
  61. /*
  62. * As documented in the iBCS2 standard:
  63. *
  64. * The first part of "struct _fpstate" is just the normal i387 hardware setup,
  65. * the extra "status" word is used to save the coprocessor status word before
  66. * entering the handler.
  67. *
  68. * The FPU state data structure has had to grow to accommodate the extended FPU
  69. * state required by the Streaming SIMD Extensions. There is no documented
  70. * standard to accomplish this at the moment.
  71. */
  72. /* 10-byte legacy floating point register: */
  73. struct _fpreg {
  74. __u16 significand[4];
  75. __u16 exponent;
  76. };
  77. /* 16-byte floating point register: */
  78. struct _fpxreg {
  79. __u16 significand[4];
  80. __u16 exponent;
  81. __u16 padding[3];
  82. };
  83. /* 16-byte XMM register: */
  84. struct _xmmreg {
  85. __u32 element[4];
  86. };
  87. #define X86_FXSR_MAGIC 0x0000
  88. /*
  89. * The 32-bit FPU frame:
  90. */
  91. struct _fpstate_32 {
  92. /* Legacy FPU environment: */
  93. __u32 cw;
  94. __u32 sw;
  95. __u32 tag;
  96. __u32 ipoff;
  97. __u32 cssel;
  98. __u32 dataoff;
  99. __u32 datasel;
  100. struct _fpreg _st[8];
  101. __u16 status;
  102. __u16 magic; /* 0xffff: regular FPU data only */
  103. /* 0x0000: FXSR FPU data */
  104. /* FXSR FPU environment */
  105. __u32 _fxsr_env[6]; /* FXSR FPU env is ignored */
  106. __u32 mxcsr;
  107. __u32 reserved;
  108. struct _fpxreg _fxsr_st[8]; /* FXSR FPU reg data is ignored */
  109. struct _xmmreg _xmm[8]; /* First 8 XMM registers */
  110. union {
  111. __u32 padding1[44]; /* Second 8 XMM registers plus padding */
  112. __u32 padding[44]; /* Alias name for old user-space */
  113. };
  114. union {
  115. __u32 padding2[12];
  116. struct _fpx_sw_bytes sw_reserved; /* Potential extended state is encoded here */
  117. };
  118. };
  119. /*
  120. * The 64-bit FPU frame. (FXSAVE format and later)
  121. *
  122. * Note1: If sw_reserved.magic1 == FP_XSTATE_MAGIC1 then the structure is
  123. * larger: 'struct _xstate'. Note that 'struct _xstate' embedds
  124. * 'struct _fpstate' so that you can always assume the _fpstate portion
  125. * exists so that you can check the magic value.
  126. *
  127. * Note2: Reserved fields may someday contain valuable data. Always
  128. * save/restore them when you change signal frames.
  129. */
  130. struct _fpstate_64 {
  131. __u16 cwd;
  132. __u16 swd;
  133. /* Note this is not the same as the 32-bit/x87/FSAVE twd: */
  134. __u16 twd;
  135. __u16 fop;
  136. __u64 rip;
  137. __u64 rdp;
  138. __u32 mxcsr;
  139. __u32 mxcsr_mask;
  140. __u32 st_space[32]; /* 8x FP registers, 16 bytes each */
  141. __u32 xmm_space[64]; /* 16x XMM registers, 16 bytes each */
  142. __u32 reserved2[12];
  143. union {
  144. __u32 reserved3[12];
  145. struct _fpx_sw_bytes sw_reserved; /* Potential extended state is encoded here */
  146. };
  147. };
  148. #ifdef __i386__
  149. # define _fpstate _fpstate_32
  150. #else
  151. # define _fpstate _fpstate_64
  152. #endif
  153. struct _header {
  154. __u64 xfeatures;
  155. __u64 reserved1[2];
  156. __u64 reserved2[5];
  157. };
  158. struct _ymmh_state {
  159. /* 16x YMM registers, 16 bytes each: */
  160. __u32 ymmh_space[64];
  161. };
  162. /*
  163. * Extended state pointed to by sigcontext::fpstate.
  164. *
  165. * In addition to the fpstate, information encoded in _xstate::xstate_hdr
  166. * indicates the presence of other extended state information supported
  167. * by the CPU and kernel:
  168. */
  169. struct _xstate {
  170. struct _fpstate fpstate;
  171. struct _header xstate_hdr;
  172. struct _ymmh_state ymmh;
  173. /* New processor state extensions go here: */
  174. };
  175. /*
  176. * The 32-bit signal frame:
  177. */
  178. struct sigcontext_32 {
  179. __u16 gs, __gsh;
  180. __u16 fs, __fsh;
  181. __u16 es, __esh;
  182. __u16 ds, __dsh;
  183. __u32 di;
  184. __u32 si;
  185. __u32 bp;
  186. __u32 sp;
  187. __u32 bx;
  188. __u32 dx;
  189. __u32 cx;
  190. __u32 ax;
  191. __u32 trapno;
  192. __u32 err;
  193. __u32 ip;
  194. __u16 cs, __csh;
  195. __u32 flags;
  196. __u32 sp_at_signal;
  197. __u16 ss, __ssh;
  198. /*
  199. * fpstate is really (struct _fpstate *) or (struct _xstate *)
  200. * depending on the FP_XSTATE_MAGIC1 encoded in the SW reserved
  201. * bytes of (struct _fpstate) and FP_XSTATE_MAGIC2 present at the end
  202. * of extended memory layout. See comments at the definition of
  203. * (struct _fpx_sw_bytes)
  204. */
  205. __u32 fpstate; /* Zero when no FPU/extended context */
  206. __u32 oldmask;
  207. __u32 cr2;
  208. };
  209. /*
  210. * The 64-bit signal frame:
  211. */
  212. struct sigcontext_64 {
  213. __u64 r8;
  214. __u64 r9;
  215. __u64 r10;
  216. __u64 r11;
  217. __u64 r12;
  218. __u64 r13;
  219. __u64 r14;
  220. __u64 r15;
  221. __u64 di;
  222. __u64 si;
  223. __u64 bp;
  224. __u64 bx;
  225. __u64 dx;
  226. __u64 ax;
  227. __u64 cx;
  228. __u64 sp;
  229. __u64 ip;
  230. __u64 flags;
  231. __u16 cs;
  232. __u16 gs;
  233. __u16 fs;
  234. __u16 __pad0;
  235. __u64 err;
  236. __u64 trapno;
  237. __u64 oldmask;
  238. __u64 cr2;
  239. /*
  240. * fpstate is really (struct _fpstate *) or (struct _xstate *)
  241. * depending on the FP_XSTATE_MAGIC1 encoded in the SW reserved
  242. * bytes of (struct _fpstate) and FP_XSTATE_MAGIC2 present at the end
  243. * of extended memory layout. See comments at the definition of
  244. * (struct _fpx_sw_bytes)
  245. */
  246. __u64 fpstate; /* Zero when no FPU/extended context */
  247. __u64 reserved1[8];
  248. };
  249. /*
  250. * Create the real 'struct sigcontext' type:
  251. */
  252. /*
  253. * The old user-space sigcontext definition, just in case user-space still
  254. * relies on it. The kernel definition (in asm/sigcontext.h) has unified
  255. * field names but otherwise the same layout.
  256. */
  257. #define _fpstate_ia32 _fpstate_32
  258. #define sigcontext_ia32 sigcontext_32
  259. # ifdef __i386__
  260. struct sigcontext {
  261. __u16 gs, __gsh;
  262. __u16 fs, __fsh;
  263. __u16 es, __esh;
  264. __u16 ds, __dsh;
  265. __u32 edi;
  266. __u32 esi;
  267. __u32 ebp;
  268. __u32 esp;
  269. __u32 ebx;
  270. __u32 edx;
  271. __u32 ecx;
  272. __u32 eax;
  273. __u32 trapno;
  274. __u32 err;
  275. __u32 eip;
  276. __u16 cs, __csh;
  277. __u32 eflags;
  278. __u32 esp_at_signal;
  279. __u16 ss, __ssh;
  280. struct _fpstate *fpstate;
  281. __u32 oldmask;
  282. __u32 cr2;
  283. };
  284. # else /* __x86_64__: */
  285. struct sigcontext {
  286. __u64 r8;
  287. __u64 r9;
  288. __u64 r10;
  289. __u64 r11;
  290. __u64 r12;
  291. __u64 r13;
  292. __u64 r14;
  293. __u64 r15;
  294. __u64 rdi;
  295. __u64 rsi;
  296. __u64 rbp;
  297. __u64 rbx;
  298. __u64 rdx;
  299. __u64 rax;
  300. __u64 rcx;
  301. __u64 rsp;
  302. __u64 rip;
  303. __u64 eflags; /* RFLAGS */
  304. __u16 cs;
  305. __u16 gs;
  306. __u16 fs;
  307. __u16 __pad0;
  308. __u64 err;
  309. __u64 trapno;
  310. __u64 oldmask;
  311. __u64 cr2;
  312. struct _fpstate *fpstate; /* Zero when no FPU context */
  313. # ifdef __ILP32__
  314. __u32 __fpstate_pad;
  315. # endif
  316. __u64 reserved1[8];
  317. };
  318. # endif /* __x86_64__ */
  319. #endif /* _ASM_X86_SIGCONTEXT_H */