VirtualBox

Changeset 78120 in vbox


Ignore:
Timestamp:
Apr 12, 2019 1:20:50 PM (5 years ago)
Author:
vboxsync
Message:

IPRT: Started adding a RTR0MemObjMapUserEx function that takes offSub and cbSub. bugref:9217

Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/mangling.h

    r78098 r78120  
    17391739# define RTR0MemObjMapKernelTag                         RT_MANGLER(RTR0MemObjMapKernelTag)     /* r0drv */
    17401740# define RTR0MemObjMapUserTag                           RT_MANGLER(RTR0MemObjMapUserTag)       /* r0drv */
     1741# define RTR0MemObjMapUserExTag                         RT_MANGLER(RTR0MemObjMapUserExTag)     /* r0drv */
    17411742# define RTR0MemObjProtect                              RT_MANGLER(RTR0MemObjProtect)          /* r0drv */
    17421743# define RTR0MemObjReserveKernelTag                     RT_MANGLER(RTR0MemObjReserveKernelTag) /* r0drv */
  • trunk/include/iprt/memobj.h

    r76585 r78120  
    607607
    608608/**
     609 * Maps a memory object into user virtual address space in the current process
     610 * (default tag).
     611 *
     612 * @returns IPRT status code.
     613 * @param   pMemObj         Where to store the ring-0 memory object handle of the mapping object.
     614 * @param   MemObjToMap     The object to be map.
     615 * @param   R3PtrFixed      Requested address. (RTR3PTR)-1 means any address. This must match the alignment.
     616 * @param   uAlignment      The alignment of the reserved memory.
     617 *                          Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
     618 * @param   fProt           Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE).
     619 * @param   R0Process       The process to map the memory into. NIL_R0PROCESS is an alias for the current one.
     620 * @param   offSub          Where in the object to start mapping. If non-zero
     621 *                          the value must be page aligned and cbSub must be
     622 *                          non-zero as well.
     623 * @param   cbSub           The size of the part of the object to be mapped. If
     624 *                          zero the entire object is mapped. The value must be
     625 *                          page aligned.
     626 */
     627#define RTR0MemObjMapUserEx(pMemObj, MemObjToMap, R3PtrFixed, uAlignment, fProt, R0Process, offSub, cbSub) \
     628    RTR0MemObjMapUserExTag((pMemObj), (MemObjToMap), (R3PtrFixed), (uAlignment), (fProt), (R0Process), \
     629                           (offSub), (cbSub), RTMEM_TAG)
     630
     631/**
     632 * Maps a memory object into user virtual address space in the current process
     633 * (custom tag).
     634 *
     635 * @returns IPRT status code.
     636 * @param   pMemObj         Where to store the ring-0 memory object handle of the mapping object.
     637 * @param   MemObjToMap     The object to be map.
     638 * @param   R3PtrFixed      Requested address. (RTR3PTR)-1 means any address. This must match the alignment.
     639 * @param   uAlignment      The alignment of the reserved memory.
     640 *                          Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
     641 * @param   fProt           Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE).
     642 * @param   R0Process       The process to map the memory into. NIL_R0PROCESS is an alias for the current one.
     643 * @param   offSub          Where in the object to start mapping. If non-zero
     644 *                          the value must be page aligned and cbSub must be
     645 *                          non-zero as well.
     646 * @param   cbSub           The size of the part of the object to be mapped. If
     647 *                          zero the entire object is mapped. The value must be
     648 *                          page aligned.
     649 * @param   pszTag          Allocation tag used for statistics and such.
     650 */
     651RTR0DECL(int) RTR0MemObjMapUserExTag(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, RTR3PTR R3PtrFixed, size_t uAlignment,
     652                                     unsigned fProt, RTR0PROCESS R0Process, size_t offSub, size_t cbSub, const char *pszTag);
     653
     654/**
    609655 * Change the page level protection of one or more pages in a memory object.
    610656 *
  • trunk/src/VBox/Runtime/include/internal/memobj.h

    r76585 r78120  
    447447 * @param   fProt           Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE).
    448448 * @param   R0Process       The process to map the memory into.
    449  */
    450 DECLHIDDEN(int) rtR0MemObjNativeMapUser(PPRTR0MEMOBJINTERNAL ppMem, PRTR0MEMOBJINTERNAL pMemToMap, RTR3PTR R3PtrFixed, size_t uAlignment, unsigned fProt, RTR0PROCESS R0Process);
     449 * @param   offSub          Where in the object to start mapping. If non-zero
     450 *                          the value must be page aligned and cbSub must be
     451 *                          non-zero as well.
     452 * @param   cbSub           The size of the part of the object to be mapped. If
     453 *                          zero the entire object is mapped. The value must be
     454 *                          page aligned.
     455 */
     456DECLHIDDEN(int) rtR0MemObjNativeMapUser(PPRTR0MEMOBJINTERNAL ppMem, PRTR0MEMOBJINTERNAL pMemToMap, RTR3PTR R3PtrFixed,
     457                                        size_t uAlignment, unsigned fProt, RTR0PROCESS R0Process, size_t offSub, size_t cbSub);
    451458
    452459/**
  • trunk/src/VBox/Runtime/r0drv/darwin/memobj-r0drv-darwin.cpp

    r76553 r78120  
    893893    if (uAlignment > PAGE_SIZE)
    894894        return VERR_NOT_SUPPORTED;
     895    Assert(!offSub || cbSub);
    895896
    896897    IPRT_DARWIN_SAVE_EFL_AC();
     
    959960                         */
    960961                        PRTR0MEMOBJDARWIN pMemDarwin = (PRTR0MEMOBJDARWIN)rtR0MemObjNew(sizeof(*pMemDarwin), RTR0MEMOBJTYPE_MAPPING,
    961                                                                                         pv, cbSub);
     962                                                                                        pv, cbSub ? cbSub : pMemToMap->cb);
    962963                        if (pMemDarwin)
    963964                        {
     
    995996
    996997DECLHIDDEN(int) rtR0MemObjNativeMapUser(PPRTR0MEMOBJINTERNAL ppMem, RTR0MEMOBJ pMemToMap, RTR3PTR R3PtrFixed, size_t uAlignment,
    997                                         unsigned fProt, RTR0PROCESS R0Process)
     998                                        unsigned fProt, RTR0PROCESS R0Process, size_t offSub, size_t cbSub)
    998999{
    9991000    RT_NOREF(fProt);
     
    10051006    if (uAlignment > PAGE_SIZE)
    10061007        return VERR_NOT_SUPPORTED;
     1008    Assert(!offSub || cbSub);
    10071009
    10081010    IPRT_DARWIN_SAVE_EFL_AC();
     
    10191021                                                                              0,
    10201022                                                                              kIOMapAnywhere | kIOMapDefaultCache,
    1021                                                                               0 /* offset */,
    1022                                                                               0 /* length */);
     1023                                                                              offSub,
     1024                                                                              cbSub);
    10231025#else
    10241026        IOMemoryMap *pMemMap = pMemToMapDarwin->pMemDesc->map((task_t)R0Process,
    10251027                                                              0,
    1026                                                               kIOMapAnywhere | kIOMapDefaultCache);
     1028                                                              kIOMapAnywhere | kIOMapDefaultCache,
     1029                                                              offSub,
     1030                                                              cbSub);
    10271031#endif
    10281032        if (pMemMap)
     
    10361040                 */
    10371041                PRTR0MEMOBJDARWIN pMemDarwin = (PRTR0MEMOBJDARWIN)rtR0MemObjNew(sizeof(*pMemDarwin), RTR0MEMOBJTYPE_MAPPING,
    1038                                                                                 pv, pMemToMapDarwin->Core.cb);
     1042                                                                                pv, cbSub ? cbSub : pMemToMap->cb);
    10391043                if (pMemDarwin)
    10401044                {
  • trunk/src/VBox/Runtime/r0drv/freebsd/memobj-r0drv-freebsd.c

    r77131 r78120  
    651651    if (uAlignment > PAGE_SIZE)
    652652        return VERR_NOT_SUPPORTED;
     653    Assert(!offSub || cbSub);
    653654
    654655    int                rc;
     
    711712
    712713DECLHIDDEN(int) rtR0MemObjNativeMapUser(PPRTR0MEMOBJINTERNAL ppMem, RTR0MEMOBJ pMemToMap, RTR3PTR R3PtrFixed, size_t uAlignment,
    713                                         unsigned fProt, RTR0PROCESS R0Process)
     714                                        unsigned fProt, RTR0PROCESS R0Process, size_t offSub, size_t cbSub)
    714715{
    715716    /*
     
    719720    if (uAlignment > PAGE_SIZE)
    720721        return VERR_NOT_SUPPORTED;
     722    Assert(!offSub || cbSub);
    721723
    722724    int                rc;
     
    748750        AddrR3 = (vm_offset_t)R3PtrFixed;
    749751
     752    if (cbSub == 0)
     753        cbSub = pMemToMap->cb - offSub;
     754
    750755    /* Insert the pObject in the map. */
    751756    vm_object_reference(pMemToMapFreeBSD->pObject);
    752757    rc = vm_map_find(pProcMap,              /* Map to insert the object in */
    753758                     pMemToMapFreeBSD->pObject, /* Object to map */
    754                      0,                     /* Start offset in the object */
     759                     offSub,                /* Start offset in the object */
    755760                     &AddrR3,               /* Start address IN/OUT */
    756                      pMemToMap->cb,         /* Size of the mapping */
     761                     cbSub,                 /* Size of the mapping */
    757762#if __FreeBSD_version >= 1000055
    758763                     0,                     /* Upper bound of the mapping */
  • trunk/src/VBox/Runtime/r0drv/haiku/memobj-r0drv-haiku.c

    r76553 r78120  
    478478
    479479int rtR0MemObjNativeMapUser(PPRTR0MEMOBJINTERNAL ppMem, RTR0MEMOBJ pMemToMap, RTR3PTR R3PtrFixed, size_t uAlignment,
    480                             unsigned fProt, RTR0PROCESS R0Process)
     480                            unsigned fProt, RTR0PROCESS R0Process, size_t offSub, size_t cbSub)
    481481{
    482482#if 0
     
    487487    AssertMsgReturn(R3PtrFixed == (RTR3PTR)-1, ("%p\n", R3PtrFixed), VERR_NOT_SUPPORTED);
    488488    if (uAlignment > PAGE_SIZE)
    489     return VERR_NOT_SUPPORTED;
     489        return VERR_NOT_SUPPORTED;
     490    AssertMsgReturn(!offSub && !cbSub, ("%#zx %#zx\n", offSub, cbSub), VERR_NOT_SUPPORTED); /** @todo implement sub maps */
    490491
    491492    int                rc;
  • trunk/src/VBox/Runtime/r0drv/linux/memobj-r0drv-linux.c

    r77730 r78120  
    15301530
    15311531
    1532 DECLHIDDEN(int) rtR0MemObjNativeMapUser(PPRTR0MEMOBJINTERNAL ppMem, RTR0MEMOBJ pMemToMap, RTR3PTR R3PtrFixed,
    1533                                         size_t uAlignment, unsigned fProt, RTR0PROCESS R0Process)
     1532DECLHIDDEN(int) rtR0MemObjNativeMapUser(PPRTR0MEMOBJINTERNAL ppMem, RTR0MEMOBJ pMemToMap, RTR3PTR R3PtrFixed, size_t uAlignment,
     1533                                        unsigned fProt, RTR0PROCESS R0Process, size_t offSub, size_t cbSub)
    15341534{
    15351535    struct task_struct *pTask        = rtR0ProcessToLinuxTask(R0Process);
     
    15501550    if (uAlignment > PAGE_SIZE)
    15511551        return VERR_NOT_SUPPORTED;
     1552    AssertMsgReturn(!offSub && !cbSub, ("%#zx %#zx\n", offSub, cbSub), VERR_NOT_SUPPORTED); /** @todo implement sub maps */
    15521553
    15531554#ifdef VBOX_USE_PAE_HACK
  • trunk/src/VBox/Runtime/r0drv/memobj-r0drv.cpp

    r76553 r78120  
    730730                                   size_t uAlignment, unsigned fProt, RTR0PROCESS R0Process, const char *pszTag)
    731731{
     732    return RTR0MemObjMapUserExTag(pMemObj, MemObjToMap, R3PtrFixed, uAlignment, fProt, R0Process, 0, 0, pszTag);
     733}
     734RT_EXPORT_SYMBOL(RTR0MemObjMapUserTag);
     735
     736
     737RTR0DECL(int) RTR0MemObjMapUserExTag(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, RTR3PTR R3PtrFixed, size_t uAlignment,
     738                                     unsigned fProt, RTR0PROCESS R0Process, size_t offSub, size_t cbSub, const char *pszTag)
     739{
    732740    /* sanity checks. */
    733741    PRTR0MEMOBJINTERNAL pMemToMap;
     
    749757    AssertReturn(fProt != RTMEM_PROT_NONE, VERR_INVALID_PARAMETER);
    750758    AssertReturn(!(fProt & ~(RTMEM_PROT_READ | RTMEM_PROT_WRITE | RTMEM_PROT_EXEC)), VERR_INVALID_PARAMETER);
     759    AssertReturn(!(offSub & PAGE_OFFSET_MASK), VERR_INVALID_PARAMETER);
     760    AssertReturn(offSub < pMemToMap->cb, VERR_INVALID_PARAMETER);
     761    AssertReturn(!(cbSub & PAGE_OFFSET_MASK), VERR_INVALID_PARAMETER);
     762    AssertReturn(cbSub <= pMemToMap->cb, VERR_INVALID_PARAMETER);
     763    AssertReturn((!offSub && !cbSub) || (offSub + cbSub) <= pMemToMap->cb, VERR_INVALID_PARAMETER);
    751764    if (R0Process == NIL_RTR0PROCESS)
    752765        R0Process = RTR0ProcHandleSelf();
     
    755768    RT_NOREF_PV(pszTag);
    756769
     770    /* adjust the request to simplify the native code. */
     771    if (offSub == 0 && cbSub == pMemToMap->cb)
     772        cbSub = 0;
     773
    757774    /* do the mapping. */
    758     rc = rtR0MemObjNativeMapUser(&pNew, pMemToMap, R3PtrFixed, uAlignment, fProt, R0Process);
     775    rc = rtR0MemObjNativeMapUser(&pNew, pMemToMap, R3PtrFixed, uAlignment, fProt, R0Process, offSub, cbSub);
    759776    if (RT_SUCCESS(rc))
    760777    {
     
    776793    return rc;
    777794}
    778 RT_EXPORT_SYMBOL(RTR0MemObjMapUserTag);
     795RT_EXPORT_SYMBOL(RTR0MemObjMapUserExTag);
    779796
    780797
  • trunk/src/VBox/Runtime/r0drv/netbsd/memobj-r0drv-netbsd.c

    r77120 r78120  
    499499
    500500DECLHIDDEN(int) rtR0MemObjNativeMapUser(PPRTR0MEMOBJINTERNAL ppMem, RTR0MEMOBJ pMemToMap, RTR3PTR R3PtrFixed, size_t uAlignment,
    501                                         unsigned fProt, RTR0PROCESS R0Process)
     501                                        unsigned fProt, RTR0PROCESS R0Process, size_t offSub, size_t cbSub)
    502502{
    503503    printf("NativeMapUser\n");
  • trunk/src/VBox/Runtime/r0drv/nt/memobj-r0drv-nt.cpp

    r76553 r78120  
    835835
    836836
    837 DECLHIDDEN(int) rtR0MemObjNativeMapUser(PPRTR0MEMOBJINTERNAL ppMem, RTR0MEMOBJ pMemToMap, RTR3PTR R3PtrFixed,
    838                                         size_t uAlignment, unsigned fProt, RTR0PROCESS R0Process)
     837DECLHIDDEN(int) rtR0MemObjNativeMapUser(PPRTR0MEMOBJINTERNAL ppMem, RTR0MEMOBJ pMemToMap, RTR3PTR R3PtrFixed, size_t uAlignment,
     838                                        unsigned fProt, RTR0PROCESS R0Process, size_t offSub, size_t cbSub)
    839839{
    840840    AssertReturn(R0Process == RTR0ProcHandleSelf(), VERR_NOT_SUPPORTED);
     841    AssertMsgReturn(!offSub && !cbSub, ("%#zx %#zx\n", offSub, cbSub), VERR_NOT_SUPPORTED); /** @todo implement sub maps */
    841842    return rtR0MemObjNtMap(ppMem, pMemToMap, (void *)R3PtrFixed, uAlignment, fProt, R0Process);
    842843}
  • trunk/src/VBox/Runtime/r0drv/os2/memobj-r0drv-os2.cpp

    r77120 r78120  
    428428
    429429
    430 DECLHIDDEN(int) rtR0MemObjNativeMapUser(PPRTR0MEMOBJINTERNAL ppMem, RTR0MEMOBJ pMemToMap, RTR3PTR R3PtrFixed, size_t uAlignment, unsigned fProt, RTR0PROCESS R0Process)
     430DECLHIDDEN(int) rtR0MemObjNativeMapUser(PPRTR0MEMOBJINTERNAL ppMem, RTR0MEMOBJ pMemToMap, RTR3PTR R3PtrFixed, size_t uAlignment,
     431                                        unsigned fProt, RTR0PROCESS R0Process, size_t offSub, size_t cbSub)
    431432{
    432433    AssertMsgReturn(R0Process == RTR0ProcHandleSelf(), ("%p != %p\n", R0Process, RTR0ProcHandleSelf()), VERR_NOT_SUPPORTED);
     
    434435    if (uAlignment > PAGE_SIZE)
    435436        return VERR_NOT_SUPPORTED;
     437    AssertMsgReturn(!offSub && !cbSub, ("%#zx %#zx\n", offSub, cbSub), VERR_NOT_SUPPORTED); /** @todo implement sub maps */
    436438
    437439    int rc;
  • trunk/src/VBox/Runtime/r0drv/solaris/memobj-r0drv-solaris.c

    r76553 r78120  
    10121012
    10131013DECLHIDDEN(int) rtR0MemObjNativeMapUser(PPRTR0MEMOBJINTERNAL ppMem, PRTR0MEMOBJINTERNAL pMemToMap, RTR3PTR R3PtrFixed,
    1014                                         size_t uAlignment, unsigned fProt, RTR0PROCESS R0Process)
     1014                                        size_t uAlignment, unsigned fProt, RTR0PROCESS R0Process, size_t offSub, size_t cbSub)
    10151015{
    10161016    /*
     
    10211021    if (uAlignment != PAGE_SIZE)
    10221022        return VERR_NOT_SUPPORTED;
     1023    AssertMsgReturn(!offSub && !cbSub, ("%#zx %#zx\n", offSub, cbSub), VERR_NOT_SUPPORTED); /** @todo implement sub maps */
    10231024
    10241025    /*
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