Information Technology Reference
In-Depth Information
Exceptions and virtualization
Exceptions are a particularly powerful tool for virtualization — the emulation of hard-
ware that does not actually exist. As one example, it is common for different versions of
a processor architecture family to support some parts of the instruction set and not oth-
ers, such as when an inexpensive low power processor does not support floating point
operations. At some cost in performance, the operating system can use exceptions to
make the difference completely transparent to the user process. When the program
issues a floating point instruction, an exception is raised, trapping into the operating
system kernel. Instead of halting the process, the operating system can emulate the
missing instruction, and on completion, return to the user process at the instruction im-
mediately after the one that caused the exception. This way, the same program binary
can run on all the different versions of the processor.
More generally, exceptions are used to transparently emulate a virtual machine.
When a guest operating system is running as a user-level process on top of an op-
erating system, it will attempt to execute privileged instructions as if it were running on
physical hardware. These instructions will cause privilege violations, trapping into the
host operating system kernel. To maintain the illusion of physical hardware, the host
kernel then performs the requested instruction of behalf of the user-level virtual ma-
chine, and restarts the guest operating system at the instruction immediately following
the one that caused the exception.
As a final example, exceptions are a key building block for memory management.
With most types of virtual addressing, the processor can be set up to take an exception
whenever it reads or writes inside a particular virtual address range. This allows the
kernel to treat addressing as virtual — a virtual address need not always correspond
to a physical memory location. Whenever the program touches a missing address, the
operating system takes an exception and fills in the data from disk before resuming the
program. In this way, the operating system can execute programs that require more
memory than can ever be physically on the machine at any one time.
the multiprocessor; for example, if one processor takes a fatal exception,
the kernel will normally send an interrupt to stop any of the other proces-
sors who might be running the failed program.
System calls. User processes can also transition into the operating sys-
tem kernel voluntarily, to request that the kernel do some operation on
the user's behalf. A system call is any procedure provided by the kernel
Definition: system call
that can be called from user-level. Most processors implement system
calls using a special trap instruction. However, a trap instruction is not
strictly required; we can voluntarily cause a trap by executing any in-
struction that causes an exception (e.g., one with an invalid opcode). As
with an interrupt or an exception, the trap instruction changes the pro-
cessor mode from user to kernel and starts executing in the kernel at a
pre-defined handler. As we will explain shortly, to protect the kernel from
Search WWH ::




Custom Search