VirtualBox

vbox的更動 46572 路徑 trunk/src/VBox/Runtime/r3/posix


忽略:
時間撮記:
2013-6-14 下午05:01:33 (11 年 以前)
作者:
vboxsync
訊息:

More correct.

檔案:
修改 1 筆資料

圖例:

未更動
新增
刪除
  • trunk/src/VBox/Runtime/r3/posix/allocex-r3-posix.cpp

    r46570 r46572  
    7070static void *rtMemAllocExAllocLow(size_t cbAlloc, uint32_t fFlags)
    7171{
    72     int       fProt     = PROT_READ | PROT_WRITE | (fFlags & RTMEMALLOCEX_FLAGS_EXEC ? PROT_EXEC : 0);
    73     uintptr_t uAddrLast = fFlags & RTMEMALLOCEX_FLAGS_16BIT_REACH ? _1M - 1 : UINT32_MAX;
    74     uintptr_t uAddr     = fFlags & RTMEMALLOCEX_FLAGS_16BIT_REACH ? 0x1000  : _1M;
    75     void *pv = mmap((void *)uAddr, cbAlloc, fProt, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
    76     if (pv && ((uintptr_t)(pv) + cbAlloc - 1U) > uAddrLast)
     72    int   fProt = PROT_READ | PROT_WRITE | (fFlags & RTMEMALLOCEX_FLAGS_EXEC ? PROT_EXEC : 0);
     73    void *pv;
     74    if (fFlags & RTMEMALLOCEX_FLAGS_16BIT_REACH)
    7775    {
    78         munmap(pv, cbAlloc);
    79         return NULL;
     76        AssertReturn(cbAlloc < _64K, NULL);
     77
     78        /*
     79         * Try with every possible address hint since the possible range is very limited.
     80         */
     81        uintptr_t uAddr     = fFlags & RTMEMALLOCEX_FLAGS_16BIT_REACH ? 0x1000  : _1M;
     82        uintptr_t uAddrLast = _64K - uAddr - cbAlloc;
     83        while (uAddr < uAddrLast)
     84        {
     85            pv = mmap((void *)uAddr, cbAlloc, fProt, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
     86            if (pv && (uintptr_t)pv <= uAddrLast)
     87                break;
     88            if (pv)
     89            {
     90                munmap(pv, cbAlloc);
     91                pv = NULL;
     92            }
     93            uAddr += _4K;
     94        }
    8095    }
    81     /** @todo On linux, this method works for exactly one allocation. need to do
    82      *        OS specific stuff to select a good address hint. Leaving this as a
    83      *        TODO for now as I only need one allocation. */
     96    else
     97    {
     98        /** @todo On linux, we need an accurate hint. Since I don't need this branch of
     99         *        the code right now, I won't bother starting to parse
     100         *        /proc/curproc/mmap right now... */
     101        pv = NULL;
     102    }
    84103    return pv;
    85104}
注意: 瀏覽 TracChangeset 來幫助您使用更動檢視器

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