vbox的更動 46570 路徑 trunk/src/VBox/Runtime/r3/posix
- 時間撮記:
- 2013-6-14 下午04:47:24 (11 年 以前)
- 檔案:
-
- 複製 1 筆資料
圖例:
- 未更動
- 新增
- 刪除
-
trunk/src/VBox/Runtime/r3/posix/allocex-r3-posix.cpp
r46567 r46570 1 1 /* $Id$ */ 2 2 /** @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. 4 4 */ 5 5 … … 37 37 #include "internal/magics.h" 38 38 39 #include <sys/mman.h> 40 39 41 40 42 /******************************************************************************* … … 59 61 60 62 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 */ 70 static 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 61 87 62 88 RTDECL(int) RTMemAllocExTag(size_t cb, size_t cbAlignment, uint32_t fFlags, const char *pszTag, void **ppv) RT_NO_THROW … … 70 96 AssertMsgReturn(cbAlignment <= sizeof(void *), ("%zu (%#x)\n", cbAlignment, cbAlignment), VERR_UNSUPPORTED_ALIGNMENT); 71 97 72 if (fFlags & (RTMEMALLOCEX_FLAGS_16BIT_REACH | RTMEMALLOCEX_FLAGS_32BIT_REACH | RTMEMALLOCEX_FLAGS_ANY_CTX))98 if (fFlags & RTMEMALLOCEX_FLAGS_ANY_CTX) 73 99 return VERR_NOT_SUPPORTED; 74 100 … … 81 107 else 82 108 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), 84 110 VERR_INVALID_PARAMETER); 85 111 … … 88 114 */ 89 115 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) 91 119 { 92 120 pv = RTMemExecAlloc(cbAligned + sizeof(RTMEMHDRR3)); … … 127 155 Assert(pHdr->cbReq == cb); 128 156 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) 130 160 RTMemExecFree(pHdr, pHdr->cb + sizeof(*pHdr)); 131 161 else
注意:
瀏覽 TracChangeset
來幫助您使用更動檢視器