Boost logo

Boost :

Subject: [boost] [context] Linux x64 / printf
From: Daniel Larimer (dlarimer_at_[hidden])
Date: 2012-09-10 22:00:47


I modified the 'jump.cpp' example and added the line marked CRASH in f1()

#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>

#include <boost/assert.hpp>
#include <boost/context/all.hpp>

namespace ctx = boost::ctx;

ctx::fcontext_t fcm, fc1, fc2;

void f1( intptr_t)
{
        std::cout<<"hello "<<0; // WORKS
        printf( "hello %d", 0 ); // <<< CRASH
        std::cout << "f1: entered" << std::endl;
        std::cout << "f1: call jump_fcontext( & fc1, & fc2, 0)" << std::endl;
        ctx::jump_fcontext( & fc1, & fc2, 0);
        std::cout << "f1: return" << std::endl;
        ctx::jump_fcontext( & fc1, & fcm, 0);
}

void f2( intptr_t)
{
        std::cout << "f2: entered" << std::endl;
        std::cout << "f2: call jump_fcontext( & fc2, & fc1, 0)" << std::endl;
        ctx::jump_fcontext( & fc2, & fc1, 0);
        BOOST_ASSERT( false && ! "f2: never returns");
}

int main( int argc, char * argv[])
{
        ctx::stack_allocator alloc1, alloc2;

        fc1.fc_stack.base = alloc1.allocate(ctx::minimum_stacksize());
        fc1.fc_stack.limit =
            static_cast< char * >( fc1.fc_stack.base) - ctx::minimum_stacksize();
                ctx::make_fcontext( & fc1, f1);

        fc2.fc_stack.base = alloc2.allocate(ctx::minimum_stacksize());
        fc2.fc_stack.limit =
            static_cast< char * >( fc2.fc_stack.base) - ctx::minimum_stacksize();
                ctx::make_fcontext( & fc2, f2);

                std::cout << "main: call start_fcontext( & fcm, & fc1, 0)" << std::endl;
                ctx::jump_fcontext( & fcm, & fc1, 0);

                std::cout << "main: done" << std::endl;

        return EXIT_SUCCESS;
}


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk