VirtualBox

Changeset 54686 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Mar 8, 2015 8:51:01 PM (10 years ago)
Author:
vboxsync
Message:

PATM: Added some comments and formalized the reloc array type (instead of having two anonymous uint32_t's).

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

Legend:

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

    r52771 r54686  
    308308#endif /* VBOX_WITH_STATISTICS */
    309309
    310     Log(("PATMCallRecord.size           %d\n", PATMCallRecord.size));
    311     Log(("PATMCallIndirectRecord.size   %d\n", PATMCallIndirectRecord.size));
    312     Log(("PATMRetRecord.size            %d\n", PATMRetRecord.size));
    313     Log(("PATMJumpIndirectRecord.size   %d\n", PATMJumpIndirectRecord.size));
    314     Log(("PATMPopf32Record.size         %d\n", PATMPopf32Record.size));
    315     Log(("PATMIretRecord.size           %d\n", PATMIretRecord.size));
    316     Log(("PATMStiRecord.size            %d\n", PATMStiRecord.size));
    317     Log(("PATMCheckIFRecord.size        %d\n", PATMCheckIFRecord.size));
     310    Log(("PATMCallRecord.cbFunction           %u\n", PATMCallRecord.cbFunction));
     311    Log(("PATMCallIndirectRecord.cbFunction   %u\n", PATMCallIndirectRecord.cbFunction));
     312    Log(("PATMRetRecord.cbFunction            %u\n", PATMRetRecord.cbFunction));
     313    Log(("PATMJumpIndirectRecord.cbFunction   %u\n", PATMJumpIndirectRecord.cbFunction));
     314    Log(("PATMPopf32Record.cbFunction         %u\n", PATMPopf32Record.cbFunction));
     315    Log(("PATMIretRecord.cbFunction           %u\n", PATMIretRecord.cbFunction));
     316    Log(("PATMStiRecord.cbFunction            %u\n", PATMStiRecord.cbFunction));
     317    Log(("PATMCheckIFRecord.cbFunction        %u\n", PATMCheckIFRecord.cbFunction));
    318318
    319319    return rc;
  • trunk/src/VBox/VMM/VMMR3/PATMA.asm

    r45276 r54686  
    19121912SECTION .data
    19131913; Patch record for 'cpuid'
    1914 GLOBALNAME PATMCpuidRecord
    1915     RTCCPTR_DEF PATMCpuidStart
    1916     DD      0
    1917     DD      0
    1918     DD      0
    1919     DD      PATMCpuidEnd- PATMCpuidStart
    1920     DD      9
    1921     DD      PATM_INTERRUPTFLAG
    1922     DD      0
    1923     DD      PATM_CPUID_STD_MAX
    1924     DD      0
    1925     DD      PATM_CPUID_EXT_MAX
    1926     DD      0
    1927     DD      PATM_CPUID_CENTAUR_MAX
    1928     DD      0
    1929     DD      PATM_CPUID_DEF_PTR
    1930     DD      0
    1931     DD      PATM_CPUID_STD_PTR
    1932     DD      0
    1933     DD      PATM_CPUID_EXT_PTR
    1934     DD      0
    1935     DD      PATM_CPUID_CENTAUR_PTR
    1936     DD      0
    1937     DD      PATM_INTERRUPTFLAG
    1938     DD      0
    1939     DD      0ffffffffh
     1914GLOBALNAME PATMCpuidRecord
     1915    istruc PATCHASMRECORD
     1916    at PATCHASMRECORD.pbFunction,     RTCCPTR_DEF PATMCpuidStart
     1917    at PATCHASMRECORD.offJump,        DD          0
     1918    at PATCHASMRECORD.offRelJump,     DD          0
     1919    at PATCHASMRECORD.offSizeOverride,DD          0
     1920    at PATCHASMRECORD.cbFunction,     DD          PATMCpuidEnd- PATMCpuidStart
     1921    at PATCHASMRECORD.cRelocs,        DD          9
     1922    iend
     1923    DD      PATM_INTERRUPTFLAG,     0       ; 0
     1924    DD      PATM_CPUID_STD_MAX,     0       ; 1
     1925    DD      PATM_CPUID_EXT_MAX,     0       ; 2
     1926    DD      PATM_CPUID_CENTAUR_MAX, 0       ; 3
     1927    DD      PATM_CPUID_DEF_PTR,     0       ; 4
     1928    DD      PATM_CPUID_STD_PTR,     0       ; 5
     1929    DD      PATM_CPUID_EXT_PTR,     0       ; 6
     1930    DD      PATM_CPUID_CENTAUR_PTR, 0       ; 7
     1931    DD      PATM_INTERRUPTFLAG,     0       ; 8
     1932    DD      0ffffffffh, 0ffffffffh          ; 9 - for sanity checks
    19401933SECTION .text
    19411934
  • trunk/src/VBox/VMM/VMMR3/PATMA.mac

    r44528 r54686  
    11; $Id$
    22;; @file
    3 ; PATM macros & definitions (identical to PATMA.h!!)
     3; PATM macros & definitions (identical to PATMA.h!).
    44;
    55
    66;
    7 ; Copyright (C) 2006-2010 Oracle Corporation
     7; Copyright (C) 2006-2015 Oracle Corporation
    88;
    99; This file is part of VirtualBox Open Source Edition (OSE), as
     
    1919%define PATM_INT3            int3
    2020
    21 %define PATM_VMFLAGS         0xF1ABCD00
     21;; @name Patch Fixup Types
     22; @{
     23%define PATM_VMFLAGS                            0xF1ABCD00
    2224%ifdef VBOX_WITH_STATISTICS
    23 %define PATM_ALLPATCHCALLS   0xF1ABCD01
    24 %define PATM_PERPATCHCALLS   0xF1ABCD02
     25 %define PATM_ALLPATCHCALLS                     0xF1ABCD01
     26 %define PATM_PERPATCHCALLS                     0xF1ABCD02
    2527%endif
    26 %define PATM_JUMPDELTA       0xF1ABCD03
     28%define PATM_JUMPDELTA                          0xF1ABCD03
    2729%ifdef VBOX_WITH_STATISTICS
    28 %define PATM_IRETEFLAGS      0xF1ABCD04
    29 %define PATM_IRETCS          0xF1ABCD05
    30 %define PATM_IRETEIP         0xF1ABCD06
     30 %define PATM_IRETEFLAGS                        0xF1ABCD04
     31 %define PATM_IRETCS                            0xF1ABCD05
     32 %define PATM_IRETEIP                           0xF1ABCD06
    3133%endif
    32 %define PATM_FIXUP           0xF1ABCD07
    33 %define PATM_PENDINGACTION   0xF1ABCD08
    34 %define PATM_CPUID_STD_PTR   0xF1ABCD09
    35 %define PATM_CPUID_EXT_PTR   0xF1ABCD0a
    36 %define PATM_CPUID_DEF_PTR   0xF1ABCD0b
    37 %define PATM_STACKBASE       0xF1ABCD0c    ;/** Stack to store our private patch return addresses */
    38 %define PATM_STACKBASE_GUEST 0xF1ABCD0d    ;/** Stack to store guest return addresses */
    39 %define PATM_STACKPTR        0xF1ABCD0e
    40 %define PATM_PATCHBASE       0xF1ABCD0f
    41 %define PATM_INTERRUPTFLAG   0xF1ABCD10
    42 %define PATM_INHIBITIRQADDR  0xF1ABCD11
    43 %define PATM_VM_FORCEDACTIONS  0xF1ABCD12
    44 %define PATM_TEMP_EAX                           0xF1ABCD13      ;/** Location for original EAX register */
    45 %define PATM_TEMP_ECX                           0xF1ABCD14      ;/** Location for original ECX register */
    46 %define PATM_TEMP_EDI                           0xF1ABCD15      ;/** Location for original EDI register */
    47 %define PATM_TEMP_EFLAGS                        0xF1ABCD16      ;/** Location for original eflags */
    48 %define PATM_TEMP_RESTORE_FLAGS                 0xF1ABCD17      ;/** Which registers to restore */
     34%define PATM_FIXUP                              0xF1ABCD07
     35%define PATM_PENDINGACTION                      0xF1ABCD08
     36%define PATM_CPUID_STD_PTR                      0xF1ABCD09
     37%define PATM_CPUID_EXT_PTR                      0xF1ABCD0a
     38%define PATM_CPUID_DEF_PTR                      0xF1ABCD0b
     39%define PATM_STACKBASE                          0xF1ABCD0c  ;;< Stack to store our private patch return addresses
     40%define PATM_STACKBASE_GUEST                    0xF1ABCD0d  ;;< Stack to store guest return addresses
     41%define PATM_STACKPTR                           0xF1ABCD0e
     42%define PATM_PATCHBASE                          0xF1ABCD0f
     43%define PATM_INTERRUPTFLAG                      0xF1ABCD10
     44%define PATM_INHIBITIRQADDR                     0xF1ABCD11
     45%define PATM_VM_FORCEDACTIONS                   0xF1ABCD12
     46%define PATM_TEMP_EAX                           0xF1ABCD13  ;;< Location for original EAX register
     47%define PATM_TEMP_ECX                           0xF1ABCD14  ;;< Location for original ECX register
     48%define PATM_TEMP_EDI                           0xF1ABCD15  ;;< Location for original EDI register
     49%define PATM_TEMP_EFLAGS                        0xF1ABCD16  ;;< Location for original eflags
     50%define PATM_TEMP_RESTORE_FLAGS                 0xF1ABCD17  ;;< Which registers to restore
    4951%define PATM_CALL_PATCH_TARGET_ADDR             0xF1ABCD18
    5052%define PATM_CALL_RETURN_ADDR                   0xF1ABCD19
    51 %define PATM_CPUID_CENTAUR_PTR                  0xF1ABCD1A
     53%define PATM_CPUID_CENTAUR_PTR                  0xF1ABCD1a
    5254
    5355;/* Anything larger doesn't require a fixup */
    54 %define PATM_NO_FIXUP        0xF1ABCE00
    55 %define PATM_CPUID_STD_MAX   0xF1ABCE00
    56 %define PATM_CPUID_EXT_MAX   0xF1ABCE01
    57 %define PATM_RETURNADDR      0xF1ABCE02
    58 %define PATM_PATCHNEXTBLOCK  0xF1ABCE03
    59 %define PATM_CALLTARGET      0xF1ABCE04    ; /* relative */
    60 %define PATM_NEXTINSTRADDR   0xF1ABCE05    ; /* absolute guest address of the next instruction */
    61 %define PATM_CURINSTRADDR    0xF1ABCE06    ; /* absolute guest address of the current instruction */
    62 %define PATM_LOOKUP_AND_CALL_FUNCTION           0xF1ABCE07   ; /** Relative address of global PATM lookup and call function. */
    63 %define PATM_RETURN_FUNCTION                    0xF1ABCE08   ; /** Relative address of global PATM return function. */
    64 %define PATM_LOOKUP_AND_JUMP_FUNCTION           0xF1ABCE09   ; /** Relative address of global PATM lookup and jump function. */
    65 %define PATM_IRET_FUNCTION                      0xF1ABCE0A   ; /** Relative address of global PATM iret function. */
     56%define PATM_NO_FIXUP                           0xF1ABCE00
     57%define PATM_CPUID_STD_MAX                      0xF1ABCE00
     58%define PATM_CPUID_EXT_MAX                      0xF1ABCE01
     59%define PATM_RETURNADDR                         0xF1ABCE02
     60%define PATM_PATCHNEXTBLOCK                     0xF1ABCE03
     61%define PATM_CALLTARGET                         0xF1ABCE04  ;;< relative call target
     62%define PATM_NEXTINSTRADDR                      0xF1ABCE05  ;;< absolute guest address of the next instruction
     63%define PATM_CURINSTRADDR                       0xF1ABCE06  ;;< absolute guest address of the current instruction
     64%define PATM_LOOKUP_AND_CALL_FUNCTION           0xF1ABCE07  ;;< Relative address of global PATM lookup and call function.
     65%define PATM_RETURN_FUNCTION                    0xF1ABCE08  ;;< Relative address of global PATM return function.
     66%define PATM_LOOKUP_AND_JUMP_FUNCTION           0xF1ABCE09  ;;< Relative address of global PATM lookup and jump function.
     67%define PATM_IRET_FUNCTION                      0xF1ABCE0A  ;;< Relative address of global PATM iret function.
    6668%define PATM_CPUID_CENTAUR_MAX                  0xF1ABCE0B
     69;; @}
    6770
    6871
    69 ; everything except IOPL, NT, IF, VM, VIF, VIP and RF
     72;; Everything except IOPL, NT, IF, VM, VIF, VIP and RF
    7073%define PATM_FLAGS_MASK      (X86_EFL_CF|X86_EFL_PF|X86_EFL_AF|X86_EFL_ZF|X86_EFL_SF|X86_EFL_TF|X86_EFL_DF|X86_EFL_OF|X86_EFL_AC|X86_EFL_ID)
    7174
     
    7376%define PATM_VIRTUAL_FLAGS_MASK (X86_EFL_IF|X86_EFL_IOPL)
    7477
    75 ; PATM stack size (identical in PATMA.mac!!)
     78; PATM stack size (identical in PATMA.h!!)
    7679%define PATM_STACK_SIZE                    (4096)
    77 %define PATM_STACK_TOTAL_SIZE              (2*PATM_STACK_SIZE)
     80%define PATM_STACK_TOTAL_SIZE              (2 * PATM_STACK_SIZE)
     81%define PATM_MAX_STACK                     (PATM_STACK_SIZE / RTRCPTR_CB)
    7882
    79 ;/* Patch Manager pending actions (in GCSTATE). */
     83;; @name Patch Manager pending actions (in GCSTATE).
     84;; @{
    8085%define PATM_ACTION_LOOKUP_ADDRESS              1
    8186%define PATM_ACTION_DISPATCH_PENDING_IRQ        2
     
    9297%define PATM_ACTION_LOG_CALL                    13
    9398%define PATM_ACTION_LOG_GATE_ENTRY              14
     99;; @}
    94100
    95 ;/* Magic dword found in ecx for patm pending actions. */
    96 %define PATM_ACTION_MAGIC          0xABCD4321
     101;; Magic dword found in ecx for patm pending actions.
     102%define PATM_ACTION_MAGIC                       0xABCD4321
    97103
     104;; @name PATM_TEMP_RESTORE_FLAGS
     105;; @{
    98106%define PATM_RESTORE_EAX                        RT_BIT(0)
    99107%define PATM_RESTORE_ECX                        RT_BIT(1)
    100108%define PATM_RESTORE_EDI                        RT_BIT(2)
     109;; @}
    101110
     111
     112;;
     113; Relocation entry for PATCHASMRECORD.
     114;
     115struc PATCHASMRELOC
     116    ;; The relocation type.
     117    .uType              resd 1
     118    ;; Additional information specific to the relocation type.
     119    .uCode              resd 1
     120endstruc
     121
     122;;
     123; Assembly patch descriptor record.
     124;
     125struc PATCHASMRECORD
     126    ;; Pointer to the patch code.
     127    .pbFunction         RTCCPTR_RES 1
     128    ;; Offset of the jump table?
     129    .offJump            resd 1
     130    ;; Used only by loop/loopz/loopnz.
     131    .offRelJump         resd 1       
     132    ;; Size override byte position.
     133    .offSizeOverride    resd 1       
     134    ;; The size of the patch function.
     135    .cbFunction         resd 1
     136    ;; The number of relocations in aRelocs.
     137    .cRelocs            resd 1
     138    ;; Variable sized relocation table. (put after the iend, so no included)
     139    ;.aRelocs            resb PATCHASMRELOC_size
     140endstruc
    102141
    103142;/* For indirect calls/jump (identical in PATMA.h & PATMA.mac!) */
  • trunk/src/VBox/VMM/VMMR3/PATMPatch.cpp

    r54674 r54686  
    117117
    118118
    119 static uint32_t patmPatchGenCode(PVM pVM, PPATCHINFO pPatch, uint8_t *pPB, PPATCHASMRECORD pAsmRecord, RCPTRTYPE(uint8_t *) pReturnAddrGC, bool fGenJump,
     119static uint32_t patmPatchGenCode(PVM pVM, PPATCHINFO pPatch, uint8_t *pPB, PCPATCHASMRECORD pAsmRecord,
     120                                 RCPTRTYPE(uint8_t *) pReturnAddrGC, bool fGenJump,
    120121                                 PPATMCALLINFO pCallInfo = 0)
    121122{
    122     uint32_t i, j;
    123 
    124123    Assert(fGenJump == false || pReturnAddrGC);
    125124    Assert(fGenJump == false || pAsmRecord->offJump);
    126     Assert(pAsmRecord && pAsmRecord->size > sizeof(pAsmRecord->uReloc[0]));
     125    Assert(pAsmRecord);
     126    Assert(pAsmRecord->cbFunction > sizeof(pAsmRecord->aRelocs[0].uType) * pAsmRecord->cRelocs);
    127127
    128128    // Copy the code block
    129     memcpy(pPB, pAsmRecord->pFunction, pAsmRecord->size);
     129    memcpy(pPB, pAsmRecord->pbFunction, pAsmRecord->cbFunction);
    130130
    131131    // Process all fixups
    132     for (j=0,i=0;i<pAsmRecord->nrRelocs*2; i+=2)
    133     {
    134         for (;j<pAsmRecord->size;j++)
     132    uint32_t i, j;
     133    for (j = 0, i = 0; i < pAsmRecord->cRelocs; i++)
     134    {
     135        for (; j < pAsmRecord->cbFunction; j++)
    135136        {
    136             if (*(uint32_t*)&pPB[j] == pAsmRecord->uReloc[i])
     137            if (*(uint32_t*)&pPB[j] == pAsmRecord->aRelocs[i].uType)
    137138            {
    138139                RCPTRTYPE(uint32_t *) dest;
    139140
    140141#ifdef VBOX_STRICT
    141                 if (pAsmRecord->uReloc[i] == PATM_FIXUP)
    142                     Assert(pAsmRecord->uReloc[i+1] != 0);
     142                if (pAsmRecord->aRelocs[i].uType == PATM_FIXUP)
     143                    Assert(pAsmRecord->aRelocs[i].uInfo != 0);
    143144                else
    144                     Assert(pAsmRecord->uReloc[i+1] == 0);
     145                    Assert(pAsmRecord->aRelocs[i].uInfo == 0);
    145146#endif
    146147
     
    149150                 * A DIFFERENT HYPERVISOR LAYOUT.
    150151                 */
    151                 switch (pAsmRecord->uReloc[i])
     152                switch (pAsmRecord->aRelocs[i].uType)
    152153                {
    153154                case PATM_VMFLAGS:
     
    160161
    161162                case PATM_FIXUP:
    162                     /* Offset in uReloc[i+1] is from the base of the function. */
    163                     dest = (RTGCUINTPTR32)pVM->patm.s.pPatchMemGC + pAsmRecord->uReloc[i+1] + (RTGCUINTPTR32)(pPB - pVM->patm.s.pPatchMemHC);
     163                    /* Offset in aRelocs[i].uInfo is from the base of the function. */
     164                    dest = (RTGCUINTPTR32)pVM->patm.s.pPatchMemGC + pAsmRecord->aRelocs[i].uInfo
     165                         + (RTGCUINTPTR32)(pPB - pVM->patm.s.pPatchMemHC);
    164166                    break;
    165167#ifdef VBOX_WITH_STATISTICS
     
    200202
    201203                case PATM_RETURNADDR:   /* absolute guest address; no fixup required */
    202                     Assert(pCallInfo && pAsmRecord->uReloc[i] >= PATM_NO_FIXUP);
     204                    Assert(pCallInfo && pAsmRecord->aRelocs[i].uType >= PATM_NO_FIXUP);
    203205                    dest = pCallInfo->pReturnGC;
    204206                    break;
    205207
    206208                case PATM_PATCHNEXTBLOCK:  /* relative address of instruction following this block */
    207                     Assert(pCallInfo && pAsmRecord->uReloc[i] >= PATM_NO_FIXUP);
     209                    Assert(pCallInfo && pAsmRecord->aRelocs[i].uType >= PATM_NO_FIXUP);
    208210
    209211                    /** @note hardcoded assumption that we must return to the instruction following this block */
    210                     dest = (uintptr_t)pPB - (uintptr_t)pVM->patm.s.pPatchMemHC + pAsmRecord->size;
     212                    dest = (uintptr_t)pPB - (uintptr_t)pVM->patm.s.pPatchMemHC + pAsmRecord->cbFunction;
    211213                    break;
    212214
    213215                case PATM_CALLTARGET:   /* relative to patch address; no fixup required */
    214                     Assert(pCallInfo && pAsmRecord->uReloc[i] >= PATM_NO_FIXUP);
     216                    Assert(pCallInfo && pAsmRecord->aRelocs[i].uType >= PATM_NO_FIXUP);
    215217
    216218                    /* Address must be filled in later. (see patmr3SetBranchTargets)  */
     
    224226
    225227                case PATM_CPUID_STD_PTR:
    226                     /* @todo dirty hack when correcting this fixup (state restore) */
     228                    /** @todo dirty hack when correcting this fixup (state restore) */
    227229                    dest = CPUMR3GetGuestCpuIdPatmStdRCPtr(pVM);
    228230                    break;
    229231
    230232                case PATM_CPUID_EXT_PTR:
    231                     /* @todo dirty hack when correcting this fixup (state restore) */
     233                    /** @todo dirty hack when correcting this fixup (state restore) */
    232234                    dest = CPUMR3GetGuestCpuIdPatmExtRCPtr(pVM);
    233235                    break;
    234236
    235237                case PATM_CPUID_CENTAUR_PTR:
    236                     /* @todo dirty hack when correcting this fixup (state restore) */
     238                    /** @todo dirty hack when correcting this fixup (state restore) */
    237239                    dest = CPUMR3GetGuestCpuIdPatmCentaurRCPtr(pVM);
    238240                    break;
    239241
    240242                case PATM_CPUID_DEF_PTR:
    241                     /* @todo dirty hack when correcting this fixup (state restore) */
     243                    /** @todo dirty hack when correcting this fixup (state restore) */
    242244                    dest = CPUMR3GetGuestCpuIdPatmDefRCPtr(pVM);
    243245                    break;
     
    353355
    354356                *(RTRCPTR *)&pPB[j] = dest;
    355                 if (pAsmRecord->uReloc[i] < PATM_NO_FIXUP)
     357                if (pAsmRecord->aRelocs[i].uType < PATM_NO_FIXUP)
    356358                {
    357359                    patmPatchAddReloc32(pVM, pPatch, &pPB[j], FIXUP_ABSOLUTE);
     
    360362            }
    361363        }
    362         Assert(j < pAsmRecord->size);
    363     }
    364     Assert(pAsmRecord->uReloc[i] == 0xffffffff);
     364        Assert(j < pAsmRecord->cbFunction);
     365    }
     366    Assert(pAsmRecord->aRelocs[i].uInfo == 0xffffffff);
    365367
    366368    /* Add the jump back to guest code (if required) */
     
    381383    // Calculate the right size of this patch block
    382384    if ((fGenJump && pAsmRecord->offJump) || (!fGenJump && !pAsmRecord->offJump))
    383     {
    384         return pAsmRecord->size;
    385     }
    386     else {
    387         // if a jump instruction is present and we don't want one, then subtract SIZEOF_NEARJUMP32
    388         return pAsmRecord->size - SIZEOF_NEARJUMP32;
    389     }
     385        return pAsmRecord->cbFunction;
     386    // if a jump instruction is present and we don't want one, then subtract SIZEOF_NEARJUMP32
     387    return pAsmRecord->cbFunction - SIZEOF_NEARJUMP32;
    390388}
    391389
     
    531529{
    532530    uint32_t size = 0;
    533     PPATCHASMRECORD pPatchAsmRec;
     531    PCPATCHASMRECORD pPatchAsmRec;
    534532
    535533    PATCHGEN_PROLOG(pVM, pPatch);
  • trunk/src/VBox/VMM/VMMR3/PATMR3Dbg.cpp

    r46177 r54686  
    241241     * Global functions and a start marker.
    242242     */
    243     ADD_FUNC(hDbgMod, pVM->patm.s.pPatchMemGC, pVM->patm.s.pfnHelperCallGC, PATMLookupAndCallRecord.size, "PATMLookupAndCall");
    244     ADD_FUNC(hDbgMod, pVM->patm.s.pPatchMemGC, pVM->patm.s.pfnHelperRetGC,  PATMRetFunctionRecord.size,   "PATMRetFunction");
    245     ADD_FUNC(hDbgMod, pVM->patm.s.pPatchMemGC, pVM->patm.s.pfnHelperJumpGC, PATMLookupAndJumpRecord.size, "PATMLookupAndJump");
    246     ADD_FUNC(hDbgMod, pVM->patm.s.pPatchMemGC, pVM->patm.s.pfnHelperIretGC, PATMIretFunctionRecord.size,  "PATMIretFunction");
     243    ADD_FUNC(hDbgMod, pVM->patm.s.pPatchMemGC, pVM->patm.s.pfnHelperCallGC, PATMLookupAndCallRecord.cbFunction, "PATMLookupAndCall");
     244    ADD_FUNC(hDbgMod, pVM->patm.s.pPatchMemGC, pVM->patm.s.pfnHelperRetGC,  PATMRetFunctionRecord.cbFunction,   "PATMRetFunction");
     245    ADD_FUNC(hDbgMod, pVM->patm.s.pPatchMemGC, pVM->patm.s.pfnHelperJumpGC, PATMLookupAndJumpRecord.cbFunction, "PATMLookupAndJump");
     246    ADD_FUNC(hDbgMod, pVM->patm.s.pPatchMemGC, pVM->patm.s.pfnHelperIretGC, PATMIretFunctionRecord.cbFunction,  "PATMIretFunction");
    247247
    248248    ADD_FUNC(hDbgMod, pVM->patm.s.pPatchMemGC, pVM->patm.s.pPatchMemGC, 0,  "PatchMemStart");
  • trunk/src/VBox/VMM/include/PATMA.h

    r45276 r54686  
    11/* $Id$ */
    22/** @file
    3  * PATM macros & definitions (identical to PATMA.mac!!)
     3 * PATM macros & definitions (identical to PATMA.mac!).
    44 */
    55
    66/*
    7  * Copyright (C) 2006-2012 Oracle Corporation
     7 * Copyright (C) 2006-2015 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1919#define ___PATMA_H
    2020
    21 
     21/** @name Patch Fixup Types
     22 * @{ */
    2223#define PATM_VMFLAGS                            0xF1ABCD00
    2324#ifdef VBOX_WITH_STATISTICS
    24 #define PATM_ALLPATCHCALLS                      0xF1ABCD01
    25 #define PATM_PERPATCHCALLS                      0xF1ABCD02
     25# define PATM_ALLPATCHCALLS                     0xF1ABCD01
     26# define PATM_PERPATCHCALLS                     0xF1ABCD02
    2627#endif
    2728#define PATM_JUMPDELTA                          0xF1ABCD03
    2829#ifdef VBOX_WITH_STATISTICS
    29 #define PATM_IRETEFLAGS                         0xF1ABCD04
    30 #define PATM_IRETCS                             0xF1ABCD05
    31 #define PATM_IRETEIP                            0xF1ABCD06
     30# define PATM_IRETEFLAGS                        0xF1ABCD04
     31# define PATM_IRETCS                            0xF1ABCD05
     32# define PATM_IRETEIP                           0xF1ABCD06
    3233#endif
    3334#define PATM_FIXUP                              0xF1ABCD07
     
    3637#define PATM_CPUID_EXT_PTR                      0xF1ABCD0a
    3738#define PATM_CPUID_DEF_PTR                      0xF1ABCD0b
    38 #define PATM_STACKBASE                          0xF1ABCD0c    /** Stack to store our private patch return addresses */
    39 #define PATM_STACKBASE_GUEST                    0xF1ABCD0d    /** Stack to store guest return addresses */
     39#define PATM_STACKBASE                          0xF1ABCD0c  /**< Stack to store our private patch return addresses */
     40#define PATM_STACKBASE_GUEST                    0xF1ABCD0d  /**< Stack to store guest return addresses */
    4041#define PATM_STACKPTR                           0xF1ABCD0e
    4142#define PATM_PATCHBASE                          0xF1ABCD0f
     
    4344#define PATM_INHIBITIRQADDR                     0xF1ABCD11
    4445#define PATM_VM_FORCEDACTIONS                   0xF1ABCD12
    45 #define PATM_TEMP_EAX                           0xF1ABCD13      /** Location for original EAX register */
    46 #define PATM_TEMP_ECX                           0xF1ABCD14      /** Location for original ECX register */
    47 #define PATM_TEMP_EDI                           0xF1ABCD15      /** Location for original EDI register */
    48 #define PATM_TEMP_EFLAGS                        0xF1ABCD16      /** Location for original eflags */
    49 #define PATM_TEMP_RESTORE_FLAGS                 0xF1ABCD17      /** Which registers to restore */
     46#define PATM_TEMP_EAX                           0xF1ABCD13  /**< Location for original EAX register */
     47#define PATM_TEMP_ECX                           0xF1ABCD14  /**< Location for original ECX register */
     48#define PATM_TEMP_EDI                           0xF1ABCD15  /**< Location for original EDI register */
     49#define PATM_TEMP_EFLAGS                        0xF1ABCD16  /**< Location for original eflags */
     50#define PATM_TEMP_RESTORE_FLAGS                 0xF1ABCD17  /**< Which registers to restore */
    5051#define PATM_CALL_PATCH_TARGET_ADDR             0xF1ABCD18
    5152#define PATM_CALL_RETURN_ADDR                   0xF1ABCD19
     
    5859#define PATM_RETURNADDR                         0xF1ABCE02
    5960#define PATM_PATCHNEXTBLOCK                     0xF1ABCE03
    60 #define PATM_CALLTARGET                         0xF1ABCE04    /** relative call target */
    61 #define PATM_NEXTINSTRADDR                      0xF1ABCE05    /** absolute guest address of the next instruction */
    62 #define PATM_CURINSTRADDR                       0xF1ABCE06    /** absolute guest address of the current instruction */
    63 #define PATM_LOOKUP_AND_CALL_FUNCTION           0xF1ABCE07    /** Relative address of global PATM lookup and call function. */
    64 #define PATM_RETURN_FUNCTION                    0xF1ABCE08    /** Relative address of global PATM return function. */
    65 #define PATM_LOOKUP_AND_JUMP_FUNCTION           0xF1ABCE09    /** Relative address of global PATM lookup and jump function. */
    66 #define PATM_IRET_FUNCTION                      0xF1ABCE0A    /** Relative address of global PATM iret function. */
     61#define PATM_CALLTARGET                         0xF1ABCE04  /**< relative call target */
     62#define PATM_NEXTINSTRADDR                      0xF1ABCE05  /**< absolute guest address of the next instruction */
     63#define PATM_CURINSTRADDR                       0xF1ABCE06  /**< absolute guest address of the current instruction */
     64#define PATM_LOOKUP_AND_CALL_FUNCTION           0xF1ABCE07  /**< Relative address of global PATM lookup and call function. */
     65#define PATM_RETURN_FUNCTION                    0xF1ABCE08  /**< Relative address of global PATM return function. */
     66#define PATM_LOOKUP_AND_JUMP_FUNCTION           0xF1ABCE09  /**< Relative address of global PATM lookup and jump function. */
     67#define PATM_IRET_FUNCTION                      0xF1ABCE0A  /**< Relative address of global PATM iret function. */
    6768#define PATM_CPUID_CENTAUR_MAX                  0xF1ABCE0B
    68 
    69 // everything except IOPL, NT, IF, VM, VIF, VIP and RF
    70 #define PATM_FLAGS_MASK                         (X86_EFL_CF|X86_EFL_PF|X86_EFL_AF|X86_EFL_ZF|X86_EFL_SF|X86_EFL_TF|X86_EFL_DF|X86_EFL_OF|X86_EFL_AC|X86_EFL_ID)
    71 
    72 // currently only IF & IOPL
    73 #define PATM_VIRTUAL_FLAGS_MASK                 (X86_EFL_IF|X86_EFL_IOPL)
     69/** @} */
     70
     71
     72/** Everything except IOPL, NT, IF, VM, VIF, VIP and RF */
     73#define PATM_FLAGS_MASK                         (  X86_EFL_CF | X86_EFL_PF | X86_EFL_AF | X86_EFL_ZF | X86_EFL_SF \
     74                                                 | X86_EFL_TF | X86_EFL_DF | X86_EFL_OF | X86_EFL_AC | X86_EFL_ID)
     75
     76/** Flags that PATM virtualizes. Currently only IF & IOPL. */
     77#define PATM_VIRTUAL_FLAGS_MASK                 (X86_EFL_IF | X86_EFL_IOPL)
    7478
    7579/* PATM stack size (identical in PATMA.mac!!) */
    76 #define PATM_STACK_SIZE                         (PAGE_SIZE)
    77 #define PATM_STACK_TOTAL_SIZE                   (2*PATM_STACK_SIZE)
     80#define PATM_STACK_SIZE                         (4096)
     81#define PATM_STACK_TOTAL_SIZE                   (2 * PATM_STACK_SIZE)
    7882#define PATM_MAX_STACK                          (PATM_STACK_SIZE/sizeof(RTRCPTR))
    7983
    80 /* Patch Manager pending actions (in GCSTATE). */
     84/** @name Patch Manager pending actions (in GCSTATE).
     85 * @{  */
    8186#define PATM_ACTION_LOOKUP_ADDRESS              1
    8287#define PATM_ACTION_DISPATCH_PENDING_IRQ        2
     
    9398#define PATM_ACTION_LOG_CALL                    13
    9499#define PATM_ACTION_LOG_GATE_ENTRY              14
    95 
    96 /* Magic dword found in ecx for patm pending actions. */
     100/** @} */
     101
     102/** Magic dword found in ecx for patm pending actions. */
    97103#define PATM_ACTION_MAGIC                       0xABCD4321
    98104
    99 /** PATM_TEMP_RESTORE_FLAGS */
     105/** @name PATM_TEMP_RESTORE_FLAGS
     106 * @{ */
    100107#define PATM_RESTORE_EAX                        RT_BIT(0)
    101108#define PATM_RESTORE_ECX                        RT_BIT(1)
    102109#define PATM_RESTORE_EDI                        RT_BIT(2)
    103 
     110/** @} */
     111
     112/** Relocation entry for PATCHASMRECORD. */
     113typedef struct PATCHASMRELOC
     114{
     115    /** The relocation type. */
     116    uint32_t uType;
     117    /** Additional information specific to the relocation type. */
     118    uint32_t uInfo;
     119} PATCHASMRELOC;
     120typedef PATCHASMRELOC const *PCPATCHASMRELOC;
     121
     122/**
     123 * Assembly patch descriptor record.
     124 */
    104125typedef struct
    105126{
    106     uint8_t *pFunction;
    107     uint32_t offJump;
    108     uint32_t offRelJump;        //used only by loop/loopz/loopnz
    109     uint32_t offSizeOverride;   //size override byte position
    110     uint32_t size;
    111     uint32_t nrRelocs;
    112     uint32_t uReloc[1];
    113 } PATCHASMRECORD, *PPATCHASMRECORD;
     127    /** Pointer to the patch code. */
     128    uint8_t        *pbFunction;
     129    /** Offset of the jump table? */
     130    uint32_t        offJump;
     131    /** Used only by loop/loopz/loopnz. */
     132    uint32_t        offRelJump;
     133    /** Size override byte position. */
     134    uint32_t        offSizeOverride;
     135    /** The size of the patch function. */
     136    uint32_t        cbFunction;
     137    /** The number of relocations in aRelocs. */
     138    uint32_t        cRelocs;
     139    /** Variable sized relocation table. */
     140    PATCHASMRELOC   aRelocs[1];
     141} PATCHASMRECORD;
     142/** Pointer to a const patch descriptor record. */
     143typedef PATCHASMRECORD const *PCPATCHASMRECORD;
     144
    114145
    115146/* For indirect calls/jump (identical in PATMA.h & PATMA.mac!) */
     
    137168RT_C_DECLS_BEGIN
    138169
     170/** @name Patch Descriptor Records (in PATMA.asm)
     171 * @{ */
    139172extern PATCHASMRECORD PATMCliRecord;
    140173extern PATCHASMRECORD PATMStiRecord;
     
    181214
    182215extern PATCHASMRECORD PATMMovFromSSRecord;
     216/** @} */
    183217
    184218extern const uint32_t PATMInterruptFlag;
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