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

int kldrDyldFindNewModule ( const char *  pszName,
const char *  pszPrefix,
const char *  pszSuffix,
KLDRDYLDSEARCH  enmSearch,
unsigned  fFlags,
PPKLDRDYLDMOD  ppMod 
)

Locates and opens a module using the specified search method.

Returns:
0 and *ppMod on success, non-zero OS specific error on failure.
Parameters:
pszName Partial or complete name, it's specific to the search method to determin which.
pszPrefix Prefix than can be used when searching.
pszSuffix Suffix than can be used when searching.
enmSearch The file search method to apply.
fFlags Search flags.
ppMod Where to store the file provider instance on success.

Definition at line 382 of file kLdrDyldFind.c.

References KLDRMOD::cchFilename, KLDRDYLDMOD::fGlobalOrSpecific, KLDRDYLD_LOAD_FLAGS_EXECUTABLE, KLDRDYLDFIND_ASSERT, kldrDyldFindDoDllSearch(), kldrDyldFindDoExeSearch(), kldrDyldFindTryOpen(), kLdrDyldHead, kldrDyldModCreate(), kldrDyldModMarkGlobal(), KLDRYDLD_LOAD_FLAGS_SPECIFIC_MODULE, KSIZE, KLDRDYLDMOD::Load, NULL, KLDRDYLDMOD::pMod, KLDRDYLDMOD::pNext, and KLDRMOD::pszFilename.

Referenced by kldrDyldDoLoad(), kldrDyldGetPrerequisite(), and kLdrDyldLoadExe().

{
    int rc;
    PKRDR pRdr = NULL;

    *ppMod = NULL;

    /*
     * If this isn't just a filename, we the caller has specified a file
     * that should be opened directly and not a module name to be searched for.
     */
    if (!kHlpIsFilenameOnly(pszName))
        rc = kldrDyldFindTryOpen(pszName, &pRdr);
    else if (!(fFlags & KLDRDYLD_LOAD_FLAGS_EXECUTABLE))
        rc = kldrDyldFindDoDllSearch(pszName, pszPrefix, pszSuffix, enmSearch, fFlags, &pRdr);
    else
        rc = kldrDyldFindDoExeSearch(pszName, pszPrefix, pszSuffix, enmSearch, fFlags, &pRdr);
    if (!rc)
    {
#ifdef KLDRDYLDFIND_STRICT
        /* Sanity check of kldrDyldFindExistingModule. */
        if (fFlags & KLDRYDLD_LOAD_FLAGS_SPECIFIC_MODULE)
        {
            const char     *pszFilename = kRdrName(pRdr);
            const KSIZE     cchFilename = kHlpStrLen(pszFilename);
            PKLDRDYLDMOD    pCur;
            for (pCur = kLdrDyldHead; pCur; pCur = pCur->Load.pNext)
                KLDRDYLDFIND_ASSERT(    pCur->pMod->cchFilename != cchFilename
                                    ||  kHlpMemComp(pCur->pMod->pszFilename, pszFilename, cchFilename));
        }
#endif

        /*
         * Check for matching non-global modules that should be promoted.
         */
        if (!(fFlags & KLDRYDLD_LOAD_FLAGS_SPECIFIC_MODULE))
        {
            const char     *pszFilename = kRdrName(pRdr);
            const KSIZE     cchFilename = kHlpStrLen(pszFilename);
            PKLDRDYLDMOD    pCur;
            for (pCur = kLdrDyldHead; pCur; pCur = pCur->Load.pNext)
            {
                if (    !pCur->fGlobalOrSpecific
                    &&  pCur->pMod->cchFilename == cchFilename
                    &&  !kHlpMemComp(pCur->pMod->pszFilename, pszFilename, cchFilename))
                {
                    kRdrClose(pRdr);
                    kldrDyldModMarkGlobal(pCur);
                    *ppMod = pCur;
                    return 0;
                }
                KLDRDYLDFIND_ASSERT(    pCur->pMod->cchFilename != cchFilename
                                    ||  kHlpMemComp(pCur->pMod->pszFilename, pszFilename, cchFilename));
            }
        }

        /*
         * Create a new module.
         */
        rc = kldrDyldModCreate(pRdr, fFlags, ppMod);
        if (rc)
            kRdrClose(pRdr);
    }
    return rc;
}


Generated by  Doxygen 1.6.0   Back to index