I found a good example to demostrate the memory layout and its stack info of a user-mode process, only that this example is for Linux. But it is still worth taking a look at it.
C source file is quite simple:
Void func (int x, int y) <br/>{< br/> int A; <br/> int B [3]; <br/>/* No other auto variable */<br/>... <br/>}< br/> void main () <br/>{< br/>... <br/> func (); <br/>... <br/>}
Memory layout is as below. I will talk about the stack in the next session.
The dimo-below shows the memory layout
A typical
C's process. The process load segments (corresponding"
Text
"And"
Data
"
At the process's base address. The main stack is located
Just
Below and grows downwards. Any additional threads that are created will
Have
Their own stacks, located below the main stack. Each of the stack Frames
Is
Separated by a guard page to detect stack overflows among stacks frame.
The
Heap is located above the process and grows upwards.
In the middle of the process's address
Space, there
Is a region is reserved for shared objects. When a new process is
Created,
The Process Manager first maps the two segments from the executable
Memory.
It then decodes the program's elf header. If the program Header
Indicates that
The executable was linked against a shared library, the Process Manager
Will
Extract the name of the dynamic interpreter from the program header.
Dynamic
Interpreter points to a shared library that contains the runtime linker
Code.
The Process Manager will load this shared library in memory and will
Then pass
Control to the runtime linker code in this library.
Ref:
Http://www.cs.uleth.ca /~ Holzmann/C/system/memorylayouttasks
Http://www.tenouk.com/Bufferoverflowc/Bufferoverflow1c.html