#ifndef __IOPEFINTERNALS__
#define __IOPEFINTERNALS__ 1
#include "IOPEFLoader.h"
typedef signed int PEF_SBits32; typedef unsigned int PEF_UBits32;
#pragma options align=mac68k
typedef struct {
UInt16 magic1;
UInt16 magic2;
OSType fileTypeID;
OSType architectureID;
UInt32 versionNumber;
UInt32 dateTimeStamp;
UInt32 oldDefVersion;
UInt32 oldImpVersion;
UInt32 currentVersion;
SInt16 numberSections;
SInt16 loadableSections;
BytePtr memoryAddress;
} FileHeader, *FileHeaderPtr;
#define kPEFVersion 1
#define kPEFMagic1 0x4A6F
#define kPEFMagic2 0x7921
#define kPEFTypeID 0x70656666
#define kPowerPCID 0x70777063
typedef struct {
ByteCount sectionName;
BytePtr sectionAddress;
ByteCount execSize;
ByteCount initSize;
ByteCount rawSize;
ByteCount containerOffset;
UInt8 regionKind;
UInt8 shareKind;
UInt8 alignment;
UInt8 reservedA;
} SectionHeader, *SectionHeaderPtr;
#define kPEFCodeSection 0
#define kPEFDataSection 1
#define kPEFPIDataSection 2
#define kPEFConstantSection 3
#define kPEFLoaderSection 4
#define kPEFDebugSection 5
#define kPEFExecDataSection 6
#define kPEFExceptionSection 7
#define kPEFTracebackSection 8
#define kPEFContextShare 1
#define kPEFGlobalShare 4
#define kPEFProtectedShare 5
#define kPEFZero 0
#define kPEFBlock 1
#define kPEFRepeat 2
#define kPEFRepeatBlock 3
#define kPEFRepeatZero 4
#define kPEFNoOpcode 0x0fff
#define kPEFOpcodeShift 5
#define kPEFFirstOperandMask 31
typedef struct {
SInt32 entryPointSection;
ByteCount entryPointOffset;
SInt32 initPointSection;
ByteCount initPointOffset;
SInt32 termPointSection;
ByteCount termPointOffset;
ItemCount numImportFiles;
ItemCount numImportSyms;
ItemCount numSections;
ByteCount relocationsOffset;
ByteCount stringsOffset;
ByteCount hashSlotTable;
ItemCount hashSlotTabSize;
ItemCount numExportSyms;
} LoaderHeader, *LoaderHeaderPtr;
typedef struct {
SInt16 sectionNumber;
SInt16 reservedA;
ItemCount numRelocations;
ByteCount relocationsOffset;
} LoaderRelExpHeader, *LoaderRelExpHeaderPtr;
typedef struct {
ByteCount fileNameOffset;
UInt32 oldImpVersion;
UInt32 linkedVersion;
ItemCount numImports;
ItemCount impFirst;
UInt8 options;
UInt8 reservedA;
UInt16 reservedB;
} LoaderImportFileID, *LoaderImportFileIDPtr;
#define kPEFInitBeforeMask 0x80
#define kPEFWeakLibraryMask 0x40
#define kPEFDeferredBindMask 0x20
typedef struct {
PEF_UBits32 symClass : 8; PEF_UBits32 nameOffset : 24;
} LoaderImport, *LoaderImportPtr;
#define kPEFWeakSymbolMask 0x80
typedef struct {
PEF_UBits32 chainCount : 14;
PEF_UBits32 chainIndex : 18;
} HashSlotEntry, *HashSlotEntryPtr;
#define PEFHashHighBits(hashword,bitCount) ((hashword) >> (bitCount))
#define PEFHashMaskBits(hashword,bitCount) (((UInt32)(1) << (bitCount)) - 1)
#define GetPEFHashSlot(hashword,bitCount) \
( (ItemCount) (((hashword) ^ PEFHashHighBits((hashword),(bitCount))) & PEFHashMaskBits((hashword),(bitCount))) )
typedef struct {
UInt32 hashword;
} HashChainEntry, *HashChainEntryPtr;
typedef struct {
PEF_UBits32 symClass : 8; PEF_UBits32 nameOffset : 24;
ByteCount offset;
SInt16 sectionNumber;
} LoaderExport, *LoaderExportPtr;
#define SIZEOF_LoaderExport (sizeof (TUnsigned32)*2 + sizeof (SInt16))
#define kPEFAbsoluteExport -1
#define kPEFPhysicalExport -2
#define kPEFReExportImport -3
typedef UInt16 RelocInstr;
typedef union {
struct { unsigned op:7, rest:9; } opcode;
struct { unsigned op:2, delta_d4:8, cnt:6; } deltadata;
struct { unsigned op:7, cnt_m1:9; } run;
struct { unsigned op:7, idx:9; } glp;
struct { unsigned op:4, delta_m1:12; } delta;
struct { unsigned op:4, icnt_m1:4, rcnt_m1:8; } rpt;
struct { unsigned op:6, idx_top:10; } large1;
struct { unsigned op:6, cnt_m1:4, idx_top:6; } large2;
UInt16 instr;
UInt16 bot;
} Relocation;
#define krDDAT 0x00 // type deltadata
#define krCODE 0x20 // type run
#define krDATA 0x21 // type run
#define krDESC 0x22 // type run
#define krDSC2 0x23 // type run
#define krVTBL 0x24 // type run
#define krSYMR 0x25 // type run
#define krSYMB 0x30 // type glp
#define krCDIS 0x31 // type glp
#define krDTIS 0x32 // type glp
#define krSECN 0x33 // type glp
#define krDELT 0x40 // type delta
#define krRPT 0x48 // type rpt
#define krLABS 0x50 // type large1
#define krLSYM 0x52 // type large1
#define krLRPT 0x58 // type large2
#define krLSEC 0x5A // type large2
#define ksDELTA 4096 // delta max for DELTA from
#define ksDDDMAX 1023 // delta max for DELTA-DAT (DDAT) form
#define ksDDRMAX 63 // run max for DELTA-DAT (DDAT) form
#define ksCODE 512 // count max for CODE form
#define ksDATA 512 // count max for DATA form
#define ksDEMAX 512 // count max for DESC form
#define ksVTMAX 512 // count max for VTBL form
#define ksISMAX 512 // count max for IMPS form
#define ksRPTMAX 256 // count max for RPT form
#define IsLARG(op) (((op) & 0x70) == 0x50)
#define RELOPSHFT 9
#define ksDVDMAX 0 // (63) delta max for DELTA-VTBL (DVBL) form
#define ksDVRMAX 0 // (256) run max for DELTA-VTBL (DVBL) form
#define krXXXX 0xff
enum {
kPEFPkDataZero = 0,
kPEFPkDataBlock = 1,
kPEFPkDataRepeat = 2,
kPEFPkDataRepeatBlock = 3,
kPEFPkDataRepeatZero = 4
};
enum {
kPEFPkDataOpcodeShift = 5,
kPEFPkDataCount5Mask = 0x1F,
kPEFPkDataMaxCount5 = 31,
kPEFPkDataVCountShift = 7,
kPEFPkDataVCountMask = 0x7F,
kPEFPkDataVCountEndMask = 0x80
};
#define PEFPkDataOpcode(byte) ( ((UInt8)(byte)) >> kPEFPkDataOpcodeShift )
#define PEFPkDataCount5(byte) ( ((UInt8)(byte)) & kPEFPkDataCount5Mask )
#define PEFPkDataComposeInstr(opcode,count5) \
( (((UInt8)(opcode)) << kPEFPkDataOpcodeShift) | ((UInt8)(count5)) )
typedef SInt32 CFContSignedIndex;
typedef UInt32 CFContStringHash;
#define CFContStringHashLength(hashValue) ((hashValue) >> 16)
struct CFContHashedName {
CFContStringHash nameHash;
BytePtr nameText;
};
typedef struct CFContHashedName CFContHashedName;
enum {
kCFContContainerInfoVersion = 0x00010001
};
struct CFContContainerInfo {
CFContHashedName cfragName;
UInt32 modDate;
OSType architecture;
CFragVersionNumber currentVersion;
CFragVersionNumber oldImpVersion;
CFragVersionNumber oldDefVersion;
UInt32 reservedA;
void * reservedB;
};
typedef struct CFContContainerInfo CFContContainerInfo;
struct CFContLogicalLocation {
CFContSignedIndex section;
ByteCount offset;
};
typedef struct CFContLogicalLocation CFContLogicalLocation;
enum {
kCFContNoSectionIndex = -1,
kCFContAbsoluteSectionIndex = -2,
kCFContReexportSectionIndex = -3
};
typedef UInt8 CFContSectionSharing;
enum {
kCFContShareSectionInClosure = 0,
kCFContShareSectionInProcess = 1,
kCFContShareSectionAcrossSystem = 4,
kCFContShareSectionWithProtection = 5
};
typedef UInt8 CFContMemoryAccess;
enum {
kCFContMemReadMask = 0x01,
kCFContMemWriteMask = 0x02,
kCFContMemExecuteMask = 0x04,
kCFContReadOnlyData = kCFContMemReadMask,
kCFContWriteableData = kCFContMemReadMask | kCFContMemWriteMask,
kCFContNormalCode = kCFContMemReadMask | kCFContMemExecuteMask,
kCFContExcludedMemory = 0
};
typedef UInt32 CFContSectionOptions;
enum {
kPackedCFContSectionMask = 0x01,
kRelocatedCFContSectionMask = 0x02,
kEmptyFillCFContSectionMask = 0x04,
kResidentCFContSectionMask = 0x08,
kPrefaultCFContSectionMask = 0x10
};
enum {
kCFContSectionInfoVersion = 0x00010001
};
struct CFContSectionInfo {
CFContHashedName sectionName;
CFContMemoryAccess access;
CFContSectionSharing sharing;
UInt8 alignment;
UInt8 reservedA;
CFContSectionOptions options;
ByteCount containerOffset;
ByteCount containerLength;
ByteCount unpackedLength;
ByteCount totalLength;
LogicalAddress defaultAddress;
UInt32 reservedB;
void * reservedC;
};
typedef struct CFContSectionInfo CFContSectionInfo;
typedef UInt32 CFContExportedSymbolOptions;
enum {
kCFContExportedSymbolInfoVersion = 0x00010001
};
struct CFContExportedSymbolInfo {
CFContHashedName symbolName;
CFContLogicalLocation location;
CFContExportedSymbolOptions options;
CFragSymbolClass symbolClass;
UInt8 reservedA;
UInt16 reservedB;
UInt32 reservedC;
void * reservedD;
};
typedef struct CFContExportedSymbolInfo CFContExportedSymbolInfo;
typedef UInt32 CFContImportedLibraryOptions;
enum {
kCFContWeakLibraryMask = 0x01,
kCFContInitBeforeMask = 0x02,
kCFContDeferredBindMask = 0x04
};
enum {
kCFContImportedLibraryInfoVersion = 0x00010001
};
struct CFContImportedLibraryInfo {
CFContHashedName libraryName;
CFragVersionNumber linkedVersion;
CFragVersionNumber oldImpVersion;
CFContImportedLibraryOptions options;
};
typedef struct CFContImportedLibraryInfo CFContImportedLibraryInfo;
typedef UInt32 CFContImportedSymbolOptions;
enum {
kCFContWeakSymbolMask = 0x01
};
enum {
kCFContImportedSymbolInfoVersion = 0x00010001
};
struct CFContImportedSymbolInfo {
CFContHashedName symbolName;
ItemCount libraryIndex;
CFContImportedSymbolOptions options;
CFragSymbolClass symbolClass;
UInt8 reservedA;
UInt16 reservedB;
UInt32 reservedC;
void * reservedD;
};
typedef struct CFContImportedSymbolInfo CFContImportedSymbolInfo;
typedef UInt32 CFContOpenOptions;
enum {
kCFContPrepareInPlaceMask = 0x01,
kCFContMinimalOpenMask = 0x02
};
typedef UInt32 CFContCloseOptions;
enum {
kCFContPartialCloseMask = 0x01
};
typedef struct OpaqueCFContHandlerRef* CFContHandlerRef;
typedef struct CFContHandlerProcs CFContHandlerProcs;
typedef CFContHandlerProcs *CFContHandlerProcsPtr;
typedef LogicalAddress (*CFContAllocateMem)(ByteCount size);
typedef void (*CFContReleaseMem)(LogicalAddress address);
typedef OSStatus (*CFCont_OpenContainer)(LogicalAddress mappedAddress, LogicalAddress runningAddress, ByteCount containerLength, CFContOpenOptions options, CFContAllocateMem Allocate, CFContReleaseMem Release, CFContHandlerRef *containerRef, CFContHandlerProcsPtr *handlerProcs, UInt32 * createDate);
typedef OSStatus (*CFCont_CloseContainer)(CFContHandlerRef containerRef, CFContCloseOptions options);
typedef OSStatus (*CFCont_GetContainerInfo)(CFContHandlerRef containerRef, PBVersion infoVersion, CFContContainerInfo *containerInfo);
typedef OSStatus (*CFCont_GetSectionCount)(CFContHandlerRef containerRef, ItemCount *sectionCount);
typedef OSStatus (*CFCont_GetSectionInfo)(CFContHandlerRef containerRef, ItemCount sectionIndex, PBVersion infoVersion, CFContSectionInfo *sectionInfo);
typedef OSStatus (*CFCont_FindSectionInfo)(CFContHandlerRef containerRef, const CFContHashedName *sectionName, PBVersion infoVersion, ItemCount *sectionIndex, CFContSectionInfo *sectionInfo);
typedef OSStatus (*CFCont_SetSectionAddress)(CFContHandlerRef containerRef, ItemCount sectionIndex, LogicalAddress mappedAddress, LogicalAddress runningAddress);
typedef OSStatus (*CFCont_GetAnonymousSymbolLocations)(CFContHandlerRef containerRef, CFContLogicalLocation *mainLocation, CFContLogicalLocation *initLocation, CFContLogicalLocation *termLocation);
typedef OSStatus (*CFCont_GetExportedSymbolCount)(CFContHandlerRef containerRef, ItemCount *exportCount);
typedef OSStatus (*CFCont_GetExportedSymbolInfo)(CFContHandlerRef containerRef, CFContSignedIndex exportedIndex, PBVersion infoVersion, CFContExportedSymbolInfo *exportInfo);
typedef OSStatus (*CFCont_FindExportedSymbolInfo)(CFContHandlerRef containerRef, const CFContHashedName *exportName, PBVersion infoVersion, ItemCount *exportIndex, CFContExportedSymbolInfo *exportInfo);
typedef OSStatus (*CFCont_GetImportCounts)(CFContHandlerRef containerRef, ItemCount *libraryCount, ItemCount *symbolCount);
typedef OSStatus (*CFCont_GetImportedLibraryInfo)(CFContHandlerRef containerRef, ItemCount libraryIndex, PBVersion infoVersion, CFContImportedLibraryInfo *libraryInfo);
typedef OSStatus (*CFCont_GetImportedSymbolInfo)(CFContHandlerRef containerRef, ItemCount symbolIndex, PBVersion infoVersion, CFContImportedSymbolInfo *symbolInfo);
typedef OSStatus (*CFCont_SetImportedSymbolAddress)(CFContHandlerRef containerRef, ItemCount symbolIndex, LogicalAddress symbolAddress);
typedef OSStatus (*CFCont_UnpackSection)(CFContHandlerRef containerRef, ItemCount sectionIndex, ByteCount sectionOffset, LogicalAddress bufferAddress, ByteCount bufferLength);
typedef OSStatus (*CFCont_RelocateSection)(CFContHandlerRef containerRef, ItemCount sectionIndex);
typedef OSStatus (*CFCont_RelocateImportsOnly)(CFContHandlerRef containerRef, ItemCount sectionIndex, ItemCount libraryIndex);
typedef OSStatus (*CFCont_MakeSectionExecutable)(CFContHandlerRef containerRef, ItemCount sectionIndex);
typedef OSStatus (*CFCont_AllocateSection)(CFContHandlerRef containerRef, ItemCount sectionIndex, LogicalAddress *mappedAddress, LogicalAddress *runningAddress);
typedef OSStatus (*CFCont_ReleaseSection)(CFContHandlerRef containerRef, ItemCount sectionIndex);
#if 0
struct CFContHandlerInfo {
OrderedItemName orderedName;
OrderRequirements orderedReq;
CFCont_OpenContainer OpenHandler;
};
typedef struct CFContHandlerInfo CFContHandlerInfo;
#endif
struct CFContHandlerProcs {
ItemCount procCount;
CFragShortVersionPair abiVersion;
CFCont_OpenContainer OpenContainer;
CFCont_CloseContainer CloseContainer;
CFCont_GetContainerInfo GetContainerInfo;
CFCont_GetSectionCount GetSectionCount;
CFCont_GetSectionInfo GetSectionInfo;
CFCont_FindSectionInfo FindSectionInfo;
CFCont_SetSectionAddress SetSectionAddress;
CFCont_GetAnonymousSymbolLocations GetAnonymousSymbolLocations;
CFCont_GetExportedSymbolCount GetExportedSymbolCount;
CFCont_GetExportedSymbolInfo GetExportedSymbolInfo;
CFCont_FindExportedSymbolInfo FindExportedSymbolInfo;
CFCont_GetImportCounts GetImportCounts;
CFCont_GetImportedLibraryInfo GetImportedLibraryInfo;
CFCont_GetImportedSymbolInfo GetImportedSymbolInfo;
CFCont_SetImportedSymbolAddress SetImportedSymbolAddress;
CFCont_UnpackSection UnpackSection;
CFCont_RelocateSection RelocateSection;
CFCont_RelocateImportsOnly RelocateImportsOnly;
CFCont_MakeSectionExecutable MakeSectionExecutable;
CFCont_AllocateSection AllocateSection;
CFCont_ReleaseSection ReleaseSection;
};
enum {
kCFContMinimumProcCount = 18,
kCFContCurrentProcCount = 21,
kCFContHandlerABIVersion = 0x00010001
};
extern CFContStringHash CFContHashName(BytePtr nameText, ByteCount nameLength);
#if 0
extern OSStatus CFContOpenContainer(LogicalAddress mappedAddress, LogicalAddress runningAddress, ByteCount containerLength, KernelProcessID runningProcessID, const CFContHashedName *cfragName, CFContOpenOptions options, CFContAllocateMem Allocate, CFContReleaseMem Release, CFContHandlerRef *containerRef, CFContHandlerProcsPtr *handlerProcs);
extern OSStatus CFContRegisterContainerHandler(const OrderedItemName *orderedName, const OrderRequirements *orderedReq, CFCont_OpenContainer OpenHandler, OrderedItemName *rejectingHandler);
extern OSStatus CFContUnregisterContainerHandler(const OrderedItemName *orderedName);
extern OSStatus CFContGetContainerHandlers(ItemCount requestedCount, ItemCount *totalCount, CFContHandlerInfo *handlers);
#endif
enum {
kBuiltinSectionArraySize = 4
};
struct PEFPrivateInfo { CFContAllocateMem Allocate;
CFContReleaseMem Release;
BytePtr mappedContainer;
BytePtr runningContainer;
ItemCount sectionCount; SectionHeader * sections;
BytePtr stringTable;
ItemCount ldrSectionNo;
LoaderHeader * ldrHeader;
BytePtr ldrStringTable;
LoaderRelExpHeader * ldrSections;
LoaderImportFileID * ldrImportFiles;
LoaderImport * ldrImportSymbols;
HashSlotEntry * ldrHashSlot;
HashChainEntry * ldrHashChain;
LoaderExport * ldrExportSymbols;
BytePtr ldrRelocations;
BytePtr * mappedOrigins; ByteCount * runningOffsets; BytePtr * imports;
BytePtr originArray [kBuiltinSectionArraySize]; ByteCount offsetArray [kBuiltinSectionArraySize]; Boolean loadInPlace;
Boolean resolved;
};
typedef struct PEFPrivateInfo PEFPrivateInfo;
extern OSStatus PEF_OpenContainer ( LogicalAddress mappedAddress,
LogicalAddress runningAddress,
ByteCount containerLength,
CFContOpenOptions options,
CFContAllocateMem Allocate,
CFContReleaseMem Release,
CFContHandlerRef * containerRef_o,
CFContHandlerProcs * * handlerProcs_o,
UInt32 * createDate );
extern OSStatus PEF_CloseContainer ( CFContHandlerRef containerRef,
CFContCloseOptions options );
extern OSStatus PEF_GetContainerInfo ( CFContHandlerRef containerRef,
PBVersion infoVersion,
CFContContainerInfo * containerInfo );
extern OSStatus PEF_GetSectionCount ( CFContHandlerRef containerRef,
ItemCount * sectionCount );
extern OSStatus PEF_GetSectionInfo ( CFContHandlerRef containerRef,
ItemCount sectionIndex,
PBVersion infoVersion,
CFContSectionInfo * sectionInfo );
extern OSStatus PEF_FindSectionInfo ( CFContHandlerRef containerRef,
const CFContHashedName * sectionName,
PBVersion infoVersion,
ItemCount * sectionIndex, CFContSectionInfo * sectionInfo );
extern OSStatus PEF_SetSectionAddress ( CFContHandlerRef containerRef,
ItemCount sectionIndex,
LogicalAddress mappedAddress,
LogicalAddress runningAddress );
extern OSStatus PEF_GetAnonymousSymbolLocations ( CFContHandlerRef containerRef,
CFContLogicalLocation * mainLocation, CFContLogicalLocation * initLocation, CFContLogicalLocation * termLocation );
extern OSStatus PEF_GetExportedSymbolCount ( CFContHandlerRef containerRef,
ItemCount * exportCount );
extern OSStatus PEF_GetExportedSymbolInfo ( CFContHandlerRef containerRef,
CFContSignedIndex exportIndex,
PBVersion infoVersion,
CFContExportedSymbolInfo * exportInfo );
extern OSStatus PEF_FindExportedSymbolInfo ( CFContHandlerRef containerRef,
const CFContHashedName * exportName,
PBVersion infoVersion,
ItemCount * exportIndex, CFContExportedSymbolInfo * exportInfo );
extern OSStatus PEF_GetImportCounts ( CFContHandlerRef containerRef,
ItemCount * libraryCount, ItemCount * symbolCount );
extern OSStatus PEF_GetImportedLibraryInfo ( CFContHandlerRef containerRef,
ItemCount libraryIndex,
PBVersion infoVersion,
CFContImportedLibraryInfo * libraryInfo );
extern OSStatus PEF_GetImportedSymbolInfo ( CFContHandlerRef containerRef,
ItemCount symbolIndex,
PBVersion infoVersion,
CFContImportedSymbolInfo * symbolInfo );
extern OSStatus PEF_SetImportedSymbolAddress ( CFContHandlerRef containerRef,
ItemCount symbolIndex,
LogicalAddress symbolAddress );
extern OSStatus PEF_UnpackSection ( CFContHandlerRef containerRef,
ItemCount sectionIndex,
ByteCount sectionOffset,
LogicalAddress bufferAddress,
ByteCount bufferLength );
extern OSStatus PEF_RelocateSection ( CFContHandlerRef containerRef,
ItemCount sectionIndex );
extern OSStatus PEF_RelocateImportsOnly ( CFContHandlerRef containerRef,
ItemCount sectionIndex,
ItemCount libraryIndex );
struct CFragInitBlock {
void * contextID;
void * closureID;
void * connectionID;
SInt32 where; LogicalAddress address;
ByteCount length;
Boolean inPlace;
UInt8 resvA;
UInt16 resvB;
char * libName;
UInt32 resvC;
};
typedef struct CFragInitBlock CFragInitBlock;
#pragma options align=reset
#endif // __IOPEFINTERNALS__