VirtualBox

Changeset 100149 in vbox for trunk/src/VBox/VMM/VMMAll


Ignore:
Timestamp:
Jun 10, 2023 8:49:28 PM (21 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
157844
Message:

VMM/IEM: Emit extra mode-check after CIMPL calls with the IEM_CIMPL_F_MODE or IEM_CIMPL_F_XCPT flags set. bugref:10369

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMAll/IEMAllThreadedFunctions.cpp

    r100148 r100149  
    595595
    596596
     597/**
     598 * Built-in function that compares the fExec mask against uParam0.
     599 */
     600static IEM_DECL_IMPL_DEF(VBOXSTRICTRC, iemThreadedFunc_BltIn_CheckMode,
     601                         (PVMCPU pVCpu, uint64_t uParam0, uint64_t uParam1, uint64_t uParam2))
     602{
     603    uint32_t const fExpectedExec = (uint32_t)uParam0;
     604    if (pVCpu->iem.s.fExec == fExpectedExec)
     605        return VINF_SUCCESS;
     606    Log12(("Mode changed at %04x:%08RX64: %#x -> %#x (xor: %#x)\n", pVCpu->cpum.GstCtx.cs.Sel, pVCpu->cpum.GstCtx.rip,
     607           fExpectedExec, pVCpu->iem.s.fExec, fExpectedExec ^ pVCpu->iem.s.fExec));
     608    RT_NOREF(uParam1, uParam2);
     609    return VINF_IEM_REEXEC_MODE_CHANGED;
     610}
     611
    597612/*
    598613 * The threaded functions.
  • trunk/src/VBox/VMM/VMMAll/IEMAllThreadedPython.py

    r100148 r100149  
    196196    ## @}
    197197
     198    ## IEM_CIMPL_F_XXX flags that we know.
     199    kdCImplFlags = {
     200        'IEM_CIMPL_F_MODE':             True,
     201        'IEM_CIMPL_F_BRANCH':           False,
     202        'IEM_CIMPL_F_RFLAGS':           False,
     203        'IEM_CIMPL_F_STATUS_FLAGS':     False,
     204        'IEM_CIMPL_F_VMEXIT':           False,
     205        'IEM_CIMPL_F_FPU':              False,
     206        'IEM_CIMPL_F_REP':              False,
     207        'IEM_CIMPL_F_END_TB':           False,
     208        'IEM_CIMPL_F_XCPT':             True,
     209    };
     210
    198211    def __init__(self, oThreadedFunction, sVariation = ksVariation_Default):
    199212        self.oParent        = oThreadedFunction # type: ThreadedFunction
     
    210223        ## List/tree of statements for the threaded function.
    211224        self.aoStmtsForThreadedFunction = [] # type: list(McStmt)
     225
     226        ## Dictionary with any IEM_CIMPL_F_XXX flags associated to the code block.
     227        self.dsCImplFlags   = { }           # type: dict(str, bool)
    212228
    213229        ## Function enum number, for verification. Set by generateThreadedFunctionsHeader.
     
    464480        return (aoThreadedStmts, iParamRef);
    465481
     482    def analyzeCodeOperation(self, aoStmts):
     483        """
     484        Analyzes the code looking clues as to additional side-effects.
     485
     486        Currently this is simply looking for any IEM_IMPL_C_F_XXX flags and
     487        collecting these in self.dsCImplFlags.
     488        """
     489        for oStmt in aoStmts:
     490            if oStmt.sName.startswith('IEM_MC_CALL_CIMPL_') or oStmt.sName.startswith('IEM_MC_DEFER_TO_CIMPL_'):
     491                sFlagsSansComments = iai.McBlock.stripComments(oStmt.asParams[0]);
     492                for sFlag in sFlagsSansComments.split('|'):
     493                    sFlag = sFlag.strip();
     494                    if sFlag != '0':
     495                        if sFlag in self.kdCImplFlags:
     496                            self.dsCImplFlags[sFlag] = True;
     497                        else:
     498                            self.raiseProblem('Unknown CIMPL flag value: %s' % (sFlag,));
     499
     500            # Process branches of conditionals recursively.
     501            if isinstance(oStmt, iai.McStmtCond):
     502                self.analyzeCodeOperation(oStmt.aoIfBranch);
     503                if oStmt.aoElseBranch:
     504                    self.analyzeCodeOperation(oStmt.aoElseBranch);
     505
     506        return True;
     507
     508
    466509    def analyzeConsolidateThreadedParamRefs(self):
    467510        """
     
    543586    ksHexDigits = '0123456789abcdefABCDEF';
    544587
    545     def analyzeFindThreadedParamRefs(self, aoStmts):
     588    def analyzeFindThreadedParamRefs(self, aoStmts): # pylint: disable=too-many-statements
    546589        """
    547590        Scans the statements for things that have to passed on to the threaded
     
    777820        self.analyzeConsolidateThreadedParamRefs();
    778821
     822        # Scan the code for IEM_CIMPL_F_ and other clues.
     823        self.analyzeCodeOperation(aoStmts);
     824
    779825        # Morph the statement stream for the block into what we'll be using in the threaded function.
    780826        (self.aoStmtsForThreadedFunction, iParamRef) = self.analyzeMorphStmtForThreaded(aoStmts);
     
    786832    def emitThreadedCallStmts(self, cchIndent):
    787833        """
    788         Produces a generic C++ statment that emits a call to the thread function variation.
    789         """
     834        Produces generic C++ statments that emits a call to the thread function
     835        variation and any subsequent checks that may be necessary after that.
     836        """
     837        # The call to the threaded function.
    790838        sCode = 'IEM_MC2_EMIT_CALL_%s(%s' % (self.cMinParams, self.getIndexName(), );
    791839        for iParam in range(self.cMinParams):
     
    801849            sCode += ', ' + ' | '.join(asFrags);
    802850        sCode += ');';
    803         return [iai.McCppGeneric(sCode, cchIndent = cchIndent),];
     851        aoStmts = [ iai.McCppGeneric(sCode, cchIndent = cchIndent), ];
     852
     853        # For CIMPL stuff, we need to consult the associated IEM_CIMPL_F_XXX
     854        # mask and maybe emit additional checks.
     855        if 'IEM_CIMPL_F_MODE' in self.dsCImplFlags or 'IEM_CIMPL_F_XCPT' in self.dsCImplFlags:
     856            aoStmts.append(iai.McCppGeneric('IEM_MC2_EMIT_CALL_1(kIemThreadedFunc_CheckMode, pVCpu->iem.s.fExec);',
     857                                            cchIndent = cchIndent));
     858
     859        return aoStmts;
    804860
    805861
     
    11391195            '{',
    11401196            '    kIemThreadedFunc_Invalid = 0,',
     1197            '',
     1198            '    /*'
     1199            '     * Predefined'
     1200            '     */'
     1201            '    kIemThreadedFunc_CheckMode,',
    11411202        ];
    1142         iThreadedFunction = 0;
     1203        iThreadedFunction = 1;
    11431204        for sVariation in ThreadedFunctionVariation.kasVariationsEmitOrder:
    11441205            asLines += [
     
    12881349                   + 'const PFNIEMTHREADEDFUNC g_apfnIemThreadedFunctions[kIemThreadedFunc_End] =\n'
    12891350                   + '{\n'
    1290                    + '    /*Invalid*/ NULL, \n');
    1291         iThreadedFunction = 0;
     1351                   + '    /*Invalid*/ NULL,\n'
     1352                   + '\n'
     1353                   + '    /*\n'
     1354                   + '     * Predefined.\n'
     1355                   + '     */'
     1356                   + '    iemThreadedFunc_BltIn_CheckMode,\n'
     1357                   );
     1358        iThreadedFunction = 1;
    12921359        for sVariation in ThreadedFunctionVariation.kasVariationsEmitOrder:
    12931360            oOut.write(  '\n'
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