Changeset 2875
- Timestamp:
- Nov 12, 2006, 9:59:45 AM (19 years ago)
- Location:
- trunk/kLdr
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kLdr/Makefile.kmk
r2874 r2875 144 144 kLdrExeStub-win_CFLAGS = -W3 -Zl 145 145 kLdrExeStub-win_CFLAGS.debug = -Zi 146 kLdrExeStub-win_LDFLAGS = -Entry:Win Main-FIXED:NO146 kLdrExeStub-win_LDFLAGS = -Entry:WindowsMain -SubSystem:Console -FIXED:NO 147 147 kLdrExeStub-win_LIBS = $(TARGET_kLdr:.dll=.lib) 148 148 kLdrExeStub-win_SOURCES = kLdrExeStub-win.c -
trunk/kLdr/kLdr.h
r2874 r2875 921 921 typedef struct KLDREXEARGS 922 922 { 923 /** Flags. (Currently unused, MBZ.)*/923 /** Load & search flags, some which will become defaults. */ 924 924 uint32_t fFlags; 925 /** The search method to use when loading this executable. */925 /** The default search method. */ 926 926 KLDRDYLDSEARCH enmSearch; 927 927 /** The executable file that the stub is supposed to load. */ … … 937 937 typedef const KLDREXEARGS *PCKLDREXEARGS; 938 938 939 void kLdrLoadExe(P KLDREXEARGS pArgs, void *pvOS);939 void kLdrLoadExe(PCKLDREXEARGS pArgs, void *pvOS); 940 940 941 941 /** @} */ -
trunk/kLdr/kLdrDyld.c
r2874 r2875 98 98 uint32_t kLdrDyldFlags = 0; 99 99 /** The default search method. */ 100 KLDRDYLDSEARCH kLdrDyldSearch = KLDRDYLD_SEARCH_ INVALID;100 KLDRDYLDSEARCH kLdrDyldSearch = KLDRDYLD_SEARCH_HOST; 101 101 102 102 … … 146 146 * @{ */ 147 147 void kldrDyldDoLoadExeStackSwitch(PKLDRDYLDMOD pExe, void *pvStack, size_t cbStack); 148 void kldrDyldDoLoadExe(PKLDRDYLDMOD pExe);149 148 static int kldrDyldDoLoad(const char *pszDll, const char *pszPrefix, const char *pszSuffix, KLDRDYLDSEARCH enmSearch, 150 149 unsigned fFlags, PPKLDRDYLDMOD ppMod, char *pszErr, size_t cchErr); … … 229 228 * @param pvOS OS specific argument. 230 229 */ 231 #ifndef __OS2__ 232 void kLdrDyldLoadExe(P KLDREXEARGS pArgs, void *pvOS)230 #ifndef __OS2__ /* kLdrDyldLoadExe is implemented in assembly on OS/2. */ 231 void kLdrDyldLoadExe(PCKLDREXEARGS pArgs, void *pvOS) 233 232 #else 234 void kldrDyldLoadExe(P KLDREXEARGS pArgs, void *pvOS)233 void kldrDyldLoadExe(PCKLDREXEARGS pArgs, void *pvOS) 235 234 #endif 236 235 { … … 241 240 242 241 /* 243 * Copy the arguments into the globals and do loader init (probably already initialized). 244 */ 245 kLdrDyldFlags = pArgs->fFlags; 242 * Indicate that we're boostrapping and ensure that initialization was successful. 243 */ 244 g_fBootstrapping = 1; 245 rc = kldrInit(); 246 if (rc) 247 kldrDyldFailure(rc, "Init failure, rc=%d", rc); 248 249 /* 250 * Validate the argument package. 251 */ 252 if (pArgs->fFlags & ~( KLDRYDLD_LOAD_FLAGS_GLOBAL_SYMBOLS 253 | KLDRYDLD_LOAD_FLAGS_DEEP_SYMBOLS 254 | KLDRDYLD_LOAD_FLAGS_RECURSIVE_INIT 255 | KLDRYDLD_LOAD_FLAGS_SPECIFIC_MODULE)) 256 kldrDyldFailure(KLDR_ERR_INVALID_PARAMETER, "Bad fFlags=%#x", pArgs->fFlags); 257 if ( pArgs->enmSearch <= KLDRDYLD_SEARCH_INVALID 258 || pArgs->enmSearch >= KLDRDYLD_SEARCH_END) 259 kldrDyldFailure(KLDR_ERR_INVALID_PARAMETER, "Bad enmSearch=%d", pArgs->enmSearch); 260 261 /* 262 * Set defaults. 263 */ 264 kLdrDyldFlags |= (pArgs->fFlags & KLDRDYLD_LOAD_FLAGS_RECURSIVE_INIT); 246 265 kLdrDyldSearch = pArgs->enmSearch; 266 267 /** @todo make sense of this default prefix/suffix stuff. */ 247 268 if (pArgs->szDefPrefix[0] != '\0') 248 269 kLdrHlpMemCopy(kLdrDyldDefPrefix, pArgs->szDefPrefix, KLDR_MIN(sizeof(pArgs->szDefPrefix), sizeof(kLdrDyldDefPrefix))); 249 270 if (pArgs->szDefSuffix[0] != '\0') 250 271 kLdrHlpMemCopy(kLdrDyldDefSuffix, pArgs->szDefSuffix, KLDR_MIN(sizeof(pArgs->szDefSuffix), sizeof(kLdrDyldDefSuffix))); 251 /* append */ /** @todo create a function for doing this, an exposed api preferably. */ 252 cbStack = sizeof(kLdrDyldPath) - kLdrHlpStrLen(kLdrDyldPath); /* borrow cbStack for a itty bit. */ 253 kLdrHlpMemCopy(kLdrDyldPath, pArgs->szLibPath, KLDR_MIN(sizeof(pArgs->szLibPath), cbStack)); 254 kLdrDyldPath[sizeof(kLdrDyldPath) - 1] = '\0'; 255 256 g_fBootstrapping = 1; 257 rc = kldrInit(); 258 if (rc) 259 kldrDyldFailure(rc, "Init failure, rc=%d", rc); 272 273 /** @todo append that path to the one for the specified search method. */ 274 /** @todo create a function for doing this, an exposed api preferably. */ 275 /* append path */ 276 cbStack = sizeof(kLdrDyldLibraryPath) - kLdrHlpStrLen(kLdrDyldLibraryPath); /* borrow cbStack for a itty bit. */ 277 kLdrHlpMemCopy(kLdrDyldLibraryPath, pArgs->szLibPath, KLDR_MIN(sizeof(pArgs->szLibPath), cbStack)); 278 kLdrDyldLibraryPath[sizeof(kLdrDyldLibraryPath) - 1] = '\0'; 260 279 261 280 /* … … 269 288 * Open and map the executable module before we join paths with kLdrDyldLoad(). 270 289 */ 271 rc = kldrDyldFindNewModule(pArgs->szExecutable, NULL, NULL, kLdrDyldSearch,272 kLdrDyldFlags | KLDRDYLD_LOAD_FLAGS_EXECUTABLE, &pExe);290 rc = kldrDyldFindNewModule(pArgs->szExecutable, NULL, NULL, pArgs->enmSearch, 291 pArgs->fFlags | KLDRDYLD_LOAD_FLAGS_EXECUTABLE, &pExe); 273 292 if (rc) 274 293 kldrDyldFailure(rc, "Can't find/open the executable '%s', rc=%d", pArgs->szExecutable, rc); … … 745 764 { 746 765 if (fFlags & KLDRDYLD_LOAD_FLAGS_EXECUTABLE) 747 pLoadedMod->cDepRefs = 0xffff; 766 { 767 pLoadedMod->cDepRefs++; /* just make it stick. */ 768 pLoadedMod->cRefs++; 769 } 748 770 else 749 771 rc = kldrDyldModDynamicLoad(pLoadedMod); -
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); -
trunk/kLdr/kLdrDyldOS.c
r2854 r2875 89 89 int kldrDyldOSStartExe(uintptr_t uMainEPAddress, void *pvStack, size_t cbStack) 90 90 { 91 #if defined(__OS2__) 92 93 #elif defined(__WIN__) 94 /* 95 * Invoke the entrypoint on the current stack for now. 96 * Deal with other formats and stack switching another day. 97 */ 98 int rc; 99 int (*pfnEP)(void); 100 pfnEP = (int (*)(void))uMainEPAddress; 101 102 rc = pfnEP(); 103 104 TerminateProcess(GetCurrentProcess(), rc); 105 kldrHlpAssert(!"TerminateProcess failed"); 106 for (;;) 107 TerminateProcess(GetCurrentProcess(), rc); 108 109 //#elif defined(__NT__) 110 #else 111 # error "Port me" 112 #endif 113 91 114 return -1; 92 115 } 93 116 117 94 118 void kldrDyldDoLoadExeStackSwitch(PKLDRDYLDMOD pExe, void *pvStack, size_t cbStack) 95 119 { 96 kldrHlpAssert(!"not implemented"); 120 //kldrHlpAssert(!"not implemented"); 121 122 /** @todo implement this properly! */ 123 kldrDyldDoLoadExe(pExe); 97 124 } -
trunk/kLdr/kLdrExeStub-win.c
r2874 r2875 48 48 49 49 /** 50 * Window 'main'50 * Windows 'main'. 51 51 */ 52 int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pszCmdLine, int nCmdShow)52 int WindowsMain(void) 53 53 { 54 54 return kLdrDyldLoadExe(&g_Args, NULL); -
trunk/kLdr/kLdrInternal.h
r2869 r2875 313 313 314 314 315 int kldrInit(void); 316 void kldrTerm(void); 317 318 int kldrDyldInit(void); 319 void kldrDyldTerm(void); 320 321 void kldrDyldDoLoadExe(PKLDRDYLDMOD pExe); 322 int kldrDyldFailure(int rc, const char *pszFormat, ...); 323 324 int kldrDyldOSStartExe(uintptr_t uMainEntrypoint, void *pvStack, size_t cbStack); 325 void *kldrDyldOSAllocStack(size_t cb); 326 327 int kldrDyldFindInit(void); 315 328 int kldrDyldFindNewModule(const char *pszName, const char *pszPrefix, const char *pszSuffix, 316 329 KLDRDYLDSEARCH enmSearch, unsigned fFlags, PPKLDRDYLDMOD ppMod); … … 353 366 int kldrDyldModQuerySymbol(PKLDRDYLDMOD pMod, uint32_t uSymbolOrdinal, const char *pszSymbolName, uintptr_t *puValue, uint32_t *pfKind); 354 367 355 int kldrDyldInit(void);356 void kldrDyldTerm(void);357 int kldrDyldFindInit(void);358 359 int kldrDyldFailure(int rc, const char *pszFormat, ...);360 int kldrInit(void);361 void kldrTerm(void);362 363 364 int kldrDyldOSStartExe(uintptr_t uMainEntrypoint, void *pvStack, size_t cbStack);365 void *kldrDyldOSAllocStack(size_t cb);366 367 368 368 369 /** Pointer to the head module (the executable). … … 403 404 extern char g_szkLdrDyldError[1024]; 404 405 405 extern char kLdrDyldPath[8192]; 406 extern char kLdrDyldExePath[8192]; 407 extern char kLdrDyldLibraryPath[8192]; 406 408 extern char kLdrDyldDefPrefix[16]; 407 409 extern char kLdrDyldDefSuffix[16]; 410 411 extern int g_fBootstrapping; 408 412 409 413 -
trunk/kLdr/testcase/Makefile.kmk
r2873 r2875 113 113 TEMPLATE_TSTBAREPROG_EXTENDS = TSTBARE 114 114 ifneq ($(filter win win32 win64,$(BUILD_TARGET)),) 115 TEMPLATE_TSTBAREPROG_LDFLAGS += -Entry:Win Main -FIXED:NO115 TEMPLATE_TSTBAREPROG_LDFLAGS += -Entry:WindowsMain -FIXED:NO 116 116 else 117 117 TEMPLATE_TSTBAREPROG_LDFLAGS.nt += -FIXED:NO -
trunk/kLdr/testcase/tstExeMainStub.c
r2873 r2875 36 36 37 37 #elif defined(__WIN__) 38 # include <windows.h> 38 /* nothing */ 39 39 40 40 #elif defined(__NT__) … … 64 64 * Window 'main' 65 65 */ 66 int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pszCmdLine, int nCmdShow)66 int WindowsMain(void) 67 67 { 68 68 int rc;
Note:
See TracChangeset
for help on using the changeset viewer.