Logo Search packages:      
Sourcecode: virtualbox-ose version File versions

static bool KPRF_NAME() IsValid ( KPRF_TYPE(PC, HDR)  pHdr,
KU32  cb,
FILE *  pOut 
) [static]

Validates the non-header parts of a data-set.

Returns:
true if valid.

false if invalid. (written description to pOut)

Parameters:
pHdr Pointer to the data set.
cb The size of the data set.
pOut Where to write error messages.

Todo:
more validation here..

Definition at line 38 of file prfreader.cpp.h.

References KPRF_ALIGN, KPRF_OFF2PTR, KPRF_OFFSETOF, KPRF_TYPE, and strlen().

{
    KPRF_TYPE(,UPTR) uMaxPtr = ~(KPRF_TYPE(,UPTR))0 - pHdr->uBasePtr;

    /*
     * Iterate the module segments.
     */
    KU32 off = pHdr->offModSegs;
    while (off < pHdr->offModSegs + pHdr->cbModSegs)
    {
        KPRF_TYPE(PC,MODSEG) pCur = KPRF_OFF2PTR(PC,MODSEG, off, pHdr);
        KU32 cbCur = KPRF_OFFSETOF(MODSEG, szPath[pCur->cchPath + 1]);
        cbCur = KPRF_ALIGN(cbCur, KPRF_SIZEOF(UPTR));
        if (cbCur + off > pHdr->offModSegs + pHdr->cbModSegs)
        {
            fprintf(pOut, "The module segment record at 0x%x is too long!\n", off);
            return false;
        }
        if (pCur->uBasePtr > uMaxPtr)
            fprintf(pOut, "warning: The module segment record at 0x%x has a too high base address.\n", off);

        if (strlen(pCur->szPath) != pCur->cchPath)
        {
            fprintf(pOut, "The module segment record at 0x%x has an invalid path length 0x%x it the actual length is 0x%x\n",
                    pCur->cchPath, strlen(pCur->szPath));
            return false;
        }

        /* next */
        off += cbCur;
    }


    /*
     * Iterate the functions.
     */
    KPRF_TYPE(PC,FUNC) paFuncs = KPRF_OFF2PTR(PC,FUNC, pHdr->offFunctions, pHdr);
    for (KU32 i = 0; i < pHdr->cFunctions; i++)
    {
        KPRF_TYPE(PC,FUNC) pCur = &paFuncs[i];
        if (pCur->uEntryPtr > uMaxPtr)
            fprintf(pOut, "warning: Function 0x%x has a too high base address.\n", i);
        if (pCur->offModSeg)
        {
            if (    pCur->offModSeg < pHdr->offModSegs
                ||  pCur->offModSeg >= pHdr->offModSegs + pHdr->cbModSegs
                ||  pCur->offModSeg != KPRF_ALIGN(pCur->offModSeg, sizeof(pCur->uEntryPtr))
               )
            {
                fprintf(pOut, "Function 0x%x has an invalid offModSeg value (0x%x).\n", i, pCur->offModSeg);
                return false;
            }
            /** @todo more validation here.. */
        }
    }


    /*
     * Validate the threads.
     */
    KPRF_TYPE(PC,THREAD) paThreads = KPRF_OFF2PTR(PC,THREAD, pHdr->offThreads, pHdr);
    for (KU32 i = 0; i < pHdr->cThreads; i++)
    {
        KPRF_TYPE(PC,THREAD) pCur = &paThreads[i];
        if (pCur->uStackBasePtr > uMaxPtr)
            fprintf(pOut, "warning: Thread 0x%x has a too high base address.\n", i);
        switch (pCur->enmState)
        {
            case KPRF_TYPE(,THREADSTATE_ACTIVE):
            case KPRF_TYPE(,THREADSTATE_SUSPENDED):
            case KPRF_TYPE(,THREADSTATE_OVERFLOWED):
            case KPRF_TYPE(,THREADSTATE_TERMINATED):
                break;
            default:
                fprintf(pOut, "Thread 0x%x has an invalid state value (0x%x).\n", i, pCur->enmState);
                return false;
        }
    }


    return true;
}


Generated by  Doxygen 1.6.0   Back to index