Index: /trunk/include/VBox/VBoxGuestLib.h
===================================================================
--- /trunk/include/VBox/VBoxGuestLib.h	(revision 58177)
+++ /trunk/include/VBox/VBoxGuestLib.h	(revision 58178)
@@ -94,6 +94,4 @@
 # define DECLVBGL(type) DECLR0VBGL(type)
 
-typedef uint32_t VBGLIOPORT; /**< @todo r=bird: We have RTIOPORT (uint16_t) for this. */
-
 
 # ifdef VBGL_VBOXGUEST
@@ -105,5 +103,5 @@
  * @return VBox status code.
  */
-DECLVBGL(int) VbglInit (VBGLIOPORT portVMMDev, struct VMMDevMemory *pVMMDevMemory);
+DECLVBGL(int) VbglInitPrimary(RTIOPORT portVMMDev, struct VMMDevMemory *pVMMDevMemory);
 
 # else
@@ -115,5 +113,5 @@
  * @return VBox status code.
  */
-DECLVBGL(int) VbglInit (void);
+DECLVBGL(int) VbglInitClient(void);
 
 # endif
@@ -122,5 +120,5 @@
  * The library termination function.
  */
-DECLVBGL(void) VbglTerminate (void);
+DECLVBGL(void) VbglTerminate(void);
 
 
@@ -132,11 +130,10 @@
  * Allocate memory for generic request and initialize the request header.
  *
- * @param ppReq    pointer to resulting memory address.
- * @param cbSize   size of memory block required for the request.
- * @param reqType  the generic request type.
- *
- * @return VBox status code.
- */
-DECLVBGL(int) VbglGRAlloc (VMMDevRequestHeader **ppReq, uint32_t cbSize, VMMDevRequestType reqType);
+ * @returns VBox status code.
+ * @param   ppReq       Where to return the pointer to the allocated memory.
+ * @param   cbReq       Size of memory block required for the request.
+ * @param   enmReqType  the generic request type.
+ */
+DECLVBGL(int) VbglGRAlloc(VMMDevRequestHeader **ppReq, uint32_t cbReq, VMMDevRequestType enmReqType);
 
 /**
@@ -147,5 +144,5 @@
  * @return VBox status code.
  */
-DECLVBGL(int) VbglGRPerform (VMMDevRequestHeader *pReq);
+DECLVBGL(int) VbglGRPerform(VMMDevRequestHeader *pReq);
 
 /**
@@ -156,5 +153,5 @@
  * @return VBox status code.
  */
-DECLVBGL(void) VbglGRFree (VMMDevRequestHeader *pReq);
+DECLVBGL(void) VbglGRFree(VMMDevRequestHeader *pReq);
 
 /**
@@ -168,5 +165,5 @@
  * @return VBox status code.
  */
-DECLVBGL(int) VbglGRVerify (const VMMDevRequestHeader *pReq, size_t cbReq);
+DECLVBGL(int) VbglGRVerify(const VMMDevRequestHeader *pReq, size_t cbReq);
 /** @} */
 
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPWddm.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPWddm.cpp	(revision 58177)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPWddm.cpp	(revision 58178)
@@ -7462,5 +7462,5 @@
     NTSTATUS Status = STATUS_SUCCESS;
     /* Initialize VBoxGuest library, which is used for requests which go through VMMDev. */
