Created
September 22, 2014 03:17
-
-
Save jamboree/38bdd0af939bfbf6df8a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <boost/context/all.hpp> | |
bool is_upward() | |
{ | |
struct C | |
{ | |
boost::context::fcontext_t master; | |
char stack1[512], stack2[512]; | |
} c; | |
auto slave = boost::context::make_fcontext(c.stack2, 512, [](boost::intptr_t p) | |
{ | |
auto c = reinterpret_cast<C*>(p); | |
char s[32]; | |
boost::context::jump_fcontext(&c->master, c->master, c->stack2 < s); | |
}); | |
return boost::context::jump_fcontext(&c.master, slave, reinterpret_cast<boost::intptr_t>(&c)); | |
} | |
int main(int argc, char** argv) { | |
std::cout << is_upward(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment