From 65f8e49c0fba5ce4ae2f1ab708e8321f6201ed4f Mon Sep 17 00:00:00 2001 From: Ilya Kurdyukov Date: Wed, 23 Jun 2021 12:40:23 +0700 Subject: [PATCH] boost-1.76 e2k support Build with b2 options: context-impl=ucontext define=BOOST_USE_UCONTEXT --- boost/context/continuation_ucontext.hpp | 23 +++++++++++++++++++ boost/context/detail/config.hpp | 2 +- boost/context/fiber_ucontext.hpp | 23 +++++++++++++++++++ .../src/detail/coroutine_context.cpp | 11 +++++++++ 4 files changed, 58 insertions(+), 1 deletion(-) diff --git a/boost/context/continuation_ucontext.hpp b/boost/context/continuation_ucontext.hpp index 78889fd5f..d339c97e6 100644 --- a/boost/boost/context/continuation_ucontext.hpp +++ b/boost/boost/context/continuation_ucontext.hpp @@ -233,6 +233,9 @@ static void destroy( capture_record * p) noexcept { typename std::decay< StackAlloc >::type salloc = std::move( p->salloc_); stack_context sctx = p->sctx; +#ifdef __e2k__ + ::freecontext_e2k( & p->uctx); +#endif // deallocate activation record p->~capture_record(); // destroy stack with stack allocator @@ -312,9 +315,19 @@ std::uint32_t((integer >> 32) & 0xFFFFFFFF), std::uint32_t(integer)); #else +#ifdef __e2k__ + if ( BOOST_UNLIKELY( ::makecontext_e2k( & record->uctx, ( void (*)() ) & entry_func< capture_t >, 1, record) < 0) ) { + record->~capture_t(); + salloc.deallocate( sctx); + throw std::system_error( + std::error_code( errno, std::system_category() ), + "makecontext_e2k() failed"); + } +#else ::makecontext(&record->uctx, (void (*)()) & entry_func, 1, record); #endif +#endif #if defined(BOOST_USE_ASAN) record->stack_bottom = record->uctx.uc_stack.ss_sp; record->stack_size = record->uctx.uc_stack.ss_size; @@ -355,9 +368,19 @@ std::uint32_t((integer >> 32) & 0xFFFFFFFF), std::uint32_t(integer)); #else +#ifdef __e2k__ + if ( BOOST_UNLIKELY( ::makecontext_e2k( & record->uctx, ( void (*)() ) & entry_func< capture_t >, 1, record) < 0) ) { + record->~capture_t(); + salloc.deallocate( palloc.sctx); + throw std::system_error( + std::error_code( errno, std::system_category() ), + "makecontext_e2k() failed"); + } +#else ::makecontext(&record->uctx, (void (*)()) & entry_func, 1, record); #endif +#endif #if defined(BOOST_USE_ASAN) record->stack_bottom = record->uctx.uc_stack.ss_sp; record->stack_size = record->uctx.uc_stack.ss_size; diff --git a/boost/context/detail/config.hpp b/boost/context/detail/config.hpp index 06737fdf9..b62b8e176 100644 --- a/boost/boost/context/detail/config.hpp +++ b/boost/boost/context/detail/config.hpp @@ -30,7 +30,7 @@ # define BOOST_CONTEXT_DECL #endif -#if ! defined(BOOST_USE_UCONTEXT) && defined(__CYGWIN__) +#if ! defined(BOOST_USE_UCONTEXT) && (defined(__CYGWIN__) || defined(__e2k__) ) # define BOOST_USE_UCONTEXT #endif diff --git a/boost/context/fiber_ucontext.hpp b/boost/context/fiber_ucontext.hpp index 859b7bc6a..c2152f65f 100644 --- a/boost/boost/context/fiber_ucontext.hpp +++ b/boost/boost/context/fiber_ucontext.hpp @@ -258,6 +258,9 @@ static void destroy( fiber_capture_record * p) noexcept { typename std::decay< StackAlloc >::type salloc = std::move( p->salloc_); stack_context sctx = p->sctx; +#ifdef __e2k__ + ::freecontext_e2k( & p->uctx); +#endif // deallocate activation record p->~fiber_capture_record(); // destroy stack with stack allocator @@ -342,9 +345,19 @@ std::uint32_t((integer >> 32) & 0xFFFFFFFF), std::uint32_t(integer)); #else +#ifdef __e2k__ + if ( BOOST_UNLIKELY( ::makecontext_e2k( & record->uctx, ( void (*)() ) & fiber_entry_func< capture_t >, 1, record) < 0) ) { + record->~capture_t(); + salloc.deallocate( sctx); + throw std::system_error( + std::error_code( errno, std::system_category() ), + "makecontext_e2k() failed"); + } +#else ::makecontext(&record->uctx, (void (*)()) & fiber_entry_func, 1, record); #endif +#endif #if defined(BOOST_USE_ASAN) record->stack_bottom = record->uctx.uc_stack.ss_sp; record->stack_size = record->uctx.uc_stack.ss_size; @@ -393,9 +406,19 @@ std::uint32_t((integer >> 32) & 0xFFFFFFFF), std::uint32_t(integer)); #else +#ifdef __e2k__ + if ( BOOST_UNLIKELY( ::makecontext_e2k( & record->uctx, ( void (*)() ) & fiber_entry_func< capture_t >, 1, record) < 0) ) { + record->~capture_t(); + salloc.deallocate( palloc.sctx); + throw std::system_error( + std::error_code( errno, std::system_category() ), + "makecontext_e2k() failed"); + } +#else ::makecontext(&record->uctx, (void (*)()) & fiber_entry_func, 1, record); #endif +#endif #if defined(BOOST_USE_ASAN) record->stack_bottom = record->uctx.uc_stack.ss_sp; record->stack_size = record->uctx.uc_stack.ss_size; diff --git a/libs/coroutine/src/detail/coroutine_context.cpp b/libs/coroutine/src/detail/coroutine_context.cpp index 6a6d52483..1949cfd91 100644 --- a/boost/libs/coroutine/src/detail/coroutine_context.cpp +++ b/boost/libs/coroutine/src/detail/coroutine_context.cpp @@ -8,6 +8,17 @@ #include "boost/coroutine/detail/data.hpp" +#ifdef __e2k__ +#include +#define UNSUPPORTED_E2K(name) extern "C" void name() { \ + std::cerr << "function \"" #name "\" is unsupported on e2k" << std::endl; \ + std::abort(); \ +} +UNSUPPORTED_E2K(jump_fcontext) +UNSUPPORTED_E2K(make_fcontext) +UNSUPPORTED_E2K(ontop_fcontext) +#endif + #ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_PREFIX #endif -- 2.17.1