2014-09-19 14:10 GMT+08:00 Oliver Kowalke <oliver.kowalke@gmail.com>:
But it's still not clear how to set the stack pointer portably, even after examining the code of Boost.Coroutine. For now, Boost.Context only supports downward stack, and Boost.Coroutine, which happened to be written by the same author, just assumes that the stack always grows downward, which is not really a portable implementation, if future Boost.Context

boost.context is implemented for specific architectures/platforms, e.g. it does not contain generic code which will work in general.
that said -  you can not have a 'portable' implementation.
an architecture/platform determines in which direction the stack grows - at the moment all architectures/platforms supported by boost.context have
downward growing stack.

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?

supports upward stack, Boost.Coroutine has to be changed as well.

yes, if in the future an architecture/platform with upward growing stack will be supported, the stack allocator classes have to be modified

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

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


Thanks.