为什么syscall需要切换到内核模式?
我正在学习我的操作系统期末考试,想知道是否有人可以告诉我为什么操作系统需要切换到系统调用的内核模式?
I'm studying for my operating systems final and was wondering if someone could tell me why the OS needs to switch into kernel mode for syscalls?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
系统调用专门用于在内核模式下运行操作,因为出于安全原因不允许通常的用户代码执行此操作。
例如,如果您想分配内存,操作系统有权执行此操作(因为它知道页表并允许访问其他进程的内存),但作为用户程序,不应允许您查看或破坏其他进程的内存。
这是一种对你进行沙箱处理的方式。 因此,您发送一个系统调用,请求操作系统分配内存,这发生在内核级别。
编辑:我现在看到维基百科文章对此非常有用
A syscall is used specifically to run an operating in the kernel mode since the usual user code is not allowed to do this for security reasons.
For example, if you wanted to allocate memory, the operating system is privileged to do it (since it knows the page tables and is allowed to access memory of other processes), but you as a user program should not be allowed to peek or ruin the memory of other processes.
It's a way of sandboxing you. So you send a syscall requesting the operating system to allocate memory, and that happens at the kernel level.
Edit: I see now that the Wikipedia article is surprisingly useful on this
由于这被标记为“家庭作业”,所以我不会只是给出答案,而是会提供一个提示:
内核负责访问计算机的硬件并确保应用程序不会互相干扰。 如果任何应用程序无需内核的配合就可以访问硬件设备(例如硬盘),会发生什么情况?
Since this is tagged "homework", I won't just give the answer away but will provide a hint:
The kernel is responsible for accessing the hardware of the computer and ensuring that applications don't step on one another. What would happen if any application could access a hardware device (say, the hard drive) without the cooperation of the kernel?