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: Mac OS Runtime Architectures /
Appendix B - The RTLib.o and NuRTLib.o Libraries / Runtime Operations


Segment Manager Hooks

Several Runtime operations allow the application to take control and execute a user-defined handler routine during the segment loading or unloading process. These operations are

In each of these cases, control is passed by replacing the null user vector (set up by the patched Segment Manager) with a user handler.

The fRTParams structure used with these operations is as follows:

struct RTSetSegLoadParam {
   SegLoadHdlrPtr fUserHdlr;
   SegLoadHdlrPtr fOldUserHdlr;
   };
typedef struct RTSetSegLoadParam RTSetSegLoadParam;
The pointer fUserHdlr points to the user handler to be called at the time indicated by the operation. A pointer to the original (bypassed) handler is returned in fOldUserHdlr.

User Handlers

A user handler is defined as follows:

typedef pascal short (*SegLoadHdlrPtr)(RTState* state)
The handler may return a result code of type short. This code is ignored by the Segment Manager except in the case of the error handler. See "Error Handling With kRTSetSegLoadErr" (page B-7) for more details.

WARNING
User handlers must be defined within the segment to be loaded into memory when the handler is invoked (usually the main segment). Also, the user handler must not call any routines in unloaded segments as this may result in a system crash.
Information about the Segment Manager operation is passed to the user handler through the RTState structure. This structure has the following form:

struct RTState {
   unsigned short   fVersion;/* runtime version */
   void*     fSP;       /* SP: address of user return address */
   void*     fJTAddr;   /* PC: address of jump table entry */
                        /*    or  (see fCallType) */
                        /*    address of a transition vector*/
   long      fRegisters[15];/* registers D0-D7 and A0-A6 */
   short     fSegNo;    /* segment number */
   ResType   fSegType;  /* segment type (normally 'CODE') */
   long      fSegSize;  /* segment size */
   Boolean   fSegInCore;/* true if segment is in memory */
   Boolean   fCallType; /* 0 = _LoadSeg, */
                        /* 1 = fJTAddr, address of TVector */
   OSErr     fOSErr;    /* error number */
   long      fReserved2;/* (reserved for future use) */
   };
typedef struct RTState RTState;
The fields in the structure are as follows:

All attempts to modify the RTState structure are ignored except for alterations of fJTAddr by the user error handler.

Error Handling With kRTSetSegLoadErr

When kRTSetSegLoadErr invokes the user error handler (that is, when a segment loading error occurs), the stack has the form shown in Figure B-1.

Figure B-1 The stack when a user error handler is called

The error handler should use the information at the following locations:

Items on the stack labeled as optional may not actually appear. For example, a simple JMP instruction would not push user parameters or a return address onto the stack.

The error handler should examine the RTState structure and then take appropriate action (for example, release some memory). After doing so, the handler can do one of the following:


Previous Book Contents Book Index Next

© Apple Computer, Inc.
11 MARCH 1997