Changeset 16933 in vbox for trunk/src/VBox/Runtime/common
- Timestamp:
- Feb 18, 2009 11:42:57 PM (16 years ago)
- Location:
- trunk/src/VBox/Runtime/common/ldr
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/ldr/ldrELF.cpp
r8245 r16933 114 114 * @returns iprt status code. 115 115 * @param pReader The loader reader instance which will provide the raw image bits. 116 * @param fFlags Reserved, MBZ. 117 * @param enmArch Architecture specifier. 116 118 * @param phLdrMod Where to store the handle. 117 119 */ 118 int rtldrELFOpen(PRTLDRREADER pReader, PRTLDRMOD phLdrMod)120 int rtldrELFOpen(PRTLDRREADER pReader, uint32_t fFlags, RTLDRARCH enmArch, PRTLDRMOD phLdrMod) 119 121 { 120 122 const char *pszLogName = pReader->pfnLogName(pReader); NOREF(pszLogName); … … 145 147 } 146 148 if (e_ident[EI_CLASS] == ELFCLASS32) 147 rc = rtldrELF32Open(pReader, phLdrMod);149 rc = rtldrELF32Open(pReader, fFlags, enmArch, phLdrMod); 148 150 else 149 rc = rtldrELF64Open(pReader, phLdrMod);151 rc = rtldrELF64Open(pReader, fFlags, enmArch, phLdrMod); 150 152 return rc; 151 153 } -
trunk/src/VBox/Runtime/common/ldr/ldrELFRelocatable.cpp.h
r14049 r16933 721 721 * @param cbRawImage The size of the raw image. 722 722 */ 723 static int RTLDRELF_NAME(ValidateElfHeader)(const Elf_Ehdr *pEhdr, const char *pszLogName, uint64_t cbRawImage )723 static int RTLDRELF_NAME(ValidateElfHeader)(const Elf_Ehdr *pEhdr, const char *pszLogName, uint64_t cbRawImage, PRTLDRARCH penmArch) 724 724 { 725 725 Log3(("RTLdrELF: e_ident: %.*Rhxs\n" … … 806 806 case EM_386: 807 807 case EM_486: 808 *penmArch = RTLDRARCH_X86_32; 809 break; 808 810 #elif ELF_MODE == 64 809 811 case EM_X86_64: 812 *penmArch = RTLDRARCH_AMD64; 813 break; 810 814 #endif 811 break;812 815 default: 813 816 Log(("RTLdrELF: %s: machine type %u is not supported!\n", pEhdr->e_machine)); … … 986 989 * @returns iprt status code. 987 990 * @param pReader The loader reader instance which will provide the raw image bits. 991 * @param fFlags Reserved, MBZ. 992 * @param enmArch Architecture specifier. 988 993 * @param phLdrMod Where to store the handle. 989 994 */ 990 static int RTLDRELF_NAME(Open)(PRTLDRREADER pReader, PRTLDRMOD phLdrMod)995 static int RTLDRELF_NAME(Open)(PRTLDRREADER pReader, uint32_t fFlags, RTLDRARCH enmArch, PRTLDRMOD phLdrMod) 991 996 { 992 997 const char *pszLogName = pReader->pfnLogName(pReader); … … 1015 1020 1016 1021 /* 1017 * Read and validate the ELF header .1022 * Read and validate the ELF header and match up the CPU architecture. 1018 1023 */ 1019 1024 int rc = pReader->pfnRead(pReader, &pModElf->Ehdr, sizeof(pModElf->Ehdr), 0); 1020 1025 if (RT_SUCCESS(rc)) 1021 rc = RTLDRELF_NAME(ValidateElfHeader)(&pModElf->Ehdr, pszLogName, cbRawImage); 1026 { 1027 RTLDRARCH enmArchImage; 1028 rc = RTLDRELF_NAME(ValidateElfHeader)(&pModElf->Ehdr, pszLogName, cbRawImage, &enmArchImage); 1029 if (RT_SUCCESS(rc)) 1030 { 1031 if ( enmArch != RTLDRARCH_WHATEVER 1032 && enmArch != enmArchImage) 1033 rc = VERR_LDR_ARCH_MISMATCH; 1034 } 1035 } 1022 1036 if (RT_SUCCESS(rc)) 1023 1037 { -
trunk/src/VBox/Runtime/common/ldr/ldrEx.cpp
r13837 r16933 49 49 * @returns iprt status code. 50 50 * @param pReader The loader reader instance which will provide the raw image bits. 51 * @param fFlags Reserved, MBZ. 52 * @param enmArch Architecture specifier. 51 53 * @param phMod Where to store the handle. 52 54 */ 53 int rtldrOpenWithReader(PRTLDRREADER pReader, PRTLDRMOD phMod)55 int rtldrOpenWithReader(PRTLDRREADER pReader, uint32_t fFlags, RTLDRARCH enmArch, PRTLDRMOD phMod) 54 56 { 55 57 /* … … 105 107 if (uSign.u32 == IMAGE_NT_SIGNATURE) 106 108 #ifdef LDR_WITH_PE 107 rc = rtldrPEOpen(pReader, offHdr, phMod);109 rc = rtldrPEOpen(pReader, fFlags, enmArch, offHdr, phMod); 108 110 #else 109 111 rc = VERR_PE_EXE_NOT_SUPPORTED; … … 111 113 else if (uSign.u32 == IMAGE_ELF_SIGNATURE) 112 114 #if defined(LDR_WITH_ELF) 113 rc = rtldrELFOpen(pReader, phMod);115 rc = rtldrELFOpen(pReader, fFlags, enmArch, phMod); 114 116 #else 115 117 rc = VERR_ELF_EXE_NOT_SUPPORTED; … … 117 119 else if (uSign.au16[0] == IMAGE_LX_SIGNATURE) 118 120 #ifdef LDR_WITH_LX 119 rc = rtldrLXOpen(pReader, offHdr, phMod);121 rc = rtldrLXOpen(pReader, fFlags, enmArch, offHdr, phMod); 120 122 #else 121 123 rc = VERR_LX_EXE_NOT_SUPPORTED; … … 123 125 else if (uSign.au16[0] == IMAGE_LE_SIGNATURE) 124 126 #ifdef LDR_WITH_LE 125 rc = rtldrLEOpen(pReader, phMod);127 rc = rtldrLEOpen(pReader, fFlags, enmArch, phMod); 126 128 #else 127 129 rc = VERR_LE_EXE_NOT_SUPPORTED; … … 129 131 else if (uSign.au16[0] == IMAGE_NE_SIGNATURE) 130 132 #ifdef LDR_WITH_NE 131 rc = rtldrNEOpen(pReader, phMod);133 rc = rtldrNEOpen(pReader, fFlags, enmArch, phMod); 132 134 #else 133 135 rc = VERR_NE_EXE_NOT_SUPPORTED; … … 135 137 else if (uSign.au16[0] == IMAGE_DOS_SIGNATURE) 136 138 #ifdef LDR_WITH_MZ 137 rc = rtldrMZOpen(pReader, phMod);139 rc = rtldrMZOpen(pReader, fFlags, enmArch, phMod); 138 140 #else 139 141 rc = VERR_MZ_EXE_NOT_SUPPORTED; … … 143 145 0) 144 146 #ifdef LDR_WITH_AOUT 145 rc = rtldrAOUTOpen(pReader, phMod);147 rc = rtldrAOUTOpen(pReader, fFlags, enmArch, phMod); 146 148 #else 147 149 rc = VERR_AOUT_EXE_NOT_SUPPORTED; … … 158 160 /* Try kLdr if it's a format we don't recognize. */ 159 161 if (rc <= VERR_INVALID_EXE_SIGNATURE && rc > VERR_BAD_EXE_FORMAT) 160 rc = rtldrkLdrOpen(pReader, phMod);162 rc = rtldrkLdrOpen(pReader, fFlags, enmArch, phMod); 161 163 #endif 162 164 -
trunk/src/VBox/Runtime/common/ldr/ldrFile.cpp
r8245 r16933 241 241 242 242 /** 243 * Open a binary image file .243 * Open a binary image file, extended version. 244 244 * 245 245 * @returns iprt status code. 246 246 * @param pszFilename Image filename. 247 * @param phLdrMod Where to store the handle to the loaded module. 248 */ 249 RTDECL(int) RTLdrOpen(const char *pszFilename, PRTLDRMOD phLdrMod) 250 { 251 LogFlow(("RTLdrOpen: pszFilename=%p:{%s} phLdrMod=%p\n", 252 pszFilename, pszFilename, phLdrMod)); 247 * @param fFlags Reserved, MBZ. 248 * @param enmArch CPU architecture specifier for the image to be loaded. 249 * @param phLdrMod Where to store the handle to the loader module. 250 */ 251 RTDECL(int) RTLdrOpen(const char *pszFilename, uint32_t fFlags, RTLDRARCH enmArch, PRTLDRMOD phLdrMod) 252 { 253 LogFlow(("RTLdrOpen: pszFilename=%p:{%s} fFlags=%#x enmArch=%d phLdrMod=%p\n", 254 pszFilename, pszFilename, fFlags, enmArch, phLdrMod)); 255 AssertMsgReturn(!fFlags, ("%#x\n", fFlags), VERR_INVALID_PARAMETER); 256 AssertMsgReturn(enmArch > RTLDRARCH_INVALID && enmArch < RTLDRARCH_END, ("%d\n", enmArch), VERR_INVALID_PARAMETER); 257 258 /* 259 * Resolve RTLDRARCH_HOST. 260 */ 261 if (enmArch == RTLDRARCH_HOST) 262 #if defined(RT_ARCH_AMD64) 263 enmArch = RTLDRARCH_AMD64; 264 #elif defined(RT_ARCH_X86) 265 enmArch = RTLDRARCH_X86_32; 266 #else 267 enmArch = RTLDRARCH_WHATEVER; 268 #endif 253 269 254 270 /* … … 259 275 if (RT_SUCCESS(rc)) 260 276 { 261 rc = rtldrOpenWithReader(pReader, phLdrMod);277 rc = rtldrOpenWithReader(pReader, fFlags, enmArch, phLdrMod); 262 278 if (RT_SUCCESS(rc)) 263 279 { … … 277 293 * 278 294 * @returns iprt status code. 279 * @param pszFilename Image filename. 280 * @param phLdrMod Where to store the handle to the loaded module. 295 * @param pszFilename Image filename. 296 * @param fFlags Reserved, MBZ. 297 * @param enmArch CPU architecture specifier for the image to be loaded. 298 * @param phLdrMod Where to store the handle to the loaded module. 281 299 * @remark Primarily for testing the loader. 282 300 */ 283 RTDECL(int) RTLdrOpenkLdr(const char *pszFilename, PRTLDRMOD phLdrMod)301 RTDECL(int) RTLdrOpenkLdr(const char *pszFilename, uint32_t fFlags, RTLDRARCH enmArch, PRTLDRMOD phLdrMod) 284 302 { 285 303 #ifdef LDR_WITH_KLDR 286 LogFlow(("RTLdrOpenkLdr: pszFilename=%p:{%s} phLdrMod=%p\n", 287 pszFilename, pszFilename, phLdrMod)); 304 LogFlow(("RTLdrOpenkLdr: pszFilename=%p:{%s} fFlags=%#x enmArch=%d phLdrMod=%p\n", 305 pszFilename, pszFilename, fFlags, enmArch, phLdrMod)); 306 307 /* 308 * Resolve RTLDRARCH_HOST. 309 */ 310 if (enmArch == RTLDRARCH_HOST) 311 # if defined(RT_ARCH_AMD64) 312 enmArch = RTLDRARCH_AMD64; 313 # elif defined(RT_ARCH_X86) 314 enmArch = RTLDRARCH_X86_32; 315 # else 316 enmArch = RTLDRARCH_WHATEVER; 317 # endif 288 318 289 319 /* … … 294 324 if (RT_SUCCESS(rc)) 295 325 { 296 rc = rtldrkLdrOpen(pReader, phLdrMod);326 rc = rtldrkLdrOpen(pReader, fFlags, enmArch, phLdrMod); 297 327 if (RT_SUCCESS(rc)) 298 328 { … … 307 337 308 338 #else 309 return RTLdrOpen(pszFilename, phLdrMod);339 return RTLdrOpen(pszFilename, fFlags, enmArch, phLdrMod); 310 340 #endif 311 341 } -
trunk/src/VBox/Runtime/common/ldr/ldrPE.cpp
r13837 r16933 944 944 * @param pFileHdr Pointer to the file header that needs validating. 945 945 * @param pszLogName The log name to prefix the errors with. 946 */ 947 int rtldrPEValidateFileHeader(PIMAGE_FILE_HEADER pFileHdr, const char *pszLogName) 946 * @param penmArch Where to store the CPU architecture. 947 */ 948 int rtldrPEValidateFileHeader(PIMAGE_FILE_HEADER pFileHdr, const char *pszLogName, PRTLDRARCH penmArch) 948 949 { 949 950 size_t cbOptionalHeader; … … 952 953 case IMAGE_FILE_MACHINE_I386: 953 954 cbOptionalHeader = sizeof(IMAGE_OPTIONAL_HEADER32); 955 *penmArch = RTLDRARCH_X86_32; 954 956 break; 955 957 case IMAGE_FILE_MACHINE_AMD64: 956 958 cbOptionalHeader = sizeof(IMAGE_OPTIONAL_HEADER64); 959 *penmArch = RTLDRARCH_AMD64; 957 960 break; 958 961 … … 960 963 Log(("rtldrPEOpen: %s: Unsupported Machine=%#x\n", 961 964 pszLogName, pFileHdr->Machine)); 965 *penmArch = RTLDRARCH_INVALID; 962 966 return VERR_BAD_EXE_FORMAT; 963 967 } … … 1417 1421 * @returns iprt status code. 1418 1422 * @param pReader The loader reader instance which will provide the raw image bits. 1423 * @param fFlags Reserved, MBZ. 1424 * @param enmArch Architecture specifier. 1419 1425 * @param offNtHdrs The offset of the NT headers (where you find "PE\0\0"). 1420 1426 * @param phLdrMod Where to store the handle. 1421 1427 */ 1422 int rtldrPEOpen(PRTLDRREADER pReader, RTFOFF offNtHdrs, PRTLDRMOD phLdrMod)1428 int rtldrPEOpen(PRTLDRREADER pReader, uint32_t fFlags, RTLDRARCH enmArch, RTFOFF offNtHdrs, PRTLDRMOD phLdrMod) 1423 1429 { 1424 1430 /* … … 1429 1435 if (RT_FAILURE(rc)) 1430 1436 return rc; 1437 RTLDRARCH enmArchImage; 1431 1438 const char *pszLogName = pReader->pfnLogName(pReader); 1432 rc = rtldrPEValidateFileHeader(&FileHdr, pszLogName );1439 rc = rtldrPEValidateFileHeader(&FileHdr, pszLogName, &enmArchImage); 1433 1440 if (RT_FAILURE(rc)) 1434 1441 return rc; 1442 1443 /* 1444 * Match the CPU architecture. 1445 */ 1446 if ( enmArch != RTLDRARCH_WHATEVER 1447 && enmArch != enmArchImage) 1448 return VERR_LDR_ARCH_MISMATCH; 1435 1449 1436 1450 /* -
trunk/src/VBox/Runtime/common/ldr/ldrkStuff.cpp
r16439 r16933 636 636 * @returns iprt status code. 637 637 * @param pReader The loader reader instance which will provide the raw image bits. 638 * @param fFlags Reserved, MBZ. 639 * @param enmArch CPU architecture specifier for the image to be loaded. 638 640 * @param phLdrMod Where to store the handle. 639 641 */ 640 int rtldrkLdrOpen(PRTLDRREADER pReader, PRTLDRMOD phLdrMod) 641 { 642 int rtldrkLdrOpen(PRTLDRREADER pReader, uint32_t fFlags, RTLDRARCH enmArch, PRTLDRMOD phLdrMod) 643 { 644 /* Convert enmArch to k-speak. */ 645 KCPUARCH enmCpuArch; 646 switch (enmArch) 647 { 648 case RTLDRARCH_WHATEVER: 649 enmCpuArch = KCPUARCH_UNKNOWN; 650 break; 651 case RTLDRARCH_X86_32: 652 enmCpuArch = KCPUARCH_X86_32; 653 break; 654 case RTLDRARCH_AMD64: 655 enmCpuArch = KCPUARCH_AMD64; 656 break; 657 default: 658 return VERR_INVALID_PARAMETER; 659 } 660 642 661 /* Create a rtkldrRdr instance. */ 643 662 PRTKLDRRDR pRdr = (PRTKLDRRDR)RTMemAllocZ(sizeof(*pRdr));
Note:
See TracChangeset
for help on using the changeset viewer.