Changeset 2854
- Timestamp:
- Nov 3, 2006, 4:39:12 AM (19 years ago)
- Location:
- trunk/kLdr
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kLdr/Makefile.kmk
r2846 r2854 100 100 kLdrRdrFile.c \ 101 101 kLdrMod.c \ 102 kLdrModLX.c 102 kLdrModLX.c \ 103 kLdrModPE.c 103 104 kLdr_SOURCES.os2 = \ 104 105 kLdr-os2.def \ -
trunk/kLdr/kLdr.h
r2851 r2854 341 341 /** Variable free to use for the kLdr user. */ 342 342 void *pvUser; 343 /** The segment name. */ 344 const char *pszName; 343 /** The segment name. (Might not be zero terminated!) */ 344 const char *pchName; 345 /** The length of the segment name. */ 346 uint32_t cchName; 345 347 /** The size of the segment. */ 346 348 KLDRSIZE cb; 347 /** The link time load address. */ 349 /** The required segment alignment. */ 350 KLDRADDR Alignment; 351 /** The link address. 352 * Set to NIL_KLDRADDR if the segment isn't supposed to be mapped. */ 348 353 KLDRADDR LinkAddress; 349 354 /** The address the segment was mapped at by kLdrModMap(). … … 569 574 * Not meant for calling directly thru! */ 570 575 PCKLDRMODOPS pOps; 576 /** Pointer to the read instance. (Can be NULL after kLdrModDone().)*/ 577 PKLDRRDR pRdr; 571 578 /** The module data. */ 572 579 void *pvData; … … 617 624 /** Weak symbol. */ 618 625 #define KLDRSYMKIND_WEAK 0x00000100 626 /** Forwarder symbol. */ 627 #define KLDRSYMKIND_FORWARDER 0x00000200 619 628 /** @} */ 620 629 … … 691 700 692 701 int kLdrModQuerySymbol(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, uint32_t uSymbol, 693 const char *pszSymbol, PKLDRADDR puValue, uint32_t *pfKind); 694 int kLdrModEnumSymbols(PKLDRMOD pMod, uint32_t fFlags, const void *pvBits, KLDRADDR BaseAddress, 695 PFNKLDRMODENUMSYMS pfnCallback, void *pvUser); 702 const char *pszSymbol, PFNKLDRMODGETIMPORT pfnGetForwarder, void *pvUser, 703 PKLDRADDR puValue, uint32_t *pfKind); 704 int kLdrModEnumSymbols(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, 705 uint32_t fFlags, PFNKLDRMODENUMSYMS pfnCallback, void *pvUser); 696 706 int kLdrModGetImport(PKLDRMOD pMod, void *pvBits, uint32_t iImport, const char *pszName, size_t cchName); 697 707 int32_t kLdrModNumberOfImports(PKLDRMOD pMod, void *pvBits); … … 761 771 /** @copydoc kLdrModQuerySymbol */ 762 772 int (* pfnQuerySymbol)(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, uint32_t uSymbol, 763 const char *pszSymbol, PKLDRADDR puValue, uint32_t *pfKind); 773 const char *pszSymbol, PFNKLDRMODGETIMPORT pfnGetForwarder, void *pvUser, 774 PKLDRADDR puValue, uint32_t *pfKind); 764 775 /** @copydoc kLdrModEnumSymbols */ 765 int (* pfnEnumSymbols)(PKLDRMOD pMod, uint32_t fFlags, const void *pvBits, KLDRADDR BaseAddress,776 int (* pfnEnumSymbols)(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, uint32_t fFlags, 766 777 PFNKLDRMODENUMSYMS pfnCallback, void *pvUser); 767 778 /** @copydoc kLdrModGetImport */ … … 1016 1027 /** Symbol not found. */ 1017 1028 #define KLDR_ERR_SYMBOL_NOT_FOUND (KLDR_ERR_BASE + 46) 1018 1029 /** A forward symbol was encountered but the caller didn't provide any means to resolve it. */ 1030 #define KLDR_ERR_FORWARDER_SYMBOL (KLDR_ERR_BASE + 47) 1019 1031 /** Encountered a bad fixup. */ 1020 1032 #define KLDR_ERR_BAD_FIXUP (KLDR_ERR_BASE + 48) 1021 1022 1033 /** A memory allocation failed. */ 1023 #define KLDR_ERR_NO_MEMORY (KLDR_ERR_BASE + 64) 1034 #define KLDR_ERR_NO_MEMORY (KLDR_ERR_BASE + 49) 1035 1036 1037 /** @name kLdrModPE status codes 1038 * @{ */ 1039 #define KLDR_ERR_BASE_PE (KLDR_ERR_BASE + 96) 1040 /** The machine isn't supported by the interpreter. */ 1041 #define KLDR_ERR_PE_UNSUPPORTED_MACHINE (KLDR_ERR_BASE_PE + 0) 1042 /** The file handler isn't valid. */ 1043 #define KLDR_ERR_PE_BAD_FILE_HEADER (KLDR_ERR_BASE_PE + 1) 1044 /** The the optional headers isn't valid. */ 1045 #define KLDR_ERR_PE_BAD_OPTIONAL_HEADER (KLDR_ERR_BASE_PE + 2) 1046 /** One of the section headers aren't valid. */ 1047 #define KLDR_ERR_PE_BAD_SECTION_HEADER (KLDR_ERR_BASE_PE + 3) 1048 /** Bad forwarder entry. */ 1049 #define KLDR_ERR_PE_BAD_FORWARDER (KLDR_ERR_BASE_PE + 4) 1050 /** Forwarder module not found in the import descriptor table. */ 1051 #define KLDR_ERR_PE_FORWARDER_IMPORT_NOT_FOUND (KLDR_ERR_BASE_PE + 5) 1052 /** @} */ 1053 1024 1054 1025 1055 /** @} */ -
trunk/kLdr/kLdrDyldMod.c
r2850 r2854 884 884 PKLDRADDR puValue, uint32_t *pfKind, void *pvUser) 885 885 { 886 static int s_cRecursiveCalls = 0; 887 PKLDRDYLDMOD pDyldMod = (PKLDRDYLDMOD)pvUser; 886 888 int rc; 887 PKLDRDYLDMOD pDyldMod = (PKLDRDYLDMOD)pvUser; 889 890 /* guard against too deep forwarder recursion. */ 891 if (s_cRecursiveCalls >= 5) 892 return KLDR_ERR_TOO_LONG_FORWARDER_CHAIN; 893 s_cRecursiveCalls++; 888 894 889 895 if (iImport != NIL_KLDRMOD_IMPORT) … … 901 907 902 908 rc = kLdrModQuerySymbol(pPrereqMod->pMod, NULL, KLDRMOD_BASEADDRESS_MAP, 903 uSymbol, pszSymbol, puValue, pfKind);909 uSymbol, pszSymbol, kldrDyldModFixupGetImportCallback, pPrereqMod, puValue, pfKind); 904 910 if (rc) 905 911 { … … 923 929 KLDRADDR uValue; 924 930 rc = kLdrModQuerySymbol(pBindMod->pMod, NULL, KLDRMOD_BASEADDRESS_MAP, 925 uSymbol, pszSymbol, &uValue, &fKind);931 uSymbol, pszSymbol, kldrDyldModFixupGetImportCallback, pPrereqMod, &uValue, &fKind); 926 932 if ( !rc 927 933 && ( !fFound … … 950 956 } 951 957 958 s_cRecursiveCalls--; 952 959 return rc; 953 960 } … … 1205 1212 1206 1213 rc = kLdrModQuerySymbol(pMod->pMod, NULL, KLDRMOD_BASEADDRESS_MAP, 1207 uSymbolOrdinal, pszSymbolName, &uValue, &fKind); 1214 uSymbolOrdinal, pszSymbolName, kldrDyldModFixupGetImportCallback, pPrereqMod, 1215 &uValue, &fKind); 1208 1216 if (!rc) 1209 1217 { -
trunk/kLdr/kLdrHlp.c
r2846 r2854 527 527 528 528 /** 529 * Get the pointer to the filename part of the name. 530 * 531 * @returns Pointer to where the filename starts within the string pointed to by pszFilename. 532 * @returns Pointer to the terminator char if no filename. 533 * @param pszFilename The filename to parse. 534 */ 535 char *kldrHlpGetFilename(const char *pszFilename) 536 { 537 const char *pszLast = NULL; 538 for (;;) 539 { 540 char ch = *pszFilename; 541 #if defined(__OS2__) || defined(__WIN__) 542 if (ch == '/' || ch == '\\' || ch == ':') 543 { 544 while ((ch = *++pszFilename) == '/' || ch == '\\' || ch == ':') 545 /* nothing */; 546 pszLast = pszFilename; 547 } 548 #else 549 if (ch == '/') 550 { 551 while ((ch = *++pszFilename) == '/') 552 /* betsuni */; 553 pszLast = pszFilename; 554 } 555 #endif 556 if (!ch) 557 return (char *)(pszLast ? pszLast : pszFilename); 558 pszFilename++; 559 } 560 } 561 562 563 /** 564 * Gets the filename suffix. 565 * 566 * @returns Pointer to where the suffix starts within the string pointed to by pszFilename. 567 * @returns Pointer to the terminator char if no suffix. 568 * @param pszFilename The filename to parse. 569 */ 570 char *kldrHlpGetSuff(const char *pszFilename) 571 { 572 const char *pszDot = NULL; 573 pszFilename = kldrHlpGetFilename(pszFilename); 574 for (;;) 575 { 576 char ch = *pszFilename; 577 if (ch == '.') 578 { 579 while ((ch = *++pszFilename) == '.') 580 /* nothing */; 581 if (ch) 582 pszDot = pszFilename - 1; 583 } 584 if (!ch) 585 return (char *)(pszDot ? pszDot : pszFilename); 586 pszFilename++; 587 } 588 } 589 590 591 /** 592 * Gets the filename extention. 593 * 594 * @returns Pointer to where the extension starts within the string pointed to by pszFilename. 595 * @returns Pointer to the terminator char if no extension. 596 * @param pszFilename The filename to parse. 597 */ 598 char *kldrHlpGetExt(const char *pszFilename) 599 { 600 char *psz = kldrHlpGetSuff(pszFilename); 601 return *psz ? psz + 1 : psz; 602 } 603 604 605 606 /** 529 607 * Terminate the process. 530 608 * … … 717 795 #endif 718 796 797 798 int kLdrHlpMemIComp(const void *pv1, const void *pv2, size_t cb) 799 { 800 const uint8_t *pb1 = (const uint8_t *)pv1; 801 const uint8_t *pb2 = (const uint8_t *)pv2; 802 while (cb) 803 { 804 if (*pb1 != *pb2) 805 { 806 const uint8_t u1 = *pb1 >= 'a' && *pb1 <= 'z' ? *pb1 - 'a' : *pb1; 807 const uint8_t u2 = *pb2 >= 'a' && *pb2 <= 'z' ? *pb2 - 'a' : *pb2; 808 if (u1 != u2) 809 return (int)*pb1 - (int)*pb2; 810 } 811 pb1++; 812 pb2++; 813 } 814 return 0; 815 } 816 817 818 int kLdrHlpStrIComp(const char *pv1, const char *pv2) 819 { 820 const uint8_t *pb1 = (const uint8_t *)pv1; 821 const uint8_t *pb2 = (const uint8_t *)pv2; 822 for (;;) 823 { 824 if (*pb1 != *pb2) 825 { 826 const uint8_t u1 = *pb1 >= 'a' && *pb1 <= 'z' ? *pb1 - 'a' : *pb1; 827 const uint8_t u2 = *pb2 >= 'a' && *pb2 <= 'z' ? *pb2 - 'a' : *pb2; 828 if (u1 != u2) 829 return (int)*pb1 - (int)*pb2; 830 } 831 if (!*pb1) 832 break; 833 pb1++; 834 pb2++; 835 } 836 return 0; 837 } 838 -
trunk/kLdr/kLdrHlp.h
r2851 r2854 74 74 /** strchr */ 75 75 # define kLdrHlpStrChr(a, b) __builtin_strchr(a, b) 76 /** strcmp */ 77 # define kLdrHlpStrComp(a, b) __builtin_strcmp(a, b) 76 78 /** strlen */ 77 79 # define kLdrHlpStrLen(a) __builtin_strlen(a) … … 89 91 # include <string.h> 90 92 # include <malloc.h> 91 # pragma intrinsic(memcmp, memcpy, memset, str len, __debugbreak)93 # pragma intrinsic(memcmp, memcpy, memset, strcmp, strlen, __debugbreak) 92 94 /** memchr */ 93 95 # define kLdrHlpMemChr_needed … … 98 100 /** memset */ 99 101 # define kLdrHlpMemSet(a,b,c) memset(a,b,c) 102 /** strcmp */ 103 # define kLdrHlpStrComp(a, b) strcmp(a, b) 100 104 /** strlen */ 101 105 # define kLdrHlpStrLen(a) strlen(a) … … 118 122 void *kLdrHlpMemChr(const void *pv, int ch, size_t cb); 119 123 #endif 124 int kLdrHlpMemIComp(const void *pv1, const void *pv2, size_t cb); 125 int kLdrHlpStrIComp(const char *pv1, const char *pv2); 126 120 127 121 128 #if (!defined(kLdrHlpMemChr) && !defined(kLdrHlpStrChr_needed))\ … … 148 155 int kldrHlpGetEnv(const char *pszVar, char *pszVal, size_t *pcchVal); 149 156 int kldrHlpGetEnvUZ(const char *pszVar, size_t *pcb); 157 char *kldrHlpGetFilename(const char *pszFilename); 158 char *kldrHlpGetExt(const char *pszFilename); 150 159 void kldrHlpExit(int rc); 151 160 void kldrHlpSleep(unsigned cMillies); -
trunk/kLdr/kLdrMod.c
r2851 r2854 2 2 /** @file 3 3 * 4 * kLdr - The Dynamic Loader, The module interpreter.4 * kLdr - The Module Interpreter. 5 5 * 6 6 * Copyright (c) 2006 knut st. osmundsen <bird-kbuild-src@anduin.net> … … 262 262 * @param uSymbol The symbol ordinal. (optional) 263 263 * @param pszSymbol The symbol name. (optional) 264 * @param pfnGetForwarder The callback to use when resolving a forwarder symbol. This is optional 265 * and if not specified KLDR_ERR_FORWARDER is returned instead. 266 * @param pvUser The user argument for the pfnGetForwarder callback. 264 267 * @param puValue Where to store the symbol value. (optional) 265 268 * @param pfKind Where to store the symbol kind. (optional) 266 269 */ 267 270 int kLdrModQuerySymbol(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, uint32_t uSymbol, 268 const char *pszSymbol, PKLDRADDR puValue, uint32_t *pfKind) 271 const char *pszSymbol, PFNKLDRMODGETIMPORT pfnGetForwarder, void *pvUser, 272 PKLDRADDR puValue, uint32_t *pfKind) 269 273 { 270 274 KLDRMOD_VALIDATE(pMod); … … 275 279 if (pfKind) 276 280 *pfKind = 0; 277 return pMod->pOps->pfn Destroy(pMod);281 return pMod->pOps->pfnQuerySymbol(pMod, pvBits, BaseAddress, uSymbol, pszSymbol, pfnGetForwarder, pvUser, puValue, pfKind); 278 282 } 279 283 … … 284 288 * @returns 0 on success and non-zero a status code on failure. 285 289 * @param pMod The module which symbols should be enumerated. 286 * @param fFlags The enumeration flags. A combination of the KLDRMOD_ENUM_SYMS_FLAGS_* \#defines.287 290 * @param pvBits Optional pointer to bits returned by kLdrModGetBits() currently located at BaseAddress. 288 291 * This can be used by some module interpreters to reduce memory consumption. … … 290 293 * There are two special values that could be can: 291 294 * KLDRMOD_BASEADDRESS_LINK and KLDRMOD_BASEADDRESS_MAP. 295 * @param fFlags The enumeration flags. A combination of the KLDRMOD_ENUM_SYMS_FLAGS_* \#defines. 292 296 * @param pfnCallback The enumeration callback function. 293 297 * @param pvUser The user argument to the callback function. 294 298 */ 295 int kLdrModEnumSymbols(PKLDRMOD pMod, uint32_t fFlags, const void *pvBits, KLDRADDR BaseAddress,299 int kLdrModEnumSymbols(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, uint32_t fFlags, 296 300 PFNKLDRMODENUMSYMS pfnCallback, void *pvUser) 297 301 { 298 302 KLDRMOD_VALIDATE(pMod); 299 303 KLDRHLP_VALIDATE_FLAGS(fFlags, KLDRMOD_ENUM_SYMS_FLAGS_ALL); 300 return pMod->pOps->pfnEnumSymbols(pMod, fFlags, pvBits, BaseAddress, pfnCallback, pvUser);304 return pMod->pOps->pfnEnumSymbols(pMod, pvBits, BaseAddress, fFlags, pfnCallback, pvUser); 301 305 } 302 306
Note:
See TracChangeset
for help on using the changeset viewer.