VirtualBox

Ignore:
Timestamp:
Apr 25, 2012 3:11:33 PM (13 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
77618
Message:

alloc-r0drv-darwin.cpp: Use RTR0MemObjAllocPage to satisfy RTMEMHDR_FLAG_EXEC requests.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r0drv/darwin/alloc-r0drv-darwin.cpp

    r36555 r41054  
    55
    66/*
    7  * Copyright (C) 2006-2010 Oracle Corporation
     7 * Copyright (C) 2006-2012 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3232#include "internal/iprt.h"
    3333#include <iprt/mem.h>
     34#include <iprt/memobj.h>
    3435
    3536#include <iprt/assert.h>
     
    3738#include <iprt/thread.h>
    3839#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 */
     51typedef 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;
     60AssertCompileSize(RTMEMDARWINHDREX, 32);
     61/** Pointer to an extended memory header. */
     62typedef RTMEMDARWINHDREX *PRTMEMDARWINHDREX;
    3963
    4064
     
    4771        return VERR_NOT_SUPPORTED;
    4872
    49     PRTMEMHDR pHdr = (PRTMEMHDR)IOMalloc(cb + sizeof(*pHdr));
    50     if (RT_UNLIKELY(!pHdr))
     73    PRTMEMHDR pHdr;
     74    if (fFlags & RTMEMHDR_FLAG_EXEC)
    5175    {
    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        }
    5493    }
    5594
     
    69108{
    70109    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));
    72118}
    73119
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette