VirtualBox

Ignore:
Timestamp:
Sep 18, 2023 11:12:16 AM (16 months ago)
Author:
vboxsync
Message:

IPRT/mem: Added a RTMEMPAGEALLOC_F_EXECUTABLE to RTMemPageAllocEx. Untested on windows. bugref:10370

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/posix/rtmempage-exec-mmap-heap-posix.cpp

    r99779 r101142  
    550550
    551551/**
    552  * Allocates one or more pages off the heap.
     552 * Frees an allocation.
    553553 *
    554554 * @returns IPRT status code.
     555 * @retval  VERR_NOT_FOUND if pv isn't within any of the memory blocks in the
     556 *          heap.
     557 * @retval  VERR_INVALID_POINTER if the given memory range isn't exactly one
     558 *          allocation block.
    555559 * @param   pHeap           The page heap.
    556560 * @param   pv              Pointer to what RTHeapPageAlloc returned.
     
    652656        }
    653657        else
    654             rc = VERR_INVALID_POINTER;
     658            rc = VERR_NOT_FOUND; /* Distinct return code for this so rtMemPagePosixFree and others can try alternative heaps. */
    655659
    656660        RTCritSectLeave(&pHeap->CritSect);
     
    737741 * Free memory allocated by rtMemPagePosixAlloc.
    738742 *
    739  * @param   pv                  The address of the memory to free.
    740  * @param   cb                  The size.
    741  * @param   pHeap               The heap.
    742  */
    743 static void rtMemPagePosixFree(void *pv, size_t cb, PRTHEAPPAGE pHeap)
     743 * @param   pv      The address of the memory to free.
     744 * @param   cb      The size.
     745 * @param   pHeap1  The most probable heap.
     746 * @param   pHeap2  The less probable heap.
     747 */
     748static void rtMemPagePosixFree(void *pv, size_t cb, PRTHEAPPAGE pHeap1, PRTHEAPPAGE pHeap2)
    744749{
    745750    /*
     
    763768    else
    764769    {
    765         int rc = RTHeapPageFree(pHeap, pv, cb >> PAGE_SHIFT);
     770        int rc = RTHeapPageFree(pHeap1, pv, cb >> PAGE_SHIFT);
     771        if (rc == VERR_NOT_FOUND)
     772            rc = RTHeapPageFree(pHeap2, pv, cb >> PAGE_SHIFT);
    766773        AssertRC(rc);
    767774    }
     
    787794{
    788795    AssertReturn(!(fFlags & ~RTMEMPAGEALLOC_F_VALID_MASK), NULL);
    789     return rtMemPagePosixAlloc(cb, pszTag, fFlags, &g_MemPagePosixHeap);
     796    return rtMemPagePosixAlloc(cb, pszTag, fFlags,
     797                               !(fFlags & RTMEMPAGEALLOC_F_EXECUTABLE) ? &g_MemPagePosixHeap : &g_MemExecPosixHeap);
    790798}
    791799
     
    793801RTDECL(void) RTMemPageFree(void *pv, size_t cb) RT_NO_THROW_DEF
    794802{
    795     return rtMemPagePosixFree(pv, cb, &g_MemPagePosixHeap);
    796 }
    797 
     803    rtMemPagePosixFree(pv, cb, &g_MemPagePosixHeap, &g_MemExecPosixHeap);
     804}
     805
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