VBoxGuestLib.h revision c5dcc851f65b0d1a63e37d75c84a17403e77b3ba
/** @file
* VBoxGuestLib - VirtualBox Guest Additions Library.
*/
/*
* Copyright (C) 2006-2009 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
#ifndef ___VBox_VBoxGuestLib_h
#define ___VBox_VBoxGuestLib_h
#ifdef IN_RING0
# include <VBox/VBoxGuest2.h>
#endif
/** @defgroup grp_guest_lib VirtualBox Guest Additions Library
* @{
*/
/** @page pg_guest_lib VirtualBox Guest Library
*
* This is a library for abstracting the additions driver interface. There are
* multiple versions of the library depending on the context. The main
* distinction is between kernel and user mode where the interfaces are very
* different.
*
*
* @section sec_guest_lib_ring0 Ring-0
*
* In ring-0 there are two version:
* - VBOX_LIB_VBGL_R0_BASE / VBoxGuestR0LibBase for the VBoxGuest main driver,
* who is responsible for managing the VMMDev virtual hardware.
* - VBOX_LIB_VBGL_R0 / VBoxGuestR0Lib for other (client) guest drivers.
*
*
* The library source code and the header have a define VBGL_VBOXGUEST, which is
* defined for VBoxGuest and undefined for other drivers. Drivers must choose
* right library in their makefiles and set VBGL_VBOXGUEST accordingly.
*
* The libraries consists of:
* - common code to be used by both VBoxGuest and other drivers;
* - VBoxGuest specific code;
* - code for other drivers which communicate with VBoxGuest via an IOCTL.
*
*
* @section sec_guest_lib_ring3 Ring-3
*
* There are more variants of the library here:
* - VBOX_LIB_VBGL_R3 / VBoxGuestR3Lib for programs.
* - VBOX_LIB_VBGL_R3_XFREE86 / VBoxGuestR3LibXFree86 for old style XFree
* drivers which uses special loader and or symbol resolving strategy.
* - VBOX_LIB_VBGL_R3_SHARED / VBoxGuestR3LibShared for shared objects / DLLs /
* Dylibs.
*
*/
/** @defgroup grp_guest_lib_r0 Ring-0 interface.
* @{
*/
#if defined(IN_RING0) && !defined(IN_RING0_AGNOSTIC)
/** @def DECLR0VBGL
* Declare a VBGL ring-0 API with the right calling convention and visibilitiy.
* @param type Return type. */
# ifdef VBGL_VBOXGUEST
/**
* The library initialization function to be used by the main
* VBoxGuest system driver.
*
* @return VBox status code.
*/
# else
/**
* The library initialization function to be used by all drivers
* other than the main VBoxGuest system driver.
*
* @return VBox status code.
*/
# endif
/**
* The library termination function.
*/
DECLVBGL(void) VbglTerminate (void);
/** @name Generic request functions.
* @{
*/
/**
* Allocate memory for generic request and initialize the request header.
*
* @param ppReq pointer to resulting memory address.
* @param cbSize size of memory block required for the request.
* @param reqType the generic request type.
*
* @return VBox status code.
*/
DECLVBGL(int) VbglGRAlloc (VMMDevRequestHeader **ppReq, uint32_t cbSize, VMMDevRequestType reqType);
/**
* Perform the generic request.
*
* @param pReq pointer the request structure.
*
* @return VBox status code.
*/
/**
* Free the generic request memory.
*
* @param pReq pointer the request structure.
*
* @return VBox status code.
*/
/**
* Verify the generic request header.
*
* @param pReq pointer the request header structure.
* @param cbReq size of the request memory block. It should be equal to the request size
* for fixed size requests. It can be greater than the request size for
* variable size requests.
*
* @return VBox status code.
*/
/** @} */
# ifdef VBOX_WITH_HGCM
# ifdef VBGL_VBOXGUEST
/**
* Callback function called from HGCM helpers when a wait for request
* completion IRQ is required.
*
* @returns VINF_SUCCESS, VERR_INTERRUPT or VERR_TIMEOUT.
* @param pvData VBoxGuest pointer to be passed to callback.
* @param u32Data VBoxGuest 32 bit value to be passed to callback.
*/
typedef DECLVBGL(int) FNVBGLHGCMCALLBACK(VMMDevHGCMRequestHeader *pHeader, void *pvData, uint32_t u32Data);
/** Pointer to a FNVBGLHGCMCALLBACK. */
typedef FNVBGLHGCMCALLBACK *PFNVBGLHGCMCALLBACK;
/**
* Perform a connect request. That is locate required service and
* obtain a client identifier for future access.
*
* @note This function can NOT handle cancelled requests!
*
* @param pConnectInfo The request data.
* @param pfnAsyncCallback Required pointer to function that is calledwhen
* host returns VINF_HGCM_ASYNC_EXECUTE. VBoxGuest
* implements waiting for an IRQ in this function.
* @param pvAsyncData An arbitrary VBoxGuest pointer to be passed to callback.
* @param u32AsyncData An arbitrary VBoxGuest 32 bit value to be passed to callback.
*
* @return VBox status code.
*/
/**
* Perform a disconnect request. That is tell the host that
* the client will not call the service anymore.
*
* @note This function can NOT handle cancelled requests!
*
* @param pDisconnectInfo The request data.
* @param pfnAsyncCallback Required pointer to function that is called when
* host returns VINF_HGCM_ASYNC_EXECUTE. VBoxGuest
* implements waiting for an IRQ in this function.
* @param pvAsyncData An arbitrary VBoxGuest pointer to be passed to callback.
* @param u32AsyncData An arbitrary VBoxGuest 32 bit value to be passed to
* callback.
*
* @return VBox status code.
*/
/** Call a HGCM service.
*
* @note This function can deal with cancelled requests.
*
* @param pCallInfo The request data.
* @param fFlags Flags, see VBGLR0_HGCMCALL_F_XXX.
* @param pfnAsyncCallback Required pointer to function that is called when
* host returns VINF_HGCM_ASYNC_EXECUTE. VBoxGuest
* implements waiting for an IRQ in this function.
* @param pvAsyncData An arbitrary VBoxGuest pointer to be passed to callback.
* @param u32AsyncData An arbitrary VBoxGuest 32 bit value to be passed to callback.
*
* @return VBox status code.
*/
DECLR0VBGL(int) VbglR0HGCMInternalCall (VBoxGuestHGCMCallInfo *pCallInfo, uint32_t cbCallInfo, uint32_t fFlags,
/** Call a HGCM service. (32 bits packet structure in a 64 bits guest)
*
* @note This function can deal with cancelled requests.
*
* @param pCallInfo The request data.
* @param fFlags Flags, see VBGLR0_HGCMCALL_F_XXX.
* @param pfnAsyncCallback Required pointer to function that is called when
* host returns VINF_HGCM_ASYNC_EXECUTE. VBoxGuest
* implements waiting for an IRQ in this function.
* @param pvAsyncData An arbitrary VBoxGuest pointer to be passed to callback.
* @param u32AsyncData An arbitrary VBoxGuest 32 bit value to be passed to callback.
*
* @return VBox status code.
*/
DECLR0VBGL(int) VbglR0HGCMInternalCall32 (VBoxGuestHGCMCallInfo *pCallInfo, uint32_t cbCallInfo, uint32_t fFlags,
/** @name VbglR0HGCMInternalCall flags
* @{ */
/** User mode request.
* Indicates that only user mode addresses are permitted as parameters. */
#define VBGLR0_HGCMCALL_F_USER UINT32_C(0)
/** Kernel mode request.
* Indicates that kernel mode addresses are permitted as parameters. Whether or
* not user mode addresses are permitted is, unfortunately, OS specific. The
* following OSes allows user mode addresses: Windows, TODO.
*/
/** Mode mask. */
/** @} */
# else /* !VBGL_VBOXGUEST */
struct VBGLHGCMHANDLEDATA;
typedef struct VBGLHGCMHANDLEDATA *VBGLHGCMHANDLE;
/** @name HGCM functions
* @{
*/
/**
* Connect to a service.
*
* @param pHandle Pointer to variable that will hold a handle to be used
* further in VbglHGCMCall and VbglHGCMClose.
* @param pData Connection information structure.
*
* @return VBox status code.
*/
/**
* Connect to a service.
*
* @param handle Handle of the connection.
* @param pData Disconnect request information structure.
*
* @return VBox status code.
*/
/**
* Call to a service.
*
* @param handle Handle of the connection.
* @param pData Call request information structure, including function parameters.
* @param cbData Length in bytes of data.
*
* @return VBox status code.
*/
/**
* Call to a service with timeout.
*
* @param handle Handle of the connection.
* @param pData Call request information structure, including function parameters.
* @param cbData Length in bytes of data.
* @param cMillies Timeout in milliseconds. Use RT_INDEFINITE_WAIT to wait forever.
*
* @return VBox status code.
*/
/** @} */
# endif /* !VBGL_VBOXGUEST */
# endif /* VBOX_WITH_HGCM */
/**
* Initialize the heap.
*
* @return VBox error code.
*/
DECLVBGL(int) VbglPhysHeapInit (void);
/**
* Shutdown the heap.
*/
DECLVBGL(void) VbglPhysHeapTerminate (void);
/**
* Allocate a memory block.
*
* @param cbSize Size of block to be allocated.
* @return Virtual address of allocated memory block.
*/
/**
* Get physical address of memory block pointed by
* the virtual address.
*
* @note WARNING!
* The function does not acquire the Heap mutex!
* When calling the function make sure that
* the pointer is a valid one and is not being
* deallocated.
* This function can NOT be used for verifying
* if the given pointer is a valid one allocated
* from the heap.
*
*
* @param p Virtual address of memory block.
* @return Physical memory block.
*/
/**
* Free a memory block.
*
* @param p Virtual address of memory block.
*/
DECLVBGL(void) VbglPhysHeapFree (void *p);
DECLR0VBGL(bool) VbglR0CanUsePhysPageList(void);
#endif /* IN_RING0 && !IN_RING0_AGNOSTIC */
/** @} */
/** @defgroup grp_guest_lib_r3 Ring-3 interface.
* @{
*/
#ifdef IN_RING3
/** @def VBGLR3DECL
* Ring 3 VBGL declaration.
* @param type The return type of the function declaration.
*/
/** @name General-purpose functions
* @{ */
VBGLR3DECL(int) VbglR3Init(void);
VBGLR3DECL(int) VbglR3InitUser(void);
VBGLR3DECL(void) VbglR3Term(void);
# ifdef ___iprt_time_h
# endif
VBGLR3DECL(int) VbglR3InterruptEventWaits(void);
/** @} */
/** @name Shared clipboard
* @{ */
VBGLR3DECL(int) VbglR3ClipboardGetHostMsg(uint32_t u32ClientId, uint32_t *pMsg, uint32_t *pfFormats);
VBGLR3DECL(int) VbglR3ClipboardReadData(uint32_t u32ClientId, uint32_t fFormat, void *pv, uint32_t cb, uint32_t *pcb);
VBGLR3DECL(int) VbglR3ClipboardWriteData(uint32_t u32ClientId, uint32_t fFormat, void *pv, uint32_t cb);
/** @} */
/** @name Seamless mode
* @{ */
/** @} */
/** @name Mouse
* @{ */
/** @} */
/** @name Video
* @{ */
VBGLR3DECL(int) VbglR3VideoAccelFlush(void);
VBGLR3DECL(int) VbglR3SetPointerShape(uint32_t fFlags, uint32_t xHot, uint32_t yHot, uint32_t cx, uint32_t cy, const void *pvImg, size_t cbImg);
/** @} */
/** @name Display
* @{ */
VBGLR3DECL(int) VbglR3GetDisplayChangeRequest(uint32_t *pcx, uint32_t *pcy, uint32_t *pcBits, uint32_t *piDisplay, bool fAck);
VBGLR3DECL(int) VbglR3RetrieveVideoMode(const char *pszName, uint32_t *pcx, uint32_t *pcy, uint32_t *pcBits);
/** @} */
/** @name VM Statistics
* @{ */
/** @} */
/** @name Memory ballooning
* @{ */
/** @} */
# ifdef VBOX_WITH_GUEST_PROPS
/** @name Guest properties
* @{ */
/** @todo Docs. */
typedef struct VBGLR3GUESTPROPENUM VBGLR3GUESTPROPENUM;
/** @todo Docs. */
typedef VBGLR3GUESTPROPENUM *PVBGLR3GUESTPROPENUM;
VBGLR3DECL(int) VbglR3GuestPropWrite(uint32_t u32ClientId, const char *pszName, const char *pszValue, const char *pszFlags);
VBGLR3DECL(int) VbglR3GuestPropWriteValue(uint32_t u32ClientId, const char *pszName, const char *pszValue);
VBGLR3DECL(int) VbglR3GuestPropWriteValueV(uint32_t u32ClientId, const char *pszName, const char *pszValueFormat, va_list va);
VBGLR3DECL(int) VbglR3GuestPropWriteValueF(uint32_t u32ClientId, const char *pszName, const char *pszValueFormat, ...);
VBGLR3DECL(int) VbglR3GuestPropRead(uint32_t u32ClientId, const char *pszName, void *pvBuf, uint32_t cbBuf, char **ppszValue, uint64_t *pu64Timestamp, char **ppszFlags, uint32_t *pcbBufActual);
VBGLR3DECL(int) VbglR3GuestPropReadValue(uint32_t ClientId, const char *pszName, char *pszValue, uint32_t cchValue, uint32_t *pcchValueActual);
VBGLR3DECL(int) VbglR3GuestPropReadValueAlloc(uint32_t u32ClientId, const char *pszName, char **ppszValue);
VBGLR3DECL(int) VbglR3GuestPropEnumRaw(uint32_t u32ClientId, const char *paszPatterns, char *pcBuf, uint32_t cbBuf, uint32_t *pcbBufActual);
VBGLR3DECL(int) VbglR3GuestPropEnum(uint32_t u32ClientId, char const * const *ppaszPatterns, uint32_t cPatterns, PVBGLR3GUESTPROPENUM *ppHandle,
VBGLR3DECL(int) VbglR3GuestPropEnumNext(PVBGLR3GUESTPROPENUM pHandle, char const **ppszName, char const **ppszValue, uint64_t *pu64Timestamp,
char const **ppszFlags);
VBGLR3DECL(int) VbglR3GuestPropDelSet(uint32_t u32ClientId, char const * const *papszPatterns, uint32_t cPatterns);
VBGLR3DECL(int) VbglR3GuestPropWait(uint32_t u32ClientId, const char *pszPatterns, void *pvBuf, uint32_t cbBuf, uint64_t u64Timestamp, uint32_t cMillies, char ** ppszName, char **ppszValue, uint64_t *pu64Timestamp, char **ppszFlags, uint32_t *pcbBufActual);
/** @} */
/** @name Host version handling
* @{ */
VBGLR3DECL(int) VbglR3HostVersionCheckForUpdate(uint32_t u32ClientId, bool *pfUpdate, char **ppszHostVersion, char **ppszGuestVersion);
/** @} */
# endif /* VBOX_WITH_GUEST_PROPS defined */
/** @name Guest control
* @{ */
/** @} */
/** @name User credentials handling
* @{ */
VBGLR3DECL(int) VbglR3CredentialsQueryAvailability(void);
VBGLR3DECL(void) VbglR3CredentialsDestroy(char *pszUser, char *pszPassword, char *pszDomain, uint32_t cPasses);
/** @} */
/** @name CPU hotplug monitor
* @{ */
VBGLR3DECL(int) VbglR3CpuHotPlugInit(void);
VBGLR3DECL(int) VbglR3CpuHotPlugTerm(void);
VBGLR3DECL(int) VbglR3CpuHotPlugWaitForEvent(VMMDevCpuEventType *penmEventType, uint32_t *pidCpuCore, uint32_t *pidCpuPackage);
/** @} */
#endif /* IN_RING3 */
/** @} */
/** @} */
#endif