- Timestamp:
- Nov 25, 2008 8:18:41 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/mm.h
r13832 r14594 340 340 VMMR3DECL(int) MMR3HyperMapGCPhys(PVM pVM, RTGCPHYS GCPhys, size_t cb, const char *pszDesc, PRTGCPTR pGCPtr); 341 341 VMMR3DECL(int) MMR3HyperMapMMIO2(PVM pVM, PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS off, RTGCPHYS cb, const char *pszDesc, PRTRCPTR pRCPtr); 342 VMMR3DECL(int) MMR3HyperMapHCRam(PVM pVM, void *pvHC, size_t cb, bool fFree, const char *pszDesc, PRTGCPTR pGCPtr);343 342 VMMR3DECL(int) MMR3HyperMapPages(PVM pVM, void *pvR3, RTR0PTR pvR0, size_t cPages, PCSUPPAGE paPages, const char *pszDesc, PRTGCPTR pGCPtr); 344 343 VMMR3DECL(int) MMR3HyperReserve(PVM pVM, unsigned cb, const char *pszDesc, PRTGCPTR pGCPtr); -
trunk/src/VBox/VMM/MMHyper.cpp
r14592 r14594 510 510 } 511 511 } 512 return rc;513 }514 515 516 /**517 * Locks and Maps HC virtual memory into the hypervisor region in the GC.518 *519 * @return VBox status code.520 *521 * @param pVM VM handle.522 * @param pvR3 Host context address of the memory (may be not page523 * aligned).524 * @param cb Size of the memory. Will be rounded up to nearest page.525 * @param fFree Set this if MM is responsible for freeing the memory526 * using SUPPageFree.527 * @param pszDesc Mapping description.528 * @param pGCPtr Where to store the GC address corresponding to pvR3.529 */530 VMMR3DECL(int) MMR3HyperMapHCRam(PVM pVM, void *pvR3, size_t cb, bool fFree, const char *pszDesc, PRTGCPTR pGCPtr)531 {532 LogFlow(("MMR3HyperMapHCRam: pvR3=%p cb=%d fFree=%d pszDesc=%p:{%s} pGCPtr=%p\n", pvR3, (int)cb, fFree, pszDesc, pszDesc, pGCPtr));533 534 /*535 * Validate input.536 */537 if ( !pvR3538 || cb <= 0539 || !pszDesc540 || !*pszDesc)541 {542 AssertMsgFailed(("Invalid parameter\n"));543 return VERR_INVALID_PARAMETER;544 }545 546 /*547 * Page align address and size.548 */549 void *pvR3Page = (void *)((uintptr_t)pvR3 & PAGE_BASE_HC_MASK);550 cb += (uintptr_t)pvR3 & PAGE_OFFSET_MASK;551 cb = RT_ALIGN_Z(cb, PAGE_SIZE);552 553 /*554 * Add the memory to the hypervisor area.555 */556 RTGCPTR GCPtr;557 PMMLOOKUPHYPER pLookup;558 int rc = mmR3HyperMap(pVM, cb, pszDesc, &GCPtr, &pLookup);559 if (RT_SUCCESS(rc))560 {561 /*562 * Lock the heap memory and tell PGM about the locked pages.563 */564 PMMLOCKEDMEM pLockedMem;565 rc = mmR3LockMem(pVM, pvR3Page, cb, fFree ? MM_LOCKED_TYPE_HYPER : MM_LOCKED_TYPE_HYPER_NOFREE, &pLockedMem, false /* fSilentFailure */);566 if (RT_SUCCESS(rc))567 {568 /* map the stuff into guest address space. */569 if (pVM->mm.s.fPGMInitialized)570 rc = mmR3MapLocked(pVM, pLockedMem, GCPtr, 0, ~(size_t)0, 0);571 if (RT_SUCCESS(rc))572 {573 pLookup->enmType = MMLOOKUPHYPERTYPE_LOCKED;574 pLookup->u.Locked.pvR3 = pvR3;575 pLookup->u.Locked.pvR0 = NIL_RTR0PTR;576 pLookup->u.Locked.pLockedMem = pLockedMem;577 578 /* done. */579 GCPtr |= (uintptr_t)pvR3 & PAGE_OFFSET_MASK;580 *pGCPtr = GCPtr;581 return rc;582 }583 /* Don't care about failure clean, we're screwed if this fails anyway. */584 }585 }586 587 512 return rc; 588 513 } -
trunk/src/VBox/VMM/PDMLdr.cpp
r14498 r14594 460 460 * Allocate space in the hypervisor. 461 461 */ 462 size_t cb = RTLdrSize(pModule->hLdrMod);462 size_t cb = RTLdrSize(pModule->hLdrMod); 463 463 cb = RT_ALIGN_Z(cb, PAGE_SIZE); 464 rc = SUPPageAlloc(cb >> PAGE_SHIFT, &pModule->pvBits);465 if (RT_SUCCESS(rc))466 {467 RTGCPTR GCPtr;468 rc = MMR3HyperMapHCRam(pVM, pModule->pvBits, cb, true, pModule->szName, &GCPtr);464 uint32_t cPages = cb >> PAGE_SHIFT; 465 PSUPPAGE paPages = (PSUPPAGE)RTMemTmpAlloc(cPages * sizeof(paPages[0])); 466 if (paPages) 467 { 468 rc = SUPR3PageAllocEx(cPages, 0 /*fFlags*/, &pModule->pvBits, NULL /*pR0Ptr*/, paPages); 469 469 if (RT_SUCCESS(rc)) 470 470 { 471 MMR3HyperReserve(pVM, PAGE_SIZE, "fence", NULL); 472 473 /* 474 * Get relocated image bits. 475 */ 476 Assert(MMHyperR3ToRC(pVM, pModule->pvBits) == GCPtr); 477 pModule->ImageBase = GCPtr; 478 PDMGETIMPORTARGS Args; 479 Args.pVM = pVM; 480 Args.pModule = pModule; 481 rc = RTLdrGetBits(pModule->hLdrMod, pModule->pvBits, pModule->ImageBase, pdmR3GetImportRC, &Args); 471 RTGCPTR GCPtr; 472 rc = MMR3HyperMapPages(pVM, pModule->pvBits, (uintptr_t)pModule->pvBits, 473 cPages, paPages, pModule->szName, &GCPtr); 482 474 if (RT_SUCCESS(rc)) 483 475 { 476 MMR3HyperReserve(pVM, PAGE_SIZE, "fence", NULL); 477 484 478 /* 485 * Insert the module.479 * Get relocated image bits. 486 480 */ 487 PUVM pUVM = pVM->pUVM; 488 if (pUVM->pdm.s.pModules) 481 Assert(MMHyperR3ToRC(pVM, pModule->pvBits) == GCPtr); 482 pModule->ImageBase = GCPtr; 483 PDMGETIMPORTARGS Args; 484 Args.pVM = pVM; 485 Args.pModule = pModule; 486 rc = RTLdrGetBits(pModule->hLdrMod, pModule->pvBits, pModule->ImageBase, pdmR3GetImportRC, &Args); 487 if (RT_SUCCESS(rc)) 489 488 { 490 /* we don't expect this list to be very long, so rather save the tail pointer. */ 491 PPDMMOD pCur = pUVM->pdm.s.pModules; 492 while (pCur->pNext) 493 pCur = pCur->pNext; 494 pCur->pNext = pModule; 489 /* 490 * Insert the module. 491 */ 492 PUVM pUVM = pVM->pUVM; 493 if (pUVM->pdm.s.pModules) 494 { 495 /* we don't expect this list to be very long, so rather save the tail pointer. */ 496 PPDMMOD pCur = pUVM->pdm.s.pModules; 497 while (pCur->pNext) 498 pCur = pCur->pNext; 499 pCur->pNext = pModule; 500 } 501 else 502 pUVM->pdm.s.pModules = pModule; /* (pNext is zeroed by alloc) */ 503 Log(("PDM: RC Module at %RRv %s (%s)\n", (RTRCPTR)pModule->ImageBase, pszName, pszFilename)); 504 RTMemTmpFree(pszFile); 505 RTMemTmpFree(paPages); 506 return VINF_SUCCESS; 495 507 } 496 else497 pUVM->pdm.s.pModules = pModule; /* (pNext is zeroed by alloc) */498 Log(("PDM: RC Module at %RRv %s (%s)\n", (RTRCPTR)pModule->ImageBase, pszName, pszFilename));499 RTMemTmpFree(pszFile);500 return VINF_SUCCESS;501 508 } 509 else 510 { 511 AssertRC(rc); 512 SUPR3PageFreeEx(pModule->pvBits, cPages); 513 } 502 514 } 503 515 else 504 { 505 AssertRC(rc); 506 SUPPageFree(pModule->pvBits, cb >> PAGE_SHIFT); 507 } 516 AssertMsgFailed(("SUPPageAlloc(%d,) -> %Rrc\n", cPages, rc)); 517 RTMemTmpFree(paPages); 508 518 } 509 519 else 510 AssertMsgFailed(("SUPPageAlloc(%d,) -> %Rrc\n", cb >> PAGE_SHIFT, rc));520 rc = VERR_NO_TMP_MEMORY; 511 521 int rc2 = RTLdrClose(pModule->hLdrMod); 512 522 AssertRC(rc2);
Note:
See TracChangeset
for help on using the changeset viewer.