Changeset 46572 in vbox
- Timestamp:
- Jun 14, 2013 5:01:33 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/posix/allocex-r3-posix.cpp
r46570 r46572 70 70 static void *rtMemAllocExAllocLow(size_t cbAlloc, uint32_t fFlags) 71 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) 72 int fProt = PROT_READ | PROT_WRITE | (fFlags & RTMEMALLOCEX_FLAGS_EXEC ? PROT_EXEC : 0); 73 void *pv; 74 if (fFlags & RTMEMALLOCEX_FLAGS_16BIT_REACH) 77 75 { 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 } 80 95 } 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 } 84 103 return pv; 85 104 }
Note:
See TracChangeset
for help on using the changeset viewer.