Ejemplo n.º 1
0
void
EmitCvPublics (
    PIMAGE pimage,
    PCVINFO CvInfo
    )

/*++

Routine Description:

    Writes the cv publics to disk.

Arguments:

    PtrExtern - Pointer to external structure.

Return Value:

    None.

--*/

{
    SHORT isecAbsolute = (SHORT) (pimage->ImgFileHdr.NumberOfSections + 1);
    LEXT *plext;
    LEXT *plextNext;

    for (plext = CvInfo->pmod->plextPublic; plext != NULL; plext = plextNext) {
        EmitOneCvPublic(pimage, plext->pext, isecAbsolute);
        plextNext = plext->plextNext;
        FreePv(plext);
    }

    // Walk the common vars which this module saw first, and emit public
    // records for them here.

    while (CvInfo->pmod->plextCommon != NULL) {
        LEXT *plext = CvInfo->pmod->plextCommon;

        // Make sure the symbol is still COMMON and defined

        if ((plext->pext->Flags & (EXTERN_DEFINED | EXTERN_COMMON)) ==
            (EXTERN_DEFINED | EXTERN_COMMON))
        {
            EmitOneCvPublic(pimage, plext->pext, isecAbsolute);
        }

        CvInfo->pmod->plextCommon = plext->plextNext;
        FreePv(plext);
    }
}
Ejemplo n.º 2
0
//-----------------------------------------------------------------------------
// Memory deallocation
//-----------------------------------------------------------------------------
void CUtlMemoryBase::Purge()
{
	if ( !IsExternallyAllocated() )
	{
		if (m_pMemory)
		{
			UTLMEMORY_TRACK_FREE();
			FreePv( m_pMemory );
			m_pMemory = 0;
		}
		m_nAllocationCount = 0;
	}
}
Ejemplo n.º 3
0
void
SetDefinedExt(PEXTERNAL pext, BOOL fNowDefined, PST pst)
{
    if (!!(pext->Flags & EXTERN_DEFINED) == !!fNowDefined) {
        return;      // already in desired state
    }

    if (fNowDefined) {
        if (!fINCR && pext->Flags & EXTERN_MULT_REFS) {
            // Free the list of modules which referenced this symbol (on a non-ilink)

            while (pext->pmodsFirst != NULL) {
                PMODS pmods = pext->pmodsFirst;
                pext->pmodsFirst = pmods->pmodsNext;
                FreePv(pmods);
            }

            pext->Flags &= ~EXTERN_MULT_REFS;
        }

        pext->Flags |= EXTERN_DEFINED;

        if (pext->pextNextUndefined != NULL) {
            pext->pextNextUndefined->ppextPrevUndefined =
                pext->ppextPrevUndefined;
        }
        *pext->ppextPrevUndefined = pext->pextNextUndefined;
        if (pst->ppextLastUndefined == &pext->pextNextUndefined) {
            pst->ppextLastUndefined = pext->ppextPrevUndefined;
        }

        // bug trap -- not strictly necessary
        pext->ppextPrevUndefined = NULL;
        pext->pextNextUndefined = NULL;
    } else {
        PEXTERNAL *ppextLoc;

        pext->Flags &= ~EXTERN_DEFINED;

        // Add the symbol to a link list of external symbols.  The list is
        // doubly linked to support deletion.

        ppextLoc = pst->ppextLastUndefined;

        assert(*ppextLoc == NULL ||
           (*ppextLoc)->ppextPrevUndefined == ppextLoc);

        pext->pextNextUndefined = *ppextLoc;
        pext->ppextPrevUndefined = ppextLoc;

        *ppextLoc = pext;
        if (pext->pextNextUndefined != NULL) {
            pext->pextNextUndefined->ppextPrevUndefined =
                &pext->pextNextUndefined;
        }
        if (pst->ppextLastUndefined == ppextLoc) {
            pst->ppextLastUndefined = &pext->pextNextUndefined;
        }

        // on an ilink we want to keep the list of references        
        if (!fINCR) {
            pext->pmodOnly = NULL;  // no references to this external
        }
    }
}
Ejemplo n.º 4
0
void
EmitCvInfo (
    PIMAGE pimage)

/*++

Routine Description:



Arguments:

    None.

Return Value:

    None.

--*/

