VirtualBox

Changeset 101535 in vbox for trunk/src/VBox/VMM/include


Ignore:
Timestamp:
Oct 20, 2023 9:53:15 PM (15 months ago)
Author:
vboxsync
Message:

VMM/IEM: Assert that we don't overshoot iemNativeInstrBufEnsure space reservations (mainly an x86 host issue). bugref:10371

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/include/IEMN8veRecompiler.h

    r101523 r101535  
    473473     * IEMNATIVEINSTR units. */
    474474    uint32_t                    cInstrBufAlloc;
    475     uint32_t                    uPadding; /* We don't keep track of this here... */
     475#ifdef VBOX_STRICT
     476    /** Strict: How far the last iemNativeInstrBufEnsure() checked. */
     477    uint32_t                    offInstrBufChecked;
     478#else
     479    uint32_t                    uPadding; /* We don't keep track of the size here... */
     480#endif
    476481    /** Fixed temporary code buffer for native recompilation. */
    477482    PIEMNATIVEINSTR             pInstrBuf;
     
    595600DECL_FORCE_INLINE(PIEMNATIVEINSTR) iemNativeInstrBufEnsure(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint32_t cInstrReq)
    596601{
    597     if (RT_LIKELY(off + (uint64_t)cInstrReq <= pReNative->cInstrBufAlloc))
     602    uint64_t const offChecked = off + (uint64_t)cInstrReq;
     603    if (RT_LIKELY(offChecked <= pReNative->cInstrBufAlloc))
     604    {
     605#ifdef VBOX_STRICT
     606        pReNative->offInstrBufChecked = offChecked;
     607#endif
    598608        return pReNative->pInstrBuf;
     609    }
    599610    return iemNativeInstrBufEnsureSlow(pReNative, off, cInstrReq);
    600611}
     612
     613/**
     614 * Checks that we didn't exceed the space requested in the last
     615 * iemNativeInstrBufEnsure() call. */
     616#define IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(a_pReNative, a_off) \
     617    AssertMsg((a_off) <= (a_pReNative)->offInstrBufChecked, \
     618              ("off=%#x offInstrBufChecked=%#x\n", (a_off), (a_pReNative)->offInstrBufChecked))
    601619
    602620
     
    636654# error "port me"
    637655#endif
     656    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
    638657    return off;
    639658}
     
    663682# error "port me"
    664683#endif
    665     RT_NOREF(pReNative);
     684    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
    666685    return off;
    667686}
     
    760779# error "port me"
    761780#endif
     781    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
    762782    return off;
    763783}
     
    791811# error "port me"
    792812#endif
     813    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
    793814    return off;
    794815}
     
    853874        pu32CodeBuf[off++] = Armv8A64MkInstrStLdRegIdx(enmOperation, iGpr, IEMNATIVE_REG_FIXED_PVMCPU, IEMNATIVE_REG_FIXED_TMP);
    854875    }
     876    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
    855877    return off;
    856878}
     
    873895    pbCodeBuf[off++] = 0x8b;
    874896    off = iemNativeEmitGprByVCpuDisp(pbCodeBuf,off,iGpr, offVCpu);
     897    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
    875898
    876899#elif RT_ARCH_ARM64
     
    898921    pbCodeBuf[off++] = 0x8b;
    899922    off = iemNativeEmitGprByVCpuDisp(pbCodeBuf, off, iGpr, offVCpu);
     923    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
    900924
    901925#elif RT_ARCH_ARM64
     
    924948    pbCodeBuf[off++] = 0xb7;
    925949    off = iemNativeEmitGprByVCpuDisp(pbCodeBuf, off, iGpr, offVCpu);
     950    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
    926951
    927952#elif RT_ARCH_ARM64
     
    950975    pbCodeBuf[off++] = 0xb6;
    951976    off = iemNativeEmitGprByVCpuDisp(pbCodeBuf, off, iGpr, offVCpu);
     977    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
    952978
    953979#elif RT_ARCH_ARM64
     
    9761002    pbCodeBuf[off++] = 0x89;
    9771003    off = iemNativeEmitGprByVCpuDisp(pbCodeBuf,off,iGpr, offVCpu);
     1004    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
    9781005
    9791006#elif RT_ARCH_ARM64
     
    10001027    pbCodeBuf[off++] = 0x89;
    10011028    off = iemNativeEmitGprByVCpuDisp(pbCodeBuf, off, iGpr, offVCpu);
     1029    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
    10021030
    10031031#elif RT_ARCH_ARM64
     
    10251053    pbCodeBuf[off++] = 0x89;
    10261054    off = iemNativeEmitGprByVCpuDisp(pbCodeBuf, off, iGpr, offVCpu);
     1055    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
    10271056
    10281057#elif RT_ARCH_ARM64
     
    10491078    pbCodeBuf[off++] = 0x88;
    10501079    off = iemNativeEmitGprByVCpuDisp(pbCodeBuf, off, iGpr, offVCpu);
     1080    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
    10511081
    10521082#elif RT_ARCH_ARM64
     
    10871117# error "port me"
    10881118#endif
     1119    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
    10891120    return off;
    10901121}
     
    10941125 * Common bit of iemNativeEmitLoadGprByBp and friends.
    10951126 */
    1096 DECL_FORCE_INLINE(uint32_t) iemNativeEmitGprByBpDisp(uint8_t *pbCodeBuf, uint32_t off, uint8_t iGprReg, int32_t offDisp)
     1127DECL_FORCE_INLINE(uint32_t) iemNativeEmitGprByBpDisp(uint8_t *pbCodeBuf, uint32_t off, uint8_t iGprReg, int32_t offDisp,
     1128                                                     PIEMRECOMPILERSTATE pReNativeAssert)
    10971129{
    10981130    if (offDisp < 128 && offDisp >= -128)
     
    11091141        pbCodeBuf[off++] = RT_BYTE4((uint32_t)offDisp);
    11101142    }
     1143    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNativeAssert, off); RT_NOREF(pReNativeAssert);
    11111144    return off;
    11121145}
     
    11281161        pbCodeBuf[off++] = X86_OP_REX_W | X86_OP_REX_R;
    11291162    pbCodeBuf[off++] = 0x8b;
    1130     return iemNativeEmitGprByBpDisp(pbCodeBuf, off, iGprDst, offDisp);
     1163    return iemNativeEmitGprByBpDisp(pbCodeBuf, off, iGprDst, offDisp, pReNative);
    11311164}
    11321165#endif
     
    11451178        pbCodeBuf[off++] = X86_OP_REX_R;
    11461179    pbCodeBuf[off++] = 0x8b;
    1147     return iemNativeEmitGprByBpDisp(pbCodeBuf, off, iGprDst, offDisp);
     1180    return iemNativeEmitGprByBpDisp(pbCodeBuf, off, iGprDst, offDisp, pReNative);
    11481181}
    11491182#endif
     
    11641197        pbCodeBuf[off++] = X86_OP_REX_W | X86_OP_REX_R;
    11651198    pbCodeBuf[off++] = 0x8d;
    1166     return iemNativeEmitGprByBpDisp(pbCodeBuf, off, iGprDst, offDisp);
     1199    return iemNativeEmitGprByBpDisp(pbCodeBuf, off, iGprDst, offDisp, pReNative);
    11671200}
    11681201#endif
     
    11851218        pbCodeBuf[off++] = X86_OP_REX_W | X86_OP_REX_R;
    11861219    pbCodeBuf[off++] = 0x89;
    1187     return iemNativeEmitGprByBpDisp(pbCodeBuf, off, iGprSrc, offDisp);
     1220    return iemNativeEmitGprByBpDisp(pbCodeBuf, off, iGprSrc, offDisp, pReNative);
    11881221
    11891222#elif defined(RT_ARCH_ARM64)
     
    12121245                                                       IEMNATIVE_REG_FIXED_TMP0, kArmv8A64InstrLdStExtend_Sxtw);
    12131246    }
     1247    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
    12141248    return off;
    12151249
     
    12531287        pbCodeBuf[off++] = RT_BYTE3(uImm64);
    12541288        pbCodeBuf[off++] = RT_BYTE4(uImm64);
     1289        IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
    12551290        return off;
    12561291    }
     
    12911326        pbCodeBuf[off++] = RT_BYTE4(iSubtrahend);
    12921327    }
     1328    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
    12931329    return off;
    12941330}
     
    13191355# error "Port me"
    13201356#endif
     1357    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
    13211358    return off;
    13221359}
     
    13561393# error "Port me"
    13571394#endif
     1395    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
    13581396    return off;
    13591397}
     
    13951433# error "Port me"
    13961434#endif
     1435    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
    13971436    return off;
    13981437}
     
    14651504# error "Port me"
    14661505#endif
     1506    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
    14671507    return off;
    14681508}
     
    15181558# error "Port me"
    15191559#endif
     1560    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
    15201561    return off;
    15211562}
     
    15491590# error "Port me"
    15501591#endif
     1592    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
    15511593    return off;
    15521594}
     
    15751617# error "Port me"
    15761618#endif
     1619    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
    15771620    return off;
    15781621}
     
    15911634    pu32CodeBuf[off++] = Armv8A64MkInstrAddSubReg(true /*fSub*/, ARMV8_A64_REG_XZR /*iRegResult*/, iGprLeft, iGprRight,
    15921635                                                  f64Bit, true /*fSetFlags*/, cShift, enmShift);
     1636    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
    15931637    return off;
    15941638}
     
    16091653    pbCodeBuf[off++] = 0x3b;
    16101654    pbCodeBuf[off++] = X86_MODRM_MAKE(X86_MOD_REG, iGprLeft & 7, iGprRight & 7);
     1655    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
    16111656
    16121657#elif defined(RT_ARCH_ARM64)
     
    16351680    pbCodeBuf[off++] = 0x3b;
    16361681    pbCodeBuf[off++] = X86_MODRM_MAKE(X86_MOD_REG, iGprLeft & 7, iGprRight & 7);
     1682    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
    16371683
    16381684#elif defined(RT_ARCH_ARM64)
     
    17001746# error "Port me!"
    17011747#endif
     1748    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
    17021749    return off;
    17031750}
     
    17541801# error "Port me!"
    17551802#endif
     1803    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
    17561804    return off;
    17571805}
     
    18681916# error "Port me!"
    18691917#endif
     1918    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
    18701919    return off;
    18711920}
     
    19932042# error "port me"
    19942043#endif
     2044    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
    19952045    return off;
    19962046}
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