Index: trunk/include/VBox/sup.h
===================================================================
--- trunk/include/VBox/sup.h	(revision 1839)
+++ trunk/include/VBox/sup.h	(revision 1840)
@@ -138,8 +138,9 @@
     /** Magic (SUPGLOBALINFOPAGE_MAGIC). */
     uint32_t            u32Magic;
+    /** The GIP version. */
+    uint32_t            u32Version;
 
     /** The GIP update mode, see SUPGIPMODE. */
     uint32_t            u32Mode;
-
     /** The update frequency of the of the NanoTS. */
     volatile uint32_t   u32UpdateHz;
@@ -170,4 +171,8 @@
 /** The value of the SUPGLOBALINFOPAGE::u32Magic field. (Soryo Fuyumi) */
 #define SUPGLOBALINFOPAGE_MAGIC     0x19590106
+/** The GIP version. 
+ * Upper 16 bits is the major version. Major version is only changed with 
+ * incompatible changes in the GIP. */
+#define SUPGLOBALINFOPAGE_VERSION   0x00020000
 
 /** 
@@ -552,5 +557,5 @@
 SUPR0DECL(int) SUPR0MemGetPhys(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr, PSUPPAGE paPages);
 SUPR0DECL(int) SUPR0MemFree(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr);
-SUPR0DECL(int) SUPR0GipMap(PSUPDRVSESSION pSession, PCSUPGLOBALINFOPAGE *ppGip, PRTHCPHYS pHCPhysGid);
+SUPR0DECL(int) SUPR0GipMap(PSUPDRVSESSION pSession, PRTR3PTR ppGipR3, PRTHCPHYS pHCPhysGid);
 SUPR0DECL(int) SUPR0GipUnmap(PSUPDRVSESSION pSession);
 SUPR0DECL(int) SUPR0Printf(const char *pszFormat, ...);
Index: trunk/include/VBox/types.h
===================================================================
--- trunk/include/VBox/types.h	(revision 1839)
+++ trunk/include/VBox/types.h	(revision 1840)
@@ -74,5 +74,5 @@
  * (The data is a R0 entity and private to the the R0 SUP part. All
  * other should consider this a sort of handle.) */
-typedef struct SUPDRVSESSION   *PSUPDRVSESSION;
+typedef R0PTRTYPE(struct SUPDRVSESSION *) PSUPDRVSESSION;
 
 /** Pointer to a VM. */
Index: trunk/src/VBox/HostDrivers/Support/SUPDRVIOC.h
===================================================================
--- trunk/src/VBox/HostDrivers/Support/SUPDRVIOC.h	(revision 1839)
+++ trunk/src/VBox/HostDrivers/Support/SUPDRVIOC.h	(revision 1840)
@@ -169,4 +169,11 @@
 
 
+/** SUPCOOKIE_IN magic word. */
+#define SUPCOOKIE_MAGIC             "The Magic Word!"
+/** Current interface version.
+ * The upper 16-bit is the major version, the the lower the minor version.
+ * When incompatible changes are made, the upper major number has to be changed. */
+#define SUPDRVIOC_VERSION           0x00040002
+
 /** SUP_IOCTL_COOKIE Input. */
 typedef struct SUPCOOKIE_IN
@@ -174,12 +181,9 @@
     /** Magic word. */
     char            szMagic[16];
-    /** The requested version number. */
-    uint32_t        u32Version;
+    /** The requested interface version number. */
+    uint32_t        u32ReqVersion;
+    /** The minimum interface version number. */
+    uint32_t        u32MinVersion;
 } SUPCOOKIE_IN, *PSUPCOOKIE_IN;
-
-/** SUPCOOKIE_IN magic word. */
-#define SUPCOOKIE_MAGIC             "The Magic Word!"
-/** Current interface version. */
-#define SUPDRVIOC_VERSION           0x00040001
 
 /** SUP_IOCTL_COOKIE Output. */
@@ -190,11 +194,15 @@
     /** Session cookie. */
     uint32_t        u32SessionCookie;
-    /** Interface version. High word(=uint16) is major, low word is minor. */
-    uint32_t        u32Version;
+    /** Interface version for this session. */
+    uint32_t        u32SessionVersion;
+    /** The actual interface version in the driver. */
+    uint32_t        u32DriverVersion;
     /** Number of functions available for the SUP_IOCTL_QUERY_FUNCS request. */
     uint32_t        cFunctions;
     /** Session handle. */
-    PSUPDRVSESSION  pSession;
+    R0PTRTYPE(PSUPDRVSESSION)   pSession;
 } SUPCOOKIE_OUT, *PSUPCOOKIE_OUT;
+
+
 
 /** SUP_IOCTL_QUERY_FUNCS Input. */
@@ -202,7 +210,7 @@
 {
     /** Cookie. */
-    uint32_t    u32Cookie;
-    /** Session cookie. */
-    uint32_t    u32SessionCookie;
+    uint32_t        u32Cookie;
+    /** Session cookie. */
+    uint32_t        u32SessionCookie;
 } SUPQUERYFUNCS_IN, *PSUPQUERYFUNCS_IN;
 
