INTERFACE Auth;
TYPE
Key = REFANY;
T = OBJECT
METHODS
authorize(key: Key; arg: REFANY := NIL): BOOLEAN
RAISES {Retry};
END;
END Auth.
INTERFACE Dispatcher;
PROCEDURE InstallAuthorizerForInterface (auth : Auth.T;
interface: RTCode.Interface;
module : RTCode.Module)
RAISES {Error};
PROCEDURE InstallAuthorizerForEvent (auth : Auth.T;
event : PROCANY;
module: RTCode.Module)
RAISES { Error };
END Dispatcher.
INTERFACE MachineTrap;
TYPE
AuthKey = REF RECORD
minProcID, maxProcID : INTEGER;
END;
END MachineTrap.
The MachineTrap module installs an authorizer of type
AuthT (a subtype of Auth.T) on the
MachineTrap.Syscall event. The Authorize method of the
authorizer imposes a guard (the ImposedGuard procedure) on each
handler installed on that event. The imposed guard verifies that that
handler receives only syscalls with syscall numbers authorized by the
key of type AuthT.
UNSAFE MODULE MachineTrap;
TYPE
AuthT = Auth.T BRANDED OBJECT
OVERRIDES
authorize := Authorize;
END;
PROCEDURE Authorize (a : AuthT; k : Auth.Key; r : REFANY) : BOOLEAN =
VAR
binding : Dispatcher.Binding := r;
newKey := NEW(MachineTrap.AuthKey);
BEGIN
IF k = NIL OR NOT ISTYPE(k, MachineTrap.AuthKey) THEN
IO.Put("syscall auth : key is not of type AuthKey\n");
RETURN FALSE;
END;
newKey^ := NARROW(k, MachineTrap.AuthKey)^;
EVAL Dispatcher.ImposeGuardWithClosure(binding, ImposedGuard, newKey);
RETURN TRUE;
END Authorize;
PROCEDURE ImposedGuard (key : MachineTrap.AuthKey;
strand: Strand.T;
VAR ms: MachineCPU.SavedState) : BOOLEAN =
BEGIN
RETURN ms.v0 >= key.minProcID AND ms.v0 <= key.maxProcID;
END ImposedGuard;
BEGIN
Dispatcher.InstallAuthorizerForEvent(NEW(AuthT),
MachineTrap.Syscall,
THIS_MODULE());
END MachineTrap.
Przemek Pardyak,