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

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

问题描述

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

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天全站免登陆