VirtualBox

Changeset 6839 in vbox


Ignore:
Timestamp:
Feb 7, 2008 10:12:59 AM (17 years ago)
Author:
vboxsync
Message:

Added GMMR0FreePages request wrappers for ring-3.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/gmm.h

    r6836 r6839  
    386386GMMR3DECL(int)  GMMR3AllocatePagesPerform(PVM pVM, PGMMALLOCATEPAGESREQ pReq);
    387387GMMR3DECL(void) GMMR3AllocatePagesCleanup(PGMMALLOCATEPAGESREQ pReq);
     388GMMR3DECL(int)  GMMR3FreePagesPrepare(PVM pVM, PGMMFREEPAGESREQ *ppReq, uint32_t cPages, GMMACCOUNT enmAccount);
     389GMMR3DECL(int)  GMMR3FreePagesPerform(PVM pVM, PGMMFREEPAGESREQ pReq);
     390GMMR3DECL(void) GMMR3FreePagesCleanup(PGMMFREEPAGESREQ pReq);
     391GMMR3DECL(void) GMMR3FreeAllocatedPages(PVM pVM, GMMALLOCATEPAGESREQ const *pAllocReq);
    388392GMMR3DECL(int)  GMMR3DeflatedBalloon(PVM pVM, uint32_t cPages);
    389393GMMR3DECL(int)  GMMR3MapUnmapChunk(PVM pVM, uint32_t idChunkMap, uint32_t idChunkUnmap, PRTR3PTR ppvR3);
  • trunk/src/VBox/VMM/GMM.cpp

    r6836 r6839  
    6565/**
    6666 * Prepares a GMMR0AllocatePages request.
     67 *
     68 * @returns VINF_SUCCESS or VERR_NO_TMP_MEMORY.
     69 * @param       pVM         Pointer to the shared VM structure.
     70 * @param[out]  ppReq       Where to store the pointer to the request packet.
     71 * @param       cPages      The number of pages that's to be allocated.
     72 * @param       enmAccount  The account to charge.
    6773 */
    6874GMMR3DECL(int) GMMR3AllocatePagesPrepare(PVM pVM, PGMMALLOCATEPAGESREQ *ppReq, uint32_t cPages, GMMACCOUNT enmAccount)
     
    130136
    131137
    132 #if 0 /* impractical */
    133 GMMR3DECL(int)  GMMR3FreePages(PVM pVM, uint32_t cPages, PGMMFREEPAGEDESC paPages, GMMACCOUNT enmAccount)
    134 {
    135     GMMFREEPAGESREQ Req;
    136     Req.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC;
    137     Req.Hdr.cbReq = sizeof(Req);
    138 
    139     return SUPCallVMMR0Ex(pVM->pVMR0, VMMR0_DO_GMM_FREE_PAGES, 0, &Req.Hdr);
    140 }
    141 #endif
     138/**
     139 * Prepares a GMMR0FreePages request.
     140 *
     141 * @returns VINF_SUCCESS or VERR_NO_TMP_MEMORY.
     142 * @param       pVM         Pointer to the shared VM structure.
     143 * @param[out]  ppReq       Where to store the pointer to the request packet.
     144 * @param       cPages      The number of pages that's to be freed.
     145 * @param       enmAccount  The account to charge.
     146 */
     147GMMR3DECL(int) GMMR3FreePagesPrepare(PVM pVM, PGMMFREEPAGESREQ *ppReq, uint32_t cPages, GMMACCOUNT enmAccount)
     148{
     149    uint32_t cb = RT_OFFSETOF(GMMFREEPAGESREQ, aPages[cPages]);
     150    PGMMFREEPAGESREQ pReq = (PGMMFREEPAGESREQ)RTMemTmpAllocZ(cb);
     151    if (!pReq)
     152        return VERR_NO_TMP_MEMORY;
     153
     154    pReq->Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC;
     155    pReq->Hdr.cbReq = cb;
     156    pReq->enmAccount = enmAccount;
     157    pReq->cPages = cPages;
     158    NOREF(pVM);
     159    return VINF_SUCCESS;
     160}
     161
     162
     163/**
     164 * Performs a GMMR0FreePages request.
     165 * This will call VMSetError on failure.
     166 *
     167 * @returns VBox status code.
     168 * @param   pVM         Pointer to the shared VM structure.
     169 * @param   pReq        Pointer to the request (returned by GMMR3FreePagesPrepare).
     170 */
     171GMMR3DECL(int) GMMR3FreePagesPerform(PVM pVM, PGMMFREEPAGESREQ pReq)
     172{
     173    int rc = SUPCallVMMR0Ex(pVM->pVMR0, VMMR0_DO_GMM_FREE_PAGES, 0, &pReq->Hdr);
     174    if (RT_SUCCESS(rc))
     175        return rc;
     176    AssertRC(rc);
     177    return VMSetError(pVM, rc, RT_SRC_POS,
     178                      N_("GMMR0FreePages failed to free %u pages"),
     179                      pReq->cPages);
     180}
     181
     182
     183/**
     184 * Cleans up a GMMR0FreePages request.
     185 * @param   pReq        Pointer to the request (returned by GMMR3FreePagesPrepare).
     186 */
     187GMMR3DECL(void) GMMR3FreePagesCleanup(PGMMFREEPAGESREQ pReq)
     188{
     189    RTMemTmpFree(pReq);
     190}
     191
     192
     193/**
     194 * Frees allocated pages, for bailing out on failure.
     195 *
     196 * This will not call VMSetError on failure but will use AssertLogRel instead.
     197 *
     198 * @param   pVM         Pointer to the shared VM structure.
     199 * @param   pAllocReq   The allocation request to undo.
     200 */
     201GMMR3DECL(void) GMMR3FreeAllocatedPages(PVM pVM, GMMALLOCATEPAGESREQ const *pAllocReq)
     202{
     203    uint32_t cb = RT_OFFSETOF(GMMFREEPAGESREQ, aPages[pAllocReq->cPages]);
     204    PGMMFREEPAGESREQ pReq = (PGMMFREEPAGESREQ)RTMemTmpAllocZ(cb);
     205    AssertLogRelReturnVoid(pReq);
     206
     207    pReq->Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC;
     208    pReq->Hdr.cbReq = cb;
     209    pReq->enmAccount = pAllocReq->enmAccount;
     210    pReq->cPages = pAllocReq->cPages;
     211    uint32_t iPage = pAllocReq->cPages;
     212    while (iPage-- > 0)
     213    {
     214        Assert(pAllocReq->aPages[iPage].idPage != NIL_GMM_PAGEID);
     215        pReq->aPages[iPage].idPage = pAllocReq->aPages[iPage].idPage;
     216    }
     217
     218    int rc = SUPCallVMMR0Ex(pVM->pVMR0, VMMR0_DO_GMM_FREE_PAGES, 0, &pReq->Hdr);
     219    AssertLogRelRC(rc);
     220
     221    RTMemTmpFree(pReq);
     222}
    142223
    143224
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette