1 | /* $Id: VBoxGuestInternal.h 53077 2014-10-16 12:36:28Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxGuest - Guest Additions Driver.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2010-2014 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 | #ifndef ___VBoxGuestInternal_h
|
---|
28 | #define ___VBoxGuestInternal_h
|
---|
29 |
|
---|
30 | #include <iprt/types.h>
|
---|
31 | #include <iprt/list.h>
|
---|
32 | #include <iprt/semaphore.h>
|
---|
33 | #include <iprt/spinlock.h>
|
---|
34 | #include <iprt/timer.h>
|
---|
35 | #include <VBox/VMMDev.h>
|
---|
36 | #include <VBox/VBoxGuest.h>
|
---|
37 | #include <VBox/VBoxGuestLib.h>
|
---|
38 |
|
---|
39 | /** @def VBOXGUEST_USE_WAKE_UP_LIST
|
---|
40 | * Defer wake-up of waiting thread when defined. */
|
---|
41 | #if defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_WINDOWS) || defined(DOXYGEN_RUNNING)
|
---|
42 | # define VBOXGUEST_USE_DEFERRED_WAKE_UP
|
---|
43 | #endif
|
---|
44 |
|
---|
45 |
|
---|
46 | /** Pointer to the VBoxGuest per session data. */
|
---|
47 | typedef struct VBOXGUESTSESSION *PVBOXGUESTSESSION;
|
---|
48 |
|
---|
49 | /** Pointer to a wait-for-event entry. */
|
---|
50 | typedef struct VBOXGUESTWAIT *PVBOXGUESTWAIT;
|
---|
51 |
|
---|
52 | /**
|
---|
53 | * VBox guest wait for event entry.
|
---|
54 | *
|
---|
55 | * Each waiting thread allocates one of these items and adds
|
---|
56 | * it to the wait list before going to sleep on the event sem.
|
---|
57 | */
|
---|
58 | typedef struct VBOXGUESTWAIT
|
---|
59 | {
|
---|
60 | /** The list node. */
|
---|
61 | RTLISTNODE ListNode;
|
---|
62 | /** The events we are waiting on. */
|
---|
63 | uint32_t fReqEvents;
|
---|
64 | /** The events we received. */
|
---|
65 | uint32_t volatile fResEvents;
|
---|
66 | #ifdef VBOXGUEST_USE_DEFERRED_WAKE_UP
|
---|
67 | /** Set by VBoxGuestWaitDoWakeUps before leaving the spinlock to call
|
---|
68 | * RTSemEventMultiSignal. */
|
---|
69 | bool volatile fPendingWakeUp;
|
---|
70 | /** Set by the requestor thread if it got the spinlock before the
|
---|
71 | * signaller. Deals with the race in VBoxGuestWaitDoWakeUps. */
|
---|
72 | bool volatile fFreeMe;
|
---|
73 | #endif
|
---|
74 | /** The event semaphore. */
|
---|
75 | RTSEMEVENTMULTI Event;
|
---|
76 | /** The session that's waiting. */
|
---|
77 | PVBOXGUESTSESSION pSession;
|
---|
78 | #ifdef VBOX_WITH_HGCM
|
---|
79 | /** The HGCM request we're waiting for to complete. */
|
---|
80 | VMMDevHGCMRequestHeader volatile *pHGCMReq;
|
---|
81 | #endif
|
---|
82 | } VBOXGUESTWAIT;
|
---|
83 |
|
---|
84 |
|
---|
85 | /**
|
---|
86 | * VBox guest memory balloon.
|
---|
87 | */
|
---|
88 | typedef struct VBOXGUESTMEMBALLOON
|
---|
89 | {
|
---|
90 | /** Mutex protecting the members below from concurrent access.. */
|
---|
91 | RTSEMFASTMUTEX hMtx;
|
---|
92 | /** The current number of chunks in the balloon. */
|
---|
93 | uint32_t cChunks;
|
---|
94 | /** The maximum number of chunks in the balloon (typically the amount of guest
|
---|
95 | * memory / chunksize). */
|
---|
96 | uint32_t cMaxChunks;
|
---|
97 | /** This is true if we are using RTR0MemObjAllocPhysNC() / RTR0MemObjGetPagePhysAddr()
|
---|
98 | * and false otherwise. */
|
---|
99 | bool fUseKernelAPI;
|
---|
100 | /** The current owner of the balloon.
|
---|
101 | * This is automatically assigned to the first session using the ballooning
|
---|
102 | * API and first released when the session closes. */
|
---|
103 | PVBOXGUESTSESSION pOwner;
|
---|
104 | /** The pointer to the array of memory objects holding the chunks of the
|
---|
105 | * balloon. This array is cMaxChunks in size when present. */
|
---|
106 | PRTR0MEMOBJ paMemObj;
|
---|
107 | } VBOXGUESTMEMBALLOON;
|
---|
108 | /** Pointer to a memory balloon. */
|
---|
109 | typedef VBOXGUESTMEMBALLOON *PVBOXGUESTMEMBALLOON;
|
---|
110 |
|
---|
111 | /**
|
---|
112 | * VBox guest device (data) extension.
|
---|
113 | */
|
---|
114 | typedef struct VBOXGUESTDEVEXT
|
---|
115 | {
|
---|
116 | /** The base of the adapter I/O ports. */
|
---|
117 | RTIOPORT IOPortBase;
|
---|
118 | /** Pointer to the mapping of the VMMDev adapter memory. */
|
---|
119 | VMMDevMemory volatile *pVMMDevMemory;
|
---|
120 | /** Events we won't permit anyone to filter out. */
|
---|
121 | uint32_t fFixedEvents;
|
---|
122 | /** The memory object reserving space for the guest mappings. */
|
---|
123 | RTR0MEMOBJ hGuestMappings;
|
---|
124 | /** Spinlock protecting the signaling and resetting of the wait-for-event
|
---|
125 | * semaphores as well as the event acking in the ISR. */
|
---|
126 | RTSPINLOCK EventSpinlock;
|
---|
127 | /** Preallocated VMMDevEvents for the IRQ handler. */
|
---|
128 | VMMDevEvents *pIrqAckEvents;
|
---|
129 | /** The physical address of pIrqAckEvents. */
|
---|
130 | RTCCPHYS PhysIrqAckEvents;
|
---|
131 | /** Wait-for-event list for threads waiting for multiple events
|
---|
132 | * (VBOXGUESTWAIT). */
|
---|
133 | RTLISTANCHOR WaitList;
|
---|
134 | #ifdef VBOX_WITH_HGCM
|
---|
135 | /** Wait-for-event list for threads waiting on HGCM async completion
|
---|
136 | * (VBOXGUESTWAIT).
|
---|
137 | *
|
---|
138 | * The entire list is evaluated upon the arrival of an HGCM event, unlike
|
---|
139 | * the other lists which are only evaluated till the first thread has
|
---|
140 | * been woken up. */
|
---|
141 | RTLISTANCHOR HGCMWaitList;
|
---|
142 | #endif
|
---|
143 | #ifdef VBOXGUEST_USE_DEFERRED_WAKE_UP
|
---|
144 | /** List of wait-for-event entries that needs waking up
|
---|
145 | * (VBOXGUESTWAIT). */
|
---|
146 | RTLISTANCHOR WakeUpList;
|
---|
147 | #endif
|
---|
148 | /** List of wait-for-event entries that has been woken up
|
---|
149 | * (VBOXGUESTWAIT). */
|
---|
150 | RTLISTANCHOR WokenUpList;
|
---|
151 | /** List of free wait-for-event entries (VBOXGUESTWAIT). */
|
---|
152 | RTLISTANCHOR FreeList;
|
---|
153 | /** Mask of pending events. */
|
---|
154 | uint32_t volatile f32PendingEvents;
|
---|
155 | /** Current VMMDEV_EVENT_MOUSE_POSITION_CHANGED sequence number.
|
---|
156 | * Used to implement polling. */
|
---|
157 | uint32_t volatile u32MousePosChangedSeq;
|
---|
158 |
|
---|
159 | /** Spinlock various items in the VBOXGUESTSESSION. */
|
---|
160 | RTSPINLOCK SessionSpinlock;
|
---|
161 | /** List of guest sessions (VBOXGUESTSESSION). We currently traverse this
|
---|
162 | * but do not search it, so a list data type should be fine. Use under the
|
---|
163 | * #SessionSpinlock lock. */
|
---|
164 | RTLISTANCHOR SessionList;
|
---|
165 | /** Flag indicating whether logging to the release log
|
---|
166 | * is enabled. */
|
---|
167 | bool fLoggingEnabled;
|
---|
168 | /** Memory balloon information for RTR0MemObjAllocPhysNC(). */
|
---|
169 | VBOXGUESTMEMBALLOON MemBalloon;
|
---|
170 | /** Callback and user data for a kernel mouse handler. */
|
---|
171 | VBoxGuestMouseSetNotifyCallback MouseNotifyCallback;
|
---|
172 | /** Guest capabilities which have been set to "acquire" mode. This means
|
---|
173 | * that only one session can use them at a time, and that they will be
|
---|
174 | * automatically cleaned up if that session exits without doing so. */
|
---|
175 | uint32_t u32AcquireModeGuestCaps;
|
---|
176 | /** Guest capabilities which have been set to "set" mode. This just means
|
---|
177 | * that they have been blocked from ever being set to "acquire" mode. */
|
---|
178 | uint32_t u32SetModeGuestCaps;
|
---|
179 | /** Mask of all capabilities which are currently acquired by some session
|
---|
180 | * and as such reported to the host. */
|
---|
181 | uint32_t u32GuestCaps;
|
---|
182 | /** Heartbeat timer which fires with interval
|
---|
183 | * cNsHearbeatInterval and its handler sends
|
---|
184 | * VMMDevReq_GuestHeartbeat to VMMDev. */
|
---|
185 | PRTTIMER pHeartbeatTimer;
|
---|
186 | /** Heartbeat timer interval in nanoseconds. */
|
---|
187 | uint64_t cNsHeartbeatInterval;
|
---|
188 | /** Preallocated VMMDevReq_GuestHeartbeat request. */
|
---|
189 | VMMDevRequestHeader *pReqGuestHeartbeat;
|
---|
190 | } VBOXGUESTDEVEXT;
|
---|
191 | /** Pointer to the VBoxGuest driver data. */
|
---|
192 | typedef VBOXGUESTDEVEXT *PVBOXGUESTDEVEXT;
|
---|
193 |
|
---|
194 |
|
---|
195 | /**
|
---|
196 | * The VBoxGuest per session data.
|
---|
197 | *
|
---|
198 | * @remark Not quite sure whether this will be useful or not, but since
|
---|
199 | * its already there let's keep it for now in case it might come
|
---|
200 | * in handy later.
|
---|
201 | */
|
---|
202 | typedef struct VBOXGUESTSESSION
|
---|
203 | {
|
---|
204 | /** The list node. */
|
---|
205 | RTLISTNODE ListNode;
|
---|
206 | #if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_OS2) || defined(RT_OS_SOLARIS)
|
---|
207 | /** Pointer to the next session with the same hash. */
|
---|
208 | PVBOXGUESTSESSION pNextHash;
|
---|
209 | #endif
|
---|
210 | #if defined(RT_OS_OS2)
|
---|
211 | /** The system file number of this session. */
|
---|
212 | uint16_t sfn;
|
---|
213 | uint16_t Alignment; /**< Alignment */
|
---|
214 | #endif
|
---|
215 | /** The process (id) of the session.
|
---|
216 | * This is NIL if it's a kernel session. */
|
---|
217 | RTPROCESS Process;
|
---|
218 | /** Which process this session is associated with.
|
---|
219 | * This is NIL if it's a kernel session. */
|
---|
220 | RTR0PROCESS R0Process;
|
---|
221 | /** Pointer to the device extension. */
|
---|
222 | PVBOXGUESTDEVEXT pDevExt;
|
---|
223 |
|
---|
224 | #ifdef VBOX_WITH_HGCM
|
---|
225 | /** Array containing HGCM client IDs associated with this session.
|
---|
226 | * This will be automatically disconnected when the session is closed. */
|
---|
227 | uint32_t volatile aHGCMClientIds[64];
|
---|
228 | #endif
|
---|
229 | /** The last consumed VMMDEV_EVENT_MOUSE_POSITION_CHANGED sequence number.
|
---|
230 | * Used to implement polling. */
|
---|
231 | uint32_t volatile u32MousePosChangedSeq;
|
---|
232 | /** VMMDev events requested. An event type requested in any guest session
|
---|
233 | * will be added to the host filter.
|
---|
234 | * Use under the VBOXGUESTDEVEXT#SessionSpinlock lock. */
|
---|
235 | uint32_t fFilterMask;
|
---|
236 | /** Capabilities supported. A capability enabled in any guest session will
|
---|
237 | * be enabled for the host.
|
---|
238 | * Use under the VBOXGUESTDEVEXT#SessionSpinlock lock. */
|
---|
239 | uint32_t fCapabilities;
|
---|
240 | /** Mouse features supported. A feature enabled in any guest session will
|
---|
241 | * be enabled for the host.
|
---|
242 | * @note We invert the VMMDEV_MOUSE_GUEST_NEEDS_HOST_CURSOR feature in this
|
---|
243 | * bitmap. The logic of this is that the real feature is when the host
|
---|
244 | * cursor is not needed, and we tell the host it is not needed if any
|
---|
245 | * session explicitly fails to assert it. Storing it inverted simplifies
|
---|
246 | * the checks.
|
---|
247 | * Use under the VBOXGUESTDEVEXT#SessionSpinlock lock. */
|
---|
248 | uint32_t fMouseStatus;
|
---|
249 | #ifdef RT_OS_DARWIN
|
---|
250 | /** Pointer to the associated org_virtualbox_VBoxGuestClient object. */
|
---|
251 | void *pvVBoxGuestClient;
|
---|
252 | /** Whether this session has been opened or not. */
|
---|
253 | bool fOpened;
|
---|
254 | #endif
|
---|
255 | /** Mask of guest capabilities acquired by this session. These will all be
|
---|
256 | * reported to the host. */
|
---|
257 | uint32_t u32AquiredGuestCaps;
|
---|
258 | /** Whether a CANCEL_ALL_WAITEVENTS is pending. This happens when
|
---|
259 | * CANCEL_ALL_WAITEVENTS is called, but no call to WAITEVENT is in process
|
---|
260 | * in the current session. In that case the next call will be interrupted
|
---|
261 | * at once. */
|
---|
262 | bool volatile fPendingCancelWaitEvents;
|
---|
263 | /** Does this session belong to a root process or a user one? */
|
---|
264 | bool fUserSession;
|
---|
265 | } VBOXGUESTSESSION;
|
---|
266 |
|
---|
267 | RT_C_DECLS_BEGIN
|
---|
268 |
|
---|
269 | int VBoxGuestInitDevExt(PVBOXGUESTDEVEXT pDevExt, uint16_t IOPortBase, void *pvMMIOBase, uint32_t cbMMIO, VBOXOSTYPE enmOSType, uint32_t fEvents);
|
---|
270 | bool VBoxGuestCommonISR(PVBOXGUESTDEVEXT pDevExt);
|
---|
271 | void VBoxGuestDeleteDevExt(PVBOXGUESTDEVEXT pDevExt);
|
---|
272 | int VBoxGuestReinitDevExtAfterHibernation(PVBOXGUESTDEVEXT pDevExt, VBOXOSTYPE enmOSType);
|
---|
273 | int VBoxGuestSetGuestCapabilities(uint32_t fOr, uint32_t fNot);
|
---|
274 | #ifdef VBOXGUEST_USE_DEFERRED_WAKE_UP
|
---|
275 | void VBoxGuestWaitDoWakeUps(PVBOXGUESTDEVEXT pDevExt);
|
---|
276 | #endif
|
---|
277 |
|
---|
278 | int VBoxGuestCreateUserSession(PVBOXGUESTDEVEXT pDevExt, PVBOXGUESTSESSION *ppSession);
|
---|
279 | int VBoxGuestCreateKernelSession(PVBOXGUESTDEVEXT pDevExt, PVBOXGUESTSESSION *ppSession);
|
---|
280 | void VBoxGuestCloseSession(PVBOXGUESTDEVEXT pDevExt, PVBOXGUESTSESSION pSession);
|
---|
281 |
|
---|
282 | int VBoxGuestCommonIOCtlFast(unsigned iFunction, PVBOXGUESTDEVEXT pDevExt, PVBOXGUESTSESSION pSession);
|
---|
283 | int VBoxGuestCommonIOCtl(unsigned iFunction, PVBOXGUESTDEVEXT pDevExt, PVBOXGUESTSESSION pSession,
|
---|
284 | void *pvData, size_t cbData, size_t *pcbDataReturned);
|
---|
285 |
|
---|
286 | #if defined(RT_OS_SOLARIS) \
|
---|
287 | || defined(RT_OS_FREEBSD) \
|
---|
288 | || defined(RT_OS_LINUX)
|
---|
289 | DECLVBGL(void *) VBoxGuestNativeServiceOpen(uint32_t *pu32Version);
|
---|
290 | DECLVBGL(void) VBoxGuestNativeServiceClose(void *pvOpaque);
|
---|
291 | DECLVBGL(int) VBoxGuestNativeServiceCall(void *pvOpaque, unsigned int iCmd, void *pvData, size_t cbSize, size_t *pcbReturn);
|
---|
292 | #endif
|
---|
293 |
|
---|
294 | /**
|
---|
295 | * ISR callback for notifying threads polling for mouse events.
|
---|
296 | *
|
---|
297 | * This is called at the end of the ISR, after leaving the event spinlock, if
|
---|
298 | * VMMDEV_EVENT_MOUSE_POSITION_CHANGED was raised by the host.
|
---|
299 | *
|
---|
300 | * @param pDevExt The device extension.
|
---|
301 | */
|
---|
302 | void VBoxGuestNativeISRMousePollEvent(PVBOXGUESTDEVEXT pDevExt);
|
---|
303 |
|
---|
304 |
|
---|
305 | #ifdef VBOX_WITH_DPC_LATENCY_CHECKER
|
---|
306 | int VbgdNtIOCtl_DpcLatencyChecker(void);
|
---|
307 | #endif
|
---|
308 |
|
---|
309 | RT_C_DECLS_END
|
---|
310 |
|
---|
311 | #endif
|
---|
312 |
|
---|