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 03:21:15


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

> I'm not familiar with the asm enough, but can't you adjust the sp in the
> asm so that in user code it always has to be the lowest position?
>

no idea what you want - fcontext_t is a pointer containing the address of
the lowest address of the stack - but it is not the stack point position
if the context is resumed

> So how would you modify them to support both upward and downward stack?
> preprocessor branch? runtime check?
>

preprocessor - because it is determined at compile time

> My prevoius question stays unanswered, so let me repeat here:
> what does "beginning of the stack" really means?
> Suppose we have a stack of size 3, starting at [s]:
>
> [s-1][s][s+1][s+2][s+3]
>
> Why the beginning of a downward stack is [s+3], not [s+2]?
> If it's a upward stack, is beginning [s] or [s-1]?
>

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.



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