VirtualBox

Changeset 101535 in vbox


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

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

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

Legend:

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

    r101523 r101535  
    29602960#  error "Port me!"
    29612961# endif
     2962    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
    29622963    return off;
    29632964}
     
    29892990    pbCodeBuf[off++] = 0x0b;                    /* or edx, eax */
    29902991    pbCodeBuf[off++] = X86_MODRM_MAKE(X86_MOD_REG, X86_GREG_xDX, X86_GREG_xAX);
     2992    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
    29912993
    29922994    /* Jump to non-zero status return path. */
     
    30153017# error "port me"
    30163018#endif
     3019    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
    30173020    return off;
    30183021}
     
    32013204     * Make the call.
    32023205     */
    3203 #ifdef RT_ARCH_AMD64
    3204     off = iemNativeEmitLoadGprImm64(pReNative, off, X86_GREG_xAX, pfnCImpl);
    3205 
    3206     uint8_t *pbCodeBuf = iemNativeInstrBufEnsure(pReNative, off, 2);
    3207     AssertReturn(pbCodeBuf, UINT32_MAX);
    3208     pbCodeBuf[off++] = 0xff;                    /* call rax */
    3209     pbCodeBuf[off++] = X86_MODRM_MAKE(X86_MOD_REG, 2, X86_GREG_xAX);
    3210 
    3211 # if defined(VBOXSTRICTRC_STRICT_ENABLED) && defined(RT_OS_WINDOWS)
     3206    off = iemNativeEmitCallImm(pReNative, off, pfnCImpl);
     3207
     3208#if defined(RT_ARCH_AMD64) && defined(VBOXSTRICTRC_STRICT_ENABLED) && defined(RT_OS_WINDOWS)
    32123209    off = iemNativeEmitLoadGprByBpU32(pReNative, off, X86_GREG_xAX, IEMNATIVE_FP_OFF_IN_SHADOW_ARG0); /* rcStrict (see above) */
    3213 # endif
    3214 
    3215 #elif defined(RT_ARCH_ARM64)
    3216     off = iemNativeEmitLoadGprImm64(pReNative, off, IEMNATIVE_REG_FIXED_TMP0, pfnCImpl);
    3217 
    3218     uint32_t *pu32CodeBuf = iemNativeInstrBufEnsure(pReNative, off, 1);
    3219     AssertReturn(pu32CodeBuf, UINT32_MAX);
    3220     pu32CodeBuf[off++] = Armv8A64MkInstrBlr(IEMNATIVE_REG_FIXED_TMP0);
    3221 
    3222 #else
    3223 # error "Port me!"
    32243210#endif
    32253211
     
    33473333        /* iemNativeHlpExecStatusCodeFiddling(PVMCPUCC pVCpu, int rc, uint8_t idxInstr) */
    33483334#ifdef RT_ARCH_AMD64
    3349         /*
    3350          * AMD64:
    3351          */
    3352         uint8_t *pbCodeBuf = iemNativeInstrBufEnsure(pReNative, off, 20);
    3353         AssertReturn(pbCodeBuf, UINT32_MAX);
    3354 
    3355         /* Call helper and jump to return point. */
    33563335# ifdef RT_OS_WINDOWS
    33573336#  ifdef IEMNATIVE_WITH_INSTRUCTION_COUNTING
     
    33713350# endif
    33723351
    3373 #elif defined(RT_ARCH_ARM64)
    3374         /*
    3375          * ARM64:
    3376          */
     3352#else
    33773353        off = iemNativeEmitLoadGprFromGpr(pReNative, off, IEMNATIVE_CALL_ARG1_GREG, IEMNATIVE_CALL_RET_GREG);
    33783354        off = iemNativeEmitLoadGprFromGpr(pReNative, off, IEMNATIVE_CALL_ARG0_GREG, IEMNATIVE_REG_FIXED_PVMCPU);
    33793355        /* IEMNATIVE_CALL_ARG2_GREG is already set. */
    3380         off = iemNativeEmitLoadGprImm64(pReNative, off, IEMNATIVE_REG_FIXED_TMP0, (uintptr_t)iemNativeHlpExecStatusCodeFiddling);
    3381         AssertReturn(off != UINT32_MAX, UINT32_MAX);
    3382 #else
    3383 # error "port me"
    33843356#endif
    33853357
     
    34773449# error "port me"
    34783450#endif
     3451    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
    34793452
    34803453    return iemNativeEmitRcFiddling(pReNative, off, idxReturn);
     
    35833556# error "port me"
    35843557#endif
     3558    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
    35853559    return off;
    35863560}
  • 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