http://blog.csdn.net/bettermanlu/article/details/5571663
[windows_internals]Memory Layout (Virtual address space of a C process) under Linux OS
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)
- {
- int a;
- int b[3];
- /* no other auto variable */
- ...
- }
- void main()
- {
- ...
- func(72,73);
- ...
- }
memory layout is as below. I will talk about the stack in the next session.
The diagram below shows the memory layout of a typical C’s process. The process load segments (corresponding to " text " and " data " in the diagram) 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 into 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. The 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/memorylayout.pdf
http://www.tenouk.com/Bufferoverflowc/Bufferoverflow1c.html