VirtualBox

Changeset 4287 in vbox for trunk/src/VBox/Runtime


Ignore:
Timestamp:
Aug 22, 2007 2:49:19 PM (17 years ago)
Author:
vboxsync
Message:

Solaris

Location:
trunk/src/VBox/Runtime
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/Makefile.kmk

    r4231 r4287  
    882882        r0drv/solaris/assert-r0drv-solaris.c \
    883883        r0drv/solaris/initterm-r0drv-solaris.c \
     884        r0drv/solaris/memobj-r0drv-solaris.c \
    884885        r0drv/solaris/process-r0drv-solaris.c \
    885886        r0drv/solaris/semevent-r0drv-solaris.c \
  • trunk/src/VBox/Runtime/generic/env-generic.cpp

    r4130 r4287  
    3333
    3434#include <string.h>
     35
     36#if defined(RT_OS_SOLARIS)
     37/* It's an implementation detail in Solaris, see
     38 * http://cvs.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/lib/libc/port/gen/getenv.c line 50.
     39 */
     40extern const char               **environ;
     41#endif
    3542
    3643struct RTENVINTERNAL
  • trunk/src/VBox/Runtime/r0drv/solaris/alloc-r0drv-solaris.c

    r4178 r4287  
    2121*******************************************************************************/
    2222#include "the-solaris-kernel.h"
    23 #include <malloc.h>
    2423
    2524#include <iprt/alloc.h>
    2625#include <iprt/assert.h>
    2726#include <iprt/types.h>
     27#include <iprt/param.h>
    2828#include "r0drv/alloc-r0drv.h"
    2929
     
    7474RTR0DECL(void *) RTMemContAlloc(PRTCCPHYS pPhys, size_t cb)
    7575{
    76     /** @todo: implement RTMemContAlloc in Solaris */
    77     /* ddi_umem_alloc without PAGEABLE flag might produce contiguous physical memory, but
    78         the documentation doesn't talk about contiguous at all :(
    79        If we can use ddi_umem_alloc we need to keep track of the ddi_umem_cookie
    80        which kernel allocates, but the ContFree() function only passes us back
    81        the address. Maybe we could for each ContAlloc build a linked list of
    82        structures that have the cookie and corresponding virtual address. */
    83     return NULL;
     76    AssertPtr(pPhys);
     77    Assert(cb > 0);
     78
     79    /* Allocate physically contiguous page-aligned memory. */
     80    caddr_t virtAddr;
     81    int rc = i_ddi_mem_alloc(NULL, &g_SolarisX86PhysMemLimits, cb, 1, 0, NULL, &virtAddr, NULL, NULL);
     82    if (rc != DDI_SUCCESS)
     83        return NULL;
     84
     85    *pPhys = PAGE_SIZE * hat_getpfnum(kas.a_hat, virtAddr);
     86    return virtAddr;
    8487}
    8588
    8689RTR0DECL(void) RTMemContFree(void *pv, size_t cb)
    8790{
    88     /** @todo implement RTMemContFree on solaris, see RTMemContAlloc() for details. */
    89     NOREF(pv);
    9091    NOREF(cb);
     92    if (pv)
     93        i_ddi_mem_free(pv, NULL);
    9194}
  • trunk/src/VBox/Runtime/r0drv/solaris/memobj-r0drv-solaris.c

    r4179 r4287  
    4242    /** The core structure. */
    4343    RTR0MEMOBJINTERNAL  Core;
    44 #if 0
    45     /** Lock for the ring-3 / ring-0 pinned objectes.
    46      * This member might not be allocated for some object types. */
    47     KernVMLock_t        Lock;
    48     /** Array of physical pages.
    49      * This array can be 0 in length for some object types. */
    50     KernPageList_t      aPages[1];
    51 #endif
     44    /** Pointer to kernel memory cookie. */
     45    ddi_umem_cookie_t   Cookie;
     46    /** Shadow locked pages. */
     47    page_t              **ppShadowPages;
    5248} RTR0MEMOBJSOLARIS, *PRTR0MEMOBJSOLARIS;
    5349
     
    6157{
    6258    PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)pMem;
    63 //    int rc;
    6459
    6560    switch (pMemSolaris->Core.enmType)
    6661    {
     62        case RTR0MEMOBJTYPE_CONT:
     63            ddi_mem_free(pMemSolaris->Core.pv);
     64            break;
     65
     66        case RTR0MEMOBJTYPE_PAGE:
     67#if 0
     68            ddi_umem_free(pMemSolaris->Cookie);
     69#endif
     70            ddi_mem_free(pMemSolaris->Core.pv);
     71            break;
     72
     73        case RTR0MEMOBJTYPE_LOCK:
     74        {
     75            struct as* addrSpace;
     76            if (pMemSolaris->Core.u.Lock.R0Process == NIL_RTR0PROCESS)
     77                addrSpace = &kas;
     78            else
     79                addrSpace = ((proc_t *)pMemSolaris->Core.u.Lock.R0Process)->p_as;
     80
     81            as_pageunlock(addrSpace, pMemSolaris->ppShadowPages, pMemSolaris->Core.pv, pMemSolaris->Core.cb, S_WRITE);
     82            break;
     83        }
     84       
     85        case RTR0MEMOBJTYPE_MAPPING:
     86        {
     87            if (pMemSolaris->Core.u.Mapping.R0Process == NIL_RTR0PROCESS)
     88            {
     89                /* Kernel process*/
     90                hat_unload(kas.a_hat, (caddr_t)pMemSolaris->Core.pv, pMemSolaris->Core.cb, HAT_UNLOAD_UNLOCK);
     91                vmem_xfree(heap32_arena, (caddr_t)pMemSolaris->Core.pv, pMemSolaris->Core.cb);
     92            }
     93            else
     94            {
     95                /* User process */
     96                proc_t *p = (proc_t *)pMemSolaris->Core.u.Mapping.R0Process;
     97                struct as *useras = p->p_as;
     98                hat_unload(useras->a_hat, (caddr_t)pMemSolaris->Core.pv, pMemSolaris->Core.cb, HAT_UNLOAD_UNLOCK);
     99            }
     100           
     101            break;
     102        }
     103           
     104        /* unused */
     105        case RTR0MEMOBJTYPE_LOW:
    67106        case RTR0MEMOBJTYPE_PHYS:
    68             if (!pMemSolaris->Core.pv)
    69                 break;
    70 
    71         case RTR0MEMOBJTYPE_MAPPING:
    72             if (pMemSolaris->Core.u.Mapping.R0Process == NIL_RTR0PROCESS)
    73                 break;
    74 
    75         case RTR0MEMOBJTYPE_PAGE:
    76         case RTR0MEMOBJTYPE_LOW:
    77         case RTR0MEMOBJTYPE_CONT:
    78             kmem_free(pMemSolaris->Core.pv, pMemSolaris->Core.cb);
    79             //rc = KernVMFree(pMemSolaris->Core.pv);
    80             //AssertMsg(!rc, ("rc=%d type=%d pv=%p cb=%#zx\n", rc, pMemSolaris->Core.enmType, pMemSolaris->Core.pv, pMemSolaris->Core.cb));
    81             break;
    82 
    83         case RTR0MEMOBJTYPE_LOCK:
    84             //rc = KernVMUnlock(&pMemSolaris->Lock);
    85             //AssertMsg(!rc, ("rc=%d\n", rc));
    86             break;
    87 
    88107        case RTR0MEMOBJTYPE_RES_VIRT:
    89108        default:
     
    91110            return VERR_INTERNAL_ERROR;
    92111    }
    93 
     112   
    94113    return VINF_SUCCESS;
    95114}
     
    98117int rtR0MemObjNativeAllocPage(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable)
    99118{
     119    /* Create the object */
     120    PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_PAGE, NULL, cb);
     121    if (!pMemSolaris)
     122        return VERR_NO_MEMORY;
     123#if 1
     124    /* Allocate physically contiguous page-aligned memory. */
     125    caddr_t virtAddr;
     126    int rc = i_ddi_mem_alloc(NULL, &g_SolarisX86PhysMemLimits, cb, 1, 0, NULL, &virtAddr, NULL, NULL);
     127    if (rc != DDI_SUCCESS)
     128    {
     129        rtR0MemObjDelete(&pMemSolaris->Core);
     130        return VERR_NO_MEMORY;
     131    }
     132   
     133    pMemSolaris->Core.pv = virtAddr;
     134    pMemSolaris->Core.u.Cont.Phys = PAGE_SIZE * hat_getpfnum(kas.a_hat, virtAddr);
     135    *ppMem = &pMemSolaris->Core;   
     136    cmn_err(CE_NOTE, "xAllocPage success physAddr=%p virt=%p\n", PAGE_SIZE * hat_getpfnum(kas.a_hat, virtAddr), virtAddr);
     137#endif
    100138#if 0
    101     int rc = VERR_NO_PAGE_MEMORY;
    102     void *pv = kmem_alloc(cb, KM_SLEEP);
    103     if (!pv)
    104         return rc;
    105 
    106     IOMemoryDescriptor *pMemDesc = IOMemoryDescriptor::withAddress((vm_address_t)pv, cb, kIODirectionInOut, kernel_task);
    107     if (pMemDesc)
    108     {
    109         /*
    110          * Create the IPRT memory object.
    111         */
    112         PRTR0MEMOBJDARWIN pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_PAGE, pv, cb);
    113         if (pMemSolaris)
    114         {
    115             pMemSolaris->pMemDesc = pMemDesc;
    116             *ppMem = &pMemSolaris->Core;
    117             return VINF_SUCCESS;
    118         }
    119 
    120         rc = VERR_NO_MEMORY;
    121         pMemDesc->release();
    122     }
    123     else
    124         rc = VERR_MEMOBJ_INIT_FAILED;
    125     IOFreeAligned(pv, cb);
    126 #endif
    127     return VERR_NOT_IMPLEMENTED;
     139    /* Allocate page-aligned kernel memory */
     140    void *pv = ddi_umem_alloc(cb, DDI_UMEM_SLEEP, &pMemSolaris->Cookie);
     141    if (pv == NULL)
     142    {
     143        rtR0MemObjDelete(&pMemSolaris->Core);
     144        return VERR_NO_MEMORY;
     145    }
     146   
     147    pMemSolaris->Core.pv = pv;
     148    *ppMem = &pMemSolaris->Core;
     149    cmn_err(CE_NOTE, "ddi_umem_alloc, success\n");
     150#endif       
     151    return VINF_SUCCESS;
    128152}
    129153
     
    131155int rtR0MemObjNativeAllocLow(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable)
    132156{
    133     /* create the object */
    134     PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_LOW, NULL, cb);
     157    /* Try page alloc first */
     158    int rc = rtR0MemObjNativeAllocPage(ppMem, cb, fExecutable);
     159    if (RT_SUCCESS(rc))
     160    {
     161        size_t iPage = cb >> PAGE_SHIFT;
     162        while (iPage-- > 0)
     163            if (rtR0MemObjNativeGetPagePhysAddr(*ppMem, iPage) > (_4G - PAGE_SIZE))
     164            {
     165                /* Failed! Fall back to physical contiguous alloc */
     166                cmn_err(CE_NOTE, "4G boundary exceeded\n");
     167                RTR0MemObjFree(*ppMem, false);
     168                rc = rtR0MemObjNativeAllocCont(ppMem, cb, fExecutable);
     169                break;
     170            }
     171    }
     172   
     173    return rc;
     174}
     175
     176
     177int rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable)
     178{
     179    NOREF(fExecutable);
     180
     181    /* Create the object */
     182    PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_CONT, NULL, cb);
    135183    if (!pMemSolaris)
    136184        return VERR_NO_MEMORY;
    137185
    138     /* do the allocation, patiently */
    139     void* pv = kmem_alloc(cb, KM_SLEEP);
    140     if (!pv)
     186    /* Allocate physically contiguous page-aligned memory. */
     187    caddr_t virtAddr;
     188    int rc = i_ddi_mem_alloc(NULL, &g_SolarisX86PhysMemLimits, cb, 1, 0, NULL, &virtAddr, NULL, NULL);
     189    if (rc != DDI_SUCCESS)
    141190    {
    142191        rtR0MemObjDelete(&pMemSolaris->Core);
    143192        return VERR_NO_MEMORY;
    144193    }
    145 
    146     /* associate object with allocated memory */
    147     pMemSolaris->Core.pv = pv;      /* This would be NULL by rtR0MemObjNew(), set it correctly */
    148     *ppMem = &pMemSolaris->Core;
    149     return VINF_SUCCESS;
    150 }
    151 
    152 
    153 int rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable)
    154 {
    155     NOREF(fExecutable);
    156 
    157 #if 0
    158     /* create the object. */
    159     PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, Lock), RTR0MEMOBJTYPE_CONT, NULL, cb);
     194   
     195    pMemSolaris->Core.pv = virtAddr;
     196    pMemSolaris->Core.u.Cont.Phys = PAGE_SIZE * hat_getpfnum(kas.a_hat, virtAddr);
     197    *ppMem = &pMemSolaris->Core;
     198    return VINF_SUCCESS;
     199}
     200
     201
     202int rtR0MemObjNativeAllocPhysNC(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest)
     203{
     204    /** @todo rtR0MemObjNativeAllocPhys / solaris */
     205    return rtR0MemObjNativeAllocPhys(ppMem, cb, PhysHighest);
     206}
     207
     208
     209int rtR0MemObjNativeAllocPhys(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest)
     210{
     211    AssertMsgReturn(PhysHighest >= 16 *_1M, ("PhysHigest=%VHp\n", PhysHighest), VERR_NOT_IMPLEMENTED);
     212
     213    return rtR0MemObjNativeAllocCont(ppMem, cb, false);
     214}
     215
     216
     217int rtR0MemObjNativeEnterPhys(PPRTR0MEMOBJINTERNAL ppMem, RTHCPHYS Phys, size_t cb)
     218{
     219    /* Create the object */
     220    PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_PHYS, NULL, cb);
    160221    if (!pMemSolaris)
    161222        return VERR_NO_MEMORY;
    162 
    163     /* do the allocation. */
    164     ULONG ulPhys = ~0UL;
    165     int rc = KernVMAlloc(cb, VMDHA_FIXED | VMDHA_CONTIG, &pMemSolaris->Core.pv, (PPVOID)&ulPhys, NULL);
    166     if (!rc)
    167     {
    168         Assert(ulPhys != ~0UL);
    169         pMemSolaris->Core.u.Cont.Phys = ulPhys;
    170         *ppMem = &pMemSolaris->Core;
    171         return VINF_SUCCESS;
    172     }
    173     rtR0MemObjDelete(&pMemSolaris->Core);
    174     return RTErrConvertFromOS2(rc);
    175 #endif
    176     return VERR_NOT_IMPLEMENTED;
    177 }
    178 
    179 
    180 int rtR0MemObjNativeAllocPhys(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest)
    181 {
    182 #if 0
    183     AssertMsgReturn(PhysHighest >= 16 *_1M, ("PhysHigest=%VHp\n", PhysHighest), VERR_NOT_IMPLEMENTED);
    184 
    185     /* create the object. */
    186     PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, Lock), RTR0MEMOBJTYPE_PHYS, NULL, cb);
    187     if (!pMemSolaris)
    188         return VERR_NO_MEMORY;
    189 
    190     /* do the allocation. */
    191     ULONG ulPhys = ~0UL;
    192     int rc = KernVMAlloc(cb, VMDHA_FIXED | VMDHA_CONTIG | (PhysHighest < _4G ? VMDHA_16M : 0), &pMemSolaris->Core.pv, (PPVOID)&ulPhys, NULL);
    193     if (!rc)
    194     {
    195         Assert(ulPhys != ~0UL);
    196         pMemSolaris->Core.u.Phys.fAllocated = true;
    197         pMemSolaris->Core.u.Phys.PhysBase = ulPhys;
    198         *ppMem = &pMemSolaris->Core;
    199         return VINF_SUCCESS;
    200     }
    201     rtR0MemObjDelete(&pMemSolaris->Core);
    202     return RTErrConvertFromOS2(rc);
    203 #endif
    204     return VERR_NOT_IMPLEMENTED;
    205 }
    206 
    207 
    208 int rtR0MemObjNativeAllocPhysNC(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest)
    209 {
    210     return VERR_NOT_IMPLEMENTED;
    211 }
    212 
    213 
    214 int rtR0MemObjNativeEnterPhys(PPRTR0MEMOBJINTERNAL ppMem, RTHCPHYS Phys, size_t cb)
    215 {
    216 #if 0
    217     /* create the object. */
    218     PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, Lock), RTR0MEMOBJTYPE_PHYS, NULL, cb);
    219     if (!pMemSolaris)
    220         return VERR_NO_MEMORY;
    221 
    222     /* there is no allocation here, right? it needs to be mapped somewhere first. */
     223   
     224    /* @todo validate Phys as a proper physical address */
     225
     226    /* There is no allocation here, it needs to be mapped somewhere first */
    223227    pMemSolaris->Core.u.Phys.fAllocated = false;
    224228    pMemSolaris->Core.u.Phys.PhysBase = Phys;
    225229    *ppMem = &pMemSolaris->Core;
    226230    return VINF_SUCCESS;
    227 #endif
     231}
     232
     233
     234int rtR0MemObjNativeLockUser(PPRTR0MEMOBJINTERNAL ppMem, RTR3PTR R3Ptr, size_t cb, RTR0PROCESS R0Process)
     235{
     236    /* Create the object */
     237    PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_LOCK, (void*)R3Ptr, cb);
     238    if (!pMemSolaris)
     239        return VERR_NO_MEMORY;
     240
     241    proc_t *userProcess = curproc;
     242    if (R0Process != NIL_RTR0PROCESS)
     243        userProcess = (proc_t *)R0Process;
     244   
     245    struct as* userAddrSpace = userProcess->p_as;
     246    caddr_t userAddr = (caddr_t)((uintptr_t)R3Ptr & (uintptr_t)PAGEMASK);
     247    page_t **ppl;
     248
     249    int rc = as_pagelock(userAddrSpace, &ppl, userAddr, cb, S_WRITE);
     250    if (rc != 0)
     251        return VERR_NO_MEMORY;
     252
     253    pMemSolaris->Core.u.Lock.R0Process = (RTR0PROCESS)userProcess;
     254    pMemSolaris->ppShadowPages = ppl;
     255    *ppMem = &pMemSolaris->Core;
     256   
     257    return VINF_SUCCESS;
     258   
     259#if 0   
     260    /* Lock down the physical pages of current process' virtual address space */
     261    int rc = ddi_umem_lock(pv, cb, DDI_UMEMLOCK_WRITE, &pMemSolaris->Cookie);
     262    if (rc != 0)
     263    {
     264        rtR0MemObjDelete(&pMemSolaris->Core);
     265        return VERR_NO_MEMORY;  /** @todo fix mach -> vbox error conversion for Solaris. */
     266    }
     267
     268    pMemSolaris->Core.u.Lock.R0Process = R0Process;
     269    *ppMem = &pMemSolaris->Core;
     270    return VINF_SUCCESS;
     271#endif   
     272}
     273
     274
     275int rtR0MemObjNativeLockKernel(PPRTR0MEMOBJINTERNAL ppMem, void *pv, size_t cb)
     276{
     277    /* Create the object */
     278    PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_LOCK, pv, cb);
     279    if (!pMemSolaris)
     280        return VERR_NO_MEMORY;
     281
     282    caddr_t userAddr = (caddr_t)((uintptr_t)pv & (uintptr_t)PAGEMASK);
     283    page_t **ppl;
     284   
     285    int rc = as_pagelock(&kas, &ppl, userAddr, cb, S_WRITE);
     286    if (rc != 0)
     287        return VERR_NO_MEMORY;
     288
     289    pMemSolaris->Core.u.Lock.R0Process = NIL_RTR0PROCESS;   /* means kernel, see rtR0MemObjNativeFree() */
     290    pMemSolaris->ppShadowPages = ppl;
     291    *ppMem = &pMemSolaris->Core;
     292   
     293    return VINF_SUCCESS;
     294}
     295
     296
     297int rtR0MemObjNativeReserveKernel(PPRTR0MEMOBJINTERNAL ppMem, void *pvFixed, size_t cb, size_t uAlignment)
     298{
    228299    return VERR_NOT_IMPLEMENTED;
    229300}
    230301
    231302
    232 int rtR0MemObjNativeLockUser(PPRTR0MEMOBJINTERNAL ppMem, RTR3PTR R3Ptr, size_t cb, RTR0PROCESS R0Process)
    233 {
    234 #if 0
    235     AssertMsgReturn(R0Process == RTR0ProcHandleSelf(), ("%p != %p\n", R0Process, RTR0ProcHandleSelf()), VERR_NOT_SUPPORTED);
    236 
    237     /* create the object. */
    238     const ULONG cPages = cb >> PAGE_SHIFT;
    239     PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, aPages[cPages]), RTR0MEMOBJTYPE_LOCK, (void *)R3Ptr, cb);
    240     if (!pMemSolaris)
    241         return VERR_NO_MEMORY;
    242 
    243     /* lock it. */
    244     ULONG cPagesRet = cPages;
    245     int rc = KernVMLock(VMDHL_LONG | VMDHL_WRITE, (void *)R3Ptr, cb, &pMemSolaris->Lock, &pMemSolaris->aPages[0], &cPagesRet);
    246     if (!rc)
    247     {
    248         rtR0MemObjFixPageList(&pMemSolaris->aPages[0], cPages, cPagesRet);
    249         pMemSolaris->Core.u.Lock.R0Process = R0Process;
    250         *ppMem = &pMemSolaris->Core;
    251         return VINF_SUCCESS;
    252     }
    253     rtR0MemObjDelete(&pMemSolaris->Core);
    254     return RTErrConvertFromOS2(rc);
    255 #endif
     303int rtR0MemObjNativeReserveUser(PPRTR0MEMOBJINTERNAL ppMem, RTR3PTR R3PtrFixed, size_t cb, size_t uAlignment, RTR0PROCESS R0Process)
     304{
    256305    return VERR_NOT_IMPLEMENTED;
    257306}
    258307
    259 
    260 int rtR0MemObjNativeLockKernel(PPRTR0MEMOBJINTERNAL ppMem, void *pv, size_t cb)
    261 {
    262 #if 0
    263     /* create the object. */
    264     const ULONG cPages = cb >> PAGE_SHIFT;
    265     PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, aPages[cPages]), RTR0MEMOBJTYPE_LOCK, pv, cb);
    266     if (!pMemSolaris)
    267         return VERR_NO_MEMORY;
    268 
    269     /* lock it. */
    270     ULONG cPagesRet = cPages;
    271     int rc = KernVMLock(VMDHL_LONG | VMDHL_WRITE, pv, cb, &pMemSolaris->Lock, &pMemSolaris->aPages[0], &cPagesRet);
    272     if (!rc)
    273     {
    274         rtR0MemObjFixPageList(&pMemSolaris->aPages[0], cPages, cPagesRet);
    275         pMemSolaris->Core.u.Lock.R0Process = NIL_RTR0PROCESS;
    276         *ppMem = &pMemSolaris->Core;
    277         return VINF_SUCCESS;
    278     }
    279     rtR0MemObjDelete(&pMemSolaris->Core);
    280     return RTErrConvertFromOS2(rc);
    281 #endif
    282     return VERR_NOT_IMPLEMENTED;
    283 }
    284 
    285 
    286 int rtR0MemObjNativeReserveKernel(PPRTR0MEMOBJINTERNAL ppMem, void *pvFixed, size_t cb, size_t uAlignment)
    287 {
    288     return VERR_NOT_IMPLEMENTED;
    289 }
    290 
    291 
    292 int rtR0MemObjNativeReserveUser(PPRTR0MEMOBJINTERNAL ppMem, RTR3PTR R3PtrFixed, size_t cb, size_t uAlignment, RTR0PROCESS R0Process)
    293 {
    294     return VERR_NOT_IMPLEMENTED;
    295 }
    296 
    297 
    298308int rtR0MemObjNativeMapKernel(PPRTR0MEMOBJINTERNAL ppMem, RTR0MEMOBJ pMemToMap, void *pvFixed, size_t uAlignment, unsigned fProt)
    299309{
    300     AssertMsgReturn(pvFixed == (void *)-1, ("%p\n", pvFixed), VERR_NOT_SUPPORTED);
    301 
    302 #if 0
    303 /** @todo finish the implementation. */
    304 
     310    PRTR0MEMOBJSOLARIS pMemToMapSolaris = (PRTR0MEMOBJSOLARIS)pMemToMap;   
     311    size_t size = P2ROUNDUP(pMemToMapSolaris->Core.cb, PAGE_SIZE);
     312    void* pv = pMemToMapSolaris->Core.pv;
     313   
     314    void* kernVirtAddr = vmem_xalloc(heap32_arena, size, PAGE_SIZE, 0, PAGE_SIZE, NULL, 0, VM_SLEEP);
     315    if (kernVirtAddr == NULL)
     316        return VERR_NO_MEMORY;
     317   
     318    hat_devload(kas.a_hat, (caddr_t)kernVirtAddr, size, hat_getpfnum(kas.a_hat, pv), PROT_READ | PROT_WRITE | PROT_EXEC,
     319                HAT_STRICTORDER | HAT_LOAD_NOCONSIST | HAT_LOAD_LOCK);
     320   
     321    /* Create the mapping object */
     322    PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_MAPPING,
     323                                                                    kernVirtAddr, pMemToMapSolaris->Core.cb);
     324    if (pMemSolaris == NULL)
     325    {
     326        hat_unload(kas.a_hat, (caddr_t)kernVirtAddr, size, HAT_UNLOAD_UNLOCK);
     327        vmem_xfree(heap32_arena, kernVirtAddr, size);
     328        return VERR_NO_MEMORY;
     329    }
     330
     331    pMemSolaris->Core.u.Mapping.R0Process = NIL_RTR0PROCESS;    /* NIL_RTR0PROCESS means kernel process */
     332    *ppMem = &pMemSolaris->Core;
     333    return VINF_SUCCESS;
     334}
     335
     336
     337int rtR0MemObjNativeMapUser(PPRTR0MEMOBJINTERNAL ppMem, PRTR0MEMOBJINTERNAL pMemToMap, RTR3PTR R3PtrFixed, size_t uAlignment, unsigned fProt, RTR0PROCESS R0Process)
     338{
     339    PRTR0MEMOBJSOLARIS pMemToMapSolaris = (PRTR0MEMOBJSOLARIS)pMemToMap;   
     340    size_t size = P2ROUNDUP(pMemToMapSolaris->Core.cb, PAGE_SIZE);
     341    proc_t *userproc = (proc_t *)R0Process;
     342    struct as *useras = userproc->p_as;
     343    void *pv = pMemToMapSolaris->Core.pv;
     344    pfn_t pfnum = hat_getpfnum(kas.a_hat, pv);
    305345    int rc;
    306     void *pvR0 = NULL;
    307     PRTR0MEMOBJSOLARIS pMemToMapOs2 = (PRTR0MEMOBJSOLARIS)pMemToMap;
    308     switch (pMemToMapOs2->Core.enmType)
    309     {
    310         /*
    311          * These has kernel mappings.
    312          */
     346   
     347    void* kernVirtAddr = vmem_xalloc(heap32_arena, size, PAGE_SIZE, 0, PAGE_SIZE, NULL, 0, VM_SLEEP);
     348    if (kernVirtAddr == NULL)
     349        return VERR_NO_MEMORY;
     350   
     351    cmn_err(CE_NOTE, "vmem_xalloc successful.\n");
     352   
     353    /* Wrong ones to use: as_map() */
     354    hat_devload(kas.a_hat, (caddr_t)kernVirtAddr, size, pfnum, PROT_READ | PROT_WRITE | PROT_EXEC,
     355                    HAT_STRICTORDER | HAT_LOAD_NOCONSIST | HAT_LOAD_LOCK);
     356   
     357    cmn_err(CE_NOTE, "hat_devload successful.\n");
     358   
     359    /* Create the mapping object */
     360    PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_MAPPING,
     361                                                                    pv, pMemToMapSolaris->Core.cb);
     362    if (pMemSolaris == NULL)
     363    {
     364        /* @todo cleanup */
     365        return VERR_NO_MEMORY;
     366    }
     367
     368    pMemSolaris->Core.u.Mapping.R0Process = R0Process;
     369    *ppMem = &pMemSolaris->Core;
     370    return VINF_SUCCESS;
     371}
     372
     373
     374RTHCPHYS rtR0MemObjNativeGetPagePhysAddr(PRTR0MEMOBJINTERNAL pMem, unsigned iPage)
     375{
     376    PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)pMem;
     377
     378    switch (pMemSolaris->Core.enmType)
     379    {
     380        case RTR0MEMOBJTYPE_LOCK:
     381        {
     382            /* @todo figure this one out */
     383            return NIL_RTHCPHYS;
     384        }
     385       
    313386        case RTR0MEMOBJTYPE_PAGE:
    314387        case RTR0MEMOBJTYPE_LOW:
    315         case RTR0MEMOBJTYPE_CONT:
    316             pvR0 = pMemToMapOs2->Core.pv;
    317             break;
    318 
    319         case RTR0MEMOBJTYPE_PHYS:
    320             pvR0 = pMemToMapOs2->Core.pv;
    321             if (!pvR0)
    322             {
    323                 /* no ring-0 mapping, so allocate a mapping in the process. */
    324                 AssertMsgReturn(uAlignment == PAGE_SIZE, ("%#zx\n", uAlignment), VERR_NOT_SUPPORTED);
    325                 AssertMsgReturn(fProt & RTMEM_PROT_WRITE, ("%#x\n", fProt), VERR_NOT_SUPPORTED);
    326                 Assert(!pMemToMapOs2->Core.u.Phys.fAllocated);
    327                 ULONG ulPhys = pMemToMapOs2->Core.u.Phys.PhysBase;
    328                 rc = KernVMAlloc(pMemToMapOs2->Core.cb, VMDHA_PHYS, &pvR0, (PPVOID)&ulPhys, NULL);
    329                 if (rc)
    330                     return RTErrConvertFromOS2(rc);
    331                 pMemToMapOs2->Core.pv = pvR0;
    332             }
    333             break;
    334 
    335         case RTR0MEMOBJTYPE_LOCK:
    336             if (pMemToMapOs2->Core.u.Lock.R0Process != NIL_RTR0PROCESS)
    337                 return VERR_NOT_SUPPORTED; /** @todo implement this... */
    338             pvR0 = pMemToMapOs2->Core.pv;
    339             break;
    340 
    341         case RTR0MEMOBJTYPE_RES_VIRT:
    342         case RTR0MEMOBJTYPE_MAPPING:
    343         default:
    344             AssertMsgFailed(("enmType=%d\n", pMemToMapOs2->Core.enmType));
    345             return VERR_INTERNAL_ERROR;
    346     }
    347 
    348     /*
    349      * Create a dummy mapping object for it.
    350      *
    351      * All mappings are read/write/execute in OS/2 and there isn't
    352      * any cache options, so sharing is ok. And the main memory object
    353      * isn't actually freed until all the mappings have been freed up
    354      * (reference counting).
    355      */
    356     PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, Lock), RTR0MEMOBJTYPE_MAPPING, pvR0, pMemToMapOs2->Core.cb);
    357     if (pMemSolaris)
    358     {
    359         pMemSolaris->Core.u.Mapping.R0Process = NIL_RTR0PROCESS;
    360         *ppMem = &pMemSolaris->Core;
    361         return VINF_SUCCESS;
    362     }
    363     return VERR_NO_MEMORY;
    364 #endif
    365     return VERR_NOT_IMPLEMENTED;
    366 }
    367 
    368 /*
    369  * Maps a memory object into user virtual address space in the current process.
    370  */
    371 int rtR0MemObjNativeMapUser(PPRTR0MEMOBJINTERNAL ppMem, RTR0MEMOBJ pMemToMap, RTR3PTR R3PtrFixed, size_t uAlignment, unsigned fProt, RTR0PROCESS R0Process)
    372 {
    373 #if 0
    374     int rc = VERR_INVALID_PARAMETER;
    375 
    376     AssertMsgReturn(R0Process == RTR0ProcHandleSelf(), ("%p != %p\n", R0Process, RTR0ProcHandleSelf()), VERR_NOT_SUPPORTED);
    377     AssertMsgReturn(R3PtrFixed == (RTR3PTR)-1, ("%p\n", R3PtrFixed), VERR_NOT_SUPPORTED);
    378 
    379     PRTR0MEMOBJSOLARIS pMemToMapSolaris = (PRTR0MEMOBJSOLARIS)pMemToMap;
    380     caddr_t virtAddr = mmap(pMemToMapSolaris->Core.pv, pMemToMapSolaris->Core.cb, fProt, MAP_ANON, -1, 0);
    381 
    382     if (virtAddr != MAP_FAILED)
    383     {
    384         /*
    385          * Create the IPRT memory object.
    386          */
    387         PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_MAPPING,
    388                                                                         virtAddr, pMemToMapSolaris->Core.cb);
    389         if (pMemSolaris)
    390388        {
    391             pMemSolaris->Core.u.Mapping.R0Process = R0Process;
    392             *ppMem = &pMemSolaris->Core;
    393             return VINF_SUCCESS;
     389            uint8_t *pb = (uint8_t *)pMemSolaris->Core.pv + ((size_t)iPage << PAGE_SHIFT);
     390            return PAGE_SIZE * hat_getpfnum(kas.a_hat, pb);
    394391        }
    395 
    396         munmap(virtAddr, pMemSolaris->Core.cb);
    397         rc = VERR_NO_MEMORY;
    398     }
    399     else
    400         rc = VERR_MAP_FAILED;
    401 
    402     return rc;
    403 #endif
    404     return VERR_NOT_IMPLEMENTED;
    405 }
    406 
    407 
    408 RTHCPHYS rtR0MemObjNativeGetPagePhysAddr(PRTR0MEMOBJINTERNAL pMem, unsigned iPage)
    409 {
    410     PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)pMem;
    411 
    412     switch (pMemSolaris->Core.enmType)
    413     {
    414         case RTR0MEMOBJTYPE_PAGE:
    415         case RTR0MEMOBJTYPE_LOW:
    416         case RTR0MEMOBJTYPE_LOCK:
    417 //            return pMemSolaris->aPages[iPage].Addr;
    418 return NIL_RTHCPHYS;
    419392
    420393        case RTR0MEMOBJTYPE_CONT:
  • trunk/src/VBox/Runtime/r0drv/solaris/process-r0drv-solaris.c

    r4071 r4287  
    2626RTDECL(RTPROCESS) RTProcSelf(void)
    2727{
    28     struct proc *pCurProc = curproc;
    29     struct pid *pPidInfo = pCurProc->p_pidp;
    30    
     28    struct pid *pPidInfo = curproc->p_pidp;
    3129    return pPidInfo->pid_id;
    3230}
  • trunk/src/VBox/Runtime/r0drv/solaris/semevent-r0drv-solaris.c

    r4178 r4287  
    1515 * be useful, but WITHOUT ANY WARRANTY of any kind.
    1616 */
    17 
    18 
    1917
    2018/*******************************************************************************
     
    155153    else
    156154    {
    157         unsigned long timeout;
    158         drv_getparm(LBOLT, &timeout);
    159        
    160155        /*
    161156         * Translate milliseconds into ticks and go to sleep.
    162157         */
    163158        int cTicks;
     159        unsigned long timeout;
    164160        if (cMillies != RT_INDEFINITE_WAIT)
    165161            cTicks = drv_usectohz((clock_t)(cMillies * 1000L));
  • trunk/src/VBox/Runtime/r0drv/solaris/semfastmutex-r0drv-solaris.c

    r4178 r4287  
    3535*******************************************************************************/
    3636/**
    37  * Wrapper for the FreeBSD (sleep) mutex.
     37 * Wrapper for the Solaris mutex.
    3838 */
    3939typedef struct RTSEMFASTMUTEXINTERNAL
  • trunk/src/VBox/Runtime/r0drv/solaris/the-solaris-kernel.h

    r4178 r4287  
    2121#include <sys/kmem.h>
    2222#include <sys/types.h>
    23 #include <sys/sunddi.h>
    24 #include <sys/ddi.h>
    2523#include <sys/mman.h>
    2624#include <sys/thread.h>
     
    3028#include <sys/schedctl.h>
    3129#include <sys/time.h>
     30#include <sys/sysmacros.h>
     31#include <vm/hat.h>
     32#include <vm/seg_kmem.h>
     33#include <sys/ddi.h>
     34#include <sys/sunddi.h>
     35
     36#include <iprt/param.h> /* for PAGE_SIZE */
     37
     38/**
     39 * Used in alloc-r0drv-solaris.c and in memobj-r0drv-solaris.cpp
     40 * Basically needs to be used anywhere where contiguous allocation
     41 * is needed.
     42 *
     43 * @todo r=bird: This should be moved out of this header as it will probably
     44 *               be instantiated in all the files using this header and
     45 *               the compiler will bitch about it not being used.
     46 */
     47static struct ddi_dma_attr g_SolarisX86PhysMemLimits =
     48{
     49    DMA_ATTR_V0,            /* Version Number */
     50    (uint64_t)0,            /* lower limit */
     51    (uint64_t)0xffffffff,   /* high limit (32-bit PA) */
     52    (uint64_t)0xffffffff,   /* counter limit */
     53    (uint64_t)PAGE_SIZE,    /* alignment */
     54    (uint64_t)PAGE_SIZE,    /* burst size */
     55    (uint64_t)PAGE_SIZE,    /* effective DMA size */
     56    (uint64_t)0xffffffff,   /* max DMA xfer size */
     57    (uint64_t)0xffffffff,   /* segment boundary */
     58    512,                    /* s/g length */
     59    1,                      /* device granularity */
     60    0                       /* bus-specific flags */
     61};
    3262
    3363/* commented for now
  • trunk/src/VBox/Runtime/r0drv/solaris/thread-r0drv-solaris.c

    r4178 r4287  
    4747    else
    4848        cTicks = 0;
     49
    4950#if 0
    5051    timeout = ddi_get_lbolt();
     
    5657    cv_init(&cnd, "IPRT Sleep CV", CV_DRIVER, NULL);
    5758    mutex_enter(&mtx);
    58     cv_timedwait (&cnd, &mtx, 9000 * timeout);
     59    cv_timedwait (&cnd, &mtx, timeout);
    5960    mutex_exit(&mtx);
    6061    cv_destroy(&cnd);
  • trunk/src/VBox/Runtime/r0drv/solaris/time-r0drv-solaris.c

    r4179 r4287  
    2626
    2727
    28 /**
    29  * Gets the current nanosecond timestamp.
    30  *
    31  * @returns nanosecond timestamp.
    32  */
    3328RTDECL(uint64_t) RTTimeNanoTS(void)
    3429{
     
    3732
    3833
    39 /**
    40  * Gets the current millisecond timestamp.
    41  *
    42  * @returns millisecond timestamp.
    43  */
    4434RTDECL(uint64_t) RTTimeMilliTS(void)
    4535{
    46     return RTTimeNanoTS() / 1000;
     36    return RTTimeNanoTS() / 1000000;
    4737}
    4838
    4939
    50 /**
    51  * Gets the current nanosecond timestamp.
    52  *
    53  * This differs from RTTimeNanoTS in that it will use system APIs and not do any
    54  * resolution or performance optimizations.
    55  *
    56  * @returns nanosecond timestamp.
    57  */
    5840RTDECL(uint64_t) RTTimeSystemNanoTS(void)
    5941{
     
    6244
    6345
    64 /**
    65  * Gets the current millisecond timestamp.
    66  *
    67  * This differs from RTTimeNanoTS in that it will use system APIs and not do any
    68  * resolution or performance optimizations.
    69  *
    70  * @returns millisecond timestamp.
    71  */
    7246RTDECL(uint64_t) RTTimeSystemMilliTS(void)
    7347{
    74     return RTTimeMilliTS();
     48    return RTTimeNanoTS() / 1000000;
    7549}
    7650
    7751
    78 /**
    79  * Gets the current system time.
    80  *
    81  * @returns pTime.
    82  * @param   pTime   Where to store the time.
    83  */
    8452RTDECL(PRTTIMESPEC) RTTimeNow(PRTTIMESPEC pTime)
    8553{
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