Index: /trunk/include/VBox/VBoxGuest.h
===================================================================
--- /trunk/include/VBox/VBoxGuest.h	(revision 41851)
+++ /trunk/include/VBox/VBoxGuest.h	(revision 41852)
@@ -364,4 +364,7 @@
 #define VBOXGUEST_IOCTL_SET_MOUSE_NOTIFY_CALLBACK   VBOXGUEST_IOCTL_CODE_(31, sizeof(VBoxGuestMouseSetNotifyCallback))
 
+typedef DECLCALLBACK(void) FNVBOXGUESTMOUSENOTIFY(void *pfnUser);
+typedef FNVBOXGUESTMOUSENOTIFY *PFNVBOXGUESTMOUSENOTIFY;
+
 /** Input buffer for VBOXGUEST_IOCTL_INTERNAL_SET_MOUSE_NOTIFY_CALLBACK. */
 typedef struct VBoxGuestMouseSetNotifyCallback
@@ -372,5 +375,5 @@
      * @param   pvUser      The callback argument.
      */
-    DECLR0CALLBACKMEMBER(void,  pfnNotify, (void *pvUser));
+    PFNVBOXGUESTMOUSENOTIFY      pfnNotify;
     /** The callback argument*/
     void                       *pvUser;
Index: /trunk/include/VBox/VBoxGuestLib.h
===================================================================
--- /trunk/include/VBox/VBoxGuestLib.h	(revision 41851)
+++ /trunk/include/VBox/VBoxGuestLib.h	(revision 41852)
@@ -31,4 +31,5 @@
 #include <VBox/VMMDev.h>     /* grumble */
 #ifdef IN_RING0
+# include <VBox/VBoxGuest.h>
 # include <VBox/VBoxGuest2.h>
 #endif
@@ -111,4 +112,10 @@
  */
 DECLVBGL(int) VbglInit (void);
+
+/**
+ * Check whether the main VBoxGuest driver is loaded.  (The load order of guest
+ * drivers is not guaranteed on all platforms.)
+ */
+DECLVBGL(bool) VbglIsReady(void);
 
 # endif
@@ -392,4 +399,13 @@
 DECLVBGL(int) VbglQueryVMMDevMemory (VMMDevMemory **ppVMMDevMemory);
 DECLR0VBGL(bool) VbglR0CanUsePhysPageList(void);
+
+# ifndef VBOX_GUEST
+/** @name Mouse
+ * @{ */
+DECLVBGL(int)     VbglSetMouseNotifyCallback(PFNVBOXGUESTMOUSENOTIFY pfnNotify, void *pvUser);
+DECLVBGL(int)     VbglGetMouseStatus(uint32_t *pfFeatures, uint32_t *px, uint32_t *py);
+DECLVBGL(int)     VbglSetMouseStatus(uint32_t fFeatures);
+/** @}  */
+# endif /* VBOX_GUEST */
 
 #endif /* IN_RING0 && !IN_RING0_AGNOSTIC */
Index: /trunk/src/VBox/Additions/common/VBoxGuestLib/Init.cpp
===================================================================
--- /trunk/src/VBox/Additions/common/VBoxGuestLib/Init.cpp	(revision 41851)
+++ /trunk/src/VBox/Additions/common/VBoxGuestLib/Init.cpp	(revision 41852)
@@ -33,4 +33,5 @@
 #include <iprt/string.h>
 #include <iprt/assert.h>
+#include <iprt/semaphore.h>
 
 /*******************************************************************************
@@ -41,5 +42,5 @@
 
 /**
- * Used by vbglQueryVMMDevPort and VbglInit to try get the host feature mask and
+ * Used by vbglQueryDriverInfo and VbglInit to try get the host feature mask and
  * version information (g_vbgldata::hostVersion).
  *
@@ -78,11 +79,20 @@
  *
  */
-static void vbglQueryVMMDevPort (void)
+static void vbglQueryDriverInfo (void)
 {
     int rc = VINF_SUCCESS;
 
-    VBGLDRIVER driver;
-
-    rc = vbglDriverOpen (&driver);
+    rc = RTSemFastMutexRequest(g_vbgldata.mutexDriverInit);
+    
+    if (RT_FAILURE(rc))
+        return;
+
+    if (g_vbgldata.status == VbglStatusReady)
+    {
+        RTSemFastMutexRelease(g_vbgldata.mutexDriverInit);
+        return;
+    }
+
+    rc = vbglDriverOpen(&g_vbgldata.driver);
 
     if (RT_SUCCESS(rc))
@@ -93,5 +103,7 @@
         VBoxGuestPortInfo port;
 
-        rc = vbglDriverIOCtl (&driver, VBOXGUEST_IOCTL_GETVMMDEVPORT, &port, sizeof (port));
+        rc = vbglDriverIOCtl (&g_vbgldata.driver,
+                              VBOXGUEST_IOCTL_GETVMMDEVPORT, &port,
+                              sizeof (port));
 
         if (RT_SUCCESS (rc))
@@ -106,9 +118,7 @@
             vbglR0QueryHostVersion();
         }
