Boost logo

Boost Users :

Subject: Re: [Boost-users] [context] How to set stack pointer in a platform-independent way?
From: Oliver Kowalke (oliver.kowalke_at_[hidden])
Date: 2014-09-19 04:19:35


2014-09-19 10:12 GMT+02:00 TONGARI J <tongari95_at_[hidden]>:

> 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



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