Boost logo

Boost Users :

Subject: Re: [Boost-users] [context] How to set stack pointer in a platform-independent way?
From: TONGARI J (tongari95_at_[hidden])
Date: 2014-09-19 04:42:39


2014-09-19 16:19 GMT+08:00 Oliver Kowalke <oliver.kowalke_at_[hidden]>:
>
> boost.context is low level and the design decision was that higher level
> libraries using boost.context have to take care about the stack, e.g.
> boost.context is not responsible for allocating/deallocating the stack.
>

I know boost.context is low level, and I don't expect it to alloc/dealloc
the stack, what I proposed is:

```c++
fcontext_t BOOST_CONTEXT_CALLDECL make_fcontext_portable(void* sp,
std::size_t size, void (*fn)(intptr_t))
{
#if STACK_GROWS_UPWARD
    return make_fcontext(sp, size, fn);
#else
    return make_fcontext(sp + size, size, fn);
}
...
char stack[1024];
// works for both downward/upward stacks
auto ctx = make_fcontext_portable(stack, 1024, f);
```

Does that make sense?

Is it possible to embed the logic in asm so you don't have to use
preprocessor condition at all?

Thanks.



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net