162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
262306a36Sopenharmony_ci#ifndef _ASM_X86_UCONTEXT_H
362306a36Sopenharmony_ci#define _ASM_X86_UCONTEXT_H
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci/*
662306a36Sopenharmony_ci * Indicates the presence of extended state information in the memory
762306a36Sopenharmony_ci * layout pointed by the fpstate pointer in the ucontext's sigcontext
862306a36Sopenharmony_ci * struct (uc_mcontext).
962306a36Sopenharmony_ci */
1062306a36Sopenharmony_ci#define UC_FP_XSTATE	0x1
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci#ifdef __x86_64__
1362306a36Sopenharmony_ci/*
1462306a36Sopenharmony_ci * UC_SIGCONTEXT_SS will be set when delivering 64-bit or x32 signals on
1562306a36Sopenharmony_ci * kernels that save SS in the sigcontext.  All kernels that set
1662306a36Sopenharmony_ci * UC_SIGCONTEXT_SS will correctly restore at least the low 32 bits of esp
1762306a36Sopenharmony_ci * regardless of SS (i.e. they implement espfix).
1862306a36Sopenharmony_ci *
1962306a36Sopenharmony_ci * Kernels that set UC_SIGCONTEXT_SS will also set UC_STRICT_RESTORE_SS
2062306a36Sopenharmony_ci * when delivering a signal that came from 64-bit code.
2162306a36Sopenharmony_ci *
2262306a36Sopenharmony_ci * Sigreturn restores SS as follows:
2362306a36Sopenharmony_ci *
2462306a36Sopenharmony_ci * if (saved SS is valid || UC_STRICT_RESTORE_SS is set ||
2562306a36Sopenharmony_ci *     saved CS is not 64-bit)
2662306a36Sopenharmony_ci *         new SS = saved SS  (will fail IRET and signal if invalid)
2762306a36Sopenharmony_ci * else
2862306a36Sopenharmony_ci *         new SS = a flat 32-bit data segment
2962306a36Sopenharmony_ci *
3062306a36Sopenharmony_ci * This behavior serves three purposes:
3162306a36Sopenharmony_ci *
3262306a36Sopenharmony_ci * - Legacy programs that construct a 64-bit sigcontext from scratch
3362306a36Sopenharmony_ci *   with zero or garbage in the SS slot (e.g. old CRIU) and call
3462306a36Sopenharmony_ci *   sigreturn will still work.
3562306a36Sopenharmony_ci *
3662306a36Sopenharmony_ci * - Old DOSEMU versions sometimes catch a signal from a segmented
3762306a36Sopenharmony_ci *   context, delete the old SS segment (with modify_ldt), and change
3862306a36Sopenharmony_ci *   the saved CS to a 64-bit segment.  These DOSEMU versions expect
3962306a36Sopenharmony_ci *   sigreturn to send them back to 64-bit mode without killing them,
4062306a36Sopenharmony_ci *   despite the fact that the SS selector when the signal was raised is
4162306a36Sopenharmony_ci *   no longer valid.  UC_STRICT_RESTORE_SS will be clear, so the kernel
4262306a36Sopenharmony_ci *   will fix up SS for these DOSEMU versions.
4362306a36Sopenharmony_ci *
4462306a36Sopenharmony_ci * - Old and new programs that catch a signal and return without
4562306a36Sopenharmony_ci *   modifying the saved context will end up in exactly the state they
4662306a36Sopenharmony_ci *   started in, even if they were running in a segmented context when
4762306a36Sopenharmony_ci *   the signal was raised..  Old kernels would lose track of the
4862306a36Sopenharmony_ci *   previous SS value.
4962306a36Sopenharmony_ci */
5062306a36Sopenharmony_ci#define UC_SIGCONTEXT_SS	0x2
5162306a36Sopenharmony_ci#define UC_STRICT_RESTORE_SS	0x4
5262306a36Sopenharmony_ci#endif
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_ci#include <asm-generic/ucontext.h>
5562306a36Sopenharmony_ci
5662306a36Sopenharmony_ci#endif /* _ASM_X86_UCONTEXT_H */
57