(* Copyright (C) 1990, Digital Equipment Corporation *) (* All rights reserved. *) (* See the file COPYRIGHT for a full description. *) (* Last modified on Thu Jul 30 13:25:17 PDT 1992 by muller *) (* modified on Tue Mar 3 17:04:24 PST 1992 by kalsow *) UNSAFE MODULE RTStack; IMPORT Unix, Umman, RTMisc; VAR page_bytes : CARDINAL := 0; VAR stack_slop : CARDINAL; PROCEDURE Init () = BEGIN page_bytes := Unix.getpagesize (); stack_slop := 2 * (page_bytes DIV BYTESIZE (INTEGER)); END Init; PROCEDURE New (size: INTEGER): T = VAR t: T; i: INTEGER; start: ADDRESS; BEGIN IF (page_bytes = 0) THEN Init () END; (* allocate enough so that we're guaranteed to get a full, aligned page *) t := NEW (T, size + stack_slop); (* find the aligned page and unmap it *) start := RTMisc.Align (ADR (t[0]), page_bytes); i := Umman.mprotect (start, page_bytes, Umman.PROT_READ); (* The protection should be 0, but a bug in MIPS/Ultrix 4.2 (vmdup) causes kernel panics when it is. Making the page read-only is good enough to prevent unchecked runtime errors *) <* ASSERT i = page_bytes *> (* finally, return the new stack *) RETURN t; END New; PROCEDURE Dispose (t: T) = VAR i: INTEGER; start := RTMisc.Align (ADR (t[0]), page_bytes); BEGIN (* find the aligned page and re-map it *) i := Umman.mprotect (start, page_bytes, Umman.PROT_READ + Umman.PROT_WRITE); <* ASSERT i = page_bytes *> (* and finally, free the storage *) DISPOSE (t); END Dispose; PROCEDURE GetBounds (t: T; VAR(*OUT*) first, last: ADDRESS) = VAR start := RTMisc.Align (ADR (t[0]), page_bytes); BEGIN first := start + page_bytes; last := ADR (t [0]) + NUMBER (t^) * ADRSIZE (t[0]); END GetBounds; BEGIN END RTStack.