VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuestInternal.h@ 76409

Last change on this file since 76409 was 75705, checked in by vboxsync, 6 years ago

VBoxGuest/darwin: Implemented straight forward interrupt handling. Enabled test signing. Adjustments. bugref:4686

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 16.5 KB
Line 
1/* $Id: VBoxGuestInternal.h 75705 2018-11-25 01:44:41Z vboxsync $ */
2/** @file
3 * VBoxGuest - Guest Additions Driver, Internal Header.
4 */
5
6/*
7 * Copyright (C) 2010-2017 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_DEFERRED_WAKE_UP
40 * Defer wake-up of waiting thread when defined. */
41#if defined(RT_OS_SOLARIS) || defined(RT_OS_WINDOWS) || defined(DOXYGEN_RUNNING)
42# define VBOXGUEST_USE_DEFERRED_WAKE_UP
43#endif
44
45/** @def VBOXGUEST_MOUSE_NOTIFY_CAN_PREEMPT
46 * The mouse notification callback can cause preemption and must not be invoked
47 * while holding a high-level spinlock.
48 */
49#if defined(RT_OS_SOLARIS) || defined(RT_OS_WINDOWS) || defined(DOXYGEN_RUNNING)
50# define VBOXGUEST_MOUSE_NOTIFY_CAN_PREEMPT
51#endif
52
53/** Pointer to the VBoxGuest per session data. */
54typedef struct VBOXGUESTSESSION *PVBOXGUESTSESSION;
55
56/** Pointer to a wait-for-event entry. */
57typedef struct VBOXGUESTWAIT *PVBOXGUESTWAIT;
58
59/**
60 * VBox guest wait for event entry.
61 *
62 * Each waiting thread allocates one of these items and adds
63 * it to the wait list before going to sleep on the event sem.
64 */
65typedef struct VBOXGUESTWAIT
66{
67 /** The list node. */
68 RTLISTNODE ListNode;
69 /** The events we are waiting on. */
70 uint32_t fReqEvents;
71 /** The events we received. */
72 uint32_t volatile fResEvents;
73#ifdef VBOXGUEST_USE_DEFERRED_WAKE_UP
74 /** Set by VGDrvCommonWaitDoWakeUps before leaving the spinlock to call
75 * RTSemEventMultiSignal. */
76 bool volatile fPendingWakeUp;
77 /** Set by the requestor thread if it got the spinlock before the
78 * signaller. Deals with the race in VGDrvCommonWaitDoWakeUps. */
79 bool volatile fFreeMe;
80#endif
81 /** The event semaphore. */
82 RTSEMEVENTMULTI Event;
83 /** The session that's waiting. */
84 PVBOXGUESTSESSION pSession;
85#ifdef VBOX_WITH_HGCM
86 /** The HGCM request we're waiting for to complete. */
87 VMMDevHGCMRequestHeader volatile *pHGCMReq;
88#endif
89} VBOXGUESTWAIT;
90
91
92/**
93 * VBox guest memory balloon.
94 */
95typedef struct VBOXGUESTMEMBALLOON
96{
97 /** Mutex protecting the members below from concurrent access. */
98 RTSEMFASTMUTEX hMtx;
99 /** The current number of chunks in the balloon. */
100 uint32_t cChunks;
101 /** The maximum number of chunks in the balloon (typically the amount of guest
102 * memory / chunksize). */
103 uint32_t cMaxChunks;
104 /** This is true if we are using RTR0MemObjAllocPhysNC() / RTR0MemObjGetPagePhysAddr()
105 * and false otherwise. */
106 bool fUseKernelAPI;
107 /** The current owner of the balloon.
108 * This is automatically assigned to the first session using the ballooning
109 * API and first released when the session closes. */
110 PVBOXGUESTSESSION pOwner;
111 /** The pointer to the array of memory objects holding the chunks of the
112 * balloon. This array is cMaxChunks in size when present. */
113 PRTR0MEMOBJ paMemObj;
114} VBOXGUESTMEMBALLOON;
115/** Pointer to a memory balloon. */
116typedef VBOXGUESTMEMBALLOON *PVBOXGUESTMEMBALLOON;
117
118
119/**
120 * Per bit usage tracker for a uint32_t mask.
121 *
122 * Used for optimal handling of guest properties, mouse status and event filter.
123 */
124typedef struct VBOXGUESTBITUSAGETRACER
125{
126 /** Per bit usage counters. */
127 uint32_t acPerBitUsage[32];
128 /** The current mask according to acPerBitUsage. */
129 uint32_t fMask;
130} VBOXGUESTBITUSAGETRACER;
131/** Pointer to a per bit usage tracker. */
132typedef VBOXGUESTBITUSAGETRACER *PVBOXGUESTBITUSAGETRACER;
133/** Pointer to a const per bit usage tracker. */
134typedef VBOXGUESTBITUSAGETRACER const *PCVBOXGUESTBITUSAGETRACER;
135
136
137/**
138 * VBox guest device (data) extension.
139 */
140typedef struct VBOXGUESTDEVEXT
141{
142 /** VBOXGUESTDEVEXT_INIT_STATE_XXX. */
143 uint32_t uInitState;
144 /** The base of the adapter I/O ports. */
145 RTIOPORT IOPortBase;
146 /** Pointer to the mapping of the VMMDev adapter memory. */
147 VMMDevMemory volatile *pVMMDevMemory;
148 /** The memory object reserving space for the guest mappings. */
149 RTR0MEMOBJ hGuestMappings;
150 /** Spinlock protecting the signaling and resetting of the wait-for-event
151 * semaphores as well as the event acking in the ISR. */
152 RTSPINLOCK EventSpinlock;
153 /** Host feature flags (VMMDEV_HVF_XXX). */
154 uint32_t fHostFeatures;
155 /** Preallocated VMMDevEvents for the IRQ handler. */
156 VMMDevEvents *pIrqAckEvents;
157 /** The physical address of pIrqAckEvents. */
158 RTCCPHYS PhysIrqAckEvents;
159 /** Wait-for-event list for threads waiting for multiple events
160 * (VBOXGUESTWAIT). */
161 RTLISTANCHOR WaitList;
162#ifdef VBOX_WITH_HGCM
163 /** Wait-for-event list for threads waiting on HGCM async completion
164 * (VBOXGUESTWAIT).
165 *
166 * The entire list is evaluated upon the arrival of an HGCM event, unlike
167 * the other lists which are only evaluated till the first thread has
168 * been woken up. */
169 RTLISTANCHOR HGCMWaitList;
170#endif
171#ifdef VBOXGUEST_USE_DEFERRED_WAKE_UP
172 /** List of wait-for-event entries that needs waking up
173 * (VBOXGUESTWAIT). */
174 RTLISTANCHOR WakeUpList;
175#endif
176 /** List of wait-for-event entries that has been woken up
177 * (VBOXGUESTWAIT). */
178 RTLISTANCHOR WokenUpList;
179 /** List of free wait-for-event entries (VBOXGUESTWAIT). */
180 RTLISTANCHOR FreeList;
181 /** Mask of pending events. */
182 uint32_t volatile f32PendingEvents;
183 /** Current VMMDEV_EVENT_MOUSE_POSITION_CHANGED sequence number.
184 * Used to implement polling. */
185 uint32_t volatile u32MousePosChangedSeq;
186
187 /** Spinlock various items in the VBOXGUESTSESSION. */
188 RTSPINLOCK SessionSpinlock;
189 /** List of guest sessions (VBOXGUESTSESSION). We currently traverse this
190 * but do not search it, so a list data type should be fine. Use under the
191 * #SessionSpinlock lock. */
192 RTLISTANCHOR SessionList;
193 /** Number of session. */
194 uint32_t cSessions;
195 /** Flag indicating whether logging to the release log
196 * is enabled. */
197 bool fLoggingEnabled;
198 /** Memory balloon information for RTR0MemObjAllocPhysNC(). */
199 VBOXGUESTMEMBALLOON MemBalloon;
200 /** Mouse notification callback function. */
201 PFNVBOXGUESTMOUSENOTIFY pfnMouseNotifyCallback;
202 /** The callback argument for the mouse ntofication callback. */
203 void *pvMouseNotifyCallbackArg;
204
205 /** @name Host Event Filtering
206 * @{ */
207 /** Events we won't permit anyone to filter out. */
208 uint32_t fFixedEvents;
209 /** Usage counters for the host events. (Fixed events are not included.) */
210 VBOXGUESTBITUSAGETRACER EventFilterTracker;
211 /** The event filter last reported to the host (UINT32_MAX on failure). */
212 uint32_t fEventFilterHost;
213 /** @} */
214
215 /** @name Mouse Status
216 * @{ */
217 /** Usage counters for the mouse statuses (VMMDEV_MOUSE_XXX). */
218 VBOXGUESTBITUSAGETRACER MouseStatusTracker;
219 /** The mouse status last reported to the host (UINT32_MAX on failure). */
220 uint32_t fMouseStatusHost;
221 /** @} */
222
223 /** @name Guest Capabilities
224 * @{ */
225 /** Guest capabilities which have been set to "acquire" mode. This means
226 * that only one session can use them at a time, and that they will be
227 * automatically cleaned up if that session exits without doing so.
228 *
229 * Protected by VBOXGUESTDEVEXT::SessionSpinlock, but is unfortunately read
230 * without holding the lock in a couple of places. */
231 uint32_t volatile fAcquireModeGuestCaps;
232 /** Guest capabilities which have been set to "set" mode. This just means
233 * that they have been blocked from ever being set to "acquire" mode. */
234 uint32_t fSetModeGuestCaps;
235 /** Mask of all capabilities which are currently acquired by some session
236 * and as such reported to the host. */
237 uint32_t fAcquiredGuestCaps;
238 /** Usage counters for guest capabilities in "set" mode. Indexed by
239 * capability bit number, one count per session using a capability. */
240 VBOXGUESTBITUSAGETRACER SetGuestCapsTracker;
241 /** The guest capabilities last reported to the host (UINT32_MAX on failure). */
242 uint32_t fGuestCapsHost;
243 /** @} */
244
245 /** Heartbeat timer which fires with interval
246 * cNsHearbeatInterval and its handler sends
247 * VMMDevReq_GuestHeartbeat to VMMDev. */
248 PRTTIMER pHeartbeatTimer;
249 /** Heartbeat timer interval in nanoseconds. */
250 uint64_t cNsHeartbeatInterval;
251 /** Preallocated VMMDevReq_GuestHeartbeat request. */
252 VMMDevRequestHeader *pReqGuestHeartbeat;
253} VBOXGUESTDEVEXT;
254/** Pointer to the VBoxGuest driver data. */
255typedef VBOXGUESTDEVEXT *PVBOXGUESTDEVEXT;
256
257/** @name VBOXGUESTDEVEXT_INIT_STATE_XXX - magic values for validating init
258 * state of the device extension structur.
259 * @{ */
260#define VBOXGUESTDEVEXT_INIT_STATE_FUNDAMENT UINT32_C(0x0badcafe)
261#define VBOXGUESTDEVEXT_INIT_STATE_RESOURCES UINT32_C(0xcafebabe)
262#define VBOXGUESTDEVEXT_INIT_STATE_DELETED UINT32_C(0xdeadd0d0)
263/** @} */
264
265/**
266 * The VBoxGuest per session data.
267 */
268typedef struct VBOXGUESTSESSION
269{
270 /** The list node. */
271 RTLISTNODE ListNode;
272#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_OS2) || defined(RT_OS_SOLARIS)
273 /** Pointer to the next session with the same hash. */
274 PVBOXGUESTSESSION pNextHash;
275#endif
276#if defined(RT_OS_OS2)
277 /** The system file number of this session. */
278 uint16_t sfn;
279 uint16_t Alignment; /**< Alignment */
280#endif
281 /** The requestor information to pass to the host for this session.
282 * @sa VMMDevRequestHeader::fRequestor */
283 uint32_t fRequestor;
284 /** The process (id) of the session.
285 * This is NIL if it's a kernel session. */
286 RTPROCESS Process;
287 /** Which process this session is associated with.
288 * This is NIL if it's a kernel session. */
289 RTR0PROCESS R0Process;
290 /** Pointer to the device extension. */
291 PVBOXGUESTDEVEXT pDevExt;
292
293#ifdef VBOX_WITH_HGCM
294 /** Array containing HGCM client IDs associated with this session.
295 * This will be automatically disconnected when the session is closed. */
296 uint32_t volatile aHGCMClientIds[64];
297#endif
298 /** The last consumed VMMDEV_EVENT_MOUSE_POSITION_CHANGED sequence number.
299 * Used to implement polling. */
300 uint32_t volatile u32MousePosChangedSeq;
301 /** Host events requested by the session.
302 * An event type requested in any guest session will be added to the host
303 * filter. Protected by VBOXGUESTDEVEXT::SessionSpinlock. */
304 uint32_t fEventFilter;
305 /** Guest capabilities held in "acquired" by this session.
306 * Protected by VBOXGUESTDEVEXT::SessionSpinlock, but is unfortunately read
307 * without holding the lock in a couple of places. */
308 uint32_t volatile fAcquiredGuestCaps;
309 /** Guest capabilities in "set" mode for this session.
310 * These accumulated for sessions via VBOXGUESTDEVEXT::acGuestCapsSet and
311 * reported to the host. Protected by VBOXGUESTDEVEXT::SessionSpinlock. */
312 uint32_t fCapabilities;
313 /** Mouse features supported. A feature enabled in any guest session will
314 * be enabled for the host.
315 * @note We invert the VMMDEV_MOUSE_GUEST_NEEDS_HOST_CURSOR feature in this
316 * bitmap. The logic of this is that the real feature is when the host
317 * cursor is not needed, and we tell the host it is not needed if any
318 * session explicitly fails to assert it. Storing it inverted simplifies
319 * the checks.
320 * Use under the VBOXGUESTDEVEXT#SessionSpinlock lock. */
321 uint32_t fMouseStatus;
322#ifdef RT_OS_DARWIN
323 /** Pointer to the associated org_virtualbox_VBoxGuestClient object. */
324 void *pvVBoxGuestClient;
325 /** Whether this session has been opened or not. */
326 bool fOpened;
327#endif
328 /** Whether a CANCEL_ALL_WAITEVENTS is pending. This happens when
329 * CANCEL_ALL_WAITEVENTS is called, but no call to WAITEVENT is in process
330 * in the current session. In that case the next call will be interrupted
331 * at once. */
332 bool volatile fPendingCancelWaitEvents;
333 /** Does this session belong to a root process or a user one? */
334 bool fUserSession;
335} VBOXGUESTSESSION;
336
337RT_C_DECLS_BEGIN
338
339int VGDrvCommonInitDevExt(PVBOXGUESTDEVEXT pDevExt, uint16_t IOPortBase, void *pvMMIOBase, uint32_t cbMMIO,
340 VBOXOSTYPE enmOSType, uint32_t fEvents);
341void VGDrvCommonDeleteDevExt(PVBOXGUESTDEVEXT pDevExt);
342
343int VGDrvCommonInitLoggers(void);
344void VGDrvCommonDestroyLoggers(void);
345int VGDrvCommonInitDevExtFundament(PVBOXGUESTDEVEXT pDevExt);
346void VGDrvCommonDeleteDevExtFundament(PVBOXGUESTDEVEXT pDevExt);
347int VGDrvCommonInitDevExtResources(PVBOXGUESTDEVEXT pDevExt, uint16_t IOPortBase,
348 void *pvMMIOBase, uint32_t cbMMIO, VBOXOSTYPE enmOSType, uint32_t fFixedEvents);
349void VGDrvCommonDeleteDevExtResources(PVBOXGUESTDEVEXT pDevExt);
350int VGDrvCommonReinitDevExtAfterHibernation(PVBOXGUESTDEVEXT pDevExt, VBOXOSTYPE enmOSType);
351
352bool VBDrvCommonIsOptionValueTrue(const char *pszValue);
353void VGDrvCommonProcessOption(PVBOXGUESTDEVEXT pDevExt, const char *pszName, const char *pszValue);
354void VGDrvCommonProcessOptionsFromHost(PVBOXGUESTDEVEXT pDevExt);
355bool VGDrvCommonIsOurIRQ(PVBOXGUESTDEVEXT pDevExt);
356bool VGDrvCommonISR(PVBOXGUESTDEVEXT pDevExt);
357
358#ifdef VBOXGUEST_USE_DEFERRED_WAKE_UP
359void VGDrvCommonWaitDoWakeUps(PVBOXGUESTDEVEXT pDevExt);
360#endif
361
362int VGDrvCommonCreateUserSession(PVBOXGUESTDEVEXT pDevExt, uint32_t fRequestor, PVBOXGUESTSESSION *ppSession);
363int VGDrvCommonCreateKernelSession(PVBOXGUESTDEVEXT pDevExt, PVBOXGUESTSESSION *ppSession);
364void VGDrvCommonCloseSession(PVBOXGUESTDEVEXT pDevExt, PVBOXGUESTSESSION pSession);
365
366int VGDrvCommonIoCtlFast(uintptr_t iFunction, PVBOXGUESTDEVEXT pDevExt, PVBOXGUESTSESSION pSession);
367int VGDrvCommonIoCtl(uintptr_t iFunction, PVBOXGUESTDEVEXT pDevExt, PVBOXGUESTSESSION pSession,
368 PVBGLREQHDR pReqHdr, size_t cbReq);
369
370/**
371 * ISR callback for notifying threads polling for mouse events.
372 *
373 * This is called at the end of the ISR, after leaving the event spinlock, if
374 * VMMDEV_EVENT_MOUSE_POSITION_CHANGED was raised by the host.
375 *
376 * @param pDevExt The device extension.
377 */
378void VGDrvNativeISRMousePollEvent(PVBOXGUESTDEVEXT pDevExt);
379
380/**
381 * Hook for handling OS specfic options from the host.
382 *
383 * @returns true if handled, false if not.
384 * @param pDevExt The device extension.
385 * @param pszName The option name.
386 * @param pszValue The option value.
387 */
388bool VGDrvNativeProcessOption(PVBOXGUESTDEVEXT pDevExt, const char *pszName, const char *pszValue);
389
390
391#ifdef VBOX_WITH_DPC_LATENCY_CHECKER
392int VGDrvNtIOCtl_DpcLatencyChecker(void);
393#endif
394
395#ifdef VBOXGUEST_MOUSE_NOTIFY_CAN_PREEMPT
396int VGDrvNativeSetMouseNotifyCallback(PVBOXGUESTDEVEXT pDevExt, PVBGLIOCSETMOUSENOTIFYCALLBACK pNotify);
397#endif
398
399RT_C_DECLS_END
400
401#endif
402
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