- Timestamp:
- Sep 25, 2007 3:49:09 PM (17 years ago)
- Location:
- trunk/src/VBox/VMM
- Files:
-
- 2 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/Makefile.kmk
r4975 r5026 327 327 VMMR0/CPUMR0.cpp \ 328 328 VMMR0/DBGFR0.cpp \ 329 VMMR0/GVM R0.cpp \329 VMMR0/GVMMR0.cpp \ 330 330 VMMR0/HWACCMR0.cpp \ 331 331 VMMR0/HWACCMR0A.asm \ -
trunk/src/VBox/VMM/VMMR0/GVMMR0.cpp
r5014 r5026 1 1 /* $Id$ */ 2 2 /** @file 3 * GVM - Global VM Manager.3 * GVMM - Global VM Manager. 4 4 */ 5 5 … … 18 18 19 19 20 /** @page pg_GVM GVM -Global VM Manager20 /** @page pg_GVMM GVMM - The Global VM Manager 21 21 * 22 22 * 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 to24 * each of them (so GMM can track page owners). The idea for the future is25 * to add an idle priority kernel thread that can take care of tasks like26 * page sharing.27 * 28 * The GVM will create a ring-0 object for each VM when it's registered, this29 * is both for session cleanup purposes and for having a point where it's30 * 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). 31 31 */ 32 32 … … 36 36 *******************************************************************************/ 37 37 #define LOG_GROUP LOG_GROUP_GVM 38 #include <VBox/gvm .h>39 /* #include "GVM Internal.h" */38 #include <VBox/gvmm.h> 39 /* #include "GVMMInternal.h" */ 40 40 #include <VBox/vm.h> 41 41 #include <VBox/err.h> … … 63 63 /** Whether to free the VM structure or not. */ 64 64 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. */ 66 68 PVM pVM; 67 69 /** The virtual machine object. */ … … 77 79 78 80 /** 79 * The GVM instance data.80 */ 81 typedef struct 81 * The GVMM instance data. 82 */ 83 typedef struct GVMM 82 84 { 83 85 /** Eyecatcher / magic. */ … … 93 95 * The first entry is unused as it represents the NIL handle. */ 94 96 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 _MAGIC0x1937080697 } GVMM; 98 /** Pointer to the GVMM instance data. */ 99 typedef GVMM *PGVMM; 100 101 /** The GVMM::u32Magic value (Charlie Haden). */ 102 #define GVMM_MAGIC 0x19370806 101 103 102 104 … … 105 107 * Global Variables * 106 108 *******************************************************************************/ 107 /** Pointer to the GVM instance data.109 /** Pointer to the GVMM instance data. 108 110 * (Just my general dislike for global variables.) */ 109 static PGVM g_pGVM = NULL;111 static PGVMM g_pGVMM = NULL; 110 112 111 113 … … 113 115 * Internal Functions * 114 116 *******************************************************************************/ 115 static DECLCALLBACK(void) gvm R0HandleObjDestructor(void *pvObj, void *pvGVM, void *pvHandle);116 117 118 /** 119 * Initializes the GVM .117 static DECLCALLBACK(void) gvmmR0HandleObjDestructor(void *pvObj, void *pvGVMM, void *pvHandle); 118 119 120 /** 121 * Initializes the GVMM. 120 122 * 121 123 * This is called while owninng the loader sempahore (see supdrvIOCtl_LdrLoad()). … … 123 125 * @returns VBox status code. 124 126 */ 125 GVM R0DECL(int) GVMR0Init(void)126 { 127 SUPR0Printf("GVM R0Init:\n");127 GVMMR0DECL(int) GVMMR0Init(void) 128 { 129 SUPR0Printf("GVMMR0Init:\n"); 128 130 129 131 /* 130 132 * Allocate and initialize the instance data. 131 133 */ 132 PGVM pGVM = (PGVM)RTMemAllocZ(sizeof(*pGVM));133 if (!pGVM )134 PGVMM pGVMM = (PGVMM)RTMemAllocZ(sizeof(*pGVMM)); 135 if (!pGVMM) 134 136 return VERR_NO_MEMORY; 135 int rc = RTSemFastMutexCreate(&pGVM ->Lock);137 int rc = RTSemFastMutexCreate(&pGVMM->Lock); 136 138 if (RT_SUCCESS(rc)) 137 139 { 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; 141 143 142 144 /* 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; 145 147 146 148 /* 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 */ 150 152 151 153 /* the rest */ 152 154 while (i-- > 1) 153 155 { 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; 156 158 } 157 159 158 g_pGVM = pGVM;159 SUPR0Printf("GVM R0Init: pGVM=%p\n", pGVM);160 g_pGVMM = pGVMM; 161 SUPR0Printf("GVMMR0Init: pGVMM=%p\n", pGVMM); 160 162 return VINF_SUCCESS; 161 163 } 162 164 163 RTMemFree(pGVM );165 RTMemFree(pGVMM); 164 166 return rc; 165 167 } … … 173 175 * registered at this point. 174 176 */ 175 GVM R0DECL(void) GVMR0Term(void)176 { 177 SUPR0Printf("GVM R0Term:\n");178 179 PGVM pGVM = g_pGVM;180 g_pGVM = NULL;181 if (RT_UNLIKELY(!VALID_PTR(pGVM )))182 { 183 SUPR0Printf("GVM R0Term: pGVM=%p\n", pGVM);177 GVMMR0DECL(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); 184 186 return; 185 187 } 186 188 187 RTSemFastMutexDestroy(pGVM ->Lock);188 pGVM ->Lock = NIL_RTSEMFASTMUTEX;189 pGVM ->u32Magic++;190 pGVM ->iFreeHead = 0;191 if (pGVM ->iUsedHead)192 { 193 SUPR0Printf("GVM R0Term: 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); 198 200 } 199 201 … … 209 211 * @thread EMT. 210 212 */ 211 GVM R0DECL(int) GVMR0CreateVM(PSUPDRVSESSION pSession, PVM *ppVM)212 { 213 SUPR0Printf("GVM R0CreateVM: pSession=%p\n", pSession);214 PGVM pGVM = g_pGVM;215 AssertPtrReturn(pGVM , VERR_INTERNAL_ERROR);213 GVMMR0DECL(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); 216 218 217 219 AssertPtrReturn(ppVM, VERR_INVALID_POINTER); … … 224 226 * The whole allocation process is protected by the lock. 225 227 */ 226 int rc = RTSemFastMutexRequest(pGVM ->Lock);228 int rc = RTSemFastMutexRequest(pGVMM->Lock); 227 229 AssertRCReturn(rc, rc); 228 230 … … 230 232 * Allocate a handle first so we don't waste resources unnecessarily. 231 233 */ 232 uint16_t iHandle = pGVM ->iFreeHead;234 uint16_t iHandle = pGVMM->iFreeHead; 233 235 if (iHandle) 234 236 { 235 PGVM HANDLE pHandle = &pGVM->aHandles[iHandle];237 PGVMMHANDLE pHandle = &pGVMM->aHandles[iHandle]; 236 238 237 239 /* consistency checks, a bit paranoid as always. */ 238 240 if ( !pHandle->pVM 241 /*&& !pHandle->pGVM */ 239 242 && !pHandle->pvObj 240 243 && pHandle->iSelf == iHandle) 241 244 { 242 pHandle->pvObj = SUPR0ObjRegister(pSession, SUPDRVOBJTYPE_VM, gvm R0HandleObjDestructor, pGVM, pHandle);245 pHandle->pvObj = SUPR0ObjRegister(pSession, SUPDRVOBJTYPE_VM, gvmmR0HandleObjDestructor, pGVMM, pHandle); 243 246 if (pHandle->pvObj) 244 247 { … … 246 249 * Move the handle from the free to used list and perform permission checks. 247 250 */ 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; 251 254 252 255 pHandle->fFreeVM = true; 253 256 pHandle->pVM = NULL; 257 pHandle->pGVM = NULL; /* to be allocated */ 254 258 pHandle->pSession = pSession; 255 259 pHandle->hEMT = hEMT; … … 279 283 pVM->pSession = pSession; 280 284 pVM->hSelf = iHandle; 281 RTSemFastMutexRelease(pGVM ->Lock);285 RTSemFastMutexRelease(pGVMM->Lock); 282 286 283 287 *ppVM = pVM; 284 SUPR0Printf("GVM R0CreateVM: pVM=%p pVMR3=%p\n", pVM, pVMR3);288 SUPR0Printf("GVMMR0CreateVM: pVM=%p pVMR3=%p\n", pVM, pVMR3); 285 289 return VINF_SUCCESS; 286 290 } … … 292 296 293 297 /* 294 * The handle will be freed by gvm R0HandleObjDestructor as we release the298 * The handle will be freed by gvmmR0HandleObjDestructor as we release the 295 299 * object reference here. A little extra mess because of non-recursive lock. 296 300 */ 297 301 void *pvObj = pHandle->pvObj; 298 302 pHandle->pvObj = NULL; 299 RTSemFastMutexRelease(pGVM ->Lock);303 RTSemFastMutexRelease(pGVMM->Lock); 300 304 301 305 SUPR0ObjRelease(pvObj, pSession); 302 306 303 SUPR0Printf("GVM R0CreateVM: failed, rc=%d\n", rc);307 SUPR0Printf("GVMMR0CreateVM: failed, rc=%d\n", rc); 304 308 return rc; 305 309 } … … 313 317 rc = VERR_GVM_TOO_MANY_VMS; 314 318 315 RTSemFastMutexRelease(pGVM ->Lock);319 RTSemFastMutexRelease(pGVMM->Lock); 316 320 return rc; 317 321 } … … 327 331 * @thread EMT. 328 332 */ 329 GVM R0DECL(int) GVMR0DestroyVM(PVM pVM)330 { 331 SUPR0Printf("GVM R0DestroyVM: pVM=%p\n", pVM);332 333 PGVM pGVM = g_pGVM;334 AssertPtrReturn(pGVM , VERR_INTERNAL_ERROR);333 GVMMR0DECL(int) GVMMR0DestroyVM(PVM pVM) 334 { 335 SUPR0Printf("GVMMR0DestroyVM: pVM=%p\n", pVM); 336 337 PGVMM pGVMM = g_pGVMM; 338 AssertPtrReturn(pGVMM, VERR_INTERNAL_ERROR); 335 339 336 340 /* … … 343 347 uint32_t hGVM = pVM->hSelf; 344 348 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]; 348 352 AssertReturn(pHandle->hEMT != NIL_RTNATIVETHREAD, VERR_WRONG_ORDER); 349 353 AssertReturn(pHandle->pVM == pVM, VERR_NOT_OWNER); … … 357 361 * race us as we leave the lock and call SUPR0ObjRelease. 358 362 */ 359 int rc = RTSemFastMutexRequest(pGVM ->Lock);363 int rc = RTSemFastMutexRequest(pGVMM->Lock); 360 364 AssertRC(rc); 361 365 … … 367 371 void *pvObj = pHandle->pvObj; 368 372 pHandle->pvObj = NULL; 369 RTSemFastMutexRelease(pGVM ->Lock);373 RTSemFastMutexRelease(pGVMM->Lock); 370 374 371 375 SUPR0ObjRelease(pvObj, pVM->pSession); … … 373 377 else 374 378 { 375 RTSemFastMutexRelease(pGVM ->Lock);379 RTSemFastMutexRelease(pGVMM->Lock); 376 380 rc = VERR_INTERNAL_ERROR; 377 381 } … … 394 398 * @thread EMT. 395 399 */ 396 GVM R0DECL(int) GVMR0RegisterVM(PVM pVM)397 { 398 SUPR0Printf("GVM R0RegisterVM: pVM=%p\n", pVM);399 PGVM pGVM = g_pGVM;400 AssertPtrReturn(pGVM , VERR_INTERNAL_ERROR);400 GVMMR0DECL(int) GVMMR0RegisterVM(PVM pVM) 401 { 402 SUPR0Printf("GVMMR0RegisterVM: pVM=%p\n", pVM); 403 PGVMM pGVMM = g_pGVMM; 404 AssertPtrReturn(pGVMM, VERR_INTERNAL_ERROR); 401 405 402 406 /* … … 413 417 * Take the lock and call the worker function. 414 418 */ 415 int rc = RTSemFastMutexRequest(pGVM ->Lock);419 int rc = RTSemFastMutexRequest(pGVMM->Lock); 416 420 AssertRCReturn(rc, rc); 417 421 … … 419 423 * Allocate a handle. 420 424 */ 421 uint16_t iHandle = pGVM ->iFreeHead;425 uint16_t iHandle = pGVMM->iFreeHead; 422 426 if (iHandle) 423 427 { 424 PGVMHANDLE pHandle = &pGVM ->aHandles[iHandle];428 PGVMHANDLE pHandle = &pGVMM->aHandles[iHandle]; 425 429 426 430 /* consistency checks, a bit paranoid as always. */ … … 429 433 && pHandle->iSelf == iHandle) 430 434 { 431 pHandle->pvObj = SUPR0ObjRegister(pVM->pSession, SUPDRVOBJTYPE_VM, gvm R0HandleObjDestructor, pGVM, pHandle);435 pHandle->pvObj = SUPR0ObjRegister(pVM->pSession, SUPDRVOBJTYPE_VM, gvmmR0HandleObjDestructor, pGVMM, pHandle); 432 436 if (pHandle->pvObj) 433 437 { … … 436 440 * perform permission checks. 437 441 */ 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; 441 445 442 446 pHandle->fFreeVM = false; 443 447 pHandle->pVM = pVM; 448 pHandle->pGVM = NULL; /** @todo to be allocated */ 444 449 pHandle->pSession = pVM->pSession; 445 450 pHandle->hEMT = hEMT; … … 449 454 { 450 455 pVM->hSelf = iHandle; 451 RTSemFastMutexRelease(pGVM ->Lock);456 RTSemFastMutexRelease(pGVMM->Lock); 452 457 } 453 458 else … … 455 460 /* 456 461 * The user wasn't permitted to create this VM. 457 * Must use gvm R0HandleObjDestructor via SUPR0ObjRelease to do the462 * Must use gvmmR0HandleObjDestructor via SUPR0ObjRelease to do the 458 463 * cleanups. The lock isn't recursive, thus the extra mess. 459 464 */ 460 465 void *pvObj = pHandle->pvObj; 461 466 pHandle->pvObj = NULL; 462 RTSemFastMutexRelease(pGVM ->Lock);467 RTSemFastMutexRelease(pGVMM->Lock); 463 468 464 469 SUPR0ObjRelease(pvObj, pVM->pSession); 465 470 } 466 471 if (RT_FAILURE(rc)) 467 SUPR0Printf("GVM R0RegisterVM: permission denied, rc=%d\n", rc);472 SUPR0Printf("GVMMR0RegisterVM: permission denied, rc=%d\n", rc); 468 473 return rc; 469 474 } … … 477 482 rc = VERR_GVM_TOO_MANY_VMS; 478 483 479 RTSemFastMutexRelease(pGVM ->Lock);480 SUPR0Printf("GVM R0RegisterVM: failed, rc=%d, iHandle=%d\n", rc, iHandle);484 RTSemFastMutexRelease(pGVMM->Lock); 485 SUPR0Printf("GVMMR0RegisterVM: failed, rc=%d, iHandle=%d\n", rc, iHandle); 481 486 return rc; 482 487 } … … 484 489 485 490 /** 486 * Deregister a VM previously registered using the GVM R0RegisterVM API.491 * Deregister a VM previously registered using the GVMMR0RegisterVM API. 487 492 * 488 493 * … … 491 496 * @thread EMT. 492 497 */ 493 GVM R0DECL(int) GVMR0DeregisterVM(PVM pVM)494 { 495 SUPR0Printf("GVM R0DeregisterVM: pVM=%p\n", pVM);496 return GVM R0DestroyVM(pVM);498 GVMMR0DECL(int) GVMMR0DeregisterVM(PVM pVM) 499 { 500 SUPR0Printf("GVMMR0DeregisterVM: pVM=%p\n", pVM); 501 return GVMMR0DestroyVM(pVM); 497 502 } 498 503 #endif /* ... */ … … 502 507 * Handle destructor. 503 508 * 504 * @param pvGVM The GVM instance pointer.509 * @param pvGVMM The GVM instance pointer. 505 510 * @param pvHandle The handle pointer. 506 511 */ 507 static DECLCALLBACK(void) gvm R0HandleObjDestructor(void *pvObj, void *pvGVM, void *pvHandle)508 { 509 SUPR0Printf("gvm R0HandleObjDestructor: %p %p %p\n", pvObj, pvGVM, pvHandle);512 static DECLCALLBACK(void) gvmmR0HandleObjDestructor(void *pvObj, void *pvGVMM, void *pvHandle) 513 { 514 SUPR0Printf("gvmmR0HandleObjDestructor: %p %p %p\n", pvObj, pvGVMM, pvHandle); 510 515 511 516 /* … … 514 519 PGVMHANDLE pHandle = (PGVMHANDLE)pvHandle; 515 520 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]; 519 524 if ( !iHandle 520 || iHandle >= RT_ELEMENTS(pGVM ->aHandles)525 || iHandle >= RT_ELEMENTS(pGVMM->aHandles) 521 526 || iHandle != pHandle->iSelf) 522 527 { … … 525 530 } 526 531 527 int rc = RTSemFastMutexRequest(pGVM ->Lock);532 int rc = RTSemFastMutexRequest(pGVMM->Lock); 528 533 AssertRC(rc); 529 534 … … 531 536 * This is a tad slow but a doubly linked list is too much hazzle. 532 537 */ 533 if (RT_UNLIKELY(pHandle->iNext >= RT_ELEMENTS(pGVM ->aHandles)))538 if (RT_UNLIKELY(pHandle->iNext >= RT_ELEMENTS(pGVMM->aHandles))) 534 539 { 535 540 SUPR0Printf("GVM: used list index %d is out of range!\n", pHandle->iNext); 536 RTSemFastMutexRelease(pGVM ->Lock);541 RTSemFastMutexRelease(pGVMM->Lock); 537 542 return; 538 543 } 539 544 540 if (pGVM ->iUsedHead == iHandle)541 pGVM ->iUsedHead = pHandle->iNext;545 if (pGVMM->iUsedHead == iHandle) 546 pGVMM->iUsedHead = pHandle->iNext; 542 547 else 543 548 { 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; 546 551 while (!iPrev) 547 552 { 548 if (RT_UNLIKELY(iPrev >= RT_ELEMENTS(pGVM ->aHandles)))553 if (RT_UNLIKELY(iPrev >= RT_ELEMENTS(pGVMM->aHandles))) 549 554 { 550 555 SUPR0Printf("GVM: used list index %d is out of range!\n"); 551 RTSemFastMutexRelease(pGVM ->Lock);556 RTSemFastMutexRelease(pGVMM->Lock); 552 557 return; 553 558 } … … 558 563 } 559 564 560 if (pGVM ->aHandles[iPrev].iNext == iHandle)565 if (pGVMM->aHandles[iPrev].iNext == iHandle) 561 566 break; 562 iPrev = pGVM ->aHandles[iPrev].iNext;567 iPrev = pGVMM->aHandles[iPrev].iNext; 563 568 } 564 569 if (!iPrev) 565 570 { 566 571 SUPR0Printf("GVM: can't find the handle previous previous of %d!\n", pHandle->iSelf); 567 RTSemFastMutexRelease(pGVM ->Lock);572 RTSemFastMutexRelease(pGVMM->Lock); 568 573 return; 569 574 } 570 575 571 pGVM ->aHandles[iPrev].iNext = pHandle->iNext;576 pGVMM->aHandles[iPrev].iNext = pHandle->iNext; 572 577 } 573 578 pHandle->iNext = 0; … … 595 600 * Free the handle. 596 601 */ 597 pHandle->iNext = pGVM ->iFreeHead;602 pHandle->iNext = pGVMM->iFreeHead; 598 603 pHandle->fFreeVM = false; 599 pGVM ->iFreeHead = iHandle;604 pGVMM->iFreeHead = iHandle; 600 605 ASMAtomicXchgPtr((void * volatile *)&pHandle->pVM, NULL); 601 606 ASMAtomicXchgPtr((void * volatile *)&pHandle->pvObj, NULL); … … 603 608 ASMAtomicXchgSize(&pHandle->hEMT, NIL_RTNATIVETHREAD); 604 609 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 */ 621 GVMMR0DECL(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; 607 640 } 608 641 … … 614 647 * @param hGVM The global VM handle. Asserts on bad handle. 615 648 */ 616 GVM R0DECL(PVM) GVMR0ByHandle(uint32_t hGVM)617 { 618 PGVM pGVM = g_pGVM;619 AssertPtrReturn(pGVM , NULL);649 GVMMR0DECL(PVM) GVMMR0GetVMByHandle(uint32_t hGVM) 650 { 651 PGVMM pGVMM = g_pGVMM; 652 AssertPtrReturn(pGVMM, NULL); 620 653 621 654 /* … … 623 656 */ 624 657 AssertReturn(hGVM != NIL_GVM_HANDLE, NULL); 625 AssertReturn(hGVM < RT_ELEMENTS(pGVM ->aHandles), NULL);658 AssertReturn(hGVM < RT_ELEMENTS(pGVMM->aHandles), NULL); 626 659 627 660 /* 628 661 * Look it up. 629 662 */ 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; 635 668 } 636 669 … … 647 680 * NIL_RTNATIVETHREAD means the current thread 648 681 */ 649 GVM R0DECL(PVM) GVMR0ByEMT(RTNATIVETHREAD hEMT)682 GVMMR0DECL(PVM) GVMMR0GetVMByEMT(RTNATIVETHREAD hEMT) 650 683 { 651 684 /* 652 685 * Be very careful here as we're called in AssertMsgN context. 653 686 */ 654 PGVM pGVM = g_pGVM;655 if (!VALID_PTR(pGVM ))687 PGVMM pGVMM = g_pGVMM; 688 if (!VALID_PTR(pGVMM)) 656 689 return NULL; 657 690 … … 662 695 * Search the handles, we don't dare take the lock (assert). 663 696 */ 664 for (unsigned i = 1; i < RT_ELEMENTS(pGVM ->aHandles); i++)665 if ( pGVM ->aHandles[i].hEMT == hEMT666 && pGVM ->aHandles[i].iSelf == i667 && 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; 670 703 671 704 return NULL; -
trunk/src/VBox/VMM/VMMR0/VMMR0.cpp
r4984 r5026 29 29 #include "VMMInternal.h" 30 30 #include <VBox/vm.h> 31 #include <VBox/gvm .h>31 #include <VBox/gvmm.h> 32 32 #include <VBox/intnet.h> 33 33 #include <VBox/hwaccm.h> … … 76 76 77 77 /* 78 * Initialize GVM.78 * Initialize the GVMM. 79 79 */ 80 int rc = GVM R0Init();80 int rc = GVMMR0Init(); 81 81 if (RT_SUCCESS(rc)) 82 82 { … … 124 124 125 125 /* 126 * Destroy the GVM instance.126 * Destroy the GVMM instance. 127 127 */ 128 GVM R0Term();128 GVMMR0Term(); 129 129 130 130 LogFlow(("ModuleTerm: returns\n")); … … 193 193 194 194 /* 195 * Try register the VM with GVM .195 * Try register the VM with GVMM. 196 196 */ 197 int rc = GVM R0RegisterVM(pVM);197 int rc = GVMMR0RegisterVM(pVM); 198 198 if (RT_SUCCESS(rc)) 199 199 { … … 214 214 } 215 215 216 GVM R0DeregisterVM(pVM);216 GVMMR0DeregisterVM(pVM); 217 217 } 218 218 … … 233 233 { 234 234 /* 235 * Deregister the logger.235 * Deregister the VM and the logger. 236 236 */ 237 GVM R0DeregisterVM(pVM);237 GVMMR0DeregisterVM(pVM); 238 238 RTLogSetDefaultInstanceThread(NULL, 0); 239 239 return VINF_SUCCESS; … … 935 935 DECLEXPORT(bool) RTCALL RTAssertDoBreakpoint(void) 936 936 { 937 PVM pVM = GVM R0ByEMT(NIL_RTNATIVETHREAD);937 PVM pVM = GVMMR0GetVMByEMT(NIL_RTNATIVETHREAD); 938 938 if (pVM) 939 939 {
Note:
See TracChangeset
for help on using the changeset viewer.