VirtualBox

Changeset 1480 in vbox


Ignore:
Timestamp:
Mar 14, 2007 6:27:47 PM (18 years ago)
Author:
vboxsync
Message:

No longer require contiguous memory for the VM structure.
Did long overdue IOCtl cleanup wrt R3/R0 pointers.

Location:
trunk
Files:
23 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/mm.h

    r834 r1480  
    2525#include <VBox/types.h>
    2626#include <VBox/x86.h>
     27#include <VBox/sup.h>
    2728
    2829
     
    767768
    768769/**
     770 * Maps locked R3 virtual memory into the hypervisor region in the GC.
     771 *
     772 * @return VBox status code.
     773 *
     774 * @param   pVM         VM handle.
     775 * @param   pvR3        The ring-3 address of the memory, must be page aligned.
     776 * @param   pvR0        The ring-0 address of the memory, must be page aligned. (optional)
     777 * @param   cPages      The number of pages.
     778 * @param   paPages     The page descriptors.
     779 * @param   pszDesc     Mapping description.
     780 * @param   pGCPtr      Where to store the GC address corresponding to pvHC.
     781 */
     782MMR3DECL(int) MMR3HyperMapPages(PVM pVM, void *pvR3, RTR0PTR pvR0, size_t cPages, PCSUPPAGE paPages, const char *pszDesc, PRTGCPTR pGCPtr);
     783
     784/**
    769785 * Reserves a hypervisor memory area.
    770786 * Most frequent usage is fence pages and dynamically mappings like the guest PD and PDPTR.
  • trunk/include/VBox/sup.h

    r1027 r1480  
    3333 */
    3434
    35 /** Physical page.
     35/**
     36 * Physical page descriptor.
    3637 */
    3738#pragma pack(4) /* space is more important. */
     
    4243    /** Reserved entry for internal use by the caller. */
    4344    RTHCUINTPTR     uReserved;
    44 } SUPPAGE, *PSUPPAGE;
     45} SUPPAGE;
    4546#pragma pack()
     47/** Pointer to a page descriptor. */
     48typedef SUPPAGE *PSUPPAGE;
     49/** Pointer to a const page descriptor. */
     50typedef const SUPPAGE *PCSUPPAGE;
    4651
    4752/**
     
    428433 *                      The pointer stored here on success must be passed to SUPLowFree when
    429434 *                      the memory should be released.
     435 * @param   ppvPagesR0  Where to store the ring-0 pointer to the allocated memory. optional.
    430436 * @param   paPages     Where to store the physical addresses of the individual pages.
    431437 */
    432 SUPR3DECL(int) SUPLowAlloc(unsigned cPages, void **ppvPages, PSUPPAGE paPages);
     438SUPR3DECL(int) SUPLowAlloc(unsigned cPages, void **ppvPages, PRTR0PTR ppvPagesR0, PSUPPAGE paPages);
    433439
    434440/**
     
    537543SUPR0DECL(int) SUPR0ObjVerifyAccess(void *pvObj, PSUPDRVSESSION pSession, const char *pszObjName);
    538544
    539 SUPR0DECL(int) SUPR0LockMem(PSUPDRVSESSION pSession, void *pvR3, unsigned cb, PSUPPAGE paPages);
    540 SUPR0DECL(int) SUPR0UnlockMem(PSUPDRVSESSION pSession, void *pvR3);
    541 SUPR0DECL(int) SUPR0ContAlloc(PSUPDRVSESSION pSession, unsigned cb, void **ppvR0, PRTR3PTR ppvR3, PRTHCPHYS pHCPhys);
    542 SUPR0DECL(int) SUPR0ContFree(PSUPDRVSESSION pSession, void *pv);
    543 SUPR0DECL(int) SUPR0LowAlloc(PSUPDRVSESSION pSession, unsigned cPages, void **ppvR3, PSUPPAGE paPages);
    544 SUPR0DECL(int) SUPR0LowFree(PSUPDRVSESSION pSession, void *pv);
    545 SUPR0DECL(int) SUPR0MemAlloc(PSUPDRVSESSION pSession, unsigned cb, void **ppvR0, void **ppvR3);
    546 SUPR0DECL(int) SUPR0MemGetPhys(PSUPDRVSESSION pSession, void *pv, PSUPPAGE paPages);
    547 SUPR0DECL(int) SUPR0MemFree(PSUPDRVSESSION pSession, void *pv);
    548 SUPR0DECL(int) SUPR0GipMap(PSUPDRVSESSION pSession, PCSUPGLOBALINFOPAGE *ppGip, RTHCPHYS *pHCPhysGid);
     545SUPR0DECL(int) SUPR0LockMem(PSUPDRVSESSION pSession, RTR3PTR pvR3, uint32_t cb, PSUPPAGE paPages);
     546SUPR0DECL(int) SUPR0UnlockMem(PSUPDRVSESSION pSession, RTR3PTR pvR3);
     547SUPR0DECL(int) SUPR0ContAlloc(PSUPDRVSESSION pSession, uint32_t cb, PRTR0PTR ppvR0, PRTR3PTR ppvR3, PRTHCPHYS pHCPhys);
     548SUPR0DECL(int) SUPR0ContFree(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr);
     549SUPR0DECL(int) SUPR0LowAlloc(PSUPDRVSESSION pSession, uint32_t cPages, PRTR0PTR ppvR0, PRTR3PTR ppvR3, PSUPPAGE paPages);
     550SUPR0DECL(int) SUPR0LowFree(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr);
     551SUPR0DECL(int) SUPR0MemAlloc(PSUPDRVSESSION pSession, uint32_t cb, PRTR0PTR ppvR0, PRTR3PTR ppvR3);
     552SUPR0DECL(int) SUPR0MemGetPhys(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr, PSUPPAGE paPages);
     553SUPR0DECL(int) SUPR0MemFree(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr);
     554SUPR0DECL(int) SUPR0GipMap(PSUPDRVSESSION pSession, PCSUPGLOBALINFOPAGE *ppGip, PRTHCPHYS pHCPhysGid);
    549555SUPR0DECL(int) SUPR0GipUnmap(PSUPDRVSESSION pSession);
    550556SUPR0DECL(int) SUPR0Printf(const char *pszFormat, ...);
  • trunk/include/VBox/vm.h

    r1283 r1480  
    2828#include <VBox/stam.h>
    2929#include <VBox/vmapi.h>
     30#include <VBox/sup.h>
    3031
    3132
     
    227228     */
    228229    volatile uint32_t           fForcedActions;
    229     /** Physical address (real) of this structure. */
    230     RTHCPHYS                    HCPhysVM;
     230    /** Pointer to the array of page descriptors for the VM structure allocation. */
     231    R3PTRTYPE(PSUPPAGE)         paVMPagesR3;
    231232    /** Session handle. For use when calling SUPR0 APIs. */
    232233    HCPTRTYPE(PSUPDRVSESSION)   pSession;
     
    318319
    319320    /* padding to make gnuc put the StatQemuToGC where msc does. */
    320 #if HC_ARCH_BITS == 32
     321/*#if HC_ARCH_BITS == 32
    321322    uint32_t            padding0;
    322 #endif
     323#endif*/
    323324
    324325    /** Profiling the total time from Qemu to GC. */
  • trunk/include/VBox/vm.mac

    r1283 r1480  
    4040    .enmVMState         resd 1
    4141    .fForcedActions     resd 1
    42     .HCPhysVM           resq 1
     42    .paVMPagesR3        RTR3PTR_RES 1
    4343    .pSession           RTR3PTR_RES 1
    4444    .pNext              RTHCPTR_RES 1
  • trunk/include/VBox/vmapi.h

    r869 r1480  
    3636 * @{ */
    3737
    38 /** @def VM_PHYS_ADDR
    39  * Converts address of data within the VM structure to the equivalent
    40  * physical address.
    41  *
    42  * @returns physical address.
    43  * @param   pVM     Pointer to the VM.
    44  * @param   pvInVM  Pointer within the VM.
    45  */
    46 #define VM_PHYS_ADDR(pVM, pvInVM)   ( pVM->PhysVM + (uint32_t)((uintptr_t)pvInVM - (uintptr_t)pVM) )
    47 
    4838/** @def VM_GUEST_ADDR
    49  * Converts host address of data within the VM structure to the equivalent
     39 * Converts a current context address of data within the VM structure to the equivalent
    5040 * guest address.
    5141 *
    5242 * @returns guest virtual address.
    5343 * @param   pVM     Pointer to the VM.
    54  * @param   pvInVM  HC Pointer within the VM.
    55  */
    56 #define VM_GUEST_ADDR(pVM, pvInVM)     ( (RTGCPTR)((RTGCUINTPTR)pVM->pVMGC + (uint32_t)((uintptr_t)(pvInVM) - (uintptr_t)pVM->pVMHC)) )
     44 * @param   pvInVM  CC Pointer within the VM.
     45 */
     46#ifdef IN_RING3
     47# define VM_GUEST_ADDR(pVM, pvInVM)     ( (RTGCPTR)((RTGCUINTPTR)pVM->pVMGC + (uint32_t)((uintptr_t)(pvInVM) - (uintptr_t)pVM->pVMR3)) )
     48#elif defined(IN_RING0)
     49# define VM_GUEST_ADDR(pVM, pvInVM)     ( (RTGCPTR)((RTGCUINTPTR)pVM->pVMGC + (uint32_t)((uintptr_t)(pvInVM) - (uintptr_t)pVM->pVMR0)) )
     50#else
     51# define VM_GUEST_ADDR(pVM, pvInVM)     ( (RTGCPTR)(pvInVM) )
     52#endif
     53
     54/** @def VM_R3_ADDR
     55 * Converts a current context address of data within the VM structure to the equivalent
     56 * ring-3 host address.
     57 *
     58 * @returns host virtual address.
     59 * @param   pVM     Pointer to the VM.
     60 * @param   pvInVM  CC pointer within the VM.
     61 */
     62#ifdef IN_GC
     63# define VM_R3_ADDR(pVM, pvInVM)       ( (RTR3PTR)((RTR3UINTPTR)pVM->pVMR3 + (uint32_t)((uintptr_t)(pvInVM) - (uintptr_t)pVM->pVMGC)) )
     64#elif defined(IN_RING0)
     65# define VM_R3_ADDR(pVM, pvInVM)       ( (RTR3PTR)((RTR3UINTPTR)pVM->pVMR3 + (uint32_t)((uintptr_t)(pvInVM) - (uintptr_t)pVM->pVMR0)) )
     66#else
     67# define VM_R3_ADDR(pVM, pvInVM)       ( (RTR3PTR)(pvInVM) )
     68#endif
     69
     70
     71/** @def VM_R0_ADDR
     72 * Converts a current context address of data within the VM structure to the equivalent
     73 * ring-0 host address.
     74 *
     75 * @returns host virtual address.
     76 * @param   pVM     Pointer to the VM.
     77 * @param   pvInVM  CC pointer within the VM.
     78 */
     79#ifdef IN_GC
     80# define VM_R0_ADDR(pVM, pvInVM)       ( (RTR0PTR)((RTR0UINTPTR)pVM->pVMR0 + (uint32_t)((uintptr_t)(pvInVM) - (uintptr_t)pVM->pVMGC)) )
     81#elif defined(IN_RING3)
     82# define VM_R0_ADDR(pVM, pvInVM)       ( (RTR0PTR)((RTR0UINTPTR)pVM->pVMR0 + (uint32_t)((uintptr_t)(pvInVM) - (uintptr_t)pVM->pVMR3)) )
     83#else
     84# define VM_R0_ADDR(pVM, pvInVM)       ( (RTR0PTR)(pvInVM) )
     85#endif
    5786
    5887/** @def VM_HOST_ADDR
     
    6392 * @param   pVM     Pointer to the VM.
    6493 * @param   pvInVM  GC Pointer within the VM.
     94 * @deprecated
    6595 */
    6696#define VM_HOST_ADDR(pVM, pvInVM)     ( (RTHCPTR)((RTHCUINTPTR)pVM->pVMHC + (uint32_t)((uintptr_t)(pvInVM) - (uintptr_t)pVM->pVMGC)) )
     97
    6798
    6899
  • trunk/src/VBox/HostDrivers/Support/SUPDRV.h

    r1193 r1480  
    357357    /** Pointer to the R3 mapping of the memory.
    358358     * Set to NULL if N/A. */
    359     void               *pvR3;
     359    RTR3PTR             pvR3;
    360360    /** Size of the locked memory. */
    361361    unsigned            cb;
     
    662662int  VBOXCALL   supdrvOSLockMemOne(PSUPDRVMEMREF pMem, PSUPPAGE paPages);
    663663void VBOXCALL   supdrvOSUnlockMemOne(PSUPDRVMEMREF pMem);
    664 int  VBOXCALL   supdrvOSContAllocOne(PSUPDRVMEMREF pMem, void **ppvR0, void **ppvR3, PRTHCPHYS pHCPhys);
     664int  VBOXCALL   supdrvOSContAllocOne(PSUPDRVMEMREF pMem, PRTR0PTR ppvR0, PRTR3PTR ppvR3, PRTHCPHYS pHCPhys);
    665665void VBOXCALL   supdrvOSContFreeOne(PSUPDRVMEMREF pMem);
    666 int  VBOXCALL   supdrvOSLowAllocOne(PSUPDRVMEMREF pMem, void **ppvR3, PSUPPAGE paPages);
     666int  VBOXCALL   supdrvOSLowAllocOne(PSUPDRVMEMREF pMem, PRTR0PTR ppvR0, PRTR3PTR ppvR3, PSUPPAGE paPages);
    667667void VBOXCALL   supdrvOSLowFreeOne(PSUPDRVMEMREF pMem);
    668 int  VBOXCALL   supdrvOSMemAllocOne(PSUPDRVMEMREF pMem, void **ppvR0, void **ppvR3);
     668int  VBOXCALL   supdrvOSMemAllocOne(PSUPDRVMEMREF pMem, PRTR0PTR ppvR0, PRTR3PTR ppvR3);
    669669void VBOXCALL   supdrvOSMemGetPages(PSUPDRVMEMREF pMem, PSUPPAGE paPages);
    670670void VBOXCALL   supdrvOSMemFreeOne(PSUPDRVMEMREF pMem);
  • trunk/src/VBox/HostDrivers/Support/SUPDRVIOC.h

    r1193 r1480  
    181181#define SUPCOOKIE_MAGIC             "The Magic Word!"
    182182/** Current interface version. */
    183 #define SUPDRVIOC_VERSION           0x00040000
     183#define SUPDRVIOC_VERSION           0x00040001
    184184
    185185/** SUP_IOCTL_COOKIE Output. */
     
    263263    uint32_t    u32SessionCookie;
    264264    /** Start of page range. Must be PAGE aligned. */
    265     void       *pv;
     265    RTR3PTR     pvR3;
    266266    /** Size of the range. Must be PAGE aligned. */
    267267    uint32_t    cb;
     
    285285    uint32_t    u32SessionCookie;
    286286    /** Start of page range of a range previuosly pinned. */
    287     void        *pv;
     287    RTR3PTR     pvR3;
    288288} SUPUNPINPAGES_IN, *PSUPUNPINPAGES_IN;
    289289
     
    320320    /** Session cookie. */
    321321    uint32_t    u32SessionCookie;
    322     /** The address (virtual, not physical address) of the memory to free. */
    323     void       *pv;
     322    /** The ring-3 address of the memory to free. */
     323    RTR3PTR     pvR3;
    324324} SUPCONTFREE_IN, *PSUPCONTFREE_IN;
    325325
     
    511511typedef struct SUPLOWALLOC_OUT
    512512{
    513     /** The address (virtual & linear) of the allocated memory. */
    514     void       *pvVirt;
     513    /** The ring-3 address of the allocated memory. */
     514    RTR3PTR     pvR3;
     515    /** The ring-0 address of the allocated memory. */
     516    RTR0PTR     pvR0;
    515517    /** Array of pages. */
    516518    SUPPAGE     aPages[1];
     
    525527    /** Session cookie. */
    526528    uint32_t    u32SessionCookie;
    527     /** The address (virtual, not physical address) of the memory to free. */
    528     void       *pv;
     529    /** The ring-3 address of the memory to free. */
     530    RTR3PTR     pvR3;
    529531} SUPLOWFREE_IN, *PSUPLOWFREE_IN;
    530532
  • trunk/src/VBox/HostDrivers/Support/SUPDRVShared.c

    r1193 r1480  
    146146__BEGIN_DECLS
    147147static int      supdrvMemAdd(PSUPDRVMEMREF pMem, PSUPDRVSESSION pSession);
    148 static int      supdrvMemRelease(PSUPDRVSESSION pSession, void *pv, SUPDRVMEMREFTYPE eType);
     148static int      supdrvMemRelease(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr, SUPDRVMEMREFTYPE eType);
    149149#ifndef VBOX_WITHOUT_IDT_PATCHING
    150150static int      supdrvIOCtl_IdtInstall(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPIDTINSTALL_IN pIn, PSUPIDTINSTALL_OUT pOut);
     
    644644                ||  cbOut != sizeof(*pOut))
    645645            {
    646                 dprintf(("SUP_IOCTL_COOKIE: Invalid input/output sizes. cbIn=%d expected %d. cbOut=%d expected %d.\n",
    647                          cbIn, sizeof(*pIn), cbOut, sizeof(*pOut)));
     646                dprintf(("SUP_IOCTL_COOKIE: Invalid input/output sizes. cbIn=%ld expected %ld. cbOut=%ld expected %ld.\n",
     647                         (long)cbIn, (long)sizeof(*pIn), (long)cbOut, (long)sizeof(*pOut)));
    648648                return SUPDRV_ERR_INVALID_PARAM;
    649649            }
     
    685685                ||  cbOut < sizeof(*pOut))
    686686            {
    687                 dprintf(("SUP_IOCTL_QUERY_FUNCS: Invalid input/output sizes. cbIn=%d expected %d. cbOut=%d expected %d.\n",
    688                          cbIn, sizeof(*pIn), cbOut, sizeof(*pOut)));
     687                dprintf(("SUP_IOCTL_QUERY_FUNCS: Invalid input/output sizes. cbIn=%ld expected %ld. cbOut=%ld expected %ld.\n",
     688                         (long)cbIn, (long)sizeof(*pIn), (long)cbOut, (long)sizeof(*pOut)));
    689689                return SUPDRV_ERR_INVALID_PARAM;
    690690            }
     
    723723                ||  cbOut != sizeof(*pOut))
    724724            {
    725                 dprintf(("SUP_IOCTL_INSTALL: Invalid input/output sizes. cbIn=%d expected %d. cbOut=%d expected %d.\n",
    726                          cbIn, sizeof(*pIn), cbOut, sizeof(*pOut)));
     725                dprintf(("SUP_IOCTL_INSTALL: Invalid input/output sizes. cbIn=%ld expected %ld. cbOut=%ld expected %ld.\n",
     726                         (long)cbIn, (long)sizeof(*pIn), (long)cbOut, (long)sizeof(*pOut)));
    727727                return SUPDRV_ERR_INVALID_PARAM;
    728728            }
     
    756756                ||  cbOut != 0)
    757757            {
    758                 dprintf(("SUP_IOCTL_REMOVE: Invalid input/output sizes. cbIn=%d expected %d. cbOut=%d expected %d.\n",
    759                          cbIn, sizeof(*pIn), cbOut, 0));
     758                dprintf(("SUP_IOCTL_REMOVE: Invalid input/output sizes. cbIn=%ld expected %ld. cbOut=%ld expected %ld.\n",
     759                         (long)cbIn, (long)sizeof(*pIn), (long)cbOut, (long)0));
    760760                return SUPDRV_ERR_INVALID_PARAM;
    761761            }
     
    788788                ||  cbOut < sizeof(*pOut))
    789789            {
    790                 dprintf(("SUP_IOCTL_PINPAGES: Invalid input/output sizes. cbIn=%d expected %d. cbOut=%d expected %d.\n",
    791                          cbIn, sizeof(*pIn), cbOut, sizeof(*pOut)));
     790                dprintf(("SUP_IOCTL_PINPAGES: Invalid input/output sizes. cbIn=%ld expected %ld. cbOut=%ld expected %ld.\n",
     791                         (long)cbIn, (long)sizeof(*pIn), (long)cbOut, (long)sizeof(*pOut)));
    792792                return SUPDRV_ERR_INVALID_PARAM;
    793793            }
     
    799799                return SUPDRV_ERR_INVALID_MAGIC;
    800800            }
    801             if (pIn->cb <= 0 || !pIn->pv)
    802             {
    803                 dprintf(("SUP_IOCTL_PINPAGES: Illegal request %p %d\n", pIn->pv, pIn->cb));
     801            if (pIn->cb <= 0 || !pIn->pvR3)
     802            {
     803                dprintf(("SUP_IOCTL_PINPAGES: Illegal request %p %d\n", (void *)pIn->pvR3, pIn->cb));
    804804                return SUPDRV_ERR_INVALID_PARAM;
    805805            }
     
    815815             */
    816816            *pcbReturned = RT_OFFSETOF(SUPPINPAGES_OUT, aPages[pIn->cb >> PAGE_SHIFT]);
    817             rc = SUPR0LockMem(pSession, pIn->pv, pIn->cb, &pOut->aPages[0]);
     817            rc = SUPR0LockMem(pSession, pIn->pvR3, pIn->cb, &pOut->aPages[0]);
    818818            if (rc)
    819819                *pcbReturned = 0;
     
    832832                ||  cbOut != 0)
    833833            {
    834                 dprintf(("SUP_IOCTL_UNPINPAGES: Invalid input/output sizes. cbIn=%d expected %d. cbOut=%d expected %d.\n",
    835                          cbIn, sizeof(*pIn), cbOut, 0));
     834                dprintf(("SUP_IOCTL_UNPINPAGES: Invalid input/output sizes. cbIn=%ld expected %ld. cbOut=%ld expected %ld.\n",
     835                         (long)cbIn, (long)sizeof(*pIn), (long)cbOut, (long)0));
    836836                return SUPDRV_ERR_INVALID_PARAM;
    837837            }
     
    847847             * Execute.
    848848             */
    849             return SUPR0UnlockMem(pSession, pIn->pv);
     849            return SUPR0UnlockMem(pSession, pIn->pvR3);
    850850        }
    851851
     
    862862                ||  cbOut < sizeof(*pOut))
    863863            {
    864                 dprintf(("SUP_IOCTL_CONT_ALLOC: Invalid input/output sizes. cbIn=%d expected %d. cbOut=%d expected %d.\n",
    865                          cbIn, sizeof(*pIn), cbOut, sizeof(*pOut)));
     864                dprintf(("SUP_IOCTL_CONT_ALLOC: Invalid input/output sizes. cbIn=%ld expected %ld. cbOut=%ld expected %ld.\n",
     865                         (long)cbIn, (long)sizeof(*pIn), (long)cbOut, (long)sizeof(*pOut)));
    866866                return SUPDRV_ERR_INVALID_PARAM;
    867867            }
     
    894894                ||  cbOut != 0)
    895895            {
    896                 dprintf(("SUP_IOCTL_CONT_FREE: Invalid input/output sizes. cbIn=%d expected %d. cbOut=%d expected %d.\n",
    897                          cbIn, sizeof(*pIn), cbOut, 0));
     896                dprintf(("SUP_IOCTL_CONT_FREE: Invalid input/output sizes. cbIn=%ld expected %ld. cbOut=%ld expected %ld.\n",
     897                         (long)cbIn, (long)sizeof(*pIn), (long)cbOut, (long)0));
    898898                return SUPDRV_ERR_INVALID_PARAM;
    899899            }
     
    909909             * Execute.
    910910             */
    911             return SUPR0ContFree(pSession, pIn->pv);
     911            return SUPR0ContFree(pSession, (RTHCUINTPTR)pIn->pvR3);
    912912        }
    913913
     
    924924                ||  cbOut != sizeof(*pOut))
    925925            {
    926                 dprintf(("SUP_IOCTL_LDR_OPEN: Invalid input/output sizes. cbIn=%d expected %d. cbOut=%d expected %d.\n",
    927                          cbIn, sizeof(*pIn), cbOut, sizeof(*pOut)));
     926                dprintf(("SUP_IOCTL_LDR_OPEN: Invalid input/output sizes. cbIn=%ld expected %ld. cbOut=%ld expected %ld.\n",
     927                         (long)cbIn, (long)sizeof(*pIn), (long)cbOut, (long)sizeof(*pOut)));
    928928                return SUPDRV_ERR_INVALID_PARAM;
    929929            }
     
    972972                ||  cbOut != 0)
    973973            {
    974                 dprintf(("SUP_IOCTL_LDR_LOAD: Invalid input/output sizes. cbIn=%d expected greater than %d. cbOut=%d expected %d.\n",
    975                          cbIn, sizeof(*pIn), cbOut, 0));
     974                dprintf(("SUP_IOCTL_LDR_LOAD: Invalid input/output sizes. cbIn=%ld expected greater than %ld. cbOut=%ld expected %ld.\n",
     975                         (long)cbIn, (long)sizeof(*pIn), (long)cbOut, (long)0));
    976976                return SUPDRV_ERR_INVALID_PARAM;
    977977            }
     
    10551055                ||  cbOut != 0)
    10561056            {
    1057                 dprintf(("SUP_IOCTL_LDR_FREE: Invalid input/output sizes. cbIn=%d expected %d. cbOut=%d expected %d.\n",
    1058                          cbIn, sizeof(*pIn), cbOut, 0));
     1057                dprintf(("SUP_IOCTL_LDR_FREE: Invalid input/output sizes. cbIn=%ld expected %ld. cbOut=%ld expected %ld.\n",
     1058                         (long)cbIn, (long)sizeof(*pIn), (long)cbOut, (long)0));
    10591059                return SUPDRV_ERR_INVALID_PARAM;
    10601060            }
     
    11021102            if (pszEnd - &pIn->szSymbol[0] >= 1024)
    11031103            {
    1104                 dprintf(("SUP_IOCTL_LDR_GET_SYMBOL: The symbol name too long (%d chars, max is %d)!\n",
    1105                          pszEnd - &pIn->szSymbol[0], 1024));
     1104                dprintf(("SUP_IOCTL_LDR_GET_SYMBOL: The symbol name too long (%ld chars, max is %d)!\n",
     1105                         (long)(pszEnd - &pIn->szSymbol[0]), 1024));
    11061106                return SUPDRV_ERR_INVALID_PARAM;
    11071107            }
     
    11251125                ||  cbOut != sizeof(*pOut))
    11261126            {
    1127                 dprintf(("SUP_IOCTL_CALL_VMMR0: Invalid input/output sizes. cbIn=%d expected %d. cbOut=%d expected %d.\n",
    1128                          cbIn, sizeof(*pIn), cbOut, sizeof(*pOut)));
     1127                dprintf(("SUP_IOCTL_CALL_VMMR0: Invalid input/output sizes. cbIn=%ld expected %ld. cbOut=%ld expected %ld.\n",
     1128                         (long)cbIn, (long)sizeof(*pIn), (long)cbOut, (long)sizeof(*pOut)));
    11291129                return SUPDRV_ERR_INVALID_PARAM;
    11301130            }
     
    11641164                ||  cbOut != sizeof(*pOut))
    11651165            {
    1166                 dprintf(("SUP_IOCTL_GET_PAGING_MODE: Invalid input/output sizes. cbIn=%d expected %d. cbOut=%d expected %d.\n",
    1167                          cbIn, sizeof(*pIn), cbOut, sizeof(*pOut)));
     1166                dprintf(("SUP_IOCTL_GET_PAGING_MODE: Invalid input/output sizes. cbIn=%ld expected %ld. cbOut=%ld expected %ld.\n",
     1167                         (long)cbIn, (long)sizeof(*pIn), (long)cbOut, (long)sizeof(*pOut)));
    11681168                return SUPDRV_ERR_INVALID_PARAM;
    11691169            }
     
    11991199                ||  cbOut < sizeof(*pOut))
    12001200            {
    1201                 dprintf(("SUP_IOCTL_LOW_ALLOC: Invalid input/output sizes. cbIn=%d expected %d. cbOut=%d expected %d.\n",
    1202                          cbIn, sizeof(*pIn), cbOut, sizeof(*pOut)));
     1201                dprintf(("SUP_IOCTL_LOW_ALLOC: Invalid input/output sizes. cbIn=%ld expected %ld. cbOut=%ld expected %ld.\n",
     1202                         (long)cbIn, (long)sizeof(*pIn), (long)cbOut, (long)sizeof(*pOut)));
    12031203                return SUPDRV_ERR_INVALID_PARAM;
    12041204            }
     
    12211221             */
    12221222            *pcbReturned = RT_OFFSETOF(SUPLOWALLOC_OUT, aPages[pIn->cPages]);
    1223             rc = SUPR0LowAlloc(pSession, pIn->cPages, &pOut->pvVirt, &pOut->aPages[0]);
     1223            rc = SUPR0LowAlloc(pSession, pIn->cPages, &pOut->pvR0, &pOut->pvR3, &pOut->aPages[0]);
    12241224            if (rc)
    12251225                *pcbReturned = 0;
     
    12381238                ||  cbOut != 0)
    12391239            {
    1240                 dprintf(("SUP_IOCTL_LOW_FREE: Invalid input/output sizes. cbIn=%d expected %d. cbOut=%d expected %d.\n",
    1241                          cbIn, sizeof(*pIn), cbOut, 0));
     1240                dprintf(("SUP_IOCTL_LOW_FREE: Invalid input/output sizes. cbIn=%ld expected %ld. cbOut=%ld expected %ld.\n",
     1241                         (long)cbIn, (long)sizeof(*pIn), (long)cbOut, (long)0));
    12421242                return SUPDRV_ERR_INVALID_PARAM;
    12431243            }
     
    12531253             * Execute.
    12541254             */
    1255             return SUPR0LowFree(pSession, pIn->pv);
     1255            return SUPR0LowFree(pSession, (RTHCUINTPTR)pIn->pvR3);
    12561256        }
    12571257
     
    12691269                ||  cbOut != sizeof(*pOut))
    12701270            {
    1271                 dprintf(("SUP_IOCTL_GIP_MAP: Invalid input/output sizes. cbIn=%d expected %d. cbOut=%d expected %d.\n",
    1272                          cbIn, sizeof(*pIn), cbOut, 0));
     1271                dprintf(("SUP_IOCTL_GIP_MAP: Invalid input/output sizes. cbIn=%ld expected %ld. cbOut=%ld expected %ld.\n",
     1272                         (long)cbIn, (long)sizeof(*pIn), (long)cbOut, (long)0));
    12731273                return SUPDRV_ERR_INVALID_PARAM;
    12741274            }
     
    13041304                ||  cbOut != 0)
    13051305            {
    1306                 dprintf(("SUP_IOCTL_GIP_UNMAP: Invalid input/output sizes. cbIn=%d expected %d. cbOut=%d expected %d.\n",
    1307                          cbIn, sizeof(*pIn), cbOut, 0));
     1306                dprintf(("SUP_IOCTL_GIP_UNMAP: Invalid input/output sizes. cbIn=%ld expected %ld. cbOut=%ld expected %ld.\n",
     1307                         (long)cbIn, (long)sizeof(*pIn), (long)cbOut, (long)0));
    13081308                return SUPDRV_ERR_INVALID_PARAM;
    13091309            }
     
    13331333                ||  cbOut != 0)
    13341334            {
    1335                 dprintf(("SUP_IOCTL_SET_VM_FOR_FAST: Invalid input/output sizes. cbIn=%d expected %d. cbOut=%d expected %d.\n",
    1336                          cbIn, sizeof(*pIn), cbOut, 0));
     1335                dprintf(("SUP_IOCTL_SET_VM_FOR_FAST: Invalid input/output sizes. cbIn=%ld expected %ld. cbOut=%ld expected %ld.\n",
     1336                         (long)cbIn, (long)sizeof(*pIn), (long)cbOut, (long)0));
    13371337                return SUPDRV_ERR_INVALID_PARAM;
    13381338            }
     
    17321732 *                      This must be page aligned.
    17331733 */
    1734 SUPR0DECL(int) SUPR0LockMem(PSUPDRVSESSION pSession, void *pvR3, unsigned cb, PSUPPAGE paPages)
     1734SUPR0DECL(int) SUPR0LockMem(PSUPDRVSESSION pSession, RTR3PTR pvR3, uint32_t cb, PSUPPAGE paPages)
    17351735{
    17361736    int             rc;
    17371737    SUPDRVMEMREF    Mem = {0};
    17381738    dprintf(("SUPR0LockMem: pSession=%p pvR3=%p cb=%d paPages=%p\n",
    1739              pSession, pvR3, cb, paPages));
     1739             pSession, (void *)pvR3, cb, paPages));
    17401740
    17411741    /*
    17421742     * Verify input.
    17431743     */
    1744     if (RT_ALIGN_R3PT(pvR3, PAGE_SIZE, void *) != pvR3 || !pvR3)
    1745     {
    1746         dprintf(("pvR3 (%p) must be page aligned and not NULL!\n", pvR3));
     1744    if (RT_ALIGN_R3PT(pvR3, PAGE_SIZE, RTR3PTR) != pvR3 || !pvR3)
     1745    {
     1746        dprintf(("pvR3 (%p) must be page aligned and not NULL!\n", (void *)pvR3));
    17471747        return SUPDRV_ERR_INVALID_PARAM;
    17481748    }
    1749     if (RT_ALIGN(cb, PAGE_SIZE) != cb)
     1749    if (RT_ALIGN_Z(cb, PAGE_SIZE) != cb)
    17501750    {
    17511751        dprintf(("cb (%u) must be page aligned!\n", cb));
     
    18221822 * @param   pvR3        Memory to unlock.
    18231823 */
    1824 SUPR0DECL(int) SUPR0UnlockMem(PSUPDRVSESSION pSession, void *pvR3)
    1825 {
    1826     dprintf(("SUPR0UnlockMem: pSession=%p pvR3=%p\n", pSession, pvR3));
    1827     return supdrvMemRelease(pSession, pvR3, MEMREF_TYPE_LOCKED);
     1824SUPR0DECL(int) SUPR0UnlockMem(PSUPDRVSESSION pSession, RTR3PTR pvR3)
     1825{
     1826    dprintf(("SUPR0UnlockMem: pSession=%p pvR3=%p\n", pSession, (void *)pvR3));
     1827    return supdrvMemRelease(pSession, (RTHCUINTPTR)pvR3, MEMREF_TYPE_LOCKED);
    18281828}
    18291829
     
    18371837 * @param   pSession    Session data.
    18381838 * @param   cb          Number of bytes to allocate.
    1839  * @param   ppvR0       Where to put the address of Ring-0 mapping the allocated memory. optional
     1839 * @param   ppvR0       Where to put the address of Ring-0 mapping the allocated memory.
    18401840 * @param   ppvR3       Where to put the address of Ring-3 mapping the allocated memory.
    18411841 * @param   pHCPhys     Where to put the physical address of allocated memory.
    18421842 */
    1843 SUPR0DECL(int) SUPR0ContAlloc(PSUPDRVSESSION pSession, unsigned cb, void **ppvR0, PRTR3PTR ppvR3, PRTHCPHYS pHCPhys)
     1843SUPR0DECL(int) SUPR0ContAlloc(PSUPDRVSESSION pSession, uint32_t cb, PRTR0PTR ppvR0, PRTR3PTR ppvR3, PRTHCPHYS pHCPhys)
    18441844{
    18451845    int             rc;
     
    18501850     * Validate input.
    18511851     */
    1852     if (!pSession || !ppvR3 || !pHCPhys)
    1853     {
    1854         dprintf(("Null pointer. All of these should be set: pSession=%p ppvR3=%p pHCPhys=%p\n",
    1855                  pSession, ppvR3, pHCPhys));
     1852    if (!pSession || !ppvR3 || !ppvR0 || !pHCPhys)
     1853    {
     1854        dprintf(("Null pointer. All of these should be set: pSession=%p ppvR0=%p ppvR3=%p pHCPhys=%p\n",
     1855                 pSession, ppvR0, ppvR3, pHCPhys));
    18561856        return SUPDRV_ERR_INVALID_PARAM;
    18571857
     
    18791879            if (!rc)
    18801880            {
    1881                 if (ppvR0)
    1882                     *ppvR0 = RTR0MemObjAddress(Mem.MemObj);
    1883                 *ppvR3 = RTR0MemObjAddress(Mem.MapObjR3);
     1881                *ppvR0 = RTR0MemObjAddress(Mem.MemObj);
     1882                *ppvR3 = (RTR3PTR)RTR0MemObjAddress(Mem.MapObjR3);
    18841883                *pHCPhys = RTR0MemObjGetPagePhysAddr(Mem.MemObj, 0);
    18851884                return 0;
     
    18991898     */
    19001899    Mem.pvR0    = NULL;
    1901     Mem.pvR3    = NULL;
     1900    Mem.pvR3    = NIL_RTR3PTR;
    19021901    Mem.eType   = MEMREF_TYPE_CONT;
    19031902    Mem.cb      = cb;
     
    19261925 * @returns SUPDRV_ERR_* on failure.
    19271926 * @param   pSession    The session to which the memory was allocated.
    1928  * @param   pv          Pointer to the memory.
    1929  */
    1930 SUPR0DECL(int) SUPR0ContFree(PSUPDRVSESSION pSession, void *pv)
    1931 {
    1932     dprintf(("SUPR0ContFree: pSession=%p pv=%p\n", pSession, pv));
    1933     return supdrvMemRelease(pSession, pv, MEMREF_TYPE_CONT);
     1927 * @param   uPtr        Pointer to the memory (ring-3 or ring-0).
     1928 */
     1929SUPR0DECL(int) SUPR0ContFree(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr)
     1930{
     1931    dprintf(("SUPR0ContFree: pSession=%p uPtr=%p\n", pSession, (void *)uPtr));
     1932    return supdrvMemRelease(pSession, uPtr, MEMREF_TYPE_CONT);
    19341933}
    19351934
     
    19421941 * @param   pSession    Session data.
    19431942 * @param   cPages      Number of pages to allocate.
     1943 * @param   ppvR0       Where to put the address of Ring-0 mapping of the allocated memory.
    19441944 * @param   ppvR3       Where to put the address of Ring-3 mapping of the allocated memory.
    19451945 * @param   paPages     Where to put the physical addresses of allocated memory.
    19461946 */
    1947 SUPR0DECL(int) SUPR0LowAlloc(PSUPDRVSESSION pSession, unsigned cPages, void **ppvR3, PSUPPAGE paPages)
     1947SUPR0DECL(int) SUPR0LowAlloc(PSUPDRVSESSION pSession, uint32_t cPages, PRTR0PTR ppvR0, PRTR3PTR ppvR3, PSUPPAGE paPages)
    19481948{
    19491949    unsigned        iPage;
    19501950    int             rc;
    19511951    SUPDRVMEMREF    Mem = {0};
    1952     dprintf(("SUPR0LowAlloc: pSession=%p cPages=%d ppvR3=%p paPages=%p\n", pSession, cPages, ppvR3, paPages));
     1952    dprintf(("SUPR0LowAlloc: pSession=%p cPages=%d ppvR3=%p ppvR0=%p paPages=%p\n", pSession, cPages, ppvR3, ppvR0, paPages));
    19531953
    19541954    /*
    19551955     * Validate input.
    19561956     */
    1957     if (!pSession || !ppvR3 || !paPages)
    1958     {
    1959         dprintf(("Null pointer. All of these should be set: pSession=%p ppvR3=%p paPages=%p\n",
    1960                  pSession, ppvR3, paPages));
     1957    if (!pSession || !ppvR3 || !ppvR0 || !paPages)
     1958    {
     1959        dprintf(("Null pointer. All of these should be set: pSession=%p ppvR3=%p ppvR0=%p paPages=%p\n",
     1960                 pSession, ppvR3, ppvR0, paPages));
    19611961        return SUPDRV_ERR_INVALID_PARAM;
    19621962
     
    19901990                    AssertMsg(!(paPages[iPage].Phys & (PAGE_SIZE - 1)), ("iPage=%d Phys=%VHp\n", paPages[iPage].Phys));
    19911991                }
    1992                 /*if (ppvR0)
    1993                     *ppvR0 = RTR0MemObjAddress(Mem.MemObj); */
     1992                *ppvR0 = RTR0MemObjAddress(Mem.MemObj);
    19941993                *ppvR3 = RTR0MemObjAddress(Mem.MapObjR3);
    19951994                return 0;
     
    20102009     */
    20112010    Mem.pvR0    = NULL;
    2012     Mem.pvR3    = NULL;
     2011    Mem.pvR3    = NIL_RTR3PTR;
    20132012    Mem.eType   = MEMREF_TYPE_LOW;
    20142013    Mem.cb      = cPages << PAGE_SHIFT;
    2015     rc = supdrvOSLowAllocOne(&Mem, ppvR3, paPages);
     2014    rc = supdrvOSLowAllocOne(&Mem, ppvR0, ppvR3, paPages);
    20162015    if (rc)
    20172016        return rc;
    20182017    AssertMsg(!((uintptr_t)*ppvR3 & (PAGE_SIZE - 1)), ("Memory is not page aligned! virt=%p\n", *ppvR3));
     2018    AssertMsg(!((uintptr_t)*ppvR0 & (PAGE_SIZE - 1)), ("Memory is not page aligned! virt=%p\n", *ppvR0));
    20192019    for (iPage = 0; iPage < cPages; iPage++)
    20202020        AssertMsg(!(paPages[iPage].Phys & (PAGE_SIZE - 1)), ("iPage=%d Phys=%VHp\n", paPages[iPage].Phys));
     
    20372037 * @returns SUPDRV_ERR_* on failure.
    20382038 * @param   pSession    The session to which the memory was allocated.
    2039  * @param   pv          Pointer to the memory.
    2040  */
    2041 SUPR0DECL(int) SUPR0LowFree(PSUPDRVSESSION pSession, void *pv)
    2042 {
    2043     dprintf(("SUPR0LowFree: pSession=%p pv=%p\n", pSession, pv));
    2044     return supdrvMemRelease(pSession, pv, MEMREF_TYPE_LOW);
     2039 * @param   uPtr        Pointer to the memory (ring-3 or ring-0).
     2040 */
     2041SUPR0DECL(int) SUPR0LowFree(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr)
     2042{
     2043    dprintf(("SUPR0LowFree: pSession=%p uPtr=%p\n", pSession, (void *)uPtr));
     2044    return supdrvMemRelease(pSession, uPtr, MEMREF_TYPE_LOW);
    20452045}
    20462046
     
    20572057 * @param   ppvR3       Where to store the address of the Ring-3 mapping.
    20582058 */
    2059 SUPR0DECL(int) SUPR0MemAlloc(PSUPDRVSESSION pSession, unsigned cb, void **ppvR0, void **ppvR3)
     2059SUPR0DECL(int) SUPR0MemAlloc(PSUPDRVSESSION pSession, uint32_t cb, PRTR0PTR ppvR0, PRTR3PTR ppvR3)
    20602060{
    20612061    int             rc;
     
    20962096            {
    20972097                *ppvR0 = RTR0MemObjAddress(Mem.MemObj);
    2098                 *ppvR3 = RTR0MemObjAddress(Mem.MapObjR3);
     2098                *ppvR3 = (RTR3PTR)RTR0MemObjAddress(Mem.MapObjR3);
    20992099                return 0;
    21002100            }
     
    21132113     */
    21142114    Mem.pvR0    = NULL;
    2115     Mem.pvR3    = NULL;
     2115    Mem.pvR3    = NIL_RTR3PTR;
    21162116    Mem.eType   = MEMREF_TYPE_MEM;
    21172117    Mem.cb      = cb;
     
    21392139 * @returns SUPDRV_ERR_* on failure.
    21402140 * @param   pSession        The session to which the memory was allocated.
    2141  * @param   pv              The Ring-0 or Ring-3 address returned by SUPR0MemAlloc().
    2142  */
    2143 SUPR0DECL(int) SUPR0MemGetPhys(PSUPDRVSESSION pSession, void *pv, PSUPPAGE paPages)
     2141 * @param   uPtr            The Ring-0 or Ring-3 address returned by SUPR0MemAlloc().
     2142 * @param   paPages         Where to store the physical addresses.
     2143 */
     2144SUPR0DECL(int) SUPR0MemGetPhys(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr, PSUPPAGE paPages)
    21442145{
    21452146    PSUPDRVBUNDLE pBundle;
    21462147    RTSPINLOCKTMP SpinlockTmp = RTSPINLOCKTMP_INITIALIZER;
    2147     dprintf(("SUPR0MemGetPhys: pSession=%p pv=%p paPages=%p\n", pSession, pv, paPages));
     2148    dprintf(("SUPR0MemGetPhys: pSession=%p uPtr=%p paPages=%p\n", pSession, (void *)uPtr, paPages));
    21482149
    21492150    /*
     
    21552156        return SUPDRV_ERR_INVALID_PARAM;
    21562157    }
    2157     if (!pv || !paPages)
    2158     {
    2159         dprintf(("Illegal address pv=%p or/and paPages=%p\n", pv, paPages));
     2158    if (!uPtr || !paPages)
     2159    {
     2160        dprintf(("Illegal address uPtr=%p or/and paPages=%p\n", (void *)uPtr, paPages));
    21602161        return SUPDRV_ERR_INVALID_PARAM;
    21612162    }
     
    21752176                if (    pBundle->aMem[i].eType == MEMREF_TYPE_MEM
    21762177                    &&  pBundle->aMem[i].MemObj != NIL_RTR0MEMOBJ
    2177                     &&  (   RTR0MemObjAddress(pBundle->aMem[i].MemObj) == pv
     2178                    &&  (   (RTHCUINTPTR)RTR0MemObjAddress(pBundle->aMem[i].MemObj) == uPtr
    21782179                         || (   pBundle->aMem[i].MapObjR3 != NIL_RTR0MEMOBJ
    2179                              && RTR0MemObjAddress(pBundle->aMem[i].MapObjR3) == pv)
     2180                             && (RTHCUINTPTR)RTR0MemObjAddress(pBundle->aMem[i].MapObjR3) == uPtr)
    21802181                        )
    21812182                   )
     
    21932194#else /* !USE_NEW_OS_INTERFACE */
    21942195                if (    pBundle->aMem[i].eType == MEMREF_TYPE_MEM
    2195                     &&  (   pBundle->aMem[i].pvR0 == pv
    2196                          || pBundle->aMem[i].pvR3 == pv))
     2196                    &&  (   (RTHCUINTPTR)pBundle->aMem[i].pvR0 == uPtr
     2197                         || (RTHCUINTPTR)pBundle->aMem[i].pvR3 == uPtr))
    21972198                {
    21982199                    supdrvOSMemGetPages(&pBundle->aMem[i], paPages);
     
    22052206    }
    22062207    RTSpinlockRelease(pSession->Spinlock, &SpinlockTmp);
    2207     dprintf(("Failed to find %p!!!\n", pv));
     2208    dprintf(("Failed to find %p!!!\n", (void *)uPtr));
    22082209    return SUPDRV_ERR_INVALID_PARAM;
    22092210}
     
    22162217 * @returns SUPDRV_ERR_* on failure.
    22172218 * @param   pSession        The session owning the allocation.
    2218  * @param   pv              The Ring-0 or Ring-3 address returned by SUPR0MemAlloc().
    2219  */
    2220 SUPR0DECL(int) SUPR0MemFree(PSUPDRVSESSION pSession, void *pv)
    2221 {
    2222     dprintf(("SUPR0MemFree: pSession=%p pv=%p\n", pSession, pv));
    2223     return supdrvMemRelease(pSession, pv, MEMREF_TYPE_MEM);
     2219 * @param   uPtr            The Ring-0 or Ring-3 address returned by SUPR0MemAlloc().
     2220 */
     2221SUPR0DECL(int) SUPR0MemFree(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr)
     2222{
     2223    dprintf(("SUPR0MemFree: pSession=%p uPtr=%p\n", pSession, (void *)uPtr));
     2224    return supdrvMemRelease(pSession, uPtr, MEMREF_TYPE_MEM);
    22242225}
    22252226
     
    22382239 *          and remove the session as a GIP user.
    22392240 */
    2240 SUPR0DECL(int) SUPR0GipMap(PSUPDRVSESSION pSession, PCSUPGLOBALINFOPAGE *ppGip, RTHCPHYS *pHCPhysGid)
     2241SUPR0DECL(int) SUPR0GipMap(PSUPDRVSESSION pSession, PCSUPGLOBALINFOPAGE *ppGip, PRTHCPHYS pHCPhysGid)
    22412242{
    22422243    int                     rc = 0;
     
    24612462 * @returns SUPDRV_ERR_INVALID_PARAM on failure.
    24622463 * @param   pSession    Session data.
    2463  * @param   pv          Pointer to memory. This is matched against both the R0 and R3 addresses.
     2464 * @param   uPtr        Pointer to memory. This is matched against both the R0 and R3 addresses.
    24642465 * @param   eType       Memory type.
    24652466 */
    2466 static int supdrvMemRelease(PSUPDRVSESSION pSession, void *pv, SUPDRVMEMREFTYPE eType)
     2467static int supdrvMemRelease(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr, SUPDRVMEMREFTYPE eType)
    24672468{
    24682469    PSUPDRVBUNDLE pBundle;
     
    24772478        return SUPDRV_ERR_INVALID_PARAM;
    24782479    }
    2479     if (!pv)
    2480     {
    2481         dprintf(("Illegal address %p\n", pv));
     2480    if (!uPtr)
     2481    {
     2482        dprintf(("Illegal address %p\n", (void *)uPtr));
    24822483        return SUPDRV_ERR_INVALID_PARAM;
    24832484    }
     
    24972498                if (    pBundle->aMem[i].eType == eType
    24982499                    &&  pBundle->aMem[i].MemObj != NIL_RTR0MEMOBJ
    2499                     &&  (   RTR0MemObjAddress(pBundle->aMem[i].MemObj) == pv
     2500                    &&  (   (RTHCUINTPTR)RTR0MemObjAddress(pBundle->aMem[i].MemObj) == uPtr
    25002501                         || (   pBundle->aMem[i].MapObjR3 != NIL_RTR0MEMOBJ
    2501                              && RTR0MemObjAddress(pBundle->aMem[i].MapObjR3) == pv))
     2502                             && (RTHCUINTPTR)RTR0MemObjAddress(pBundle->aMem[i].MapObjR3) == uPtr))
    25022503                   )
    25032504                {
     
    25232524#else /* !USE_NEW_OS_INTERFACE */
    25242525                if (    pBundle->aMem[i].eType == eType
    2525                     &&  (   pBundle->aMem[i].pvR0 == pv
    2526                          || pBundle->aMem[i].pvR3 == pv))
     2526                    &&  (   (RTHCUINTPTR)pBundle->aMem[i].pvR0 == uPtr
     2527                         || (RTHCUINTPTR)pBundle->aMem[i].pvR3 == uPtr))
    25272528                {
    25282529                    /* Make a copy of it and release it outside the spinlock. */
     
    25302531                    pBundle->aMem[i].eType = MEMREF_TYPE_UNUSED;
    25312532                    pBundle->aMem[i].pvR0  = NULL;
    2532                     pBundle->aMem[i].pvR3  = NULL;
     2533                    pBundle->aMem[i].pvR3  = NIL_RTR3PTR;
    25332534                    pBundle->aMem[i].cb    = 0;
    25342535                    RTSpinlockRelease(pSession->Spinlock, &SpinlockTmp);
     
    25602561    }
    25612562    RTSpinlockRelease(pSession->Spinlock, &SpinlockTmp);
    2562     dprintf(("Failed to find %p!!! (eType=%d)\n", pv, eType));
     2563    dprintf(("Failed to find %p!!! (eType=%d)\n", (void *)uPtr, eType));
    25632564    return SUPDRV_ERR_INVALID_PARAM;
    25642565}
     
    38333834 * @param   pMem        Memory reference record of the memory to be allocated.
    38343835 *                      (This is not linked in anywhere.)
     3836 * @param   ppvR3       Where to store the Ring-0 mapping of the allocated memory.
    38353837 * @param   ppvR3       Where to store the Ring-3 mapping of the allocated memory.
    38363838 * @param   paPagesOut  Where to store the physical addresss.
    38373839 */
    3838 int VBOXCALL supdrvOSLowAllocOne(PSUPDRVMEMREF pMem, void **ppvR3, PSUPPAGE paPagesOut)
     3840int VBOXCALL supdrvOSLowAllocOne(PSUPDRVMEMREF pMem, PRTR0PTR ppvR0, PRTR3PTR ppvR3, PSUPPAGE paPagesOut)
    38393841{
    38403842    RTHCPHYS HCPhys;
    3841     int rc = supdrvOSContAllocOne(pMem, NULL, ppvR3, &HCPhys);
     3843    int rc = supdrvOSContAllocOne(pMem, ppvR0, ppvR3, &HCPhys);
    38423844    if (!rc)
    38433845    {
  • trunk/src/VBox/HostDrivers/Support/SUPLib.cpp

    r1199 r1480  
    474474    In.u32Cookie        = g_u32Cookie;
    475475    In.u32SessionCookie = g_u32SessionCookie;
    476     In.pv               = pvStart;
     476    In.pvR3             = pvStart;
    477477    In.cb               = (uint32_t)cbMemory; AssertRelease(In.cb == cbMemory);
    478478    int rc;
     
    529529    In.u32Cookie        = g_u32Cookie;
    530530    In.u32SessionCookie = g_u32SessionCookie;
    531     In.pv               = pvStart;
     531    In.pvR3             = pvStart;
    532532    int rc;
    533533    if (!g_u32FakeMode)
     
    602602    In.u32Cookie        = g_u32Cookie;
    603603    In.u32SessionCookie = g_u32SessionCookie;
    604     In.pv               = pv;
     604    In.pvR3             = pv;
    605605    int rc;
    606606    if (!g_u32FakeMode)
     
    613613
    614614
    615 SUPR3DECL(int) SUPLowAlloc(unsigned cPages, void **ppvPages, PSUPPAGE paPages)
     615SUPR3DECL(int) SUPLowAlloc(unsigned cPages, void **ppvPages, PRTR0PTR ppvPagesR0, PSUPPAGE paPages)
    616616{
    617617    /*
     
    640640            if (VBOX_SUCCESS(rc))
    641641            {
    642                 *ppvPages = pOut->pvVirt;
     642                *ppvPages = pOut->pvR3;
     643                if (ppvPagesR0)
     644                    *ppvPagesR0 = pOut->pvR0;
    643645                AssertCompile(sizeof(paPages[0]) == sizeof(pOut->aPages[0]));
    644646                memcpy(paPages, &pOut->aPages[0], sizeof(paPages[0]) * cPages);
     
    688690    In.u32Cookie        = g_u32Cookie;
    689691    In.u32SessionCookie = g_u32SessionCookie;
    690     In.pv               = pv;
     692    In.pvR3             = pv;
    691693    int rc;
    692694    if (!g_u32FakeMode)
  • trunk/src/VBox/HostDrivers/Support/linux/SUPDrv-linux.c

    r1355 r1480  
    246246static int      VBoxSupDrvDeviceControl(struct inode *pInode, struct file *pFilp,
    247247                                        unsigned int IOCmd, unsigned long IOArg);
    248 static void    *VBoxSupDrvMapUser(struct page **papPages, unsigned cPages, unsigned fProt, pgprot_t pgFlags);
     248static RTR3PTR  VBoxSupDrvMapUser(struct page **papPages, unsigned cPages, unsigned fProt, pgprot_t pgFlags);
    249249static int      VBoxSupDrvInitGip(PSUPDRVDEVEXT pDevExt);
    250250static int      VBoxSupDrvTermGip(PSUPDRVDEVEXT pDevExt);
    251251static void     VBoxSupGipTimer(unsigned long ulUser);
     252#ifdef CONFIG_SMP
    252253static void     VBoxSupDrvGipPerCpu(void *pvUser);
     254#endif
    253255static int      VBoxSupDrvOrder(unsigned long size);
    254256static int      VBoxSupDrvErr2LinuxErr(int);
     
    827829 * @param   pHCPhys     Where to store the physical address.
    828830 */
    829 int VBOXCALL supdrvOSContAllocOne(PSUPDRVMEMREF pMem, void **ppvR0, void **ppvR3, PRTHCPHYS pHCPhys)
     831int VBOXCALL supdrvOSContAllocOne(PSUPDRVMEMREF pMem, PRTR0PTR ppvR0, PRTR3PTR ppvR3, PRTHCPHYS pHCPhys)
    830832{
    831833    struct page *paPages;
     
    916918    {
    917919        *pHCPhys = HCPhys;
    918         *ppvR3 = (void *)ulAddr;
     920        *ppvR3 = ulAddr;
    919921        if (ppvR0)
    920922            *ppvR0 = (void *)ulAddr;
    921         pMem->pvR3              = (void *)ulAddr;
     923        pMem->pvR3              = ulAddr;
    922924        pMem->pvR0              = NULL;
    923925        pMem->u.cont.paPages    = paPages;
     
    10001002 * @param   ppvR3       Where to store the address of the Ring-3 mapping.
    10011003 */
    1002 int  VBOXCALL   supdrvOSMemAllocOne(PSUPDRVMEMREF pMem, void **ppvR0, void **ppvR3)
     1004int  VBOXCALL   supdrvOSMemAllocOne(PSUPDRVMEMREF pMem, PRTR0PTR ppvR0, PRTR3PTR ppvR3)
    10031005{
    10041006    const unsigned  cbAligned = RT_ALIGN(pMem->cb, PAGE_SIZE);
     
    11321134        up_write(&current->mm->mmap_sem);   /* check when we can leave this. */
    11331135    }
    1134     pMem->pvR3 = NULL;
     1136    pMem->pvR3 = NIL_RTR3PTR;
    11351137
    11361138    /*
     
    11901192 * @param   pgFlags     The page level protection.
    11911193 */
    1192 static void *VBoxSupDrvMapUser(struct page **papPages, unsigned cPages, unsigned fProt, pgprot_t pgFlags)
     1194static RTR3PTR VBoxSupDrvMapUser(struct page **papPages, unsigned cPages, unsigned fProt, pgprot_t pgFlags)
    11931195{
    11941196    int             rc = SUPDRV_ERR_NO_MEMORY;
     
    12341236        {
    12351237            up_write(&current->mm->mmap_sem);
    1236             return (void *)ulAddr;
     1238            return ulAddr;
    12371239        }
    12381240
     
    12521254    up_write(&current->mm->mmap_sem);
    12531255
    1254     return NULL;
     1256    return NIL_RTR3PTR;
    12551257}
    12561258
  • trunk/src/VBox/HostDrivers/Support/testcase/tstInt.cpp

    r914 r1480  
    8787             * Create a fake 'VM'.
    8888             */
    89             PVMR0 pVMR0;
    90             RTHCPHYS HCPhysVM;
    91             PVM pVM = (PVM)SUPContAlloc2(sizeof(*pVM), &pVMR0, &HCPhysVM);
    92             if (pVM)
     89            PVMR0 pVMR0 = NIL_RTR0PTR;
     90            PVM pVM = NULL;
     91            const unsigned cPages = RT_ALIGN_Z(sizeof(*pVM), PAGE_SIZE) >> PAGE_SHIFT;
     92            PSUPPAGE paPages = (PSUPPAGE)RTMemAllocZ(cPages * sizeof(SUPPAGE));
     93            if (paPages)
     94                rc = SUPLowAlloc(cPages, (void **)&pVM, &pVMR0, &paPages[0]);
     95            else
     96                rc = VERR_NO_MEMORY;
     97            if (VBOX_SUCCESS(rc))
    9398            {
    9499                pVM->pVMGC = 0;
    95100                pVM->pVMR3 = pVM;
    96101                pVM->pVMR0 = pVMR0;
     102#ifdef VBOX_USE_LOW_MEM_FOR_VM
     103                pVM->paVMPagesR3 = paPages;
     104#else
    97105                pVM->HCPhysVM = HCPhysVM;
     106#endif
    98107                pVM->pSession = pSession;
    99108
  • trunk/src/VBox/HostDrivers/Support/testcase/tstLow.cpp

    r1 r1480  
    5050        void *pvPages0 = (void *)0x77777777;
    5151        memset(&aPages0[0], 0x8f, sizeof(aPages0));
    52         rc = SUPLowAlloc(ELEMENTS(aPages0), &pvPages0, aPages0);
     52        rc = SUPLowAlloc(ELEMENTS(aPages0), &pvPages0, NULL, aPages0);
    5353        if (VBOX_SUCCESS(rc))
    5454        {
     
    9898            void *pvPages1 = (void *)0x77777777;
    9999            memset(&aPages1[0], 0x8f, sizeof(aPages1));
    100             rc = SUPLowAlloc(cPages, &pvPages1, aPages1);
     100            rc = SUPLowAlloc(cPages, &pvPages1, NULL, aPages1);
    101101            if (VBOX_SUCCESS(rc))
    102102            {
  • trunk/src/VBox/HostDrivers/Support/win32/SUPDrv-win32.cpp

    r1355 r1480  
    521521 * @param   pHCPhys     Where to store the physical address.
    522522 */
    523 int VBOXCALL supdrvOSContAllocOne(PSUPDRVMEMREF pMem, void **ppvR0, void **ppvR3, PRTHCPHYS pHCPhys)
     523int VBOXCALL supdrvOSContAllocOne(PSUPDRVMEMREF pMem, PRTR0PTR ppvR0, PRTR3PTR ppvR3, PRTHCPHYS pHCPhys)
    524524{
    525525    Assert(ppvR3);
     
    547547        __try
    548548        {
    549             pMem->pvR3 = MmMapLockedPages(pMem->u.cont.pMdl, UserMode);
     549            pMem->pvR3 = (RTR3PTR)MmMapLockedPages(pMem->u.cont.pMdl, UserMode);
    550550            if (pMem->pvR3)
    551551            {
     
    593593        if (pMem->pvR3)
    594594        {
    595             MmUnmapLockedPages(pMem->pvR3, pMem->u.cont.pMdl);
     595            MmUnmapLockedPages((void *)pMem->pvR3, pMem->u.cont.pMdl);
    596596            dprintf2(("MmUnmapLockedPages ok!\n"));
    597597            pMem->pvR3 = NULL;
     
    625625 * @param   ppvR3       Where to store the address of the Ring-3 mapping.
    626626 */
    627 int  VBOXCALL   supdrvOSMemAllocOne(PSUPDRVMEMREF pMem, void **ppvR0, void **ppvR3)
     627int  VBOXCALL   supdrvOSMemAllocOne(PSUPDRVMEMREF pMem, PRTR0PTR ppvR0, PRTR3PTR ppvR3)
    628628{
    629629    Assert(ppvR0);
     
    648648        __try
    649649        {
    650             pMem->pvR3 = MmMapLockedPages(pMem->u.mem.pMdl, UserMode);
     650            pMem->pvR3 = (RTR3PTR)MmMapLockedPages(pMem->u.mem.pMdl, UserMode);
    651651            if (pMem->pvR3)
    652652            {
     
    711711        if (pMem->pvR3)
    712712        {
    713             MmUnmapLockedPages(pMem->pvR3, pMem->u.mem.pMdl);
     713            MmUnmapLockedPages((void *)pMem->pvR3, pMem->u.mem.pMdl);
    714714            pMem->pvR3 = NULL;
    715715            dprintf2(("MmUnmapLockedPages ok!\n"));
  • trunk/src/VBox/VMM/MM.cpp

    r247 r1480  
    291291     * (Associated record are released by the heap.)
    292292     */
    293     PMMLOCKEDMEM    pLockedMem = pVM->mm.s.pLockedMem;
     293    PMMLOCKEDMEM pLockedMem = pVM->mm.s.pLockedMem;
    294294    while (pLockedMem)
    295295    {
     
    298298        switch (pLockedMem->eType)
    299299        {
    300             case MM_LOCKED_TYPE_PHYS:
    301             case MM_LOCKED_TYPE_HYPER_NOFREE:
    302                 break;
    303300            case MM_LOCKED_TYPE_HYPER:
    304301                rc = SUPPageFree(pLockedMem->pv);
    305302                AssertMsgRC(rc, ("SUPPageFree(%p) -> rc=%d\n", pLockedMem->pv, rc));
     303                break;
     304            case MM_LOCKED_TYPE_HYPER_NOFREE:
     305            case MM_LOCKED_TYPE_HYPER_PAGES:
     306            case MM_LOCKED_TYPE_PHYS:
     307                /* nothing to do. */
    306308                break;
    307309        }
     
    543545
    544546    /*
    545      * The VM structure?
    546      */
    547     uint32_t off = (uint32_t)(HCPhys - pVM->HCPhysVM);
    548     if (off < RT_ALIGN_32(sizeof(*pVM), PAGE_SIZE))
    549     {
    550         *ppv = (char *)pVM + off;
    551         return VINF_SUCCESS;
    552     }
    553 
    554     /*
    555547     * Iterate the locked memory - very slow.
    556548     */
    557     off = HCPhys & PAGE_OFFSET_MASK;
     549    uint32_t off = HCPhys & PAGE_OFFSET_MASK;
    558550    HCPhys &= X86_PTE_PAE_PG_MASK;
    559551    for (PMMLOCKEDMEM pCur = pVM->mm.s.pLockedMem; pCur; pCur = pCur->pNext)
  • trunk/src/VBox/VMM/MMHyper.cpp

    r323 r1480  
    100100         * Map the VM structure into the hypervisor space.
    101101         */
    102         rc = MMR3HyperMapHCPhys(pVM, pVM, pVM->HCPhysVM, sizeof(VM), "VM", &pVM->pVMGC);
     102        rc = MMR3HyperMapPages(pVM, pVM, pVM->pVMR0, RT_ALIGN_Z(sizeof(VM), PAGE_SIZE) >> PAGE_SHIFT, pVM->paVMPagesR3, "VM", &pVM->pVMGC);
    103103        if (VBOX_SUCCESS(rc))
    104104        {
     
    446446                pLookup->enmType = MMLOOKUPHYPERTYPE_LOCKED;
    447447                pLookup->u.Locked.pvHC       = pvHC;
     448                pLookup->u.Locked.pvR0       = NIL_RTR0PTR;
    448449                pLookup->u.Locked.pLockedMem = pLockedMem;
    449450
    450451                /* done. */
    451452                GCPtr    |= (uintptr_t)pvHC & PAGE_OFFSET_MASK;
     453                *pGCPtr   = GCPtr;
     454                return rc;
     455            }
     456            /* Don't care about failure clean, we're screwed if this fails anyway. */
     457        }
     458    }
     459
     460    return rc;
     461}
     462
     463
     464/**
     465 * Maps locked R3 virtual memory into the hypervisor region in the GC.
     466 *
     467 * @return VBox status code.
     468 *
     469 * @param   pVM         VM handle.
     470 * @param   pvR3        The ring-3 address of the memory, must be page aligned.
     471 * @param   pvR0        The ring-0 address of the memory, must be page aligned. (optional)
     472 * @param   cPages      The number of pages.
     473 * @param   paPages     The page descriptors.
     474 * @param   pszDesc     Mapping description.
     475 * @param   pGCPtr      Where to store the GC address corresponding to pvHC.
     476 */
     477MMR3DECL(int) MMR3HyperMapPages(PVM pVM, void *pvR3, RTR0PTR pvR0, size_t cPages, PCSUPPAGE paPages, const char *pszDesc, PRTGCPTR pGCPtr)
     478{
     479    LogFlow(("MMR3HyperMapPages: pvR3=%p pvR0=%p cPages=%zu paPages=%p pszDesc=%p:{%s} pGCPtr=%p\n",
     480             pvR3, pvR0, cPages, paPages, pszDesc, pszDesc, pGCPtr));
     481
     482    /*
     483     * Validate input.
     484     */
     485    AssertPtrReturn(pvR3, VERR_INVALID_POINTER);
     486    AssertPtrReturn(paPages, VERR_INVALID_POINTER);
     487    AssertReturn(cPages > 0, VERR_INVALID_PARAMETER);
     488    AssertReturn(cPages < 1024, VERR_INVALID_PARAMETER);
     489    AssertPtrReturn(pszDesc, VERR_INVALID_POINTER);
     490    AssertReturn(*pszDesc, VERR_INVALID_PARAMETER);
     491    AssertPtrReturn(pGCPtr, VERR_INVALID_PARAMETER);
     492
     493    /*
     494     * Add the memory to the hypervisor area.
     495     */
     496    RTGCPTR         GCPtr;
     497    PMMLOOKUPHYPER  pLookup;
     498    int rc = mmR3HyperMap(pVM, cPages << PAGE_SHIFT, pszDesc, &GCPtr, &pLookup);
     499    if (VBOX_SUCCESS(rc))
     500    {
     501        /*
     502         * Create a locked memory record and tell PGM about this.
     503         */
     504        PMMLOCKEDMEM pLockedMem = (PMMLOCKEDMEM)MMR3HeapAlloc(pVM, MM_TAG_MM, RT_OFFSETOF(MMLOCKEDMEM, aPhysPages[cPages]));
     505        if (pLockedMem)
     506        {
     507            pLockedMem->pv      = pvR3;
     508            pLockedMem->cb      = cPages << PAGE_SHIFT;
     509            pLockedMem->eType   = MM_LOCKED_TYPE_HYPER_PAGES;
     510            memset(&pLockedMem->u, 0, sizeof(pLockedMem->u));
     511            for (size_t i = 0; i < cPages; i++)
     512            {
     513                AssertReleaseReturn(paPages[i].Phys != 0 && paPages[i].Phys != NIL_RTHCPHYS && !(paPages[i].Phys & PAGE_OFFSET_MASK), VERR_INTERNAL_ERROR);
     514                pLockedMem->aPhysPages[i].Phys = paPages[i].Phys;
     515                pLockedMem->aPhysPages[i].uReserved = (RTHCUINTPTR)pLockedMem;
     516            }
     517
     518            /* map the stuff into guest address space. */
     519            if (pVM->mm.s.fPGMInitialized)
     520                rc = mmr3MapLocked(pVM, pLockedMem, GCPtr, 0, ~(size_t)0, 0);
     521            if (VBOX_SUCCESS(rc))
     522            {
     523                pLookup->enmType = MMLOOKUPHYPERTYPE_LOCKED;
     524                pLookup->u.Locked.pvHC       = pvR3;
     525                pLookup->u.Locked.pvR0       = pvR0;
     526                pLookup->u.Locked.pLockedMem = pLockedMem;
     527
     528                /* done. */
    452529                *pGCPtr   = GCPtr;
    453530                return rc;
     
    864941                                pLookup->u.Locked.pvHC,
    865942                                sizeof(RTHCPTR) * 2,
    866                                 pLookup->u.Locked.pLockedMem->eType == MM_LOCKED_TYPE_HYPER_NOFREE
    867                                     ? "nofree" : "autofree",
     943                                pLookup->u.Locked.pLockedMem->eType == MM_LOCKED_TYPE_HYPER_NOFREE  ? "nofree"
     944                                : pLookup->u.Locked.pLockedMem->eType == MM_LOCKED_TYPE_HYPER       ? "autofree"
     945                                : pLookup->u.Locked.pLockedMem->eType == MM_LOCKED_TYPE_HYPER_PAGES ? "pages"
     946                                : pLookup->u.Locked.pLockedMem->eType == MM_LOCKED_TYPE_PHYS        ? "gstphys"
     947                                : "??",
    868948                                pLookup->pszDesc);
    869949                break;
  • trunk/src/VBox/VMM/MMInternal.h

    r323 r1480  
    440440typedef enum MMLOCKEDTYPE
    441441{
    442     /** Hypervisor memory (VMM GC). */
     442    /** Hypervisor: Ring-3 memory locked by MM. */
    443443    MM_LOCKED_TYPE_HYPER,
    444     /** Hypervisor memory to be mapped from HC. */
     444    /** Hypervisor: Ring-3 memory locked by MM that shouldn't be freed up. */
    445445    MM_LOCKED_TYPE_HYPER_NOFREE,
    446     /** Physical VM memory (RAM & MMIO2). */
     446    /** Hypervisor: Pre-locked ring-3 pages. */
     447    MM_LOCKED_TYPE_HYPER_PAGES,
     448    /** Guest: Physical VM memory (RAM & MMIO2). */
    447449    MM_LOCKED_TYPE_PHYS
    448450} MMLOCKEDTYPE;
     
    475477    union
    476478    {
    477         /** Data for MM_LOCKED_TYPE_HYPER. */
     479        /** Data for MM_LOCKED_TYPE_HYPER, MM_LOCKED_TYPE_HYPER_NOFREE and MM_LOCKED_TYPE_HYPER_PAGES. */
    478480        struct
    479481        {
     
    544546            /** Host context pointer. */
    545547            HCPTRTYPE(void *)       pvHC;
     548            /** Host context ring-0 pointer. */
     549            RTR0PTR                 pvR0;
    546550            /** Pointer to the locked mem record. */
    547551            HCPTRTYPE(PMMLOCKEDMEM) pLockedMem;
  • trunk/src/VBox/VMM/MMPagePool.cpp

    r1468 r1480  
    252252    }
    253253    else
    254         rc = SUPLowAlloc(cPages, &pSub->pvPages, paPhysPages);
     254        rc = SUPLowAlloc(cPages, &pSub->pvPages, NULL, paPhysPages);
    255255    if (VBOX_SUCCESS(rc))
    256256    {
  • trunk/src/VBox/VMM/SELM.cpp

    r1450 r1480  
    9898    /*
    9999     * Assert alignment and sizes.
    100      */
     100     * (The TSS block requires contiguous back.)
     101     */
     102    AssertCompile(sizeof(pVM->selm.s) <= sizeof(pVM->selm.padding));    AssertRelease(sizeof(pVM->selm.s) <= sizeof(pVM->selm.padding));
    101103    AssertCompileMemberAlignment(VM, selm.s, 32);                       AssertRelease(!(RT_OFFSETOF(VM, selm.s) & 31));
    102     AssertCompileMemberAlignment(VM, selm.s.Tss, 16);                   AssertRelease(!(RT_OFFSETOF(VM, selm.s.Tss) & 15));
    103     AssertCompile(sizeof(pVM->selm.s) <= sizeof(pVM->selm.padding));    AssertRelease(sizeof(pVM->selm.s) <= sizeof(pVM->selm.padding));
     104#ifndef __AMD64__ /* gcc 4.1.1 doesn't deal correctly with this :/ */
     105    AssertCompile((RT_OFFSETOF(VM, selm.s.Tss)       & PAGE_OFFSET_MASK) <= PAGE_SIZE - sizeof(pVM->selm.s.Tss));       
     106    AssertCompile((RT_OFFSETOF(VM, selm.s.TssTrap08) & PAGE_OFFSET_MASK) <= PAGE_SIZE - sizeof(pVM->selm.s.TssTrap08));
     107#endif
     108    AssertRelease((RT_OFFSETOF(VM, selm.s.Tss)       & PAGE_OFFSET_MASK) <= PAGE_SIZE - sizeof(pVM->selm.s.Tss));
     109    AssertRelease((RT_OFFSETOF(VM, selm.s.TssTrap08) & PAGE_OFFSET_MASK) <= PAGE_SIZE - sizeof(pVM->selm.s.TssTrap08));
    104110
    105111    /*
  • trunk/src/VBox/VMM/SELMInternal.h

    r1449 r1480  
    114114    RTUINT                  auPadding[2];
    115115#endif
    116     /** TSS. (This is 16 byte aligned!) */
     116    /** TSS. (This is 16 byte aligned!)
     117      * @todo I/O bitmap & interrupt redirection table? */
    117118    VBOXTSS                 Tss;
    118     /** @todo I/O bitmap & interrupt redirection table. */
    119119
    120120    /** TSS for trap 08 (\#DF). */
    121121    VBOXTSS                 TssTrap08;
    122     /** TSS for trap 0a (\#TS). */
    123     VBOXTSS                 TssTrap0a;
    124122
    125123    /** GC Pointer to the TSS shadow area (Tss) placed in Hypervisor memory arena. */
  • trunk/src/VBox/VMM/VM.cpp

    r1468 r1480  
    187187         * Allocate memory for the VM structure.
    188188         */
    189         RTHCPHYS HCPhysVM;
    190         PVMR0 pVMR0;
    191         PVM pVM = (PVM)SUPContAlloc2(RT_ALIGN_Z(sizeof(*pVM), PAGE_SIZE), &pVMR0, &HCPhysVM);
    192         if (pVM)
     189        PVMR0 pVMR0 = NIL_RTR0PTR;
     190        PVM pVM = NULL;
     191        const unsigned cPages = RT_ALIGN_Z(sizeof(*pVM), PAGE_SIZE) >> PAGE_SHIFT;
     192        PSUPPAGE paPages = (PSUPPAGE)RTMemAllocZ(cPages * sizeof(SUPPAGE));
     193        AssertReturn(paPages, VERR_NO_MEMORY);
     194        rc = SUPLowAlloc(cPages, (void **)&pVM, &pVMR0, &paPages[0]);
     195        if (VBOX_SUCCESS(rc))
    193196        {
    194             Log(("VMR3Create: Allocated pVM=%p HCPhysVM=%VHp\n", pVM, HCPhysVM));
     197            Log(("VMR3Create: Allocated pVM=%p pVMR0=%p\n", pVM, pVMR0));
    195198
    196199            /*
     
    201204            pVM->pVMR0 = pVMR0;
    202205            pVM->pVMR3 = pVM;
    203             pVM->HCPhysVM = HCPhysVM;
     206            pVM->paVMPagesR3 = paPages;
    204207            pVM->pSession = pSession;
    205208            pVM->vm.s.offVM = RT_OFFSETOF(VM, vm.s);
     
    209212            pVM->vm.s.ppAtRuntimeErrorNext = &pVM->vm.s.pAtRuntimeError;
    210213            rc = RTSemEventCreate(&pVM->vm.s.EventSemWait);
    211             if (VBOX_FAILURE(rc))
    212             {
    213                 AssertMsgFailed(("RTSemEventCreate -> rc=%Vrc\n", rc));
    214                 return rc;
    215             }
     214            AssertRCReturn(rc, rc);
    216215
    217216            /*
     
    265264            AssertRC(rc2);
    266265
    267             /* free VM memory */
    268             rc2 = SUPContFree(pVM);
     266            /* free the VM memory */
     267            rc2 = SUPLowFree(pVM);
    269268            AssertRC(rc2);
    270269        }
     
    277276            AssertMsgFailed(("Failed to allocate %d bytes of contiguous memory for the VM structure!\n", RT_ALIGN(sizeof(*pVM), PAGE_SIZE)));
    278277        }
     278        RTMemFree(paPages);
    279279
    280280        /* terminate SUPLib */
     
    15191519     * Free the VM structure.
    15201520     */
    1521     rc = SUPContFree(pVM);
     1521    rc = SUPLowFree(pVM);
    15221522    AssertRC(rc);
    15231523    rc = SUPTerm();
  • trunk/src/VBox/VMM/VMMAll/MMAll.cpp

    r1309 r1480  
    213213DECLINLINE(RTR0PTR) mmHyperLookupCalcR0(PMMLOOKUPHYPER pLookup, uint32_t off)
    214214{
    215     return (RTR0PTR)mmHyperLookupCalcR3(pLookup, off);
     215    switch (pLookup->enmType)
     216    {
     217        case MMLOOKUPHYPERTYPE_LOCKED:
     218            if (pLookup->u.Locked.pvR0)
     219                return (RTR0PTR)((RTR0UINTPTR)pLookup->u.Locked.pvR0 + off);
     220            return (RTR0PTR)((RTR3UINTPTR)pLookup->u.Locked.pvHC + off);
     221        case MMLOOKUPHYPERTYPE_HCPHYS:
     222            return (RTR0PTR)((RTR3UINTPTR)pLookup->u.HCPhys.pvHC + off);
     223        default:
     224            AssertMsgFailed(("enmType=%d\n", pLookup->enmType));
     225            return NIL_RTR0PTR;
     226    }
    216227}
    217228
  • trunk/src/VBox/VMM/testcase/tstVMStructGC.cpp

    r1408 r1480  
    165165    GEN_CHECK_OFF(MMLOOKUPHYPER, enmType);
    166166    GEN_CHECK_OFF(MMLOOKUPHYPER, u.Locked.pvHC);
     167    GEN_CHECK_OFF(MMLOOKUPHYPER, u.Locked.pvR0);
    167168    GEN_CHECK_OFF(MMLOOKUPHYPER, u.Locked.pLockedMem);
    168169    GEN_CHECK_OFF(MMLOOKUPHYPER, u.HCPhys.pvHC);
     
    565566    GEN_CHECK_OFF(SELM, Tss);
    566567    GEN_CHECK_OFF(SELM, TssTrap08);
    567     GEN_CHECK_OFF(SELM, TssTrap0a);
    568568    GEN_CHECK_OFF(SELM, GCPtrTss);
    569569    GEN_CHECK_OFF(SELM, GCPtrGuestTss);
  • trunk/src/VBox/VMM/testcase/tstVMStructSize.cpp

    r1283 r1480  
    9090    do \
    9191    { \
    92         printf("%s::%s offset %d sizeof %d\n",  #strct, #member, (int)RT_OFFSETOF(strct, member), (int)RT_SIZEOFMEMB(strct, member)); \
     92        printf("%s::%s offset %#x (%d) sizeof %d\n",  #strct, #member, (int)RT_OFFSETOF(strct, member), (int)RT_OFFSETOF(strct, member), (int)RT_SIZEOFMEMB(strct, member)); \
    9393    } while (0)
    9494
     
    148148    CHECK_PADDING_VM(csam);
    149149    CHECK_MEMBER_ALIGNMENT(VM, selm.s.Tss, 16);
     150    PRINT_OFFSET(VM, selm.s.Tss);
     151    PVM pVM;
     152    if ((RT_OFFSETOF(VM, selm.s.Tss) & PAGE_OFFSET_MASK) > PAGE_SIZE - sizeof(pVM->selm.s.Tss))
     153    {
     154        printf("SELM:Tss is crossing a page!\n");
     155        rc++;
     156    }
     157    PRINT_OFFSET(VM, selm.s.TssTrap08);
     158    if ((RT_OFFSETOF(VM, selm.s.TssTrap08) & PAGE_OFFSET_MASK) > PAGE_SIZE - sizeof(pVM->selm.s.TssTrap08))
     159    {
     160        printf("SELM:TssTrap08 is crossing a page!\n");
     161        rc++;
     162    }
    150163    CHECK_MEMBER_ALIGNMENT(VM, trpm.s.aIdt, 16);
    151164    CHECK_MEMBER_ALIGNMENT(VM, cpum.s.Host, 32);
Note: See TracChangeset for help on using the changeset viewer.

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