UnsafeStorageImpl.mesa
Copyright Ó 1988, 1991 by Xerox Corporation. All rights reserved.
Andy Litman May 25, 1988 5:42:58 pm PDT
JKF August 1, 1988 11:11:22 am PDT
Chauser, July 22, 1992 10:01 am PDT
DIRECTORY
UnsafeStorage;
UnsafeStorageImpl: CEDAR PROGRAM
IMPORTS
EXPORTS UnsafeStorage
~ BEGIN
UZone: TYPE = POINTER TO UZoneRecord;
UZoneRecord: TYPE = MACHINE DEPENDENT RECORD [new: NewProc, free: FreeProc];
NewProc: TYPE = UNSAFE PROC[self: UZone, units: CARD32] RETURNS[POINTER];
FreeProc: TYPE = UNSAFE PROC[self: UZone, object: POINTER];
systemUZone: UNCOUNTED ZONE ¬ GetUZone[New, Free];
GetSystemUZone: PUBLIC PROC RETURNS [UNCOUNTED ZONE] = {
RETURN[systemUZone]};
GetUZone: PROC [new: NewProc, free: FreeProc] RETURNS [UNCOUNTED ZONE] = TRUSTED {
uZone: UZone ¬ new[NIL, UNITS[UZoneRecord]];
uZone­ ¬ [new, free];
RETURN[LOOPHOLE[uZone]]};
overheadBytes: CARD = 8; -- There exist broken clients that use these bytes for there own purposes.
New: NewProc = {
malloc: PROC[units: CARD32] RETURNS [WORD] ~ TRUSTED MACHINE CODE {
"GC←malloc"
};
ptr: WORD ¬ malloc[units+overheadBytes];
RETURN [LOOPHOLE[ptr+overheadBytes]];
};
Free: FreeProc = {
free: PROC[p: CARDINAL] = TRUSTED MACHINE CODE
{ "GC𡤏ree" };
ptr: CARDINAL ¬ LOOPHOLE[object, CARDINAL]-overheadBytes;
free[LOOPHOLE[ptr]]; };
NewUObject: PUBLIC PROC [size: CARDINAL, zone: UNCOUNTED ZONE] RETURNS [LONG POINTER] = TRUSTED {
RETURN [New[LOOPHOLE[zone, UZone], size]];
};
GetTransientPageUZone: PUBLIC PROC RETURNS [UNCOUNTED ZONE] = {ERROR NYI};
NYI: ERROR ~ CODE ;
InvalidPointer: PUBLIC ERROR [ptr: LONG POINTER] ~ CODE;
END.