update boost
This commit is contained in:
@@ -44,6 +44,17 @@
|
||||
# include BOOST_ABI_PREFIX
|
||||
#endif
|
||||
|
||||
#if defined(__CET__) && defined(__unix__)
|
||||
# include <cet.h>
|
||||
# include <sys/mman.h>
|
||||
# define SHSTK_ENABLED (__CET__ & 0x2)
|
||||
# define BOOST_CONTEXT_SHADOW_STACK (SHSTK_ENABLED && SHADOW_STACK_SYSCALL)
|
||||
# define __NR_map_shadow_stack 451
|
||||
#ifndef SHADOW_STACK_SET_TOKEN
|
||||
# define SHADOW_STACK_SET_TOKEN 0x1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_MSVC)
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable: 4702)
|
||||
@@ -62,6 +73,12 @@ transfer_t fiber_unwind( transfer_t t) {
|
||||
template< typename Rec >
|
||||
transfer_t fiber_exit( transfer_t t) noexcept {
|
||||
Rec * rec = static_cast< Rec * >( t.data);
|
||||
#if BOOST_CONTEXT_SHADOW_STACK
|
||||
// destory shadow stack
|
||||
std::size_t ss_size = *((unsigned long*)(reinterpret_cast< uintptr_t >( rec)- 16));
|
||||
long unsigned int ss_base = *((unsigned long*)(reinterpret_cast< uintptr_t >( rec)- 8));
|
||||
munmap((void *)ss_base, ss_size);
|
||||
#endif
|
||||
// destroy context stack
|
||||
rec->deallocate();
|
||||
return { nullptr, nullptr };
|
||||
@@ -80,9 +97,6 @@ void fiber_entry( transfer_t t) noexcept {
|
||||
t.fctx = rec->run( t.fctx);
|
||||
} catch ( forced_unwind const& ex) {
|
||||
t = { ex.fctx, nullptr };
|
||||
#ifndef BOOST_ASSERT_IS_VOID
|
||||
const_cast< forced_unwind & >( ex).caught = true;
|
||||
#endif
|
||||
}
|
||||
BOOST_ASSERT( nullptr != t.fctx);
|
||||
// destroy context-stack of `this`context on next context
|
||||
@@ -168,6 +182,25 @@ fcontext_t create_fiber1( StackAlloc && salloc, Fn && fn) {
|
||||
reinterpret_cast< uintptr_t >( sctx.sp) - static_cast< uintptr_t >( sctx.size) );
|
||||
// create fast-context
|
||||
const std::size_t size = reinterpret_cast< uintptr_t >( stack_top) - reinterpret_cast< uintptr_t >( stack_bottom);
|
||||
|
||||
#if BOOST_CONTEXT_SHADOW_STACK
|
||||
std::size_t ss_size = size >> 5;
|
||||
// align shadow stack to 8 bytes.
|
||||
ss_size = (ss_size + 7) & ~7;
|
||||
// Todo: shadow stack occupies at least 4KB
|
||||
ss_size = (ss_size > 4096) ? size : 4096;
|
||||
// create shadow stack
|
||||
void *ss_base = (void *)syscall(__NR_map_shadow_stack, 0, ss_size, SHADOW_STACK_SET_TOKEN);
|
||||
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? */
|
||||
*((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;
|
||||
*((unsigned long*)(reinterpret_cast< uintptr_t >( storage)- 16)) = ss_size;
|
||||
#endif
|
||||
const fcontext_t fctx = make_fcontext( stack_top, size, & fiber_entry< Record >);
|
||||
BOOST_ASSERT( nullptr != fctx);
|
||||
// transfer control structure to context-stack
|
||||
@@ -190,6 +223,25 @@ fcontext_t create_fiber2( preallocated palloc, StackAlloc && salloc, Fn && fn) {
|
||||
reinterpret_cast< uintptr_t >( palloc.sctx.sp) - static_cast< uintptr_t >( palloc.sctx.size) );
|
||||
// create fast-context
|
||||
const std::size_t size = reinterpret_cast< uintptr_t >( stack_top) - reinterpret_cast< uintptr_t >( stack_bottom);
|
||||
|
||||
#if BOOST_CONTEXT_SHADOW_STACK
|
||||
std::size_t ss_size = size >> 5;
|
||||
// align shadow stack to 8 bytes.
|
||||
ss_size = (ss_size + 7) & ~7;
|
||||
// Todo: shadow stack occupies at least 4KB
|
||||
ss_size = (ss_size > 4096) ? size : 4096;
|
||||
// create shadow stack
|
||||
void *ss_base = (void *)syscall(__NR_map_shadow_stack, 0, ss_size, SHADOW_STACK_SET_TOKEN);
|
||||
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? */
|
||||
*((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;
|
||||
*((unsigned long*)(reinterpret_cast< uintptr_t >( storage)- 16)) = ss_size;
|
||||
#endif
|
||||
const fcontext_t fctx = make_fcontext( stack_top, size, & fiber_entry< Record >);
|
||||
BOOST_ASSERT( nullptr != fctx);
|
||||
// transfer control structure to context-stack
|
||||
@@ -207,14 +259,6 @@ private:
|
||||
friend detail::transfer_t
|
||||
detail::fiber_ontop( detail::transfer_t);
|
||||
|
||||
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::fcontext_t fctx_{ nullptr };
|
||||
|
||||
fiber( detail::fcontext_t fctx) noexcept :
|
||||
@@ -314,6 +358,8 @@ public:
|
||||
return fctx_ < other.fctx_;
|
||||
}
|
||||
|
||||
#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) {
|
||||
@@ -324,11 +370,33 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
template< typename charT, class traitsT >
|
||||
friend std::basic_ostream< charT, traitsT > &
|
||||
operator<<( std::basic_ostream< charT, traitsT > & os, fiber const& other);
|
||||
|
||||
#endif
|
||||
|
||||
void swap( fiber & other) noexcept {
|
||||
std::swap( fctx_, other.fctx_);
|
||||
}
|
||||
};
|
||||
|
||||
#if defined(BOOST_EMBTC)
|
||||
|
||||
template< typename charT, class traitsT >
|
||||
inline std::basic_ostream< charT, traitsT > &
|
||||
operator<<( std::basic_ostream< charT, traitsT > & os, fiber const& other) {
|
||||
if ( nullptr != other.fctx_) {
|
||||
return os << other.fctx_;
|
||||
} else {
|
||||
return os << "{not-a-context}";
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
inline
|
||||
void swap( fiber & l, fiber & r) noexcept {
|
||||
l.swap( r);
|
||||
|
||||
Reference in New Issue
Block a user