-    int rc = VbglInit();
+    int rc = VbglInitClient();
     if (RT_SUCCESS(rc))
     {
@@ -7592,5 +7592,5 @@
     else
     {
-        WARN(("VbglInit failed, rc(%d)", rc));
+        WARN(("VbglInitClient failed, rc(%d)", rc));
         Status = STATUS_UNSUCCESSFUL;
     }
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/xpdm/VBoxMPDriver.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/xpdm/VBoxMPDriver.cpp	(revision 58177)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/xpdm/VBoxMPDriver.cpp	(revision 58178)
@@ -130,5 +130,5 @@
 
     /* Initialize VBoxGuest library, which is used for requests which go through VMMDev. */
-    rc = VbglInit();
+    rc = VbglInitClient();
     VBOXMP_WARN_VPS(rc);
 
Index: /trunk/src/VBox/Additions/WINNT/Mouse/NT4/VBoxPS2NT.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Mouse/NT4/VBoxPS2NT.cpp	(revision 58177)
+++ /trunk/src/VBox/Additions/WINNT/Mouse/NT4/VBoxPS2NT.cpp	(revision 58178)
@@ -2137,5 +2137,5 @@
     ASSERT(status == STATUS_SUCCESS);
 
-    int rcVBox = VbglInit();
+    int rcVBox = VbglInitClient();
     if (RT_FAILURE(rcVBox))
     {
Index: /trunk/src/VBox/Additions/WINNT/Mouse/NT5/VBoxMFInternal.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Mouse/NT5/VBoxMFInternal.cpp	(revision 58177)
+++ /trunk/src/VBox/Additions/WINNT/Mouse/NT5/VBoxMFInternal.cpp	(revision 58178)
@@ -333,5 +333,5 @@
         if (!vboxIsVBGLInited() && !vboxIsVBGLInitFailed())
         {
-            int rc = VbglInit();
+            int rc = VbglInitClient();
 
             if (RT_SUCCESS(rc))
Index: /trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest.cpp
===================================================================
--- /trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest.cpp	(revision 58177)
+++ /trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest.cpp	(revision 58178)
@@ -1065,5 +1065,5 @@
      * made by the VMM.
      */
-    rc = VbglInit(pDevExt->IOPortBase, (VMMDevMemory *)pDevExt->pVMMDevMemory);
+    rc = VbglInitPrimary(pDevExt->IOPortBase, (VMMDevMemory *)pDevExt->pVMMDevMemory);
     if (RT_SUCCESS(rc))
     {
Index: /trunk/src/VBox/Additions/common/VBoxGuestLib/GenericRequest.cpp
===================================================================
--- /trunk/src/VBox/Additions/common/VBoxGuestLib/GenericRequest.cpp	(revision 58177)
+++ /trunk/src/VBox/Additions/common/VBoxGuestLib/GenericRequest.cpp	(revision 58178)
@@ -31,9 +31,10 @@
 #include <iprt/string.h>
 
-DECLVBGL(int) VbglGRVerify (const VMMDevRequestHeader *pReq, size_t cbReq)
+
+DECLVBGL(int) VbglGRVerify(const VMMDevRequestHeader *pReq, size_t cbReq)
 {
     size_t cbReqExpected;
 
-    if (!pReq || cbReq < sizeof (VMMDevRequestHeader))
+    if (RT_UNLIKELY(!pReq || cbReq < sizeof(VMMDevRequestHeader)))
     {
         dprintf(("VbglGRVerify: Invalid parameter: pReq = %p, cbReq = %zu\n", pReq, cbReq));
@@ -41,5 +42,5 @@
     }
 
-    if (pReq->size > cbReq)
+    if (RT_UNLIKELY(pReq->size > cbReq))
     {
         dprintf(("VbglGRVerify: request size %u > buffer size %zu\n", pReq->size, cbReq));
@@ -49,6 +50,5 @@
     /* The request size must correspond to the request type. */
     cbReqExpected = vmmdevGetRequestSize(pReq->requestType);
-
-    if (cbReq < cbReqExpected)
+    if (RT_UNLIKELY(cbReq < cbReqExpected))
     {
         dprintf(("VbglGRVerify: buffer size %zu < expected size %zu\n", cbReq, cbReqExpected));
@@ -58,8 +58,9 @@
     if (cbReqExpected == cbReq)
     {
-        /* This is most likely a fixed size request, and in this case the request size
-         * must be also equal to the expected size.
+        /*
+         * This is most likely a fixed size request, and in this case the
+         * request size must be also equal to the expected size.
          */
-        if (pReq->size != cbReqExpected)
+        if (RT_UNLIKELY(pReq->size != cbReqExpected))
         {
             dprintf(("VbglGRVerify: request size %u != expected size %zu\n", pReq->size, cbReqExpected));
@@ -82,5 +83,5 @@
 #else
         || pReq->requestType == VMMDevReq_HGCMCall
-#endif /* VBOX_WITH_64_BITS_GUESTS */
+#endif
         || pReq->requestType == VMMDevReq_RegisterSharedModule
         || pReq->requestType == VMMDevReq_ReportGuestUserState
@@ -89,8 +90,8 @@
         || pReq->requestType == VMMDevReq_VideoSetVisibleRegion)
     {
-        if (cbReq > VMMDEV_MAX_VMMDEVREQ_SIZE)
+        if (RT_UNLIKELY(cbReq > VMMDEV_MAX_VMMDEVREQ_SIZE))
         {
             dprintf(("VbglGRVerify: VMMDevReq_LogString: buffer size %zu too big\n", cbReq));
-            return VERR_BUFFER_OVERFLOW; /* @todo is this error code ok? */
+            return VERR_BUFFER_OVERFLOW; /** @todo is this error code ok? */
         }
     }
@@ -98,5 +99,5 @@
     {
         dprintf(("VbglGRVerify: request size %u > buffer size %zu\n", pReq->size, cbReq));
-        return VERR_IO_BAD_LENGTH; /* @todo is this error code ok? */
+        return VERR_IO_BAD_LENGTH; /** @todo is this error code ok? */
     }
 
@@ -104,76 +105,64 @@
 }
 
-DECLVBGL(int) VbglGRAlloc (VMMDevRequestHeader **ppReq, uint32_t cbSize, VMMDevRequestType reqType)
+DECLVBGL(int) VbglGRAlloc(VMMDevRequestHeader **ppReq, uint32_t cbReq, VMMDevRequestType enmReqType)
 {
-    VMMDevRequestHeader *pReq;
-    int rc = vbglR0Enter ();
+    int rc = vbglR0Enter();
+    if (RT_SUCCESS(rc))
+    {
+        if (ppReq && cbReq >= sizeof(VMMDevRequestHeader))
+        {
+            VMMDevRequestHeader *pReq = (VMMDevRequestHeader *)VbglPhysHeapAlloc(cbReq);
+            AssertMsgReturn(pReq, ("VbglGRAlloc: no memory (cbReq=%u)\n", cbReq), VERR_NO_MEMORY);
+            memset(pReq, 0xAA, cbReq);
 
-    if (RT_FAILURE(rc))
-        return rc;
+            pReq->size        = cbReq;
+            pReq->version     = VMMDEV_REQUEST_HEADER_VERSION;
+            pReq->requestType = enmReqType;
+            pReq->rc          = VERR_GENERAL_FAILURE;
+            pReq->reserved1   = 0;
+            pReq->reserved2   = 0;
 
-    if (!ppReq || cbSize < sizeof (VMMDevRequestHeader))
-    {
-        dprintf(("VbglGRAlloc: Invalid parameter: ppReq = %p, cbSize = %u\n", ppReq, cbSize));
-        return VERR_INVALID_PARAMETER;
-    }
-
-    pReq = (VMMDevRequestHeader *)VbglPhysHeapAlloc (cbSize);
-    if (!pReq)
-    {
-        AssertMsgFailed(("VbglGRAlloc: no memory\n"));
-        rc = VERR_NO_MEMORY;
-    }
-    else
-    {
-        memset(pReq, 0xAA, cbSize);
-
-        pReq->size        = cbSize;
-        pReq->version     = VMMDEV_REQUEST_HEADER_VERSION;
-        pReq->requestType = reqType;
-        pReq->rc          = VERR_GENERAL_FAILURE;
-        pReq->reserved1   = 0;
-        pReq->reserved2   = 0;
-
-        *ppReq = pReq;
-    }
-
-    return rc;
-}
-
-DECLVBGL(int) VbglGRPerform (VMMDevRequestHeader *pReq)
-{
-    RTCCPHYS physaddr;
-    int rc = vbglR0Enter ();
-
-    if (RT_FAILURE(rc))
-        return rc;
-
-    if (!pReq)
-        return VERR_INVALID_PARAMETER;
-
-    physaddr = VbglPhysHeapGetPhysAddr (pReq);
-    if (  !physaddr
-       || (physaddr >> 32) != 0) /* Port IO is 32 bit. */
-    {
-        rc = VERR_VBGL_INVALID_ADDR;
-    }
-    else
-    {
-        ASMOutU32(g_vbgldata.portVMMDev + VMMDEV_PORT_OFF_REQUEST, (uint32_t)physaddr);
-        /* Make the compiler aware that the host has changed memory. */
-        ASMCompilerBarrier();
-        rc = pReq->rc;
+            *ppReq = pReq;
+            rc = VINF_SUCCESS;
+        }
+        else
+        {
+            dprintf(("VbglGRAlloc: Invalid parameter: ppReq=%p cbReq=%u\n", ppReq, cbReq));
+            rc = VERR_INVALID_PARAMETER;
+        }
     }
     return rc;
 }
 
-DECLVBGL(void) VbglGRFree (VMMDevRequestHeader *pReq)
+DECLVBGL(int) VbglGRPerform(VMMDevRequestHeader *pReq)
 {
-    int rc = vbglR0Enter ();
-
-    if (RT_FAILURE(rc))
-        return;
-
-    VbglPhysHeapFree (pReq);
+    int rc = vbglR0Enter();
+    if (RT_SUCCESS(rc))
+    {
+        if (pReq)
+        {
+            RTCCPHYS PhysAddr = VbglPhysHeapGetPhysAddr(pReq);
+            if (   PhysAddr != 0
+                && PhysAddr < _4G) /* Port IO is 32 bit. */
+            {
+                ASMOutU32(g_vbgldata.portVMMDev + VMMDEV_PORT_OFF_REQUEST, (uint32_t)PhysAddr);
+                /* Make the compiler aware that the host has changed memory. */
+                ASMCompilerBarrier();
+                rc = pReq->rc;
+            }
+            else
+                rc = VERR_VBGL_INVALID_ADDR;
+        }
+        else
+            rc = VERR_INVALID_PARAMETER;
+    }
+    return rc;
 }
 
+DECLVBGL(void) VbglGRFree(VMMDevRequestHeader *pReq)
+{
+    int rc = vbglR0Enter();
+    if (RT_SUCCESS(rc))
+        VbglPhysHeapFree(pReq);
+}
+
Index: /trunk/src/VBox/Additions/common/VBoxGuestLib/Init.cpp
===================================================================
--- /trunk/src/VBox/Additions/common/VBoxGuestLib/Init.cpp	(revision 58177)
+++ /trunk/src/VBox/Additions/common/VBoxGuestLib/Init.cpp	(revision 58178)
@@ -113,5 +113,5 @@
             dprintf (("port = 0x%04X, mem = %p\n", port.portAddress, port.pVMMDevMemory));
 
-            g_vbgldata.portVMMDev = port.portAddress;
+            g_vbgldata.portVMMDev = (RTIOPORT)port.portAddress;
             g_vbgldata.pVMMDevMemory = port.pVMMDevMemory;
 
@@ -187,5 +187,5 @@
 #ifdef VBGL_VBOXGUEST
 
-DECLVBGL(int) VbglInit (VBGLIOPORT portVMMDev, VMMDevMemory *pVMMDevMemory)
+DECLVBGL(int) VbglInitPrimary(RTIOPORT portVMMDev, VMMDevMemory *pVMMDevMemory)
 {
     int rc = VINF_SUCCESS;
@@ -194,5 +194,5 @@
     dprintf(("vbglInit: starts g_vbgldata.status %d\n", g_vbgldata.status));
 
-    if (g_vbgldata.status == VbglStatusInitializing
+    if (   g_vbgldata.status == VbglStatusInitializing
         || g_vbgldata.status == VbglStatusReady)
     {
@@ -233,9 +233,9 @@
 #else /* !VBGL_VBOXGUEST */
 
-DECLVBGL(int) VbglInit (void)
+DECLVBGL(int) VbglInitClient(void)
 {
     int rc = VINF_SUCCESS;
 
-    if (g_vbgldata.status == VbglStatusInitializing
+    if (   g_vbgldata.status == VbglStatusInitializing
         || g_vbgldata.status == VbglStatusReady)
     {
Index: /trunk/src/VBox/Additions/common/VBoxGuestLib/VBGLInternal.h
===================================================================
--- /trunk/src/VBox/Additions/common/VBoxGuestLib/VBGLInternal.h	(revision 58177)
+++ /trunk/src/VBox/Additions/common/VBoxGuestLib/VBGLInternal.h	(revision 58178)
@@ -73,9 +73,9 @@
  * Lives in VbglR0Init.cpp.
  */
-typedef struct _VBGLDATA
+typedef struct VBGLDATA
 {
     enum VbglLibStatus status;
 
-    VBGLIOPORT portVMMDev;
+    RTIOPORT portVMMDev;
 
     VMMDevMemory *pVMMDevMemory;
Index: /trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR0LibSharedFolders.c
===================================================================
--- /trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR0LibSharedFolders.c	(revision 58177)
+++ /trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR0LibSharedFolders.c	(revision 58178)
@@ -65,5 +65,5 @@
     int rc = VINF_SUCCESS;
 
-    rc = VbglInit ();
+    rc = VbglInitClient();
     return rc;
 }
Index: /trunk/src/VBox/Additions/os2/VBoxSF/VBoxSFInit.cpp
===================================================================
--- /trunk/src/VBox/Additions/os2/VBoxSF/VBoxSFInit.cpp	(revision 58177)
+++ /trunk/src/VBox/Additions/os2/VBoxSF/VBoxSFInit.cpp	(revision 58178)
@@ -64,10 +64,9 @@
  * The caller will do the necessary AttachDD and calling of the 16 bit
  * IDC to initialize the g_VBoxGuestIDC global. Perhaps we should move
- * this bit to VbglInit? It's just that it's so much simpler to do it
+ * this bit to VbglInitClient? It's just that it's so much simpler to do it
  * while we're on the way here...
  *
  */
-DECLASM(void)
-VBoxSFR0Init(void)
+DECLASM(void) VBoxSFR0Init(void)
 {
     Log(("VBoxSFR0Init: g_fpfnDevHlp=%lx u32Version=%RX32 u32Session=%RX32 pfnServiceEP=%p g_u32Info=%u (%#x)\n",
@@ -84,5 +83,5 @@
         if (RT_SUCCESS(rc))
         {
-            rc = VbglInit();
+            rc = VbglInitClient();
             if (RT_SUCCESS(rc))
             {
Index: /trunk/src/VBox/Additions/solaris/Mouse/testcase/solaris.h
===================================================================
--- /trunk/src/VBox/Additions/solaris/Mouse/testcase/solaris.h	(revision 58177)
+++ /trunk/src/VBox/Additions/solaris/Mouse/testcase/solaris.h	(revision 58178)
@@ -351,5 +351,5 @@
 #define VbglGRFree(...) do {} while(0)
 #endif
-#define VbglInit(...) VINF_SUCCESS
+#define VbglInitClient(...) VINF_SUCCESS
 #define vbglDriverOpen(...) VINF_SUCCESS
 #define vbglDriverClose(...) do {} while(0)
Index: /trunk/src/VBox/Additions/solaris/Mouse/vboxms.c
===================================================================
--- /trunk/src/VBox/Additions/solaris/Mouse/vboxms.c	(revision 58177)
+++ /trunk/src/VBox/Additions/solaris/Mouse/vboxms.c	(revision 58178)
@@ -471,5 +471,5 @@
          * init, and create a new session.
          */
-        rc = VbglInit();
+        rc = VbglInitClient();
         if (RT_SUCCESS(rc))
         {
