操作系统内部到底发生什么导致分段错误 [英] What exactly happens inside the OS to cause the segmentation fault

查看:119
本文介绍了操作系统内部到底发生什么导致分段错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了很多有关虚拟地址和页面调度的信息. 首先让我告诉大家我的理解.当进程想要执行某些操作时,它将尝试将数据从硬盘加载到内存中.为此,它使用虚拟地址.因此,我们的MMU会验证虚拟地址是否在TLB中查找到相应的物理页面,如果找不到,则将其查询到反向页面表",最后在没有找到条目的情况下,将查询页面表".它会产生页面错误,并且所有页面交换都已完成,所有表都将被更新. 在我阅读时,所有进程都具有不同的页表和相同的虚拟地址.因此,如果我尝试访问定义为int a [100]的数组元素a [1000],我肯定会遇到分段错误,原因是该指令可能试图访问不属于它的内存.但是OS如何仅通过使用虚拟地址和物理页面的概念就知道a [1000]不属于正在运行的进程.我是否在这里缺少某些东西,或者我的整体理解是错误的?

I have read a lot about the virtual address and paging. Let me first tell you people what i understood. When a process wants to execute something it tries to load the data from the hard disk to memory. To do this it uses a virtual address. So our MMU validates the virtual address looks into the TLB to find the corresponding physical page, if it doesn't find there it looks into Inverted Page Table and at the end it looks into Page table if it doesn't find an entry over there it generates a page fault and all the swapping of page is done and all the tables will be updated. And as I read all the processes have different page tables and same virtual address. so if I try access an array element a[1000] which was defined as int a[100] I am sure that am gonna get a segmentation fault cause that instruction might be trying to access a memory that doesn't belong to it. but how OS comes to know that a[1000] doesn't belong to the running process by just using the concept of virtual address and physical pages. Am I missing something here or my entire understanding is wrong?

我知道我们可以说,如果进程试图访问只读或超真实内存段,则内存访问是非法的.

I know we can say a memory access is illegal if a process is trying to access a read only or sup true memory segment.

最后,沸腾的问题是OS如何确定将哪个内存分配给哪个进程以及如何确定这种对内存的访问是非法的.

at the end the boiling question is how OS decides which memory is allocated to which process and how it decides that this access of memory is illegal.

什么是Linux上的分段错误?

此链接没有太大帮助.

非常感谢您可爱的人们的投入:)

thanks a lot in advance for all you lovely people's inputs :)

推荐答案

在x86上,Linux使用分段和分页的组合,因此程序生成的地址首先查找相应的分段基址和限制寄存器值.这给出了虚拟地址,然后使用页表进行翻译.当您尝试访问尚未分配的内存时,访问的页面超出了限制寄存器所允许的范围,因此会产生分段错误.

On x86, linux uses a combination of segmentation and paging, so the address generated by program first looks up for the corresponding segments base and limit registers values. This gives the virtual address which is then translated using the page table. When you try to access a memory which has not been allocated, the accessed page is beyond what the limit register allows, hence generating a segmentation fault.

这篇关于操作系统内部到底发生什么导致分段错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