VirtualBox

Changeset 55318 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Apr 17, 2015 8:25:49 AM (10 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
99638
Message:

forward-ported r98913 from 4.3 to trunk (Support/Darwin: on recent CPUs set EFLAGS.AC before executing the IOCtl to disable SMAP)

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/VBox

  • trunk/src/VBox/HostDrivers/Support/darwin/SUPDrv-darwin.cpp

    r54581 r55318  
    5252#include <iprt/power.h>
    5353#include <iprt/dbg.h>
     54#include <iprt/x86.h>
    5455#include <VBox/err.h>
    5556#include <VBox/log.h>
     
    105106static int              VBoxDrvDarwinClose(dev_t Dev, int fFlags, int fDevType, struct proc *pProcess);
    106107static int              VBoxDrvDarwinIOCtl(dev_t Dev, u_long iCmd, caddr_t pData, int fFlags, struct proc *pProcess);
     108static int              VBoxDrvDarwinIOCtlSMAP(dev_t Dev, u_long iCmd, caddr_t pData, int fFlags, struct proc *pProcess);
    107109static int              VBoxDrvDarwinIOCtlSlow(PSUPDRVSESSION pSession, u_long iCmd, caddr_t pData, struct proc *pProcess);
    108110
     
    113115
    114116static void             vboxdrvDarwinResolveSymbols(void);
     117static bool             vboxdrvDarwinCpuHasSMAP(void);
    115118
    116119
     
    275278            if (RT_SUCCESS(rc))
    276279            {
     280                if (vboxdrvDarwinCpuHasSMAP())
     281                    g_DevCW.d_ioctl = VBoxDrvDarwinIOCtlSMAP;
    277282                /*
    278283                 * Registering ourselves as a character device.
     
    598603
    599604/**
     605 * Alternative Device I/O Control entry point on hosts with SMAP support.
     606 *
     607 * @returns Darwin for slow IOCtls and VBox status code for the fast ones.
     608 * @param   Dev         The device number (major+minor).
     609 * @param   iCmd        The IOCtl command.
     610 * @param   pData       Pointer to the data (if any it's a SUPDRVIOCTLDATA (kernel copy)).
     611 * @param   fFlags      Flag saying we're a character device (like we didn't know already).
     612 * @param   pProcess    The process issuing this request.
     613 */
     614static int VBoxDrvDarwinIOCtlSMAP(dev_t Dev, u_long iCmd, caddr_t pData, int fFlags, struct proc *pProcess)
     615{
     616    /*
     617     * Allow VBox R0 code to touch R3 memory. Setting the AC bit disables the
     618     * SMAP check.
     619     */
     620    RTCCUINTREG uFlags = ASMGetFlags();
     621    ASMSetAC();
     622    int rc = VBoxDrvDarwinIOCtl(Dev, iCmd, pData, fFlags, pProcess);
     623    ASMSetFlags(uFlags);
     624    return rc;
     625}
     626
     627
     628/**
    600629 * Worker for VBoxDrvDarwinIOCtl that takes the slow IOCtl functions.
    601630 *
     
    12861315}
    12871316
     1317/**
     1318 * Check if the CPU has SMAP support.
     1319 */
     1320static bool vboxdrvDarwinCpuHasSMAP(void)
     1321{
     1322    uint32_t uMaxId, uEAX, uEBX, uECX, uEDX;
     1323    ASMCpuId(0, &uMaxId, &uEBX, &uECX, &uEDX);
     1324    if (   ASMIsValidStdRange(uMaxId)
     1325        && uMaxId >= 0x00000007)
     1326    {
     1327        ASMCpuId_Idx_ECX(0x00000007, 0, &uEAX, &uEBX, &uECX, &uEDX);
     1328        if (uEBX & X86_CPUID_STEXT_FEATURE_EBX_SMAP)
     1329            return true;
     1330    }
     1331    return false;
     1332}
    12881333
    12891334RTDECL(int) SUPR0Printf(const char *pszFormat, ...)
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