-
-        vbglDriverClose (&driver);
-    }
-
-    dprintf (("vbglQueryVMMDevPort rc = %d\n", rc));
+    }
+    RTSemFastMutexRelease(g_vbgldata.mutexDriverInit);
+    dprintf (("vbglQueryDriverInfo rc = %d\n", rc));
 }
 #endif /* !VBGL_VBOXGUEST */
@@ -128,5 +138,5 @@
     if (g_vbgldata.status == VbglStatusInitializing)
     {
-        vbglQueryVMMDevPort ();
+        vbglQueryDriverInfo ();
     }
 #endif
@@ -234,10 +244,20 @@
     if (RT_SUCCESS(rc))
     {
-        /* Try to obtain VMMDev port via IOCTL to VBoxGuest main driver. */
-        vbglQueryVMMDevPort ();
+        rc = RTSemFastMutexCreate(&g_vbgldata.mutexDriverInit);
+        if (RT_SUCCESS(rc))
+        {
+            /* Try to obtain VMMDev port via IOCTL to VBoxGuest main driver. */
+            vbglQueryDriverInfo ();
 
 # ifdef VBOX_WITH_HGCM
-        rc = vbglR0HGCMInit ();
+            rc = vbglR0HGCMInit ();
 # endif /* VBOX_WITH_HGCM */
+
+            if (RT_FAILURE(rc))
+            {
+                RTSemFastMutexDestroy(g_vbgldata.mutexDriverInit);
+                g_vbgldata.mutexDriverInit = NIL_RTSEMFASTMUTEX;
+            }
+        }
 
         if (RT_FAILURE(rc))
@@ -245,7 +265,13 @@
             vbglTerminateCommon ();
         }
+        
     }
 
     return rc;
+}
+
+DECLVBGL(bool) VbglIsReady(void)
+{
+    return(g_vbgldata.status == VbglStatusReady);
 }
 
@@ -257,8 +283,22 @@
 
     vbglTerminateCommon ();
+    vbglDriverClose(&g_vbgldata.driver);
+    RTSemFastMutexDestroy(g_vbgldata.mutexDriverInit);
+    g_vbgldata.mutexDriverInit = NIL_RTSEMFASTMUTEX;
 
     return;
 }
 
+int vbglGetDriver(VBGLDRIVER **ppDriver)
+{
+    if (g_vbgldata.status != VbglStatusReady)
+    {
+        vbglQueryDriverInfo();
+        if (g_vbgldata.status != VbglStatusReady)
+            return VERR_TRY_AGAIN;
+    }
+    *ppDriver = &g_vbgldata.driver;
+    return VINF_SUCCESS;
+}
+
 #endif /* !VBGL_VBOXGUEST */
-
Index: /trunk/src/VBox/Additions/common/VBoxGuestLib/Makefile.kmk
===================================================================
--- /trunk/src/VBox/Additions/common/VBoxGuestLib/Makefile.kmk	(revision 41851)
+++ /trunk/src/VBox/Additions/common/VBoxGuestLib/Makefile.kmk	(revision 41852)
@@ -61,4 +61,5 @@
 	PhysHeap.cpp \
 	Init.cpp \
+	Mouse.cpp \
 	VMMDev.cpp \
 	HGCM.cpp \
