Changeset 97910 in vbox for trunk/src/VBox/Runtime/r0drv/darwin
- Timestamp:
- Dec 29, 2022 7:15:56 PM (2 years ago)
- svn:sync-xref-src-repo-rev:
- 155000
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r0drv/darwin/alloc-r0drv-darwin.cpp
r96407 r97910 51 51 52 52 53 /*********************************************************************************************************************************54 * Structures and Typedefs *55 *********************************************************************************************************************************/56 /**57 * Extended header used for headers marked with RTMEMHDR_FLAG_EXEC.58 *59 * This is used with allocating executable memory, for things like generated60 * code and loaded modules.61 */62 typedef struct RTMEMDARWINHDREX63 {64 /** The associated memory object. */65 RTR0MEMOBJ hMemObj;66 /** Alignment padding. */67 uint8_t abPadding[ARCH_BITS == 32 ? 12 : 8];68 /** The header we present to the generic API. */69 RTMEMHDR Hdr;70 } RTMEMDARWINHDREX;71 AssertCompileSize(RTMEMDARWINHDREX, 32);72 /** Pointer to an extended memory header. */73 typedef RTMEMDARWINHDREX *PRTMEMDARWINHDREX;74 75 53 76 54 /** … … 80 58 { 81 59 IPRT_DARWIN_SAVE_EFL_AC(); 60 if (RT_LIKELY(!(fFlags & RTMEMHDR_FLAG_ANY_CTX))) 61 { 62 PRTMEMHDR pHdr = (PRTMEMHDR)IOMalloc(cb + sizeof(*pHdr)); 63 if (RT_LIKELY(pHdr)) 64 { 65 pHdr->u32Magic = RTMEMHDR_MAGIC; 66 pHdr->fFlags = fFlags; 67 pHdr->cb = cb; 68 pHdr->cbReq = cb; 69 *ppHdr = pHdr; 82 70 83 if (RT_UNLIKELY(fFlags & RTMEMHDR_FLAG_ANY_CTX)) 84 return VERR_NOT_SUPPORTED; 71 IPRT_DARWIN_RESTORE_EFL_AC(); 72 return VINF_SUCCESS; 73 } 85 74 86 PRTMEMHDR pHdr; 87 if (fFlags & RTMEMHDR_FLAG_EXEC) 88 { 89 RTR0MEMOBJ hMemObj; 90 int rc = RTR0MemObjAllocPage(&hMemObj, cb + sizeof(RTMEMDARWINHDREX), true /*fExecutable*/); 91 if (RT_FAILURE(rc)) 92 { 93 IPRT_DARWIN_RESTORE_EFL_AC(); 94 return rc; 95 } 96 PRTMEMDARWINHDREX pExHdr = (PRTMEMDARWINHDREX)RTR0MemObjAddress(hMemObj); 97 pExHdr->hMemObj = hMemObj; 98 pHdr = &pExHdr->Hdr; 99 #if 1 /*fExecutable isn't currently honored above. */ 100 rc = RTR0MemObjProtect(hMemObj, 0, RTR0MemObjSize(hMemObj), RTMEM_PROT_READ | RTMEM_PROT_WRITE | RTMEM_PROT_EXEC); 101 AssertRC(rc); 102 #endif 75 printf("rtR0MemAllocEx(%#zx, %#x) failed\n", cb + sizeof(*pHdr), fFlags); 76 IPRT_DARWIN_RESTORE_EFL_AC(); 77 return VERR_NO_MEMORY; 103 78 } 104 else105 {106 pHdr = (PRTMEMHDR)IOMalloc(cb + sizeof(*pHdr));107 if (RT_UNLIKELY(!pHdr))108 {109 printf("rtR0MemAllocEx(%#zx, %#x) failed\n", cb + sizeof(*pHdr), fFlags);110 IPRT_DARWIN_RESTORE_EFL_AC();111 return VERR_NO_MEMORY;112 }113 }114 115 pHdr->u32Magic = RTMEMHDR_MAGIC;116 pHdr->fFlags = fFlags;117 pHdr->cb = cb;118 pHdr->cbReq = cb;119 *ppHdr = pHdr;120 121 79 IPRT_DARWIN_RESTORE_EFL_AC(); 122 return V INF_SUCCESS;80 return VERR_NOT_SUPPORTED; 123 81 } 124 82 … … 132 90 133 91 pHdr->u32Magic += 1; 134 if (pHdr->fFlags & RTMEMHDR_FLAG_EXEC) 135 { 136 PRTMEMDARWINHDREX pExHdr = RT_FROM_MEMBER(pHdr, RTMEMDARWINHDREX, Hdr); 137 int rc = RTR0MemObjFree(pExHdr->hMemObj, false /*fFreeMappings*/); 138 AssertRC(rc); 139 } 140 else 141 IOFree(pHdr, pHdr->cb + sizeof(*pHdr)); 92 IOFree(pHdr, pHdr->cb + sizeof(*pHdr)); 142 93 143 94 IPRT_DARWIN_RESTORE_EFL_AC();
Note:
See TracChangeset
for help on using the changeset viewer.