Index: trunk/src/VBox/HostDrivers/Support/solaris/SUPDrv-solaris.c
===================================================================
--- trunk/src/VBox/HostDrivers/Support/solaris/SUPDrv-solaris.c	(revision 4851)
+++ trunk/src/VBox/HostDrivers/Support/solaris/SUPDrv-solaris.c	(revision 4868)
@@ -210,191 +210,4 @@
 }
 
-/**
- * User context entry points
- */
-static int VBoxDrvSolarisOpen(dev_t *pDev, int fFlag, int fType, cred_t *pCred)
-{
-    int                 rc;
-    PSUPDRVSESSION      pSession;
-    dprintf(("VBoxDrvSolarisOpen: pDev=%p:%#x\n", pDev, *pDev));
-
-#ifndef USE_SESSION_HASH
-    /*
-     * Locate a new device open instance.
-     *
-     * For each open call we'll allocate an item in the soft state of the device.
-     * The item index is stored in the dev_t. I hope this is ok...
-     */
-    vbox_devstate_t *pState = NULL;
-    unsigned iOpenInstance;
-    for (iOpenInstance = 0; iOpenInstance < 4096; iOpenInstance++)
-    {
-        if (    !ddi_get_soft_state(g_pVBoxDrvSolarisState, iOpenInstance) /* faster */
-            &&  ddi_soft_state_zalloc(g_pVBoxDrvSolarisState, iOpenInstance) == DDI_SUCCESS)
-        {
-            pState = ddi_get_soft_state(g_pVBoxDrvSolarisState, iOpenInstance);
-            break;
-        }
-    }
-    if (!pState)
-    {
-        cmn_err(CE_NOTE,"VBoxDrvSolarisOpen: too many open instances.");
-        return ENXIO;
-    }
-
-    /*
-     * Create a new session.
-     */
-    rc = supdrvCreateSession(&g_DevExt, &pSession);
-    if (RT_SUCCESS(rc))
-    {
-        pState->pSession = pSession;
-        *pDev = makedevice(getmajor(*pDev), iOpenInstance);
-        dprintf(("VBoxDrvSolarisOpen: returns pDev=%#x pSession=%p pState=%p\n", *pDev, pSession, pState));
-        return 0;
-    }
-
-    /* failed - clean up */
-    ddi_soft_state_free(g_pVBoxDrvSolarisState, iOpenInstance);
-
-#else
-    /*
-     * Create a new session.
-     * Sessions in Solaris driver are mostly useless. It's however needed
-     * in VBoxDrvSolarisIOCtlSlow() while calling supdrvIOCtl()
-     */
-    rc = supdrvCreateSession(&g_DevExt, &pSession);
-    if (RT_SUCCESS(rc))
-    {
-        RTSPINLOCKTMP   Tmp = RTSPINLOCKTMP_INITIALIZER;
-        unsigned        iHash;
-
-        pSession->Uid       = crgetuid(pCred);
-        pSession->Gid       = crgetgid(pCred);
-        pSession->Process   = RTProcSelf();
-        pSession->R0Process = RTR0ProcHandleSelf();
-
-        /*
-         * Insert it into the hash table.
-         */
-        iHash = SESSION_HASH(pSession->Process);
-        RTSpinlockAcquireNoInts(g_Spinlock, &Tmp);
-        pSession->pNextHash = g_apSessionHashTab[iHash];
-        g_apSessionHashTab[iHash] = pSession;
-        RTSpinlockReleaseNoInts(g_Spinlock, &Tmp);
-        cmn_err(CE_NOTE,"VBoxDrvSolarisOpen success");
-    }
-
-    int instance;
-    for (instance = 0; instance < DEVICE_MAXINSTANCES; instance++)
-    {
-        vbox_devstate_t *pState = ddi_get_soft_state(g_pVBoxDrvSolarisState, instance);
-        if (pState)
-            break;
-    }
-
-    if (instance >= DEVICE_MAXINSTANCES)
-    {
-        cmn_err(CE_NOTE, "VBoxDrvSolarisOpen: All instances exhausted\n");
-        return ENXIO;
-    }
-
-    *pDev = makedevice(getmajor(*pDev), instance);
-
-    return VBoxSupDrvErr2SolarisErr(rc);
-#endif
-}
-
-
-static int VBoxDrvSolarisClose(dev_t Dev, int flag, int otyp, cred_t *cred)
-{
-    dprintf(("VBoxDrvSolarisClose: Dev=%#x\n", Dev));
-#ifndef USE_SESSION_HASH
-    /*
-     * Get the session and free the soft state item.
-     */
-    vbox_devstate_t *pState = ddi_get_soft_state(g_pVBoxDrvSolarisState, getminor(Dev));
-    if (!pState)
-    {
-        OSDBGPRINT(("VBoxDrvSolarisClose: no state data for %#x (%d)\n", Dev, getminor(Dev)));
-        return DDI_SUCCESS;
-    }
-
-    PSUPDRVSESSION pSession = pState->pSession;
-    pState->pSession = NULL;
-    ddi_soft_state_free(g_pVBoxDrvSolarisState, getminor(Dev));
-
-    if (!pSession)
-    {
-        OSDBGPRINT(("VBoxDrvSolarisClose: no session in state data for %#x (%d)\n", Dev, getminor(Dev)));
-        return DDI_SUCCESS;
-    }
-
-#else
-    RTSPINLOCKTMP   Tmp = RTSPINLOCKTMP_INITIALIZER;
-    const RTPROCESS Process = RTProcSelf();
-    const unsigned  iHash = SESSION_HASH(Process);
-    PSUPDRVSESSION  pSession;
-
-    /*
-     * Remove from the hash table.
-     */
-    RTSpinlockAcquireNoInts(g_Spinlock, &Tmp);
-    pSession = g_apSessionHashTab[iHash];
-    if (pSession)
-    {
-        if (pSession->Process == Process)
-        {
-            g_apSessionHashTab[iHash] = pSession->pNextHash;
-            pSession->pNextHash = NULL;
-        }
-        else
-        {
-            PSUPDRVSESSION pPrev = pSession;
-            pSession = pSession->pNextHash;
-            while (pSession)
-            {
-                if (pSession->Process == Process)
-                {
-                    pPrev->pNextHash = pSession->pNextHash;
-                    pSession->pNextHash = NULL;
-                    break;
-                }
-
-                /* next */
-                pPrev = pSession;
-                pSession = pSession->pNextHash;
-            }
-        }
-    }
-    RTSpinlockReleaseNoInts(g_Spinlock, &Tmp);
-    if (!pSession)
-    {
-        OSDBGPRINT(("VBoxDrvSolarisClose: WHAT?!? pSession == NULL! This must be a mistake... pid=%d (close)\n",
-                    (int)Process));
-        return DDI_FAILURE;
-    }
-#endif
-
-    /*
-     * Close the session.
-     */
-    supdrvCloseSession(&g_DevExt, pSession);
-    return DDI_SUCCESS;
-}
-
-
-static int VBoxDrvSolarisRead(dev_t Dev, struct uio *pUio, cred_t *pCred)
-{
-    cmn_err(CE_CONT, "VBoxDrvSolarisRead");
-    return DDI_SUCCESS;
-}
-
-
-static int VBoxDrvSolarisWrite(dev_t Dev, struct uio *pUio, cred_t *pCred)
-{
-    cmn_err(CE_CONT, "VBoxDrvSolarisWrite");
-    return DDI_SUCCESS;
-}
 
 /**
@@ -487,4 +300,5 @@
 }
 
+
 /**
  * Detach entry point, to detach a device to the system or suspend it.
@@ -531,4 +345,195 @@
     }
 }
+
+
+
+/**
+ * User context entry points
+ */
+static int VBoxDrvSolarisOpen(dev_t *pDev, int fFlag, int fType, cred_t *pCred)
+{
+    int                 rc;
+    PSUPDRVSESSION      pSession;
+    dprintf(("VBoxDrvSolarisOpen: pDev=%p:%#x\n", pDev, *pDev));
+
+#ifndef USE_SESSION_HASH
+    /*
+     * Locate a new device open instance.
+     *
+     * For each open call we'll allocate an item in the soft state of the device.
+     * The item index is stored in the dev_t. I hope this is ok...
+     */
+    vbox_devstate_t *pState = NULL;
+    unsigned iOpenInstance;
+    for (iOpenInstance = 0; iOpenInstance < 4096; iOpenInstance++)
+    {
+        if (    !ddi_get_soft_state(g_pVBoxDrvSolarisState, iOpenInstance) /* faster */
+            &&  ddi_soft_state_zalloc(g_pVBoxDrvSolarisState, iOpenInstance) == DDI_SUCCESS)
+        {
+            pState = ddi_get_soft_state(g_pVBoxDrvSolarisState, iOpenInstance);
+            break;
+        }
+    }
+    if (!pState)
+    {
+        cmn_err(CE_NOTE,"VBoxDrvSolarisOpen: too many open instances.");
+        return ENXIO;
+    }
+
+    /*
+     * Create a new session.
+     */
+    rc = supdrvCreateSession(&g_DevExt, &pSession);
+    if (RT_SUCCESS(rc))
+    {
+        pState->pSession = pSession;
+        *pDev = makedevice(getmajor(*pDev), iOpenInstance);
+        dprintf(("VBoxDrvSolarisOpen: returns pDev=%#x pSession=%p pState=%p\n", *pDev, pSession, pState));
+        return 0;
+    }
+
+    /* failed - clean up */
+    ddi_soft_state_free(g_pVBoxDrvSolarisState, iOpenInstance);
+
+#else
+    /*
+     * Create a new session.
+     * Sessions in Solaris driver are mostly useless. It's however needed
+     * in VBoxDrvSolarisIOCtlSlow() while calling supdrvIOCtl()
+     */
+    rc = supdrvCreateSession(&g_DevExt, &pSession);
+    if (RT_SUCCESS(rc))
+    {
+        RTSPINLOCKTMP   Tmp = RTSPINLOCKTMP_INITIALIZER;
+        unsigned        iHash;
+
+        pSession->Uid       = crgetuid(pCred);
+        pSession->Gid       = crgetgid(pCred);
+        pSession->Process   = RTProcSelf();
+        pSession->R0Process = RTR0ProcHandleSelf();
+
+        /*
+         * Insert it into the hash table.
+         */
+        iHash = SESSION_HASH(pSession->Process);
+        RTSpinlockAcquireNoInts(g_Spinlock, &Tmp);
+        pSession->pNextHash = g_apSessionHashTab[iHash];
+        g_apSessionHashTab[iHash] = pSession;
+        RTSpinlockReleaseNoInts(g_Spinlock, &Tmp);
+        cmn_err(CE_NOTE,"VBoxDrvSolarisOpen success");
+    }
+
+    int instance;
+    for (instance = 0; instance < DEVICE_MAXINSTANCES; instance++)
+    {
+        vbox_devstate_t *pState = ddi_get_soft_state(g_pVBoxDrvSolarisState, instance);
+        if (pState)
+            break;
+    }
+
+    if (instance >= DEVICE_MAXINSTANCES)
+    {
+        cmn_err(CE_NOTE, "VBoxDrvSolarisOpen: All instances exhausted\n");
+        return ENXIO;
+    }
+
+    *pDev = makedevice(getmajor(*pDev), instance);
+
+    return VBoxSupDrvErr2SolarisErr(rc);
+#endif
+}
+
+
+static int VBoxDrvSolarisClose(dev_t Dev, int flag, int otyp, cred_t *cred)
+{
+    dprintf(("VBoxDrvSolarisClose: Dev=%#x\n", Dev));
+#ifndef USE_SESSION_HASH
+    /*
+     * Get the session and free the soft state item.
+     */
+    vbox_devstate_t *pState = ddi_get_soft_state(g_pVBoxDrvSolarisState, getminor(Dev));
+    if (!pState)
+    {
+        OSDBGPRINT(("VBoxDrvSolarisClose: no state data for %#x (%d)\n", Dev, getminor(Dev)));
+        return DDI_SUCCESS;
+    }
+
+    PSUPDRVSESSION pSession = pState->pSession;
+    pState->pSession = NULL;
+    ddi_soft_state_free(g_pVBoxDrvSolarisState, getminor(Dev));
+
+    if (!pSession)
+    {
+        OSDBGPRINT(("VBoxDrvSolarisClose: no session in state data for %#x (%d)\n", Dev, getminor(Dev)));
+        return DDI_SUCCESS;
+    }
+
+#else
+    RTSPINLOCKTMP   Tmp = RTSPINLOCKTMP_INITIALIZER;
+    const RTPROCESS Process = RTProcSelf();
+    const unsigned  iHash = SESSION_HASH(Process);
+    PSUPDRVSESSION  pSession;
+
+    /*
+     * Remove from the hash table.
+     */
+    RTSpinlockAcquireNoInts(g_Spinlock, &Tmp);
+    pSession = g_apSessionHashTab[iHash];
+    if (pSession)
+    {
+        if (pSession->Process == Process)
+        {
+            g_apSessionHashTab[iHash] = pSession->pNextHash;
+            pSession->pNextHash = NULL;
+        }
+        else
+        {
+            PSUPDRVSESSION pPrev = pSession;
+            pSession = pSession->pNextHash;
+            while (pSession)
+            {
+                if (pSession->Process == Process)
+                {
+                    pPrev->pNextHash = pSession->pNextHash;
+                    pSession->pNextHash = NULL;
+                    break;
+                }
+
+                /* next */
+                pPrev = pSession;
+                pSession = pSession->pNextHash;
+            }
+        }
+    }
+    RTSpinlockReleaseNoInts(g_Spinlock, &Tmp);
+    if (!pSession)
+    {
+        OSDBGPRINT(("VBoxDrvSolarisClose: WHAT?!? pSession == NULL! This must be a mistake... pid=%d (close)\n",
+                    (int)Process));
+        return DDI_FAILURE;
+    }
+#endif
+
+    /*
+     * Close the session.
+     */
+    supdrvCloseSession(&g_DevExt, pSession);
+    return DDI_SUCCESS;
+}
+
+
+static int VBoxDrvSolarisRead(dev_t Dev, struct uio *pUio, cred_t *pCred)
+{
+    cmn_err(CE_CONT, "VBoxDrvSolarisRead");
+    return DDI_SUCCESS;
+}
+
+
+static int VBoxDrvSolarisWrite(dev_t Dev, struct uio *pUio, cred_t *pCred)
+{
+    cmn_err(CE_CONT, "VBoxDrvSolarisWrite");
+    return DDI_SUCCESS;
+}
+
 
 /**
@@ -733,4 +738,5 @@
 }
 
+
 /**
  * Initializes any OS specific object creator fields.
