启动系统调用时,如何保存用户模式的ss和esp,例如在Linux中? [英] When starting a system call, how are user-mode ss and esp saved, e.g. in linux?

查看:47
本文介绍了启动系统调用时,如何保存用户模式的ss和esp,例如在Linux中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道用户模式ss/esp应该保存到内核模式堆栈中,以便以后还原.

I know user-mode ss/esp should be saved into the kernel-mode stack for later restore.

问题是要定位内核模式堆栈,必须先将相应的内核模式值加载到ss/esp中.现在在我看来,用户模式ss/esp已被刷新.那么硬件/系统如何检索用户模式ss/esp?

The question is that to locate kernel-mode stack, ss/esp have to be loaded with the corresponding kernel-mode values first. Now it seems to me that user-mode ss/esp have been flushed. Then how does the hardware/system retrieve the user-mode ss/esp?

用户模式ss和esp是否保存在某些临时位置?还是该操作受x86电路支持?

Are user-mode ss and esp saved in some temporary places? Or the operation is supported by x86 circuit?

推荐答案

考虑指令指针会发生什么.显然,某处必须有一些硬件支持.

Think about what happens with the instruction pointer. Clearly there must be some hardware support in there somewhere.

抛开现代的快速系统调用"技术(稍后再讲),请注意,通过发出带有适当设置的某些处理器寄存器的特定软件中断,可以请求系统调用.因此,随后发生的事情取决于处理器中的中断硬件.

Putting aside modern "fast system call" techniques (I'll return to this later), note that a system call is requested by just issuing a specific software interrupt with certain processor registers set up appropriately. So what happens then is down to the interrupt hardware in the processor.

发生中断时,处理器会自动将各种寄存器和其他信息(例如指令指针之类的内容,以及即使在处理程序有机会保存它们之前也可能被修改的其他内容)推入内核堆栈.此外,如果处理器当前不是处于内核模式,则它将堆栈指针和堆栈段寄存器压入内核堆栈,并转换为内核模式,执行中断处理程序.

When an interrupt occurs, the processor automatically pushes various registers and other information (things like the instruction pointer, and other stuff that could be modified even before the handler gets a chance to save them) onto the kernel stack. Additionally, if the processor is currently not in kernel mode, it pushes the stack pointer and stack segment register onto the kernel stack and transitions to kernel mode, executing the interrupt handler.

现在,如果我们看快速系统调用"(SYSENTER指令),我们注意到它需要已经设置了一些机器状态寄存器,并且它不保存状态(这是使它比发出中断更快的原因之一.调用代码负责将内核执行系统调用所需的数据以及返回原始状态所需的数据放置在未注册的寄存器中.

Now if we look at "fast system calls" (the SYSENTER instruction), we note that it requires some machine state registers to be already set up, and it doesn't save state (this is part of what makes it faster than issuing an interrupt). The calling code is responsible for placing in the unclobbered registers the data that the kernel needs in order to execute the system call, and the data it needs to return to its original state.

这篇关于启动系统调用时,如何保存用户模式的ss和esp,例如在Linux中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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