Index: /trunk/src/VBox/HostDrivers/Support/Makefile.kmk
===================================================================
--- /trunk/src/VBox/HostDrivers/Support/Makefile.kmk	(revision 19891)
+++ /trunk/src/VBox/HostDrivers/Support/Makefile.kmk	(revision 19892)
@@ -82,4 +82,5 @@
 SUPR3_SOURCES       = \
 	SUPLib.cpp \
+	SUPLibSem.cpp \
 	SUPR3HardenedIPRT.cpp \
 	SUPR3HardenedVerify.cpp \
Index: /trunk/src/VBox/HostDrivers/Support/SUPLib.cpp
===================================================================
--- /trunk/src/VBox/HostDrivers/Support/SUPLib.cpp	(revision 19891)
+++ /trunk/src/VBox/HostDrivers/Support/SUPLib.cpp	(revision 19892)
@@ -100,5 +100,5 @@
  * Well, at least parts of it, specificly the parts that are being handed over
  * via the pre-init mechanism from the hardened executable stub.  */
-static SUPLIBDATA               g_supLibData =
+SUPLIBDATA                      g_supLibData =
 {
     NIL_RTFILE
Index: /trunk/src/VBox/HostDrivers/Support/SUPLibInternal.h
===================================================================
--- /trunk/src/VBox/HostDrivers/Support/SUPLibInternal.h	(revision 19891)
+++ /trunk/src/VBox/HostDrivers/Support/SUPLibInternal.h	(revision 19892)
@@ -97,15 +97,4 @@
 
 /*******************************************************************************
-*   Global Variables                                                           *
-*******************************************************************************/
-/** The negotiated interrupt number. */
-extern DECLHIDDEN(uint8_t)        g_uchInterruptNo;
-/** The negotiated cookie. */
-extern DECLHIDDEN(uint32_t)       g_u32Cookie;
-/** The negotiated cookie. */
-extern DECLHIDDEN(uint32_t)       g_u32CookieSession;
-
-
-/*******************************************************************************
 *   Structures and Typedefs                                                    *
 *******************************************************************************/
@@ -243,4 +232,12 @@
 
 /*******************************************************************************
+*   Global Variables                                                           *
+*******************************************************************************/
+extern DECLHIDDEN(uint32_t)     g_u32Cookie;
+extern DECLHIDDEN(uint32_t)     g_u32SessionCookie;
+extern DECLHIDDEN(SUPLIBDATA)   g_supLibData;
+
+
+/*******************************************************************************
 *   OS Specific Function                                                       *
 *******************************************************************************/
Index: /trunk/src/VBox/HostDrivers/Support/SUPLibSem.cpp
===================================================================
--- /trunk/src/VBox/HostDrivers/Support/SUPLibSem.cpp	(revision 19892)
+++ /trunk/src/VBox/HostDrivers/Support/SUPLibSem.cpp	(revision 19892)
@@ -0,0 +1,169 @@
+/* $Id$ */
+/** @file
+ * VirtualBox Support Library - Semaphores, ring-3 implementation.
+ */
+
+/*
+ * Copyright (C) 2009 Sun Microsystems, Inc.
+ *
+ * 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.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
+ * Clara, CA 95054 USA or visit http://www.sun.com if you need
+ * additional information or have any questions.
+ */
+
+
+/*******************************************************************************
+*   Header Files                                                               *
+*******************************************************************************/
+#define LOG_GROUP LOG_GROUP_SUP
+#include <VBox/sup.h>
+
+#include <VBox/err.h>
+#include <VBox/param.h>
+#include <iprt/assert.h>
+
+#include "SUPLibInternal.h"
+#include "SUPDrvIOC.h"
+
+
+/**
+ * Worker that makes a SUP_IOCTL_SEM_OP request.
+ *
+ * @returns VBox status code.
+ * @param   pSession            The session handle.
+ * @param   uType               The semaphore type.
+ * @param   hSem                The semaphore handle.
+ * @param   uOp                 The operation.
+ * @param   cMillies            The timeout if applicable, otherwise 0.
+ */
+DECLINLINE(int) supSemOp(PSUPDRVSESSION pSession, uint32_t uType, uintptr_t hSem, uint32_t uOp, uint32_t cMillies)
+{
+    SUPSEMOP Req;
+    Req.Hdr.u32Cookie           = g_u32Cookie;
+    Req.Hdr.u32SessionCookie    = g_u32SessionCookie;
+    Req.Hdr.cbIn                = SUP_IOCTL_SEM_OP_SIZE_IN;
+    Req.Hdr.cbOut               = SUP_IOCTL_SEM_OP_SIZE_OUT;
+    Req.Hdr.fFlags              = SUPREQHDR_FLAGS_DEFAULT;
+    Req.Hdr.rc                  = VERR_INTERNAL_ERROR;
+    Req.u.In.uType              = uType;
+    Req.u.In.hSem               = (uint32_t)hSem;
+    AssertReturn(Req.u.In.hSem == hSem, VERR_INVALID_HANDLE);
+    Req.u.In.uOp                = uOp;
+    Req.u.In.cMillies           = 0;
+    int rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_SEM_OP, &Req, sizeof(Req));
+    if (RT_SUCCESS(rc))
+        rc = Req.Hdr.rc;
+
+    return rc;
+}
+
+
+SUPDECL(int) SUPSemEventCreate(PSUPDRVSESSION pSession, PSUPSEMEVENT phEvent)
+{
+    AssertPtrReturn(phEvent, VERR_INVALID_POINTER);
+
+    SUPSEMCREATE Req;
+    Req.Hdr.u32Cookie           = g_u32Cookie;
+    Req.Hdr.u32SessionCookie    = g_u32SessionCookie;
+    Req.Hdr.cbIn                = SUP_IOCTL_SEM_CREATE_SIZE_IN;
+    Req.Hdr.cbOut               = SUP_IOCTL_SEM_CREATE_SIZE_OUT;
+    Req.Hdr.fFlags              = SUPREQHDR_FLAGS_DEFAULT;
+    Req.Hdr.rc                  = VERR_INTERNAL_ERROR;
+    Req.u.In.uType              = SUP_SEM_TYPE_EVENT;
+    int rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_SEM_CREATE, &Req, sizeof(Req));
+    if (RT_SUCCESS(rc))
+    {
+        rc = Req.Hdr.rc;
+        if (RT_SUCCESS(rc))
+            *phEvent = (SUPSEMEVENT)(uintptr_t)Req.u.Out.hSem;
+    }
+
+    return rc;
+}
+
+
+SUPDECL(int) SUPSemEventClose(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent)
+{
+    if (hEvent == NIL_SUPSEMEVENT)
+        return VINF_SUCCESS;
+    return supSemOp(pSession, SUP_SEM_TYPE_EVENT, (uintptr_t)hEvent, SUPSEMOP_CLOSE, 0);
+}
+
+
+SUPDECL(int) SUPSemEventSignal(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent)
+{
+    return supSemOp(pSession, SUP_SEM_TYPE_EVENT, (uintptr_t)hEvent, SUPSEMOP_SIGNAL, 0);
+}
+
+
+SUPDECL(int) SUPSemEventWaitNoResume(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent, uint32_t cMillies)
+{
+    return supSemOp(pSession, SUP_SEM_TYPE_EVENT, (uintptr_t)hEvent, SUPSEMOP_WAIT, cMillies);
+}
+
+SUPDECL(int) SUPSemEventMultiCreate(PSUPDRVSESSION pSession, PSUPSEMEVENTMULTI phEventMulti)
+{
+    AssertPtrReturn(phEventMulti, VERR_INVALID_POINTER);
+
+    SUPSEMCREATE Req;
+    Req.Hdr.u32Cookie           = g_u32Cookie;
+    Req.Hdr.u32SessionCookie    = g_u32SessionCookie;
+    Req.Hdr.cbIn                = SUP_IOCTL_SEM_CREATE_SIZE_IN;
+    Req.Hdr.cbOut               = SUP_IOCTL_SEM_CREATE_SIZE_OUT;
+    Req.Hdr.fFlags              = SUPREQHDR_FLAGS_DEFAULT;
+    Req.Hdr.rc                  = VERR_INTERNAL_ERROR;
+    Req.u.In.uType              = SUP_SEM_TYPE_EVENT_MULTI;
+    int rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_SEM_CREATE, &Req, sizeof(Req));
+    if (RT_SUCCESS(rc))
+    {
+        rc = Req.Hdr.rc;
+        if (RT_SUCCESS(rc))
+            *phEventMulti = (SUPSEMEVENTMULTI)(uintptr_t)Req.u.Out.hSem;
+    }
+
+    return rc;
+}
+
+
+SUPDECL(int) SUPSemEventMultiClose(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti)
+{
+    if (hEventMulti == NIL_SUPSEMEVENTMULTI)
+        return VINF_SUCCESS;
+    return supSemOp(pSession, SUP_SEM_TYPE_EVENT_MULTI, (uintptr_t)hEventMulti, SUPSEMOP_CLOSE, 0);
+}
+
+
+SUPDECL(int) SUPSemEventMultiSignal(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti)
+{
+    return supSemOp(pSession, SUP_SEM_TYPE_EVENT_MULTI, (uintptr_t)hEventMulti, SUPSEMOP_SIGNAL, 0);
+}
+
+
+SUPDECL(int) SUPSemEventMultiReset(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti)
+{
+    return supSemOp(pSession, SUP_SEM_TYPE_EVENT_MULTI, (uintptr_t)hEventMulti, SUPSEMOP_RESET, 0);
+}
+
+
+SUPDECL(int) SUPSemEventMultiWaitNoResume(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti, uint32_t cMillies)
+{
+    return supSemOp(pSession, SUP_SEM_TYPE_EVENT_MULTI, (uintptr_t)hEventMulti, SUPSEMOP_WAIT, cMillies);
+}
+
Index: /trunk/src/VBox/HostDrivers/Support/testcase/Makefile.kmk
===================================================================
--- /trunk/src/VBox/HostDrivers/Support/testcase/Makefile.kmk	(revision 19891)
+++ /trunk/src/VBox/HostDrivers/Support/testcase/Makefile.kmk	(revision 19892)
@@ -5,5 +5,5 @@
 
 #
