- Timestamp:
- May 14, 2013 11:39:28 PM (12 years ago)
- svn:sync-xref-src-repo-rev:
- 85759
- Location:
- trunk
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/dbg.h
r46074 r46083 927 927 RTDECL(int) RTDbgModCreateFromMap(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName, RTUINTPTR uSubtrahend, 928 928 RTDBGCFG hDbgCfg); 929 RTDECL(int) RTDbgModCreateFromPeImage(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName, uint32_t cbImage,930 uint32_t uTimeDateStamp, RTDBGCFG hDbgCfg);929 RTDECL(int) RTDbgModCreateFromPeImage(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName, RTLDRMOD hLdrMod, 930 uint32_t cbImage, uint32_t uTimeDateStamp, RTDBGCFG hDbgCfg); 931 931 RTDECL(int) RTDbgModCreateFromDbg(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName, uint32_t cbImage, 932 932 uint32_t uTimeDateStamp, RTDBGCFG hDbgCfg); -
trunk/include/iprt/ldr.h
r46080 r46083 227 227 * a pointer to a memory block. 228 228 * @param phLdrMod Where to return the module handle. 229 * 230 * @remarks With the exception of invalid @a pfnDtor and/or @a pvUser 231 * parameters, the pfnDtor methods (or the default one if NULL) will 232 * always be invoked. The destruction of pvUser is entirely in the 233 * hands of this method once it's called. 229 234 */ 230 235 RTDECL(int) RTLdrOpenInMemory(const char *pszName, uint32_t fFlags, RTLDRARCH enmArch, size_t cbImage, 231 236 PFNRTLDRRDRMEMREAD pfnRead, PFNRTLDRRDRMEMDTOR pfnDtor, void *pvUser, 232 237 PRTLDRMOD phLdrMod); 233 234 238 235 239 /** -
trunk/src/VBox/Debugger/DBGPlugInWinNt.cpp
r45994 r46083 25 25 #include <VBox/err.h> 26 26 #include <VBox/param.h> 27 #include <iprt/ string.h>27 #include <iprt/ldr.h> 28 28 #include <iprt/mem.h> 29 29 #include <iprt/stream.h> 30 #include <iprt/string.h> 30 31 31 32 #include "../Runtime/include/internal/ldrMZ.h" /* ugly */ … … 239 240 240 241 242 /** 243 * The WinNT digger's loader reader instance data. 244 */ 245 typedef struct DBGDIGGERWINNTRDR 246 { 247 /** The VM handle (referenced). */ 248 PUVM pUVM; 249 /** The image base. */ 250 DBGFADDRESS ImageAddr; 251 /** The image size. */ 252 uint32_t cbImage; 253 /** Number of entries in the aMappings table. */ 254 uint32_t cMappings; 255 /** Mapping hint. */ 256 uint32_t iHint; 257 /** Mapping file offset to memory offsets, ordered by file offset. */ 258 struct 259 { 260 /** The file offset. */ 261 uint32_t offFile; 262 /** The size of this mapping. */ 263 uint32_t cbMem; 264 /** The offset to the memory from the start of the image. */ 265 uint32_t offMem; 266 } aMappings[1]; 267 } DBGDIGGERWINNTRDR; 268 /** Pointer a WinNT loader reader instance data. */ 269 typedef DBGDIGGERWINNTRDR *PDBGDIGGERWINNTRDR; 270 271 241 272 /******************************************************************************* 242 273 * Defined Constants And Macros * … … 274 305 275 306 307 308 /** @callback_method_impl{PFNRTLDRRDRMEMREAD} */ 309 static DECLCALLBACK(int) dbgDiggerWinNtRdr_Read(void *pvBuf, size_t cb, size_t off, void *pvUser) 310 { 311 PDBGDIGGERWINNTRDR pThis = (PDBGDIGGERWINNTRDR)pvUser; 312 313 uint32_t i = pThis->iHint; 314 if (pThis->aMappings[i].offFile > off) 315 { 316 i = pThis->cMappings; 317 while (i-- > 0) 318 if (off >= pThis->aMappings[i].offFile) 319 break; 320 pThis->iHint = i; 321 } 322 323 while (cb > 0) 324 { 325 uint32_t offNextMap = i + 1 < pThis->cMappings ? pThis->aMappings[i + 1].offFile : pThis->cbImage; 326 uint32_t offMap = (uint32_t)off - pThis->aMappings[i].offFile; 327 328 /* Read file bits backed by memory. */ 329 if (off < pThis->aMappings[i].cbMem) 330 { 331 uint32_t cbToRead = pThis->aMappings[i].cbMem - offMap; 332 if (cbToRead > cb) 333 cbToRead = (uint32_t)cb; 334 335 DBGFADDRESS Addr = pThis->ImageAddr; 336 DBGFR3AddrAdd(&Addr, pThis->aMappings[i].offMem + offMap); 337 338 int rc = DBGFR3MemRead(pThis->pUVM, 0 /*idCpu*/, &Addr, pvBuf, cbToRead); 339 if (RT_FAILURE(rc)) 340 return rc; 341 if (cbToRead == cb) 342 break; 343 344 off += cbToRead; 345 cb -= cbToRead; 346 pvBuf = (char *)pvBuf + cbToRead; 347 } 348 349 /* Mind the gap. */ 350 if (offNextMap > off) 351 { 352 uint32_t cbZero = offNextMap - (uint32_t)off; 353 if (cbZero > cb) 354 { 355 RT_BZERO(pvBuf, cb); 356 break; 357 } 358 359 RT_BZERO(pvBuf, cbZero); 360 off += cbZero; 361 cb -= cbZero; 362 pvBuf = (char *)pvBuf + cbZero; 363 } 364 365 pThis->iHint = ++i; 366 } 367 368 return VINF_SUCCESS; 369 } 370 371 372 /** @callback_method_impl{PFNRTLDRRDRMEMDTOR} */ 373 static DECLCALLBACK(void) dbgDiggerWinNtRdr_Dtor(void *pvUser) 374 { 375 PDBGDIGGERWINNTRDR pThis = (PDBGDIGGERWINNTRDR)pvUser; 376 377 VMR3ReleaseUVM(pThis->pUVM); 378 pThis->pUVM = NULL; 379 RTMemFree(pvUser); 380 } 381 382 276 383 /** 277 384 * Process a PE image found in guest memory. … … 390 497 * Create the module. 391 498 */ 392 bool fPeImageMod = true;393 499 RTDBGMOD hMod; 394 int rc = RTDbgModCreateFromPeImage(&hMod, pszName, NULL, cbImageFromHdr, TimeDateStamp, DBGFR3AsGetConfig(pUVM)); 500 int rc = RTDbgModCreateFromPeImage(&hMod, pszName, NULL, NIL_RTLDRMOD, 501 cbImageFromHdr, TimeDateStamp, DBGFR3AsGetConfig(pUVM)); 395 502 if (RT_FAILURE(rc)) 396 503 { 397 rc = RTDbgModCreate(&hMod, pszName, cbImage, 0); 504 /* 505 * Probably didn't find the image any where, try fake an image 506 * from guest memory. 507 */ 508 uint32_t cMappings = WINNT_UNION(pThis, pHdrs, FileHeader.NumberOfSections) + 3; 509 PDBGDIGGERWINNTRDR pRdr = (PDBGDIGGERWINNTRDR)RTMemAlloc(RT_OFFSETOF(DBGDIGGERWINNTRDR, aMappings[cMappings])); 510 if (!pRdr) 511 return; 512 513 VMR3RetainUVM(pUVM); 514 pRdr->pUVM = pUVM; 515 pRdr->ImageAddr = *pImageAddr; 516 pRdr->cbImage = cbImageFromHdr; 517 pRdr->cMappings = 1; 518 pRdr->iHint = 0; 519 pRdr->aMappings[0].offFile = 0; 520 pRdr->aMappings[0].offMem = 0; 521 pRdr->aMappings[0].cbMem = cbImageFromHdr; 522 523 RTLDRMOD hLdrMod; 524 rc = RTLdrOpenInMemory(pszName, RTLDR_O_FOR_DEBUG, RTLDRARCH_WHATEVER, pRdr->cbImage, 525 dbgDiggerWinNtRdr_Read, dbgDiggerWinNtRdr_Dtor, pRdr, 526 &hLdrMod); 527 if (RT_SUCCESS(rc)) 528 { 529 rc = RTDbgModCreateFromPeImage(&hMod, pszName, NULL, hLdrMod, 530 cbImageFromHdr, TimeDateStamp, DBGFR3AsGetConfig(pUVM)); 531 if (RT_FAILURE(rc)) 532 RTLdrClose(hLdrMod); 533 } 398 534 if (RT_FAILURE(rc)) 399 return; 400 fPeImageMod = false; 535 { 536 /* 537 * Final fallback is a container module. 538 */ 539 rc = RTDbgModCreate(&hMod, pszName, cbImage, 0); 540 if (RT_FAILURE(rc)) 541 return; 542 543 rc = RTDbgModSymbolAdd(hMod, "Headers", 0 /*iSeg*/, 0, cbImage, 0 /*fFlags*/, NULL); AssertRC(rc); 544 } 401 545 } 402 546 rc = RTDbgModSetTag(hMod, DIG_WINNT_MOD_TAG); AssertRC(rc); 403 547 404 if (fPeImageMod) 405 { 406 rc = RTDbgModSymbolAdd(hMod, "Headers", 0 /*iSeg*/, 0, cbImage, 0 /*fFlags*/, NULL); 407 AssertRC(rc); 408 /** @todo add sections? */ 409 } 410 548 #if 0 411 549 /* 412 550 * Dig out debug info if possible. What we're after is the CODEVIEW part. … … 434 572 } 435 573 } 574 #endif 436 575 437 576 /* -
trunk/src/VBox/Runtime/common/dbg/dbgmod.cpp
r46070 r46083 885 885 886 886 Assert(pDbgMod->pszImgFile); 887 if ( pDeferred->hDbgCfg != NIL_RTDBGCFG)887 if (!pDbgMod->pImgVt) 888 888 rc = RTDbgCfgOpenPeImage(pDeferred->hDbgCfg, pDbgMod->pszImgFile, 889 889 pDeferred->cbImage, pDeferred->u.PeImage.uTimestamp, 890 890 rtDbgModFromPeImageOpenCallback, pDbgMod, pDeferred); 891 891 else 892 rc = rtDbgModFromPeImageOpenCallback(NIL_RTDBGCFG, pDbgMod->pszImgFile, pDbgMod, pDeferred); 893 894 return rc; 895 } 896 897 898 RTDECL(int) RTDbgModCreateFromPeImage(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName, uint32_t cbImage, 899 uint32_t uTimestamp, RTDBGCFG hDbgCfg) 892 { 893 rc = rtDbgModOpenDebugInfoExternalToImage(pDbgMod, pDeferred->hDbgCfg); 894 if (RT_FAILURE(rc)) 895 rc = rtDbgModOpenDebugInfoInsideImage(pDbgMod); 896 if (RT_FAILURE(rc)) 897 rc = rtDbgModCreateForExports(pDbgMod); 898 } 899 return rc; 900 } 901 902 903 RTDECL(int) RTDbgModCreateFromPeImage(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName, RTLDRMOD hLdrMod, 904 uint32_t cbImage, uint32_t uTimestamp, RTDBGCFG hDbgCfg) 900 905 { 901 906 /* … … 909 914 pszName = RTPathFilename(pszFilename); 910 915 AssertPtrReturn(pszName, VERR_INVALID_POINTER); 916 AssertReturn(hLdrMod == NIL_RTLDRMOD || RTLdrSize(hLdrMod) != ~(size_t)0, VERR_INVALID_HANDLE); 911 917 912 918 int rc = rtDbgModLazyInit(); … … 939 945 { 940 946 /* 941 * Do it now or procrastinate? 947 * If we have a loader module, we must instantiate the loader 948 * side of things regardless of the deferred setting. 942 949 */ 943 if ( !(fDbgCfg & RTDBGCFG_FLAGS_DEFERRED) || !cbImage)950 if (hLdrMod != NIL_RTLDRMOD) 944 951 { 945 RTDBGMODDEFERRED Deferred; 946 Deferred.cbImage = cbImage; 947 Deferred.hDbgCfg = hDbgCfg; 948 Deferred.u.PeImage.uTimestamp = uTimestamp; 949 rc = rtDbgModFromPeImageDeferredCallback(pDbgMod, &Deferred); 950 } 951 else 952 { 953 PRTDBGMODDEFERRED pDeferred; 954 rc = rtDbgModDeferredCreate(pDbgMod, rtDbgModFromPeImageDeferredCallback, cbImage, hDbgCfg, &pDeferred); 955 if (RT_SUCCESS(rc)) 956 pDeferred->u.PeImage.uTimestamp = uTimestamp; 952 if (!cbImage) 953 cbImage = (uint32_t)RTLdrSize(hLdrMod); 954 pDbgMod->pImgVt = &g_rtDbgModVtImgLdr; 955 956 rc = rtDbgModLdrOpenFromHandle(pDbgMod, hLdrMod); 957 957 } 958 958 if (RT_SUCCESS(rc)) 959 959 { 960 *phDbgMod = pDbgMod; 961 return VINF_SUCCESS; 960 /* 961 * Do it now or procrastinate? 962 */ 963 if (!(fDbgCfg & RTDBGCFG_FLAGS_DEFERRED) || !cbImage) 964 { 965 RTDBGMODDEFERRED Deferred; 966 Deferred.cbImage = cbImage; 967 Deferred.hDbgCfg = hDbgCfg; 968 Deferred.u.PeImage.uTimestamp = uTimestamp; 969 rc = rtDbgModFromPeImageDeferredCallback(pDbgMod, &Deferred); 970 } 971 else 972 { 973 PRTDBGMODDEFERRED pDeferred; 974 rc = rtDbgModDeferredCreate(pDbgMod, rtDbgModFromPeImageDeferredCallback, cbImage, hDbgCfg, &pDeferred); 975 if (RT_SUCCESS(rc)) 976 pDeferred->u.PeImage.uTimestamp = uTimestamp; 977 } 978 if (RT_SUCCESS(rc)) 979 { 980 *phDbgMod = pDbgMod; 981 return VINF_SUCCESS; 982 } 983 984 /* Failed, bail out. */ 985 if (hLdrMod != NIL_RTLDRMOD) 986 { 987 Assert(pDbgMod->pImgVt); 988 pDbgMod->pImgVt->pfnClose(pDbgMod); 989 } 962 990 } 963 964 /* bail out */965 991 RTStrCacheRelease(g_hDbgModStrCache, pDbgMod->pszName); 966 992 } -
trunk/src/VBox/Runtime/common/dbg/dbgmodldr.cpp
r46025 r46083 41 41 #include <iprt/string.h> 42 42 #include "internal/dbgmod.h" 43 #include "internal/ldr.h" 43 44 #include "internal/magics.h" 44 45 … … 54 55 /** The loader handle. */ 55 56 RTLDRMOD hLdrMod; 56 /** File handle for the image. */57 RTFILE hFile;58 57 } RTDBGMODLDR; 59 58 /** Pointer to instance data NM map reader. */ … … 80 79 return VERR_NO_MEMORY; 81 80 82 int rc = RTFileReadAt(pThis->hFile, off, pvMap, cb, NULL);81 int rc = rtLdrReadAt(pThis->hLdrMod, pvMap, off, cb); 83 82 if (RT_SUCCESS(rc)) 84 83 *ppvMap = pvMap; … … 134 133 pThis->hLdrMod = NIL_RTLDRMOD; 135 134 136 rc = RTFileClose(pThis->hFile); AssertRC(rc);137 pThis->hFile = NIL_RTFILE;138 139 135 RTMemFree(pThis); 140 136 … … 146 142 static DECLCALLBACK(int) rtDbgModLdr_TryOpen(PRTDBGMODINT pMod) 147 143 { 148 RT FILE hFile;149 int rc = RT FileOpen(&hFile, pMod->pszImgFile, RTFILE_O_READ | RTFILE_O_DENY_WRITE | RTFILE_O_OPEN);144 RTLDRMOD hLdrMod; 145 int rc = RTLdrOpen(pMod->pszImgFile, RTLDR_O_FOR_DEBUG, RTLDRARCH_WHATEVER, &hLdrMod); 150 146 if (RT_SUCCESS(rc)) 151 147 { 152 RTLDRMOD hLdrMod; 153 rc = RTLdrOpen(pMod->pszImgFile, RTLDR_O_FOR_DEBUG, RTLDRARCH_WHATEVER, &hLdrMod); 154 if (RT_SUCCESS(rc)) 155 { 156 PRTDBGMODLDR pThis = (PRTDBGMODLDR)RTMemAllocZ(sizeof(RTDBGMODLDR)); 157 if (pThis) 158 { 159 pThis->hLdrMod = hLdrMod; 160 pThis->hFile = hFile; 161 pMod->pvImgPriv = pThis; 162 return VINF_SUCCESS; 163 } 164 165 rc = VERR_NO_MEMORY; 148 rc = rtDbgModLdrOpenFromHandle(pMod, hLdrMod); 149 if (RT_FAILURE(rc)) 166 150 RTLdrClose(hLdrMod); 167 }168 169 RTFileClose(hFile);170 151 } 171 152 return rc; … … 191 172 }; 192 173 174 175 /** 176 * Open PE-image trick. 177 * 178 * @returns IPRT status code 179 * @param pDbgMod The debug module instance. 180 * @param hLdrMod The module to open a image debug backend for. 181 */ 182 DECLHIDDEN(int) rtDbgModLdrOpenFromHandle(PRTDBGMODINT pDbgMod, RTLDRMOD hLdrMod) 183 { 184 PRTDBGMODLDR pThis = (PRTDBGMODLDR)RTMemAllocZ(sizeof(RTDBGMODLDR)); 185 if (!pThis) 186 return VERR_NO_MEMORY; 187 188 pThis->hLdrMod = hLdrMod; 189 pDbgMod->pvImgPriv = pThis; 190 return VINF_SUCCESS; 191 } 192 -
trunk/src/VBox/Runtime/common/ldr/ldrELFRelocatable.cpp.h
r45994 r46083 93 93 /** Core module structure. */ 94 94 RTLDRMODINTERNAL Core; 95 /** Pointer to the reader instance. */96 PRTLDRREADER pReader;97 95 /** Pointer to readonly mapping of the image bits. 98 96 * This mapping is provided by the pReader. */ … … 145 143 if (pModElf->pvBits) 146 144 return VINF_SUCCESS; 147 int rc = pModElf-> pReader->pfnMap(pModElf->pReader, &pModElf->pvBits);145 int rc = pModElf->Core.pReader->pfnMap(pModElf->Core.pReader, &pModElf->pvBits); 148 146 if (RT_SUCCESS(rc)) 149 147 { … … 423 421 } 424 422 425 if (pModElf->pReader)426 {427 pModElf->pReader->pfnDestroy(pModElf->pReader);428 pModElf->pReader = NULL;429 }430 431 423 pModElf->pvBits = NULL; 432 424 … … 534 526 break; 535 527 case ET_EXEC: 536 Log(("RTLdrELF: %s: Executable images are not supported yet!\n", pModElf-> pReader->pfnLogName(pModElf->pReader)));528 Log(("RTLdrELF: %s: Executable images are not supported yet!\n", pModElf->Core.pReader->pfnLogName(pModElf->Core.pReader))); 537 529 return VERR_LDRELF_EXEC; 538 530 case ET_DYN: 539 Log(("RTLdrELF: %s: Dynamic images are not supported yet!\n", pModElf-> pReader->pfnLogName(pModElf->pReader)));531 Log(("RTLdrELF: %s: Dynamic images are not supported yet!\n", pModElf->Core.pReader->pfnLogName(pModElf->Core.pReader))); 540 532 return VERR_LDRELF_DYN; 541 533 default: AssertFailedReturn(VERR_BAD_EXE_FORMAT); … … 560 552 default: 561 553 { 562 int rc = pModElf-> pReader->pfnRead(pModElf->pReader, (uint8_t *)pvBits + paShdrs[iShdr].sh_addr,563 (size_t)paShdrs[iShdr].sh_size, paShdrs[iShdr].sh_offset);554 int rc = pModElf->Core.pReader->pfnRead(pModElf->Core.pReader, (uint8_t *)pvBits + paShdrs[iShdr].sh_addr, 555 (size_t)paShdrs[iShdr].sh_size, paShdrs[iShdr].sh_offset); 564 556 if (RT_FAILURE(rc)) 565 557 { 566 558 Log(("RTLdrELF: %s: Read error when reading " FMT_ELF_SIZE " bytes at " FMT_ELF_OFF ", iShdr=%d\n", 567 pModElf-> pReader->pfnLogName(pModElf->pReader),559 pModElf->Core.pReader->pfnLogName(pModElf->Core.pReader), 568 560 paShdrs[iShdr].sh_size, paShdrs[iShdr].sh_offset, iShdr)); 569 561 return rc; … … 587 579 PRTLDRMODELF pModElf = (PRTLDRMODELF)pMod; 588 580 #ifdef LOG_ENABLED 589 const char *pszLogName = pModElf-> pReader->pfnLogName(pModElf->pReader);581 const char *pszLogName = pModElf->Core.pReader->pfnLogName(pModElf->Core.pReader); 590 582 #endif 591 583 NOREF(OldBaseAddress); … … 1170 1162 * 1171 1163 * @returns pszName. 1172 * @param pReader The loader reader instance.1173 1164 * @param pEhdr The elf header. 1174 1165 * @param offName The offset of the section header name. … … 1179 1170 { 1180 1171 RTFOFF off = pModElf->paShdrs[pModElf->Ehdr.e_shstrndx].sh_offset + offName; 1181 int rc = pModElf-> pReader->pfnRead(pModElf->pReader, pszName, cbName - 1, off);1172 int rc = pModElf->Core.pReader->pfnRead(pModElf->Core.pReader, pszName, cbName - 1, off); 1182 1173 if (RT_FAILURE(rc)) 1183 1174 { … … 1185 1176 for (unsigned i = 0; i < cbName; i++, off++) 1186 1177 { 1187 rc = pModElf-> pReader->pfnRead(pModElf->pReader, pszName + i, 1, off);1178 rc = pModElf->Core.pReader->pfnRead(pModElf->Core.pReader, pszName + i, 1, off); 1188 1179 if (RT_FAILURE(rc)) 1189 1180 { … … 1347 1338 pModElf->Core.u32Magic = RTLDRMOD_MAGIC; 1348 1339 pModElf->Core.eState = LDR_STATE_INVALID; 1349 pModElf-> pReader= pReader;1340 pModElf->Core.pReader = pReader; 1350 1341 //pModElf->pvBits = NULL; 1351 1342 //pModElf->Ehdr = {0}; -
trunk/src/VBox/Runtime/common/ldr/ldrEx.cpp
r46080 r46083 539 539 RT_EXPORT_SYMBOL(RTLdrRvaToSegOffset); 540 540 541 542 /** 543 * Internal method used by the IPRT debug bits. 544 * 545 * @returns IPRT status code. 546 * @param hLdrMod The loader handle which executable we wish to 547 * read from. 548 * @param pvBuf The output buffer. 549 * @param off Where in the executable file to start reading. 550 * @param cb The number of bytes to read. 551 */ 552 DECLHIDDEN(int) rtLdrReadAt(RTLDRMOD hLdrMod, void *pvBuf, RTFOFF off, size_t cb) 553 { 554 AssertMsgReturn(rtldrIsValid(hLdrMod), ("hLdrMod=%p\n", hLdrMod), VERR_INVALID_HANDLE); 555 PRTLDRMODINTERNAL pMod = (PRTLDRMODINTERNAL)hLdrMod; 556 AssertReturn(pMod->pReader, VERR_INVALID_HANDLE); 557 558 return pMod->pReader->pfnRead(pMod->pReader, pvBuf, cb, off); 559 } 560 -
trunk/src/VBox/Runtime/common/ldr/ldrMemory.cpp
r46082 r46083 264 264 LogFlow(("RTLdrOpenInMemory: pszName=%p:{%s} fFlags=%#x enmArch=%d cbImage=%#zu pfnRead=%p pfnDtor=%p pvUser=%p phLdrMod=%p\n", 265 265 pszName, pszName, fFlags, enmArch, cbImage, pfnRead, pfnDtor, pvUser, phLdrMod)); 266 AssertMsgReturn(!(fFlags & ~RTLDR_O_VALID_MASK), ("%#x\n", fFlags), VERR_INVALID_PARAMETER); 267 AssertMsgReturn(enmArch > RTLDRARCH_INVALID && enmArch < RTLDRARCH_END, ("%d\n", enmArch), VERR_INVALID_PARAMETER); 266 268 267 if (!pfnRead || !pfnDtor) 269 268 AssertPtrReturn(pvUser, VERR_INVALID_POINTER); 269 if (!pfnDtor) 270 pfnDtor = rtldrRdrMemDefaultDtor; 271 else 272 AssertPtrReturn(pfnRead, VERR_INVALID_POINTER); 273 274 /* The rest of the validations will call the destructor. */ 275 AssertMsgReturnStmt(!(fFlags & ~RTLDR_O_VALID_MASK), ("%#x\n", fFlags), 276 pfnDtor(pvUser), VERR_INVALID_PARAMETER); 277 AssertMsgReturnStmt(enmArch > RTLDRARCH_INVALID && enmArch < RTLDRARCH_END, ("%d\n", enmArch), 278 pfnDtor(pvUser), VERR_INVALID_PARAMETER); 270 279 if (!pfnRead) 271 280 pfnRead = rtldrRdrMemDefaultReader; 272 281 else 273 AssertPtrReturn(pfnRead, VERR_INVALID_POINTER); 274 if (!pfnDtor) 275 pfnDtor = rtldrRdrMemDefaultDtor; 276 else 277 AssertPtrReturn(pfnRead, VERR_INVALID_POINTER); 278 AssertReturn(cbImage > 0, VERR_INVALID_PARAMETER); 279 282 AssertReturnStmt(RT_VALID_PTR(pfnRead), pfnDtor(pvUser), VERR_INVALID_POINTER); 283 AssertReturnStmt(cbImage > 0, pfnDtor(pvUser), VERR_INVALID_PARAMETER); 280 284 281 285 /* … … 304 308 return rc; 305 309 } 310 306 311 pReader->pfnDestroy(pReader); 307 312 } 313 else 314 pfnDtor(pvUser), 308 315 *phLdrMod = NIL_RTLDRMOD; 316 309 317 LogFlow(("RTLdrOpen: return %Rrc\n", rc)); 310 318 return rc; -
trunk/src/VBox/Runtime/common/ldr/ldrNative.cpp
r44528 r46083 131 131 pMod->Core.eState = LDR_STATE_LOADED; 132 132 pMod->Core.pOps = &s_rtldrNativeOps; 133 pMod->Core.pReader = NULL; 133 134 pMod->hNative = ~(uintptr_t)0; 134 135 -
trunk/src/VBox/Runtime/common/ldr/ldrPE.cpp
r46078 r46083 65 65 /** Core module structure. */ 66 66 RTLDRMODINTERNAL Core; 67 /** Pointer to the reader instance. */68 PRTLDRREADER pReader;69 67 /** Pointer to internal copy of image bits. 70 68 * @todo the reader should take care of this. */ … … 160 158 * Both these checks are related to pfnDone(). 161 159 */ 162 PRTLDRREADER pReader = pModPe-> pReader;160 PRTLDRREADER pReader = pModPe->Core.pReader; 163 161 if (!pReader) 164 162 { … … 1101 1099 pModPe->pvBits = NULL; 1102 1100 } 1103 if (pModPe->pReader)1104 {1105 int rc = pModPe->pReader->pfnDestroy(pModPe->pReader);1106 AssertRC(rc);1107 pModPe->pReader = NULL;1108 }1109 1101 return VINF_SUCCESS; 1110 1102 } … … 1124 1116 pModPe->pvBits = NULL; 1125 1117 } 1126 if (pModPe-> pReader)1127 { 1128 int rc = pModPe-> pReader->pfnDestroy(pModPe->pReader);1118 if (pModPe->Core.pReader) 1119 { 1120 int rc = pModPe->Core.pReader->pfnDestroy(pModPe->Core.pReader); 1129 1121 AssertRC(rc); 1130 pModPe-> pReader = NULL;1122 pModPe->Core.pReader = NULL; 1131 1123 } 1132 1124 return VINF_SUCCESS; … … 1618 1610 { 1619 1611 const IMAGE_SECTION_HEADER *pSH = pModPe->paSections; 1620 PRTLDRREADER pReader = pModPe-> pReader;1612 PRTLDRREADER pReader = pModPe->Core.pReader; 1621 1613 uint32_t cbRead; 1622 1614 int rc; … … 1698 1690 int rtldrPEValidateDirectories(PRTLDRMODPE pModPe, const IMAGE_OPTIONAL_HEADER64 *pOptHdr) 1699 1691 { 1700 const char *pszLogName = pModPe-> pReader->pfnLogName(pModPe->pReader); NOREF(pszLogName);1692 const char *pszLogName = pModPe->Core.pReader->pfnLogName(pModPe->Core.pReader); NOREF(pszLogName); 1701 1693 union /* combine stuff we're reading to help reduce stack usage. */ 1702 1694 { … … 1772 1764 if (!pFirst) 1773 1765 return VERR_NO_TMP_MEMORY; 1774 int rc = pModPe-> pReader->pfnRead(pModPe->pReader, pFirst, Dir.Size, Dir.VirtualAddress);1766 int rc = pModPe->Core.pReader->pfnRead(pModPe->Core.pReader, pFirst, Dir.Size, Dir.VirtualAddress); 1775 1767 if (RT_SUCCESS(rc)) 1776 1768 { … … 1897 1889 else 1898 1890 pModPe->Core.pOps = &s_rtldrPE32Ops.Core; 1899 pModPe-> pReader= pReader;1891 pModPe->Core.pReader = pReader; 1900 1892 pModPe->pvBits = NULL; 1901 1893 pModPe->offNtHdrs = offNtHdrs; -
trunk/src/VBox/Runtime/common/ldr/ldrkStuff.cpp
r45994 r46083 241 241 static int rtkldrRdr_Destroy( PKRDR pRdr) 242 242 { 243 PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader; 244 int rc = pReader->pfnDestroy(pReader); 245 return rtkldrConvertErrorFromIPRT(rc); 243 PRTKLDRRDR pThis = (PRTKLDRRDR)pRdr; 244 pThis->pReader = NULL; 245 RTMemFree(pThis); 246 return 0; 246 247 } 247 248 … … 877 878 { 878 879 pNewMod->Core.u32Magic = RTLDRMOD_MAGIC; 879 pNewMod->Core.eState = LDR_STATE_OPENED; 880 pNewMod->Core.pOps = &g_rtkldrOps; 881 pNewMod->pMod = pMod; 880 pNewMod->Core.eState = LDR_STATE_OPENED; 881 pNewMod->Core.pOps = &g_rtkldrOps; 882 pNewMod->Core.pReader = pReader; 883 pNewMod->pMod = pMod; 882 884 *phLdrMod = &pNewMod->Core; 883 885 … … 896 898 return VINF_SUCCESS; 897 899 } 900 901 /* bail out */ 898 902 kLdrModClose(pMod); 899 903 krc = KERR_NO_MEMORY; 900 904 } 905 else 906 RTMemFree(pRdr); 907 901 908 return rtkldrConvertError(krc); 902 909 } -
trunk/src/VBox/Runtime/include/internal/dbgmod.h
r46048 r46083 567 567 RTDBGCFG hDbgCfg, PRTDBGMODDEFERRED *ppDeferred); 568 568 569 DECLHIDDEN(int) rtDbgModLdrOpenFromHandle(PRTDBGMODINT pDbgMod, RTLDRMOD hLdrMod); 570 569 571 /** @} */ 570 572 -
trunk/src/VBox/Runtime/include/internal/ldr.h
r44528 r46083 403 403 /** Loader ops. */ 404 404 PCRTLDROPS pOps; 405 /** Pointer to the reader instance. This is NULL for native image. */ 406 PRTLDRREADER pReader; 405 407 } RTLDRMODINTERNAL; 406 408 … … 456 458 457 459 460 DECLHIDDEN(int) rtLdrReadAt(RTLDRMOD hLdrMod, void *pvBuf, RTFOFF off, size_t cb); 461 458 462 RT_C_DECLS_END 459 463 -
trunk/src/VBox/Runtime/tools/RTLdrFlt.cpp
r46070 r46083 239 239 rc = RTDbgModCreateFromImage(&hMod, pszModule, NULL, hDbgCfg); 240 240 else 241 rc = RTDbgModCreateFromPeImage(&hMod, pszModule, NULL, cbImage, uTimestamp, hDbgCfg);241 rc = RTDbgModCreateFromPeImage(&hMod, pszModule, NULL, NIL_RTLDRMOD, cbImage, uTimestamp, hDbgCfg); 242 242 if (RT_FAILURE(rc)) 243 243 return RTMsgErrorExit(RTEXITCODE_FAILURE, "RTDbgModCreateFromImage(,%s,,) -> %Rrc", pszModule, rc);
Note:
See TracChangeset
for help on using the changeset viewer.