// PART OF THE MACHINE SIMULATION. DO NOT CHANGE. package nachos.security; import nachos.machine.*; import nachos.threads.KThread; import java.security.PrivilegedAction; import java.security.PrivilegedExceptionAction; import java.security.PrivilegedActionException; /** * A capability that allows privileged access to the Nachos machine. * * * Some privileged operations are guarded by the Nachos security manager: * * creating threads * writing/deleting files in the test directory * exit with specific status code * * These operations can only be performed through doPrivileged(). * * * Some privileged operations require a capability: * * scheduling interrupts * advancing the simulated time * accessing machine statistics * installing a console * flushing the simulated processor's pipeline * approving TCB operations * * These operations can be directly performed using a Privilege * object. * * * The Nachos kernel should never be able to directly perform any of * these privileged operations. If you have discovered a loophole somewhere, * notify someone. */ public abstract class Privilege { /** * Allocate a new Privilege object. Note that this object in * itself does not encapsulate privileged access until the machine devices * fill it in. */ public Privilege() { } /** * Perform the specified action with privilege. * * @param action the action to perform. */ public abstract void doPrivileged(Runnable action); /** * Exit Nachos with the specified status. * * @param exitStatus the exit status of the Nachos process. */ public abstract void exit(int exitStatus); /** Nachos runtime statistics. */ public Stats stats = null; /** Provides access to some private Machine methods. */ public MachinePrivilege machine = null; /** Provides access to some private Interrupt methods. */ public InterruptPrivilege interrupt = null; /** Provides access to some private Processor methods. */ public ProcessorPrivilege processor = null; /** Provides access to some private TCB methods. */ public TCBPrivilege tcb = null; /** * An interface that provides access to some private Machine * methods. */ public interface MachinePrivilege { /** * Install a hardware console. * * @param console the new hardware console. */ public void setConsole(SerialConsole console); } /** * An interface that provides access to some private Interrupt * methods. */ public interface InterruptPrivilege { /** * Schedule an interrupt to occur at some time in the future. * * @param when the number of ticks until the interrupt should * occur. * @param type a name for the type of interrupt being * scheduled. * @param handler the interrupt handler to call. */ public void schedule(long when, String type, Runnable handler); /** * Advance the simulated time. * * @param true if the current thread is running kernel * code, false if the current thread is running * MIPS user code. */ public void tick(boolean inKernelMode); } /** * An interface that provides access to some private Processor * methods. */ public interface ProcessorPrivilege { /** * Flush the processor pipeline in preparation for switching to kernel * mode. */ public void flushPipe(); } /** * An interface that provides access to some private TCB methods. */ public interface TCBPrivilege { /** * Associate the current TCB with the specified KThread. * AutoGrader.runningThread() must call this method * before returning. * * @param thread the current thread. */ public void associateThread(KThread thread); /** * Authorize the TCB associated with the specified thread to be * destroyed. * * @param thread the thread whose TCB is about to be destroyed. */ public void authorizeDestroy(KThread thread); } }