Changeset 4673 in vbox for trunk/src/VBox/Additions/WINNT/VBoxGuest/VBoxGuest.cpp
- Timestamp:
- Sep 10, 2007 3:38:23 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/VBoxGuest/VBoxGuest.cpp
r4667 r4673 457 457 for (uint32_t i=pDevExt->MemBalloon.cBalloons;i<u32BalloonSize;i++) 458 458 { 459 #ifndef TARGET_NT4 460 /* 461 * Use MmAllocatePagesForMdl to specify the range of physical addresses we wish to use. 462 */ 463 PHYSICAL_ADDRESS Zero; 464 PHYSICAL_ADDRESS HighAddr; 465 Zero.QuadPart = 0; 466 HighAddr.QuadPart = _4G - 1; 467 PMDL pMdl = MmAllocatePagesForMdl(Zero, HighAddr, Zero, VMMDEV_MEMORY_BALLOON_CHUNK_SIZE); 468 if (pMdl) 469 { 470 if (MmGetMdlByteCount(pMdl) < VMMDEV_MEMORY_BALLOON_CHUNK_SIZE) 471 { 472 MmFreePagesFromMdl(pMdl); 473 ExFreePool(pMdl); 474 rc = VERR_NO_MEMORY; 475 goto end; 476 } 477 } 478 #else 459 479 PVOID pvBalloon; 460 461 480 pvBalloon = ExAllocatePoolWithTag(PagedPool, VMMDEV_MEMORY_BALLOON_CHUNK_SIZE, 'MBAL'); 462 481 if (!pvBalloon) … … 482 501 __except(EXCEPTION_EXECUTE_HANDLER) 483 502 { 503 Log(("MmProbeAndLockPages failed!\n")); 484 504 rc = VERR_NO_MEMORY; 485 505 IoFreeMdl (pMdl); … … 488 508 } 489 509 } 510 #endif 490 511 491 512 PPFN_NUMBER pPageDesc = MmGetMdlPfnArray(pMdl); … … 505 526 "rc = %d, VMMDev rc = %Vrc\n", rc, req->header.rc)); 506 527 528 #ifndef TARGET_NT4 529 MmFreePagesFromMdl(pMdl); 530 ExFreePool(pMdl); 531 #else 507 532 IoFreeMdl (pMdl); 508 533 ExFreePoolWithTag(pvBalloon, 'MBAL'); 534 #endif 509 535 goto end; 510 536 } 511 537 else 512 538 { 513 dprintf(("VBoxGuest::VBoxGuestSetBalloonSize added 1 MB chunk at %x\n", pvBalloon)); 539 #ifndef TARGET_NT4 540 dprintf(("VBoxGuest::VBoxGuestSetBalloonSize %d MB added chunk at %x\n", i, pMdl)); 541 #else 542 dprintf(("VBoxGuest::VBoxGuestSetBalloonSize %d MB added chunk at %x\n", i, pvBalloon)); 543 #endif 514 544 pDevExt->MemBalloon.paMdlMemBalloon[i] = pMdl; 515 545 pDevExt->MemBalloon.cBalloons++; … … 522 552 for (uint32_t i=pDevExt->MemBalloon.cBalloons-1;i>=u32BalloonSize;i--) 523 553 { 524 PMDL pMdl = pDevExt->MemBalloon.paMdlMemBalloon[i]; 525 PVOID pvBalloon = MmGetMdlVirtualAddress(pMdl); 526 527 PPFN_NUMBER pPageDesc = MmGetMdlPfnArray(pMdl); 528 529 /* Copy manually as RTGCPHYS is always 64 bits */ 530 for (uint32_t j=0;j<VMMDEV_MEMORY_BALLOON_CHUNK_PAGES;j++) 531 req->aPhysPage[j] = pPageDesc[j]; 532 533 req->header.size = RT_OFFSETOF(VMMDevChangeMemBalloon, aPhysPage[VMMDEV_MEMORY_BALLOON_CHUNK_PAGES]); 534 req->cPages = VMMDEV_MEMORY_BALLOON_CHUNK_PAGES; 535 req->fInflate = false; 536 537 rc = VbglGRPerform(&req->header); 538 if (VBOX_FAILURE(rc) || VBOX_FAILURE(req->header.rc)) 539 { 540 AssertMsgFailed(("VBoxGuest::VBoxGuestSetBalloonSize: error issuing request to VMMDev! rc = %d, VMMDev rc = %Vrc\n", rc, req->header.rc)); 541 /* ignore error and just continue; this should never fail */ 542 } 543 544 dprintf(("VBoxGuest::VBoxGuestSetBalloonSize free 1 MB chunk at %x\n", pvBalloon)); 545 546 /* Free the ballooned memory */ 547 MmUnlockPages (pMdl); 548 IoFreeMdl (pMdl); 549 ExFreePoolWithTag(pvBalloon, 'MBAL'); 550 551 pDevExt->MemBalloon.paMdlMemBalloon[i] = NULL; 552 pDevExt->MemBalloon.cBalloons--; 554 PMDL pMdl = pDevExt->MemBalloon.paMdlMemBalloon[i]; 555 556 Assert(pMdl); 557 if (pMdl) 558 { 559 PVOID pvBalloon = MmGetMdlVirtualAddress(pMdl); 560 561 PPFN_NUMBER pPageDesc = MmGetMdlPfnArray(pMdl); 562 563 /* Copy manually as RTGCPHYS is always 64 bits */ 564 for (uint32_t j=0;j<VMMDEV_MEMORY_BALLOON_CHUNK_PAGES;j++) 565 req->aPhysPage[j] = pPageDesc[j]; 566 567 req->header.size = RT_OFFSETOF(VMMDevChangeMemBalloon, aPhysPage[VMMDEV_MEMORY_BALLOON_CHUNK_PAGES]); 568 req->cPages = VMMDEV_MEMORY_BALLOON_CHUNK_PAGES; 569 req->fInflate = false; 570 571 rc = VbglGRPerform(&req->header); 572 if (VBOX_FAILURE(rc) || VBOX_FAILURE(req->header.rc)) 573 { 574 AssertMsgFailed(("VBoxGuest::VBoxGuestSetBalloonSize: error issuing request to VMMDev! rc = %d, VMMDev rc = %Vrc\n", rc, req->header.rc)); 575 break; 576 } 577 578 dprintf(("VBoxGuest::VBoxGuestSetBalloonSize %d MB free chunk at %x\n", i, pvBalloon)); 579 580 /* Free the ballooned memory */ 581 #ifndef TARGET_NT4 582 MmFreePagesFromMdl(pMdl); 583 ExFreePool(pMdl); 584 #else 585 MmUnlockPages (pMdl); 586 IoFreeMdl (pMdl); 587 ExFreePoolWithTag(pvBalloon, 'MBAL'); 588 #endif 589 590 pDevExt->MemBalloon.paMdlMemBalloon[i] = NULL; 591 pDevExt->MemBalloon.cBalloons--; 592 } 553 593 } 554 594 } … … 593 633 594 634 rc = VBoxGuestSetBalloonSize(pDevExt, req->u32BalloonSize); 635 /* ignore out of memory failures */ 636 if (rc == VERR_NO_MEMORY) 637 rc = VINF_SUCCESS; 638 595 639 if (pMemBalloonSize) 596 640 *pMemBalloonSize = pDevExt->MemBalloon.cBalloons;
Note:
See TracChangeset
for help on using the changeset viewer.