SUPDrv.c revision d0dda9013fea84af1276affdb6e6001123ae0b13
/* $Revision$ */
/** @file
* VBoxDrv - The VirtualBox Support Driver - Common code.
*/
/*
* Copyright (C) 2006-2011 Oracle Corporation
*
* 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.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP LOG_GROUP_SUP_DRV
#define SUPDRV_AGNOSTIC
#include "SUPDrvInternal.h"
#ifndef PAGE_SHIFT
#endif
#include <iprt/asm-amd64-x86.h>
#include <iprt/asm-math.h>
#include <iprt/handletable.h>
#include <iprt/semaphore.h>
#include <iprt/spinlock.h>
#endif
#ifdef VBOX_WITH_DTRACE
# include "SUPDrv-dtrace.h"
#else
# define VBOXDRV_SUPDRV_SESSION_CLOSE(pvSession) do { } while (0)
# define VBOXDRV_SUPDRV_IOCCLOSE(pvSession) do { } while (0)
#endif
/*
* Logging assignments:
* Log - useful stuff, like failures.
* LogFlow - program flow, except the really noisy bits.
* Log2 - Cleanup.
* Log3 - Loader flow noise.
* Log4 - Call VMMR0 flow noise.
* Log5 - Native yet-to-be-defined noise.
* Log6 - Native ioctl flow noise.
*
* Logging requires BUILD_TYPE=debug and possibly changes to the logger
* instantiation in log-vbox.c(pp).
*/
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
/** The frequency by which we recalculate the u32UpdateHz and
* u32UpdateIntervalNS GIP members. The value must be a power of 2. */
#define GIP_UPDATEHZ_RECALC_FREQ 0x800
/** @def VBOX_SVN_REV
* The makefile should define this if it can. */
#ifndef VBOX_SVN_REV
# define VBOX_SVN_REV 0
#endif
#if 0 /* Don't start the GIP timers. Useful when debugging the IPRT timer code. */
# define DO_NOT_START_GIP
#endif
/*******************************************************************************
* Internal Functions *
*******************************************************************************/
static DECLCALLBACK(int) supdrvSessionObjHandleRetain(RTHANDLETABLE hHandleTable, void *pvObj, void *pvCtx, void *pvUser);
static DECLCALLBACK(void) supdrvSessionObjHandleDelete(RTHANDLETABLE hHandleTable, uint32_t h, void *pvObj, void *pvCtx, void *pvUser);
static int supdrvIOCtl_LdrGetSymbol(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPLDRGETSYMBOL pReq);
static int supdrvIDC_LdrGetSymbol(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPDRVIDCREQGETSYM pReq);
static int supdrvLdrSetVMMR0EPs(PSUPDRVDEVEXT pDevExt, void *pvVMMR0, void *pvVMMR0EntryInt, void *pvVMMR0EntryFast, void *pvVMMR0EntryEx);
static int supdrvIOCtl_CallServiceModule(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPCALLSERVICE pReq);
static int supdrvIOCtl_LoggerSettings(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPLOGGERSETTINGS pReq);
static void supdrvGipUpdate(PSUPGLOBALINFOPAGE pGip, uint64_t u64NanoTS, uint64_t u64TSC, RTCPUID idCpu, uint64_t iTick);
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/**
* Array of the R0 SUP API.
*/
static SUPFUNC g_aFunctions[] =
{
/* name function */
/* Entries with absolute addresses determined at runtime, fixup
code makes ugly ASSUMPTIONS about the order here: */
{ "SUPR0AbsIs64bit", (void *)0 },
{ "SUPR0Abs64bitKernelCS", (void *)0 },
{ "SUPR0Abs64bitKernelSS", (void *)0 },
{ "SUPR0Abs64bitKernelDS", (void *)0 },
{ "SUPR0AbsKernelCS", (void *)0 },
{ "SUPR0AbsKernelSS", (void *)0 },
{ "SUPR0AbsKernelDS", (void *)0 },
{ "SUPR0AbsKernelES", (void *)0 },
{ "SUPR0AbsKernelFS", (void *)0 },
{ "SUPR0AbsKernelGS", (void *)0 },
/* Normal function pointers: */
{ "SUPR0ComponentRegisterFactory", (void *)SUPR0ComponentRegisterFactory },
{ "SUPR0ComponentDeregisterFactory", (void *)SUPR0ComponentDeregisterFactory },
{ "SUPR0ComponentQueryFactory", (void *)SUPR0ComponentQueryFactory },
{ "SUPR0ObjRegister", (void *)SUPR0ObjRegister },
{ "SUPR0ObjAddRef", (void *)SUPR0ObjAddRef },
{ "SUPR0ObjAddRefEx", (void *)SUPR0ObjAddRefEx },
{ "SUPR0ObjRelease", (void *)SUPR0ObjRelease },
{ "SUPR0ObjVerifyAccess", (void *)SUPR0ObjVerifyAccess },
{ "SUPR0LockMem", (void *)SUPR0LockMem },
{ "SUPR0UnlockMem", (void *)SUPR0UnlockMem },
{ "SUPR0ContAlloc", (void *)SUPR0ContAlloc },
{ "SUPR0ContFree", (void *)SUPR0ContFree },
{ "SUPR0LowAlloc", (void *)SUPR0LowAlloc },
{ "SUPR0LowFree", (void *)SUPR0LowFree },
{ "SUPR0MemAlloc", (void *)SUPR0MemAlloc },
{ "SUPR0MemGetPhys", (void *)SUPR0MemGetPhys },
{ "SUPR0MemFree", (void *)SUPR0MemFree },
{ "SUPR0PageAllocEx", (void *)SUPR0PageAllocEx },
{ "SUPR0PageFree", (void *)SUPR0PageFree },
{ "SUPSemEventCreate", (void *)SUPSemEventCreate },
{ "SUPSemEventClose", (void *)SUPSemEventClose },
{ "SUPSemEventSignal", (void *)SUPSemEventSignal },
{ "SUPSemEventWait", (void *)SUPSemEventWait },
{ "SUPSemEventWaitNoResume", (void *)SUPSemEventWaitNoResume },
{ "SUPSemEventWaitNsAbsIntr", (void *)SUPSemEventWaitNsAbsIntr },
{ "SUPSemEventWaitNsRelIntr", (void *)SUPSemEventWaitNsRelIntr },
{ "SUPSemEventGetResolution", (void *)SUPSemEventGetResolution },
{ "SUPSemEventMultiCreate", (void *)SUPSemEventMultiCreate },
{ "SUPSemEventMultiClose", (void *)SUPSemEventMultiClose },
{ "SUPSemEventMultiSignal", (void *)SUPSemEventMultiSignal },
{ "SUPSemEventMultiReset", (void *)SUPSemEventMultiReset },
{ "SUPSemEventMultiWait", (void *)SUPSemEventMultiWait },
{ "SUPSemEventMultiWaitNoResume", (void *)SUPSemEventMultiWaitNoResume },
{ "SUPSemEventMultiWaitNsAbsIntr", (void *)SUPSemEventMultiWaitNsAbsIntr },
{ "SUPSemEventMultiWaitNsRelIntr", (void *)SUPSemEventMultiWaitNsRelIntr },
{ "SUPSemEventMultiGetResolution", (void *)SUPSemEventMultiGetResolution },
{ "SUPR0GetPagingMode", (void *)SUPR0GetPagingMode },
{ "SUPR0EnableVTx", (void *)SUPR0EnableVTx },
{ "SUPGetGIP", (void *)SUPGetGIP },
{ "g_pSUPGlobalInfoPage", (void *)&g_pSUPGlobalInfoPage },
{ "RTMemAllocTag", (void *)RTMemAllocTag },
{ "RTMemAllocZTag", (void *)RTMemAllocZTag },
{ "RTMemAllocVarTag", (void *)RTMemAllocVarTag },
{ "RTMemAllocZVarTag", (void *)RTMemAllocZVarTag },
{ "RTMemFree", (void *)RTMemFree },
{ "RTMemDupTag", (void *)RTMemDupTag },
{ "RTMemDupExTag", (void *)RTMemDupExTag },
{ "RTMemReallocTag", (void *)RTMemReallocTag },
{ "RTR0MemObjAllocLowTag", (void *)RTR0MemObjAllocLowTag },
{ "RTR0MemObjAllocPageTag", (void *)RTR0MemObjAllocPageTag },
{ "RTR0MemObjAllocPhysTag", (void *)RTR0MemObjAllocPhysTag },
{ "RTR0MemObjAllocPhysExTag", (void *)RTR0MemObjAllocPhysExTag },
{ "RTR0MemObjAllocPhysNCTag", (void *)RTR0MemObjAllocPhysNCTag },
{ "RTR0MemObjAllocContTag", (void *)RTR0MemObjAllocContTag },
{ "RTR0MemObjEnterPhysTag", (void *)RTR0MemObjEnterPhysTag },
{ "RTR0MemObjLockUserTag", (void *)RTR0MemObjLockUserTag },
{ "RTR0MemObjMapKernelTag", (void *)RTR0MemObjMapKernelTag },
{ "RTR0MemObjMapKernelExTag", (void *)RTR0MemObjMapKernelExTag },
{ "RTR0MemObjMapUserTag", (void *)RTR0MemObjMapUserTag },
{ "RTR0MemObjProtect", (void *)RTR0MemObjProtect },
{ "RTR0MemObjAddress", (void *)RTR0MemObjAddress },
{ "RTR0MemObjAddressR3", (void *)RTR0MemObjAddressR3 },
{ "RTR0MemObjSize", (void *)RTR0MemObjSize },
{ "RTR0MemObjIsMapping", (void *)RTR0MemObjIsMapping },
{ "RTR0MemObjGetPagePhysAddr", (void *)RTR0MemObjGetPagePhysAddr },
{ "RTR0MemObjFree", (void *)RTR0MemObjFree },
{ "RTR0MemUserCopyFrom", (void *)RTR0MemUserCopyFrom },
{ "RTR0MemUserCopyTo", (void *)RTR0MemUserCopyTo },
{ "RTR0MemUserIsValidAddr", (void *)RTR0MemUserIsValidAddr },
{ "RTR0MemKernelIsValidAddr", (void *)RTR0MemKernelIsValidAddr },
{ "RTR0MemAreKrnlAndUsrDifferent", (void *)RTR0MemAreKrnlAndUsrDifferent },
{ "RTSemMutexCreate", (void *)RTSemMutexCreate },
{ "RTSemMutexRequest", (void *)RTSemMutexRequest },
{ "RTSemMutexRequestDebug", (void *)RTSemMutexRequestDebug },
{ "RTSemMutexRequestNoResume", (void *)RTSemMutexRequestNoResume },
{ "RTSemMutexRequestNoResumeDebug", (void *)RTSemMutexRequestNoResumeDebug },
{ "RTSemMutexRelease", (void *)RTSemMutexRelease },
{ "RTSemMutexDestroy", (void *)RTSemMutexDestroy },
{ "RTProcSelf", (void *)RTProcSelf },
{ "RTR0ProcHandleSelf", (void *)RTR0ProcHandleSelf },
{ "RTSemFastMutexCreate", (void *)RTSemFastMutexCreate },
{ "RTSemFastMutexDestroy", (void *)RTSemFastMutexDestroy },
{ "RTSemFastMutexRequest", (void *)RTSemFastMutexRequest },
{ "RTSemFastMutexRelease", (void *)RTSemFastMutexRelease },
{ "RTSemEventCreate", (void *)RTSemEventCreate },
{ "RTSemEventSignal", (void *)RTSemEventSignal },
{ "RTSemEventWait", (void *)RTSemEventWait },
{ "RTSemEventWaitNoResume", (void *)RTSemEventWaitNoResume },
{ "RTSemEventWaitEx", (void *)RTSemEventWaitEx },
{ "RTSemEventWaitExDebug", (void *)RTSemEventWaitExDebug },
{ "RTSemEventGetResolution", (void *)RTSemEventGetResolution },
{ "RTSemEventDestroy", (void *)RTSemEventDestroy },
{ "RTSemEventMultiCreate", (void *)RTSemEventMultiCreate },
{ "RTSemEventMultiSignal", (void *)RTSemEventMultiSignal },
{ "RTSemEventMultiReset", (void *)RTSemEventMultiReset },
{ "RTSemEventMultiWait", (void *)RTSemEventMultiWait },
{ "RTSemEventMultiWaitNoResume", (void *)RTSemEventMultiWaitNoResume },
{ "RTSemEventMultiWaitEx", (void *)RTSemEventMultiWaitEx },
{ "RTSemEventMultiWaitExDebug", (void *)RTSemEventMultiWaitExDebug },
{ "RTSemEventMultiGetResolution", (void *)RTSemEventMultiGetResolution },
{ "RTSemEventMultiDestroy", (void *)RTSemEventMultiDestroy },
{ "RTSpinlockCreate", (void *)RTSpinlockCreate },
{ "RTSpinlockDestroy", (void *)RTSpinlockDestroy },
{ "RTSpinlockAcquire", (void *)RTSpinlockAcquire },
{ "RTSpinlockRelease", (void *)RTSpinlockRelease },
{ "RTSpinlockAcquireNoInts", (void *)RTSpinlockAcquireNoInts },
{ "RTSpinlockReleaseNoInts", (void *)RTSpinlockReleaseNoInts },
{ "RTTimeNanoTS", (void *)RTTimeNanoTS },
{ "RTTimeMilliTS", (void *)RTTimeMilliTS },
{ "RTTimeSystemNanoTS", (void *)RTTimeSystemNanoTS },
{ "RTTimeSystemMilliTS", (void *)RTTimeSystemMilliTS },
{ "RTThreadNativeSelf", (void *)RTThreadNativeSelf },
{ "RTThreadSleep", (void *)RTThreadSleep },
{ "RTThreadYield", (void *)RTThreadYield },
{ "RTThreadSelf", (void *)RTThreadSelf },
{ "RTThreadCreate", (void *)RTThreadCreate },
{ "RTThreadGetNative", (void *)RTThreadGetNative },
{ "RTThreadWait", (void *)RTThreadWait },
{ "RTThreadWaitNoResume", (void *)RTThreadWaitNoResume },
{ "RTThreadGetName", (void *)RTThreadGetName },
{ "RTThreadSelfName", (void *)RTThreadSelfName },
{ "RTThreadGetType", (void *)RTThreadGetType },
{ "RTThreadUserSignal", (void *)RTThreadUserSignal },
{ "RTThreadUserReset", (void *)RTThreadUserReset },
{ "RTThreadUserWait", (void *)RTThreadUserWait },
{ "RTThreadUserWaitNoResume", (void *)RTThreadUserWaitNoResume },
{ "RTThreadPreemptIsEnabled", (void *)RTThreadPreemptIsEnabled },
{ "RTThreadPreemptIsPending", (void *)RTThreadPreemptIsPending },
{ "RTThreadPreemptIsPendingTrusty", (void *)RTThreadPreemptIsPendingTrusty },
{ "RTThreadPreemptIsPossible", (void *)RTThreadPreemptIsPossible },
{ "RTThreadPreemptDisable", (void *)RTThreadPreemptDisable },
{ "RTThreadPreemptRestore", (void *)RTThreadPreemptRestore },
{ "RTThreadIsInInterrupt", (void *)RTThreadIsInInterrupt },
{ "RTTimerCreate", (void *)RTTimerCreate },
{ "RTTimerCreateEx", (void *)RTTimerCreateEx },
{ "RTTimerDestroy", (void *)RTTimerDestroy },
{ "RTTimerStart", (void *)RTTimerStart },
{ "RTTimerStop", (void *)RTTimerStop },
{ "RTTimerChangeInterval", (void *)RTTimerChangeInterval },
{ "RTTimerGetSystemGranularity", (void *)RTTimerGetSystemGranularity },
{ "RTTimerRequestSystemGranularity", (void *)RTTimerRequestSystemGranularity },
{ "RTTimerReleaseSystemGranularity", (void *)RTTimerReleaseSystemGranularity },
{ "RTTimerCanDoHighResolution", (void *)RTTimerCanDoHighResolution },
{ "RTLogDefaultInstance", (void *)RTLogDefaultInstance },
{ "RTMpCpuId", (void *)RTMpCpuId },
{ "RTMpCpuIdFromSetIndex", (void *)RTMpCpuIdFromSetIndex },
{ "RTMpCpuIdToSetIndex", (void *)RTMpCpuIdToSetIndex },
{ "RTMpGetArraySize", (void *)RTMpGetArraySize },
{ "RTMpIsCpuPossible", (void *)RTMpIsCpuPossible },
{ "RTMpGetCount", (void *)RTMpGetCount },
{ "RTMpGetMaxCpuId", (void *)RTMpGetMaxCpuId },
{ "RTMpGetOnlineCount", (void *)RTMpGetOnlineCount },
{ "RTMpGetOnlineSet", (void *)RTMpGetOnlineSet },
{ "RTMpGetSet", (void *)RTMpGetSet },
{ "RTMpIsCpuOnline", (void *)RTMpIsCpuOnline },
{ "RTMpIsCpuWorkPending", (void *)RTMpIsCpuWorkPending },
{ "RTMpNotificationRegister", (void *)RTMpNotificationRegister },
{ "RTMpNotificationDeregister", (void *)RTMpNotificationDeregister },
{ "RTMpOnAll", (void *)RTMpOnAll },
{ "RTMpOnOthers", (void *)RTMpOnOthers },
{ "RTMpOnSpecific", (void *)RTMpOnSpecific },
{ "RTMpPokeCpu", (void *)RTMpPokeCpu },
{ "RTPowerNotificationRegister", (void *)RTPowerNotificationRegister },
{ "RTPowerNotificationDeregister", (void *)RTPowerNotificationDeregister },
{ "RTLogRelDefaultInstance", (void *)RTLogRelDefaultInstance },
{ "RTLogSetDefaultInstanceThread", (void *)RTLogSetDefaultInstanceThread },
{ "RTLogLoggerExV", (void *)RTLogLoggerExV },
{ "RTLogPrintfV", (void *)RTLogPrintfV },
{ "RTR0AssertPanicSystem", (void *)RTR0AssertPanicSystem },
{ "RTAssertMsg1", (void *)RTAssertMsg1 },
{ "RTAssertMsg2V", (void *)RTAssertMsg2V },
{ "RTAssertMsg2AddV", (void *)RTAssertMsg2AddV },
{ "RTAssertSetQuiet", (void *)RTAssertSetQuiet },
{ "RTAssertMayPanic", (void *)RTAssertMayPanic },
{ "RTAssertSetMayPanic", (void *)RTAssertSetMayPanic },
{ "RTAssertAreQuiet", (void *)RTAssertAreQuiet },
{ "RTStrFormat", (void *)RTStrFormat },
{ "RTStrFormatNumber", (void *)RTStrFormatNumber },
{ "RTStrFormatTypeDeregister", (void *)RTStrFormatTypeDeregister },
{ "RTStrFormatTypeRegister", (void *)RTStrFormatTypeRegister },
{ "RTStrFormatTypeSetUser", (void *)RTStrFormatTypeSetUser },
{ "RTStrFormatV", (void *)RTStrFormatV },
{ "RTStrPrintf", (void *)RTStrPrintf },
{ "RTStrPrintfEx", (void *)RTStrPrintfEx },
{ "RTStrPrintfExV", (void *)RTStrPrintfExV },
{ "RTStrPrintfV", (void *)RTStrPrintfV },
{ "RTHandleTableAllocWithCtx", (void *)RTHandleTableAllocWithCtx },
{ "RTHandleTableCreate", (void *)RTHandleTableCreate },
{ "RTHandleTableCreateEx", (void *)RTHandleTableCreateEx },
{ "RTHandleTableDestroy", (void *)RTHandleTableDestroy },
{ "RTHandleTableFreeWithCtx", (void *)RTHandleTableFreeWithCtx },
{ "RTHandleTableLookupWithCtx", (void *)RTHandleTableLookupWithCtx },
{ "RTNetIPv4AddDataChecksum", (void *)RTNetIPv4AddDataChecksum },
{ "RTNetIPv4AddTCPChecksum", (void *)RTNetIPv4AddTCPChecksum },
{ "RTNetIPv4AddUDPChecksum", (void *)RTNetIPv4AddUDPChecksum },
{ "RTNetIPv4FinalizeChecksum", (void *)RTNetIPv4FinalizeChecksum },
{ "RTNetIPv4HdrChecksum", (void *)RTNetIPv4HdrChecksum },
{ "RTNetIPv4IsDHCPValid", (void *)RTNetIPv4IsDHCPValid },
{ "RTNetIPv4IsHdrValid", (void *)RTNetIPv4IsHdrValid },
{ "RTNetIPv4IsTCPSizeValid", (void *)RTNetIPv4IsTCPSizeValid },
{ "RTNetIPv4IsTCPValid", (void *)RTNetIPv4IsTCPValid },
{ "RTNetIPv4IsUDPSizeValid", (void *)RTNetIPv4IsUDPSizeValid },
{ "RTNetIPv4IsUDPValid", (void *)RTNetIPv4IsUDPValid },
{ "RTNetIPv4PseudoChecksum", (void *)RTNetIPv4PseudoChecksum },
{ "RTNetIPv4PseudoChecksumBits", (void *)RTNetIPv4PseudoChecksumBits },
{ "RTNetIPv4TCPChecksum", (void *)RTNetIPv4TCPChecksum },
{ "RTNetIPv4UDPChecksum", (void *)RTNetIPv4UDPChecksum },
{ "RTNetIPv6PseudoChecksum", (void *)RTNetIPv6PseudoChecksum },
{ "RTNetIPv6PseudoChecksumBits", (void *)RTNetIPv6PseudoChecksumBits },
{ "RTNetIPv6PseudoChecksumEx", (void *)RTNetIPv6PseudoChecksumEx },
{ "RTNetTCPChecksum", (void *)RTNetTCPChecksum },
{ "RTNetUDPChecksum", (void *)RTNetUDPChecksum },
{ "RTCrc32", (void *)RTCrc32 },
{ "RTCrc32Finish", (void *)RTCrc32Finish },
{ "RTCrc32Process", (void *)RTCrc32Process },
{ "RTCrc32Start", (void *)RTCrc32Start },
};
/**
* Drag in the rest of IRPT since we share it with the
* rest of the kernel modules on darwin.
*/
{
/* VBoxNetFlt */
/* VBoxNetAdp */
/* VBoxUSB */
};
#endif /* RT_OS_DARWIN || RT_OS_SOLARIS || RT_OS_SOLARIS */
/**
* Initializes the device extentsion structure.
*
* @returns IPRT status code.
* @param pDevExt The device extension to initialize.
* @param cbSession The size of the session structure. The size of
* SUPDRVSESSION may be smaller when SUPDRV_AGNOSTIC is
* defined because we're skipping the OS specific members
* then.
*/
{
int rc;
#ifdef SUPDRV_WITH_RELEASE_LOGGER
/*
* Create the release log.
*/
static const char * const s_apszGroups[] = VBOX_LOGGROUP_NAMES;
"VBOX_RELEASE_LOG", RT_ELEMENTS(s_apszGroups), s_apszGroups, RTLOGDEST_STDOUT | RTLOGDEST_DEBUGGER, NULL);
if (RT_SUCCESS(rc))
/** @todo Add native hook for getting logger config parameters and setting
* them. On linux we should use the module parameter stuff... */
#endif
/*
* Initialize it.
*/
if (RT_SUCCESS(rc))
{
#ifdef SUPDRV_USE_MUTEX_FOR_LDR
#else
#endif
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
#ifdef SUPDRV_USE_MUTEX_FOR_LDR
#else
#endif
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
/*
* Fixup the absolute symbols.
*
* Because of the table indexing assumptions we'll have a little #ifdef orgy
* here rather than distributing this to OS specific files. At least for now.
*/
#ifdef RT_OS_DARWIN
# if ARCH_BITS == 32
if (SUPR0GetPagingMode() >= SUPPAGINGMODE_AMD64)
{
}
else
# else /* 64-bit darwin: */
# endif
#else /* !RT_OS_DARWIN */
# if ARCH_BITS == 64
# else
# endif
#endif /* !RT_OS_DARWIN */
return VINF_SUCCESS;
}
#ifdef SUPDRV_USE_MUTEX_FOR_GIP
#else
#endif
}
}
#ifdef SUPDRV_USE_MUTEX_FOR_LDR
#else
#endif
}
}
#ifdef SUPDRV_WITH_RELEASE_LOGGER
#endif
return rc;
}
/**
* Delete the device extension (e.g. cleanup members).
*
* @param pDevExt The device extension to delete.
*/
{
/*
* Kill mutexes and spinlocks.
*/
#ifdef SUPDRV_USE_MUTEX_FOR_GIP
#else
#endif
#ifdef SUPDRV_USE_MUTEX_FOR_LDR
#else
#endif
/*
* Free lists.
*/
/* objects. */
while (pObj)
{
}
/* usage records. */
while (pUsage)
{
}
/* kill the GIP. */
#ifdef SUPDRV_WITH_RELEASE_LOGGER
/* destroy the loggers. */
#endif
}
/**
* Create session.
*
* @returns IPRT status code.
* @param pDevExt Device extension.
* @param fUser Flag indicating whether this is a user or kernel session.
* @param ppSession Where to store the pointer to the session data.
*/
{
/*
* Allocate memory for the session data.
*/
int rc;
if (pSession)
{
/* Initialize session data. */
if (!rc)
{
if (RT_SUCCESS(rc))
{
/*pSession->pLdrUsage = NULL;
pSession->pVM = NULL;
pSession->pUsage = NULL;
pSession->pGip = NULL;
pSession->fGipReferenced = false;
pSession->Bundle.cUsed = 0; */
if (fUser)
{
}
else
{
}
return VINF_SUCCESS;
}
}
}
else
rc = VERR_NO_MEMORY;
return rc;
}
/**
* Shared code for cleaning up a session.
*
* @param pDevExt Device extension.
* @param pSession Session data.
* This data will be freed by this routine.
*/
{
/*
* Cleanup the session first.
*/
/*
* Free the rest of the session stuff.
*/
LogFlow(("supdrvCloseSession: returns\n"));
}
/**
* Shared code for cleaning up a session (but not quite freeing it).
*
* This is primarily intended for MAC OS X where we have to clean up the memory
* stuff before the file handle is closed.
*
* @param pDevExt Device extension.
* @param pSession Session data.
* This data will be freed by this routine.
*/
{
int rc;
/*
* Remove logger instances related to this session.
*/
/*
* Destroy the handle table.
*/
/*
* Release object references made in this session.
* In theory there should be noone racing us in this session.
*/
Log2(("release objects - start\n"));
{
{
AssertMsg(pUsage->cUsage >= 1 && pObj->cUsage >= pUsage->cUsage, ("glob %d; sess %d\n", pObj->cUsage, pUsage->cUsage));
{
}
else
{
/* Destroy the object and free the record. */
else
{
{
break;
}
}
Log(("supdrvCleanupSession: destroying %p/%d (%p/%p) cpid=%RTproc pid=%RTproc dtor=%p\n",
pObj, pObj->enmType, pObj->pvUser1, pObj->pvUser2, pObj->CreatorProcess, RTProcSelf(), pObj->pfnDestructor));
if (pObj->pfnDestructor)
}
/* free it and continue. */
}
}
Log2(("release objects - done\n"));
/*
* Release memory allocated in the session.
*
* We do not serialize this as we assume that the application will
* not allocated memory while closing the file handle object.
*/
Log2(("freeing memory:\n"));
while (pBundle)
{
unsigned i;
/*
* Check and unlock all entries in the bundle.
*/
{
{
Log2(("eType=%d pvR0=%p pvR3=%p cb=%ld\n", pBundle->aMem[i].eType, RTR0MemObjAddress(pBundle->aMem[i].MemObj),
(void *)RTR0MemObjAddressR3(pBundle->aMem[i].MapObjR3), (long)RTR0MemObjSize(pBundle->aMem[i].MemObj)));
{
}
}
}
/*
* Advance and free previous bundle.
*/
}
Log2(("freeing memory - done\n"));
/*
* Deregister component factories.
*/
Log2(("deregistering component factories:\n"));
if (pDevExt->pComponentFactoryHead)
{
while (pCur)
{
{
/* unlink it */
if (pPrev)
else
/* free it */
/* next */
}
else
{
/* next */
}
}
}
Log2(("deregistering component factories - done\n"));
/*
* Loaded images needs to be dereferenced and possibly freed up.
*/
Log2(("freeing images:\n"));
{
while (pUsage)
{
else
}
}
Log2(("freeing images - done\n"));
/*
* Unmap the GIP.
*/
Log2(("umapping GIP:\n"));
{
pSession->fGipReferenced = 0;
}
Log2(("umapping GIP - done\n"));
}
/**
* RTHandleTableDestroy callback used by supdrvCleanupSession.
*
* @returns IPRT status code, see SUPR0ObjAddRef.
* @param hHandleTable The handle table handle. Ignored.
* @param pvObj The object pointer.
* @param pvCtx Context, the handle type. Ignored.
* @param pvUser Session pointer.
*/
static DECLCALLBACK(int) supdrvSessionObjHandleRetain(RTHANDLETABLE hHandleTable, void *pvObj, void *pvCtx, void *pvUser)
{
}
/**
* RTHandleTableDestroy callback used by supdrvCleanupSession.
*
* @param hHandleTable The handle table handle. Ignored.
* @param h The handle value. Ignored.
* @param pvObj The object pointer.
* @param pvCtx Context, the handle type. Ignored.
* @param pvUser Session pointer.
*/
static DECLCALLBACK(void) supdrvSessionObjHandleDelete(RTHANDLETABLE hHandleTable, uint32_t h, void *pvObj, void *pvCtx, void *pvUser)
{
NOREF(h);
}
/**
* Fast path I/O Control worker.
*
* @returns VBox status code that should be passed down to ring-3 unchanged.
* @param uIOCtl Function number.
* @param idCpu VMCPU id.
* @param pDevExt Device extention.
* @param pSession Session data.
*/
int VBOXCALL supdrvIOCtlFast(uintptr_t uIOCtl, VMCPUID idCpu, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession)
{
/*
* We check the two prereqs after doing this only to allow the compiler to optimize things better.
*/
&& pDevExt->pfnVMMR0EntryFast))
{
switch (uIOCtl)
{
break;
break;
case SUP_IOCTL_FAST_DO_NOP:
break;
default:
return VERR_INTERNAL_ERROR;
}
return VINF_SUCCESS;
}
return VERR_INTERNAL_ERROR;
}
/**
* Helper for supdrvIOCtl. Check if pszStr contains any character of pszChars.
* We would use strpbrk here if this function would be contained in the RedHat kABI white
* list, see http://www.kerneldrivers.org/RHEL5.
*
* @returns 1 if pszStr does contain any character of pszChars, 0 otherwise.
* @param pszStr String to check
* @param pszChars Character set
*/
{
int chCur;
{
int ch;
return 1;
}
return 0;
}
/**
* I/O Control worker.
*
* @returns IPRT status code.
* @retval VERR_INVALID_PARAMETER if the request is invalid.
*
* @param uIOCtl Function number.
* @param pDevExt Device extention.
* @param pSession Session data.
* @param pReqHdr The request header.
*/
int VBOXCALL supdrvIOCtl(uintptr_t uIOCtl, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPREQHDR pReqHdr)
{
/*
* Validate the request.
*/
/* this first check could probably be omitted as its also done by the OS specific code... */
{
OSDBGPRINT(("vboxdrv: Bad ioctl request header; cbIn=%#lx cbOut=%#lx fFlags=%#lx\n",
return VERR_INVALID_PARAMETER;
}
{
return VERR_INVALID_PARAMETER;
}
{
{
return VERR_INVALID_PARAMETER;
}
}
{
OSDBGPRINT(("vboxdrv: bad cookie %#lx / %#lx.\n", (long)pReqHdr->u32Cookie, (long)pReqHdr->u32SessionCookie));
return VERR_INVALID_PARAMETER;
}
/*
* Validation macros
*/
do { \
{ \
OSDBGPRINT(( #Name ": Invalid input/output sizes. cbIn=%ld expected %ld. cbOut=%ld expected %ld.\n", \
VBOXDRV_SUPDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VERR_INVALID_PARAMETER, VERR_INVALID_PARAMETER); \
} \
} while (0)
do { \
{ \
VBOXDRV_SUPDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VERR_INVALID_PARAMETER, VERR_INVALID_PARAMETER); \
} \
} while (0)
do { \
{ \
VBOXDRV_SUPDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VERR_INVALID_PARAMETER, VERR_INVALID_PARAMETER); \
} \
} while (0)
do { \
if (RT_UNLIKELY(!(expr))) \
{ \
VBOXDRV_SUPDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VERR_INVALID_PARAMETER, VERR_INVALID_PARAMETER); \
} \
} while (0)
do { \
if (RT_UNLIKELY(!(expr))) \
{ \
OSDBGPRINT( fmt ); \
VBOXDRV_SUPDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VERR_INVALID_PARAMETER, VERR_INVALID_PARAMETER); \
} \
} while (0)
/*
* The switch.
*/
switch (SUP_CTL_CODE_NO_SIZE(uIOCtl))
{
{
{
return 0;
}
#if 0
/*
* Call out to the OS specific code and let it do permission checks on the
* client process.
*/
{
return 0;
}
#endif
/*
* Match the version.
* The current logic is very simple, match the major interface version.
*/
{
OSDBGPRINT(("SUP_IOCTL_COOKIE: Version mismatch. Requested: %#x Min: %#x Current: %#x\n",
return 0;
}
/*
* Fill in return data and be gone.
* N.B. The first one to change SUPDRV_IOC_VERSION shall makes sure that
* u32SessionVersion <= u32ReqVersion!
*/
/** @todo Somehow validate the client and negotiate a secure cookie... */
return 0;
}
case SUP_CTL_CODE_NO_SIZE(SUP_IOCTL_QUERY_FUNCS(0)):
{
/* validate */
REQ_CHECK_SIZES_EX(SUP_IOCTL_QUERY_FUNCS, SUP_IOCTL_QUERY_FUNCS_SIZE_IN, SUP_IOCTL_QUERY_FUNCS_SIZE_OUT(RT_ELEMENTS(g_aFunctions)));
/* execute */
return 0;
}
{
/* validate */
/* execute */
return 0;
}
{
/* validate */
/* execute */
return 0;
}
{
/* validate */
/* execute */
pReq->Hdr.rc = SUPR0ContAlloc(pSession, pReq->u.In.cPages, &pReq->u.Out.pvR0, &pReq->u.Out.pvR3, &pReq->u.Out.HCPhys);
return 0;
}
{
/* validate */
/* execute */
return 0;
}
{
/* validate */
REQ_CHECK_EXPR(SUP_IOCTL_LDR_OPEN, !supdrvCheckInvalidChar(pReq->u.In.szName, ";:()[]{}/\\|&*%#@!~`\"'"));
/* execute */
return 0;
}
{
/* validate */
REQ_CHECK_SIZES_EX(SUP_IOCTL_LDR_LOAD, SUP_IOCTL_LDR_LOAD_SIZE_IN(pReq->u.In.cbImageWithTabs), SUP_IOCTL_LDR_LOAD_SIZE_OUT);
("SUP_IOCTL_LDR_LOAD: offSymbols=%#lx cSymbols=%#lx cbImageWithTabs=%#lx\n", (long)pReq->u.In.offSymbols,
("SUP_IOCTL_LDR_LOAD: offStrTab=%#lx cbStrTab=%#lx cbImageWithTabs=%#lx\n", (long)pReq->u.In.offStrTab,
{
uint32_t i;
{
("SUP_IOCTL_LDR_LOAD: sym #%ld: symb off %#lx (max=%#lx)\n", (long)i, (long)paSyms[i].offSymbol, (long)pReq->u.In.cbImageWithTabs));
("SUP_IOCTL_LDR_LOAD: sym #%ld: name off %#lx (max=%#lx)\n", (long)i, (long)paSyms[i].offName, (long)pReq->u.In.cbImageWithTabs));
REQ_CHECK_EXPR_FMT(RTStrEnd((char const *)&pReq->u.In.abImage[pReq->u.In.offStrTab + paSyms[i].offName],
("SUP_IOCTL_LDR_LOAD: sym #%ld: unterminated name! (%#lx / %#lx)\n", (long)i, (long)paSyms[i].offName, (long)pReq->u.In.cbImageWithTabs));
}
}
/* execute */
return 0;
}
{
/* validate */
/* execute */
return 0;
}
{
/* validate */
REQ_CHECK_EXPR(SUP_IOCTL_LDR_GET_SYMBOL, RTStrEnd(pReq->u.In.szSymbol, sizeof(pReq->u.In.szSymbol)));
/* execute */
return 0;
}
case SUP_CTL_CODE_NO_SIZE(SUP_IOCTL_CALL_VMMR0(0)):
{
/* validate */
Log4(("SUP_IOCTL_CALL_VMMR0: op=%u in=%u arg=%RX64 p/t=%RTproc/%RTthrd\n",
{
REQ_CHECK_SIZES_EX(SUP_IOCTL_CALL_VMMR0, SUP_IOCTL_CALL_VMMR0_SIZE_IN(0), SUP_IOCTL_CALL_VMMR0_SIZE_OUT(0));
/* execute */
pReq->Hdr.rc = pDevExt->pfnVMMR0EntryEx(pReq->u.In.pVMR0, pReq->u.In.idCpu, pReq->u.In.uOperation, NULL, pReq->u.In.u64Arg, pSession);
else
}
else
{
("SUP_IOCTL_CALL_VMMR0: cbIn=%#x < %#lx\n", pReq->Hdr.cbIn, SUP_IOCTL_CALL_VMMR0_SIZE(sizeof(SUPVMMR0REQHDR))));
REQ_CHECK_SIZES_EX(SUP_IOCTL_CALL_VMMR0, SUP_IOCTL_CALL_VMMR0_SIZE_IN(pVMMReq->cbReq), SUP_IOCTL_CALL_VMMR0_SIZE_OUT(pVMMReq->cbReq));
/* execute */
pReq->Hdr.rc = pDevExt->pfnVMMR0EntryEx(pReq->u.In.pVMR0, pReq->u.In.idCpu, pReq->u.In.uOperation, pVMMReq, pReq->u.In.u64Arg, pSession);
else
}
Log(("SUP_IOCTL_CALL_VMMR0: rc=%Rrc op=%u out=%u arg=%RX64 p/t=%RTproc/%RTthrd\n",
pReq->Hdr.rc, pReq->u.In.uOperation, pReq->Hdr.cbOut, pReq->u.In.u64Arg, RTProcSelf(), RTThreadNativeSelf()));
else
Log4(("SUP_IOCTL_CALL_VMMR0: rc=%Rrc op=%u out=%u arg=%RX64 p/t=%RTproc/%RTthrd\n",
pReq->Hdr.rc, pReq->u.In.uOperation, pReq->Hdr.cbOut, pReq->u.In.u64Arg, RTProcSelf(), RTThreadNativeSelf()));
return 0;
}
{
/* validate */
Log4(("SUP_IOCTL_CALL_VMMR0_BIG: op=%u in=%u arg=%RX64 p/t=%RTproc/%RTthrd\n",
("SUP_IOCTL_CALL_VMMR0_BIG: cbIn=%#x < %#lx\n", pReq->Hdr.cbIn, SUP_IOCTL_CALL_VMMR0_BIG_SIZE(sizeof(SUPVMMR0REQHDR))));
REQ_CHECK_SIZES_EX(SUP_IOCTL_CALL_VMMR0_BIG, SUP_IOCTL_CALL_VMMR0_BIG_SIZE_IN(pVMMReq->cbReq), SUP_IOCTL_CALL_VMMR0_BIG_SIZE_OUT(pVMMReq->cbReq));
/* execute */
pReq->Hdr.rc = pDevExt->pfnVMMR0EntryEx(pReq->u.In.pVMR0, pReq->u.In.idCpu, pReq->u.In.uOperation, pVMMReq, pReq->u.In.u64Arg, pSession);
else
Log(("SUP_IOCTL_CALL_VMMR0_BIG: rc=%Rrc op=%u out=%u arg=%RX64 p/t=%RTproc/%RTthrd\n",
pReq->Hdr.rc, pReq->u.In.uOperation, pReq->Hdr.cbOut, pReq->u.In.u64Arg, RTProcSelf(), RTThreadNativeSelf()));
else
Log4(("SUP_IOCTL_CALL_VMMR0_BIG: rc=%Rrc op=%u out=%u arg=%RX64 p/t=%RTproc/%RTthrd\n",
pReq->Hdr.rc, pReq->u.In.uOperation, pReq->Hdr.cbOut, pReq->u.In.u64Arg, RTProcSelf(), RTThreadNativeSelf()));
return 0;
}
{
/* validate */
/* execute */
return 0;
}
{
/* validate */
REQ_CHECK_SIZES_EX(SUP_IOCTL_LOW_ALLOC, SUP_IOCTL_LOW_ALLOC_SIZE_IN, SUP_IOCTL_LOW_ALLOC_SIZE_OUT(pReq->u.In.cPages));
/* execute */
pReq->Hdr.rc = SUPR0LowAlloc(pSession, pReq->u.In.cPages, &pReq->u.Out.pvR0, &pReq->u.Out.pvR3, &pReq->u.Out.aPages[0]);
return 0;
}
{
/* validate */
/* execute */
return 0;
}
{
/* validate */
/* execute */
return 0;
}
{
/* validate */
/* execute */
return 0;
}
{
/* validate */
/* execute */
return 0;
}
{
/* validate */
REQ_CHECK_SIZES_EX(SUP_IOCTL_PAGE_ALLOC_EX, SUP_IOCTL_PAGE_ALLOC_EX_SIZE_IN, SUP_IOCTL_PAGE_ALLOC_EX_SIZE_OUT(pReq->u.In.cPages));
("SUP_IOCTL_PAGE_ALLOC_EX: No mapping requested!\n"));
("SUP_IOCTL_PAGE_ALLOC_EX: Must have user mapping!\n"));
("SUP_IOCTL_PAGE_ALLOC_EX: fReserved0=%d fReserved1=%d\n", pReq->u.In.fReserved0, pReq->u.In.fReserved1));
/* execute */
return 0;
}
{
/* validate */
REQ_CHECK_EXPR_FMT(!pReq->u.In.fFlags, ("SUP_IOCTL_PAGE_MAP_KERNEL: fFlags=%#x! MBZ\n", pReq->u.In.fFlags));
REQ_CHECK_EXPR_FMT(!(pReq->u.In.offSub & PAGE_OFFSET_MASK), ("SUP_IOCTL_PAGE_MAP_KERNEL: offSub=%#x\n", pReq->u.In.offSub));
/* execute */
return 0;
}
{
/* validate */
REQ_CHECK_EXPR_FMT(!(pReq->u.In.fProt & ~(RTMEM_PROT_READ | RTMEM_PROT_WRITE | RTMEM_PROT_EXEC | RTMEM_PROT_NONE)),
REQ_CHECK_EXPR_FMT(!(pReq->u.In.offSub & PAGE_OFFSET_MASK), ("SUP_IOCTL_PAGE_PROTECT: offSub=%#x\n", pReq->u.In.offSub));
/* execute */
pReq->Hdr.rc = SUPR0PageProtect(pSession, pReq->u.In.pvR3, pReq->u.In.pvR0, pReq->u.In.offSub, pReq->u.In.cbSub, pReq->u.In.fProt);
return 0;
}
{
/* validate */
/* execute */
return 0;
}
case SUP_CTL_CODE_NO_SIZE(SUP_IOCTL_CALL_SERVICE(0)):
{
/* validate */
Log4(("SUP_IOCTL_CALL_SERVICE: op=%u in=%u arg=%RX64 p/t=%RTproc/%RTthrd\n",
REQ_CHECK_SIZES_EX(SUP_IOCTL_CALL_SERVICE, SUP_IOCTL_CALL_SERVICE_SIZE_IN(0), SUP_IOCTL_CALL_SERVICE_SIZE_OUT(0));
else
{
("SUP_IOCTL_CALL_SERVICE: cbIn=%#x < %#lx\n", pReq->Hdr.cbIn, SUP_IOCTL_CALL_SERVICE_SIZE(sizeof(SUPR0SERVICEREQHDR))));
REQ_CHECK_SIZES_EX(SUP_IOCTL_CALL_SERVICE, SUP_IOCTL_CALL_SERVICE_SIZE_IN(pSrvReq->cbReq), SUP_IOCTL_CALL_SERVICE_SIZE_OUT(pSrvReq->cbReq));
}
/* execute */
return 0;
}
{
/* validate */
("SUP_IOCTL_LOGGER_SETTINGS: cbIn=%#x cbStrTab=%#zx LastChar=%d\n",
/* execute */
return 0;
}
{
/* validate */
/* execute */
{
case SUP_SEM_TYPE_EVENT:
{
{
case SUPSEMOP2_WAIT_MS_REL:
break;
case SUPSEMOP2_WAIT_NS_ABS:
break;
case SUPSEMOP2_WAIT_NS_REL:
break;
case SUPSEMOP2_SIGNAL:
break;
case SUPSEMOP2_CLOSE:
break;
case SUPSEMOP2_RESET:
default:
break;
}
break;
}
case SUP_SEM_TYPE_EVENT_MULTI:
{
{
case SUPSEMOP2_WAIT_MS_REL:
break;
case SUPSEMOP2_WAIT_NS_ABS:
break;
case SUPSEMOP2_WAIT_NS_REL:
break;
case SUPSEMOP2_SIGNAL:
break;
case SUPSEMOP2_CLOSE:
break;
case SUPSEMOP2_RESET:
break;
default:
break;
}
break;
}
default:
break;
}
return 0;
}
{
/* validate */
/* execute */
{
case SUP_SEM_TYPE_EVENT:
{
{
case SUPSEMOP3_CREATE:
break;
case SUPSEMOP3_GET_RESOLUTION:
break;
default:
break;
}
break;
}
case SUP_SEM_TYPE_EVENT_MULTI:
{
{
case SUPSEMOP3_CREATE:
break;
case SUPSEMOP3_GET_RESOLUTION:
break;
default:
break;
}
break;
}
default:
break;
}
return 0;
}
{
/* validate */
/* execute */
return 0;
}
default:
break;
}
return VERR_GENERAL_FAILURE;
}
/**
* Inter-Driver Communication (IDC) worker.
*
* @returns VBox status code.
* @retval VINF_SUCCESS on success.
* @retval VERR_INVALID_PARAMETER if the request is invalid.
* @retval VERR_NOT_SUPPORTED if the request isn't supported.
*
* @param uReq The request (function) code.
* @param pDevExt Device extention.
* @param pSession Session data.
* @param pReqHdr The request header.
*/
int VBOXCALL supdrvIDC(uintptr_t uReq, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPDRVIDCREQHDR pReqHdr)
{
/*
* The OS specific code has already validated the pSession
* pointer, and the request size being greater or equal to
* size of the header.
*
* So, just check that pSession is a kernel context session.
*/
if (RT_UNLIKELY( pSession
return VERR_INVALID_PARAMETER;
/*
* Validation macro.
*/
do { \
{ \
} \
} while (0)
switch (uReq)
{
case SUPDRV_IDC_REQ_CONNECT:
{
/*
* Validate the cookie and other input.
*/
{
}
{
OSDBGPRINT(("SUPDRV_IDC_REQ_CONNECT: u32MagicCookie=%#x expected %#x!\n",
}
|| (pReq->u.In.uMinVersion & UINT32_C(0xffff0000)) != (pReq->u.In.uReqVersion & UINT32_C(0xffff0000)))
{
OSDBGPRINT(("SUPDRV_IDC_REQ_CONNECT: uMinVersion=%#x uMaxVersion=%#x doesn't match!\n",
}
{
}
/*
* Match the version.
* The current logic is very simple, match the major interface version.
*/
{
OSDBGPRINT(("SUPDRV_IDC_REQ_CONNECT: Version mismatch. Requested: %#x Min: %#x Current: %#x\n",
return VINF_SUCCESS;
}
{
return VINF_SUCCESS;
}
return VINF_SUCCESS;
}
{
#ifdef RT_OS_WINDOWS
/* Windows will destroy the session when the file object is destroyed. */
#else
#endif
}
{
return VINF_SUCCESS;
}
{
return VINF_SUCCESS;
}
{
return VINF_SUCCESS;
}
default:
break;
}
return VERR_NOT_SUPPORTED;
}
/**
* Register a object for reference counting.
* The object is registered with one reference in the specified session.
*
* @returns Unique identifier on success (pointer).
* All future reference must use this identifier.
* @returns NULL on failure.
* @param pfnDestructor The destructore function which will be called when the reference count reaches 0.
* @param pvUser1 The first user argument.
* @param pvUser2 The second user argument.
*/
SUPR0DECL(void *) SUPR0ObjRegister(PSUPDRVSESSION pSession, SUPDRVOBJTYPE enmType, PFNSUPDRVDESTRUCTOR pfnDestructor, void *pvUser1, void *pvUser2)
{
/*
* Validate the input.
*/
/*
* Allocate and initialize the object.
*/
if (!pObj)
return NULL;
/*
* Allocate the usage record.
* (We keep freed usage records around to simplify SUPR0ObjAddRefEx().)
*/
if (pUsage)
else
{
if (!pUsage)
{
return NULL;
}
}
/*
* Insert the object and create the session usage record.
*/
/* The object. */
/* The session record. */
/* Log2(("SUPR0ObjRegister: pUsage=%p:{.pObj=%p, .pNext=%p}\n", pUsage, pUsage->pObj, pUsage->pNext)); */
return pObj;
}
/**
* Increment the reference counter for the object associating the reference
* with the specified session.
*
* @returns IPRT status code.
* @param pvObj The identifier returned by SUPR0ObjRegister().
* @param pSession The session which is referencing the object.
*
* @remarks The caller should not own any spinlocks and must carefully protect
* itself against potential race with the destructor so freed memory
* isn't accessed here.
*/
{
}
/**
* Increment the reference counter for the object associating the reference
* with the specified session.
*
* @returns IPRT status code.
* @retval VERR_TRY_AGAIN if fNoBlocking was set and a new usage record
* couldn't be allocated. (If you see this you're not doing the right
* thing and it won't ever work reliably.)
*
* @param pvObj The identifier returned by SUPR0ObjRegister().
* @param pSession The session which is referencing the object.
* @param fNoBlocking Set if it's not OK to block. Never try to make the
* first reference to an object in a session with this
* argument set.
*
* @remarks The caller should not own any spinlocks and must carefully protect
* itself against potential race with the destructor so freed memory
* isn't accessed here.
*/
{
int rc = VINF_SUCCESS;
/*
* Validate the input.
* Be ready for the destruction race (someone might be stuck in the
* destructor waiting a lock we own).
*/
("Invalid pvObj=%p magic=%#x (expected %#x or %#x)\n", pvObj, pObj->u32Magic, SUPDRVOBJ_MAGIC, SUPDRVOBJ_MAGIC_DEAD),
{
return VERR_WRONG_ORDER;
}
/*
* Preallocate the usage record if we can.
*/
if (pUsagePre)
else if (!fNoBlocking)
{
if (!pUsagePre)
return VERR_NO_MEMORY;
{
return VERR_WRONG_ORDER;
}
}
/*
* Reference the object.
*/
/*
* Look for the session record.
*/
{
/*Log(("SUPR0AddRef: pUsage=%p:{.pObj=%p, .pNext=%p}\n", pUsage, pUsage->pObj, pUsage->pNext));*/
break;
}
if (pUsage)
else if (pUsagePre)
{
/* create a new session record. */
/*Log(("SUPR0AddRef: pUsagePre=%p:{.pObj=%p, .pNext=%p}\n", pUsagePre, pUsagePre->pObj, pUsagePre->pNext));*/
}
else
{
rc = VERR_TRY_AGAIN;
}
/*
* Put any unused usage record into the free list..
*/
if (pUsagePre)
{
}
return rc;
}
/**
* Decrement / destroy a reference counter record for an object.
*
* The object is uniquely identified by pfnDestructor+pvUser1+pvUser2.
*
* @returns IPRT status code.
* @retval VINF_SUCCESS if not destroyed.
* @retval VINF_OBJECT_DESTROYED if it's destroyed by this release call.
* @retval VERR_INVALID_PARAMETER if the object isn't valid. Will assert in
* string builds.
*
* @param pvObj The identifier returned by SUPR0ObjRegister().
* @param pSession The session which is referencing the object.
*/
{
int rc = VERR_INVALID_PARAMETER;
/*
* Validate the input.
*/
/*
* Acquire the spinlock and look for the usage record.
*/
{
/*Log2(("SUPR0ObjRelease: pUsage=%p:{.pObj=%p, .pNext=%p}\n", pUsage, pUsage->pObj, pUsage->pNext));*/
{
rc = VINF_SUCCESS;
AssertMsg(pUsage->cUsage >= 1 && pObj->cUsage >= pUsage->cUsage, ("glob %d; sess %d\n", pObj->cUsage, pUsage->cUsage));
{
}
else
{
/*
* Free the session record.
*/
if (pUsagePrev)
else
/* What about the object? */
else
{
/*
* Object is to be destroyed, unlink it.
*/
else
{
{
break;
}
}
}
}
break;
}
}
/*
* Call the destructor and free the object if required.
*/
if (rc == VINF_OBJECT_DESTROYED)
{
Log(("SUPR0ObjRelease: destroying %p/%d (%p/%p) cpid=%RTproc pid=%RTproc dtor=%p\n",
pObj, pObj->enmType, pObj->pvUser1, pObj->pvUser2, pObj->CreatorProcess, RTProcSelf(), pObj->pfnDestructor));
if (pObj->pfnDestructor)
}
return rc;
}
/**
* Verifies that the current process can access the specified object.
*
* @returns The following IPRT status code:
* @retval VINF_SUCCESS if access was granted.
* @retval VERR_PERMISSION_DENIED if denied access.
* @retval VERR_INVALID_PARAMETER if invalid parameter.
*
* @param pvObj The identifier returned by SUPR0ObjRegister().
* @param pSession The session which wishes to access the object.
* @param pszObjName Object string name. This is optional and depends on the object type.
*
* @remark The caller is responsible for making sure the object isn't removed while
* we're inside this function. If uncertain about this, just call AddRef before calling us.
*/
{
int rc;
/*
* Validate the input.
*/
/*
* Check access. (returns true if a decision has been made.)
*/
return rc;
/*
* Default policy is to allow the user to access his own
* stuff but nothing else.
*/
return VINF_SUCCESS;
return VERR_PERMISSION_DENIED;
}
/**
* Lock pages.
*
* @returns IPRT status code.
* @param pSession Session to which the locked memory should be associated.
* @param pvR3 Start of the memory range to lock.
* This must be page aligned.
* @param cPages Number of pages to lock.
* @param paPages Where to put the physical addresses of locked memory.
*/
SUPR0DECL(int) SUPR0LockMem(PSUPDRVSESSION pSession, RTR3PTR pvR3, uint32_t cPages, PRTHCPHYS paPages)
{
int rc;
LogFlow(("SUPR0LockMem: pSession=%p pvR3=%p cPages=%d paPages=%p\n", pSession, (void *)pvR3, cPages, paPages));
/*
* Verify input.
*/
|| !pvR3)
{
return VERR_INVALID_PARAMETER;
}
/*
* Let IPRT do the job.
*/
rc = RTR0MemObjLockUser(&Mem.MemObj, pvR3, cb, RTMEM_PROT_READ | RTMEM_PROT_WRITE, RTR0ProcHandleSelf());
if (RT_SUCCESS(rc))
{
AssertMsg(RTR0MemObjAddressR3(Mem.MemObj) == pvR3, ("%p == %p\n", RTR0MemObjAddressR3(Mem.MemObj), pvR3));
while (iPage-- > 0)
{
{
break;
}
}
if (RT_SUCCESS(rc))
if (RT_FAILURE(rc))
{
}
}
return rc;
}
/**
* Unlocks the memory pointed to by pv.
*
* @returns IPRT status code.
* @param pSession Session to which the memory was locked.
* @param pvR3 Memory to unlock.
*/
{
}
/**
* Allocates a chunk of page aligned memory with contiguous and fixed physical
* backing.
*
* @returns IPRT status code.
* @param pSession Session data.
* @param cPages Number of pages to allocate.
* @param ppvR0 Where to put the address of Ring-0 mapping the allocated memory.
* @param ppvR3 Where to put the address of Ring-3 mapping the allocated memory.
* @param pHCPhys Where to put the physical address of allocated memory.
*/
SUPR0DECL(int) SUPR0ContAlloc(PSUPDRVSESSION pSession, uint32_t cPages, PRTR0PTR ppvR0, PRTR3PTR ppvR3, PRTHCPHYS pHCPhys)
{
int rc;
LogFlow(("SUPR0ContAlloc: pSession=%p cPages=%d ppvR0=%p ppvR3=%p pHCPhys=%p\n", pSession, cPages, ppvR0, ppvR3, pHCPhys));
/*
* Validate input.
*/
{
Log(("Null pointer. All of these should be set: pSession=%p ppvR0=%p ppvR3=%p pHCPhys=%p\n",
return VERR_INVALID_PARAMETER;
}
{
return VERR_PAGE_COUNT_OUT_OF_RANGE;
}
/*
* Let IPRT do the job.
*/
if (RT_SUCCESS(rc))
{
int rc2;
if (RT_SUCCESS(rc))
{
if (!rc)
{
return 0;
}
}
}
return rc;
}
/**
* Frees memory allocated using SUPR0ContAlloc().
*
* @returns IPRT status code.
* @param pSession The session to which the memory was allocated.
* @param uPtr Pointer to the memory (ring-3 or ring-0).
*/
{
}
/**
* Allocates a chunk of page aligned memory with fixed physical backing below 4GB.
*
* The memory isn't zeroed.
*
* @returns IPRT status code.
* @param pSession Session data.
* @param cPages Number of pages to allocate.
* @param ppvR0 Where to put the address of Ring-0 mapping of the allocated memory.
* @param ppvR3 Where to put the address of Ring-3 mapping of the allocated memory.
* @param paPages Where to put the physical addresses of allocated memory.
*/
SUPR0DECL(int) SUPR0LowAlloc(PSUPDRVSESSION pSession, uint32_t cPages, PRTR0PTR ppvR0, PRTR3PTR ppvR3, PRTHCPHYS paPages)
{
unsigned iPage;
int rc;
LogFlow(("SUPR0LowAlloc: pSession=%p cPages=%d ppvR3=%p ppvR0=%p paPages=%p\n", pSession, cPages, ppvR3, ppvR0, paPages));
/*
* Validate input.
*/
{
Log(("Null pointer. All of these should be set: pSession=%p ppvR3=%p ppvR0=%p paPages=%p\n",
return VERR_INVALID_PARAMETER;
}
{
return VERR_PAGE_COUNT_OUT_OF_RANGE;
}
/*
* Let IPRT do the work.
*/
if (RT_SUCCESS(rc))
{
int rc2;
if (RT_SUCCESS(rc))
{
if (!rc)
{
{
}
return 0;
}
}
}
return rc;
}
/**
* Frees memory allocated using SUPR0LowAlloc().
*
* @returns IPRT status code.
* @param pSession The session to which the memory was allocated.
* @param uPtr Pointer to the memory (ring-3 or ring-0).
*/
{
}
/**
* Allocates a chunk of memory with both R0 and R3 mappings.
* The memory is fixed and it's possible to query the physical addresses using SUPR0MemGetPhys().
*
* @returns IPRT status code.
* @param pSession The session to associated the allocation with.
* @param cb Number of bytes to allocate.
* @param ppvR0 Where to store the address of the Ring-0 mapping.
* @param ppvR3 Where to store the address of the Ring-3 mapping.
*/
{
int rc;
/*
* Validate input.
*/
{
return VERR_INVALID_PARAMETER;
}
/*
* Let IPRT do the work.
*/
if (RT_SUCCESS(rc))
{
int rc2;
if (RT_SUCCESS(rc))
{
if (!rc)
{
return VINF_SUCCESS;
}
}
}
return rc;
}
/**
* Get the physical addresses of memory allocated using SUPR0MemAlloc().
*
* @returns IPRT status code.
* @param pSession The session to which the memory was allocated.
* @param uPtr The Ring-0 or Ring-3 address returned by SUPR0MemAlloc().
* @param paPages Where to store the physical addresses.
*/
SUPR0DECL(int) SUPR0MemGetPhys(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr, PSUPPAGE paPages) /** @todo switch this bugger to RTHCPHYS */
{
/*
* Validate input.
*/
/*
* Search for the address.
*/
{
{
unsigned i;
{
)
)
{
{
}
return VINF_SUCCESS;
}
}
}
}
return VERR_INVALID_PARAMETER;
}
/**
* Free memory allocated by SUPR0MemAlloc().
*
* @returns IPRT status code.
* @param pSession The session owning the allocation.
* @param uPtr The Ring-0 or Ring-3 address returned by SUPR0MemAlloc().
*/
{
}
/**
*
* The memory is fixed and it's possible to query the physical addresses using
* SUPR0MemGetPhys().
*
* @returns IPRT status code.
* @param pSession The session to associated the allocation with.
* @param cPages The number of pages to allocate.
* @param fFlags Flags, reserved for the future. Must be zero.
* @param ppvR3 Where to store the address of the Ring-3 mapping.
* NULL if no ring-3 mapping.
* @param ppvR3 Where to store the address of the Ring-0 mapping.
* NULL if no ring-0 mapping.
* @param paPages Where to store the addresses of the pages. Optional.
*/
SUPR0DECL(int) SUPR0PageAllocEx(PSUPDRVSESSION pSession, uint32_t cPages, uint32_t fFlags, PRTR3PTR ppvR3, PRTR0PTR ppvR0, PRTHCPHYS paPages)
{
int rc;
/*
* Validate input. The allowed allocation size must be at least equal to the maximum guest VRAM size.
*/
{
Log(("SUPR0PageAlloc: Illegal request cb=%u; must be greater than 0 and smaller than %uMB (VBOX_MAX_ALLOC_PAGE_COUNT pages).\n", cPages, VBOX_MAX_ALLOC_PAGE_COUNT * (_1M / _4K)));
return VERR_PAGE_COUNT_OUT_OF_RANGE;
}
/*
* Let IPRT do the work.
*/
if (ppvR0)
else
if (RT_SUCCESS(rc))
{
int rc2;
if (ppvR3)
else
if (RT_SUCCESS(rc))
{
if (!rc)
{
if (ppvR3)
if (ppvR0)
if (paPages)
{
while (iPage-- > 0)
{
}
}
return VINF_SUCCESS;
}
}
}
return rc;
}
/**
* Maps a chunk of memory previously allocated by SUPR0PageAllocEx into kernel
* space.
*
* @returns IPRT status code.
* @param pSession The session to associated the allocation with.
* @param pvR3 The ring-3 address returned by SUPR0PageAllocEx.
* @param offSub Where to start mapping. Must be page aligned.
* @param cbSub How much to map. Must be page aligned.
* @param fFlags Flags, MBZ.
* @param ppvR0 Where to return the address of the ring-0 mapping on
* success.
*/
SUPR0DECL(int) SUPR0PageMapKernel(PSUPDRVSESSION pSession, RTR3PTR pvR3, uint32_t offSub, uint32_t cbSub,
{
int rc;
LogFlow(("SUPR0PageMapKernel: pSession=%p pvR3=%p offSub=%#x cbSub=%#x\n", pSession, pvR3, offSub, cbSub));
/*
* Validate input. The allowed allocation size must be at least equal to the maximum guest VRAM size.
*/
/*
* Find the memory object.
*/
{
{
unsigned i;
{
{
break;
}
}
}
}
if (hMemObj != NIL_RTR0MEMOBJ)
{
/*
* Do some further input validations before calling IPRT.
* (Cleanup is done indirectly by telling RTR0MemObjFree to include mappings.)
*/
{
if (RT_SUCCESS(rc))
}
else
}
return rc;
}
/**
* Changes the page level protection of one or more pages previously allocated
* by SUPR0PageAllocEx.
*
* @returns IPRT status code.
* @param pSession The session to associated the allocation with.
* @param pvR3 The ring-3 address returned by SUPR0PageAllocEx.
* NIL_RTR3PTR if the ring-3 mapping should be unaffected.
* @param pvR0 The ring-0 address returned by SUPR0PageAllocEx.
* NIL_RTR0PTR if the ring-0 mapping should be unaffected.
* @param offSub Where to start changing. Must be page aligned.
* @param cbSub How much to change. Must be page aligned.
* @param fProt The new page level protection, see RTMEM_PROT_*.
*/
SUPR0DECL(int) SUPR0PageProtect(PSUPDRVSESSION pSession, RTR3PTR pvR3, RTR0PTR pvR0, uint32_t offSub, uint32_t cbSub, uint32_t fProt)
{
int rc;
LogFlow(("SUPR0PageProtect: pSession=%p pvR3=%p pvR0=%p offSub=%#x cbSub=%#x fProt-%#x\n", pSession, pvR3, pvR0, offSub, cbSub, fProt));
/*
* Validate input. The allowed allocation size must be at least equal to the maximum guest VRAM size.
*/
AssertReturn(!(fProt & ~(RTMEM_PROT_READ | RTMEM_PROT_WRITE | RTMEM_PROT_EXEC | RTMEM_PROT_NONE)), VERR_INVALID_PARAMETER);
/*
* Find the memory object.
*/
{
{
unsigned i;
{
|| pvR3 == NIL_RTR3PTR)
&& ( pvR0 == NIL_RTR0PTR
&& ( pvR3 == NIL_RTR3PTR
{
if (pvR0 != NIL_RTR0PTR)
if (pvR3 != NIL_RTR3PTR)
break;
}
}
}
}
if ( hMemObjR0 != NIL_RTR0MEMOBJ
|| hMemObjR3 != NIL_RTR0MEMOBJ)
{
/*
* Do some further input validations before calling IPRT.
*/
{
rc = VINF_SUCCESS;
if (hMemObjR3 != NIL_RTR0PTR)
}
else
}
return rc;
}
/**
* Free memory allocated by SUPR0PageAlloc() and SUPR0PageAllocEx().
*
* @returns IPRT status code.
* @param pSession The session owning the allocation.
* @param pvR3 The Ring-3 address returned by SUPR0PageAlloc() or
* SUPR0PageAllocEx().
*/
{
}
/**
* Gets the paging mode of the current CPU.
*
* @returns Paging mode, SUPPAGEINGMODE_INVALID on error.
*/
{
else
{
uint32_t fNXEPlusLMA = 0;
if (cr4 & X86_CR4_PAE)
{
{
fNXEPlusLMA |= RT_BIT(0);
}
}
{
case 0:
break;
case X86_CR4_PGE:
break;
case X86_CR4_PAE:
break;
case X86_CR4_PAE | RT_BIT(0):
break;
case X86_CR4_PAE | X86_CR4_PGE:
break;
break;
break;
break;
break;
break;
default:
break;
}
}
return enmMode;
}
/**
* Enables or disabled hardware virtualization extensions using native OS APIs.
*
* @returns VBox status code.
* @retval VINF_SUCCESS on success.
* @retval VERR_NOT_SUPPORTED if not supported by the native OS.
*
* @param fEnable Whether to enable or disable.
*/
{
#ifdef RT_OS_DARWIN
return supdrvOSEnableVTx(fEnable);
#else
return VERR_NOT_SUPPORTED;
#endif
}
/** @todo document me */
{
/*
* Input validation.
*/
*pfCaps = 0;
if (ASMHasCpuId())
{
/* Query AMD features. */
)
{
if ( (u32FeaturesECX & X86_CPUID_FEATURE_ECX_VMX)
)
{
/*
* Both the LOCK and VMXON bit must be set; otherwise VMXON will generate a #GP.
* Once the lock bit is set, this MSR can no longer be modified.
*/
)
{
*pfCaps |= SUPVTCAPS_VT_X;
{
}
return VINF_SUCCESS;
}
return VERR_VMX_MSR_LOCKED_OR_DISABLED;
}
return VERR_VMX_NO_VMX;
}
if ( u32VendorEBX == X86_CPUID_VENDOR_AMD_EBX
)
{
)
{
/* Check if SVM is disabled */
if (!(val & MSR_K8_VM_CR_SVM_DISABLE))
{
*pfCaps |= SUPVTCAPS_AMD_V;
/* Query AMD features. */
return VINF_SUCCESS;
}
return VERR_SVM_DISABLED;
}
return VERR_SVM_NO_SVM;
}
}
return VERR_UNSUPPORTED_CPU;
}
/**
* (Re-)initializes the per-cpu structure prior to starting or resuming the GIP
* updating.
*
* @param pGipCpu The per CPU structure for this CPU.
* @param u64NanoTS The current time.
*/
{
}
/**
* Set the current TSC and NanoTS value for the CPU.
*
* @param idCpu The CPU ID. Unused - we have to use the APIC ID.
* @param pvUser1 Pointer to the ring-0 GIP mapping.
* @param pvUser2 Pointer to the variable holding the current time.
*/
{
}
/**
*
* @returns IPRT status code.
* @param pSession Session to which the GIP mapping should belong.
* @param ppGipR3 Where to store the address of the ring-3 mapping. (optional)
* @param pHCPhysGip Where to store the physical address. (optional)
*
* @remark There is no reference counting on the mapping, so one call to this function
* count globally as one reference. One call to SUPR0GipUnmap() is will unmap GIP
* and remove the session as a GIP user.
*/
{
int rc;
/*
* Validate
*/
#ifdef SUPDRV_USE_MUTEX_FOR_GIP
#else
#endif
{
/*
* Map it?
*/
rc = VINF_SUCCESS;
if (ppGipR3)
{
if (RT_SUCCESS(rc))
}
/*
* Get physical address.
*/
/*
* Reference globally.
*/
{
{
unsigned i;
LogFlow(("SUPR0GipMap: Resumes GIP updating\n"));
/*
* Try bump up the system timer resolution.
* The more interrupts the better...
*/
)
{
}
{
}
|| RTMpGetOnlineCount() == 1)
else
#ifndef DO_NOT_START_GIP
#endif
rc = VINF_SUCCESS;
}
}
}
else
{
Log(("SUPR0GipMap: GIP is not available!\n"));
}
#ifdef SUPDRV_USE_MUTEX_FOR_GIP
#else
#endif
/*
* Write returns.
*/
if (pHCPhysGip)
*pHCPhysGip = HCPhys;
if (ppGipR3)
#ifdef DEBUG_DARWIN_GIP
OSDBGPRINT(("SUPR0GipMap: returns %d *pHCPhysGip=%lx pGipR3=%p\n", rc, (unsigned long)HCPhys, (void *)pGipR3));
#else
LogFlow(( "SUPR0GipMap: returns %d *pHCPhysGip=%lx pGipR3=%p\n", rc, (unsigned long)HCPhys, (void *)pGipR3));
#endif
return rc;
}
/**
* Unmaps any user mapping of the GIP and terminates all GIP access
* from this session.
*
* @returns IPRT status code.
* @param pSession Session to which the GIP mapping should belong.
*/
{
int rc = VINF_SUCCESS;
#ifdef DEBUG_DARWIN_GIP
OSDBGPRINT(("SUPR0GipUnmap: pSession=%p pGip=%p GipMapObjR3=%p\n",
pSession->GipMapObjR3));
#else
#endif
#ifdef SUPDRV_USE_MUTEX_FOR_GIP
#else
#endif
/*
* Unmap anything?
*/
{
if (RT_SUCCESS(rc))
}
/*
* Dereference global GIP.
*/
{
pSession->fGipReferenced = 0;
{
LogFlow(("SUPR0GipUnmap: Suspends GIP updating\n"));
#ifndef DO_NOT_START_GIP
#endif
{
}
}
}
#ifdef SUPDRV_USE_MUTEX_FOR_GIP
#else
#endif
return rc;
}
/**
* Gets the GIP pointer.
*
* @returns Pointer to the GIP or NULL.
*/
{
return g_pSUPGlobalInfoPage;
}
/**
* Register a component factory with the support driver.
*
* This is currently restricted to kernel sessions only.
*
* @returns VBox status code.
* @retval VINF_SUCCESS on success.
* @retval VERR_NO_MEMORY if we're out of memory.
* @retval VERR_ALREADY_EXISTS if the factory has already been registered.
* @retval VERR_ACCESS_DENIED if it isn't a kernel session.
* @retval VERR_INVALID_PARAMETER on invalid parameter.
* @retval VERR_INVALID_POINTER on invalid pointer parameter.
*
* @param pSession The SUPDRV session (must be a ring-0 session).
* @param pFactory Pointer to the component factory registration structure.
*
* @remarks This interface is also available via SUPR0IdcComponentRegisterFactory.
*/
{
const char *psz;
int rc;
/*
* Validate parameters.
*/
/*
* Allocate and initialize a new registration structure.
*/
if (pNewReg)
{
/*
* Add it to the tail of the list after checking for prior registration.
*/
if (RT_SUCCESS(rc))
{
{
}
if (!pCur)
{
if (pPrev)
else
rc = VINF_SUCCESS;
}
else
}
if (RT_FAILURE(rc))
}
else
rc = VERR_NO_MEMORY;
return rc;
}
/**
* Deregister a component factory.
*
* @returns VBox status code.
* @retval VINF_SUCCESS on success.
* @retval VERR_NOT_FOUND if the factory wasn't registered.
* @retval VERR_ACCESS_DENIED if it isn't a kernel session.
* @retval VERR_INVALID_PARAMETER on invalid parameter.
* @retval VERR_INVALID_POINTER on invalid pointer parameter.
*
* @param pSession The SUPDRV session (must be a ring-0 session).
* @param pFactory Pointer to the component factory registration structure
* previously passed SUPR0ComponentRegisterFactory().
*
* @remarks This interface is also available via SUPR0IdcComponentDeregisterFactory.
*/
{
int rc;
/*
* Validate parameters.
*/
/*
* Take the lock and look for the registration record.
*/
if (RT_SUCCESS(rc))
{
{
}
if (pCur)
{
if (!pPrev)
else
rc = VINF_SUCCESS;
}
else
rc = VERR_NOT_FOUND;
}
return rc;
}
/**
* Queries a component factory.
*
* @returns VBox status code.
* @retval VERR_INVALID_PARAMETER on invalid parameter.
* @retval VERR_INVALID_POINTER on invalid pointer parameter.
* @retval VERR_SUPDRV_COMPONENT_NOT_FOUND if the component factory wasn't found.
* @retval VERR_SUPDRV_INTERFACE_NOT_SUPPORTED if the interface wasn't supported.
*
* @param pSession The SUPDRV session.
* @param pszName The name of the component factory.
* @param pszInterfaceUuid The UUID of the factory interface (stringified).
* @param ppvFactoryIf Where to store the factory interface.
*/
SUPR0DECL(int) SUPR0ComponentQueryFactory(PSUPDRVSESSION pSession, const char *pszName, const char *pszInterfaceUuid, void **ppvFactoryIf)
{
const char *pszEnd;
int rc;
/*
* Validate parameters.
*/
*ppvFactoryIf = NULL;
/*
* Take the lock and try all factories by this name.
*/
if (RT_SUCCESS(rc))
{
while (pCur)
{
{
void *pvFactory = pCur->pFactory->pfnQueryFactoryInterface(pCur->pFactory, pSession, pszInterfaceUuid);
if (pvFactory)
{
rc = VINF_SUCCESS;
break;
}
}
/* next */
}
}
return rc;
}
/**
* Adds a memory object to the session.
*
* @returns IPRT status code.
* @param pMem Memory tracking structure containing the
* information to track.
* @param pSession The session.
*/
{
/*
* Find free entry and record the allocation.
*/
{
{
unsigned i;
{
{
return VINF_SUCCESS;
}
}
AssertFailed(); /* !!this can't be happening!!! */
}
}
/*
* Need to allocate a new bundle.
* Insert into the last entry in the bundle.
*/
if (!pBundle)
return VERR_NO_MEMORY;
/* take last entry. */
/* insert into list. */
return VINF_SUCCESS;
}
/**
* Releases a memory object referenced by pointer and type.
*
* @returns IPRT status code.
* @param pSession Session data.
* @param uPtr Pointer to memory. This is matched against both the R0 and R3 addresses.
* @param eType Memory type.
*/
{
/*
* Validate input.
*/
if (!uPtr)
{
return VERR_INVALID_PARAMETER;
}
/*
* Search for the address.
*/
{
{
unsigned i;
{
)
{
/* Make a copy of it and release it outside the spinlock. */
{
}
{
}
return VINF_SUCCESS;
}
}
}
}
return VERR_INVALID_PARAMETER;
}
/**
* Opens an image. If it's the first time it's opened the call must upload
* the bits using the supdrvIOCtl_LdrLoad() / SUPDRV_IOCTL_LDR_LOAD function.
*
* This is the 1st step of the loading.
*
* @returns IPRT status code.
* @param pDevExt Device globals.
* @param pSession Session data.
* @param pReq The open request.
*/
{
int rc;
void *pv;
LogFlow(("supdrvIOCtl_LdrOpen: szName=%s cbImageWithTabs=%d\n", pReq->u.In.szName, pReq->u.In.cbImageWithTabs));
/*
* Check if we got an instance of the image already.
*/
{
{
/** @todo check cbImageBits and cbImageWithTabs here, if they differs that indicates that the images are different. */
return VINF_SUCCESS;
}
}
/* (not found - add it!) */
/*
* Allocate memory.
*/
if (!pv)
{
Log(("supdrvIOCtl_LdrOpen: RTMemAlloc() failed\n"));
return /*VERR_NO_MEMORY*/ VERR_INTERNAL_ERROR_2;
}
/*
* Setup and link in the LDR stuff.
*/
/*
* Try load it using the native loader, if that isn't supported, fall back
* on the older method.
*/
if (rc == VERR_NOT_SUPPORTED)
{
}
if (RT_FAILURE(rc))
{
return rc;
}
/*
* Link it.
*/
#if defined(RT_OS_WINDOWS) && defined(DEBUG)
#endif
return VINF_SUCCESS;
}
/**
* Worker that validates a pointer to an image entrypoint.
*
* @returns IPRT status code.
* @param pDevExt The device globals.
* @param pImage The loader image.
* @param pv The pointer into the image.
* @param fMayBeNull Whether it may be NULL.
* @param pszWhat What is this entrypoint? (for logging)
* @param pbImageBits The image bits prepared by ring-3.
*
* @remarks Will leave the lock on failure.
*/
{
if (!fMayBeNull || pv)
{
{
return VERR_INVALID_PARAMETER;
}
{
if (RT_FAILURE(rc))
{
return rc;
}
}
}
return VINF_SUCCESS;
}
/**
* Loads the image bits.
*
* This is the 2nd step of the loading.
*
* @returns IPRT status code.
* @param pDevExt Device globals.
* @param pSession Session data.
* @param pReq The request.
*/
{
int rc;
LogFlow(("supdrvIOCtl_LdrLoad: pvImageBase=%p cbImageWithBits=%d\n", pReq->u.In.pvImageBase, pReq->u.In.cbImageWithTabs));
/*
* Find the ldr image.
*/
if (!pUsage)
{
Log(("SUP_IOCTL_LDR_LOAD: couldn't find image!\n"));
return VERR_INVALID_HANDLE;
}
/*
* Validate input.
*/
{
Log(("SUP_IOCTL_LDR_LOAD: image size mismatch!! %d(prep) != %d(load) or %d != %d\n",
return VERR_INVALID_HANDLE;
}
{
if (uState != SUP_IOCTL_LDR_LOAD)
return VERR_ALREADY_LOADED;
}
{
case SUPLDRLOADEP_NOTHING:
break;
case SUPLDRLOADEP_VMMR0:
rc = supdrvLdrValidatePointer( pDevExt, pImage, pReq->u.In.EP.VMMR0.pvVMMR0, false, pReq->u.In.abImage, "pvVMMR0");
if (RT_SUCCESS(rc))
rc = supdrvLdrValidatePointer(pDevExt, pImage, pReq->u.In.EP.VMMR0.pvVMMR0EntryInt, false, pReq->u.In.abImage, "pvVMMR0EntryInt");
if (RT_SUCCESS(rc))
rc = supdrvLdrValidatePointer(pDevExt, pImage, pReq->u.In.EP.VMMR0.pvVMMR0EntryFast, false, pReq->u.In.abImage, "pvVMMR0EntryFast");
if (RT_SUCCESS(rc))
rc = supdrvLdrValidatePointer(pDevExt, pImage, pReq->u.In.EP.VMMR0.pvVMMR0EntryEx, false, pReq->u.In.abImage, "pvVMMR0EntryEx");
if (RT_FAILURE(rc))
return rc;
break;
case SUPLDRLOADEP_SERVICE:
rc = supdrvLdrValidatePointer(pDevExt, pImage, pReq->u.In.EP.Service.pfnServiceReq, false, pReq->u.In.abImage, "pfnServiceReq");
if (RT_FAILURE(rc))
return rc;
{
Log(("Out of range (%p LB %#x): apvReserved={%p,%p,%p} MBZ!\n",
return VERR_INVALID_PARAMETER;
}
break;
default:
return VERR_INVALID_PARAMETER;
}
rc = supdrvLdrValidatePointer(pDevExt, pImage, pReq->u.In.pfnModuleInit, true, pReq->u.In.abImage, "pfnModuleInit");
if (RT_FAILURE(rc))
return rc;
rc = supdrvLdrValidatePointer(pDevExt, pImage, pReq->u.In.pfnModuleTerm, true, pReq->u.In.abImage, "pfnModuleTerm");
if (RT_FAILURE(rc))
return rc;
/*
* Allocate and copy the tables.
*/
{
if (pImage->pachStrTab)
else
}
{
else
}
/*
* Copy the bits / complete native loading.
*/
if (RT_SUCCESS(rc))
{
else
}
/*
* Update any entry points.
*/
if (RT_SUCCESS(rc))
{
{
default:
case SUPLDRLOADEP_NOTHING:
rc = VINF_SUCCESS;
break;
case SUPLDRLOADEP_VMMR0:
rc = supdrvLdrSetVMMR0EPs(pDevExt, pReq->u.In.EP.VMMR0.pvVMMR0, pReq->u.In.EP.VMMR0.pvVMMR0EntryInt,
break;
case SUPLDRLOADEP_SERVICE:
rc = VINF_SUCCESS;
break;
}
}
/*
* On success call the module initialization.
*/
{
}
if (RT_FAILURE(rc))
{
}
return rc;
}
/**
* Frees a previously loaded (prep'ed) image.
*
* @returns IPRT status code.
* @param pDevExt Device globals.
* @param pSession Session data.
* @param pReq The request.
*/
{
int rc;
/*
* Find the ldr image.
*/
pUsagePrev = NULL;
{
pUsagePrev = pUsage;
}
if (!pUsage)
{
Log(("SUP_IOCTL_LDR_FREE: couldn't find image!\n"));
return VERR_INVALID_HANDLE;
}
/*
* Check if we can remove anything.
*/
rc = VINF_SUCCESS;
{
/*
* Check if there are any objects with destructors in the image, if
* so leave it for the session cleanup routine so we get a chance to
* clean things up in the right order and not leave them all dangling.
*/
{
{
break;
}
}
else
{
if (RT_UNLIKELY((uintptr_t)pGenUsage->pObj->pfnDestructor - (uintptr_t)pImage->pvImage < pImage->cbImageBits))
{
break;
}
}
if (rc == VINF_SUCCESS)
{
/* unlink it */
if (pUsagePrev)
else
/* free it */
/*
* Dereference the image.
*/
else
}
else
{
}
}
else
{
/*
* Dereference both image and usage.
*/
}
return rc;
}
/**
* Gets the address of a symbol in an open image.
*
* @returns IPRT status code.
* @param pDevExt Device globals.
* @param pSession Session data.
* @param pReq The request buffer.
*/
static int supdrvIOCtl_LdrGetSymbol(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPLDRGETSYMBOL pReq)
{
uint32_t i;
const char *pchStrings;
int rc = VERR_GENERAL_FAILURE;
Log3(("supdrvIOCtl_LdrGetSymbol: pvImageBase=%p szSymbol=\"%s\"\n", pReq->u.In.pvImageBase, pReq->u.In.szSymbol));
/*
* Find the ldr image.
*/
if (!pUsage)
{
Log(("SUP_IOCTL_LDR_GET_SYMBOL: couldn't find image!\n"));
return VERR_INVALID_HANDLE;
}
{
return VERR_ALREADY_LOADED;
}
/*
* Search the symbol strings.
*
* Note! The int32_t is for native loading on solaris where the data
* and text segments are in very different places.
*/
{
{
rc = VINF_SUCCESS;
break;
}
}
return rc;
}
/**
* Gets the address of a symbol in an open image or the support driver.
*
* @returns VINF_SUCCESS on success.
* @returns
* @param pDevExt Device globals.
* @param pSession Session data.
* @param pReq The request buffer.
*/
static int supdrvIDC_LdrGetSymbol(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPDRVIDCREQGETSYM pReq)
{
int rc = VINF_SUCCESS;
char const *pszEnd;
uint32_t i;
/*
* Input validation.
*/
if (pszModule)
{
}
Log3(("supdrvIDC_LdrGetSymbol: pszModule=%p:{%s} pszSymbol=%p:{%s}\n", pszModule, pszModule, pszSymbol, pszSymbol));
if ( !pszModule
{
/*
* Search the support driver export table.
*/
for (i = 0; i < RT_ELEMENTS(g_aFunctions); i++)
{
break;
}
}
else
{
/*
* Find the loader image.
*/
break;
{
/*
* Search the symbol strings.
*/
{
{
/*
* Found it! Calc the symbol address and add a reference to the module.
*/
break;
}
}
}
else
}
return rc;
}
/**
* Updates the VMMR0 entry point pointers.
*
* @returns IPRT status code.
* @param pDevExt Device globals.
* @param pSession Session data.
* @param pVMMR0 VMMR0 image handle.
* @param pvVMMR0EntryInt VMMR0EntryInt address.
* @param pvVMMR0EntryFast VMMR0EntryFast address.
* @param pvVMMR0EntryEx VMMR0EntryEx address.
* @remark Caller must own the loader mutex.
*/
static int supdrvLdrSetVMMR0EPs(PSUPDRVDEVEXT pDevExt, void *pvVMMR0, void *pvVMMR0EntryInt, void *pvVMMR0EntryFast, void *pvVMMR0EntryEx)
{
int rc = VINF_SUCCESS;
/*
* Check if not yet set.
*/
{
}
else
{
/*
* Return failure or success depending on whether the values match or not.
*/
{
AssertMsgFailed(("SUP_IOCTL_LDR_SETR0EP: Already set pointing to a different module!\n"));
}
}
return rc;
}
/**
* Unsets the VMMR0 entry point installed by supdrvLdrSetR0EP.
*
* @param pDevExt Device globals.
*/
{
}
/**
* Adds a usage reference in the specified session of an image.
*
* Called while owning the loader semaphore.
*
* @returns VINF_SUCCESS on success and VERR_NO_MEMORY on failure.
* @param pSession Session in question.
* @param pImage Image which the session is using.
*/
{
/*
* Referenced it already?
*/
while (pUsage)
{
{
return VINF_SUCCESS;
}
}
/*
* Allocate new usage record.
*/
return VINF_SUCCESS;
}
/**
* Frees a load image.
*
* @param pDevExt Pointer to device extension.
* @param pImage Pointer to the image we're gonna free.
* This image must exit!
* @remark The caller MUST own SUPDRVDEVEXT::mtxLdr!
*/
{
/* find it - arg. should've used doubly linked list. */
pImagePrev = NULL;
{
}
/* unlink */
if (pImagePrev)
else
/* check if this is VMMR0.r0 unset its entry point pointers. */
/* check for objects with destructors in this image. (Shouldn't happen.) */
{
unsigned cObjs = 0;
{
cObjs++;
}
if (cObjs)
}
/* call termination function if fully loaded. */
if ( pImage->pfnModuleTerm
{
pImage->pfnModuleTerm();
}
/* do native unload if appropriate. */
/* free the image */
}
/**
* Acquires the loader lock.
*
* @returns IPRT status code.
* @param pDevExt The device extension.
*/
{
#ifdef SUPDRV_USE_MUTEX_FOR_LDR
#else
#endif
return rc;
}
/**
* Releases the loader lock.
*
* @returns IPRT status code.
* @param pDevExt The device extension.
*/
{
#ifdef SUPDRV_USE_MUTEX_FOR_LDR
#else
#endif
}
/**
* Implements the service call request.
*
* @returns VBox status code.
* @param pDevExt The device extension.
* @param pSession The calling session.
* @param pReq The request packet, valid.
*/
static int supdrvIOCtl_CallServiceModule(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPCALLSERVICE pReq)
{
#if !defined(RT_OS_WINDOWS) || defined(DEBUG)
int rc;
/*
* Find the module first in the module referenced by the calling session.
*/
if (RT_SUCCESS(rc))
{
{
break;
}
if (pfnServiceReqHandler)
{
/*
* Call it.
*/
else
rc = pfnServiceReqHandler(pSession, pReq->u.In.uOperation, pReq->u.In.u64Arg, (PSUPR0SERVICEREQHDR)&pReq->abReqPkt[0]);
}
else
}
/* log it */
if ( RT_FAILURE(rc)
&& rc != VERR_INTERRUPTED
&& rc != VERR_TIMEOUT)
Log(("SUP_IOCTL_CALL_SERVICE: rc=%Rrc op=%u out=%u arg=%RX64 p/t=%RTproc/%RTthrd\n",
rc, pReq->u.In.uOperation, pReq->Hdr.cbOut, pReq->u.In.u64Arg, RTProcSelf(), RTThreadNativeSelf()));
else
Log4(("SUP_IOCTL_CALL_SERVICE: rc=%Rrc op=%u out=%u arg=%RX64 p/t=%RTproc/%RTthrd\n",
rc, pReq->u.In.uOperation, pReq->Hdr.cbOut, pReq->u.In.u64Arg, RTProcSelf(), RTThreadNativeSelf()));
return rc;
#else /* RT_OS_WINDOWS && !DEBUG */
return VERR_NOT_IMPLEMENTED;
#endif /* RT_OS_WINDOWS && !DEBUG */
}
/**
* Implements the logger settings request.
*
* @returns VBox status code.
* @param pDevExt The device extension.
* @param pSession The caller's session.
* @param pReq The request.
*/
static int supdrvIOCtl_LoggerSettings(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPLOGGERSETTINGS pReq)
{
int rc;
/*
* Some further validation.
*/
{
break;
return VERR_INVALID_PARAMETER;
return VERR_ACCESS_DENIED;
break;
default:
return VERR_INTERNAL_ERROR;
}
/*
* Get the logger.
*/
{
break;
break;
default:
return VERR_INTERNAL_ERROR;
}
/*
* Do the job.
*/
{
if (pLogger)
{
if (RT_SUCCESS(rc))
}
else
rc = VERR_NOT_FOUND;
break;
{
if (pLogger)
else
{
static const char * const s_apszGroups[] = VBOX_LOGGROUP_NAMES;
0 /* fFlags */,
? "VBOX_LOG"
: "VBOX_RELEASE_LOG",
NULL);
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
{
break;
break;
}
}
}
}
break;
}
{
break;
break;
}
break;
default:
{
break;
}
}
return rc;
}
/**
* Creates the GIP.
*
* @returns VBox status code.
* @param pDevExt Instance data. GIP stuff may be updated.
*/
{
unsigned cCpus;
int rc;
LogFlow(("supdrvGipCreate:\n"));
/* assert order */
/*
* Check the CPU count.
*/
cCpus = RTMpGetArraySize();
if ( cCpus > RTCPUSET_MAX_CPUS
{
SUPR0Printf("VBoxDrv: Too many CPUs (%u) for the GIP (max %u)\n", cCpus, RT_MIN(RTCPUSET_MAX_CPUS, 256));
return VERR_TOO_MANY_CPUS;
}
/*
* Allocate a contiguous set of pages with a default kernel mapping.
*/
rc = RTR0MemObjAllocCont(&pDevExt->GipMemObj, RT_UOFFSETOF(SUPGLOBALINFOPAGE, aCPUs[cCpus]), false /*fExecutable*/);
if (RT_FAILURE(rc))
{
return rc;
}
/*
* Find a reasonable update interval and initialize the structure.
*/
supdrvGipInit(pDevExt, pGip, HCPhysGip, RTTimeSystemNanoTS(), 1000000000 / u32Interval /*=Hz*/, cCpus);
/*
* Create the timer.
* If CPU_ALL isn't supported we'll have to fall back to synchronous mode.
*/
{
rc = RTTimerCreateEx(&pDevExt->pGipTimer, u32Interval, RTTIMER_FLAGS_CPU_ALL, supdrvGipAsyncTimer, pDevExt);
if (rc == VERR_NOT_SUPPORTED)
{
OSDBGPRINT(("supdrvGipCreate: omni timer not supported, falling back to synchronous mode\n"));
}
}
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
/*
* We're good.
*/
return VINF_SUCCESS;
}
}
else
}
else
{
OSDBGPRINT(("supdrvGipCreate: failed create GIP timer at %u ns interval. rc=%Rrc\n", u32Interval, rc));
}
return rc;
}
/**
* Terminates the GIP.
*
* @param pDevExt Instance data. GIP stuff may be updated.
*/
{
int rc;
#ifdef DEBUG_DARWIN_GIP
#endif
/*
* Invalid the GIP data.
*/
{
}
/*
* Destroy the timer and free the GIP memory object.
*/
{
}
{
}
/*
* Finally, make sure we've release the system timer resolution request
* if one actually succeeded and is still pending.
*/
{
}
}
/**
* Timer callback function sync GIP mode.
* @param pTimer The timer.
* @param pvUser The device extension.
*/
{
}
/**
* Timer callback function for async GIP mode.
* @param pTimer The timer.
* @param pvUser The device extension.
*/
{
/** @todo reset the transaction number and whatnot when iTick == 1. */
else
}
/**
* Finds our (@a idCpu) entry, or allocates a new one if not found.
*
* @returns Index of the CPU in the cache set.
* @param pGip The GIP.
* @param idCpu The CPU ID.
*/
{
/*
* ASSUMES that CPU IDs are constant.
*/
return i;
cTries = 0;
do
{
{
bool fRc;
if (fRc)
return i;
}
} while (cTries++ < 32);
return i - 1;
}
/**
* The calling CPU should be accounted as online, update GIP accordingly.
*
* This is used by supdrvGipMpEvent as well as the supdrvGipCreate.
*
* @param pGip The GIP.
* @param idCpu The CPU ID.
*/
{
int iCpuSet = 0;
uint32_t i = 0;
/*
* Update the globals.
*/
if (iCpuSet >= 0)
{
}
/*
* Update the entry.
*/
idApic = ASMGetApicId();
/*
* Update the APIC ID and CPU set index mappings.
*/
/* commit it */
}
/**
* The CPU should be accounted as offline, update the GIP accordingly.
*
* This is used by supdrvGipMpEvent.
*
* @param pGip The GIP.
* @param idCpu The CPU ID.
*/
{
int iCpuSet;
unsigned i;
AssertReturnVoid(iCpuSet >= 0);
/* commit it */
}
/**
* Multiprocessor event notification callback.
*
* This is used to make sure that the GIP master gets passed on to
* another CPU. It also updates the associated CPU data.
*
* @param enmEvent The event.
* @param idCpu The cpu it applies to.
* @param pvUser Pointer to the device extension.
*/
{
/*
* Update the GIP CPU data.
*/
if (pGip)
{
switch (enmEvent)
{
case RTMPEVENT_ONLINE:
break;
case RTMPEVENT_OFFLINE:
break;
}
}
/*
* Make sure there is a master GIP.
*/
if (enmEvent == RTMPEVENT_OFFLINE)
{
if (idGipMaster == idCpu)
{
/*
* Find a new GIP master.
*/
bool fIgnored;
unsigned i;
for (i = 0; i < RTCPUSET_MAX_CPUS; i++)
{
&& idCurCpu != idGipMaster)
{
break;
}
}
}
}
}
/**
* Callback used by supdrvDetermineAsyncTSC to read the TSC on a CPU.
*
* @param idCpu Ignored.
* @param pvUser1 Where to put the TSC.
* @param pvUser2 Ignored.
*/
static DECLCALLBACK(void) supdrvDetermineAsyncTscWorker(RTCPUID idCpu, void *pvUser1, void *pvUser2)
{
#if 1
#else
#endif
}
/**
* Determine if Async GIP mode is required because of TSC drift.
*
* (TSC) runs never backwards, that is, a read operation to the counter should return
* a bigger value than any previous read operation. This is guaranteed by the latest
* AMD CPUs and by newer Intel CPUs which never enter the C2 state (P4). In any other
* case we have to choose the asynchronous timer mode.
*
* @param poffMin Pointer to the determined difference between different cores.
* @return false if the time stamp counters appear to be synchronized, true otherwise.
*/
{
/*
* Just iterate all the cpus 8 times and make sure that the TSC is
* ever increasing. We don't bother taking TSC rollover into account.
*/
int iEndCpu = RTMpGetArraySize();
int iCpu;
int cLoops = 8;
bool fAsync = false;
int rc = VINF_SUCCESS;
while (cLoops-- > 0)
{
{
if (RT_SUCCESS(rc))
{
{
fAsync = true;
Log(("supdrvDetermineAsyncTsc: iCpu=%d cLoops=%d CurTsc=%llx PrevTsc=%llx\n",
break;
}
/* Gather statistics (except the first time). */
{
}
/* Next */
}
else if (rc == VERR_NOT_SUPPORTED)
break;
else
}
/* broke out of the loop. */
break;
}
Log(("supdrvDetermineAsyncTsc: returns %d; iEndCpu=%d rc=%d offMin=%llx offMax=%llx\n",
#endif
return fAsync;
}
/**
* Determine the GIP TSC mode.
*
* @returns The most suitable TSC mode.
* @param pDevExt Pointer to the device instance data.
*/
{
/*
* On SMP we're faced with two problems:
* (1) There might be a skew between the CPU, so that cpu0
* returns a TSC that is slightly different from cpu1.
* (2) Power management (and other things) may cause the TSC
* to run at a non-constant speed, and cause the speed
* to be different on the cpus. This will result in (1).
*
* So, on SMP systems we'll have to select the ASYNC update method
* if there are symptoms of these problems.
*/
if (RTMpGetCount() > 1)
{
return SUPGIPMODE_ASYNC_TSC;
/* Try check for current differences between the cpus. */
return SUPGIPMODE_ASYNC_TSC;
/*
* If the CPU supports power management and is an AMD one we
* won't trust it unless it has the TscInvariant bit is set.
*/
/* Check for "AuthenticAMD" */
if ( uEAX >= 1
&& uEBX == X86_CPUID_VENDOR_AMD_EBX
&& uECX == X86_CPUID_VENDOR_AMD_ECX
&& uEDX == X86_CPUID_VENDOR_AMD_EDX)
{
/* Check for APM support and that TscInvariant is cleared. */
if (uEAX >= 0x80000007)
{
return SUPGIPMODE_ASYNC_TSC;
}
}
}
return SUPGIPMODE_SYNC_TSC;
}
/**
* Initializes the GIP data.
*
* @param pDevExt Pointer to the device instance data.
* @param pGip Pointer to the read-write kernel mapping of the GIP.
* @param HCPhys The physical address of the GIP.
* @param u64NanoTS The current nanosecond timestamp.
* @param uUpdateHz The update frequency.
* @param cCpus The CPU count.
*/
{
unsigned i;
#ifdef DEBUG_DARWIN_GIP
OSDBGPRINT(("supdrvGipInit: pGip=%p HCPhys=%lx u64NanoTS=%llu uUpdateHz=%d cCpus=%u\n", pGip, (long)HCPhys, u64NanoTS, uUpdateHz, cCpus));
#else
LogFlow(("supdrvGipInit: pGip=%p HCPhys=%lx u64NanoTS=%llu uUpdateHz=%d cCpus=%u\n", pGip, (long)HCPhys, u64NanoTS, uUpdateHz, cCpus));
#endif
/*
* Initialize the structure.
*/
pGip->aiCpuFromApicId[i] = 0;
for (i = 0; i < cCpus; i++)
{
/*
* We don't know the following values until we've executed updates.
* So, we'll just pretend it's a 4 GHz CPU and adjust the history it on
* the 2nd timer callout.
*/
}
/*
* Link it to the device extension.
*/
}
/**
* On CPU initialization callback for RTMpOnAll.
*
* @param idCpu The CPU ID.
* @param pvUser1 The device extension.
* @param pvUser2 The GIP.
*/
{
/* This is good enough, even though it will update some of the globals a
bit to much. */
}
/**
* Invalidates the GIP data upon termination.
*
* @param pGip Pointer to the read-write kernel mapping of the GIP.
*/
{
unsigned i;
{
}
}
/**
* Worker routine for supdrvGipUpdate and supdrvGipUpdatePerCpu that
* updates all the per cpu data except the transaction id.
*
* @param pGip The GIP.
* @param pGipCpu Pointer to the per cpu data.
* @param u64NanoTS The current time stamp.
* @param u64TSC The current TSC.
* @param iTick The current timer tick.
*/
static void supdrvGipDoUpdateCpu(PSUPGLOBALINFOPAGE pGip, PSUPGIPCPU pGipCpu, uint64_t u64NanoTS, uint64_t u64TSC, uint64_t iTick)
{
unsigned iTSCHistoryHead;
/* Delta between this and the previous update. */
/*
* Update the NanoTS.
*/
/*
* Calc TSC delta.
*/
/** @todo validate the NanoTS delta, don't trust the OS to call us when it should... */
if (u64TSCDelta >> 32)
{
}
/*
* On the 2nd and 3rd callout, reset the history with the current TSC
* interval since the values entered by supdrvGipInit are totally off.
* The interval on the 1st callout completely unreliable, the 2nd is a bit
* better, while the 3rd should be most reliable.
*/
|| u32TransactionId == 7)
&& ( iTick == 2
|| iTick == 3) ))
{
unsigned i;
}
/*
* TSC History.
*/
/*
* UpdateIntervalTSC = average of last 8,2,1 intervals depending on update HZ.
*/
{
u32 >>= 2;
u32UpdateIntervalTSC >>= 2;
u32UpdateIntervalTSC >>= 1;
/* Value chosen for a 2GHz Athlon64 running linux 2.6.10/11, . */
}
{
u32UpdateIntervalTSC >>= 1;
/* value chosen on a 2GHz thinkpad running windows */
}
else
{
/* This value hasn't be checked yet.. waiting for OS/2 and 33Hz timers.. :-) */
}
ASMAtomicWriteU32(&pGipCpu->u32UpdateIntervalTSC, u32UpdateIntervalTSC + u32UpdateIntervalTSCSlack);
/*
* CpuHz.
*/
}
/**
* Updates the GIP.
*
* @param pGip Pointer to the GIP.
* @param u64NanoTS The current nanosecond timesamp.
* @param u64TSC The current TSC timesamp.
* @param idCpu The CPU ID.
* @param iTick The current timer tick.
*/
static void supdrvGipUpdate(PSUPGLOBALINFOPAGE pGip, uint64_t u64NanoTS, uint64_t u64TSC, RTCPUID idCpu, uint64_t iTick)
{
/*
* Determine the relevant CPU data.
*/
else
{
return;
return;
}
/*
* Start update transaction.
*/
{
/* this can happen on win32 if we're taking to long and there are more CPUs around. shouldn't happen though. */
return;
}
/*
* Recalc the update frequency every 0x800th time.
*/
{
if (pGip->u64NanoTSLastUpdateHz)
{
#ifdef RT_ARCH_AMD64 /** @todo fix 64-bit div here to work on x86 linux. */
{
}
#endif
}
}
/*
* Update the data.
*/
/*
* Complete transaction.
*/
}
/**
* Updates the per cpu GIP data for the calling cpu.
*
* @param pGip Pointer to the GIP.
* @param u64NanoTS The current nanosecond timesamp.
* @param u64TSC The current TSC timesamp.
* @param idCpu The CPU ID.
* @param idApic The APIC id for the CPU index.
* @param iTick The current timer tick.
*/
{
/*
* Avoid a potential race when a CPU online notification doesn't fire on
* the onlined CPU but the tick creeps in before the event notification is
* run.
*/
{
}
{
{
/*
* Start update transaction.
*/
{
return;
}
/*
* Update the data.
*/
/*
* Complete transaction.
*/
}
}
}