VirtualBox

Changeset 55318 in 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:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/include/iprt/asm-amd64-x86.h

    r55310 r55318  
    30933093}
    30943094
     3095
     3096/*
     3097 * Clear the AC bit in the EFLAGS register.
     3098 * Requires the X86_CPUID_STEXT_FEATURE_EBX_SMAP CPUID bit set.
     3099 * Requires to be executed in R0.
     3100 */
     3101DECLINLINE(void) ASMClearAC(void)
     3102{
     3103#if RT_INLINE_ASM_GNU_STYLE
     3104    __asm__ __volatile__ (".byte 0x0f,0x01,0xca\n\t");
     3105#else
     3106    __asm
     3107    {
     3108        _emit   0x0f
     3109        _emit   0x01
     3110        _emit   0xca
     3111    }
     3112#endif
     3113}
     3114
     3115
     3116/*
     3117 * Set the AC bit in the EFLAGS register.
     3118 * Requires the X86_CPUID_STEXT_FEATURE_EBX_SMAP CPUID bit set.
     3119 * Requires to be executed in R0.
     3120 */
     3121DECLINLINE(void) ASMSetAC(void)
     3122{
     3123#if RT_INLINE_ASM_GNU_STYLE
     3124    __asm__ __volatile__ (".byte 0x0f,0x01,0xcb\n\t");
     3125#else
     3126    __asm
     3127    {
     3128        _emit   0x0f
     3129        _emit   0x01
     3130        _emit   0xcb
     3131    }
     3132#endif
     3133}
     3134
    30953135/** @} */
    30963136#endif
  • 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.

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