VirtualBox

source: vbox/trunk/include/VBox/VBoxGuest.h@ 21226

Last change on this file since 21226 was 21226, checked in by vboxsync, 16 years ago

VMMDev.h: cleanup.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 17.4 KB
Line 
1/** @file
2 * VBoxGuest - VirtualBox Guest Additions Driver Interface. (ADD,DEV)
3 *
4 * @remarks This is in the process of being split up and usage cleaned up.
5 */
6
7/*
8 * Copyright (C) 2006-2009 Sun Microsystems, Inc.
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 *
18 * The contents of this file may alternatively be used under the terms
19 * of the Common Development and Distribution License Version 1.0
20 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
21 * VirtualBox OSE distribution, in which case the provisions of the
22 * CDDL are applicable instead of those of the GPL.
23 *
24 * You may elect to license modified versions of this file under the
25 * terms and conditions of either the GPL or the CDDL or both.
26 *
27 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
28 * Clara, CA 95054 USA or visit http://www.sun.com if you need
29 * additional information or have any questions.
30 */
31
32#ifndef ___VBox_VBoxGuest_h
33#define ___VBox_VBoxGuest_h
34
35#include <VBox/cdefs.h>
36#include <VBox/types.h>
37#include <iprt/assert.h>
38#include <VBox/VMMDev.h> /* Temporarily. */
39
40
41/** @defgroup grp_vboxguest VirtualBox Guest Additions Driver Interface
42 * @{
43 */
44
45/** @todo it would be nice if we could have two define without paths. */
46
47/** @def VBOXGUEST_DEVICE_NAME
48 * The support device name. */
49/** @def VBOXGUEST_USER_DEVICE_NAME
50 * The support device name of the user accessible device node. */
51
52#if defined(RT_OS_OS2)
53# define VBOXGUEST_DEVICE_NAME "\\Dev\\VBoxGst$"
54
55#elif defined(RT_OS_WINDOWS)
56# define VBOXGUEST_DEVICE_NAME "\\\\.\\VBoxGuest"
57
58/** The support service name. */
59# define VBOXGUEST_SERVICE_NAME "VBoxGuest"
60/** Global name for Win2k+ */
61# define VBOXGUEST_DEVICE_NAME_GLOBAL "\\\\.\\Global\\VBoxGuest"
62/** Win32 driver name */
63# define VBOXGUEST_DEVICE_NAME_NT L"\\Device\\VBoxGuest"
64/** Device name. */
65# define VBOXGUEST_DEVICE_NAME_DOS L"\\DosDevices\\VBoxGuest"
66
67#elif defined(RT_OS_LINUX) && !defined(VBOX_WITH_COMMON_VBOXGUEST_ON_LINUX)
68# define VBOXGUEST_DEVICE_NAME "/dev/vboxadd"
69# define VBOXGUEST_USER_DEVICE_NAME "/dev/vboxuser"
70
71#else /* PORTME */
72# define VBOXGUEST_DEVICE_NAME "/dev/vboxguest"
73# if defined(RT_OS_LINUX)
74# define VBOXGUEST_USER_DEVICE_NAME "/dev/vboxuser"
75# endif
76#endif
77
78#ifndef VBOXGUEST_USER_DEVICE_NAME
79# define VBOXGUEST_USER_DEVICE_NAME VBOXGUEST_DEVICE_NAME
80#endif
81
82/** Fictive start address of the hypervisor physical memory for MmMapIoSpace. */
83#define VBOXGUEST_HYPERVISOR_PHYSICAL_START UINT32_C(0xf8000000)
84
85
86#if !defined(IN_RC) && !defined(IN_RING0_AGNOSTIC) && !defined(IPRT_NO_CRT)
87/** @name VBoxGuest IOCTL codes and structures.
88 *
89 * The range 0..15 is for basic driver communication.
90 * The range 16..31 is for HGCM communcation.
91 * The range 32..47 is reserved for future use.
92 * The range 48..63 is for OS specific communcation.
93 * The 7th bit is reserved for future hacks.
94 * The 8th bit is reserved for distinguishing between 32-bit and 64-bit
95 * processes in future 64-bit guest additions.
96 *
97 * @remarks When creating new IOCtl interfaces keep in mind that not all OSes supports
98 * reporting back the output size. (This got messed up a little bit in VBoxDrv.)
99 *
100 * The request size is also a little bit tricky as it's passed as part of the
101 * request code on unix. The size field is 14 bits on Linux, 12 bits on *BSD,
102 * 13 bits Darwin, and 8-bits on Solaris. All the BSDs and Darwin kernels
103 * will make use of the size field, while Linux and Solaris will not. We're of
104 * course using the size to validate and/or map/lock the request, so it has
105 * to be valid.
106 *
107 * For Solaris we will have to do something special though, 255 isn't
108 * sufficent for all we need. A 4KB restriction (BSD) is probably not
109 * too problematic (yet) as a general one.
110 *
111 * More info can be found in SUPDRVIOC.h and related sources.
112 *
113 * @remarks If adding interfaces that only has input or only has output, some new macros
114 * needs to be created so the most efficient IOCtl data buffering method can be
115 * used.
116 * @{
117 */
118#ifdef RT_ARCH_AMD64
119# define VBOXGUEST_IOCTL_FLAG 128
120#elif defined(RT_ARCH_X86)
121# define VBOXGUEST_IOCTL_FLAG 0
122#else
123# error "dunno which arch this is!"
124#endif
125
126/** Ring-3 request wrapper for big requests.
127 *
128 * This is necessary because the ioctl number scheme on many Unixy OSes (esp. Solaris)
129 * only allows a relatively small size to be encoded into the request. So, for big
130 * request this generic form is used instead. */
131typedef struct VBGLBIGREQ
132{
133 /** Magic value (VBGLBIGREQ_MAGIC). */
134 uint32_t u32Magic;
135 /** The size of the data buffer. */
136 uint32_t cbData;
137 /** The user address of the data buffer. */
138 RTR3PTR pvDataR3;
139#if HC_ARCH_BITS == 32
140 uint32_t u32Padding;
141#endif
142/** @todo r=bird: We need a 'rc' field for passing VBox status codes. Reused
143 * some input field as rc on output. */
144} VBGLBIGREQ;
145/** Pointer to a request wrapper for solaris guests. */
146typedef VBGLBIGREQ *PVBGLBIGREQ;
147/** Pointer to a const request wrapper for solaris guests. */
148typedef const VBGLBIGREQ *PCVBGLBIGREQ;
149
150/** The VBGLBIGREQ::u32Magic value (Ryuu Murakami). */
151#define VBGLBIGREQ_MAGIC 0x19520219
152
153
154#if defined(RT_OS_WINDOWS)
155/* @todo Remove IOCTL_CODE later! Integrate it in VBOXGUEST_IOCTL_CODE below. */
156/** @todo r=bird: IOCTL_CODE is supposedly defined in some header included by Windows.h or ntddk.h, which is why it wasn't in the #if 0 earlier. See HostDrivers/Support/SUPDrvIOC.h... */
157# define IOCTL_CODE(DeviceType, Function, Method, Access, DataSize_ignored) \
158 ( ((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method))
159# define VBOXGUEST_IOCTL_CODE_(Function, Size) IOCTL_CODE(FILE_DEVICE_UNKNOWN, 2048 + (Function), METHOD_BUFFERED, FILE_WRITE_ACCESS, 0)
160# define VBOXGUEST_IOCTL_STRIP_SIZE_(Code) (Code)
161
162#elif defined(RT_OS_OS2)
163 /* No automatic buffering, size not encoded. */
164# define VBOXGUEST_IOCTL_CATEGORY 0xc2
165# define VBOXGUEST_IOCTL_CODE_(Function, Size) ((unsigned char)(Function))
166# define VBOXGUEST_IOCTL_CATEGORY_FAST 0xc3 /**< Also defined in VBoxGuestA-os2.asm. */
167# define VBOXGUEST_IOCTL_CODE_FAST_(Function) ((unsigned char)(Function))
168# define VBOXGUEST_IOCTL_STRIP_SIZE(Code) (Code)
169
170#elif defined(RT_OS_SOLARIS)
171 /* No automatic buffering, size limited to 255 bytes => use VBGLBIGREQ for everything. */
172# include <sys/ioccom.h>
173# define VBOXGUEST_IOCTL_CODE_(Function, Size) _IOWRN('V', (Function), sizeof(VBGLBIGREQ))
174# define VBOXGUEST_IOCTL_CODE_FAST_(Function) _IO( 'V', (Function))
175# define VBOXGUEST_IOCTL_STRIP_SIZE(Code) (Code)
176
177#elif defined(RT_OS_LINUX)
178 /* No automatic buffering, size limited to 16KB. */
179# include <linux/ioctl.h>
180# define VBOXGUEST_IOCTL_CODE_(Function, Size) _IOC(_IOC_READ|_IOC_WRITE, 'V', (Function), (Size))
181# define VBOXGUEST_IOCTL_CODE_FAST_(Function) _IO( 'V', (Function))
182# define VBOXGUEST_IOCTL_STRIP_SIZE(Code) VBOXGUEST_IOCTL_CODE_(_IOC_NR((Code)), 0)
183
184#elif defined(RT_OS_FREEBSD) /** @todo r=bird: Please do it like SUPDRVIOC to keep it as similar as possible. */
185# include <sys/ioccom.h>
186
187# define VBOXGUEST_IOCTL_CODE_(Function, Size) _IOWR('V', (Function), VBGLBIGREQ)
188# define VBOXGUEST_IOCTL_CODE_FAST_(Function) _IO( 'V', (Function))
189# define VBOXGUEST_IOCTL_STRIP_SIZE(Code) IOCBASECMD(Code)
190
191#else
192/* PORTME */
193#endif
194
195#define VBOXGUEST_IOCTL_CODE(Function, Size) VBOXGUEST_IOCTL_CODE_((Function) | VBOXGUEST_IOCTL_FLAG, Size)
196#define VBOXGUEST_IOCTL_CODE_FAST(Function) VBOXGUEST_IOCTL_CODE_FAST_((Function) | VBOXGUEST_IOCTL_FLAG)
197
198/* Define 32 bit codes to support 32 bit applications requests in the 64 bit guest driver. */
199#ifdef RT_ARCH_AMD64
200# define VBOXGUEST_IOCTL_CODE_32(Function, Size) VBOXGUEST_IOCTL_CODE_(Function, Size)
201# define VBOXGUEST_IOCTL_CODE_FAST_32(Function) VBOXGUEST_IOCTL_CODE_FAST_(Function)
202#endif /* RT_ARCH_AMD64 */
203
204
205
206/** IOCTL to VBoxGuest to query the VMMDev IO port region start.
207 * @remarks Ring-0 only. */
208#define VBOXGUEST_IOCTL_GETVMMDEVPORT VBOXGUEST_IOCTL_CODE(1, sizeof(VBoxGuestPortInfo))
209
210#pragma pack(4)
211typedef struct _VBoxGuestPortInfo
212{
213 uint32_t portAddress;
214 VMMDevMemory *pVMMDevMemory;
215} VBoxGuestPortInfo;
216
217
218/** IOCTL to VBoxGuest to wait for a VMMDev host notification */
219#define VBOXGUEST_IOCTL_WAITEVENT VBOXGUEST_IOCTL_CODE_(2, sizeof(VBoxGuestWaitEventInfo))
220
221/** @name Result codes for VBoxGuestWaitEventInfo::u32Result
222 * @{
223 */
224/** Successful completion, an event occured. */
225#define VBOXGUEST_WAITEVENT_OK (0)
226/** Successful completion, timed out. */
227#define VBOXGUEST_WAITEVENT_TIMEOUT (1)
228/** Wait was interrupted. */
229#define VBOXGUEST_WAITEVENT_INTERRUPTED (2)
230/** An error occured while processing the request. */
231#define VBOXGUEST_WAITEVENT_ERROR (3)
232/** @} */
233
234/** Input and output buffers layout of the IOCTL_VBOXGUEST_WAITEVENT */
235typedef struct VBoxGuestWaitEventInfo
236{
237 /** timeout in milliseconds */
238 uint32_t u32TimeoutIn;
239 /** events to wait for */
240 uint32_t u32EventMaskIn;
241 /** result code */
242 uint32_t u32Result;
243 /** events occured */
244 uint32_t u32EventFlagsOut;
245} VBoxGuestWaitEventInfo;
246AssertCompileSize(VBoxGuestWaitEventInfo, 16);
247
248
249/** IOCTL to VBoxGuest to interrupt (cancel) any pending WAITEVENTs and return.
250 * Handled inside the guest additions and not seen by the host at all.
251 * @see VBOXGUEST_IOCTL_WAITEVENT */
252#define VBOXGUEST_IOCTL_CANCEL_ALL_WAITEVENTS VBOXGUEST_IOCTL_CODE_(5, 0)
253
254
255
256/** IOCTL to VBoxGuest to perform a VMM request
257 * @remark The data buffer for this IOCtl has an variable size, keep this in mind
258 * on systems where this matters. */
259#define VBOXGUEST_IOCTL_VMMREQUEST(Size) VBOXGUEST_IOCTL_CODE_(3, (Size))
260
261
262/** IOCTL to VBoxGuest to control event filter mask. */
263#define VBOXGUEST_IOCTL_CTL_FILTER_MASK VBOXGUEST_IOCTL_CODE_(4, sizeof(VBoxGuestFilterMaskInfo))
264
265/** Input and output buffer layout of the IOCTL_VBOXGUEST_CTL_FILTER_MASK. */
266typedef struct VBoxGuestFilterMaskInfo
267{
268 uint32_t u32OrMask;
269 uint32_t u32NotMask;
270} VBoxGuestFilterMaskInfo;
271AssertCompileSize(VBoxGuestFilterMaskInfo, 8);
272#pragma pack()
273
274
275/** IOCTL to VBoxGuest to check memory ballooning. */
276#define VBOXGUEST_IOCTL_CTL_CHECK_BALLOON_MASK VBOXGUEST_IOCTL_CODE_(7, 100)
277
278
279/** IOCTL to VBoxGuest to perform backdoor logging.
280 * The argument is a string buffer of the specified size. */
281#define VBOXGUEST_IOCTL_LOG(Size) VBOXGUEST_IOCTL_CODE_(6, (Size))
282
283
284#ifdef VBOX_WITH_HGCM
285/** IOCTL to VBoxGuest to connect to a HGCM service. */
286# define VBOXGUEST_IOCTL_HGCM_CONNECT VBOXGUEST_IOCTL_CODE(16, sizeof(VBoxGuestHGCMConnectInfo))
287
288# pragma pack(1) /* explicit packing for good measure. */
289typedef struct VBoxGuestHGCMConnectInfo
290{
291 int32_t result; /**< OUT */
292 HGCMServiceLocation Loc; /**< IN */
293 uint32_t u32ClientID; /**< OUT */
294} VBoxGuestHGCMConnectInfo;
295AssertCompileSize(VBoxGuestHGCMConnectInfo, 4+4+128+4);
296# pragma pack()
297
298
299/** IOCTL to VBoxGuest to disconnect from a HGCM service. */
300# define VBOXGUEST_IOCTL_HGCM_DISCONNECT VBOXGUEST_IOCTL_CODE(17, sizeof(VBoxGuestHGCMDisconnectInfo))
301typedef struct VBoxGuestHGCMDisconnectInfo
302{
303 int32_t result; /**< OUT */
304 uint32_t u32ClientID; /**< IN */
305} VBoxGuestHGCMDisconnectInfo;
306AssertCompileSize(VBoxGuestHGCMDisconnectInfo, 8);
307
308
309/** IOCTL to VBoxGuest to make a call to a HGCM service. */
310# define VBOXGUEST_IOCTL_HGCM_CALL(Size) VBOXGUEST_IOCTL_CODE(18, (Size))
311typedef struct VBoxGuestHGCMCallInfo
312{
313 int32_t result; /**< OUT Host HGCM return code.*/
314 uint32_t u32ClientID; /**< IN The id of the caller. */
315 uint32_t u32Function; /**< IN Function number. */
316 uint32_t cParms; /**< IN How many parms. */
317 /* Parameters follow in form HGCMFunctionParameter aParms[cParms] */
318} VBoxGuestHGCMCallInfo;
319AssertCompileSize(VBoxGuestHGCMCallInfo, 16);
320
321
322/** IOCTL to VBoxGuest to make a timed call to a HGCM service. */
323# define VBOXGUEST_IOCTL_HGCM_CALL_TIMED(Size) VBOXGUEST_IOCTL_CODE(20, (Size))
324# pragma pack(1) /* explicit packing for good measure. */
325typedef struct VBoxGuestHGCMCallInfoTimed
326{
327 uint32_t u32Timeout; /**< IN How long to wait for completion before cancelling the call. */
328 uint32_t fInterruptible; /**< IN Is this request interruptible? */
329 VBoxGuestHGCMCallInfo info; /**< IN/OUT The rest of the call information. Placed after the timeout
330 * so that the parameters follow as they would for a normal call. */
331 /* Parameters follow in form HGCMFunctionParameter aParms[cParms] */
332} VBoxGuestHGCMCallInfoTimed;
333AssertCompileSize(VBoxGuestHGCMCallInfoTimed, 8+16);
334# pragma pack()
335
336# ifdef RT_ARCH_AMD64
337/** @name IOCTL numbers that 32-bit clients, like the Windows OpenGL guest
338 * driver, will use when taking to a 64-bit driver.
339 * @remarks These are only used by the driver implementation! */
340# define VBOXGUEST_IOCTL_HGCM_CONNECT_32 VBOXGUEST_IOCTL_CODE_32(16, sizeof(VBoxGuestHGCMConnectInfo))
341# define VBOXGUEST_IOCTL_HGCM_DISCONNECT_32 VBOXGUEST_IOCTL_CODE_32(17, sizeof(VBoxGuestHGCMDisconnectInfo))
342# define VBOXGUEST_IOCTL_HGCM_CALL_32(Size) VBOXGUEST_IOCTL_CODE_32(18, (Size))
343# define VBOXGUEST_IOCTL_HGCM_CALL_TIMED_32(Size) VBOXGUEST_IOCTL_CODE_32(20, (Size))
344/** @} */
345# endif /* RT_ARCH_AMD64 */
346
347/** Get the pointer to the first HGCM parameter. */
348# define VBOXGUEST_HGCM_CALL_PARMS(a) ( (HGCMFunctionParameter *)((uint8_t *)(a) + sizeof(VBoxGuestHGCMCallInfo)) )
349/** Get the pointer to the first HGCM parameter in a 32-bit request. */
350# define VBOXGUEST_HGCM_CALL_PARMS32(a) ( (HGCMFunctionParameter32 *)((uint8_t *)(a) + sizeof(VBoxGuestHGCMCallInfo)) )
351
352/** IOCTL to VBoxGuest to make a connect to the clipboard service.
353 * @todo Seems this is no longer is use. Try remove it. */
354# define VBOXGUEST_IOCTL_CLIPBOARD_CONNECT VBOXGUEST_IOCTL_CODE_(19, sizeof(uint32_t))
355
356#endif /* VBOX_WITH_HGCM */
357
358
359#ifdef RT_OS_OS2
360
361/**
362 * The data buffer layout for the IDC entry point (AttachDD).
363 *
364 * @remark This is defined in multiple 16-bit headers / sources.
365 * Some places it's called VBGOS2IDC to short things a bit.
366 */
367typedef struct VBOXGUESTOS2IDCCONNECT
368{
369 /** VMMDEV_VERSION. */
370 uint32_t u32Version;
371 /** Opaque session handle. */
372 uint32_t u32Session;
373
374 /**
375 * The 32-bit service entry point.
376 *
377 * @returns VBox status code.
378 * @param u32Session The above session handle.
379 * @param iFunction The requested function.
380 * @param pvData The input/output data buffer. The caller ensures that this
381 * cannot be swapped out, or that it's acceptable to take a
382 * page in fault in the current context. If the request doesn't
383 * take input or produces output, apssing NULL is okay.
384 * @param cbData The size of the data buffer.
385 * @param pcbDataReturned Where to store the amount of data that's returned.
386 * This can be NULL if pvData is NULL.
387 */
388 DECLCALLBACKMEMBER(int, pfnServiceEP)(uint32_t u32Session, unsigned iFunction, void *pvData, size_t cbData, size_t *pcbDataReturned);
389
390 /** The 16-bit service entry point for C code (cdecl).
391 *
392 * It's the same as the 32-bit entry point, but the types has
393 * changed to 16-bit equivalents.
394 *
395 * @code
396 * int far cdecl
397 * VBoxGuestOs2IDCService16(uint32_t u32Session, uint16_t iFunction,
398 * void far *fpvData, uint16_t cbData, uint16_t far *pcbDataReturned);
399 * @endcode
400 */
401 RTFAR16 fpfnServiceEP;
402
403 /** The 16-bit service entry point for Assembly code (register).
404 *
405 * This is just a wrapper around fpfnServiceEP to simplify calls
406 * from 16-bit assembly code.
407 *
408 * @returns (e)ax: VBox status code; cx: The amount of data returned.
409 *
410 * @param u32Session eax - The above session handle.
411 * @param iFunction dl - The requested function.
412 * @param pvData es:bx - The input/output data buffer.
413 * @param cbData cx - The size of the data buffer.
414 */
415 RTFAR16 fpfnServiceAsmEP;
416} VBOXGUESTOS2IDCCONNECT;
417/** Pointer to VBOXGUESTOS2IDCCONNECT buffer. */
418typedef VBOXGUESTOS2IDCCONNECT *PVBOXGUESTOS2IDCCONNECT;
419
420/** OS/2 specific: IDC client disconnect request.
421 *
422 * This takes no input and it doesn't return anything. Obviously this
423 * is only recognized if it arrives thru the IDC service EP.
424 */
425# define VBOXGUEST_IOCTL_OS2_IDC_DISCONNECT VBOXGUEST_IOCTL_CODE(48, sizeof(uint32_t))
426
427#endif /* RT_OS_OS2 */
428
429/** @} */
430#endif /* !defined(IN_RC) && !defined(IN_RING0_AGNOSTIC) && !defined(IPRT_NO_CRT) */
431
432
433#ifdef IN_RING3
434# include <VBox/VBoxGuestLib.h> /** @todo eliminate this. */
435#endif /* IN_RING3 */
436
437#endif
438
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