aboutsummaryrefslogtreecommitdiffstats
path: root/contrib
diff options
context:
space:
mode:
authorthegeorg <thegeorg@yandex-team.com>2022-12-22 17:43:48 +0300
committerthegeorg <thegeorg@yandex-team.com>2022-12-22 17:43:48 +0300
commite640635ed609ad90b26d7241d9aebb801e51b4da (patch)
tree19a9ac40f45752040e2a53849677f0b731f18810 /contrib
parent3c8ee53569860626532fd1c34cbe8585e73e6703 (diff)
downloadydb-e640635ed609ad90b26d7241d9aebb801e51b4da.tar.gz
Update contrib/restricted/boost/context to 1.81.0
Diffstat (limited to 'contrib')
-rw-r--r--contrib/restricted/boost/context/include/boost/context/fiber_ucontext.hpp8
-rw-r--r--contrib/restricted/boost/context/include/boost/context/fiber_winfib.hpp8
-rw-r--r--contrib/restricted/boost/context/src/asm/jump_x86_64_sysv_elf_gas.S29
-rw-r--r--contrib/restricted/boost/context/src/asm/make_x86_64_sysv_elf_gas.S45
-rw-r--r--contrib/restricted/boost/context/src/asm/ontop_x86_64_sysv_elf_gas.S22
5 files changed, 96 insertions, 16 deletions
diff --git a/contrib/restricted/boost/context/include/boost/context/fiber_ucontext.hpp b/contrib/restricted/boost/context/include/boost/context/fiber_ucontext.hpp
index 97537f0140..696ce58084 100644
--- a/contrib/restricted/boost/context/include/boost/context/fiber_ucontext.hpp
+++ b/contrib/restricted/boost/context/include/boost/context/fiber_ucontext.hpp
@@ -397,14 +397,6 @@ private:
template< typename Ctx, typename StackAlloc, typename Fn >
friend detail::fiber_activation_record * detail::create_fiber2( preallocated, StackAlloc &&, Fn &&);
- template< typename StackAlloc, typename Fn >
- friend fiber
- callcc( std::allocator_arg_t, StackAlloc &&, Fn &&);
-
- template< typename StackAlloc, typename Fn >
- friend fiber
- callcc( std::allocator_arg_t, preallocated, StackAlloc &&, Fn &&);
-
detail::fiber_activation_record * ptr_{ nullptr };
fiber( detail::fiber_activation_record * ptr) noexcept :
diff --git a/contrib/restricted/boost/context/include/boost/context/fiber_winfib.hpp b/contrib/restricted/boost/context/include/boost/context/fiber_winfib.hpp
index 727b3742af..cd496d1be1 100644
--- a/contrib/restricted/boost/context/include/boost/context/fiber_winfib.hpp
+++ b/contrib/restricted/boost/context/include/boost/context/fiber_winfib.hpp
@@ -290,14 +290,6 @@ private:
template< typename Ctx, typename StackAlloc, typename Fn >
friend detail::fiber_activation_record * detail::create_fiber2( preallocated, StackAlloc &&, Fn &&);
- template< typename StackAlloc, typename Fn >
- friend fiber
- callcc( std::allocator_arg_t, StackAlloc &&, Fn &&);
-
- template< typename StackAlloc, typename Fn >
- friend fiber
- callcc( std::allocator_arg_t, preallocated, StackAlloc &&, Fn &&);
-
detail::fiber_activation_record * ptr_{ nullptr };
fiber( detail::fiber_activation_record * ptr) noexcept :
diff --git a/contrib/restricted/boost/context/src/asm/jump_x86_64_sysv_elf_gas.S b/contrib/restricted/boost/context/src/asm/jump_x86_64_sysv_elf_gas.S
index 2505219cfa..58f0e241d7 100644
--- a/contrib/restricted/boost/context/src/asm/jump_x86_64_sysv_elf_gas.S
+++ b/contrib/restricted/boost/context/src/asm/jump_x86_64_sysv_elf_gas.S
@@ -30,8 +30,11 @@
* ---------------------------------------------------------------------------------- *
* *
****************************************************************************************/
+
# if defined __CET__
# include <cet.h>
+# define SHSTK_ENABLED (__CET__ & 0x2)
+# define BOOST_CONTEXT_SHADOW_STACK (SHSTK_ENABLED && SHADOW_STACK_SYSCALL)
# else
# define _CET_ENDBR
# endif
@@ -61,12 +64,38 @@ jump_fcontext:
movq %rbx, 0x30(%rsp) /* save RBX */
movq %rbp, 0x38(%rsp) /* save RBP */
+#if BOOST_CONTEXT_SHADOW_STACK
+ /* grow the stack to reserve space for shadow stack pointer(SSP) */
+ leaq -0x8(%rsp), %rsp
+ /* read the current SSP and store it */
+ rdsspq %rcx
+ movq %rcx, (%rsp)
+#endif
+
/* store RSP (pointing to context-data) in RAX */
movq %rsp, %rax
/* restore RSP (pointing to context-data) from RDI */
movq %rdi, %rsp
+#if BOOST_CONTEXT_SHADOW_STACK
+ /* first 8 bytes are SSP */
+ movq (%rsp), %rcx
+ leaq 0x8(%rsp), %rsp
+
+ /* Restore target(new) shadow stack */
+ rstorssp -8(%rcx)
+ /* restore token for previous shadow stack is pushed */
+ /* on previous shadow stack after saveprevssp */
+ saveprevssp
+
+ /* when return, jump_fcontext jump to restored return address */
+ /* (r8) instead of RET. This miss of RET implies us to unwind */
+ /* shadow stack accordingly. Otherwise mismatch occur */
+ movq $1, %rcx
+ incsspq %rcx
+#endif
+
movq 0x40(%rsp), %r8 /* restore return-address */
#if !defined(BOOST_USE_TSX)
diff --git a/contrib/restricted/boost/context/src/asm/make_x86_64_sysv_elf_gas.S b/contrib/restricted/boost/context/src/asm/make_x86_64_sysv_elf_gas.S
index 0890fcfb27..4294398a2e 100644
--- a/contrib/restricted/boost/context/src/asm/make_x86_64_sysv_elf_gas.S
+++ b/contrib/restricted/boost/context/src/asm/make_x86_64_sysv_elf_gas.S
@@ -30,8 +30,11 @@
* ---------------------------------------------------------------------------------- *
* *
****************************************************************************************/
+
# if defined __CET__
# include <cet.h>
+# define SHSTK_ENABLED (__CET__ & 0x2)
+# define BOOST_CONTEXT_SHADOW_STACK (SHSTK_ENABLED && SHADOW_STACK_SYSCALL)
# else
# define _CET_ENDBR
# endif
@@ -42,6 +45,11 @@
.align 16
make_fcontext:
_CET_ENDBR
+#if BOOST_CONTEXT_SHADOW_STACK
+ /* the new shadow stack pointer (SSP) */
+ movq -0x8(%rdi), %r9
+#endif
+
/* first arg of make_fcontext() == top of context-stack */
movq %rdi, %rax
@@ -79,13 +87,50 @@ make_fcontext:
/* will be entered after context-function returns */
movq %rcx, 0x38(%rax)
+#if BOOST_CONTEXT_SHADOW_STACK
+ /* Populate the shadow stack and normal stack */
+ /* get original SSP */
+ rdsspq %r8
+ /* restore new shadow stack */
+ rstorssp -0x8(%r9)
+ /* save the restore token on the original shadow stack */
+ saveprevssp
+ /* push the address of "jmp trampoline" to the new shadow stack */
+ /* as well as the stack */
+ call 1f
+ jmp trampoline
+1:
+ /* save address of "jmp trampoline" as return-address */
+ /* for context-function */
+ pop 0x38(%rax)
+ /* Get the new SSP. */
+ rdsspq %r9
+ /* restore original shadow stack */
+ rstorssp -0x8(%r8)
+ /* save the restore token on the new shadow stack. */
+ saveprevssp
+
+ /* reserve space for the new SSP */
+ leaq -0x8(%rax), %rax
+ /* save the new SSP to this fcontext */
+ movq %r9, (%rax)
+#endif
+
ret /* return pointer to context-data */
trampoline:
_CET_ENDBR
/* store return address on stack */
/* fix stack alignment */
+#if BOOST_CONTEXT_SHADOW_STACK
+ /* save address of "jmp *%rbp" as return-address */
+ /* on stack and shadow stack */
+ call 2f
+ jmp *%rbp
+2:
+#else
push %rbp
+#endif
/* jump to context-function */
jmp *%rbx
diff --git a/contrib/restricted/boost/context/src/asm/ontop_x86_64_sysv_elf_gas.S b/contrib/restricted/boost/context/src/asm/ontop_x86_64_sysv_elf_gas.S
index 6b35a7c955..c3892b8ba0 100644
--- a/contrib/restricted/boost/context/src/asm/ontop_x86_64_sysv_elf_gas.S
+++ b/contrib/restricted/boost/context/src/asm/ontop_x86_64_sysv_elf_gas.S
@@ -32,6 +32,8 @@
****************************************************************************************/
# if defined __CET__
# include <cet.h>
+# define SHSTK_ENABLED (__CET__ & 0x2)
+# define BOOST_CONTEXT_SHADOW_STACK (SHSTK_ENABLED && SHADOW_STACK_SYSCALL)
# else
# define _CET_ENDBR
# endif
@@ -64,12 +66,32 @@ ontop_fcontext:
movq %rbx, 0x30(%rsp) /* save RBX */
movq %rbp, 0x38(%rsp) /* save RBP */
+#if BOOST_CONTEXT_SHADOW_STACK
+ /* grow the stack to reserve space for shadow stack pointer(SSP) */
+ leaq -0x8(%rsp), %rsp
+ /* read the current SSP and store it */
+ rdsspq %rcx
+ movq %rcx, (%rsp)
+#endif
+
/* store RSP (pointing to context-data) in RAX */
movq %rsp, %rax
/* restore RSP (pointing to context-data) from RDI */
movq %rdi, %rsp
+#if BOOST_CONTEXT_SHADOW_STACK
+ /* first 8 bytes are SSP */
+ movq (%rsp), %rcx
+ leaq 0x8(%rsp), %rsp
+
+ /* Restore target(new) shadow stack */
+ rstorssp -8(%rcx)
+ /* restore token for previous shadow stack is pushed */
+ /* on previous shadow stack after saveprevssp */
+ saveprevssp
+#endif
+
#if !defined(BOOST_USE_TSX)
ldmxcsr (%rsp) /* restore MMX control- and status-word */
fldcw 0x4(%rsp) /* restore x87 control-word */