2 * Copyright 2016 Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <boost/context/all.hpp>
19 #include <boost/version.hpp>
22 * Wrappers for different versions of boost::context library
23 * API reference for different versions
25 * http://www.boost.org/doc/libs/1_51_0/libs/context/doc/html/context/context/boost_fcontext.html
27 * http://www.boost.org/doc/libs/1_52_0/libs/context/doc/html/context/context/boost_fcontext.html
29 * http://www.boost.org/doc/libs/1_56_0/libs/context/doc/html/context/context/boost_fcontext.html
37 #if BOOST_VERSION >= 105200
38 using ContextStruct = boost::context::fcontext_t;
40 using ContextStruct = boost::ctx::fcontext_t;
43 void* stackLimit() const {
47 void* stackBase() const {
55 #if BOOST_VERSION >= 105600
56 ContextStruct context_;
57 #elif BOOST_VERSION >= 105200
58 ContextStruct* context_;
60 ContextStruct context_;
64 jumpContext(FContext* oldC, FContext::ContextStruct* newC, intptr_t p);
66 jumpContext(FContext::ContextStruct* oldC, FContext* newC, intptr_t p);
68 makeContext(void* stackLimit, size_t stackSize, void (*fn)(intptr_t));
72 jumpContext(FContext* oldC, FContext::ContextStruct* newC, intptr_t p) {
73 #if BOOST_VERSION >= 105600
74 return boost::context::jump_fcontext(&oldC->context_, *newC, p);
75 #elif BOOST_VERSION >= 105200
76 return boost::context::jump_fcontext(oldC->context_, newC, p);
78 return jump_fcontext(&oldC->context_, newC, p);
83 jumpContext(FContext::ContextStruct* oldC, FContext* newC, intptr_t p) {
84 #if BOOST_VERSION >= 105200
85 return boost::context::jump_fcontext(oldC, newC->context_, p);
87 return jump_fcontext(oldC, &newC->context_, p);
92 makeContext(void* stackLimit, size_t stackSize, void (*fn)(intptr_t)) {
94 res.stackLimit_ = stackLimit;
95 res.stackBase_ = static_cast<unsigned char*>(stackLimit) + stackSize;
97 #if BOOST_VERSION >= 105200
98 res.context_ = boost::context::make_fcontext(res.stackBase_, stackSize, fn);
100 res.context_.fc_stack.limit = stackLimit;
101 res.context_.fc_stack.base = res.stackBase_;
102 make_fcontext(&res.context_, fn);