分段错误与页面错误 [英] segmentation fault vs page fault

查看:101
本文介绍了分段错误与页面错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  1. 我想知道两者之间有什么区别和关系 分段错误和页面错误?

  1. I was wondering what differences and relations are between segmentation fault and page fault?

分段错误仅属于分段存储器模型吗?

Does segmentation fault only belong to segmented memory model?

页面错误仅属于页面内存模型吗?

Does page fault only belong to paged memory model?

如果都是,则由于大多数计算机系统(例如x86和Linux)使用分页内存模型而不是分段内存模型,为什么GCC C编译器有时会报告分段错误错误?

If both are yes, since most computer systems such as x86 and Linux use paged memory model instead of segmented memory model, why does GCC C compiler sometimes report segmentation fault error?

感谢和问候!

推荐答案

实际上,这两件事是非常不同的. segmentation fault 是指程序试图访问无效或非法的内存地址,例如0或大于任何有效指针的值. 页面错误是指指针试图访问当前未映射到物理内存的地址空间页面,因此MMU需要先将其从磁盘上夺走,然后才能使用.前者是非法情况,该程序通常将被中止;后者是完全正常的,程序甚至不知道它.

These two things are very dissimilar, actually. A segmentation fault means a program tried to access an invalid or illegal memory address: for example, 0, or a value larger than any valid pointer. A page fault is when a pointer tries to access a page of address space that's currently not mapped onto physical memory, so that the MMU needs to grab it off of disk before it can be used. The former is an illegal condition and the program will generally be aborted; the latter is perfectly normal and the program won't even know about it.

分段"与早期x86处理器所使用的旧分段内存模型"完全无关.这是一种较早的用法,仅指内存的一部分或.

"Segmentation" isn't at all related to the old "segmented memory model" used by early x86 processors; it's an earlier use which just refers to a portion or segment of memory.

这篇关于分段错误与页面错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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