@@ -211,7 +219,7 @@
 {
     /** Name - mangled. */
-    char        szName[32];
+    char            szName[32];
     /** Address. */
-    void       *pfn;
+    RTR0PTR         pfn;
 } SUPFUNC, *PSUPFUNC;
 
@@ -220,8 +228,9 @@
 {
     /** Number of functions returned. */
-    uint32_t    cFunctions;
+    uint32_t        cFunctions;
     /** Array of functions. */
-    SUPFUNC     aFunctions[1];
+    SUPFUNC         aFunctions[1];
 } SUPQUERYFUNCS_OUT, *PSUPQUERYFUNCS_OUT;
+
 
 
@@ -230,7 +239,7 @@
 {
     /** Cookie. */
-    uint32_t    u32Cookie;
-    /** Session cookie. */
-    uint32_t    u32SessionCookie;
+    uint32_t        u32Cookie;
+    /** Session cookie. */
+    uint32_t        u32SessionCookie;
 } SUPIDTINSTALL_IN, *PSUPIDTINSTALL_IN;
 
@@ -239,5 +248,5 @@
 {
     /** Cookie. */
-    uint8_t     u8Idt;
+    uint8_t         u8Idt;
 } SUPIDTINSTALL_OUT, *PSUPIDTINSTALL_OUT;
 
@@ -248,7 +257,7 @@
 {
     /** Cookie. */
-    uint32_t    u32Cookie;
-    /** Session cookie. */
-    uint32_t    u32SessionCookie;
+    uint32_t        u32Cookie;
+    /** Session cookie. */
+    uint32_t        u32SessionCookie;
 } SUPIDTREMOVE_IN, *PSUPIDTREMOVE_IN;
 
@@ -259,11 +268,11 @@
 {
     /** Cookie. */
-    uint32_t    u32Cookie;
-    /** Session cookie. */
-    uint32_t    u32SessionCookie;
+    uint32_t        u32Cookie;
+    /** Session cookie. */
+    uint32_t        u32SessionCookie;
     /** Start of page range. Must be PAGE aligned. */
-    RTR3PTR     pvR3;
+    RTR3PTR         pvR3;
     /** Size of the range. Must be PAGE aligned. */
-    uint32_t    cb;
+    uint32_t        cb;
 } SUPPINPAGES_IN, *PSUPPINPAGES_IN;
 
@@ -272,5 +281,5 @@
 {
     /** Array of pages. */
-    SUPPAGE     aPages[1];
+    SUPPAGE         aPages[1];
 } SUPPINPAGES_OUT, *PSUPPINPAGES_OUT;
 
@@ -281,10 +290,11 @@
 {
     /** Cookie. */
-    uint32_t    u32Cookie;
-    /** Session cookie. */
-    uint32_t    u32SessionCookie;
+    uint32_t        u32Cookie;
+    /** Session cookie. */
+    uint32_t        u32SessionCookie;
     /** Start of page range of a range previuosly pinned. */
-    RTR3PTR     pvR3;
+    RTR3PTR         pvR3;
 } SUPUNPINPAGES_IN, *PSUPUNPINPAGES_IN;
+
 
 
@@ -293,10 +303,11 @@
 {
     /** Cookie. */
-    uint32_t    u32Cookie;
-    /** Session cookie. */
-    uint32_t    u32SessionCookie;
+    uint32_t        u32Cookie;
+    /** Session cookie. */
+    uint32_t        u32SessionCookie;
     /** Number of bytes to allocate. */
-    uint32_t    cb;
+    uint32_t        cb;
 } SUPCONTALLOC_IN, *PSUPCONTALLOC_IN;
+
 
 
@@ -305,10 +316,11 @@
 {
     /** The address of the ring-0 mapping of the allocated memory. */
-    RTR0PTR     pvR0;
+    RTR0PTR         pvR0;
     /** The address of the ring-3 mapping of the allocated memory. */
-    RTR3PTR     pvR3;
+    RTR3PTR         pvR3;
     /** The physical address of the allocation. */
-    RTHCPHYS    HCPhys;
+    RTHCPHYS        HCPhys;
 } SUPCONTALLOC_OUT, *PSUPCONTALLOC_OUT;
+
 
 
@@ -317,10 +329,11 @@
 {
     /** Cookie. */
-    uint32_t    u32Cookie;
-    /** Session cookie. */
-    uint32_t    u32SessionCookie;
+    uint32_t        u32Cookie;
+    /** Session cookie. */
+    uint32_t        u32SessionCookie;
     /** The ring-3 address of the memory to free. */
-    RTR3PTR     pvR3;
+    RTR3PTR         pvR3;
 } SUPCONTFREE_IN, *PSUPCONTFREE_IN;
