SUPDrv.c revision dbb5c497af4fd871af632a41a391450464cd1135
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico/* $Revision$ */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * VBoxDrv - The VirtualBox Support Driver - Common code.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Copyright (C) 2006-2010 Oracle Corporation
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * This file is part of VirtualBox Open Source Edition (OSE), as
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * available from http://www.virtualbox.org. This file is free software;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * you can redistribute it and/or modify it under the terms of the GNU
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * General Public License (GPL) as published by the Free Software
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Foundation, in version 2 as it comes in the "COPYING" file of the
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * The contents of this file may alternatively be used under the terms
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * of the Common Development and Distribution License Version 1.0
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * VirtualBox OSE distribution, in which case the provisions of the
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * CDDL are applicable instead of those of the GPL.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * You may elect to license modified versions of this file under the
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * terms and conditions of either the GPL or the CDDL or both.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico/*******************************************************************************
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico* Header Files *
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico*******************************************************************************/
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico#if defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico# define VBOXDRV_SUPDRV_SESSION_CREATE(pvSession, fUser) do { } while (0)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico# define VBOXDRV_SUPDRV_SESSION_CLOSE(pvSession) do { } while (0)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico# define VBOXDRV_SUPDRV_IOCCLOSE(pvSession) do { } while (0)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico# define VBOXDRV_SUPDRV_IOCTL_ENTRY(pvSession, uIOCtl, pvReqHdr) do { } while (0)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico# define VBOXDRV_SUPDRV_IOCTL_RETURN(pvSession, uIOCtl, pvReqHdr, rcRet, rcReq) do { } while (0)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Logging assignments:
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Log - useful stuff, like failures.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * LogFlow - program flow, except the really noisy bits.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Log2 - Cleanup.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Log3 - Loader flow noise.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Log4 - Call VMMR0 flow noise.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Log5 - Native yet-to-be-defined noise.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Log6 - Native ioctl flow noise.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Logging requires BUILD_TYPE=debug and possibly changes to the logger
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * instanciation in log-vbox.c(pp).
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico/*******************************************************************************
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico* Defined Constants And Macros *
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico*******************************************************************************/
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico/** The frequency by which we recalculate the u32UpdateHz and
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * u32UpdateIntervalNS GIP members. The value must be a power of 2. */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico/** @def VBOX_SVN_REV
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * The makefile should define this if it can. */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico#if 0 /* Don't start the GIP timers. Useful when debugging the IPRT timer code. */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico/*******************************************************************************
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico* Internal Functions *
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico*******************************************************************************/
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic DECLCALLBACK(int) supdrvSessionObjHandleRetain(RTHANDLETABLE hHandleTable, void *pvObj, void *pvCtx, void *pvUser);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic DECLCALLBACK(void) supdrvSessionObjHandleDelete(RTHANDLETABLE hHandleTable, uint32_t h, void *pvObj, void *pvCtx, void *pvUser);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic int supdrvMemAdd(PSUPDRVMEMREF pMem, PSUPDRVSESSION pSession);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic int supdrvMemRelease(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr, SUPDRVMEMREFTYPE eType);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic int supdrvIOCtl_LdrOpen(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPLDROPEN pReq);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic int supdrvIOCtl_LdrLoad(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPLDRLOAD pReq);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic int supdrvIOCtl_LdrFree(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPLDRFREE pReq);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic int supdrvIOCtl_LdrGetSymbol(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPLDRGETSYMBOL pReq);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic int supdrvIDC_LdrGetSymbol(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPDRVIDCREQGETSYM pReq);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic int supdrvLdrSetVMMR0EPs(PSUPDRVDEVEXT pDevExt, void *pvVMMR0, void *pvVMMR0EntryInt, void *pvVMMR0EntryFast, void *pvVMMR0EntryEx);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic void supdrvLdrUnsetVMMR0EPs(PSUPDRVDEVEXT pDevExt);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic int supdrvLdrAddUsage(PSUPDRVSESSION pSession, PSUPDRVLDRIMAGE pImage);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic void supdrvLdrFree(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicoDECLINLINE(int) supdrvLdrLock(PSUPDRVDEVEXT pDevExt);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicoDECLINLINE(int) supdrvLdrUnlock(PSUPDRVDEVEXT pDevExt);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic int supdrvIOCtl_CallServiceModule(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPCALLSERVICE pReq);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic int supdrvIOCtl_LoggerSettings(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPLOGGERSETTINGS pReq);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic void supdrvGipDestroy(PSUPDRVDEVEXT pDevExt);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic DECLCALLBACK(void) supdrvGipSyncTimer(PRTTIMER pTimer, void *pvUser, uint64_t iTick);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic DECLCALLBACK(void) supdrvGipAsyncTimer(PRTTIMER pTimer, void *pvUser, uint64_t iTick);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic DECLCALLBACK(void) supdrvGipMpEvent(RTMPEVENT enmEvent, RTCPUID idCpu, void *pvUser);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic void supdrvGipInit(PSUPDRVDEVEXT pDevExt, PSUPGLOBALINFOPAGE pGip, RTHCPHYS HCPhys, uint64_t u64NanoTS, unsigned uUpdateHz);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic void supdrvGipTerm(PSUPGLOBALINFOPAGE pGip);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic void supdrvGipUpdate(PSUPGLOBALINFOPAGE pGip, uint64_t u64NanoTS, uint64_t u64TSC, uint64_t iTick);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic void supdrvGipUpdatePerCpu(PSUPGLOBALINFOPAGE pGip, uint64_t u64NanoTS, uint64_t u64TSC, unsigned iCpu, uint64_t iTick);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico/*******************************************************************************
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico* Global Variables *
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico*******************************************************************************/
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicoDECLEXPORT(PSUPGLOBALINFOPAGE) g_pSUPGlobalInfoPage = NULL;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Array of the R0 SUP API.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* name function */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* Entries with absolute addresses determined at runtime, fixup
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico code makes ugly ASSUMPTIONS about the order here: */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "SUPR0AbsIs64bit", (void *)0 },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "SUPR0Abs64bitKernelCS", (void *)0 },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "SUPR0Abs64bitKernelSS", (void *)0 },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "SUPR0Abs64bitKernelDS", (void *)0 },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "SUPR0AbsKernelCS", (void *)0 },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "SUPR0AbsKernelSS", (void *)0 },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "SUPR0AbsKernelDS", (void *)0 },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "SUPR0AbsKernelES", (void *)0 },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "SUPR0AbsKernelFS", (void *)0 },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "SUPR0AbsKernelGS", (void *)0 },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* Normal function pointers: */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "SUPR0ComponentRegisterFactory", (void *)SUPR0ComponentRegisterFactory },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "SUPR0ComponentDeregisterFactory", (void *)SUPR0ComponentDeregisterFactory },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "SUPR0ComponentQueryFactory", (void *)SUPR0ComponentQueryFactory },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "SUPR0ObjVerifyAccess", (void *)SUPR0ObjVerifyAccess },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "SUPR0Printf", (void *)SUPR0Printf }, /** @todo needs wrapping? */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "SUPSemEventCreate", (void *)SUPSemEventCreate },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "SUPSemEventSignal", (void *)SUPSemEventSignal },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "SUPSemEventWaitNoResume", (void *)SUPSemEventWaitNoResume },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "SUPSemEventWaitNsAbsIntr", (void *)SUPSemEventWaitNsAbsIntr },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "SUPSemEventWaitNsRelIntr", (void *)SUPSemEventWaitNsRelIntr },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "SUPSemEventGetResolution", (void *)SUPSemEventGetResolution },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "SUPSemEventMultiCreate", (void *)SUPSemEventMultiCreate },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "SUPSemEventMultiClose", (void *)SUPSemEventMultiClose },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "SUPSemEventMultiSignal", (void *)SUPSemEventMultiSignal },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "SUPSemEventMultiReset", (void *)SUPSemEventMultiReset },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "SUPSemEventMultiWait", (void *)SUPSemEventMultiWait },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "SUPSemEventMultiWaitNoResume", (void *)SUPSemEventMultiWaitNoResume },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "SUPSemEventMultiWaitNsAbsIntr", (void *)SUPSemEventMultiWaitNsAbsIntr },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "SUPSemEventMultiWaitNsRelIntr", (void *)SUPSemEventMultiWaitNsRelIntr },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "SUPSemEventMultiGetResolution", (void *)SUPSemEventMultiGetResolution },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "SUPR0GetPagingMode", (void *)SUPR0GetPagingMode },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "g_pSUPGlobalInfoPage", (void *)&g_pSUPGlobalInfoPage },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTMemAllocZVarTag", (void *)RTMemAllocZVarTag },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTR0MemObjAllocLowTag", (void *)RTR0MemObjAllocLowTag },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTR0MemObjAllocPageTag", (void *)RTR0MemObjAllocPageTag },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTR0MemObjAllocPhysTag", (void *)RTR0MemObjAllocPhysTag },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTR0MemObjAllocPhysExTag", (void *)RTR0MemObjAllocPhysExTag },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTR0MemObjAllocPhysNCTag", (void *)RTR0MemObjAllocPhysNCTag },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTR0MemObjAllocContTag", (void *)RTR0MemObjAllocContTag },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTR0MemObjEnterPhysTag", (void *)RTR0MemObjEnterPhysTag },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTR0MemObjLockUserTag", (void *)RTR0MemObjLockUserTag },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTR0MemObjMapKernelTag", (void *)RTR0MemObjMapKernelTag },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTR0MemObjMapKernelExTag", (void *)RTR0MemObjMapKernelExTag },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTR0MemObjMapUserTag", (void *)RTR0MemObjMapUserTag },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTR0MemObjProtect", (void *)RTR0MemObjProtect },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTR0MemObjAddress", (void *)RTR0MemObjAddress },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTR0MemObjAddressR3", (void *)RTR0MemObjAddressR3 },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTR0MemObjIsMapping", (void *)RTR0MemObjIsMapping },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTR0MemObjGetPagePhysAddr", (void *)RTR0MemObjGetPagePhysAddr },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTR0MemUserCopyFrom", (void *)RTR0MemUserCopyFrom },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTR0MemUserCopyTo", (void *)RTR0MemUserCopyTo },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTR0MemUserIsValidAddr", (void *)RTR0MemUserIsValidAddr },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTR0MemKernelIsValidAddr", (void *)RTR0MemKernelIsValidAddr },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTR0MemAreKrnlAndUsrDifferent", (void *)RTR0MemAreKrnlAndUsrDifferent },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTSemMutexRequest", (void *)RTSemMutexRequest },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTSemMutexRequestDebug", (void *)RTSemMutexRequestDebug },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTSemMutexRequestNoResume", (void *)RTSemMutexRequestNoResume },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTSemMutexRequestNoResumeDebug", (void *)RTSemMutexRequestNoResumeDebug },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTSemMutexRelease", (void *)RTSemMutexRelease },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTSemMutexDestroy", (void *)RTSemMutexDestroy },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTR0ProcHandleSelf", (void *)RTR0ProcHandleSelf },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTSemFastMutexCreate", (void *)RTSemFastMutexCreate },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTSemFastMutexDestroy", (void *)RTSemFastMutexDestroy },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTSemFastMutexRequest", (void *)RTSemFastMutexRequest },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTSemFastMutexRelease", (void *)RTSemFastMutexRelease },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTSemEventWaitNoResume", (void *)RTSemEventWaitNoResume },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTSemEventWaitExDebug", (void *)RTSemEventWaitExDebug },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTSemEventGetResolution", (void *)RTSemEventGetResolution },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTSemEventDestroy", (void *)RTSemEventDestroy },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTSemEventMultiCreate", (void *)RTSemEventMultiCreate },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTSemEventMultiSignal", (void *)RTSemEventMultiSignal },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTSemEventMultiReset", (void *)RTSemEventMultiReset },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTSemEventMultiWait", (void *)RTSemEventMultiWait },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTSemEventMultiWaitNoResume", (void *)RTSemEventMultiWaitNoResume },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTSemEventMultiWaitEx", (void *)RTSemEventMultiWaitEx },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTSemEventMultiWaitExDebug", (void *)RTSemEventMultiWaitExDebug },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTSemEventMultiGetResolution", (void *)RTSemEventMultiGetResolution },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTSemEventMultiDestroy", (void *)RTSemEventMultiDestroy },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTSpinlockDestroy", (void *)RTSpinlockDestroy },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTSpinlockAcquire", (void *)RTSpinlockAcquire },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTSpinlockRelease", (void *)RTSpinlockRelease },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTSpinlockAcquireNoInts", (void *)RTSpinlockAcquireNoInts },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTSpinlockReleaseNoInts", (void *)RTSpinlockReleaseNoInts },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTTimeSystemNanoTS", (void *)RTTimeSystemNanoTS },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTTimeSystemMilliTS", (void *)RTTimeSystemMilliTS },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTThreadNativeSelf", (void *)RTThreadNativeSelf },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico#if 0 /* Thread APIs, Part 2. */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTThreadGetNative", (void *)RTThreadGetNative },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTThreadWaitNoResume", (void *)RTThreadWaitNoResume },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTThreadUserSignal", (void *)RTThreadUserSignal },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTThreadUserReset", (void *)RTThreadUserReset },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTThreadUserWaitNoResume", (void *)RTThreadUserWaitNoResume },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTThreadPreemptIsEnabled", (void *)RTThreadPreemptIsEnabled },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTThreadPreemptIsPending", (void *)RTThreadPreemptIsPending },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTThreadPreemptIsPendingTrusty", (void *)RTThreadPreemptIsPendingTrusty },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTThreadPreemptIsPossible", (void *)RTThreadPreemptIsPossible },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTThreadPreemptDisable", (void *)RTThreadPreemptDisable },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTThreadPreemptRestore", (void *)RTThreadPreemptRestore },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTThreadIsInInterrupt", (void *)RTThreadIsInInterrupt },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTTimerChangeInterval", (void *)RTTimerChangeInterval },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTTimerGetSystemGranularity", (void *)RTTimerGetSystemGranularity },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTTimerRequestSystemGranularity", (void *)RTTimerRequestSystemGranularity },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTTimerReleaseSystemGranularity", (void *)RTTimerReleaseSystemGranularity },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTTimerCanDoHighResolution", (void *)RTTimerCanDoHighResolution },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTLogDefaultInstance", (void *)RTLogDefaultInstance },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTMpCpuIdFromSetIndex", (void *)RTMpCpuIdFromSetIndex },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTMpCpuIdToSetIndex", (void *)RTMpCpuIdToSetIndex },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTMpIsCpuPossible", (void *)RTMpIsCpuPossible },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTMpGetOnlineCount", (void *)RTMpGetOnlineCount },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTMpIsCpuWorkPending", (void *)RTMpIsCpuWorkPending },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTPowerNotificationRegister", (void *)RTPowerNotificationRegister },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTPowerNotificationDeregister", (void *)RTPowerNotificationDeregister },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTLogRelDefaultInstance", (void *)RTLogRelDefaultInstance },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTLogSetDefaultInstanceThread", (void *)RTLogSetDefaultInstanceThread },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTR0AssertPanicSystem", (void *)RTR0AssertPanicSystem },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTAssertSetMayPanic", (void *)RTAssertSetMayPanic },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTStrFormatNumber", (void *)RTStrFormatNumber },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTStrFormatTypeDeregister", (void *)RTStrFormatTypeDeregister },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTStrFormatTypeRegister", (void *)RTStrFormatTypeRegister },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTStrFormatTypeSetUser", (void *)RTStrFormatTypeSetUser },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTHandleTableAllocWithCtx", (void *)RTHandleTableAllocWithCtx },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTHandleTableCreate", (void *)RTHandleTableCreate },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTHandleTableCreateEx", (void *)RTHandleTableCreateEx },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTHandleTableDestroy", (void *)RTHandleTableDestroy },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTHandleTableFreeWithCtx", (void *)RTHandleTableFreeWithCtx },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTHandleTableLookupWithCtx", (void *)RTHandleTableLookupWithCtx },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTNetIPv4AddDataChecksum", (void *)RTNetIPv4AddDataChecksum },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTNetIPv4AddTCPChecksum", (void *)RTNetIPv4AddTCPChecksum },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTNetIPv4AddUDPChecksum", (void *)RTNetIPv4AddUDPChecksum },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTNetIPv4FinalizeChecksum", (void *)RTNetIPv4FinalizeChecksum },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTNetIPv4HdrChecksum", (void *)RTNetIPv4HdrChecksum },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTNetIPv4IsDHCPValid", (void *)RTNetIPv4IsDHCPValid },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTNetIPv4IsHdrValid", (void *)RTNetIPv4IsHdrValid },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTNetIPv4IsTCPSizeValid", (void *)RTNetIPv4IsTCPSizeValid },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTNetIPv4IsTCPValid", (void *)RTNetIPv4IsTCPValid },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTNetIPv4IsUDPSizeValid", (void *)RTNetIPv4IsUDPSizeValid },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTNetIPv4IsUDPValid", (void *)RTNetIPv4IsUDPValid },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTNetIPv4PseudoChecksum", (void *)RTNetIPv4PseudoChecksum },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTNetIPv4PseudoChecksumBits", (void *)RTNetIPv4PseudoChecksumBits },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTNetIPv4TCPChecksum", (void *)RTNetIPv4TCPChecksum },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTNetIPv4UDPChecksum", (void *)RTNetIPv4UDPChecksum },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTNetIPv6PseudoChecksum", (void *)RTNetIPv6PseudoChecksum },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTNetIPv6PseudoChecksumBits", (void *)RTNetIPv6PseudoChecksumBits },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico { "RTNetIPv6PseudoChecksumEx", (void *)RTNetIPv6PseudoChecksumEx },
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico#if defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Drag in the rest of IRPT since we share it with the
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * rest of the kernel modules on darwin.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* VBoxNetFlt */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* VBoxNetAdp */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* VBoxUSB */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico#endif /* RT_OS_DARWIN || RT_OS_SOLARIS || RT_OS_SOLARIS */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Initializes the device extentsion structure.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns IPRT status code.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pDevExt The device extension to initialize.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param cbSession The size of the session structure. The size of
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * SUPDRVSESSION may be smaller when SUPDRV_AGNOSTIC is
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * defined because we're skipping the OS specific members
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicoint VBOXCALL supdrvInitDevExt(PSUPDRVDEVEXT pDevExt, size_t cbSession)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Create the release log.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico static const char * const s_apszGroups[] = VBOX_LOGGROUP_NAMES;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = RTLogCreate(&pRelLogger, 0 /* fFlags */, "all",
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico "VBOX_RELEASE_LOG", RT_ELEMENTS(s_apszGroups), s_apszGroups,
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /** @todo Add native hook for getting logger config parameters and setting
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * them. On linux we should use the module parameter stuff... */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Initialize it.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = RTSemFastMutexCreate(&pDevExt->mtxComponentFactory);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pDevExt->u32Cookie = BIRD; /** @todo make this random? */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Fixup the absolute symbols.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Because of the table indexing assumptions we'll have a little #ifdef orgy
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * here rather than distributing this to OS specific files. At least for now.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico g_aFunctions[0].pfn = (void *)1; /* SUPR0AbsIs64bit */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico g_aFunctions[1].pfn = (void *)0x80; /* SUPR0Abs64bitKernelCS - KERNEL64_CS, seg.h */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico g_aFunctions[2].pfn = (void *)0x88; /* SUPR0Abs64bitKernelSS - KERNEL64_SS, seg.h */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico g_aFunctions[3].pfn = (void *)0x88; /* SUPR0Abs64bitKernelDS - KERNEL64_SS, seg.h */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico g_aFunctions[0].pfn = g_aFunctions[1].pfn = g_aFunctions[2].pfn = g_aFunctions[4].pfn = (void *)0;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico g_aFunctions[4].pfn = (void *)0x08; /* SUPR0AbsKernelCS - KERNEL_CS, seg.h */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico g_aFunctions[5].pfn = (void *)0x10; /* SUPR0AbsKernelSS - KERNEL_DS, seg.h */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico g_aFunctions[6].pfn = (void *)0x10; /* SUPR0AbsKernelDS - KERNEL_DS, seg.h */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico g_aFunctions[7].pfn = (void *)0x10; /* SUPR0AbsKernelES - KERNEL_DS, seg.h */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico g_aFunctions[8].pfn = (void *)0x10; /* SUPR0AbsKernelFS - KERNEL_DS, seg.h */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico g_aFunctions[9].pfn = (void *)0x48; /* SUPR0AbsKernelGS - CPU_DATA_GS, seg.h */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico# else /* 64-bit darwin: */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico g_aFunctions[0].pfn = (void *)1; /* SUPR0AbsIs64bit */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico g_aFunctions[1].pfn = (void *)(uintptr_t)ASMGetCS(); /* SUPR0Abs64bitKernelCS */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico g_aFunctions[2].pfn = (void *)(uintptr_t)ASMGetSS(); /* SUPR0Abs64bitKernelSS */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico g_aFunctions[3].pfn = (void *)0; /* SUPR0Abs64bitKernelDS */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico g_aFunctions[4].pfn = (void *)(uintptr_t)ASMGetCS(); /* SUPR0AbsKernelCS */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico g_aFunctions[5].pfn = (void *)(uintptr_t)ASMGetSS(); /* SUPR0AbsKernelSS */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico g_aFunctions[6].pfn = (void *)0; /* SUPR0AbsKernelDS */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico g_aFunctions[7].pfn = (void *)0; /* SUPR0AbsKernelES */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico g_aFunctions[8].pfn = (void *)0; /* SUPR0AbsKernelFS */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico g_aFunctions[9].pfn = (void *)0; /* SUPR0AbsKernelGS */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico#else /* !RT_OS_DARWIN */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico g_aFunctions[0].pfn = (void *)1; /* SUPR0AbsIs64bit */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico g_aFunctions[1].pfn = (void *)(uintptr_t)ASMGetCS(); /* SUPR0Abs64bitKernelCS */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico g_aFunctions[2].pfn = (void *)(uintptr_t)ASMGetSS(); /* SUPR0Abs64bitKernelSS */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico g_aFunctions[3].pfn = (void *)(uintptr_t)ASMGetDS(); /* SUPR0Abs64bitKernelDS */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico g_aFunctions[0].pfn = g_aFunctions[1].pfn = g_aFunctions[2].pfn = g_aFunctions[4].pfn = (void *)0;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico g_aFunctions[4].pfn = (void *)(uintptr_t)ASMGetCS(); /* SUPR0AbsKernelCS */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico g_aFunctions[5].pfn = (void *)(uintptr_t)ASMGetSS(); /* SUPR0AbsKernelSS */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico g_aFunctions[6].pfn = (void *)(uintptr_t)ASMGetDS(); /* SUPR0AbsKernelDS */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico g_aFunctions[7].pfn = (void *)(uintptr_t)ASMGetES(); /* SUPR0AbsKernelES */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico g_aFunctions[8].pfn = (void *)(uintptr_t)ASMGetFS(); /* SUPR0AbsKernelFS */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico g_aFunctions[9].pfn = (void *)(uintptr_t)ASMGetGS(); /* SUPR0AbsKernelGS */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico#endif /* !RT_OS_DARWIN */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSemFastMutexDestroy(pDevExt->mtxComponentFactory);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pDevExt->mtxComponentFactory = NIL_RTSEMFASTMUTEX;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Delete the device extension (e.g. cleanup members).
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pDevExt The device extension to delete.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicovoid VBOXCALL supdrvDeleteDevExt(PSUPDRVDEVEXT pDevExt)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Kill mutexes and spinlocks.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSemFastMutexDestroy(pDevExt->mtxComponentFactory);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pDevExt->mtxComponentFactory = NIL_RTSEMFASTMUTEX;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Free lists.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* objects. */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico Assert(!pObj); /* (can trigger on forced unloads) */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* usage records. */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* kill the GIP. */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* destroy the loggers. */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Create session.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns IPRT status code.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pDevExt Device extension.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param fUser Flag indicating whether this is a user or kernel session.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param ppSession Where to store the pointer to the session data.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicoint VBOXCALL supdrvCreateSession(PSUPDRVDEVEXT pDevExt, bool fUser, PSUPDRVSESSION *ppSession)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Allocate memory for the session data.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico PSUPDRVSESSION pSession = *ppSession = (PSUPDRVSESSION)RTMemAllocZ(pDevExt->cbSession);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* Initialize session data. */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = RTHandleTableCreateEx(&pSession->hHandleTable,
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTHANDLETABLE_FLAGS_LOCKED | RTHANDLETABLE_FLAGS_CONTEXT,
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico 1 /*uBase*/, 32768 /*cMax*/, supdrvSessionObjHandleRetain, pSession);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /*pSession->pLdrUsage = NULL;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pSession->pVM = NULL;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pSession->pUsage = NULL;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pSession->pGip = NULL;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pSession->fGipReferenced = false;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pSession->Bundle.cUsed = 0; */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico LogFlow(("Created session %p initial cookie=%#x\n", pSession, pSession->u32Cookie));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Shared code for cleaning up a session.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pDevExt Device extension.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pSession Session data.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * This data will be freed by this routine.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicovoid VBOXCALL supdrvCloseSession(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Cleanup the session first.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Free the rest of the session stuff.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Shared code for cleaning up a session (but not quite freeing it).
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * This is primarily intended for MAC OS X where we have to clean up the memory
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * stuff before the file handle is closed.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pDevExt Device extension.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pSession Session data.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * This data will be freed by this routine.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicovoid VBOXCALL supdrvCleanupSession(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico LogFlow(("supdrvCleanupSession: pSession=%p\n", pSession));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Remove logger instances related to this session.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTLogSetDefaultInstanceThread(NULL, (uintptr_t)pSession);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Destroy the handle table.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = RTHandleTableDestroy(pSession->hHandleTable, supdrvSessionObjHandleDelete, pSession);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Release object references made in this session.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * In theory there should be noone racing us in this session.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSPINLOCKTMP SpinlockTmp = RTSPINLOCKTMP_INITIALIZER;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSpinlockAcquire(pDevExt->Spinlock, &SpinlockTmp);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertMsg(pUsage->cUsage >= 1 && pObj->cUsage >= pUsage->cUsage, ("glob %d; sess %d\n", pObj->cUsage, pUsage->cUsage));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSpinlockRelease(pDevExt->Spinlock, &SpinlockTmp);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* Destroy the object and free the record. */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico for (pObjPrev = pDevExt->pObjs; pObjPrev; pObjPrev = pObjPrev->pNext)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSpinlockRelease(pDevExt->Spinlock, &SpinlockTmp);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico Log(("supdrvCleanupSession: destroying %p/%d (%p/%p) cpid=%RTproc pid=%RTproc dtor=%p\n",
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pObj, pObj->enmType, pObj->pvUser1, pObj->pvUser2, pObj->CreatorProcess, RTProcSelf(), pObj->pfnDestructor));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pObj->pfnDestructor(pObj, pObj->pvUser1, pObj->pvUser2);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* free it and continue. */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSpinlockAcquire(pDevExt->Spinlock, &SpinlockTmp);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSpinlockRelease(pDevExt->Spinlock, &SpinlockTmp);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertMsg(!pSession->pUsage, ("Some buster reregistered an object during desturction!\n"));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Release memory allocated in the session.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * We do not serialize this as we assume that the application will
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * not allocated memory while closing the file handle object.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Check and unlock all entries in the bundle.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico Log2(("eType=%d pvR0=%p pvR3=%p cb=%ld\n", pBundle->aMem[i].eType, RTR0MemObjAddress(pBundle->aMem[i].MemObj),
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico (void *)RTR0MemObjAddressR3(pBundle->aMem[i].MapObjR3), (long)RTR0MemObjSize(pBundle->aMem[i].MemObj)));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = RTR0MemObjFree(pBundle->aMem[i].MapObjR3, false);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertRC(rc); /** @todo figure out how to handle this. */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = RTR0MemObjFree(pBundle->aMem[i].MemObj, true /* fFreeMappings */);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertRC(rc); /** @todo figure out how to handle this. */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Advance and free previous bundle.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Deregister component factories.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSemFastMutexRequest(pDevExt->mtxComponentFactory);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico PSUPDRVFACTORYREG pCur = pDevExt->pComponentFactoryHead;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* unlink it */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* free it */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSemFastMutexRelease(pDevExt->mtxComponentFactory);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico Log2(("deregistering component factories - done\n"));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Loaded images needs to be dereferenced and possibly freed up.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Unmap the GIP.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * RTHandleTableDestroy callback used by supdrvCleanupSession.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns IPRT status code, see SUPR0ObjAddRef.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param hHandleTable The handle table handle. Ignored.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pvObj The object pointer.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pvCtx Context, the handle type. Ignored.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pvUser Session pointer.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic DECLCALLBACK(int) supdrvSessionObjHandleRetain(RTHANDLETABLE hHandleTable, void *pvObj, void *pvCtx, void *pvUser)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico return SUPR0ObjAddRefEx(pvObj, (PSUPDRVSESSION)pvUser, true /*fNoBlocking*/);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * RTHandleTableDestroy callback used by supdrvCleanupSession.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param hHandleTable The handle table handle. Ignored.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param h The handle value. Ignored.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pvObj The object pointer.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pvCtx Context, the handle type. Ignored.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pvUser Session pointer.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic DECLCALLBACK(void) supdrvSessionObjHandleDelete(RTHANDLETABLE hHandleTable, uint32_t h, void *pvObj, void *pvCtx, void *pvUser)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Fast path I/O Control worker.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns VBox status code that should be passed down to ring-3 unchanged.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param uIOCtl Function number.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param idCpu VMCPU id.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pDevExt Device extention.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pSession Session data.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicoint VBOXCALL supdrvIOCtlFast(uintptr_t uIOCtl, VMCPUID idCpu, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * We check the two prereqs after doing this only to allow the compiler to optimize things better.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico if (RT_LIKELY(pSession->pVM && pDevExt->pfnVMMR0EntryFast))
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pDevExt->pfnVMMR0EntryFast(pSession->pVM, idCpu, SUP_VMMR0_DO_RAW_RUN);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pDevExt->pfnVMMR0EntryFast(pSession->pVM, idCpu, SUP_VMMR0_DO_HWACC_RUN);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pDevExt->pfnVMMR0EntryFast(pSession->pVM, idCpu, SUP_VMMR0_DO_NOP);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Helper for supdrvIOCtl. Check if pszStr contains any character of pszChars.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * We would use strpbrk here if this function would be contained in the RedHat kABI white
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns 1 if pszStr does contain any character of pszChars, 0 otherwise.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pszStr String to check
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pszChars Character set
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic int supdrvCheckInvalidChar(const char *pszStr, const char *pszChars)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * I/O Control worker.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns IPRT status code.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @retval VERR_INVALID_PARAMETER if the request is invalid.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param uIOCtl Function number.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pDevExt Device extention.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pSession Session data.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pReqHdr The request header.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicoint VBOXCALL supdrvIOCtl(uintptr_t uIOCtl, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPREQHDR pReqHdr)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico VBOXDRV_SUPDRV_IOCTL_ENTRY(pSession, uIOCtl, pReqHdr);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Validate the request.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* this first check could probably be omitted as its also done by the OS specific code... */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico if (RT_UNLIKELY( (pReqHdr->fFlags & SUPREQHDR_FLAGS_MAGIC_MASK) != SUPREQHDR_FLAGS_MAGIC
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico OSDBGPRINT(("vboxdrv: Bad ioctl request header; cbIn=%#lx cbOut=%#lx fFlags=%#lx\n",
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico (long)pReqHdr->cbIn, (long)pReqHdr->cbOut, (long)pReqHdr->fFlags));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico VBOXDRV_SUPDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VERR_INVALID_PARAMETER, VINF_SUCCESS);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico if (pReqHdr->u32Cookie != SUPCOOKIE_INITIAL_COOKIE)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico OSDBGPRINT(("SUP_IOCTL_COOKIE: bad cookie %#lx\n", (long)pReqHdr->u32Cookie));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico VBOXDRV_SUPDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VERR_INVALID_PARAMETER, VINF_SUCCESS);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico else if (RT_UNLIKELY( pReqHdr->u32Cookie != pDevExt->u32Cookie
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico || pReqHdr->u32SessionCookie != pSession->u32Cookie))
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico OSDBGPRINT(("vboxdrv: bad cookie %#lx / %#lx.\n", (long)pReqHdr->u32Cookie, (long)pReqHdr->u32SessionCookie));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico VBOXDRV_SUPDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VERR_INVALID_PARAMETER, VINF_SUCCESS);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Validation macros
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico#define REQ_CHECK_SIZES_EX(Name, cbInExpect, cbOutExpect) \
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico if (RT_UNLIKELY(pReqHdr->cbIn != (cbInExpect) || pReqHdr->cbOut != (cbOutExpect))) \
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico OSDBGPRINT(( #Name ": Invalid input/output sizes. cbIn=%ld expected %ld. cbOut=%ld expected %ld.\n", \
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico (long)pReq->Hdr.cbIn, (long)(cbInExpect), (long)pReq->Hdr.cbOut, (long)(cbOutExpect))); \
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico VBOXDRV_SUPDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VERR_INVALID_PARAMETER, VERR_INVALID_PARAMETER); \
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico#define REQ_CHECK_SIZES(Name) REQ_CHECK_SIZES_EX(Name, Name ## _SIZE_IN, Name ## _SIZE_OUT)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico OSDBGPRINT(( #Name ": Invalid input/output sizes. cbIn=%ld expected %ld.\n", \
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico VBOXDRV_SUPDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VERR_INVALID_PARAMETER, VERR_INVALID_PARAMETER); \
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico if (RT_UNLIKELY(pReqHdr->cbOut != (cbOutExpect))) \
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico OSDBGPRINT(( #Name ": Invalid input/output sizes. cbOut=%ld expected %ld.\n", \
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico VBOXDRV_SUPDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VERR_INVALID_PARAMETER, VERR_INVALID_PARAMETER); \
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico VBOXDRV_SUPDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VERR_INVALID_PARAMETER, VERR_INVALID_PARAMETER); \
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico VBOXDRV_SUPDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VERR_INVALID_PARAMETER, VERR_INVALID_PARAMETER); \
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * The switch.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico if (strncmp(pReq->u.In.szMagic, SUPCOOKIE_MAGIC, sizeof(pReq->u.In.szMagic)))
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico OSDBGPRINT(("SUP_IOCTL_COOKIE: invalid magic %.16s\n", pReq->u.In.szMagic));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico VBOXDRV_SUPDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VINF_SUCCESS, VERR_INVALID_MAGIC);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Call out to the OS specific code and let it do permission checks on the
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * client process.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico if (!supdrvOSValidateClientProcess(pDevExt, pSession))
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->u.Out.u32DriverVersion = SUPDRV_IOC_VERSION;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico VBOXDRV_SUPDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VINF_SUCCESS, VERR_PERMISSION_DENIED);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Match the version.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * The current logic is very simple, match the major interface version.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico if ( pReq->u.In.u32MinVersion > SUPDRV_IOC_VERSION
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico || (pReq->u.In.u32MinVersion & 0xffff0000) != (SUPDRV_IOC_VERSION & 0xffff0000))
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico OSDBGPRINT(("SUP_IOCTL_COOKIE: Version mismatch. Requested: %#x Min: %#x Current: %#x\n",
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->u.In.u32ReqVersion, pReq->u.In.u32MinVersion, SUPDRV_IOC_VERSION));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->u.Out.u32DriverVersion = SUPDRV_IOC_VERSION;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico VBOXDRV_SUPDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VINF_SUCCESS, pReq->Hdr.rc);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Fill in return data and be gone.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * N.B. The first one to change SUPDRV_IOC_VERSION shall makes sure that
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * u32SessionVersion <= u32ReqVersion!
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /** @todo Somehow validate the client and negotiate a secure cookie... */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->u.Out.u32SessionCookie = pSession->u32Cookie;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->u.Out.u32SessionVersion = SUPDRV_IOC_VERSION;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->u.Out.u32DriverVersion = SUPDRV_IOC_VERSION;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->u.Out.cFunctions = sizeof(g_aFunctions) / sizeof(g_aFunctions[0]);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico VBOXDRV_SUPDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VINF_SUCCESS, pReq->Hdr.rc);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico case SUP_CTL_CODE_NO_SIZE(SUP_IOCTL_QUERY_FUNCS(0)):
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* validate */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_SIZES_EX(SUP_IOCTL_QUERY_FUNCS, SUP_IOCTL_QUERY_FUNCS_SIZE_IN, SUP_IOCTL_QUERY_FUNCS_SIZE_OUT(RT_ELEMENTS(g_aFunctions)));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* execute */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->u.Out.cFunctions = RT_ELEMENTS(g_aFunctions);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico memcpy(&pReq->u.Out.aFunctions[0], g_aFunctions, sizeof(g_aFunctions));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico VBOXDRV_SUPDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VINF_SUCCESS, pReq->Hdr.rc);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* validate */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_SIZE_IN(SUP_IOCTL_PAGE_LOCK, SUP_IOCTL_PAGE_LOCK_SIZE_IN);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_SIZE_OUT(SUP_IOCTL_PAGE_LOCK, SUP_IOCTL_PAGE_LOCK_SIZE_OUT(pReq->u.In.cPages));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_EXPR(SUP_IOCTL_PAGE_LOCK, pReq->u.In.cPages > 0);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_EXPR(SUP_IOCTL_PAGE_LOCK, pReq->u.In.pvR3 >= PAGE_SIZE);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* execute */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->Hdr.rc = SUPR0LockMem(pSession, pReq->u.In.pvR3, pReq->u.In.cPages, &pReq->u.Out.aPages[0]);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico VBOXDRV_SUPDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VINF_SUCCESS, pReq->Hdr.rc);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* validate */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* execute */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->Hdr.rc = SUPR0UnlockMem(pSession, pReq->u.In.pvR3);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico VBOXDRV_SUPDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VINF_SUCCESS, pReq->Hdr.rc);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* validate */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* execute */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->Hdr.rc = SUPR0ContAlloc(pSession, pReq->u.In.cPages, &pReq->u.Out.pvR0, &pReq->u.Out.pvR3, &pReq->u.Out.HCPhys);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico VBOXDRV_SUPDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VINF_SUCCESS, pReq->Hdr.rc);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* validate */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* execute */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->Hdr.rc = SUPR0ContFree(pSession, (RTHCUINTPTR)pReq->u.In.pvR3);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico VBOXDRV_SUPDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VINF_SUCCESS, pReq->Hdr.rc);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* validate */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_EXPR(SUP_IOCTL_LDR_OPEN, pReq->u.In.cbImageWithTabs > 0);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_EXPR(SUP_IOCTL_LDR_OPEN, pReq->u.In.cbImageWithTabs < 16*_1M);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_EXPR(SUP_IOCTL_LDR_OPEN, pReq->u.In.cbImageBits > 0);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_EXPR(SUP_IOCTL_LDR_OPEN, pReq->u.In.cbImageBits > 0);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_EXPR(SUP_IOCTL_LDR_OPEN, pReq->u.In.cbImageBits < pReq->u.In.cbImageWithTabs);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_EXPR(SUP_IOCTL_LDR_OPEN, pReq->u.In.szName[0]);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_EXPR(SUP_IOCTL_LDR_OPEN, RTStrEnd(pReq->u.In.szName, sizeof(pReq->u.In.szName)));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_EXPR(SUP_IOCTL_LDR_OPEN, !supdrvCheckInvalidChar(pReq->u.In.szName, ";:()[]{}/\\|&*%#@!~`\"'"));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_EXPR(SUP_IOCTL_LDR_OPEN, RTStrEnd(pReq->u.In.szFilename, sizeof(pReq->u.In.szFilename)));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* execute */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->Hdr.rc = supdrvIOCtl_LdrOpen(pDevExt, pSession, pReq);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico VBOXDRV_SUPDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VINF_SUCCESS, pReq->Hdr.rc);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* validate */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_EXPR(Name, pReq->Hdr.cbIn >= sizeof(*pReq));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_SIZES_EX(SUP_IOCTL_LDR_LOAD, SUP_IOCTL_LDR_LOAD_SIZE_IN(pReq->u.In.cbImageWithTabs), SUP_IOCTL_LDR_LOAD_SIZE_OUT);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_EXPR(SUP_IOCTL_LDR_LOAD, pReq->u.In.cSymbols <= 16384);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico || ( pReq->u.In.offSymbols < pReq->u.In.cbImageWithTabs
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico && pReq->u.In.offSymbols + pReq->u.In.cSymbols * sizeof(SUPLDRSYM) <= pReq->u.In.cbImageWithTabs),
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico ("SUP_IOCTL_LDR_LOAD: offSymbols=%#lx cSymbols=%#lx cbImageWithTabs=%#lx\n", (long)pReq->u.In.offSymbols,
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico (long)pReq->u.In.cSymbols, (long)pReq->u.In.cbImageWithTabs));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico || ( pReq->u.In.offStrTab < pReq->u.In.cbImageWithTabs
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico && pReq->u.In.offStrTab + pReq->u.In.cbStrTab <= pReq->u.In.cbImageWithTabs
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico && pReq->u.In.cbStrTab <= pReq->u.In.cbImageWithTabs),
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico ("SUP_IOCTL_LDR_LOAD: offStrTab=%#lx cbStrTab=%#lx cbImageWithTabs=%#lx\n", (long)pReq->u.In.offStrTab,
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico (long)pReq->u.In.cbStrTab, (long)pReq->u.In.cbImageWithTabs));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico PSUPLDRSYM paSyms = (PSUPLDRSYM)&pReq->u.In.abImage[pReq->u.In.offSymbols];
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_EXPR_FMT(paSyms[i].offSymbol < pReq->u.In.cbImageWithTabs,
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico ("SUP_IOCTL_LDR_LOAD: sym #%ld: symb off %#lx (max=%#lx)\n", (long)i, (long)paSyms[i].offSymbol, (long)pReq->u.In.cbImageWithTabs));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_EXPR_FMT(paSyms[i].offName < pReq->u.In.cbStrTab,
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico ("SUP_IOCTL_LDR_LOAD: sym #%ld: name off %#lx (max=%#lx)\n", (long)i, (long)paSyms[i].offName, (long)pReq->u.In.cbImageWithTabs));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_EXPR_FMT(RTStrEnd((char const *)&pReq->u.In.abImage[pReq->u.In.offStrTab + paSyms[i].offName],
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico ("SUP_IOCTL_LDR_LOAD: sym #%ld: unterminated name! (%#lx / %#lx)\n", (long)i, (long)paSyms[i].offName, (long)pReq->u.In.cbImageWithTabs));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* execute */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->Hdr.rc = supdrvIOCtl_LdrLoad(pDevExt, pSession, pReq);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico VBOXDRV_SUPDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VINF_SUCCESS, pReq->Hdr.rc);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* validate */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* execute */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->Hdr.rc = supdrvIOCtl_LdrFree(pDevExt, pSession, pReq);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico VBOXDRV_SUPDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VINF_SUCCESS, pReq->Hdr.rc);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico case SUP_CTL_CODE_NO_SIZE(SUP_IOCTL_LDR_GET_SYMBOL):
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* validate */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico PSUPLDRGETSYMBOL pReq = (PSUPLDRGETSYMBOL)pReqHdr;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_EXPR(SUP_IOCTL_LDR_GET_SYMBOL, RTStrEnd(pReq->u.In.szSymbol, sizeof(pReq->u.In.szSymbol)));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* execute */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->Hdr.rc = supdrvIOCtl_LdrGetSymbol(pDevExt, pSession, pReq);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico VBOXDRV_SUPDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VINF_SUCCESS, pReq->Hdr.rc);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico case SUP_CTL_CODE_NO_SIZE(SUP_IOCTL_CALL_VMMR0(0)):
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* validate */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico Log4(("SUP_IOCTL_CALL_VMMR0: op=%u in=%u arg=%RX64 p/t=%RTproc/%RTthrd\n",
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->u.In.uOperation, pReq->Hdr.cbIn, pReq->u.In.u64Arg, RTProcSelf(), RTThreadNativeSelf()));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico if (pReq->Hdr.cbIn == SUP_IOCTL_CALL_VMMR0_SIZE(0))
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_SIZES_EX(SUP_IOCTL_CALL_VMMR0, SUP_IOCTL_CALL_VMMR0_SIZE_IN(0), SUP_IOCTL_CALL_VMMR0_SIZE_OUT(0));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* execute */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->Hdr.rc = pDevExt->pfnVMMR0EntryEx(pReq->u.In.pVMR0, pReq->u.In.idCpu, pReq->u.In.uOperation, NULL, pReq->u.In.u64Arg, pSession);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico PSUPVMMR0REQHDR pVMMReq = (PSUPVMMR0REQHDR)&pReq->abReqPkt[0];
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_EXPR_FMT(pReq->Hdr.cbIn >= SUP_IOCTL_CALL_VMMR0_SIZE(sizeof(SUPVMMR0REQHDR)),
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico ("SUP_IOCTL_CALL_VMMR0: cbIn=%#x < %#lx\n", pReq->Hdr.cbIn, SUP_IOCTL_CALL_VMMR0_SIZE(sizeof(SUPVMMR0REQHDR))));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_EXPR(SUP_IOCTL_CALL_VMMR0, pVMMReq->u32Magic == SUPVMMR0REQHDR_MAGIC);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_SIZES_EX(SUP_IOCTL_CALL_VMMR0, SUP_IOCTL_CALL_VMMR0_SIZE_IN(pVMMReq->cbReq), SUP_IOCTL_CALL_VMMR0_SIZE_OUT(pVMMReq->cbReq));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* execute */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->Hdr.rc = pDevExt->pfnVMMR0EntryEx(pReq->u.In.pVMR0, pReq->u.In.idCpu, pReq->u.In.uOperation, pVMMReq, pReq->u.In.u64Arg, pSession);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico Log(("SUP_IOCTL_CALL_VMMR0: rc=%Rrc op=%u out=%u arg=%RX64 p/t=%RTproc/%RTthrd\n",
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->Hdr.rc, pReq->u.In.uOperation, pReq->Hdr.cbOut, pReq->u.In.u64Arg, RTProcSelf(), RTThreadNativeSelf()));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico Log4(("SUP_IOCTL_CALL_VMMR0: rc=%Rrc op=%u out=%u arg=%RX64 p/t=%RTproc/%RTthrd\n",
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->Hdr.rc, pReq->u.In.uOperation, pReq->Hdr.cbOut, pReq->u.In.u64Arg, RTProcSelf(), RTThreadNativeSelf()));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico VBOXDRV_SUPDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VINF_SUCCESS, pReq->Hdr.rc);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico case SUP_CTL_CODE_NO_SIZE(SUP_IOCTL_GET_PAGING_MODE):
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* validate */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico PSUPGETPAGINGMODE pReq = (PSUPGETPAGINGMODE)pReqHdr;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* execute */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico VBOXDRV_SUPDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VINF_SUCCESS, pReq->Hdr.rc);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* validate */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_EXPR(SUP_IOCTL_LOW_ALLOC, pReq->Hdr.cbIn <= SUP_IOCTL_LOW_ALLOC_SIZE_IN);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_SIZES_EX(SUP_IOCTL_LOW_ALLOC, SUP_IOCTL_LOW_ALLOC_SIZE_IN, SUP_IOCTL_LOW_ALLOC_SIZE_OUT(pReq->u.In.cPages));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* execute */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->Hdr.rc = SUPR0LowAlloc(pSession, pReq->u.In.cPages, &pReq->u.Out.pvR0, &pReq->u.Out.pvR3, &pReq->u.Out.aPages[0]);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico VBOXDRV_SUPDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VINF_SUCCESS, pReq->Hdr.rc);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* validate */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* execute */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->Hdr.rc = SUPR0LowFree(pSession, (RTHCUINTPTR)pReq->u.In.pvR3);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico VBOXDRV_SUPDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VINF_SUCCESS, pReq->Hdr.rc);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* validate */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* execute */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->Hdr.rc = SUPR0GipMap(pSession, &pReq->u.Out.pGipR3, &pReq->u.Out.HCPhysGip);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico VBOXDRV_SUPDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VINF_SUCCESS, pReq->Hdr.rc);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* validate */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* execute */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico VBOXDRV_SUPDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VINF_SUCCESS, pReq->Hdr.rc);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico case SUP_CTL_CODE_NO_SIZE(SUP_IOCTL_SET_VM_FOR_FAST):
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* validate */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico PSUPSETVMFORFAST pReq = (PSUPSETVMFORFAST)pReqHdr;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico && !((uintptr_t)pReq->u.In.pVMR0 & (PAGE_SIZE - 1))),
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico ("SUP_IOCTL_SET_VM_FOR_FAST: pVMR0=%p!\n", pReq->u.In.pVMR0));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* execute */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico VBOXDRV_SUPDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VINF_SUCCESS, pReq->Hdr.rc);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico case SUP_CTL_CODE_NO_SIZE(SUP_IOCTL_PAGE_ALLOC_EX):
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* validate */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_EXPR(SUP_IOCTL_PAGE_ALLOC_EX, pReq->Hdr.cbIn <= SUP_IOCTL_PAGE_ALLOC_EX_SIZE_IN);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico 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));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_EXPR_FMT(pReq->u.In.fKernelMapping || pReq->u.In.fUserMapping,
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico ("SUP_IOCTL_PAGE_ALLOC_EX: No mapping requested!\n"));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico ("SUP_IOCTL_PAGE_ALLOC_EX: Must have user mapping!\n"));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_EXPR_FMT(!pReq->u.In.fReserved0 && !pReq->u.In.fReserved1,
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico ("SUP_IOCTL_PAGE_ALLOC_EX: fReserved0=%d fReserved1=%d\n", pReq->u.In.fReserved0, pReq->u.In.fReserved1));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* execute */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->Hdr.rc = SUPR0PageAllocEx(pSession, pReq->u.In.cPages, 0 /* fFlags */,
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->u.In.fUserMapping ? &pReq->u.Out.pvR3 : NULL,
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->u.In.fKernelMapping ? &pReq->u.Out.pvR0 : NULL,
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico VBOXDRV_SUPDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VINF_SUCCESS, pReq->Hdr.rc);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico case SUP_CTL_CODE_NO_SIZE(SUP_IOCTL_PAGE_MAP_KERNEL):
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* validate */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico PSUPPAGEMAPKERNEL pReq = (PSUPPAGEMAPKERNEL)pReqHdr;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_EXPR_FMT(!pReq->u.In.fFlags, ("SUP_IOCTL_PAGE_MAP_KERNEL: fFlags=%#x! MBZ\n", pReq->u.In.fFlags));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_EXPR_FMT(!(pReq->u.In.offSub & PAGE_OFFSET_MASK), ("SUP_IOCTL_PAGE_MAP_KERNEL: offSub=%#x\n", pReq->u.In.offSub));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_EXPR_FMT(pReq->u.In.cbSub && !(pReq->u.In.cbSub & PAGE_OFFSET_MASK),
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico ("SUP_IOCTL_PAGE_MAP_KERNEL: cbSub=%#x\n", pReq->u.In.cbSub));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* execute */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->Hdr.rc = SUPR0PageMapKernel(pSession, pReq->u.In.pvR3, pReq->u.In.offSub, pReq->u.In.cbSub,
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico VBOXDRV_SUPDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VINF_SUCCESS, pReq->Hdr.rc);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico case SUP_CTL_CODE_NO_SIZE(SUP_IOCTL_PAGE_PROTECT):
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* validate */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_EXPR_FMT(!(pReq->u.In.fProt & ~(RTMEM_PROT_READ | RTMEM_PROT_WRITE | RTMEM_PROT_EXEC | RTMEM_PROT_NONE)),
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico ("SUP_IOCTL_PAGE_PROTECT: fProt=%#x!\n", pReq->u.In.fProt));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_EXPR_FMT(!(pReq->u.In.offSub & PAGE_OFFSET_MASK), ("SUP_IOCTL_PAGE_PROTECT: offSub=%#x\n", pReq->u.In.offSub));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_EXPR_FMT(pReq->u.In.cbSub && !(pReq->u.In.cbSub & PAGE_OFFSET_MASK),
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico ("SUP_IOCTL_PAGE_PROTECT: cbSub=%#x\n", pReq->u.In.cbSub));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* execute */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico 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);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico VBOXDRV_SUPDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VINF_SUCCESS, pReq->Hdr.rc);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* validate */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* execute */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->Hdr.rc = SUPR0PageFree(pSession, pReq->u.In.pvR3);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico VBOXDRV_SUPDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VINF_SUCCESS, pReq->Hdr.rc);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico case SUP_CTL_CODE_NO_SIZE(SUP_IOCTL_CALL_SERVICE(0)):
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* validate */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico Log4(("SUP_IOCTL_CALL_SERVICE: op=%u in=%u arg=%RX64 p/t=%RTproc/%RTthrd\n",
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->u.In.uOperation, pReq->Hdr.cbIn, pReq->u.In.u64Arg, RTProcSelf(), RTThreadNativeSelf()));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico if (pReq->Hdr.cbIn == SUP_IOCTL_CALL_SERVICE_SIZE(0))
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_SIZES_EX(SUP_IOCTL_CALL_SERVICE, SUP_IOCTL_CALL_SERVICE_SIZE_IN(0), SUP_IOCTL_CALL_SERVICE_SIZE_OUT(0));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico PSUPR0SERVICEREQHDR pSrvReq = (PSUPR0SERVICEREQHDR)&pReq->abReqPkt[0];
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_EXPR_FMT(pReq->Hdr.cbIn >= SUP_IOCTL_CALL_SERVICE_SIZE(sizeof(SUPR0SERVICEREQHDR)),
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico ("SUP_IOCTL_CALL_SERVICE: cbIn=%#x < %#lx\n", pReq->Hdr.cbIn, SUP_IOCTL_CALL_SERVICE_SIZE(sizeof(SUPR0SERVICEREQHDR))));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_EXPR(SUP_IOCTL_CALL_SERVICE, pSrvReq->u32Magic == SUPR0SERVICEREQHDR_MAGIC);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_SIZES_EX(SUP_IOCTL_CALL_SERVICE, SUP_IOCTL_CALL_SERVICE_SIZE_IN(pSrvReq->cbReq), SUP_IOCTL_CALL_SERVICE_SIZE_OUT(pSrvReq->cbReq));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_EXPR(SUP_IOCTL_CALL_SERVICE, RTStrEnd(pReq->u.In.szName, sizeof(pReq->u.In.szName)));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* execute */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->Hdr.rc = supdrvIOCtl_CallServiceModule(pDevExt, pSession, pReq);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico VBOXDRV_SUPDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VINF_SUCCESS, pReq->Hdr.rc);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico case SUP_CTL_CODE_NO_SIZE(SUP_IOCTL_LOGGER_SETTINGS(0)):
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* validate */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico PSUPLOGGERSETTINGS pReq = (PSUPLOGGERSETTINGS)pReqHdr;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_SIZE_OUT(SUP_IOCTL_LOGGER_SETTINGS, SUP_IOCTL_LOGGER_SETTINGS_SIZE_OUT);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_EXPR(SUP_IOCTL_LOGGER_SETTINGS, pReq->Hdr.cbIn >= SUP_IOCTL_LOGGER_SETTINGS_SIZE_IN(1));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico cbStrTab = pReq->Hdr.cbIn - SUP_IOCTL_LOGGER_SETTINGS_SIZE_IN(0);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_EXPR(SUP_IOCTL_LOGGER_SETTINGS, pReq->u.In.offGroups < cbStrTab);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_EXPR(SUP_IOCTL_LOGGER_SETTINGS, pReq->u.In.offFlags < cbStrTab);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_EXPR(SUP_IOCTL_LOGGER_SETTINGS, pReq->u.In.offDestination < cbStrTab);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_EXPR_FMT(pReq->u.In.szStrings[cbStrTab - 1] == '\0',
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico ("SUP_IOCTL_LOGGER_SETTINGS: cbIn=%#x cbStrTab=%#zx LastChar=%d\n",
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->Hdr.cbIn, cbStrTab, pReq->u.In.szStrings[cbStrTab - 1]));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_EXPR(SUP_IOCTL_LOGGER_SETTINGS, pReq->u.In.fWhich <= SUPLOGGERSETTINGS_WHICH_RELEASE);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_EXPR(SUP_IOCTL_LOGGER_SETTINGS, pReq->u.In.fWhat <= SUPLOGGERSETTINGS_WHAT_DESTROY);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* execute */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->Hdr.rc = supdrvIOCtl_LoggerSettings(pDevExt, pSession, pReq);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico VBOXDRV_SUPDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VINF_SUCCESS, pReq->Hdr.rc);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* validate */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_SIZES_EX(SUP_IOCTL_SEM_CREATE, SUP_IOCTL_SEM_CREATE_SIZE_IN, SUP_IOCTL_SEM_CREATE_SIZE_OUT);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* execute */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->Hdr.rc = SUPSemEventCreate(pSession, &hEvent);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->Hdr.rc = SUPSemEventMultiCreate(pSession, &hEventMulti);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->u.Out.hSem = (uint32_t)(uintptr_t)hEventMulti;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico VBOXDRV_SUPDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VINF_SUCCESS, pReq->Hdr.rc);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* validate */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_SIZES_EX(SUP_IOCTL_SEM_OP, SUP_IOCTL_SEM_OP_SIZE_IN, SUP_IOCTL_SEM_OP_SIZE_OUT);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* execute */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico SUPSEMEVENT hEvent = (SUPSEMEVENT)(uintptr_t)pReq->u.In.hSem;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->Hdr.rc = SUPSemEventWaitNoResume(pSession, hEvent, pReq->u.In.cMillies);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->Hdr.rc = SUPSemEventSignal(pSession, hEvent);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->Hdr.rc = SUPSemEventClose(pSession, hEvent);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico SUPSEMEVENTMULTI hEventMulti = (SUPSEMEVENTMULTI)(uintptr_t)pReq->u.In.hSem;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->Hdr.rc = SUPSemEventMultiWaitNoResume(pSession, hEventMulti, pReq->u.In.cMillies);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->Hdr.rc = SUPSemEventMultiSignal(pSession, hEventMulti);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->Hdr.rc = SUPSemEventMultiClose(pSession, hEventMulti);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->Hdr.rc = SUPSemEventMultiReset(pSession, hEventMulti);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico VBOXDRV_SUPDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VINF_SUCCESS, pReq->Hdr.rc);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* validate */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_SIZES_EX(SUP_IOCTL_SEM_OP2, SUP_IOCTL_SEM_OP2_SIZE_IN, SUP_IOCTL_SEM_OP2_SIZE_OUT);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_EXPR(SUP_IOCTL_SEM_OP2, pReq->u.In.uReserved == 0);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* execute */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico SUPSEMEVENT hEvent = (SUPSEMEVENT)(uintptr_t)pReq->u.In.hSem;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->Hdr.rc = SUPSemEventWaitNoResume(pSession, hEvent, pReq->u.In.uArg.cRelMsTimeout);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->Hdr.rc = SUPSemEventWaitNsAbsIntr(pSession, hEvent, pReq->u.In.uArg.uAbsNsTimeout);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->Hdr.rc = SUPSemEventWaitNsRelIntr(pSession, hEvent, pReq->u.In.uArg.cRelNsTimeout);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->Hdr.rc = SUPSemEventSignal(pSession, hEvent);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->Hdr.rc = SUPSemEventClose(pSession, hEvent);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico SUPSEMEVENTMULTI hEventMulti = (SUPSEMEVENTMULTI)(uintptr_t)pReq->u.In.hSem;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->Hdr.rc = SUPSemEventMultiWaitNoResume(pSession, hEventMulti, pReq->u.In.uArg.cRelMsTimeout);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->Hdr.rc = SUPSemEventMultiWaitNsAbsIntr(pSession, hEventMulti, pReq->u.In.uArg.uAbsNsTimeout);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->Hdr.rc = SUPSemEventMultiWaitNsRelIntr(pSession, hEventMulti, pReq->u.In.uArg.cRelNsTimeout);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->Hdr.rc = SUPSemEventMultiSignal(pSession, hEventMulti);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->Hdr.rc = SUPSemEventMultiClose(pSession, hEventMulti);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->Hdr.rc = SUPSemEventMultiReset(pSession, hEventMulti);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* validate */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_SIZES_EX(SUP_IOCTL_SEM_OP3, SUP_IOCTL_SEM_OP3_SIZE_IN, SUP_IOCTL_SEM_OP3_SIZE_OUT);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_EXPR(SUP_IOCTL_SEM_OP3, pReq->u.In.u32Reserved == 0 && pReq->u.In.u64Reserved == 0);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* execute */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico SUPSEMEVENT hEvent = (SUPSEMEVENT)(uintptr_t)pReq->u.In.hSem;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_EXPR(SUP_IOCTL_SEM_OP3, hEvent == NIL_SUPSEMEVENT);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->Hdr.rc = SUPSemEventCreate(pSession, &hEvent);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_EXPR(SUP_IOCTL_SEM_OP3, hEvent == NIL_SUPSEMEVENT);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->u.Out.cNsResolution = SUPSemEventGetResolution(pSession);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico SUPSEMEVENTMULTI hEventMulti = (SUPSEMEVENTMULTI)(uintptr_t)pReq->u.In.hSem;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_EXPR(SUP_IOCTL_SEM_OP3, hEventMulti == NIL_SUPSEMEVENTMULTI);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->Hdr.rc = SUPSemEventMultiCreate(pSession, &hEventMulti);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->u.Out.hSem = (uint32_t)(uintptr_t)hEventMulti;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_EXPR(SUP_IOCTL_SEM_OP3, hEventMulti == NIL_SUPSEMEVENTMULTI);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->u.Out.cNsResolution = SUPSemEventMultiGetResolution(pSession);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* validate */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_EXPR(SUP_IOCTL_VT_CAPS, pReq->Hdr.cbIn <= SUP_IOCTL_VT_CAPS_SIZE_IN);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* execute */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->Hdr.rc = SUPR0QueryVTCaps(pSession, &pReq->u.Out.Caps);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico VBOXDRV_SUPDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VINF_SUCCESS, pReq->Hdr.rc);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico VBOXDRV_SUPDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VERR_GENERAL_FAILURE, VERR_GENERAL_FAILURE);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Inter-Driver Communcation (IDC) worker.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns VBox status code.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @retval VINF_SUCCESS on success.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @retval VERR_INVALID_PARAMETER if the request is invalid.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @retval VERR_NOT_SUPPORTED if the request isn't supported.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param uReq The request (function) code.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pDevExt Device extention.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pSession Session data.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pReqHdr The request header.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicoint VBOXCALL supdrvIDC(uintptr_t uReq, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPDRVIDCREQHDR pReqHdr)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * The OS specific code has already validated the pSession
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * pointer, and the request size being greater or equal to
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * size of the header.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * So, just check that pSession is a kernel context session.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Validation macro.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico OSDBGPRINT(( #Name ": Invalid input/output sizes. cb=%ld expected %ld.\n", \
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico PSUPDRVIDCREQCONNECT pReq = (PSUPDRVIDCREQCONNECT)pReqHdr;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_IDC_SIZE(SUPDRV_IDC_REQ_CONNECT, sizeof(*pReq));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Validate the cookie and other input.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico OSDBGPRINT(("SUPDRV_IDC_REQ_CONNECT: pSession=%p expected NULL!\n", pReq->Hdr.pSession));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico if (pReq->u.In.u32MagicCookie != SUPDRVIDCREQ_CONNECT_MAGIC_COOKIE)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico OSDBGPRINT(("SUPDRV_IDC_REQ_CONNECT: u32MagicCookie=%#x expected %#x!\n",
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico (unsigned)pReq->u.In.u32MagicCookie, (unsigned)SUPDRVIDCREQ_CONNECT_MAGIC_COOKIE));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico if ( pReq->u.In.uMinVersion > pReq->u.In.uReqVersion
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico || (pReq->u.In.uMinVersion & UINT32_C(0xffff0000)) != (pReq->u.In.uReqVersion & UINT32_C(0xffff0000)))
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico OSDBGPRINT(("SUPDRV_IDC_REQ_CONNECT: uMinVersion=%#x uMaxVersion=%#x doesn't match!\n",
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Match the version.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * The current logic is very simple, match the major interface version.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico || (pReq->u.In.uMinVersion & 0xffff0000) != (SUPDRV_IDC_VERSION & 0xffff0000))
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico OSDBGPRINT(("SUPDRV_IDC_REQ_CONNECT: Version mismatch. Requested: %#x Min: %#x Current: %#x\n",
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->u.In.uReqVersion, pReq->u.In.uMinVersion, (unsigned)SUPDRV_IDC_VERSION));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * On NT we will already have a session associated with the
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * client, just like with the SUP_IOCTL_COOKIE request, while
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * the other doesn't.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->Hdr.rc = supdrvCreateSession(pDevExt, false /* fUser */, &pSession);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico OSDBGPRINT(("SUPDRV_IDC_REQ_CONNECT: failed to create session, rc=%d\n", pReq->Hdr.rc));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_IDC_SIZE(SUPDRV_IDC_REQ_DISCONNECT, sizeof(*pReqHdr));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* Windows will destroy the session when the file object is destroyed. */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico PSUPDRVIDCREQGETSYM pReq = (PSUPDRVIDCREQGETSYM)pReqHdr;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_IDC_SIZE(SUPDRV_IDC_REQ_GET_SYMBOL, sizeof(*pReq));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->Hdr.rc = supdrvIDC_LdrGetSymbol(pDevExt, pSession, pReq);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico PSUPDRVIDCREQCOMPREGFACTORY pReq = (PSUPDRVIDCREQCOMPREGFACTORY)pReqHdr;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_IDC_SIZE(SUPDRV_IDC_REQ_COMPONENT_REGISTER_FACTORY, sizeof(*pReq));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->Hdr.rc = SUPR0ComponentRegisterFactory(pSession, pReq->u.In.pFactory);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico PSUPDRVIDCREQCOMPDEREGFACTORY pReq = (PSUPDRVIDCREQCOMPDEREGFACTORY)pReqHdr;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico REQ_CHECK_IDC_SIZE(SUPDRV_IDC_REQ_COMPONENT_DEREGISTER_FACTORY, sizeof(*pReq));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->Hdr.rc = SUPR0ComponentDeregisterFactory(pSession, pReq->u.In.pFactory);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Register a object for reference counting.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * The object is registered with one reference in the specified session.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns Unique identifier on success (pointer).
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * All future reference must use this identifier.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns NULL on failure.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pfnDestructor The destructore function which will be called when the reference count reaches 0.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pvUser1 The first user argument.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pvUser2 The second user argument.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicoSUPR0DECL(void *) SUPR0ObjRegister(PSUPDRVSESSION pSession, SUPDRVOBJTYPE enmType, PFNSUPDRVDESTRUCTOR pfnDestructor, void *pvUser1, void *pvUser2)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSPINLOCKTMP SpinlockTmp = RTSPINLOCKTMP_INITIALIZER;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Validate the input.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertReturn(SUP_IS_SESSION_VALID(pSession), NULL);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertReturn(enmType > SUPDRVOBJTYPE_INVALID && enmType < SUPDRVOBJTYPE_END, NULL);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Allocate and initialize the object.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Allocate the usage record.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * (We keep freed usage records around to simplify SUPR0ObjAddRefEx().)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSpinlockAcquire(pDevExt->Spinlock, &SpinlockTmp);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSpinlockRelease(pDevExt->Spinlock, &SpinlockTmp);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pUsage = (PSUPDRVUSAGE)RTMemAlloc(sizeof(*pUsage));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSpinlockAcquire(pDevExt->Spinlock, &SpinlockTmp);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Insert the object and create the session usage record.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* The object. */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* The session record. */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* Log2(("SUPR0ObjRegister: pUsage=%p:{.pObj=%p, .pNext=%p}\n", pUsage, pUsage->pObj, pUsage->pNext)); */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSpinlockRelease(pDevExt->Spinlock, &SpinlockTmp);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico Log(("SUPR0ObjRegister: returns %p (pvUser1=%p, pvUser=%p)\n", pObj, pvUser1, pvUser2));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Increment the reference counter for the object associating the reference
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * with the specified session.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns IPRT status code.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pvObj The identifier returned by SUPR0ObjRegister().
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pSession The session which is referencing the object.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @remarks The caller should not own any spinlocks and must carefully protect
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * itself against potential race with the destructor so freed memory
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * isn't accessed here.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicoSUPR0DECL(int) SUPR0ObjAddRef(void *pvObj, PSUPDRVSESSION pSession)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico return SUPR0ObjAddRefEx(pvObj, pSession, false /* fNoBlocking */);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Increment the reference counter for the object associating the reference
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * with the specified session.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns IPRT status code.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @retval VERR_TRY_AGAIN if fNoBlocking was set and a new usage record
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * couldn't be allocated. (If you see this you're not doing the right
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * thing and it won't ever work reliably.)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pvObj The identifier returned by SUPR0ObjRegister().
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pSession The session which is referencing the object.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param fNoBlocking Set if it's not OK to block. Never try to make the
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * first reference to an object in a session with this
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * argument set.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @remarks The caller should not own any spinlocks and must carefully protect
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * itself against potential race with the destructor so freed memory
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * isn't accessed here.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicoSUPR0DECL(int) SUPR0ObjAddRefEx(void *pvObj, PSUPDRVSESSION pSession, bool fNoBlocking)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSPINLOCKTMP SpinlockTmp = RTSPINLOCKTMP_INITIALIZER;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Validate the input.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Be ready for the destruction race (someone might be stuck in the
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * destructor waiting a lock we own).
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertReturn(SUP_IS_SESSION_VALID(pSession), VERR_INVALID_PARAMETER);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertMsgReturn(pObj->u32Magic == SUPDRVOBJ_MAGIC || pObj->u32Magic == SUPDRVOBJ_MAGIC_DEAD,
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico ("Invalid pvObj=%p magic=%#x (expected %#x or %#x)\n", pvObj, pObj->u32Magic, SUPDRVOBJ_MAGIC, SUPDRVOBJ_MAGIC_DEAD),
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSpinlockAcquire(pDevExt->Spinlock, &SpinlockTmp);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico if (RT_UNLIKELY(pObj->u32Magic != SUPDRVOBJ_MAGIC))
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSpinlockRelease(pDevExt->Spinlock, &SpinlockTmp);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertMsgFailed(("pvObj=%p magic=%#x\n", pvObj, pObj->u32Magic));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Preallocate the usage record if we can.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSpinlockRelease(pDevExt->Spinlock, &SpinlockTmp);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pUsagePre = (PSUPDRVUSAGE)RTMemAlloc(sizeof(*pUsagePre));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSpinlockAcquire(pDevExt->Spinlock, &SpinlockTmp);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico if (RT_UNLIKELY(pObj->u32Magic != SUPDRVOBJ_MAGIC))
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSpinlockRelease(pDevExt->Spinlock, &SpinlockTmp);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertMsgFailed(("pvObj=%p magic=%#x\n", pvObj, pObj->u32Magic));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Reference the object.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Look for the session record.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico for (pUsage = pSession->pUsage; pUsage; pUsage = pUsage->pNext)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /*Log(("SUPR0AddRef: pUsage=%p:{.pObj=%p, .pNext=%p}\n", pUsage, pUsage->pObj, pUsage->pNext));*/
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* create a new session record. */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /*Log(("SUPR0AddRef: pUsagePre=%p:{.pObj=%p, .pNext=%p}\n", pUsagePre, pUsagePre->pObj, pUsagePre->pNext));*/
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Put any unused usage record into the free list..
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSpinlockRelease(pDevExt->Spinlock, &SpinlockTmp);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Decrement / destroy a reference counter record for an object.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * The object is uniquely identified by pfnDestructor+pvUser1+pvUser2.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns IPRT status code.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @retval VINF_SUCCESS if not destroyed.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @retval VINF_OBJECT_DESTROYED if it's destroyed by this release call.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @retval VERR_INVALID_PARAMETER if the object isn't valid. Will assert in
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * string builds.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pvObj The identifier returned by SUPR0ObjRegister().
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pSession The session which is referencing the object.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicoSUPR0DECL(int) SUPR0ObjRelease(void *pvObj, PSUPDRVSESSION pSession)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSPINLOCKTMP SpinlockTmp = RTSPINLOCKTMP_INITIALIZER;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Validate the input.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertReturn(SUP_IS_SESSION_VALID(pSession), VERR_INVALID_PARAMETER);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertMsgReturn(VALID_PTR(pObj) && pObj->u32Magic == SUPDRVOBJ_MAGIC,
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico ("Invalid pvObj=%p magic=%#x (exepcted %#x)\n", pvObj, pObj ? pObj->u32Magic : 0, SUPDRVOBJ_MAGIC),
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Acquire the spinlock and look for the usage record.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSpinlockAcquire(pDevExt->Spinlock, &SpinlockTmp);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico for (pUsagePrev = NULL, pUsage = pSession->pUsage;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /*Log2(("SUPR0ObjRelease: pUsage=%p:{.pObj=%p, .pNext=%p}\n", pUsage, pUsage->pObj, pUsage->pNext));*/
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertMsg(pUsage->cUsage >= 1 && pObj->cUsage >= pUsage->cUsage, ("glob %d; sess %d\n", pObj->cUsage, pUsage->cUsage));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Free the session record.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* What about the object? */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Object is to be destroyed, unlink it.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico for (pObjPrev = pDevExt->pObjs; pObjPrev; pObjPrev = pObjPrev->pNext)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSpinlockRelease(pDevExt->Spinlock, &SpinlockTmp);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Call the destructor and free the object if required.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico Log(("SUPR0ObjRelease: destroying %p/%d (%p/%p) cpid=%RTproc pid=%RTproc dtor=%p\n",
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pObj, pObj->enmType, pObj->pvUser1, pObj->pvUser2, pObj->CreatorProcess, RTProcSelf(), pObj->pfnDestructor));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pObj->pfnDestructor(pObj, pObj->pvUser1, pObj->pvUser2);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Verifies that the current process can access the specified object.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns The following IPRT status code:
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @retval VINF_SUCCESS if access was granted.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @retval VERR_PERMISSION_DENIED if denied access.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @retval VERR_INVALID_PARAMETER if invalid parameter.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pvObj The identifier returned by SUPR0ObjRegister().
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pSession The session which wishes to access the object.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pszObjName Object string name. This is optional and depends on the object type.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @remark The caller is responsible for making sure the object isn't removed while
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * we're inside this function. If uncertain about this, just call AddRef before calling us.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicoSUPR0DECL(int) SUPR0ObjVerifyAccess(void *pvObj, PSUPDRVSESSION pSession, const char *pszObjName)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Validate the input.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertReturn(SUP_IS_SESSION_VALID(pSession), VERR_INVALID_PARAMETER);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertMsgReturn(VALID_PTR(pObj) && pObj->u32Magic == SUPDRVOBJ_MAGIC,
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico ("Invalid pvObj=%p magic=%#x (exepcted %#x)\n", pvObj, pObj ? pObj->u32Magic : 0, SUPDRVOBJ_MAGIC),
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Check access. (returns true if a decision has been made.)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico if (supdrvOSObjCanAccess(pObj, pSession, pszObjName, &rc))
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Default policy is to allow the user to access his own
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * stuff but nothing else.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Lock pages.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns IPRT status code.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pSession Session to which the locked memory should be associated.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pvR3 Start of the memory range to lock.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * This must be page aligned.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param cPages Number of pages to lock.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param paPages Where to put the physical addresses of locked memory.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicoSUPR0DECL(int) SUPR0LockMem(PSUPDRVSESSION pSession, RTR3PTR pvR3, uint32_t cPages, PRTHCPHYS paPages)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico SUPDRVMEMREF Mem = { NIL_RTR0MEMOBJ, NIL_RTR0MEMOBJ, MEMREF_TYPE_UNUSED };
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico LogFlow(("SUPR0LockMem: pSession=%p pvR3=%p cPages=%d paPages=%p\n", pSession, (void *)pvR3, cPages, paPages));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Verify input.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertReturn(SUP_IS_SESSION_VALID(pSession), VERR_INVALID_PARAMETER);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico if ( RT_ALIGN_R3PT(pvR3, PAGE_SIZE, RTR3PTR) != pvR3
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico Log(("pvR3 (%p) must be page aligned and not NULL!\n", (void *)pvR3));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Let IPRT do the job.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = RTR0MemObjLockUser(&Mem.MemObj, pvR3, cb, RTMEM_PROT_READ | RTMEM_PROT_WRITE, RTR0ProcHandleSelf());
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertMsg(RTR0MemObjAddressR3(Mem.MemObj) == pvR3, ("%p == %p\n", RTR0MemObjAddressR3(Mem.MemObj), pvR3));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertMsg(RTR0MemObjSize(Mem.MemObj) == cb, ("%x == %x\n", RTR0MemObjSize(Mem.MemObj), cb));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico while (iPage-- > 0)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico paPages[iPage] = RTR0MemObjGetPagePhysAddr(Mem.MemObj, iPage);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Unlocks the memory pointed to by pv.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns IPRT status code.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pSession Session to which the memory was locked.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pvR3 Memory to unlock.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicoSUPR0DECL(int) SUPR0UnlockMem(PSUPDRVSESSION pSession, RTR3PTR pvR3)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico LogFlow(("SUPR0UnlockMem: pSession=%p pvR3=%p\n", pSession, (void *)pvR3));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertReturn(SUP_IS_SESSION_VALID(pSession), VERR_INVALID_PARAMETER);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico return supdrvMemRelease(pSession, (RTHCUINTPTR)pvR3, MEMREF_TYPE_LOCKED);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Allocates a chunk of page aligned memory with contiguous and fixed physical
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns IPRT status code.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pSession Session data.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param cPages Number of pages to allocate.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param ppvR0 Where to put the address of Ring-0 mapping the allocated memory.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param ppvR3 Where to put the address of Ring-3 mapping the allocated memory.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pHCPhys Where to put the physical address of allocated memory.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicoSUPR0DECL(int) SUPR0ContAlloc(PSUPDRVSESSION pSession, uint32_t cPages, PRTR0PTR ppvR0, PRTR3PTR ppvR3, PRTHCPHYS pHCPhys)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico SUPDRVMEMREF Mem = { NIL_RTR0MEMOBJ, NIL_RTR0MEMOBJ, MEMREF_TYPE_UNUSED };
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico LogFlow(("SUPR0ContAlloc: pSession=%p cPages=%d ppvR0=%p ppvR3=%p pHCPhys=%p\n", pSession, cPages, ppvR0, ppvR3, pHCPhys));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Validate input.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertReturn(SUP_IS_SESSION_VALID(pSession), VERR_INVALID_PARAMETER);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico Log(("Null pointer. All of these should be set: pSession=%p ppvR0=%p ppvR3=%p pHCPhys=%p\n",
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico Log(("Illegal request cPages=%d, must be greater than 0 and smaller than 256.\n", cPages));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Let IPRT do the job.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = RTR0MemObjAllocCont(&Mem.MemObj, cPages << PAGE_SHIFT, true /* executable R0 mapping */);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = RTR0MemObjMapUser(&Mem.MapObjR3, Mem.MemObj, (RTR3PTR)-1, 0,
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTMEM_PROT_EXEC | RTMEM_PROT_WRITE | RTMEM_PROT_READ, RTR0ProcHandleSelf());
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico *pHCPhys = RTR0MemObjGetPagePhysAddr(Mem.MemObj, 0);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Frees memory allocated using SUPR0ContAlloc().
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns IPRT status code.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pSession The session to which the memory was allocated.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param uPtr Pointer to the memory (ring-3 or ring-0).
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicoSUPR0DECL(int) SUPR0ContFree(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico LogFlow(("SUPR0ContFree: pSession=%p uPtr=%p\n", pSession, (void *)uPtr));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertReturn(SUP_IS_SESSION_VALID(pSession), VERR_INVALID_PARAMETER);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico return supdrvMemRelease(pSession, uPtr, MEMREF_TYPE_CONT);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Allocates a chunk of page aligned memory with fixed physical backing below 4GB.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * The memory isn't zeroed.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns IPRT status code.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pSession Session data.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param cPages Number of pages to allocate.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param ppvR0 Where to put the address of Ring-0 mapping of the allocated memory.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param ppvR3 Where to put the address of Ring-3 mapping of the allocated memory.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param paPages Where to put the physical addresses of allocated memory.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicoSUPR0DECL(int) SUPR0LowAlloc(PSUPDRVSESSION pSession, uint32_t cPages, PRTR0PTR ppvR0, PRTR3PTR ppvR3, PRTHCPHYS paPages)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico SUPDRVMEMREF Mem = { NIL_RTR0MEMOBJ, NIL_RTR0MEMOBJ, MEMREF_TYPE_UNUSED };
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico LogFlow(("SUPR0LowAlloc: pSession=%p cPages=%d ppvR3=%p ppvR0=%p paPages=%p\n", pSession, cPages, ppvR3, ppvR0, paPages));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Validate input.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertReturn(SUP_IS_SESSION_VALID(pSession), VERR_INVALID_PARAMETER);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico Log(("Null pointer. All of these should be set: pSession=%p ppvR3=%p ppvR0=%p paPages=%p\n",
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico Log(("Illegal request cPages=%d, must be greater than 0 and smaller than 256.\n", cPages));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Let IPRT do the work.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = RTR0MemObjAllocLow(&Mem.MemObj, cPages << PAGE_SHIFT, true /* executable ring-0 mapping */);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = RTR0MemObjMapUser(&Mem.MapObjR3, Mem.MemObj, (RTR3PTR)-1, 0,
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTMEM_PROT_EXEC | RTMEM_PROT_WRITE | RTMEM_PROT_READ, RTR0ProcHandleSelf());
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico paPages[iPage] = RTR0MemObjGetPagePhysAddr(Mem.MemObj, iPage);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertMsg(!(paPages[iPage] & (PAGE_SIZE - 1)), ("iPage=%d Phys=%RHp\n", paPages[iPage]));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Frees memory allocated using SUPR0LowAlloc().
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns IPRT status code.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pSession The session to which the memory was allocated.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param uPtr Pointer to the memory (ring-3 or ring-0).
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicoSUPR0DECL(int) SUPR0LowFree(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico LogFlow(("SUPR0LowFree: pSession=%p uPtr=%p\n", pSession, (void *)uPtr));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertReturn(SUP_IS_SESSION_VALID(pSession), VERR_INVALID_PARAMETER);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico return supdrvMemRelease(pSession, uPtr, MEMREF_TYPE_LOW);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Allocates a chunk of memory with both R0 and R3 mappings.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * The memory is fixed and it's possible to query the physical addresses using SUPR0MemGetPhys().
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns IPRT status code.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pSession The session to associated the allocation with.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param cb Number of bytes to allocate.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param ppvR0 Where to store the address of the Ring-0 mapping.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param ppvR3 Where to store the address of the Ring-3 mapping.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicoSUPR0DECL(int) SUPR0MemAlloc(PSUPDRVSESSION pSession, uint32_t cb, PRTR0PTR ppvR0, PRTR3PTR ppvR3)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico SUPDRVMEMREF Mem = { NIL_RTR0MEMOBJ, NIL_RTR0MEMOBJ, MEMREF_TYPE_UNUSED };
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico LogFlow(("SUPR0MemAlloc: pSession=%p cb=%d ppvR0=%p ppvR3=%p\n", pSession, cb, ppvR0, ppvR3));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Validate input.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertReturn(SUP_IS_SESSION_VALID(pSession), VERR_INVALID_PARAMETER);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico Log(("Illegal request cb=%u; must be greater than 0 and smaller than 4MB.\n", cb));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Let IPRT do the work.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = RTR0MemObjAllocPage(&Mem.MemObj, cb, true /* executable ring-0 mapping */);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = RTR0MemObjMapUser(&Mem.MapObjR3, Mem.MemObj, (RTR3PTR)-1, 0,
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTMEM_PROT_EXEC | RTMEM_PROT_WRITE | RTMEM_PROT_READ, RTR0ProcHandleSelf());
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Get the physical addresses of memory allocated using SUPR0MemAlloc().
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns IPRT status code.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pSession The session to which the memory was allocated.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param uPtr The Ring-0 or Ring-3 address returned by SUPR0MemAlloc().
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param paPages Where to store the physical addresses.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicoSUPR0DECL(int) SUPR0MemGetPhys(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr, PSUPPAGE paPages) /** @todo switch this bugger to RTHCPHYS */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSPINLOCKTMP SpinlockTmp = RTSPINLOCKTMP_INITIALIZER;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico LogFlow(("SUPR0MemGetPhys: pSession=%p uPtr=%p paPages=%p\n", pSession, (void *)uPtr, paPages));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Validate input.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertReturn(SUP_IS_SESSION_VALID(pSession), VERR_INVALID_PARAMETER);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Search for the address.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSpinlockAcquire(pSession->Spinlock, &SpinlockTmp);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico for (pBundle = &pSession->Bundle; pBundle; pBundle = pBundle->pNext)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico && ( (RTHCUINTPTR)RTR0MemObjAddress(pBundle->aMem[i].MemObj) == uPtr
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico && RTR0MemObjAddressR3(pBundle->aMem[i].MapObjR3) == uPtr)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico const size_t cPages = RTR0MemObjSize(pBundle->aMem[i].MemObj) >> PAGE_SHIFT;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico paPages[iPage].Phys = RTR0MemObjGetPagePhysAddr(pBundle->aMem[i].MemObj, iPage);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSpinlockRelease(pSession->Spinlock, &SpinlockTmp);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSpinlockRelease(pSession->Spinlock, &SpinlockTmp);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Free memory allocated by SUPR0MemAlloc().
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns IPRT status code.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pSession The session owning the allocation.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param uPtr The Ring-0 or Ring-3 address returned by SUPR0MemAlloc().
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicoSUPR0DECL(int) SUPR0MemFree(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico LogFlow(("SUPR0MemFree: pSession=%p uPtr=%p\n", pSession, (void *)uPtr));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertReturn(SUP_IS_SESSION_VALID(pSession), VERR_INVALID_PARAMETER);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico return supdrvMemRelease(pSession, uPtr, MEMREF_TYPE_MEM);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Allocates a chunk of memory with a kernel or/and a user mode mapping.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * The memory is fixed and it's possible to query the physical addresses using
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * SUPR0MemGetPhys().
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns IPRT status code.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pSession The session to associated the allocation with.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param cPages The number of pages to allocate.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param fFlags Flags, reserved for the future. Must be zero.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param ppvR3 Where to store the address of the Ring-3 mapping.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * NULL if no ring-3 mapping.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param ppvR3 Where to store the address of the Ring-0 mapping.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * NULL if no ring-0 mapping.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param paPages Where to store the addresses of the pages. Optional.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicoSUPR0DECL(int) SUPR0PageAllocEx(PSUPDRVSESSION pSession, uint32_t cPages, uint32_t fFlags, PRTR3PTR ppvR3, PRTR0PTR ppvR0, PRTHCPHYS paPages)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico SUPDRVMEMREF Mem = { NIL_RTR0MEMOBJ, NIL_RTR0MEMOBJ, MEMREF_TYPE_UNUSED };
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico LogFlow(("SUPR0PageAlloc: pSession=%p cb=%d ppvR3=%p\n", pSession, cPages, ppvR3));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Validate input. The allowed allocation size must be at least equal to the maximum guest VRAM size.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertReturn(SUP_IS_SESSION_VALID(pSession), VERR_INVALID_PARAMETER);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertReturn(ppvR3 || ppvR0, VERR_INVALID_PARAMETER);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico if (cPages < 1 || cPages > VBOX_MAX_ALLOC_PAGE_COUNT)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico 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)));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Let IPRT do the work.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = RTR0MemObjAllocPage(&Mem.MemObj, (size_t)cPages * PAGE_SIZE, true /* fExecutable */);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = RTR0MemObjAllocPhysNC(&Mem.MemObj, (size_t)cPages * PAGE_SIZE, NIL_RTHCPHYS);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = RTR0MemObjMapUser(&Mem.MapObjR3, Mem.MemObj, (RTR3PTR)-1, 0,
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTMEM_PROT_EXEC | RTMEM_PROT_WRITE | RTMEM_PROT_READ, RTR0ProcHandleSelf());
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico while (iPage-- > 0)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico paPages[iPage] = RTR0MemObjGetPagePhysAddr(Mem.MapObjR3, iPage);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Maps a chunk of memory previously allocated by SUPR0PageAllocEx into kernel
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns IPRT status code.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pSession The session to associated the allocation with.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pvR3 The ring-3 address returned by SUPR0PageAllocEx.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param offSub Where to start mapping. Must be page aligned.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param cbSub How much to map. Must be page aligned.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param fFlags Flags, MBZ.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param ppvR0 Where to reutrn the address of the ring-0 mapping on
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicoSUPR0DECL(int) SUPR0PageMapKernel(PSUPDRVSESSION pSession, RTR3PTR pvR3, uint32_t offSub, uint32_t cbSub,
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSPINLOCKTMP SpinlockTmp = RTSPINLOCKTMP_INITIALIZER;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico LogFlow(("SUPR0PageMapKernel: pSession=%p pvR3=%p offSub=%#x cbSub=%#x\n", pSession, pvR3, offSub, cbSub));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Validate input. The allowed allocation size must be at least equal to the maximum guest VRAM size.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertReturn(SUP_IS_SESSION_VALID(pSession), VERR_INVALID_PARAMETER);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertReturn(!(offSub & PAGE_OFFSET_MASK), VERR_INVALID_PARAMETER);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertReturn(!(cbSub & PAGE_OFFSET_MASK), VERR_INVALID_PARAMETER);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Find the memory object.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSpinlockAcquire(pSession->Spinlock, &SpinlockTmp);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico for (pBundle = &pSession->Bundle; pBundle; pBundle = pBundle->pNext)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico && RTR0MemObjAddressR3(pBundle->aMem[i].MapObjR3) == pvR3)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico && RTR0MemObjAddressR3(pBundle->aMem[i].MemObj) == pvR3))
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSpinlockRelease(pSession->Spinlock, &SpinlockTmp);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Do some furter input validations before calling IPRT.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * (Cleanup is done indirectly by telling RTR0MemObjFree to include mappings.)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = RTR0MemObjMapKernelEx(&hMapObj, hMemObj, (void *)-1, 0,
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTMEM_PROT_READ | RTMEM_PROT_WRITE, offSub, cbSub);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico SUPR0Printf("SUPR0PageMapKernel: cbMemObj=%#x offSub=%#x cbSub=%#x\n", cbMemObj, offSub, cbSub);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Changes the page level protection of one or more pages previously allocated
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * by SUPR0PageAllocEx.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns IPRT status code.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pSession The session to associated the allocation with.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pvR3 The ring-3 address returned by SUPR0PageAllocEx.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * NIL_RTR3PTR if the ring-3 mapping should be unaffected.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pvR0 The ring-0 address returned by SUPR0PageAllocEx.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * NIL_RTR0PTR if the ring-0 mapping should be unaffected.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param offSub Where to start changing. Must be page aligned.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param cbSub How much to change. Must be page aligned.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param fProt The new page level protection, see RTMEM_PROT_*.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicoSUPR0DECL(int) SUPR0PageProtect(PSUPDRVSESSION pSession, RTR3PTR pvR3, RTR0PTR pvR0, uint32_t offSub, uint32_t cbSub, uint32_t fProt)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSPINLOCKTMP SpinlockTmp = RTSPINLOCKTMP_INITIALIZER;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico LogFlow(("SUPR0PageProtect: pSession=%p pvR3=%p pvR0=%p offSub=%#x cbSub=%#x fProt-%#x\n", pSession, pvR3, pvR0, offSub, cbSub, fProt));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Validate input. The allowed allocation size must be at least equal to the maximum guest VRAM size.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertReturn(SUP_IS_SESSION_VALID(pSession), VERR_INVALID_PARAMETER);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertReturn(!(fProt & ~(RTMEM_PROT_READ | RTMEM_PROT_WRITE | RTMEM_PROT_EXEC | RTMEM_PROT_NONE)), VERR_INVALID_PARAMETER);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertReturn(!(offSub & PAGE_OFFSET_MASK), VERR_INVALID_PARAMETER);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertReturn(!(cbSub & PAGE_OFFSET_MASK), VERR_INVALID_PARAMETER);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Find the memory object.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSpinlockAcquire(pSession->Spinlock, &SpinlockTmp);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico for (pBundle = &pSession->Bundle; pBundle; pBundle = pBundle->pNext)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico || RTR0MemObjAddress(pBundle->aMem[i].MemObj) == pvR0)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico || RTR0MemObjAddressR3(pBundle->aMem[i].MapObjR3) == pvR3))
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSpinlockRelease(pSession->Spinlock, &SpinlockTmp);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Do some furter input validations before calling IPRT.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico size_t cbMemObj = hMemObjR0 != NIL_RTR0PTR ? RTR0MemObjSize(hMemObjR0) : RTR0MemObjSize(hMemObjR3);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = RTR0MemObjProtect(hMemObjR3, offSub, cbSub, fProt);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = RTR0MemObjProtect(hMemObjR0, offSub, cbSub, fProt);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico SUPR0Printf("SUPR0PageMapKernel: cbMemObj=%#x offSub=%#x cbSub=%#x\n", cbMemObj, offSub, cbSub);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Free memory allocated by SUPR0PageAlloc() and SUPR0PageAllocEx().
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns IPRT status code.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pSession The session owning the allocation.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pvR3 The Ring-3 address returned by SUPR0PageAlloc() or
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * SUPR0PageAllocEx().
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicoSUPR0DECL(int) SUPR0PageFree(PSUPDRVSESSION pSession, RTR3PTR pvR3)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico LogFlow(("SUPR0PageFree: pSession=%p pvR3=%p\n", pSession, (void *)pvR3));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertReturn(SUP_IS_SESSION_VALID(pSession), VERR_INVALID_PARAMETER);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico return supdrvMemRelease(pSession, (RTHCUINTPTR)pvR3, MEMREF_TYPE_PAGE);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Gets the paging mode of the current CPU.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns Paging mode, SUPPAGEINGMODE_INVALID on error.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico if ((cr0 & (X86_CR0_PG | X86_CR0_PE)) != (X86_CR0_PG | X86_CR0_PE))
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico if (fAmdFeatures & (X86_CPUID_AMD_FEATURE_EDX_NX | X86_CPUID_AMD_FEATURE_EDX_LONG_MODE))
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico if ((fAmdFeatures & X86_CPUID_AMD_FEATURE_EDX_NX) && (efer & MSR_K6_EFER_NXE))
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico if ((fAmdFeatures & X86_CPUID_AMD_FEATURE_EDX_LONG_MODE) && (efer & MSR_K6_EFER_LMA))
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico switch ((cr4 & (X86_CR4_PAE | X86_CR4_PGE)) | fNXEPlusLMA)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico case RT_BIT(1) | X86_CR4_PAE | X86_CR4_PGE | RT_BIT(0):
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertMsgFailed(("Cannot happen! cr4=%#x fNXEPlusLMA=%d\n", cr4, fNXEPlusLMA));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Enables or disabled hardware virtualization extensions using native OS APIs.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns VBox status code.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @retval VINF_SUCCESS on success.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @retval VERR_NOT_SUPPORTED if not supported by the native OS.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param fEnable Whether to enable or disable.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico/** @todo document me */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicoSUPR0DECL(int) SUPR0QueryVTCaps(PSUPDRVSESSION pSession, uint32_t *pfCaps)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Input validation.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertReturn(SUP_IS_SESSION_VALID(pSession), VERR_INVALID_PARAMETER);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico uint32_t u32VendorEBX, u32VendorECX, u32VendorEDX, u32AMDFeatureEDX, u32AMDFeatureECX;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico ASMCpuId(0, &u32Dummy, &u32VendorEBX, &u32VendorECX, &u32VendorEDX);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico ASMCpuId(1, &u32Dummy, &u32Dummy, &u32FeaturesECX, &u32FeaturesEDX);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* Query AMD features. */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico ASMCpuId(0x80000001, &u32Dummy, &u32Dummy, &u32AMDFeatureECX, &u32AMDFeatureEDX);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Both the LOCK and VMXON bit must be set; otherwise VMXON will generate a #GP.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Once the lock bit is set, this MSR can no longer be modified.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico if ( (val & (MSR_IA32_FEATURE_CONTROL_VMXON|MSR_IA32_FEATURE_CONTROL_LOCK))
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico == (MSR_IA32_FEATURE_CONTROL_VMXON|MSR_IA32_FEATURE_CONTROL_LOCK) /* enabled and locked */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico || !(val & MSR_IA32_FEATURE_CONTROL_LOCK) /* not enabled, but not locked either */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico if (vtCaps.n.allowed1 & VMX_VMCS_CTRL_PROC_EXEC_USE_SECONDARY_EXEC_CTRL)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico vtCaps.u = ASMRdMsr(MSR_IA32_VMX_PROCBASED_CTLS2);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico if (vtCaps.n.allowed1 & VMX_VMCS_CTRL_PROC_EXEC2_EPT)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico if ( (u32AMDFeatureECX & X86_CPUID_AMD_FEATURE_ECX_SVM)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* Check if SVM is disabled */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* Query AMD features. */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico ASMCpuId(0x8000000A, &u32Dummy, &u32Dummy, &u32Dummy, &u32FeaturesEDX);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico if (u32FeaturesEDX & AMD_CPUID_SVM_FEATURE_EDX_NESTED_PAGING)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * (Re-)initializes the per-cpu structure prior to starting or resuming the GIP
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pGipCpu The per CPU structure for this CPU.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param u64NanoTS The current time.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic void supdrvGipReInitCpu(PSUPGIPCPU pGipCpu, uint64_t u64NanoTS)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pGipCpu->u64TSC = ASMReadTSC() - pGipCpu->u32UpdateIntervalTSC;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Set the current TSC and NanoTS value for the CPU.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param idCpu The CPU ID. Unused - we have to use the APIC ID.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pvUser1 Pointer to the ring-0 GIP mapping.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pvUser2 Pointer to the variable holding the current time.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic DECLCALLBACK(void) supdrvGipReInitCpuCallback(RTCPUID idCpu, void *pvUser1, void *pvUser2)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico PSUPGLOBALINFOPAGE pGip = (PSUPGLOBALINFOPAGE)pvUser1;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico supdrvGipReInitCpu(&pGip->aCPUs[iCpu], *(uint64_t *)pvUser2);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Maps the GIP into userspace and/or get the physical address of the GIP.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns IPRT status code.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pSession Session to which the GIP mapping should belong.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param ppGipR3 Where to store the address of the ring-3 mapping. (optional)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pHCPhysGip Where to store the physical address. (optional)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @remark There is no reference counting on the mapping, so one call to this function
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * count globally as one reference. One call to SUPR0GipUnmap() is will unmap GIP
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * and remove the session as a GIP user.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicoSUPR0DECL(int) SUPR0GipMap(PSUPDRVSESSION pSession, PRTR3PTR ppGipR3, PRTHCPHYS pHCPhysGip)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico LogFlow(("SUPR0GipMap: pSession=%p ppGipR3=%p pHCPhysGip=%p\n", pSession, ppGipR3, pHCPhysGip));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertReturn(SUP_IS_SESSION_VALID(pSession), VERR_INVALID_PARAMETER);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertPtrNullReturn(ppGipR3, VERR_INVALID_POINTER);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertPtrNullReturn(pHCPhysGip, VERR_INVALID_POINTER);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSemMutexRequest(pDevExt->mtxGip, RT_INDEFINITE_WAIT);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = RTR0MemObjMapUser(&pSession->GipMapObjR3, pDevExt->GipMemObj, (RTR3PTR)-1, 0,
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pGipR3 = RTR0MemObjAddressR3(pSession->GipMapObjR3);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Get physical address.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Reference globally.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico if (pGipR0->aCPUs[0].u32TransactionId != 2 /* not the first time */)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico ASMAtomicUoWriteU32(&pGipR0->aCPUs[i].u32TransactionId,
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico (pGipR0->aCPUs[i].u32TransactionId + GIP_UPDATEHZ_RECALC_FREQ * 2)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico ASMAtomicWriteU64(&pGipR0->u64NanoTSLastUpdateHz, 0);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico u64NanoTS = RTTimeSystemNanoTS() - pGipR0->u32UpdateIntervalNS;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTMpOnAll(supdrvGipReInitCpuCallback, pGipR0, &u64NanoTS);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = RTTimerStart(pDevExt->pGipTimer, 0); AssertRC(rc);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Write returns.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico OSDBGPRINT(("SUPR0GipMap: returns %d *pHCPhysGip=%lx pGipR3=%p\n", rc, (unsigned long)HCPhys, (void *)pGipR3));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico LogFlow(( "SUPR0GipMap: returns %d *pHCPhysGip=%lx pGipR3=%p\n", rc, (unsigned long)HCPhys, (void *)pGipR3));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Unmaps any user mapping of the GIP and terminates all GIP access
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * from this session.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns IPRT status code.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pSession Session to which the GIP mapping should belong.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicoSUPR0DECL(int) SUPR0GipUnmap(PSUPDRVSESSION pSession)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico OSDBGPRINT(("SUPR0GipUnmap: pSession=%p pGip=%p GipMapObjR3=%p\n",
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pSession->GipMapObjR3 != NIL_RTR0MEMOBJ ? RTR0MemObjAddress(pSession->GipMapObjR3) : NULL,
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico LogFlow(("SUPR0GipUnmap: pSession=%p\n", pSession));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertReturn(SUP_IS_SESSION_VALID(pSession), VERR_INVALID_PARAMETER);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSemMutexRequest(pDevExt->mtxGip, RT_INDEFINITE_WAIT);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Unmap anything?
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = RTR0MemObjFree(pSession->GipMapObjR3, false);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Dereference global GIP.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico LogFlow(("SUPR0GipUnmap: Suspends GIP updating\n"));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = RTTimerStop(pDevExt->pGipTimer); AssertRC(rc); rc = VINF_SUCCESS;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Gets the GIP pointer.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns Pointer to the GIP or NULL.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Register a component factory with the support driver.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * This is currently restricted to kernel sessions only.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns VBox status code.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @retval VINF_SUCCESS on success.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @retval VERR_NO_MEMORY if we're out of memory.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @retval VERR_ALREADY_EXISTS if the factory has already been registered.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @retval VERR_ACCESS_DENIED if it isn't a kernel session.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @retval VERR_INVALID_PARAMETER on invalid parameter.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @retval VERR_INVALID_POINTER on invalid pointer parameter.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pSession The SUPDRV session (must be a ring-0 session).
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pFactory Pointer to the component factory registration structure.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @remarks This interface is also available via SUPR0IdcComponentRegisterFactory.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicoSUPR0DECL(int) SUPR0ComponentRegisterFactory(PSUPDRVSESSION pSession, PCSUPDRVFACTORY pFactory)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico const char *psz;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Validate parameters.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertReturn(SUP_IS_SESSION_VALID(pSession), VERR_INVALID_PARAMETER);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertReturn(pSession->R0Process == NIL_RTR0PROCESS, VERR_ACCESS_DENIED);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertPtrReturn(pFactory->pfnQueryFactoryInterface, VERR_INVALID_POINTER);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico psz = RTStrEnd(pFactory->szName, sizeof(pFactory->szName));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Allocate and initialize a new registration structure.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pNewReg = (PSUPDRVFACTORYREG)RTMemAlloc(sizeof(SUPDRVFACTORYREG));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Add it to the tail of the list after checking for prior registration.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = RTSemFastMutexRequest(pSession->pDevExt->mtxComponentFactory);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico PSUPDRVFACTORYREG pCur = pSession->pDevExt->pComponentFactoryHead;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pSession->pDevExt->pComponentFactoryHead = pNewReg;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSemFastMutexRelease(pSession->pDevExt->mtxComponentFactory);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Deregister a component factory.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns VBox status code.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @retval VINF_SUCCESS on success.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @retval VERR_NOT_FOUND if the factory wasn't registered.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @retval VERR_ACCESS_DENIED if it isn't a kernel session.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @retval VERR_INVALID_PARAMETER on invalid parameter.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @retval VERR_INVALID_POINTER on invalid pointer parameter.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pSession The SUPDRV session (must be a ring-0 session).
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pFactory Pointer to the component factory registration structure
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * previously passed SUPR0ComponentRegisterFactory().
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @remarks This interface is also available via SUPR0IdcComponentDeregisterFactory.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicoSUPR0DECL(int) SUPR0ComponentDeregisterFactory(PSUPDRVSESSION pSession, PCSUPDRVFACTORY pFactory)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Validate parameters.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertReturn(SUP_IS_SESSION_VALID(pSession), VERR_INVALID_PARAMETER);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertReturn(pSession->R0Process == NIL_RTR0PROCESS, VERR_ACCESS_DENIED);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Take the lock and look for the registration record.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = RTSemFastMutexRequest(pSession->pDevExt->mtxComponentFactory);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico PSUPDRVFACTORYREG pCur = pSession->pDevExt->pComponentFactoryHead;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pSession->pDevExt->pComponentFactoryHead = pCur->pNext;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSemFastMutexRelease(pSession->pDevExt->mtxComponentFactory);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Queries a component factory.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns VBox status code.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @retval VERR_INVALID_PARAMETER on invalid parameter.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @retval VERR_INVALID_POINTER on invalid pointer parameter.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @retval VERR_SUPDRV_COMPONENT_NOT_FOUND if the component factory wasn't found.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @retval VERR_SUPDRV_INTERFACE_NOT_SUPPORTED if the interface wasn't supported.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pSession The SUPDRV session.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pszName The name of the component factory.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pszInterfaceUuid The UUID of the factory interface (stringified).
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param ppvFactoryIf Where to store the factory interface.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicoSUPR0DECL(int) SUPR0ComponentQueryFactory(PSUPDRVSESSION pSession, const char *pszName, const char *pszInterfaceUuid, void **ppvFactoryIf)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico const char *pszEnd;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Validate parameters.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertReturn(SUP_IS_SESSION_VALID(pSession), VERR_INVALID_PARAMETER);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pszEnd = RTStrEnd(pszName, RT_SIZEOFMEMB(SUPDRVFACTORY, szName));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertPtrReturn(pszInterfaceUuid, VERR_INVALID_POINTER);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pszEnd = RTStrEnd(pszInterfaceUuid, RTUUID_STR_LENGTH);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertPtrReturn(ppvFactoryIf, VERR_INVALID_POINTER);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Take the lock and try all factories by this name.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = RTSemFastMutexRequest(pSession->pDevExt->mtxComponentFactory);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico PSUPDRVFACTORYREG pCur = pSession->pDevExt->pComponentFactoryHead;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico && !memcmp(pCur->pFactory->szName, pszName, cchName))
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico void *pvFactory = pCur->pFactory->pfnQueryFactoryInterface(pCur->pFactory, pSession, pszInterfaceUuid);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSemFastMutexRelease(pSession->pDevExt->mtxComponentFactory);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Adds a memory object to the session.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns IPRT status code.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pMem Memory tracking structure containing the
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * information to track.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pSession The session.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic int supdrvMemAdd(PSUPDRVMEMREF pMem, PSUPDRVSESSION pSession)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSPINLOCKTMP SpinlockTmp = RTSPINLOCKTMP_INITIALIZER;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Find free entry and record the allocation.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSpinlockAcquire(pSession->Spinlock, &SpinlockTmp);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico for (pBundle = &pSession->Bundle; pBundle; pBundle = pBundle->pNext)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSpinlockRelease(pSession->Spinlock, &SpinlockTmp);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertFailed(); /* !!this can't be happening!!! */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSpinlockRelease(pSession->Spinlock, &SpinlockTmp);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Need to allocate a new bundle.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Insert into the last entry in the bundle.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pBundle = (PSUPDRVBUNDLE)RTMemAllocZ(sizeof(*pBundle));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* take last entry. */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pBundle->aMem[RT_ELEMENTS(pBundle->aMem) - 1] = *pMem;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* insert into list. */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSpinlockAcquire(pSession->Spinlock, &SpinlockTmp);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSpinlockRelease(pSession->Spinlock, &SpinlockTmp);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Releases a memory object referenced by pointer and type.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns IPRT status code.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pSession Session data.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param uPtr Pointer to memory. This is matched against both the R0 and R3 addresses.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param eType Memory type.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic int supdrvMemRelease(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr, SUPDRVMEMREFTYPE eType)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSPINLOCKTMP SpinlockTmp = RTSPINLOCKTMP_INITIALIZER;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Validate input.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Search for the address.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSpinlockAcquire(pSession->Spinlock, &SpinlockTmp);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico for (pBundle = &pSession->Bundle; pBundle; pBundle = pBundle->pNext)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico && ( (RTHCUINTPTR)RTR0MemObjAddress(pBundle->aMem[i].MemObj) == uPtr
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico && RTR0MemObjAddressR3(pBundle->aMem[i].MapObjR3) == uPtr))
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* Make a copy of it and release it outside the spinlock. */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSpinlockRelease(pSession->Spinlock, &SpinlockTmp);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertRC(rc); /** @todo figure out how to handle this. */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico int rc = RTR0MemObjFree(Mem.MemObj, true /* fFreeMappings */);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertRC(rc); /** @todo figure out how to handle this. */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSpinlockRelease(pSession->Spinlock, &SpinlockTmp);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico Log(("Failed to find %p!!! (eType=%d)\n", (void *)uPtr, eType));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Opens an image. If it's the first time it's opened the call must upload
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * the bits using the supdrvIOCtl_LdrLoad() / SUPDRV_IOCTL_LDR_LOAD function.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * This is the 1st step of the loading.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns IPRT status code.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pDevExt Device globals.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pSession Session data.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pReq The open request.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic int supdrvIOCtl_LdrOpen(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPLDROPEN pReq)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico size_t cchName = strlen(pReq->u.In.szName); /* (caller checked < 32). */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico LogFlow(("supdrvIOCtl_LdrOpen: szName=%s cbImageWithTabs=%d\n", pReq->u.In.szName, pReq->u.In.cbImageWithTabs));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Check if we got an instance of the image already.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico for (pImage = pDevExt->pLdrImages; pImage; pImage = pImage->pNext)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico && !memcmp(pImage->szName, pReq->u.In.szName, cchName))
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /** @todo check cbImageBits and cbImageWithTabs here, if they differs that indicates that the images are different. */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->u.Out.fNeedsLoading = pImage->uState == SUP_IOCTL_LDR_OPEN;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* (not found - add it!) */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Allocate memory.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pv = RTMemAlloc(RT_OFFSETOF(SUPDRVLDRIMAGE, szName[cchName + 1]));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico Log(("supdrvIOCtl_LdrOpen: RTMemAlloc() failed\n"));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Setup and link in the LDR stuff.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pImage->cbImageWithTabs = pReq->u.In.cbImageWithTabs;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico memcpy(pImage->szName, pReq->u.In.szName, cchName + 1);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Try load it using the native loader, if that isn't supported, fall back
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * on the older method.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = supdrvOSLdrOpen(pDevExt, pImage, pReq->u.In.szFilename);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pImage->pvImageAlloc = RTMemExecAlloc(pImage->cbImageBits + 31);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pImage->pvImage = RT_ALIGN_P(pImage->pvImageAlloc, 32);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = pImage->pvImageAlloc ? VINF_SUCCESS : VERR_NO_EXEC_MEMORY;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico Log(("supdrvIOCtl_LdrOpen(%s): failed - %Rrc\n", pReq->u.In.szName, rc));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico Assert(VALID_PTR(pImage->pvImage) || RT_FAILURE(rc));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico SUPR0Printf("VBoxDrv: windbg> .reload /f %s=%#p\n", pImage->szName, pImage->pvImage);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Worker that validates a pointer to an image entrypoint.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns IPRT status code.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pDevExt The device globals.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pImage The loader image.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pv The pointer into the image.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param fMayBeNull Whether it may be NULL.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pszWhat What is this entrypoint? (for logging)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pbImageBits The image bits prepared by ring-3.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @remarks Will leave the lock on failure.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic int supdrvLdrValidatePointer(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, void *pv,
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico bool fMayBeNull, const uint8_t *pbImageBits, const char *pszWhat)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico if ((uintptr_t)pv - (uintptr_t)pImage->pvImage >= pImage->cbImageBits)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico Log(("Out of range (%p LB %#x): %s=%p\n", pImage->pvImage, pImage->cbImageBits, pszWhat, pv));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico int rc = supdrvOSLdrValidatePointer(pDevExt, pImage, pv, pbImageBits);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico Log(("Bad entry point address: %s=%p (rc=%Rrc)\n", pszWhat, pv, rc));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Loads the image bits.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * This is the 2nd step of the loading.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns IPRT status code.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pDevExt Device globals.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pSession Session data.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pReq The request.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic int supdrvIOCtl_LdrLoad(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPLDRLOAD pReq)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico LogFlow(("supdrvIOCtl_LdrLoad: pvImageBase=%p cbImageWithBits=%d\n", pReq->u.In.pvImageBase, pReq->u.In.cbImageWithTabs));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Find the ldr image.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico while (pUsage && pUsage->pImage->pvImage != pReq->u.In.pvImageBase)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico Log(("SUP_IOCTL_LDR_LOAD: couldn't find image!\n"));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Validate input.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico if ( pImage->cbImageWithTabs != pReq->u.In.cbImageWithTabs
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico Log(("SUP_IOCTL_LDR_LOAD: image size mismatch!! %d(prep) != %d(load) or %d != %d\n",
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pImage->cbImageWithTabs, pReq->u.In.cbImageWithTabs, pImage->cbImageBits, pReq->u.In.cbImageBits));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertMsgFailed(("SUP_IOCTL_LDR_LOAD: invalid image state %d (%#x)!\n", uState, uState));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = supdrvLdrValidatePointer( pDevExt, pImage, pReq->u.In.EP.VMMR0.pvVMMR0, false, pReq->u.In.abImage, "pvVMMR0");
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = supdrvLdrValidatePointer(pDevExt, pImage, pReq->u.In.EP.VMMR0.pvVMMR0EntryInt, false, pReq->u.In.abImage, "pvVMMR0EntryInt");
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = supdrvLdrValidatePointer(pDevExt, pImage, pReq->u.In.EP.VMMR0.pvVMMR0EntryFast, false, pReq->u.In.abImage, "pvVMMR0EntryFast");
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = supdrvLdrValidatePointer(pDevExt, pImage, pReq->u.In.EP.VMMR0.pvVMMR0EntryEx, false, pReq->u.In.abImage, "pvVMMR0EntryEx");
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = supdrvLdrValidatePointer(pDevExt, pImage, pReq->u.In.EP.Service.pfnServiceReq, false, pReq->u.In.abImage, "pfnServiceReq");
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico if ( pReq->u.In.EP.Service.apvReserved[0] != NIL_RTR0PTR
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico || pReq->u.In.EP.Service.apvReserved[1] != NIL_RTR0PTR
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico || pReq->u.In.EP.Service.apvReserved[2] != NIL_RTR0PTR)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico Log(("Out of range (%p LB %#x): apvReserved={%p,%p,%p} MBZ!\n",
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico Log(("Invalid eEPType=%d\n", pReq->u.In.eEPType));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = supdrvLdrValidatePointer(pDevExt, pImage, pReq->u.In.pfnModuleInit, true, pReq->u.In.abImage, "pfnModuleInit");
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = supdrvLdrValidatePointer(pDevExt, pImage, pReq->u.In.pfnModuleTerm, true, pReq->u.In.abImage, "pfnModuleTerm");
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Allocate and copy the tables.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * (No need to do try/except as this is a buffered request.)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pImage->pachStrTab = (char *)RTMemAlloc(pImage->cbStrTab);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico memcpy(pImage->pachStrTab, &pReq->u.In.abImage[pReq->u.In.offStrTab], pImage->cbStrTab);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico size_t cbSymbols = pImage->cSymbols * sizeof(SUPLDRSYM);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pImage->paSymbols = (PSUPLDRSYM)RTMemAlloc(cbSymbols);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico memcpy(pImage->paSymbols, &pReq->u.In.abImage[pReq->u.In.offSymbols], cbSymbols);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Copy the bits / complete native loading.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = supdrvOSLdrLoad(pDevExt, pImage, pReq->u.In.abImage);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico memcpy(pImage->pvImage, &pReq->u.In.abImage[0], pImage->cbImageBits);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Update any entry points.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = supdrvLdrSetVMMR0EPs(pDevExt, pReq->u.In.EP.VMMR0.pvVMMR0, pReq->u.In.EP.VMMR0.pvVMMR0EntryInt,
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->u.In.EP.VMMR0.pvVMMR0EntryFast, pReq->u.In.EP.VMMR0.pvVMMR0EntryEx);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pImage->pfnServiceReqHandler = pReq->u.In.EP.Service.pfnServiceReq;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * On success call the module initialization.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico LogFlow(("supdrvIOCtl_LdrLoad: pfnModuleInit=%p\n", pImage->pfnModuleInit));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico Log(("supdrvIOCtl_LdrLoad: calling pfnModuleInit=%p\n", pImage->pfnModuleInit));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Frees a previously loaded (prep'ed) image.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns IPRT status code.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pDevExt Device globals.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pSession Session data.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pReq The request.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic int supdrvIOCtl_LdrFree(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPLDRFREE pReq)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico LogFlow(("supdrvIOCtl_LdrFree: pvImageBase=%p\n", pReq->u.In.pvImageBase));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Find the ldr image.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico while (pUsage && pUsage->pImage->pvImage != pReq->u.In.pvImageBase)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico Log(("SUP_IOCTL_LDR_FREE: couldn't find image!\n"));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Check if we can remove anything.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Check if there are any objects with destructors in the image, if
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * so leave it for the session cleanup routine so we get a chance to
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * clean things up in the right order and not leave them all dangling.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSPINLOCKTMP SpinlockTmp = RTSPINLOCKTMP_INITIALIZER;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSpinlockAcquire(pDevExt->Spinlock, &SpinlockTmp);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico for (pObj = pDevExt->pObjs; pObj; pObj = pObj->pNext)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico if (RT_UNLIKELY((uintptr_t)pObj->pfnDestructor - (uintptr_t)pImage->pvImage < pImage->cbImageBits))
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico for (pGenUsage = pSession->pUsage; pGenUsage; pGenUsage = pGenUsage->pNext)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico if (RT_UNLIKELY((uintptr_t)pGenUsage->pObj->pfnDestructor - (uintptr_t)pImage->pvImage < pImage->cbImageBits))
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSpinlockRelease(pDevExt->Spinlock, &SpinlockTmp);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* unlink it */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* free it */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Dereference the image.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico Log(("supdrvIOCtl_LdrFree: Dangling objects in %p/%s!\n", pImage->pvImage, pImage->szName));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = VINF_SUCCESS; /** @todo BRANCH-2.1: remove this after branching. */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Dereference both image and usage.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Gets the address of a symbol in an open image.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns IPRT status code.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pDevExt Device globals.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pSession Session data.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pReq The request buffer.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic int supdrvIOCtl_LdrGetSymbol(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPLDRGETSYMBOL pReq)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico const size_t cbSymbol = strlen(pReq->u.In.szSymbol) + 1;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico Log3(("supdrvIOCtl_LdrGetSymbol: pvImageBase=%p szSymbol=\"%s\"\n", pReq->u.In.pvImageBase, pReq->u.In.szSymbol));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Find the ldr image.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico while (pUsage && pUsage->pImage->pvImage != pReq->u.In.pvImageBase)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico Log(("SUP_IOCTL_LDR_GET_SYMBOL: couldn't find image!\n"));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico Log(("SUP_IOCTL_LDR_GET_SYMBOL: invalid image state %d (%#x)!\n", uState, uState)); NOREF(uState);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Search the symbol strings.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico if ( paSyms[i].offSymbol < pImage->cbImageBits /* paranoia */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico && paSyms[i].offName + cbSymbol <= pImage->cbStrTab
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico && !memcmp(pchStrings + paSyms[i].offName, pReq->u.In.szSymbol, cbSymbol))
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pvSymbol = (uint8_t *)pImage->pvImage + paSyms[i].offSymbol;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Gets the address of a symbol in an open image or the support driver.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns VINF_SUCCESS on success.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pDevExt Device globals.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pSession Session data.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pReq The request buffer.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic int supdrvIDC_LdrGetSymbol(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPDRVIDCREQGETSYM pReq)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico char const *pszEnd;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Input validation.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico Log3(("supdrvIDC_LdrGetSymbol: pszModule=%p:{%s} pszSymbol=%p:{%s}\n", pszModule, pszModule, pszSymbol, pszSymbol));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Search the support driver export table.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Find the loader image.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico for (pImage = pDevExt->pLdrImages; pImage; pImage = pImage->pNext)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico if (pImage && pImage->uState == SUP_IOCTL_LDR_LOAD)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Search the symbol strings.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico if ( paSyms[i].offSymbol < pImage->cbImageBits /* paranoia */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico && paSyms[i].offName + cbSymbol <= pImage->cbStrTab
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico && !memcmp(pchStrings + paSyms[i].offName, pszSymbol, cbSymbol))
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Found it! Calc the symbol address and add a reference to the module.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->u.Out.pfnSymbol = (PFNRT)((uint8_t *)pImage->pvImage + paSyms[i].offSymbol);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = pImage ? VERR_WRONG_ORDER : VERR_MODULE_NOT_FOUND;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Updates the VMMR0 entry point pointers.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns IPRT status code.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pDevExt Device globals.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pSession Session data.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pVMMR0 VMMR0 image handle.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pvVMMR0EntryInt VMMR0EntryInt address.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pvVMMR0EntryFast VMMR0EntryFast address.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pvVMMR0EntryEx VMMR0EntryEx address.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @remark Caller must own the loader mutex.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic int supdrvLdrSetVMMR0EPs(PSUPDRVDEVEXT pDevExt, void *pvVMMR0, void *pvVMMR0EntryInt, void *pvVMMR0EntryFast, void *pvVMMR0EntryEx)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico LogFlow(("supdrvLdrSetR0EP pvVMMR0=%p pvVMMR0EntryInt=%p\n", pvVMMR0, pvVMMR0EntryInt));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Check if not yet set.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Return failure or success depending on whether the values match or not.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico || (void *)pDevExt->pfnVMMR0EntryInt != pvVMMR0EntryInt
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico || (void *)pDevExt->pfnVMMR0EntryFast != pvVMMR0EntryFast
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico || (void *)pDevExt->pfnVMMR0EntryEx != pvVMMR0EntryEx)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertMsgFailed(("SUP_IOCTL_LDR_SETR0EP: Already set pointing to a different module!\n"));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Unsets the VMMR0 entry point installed by supdrvLdrSetR0EP.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pDevExt Device globals.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic void supdrvLdrUnsetVMMR0EPs(PSUPDRVDEVEXT pDevExt)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Adds a usage reference in the specified session of an image.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Called while owning the loader semaphore.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns VINF_SUCCESS on success and VERR_NO_MEMORY on failure.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pSession Session in question.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pImage Image which the session is using.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic int supdrvLdrAddUsage(PSUPDRVSESSION pSession, PSUPDRVLDRIMAGE pImage)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico LogFlow(("supdrvLdrAddUsage: pImage=%p\n", pImage));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Referenced it already?
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Allocate new usage record.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pUsage = (PSUPDRVLDRUSAGE)RTMemAlloc(sizeof(*pUsage));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertReturn(pUsage, /*VERR_NO_MEMORY*/ VERR_INTERNAL_ERROR_5);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Frees a load image.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pDevExt Pointer to device extension.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pImage Pointer to the image we're gonna free.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * This image must exit!
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @remark The caller MUST own SUPDRVDEVEXT::mtxLdr!
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic void supdrvLdrFree(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* find it - arg. should've used doubly linked list. */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* unlink */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* check if this is VMMR0.r0 unset its entry point pointers. */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* check for objects with destructors in this image. (Shouldn't happen.) */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico unsigned cObjs = 0;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSPINLOCKTMP SpinlockTmp = RTSPINLOCKTMP_INITIALIZER;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSpinlockAcquire(pDevExt->Spinlock, &SpinlockTmp);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico for (pObj = pDevExt->pObjs; pObj; pObj = pObj->pNext)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico if (RT_UNLIKELY((uintptr_t)pObj->pfnDestructor - (uintptr_t)pImage->pvImage < pImage->cbImageBits))
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTSpinlockRelease(pDevExt->Spinlock, &SpinlockTmp);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico OSDBGPRINT(("supdrvLdrFree: Image '%s' has %d dangling objects!\n", pImage->szName, cObjs));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* call termination function if fully loaded. */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico LogFlow(("supdrvIOCtl_LdrLoad: calling pfnModuleTerm=%p\n", pImage->pfnModuleTerm));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* do native unload if appropriate. */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* free the image */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTMemExecFree(pImage->pvImageAlloc, pImage->cbImageBits + 31);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Acquires the loader lock.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns IPRT status code.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pDevExt The device extension.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicoDECLINLINE(int) supdrvLdrLock(PSUPDRVDEVEXT pDevExt)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico int rc = RTSemMutexRequest(pDevExt->mtxLdr, RT_INDEFINITE_WAIT);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Releases the loader lock.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns IPRT status code.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pDevExt The device extension.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicoDECLINLINE(int) supdrvLdrUnlock(PSUPDRVDEVEXT pDevExt)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Implements the service call request.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns VBox status code.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pDevExt The device extension.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pSession The calling session.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pReq The request packet, valid.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic int supdrvIOCtl_CallServiceModule(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPCALLSERVICE pReq)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Find the module first in the module referenced by the calling session.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico PFNSUPR0SERVICEREQHANDLER pfnServiceReqHandler = NULL;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico for (pUsage = pSession->pLdrUsage; pUsage; pUsage = pUsage->pNext)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico && !strcmp(pUsage->pImage->szName, pReq->u.In.szName))
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pfnServiceReqHandler = pUsage->pImage->pfnServiceReqHandler;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico if (pReq->Hdr.cbIn == SUP_IOCTL_CALL_SERVICE_SIZE(0))
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = pfnServiceReqHandler(pSession, pReq->u.In.uOperation, pReq->u.In.u64Arg, NULL);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = pfnServiceReqHandler(pSession, pReq->u.In.uOperation, pReq->u.In.u64Arg, (PSUPR0SERVICEREQHDR)&pReq->abReqPkt[0]);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* log it */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico Log(("SUP_IOCTL_CALL_SERVICE: rc=%Rrc op=%u out=%u arg=%RX64 p/t=%RTproc/%RTthrd\n",
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc, pReq->u.In.uOperation, pReq->Hdr.cbOut, pReq->u.In.u64Arg, RTProcSelf(), RTThreadNativeSelf()));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico Log4(("SUP_IOCTL_CALL_SERVICE: rc=%Rrc op=%u out=%u arg=%RX64 p/t=%RTproc/%RTthrd\n",
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc, pReq->u.In.uOperation, pReq->Hdr.cbOut, pReq->u.In.u64Arg, RTProcSelf(), RTThreadNativeSelf()));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico#else /* RT_OS_WINDOWS && !DEBUG */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico#endif /* RT_OS_WINDOWS && !DEBUG */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Implements the logger settings request.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns VBox status code.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pDevExt The device extension.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pSession The caller's session.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pReq The request.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic int supdrvIOCtl_LoggerSettings(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPLOGGERSETTINGS pReq)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico const char *pszGroup = &pReq->u.In.szStrings[pReq->u.In.offGroups];
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico const char *pszFlags = &pReq->u.In.szStrings[pReq->u.In.offFlags];
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico const char *pszDest = &pReq->u.In.szStrings[pReq->u.In.offDestination];
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Some further validation.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico if (pReq->u.In.fWhich == SUPLOGGERSETTINGS_WHICH_RELEASE)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Get the logger.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Do the job.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico static const char * const s_apszGroups[] = VBOX_LOGGROUP_NAMES;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico 0 /* fFlags */,
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pReq->u.In.fWhich == SUPLOGGERSETTINGS_WHICH_DEBUG
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico ? "VBOX_LOG"
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico : "VBOX_RELEASE_LOG",
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Creates the GIP.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns VBox status code.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pDevExt Instance data. GIP stuff may be updated.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* assert order */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico Assert(pDevExt->u32SystemTimerGranularityGrant == 0);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Allocate a suitable page with a default kernel mapping.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = RTR0MemObjAllocLow(&pDevExt->GipMemObj, PAGE_SIZE, false);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico OSDBGPRINT(("supdrvGipCreate: failed to allocate the GIP page. rc=%d\n", rc));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pGip = (PSUPGLOBALINFOPAGE)RTR0MemObjAddress(pDevExt->GipMemObj); AssertPtr(pGip);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico HCPhysGip = RTR0MemObjGetPagePhysAddr(pDevExt->GipMemObj, 0); Assert(HCPhysGip != NIL_RTHCPHYS);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico#if 0 /** @todo Disabled this as we didn't used to do it before and causes unnecessary stress on laptops.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * It only applies to Windows and should probably revisited later, if possible made part of the
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * timer code (return min granularity in RTTimerGetSystemGranularity and set it in RTTimerStart). */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Try bump up the system timer resolution.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * The more interrupts the better...
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico if ( RT_SUCCESS(RTTimerRequestSystemGranularity( 488281 /* 2048 HZ */, &u32SystemResolution))
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico || RT_SUCCESS(RTTimerRequestSystemGranularity( 500000 /* 2000 HZ */, &u32SystemResolution))
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico || RT_SUCCESS(RTTimerRequestSystemGranularity( 976563 /* 1024 HZ */, &u32SystemResolution))
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico || RT_SUCCESS(RTTimerRequestSystemGranularity( 1000000 /* 1000 HZ */, &u32SystemResolution))
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico || RT_SUCCESS(RTTimerRequestSystemGranularity( 1953125 /* 512 HZ */, &u32SystemResolution))
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico || RT_SUCCESS(RTTimerRequestSystemGranularity( 2000000 /* 500 HZ */, &u32SystemResolution))
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico || RT_SUCCESS(RTTimerRequestSystemGranularity( 3906250 /* 256 HZ */, &u32SystemResolution))
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico || RT_SUCCESS(RTTimerRequestSystemGranularity( 4000000 /* 250 HZ */, &u32SystemResolution))
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico || RT_SUCCESS(RTTimerRequestSystemGranularity( 7812500 /* 128 HZ */, &u32SystemResolution))
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico || RT_SUCCESS(RTTimerRequestSystemGranularity(10000000 /* 100 HZ */, &u32SystemResolution))
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico || RT_SUCCESS(RTTimerRequestSystemGranularity(15625000 /* 64 HZ */, &u32SystemResolution))
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico || RT_SUCCESS(RTTimerRequestSystemGranularity(31250000 /* 32 HZ */, &u32SystemResolution))
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico Assert(RTTimerGetSystemGranularity() <= u32SystemResolution);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pDevExt->u32SystemTimerGranularityGrant = u32SystemResolution;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Find a reasonable update interval and initialize the structure.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico u32Interval = u32SystemResolution = RTTimerGetSystemGranularity();
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico supdrvGipInit(pDevExt, pGip, HCPhysGip, RTTimeSystemNanoTS(), 1000000000 / u32Interval /*=Hz*/);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Create the timer.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * If CPU_ALL isn't supported we'll have to fall back to synchronous mode.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = RTTimerCreateEx(&pDevExt->pGipTimer, u32Interval, RTTIMER_FLAGS_CPU_ALL, supdrvGipAsyncTimer, pDevExt);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico OSDBGPRINT(("supdrvGipCreate: omni timer not supported, falling back to synchronous mode\n"));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = RTTimerCreateEx(&pDevExt->pGipTimer, u32Interval, 0, supdrvGipSyncTimer, pDevExt);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = RTMpNotificationRegister(supdrvGipMpEvent, pDevExt);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * We're good.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico Log(("supdrvGipCreate: %ld ns interval.\n", (long)u32Interval));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico OSDBGPRINT(("supdrvGipCreate: failed register MP event notfication. rc=%d\n", rc));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico OSDBGPRINT(("supdrvGipCreate: failed create GIP timer at %ld ns interval. rc=%d\n", (long)u32Interval, rc));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Terminates the GIP.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pDevExt Instance data. GIP stuff may be updated.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic void supdrvGipDestroy(PSUPDRVDEVEXT pDevExt)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico OSDBGPRINT(("supdrvGipDestroy: pDevExt=%p pGip=%p pGipTimer=%p GipMemObj=%p\n", pDevExt,
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pDevExt->GipMemObj != NIL_RTR0MEMOBJ ? RTR0MemObjAddress(pDevExt->GipMemObj) : NULL,
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Invalid the GIP data.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Destroy the timer and free the GIP memory object.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = RTTimerDestroy(pDevExt->pGipTimer); AssertRC(rc);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = RTR0MemObjFree(pDevExt->GipMemObj, true /* free mappings */); AssertRC(rc);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Finally, release the system timer resolution request if one succeeded.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = RTTimerReleaseSystemGranularity(pDevExt->u32SystemTimerGranularityGrant); AssertRC(rc);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Timer callback function sync GIP mode.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pTimer The timer.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pvUser The device extension.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic DECLCALLBACK(void) supdrvGipSyncTimer(PRTTIMER pTimer, void *pvUser, uint64_t iTick)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTCCUINTREG fOldFlags = ASMIntDisableFlags(); /* No interruptions please (real problem on S10). */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico supdrvGipUpdate(pDevExt->pGip, NanoTS, u64TSC, iTick);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Timer callback function for async GIP mode.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pTimer The timer.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pvUser The device extension.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic DECLCALLBACK(void) supdrvGipAsyncTimer(PRTTIMER pTimer, void *pvUser, uint64_t iTick)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico RTCCUINTREG fOldFlags = ASMIntDisableFlags(); /* No interruptions please (real problem on S10). */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /** @todo reset the transaction number and whatnot when iTick == 1. */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico supdrvGipUpdate(pDevExt->pGip, NanoTS, u64TSC, iTick);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico supdrvGipUpdatePerCpu(pDevExt->pGip, NanoTS, u64TSC, ASMGetApicId(), iTick);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Multiprocessor event notification callback.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * This is used to make sue that the GIP master gets passed on to
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * another CPU.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param enmEvent The event.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param idCpu The cpu it applies to.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pvUser Pointer to the device extension.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic DECLCALLBACK(void) supdrvGipMpEvent(RTMPEVENT enmEvent, RTCPUID idCpu, void *pvUser)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico ASMAtomicReadSize(&pDevExt->idGipMaster, &idGipMaster);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Find a new GIP master.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico for (i = 0; i < RTCPUSET_MAX_CPUS; i++)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico Log(("supdrvGipMpEvent: Gip master %#lx -> %#lx\n", (long)idGipMaster, (long)idNewGipMaster));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico ASMAtomicCmpXchgSize(&pDevExt->idGipMaster, idNewGipMaster, idGipMaster, fIgnored);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Callback used by supdrvDetermineAsyncTSC to read the TSC on a CPU.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param idCpu Ignored.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pvUser1 Where to put the TSC.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pvUser2 Ignored.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic DECLCALLBACK(void) supdrvDetermineAsyncTscWorker(RTCPUID idCpu, void *pvUser1, void *pvUser2)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico ASMAtomicWriteU64((uint64_t volatile *)pvUser1, ASMReadTSC());
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Determine if Async GIP mode is required because of TSC drift.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * When using the default/normal timer code it is essential that the time stamp counter
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * (TSC) runs never backwards, that is, a read operation to the counter should return
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * a bigger value than any previous read operation. This is guaranteed by the latest
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * AMD CPUs and by newer Intel CPUs which never enter the C2 state (P4). In any other
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * case we have to choose the asynchronous timer mode.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param poffMin Pointer to the determined difference between different cores.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @return false if the time stamp counters appear to be synchron, true otherwise.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic bool supdrvDetermineAsyncTsc(uint64_t *poffMin)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Just iterate all the cpus 8 times and make sure that the TSC is
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * ever increasing. We don't bother taking TSC rollover into account.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico bool fAsync = false;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico while (cLoops-- > 0)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico rc = RTMpOnSpecific(RTMpCpuIdFromSetIndex(iCpu), supdrvDetermineAsyncTscWorker, &CurTsc, NULL);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico Log(("supdrvDetermineAsyncTsc: iCpu=%d cLoops=%d CurTsc=%llx PrevTsc=%llx\n",
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* Gather statistics (except the first time). */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertMsg(rc == VERR_CPU_NOT_FOUND || rc == VERR_CPU_OFFLINE, ("%d\n", rc));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* broke out of the loop. */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico *poffMin = offMin; /* Almost RTMpOnSpecific profiling. */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico Log(("supdrvDetermineAsyncTsc: returns %d; iEndCpu=%d rc=%d offMin=%llx offMax=%llx\n",
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico#if !defined(RT_OS_SOLARIS) && !defined(RT_OS_OS2) && !defined(RT_OS_WINDOWS)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico OSDBGPRINT(("vboxdrv: fAsync=%d offMin=%#lx offMax=%#lx\n", fAsync, (long)offMin, (long)offMax));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Determin the GIP TSC mode.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @returns The most suitable TSC mode.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pDevExt Pointer to the device instance data.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic SUPGIPMODE supdrvGipDeterminTscMode(PSUPDRVDEVEXT pDevExt)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * On SMP we're faced with two problems:
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * (1) There might be a skew between the CPU, so that cpu0
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * returns a TSC that is sligtly different from cpu1.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * (2) Power management (and other things) may cause the TSC
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * to run at a non-constant speed, and cause the speed
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * to be different on the cpus. This will result in (1).
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * So, on SMP systems we'll have to select the ASYNC update method
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * if there are symphoms of these problems.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* Permit the user and/or the OS specfic bits to force async mode. */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* Try check for current differences between the cpus. */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico if (supdrvDetermineAsyncTsc(&u64DiffCoresIgnored))
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * If the CPU supports power management and is an AMD one we
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * won't trust it unless it has the TscInvariant bit is set.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* Check for "AuthenticAMD" */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* Check for APM support and that TscInvariant is cleared. */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico && (uEDX & 0x3e)) /* STC|TM|THERMTRIP|VID|FID. Ignore TS. */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Initializes the GIP data.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pDevExt Pointer to the device instance data.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pGip Pointer to the read-write kernel mapping of the GIP.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param HCPhys The physical address of the GIP.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param u64NanoTS The current nanosecond timestamp.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param uUpdateHz The update freqence.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic void supdrvGipInit(PSUPDRVDEVEXT pDevExt, PSUPGLOBALINFOPAGE pGip, RTHCPHYS HCPhys, uint64_t u64NanoTS, unsigned uUpdateHz)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico OSDBGPRINT(("supdrvGipInit: pGip=%p HCPhys=%lx u64NanoTS=%llu uUpdateHz=%d\n", pGip, (long)HCPhys, u64NanoTS, uUpdateHz));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico LogFlow(("supdrvGipInit: pGip=%p HCPhys=%lx u64NanoTS=%llu uUpdateHz=%d\n", pGip, (long)HCPhys, u64NanoTS, uUpdateHz));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Initialize the structure.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pGip->u32Mode = supdrvGipDeterminTscMode(pDevExt);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pGip->u32UpdateIntervalNS = 1000000000 / uUpdateHz;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * We don't know the following values until we've executed updates.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * So, we'll just pretend it's a 4 GHz CPU and adjust the history it on
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * the 2nd timer callout.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico pGip->aCPUs[i].u64CpuHz = _4G + 1; /* tstGIP-2 depends on this. */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Link it to the device extension.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Invalidates the GIP data upon termination.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pGip Pointer to the read-write kernel mapping of the GIP.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Worker routine for supdrvGipUpdate and supdrvGipUpdatePerCpu that
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * updates all the per cpu data except the transaction id.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pGip The GIP.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pGipCpu Pointer to the per cpu data.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param u64NanoTS The current time stamp.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param u64TSC The current TSC.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param iTick The current timer tick.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic void supdrvGipDoUpdateCpu(PSUPGLOBALINFOPAGE pGip, PSUPGIPCPU pGipCpu, uint64_t u64NanoTS, uint64_t u64TSC, uint64_t iTick)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* Delta between this and the previous update. */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico ASMAtomicUoWriteU32(&pGipCpu->u32PrevUpdateIntervalNS, (uint32_t)(u64NanoTS - pGipCpu->u64NanoTS));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Update the NanoTS.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Calc TSC delta.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /** @todo validate the NanoTS delta, don't trust the OS to call us when it should... */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * On the 2nd and 3rd callout, reset the history with the current TSC
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * interval since the values entered by supdrvGipInit are totally off.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * The interval on the 1st callout completely unreliable, the 2nd is a bit
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * better, while the 3rd should be most reliable.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico for (i = 0; i < RT_ELEMENTS(pGipCpu->au32TSCHistory); i++)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico ASMAtomicUoWriteU32(&pGipCpu->au32TSCHistory[i], (uint32_t)u64TSCDelta);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * TSC History.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico Assert(RT_ELEMENTS(pGipCpu->au32TSCHistory) == 8);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico iTSCHistoryHead = (pGipCpu->iTSCHistoryHead + 1) & 7;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico ASMAtomicXchgU32(&pGipCpu->iTSCHistoryHead, iTSCHistoryHead);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico ASMAtomicXchgU32(&pGipCpu->au32TSCHistory[iTSCHistoryHead], (uint32_t)u64TSCDelta);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * UpdateIntervalTSC = average of last 8,2,1 intervals depending on update HZ.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico u32UpdateIntervalTSC = pGipCpu->au32TSCHistory[4];
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico u32UpdateIntervalTSC += pGipCpu->au32TSCHistory[5];
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico u32UpdateIntervalTSC += pGipCpu->au32TSCHistory[6];
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico u32UpdateIntervalTSC += pGipCpu->au32TSCHistory[7];
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* Value choosen for a 2GHz Athlon64 running linux 2.6.10/11, . */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico u32UpdateIntervalTSCSlack = u32UpdateIntervalTSC >> 14;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico u32UpdateIntervalTSC += pGipCpu->au32TSCHistory[(iTSCHistoryHead - 1) & 7];
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* value choosen on a 2GHz thinkpad running windows */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico u32UpdateIntervalTSCSlack = u32UpdateIntervalTSC >> 7;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* This value hasn't be checked yet.. waiting for OS/2 and 33Hz timers.. :-) */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico u32UpdateIntervalTSCSlack = u32UpdateIntervalTSC >> 6;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico ASMAtomicXchgU32(&pGipCpu->u32UpdateIntervalTSC, u32UpdateIntervalTSC + u32UpdateIntervalTSCSlack);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico u64CpuHz = ASMMult2xU32RetU64(u32UpdateIntervalTSC, pGip->u32UpdateHz);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Updates the GIP.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pGip Pointer to the GIP.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param u64NanoTS The current nanosecond timesamp.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param u64TSC The current TSC timesamp.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param iTick The current timer tick.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic void supdrvGipUpdate(PSUPGLOBALINFOPAGE pGip, uint64_t u64NanoTS, uint64_t u64TSC, uint64_t iTick)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Determin the relevant CPU data.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico if (RT_UNLIKELY(iCpu >= RT_ELEMENTS(pGip->aCPUs)))
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Start update transaction.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico if (!(ASMAtomicIncU32(&pGipCpu->u32TransactionId) & 1))
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico /* this can happen on win32 if we're taking to long and there are more CPUs around. shouldn't happen though. */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertMsgFailed(("Invalid transaction id, %#x, not odd!\n", pGipCpu->u32TransactionId));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Recalc the update frequency every 0x800th time.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico if (!(pGipCpu->u32TransactionId & (GIP_UPDATEHZ_RECALC_FREQ * 2 - 2)))
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico#ifdef RT_ARCH_AMD64 /** @todo fix 64-bit div here to work on x86 linux. */
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico uint64_t u64Delta = u64NanoTS - pGip->u64NanoTSLastUpdateHz;
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico uint32_t u32UpdateHz = (uint32_t)((UINT64_C(1000000000) * GIP_UPDATEHZ_RECALC_FREQ) / u64Delta);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico ASMAtomicXchgU32(&pGip->u32UpdateHz, u32UpdateHz);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico ASMAtomicXchgU32(&pGip->u32UpdateIntervalNS, 1000000000 / u32UpdateHz);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico ASMAtomicXchgU64(&pGip->u64NanoTSLastUpdateHz, u64NanoTS);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Update the data.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico supdrvGipDoUpdateCpu(pGip, pGipCpu, u64NanoTS, u64TSC, iTick);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Complete transaction.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Updates the per cpu GIP data for the calling cpu.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param pGip Pointer to the GIP.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param u64NanoTS The current nanosecond timesamp.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param u64TSC The current TSC timesamp.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param iCpu The CPU index.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * @param iTick The current timer tick.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNicostatic void supdrvGipUpdatePerCpu(PSUPGLOBALINFOPAGE pGip, uint64_t u64NanoTS, uint64_t u64TSC, unsigned iCpu, uint64_t iTick)
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Start update transaction.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico if (!(ASMAtomicIncU32(&pGipCpu->u32TransactionId) & 1))
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico AssertMsgFailed(("Invalid transaction id, %#x, not odd!\n", pGipCpu->u32TransactionId));
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Update the data.
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico supdrvGipDoUpdateCpu(pGip, pGipCpu, u64NanoTS, u64TSC, iTick);
784a17b07dd7b7acbc0499b915a969f6937533fdJazzyNico * Complete transaction.