[windows_internals]Memory Layout (Virtual address space of a C process) under Linux OS

11 篇文章 0 订阅
6 篇文章 0 订阅

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:

[cpp]  view plain copy
  1. void func(int x, int y)  
  2. {  
  3.    int a;  
  4.    int b[3];  
  5.    /* no other auto variable */  
  6.   ...  
  7. }  
  8. void main()  
  9. {  
  10.     ...  
  11.     func(72,73);  
  12.     ...  
  13. }  

 

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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值