+
 
 
@@ -329,13 +342,13 @@
 {
     /** Cookie. */
-    uint32_t    u32Cookie;
-    /** Session cookie. */
-    uint32_t    u32SessionCookie;
+    uint32_t        u32Cookie;
+    /** Session cookie. */
+    uint32_t        u32SessionCookie;
     /** Size of the image we'll be loading. */
-    uint32_t    cbImage;
+    uint32_t        cbImage;
     /** Image name.
      * This is the NAME of the image, not the file name. It is used
      * to share code with other processes. (Max len is 32 chars!)  */
-    char        szName[32];
+    char            szName[32];
 } SUPLDROPEN_IN, *PSUPLDROPEN_IN;
 
@@ -344,8 +357,9 @@
 {
     /** The base address of the image. */
-    void       *pvImageBase;
+    RTR0PTR         pvImageBase;
     /** Indicate whether or not the image requires loading. */
-    bool        fNeedsLoading;
+    bool            fNeedsLoading;
 } SUPLDROPEN_OUT, *PSUPLDROPEN_OUT;
+
 
 
@@ -359,5 +373,5 @@
 typedef DECLCALLBACK(int) FNR0MODULEINIT(void);
 /** Pointer to a FNR0MODULEINIT(). */
-typedef FNR0MODULEINIT *PFNR0MODULEINIT;
+typedef R0PTRTYPE(FNR0MODULEINIT *) PFNR0MODULEINIT;
 
 /**
@@ -367,5 +381,5 @@
 typedef DECLCALLBACK(void) FNR0MODULETERM(void);
 /** Pointer to a FNR0MODULETERM(). */
-typedef FNR0MODULETERM *PFNR0MODULETERM;
+typedef R0PTRTYPE(FNR0MODULETERM *) PFNR0MODULETERM;
 
 /**
@@ -397,27 +411,28 @@
         {
             /** The module handle (i.e. address). */
-            void       *pvVMMR0;
+            RTR0PTR         pvVMMR0;
             /** Address of VMMR0Entry function. */
-            void       *pvVMMR0Entry;
+            RTR0PTR         pvVMMR0Entry;
         } VMMR0;
-    }           EP;
+    }               EP;
     /** Address. */
-    void       *pvImageBase;
+    RTR0PTR         pvImageBase;
     /** Entry point type. */
     enum { EP_NOTHING, EP_VMMR0 }
                     eEPType;
     /** The offset of the symbol table. */
-    uint32_t    offSymbols;
+    uint32_t        offSymbols;
     /** The number of entries in the symbol table. */
-    uint32_t    cSymbols;
+    uint32_t        cSymbols;
     /** The offset of the string table. */
-    uint32_t    offStrTab;
+    uint32_t        offStrTab;
     /** Size of the string table. */
-    uint32_t    cbStrTab;
+    uint32_t        cbStrTab;
     /** Size of image (including string and symbol tables). */
-    uint32_t    cbImage;
+    uint32_t        cbImage;
     /** The image data. */
-    char        achImage[1];
+    char            achImage[1];
 } SUPLDRLOAD_IN, *PSUPLDRLOAD_IN;
+
 
 
@@ -426,10 +441,11 @@
 {
     /** Cookie. */
-    uint32_t    u32Cookie;
-    /** Session cookie. */
-    uint32_t    u32SessionCookie;
+    uint32_t        u32Cookie;
+    /** Session cookie. */
+    uint32_t        u32SessionCookie;
     /** Address. */
-    void       *pvImageBase;
+    RTR0PTR         pvImageBase;
 } SUPLDRFREE_IN, *PSUPLDRFREE_IN;
+
 
 
@@ -438,11 +454,11 @@
 {
     /** Cookie. */
-    uint32_t    u32Cookie;
-    /** Session cookie. */
-    uint32_t    u32SessionCookie;
+    uint32_t        u32Cookie;
+    /** Session cookie. */
+    uint32_t        u32SessionCookie;
     /** Address. */
-    void       *pvImageBase;
+    RTR0PTR         pvImageBase;
     /** The symbol name (variable length). */
-    char        szSymbol[1];
+    char            szSymbol[1];
 } SUPLDRGETSYMBOL_IN, *PSUPLDRGETSYMBOL_IN;
 
@@ -451,6 +467,7 @@
 {
     /** The symbol address. */
-    void       *pvSymbol;
+    RTR0PTR         pvSymbol;
 } SUPLDRGETSYMBOL_OUT, *PSUPLDRGETSYMBOL_OUT;
+
 
 
@@ -459,15 +476,15 @@
 {
     /** Cookie. */
-    uint32_t    u32Cookie;
-    /** Session cookie. */
-    uint32_t    u32SessionCookie;
+    uint32_t        u32Cookie;
+    /** Session cookie. */
+    uint32_t        u32SessionCookie;
     /** The VM handle. */
-    PVMR0       pVMR0;
+    PVMR0           pVMR0;
     /** Which operation to execute. */
-    uint32_t    uOperation;
+    uint32_t        uOperation;
     /** The size of the buffer pointed to by pvArg. */
-    uint32_t    cbArg;
+    uint32_t        cbArg;
     /** Argument to that operation. */
-    void       *pvArg;
+    RTR3PTR         pvArg;
 } SUPCALLVMMR0_IN, *PSUPCALLVMMR0_IN;
 
