VirtualBox

Changeset 1086 in vbox for trunk


Ignore:
Timestamp:
Feb 28, 2007 8:36:20 AM (18 years ago)
Author:
vboxsync
Message:

Corrected assumptions about flat addresses

Location:
trunk/src/VBox/VMM/PATM
Files:
3 edited

Legend:

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

    r882 r1086  
    20322032 * @returns VBox status code.
    20332033 * @param   pVM         The VM to operate on.
    2034  * @param   pCtx        CPU context
     2034 * @param   Sel         selector
     2035 * @param   pHiddenSel  The hidden selector register.
    20352036 * @param   pInstrGC    Instruction pointer
    20362037 */
    2037 CSAMR3DECL(int) CSAMR3CheckCode(PVM pVM, PCPUMCTX pCtx, RTGCPTR pInstrGC)
     2038CSAMR3DECL(int) CSAMR3CheckCodeEx(PVM pVM, RTSEL Sel, CPUMSELREGHID *pHiddenSel, RTGCPTR pInstrGC)
     2039{
     2040    PCSAMPAGE pPage = NULL;
     2041
     2042    if (EMIsRawRing0Enabled(pVM) == false || PATMIsPatchGCAddr(pVM, pInstrGC) == true)
     2043    {
     2044        // No use
     2045        return VINF_SUCCESS;
     2046    }
     2047
     2048    if (CSAMIsEnabled(pVM))
     2049    {
     2050        bool fCode32 = SELMIsSelector32Bit(pVM, Sel, pHiddenSel);
     2051
     2052        //assuming 32 bits code for now
     2053        Assert(fCode32);
     2054
     2055        pInstrGC = SELMToFlat(pVM, Sel, pHiddenSel, pInstrGC);
     2056
     2057        return CSAMR3CheckCode(pVM, pInstrGC);
     2058    }
     2059    return VINF_SUCCESS;
     2060}
     2061
     2062/**
     2063 * Scan and analyse code
     2064 *
     2065 * @returns VBox status code.
     2066 * @param   pVM         The VM to operate on.
     2067 * @param   pInstrGC    Instruction pointer (0:32 virtual address)
     2068 */
     2069CSAMR3DECL(int) CSAMR3CheckCode(PVM pVM, RTGCPTR pInstrGC)
    20382070{
    20392071    int rc;
     
    20502082        // Cache record for PATMGCVirtToHCVirt
    20512083        CSAMP2GLOOKUPREC cacheRec = {0};
    2052         bool fCode32 = SELMIsSelector32Bit(pVM, pCtx->cs, &pCtx->csHid);
    2053 
    2054         //assuming 32 bits code for now
    2055         Assert(fCode32);
    2056 
    2057         pInstrGC = SELMToFlat(pVM, pCtx->cs, &pCtx->csHid, pInstrGC);
    20582084
    20592085        STAM_PROFILE_START(&pVM->csam.s.StatTime, a);
    2060         rc = csamAnalyseCallCodeStream(pVM, pInstrGC, pInstrGC, fCode32, CSAMR3AnalyseCallback, pPage, &cacheRec);
     2086        rc = csamAnalyseCallCodeStream(pVM, pInstrGC, pInstrGC, true /* 32 bits code */, CSAMR3AnalyseCallback, pPage, &cacheRec);
    20612087        STAM_PROFILE_STOP(&pVM->csam.s.StatTime, a);
    20622088        if (rc != VINF_SUCCESS)
  • trunk/src/VBox/VMM/PATM/PATM.cpp

    r885 r1086  
    33363336
    33373337    pBranchTarget = pCtx->edx;
     3338    pBranchTarget = SELMToFlat(pVM, pCtx->cs, &pCtx->csHid, pBranchTarget);
    33383339
    33393340    /* First we check if the duplicate function target lies in some existing function patch already. Will save some space. */
     
    39013902 * @returns VBox status code.
    39023903 * @param   pVM         The VM to operate on.
    3903  * @param   pInstr      Guest context point to privileged instruction
     3904 * @param   pInstr      Guest context point to privileged instruction (0:32 flat address)
    39043905 * @param   flags       Patch flags
    39053906 *
     
    39093910{
    39103911    DISCPUSTATE cpu;
    3911     PCPUMCTX    pCtx;
    39123912    HCPTRTYPE(uint8_t *) pInstrHC;
    39133913    uint32_t opsize;
     
    39253925        return VERR_PATCHING_REFUSED;
    39263926
    3927     CPUMQueryGuestCtxPtr(pVM, &pCtx);
    3928 
    39293927    /* Test for patch conflict only with patches that actually change guest code. */
    39303928    if (!(flags & (PATMFL_GUEST_SPECIFIC|PATMFL_IDTHANDLER|PATMFL_INTHANDLER|PATMFL_TRAMPOLINE)))
     
    39473945        return VERR_PATCHING_REFUSED;
    39483946
     3947#ifdef VBOX_STRICT
     3948    PCPUMCTX pCtx = 0;
     3949
     3950    CPUMQueryGuestCtxPtr(pVM, &pCtx);
     3951
     3952    if (    !pCtx->eflags.Bits.u1VM
     3953        &&  (pCtx->ss & X86_SEL_RPL) == 0)
     3954    {
     3955        RTGCPTR pInstrGCFlat = SELMToFlat(pVM, pCtx->cs, &pCtx->csHid, pInstrGC);
     3956        Assert(pInstrGCFlat == pInstrGC);
     3957    }
     3958#endif
     3959
    39493960    /** @note the OpenBSD specific check will break if we allow additional patches to be installed (int 3)) */
    39503961    if (!(flags & PATMFL_GUEST_SPECIFIC))
    39513962    {
    39523963        /* New code. Make sure CSAM has a go at it first. */
    3953         CSAMR3CheckCode(pVM, pCtx, pInstrGC);
     3964        CSAMR3CheckCode(pVM, pInstrGC);
    39543965    }
    39553966
  • trunk/src/VBox/VMM/PATM/PATMA.asm

    r744 r1086  
    4141; Noisy, but useful for debugging certain problems
    4242;;;%define PATM_LOG_PATCHINSTR
     43%define PATM_LOG_PATCHIRET
    4344%endif
    4445
     
    378379; Trampoline code for trap entry (without error code on the stack)
    379380;
     381; esp + 32 - GS         (V86 only)
     382; esp + 28 - FS         (V86 only)
     383; esp + 24 - DS         (V86 only)
     384; esp + 20 - ES         (V86 only)
    380385; esp + 16 - SS         (if transfer to inner ring)
    381386; esp + 12 - ESP        (if transfer to inner ring)
     
    388393    mov     dword [ss:PATM_INTERRUPTFLAG], 0
    389394    pushf
     395
     396    test    dword [esp+12], X86_EFL_VM
     397    jnz     PATMTrapNoRing1
    390398
    391399    ; make sure the saved CS selector for ring 1 is made 0
     
    433441; Trampoline code for trap entry (with error code on the stack)
    434442;
     443; esp + 36 - GS         (V86 only)
     444; esp + 32 - FS         (V86 only)
     445; esp + 28 - DS         (V86 only)
     446; esp + 24 - ES         (V86 only)
    435447; esp + 20 - SS         (if transfer to inner ring)
    436448; esp + 16 - ESP        (if transfer to inner ring)
     
    444456    mov     dword [ss:PATM_INTERRUPTFLAG], 0
    445457    pushf
     458
     459    test    dword [esp+16], X86_EFL_VM
     460    jnz     PATMTrapErrorCodeNoRing1
    446461
    447462    ; make sure the saved CS selector for ring 1 is made 0
     
    490505; Trampoline code for interrupt gate entry (without error code on the stack)
    491506;
     507; esp + 32 - GS         (V86 only)
     508; esp + 28 - FS         (V86 only)
     509; esp + 24 - DS         (V86 only)
     510; esp + 20 - ES         (V86 only)
    492511; esp + 16 - SS         (if transfer to inner ring)
    493512; esp + 12 - ESP        (if transfer to inner ring)
     
    500519    mov     dword [ss:PATM_INTERRUPTFLAG], 0
    501520    pushf
     521
     522    test    dword [esp+12], X86_EFL_VM
     523    jnz     PATMIntNoRing1
    502524
    503525    ; make sure the saved CS selector for ring 1 is made 0
     
    542564; Trampoline code for interrupt gate entry (*with* error code on the stack)
    543565;
     566; esp + 36 - GS         (V86 only)
     567; esp + 32 - FS         (V86 only)
     568; esp + 28 - DS         (V86 only)
     569; esp + 24 - ES         (V86 only)
    544570; esp + 20 - SS         (if transfer to inner ring)
    545571; esp + 16 - ESP        (if transfer to inner ring)
     
    553579    mov     dword [ss:PATM_INTERRUPTFLAG], 0
    554580    pushf
     581
     582    test    dword [esp+16], X86_EFL_VM
     583    jnz     PATMIntNoRing1_ErrorCode
    555584
    556585    ; make sure the saved CS selector for ring 1 is made 0
     
    10701099    pushfd
    10711100
    1072 %ifdef PATM_LOG_PATCHINSTR
     1101%ifdef PATM_LOG_PATCHIRET
    10731102    push    eax
    10741103    push    ecx
     
    10851114
    10861115    test    dword [esp], X86_EFL_NT
    1087     jnz near iret_fault1
     1116    jnz     iret_fault1
    10881117
    10891118    test    dword [esp+12], X86_EFL_VM
    1090     jnz near iret_fault
     1119    jnz     iret_notring0
    10911120
    10921121    ;;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
     
    10981127
    10991128    test    dword [esp+12], X86_EFL_IF
    1100     jz near iret_clearIF
     1129    jz     iret_clearIF
    11011130
    11021131    ; if interrupts are pending, then we must go back to the host context to handle them!
     
    12171246    DD      0
    12181247    DD      PATMIretEnd- PATMIretStart
    1219 %ifdef PATM_LOG_PATCHINSTR
     1248%ifdef PATM_LOG_PATCHIRET
    12201249    DD      22
    12211250%else
     
    12241253    DD      PATM_INTERRUPTFLAG
    12251254    DD      0
    1226 %ifdef PATM_LOG_PATCHINSTR
     1255%ifdef PATM_LOG_PATCHIRET
    12271256    DD      PATM_PENDINGACTION
    12281257    DD      0
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