-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathboost-1.76-e2k.patch
151 lines (144 loc) · 6.46 KB
/
boost-1.76-e2k.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
From 65f8e49c0fba5ce4ae2f1ab708e8321f6201ed4f Mon Sep 17 00:00:00 2001
From: Ilya Kurdyukov <[email protected]>
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/context/continuation_ucontext.hpp
+++ b/boost/context/continuation_ucontext.hpp
@@ -234,6 +234,9 @@ private:
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
@@ -310,7 +313,17 @@ 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 __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< capture_t >, 1, record);
+#endif
#if defined(BOOST_USE_ASAN)
record->stack_bottom = record->uctx.uc_stack.ss_sp;
record->stack_size = record->uctx.uc_stack.ss_size;
@@ -345,7 +358,17 @@ 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 __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< capture_t >, 1, record);
+#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/context/detail/config.hpp
+++ b/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/context/fiber_ucontext.hpp
+++ b/boost/context/fiber_ucontext.hpp
@@ -258,6 +258,9 @@ private:
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
@@ -334,7 +337,17 @@ 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 __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< capture_t >, 1, record);
+#endif
#if defined(BOOST_USE_ASAN)
record->stack_bottom = record->uctx.uc_stack.ss_sp;
record->stack_size = record->uctx.uc_stack.ss_size;
@@ -372,7 +385,17 @@ 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 __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< capture_t >, 1, record);
+#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/libs/coroutine/src/detail/coroutine_context.cpp
+++ b/libs/coroutine/src/detail/coroutine_context.cpp
@@ -8,6 +8,17 @@
#include "boost/coroutine/detail/data.hpp"
+#ifdef __e2k__
+#include <iostream>
+#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