]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/doc/gcc/extensions-to-the-c-language-family/target-builtins/x86-control-flow-protection-intrinsics.rst
sphinx: add missing trailing newline
[thirdparty/gcc.git] / gcc / doc / gcc / extensions-to-the-c-language-family / target-builtins / x86-control-flow-protection-intrinsics.rst
1 ..
2 Copyright 1988-2022 Free Software Foundation, Inc.
3 This is part of the GCC manual.
4 For copying conditions, see the copyright.rst file.
5
6 .. _x86-control-flow-protection-intrinsics:
7
8 x86 Control-Flow Protection Intrinsics
9 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10
11 .. function:: ret_type _get_ssp (void)
12
13 Get the current value of shadow stack pointer if shadow stack support
14 from Intel CET is enabled in the hardware or ``0`` otherwise.
15 The ``ret_type`` is ``unsigned long long`` for 64-bit targets
16 and ``unsigned int`` for 32-bit targets.
17
18 .. function:: void _inc_ssp (unsigned int)
19
20 Increment the current shadow stack pointer by the size specified by the
21 function argument. The argument is masked to a byte value for security
22 reasons, so to increment by more than 255 bytes you must call the function
23 multiple times.
24
25 The shadow stack unwind code looks like:
26
27 .. code-block:: c++
28
29 #include <immintrin.h>
30
31 /* Unwind the shadow stack for EH. */
32 #define _Unwind_Frames_Extra(x) \
33 do \
34 { \
35 _Unwind_Word ssp = _get_ssp (); \
36 if (ssp != 0) \
37 { \
38 _Unwind_Word tmp = (x); \
39 while (tmp > 255) \
40 { \
41 _inc_ssp (tmp); \
42 tmp -= 255; \
43 } \
44 _inc_ssp (tmp); \
45 } \
46 } \
47 while (0)
48
49 This code runs unconditionally on all 64-bit processors. For 32-bit
50 processors the code runs on those that support multi-byte NOP instructions.