VirtualBox

Changeset 86749 in vbox for trunk/src/VBox/VMM/VMMAll


Ignore:
Timestamp:
Oct 28, 2020 9:04:02 PM (4 years ago)
Author:
vboxsync
Message:

VMM/DBGF: Implement L2 binary search tree node removal and make the all context breakpoint management code compile in ring-3, completely untested though, bugref:9837

File:
1 edited

Legend:

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

    r86730 r86749  
    2929#include <iprt/assert.h>
    3030
     31#include "DBGFInline.h"
     32
    3133
    3234#ifdef IN_RC
     
    4042
    4143#ifdef VBOX_WITH_LOTS_OF_DBGF_BPS
    42 # ifdef IN_RING0
    4344/**
    4445 * Returns the internal breakpoint state for the given handle.
     
    5051 *                              on success, optional.
    5152 */
    52 DECLINLINE(PDBGFBPINT) dbgfR0BpGetByHnd(PVMCC pVM, DBGFBP hBp, PDBGFBPINTR0 *ppBpR0)
     53# ifdef IN_RING0
     54DECLINLINE(PDBGFBPINT) dbgfBpGetByHnd(PVMCC pVM, DBGFBP hBp, PDBGFBPINTR0 *ppBpR0)
     55# else
     56DECLINLINE(PDBGFBPINT) dbgfBpGetByHnd(PVMCC pVM, DBGFBP hBp)
     57# endif
    5358{
    5459    uint32_t idChunk  = DBGF_BP_HND_GET_CHUNK_ID(hBp);
     
    5863    AssertReturn(idxEntry < DBGF_BP_COUNT_PER_CHUNK, NULL);
    5964
     65# ifdef IN_RING0
    6066    PDBGFBPCHUNKR0 pBpChunk = &pVM->dbgfr0.s.aBpChunks[idChunk];
    61     AssertPtrReturn(pBpChunk->paBpBaseSharedR0, NULL);
     67    AssertPtrReturn(pBpChunk->CTX_SUFF(paBpBaseShared), NULL);
    6268
    6369    if (ppBpR0)
    6470        *ppBpR0 = &pBpChunk->paBpBaseR0Only[idxEntry];
    65     return &pBpChunk->paBpBaseSharedR0[idxEntry];
     71    return &pBpChunk->CTX_SUFF(paBpBaseShared)[idxEntry];
     72# elif defined(IN_RING3)
     73    PUVM pUVM = pVM->pUVM;
     74    PDBGFBPCHUNKR3 pBpChunk = &pUVM->dbgf.s.aBpChunks[idChunk];
     75    AssertPtrReturn(pBpChunk->CTX_SUFF(pBpBase), NULL);
     76
     77    return &pBpChunk->CTX_SUFF(pBpBase)[idxEntry];
     78# else
     79#  error "Unsupported host context"
     80# endif
     81}
     82
     83
     84/**
     85 * Returns the pointer to the L2 table entry from the given index.
     86 *
     87 * @returns Current context pointer to the L2 table entry or NULL if the provided index value is invalid.
     88 * @param   pVM         The cross context VM structure.
     89 * @param   idxL2       The L2 table index to resolve.
     90 *
     91 * @note The content of the resolved L2 table entry is not validated!.
     92 */
     93DECLINLINE(PCDBGFBPL2ENTRY) dbgfBpL2GetByIdx(PVMCC pVM, uint32_t idxL2)
     94{
     95    uint32_t idChunk  = DBGF_BP_L2_IDX_GET_CHUNK_ID(idxL2);
     96    uint32_t idxEntry = DBGF_BP_L2_IDX_GET_ENTRY(idxL2);
     97
     98    AssertReturn(idChunk < DBGF_BP_L2_TBL_CHUNK_COUNT, NULL);
     99    AssertReturn(idxEntry < DBGF_BP_L2_TBL_ENTRIES_PER_CHUNK, NULL);
     100
     101# ifdef IN_RING0
     102    PDBGFBPL2TBLCHUNKR0 pL2Chunk = &pVM->dbgfr0.s.aBpL2TblChunks[idChunk];
     103    AssertPtrReturn(pL2Chunk->CTX_SUFF(paBpL2TblBaseShared), NULL);
     104
     105    return &pL2Chunk->CTX_SUFF(paBpL2TblBaseShared)[idxEntry];
     106# elif defined(IN_RING3)
     107    PUVM pUVM = pVM->pUVM;
     108    PDBGFBPL2TBLCHUNKR3 pL2Chunk = &pUVM->dbgf.s.aBpL2TblChunks[idChunk];
     109    AssertPtrReturn(pL2Chunk->pbmAlloc, NULL);
     110    AssertReturn(ASMBitTest(pL2Chunk->pbmAlloc, idxEntry), NULL);
     111
     112    return &pL2Chunk->CTX_SUFF(pL2Base)[idxEntry];
     113# endif
    66114}
    67115
     
    78126 * @param   pBpR0       The ring-0 only breakpoint state.
    79127 */
    80 DECLINLINE(int) dbgfR0BpHit(PVMCC pVM, PVMCPUCC pVCpu, PCPUMCTXCORE pRegFrame,
    81                             DBGFBP hBp, PDBGFBPINT pBp, PDBGFBPINTR0 pBpR0)
     128# ifdef IN_RING0
     129DECLINLINE(int) dbgfBpHit(PVMCC pVM, PVMCPUCC pVCpu, PCPUMCTXCORE pRegFrame,
     130                          DBGFBP hBp, PDBGFBPINT pBp, PDBGFBPINTR0 pBpR0)
     131# else
     132DECLINLINE(int) dbgfBpHit(PVMCC pVM, PVMCPUCC pVCpu, PCPUMCTXCORE pRegFrame,
     133                          DBGFBP hBp, PDBGFBPINT pBp)
     134# endif
    82135{
    83136    uint64_t cHits = ASMAtomicIncU64(&pBp->Pub.cHits);
     
    85138
    86139    /** @todo Owner handling. */
    87     RT_NOREF(pVM, pRegFrame, pBpR0);
    88 
    89     LogFlow(("dbgfRZBpHit: hit breakpoint %u at %04x:%RGv cHits=0x%RX64\n",
     140    RT_NOREF(pVM, pRegFrame);
     141#ifdef IN_RING0
     142    RT_NOREF(pBpR0);
     143#endif
     144
     145    LogFlow(("dbgfBpHit: hit breakpoint %u at %04x:%RGv cHits=0x%RX64\n",
    90146             hBp, pRegFrame->cs.Sel, pRegFrame->rip, cHits));
    91147    return VINF_EM_DBG_BREAKPOINT;
    92 }
    93 
    94 
    95 /**
    96  * Returns the pointer to the L2 table entry from the given index.
    97  *
    98  * @returns Current context pointer to the L2 table entry or NULL if the provided index value is invalid.
    99  * @param   pVM         The cross context VM structure.
    100  * @param   idxL2       The L2 table index to resolve.
    101  *
    102  * @note The content of the resolved L2 table entry is not validated!.
    103  */
    104 DECLINLINE(PCDBGFBPL2ENTRY) dbgfR0BpL2GetByIdx(PVMCC pVM, uint32_t idxL2)
    105 {
    106     uint32_t idChunk  = DBGF_BP_L2_IDX_GET_CHUNK_ID(idxL2);
    107     uint32_t idxEntry = DBGF_BP_L2_IDX_GET_ENTRY(idxL2);
    108 
    109     AssertReturn(idChunk < DBGF_BP_L2_TBL_CHUNK_COUNT, NULL);
    110     AssertReturn(idxEntry < DBGF_BP_L2_TBL_ENTRIES_PER_CHUNK, NULL);
    111 
    112     PDBGFBPL2TBLCHUNKR0 pL2Chunk = &pVM->dbgfr0.s.aBpL2TblChunks[idChunk];
    113     AssertPtrReturn(pL2Chunk->paBpL2TblBaseSharedR0, NULL);
    114 
    115     return &pL2Chunk->CTX_SUFF(paBpL2TblBaseShared)[idxEntry];
    116148}
    117149
     
    132164    /** @todo We don't use the depth right now but abort the walking after a fixed amount of levels. */
    133165    uint8_t iDepth = 32;
    134     PCDBGFBPL2ENTRY pL2Entry = dbgfR0BpL2GetByIdx(pVM, idxL2Root);
     166    PCDBGFBPL2ENTRY pL2Entry = dbgfBpL2GetByIdx(pVM, idxL2Root);
    135167
    136168    while (RT_LIKELY(   iDepth-- > 0
     
    148180
    149181            /* Query the internal breakpoint state from the handle. */
     182# ifdef IN_RING0
    150183            PDBGFBPINTR0 pBpR0 = NULL;
    151             PDBGFBPINT pBp = dbgfR0BpGetByHnd(pVM, hBp, &pBpR0);
     184            PDBGFBPINT pBp = dbgfBpGetByHnd(pVM, hBp, &pBpR0);
     185# else
     186            PDBGFBPINT pBp = dbgfBpGetByHnd(pVM, hBp);
     187# endif
    152188            if (   pBp
    153189                && DBGF_BP_PUB_GET_TYPE(pBp->Pub.fFlagsAndType) == DBGFBPTYPE_INT3)
    154                 return dbgfR0BpHit(pVM, pVCpu, pRegFrame, hBp, pBp, pBpR0);
     190                return dbgfBpHit(pVM, pVCpu, pRegFrame, hBp, pBp
     191# ifdef IN_RING0
     192                                 , pBpR0
     193# endif
     194                                 );
    155195
    156196            /* The entry got corrupted, just abort. */
     
    166206            return VINF_EM_RAW_GUEST_TRAP;
    167207
    168         pL2Entry = dbgfR0BpL2GetByIdx(pVM, idxL2Next);
     208        pL2Entry = dbgfBpL2GetByIdx(pVM, idxL2Next);
    169209    }
    170210
    171211    return VERR_DBGF_BP_L2_LOOKUP_FAILED;
    172212}
    173 # endif /* !IN_RING0 */
    174213#endif /* !VBOX_WITH_LOTS_OF_DBGF_BPS */
    175214
     
    290329    }
    291330#else
    292 #ifndef IN_RING0
    293 # error "Todo"
    294 #endif
    295     if (pVM->dbgfr0.s.CTX_SUFF(paBpLocL1))
     331# if defined(IN_RING0)
     332    uint32_t volatile *paBpLocL1 = pVM->dbgfr0.s.CTX_SUFF(paBpLocL1);
     333# elif defined(IN_RING3)
     334    PUVM pUVM = pVM->pUVM;
     335    uint32_t volatile *paBpLocL1 = pUVM->dbgf.s.CTX_SUFF(paBpLocL1);
     336# else
     337#  error "Unsupported host context"
     338# endif
     339    if (paBpLocL1)
    296340    {
    297341        RTGCPTR GCPtrBp;
     
    302346
    303347        const uint16_t idxL1      = DBGF_BP_INT3_L1_IDX_EXTRACT_FROM_ADDR(GCPtrBp);
    304         const uint32_t u32L1Entry = ASMAtomicReadU32(&pVM->dbgfr0.s.CTX_SUFF(paBpLocL1)[idxL1]);
     348        const uint32_t u32L1Entry = ASMAtomicReadU32(&paBpLocL1[idxL1]);
    305349
    306350        LogFlowFunc(("GCPtrBp=%RGv idxL1=%u u32L1Entry=%#x\n", GCPtrBp, idxL1, u32L1Entry));
     
    314358
    315359                /* Query the internal breakpoint state from the handle. */
     360#ifdef IN_RING0
    316361                PDBGFBPINTR0 pBpR0 = NULL;
    317                 PDBGFBPINT pBp = dbgfR0BpGetByHnd(pVM, hBp, &pBpR0);
     362#endif
     363                PDBGFBPINT pBp = dbgfBpGetByHnd(pVM, hBp
     364#ifdef IN_RING0
     365                                                , &pBpR0
     366#endif
     367                                                );
    318368                if (   pBp
    319369                    && DBGF_BP_PUB_GET_TYPE(pBp->Pub.fFlagsAndType) == DBGFBPTYPE_INT3)
    320370                {
    321371                    if (pBp->Pub.u.Int3.GCPtr == (RTGCUINTPTR)GCPtrBp)
    322                         rc = dbgfR0BpHit(pVM, pVCpu, pRegFrame, hBp, pBp, pBpR0);
     372                        rc = dbgfBpHit(pVM, pVCpu, pRegFrame, hBp, pBp
     373#ifdef IN_RING0
     374                                       , pBpR0
     375#endif
     376                                       );
    323377                    /* else: Genuine guest trap. */
    324378                }
     
    333387        }
    334388        /* else: Genuine guest trap. */
     389
     390        return rc;
    335391    }
    336392#endif /* !VBOX_WITH_LOTS_OF_DBGF_BPS */
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