VirtualBox

Changeset 54688 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Mar 8, 2015 11:08:04 PM (10 years ago)
Author:
vboxsync
Message:

PATM: Doing some more cleanups while trying to understand stuff again.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMR3/PATMA.asm

    r54687 r54688  
    44;
    55
    6 ; Copyright (C) 2006-2012 Oracle Corporation
     6; Copyright (C) 2006-2015 Oracle Corporation
    77;
    88; This file is part of VirtualBox Open Source Edition (OSE), as
     
    3535%include "PATMA.mac"
    3636
     37;*******************************************************************************
     38;*  Defined Constants And Macros                                               *
     39;*******************************************************************************
    3740%ifdef DEBUG
    3841; Noisy, but useful for debugging certain problems
     
    4144%endif
    4245
    43 BEGINCONST
    44 
     46;;
     47; Simple PATCHASMRECORD initializer
     48; @param %1     The patch function name.
     49; @param %2     The number of fixups.
     50;
     51%macro PATCHASMRECORD_INIT 2
     52istruc PATCHASMRECORD
     53    at PATCHASMRECORD.pbFunction,     RTCCPTR_DEF NAME(%1)
     54    at PATCHASMRECORD.offJump,        DD          0
     55    at PATCHASMRECORD.offRelJump,     DD          0
     56    at PATCHASMRECORD.offSizeOverride,DD          0
     57    at PATCHASMRECORD.cbFunction,     DD          NAME(%1 %+ _EndProc) - NAME(%1)
     58    at PATCHASMRECORD.cRelocs,        DD          %2
     59iend                                                         
     60%endmacro
     61
     62;;
     63; Simple PATCHASMRECORD initializer
     64; @param %1     The patch function name.
     65; @param %2     Jump lable.
     66; @param %3     The number of fixups.
     67;
     68%macro PATCHASMRECORD_INIT_JUMP 3
     69istruc PATCHASMRECORD
     70    at PATCHASMRECORD.pbFunction,     RTCCPTR_DEF NAME(%1)
     71    at PATCHASMRECORD.offJump,        DD          %2 - NAME(%1)
     72    at PATCHASMRECORD.offRelJump,     DD          0
     73    at PATCHASMRECORD.offSizeOverride,DD          0
     74    at PATCHASMRECORD.cbFunction,     DD          NAME(%1 %+ _EndProc) - NAME(%1)
     75    at PATCHASMRECORD.cRelocs,        DD          %3
     76iend                                                         
     77%endmacro
     78
     79;;
     80; Switches to the code section and aligns the function.
     81%macro BEGIN_PATCH_CODE_SECTION 0
     82BEGINCODE
     83align 32
     84%endmacro
     85
     86;;
     87; Switches to the data section for the read-only patch descriptor data and
     88; aligns it appropriately.
     89%macro BEGIN_PATCH_RODATA_SECTION 0   
     90BEGINDATA
     91align 16
     92%endmacro
     93
     94
     95;
     96; Switch to 32-bit mode (x86).
     97;
    4598%ifdef RT_ARCH_AMD64
    46  BITS 32 ; switch to 32-bit mode (x86).
    47 %endif
     99 BITS 32
     100%endif
     101
    48102
    49103%ifdef VBOX_WITH_STATISTICS
     
    51105; Patch call statistics
    52106;
     107BEGIN_PATCH_CODE_SECTION
    53108BEGINPROC   PATMStats
    54 PATMStats_Start:
    55109    mov     dword [ss:PATM_INTERRUPTFLAG], 0
    56110    pushf
     
    59113    popf
    60114    mov     dword [ss:PATM_INTERRUPTFLAG], 1
    61 PATMStats_End:
    62115ENDPROC     PATMStats
    63 
    64116
    65117; Patch record for statistics
    66118GLOBALNAME g_patmStatsRecord
    67     RTCCPTR_DEF PATMStats_Start
    68     DD      0
    69     DD      0
    70     DD      0
    71     DD      PATMStats_End - PATMStats_Start
    72     DD      4
    73     DD      PATM_INTERRUPTFLAG
    74     DD      0
    75     DD      PATM_ALLPATCHCALLS
    76     DD      0
    77     DD      PATM_PERPATCHCALLS
    78     DD      0
    79     DD      PATM_INTERRUPTFLAG
    80     DD      0
    81     DD      0ffffffffh
    82 %endif
     119    PATCHASMRECORD_INIT PATMStats, 4
     120    DD      PATM_INTERRUPTFLAG, 0
     121    DD      PATM_ALLPATCHCALLS, 0
     122    DD      PATM_PERPATCHCALLS, 0
     123    DD      PATM_INTERRUPTFLAG, 0
     124    DD      0ffffffffh, 0ffffffffh
     125%endif ; VBOX_WITH_STATISTICS
     126
    83127
    84128;
    85129; Set PATM_INTERRUPTFLAG
    86130;
     131BEGIN_PATCH_CODE_SECTION
    87132BEGINPROC   PATMSetPIF
    88 PATMSetPIF_Start:
    89     mov     dword [ss:PATM_INTERRUPTFLAG], 1
    90 PATMSetPIF_End:
     133    mov     dword [ss:PATM_INTERRUPTFLAG], 1
    91134ENDPROC     PATMSetPIF
    92135
    93 
    94 SECTION .data
    95136; Patch record for setting PATM_INTERRUPTFLAG
     137BEGIN_PATCH_RODATA_SECTION
    96138GLOBALNAME g_patmSetPIFRecord
    97     RTCCPTR_DEF PATMSetPIF_Start
    98     DD      0
    99     DD      0
    100     DD      0
    101     DD      PATMSetPIF_End - PATMSetPIF_Start
    102     DD      1
    103     DD      PATM_INTERRUPTFLAG
    104     DD      0
    105     DD      0ffffffffh
    106 SECTION .text
     139    PATCHASMRECORD_INIT PATMSetPIF, 1
     140    DD      PATM_INTERRUPTFLAG, 0
     141    DD      0ffffffffh, 0ffffffffh
    107142
    108143;
    109144; Clear PATM_INTERRUPTFLAG
    110145;
     146BEGIN_PATCH_CODE_SECTION
    111147BEGINPROC   PATMClearPIF
    112 PATMClearPIF_Start:
    113148    ; probe stack here as we can't recover from page faults later on
    114149    not     dword [esp-64]
    115150    not     dword [esp-64]
    116151    mov     dword [ss:PATM_INTERRUPTFLAG], 0
    117 PATMClearPIF_End:
    118152ENDPROC     PATMClearPIF
    119153
    120 
    121 SECTION .data
    122154; Patch record for clearing PATM_INTERRUPTFLAG
     155BEGIN_PATCH_RODATA_SECTION
    123156GLOBALNAME g_patmClearPIFRecord
    124     RTCCPTR_DEF PATMClearPIF_Start
    125     DD      0
    126     DD      0
    127     DD      0
    128     DD      PATMClearPIF_End - PATMClearPIF_Start
    129     DD      1
    130     DD      PATM_INTERRUPTFLAG
    131     DD      0
    132     DD      0ffffffffh
    133 SECTION .text
     157    PATCHASMRECORD_INIT PATMClearPIF, 1
     158    DD      PATM_INTERRUPTFLAG, 0
     159    DD      0ffffffffh, 0ffffffffh
    134160
    135161;
    136162; Clear PATM_INHIBITIRQADDR and fault if IF=0
    137163;
     164BEGIN_PATCH_CODE_SECTION
    138165BEGINPROC   PATMClearInhibitIRQFaultIF0
    139 PATMClearInhibitIRQFaultIF0_Start:
    140166    mov     dword [ss:PATM_INTERRUPTFLAG], 0
    141167    mov     dword [ss:PATM_INHIBITIRQADDR], 0
     
    170196    popf
    171197    mov     dword [ss:PATM_INTERRUPTFLAG], 1
    172 PATMClearInhibitIRQFaultIF0_End:
    173198ENDPROC     PATMClearInhibitIRQFaultIF0
    174199
    175 
    176 SECTION .data
    177200; Patch record for clearing PATM_INHIBITIRQADDR
     201BEGIN_PATCH_RODATA_SECTION
    178202GLOBALNAME g_patmClearInhibitIRQFaultIF0Record
    179     RTCCPTR_DEF PATMClearInhibitIRQFaultIF0_Start
    180     DD      0
    181     DD      0
    182     DD      0
    183     DD      PATMClearInhibitIRQFaultIF0_End - PATMClearInhibitIRQFaultIF0_Start
    184     DD      12
    185     DD      PATM_INTERRUPTFLAG
    186     DD      0
    187     DD      PATM_INHIBITIRQADDR
    188     DD      0
    189     DD      PATM_VMFLAGS
    190     DD      0
    191     DD      PATM_VM_FORCEDACTIONS
    192     DD      0
    193     DD      PATM_TEMP_EAX
    194     DD      0
    195     DD      PATM_TEMP_ECX
    196     DD      0
    197     DD      PATM_TEMP_EDI
    198     DD      0
    199     DD      PATM_TEMP_RESTORE_FLAGS
    200     DD      0
    201     DD      PATM_PENDINGACTION
    202     DD      0
    203     DD      PATM_NEXTINSTRADDR
    204     DD      0
    205     DD      PATM_INTERRUPTFLAG
    206     DD      0
    207     DD      PATM_INTERRUPTFLAG
    208     DD      0
    209     DD      0ffffffffh
    210 SECTION .text
     203    PATCHASMRECORD_INIT PATMClearInhibitIRQFaultIF0, 12
     204    DD      PATM_INTERRUPTFLAG,      0
     205    DD      PATM_INHIBITIRQADDR,     0
     206    DD      PATM_VMFLAGS,            0
     207    DD      PATM_VM_FORCEDACTIONS,   0
     208    DD      PATM_TEMP_EAX,           0
     209    DD      PATM_TEMP_ECX,           0
     210    DD      PATM_TEMP_EDI,           0
     211    DD      PATM_TEMP_RESTORE_FLAGS, 0
     212    DD      PATM_PENDINGACTION,      0
     213    DD      PATM_NEXTINSTRADDR,      0
     214    DD      PATM_INTERRUPTFLAG,      0
     215    DD      PATM_INTERRUPTFLAG,      0
     216    DD      0ffffffffh, 0ffffffffh
     217
    211218
    212219;
    213220; Clear PATM_INHIBITIRQADDR and continue if IF=0 (duplicated function only; never jump back to guest code afterwards!!)
    214221;
     222BEGIN_PATCH_CODE_SECTION
    215223BEGINPROC   PATMClearInhibitIRQContIF0
    216 PATMClearInhibitIRQContIF0_Start:
    217224    mov     dword [ss:PATM_INTERRUPTFLAG], 0
    218225    mov     dword [ss:PATM_INHIBITIRQADDR], 0
     
    242249    popf
    243250    mov     dword [ss:PATM_INTERRUPTFLAG], 1
    244 PATMClearInhibitIRQContIF0_End:
    245251ENDPROC     PATMClearInhibitIRQContIF0
    246252
    247 
    248 SECTION .data
    249253; Patch record for clearing PATM_INHIBITIRQADDR
     254BEGIN_PATCH_RODATA_SECTION
    250255GLOBALNAME g_patmClearInhibitIRQContIF0Record
    251     RTCCPTR_DEF PATMClearInhibitIRQContIF0_Start
    252     DD      0
    253     DD      0
    254     DD      0
    255     DD      PATMClearInhibitIRQContIF0_End - PATMClearInhibitIRQContIF0_Start
    256     DD      11
    257     DD      PATM_INTERRUPTFLAG
    258     DD      0
    259     DD      PATM_INHIBITIRQADDR
    260     DD      0
    261     DD      PATM_VMFLAGS
    262     DD      0
    263     DD      PATM_VM_FORCEDACTIONS
    264     DD      0
    265     DD      PATM_TEMP_EAX
    266     DD      0
    267     DD      PATM_TEMP_ECX
    268     DD      0
    269     DD      PATM_TEMP_EDI
    270     DD      0
    271     DD      PATM_TEMP_RESTORE_FLAGS
    272     DD      0
    273     DD      PATM_PENDINGACTION
    274     DD      0
    275     DD      PATM_NEXTINSTRADDR
    276     DD      0
    277     DD      PATM_INTERRUPTFLAG
    278     DD      0
    279     DD      0ffffffffh
    280 SECTION .text
    281 
    282 
     256    PATCHASMRECORD_INIT PATMClearInhibitIRQContIF0, 11
     257    DD      PATM_INTERRUPTFLAG,      0   
     258    DD      PATM_INHIBITIRQADDR,     0
     259    DD      PATM_VMFLAGS,            0
     260    DD      PATM_VM_FORCEDACTIONS,   0
     261    DD      PATM_TEMP_EAX,           0
     262    DD      PATM_TEMP_ECX,           0
     263    DD      PATM_TEMP_EDI,           0
     264    DD      PATM_TEMP_RESTORE_FLAGS, 0
     265    DD      PATM_PENDINGACTION,      0
     266    DD      PATM_NEXTINSTRADDR,      0
     267    DD      PATM_INTERRUPTFLAG,      0
     268    DD      0ffffffffh, 0ffffffffh
     269
     270
     271;
     272;
     273;
     274BEGIN_PATCH_CODE_SECTION
    283275BEGINPROC   PATMCliReplacement
    284 PATMCliStart:
    285276    mov     dword [ss:PATM_INTERRUPTFLAG], 0
    286277    pushf
     
    303294PATMCliJump:
    304295    DD      PATM_JUMPDELTA
    305 PATMCliEnd:
    306296ENDPROC     PATMCliReplacement
    307297
    308 
    309 SECTION .data
    310298; Patch record for 'cli'
     299BEGIN_PATCH_RODATA_SECTION
    311300GLOBALNAME g_patmCliRecord
    312     RTCCPTR_DEF PATMCliStart
    313     DD      PATMCliJump - PATMCliStart
    314     DD      0
    315     DD      0
    316     DD      PATMCliEnd - PATMCliStart
    317301%ifdef PATM_LOG_PATCHINSTR
    318     DD      4
     302    PATCHASMRECORD_INIT_JUMP PATMCliReplacement, PATMCliJump, 4
    319303%else
    320     DD      3
    321 %endif
    322     DD      PATM_INTERRUPTFLAG
    323     DD      0
     304    PATCHASMRECORD_INIT_JUMP PATMCliReplacement, PATMCliJump, 3
     305%endif
     306    DD      PATM_INTERRUPTFLAG, 0
    324307%ifdef PATM_LOG_PATCHINSTR
    325     DD      PATM_PENDINGACTION
    326     DD      0
    327 %endif
    328     DD      PATM_VMFLAGS
    329     DD      0
    330     DD      PATM_INTERRUPTFLAG
    331     DD      0
    332     DD      0ffffffffh
    333 SECTION .text
    334 
    335 
     308    DD      PATM_PENDINGACTION, 0
     309%endif
     310    DD      PATM_VMFLAGS,       0
     311    DD      PATM_INTERRUPTFLAG, 0
     312    DD      0ffffffffh, 0ffffffffh
     313
     314
     315;
     316;
     317;
     318BEGIN_PATCH_CODE_SECTION
    336319BEGINPROC   PATMStiReplacement
    337320PATMStiStart:
     
    355338ENDPROC     PATMStiReplacement
    356339
    357 SECTION .data
    358340; Patch record for 'sti'
     341BEGIN_PATCH_RODATA_SECTION
    359342GLOBALNAME g_patmStiRecord
    360343    RTCCPTR_DEF PATMStiStart
     
    383366    DD      0
    384367    DD      0ffffffffh
    385 SECTION .text
     368
    386369
    387370;
     
    398381; esp      - EIP
    399382;
     383BEGIN_PATCH_CODE_SECTION
    400384BEGINPROC   PATMTrapEntry
    401385PATMTrapEntryStart:
     
    444428ENDPROC     PATMTrapEntry
    445429
    446 
    447 SECTION .data
    448430; Patch record for trap gate entrypoint
     431BEGIN_PATCH_RODATA_SECTION
    449432GLOBALNAME g_patmTrapEntryRecord
    450433    RTCCPTR_DEF PATMTrapEntryStart
     
    469452    DD      0
    470453    DD      0ffffffffh
    471 SECTION .text
     454
    472455
    473456;
     
    485468; esp      - error code
    486469;
     470BEGIN_PATCH_CODE_SECTION
    487471BEGINPROC   PATMTrapEntryErrorCode
    488472PATMTrapErrorCodeEntryStart:
     
    531515ENDPROC     PATMTrapEntryErrorCode
    532516
    533 
    534 SECTION .data
    535517; Patch record for trap gate entrypoint
     518BEGIN_PATCH_RODATA_SECTION
    536519GLOBALNAME g_patmTrapEntryRecordErrorCode
    537520    RTCCPTR_DEF PATMTrapErrorCodeEntryStart
     
    556539    DD      0
    557540    DD      0ffffffffh
    558 SECTION .text
    559541
    560542
     
    572554; esp      - EIP
    573555;
     556BEGIN_PATCH_CODE_SECTION
    574557BEGINPROC   PATMIntEntry
    575558PATMIntEntryStart:
     
    615598ENDPROC     PATMIntEntry
    616599
    617 
    618 SECTION .data
    619600; Patch record for interrupt gate entrypoint
     601BEGIN_PATCH_RODATA_SECTION
    620602GLOBALNAME g_patmIntEntryRecord
    621603    RTCCPTR_DEF PATMIntEntryStart
     
    640622    DD      0
    641623    DD      0ffffffffh
    642 SECTION .text
     624
    643625
    644626;
     
    656638; esp      - error code
    657639;
     640BEGIN_PATCH_CODE_SECTION
    658641BEGINPROC   PATMIntEntryErrorCode
    659642PATMIntEntryErrorCodeStart:
     
    699682ENDPROC     PATMIntEntryErrorCode
    700683
    701 
    702 SECTION .data
    703684; Patch record for interrupt gate entrypoint
     685BEGIN_PATCH_RODATA_SECTION
    704686GLOBALNAME g_patmIntEntryRecordErrorCode
    705687    RTCCPTR_DEF PATMIntEntryErrorCodeStart
     
    724706    DD      0
    725707    DD      0ffffffffh
    726 SECTION .text
     708
    727709
    728710;
    729711; 32 bits Popf replacement that faults when IF remains 0
    730712;
     713BEGIN_PATCH_CODE_SECTION
    731714BEGINPROC   PATMPopf32Replacement
    732715PATMPopf32Start:
     
    786769ENDPROC     PATMPopf32Replacement
    787770
    788 
    789 SECTION .data
    790771; Patch record for 'popfd'
     772BEGIN_PATCH_RODATA_SECTION
    791773GLOBALNAME g_patmPopf32Record
    792774    RTCCPTR_DEF PATMPopf32Start
     
    827809    DD      0
    828810    DD      0ffffffffh
    829 SECTION .text
    830 
     811
     812
     813;
    831814; no need to check the IF flag when popf isn't an exit point of a patch (e.g. function duplication)
     815;
     816BEGIN_PATCH_CODE_SECTION
    832817BEGINPROC   PATMPopf32Replacement_NoExit
    833818PATMPopf32_NoExitStart:
     
    880865ENDPROC     PATMPopf32Replacement_NoExit
    881866
    882 
    883 SECTION .data
    884867; Patch record for 'popfd'
     868BEGIN_PATCH_RODATA_SECTION
    885869GLOBALNAME g_patmPopf32Record_NoExit
    886870    RTCCPTR_DEF PATMPopf32_NoExitStart
     
    925909    DD      0
    926910    DD      0ffffffffh
    927 SECTION .text
    928911
    929912
     
    931914; 16 bits Popf replacement that faults when IF remains 0
    932915;
     916BEGIN_PATCH_CODE_SECTION
    933917BEGINPROC   PATMPopf16Replacement
    934918PATMPopf16Start:
     
    964948ENDPROC     PATMPopf16Replacement
    965949
    966 
    967 SECTION .data
    968950; Patch record for 'popf'
     951BEGIN_PATCH_RODATA_SECTION
    969952GLOBALNAME g_patmPopf16Record
    970953    RTCCPTR_DEF PATMPopf16Start
     
    993976    DD      0
    994977    DD      0ffffffffh
    995 SECTION .text
     978
    996979
    997980;
    998981; 16 bits Popf replacement that faults when IF remains 0
    999982; @todo not necessary to fault in that case (see 32 bits version)
     983;
     984BEGIN_PATCH_CODE_SECTION
    1000985BEGINPROC   PATMPopf16Replacement_NoExit
    1001986PATMPopf16Start_NoExit:
     
    10271012ENDPROC     PATMPopf16Replacement_NoExit
    10281013
    1029 
    1030 SECTION .data
    10311014; Patch record for 'popf'
     1015BEGIN_PATCH_RODATA_SECTION
    10321016GLOBALNAME g_patmPopf16Record_NoExit
    10331017    RTCCPTR_DEF PATMPopf16Start_NoExit
     
    10561040    DD      0
    10571041    DD      0ffffffffh
    1058 SECTION .text
    1059 
    1060 
     1042
     1043
     1044;
     1045;
     1046;
     1047BEGIN_PATCH_CODE_SECTION
    10611048BEGINPROC   PATMPushf32Replacement
    10621049PATMPushf32Start:
     
    10861073ENDPROC     PATMPushf32Replacement
    10871074
    1088 
    1089 SECTION .data
    10901075; Patch record for 'pushfd'
     1076BEGIN_PATCH_RODATA_SECTION
    10911077GLOBALNAME g_patmPushf32Record
    10921078    RTCCPTR_DEF PATMPushf32Start
     
    11111097    DD      0
    11121098    DD      0ffffffffh
    1113 SECTION .text
    1114 
    1115 
     1099
     1100
     1101;
     1102;
     1103;
     1104BEGIN_PATCH_CODE_SECTION
    11161105BEGINPROC   PATMPushf16Replacement
    11171106PATMPushf16Start:
     
    11351124ENDPROC     PATMPushf16Replacement
    11361125
    1137 
    1138 SECTION .data
    11391126; Patch record for 'pushf'
     1127BEGIN_PATCH_RODATA_SECTION
    11401128GLOBALNAME g_patmPushf16Record
    11411129    RTCCPTR_DEF PATMPushf16Start
     
    11521140    DD      0
    11531141    DD      0ffffffffh
    1154 SECTION .text
    1155 
    1156 
     1142
     1143
     1144;
     1145;
     1146;
     1147BEGIN_PATCH_CODE_SECTION
    11571148BEGINPROC   PATMPushCSReplacement
    11581149PATMPushCSStart:
     
    11771168ENDPROC     PATMPushCSReplacement
    11781169
    1179 
    1180 SECTION .data
    11811170; Patch record for 'push cs'
     1171BEGIN_PATCH_RODATA_SECTION
    11821172GLOBALNAME g_patmPushCSRecord
    11831173    RTCCPTR_DEF PATMPushCSStart
     
    11921182    DD      0
    11931183    DD      0ffffffffh
    1194 SECTION .text
     1184
    11951185
    11961186;;****************************************************
     
    12251215; esp      - EIP
    12261216;;
     1217BEGIN_PATCH_CODE_SECTION
    12271218BEGINPROC   PATMIretReplacement
    12281219PATMIretStart:
     
    13921383ENDPROC     PATMIretReplacement
    13931384
    1394 SECTION .data
    13951385; Patch record for 'iretd'
     1386BEGIN_PATCH_RODATA_SECTION
    13961387GLOBALNAME g_patmIretRecord
    13971388    RTCCPTR_DEF PATMIretStart
     
    14601451    DD      0
    14611452    DD      0ffffffffh
    1462 SECTION .text
     1453
    14631454
    14641455;;****************************************************
     
    14931484; esp      - EIP
    14941485;;
     1486BEGIN_PATCH_CODE_SECTION
    14951487BEGINPROC   PATMIretRing1Replacement
    14961488PATMIretRing1Start:
     
    16901682ENDPROC     PATMIretRing1Replacement
    16911683
    1692 SECTION .data
    16931684; Patch record for 'iretd'
     1685BEGIN_PATCH_RODATA_SECTION
    16941686GLOBALNAME g_patmIretRing1Record
    16951687    RTCCPTR_DEF PATMIretRing1Start
     
    17581750    DD      0
    17591751    DD      0ffffffffh
    1760 SECTION .text
    17611752
    17621753
     
    17781769;
    17791770; @note NEVER change this without bumping the SSM version
    1780 align 32
     1771BEGIN_PATCH_CODE_SECTION
    17811772BEGINPROC   PATMIretFunction
    17821773PATMIretFunction_Start:
     
    18421833ENDPROC     PATMIretFunction
    18431834
    1844 SECTION .data
     1835BEGIN_PATCH_RODATA_SECTION
    18451836GLOBALNAME g_patmIretFunctionRecord
    18461837    RTCCPTR_DEF PATMIretFunction_Start
     
    18551846    DD      0
    18561847    DD      0ffffffffh
    1857 SECTION .text
    1858 
    1859 
    1860 align 32 ; yasm / nasm diff - remove me!
     1848
     1849
     1850;
     1851; PATMCpuidReplacement
     1852;
     1853BEGIN_PATCH_CODE_SECTION
    18611854BEGINPROC   PATMCpuidReplacement
    18621855PATMCpuidStart:
     
    19101903ENDPROC PATMCpuidReplacement
    19111904
    1912 SECTION .data
    19131905; Patch record for 'cpuid'
     1906BEGIN_PATCH_RODATA_SECTION
    19141907GLOBALNAME g_patmCpuidRecord
    19151908    istruc PATCHASMRECORD
     
    19311924    DD      PATM_INTERRUPTFLAG,     0       ; 8
    19321925    DD      0ffffffffh, 0ffffffffh          ; 9 - for sanity checks
    1933 SECTION .text
    1934 
    1935 
     1926
     1927
     1928;
     1929;
     1930;
     1931BEGIN_PATCH_CODE_SECTION
    19361932BEGINPROC   PATMJEcxReplacement
    19371933PATMJEcxStart:
     
    19551951ENDPROC PATMJEcxReplacement
    19561952
    1957 SECTION .data
    19581953; Patch record for 'JEcx'
     1954BEGIN_PATCH_RODATA_SECTION
    19591955GLOBALNAME g_patmJEcxRecord
    19601956    RTCCPTR_DEF PATMJEcxStart
     
    19701966    DD      PATM_INTERRUPTFLAG
    19711967    DD      0
    1972     DD      0ffffffffh
    1973 SECTION .text
    1974 
    1975 align 32; yasm / nasm diffing. remove me!
     1968    DD      0ffffffffh, 0ffffffffh
     1969
     1970
     1971;
     1972;
     1973;
     1974BEGIN_PATCH_CODE_SECTION
    19761975BEGINPROC   PATMLoopReplacement
    19771976PATMLoopStart:
     
    19951994ENDPROC PATMLoopReplacement
    19961995
    1997 SECTION .data
    19981996; Patch record for 'Loop'
     1997BEGIN_PATCH_RODATA_SECTION
    19991998GLOBALNAME g_patmLoopRecord
    20001999    RTCCPTR_DEF PATMLoopStart
     
    20102009    DD      PATM_INTERRUPTFLAG
    20112010    DD      0
    2012     DD      0ffffffffh
    2013 SECTION .text
    2014 
     2011    DD      0ffffffffh, 0ffffffffh
     2012
     2013
     2014;
     2015;
     2016;
     2017BEGIN_PATCH_CODE_SECTION
    20152018BEGINPROC   PATMLoopZReplacement
    20162019PATMLoopZStart:
     
    20372040ENDPROC PATMLoopZReplacement
    20382041
    2039 SECTION .data
    20402042; Patch record for 'Loopz'
     2043BEGIN_PATCH_RODATA_SECTION
    20412044GLOBALNAME g_patmLoopZRecord
    20422045    RTCCPTR_DEF PATMLoopZStart
     
    20522055    DD      PATM_INTERRUPTFLAG
    20532056    DD      0
    2054     DD      0ffffffffh
    2055 SECTION .text
    2056 
    2057 
     2057    DD      0ffffffffh, 0ffffffffh
     2058
     2059
     2060;
     2061;
     2062;
     2063BEGIN_PATCH_CODE_SECTION
    20582064BEGINPROC   PATMLoopNZReplacement
    20592065PATMLoopNZStart:
     
    20802086ENDPROC PATMLoopNZReplacement
    20812087
    2082 SECTION .data
    20832088; Patch record for 'LoopNZ'
     2089BEGIN_PATCH_RODATA_SECTION
    20842090GLOBALNAME g_patmLoopNZRecord
    20852091    RTCCPTR_DEF PATMLoopNZStart
     
    20952101    DD      PATM_INTERRUPTFLAG
    20962102    DD      0
    2097     DD      0ffffffffh
    2098 SECTION .text
    2099 
    2100 align 32
     2103    DD      0ffffffffh, 0ffffffffh
     2104
     2105
     2106;
    21012107; Global patch function for indirect calls
    21022108; Caller is responsible for clearing PATM_INTERRUPTFLAG and doing:
     
    21092115;
    21102116; @note NEVER change this without bumping the SSM version
     2117BEGIN_PATCH_CODE_SECTION
    21112118BEGINPROC PATMLookupAndCall
    21122119PATMLookupAndCallStart:
     
    22152222ENDPROC PATMLookupAndCall
    22162223
    2217 SECTION .data
    22182224; Patch record for indirect calls and jumps
     2225BEGIN_PATCH_RODATA_SECTION
    22192226GLOBALNAME g_patmLookupAndCallRecord
    22202227    RTCCPTR_DEF PATMLookupAndCallStart
     
    22502257    DD      PATM_CALL_PATCH_TARGET_ADDR
    22512258    DD      0
    2252     DD      0ffffffffh
    2253 SECTION .text
    2254 
    2255 
    2256 align 32
     2259    DD      0ffffffffh, 0ffffffffh
     2260
     2261
     2262;
    22572263; Global patch function for indirect jumps
    22582264; Caller is responsible for clearing PATM_INTERRUPTFLAG and doing:
     
    22632269;
    22642270; @note NEVER change this without bumping the SSM version
     2271BEGIN_PATCH_CODE_SECTION
    22652272BEGINPROC PATMLookupAndJump
    22662273PATMLookupAndJumpStart:
     
    23342341ENDPROC PATMLookupAndJump
    23352342
    2336 SECTION .data
    23372343; Patch record for indirect calls and jumps
     2344BEGIN_PATCH_RODATA_SECTION
    23382345GLOBALNAME g_patmLookupAndJumpRecord
    23392346    RTCCPTR_DEF PATMLookupAndJumpStart
     
    23532360    DD      PATM_TEMP_EAX
    23542361    DD      0
    2355     DD      0ffffffffh
    2356 SECTION .text
    2357 
    2358 
    2359 
    2360 
    2361 align 32
     2362    DD      0ffffffffh, 0ffffffffh
     2363
     2364
    23622365; Patch function for static calls
    23632366; @note static calls have only one lookup slot!
     
    23652368;   push    [pTargetGC]
    23662369;
     2370BEGIN_PATCH_CODE_SECTION
    23672371BEGINPROC PATMCall
    23682372PATMCallStart:
     
    23952399ENDPROC PATMCall
    23962400
    2397 SECTION .data
    23982401; Patch record for direct calls
     2402BEGIN_PATCH_RODATA_SECTION
    23992403GLOBALNAME g_patmCallRecord
    24002404    RTCCPTR_DEF PATMCallStart
     
    24142418    DD      PATM_INTERRUPTFLAG
    24152419    DD      0
    2416     DD      0ffffffffh
    2417 SECTION .text
    2418 
    2419 
    2420 align 32
     2420    DD      0ffffffffh, 0ffffffffh
     2421
     2422
    24212423; Patch function for indirect calls
    24222424; Caller is responsible for clearing PATM_INTERRUPTFLAG and adding:
    24232425;   push    [pTargetGC]
    24242426;
     2427BEGIN_PATCH_CODE_SECTION
    24252428BEGINPROC PATMCallIndirect
    24262429PATMCallIndirectStart:
     
    24532456ENDPROC PATMCallIndirect
    24542457
    2455 SECTION .data
    24562458; Patch record for indirect calls
     2459BEGIN_PATCH_RODATA_SECTION
    24572460GLOBALNAME g_patmCallIndirectRecord
    24582461    RTCCPTR_DEF PATMCallIndirectStart
     
    24722475    DD      PATM_INTERRUPTFLAG
    24732476    DD      0
    2474     DD      0ffffffffh
    2475 SECTION .text
    2476 
    2477 
    2478 align 32
     2477    DD      0ffffffffh, 0ffffffffh
     2478
     2479
     2480;
    24792481; Patch function for indirect jumps
    24802482; Caller is responsible for clearing PATM_INTERRUPTFLAG and adding:
    24812483;   push    [pTargetGC]
    24822484;
     2485BEGIN_PATCH_CODE_SECTION
    24832486BEGINPROC PATMJumpIndirect
    24842487PATMJumpIndirectStart:
     
    25162519ENDPROC PATMJumpIndirect
    25172520
    2518 SECTION .data
    25192521; Patch record for indirect jumps
     2522BEGIN_PATCH_RODATA_SECTION
    25202523GLOBALNAME g_patmJumpIndirectRecord
    25212524    RTCCPTR_DEF PATMJumpIndirectStart
     
    25352538    DD      PATM_INTERRUPTFLAG
    25362539    DD      0
    2537     DD      0ffffffffh
    2538 SECTION .text
     2540    DD      0ffffffffh, 0ffffffffh
     2541
    25392542
    25402543;
    25412544; return from duplicated function
    25422545;
    2543 align 32
     2546BEGIN_PATCH_CODE_SECTION
    25442547BEGINPROC   PATMRet
    25452548PATMRet_Start:
     
    25832586ENDPROC     PATMRet
    25842587
    2585 SECTION .data
     2588BEGIN_PATCH_RODATA_SECTION
    25862589GLOBALNAME g_patmRetRecord
    25872590    RTCCPTR_DEF PATMRet_Start
     
    25992602    DD      PATM_INTERRUPTFLAG
    26002603    DD      0
    2601     DD      0ffffffffh
    2602 SECTION .text
     2604    DD      0ffffffffh, 0ffffffffh
     2605
    26032606
    26042607;
     
    26192622;
    26202623; @note NEVER change this without bumping the SSM version
    2621 align 32
     2624BEGIN_PATCH_CODE_SECTION
    26222625BEGINPROC   PATMRetFunction
    26232626PATMRetFunction_Start:
     
    27502753ENDPROC     PATMRetFunction
    27512754
    2752 SECTION .data
     2755BEGIN_PATCH_RODATA_SECTION
    27532756GLOBALNAME g_patmRetFunctionRecord
    27542757    RTCCPTR_DEF PATMRetFunction_Start
     
    27842787    DD      0
    27852788%endif
    2786     DD      0ffffffffh
    2787 SECTION .text
     2789    DD      0ffffffffh, 0ffffffffh
    27882790
    27892791
     
    27912793; Jump to original instruction if IF=1
    27922794;
     2795BEGIN_PATCH_CODE_SECTION
    27932796BEGINPROC   PATMCheckIF
    27942797PATMCheckIF_Start:
     
    28272830ENDPROC     PATMCheckIF
    28282831
    2829 SECTION .data
    28302832; Patch record for call instructions
     2833BEGIN_PATCH_RODATA_SECTION
    28312834GLOBALNAME g_patmCheckIFRecord
    28322835    RTCCPTR_DEF PATMCheckIF_Start
     
    28542857    DD      PATM_INTERRUPTFLAG
    28552858    DD      0
    2856     DD      0ffffffffh
    2857 SECTION .text
     2859    DD      0ffffffffh, 0ffffffffh
     2860
    28582861
    28592862;
    28602863; Jump back to guest if IF=1, else fault
    28612864;
     2865BEGIN_PATCH_CODE_SECTION
    28622866BEGINPROC   PATMJumpToGuest_IF1
    28632867PATMJumpToGuest_IF1_Start:
     
    28832887ENDPROC     PATMJumpToGuest_IF1
    28842888
    2885 SECTION .data
    28862889; Patch record for call instructions
     2890BEGIN_PATCH_RODATA_SECTION
    28872891GLOBALNAME PATMJumpToGuest_IF1Record
    28882892    RTCCPTR_DEF PATMJumpToGuest_IF1_Start
     
    29002904    DD      PATM_INTERRUPTFLAG
    29012905    DD      0
    2902     DD      0ffffffffh
    2903 SECTION .text
    2904 
    2905 
    2906 ; check and correct RPL of pushed ss
     2906    DD      0ffffffffh, 0ffffffffh
     2907
     2908
     2909;
     2910; Check and correct RPL of pushed ss.
     2911;
     2912BEGIN_PATCH_CODE_SECTION
    29072913BEGINPROC PATMMovFromSS
    29082914PATMMovFromSS_Start:
     
    29212927ENDPROC PATMMovFromSS
    29222928
    2923 SECTION .data
     2929BEGIN_PATCH_RODATA_SECTION
    29242930GLOBALNAME g_patmMovFromSSRecord
    29252931    RTCCPTR_DEF PATMMovFromSS_Start
     
    29292935    DD      PATMMovFromSS_Start_End - PATMMovFromSS_Start
    29302936    DD      0
    2931     DD      0ffffffffh
     2937    DD      0ffffffffh, 0ffffffffh
    29322938
    29332939
  • trunk/src/VBox/VMM/VMMR3/PATMPatch.cpp

    r54687 r54688  
    4545#include "PATMPatch.h"
    4646
    47 /* internal structure for passing more information about call fixups to patmPatchGenCode */
     47
     48/*******************************************************************************
     49*   Structures and Typedefs                                                    *
     50*******************************************************************************/
     51/**
     52 * Internal structure for passing more information about call fixups to
     53 * patmPatchGenCode.
     54 */
    4855typedef struct
    4956{
     
    5461} PATMCALLINFO, *PPATMCALLINFO;
    5562
    56 int patmPatchAddReloc32(PVM pVM, PPATCHINFO pPatch, uint8_t *pRelocHC, uint32_t uType, RTRCPTR pSource, RTRCPTR pDest)
     63
     64/*******************************************************************************
     65*   Defined Constants And Macros                                               *
     66*******************************************************************************/
     67#define PATCHGEN_PROLOG_NODEF(pVM, pPatch) \
     68    do { \
     69        pPB = PATCHCODE_PTR_HC(pPatch) + pPatch->uCurPatchOffset; \
     70        if (pPB + 256 >= pVM->patm.s.pPatchMemHC + pVM->patm.s.cbPatchMem) \
     71        { \
     72            pVM->patm.s.fOutOfMemory = true; \
     73            Assert(pPB + 256 >= pVM->patm.s.pPatchMemHC + pVM->patm.s.cbPatchMem); \
     74            return VERR_NO_MEMORY; \
     75        } \
     76    } while (0)
     77
     78#define PATCHGEN_PROLOG(pVM, pPatch) \
     79    uint8_t *pPB; \
     80    PATCHGEN_PROLOG_NODEF(pVM, pPatch)
     81
     82#define PATCHGEN_EPILOG(pPatch, size) \
     83    do { \
     84        Assert(size <= 640); \
     85        pPatch->uCurPatchOffset += size; \
     86    } while (0)
     87
     88
     89
     90
     91int patmPatchAddReloc32(PVM pVM, PPATCHINFO pPatch, uint8_t *pRelocHC, uint32_t uType,
     92                        RTRCPTR pSource /*= 0*/, RTRCPTR pDest /*= 0*/)
    5793{
    5894    PRELOCREC pRec;
     
    96132    return VINF_SUCCESS;
    97133}
    98 
    99 #define PATCHGEN_PROLOG_NODEF(pVM, pPatch)                                      \
    100     pPB = PATCHCODE_PTR_HC(pPatch) + pPatch->uCurPatchOffset;            \
    101                                                                                \
    102     if (pPB + 256 >= pVM->patm.s.pPatchMemHC + pVM->patm.s.cbPatchMem)          \
    103     {                                                                          \
    104         pVM->patm.s.fOutOfMemory = true; \
    105         Assert(pPB + 256 >= pVM->patm.s.pPatchMemHC + pVM->patm.s.cbPatchMem); \
    106         return VERR_NO_MEMORY; \
    107     }
    108 
    109 #define PATCHGEN_PROLOG(pVM, pPatch)                                      \
    110     uint8_t *pPB;                                                         \
    111     PATCHGEN_PROLOG_NODEF(pVM, pPatch);
    112 
    113 
    114 #define PATCHGEN_EPILOG(pPatch, size) \
    115     Assert(size <= 640);              \
    116     pPatch->uCurPatchOffset += size;
    117 
    118134
    119135static uint32_t patmPatchGenCode(PVM pVM, PPATCHINFO pPatch, uint8_t *pPB, PCPATCHASMRECORD pAsmRecord,
     
    226242
    227243                case PATM_CPUID_STD_PTR:
    228                     /** @todo dirty hack when correcting this fixup (state restore) */
    229244                    dest = CPUMR3GetGuestCpuIdPatmStdRCPtr(pVM);
    230245                    break;
    231246
    232247                case PATM_CPUID_EXT_PTR:
    233                     /** @todo dirty hack when correcting this fixup (state restore) */
    234248                    dest = CPUMR3GetGuestCpuIdPatmExtRCPtr(pVM);
    235249                    break;
    236250
    237251                case PATM_CPUID_CENTAUR_PTR:
    238                     /** @todo dirty hack when correcting this fixup (state restore) */
    239252                    dest = CPUMR3GetGuestCpuIdPatmCentaurRCPtr(pVM);
    240253                    break;
    241254
    242255                case PATM_CPUID_DEF_PTR:
    243                     /** @todo dirty hack when correcting this fixup (state restore) */
    244256                    dest = CPUMR3GetGuestCpuIdPatmDefRCPtr(pVM);
    245257                    break;
     
    377389        *(uint32_t *)&pPB[pAsmRecord->offJump] = displ;
    378390        patmPatchAddReloc32(pVM, pPatch, &pPB[pAsmRecord->offJump], FIXUP_REL_JMPTOGUEST,
    379                         PATCHCODE_PTR_GC(pPatch) + pPatch->uCurPatchOffset + pAsmRecord->offJump - 1 + SIZEOF_NEARJUMP32,
    380                         pReturnAddrGC);
     391                            PATCHCODE_PTR_GC(pPatch) + pPatch->uCurPatchOffset + pAsmRecord->offJump - 1 + SIZEOF_NEARJUMP32,
     392                            pReturnAddrGC);
    381393    }
    382394
  • trunk/src/VBox/VMM/VMMR3/PATMSSM.cpp

    r54674 r54688  
    11021102 * @returns VBox status code.
    11031103 * @param   pVM             Pointer to the VM.
    1104  * @param   ulSSMVersion    SSM version
     1104 * @param   uVersion        Saved state version.
    11051105 * @param   patmInfo        Saved PATM structure
    11061106 * @param   pPatch          Patch record
     
    11091109 * @param   pFixup          Fixup address
    11101110 */
    1111 static void patmCorrectFixup(PVM pVM, unsigned ulSSMVersion, PATM &patmInfo, PPATCHINFO pPatch, PRELOCREC pRec, int32_t offset, RTRCPTR *pFixup)
     1111static void patmCorrectFixup(PVM pVM, unsigned uVersion, PATM &patmInfo, PPATCHINFO pPatch, PRELOCREC pRec,
     1112                             int32_t offset, RTRCPTR *pFixup)
    11121113{
    11131114    int32_t delta = pVM->patm.s.pPatchMemGC - patmInfo.pPatchMemGC;
     
    11201121            break;
    11211122
    1122         if (    *pFixup >= patmInfo.pGCStateGC
    1123             &&  *pFixup <  patmInfo.pGCStateGC + sizeof(PATMGCSTATE))
    1124         {
    1125             LogFlow(("Changing absolute GCState at %RRv from %RRv to %RRv\n", patmInfo.pPatchMemGC + offset, *pFixup, (*pFixup - patmInfo.pGCStateGC) + pVM->patm.s.pGCStateGC));
    1126             *pFixup = (*pFixup - patmInfo.pGCStateGC) + pVM->patm.s.pGCStateGC;
    1127         }
    1128         else
    1129         if (    *pFixup >= patmInfo.pCPUMCtxGC
    1130             &&  *pFixup <  patmInfo.pCPUMCtxGC + sizeof(CPUMCTX))
    1131         {
    1132             LogFlow(("Changing absolute CPUMCTX at %RRv from %RRv to %RRv\n", patmInfo.pPatchMemGC + offset, *pFixup, (*pFixup - patmInfo.pCPUMCtxGC) + pVM->patm.s.pCPUMCtxGC));
     1123        RTRCPTR const uFixup = *pFixup;
     1124        if (    uFixup >= patmInfo.pGCStateGC
     1125            &&  uFixup <  patmInfo.pGCStateGC + sizeof(PATMGCSTATE))
     1126        {
     1127            LogFlow(("Changing absolute GCState at %RRv from %RRv to %RRv\n", patmInfo.pPatchMemGC + offset, uFixup, (uFixup - patmInfo.pGCStateGC) + pVM->patm.s.pGCStateGC));
     1128            *pFixup = (uFixup - patmInfo.pGCStateGC) + pVM->patm.s.pGCStateGC;
     1129        }
     1130        else if (   uFixup >= patmInfo.pCPUMCtxGC
     1131                 && uFixup <  patmInfo.pCPUMCtxGC + sizeof(CPUMCTX))
     1132        {
     1133            LogFlow(("Changing absolute CPUMCTX at %RRv from %RRv to %RRv\n", patmInfo.pPatchMemGC + offset, uFixup, (uFixup - patmInfo.pCPUMCtxGC) + pVM->patm.s.pCPUMCtxGC));
    11331134
    11341135            /* The CPUMCTX structure has completely changed, so correct the offsets too. */
    1135             if (ulSSMVersion == PATM_SAVED_STATE_VERSION_VER16)
     1136            if (uVersion == PATM_SAVED_STATE_VERSION_VER16)
    11361137            {
    1137                 unsigned uCPUMOffset = *pFixup - patmInfo.pCPUMCtxGC;
     1138                unsigned offCpumCtx = uFixup - patmInfo.pCPUMCtxGC;
    11381139
    11391140                /* ''case RT_OFFSETOF()'' does not work as gcc refuses to use & as a constant expression.
    11401141                 * Defining RT_OFFSETOF as __builtin_offsetof for gcc would make this possible. But this
    11411142                 * function is not available in older gcc versions, at least not in gcc-3.3 */
    1142                 if (uCPUMOffset == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, dr0))
    1143                 {
    1144                     LogFlow(("Changing dr[0] offset from %x to %x\n", uCPUMOffset, RT_OFFSETOF(CPUMCTX, dr[0])));
     1143                if (offCpumCtx == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, dr0))
     1144                {
     1145                    LogFlow(("Changing dr[0] offset from %x to %x\n", offCpumCtx, RT_OFFSETOF(CPUMCTX, dr[0])));
    11451146                    *pFixup = pVM->patm.s.pCPUMCtxGC + RT_OFFSETOF(CPUMCTX, dr[0]);
    11461147                }
    1147                 else if (uCPUMOffset == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, dr1))
    1148                 {
    1149                     LogFlow(("Changing dr[1] offset from %x to %x\n", uCPUMOffset, RT_OFFSETOF(CPUMCTX, dr[1])));
     1148                else if (offCpumCtx == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, dr1))
     1149                {
     1150                    LogFlow(("Changing dr[1] offset from %x to %x\n", offCpumCtx, RT_OFFSETOF(CPUMCTX, dr[1])));
    11501151                    *pFixup = pVM->patm.s.pCPUMCtxGC + RT_OFFSETOF(CPUMCTX, dr[1]);
    11511152                }
    1152                 else if (uCPUMOffset == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, dr2))
    1153                 {
    1154                     LogFlow(("Changing dr[2] offset from %x to %x\n", uCPUMOffset, RT_OFFSETOF(CPUMCTX, dr[2])));
     1153                else if (offCpumCtx == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, dr2))
     1154                {
     1155                    LogFlow(("Changing dr[2] offset from %x to %x\n", offCpumCtx, RT_OFFSETOF(CPUMCTX, dr[2])));
    11551156                    *pFixup = pVM->patm.s.pCPUMCtxGC + RT_OFFSETOF(CPUMCTX, dr[2]);
    11561157                }
    1157                 else if (uCPUMOffset == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, dr3))
    1158                 {
    1159                     LogFlow(("Changing dr[3] offset from %x to %x\n", uCPUMOffset, RT_OFFSETOF(CPUMCTX, dr[3])));
     1158                else if (offCpumCtx == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, dr3))
     1159                {
     1160                    LogFlow(("Changing dr[3] offset from %x to %x\n", offCpumCtx, RT_OFFSETOF(CPUMCTX, dr[3])));
    11601161                    *pFixup = pVM->patm.s.pCPUMCtxGC + RT_OFFSETOF(CPUMCTX, dr[3]);
    11611162                }
    1162                 else if (uCPUMOffset == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, dr4))
    1163                 {
    1164                     LogFlow(("Changing dr[4] offset from %x to %x\n", uCPUMOffset, RT_OFFSETOF(CPUMCTX, dr[4])));
     1163                else if (offCpumCtx == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, dr4))
     1164                {
     1165                    LogFlow(("Changing dr[4] offset from %x to %x\n", offCpumCtx, RT_OFFSETOF(CPUMCTX, dr[4])));
    11651166                    *pFixup = pVM->patm.s.pCPUMCtxGC + RT_OFFSETOF(CPUMCTX, dr[4]);
    11661167                }
    1167                 else if (uCPUMOffset == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, dr5))
    1168                 {
    1169                     LogFlow(("Changing dr[5] offset from %x to %x\n", uCPUMOffset, RT_OFFSETOF(CPUMCTX, dr[5])));
     1168                else if (offCpumCtx == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, dr5))
     1169                {
     1170                    LogFlow(("Changing dr[5] offset from %x to %x\n", offCpumCtx, RT_OFFSETOF(CPUMCTX, dr[5])));
    11701171                    *pFixup = pVM->patm.s.pCPUMCtxGC + RT_OFFSETOF(CPUMCTX, dr[5]);
    11711172                }
    1172                 else if (uCPUMOffset == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, dr6))
    1173                 {
    1174                     LogFlow(("Changing dr[6] offset from %x to %x\n", uCPUMOffset, RT_OFFSETOF(CPUMCTX, dr[6])));
     1173                else if (offCpumCtx == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, dr6))
     1174                {
     1175                    LogFlow(("Changing dr[6] offset from %x to %x\n", offCpumCtx, RT_OFFSETOF(CPUMCTX, dr[6])));
    11751176                    *pFixup = pVM->patm.s.pCPUMCtxGC + RT_OFFSETOF(CPUMCTX, dr[6]);
    11761177                }
    1177                 else if (uCPUMOffset == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, dr7))
    1178                 {
    1179                     LogFlow(("Changing dr[7] offset from %x to %x\n", uCPUMOffset, RT_OFFSETOF(CPUMCTX, dr[7])));
     1178                else if (offCpumCtx == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, dr7))
     1179                {
     1180                    LogFlow(("Changing dr[7] offset from %x to %x\n", offCpumCtx, RT_OFFSETOF(CPUMCTX, dr[7])));
    11801181                    *pFixup = pVM->patm.s.pCPUMCtxGC + RT_OFFSETOF(CPUMCTX, dr[7]);
    11811182                }
    1182                 else if (uCPUMOffset == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, cr0))
    1183                 {
    1184                     LogFlow(("Changing cr0 offset from %x to %x\n", uCPUMOffset, RT_OFFSETOF(CPUMCTX, cr0)));
     1183                else if (offCpumCtx == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, cr0))
     1184                {
     1185                    LogFlow(("Changing cr0 offset from %x to %x\n", offCpumCtx, RT_OFFSETOF(CPUMCTX, cr0)));
    11851186                    *pFixup = pVM->patm.s.pCPUMCtxGC + RT_OFFSETOF(CPUMCTX, cr0);
    11861187                }
    1187                 else if (uCPUMOffset == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, cr2))
    1188                 {
    1189                     LogFlow(("Changing cr2 offset from %x to %x\n", uCPUMOffset, RT_OFFSETOF(CPUMCTX, cr2)));
     1188                else if (offCpumCtx == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, cr2))
     1189                {
     1190                    LogFlow(("Changing cr2 offset from %x to %x\n", offCpumCtx, RT_OFFSETOF(CPUMCTX, cr2)));
    11901191                    *pFixup = pVM->patm.s.pCPUMCtxGC + RT_OFFSETOF(CPUMCTX, cr2);
    11911192                }
    1192                 else if (uCPUMOffset == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, cr3))
    1193                 {
    1194                     LogFlow(("Changing cr3 offset from %x to %x\n", uCPUMOffset, RT_OFFSETOF(CPUMCTX, cr3)));
     1193                else if (offCpumCtx == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, cr3))
     1194                {
     1195                    LogFlow(("Changing cr3 offset from %x to %x\n", offCpumCtx, RT_OFFSETOF(CPUMCTX, cr3)));
    11951196                    *pFixup = pVM->patm.s.pCPUMCtxGC + RT_OFFSETOF(CPUMCTX, cr3);
    11961197                }
    1197                 else if (uCPUMOffset == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, cr4))
    1198                 {
    1199                     LogFlow(("Changing cr4 offset from %x to %x\n", uCPUMOffset, RT_OFFSETOF(CPUMCTX, cr4)));
     1198                else if (offCpumCtx == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, cr4))
     1199                {
     1200                    LogFlow(("Changing cr4 offset from %x to %x\n", offCpumCtx, RT_OFFSETOF(CPUMCTX, cr4)));
    12001201                    *pFixup = pVM->patm.s.pCPUMCtxGC + RT_OFFSETOF(CPUMCTX, cr4);
    12011202                }
    1202                 else if (uCPUMOffset == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, tr))
    1203                 {
    1204                     LogFlow(("Changing tr offset from %x to %x\n", uCPUMOffset, RT_OFFSETOF(CPUMCTX, tr)));
     1203                else if (offCpumCtx == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, tr))
     1204                {
     1205                    LogFlow(("Changing tr offset from %x to %x\n", offCpumCtx, RT_OFFSETOF(CPUMCTX, tr)));
    12051206                    *pFixup = pVM->patm.s.pCPUMCtxGC + RT_OFFSETOF(CPUMCTX, tr);
    12061207                }
    1207                 else if (uCPUMOffset == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, ldtr))
    1208                 {
    1209                     LogFlow(("Changing ldtr offset from %x to %x\n", uCPUMOffset, RT_OFFSETOF(CPUMCTX, ldtr)));
     1208                else if (offCpumCtx == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, ldtr))
     1209                {
     1210                    LogFlow(("Changing ldtr offset from %x to %x\n", offCpumCtx, RT_OFFSETOF(CPUMCTX, ldtr)));
    12101211                    *pFixup = pVM->patm.s.pCPUMCtxGC + RT_OFFSETOF(CPUMCTX, ldtr);
    12111212                }
    1212                 else if (uCPUMOffset == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, gdtr.pGdt))
    1213                 {
    1214                     LogFlow(("Changing pGdt offset from %x to %x\n", uCPUMOffset, RT_OFFSETOF(CPUMCTX, gdtr.pGdt)));
     1213                else if (offCpumCtx == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, gdtr.pGdt))
     1214                {
     1215                    LogFlow(("Changing pGdt offset from %x to %x\n", offCpumCtx, RT_OFFSETOF(CPUMCTX, gdtr.pGdt)));
    12151216                    *pFixup = pVM->patm.s.pCPUMCtxGC + RT_OFFSETOF(CPUMCTX, gdtr.pGdt);
    12161217                }
    1217                 else if (uCPUMOffset == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, gdtr.cbGdt))
    1218                 {
    1219                     LogFlow(("Changing cbGdt offset from %x to %x\n", uCPUMOffset, RT_OFFSETOF(CPUMCTX, gdtr.cbGdt)));
     1218                else if (offCpumCtx == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, gdtr.cbGdt))
     1219                {
     1220                    LogFlow(("Changing cbGdt offset from %x to %x\n", offCpumCtx, RT_OFFSETOF(CPUMCTX, gdtr.cbGdt)));
    12201221                    *pFixup = pVM->patm.s.pCPUMCtxGC + RT_OFFSETOF(CPUMCTX, gdtr.cbGdt);
    12211222                }
    1222                 else if (uCPUMOffset == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, idtr.pIdt))
    1223                 {
    1224                     LogFlow(("Changing pIdt offset from %x to %x\n", uCPUMOffset, RT_OFFSETOF(CPUMCTX, idtr.pIdt)));
     1223                else if (offCpumCtx == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, idtr.pIdt))
     1224                {
     1225                    LogFlow(("Changing pIdt offset from %x to %x\n", offCpumCtx, RT_OFFSETOF(CPUMCTX, idtr.pIdt)));
    12251226                    *pFixup = pVM->patm.s.pCPUMCtxGC + RT_OFFSETOF(CPUMCTX, idtr.pIdt);
    12261227                }
    1227                 else if (uCPUMOffset == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, idtr.cbIdt))
    1228                 {
    1229                     LogFlow(("Changing cbIdt offset from %x to %x\n", uCPUMOffset, RT_OFFSETOF(CPUMCTX, idtr.cbIdt)));
     1228                else if (offCpumCtx == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, idtr.cbIdt))
     1229                {
     1230                    LogFlow(("Changing cbIdt offset from %x to %x\n", offCpumCtx, RT_OFFSETOF(CPUMCTX, idtr.cbIdt)));
    12301231                    *pFixup = pVM->patm.s.pCPUMCtxGC + RT_OFFSETOF(CPUMCTX, idtr.cbIdt);
    12311232                }
    12321233                else
    1233                     AssertMsgFailed(("Unexpected CPUMCTX offset %x\n", uCPUMOffset));
     1234                    AssertMsgFailed(("Unexpected CPUMCTX offset %x\n", offCpumCtx));
    12341235            }
    12351236            else
    1236                 *pFixup = (*pFixup - patmInfo.pCPUMCtxGC) + pVM->patm.s.pCPUMCtxGC;
    1237         }
    1238         else
    1239         if (    *pFixup >= patmInfo.pStatsGC
    1240             &&  *pFixup <  patmInfo.pStatsGC + PATM_STAT_MEMSIZE)
    1241         {
    1242             LogFlow(("Changing absolute Stats at %RRv from %RRv to %RRv\n", patmInfo.pPatchMemGC + offset, *pFixup, (*pFixup - patmInfo.pStatsGC) + pVM->patm.s.pStatsGC));
    1243             *pFixup = (*pFixup - patmInfo.pStatsGC) + pVM->patm.s.pStatsGC;
    1244         }
    1245         else
    1246         if (    *pFixup >= patmInfo.pGCStackGC
    1247             &&  *pFixup <  patmInfo.pGCStackGC + PATM_STACK_TOTAL_SIZE)
    1248         {
    1249             LogFlow(("Changing absolute Stack at %RRv from %RRv to %RRv\n", patmInfo.pPatchMemGC + offset, *pFixup, (*pFixup - patmInfo.pGCStackGC) + pVM->patm.s.pGCStackGC));
    1250             *pFixup = (*pFixup - patmInfo.pGCStackGC) + pVM->patm.s.pGCStackGC;
    1251         }
    1252         else
    1253         if (    *pFixup >= patmInfo.pPatchMemGC
    1254             &&  *pFixup <  patmInfo.pPatchMemGC + patmInfo.cbPatchMem)
    1255         {
    1256             LogFlow(("Changing absolute PatchMem at %RRv from %RRv to %RRv\n", patmInfo.pPatchMemGC + offset, *pFixup, (*pFixup - patmInfo.pPatchMemGC) + pVM->patm.s.pPatchMemGC));
    1257             *pFixup = (*pFixup - patmInfo.pPatchMemGC) + pVM->patm.s.pPatchMemGC;
    1258         }
    1259         else
     1237                *pFixup = (uFixup - patmInfo.pCPUMCtxGC) + pVM->patm.s.pCPUMCtxGC;
     1238        }
     1239        else if (   uFixup >= patmInfo.pStatsGC
     1240                 && uFixup <  patmInfo.pStatsGC + PATM_STAT_MEMSIZE)
     1241        {
     1242            LogFlow(("Changing absolute Stats at %RRv from %RRv to %RRv\n", patmInfo.pPatchMemGC + offset, uFixup, (uFixup - patmInfo.pStatsGC) + pVM->patm.s.pStatsGC));
     1243            *pFixup = (uFixup - patmInfo.pStatsGC) + pVM->patm.s.pStatsGC;
     1244        }
     1245        else if (   uFixup >= patmInfo.pGCStackGC
     1246                 && uFixup <  patmInfo.pGCStackGC + PATM_STACK_TOTAL_SIZE)
     1247        {
     1248            LogFlow(("Changing absolute Stack at %RRv from %RRv to %RRv\n", patmInfo.pPatchMemGC + offset, uFixup, (uFixup - patmInfo.pGCStackGC) + pVM->patm.s.pGCStackGC));
     1249            *pFixup = (uFixup - patmInfo.pGCStackGC) + pVM->patm.s.pGCStackGC;
     1250        }
     1251        else if (   uFixup >= patmInfo.pPatchMemGC
     1252                 && uFixup <  patmInfo.pPatchMemGC + patmInfo.cbPatchMem)
     1253        {
     1254            LogFlow(("Changing absolute PatchMem at %RRv from %RRv to %RRv\n", patmInfo.pPatchMemGC + offset, uFixup, (uFixup - patmInfo.pPatchMemGC) + pVM->patm.s.pPatchMemGC));
     1255            *pFixup = (uFixup - patmInfo.pPatchMemGC) + pVM->patm.s.pPatchMemGC;
     1256        }
    12601257        /* Boldly ASSUMES:
    12611258         * 1. That pCPUMCtxGC is in the VM structure and that its location is
     
    12641261         *    structure.
    12651262         * 3. That the CPUM leafs are less than 8KB into the structure. */
    1266         if (    ulSSMVersion <= PATM_SAVED_STATE_VERSION_FIXUP_HACK
    1267             &&  *pFixup - (patmInfo.pCPUMCtxGC & UINT32_C(0xffc00000)) < UINT32_C(32))
    1268         {
    1269             LogFlow(("Changing fLocalForcedActions fixup from %RRv to %RRv\n", *pFixup, pVM->pVMRC + RT_OFFSETOF(VM, aCpus[0].fLocalForcedActions)));
     1263        else if (   uVersion <= PATM_SAVED_STATE_VERSION_FIXUP_HACK
     1264                 && uFixup - (patmInfo.pCPUMCtxGC & UINT32_C(0xffc00000)) < UINT32_C(32))
     1265        {
     1266            LogFlow(("Changing fLocalForcedActions fixup from %RRv to %RRv\n", uFixup, pVM->pVMRC + RT_OFFSETOF(VM, aCpus[0].fLocalForcedActions)));
    12701267            *pFixup = pVM->pVMRC + RT_OFFSETOF(VM, aCpus[0].fLocalForcedActions);
    12711268        }
    1272         else
    1273         if (    ulSSMVersion <= PATM_SAVED_STATE_VERSION_FIXUP_HACK
    1274             &&  *pFixup - (patmInfo.pCPUMCtxGC & UINT32_C(0xffc00000)) < UINT32_C(8192))
     1269        else if (   uVersion <= PATM_SAVED_STATE_VERSION_FIXUP_HACK
     1270                 && uFixup - (patmInfo.pCPUMCtxGC & UINT32_C(0xffc00000)) < UINT32_C(8192))
    12751271        {
    12761272            static int cCpuidFixup = 0;
    1277 #ifdef LOG_ENABLED
    1278             RTRCPTR oldFixup = *pFixup;
    1279 #endif
     1273
    12801274            /* very dirty assumptions about the cpuid patch and cpuid ordering. */
    1281             switch(cCpuidFixup & 3)
     1275            switch (cCpuidFixup & 3)
    12821276            {
    12831277            case 0:
     
    12941288                break;
    12951289            }
    1296             LogFlow(("Changing cpuid fixup %d from %RRv to %RRv\n", cCpuidFixup, oldFixup, *pFixup));
     1290            LogFlow(("Changing cpuid fixup %d from %RRv to %RRv\n", cCpuidFixup, uFixup, *pFixup));
    12971291            cCpuidFixup++;
    12981292        }
    1299         else
    1300         if (ulSSMVersion >= PATM_SAVED_STATE_VERSION_MEM)
    1301         {
    1302 #ifdef LOG_ENABLED
    1303             RTRCPTR oldFixup = *pFixup;
    1304 #endif
    1305             /* Core.Key abused to store the type of fixup */
     1293        else if (uVersion >= PATM_SAVED_STATE_VERSION_MEM)
     1294        {
     1295            /* Core.Key abused to store the type of fixup. */
    13061296            switch ((uintptr_t)pRec->Core.Key)
    13071297            {
    13081298            case PATM_FIXUP_CPU_FF_ACTION:
    13091299                *pFixup = pVM->pVMRC + RT_OFFSETOF(VM, aCpus[0].fLocalForcedActions);
    1310                 LogFlow(("Changing cpu ff action fixup from %x to %x\n", oldFixup, *pFixup));
     1300                LogFlow(("Changing cpu ff action fixup from %x to %x\n", uFixup, *pFixup));
    13111301                break;
    13121302            case PATM_FIXUP_CPUID_DEFAULT:
    13131303                *pFixup = CPUMR3GetGuestCpuIdPatmDefRCPtr(pVM);
    1314                 LogFlow(("Changing cpuid def fixup from %x to %x\n", oldFixup, *pFixup));
     1304                LogFlow(("Changing cpuid def fixup from %x to %x\n", uFixup, *pFixup));
    13151305                break;
    13161306            case PATM_FIXUP_CPUID_STANDARD:
    13171307                *pFixup = CPUMR3GetGuestCpuIdPatmStdRCPtr(pVM);
    1318                 LogFlow(("Changing cpuid std fixup from %x to %x\n", oldFixup, *pFixup));
     1308                LogFlow(("Changing cpuid std fixup from %x to %x\n", uFixup, *pFixup));
    13191309                break;
    13201310            case PATM_FIXUP_CPUID_EXTENDED:
    13211311                *pFixup = CPUMR3GetGuestCpuIdPatmExtRCPtr(pVM);
    1322                 LogFlow(("Changing cpuid ext fixup from %x to %x\n", oldFixup, *pFixup));
     1312                LogFlow(("Changing cpuid ext fixup from %x to %x\n", uFixup, *pFixup));
    13231313                break;
    13241314            case PATM_FIXUP_CPUID_CENTAUR:
    13251315                *pFixup = CPUMR3GetGuestCpuIdPatmCentaurRCPtr(pVM);
    1326                 LogFlow(("Changing cpuid centaur fixup from %x to %x\n", oldFixup, *pFixup));
     1316                LogFlow(("Changing cpuid centaur fixup from %x to %x\n", uFixup, *pFixup));
    13271317                break;
    13281318            default:
    1329                 AssertMsgFailed(("Unexpected fixup value %x\n", *pFixup));
     1319                AssertMsgFailed(("Unexpected fixup value %p\n", (uintptr_t)pRec->Core.Key));
    13301320                break;
    13311321            }
  • trunk/src/VBox/VMM/include/PATMInternal.h

    r52771 r54688  
    153153} RELOCREC, *PRELOCREC;
    154154
    155 /* forward decl */
    156 struct _PATCHINFO;
    157 
    158155/* Cache record for guest to host pointer conversions. */
    159156typedef struct
     
    258255 * Patch information.
    259256 */
    260 typedef struct _PATCHINFO
     257typedef struct PATCHINFO
    261258{
    262259    /** Current patch state (enabled, disabled, etc.). */
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