VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/Support/SUPLibSem.cpp@ 34959

Last change on this file since 34959 was 33167, checked in by vboxsync, 14 years ago

SUPDrv,SUPLib: Expose the high resolution event semaphore APIs.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.7 KB
Line 
1/* $Id: SUPLibSem.cpp 33167 2010-10-15 18:16:59Z vboxsync $ */
2/** @file
3 * VirtualBox Support Library - Semaphores, ring-3 implementation.
4 */
5
6/*
7 * Copyright (C) 2009 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*******************************************************************************
29* Header Files *
30*******************************************************************************/
31#define LOG_GROUP LOG_GROUP_SUP
32#include <VBox/sup.h>
33
34#include <VBox/err.h>
35#include <VBox/param.h>
36#include <iprt/assert.h>
37
38#include "SUPLibInternal.h"
39#include "SUPDrvIOC.h"
40
41
42/**
43 * Worker that makes a SUP_IOCTL_SEM_OP2 request.
44 *
45 * @returns VBox status code.
46 * @param pSession The session handle.
47 * @param uType The semaphore type.
48 * @param hSem The semaphore handle.
49 * @param uOp The operation.
50 * @param u64Arg The argument if applicable, otherwise 0.
51 */
52DECLINLINE(int) supSemOp2(PSUPDRVSESSION pSession, uint32_t uType, uintptr_t hSem, uint32_t uOp, uint64_t u64Arg)
53{
54 SUPSEMOP2 Req;
55 Req.Hdr.u32Cookie = g_u32Cookie;
56 Req.Hdr.u32SessionCookie = g_u32SessionCookie;
57 Req.Hdr.cbIn = SUP_IOCTL_SEM_OP2_SIZE_IN;
58 Req.Hdr.cbOut = SUP_IOCTL_SEM_OP2_SIZE_OUT;
59 Req.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT;
60 Req.Hdr.rc = VERR_INTERNAL_ERROR;
61 Req.u.In.uType = uType;
62 Req.u.In.hSem = (uint32_t)hSem;
63 AssertReturn(Req.u.In.hSem == hSem, VERR_INVALID_HANDLE);
64 Req.u.In.uOp = uOp;
65 Req.u.In.uReserved = 0;
66 Req.u.In.uArg.u64 = u64Arg;
67 int rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_SEM_OP2, &Req, sizeof(Req));
68 if (RT_SUCCESS(rc))
69 rc = Req.Hdr.rc;
70
71 return rc;
72}
73
74
75/**
76 * Worker that makes a SUP_IOCTL_SEM_OP3 request.
77 *
78 * @returns VBox status code.
79 * @param pSession The session handle.
80 * @param uType The semaphore type.
81 * @param hSem The semaphore handle.
82 * @param uOp The operation.
83 * @param pReq The request structure. The caller should pick
84 * the output data from it himself.
85 */
86DECLINLINE(int) supSemOp3(PSUPDRVSESSION pSession, uint32_t uType, uintptr_t hSem, uint32_t uOp, PSUPSEMOP3 pReq)
87{
88 pReq->Hdr.u32Cookie = g_u32Cookie;
89 pReq->Hdr.u32SessionCookie = g_u32SessionCookie;
90 pReq->Hdr.cbIn = SUP_IOCTL_SEM_OP3_SIZE_IN;
91 pReq->Hdr.cbOut = SUP_IOCTL_SEM_OP3_SIZE_OUT;
92 pReq->Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT;
93 pReq->Hdr.rc = VERR_INTERNAL_ERROR;
94 pReq->u.In.uType = uType;
95 pReq->u.In.hSem = (uint32_t)hSem;
96 AssertReturn(pReq->u.In.hSem == hSem, VERR_INVALID_HANDLE);
97 pReq->u.In.uOp = uOp;
98 pReq->u.In.u32Reserved = 0;
99 pReq->u.In.u64Reserved = 0;
100 int rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_SEM_OP3, pReq, sizeof(*pReq));
101 if (RT_SUCCESS(rc))
102 rc = pReq->Hdr.rc;
103
104 return rc;
105}
106
107
108SUPDECL(int) SUPSemEventCreate(PSUPDRVSESSION pSession, PSUPSEMEVENT phEvent)
109{
110 AssertPtrReturn(phEvent, VERR_INVALID_POINTER);
111
112 SUPSEMOP3 Req;
113 int rc = supSemOp3(pSession, SUP_SEM_TYPE_EVENT, (uintptr_t)NIL_SUPSEMEVENT, SUPSEMOP3_CREATE, &Req);
114 if (RT_SUCCESS(rc))
115 *phEvent = (SUPSEMEVENT)(uintptr_t)Req.u.Out.hSem;
116 return rc;
117}
118
119
120SUPDECL(int) SUPSemEventClose(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent)
121{
122 if (hEvent == NIL_SUPSEMEVENT)
123 return VINF_SUCCESS;
124 return supSemOp2(pSession, SUP_SEM_TYPE_EVENT, (uintptr_t)hEvent, SUPSEMOP2_CLOSE, 0);
125}
126
127
128SUPDECL(int) SUPSemEventSignal(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent)
129{
130 return supSemOp2(pSession, SUP_SEM_TYPE_EVENT, (uintptr_t)hEvent, SUPSEMOP2_SIGNAL, 0);
131}
132
133
134SUPDECL(int) SUPSemEventWaitNoResume(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent, uint32_t cMillies)
135{
136 return supSemOp2(pSession, SUP_SEM_TYPE_EVENT, (uintptr_t)hEvent, SUPSEMOP2_WAIT_MS_REL, cMillies);
137}
138
139
140SUPDECL(int) SUPSemEventWaitNsAbsIntr(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent, uint64_t uNsTimeout)
141{
142 return supSemOp2(pSession, SUP_SEM_TYPE_EVENT, (uintptr_t)hEvent, SUPSEMOP2_WAIT_NS_ABS, uNsTimeout);
143}
144
145
146SUPDECL(int) SUPSemEventWaitNsRelIntr(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent, uint64_t cNsTimeout)
147{
148 return supSemOp2(pSession, SUP_SEM_TYPE_EVENT, (uintptr_t)hEvent, SUPSEMOP2_WAIT_NS_REL, cNsTimeout);
149}
150
151
152SUPDECL(uint32_t) SUPSemEventGetResolution(PSUPDRVSESSION pSession)
153{
154 SUPSEMOP3 Req;
155 int rc = supSemOp3(pSession, SUP_SEM_TYPE_EVENT, (uintptr_t)NIL_SUPSEMEVENT, SUPSEMOP3_GET_RESOLUTION, &Req);
156 if (RT_SUCCESS(rc))
157 return Req.u.Out.cNsResolution;
158 return 1000 / 100;
159}
160
161
162
163
164
165SUPDECL(int) SUPSemEventMultiCreate(PSUPDRVSESSION pSession, PSUPSEMEVENTMULTI phEventMulti)
166{
167 AssertPtrReturn(phEventMulti, VERR_INVALID_POINTER);
168
169 SUPSEMOP3 Req;
170 int rc = supSemOp3(pSession, SUP_SEM_TYPE_EVENT_MULTI, (uintptr_t)NIL_SUPSEMEVENTMULTI, SUPSEMOP3_CREATE, &Req);
171 if (RT_SUCCESS(rc))
172 *phEventMulti = (SUPSEMEVENTMULTI)(uintptr_t)Req.u.Out.hSem;
173 return rc;
174}
175
176
177SUPDECL(int) SUPSemEventMultiClose(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti)
178{
179 if (hEventMulti == NIL_SUPSEMEVENTMULTI)
180 return VINF_SUCCESS;
181 return supSemOp2(pSession, SUP_SEM_TYPE_EVENT_MULTI, (uintptr_t)hEventMulti, SUPSEMOP2_CLOSE, 0);
182}
183
184
185SUPDECL(int) SUPSemEventMultiSignal(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti)
186{
187 return supSemOp2(pSession, SUP_SEM_TYPE_EVENT_MULTI, (uintptr_t)hEventMulti, SUPSEMOP2_SIGNAL, 0);
188}
189
190
191SUPDECL(int) SUPSemEventMultiReset(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti)
192{
193 return supSemOp2(pSession, SUP_SEM_TYPE_EVENT_MULTI, (uintptr_t)hEventMulti, SUPSEMOP2_RESET, 0);
194}
195
196
197SUPDECL(int) SUPSemEventMultiWaitNoResume(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti, uint32_t cMillies)
198{
199 return supSemOp2(pSession, SUP_SEM_TYPE_EVENT_MULTI, (uintptr_t)hEventMulti, SUPSEMOP2_WAIT_MS_REL, cMillies);
200}
201
202
203SUPDECL(int) SUPSemEventMultiWaitNsAbsIntr(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti, uint64_t uNsTimeout)
204{
205 return supSemOp2(pSession, SUP_SEM_TYPE_EVENT_MULTI, (uintptr_t)hEventMulti, SUPSEMOP2_WAIT_NS_ABS, uNsTimeout);
206}
207
208
209SUPDECL(int) SUPSemEventMultiWaitNsRelIntr(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti, uint64_t cNsTimeout)
210{
211 return supSemOp2(pSession, SUP_SEM_TYPE_EVENT_MULTI, (uintptr_t)hEventMulti, SUPSEMOP2_WAIT_NS_REL, cNsTimeout);
212}
213
214
215SUPDECL(uint32_t) SUPSemEventMultiGetResolution(PSUPDRVSESSION pSession)
216{
217 SUPSEMOP3 Req;
218 int rc = supSemOp3(pSession, SUP_SEM_TYPE_EVENT_MULTI, (uintptr_t)NIL_SUPSEMEVENTMULTI, SUPSEMOP3_GET_RESOLUTION, &Req);
219 if (RT_SUCCESS(rc))
220 return Req.u.Out.cNsResolution;
221 return 1000 / 100;
222}
223
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette