[45188] | 1 | /* $Id: SUPDrvInternal.h 67955 2017-07-13 21:13:23Z vboxsync $ */
|
---|
[1] | 2 | /** @file
|
---|
[3537] | 3 | * VirtualBox Support Driver - Internal header.
|
---|
[1] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[62490] | 7 | * Copyright (C) 2006-2016 Oracle Corporation
|
---|
[1] | 8 | *
|
---|
| 9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
| 10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
| 11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
[5999] | 12 | * General Public License (GPL) as published by the Free Software
|
---|
| 13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
| 14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
| 15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
| 16 | *
|
---|
| 17 | * The contents of this file may alternatively be used under the terms
|
---|
| 18 | * of the Common Development and Distribution License Version 1.0
|
---|
| 19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
| 20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
| 21 | * CDDL are applicable instead of those of the GPL.
|
---|
| 22 | *
|
---|
| 23 | * You may elect to license modified versions of this file under the
|
---|
| 24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
[1] | 25 | */
|
---|
| 26 |
|
---|
[10254] | 27 | #ifndef ___SUPDrvInternal_h
|
---|
| 28 | #define ___SUPDrvInternal_h
|
---|
[1] | 29 |
|
---|
| 30 |
|
---|
| 31 | /*******************************************************************************
|
---|
| 32 | * Header Files *
|
---|
| 33 | *******************************************************************************/
|
---|
| 34 | #include <VBox/cdefs.h>
|
---|
| 35 | #include <VBox/types.h>
|
---|
[40602] | 36 | #include <VBox/sup.h>
|
---|
| 37 |
|
---|
[1] | 38 | #include <iprt/assert.h>
|
---|
[40602] | 39 | #include <iprt/list.h>
|
---|
[10250] | 40 | #include <iprt/memobj.h>
|
---|
| 41 | #include <iprt/time.h>
|
---|
| 42 | #include <iprt/timer.h>
|
---|
| 43 | #include <iprt/string.h>
|
---|
| 44 | #include <iprt/err.h>
|
---|
[1] | 45 |
|
---|
[23725] | 46 | #ifdef SUPDRV_AGNOSTIC
|
---|
| 47 | /* do nothing */
|
---|
[1] | 48 |
|
---|
[23725] | 49 | #elif defined(RT_OS_WINDOWS)
|
---|
[62664] | 50 | # include <iprt/nt/nt.h>
|
---|
[1] | 51 | # include <memory.h>
|
---|
| 52 |
|
---|
[3672] | 53 | #elif defined(RT_OS_LINUX)
|
---|
[35647] | 54 | # include <linux/version.h>
|
---|
[42784] | 55 | # if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 33)
|
---|
[35647] | 56 | # include <generated/autoconf.h>
|
---|
| 57 | # else
|
---|
| 58 | # ifndef AUTOCONF_INCLUDED
|
---|
| 59 | # include <linux/autoconf.h>
|
---|
| 60 | # endif
|
---|
[25591] | 61 | # endif
|
---|
[1] | 62 | # if defined(CONFIG_MODVERSIONS) && !defined(MODVERSIONS)
|
---|
| 63 | # define MODVERSIONS
|
---|
| 64 | # if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 71)
|
---|
| 65 | # include <linux/modversions.h>
|
---|
| 66 | # endif
|
---|
| 67 | # endif
|
---|
| 68 | # ifndef KBUILD_STR
|
---|
| 69 | # if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 16)
|
---|
| 70 | # define KBUILD_STR(s) s
|
---|
| 71 | # else
|
---|
| 72 | # define KBUILD_STR(s) #s
|
---|
| 73 | # endif
|
---|
| 74 | # endif
|
---|
| 75 | # include <linux/string.h>
|
---|
| 76 | # include <linux/spinlock.h>
|
---|
| 77 | # include <linux/slab.h>
|
---|
[10935] | 78 | # if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)
|
---|
| 79 | # include <linux/semaphore.h>
|
---|
| 80 | # else /* older kernels */
|
---|
| 81 | # include <asm/semaphore.h>
|
---|
| 82 | # endif /* older kernels */
|
---|
[1563] | 83 | # include <linux/timer.h>
|
---|
[1] | 84 |
|
---|
[3672] | 85 | #elif defined(RT_OS_DARWIN)
|
---|
[1] | 86 | # include <libkern/libkern.h>
|
---|
| 87 | # include <iprt/string.h>
|
---|
| 88 |
|
---|
[3672] | 89 | #elif defined(RT_OS_OS2)
|
---|
[1193] | 90 |
|
---|
[3672] | 91 | #elif defined(RT_OS_FREEBSD)
|
---|
[16029] | 92 | # define memset libkern_memset /** @todo these are just hacks to get it compiling, check out later. */
|
---|
| 93 | # define memcmp libkern_memcmp
|
---|
| 94 | # define strchr libkern_strchr
|
---|
| 95 | # define strrchr libkern_strrchr
|
---|
| 96 | # define ffsl libkern_ffsl
|
---|
| 97 | # define fls libkern_fls
|
---|
| 98 | # define flsl libkern_flsl
|
---|
[3621] | 99 | # include <sys/libkern.h>
|
---|
[16029] | 100 | # undef memset
|
---|
| 101 | # undef memcmp
|
---|
| 102 | # undef strchr
|
---|
| 103 | # undef strrchr
|
---|
| 104 | # undef ffs
|
---|
| 105 | # undef ffsl
|
---|
| 106 | # undef fls
|
---|
| 107 | # undef flsl
|
---|
[3621] | 108 | # include <iprt/string.h>
|
---|
| 109 |
|
---|
[3888] | 110 | #elif defined(RT_OS_SOLARIS)
|
---|
[4474] | 111 | # include <sys/cmn_err.h>
|
---|
[3888] | 112 | # include <iprt/string.h>
|
---|
| 113 |
|
---|
[1] | 114 | #else
|
---|
| 115 | # error "unsupported OS."
|
---|
| 116 | #endif
|
---|
| 117 |
|
---|
[10256] | 118 | #include "SUPDrvIOC.h"
|
---|
[10263] | 119 | #include "SUPDrvIDC.h"
|
---|
[1] | 120 |
|
---|
| 121 |
|
---|
| 122 |
|
---|
| 123 | /*******************************************************************************
|
---|
| 124 | * Defined Constants And Macros *
|
---|
| 125 | *******************************************************************************/
|
---|
| 126 | /*
|
---|
| 127 | * Hardcoded cookies.
|
---|
| 128 | */
|
---|
| 129 | #define BIRD 0x64726962 /* 'bird' */
|
---|
| 130 | #define BIRD_INV 0x62697264 /* 'drib' */
|
---|
| 131 |
|
---|
| 132 |
|
---|
[25465] | 133 | #ifdef RT_OS_WINDOWS
|
---|
[25307] | 134 | /** Use a normal mutex for the loader so we remain at the same IRQL after
|
---|
| 135 | * taking it.
|
---|
| 136 | * @todo fix the mutex implementation on linux and make this the default. */
|
---|
| 137 | # define SUPDRV_USE_MUTEX_FOR_LDR
|
---|
[1] | 138 |
|
---|
[25461] | 139 | /** Use a normal mutex for the GIP so we remain at the same IRQL after
|
---|
| 140 | * taking it.
|
---|
| 141 | * @todo fix the mutex implementation on linux and make this the default. */
|
---|
| 142 | # define SUPDRV_USE_MUTEX_FOR_GIP
|
---|
[1] | 143 | #endif
|
---|
| 144 |
|
---|
| 145 |
|
---|
[25465] | 146 | /**
|
---|
| 147 | * OS debug print macro.
|
---|
[1] | 148 | */
|
---|
[25465] | 149 | #define OSDBGPRINT(a) SUPR0Printf a
|
---|
[1] | 150 |
|
---|
[51770] | 151 | /** Debug printf macro shared with the ring-3 part. */
|
---|
| 152 | #ifdef DEBUG_bird
|
---|
| 153 | # define SUP_DPRINTF(a) SUPR0Printf a
|
---|
| 154 | #else
|
---|
| 155 | # define SUP_DPRINTF(a) do { } while (0)
|
---|
| 156 | #endif
|
---|
[1] | 157 |
|
---|
[51770] | 158 |
|
---|
[19866] | 159 | /** @name Context values for the per-session handle tables.
|
---|
[33540] | 160 | * The context value is used to distinguish between the different kinds of
|
---|
[19866] | 161 | * handles, making the handle table API do all the work.
|
---|
| 162 | * @{ */
|
---|
| 163 | /** Handle context value for single release event handles. */
|
---|
| 164 | #define SUPDRV_HANDLE_CTX_EVENT ((void *)(uintptr_t)(SUPDRVOBJTYPE_SEM_EVENT))
|
---|
| 165 | /** Handle context value for multiple release event handles. */
|
---|
| 166 | #define SUPDRV_HANDLE_CTX_EVENT_MULTI ((void *)(uintptr_t)(SUPDRVOBJTYPE_SEM_EVENT_MULTI))
|
---|
| 167 | /** @} */
|
---|
[1] | 168 |
|
---|
[19866] | 169 |
|
---|
[23726] | 170 | /**
|
---|
| 171 | * Validates a session pointer.
|
---|
| 172 | *
|
---|
| 173 | * @returns true/false accordingly.
|
---|
| 174 | * @param pSession The session.
|
---|
| 175 | */
|
---|
| 176 | #define SUP_IS_SESSION_VALID(pSession) \
|
---|
| 177 | ( VALID_PTR(pSession) \
|
---|
| 178 | && pSession->u32Cookie == BIRD_INV)
|
---|
| 179 |
|
---|
[44188] | 180 | /**
|
---|
| 181 | * Validates a device extension pointer.
|
---|
| 182 | *
|
---|
| 183 | * @returns true/false accordingly.
|
---|
| 184 | * @param pDevExt The device extension.
|
---|
| 185 | */
|
---|
| 186 | #define SUP_IS_DEVEXT_VALID(pDevExt) \
|
---|
| 187 | ( VALID_PTR(pDevExt)\
|
---|
| 188 | && pDevExt->u32Cookie == BIRD)
|
---|
[23726] | 189 |
|
---|
[44188] | 190 |
|
---|
[49634] | 191 | /** @def SUPDRV_WITH_MSR_PROBER
|
---|
| 192 | * Enables the SUP_IOCTL_MSR_PROBER function.
|
---|
| 193 | * By default, only enabled in DEBUG builds as it's a sensitive feature.
|
---|
| 194 | */
|
---|
| 195 | #if defined(DEBUG) && !defined(SUPDRV_WITH_MSR_PROBER) && !defined(SUPDRV_WITHOUT_MSR_PROBER)
|
---|
| 196 | # define SUPDRV_WITH_MSR_PROBER
|
---|
| 197 | #endif
|
---|
| 198 |
|
---|
| 199 | /** @def SUPDRV_WITHOUT_MSR_PROBER
|
---|
| 200 | * Executive overide for disabling the SUP_IOCTL_MSR_PROBER function.
|
---|
| 201 | */
|
---|
| 202 | #ifdef SUPDRV_WITHOUT_MSR_PROBER
|
---|
| 203 | # undef SUPDRV_WITH_MSR_PROBER
|
---|
| 204 | #endif
|
---|
| 205 |
|
---|
[58340] | 206 | #ifdef DOXYGEN_RUNNING
|
---|
| 207 | # define SUPDRV_WITH_MSR_PROBER
|
---|
| 208 | # define SUPDRV_WITHOUT_MSR_PROBER
|
---|
| 209 | #endif
|
---|
| 210 |
|
---|
[54306] | 211 | #if 1
|
---|
[58340] | 212 | /** @def SUPDRV_USE_TSC_DELTA_THREAD
|
---|
| 213 | * Use a dedicated kernel thread to service TSC-delta measurement requests.
|
---|
| 214 | * @todo Test on servers with many CPUs and sockets. */
|
---|
| 215 | # define SUPDRV_USE_TSC_DELTA_THREAD
|
---|
[53054] | 216 | #endif
|
---|
[49634] | 217 |
|
---|
[58340] | 218 |
|
---|
[1] | 219 | /*******************************************************************************
|
---|
| 220 | * Structures and Typedefs *
|
---|
| 221 | *******************************************************************************/
|
---|
| 222 | /** Pointer to the device extension. */
|
---|
| 223 | typedef struct SUPDRVDEVEXT *PSUPDRVDEVEXT;
|
---|
| 224 |
|
---|
[53054] | 225 | #ifdef SUPDRV_USE_TSC_DELTA_THREAD
|
---|
| 226 | /**
|
---|
| 227 | * TSC-delta measurement thread state machine.
|
---|
| 228 | */
|
---|
[54290] | 229 | typedef enum SUPDRVTSCDELTATHREADSTATE
|
---|
[53054] | 230 | {
|
---|
| 231 | /** Uninitialized/invalid value. */
|
---|
[54290] | 232 | kTscDeltaThreadState_Invalid = 0,
|
---|
[54315] | 233 | /** The thread is being created.
|
---|
| 234 | * Next state: Listening, Butchered, Terminating */
|
---|
[54290] | 235 | kTscDeltaThreadState_Creating,
|
---|
[54315] | 236 | /** The thread is listening for events.
|
---|
| 237 | * Previous state: Creating, Measuring
|
---|
| 238 | * Next state: WaitAndMeasure, Butchered, Terminated */
|
---|
[54290] | 239 | kTscDeltaThreadState_Listening,
|
---|
[54315] | 240 | /** The thread is sleeping before starting a measurement.
|
---|
| 241 | * Previous state: Listening, Measuring
|
---|
| 242 | * Next state: Measuring, Butchered, Terminating
|
---|
| 243 | * @remarks The thread won't enter this state on its own, it is put into this
|
---|
| 244 | * state by the GIP timer, the CPU online callback and by the
|
---|
| 245 | * SUP_IOCTL_TSC_DELTA_MEASURE code. */
|
---|
[54290] | 246 | kTscDeltaThreadState_WaitAndMeasure,
|
---|
[54315] | 247 | /** The thread is currently servicing a measurement request.
|
---|
| 248 | * Previous state: WaitAndMeasure
|
---|
| 249 | * Next state: Listening, WaitAndMeasure, Terminate */
|
---|
[54290] | 250 | kTscDeltaThreadState_Measuring,
|
---|
[54315] | 251 | /** The thread is terminating.
|
---|
| 252 | * @remarks The thread won't enter this state on its own, is put into this state
|
---|
| 253 | * by supdrvTscDeltaTerm. */
|
---|
[54290] | 254 | kTscDeltaThreadState_Terminating,
|
---|
[54315] | 255 | /** The thread is butchered due to an unexpected error.
|
---|
| 256 | * Previous State: Creating, Listening, WaitAndMeasure */
|
---|
[54290] | 257 | kTscDeltaThreadState_Butchered,
|
---|
[54315] | 258 | /** The thread is destroyed (final).
|
---|
| 259 | * Previous state: Terminating */
|
---|
[54290] | 260 | kTscDeltaThreadState_Destroyed,
|
---|
[53054] | 261 | /** The usual 32-bit blowup hack. */
|
---|
[54290] | 262 | kTscDeltaThreadState_32BitHack = 0x7fffffff
|
---|
[54315] | 263 | } SUPDRVTSCDELTATHREADSTATE;
|
---|
| 264 | #endif /* SUPDRV_USE_TSC_DELTA_THREAD */
|
---|
[1] | 265 |
|
---|
| 266 | /**
|
---|
| 267 | * Memory reference types.
|
---|
| 268 | */
|
---|
| 269 | typedef enum
|
---|
| 270 | {
|
---|
| 271 | /** Unused entry */
|
---|
| 272 | MEMREF_TYPE_UNUSED = 0,
|
---|
| 273 | /** Locked memory (r3 mapping only). */
|
---|
| 274 | MEMREF_TYPE_LOCKED,
|
---|
[33540] | 275 | /** Continuous memory block (r3 and r0 mapping). */
|
---|
[1] | 276 | MEMREF_TYPE_CONT,
|
---|
| 277 | /** Low memory block (r3 and r0 mapping). */
|
---|
| 278 | MEMREF_TYPE_LOW,
|
---|
| 279 | /** Memory block (r3 and r0 mapping). */
|
---|
| 280 | MEMREF_TYPE_MEM,
|
---|
[4755] | 281 | /** Locked memory (r3 mapping only) allocated by the support driver. */
|
---|
[14575] | 282 | MEMREF_TYPE_PAGE,
|
---|
[1] | 283 | /** Blow the type up to 32-bit and mark the end. */
|
---|
[35494] | 284 | MEMREF_TYPE_32BIT_HACK = 0x7fffffff
|
---|
[1] | 285 | } SUPDRVMEMREFTYPE, *PSUPDRVMEMREFTYPE;
|
---|
| 286 |
|
---|
| 287 |
|
---|
| 288 | /**
|
---|
| 289 | * Structure used for tracking memory a session
|
---|
| 290 | * references in one way or another.
|
---|
| 291 | */
|
---|
| 292 | typedef struct SUPDRVMEMREF
|
---|
| 293 | {
|
---|
| 294 | /** The memory object handle. */
|
---|
[14332] | 295 | RTR0MEMOBJ MemObj;
|
---|
[1] | 296 | /** The ring-3 mapping memory object handle. */
|
---|
[14332] | 297 | RTR0MEMOBJ MapObjR3;
|
---|
[1] | 298 | /** Type of memory. */
|
---|
[14332] | 299 | SUPDRVMEMREFTYPE eType;
|
---|
[1] | 300 | } SUPDRVMEMREF, *PSUPDRVMEMREF;
|
---|
| 301 |
|
---|
| 302 |
|
---|
| 303 | /**
|
---|
| 304 | * Bundle of locked memory ranges.
|
---|
| 305 | */
|
---|
| 306 | typedef struct SUPDRVBUNDLE
|
---|
| 307 | {
|
---|
| 308 | /** Pointer to the next bundle. */
|
---|
[14332] | 309 | struct SUPDRVBUNDLE * volatile pNext;
|
---|
[1] | 310 | /** Referenced memory. */
|
---|
[14332] | 311 | SUPDRVMEMREF aMem[64];
|
---|
[1] | 312 | /** Number of entries used. */
|
---|
| 313 | uint32_t volatile cUsed;
|
---|
| 314 | } SUPDRVBUNDLE, *PSUPDRVBUNDLE;
|
---|
| 315 |
|
---|
| 316 |
|
---|
| 317 | /**
|
---|
| 318 | * Loaded image.
|
---|
| 319 | */
|
---|
| 320 | typedef struct SUPDRVLDRIMAGE
|
---|
| 321 | {
|
---|
| 322 | /** Next in chain. */
|
---|
| 323 | struct SUPDRVLDRIMAGE * volatile pNext;
|
---|
| 324 | /** Pointer to the image. */
|
---|
[14332] | 325 | void *pvImage;
|
---|
[25258] | 326 | /** Pointer to the allocated image buffer.
|
---|
| 327 | * pvImage is 32-byte aligned or it may governed by the native loader (this
|
---|
| 328 | * member is NULL then). */
|
---|
| 329 | void *pvImageAlloc;
|
---|
| 330 | /** Size of the image including the tables. This is mainly for verification
|
---|
| 331 | * of the load request. */
|
---|
| 332 | uint32_t cbImageWithTabs;
|
---|
| 333 | /** Size of the image. */
|
---|
| 334 | uint32_t cbImageBits;
|
---|
| 335 | /** The number of entries in the symbol table. */
|
---|
| 336 | uint32_t cSymbols;
|
---|
| 337 | /** Pointer to the symbol table. */
|
---|
| 338 | PSUPLDRSYM paSymbols;
|
---|
| 339 | /** The offset of the string table. */
|
---|
| 340 | char *pachStrTab;
|
---|
| 341 | /** Size of the string table. */
|
---|
| 342 | uint32_t cbStrTab;
|
---|
[1] | 343 | /** Pointer to the optional module initialization callback. */
|
---|
[14332] | 344 | PFNR0MODULEINIT pfnModuleInit;
|
---|
[1] | 345 | /** Pointer to the optional module termination callback. */
|
---|
[14332] | 346 | PFNR0MODULETERM pfnModuleTerm;
|
---|
| 347 | /** Service request handler. This is NULL for non-service modules. */
|
---|
| 348 | PFNSUPR0SERVICEREQHANDLER pfnServiceReqHandler;
|
---|
[33540] | 349 | /** The ldr image state. (IOCtl code of last operation.) */
|
---|
[14332] | 350 | uint32_t uState;
|
---|
[1] | 351 | /** Usage count. */
|
---|
[14332] | 352 | uint32_t volatile cUsage;
|
---|
[40636] | 353 | /** Pointer to the device extension. */
|
---|
| 354 | struct SUPDRVDEVEXT *pDevExt;
|
---|
[25278] | 355 | #ifdef RT_OS_WINDOWS
|
---|
[25262] | 356 | /** The section object for the loaded image (fNative=true). */
|
---|
| 357 | void *pvNtSectionObj;
|
---|
[25308] | 358 | /** Lock object. */
|
---|
| 359 | RTR0MEMOBJ hMemLock;
|
---|
[25278] | 360 | #endif
|
---|
[37228] | 361 | #if defined(RT_OS_SOLARIS) && defined(VBOX_WITH_NATIVE_SOLARIS_LOADING)
|
---|
| 362 | /** The Solaris module ID. */
|
---|
| 363 | int idSolMod;
|
---|
| 364 | /** Pointer to the module control structure. */
|
---|
| 365 | struct modctl *pSolModCtl;
|
---|
| 366 | #endif
|
---|
[58872] | 367 | #ifdef RT_OS_LINUX
|
---|
| 368 | /** Hack for seeing the module in perf, dtrace and other stack crawlers. */
|
---|
| 369 | struct module *pLnxModHack;
|
---|
| 370 | #endif
|
---|
[25258] | 371 | /** Whether it's loaded by the native loader or not. */
|
---|
| 372 | bool fNative;
|
---|
[1] | 373 | /** Image name. */
|
---|
[14332] | 374 | char szName[32];
|
---|
[1] | 375 | } SUPDRVLDRIMAGE, *PSUPDRVLDRIMAGE;
|
---|
| 376 |
|
---|
| 377 |
|
---|
| 378 | /** Image usage record. */
|
---|
| 379 | typedef struct SUPDRVLDRUSAGE
|
---|
| 380 | {
|
---|
| 381 | /** Next in chain. */
|
---|
| 382 | struct SUPDRVLDRUSAGE * volatile pNext;
|
---|
| 383 | /** The image. */
|
---|
[14332] | 384 | PSUPDRVLDRIMAGE pImage;
|
---|
[1] | 385 | /** Load count. */
|
---|
[14332] | 386 | uint32_t volatile cUsage;
|
---|
[1] | 387 | } SUPDRVLDRUSAGE, *PSUPDRVLDRUSAGE;
|
---|
| 388 |
|
---|
| 389 |
|
---|
| 390 | /**
|
---|
[10377] | 391 | * Component factory registration record.
|
---|
| 392 | */
|
---|
| 393 | typedef struct SUPDRVFACTORYREG
|
---|
| 394 | {
|
---|
| 395 | /** Pointer to the next registration. */
|
---|
[14332] | 396 | struct SUPDRVFACTORYREG *pNext;
|
---|
[10377] | 397 | /** Pointer to the registered factory. */
|
---|
[14332] | 398 | PCSUPDRVFACTORY pFactory;
|
---|
[10377] | 399 | /** The session owning the factory.
|
---|
| 400 | * Used for deregistration and session cleanup. */
|
---|
[14332] | 401 | PSUPDRVSESSION pSession;
|
---|
[10377] | 402 | /** Length of the name. */
|
---|
[14332] | 403 | size_t cchName;
|
---|
[10377] | 404 | } SUPDRVFACTORYREG;
|
---|
| 405 | /** Pointer to a component factory registration record. */
|
---|
| 406 | typedef SUPDRVFACTORYREG *PSUPDRVFACTORYREG;
|
---|
| 407 | /** Pointer to a const component factory registration record. */
|
---|
| 408 | typedef SUPDRVFACTORYREG const *PCSUPDRVFACTORYREG;
|
---|
| 409 |
|
---|
| 410 |
|
---|
| 411 | /**
|
---|
[1] | 412 | * Registered object.
|
---|
| 413 | * This takes care of reference counting and tracking data for access checks.
|
---|
| 414 | */
|
---|
| 415 | typedef struct SUPDRVOBJ
|
---|
| 416 | {
|
---|
| 417 | /** Magic value (SUPDRVOBJ_MAGIC). */
|
---|
| 418 | uint32_t u32Magic;
|
---|
| 419 | /** The object type. */
|
---|
| 420 | SUPDRVOBJTYPE enmType;
|
---|
| 421 | /** Pointer to the next in the global list. */
|
---|
| 422 | struct SUPDRVOBJ * volatile pNext;
|
---|
[4971] | 423 | /** Pointer to the object destructor.
|
---|
| 424 | * This may be set to NULL if the image containing the destructor get unloaded. */
|
---|
[1] | 425 | PFNSUPDRVDESTRUCTOR pfnDestructor;
|
---|
| 426 | /** User argument 1. */
|
---|
| 427 | void *pvUser1;
|
---|
| 428 | /** User argument 2. */
|
---|
| 429 | void *pvUser2;
|
---|
| 430 | /** The total sum of all per-session usage. */
|
---|
| 431 | uint32_t volatile cUsage;
|
---|
| 432 | /** The creator user id. */
|
---|
| 433 | RTUID CreatorUid;
|
---|
| 434 | /** The creator group id. */
|
---|
| 435 | RTGID CreatorGid;
|
---|
| 436 | /** The creator process id. */
|
---|
| 437 | RTPROCESS CreatorProcess;
|
---|
| 438 | } SUPDRVOBJ, *PSUPDRVOBJ;
|
---|
| 439 |
|
---|
| 440 | /** Magic number for SUPDRVOBJ::u32Magic. (Dame Agatha Mary Clarissa Christie). */
|
---|
[45188] | 441 | #define SUPDRVOBJ_MAGIC UINT32_C(0x18900915)
|
---|
[15841] | 442 | /** Dead number magic for SUPDRVOBJ::u32Magic. */
|
---|
[45188] | 443 | #define SUPDRVOBJ_MAGIC_DEAD UINT32_C(0x19760112)
|
---|
[1] | 444 |
|
---|
| 445 | /**
|
---|
| 446 | * The per-session object usage record.
|
---|
| 447 | */
|
---|
| 448 | typedef struct SUPDRVUSAGE
|
---|
| 449 | {
|
---|
| 450 | /** Pointer to the next in the list. */
|
---|
| 451 | struct SUPDRVUSAGE * volatile pNext;
|
---|
| 452 | /** Pointer to the object we're recording usage for. */
|
---|
| 453 | PSUPDRVOBJ pObj;
|
---|
| 454 | /** The usage count. */
|
---|
| 455 | uint32_t volatile cUsage;
|
---|
| 456 | } SUPDRVUSAGE, *PSUPDRVUSAGE;
|
---|
| 457 |
|
---|
| 458 |
|
---|
| 459 | /**
|
---|
| 460 | * Per session data.
|
---|
| 461 | * This is mainly for memory tracking.
|
---|
| 462 | */
|
---|
| 463 | typedef struct SUPDRVSESSION
|
---|
| 464 | {
|
---|
| 465 | /** Pointer to the device extension. */
|
---|
[14332] | 466 | PSUPDRVDEVEXT pDevExt;
|
---|
[1] | 467 | /** Session Cookie. */
|
---|
[14332] | 468 | uint32_t u32Cookie;
|
---|
[44173] | 469 | /** Set if is an unrestricted session, clear if restricted. */
|
---|
| 470 | bool fUnrestricted;
|
---|
[51770] | 471 |
|
---|
| 472 | /** Set if we're in the hash table, clear if not. Protected by the hash
|
---|
| 473 | * table spinlock. */
|
---|
| 474 | bool fInHashTable;
|
---|
| 475 | /** Reference counter. */
|
---|
[47537] | 476 | uint32_t volatile cRefs;
|
---|
[51770] | 477 | /** Pointer to the next session with the same hash (common hash table).
|
---|
| 478 | * Protected by the hash table spinlock. */
|
---|
| 479 | PSUPDRVSESSION pCommonNextHash;
|
---|
| 480 | /** Pointer to the OS specific session pointer, if available and in use.
|
---|
| 481 | * This is atomically set and cleared as the session is inserted and removed
|
---|
| 482 | * from the hash table (protected by the session hash table spinlock). */
|
---|
| 483 | PSUPDRVSESSION *ppOsSessionPtr;
|
---|
| 484 | /** The process (id) of the session. */
|
---|
| 485 | RTPROCESS Process;
|
---|
| 486 | /** Which process this session is associated with.
|
---|
| 487 | * This is NIL_RTR0PROCESS for kernel sessions and valid for user ones. */
|
---|
| 488 | RTR0PROCESS R0Process;
|
---|
[1] | 489 |
|
---|
[67955] | 490 | /** The GVM associated with the session.
|
---|
| 491 | * This is set by VMMR0. */
|
---|
| 492 | PGVM pSessionGVM;
|
---|
| 493 | /** The VM associated with the session.
|
---|
| 494 | * This is set by VMMR0. */
|
---|
| 495 | PVM pSessionVM;
|
---|
| 496 | /** Set to pSessionVM if fast I/O controlls are enabled. */
|
---|
| 497 | PVM pFastIoCtrlVM;
|
---|
[19866] | 498 | /** Handle table for IPRT semaphore wrapper APIs.
|
---|
[45188] | 499 | * This takes care of its own locking in an IRQ safe manner. */
|
---|
[19866] | 500 | RTHANDLETABLE hHandleTable;
|
---|
[1] | 501 | /** Load usage records. (protected by SUPDRVDEVEXT::mtxLdr) */
|
---|
[14332] | 502 | PSUPDRVLDRUSAGE volatile pLdrUsage;
|
---|
[1] | 503 |
|
---|
[51770] | 504 | /** Spinlock protecting the bundles, the GIP members and the
|
---|
| 505 | * fProcessCleanupDone flag. It continues to be valid until the last
|
---|
| 506 | * reference to the session is released. */
|
---|
[14332] | 507 | RTSPINLOCK Spinlock;
|
---|
[1] | 508 | /** The ring-3 mapping of the GIP (readonly). */
|
---|
[14332] | 509 | RTR0MEMOBJ GipMapObjR3;
|
---|
[1] | 510 | /** Set if the session is using the GIP. */
|
---|
[14332] | 511 | uint32_t fGipReferenced;
|
---|
[1] | 512 | /** Bundle of locked memory objects. */
|
---|
[14332] | 513 | SUPDRVBUNDLE Bundle;
|
---|
[19866] | 514 | /** List of generic usage records. (protected by SUPDRVDEVEXT::SpinLock) */
|
---|
| 515 | PSUPDRVUSAGE volatile pUsage;
|
---|
[1] | 516 |
|
---|
| 517 | /** The user id of the session. (Set by the OS part.) */
|
---|
[14332] | 518 | RTUID Uid;
|
---|
[1] | 519 | /** The group id of the session. (Set by the OS part.) */
|
---|
[14332] | 520 | RTGID Gid;
|
---|
[40759] | 521 | /** Per session tracer specfic data. */
|
---|
| 522 | uintptr_t uTracerData;
|
---|
[40819] | 523 | /** The thread currently actively talking to the tracer. (One at the time!) */
|
---|
| 524 | RTNATIVETHREAD hTracerCaller;
|
---|
[41117] | 525 | /** List of tracepoint providers associated with the session
|
---|
| 526 | * (SUPDRVTPPROVIDER). */
|
---|
| 527 | RTLISTANCHOR TpProviders;
|
---|
| 528 | /** The number of providers in TpProviders. */
|
---|
| 529 | uint32_t cTpProviders;
|
---|
| 530 | /** The number of threads active in supdrvIOCtl_TracerUmodProbeFire or
|
---|
| 531 | * SUPR0TracerUmodProbeFire. */
|
---|
| 532 | uint32_t volatile cTpProbesFiring;
|
---|
| 533 | /** User tracepoint modules (PSUPDRVTRACKERUMOD). */
|
---|
| 534 | RTLISTANCHOR TpUmods;
|
---|
| 535 | /** The user tracepoint module lookup table. */
|
---|
| 536 | struct SUPDRVTRACERUMOD *apTpLookupTable[32];
|
---|
[57218] | 537 | /** Whether this is a GIP test-mode client session or not. */
|
---|
| 538 | bool fGipTestMode;
|
---|
[23725] | 539 | #ifndef SUPDRV_AGNOSTIC
|
---|
| 540 | # if defined(RT_OS_DARWIN)
|
---|
[10836] | 541 | /** Pointer to the associated org_virtualbox_SupDrvClient object. */
|
---|
[14332] | 542 | void *pvSupDrvClient;
|
---|
[10836] | 543 | /** Whether this session has been opened or not. */
|
---|
[14332] | 544 | bool fOpened;
|
---|
[23725] | 545 | # endif
|
---|
| 546 | # if defined(RT_OS_OS2)
|
---|
[1193] | 547 | /** The system file number of this session. */
|
---|
[14332] | 548 | uint16_t sfn;
|
---|
| 549 | uint16_t Alignment; /**< Alignment */
|
---|
[23725] | 550 | # endif
|
---|
| 551 | # if defined(RT_OS_DARWIN) || defined(RT_OS_OS2) || defined(RT_OS_SOLARIS)
|
---|
[3189] | 552 | /** Pointer to the next session with the same hash. */
|
---|
[14332] | 553 | PSUPDRVSESSION pNextHash;
|
---|
[23725] | 554 | # endif
|
---|
[51770] | 555 | # if defined(RT_OS_WINDOWS) && defined(VBOX_WITH_HARDENING)
|
---|
| 556 | /** Pointer to the process protection structure for this session. */
|
---|
| 557 | struct SUPDRVNTPROTECT *pNtProtect;
|
---|
| 558 | # endif
|
---|
[23725] | 559 | #endif /* !SUPDRV_AGNOSTIC */
|
---|
[1] | 560 | } SUPDRVSESSION;
|
---|
| 561 |
|
---|
| 562 |
|
---|
| 563 | /**
|
---|
| 564 | * Device extension.
|
---|
| 565 | */
|
---|
| 566 | typedef struct SUPDRVDEVEXT
|
---|
| 567 | {
|
---|
[44188] | 568 | /** Global cookie. */
|
---|
| 569 | uint32_t u32Cookie;
|
---|
| 570 | /** The actual size of SUPDRVSESSION. (SUPDRV_AGNOSTIC) */
|
---|
| 571 | uint32_t cbSession;
|
---|
| 572 |
|
---|
[45188] | 573 | /** Spinlock to serialize the initialization, usage counting and objects.
|
---|
| 574 | * This is IRQ safe because we want to be able signal semaphores from the
|
---|
| 575 | * special HM context (and later maybe interrupt handlers), so we must be able
|
---|
| 576 | * to reference and dereference handles when IRQs are disabled. */
|
---|
[14332] | 577 | RTSPINLOCK Spinlock;
|
---|
[1] | 578 |
|
---|
[4971] | 579 | /** List of registered objects. Protected by the spinlock. */
|
---|
[14332] | 580 | PSUPDRVOBJ volatile pObjs;
|
---|
[1] | 581 | /** List of free object usage records. */
|
---|
[14332] | 582 | PSUPDRVUSAGE volatile pUsageFree;
|
---|
[1] | 583 |
|
---|
| 584 | /** Loader mutex.
|
---|
| 585 | * This protects pvVMMR0, pvVMMR0Entry, pImages and SUPDRVSESSION::pLdrUsage. */
|
---|
[25307] | 586 | #ifdef SUPDRV_USE_MUTEX_FOR_LDR
|
---|
| 587 | RTSEMMUTEX mtxLdr;
|
---|
| 588 | #else
|
---|
[14332] | 589 | RTSEMFASTMUTEX mtxLdr;
|
---|
[25307] | 590 | #endif
|
---|
[1] | 591 |
|
---|
| 592 | /** VMM Module 'handle'.
|
---|
| 593 | * 0 if the code VMM isn't loaded and Idt are nops. */
|
---|
[14332] | 594 | void * volatile pvVMMR0;
|
---|
[4811] | 595 | /** VMMR0EntryFast() pointer. */
|
---|
[67955] | 596 | DECLR0CALLBACKMEMBER(void, pfnVMMR0EntryFast, (PGVM pGVM, PVM pVM, VMCPUID idCpu, uint32_t uOperation));
|
---|
[4811] | 597 | /** VMMR0EntryEx() pointer. */
|
---|
[67955] | 598 | DECLR0CALLBACKMEMBER(int, pfnVMMR0EntryEx, (PGVM pGVM, PVM pVM, VMCPUID idCpu, uint32_t uOperation,
|
---|
| 599 | PSUPVMMR0REQHDR pReq, uint64_t u64Arg, PSUPDRVSESSION pSession));
|
---|
[1] | 600 |
|
---|
| 601 | /** Linked list of loaded code. */
|
---|
[14332] | 602 | PSUPDRVLDRIMAGE volatile pLdrImages;
|
---|
[54013] | 603 | /** Set if the image loading interface got disabled after loading all needed images */
|
---|
| 604 | bool fLdrLockedDown;
|
---|
[1] | 605 |
|
---|
[40636] | 606 | /** @name These members for detecting whether an API caller is in ModuleInit.
|
---|
[40756] | 607 | * Certain APIs are only permitted from ModuleInit, like for instance tracepoint
|
---|
| 608 | * registration.
|
---|
[40636] | 609 | * @{ */
|
---|
| 610 | /** The image currently executing its ModuleInit. */
|
---|
| 611 | PSUPDRVLDRIMAGE volatile pLdrInitImage;
|
---|
| 612 | /** The thread currently executing a ModuleInit function. */
|
---|
| 613 | RTNATIVETHREAD volatile hLdrInitThread;
|
---|
| 614 | /** @} */
|
---|
| 615 |
|
---|
[57229] | 616 | /** Number of times someone reported bad execution context via SUPR0BadContext.
|
---|
| 617 | * (This is times EFLAGS.AC is zero when we expected it to be 1.) */
|
---|
| 618 | uint32_t volatile cBadContextCalls;
|
---|
[40636] | 619 |
|
---|
[1] | 620 | /** GIP mutex.
|
---|
| 621 | * Any changes to any of the GIP members requires ownership of this mutex,
|
---|
| 622 | * except on driver init and termination. */
|
---|
[25461] | 623 | #ifdef SUPDRV_USE_MUTEX_FOR_GIP
|
---|
| 624 | RTSEMMUTEX mtxGip;
|
---|
| 625 | #else
|
---|
[14332] | 626 | RTSEMFASTMUTEX mtxGip;
|
---|
[25461] | 627 | #endif
|
---|
[45188] | 628 | /** GIP spinlock protecting GIP members during Mp events.
|
---|
| 629 | * This is IRQ safe since be may get MP callbacks in contexts where IRQs are
|
---|
| 630 | * disabled (on some platforms). */
|
---|
[40806] | 631 | RTSPINLOCK hGipSpinlock;
|
---|
[1] | 632 | /** Pointer to the Global Info Page (GIP). */
|
---|
[14332] | 633 | PSUPGLOBALINFOPAGE pGip;
|
---|
[1] | 634 | /** The physical address of the GIP. */
|
---|
[14332] | 635 | RTHCPHYS HCPhysGip;
|
---|
[1] | 636 | /** Number of processes using the GIP.
|
---|
| 637 | * (The updates are suspend while cGipUsers is 0.)*/
|
---|
[14332] | 638 | uint32_t volatile cGipUsers;
|
---|
[1] | 639 | /** The ring-0 memory object handle for the GIP page. */
|
---|
[14332] | 640 | RTR0MEMOBJ GipMemObj;
|
---|
[1] | 641 | /** The GIP timer handle. */
|
---|
[14332] | 642 | PRTTIMER pGipTimer;
|
---|
[1] | 643 | /** If non-zero we've successfully called RTTimerRequestSystemGranularity(). */
|
---|
[14332] | 644 | uint32_t u32SystemTimerGranularityGrant;
|
---|
[9470] | 645 | /** The CPU id of the GIP master.
|
---|
[54315] | 646 | * This CPU is responsible for the updating the common GIP data and it is
|
---|
| 647 | * the one used to calculate TSC deltas relative to.
|
---|
| 648 | * (The initial master will have a 0 zero value, but it it goes offline the
|
---|
| 649 | * new master may have a non-zero value.) */
|
---|
[14332] | 650 | RTCPUID volatile idGipMaster;
|
---|
[10377] | 651 |
|
---|
[23725] | 652 | /** Component factory mutex.
|
---|
| 653 | * This protects pComponentFactoryHead and component factory querying. */
|
---|
| 654 | RTSEMFASTMUTEX mtxComponentFactory;
|
---|
| 655 | /** The head of the list of registered component factories. */
|
---|
| 656 | PSUPDRVFACTORYREG pComponentFactoryHead;
|
---|
| 657 |
|
---|
[40756] | 658 | /** Lock protecting The tracer members. */
|
---|
| 659 | RTSEMFASTMUTEX mtxTracer;
|
---|
| 660 | /** List of tracer providers (SUPDRVTPPROVIDER). */
|
---|
| 661 | RTLISTANCHOR TracerProviderList;
|
---|
| 662 | /** List of zombie tracer providers (SUPDRVTPPROVIDER). */
|
---|
| 663 | RTLISTANCHOR TracerProviderZombieList;
|
---|
| 664 | /** Pointer to the tracer registration record. */
|
---|
| 665 | PCSUPDRVTRACERREG pTracerOps;
|
---|
| 666 | /** The ring-0 session of a native tracer provider. */
|
---|
| 667 | PSUPDRVSESSION pTracerSession;
|
---|
| 668 | /** The image containing the tracer. */
|
---|
| 669 | PSUPDRVLDRIMAGE pTracerImage;
|
---|
| 670 | /** The tracer helpers. */
|
---|
| 671 | SUPDRVTRACERHLP TracerHlp;
|
---|
[40819] | 672 | /** The number of session having opened the tracer currently. */
|
---|
| 673 | uint32_t cTracerOpens;
|
---|
[41117] | 674 | /** The number of threads currently calling into the tracer. */
|
---|
| 675 | uint32_t volatile cTracerCallers;
|
---|
[40756] | 676 | /** Set if the tracer is being unloaded. */
|
---|
| 677 | bool fTracerUnloading;
|
---|
[41117] | 678 | /** Hash table for user tracer modules (SUPDRVVTGCOPY). */
|
---|
| 679 | RTLISTANCHOR aTrackerUmodHash[128];
|
---|
[40756] | 680 |
|
---|
[51770] | 681 | /** @name Session Handle Table.
|
---|
| 682 | * @{ */
|
---|
| 683 | /** Spinlock protecting apSessionHashTab, cSessions,
|
---|
| 684 | * SUPDRVSESSION::ppOsSessionPtr, SUPDRVSESSION::pCommonNextHash, and possibly
|
---|
| 685 | * others depending on the OS. */
|
---|
| 686 | RTSPINLOCK hSessionHashTabSpinlock;
|
---|
| 687 | /** Session hash table hash table. The size of this table must make sense in
|
---|
| 688 | * comparison to GVMM_MAX_HANDLES. */
|
---|
| 689 | PSUPDRVSESSION apSessionHashTab[HC_ARCH_BITS == 64 ? 8191 : 127];
|
---|
| 690 | /** The number of open sessions. */
|
---|
| 691 | int32_t cSessions;
|
---|
| 692 | /** @} */
|
---|
| 693 |
|
---|
[54352] | 694 | /** @name Invariant TSC frequency refinement.
|
---|
| 695 | * @{ */
|
---|
| 696 | /** Nanosecond timestamp at the start of the TSC frequency refinement phase. */
|
---|
| 697 | uint64_t nsStartInvarTscRefine;
|
---|
| 698 | /** TSC reading at the start of the TSC frequency refinement phase. */
|
---|
| 699 | uint64_t uTscStartInvarTscRefine;
|
---|
| 700 | /** The CPU id of the CPU that u64TscAnchor was measured on. */
|
---|
| 701 | RTCPUID idCpuInvarTscRefine;
|
---|
| 702 | /** Pointer to the timer used to refine the TSC frequency. */
|
---|
| 703 | PRTTIMER pInvarTscRefineTimer;
|
---|
[54448] | 704 | /** Stop the timer on the next tick because we saw a power event. */
|
---|
| 705 | bool volatile fInvTscRefinePowerEvent;
|
---|
[54352] | 706 | /** @} */
|
---|
| 707 |
|
---|
[53054] | 708 | /** @name TSC-delta measurement.
|
---|
| 709 | * @{ */
|
---|
[54448] | 710 | /** Number of online/offline events, incremented each time a CPU goes online
|
---|
| 711 | * or offline. */
|
---|
| 712 | uint32_t volatile cMpOnOffEvents;
|
---|
[54375] | 713 | /** TSC-delta measurement mutext.
|
---|
| 714 | * At the moment, we don't want to have more than one measurement going on at
|
---|
| 715 | * any one time. We might be using broadcast IPIs which are heavy and could
|
---|
| 716 | * perhaps get in each others way. */
|
---|
| 717 | #ifdef SUPDRV_USE_MUTEX_FOR_GIP
|
---|
| 718 | RTSEMMUTEX mtxTscDelta;
|
---|
| 719 | #else
|
---|
| 720 | RTSEMFASTMUTEX mtxTscDelta;
|
---|
| 721 | #endif
|
---|
[54306] | 722 | /** The set of CPUs we need to take measurements for. */
|
---|
| 723 | RTCPUSET TscDeltaCpuSet;
|
---|
| 724 | /** The set of CPUs we have completed taken measurements for. */
|
---|
| 725 | RTCPUSET TscDeltaObtainedCpuSet;
|
---|
[53464] | 726 | /** @} */
|
---|
| 727 |
|
---|
| 728 | #ifdef SUPDRV_USE_TSC_DELTA_THREAD
|
---|
| 729 | /** @name TSC-delta measurement thread.
|
---|
| 730 | * @{ */
|
---|
[54290] | 731 | /** Spinlock protecting enmTscDeltaThreadState. */
|
---|
[53054] | 732 | RTSPINLOCK hTscDeltaSpinlock;
|
---|
| 733 | /** TSC-delta measurement thread. */
|
---|
| 734 | RTTHREAD hTscDeltaThread;
|
---|
| 735 | /** The event signalled during state changes to the TSC-delta thread. */
|
---|
| 736 | RTSEMEVENT hTscDeltaEvent;
|
---|
| 737 | /** The state of the TSC-delta measurement thread. */
|
---|
[54290] | 738 | SUPDRVTSCDELTATHREADSTATE enmTscDeltaThreadState;
|
---|
[53054] | 739 | /** Thread timeout time before rechecking state in ms. */
|
---|
| 740 | RTMSINTERVAL cMsTscDeltaTimeout;
|
---|
| 741 | /** Whether the TSC-delta measurement was successful. */
|
---|
[54262] | 742 | int32_t volatile rcTscDelta;
|
---|
[54578] | 743 | /** Tell the thread we want TSC-deltas for all CPUs with retries. */
|
---|
| 744 | bool fTscThreadRecomputeAllDeltas;
|
---|
[53054] | 745 | /** @} */
|
---|
| 746 | #endif
|
---|
| 747 |
|
---|
[57218] | 748 | /** @name GIP test mode.
|
---|
| 749 | * @{ */
|
---|
| 750 | /** Reference counter for GIP test-mode sessions. */
|
---|
[57224] | 751 | uint32_t cGipTestModeRefs;
|
---|
[57218] | 752 | /** Cache of TSC frequency before enabling test-mode on invariant GIP systems. */
|
---|
| 753 | uint64_t uGipTestModeInvariantCpuHz;
|
---|
| 754 | /** @} */
|
---|
| 755 |
|
---|
[40602] | 756 | /*
|
---|
[51770] | 757 | * Note! The non-agnostic bits must be at the very end of the structure!
|
---|
[40518] | 758 | */
|
---|
[23725] | 759 | #ifndef SUPDRV_AGNOSTIC
|
---|
| 760 | # ifdef RT_OS_WINDOWS
|
---|
[40518] | 761 | /** Callback object returned by ExCreateCallback. */
|
---|
[14332] | 762 | PCALLBACK_OBJECT pObjPowerCallback;
|
---|
[40518] | 763 | /** Callback handle returned by ExRegisterCallback. */
|
---|
[14332] | 764 | PVOID hPowerCallback;
|
---|
[23725] | 765 | # endif
|
---|
[13494] | 766 | #endif
|
---|
[1] | 767 | } SUPDRVDEVEXT;
|
---|
| 768 |
|
---|
[51770] | 769 | /** Calculates the index into g_apSessionHashTab.*/
|
---|
| 770 | #define SUPDRV_SESSION_HASH(a_pid) ( (a_pid) % RT_ELEMENTS(((SUPDRVDEVEXT *)NULL)->apSessionHashTab) )
|
---|
[1] | 771 |
|
---|
[51770] | 772 |
|
---|
[20374] | 773 | RT_C_DECLS_BEGIN
|
---|
[1] | 774 |
|
---|
| 775 | /*******************************************************************************
|
---|
| 776 | * OS Specific Functions *
|
---|
| 777 | *******************************************************************************/
|
---|
[51770] | 778 | /**
|
---|
| 779 | * Called to clean up the session structure before it's freed.
|
---|
| 780 | *
|
---|
| 781 | * @param pDevExt The device globals.
|
---|
| 782 | * @param pSession The session that's being cleaned up.
|
---|
| 783 | */
|
---|
| 784 | void VBOXCALL supdrvOSCleanupSession(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession);
|
---|
| 785 |
|
---|
| 786 | /**
|
---|
| 787 | * Called to let the OS specfic code perform additional insertion work while
|
---|
| 788 | * still under the protection of the hash table spinlock.
|
---|
| 789 | *
|
---|
| 790 | * @param pDevExt The device globals.
|
---|
| 791 | * @param pSession The session that was inserted.
|
---|
| 792 | * @param pvUser User context specified to the insert call.
|
---|
| 793 | */
|
---|
| 794 | void VBOXCALL supdrvOSSessionHashTabInserted(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, void *pvUser);
|
---|
| 795 |
|
---|
| 796 | /**
|
---|
| 797 | * Called to let the OS specfic code perform additional removal work while still
|
---|
| 798 | * under the protection of the hash table spinlock.
|
---|
| 799 | *
|
---|
| 800 | * @param pDevExt The device globals.
|
---|
| 801 | * @param pSession The session that was removed.
|
---|
| 802 | * @param pvUser User context specified to the remove call.
|
---|
| 803 | */
|
---|
| 804 | void VBOXCALL supdrvOSSessionHashTabRemoved(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, void *pvUser);
|
---|
| 805 |
|
---|
[64255] | 806 | /**
|
---|
[64281] | 807 | * Called during GIP initializtion to calc the CPU group table size.
|
---|
| 808 | *
|
---|
| 809 | * This is currently only implemented on windows [lazy bird].
|
---|
| 810 | *
|
---|
| 811 | * @returns Number of bytes needed for SUPGIPCPUGROUP structures.
|
---|
| 812 | * @param pDevExt The device globals.
|
---|
| 813 | */
|
---|
| 814 | size_t VBOXCALL supdrvOSGipGetGroupTableSize(PSUPDRVDEVEXT pDevExt);
|
---|
| 815 |
|
---|
| 816 | /**
|
---|
[64255] | 817 | * Called during GIP initialization to set up the group table and group count.
|
---|
| 818 | *
|
---|
| 819 | * This is currently only implemented on windows [lazy bird].
|
---|
| 820 | *
|
---|
| 821 | * @param pDevExt The device globals.
|
---|
| 822 | * @param pGip The GIP which group table needs initialization.
|
---|
| 823 | * It's only partially initialized at this point.
|
---|
[64281] | 824 | * @param cbGipCpuGroups What supdrvOSGipGetGroupTableSize returned.
|
---|
[64255] | 825 | */
|
---|
[64281] | 826 | int VBOXCALL supdrvOSInitGipGroupTable(PSUPDRVDEVEXT pDevExt, PSUPGLOBALINFOPAGE pGip, size_t cbGipCpuGroups);
|
---|
[64255] | 827 |
|
---|
| 828 | /**
|
---|
[64281] | 829 | * Initializes the group related members when a CPU is added to the GIP.
|
---|
[64255] | 830 | *
|
---|
[64281] | 831 | * This is called both during GIP initalization and during an CPU online event.
|
---|
| 832 | *
|
---|
[64255] | 833 | * This is currently only implemented on windows [lazy bird].
|
---|
| 834 | *
|
---|
| 835 | * @returns CPU group number.
|
---|
| 836 | * @param pDevExt The device globals.
|
---|
[64284] | 837 | * @param pGip The GIP.
|
---|
| 838 | * @param pGipCpu The GIP CPU structure being initialized.
|
---|
[64255] | 839 | */
|
---|
[64281] | 840 | void VBOXCALL supdrvOSGipInitGroupBitsForCpu(PSUPDRVDEVEXT pDevExt, PSUPGLOBALINFOPAGE pGip, PSUPGIPCPU pGipCpu);
|
---|
[64255] | 841 |
|
---|
[1] | 842 | void VBOXCALL supdrvOSObjInitCreator(PSUPDRVOBJ pObj, PSUPDRVSESSION pSession);
|
---|
| 843 | bool VBOXCALL supdrvOSObjCanAccess(PSUPDRVOBJ pObj, PSUPDRVSESSION pSession, const char *pszObjName, int *prc);
|
---|
[8789] | 844 | bool VBOXCALL supdrvOSGetForcedAsyncTscMode(PSUPDRVDEVEXT pDevExt);
|
---|
[54581] | 845 | bool VBOXCALL supdrvOSAreCpusOfflinedOnSuspend(void);
|
---|
[53396] | 846 | bool VBOXCALL supdrvOSAreTscDeltasInSync(void);
|
---|
[14901] | 847 | int VBOXCALL supdrvOSEnableVTx(bool fEnabled);
|
---|
[54650] | 848 | RTCCUINTREG VBOXCALL supdrvOSChangeCR4(RTCCUINTREG fOrMask, RTCCUINTREG fAndMask);
|
---|
[43379] | 849 | bool VBOXCALL supdrvOSSuspendVTxOnCpu(void);
|
---|
| 850 | void VBOXCALL supdrvOSResumeVTxOnCpu(bool fSuspended);
|
---|
[67137] | 851 | int VBOXCALL supdrvOSGetCurrentGdtRw(RTHCUINTPTR *pGdtRw);
|
---|
[1] | 852 |
|
---|
[25258] | 853 | /**
|
---|
| 854 | * Try open the image using the native loader.
|
---|
| 855 | *
|
---|
| 856 | * @returns IPRT status code.
|
---|
| 857 | * @retval VERR_NOT_SUPPORTED if native loading isn't supported.
|
---|
| 858 | *
|
---|
| 859 | * @param pDevExt The device globals.
|
---|
| 860 | * @param pImage The image handle. pvImage should be set on
|
---|
| 861 | * success, pvImageAlloc can also be set if
|
---|
| 862 | * appropriate.
|
---|
[33540] | 863 | * @param pszFilename The file name - UTF-8, may containing UNIX
|
---|
[25258] | 864 | * slashes on non-UNIX systems.
|
---|
| 865 | */
|
---|
| 866 | int VBOXCALL supdrvOSLdrOpen(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, const char *pszFilename);
|
---|
| 867 |
|
---|
| 868 | /**
|
---|
[41067] | 869 | * Notification call indicating that a image is being opened for the first time.
|
---|
| 870 | *
|
---|
[58872] | 871 | * Called for both native and non-native images (after supdrvOSLdrOpen). Can be
|
---|
| 872 | * used to log the load address of the image or inform the kernel about the
|
---|
| 873 | * alien image.
|
---|
[41067] | 874 | *
|
---|
| 875 | * @param pDevExt The device globals.
|
---|
| 876 | * @param pImage The image handle.
|
---|
[58872] | 877 | * @param pszFilename The file name - UTF-8, may containing UNIX
|
---|
| 878 | * slashes on non-UNIX systems.
|
---|
[41067] | 879 | */
|
---|
[58872] | 880 | void VBOXCALL supdrvOSLdrNotifyOpened(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, const char *pszFilename);
|
---|
[41067] | 881 |
|
---|
| 882 | /**
|
---|
[25258] | 883 | * Validates an entry point address.
|
---|
| 884 | *
|
---|
| 885 | * Called before supdrvOSLdrLoad.
|
---|
| 886 | *
|
---|
| 887 | * @returns IPRT status code.
|
---|
| 888 | * @param pDevExt The device globals.
|
---|
| 889 | * @param pImage The image data (still in the open state).
|
---|
| 890 | * @param pv The address within the image.
|
---|
| 891 | * @param pbImageBits The image bits as loaded by ring-3.
|
---|
| 892 | */
|
---|
| 893 | int VBOXCALL supdrvOSLdrValidatePointer(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage,
|
---|
| 894 | void *pv, const uint8_t *pbImageBits);
|
---|
| 895 |
|
---|
| 896 | /**
|
---|
| 897 | * Load the image.
|
---|
| 898 | *
|
---|
| 899 | * @returns IPRT status code.
|
---|
| 900 | * @param pDevExt The device globals.
|
---|
[37249] | 901 | * @param pImage The image data (up to date). Adjust entrypoints
|
---|
| 902 | * and exports if necessary.
|
---|
[25258] | 903 | * @param pbImageBits The image bits as loaded by ring-3.
|
---|
[37249] | 904 | * @param pReq Pointer to the request packet so that the VMMR0
|
---|
| 905 | * entry points can be adjusted.
|
---|
[25258] | 906 | */
|
---|
[37249] | 907 | int VBOXCALL supdrvOSLdrLoad(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, const uint8_t *pbImageBits, PSUPLDRLOAD pReq);
|
---|
[25258] | 908 |
|
---|
| 909 |
|
---|
| 910 | /**
|
---|
[58872] | 911 | * Unload the image (only called if supdrvOSLdrOpen returned success).
|
---|
[25258] | 912 | *
|
---|
| 913 | * @param pDevExt The device globals.
|
---|
| 914 | * @param pImage The image data (mostly still valid).
|
---|
| 915 | */
|
---|
| 916 | void VBOXCALL supdrvOSLdrUnload(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage);
|
---|
| 917 |
|
---|
[58872] | 918 | /**
|
---|
| 919 | * Notification call indicating that a image is being unloaded.
|
---|
| 920 | *
|
---|
| 921 | * Called for both native and non-native images. In the former case, it's
|
---|
| 922 | * called after supdrvOSLdrUnload.
|
---|
| 923 | *
|
---|
| 924 | * @param pDevExt The device globals.
|
---|
| 925 | * @param pImage The image handle.
|
---|
| 926 | */
|
---|
| 927 | void VBOXCALL supdrvOSLdrNotifyUnloaded(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage);
|
---|
[25258] | 928 |
|
---|
[58872] | 929 |
|
---|
[49634] | 930 | #ifdef SUPDRV_WITH_MSR_PROBER
|
---|
| 931 |
|
---|
| 932 | /**
|
---|
| 933 | * Tries to read an MSR.
|
---|
| 934 | *
|
---|
| 935 | * @returns One of the listed VBox status codes.
|
---|
| 936 | * @retval VINF_SUCCESS if read successfully, value in *puValue.
|
---|
| 937 | * @retval VERR_ACCESS_DENIED if we couldn't read it (GP).
|
---|
| 938 | * @retval VERR_NOT_SUPPORTED if not supported.
|
---|
| 939 | *
|
---|
| 940 | * @param uMsr The MSR to read from.
|
---|
| 941 | * @param idCpu The CPU to read the MSR on. NIL_RTCPUID
|
---|
| 942 | * indicates any suitable CPU.
|
---|
| 943 | * @param puValue Where to return the value.
|
---|
| 944 | */
|
---|
| 945 | int VBOXCALL supdrvOSMsrProberRead(uint32_t uMsr, RTCPUID idCpu, uint64_t *puValue);
|
---|
| 946 |
|
---|
| 947 | /**
|
---|
| 948 | * Tries to write an MSR.
|
---|
| 949 | *
|
---|
| 950 | * @returns One of the listed VBox status codes.
|
---|
| 951 | * @retval VINF_SUCCESS if written successfully.
|
---|
| 952 | * @retval VERR_ACCESS_DENIED if we couldn't write the value to it (GP).
|
---|
| 953 | * @retval VERR_NOT_SUPPORTED if not supported.
|
---|
| 954 | *
|
---|
| 955 | * @param uMsr The MSR to write to.
|
---|
| 956 | * @param idCpu The CPU to write the MSR on. NIL_RTCPUID
|
---|
| 957 | * indicates any suitable CPU.
|
---|
| 958 | * @param uValue The value to write.
|
---|
| 959 | */
|
---|
| 960 | int VBOXCALL supdrvOSMsrProberWrite(uint32_t uMsr, RTCPUID idCpu, uint64_t uValue);
|
---|
| 961 |
|
---|
| 962 | /**
|
---|
| 963 | * Tries to modify an MSR value.
|
---|
| 964 | *
|
---|
| 965 | * @returns One of the listed VBox status codes.
|
---|
| 966 | * @retval VINF_SUCCESS if succeeded.
|
---|
| 967 | * @retval VERR_NOT_SUPPORTED if not supported.
|
---|
| 968 | *
|
---|
| 969 | * @param idCpu The CPU to modify the MSR on. NIL_RTCPUID
|
---|
| 970 | * indicates any suitable CPU.
|
---|
| 971 | * @param pReq The request packet with input arguments and
|
---|
| 972 | * where to store the results.
|
---|
| 973 | */
|
---|
| 974 | int VBOXCALL supdrvOSMsrProberModify(RTCPUID idCpu, PSUPMSRPROBER pReq);
|
---|
| 975 |
|
---|
| 976 | #endif /* SUPDRV_WITH_MSR_PROBER */
|
---|
| 977 |
|
---|
[49787] | 978 | #if defined(RT_OS_DARWIN)
|
---|
[49965] | 979 | int VBOXCALL supdrvDarwinResumeSuspendedKbds(void);
|
---|
[49787] | 980 | #endif
|
---|
[49634] | 981 |
|
---|
[1] | 982 | /*******************************************************************************
|
---|
| 983 | * Shared Functions *
|
---|
| 984 | *******************************************************************************/
|
---|
[23725] | 985 | /* SUPDrv.c */
|
---|
[52575] | 986 | int VBOXCALL supdrvIOCtl(uintptr_t uIOCtl, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPREQHDR pReqHdr, size_t cbReq);
|
---|
[19454] | 987 | int VBOXCALL supdrvIOCtlFast(uintptr_t uIOCtl, VMCPUID idCpu, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession);
|
---|
[10263] | 988 | int VBOXCALL supdrvIDC(uintptr_t uIOCtl, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPDRVIDCREQHDR pReqHdr);
|
---|
[25484] | 989 | int VBOXCALL supdrvInitDevExt(PSUPDRVDEVEXT pDevExt, size_t cbSession);
|
---|
[4800] | 990 | void VBOXCALL supdrvDeleteDevExt(PSUPDRVDEVEXT pDevExt);
|
---|
[44173] | 991 | int VBOXCALL supdrvCreateSession(PSUPDRVDEVEXT pDevExt, bool fUser, bool fUnrestricted, PSUPDRVSESSION *ppSession);
|
---|
[51770] | 992 | int VBOXCALL supdrvSessionHashTabInsert(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPDRVSESSION *ppOsSessionPtr, void *pvUser);
|
---|
| 993 | int VBOXCALL supdrvSessionHashTabRemove(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, void *pvUser);
|
---|
| 994 | PSUPDRVSESSION VBOXCALL supdrvSessionHashTabLookup(PSUPDRVDEVEXT pDevExt, RTPROCESS Process, RTR0PROCESS R0Process,
|
---|
| 995 | PSUPDRVSESSION *ppOsSessionPtr);
|
---|
[47537] | 996 | uint32_t VBOXCALL supdrvSessionRetain(PSUPDRVSESSION pSession);
|
---|
| 997 | uint32_t VBOXCALL supdrvSessionRelease(PSUPDRVSESSION pSession);
|
---|
[57229] | 998 | void VBOXCALL supdrvBadContext(PSUPDRVDEVEXT pDevExt, const char *pszFile, uint32_t uLine, const char *pszExtra);
|
---|
[56558] | 999 | int VBOXCALL supdrvQueryVTCapsInternal(uint32_t *pfCaps);
|
---|
[57378] | 1000 | int VBOXCALL supdrvLdrLoadError(int rc, PSUPLDRLOAD pReq, const char *pszFormat, ...);
|
---|
[1] | 1001 |
|
---|
[54327] | 1002 | /* SUPDrvGip.cpp */
|
---|
| 1003 | int VBOXCALL supdrvGipCreate(PSUPDRVDEVEXT pDevExt);
|
---|
| 1004 | void VBOXCALL supdrvGipDestroy(PSUPDRVDEVEXT pDevExt);
|
---|
| 1005 | int VBOXCALL supdrvIOCtl_TscDeltaMeasure(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPTSCDELTAMEASURE pReq);
|
---|
| 1006 | int VBOXCALL supdrvIOCtl_TscRead(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPTSCREAD pReq);
|
---|
[57218] | 1007 | int VBOXCALL supdrvIOCtl_GipSetFlags(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, uint32_t fOrMask, uint32_t fAndMask);
|
---|
[54327] | 1008 |
|
---|
[57218] | 1009 |
|
---|
[54327] | 1010 | /* SUPDrvTracer.cpp */
|
---|
[40756] | 1011 | int VBOXCALL supdrvTracerInit(PSUPDRVDEVEXT pDevExt);
|
---|
| 1012 | void VBOXCALL supdrvTracerTerm(PSUPDRVDEVEXT pDevExt);
|
---|
| 1013 | void VBOXCALL supdrvTracerModuleUnloading(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage);
|
---|
| 1014 | void VBOXCALL supdrvTracerCleanupSession(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession);
|
---|
[41117] | 1015 | int VBOXCALL supdrvIOCtl_TracerUmodRegister(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession,
|
---|
| 1016 | RTR3PTR R3PtrVtgHdr, RTUINTPTR uVtgHdrAddr,
|
---|
| 1017 | RTR3PTR R3PtrStrTab, uint32_t cbStrTab,
|
---|
| 1018 | const char *pszModName, uint32_t fFlags);
|
---|
| 1019 | int VBOXCALL supdrvIOCtl_TracerUmodDeregister(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, RTR3PTR R3PtrVtgHdr);
|
---|
| 1020 | void VBOXCALL supdrvIOCtl_TracerUmodProbeFire(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPDRVTRACERUSRCTX pCtx);
|
---|
[40819] | 1021 | int VBOXCALL supdrvIOCtl_TracerOpen(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, uint32_t uCookie, uintptr_t uArg);
|
---|
| 1022 | int VBOXCALL supdrvIOCtl_TracerClose(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession);
|
---|
| 1023 | int VBOXCALL supdrvIOCtl_TracerIOCtl(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, uintptr_t uCmd, uintptr_t uArg, int32_t *piRetVal);
|
---|
[40777] | 1024 | extern PFNRT g_pfnSupdrvProbeFireKernel;
|
---|
| 1025 | DECLASM(void) supdrvTracerProbeFireStub(void);
|
---|
[40611] | 1026 |
|
---|
[40975] | 1027 | #ifdef VBOX_WITH_NATIVE_DTRACE
|
---|
[40851] | 1028 | const SUPDRVTRACERREG * VBOXCALL supdrvDTraceInit(void);
|
---|
| 1029 | #endif
|
---|
[40756] | 1030 |
|
---|
[20374] | 1031 | RT_C_DECLS_END
|
---|
[1] | 1032 |
|
---|
| 1033 | #endif
|
---|
| 1034 |
|
---|