VirtualBox

Changeset 6836 in vbox


Ignore:
Timestamp:
Feb 6, 2008 7:59:53 PM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
27955
Message:

Added ring-3 request wrapper for GMMR0AllocatePages that takes care of seeding and VMSetError.

Location:
trunk
Files:
2 edited

Legend:

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

    r6800 r6836  
    250250
    251251
    252 GMMR3DECL(int)  GMMR3InitialReservation(PVM pVM, uint64_t cBasePages, uint32_t cShadowPages, uint32_t cFixedPages,
    253                                         GMMOCPOLICY enmPolicy, GMMPRIORITY enmPriority);
    254 GMMR3DECL(int)  GMMR3UpdateReservation(PVM pVM, uint64_t cBasePages, uint32_t cShadowPages, uint32_t cFixedPages);
    255 GMMR3DECL(int)  GMMR3DeflatedBalloon(PVM pVM, uint32_t cPages);
    256 GMMR3DECL(int)  GMMR3MapUnmapChunk(PVM pVM, uint32_t idChunkMap, uint32_t idChunkUnmap, PRTR3PTR ppvR3);
    257 GMMR3DECL(int)  GMMR3SeedChunk(PVM pVM, RTR3PTR pvR3);
    258 
    259 
    260252
    261253/**
     
    383375
    384376
     377#ifdef IN_RING3
     378/** @defgroup grp_gmm_r3    The Global Memory Manager Ring-3 API Wrappers
     379 * @ingroup grp_gmm
     380 * @{
     381 */
     382GMMR3DECL(int)  GMMR3InitialReservation(PVM pVM, uint64_t cBasePages, uint32_t cShadowPages, uint32_t cFixedPages,
     383                                        GMMOCPOLICY enmPolicy, GMMPRIORITY enmPriority);
     384GMMR3DECL(int)  GMMR3UpdateReservation(PVM pVM, uint64_t cBasePages, uint32_t cShadowPages, uint32_t cFixedPages);
     385GMMR3DECL(int)  GMMR3AllocatePagesPrepare(PVM pVM, PGMMALLOCATEPAGESREQ *ppReq, uint32_t cPages, GMMACCOUNT enmAccount);
     386GMMR3DECL(int)  GMMR3AllocatePagesPerform(PVM pVM, PGMMALLOCATEPAGESREQ pReq);
     387GMMR3DECL(void) GMMR3AllocatePagesCleanup(PGMMALLOCATEPAGESREQ pReq);
     388GMMR3DECL(int)  GMMR3DeflatedBalloon(PVM pVM, uint32_t cPages);
     389GMMR3DECL(int)  GMMR3MapUnmapChunk(PVM pVM, uint32_t idChunkMap, uint32_t idChunkUnmap, PRTR3PTR ppvR3);
     390GMMR3DECL(int)  GMMR3SeedChunk(PVM pVM, RTR3PTR pvR3);
    385391/** @} */
     392#endif /* IN_RING3 */
     393
     394/** @} */
    386395
    387396__END_DECLS
  • trunk/src/VBox/VMM/GMM.cpp

    r6581 r6836  
    2525#include <VBox/sup.h>
    2626#include <VBox/err.h>
     27#include <VBox/param.h>
     28
     29#include <iprt/mem.h>
    2730
    2831
     
    6063
    6164
    62 #if 0 /* impractical */
    63 GMMR3DECL(int)  GMMR3AllocatePages(PVM pVM, uint32_t cPages, PGMMPAGEDESC paPages, GMMACCOUNT enmAccount)
     65/**
     66 * Prepares a GMMR0AllocatePages request.
     67 */
     68GMMR3DECL(int) GMMR3AllocatePagesPrepare(PVM pVM, PGMMALLOCATEPAGESREQ *ppReq, uint32_t cPages, GMMACCOUNT enmAccount)
    6469{
    65     GMMALLOCATEPAGESREQ Req;
    66     Req.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC;
    67     Req.Hdr.cbReq = sizeof(Req);
     70    uint32_t cb = RT_OFFSETOF(GMMALLOCATEPAGESREQ, aPages[cPages]);
     71    PGMMALLOCATEPAGESREQ pReq = (PGMMALLOCATEPAGESREQ)RTMemTmpAllocZ(cb);
     72    if (!pReq)
     73        return VERR_NO_TMP_MEMORY;
    6874
    69     return SUPCallVMMR0Ex(pVM->pVMR0, VMMR0_DO_GMM_ALLOCATE_PAGES, 0, &Req.Hdr);
     75    pReq->Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC;
     76    pReq->Hdr.cbReq = cb;
     77    pReq->enmAccount = enmAccount;
     78    pReq->cPages = cPages;
     79    NOREF(pVM);
     80    return VINF_SUCCESS;
    7081}
    71 #endif
     82
     83
     84/**
     85 * Performs a GMMR0AllocatePages request.
     86 * This will call VMSetError on failure.
     87 *
     88 * @returns VBox status code.
     89 * @param   pVM         Pointer to the shared VM structure.
     90 * @param   pReq        Pointer to the request (returned by GMMR3AllocatePagesPrepare).
     91 */
     92GMMR3DECL(int) GMMR3AllocatePagesPerform(PVM pVM, PGMMALLOCATEPAGESREQ pReq)
     93{
     94    for (unsigned i = 0; ; i++)
     95    {
     96        int rc = SUPCallVMMR0Ex(pVM->pVMR0, VMMR0_DO_GMM_ALLOCATE_PAGES, 0, &pReq->Hdr);
     97        if (RT_SUCCESS(rc))
     98            return rc;
     99        if (rc != VERR_GMM_SEED_ME)
     100            return VMSetError(pVM, rc, RT_SRC_POS,
     101                              N_("GMMR0AllocatePages failed to allocate %u pages"),
     102                              pReq->cPages);
     103        Assert(i < pReq->cPages);
     104
     105        /*
     106         * Seed another chunk.
     107         */
     108        void *pvChunk;
     109        rc = SUPPageAlloc(GMM_CHUNK_SIZE >> PAGE_SHIFT, &pvChunk);
     110        if (VBOX_FAILURE(rc))
     111            return VMSetError(pVM, rc, RT_SRC_POS,
     112                              N_("Out of memory (SUPPageAlloc) seeding a %u pages allocation request"),
     113                              pReq->cPages);
     114
     115        rc = SUPCallVMMR0Ex(pVM->pVMR0, VMMR0_DO_GMM_SEED_CHUNK, (uintptr_t)pvChunk, NULL);
     116        if (RT_FAILURE(rc))
     117            return VMSetError(pVM, rc, RT_SRC_POS, N_("GMM seeding failed"));
     118    }
     119}
     120
     121
     122/**
     123 * Cleans up a GMMR0AllocatePages request.
     124 * @param   pReq        Pointer to the request (returned by GMMR3AllocatePagesPrepare).
     125 */
     126GMMR3DECL(void) GMMR3AllocatePagesCleanup(PGMMALLOCATEPAGESREQ pReq)
     127{
     128    RTMemTmpFree(pReq);
     129}
    72130
    73131
Note: See TracChangeset for help on using the changeset viewer.

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