VirtualBox

儲存庫 vbox 的更動 103156


忽略:
時間撮記:
2024-2-1 上午10:23:11 (13 月 以前)
作者:
vboxsync
svn:sync-xref-src-repo-rev:
161409
訊息:

ValidationKit/{common,testboxscript}: Add a has native API support flag when signing on indicating whether the testbox supports testing through NEM (Hyper-V on Windows, KVM on Linux and Hypervisor.framework on macOS). This is the first part not touching the actual testmanager, bugref:10592

位置:
trunk/src/VBox/ValidationKit
檔案:
修改 3 筆資料

圖例:

未更動
新增
刪除
  • trunk/src/VBox/ValidationKit/common/constants/tbreq.py

    r98103 r103156  
    8686SIGNON_PARAM_HAS_IOMMU          = 'HAS_IOMMU';
    8787SIGNON_PARAM_WITH_RAW_MODE      = 'WITH_RAW_MODE';
     88SIGNON_PARAM_HAS_NATIVE_API     = 'HAS_NATIVE_API';
    8889SIGNON_PARAM_MEM_SIZE           = 'MEM_SIZE';
    8990SIGNON_PARAM_SCRATCH_SIZE       = 'SCRATCH_SIZE';
  • trunk/src/VBox/ValidationKit/testboxscript/TestBoxHelper.cpp

    r101672 r103156  
    6363# include <sys/types.h>
    6464# include <sys/sysctl.h>
     65#elif defined(RT_OS_WINDOWS)
     66# include <iprt/nt/nt-and-windows.h>
     67# include <iprt/ldr.h>
     68
     69extern "C" HRESULT WINAPI
     70WHvGetCapability(UINT32 CapabilityCode, VOID *CapabilityBuffer, UINT32 CapabilityBufferSizeInBytes, UINT32 *WrittenSizeInBytes);
     71#elif defined(RT_OS_LINUX)
     72# include <sys/stat.h>
     73# include <fcntl.h>
     74# include <unistd.h>
    6575#endif
    6676
     
    470480}
    471481
     482
     483static bool isNativeApiSupported(void)
     484{
     485    bool fSupported = false;
     486
     487#if defined(RT_OS_DARWIN)
     488    /*
     489     * The kern.hv_support parameter indicates support for the hypervisor API
     490     * in the kernel.
     491     */
     492    int32_t fHvSupport = 0;
     493    size_t  cbOld = sizeof(fHvSupport);
     494    if (sysctlbyname("kern.hv_support", &fHvSupport, &cbOld, NULL, 0) == 0)
     495    {
     496        if (fHvSupport != 0)
     497            fSupported = true;
     498    }
     499
     500#elif defined(RT_OS_WINDOWS)
     501    /*
     502     * Check whether we can load WinHvPlatform.dll and whether the Hypervisor
     503     * capability is present.
     504     */
     505    RTLDRMOD hLdrMod;
     506    int rc = RTLdrLoadSystem("WinHvPlatform.dll", false /*fNoUnload*/, &hLdrMod);
     507    if (RT_SUCCESS(rc))
     508    {
     509        decltype(WHvGetCapability) *pfnWHvGetCapability;
     510
     511        rc = RTLdrGetSymbol(hLdrMod, "WHvGetCapability", (void **)&pfnWHvGetCapability);
     512        if (RT_SUCCESS(rc))
     513        {
     514            BOOL fHypervisorPresent = FALSE;
     515            SetLastError(0);
     516            HRESULT hrc = pfnWHvGetCapability(0 /*WHvCapabilityCodeHypervisorPresent*/,
     517                                              &fHypervisorPresent,
     518                                              sizeof(fHypervisorPresent),
     519                                              NULL);
     520            if (   SUCCEEDED(hrc)
     521                && fHypervisorPresent)
     522                fSupported = true;
     523        }
     524
     525        RTLdrClose(hLdrMod);
     526    }
     527
     528#elif defined(RT_OS_LINUX)
     529    /* Check by opening /dev/kvm. */
     530    int fdKvm = open("/dev/kvm", O_RDWR | O_CLOEXEC);
     531    if (fdKvm >= 0)
     532    {
     533        close(fdKvm);
     534        fSupported = true;
     535    }
     536#endif 
     537
     538    return fSupported;
     539}
     540
     541/** Print the 'true' if native API virtualization is supported, 'false' if not and
     542 * 'dunno' if we cannot tell. */
     543static RTEXITCODE handlerNativeApi(int argc, char **argv)
     544{
     545    NOREF(argc); NOREF(argv);
     546
     547    int cch = RTPrintf(isNativeApiSupported() ? "true\n" : "false\n");
     548    return cch > 0 ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
     549}
     550
     551
    472552typedef enum { HWVIRTTYPE_NONE, HWVIRTTYPE_VTX, HWVIRTTYPE_AMDV, HVIRTTYPE_ARMV8 } HWVIRTTYPE;
    473553static HWVIRTTYPE isHwVirtSupported(void)
    474554{
    475 #if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
     555    /* No native virtualization supported on macOS anymore (for the VBox versions we care about). */
     556#if !defined RT_OS_DARWIN
     557# if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
    476558    uint32_t uEax, uEbx, uEcx, uEdx;
    477559
     
    493575            return HWVIRTTYPE_AMDV;
    494576    }
    495 #elif defined(RT_ARCH_ARM64)
    496 # if defined(RT_OS_DARWIN)
    497     /*
    498      * The kern.hv_support parameter indicates support for the hypervisor API in the
    499      * kernel, which is the only way for virtualization on macOS on Apple Silicon.
    500      */
    501     int32_t fHvSupport = 0;
    502     size_t  cbOld = sizeof(fHvSupport);
    503     if (sysctlbyname("kern.hv_support", &fHvSupport, &cbOld, NULL, 0) == 0)
    504     {
    505         if (fHvSupport != 0)
    506             return HVIRTTYPE_ARMV8;
    507     }
    508577# endif
    509578#endif
     
    529598
    530599    HWVIRTTYPE  enmHwVirt  = isHwVirtSupported();
     600    if (enmHwVirt == HWVIRTTYPE_NONE)
     601        fSupported = 0;
    531602#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
    532     if (enmHwVirt == HWVIRTTYPE_AMDV)
     603    else if (enmHwVirt == HWVIRTTYPE_AMDV)
    533604    {
    534605        uint32_t uEax, uEbx, uEcx, uEdx;
     
    589660        }
    590661    }
    591 # elif defined(RT_OS_DARWIN)
    592     else if (enmHwVirt == HWVIRTTYPE_VTX)
    593     {
    594         /*
    595          * The kern.hv_support parameter indicates support for the hypervisor API in the
    596          * kernel, which in turn is documented require nested paging and unrestricted
    597          * guest mode.  So, if it's there and set we've got nested paging.  Howeber, if
    598          * it's there and clear we have not definite answer as it might be due to lack
    599          * of unrestricted guest mode support.
    600          */
    601         int32_t fHvSupport = 0;
    602         size_t  cbOld = sizeof(fHvSupport);
    603         if (sysctlbyname("kern.hv_support", &fHvSupport, &cbOld, NULL, 0) == 0)
    604         {
    605             if (fHvSupport != 0)
    606                 fSupported = true;
    607         }
    608     }
    609662# endif
    610 #elif defined(RT_ARCH_ARM64)
    611     /* On ARM nested paging is always supported if virtualization is there. */
    612     if (enmHwVirt == HVIRTTYPE_ARMV8)
    613         fSupported = 1;
    614663#endif
    615664
     
    625674    NOREF(argc); NOREF(argv);
    626675    HWVIRTTYPE  enmHwVirt  = isHwVirtSupported();
     676    bool        fNativeApi = isNativeApiSupported();
    627677    int         fSupported = 0;
    628678
    629     if (enmHwVirt != HWVIRTTYPE_NONE)
     679    if (   enmHwVirt != HWVIRTTYPE_NONE
     680        || fNativeApi)
    630681    {
    631682#if defined(RT_ARCH_AMD64)
     
    767818        { "nestedpaging",   handlerCpuNestedPaging, true },
    768819        { "longmode",       handlerCpuLongMode,     true },
     820        { "nativeapi",      handlerNativeApi,       true },
    769821        { "memsize",        handlerMemSize,         true },
    770822        { "report",         handlerReport,          true },
  • trunk/src/VBox/ValidationKit/testboxscript/testboxscript_real.py

    r98651 r103156  
    184184            constants.tbreq.SIGNON_PARAM_HAS_64_BIT_GUEST: { self.VALUE: self._can64BitGuest(),        self.FN: None },
    185185            constants.tbreq.SIGNON_PARAM_HAS_IOMMU:        { self.VALUE: self._hasHostIoMmu(),         self.FN: None },
     186            constants.tbreq.SIGNON_PARAM_HAS_NATIVE_API:   { self.VALUE: self._hasHostNativeApi(),     self.FN: None },
    186187            #constants.tbreq.SIGNON_PARAM_WITH_RAW_MODE:    { self.VALUE: self._withRawModeSupport(),   self.FN: None },
    187188            constants.tbreq.SIGNON_PARAM_SCRIPT_REV:       { self.VALUE: self._getScriptRev(),         self.FN: None },
     
    559560            self._oOptions.fHasIoMmu = False;
    560561        return self._oOptions.fHasIoMmu;
     562
     563    def _hasHostNativeApi(self):
     564        """
     565        Check if the host supports the native API/NEM mode.
     566        """
     567        if self._oOptions.fHasNativeApi is None:
     568            self._oOptions.fHasNativeApi = self._getHelperOutput('nativeapi');
     569        return self._oOptions.fHasNativeApi;
    561570
    562571    def _withRawModeSupport(self):
     
    10051014                          dest="fCan64BitGuest", action="store_false", default=None,
    10061015                          help="Host cannot execute 64-bit guests");
     1016        parser.add_option("--native-api",
     1017                          dest="fHasNativeApi", action="store_true", default=None,
     1018                          help="Native API virtualization is available");
     1019        parser.add_option("--no-native-api",
     1020                          dest="fHasNativeApi", action="store_false", default=None,
     1021                          help="Native API virtualization is not available");
    10071022        parser.add_option("--io-mmu",
    10081023                          dest="fHasIoMmu", action="store_true", default=None,
注意: 瀏覽 TracChangeset 來幫助您使用更動檢視器

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