Changeset 2843 for trunk/kLdr/kLdrDyld.c
- Timestamp:
- Oct 30, 2006, 5:16:08 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kLdr/kLdrDyld.c
r2842 r2843 59 59 * Global Variables * 60 60 *******************************************************************************/ 61 /** Pointer to the executable module. 62 * (This is exported, so no prefix.) */ 63 PKLDRDYLDMOD kLdrDyldExe = NULL; 61 64 /** Pointer to the head module (the executable). 62 65 * (This is exported, so no prefix.) */ … … 84 87 PKLDRDYLDMOD g_pkLdrDyldBindTail; 85 88 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. */ 92 int g_fBootstrapping; 93 /** The global error buffer. */ 94 char g_szkLdrDyldError[1024]; 95 96 /** The Library search path. */ 97 char kLdrDyldLibraryPath[4096]; 98 99 /** The default flags. */ 100 uint32_t kLdrDyldFlags = 0; 101 /** The default search method. */ 102 KLDRDYLDSEARCH kLdrDyldSearch = KLDRDYLD_SEARCH_INVALID; 103 /** The default DLL prefix. */ 104 char kLdrDyldDefPrefix[16]; 105 /** The default DLL suffix. */ 106 char 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. 104 115 */ 105 116 static PPKLDRDYLDMOD g_papStackMods; … … 119 130 static uint32_t g_fActiveGC; 120 131 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 129 132 130 133 … … 135 138 * @internal 136 139 * @{ */ 137 static int kldrDyldDoLoad(const char *pszDll, const char *pszDefPrefix, const char *pszDefSuffix, KLDRDYLDSEARCH enmSearch, 140 void kldrDyldDoLoadExeStackSwitch(PKLDRDYLDMOD pExe, void *pvStack, size_t cbStack); 141 void kldrDyldDoLoadExe(PKLDRDYLDMOD pExe); 142 static int kldrDyldDoLoad(const char *pszDll, const char *pszPrefix, const char *pszSuffix, KLDRDYLDSEARCH enmSearch, 138 143 unsigned fFlags, PPKLDRDYLDMOD ppMod, char *pszErr, size_t cchErr); 139 static int kldrDyldDoLoadPrerequisites(PKLDRDYLDMOD pMod, const char *pszDefPrefix, const char *pszDefSuffix, 144 static int kldrDyldDoLoad2(PKLDRDYLDMOD pLoadedMod, const char *pszPrefix, const char *pszSuffix, 145 KLDRDYLDSEARCH enmSearch, unsigned fFlags); 146 static int kldrDyldDoLoadPrerequisites(PKLDRDYLDMOD pMod, const char *pszPrefix, const char *pszSuffix, 140 147 KLDRDYLDSEARCH enmSearch, unsigned fFlags); 141 148 static int kldrDyldDoUnload(PKLDRDYLDMOD pMod); 142 static int kldrDyldDoFindByName(const char *pszDll, const char *psz DefPrefix, const char *pszDefSuffix, KLDRDYLDSEARCH enmSearch,149 static int kldrDyldDoFindByName(const char *pszDll, const char *pszPrefix, const char *pszSuffix, KLDRDYLDSEARCH enmSearch, 143 150 unsigned fFlags, PPKLDRDYLDMOD ppMod); 144 151 static int kldrDyldDoFindByAddress(uintptr_t Address, PPKLDRDYLDMOD ppMod, uint32_t *piSegment, uintptr_t *poffSegment); … … 192 199 193 200 /** 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 */ 216 void 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 /** 194 271 * Loads a module into the current process. 195 272 * 196 273 * @returns 0 on success, non-zero native OS status code or kLdr status code on failure. 197 274 * @param pszDll The name of the dll to open. 198 * @param psz DefPrefixPrefix to use when searching.199 * @param psz DefSuffixSuffix to use when searching.275 * @param pszPrefix Prefix to use when searching. 276 * @param pszSuffix Suffix to use when searching. 200 277 * @param enmSearch Method to use when locating the module and any modules it may depend on. 201 278 * @param fFlags Flags, a combintation of the KLDRYDLD_LOAD_FLAGS_* \#defines. … … 204 281 * @param cchErr The size of the buffer pointed to by pszErr. 205 282 */ 206 int kLdrDyldLoad(const char *pszDll, const char *psz DefPrefix, const char *pszDefSuffix, KLDRDYLDSEARCH enmSearch,283 int kLdrDyldLoad(const char *pszDll, const char *pszPrefix, const char *pszSuffix, KLDRDYLDSEARCH enmSearch, 207 284 unsigned fFlags, PHKLDRMOD phMod, char *pszErr, size_t cchErr) 208 285 { … … 214 291 *phMod = NIL_HKLDRMOD; 215 292 KLDRHLP_VALIDATE_STRING(pszDll); 216 KLDRHLP_VALIDATE_OPTIONAL_STRING(psz DefPrefix);217 KLDRHLP_VALIDATE_OPTIONAL_STRING(psz DefSuffix);293 KLDRHLP_VALIDATE_OPTIONAL_STRING(pszPrefix); 294 KLDRHLP_VALIDATE_OPTIONAL_STRING(pszSuffix); 218 295 KLDRHLP_VALIDATE_ENUM(enmSearch, KLDRDYLD_SEARCH); 219 296 KLDRHLP_VALIDATE_OPTIONAL_BUFFER(pszErr, cchErr); … … 226 303 g_cTotalLoadCalls++; 227 304 g_cActiveLoadCalls++; 228 rc = kldrDyldDoLoad(pszDll, psz DefPrefix, pszDefSuffix, enmSearch, fFlags, phMod, pszErr, cchErr);305 rc = kldrDyldDoLoad(pszDll, pszPrefix, pszSuffix, enmSearch, fFlags, phMod, pszErr, cchErr); 229 306 g_cActiveLoadCalls--; 230 307 kldrDyldDoModuleTerminationAndGarabageCollection(); … … 273 350 * @returns KLDR_ERR_MODULE_NOT_FOUND or some I/O error on failure. 274 351 * @param pszDll The name of the dll to look for. 275 * @param psz DefPrefixPrefix than can be used when searching.276 * @param psz DefSuffixSuffix 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. 277 354 * @param enmSearch Method to use when locating the module. 278 355 * @param fFlags Flags, a combintation of the KLDRYDLD_LOAD_FLAGS_* \#defines. 279 356 * @param phMod Where to store the handle of the module on success. 280 357 */ 281 int kLdrDyldFindByName(const char *pszDll, const char *psz DefPrefix, const char *pszDefSuffix, KLDRDYLDSEARCH enmSearch,358 int kLdrDyldFindByName(const char *pszDll, const char *pszPrefix, const char *pszSuffix, KLDRDYLDSEARCH enmSearch, 282 359 unsigned fFlags, PHKLDRMOD phMod) 283 360 { … … 293 370 { 294 371 PKLDRDYLDMOD pMod = NULL; 295 rc = kldrDyldDoFindByName(pszDll, psz DefPrefix, pszDefSuffix, enmSearch, fFlags, phMod);372 rc = kldrDyldDoFindByName(pszDll, pszPrefix, pszSuffix, enmSearch, fFlags, phMod); 296 373 kldrHlpSemRelease(); 297 374 *phMod = pMod; … … 436 513 437 514 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 */ 522 void 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 438 543 439 544 /** … … 441 546 * @internal 442 547 */ 443 static int kldrDyldDoLoad(const char *pszDll, const char *psz DefPrefix, const char *pszDefSuffix, KLDRDYLDSEARCH enmSearch,548 static int kldrDyldDoLoad(const char *pszDll, const char *pszPrefix, const char *pszSuffix, KLDRDYLDSEARCH enmSearch, 444 549 unsigned fFlags, PPKLDRDYLDMOD ppMod, char *pszErr, size_t cchErr) 445 550 { … … 449 554 * Try find the module among the ones that's already loaded. 450 555 */ 451 rc = kldrDyldFindExistingModule(pszDll, psz DefPrefix, pszDefSuffix, enmSearch, fFlags, ppMod);556 rc = kldrDyldFindExistingModule(pszDll, pszPrefix, pszSuffix, enmSearch, fFlags, ppMod); 452 557 if (!rc) 453 558 { … … 510 615 * We'll have to load it from file. 511 616 */ 512 rc = kldrDyldFindNewModule(pszDll, psz DefPrefix, pszDefSuffix, enmSearch, fFlags, ppMod);617 rc = kldrDyldFindNewModule(pszDll, pszPrefix, pszSuffix, enmSearch, fFlags, ppMod); 513 618 if (rc) 514 619 return kldrDyldCopyError(rc, pszErr, cchErr); … … 516 621 } 517 622 623 /* 624 * Join cause with kLdrDyldLoadExe. 625 */ 518 626 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 */ 648 static 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 { 532 689 for (i = iLoad1st; !rc && i < iLoadEnd; i++) 533 690 { 534 691 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); 538 698 } 539 540 /* 541 * Advance fixed up module onto initialization. 542 */ 699 #ifdef KLDRDYLD_STRICT 543 700 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) 544 707 { 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); 551 713 } 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; 613 730 } 614 731 … … 620 737 * @returns 0 on success, non-zero error code on failure. 621 738 * @param pMod The module to start at. 622 * @param psz DefPrefix Prefix to use when searching.623 * @param psz DefSuffix Suffix to use when searching.739 * @param pszPrefix Prefix to use when searching. 740 * @param pszSuffix Suffix to use when searching. 624 741 * @param enmSearch Method to use when locating the module and any modules it may depend on. 625 742 * @param fFlags Flags, a combintation of the KLDRYDLD_LOAD_FLAGS_* \#defines. 626 743 */ 627 static int kldrDyldDoLoadPrerequisites(PKLDRDYLDMOD pMod, const char *psz DefPrefix, const char *pszDefSuffix,744 static int kldrDyldDoLoadPrerequisites(PKLDRDYLDMOD pMod, const char *pszPrefix, const char *pszSuffix, 628 745 KLDRDYLDSEARCH enmSearch, unsigned fFlags) 629 746 { … … 665 782 case KLDRSTATE_RELOADED: 666 783 case KLDRSTATE_PENDING_TERMINATION: 667 rc = kldrDyldModLoadPrerequisites(pMod, psz DefPrefix, pszDefSuffix, enmSearch, fFlags);784 rc = kldrDyldModLoadPrerequisites(pMod, pszPrefix, pszSuffix, enmSearch, fFlags); 668 785 KLDRDYLD_ASSERT( pMod->enmState == KLDRSTATE_GOOD 669 786 || pMod->enmState == KLDRSTATE_RELOADED_LOADED_PREREQUISITES … … 753 870 * @returns KLDR_ERR_MODULE_NOT_FOUND or I/O error on failure. 754 871 * @param pszDll The name of the dll to look for. 755 * @param psz DefPrefix Prefix than can be used when searching.756 * @param psz DefSuffix 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. 757 874 * @param enmSearch Method to use when locating the module. 758 875 * @param fFlags Flags, a combintation of the KLDRYDLD_LOAD_FLAGS_* \#defines. … … 760 877 * @param ppMod Where to put the module we get. 761 878 */ 762 int kldrDyldGetPrerequisite(const char *pszDll, const char *psz DefPrefix, const char *pszDefSuffix, KLDRDYLDSEARCH enmSearch,879 int kldrDyldGetPrerequisite(const char *pszDll, const char *pszPrefix, const char *pszSuffix, KLDRDYLDSEARCH enmSearch, 763 880 unsigned fFlags, PKLDRDYLDMOD pDep, PPKLDRDYLDMOD ppMod) 764 881 { … … 775 892 * and the action taken is a little bit different. 776 893 */ 777 rc = kldrDyldFindExistingModule(pszDll, psz DefPrefix, pszDefSuffix, enmSearch, fFlags, &pMod);894 rc = kldrDyldFindExistingModule(pszDll, pszPrefix, pszSuffix, enmSearch, fFlags, &pMod); 778 895 if (!rc) 779 896 { … … 827 944 * We'll have to load it from file. 828 945 */ 829 rc = kldrDyldFindNewModule(pszDll, psz DefPrefix, pszDefSuffix, enmSearch, fFlags, ppMod);946 rc = kldrDyldFindNewModule(pszDll, pszPrefix, pszSuffix, enmSearch, fFlags, ppMod); 830 947 if (!rc) 831 948 rc = kldrDyldModMap(pMod); … … 1199 1316 * @internal 1200 1317 */ 1201 static int kldrDyldDoFindByName(const char *pszDll, const char *psz DefPrefix, const char *pszDefSuffix, KLDRDYLDSEARCH enmSearch,1318 static int kldrDyldDoFindByName(const char *pszDll, const char *pszPrefix, const char *pszSuffix, KLDRDYLDSEARCH enmSearch, 1202 1319 unsigned fFlags, PPKLDRDYLDMOD ppMod) 1203 1320 { 1204 return kldrDyldFindExistingModule(pszDll, psz DefPrefix, pszDefSuffix, enmSearch, fFlags, ppMod);1321 return kldrDyldFindExistingModule(pszDll, pszPrefix, pszSuffix, enmSearch, fFlags, ppMod); 1205 1322 } 1206 1323 … … 1269 1386 1270 1387 1271 #if 01272 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 executable1294 * 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 #endif1355 1356 1357 1388 /** 1358 1389 * Panic / failure … … 1363 1394 * @param ... Message string arguments. 1364 1395 */ 1365 int kldr Failure(int rc, const char *pszFormat, ...)1396 int kldrDyldFailure(int rc, const char *pszFilename, ...) 1366 1397 { 1367 1398 kldrHlpExit(1);
Note:
See TracChangeset
for help on using the changeset viewer.