VirtualBox

Changeset 97904 in vbox


Ignore:
Timestamp:
Dec 29, 2022 6:14:03 PM (2 years ago)
Author:
vboxsync
Message:

IPRT/r3/allocex: Implement RTMEMALLOCEX_FLAGS_EXEC using RTMemPageAlloc+RTMemProtect instead of RTMemExecAlloc.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/allocex.cpp

    r96407 r97904  
    9292    else if (fFlags & RTMEMALLOCEX_FLAGS_EXEC)
    9393    {
    94         pv = RTMemExecAlloc(cbAligned + sizeof(RTMEMHDRR3));
    95         if ((fFlags & RTMEMALLOCEX_FLAGS_ZEROED) && pv)
    96             RT_BZERO(pv, cbAligned + sizeof(RTMEMHDRR3));
     94        pv = RTMemPageAlloc(cbAligned + sizeof(RTMEMHDRR3));
     95        if (pv)
     96        {
     97            if (fFlags & RTMEMALLOCEX_FLAGS_ZEROED)
     98                RT_BZERO(pv, cbAligned + sizeof(RTMEMHDRR3));
     99
     100            int rc = RTMemProtect(pv, cbAligned + sizeof(RTMEMHDRR3), RTMEM_PROT_EXEC | RTMEM_PROT_READ | RTMEM_PROT_WRITE);
     101            if (RT_FAILURE(rc))
     102            {
     103                RTMemPageFree(pv, cbAligned + sizeof(RTMEMHDRR3));
     104                return rc;
     105            }
     106        }
    97107    }
    98108    else if (fFlags & RTMEMALLOCEX_FLAGS_ZEROED)
     
    132142        rtMemFreeExYyBitReach(pHdr, pHdr->cb + sizeof(*pHdr), pHdr->fFlags);
    133143    else if (pHdr->fFlags & RTMEMALLOCEX_FLAGS_EXEC)
    134         RTMemExecFree(pHdr, pHdr->cb + sizeof(*pHdr));
     144    {
     145        RTMemProtect(pHdr, pHdr->cb + sizeof(*pHdr), RTMEM_PROT_READ | RTMEM_PROT_WRITE);
     146        RTMemPageFree(pHdr, pHdr->cb + sizeof(*pHdr));
     147    }
    135148    else
    136149        RTMemFree(pHdr);
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