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

void kLdrDyldLoadExe ( PCKLDREXEARGS  pArgs,
void *  pvOS 

fix this mess...
Bootstrap an executable.

This is called from the executable stub to replace the stub and run the executable specified in the argument package.

Since this is boostrap time there isn't anything to return to. So, instead the process will be terminated upon failure.

We also have to keep in mind that this function is called on a small, small, stack and therefore any kind of large stack objects or deep recursions must be avoided. Since loading the executable will involve more or less all operations in the loader, this restriction really applies everywhere.

pArgs Pointer to the argument package residing in the executable stub.
pvOS OS specific argument.

make sense of this default prefix/suffix stuff.

append that path to the one for the specified search method.

create a function for doing this, an exposed api preferably.

Definition at line 235 of file kLdrDyld.c.

References KLDREXEARGS::enmSearch, KLDREXEARGS::fFlags, g_fBootstrapping, K_MIN, KERR_INVALID_PARAMETER, KLDRDYLD_LOAD_FLAGS_EXECUTABLE, KLDRDYLD_LOAD_FLAGS_RECURSIVE_INIT, KLDRDYLD_SEARCH_END, KLDRDYLD_SEARCH_INVALID, kLdrDyldDefPrefix, kLdrDyldDefSuffix, kldrDyldDoLoadExeStackSwitch(), kldrDyldFailure(), kldrDyldFindNewModule(), kLdrDyldFlags, kLdrDyldLibraryPath, kldrDyldModGetMainStack(), kldrDyldModMap(), kLdrDyldSearch, kLdrDyldSemRequest(), kldrInit(), KLDRYDLD_LOAD_FLAGS_DEEP_SYMBOLS, KLDRYDLD_LOAD_FLAGS_GLOBAL_SYMBOLS, KLDRYDLD_LOAD_FLAGS_SPECIFIC_MODULE, KSIZE, NULL, KLDRDYLDMOD::pMod, KLDRMOD::pszFilename, KLDREXEARGS::szDefPrefix, KLDREXEARGS::szDefSuffix, KLDREXEARGS::szExecutable, and KLDREXEARGS::szLibPath.

Referenced by OS2Main(), and WindowsMain().

    void *pvStack;
    KSIZE  cbStack;
    int rc;

     * Indicate that we're boostrapping and ensure that initialization was successful.
    g_fBootstrapping = 1;
    rc = kldrInit();
    if (rc)
        kldrDyldFailure(rc, "Init failure, rc=%d", rc);

     * Validate the argument package.
                          | KLDRYDLD_LOAD_FLAGS_DEEP_SYMBOLS
                          | KLDRDYLD_LOAD_FLAGS_RECURSIVE_INIT
                          | KLDRYDLD_LOAD_FLAGS_SPECIFIC_MODULE))
        kldrDyldFailure(KERR_INVALID_PARAMETER, "Bad fFlags=%#x", pArgs->fFlags);
    if (    pArgs->enmSearch <= KLDRDYLD_SEARCH_INVALID
        ||  pArgs->enmSearch >= KLDRDYLD_SEARCH_END)
        kldrDyldFailure(KERR_INVALID_PARAMETER, "Bad enmSearch=%d", pArgs->enmSearch);

     * Set defaults.
    kLdrDyldFlags |= (pArgs->fFlags & KLDRDYLD_LOAD_FLAGS_RECURSIVE_INIT);
    kLdrDyldSearch = pArgs->enmSearch;

    /** @todo make sense of this default prefix/suffix stuff. */
    if (pArgs->szDefPrefix[0] != '\0')
        kHlpMemCopy(kLdrDyldDefPrefix, pArgs->szDefPrefix, K_MIN(sizeof(pArgs->szDefPrefix), sizeof(kLdrDyldDefPrefix)));
    if (pArgs->szDefSuffix[0] != '\0')
        kHlpMemCopy(kLdrDyldDefSuffix, pArgs->szDefSuffix, K_MIN(sizeof(pArgs->szDefSuffix), sizeof(kLdrDyldDefSuffix)));

    /** @todo append that path to the one for the specified search method. */
    /** @todo create a function for doing this, an exposed api preferably. */
    /* append path */
    cbStack = sizeof(kLdrDyldLibraryPath) - kHlpStrLen(kLdrDyldLibraryPath); /* borrow cbStack for a itty bit. */
    kHlpMemCopy(kLdrDyldLibraryPath, pArgs->szLibPath, K_MIN(sizeof(pArgs->szLibPath), cbStack));
    kLdrDyldLibraryPath[sizeof(kLdrDyldLibraryPath) - 1] = '\0';

     * Make sure we own the loader semaphore (necessary for init).
    rc = kLdrDyldSemRequest();
    if (rc)
        kldrDyldFailure(rc, "Sem req. failure, rc=%d", rc);

     * Open and map the executable module before we join paths with kLdrDyldLoad().
    rc = kldrDyldFindNewModule(pArgs->szExecutable, NULL, NULL, pArgs->enmSearch,
                               pArgs->fFlags | KLDRDYLD_LOAD_FLAGS_EXECUTABLE, &pExe);
    if (rc)
        kldrDyldFailure(rc, "Can't find/open the executable '%s', rc=%d", pArgs->szExecutable, rc);
    rc = kldrDyldModMap(pExe);
    if (rc)
        kldrDyldFailure(rc, "Failed to map the executable '%s', rc=%d", pExe->pMod->pszFilename, rc);

    kLdrDyldExe = pExe;

     * Query the stack and go to OS specific code to
     * setup and switch stack. The OS specific code will call us
     * back at kldrDyldDoLoadExe.
    rc = kldrDyldModGetMainStack(pExe, &pvStack, &cbStack);
    if (rc)
        kldrDyldFailure(rc, "Failed to map the executable '%s', rc=%d", pExe->pMod->pszFilename, rc);
    kldrDyldDoLoadExeStackSwitch(pExe, pvStack, cbStack);
    kldrDyldFailure(-1, "Failed to setup the stack for '%s'.", pExe->pMod->pszFilename);

Generated by  Doxygen 1.6.0   Back to index