VirtualBox

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


Ignore:
Timestamp:
Sep 25, 2019 9:12:34 AM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
133599
Message:

VMM: bugref:9566 TRPM enhancements and cleanup. Bumps TRPM saved-state version.

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

Legend:

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

    r80815 r81002  
    11221122 * @param   uVector         The event vector.
    11231123 * @param   enmTrpmEvent    The TRPM event.
     1124 * @param   fIcebp          Whether the \#DB vector is caused by an INT1/ICEBP
     1125 *                          instruction.
    11241126 */
    1125 VMM_INT_DECL(uint32_t) HMTrpmEventTypeToVmxEventType(uint8_t uVector, TRPMEVENT enmTrpmEvent)
     1127VMM_INT_DECL(uint32_t) HMTrpmEventTypeToVmxEventType(uint8_t uVector, TRPMEVENT enmTrpmEvent, bool fIcebp)
    11261128{
    11271129    uint32_t uIntInfoType = 0;
    11281130    if (enmTrpmEvent == TRPM_TRAP)
    11291131    {
    1130         /** @todo r=ramshankar: TRPM currently offers no way to determine a \#DB that was
    1131          *        generated using INT1 (ICEBP). */
     1132        Assert(!fIcebp);
    11321133        switch (uVector)
    11331134        {
     
    11561157    }
    11571158    else if (enmTrpmEvent == TRPM_HARDWARE_INT)
     1159    {
     1160        Assert(!fIcebp);
    11581161        uIntInfoType |= (VMX_IDT_VECTORING_INFO_TYPE_EXT_INT << VMX_IDT_VECTORING_INFO_TYPE_SHIFT);
     1162    }
    11591163    else if (enmTrpmEvent == TRPM_SOFTWARE_INT)
    11601164    {
     
    11661170                break;
    11671171
     1172            case X86_XCPT_DB:
     1173            {
     1174                if (fIcebp)
     1175                {
     1176                    uIntInfoType |= (VMX_IDT_VECTORING_INFO_TYPE_PRIV_SW_XCPT << VMX_IDT_VECTORING_INFO_TYPE_SHIFT);
     1177                    break;
     1178                }
     1179                RT_FALL_THRU();
     1180            }
    11681181            default:
    11691182                uIntInfoType |= (VMX_IDT_VECTORING_INFO_TYPE_SW_INT << VMX_IDT_VECTORING_INFO_TYPE_SHIFT);
  • trunk/src/VBox/VMM/VMMAll/IEMAll.cpp

    r80808 r81002  
    1428014280        uint8_t     u8TrapNo;
    1428114281        TRPMEVENT   enmType;
    14282         RTGCUINT    uErrCode;
     14282        uint32_t    uErrCode;
    1428314283        RTGCPTR     uCr2;
    14284         int rc2 = TRPMQueryTrapAll(pVCpu, &u8TrapNo, &enmType, &uErrCode, &uCr2, NULL /* pu8InstLen */); AssertRC(rc2);
     14284        int rc2 = TRPMQueryTrapAll(pVCpu, &u8TrapNo, &enmType, &uErrCode, &uCr2, NULL /* pu8InstLen */, NULL /* fIcebp */);
     14285        AssertRC(rc2);
    1428514286        Assert(enmType == TRPM_HARDWARE_INT);
    1428614287        VBOXSTRICTRC rcStrict = IEMInjectTrap(pVCpu, u8TrapNo, enmType, (uint16_t)uErrCode, uCr2, 0 /* cbInstr */);
     
    1466314664    uint8_t     u8TrapNo;
    1466414665    TRPMEVENT   enmType;
    14665     RTGCUINT    uErrCode;
     14666    uint32_t    uErrCode;
    1466614667    RTGCUINTPTR uCr2;
    1466714668    uint8_t     cbInstr;
    14668     int rc = TRPMQueryTrapAll(pVCpu, &u8TrapNo, &enmType, &uErrCode, &uCr2, &cbInstr);
     14669    int rc = TRPMQueryTrapAll(pVCpu, &u8TrapNo, &enmType, &uErrCode, &uCr2, &cbInstr, NULL /* fIcebp */);
    1466914670    if (RT_FAILURE(rc))
    1467014671        return rc;
    1467114672
     14673    /** @todo r=ramshankar: Pass ICEBP info. to IEMInjectTrap() below and handle
     14674     *        ICEBP \#DB injection as a special case. */
    1467214675    VBOXSTRICTRC rcStrict = IEMInjectTrap(pVCpu, u8TrapNo, enmType, uErrCode, uCr2, cbInstr);
    1467314676#ifdef VBOX_WITH_NESTED_HWVIRT_SVM
  • trunk/src/VBox/VMM/VMMAll/IEMAllCImplVmxInstr.cpp.h

    r80912 r81002  
    70917091    }
    70927092
     7093    if (VMX_ENTRY_INT_INFO_TYPE(uEntryIntInfo) == VMX_ENTRY_INT_INFO_TYPE_PRIV_SW_XCPT)
     7094    {
     7095        TRPMSetTrapDueToIcebp(pVCpu);
     7096        Log(("%s: Injecting: icebp\n", pszInstr));
     7097    }
     7098
    70937099    NOREF(pszInstr);
    70947100}
  • trunk/src/VBox/VMM/VMMAll/PGMAllPhys.cpp

    r80333 r81002  
    36243624VMMDECL(int) PGMPhysInterpretedRead(PVMCPUCC pVCpu, PCPUMCTXCORE pCtxCore, void *pvDst, RTGCUINTPTR GCPtrSrc, size_t cb)
    36253625{
     3626    NOREF(pCtxCore);
    36263627    PVMCC pVM = pVCpu->CTX_SUFF(pVM);
    36273628    Assert(cb <= PAGE_SIZE);
     
    37693770    }
    37703771    Log(("PGMPhysInterpretedRead: GCPtrSrc=%RGv cb=%#x -> #PF(%#x)\n", GCPtrSrc, cb, uErr));
    3771     return TRPMRaiseXcptErrCR2(pVCpu, pCtxCore, X86_XCPT_PF, uErr, GCPtrSrc);
     3772    rc = TRPMAssertXcptPF(pVCpu, GCPtrSrc, uErr);
     3773    if (RT_SUCCESS(rc))
     3774        return VINF_EM_RAW_GUEST_TRAP;
     3775    return rc;
    37723776}
    37733777
     
    38073811                                              bool fRaiseTrap)
    38083812{
     3813    NOREF(pCtxCore);
    38093814    PVMCC pVM = pVCpu->CTX_SUFF(pVM);
    38103815    Assert(cb <= PAGE_SIZE);
     
    39633968    {
    39643969        Log(("PGMPhysInterpretedReadNoHandlers: GCPtrSrc=%RGv cb=%#x -> Raised #PF(%#x)\n", GCPtrSrc, cb, uErr));
    3965         return TRPMRaiseXcptErrCR2(pVCpu, pCtxCore, X86_XCPT_PF, uErr, GCPtrSrc);
     3970        rc = TRPMAssertXcptPF(pVCpu, GCPtrSrc, uErr);
     3971        if (RT_SUCCESS(rc))
     3972            return VINF_EM_RAW_GUEST_TRAP;
     3973        return rc;
    39663974    }
    39673975    Log(("PGMPhysInterpretedReadNoHandlers: GCPtrSrc=%RGv cb=%#x -> #PF(%#x) [!raised]\n", GCPtrSrc, cb, uErr));
     
    40004008                                               size_t cb, bool fRaiseTrap)
    40014009{
     4010    NOREF(pCtxCore);
    40024011    Assert(cb <= PAGE_SIZE);
    40034012    PVMCC pVM = pVCpu->CTX_SUFF(pVM);
     
    41714180    {
    41724181        Log(("PGMPhysInterpretedWriteNoHandlers: GCPtrDst=%RGv cb=%#x -> Raised #PF(%#x)\n", GCPtrDst, cb, uErr));
    4173         return TRPMRaiseXcptErrCR2(pVCpu, pCtxCore, X86_XCPT_PF, uErr, GCPtrDst);
     4182        rc = TRPMAssertXcptPF(pVCpu, GCPtrDst, uErr);
     4183        if (RT_SUCCESS(rc))
     4184            return VINF_EM_RAW_GUEST_TRAP;
     4185        return rc;
    41744186    }
    41754187    Log(("PGMPhysInterpretedWriteNoHandlers: GCPtrDst=%RGv cb=%#x -> #PF(%#x) [!raised]\n", GCPtrDst, cb, uErr));
  • trunk/src/VBox/VMM/VMMAll/TRPMAll.cpp

    r80333 r81002  
    9393 * @param   pVCpu                   The cross context virtual CPU structure.
    9494 */
    95 VMMDECL(RTGCUINT) TRPMGetErrorCode(PVMCPU pVCpu)
     95VMMDECL(uint32_t) TRPMGetErrorCode(PVMCPU pVCpu)
    9696{
    9797    AssertMsg(pVCpu->trpm.s.uActiveVector != ~0U, ("No active trap!\n"));
     
    151151
    152152/**
     153 * Checks if the current \#DB exception is due to an INT1/ICEBP instruction.
     154 *
     155 * The caller is responsible for making sure there is an active trap.
     156 *
     157 * @returns @c true if it's due to INT1/ICEBP, @c false if not.
     158 *
     159 * @param   pVCpu               The cross context virtual CPU structure.
     160 */
     161VMMDECL(bool) TRPMIsTrapDueToIcebp(PVMCPU pVCpu)
     162{
     163    AssertMsg(pVCpu->trpm.s.uActiveVector != ~0U, ("No active trap!\n"));
     164    return pVCpu->trpm.s.fIcebp;
     165}
     166
     167
     168/**
    153169 * Clears the current active trap/exception/interrupt.
    154170 *
     
    204220    pVCpu->trpm.s.uActiveVector               = u8TrapNo;
    205221    pVCpu->trpm.s.enmActiveType               = enmType;
    206     pVCpu->trpm.s.uActiveErrorCode            = ~(RTGCUINT)0;
     222    pVCpu->trpm.s.uActiveErrorCode            = ~0U;
    207223    pVCpu->trpm.s.uActiveCR2                  = 0xdeadface;
    208224    pVCpu->trpm.s.cbInstr                     = UINT8_MAX;
     225    pVCpu->trpm.s.fIcebp                      = false;
    209226    return VINF_SUCCESS;
    210227}
     
    222239 * @param   uErrorCode          The error code for the page-fault.
    223240 */
    224 VMMDECL(int) TRPMAssertXcptPF(PVMCPUCC pVCpu, RTGCUINTPTR uCR2, RTGCUINT uErrorCode)
    225 {
    226     Log2(("TRPMAssertXcptPF: uCR2=%RGv uErrorCode=%RGv\n", uCR2, uErrorCode)); /** @todo RTGCUINT to be fixed. */
     241VMMDECL(int) TRPMAssertXcptPF(PVMCPUCC pVCpu, RTGCUINTPTR uCR2, uint32_t uErrorCode)
     242{
     243    Log2(("TRPMAssertXcptPF: uCR2=%RGv uErrorCode=%#RX32\n", uCR2, uErrorCode));
    227244
    228245    /*
     
    254271 * @param   uErrorCode          The new error code.
    255272 */
    256 VMMDECL(void) TRPMSetErrorCode(PVMCPU pVCpu, RTGCUINT uErrorCode)
    257 {
    258     Log2(("TRPMSetErrorCode: uErrorCode=%RGv\n", uErrorCode)); /** @todo RTGCUINT mess! */
    259     AssertMsg(pVCpu->trpm.s.uActiveVector != ~0U, ("No active trap!\n"));
     273VMMDECL(void) TRPMSetErrorCode(PVMCPU pVCpu, uint32_t uErrorCode)
     274{
     275    Log2(("TRPMSetErrorCode: uErrorCode=%#RX32\n", uErrorCode));
     276    AssertMsg(pVCpu->trpm.s.uActiveVector != ~0U, ("No active trap!\n"));
     277    AssertMsg(   pVCpu->trpm.s.enmActiveType == TRPM_TRAP
     278              || (   pVCpu->trpm.s.enmActiveType == TRPM_SOFTWARE_INT && pVCpu->trpm.s.uActiveVector == X86_XCPT_DB),
     279              ("Not hardware exception or privileged software exception (INT1/ICEBP)!\n"));
    260280    pVCpu->trpm.s.uActiveErrorCode = uErrorCode;
    261281#ifdef VBOX_STRICT
    262     switch (pVCpu->trpm.s.uActiveVector)
    263     {
    264         case X86_XCPT_TS: case X86_XCPT_NP: case X86_XCPT_SS: case X86_XCPT_GP: case X86_XCPT_PF:
    265             AssertMsg(uErrorCode != ~(RTGCUINT)0, ("Invalid uErrorCode=%#x u8TrapNo=%d\n", uErrorCode, pVCpu->trpm.s.uActiveVector));
    266             break;
    267         case X86_XCPT_AC: case X86_XCPT_DF:
    268             AssertMsg(uErrorCode == 0,            ("Invalid uErrorCode=%#x u8TrapNo=%d\n", uErrorCode, pVCpu->trpm.s.uActiveVector));
    269             break;
    270         default:
    271             AssertMsg(uErrorCode == ~(RTGCUINT)0, ("Invalid uErrorCode=%#x u8TrapNo=%d\n", uErrorCode, pVCpu->trpm.s.uActiveVector));
    272             break;
     282    if (pVCpu->trpm.s.enmActiveType == TRPM_TRAP)
     283    {
     284        switch (pVCpu->trpm.s.uActiveVector)
     285        {
     286            case X86_XCPT_TS: case X86_XCPT_NP: case X86_XCPT_SS: case X86_XCPT_GP: case X86_XCPT_PF:
     287                AssertMsg(uErrorCode != ~0U, ("Invalid uErrorCode=%#x u8TrapNo=%u\n", uErrorCode, pVCpu->trpm.s.uActiveVector));
     288                break;
     289            case X86_XCPT_AC: case X86_XCPT_DF:
     290                AssertMsg(uErrorCode == 0,   ("Invalid uErrorCode=%#x u8TrapNo=%u\n", uErrorCode, pVCpu->trpm.s.uActiveVector));
     291                break;
     292            default:
     293                AssertMsg(uErrorCode == ~0U, ("Invalid uErrorCode=%#x u8TrapNo=%u\n", uErrorCode, pVCpu->trpm.s.uActiveVector));
     294                break;
     295        }
    273296    }
    274297#endif
     
    310333    Log2(("TRPMSetInstrLength: cbInstr=%u\n", cbInstr));
    311334    AssertMsg(pVCpu->trpm.s.uActiveVector != ~0U, ("No active trap!\n"));
    312     /** @todo We should be able to set the instruction length for a \#DB raised by
    313      *        INT1/ICEBP as well. However, TRPM currently has no way to distinguish
    314      *        INT1/ICEBP from regular \#DB. */
    315335    AssertMsg(   pVCpu->trpm.s.enmActiveType == TRPM_SOFTWARE_INT
    316336              || (   pVCpu->trpm.s.enmActiveType == TRPM_TRAP
     
    323343
    324344/**
     345 * Sets if the current \#DB exception is due to an INT1/ICEBP instruction.
     346 *
     347 * The caller is responsible for making sure there is an active trap and it's a
     348 * \#DB.
     349 *
     350 * @param   pVCpu               The cross context virtual CPU structure.
     351 */
     352VMMDECL(void) TRPMSetTrapDueToIcebp(PVMCPU pVCpu)
     353{
     354    AssertMsg(pVCpu->trpm.s.enmActiveType == TRPM_SOFTWARE_INT, ("Trap type for INT1/ICEBP invalid!"));
     355    AssertMsg(pVCpu->trpm.s.uActiveVector == X86_XCPT_DB, ("INT1/ICEBP must be indicated by a #DB!\n"));
     356    pVCpu->trpm.s.fIcebp = true;
     357}
     358
     359
     360/**
    325361 * Checks if the current active trap/interrupt/exception/fault/whatever is a software
    326362 * interrupt or not.
     
    357393 *
    358394 * @returns VBox status code.
    359  * @param   pVCpu                   The cross context virtual CPU structure.
    360  * @param   pu8TrapNo               Where to store the trap number.
    361  * @param   pEnmType                Where to store the trap type
    362  * @param   puErrorCode             Where to store the error code associated with some traps.
    363  *                                  ~0U is stored if the trap has no error code.
    364  * @param   puCR2                   Where to store the CR2 associated with a trap 0E.
    365  * @param   pcbInstr                Where to store the instruction-length
    366  *                                  associated with some traps.
    367  */
    368 VMMDECL(int) TRPMQueryTrapAll(PVMCPU pVCpu, uint8_t *pu8TrapNo, TRPMEVENT *pEnmType, PRTGCUINT puErrorCode, PRTGCUINTPTR puCR2,
    369                                uint8_t *pcbInstr)
    370 {
    371     /*
    372      * Check if we have a trap at present.
     395 * @param   pVCpu           The cross context virtual CPU structure.
     396 * @param   pu8TrapNo       Where to store the trap number.
     397 * @param   pEnmType        Where to store the trap type.
     398 * @param   puErrorCode     Where to store the error code associated with some
     399 *                          traps. ~0U is stored if the trap has no error code.
     400 * @param   puCR2           Where to store the CR2 associated with a trap 0E.
     401 * @param   pcbInstr        Where to store the instruction-length associated with
     402 *                          some traps.
     403 * @param   pfIcebp         Where to store whether the trap is a \#DB caused by an
     404 *                          INT1/ICEBP instruction.
     405 */
     406VMMDECL(int) TRPMQueryTrapAll(PVMCPU pVCpu, uint8_t *pu8TrapNo, TRPMEVENT *pEnmType, uint32_t *puErrorCode, PRTGCUINTPTR puCR2,
     407                              uint8_t *pcbInstr, bool *pfIcebp)
     408{
     409    /*
     410     * Check if we have an active trap.
    373411     */
    374412    if (pVCpu->trpm.s.uActiveVector == ~0U)
     
    385423    if (pcbInstr)
    386424        *pcbInstr       = pVCpu->trpm.s.cbInstr;
     425    if (pfIcebp)
     426        *pfIcebp        = pVCpu->trpm.s.fIcebp;
    387427    return VINF_SUCCESS;
    388428}
    389429
    390 
    391 /**
    392  * Save the active trap.
    393  *
    394  * This routine useful when doing try/catch in the hypervisor.
    395  * Any function which uses temporary trap handlers should
    396  * probably also use this facility to save the original trap.
    397  *
    398  * @param   pVCpu       The cross context virtual CPU structure.
    399  */
    400 VMMDECL(void) TRPMSaveTrap(PVMCPU pVCpu)
    401 {
    402     pVCpu->trpm.s.uSavedVector        = pVCpu->trpm.s.uActiveVector;
    403     pVCpu->trpm.s.enmSavedType        = pVCpu->trpm.s.enmActiveType;
    404     pVCpu->trpm.s.uSavedErrorCode     = pVCpu->trpm.s.uActiveErrorCode;
    405     pVCpu->trpm.s.uSavedCR2           = pVCpu->trpm.s.uActiveCR2;
    406     pVCpu->trpm.s.cbSavedInstr        = pVCpu->trpm.s.cbInstr;
    407 }
    408 
    409 
    410 /**
    411  * Restore a saved trap.
    412  *
    413  * Multiple restores of a saved trap is possible.
    414  *
    415  * @param   pVCpu       The cross context virtual CPU structure.
    416  */
    417 VMMDECL(void) TRPMRestoreTrap(PVMCPU pVCpu)
    418 {
    419     pVCpu->trpm.s.uActiveVector       = pVCpu->trpm.s.uSavedVector;
    420     pVCpu->trpm.s.enmActiveType       = pVCpu->trpm.s.enmSavedType;
    421     pVCpu->trpm.s.uActiveErrorCode    = pVCpu->trpm.s.uSavedErrorCode;
    422     pVCpu->trpm.s.uActiveCR2          = pVCpu->trpm.s.uSavedCR2;
    423     pVCpu->trpm.s.cbInstr             = pVCpu->trpm.s.cbSavedInstr;
    424 }
    425 
    426 
    427 /**
    428  * Raises a cpu exception which doesn't take an error code.
    429  *
    430  * This function may or may not dispatch the exception before returning.
    431  *
    432  * @returns VBox status code fit for scheduling.
    433  * @retval  VINF_EM_RAW_GUEST_TRAP if the exception was left pending.
    434  * @retval  VINF_TRPM_XCPT_DISPATCHED if the exception was raised and dispatched for raw-mode execution.
    435  * @retval  VINF_EM_RESCHEDULE_REM if the exception was dispatched and cannot be executed in raw-mode.
    436  *
    437  * @param   pVCpu       The cross context virtual CPU structure of the calling EMT.
    438  * @param   pCtxCore    The CPU context core.
    439  * @param   enmXcpt     The exception.
    440  */
    441 VMMDECL(int) TRPMRaiseXcpt(PVMCPU pVCpu, PCPUMCTXCORE pCtxCore, X86XCPT enmXcpt)
    442 {
    443     LogFlow(("TRPMRaiseXcptErr: cs:eip=%RTsel:%RX32 enmXcpt=%#x\n", pCtxCore->cs.Sel, pCtxCore->eip, enmXcpt));
    444     NOREF(pCtxCore);
    445 /** @todo dispatch the trap. */
    446     pVCpu->trpm.s.uActiveVector            = enmXcpt;
    447     pVCpu->trpm.s.enmActiveType            = TRPM_TRAP;
    448     pVCpu->trpm.s.uActiveErrorCode         = 0xdeadbeef;
    449     pVCpu->trpm.s.uActiveCR2               = 0xdeadface;
    450     pVCpu->trpm.s.cbInstr                  = UINT8_MAX;
    451     return VINF_EM_RAW_GUEST_TRAP;
    452 }
    453 
    454 
    455 /**
    456  * Raises a cpu exception with an errorcode.
    457  *
    458  * This function may or may not dispatch the exception before returning.
    459  *
    460  * @returns VBox status code fit for scheduling.
    461  * @retval  VINF_EM_RAW_GUEST_TRAP if the exception was left pending.
    462  * @retval  VINF_TRPM_XCPT_DISPATCHED if the exception was raised and dispatched for raw-mode execution.
    463  * @retval  VINF_EM_RESCHEDULE_REM if the exception was dispatched and cannot be executed in raw-mode.
    464  *
    465  * @param   pVCpu       The cross context virtual CPU structure of the calling EMT.
    466  * @param   pCtxCore    The CPU context core.
    467  * @param   enmXcpt     The exception.
    468  * @param   uErr        The error code.
    469  */
    470 VMMDECL(int) TRPMRaiseXcptErr(PVMCPU pVCpu, PCPUMCTXCORE pCtxCore, X86XCPT enmXcpt, uint32_t uErr)
    471 {
    472     LogFlow(("TRPMRaiseXcptErr: cs:eip=%RTsel:%RX32 enmXcpt=%#x uErr=%RX32\n", pCtxCore->cs.Sel, pCtxCore->eip, enmXcpt, uErr));
    473     NOREF(pCtxCore);
    474 /** @todo dispatch the trap. */
    475     pVCpu->trpm.s.uActiveVector            = enmXcpt;
    476     pVCpu->trpm.s.enmActiveType            = TRPM_TRAP;
    477     pVCpu->trpm.s.uActiveErrorCode         = uErr;
    478     pVCpu->trpm.s.uActiveCR2               = 0xdeadface;
    479     pVCpu->trpm.s.cbInstr                  = UINT8_MAX;
    480     return VINF_EM_RAW_GUEST_TRAP;
    481 }
    482 
    483 
    484 /**
    485  * Raises a cpu exception with an errorcode and CR2.
    486  *
    487  * This function may or may not dispatch the exception before returning.
    488  *
    489  * @returns VBox status code fit for scheduling.
    490  * @retval  VINF_EM_RAW_GUEST_TRAP if the exception was left pending.
    491  * @retval  VINF_TRPM_XCPT_DISPATCHED if the exception was raised and dispatched for raw-mode execution.
    492  * @retval  VINF_EM_RESCHEDULE_REM if the exception was dispatched and cannot be executed in raw-mode.
    493  *
    494  * @param   pVCpu       The cross context virtual CPU structure of the calling EMT.
    495  * @param   pCtxCore    The CPU context core.
    496  * @param   enmXcpt     The exception.
    497  * @param   uErr        The error code.
    498  * @param   uCR2        The CR2 value.
    499  */
    500 VMMDECL(int) TRPMRaiseXcptErrCR2(PVMCPU pVCpu, PCPUMCTXCORE pCtxCore, X86XCPT enmXcpt, uint32_t uErr, RTGCUINTPTR uCR2)
    501 {
    502     LogFlow(("TRPMRaiseXcptErr: cs:eip=%RTsel:%RX32 enmXcpt=%#x uErr=%RX32 uCR2=%RGv\n", pCtxCore->cs.Sel, pCtxCore->eip, enmXcpt, uErr, uCR2));
    503     NOREF(pCtxCore);
    504 /** @todo dispatch the trap. */
    505     pVCpu->trpm.s.uActiveVector            = enmXcpt;
    506     pVCpu->trpm.s.enmActiveType            = TRPM_TRAP;
    507     pVCpu->trpm.s.uActiveErrorCode         = uErr;
    508     pVCpu->trpm.s.uActiveCR2               = uCR2;
    509     pVCpu->trpm.s.cbInstr                  = UINT8_MAX;
    510     return VINF_EM_RAW_GUEST_TRAP;
    511 }
    512 
  • trunk/src/VBox/VMM/VMMR0/HMSVMR0.cpp

    r80911 r81002  
    33833383    uint8_t     uVector;
    33843384    TRPMEVENT   enmTrpmEvent;
    3385     RTGCUINT    uErrCode;
     3385    uint32_t    uErrCode;
    33863386    RTGCUINTPTR GCPtrFaultAddress;
    33873387    uint8_t     cbInstr;
    33883388
    3389     int rc = TRPMQueryTrapAll(pVCpu, &uVector, &enmTrpmEvent, &uErrCode, &GCPtrFaultAddress, &cbInstr);
     3389    int rc = TRPMQueryTrapAll(pVCpu, &uVector, &enmTrpmEvent, &uErrCode, &GCPtrFaultAddress, &cbInstr, NULL /* pfIcebp */);
    33903390    AssertRC(rc);
    33913391
  • trunk/src/VBox/VMM/VMMR0/HMVMXR0.cpp

    r80911 r81002  
    78287828    uint8_t     uVector;
    78297829    TRPMEVENT   enmTrpmEvent;
    7830     RTGCUINT    uErrCode;
     7830    uint32_t    uErrCode;
    78317831    RTGCUINTPTR GCPtrFaultAddress;
    78327832    uint8_t     cbInstr;
    7833 
    7834     int rc = TRPMQueryTrapAll(pVCpu, &uVector, &enmTrpmEvent, &uErrCode, &GCPtrFaultAddress, &cbInstr);
     7833    bool        fIcebp;
     7834
     7835    int rc = TRPMQueryTrapAll(pVCpu, &uVector, &enmTrpmEvent, &uErrCode, &GCPtrFaultAddress, &cbInstr, &fIcebp);
    78357836    AssertRC(rc);
    78367837
    78377838    uint32_t u32IntInfo;
    78387839    u32IntInfo  = uVector | VMX_IDT_VECTORING_INFO_VALID;
    7839     u32IntInfo |= HMTrpmEventTypeToVmxEventType(uVector, enmTrpmEvent);
     7840    u32IntInfo |= HMTrpmEventTypeToVmxEventType(uVector, enmTrpmEvent, fIcebp);
    78407841
    78417842    rc = TRPMResetTrap(pVCpu);
     
    78767877    else if (VMX_IDT_VECTORING_INFO_TYPE(u32IntInfo) == VMX_IDT_VECTORING_INFO_TYPE_SW_INT)
    78777878        TRPMSetInstrLength(pVCpu, pVCpu->hm.s.Event.cbInstr);
     7879
     7880    if (VMX_IDT_VECTORING_INFO_TYPE(u32IntInfo) == VMX_IDT_VECTORING_INFO_TYPE_PRIV_SW_XCPT)
     7881        TRPMSetTrapDueToIcebp(pVCpu);
    78787882
    78797883    /* We're now done converting the pending event. */
     
    1361913623        {
    1362013624            /* It's a guest page fault and needs to be reflected to the guest. */
    13621             uint32_t uGstErrorCode = TRPMGetErrorCode(pVCpu);
     13625            uint32_t const uGstErrorCode = TRPMGetErrorCode(pVCpu);
    1362213626            TRPMResetTrap(pVCpu);
    1362313627            pVCpu->hm.s.Event.fPending = false;                 /* In case it's a contributory #PF. */
  • trunk/src/VBox/VMM/VMMR3/TRPM.cpp

    r80811 r81002  
    107107*********************************************************************************************************************************/
    108108/** TRPM saved state version. */
    109 #define TRPM_SAVED_STATE_VERSION        9
    110 #define TRPM_SAVED_STATE_VERSION_UNI    8   /* SMP support bumped the version */
     109#define TRPM_SAVED_STATE_VERSION                10
     110#define TRPM_SAVED_STATE_VERSION_PRE_ICEBP      9   /* INT1/ICEBP support bumped the version */
     111#define TRPM_SAVED_STATE_VERSION_UNI            8   /* SMP support bumped the version */
    111112
    112113
     
    247248    LogFlow(("trpmR3Save:\n"));
    248249
    249     /*
    250      * Active and saved traps.
    251      */
    252250    for (VMCPUID i = 0; i < pVM->cCpus; i++)
    253251    {
    254         PTRPMCPU pTrpmCpu = &pVM->apCpusR3[i]->trpm.s;
    255         SSMR3PutUInt(pSSM,      pTrpmCpu->uActiveVector);
    256         SSMR3PutUInt(pSSM,      pTrpmCpu->enmActiveType);
    257         SSMR3PutGCUInt(pSSM,    pTrpmCpu->uActiveErrorCode);
    258         SSMR3PutGCUIntPtr(pSSM, pTrpmCpu->uActiveCR2);
    259         SSMR3PutGCUInt(pSSM,    pTrpmCpu->uSavedVector);
    260         SSMR3PutUInt(pSSM,      pTrpmCpu->enmSavedType);
    261         SSMR3PutGCUInt(pSSM,    pTrpmCpu->uSavedErrorCode);
    262         SSMR3PutGCUIntPtr(pSSM, pTrpmCpu->uSavedCR2);
    263         SSMR3PutGCUInt(pSSM,    pTrpmCpu->uPrevVector);
    264     }
    265     SSMR3PutBool(pSSM,      false /* raw-mode enabled */);
    266     SSMR3PutUInt(pSSM,      0 /*was VMCPU_FF_TRPM_SYNC_IDT*/);
    267     uint32_t au32IdtPatched[8];
    268     RT_ZERO(au32IdtPatched);
    269     SSMR3PutMem(pSSM,       &au32IdtPatched[0], sizeof(au32IdtPatched));
    270     SSMR3PutU32(pSSM, UINT32_MAX);          /* separator. */
    271     /* Next came trampoline gates, terminating with UINT32_MAX. */
    272     return SSMR3PutU32(pSSM, UINT32_MAX);   /* terminator */
     252        PCTRPMCPU pTrpmCpu = &pVM->apCpusR3[i]->trpm.s;
     253        SSMR3PutUInt(pSSM,       pTrpmCpu->uActiveVector);
     254        SSMR3PutUInt(pSSM,       pTrpmCpu->enmActiveType);
     255        SSMR3PutU32(pSSM,        pTrpmCpu->uActiveErrorCode);
     256        SSMR3PutGCUIntPtr(pSSM,  pTrpmCpu->uActiveCR2);
     257        SSMR3PutU8(pSSM,         pTrpmCpu->cbInstr);
     258        SSMR3PutBool(pSSM,       pTrpmCpu->fIcebp);
     259    }
     260    return VINF_SUCCESS;
    273261}
    274262
     
    292280     */
    293281    if (    uVersion != TRPM_SAVED_STATE_VERSION
     282        &&  uVersion != TRPM_SAVED_STATE_VERSION_PRE_ICEBP
    294283        &&  uVersion != TRPM_SAVED_STATE_VERSION_UNI)
    295284    {
     
    298287    }
    299288
    300     /*
    301      * Call the reset function to kick out any handled gates and other potential trouble.
    302      */
    303     TRPMR3Reset(pVM);
    304 
    305     /*
    306      * Active and saved traps.
    307      */
    308289    if (uVersion == TRPM_SAVED_STATE_VERSION)
    309290    {
     
    313294            SSMR3GetUInt(pSSM,      &pTrpmCpu->uActiveVector);
    314295            SSMR3GetUInt(pSSM,      (uint32_t *)&pTrpmCpu->enmActiveType);
    315             SSMR3GetGCUInt(pSSM,    &pTrpmCpu->uActiveErrorCode);
     296            SSMR3GetU32(pSSM,       &pTrpmCpu->uActiveErrorCode);
    316297            SSMR3GetGCUIntPtr(pSSM, &pTrpmCpu->uActiveCR2);
    317             SSMR3GetGCUInt(pSSM,    &pTrpmCpu->uSavedVector);
    318             SSMR3GetUInt(pSSM,      (uint32_t *)&pTrpmCpu->enmSavedType);
    319             SSMR3GetGCUInt(pSSM,    &pTrpmCpu->uSavedErrorCode);
    320             SSMR3GetGCUIntPtr(pSSM, &pTrpmCpu->uSavedCR2);
    321             SSMR3GetGCUInt(pSSM,    &pTrpmCpu->uPrevVector);
    322         }
    323 
    324         bool fIgnored;
    325         SSMR3GetBool(pSSM, &fIgnored);
     298            SSMR3GetU8(pSSM,        &pTrpmCpu->cbInstr);
     299            SSMR3GetBool(pSSM,      &pTrpmCpu->fIcebp);
     300        }
    326301    }
    327302    else
    328303    {
    329         PTRPMCPU pTrpmCpu = &pVM->apCpusR3[0]->trpm.s;
    330         SSMR3GetUInt(pSSM,      &pTrpmCpu->uActiveVector);
    331         SSMR3GetUInt(pSSM,      (uint32_t *)&pTrpmCpu->enmActiveType);
    332         SSMR3GetGCUInt(pSSM,    &pTrpmCpu->uActiveErrorCode);
    333         SSMR3GetGCUIntPtr(pSSM, &pTrpmCpu->uActiveCR2);
    334         SSMR3GetGCUInt(pSSM,    &pTrpmCpu->uSavedVector);
    335         SSMR3GetUInt(pSSM,      (uint32_t *)&pTrpmCpu->enmSavedType);
    336         SSMR3GetGCUInt(pSSM,    &pTrpmCpu->uSavedErrorCode);
    337         SSMR3GetGCUIntPtr(pSSM, &pTrpmCpu->uSavedCR2);
    338         SSMR3GetGCUInt(pSSM,    &pTrpmCpu->uPrevVector);
    339 
    340         RTGCUINT fIgnored;
    341         SSMR3GetGCUInt(pSSM,    &fIgnored);
    342     }
    343 
    344     RTUINT fSyncIDT;
    345     int rc = SSMR3GetUInt(pSSM, &fSyncIDT);
    346     if (RT_FAILURE(rc))
    347         return rc;
    348     AssertMsgReturn(!(fSyncIDT & ~1), ("fSyncIDT=%#x\n", fSyncIDT), VERR_SSM_DATA_UNIT_FORMAT_CHANGED);
    349 
    350     uint32_t au32IdtPatched[8];
    351     SSMR3GetMem(pSSM, &au32IdtPatched[0], sizeof(au32IdtPatched));
    352 
    353     /* check the separator */
    354     uint32_t u32Sep;
    355     rc = SSMR3GetU32(pSSM, &u32Sep);
    356     if (RT_FAILURE(rc))
    357         return rc;
    358     AssertMsgReturn(u32Sep == (uint32_t)~0, ("u32Sep=%#x (first)\n", u32Sep), VERR_SSM_DATA_UNIT_FORMAT_CHANGED);
    359 
    360     /*
    361      * Restore any trampoline gates.
    362      */
    363     for (;;)
    364     {
    365         /* gate number / terminator */
    366         uint32_t iTrap;
    367         rc = SSMR3GetU32(pSSM, &iTrap);
    368         if (RT_FAILURE(rc))
    369             return rc;
    370         if (iTrap == (uint32_t)~0)
    371             break;
    372         AssertMsgReturn(iTrap < 256, ("iTrap=%#x\n", iTrap), VERR_SSM_DATA_UNIT_FORMAT_CHANGED);
    373 
    374         /* restore the IDT entry. */
    375         RTGCPTR GCPtrHandler;
    376         SSMR3GetGCPtr(pSSM, &GCPtrHandler);
    377         VBOXIDTE Idte;
    378         rc = SSMR3GetMem(pSSM, &Idte, sizeof(Idte));
    379         if (RT_FAILURE(rc))
    380             return rc;
    381         Assert(GCPtrHandler);
    382         //pTrpm->aIdt[iTrap] = Idte; - not any more.
     304        /*
     305         * Active and saved traps.
     306         */
     307        if (uVersion == TRPM_SAVED_STATE_VERSION_PRE_ICEBP)
     308        {
     309            for (VMCPUID i = 0; i < pVM->cCpus; i++)
     310            {
     311                RTGCUINT GCUIntErrCode;
     312                PTRPMCPU pTrpmCpu = &pVM->apCpusR3[i]->trpm.s;
     313                SSMR3GetUInt(pSSM,      &pTrpmCpu->uActiveVector);
     314                SSMR3GetUInt(pSSM,      (uint32_t *)&pTrpmCpu->enmActiveType);
     315                SSMR3GetGCUInt(pSSM,    &GCUIntErrCode);
     316                SSMR3GetGCUIntPtr(pSSM, &pTrpmCpu->uActiveCR2);
     317                SSMR3Skip(pSSM,          sizeof(RTGCUINT));      /* uSavedVector    - No longer used. */
     318                SSMR3Skip(pSSM,          sizeof(RTUINT));        /* enmSavedType    - No longer used. */
     319                SSMR3Skip(pSSM,          sizeof(RTGCUINT));      /* uSavedErrorCode - No longer used. */
     320                SSMR3Skip(pSSM,          sizeof(RTGCUINTPTR));   /* uSavedCR2       - No longer used. */
     321                SSMR3Skip(pSSM,          sizeof(RTGCUINT));      /* uPrevVector     - No longer used. */
     322
     323                /*
     324                 * We lose the high 64-bits here (if RTGCUINT is 64-bit) after making the
     325                 * active error code as 32-bits. However, for error codes even 16-bit should
     326                 * be sufficient. Despite this, we decided to use and keep it at 32-bits
     327                 * since VMX/SVM defines these as 32-bit in their event fields and converting
     328                 * to/from these events are safer.
     329                 */
     330                pTrpmCpu->uActiveErrorCode = GCUIntErrCode;
     331            }
     332        }
     333        else
     334        {
     335            RTGCUINT GCUIntErrCode;
     336            PTRPMCPU pTrpmCpu = &pVM->apCpusR3[0]->trpm.s;
     337            SSMR3GetUInt(pSSM,      &pTrpmCpu->uActiveVector);
     338            SSMR3GetUInt(pSSM,      (uint32_t *)&pTrpmCpu->enmActiveType);
     339            SSMR3GetGCUInt(pSSM,    &GCUIntErrCode);
     340            SSMR3GetGCUIntPtr(pSSM, &pTrpmCpu->uActiveCR2);
     341            pTrpmCpu->uActiveErrorCode = GCUIntErrCode;
     342        }
     343
     344        /*
     345         * Skip rest of TRPM saved-state unit involving IDT and trampoline gates.
     346         * With the removal of raw-mode support, we no longer need these.
     347         */
     348        SSMR3SkipToEndOfUnit(pSSM);
    383349    }
    384350
     
    467433    uint8_t     cbInstr;
    468434    TRPMEVENT   enmTrapEvent;
    469     RTGCUINT    uErrorCode;
     435    uint32_t    uErrorCode;
    470436    RTGCUINTPTR uCR2;
    471     int rc = TRPMQueryTrapAll(pVCpu, &uVector, &enmTrapEvent, &uErrorCode, &uCR2, &cbInstr);
     437    bool        fIcebp;
     438    int rc = TRPMQueryTrapAll(pVCpu, &uVector, &enmTrapEvent, &uErrorCode, &uCR2, &cbInstr, &fIcebp);
    472439    if (RT_SUCCESS(rc))
    473440    {
     
    483450            pHlp->pfnPrintf(pHlp, " Type       = %s\n", s_apszTrpmEventType[enmTrapEvent]);
    484451            pHlp->pfnPrintf(pHlp, " uVector    = %#x\n", uVector);
    485             pHlp->pfnPrintf(pHlp, " uErrorCode = %#RGu\n", uErrorCode);
     452            pHlp->pfnPrintf(pHlp, " uErrorCode = %#x\n", uErrorCode);
    486453            pHlp->pfnPrintf(pHlp, " uCR2       = %#RGp\n", uCR2);
    487454            pHlp->pfnPrintf(pHlp, " cbInstr    = %u bytes\n", cbInstr);
     455            pHlp->pfnPrintf(pHlp, " fIcebp     = %RTbool\n", fIcebp);
    488456        }
    489457        else
  • trunk/src/VBox/VMM/VMMR3/VMMGuruMeditation.cpp

    r80333 r81002  
    355355            TRPMEVENT       enmType;
    356356            uint8_t         u8TrapNo   =       0xce;
    357             RTGCUINT        uErrorCode = 0xdeadface;
     357            uint32_t        uErrorCode = 0xdeadface;
    358358            RTGCUINTPTR     uCR2       = 0xdeadface;
    359359            uint8_t         cbInstr    = UINT8_MAX;
    360             int rc2 = TRPMQueryTrapAll(pVCpu, &u8TrapNo, &enmType, &uErrorCode, &uCR2, &cbInstr);
     360            bool            fIcebp     = false;
     361            int rc2 = TRPMQueryTrapAll(pVCpu, &u8TrapNo, &enmType, &uErrorCode, &uCR2, &cbInstr, &fIcebp);
    361362            if (VM_IS_RAW_MODE_ENABLED(pVM))
    362363            {
    363364                if (RT_SUCCESS(rc2))
    364365                    pHlp->pfnPrintf(pHlp,
    365                                     "!! TRAP=%02x ERRCD=%RGv CR2=%RGv EIP=%RX32 Type=%d cbInstr=%02x\n",
    366                                     u8TrapNo, uErrorCode, uCR2, uEIP, enmType, cbInstr);
     366                                    "!! TRAP=%02x ERRCD=%RX32 CR2=%RGv EIP=%RX32 Type=%d cbInstr=%02x fIcebp=%RTbool\n",
     367                                    u8TrapNo, uErrorCode, uCR2, uEIP, enmType, cbInstr, fIcebp);
    367368                else
    368369                    pHlp->pfnPrintf(pHlp,
     
    372373            else if (RT_SUCCESS(rc2))
    373374                pHlp->pfnPrintf(pHlp,
    374                                 "!! ACTIVE TRAP=%02x ERRCD=%RGv CR2=%RGv PC=%RGr Type=%d cbInstr=%02x (Guest!)\n",
    375                                 u8TrapNo, uErrorCode, uCR2, CPUMGetGuestRIP(pVCpu), enmType, cbInstr);
     375                                "!! ACTIVE TRAP=%02x ERRCD=%RX32 CR2=%RGv PC=%RGr Type=%d cbInstr=%02x fIcebp=%RTbool (Guest!)\n",
     376                                u8TrapNo, uErrorCode, uCR2, CPUMGetGuestRIP(pVCpu), enmType, cbInstr, fIcebp);
    376377
    377378            /*
  • trunk/src/VBox/VMM/include/TRPMInternal.h

    r80938 r81002  
    7272
    7373    /** Errorcode for the active interrupt/trap. */
    74     RTGCUINT                uActiveErrorCode; /**< @todo don't use RTGCUINT */
    75 
    76     /** CR2 at the time of the active exception. */
    77     RTGCUINTPTR             uActiveCR2;
    78 
    79     /** Saved trap vector number. */
    80     RTGCUINT                uSavedVector; /**< @todo don't use RTGCUINT */
    81 
    82     /** Saved errorcode. */
    83     RTGCUINT                uSavedErrorCode;
    84 
    85     /** Saved cr2. */
    86     RTGCUINTPTR             uSavedCR2;
    87 
    88     /** Saved trap type. */
    89     TRPMEVENT               enmSavedType;
     74    uint32_t                uActiveErrorCode;
    9075
    9176    /** Instruction length for software interrupts and software exceptions
     
    9378    uint8_t                 cbInstr;
    9479
    95     /** Saved instruction length. */
    96     uint8_t                 cbSavedInstr;
     80    /** Whether this \#DB trap is caused due to INT1/ICEBP. */
     81    bool                    fIcebp;
    9782
    98     /** Padding. */
    99     uint8_t                 au8Padding[2];
    100 
    101     /** Previous trap vector # - for debugging. */
    102     RTGCUINT                uPrevVector;
     83    /** CR2 at the time of the active exception. */
     84    RTGCUINTPTR             uActiveCR2;
    10385} TRPMCPU;
    10486
    10587/** Pointer to TRPMCPU Data. */
    10688typedef TRPMCPU *PTRPMCPU;
     89/** Pointer to const TRPMCPU Data. */
     90typedef const TRPMCPU *PCTRPMCPU;
    10791
    10892/** @} */
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