Skip to content

Commit

Permalink
feat core: update Boost.Context and Boost.Coroutine2 to 1.87
Browse files Browse the repository at this point in the history
Fixes: #620
Tests: протестировано CI
commit_hash:676dd740ba452798dfb84df2a8731e6444110489
  • Loading branch information
apolukhin committed Jan 9, 2025
1 parent 65806bf commit f44b36e
Show file tree
Hide file tree
Showing 27 changed files with 124 additions and 32 deletions.
1 change: 1 addition & 0 deletions .mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -3950,6 +3950,7 @@
"third_party/uboost_coro/src/context/asm/ontop_x86_64_sysv_macho_gas.S":"taxi/uservices/userver/third_party/uboost_coro/src/context/asm/ontop_x86_64_sysv_macho_gas.S",
"third_party/uboost_coro/src/context/continuation.cpp":"taxi/uservices/userver/third_party/uboost_coro/src/context/continuation.cpp",
"third_party/uboost_coro/src/context/dummy.cpp":"taxi/uservices/userver/third_party/uboost_coro/src/context/dummy.cpp",
"third_party/uboost_coro/src/context/fcontext.cpp":"taxi/uservices/userver/third_party/uboost_coro/src/context/fcontext.cpp",
"third_party/uboost_coro/src/context/fiber.cpp":"taxi/uservices/userver/third_party/uboost_coro/src/context/fiber.cpp",
"third_party/uboost_coro/src/context/posix/stack_traits.cpp":"taxi/uservices/userver/third_party/uboost_coro/src/context/posix/stack_traits.cpp",
"third_party/uboost_coro/src/context/untested.cpp":"taxi/uservices/userver/third_party/uboost_coro/src/context/untested.cpp",
Expand Down
1 change: 1 addition & 0 deletions third_party/uboost_coro/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ endif()

set(SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/context/posix/stack_traits.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/context/fcontext.cpp
)

