VirtualBox

Changeset 104123 in vbox


Ignore:
Timestamp:
Mar 30, 2024 1:12:57 AM (8 months ago)
Author:
vboxsync
Message:

VMM/IEM: Avoid the two RTMemProtect calls in iemExecMemAllocatorFree on darwin. bugref:10370

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

Legend:

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

    r104116 r104123  
    373373    AssertReturnVoid(cChunks >= 1);
    374374
     375    Assert(!pVCpu->iem.s.pCurTbR3);
     376
    375377    /*
    376378     * Decide how much to prune.  The chunk is is a multiple of two, so we'll be
     
    424426            PIEMTB const pTb = pHdr->pTb;
    425427            AssertPtr(pTb);
    426             Assert((pTb->fFlags & IEMTB_F_TYPE_MASK) == IEMTB_F_TYPE_NATIVE);
    427 
    428             uint32_t const cbBlock = RT_ALIGN_32(pTb->Native.cInstructions * sizeof(IEMNATIVEINSTR) + sizeof(*pHdr),
    429                                                  IEMEXECMEM_ALT_SUB_ALLOC_UNIT_SIZE);
    430             AssertBreakStmt(offChunk + cbBlock <= cbChunk, offChunk += IEMEXECMEM_ALT_SUB_ALLOC_UNIT_SIZE); /* paranoia */
    431 
    432             iemTbAllocatorFree(pVCpu, pTb);
    433 
    434             cbPruned += cbBlock;
    435             offChunk += cbBlock;
     428
     429            /* We now have to check that this isn't a old freed header, given
     430               that we don't invalidate the header upon free because of darwin
     431               restrictions on executable memory (iemExecMemAllocatorFree).
     432               This relies upon iemTbAllocatorFreeInner resetting TB members. */
     433            if (   pTb->Native.paInstructions == (PIEMNATIVEINSTR)(pHdr + 1)
     434                && (pTb->fFlags & IEMTB_F_TYPE_MASK) == IEMTB_F_TYPE_NATIVE)
     435            {
     436                uint32_t const cbBlock = RT_ALIGN_32(pTb->Native.cInstructions * sizeof(IEMNATIVEINSTR) + sizeof(*pHdr),
     437                                                     IEMEXECMEM_ALT_SUB_ALLOC_UNIT_SIZE);
     438                AssertBreakStmt(offChunk + cbBlock <= cbChunk, offChunk += IEMEXECMEM_ALT_SUB_ALLOC_UNIT_SIZE); /* paranoia */
     439
     440                iemTbAllocatorFree(pVCpu, pTb);
     441
     442                cbPruned += cbBlock;
     443                offChunk += cbBlock;
     444            }
     445            else
     446                offChunk += IEMEXECMEM_ALT_SUB_ALLOC_UNIT_SIZE;
    436447        }
    437448        else
     
    713724            ASMBitClearRange(pbmAlloc, idxFirst, idxFirst + cReqUnits);
    714725
    715 #ifdef IEMEXECMEM_ALT_SUB_WITH_ALLOC_HEADER
     726#if 0 /*def IEMEXECMEM_ALT_SUB_WITH_ALLOC_HEADER - not necessary, we'll validate the header in the pruning code. */
    716727# ifdef RT_OS_DARWIN
    717728            int rc = RTMemProtect(pHdr, sizeof(*pHdr), RTMEM_PROT_WRITE | RTMEM_PROT_READ);
  • trunk/src/VBox/VMM/VMMAll/IEMAllThrdRecompiler.cpp

    r104114 r104123  
    885885            iemExecMemAllocatorFree(pVCpu, pTb->Native.paInstructions,
    886886                                    pTb->Native.cInstructions * sizeof(pTb->Native.paInstructions[0]));
     887            pVCpu, pTb->Native.paInstructions = NULL; /* required by iemExecMemAllocatorPrune */
    887888            break;
    888889#endif
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