[OSTEP chapter 6] Mechanism: Limited Direct Execution

操作系统通过time sharing 的方式来虚拟化CPU 要做到以下两点:
基本解决方案:Limited Direct Execution  这个方案带来了两个问题
The first :
if we just run a program, how can the OS make sure the program doesn’t do anything that we don’t want it to do, while still running it efficiently?
The second:
when we are running a process, how does the operating system stop it from running and switch to another process, thus implementing the time sharing we require to virtualize the CPU
problem #1 : Restricted Operations 严格控制操作
user mode 限制进程能访问操作到的资源
kernel model 能像操作系统一样访问所有资源
通过操作系统的 user mode 和 kernel mode  以及两者之间的转换指令[特殊的 return-from-trap 指令]来控制进程的执行
但是允许程序在内核模式到处跳转是一个Very Bad Idea, 为了直接这一点内核在启动boot time 的时候用建立一个trap table.
系统在启动的时候就会配置好硬件,告诉硬件什么时候执行什么代码,而且会告诉硬件trap instruction 的句柄 handle
Problem #2 Switching Between Process 进程间的切换
A Cooperation Approach : Wait For System Calls
一个合作的方式: OS 信任application,application会自己调用system call 或者 自己产生了一个错误异常调用一个trap 把从职权交回OS
A Non-Cooperation Approach : The OS Take Control
如果碰到拒绝交出控制权的process ,  可以通过  time interrupt 【硬件级别支持】 来使 OS 重新获取控制权;每隔一段时间就产生一个中断  ,系统中预设好的interrupt handler 会运行,这个handler 拿回控制权然后会决定是不是接着运行之前的process ; timer 的硬件要保存中断时候的上下文环境。
Just run the program you want to run on the CPU ,but first make sure to set up the hardware so to limit what the process can do without OS assistance

Published by

Leave a Reply

Your email address will not be published. Required fields are marked *