enable_language(ASM)
Expand Down
2 changes: 1 addition & 1 deletion third_party/uboost_coro/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# userver: Boost.Coro
Subset of [Boost C++ Libraries](https://www.boost.org) 1.83.0, that includes Coroutine2 and Context.
Subset of [Boost C++ Libraries](https://www.boost.org) 1.87.0, that includes Coroutine2 and Context.
`CMakeLists.txt` is based on [boost-cmake](https://github.com/Orphis/boost-cmake).

Sanitizers could be enabled via [USERVER_SANITIZE](https://userver.tech/d3/da9/md_en_2userver_2tutorial_2build.html).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace detail {
// entered if the execution context
// is resumed for the first time
template <typename Record>
#ifdef BOOST_OS_MACOS
#if BOOST_OS_MACOS
static void entry_func(std::uint32_t data_high,
std::uint32_t data_low) noexcept {
auto data =
Expand Down Expand Up @@ -306,7 +306,7 @@ static activation_record * create_context1( StackAlloc && salloc, Fn && fn) {
record->uctx.uc_stack.ss_size = reinterpret_cast< uintptr_t >( storage) -
reinterpret_cast< uintptr_t >( stack_bottom) - static_cast< uintptr_t >( 64);
record->uctx.uc_link = nullptr;
#ifdef BOOST_OS_MACOS
#if BOOST_OS_MACOS
const auto integer = std::uint64_t(record);
::makecontext(&record->uctx, (void (*)()) & entry_func<capture_t>, 2,
std::uint32_t((integer >> 32) & 0xFFFFFFFF),
Expand Down Expand Up @@ -349,7 +349,7 @@ static activation_record * create_context2( preallocated palloc, StackAlloc && s
record->uctx.uc_stack.ss_size = reinterpret_cast< uintptr_t >( storage) -
reinterpret_cast< uintptr_t >( stack_bottom) - static_cast< uintptr_t >( 64);
record->uctx.uc_link = nullptr;
#ifdef BOOST_OS_MACOS
#if BOOST_OS_MACOS
const auto integer = std::uint64_t(record);
::makecontext(&record->uctx, (void (*)()) & entry_func<capture_t>, 2,
std::uint32_t((integer >> 32) & 0xFFFFFFFF),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,11 @@ struct transfer_t {
void * data;
};

extern "C" BOOST_CONTEXT_DECL
transfer_t BOOST_CONTEXT_CALLDECL jump_fcontext( fcontext_t const to, void * vp);
extern "C" BOOST_CONTEXT_DECL
fcontext_t BOOST_CONTEXT_CALLDECL make_fcontext( void * sp, std::size_t size, void (* fn)( transfer_t) );
BOOST_CONTEXT_DECL transfer_t jump_fcontext( fcontext_t const to, void * vp);
BOOST_CONTEXT_DECL fcontext_t make_fcontext( void * sp, std::size_t size, void (* fn)( transfer_t) );

// based on an idea of Giovanni Derreta
extern "C" BOOST_CONTEXT_DECL
transfer_t BOOST_CONTEXT_CALLDECL ontop_fcontext( fcontext_t const to, void * vp, transfer_t (* fn)( transfer_t) );
BOOST_CONTEXT_DECL transfer_t ontop_fcontext( fcontext_t const to, void * vp, transfer_t (* fn)( transfer_t) );

}}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ namespace detail {
// entered if the execution context
// is resumed for the first time
template <typename Record>
#ifdef BOOST_OS_MACOS
#if BOOST_OS_MACOS
static void fiber_entry_func(std::uint32_t data_high,
std::uint32_t data_low) noexcept {
auto data =
Expand Down Expand Up @@ -336,7 +336,7 @@ static fiber_activation_record * create_fiber1( StackAlloc && salloc, Fn && fn)
record->uctx.uc_stack.ss_size = reinterpret_cast< uintptr_t >( storage) -
reinterpret_cast< uintptr_t >( stack_bottom) - static_cast< uintptr_t >( 64);
record->uctx.uc_link = nullptr;
#ifdef BOOST_OS_MACOS
#if BOOST_OS_MACOS
const auto integer = std::uint64_t(record);
::makecontext(&record->uctx, (void (*)()) & fiber_entry_func<capture_t>, 2,
std::uint32_t((integer >> 32) & 0xFFFFFFFF),
Expand Down Expand Up @@ -387,7 +387,7 @@ static fiber_activation_record * create_fiber2( preallocated palloc, StackAlloc
record->uctx.uc_stack.ss_size = reinterpret_cast< uintptr_t >( storage) -
reinterpret_cast< uintptr_t >( stack_bottom) - static_cast< uintptr_t >( 64);
record->uctx.uc_link = nullptr;
#ifdef BOOST_OS_MACOS
#if BOOST_OS_MACOS
const auto integer = std::uint64_t(record);
::makecontext(&record->uctx, (void (*)()) & fiber_entry_func<capture_t>, 2,
std::uint32_t((integer >> 32) & 0xFFFFFFFF),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct pull_coroutine< T >::control_block {
state_t state;
std::exception_ptr except;
bool bvalid;
typename std::aligned_storage< sizeof( T), alignof( T) >::type storage;
alignas(T) unsigned char storage[sizeof(T)];

static void destroy( control_block * cb) noexcept;

Expand Down Expand Up @@ -71,7 +71,7 @@ struct pull_coroutine< T & >::control_block {
state_t state;
std::exception_ptr except;
bool bvalid;
typename std::aligned_storage< sizeof( holder), alignof( holder) >::type storage;
alignas(holder) unsigned char storage[sizeof(holder)];

static void destroy( control_block * cb) noexcept;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
.text
.align 2
.global jump_fcontext
.hidden jump_fcontext
.type jump_fcontext, %function
jump_fcontext:
# prepare stack for GP + FPU
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
*******************************************************/

.text
.private_extern _jump_fcontext
.globl _jump_fcontext
.balign 16
_jump_fcontext:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
.file "jump_arm_aapcs_elf_gas.S"
.text
.globl jump_fcontext
.hidden jump_fcontext
.align 2
.type jump_fcontext,%function
.syntax unified
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@
* *
****************************************************************************************/

#ifdef __x86_64__
#include "jump_x86_64_sysv_elf_gas.S"
#else

.file "jump_i386_sysv_elf_gas.S"
.text
.globl jump_fcontext
.hidden jump_fcontext
.align 2
.type jump_fcontext,@function
jump_fcontext:
Expand Down Expand Up @@ -91,3 +96,5 @@ jump_fcontext:

/* Mark that we don't need executable stack. */
.section .note.GNU-stack,"",%progbits

#endif
19 changes: 12 additions & 7 deletions third_party/uboost_coro/src/context/asm/jump_x86_64_sysv_elf_gas.S
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,20 @@
* *
****************************************************************************************/

# if defined __CET__
# include <cet.h>
# define SHSTK_ENABLED (__CET__ & 0x2)
# define BOOST_CONTEXT_SHADOW_STACK (SHSTK_ENABLED && SHADOW_STACK_SYSCALL)
# ifdef __i386__
# include "jump_i386_sysv_elf_gas.S"
# else
# define _CET_ENDBR
# endif
# 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
.file "jump_x86_64_sysv_elf_gas.S"
.text
.globl jump_fcontext
.hidden jump_fcontext
.type jump_fcontext,@function
.align 16
jump_fcontext:
Expand Down Expand Up @@ -70,7 +74,7 @@ jump_fcontext:
/* read the current SSP and store it */
rdsspq %rcx
movq %rcx, (%rsp)
#endif
# endif

/* store RSP (pointing to context-data) in RAX */
movq %rsp, %rax
Expand Down Expand Up @@ -140,3 +144,4 @@ jump_fcontext:

/* Mark that we don't need executable stack. */
.section .note.GNU-stack,"",%progbits
# endif
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
****************************************************************************************/

.text
.private_extern _jump_fcontext
.globl _jump_fcontext
.align 8
_jump_fcontext:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
.text
.align 2
.global make_fcontext
.hidden make_fcontext
.type make_fcontext, %function
make_fcontext:
# shift address in x0 (allocated stack) to lower 16 byte boundary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
*******************************************************/

.text
.private_extern _make_fcontext
.globl _make_fcontext
.balign 16

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
.file "make_arm_aapcs_elf_gas.S"
.text
.globl make_fcontext
.hidden make_fcontext
.align 2
.type make_fcontext,%function
.syntax unified
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@
* *
****************************************************************************************/

#ifdef __x86_64__
#include "make_x86_64_sysv_elf_gas.S"
#else

.file "make_i386_sysv_elf_gas.S"
.text
.globl make_fcontext
.hidden make_fcontext
.align 2
.type make_fcontext,@function
make_fcontext:
Expand Down Expand Up @@ -111,3 +116,5 @@ finish:

/* Mark that we don't need executable stack. */
.section .note.GNU-stack,"",%progbits

#endif
31 changes: 23 additions & 8 deletions third_party/uboost_coro/src/context/asm/make_x86_64_sysv_elf_gas.S
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,25 @@
* *
****************************************************************************************/

# if defined __CET__
# include <cet.h>
# define SHSTK_ENABLED (__CET__ & 0x2)
# define BOOST_CONTEXT_SHADOW_STACK (SHSTK_ENABLED && SHADOW_STACK_SYSCALL)
# ifdef __i386__
# include "make_i386_sysv_elf_gas.S"
# else
# define _CET_ENDBR
# endif
# 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
.file "make_x86_64_sysv_elf_gas.S"
.text
.globl make_fcontext
.hidden make_fcontext
.type make_fcontext,@function
.align 16
make_fcontext:
_CET_ENDBR

#if BOOST_CONTEXT_SHADOW_STACK
/* the new shadow stack pointer (SSP) */
movq -0x8(%rdi), %r9
Expand Down Expand Up @@ -88,7 +93,8 @@ make_fcontext:
movq %rcx, 0x38(%rax)

#if BOOST_CONTEXT_SHADOW_STACK
/* Populate the shadow stack and normal stack */
/* Populate the shadow stack */

/* get original SSP */
rdsspq %r8
/* restore new shadow stack */
Expand All @@ -110,6 +116,14 @@ make_fcontext:
/* save the restore token on the new shadow stack. */
saveprevssp

/* now the new shadow stack looks like:
base-> +------------------------------+
| address of "jmp trampoline" |
SSP-> +------------------------------+
| restore token |
+------------------------------+
*/

/* reserve space for the new SSP */
leaq -0x8(%rax), %rax
/* save the new SSP to this fcontext */
Expand All @@ -119,9 +133,9 @@ make_fcontext:
ret /* return pointer to context-data */

trampoline:
_CET_ENDBR
/* store return address on stack */
/* fix stack alignment */
_CET_ENDBR
#if BOOST_CONTEXT_SHADOW_STACK
/* save address of "jmp *%rbp" as return-address */
/* on stack and shadow stack */
Expand All @@ -145,3 +159,4 @@ finish:

/* Mark that we don't need executable stack. */
.section .note.GNU-stack,"",%progbits
# endif
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
****************************************************************************************/

.text
.private_extern _make_fcontext
.globl _make_fcontext
.align 8
_make_fcontext:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
.text
.align 2
.global ontop_fcontext
.hidden ontop_fcontext
.type ontop_fcontext, %function
ontop_fcontext:
# prepare stack for GP + FPU
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
*******************************************************/

.text
.private_extern _ontop_fcontext
.global _ontop_fcontext
.balign 16
_ontop_fcontext:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
.file "ontop_arm_aapcs_elf_gas.S"
.text
.globl ontop_fcontext
.hidden ontop_fcontext
.align 2
.type ontop_fcontext,%function
.syntax unified
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@
* *
****************************************************************************************/

#ifdef __x86_64__
#include "ontop_x86_64_sysv_elf_gas.S"
#else

.file "ontop_i386_sysv_elf_gas.S"
.text
.globl ontop_fcontext
.hidden ontop_fcontext
.align 2
.type ontop_fcontext,@function
ontop_fcontext:
Expand Down Expand Up @@ -98,3 +103,5 @@ ontop_fcontext:

/* Mark that we don't need executable stack. */
.section .note.GNU-stack,"",%progbits

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
.file "ontop_x86_64_sysv_elf_gas.S"
.text
.globl ontop_fcontext
.hidden ontop_fcontext
.type ontop_fcontext,@function
.align 16
ontop_fcontext:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
****************************************************************************************/

.text
.private_extern _ontop_fcontext
.globl _ontop_fcontext
.align 8
_ontop_fcontext:
Expand Down
Loading

0 comments on commit f44b36e

Please sign in to comment.