Changeset 2836
- Timestamp:
- Oct 26, 2006, 5:58:53 AM (19 years ago)
- Location:
- trunk/kLdr
- Files:
-
- 5 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/kLdr/Makefile.kmk
r2835 r2836 91 91 kLdr_SOURCES = \ 92 92 kLdr.c \ 93 kLdrDy.c \ 93 kLdrDyld.c \ 94 kLdrDyldFind.c \ 94 95 kLdrDyldMod.c \ 95 kLdrDySearch.c \96 96 kLdrHlp.c \ 97 97 kLdrHlpHeap.c \ -
trunk/kLdr/kLdr.h
r2835 r2836 44 44 typedef signed __int64 int64_t; 45 45 typedef unsigned __int64 uint64_t; 46 typedef int64_t intmax_t; 46 47 typedef uint64_t uintmax_t; 47 48 #else … … 287 288 const char *pszName; 288 289 /** The size of the segment. */ 289 size_tcb;290 uintmax_t cb; 290 291 /** The link time load address. */ 291 void *pvLink;292 uintmax_t LinkAddress; 292 293 /** The actual load address (if loaded). */ 293 void *pv;294 uintmax_t LoadAddress; 294 295 /** The segment protection. */ 295 296 KLDRPROT enmProt; … … 609 610 } KLDRDYLDSEARCH; 610 611 611 /** @name kLdr LoadDllflags.612 /** @name kLdrDyldLoad and kLdrDyldFindByName flags. 612 613 * @{ */ 613 614 /** The symbols in the module should be loaded into the global unix namespace. … … 625 626 unsigned fFlags, PHKLDRMOD phMod, char *pszErr, size_t cchErr); 626 627 int kLdrDyldUnload(HKLDRMOD hMod); 627 int kLdrDyldFindByName(const char *pszDll, const char *pszDefPrefix, const char *pszDefSuffix, KLDRDYLDSEARCH enmSearch, PHKLDRMOD phMod); 628 int kLdrDyldFindByName(const char *pszDll, const char *pszDefPrefix, const char *pszDefSuffix, KLDRDYLDSEARCH enmSearch, 629 unsigned fFlags, PHKLDRMOD phMod); 628 630 int kLdrDyldFindByAddress(uintptr_t Address, PHKLDRMOD phMod, uint32_t *piSegment, uintptr_t *poffSegment); 629 631 int kLdrDyldGetName(HKLDRMOD hMod, char *pszName, size_t cchName); … … 728 730 /** Invalid handle parameter to a kLdr API. */ 729 731 #define KLDR_ERR_INVALID_HANDLE (KLDR_ERR_BASE + 33) 732 /** The module wasn't found. */ 733 #define KLDR_ERR_MODULE_NOT_FOUND (KLDR_ERR_BASE + 34) 730 734 731 735 /** Encountered a bad fixup. */ -
trunk/kLdr/kLdrDyld.c
r2833 r2836 32 32 #include "kLdrHlp.h" 33 33 #include "kLdrInternal.h" 34 35 36 /******************************************************************************* 37 * Defined Constants And Macros * 38 *******************************************************************************/ 39 /** @def KLDRDYLD_STRICT 40 * Define KLDRDYLD_STRICT to enabled strict checks in kLdrDyld. */ 41 #define KLDRDYLD_STRICT 1 42 43 /** @def KLDRDYLD_ASSERT 44 * Assert that an expression is true when KLDRDYLD_STRICT is defined. 45 */ 46 #ifdef KLDRDYLD_STRICT 47 # define KLDRDYLD_ASSERT(expr) kldrHlpAssert(expr) 48 #else 49 # define KLDRDYLD_ASSERT(expr) do {} while (0) 50 #endif 34 51 35 52 … … 43 60 * (This is exported, so no prefix.) */ 44 61 PKLDRDYLDMOD kLdrDyldTail = NULL; 62 /** Pointer to the head module of the termination order list. */ 63 PKLDRDYLDMOD g_pkLdrDyldTermHead; 64 /** Pointer to the tail module of the termination order list. */ 65 PKLDRDYLDMOD g_pkLdrDyldTermTail; 66 /** Pointer to the head module of the bind order list. 67 * The modules in this list makes up the global namespace used when binding symbol unix fashion. */ 68 PKLDRDYLDMOD g_pkLdrDyldBindHead; 69 /** Pointer to the tail module of the bind order list. */ 70 PKLDRDYLDMOD g_pkLdrDyldBindTail; 71 72 /** Stack of modules involved in the active loads. 73 * 74 * The main purpose is to allow module init routines to loading and unloading 75 * modules without upsetting the init order and to assist in dereferencing 76 * modules on load failure. 77 * 78 * Each call to kLdrDyldLoad and kLdrDyldLoadExe will start a load frame 79 * when doing a fresh load. All dependant modules will be pushed on each 80 * reference. The frame is completed when all the dependant modules has 81 * been resolved (or a failure occurs). After doing fixups, the frame is 82 * used to do module initialization. Should an error occur during the load 83 * the frame will be used to dereference all the modules involved in the 84 * load operation (it will not however, be used for termination calls as 85 * they are postponed till the last load operation completes). 86 * 87 * Should any of the init calls load a module, a new frame will be created 88 * for that operation and processed before the init call returns to the 89 * previous frame. 90 */ 91 PPKLDRDYLDMOD g_pakLdrDyld; 92 /** The number of used entries in the g_pakLdrDyld array. */ 93 uint32_t g_ckLdrDyld; 94 /** The number of entries allocated for the g_pakLdrDyld array. */ 95 uint32_t g_ckLdrDyldAllocated; 96 97 /** The global error buffer. */ 98 char g_szkLdrDyldError[1024]; 99 45 100 /** The Library search path. */ 46 101 char kLdrDyldLibraryPath[4096]; … … 52 107 * Internal Functions * 53 108 *******************************************************************************/ 54 static int kldrDyldLoad(const char *pszDll, const char *pszDefPrefix, const char *pszDefSuffix, KLDRDYLDSEARCH enmSearch, 55 unsigned fFlags, PPKLDRDYLDMOD ppMod, char *pszErr, size_t cchErr); 56 static int kldrDyldUnload(PKLDRDYLDMOD pMod); 57 static int kldrDyldFindByName(const char *pszDll, const char *pszDefPrefix, const char *pszDefSuffix, KLDRDYLDSEARCH enmSearch, PPKLDRDYLDMOD ppMod); 58 static int kldrDyldFindByAddress(uintptr_t Address, PPKLDRDYLDMOD ppMod, uint32_t *piSegment, uintptr_t *poffSegment); 59 static int kldrDyldGetName(PKLDRDYLDMOD pMod, char *pszName, size_t cchName); 60 static int kldrDyldGetFilename(PKLDRDYLDMOD pMod, char *pszFilename, size_t cchFilename); 61 static int kldrDyldQuerySymbol(PKLDRDYLDMOD pMod, uint32_t uSymbolOrdinal, const char *pszSymbolName, uintptr_t *pValue, uint32_t *pfKind); 109 static int kldrDyldDoLoad(const char *pszDll, const char *pszDefPrefix, const char *pszDefSuffix, KLDRDYLDSEARCH enmSearch, 110 unsigned fFlags, PPKLDRDYLDMOD ppMod, char *pszErr, size_t cchErr); 111 static int kldrDyldDoUnload(PKLDRDYLDMOD pMod); 112 static int kldrDyldDoFindByName(const char *pszDll, const char *pszDefPrefix, const char *pszDefSuffix, KLDRDYLDSEARCH enmSearch, 113 unsigned fFlags, PPKLDRDYLDMOD ppMod); 114 static int kldrDyldDoFindByAddress(uintptr_t Address, PPKLDRDYLDMOD ppMod, uint32_t *piSegment, uintptr_t *poffSegment); 115 static int kldrDyldDoGetName(PKLDRDYLDMOD pMod, char *pszName, size_t cchName); 116 static int kldrDyldDoGetFilename(PKLDRDYLDMOD pMod, char *pszFilename, size_t cchFilename); 117 static int kldrDyldDoQuerySymbol(PKLDRDYLDMOD pMod, uint32_t uSymbolOrdinal, const char *pszSymbolName, uintptr_t *pValue, uint32_t *pfKind); 118 static void kldrDyldStartLoading(void); 119 static void kldrDyldStopLoading(void); 120 static int kldrDyldCopyError(int rc, char *pszErr, size_t cchErr); 62 121 63 122 … … 68 127 int kldrDyInit(void) 69 128 { 70 kLdrDyldHead = NULL; 71 kLdrDyldTail = NULL; 129 kLdrDyldHead = kLdrDyldTail = NULL; 130 g_pkLdrDyldTermHead = g_pkLdrDyldTermTail = NULL; 131 g_pkLdrDyldBindHead = g_pkLdrDyldBindTail = NULL; 72 132 kLdrDyldFlags = 0; 133 g_szkLdrDyldError[0] = '\0'; 73 134 return 0; 74 135 } … … 117 178 { 118 179 PKLDRDYLDMOD pMod = NULL; 119 rc = kldrDyld Load(pszDll, pszDefPrefix, pszDefSuffix, enmSearch, fFlags, phMod, pszErr, cchErr);180 rc = kldrDyldDoLoad(pszDll, pszDefPrefix, pszDefSuffix, enmSearch, fFlags, phMod, pszErr, cchErr); 120 181 kldrHlpSemRelease(); 121 182 *phMod = pMod; … … 142 203 if (!rc) 143 204 { 144 rc = kldrDyld Unload(hMod);205 rc = kldrDyldDoUnload(hMod); 145 206 kldrHlpSemRelease(); 146 207 } … … 158 219 * @returns KLDR_ERR_MODULE_NOT_FOUND on failure. 159 220 * @param pszDll The name of the dll to look for. 160 * @param pszDefPrefix Prefix t o usewhen searching.161 * @param pszDefSuffix Suffix t o usewhen searching.221 * @param pszDefPrefix Prefix than can be used when searching. 222 * @param pszDefSuffix Suffix than can be used when searching. 162 223 * @param enmSearch Method to use when locating the module. 224 * @param fFlags Flags, a combintation of the KLDRYDLD_LOAD_FLAGS_* \#defines. 163 225 * @param phMod Where to store the handle of the module on success. 164 226 */ 165 int kLdrDyldFindByName(const char *pszDll, const char *pszDefPrefix, const char *pszDefSuffix, KLDRDYLDSEARCH enmSearch, PHKLDRMOD phMod) 227 int kLdrDyldFindByName(const char *pszDll, const char *pszDefPrefix, const char *pszDefSuffix, KLDRDYLDSEARCH enmSearch, 228 unsigned fFlags, PHKLDRMOD phMod) 166 229 { 167 230 int rc; … … 176 239 { 177 240 PKLDRDYLDMOD pMod = NULL; 178 rc = kldrDyld FindByName(pszDll, pszDefPrefix, pszDefSuffix, enmSearch, phMod);241 rc = kldrDyldDoFindByName(pszDll, pszDefPrefix, pszDefSuffix, enmSearch, fFlags, phMod); 179 242 kldrHlpSemRelease(); 180 243 *phMod = pMod; … … 213 276 { 214 277 PKLDRDYLDMOD pMod = NULL; 215 rc = kldrDyld FindByAddress(Address, &pMod, piSegment, poffSegment);278 rc = kldrDyldDoFindByAddress(Address, &pMod, piSegment, poffSegment); 216 279 kldrHlpSemRelease(); 217 280 *phMod = pMod; … … 245 308 if (!rc) 246 309 { 247 rc = kldrDyld GetName(hMod, pszName, cchName);310 rc = kldrDyldDoGetName(hMod, pszName, cchName); 248 311 kldrHlpSemRelease(); 249 312 } … … 276 339 if (!rc) 277 340 { 278 rc = kldrDyld GetFilename(hMod, pszFilename, cchFilename);341 rc = kldrDyldDoGetFilename(hMod, pszFilename, cchFilename); 279 342 kldrHlpSemRelease(); 280 343 } … … 312 375 if (!rc) 313 376 { 314 rc = kldrDyld QuerySymbol(hMod, uSymbolOrdinal, pszSymbolName, pValue, pfKind);377 rc = kldrDyldDoQuerySymbol(hMod, uSymbolOrdinal, pszSymbolName, pValue, pfKind); 315 378 kldrHlpSemRelease(); 316 379 } … … 322 385 323 386 324 325 /** 326 * Worker for kldrDyldLoad(). 387 /** 388 * Worker for kLdrDyldLoad(). 327 389 * @internal 328 390 */ 329 static int kldrDyldLoad(const char *pszDll, const char *pszDefPrefix, const char *pszDefSuffix, KLDRDYLDSEARCH enmSearch, 330 unsigned fFlags, PPKLDRDYLDMOD ppMod, char *pszErr, size_t cchErr) 331 { 332 /* 333 * Open the module. 334 */ 335 336 337 return -1; 338 } 339 340 341 /** 342 * Worker for kldrDyldUnload(). 391 static int kldrDyldDoLoad(const char *pszDll, const char *pszDefPrefix, const char *pszDefSuffix, KLDRDYLDSEARCH enmSearch, 392 unsigned fFlags, PPKLDRDYLDMOD ppMod, char *pszErr, size_t cchErr) 393 { 394 int rc; 395 396 /* 397 * Try find it among the modules that's already loaded. 398 */ 399 rc = kldrDyldFindExistingModule(pszDll, pszDefPrefix, pszDefSuffix, enmSearch, fFlags, ppMod); 400 if (!rc) 401 { 402 /* 403 * If we're in a module termination call we must check that all the modules we 404 * depend on are loaded and initialized. 405 */ 406 //continue here if ((*ppMod)->enmState::KLDRSTATE_LOADED) 407 { 408 kldrHlpAssert(!"implement me"); 409 } 410 return kldrDyldModDynamicLoad(*ppMod); 411 } 412 413 /* 414 * Try open it. 415 */ 416 kldrDyldStartLoading(); 417 rc = kldrDyldFindNewModule(pszDll, pszDefPrefix, pszDefSuffix, enmSearch, fFlags, ppMod); 418 if (!rc) 419 { 420 421 422 } 423 return kldrDyldCopyError(rc, pszErr, cchErr); 424 } 425 426 427 /** 428 * Worker for kLdrDyldUnload(). 343 429 * @internal 344 430 */ 345 static int kldrDyld Unload(HKLDRMOD hMod)346 { 347 return -1;431 static int kldrDyldDoUnload(PKLDRDYLDMOD pMod) 432 { 433 return kldrDyldModDynamicUnload(pMod); 348 434 } 349 435 … … 353 439 * @internal 354 440 */ 355 static int kldrDyldFindByName(const char *pszDll, const char *pszDefPrefix, const char *pszDefSuffix, KLDRDYLDSEARCH enmSearch, PPKLDRDYLDMOD ppMod) 356 { 357 return -1; 441 static int kldrDyldDoFindByName(const char *pszDll, const char *pszDefPrefix, const char *pszDefSuffix, KLDRDYLDSEARCH enmSearch, 442 unsigned fFlags, PPKLDRDYLDMOD ppMod) 443 { 444 return kldrDyldFindExistingModule(pszDll, pszDefPrefix, pszDefSuffix, enmSearch, fFlags, ppMod); 358 445 } 359 446 … … 363 450 * @internal 364 451 */ 365 static int kldrDyldFindByAddress(uintptr_t Address, PPKLDRDYLDMOD ppMod, uint32_t *piSegment, uintptr_t *poffSegment) 366 { 367 return -1; 452 static int kldrDyldDoFindByAddress(uintptr_t Address, PPKLDRDYLDMOD ppMod, uint32_t *piSegment, uintptr_t *poffSegment) 453 { 454 /* Scan the segments of each module in the load list. */ 455 PKLDRDYLDMOD pMod = kLdrDyldHead; 456 while (pMod) 457 { 458 uint32_t iSeg; 459 for (iSeg = 0; iSeg < pMod->pMod->cSegments; iSeg++) 460 { 461 uintmax_t off = (uintmax_t)Address - pMod->pMod->aSegments[iSeg].LoadAddress; 462 if (off < pMod->pMod->aSegments[iSeg].cb) 463 { 464 *ppMod = pMod->hMod; 465 if (piSegment) 466 *piSegment = iSeg; 467 if (poffSegment) 468 *poffSegment = (uintptr_t)off; 469 return 0; 470 } 471 } 472 473 /* next */ 474 pMod = pMod->Load.pNext; 475 } 476 477 return KLDR_ERR_MODULE_NOT_FOUND; 368 478 } 369 479 … … 373 483 * @internal 374 484 */ 375 static int kldrDyld GetName(PKLDRDYLDMOD pMod, char *pszName, size_t cchName)376 { 377 return -1;485 static int kldrDyldDoGetName(PKLDRDYLDMOD pMod, char *pszName, size_t cchName) 486 { 487 return kldrDyldModGetName(pMod, pszName, cchName); 378 488 } 379 489 … … 383 493 * @internal 384 494 */ 385 static int kldrDyld GetFilename(PKLDRDYLDMOD pMod, char *pszFilename, size_t cchFilename)386 { 387 return -1;495 static int kldrDyldDoGetFilename(PKLDRDYLDMOD pMod, char *pszFilename, size_t cchFilename) 496 { 497 return kldrDyldModGetFilename(pMod, pszFilename, cchFilename); 388 498 } 389 499 … … 393 503 * @internal 394 504 */ 395 static int kldrDyld QuerySymbol(PKLDRDYLDMOD pMod, uint32_t uSymbolOrdinal, const char *pszSymbolName, uintptr_t *pValue, uint32_t *pfKind)396 { 397 return -1;505 static int kldrDyldDoQuerySymbol(PKLDRDYLDMOD pMod, uint32_t uSymbolOrdinal, const char *pszSymbolName, uintptr_t *pValue, uint32_t *pfKind) 506 { 507 return kldrDyldModQuerySymbol(pMod, uSymbolOrdinal, pszSymbolName, pValue, pfKind); 398 508 } 399 509 … … 482 592 } 483 593 594 #endif 595 596 /** 597 * Starts loading a new module and its dependencies. 598 */ 599 static void kldrDyldStartLoading(void) 600 { 601 #ifdef KLDRDYLD_STRICT 602 /* check that all modules are in the correct state */ 603 PKLDRDYLDMOD pMod = kLdrDyldHead; 604 while (pMod) 605 { 606 //KLDRDYLD_ASSERT(pMod->enmState == KLDRSTATE_LOADED); 607 608 /* next */ 609 pMod = pMod->Load.pNext; 610 } 611 #endif 612 } 613 614 615 /** 616 * Records the loading of the module. 617 * 618 * @return 0 on success, KLDR_ERR_NO_MEMORY if we can't expand the table. 619 * @param pMod The module to record. 620 */ 621 static int kldrDyldRecord(PKLDRDYLDMOD pMod) 622 { 623 624 } 625 626 627 628 /** 629 * Done loading a module and its dependencies. 630 * 631 * If the load failed, unload all the modules involved. 632 * If the load succeeded, 633 * 634 * @returns rc. 635 * @param rc The status code. 636 */ 637 static void kldrDyldDoneLoading(int rc) 638 { 639 640 } 641 642 484 643 485 644 /** … … 493 652 int kldrFailure(int rc, const char *pszFormat, ...) 494 653 { 495 kldrExit(1); 496 return rc; 497 } 498 499 #endif 500 654 kldrHlpExit(1); 655 return rc; 656 } 657 658 659 /** 660 * Copies the error string to the user buffer. 661 * 662 * @returns rc. 663 * @param rc The status code. 664 * @param pszErr Where to copy the error string to. 665 * @param cchErr The size of the destination buffer. 666 */ 667 static int kldrDyldCopyError(int rc, char *pszErr, size_t cchErr) 668 { 669 size_t cchToCopy; 670 671 /* if no error string, format the rc into a string. */ 672 if (!g_szkLdrDyldError[0] && rc) 673 kldrHlpInt2Ascii(g_szkLdrDyldError, sizeof(g_szkLdrDyldError), rc, 10); 674 675 /* copy it if we got something. */ 676 if (cchErr && pszErr && g_szkLdrDyldError[0]) 677 { 678 cchToCopy = kLdrHlpStrLen(g_szkLdrDyldError); 679 if (cchToCopy >= cchErr) 680 cchToCopy = cchErr - 1; 681 kLdrHlpMemCopy(pszErr, g_szkLdrDyldError, cchToCopy); 682 pszErr[cchToCopy] = '\0'; 683 } 684 685 return rc; 686 } 687 -
trunk/kLdr/kLdrDyldFind.c
r2835 r2836 41 41 * 42 42 * @param pszName Partial or complete name, it's specific to the search method to determin which. 43 * @param psz Prefix Prefix that might be used (that's method specific).44 * @param psz Suffix Suffix that can be applied to an incomplete name.43 * @param pszDefPrefix Prefix than can be used when searching. 44 * @param pszDefSuffix Suffix than can be used when searching. 45 45 * @param enmSearch The file search method to apply. 46 46 * @param fFlags Search flags. … … 61 61 * 62 62 * @param pszName Partial or complete name, it's specific to the search method to determin which. 63 * @param psz Prefix Prefix that might be used (that's method specific).64 * @param psz Suffix Suffix that can be applied to an incomplete name.63 * @param pszDefPrefix Prefix than can be used when searching. 64 * @param pszDefSuffix Suffix than can be used when searching. 65 65 * @param enmSearch The file search method to apply. 66 66 * @param fFlags Search flags. -
trunk/kLdr/kLdrHlp.c
r2832 r2836 494 494 495 495 496 /** Internal worker for kldrHlpAssertMsg. */ 497 static void int2dec(char *pszLine, unsigned iLine) 498 { 499 do 500 { 501 *pszLine = (iLine % 10) + '0'; 502 iLine /= 10; 503 } while (iLine); 504 *pszLine++ = '\0'; 496 /** 497 * Converts an signed integer to an ascii string. 498 * 499 * @returns psz. 500 * @param psz Pointer to the output buffer. 501 * @param cch The size of the output buffer. 502 * @param lVal The value. 503 * @param iBase The base to format it. (2,8,10 or 16) 504 */ 505 char *kldrHlpInt2Ascii(char *psz, size_t cch, long lVal, unsigned iBase) 506 { 507 static const char s_szDigits[] = "0123456789abcdefghijklmnopqrstuvwxyz"; 508 char *pszRet = psz; 509 510 if (cch >= (lVal < 0 ? 3U : 2U) && psz) 511 { 512 /* prefix */ 513 if (lVal < 0) 514 { 515 *psz++ = '-'; 516 cch--; 517 lVal = -lVal; 518 } 519 520 /* the digits */ 521 do 522 { 523 *psz++ = s_szDigits[lVal % iBase]; 524 cch--; 525 lVal /= iBase; 526 } while (lVal && cch > 1); 527 528 /* overflow indicator */ 529 if (lVal) 530 psz[-1] = '+'; 531 } 532 else if (!pszRet) 533 return pszRet; 534 else if (cch < 1 || !pszRet) 535 return pszRet; 536 else 537 *psz++ = '+'; 538 *psz = '\0'; 539 540 return pszRet; 505 541 } 506 542 … … 574 610 kldrHlpAssertWrite(pszFile); 575 611 kldrHlpAssertWrite("("); 576 int2dec(szLine, iLine); 577 kldrHlpAssertWrite(szLine); 612 kldrHlpAssertWrite(kldrHlpInt2Ascii(szLine, sizeof(szLine), iLine, 10)); 578 613 kldrHlpAssertWrite(") "); 579 614 kldrHlpAssertWrite(pszFunction); -
trunk/kLdr/kLdrHlp.h
r2833 r2836 146 146 void kldrHlpExit(int rc); 147 147 void kldrHlpSleep(unsigned cMillies); 148 char *kldrHlpInt2Ascii(char *psz, size_t cch, long lVal, unsigned iBase); 148 149 void kldrHlpAssertMsg(const char *pszExpr, const char *pszFile, unsigned iLine, const char *pszFunction); 149 150 -
trunk/kLdr/kLdrInternal.h
r2835 r2836 70 70 /** The usual invalid 0 enum. */ 71 71 KLDRSTATE_INVALID = 0, 72 /** kldrOpen succeeded. 73 * Modules in this state will be freed at */ 72 /** The module has just been opened and has no references. 73 * Prev state: - 74 * Next state: MAPPED, DESTROYED 75 */ 74 76 KLDRSTATE_OPEN, 75 /** Dependencies has been loaded. */ 76 KLDRSTATE_DEPS, 77 /** Fixups has been applied. */ 78 KLDRSTATE_FIXED, 79 /** The module has been initialized. */ 80 KLDRSTATE_INITED, 81 /** The module is loaded successfully. */ 82 KLDRSTATE_LOADED, 77 /** The module been mapped. 78 * Prev state: OPEN 79 * Next state: LOADED_DEPS, DESTROYED 80 */ 81 KLDRSTATE_MAPPED, 82 /** The immediate dependencies has been loaded. 83 * Prev state: MAPPED 84 * Next state: FIXED_UP, DESTROYED 85 */ 86 KLDRSTATE_LOADED_DEPS, 87 /** Fixups has been applied. 88 * Prev state: LOADED_DEPS 89 * Next state: PENDING_INIT, DESTROYED 90 */ 91 KLDRSTATE_FIXED_UP, 92 /** Pending initialization. 93 * (The loader can now be in a re-entrant mode.) 94 * Prev state: FIXED_UP 95 * Next state: PENDING_INITIALIZATION, PENDING_GC 96 */ 97 KLDRSTATE_PENDING_INITIALIZATION, 98 /** Initializing. 99 * (The loader is now in a re-entrant mode.) 100 * Prev state: PENDING_INITIALIZATION 101 * Next state: GOOD, PENDING_GC 102 */ 103 KLDRSTATE_INITIALIZING, 104 /** The module has been successfully loaded and initialized. 105 * (The loader can still be in a re-entrant mode.) 106 * Prev state: INITIALIZING 107 * Next state: PENDING_TERMINATION 108 * Re-entrant. 109 */ 110 KLDRSTATE_GOOD, 111 /** Pending termination, reference count is 0. 112 * (The loader can now be in a re-entrant mode.) 113 * Prev state: GOOD 114 * Next state: TERMINATING, GOOD 115 */ 116 KLDRSTATE_PENDING_TERMINATION, 117 /** Terminating, reference count is still 0. 118 * (The loader is now in a re-entrant mode, but loading is a bit restricted.) 119 * Prev state: PENDING_TERMINATION 120 * Next state: PENDING_GC 121 */ 122 KLDRSTATE_TERMINATING, 123 /** Pending garbage collection. 124 * (The loader can still be in a re-entrant mode.) 125 * Prev state: TERMINATING, INITIALIZING, PENDING_INITIALIZATION 126 * Next state: GC, RELOADING 127 */ 128 KLDRSTATE_PENDING_GC, 129 /** Being garbage collected. 130 * (The loader can still be in a re-entrant mode.) 131 * Prev state: PENDING_GC 132 * Next state: DESTROYED 133 */ 134 KLDRSTATE_GC, 135 /** The module is being reloaded after having been scheduled for termination or/and GC. 136 * (The loader can still be in a re-entrant mode.) 137 * Prev state: PENDING_GC 138 * Next state: PENDING_INITIALIZATION 139 */ 140 KLDRSTATE_RELOADING, 141 /** The module has been destroyed and is no longer valid. 142 * Prev state: GC 143 */ 144 KLDRSTATE_DESTROYED, 83 145 /** The end of valid states (exclusive) */ 84 KLDRSTATE_END ,146 KLDRSTATE_END = KLDRSTATE_DESTROYED, 85 147 /** The usual 32-bit blowup. */ 86 148 KLDRSTATE_32BIT_HACK = 0x7fffffff … … 99 161 /** The module. */ 100 162 PKLDRMOD pMod; 163 /** The module handle. */ 164 HKLDRMOD hMod; 101 165 /** The number of references. */ 102 166 uint32_t cRefs; 103 167 /** The number of dynamic references. */ 104 168 uint32_t cDynRefs; 105 /** Set if this is the executable module. */ 169 /** The number of dynamic load operations in progress. 170 * This is used to reject anyone trying to unload a module before the load has 171 * been completed. An alternative to this would be to not add the cDynRefs until 172 * the load operation has completed... */ 173 uint32_t cDynRefsInProgress; 174 /** Set if this is the executable module. 175 * When clear, the module is a shared object or relocatable object. */ 106 176 uint32_t fExecutable : 1; 107 177 /** Global DLL (set) or specific DLL (clear). */ 108 uint32_t fGlobal : 1;109 /** Load stage one. */110 uint32_t f LoadStageOne : 1;178 uint32_t fGlobalOrSpecific : 1; 179 /** Whether the module contains bindable symbols in the global unix namespace. */ 180 uint32_t fBindable : 1; 111 181 /** Reserved for future use. */ 112 182 uint32_t fReserved : 29; 113 /** The next module in the list. */ 114 struct KLDRDYMOD *pNext; 115 /** The prev module in the list. */ 116 struct KLDRDYMOD *pPrev; 183 /** The load list linkage. */ 184 struct 185 { 186 /** The next module in the list. */ 187 struct KLDRDYLDMOD *pNext; 188 /** The prev module in the list. */ 189 struct KLDRDYLDMOD *pPrev; 190 } Load; 191 /** The termination list linkage. */ 192 struct 193 { 194 /** The next module in the list. */ 195 struct KLDRDYLDMOD *pNext; 196 /** The prev module in the list. */ 197 struct KLDRDYLDMOD *pPrev; 198 } Term; 199 /** The bind order list linkage. 200 * The module is not in this list when fBindable is clear. */ 201 struct 202 { 203 /** The next module in the list. */ 204 struct KLDRDYLDMOD *pNext; 205 /** The prev module in the list. */ 206 struct KLDRDYLDMOD *pPrev; 207 } Bind; 117 208 /** Magic number. */ 118 209 uint32_t u32MagicTail; 119 210 } KLDRDYLDMOD, *PKLDRDYLDMOD, **PPKLDRDYLDMOD; 120 211 121 /** KLDRDY MOD magic value. (Fuyumi Soryo) */212 /** KLDRDYLDMOD magic value. (Fuyumi Soryo) */ 122 213 #define KLDRDYMOD_MAGIC 0x19590106 123 214 … … 134 225 135 226 136 int kldrDyldFindNewModule(const char *pszName, const char *psz Prefix, const char *pszSuffix,227 int kldrDyldFindNewModule(const char *pszName, const char *pszDefPrefix, const char *pszDefSuffix, 137 228 KLDRDYLDSEARCH enmSearch, unsigned fFlags, PPKLDRDYLDMOD ppMod); 138 int kldrDyldFindExistingModule(const char *pszName, const char *psz Prefix, const char *pszSuffix,229 int kldrDyldFindExistingModule(const char *pszName, const char *pszDefPrefix, const char *pszDefSuffix, 139 230 KLDRDYLDSEARCH enmSearch, unsigned fFlags, PPKLDRDYLDMOD ppMod); 140 231 … … 158 249 int kldrDyldModCallInit(PKLDRDYLDMOD pMod); 159 250 int kldrDyldModCallTerm(PKLDRDYLDMOD pMod); 251 int kldrDyldModAttachThread(PKLDRDYLDMOD pMod); 252 int kldrDyldModDetachThread(PKLDRDYLDMOD pMod); 160 253 int kldrDyldModGetStackInfo(PKLDRDYLDMOD pMod, void *pvStack, size_t *pcbStack, size_t); 161 254 int kldrDyldModStartExe(PKLDRDYLDMOD pMod); … … 169 262 170 263 171 /** Pointer to the head module (the executable). */264 /** Pointer to the head module of the load list (the executable). */ 172 265 extern PKLDRDYLDMOD kLdrDyldModuleHead; 173 /** Pointer to the tail module . */266 /** Pointer to the tail module of the load list. */ 174 267 extern PKLDRDYLDMOD kLdrDyldModuleTail; 268 /** Pointer to the head module of the termination order list. */ 269 extern PKLDRDYLDMOD g_pkLdrDyldTermHead; 270 /** Pointer to the tail module of the termination order list. */ 271 extern PKLDRDYLDMOD g_pkLdrDyldTermTail; 272 /** Pointer to the head module of the bind order list. 273 * The modules in this list makes up the global namespace used when binding symbol unix fashion. */ 274 extern PKLDRDYLDMOD g_pkLdrDyldBindHead; 275 /** Pointer to the tail module of the bind order list. */ 276 extern PKLDRDYLDMOD g_pkLdrDyldBindTail; 277 278 /** The global error buffer. */ 279 extern char g_szkLdrDyldError[1024]; 280 175 281 /** The Library search path. */ 176 282 extern char kLdrDyldLibraryPath[4096]; 177 /** The global error buffer. */178 extern char g_szkLdrDyldError[1024];179 283 180 284
Note:
See TracChangeset
for help on using the changeset viewer.