Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes
sym_file Struct Reference

List of all members.

Public Member Functions

 sym_file (const FSSpec *spec)
 ~sym_file ()
voidoperator new (size_t n)
void operator delete (void *ptr)
bool init ()
bool open ()
bool close ()
bool seek (UInt32 position)
UInt32 read (void *buffer, UInt32 count)
const UInt8 * getName (UInt32 nameIndex)

Public Attributes

FSSpec mFileSpec
SInt16 mFileRef
UInt8 * mPageBuffer
UInt32 mPageOffset
UInt32 mBufferOffset
DiskSymbolHeaderBlock mHeader
ResourceTableEntry mCodeEntry
UInt8 ** mNameTable

Detailed Description

Definition at line 46 of file SymFiles.cpp.


Constructor & Destructor Documentation

Definition at line 73 of file SymFiles.cpp.

Definition at line 79 of file SymFiles.cpp.

{
       // this seems to die when we are being debugged.
       if (mFileRef != -1) {
              ::FSClose(mFileRef);
              mFileRef = -1;
       }
       
       if (mPageBuffer != NULL) {
              GC_free(mPageBuffer);
              mPageBuffer = NULL;
       }
       
       if (mNameTable != NULL) {
              UInt8** nameTable = mNameTable;
              UInt16 pageCount = mHeader.dshb_nte.dti_page_count;
              while (pageCount-- > 0) {
                     GC_free(*nameTable++);
              }
              GC_free(mNameTable);
              mNameTable = NULL;
       }
}

Here is the call graph for this function:


Member Function Documentation

Definition at line 166 of file SymFiles.cpp.

{
       if (mFileRef != -1) {
              ::FSClose(mFileRef);
              mFileRef = -1;
       }
       return true;
}

Here is the caller graph for this function:

const UInt8 * sym_file::getName ( UInt32  nameIndex)

Definition at line 208 of file SymFiles.cpp.

{
       UInt32 nameOffset = 2 * nameIndex;
       const UInt8* page = mNameTable[nameOffset / mHeader.dshb_page_size];
       const UInt8* name = page + (nameOffset % mHeader.dshb_page_size);
       return name;
}

Here is the caller graph for this function:

Definition at line 103 of file SymFiles.cpp.

{
       // open the file.
       if (!open())
              return false;

       // read the header. should make sure it is a valid .xSYM file, etc.
       DiskSymbolHeaderBlock& header = mHeader;
       long count = sizeof(header);
       if (::FSRead(mFileRef, (long*) &count, &header) != noErr || count != sizeof(header))
              return false;

       // read the name table.
       // mNameTable = new UInt8*[header.dshb_nte.dti_page_count];
       mNameTable = (UInt8**) GC_malloc_ignore_off_page(header.dshb_nte.dti_page_count * sizeof(UInt8*));
       if (mNameTable == NULL)
              return false;
       
       // seek to first page of the name table.
       ::SetFPos(mFileRef, fsFromStart, header.dshb_nte.dti_first_page * header.dshb_page_size);
       // read all of the pages into memory, for speed.
       for (int i = 0; i < header.dshb_nte.dti_page_count; i++) {
              // allocate each page atomically, so GC won't have to scan them.
              UInt8* page = mNameTable[i] = (UInt8*) GC_malloc_atomic(header.dshb_page_size);
              if (page == NULL)
                     return false;
              count = header.dshb_page_size;
              if (::FSRead(mFileRef, &count, page) != noErr || count != header.dshb_page_size)
                     return false;
       }

       // allocate the page buffer and initialize offsets.
       // mPageBuffer = (UInt8*) new UInt8[header.dshb_page_size];
       mPageBuffer = (UInt8*) GC_malloc_atomic(header.dshb_page_size);

       // read the RTE tables.
       seek(header.dshb_rte.dti_first_page * header.dshb_page_size + sizeof(ResourceTableEntry));
       for (int i = 1; i <= header.dshb_rte.dti_object_count; i++) {
              ResourceTableEntry resEntry;
              if (read(&resEntry, sizeof(resEntry)) == sizeof(resEntry)) {
                     switch (resEntry.rte_ResType) {
                     case 'CODE':
                            mCodeEntry = resEntry;
                            break;
                     case 'DATA':
                            break;
                     }
              }
       }
       
       return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 156 of file SymFiles.cpp.

{
       if (mFileRef == -1) {
              // open the specified symbol file.
              if (::FSpOpenDF(&mFileSpec, fsRdPerm, &mFileRef) != noErr)
                     return false;
       }
       return true;
}

Here is the caller graph for this function:

void sym_file::operator delete ( void ptr) [inline]

Definition at line 62 of file SymFiles.cpp.

Here is the call graph for this function:

void* sym_file::operator new ( size_t  n) [inline]

Definition at line 61 of file SymFiles.cpp.

Here is the call graph for this function:

UInt32 sym_file::read ( void buffer,
UInt32  count 
)

Definition at line 197 of file SymFiles.cpp.

{
       // we don't handle reads that aren't on the current page.
       if ((mBufferOffset + count) < mHeader.dshb_page_size) {
              ::BlockMoveData(mPageBuffer + mBufferOffset, buffer, count);
              mBufferOffset += count;
              return count;
       }
       return 0;
}

Here is the caller graph for this function:

bool sym_file::seek ( UInt32  position)

Definition at line 175 of file SymFiles.cpp.

{
       if (position != (mPageOffset + mBufferOffset)) {
              // if position is off current page, the resync the buffer.
              UInt32 pageSize = mHeader.dshb_page_size;
              if (position < mPageOffset || position >= (mPageOffset + pageSize)) {
                     // make sure the file is open.
                     if (!open())
                            return false;
                     // read the nearest page to this offset.
                     mPageOffset = (position - (position % pageSize));
                     if (::SetFPos(mFileRef, fsFromStart, mPageOffset) != noErr)
                            return false;
                     long count = pageSize;
                     if (::FSRead(mFileRef, &count, mPageBuffer) != noErr)
                            return false;
              }
              mBufferOffset = (position - mPageOffset);
       }
       return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 52 of file SymFiles.cpp.

Definition at line 55 of file SymFiles.cpp.

Definition at line 49 of file SymFiles.cpp.

Definition at line 48 of file SymFiles.cpp.

Definition at line 54 of file SymFiles.cpp.

Definition at line 56 of file SymFiles.cpp.

Definition at line 50 of file SymFiles.cpp.

Definition at line 51 of file SymFiles.cpp.


The documentation for this struct was generated from the following file: