“从用户模式切换到内核模式"是一个不正确的概念 [英] "Switching from user mode to kernel mode" is an incorrect concept

查看:288
本文介绍了“从用户模式切换到内核模式"是一个不正确的概念的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是第一次学习操作系统".在我的书中,我发现了有关用户模式"和内核模式"的句子:

Im studying for the first time "Operating System". In my book i found this sentence about "User Mode" and "Kernel Mode":

从用户模式切换到内核模式"指令仅在内核中执行 模式

"Switch from user to kernel mode" instruction is executed only in kernel mode

我认为这是一个错误的句子,因为实际上没有内核切换".实际上,当用户进程需要执行特权指令时,它只是要求内核为自己做一些事情.是对的吗?

I think that is a incorrect sentence as in practice there is no "switch of kernel". In fact, when a user process need to do a privileged instruction it simply ask the kernel to do something for itself. Is it correct ?

推荐答案

实际上,当用户进程需要执行特权指令时,它只是要求内核为自己做一些事情.

In fact, when a user process need to do a privileged instruction it simply ask the kernel to do something for itself.

但是那是怎么发生的呢?详细信息包括处理器(即指令集架构)和与您的系统相关的ABI 规范,例如此处),但通常涉及到机器代码指令,例如 SYSCALL (或 SVC 大型机) 更改 CPU模式(即以受控转换为内核模式).系统调用的实际参数(甚至包括系统调用号)通常在寄存器中传递(但详细信息是特定于ABI的.)

But how does that happen? Details are processor (i.e. instruction set architecture) and OS specific (explained in ABI specifications relevant to your system, e.g. here), but that usually involves some machine code instruction like SYSENTER or SYSCALL (or SVC on mainframes) capable of atomically changing the CPU mode (that is switching it in a controlled manner to kernel mode). The actual parameters of the system call (including even the syscall number) are often passed in registers (but details are ABI specific).

因此,我认为从用户模式切换到内核模式的概念是相关且有意义的(如此正确").

So I feel the concept of switching from user-mode to kernel-mode is relevant, and meaningful (so "correct").

顺便说一句,硬件禁止用户模式代码执行特权机器指令,例如那些与IO硬件设备进行交互的机器指令(有关例外(有点类似于

BTW, user-mode code is forbidden (by the hardware) to execute privileged machine instructions, such as those interacting with IO hardware devices (read about protection rings). If you try, you get some hardware exception (a bit similar to interrupts). Hence your code (even if it is malicious) has to make system calls, which the kernel controls (it has lots of code related to permission checking), for e.g. all IO.

还请阅读 操作系统:三件简单的书 -可免费下载.另请参见 http://osdev.org/.阅读系统调用 Wikipage& syscalls(2)

Read also Operating Systems: Three Easy Pieces - freely downloadable. See also http://osdev.org/. Read system call wikipage & syscalls(2), and the Assembler HowTo.

在现实生活中,事情要复杂得多.阅读有关系统管理模式以及(吓人的)

In real life, things are much more complex. Read about System Management Mode and about the (scary) Intel Management Engine.

这篇关于“从用户模式切换到内核模式"是一个不正确的概念的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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