@@ -476,6 +493,7 @@
 {
     /** The VBox status code for the operation. */
-    int32_t     rc;
+    int32_t         rc;
 } SUPCALLVMMR0_OUT, *PSUPCALLVMMR0_OUT;
+
 
 
@@ -484,7 +502,7 @@
 {
     /** Cookie. */
-    uint32_t    u32Cookie;
-    /** Session cookie. */
-    uint32_t    u32SessionCookie;
+    uint32_t        u32Cookie;
+    /** Session cookie. */
+    uint32_t        u32SessionCookie;
 } SUPGETPAGINGMODE_IN, *PSUPGETPAGINGMODE_IN;
 
@@ -493,6 +511,7 @@
 {
     /** The paging mode. */
-    SUPPAGINGMODE   enmMode;
+    SUPPAGINGMODE       enmMode;
 } SUPGETPAGINGMODE_OUT, *PSUPGETPAGINGMODE_OUT;
+
 
 
@@ -501,9 +520,9 @@
 {
     /** Cookie. */
-    uint32_t    u32Cookie;
-    /** Session cookie. */
-    uint32_t    u32SessionCookie;
+    uint32_t        u32Cookie;
+    /** Session cookie. */
+    uint32_t        u32SessionCookie;
     /** Number of pages to allocate. */
-    uint32_t    cPages;
+    uint32_t        cPages;
 } SUPLOWALLOC_IN, *PSUPLOWALLOC_IN;
 
@@ -512,10 +531,11 @@
 {
     /** The ring-3 address of the allocated memory. */
-    RTR3PTR     pvR3;
+    RTR3PTR         pvR3;
     /** The ring-0 address of the allocated memory. */
-    RTR0PTR     pvR0;
+    RTR0PTR         pvR0;
     /** Array of pages. */
-    SUPPAGE     aPages[1];
+    SUPPAGE         aPages[1];
 } SUPLOWALLOC_OUT, *PSUPLOWALLOC_OUT;
+
 
 
@@ -524,10 +544,11 @@
 {
     /** Cookie. */
-    uint32_t    u32Cookie;
-    /** Session cookie. */
-    uint32_t    u32SessionCookie;
+    uint32_t        u32Cookie;
+    /** Session cookie. */
+    uint32_t        u32SessionCookie;
     /** The ring-3 address of the memory to free. */
-    RTR3PTR     pvR3;
+    RTR3PTR         pvR3;
 } SUPLOWFREE_IN, *PSUPLOWFREE_IN;
+
 
 
@@ -536,7 +557,7 @@
 {
     /** Cookie. */
-    uint32_t    u32Cookie;
-    /** Session cookie. */
-    uint32_t    u32SessionCookie;
+    uint32_t        u32Cookie;
+    /** Session cookie. */
+    uint32_t        u32SessionCookie;
 } SUPGIPMAP_IN, *PSUPGIPMAP_IN;
 
@@ -545,10 +566,11 @@
 {
     /** Pointer to the read-only usermode GIP mapping for this session. */
-    PCSUPGLOBALINFOPAGE pGipR3;
+    R3PTRTYPE(PCSUPGLOBALINFOPAGE)  pGipR3;
     /** Pointer to the supervisor mode GIP mapping. */
-    PCSUPGLOBALINFOPAGE pGipR0;
+    R0PTRTYPE(PCSUPGLOBALINFOPAGE)  pGipR0;
     /** The physical address of the GIP. */
-    RTHCPHYS    HCPhysGip;
+    RTHCPHYS                        HCPhysGip;
 } SUPGIPMAP_OUT, *PSUPGIPMAP_OUT;
+
 
 
@@ -557,8 +579,9 @@
 {
     /** Cookie. */
-    uint32_t    u32Cookie;
-    /** Session cookie. */
-    uint32_t    u32SessionCookie;
+    uint32_t        u32Cookie;
+    /** Session cookie. */
+    uint32_t        u32SessionCookie;
 } SUPGIPUNMAP_IN, *PSUPGIPUNMAP_IN;
+
 
 
@@ -567,9 +590,9 @@
 {
     /** Cookie. */
-    uint32_t    u32Cookie;
-    /** Session cookie. */
-    uint32_t    u32SessionCookie;
+    uint32_t        u32Cookie;
+    /** Session cookie. */
+    uint32_t        u32SessionCookie;
     /** The ring-0 VM handle (pointer). */
-    PVMR0       pVMR0;
+    PVMR0           pVMR0;
 } SUPSETVMFORFAST_IN, *PSUPSETVMFORFAST_IN;
 
