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

static int krdrFileGenericMap ( PKRDR  pRdr,
PKRDRFILEPREP  pPrep,
KU32  cSegments,
PCKLDRSEG  paSegments,
KBOOL  fFixed 
) [static]

Generic implementation of krdrFileMap.

Definition at line 787 of file kRdrFile.cpp.

References KRDRFILEPREP::cb, KLDRSEG::cbFile, KPROT_EXECUTE_READWRITE, krdrFileGenericProtect(), NIL_KLDRADDR, KLDRSEG::offFile, KRDROPS::pfnRead, KRDR::pOps, KRDRFILEPREP::pv, and KLDRSEG::RVA.

Referenced by krdrFileMap().

{
    int rc;
    KU32 i;

    /*
     * Generic mapping code using kHlpPageAlloc(), kHlpPageFree() and kHlpPageProtect().
     */
    rc = kHlpPageAlloc(&pPrep->pv, pPrep->cb, KPROT_EXECUTE_READWRITE, fFixed);
    if (rc)
        return rc;

    /*
     * Load the data.
     */
    for (i = 0; i < cSegments; i++)
    {
        void *pv;

        if (    paSegments[i].RVA == NIL_KLDRADDR
            ||  paSegments[i].cbFile <= 0)
            continue;

        pv = (KU8 *)pPrep->pv + paSegments[i].RVA;
        rc = pRdr->pOps->pfnRead(pRdr, pv, paSegments[i].cbFile, paSegments[i].offFile);
        if (rc)
            break;
    }

    /*
     * Set segment protection.
     */
    if (!rc)
    {
        rc = krdrFileGenericProtect(pRdr, pPrep, cSegments, paSegments, 0 /* protect */);
        if (!rc)
            return 0;
        krdrFileGenericProtect(pRdr, pPrep, cSegments, paSegments, 1 /* unprotect */);
    }

    /* bailout */
    kHlpPageFree(pPrep->pv, pPrep->cb);
    return rc;
}


Generated by  Doxygen 1.6.0   Back to index