xref: /openbmc/linux/arch/x86/include/uapi/asm/ucontext.h (revision 6f52b16c)
16f52b16cSGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2af170c50SDavid Howells #ifndef _ASM_X86_UCONTEXT_H
3af170c50SDavid Howells #define _ASM_X86_UCONTEXT_H
4af170c50SDavid Howells 
56c25da5aSAndy Lutomirski /*
66c25da5aSAndy Lutomirski  * Indicates the presence of extended state information in the memory
76c25da5aSAndy Lutomirski  * layout pointed by the fpstate pointer in the ucontext's sigcontext
86c25da5aSAndy Lutomirski  * struct (uc_mcontext).
9af170c50SDavid Howells  */
106c25da5aSAndy Lutomirski #define UC_FP_XSTATE	0x1
116c25da5aSAndy Lutomirski 
126c25da5aSAndy Lutomirski #ifdef __x86_64__
136c25da5aSAndy Lutomirski /*
146c25da5aSAndy Lutomirski  * UC_SIGCONTEXT_SS will be set when delivering 64-bit or x32 signals on
156c25da5aSAndy Lutomirski  * kernels that save SS in the sigcontext.  All kernels that set
166c25da5aSAndy Lutomirski  * UC_SIGCONTEXT_SS will correctly restore at least the low 32 bits of esp
176c25da5aSAndy Lutomirski  * regardless of SS (i.e. they implement espfix).
186c25da5aSAndy Lutomirski  *
196c25da5aSAndy Lutomirski  * Kernels that set UC_SIGCONTEXT_SS will also set UC_STRICT_RESTORE_SS
206c25da5aSAndy Lutomirski  * when delivering a signal that came from 64-bit code.
216c25da5aSAndy Lutomirski  *
226c25da5aSAndy Lutomirski  * Sigreturn restores SS as follows:
236c25da5aSAndy Lutomirski  *
246c25da5aSAndy Lutomirski  * if (saved SS is valid || UC_STRICT_RESTORE_SS is set ||
256c25da5aSAndy Lutomirski  *     saved CS is not 64-bit)
266c25da5aSAndy Lutomirski  *         new SS = saved SS  (will fail IRET and signal if invalid)
276c25da5aSAndy Lutomirski  * else
286c25da5aSAndy Lutomirski  *         new SS = a flat 32-bit data segment
296c25da5aSAndy Lutomirski  *
306c25da5aSAndy Lutomirski  * This behavior serves three purposes:
316c25da5aSAndy Lutomirski  *
326c25da5aSAndy Lutomirski  * - Legacy programs that construct a 64-bit sigcontext from scratch
336c25da5aSAndy Lutomirski  *   with zero or garbage in the SS slot (e.g. old CRIU) and call
346c25da5aSAndy Lutomirski  *   sigreturn will still work.
356c25da5aSAndy Lutomirski  *
366c25da5aSAndy Lutomirski  * - Old DOSEMU versions sometimes catch a signal from a segmented
376c25da5aSAndy Lutomirski  *   context, delete the old SS segment (with modify_ldt), and change
386c25da5aSAndy Lutomirski  *   the saved CS to a 64-bit segment.  These DOSEMU versions expect
396c25da5aSAndy Lutomirski  *   sigreturn to send them back to 64-bit mode without killing them,
406c25da5aSAndy Lutomirski  *   despite the fact that the SS selector when the signal was raised is
416c25da5aSAndy Lutomirski  *   no longer valid.  UC_STRICT_RESTORE_SS will be clear, so the kernel
426c25da5aSAndy Lutomirski  *   will fix up SS for these DOSEMU versions.
436c25da5aSAndy Lutomirski  *
446c25da5aSAndy Lutomirski  * - Old and new programs that catch a signal and return without
456c25da5aSAndy Lutomirski  *   modifying the saved context will end up in exactly the state they
466c25da5aSAndy Lutomirski  *   started in, even if they were running in a segmented context when
476c25da5aSAndy Lutomirski  *   the signal was raised..  Old kernels would lose track of the
486c25da5aSAndy Lutomirski  *   previous SS value.
496c25da5aSAndy Lutomirski  */
506c25da5aSAndy Lutomirski #define UC_SIGCONTEXT_SS	0x2
516c25da5aSAndy Lutomirski #define UC_STRICT_RESTORE_SS	0x4
526c25da5aSAndy Lutomirski #endif
53af170c50SDavid Howells 
54af170c50SDavid Howells #include <asm-generic/ucontext.h>
55af170c50SDavid Howells 
56af170c50SDavid Howells #endif /* _ASM_X86_UCONTEXT_H */
57