VirtualBox

Changeset 54746 in vbox for trunk


Ignore:
Timestamp:
Mar 13, 2015 3:53:54 PM (10 years ago)
Author:
vboxsync
Message:

Changed PATCHGEN_PROLOG to take the expected output size as input instead of making an educated guess at max 256 bytes. Adjusting patch stats a little.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMR3/PATM.cpp

    r54728 r54746  
    45844584            /* Full breakdown for the GUI. */
    45854585            STAMR3RegisterF(pVM, &pVM->patm.s.pStatsHC[pPatchRec->patch.uPatchIdx], STAMTYPE_RATIO_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_GOOD_BAD, PATMPatchType(pVM, &pPatchRec->patch),
    4586                             "/PATM/Stats/PatchBD/0x%RRv", pPatchRec->patch.pPrivInstrGC);
    4587             STAMR3RegisterF(pVM, &pPatchRec->patch.cbPatchBlockSize,STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES,      NULL, "/PATM/Stats/PatchBD/0x%RRv/cbPatchBlockSize", pPatchRec->patch.pPrivInstrGC);
    4588             STAMR3RegisterF(pVM, &pPatchRec->patch.cbPatchJump,     STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES,      NULL, "/PATM/Stats/PatchBD/0x%RRv/cbPatchJump", pPatchRec->patch.pPrivInstrGC);
    4589             STAMR3RegisterF(pVM, &pPatchRec->patch.cbPrivInstr,     STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES,      NULL, "/PATM/Stats/PatchBD/0x%RRv/cbPrivInstr", pPatchRec->patch.pPrivInstrGC);
    4590             STAMR3RegisterF(pVM, &pPatchRec->patch.cCodeWrites,     STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, NULL, "/PATM/Stats/PatchBD/0x%RRv/cCodeWrites", pPatchRec->patch.pPrivInstrGC);
    4591             STAMR3RegisterF(pVM, &pPatchRec->patch.cInvalidWrites,  STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, NULL, "/PATM/Stats/PatchBD/0x%RRv/cInvalidWrites", pPatchRec->patch.pPrivInstrGC);
    4592             STAMR3RegisterF(pVM, &pPatchRec->patch.cTraps,          STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, NULL, "/PATM/Stats/PatchBD/0x%RRv/cTraps", pPatchRec->patch.pPrivInstrGC);
    4593             STAMR3RegisterF(pVM, &pPatchRec->patch.flags,           STAMTYPE_X32, STAMVISIBILITY_ALWAYS, STAMUNIT_NONE,       NULL, "/PATM/Stats/PatchBD/0x%RRv/flags", pPatchRec->patch.pPrivInstrGC);
    4594             STAMR3RegisterF(pVM, &pPatchRec->patch.nrJumpRecs,      STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, NULL, "/PATM/Stats/PatchBD/0x%RRv/nrJumpRecs", pPatchRec->patch.pPrivInstrGC);
    4595             STAMR3RegisterF(pVM, &pPatchRec->patch.nrFixups,        STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, NULL, "/PATM/Stats/PatchBD/0x%RRv/nrFixups", pPatchRec->patch.pPrivInstrGC);
    4596             STAMR3RegisterF(pVM, &pPatchRec->patch.opcode,          STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, NULL, "/PATM/Stats/PatchBD/0x%RRv/opcode", pPatchRec->patch.pPrivInstrGC);
    4597             STAMR3RegisterF(pVM, &pPatchRec->patch.uOldState,       STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_NONE,       NULL, "/PATM/Stats/PatchBD/0x%RRv/uOldState", pPatchRec->patch.pPrivInstrGC);
    4598             STAMR3RegisterF(pVM, &pPatchRec->patch.uOpMode,         STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_NONE,       NULL, "/PATM/Stats/PatchBD/0x%RRv/uOpMode", pPatchRec->patch.pPrivInstrGC);
     4586                            "/PATM/PatchBD/0x%RRv", pPatchRec->patch.pPrivInstrGC);
     4587            STAMR3RegisterF(pVM, &pPatchRec->patch.pPatchBlockOffset,STAMTYPE_X32, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES,     NULL, "/PATM/PatchBD/0x%RRv/offPatchBlock", pPatchRec->patch.pPrivInstrGC);
     4588            STAMR3RegisterF(pVM, &pPatchRec->patch.cbPatchBlockSize,STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES,      NULL, "/PATM/PatchBD/0x%RRv/cbPatchBlockSize", pPatchRec->patch.pPrivInstrGC);
     4589            STAMR3RegisterF(pVM, &pPatchRec->patch.cbPatchJump,     STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES,      NULL, "/PATM/PatchBD/0x%RRv/cbPatchJump", pPatchRec->patch.pPrivInstrGC);
     4590            STAMR3RegisterF(pVM, &pPatchRec->patch.cbPrivInstr,     STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES,      NULL, "/PATM/PatchBD/0x%RRv/cbPrivInstr", pPatchRec->patch.pPrivInstrGC);
     4591            STAMR3RegisterF(pVM, &pPatchRec->patch.cCodeWrites,     STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, NULL, "/PATM/PatchBD/0x%RRv/cCodeWrites", pPatchRec->patch.pPrivInstrGC);
     4592            STAMR3RegisterF(pVM, &pPatchRec->patch.cInvalidWrites,  STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, NULL, "/PATM/PatchBD/0x%RRv/cInvalidWrites", pPatchRec->patch.pPrivInstrGC);
     4593            STAMR3RegisterF(pVM, &pPatchRec->patch.cTraps,          STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, NULL, "/PATM/PatchBD/0x%RRv/cTraps", pPatchRec->patch.pPrivInstrGC);
     4594            STAMR3RegisterF(pVM, &pPatchRec->patch.flags,           STAMTYPE_X64, STAMVISIBILITY_ALWAYS, STAMUNIT_NONE,       NULL, "/PATM/PatchBD/0x%RRv/flags", pPatchRec->patch.pPrivInstrGC);
     4595            STAMR3RegisterF(pVM, &pPatchRec->patch.nrJumpRecs,      STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, NULL, "/PATM/PatchBD/0x%RRv/nrJumpRecs", pPatchRec->patch.pPrivInstrGC);
     4596            STAMR3RegisterF(pVM, &pPatchRec->patch.nrFixups,        STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, NULL, "/PATM/PatchBD/0x%RRv/nrFixups", pPatchRec->patch.pPrivInstrGC);
     4597            STAMR3RegisterF(pVM, &pPatchRec->patch.opcode,          STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, NULL, "/PATM/PatchBD/0x%RRv/opcode", pPatchRec->patch.pPrivInstrGC);
     4598            STAMR3RegisterF(pVM, &pPatchRec->patch.uOldState,       STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_NONE,       NULL, "/PATM/PatchBD/0x%RRv/uOldState", pPatchRec->patch.pPrivInstrGC);
     4599            STAMR3RegisterF(pVM, &pPatchRec->patch.uOpMode,         STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_NONE,       NULL, "/PATM/PatchBD/0x%RRv/uOpMode", pPatchRec->patch.pPrivInstrGC);
    45994600            /// @todo change the state to be a callback so we can get a state mnemonic instead.
    4600             STAMR3RegisterF(pVM, &pPatchRec->patch.uState,          STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_NONE,       NULL, "/PATM/Stats/PatchBD/0x%RRv/uState", pPatchRec->patch.pPrivInstrGC);
     4601            STAMR3RegisterF(pVM, &pPatchRec->patch.uState,          STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_NONE,       NULL, "/PATM/PatchBD/0x%RRv/uState", pPatchRec->patch.pPrivInstrGC);
    46014602#endif
    46024603        }
     
    56375638    {
    56385639        STAMR3DeregisterF(pVM->pUVM, "/PATM/Stats/Patch/0x%RRv", pPatchRec->patch.pPrivInstrGC);
    5639         STAMR3DeregisterF(pVM->pUVM, "/PATM/Stats/PatchBD/0x%RRv*", pPatchRec->patch.pPrivInstrGC);
     5640        STAMR3DeregisterF(pVM->pUVM, "/PATM/PatchBD/0x%RRv*", pPatchRec->patch.pPrivInstrGC);
    56405641    }
    56415642#endif
     
    57505751    {
    57515752        STAMR3DeregisterF(pVM->pUVM, "/PATM/Stats/Patch/0x%RRv", pPatchRec->patch.pPrivInstrGC);
    5752         STAMR3DeregisterF(pVM->pUVM, "/PATM/Stats/PatchBD/0x%RRv*", pPatchRec->patch.pPrivInstrGC);
     5753        STAMR3DeregisterF(pVM->pUVM, "/PATM/PatchBD/0x%RRv*", pPatchRec->patch.pPrivInstrGC);
    57535754    }
    57545755#endif
  • trunk/src/VBox/VMM/VMMR3/PATMPatch.cpp

    r54714 r54746  
    77
    88/*
    9  * Copyright (C) 2006-2013 Oracle Corporation
     9 * Copyright (C) 2006-2015 Oracle Corporation
    1010 *
    1111 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    6565*   Defined Constants And Macros                                               *
    6666*******************************************************************************/
    67 #define PATCHGEN_PROLOG_NODEF(pVM, pPatch) \
     67/** Value to use when not sure about the patch size. */
     68#define PATCHGEN_DEF_SIZE   256
     69
     70#define PATCHGEN_PROLOG_NODEF(pVM, pPatch, a_cbMaxEmit) \
    6871    do { \
    69         pPB = PATCHCODE_PTR_HC(pPatch) + pPatch->uCurPatchOffset; \
    70         if (pPB + 256 >= pVM->patm.s.pPatchMemHC + pVM->patm.s.cbPatchMem) \
     72        cbGivenPatchSize = (a_cbMaxEmit) + 16U /*jmp++*/; \
     73        if (RT_LIKELY((pPatch)->pPatchBlockOffset + pPatch->uCurPatchOffset + cbGivenPatchSize < pVM->patm.s.cbPatchMem)) \
     74            pPB = PATCHCODE_PTR_HC(pPatch) + pPatch->uCurPatchOffset; \
     75        else \
    7176        { \
    7277            pVM->patm.s.fOutOfMemory = true; \
    73             Assert(pPB + 256 >= pVM->patm.s.pPatchMemHC + pVM->patm.s.cbPatchMem); \
     78            AssertMsgFailed(("offPatch=%#x + offEmit=%#x + a_cbMaxEmit=%#x + jmp -->  cbTotalWithFudge=%#x >= cbPatchMem=%#x", \
     79                             (pPatch)->pPatchBlockOffset, pPatch->uCurPatchOffset, a_cbMaxEmit, \
     80                             (pPatch)->pPatchBlockOffset + pPatch->uCurPatchOffset + cbGivenPatchSize, pVM->patm.s.cbPatchMem)); \
    7481            return VERR_NO_MEMORY; \
    7582        } \
    7683    } while (0)
    7784
    78 #define PATCHGEN_PROLOG(pVM, pPatch) \
     85#define PATCHGEN_PROLOG(pVM, pPatch, a_cbMaxEmit) \
    7986    uint8_t *pPB; \
    80     PATCHGEN_PROLOG_NODEF(pVM, pPatch)
    81 
    82 #define PATCHGEN_EPILOG(pPatch, size) \
     87    uint32_t cbGivenPatchSize; \
     88    PATCHGEN_PROLOG_NODEF(pVM, pPatch, a_cbMaxEmit)
     89
     90#define PATCHGEN_EPILOG(pPatch, a_cbActual) \
    8391    do { \
    84         Assert(size <= 640); \
    85         pPatch->uCurPatchOffset += size; \
     92        AssertMsg((a_cbActual) <= cbGivenPatchSize, ("a_cbActual=%#x cbGivenPatchSize=%#x\n", a_cbActual, cbGivenPatchSize)); \
     93        Assert((a_cbActual) <= 640); \
     94        pPatch->uCurPatchOffset += (a_cbActual); \
    8695    } while (0)
    8796
     
    441450int patmPatchGenDuplicate(PVM pVM, PPATCHINFO pPatch, DISCPUSTATE *pCpu, RCPTRTYPE(uint8_t *) pCurInstrGC)
    442451{
    443     int rc = VINF_SUCCESS;
    444     PATCHGEN_PROLOG(pVM, pPatch);
    445 
    446452    uint32_t const cbInstrShutUpGcc = pCpu->cbInstr;
    447     rc = patmPatchReadBytes(pVM, pPB, pCurInstrGC, cbInstrShutUpGcc);
     453    PATCHGEN_PROLOG(pVM, pPatch, cbInstrShutUpGcc);
     454
     455    int rc = patmPatchReadBytes(pVM, pPB, pCurInstrGC, cbInstrShutUpGcc);
    448456    AssertRC(rc);
    449457    PATCHGEN_EPILOG(pPatch, cbInstrShutUpGcc);
     
    455463    uint32_t size;
    456464    PATMCALLINFO callInfo;
    457 
    458     PATCHGEN_PROLOG(pVM, pPatch);
     465    PCPATCHASMRECORD pPatchAsmRec = EMIsRawRing1Enabled(pVM) ? &g_patmIretRing1Record : &g_patmIretRecord;
     466
     467    PATCHGEN_PROLOG(pVM, pPatch, pPatchAsmRec->cbFunction);
    459468
    460469    AssertMsg(fSizeOverride == false, ("operand size override!!\n"));
    461470    callInfo.pCurInstrGC = pCurInstrGC;
    462471
    463     if (EMIsRawRing1Enabled(pVM))
    464         size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmIretRing1Record, 0, false, &callInfo);
    465     else
    466         size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmIretRecord, 0, false, &callInfo);
     472    size = patmPatchGenCode(pVM, pPatch, pPB, pPatchAsmRec, 0, false, &callInfo);
    467473
    468474    PATCHGEN_EPILOG(pPatch, size);
     
    473479{
    474480    uint32_t size;
    475     PATCHGEN_PROLOG(pVM, pPatch);
     481    PATCHGEN_PROLOG(pVM, pPatch, g_patmCliRecord.cbFunction);
    476482
    477483    size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmCliRecord, 0, false);
     
    490496
    491497    Log(("patmPatchGenSti at %RRv; next %RRv\n", pCurInstrGC, pNextInstrGC));
    492     PATCHGEN_PROLOG(pVM, pPatch);
     498    PATCHGEN_PROLOG(pVM, pPatch, g_patmStiRecord.cbFunction);
    493499    callInfo.pNextInstrGC = pNextInstrGC;
    494500    size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmStiRecord, 0, false, &callInfo);
     
    503509    uint32_t        size;
    504510    PATMCALLINFO    callInfo;
    505 
    506     PATCHGEN_PROLOG(pVM, pPatch);
     511    PCPATCHASMRECORD pPatchAsmRec;
     512    if (fSizeOverride == true)
     513        pPatchAsmRec = fGenJumpBack ? &g_patmPopf16Record : &g_patmPopf16Record_NoExit;
     514    else
     515        pPatchAsmRec = fGenJumpBack ? &g_patmPopf32Record : &g_patmPopf32Record_NoExit;
     516
     517    PATCHGEN_PROLOG(pVM, pPatch, pPatchAsmRec->cbFunction);
    507518
    508519    callInfo.pNextInstrGC = pReturnAddrGC;
     
    512523    /* Note: keep IOPL in mind when changing any of this!! (see comments in PATMA.asm, PATMPopf32Replacement) */
    513524    if (fSizeOverride == true)
    514     {
    515525        Log(("operand size override!!\n"));
    516         size = patmPatchGenCode(pVM, pPatch, pPB, (fGenJumpBack) ? &g_patmPopf16Record : &g_patmPopf16Record_NoExit , pReturnAddrGC, fGenJumpBack, &callInfo);
    517     }
    518     else
    519     {
    520         size = patmPatchGenCode(pVM, pPatch, pPB, (fGenJumpBack) ? &g_patmPopf32Record : &g_patmPopf32Record_NoExit, pReturnAddrGC, fGenJumpBack, &callInfo);
    521     }
     526    size = patmPatchGenCode(pVM, pPatch, pPB, pPatchAsmRec, pReturnAddrGC, fGenJumpBack, &callInfo);
    522527
    523528    PATCHGEN_EPILOG(pPatch, size);
     
    529534{
    530535    uint32_t size;
    531     PATCHGEN_PROLOG(pVM, pPatch);
    532 
    533     if (fSizeOverride == true)
    534     {
    535         Log(("operand size override!!\n"));
    536         size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmPushf16Record, 0, false);
    537     }
    538     else
    539     {
    540         size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmPushf32Record, 0, false);
    541     }
     536    PCPATCHASMRECORD pPatchAsmRec = fSizeOverride == true ?  &g_patmPushf16Record : &g_patmPushf32Record;
     537    PATCHGEN_PROLOG(pVM, pPatch, pPatchAsmRec->cbFunction);
     538
     539    size = patmPatchGenCode(pVM, pPatch, pPB, pPatchAsmRec, 0, false);
    542540
    543541    PATCHGEN_EPILOG(pPatch, size);
     
    548546{
    549547    uint32_t size;
    550     PATCHGEN_PROLOG(pVM, pPatch);
     548    PATCHGEN_PROLOG(pVM, pPatch, g_patmPushCSRecord.cbFunction);
    551549    size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmPushCSRecord, 0, false);
    552550    PATCHGEN_EPILOG(pPatch, size);
     
    558556    uint32_t size = 0;
    559557    PCPATCHASMRECORD pPatchAsmRec;
    560 
    561     PATCHGEN_PROLOG(pVM, pPatch);
    562 
    563558    switch (opcode)
    564559    {
     
    581576    Assert(pPatchAsmRec->offSizeOverride && pPatchAsmRec->offRelJump);
    582577
     578    PATCHGEN_PROLOG(pVM, pPatch, pPatchAsmRec->cbFunction);
    583579    Log(("PatchGenLoop %d jump %d to %08x offrel=%d\n", opcode, pPatch->nrJumpRecs, pTargetGC, pPatchAsmRec->offRelJump));
    584580
     
    602598{
    603599    uint32_t offset = 0;
    604     PATCHGEN_PROLOG(pVM, pPatch);
     600    PATCHGEN_PROLOG(pVM, pPatch, PATCHGEN_DEF_SIZE);
    605601
    606602    // internal relative jumps from patch code to patch code; no relocation record required
     
    713709    AssertRCReturn(rc, rc);
    714710
    715     PATCHGEN_PROLOG(pVM, pPatch);
     711    PATCHGEN_PROLOG(pVM, pPatch, PATCHGEN_DEF_SIZE);
    716712    /* 2: We must push the target address onto the stack before appending the indirect call code. */
    717713
     
    773769
    774770    /* 3: Generate code to lookup address in our local cache; call hypervisor PATM code if it can't be located. */
    775     PATCHGEN_PROLOG_NODEF(pVM, pPatch);
     771    PCPATCHASMRECORD pPatchAsmRec = fIndirect ? &g_patmCallIndirectRecord : &g_patmCallRecord;
     772    PATCHGEN_PROLOG_NODEF(pVM, pPatch, pPatchAsmRec->cbFunction);
    776773    callInfo.pReturnGC      = pCurInstrGC + pCpu->cbInstr;
    777774    callInfo.pTargetGC      = (fIndirect) ? 0xDEADBEEF : pTargetGC;
    778     size = patmPatchGenCode(pVM, pPatch, pPB, (fIndirect) ? &g_patmCallIndirectRecord : &g_patmCallRecord, 0, false, &callInfo);
     775    size = patmPatchGenCode(pVM, pPatch, pPB, pPatchAsmRec, 0, false, &callInfo);
    779776    PATCHGEN_EPILOG(pPatch, size);
    780777
     
    811808    AssertRCReturn(rc, rc);
    812809
    813     PATCHGEN_PROLOG(pVM, pPatch);
     810    PATCHGEN_PROLOG(pVM, pPatch, PATCHGEN_DEF_SIZE);
    814811    /* 2: We must push the target address onto the stack before appending the indirect call code. */
    815812
     
    850847
    851848    /* 3: Generate code to lookup address in our local cache; call hypervisor PATM code if it can't be located. */
    852     PATCHGEN_PROLOG_NODEF(pVM, pPatch);
     849    PATCHGEN_PROLOG_NODEF(pVM, pPatch, g_patmJumpIndirectRecord.cbFunction);
    853850    callInfo.pReturnGC      = pCurInstrGC + pCpu->cbInstr;
    854851    callInfo.pTargetGC      = 0xDEADBEEF;
     
    872869int patmPatchGenRet(PVM pVM, PPATCHINFO pPatch, DISCPUSTATE *pCpu, RCPTRTYPE(uint8_t *) pCurInstrGC)
    873870{
    874     int size = 0, rc;
    875871    RTRCPTR pPatchRetInstrGC;
    876872
     
    892888    /* Jump back to the original instruction if IF is set again. */
    893889    Assert(!patmFindActivePatchByEntrypoint(pVM, pCurInstrGC));
    894     rc = patmPatchGenCheckIF(pVM, pPatch, pCurInstrGC);
     890    int rc = patmPatchGenCheckIF(pVM, pPatch, pCurInstrGC);
    895891    AssertRCReturn(rc, rc);
    896892
    897893    /* align this block properly to make sure the jump table will not be misaligned. */
    898     PATCHGEN_PROLOG(pVM, pPatch);
    899     size = (RTHCUINTPTR)pPB & 3;
     894    PATCHGEN_PROLOG(pVM, pPatch, 4);
     895    uint32_t size = (RTHCUINTPTR)pPB & 3;
    900896    if (size)
    901897        size = 4 - size;
    902898
    903     for (int i=0;i<size;i++)
     899    for (uint32_t i = 0; i < size; i++)
    904900        pPB[i] = 0x90;   /* nop */
    905901    PATCHGEN_EPILOG(pPatch, size);
    906902
    907     PATCHGEN_PROLOG_NODEF(pVM, pPatch);
     903    PATCHGEN_PROLOG_NODEF(pVM, pPatch, g_patmRetRecord.cbFunction);
    908904    size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmRetRecord, 0, false);
    909905    PATCHGEN_EPILOG(pPatch, size);
     
    931927int patmPatchGenGlobalFunctions(PVM pVM, PPATCHINFO pPatch)
    932928{
    933     int size = 0;
    934 
    935929    pVM->patm.s.pfnHelperCallGC = PATCHCODE_PTR_GC(pPatch) + pPatch->uCurPatchOffset;
    936     PATCHGEN_PROLOG(pVM, pPatch);
    937     size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmLookupAndCallRecord, 0, false);
     930    PATCHGEN_PROLOG(pVM, pPatch, g_patmLookupAndCallRecord.cbFunction);
     931    uint32_t size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmLookupAndCallRecord, 0, false);
    938932    PATCHGEN_EPILOG(pPatch, size);
    939933
     
    942936
    943937    pVM->patm.s.pfnHelperRetGC = PATCHCODE_PTR_GC(pPatch) + pPatch->uCurPatchOffset;
    944     PATCHGEN_PROLOG_NODEF(pVM, pPatch);
     938    PATCHGEN_PROLOG_NODEF(pVM, pPatch, g_patmRetFunctionRecord.cbFunction);
    945939    size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmRetFunctionRecord, 0, false);
    946940    PATCHGEN_EPILOG(pPatch, size);
     
    950944
    951945    pVM->patm.s.pfnHelperJumpGC = PATCHCODE_PTR_GC(pPatch) + pPatch->uCurPatchOffset;
    952     PATCHGEN_PROLOG_NODEF(pVM, pPatch);
     946    PATCHGEN_PROLOG_NODEF(pVM, pPatch, g_patmLookupAndJumpRecord.cbFunction);
    953947    size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmLookupAndJumpRecord, 0, false);
    954948    PATCHGEN_EPILOG(pPatch, size);
     
    958952
    959953    pVM->patm.s.pfnHelperIretGC = PATCHCODE_PTR_GC(pPatch) + pPatch->uCurPatchOffset;
    960     PATCHGEN_PROLOG_NODEF(pVM, pPatch);
     954    PATCHGEN_PROLOG_NODEF(pVM, pPatch, g_patmIretFunctionRecord.cbFunction);
    961955    size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmIretFunctionRecord, 0, false);
    962956    PATCHGEN_EPILOG(pPatch, size);
     
    980974int patmPatchGenIllegalInstr(PVM pVM, PPATCHINFO pPatch)
    981975{
    982     PATCHGEN_PROLOG(pVM, pPatch);
     976    PATCHGEN_PROLOG(pVM, pPatch, 1);
    983977
    984978    pPB[0] = 0xCC;
     
    1001995    uint32_t size;
    1002996
    1003     PATCHGEN_PROLOG(pVM, pPatch);
     997    PATCHGEN_PROLOG(pVM, pPatch, g_patmCheckIFRecord.cbFunction);
    1004998
    1005999    /* Add lookup record for patch to guest address translation */
     
    10241018int patmPatchGenSetPIF(PVM pVM, PPATCHINFO pPatch, RTRCPTR pInstrGC)
    10251019{
    1026     PATCHGEN_PROLOG(pVM, pPatch);
     1020    PATCHGEN_PROLOG(pVM, pPatch, g_patmSetPIFRecord.cbFunction);
    10271021
    10281022    /* Add lookup record for patch to guest address translation */
    10291023    patmR3AddP2GLookupRecord(pVM, pPatch, pPB, pInstrGC, PATM_LOOKUP_PATCH2GUEST);
    10301024
    1031     int size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmSetPIFRecord, 0, false);
     1025    uint32_t size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmSetPIFRecord, 0, false);
    10321026    PATCHGEN_EPILOG(pPatch, size);
    10331027    return VINF_SUCCESS;
     
    10451039int patmPatchGenClearPIF(PVM pVM, PPATCHINFO pPatch, RTRCPTR pInstrGC)
    10461040{
    1047     PATCHGEN_PROLOG(pVM, pPatch);
     1041    PATCHGEN_PROLOG(pVM, pPatch, g_patmSetPIFRecord.cbFunction);
    10481042
    10491043    /* Add lookup record for patch to guest address translation */
    10501044    patmR3AddP2GLookupRecord(pVM, pPatch, pPB, pInstrGC, PATM_LOOKUP_PATCH2GUEST);
    10511045
    1052     int size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmClearPIFRecord, 0, false);
     1046    uint32_t size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmClearPIFRecord, 0, false);
    10531047    PATCHGEN_EPILOG(pPatch, size);
    10541048    return VINF_SUCCESS;
     
    10661060int patmPatchGenClearInhibitIRQ(PVM pVM, PPATCHINFO pPatch, RTRCPTR pNextInstrGC)
    10671061{
    1068     int          size;
    10691062    PATMCALLINFO callInfo;
    1070 
    1071     PATCHGEN_PROLOG(pVM, pPatch);
     1063    PCPATCHASMRECORD pPatchAsmRec = pPatch->flags & PATMFL_DUPLICATE_FUNCTION
     1064                                  ? &g_patmClearInhibitIRQContIF0Record : &g_patmClearInhibitIRQFaultIF0Record;
     1065    PATCHGEN_PROLOG(pVM, pPatch, pPatchAsmRec->cbFunction);
    10721066
    10731067    Assert((pPatch->flags & (PATMFL_GENERATE_JUMPTOGUEST|PATMFL_DUPLICATE_FUNCTION)) != (PATMFL_GENERATE_JUMPTOGUEST|PATMFL_DUPLICATE_FUNCTION));
     
    10781072    callInfo.pNextInstrGC = pNextInstrGC;
    10791073
    1080     if (pPatch->flags & PATMFL_DUPLICATE_FUNCTION)
    1081         size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmClearInhibitIRQContIF0Record, 0, false, &callInfo);
    1082     else
    1083         size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmClearInhibitIRQFaultIF0Record, 0, false, &callInfo);
     1074    uint32_t size = patmPatchGenCode(pVM, pPatch, pPB, pPatchAsmRec, 0, false, &callInfo);
    10841075
    10851076    PATCHGEN_EPILOG(pPatch, size);
     
    11061097    {
    11071098        uint32_t size;
    1108         PATCHGEN_PROLOG(pVM, pPatch);
     1099        PCPATCHASMRECORD pPatchAsmRec = pPatch->flags & PATMFL_INTHANDLER_WITH_ERRORCODE
     1100                                      ? &g_patmIntEntryRecordErrorCode : &g_patmIntEntryRecord;
     1101        PATCHGEN_PROLOG(pVM, pPatch, pPatchAsmRec->cbFunction);
    11091102
    11101103        /* Add lookup record for patch to guest address translation */
     
    11121105
    11131106        /* Generate entrypoint for the interrupt handler (correcting CS in the interrupt stack frame) */
    1114         size = patmPatchGenCode(pVM, pPatch, pPB,
    1115                                 (pPatch->flags & PATMFL_INTHANDLER_WITH_ERRORCODE) ? &g_patmIntEntryRecordErrorCode : &g_patmIntEntryRecord,
    1116                                 0, false);
     1107        size = patmPatchGenCode(pVM, pPatch, pPB, pPatchAsmRec, 0, false);
    11171108
    11181109        PATCHGEN_EPILOG(pPatch, size);
     
    11371128{
    11381129    uint32_t size;
     1130    PCPATCHASMRECORD pPatchAsmRec = (pPatch->flags & PATMFL_TRAPHANDLER_WITH_ERRORCODE)
     1131                                  ? &g_patmTrapEntryRecordErrorCode : &g_patmTrapEntryRecord;
    11391132
    11401133    Assert(!EMIsRawRing1Enabled(pVM));
    11411134
    1142     PATCHGEN_PROLOG(pVM, pPatch);
     1135    PATCHGEN_PROLOG(pVM, pPatch, pPatchAsmRec->cbFunction);
    11431136
    11441137    /* Add lookup record for patch to guest address translation */
     
    11461139
    11471140    /* Generate entrypoint for the trap handler (correcting CS in the interrupt stack frame) */
    1148     size = patmPatchGenCode(pVM, pPatch, pPB,
    1149                             (pPatch->flags & PATMFL_TRAPHANDLER_WITH_ERRORCODE) ? &g_patmTrapEntryRecordErrorCode : &g_patmTrapEntryRecord,
    1150                             pTrapHandlerGC, true);
     1141    size = patmPatchGenCode(pVM, pPatch, pPB, pPatchAsmRec, pTrapHandlerGC, true);
    11511142    PATCHGEN_EPILOG(pPatch, size);
    11521143
     
    11591150    uint32_t size;
    11601151
    1161     PATCHGEN_PROLOG(pVM, pPatch);
     1152    PATCHGEN_PROLOG(pVM, pPatch, g_patmStatsRecord.cbFunction);
    11621153
    11631154    /* Add lookup record for stats code -> guest handler. */
     
    11861177    uint32_t offset;
    11871178
    1188     PATCHGEN_PROLOG(pVM, pPatch);
     1179    PATCHGEN_PROLOG(pVM, pPatch, PATCHGEN_DEF_SIZE);
    11891180
    11901181    mod = 0;            //effective address (only)
     
    12361227    uint32_t offset;
    12371228
    1238     PATCHGEN_PROLOG(pVM, pPatch);
     1229    PATCHGEN_PROLOG(pVM, pPatch, PATCHGEN_DEF_SIZE);
    12391230
    12401231    mod = 0;            //effective address (only)
     
    13021293    Assert(pPatch->flags & PATMFL_CODE32);
    13031294
    1304     PATCHGEN_PROLOG(pVM, pPatch);
     1295    PATCHGEN_PROLOG(pVM, pPatch, g_patmClearPIFRecord.cbFunction + 2 + g_patmMovFromSSRecord.cbFunction + 2 + g_patmSetPIFRecord.cbFunction);
    13051296    size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmClearPIFRecord, 0, false);
    13061297    PATCHGEN_EPILOG(pPatch, size);
    13071298
    13081299    /* push ss */
    1309     PATCHGEN_PROLOG_NODEF(pVM, pPatch);
     1300    PATCHGEN_PROLOG_NODEF(pVM, pPatch, 2);
    13101301    offset = 0;
    13111302    if (pCpu->fPrefix & DISPREFIX_OPSIZE)
     
    13151306
    13161307    /* checks and corrects RPL of pushed ss*/
    1317     PATCHGEN_PROLOG_NODEF(pVM, pPatch);
     1308    PATCHGEN_PROLOG_NODEF(pVM, pPatch, g_patmMovFromSSRecord.cbFunction);
    13181309    size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmMovFromSSRecord, 0, false);
    13191310    PATCHGEN_EPILOG(pPatch, size);
    13201311
    13211312    /* pop general purpose register */
    1322     PATCHGEN_PROLOG_NODEF(pVM, pPatch);
     1313    PATCHGEN_PROLOG_NODEF(pVM, pPatch, 2);
    13231314    offset = 0;
    13241315    if (pCpu->fPrefix & DISPREFIX_OPSIZE)
     
    13281319
    13291320
    1330     PATCHGEN_PROLOG_NODEF(pVM, pPatch);
     1321    PATCHGEN_PROLOG_NODEF(pVM, pPatch, g_patmSetPIFRecord.cbFunction);
    13311322    size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmSetPIFRecord, 0, false);
    13321323    PATCHGEN_EPILOG(pPatch, size);
     
    13551346    Assert(pCpu->fPrefix == DISPREFIX_NONE || pCpu->fPrefix == DISPREFIX_OPSIZE);
    13561347
    1357     PATCHGEN_PROLOG(pVM, pPatch);
     1348    PATCHGEN_PROLOG(pVM, pPatch, PATCHGEN_DEF_SIZE);
    13581349
    13591350    if (pCpu->Param1.fUse == DISUSE_REG_GEN32 || pCpu->Param1.fUse == DISUSE_REG_GEN16)
     
    14841475//58                   pop         eax
    14851476
    1486     PATCHGEN_PROLOG(pVM, pPatch);
     1477    PATCHGEN_PROLOG(pVM, pPatch, PATCHGEN_DEF_SIZE);
    14871478    pPB[offset++] = 0x50;              // push      eax
    14881479    pPB[offset++] = 0x52;              // push      edx
     
    15431534{
    15441535    uint32_t size;
    1545     PATCHGEN_PROLOG(pVM, pPatch);
     1536    PATCHGEN_PROLOG(pVM, pPatch, g_patmCpuidRecord.cbFunction);
    15461537
    15471538    size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmCpuidRecord, 0, false);
     
    15741565    }
    15751566
    1576     PATCHGEN_PROLOG(pVM, pPatch);
     1567    PATCHGEN_PROLOG(pVM, pPatch, PATMJumpToGuest_IF1Record.cbFunction);
    15771568
    15781569    /* Add lookup record for patch to guest address translation */
     
    15951586
    15961587    Assert(PATMIsPatchGCAddr(pVM, pPatchAddrGC));
    1597     PATCHGEN_PROLOG(pVM, pPatch);
     1588    PATCHGEN_PROLOG(pVM, pPatch, SIZEOF_NEARJUMP32);
    15981589
    15991590    if (fAddLookupRecord)
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