Index: /trunk/src/VBox/Additions/common/VBoxGuestLib/Mouse.cpp
===================================================================
--- /trunk/src/VBox/Additions/common/VBoxGuestLib/Mouse.cpp	(revision 41852)
+++ /trunk/src/VBox/Additions/common/VBoxGuestLib/Mouse.cpp	(revision 41852)
@@ -0,0 +1,82 @@
+/* $Revision$ */
+/** @file
+ * VBoxGuestLibR0 - Mouse Integration.
+ */
+
+/*
+ * Copyright (C) 2012 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ *
+ * The contents of this file may alternatively be used under the terms
+ * of the Common Development and Distribution License Version 1.0
+ * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
+ * VirtualBox OSE distribution, in which case the provisions of the
+ * CDDL are applicable instead of those of the GPL.
+ *
+ * You may elect to license modified versions of this file under the
+ * terms and conditions of either the GPL or the CDDL or both.
+ */
+
+#include "VBGLInternal.h"
+
+DECLVBGL(int) VbglSetMouseNotifyCallback(PFNVBOXGUESTMOUSENOTIFY pfnNotify,
+                                         void *pvUser)
+{
+    VBoxGuestMouseSetNotifyCallback NotifyCallback;
+    VBGLDRIVER *pDriver;
+    int rc;
+
+    rc = vbglGetDriver(&pDriver);
+    if (RT_FAILURE(rc))
+        return rc;
+    NotifyCallback.pfnNotify = pfnNotify;
+    NotifyCallback.pvUser    = pvUser;
+    return vbglDriverIOCtl(pDriver, VBOXGUEST_IOCTL_SET_MOUSE_NOTIFY_CALLBACK,
+                           &NotifyCallback, sizeof(NotifyCallback));
+}
+
+DECLVBGL(int) VbglGetMouseStatus(uint32_t *pfFeatures, uint32_t *px,
+                                 uint32_t *py)
+{
+    VMMDevReqMouseStatus Req;
+    VBGLDRIVER *pDriver;
+    int rc;
+
+    rc = vbglGetDriver(&pDriver);
+    if (RT_FAILURE(rc))
+        return rc;
+    vmmdevInitRequest(&Req.header, VMMDevReq_GetMouseStatus);
+    Req.mouseFeatures = 0;
+    Req.pointerXPos = 0;
+    Req.pointerYPos = 0;
+    rc = vbglDriverIOCtl(pDriver, VBOXGUEST_IOCTL_VMMREQUEST(sizeof(Req)),
+                         &Req.header, sizeof(Req));
+    if (RT_FAILURE(rc))
+        return rc;
+    if (pfFeatures)
+        *pfFeatures = Req.mouseFeatures;
+    if (px)
+        *px = Req.pointerXPos;
+    if (py)
+        *py = Req.pointerYPos;
+    return VINF_SUCCESS;
+}
+
+DECLVBGL(int) VbglSetMouseStatus(uint32_t fFeatures)
+{
+    VBGLDRIVER *pDriver;
+    int rc;
+
+    rc = vbglGetDriver(&pDriver);
+    if (RT_FAILURE(rc))
+        return rc;
+    return vbglDriverIOCtl(pDriver, VBOXGUEST_IOCTL_SET_MOUSE_STATUS,
+                           &fFeatures, sizeof(fFeatures));
+}
Index: /trunk/src/VBox/Additions/common/VBoxGuestLib/VBGLInternal.h
===================================================================
--- /trunk/src/VBox/Additions/common/VBoxGuestLib/VBGLInternal.h	(revision 41851)
+++ /trunk/src/VBox/Additions/common/VBoxGuestLib/VBGLInternal.h	(revision 41852)
@@ -101,4 +101,15 @@
 #ifndef VBGL_VBOXGUEST
     /**
+     * Handle for the main driver instance.
+     * @{
+     */
+
+    RTSEMFASTMUTEX mutexDriverInit;
+
+    VBGLDRIVER driver;
+
+    /** @} */
+
+    /**
      * Fast heap for HGCM handles data.
      * @{
@@ -156,4 +167,12 @@
 #endif /* VBOX_WITH_HGCM */
 
+#ifndef VBGL_VBOXGUEST
+/**
+ * Get a handle to the main VBoxGuest driver.
+ * @returns VERR_TRY_AGAIN if the main driver has not yet been loaded.
+ */
+int vbglGetDriver(VBGLDRIVER **ppDriver);
+#endif
+
 #endif /* !___VBoxGuestLib_VBGLInternal_h */
 
Index: /trunk/src/VBox/Additions/solaris/Mouse/Makefile.kmk
===================================================================
--- /trunk/src/VBox/Additions/solaris/Mouse/Makefile.kmk	(revision 41851)
+++ /trunk/src/VBox/Additions/solaris/Mouse/Makefile.kmk	(revision 41852)
@@ -33,19 +33,19 @@
 
 #
-# vboxmouse - The Mouse Integration Driver
+# vboxms - The Mouse Integration Driver
 #
