'STACK' of ELF executable in Memory

Programming, for all ages and all languages.
Post Reply
okaox
Posts: 6
Joined: Thu Sep 24, 2009 12:59 pm

'STACK' of ELF executable in Memory

Post 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
Last edited by okaox on Sat Nov 21, 2009 10:18 am, edited 1 time in total.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: 'STACK' of ELF executable Image

Post 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
okaox
Posts: 6
Joined: Thu Sep 24, 2009 12:59 pm

Re: 'STACK' of ELF executable in Memory

Post by okaox »

Ok Adam.

Thanks
Sebas
Post Reply