Changeset 29138 in vbox for trunk/src/VBox/VMM
- Timestamp:
- May 6, 2010 11:49:48 AM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 61205
- Location:
- trunk/src/VBox/VMM/VMMR0
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/VMMR0/GMMR0.cpp
r29091 r29138 3414 3414 3415 3415 pRecVM->Core.Key = GCBaseAddr; 3416 pRecVM->cRegions = cRegions; 3417 for (unsigned i = 0; i < cRegions; i++) 3418 { 3419 pRecVM->aRegions[i].GCRegionAddr = pRegions[i].GCRegionAddr; 3420 pRecVM->aRegions[i].cbRegion = pRegions[i].cbRegion; 3421 pRecVM->aRegions[i].u32Alignment = 0; 3422 pRecVM->aRegions[i].paHCPhysAndPageID = 0; /* uninitialized. */ 3423 } 3416 3424 3417 3425 bool ret = RTAvlGCPtrInsert(&pGVM->gmm.s.pSharedModuleTree, &pRecVM->Core); … … 3448 3456 3449 3457 for (unsigned i = 0; i < cRegions; i++) 3450 pRec->aRegions[i] = pRegions[i]; 3458 { 3459 pRec->aRegions[i].GCRegionAddr = pRegions[i].GCRegionAddr; 3460 pRec->aRegions[i].cbRegion = pRegions[i].cbRegion; 3461 pRec->aRegions[i].u32Alignment = 0; 3462 pRec->aRegions[i].paHCPhysAndPageID = 0; /* uninitialized. */ 3463 } 3451 3464 3452 3465 /* Save reference. */ … … 3553 3566 goto end; 3554 3567 } 3555 PGMMSHAREDMODULE pRec = pRecVM->pSharedModule; 3556 Assert(pRec); 3557 Assert(pRec->cUsers); 3558 3559 pRec->cUsers--; 3560 if (pRec->cUsers == 0) 3561 { 3562 /* @todo free shared pages. */ 3563 RTMemFree(pRec); 3564 } 3568 /* Force pRec to go out of scope after freeing it. */ 3569 { 3570 PGMMSHAREDMODULE pRec = pRecVM->pSharedModule; 3571 Assert(pRec); 3572 Assert(pRec->cUsers); 3573 3574 pRec->cUsers--; 3575 if (pRec->cUsers == 0) 3576 { 3577 /* @todo free shared pages. */ 3578 for (unsigned i = 0; i < pRec->cRegions; i++) 3579 if (pRec->aRegions[i].paHCPhysAndPageID) 3580 RTMemFree(pRec->aRegions[i].paHCPhysAndPageID); 3581 3582 RTMemFree(pRec); 3583 } 3584 } 3585 3586 for (unsigned i = 0; i < pRecVM->cRegions; i++) 3587 if (pRecVM->aRegions[i].paHCPhysAndPageID) 3588 RTMemFree(pRecVM->aRegions[i].paHCPhysAndPageID); 3565 3589 RTMemFree(pRecVM); 3566 3590 … … 3599 3623 3600 3624 3625 #ifdef VBOX_WITH_PAGE_SHARING 3626 /** 3627 * Checks specified shared module range for changes 3628 * 3629 * @returns VBox status code. 3630 * @param pVM VM handle 3631 * @param idCpu VCPU id 3632 * @param pReq Module description 3633 * @param idxRegion Region index 3634 * @param cPages Number of entries in the paHCPhysAndPageID array 3635 * @param paHCPhysAndPageID Host physical address and the Page ID array 3636 */ 3637 GMMR0DECL(int) GMMR0SharedModuleCheckRange(PVM pVM, VMCPUID idCpu, PGMMREGISTERSHAREDMODULEREQ pReq, unsigned idxRegion, unsigned cPages, PRTHCPHYS paHCPhysAndPageID) 3638 { 3639 AssertReturn(idxRegion < pReq->cRegions, VERR_INVALID_PARAMETER); 3640 AssertReturn(cPages == (pReq->aRegions[idxRegion].cbRegion >> PAGE_SHIFT), VERR_INVALID_PARAMETER); 3641 3642 /* 3643 * Validate input and get the basics. 3644 */ 3645 PGMM pGMM; 3646 GMM_GET_VALID_INSTANCE(pGMM, VERR_INTERNAL_ERROR); 3647 PGVM pGVM; 3648 int rc = GVMMR0ByVMAndEMT(pVM, idCpu, &pGVM); 3649 if (RT_FAILURE(rc)) 3650 return rc; 3651 3652 /* 3653 * Take the sempahore and do some more validations. 3654 */ 3655 rc = RTSemFastMutexRequest(pGMM->Mtx); 3656 AssertRC(rc); 3657 if (GMM_CHECK_SANITY_UPON_ENTERING(pGMM)) 3658 { 3659 PGMMSHAREDMODULEPERVM pRecVM = (PGMMSHAREDMODULEPERVM)RTAvlGCPtrGet(&pGVM->gmm.s.pSharedModuleTree, pReq->GCBaseAddr); 3660 if (!pRecVM) 3661 { 3662 rc = VERR_PGM_SHARED_MODULE_NOT_FOUND; 3663 goto end; 3664 } 3665 3666 for (unsigned i = 0; i < cPages; i++) 3667 { 3668 } 3669 3670 GMM_CHECK_SANITY_UPON_LEAVING(pGMM); 3671 } 3672 else 3673 rc = VERR_INTERNAL_ERROR_5; 3674 3675 end: 3676 RTSemFastMutexRelease(pGMM->Mtx); 3677 return rc; 3678 } 3679 #endif 3680 3601 3681 /** 3602 3682 * Checks registered modules for shared pages -
trunk/src/VBox/VMM/VMMR0/GMMR0Internal.h
r29024 r29138 35 35 uint32_t cFixedPages; 36 36 } GMMVMSIZES; 37 /** Pointer to a GMMVMSIZES. */ 37 38 typedef GMMVMSIZES *PGMMVMSIZES; 38 39 40 /** 41 * Shared region descriptor 42 */ 43 typedef struct GMMSHAREDREGIONDESC 44 { 45 /** Region base address. */ 46 RTGCPTR64 GCRegionAddr; 47 /** Region size. */ 48 uint32_t cbRegion; 49 /** Alignment. */ 50 uint32_t u32Alignment; 51 /** Pointer to physical page address array. */ 52 PRTHCPHYS paHCPhysAndPageID; 53 } GMMSHAREDREGIONDESC; 54 /** Pointer to a GMMSHAREDREGIONDESC. */ 55 typedef GMMSHAREDREGIONDESC *PGMMSHAREDREGIONDESC; 39 56 40 57 /** … … 58 75 char szVersion[GMM_SHARED_MODULE_MAX_VERSION_STRING]; 59 76 /** Shared region descriptor(s). */ 60 VMMDEVSHAREDREGIONDESCaRegions[1];77 GMMSHAREDREGIONDESC aRegions[1]; 61 78 } GMMSHAREDMODULE; 62 79 /** Pointer to a GMMSHAREDMODULE. */ … … 76 93 /* Set if another VM registered a different shared module at the same base address. */ 77 94 bool fCollision; 95 /** Align at 8 byte boundary */ 96 bool abAlignment[7]; 78 97 98 /** Number of regions in the aRegions array. */ 99 unsigned cRegions; 100 101 /** Shared region descriptor(s). */ 102 GMMSHAREDREGIONDESC aRegions[1]; 79 103 } GMMSHAREDMODULEPERVM; 80 104 /** Pointer to a GMMSHAREDMODULEPERVM. */ -
trunk/src/VBox/VMM/VMMR0/PGMR0.cpp
r29091 r29138 27 27 #include <VBox/err.h> 28 28 #include <iprt/assert.h> 29 #include <iprt/mem.h> 29 30 30 31 RT_C_DECLS_BEGIN … … 313 314 { 314 315 int rc = VINF_SUCCESS; 316 PRTHCPHYS paHCPhysAndPageID = NULL; 317 uint32_t cbPreviousRegion = 0; 315 318 316 319 /* … … 328 331 Assert((pReq->aRegions[i].GCRegionAddr & 0xfff) == 0); 329 332 330 RTGCPTR GCRegion = pReq->aRegions[i].GCRegionAddr; 331 uint32_t cbRegion = pReq->aRegions[i].cbRegion & ~0xfff; 333 RTGCPTR GCRegion = pReq->aRegions[i].GCRegionAddr; 334 unsigned cbRegion = pReq->aRegions[i].cbRegion & ~0xfff; 335 unsigned idxPage = 0; 336 bool fValidChanges = false; 337 338 if (cbPreviousRegion < cbRegion) 339 { 340 if (paHCPhysAndPageID) 341 RTMemFree(paHCPhysAndPageID); 342 343 paHCPhysAndPageID = (PRTHCPHYS)RTMemAlloc((cbRegion << PAGE_SHIFT) * sizeof(*paHCPhysAndPageID)); 344 if (!paHCPhysAndPageID) 345 { 346 AssertFailed(); 347 rc = VERR_NO_MEMORY; 348 goto end; 349 } 350 cbPreviousRegion = cbRegion; 351 } 332 352 333 353 while (cbRegion) … … 344 364 && !PGM_PAGE_IS_SHARED(pPage)) 345 365 { 366 fValidChanges = true; 367 paHCPhysAndPageID[idxPage] = pPage->HCPhysAndPageID; 346 368 } 369 else 370 paHCPhysAndPageID[idxPage] = NIL_RTHCPHYS; 347 371 } 348 372 else 373 paHCPhysAndPageID[idxPage] = NIL_RTHCPHYS; 374 375 idxPage++; 349 376 GCRegion += PAGE_SIZE; 350 377 cbRegion -= PAGE_SIZE; 351 378 } 352 } 353 379 380 if (fValidChanges) 381 { 382 rc = GMMR0SharedModuleCheckRange(pVM, pVCpu->idCpu, pReq, i, idxPage, paHCPhysAndPageID); 383 AssertRC(rc); 384 if (RT_FAILURE(rc)) 385 break; 386 } 387 } 388 389 end: 354 390 pgmUnlock(pVM); 391 if (paHCPhysAndPageID) 392 RTMemFree(paHCPhysAndPageID); 393 355 394 return rc; 356 395 }
Note:
See TracChangeset
for help on using the changeset viewer.