VirtualBox

source: vbox/trunk/include/VBox/VBoxGuestLib.h@ 21456

Last change on this file since 21456 was 21456, checked in by vboxsync, 15 years ago

HGCM&Co: physical page list.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 17.3 KB
Line 
1/** @file
2 * VBoxGuestLib - VirtualBox Guest Additions Library.
3 */
4
5/*
6 * Copyright (C) 2006-2009 Sun Microsystems, Inc.
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 *
25 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
26 * Clara, CA 95054 USA or visit http://www.sun.com if you need
27 * additional information or have any questions.
28 */
29
30#ifndef ___VBox_VBoxGuestLib_h
31#define ___VBox_VBoxGuestLib_h
32
33#include <VBox/types.h>
34#include <VBox/VMMDev2.h>
35#ifdef IN_RING0
36# include <VBox/VMMDev.h> /* grumble */
37# include <VBox/VBoxGuest2.h>
38#endif
39
40
41/** @defgroup grp_guest_lib VirtualBox Guest Additions Library
42 * @{
43 */
44
45/** @page pg_guest_lib VirtualBox Guest Library
46 *
47 * This is a library for abstracting the additions driver interface. There are
48 * multiple versions of the library depending on the context. The main
49 * distinction is between kernel and user mode where the interfaces are very
50 * different.
51 *
52 *
53 * @section sec_guest_lib_ring0 Ring-0
54 *
55 * In ring-0 there are two version:
56 * - VBOX_LIB_VBGL_R0_BASE / VBoxGuestR0LibBase for the VBoxGuest main driver,
57 * who is responsible for managing the VMMDev virtual hardware.
58 * - VBOX_LIB_VBGL_R0 / VBoxGuestR0Lib for other (client) guest drivers.
59 *
60 *
61 * The library source code and the header have a define VBGL_VBOXGUEST, which is
62 * defined for VBoxGuest and undefined for other drivers. Drivers must choose
63 * right library in their makefiles and set VBGL_VBOXGUEST accordingly.
64 *
65 * The libraries consists of:
66 * - common code to be used by both VBoxGuest and other drivers;
67 * - VBoxGuest specific code;
68 * - code for other drivers which communicate with VBoxGuest via an IOCTL.
69 *
70 *
71 * @section sec_guest_lib_ring3 Ring-3
72 *
73 * There are more variants of the library here:
74 * - VBOX_LIB_VBGL_R3 / VBoxGuestR3Lib for programs.
75 * - VBOX_LIB_VBGL_R3_XFREE86 / VBoxGuestR3LibXFree86 for old style XFree
76 * drivers which uses special loader and or symbol resolving strategy.
77 * - VBOX_LIB_VBGL_R3_SHARED / VBoxGuestR3LibShared for shared objects / DLLs /
78 * Dylibs.
79 *
80 */
81
82RT_C_DECLS_BEGIN
83
84
85/** @defgroup grp_guest_lib_r0 Ring-0 interface.
86 * @{
87 */
88#if defined(IN_RING0) && !defined(IN_RING0_AGNOSTIC)
89/** @def DECLR0VBGL
90 * Declare a VBGL ring-0 API with the right calling convention and visibilitiy.
91 * @param type Return type. */
92# define DECLR0VBGL(type) type VBOXCALL
93# define DECLVBGL(type) DECLR0VBGL(type)
94
95typedef uint32_t VBGLIOPORT; /**< @todo r=bird: We have RTIOPORT (uint16_t) for this. */
96
97
98# ifdef VBGL_VBOXGUEST
99
100/**
101 * The library initialization function to be used by the main
102 * VBoxGuest system driver.
103 *
104 * @return VBox status code.
105 */
106DECLVBGL(int) VbglInit (VBGLIOPORT portVMMDev, struct VMMDevMemory *pVMMDevMemory);
107
108# else
109
110/**
111 * The library initialization function to be used by all drivers
112 * other than the main VBoxGuest system driver.
113 *
114 * @return VBox status code.
115 */
116DECLVBGL(int) VbglInit (void);
117
118# endif
119
120/**
121 * The library termination function.
122 */
123DECLVBGL(void) VbglTerminate (void);
124
125
126/** @name Generic request functions.
127 * @{
128 */
129
130/**
131 * Allocate memory for generic request and initialize the request header.
132 *
133 * @param ppReq pointer to resulting memory address.
134 * @param cbSize size of memory block required for the request.
135 * @param reqType the generic request type.
136 *
137 * @return VBox status code.
138 */
139DECLVBGL(int) VbglGRAlloc (VMMDevRequestHeader **ppReq, uint32_t cbSize, VMMDevRequestType reqType);
140
141/**
142 * Perform the generic request.
143 *
144 * @param pReq pointer the request structure.
145 *
146 * @return VBox status code.
147 */
148DECLVBGL(int) VbglGRPerform (VMMDevRequestHeader *pReq);
149
150/**
151 * Free the generic request memory.
152 *
153 * @param pReq pointer the request structure.
154 *
155 * @return VBox status code.
156 */
157DECLVBGL(void) VbglGRFree (VMMDevRequestHeader *pReq);
158/** @} */
159
160# ifdef VBOX_WITH_HGCM
161
162# ifdef VBGL_VBOXGUEST
163
164/**
165 * Callback function called from HGCM helpers when a wait for request
166 * completion IRQ is required.
167 *
168 * @param pvData VBoxGuest pointer to be passed to callback.
169 * @param u32Data VBoxGuest 32 bit value to be passed to callback.
170 */
171
172typedef DECLVBGL(void) VBGLHGCMCALLBACK(VMMDevHGCMRequestHeader *pHeader, void *pvData, uint32_t u32Data);
173
174/**
175 * Perform a connect request. That is locate required service and
176 * obtain a client identifier for future access.
177 *
178 * @note This function can NOT handle cancelled requests!
179 *
180 * @param pConnectInfo The request data.
181 * @param pAsyncCallback Required pointer to function that is called when
182 * host returns VINF_HGCM_ASYNC_EXECUTE. VBoxGuest
183 * implements waiting for an IRQ in this function.
184 * @param pvAsyncData An arbitrary VBoxGuest pointer to be passed to callback.
185 * @param u32AsyncData An arbitrary VBoxGuest 32 bit value to be passed to callback.
186 *
187 * @return VBox status code.
188 */
189
190DECLR0VBGL(int) VbglR0HGCMInternalConnect (VBoxGuestHGCMConnectInfo *pConnectInfo,
191 VBGLHGCMCALLBACK *pAsyncCallback, void *pvAsyncData, uint32_t u32AsyncData);
192
193
194/**
195 * Perform a disconnect request. That is tell the host that
196 * the client will not call the service anymore.
197 *
198 * @note This function can NOT handle cancelled requests!
199 *
200 * @param pDisconnectInfo The request data.
201 * @param pAsyncCallback Required pointer to function that is called when
202 * host returns VINF_HGCM_ASYNC_EXECUTE. VBoxGuest
203 * implements waiting for an IRQ in this function.
204 * @param pvAsyncData An arbitrary VBoxGuest pointer to be passed to callback.
205 * @param u32AsyncData An arbitrary VBoxGuest 32 bit value to be passed to callback.
206 *
207 * @return VBox status code.
208 */
209
210DECLR0VBGL(int) VbglR0HGCMInternalDisconnect (VBoxGuestHGCMDisconnectInfo *pDisconnectInfo,
211 VBGLHGCMCALLBACK *pAsyncCallback, void *pvAsyncData, uint32_t u32AsyncData);
212
213/** Call a HGCM service.
214 *
215 * @note This function can deal with cancelled requests.
216 *
217 * @param pCallInfo The request data.
218 * @param fFlags Flags, see VBGLR0_HGCMCALL_F_XXX.
219 * @param pAsyncCallback Required pointer to function that is called when
220 * host returns VINF_HGCM_ASYNC_EXECUTE. VBoxGuest
221 * implements waiting for an IRQ in this function.
222 * @param pvAsyncData An arbitrary VBoxGuest pointer to be passed to callback.
223 * @param u32AsyncData An arbitrary VBoxGuest 32 bit value to be passed to callback.
224 *
225 * @return VBox status code.
226 */
227DECLR0VBGL(int) VbglR0HGCMInternalCall (VBoxGuestHGCMCallInfo *pCallInfo, uint32_t cbCallInfo, uint32_t fFlags,
228 VBGLHGCMCALLBACK *pAsyncCallback, void *pvAsyncData, uint32_t u32AsyncData);
229
230/** Call a HGCM service. (32 bits packet structure in a 64 bits guest)
231 *
232 * @note This function can deal with cancelled requests.
233 *
234 * @param pCallInfo The request data.
235 * @param fFlags Flags, see VBGLR0_HGCMCALL_F_XXX.
236 * @param pAsyncCallback Required pointer to function that is called when
237 * host returns VINF_HGCM_ASYNC_EXECUTE. VBoxGuest
238 * implements waiting for an IRQ in this function.
239 * @param pvAsyncData An arbitrary VBoxGuest pointer to be passed to callback.
240 * @param u32AsyncData An arbitrary VBoxGuest 32 bit value to be passed to callback.
241 *
242 * @return VBox status code.
243 */
244DECLR0VBGL(int) VbglR0HGCMInternalCall32 (VBoxGuestHGCMCallInfo *pCallInfo, uint32_t cbCallInfo, uint32_t fFlags,
245 VBGLHGCMCALLBACK *pAsyncCallback, void *pvAsyncData, uint32_t u32AsyncData);
246
247/** @name VbglR0HGCMInternalCall flags
248 * @{ */
249/** User mode request.
250 * Indicates that only user mode addresses are permitted as parameters. */
251#define VBGLR0_HGCMCALL_F_USER UINT32_C(0)
252/** Kernel mode request.
253 * Indicates that kernel mode addresses are permitted as parameters. Whether or
254 * not user mode addresses are permitted is, unfortunately, OS specific. The
255 * following OSes allows user mode addresses: Windows, TODO.
256 */
257#define VBGLR0_HGCMCALL_F_KERNEL UINT32_C(1)
258/** Mode mask. */
259#define VBGLR0_HGCMCALL_F_MODE_MASK UINT32_C(1)
260/** @} */
261
262# else /* !VBGL_VBOXGUEST */
263
264struct VBGLHGCMHANDLEDATA;
265typedef struct VBGLHGCMHANDLEDATA *VBGLHGCMHANDLE;
266
267/** @name HGCM functions
268 * @{
269 */
270
271/**
272 * Connect to a service.
273 *
274 * @param pHandle Pointer to variable that will hold a handle to be used
275 * further in VbglHGCMCall and VbglHGCMClose.
276 * @param pData Connection information structure.
277 *
278 * @return VBox status code.
279 */
280DECLVBGL(int) VbglHGCMConnect (VBGLHGCMHANDLE *pHandle, VBoxGuestHGCMConnectInfo *pData);
281
282/**
283 * Connect to a service.
284 *
285 * @param handle Handle of the connection.
286 * @param pData Disconnect request information structure.
287 *
288 * @return VBox status code.
289 */
290DECLVBGL(int) VbglHGCMDisconnect (VBGLHGCMHANDLE handle, VBoxGuestHGCMDisconnectInfo *pData);
291
292/**
293 * Call to a service.
294 *
295 * @param handle Handle of the connection.
296 * @param pData Call request information structure, including function parameters.
297 * @param cbData Length in bytes of data.
298 *
299 * @return VBox status code.
300 */
301DECLVBGL(int) VbglHGCMCall (VBGLHGCMHANDLE handle, VBoxGuestHGCMCallInfo *pData, uint32_t cbData);
302
303/**
304 * Call to a service with timeout.
305 *
306 * @param handle Handle of the connection.
307 * @param pData Call request information structure, including function parameters.
308 * @param cbData Length in bytes of data.
309 * @param cMillies Timeout in milliseconds. Use RT_INDEFINITE_WAIT to wait forever.
310 *
311 * @return VBox status code.
312 */
313DECLVBGL(int) VbglHGCMCallTimed (VBGLHGCMHANDLE handle,
314 VBoxGuestHGCMCallInfoTimed *pData, uint32_t cbData);
315/** @} */
316
317# endif /* !VBGL_VBOXGUEST */
318
319# endif /* VBOX_WITH_HGCM */
320
321
322/**
323 * Initialize the heap.
324 *
325 * @return VBox error code.
326 */
327DECLVBGL(int) VbglPhysHeapInit (void);
328
329/**
330 * Shutdown the heap.
331 */
332DECLVBGL(void) VbglPhysHeapTerminate (void);
333
334
335/**
336 * Allocate a memory block.
337 *
338 * @param cbSize Size of block to be allocated.
339 * @return Virtual address of allocated memory block.
340 */
341DECLVBGL(void *) VbglPhysHeapAlloc (uint32_t cbSize);
342
343/**
344 * Get physical address of memory block pointed by
345 * the virtual address.
346 *
347 * @note WARNING!
348 * The function does not acquire the Heap mutex!
349 * When calling the function make sure that
350 * the pointer is a valid one and is not being
351 * deallocated.
352 * This function can NOT be used for verifying
353 * if the given pointer is a valid one allocated
354 * from the heap.
355 *
356 *
357 * @param p Virtual address of memory block.
358 * @return Physical memory block.
359 */
360DECLVBGL(RTCCPHYS) VbglPhysHeapGetPhysAddr (void *p);
361
362/**
363 * Free a memory block.
364 *
365 * @param p Virtual address of memory block.
366 */
367DECLVBGL(void) VbglPhysHeapFree (void *p);
368
369DECLVBGL(int) VbglQueryVMMDevMemory (VMMDevMemory **ppVMMDevMemory);
370
371#endif /* IN_RING0 && !IN_RING0_AGNOSTIC */
372/** @} */
373
374
375/** @defgroup grp_guest_lib_r3 Ring-3 interface.
376 * @{
377 */
378#ifdef IN_RING3
379
380/** @def VBGLR3DECL
381 * Ring 3 VBGL declaration.
382 * @param type The return type of the function declaration.
383 */
384# define VBGLR3DECL(type) type VBOXCALL
385
386/** @name General-purpose functions
387 * @{ */
388VBGLR3DECL(int) VbglR3Init(void);
389VBGLR3DECL(int) VbglR3InitUser(void);
390VBGLR3DECL(void) VbglR3Term(void);
391# ifdef ___iprt_time_h
392VBGLR3DECL(int) VbglR3GetHostTime(PRTTIMESPEC pTime);
393# endif
394VBGLR3DECL(int) VbglR3InterruptEventWaits(void);
395VBGLR3DECL(int) VbglR3WriteLog(const char *pch, size_t cb);
396VBGLR3DECL(int) VbglR3CtlFilterMask(uint32_t fOr, uint32_t fNot);
397VBGLR3DECL(int) VbglR3Daemonize(bool fNoChDir, bool fNoClose);
398VBGLR3DECL(int) VbglR3PidFile(const char *pszPath, PRTFILE phFile);
399VBGLR3DECL(void) VbglR3ClosePidFile(const char *pszPath, RTFILE hFile);
400VBGLR3DECL(int) VbglR3SetGuestCaps(uint32_t fOr, uint32_t fNot);
401/** @} */
402
403/** @name Shared clipboard
404 * @{ */
405VBGLR3DECL(int) VbglR3ClipboardConnect(uint32_t *pu32ClientId);
406VBGLR3DECL(int) VbglR3ClipboardDisconnect(uint32_t u32ClientId);
407VBGLR3DECL(int) VbglR3ClipboardGetHostMsg(uint32_t u32ClientId, uint32_t *pMsg, uint32_t *pfFormats);
408VBGLR3DECL(int) VbglR3ClipboardReadData(uint32_t u32ClientId, uint32_t fFormat, void *pv, uint32_t cb, uint32_t *pcb);
409VBGLR3DECL(int) VbglR3ClipboardReportFormats(uint32_t u32ClientId, uint32_t fFormats);
410VBGLR3DECL(int) VbglR3ClipboardWriteData(uint32_t u32ClientId, uint32_t fFormat, void *pv, uint32_t cb);
411/** @} */
412
413/** @name Seamless mode
414 * @{ */
415VBGLR3DECL(int) VbglR3SeamlessSetCap(bool fState);
416VBGLR3DECL(int) VbglR3SeamlessWaitEvent(VMMDevSeamlessMode *pMode);
417VBGLR3DECL(int) VbglR3SeamlessSendRects(uint32_t cRects, PRTRECT pRects);
418/** @} */
419
420/** @name Mouse
421 * @{ */
422VBGLR3DECL(int) VbglR3GetMouseStatus(uint32_t *pfFeatures, uint32_t *px, uint32_t *py);
423VBGLR3DECL(int) VbglR3SetMouseStatus(uint32_t fFeatures);
424/** @} */
425
426/** @name Video
427 * @{ */
428VBGLR3DECL(int) VbglR3VideoAccelEnable(bool fEnable);
429VBGLR3DECL(int) VbglR3VideoAccelFlush(void);
430VBGLR3DECL(int) VbglR3SetPointerShape(uint32_t fFlags, uint32_t xHot, uint32_t yHot, uint32_t cx, uint32_t cy, const void *pvImg, size_t cbImg);
431VBGLR3DECL(int) VbglR3SetPointerShapeReq(struct VMMDevReqMousePointer *pReq);
432/** @} */
433
434/** @name Display
435 * @{ */
436VBGLR3DECL(int) VbglR3GetLastDisplayChangeRequest(uint32_t *pcx, uint32_t *pcy, uint32_t *pcBits, uint32_t *piDisplay);
437VBGLR3DECL(int) VbglR3DisplayChangeWaitEvent(uint32_t *pcx, uint32_t *pcy, uint32_t *pcBits, uint32_t *piDisplay);
438VBGLR3DECL(bool) VbglR3HostLikesVideoMode(uint32_t cx, uint32_t cy, uint32_t cBits);
439VBGLR3DECL(int) VbglR3SaveVideoMode(const char *pszName, uint32_t cx, uint32_t cy, uint32_t cBits);
440VBGLR3DECL(int) VbglR3RetrieveVideoMode(const char *pszName, uint32_t *pcx, uint32_t *pcy, uint32_t *pcBits);
441/** @} */
442
443# ifdef VBOX_WITH_GUEST_PROPS
444/** @name Guest properties
445 * @{ */
446/** @todo Docs. */
447typedef struct VBGLR3GUESTPROPENUM VBGLR3GUESTPROPENUM;
448/** @todo Docs. */
449typedef VBGLR3GUESTPROPENUM *PVBGLR3GUESTPROPENUM;
450VBGLR3DECL(int) VbglR3GuestPropConnect(uint32_t *pu32ClientId);
451VBGLR3DECL(int) VbglR3GuestPropDisconnect(uint32_t u32ClientId);
452VBGLR3DECL(int) VbglR3GuestPropWrite(uint32_t u32ClientId, const char *pszName, const char *pszValue, const char *pszFlags);
453VBGLR3DECL(int) VbglR3GuestPropWriteValue(uint32_t u32ClientId, const char *pszName, const char *pszValue);
454VBGLR3DECL(int) VbglR3GuestPropWriteValueV(uint32_t u32ClientId, const char *pszName, const char *pszValueFormat, va_list va);
455VBGLR3DECL(int) VbglR3GuestPropWriteValueF(uint32_t u32ClientId, const char *pszName, const char *pszValueFormat, ...);
456VBGLR3DECL(int) VbglR3GuestPropRead(uint32_t u32ClientId, const char *pszName, void *pvBuf, uint32_t cbBuf, char **ppszValue, uint64_t *pu64Timestamp, char **ppszFlags, uint32_t *pcbBufActual);
457VBGLR3DECL(int) VbglR3GuestPropReadValue(uint32_t ClientId, const char *pszName, char *pszValue, uint32_t cchValue, uint32_t *pcchValueActual);
458VBGLR3DECL(int) VbglR3GuestPropReadValueAlloc(uint32_t u32ClientId, const char *pszName, char **ppszValue);
459VBGLR3DECL(void) VbglR3GuestPropReadValueFree(char *pszValue);
460VBGLR3DECL(int) VbglR3GuestPropEnumRaw(uint32_t u32ClientId, const char *paszPatterns, char *pcBuf, uint32_t cbBuf, uint32_t *pcbBufActual);
461VBGLR3DECL(int) VbglR3GuestPropEnum(uint32_t u32ClientId, char const * const *ppaszPatterns, uint32_t cPatterns, PVBGLR3GUESTPROPENUM *ppHandle,
462 char const **ppszName, char const **ppszValue, uint64_t *pu64Timestamp, char const **ppszFlags);
463VBGLR3DECL(int) VbglR3GuestPropEnumNext(PVBGLR3GUESTPROPENUM pHandle, char const **ppszName, char const **ppszValue, uint64_t *pu64Timestamp,
464 char const **ppszFlags);
465VBGLR3DECL(void) VbglR3GuestPropEnumFree(PVBGLR3GUESTPROPENUM pHandle);
466VBGLR3DECL(int) VbglR3GuestPropDelSet(uint32_t u32ClientId, char const * const *papszPatterns, uint32_t cPatterns);
467VBGLR3DECL(int) VbglR3GuestPropWait(uint32_t u32ClientId, const char *pszPatterns, void *pvBuf, uint32_t cbBuf, uint64_t u64Timestamp, uint32_t u32Timeout, char ** ppszName, char **ppszValue, uint64_t *pu64Timestamp, char **ppszFlags, uint32_t *pcbBufActual);
468/** @} */
469# endif /* VBOX_WITH_GUEST_PROPS defined */
470
471#endif /* IN_RING3 */
472/** @} */
473
474RT_C_DECLS_END
475
476/** @} */
477
478#endif
479
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