Index: trunk/src/VBox/HostDrivers/Support/SUPDRVShared.c
===================================================================
--- trunk/src/VBox/HostDrivers/Support/SUPDRVShared.c	(revision 1839)
+++ trunk/src/VBox/HostDrivers/Support/SUPDRVShared.c	(revision 1840)
@@ -644,16 +644,30 @@
                 ||  cbOut != sizeof(*pOut))
             {
-                dprintf(("SUP_IOCTL_COOKIE: Invalid input/output sizes. cbIn=%ld expected %ld. cbOut=%ld expected %ld.\n",
-                         (long)cbIn, (long)sizeof(*pIn), (long)cbOut, (long)sizeof(*pOut)));
+                OSDBGPRINT(("SUP_IOCTL_COOKIE: Invalid input/output sizes. cbIn=%ld expected %ld. cbOut=%ld expected %ld.\n",
+                            (long)cbIn, (long)sizeof(*pIn), (long)cbOut, (long)sizeof(*pOut)));
                 return SUPDRV_ERR_INVALID_PARAM;
             }
             if (strncmp(pIn->szMagic, SUPCOOKIE_MAGIC, sizeof(pIn->szMagic)))
             {
-                dprintf(("SUP_IOCTL_COOKIE: invalid magic %.16s\n", pIn->szMagic));
+                OSDBGPRINT(("SUP_IOCTL_COOKIE: invalid magic %.16s\n", pIn->szMagic));
                 return SUPDRV_ERR_INVALID_MAGIC;
             }
