当启动系统调用时,用户模式的ss和esp是如何保存的,例如在linux中?

发布于 2024-10-12 11:18:48 字数 189 浏览 4 评论 0原文

我知道用户模式 ​​ss/esp 应该保存到内核模式堆栈中以供以后恢复。

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

用户态的ss和esp是否保存在一些临时的地方?或者x86电路支持该操作?

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

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?

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

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

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

发布评论

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

评论(1

清秋悲枫 2024-10-19 11:18:48

想想指令指针会发生什么。显然,那里一定有一些硬件支持。

抛开现代的“快速系统调用”技术(我稍后会讨论这一点),请注意,系统调用是通过发出特定的软件中断以及适当设置的某些处理器寄存器来请求的。那么接下来发生的事情取决于处理器中的中断硬件。

当中断发生时,处理器会自动将各种寄存器和其他信息(例如指令指针,以及甚至在处理程序有机会保存它们之前就可以修改的其他内容)推送到内核堆栈上。此外,如果处理器当前处于内核模式,它将堆栈指针和堆栈段寄存器推送到内核堆栈并转换到内核模式,执行中断处理程序。

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

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.

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.

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