A method for monitoring and emulating privileged instructions of a program
that is being executed at a privilege level in a virtual machine is
disclosed. A privilege level associated with a received instruction is
determined. The instruction privilege level is compared to the program
execution privilege level. If the instruction privilege level is valid
with respect to the program execution privilege level, the instruction is
executed. If the instruction privilege level is invalid with respect to
the program execution privilege level: the instruction result is
emulated; the number of times the instruction has been received from the
program is checked; and if the instruction has been received more than a
specified number of times, the instruction is overwritten with one or
more instructions with a valid privilege level with respect to the
program execution privilege level.