VirtualBox

Changeset 5026

Show
Ignore:
Timestamp:
09/25/07 17:49:09 (1 year ago)
Author:
vboxsync
Message:

GVM -> GVMM.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/include/VBox/gmm.h

    r5017 r5026  
    11/** @file 
    2  * GMM - Global Memory Manager. 
     2 * GMM - The Global Memory Manager. 
    33 */ 
    44 
     
    2121#include <VBox/types.h> 
    2222 
    23 #include "gvm.h" 
     23#include "gvmm.h" 
    2424 
    2525/** @defgroup   grp_gmm     GMM - The Global Memory Manager 
     
    3535 * @param   type    The return type of the function declaration. 
    3636 */ 
    37 #ifdef IN_GVM_R0 
    38 # define GVMR0DECL(type)    DECLEXPORT(type) VBOXCALL 
     37#ifdef IN_GMM_R0 
     38# define GMMR0DECL(type)    DECLEXPORT(type) VBOXCALL 
    3939#else 
    40 # define GVMR0DECL(type)    DECLIMPORT(type) VBOXCALL 
     40# define GMMR0DECL(type)    DECLIMPORT(type) VBOXCALL 
    4141#endif 
    4242 
  • trunk/include/VBox/gvmm.h

    r4971 r5026  
    11/* $Id$ */ 
    22/** @file 
    3  * GVM - Global VM Manager. 
     3 * GVMM - The Global VM Manager. 
    44 */ 
    55 
     
    1717 */ 
    1818 
    19 #ifndef ___VBox_gvm_h 
    20 #define ___VBox_gvm_h 
     19#ifndef ___VBox_gvmm_h 
     20#define ___VBox_gvmm_h 
    2121 
    2222#include <VBox/cdefs.h> 
    2323#include <VBox/types.h> 
    2424 
    25 /** @defgroup grp_GVM   GVM - Global VM Manager. 
     25/** @defgroup grp_GVMM  GVMM - The Global VM Manager. 
    2626 * @{ 
    2727 */ 
    2828 
    29 /** @def IN_GVM_R0 
     29/** @def IN_GVMM_R0 
    3030 * Used to indicate whether we're inside the same link module as the ring 0 
    3131 * part of the Global VM Manager or not. 
    3232 */ 
    33 /** @def GVMR0DECL 
     33/** @def GVMMR0DECL 
    3434 * Ring 0 VM export or import declaration. 
    3535 * @param   type    The return type of the function declaration. 
    3636 */ 
    37 #ifdef IN_GVM_R0 
    38 # define GVMR0DECL(type)    DECLEXPORT(type) VBOXCALL 
     37#ifdef IN_GVMM_R0 
     38# define GVMMR0DECL(type)    DECLEXPORT(type) VBOXCALL 
    3939#else 
    40 # define GVMR0DECL(type)    DECLIMPORT(type) VBOXCALL 
     40# define GVMMR0DECL(type)    DECLIMPORT(type) VBOXCALL 
    4141#endif 
    4242 
     
    4646#define NIL_GVM_HANDLE 0 
    4747 
    48 GVMR0DECL(int)  GVMR0Init(void); 
    49 GVMR0DECL(void) GVMR0Term(void); 
    50 GVMR0DECL(int)  GVMR0RegisterVM(PVM pVM); 
    51 GVMR0DECL(int)  GVMR0DeregisterVM(PVM pVM); 
    52 GVMR0DECL(PVM)  GVMR0ByEMT(RTNATIVETHREAD hEMT); 
    53 GVMR0DECL(PVM)  GVMR0ByHandle(uint32_t hGVM); 
     48GVMMR0DECL(int)  GVMMR0Init(void); 
     49GVMMR0DECL(void) GVMMR0Term(void); 
     50GVMMR0DECL(int)  GVMMR0RegisterVM(PVM pVM); 
     51GVMMR0DECL(int)  GVMMR0DeregisterVM(PVM pVM); 
     52GVMMR0DECL(PGVM) GVMMR0ByHandle(uint32_t hGVM); 
     53GVMMR0DECL(PVM)  GVMMR0GetVMByEMT(RTNATIVETHREAD hEMT); 
     54GVMMR0DECL(PVM)  GVMMR0GetVMByHandle(uint32_t hGVM); 
    5455 
    5556 
    5657/** @} */ 
    5758 
    58 #endif  
     59#endif 
     60 
  • trunk/include/VBox/types.h

    r4787 r5026  
    8080/** Pointer to a VM - GC Ptr. */ 
    8181typedef GCPTRTYPE(struct VM *)  PVMGC; 
     82 
     83/** Pointer to a the ring-0 (global) VM structure. */ 
     84typedef R0PTRTYPE(struct GVM *) PGVM; 
    8285 
    8386 
  • trunk/src/VBox/VMM/Makefile.kmk

    r4975 r5026  
    327327        VMMR0/CPUMR0.cpp \ 
    328328        VMMR0/DBGFR0.cpp \ 
    329         VMMR0/GVMR0.cpp \ 
     329        VMMR0/GVMMR0.cpp \ 
    330330        VMMR0/HWACCMR0.cpp \ 
    331331        VMMR0/HWACCMR0A.asm \ 
  • trunk/src/VBox/VMM/VMMR0/GVMMR0.cpp

    r4980 r5026  
    11/* $Id$ */ 
    22/** @file 
    3  * GVM - Global VM Manager. 
     3 * GVMM - Global VM Manager. 
    44 */ 
    55 
     
    1818 
    1919 
    20 /** @page pg_GVM    GVM - Global VM Manager 
     20/** @page pg_GVMM   GVMM - The Global VM Manager 
    2121 * 
    2222 * The Global VM Manager lives in ring-0. It's main function at the moment 
    23  * is to manage a list of all running VMs and assign unique identifiers to 
    24  * each of them (so GMM can track page owners). The idea for the future is 
    25  * to add an idle priority kernel thread that can take care of tasks like 
    26  * page sharing. 
    27  * 
    28  * The GVM will create a ring-0 object for each VM when it's registered, this 
    29  * is both for session cleanup purposes and for having a point where it's 
    30  * possible to implement usage polices later (in SUPR0ObjRegister). 
     23 * is to manage a list of all running VMs, keep a ring-0 only structure (GVM) 
     24 * for each of them, and assign them unique identifiers (so GMM can track 
     25 * page owners). The idea for the future is to add an idle priority kernel 
     26 * thread that can take care of tasks like page sharing. 
     27 * 
     28 * The GVMM will create a ring-0 object for each VM when it's registered, 
     29 * this is both for session cleanup purposes and for having a point where 
     30 * it's possible to implement usage polices later (in SUPR0ObjRegister). 
    3131 */ 
    3232 
     
    3636*******************************************************************************/ 
    3737#define LOG_GROUP LOG_GROUP_GVM 
    38 #include <VBox/gvm.h> 
    39 /* #include "GVMInternal.h" */ 
     38#include <VBox/gvmm.h> 
     39/* #include "GVMMInternal.h" */ 
    4040#include <VBox/vm.h> 
    4141#include <VBox/err.h> 
     
    6363    /** Whether to free the VM structure or not. */ 
    6464    bool                fFreeVM; 
    65     /** The ring-0 mapping of the VM instance data. */ 
     65    /** The pointer to the ring-0 only (aka global) VM structure. */ 
     66    PGVM                pGVM; 
     67    /** The ring-0 mapping of the shared VM instance data. */ 
    6668    PVM                 pVM; 
    6769    /** The virtual machine object. */ 
     
    7779 
    7880/** 
    79  * The GVM instance data. 
    80  */ 
    81 typedef struct 
     81 * The GVMM instance data. 
     82 */ 
     83typedef struct GVMM 
    8284{ 
    8385    /** Eyecatcher / magic. */ 
     
    9395     * The first entry is unused as it represents the NIL handle. */ 
    9496    GVMHANDLE           aHandles[128]; 
    95 } GVM
    96 /** Pointer to the GVM instance data. */ 
    97 typedef GVM *PGVM; 
    98  
    99 /** The GVM::u32Magic value (Charlie Haden). */ 
    100 #define GVM_MAGIC       0x19370806 
     97} GVMM
     98/** Pointer to the GVMM instance data. */ 
     99typedef GVMM *PGVMM; 
     100 
     101/** The GVMM::u32Magic value (Charlie Haden). */ 
     102#define GVMM_MAGIC      0x19370806 
    101103 
    102104 
     
    105107*   Global Variables                                                           * 
    106108*******************************************************************************/ 
    107 /** Pointer to the GVM instance data. 
     109/** Pointer to the GVMM instance data. 
    108110 * (Just my general dislike for global variables.) */ 
    109 static PGVM g_pGVM = NULL; 
     111static PGVMM g_pGVMM = NULL; 
    110112 
    111113 
     
    113115*   Internal Functions                                                         * 
    114116*******************************************************************************/ 
    115 static DECLCALLBACK(void) gvmR0HandleObjDestructor(void *pvObj, void *pvGVM, void *pvHandle); 
    116  
    117  
    118 /** 
    119  * Initializes the GVM
     117static DECLCALLBACK(void) gvmmR0HandleObjDestructor(void *pvObj, void *pvGVMM, void *pvHandle); 
     118 
     119 
     120/** 
     121 * Initializes the GVMM
    120122 * 
    121123 * This is called while owninng the loader sempahore (see supdrvIOCtl_LdrLoad()). 
     
    123125 * @returns VBox status code. 
    124126 */ 
    125 GVMR0DECL(int) GVMR0Init(void) 
    126 { 
    127     SUPR0Printf("GVMR0Init:\n"); 
     127GVMMR0DECL(int) GVMMR0Init(void) 
     128{ 
     129    SUPR0Printf("GVMMR0Init:\n"); 
    128130 
    129131    /* 
    130132     * Allocate and initialize the instance data. 
    131133     */ 
    132     PGVM pGVM = (PGVM)RTMemAllocZ(sizeof(*pGVM)); 
    133     if (!pGVM
     134    PGVMM pGVMM = (PGVMM)RTMemAllocZ(sizeof(*pGVMM)); 
     135    if (!pGVMM
    134136        return VERR_NO_MEMORY; 
    135     int rc = RTSemFastMutexCreate(&pGVM->Lock); 
     137    int rc = RTSemFastMutexCreate(&pGVMM->Lock); 
    136138    if (RT_SUCCESS(rc)) 
    137139    { 
    138         pGVM->u32Magic = GVM_MAGIC; 
    139         pGVM->iUsedHead = 0; 
    140         pGVM->iFreeHead = 1; 
     140        pGVMM->u32Magic = GVMM_MAGIC; 
     141        pGVMM->iUsedHead = 0; 
     142        pGVMM->iFreeHead = 1; 
    141143 
    142144        /* the nil handle */ 
    143         pGVM->aHandles[0].iSelf = 0; 
    144         pGVM->aHandles[0].iNext = 0; 
     145        pGVMM->aHandles[0].iSelf = 0; 
     146        pGVMM->aHandles[0].iNext = 0; 
    145147 
    146148        /* the tail */ 
    147         unsigned i = RT_ELEMENTS(pGVM->aHandles); 
    148         pGVM->aHandles[i].iSelf = i; 
    149         pGVM->aHandles[i].iNext = 0; /* nil */ 
     149        unsigned i = RT_ELEMENTS(pGVMM->aHandles); 
     150        pGVMM->aHandles[i].iSelf = i; 
     151        pGVMM->aHandles[i].iNext = 0; /* nil */ 
    150152 
    151153        /* the rest */ 
    152154        while (i-- > 1) 
    153155        { 
    154             pGVM->aHandles[i].iSelf = i; 
    155             pGVM->aHandles[i].iNext = i + 1; 
     156            pGVMM->aHandles[i].iSelf = i; 
     157            pGVMM->aHandles[i].iNext = i + 1; 
    156158        } 
    157159 
    158         g_pGVM = pGVM; 
    159         SUPR0Printf("GVMR0Init: pGVM=%p\n", pGVM); 
     160        g_pGVMM = pGVMM; 
     161        SUPR0Printf("GVMMR0Init: pGVMM=%p\n", pGVMM); 
    160162        return VINF_SUCCESS; 
    161163    } 
    162164 
    163     RTMemFree(pGVM); 
     165    RTMemFree(pGVMM); 
    164166    return rc; 
    165167} 
     
    173175 * registered at this point. 
    174176 */ 
    175 GVMR0DECL(void) GVMR0Term(void) 
    176 { 
    177     SUPR0Printf("GVMR0Term:\n"); 
    178  
    179     PGVM pGVM = g_pGVM; 
    180     g_pGVM = NULL; 
    181     if (RT_UNLIKELY(!VALID_PTR(pGVM))) 
    182     { 
    183         SUPR0Printf("GVMR0Term: pGVM=%p\n", pGVM); 
     177GVMMR0DECL(void) GVMMR0Term(void) 
     178{ 
     179    SUPR0Printf("GVMMR0Term:\n"); 
     180 
     181    PGVMM pGVMM = g_pGVMM; 
     182    g_pGVMM = NULL; 
     183    if (RT_UNLIKELY(!VALID_PTR(pGVMM))) 
     184    { 
     185        SUPR0Printf("GVMMR0Term: pGVMM=%p\n", pGVMM); 
    184186        return; 
    185187    } 
    186188 
    187     RTSemFastMutexDestroy(pGVM->Lock); 
    188     pGVM->Lock = NIL_RTSEMFASTMUTEX; 
    189     pGVM->u32Magic++; 
    190     pGVM->iFreeHead = 0; 
    191     if (pGVM->iUsedHead) 
    192     { 
    193         SUPR0Printf("GVMR0Term: iUsedHead=%#x!\n", pGVM->iUsedHead); 
    194         pGVM->iUsedHead = 0; 
    195     } 
    196  
    197     RTMemFree(pGVM); 
     189    RTSemFastMutexDestroy(pGVMM->Lock); 
     190    pGVMM->Lock = NIL_RTSEMFASTMUTEX; 
     191    pGVMM->u32Magic++; 
     192    pGVMM->iFreeHead = 0; 
     193    if (pGVMM->iUsedHead) 
     194    { 
     195        SUPR0Printf("GVMMR0Term: iUsedHead=%#x!\n", pGVMM->iUsedHead); 
     196        pGVMM->iUsedHead = 0; 
     197    } 
     198 
     199    RTMemFree(pGVMM); 
    198200} 
    199201 
     
    209211 * @thread  EMT. 
    210212 */ 
    211 GVMR0DECL(int) GVMR0CreateVM(PSUPDRVSESSION pSession, PVM *ppVM) 
    212 { 
    213     SUPR0Printf("GVMR0CreateVM: pSession=%p\n", pSession); 
    214     PGVM pGVM = g_pGVM; 
    215     AssertPtrReturn(pGVM, VERR_INTERNAL_ERROR); 
     213GVMMR0DECL(int) GVMMR0CreateVM(PSUPDRVSESSION pSession, PVM *ppVM) 
     214{ 
     215    SUPR0Printf("GVMMR0CreateVM: pSession=%p\n", pSession); 
     216    PGVMM pGVMM = g_pGVMM; 
     217    AssertPtrReturn(pGVMM, VERR_INTERNAL_ERROR); 
    216218 
    217219    AssertPtrReturn(ppVM, VERR_INVALID_POINTER); 
     
    224226     * The whole allocation process is protected by the lock. 
    225227     */ 
    226     int rc = RTSemFastMutexRequest(pGVM->Lock); 
     228    int rc = RTSemFastMutexRequest(pGVMM->Lock); 
    227229    AssertRCReturn(rc, rc); 
    228230 
     
    230232     * Allocate a handle first so we don't waste resources unnecessarily. 
    231233     */ 
    232     uint16_t iHandle = pGVM->iFreeHead; 
     234    uint16_t iHandle = pGVMM->iFreeHead; 
    233235    if (iHandle) 
    234236    { 
    235         PGVMHANDLE pHandle = &pGVM->aHandles[iHandle]; 
     237        PGVMMHANDLE pHandle = &pGVMM->aHandles[iHandle]; 
    236238 
    237239        /* consistency checks, a bit paranoid as always. */ 
    238240        if (    !pHandle->pVM 
     241            /*&&  !pHandle->pGVM */ 
    239242            &&  !pHandle->pvObj 
    240243            &&  pHandle->iSelf == iHandle) 
    241244        { 
    242             pHandle->pvObj = SUPR0ObjRegister(pSession, SUPDRVOBJTYPE_VM, gvmR0HandleObjDestructor, pGVM, pHandle); 
     245            pHandle->pvObj = SUPR0ObjRegister(pSession, SUPDRVOBJTYPE_VM, gvmmR0HandleObjDestructor, pGVMM, pHandle); 
    243246            if (pHandle->pvObj) 
    244247            { 
     
    246249                 * Move the handle from the free to used list and perform permission checks. 
    247250                 */ 
    248                 pGVM->iFreeHead = pHandle->iNext; 
    249                 pHandle->iNext = pGVM->iUsedHead; 
    250                 pGVM->iUsedHead = iHandle; 
     251                pGVMM->iFreeHead = pHandle->iNext; 
     252                pHandle->iNext = pGVMM->iUsedHead; 
     253                pGVMM->iUsedHead = iHandle; 
    251254 
    252255                pHandle->fFreeVM = true; 
    253256                pHandle->pVM = NULL; 
     257                pHandle->pGVM = NULL; /* to be allocated */ 
    254258                pHandle->pSession = pSession; 
    255259                pHandle->hEMT = hEMT; 
     
    279283                            pVM->pSession = pSession; 
    280284                            pVM->hSelf = iHandle; 
    281                             RTSemFastMutexRelease(pGVM->Lock); 
     285                            RTSemFastMutexRelease(pGVMM->Lock); 
    282286 
    283287                            *ppVM = pVM; 
    284                             SUPR0Printf("GVMR0CreateVM: pVM=%p pVMR3=%p\n", pVM, pVMR3); 
     288                            SUPR0Printf("GVMMR0CreateVM: pVM=%p pVMR3=%p\n", pVM, pVMR3); 
    285289                            return VINF_SUCCESS; 
    286290                        } 
     
    292296 
    293297                /* 
    294                  * The handle will be freed by gvmR0HandleObjDestructor as we release the 
     298                 * The handle will be freed by gvmmR0HandleObjDestructor as we release the 
    295299                 * object reference here. A little extra mess because of non-recursive lock. 
    296300                 */ 
    297301                void *pvObj = pHandle->pvObj; 
    298302                pHandle->pvObj = NULL; 
    299                 RTSemFastMutexRelease(pGVM->Lock); 
     303                RTSemFastMutexRelease(pGVMM->Lock); 
    300304 
    301305                SUPR0ObjRelease(pvObj, pSession); 
    302306 
    303                 SUPR0Printf("GVMR0CreateVM: failed, rc=%d\n", rc); 
     307                SUPR0Printf("GVMMR0CreateVM: failed, rc=%d\n", rc); 
    304308                return rc; 
    305309            } 
     
    313317        rc = VERR_GVM_TOO_MANY_VMS; 
    314318 
    315     RTSemFastMutexRelease(pGVM->Lock); 
     319    RTSemFastMutexRelease(pGVMM->Lock); 
    316320    return rc; 
    317321} 
     
    327331 * @thread  EMT. 
    328332 */ 
    329 GVMR0DECL(int) GVMR0DestroyVM(PVM pVM) 
    330 { 
    331     SUPR0Printf("GVMR0DestroyVM: pVM=%p\n", pVM); 
    332  
    333     PGVM pGVM = g_pGVM; 
    334     AssertPtrReturn(pGVM, VERR_INTERNAL_ERROR); 
     333GVMMR0DECL(int) GVMMR0DestroyVM(PVM pVM) 
     334{ 
     335    SUPR0Printf("GVMMR0DestroyVM: pVM=%p\n", pVM); 
     336 
     337    PGVMM pGVMM = g_pGVMM; 
     338    AssertPtrReturn(pGVMM, VERR_INTERNAL_ERROR); 
    335339 
    336340    /* 
     
    343347    uint32_t hGVM = pVM->hSelf; 
    344348    AssertReturn(hGVM != NIL_GVM_HANDLE, VERR_INVALID_HANDLE); 
    345     AssertReturn(hGVM < RT_ELEMENTS(pGVM->aHandles), VERR_INVALID_HANDLE); 
    346  
    347     PGVMHANDLE pHandle = &pGVM->aHandles[hGVM]; 
     349    AssertReturn(hGVM < RT_ELEMENTS(pGVMM->aHandles), VERR_INVALID_HANDLE); 
     350 
     351    PGVMHANDLE pHandle = &pGVMM->aHandles[hGVM]; 
    348352    AssertReturn(pHandle->hEMT != NIL_RTNATIVETHREAD, VERR_WRONG_ORDER); 
    349353    AssertReturn(pHandle->pVM == pVM, VERR_NOT_OWNER); 
     
    357361     * race us as we leave the lock and call SUPR0ObjRelease. 
    358362     */ 
    359     int rc = RTSemFastMutexRequest(pGVM->Lock); 
     363    int rc = RTSemFastMutexRequest(pGVMM->Lock); 
    360364    AssertRC(rc); 
    361365 
     
    367371        void *pvObj = pHandle->pvObj; 
    368372        pHandle->pvObj = NULL; 
    369         RTSemFastMutexRelease(pGVM->Lock); 
     373        RTSemFastMutexRelease(pGVMM->Lock); 
    370374 
    371375        SUPR0ObjRelease(pvObj, pVM->pSession); 
     
    373377    else 
    374378    { 
    375         RTSemFastMutexRelease(pGVM->Lock); 
     379        RTSemFastMutexRelease(pGVMM->Lock); 
    376380        rc = VERR_INTERNAL_ERROR; 
    377381    } 
     
    394398 * @thread  EMT. 
    395399 */ 
    396 GVMR0DECL(int) GVMR0RegisterVM(PVM pVM) 
    397 { 
    398     SUPR0Printf("GVMR0RegisterVM: pVM=%p\n", pVM); 
    399     PGVM pGVM = g_pGVM; 
    400     AssertPtrReturn(pGVM, VERR_INTERNAL_ERROR); 
     400GVMMR0DECL(int) GVMMR0RegisterVM(PVM pVM) 
     401{ 
     402    SUPR0Printf("GVMMR0RegisterVM: pVM=%p\n", pVM); 
     403    PGVMM pGVMM = g_pGVMM; 
     404    AssertPtrReturn(pGVMM, VERR_INTERNAL_ERROR); 
    401405 
    402406    /* 
     
    413417     * Take the lock and call the worker function. 
    414418     */ 
    415     int rc = RTSemFastMutexRequest(pGVM->Lock); 
     419    int rc = RTSemFastMutexRequest(pGVMM->Lock); 
    416420    AssertRCReturn(rc, rc); 
    417421 
     
    419423     * Allocate a handle. 
    420424     */ 
    421     uint16_t iHandle = pGVM->iFreeHead; 
     425    uint16_t iHandle = pGVMM->iFreeHead; 
    422426    if (iHandle) 
    423427    { 
    424         PGVMHANDLE pHandle = &pGVM->aHandles[iHandle]; 
     428        PGVMHANDLE pHandle = &pGVMM->aHandles[iHandle]; 
    425429 
    426430        /* consistency checks, a bit paranoid as always. */ 
     
    429433            &&  pHandle->iSelf == iHandle) 
    430434        { 
    431             pHandle->pvObj = SUPR0ObjRegister(pVM->pSession, SUPDRVOBJTYPE_VM, gvmR0HandleObjDestructor, pGVM, pHandle); 
     435            pHandle->pvObj = SUPR0ObjRegister(pVM->pSession, SUPDRVOBJTYPE_VM, gvmmR0HandleObjDestructor, pGVMM, pHandle); 
    432436            if (pHandle->pvObj) 
    433437            { 
     
    436440                 * perform permission checks. 
    437441                 */ 
    438                 pGVM->iFreeHead = pHandle->iNext; 
    439                 pHandle->iNext = pGVM->iUsedHead; 
    440                 pGVM->iUsedHead = iHandle; 
     442                pGVMM->iFreeHead = pHandle->iNext; 
     443                pHandle->iNext = pGVMM->iUsedHead; 
     444                pGVMM->iUsedHead = iHandle; 
    441445 
    442446                pHandle->fFreeVM = false; 
    443447                pHandle->pVM = pVM; 
     448                pHandle->pGVM = NULL; /** @todo to be allocated */ 
    444449                pHandle->pSession = pVM->pSession; 
    445450                pHandle->hEMT = hEMT; 
     
    449454                { 
    450455                    pVM->hSelf = iHandle; 
    451                     RTSemFastMutexRelease(pGVM->Lock); 
     456                    RTSemFastMutexRelease(pGVMM->Lock); 
    452457                } 
    453458                else 
     
    455460                    /* 
    456461                     * The user wasn't permitted to create this VM. 
    457                      * Must use gvmR0HandleObjDestructor via SUPR0ObjRelease to do the 
     462                     * Must use gvmmR0HandleObjDestructor via SUPR0ObjRelease to do the 
    458463                     * cleanups. The lock isn't recursive, thus the extra mess. 
    459464                     */ 
    460465                    void *pvObj = pHandle->pvObj; 
    461466                    pHandle->pvObj = NULL; 
    462                     RTSemFastMutexRelease(pGVM->Lock); 
     467                    RTSemFastMutexRelease(pGVMM->Lock); 
    463468 
    464469                    SUPR0ObjRelease(pvObj, pVM->pSession); 
    465470                } 
    466471                if (RT_FAILURE(rc)) 
    467                     SUPR0Printf("GVMR0RegisterVM: permission denied, rc=%d\n", rc); 
     472                    SUPR0Printf("GVMMR0RegisterVM: permission denied, rc=%d\n", rc); 
    468473                return rc; 
    469474            } 
     
    477482        rc = VERR_GVM_TOO_MANY_VMS; 
    478483 
    479     RTSemFastMutexRelease(pGVM->Lock); 
    480     SUPR0Printf("GVMR0RegisterVM: failed, rc=%d, iHandle=%d\n", rc, iHandle); 
     484    RTSemFastMutexRelease(pGVMM->Lock); 
     485    SUPR0Printf("GVMMR0RegisterVM: failed, rc=%d, iHandle=%d\n", rc, iHandle); 
    481486    return rc; 
    482487} 
     
    484489 
    485490/** 
    486  * Deregister a VM previously registered using the GVMR0RegisterVM API. 
     491 * Deregister a VM previously registered using the GVMMR0RegisterVM API. 
    487492 * 
    488493 * 
     
    491496 * @thread  EMT. 
    492497 */ 
    493 GVMR0DECL(int) GVMR0DeregisterVM(PVM pVM) 
    494 { 
    495     SUPR0Printf("GVMR0DeregisterVM: pVM=%p\n", pVM); 
    496     return GVMR0DestroyVM(pVM); 
     498GVMMR0DECL(int) GVMMR0DeregisterVM(PVM pVM) 
     499{ 
     500    SUPR0Printf("GVMMR0DeregisterVM: pVM=%p\n", pVM); 
     501    return GVMMR0DestroyVM(pVM); 
    497502} 
    498503#endif /* ... */ 
     
    502507 * Handle destructor. 
    503508 * 
    504  * @param   pvGVM       The GVM instance pointer. 
     509 * @param   pvGVMM       The GVM instance pointer. 
    505510 * @param   pvHandle    The handle pointer. 
    506511 */ 
    507 static DECLCALLBACK(void) gvmR0HandleObjDestructor(void *pvObj, void *pvGVM, void *pvHandle) 
    508 { 
    509     SUPR0Printf("gvmR0HandleObjDestructor: %p %p %p\n", pvObj, pvGVM, pvHandle); 
     512static DECLCALLBACK(void) gvmmR0HandleObjDestructor(void *pvObj, void *pvGVMM, void *pvHandle) 
     513{ 
     514    SUPR0Printf("gvmmR0HandleObjDestructor: %p %p %p\n", pvObj, pvGVMM, pvHandle); 
    510515 
    511516    /* 
     
    514519    PGVMHANDLE pHandle = (PGVMHANDLE)pvHandle; 
    515520    AssertPtr(pHandle); 
    516     PGVM pGVM = (PGVM)pvGVM; 
    517     Assert(pGVM == g_pGVM); 
    518     const uint16_t iHandle = pHandle - &pGVM->aHandles[0]; 
     521    PGVMM pGVMM = (PGVMM)pvGVMM; 
     522    Assert(pGVMM == g_pGVMM); 
     523    const uint16_t iHandle = pHandle - &pGVMM->aHandles[0]; 
    519524    if (    !iHandle 
    520         ||  iHandle >= RT_ELEMENTS(pGVM->aHandles) 
     525        ||  iHandle >= RT_ELEMENTS(pGVMM->aHandles) 
    521526        ||  iHandle != pHandle->iSelf) 
    522527    { 
     
    525530    } 
    526531 
    527     int rc = RTSemFastMutexRequest(pGVM->Lock); 
     532    int rc = RTSemFastMutexRequest(pGVMM->Lock); 
    528533    AssertRC(rc); 
    529534 
     
    531536     * This is a tad slow but a doubly linked list is too much hazzle. 
    532537     */ 
    533     if (RT_UNLIKELY(pHandle->iNext >= RT_ELEMENTS(pGVM->aHandles))) 
     538    if (RT_UNLIKELY(pHandle->iNext >= RT_ELEMENTS(pGVMM->aHandles))) 
    534539    { 
    535540        SUPR0Printf("GVM: used list index %d is out of range!\n", pHandle->iNext); 
    536         RTSemFastMutexRelease(pGVM->Lock); 
     541        RTSemFastMutexRelease(pGVMM->Lock); 
    537542        return; 
    538543    } 
    539544 
    540     if (pGVM->iUsedHead == iHandle) 
    541         pGVM->iUsedHead = pHandle->iNext; 
     545    if (pGVMM->iUsedHead == iHandle) 
     546        pGVMM->iUsedHead = pHandle->iNext; 
    542547    else 
    543548    { 
    544         uint16_t iPrev = pGVM->iUsedHead; 
    545         int c = RT_ELEMENTS(pGVM->aHandles) + 2; 
     549        uint16_t iPrev = pGVMM->iUsedHead; 
     550        int c = RT_ELEMENTS(pGVMM->aHandles) + 2; 
    546551        while (!iPrev) 
    547552        { 
    548             if (RT_UNLIKELY(iPrev >= RT_ELEMENTS(pGVM->aHandles))) 
     553            if (RT_UNLIKELY(iPrev >= RT_ELEMENTS(pGVMM->aHandles))) 
    549554            { 
    550555                SUPR0Printf("GVM: used list index %d is out of range!\n"); 
    551                 RTSemFastMutexRelease(pGVM->Lock); 
     556                RTSemFastMutexRelease(pGVMM->Lock); 
    552557                return; 
    553558            } 
     
    558563            } 
    559564 
    560             if (pGVM->aHandles[iPrev].iNext == iHandle) 
     565            if (pGVMM->aHandles[iPrev].iNext == iHandle) 
    561566                break; 
    562             iPrev = pGVM->aHandles[iPrev].iNext; 
     567            iPrev = pGVMM->aHandles[iPrev].iNext; 
    563568        } 
    564569        if (!iPrev) 
    565570        { 
    566571            SUPR0Printf("GVM: can't find the handle previous previous of %d!\n", pHandle->iSelf); 
    567             RTSemFastMutexRelease(pGVM->Lock); 
     572            RTSemFastMutexRelease(pGVMM->Lock); 
    568573            return; 
    569574        } 
    570575 
    571         pGVM->aHandles[iPrev].iNext = pHandle->iNext; 
     576        pGVMM->aHandles[iPrev].iNext = pHandle->iNext; 
    572577    } 
    573578    pHandle->iNext = 0; 
     
    595600     * Free the handle. 
    596601     */ 
    597     pHandle->iNext = pGVM->iFreeHead; 
     602    pHandle->iNext = pGVMM->iFreeHead; 
    598603    pHandle->fFreeVM = false; 
    599     pGVM->iFreeHead = iHandle; 
     604    pGVMM->iFreeHead = iHandle; 
    600605    ASMAtomicXchgPtr((void * volatile *)&pHandle->pVM, NULL); 
    601606    ASMAtomicXchgPtr((void * volatile *)&pHandle->pvObj, NULL); 
     
    603608    ASMAtomicXchgSize(&pHandle->hEMT, NIL_RTNATIVETHREAD); 
    604609 
    605     RTSemFastMutexRelease(pGVM->Lock); 
    606     SUPR0Printf("gvmR0HandleObjDestructor: returns\n"); 
     610    RTSemFastMutexRelease(pGVMM->Lock); 
     611    SUPR0Printf("gvmmR0HandleObjDestructor: returns\n"); 
     612
     613 
     614 
     615/** 
     616 * Lookup a GVM pointer by its handle. 
     617 * 
     618 * @returns The GVM pointer on success, NULL on failure. 
     619 * @param   hGVM    The global VM handle. Asserts on bad handle. 
     620 */ 
     621GVMMR0DECL(PGVM) GVMMR0ByHandle(uint32_t hGVM) 
     622
     623    PGVMM pGVMM = g_pGVMM; 
     624    AssertPtrReturn(pGVMM, NULL); 
     625 
     626    /* 
     627     * Validate. 
     628     */ 
     629    AssertReturn(hGVM != NIL_GVM_HANDLE, NULL); 
     630    AssertReturn(hGVM < RT_ELEMENTS(pGVMM->aHandles), NULL); 
     631 
     632    /* 
     633     * Look it up. 
     634     */ 
     635    AssertReturn(VALID_PTR(pGVMM->aHandles[hGVM].pvObj), NULL); 
     636    AssertReturn(pGVMM->aHandles[hGVM].hEMT != NIL_RTNATIVETHREAD, NULL); 
     637    Assert(VALID_PTR(pGVMM->aHandles[hGVM].pVM)); 
     638 
     639    return pGVMM->aHandles[hGVM].pGVM; 
    607640} 
    608641 
     
    614647 * @param   hGVM    The global VM handle. Asserts on bad handle. 
    615648 */ 
    616 GVMR0DECL(PVM) GVMR0ByHandle(uint32_t hGVM) 
    617 { 
    618     PGVM pGVM = g_pGVM; 
    619     AssertPtrReturn(pGVM, NULL); 
     649GVMMR0DECL(PVM) GVMMR0GetVMByHandle(uint32_t hGVM) 
     650{ 
     651    PGVMM pGVMM = g_pGVMM; 
     652    AssertPtrReturn(pGVMM, NULL); 
    620653 
    621654    /* 
     
    623656     */ 
    624657    AssertReturn(hGVM != NIL_GVM_HANDLE, NULL); 
    625     AssertReturn(hGVM < RT_ELEMENTS(pGVM->aHandles), NULL); 
     658    AssertReturn(hGVM < RT_ELEMENTS(pGVMM->aHandles), NULL); 
    626659 
    627660    /* 
    628661     * Look it up. 
    629662     */ 
    630     AssertReturn(VALID_PTR(pGVM->aHandles[hGVM].pvObj), NULL); 
    631     AssertReturn(pGVM->aHandles[hGVM].hEMT != NIL_RTNATIVETHREAD, NULL); 
    632     Assert(VALID_PTR(pGVM->aHandles[hGVM].pVM)); 
    633  
    634     return pGVM->aHandles[hGVM].pVM; 
     663    AssertReturn(VALID_PTR(pGVMM->aHandles[hGVM].pvObj), NULL); 
     664    AssertReturn(pGVMM->aHandles[hGVM].hEMT != NIL_RTNATIVETHREAD, NULL); 
     665    Assert(VALID_PTR(pGVMM->aHandles[hGVM].pVM)); 
     666 
     667    return pGVMM->aHandles[hGVM].pVM; 
    635668} 
    636669 
     
    647680 *                  NIL_RTNATIVETHREAD means the current thread 
    648681 */ 
    649 GVMR0DECL(PVM) GVMR0ByEMT(RTNATIVETHREAD hEMT) 
     682GVMMR0DECL(PVM) GVMMR0GetVMByEMT(RTNATIVETHREAD hEMT) 
    650683{ 
    651684    /* 
    652685     * Be very careful here as we're called in AssertMsgN context. 
    653686     */ 
    654     PGVM pGVM = g_pGVM; 
    655     if (!VALID_PTR(pGVM)) 
     687    PGVMM pGVMM = g_pGVMM; 
     688    if (!VALID_PTR(pGVMM)) 
    656689        return NULL; 
    657690 
     
    662695     * Search the handles, we don't dare take the lock (assert). 
    663696     */ 
    664     for (unsigned i = 1; i < RT_ELEMENTS(pGVM->aHandles); i++) 
    665         if (    pGVM->aHandles[i].hEMT == hEMT 
    666             &&  pGVM->aHandles[i].iSelf == i 
    667             &&  VALID_PTR(pGVM->aHandles[i].pvObj) 
    668             &&  VALID_PTR(pGVM->aHandles[i].pVM)) 
    669             return pGVM->aHandles[i].pVM; 
     697    for (unsigned i = 1; i < RT_ELEMENTS(pGVMM->aHandles); i++) 
     698        if (    pGVMM->aHandles[i].hEMT == hEMT 
     699            &&  pGVMM->aHandles[i].iSelf == i 
     700            &&  VALID_PTR(pGVMM->aHandles[i].pvObj) 
     701            &&  VALID_PTR(pGVMM->aHandles[i].pVM)) 
     702            return pGVMM->aHandles[i].pVM; 
    670703 
    671704    return NULL; 
  • trunk/src/VBox/VMM/VMMR0/VMMR0.cpp

    r4984 r5026  
    2929#include "VMMInternal.h" 
    3030#include <VBox/vm.h> 
    31 #include <VBox/gvm.h> 
     31#include <VBox/gvmm.h> 
    3232#include <VBox/intnet.h> 
    3333#include <VBox/hwaccm.h> 
     
    7676 
    7777    /* 
    78      * Initialize GVM. 
     78     * Initialize the GVMM. 
    7979     */ 
    80     int rc = GVMR0Init(); 
     80    int rc = GVMMR0Init(); 
    8181    if (RT_SUCCESS(rc)) 
    8282    { 
     
    124124 
    125125    /* 
    126      * Destroy the GVM instance. 
     126     * Destroy the GVMM instance. 
    127127     */ 
    128     GVMR0Term(); 
     128    GVMMR0Term(); 
    129129 
    130130    LogFlow(("ModuleTerm: returns\n")); 
     
    193193 
    194194    /* 
    195      * Try register the VM with GVM
     195     * Try register the VM with GVMM
    196196     */ 
    197     int rc = GVMR0RegisterVM(pVM); 
     197    int rc = GVMMR0RegisterVM(pVM); 
    198198    if (RT_SUCCESS(rc)) 
    199199    { 
     
    214214        } 
    215215 
    216         GVMR0DeregisterVM(pVM); 
     216        GVMMR0DeregisterVM(pVM); 
    217217    } 
    218218 
     
    233233{ 
    234234    /* 
    235      * Deregister the logger. 
     235     * Deregister the VM and the logger. 
    236236     */ 
    237     GVMR0DeregisterVM(pVM); 
     237    GVMMR0DeregisterVM(pVM); 
    238238    RTLogSetDefaultInstanceThread(NULL, 0); 
    239239    return VINF_SUCCESS; 
     
    935935DECLEXPORT(bool) RTCALL RTAssertDoBreakpoint(void) 
    936936{ 
    937     PVM pVM = GVMR0ByEMT(NIL_RTNATIVETHREAD); 
     937    PVM pVM = GVMMR0GetVMByEMT(NIL_RTNATIVETHREAD); 
    938938    if (pVM) 
    939939    { 

© 2008 Sun Microsystems, Inc.
ContactPrivacy policy