VirtualBox

Changeset 97943 in vbox for trunk/src/VBox/Additions/common


Ignore:
Timestamp:
Jan 2, 2023 4:50:43 PM (2 years ago)
Author:
vboxsync
Message:

Add/VBoxGuestR0LibPhysHeap.cpp: Made it possible to use RTR0MemObjFree instead of RTMemContFree (disabled everywhere).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR0LibPhysHeap.cpp

    r97940 r97943  
    6262#include <iprt/err.h>
    6363#include <iprt/mem.h>
     64#include <iprt/memobj.h>
    6465#include <iprt/semaphore.h>
    6566
     
    146147                                                    - VBGL_PH_ALLOC_ALIGN, \
    147148                                                    VBGL_PH_ALLOC_ALIGN)
     149
     150/**
     151 * Whether to use the RTR0MemObjAllocCont API or RTMemContAlloc for
     152 * allocating chunks.
     153 *
     154 * This can be enabled on hosts where RTMemContAlloc is more complicated than
     155 * RTR0MemObjAllocCont.  This can also be done if we wish to save code space, as
     156 * the latter is typically always dragged into the link on guests where the
     157 * linker cannot eliminiate functions within objects.  Only drawback is that
     158 * RTR0MemObjAllocCont requires another heap allocation for the handle.
     159 */
     160#if defined(DOXYGEN_RUNNING) || (!defined(IN_TESTCASE) && 0)
     161# define VBGL_PH_USE_MEMOBJ
     162#endif
    148163
    149164
     
    207222    uint32_t physAddr;
    208223
     224#if !defined(VBGL_PH_USE_MEMOBJ) || ARCH_BITS != 32
    209225    uint32_t uPadding1;
     226#endif
    210227
    211228    /** Number of block of any kind. */
     
    218235    /** Pointer to the previous chunk. */
    219236    VBGLPHYSHEAPCHUNK  *pPrev;
     237
     238#if defined(VBGL_PH_USE_MEMOBJ)
     239    /** The allocation handle. */
     240    RTR0MEMOBJ          hMemObj;
     241#endif
     242
    220243#if ARCH_BITS == 64
    221244    /** Pad the size up to 64 bytes. */
     245# ifdef VBGL_PH_USE_MEMOBJ
     246    uintptr_t           auPadding2[2];
     247# else
    222248    uintptr_t           auPadding2[3];
     249# endif
    223250#endif
    224251};
     
    486513static VBGLPHYSHEAPFREEBLOCK *vbglPhysHeapChunkAlloc(uint32_t cbMinBlock)
    487514{
    488     RTCCPHYS           PhysAddr = NIL_RTHCPHYS;
    489     VBGLPHYSHEAPCHUNK *pChunk;
    490     uint32_t           cbChunk;
     515    RTCCPHYS            PhysAddr = NIL_RTHCPHYS;
     516    VBGLPHYSHEAPCHUNK  *pChunk;
     517    uint32_t            cbChunk;
     518#ifdef VBGL_PH_USE_MEMOBJ
     519    RTR0MEMOBJ          hMemObj = NIL_RTR0MEMOBJ;
     520    int                 rc;
     521#endif
     522
    491523    VBGL_PH_DPRINTF(("Allocating new chunk for %#x byte allocation\n", cbMinBlock));
    492524    AssertReturn(cbMinBlock <= VBGL_PH_LARGEST_ALLOC_SIZE, NULL); /* paranoia */
     
    509541     * physical address to the host.
    510542     */
     543#ifdef VBGL_PH_USE_MEMOBJ
     544    rc = RTR0MemObjAllocCont(&hMemObj, cbChunk, false /*fExecutable*/);
     545    pChunk = (VBGLPHYSHEAPCHUNK *)(RT_SUCCESS(rc) ? RTR0MemObjAddress(hMemObj) : NULL);
     546#else
    511547    pChunk = (VBGLPHYSHEAPCHUNK *)RTMemContAlloc(&PhysAddr, cbChunk);
     548#endif
    512549    if (!pChunk)
    513550    {
     
    520557                cbChunk >>= 2;
    521558                cbChunk = RT_ALIGN_32(cbChunk, PAGE_SIZE);
     559#ifdef VBGL_PH_USE_MEMOBJ
     560                rc = RTR0MemObjAllocCont(&hMemObj, cbChunk, false /*fExecutable*/);
     561                pChunk = (VBGLPHYSHEAPCHUNK *)(RT_SUCCESS(rc) ? RTR0MemObjAddress(hMemObj) : NULL);
     562#else
    522563                pChunk = (VBGLPHYSHEAPCHUNK *)RTMemContAlloc(&PhysAddr, cbChunk);
     564#endif
    523565            } while (!pChunk && cbChunk > cbMinChunk);
    524566    }
     
    539581        pChunk->pNext            = NULL;
    540582        pChunk->pPrev            = NULL;
     583#ifdef VBGL_PH_USE_MEMOBJ
     584        pChunk->hMemObj          = hMemObj;
     585#endif
     586
     587        /* Initialize the padding too: */
     588#if !defined(VBGL_PH_USE_MEMOBJ) || ARCH_BITS != 32
    541589        pChunk->uPadding1        = UINT32_C(0xADDCAAA1);
     590#endif
    542591#if ARCH_BITS == 64
    543592        pChunk->auPadding2[0]    = UINT64_C(0xADDCAAA3ADDCAAA2);
    544593        pChunk->auPadding2[1]    = UINT64_C(0xADDCAAA5ADDCAAA4);
     594# ifndef VBGL_PH_USE_MEMOBJ
    545595        pChunk->auPadding2[2]    = UINT64_C(0xADDCAAA7ADDCAAA6);
     596# endif
    546597#endif
    547598
     
    627678     * Finally, free the chunk memory.
    628679     */
     680#ifdef VBGL_PH_USE_MEMOBJ
     681    RTR0MemObjFree(pChunk->hMemObj, true /*fFreeMappings*/);
     682#else
    629683    RTMemContFree(pChunk, pChunk->cbChunk);
     684#endif
    630685}
    631686
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