Changeset 41054 in vbox for trunk/src/VBox/Runtime/r0drv/darwin
- Timestamp:
- Apr 25, 2012 3:11:33 PM (13 years ago)
- svn:sync-xref-src-repo-rev:
- 77618
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r0drv/darwin/alloc-r0drv-darwin.cpp
r36555 r41054 5 5 6 6 /* 7 * Copyright (C) 2006-201 0Oracle Corporation7 * Copyright (C) 2006-2012 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 32 32 #include "internal/iprt.h" 33 33 #include <iprt/mem.h> 34 #include <iprt/memobj.h> 34 35 35 36 #include <iprt/assert.h> … … 37 38 #include <iprt/thread.h> 38 39 #include "r0drv/alloc-r0drv.h" 40 41 42 /******************************************************************************* 43 * Structures and Typedefs * 44 *******************************************************************************/ 45 /** 46 * Extended header used for headers marked with RTMEMHDR_FLAG_EXEC. 47 * 48 * This is used with allocating executable memory, for things like generated 49 * code and loaded modules. 50 */ 51 typedef struct RTMEMDARWINHDREX 52 { 53 /** The associated memory object. */ 54 RTR0MEMOBJ hMemObj; 55 /** Alignment padding. */ 56 uint8_t abPadding[ARCH_BITS == 32 ? 12 : 8]; 57 /** The header we present to the generic API. */ 58 RTMEMHDR Hdr; 59 } RTMEMDARWINHDREX; 60 AssertCompileSize(RTMEMDARWINHDREX, 32); 61 /** Pointer to an extended memory header. */ 62 typedef RTMEMDARWINHDREX *PRTMEMDARWINHDREX; 39 63 40 64 … … 47 71 return VERR_NOT_SUPPORTED; 48 72 49 PRTMEMHDR pHdr = (PRTMEMHDR)IOMalloc(cb + sizeof(*pHdr));50 if ( RT_UNLIKELY(!pHdr))73 PRTMEMHDR pHdr; 74 if (fFlags & RTMEMHDR_FLAG_EXEC) 51 75 { 52 printf("rtR0MemAllocEx(%#zx, %#x) failed\n", cb + sizeof(*pHdr), fFlags); 53 return VERR_NO_MEMORY; 76 RTR0MEMOBJ hMemObj; 77 int rc = RTR0MemObjAllocPage(&hMemObj, cb + sizeof(RTMEMDARWINHDREX), true /*fExecutable*/); 78 if (RT_FAILURE(rc)) 79 return rc; 80 PRTMEMDARWINHDREX pExHdr = (PRTMEMDARWINHDREX)RTR0MemObjAddress(hMemObj); 81 pExHdr->hMemObj = hMemObj; 82 pHdr = &pExHdr->Hdr; 83 } 84 else 85 { 86 87 pHdr = (PRTMEMHDR)IOMalloc(cb + sizeof(*pHdr)); 88 if (RT_UNLIKELY(!pHdr)) 89 { 90 printf("rtR0MemAllocEx(%#zx, %#x) failed\n", cb + sizeof(*pHdr), fFlags); 91 return VERR_NO_MEMORY; 92 } 54 93 } 55 94 … … 69 108 { 70 109 pHdr->u32Magic += 1; 71 IOFree(pHdr, pHdr->cb + sizeof(*pHdr)); 110 if (pHdr->fFlags & RTMEMHDR_FLAG_EXEC) 111 { 112 PRTMEMDARWINHDREX pExHdr = RT_FROM_MEMBER(pHdr, RTMEMDARWINHDREX, Hdr); 113 int rc = RTR0MemObjFree(pExHdr->hMemObj, false /*fFreeMappings*/); 114 AssertRC(rc); 115 } 116 else 117 IOFree(pHdr, pHdr->cb + sizeof(*pHdr)); 72 118 } 73 119
Note:
See TracChangeset
for help on using the changeset viewer.