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

int kldrDyldModCreate ( PKRDR  pRdr,
KU32  fFlags,
PPKLDRDYLDMOD  ppMod 
)

Creates a module from the specified file provider instance.

Returns:
0 on success and *ppMod pointing to the new instance. On failure a non-zero kLdr status code is returned.
Parameters:
pRdr The file provider instance.
fFlags Load/search flags.
ppMod Where to put the pointer to the new module on success.

Todo:
deal with fFlags (exec/dll)

Todo:
Check up the cpu architecture.

Definition at line 70 of file kLdrDyldMod.c.

References KLDRDYLDMOD::Bind, KLDRDYLDMOD::cDepRefs, KLDRDYLDMOD::cDynRefs, KLDRDYLDMOD::cPrereqs, KLDRDYLDMOD::cRefs, KLDRDYLDMOD::enmState, KLDRMOD::enmType, KLDRDYLDMOD::f25Reserved, KLDRDYLDMOD::fAllocatedTLS, KLDRDYLDMOD::fAlreadySeen, KLDRDYLDMOD::fBindable, KLDRDYLDMOD::fExecutable, KLDRDYLDMOD::fGlobalOrSpecific, KLDRDYLDMOD::fInitList, KLDRDYLDMOD::fMapped, KLDRDYLDMOD::hMod, KLDRDYLDMOD::InitTerm, KCPUARCH_UNKNOWN, KERR_NO_MEMORY, KLDR_ERR_NOT_DLL, KLDR_ERR_NOT_EXE, KLDRDYLD_LOAD_FLAGS_EXECUTABLE, kldrDyldFailure(), kLdrDyldHead, KLDRDYLDMOD_ASSERT, kldrDyldModClearBindable(), kldrDyldModMarkGlobal(), kldrDyldModMarkSpecific(), kldrDyldModSetBindable(), kLdrDyldTail, KLDRDYMOD_MAGIC, kLdrModClose(), kLdrModOpenFromRdr(), KLDRSTATE_OPEN, KLDRTYPE_CORE, KLDRTYPE_EXECUTABLE_FIXED, KLDRTYPE_EXECUTABLE_PIC, KLDRTYPE_EXECUTABLE_RELOCATABLE, KLDRTYPE_FORWARDER_DLL, KLDRTYPE_OBJECT, KLDRTYPE_SHARED_LIBRARY_FIXED, KLDRTYPE_SHARED_LIBRARY_PIC, KLDRTYPE_SHARED_LIBRARY_RELOCATABLE, KLDRYDLD_LOAD_FLAGS_GLOBAL_SYMBOLS, KLDRYDLD_LOAD_FLAGS_SPECIFIC_MODULE, KLDRDYLDMOD::Load, NULL, KLDRDYLDMOD::papPrereqs, KLDRDYLDMOD::pMod, KLDRDYLDMOD::pNext, KLDRDYLDMOD::pPrev, KLDRDYLDMOD::u32MagicHead, and KLDRDYLDMOD::u32MagicTail.

Referenced by kldrDyldFindNewModule().

{
    PKLDRDYLDMOD pMod;
    PKLDRMOD pRawMod;
    int rc;

    *ppMod = NULL;

/** @todo deal with fFlags (exec/dll) */
/** @todo Check up the cpu architecture. */

    /*
     * Try open an module interpreter.
     */
    rc = kLdrModOpenFromRdr(pRdr, 0 /*fFlags*/, KCPUARCH_UNKNOWN, &pRawMod);
    if (rc)
        return kldrDyldFailure(rc, "%s: %rc", kRdrName(pRdr), rc);

    /*
     * Match the module aginst the load flags.
     */
    switch (pRawMod->enmType)
    {
        case KLDRTYPE_EXECUTABLE_FIXED:
        case KLDRTYPE_EXECUTABLE_RELOCATABLE:
        case KLDRTYPE_EXECUTABLE_PIC:
            if (!(fFlags & KLDRDYLD_LOAD_FLAGS_EXECUTABLE))
            {
                kLdrModClose(pRawMod);
                return KLDR_ERR_NOT_EXE;
            }
            break;

        case KLDRTYPE_OBJECT: /* We can handle these as DLLs. */
        case KLDRTYPE_SHARED_LIBRARY_FIXED:
        case KLDRTYPE_SHARED_LIBRARY_RELOCATABLE:
        case KLDRTYPE_SHARED_LIBRARY_PIC:
        case KLDRTYPE_FORWARDER_DLL:
            if (fFlags & KLDRDYLD_LOAD_FLAGS_EXECUTABLE)
            {
                kLdrModClose(pRawMod);
                return KLDR_ERR_NOT_DLL;
            }
            break;

        default:
            KLDRDYLDMOD_ASSERT(!"Bad enmType!");
        case KLDRTYPE_CORE:
            return fFlags & KLDRDYLD_LOAD_FLAGS_EXECUTABLE ? KLDR_ERR_NOT_EXE : KLDR_ERR_NOT_DLL;
    }

    /*
     * Allocate a new dyld module.
     */
    pMod = (PKLDRDYLDMOD)kHlpAlloc(sizeof(*pMod));
    if (pMod)
    {
        pMod->enmState = KLDRSTATE_OPEN;
        pMod->pMod = pRawMod;
        pMod->hMod = pMod;
        pMod->cDepRefs = pMod->cDynRefs = pMod->cRefs = 0;
        switch (pRawMod->enmType)
        {
            case KLDRTYPE_EXECUTABLE_FIXED:
            case KLDRTYPE_EXECUTABLE_RELOCATABLE:
            case KLDRTYPE_EXECUTABLE_PIC:
                pMod->fExecutable = 1;
                break;
            default:
                pMod->fExecutable = 0;
                break;
        }
        pMod->fGlobalOrSpecific = 0;
        pMod->fBindable = 0;
        pMod->fInitList = 0;
        pMod->fAlreadySeen = 0;
        pMod->fMapped = 0;
        pMod->fAllocatedTLS = 0;
        pMod->f25Reserved = 0;
        pMod->InitTerm.pNext = NULL;
        pMod->InitTerm.pPrev = NULL;
        pMod->Bind.pNext = NULL;
        pMod->Bind.pPrev = NULL;
        pMod->cPrereqs = 0;
        pMod->papPrereqs = NULL;
        pMod->u32MagicHead = KLDRDYMOD_MAGIC;
        pMod->u32MagicTail = KLDRDYMOD_MAGIC;

        /* it. */
        pMod->Load.pNext = NULL;
        pMod->Load.pPrev = kLdrDyldTail;
        if (kLdrDyldTail)
            kLdrDyldTail->Load.pNext = pMod;
        else
            kLdrDyldHead = pMod;
        kLdrDyldTail = pMod;

        /* deal with the remaining flags. */
        if (fFlags & KLDRYDLD_LOAD_FLAGS_SPECIFIC_MODULE)
            kldrDyldModMarkSpecific(pMod);
        else
            kldrDyldModMarkGlobal(pMod);

        if (fFlags & KLDRYDLD_LOAD_FLAGS_GLOBAL_SYMBOLS)
            kldrDyldModSetBindable(pMod, 0 /* not deep binable */);
        else
            kldrDyldModClearBindable(pMod);

        /*
         * We're good.
         */
        *ppMod = pMod;
        rc = 0;
    }
    else
    {
        kLdrModClose(pRawMod);
        rc = KERR_NO_MEMORY;
    }
    return rc;
}


Generated by  Doxygen 1.6.0   Back to index