Advanced Search
Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

Previous Book Contents Book Index Next

Inside Macintosh: PowerPC System Software /
Chapter 3 - Code Fragment Manager

Summary of the Code Fragment Manager

C Summary


/*Gestalt selector and response bits*/
#define gestaltCFMAttr     'cfrg'   /*Code Fragment Manager attributes*/
enum {
   gestaltCFMPresent = 0            /*set if Code Fragment Mgr is present*/
#define kPowerPCArch       'pwpc'   /*PowerPC instruction set architecture*/
#define kMotorola68KArch   'm68k'   /*680x0 instruction set architecture*/
#define kNoLibName                  ((unsigned char *) 0)
#define kNoConnectionID             ((ConnectionID) 0)
#define kUnresolvedSymbolAddress    ((Ptr) 0x0)
enum {
   kLoadLib          = 1,           /*load fragment*/
   kFindLib          = 2,           /*find fragment*/
   kLoadNewCopy      = 5            /*load fragment with new copy of data*/
enum {
   kCodeSymbol       = 0,           /*a code symbol*/
   kDataSymbol       = 1,           /*a data symbol*/
   kTVectSymbol      = 2            /*a transition vector symbol*/
enum {
   /*selectors for fragment location record*/
   kInMem,                          /*container in memory*/
   kOnDiskFlat,                     /*container in a data fork*/
   kOnDiskSegmented                 /*container in a resource*/

Data Types

typedef long                  ConnectionID;  /*connection ID number*/
typedef unsigned long         LoadFlags;     /*a flag long word*/
typedef unsigned char         SymClass;      /*symbol class*/

Fragment Initialization Block

struct InitBlock {
   long                    contextID;     /*context ID*/
   long                    closureID;     /*closure ID*/
   long                    connectionID;  /*connection ID*/
   FragmentLocator         fragLocator;   /*fragment location*/
   Ptr                     libName;       /*pointer to fragment name*/
   long                    reserved4a;    /*reserved*/
   long                    reserved4b;    /*reserved*/
   long                    reserved4c;    /*reserved*/
   long                    reserved4d;    /*reserved*/
typedef struct InitBlock InitBlock, *InitBlockPtr;

Fragment Location Record

struct FragmentLocator {
   long                    where;         /*location selector*/
   union {
      MemFragment          inMem;         /*memory location record*/
      DiskFragment         onDisk;        /*disk location record*/
      SegmentedFragment    inSegs;        /*segment location record*/
   } u;
typedef struct FragmentLocator FragmentLocator, *FragmentLocatorPtr;

Memory Location Record

struct MemFragment {
   Ptr                     address;       /*pointer to start of fragment*/
   long                    length;        /*length of fragment*/
   Boolean                 inPlace;       /*is data section in place?*/
typedef struct MemFragment MemFragment;

Disk Location Record

struct DiskFragment {
   FSSpecPtr               fileSpec;      /*pointer to FSSpec*/
   long                    offset;        /*offset to start of fragment*/
   long                    length;        /*length of fragment*/
typedef struct DiskFragment DiskFragment;

Segment Location Record

struct SegmentedFragment {
   FSSpecPtr               fileSpec;      /*pointer to FSSpec*/
   OSType                  rsrcType;      /*resource type*/
   short                   rsrcID;        /*resource ID*/
typedef struct SegmentedFragment SegmentedFragment;

Code Fragment Manager Routines

Loading Fragments

OSErr GetDiskFragment    (FSSpecPtr fileSpec, long offset, long length, 
                          Str63 fragName, LoadFlags findFlags, 
                          ConnectionID *connID, Ptr *mainAddr, 
                          Str255 errName);
OSErr GetMemFragment     (Ptr memAddr, long length, Str63 fragName, 
                          LoadFlags findFlags, ConnectionID *connID, 
                          Ptr *mainAddr, Str255 errName);
OSErr GetSharedLibrary   (Str63 libName, OSType archType, 
                          LoadFlags findFlags, ConnectionID *connID, 
                          Ptr *mainAddr, Str255 errName);

Unloading Fragments

OSErr CloseConnection(ConnectionID *connID);

Finding Symbols

OSErr FindSymbol         (ConnectionID connID, Str255 symName, 
                          Ptr *symAddr, SymClass *symClass);
OSErr CountSymbols       (ConnectionID connID, long *symCount);
OSErr GetIndSymbol       (ConnectionID connID, long symIndex, 
                          Str255 symName, Ptr *symAddr, 
                          SymClass *symClass);

Fragment-Defined Routines

Initializing Fragments

typedef OSErr ConnectionInitializationRoutine
(InitBlockPtr initBlkPtr);

Terminating Fragments

typedef void ConnectionTerminationRoutine

Result Codes

fragNoErr0No error
paramErr-50Parameter error
fragContextNotFound-2800Context ID is not valid
fragConnectionIDNotFound-2801Connection ID is not valid
fragSymbolNotFound-2802Symbol was not found in connection
fragSectionNotFound-2803Section was not found
fragLibNotFound-2804Library name not found in fragment registry
fragDupRegLibName-2805Registered name already in use
fragFormatUnknown-2806Fragment container format unknown
fragHadUnresolveds-2807Loaded fragment has unacceptable unresolved symbols
fragNoMem-2809Not enough memory for internal bookkeeping
fragNoAddrSpace-2810Not enough memory in user's address space for section
fragNoContextIDs-2811No more context IDs available
fragObjectInitSeqErr-2812Order error during user initialization function
fragImportTooOld-2813Import library is too old
fragImportTooNew-2814Import library is too new
fragInitLoop-2815Circularity in required initialization order
fragInitRtnUsageErr-2816Boot library has initialization routine
fragLibConnErr-2817Error connecting to library
fragMgrInitErr-2818Error during Code Fragment Manager initialization
fragConstErr-2819Internal inconsistency discovered
fragCorruptErr-2820Fragment container is corrupted
fragUserInitProcErr-2821Initialization procedure did not return noErr
fragAppNotFound-2822No application found in 'cfrg' resource
fragArchErr-2823Fragment targeted for unacceptable architecture
fragInvalidFragmentUsage-2824Fragment is used invalidly

Previous Book Contents Book Index Next

© Apple Computer, Inc.
3 JUL 1996

Get information on Apple products.
Visit the Apple Store online or at retail locations.

Copyright © 2004 Apple Computer, Inc.
All rights reserved. | Terms of use | Privacy Notice