可执行文件的装载与进程

<!-- /* Font Definitions */ @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:1; mso-generic-font-family:roman; mso-font-format:other; mso-font-pitch:variable; mso-font-signature:0 0 0 0 0 0;} @font-face {font-family:Calibri; panose-1:2 15 5 2 2 2 4 3 2 4; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:-1610611985 1073750139 0 0 159 0;} @font-face {font-family:"/@宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-unhide:no; mso-style-qformat:yes; mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:宋体; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi; mso-font-kerning:1.0pt;} p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph {mso-style-priority:34; mso-style-unhide:no; mso-style-qformat:yes; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; text-indent:21.0pt; mso-char-indent-count:2.0; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:宋体; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi; mso-font-kerning:1.0pt;} .MsoChpDefault {mso-style-type:export-only; mso-default-props:yes; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page WordSection1 {size:595.3pt 841.9pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:42.55pt; mso-footer-margin:49.6pt; mso-paper-source:0; layout-grid:15.6pt;} div.WordSection1 {page:WordSection1;} /* List Definitions */ @list l0 {mso-list-id:1510288653; mso-list-type:hybrid; mso-list-template-ids:1132376306 -277082912 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;} @list l0:level1 {mso-level-tab-stop:none; mso-level-number-position:left; margin-left:18.0pt; text-indent:-18.0pt;} ol {margin-bottom:0cm;} ul {margin-bottom:0cm;} -->

进程虚拟地址空间:

每个程序被运行起来以后,它都将拥有自己独立的虚拟地址空间。按照 32 位系统,虚拟地址可以从 0x00000000~0xffffffff, 一般 linux 操作系统会占用 1G 的虚拟空间(从 0XC0000000 开始) ,windows 占用 2G

Intel 的地址扩张方式,把硬件地址线 32 位扩充到 36 位,叫做 PAE

利用虚拟内存的一段地址空间 比如说 256M 大小的虚拟地址空间,来作为窗口,可与用大于 4G 的实际物理空间中申请多个 256M 大小的空间。

装载方式:

覆盖装入与页映射。

覆盖装入:就是把不依赖的几个模块公用一段虚拟内存空间,需要某个模块的时候才把它加入这段内存空间上,覆盖装入有些约束条件。

现在都用的是页映射,把真实的物理地址分页,自己执行的程序也分页,然后根据程序运行时是有局部性的原理,就是动态装入的原理进行程序页与真实物理地址的映射。

进程的建立:

1.       创建一个独立的虚拟地址空间

2.       读取可执行文件头,并且建立虚拟空间与可执行文件的映射关系。

3.       CPU 的指令寄存器设置成可执行文件的入口地址,启动从运行。

2 步就是可执行装载的关键:

页错误:

CPU 将控制权交给操作系统,操作系有专门的页促无处理例程来处理这种情况。这时候我们前面提到的装载过程的第 2 步建立的数据结构起到很关键的作用,操作系统将查询这个数据结构,然后找到空页面所在的 VMA ,计算出相应的页面在可执行文件中的偏移,然后在物理内存分配一个物理页面,将进程中该虚拟页与分配的物理页之间建立映射关系,然后把控制权再还给进程。

 

对于可执行文件,相同权限的段,将它们合并到一起当作一个段进行页的映射。

在虚拟地址空间里面有 2 个匿名虚拟地址区域 (Anonymous Virtual Memory Area), 分别是 heap stack ,这下大家知道了我们平时说的在 stack 分配和 heap 分配在哪里了吧。

 

然后就是关于段对齐的知识,大家有兴趣可以 google 下。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值