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:12:03


2014-09-19 15:21 GMT+08:00 Oliver Kowalke <oliver.kowalke_at_[hidden]>:

> 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
>

To be clear, I was talking about `make_fcontext(void* sp,std::size_t
size,void(*fn)(intptr_t))`.

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? Or are those asms independent of how the stack grows?

If the asm knows how the stack grows, you can offset the `sp` internally,
leave it transparent to the user.

> 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.
>

So how about upward stack, is it x or (x-1)?

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