xref: /openbmc/linux/arch/x86/include/uapi/asm/ucontext.h (revision 6c25da5ad55d48c41b8909bc1f4e3cd5d85bb499)
1af170c50SDavid Howells #ifndef _ASM_X86_UCONTEXT_H
2af170c50SDavid Howells #define _ASM_X86_UCONTEXT_H
3af170c50SDavid Howells 
4*6c25da5aSAndy Lutomirski /*
5*6c25da5aSAndy Lutomirski  * Indicates the presence of extended state information in the memory
6*6c25da5aSAndy Lutomirski  * layout pointed by the fpstate pointer in the ucontext's sigcontext
7*6c25da5aSAndy Lutomirski  * struct (uc_mcontext).
8af170c50SDavid Howells  */
9*6c25da5aSAndy Lutomirski #define UC_FP_XSTATE	0x1
10*6c25da5aSAndy Lutomirski 
11*6c25da5aSAndy Lutomirski #ifdef __x86_64__
12*6c25da5aSAndy Lutomirski /*
13*6c25da5aSAndy Lutomirski  * UC_SIGCONTEXT_SS will be set when delivering 64-bit or x32 signals on
14*6c25da5aSAndy Lutomirski  * kernels that save SS in the sigcontext.  All kernels that set
15*6c25da5aSAndy Lutomirski  * UC_SIGCONTEXT_SS will correctly restore at least the low 32 bits of esp
16*6c25da5aSAndy Lutomirski  * regardless of SS (i.e. they implement espfix).
17*6c25da5aSAndy Lutomirski  *
18*6c25da5aSAndy Lutomirski  * Kernels that set UC_SIGCONTEXT_SS will also set UC_STRICT_RESTORE_SS
19*6c25da5aSAndy Lutomirski  * when delivering a signal that came from 64-bit code.
20*6c25da5aSAndy Lutomirski  *
21*6c25da5aSAndy Lutomirski  * Sigreturn restores SS as follows:
22*6c25da5aSAndy Lutomirski  *
23*6c25da5aSAndy Lutomirski  * if (saved SS is valid || UC_STRICT_RESTORE_SS is set ||
24*6c25da5aSAndy Lutomirski  *     saved CS is not 64-bit)
25*6c25da5aSAndy Lutomirski  *         new SS = saved SS  (will fail IRET and signal if invalid)
26*6c25da5aSAndy Lutomirski  * else
27*6c25da5aSAndy Lutomirski  *         new SS = a flat 32-bit data segment
28*6c25da5aSAndy Lutomirski  *
29*6c25da5aSAndy Lutomirski  * This behavior serves three purposes:
30*6c25da5aSAndy Lutomirski  *
31*6c25da5aSAndy Lutomirski  * - Legacy programs that construct a 64-bit sigcontext from scratch
32*6c25da5aSAndy Lutomirski  *   with zero or garbage in the SS slot (e.g. old CRIU) and call
33*6c25da5aSAndy Lutomirski  *   sigreturn will still work.
34*6c25da5aSAndy Lutomirski  *
35*6c25da5aSAndy Lutomirski  * - Old DOSEMU versions sometimes catch a signal from a segmented
36*6c25da5aSAndy Lutomirski  *   context, delete the old SS segment (with modify_ldt), and change
37*6c25da5aSAndy Lutomirski  *   the saved CS to a 64-bit segment.  These DOSEMU versions expect
38*6c25da5aSAndy Lutomirski  *   sigreturn to send them back to 64-bit mode without killing them,
39*6c25da5aSAndy Lutomirski  *   despite the fact that the SS selector when the signal was raised is
40*6c25da5aSAndy Lutomirski  *   no longer valid.  UC_STRICT_RESTORE_SS will be clear, so the kernel
41*6c25da5aSAndy Lutomirski  *   will fix up SS for these DOSEMU versions.
42*6c25da5aSAndy Lutomirski  *
43*6c25da5aSAndy Lutomirski  * - Old and new programs that catch a signal and return without
44*6c25da5aSAndy Lutomirski  *   modifying the saved context will end up in exactly the state they
45*6c25da5aSAndy Lutomirski  *   started in, even if they were running in a segmented context when
46*6c25da5aSAndy Lutomirski  *   the signal was raised..  Old kernels would lose track of the
47*6c25da5aSAndy Lutomirski  *   previous SS value.
48*6c25da5aSAndy Lutomirski  */
49*6c25da5aSAndy Lutomirski #define UC_SIGCONTEXT_SS	0x2
50*6c25da5aSAndy Lutomirski #define UC_STRICT_RESTORE_SS	0x4
51*6c25da5aSAndy Lutomirski #endif
52af170c50SDavid Howells 
53af170c50SDavid Howells #include <asm-generic/ucontext.h>
54af170c50SDavid Howells 
55af170c50SDavid Howells #endif /* _ASM_X86_UCONTEXT_H */
56