{
    WORD i;
    DWORD li;
    DWORD lj;
    DWORD nameLen;
    DWORD numSubsections;
    DWORD numLocals = 0;
    DWORD numTypes = 0;
    DWORD numLinenums = 0;
    DWORD libStartSeek;
    DWORD libEndSeek;
    DWORD segTableStartSeek;
    DWORD segTableEndSeek;
    BYTE cbFilename;
    char *szFilename;
    ENM_SEC enm_sec;
    ENM_LIB enm_lib;
    PSEC psec;
    PLIB plib;
    DWORD csstPublicSym;
    DWORD cSstSrcModule=0;

    struct {
        WORD cbDirHeader;
        WORD cbDirEntry;
        DWORD cDir;
        DWORD lfoNextDir;
        DWORD flags;
    } dirHdr;

    struct {
        WORD subsection;
        WORD imod;
        DWORD lfo;
        DWORD cb;
    } subDir;

    struct {
        WORD ovlNumber;
        WORD iLib;
        WORD cSeg;
        WORD style;
    } entry;

    struct {
        WORD seg;
        WORD pad;
        DWORD offset;
        DWORD cbSeg;
    } entrySegArray;

    struct {
        WORD flags;
        WORD iovl;
        WORD igr;
        WORD isgPhy;
        WORD isegName;
        WORD iClassName;
        DWORD segOffset;
        DWORD cbSeg;
    } segTable;


    // Count the number of sstSymbols, sstTypes, sstSrcLnSeg
    // we have gathered from the object files.

    for (li = 0; li < NextCvObject; li++) {
         if (CvInfo[li].Locals.PointerToSubsection) {
             ++numLocals;
         }
         if (CvInfo[li].Types.PointerToSubsection) {
             ++numTypes;
         }
         if (CvInfo[li].Linenumbers.PointerToSubsection) {
             ++numLinenums;
         }
    }


    // Emit the sstModule subsection.

    entry.ovlNumber = 0;
    entry.style = 0x5643;               // "CV"

    for (li = 0; li < NextCvObject; li++) {
        CVSEG *pcvseg = PcvsegMapPmod(CvInfo[li].pmod, &entry.cSeg, pimage);
        WORD icvseg;

        szFilename = CvInfo[li].ObjectFilename;
        cbFilename = (BYTE) strlen(szFilename);
        nameLen = cbFilename;

        i = 0;

        if (FIsLibPMOD(CvInfo[li].pmod)) {
            InitEnmLib(&enm_lib, pimage->libs.plibHead);
            while (FNextEnmLib(&enm_lib)) {
                plib = enm_lib.plib;

                if (plib->szName != NULL) {
                    // Only named libraries are counted

                    i++;

                    if (plib == CvInfo[li].pmod->plibBack) {
                        break;
                    }
                }
            }
            EndEnmLib(&enm_lib);
        }

        entry.iLib = i;

        CvInfo[li].Module.PointerToSubsection = FileTell(FileWriteHandle);
        FileWrite(FileWriteHandle, &entry, sizeof(entry));

        // Generate the section array for this sstModule.

        for (icvseg = 0; icvseg < entry.cSeg; icvseg++) {
            CVSEG *pcvsegNext;

            entrySegArray.seg = PsecPCON(pcvseg->pconFirst)->isec;
            entrySegArray.pad = 0;
            entrySegArray.offset = pcvseg->pconFirst->rva -
                                    PsecPCON(pcvseg->pconFirst)->rva;
            entrySegArray.cbSeg =
              (pcvseg->pconLast->rva + pcvseg->pconLast->cbRawData) -
              pcvseg->pconFirst->rva;

            FileWrite(FileWriteHandle, &entrySegArray, sizeof(entrySegArray));

            pcvsegNext = pcvseg->pcvsegNext;
            FreePv(pcvseg);
            pcvseg = pcvsegNext;
        }
        assert(pcvseg == NULL);

        FileWrite(FileWriteHandle, &cbFilename, sizeof(BYTE));
        FileWrite(FileWriteHandle, szFilename, nameLen);
        CvInfo[li].Module.SizeOfSubsection =
            FileTell(FileWriteHandle) - CvInfo[li].Module.PointerToSubsection;
    }

    // Emit the sstPublicSym subsection.

    csstPublicSym = 0;   // actual number of such subsections
    ChainCvPublics(pimage);

    for (li = 0; li < NextCvObject; li++) {
        DWORD icvOther;

        if (CvInfo[li].Publics.PointerToSubsection == 0xFFFFFFFF) {
            // This is a dup of another module that has been emitted

            CvInfo[li].Publics.PointerToSubsection = 0;
            continue;
        }

        csstPublicSym++;

        CvInfo[li].Publics.PointerToSubsection = FileTell(FileWriteHandle);

        // Write signature

        lj = 1;
        FileWrite(FileWriteHandle, &lj, sizeof(DWORD));

        EmitCvPublics(pimage, &CvInfo[li]);

        if (FIsLibPMOD(CvInfo[li].pmod)) {
            for (icvOther = li + 1; icvOther < NextCvObject; icvOther++) {
                // Emit this module if
                //    (Module is from same library as current module AND
                //     Module has the same name as the current module)

                if (CvInfo[li].pmod->plibBack != CvInfo[icvOther].pmod->plibBack) {
                    continue;
                }

                if (strcmp(CvInfo[li].ObjectFilename, CvInfo[icvOther].ObjectFilename) != 0) {
                    continue;
                }

                EmitCvPublics(pimage, &CvInfo[icvOther]);
                CvInfo[icvOther].Publics.PointerToSubsection = 0xFFFFFFFF;
            }
        }

        CvInfo[li].Publics.SizeOfSubsection =
            FileTell(FileWriteHandle) - CvInfo[li].Publics.PointerToSubsection;
    }

    // The sstSymbols and sstTypes subsections have already been
    // emitted directly from the object files. The sstSrcLnSeg
    // have also been emitted indirectly from the object files.

    // Emit the sstLibraries subsection.

    libStartSeek = FileTell(FileWriteHandle);
    nameLen = 0;
    FileWrite(FileWriteHandle, &nameLen, sizeof(BYTE));

    InitEnmLib(&enm_lib, pimage->libs.plibHead);
    while (FNextEnmLib(&enm_lib)) {
        plib = enm_lib.plib;

        if (plib->szName != NULL) {
            nameLen = (BYTE) strlen(plib->szName);
            FileWrite(FileWriteHandle, &nameLen, sizeof(BYTE));
            FileWrite(FileWriteHandle, plib->szName, nameLen);
        }
    }

    libEndSeek = FileTell(FileWriteHandle);

    // Emit the sstSegTable subsection.

    segTableStartSeek = FileTell(FileWriteHandle);
    i = (WORD) (pimage->ImgFileHdr.NumberOfSections + 1);
    FileWrite(FileWriteHandle, &i, sizeof(WORD));
    FileWrite(FileWriteHandle, &i, sizeof(WORD));
    segTable.iovl = 0;
    segTable.igr = 0;
    for (i = 1; i <= pimage->ImgFileHdr.NumberOfSections; i++) {
        InitEnmSec(&enm_sec, &pimage->secs);
        while (FNextEnmSec(&enm_sec)) {
            psec = enm_sec.psec;

            if (psec->isec == i) {
                break;
            }
        }
        EndEnmSec(&enm_sec);

        segTable.flags = 0x0108;
        if (psec->flags & IMAGE_SCN_MEM_READ) {
            segTable.flags |= 0x1;
        }
        if (psec->flags & IMAGE_SCN_MEM_WRITE) {
            segTable.flags |= 0x2;
        }
        if (psec->flags & IMAGE_SCN_MEM_EXECUTE) {
            segTable.flags |= 0x4;
        }

        // In the case of M68K pass the MacResource number
        // instead of the actual section number.
        segTable.isgPhy = fM68K ? psec->iResMac : i;
        segTable.isegName = 0xffff;    // No name
        segTable.iClassName = 0xffff;  // No name
        
        // If it is M68K and the psec->iResMac is 0, then 
        // provide the offset from the beginning of the data0
        segTable.segOffset = fM68K ? psec->dwM68KDataOffset : 0;
        
        segTable.cbSeg = psec->cbVirtualSize;
        FileWrite(FileWriteHandle, &segTable, sizeof(segTable));
    }

    // Write another sstSegMap entry for all absolute symbols.

    segTable.flags = 0x0208;           // absolute
    segTable.isgPhy = 0;
    segTable.isegName = 0xffff;        // No name
    segTable.iClassName = 0xffff;      // No name
    segTable.cbSeg = 0xffffffff;       // Allow full 32 bit range
    FileWrite(FileWriteHandle, &segTable, sizeof(segTable));

    segTableEndSeek = FileTell(FileWriteHandle);

    // Write SstSrcModul entries

    for(li = 0; li < NextCvObject; li++)       // for each module
    {
        if (CvInfo[li].pmod->pModDebugInfoApi == NULL) {
            // Don't write linenumber records if there aren't any

            CvInfo[li].pmod->PointerToSubsection = 0;
        } else {
            CvInfo[li].pmod->PointerToSubsection = FileTell(FileWriteHandle);
            FileWrite(FileWriteHandle,CvInfo[li].pmod->pSstSrcModInfo,CvInfo[li].pmod->cbSstSrcModInfo);
            cSstSrcModule++;
        }
     }

    // Emit the Subsection directory.

    CvSeeks.SubsectionDir = FileTell(FileWriteHandle);

    // We'll have a sstModule for every object, an sstPublicSym for every
    // object with a unique name, and optionaly some
    // sstSymbols and sstTypes.

    numSubsections = NextCvObject + csstPublicSym +
                     numLocals +
                     numTypes +
                     numLinenums +
                     cSstSrcModule +
                     2; // include sstLibraries & sstSegTable

    dirHdr.cbDirHeader = sizeof(dirHdr);
    dirHdr.cbDirEntry = sizeof(subDir);
    dirHdr.cDir = numSubsections;
    dirHdr.lfoNextDir = 0;
    dirHdr.flags = 0;

    FileWrite(FileWriteHandle, &dirHdr, sizeof(dirHdr));

    // Emit the sstModule entries.

    subDir.subsection = 0x120;
    for (li = 0; li < NextCvObject; li++) {
        subDir.imod = (WORD)(li + 1);
        subDir.lfo = CvInfo[li].Module.PointerToSubsection - CvSeeks.Base;
        subDir.cb = CvInfo[li].Module.SizeOfSubsection;
        FileWrite(FileWriteHandle, &subDir, sizeof(subDir));
    }

    // Emit the sstPublicSym entries.

    subDir.subsection = 0x123;      // sstPublicSym
    for (li = 0; li < NextCvObject; li++) {
        if (CvInfo[li].Publics.PointerToSubsection == 0) {
            // this module doesn't have one (duplicate name)

            continue;
        }

        subDir.imod = (WORD)(li + 1);
        subDir.lfo = CvInfo[li].Publics.PointerToSubsection - CvSeeks.Base;
        subDir.cb = CvInfo[li].Publics.SizeOfSubsection;
        FileWrite(FileWriteHandle, &subDir, sizeof(subDir));
    }

    // Emit the sstSymbols entries.

    subDir.subsection = 0x124; // sstSymbols
    for (li = 0; li < NextCvObject; li++) {
        if (CvInfo[li].Locals.PointerToSubsection) {
            subDir.imod = (WORD)(li + 1);
            subDir.lfo = CvInfo[li].Locals.PointerToSubsection - CvSeeks.Base;
            subDir.cb = CvInfo[li].Locals.SizeOfSubsection;
            FileWrite(FileWriteHandle, &subDir, sizeof(subDir));
        }
    }

    // Emit the SstSrcModule entries

    subDir.subsection=0x127;  // SstSrcModule
    for(li = 0; li < NextCvObject ; li++) {
         if (CvInfo[li].pmod->PointerToSubsection) {
             subDir.imod = (WORD)(li + 1);
             subDir.lfo =  CvInfo[li].pmod->PointerToSubsection - CvSeeks.Base;
             subDir.cb = CvInfo[li].pmod->cbSstSrcModInfo;
             FileWrite(FileWriteHandle,&subDir,sizeof(subDir));
         }
    }

    // Emit the sstTypes entries.

    for (li = 0; li < NextCvObject; li++) {
        if (CvInfo[li].Types.PointerToSubsection) {
            subDir.subsection = (WORD) (CvInfo[li].Types.Precompiled ? 0x12f : 0x121);
            subDir.imod = (WORD)(li + 1);
            subDir.lfo = CvInfo[li].Types.PointerToSubsection - CvSeeks.Base;
            subDir.cb = CvInfo[li].Types.SizeOfSubsection;
            FileWrite(FileWriteHandle, &subDir, sizeof(subDir));
        }
    }

    // Emit the sstLibraries entry.

    subDir.subsection = 0x128;
    subDir.imod = 0xffff;  // -1
    subDir.lfo = libStartSeek - CvSeeks.Base;
    subDir.cb = libEndSeek - libStartSeek;
    FileWrite(FileWriteHandle, &subDir, sizeof(subDir));

    // Emit the sstSegTable entry.

    subDir.subsection = 0x12d;
    subDir.imod = 0xffff;  // -1
    subDir.lfo = segTableStartSeek - CvSeeks.Base;
    subDir.cb = segTableEndSeek - segTableStartSeek;
    FileWrite(FileWriteHandle, &subDir, sizeof(subDir));
}