2014-09-19 10:12 GMT+02:00 TONGARI J
Currently `sp` requires the user to know the whether stack grows downwards or upwards, but for a specific architecture/platform, you have to write an asm for it, and you know how the stack grows on this architecture/platform, don't you?
yes, but at the moment for all supported platforms the stack grows downward
Or are those asms independent of how the stack grows?
no
If the asm knows how the stack grows, you can offset the `sp` internally, leave it transparent to the user.
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.
stackallocator using malloc():
void * limit = std::malloc( size); if ( ! limit) throw std::bad_alloc(); ctx.size = size; ctx.sp = static_cast< char * >( limit) + ctx.size;
if limit is at x and you allocated 64byte of memory for the stack you have to adjust your stack base for downward growing stacks to address y=x+64, e.g. starting at y your stack has 64bytes to grow.
So how about upward stack, is it x or (x-1)?
of course x for upward growing stacks x is the lowest address of your stack and y is the highest address of your stack