VirtualBox

Changeset 29277 in vbox for trunk/src


Ignore:
Timestamp:
May 9, 2010 11:25:51 PM (15 years ago)
Author:
vboxsync
Message:

alloc-solaris.cpp: MMAP mode in case it comes in handy later.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/solaris/alloc-solaris.cpp

    r28800 r29277  
    3939#include <sys/mman.h>
    4040#include <strings.h>
     41
     42
     43/*******************************************************************************
     44*   Defined Constants And Macros                                               *
     45*******************************************************************************/
     46#if 0
     47# define RT_USE_MMAP_PAGE
     48#endif
    4149
    4250
     
    102110RTDECL(void *) RTMemPageAlloc(size_t cb) RT_NO_THROW
    103111{
     112#ifdef RT_USE_MMAP_PAGE
     113    size_t  cbAligned = RT_ALIGN_Z(cb, PAGE_SIZE);
     114    void   *pv = mmap(NULL, cbAligned, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
     115    AssertMsgReturn(pv != MAP_FAILED, ("errno=%d cb=%#zx\n", errno, cb), NULL);
     116    return pv;
     117
     118#else
    104119    return valloc(RT_ALIGN_Z(cb, PAGE_SIZE));
     120#endif
    105121}
    106122
     
    115131RTDECL(void *) RTMemPageAllocZ(size_t cb) RT_NO_THROW
    116132{
     133#ifdef RT_USE_MMAP_PAGE
     134    size_t  cbAligned = RT_ALIGN_Z(cb, PAGE_SIZE);
     135    void   *pv = mmap(NULL, cbAligned, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
     136    AssertMsgReturn(pv != MAP_FAILED, ("errno=%d cb=%#zx\n", errno, cb), NULL);
     137    return pv;
     138
     139#else
    117140    cb = RT_ALIGN_Z(cb, PAGE_SIZE);
    118141    void *pv = valloc(cb);
     
    120143        bzero(pv, RT_ALIGN_Z(cb, PAGE_SIZE));
    121144    return pv;
     145#endif
    122146}
    123147
     
    132156{
    133157    if (pv)
     158    {
     159#ifdef RT_USE_MMAP_PAGE
     160        size_t cbAligned = RT_ALIGN_Z(cb, PAGE_SIZE);
     161        int rc = munmap(pv, cbAligned);
     162        AssertMsg(!rc, ("munmap(%p, %#zx) -> %d errno=%d\n", pv, cbAligned, rc, errno)); NOREF(rc);
     163#else
    134164        free(pv);
     165#endif
     166    }
    135167}
    136168
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