-            if (pIn->u32Version != SUPDRVIOC_VERSION)
-            {
-                dprintf(("SUP_IOCTL_COOKIE: Version mismatch. Requested: %#x  Current: %#x\n", pIn->u32Version, SUPDRVIOC_VERSION));
+
+            /*
+             * Match the version.
+             * The current logic is very simple, match the major interface version.
+             */
+            if (    pIn->u32MinVersion > SUPDRVIOC_VERSION
+                ||  (pIn->u32ReqVersion & 0xffff0000) != (SUPDRVIOC_VERSION & 0xffff0000))
+            {
+                OSDBGPRINT(("SUP_IOCTL_COOKIE: Version mismatch. Requested: %#x  Min: %#x  Current: %#x\n", 
+                            pIn->u32ReqVersion, pIn->u32MinVersion, SUPDRVIOC_VERSION));
+                pOut->u32Cookie         = 0xffffffff;
+                pOut->u32SessionCookie  = 0xffffffff;
+                pOut->u32SessionVersion = 0xffffffff;
+                pOut->u32DriverVersion  = SUPDRVIOC_VERSION;
+                pOut->pSession          = NULL;
+                pOut->cFunctions        = 0;
+                *pcbReturned = sizeof(*pOut);
                 return SUPDRV_ERR_VERSION_MISMATCH;
             }
@@ -662,8 +676,9 @@
              * Fill in return data and be gone.
              */
-            /** @todo secure cookie negotiation? */
+            /** @todo A more secure cookie negotiation? */
             pOut->u32Cookie         = pDevExt->u32Cookie;
             pOut->u32SessionCookie  = pSession->u32Cookie;
-            pOut->u32Version        = SUPDRVIOC_VERSION;
+            pOut->u32SessionVersion = SUPDRVIOC_VERSION;
+            pOut->u32DriverVersion  = SUPDRVIOC_VERSION;
             pOut->pSession          = pSession;
             pOut->cFunctions        = sizeof(g_aFunctions) / sizeof(g_aFunctions[0]);
@@ -1146,5 +1161,5 @@
              * Execute.
              */
-            pOut->rc = pDevExt->pfnVMMR0Entry(pIn->pVMR0, pIn->uOperation, pIn->pvArg);
+            pOut->rc = pDevExt->pfnVMMR0Entry(pIn->pVMR0, pIn->uOperation, (void *)pIn->pvArg); /** @todo address the pvArg problem! */
             *pcbReturned = sizeof(*pOut);
             return 0;
@@ -2232,5 +2247,5 @@
  * @returns SUPDRV_ERR_* on failure.
  * @param   pSession        Session to which the GIP mapping should belong.
- * @param   ppGip           Where to store the address of the mapping. (optional)
+ * @param   ppGipR3         Where to store the address of the ring-3 mapping. (optional)
  * @param   pHCPhysGip      Where to store the physical address. (optional)
  *
@@ -2239,16 +2254,16 @@
  *          and remove the session as a GIP user.
  */
-SUPR0DECL(int) SUPR0GipMap(PSUPDRVSESSION pSession, PCSUPGLOBALINFOPAGE *ppGip, PRTHCPHYS pHCPhysGid)
-{
-    int                     rc = 0;
-    PSUPDRVDEVEXT           pDevExt = pSession->pDevExt;
-    PCSUPGLOBALINFOPAGE     pGip = NULL;
-    RTHCPHYS                HCPhys = NIL_RTHCPHYS;
-    dprintf(("SUPR0GipMap: pSession=%p ppGip=%p pHCPhysGid=%p\n", pSession, ppGip, pHCPhysGid));
+SUPR0DECL(int) SUPR0GipMap(PSUPDRVSESSION pSession, PRTR3PTR ppGipR3, PRTHCPHYS pHCPhysGid)
+{
+    int             rc = 0;
+    PSUPDRVDEVEXT   pDevExt = pSession->pDevExt;
+    RTR3PTR         pGip = NIL_RTR3PTR;
+    RTHCPHYS        HCPhys = NIL_RTHCPHYS;
+    dprintf(("SUPR0GipMap: pSession=%p ppGipR3=%p pHCPhysGid=%p\n", pSession, ppGipR3, pHCPhysGid));
 
     /*
      * Validate
      */
-    if (!ppGip && !pHCPhysGid)
+    if (!ppGipR3 && !pHCPhysGid)
         return 0;
 
@@ -2259,5 +2274,5 @@
          * Map it?
          */
-        if (ppGip)
+        if (ppGipR3)
         {
 #ifdef USE_NEW_OS_INTERFACE
@@ -2267,5 +2282,5 @@
             if (RT_SUCCESS(rc))
             {
-                pGip = (PCSUPGLOBALINFOPAGE)RTR0MemObjAddress(pSession->GipMapObjR3);
+                pGip = (RTR3PTR)RTR0MemObjAddress(pSession->GipMapObjR3);
                 rc = VINF_SUCCESS; /** @todo remove this and replace the !rc below with RT_SUCCESS(rc). */
             }
@@ -2274,5 +2289,5 @@
                 rc = supdrvOSGipMap(pSession->pDevExt, &pSession->pGip);
             if (!rc)
-                pGip = pSession->pGip;
+                pGip = (RTR3PTR)pSession->pGip;
 #endif /* !USE_NEW_OS_INTERFACE */
         }
@@ -2323,8 +2338,8 @@
     if (pHCPhysGid)
         *pHCPhysGid = HCPhys;
-    if (ppGip)
-        *ppGip = pGip;
-
-    dprintf(("SUPR0GipMap: returns %d *pHCPhysGid=%lx *ppGip=%p\n", rc, (unsigned long)HCPhys, pGip));
+    if (ppGipR3)
+        *ppGipR3 = pGip;
+
+    dprintf(("SUPR0GipMap: returns %d *pHCPhysGid=%lx *ppGipR3=%p\n", rc, (unsigned long)HCPhys, (void *)(uintptr_t)pGip));
     return rc;
 }
Index: trunk/src/VBox/HostDrivers/Support/SUPLib.cpp
===================================================================
--- trunk/src/VBox/HostDrivers/Support/SUPLib.cpp	(revision 1839)
+++ trunk/src/VBox/HostDrivers/Support/SUPLib.cpp	(revision 1840)
@@ -115,5 +115,5 @@
 #endif
 /** VMMR0 Load Address. */
-static void        *g_pvVMMR0 = NULL;
+static RTR0PTR      g_pvVMMR0 = NIL_RTR0PTR;
 /** Init counter. */
 static unsigned     g_cInits = 0;
@@ -183,11 +183,15 @@
          */
         SUPCOOKIE_IN    In;
-        SUPCOOKIE_OUT   Out = {0,0};
+        SUPCOOKIE_OUT   Out = {0,0,0,0,0,NIL_RTR0PTR};
         strcpy(In.szMagic, SUPCOOKIE_MAGIC);
-        In.u32Version = SUPDRVIOC_VERSION;
+        In.u32ReqVersion = SUPDRVIOC_VERSION;
+        if (SUPDRVIOC_VERSION < 0x00050000)
+            In.u32MinVersion = 0x00040002;
+        else
+            In.u32MinVersion = SUPDRVIOC_VERSION & 0xffff0000;
         rc = suplibOsIOCtl(SUP_IOCTL_COOKIE, &In, sizeof(In), &Out, sizeof(Out));
         if (VBOX_SUCCESS(rc))
         {
-            if (Out.u32Version == SUPDRVIOC_VERSION)
+            if ((Out.u32SessionVersion & 0xffff0000) == (SUPDRVIOC_VERSION & 0xffff0000))
             {
                 /*
@@ -239,5 +243,19 @@
             }
             else
+            {
+                LogRel(("Support driver version mismatch: SessionVersion=%#x DriverVersion=%#x ClientVersion=%#x\n", 
+                        Out.u32SessionVersion, Out.u32DriverVersion, SUPDRVIOC_VERSION));
                 rc = VERR_VM_DRIVER_VERSION_MISMATCH;
+            }
+        }
+        else
+        {
+             if (rc == VERR_INVALID_PARAMETER) /* for pre 0x00040002 drivers */
+                 rc = VERR_VM_DRIVER_VERSION_MISMATCH;
+             if (rc == VERR_VM_DRIVER_VERSION_MISMATCH)
+                 LogRel(("Support driver version mismatch: DriverVersion=%#x ClientVersion=%#x\n", 
+                         Out.u32DriverVersion, SUPDRVIOC_VERSION));
+             else
+                 LogRel(("Support driver version/Cookie negotiations error: rc=%Vrc\n", rc));
         }
 
@@ -259,44 +277,44 @@
     {
         /* name                                     function */
-        { "SUPR0ObjRegister",                       (void *)0xefef0000 },
-        { "SUPR0ObjAddRef",                         (void *)0xefef0001 },
-        { "SUPR0ObjRelease",                        (void *)0xefef0002 },
-        { "SUPR0ObjVerifyAccess",                   (void *)0xefef0003 },
-        { "SUPR0LockMem",                           (void *)0xefef0004 },
-        { "SUPR0UnlockMem",                         (void *)0xefef0005 },
-        { "SUPR0ContAlloc",                         (void *)0xefef0006 },
-        { "SUPR0ContFree",                          (void *)0xefef0007 },
-        { "SUPR0MemAlloc",                          (void *)0xefef0008 },
-        { "SUPR0MemGetPhys",                        (void *)0xefef0009 },
-        { "SUPR0MemFree",                           (void *)0xefef000a },
-        { "SUPR0Printf",                            (void *)0xefef000b },
-        { "RTMemAlloc",                             (void *)0xefef000c },
-        { "RTMemAllocZ",                            (void *)0xefef000d },
-        { "RTMemFree",                              (void *)0xefef000e },
-        { "RTSemFastMutexCreate",                   (void *)0xefef000f },
-        { "RTSemFastMutexDestroy",                  (void *)0xefef0010 },
-        { "RTSemFastMutexRequest",                  (void *)0xefef0011 },
-        { "RTSemFastMutexRelease",                  (void *)0xefef0012 },
-        { "RTSemEventCreate",                       (void *)0xefef0013 },
-        { "RTSemEventSignal",                       (void *)0xefef0014 },
-        { "RTSemEventWait",                         (void *)0xefef0015 },
-        { "RTSemEventDestroy",                      (void *)0xefef0016 },
-        { "RTSpinlockCreate",                       (void *)0xefef0017 },
-        { "RTSpinlockDestroy",                      (void *)0xefef0018 },
-        { "RTSpinlockAcquire",                      (void *)0xefef0019 },
-        { "RTSpinlockRelease",                      (void *)0xefef001a },
-        { "RTSpinlockAcquireNoInts",                (void *)0xefef001b },
-        { "RTSpinlockReleaseNoInts",                (void *)0xefef001c },
-        { "RTThreadNativeSelf",                     (void *)0xefef001d },
-        { "RTThreadSleep",                          (void *)0xefef001e },
-        { "RTThreadYield",                          (void *)0xefef001f },
-        { "RTLogDefaultInstance",                   (void *)0xefef0020 },
-        { "RTLogRelDefaultInstance",                (void *)0xefef0021 },
-        { "RTLogSetDefaultInstanceThread",          (void *)0xefef0022 },
-        { "RTLogLogger",                            (void *)0xefef0023 },
-        { "RTLogLoggerEx",                          (void *)0xefef0024 },
-        { "RTLogLoggerExV",                         (void *)0xefef0025 },
-        { "AssertMsg1",                             (void *)0xefef0026 },
-        { "AssertMsg2",                             (void *)0xefef0027 },
+        { "SUPR0ObjRegister",                       0xefef0000 },
+        { "SUPR0ObjAddRef",                         0xefef0001 },
+        { "SUPR0ObjRelease",                        0xefef0002 },
+        { "SUPR0ObjVerifyAccess",                   0xefef0003 },
+        { "SUPR0LockMem",                           0xefef0004 },
+        { "SUPR0UnlockMem",                         0xefef0005 },
+        { "SUPR0ContAlloc",                         0xefef0006 },
+        { "SUPR0ContFree",                          0xefef0007 },
+        { "SUPR0MemAlloc",                          0xefef0008 },
+        { "SUPR0MemGetPhys",                        0xefef0009 },
+        { "SUPR0MemFree",                           0xefef000a },
+        { "SUPR0Printf",                            0xefef000b },
+        { "RTMemAlloc",                             0xefef000c },
+        { "RTMemAllocZ",                            0xefef000d },
+        { "RTMemFree",                              0xefef000e },
+        { "RTSemFastMutexCreate",                   0xefef000f },
+        { "RTSemFastMutexDestroy",                  0xefef0010 },
+        { "RTSemFastMutexRequest",                  0xefef0011 },
+        { "RTSemFastMutexRelease",                  0xefef0012 },
+        { "RTSemEventCreate",                       0xefef0013 },
+        { "RTSemEventSignal",                       0xefef0014 },
+        { "RTSemEventWait",                         0xefef0015 },
+        { "RTSemEventDestroy",                      0xefef0016 },
+        { "RTSpinlockCreate",                       0xefef0017 },
+        { "RTSpinlockDestroy",                      0xefef0018 },
+        { "RTSpinlockAcquire",                      0xefef0019 },
+        { "RTSpinlockRelease",                      0xefef001a },
+        { "RTSpinlockAcquireNoInts",                0xefef001b },
+        { "RTSpinlockReleaseNoInts",                0xefef001c },
+        { "RTThreadNativeSelf",                     0xefef001d },
+        { "RTThreadSleep",                          0xefef001e },
+        { "RTThreadYield",                          0xefef001f },
+        { "RTLogDefaultInstance",                   0xefef0020 },
+        { "RTLogRelDefaultInstance",                0xefef0021 },
+        { "RTLogSetDefaultInstanceThread",          0xefef0022 },
+        { "RTLogLogger",                            0xefef0023 },
+        { "RTLogLoggerEx",                          0xefef0024 },
+        { "RTLogLoggerExV",                         0xefef0025 },
+        { "AssertMsg1",                             0xefef0026 },
+        { "AssertMsg2",                             0xefef0027 },
     };
 
@@ -1013,8 +1031,8 @@
     /** @todo call the SUPLoadModule caller.... */
     /** @todo proper reference counting and such. */
-    if (g_pvVMMR0)
+    if (g_pvVMMR0 != NIL_RTR0PTR)
     {
         void *pvValue;
-        if (!SUPGetSymbolR0(g_pvVMMR0, pszSymbol, &pvValue))
+        if (!SUPGetSymbolR0((void *)g_pvVMMR0, pszSymbol, &pvValue))
         {
             *pValue = (uintptr_t)pvValue;
@@ -1162,7 +1180,7 @@
         {
             OpenOut.fNeedsLoading = true;
-            OpenOut.pvImageBase = (void *)0xef423420;
-        }
-        *ppvImageBase = OpenOut.pvImageBase;
+            OpenOut.pvImageBase = 0xef423420;
+        }
+        *ppvImageBase = (void *)OpenOut.pvImageBase;
         if (    VBOX_SUCCESS(rc)
             &&  OpenOut.fNeedsLoading)
@@ -1220,11 +1238,11 @@
                     pIn->u32Cookie                  = g_u32Cookie;
                     pIn->u32SessionCookie           = g_u32SessionCookie;
-                    pIn->pfnModuleInit              = (PFNR0MODULEINIT)(uintptr_t)ModuleInit;
-                    pIn->pfnModuleTerm              = (PFNR0MODULETERM)(uintptr_t)ModuleTerm;
+                    pIn->pfnModuleInit              = (RTR0PTR)ModuleInit;
+                    pIn->pfnModuleTerm              = (RTR0PTR)ModuleTerm;
                     if (fIsVMMR0)
                     {
                         pIn->eEPType                = pIn->EP_VMMR0;
                         pIn->EP.VMMR0.pvVMMR0       = OpenOut.pvImageBase;
-                        pIn->EP.VMMR0.pvVMMR0Entry  = (void *)(uintptr_t)VMMR0Entry;
+                        pIn->EP.VMMR0.pvVMMR0Entry  = (RTR0PTR)VMMR0Entry;
                     }
                     else
@@ -1274,5 +1292,5 @@
      *      first unload will free it.
      */
-    if (pvImageBase == g_pvVMMR0)
+    if ((RTR0PTR)pvImageBase == g_pvVMMR0)
     {
         /*
@@ -1287,5 +1305,5 @@
             g_pfnCallVMMR0 = NULL;
 #endif
-            g_pvVMMR0 = NULL;
+            g_pvVMMR0 = NIL_RTR0PTR;
             return VINF_SUCCESS;
         }
@@ -1315,11 +1333,11 @@
     In.u32Cookie        = g_u32Cookie;
     In.u32SessionCookie = g_u32SessionCookie;
-    In.pvImageBase      = pvImageBase;
+    In.pvImageBase      = (RTR0PTR)pvImageBase;
     int rc = VINF_SUCCESS;
     if (!g_u32FakeMode)
         rc = suplibOsIOCtl(SUP_IOCTL_LDR_FREE, &In, sizeof(In), NULL, 0);
     if (    VBOX_SUCCESS(rc)
-        &&  pvImageBase == g_pvVMMR0)
-        g_pvVMMR0 = NULL;
+        &&  (RTR0PTR)pvImageBase == g_pvVMMR0)
+        g_pvVMMR0 = NIL_RTR0PTR;
     return rc;
 }
@@ -1335,9 +1353,9 @@
     size_t              cchSymbol = strlen(pszSymbol);
     const size_t        cbIn = RT_OFFSETOF(SUPLDRGETSYMBOL_IN, szSymbol[cchSymbol + 1]);
-    SUPLDRGETSYMBOL_OUT Out = { NULL };
+    SUPLDRGETSYMBOL_OUT Out = { NIL_RTR0PTR };
     PSUPLDRGETSYMBOL_IN pIn = (PSUPLDRGETSYMBOL_IN)alloca(cbIn);
     pIn->u32Cookie        = g_u32Cookie;
     pIn->u32SessionCookie = g_u32SessionCookie;
-    pIn->pvImageBase      = pvImageBase;
+    pIn->pvImageBase      = (RTR0PTR)pvImageBase;
     memcpy(pIn->szSymbol, pszSymbol, cchSymbol + 1);
     int rc;
@@ -1347,8 +1365,8 @@
     {
         rc = VINF_SUCCESS;
-        Out.pvSymbol = (void *)0xdeadf00d;
+        Out.pvSymbol = 0xdeadf00d;
     }
     if (VBOX_SUCCESS(rc))
-        *ppvValue = Out.pvSymbol;
+        *ppvValue = (void *)Out.pvSymbol;
     return rc;
 }
@@ -1364,5 +1382,5 @@
 SUPR3DECL(int) SUPUnloadVMM(void)
 {
-    return SUPFreeModule(g_pvVMMR0);
+    return SUPFreeModule((void*)g_pvVMMR0);
 }
 
