VirtualBox

Changeset 4135

Show
Ignore:
Timestamp:
08/14/07 03:29:43 (1 year ago)
Author:
vboxsync
Message:

Use size_t for the page index. Added API for querying the ring-3 address.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/include/iprt/memobj.h

    r4071 r4135  
    6666 * @param   iPage   The page number within the object. 
    6767 */ 
    68 RTR0DECL(RTHCPHYS) RTR0MemObjGetPagePhysAddr(RTR0MEMOBJ MemObj, unsigned iPage); 
     68RTR0DECL(RTHCPHYS) RTR0MemObjGetPagePhysAddr(RTR0MEMOBJ MemObj, size_t iPage); 
    6969 
    7070/** 
     
    123123 * @param   R0Process       The process to lock pages in. NIL_R0PROCESS is an alias for the current one. 
    124124 * 
    125  * @remark  RTR0MemObjGetAddress() will return the rounded down address. 
     125 * @remark  RTR0MemGetAddressR3() and RTR0MemGetAddress() will return the rounded down address. 
    126126 */ 
    127127RTR0DECL(int) RTR0MemObjLockUser(PRTR0MEMOBJ pMemObj, void *pv, size_t cb, RTR0PROCESS R0Process); 
     
    135135 * @param   cb              Number of bytes to lock. This is rounded up to nearest page boundrary. 
    136136 * 
    137  * @remark  RTR0MemObjGetAddress() will return the rounded down address. 
     137 * @remark  RTR0MemGetAddress() will return the rounded down address. 
    138138 */ 
    139139RTR0DECL(int) RTR0MemObjLockKernel(PRTR0MEMOBJ pMemObj, void *pv, size_t cb); 
  • trunk/src/VBox/Runtime/Makefile.kmk

    r4071 r4135  
    66# 
    77#  Copyright (C) 2006-2007 innotek GmbH 
    8 #  
     8# 
    99#  This file is part of VirtualBox Open Source Edition (OSE), as 
    1010#  available from http://www.virtualbox.org. This file is free software; 
     
    775775        string/strncmp.cpp 
    776776 
     777#RuntimeR0Drv_SOURCES.win += \ 
     778#       r0drv/memobj-r0drv.cpp \ 
     779#       r0drv/nt/memobj-r0drv-nt.cpp 
     780 
    777781RuntimeR0Drv_SOURCES.win.amd64 = \ 
    778782        $(RuntimeWin64ASM_SOURCES) 
     
    878882        r0drv/solaris/thread-r0drv-solaris.c \ 
    879883        r0drv/solaris/thread2-r0drv-solaris.c 
    880      
     884 
    881885## PORTME: Porters create and add their selection of platform specific Ring-0 Driver files here. 
    882886 
  • trunk/src/VBox/Runtime/include/internal/memobj.h

    r4071 r4135  
    9999    /** The memory address. 
    100100     * What this really is varies with the type. 
    101      * For PAGE, CONT, LOW, RES_VIRT, LOCK/R0 and MAP/R0 it's the ring-0 mapping. 
    102      * For LOCK/R3 and MAP/R3 it is the ring-3 mapping. 
     101     * For PAGE, CONT, LOW, RES_VIRT/R0, LOCK/R0 and MAP/R0 it's the ring-0 mapping. 
     102     * For LOCK/R3, RES_VIRT/R3 and MAP/R3 it is the ring-3 mapping. 
    103103     * For PHYS this might actually be NULL if there isn't any mapping. 
    104104     */ 
     
    352352 * @param   iPage           The page number within the object (valid). 
    353353 */ 
    354 RTHCPHYS rtR0MemObjNativeGetPagePhysAddr(PRTR0MEMOBJINTERNAL pMem, unsigned iPage); 
     354RTHCPHYS rtR0MemObjNativeGetPagePhysAddr(PRTR0MEMOBJINTERNAL pMem, size_t iPage); 
    355355 
    356356PRTR0MEMOBJINTERNAL rtR0MemObjNew(size_t cbSelf, RTR0MEMOBJTYPE enmType, void *pv, size_t cb); 
  • trunk/src/VBox/Runtime/r0drv/darwin/memobj-r0drv-darwin.cpp

    r4071 r4135  
    163163{ 
    164164#if 1 
    165     /*  
     165    /* 
    166166     * Allocating 128KB for the low page pool can bit a bit exhausting on the kernel, 
    167167     * it frequnetly causes the entire box to lock up on startup. 
    168168     * 
    169      * So, try allocate the memory using IOMallocAligned first and if we get any high  
     169     * So, try allocate the memory using IOMallocAligned first and if we get any high 
    170170     * physical memory we'll release it and fall back on IOMAllocContiguous. 
    171171     */ 
     
    219219     */ 
    220220    return rtR0MemObjNativeAllocCont(ppMem, cb, fExecutable); 
    221 #endif  
     221#endif 
    222222} 
    223223 
     
    582582 
    583583 
    584 RTHCPHYS rtR0MemObjNativeGetPagePhysAddr(PRTR0MEMOBJINTERNAL pMem, unsigned iPage) 
     584RTHCPHYS rtR0MemObjNativeGetPagePhysAddr(PRTR0MEMOBJINTERNAL pMem, size_t iPage) 
    585585{ 
    586586    RTHCPHYS            PhysAddr; 
  • trunk/src/VBox/Runtime/r0drv/freebsd/memobj-r0drv-freebsd.c

    r4049 r4135  
    5555    /** The core structure. */ 
    5656    RTR0MEMOBJINTERNAL  Core; 
    57     /** The VM object associated with the allocation. */    
     57    /** The VM object associated with the allocation. */ 
    5858    vm_object_t         pObject; 
    5959    /** the VM object associated with the mapping. 
     
    8383            { 
    8484                rc = vm_map_remove(kernel_map, 
    85                                    (vm_offset_t)pMemFreeBSD->Core.pv,  
     85                                   (vm_offset_t)pMemFreeBSD->Core.pv, 
    8686                                   (vm_offset_t)pMemFreeBSD->Core.pv + pMemFreeBSD->Core.cb); 
    8787                AssertMsg(rc == KERN_SUCCESS, ("%#x", rc)); 
     
    9393            { 
    9494                rc = vm_map_remove(kernel_map, 
    95                                    (vm_offset_t)pMemFreeBSD->Core.pv,  
     95                                   (vm_offset_t)pMemFreeBSD->Core.pv, 
    9696                                   (vm_offset_t)pMemFreeBSD->Core.pv + pMemFreeBSD->Core.cb); 
    9797                AssertMsg(rc == KERN_SUCCESS, ("%#x", rc)); 
     
    103103                { 
    104104                    rc = vm_map_remove(kernel_map, 
    105                                        (vm_offset_t)pMemFreeBSD->Core.pv,  
     105                                       (vm_offset_t)pMemFreeBSD->Core.pv, 
    106106                                       (vm_offset_t)pMemFreeBSD->Core.pv + pMemFreeBSD->Core.cb); 
    107107                    AssertMsg(rc == KERN_SUCCESS, ("%#x", rc)); 
     
    115115            if (pMemFreeBSD->Core.u.Lock.R0Process != NIL_RTR0PROCESS) 
    116116                pMap = &((struct proc *)pMemFreeBSD->Core.u.Lock.R0Process)->p_vmspace->vm_map; 
    117             rc = vm_map_unwire(pMap,  
    118                                (vm_offset_t)pMemFreeBSD->Core.pv,  
    119                                (vm_offset_t)pMemFreeBSD->Core.pv + pMemFreeBSD->Core.cb,  
     117            rc = vm_map_unwire(pMap, 
     118                               (vm_offset_t)pMemFreeBSD->Core.pv, 
     119                               (vm_offset_t)pMemFreeBSD->Core.pv + pMemFreeBSD->Core.cb, 
    120120                               VM_MAP_WIRE_SYSTEM | VM_MAP_WIRE_NOHOLES); 
    121121            AssertMsg(rc == KERN_SUCCESS, ("%#x", rc)); 
     
    129129                pMap = &((struct proc *)pMemFreeBSD->Core.u.Lock.R0Process)->p_vmspace->vm_map; 
    130130            rc = vm_map_remove(pMap, 
    131                                (vm_offset_t)pMemFreeBSD->Core.pv,  
     131                               (vm_offset_t)pMemFreeBSD->Core.pv, 
    132132                               (vm_offset_t)pMemFreeBSD->Core.pv + pMemFreeBSD->Core.cb); 
    133133            AssertMsg(rc == KERN_SUCCESS, ("%#x", rc)); 
    134134            break; 
    135135        } 
    136          
     136 
    137137        case RTR0MEMOBJTYPE_MAPPING: 
    138138        { 
    139139            /** @todo Figure out mapping... */ 
    140140        } 
    141              
    142         /* unused: */     
     141 
     142        /* unused: */ 
    143143        case RTR0MEMOBJTYPE_LOW: 
    144144        case RTR0MEMOBJTYPE_PHYS: 
     
    147147            return VERR_INTERNAL_ERROR; 
    148148    } 
    149      
     149 
    150150    Assert(!pMemFreeBSD->pMappingObject); 
    151151 
     
    162162    if (!pMemFreeBSD) 
    163163        return VERR_NO_MEMORY; 
    164      
    165     /*  
    166      * We've two options here both expressed nicely by how kld allocates  
    167      * memory for the module bits:  
    168      *      http://fxr.watson.org/fxr/source/kern/link_elf.c?v=RELENG62#L701  
     164 
     165    /* 
     166     * We've two options here both expressed nicely by how kld allocates 
     167     * memory for the module bits: 
     168     *      http://fxr.watson.org/fxr/source/kern/link_elf.c?v=RELENG62#L701 
    169169     */ 
    170170#if 0 
     
    183183    { 
    184184        vm_offset_t MapAddress = vm_map_min(kernel_map); 
    185         rc = vm_map_find(kernel_map,                    /* map */  
     185        rc = vm_map_find(kernel_map,                    /* map */ 
    186186                         pMemFreeBSD->pObject,          /* object */ 
    187187                         0,                             /* offset */ 
     
    206206                return VINF_SUCCESS; 
    207207            } 
    208              
     208 
    209209           vm_map_remove(kernel_map, 
    210210                         MapAddress, 
     
    218218        rc = VERR_NO_MEMORY; 
    219219#endif 
    220      
     220 
    221221    rtR0MemObjDelete(&pMemFreeBSD->Core); 
    222222    return rc; 
     
    228228    /* 
    229229     * Try a Alloc first and see if we get luck, if not try contigmalloc. 
    230      * Might wish to try find our own pages or something later if this  
    231      * turns into a problemspot on AMD64 boxes.  
     230     * Might wish to try find our own pages or something later if this 
     231     * turns into a problemspot on AMD64 boxes. 
    232232     */ 
    233233    int rc = rtR0MemObjNativeAllocPage(ppMem, cb, fExecutable); 
     
    271271        return VINF_SUCCESS; 
    272272    } 
    273      
     273 
    274274    NOREF(fExecutable); 
    275275    rtR0MemObjDelete(&pMemFreeBSD->Core); 
     
    281281{ 
    282282    /** @todo check if there is a more appropriate API somewhere.. */ 
    283      
     283 
    284284    /* create the object. */ 
    285285    PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(sizeof(*pMemFreeBSD), RTR0MEMOBJTYPE_CONT, NULL, cb); 
     
    301301        return VINF_SUCCESS; 
    302302    } 
    303      
     303 
    304304    rtR0MemObjDelete(&pMemFreeBSD->Core); 
    305305    return VERR_NO_MEMORY; 
     
    330330    if (!pMemFreeBSD) 
    331331        return VERR_NO_MEMORY; 
    332      
    333     /* 
    334      * We could've used vslock here, but we don't wish to be subject to  
     332 
     333    /* 
     334     * We could've used vslock here, but we don't wish to be subject to 
    335335     * resource usage restrictions, so we'll call vm_map_wire directly. 
    336336     */ 
    337     rc = vm_map_wire(&((struct proc *)R0Process)->p_vmspace->vm_map, /* the map */  
     337    rc = vm_map_wire(&((struct proc *)R0Process)->p_vmspace->vm_map, /* the map */ 
    338338                     (vm_offset_t)pv,                               /* start */ 
    339339                     (vm_offset_t)pv + cb,                          /* end */ 
     
    360360 
    361361    /* lock the memory */ 
    362     rc = vm_map_wire(kernel_map,                                    /* the map */  
     362    rc = vm_map_wire(kernel_map,                                    /* the map */ 
    363363                     (vm_offset_t)pv,                               /* start */ 
    364364                     (vm_offset_t)pv + cb,                          /* end */ 
     
    377377/** 
    378378 * Worker for the two virtual address space reservers. 
    379  *  
     379 * 
    380380 * We're leaning on the examples provided by mmap and vm_mmap in vm_mmap.c here. 
    381381 */ 
     
    383383{ 
    384384    int rc; 
    385      
    386     /*  
     385 
     386    /* 
    387387     * The pvFixed address range must be within the VM space when specified. 
    388388     */ 
     
    391391            ||  (vm_offset_t)pvFixed + cb > vm_map_max(pMap))) 
    392392        return VERR_INVALID_PARAMETER; 
    393      
    394     /*  
    395      * Create the object.  
     393 
     394    /* 
     395     * Create the object. 
    396396     */ 
    397397    PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(sizeof(*pMemFreeBSD), RTR0MEMOBJTYPE_RES_VIRT, NULL, cb); 
     
    412412                          MapAddress, 
    413413                          MapAddress + cb); 
    414                                 
    415         rc = vm_map_find(pMap,                          /* map */  
     414 
     415        rc = vm_map_find(pMap,                          /* map */ 
    416416                         pMemFreeBSD->pObject,          /* object */ 
    417417                         0,                             /* offset */ 
     
    425425        { 
    426426            if (R0Process != NIL_RTR0PROCESS) 
    427             {     
     427            { 
    428428                rc = vm_map_inherit(pMap, 
    429429                                    MapAddress, 
     
    444444    rtR0MemObjDelete(&pMemFreeBSD->Core); 
    445445    return rc; 
    446      
     446 
    447447} 
    448448 
     
    465465 
    466466/* Phys: see pmap_mapdev in i386/i386/pmap.c (http://fxr.watson.org/fxr/source/i386/i386/pmap.c?v=RELENG62#L2860) */ 
    467      
     467 
    468468#if 0 
    469469/** @todo finish the implementation. */ 
     
    515515     * Create a dummy mapping object for it. 
    516516     * 
    517      * All mappings are read/write/execute in OS/2 and there isn't  
     517     * All mappings are read/write/execute in OS/2 and there isn't 
    518518     * any cache options, so sharing is ok. And the main memory object 
    519519     * isn't actually freed until all the mappings have been freed up 
     
    569569            } 
    570570            break; 
    571 #endif  
     571#endif 
    572572            return VERR_NOT_SUPPORTED; 
    573573 
     
    620620 
    621621 
    622 RTHCPHYS rtR0MemObjNativeGetPagePhysAddr(PRTR0MEMOBJINTERNAL pMem, unsigned iPage) 
     622RTHCPHYS rtR0MemObjNativeGetPagePhysAddr(PRTR0MEMOBJINTERNAL pMem, size_t iPage) 
    623623{ 
    624624    PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)pMem; 
     
    633633                /* later */ 
    634634                return NIL_RTHCPHYS; 
    635             }   
     635            } 
    636636        } 
    637637        case RTR0MEMOBJTYPE_PAGE: 
     
    640640            return vtophys(pb); 
    641641        } 
    642              
     642 
    643643        case RTR0MEMOBJTYPE_CONT: 
    644644            return pMemFreeBSD->Core.u.Cont.Phys + (iPage << PAGE_SHIFT); 
  • trunk/src/VBox/Runtime/r0drv/memobj-r0drv.cpp

    r4071 r4135  
    4848        cbSelf = sizeof(*pNew); 
    4949    Assert(cbSelf >= sizeof(*pNew)); 
     50    Assert(cbSelf == (uint32_t)cbSelf); 
    5051 
    5152    /* 
     
    5657    { 
    5758        pNew->u32Magic  = RTR0MEMOBJ_MAGIC; 
    58         pNew->cbSelf    = cbSelf; 
     59        pNew->cbSelf    = (uint32_t)cbSelf; 
    5960        pNew->enmType   = enmType; 
    6061        pNew->cb        = cb; 
     
    160161 
    161162/** 
     163 * Gets the ring-3 address of a ring-0 memory object. 
     164 * 
     165 * This only applies to ring-0 memory object with ring-3 mappings of some kind, i.e. 
     166 * locked user memory, reserved user address space and user mappings. This API should 
     167 * not be used on any other objects. 
     168 * 
     169 * @returns The address of the memory object. 
     170 * @returns NULL if the handle is invalid or if it's not an object with a ring-3 mapping. 
     171 *          Strict builds will assert in both cases. 
     172 * @param   MemObj  The ring-0 memory object handle. 
     173 */ 
     174RTR0DECL(RTR3PTR) RTR0MemObjAddressR3(RTR0MEMOBJ MemObj) 
     175{ 
     176    /* Validate the object handle. */ 
     177    AssertPtrReturn(MemObj, NIL_RTR3PTR); 
     178    PRTR0MEMOBJINTERNAL pMem = (PRTR0MEMOBJINTERNAL)MemObj; 
     179    AssertMsgReturn(pMem->u32Magic == RTR0MEMOBJ_MAGIC, ("%p: %#x\n", pMem, pMem->u32Magic), NIL_RTR3PTR); 
     180    AssertMsgReturn(pMem->enmType > RTR0MEMOBJTYPE_INVALID && pMem->enmType < RTR0MEMOBJTYPE_END, ("%p: %d\n", pMem, pMem->enmType), NIL_RTR3PTR); 
     181    AssertMsgReturn(    (   pMem->enmType == RTR0MEMOBJTYPE_MAPPING 
     182                         && pMem->u.Mapping.R0Process != NIL_RTR0PROCESS) 
     183                    ||  (   pMem->enmType == RTR0MEMOBJTYPE_LOCK 
     184                         && pMem->u.Lock.R0Process != NIL_RTR0PROCESS) 
     185                    ||  (   pMem->enmType == RTR0MEMOBJTYPE_RES_VIRT 
     186                         && pMem->u.ResVirt.R0Process != NIL_RTR0PROCESS), 
     187                    ("%p: %d\n", pMem, pMem->enmType), NIL_RTR3PTR); 
     188 
     189    /* return the mapping address. */ 
     190    return (RTR3PTR)pMem->pv; 
     191} 
     192 
     193 
     194/** 
    162195 * Gets the size of a ring-0 memory object. 
    163196 * 
     
    189222 * @param   iPage   The page number within the object. 
    190223 */ 
    191 RTR0DECL(RTHCPHYS) RTR0MemObjGetPagePhysAddr(RTR0MEMOBJ MemObj, unsigned iPage) 
     224RTR0DECL(RTHCPHYS) RTR0MemObjGetPagePhysAddr(RTR0MEMOBJ MemObj, size_t iPage) 
    192225{ 
    193226    /* Validate the object handle. */ 
     
    198231    AssertMsgReturn(pMem->u32Magic == RTR0MEMOBJ_MAGIC, ("%p: %#x\n", pMem, pMem->u32Magic), NIL_RTHCPHYS); 
    199232    AssertMsgReturn(pMem->enmType > RTR0MEMOBJTYPE_INVALID && pMem->enmType < RTR0MEMOBJTYPE_END, ("%p: %d\n", pMem, pMem->enmType), NIL_RTHCPHYS); 
    200     const unsigned cPages = (pMem->cb >> PAGE_SHIFT); 
     233    const size_t cPages = (pMem->cb >> PAGE_SHIFT); 
    201234    if (iPage >= cPages) 
    202235    { 
     
    408441 * @param   R0Process       The process to lock pages in. NIL_R0PROCESS is an alias for the current one. 
    409442 * 
    410  * @remark  RTR0MemObjGetAddress() will return the rounded down address. 
     443 * @remark  RTR0MemGetAddressR3() and RTR0MemGetAddress() will return the rounded down address. 
    411444 */ 
    412445RTR0DECL(int) RTR0MemObjLockUser(PRTR0MEMOBJ pMemObj, void *pv, size_t cb, RTR0PROCESS R0Process) 
     
    435468 * @param   cb              Number of bytes to lock. This is rounded up to nearest page boundrary. 
    436469 * 
    437  * @remark  RTR0MemObjGetAddress() will return the rounded down address. 
     470 * @remark  RTR0MemGetAddress() will return the rounded down address. 
    438471 */ 
    439472RTR0DECL(int) RTR0MemObjLockKernel(PRTR0MEMOBJ pMemObj, void *pv, size_t cb) 
  • trunk/src/VBox/Runtime/r0drv/nt/memobj-r0drv-nt.cpp

    r4071 r4135  
    11/* $Id$ */ 
    22/** @file 
    3  * innotek Portable Runtime - Ring-0 Memory Objects, Darwin
     3 * innotek Portable Runtime - Ring-0 Memory Objects, NT
    44 */ 
    55 
     
    2020*   Header Files                                                               * 
    2121*******************************************************************************/ 
    22 #include "the-darwin-kernel.h" 
     22#include "the-nt-kernel.h" 
    2323 
    2424#include <iprt/memobj.h> 
     
    3131#include "internal/memobj.h" 
    3232 
    33 #define USE_VM_MAP_WIRE 
     33 
     34/******************************************************************************* 
     35*   Defined Constants And Macros                                               * 
     36*******************************************************************************/ 
     37/** Maximum number of bytes we try to lock down in one go. 
     38 * This is supposed to have a limit right below 256MB, but this appears 
     39 * to actually be much lower. The values here have been determined experimentally. 
     40 */ 
     41#ifdef RT_ARCH_X86 
     42# define MAX_LOCK_MEM_SIZE   (32*1024*1024) /* 32MB */ 
     43#endif 
     44#ifdef RT_ARCH_AMD64 
     45# define MAX_LOCK_MEM_SIZE   (24*1024*1024) /* 24MB */ 
     46#endif 
    3447 
    3548 
     
    3851*******************************************************************************/ 
    3952/** 
    40  * The Darwin version of the memory object structure. 
     53 * The NT version of the memory object structure. 
    4154 */ 
    42 typedef struct RTR0MEMOBJDARWIN 
     55typedef struct RTR0MEMOBJNT 
    4356{ 
    4457    /** The core structure. */ 
    4558    RTR0MEMOBJINTERNAL  Core; 
    46     /** Pointer to the memory descriptor created for allocated and locked memory. */ 
    47     IOMemoryDescriptor *pMemDesc
    48     /** Pointer to the memory mapping object for mapped memory. */ 
    49     IOMemoryMap        *pMemMap
    50 } RTR0MEMOBJDARWIN, *PRTR0MEMOBJDARWIN
     59    /** The number of PMDLs (memory descriptor lists) in the array. */ 
     60    unsigned            cMdls
     61    /** Array of MDL pointers. (variable size) */ 
     62    PMDL                apMdls[1]
     63} RTR0MEMOBJNT, *PRTR0MEMOBJNT
    5164 
    5265 
    5366int rtR0MemObjNativeFree(RTR0MEMOBJ pMem) 
    5467{ 
    55     PRTR0MEMOBJDARWIN pMemDarwin = (PRTR0MEMOBJDARWIN)pMem; 
    56  
    57     /* 
    58      * Release the IOMemoryDescriptor/IOMemoryMap associated with the object. 
    59      */ 
    60     if (pMemDarwin->pMemDesc) 
    61     { 
    62         if (pMemDarwin->Core.enmType == RTR0MEMOBJTYPE_LOCK) 
    63             pMemDarwin->pMemDesc->complete(); /* paranoia */ 
    64         pMemDarwin->pMemDesc->release(); 
    65         pMemDarwin->pMemDesc = NULL; 
    66         Assert(!pMemDarwin->pMemMap); 
    67     } 
    68     else if (pMemDarwin->pMemMap) 
    69     { 
    70         pMemDarwin->pMemMap->release(); 
    71         pMemDarwin->pMemMap = NULL; 
    72     } 
     68    PRTR0MEMOBJNT pMemNt = (PRTR0MEMOBJNT)pMem; 
    7369 
    7470    /* 
    7571     * Release any memory that we've allocated or locked. 
    7672     */ 
    77     switch (pMemDarwin->Core.enmType) 
     73    switch (pMemNt->Core.enmType) 
    7874    { 
    7975        case RTR0MEMOBJTYPE_LOW: 
    8076        case RTR0MEMOBJTYPE_PAGE: 
    81             IOFreeAligned(pMemDarwin->Core.pv, pMemDarwin->Core.cb); 
    8277            break; 
    8378 
    8479        case RTR0MEMOBJTYPE_CONT: 
    85             IOFreeContiguous(pMemDarwin->Core.pv, pMemDarwin->Core.cb); 
    8680            break; 
    8781 
    8882        case RTR0MEMOBJTYPE_LOCK: 
    89         { 
    90 #ifdef USE_VM_MAP_WIRE 
    91             vm_map_t Map = pMemDarwin->Core.u.Lock.R0Process != NIL_RTR0PROCESS 
    92                          ? get_task_map((task_t)pMemDarwin->Core.u.Lock.R0Process) 
    93                          : kernel_map; 
    94             kern_return_t kr = vm_map_unwire(Map, 
    95                                              (vm_map_offset_t)pMemDarwin->Core.pv, 
    96                                              (vm_map_offset_t)pMemDarwin->Core.pv + pMemDarwin->Core.cb, 
    97                                              0 /* not user */); 
    98             AssertRC(kr == KERN_SUCCESS); /** @todo don't ignore... */ 
    99 #endif 
     83            for (unsigned i = 0; i < pMemNt->cMdls; i++) 
     84                MmUnlockPages(pMemNt->apMdl[i]); 
    10085            break; 
    101         } 
    10286 
    10387        case RTR0MEMOBJTYPE_PHYS: 
    104             /*if (pMemDarwin->Core.u.Phys.fAllocated) 
    105                 IOFreePhysical(pMemDarwin->Core.u.Phys.PhysBase, pMemDarwin->Core.cb);*/ 
    106             Assert(!pMemDarwin->Core.u.Phys.fAllocated); 
     88            Assert(!pMemNt->Core.u.Phys.fAllocated); 
    10789            break; 
    10890 
     
    11799 
    118100        default: 
    119             AssertMsgFailed(("enmType=%d\n", pMemDarwin->Core.enmType)); 
     101            AssertMsgFailed(("enmType=%d\n", pMemNt->Core.enmType)); 
    120102            return VERR_INTERNAL_ERROR; 
    121103    } 
    122104 
     105    /* 
     106     * Free any MDLs. 
     107     */ 
     108    for (unsigned i = 0; i < pMemNt->cMdls; i++) 
     109    { 
     110        MmUnlockPages(pMemNt->apMdl[i]); 
     111        IoFreeMdl(pMemNt->u.locked.papMdl[i]); 
     112    } 
    123113    return VINF_SUCCESS; 
    124114} 
     
    141131             * Create the IPRT memory object. 
    142132             */ 
    143             PRTR0MEMOBJDARWIN pMemDarwin = (PRTR0MEMOBJDARWIN)rtR0MemObjNew(sizeof(*pMemDarwin), RTR0MEMOBJTYPE_PAGE, pv, cb); 
    144             if (pMemDarwin
    145             { 
    146                 pMemDarwin->pMemDesc = pMemDesc; 
    147                 *ppMem = &pMemDarwin->Core; 
     133            PRTR0MEMOBJNT pMemNt = (PRTR0MEMOBJNT)rtR0MemObjNew(sizeof(*pMemNt), RTR0MEMOBJTYPE_PAGE, pv, cb); 
     134            if (pMemNt
     135            { 
     136                pMemNt->pMemDesc = pMemDesc; 
     137                *ppMem = &pMemNt->Core; 
    148138                return VINF_SUCCESS; 
    149139            } 
     
    163153{ 
    164154#if 1 
    165     /*  
     155    /* 
    166156     * Allocating 128KB for the low page pool can bit a bit exhausting on the kernel, 
    167157     * it frequnetly causes the entire box to lock up on startup. 
    168158     * 
    169      * So, try allocate the memory using IOMallocAligned first and if we get any high  
     159     * So, try allocate the memory using IOMallocAligned first and if we get any high 
    170160     * physical memory we'll release it and fall back on IOMAllocContiguous. 
    171161     */ 
     
    196186             * Create the IPRT memory object. 
    197187             */ 
    198             PRTR0MEMOBJDARWIN pMemDarwin = (PRTR0MEMOBJDARWIN)rtR0MemObjNew(sizeof(*pMemDarwin), RTR0MEMOBJTYPE_LOW, pv, cb); 
    199             if (pMemDarwin
    200             { 
    201                 pMemDarwin->pMemDesc = pMemDesc; 
    202                 *ppMem = &pMemDarwin->Core; 
     188            PRTR0MEMOBJNT pMemNt = (PRTR0MEMOBJNT)rtR0MemObjNew(sizeof(*pMemNt), RTR0MEMOBJTYPE_LOW, pv, cb); 
     189            if (pMemNt
     190            { 
     191                pMemNt->pMemDesc = pMemDesc; 
     192                *ppMem = &pMemNt->Core; 
    203193                return VINF_SUCCESS; 
    204194            } 
     
    219209     */ 
    220210    return rtR0MemObjNativeAllocCont(ppMem, cb, fExecutable); 
    221 #endif  
     211#endif 
    222212} 
    223213 
     
    246236                 * Create the IPRT memory object. 
    247237                 */ 
    248                 PRTR0MEMOBJDARWIN pMemDarwin = (PRTR0MEMOBJDARWIN)rtR0MemObjNew(sizeof(*pMemDarwin), RTR0MEMOBJTYPE_CONT, pv, cb); 
    249                 if (pMemDarwin
     238                PRTR0MEMOBJNT pMemNt = (PRTR0MEMOBJNT)rtR0MemObjNew(sizeof(*pMemNt), RTR0MEMOBJTYPE_CONT, pv, cb); 
     239                if (pMemNt
    250240                { 
    251                     pMemDarwin->Core.u.Cont.Phys = PhysAddr; 
    252                     pMemDarwin->pMemDesc = pMemDesc; 
    253                     *ppMem = &pMemDarwin->Core; 
     241                    pMemNt->Core.u.Cont.Phys = PhysAddr; 
     242                    pMemNt->pMemDesc = pMemDesc; 
     243                    *ppMem = &pMemNt->Core; 
    254244                    return VINF_SUCCESS; 
    255245                } 
     
    310300                 * Create the IPRT memory object. 
    311301                 */ 
    312                 PRTR0MEMOBJDARWIN pMemDarwin = (PRTR0MEMOBJDARWIN)rtR0MemObjNew(sizeof(*pMemDarwin), RTR0MEMOBJTYPE_PHYS, NULL, cb); 
    313                 if (pMemDarwin
     302                PRTR0MEMOBJNT pMemNt = (PRTR0MEMOBJNT)rtR0MemObjNew(sizeof(*pMemNt), RTR0MEMOBJTYPE_PHYS, NULL, cb); 
     303                if (pMemNt
    314304                { 
    315                     pMemDarwin->Core.u.Phys.PhysBase = PhysAddr; 
    316                     pMemDarwin->Core.u.Phys.fAllocated = true; 
    317                     pMemDarwin->pMemDesc = pMemDesc; 
    318                     *ppMem = &pMemDarwin->Core; 
     305                    pMemNt->Core.u.Phys.PhysBase = PhysAddr; 
     306                    pMemNt->Core.u.Phys.fAllocated = true; 
     307                    pMemNt->pMemDesc = pMemDesc; 
     308                    *ppMem = &pMemNt->Core; 
    319309                    return VINF_SUCCESS; 
    320310                } 
     
    373363             * Create the IPRT memory object. 
    374364             */ 
    375             PRTR0MEMOBJDARWIN pMemDarwin = (PRTR0MEMOBJDARWIN)rtR0MemObjNew(sizeof(*pMemDarwin), RTR0MEMOBJTYPE_PHYS, NULL, cb); 
    376             if (pMemDarwin
    377             { 
    378                 pMemDarwin->Core.u.Phys.PhysBase = PhysAddr; 
    379                 pMemDarwin->Core.u.Phys.fAllocated = false; 
    380                 pMemDarwin->pMemDesc = pMemDesc; 
    381                 *ppMem = &pMemDarwin->Core; 
     365            PRTR0MEMOBJNT pMemNt = (PRTR0MEMOBJNT)rtR0MemObjNew(sizeof(*pMemNt), RTR0MEMOBJTYPE_PHYS, NULL, cb); 
     366            if (pMemNt
     367            { 
     368                pMemNt->Core.u.Phys.PhysBase = PhysAddr; 
     369                pMemNt->Core.u.Phys.fAllocated = false; 
     370                pMemNt->pMemDesc = pMemDesc; 
     371                *ppMem = &pMemNt->Core; 
    382372                return VINF_SUCCESS; 
    383373            } 
     
    423413         * Create the IPRT memory object. 
    424414         */ 
    425         PRTR0MEMOBJDARWIN pMemDarwin = (PRTR0MEMOBJDARWIN)rtR0MemObjNew(sizeof(*pMemDarwin), RTR0MEMOBJTYPE_LOCK, pv, cb); 
    426         if (pMemDarwin
    427         { 
    428             pMemDarwin->Core.u.Lock.R0Process = (RTR0PROCESS)Task; 
    429             *ppMem = &pMemDarwin->Core; 
     415        PRTR0MEMOBJNT pMemNt = (PRTR0MEMOBJNT)rtR0MemObjNew(sizeof(*pMemNt), RTR0MEMOBJTYPE_LOCK, pv, cb); 
     416        if (pMemNt
     417        { 
     418            pMemNt->Core.u.Lock.R0Process = (RTR0PROCESS)Task; 
     419            *ppMem = &pMemNt->Core; 
    430420            return VINF_SUCCESS; 
    431421        } 
     
    451441             * Create the IPRT memory object. 
    452442             */ 
    453             PRTR0MEMOBJDARWIN pMemDarwin = (PRTR0MEMOBJDARWIN)rtR0MemObjNew(sizeof(*pMemDarwin), RTR0MEMOBJTYPE_LOCK, pv, cb); 
    454             if (pMemDarwin
    455             { 
    456                 pMemDarwin->Core.u.Lock.R0Process = (RTR0PROCESS)Task; 
    457                 pMemDarwin->pMemDesc = pMemDesc; 
    458                 *ppMem = &pMemDarwin->Core; 
     443            PRTR0MEMOBJNT pMemNt = (PRTR0MEMOBJNT)rtR0MemObjNew(sizeof(*pMemNt), RTR0MEMOBJTYPE_LOCK, pv, cb); 
     444            if (pMemNt
     445            { 
     446                pMemNt->Core.u.Lock.R0Process = (RTR0PROCESS)Task; 
     447                pMemNt->pMemDesc = pMemDesc; 
     448                *ppMem = &pMemNt->Core; 
    459449                return VINF_SUCCESS; 
    460450            } 
     
    502492     */ 
    503493    int rc = VERR_INVALID_PARAMETER; 
    504     PRTR0MEMOBJDARWIN pMemToMapDarwin = (PRTR0MEMOBJDARWIN)pMemToMap; 
     494    PRTR0MEMOBJNT pMemToMapDarwin = (PRTR0MEMOBJNT)pMemToMap; 
    505495    if (pMemToMapDarwin->pMemDesc) 
    506496    { 
     
    516506                 * Create the IPRT memory object. 
    517507                 */ 
    518                 PRTR0MEMOBJDARWIN pMemDarwin = (PRTR0MEMOBJDARWIN)rtR0MemObjNew(sizeof(*pMemDarwin), RTR0MEMOBJTYPE_MAPPING, 
     508                PRTR0MEMOBJNT pMemNt = (PRTR0MEMOBJNT)rtR0MemObjNew(sizeof(*pMemNt), RTR0MEMOBJTYPE_MAPPING, 
    519509                                                                                pv, pMemToMapDarwin->Core.cb); 
    520                 if (pMemDarwin
     510                if (pMemNt
    521511                { 
    522                     pMemDarwin->Core.u.Mapping.R0Process = NIL_RTR0PROCESS; 
    523                     pMemDarwin->pMemMap = pMemMap; 
    524                     *ppMem = &pMemDarwin->Core; 
     512                    pMemNt->Core.u.Mapping.R0Process = NIL_RTR0PROCESS; 
     513                    pMemNt->pMemMap = pMemMap; 
     514                    *ppMem = &pMemNt->Core; 
    525515                    return VINF_SUCCESS; 
    526516                } 
     
    545535     */ 
    546536    int rc = VERR_INVALID_PARAMETER; 
    547     PRTR0MEMOBJDARWIN pMemToMapDarwin = (PRTR0MEMOBJDARWIN)pMemToMap; 
     537    PRTR0MEMOBJNT pMemToMapDarwin = (PRTR0MEMOBJNT)pMemToMap; 
    548538    if (pMemToMapDarwin->pMemDesc) 
    549539    { 
     
    559549                 * Create the IPRT memory object. 
    560550                 */ 
    561                 PRTR0MEMOBJDARWIN pMemDarwin = (PRTR0MEMOBJDARWIN)rtR0MemObjNew(sizeof(*pMemDarwin), RTR0MEMOBJTYPE_MAPPING, 
     551                PRTR0MEMOBJNT pMemNt = (PRTR0MEMOBJNT)rtR0MemObjNew(sizeof(*pMemNt), RTR0MEMOBJTYPE_MAPPING, 
    562552                                                                                pv, pMemToMapDarwin->Core.cb); 
    563                 if (pMemDarwin
     553                if (pMemNt
    564554                { 
    565                     pMemDarwin->Core.u.Mapping.R0Process = R0Process; 
    566                     pMemDarwin->pMemMap = pMemMap; 
    567                     *ppMem = &pMemDarwin->Core; 
     555                    pMemNt->Core.u.Mapping.R0Process = R0Process; 
     556                    pMemNt->pMemMap = pMemMap; 
     557                    *ppMem = &pMemNt->Core; 
    568558                    return VINF_SUCCESS; 
    569559                } 
     
    585575{ 
    586576    RTHCPHYS            PhysAddr; 
    587     PRTR0MEMOBJDARWIN   pMemDarwin = (PRTR0MEMOBJDARWIN)pMem; 
     577    PRTR0MEMOBJNT   pMemNt = (PRTR0MEMOBJNT)pMem; 
    588578 
    589579#ifdef USE_VM_MAP_WIRE 
     
    592582     * needs to be handled differently. 
    593583     */ 
    594     if (pMemDarwin->Core.enmType == RTR0MEMOBJTYPE_LOCK) 
     584    if (pMemNt->Core.enmType == RTR0MEMOBJTYPE_LOCK) 
    595585    { 
    596586        ppnum_t PgNo; 
    597         if (pMemDarwin->Core.u.Lock.R0Process == NIL_RTR0PROCESS) 
    598             PgNo = pmap_find_phys(kernel_pmap, (uintptr_t)pMemDarwin->Core.pv + iPage * PAGE_SIZE); 
     587        if (pMemNt->Core.u.Lock.R0Process == NIL_RTR0PROCESS) 
     588            PgNo = pmap_find_phys(kernel_pmap, (uintptr_t)pMemNt->Core.pv + iPage * PAGE_SIZE); 
    599589        else 
    600590        { 
     
    624614                AssertReturn(s_offPmap >= 0, NIL_RTHCPHYS); 
    625615            } 
    626             pmap_t Pmap = *(pmap_t *)((uintptr_t)get_task_map((task_t)pMemDarwin->Core.u.Lock.R0Process) + s_offPmap); 
    627             PgNo = pmap_find_phys(Pmap, (uintptr_t)pMemDarwin->Core.pv + iPage * PAGE_SIZE); 
     616            pmap_t Pmap = *(pmap_t *)((uintptr_t)get_task_map((task_t)pMemNt->Core.u.Lock.R0Process) + s_offPmap); 
     617            PgNo = pmap_find_phys(Pmap, (uintptr_t)pMemNt->Core.pv + iPage * PAGE_SIZE); 
    628618        } 
    629619 
     
    638628         * Get the memory descriptor. 
    639629         */ 
    640         IOMemoryDescriptor *pMemDesc = pMemDarwin->pMemDesc; 
     630        IOMemoryDescriptor *pMemDesc = pMemNt->pMemDesc; 
    641631        if (!pMemDesc) 
    642             pMemDesc = pMemDarwin->pMemMap->getMemoryDescriptor(); 
     632            pMemDesc = pMemNt->pMemMap->getMemoryDescriptor(); 
    643633        AssertReturn(pMemDesc, NIL_RTHCPHYS); 
    644634 
  • trunk/src/VBox/Runtime/r0drv/os2/memobj-r0drv-os2.cpp

    r3236 r4135  
    8383        case RTR0MEMOBJTYPE_MAPPING: 
    8484            if (pMemOs2->Core.u.Mapping.R0Process == NIL_RTR0PROCESS) 
    85                 break;  
     85                break; 
    8686 
    8787            /* fall thru */ 
     
    344344     * Create a dummy mapping object for it. 
    345345     * 
    346      * All mappings are read/write/execute in OS/2 and there isn't  
     346     * All mappings are read/write/execute in OS/2 and there isn't 
    347347     * any cache options, so sharing is ok. And the main memory object 
    348348     * isn't actually freed until all the mappings have been freed up 
     
    395395            } 
    396396            break; 
    397 #endif  
     397#endif 
    398398            return VERR_NOT_SUPPORTED; 
    399399 
     
    444444 
    445445 
    446 RTHCPHYS rtR0MemObjNativeGetPagePhysAddr(PRTR0MEMOBJINTERNAL pMem, unsigned iPage) 
     446RTHCPHYS rtR0MemObjNativeGetPagePhysAddr(PRTR0MEMOBJINTERNAL pMem, size_t iPage) 
    447447{ 
    448448    PRTR0MEMOBJOS2 pMemOs2 = (PRTR0MEMOBJOS2)pMem; 

© 2008 Sun Microsystems, Inc.
ContactPrivacy policy