Boost logo

Boost :

Subject: Re: [boost] [context] make_fcontext stack pointer unclear from documentation
From: Michael Marcin (mike.marcin_at_[hidden])
Date: 2013-05-25 15:55:02

On 5/25/13 6:03 AM, Oliver Kowalke wrote:
> 2013/5/25 Michael Marcin <mike.marcin_at_[hidden]>
>> The function make_fcontext takes a stack pointer. However it is not clear
>> at all from the documentation that the stack pointer should actually point
>> to the end of the stack buffer.
> hmm - itis architecture depended in which direction the stack grows. The
> current supported architectures use downward growing stacks.
> The documentation contains [1]:
> 'Note: Depending on the architecture *StackAllocator* returns an address
> from the top of the stack (grows downwards) or the bottom of the stack
> (grows upwards). '
>> [1]

It's still not clear at all to me after reading that note. And that note
is far removed from the documentation of make_fcontex which is where
this matters. Additionally I have to now know how the architecture
handles stack growth. Shouldn't the library be handling that?

If it's architectures dependent why can't make_fcontext abstract the
details as it does for other architecture dependent functionality. It
has all the information necessary to determine if it should offset the
stack buffer pointer by the stack size.

So instead of:

void* stackBuffer = std::calloc(stackSize, sizeof(char));
make_fcontext(static_cast<char*>(stackBuffer)+stackSize, stackSize, f);
make_fcontext(stackBuffer, stackSize, f);

You could just always write:
void* stackBuffer = std::calloc(stackSize, sizeof(char));
make_fcontext(stackBuffer, stackSize, f);

Boost list run by bdawes at, gregod at, cpdaniel at, john at