处理缺页错误后的指令指针值 [英] Instruction pointer value after the page fault trap has been handled

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

问题描述

老实说,我真的对这个与虚拟内存相关的特定概念感到困惑.

Honestly, I am really confused with this particular virtual memory related concept.

Q1) 发生页错误时,处理器是否先完成当前指令的执行,然后将 IP 寄存器内容(下一条指令的地址)移到堆栈中?或者,它中止当前正在执行的指令并将指令指针寄存器的内容移到堆栈中?

Q1) When a page fault occurs, does the processor first finishes the execution of the current instruction and then moves the IP register contents (address of next instruction) to the stack? Or, it aborts current instruction being executed and moves the contents of instruction pointer register to stack?

Q2) 如果第二种情况为真,那么它如何恢复被中止的指令,因为当它恢复时,堆栈包含指令指针值,该值只是下一条指令的地址.所以它永远不会恢复发生页面错误的指令.

Q2) If the second case is true, then how does it resume the instruction which was aborted because when if it resumes, the stack contains the instruction pointer value which is nothing but the address of the next instruction. So it will never resume the instruction where the page fault occurred.

我的想法
我认为第二种情况听起来不对.当我阅读 Silbershatz 和 Galvin 的《操作系统原理》时发生了混乱.因为他们写了

What I think
I think the second case sounds wrong. The confusion occurred while i was reading Operating System Principles by Silbershatz and Galvin. In that they have written

当页面错误发生时,我们将不得不引入所需的页面,纠正页表并重新启动指令.

when a page fault occurs, we will have to bring in the desired page, correct page table and restart the instruction.

但是指令指针总是指向下一条指令的地址,所以这意味着,根据本书试图传达的内容,我们递减IP的值只是为了重新执行发生缺页错误的指令?

But the instruction pointer always points to the address of the next instruction so it means, according to what this book is trying to convey, we are decrementing the value of IP just to restart the execution of the instruction where the page fault occurred?

推荐答案

在英特尔系统编程指南的第 6.5 章中,它说

In the Intel System Programming guide, chapter 6.5, it says

故障——故障是一种异常,通常可以纠正,一旦纠正,程序就可以在不失去连续性的情况下重新启动.当上报故障时,处理器将机器状态恢复为错误指令开始执行之前的状态.返回地址(保存的内容CS 和 EIP 寄存器)用于故障处理程序指向故障指令,而不是指令按照故障说明进行操作.

Faults — A fault is an exception that can generally be corrected and that, once corrected, allows the program to be restarted with no loss of continuity. When a fault is reported, the processor restores the machine state to the state prior to the beginning of execution of the faulting instruction. The return address (saved contents of the CS and EIP registers) for the fault handler points to the faulting instruction, rather than to the instruction following the faulting instruction.

页面错误被归类为错误(这并不奇怪),因此当页面错误发生时,您处于它发生之前"的状态 - 不是真的,因为您处于错误处理程序中(所以EIP 和 ESP 绝对不同,CR2 也包含地址),但是当您返回时,它将是发生之前的状态,只有处理程序进行了更改(因此,将页面放在那里,或终止进程)

A page fault is classified as a fault (no surprises there), so when a page fault happened you're in the state "before it ever happened" - well not really, because you're in the fault handler (so EIP and ESP are definitely different, also CR2 contains the address), but when you return it'll be the state before the ever happened, only with changes made by the handler (so, put there page there, or kill the process)

这篇关于处理缺页错误后的指令指针值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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