]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/x86/dl-minsigstacksize.h
1 /* Emulate AT_MINSIGSTKSZ. Linux/x86 version.
2 Copyright (C) 2020-2022 Free Software Foundation, Inc.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
18 /* Emulate AT_MINSIGSTKSZ with XSAVE. */
21 dl_check_minsigstacksize (const struct cpu_features
*cpu_features
)
23 /* Return if AT_MINSIGSTKSZ is provide by kernel. */
24 if (GLRO(dl_minsigstacksize
) != 0)
27 if (cpu_features
->basic
.max_cpuid
>= 0xd
28 && CPU_FEATURES_CPU_P (cpu_features
, OSXSAVE
))
30 /* Emulate AT_MINSIGSTKSZ. In Linux kernel, the signal frame data
31 with XSAVE is composed of the following areas and laid out as:
32 ------------------------------
34 ------------------------------
36 ------------------------------
37 | fsave header (32-bit only) |
38 ------------------------------
39 | siginfo + ucontext |
40 ------------------------------
43 unsigned int sigframe_size
;
46 /* NB: sizeof(struct rt_sigframe) + 8-byte return address in Linux
48 sigframe_size
= 440 + 8;
50 /* NB: sizeof(struct sigframe_ia32) + sizeof(struct fregs_state)) +
51 4-byte return address + 3 * 4-byte arguments in Linux kernel. */
52 sigframe_size
= 736 + 112 + 4 + 3 * 4;
55 /* Add 15 bytes to align the stack to 16 bytes. */
58 /* Make the space before xsave buffer multiple of 16 bytes. */
59 sigframe_size
= ALIGN_UP (sigframe_size
, 16);
61 /* Add (64 - 16)-byte padding to align xsave buffer at 64 bytes. */
62 sigframe_size
+= 64 - 16;
64 unsigned int eax
, ebx
, ecx
, edx
;
65 __cpuid_count (0xd, 0, eax
, ebx
, ecx
, edx
);
67 /* Add the size of xsave buffer. */
70 /* Add the size of FP_XSTATE_MAGIC2. */
71 #define FP_XSTATE_MAGIC2 0x46505845U
72 sigframe_size
+= sizeof (FP_XSTATE_MAGIC2
);
74 GLRO(dl_minsigstacksize
) = sigframe_size
;
78 /* NB: Default to a constant MINSIGSTKSZ. */
79 _Static_assert (__builtin_constant_p (MINSIGSTKSZ
),
80 "MINSIGSTKSZ is constant");
81 GLRO(dl_minsigstacksize
) = MINSIGSTKSZ
;