Boost logo

Boost :

Subject: [boost] boost.context cause strange crash on certan WIN32 API
From: microcai (microcai_at_[hidden])
Date: 2014-11-28 09:15:23


Hi, I was using Boost.Asio.Spawn happliy until I ported my project to windows.

I got stange openssl crash. many debug days speeded and there was nothing
wrong with openssl.

Strange thing is, openssl didn't crash when used in normal code, unless I used
them in asio stackful coroutine.

Now I finnally find the root cause and make it 100% reproducible.

here is the code that demostrade the crash:

<code>

boost::context::fcontext_t fcm,fc1;

void f1(intptr_t)
{
        HMODULE advapi = LoadLibrary(TEXT("advapi32")); // crash there
        FreeLibrary(advapi);
        boost::context::jump_fcontext(fc1, &fcm, 0);
}

std::thread([](){
        boost::context::guarded_stack_allocator alloc;
        std::size_t size(8192);
        void* sp1(std::malloc(size));

        fc1=boost::context::make_fcontext(sp1, size, f1);
        boost::context::jump_fcontext(&fcm, fc1, 0);
});

</code>

the context created in threads other that main thread, can't call certain
APIs. If LoadLibrary get called by an context that created in thread, it will
crash.

100% reproducible on WIN64 platform with MSVC2013.
And nothing wrong on WIN32 !


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