2014-09-19 15:21 GMT+08:00 Oliver Kowalke
2014-09-19 8:53 GMT+02:00 TONGARI J
: 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.