VirtualBox

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


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

hacked up a way of getting one block of low memory.

檔案:
複製 1 筆資料

圖例:

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

    r46567 r46570  
    11/* $Id$ */
    22/** @file
    3  * IPRT - Memory Allocation, Extended Alloc and Free Functions for Ring-3, generic.
     3 * IPRT - Memory Allocation, Extended Alloc and Free Functions for Ring-3, posix.
    44 */
    55
     
    3737#include "internal/magics.h"
    3838
     39#include <sys/mman.h>
     40
    3941
    4042/*******************************************************************************
     
    5961
    6062
     63/**
     64 * Allocates memory with upper boundrary.
     65 *
     66 * @returns Pointer to mmap allocation.
     67 * @param   cbAlloc             Number of bytes to alloacate.
     68 * @param   fFlags              Allocation flags.
     69 */
     70static void *rtMemAllocExAllocLow(size_t cbAlloc, uint32_t fFlags)
     71{
     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)
     77    {
     78        munmap(pv, cbAlloc);
     79        return NULL;
     80    }
     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. */
     84    return pv;
     85}
     86
    6187
    6288RTDECL(int) RTMemAllocExTag(size_t cb, size_t cbAlignment, uint32_t fFlags, const char *pszTag, void **ppv) RT_NO_THROW
     
    7096    AssertMsgReturn(cbAlignment <= sizeof(void *), ("%zu (%#x)\n", cbAlignment, cbAlignment), VERR_UNSUPPORTED_ALIGNMENT);
    7197
    72     if (fFlags & (RTMEMALLOCEX_FLAGS_16BIT_REACH | RTMEMALLOCEX_FLAGS_32BIT_REACH | RTMEMALLOCEX_FLAGS_ANY_CTX))
     98    if (fFlags & RTMEMALLOCEX_FLAGS_ANY_CTX)
    7399        return VERR_NOT_SUPPORTED;
    74100
     
    81107    else
    82108        cbAligned = RT_ALIGN_Z(cb, sizeof(uint64_t));
    83     AssertMsgReturn(cbAligned >= cb && cbAligned <= ~(size_t)0 / 2U, ("cbAligned=%#zx cb=%#zx", cbAligned, cb),
     109    AssertMsgReturn(cbAligned >= cb && cbAligned <= ~(size_t)0, ("cbAligned=%#zx cb=%#zx", cbAligned, cb),
    84110                    VERR_INVALID_PARAMETER);
    85111
     
    88114     */
    89115    void *pv;
    90     if (fFlags & RTMEMALLOCEX_FLAGS_EXEC)
     116    if (fFlags & (RTMEMALLOCEX_FLAGS_16BIT_REACH | RTMEMALLOCEX_FLAGS_32BIT_REACH))
     117        pv = rtMemAllocExAllocLow(cbAligned + sizeof(RTMEMHDRR3), fFlags);
     118    else if (fFlags & RTMEMALLOCEX_FLAGS_EXEC)
    91119    {
    92120        pv = RTMemExecAlloc(cbAligned + sizeof(RTMEMHDRR3));
     
    127155    Assert(pHdr->cbReq == cb);
    128156
    129     if (pHdr->fFlags & RTMEMALLOCEX_FLAGS_EXEC)
     157    if (pHdr->fFlags & (RTMEMALLOCEX_FLAGS_16BIT_REACH | RTMEMALLOCEX_FLAGS_32BIT_REACH))
     158        munmap(pHdr, pHdr->cb + sizeof(*pHdr));
     159    else if (pHdr->fFlags & RTMEMALLOCEX_FLAGS_EXEC)
    130160        RTMemExecFree(pHdr, pHdr->cb + sizeof(*pHdr));
    131161    else
注意: 瀏覽 TracChangeset 來幫助您使用更動檢視器

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