Skip to content

Instantly share code, notes, and snippets.

@jamboree
Created September 22, 2014 03:17
Show Gist options
  • Save jamboree/38bdd0af939bfbf6df8a to your computer and use it in GitHub Desktop.
Save jamboree/38bdd0af939bfbf6df8a to your computer and use it in GitHub Desktop.
#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