Page 1 of 1

'STACK' of ELF executable in Memory

Posted: Sat Nov 21, 2009 12:40 am
by okaox
To load the image of ELF executable in memory need:
.Text + . Data + . Bss. This is already.
Now. How do I know the STACK size it need? It dynamically assigns an? What size is recommended?

thanks for the reply

cheers

Re: 'STACK' of ELF executable Image

Posted: Sat Nov 21, 2009 3:01 am
by AJ
Hi,

For third party user processes, unfortunately that's an unknown. One of the common ways to deal with this seems to be to set up a small initial stack with an unmapped "guard page" close to the top of your process space. Every time there is a page fault in the guard page, you extend the stack (until the point where the guard page hits the heap or some predetermined value). Note that if you do this for a ring 0 process, you'll need to handle your PFE by using either an IST (64 bit) or task gate (32 bit) to provide the required stack switching.

If you are deciding this for a kernel image, you should be able to pretty much guess how much you need. Are you in pure ASM, making little use of recursion? If so, you need a pretty small stack (maybe only a page or two). Are you in C++ returning large objects on the stack and using recursion in your VFS? If so, a few MiB could easily be required.

Cheers,
Adam

Re: 'STACK' of ELF executable in Memory

Posted: Sun Nov 22, 2009 12:20 pm
by okaox
Ok Adam.

Thanks
Sebas