Ignore:
Timestamp:
Nov 12, 2006, 9:59:45 AM (19 years ago)
Author:
bird
Message:

Got the stub loader working (but without stack allocation/switching).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kLdr/kLdrDyldFind.c

    r2870 r2875  
    105105/** @name The kLdr search method parameters.
    106106 * @{ */
     107/** The kLdr EXE search path.
     108 * During EXE searching the it's initialized with the values of the KLDR_PATH and
     109 * the PATH env.vars. Both ';' and ':' can be used as separators.
     110 */
     111char            kLdrDyldExePath[8192];
    107112/** The kLdr DLL search path.
    108113 * During initialization the KLDR_LIBRARY_PATH env.var. and the path in the
    109114 * executable stub is appended. Both ';' and ':' can be used as separators.
    110115 */
    111 char            kLdrDyldPath[8192];
     116char            kLdrDyldLibraryPath[8192];
    112117/** The kLdr application directory.
    113118 * This is initialized when the executable is 'loaded' or by a kLdr user.
     
    195200*   Internal Functions                                                         *
    196201*******************************************************************************/
    197 static int kldrDyldFindDoSearch(const char *pszName, const char *pszPrefix, const char *pszSuffix,
     202static int kldrDyldFindDoDllSearch(const char *pszName, const char *pszPrefix, const char *pszSuffix,
    198203                                KLDRDYLDSEARCH enmSearch, unsigned fFlags, PPKLDRRDR ppRdr);
     204static int kldrDyldFindDoExeSearch(const char *pszName, const char *pszPrefix, const char *pszSuffix,
     205                                   KLDRDYLDSEARCH enmSearch, unsigned fFlags, PPKLDRRDR ppRdr);
    199206static int kldrDyldFindTryOpen(const char *pszFilename, PPKLDRRDR ppRdr);
    200207static int kldrDyldFindTryOpenPath(const char *pchPath, size_t cchPath, PCKLDRDYLDFINDARGS pArgs);
    201208static int kldrDyldFindEnumeratePath(const char *pszSearchPath, PCKLDRDYLDFINDARGS pArgs);
    202 static int kldrDyldFindGetDefaults(KLDRDYLDSEARCH *penmSearch, const char **pszPrefix, const char **pszSuffix, const char *pszName);
     209static int kldrDyldFindGetDefaults(KLDRDYLDSEARCH *penmSearch, const char **pszPrefix,
     210                                   const char **pszSuffix, const char *pszName, uint32_t fFlags);
    203211
    204212
     
    217225     * The kLdr search parameters.
    218226     */
    219     rc = kldrHlpGetEnv("KLDR_LIBRARY_PATH", kLdrDyldPath, sizeof(kLdrDyldPath));
     227    rc = kldrHlpGetEnv("KLDR_LIBRARY_PATH", kLdrDyldLibraryPath, sizeof(kLdrDyldLibraryPath));
    220228    rc = kldrHlpGetEnv("KLDR_DEF_PREFIX", szTmp, sizeof(szTmp));
    221229    if (!rc)
     
    358366    if (!kldrHlpIsFilenameOnly(pszName))
    359367        rc = kldrDyldFindTryOpen(pszName, &pRdr);
     368    else if (!(fFlags & KLDRDYLD_LOAD_FLAGS_EXECUTABLE))
     369        rc = kldrDyldFindDoDllSearch(pszName, pszPrefix, pszSuffix, enmSearch, fFlags, &pRdr);
    360370    else
    361         rc = kldrDyldFindDoSearch(pszName, pszPrefix, pszSuffix, enmSearch, fFlags, &pRdr);
     371        rc = kldrDyldFindDoExeSearch(pszName, pszPrefix, pszSuffix, enmSearch, fFlags, &pRdr);
    362372    if (!rc)
    363373    {
     
    411421
    412422/**
    413  * Searches for a file using the specified method.
     423 * Searches for a DLL file using the specified method.
    414424 *
    415425 * @returns 0 on success and *ppMod pointing to the new module.
     
    423433 * @param   ppRdr       Where to store the pointer to the file provider instance on success.
    424434 */
    425 static int kldrDyldFindDoSearch(const char *pszName, const char *pszPrefix, const char *pszSuffix,
    426                                 KLDRDYLDSEARCH enmSearch, unsigned fFlags, PPKLDRRDR ppRdr)
     435static int kldrDyldFindDoDllSearch(const char *pszName, const char *pszPrefix, const char *pszSuffix,
     436                                   KLDRDYLDSEARCH enmSearch, unsigned fFlags, PPKLDRRDR ppRdr)
    427437{
    428438    int rc;
     
    435445    Args.pszPrefix = pszPrefix;
    436446    Args.pszSuffix = pszSuffix;
    437     rc = kldrDyldFindGetDefaults(&Args.enmSearch, &Args.pszPrefix, &Args.pszSuffix, pszName);
     447    rc = kldrDyldFindGetDefaults(&Args.enmSearch, &Args.pszPrefix, &Args.pszSuffix, pszName, fFlags);
    438448    if (rc)
    439449        return rc;
     
    464474            if (rc != KLDR_ERR_MODULE_NOT_FOUND)
    465475                break;
    466             rc = kldrDyldFindEnumeratePath(kLdrDyldPath, &Args);
     476            rc = kldrDyldFindEnumeratePath(kLdrDyldLibraryPath, &Args);
    467477            break;
    468478        }
     
    525535
    526536/**
     537 * Searches for an EXE file using the specified method.
     538 *
     539 * @returns 0 on success and *ppMod pointing to the new module.
     540 * @returns KLDR_ERR_MODULE_NOT_FOUND if the specified file couldn't be opened.
     541 * @returns non-zero kLdr or OS specific status code on other failures.
     542 * @param   pszName     The name.
     543 * @param   pszPrefix   The prefix, optional.
     544 * @param   pszSuffix   The suffix, optional.
     545 * @param   enmSearch   The search method.
     546 * @param   fFlags      The load/search flags.
     547 * @param   ppRdr       Where to store the pointer to the file provider instance on success.
     548 */
     549static int kldrDyldFindDoExeSearch(const char *pszName, const char *pszPrefix, const char *pszSuffix,
     550                                   KLDRDYLDSEARCH enmSearch, unsigned fFlags, PPKLDRRDR ppRdr)
     551{
     552    int rc;
     553    KLDRDYLDFINDARGS Args;
     554
     555    /*
     556     * Initialize the argument structure and resolve defaults.
     557     */
     558    Args.enmSearch = enmSearch;
     559    Args.pszPrefix = pszPrefix;
     560    Args.pszSuffix = pszSuffix;
     561    rc = kldrDyldFindGetDefaults(&Args.enmSearch, &Args.pszPrefix, &Args.pszSuffix, pszName, fFlags);
     562    if (rc)
     563        return rc;
     564    Args.pszName = pszName;
     565    Args.cchName = kLdrHlpStrLen(pszName);
     566    Args.cchPrefix = Args.pszPrefix ? kLdrHlpStrLen(Args.pszPrefix) : 0;
     567    Args.cchSuffix = Args.pszSuffix ? kLdrHlpStrLen(Args.pszSuffix) : 0;
     568    Args.cchMaxLength = Args.cchName + Args.cchSuffix + Args.cchPrefix;
     569    Args.fFlags = fFlags;
     570    Args.ppRdr = ppRdr;
     571
     572    /*
     573     * If we're bootstrapping a process, we'll start by looking in the
     574     * application directory and the check out the path.
     575     */
     576    if (g_fBootstrapping)
     577    {
     578        kldrDyldFindLazyInitAppDir();
     579        if (kLdrDyldAppDir[0] != '\0')
     580        {
     581            rc = kldrDyldFindTryOpenPath(kLdrDyldAppDir, kLdrHlpStrLen(kLdrDyldAppDir), &Args);
     582            if (rc != KLDR_ERR_MODULE_NOT_FOUND)
     583                return rc;
     584        }
     585    }
     586
     587    /*
     588     * Search the EXE search path. Initialize it the first time around.
     589     */
     590    if (!kLdrDyldExePath[0])
     591    {
     592        size_t cch;
     593        kldrHlpGetEnv("KLDR_EXE_PATH", kLdrDyldExePath, sizeof(kLdrDyldExePath) - 10);
     594        cch = kLdrHlpStrLen(kLdrDyldExePath);
     595        kLdrDyldExePath[cch++] = ';';
     596        kldrHlpGetEnv("PATH", &kLdrDyldExePath[cch], sizeof(kLdrDyldExePath) - cch);
     597    }
     598    return kldrDyldFindEnumeratePath(kLdrDyldExePath, &Args);
     599}
     600
     601
     602/**
    527603 * Try open the specfied file.
    528604 *
     
    565641    static char s_szFilename[1024];
    566642    char *psz;
     643    int rc;
    567644
    568645    /*
     
    612689    *psz = '\0';
    613690
     691
    614692    /*
    615693     * Try open it.
    616694     */
    617     return kldrDyldFindTryOpen(s_szFilename, pArgs->ppRdr);
     695    rc = kldrDyldFindTryOpen(s_szFilename, pArgs->ppRdr);
     696    /* If we're opening an executable, try again without the suffix.*/
     697    if (    rc
     698        &&  pArgs->cchSuffix
     699        &&  (pArgs->fFlags & KLDRDYLD_LOAD_FLAGS_EXECUTABLE))
     700    {
     701        psz -= pArgs->cchSuffix;
     702        *psz = '\0';
     703        rc = kldrDyldFindTryOpen(s_szFilename, pArgs->ppRdr);
     704    }
     705    return rc;
    618706}
    619707
     
    689777 * @param   ppszSuffix  The suffix. In/Out.
    690778 * @param   pszName     The name. In.
     779 * @param   fFlags      The load/search flags.
    691780 */
    692781static int kldrDyldFindGetDefaults(KLDRDYLDSEARCH *penmSearch, const char **ppszPrefix, const char **ppszSuffix,
    693                                    const char *pszName)
     782                                   const char *pszName, uint32_t fFlags)
    694783{
    695784    unsigned fCaseSensitive;
     
    722811        case KLDRDYLD_SEARCH_OS2:
    723812            if (!*ppszSuffix)
    724                 *ppszSuffix = ".dll";
     813                *ppszSuffix = !(fFlags & KLDRDYLD_LOAD_FLAGS_EXECUTABLE) ? ".dll" : ".exe";
    725814            fCaseSensitive = 0;
    726815            break;
     
    729818        case KLDRDYLD_SEARCH_WINDOWS_ALTERED:
    730819            if (!*ppszSuffix)
    731                 *ppszSuffix = ".dll";
     820                *ppszSuffix = !(fFlags & KLDRDYLD_LOAD_FLAGS_EXECUTABLE) ? ".dll" : ".exe";
    732821            fCaseSensitive = 0;
    733822            break;
     
    790879     * Defaults.
    791880     */
    792     rc = kldrDyldFindGetDefaults(&enmSearch, &pszPrefix, &pszSuffix, pszName);
     881    rc = kldrDyldFindGetDefaults(&enmSearch, &pszPrefix, &pszSuffix, pszName, fFlags);
    793882    if (rc)
    794883        return rc;
     
    812901        PKLDRRDR pRdr;
    813902        if (fOS2LibpathStrict)
    814             rc = kldrDyldFindDoSearch(pszName, pszPrefix, pszSuffix, enmSearch, fFlags, &pRdr);
     903            rc = kldrDyldFindDoDllSearch(pszName, pszPrefix, pszSuffix, enmSearch, fFlags, &pRdr);
    815904        else
    816905            rc = kldrDyldFindTryOpen(pszName, &pRdr);
Note: See TracChangeset for help on using the changeset viewer.