VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibMisc.cpp@ 22730

Last change on this file since 22730 was 21978, checked in by vboxsync, 15 years ago

VbglR3: u32Timeout -> cMillies and other nitpicking.

  • Property svn:eol-style set to native
  • Property svn:keyword set to Id
  • Property svn:keywords set to Id
File size: 6.1 KB
Line 
1/* $Id: VBoxGuestR3LibMisc.cpp 21978 2009-08-05 11:07:39Z vboxsync $ */
2/** @file
3 * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, Misc.
4 */
5
6/*
7 * Copyright (C) 2007 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22
23/*******************************************************************************
24* Header Files *
25*******************************************************************************/
26#include <iprt/mem.h>
27#include <VBox/log.h>
28
29#include "VBGLR3Internal.h"
30
31
32/**
33 * Wait for the host to signal one or more events and return which.
34 *
35 * The events will only be delivered by the host if they have been enabled
36 * previously using @a VbglR3CtlFilterMask. If one or several of the events
37 * have already been signalled but not yet waited for, this function will return
38 * immediately and return those events.
39 *
40 * @returns IPRT status code
41 *
42 * @param fMask The events we want to wait for, or-ed together.
43 * @param cMillies How long to wait before giving up and returning
44 * (VERR_TIMEOUT). Use RT_INDEFINITE_WAIT to wait until we
45 * are interrupted or one of the events is signalled.
46 * @param pfEvents Where to store the events signalled. Optional.
47 */
48VBGLR3DECL(int) VbglR3WaitEvent(uint32_t fMask, uint32_t cMillies, uint32_t *pfEvents)
49{
50 LogFlow(("VbglR3WaitEvent: fMask=0x%x, cMillies=%u, pfEvents=%p\n",
51 fMask, cMillies, pfEvents));
52 AssertReturn((fMask & ~VMMDEV_EVENT_VALID_EVENT_MASK) == 0, VERR_INVALID_PARAMETER);
53 AssertPtrNullReturn(pfEvents, VERR_INVALID_POINTER);
54
55 VBoxGuestWaitEventInfo waitEvent;
56 waitEvent.u32TimeoutIn = cMillies;
57 waitEvent.u32EventMaskIn = fMask;
58 waitEvent.u32Result = VBOXGUEST_WAITEVENT_ERROR;
59 waitEvent.u32EventFlagsOut = 0;
60 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_WAITEVENT, &waitEvent, sizeof(waitEvent));
61 if (RT_SUCCESS(rc))
62 {
63 AssertMsg(waitEvent.u32Result == VBOXGUEST_WAITEVENT_OK, ("%d\n", waitEvent.u32Result));
64 if (pfEvents)
65 *pfEvents = waitEvent.u32EventFlagsOut;
66 }
67
68 LogFlow(("VbglR3WaitEvent: rc=%Rrc, u32EventFlagsOut=0x%x. u32Result=%d\n",
69 rc, waitEvent.u32EventFlagsOut, waitEvent.u32Result));
70 return rc;
71}
72
73
74/**
75 * Cause any pending WaitEvent calls (VBOXGUEST_IOCTL_WAITEVENT) to return
76 * with a VERR_INTERRUPTED status.
77 *
78 * Can be used in combination with a termination flag variable for interrupting
79 * event loops. Avoiding race conditions is the responsibility of the caller.
80 *
81 * @returns IPRT status code
82 */
83VBGLR3DECL(int) VbglR3InterruptEventWaits(void)
84{
85 return vbglR3DoIOCtl(VBOXGUEST_IOCTL_CANCEL_ALL_WAITEVENTS, 0, 0);
86}
87
88
89/**
90 * Write to the backdoor logger from ring 3 guest code.
91 *
92 * @returns IPRT status code
93 *
94 * @remarks This currently does not accept more than 255 bytes of data at
95 * one time. It should probably be rewritten to use pass a pointer
96 * in the IOCtl.
97 */
98VBGLR3DECL(int) VbglR3WriteLog(const char *pch, size_t cb)
99{
100 /*
101 * Quietly skip NULL strings.
102 * (Happens in the RTLogBackdoorPrintf case.)
103 */
104 if (!cb)
105 return VINF_SUCCESS;
106 if (!VALID_PTR(pch))
107 return VERR_INVALID_POINTER;
108
109#ifdef RT_OS_WINDOWS
110 /*
111 * Duplicate the string as it may be read only (a C string).
112 */
113 void *pvTmp = RTMemDup(pch, cb);
114 if (!pvTmp)
115 return VERR_NO_MEMORY;
116 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_LOG(cb), pvTmp, cb);
117 RTMemFree(pvTmp);
118 return rc;
119
120#elif 0 /** @todo Several OSes could take this route (solaris and freebsd for instance). */
121 /*
122 * Handle the entire request in one go.
123 */
124 return vbglR3DoIOCtl(VBOXGUEST_IOCTL_LOG(cb), pvTmp, cb);
125
126#else
127 /*
128 * *BSD does not accept more than 4KB per ioctl request, while
129 * Linux can't express sizes above 8KB, so, split it up into 2KB chunks.
130 */
131# define STEP 2048
132 int rc = VINF_SUCCESS;
133 for (size_t off = 0; off < cb && RT_SUCCESS(rc); off += STEP)
134 {
135 size_t cbStep = RT_MIN(cb - off, STEP);
136 rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_LOG(cbStep), (char *)pch + off, cbStep);
137 }
138# undef STEP
139 return rc;
140#endif
141}
142
143
144/**
145 * Change the IRQ filter mask.
146 *
147 * @returns IPRT status code
148 * @param fOr The OR mask.
149 * @param fNo The NOT mask.
150 */
151VBGLR3DECL(int) VbglR3CtlFilterMask(uint32_t fOr, uint32_t fNot)
152{
153#if defined(RT_OS_WINDOWS)
154 /** @todo Not yet implemented. */
155 return VERR_NOT_SUPPORTED;
156
157#else
158
159 VBoxGuestFilterMaskInfo Info;
160 Info.u32OrMask = fOr;
161 Info.u32NotMask = fNot;
162 return vbglR3DoIOCtl(VBOXGUEST_IOCTL_CTL_FILTER_MASK, &Info, sizeof(Info));
163#endif
164}
165
166
167/**
168 * Report a change in the capabilities that we support to the host.
169 *
170 * @returns IPRT status value
171 * @param fOr Capabilities which have been added.
172 * @param fNot Capabilities which have been removed.
173 *
174 * @todo Move to a different file.
175 */
176VBGLR3DECL(int) VbglR3SetGuestCaps(uint32_t fOr, uint32_t fNot)
177{
178 VMMDevReqGuestCapabilities2 vmmreqGuestCaps;
179 int rc;
180
181 vmmdevInitRequest(&vmmreqGuestCaps.header, VMMDevReq_SetGuestCapabilities);
182 vmmreqGuestCaps.u32OrMask = fOr;
183 vmmreqGuestCaps.u32NotMask = fNot;
184 rc = vbglR3GRPerform(&vmmreqGuestCaps.header);
185#ifdef DEBUG
186 if (RT_SUCCESS(rc))
187 LogRel(("Successfully changed guest capabilities: or mask 0x%x, not mask 0x%x.\n",
188 fOr, fNot));
189 else
190 LogRel(("Failed to change guest capabilities: or mask 0x%x, not mask 0x%x. rc = %Rrc.\n",
191 fOr, fNot, rc));
192#endif
193 return rc;
194}
195
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