VirtualBox

Changeset 64781 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Dec 4, 2016 1:00:49 PM (8 years ago)
Author:
vboxsync
Message:

ValidationKit/TestBoxHelper: On Linux we can check whether EPT is supported by looking for ept in /proc/cpuinfo

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/testboxscript/TestBoxHelper.cpp

    r64616 r64781  
    516516        }
    517517    }
     518# if defined(RT_OS_LINUX)
     519    else if (enmHwVirt == HWVIRTTYPE_VTX)
     520    {
     521        /*
     522         * For Intel there is no generic way to query EPT support but on
     523         * Linux we can resort to checking for the EPT flag in /proc/cpuinfo
     524         */
     525        RTFILE hFileCpu;
     526        int rc = RTFileOpen(&hFileCpu, "/proc/cpuinfo", RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_NONE);
     527        if (RT_SUCCESS(rc))
     528        {
     529            /*
     530             * Read enough to fit the first CPU entry in, we only check the first
     531             * CPU as all the others should have the same features.
     532             */
     533            char szBuf[_4K];
     534            size_t cbRead = 0;
     535
     536            RT_ZERO(szBuf); /* Ensure proper termination. */
     537            rc = RTFileRead(hFileCpu, &szBuf[0], sizeof(szBuf) - 1, &cbRead);
     538            if (RT_SUCCESS(rc))
     539            {
     540                /* Look for the start of the flags section. */
     541                char *pszStrFlags = RTStrStr(&szBuf[0], "flags");
     542                if (pszStrFlags)
     543                {
     544                    /* Look for the end as indicated by new line. */
     545                    char *pszEnd = pszStrFlags;
     546                    while (   *pszEnd != '\0'
     547                           && *pszEnd != '\n')
     548                        pszEnd++;
     549                    *pszEnd = '\0'; /* Cut off everything after the flags section. */
     550
     551                    /*
     552                     * Search for the ept flag indicating support and the absence meaning
     553                     * not supported.
     554                     */
     555                    if (RTStrStr(pszStrFlags, "ept"))
     556                        fSupported = 1;
     557                    else
     558                        fSupported = 0;
     559                }
     560            }
     561            RTFileClose(hFileCpu);
     562        }
     563    }
     564# endif
    518565#endif
    519566
Note: See TracChangeset for help on using the changeset viewer.

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