HGSMI.h revision 32b1164f35483be483177be7b5235002a4a5afbe
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * VBox Host Guest Shared Memory Interface (HGSMI).
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * Host/Guest shared part.
47355efb636d69b667c1cef0f2fe826569b991b0vboxsync * Copyright (C) 2006-2014 Oracle Corporation
cf5f6bf2704d4fff443139e10bccc6a0a7fa4b85vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
cf5f6bf2704d4fff443139e10bccc6a0a7fa4b85vboxsync * available from http://www.virtualbox.org. This file is free software;
cf5f6bf2704d4fff443139e10bccc6a0a7fa4b85vboxsync * you can redistribute it and/or modify it under the terms of the GNU
cf5f6bf2704d4fff443139e10bccc6a0a7fa4b85vboxsync * General Public License (GPL) as published by the Free Software
cf5f6bf2704d4fff443139e10bccc6a0a7fa4b85vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
cf5f6bf2704d4fff443139e10bccc6a0a7fa4b85vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
cf5f6bf2704d4fff443139e10bccc6a0a7fa4b85vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
cf5f6bf2704d4fff443139e10bccc6a0a7fa4b85vboxsync * The contents of this file may alternatively be used under the terms
cf5f6bf2704d4fff443139e10bccc6a0a7fa4b85vboxsync * of the Common Development and Distribution License Version 1.0
cf5f6bf2704d4fff443139e10bccc6a0a7fa4b85vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
cf5f6bf2704d4fff443139e10bccc6a0a7fa4b85vboxsync * VirtualBox OSE distribution, in which case the provisions of the
cf5f6bf2704d4fff443139e10bccc6a0a7fa4b85vboxsync * CDDL are applicable instead of those of the GPL.
cf5f6bf2704d4fff443139e10bccc6a0a7fa4b85vboxsync * You may elect to license modified versions of this file under the
cf5f6bf2704d4fff443139e10bccc6a0a7fa4b85vboxsync * terms and conditions of either the GPL or the CDDL or both.
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * Basic mechanism for the HGSMI is to prepare and pass data buffer to the host and the guest.
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * Data inside these buffers are opaque for the HGSMI and are interpreted by higher levels.
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * Every shared memory buffer passed between the guest/host has the following structure:
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * HGSMIBUFFERHEADER header;
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * uint8_t data[header.u32BufferSize];
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * HGSMIBUFFERTAIL tail;
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * Note: Offset of the 'header' in the memory is used for virtual hardware IO.
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * Buffers are verifyed using the offset and the content of the header and the tail,
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * which are constant during a call.
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * Invalid buffers are ignored.
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * Actual 'data' is not verifyed, as it is expected that the data can be changed by the
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * called function.
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * Since only the offset of the buffer is passed in a IO operation, the header and tail
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * must contain:
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * * size of data in this buffer;
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * * checksum for buffer verification.
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * For segmented transfers:
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * * the sequence identifier;
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * * offset of the current segment in the sequence;
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * * total bytes in the transfer.
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * Additionally contains:
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * * the channel ID;
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * * the channel information.
32b1164f35483be483177be7b5235002a4a5afbevboxsync/* Heap types. */
32b1164f35483be483177be7b5235002a4a5afbevboxsync#define HGSMI_HEAP_TYPE_NULL 0 /* Heap not initialized. */
32b1164f35483be483177be7b5235002a4a5afbevboxsync#define HGSMI_HEAP_TYPE_POINTER 1 /* RTHEAPSIMPLE. Obsolete. */
32b1164f35483be483177be7b5235002a4a5afbevboxsync#define HGSMI_HEAP_TYPE_OFFSET 2 /* RTHEAPOFFSET. Obsolete. */
32b1164f35483be483177be7b5235002a4a5afbevboxsync#define HGSMI_HEAP_TYPE_MA 3 /* Memory allocator. */
32b1164f35483be483177be7b5235002a4a5afbevboxsynctypedef struct HGSMIHEAP
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync/* The size of the array of channels. Array indexes are uint8_t. Note: the value must not be changed. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync/* Channel handler called when the guest submits a buffer. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsynctypedef DECLCALLBACK(int) FNHGSMICHANNELHANDLER(void *pvHandler, uint16_t u16ChannelInfo, void *pvBuffer, HGSMISIZE cbBuffer);
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsynctypedef FNHGSMICHANNELHANDLER *PFNHGSMICHANNELHANDLER;
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync/* Information about a handler: pfn + context. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync/* Channel description. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync HGSMICHANNELHANDLER handler; /* The channel handler. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync const char *pszName; /* NULL for hardcoded channels or RTStrDup'ed name. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync uint8_t u8Channel; /* The channel id, equal to the channel index in the array. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync HGSMICHANNEL Channels[HGSMI_NUMBER_OF_CHANNELS]; /* Channel handlers indexed by the channel id.
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * The array is accessed under the instance lock.
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync return sizeof (HGSMIBUFFERHEADER) + sizeof (HGSMIBUFFERTAIL);
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncDECLINLINE(uint8_t *) HGSMIBufferData (const HGSMIBUFFERHEADER *pHeader)
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync return (uint8_t *)pHeader + sizeof (HGSMIBUFFERHEADER);
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncDECLINLINE(HGSMIBUFFERTAIL *) HGSMIBufferTail (const HGSMIBUFFERHEADER *pHeader)
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync return (HGSMIBUFFERTAIL *)(HGSMIBufferData (pHeader) + pHeader->u32DataSize);
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncDECLINLINE(HGSMIBUFFERHEADER *) HGSMIBufferHeaderFromData (const void *pvData)
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync return (HGSMIBUFFERHEADER *)((uint8_t *)pvData - sizeof (HGSMIBUFFERHEADER));
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncDECLINLINE(HGSMISIZE) HGSMIBufferRequiredSize (uint32_t u32DataSize)
32b1164f35483be483177be7b5235002a4a5afbevboxsyncDECLINLINE(HGSMIOFFSET) HGSMIPointerToOffset(const HGSMIAREA *pArea,
32b1164f35483be483177be7b5235002a4a5afbevboxsync const void *pv)
32b1164f35483be483177be7b5235002a4a5afbevboxsync return pArea->offBase + (HGSMIOFFSET)((uint8_t *)pv - pArea->pu8Base);
32b1164f35483be483177be7b5235002a4a5afbevboxsyncDECLINLINE(void *) HGSMIOffsetToPointer(const HGSMIAREA *pArea,
32b1164f35483be483177be7b5235002a4a5afbevboxsync return pArea->pu8Base + (offBuffer - pArea->offBase);
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncDECLINLINE(uint8_t *) HGSMIBufferDataFromOffset (const HGSMIAREA *pArea, HGSMIOFFSET offBuffer)
32b1164f35483be483177be7b5235002a4a5afbevboxsync HGSMIBUFFERHEADER *pHeader = (HGSMIBUFFERHEADER *)HGSMIOffsetToPointer(pArea, offBuffer);
85e5ab5adbba74b522731762dd05ca88cb529140vboxsyncDECLINLINE(uint8_t *) HGSMIBufferDataAndChInfoFromOffset (const HGSMIAREA *pArea, HGSMIOFFSET offBuffer, uint16_t * pChInfo)
32b1164f35483be483177be7b5235002a4a5afbevboxsync HGSMIBUFFERHEADER *pHeader = (HGSMIBUFFERHEADER *)HGSMIOffsetToPointer (pArea, offBuffer);
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncHGSMICHANNEL *HGSMIChannelFindById (HGSMICHANNELINFO * pChannelInfo, uint8_t u8Channel);
32b1164f35483be483177be7b5235002a4a5afbevboxsyncDECLINLINE(bool) HGSMIAreaContainsOffset(const HGSMIAREA *pArea, HGSMIOFFSET off)
32b1164f35483be483177be7b5235002a4a5afbevboxsync return off >= pArea->offBase && off - pArea->offBase < pArea->cbArea;
32b1164f35483be483177be7b5235002a4a5afbevboxsyncDECLINLINE(bool) HGSMIAreaContainsPointer(const HGSMIAREA *pArea, const void *pv)
32b1164f35483be483177be7b5235002a4a5afbevboxsync return (uintptr_t)pv >= (uintptr_t)pArea->pu8Base && (uintptr_t)pv - (uintptr_t)pArea->pu8Base < pArea->cbArea;
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncHGSMIOFFSET HGSMIBufferInitializeSingle (const HGSMIAREA *pArea,
32b1164f35483be483177be7b5235002a4a5afbevboxsyncvoid HGSMIHeapSetupUninitialized (HGSMIHEAP *pHeap);
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncHGSMIOFFSET HGSMIHeapBufferOffset (HGSMIHEAP *pHeap,
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncDECLINLINE(HGSMIOFFSET) HGSMIHeapOffset(HGSMIHEAP *pHeap)
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync/* needed for heap relocation */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncDECLINLINE(HGSMIOFFSET) HGSMIHeapHandleLocationOffset(HGSMIHEAP *pHeap)
8fa7c8ea1fd9355ab51e7592aff6c1ae0836dcbfvboxsync /* does not work with gcc-4.5 */
8fa7c8ea1fd9355ab51e7592aff6c1ae0836dcbfvboxsync AssertCompile((uintptr_t)NIL_RTHEAPSIMPLE == (uintptr_t)NIL_RTHEAPOFFSET);
8f1c8e96fab0c5f5a8dcabeb4e20a56a8b4cea18vboxsync ? (HGSMIOFFSET)(pHeap->area.pu8Base - (uint8_t*)pHeap->u.hPtr)
7420e5ee5565b181c144eabb14da0da9e8cce657vboxsync#endif /* IN_RING3 */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncDECLINLINE(HGSMISIZE) HGSMIHeapSize(HGSMIHEAP *pHeap)
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncint HGSMIChannelRegister (HGSMICHANNELINFO * pChannelInfo,
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync const char *pszName,
7420e5ee5565b181c144eabb14da0da9e8cce657vboxsync#endif /* !___VBox_HGSMI_HGSMI_h */