Changeset 2843 for trunk/kLdr/kLdrDyld.c


Ignore:
Timestamp:
Oct 30, 2006, 5:16:08 AM (19 years ago)
Author:
bird
Message:

executable bootstrapping.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kLdr/kLdrDyld.c

    r2842 r2843  
    5959*   Global Variables                                                           *
    6060*******************************************************************************/
     61/** Pointer to the executable module.
     62 * (This is exported, so no prefix.) */
     63PKLDRDYLDMOD    kLdrDyldExe = NULL;
    6164/** Pointer to the head module (the executable).
    6265 * (This is exported, so no prefix.) */
     
    8487PKLDRDYLDMOD    g_pkLdrDyldBindTail;
    8588
    86 /** Stack of modules involved in the active loads.
    87  *
    88  * The main purpose is to allow module init routines to loading and unloading
    89  * modules without upsetting the init order and to assist in dereferencing
    90  * modules on load failure.
    91  *
    92  * Each call to kLdrDyldLoad and kLdrDyldLoadExe will start a load frame
    93  * when doing a fresh load. All dependant modules will be pushed on each
    94  * reference. The frame is completed when all the dependant modules has
    95  * been resolved (or a failure occurs). After doing fixups, the frame is
    96  * used to do module initialization. Should an error occur during the load
    97  * the frame will be used to dereference all the modules involved in the
    98  * load operation (it will not however, be used for termination calls as
    99  * they are postponed till the last load operation completes).
    100  *
    101  * Should any of the init calls load a module, a new frame will be created
    102  * for that operation and processed before the init call returns to the
    103  * previous frame.
     89/** Flag indicating bootstrap time.
     90 * When set the error behaviour changes. Any kind of serious failure
     91 * is fatal and will terminate the process. */
     92int             g_fBootstrapping;
     93/** The global error buffer. */
     94char            g_szkLdrDyldError[1024];
     95
     96/** The Library search path. */
     97char            kLdrDyldLibraryPath[4096];
     98
     99/** The default flags. */
     100uint32_t        kLdrDyldFlags = 0;
     101/** The default search method. */
     102KLDRDYLDSEARCH  kLdrDyldSearch = KLDRDYLD_SEARCH_INVALID;
     103/** The default DLL prefix. */
     104char            kLdrDyldDefPrefix[16];
     105/** The default DLL suffix. */
     106char            kLdrDyldDefSuffix[16];
     107
     108
     109/** The load stack.
     110 * This contains frames with modules affected by active loads.
     111 *
     112 * Each kLdrDyldLoad and kLdrDyldLoadExe call will create a new stack frame containing
     113 * all the modules involved in the operation. The modules will be ordered in recursive
     114 * init order within the frame.
    104115 */
    105116static PPKLDRDYLDMOD    g_papStackMods;
     
    119130static uint32_t         g_fActiveGC;
    120131
    121 /** The global error buffer. */
    122 char            g_szkLdrDyldError[1024];
    123 
    124 /** The Library search path. */
    125 char            kLdrDyldLibraryPath[4096];
    126 /** The executable flags. */
    127 uint32_t        kLdrDyldFlags;
    128 
    129132
    130133
     
    135138 * @internal
    136139 * @{ */
    137 static int kldrDyldDoLoad(const char *pszDll, const char *pszDefPrefix, const char *pszDefSuffix, KLDRDYLDSEARCH enmSearch,
     140void       kldrDyldDoLoadExeStackSwitch(PKLDRDYLDMOD pExe, void *pvStack, size_t cbStack);
     141void       kldrDyldDoLoadExe(PKLDRDYLDMOD pExe);
     142static int kldrDyldDoLoad(const char *pszDll, const char *pszPrefix, const char *pszSuffix, KLDRDYLDSEARCH enmSearch,
    138143                          unsigned fFlags, PPKLDRDYLDMOD ppMod, char *pszErr, size_t cchErr);
    139 static int kldrDyldDoLoadPrerequisites(PKLDRDYLDMOD pMod, const char *pszDefPrefix, const char *pszDefSuffix,
     144static int kldrDyldDoLoad2(PKLDRDYLDMOD pLoadedMod, const char *pszPrefix, const char *pszSuffix,
     145                           KLDRDYLDSEARCH enmSearch, unsigned fFlags);
     146static int kldrDyldDoLoadPrerequisites(PKLDRDYLDMOD pMod, const char *pszPrefix, const char *pszSuffix,
    140147                                       KLDRDYLDSEARCH enmSearch, unsigned fFlags);
    141148static int kldrDyldDoUnload(PKLDRDYLDMOD pMod);
    142 static int kldrDyldDoFindByName(const char *pszDll, const char *pszDefPrefix, const char *pszDefSuffix, KLDRDYLDSEARCH enmSearch,
     149static int kldrDyldDoFindByName(const char *pszDll, const char *pszPrefix, const char *pszSuffix, KLDRDYLDSEARCH enmSearch,
    143150                              unsigned fFlags, PPKLDRDYLDMOD ppMod);
    144151static int kldrDyldDoFindByAddress(uintptr_t Address, PPKLDRDYLDMOD ppMod, uint32_t *piSegment, uintptr_t *poffSegment);
     
    192199
    193200/**
     201 * Bootstrap an executable.
     202 *
     203 * This is called from the executable stub to replace the stub and run the
     204 * executable specified in the argument package.
     205 *
     206 * Since this is boostrap time there isn't anything to return to. So, instead
     207 * the process will be terminated upon failure.
     208 *
     209 * We also have to keep in mind that this function is called on a small, small,
     210 * stack and therefore any kind of large stack objects or deep recursions must
     211 * be avoided. Since loading the executable will involve more or less all
     212 * operations in the loader, this restriction really applies everywhere.
     213 *
     214 * @param   pArgs       Pointer to the argument package residing in the executable stub.
     215 */
     216void kldrDoDyldLoadExe(PKLDREXEARGS pArgs)
     217{
     218    void *pvStack = NULL;
     219    size_t cbStack = 0;
     220    PKLDRDYLDMOD pExe = NULL;
     221    int rc;
     222
     223    /*
     224     * Copy the arguments into the globals and do loader init.
     225     */
     226    kLdrDyldFlags = pArgs->fFlags;
     227    kLdrDyldSearch = pArgs->enmSearch;
     228    kLdrHlpMemCopy(kLdrDyldDefPrefix, pArgs->szDefPrefix, KLDR_MIN(sizeof(pArgs->szDefPrefix), sizeof(kLdrDyldDefPrefix)));
     229    kLdrHlpMemCopy(kLdrDyldDefSuffix, pArgs->szDefSuffix, KLDR_MIN(sizeof(pArgs->szDefSuffix), sizeof(kLdrDyldDefSuffix)));
     230    kLdrHlpMemCopy(kLdrDyldLibraryPath, pArgs->szLibPath, KLDR_MIN(sizeof(pArgs->szLibPath), sizeof(kLdrDyldLibraryPath)));
     231
     232    g_fBootstrapping = 1;
     233    rc = kldrInit();
     234    if (rc)
     235        kldrDyldFailure(rc, "Init failure, rc=%d", rc);
     236
     237    /*
     238     * Make sure we own the loader semaphore (necessary for init).
     239     */
     240    rc = kldrHlpSemRequest();
     241    if (rc)
     242        kldrDyldFailure(rc, "Sem req. failure, rc=%d", rc);
     243
     244    /*
     245     * Open and map the executable module before we join paths with kLdrDyldLoad().
     246     */
     247    rc = kldrDyldFindNewModule(pArgs->szExecutable, NULL, NULL, kLdrDyldSearch,
     248                               kLdrDyldFlags | KLDRDYLD_LOAD_FLAGS_EXECUTABLE, &pExe);
     249    if (rc)
     250        kldrDyldFailure(rc, "Can't find/open the executable '%s', rc=%d", pArgs->szExecutable, rc);
     251    rc = kldrDyldModMap(pExe);
     252    if (rc)
     253        kldrDyldFailure(rc, "Failed to map the executable '%s', rc=%d", pExe->pMod->pszFilename, rc);
     254
     255    kLdrDyldExe = pExe;
     256
     257    /*
     258     * Query the stack information and go to OS specific code to
     259     * setup and switch stack. The OS specific code will call us
     260     * back at kldrDyldDoLoadExe.
     261     */
     262    rc = kldrDyldModGetStackInfo(pExe, &pvStack, &cbStack);
     263    if (rc)
     264        kldrDyldFailure(rc, "Failed to map the executable '%s', rc=%d", pExe->pMod->pszFilename, rc);
     265    kldrDyldDoLoadExeStackSwitch(pExe, pvStack, cbStack);
     266    kldrDyldFailure(-1, "Failed to setup the stack for '%s'.", pExe->pMod->pszFilename);
     267}
     268
     269
     270/**
    194271 * Loads a module into the current process.
    195272 *
    196273 * @returns 0 on success, non-zero native OS status code or kLdr status code on failure.
    197274 * @param   pszDll          The name of the dll to open.
    198  * @param   pszDefPrefix    Prefix to use when searching.
    199  * @param   pszDefSuffix    Suffix to use when searching.
     275 * @param   pszPrefix       Prefix to use when searching.
     276 * @param   pszSuffix       Suffix to use when searching.
    200277 * @param   enmSearch       Method to use when locating the module and any modules it may depend on.
    201278 * @param   fFlags          Flags, a combintation of the KLDRYDLD_LOAD_FLAGS_* \#defines.
     
    204281 * @param   cchErr          The size of the buffer pointed to by pszErr.
    205282 */
    206 int     kLdrDyldLoad(const char *pszDll, const char *pszDefPrefix, const char *pszDefSuffix, KLDRDYLDSEARCH enmSearch,
     283int     kLdrDyldLoad(const char *pszDll, const char *pszPrefix, const char *pszSuffix, KLDRDYLDSEARCH enmSearch,
    207284                     unsigned fFlags, PHKLDRMOD phMod, char *pszErr, size_t cchErr)
    208285{
     
    214291    *phMod = NIL_HKLDRMOD;
    215292    KLDRHLP_VALIDATE_STRING(pszDll);
    216     KLDRHLP_VALIDATE_OPTIONAL_STRING(pszDefPrefix);
    217     KLDRHLP_VALIDATE_OPTIONAL_STRING(pszDefSuffix);
     293    KLDRHLP_VALIDATE_OPTIONAL_STRING(pszPrefix);
     294    KLDRHLP_VALIDATE_OPTIONAL_STRING(pszSuffix);
    218295    KLDRHLP_VALIDATE_ENUM(enmSearch, KLDRDYLD_SEARCH);
    219296    KLDRHLP_VALIDATE_OPTIONAL_BUFFER(pszErr, cchErr);
     
    226303        g_cTotalLoadCalls++;
    227304        g_cActiveLoadCalls++;
    228         rc = kldrDyldDoLoad(pszDll, pszDefPrefix, pszDefSuffix, enmSearch, fFlags, phMod, pszErr, cchErr);
     305        rc = kldrDyldDoLoad(pszDll, pszPrefix, pszSuffix, enmSearch, fFlags, phMod, pszErr, cchErr);
    229306        g_cActiveLoadCalls--;
    230307        kldrDyldDoModuleTerminationAndGarabageCollection();
     
    273350 * @returns KLDR_ERR_MODULE_NOT_FOUND or some I/O error on failure.
    274351 * @param   pszDll          The name of the dll to look for.
    275  * @param   pszDefPrefix    Prefix than can be used when searching.
    276  * @param   pszDefSuffix    Suffix than can be used when searching.
     352 * @param   pszPrefix       Prefix than can be used when searching.
     353 * @param   pszSuffix       Suffix than can be used when searching.
    277354 * @param   enmSearch       Method to use when locating the module.
    278355 * @param   fFlags          Flags, a combintation of the KLDRYDLD_LOAD_FLAGS_* \#defines.
    279356 * @param   phMod           Where to store the handle of the module on success.
    280357 */
    281 int     kLdrDyldFindByName(const char *pszDll, const char *pszDefPrefix, const char *pszDefSuffix, KLDRDYLDSEARCH enmSearch,
     358int     kLdrDyldFindByName(const char *pszDll, const char *pszPrefix, const char *pszSuffix, KLDRDYLDSEARCH enmSearch,
    282359                           unsigned fFlags, PHKLDRMOD phMod)
    283360{
     
    293370    {
    294371        PKLDRDYLDMOD pMod = NULL;
    295         rc = kldrDyldDoFindByName(pszDll, pszDefPrefix, pszDefSuffix, enmSearch, fFlags, phMod);
     372        rc = kldrDyldDoFindByName(pszDll, pszPrefix, pszSuffix, enmSearch, fFlags, phMod);
    296373        kldrHlpSemRelease();
    297374        *phMod = pMod;
     
    436513
    437514
     515/**
     516 * Worker kLdrDoLoadExe().
     517 * Used after we've switch to the final process stack.
     518 *
     519 * @param   pExe    The executable module.
     520 * @internal
     521 */
     522void kldrDyldDoLoadExe(PKLDRDYLDMOD pExe)
     523{
     524    int rc;
     525
     526    /*
     527     * Load the executable module with its prerequisites and initialize them.
     528     */
     529    g_cActiveLoadCalls++;
     530    rc = kldrDyldDoLoad2(pExe, NULL, NULL, kLdrDyldSearch, kLdrDyldFlags | KLDRDYLD_LOAD_FLAGS_EXECUTABLE);
     531    if (rc)
     532        kldrDyldFailure(rc, "load 2 failed for '%s', rc=%d", pExe->pMod->pszFilename);
     533    g_cActiveLoadCalls--;
     534    kldrDyldDoModuleTerminationAndGarabageCollection();
     535
     536    /*
     537     * Invoke the executable entry point.
     538     */
     539    kldrDyldModStartExe(pExe);
     540    kldrDyldFailure(-1, "failed to invoke main!");
     541}
     542
    438543
    439544/**
     
    441546 * @internal
    442547 */
    443 static int kldrDyldDoLoad(const char *pszDll, const char *pszDefPrefix, const char *pszDefSuffix, KLDRDYLDSEARCH enmSearch,
     548static int kldrDyldDoLoad(const char *pszDll, const char *pszPrefix, const char *pszSuffix, KLDRDYLDSEARCH enmSearch,
    444549                          unsigned fFlags, PPKLDRDYLDMOD ppMod, char *pszErr, size_t cchErr)
    445550{
     
    449554     * Try find the module among the ones that's already loaded.
    450555     */
    451     rc = kldrDyldFindExistingModule(pszDll, pszDefPrefix, pszDefSuffix, enmSearch, fFlags, ppMod);
     556    rc = kldrDyldFindExistingModule(pszDll, pszPrefix, pszSuffix, enmSearch, fFlags, ppMod);
    452557    if (!rc)
    453558    {
     
    510615         * We'll have to load it from file.
    511616         */
    512         rc = kldrDyldFindNewModule(pszDll, pszDefPrefix, pszDefSuffix, enmSearch, fFlags, ppMod);
     617        rc = kldrDyldFindNewModule(pszDll, pszPrefix, pszSuffix, enmSearch, fFlags, ppMod);
    513618        if (rc)
    514619            return kldrDyldCopyError(rc, pszErr, cchErr);
     
    516621    }
    517622
     623    /*
     624     * Join cause with kLdrDyldLoadExe.
     625     */
    518626    if (!rc)
    519     {
    520         /*
    521          * Load prerequisites.
    522          */
    523         uint32_t i;
    524         uint32_t iLoadEnd;
    525         uint32_t iLoad1st = kldrDyldStackNewFrame(*ppMod);
    526         rc = kldrDyldDoLoadPrerequisites(*ppMod, pszDefPrefix, pszDefSuffix, enmSearch, fFlags);
    527         iLoadEnd = kldrDyldStackFrameCompleted();
    528 
    529         /*
    530          * Apply fixups.
    531          */
     627        rc = kldrDyldDoLoad2(*ppMod, pszPrefix, pszSuffix, enmSearch, fFlags);
     628    else
     629    {
     630        /** @todo this is probably not quite right. */
     631        /* If the reference count is 0 do a quick ref/deref to trigger destruction. */
     632        kldrDyldModAddRef(*ppMod);
     633        kldrDyldModDeref(*ppMod);
     634    }
     635
     636    /*
     637     * Copy any error or warning to the error buffer.
     638     */
     639    return kldrDyldCopyError(rc, pszErr, cchErr);
     640}
     641
     642
     643/**
     644 * 2nd half of kLdrDyldLoad() and kLdrDyldLoadExe().
     645 *
     646 * @internal
     647 */
     648static int kldrDyldDoLoad2(PKLDRDYLDMOD pLoadedMod, const char *pszPrefix, const char *pszSuffix,
     649                           KLDRDYLDSEARCH enmSearch, unsigned fFlags)
     650{
     651    /*
     652     * Load prerequisites.
     653     */
     654    uint32_t i;
     655    uint32_t iLoad1st = kldrDyldStackNewFrame(pLoadedMod);
     656    int rc = kldrDyldDoLoadPrerequisites(pLoadedMod, pszPrefix, pszSuffix, enmSearch, fFlags);
     657    uint32_t iLoadEnd = kldrDyldStackFrameCompleted();
     658
     659    /*
     660     * Apply fixups.
     661     */
     662    for (i = iLoad1st; !rc && i < iLoadEnd; i++)
     663    {
     664        PKLDRDYLDMOD pMod = g_papStackMods[i];
     665        if (    pMod->enmState == KLDRSTATE_LOADED_PREREQUISITES
     666            ||  pMod->enmState == KLDRSTATE_RELOADED_LOADED_PREREQUISITES)
     667            rc = kldrDyldModFixup(pMod);
     668    }
     669
     670    /*
     671     * Advance fixed up module onto initialization.
     672     */
     673    for (i = iLoad1st; !rc && i < iLoadEnd; i++)
     674    {
     675        PKLDRDYLDMOD pMod = g_papStackMods[i];
     676        if (    pMod->enmState == KLDRSTATE_FIXED_UP
     677            ||  pMod->enmState == KLDRSTATE_RELOADED_FIXED_UP)
     678            pMod->enmState = KLDRSTATE_PENDING_INITIALIZATION;
     679        KLDRDYLD_ASSERT(    pMod->enmState == KLDRSTATE_PENDING_INITIALIZATION
     680                        ||  pMod->enmState == KLDRSTATE_GOOD);
     681    }
     682
     683    /*
     684     * Call the initializers if we're loading in recursive mode or
     685     * if we're the outermost load call.
     686     */
     687    if (fFlags & KLDRDYLD_LOAD_FLAGS_RECURSIVE_INIT)
     688    {
    532689        for (i = iLoad1st; !rc && i < iLoadEnd; i++)
    533690        {
    534691            PKLDRDYLDMOD pMod = g_papStackMods[i];
    535             if (    pMod->enmState == KLDRSTATE_LOADED_PREREQUISITES
    536                 ||  pMod->enmState == KLDRSTATE_RELOADED_LOADED_PREREQUISITES)
    537                 rc = kldrDyldModFixup(pMod);
     692            if (pMod->enmState == KLDRSTATE_PENDING_INITIALIZATION)
     693                rc = kldrDyldModCallInit(pMod);
     694            else if (pMod->enmState == KLDRSTATE_INITIALIZATION_FAILED)
     695                rc = KLDR_ERR_PREREQUISITE_MODULE_INIT_FAILED_ALREADY;
     696            else
     697                KLDRDYLD_ASSERT(g_papStackMods[i]->enmState == KLDRSTATE_GOOD);
    538698        }
    539 
    540         /*
    541          * Advance fixed up module onto initialization.
    542          */
     699#ifdef KLDRDYLD_STRICT
    543700        for (i = iLoad1st; !rc && i < iLoadEnd; i++)
     701            KLDRDYLD_ASSERT(g_papStackMods[i]->enmState == KLDRSTATE_GOOD);
     702#endif
     703    }
     704    else if (g_cActiveLoadCalls <= 1)
     705    {
     706        while (!rc && g_pkLdrDyldInitHead)
    544707        {
    545             PKLDRDYLDMOD pMod = g_papStackMods[i];
    546             if (    pMod->enmState == KLDRSTATE_FIXED_UP
    547                 ||  pMod->enmState == KLDRSTATE_RELOADED_FIXED_UP)
    548                 pMod->enmState = KLDRSTATE_PENDING_INITIALIZATION;
    549             KLDRDYLD_ASSERT(    pMod->enmState == KLDRSTATE_PENDING_INITIALIZATION
    550                             ||  pMod->enmState == KLDRSTATE_GOOD);
     708            PKLDRDYLDMOD pMod = g_pkLdrDyldInitHead;
     709            g_pkLdrDyldInitHead = pMod->InitTerm.pNext;
     710            if (pMod->InitTerm.pNext)
     711                pMod->InitTerm.pNext->InitTerm.pPrev = NULL;
     712            rc = kldrDyldModCallInit(pMod);
    551713        }
    552 
    553         /*
    554          * Call the initializers if we're loading in recursive mode or
    555          * if we're the outermost load call.
    556          */
    557         if (fFlags & KLDRDYLD_LOAD_FLAGS_RECURSIVE_INIT)
    558         {
    559             for (i = iLoad1st; !rc && i < iLoadEnd; i++)
    560             {
    561                 PKLDRDYLDMOD pMod = g_papStackMods[i];
    562                 if (pMod->enmState == KLDRSTATE_PENDING_INITIALIZATION)
    563                     rc = kldrDyldModCallInit(pMod);
    564                 else if (pMod->enmState == KLDRSTATE_INITIALIZATION_FAILED)
    565                     rc = KLDR_ERR_PREREQUISITE_MODULE_INIT_FAILED_ALREADY;
    566                 else
    567                     KLDRDYLD_ASSERT(g_papStackMods[i]->enmState == KLDRSTATE_GOOD);
    568             }
    569 #ifdef KLDRDYLD_STRICT
    570             for (i = iLoad1st; !rc && i < iLoadEnd; i++)
    571                 KLDRDYLD_ASSERT(g_papStackMods[i]->enmState == KLDRSTATE_GOOD);
    572 #endif
    573         }
    574         else if (g_cActiveLoadCalls <= 1)
    575         {
    576             while (!rc && g_pkLdrDyldInitHead)
    577             {
    578                 PKLDRDYLDMOD pMod = g_pkLdrDyldInitHead;
    579                 g_pkLdrDyldInitHead = pMod->InitTerm.pNext;
    580                 if (pMod->InitTerm.pNext)
    581                     pMod->InitTerm.pNext->InitTerm.pPrev = NULL;
    582                 rc = kldrDyldModCallInit(pMod);
    583             }
    584         }
    585 
    586         /*
    587          * Complete the load by incrementing the dynamic load count of the
    588          * requested module (return handle is already set).
    589          */
    590         if (!rc)
    591         {
    592             rc = kldrDyldModDynamicLoad(*ppMod);
    593             if (!rc)
    594             {
    595                 kldrDyldStackDropFrame(iLoad1st, iLoadEnd, rc);
    596                 kldrDyldModDeref(*ppMod);
    597                 return rc;
    598             }
    599         }
    600         kldrDyldStackDropFrame(iLoad1st, iLoadEnd, rc);
    601     }
    602     else
    603     {
    604         /* If the reference count is 0 do a quick ref/deref to trigger destruction. */
    605         kldrDyldModAddRef(*ppMod);
    606         kldrDyldModDeref(*ppMod);
    607     }
    608 
    609     /*
    610      * We've failed, copy/create error string.
    611      */
    612     return kldrDyldCopyError(rc, pszErr, cchErr);
     714    }
     715
     716    /*
     717     * Complete the load by incrementing the dynamic load count of the
     718     * requested module (return handle is already set).
     719     */
     720    if (!rc)
     721    {
     722        if (fFlags & KLDRDYLD_LOAD_FLAGS_EXECUTABLE)
     723            pLoadedMod->cDepRefs = 0xffff;
     724        else
     725            rc = kldrDyldModDynamicLoad(pLoadedMod);
     726    }
     727
     728    kldrDyldStackDropFrame(iLoad1st, iLoadEnd, rc);
     729    return rc;
    613730}
    614731
     
    620737 * @returns 0 on success, non-zero error code on failure.
    621738 * @param   pMod            The module to start at.
    622  * @param   pszDefPrefix    Prefix to use when searching.
    623  * @param   pszDefSuffix    Suffix to use when searching.
     739 * @param   pszPrefix    Prefix to use when searching.
     740 * @param   pszSuffix    Suffix to use when searching.
    624741 * @param   enmSearch       Method to use when locating the module and any modules it may depend on.
    625742 * @param   fFlags          Flags, a combintation of the KLDRYDLD_LOAD_FLAGS_* \#defines.
    626743 */
    627 static int kldrDyldDoLoadPrerequisites(PKLDRDYLDMOD pMod, const char *pszDefPrefix, const char *pszDefSuffix,
     744static int kldrDyldDoLoadPrerequisites(PKLDRDYLDMOD pMod, const char *pszPrefix, const char *pszSuffix,
    628745                                       KLDRDYLDSEARCH enmSearch, unsigned fFlags)
    629746{
     
    665782                case KLDRSTATE_RELOADED:
    666783                case KLDRSTATE_PENDING_TERMINATION:
    667                     rc = kldrDyldModLoadPrerequisites(pMod, pszDefPrefix, pszDefSuffix, enmSearch, fFlags);
     784                    rc = kldrDyldModLoadPrerequisites(pMod, pszPrefix, pszSuffix, enmSearch, fFlags);
    668785                    KLDRDYLD_ASSERT(    pMod->enmState == KLDRSTATE_GOOD
    669786                                    ||  pMod->enmState == KLDRSTATE_RELOADED_LOADED_PREREQUISITES
     
    753870 * @returns KLDR_ERR_MODULE_NOT_FOUND or I/O error on failure.
    754871 * @param   pszDll          The name of the dll to look for.
    755  * @param   pszDefPrefix    Prefix than can be used when searching.
    756  * @param   pszDefSuffix    Suffix than can be used when searching.
     872 * @param   pszPrefix    Prefix than can be used when searching.
     873 * @param   pszSuffix    Suffix than can be used when searching.
    757874 * @param   enmSearch       Method to use when locating the module.
    758875 * @param   fFlags          Flags, a combintation of the KLDRYDLD_LOAD_FLAGS_* \#defines.
     
    760877 * @param   ppMod           Where to put the module we get.
    761878 */
    762 int kldrDyldGetPrerequisite(const char *pszDll, const char *pszDefPrefix, const char *pszDefSuffix, KLDRDYLDSEARCH enmSearch,
     879int kldrDyldGetPrerequisite(const char *pszDll, const char *pszPrefix, const char *pszSuffix, KLDRDYLDSEARCH enmSearch,
    763880                            unsigned fFlags, PKLDRDYLDMOD pDep, PPKLDRDYLDMOD ppMod)
    764881{
     
    775892     * and the action taken is a little bit different.
    776893     */
    777     rc = kldrDyldFindExistingModule(pszDll, pszDefPrefix, pszDefSuffix, enmSearch, fFlags, &pMod);
     894    rc = kldrDyldFindExistingModule(pszDll, pszPrefix, pszSuffix, enmSearch, fFlags, &pMod);
    778895    if (!rc)
    779896    {
     
    827944         * We'll have to load it from file.
    828945         */
    829         rc = kldrDyldFindNewModule(pszDll, pszDefPrefix, pszDefSuffix, enmSearch, fFlags, ppMod);
     946        rc = kldrDyldFindNewModule(pszDll, pszPrefix, pszSuffix, enmSearch, fFlags, ppMod);
    830947        if (!rc)
    831948            rc = kldrDyldModMap(pMod);
     
    11991316 * @internal
    12001317 */
    1201 static int kldrDyldDoFindByName(const char *pszDll, const char *pszDefPrefix, const char *pszDefSuffix, KLDRDYLDSEARCH enmSearch,
     1318static int kldrDyldDoFindByName(const char *pszDll, const char *pszPrefix, const char *pszSuffix, KLDRDYLDSEARCH enmSearch,
    12021319                                unsigned fFlags, PPKLDRDYLDMOD ppMod)
    12031320{
    1204     return kldrDyldFindExistingModule(pszDll, pszDefPrefix, pszDefSuffix, enmSearch, fFlags, ppMod);
     1321    return kldrDyldFindExistingModule(pszDll, pszPrefix, pszSuffix, enmSearch, fFlags, ppMod);
    12051322}
    12061323
     
    12691386
    12701387
    1271 #if 0
    1272 void kldrLoadExe(PKLDREXEARGS pArgs)
    1273 {
    1274     /*
    1275      * Copy the arguments into the globals and do load init.
    1276      */
    1277     kLdrFlags = pArgs->fFlags;
    1278     kLdrHlpMemCopy(kLdrLibraryPath, pArgs->szLibPath, KLDR_MIN(sizeof(pArgs->szLibPath), sizeof(kLdrLibraryPath)));
    1279     int rc = kldrInit();
    1280     if (rc)
    1281         kldrFailure(rc, "kLdr: Init failure, rc=%d\n", rc);
    1282 
    1283     /*
    1284      * Open the executable module.
    1285      */
    1286     PKLDRMOD pExe;
    1287     kldrOpenExe(pArgs->szExecutable, &pExe);
    1288 
    1289     /* Map the segments. */
    1290     kldrModMapSegments(pExe);
    1291 
    1292     /*
    1293      * This is the point where we switch to the executable
    1294      * stack, allocating it if necessary.
    1295      */
    1296     void *pvBottom;
    1297     kldrModSetupStack(pExe, &pvBottom);
    1298     kldrLoadExecSwitchStack(pvBottom);
    1299 }
    1300 
    1301 
    1302 void kldrLoadExeOnNewStack(void)
    1303 {
    1304     /*
    1305      * Load all prerequisite modules.
    1306      */
    1307     PKLDRMOD pCur;
    1308     do  for (pCur = kLdrModuleHead; pCur; pCur = pCur->pNext)
    1309         {
    1310             if (pCur->enmState >= KLDRSTATE_DEPS)
    1311                 continue;
    1312             kldrModLoadDeps(pCur);
    1313         }
    1314     while (pCur);
    1315 
    1316     /*
    1317      * Do fixups (FIFO).
    1318      */
    1319     for (pCur = kLdrModuleHead; pCur; pCur = pCur->pNext)
    1320     {
    1321         if (pCur->enmState >= KLDRSTATE_FIXED)
    1322             continue;
    1323         kldrModFixup(pCur, 0);
    1324     }
    1325 
    1326     /*
    1327      * Do module initialization.
    1328      */
    1329     for (pCur = kLdrModuleTail; pCur != kLdrModuleTail; pCur = pCur->pPrev)
    1330     {
    1331         if (pCur->enmState >= KLDRSTATE_INITED)
    1332             continue;
    1333         kldrModCallInit(pCur);
    1334     }
    1335 
    1336     /*
    1337      * Get the executable start address and commit the work that's been done.
    1338      */
    1339     void *pvEntry;
    1340     kldrModGetExeEntry(&pvEntry);
    1341 
    1342     for (pCur = kLdrModuleHead; pCur; pCur = pCur->pNext)
    1343         if (pCur->enmState == KLDRSTATE_INITED)
    1344             pCur->enmState = KLDRSTATE_LOADED;
    1345 
    1346     kldrHlpSemRelease();
    1347 
    1348     /*
    1349      * We're now ready for starting the executable code.
    1350      */
    1351     kldrOSStartExe(pLdrModuleHead, pvEntry);
    1352 }
    1353 
    1354 #endif
    1355 
    1356 
    13571388/**
    13581389 * Panic / failure
     
    13631394 * @param   ...             Message string arguments.
    13641395 */
    1365 int kldrFailure(int rc, const char *pszFormat, ...)
     1396int kldrDyldFailure(int rc, const char *pszFilename, ...)
    13661397{
    13671398    kldrHlpExit(1);
Note: See TracChangeset for help on using the changeset viewer.