-# Copyright (C) 2006-2007 Sun Microsystems, Inc.
+# Copyright (C) 2006-2009 Sun Microsystems, Inc.
 #
 # This file is part of VirtualBox Open Source Edition (OSE), as
@@ -45,5 +45,6 @@
 	tstPin \
 	tstGIP-2 \
-	tstGetPagingMode
+	tstGetPagingMode \
+	tstSupSem
 endif # VBOX_WITH_TESTCASES
 
@@ -85,4 +86,7 @@
 tstGetPagingMode_SOURCES = tstGetPagingMode.cpp
 
+tstSupSem_TEMPLATE    = VBOXR3TSTEXE
+tstSupSem_SOURCES     = tstSupSem.cpp
+
 include $(KBUILD_PATH)/subfooter.kmk
 
Index: /trunk/src/VBox/HostDrivers/Support/testcase/tstSupSem.cpp
===================================================================
--- /trunk/src/VBox/HostDrivers/Support/testcase/tstSupSem.cpp	(revision 19892)
+++ /trunk/src/VBox/HostDrivers/Support/testcase/tstSupSem.cpp	(revision 19892)
@@ -0,0 +1,117 @@
+/* $Id$ */
+/** @file
+ * Support Library Testcase - Ring-3 Semaphore interface.
+ */
+
+/*
+ * Copyright (C) 2009 Sun Microsystems, Inc.
+ *
+ * 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.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
+ * Clara, CA 95054 USA or visit http://www.sun.com if you need
+ * additional information or have any questions.
+ */
+
+
+/*******************************************************************************
+*   Header Files                                                               *
+*******************************************************************************/
+#include <VBox/sup.h>
+
+#include <VBox/param.h>
+#include <iprt/initterm.h>
+#include <iprt/test.h>
+#include <iprt/stream.h>
+#include <iprt/string.h>
+
+
+int main(int argc, char **argv)
+{
+    /*
+     * Init.
+     */
+    int rc = RTR3InitAndSUPLib();
+    if (RT_FAILURE(rc))
+    {
+        RTPrintf("tstSupSem: fatal error: RTR3InitAndSUPLib failed with rc=%Rrc\n", rc);
+        return 1;
+    }
+    RTTEST hTest;
+    rc = RTTestCreate("tstSupSem", &hTest);
+    if (RT_FAILURE(rc))
+    {
+        RTPrintf("tstSupSem: fatal error: RTTestCreate failed with rc=%Rrc\n", rc);
+        return 1;
+    }
+    PSUPDRVSESSION pSession;
+    rc = SUPR3Init(&pSession);
+    if (RT_FAILURE(rc))
+    {
+        RTTestFailed(hTest, "SUPR3Init failed with rc=%Rrc\n", rc);
+        return RTTestSummaryAndDestroy(hTest);
+    }
+
+    /*
+     * Basic API checks.
+     */
+    RTTestSub(hTest, "Single Release Event API");
+    SUPSEMEVENT hEvent = NIL_SUPSEMEVENT;
+    RTTESTI_CHECK_RC(SUPSemEventCreate(pSession, &hEvent),          VINF_SUCCESS);
+    RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent, 0),  VERR_TIMEOUT);
+    RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent,20),  VERR_TIMEOUT);
+    RTTESTI_CHECK_RC(SUPSemEventSignal(pSession, hEvent),           VINF_SUCCESS);
+    RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent, 0),  VINF_SUCCESS);
+    RTTESTI_CHECK_RC(SUPSemEventSignal(pSession, hEvent),           VINF_SUCCESS);
+    RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent,20),  VINF_SUCCESS);
+    RTTESTI_CHECK_RC(SUPSemEventSignal(pSession, hEvent),           VINF_SUCCESS);
+    RTTESTI_CHECK_RC(SUPSemEventSignal(pSession, hEvent),           VINF_SUCCESS);
+    RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent, 0),  VINF_SUCCESS);
+    RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent, 0),  VERR_TIMEOUT);
+    RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent,20),  VERR_TIMEOUT);
+    RTTESTI_CHECK_RC(SUPSemEventClose(pSession, hEvent),            VINF_OBJECT_DESTROYED);
+    RTTESTI_CHECK_RC(SUPSemEventClose(pSession, hEvent),            VERR_INVALID_HANDLE);
+    RTTESTI_CHECK_RC(SUPSemEventClose(pSession, NIL_SUPSEMEVENT),   VINF_SUCCESS);
+
+    RTTestSub(hTest, "Multiple Release Event API");
+    SUPSEMEVENTMULTI hEventMulti = NIL_SUPSEMEVENT;
+    RTTESTI_CHECK_RC(SUPSemEventMultiCreate(pSession, &hEventMulti),            VINF_SUCCESS);
+    RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 0),    VERR_TIMEOUT);
+    RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti,20),    VERR_TIMEOUT);
+    RTTESTI_CHECK_RC(SUPSemEventMultiSignal(pSession, hEventMulti),             VINF_SUCCESS);
+    RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 0),    VINF_SUCCESS);
+    RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 0),    VINF_SUCCESS);
+    RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 0),    VINF_SUCCESS);
+    RTTESTI_CHECK_RC(SUPSemEventMultiSignal(pSession, hEventMulti),             VINF_SUCCESS);
+    RTTESTI_CHECK_RC(SUPSemEventMultiSignal(pSession, hEventMulti),             VINF_SUCCESS);
+    RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 0),    VINF_SUCCESS);
+    RTTESTI_CHECK_RC(SUPSemEventMultiReset(pSession, hEventMulti),              VINF_SUCCESS);
+    RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 0),    VERR_TIMEOUT);
+    RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti,20),    VERR_TIMEOUT);
+    RTTESTI_CHECK_RC(SUPSemEventMultiSignal(pSession, hEventMulti),             VINF_SUCCESS);
+    RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 0),    VINF_SUCCESS);
+    RTTESTI_CHECK_RC(SUPSemEventMultiClose(pSession, hEventMulti),              VINF_OBJECT_DESTROYED);
+    RTTESTI_CHECK_RC(SUPSemEventMultiClose(pSession, hEventMulti),              VERR_INVALID_HANDLE);
+    RTTESTI_CHECK_RC(SUPSemEventMultiClose(pSession, NIL_SUPSEMEVENTMULTI),     VINF_SUCCESS);
+
+    /*
+     * Done.
+     */
+    return RTTestSummaryAndDestroy(hTest);
+}
+
Index: /trunk/src/VBox/Runtime/VBox/VBoxRTDeps.cpp
===================================================================
--- /trunk/src/VBox/Runtime/VBox/VBoxRTDeps.cpp	(revision 19891)
+++ /trunk/src/VBox/Runtime/VBox/VBoxRTDeps.cpp	(revision 19892)
@@ -54,4 +54,5 @@
     (PFNRT)SUPR3Init,
     (PFNRT)SUPPageLock,
+    (PFNRT)SUPSemEventCreate,
 #ifdef VBOX_WITH_LIBXML2_IN_VBOXRT
     (PFNRT)xmlModuleOpen,
