SUPDrvInternal.h revision 9888fffcfbe2d41dce14a1249b12cb88cc9b149f
5b281ba489ca18f0380d7efc7a5108b606cce449vboxsync * VirtualBox Support Driver - Internal header.
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * Copyright (C) 2006-2014 Oracle Corporation
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * available from http://www.virtualbox.org. This file is free software;
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * you can redistribute it and/or modify it under the terms of the GNU
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * General Public License (GPL) as published by the Free Software
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * The contents of this file may alternatively be used under the terms
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * of the Common Development and Distribution License Version 1.0
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * VirtualBox OSE distribution, in which case the provisions of the
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * CDDL are applicable instead of those of the GPL.
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * You may elect to license modified versions of this file under the
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * terms and conditions of either the GPL or the CDDL or both.
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync/*******************************************************************************
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync* Header Files *
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync*******************************************************************************/
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync/* do nothing */
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync# if (_MSC_VER >= 1400) && !defined(VBOX_WITH_PATCHED_DDK)
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync# define _InterlockedExchange _InterlockedExchange_StupidDDKVsCompilerCrap
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync# define _InterlockedExchangeAdd _InterlockedExchangeAdd_StupidDDKVsCompilerCrap
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync# define _InterlockedCompareExchange _InterlockedCompareExchange_StupidDDKVsCompilerCrap
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync# define _InterlockedAddLargeStatistic _InterlockedAddLargeStatistic_StupidDDKVsCompilerCrap
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync# define _interlockedbittestandset _interlockedbittestandset_StupidDDKVsCompilerCrap
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync# define _interlockedbittestandreset _interlockedbittestandreset_StupidDDKVsCompilerCrap
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync# define _interlockedbittestandset64 _interlockedbittestandset64_StupidDDKVsCompilerCrap
3619a23ecce9ab8cdbf52dc55d9c7ff6e8ad7ccavboxsync# define _interlockedbittestandreset64 _interlockedbittestandreset64_StupidDDKVsCompilerCrap
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync# if defined(CONFIG_MODVERSIONS) && !defined(MODVERSIONS)
3619a23ecce9ab8cdbf52dc55d9c7ff6e8ad7ccavboxsync# define KBUILD_STR(s) #s
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync# else /* older kernels */
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync# endif /* older kernels */
fb27046b613e2b74e6e39910bd69bf35bd344652vboxsync# define memset libkern_memset /** @todo these are just hacks to get it compiling, check out later. */
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync/*******************************************************************************
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync* Defined Constants And Macros *
fb27046b613e2b74e6e39910bd69bf35bd344652vboxsync*******************************************************************************/
3619a23ecce9ab8cdbf52dc55d9c7ff6e8ad7ccavboxsync * Hardcoded cookies.
3619a23ecce9ab8cdbf52dc55d9c7ff6e8ad7ccavboxsync/** Use a normal mutex for the loader so we remain at the same IRQL after
fb27046b613e2b74e6e39910bd69bf35bd344652vboxsync * taking it.
3619a23ecce9ab8cdbf52dc55d9c7ff6e8ad7ccavboxsync * @todo fix the mutex implementation on linux and make this the default. */
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync/** Use a normal mutex for the GIP so we remain at the same IRQL after
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * taking it.
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * @todo fix the mutex implementation on linux and make this the default. */
fb27046b613e2b74e6e39910bd69bf35bd344652vboxsync * OS debug print macro.
3619a23ecce9ab8cdbf52dc55d9c7ff6e8ad7ccavboxsync/** Debug printf macro shared with the ring-3 part. */
3619a23ecce9ab8cdbf52dc55d9c7ff6e8ad7ccavboxsync# define SUP_DPRINTF(a) do { } while (0)
fb27046b613e2b74e6e39910bd69bf35bd344652vboxsync/** @name Context values for the per-session handle tables.
fb27046b613e2b74e6e39910bd69bf35bd344652vboxsync * The context value is used to distinguish between the different kinds of
fb27046b613e2b74e6e39910bd69bf35bd344652vboxsync * handles, making the handle table API do all the work.
fb27046b613e2b74e6e39910bd69bf35bd344652vboxsync/** Handle context value for single release event handles. */
3619a23ecce9ab8cdbf52dc55d9c7ff6e8ad7ccavboxsync#define SUPDRV_HANDLE_CTX_EVENT ((void *)(uintptr_t)(SUPDRVOBJTYPE_SEM_EVENT))
3619a23ecce9ab8cdbf52dc55d9c7ff6e8ad7ccavboxsync/** Handle context value for multiple release event handles. */
fb27046b613e2b74e6e39910bd69bf35bd344652vboxsync#define SUPDRV_HANDLE_CTX_EVENT_MULTI ((void *)(uintptr_t)(SUPDRVOBJTYPE_SEM_EVENT_MULTI))
3619a23ecce9ab8cdbf52dc55d9c7ff6e8ad7ccavboxsync * Validates a session pointer.
3619a23ecce9ab8cdbf52dc55d9c7ff6e8ad7ccavboxsync * @returns true/false accordingly.
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * @param pSession The session.
3619a23ecce9ab8cdbf52dc55d9c7ff6e8ad7ccavboxsync * Validates a device extension pointer.
fb27046b613e2b74e6e39910bd69bf35bd344652vboxsync * @returns true/false accordingly.
fb27046b613e2b74e6e39910bd69bf35bd344652vboxsync * @param pDevExt The device extension.
fb27046b613e2b74e6e39910bd69bf35bd344652vboxsync/** @def SUPDRV_WITH_MSR_PROBER
fb27046b613e2b74e6e39910bd69bf35bd344652vboxsync * Enables the SUP_IOCTL_MSR_PROBER function.
3619a23ecce9ab8cdbf52dc55d9c7ff6e8ad7ccavboxsync * By default, only enabled in DEBUG builds as it's a sensitive feature.
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync#if defined(DEBUG) && !defined(SUPDRV_WITH_MSR_PROBER) && !defined(SUPDRV_WITHOUT_MSR_PROBER)
#ifdef SUPDRV_WITHOUT_MSR_PROBER
#define SUPDRV_USE_TSC_DELTA_THREAD
#ifdef SUPDRV_USE_TSC_DELTA_THREAD
typedef enum SUPDRVTSCDELTATHREADSTATE
/** Uninitialized/invalid value. */
MEMREF_TYPE_UNUSED = 0,
typedef struct SUPDRVMEMREF
typedef struct SUPDRVBUNDLE
typedef struct SUPDRVLDRIMAGE
void *pvImage;
void *pvImageAlloc;
char *pachStrTab;
#ifdef RT_OS_WINDOWS
void *pvNtSectionObj;
int idSolMod;
bool fNative;
typedef struct SUPDRVLDRUSAGE
typedef struct SUPDRVFACTORYREG
typedef struct SUPDRVOBJ
void *pvUser1;
void *pvUser2;
typedef struct SUPDRVUSAGE
typedef struct SUPDRVSESSION
bool fUnrestricted;
bool fInHashTable;
#ifndef SUPDRV_AGNOSTIC
# if defined(RT_OS_DARWIN)
void *pvSupDrvClient;
bool fOpened;
# if defined(RT_OS_OS2)
typedef union SUPTSCDELTASYNC
volatile uint32_t u;
typedef struct SUPDRVDEVEXT
#ifdef SUPDRV_USE_MUTEX_FOR_LDR
void * volatile pvVMMR0;
DECLR0CALLBACKMEMBER(int, pfnVMMR0EntryEx, (PVM pVM, VMCPUID idCpu, unsigned uOperation, PSUPVMMR0REQHDR pReq, uint64_t u64Arg, PSUPDRVSESSION pSession));
bool fLdrLockedDown;
#ifdef SUPDRV_USE_MUTEX_FOR_GIP
bool fTracerUnloading;
void *pvTscDeltaSync;
#ifdef SUPDRV_USE_TSC_DELTA_THREAD
#ifndef SUPDRV_AGNOSTIC
# ifdef RT_OS_WINDOWS
} SUPDRVDEVEXT;
#define SUPDRV_SESSION_HASH(a_pid) ( (a_pid) % RT_ELEMENTS(((SUPDRVDEVEXT *)NULL)->apSessionHashTab) )
void VBOXCALL supdrvOSSessionHashTabInserted(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, void *pvUser);
void VBOXCALL supdrvOSSessionHashTabRemoved(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, void *pvUser);
bool VBOXCALL supdrvOSObjCanAccess(PSUPDRVOBJ pObj, PSUPDRVSESSION pSession, const char *pszObjName, int *prc);
int VBOXCALL supdrvOSLdrOpen(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, const char *pszFilename);
int VBOXCALL supdrvOSLdrLoad(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, const uint8_t *pbImageBits, PSUPLDRLOAD pReq);
#ifdef SUPDRV_WITH_MSR_PROBER
#if defined(RT_OS_DARWIN)
/* SUPDrv.c */
int VBOXCALL supdrvIOCtl(uintptr_t uIOCtl, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPREQHDR pReqHdr, size_t cbReq);
int VBOXCALL supdrvIOCtlFast(uintptr_t uIOCtl, VMCPUID idCpu, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession);
int VBOXCALL supdrvIDC(uintptr_t uIOCtl, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPDRVIDCREQHDR pReqHdr);
int VBOXCALL supdrvCreateSession(PSUPDRVDEVEXT pDevExt, bool fUser, bool fUnrestricted, PSUPDRVSESSION *ppSession);
int VBOXCALL supdrvSessionHashTabInsert(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPDRVSESSION *ppOsSessionPtr, void *pvUser);
int VBOXCALL supdrvSessionHashTabRemove(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, void *pvUser);
PSUPDRVSESSION VBOXCALL supdrvSessionHashTabLookup(PSUPDRVDEVEXT pDevExt, RTPROCESS Process, RTR0PROCESS R0Process,
/* SUPDrvGip.cpp */
int VBOXCALL supdrvIOCtl_TscDeltaMeasure(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPTSCDELTAMEASURE pReq);
/* SUPDrvTracer.cpp */
int VBOXCALL supdrvIOCtl_TracerUmodDeregister(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, RTR3PTR R3PtrVtgHdr);
void VBOXCALL supdrvIOCtl_TracerUmodProbeFire(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPDRVTRACERUSRCTX pCtx);
int VBOXCALL supdrvIOCtl_TracerOpen(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, uint32_t uCookie, uintptr_t uArg);
int VBOXCALL supdrvIOCtl_TracerIOCtl(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, uintptr_t uCmd, uintptr_t uArg, int32_t *piRetVal);
#ifdef VBOX_WITH_NATIVE_DTRACE