VirtualBox

Changeset 32674 in vbox


Ignore:
Timestamp:
Sep 21, 2010 4:51:50 PM (14 years ago)
Author:
vboxsync
Message:

IPRT: started on some internal ring-0 alloc api.

Location:
trunk/src/VBox/Runtime/r0drv
Files:
8 edited

Legend:

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

    r31157 r32674  
    318318RT_EXPORT_SYMBOL(RTMemExecFree);
    319319
     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 */
     329void *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 */
     341void  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  
    3030#include <iprt/cdefs.h>
    3131#include <iprt/types.h>
     32#include <iprt/mem.h>
    3233#include "internal/magics.h"
    3334
     
    5253/** @name RTMEMHDR::fFlags.
    5354 * @{ */
    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)
    5661#ifdef RT_OS_LINUX
    57 #define RTMEMHDR_FLAG_EXEC_HEAP RT_BIT(30)
    58 #define RTMEMHDR_FLAG_KMALLOC   RT_BIT(31)
     62# define RTMEMHDR_FLAG_EXEC_HEAP    RT_BIT(30)
     63# define RTMEMHDR_FLAG_KMALLOC      RT_BIT(31)
    5964#endif
    6065/** @} */
     
    6368PRTMEMHDR   rtR0MemAlloc(size_t cb, uint32_t fFlags);
    6469void        rtR0MemFree(PRTMEMHDR pHdr);
     70#define rtR0MemAllocEx(cb, fFlags) rtR0MemAllocExTag((cb), (fFlags), RTMEM_TAG)
     71void       *rtR0MemAllocExTag(size_t cb, uint32_t fFlags, const char *pszTag) RT_NO_THROW;
     72void        rtR0MemFreeEx(void *pv) RT_NO_THROW;
    6573
    6674RT_C_DECLS_END
  • trunk/src/VBox/Runtime/r0drv/darwin/alloc-r0drv-darwin.cpp

    r28800 r32674  
    4343PRTMEMHDR rtR0MemAlloc(size_t cb, uint32_t fFlags)
    4444{
     45    AssertReturn(!(fFlags & RTMEMHDR_FLAG_ANY_CTX), NULL);
     46
    4547    PRTMEMHDR pHdr = (PRTMEMHDR)IOMalloc(cb + sizeof(*pHdr));
    4648    if (pHdr)
  • trunk/src/VBox/Runtime/r0drv/freebsd/alloc-r0drv-freebsd.c

    r29832 r32674  
    5252PRTMEMHDR rtR0MemAlloc(size_t cb, uint32_t fFlags)
    5353{
    54     size_t cbAllocated = cb;
    55     PRTMEMHDR pHdr = NULL;
     54    size_t      cbAllocated = cb;
     55    PRTMEMHDR   pHdr        = NULL;
    5656
    5757    /*
     
    6262    if (fFlags & RTMEMHDR_FLAG_EXEC)
    6363    {
     64        AssertReturn(!(fFlags & RTMEMHDR_FLAG_ANY_CTX), NULL);
     65
    6466# ifdef USE_KMEM_ALLOC_PROT
    6567        pHdr = (PRTMEMHDR)kmem_alloc_prot(kernel_map, cb + sizeof(*pHdr),
  • trunk/src/VBox/Runtime/r0drv/linux/alloc-r0drv-linux.c

    r28800 r32674  
    113113PRTMEMHDR rtR0MemAlloc(size_t cb, uint32_t fFlags)
    114114{
     115    PRTMEMHDR pHdr;
     116
    115117    /*
    116118     * Allocate.
    117119     */
    118     PRTMEMHDR pHdr;
    119120    if (fFlags & RTMEMHDR_FLAG_EXEC)
    120121    {
     122        AssertReturn(!(fFlags & RTMEMHDR_FLAG_ANY_CTX), NULL);
     123
    121124#if defined(RT_ARCH_AMD64)
    122125# ifdef RTMEMALLOC_EXEC_HEAP
     
    143146    else
    144147    {
    145         if (cb <= PAGE_SIZE)
     148        if (cb <= PAGE_SIZE || (fFlags & RTMEMHDR_FLAG_ANY_CTX))
    146149        {
    147150            fFlags |= RTMEMHDR_FLAG_KMALLOC;
  • trunk/src/VBox/Runtime/r0drv/nt/alloc-r0drv-nt.cpp

    r28800 r32674  
    4141PRTMEMHDR rtR0MemAlloc(size_t cb, uint32_t fFlags)
    4242{
     43    AssertReturn(!(fFlags & RTMEMHDR_FLAG_ANY_CTX), NULL);
     44
    4345    PRTMEMHDR pHdr = (PRTMEMHDR)ExAllocatePoolWithTag(NonPagedPool, cb + sizeof(*pHdr), IPRT_NT_POOL_TAG);
    4446    if (pHdr)
  • trunk/src/VBox/Runtime/r0drv/os2/alloc-r0drv-os2.cpp

    r28298 r32674  
    4343PRTMEMHDR rtR0MemAlloc(size_t cb, uint32_t fFlags)
    4444{
     45    AssertReturn(!(fFlags & RTMEMHDR_FLAG_ANY_CTX), NULL);
     46
    4547    void *pv = NULL;
    4648    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  
    4646PRTMEMHDR rtR0MemAlloc(size_t cb, uint32_t fFlags)
    4747{
    48     size_t cbAllocated = cb;
    49     PRTMEMHDR pHdr;
     48    size_t      cbAllocated = cb;
     49    PRTMEMHDR   pHdr;
     50
    5051#ifdef RT_ARCH_AMD64
    5152    if (fFlags & RTMEMHDR_FLAG_EXEC)
    5253    {
     54        AssertReturn(!(fFlags & RTMEMHDR_FLAG_ANY_CTX), NULL);
    5355        cbAllocated = RT_ALIGN_Z(cb + sizeof(*pHdr), PAGE_SIZE) - sizeof(*pHdr);
    5456        pHdr = (PRTMEMHDR)vbi_text_alloc(cbAllocated + sizeof(*pHdr));
     
    5658    else
    5759#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    }
    6267    if (pHdr)
    6368    {
Note: See TracChangeset for help on using the changeset viewer.

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