VirtualBox

Changeset 1828 in vbox for trunk/src/VBox/VMM


Ignore:
Timestamp:
Mar 30, 2007 12:52:55 PM (18 years ago)
Author:
vboxsync
Message:

Cleaned up cpl checking.

Location:
trunk/src/VBox/VMM
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMAll/CPUMAllRegs.cpp

    r1157 r1828  
    14771477    pVM->cpum.s.fValidHiddenSelRegs = fValid;
    14781478}
     1479
     1480/**
     1481 * Get the current privilege level of the guest.
     1482 *
     1483 * @returns cpl
     1484 * @param   pVM         VM Handle.
     1485 * @param   pRegFrame   Trap register frame.
     1486 */
     1487CPUMDECL(uint32_t) CPUMGetGuestCPL(PVM pVM, PCPUMCTXCORE pCtxCore)
     1488{
     1489    uint32_t cpl;
     1490
     1491    if (!pCtxCore->eflags.Bits.u1VM)
     1492    {
     1493        cpl = (pCtxCore->ss & X86_SEL_RPL);
     1494#ifndef IN_RING0
     1495        if (cpl == 1)
     1496            cpl = 0;
     1497#endif
     1498    }
     1499    else
     1500        cpl = 3;
     1501
     1502    return cpl;
     1503}
  • trunk/src/VBox/VMM/VMMAll/EMAll.cpp

    r1598 r1828  
    18041804        return VERR_EM_INTERPRETER; /* illegal value. */
    18051805
    1806 #ifdef IN_GC
    1807     if (pRegFrame->eflags.Bits.u1VM || (pRegFrame->ss & X86_SEL_RPL) != 1)
    1808 #else
    1809     if (pRegFrame->eflags.Bits.u1VM || (pRegFrame->ss & X86_SEL_RPL) != 0)
    1810 #endif
     1806    /* Get the current privilege level. */
     1807    uint32_t cpl = CPUMGetGuestCPL(pVM, pRegFrame);
     1808    if (cpl != 0)
    18111809        return VERR_EM_INTERPRETER; /* supervisor only */
    18121810
     
    18231821        return VERR_EM_INTERPRETER; /* illegal value. */
    18241822
    1825 #ifdef IN_GC
    1826     if (pRegFrame->eflags.Bits.u1VM || (pRegFrame->ss & X86_SEL_RPL) != 1)
    1827 #else
    1828     if (pRegFrame->eflags.Bits.u1VM || (pRegFrame->ss & X86_SEL_RPL) != 0)
    1829 #endif
     1823    /* Get the current privilege level. */
     1824    uint32_t cpl = CPUMGetGuestCPL(pVM, pRegFrame);
     1825    if (cpl != 0)
    18301826        return VERR_EM_INTERPRETER; /* supervisor only */
    18311827
     
    18481844     * And no complicated prefixes.
    18491845     */
    1850 #ifdef IN_GC
    1851     if (pRegFrame->eflags.Bits.u1VM || (pRegFrame->ss & X86_SEL_RPL) != 1)
    1852 #else
    1853     if (pRegFrame->eflags.Bits.u1VM || (pRegFrame->ss & X86_SEL_RPL) != 0)
    1854 #endif
     1846    /* Get the current privilege level. */
     1847    uint32_t cpl = CPUMGetGuestCPL(pVM, pRegFrame);
     1848    if (cpl != 0)
    18551849    {
    18561850        Log(("WARNING: refusing instruction emulation for user-mode code!!\n"));
  • trunk/src/VBox/VMM/VMMAll/IOMAll.cpp

    r1634 r1828  
    12031203     */
    12041204    uint32_t efl = CPUMRawGetEFlags(pVM, pCtxCore);
    1205     uint32_t cpl = (pCtxCore->ss & X86_SEL_RPL);
    1206 
    1207     if (    (    cpl > 1
     1205    uint32_t cpl = CPUMGetGuestCPL(pVM, pCtxCore);
     1206
     1207    if (    (    cpl > 0
    12081208             &&  X86_EFL_GET_IOPL(efl) < cpl)
    12091209        ||  pCtxCore->eflags.Bits.u1VM      /* IOPL is ignored in V86 mode; always check TSS bitmap */
  • trunk/src/VBox/VMM/VMMAll/IOMAllMMIO.cpp

    r1359 r1828  
    512512    }
    513513
    514     uint32_t cpl;
    515     if (pRegFrame->eflags.Bits.u1VM)
    516         cpl = 3;
    517     else
    518         cpl = (pRegFrame->ss & X86_SEL_RPL);
     514    /* Get the current privilege level. */
     515    uint32_t cpl = CPUMGetGuestCPL(pVM, pRegFrame);
    519516
    520517    /*
  • trunk/src/VBox/VMM/VMMAll/PGMAllBth.h

    r1823 r1828  
    8888# endif
    8989
     90    /* Determine current privilege level */
     91    uint32_t cpl = CPUMGetGuestCPL(pVM, pRegFrame);
    9092
    9193# ifdef PGM_SYNC_DIRTY_BIT
     
    201203                 * Check if the EIP is in a virtual page access handler range.
    202204                 */
    203                 if (    (pRegFrame->ss & X86_SEL_RPL) == 1
    204                     &&  !pRegFrame->eflags.Bits.u1VM)
     205                if (cpl == 0)
    205206                {
    206207                    RTGCPTR pvEIP;
     
    552553
    553554#  ifndef IN_RING0
    554                 Assert((pRegFrame->ss & X86_SEL_RPL) == 1 || (pRegFrame->ss & X86_SEL_RPL) == 3 || pRegFrame->eflags.Bits.u1VM);
    555                 if (CSAMIsEnabled(pVM) && (pRegFrame->ss & X86_SEL_RPL) == 1)
     555                if (CSAMIsEnabled(pVM) && (cpl == 0))
    556556                {
    557557                    uint64_t fPageGst;
     
    699699    /** @todo this stuff is completely broken by the out-of-sync stuff. since we don't use this stuff, that's not really a problem yet. */
    700700    STAM_PROFILE_START(&pVM->pgm.s.StatEIPHandlers, d);
    701     if (    (pRegFrame->ss & X86_SEL_RPL) == 1
    702         &&  !pRegFrame->eflags.Bits.u1VM)
     701    if (cpl == 0)
    703702    {
    704703        RTGCPTR pvEIP;
  • trunk/src/VBox/VMM/VMMAll/PGMAllPhys.cpp

    r1159 r1828  
    17691769     */
    17701770    uint32_t uErr;
    1771     uint32_t cpl;
    1772 
    1773     cpl = (pCtxCore->eflags.Bits.u1VM) ? 3 : (pCtxCore->ss & X86_SEL_RPL);
     1771
     1772    /* Get the current privilege level. */
     1773    uint32_t cpl = CPUMGetGuestCPL(pVM, pCtxCore);
    17741774    switch (rc)
    17751775    {
  • trunk/src/VBox/VMM/VMMAll/PGMAllPool.cpp

    r58 r1828  
    717717        }
    718718
     719        /* Get the current privilege level. */
     720        uint32_t cpl = CPUMGetGuestCPL(pVM, pRegFrame);
     721
    719722        /*
    720723         * Windows is frequently doing small memset() operations (netio test 4k+).
    721724         * We have to deal with these or we'll kill the cache and performance.
    722725         */
     726
    723727        if (    Cpu.pCurInstr->opcode == OP_STOSWD
    724             &&  (pRegFrame->cs & X86_SEL_RPL) <= 1
     728            &&  cpl == 0
    725729            &&  pRegFrame->ecx <= 0x20
    726730            &&  pRegFrame->ecx * 4 <= PAGE_SIZE - ((uintptr_t)pvFault & PAGE_OFFSET_MASK)
  • trunk/src/VBox/VMM/VMMAll/TRPMAll.cpp

    r1791 r1828  
    434434        Assert(PATMAreInterruptsEnabledByCtxCore(pVM, pRegFrame));
    435435
    436         /* Must get the CPL from the SS selector (CS might be conforming) */
    437         if (eflags.Bits.u1VM)
    438             cpl = 3;
    439         else
    440         if ((pRegFrame->ss & X86_SEL_RPL) == 1)
    441             cpl = 0;
    442         else
    443             cpl = (pRegFrame->ss & X86_SEL_RPL);
     436        /* Get the current privilege level. */
     437        cpl = CPUMGetGuestCPL(pVM, pRegFrame);
    444438
    445439        if (GCPtrIDT && iGate * sizeof(VBOXIDTE) >= cbIDT)
  • trunk/src/VBox/VMM/VMMGC/IOMGC.cpp

    r1359 r1828  
    564564
    565565        /* Access verification first; we can't recover from traps inside this instruction, as the port read cannot be repeated. */
    566         uint32_t cpl = (pRegFrame->eflags.Bits.u1VM) ? 3 : (pRegFrame->ss & X86_SEL_RPL);
     566        uint32_t cpl = CPUMGetGuestCPL(pVM, pRegFrame);
     567
    567568        rc = PGMVerifyAccess(pVM, (RTGCUINTPTR)GCPtrDst, cTransfers * cbSize,
    568569                             X86_PTE_RW | ((cpl == 3) ? X86_PTE_US : 0));
     
    669670
    670671        /* Access verification first; we currently can't recover properly from traps inside this instruction */
    671         uint32_t cpl = (pRegFrame->eflags.Bits.u1VM) ? 3 : (pRegFrame->ss & X86_SEL_RPL);
     672        uint32_t cpl = CPUMGetGuestCPL(pVM, pRegFrame);
    672673        rc = PGMVerifyAccess(pVM, (RTGCUINTPTR)GCPtrSrc, cTransfers * cbSize,
    673674                             (cpl == 3) ? X86_PTE_US : 0);
  • trunk/src/VBox/VMM/VMMGC/TRPMGCHandlers.cpp

    r1797 r1828  
    615615    int rc;
    616616
     617    Assert(!pRegFrame->eflags.Bits.u1VM);
     618
    617619    switch (pCpu->pCurInstr->opcode)
    618620    {
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