-SYSMODS.solaris     += vboxmouse
-vboxmouse_TEMPLATE   = VBOXGUESTR0
-vboxmouse_DEFS       = VBOX_WITH_HGCM VBOX_SVN_REV=$(VBOX_SVN_REV)
-vboxmouse_DEPS      += $(VBOX_SVN_REV_KMK)
-vboxmouse_SOURCES    = \
+SYSMODS.solaris     += vboxms
+vboxms_TEMPLATE   = VBOXGUESTR0
+vboxms_DEFS       = VBOX_WITH_HGCM VBOX_SVN_REV=$(VBOX_SVN_REV)
+vboxms_DEPS      += $(VBOX_SVN_REV_KMK)
+vboxms_SOURCES    = \
 	vboxmouse.c
-vboxmouse_LIBS       = \
+vboxms_LIBS       = \
 	$(VBOX_LIB_VBGL_R0)
 ifeq ($(KBUILD_HOST),solaris)
- vboxmouse_LDFLAGS         += -N drv/vboxguest -N misc/ctf
+ vboxms_LDFLAGS         += -N drv/vboxguest -N misc/ctf
 else
- vboxmouse_SOURCES         += deps.asm
- vboxmouse_deps.asm_ASFLAGS = -f bin -g null
+ vboxms_SOURCES         += deps.asm
+ vboxms_deps.asm_ASFLAGS = -f bin -g null
 endif
 
Index: /trunk/src/VBox/Additions/solaris/Mouse/testcase/solaris.h
===================================================================
--- /trunk/src/VBox/Additions/solaris/Mouse/testcase/solaris.h	(revision 41851)
+++ /trunk/src/VBox/Additions/solaris/Mouse/testcase/solaris.h	(revision 41852)
@@ -335,7 +335,9 @@
 #define RTR0Init(...) VINF_SUCCESS
 #define RTR0Term(...) do {} while(0)
+#define RTR0AssertPanicSystem(...) do {} while(0)
 #define RTLogCreate(...) VINF_SUCCESS
 #define RTLogRelSetDefaultInstance(...) do {} while(0)
 #define RTLogDestroy(...) do {} while(0)
+#if 0
 #define VBoxGuestCreateKernelSession(...) VINF_SUCCESS
 #define VBoxGuestCreateUserSession(...) VINF_SUCCESS
@@ -348,4 +350,9 @@
 #define VbglGRPerform(...) VINF_SUCCESS
 #define VbglGRFree(...) do {} while(0)
+#endif
+#define VbglInit(...) VINF_SUCCESS
+#define vbglDriverOpen(...) VINF_SUCCESS
+#define vbglDriverClose(...) do {} while(0)
+#define vbglDriverIOCtl(...) VINF_SUCCESS
 #define qprocson(...) do {} while(0)
 #define qprocsoff(...) do {} while(0)
Index: /trunk/src/VBox/Additions/solaris/Mouse/vboxmouse.c
===================================================================
--- /trunk/src/VBox/Additions/solaris/Mouse/vboxmouse.c	(revision 41851)
+++ /trunk/src/VBox/Additions/solaris/Mouse/vboxmouse.c	(revision 41852)
@@ -78,5 +78,5 @@
 #define DEVICE_NAME              "vboxmouse"
 /** The module description as seen in 'modinfo'. */
