Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: Memory /
Chapter 3 - Virtual Memory Manager


Summary of the Virtual Memory Manager

Pascal Summary

Constants

CONST
   {Gestalt constants}
   gestaltVMAttr              = 'vm  ';   {virtual memory attributes}
   gestaltVMPresent           = 0;        {bit set if virtual memory present}
   {default number of physical blocks in a translation table}
   defaultPhysicalEntryCount  = 8;
   {page states}
   kPageInMemory              = 0;        {page is in RAM}
   kPageOnDisk                = 1;        {page is on disk}
   kNotPaged                  = 2;        {address is not paged}

Data Types

TYPE 
   PageState            = Integer;

   LogicalToPhysicalTable =            {translation table}
   RECORD
      logical:       MemoryBlock;      {logical block}
      physical:      ARRAY[0..defaultPhysicalEntryCount-1] OF MemoryBlock;
                                       {equivalent physical blocks}
   END;
   MemoryBlock =                       {memory-block record}
   RECORD
      address:       Ptr;              {start of block}
      count:         LongInt;          {size of block}
   END;

Routines

Virtual Memory Management

FUNCTION HoldMemory		(address: UNIV Ptr; count: LongInt): OSErr;
FUNCTION UnholdMemory		(address: UNIV Ptr; count: LongInt): OSErr;
FUNCTION LockMemory		(address: UNIV Ptr; count: LongInt): OSErr;
FUNCTION LockMemoryContiguous
   				(address: UNIV Ptr; count: LongInt): OSErr;
FUNCTION UnlockMemory		(address: UNIV Ptr; count: LongInt): OSErr;
FUNCTION GetPhysical		(VAR addresses: LogicalToPhysicalTable;
				VAR physicalEntryCount: LongInt): OSErr;
FUNCTION DeferUserFn		(userFunction: ProcPtr; argument: UNIV Ptr): 
				OSErr;

Virtual Memory Debugger Support Routines

FUNCTION DebuggerGetMax		: LongInt;
PROCEDURE DebuggerEnter;
PROCEDURE DebuggerExit;
FUNCTION PageFaultFatal		: Boolean;
FUNCTION DebuggerLockMemory	(address: UNIV Ptr; count: LongInt): OSErr;
FUNCTION DebuggerUnlockMemory
   				(address: UNIV Ptr; count: LongInt): OSErr;
PROCEDURE DebuggerPoll;
FUNCTION GetPageState		(address: UNIV Ptr): PageState;

C Summary

Constants

/*Gestalt constants*/
#define gestaltVMAttr         'vm  ';  /*virtual memory attributes*/
#define gestaltVMPresent       0;      /*bit set if virtual memory present*/
/*default number of physical blocks in table*/
enum {
   defaultPhysicalEntryCount     = 8
};
/*page states*/
enum {
   kPageInMemory                 = 0,     /*page is in RAM*/
   kPageOnDisk                   = 1,     /*page is on disk*/
   kNotPaged                     = 2      /*address is not paged*/
};

Data Types

typedef short PageState;
struct LogicalToPhysicalTable {           /*translation table*/
      MemoryBlock       logical;          /*logical block*/
      MemoryBlock       physical[defaultPhysicalEntryCount];
                                          /*equivalent physical blocks*/
   };
typedef struct LogicalToPhysicalTable LogicalToPhysicalTable;
struct MemoryBlock {                      /*memory-block record*/
      void              *address;         /*start of block*/
      unsigned long     count;            /*size of block*/
};
typedef struct MemoryBlock MemoryBlock;

Routines

Virtual Memory Management

pascal OSErr HoldMemory		(void *address, unsigned long count);
pascal OSErr UnholdMemory	(void *address, unsigned long count);
pascal OSErr LockMemory		(void *address, unsigned long count);
pascal OSErr LockMemoryContiguous
   				(void *address, unsigned long count);
pascal OSErr UnlockMemory	(void *address, unsigned long count);
pascal OSErr GetPhysical	(LogicalToPhysicalTable *addresses,
				unsigned long *physicalEntryCount);
pascal OSErr DeferUserFn	(ProcPtr userFunction, void *argument);

Virtual Memory Debugger Support Routines

pascal long DebuggerGetMax	(void);
pascal void DebuggerEnter	(void);
pascal void DebuggerExit	(void);
pascal Boolean PageFaultFatal
   				(void);
pascal OSErr DebuggerLockMemory
   				(void *address, unsigned long count);
pascal OSErr DebuggerUnlockMemory
   				(void *address, unsigned long count);
pascal void DebuggerPoll	(void);
pascal PageState GetPageState
   				(const void *address);

Assembly-Language Summary

Data Types

Memory-Block Data Structure
0addresslongstart of block
4count4 bytessize of block

Translation Table Data Structure
0logical8 byteslogical block
8physical64 bytesequivalent physical blocks

Trap Macros

Trap Macros Requiring Routine Selectors

_MemoryDispatch
SelectorRoutine
$0000HoldMemory
$0001UnholdMemory
$0002LockMemory
$0003UnlockMemory
$0004LockMemoryContiguous
_MemoryDispatchA0Result
SelectorRoutine
$0005GetPhysical
_DebugUtil
SelectorRoutine
$0000DebuggerGetMax
$0001DebuggerEnter
$0002DebuggerExit
$0003DebuggerPoll
$0004GetPageState
$0005PageFaultFatal
$0006DebuggerLockMemory
$0007DebuggerUnlockMemory
$0008EnterSupervisorMode

Result Codes
noErr0No error
paramErr-50Error in parameter list
notEnoughMemoryErr-620Insufficient physical memory
notHeldErr-621Specified range of memory is not held
cannotMakeContiguousErr-622Cannot make specified range contiguous
notLockedErr-623Specified range of memory is not locked
interruptsMaskedErr-624Called with interrupts masked
cannotDeferErr-625Unable to defer additional user functions


Previous Book Contents Book Index Next

© Apple Computer, Inc.
3 JUL 1996