Changeset 32674 in vbox
- Timestamp:
- Sep 21, 2010 4:51:50 PM (14 years ago)
- Location:
- trunk/src/VBox/Runtime/r0drv
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r0drv/alloc-r0drv.cpp
r31157 r32674 318 318 RT_EXPORT_SYMBOL(RTMemExecFree); 319 319 320 321 /** 322 * Internal IPRT API for allocating special memory. 323 * 324 * @returns Pointer to the allocated memory, NULL on failure. 325 * @param cb The amount of memory to allocate. 326 * @param fFlags Subset of the RTMEMHDR_FLAG_XXX flags. 327 * @param pszTag The tag. 328 */ 329 void *rtR0MemAllocExTag(size_t cb, uint32_t fFlags, const char *pszTag) RT_NO_THROW 330 { 331 /** @todo continue later. */ 332 return NULL; 333 } 334 335 336 /** 337 * For freeing memory allocated by rtR0MemAllocExTag. 338 * 339 * @param pv What to free, NULL is fine. 340 */ 341 void rtR0MemFreeEx(void *pv) RT_NO_THROW 342 { 343 PRTMEMHDR pHdr; 344 345 if (!pv) 346 return; 347 pHdr = (PRTMEMHDR)pv - 1; 348 if (pHdr->u32Magic == RTMEMHDR_MAGIC) 349 { 350 Assert(pHdr->fFlags & RTMEMHDR_FLAG_ALLOC_EX); 351 if (!(pHdr->fFlags & RTMEMHDR_FLAG_FREE_ANY_CTX)) 352 RT_ASSERT_INTS_ON(); 353 354 #ifdef RTR0MEM_STRICT 355 AssertReleaseMsg(!memcmp((uint8_t *)(pHdr + 1) + pHdr->cbReq, &g_abFence[0], RTR0MEM_FENCE_EXTRA), 356 ("pHdr=%p pv=%p cb=%zu\n" 357 "fence: %.*Rhxs\n" 358 "expected: %.*Rhxs\n", 359 pHdr, pv, pHdr->cb, 360 RTR0MEM_FENCE_EXTRA, (uint8_t *)(pHdr + 1) + pHdr->cb, 361 RTR0MEM_FENCE_EXTRA, &g_abFence[0])); 362 #endif 363 rtR0MemFree(pHdr); 364 } 365 else 366 AssertMsgFailed(("pHdr->u32Magic=%RX32 pv=%p\n", pHdr->u32Magic, pv)); 367 } 368 -
trunk/src/VBox/Runtime/r0drv/alloc-r0drv.h
r28800 r32674 30 30 #include <iprt/cdefs.h> 31 31 #include <iprt/types.h> 32 #include <iprt/mem.h> 32 33 #include "internal/magics.h" 33 34 … … 52 53 /** @name RTMEMHDR::fFlags. 53 54 * @{ */ 54 #define RTMEMHDR_FLAG_ZEROED RT_BIT(0) 55 #define RTMEMHDR_FLAG_EXEC RT_BIT(1) 55 #define RTMEMHDR_FLAG_ZEROED RT_BIT(0) 56 #define RTMEMHDR_FLAG_EXEC RT_BIT(1) 57 #define RTMEMHDR_FLAG_ALLOC_ANY_CTX RT_BIT(2) 58 #define RTMEMHDR_FLAG_FREE_ANY_CTX RT_BIT(3) 59 #define RTMEMHDR_FLAG_ANY_CTX (RTMEMHDR_FLAG_ALLOC_ANY_CTX | RTMEMHDR_FLAG_FREE_ANY_CTX) 60 #define RTMEMHDR_FLAG_ALLOC_EX RT_BIT(4) 56 61 #ifdef RT_OS_LINUX 57 # define RTMEMHDR_FLAG_EXEC_HEAPRT_BIT(30)58 # define RTMEMHDR_FLAG_KMALLOCRT_BIT(31)62 # define RTMEMHDR_FLAG_EXEC_HEAP RT_BIT(30) 63 # define RTMEMHDR_FLAG_KMALLOC RT_BIT(31) 59 64 #endif 60 65 /** @} */ … … 63 68 PRTMEMHDR rtR0MemAlloc(size_t cb, uint32_t fFlags); 64 69 void rtR0MemFree(PRTMEMHDR pHdr); 70 #define rtR0MemAllocEx(cb, fFlags) rtR0MemAllocExTag((cb), (fFlags), RTMEM_TAG) 71 void *rtR0MemAllocExTag(size_t cb, uint32_t fFlags, const char *pszTag) RT_NO_THROW; 72 void rtR0MemFreeEx(void *pv) RT_NO_THROW; 65 73 66 74 RT_C_DECLS_END -
trunk/src/VBox/Runtime/r0drv/darwin/alloc-r0drv-darwin.cpp
r28800 r32674 43 43 PRTMEMHDR rtR0MemAlloc(size_t cb, uint32_t fFlags) 44 44 { 45 AssertReturn(!(fFlags & RTMEMHDR_FLAG_ANY_CTX), NULL); 46 45 47 PRTMEMHDR pHdr = (PRTMEMHDR)IOMalloc(cb + sizeof(*pHdr)); 46 48 if (pHdr) -
trunk/src/VBox/Runtime/r0drv/freebsd/alloc-r0drv-freebsd.c
r29832 r32674 52 52 PRTMEMHDR rtR0MemAlloc(size_t cb, uint32_t fFlags) 53 53 { 54 size_t cbAllocated = cb;55 PRTMEMHDR pHdr= NULL;54 size_t cbAllocated = cb; 55 PRTMEMHDR pHdr = NULL; 56 56 57 57 /* … … 62 62 if (fFlags & RTMEMHDR_FLAG_EXEC) 63 63 { 64 AssertReturn(!(fFlags & RTMEMHDR_FLAG_ANY_CTX), NULL); 65 64 66 # ifdef USE_KMEM_ALLOC_PROT 65 67 pHdr = (PRTMEMHDR)kmem_alloc_prot(kernel_map, cb + sizeof(*pHdr), -
trunk/src/VBox/Runtime/r0drv/linux/alloc-r0drv-linux.c
r28800 r32674 113 113 PRTMEMHDR rtR0MemAlloc(size_t cb, uint32_t fFlags) 114 114 { 115 PRTMEMHDR pHdr; 116 115 117 /* 116 118 * Allocate. 117 119 */ 118 PRTMEMHDR pHdr;119 120 if (fFlags & RTMEMHDR_FLAG_EXEC) 120 121 { 122 AssertReturn(!(fFlags & RTMEMHDR_FLAG_ANY_CTX), NULL); 123 121 124 #if defined(RT_ARCH_AMD64) 122 125 # ifdef RTMEMALLOC_EXEC_HEAP … … 143 146 else 144 147 { 145 if (cb <= PAGE_SIZE )148 if (cb <= PAGE_SIZE || (fFlags & RTMEMHDR_FLAG_ANY_CTX)) 146 149 { 147 150 fFlags |= RTMEMHDR_FLAG_KMALLOC; -
trunk/src/VBox/Runtime/r0drv/nt/alloc-r0drv-nt.cpp
r28800 r32674 41 41 PRTMEMHDR rtR0MemAlloc(size_t cb, uint32_t fFlags) 42 42 { 43 AssertReturn(!(fFlags & RTMEMHDR_FLAG_ANY_CTX), NULL); 44 43 45 PRTMEMHDR pHdr = (PRTMEMHDR)ExAllocatePoolWithTag(NonPagedPool, cb + sizeof(*pHdr), IPRT_NT_POOL_TAG); 44 46 if (pHdr) -
trunk/src/VBox/Runtime/r0drv/os2/alloc-r0drv-os2.cpp
r28298 r32674 43 43 PRTMEMHDR rtR0MemAlloc(size_t cb, uint32_t fFlags) 44 44 { 45 AssertReturn(!(fFlags & RTMEMHDR_FLAG_ANY_CTX), NULL); 46 45 47 void *pv = NULL; 46 48 APIRET rc = KernVMAlloc(cb + sizeof(RTMEMHDR), VMDHA_FIXED, &pv, (void **)-1, NULL); -
trunk/src/VBox/Runtime/r0drv/solaris/vbi/alloc-r0drv-solaris.c
r28800 r32674 46 46 PRTMEMHDR rtR0MemAlloc(size_t cb, uint32_t fFlags) 47 47 { 48 size_t cbAllocated = cb; 49 PRTMEMHDR pHdr; 48 size_t cbAllocated = cb; 49 PRTMEMHDR pHdr; 50 50 51 #ifdef RT_ARCH_AMD64 51 52 if (fFlags & RTMEMHDR_FLAG_EXEC) 52 53 { 54 AssertReturn(!(fFlags & RTMEMHDR_FLAG_ANY_CTX), NULL); 53 55 cbAllocated = RT_ALIGN_Z(cb + sizeof(*pHdr), PAGE_SIZE) - sizeof(*pHdr); 54 56 pHdr = (PRTMEMHDR)vbi_text_alloc(cbAllocated + sizeof(*pHdr)); … … 56 58 else 57 59 #endif 58 if (fFlags & RTMEMHDR_FLAG_ZEROED) 59 pHdr = (PRTMEMHDR)kmem_zalloc(cb + sizeof(*pHdr), KM_SLEEP); 60 else 61 pHdr = (PRTMEMHDR)kmem_alloc(cb + sizeof(*pHdr), KM_SLEEP); 60 { 61 unsigned fKmFlags = fFlags & RTMEMHDR_FLAG_ALLOC_ANY_CTX ? KM_NOSLEEP : KM_SLEEP; 62 if (fFlags & RTMEMHDR_FLAG_ZEROED) 63 pHdr = (PRTMEMHDR)kmem_zalloc(cb + sizeof(*pHdr), fKmFlags); 64 else 65 pHdr = (PRTMEMHDR)kmem_alloc(cb + sizeof(*pHdr), fKmFlags); 66 } 62 67 if (pHdr) 63 68 {
Note:
See TracChangeset
for help on using the changeset viewer.