Changeset 2875 for trunk/kLdr/kLdrDyldFind.c
- Timestamp:
- Nov 12, 2006, 9:59:45 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kLdr/kLdrDyldFind.c
r2870 r2875 105 105 /** @name The kLdr search method parameters. 106 106 * @{ */ 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 */ 111 char kLdrDyldExePath[8192]; 107 112 /** The kLdr DLL search path. 108 113 * During initialization the KLDR_LIBRARY_PATH env.var. and the path in the 109 114 * executable stub is appended. Both ';' and ':' can be used as separators. 110 115 */ 111 char kLdrDyld Path[8192];116 char kLdrDyldLibraryPath[8192]; 112 117 /** The kLdr application directory. 113 118 * This is initialized when the executable is 'loaded' or by a kLdr user. … … 195 200 * Internal Functions * 196 201 *******************************************************************************/ 197 static int kldrDyldFindDo Search(const char *pszName, const char *pszPrefix, const char *pszSuffix,202 static int kldrDyldFindDoDllSearch(const char *pszName, const char *pszPrefix, const char *pszSuffix, 198 203 KLDRDYLDSEARCH enmSearch, unsigned fFlags, PPKLDRRDR ppRdr); 204 static int kldrDyldFindDoExeSearch(const char *pszName, const char *pszPrefix, const char *pszSuffix, 205 KLDRDYLDSEARCH enmSearch, unsigned fFlags, PPKLDRRDR ppRdr); 199 206 static int kldrDyldFindTryOpen(const char *pszFilename, PPKLDRRDR ppRdr); 200 207 static int kldrDyldFindTryOpenPath(const char *pchPath, size_t cchPath, PCKLDRDYLDFINDARGS pArgs); 201 208 static int kldrDyldFindEnumeratePath(const char *pszSearchPath, PCKLDRDYLDFINDARGS pArgs); 202 static int kldrDyldFindGetDefaults(KLDRDYLDSEARCH *penmSearch, const char **pszPrefix, const char **pszSuffix, const char *pszName); 209 static int kldrDyldFindGetDefaults(KLDRDYLDSEARCH *penmSearch, const char **pszPrefix, 210 const char **pszSuffix, const char *pszName, uint32_t fFlags); 203 211 204 212 … … 217 225 * The kLdr search parameters. 218 226 */ 219 rc = kldrHlpGetEnv("KLDR_LIBRARY_PATH", kLdrDyld Path, sizeof(kLdrDyldPath));227 rc = kldrHlpGetEnv("KLDR_LIBRARY_PATH", kLdrDyldLibraryPath, sizeof(kLdrDyldLibraryPath)); 220 228 rc = kldrHlpGetEnv("KLDR_DEF_PREFIX", szTmp, sizeof(szTmp)); 221 229 if (!rc) … … 358 366 if (!kldrHlpIsFilenameOnly(pszName)) 359 367 rc = kldrDyldFindTryOpen(pszName, &pRdr); 368 else if (!(fFlags & KLDRDYLD_LOAD_FLAGS_EXECUTABLE)) 369 rc = kldrDyldFindDoDllSearch(pszName, pszPrefix, pszSuffix, enmSearch, fFlags, &pRdr); 360 370 else 361 rc = kldrDyldFindDo Search(pszName, pszPrefix, pszSuffix, enmSearch, fFlags, &pRdr);371 rc = kldrDyldFindDoExeSearch(pszName, pszPrefix, pszSuffix, enmSearch, fFlags, &pRdr); 362 372 if (!rc) 363 373 { … … 411 421 412 422 /** 413 * Searches for a file using the specified method.423 * Searches for a DLL file using the specified method. 414 424 * 415 425 * @returns 0 on success and *ppMod pointing to the new module. … … 423 433 * @param ppRdr Where to store the pointer to the file provider instance on success. 424 434 */ 425 static int kldrDyldFindDo Search(const char *pszName, const char *pszPrefix, const char *pszSuffix,426 KLDRDYLDSEARCH enmSearch, unsigned fFlags, PPKLDRRDR ppRdr)435 static int kldrDyldFindDoDllSearch(const char *pszName, const char *pszPrefix, const char *pszSuffix, 436 KLDRDYLDSEARCH enmSearch, unsigned fFlags, PPKLDRRDR ppRdr) 427 437 { 428 438 int rc; … … 435 445 Args.pszPrefix = pszPrefix; 436 446 Args.pszSuffix = pszSuffix; 437 rc = kldrDyldFindGetDefaults(&Args.enmSearch, &Args.pszPrefix, &Args.pszSuffix, pszName );447 rc = kldrDyldFindGetDefaults(&Args.enmSearch, &Args.pszPrefix, &Args.pszSuffix, pszName, fFlags); 438 448 if (rc) 439 449 return rc; … … 464 474 if (rc != KLDR_ERR_MODULE_NOT_FOUND) 465 475 break; 466 rc = kldrDyldFindEnumeratePath(kLdrDyld Path, &Args);476 rc = kldrDyldFindEnumeratePath(kLdrDyldLibraryPath, &Args); 467 477 break; 468 478 } … … 525 535 526 536 /** 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 */ 549 static 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 /** 527 603 * Try open the specfied file. 528 604 * … … 565 641 static char s_szFilename[1024]; 566 642 char *psz; 643 int rc; 567 644 568 645 /* … … 612 689 *psz = '\0'; 613 690 691 614 692 /* 615 693 * Try open it. 616 694 */ 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; 618 706 } 619 707 … … 689 777 * @param ppszSuffix The suffix. In/Out. 690 778 * @param pszName The name. In. 779 * @param fFlags The load/search flags. 691 780 */ 692 781 static int kldrDyldFindGetDefaults(KLDRDYLDSEARCH *penmSearch, const char **ppszPrefix, const char **ppszSuffix, 693 const char *pszName )782 const char *pszName, uint32_t fFlags) 694 783 { 695 784 unsigned fCaseSensitive; … … 722 811 case KLDRDYLD_SEARCH_OS2: 723 812 if (!*ppszSuffix) 724 *ppszSuffix = ".dll";813 *ppszSuffix = !(fFlags & KLDRDYLD_LOAD_FLAGS_EXECUTABLE) ? ".dll" : ".exe"; 725 814 fCaseSensitive = 0; 726 815 break; … … 729 818 case KLDRDYLD_SEARCH_WINDOWS_ALTERED: 730 819 if (!*ppszSuffix) 731 *ppszSuffix = ".dll";820 *ppszSuffix = !(fFlags & KLDRDYLD_LOAD_FLAGS_EXECUTABLE) ? ".dll" : ".exe"; 732 821 fCaseSensitive = 0; 733 822 break; … … 790 879 * Defaults. 791 880 */ 792 rc = kldrDyldFindGetDefaults(&enmSearch, &pszPrefix, &pszSuffix, pszName );881 rc = kldrDyldFindGetDefaults(&enmSearch, &pszPrefix, &pszSuffix, pszName, fFlags); 793 882 if (rc) 794 883 return rc; … … 812 901 PKLDRRDR pRdr; 813 902 if (fOS2LibpathStrict) 814 rc = kldrDyldFindDo Search(pszName, pszPrefix, pszSuffix, enmSearch, fFlags, &pRdr);903 rc = kldrDyldFindDoDllSearch(pszName, pszPrefix, pszSuffix, enmSearch, fFlags, &pRdr); 815 904 else 816 905 rc = kldrDyldFindTryOpen(pszName, &pRdr);
Note:
See TracChangeset
for help on using the changeset viewer.