VirtualBox

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

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

VBoxGuest-win*: cleanups.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.9 KB
Line 
1/* $Id: VBoxGuestInternal.h 44983 2013-03-11 13:34:31Z 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/**
112 * VBox guest device (data) extension.
113 */
114typedef 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#ifdef VBOX_WITH_VRDP_SESSION_HANDLING
162 bool fVRDPEnabled;
163#endif
164 /** Flag indicating whether logging to the release log
165 * is enabled. */
166 bool fLoggingEnabled;
167 /** Memory balloon information for RTR0MemObjAllocPhysNC(). */
168 VBOXGUESTMEMBALLOON MemBalloon;
169 /** For each mouse status feature the number of sessions which have
170 * enabled it. A feature is enabled globally if at least one session has
171 * requested it. */
172 /** @todo can we programmatically determine the size of the array and
173 * still get the following alignment right? */
174 uint32_t volatile acMouseFeatureUsage[32];
175 /** The mouse feature status matching the counts above. These are updated
176 * together inside the session spinlock. */
177 uint32_t volatile fMouseStatus;
178 /** Counter of number of active ISRs. Currently used for safely removing
179 * the mouse handler callback. */
180 uint32_t volatile cISR;
181 /** Callback and user data for a kernel mouse handler. */
182 VBoxGuestMouseSetNotifyCallback MouseNotifyCallback;
183
184 /** Windows part.
185 * @todo r=bird: Entirely wrong approach. You should create
186 * VBOXGUESTDEVEXTWIN as a super structure to VBOXGUESTDEVEXT. If they
187 * were classes, class VBOXGUESTDEVEXTWIN : public VBOXGUESTDEVEXT ... */
188 union
189 {
190#ifdef ___VBoxGuest_win_h
191 VBOXGUESTDEVEXTWIN s;
192#else
193 uint32_t dummy;
194#endif
195 } win;
196
197} VBOXGUESTDEVEXT;
198/** Pointer to the VBoxGuest driver data. */
199typedef VBOXGUESTDEVEXT *PVBOXGUESTDEVEXT;
200
201
202/**
203 * The VBoxGuest per session data.
204 *
205 * @remark Not quite sure whether this will be useful or not, but since
206 * its already there let's keep it for now in case it might come
207 * in handy later.
208 */
209typedef struct VBOXGUESTSESSION
210{
211#if defined(RT_OS_OS2) || defined(RT_OS_FREEBSD) || defined(RT_OS_SOLARIS)
212 /** Pointer to the next session with the same hash. */
213 PVBOXGUESTSESSION pNextHash;
214#endif
215#if defined(RT_OS_OS2)
216 /** The system file number of this session. */
217 uint16_t sfn;
218 uint16_t Alignment; /**< Alignment */
219#endif
220 /** The process (id) of the session.
221 * This is NIL if it's a kernel session. */
222 RTPROCESS Process;
223 /** Which process this session is associated with.
224 * This is NIL if it's a kernel session. */
225 RTR0PROCESS R0Process;
226 /** Pointer to the device extension. */
227 PVBOXGUESTDEVEXT pDevExt;
228
229#ifdef VBOX_WITH_HGCM
230 /** Array containing HGCM client IDs associated with this session.
231 * This will be automatically disconnected when the session is closed. */
232 uint32_t volatile aHGCMClientIds[64];
233#endif
234 /** The last consumed VMMDEV_EVENT_MOUSE_POSITION_CHANGED sequence number.
235 * Used to implement polling. */
236 uint32_t volatile u32MousePosChangedSeq;
237 /** Mouse features supported. A feature enabled in any guest session will
238 * be enabled for the host. */
239 uint32_t volatile fMouseStatus;
240
241} VBOXGUESTSESSION;
242
243RT_C_DECLS_BEGIN
244
245int VBoxGuestInitDevExt(PVBOXGUESTDEVEXT pDevExt, uint16_t IOPortBase, void *pvMMIOBase, uint32_t cbMMIO, VBOXOSTYPE enmOSType, uint32_t fEvents);
246bool VBoxGuestCommonISR(PVBOXGUESTDEVEXT pDevExt);
247void VBoxGuestDeleteDevExt(PVBOXGUESTDEVEXT pDevExt);
248int VBoxGuestReinitDevExtAfterHibernation(PVBOXGUESTDEVEXT pDevExt, VBOXOSTYPE enmOSType);
249int VBoxGuestSetGuestCapabilities(uint32_t fOr, uint32_t fNot);
250#ifdef VBOXGUEST_USE_DEFERRED_WAKE_UP
251void VBoxGuestWaitDoWakeUps(PVBOXGUESTDEVEXT pDevExt);
252#endif
253
254int VBoxGuestCreateUserSession(PVBOXGUESTDEVEXT pDevExt, PVBOXGUESTSESSION *ppSession);
255int VBoxGuestCreateKernelSession(PVBOXGUESTDEVEXT pDevExt, PVBOXGUESTSESSION *ppSession);
256void VBoxGuestCloseSession(PVBOXGUESTDEVEXT pDevExt, PVBOXGUESTSESSION pSession);
257
258int VBoxGuestCommonIOCtlFast(unsigned iFunction, PVBOXGUESTDEVEXT pDevExt, PVBOXGUESTSESSION pSession);
259int VBoxGuestCommonIOCtl(unsigned iFunction, PVBOXGUESTDEVEXT pDevExt, PVBOXGUESTSESSION pSession,
260 void *pvData, size_t cbData, size_t *pcbDataReturned);
261
262#if defined(RT_OS_SOLARIS) \
263 || defined(RT_OS_FREEBSD) \
264 || defined(RT_OS_LINUX)
265DECLVBGL(void *) VBoxGuestNativeServiceOpen(uint32_t *pu32Version);
266DECLVBGL(void) VBoxGuestNativeServiceClose(void *pvOpaque);
267DECLVBGL(int) VBoxGuestNativeServiceCall(void *pvOpaque, unsigned int iCmd, void *pvData, size_t cbSize, size_t *pcbReturn);
268#endif
269
270/**
271 * ISR callback for notifying threads polling for mouse events.
272 *
273 * This is called at the end of the ISR, after leaving the event spinlock, if
274 * VMMDEV_EVENT_MOUSE_POSITION_CHANGED was raised by the host.
275 *
276 * @param pDevExt The device extension.
277 */
278void VBoxGuestNativeISRMousePollEvent(PVBOXGUESTDEVEXT pDevExt);
279
280RT_C_DECLS_END
281
282#endif
283
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette