From 73c90bb783f3f7482b77a14e71e932701a082358 Mon Sep 17 00:00:00 2001 From: Andrey Semashev Date: Thu, 12 Sep 2024 19:44:24 +0300 Subject: [PATCH 1/2] Fix __NR_map_shadow_stack redefinition. __NR_map_shadow_stack is defined to 453 (not 451) on Ubuntu 24.04 with Linux kernel 6.8.0-44, gcc 13.2.0 and glibc 2.39. This causes warnings about macro redefinition when Boost.Fiber is compiled. Change the syscall number to 453 and only define the macro if it has not been defined already. Also include unistd.h for syscall() and __NR_* constants. Fixes https://github.com/boostorg/context/issues/263. Fixes https://github.com/boostorg/context/issues/269. --- include/boost/context/fiber_fcontext.hpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/boost/context/fiber_fcontext.hpp b/include/boost/context/fiber_fcontext.hpp index a2760cbd..3299ff66 100644 --- a/include/boost/context/fiber_fcontext.hpp +++ b/include/boost/context/fiber_fcontext.hpp @@ -47,9 +47,12 @@ #if defined(__CET__) && defined(__unix__) # include # include +# include # define SHSTK_ENABLED (__CET__ & 0x2) # define BOOST_CONTEXT_SHADOW_STACK (SHSTK_ENABLED && SHADOW_STACK_SYSCALL) -# define __NR_map_shadow_stack 451 +# if !defined(__NR_map_shadow_stack) +# define __NR_map_shadow_stack 453 +# endif #ifndef SHADOW_STACK_SET_TOKEN # define SHADOW_STACK_SET_TOKEN 0x1 #endif From 658379be4ac7eb43e0caccf834ce6afe141ca1d8 Mon Sep 17 00:00:00 2001 From: Andrey Semashev Date: Thu, 12 Sep 2024 19:53:20 +0300 Subject: [PATCH 2/2] Replace tabs with spaces, trim trailing spaces. --- include/boost/context/fiber_fcontext.hpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/include/boost/context/fiber_fcontext.hpp b/include/boost/context/fiber_fcontext.hpp index 3299ff66..55c96d17 100644 --- a/include/boost/context/fiber_fcontext.hpp +++ b/include/boost/context/fiber_fcontext.hpp @@ -171,8 +171,8 @@ template< typename Record, typename StackAlloc, typename Fn > fcontext_t create_fiber1( StackAlloc && salloc, Fn && fn) { auto sctx = salloc.allocate(); // reserve space for control structure - void * storage = reinterpret_cast< void * >( - ( reinterpret_cast< uintptr_t >( sctx.sp) - static_cast< uintptr_t >( sizeof( Record) ) ) + void * storage = reinterpret_cast< void * >( + ( reinterpret_cast< uintptr_t >( sctx.sp) - static_cast< uintptr_t >( sizeof( Record) ) ) & ~static_cast< uintptr_t >( 0xff) ); // placment new for control structure on context stack Record * record = new ( storage) Record{ @@ -189,7 +189,7 @@ fcontext_t create_fiber1( StackAlloc && salloc, Fn && fn) { #if BOOST_CONTEXT_SHADOW_STACK std::size_t ss_size = size >> 5; // align shadow stack to 8 bytes. - ss_size = (ss_size + 7) & ~7; + ss_size = (ss_size + 7) & ~7; // Todo: shadow stack occupies at least 4KB ss_size = (ss_size > 4096) ? size : 4096; // create shadow stack @@ -197,8 +197,8 @@ fcontext_t create_fiber1( StackAlloc && salloc, Fn && fn) { BOOST_ASSERT(ss_base != -1); unsigned long ss_sp = (unsigned long)ss_base + ss_size; /* pass the shadow stack pointer to make_fcontext - i.e., link the new shadow stack with the new fcontext - TODO should be a better way? */ + i.e., link the new shadow stack with the new fcontext + TODO should be a better way? */ *((unsigned long*)(reinterpret_cast< uintptr_t >( stack_top)- 8)) = ss_sp; /* Todo: place shadow stack info in 64byte gap */ *((unsigned long*)(reinterpret_cast< uintptr_t >( storage)- 8)) = (unsigned long) ss_base; @@ -230,7 +230,7 @@ fcontext_t create_fiber2( preallocated palloc, StackAlloc && salloc, Fn && fn) { #if BOOST_CONTEXT_SHADOW_STACK std::size_t ss_size = size >> 5; // align shadow stack to 8 bytes. - ss_size = (ss_size + 7) & ~7; + ss_size = (ss_size + 7) & ~7; // Todo: shadow stack occupies at least 4KB ss_size = (ss_size > 4096) ? size : 4096; // create shadow stack @@ -238,8 +238,8 @@ fcontext_t create_fiber2( preallocated palloc, StackAlloc && salloc, Fn && fn) { BOOST_ASSERT(ss_base != -1); unsigned long ss_sp = (unsigned long)ss_base + ss_size; /* pass the shadow stack pointer to make_fcontext - i.e., link the new shadow stack with the new fcontext - TODO should be a better way? */ + i.e., link the new shadow stack with the new fcontext + TODO should be a better way? */ *((unsigned long*)(reinterpret_cast< uintptr_t >( stack_top)- 8)) = ss_sp; /* Todo: place shadow stack info in 64byte gap */ *((unsigned long*)(reinterpret_cast< uintptr_t >( storage)- 8)) = (unsigned long) ss_base; @@ -362,7 +362,7 @@ class fiber { } #if !defined(BOOST_EMBTC) - + template< typename charT, class traitsT > friend std::basic_ostream< charT, traitsT > & operator<<( std::basic_ostream< charT, traitsT > & os, fiber const& other) { @@ -374,7 +374,7 @@ class fiber { } #else - + template< typename charT, class traitsT > friend std::basic_ostream< charT, traitsT > & operator<<( std::basic_ostream< charT, traitsT > & os, fiber const& other); @@ -399,7 +399,7 @@ class fiber { } #endif - + inline void swap( fiber & l, fiber & r) noexcept { l.swap( r);