VirtualBox

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

Last change on this file since 46354 was 45779, checked in by vboxsync, 12 years ago

VBoxGuest: better caps filtering; cleanup

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.2 KB
Line 
1/* $Id: VBoxGuestInternal.h 45779 2013-04-26 15:18:59Z vboxsync $ */
2/** @file
3 * VBoxGuest - Guest Additions Driver.
4 */
5
6/*
7 * Copyright (C) 2010-2012 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 <VBox/VMMDev.h>
35#include <VBox/VBoxGuest.h>
36#include <VBox/VBoxGuestLib.h>
37
38/** @def VBOXGUEST_USE_WAKE_UP_LIST
39 * Defer wake-up of waiting thread when defined. */
40#if defined(RT_OS_SOLARIS) || defined(RT_OS_WINDOWS) || defined(DOXYGEN_RUNNING)
41# define VBOXGUEST_USE_DEFERRED_WAKE_UP
42#endif
43
44
45/** Pointer to the VBoxGuest per session data. */
46typedef struct VBOXGUESTSESSION *PVBOXGUESTSESSION;
47
48/** Pointer to a wait-for-event entry. */
49typedef struct VBOXGUESTWAIT *PVBOXGUESTWAIT;
50
51/**
52 * VBox guest wait for event entry.
53 *
54 * Each waiting thread allocates one of these items and adds
55 * it to the wait list before going to sleep on the event sem.
56 */
57typedef struct VBOXGUESTWAIT
58{
59 /** The list node. */
60 RTLISTNODE ListNode;
61 /** The events we are waiting on. */
62 uint32_t fReqEvents;
63 /** The events we received. */
64 uint32_t volatile fResEvents;
65#ifdef VBOXGUEST_USE_DEFERRED_WAKE_UP
66 /** Set by VBoxGuestWaitDoWakeUps before leaving the spinlock to call
67 * RTSemEventMultiSignal. */
68 bool volatile fPendingWakeUp;
69 /** Set by the requestor thread if it got the spinlock before the
70 * signaller. Deals with the race in VBoxGuestWaitDoWakeUps. */
71 bool volatile fFreeMe;
72#endif
73 /** The event semaphore. */
74 RTSEMEVENTMULTI Event;
75 /** The session that's waiting. */
76 PVBOXGUESTSESSION pSession;
77#ifdef VBOX_WITH_HGCM
78 /** The HGCM request we're waiting for to complete. */
79 VMMDevHGCMRequestHeader volatile *pHGCMReq;
80#endif
81} VBOXGUESTWAIT;
82
83
84/**
85 * VBox guest memory balloon.
86 */
87typedef struct VBOXGUESTMEMBALLOON
88{
89 /** Mutex protecting the members below from concurrent access.. */
90 RTSEMFASTMUTEX hMtx;
91 /** The current number of chunks in the balloon. */
92 uint32_t cChunks;
93 /** The maximum number of chunks in the balloon (typically the amount of guest
94 * memory / chunksize). */
95 uint32_t cMaxChunks;
96 /** This is true if we are using RTR0MemObjAllocPhysNC() / RTR0MemObjGetPagePhysAddr()
97 * and false otherwise. */
98 bool fUseKernelAPI;
99 /** The current owner of the balloon.
100 * This is automatically assigned to the first session using the ballooning
101 * API and first released when the session closes. */
102 PVBOXGUESTSESSION pOwner;
103 /** The pointer to the array of memory objects holding the chunks of the
104 * balloon. This array is cMaxChunks in size when present. */
105 PRTR0MEMOBJ paMemObj;
106} VBOXGUESTMEMBALLOON;
107/** Pointer to a memory balloon. */
108typedef VBOXGUESTMEMBALLOON *PVBOXGUESTMEMBALLOON;
109
110/**
111 * VBox guest device (data) extension.
112 */
113typedef struct VBOXGUESTDEVEXT
114{
115 /** The base of the adapter I/O ports. */
116 RTIOPORT IOPortBase;
117 /** Pointer to the mapping of the VMMDev adapter memory. */
118 VMMDevMemory volatile *pVMMDevMemory;
119 /** Events we won't permit anyone to filter out. */
120 uint32_t fFixedEvents;
121 /** The memory object reserving space for the guest mappings. */
122 RTR0MEMOBJ hGuestMappings;
123 /** Spinlock protecting the signaling and resetting of the wait-for-event
124 * semaphores as well as the event acking in the ISR. */
125 RTSPINLOCK EventSpinlock;
126 /** Preallocated VMMDevEvents for the IRQ handler. */
127 VMMDevEvents *pIrqAckEvents;
128 /** The physical address of pIrqAckEvents. */
129 RTCCPHYS PhysIrqAckEvents;
130 /** Wait-for-event list for threads waiting for multiple events
131 * (VBOXGUESTWAIT). */
132 RTLISTANCHOR WaitList;
133#ifdef VBOX_WITH_HGCM
134 /** Wait-for-event list for threads waiting on HGCM async completion
135 * (VBOXGUESTWAIT).
136 *
137 * The entire list is evaluated upon the arrival of an HGCM event, unlike
138 * the other lists which are only evaluated till the first thread has
139 * been woken up. */
140 RTLISTANCHOR HGCMWaitList;
141#endif
142#ifdef VBOXGUEST_USE_DEFERRED_WAKE_UP
143 /** List of wait-for-event entries that needs waking up
144 * (VBOXGUESTWAIT). */
145 RTLISTANCHOR WakeUpList;
146#endif
147 /** List of wait-for-event entries that has been woken up
148 * (VBOXGUESTWAIT). */
149 RTLISTANCHOR WokenUpList;
150 /** List of free wait-for-event entries (VBOXGUESTWAIT). */
151 RTLISTANCHOR FreeList;
152 /** Mask of pending events. */
153 uint32_t volatile f32PendingEvents;
154 /** Current VMMDEV_EVENT_MOUSE_POSITION_CHANGED sequence number.
155 * Used to implement polling. */
156 uint32_t volatile u32MousePosChangedSeq;
157
158 /** Spinlock various items in the VBOXGUESTSESSION. */
159 RTSPINLOCK SessionSpinlock;
160#ifdef VBOX_WITH_VRDP_SESSION_HANDLING
161 bool fVRDPEnabled;
162#endif
163 /** Flag indicating whether logging to the release log
164 * is enabled. */
165 bool fLoggingEnabled;
166 /** Memory balloon information for RTR0MemObjAllocPhysNC(). */
167 VBOXGUESTMEMBALLOON MemBalloon;
168 /** For each mouse status feature the number of sessions which have
169 * enabled it. A feature is enabled globally if at least one session has
170 * requested it. */
171 /** @todo can we programmatically determine the size of the array and
172 * still get the following alignment right? */
173 uint32_t volatile acMouseFeatureUsage[32];
174 /** The mouse feature status matching the counts above. These are updated
175 * together inside the session spinlock. */
176 uint32_t volatile fMouseStatus;
177 /** Counter of number of active ISRs. Currently used for safely removing
178 * the mouse handler callback. */
179 uint32_t volatile cISR;
180 /** Callback and user data for a kernel mouse handler. */
181 VBoxGuestMouseSetNotifyCallback MouseNotifyCallback;
182 /* list of caps used in acquire mode */
183 uint32_t u32AcquireModeGuestCaps;
184 /* list of caps used in set mode */
185 uint32_t u32SetModeGuestCaps;
186 /* currently acquired (and reported) guest caps */
187 uint32_t u32GuestCaps;
188} VBOXGUESTDEVEXT;
189/** Pointer to the VBoxGuest driver data. */
190typedef VBOXGUESTDEVEXT *PVBOXGUESTDEVEXT;
191
192
193/**
194 * The VBoxGuest per session data.
195 *
196 * @remark Not quite sure whether this will be useful or not, but since
197 * its already there let's keep it for now in case it might come
198 * in handy later.
199 */
200typedef struct VBOXGUESTSESSION
201{
202#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_OS2) || defined(RT_OS_SOLARIS)
203 /** Pointer to the next session with the same hash. */
204 PVBOXGUESTSESSION pNextHash;
205#endif
206#if defined(RT_OS_OS2)
207 /** The system file number of this session. */
208 uint16_t sfn;
209 uint16_t Alignment; /**< Alignment */
210#endif
211 /** The process (id) of the session.
212 * This is NIL if it's a kernel session. */
213 RTPROCESS Process;
214 /** Which process this session is associated with.
215 * This is NIL if it's a kernel session. */
216 RTR0PROCESS R0Process;
217 /** Pointer to the device extension. */
218 PVBOXGUESTDEVEXT pDevExt;
219
220#ifdef VBOX_WITH_HGCM
221 /** Array containing HGCM client IDs associated with this session.
222 * This will be automatically disconnected when the session is closed. */
223 uint32_t volatile aHGCMClientIds[64];
224#endif
225 /** The last consumed VMMDEV_EVENT_MOUSE_POSITION_CHANGED sequence number.
226 * Used to implement polling. */
227 uint32_t volatile u32MousePosChangedSeq;
228 /** Mouse features supported. A feature enabled in any guest session will
229 * be enabled for the host. */
230 uint32_t volatile fMouseStatus;
231#ifdef RT_OS_DARWIN
232 /** Pointer to the associated org_virtualbox_VBoxGuestClient object. */
233 void *pvVBoxGuestClient;
234 /** Whether this session has been opened or not. */
235 bool fOpened;
236#endif
237 /* Guest Caps Acquired & Reported by this session */
238 uint32_t u32AquiredGuestCaps;
239} VBOXGUESTSESSION;
240
241RT_C_DECLS_BEGIN
242
243int VBoxGuestInitDevExt(PVBOXGUESTDEVEXT pDevExt, uint16_t IOPortBase, void *pvMMIOBase, uint32_t cbMMIO, VBOXOSTYPE enmOSType, uint32_t fEvents);
244bool VBoxGuestCommonISR(PVBOXGUESTDEVEXT pDevExt);
245void VBoxGuestDeleteDevExt(PVBOXGUESTDEVEXT pDevExt);
246int VBoxGuestReinitDevExtAfterHibernation(PVBOXGUESTDEVEXT pDevExt, VBOXOSTYPE enmOSType);
247int VBoxGuestSetGuestCapabilities(uint32_t fOr, uint32_t fNot);
248#ifdef VBOXGUEST_USE_DEFERRED_WAKE_UP
249void VBoxGuestWaitDoWakeUps(PVBOXGUESTDEVEXT pDevExt);
250#endif
251
252int VBoxGuestCreateUserSession(PVBOXGUESTDEVEXT pDevExt, PVBOXGUESTSESSION *ppSession);
253int VBoxGuestCreateKernelSession(PVBOXGUESTDEVEXT pDevExt, PVBOXGUESTSESSION *ppSession);
254void VBoxGuestCloseSession(PVBOXGUESTDEVEXT pDevExt, PVBOXGUESTSESSION pSession);
255
256int VBoxGuestCommonIOCtlFast(unsigned iFunction, PVBOXGUESTDEVEXT pDevExt, PVBOXGUESTSESSION pSession);
257int VBoxGuestCommonIOCtl(unsigned iFunction, PVBOXGUESTDEVEXT pDevExt, PVBOXGUESTSESSION pSession,
258 void *pvData, size_t cbData, size_t *pcbDataReturned);
259
260#if defined(RT_OS_SOLARIS) \
261 || defined(RT_OS_FREEBSD) \
262 || defined(RT_OS_LINUX)
263DECLVBGL(void *) VBoxGuestNativeServiceOpen(uint32_t *pu32Version);
264DECLVBGL(void) VBoxGuestNativeServiceClose(void *pvOpaque);
265DECLVBGL(int) VBoxGuestNativeServiceCall(void *pvOpaque, unsigned int iCmd, void *pvData, size_t cbSize, size_t *pcbReturn);
266#endif
267
268/**
269 * ISR callback for notifying threads polling for mouse events.
270 *
271 * This is called at the end of the ISR, after leaving the event spinlock, if
272 * VMMDEV_EVENT_MOUSE_POSITION_CHANGED was raised by the host.
273 *
274 * @param pDevExt The device extension.
275 */
276void VBoxGuestNativeISRMousePollEvent(PVBOXGUESTDEVEXT pDevExt);
277
278
279#ifdef VBOX_WITH_DPC_LATENCY_CHECKER
280int VbgdNtIOCtl_DpcLatencyChecker(void);
281#endif
282
283RT_C_DECLS_END
284
285#endif
286
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