1 | /* $Id: VBoxGuestR3LibEvent.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, Events.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2007-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * The contents of this file may alternatively be used under the terms
|
---|
26 | * of the Common Development and Distribution License Version 1.0
|
---|
27 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
28 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
29 | * CDDL are applicable instead of those of the GPL.
|
---|
30 | *
|
---|
31 | * You may elect to license modified versions of this file under the
|
---|
32 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
33 | *
|
---|
34 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
35 | */
|
---|
36 |
|
---|
37 |
|
---|
38 | /*********************************************************************************************************************************
|
---|
39 | * Header Files *
|
---|
40 | *********************************************************************************************************************************/
|
---|
41 | #include <VBox/log.h>
|
---|
42 | #include <iprt/assert.h>
|
---|
43 | #include "VBoxGuestR3LibInternal.h"
|
---|
44 |
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * Wait for the host to signal one or more events and return which.
|
---|
48 | *
|
---|
49 | * The events will only be delivered by the host if they have been enabled
|
---|
50 | * previously using @a VbglR3CtlFilterMask. If one or several of the events
|
---|
51 | * have already been signalled but not yet waited for, this function will return
|
---|
52 | * immediately and return those events.
|
---|
53 | *
|
---|
54 | * @returns IPRT status code.
|
---|
55 | *
|
---|
56 | * @param fMask The events we want to wait for, or-ed together.
|
---|
57 | * @param cMillies How long to wait before giving up and returning
|
---|
58 | * (VERR_TIMEOUT). Use RT_INDEFINITE_WAIT to wait until we
|
---|
59 | * are interrupted or one of the events is signalled.
|
---|
60 | * @param pfEvents Where to store the events signalled. Optional.
|
---|
61 | */
|
---|
62 | VBGLR3DECL(int) VbglR3WaitEvent(uint32_t fMask, uint32_t cMillies, uint32_t *pfEvents)
|
---|
63 | {
|
---|
64 | LogFlow(("VbglR3WaitEvent: fMask=%#x, cMillies=%u, pfEvents=%p\n", fMask, cMillies, pfEvents));
|
---|
65 | AssertReturn((fMask & ~VMMDEV_EVENT_VALID_EVENT_MASK) == 0, VERR_INVALID_PARAMETER);
|
---|
66 | AssertPtrNullReturn(pfEvents, VERR_INVALID_POINTER);
|
---|
67 |
|
---|
68 | VBGLIOCWAITFOREVENTS WaitEvents;
|
---|
69 | VBGLREQHDR_INIT(&WaitEvents.Hdr, WAIT_FOR_EVENTS);
|
---|
70 | WaitEvents.u.In.fEvents = fMask;
|
---|
71 | WaitEvents.u.In.cMsTimeOut = cMillies;
|
---|
72 | int rc = vbglR3DoIOCtl(VBGL_IOCTL_WAIT_FOR_EVENTS, &WaitEvents.Hdr, sizeof(WaitEvents));
|
---|
73 | if (pfEvents)
|
---|
74 | {
|
---|
75 | if (RT_SUCCESS(rc))
|
---|
76 | *pfEvents = WaitEvents.u.Out.fEvents;
|
---|
77 | else
|
---|
78 | *pfEvents = 0;
|
---|
79 | }
|
---|
80 |
|
---|
81 | LogFlow(("VbglR3WaitEvent: rc=%Rrc fEvents=%#x\n", rc, WaitEvents.u.Out.fEvents));
|
---|
82 | return rc;
|
---|
83 | }
|
---|
84 |
|
---|
85 |
|
---|
86 | /**
|
---|
87 | * Causes any pending VbglR3WaitEvent calls (VBGL_IOCTL_WAIT_FOR_EVENTS) to
|
---|
88 | * return with a VERR_INTERRUPTED status.
|
---|
89 | *
|
---|
90 | * Can be used in combination with a termination flag variable for interrupting
|
---|
91 | * event loops. After calling this, VBGL_IOCTL_WAIT_FOR_EVENTS should no longer
|
---|
92 | * be called in the same session. At the time of writing this is not enforced;
|
---|
93 | * at the time of reading it may be.
|
---|
94 | *
|
---|
95 | * @returns IPRT status code.
|
---|
96 | */
|
---|
97 | VBGLR3DECL(int) VbglR3InterruptEventWaits(void)
|
---|
98 | {
|
---|
99 | VBGLREQHDR Req;
|
---|
100 | VBGLREQHDR_INIT(&Req, INTERRUPT_ALL_WAIT_FOR_EVENTS);
|
---|
101 | return vbglR3DoIOCtl(VBGL_IOCTL_INTERRUPT_ALL_WAIT_FOR_EVENTS, &Req, sizeof(Req));
|
---|
102 | }
|
---|
103 |
|
---|