Changeset 71296 in vbox for trunk/src/VBox/VMM/VMMR3
- Timestamp:
- Mar 10, 2018 12:53:26 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/VMMR3/NEMR3Native-win.cpp
r71293 r71296 54 54 #include <iprt/path.h> 55 55 #include <iprt/string.h> 56 #include <iprt/system.h> 56 57 57 58 … … 71 72 /** VID I/O control detection: Fake timeout input. */ 72 73 #define NEM_WIN_IOCTL_DETECTOR_FAKE_TIMEOUT UINT32_C(0x00080286) 74 75 76 /********************************************************************************************************************************* 77 * Structures and Typedefs * 78 *********************************************************************************************************************************/ 79 #ifndef NEM_WIN_USE_17110_PLUS_WDK 80 typedef HRESULT (WINAPI *PFNWHVGETCAPABILITY_17110)(WHV_CAPABILITY_CODE, void *, uint32_t, uint32_t *); 81 typedef HRESULT (WINAPI *PFNWHVSETPARTITIONPROPERTY_17110)(WHV_PARTITION_HANDLE, WHV_PARTITION_PROPERTY_CODE, void *, uint32_t); 82 #endif 73 83 74 84 … … 111 121 #endif 112 122 /** @} */ 123 124 /** The Windows build number. */ 125 static uint32_t g_uBuildNo = 17110; 126 113 127 114 128 … … 212 226 213 227 # define VidMessageSlotHandleAndGetNext g_pfnVidMessageSlotHandleAndGetNext 214 # define VidStartVirtualProcessor 228 # define VidStartVirtualProcessor g_pfnVidStartVirtualProcessor 215 229 # define VidStopVirtualProcessor g_pfnVidStopVirtualProcessor 216 230 … … 512 526 513 527 /** 528 * Wrapper for different WHvGetCapability signatures. 529 */ 530 DECLINLINE(HRESULT) WHvGetCapabilityWrapper(WHV_CAPABILITY_CODE enmCap, WHV_CAPABILITY *pOutput, uint32_t cbOutput) 531 { 532 #ifdef NEM_WIN_USE_17110_PLUS_WDK 533 return g_pfnWHvGetCapability(enmCap, pOutput, cbOutput, NULL); 534 #else 535 if (g_uBuildNo >= 17110) 536 { 537 PFNWHVGETCAPABILITY_17110 pfnNewVersion = (PFNWHVGETCAPABILITY_17110)g_pfnWHvGetCapability; 538 return pfnNewVersion(enmCap, &pOutput->HypervisorPresent, cbOutput - RT_OFFSETOF(WHV_CAPABILITY, HypervisorPresent), NULL); 539 } 540 return g_pfnWHvGetCapability(enmCap, pOutput, cbOutput); 541 #endif 542 } 543 544 545 /** 514 546 * Worker for nemR3NativeInit that gets the hypervisor capabilities. 515 547 * … … 543 575 RT_ZERO(Caps); 544 576 SetLastError(0); 545 HRESULT hrc = WHvGetCapability (WHvCapabilityCodeHypervisorPresent, &Caps, sizeof(Caps));577 HRESULT hrc = WHvGetCapabilityWrapper(WHvCapabilityCodeHypervisorPresent, &Caps, sizeof(Caps)); 546 578 DWORD rcWin = GetLastError(); 547 579 if (FAILED(hrc)) … … 563 595 */ 564 596 RT_ZERO(Caps); 565 hrc = WHvGetCapability (WHvCapabilityCodeExtendedVmExits, &Caps, sizeof(Caps));597 hrc = WHvGetCapabilityWrapper(WHvCapabilityCodeExtendedVmExits, &Caps, sizeof(Caps)); 566 598 if (FAILED(hrc)) 567 599 return RTErrInfoSetF(pErrInfo, VERR_NEM_INIT_FAILED, … … 583 615 */ 584 616 RT_ZERO(Caps); 585 hrc = WHvGetCapability (WHvCapabilityCodeFeatures, &Caps, sizeof(Caps));617 hrc = WHvGetCapabilityWrapper(WHvCapabilityCodeFeatures, &Caps, sizeof(Caps)); 586 618 if (FAILED(hrc)) 587 619 return RTErrInfoSetF(pErrInfo, VERR_NEM_INIT_FAILED, … … 596 628 */ 597 629 RT_ZERO(Caps); 598 hrc = WHvGetCapability (WHvCapabilityCodeProcessorVendor, &Caps, sizeof(Caps));630 hrc = WHvGetCapabilityWrapper(WHvCapabilityCodeProcessorVendor, &Caps, sizeof(Caps)); 599 631 if (FAILED(hrc)) 600 632 return RTErrInfoSetF(pErrInfo, VERR_NEM_INIT_FAILED, … … 621 653 */ 622 654 RT_ZERO(Caps); 623 hrc = WHvGetCapability (WHvCapabilityCodeProcessorFeatures, &Caps, sizeof(Caps));655 hrc = WHvGetCapabilityWrapper(WHvCapabilityCodeProcessorFeatures, &Caps, sizeof(Caps)); 624 656 if (FAILED(hrc)) 625 657 return RTErrInfoSetF(pErrInfo, VERR_NEM_INIT_FAILED, … … 680 712 */ 681 713 RT_ZERO(Caps); 682 hrc = WHvGetCapability (WHvCapabilityCodeProcessorClFlushSize, &Caps, sizeof(Caps));714 hrc = WHvGetCapabilityWrapper(WHvCapabilityCodeProcessorClFlushSize, &Caps, sizeof(Caps)); 683 715 if (FAILED(hrc)) 684 716 return RTErrInfoSetF(pErrInfo, VERR_NEM_INIT_FAILED, … … 710 742 { 711 743 RT_ZERO(Caps); 712 hrc = WHvGetCapability ((WHV_CAPABILITY_CODE)i, &Caps, sizeof(Caps));744 hrc = WHvGetCapabilityWrapper((WHV_CAPABILITY_CODE)i, &Caps, sizeof(Caps)); 713 745 if (SUCCEEDED(hrc)) 714 746 LogRel(("NEM: Warning! Unknown capability %#x returning: %.*Rhxs\n", i, sizeof(Caps), &Caps)); … … 977 1009 978 1010 /** 1011 * Wrapper for different WHvSetPartitionProperty signatures. 1012 */ 1013 DECLINLINE(HRESULT) WHvSetPartitionPropertyWrapper(WHV_PARTITION_HANDLE hPartition, WHV_PARTITION_PROPERTY_CODE enmProp, 1014 WHV_PARTITION_PROPERTY *pInput, uint32_t cbInput) 1015 { 1016 #ifdef NEM_WIN_USE_17110_PLUS_WDK 1017 return g_pfnWHvSetPartitionProperty(hPartition, enmProp, pInput, cbInput, NULL); 1018 #else 1019 pInput->PropertyCode = enmProp; 1020 if (g_uBuildNo >= 17110) 1021 { 1022 PFNWHVSETPARTITIONPROPERTY_17110 pfnNewVersion = (PFNWHVSETPARTITIONPROPERTY_17110)g_pfnWHvSetPartitionProperty; 1023 return pfnNewVersion(hPartition, enmProp, &pInput->ExtendedVmExits, 1024 cbInput - RT_UOFFSETOF(WHV_PARTITION_PROPERTY, ExtendedVmExits)); 1025 } 1026 return g_pfnWHvSetPartitionProperty(hPartition, pInput, cbInput); 1027 #endif 1028 } 1029 1030 1031 /** 979 1032 * Creates and sets up a Hyper-V (exo) partition. 980 1033 * … … 1012 1065 WHV_PARTITION_PROPERTY Property; 1013 1066 RT_ZERO(Property); 1014 Property.PropertyCode = WHvPartitionPropertyCodeProcessorCount;1015 1067 Property.ProcessorCount = pVM->cCpus; 1016 hrc = WHvSetPartitionProperty (hPartition, &Property, sizeof(Property));1068 hrc = WHvSetPartitionPropertyWrapper(hPartition, WHvPartitionPropertyCodeProcessorCount, &Property, sizeof(Property)); 1017 1069 if (SUCCEEDED(hrc)) 1018 1070 { 1019 1071 RT_ZERO(Property); 1020 Property.PropertyCode = WHvPartitionPropertyCodeExtendedVmExits; 1072 #if 0 1021 1073 Property.ExtendedVmExits.X64CpuidExit = pVM->nem.s.fExtendedCpuIdExit; 1022 1074 Property.ExtendedVmExits.X64MsrExit = pVM->nem.s.fExtendedMsrExit; 1023 1075 Property.ExtendedVmExits.ExceptionExit = pVM->nem.s.fExtendedXcptExit; 1024 hrc = WHvSetPartitionProperty(hPartition, &Property, sizeof(Property)); 1076 #endif 1077 hrc = WHvSetPartitionPropertyWrapper(hPartition, WHvPartitionPropertyCodeExtendedVmExits, &Property, sizeof(Property)); 1025 1078 if (SUCCEEDED(hrc)) 1026 1079 { … … 1065 1118 int nemR3NativeInit(PVM pVM, bool fFallback, bool fForced) 1066 1119 { 1120 g_uBuildNo = RTSystemGetNtBuildNo(); 1121 1067 1122 /* 1068 1123 * Error state. … … 1159 1214 * Continue setting up the partition now that we've got most of the CPUID feature stuff. 1160 1215 */ 1161 1162 /* Not sure if we really need to set the vendor. */1163 1216 WHV_PARTITION_PROPERTY Property; 1217 HRESULT hrc; 1218 1219 #if 0 1220 /* Not sure if we really need to set the vendor. 1221 Update: Apparently we don't. WHvPartitionPropertyCodeProcessorVendor was removed in 17110. */ 1164 1222 RT_ZERO(Property); 1165 Property.PropertyCode = WHvPartitionPropertyCodeProcessorVendor;1166 1223 Property.ProcessorVendor = pVM->nem.s.enmCpuVendor == CPUMCPUVENDOR_AMD ? WHvProcessorVendorAmd 1167 1224 : WHvProcessorVendorIntel; 1168 HRESULT hrc = WHvSetPartitionProperty(hPartition, &Property, sizeof(Property));1225 hrc = WHvSetPartitionPropertyWrapper(hPartition, WHvPartitionPropertyCodeProcessorVendor, &Property, sizeof(Property)); 1169 1226 if (FAILED(hrc)) 1170 1227 return VMSetError(pVM, VERR_NEM_VM_CREATE_FAILED, RT_SRC_POS, 1171 1228 "Failed to set WHvPartitionPropertyCodeProcessorVendor to %u: %Rhrc (Last=%#x/%u)", 1172 1229 Property.ProcessorVendor, hrc, RTNtLastStatusValue(), RTNtLastErrorValue()); 1230 #endif 1173 1231 1174 1232 /* Not sure if we really need to set the cache line flush size. */ 1175 1233 RT_ZERO(Property); 1176 Property.PropertyCode = WHvPartitionPropertyCodeProcessorClFlushSize;1177 1234 Property.ProcessorClFlushSize = pVM->nem.s.cCacheLineFlushShift; 1178 hrc = WHvSetPartitionProperty (hPartition, &Property, sizeof(Property));1235 hrc = WHvSetPartitionPropertyWrapper(hPartition, WHvPartitionPropertyCodeProcessorClFlushSize, &Property, sizeof(Property)); 1179 1236 if (FAILED(hrc)) 1180 1237 return VMSetError(pVM, VERR_NEM_VM_CREATE_FAILED, RT_SRC_POS, … … 1189 1246 /* Set the partition property. */ 1190 1247 RT_ZERO(Property); 1191 Property.PropertyCode = WHvPartitionPropertyCodeProcessorFeatures;1192 1248 Property.ProcessorFeatures.AsUINT64 = pVM->nem.s.uCpuFeatures.u64; 1193 hrc = WHvSetPartitionProperty (hPartition, &Property, sizeof(Property));1249 hrc = WHvSetPartitionPropertyWrapper(hPartition, WHvPartitionPropertyCodeProcessorFeatures, &Property, sizeof(Property)); 1194 1250 if (FAILED(hrc)) 1195 1251 return VMSetError(pVM, VERR_NEM_VM_CREATE_FAILED, RT_SRC_POS, … … 2491 2547 * information getters. 2492 2548 * 2549 * Update: All concerns have been addressed in build 17110. 2550 * 2493 2551 * 2494 2552 * - The WHvGetPartitionProperty function uses the same weird design as 2495 2553 * WHvGetCapability, see above. 2554 * 2555 * Update: All concerns have been addressed in build 17110. 2496 2556 * 2497 2557 * … … 2512 2572 * and others for typical pattern for generic information setters and 2513 2573 * getters. 2574 * 2575 * Update: All concerns have been addressed in build 17110. 2576 * 2514 2577 * 2515 2578 *
Note:
See TracChangeset
for help on using the changeset viewer.