VirtualBox

Ignore:
Timestamp:
Dec 29, 2022 7:15:56 PM (2 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
155000
Message:

IPRT/r0drv: Kicked out RTMEMHDR_FLAG_EXEC and associated code now that RTMemExecAlloc have been removed and RTMEMALLOCEX_FLAGS_EXEC is ring-3 only. This should simplify maintaining the linux code a bit, I hope. bugref:4567:65

File:
1 edited

Legend:

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

    r96407 r97910  
    5151
    5252
    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 generated
    60  * code and loaded modules.
    61  */
    62 typedef struct RTMEMDARWINHDREX
    63 {
    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 
    7553
    7654/**
     
    8058{
    8159    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;
    8270
    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        }
    8574
    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;
    10378    }
    104     else
    105     {
    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 
    12179    IPRT_DARWIN_RESTORE_EFL_AC();
    122     return VINF_SUCCESS;
     80    return VERR_NOT_SUPPORTED;
    12381}
    12482
     
    13290
    13391    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));
    14293
    14394    IPRT_DARWIN_RESTORE_EFL_AC();
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