-#define DEVICE_DESC              "VirtualBox MouInt"
+#define DEVICE_DESC              "VBoxMouseIntegr"
 
 
@@ -102,6 +102,6 @@
 static struct module_info g_vbmsSolModInfo =
 {
-    0x0ffff,                /* module id number */
-    "vboxmouse",
+    0,                      /* module id number */
+    "vboxms",
     0,                      /* minimum packet size */
     INFPSZ,                 /* maximum packet size accepted */
@@ -159,7 +159,7 @@
  */
 static struct fmodsw g_vbmsSolStrWrapper = {
-    "vboxmouse",
+    "vboxms",
     &g_vbmsSolStreamTab,
-    D_MP | D_MTPERMOD
+    D_MP
 };
 
@@ -193,6 +193,4 @@
 typedef struct
 {
-    /** Pointer to the Guest Library handle for the main driver. */
-    VBGLDRIVER         Driver;
     /** The STREAMS write queue which we need for sending messages up to
      * user-space. */
@@ -286,17 +284,4 @@
 
 /******************************************************************************
-*   Helper routines                                                           *
-******************************************************************************/
-
-/** Calls the kernel IOCtl to report mouse status to the host on behalf of
- * an open session. */
-static int vbmsSolSetMouseStatus(VBGLDRIVER *pDriver, uint32_t fStatus)
-{
-    return vbglDriverIOCtl(pDriver, VBOXGUEST_IOCTL_SET_MOUSE_STATUS, &fStatus,
-                           sizeof(fStatus));
-}
-
-
-/******************************************************************************
 *   Main code                                                                 *
 ******************************************************************************/
@@ -341,18 +326,11 @@
      * Create a new session.
      */
-    rc = vbglDriverOpen(&pState->Driver);
-    if (RT_SUCCESS(rc))
-    {
-        VBoxGuestMouseSetNotifyCallback NotifyCallback;
-
+    if (VbglIsReady())
+    {
         /* Initialise user data for the queues to our state and vice-versa. */
         WR(pReadQueue)->q_ptr = (char *)pState;
         pReadQueue->q_ptr = (char *)pState;
         /* Enable our IRQ handler. */
-        NotifyCallback.pfnNotify = vbmsSolNotify;
-        NotifyCallback.pvUser    = (void *)pState;
-        vbglDriverIOCtl(&pState->Driver,
-                        VBOXGUEST_IOCTL_SET_MOUSE_NOTIFY_CALLBACK,
-                        &NotifyCallback, sizeof(NotifyCallback));
+        VbglSetMouseNotifyCallback(vbmsSolNotify, (void *)pState);
         qprocson(pReadQueue);
         LogRel((DEVICE_NAME "::Open\n"));
@@ -377,16 +355,9 @@
 {
     PVBMSSTATE pState = (PVBMSSTATE)pvState;
-    VMMDevReqMouseStatus *pReq;
     int rc;
+    uint32_t x, y;
     LogFlow((DEVICE_NAME "::NativeISRMousePollEvent:\n"));
 
-    rc = VbglGRAlloc((VMMDevRequestHeader **)&pReq, sizeof(*pReq),
-                     VMMDevReq_GetMouseStatus);
-    if (RT_FAILURE(rc))
-        return;  /* If kernel memory is short a missed event is acceptable! */
-    pReq->mouseFeatures = 0;
-    pReq->pointerXPos = 0;
-    pReq->pointerYPos = 0;
-    rc = VbglGRPerform(&pReq->header);
+    rc = VbglGetMouseStatus(NULL, &x, &y);
     if (RT_SUCCESS(rc))
     {
@@ -397,12 +368,9 @@
         {
             vbmsSolVUIDPutAbsEvent(pState, LOC_X_ABSOLUTE,
-                                     pReq->pointerXPos * cMaxScreenX
-                                   / VMMDEV_MOUSE_RANGE_MAX);
+                                   x * cMaxScreenX / VMMDEV_MOUSE_RANGE_MAX);
             vbmsSolVUIDPutAbsEvent(pState, LOC_Y_ABSOLUTE,
-                                     pReq->pointerYPos * cMaxScreenY
-                                   / VMMDEV_MOUSE_RANGE_MAX);
+                                   y * cMaxScreenY / VMMDEV_MOUSE_RANGE_MAX);
         }
     }
-    VbglGRFree(&pReq->header);
 }
 
@@ -439,5 +407,4 @@
 {
     PVBMSSTATE pState = (PVBMSSTATE)pReadQueue->q_ptr;
-    VBoxGuestMouseSetNotifyCallback NotifyCallback;
 
     LogFlow((DEVICE_NAME "::Close\n"));
@@ -451,9 +418,7 @@
     }
 
+    VbglSetMouseStatus(0);
     /* Disable our IRQ handler. */
-    RT_ZERO(NotifyCallback);
-    vbglDriverIOCtl(&pState->Driver,
-                    VBOXGUEST_IOCTL_SET_MOUSE_NOTIFY_CALLBACK,
-                    &NotifyCallback, sizeof(NotifyCallback));
+    VbglSetMouseNotifyCallback(NULL, NULL);
     qprocsoff(pReadQueue);
 
@@ -461,5 +426,4 @@
      * Close the session.
      */
-    vbglDriverClose(&pState->Driver);
     ASMAtomicWriteNullPtr(&pState->pWriteQueue);
     pReadQueue->q_ptr = NULL;
@@ -1198,7 +1162,6 @@
             pState->cMaxScreenY = pResolution->height - 1;
             /* Note: we don't disable this again until session close. */
-            rc = vbmsSolSetMouseStatus(&pState->Driver,
-                                         VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE
-                                       | VMMDEV_MOUSE_NEW_PROTOCOL);
+            rc = VbglSetMouseStatus(  VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE
+                                    | VMMDEV_MOUSE_NEW_PROTOCOL);
             if (RT_SUCCESS(rc))
                 return 0;
