分段错误与页面错误

发布于 2024-11-27 19:00:58 字数 206 浏览 2 评论 0原文

  1. 我想知道它们之间有什么区别和联系 分段错误和页面错误?

  2. 分段错误只属于分段内存模型吗?

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

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

谢谢和问候!

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

  2. Does segmentation fault only belong to segmented memory model?

    Does page fault only belong to paged memory model?

    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?

Thanks and regards!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

罪#恶を代价 2024-12-04 19:00:58

实际上,这两件事非常不同。 分段错误意味着程序试图访问无效或非法的内存地址:例如,0或大于任何有效指针的值。 页面错误是指指针试图访问当前未映射到物理内存的地址空间页面,因此 MMU 需要先将其从磁盘上抓取下来才能使用。前者是非法条件,程序一般会被中止;后者是完全正常的,程序甚至不会知道它。

“分段”与早期 x86 处理器使用的旧“分段内存模型”完全无关。这是早期的用法,仅指内存的一部分或

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.

"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.

智商已欠费 2024-12-04 19:00:58

当内存不允许被访问(不存在或被禁止)时,就会出现分段错误。当您取消引用空变量或超出数组末尾时,最常见的情况是发生这种情况。当访问已映射但未加载的内存时,会发生页面错误。它们不是错误,而是向操作系统发出信号,指示它应该将适当的页面加载到内存中。

Segmentation faults occur when the memory is not allowed to be accessed (does not exist, or is forbidden). Most frequently they occur when you dereference a null variable or run off the end of an array. Page faults occur when memory that is mapped but not loaded is accessed. They are not errors, and signal to the operating system that it should load the appropriate page into memory.

人事已非 2024-12-04 19:00:58

为了方便后代,这里有一个来自加州大学伯克利分校操作系统课程的视频讲座,讨论了这一点。
https://www.youtube.com/watch?v=IBgkKX6DUTM&t= 3345s

Tl;dr 以上答案(基本上)。但值得一提的是,这个术语确实来自旧式地址转换,其中 MMU 包含段表而不是页表。

For posterity, here's a video lecture from UC Berkeley's OS course discussing this.
https://www.youtube.com/watch?v=IBgkKX6DUTM&t=3345s

Tl;dr above answers (basically). But worth mentioning that the term does come from older style address translation where MMU's contained segment tables instead of page tables.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文