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

來源:互聯網
上載者:User

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(72,73);<br /> ...<br />}

 

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.