Page 1 of 1

Where should my stack segment be located and how large shoul

Posted: Sun Aug 31, 2003 2:42 am
by Freanan
I read a tutorial that just uses a code and a data segment with the same size and location and place the stack in the data segment.

But i also read that there is the possibility to have special stack segments. I'd preffer to use that, but i don't know how large to make it and were to locate it.
I think it would be good to use data and code segment as described above, but make them smaller and put the stack in the remaining space(?)
But still i don't know how large to make my code/data space and where to put the stack then.. ???

Re:Where should my stack segment be located and how large sh

Posted: Sun Aug 31, 2003 9:38 am
by Freanan
I just set up my gdt this way(granularity bit is set, so sizes are in pages):
Code and Data Segments(sharing the same space):
Offset: 0, Size: FFFF0h
Stack Segment:
Offset: FFFF0h, Size:Fh

-It works, but i don't know if it is good that way...
please give me advice! I have no idea how large a stack should be to provide enough space.

Re:Where should my stack segment be located and how large sh

Posted: Sun Aug 31, 2003 9:39 am
by Pype.Clicker
well, the usual Unix (posix?) design is:

- decide how much space a user-level application will be allowed to use. Most of the time, it is 3GB.
- once you know what's the size of the .text and static .data's section, the rest is to be shared between heap (malloc/free) and stack.
- have your stack starting at the highest address available for the app and going down, while the Heap will grow in the other dimension.

Oh, maybe you were worrying for kernelstacks ? Its size will basically depend of the longest system call that can be involved and its location just doesn't care (well, i know, this doesn't help much). However, placing it in a memory location that belong to a specific process will reduce the stress of system-wide virtual memory demand.