VirtualBox

Changeset 1328 in vbox for trunk/src


Ignore:
Timestamp:
Mar 8, 2007 1:02:08 PM (18 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
19296
Message:

Reorganized TRPM in preparation of handling IDT writes in the guest context.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/TRPM.cpp

    r1325 r1328  
    9696    TRPM_HANDLER_MAX
    9797} TRPMHANDLER, *PTRPMHANDLER;
    98 
    99 /** First interrupt handler. Used for validating input. */
    100 #define TRPM_HANDLER_INT_BASE  0x20
    10198
    10299
     
    423420static DECLCALLBACK(int) trpmR3Load(PVM pVM, PSSMHANDLE pSSM, uint32_t u32Version);
    424421static DECLCALLBACK(int) trpmGuestIDTWriteHandler(PVM pVM, RTGCPTR GCPtr, void *pvPtr, void *pvBuf, size_t cbBuf, PGMACCESSTYPE enmAccessType, void *pvUser);
    425 static int               trpmR3ClearGuestTrapHandler(PVM pVM, unsigned iTrap);
    426422
    427423
     
    471467     * Statistics.
    472468     */
    473     STAM_REG(pVM, &pVM->trpm.s.StatGCWriteGuestIDT,     STAMTYPE_COUNTER, "/TRPM/GC/Write/Guest/IDT",   STAMUNIT_OCCURENCES,     "The number of writes to the Guest IDT.");
     469    STAM_REG(pVM, &pVM->trpm.s.StatGCWriteGuestIDTFault,   STAMTYPE_COUNTER, "/TRPM/GC/Write/IDT/Fault",   STAMUNIT_OCCURENCES,     "The number of writes to the Guest IDT.");
     470    STAM_REG(pVM, &pVM->trpm.s.StatGCWriteGuestIDTHandled, STAMTYPE_COUNTER, "/TRPM/GC/Write/IDT/Handled", STAMUNIT_OCCURENCES,     "The number of writes to the Guest IDT.");
    474471
    475472    STAM_REG(pVM, &pVM->trpm.s.StatSyncIDT,             STAMTYPE_PROFILE, "/PROF/TRPM/SyncIDT",         STAMUNIT_TICKS_PER_CALL, "Profiling of TRPMR3SyncIDT().");
     
    872869        /** @todo inefficient, but simple */
    873870        for (unsigned iGate=0;iGate<256;iGate++)
    874             trpmR3ClearGuestTrapHandler(pVM, iGate);
     871            trpmClearGuestTrapHandler(pVM, iGate);
    875872
    876873        /* Scan them all (only the first time) */
     
    11051102
    11061103/**
    1107  * Clear guest trap/interrupt gate handler
    1108  *
    1109  * @returns VBox status code.
    1110  * @param   pVM         The VM to operate on.
    1111  * @param   iTrap       Interrupt/trap number.
    1112  */
    1113 static int trpmR3ClearGuestTrapHandler(PVM pVM, unsigned iTrap)
    1114 {
    1115     /*
    1116      * Validate.
    1117      */
    1118     if (iTrap >= ELEMENTS(pVM->trpm.s.aIdt))
    1119     {
    1120         AssertMsg(iTrap < TRPM_HANDLER_INT_BASE, ("Illegal gate number %d!\n", iTrap));
    1121         return VERR_INVALID_PARAMETER;
    1122     }
    1123 
    1124     if (ASMBitTest(&pVM->trpm.s.au32IdtPatched[0], iTrap))
    1125         trpmR3ClearPassThroughHandler(pVM, iTrap);
    1126 
    1127     pVM->trpm.s.aGuestTrapHandler[iTrap] = TRPM_INVALID_HANDLER;
    1128     return VINF_SUCCESS;
    1129 }
    1130 
    1131 /**
    11321104 * Set guest trap/interrupt gate handler
    11331105 * Used for setting up trap gates used for kernel calls.
     
    11601132        /* clear trap handler */
    11611133        Log(("TRPMR3SetGuestTrapHandler: clear handler %x\n", iTrap));
    1162         return trpmR3ClearGuestTrapHandler(pVM, iTrap);
     1134        return trpmClearGuestTrapHandler(pVM, iTrap);
    11631135    }
    11641136
  • trunk/src/VBox/VMM/TRPMInternal.h

    r1283 r1328  
    3535/* Enable to allow trap forwarding in GC. */
    3636#define TRPM_FORWARD_TRAPS_IN_GC
     37
     38/** First interrupt handler. Used for validating input. */
     39#define TRPM_HANDLER_INT_BASE  0x20
    3740
    3841__BEGIN_DECLS
     
    146149
    147150    /** GC: The number of times writes to the Guest IDT were detected. */
    148     STAMCOUNTER     StatGCWriteGuestIDT;
     151    STAMCOUNTER     StatGCWriteGuestIDTFault;
     152    STAMCOUNTER     StatGCWriteGuestIDTHandled;
     153
    149154    /** HC: Profiling of the TRPMR3SyncIDT() method. */
    150155    STAMPROFILE     StatSyncIDT;
     
    176181TRPMGCDECL(int) trpmgcShadowIDTWriteHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, void *pvFault, void *pvRange, uintptr_t offRange);
    177182
     183/**
     184 * Clear guest trap/interrupt gate handler
     185 *
     186 * @returns VBox status code.
     187 * @param   pVM         The VM to operate on.
     188 * @param   iTrap       Interrupt/trap number.
     189 */
     190TRPMDECL(int) trpmClearGuestTrapHandler(PVM pVM, unsigned iTrap);
     191
    178192
    179193#ifdef IN_RING3
     194
     195/**
     196 * Clear passthrough interrupt gate handler (reset to default handler)
     197 *
     198 * @returns VBox status code.
     199 * @param   pVM         The VM to operate on.
     200 * @param   iTrap       Trap/interrupt gate number.
     201 */
     202TRPMR3DECL(int) trpmR3ClearPassThroughHandler(PVM pVM, unsigned iTrap);
    180203
    181204#endif
  • trunk/src/VBox/VMM/TRPMInternal.mac

    r716 r1328  
    5555    .aGuestTrapHandler  resd 256
    5656
    57     .StatGCWriteGuestIDT  resb STAMCOUNTER_size
     57    .StatGCWriteGuestIDTFault  resb STAMCOUNTER_size
     58    .StatGCWriteGuestIDTHandled  resb STAMCOUNTER_size
    5859    .StatSyncIDT        resb STAMPROFILE_size
    5960    .aStatGCTraps       resb STAMPROFILEADV_size * 0x14
  • trunk/src/VBox/VMM/VMMAll/TRPMAll.cpp

    r1326 r1328  
    821821}
    822822
     823
     824/**
     825 * Clear guest trap/interrupt gate handler
     826 *
     827 * @returns VBox status code.
     828 * @param   pVM         The VM to operate on.
     829 * @param   iTrap       Interrupt/trap number.
     830 */
     831TRPMDECL(int) trpmClearGuestTrapHandler(PVM pVM, unsigned iTrap)
     832{
     833    /*
     834     * Validate.
     835     */
     836    if (iTrap >= ELEMENTS(pVM->trpm.s.aIdt))
     837    {
     838        AssertMsg(iTrap < TRPM_HANDLER_INT_BASE, ("Illegal gate number %d!\n", iTrap));
     839        return VERR_INVALID_PARAMETER;
     840    }
     841
     842    if (ASMBitTest(&pVM->trpm.s.au32IdtPatched[0], iTrap))
     843#ifdef IN_RING3
     844        trpmR3ClearPassThroughHandler(pVM, iTrap);
     845#else
     846        AssertFailed();
     847#endif
     848
     849    pVM->trpm.s.aGuestTrapHandler[iTrap] = TRPM_INVALID_HANDLER;
     850    return VINF_SUCCESS;
     851}
     852
     853
  • trunk/src/VBox/VMM/VMMGC/TRPMGC.cpp

    r1327 r1328  
    3333#include <VBox/err.h>
    3434#include <VBox/x86.h>
     35#include <VBox/em.h>
    3536#include <iprt/assert.h>
    3637#include <iprt/asm.h>
     
    109110#ifdef VBOX_STRICT
    110111    RTGCPTR     GCPtrIDTEnd = (RTGCPTR)((RTGCUINTPTR)GCPtrIDT + cbIDT + 1);
     112#endif
    111113    uint32_t    iTrap       = ((RTGCUINTPTR)pvFault - (RTGCUINTPTR)GCPtrIDT)/sizeof(VBOXIDTE);
    112 #endif
    113114
    114115    Assert(pvFault >= GCPtrIDT && pvFault < GCPtrIDTEnd);
    115116    Log(("trpmgcGuestIDTWriteHandler: write to gate %x\n", iTrap));
    116117
    117     ////LogCom(("trpmgcGuestIDTWriteHandler: eip=%08X pvFault=%08X pvRange=%08X\r\n", pRegFrame->eip, pvFault, pvRange));
     118#if 0
     119    /* Check if we can handle the write here. */   
     120    if (     iTrap != 3                                         /* Gate 3 is handled differently; could do it here as well, but let ring 3 handle this case for now. */
     121        &&  !ASMBitTest(&pVM->trpm.s.au32IdtPatched[0], iTrap)) /* Passthru gates need special attention too. */
     122    {
     123        uint32_t cb;
     124        int rc = EMInterpretInstruction(pVM, pRegFrame, pvFault, &cb);
     125        if (VBOX_SUCCESS(rc) && cb)
     126        {
     127            trpmClearGuestTrapHandler(pVM, iTrap);
     128            STAM_COUNTER_INC(&pVM->trpm.s.StatGCWriteGuestIDTHandled);
     129            return VINF_SUCCESS;
     130        }
     131    }
     132#endif
     133
     134    /** @todo Check which IDT entry and keep the update cost low in TRPMR3SyncIDT() and CSAMCheckGates(). */
    118135    VM_FF_SET(pVM, VM_FF_TRPM_SYNC_IDT);
    119     /** @todo Check which IDT entry and keep the update cost low in TRPMR3SyncIDT() and CSAMCheckGates(). */
    120136
    121     STAM_COUNTER_INC(&pVM->trpm.s.StatGCWriteGuestIDT);
     137    STAM_COUNTER_INC(&pVM->trpm.s.StatGCWriteGuestIDTFault);
    122138    return VINF_EM_RAW_EMULATE_INSTR_IDT_FAULT;
    123139}
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette