VirtualBox

Ignore:
Timestamp:
Jul 4, 2023 7:00:26 AM (22 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
158087
Message:

Runtime/RTR0MemObj*: Add PhysHighest parameter to RTR0MemObjAllocCont to indicate the maximum allowed physical address for an allocation, bugref:10457 [second attempt]

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r0drv/darwin/memobj-r0drv-darwin.cpp

    r100356 r100357  
    885885
    886886
    887 DECLHIDDEN(int) rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable, const char *pszTag)
    888 {
     887/**
     888 * Translates the PhysHighest address into a mask.
     889 */
     890static mach_vm_address_t rtR0MemObjDarwinCalcPhysMask(RTHCPHYS PhysHighest, size_t uAlignment)
     891{
     892    if (PhysHighest == NIL_RTHCPHYS)
     893        return uAlignment <= PAGE_SIZE ? 0 : ~(mach_vm_address_t)(uAlignment - 1);
     894
     895    mach_vm_address_t PhysMask = ~(mach_vm_address_t)0;
     896    while (PhysMask > (PhysHighest | PAGE_OFFSET_MASK))
     897        PhysMask >>= 1;
     898    PhysMask &= ~(mach_vm_address_t)(uAlignment - 1);
     899
     900    return PhysMask;
     901}
     902
     903
     904DECLHIDDEN(int) rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest,
     905                                          bool fExecutable, const char *pszTag)
     906{
     907    mach_vm_address_t const PhysMask = rtR0MemObjDarwinCalcPhysMask(PhysHighest, PAGE_SIZE);
    889908    IPRT_DARWIN_SAVE_EFL_AC();
    890909
    891     int rc = rtR0MemObjNativeAllocWorker(ppMem, cb, fExecutable, true /* fContiguous */,
    892                                          ~(uint32_t)PAGE_OFFSET_MASK, _4G - PAGE_SIZE,
     910    int rc = rtR0MemObjNativeAllocWorker(ppMem, cb, fExecutable, true /* fContiguous */, PhysMask, PhysHighest,
    893911                                         RTR0MEMOBJTYPE_CONT, PAGE_SIZE, pszTag, false /*fOnKernelThread*/);
    894912
     
    898916     */
    899917    if (RT_FAILURE(rc) && cb <= PAGE_SIZE)
    900         rc = rtR0MemObjNativeAllocWorker(ppMem, cb + PAGE_SIZE, fExecutable, true /* fContiguous */,
    901                                          ~(uint32_t)PAGE_OFFSET_MASK, _4G - PAGE_SIZE,
     918        rc = rtR0MemObjNativeAllocWorker(ppMem, cb + PAGE_SIZE, fExecutable, true /* fContiguous */, PhysMask, PhysHighest,
    902919                                         RTR0MEMOBJTYPE_CONT, PAGE_SIZE, pszTag, false /*fOnKernelThread*/);
    903920    IPRT_DARWIN_RESTORE_EFL_AC();
     
    915932            return VERR_NOT_SUPPORTED;
    916933    }
     934    mach_vm_address_t const PhysMask = rtR0MemObjDarwinCalcPhysMask(PhysHighest, uAlignment);
    917935
    918936    IPRT_DARWIN_SAVE_EFL_AC();
     
    923941    int rc;
    924942    if (PhysHighest == NIL_RTHCPHYS)
    925         rc = rtR0MemObjNativeAllocWorker(ppMem, cb, false /* fExecutable */, true /* fContiguous */,
    926                                          uAlignment <= PAGE_SIZE ? 0 : ~(mach_vm_address_t)(uAlignment - 1) /* PhysMask*/,
    927                                          UINT64_MAX, RTR0MEMOBJTYPE_PHYS, uAlignment, pszTag, false /*fOnKernelThread*/);
     943        rc = rtR0MemObjNativeAllocWorker(ppMem, cb, false /* fExecutable */, true /* fContiguous */, PhysMask, UINT64_MAX,
     944                                         RTR0MEMOBJTYPE_PHYS, uAlignment, pszTag, false /*fOnKernelThread*/);
    928945    else
    929946    {
    930         mach_vm_address_t PhysMask = 0;
    931         PhysMask = ~(mach_vm_address_t)0;
    932         while (PhysMask > (PhysHighest | PAGE_OFFSET_MASK))
    933             PhysMask >>= 1;
    934947        AssertReturn(PhysMask + 1 <= cb, VERR_INVALID_PARAMETER);
    935         PhysMask &= ~(mach_vm_address_t)(uAlignment - 1);
    936 
    937         rc = rtR0MemObjNativeAllocWorker(ppMem, cb, false /* fExecutable */, true /* fContiguous */,
    938                                          PhysMask, PhysHighest,
     948        rc = rtR0MemObjNativeAllocWorker(ppMem, cb, false /* fExecutable */, true /* fContiguous */, PhysMask, PhysHighest,
    939949                                         RTR0MEMOBJTYPE_PHYS, uAlignment, pszTag, false /*fOnKernelThread*/);
    940950    }
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette