Changeset 36041 in vbox for trunk/src/VBox/VMM/VMMR3
- Timestamp:
- Feb 21, 2011 4:04:53 PM (14 years ago)
- Location:
- trunk/src/VBox/VMM/VMMR3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/VMMR3/PDM.cpp
r35787 r36041 2087 2087 LogFlow(("PDMR3QueryLun: pszDevice=%p:{%s} iInstance=%u iLun=%u ppBase=%p\n", 2088 2088 pszDevice, pszDevice, iInstance, iLun, ppBase)); 2089 VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE); 2089 2090 2090 2091 /* -
trunk/src/VBox/VMM/VMMR3/VM.cpp
r35810 r36041 81 81 #include <iprt/semaphore.h> 82 82 #include <iprt/thread.h> 83 #include <iprt/uuid.h> 83 84 84 85 … … 461 462 AssertCompile(sizeof(pUVM->vm.s) <= sizeof(pUVM->vm.padding)); 462 463 464 pUVM->vm.s.cUvmRefs = 1; 463 465 pUVM->vm.s.ppAtStateNext = &pUVM->vm.s.pAtState; 464 466 pUVM->vm.s.ppAtErrorNext = &pUVM->vm.s.pAtError; … … 466 468 467 469 pUVM->vm.s.enmHaltMethod = VMHALTMETHOD_BOOTSTRAP; 470 RTUuidClear(&pUVM->vm.s.Uuid); 468 471 469 472 /* Initialize the VMCPU array in the UVM. */ … … 563 566 static int vmR3CreateU(PUVM pUVM, uint32_t cCpus, PFNCFGMCONSTRUCTOR pfnCFGMConstructor, void *pvUserCFGM) 564 567 { 565 int rc = VINF_SUCCESS;566 567 568 /* 568 569 * Load the VMMR0.r0 module so that we can call GVMMR0CreateVM. 569 570 */ 570 rc = PDMR3LdrLoadVMMR0U(pUVM);571 int rc = PDMR3LdrLoadVMMR0U(pUVM); 571 572 if (RT_FAILURE(rc)) 572 573 { … … 657 658 } 658 659 } 660 661 /* 662 * Get the CPU execution cap. 663 */ 659 664 if (RT_SUCCESS(rc)) 660 665 { 661 666 rc = CFGMR3QueryU32Def(pRoot, "CpuExecutionCap", &pVM->uCpuExecutionCap, 100); 662 667 AssertLogRelMsgRC(rc, ("Configuration error: Querying \"CpuExecutionCap\" as integer failed, rc=%Rrc\n", rc)); 663 668 } 669 670 /* 671 * Get the VM name and UUID. 672 */ 673 if (RT_SUCCESS(rc)) 674 { 675 rc = CFGMR3QueryStringAllocDef(pRoot, "Name", &pUVM->vm.s.pszName, "<unknown>"); 676 AssertLogRelMsg(RT_SUCCESS(rc) && rc != VERR_CFGM_VALUE_NOT_FOUND, ("Configuration error: Querying \"Name\" failed, rc=%Rrc\n", rc)); 677 } 678 679 if (RT_SUCCESS(rc)) 680 { 681 rc = CFGMR3QueryBytes(pRoot, "UUID", &pUVM->vm.s.Uuid, sizeof(pUVM->vm.s.Uuid)); 682 AssertLogRelMsg(RT_SUCCESS(rc) && rc != VERR_CFGM_VALUE_NOT_FOUND, ("Configuration error: Querying \"UUID\" failed, rc=%Rrc\n", rc)); 683 } 684 685 if (RT_SUCCESS(rc)) 686 { 664 687 /* 665 688 * Init the ring-3 components and ring-3 per cpu data, finishing it off … … 2263 2286 */ 2264 2287 if (!pVM) 2265 return VERR_INVALID_ PARAMETER;2288 return VERR_INVALID_VM_HANDLE; 2266 2289 VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE); 2267 2290 AssertLogRelReturn(!VM_IS_EMT(pVM), VERR_VM_THREAD_IS_EMT); … … 2541 2564 2542 2565 /* 2543 * Destroy the MM heap and free the UVM structure. 2544 */ 2545 MMR3TermUVM(pUVM); 2546 STAMR3TermUVM(pUVM); 2547 2566 * Release the UVM structure reference. 2567 */ 2568 VMR3ReleaseUVM(pUVM); 2569 2570 /* 2571 * Clean up and flush logs. 2572 */ 2548 2573 #ifdef LOG_ENABLED 2549 2574 RTLogSetCustomPrefixCallback(NULL, NULL, NULL); 2550 2575 #endif 2551 RTTlsFree(pUVM->vm.s.idxTLS);2552 2553 ASMAtomicUoWriteU32(&pUVM->u32Magic, UINT32_MAX);2554 RTMemPageFree(pUVM, RT_OFFSETOF(UVM, aCpus[pUVM->cCpus]));2555 2556 2576 RTLogFlush(NULL); 2557 2577 } … … 2852 2872 2853 2873 /** 2874 * Gets the user mode VM structure pointer given the VM handle. 2875 * 2876 * @returns Pointer to the user mode VM structure on success. NULL if @a pVM is 2877 * invalid (asserted). 2878 * @param pVM The VM handle. 2879 * @sa VMR3GetVM, VMR3RetainUVM 2880 */ 2881 VMMR3DECL(PUVM) VMR3GetUVM(PVM pVM) 2882 { 2883 VM_ASSERT_VALID_EXT_RETURN(pVM, NULL); 2884 return pVM->pUVM; 2885 } 2886 2887 2888 /** 2889 * Gets the shared VM structure pointer given the pointer to the user mode VM 2890 * structure. 2891 * 2892 * @returns Pointer to the shared VM structure. 2893 * NULL if @a pUVM is invalid (asserted) or if no shared VM structure 2894 * is currently associated with it. 2895 * @param pUVM The user mode VM handle. 2896 * @sa VMR3GetUVM 2897 */ 2898 VMMR3DECL(PVM) VMR3GetVM(PUVM pUVM) 2899 { 2900 UVM_ASSERT_VALID_EXT_RETURN(pUVM, NULL); 2901 return pUVM->pVM; 2902 } 2903 2904 2905 /** 2906 * Retain the user mode VM handle. 2907 * 2908 * @returns Reference count. 2909 * UINT32_MAX if @a pUVM is invalid. 2910 * 2911 * @param pUVM The user mode VM handle. 2912 * @sa VMR3ReleaseUVM 2913 */ 2914 VMMR3DECL(uint32_t) VMR3RetainUVM(PUVM pUVM) 2915 { 2916 UVM_ASSERT_VALID_EXT_RETURN(pUVM, UINT32_MAX); 2917 uint32_t cRefs = ASMAtomicIncU32(&pUVM->vm.s.cUvmRefs); 2918 AssertMsg(cRefs > 0 && cRefs < _64K, ("%u\n", cRefs)); 2919 return cRefs; 2920 } 2921 2922 2923 /** 2924 * Does the final release of the UVM structure. 2925 * 2926 * @param pUVM The user mode VM handle. 2927 */ 2928 static void vmR3DoReleaseUVM(PUVM pUVM) 2929 { 2930 /* 2931 * Free the UVM. 2932 */ 2933 Assert(!pUVM->pVM); 2934 2935 MMR3TermUVM(pUVM); 2936 STAMR3TermUVM(pUVM); 2937 2938 ASMAtomicUoWriteU32(&pUVM->u32Magic, UINT32_MAX); 2939 RTTlsFree(pUVM->vm.s.idxTLS); 2940 RTMemPageFree(pUVM, RT_OFFSETOF(UVM, aCpus[pUVM->cCpus])); 2941 } 2942 2943 2944 /** 2945 * Releases a refernece to the mode VM handle. 2946 * 2947 * @returns The new reference count, 0 if destroyed. 2948 * UINT32_MAX if @a pUVM is invalid. 2949 * 2950 * @param pUVM The user mode VM handle. 2951 * @sa VMR3RetainUVM 2952 */ 2953 VMMR3DECL(uint32_t) VMR3ReleaseUVM(PUVM pUVM) 2954 { 2955 if (!pUVM) 2956 return 0; 2957 UVM_ASSERT_VALID_EXT_RETURN(pUVM, UINT32_MAX); 2958 uint32_t cRefs = ASMAtomicDecU32(&pUVM->vm.s.cUvmRefs); 2959 if (!cRefs) 2960 vmR3DoReleaseUVM(pUVM); 2961 else 2962 AssertMsg(cRefs < _64K, ("%u\n", cRefs)); 2963 return cRefs; 2964 } 2965 2966 2967 /** 2968 * Gets the VM name. 2969 * 2970 * @returns Pointer to a read-only string containing the name. NULL if called 2971 * too early. 2972 * @param pUVM The user mode VM handle. 2973 */ 2974 VMMR3DECL(const char *) VMR3GetName(PUVM pUVM) 2975 { 2976 UVM_ASSERT_VALID_EXT_RETURN(pUVM, NULL); 2977 return pUVM->vm.s.pszName; 2978 } 2979 2980 2981 /** 2982 * Gets the VM UUID. 2983 * 2984 * @returns pUuid on success, NULL on failure. 2985 * @param pUVM The user mode VM handle. 2986 * @param pUuid Where to store the UUID. 2987 */ 2988 VMMR3DECL(PRTUUID) VMR3GetUuid(PUVM pUVM, PRTUUID pUuid) 2989 { 2990 UVM_ASSERT_VALID_EXT_RETURN(pUVM, NULL); 2991 AssertPtrReturn(pUuid, NULL); 2992 2993 *pUuid = pUVM->vm.s.Uuid; 2994 return pUuid; 2995 } 2996 2997 2998 /** 2854 2999 * Gets the current VM state. 2855 3000 * … … 2860 3005 VMMR3DECL(VMSTATE) VMR3GetState(PVM pVM) 2861 3006 { 3007 VM_ASSERT_VALID_EXT_RETURN(pVM, VMSTATE_TERMINATED); 2862 3008 return pVM->enmVMState; 3009 } 3010 3011 3012 /** 3013 * Gets the current VM state. 3014 * 3015 * @returns The current VM state. 3016 * @param pUVM The user-mode VM handle. 3017 * @thread Any 3018 */ 3019 VMMR3DECL(VMSTATE) VMR3GetStateU(PUVM pUVM) 3020 { 3021 UVM_ASSERT_VALID_EXT_RETURN(pUVM, VMSTATE_TERMINATED); 3022 if (RT_UNLIKELY(!pUVM->pVM)) 3023 return VMSTATE_TERMINATED; 3024 return pUVM->pVM->enmVMState; 2863 3025 } 2864 3026 … … 3459 3621 VMMR3DECL(int) VMR3AtErrorRegister(PVM pVM, PFNVMATERROR pfnAtError, void *pvUser) 3460 3622 { 3623 VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE); 3461 3624 return VMR3AtErrorRegisterU(pVM->pUVM, pfnAtError, pvUser); 3462 3625 } … … 4169 4332 VMMR3DECL(int) VMR3GetCpuCoreAndPackageIdFromCpuId(PVM pVM, VMCPUID idCpu, uint32_t *pidCpuCore, uint32_t *pidCpuPackage) 4170 4333 { 4334 /* 4335 * Validate input. 4336 */ 4337 VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE); 4338 AssertPtrReturn(pidCpuCore, VERR_INVALID_POINTER); 4339 AssertPtrReturn(pidCpuPackage, VERR_INVALID_POINTER); 4171 4340 if (idCpu >= pVM->cCpus) 4172 4341 return VERR_INVALID_CPU_ID; 4173 4342 4343 /* 4344 * Set return values. 4345 */ 4174 4346 #ifdef VBOX_WITH_MULTI_CORE 4175 4347 *pidCpuCore = idCpu; … … 4223 4395 VMMR3DECL(int) VMR3HotUnplugCpu(PVM pVM, VMCPUID idCpu) 4224 4396 { 4397 VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE); 4225 4398 AssertReturn(idCpu < pVM->cCpus, VERR_INVALID_CPU_ID); 4226 4399 … … 4242 4415 VMMR3DECL(int) VMR3HotPlugCpu(PVM pVM, VMCPUID idCpu) 4243 4416 { 4417 VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE); 4244 4418 AssertReturn(idCpu < pVM->cCpus, VERR_INVALID_CPU_ID); 4245 4419 … … 4254 4428 * @returns VBox status code. 4255 4429 * @param pVM The VM to operate on. 4256 * @param ulCpuExecutionCap New CPU execution cap 4257 */ 4258 VMMR3DECL(int) VMR3SetCpuExecutionCap(PVM pVM, unsigned ulCpuExecutionCap) 4259 { 4260 AssertReturn(ulCpuExecutionCap > 0 && ulCpuExecutionCap <= 100, VERR_INVALID_PARAMETER); 4261 4262 Log(("VMR3SetCpuExecutionCap: new priority = %d\n", ulCpuExecutionCap)); 4430 * @param uCpuExecutionCap New CPU execution cap in precent, 1-100. Where 4431 * 100 is max performance (default). 4432 */ 4433 VMMR3DECL(int) VMR3SetCpuExecutionCap(PVM pVM, uint32_t uCpuExecutionCap) 4434 { 4435 VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE); 4436 AssertReturn(uCpuExecutionCap > 0 && uCpuExecutionCap <= 100, VERR_INVALID_PARAMETER); 4437 4438 Log(("VMR3SetCpuExecutionCap: new priority = %d\n", uCpuExecutionCap)); 4263 4439 /* Note: not called from EMT. */ 4264 pVM->uCpuExecutionCap = u lCpuExecutionCap;4440 pVM->uCpuExecutionCap = uCpuExecutionCap; 4265 4441 return VINF_SUCCESS; 4266 4442 }
Note:
See TracChangeset
for help on using the changeset viewer.