[45188] | 1 | /* $Id: SUPDrvInternal.h 101358 2023-10-05 15:24:57Z vboxsync $ */
|
---|
[1] | 2 | /** @file
|
---|
[3537] | 3 | * VirtualBox Support Driver - Internal header.
|
---|
[1] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
[1] | 8 | *
|
---|
[96407] | 9 | * This file is part of VirtualBox base platform packages, as
|
---|
| 10 | * available from https://www.virtualbox.org.
|
---|
[5999] | 11 | *
|
---|
[96407] | 12 | * This program is free software; you can redistribute it and/or
|
---|
| 13 | * modify it under the terms of the GNU General Public License
|
---|
| 14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
| 15 | * License.
|
---|
| 16 | *
|
---|
| 17 | * This program is distributed in the hope that it will be useful, but
|
---|
| 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 20 | * General Public License for more details.
|
---|
| 21 | *
|
---|
| 22 | * You should have received a copy of the GNU General Public License
|
---|
| 23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 24 | *
|
---|
[5999] | 25 | * The contents of this file may alternatively be used under the terms
|
---|
| 26 | * of the Common Development and Distribution License Version 1.0
|
---|
[96407] | 27 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
| 28 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
[5999] | 29 | * CDDL are applicable instead of those of the GPL.
|
---|
| 30 | *
|
---|
| 31 | * You may elect to license modified versions of this file under the
|
---|
| 32 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
[96407] | 33 | *
|
---|
| 34 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
[1] | 35 | */
|
---|
| 36 |
|
---|
[76568] | 37 | #ifndef VBOX_INCLUDED_SRC_Support_SUPDrvInternal_h
|
---|
| 38 | #define VBOX_INCLUDED_SRC_Support_SUPDrvInternal_h
|
---|
[76527] | 39 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
| 40 | # pragma once
|
---|
| 41 | #endif
|
---|
[1] | 42 |
|
---|
| 43 |
|
---|
[85174] | 44 | /*********************************************************************************************************************************
|
---|
| 45 | * Header Files *
|
---|
| 46 | *********************************************************************************************************************************/
|
---|
[1] | 47 | #include <VBox/cdefs.h>
|
---|
| 48 | #include <VBox/types.h>
|
---|
[40602] | 49 | #include <VBox/sup.h>
|
---|
| 50 |
|
---|
[1] | 51 | #include <iprt/assert.h>
|
---|
[40602] | 52 | #include <iprt/list.h>
|
---|
[10250] | 53 | #include <iprt/memobj.h>
|
---|
| 54 | #include <iprt/time.h>
|
---|
| 55 | #include <iprt/timer.h>
|
---|
| 56 | #include <iprt/string.h>
|
---|
| 57 | #include <iprt/err.h>
|
---|
[1] | 58 |
|
---|
[87700] | 59 | #if defined(SUPDRV_AGNOSTIC) && !defined(RT_OS_LINUX)
|
---|
[23725] | 60 | /* do nothing */
|
---|
[1] | 61 |
|
---|
[23725] | 62 | #elif defined(RT_OS_WINDOWS)
|
---|
[62664] | 63 | # include <iprt/nt/nt.h>
|
---|
[1] | 64 | # include <memory.h>
|
---|
| 65 |
|
---|
[3672] | 66 | #elif defined(RT_OS_LINUX)
|
---|
[85698] | 67 | # include <iprt/linux/version.h>
|
---|
| 68 | # if RTLNX_VER_MIN(2,6,33)
|
---|
[35647] | 69 | # include <generated/autoconf.h>
|
---|
| 70 | # else
|
---|
| 71 | # ifndef AUTOCONF_INCLUDED
|
---|
| 72 | # include <linux/autoconf.h>
|
---|
| 73 | # endif
|
---|
[25591] | 74 | # endif
|
---|
[1] | 75 | # if defined(CONFIG_MODVERSIONS) && !defined(MODVERSIONS)
|
---|
| 76 | # define MODVERSIONS
|
---|
[85698] | 77 | # if RTLNX_VER_MAX(2,5,71)
|
---|
[1] | 78 | # include <linux/modversions.h>
|
---|
| 79 | # endif
|
---|
| 80 | # endif
|
---|
| 81 | # ifndef KBUILD_STR
|
---|
[85698] | 82 | # if RTLNX_VER_MAX(2,6,16)
|
---|
[1] | 83 | # define KBUILD_STR(s) s
|
---|
| 84 | # else
|
---|
| 85 | # define KBUILD_STR(s) #s
|
---|
| 86 | # endif
|
---|
| 87 | # endif
|
---|
[87700] | 88 | # ifndef SUPDRV_AGNOSTIC
|
---|
| 89 | # include <linux/string.h>
|
---|
| 90 | # include <linux/spinlock.h>
|
---|
| 91 | # include <linux/slab.h>
|
---|
| 92 | # if RTLNX_VER_MIN(2,6,27)
|
---|
| 93 | # include <linux/semaphore.h>
|
---|
| 94 | # else /* older kernels */
|
---|
| 95 | # include <asm/semaphore.h>
|
---|
| 96 | # endif /* older kernels */
|
---|
| 97 | # include <linux/timer.h>
|
---|
| 98 | # endif
|
---|
[87706] | 99 | # if RTLNX_VER_MIN(3,2,0)
|
---|
[87700] | 100 | # include <linux/export.h>
|
---|
| 101 | # else
|
---|
| 102 | # include <linux/module.h>
|
---|
[87706] | 103 | # if (defined(RT_ARCH_X86) || defined(RT_ARCH_AMD64)) && defined(SUPDRV_AGNOSTIC) /* fix conflicts with iprt/x86.h */
|
---|
[87704] | 104 | # undef CS
|
---|
[87709] | 105 | # undef DS
|
---|
| 106 | # undef ES
|
---|
| 107 | # undef FS
|
---|
| 108 | # undef GS
|
---|
[87704] | 109 | # undef SS
|
---|
| 110 | # undef EFLAGS
|
---|
| 111 | # undef R15
|
---|
| 112 | # undef R14
|
---|
| 113 | # undef R13
|
---|
| 114 | # undef R12
|
---|
| 115 | # undef R11
|
---|
| 116 | # undef R10
|
---|
| 117 | # undef R9
|
---|
| 118 | # undef R8
|
---|
| 119 | # undef RDI
|
---|
| 120 | # undef RSI
|
---|
| 121 | # undef RBP
|
---|
| 122 | # undef RSP
|
---|
| 123 | # undef RBX
|
---|
| 124 | # undef RDX
|
---|
| 125 | # undef RCX
|
---|
| 126 | # undef RAX
|
---|
| 127 | # undef MSR_CORE_PERF_LIMIT_REASONS
|
---|
| 128 | # undef MSR_DRAM_ENERGY_STATUS
|
---|
| 129 | # undef MSR_DRAM_PERF_STATUS
|
---|
| 130 | # undef MSR_DRAM_POWER_INFO
|
---|
| 131 | # undef MSR_DRAM_POWER_LIMIT
|
---|
| 132 | # undef MSR_IA32_APERF
|
---|
| 133 | # undef MSR_IA32_ARCH_CAPABILITIES
|
---|
| 134 | # undef MSR_IA32_CR_PAT
|
---|
| 135 | # undef MSR_IA32_DS_AREA
|
---|
| 136 | # undef MSR_IA32_FEATURE_CONTROL
|
---|
| 137 | # undef MSR_IA32_FLUSH_CMD
|
---|
| 138 | # undef MSR_IA32_MC0_CTL
|
---|
| 139 | # undef MSR_IA32_MC0_STATUS
|
---|
| 140 | # undef MSR_IA32_MCG_CAP
|
---|
| 141 | # undef MSR_IA32_MCG_STATUS
|
---|
| 142 | # undef MSR_IA32_MISC_ENABLE
|
---|
| 143 | # undef MSR_IA32_MISC_ENABLE_BTS_UNAVAIL
|
---|
| 144 | # undef MSR_IA32_MISC_ENABLE_LIMIT_CPUID
|
---|
| 145 | # undef MSR_IA32_MISC_ENABLE_PEBS_UNAVAIL
|
---|
| 146 | # undef MSR_IA32_MISC_ENABLE_TCC
|
---|
| 147 | # undef MSR_IA32_MISC_ENABLE_XD_DISABLE
|
---|
| 148 | # undef MSR_IA32_MPERF
|
---|
| 149 | # undef MSR_IA32_PEBS_ENABLE
|
---|
| 150 | # undef MSR_IA32_PERF_CTL
|
---|
| 151 | # undef MSR_IA32_PERF_STATUS
|
---|
| 152 | # undef MSR_IA32_PLATFORM_ID
|
---|
| 153 | # undef MSR_IA32_PMC0
|
---|
| 154 | # undef MSR_IA32_PRED_CMD
|
---|
| 155 | # undef MSR_IA32_RTIT_CTL
|
---|
| 156 | # undef MSR_IA32_SMBASE
|
---|
| 157 | # undef MSR_IA32_SMM_MONITOR_CTL
|
---|
| 158 | # undef MSR_IA32_SPEC_CTRL
|
---|
| 159 | # undef MSR_IA32_THERM_STATUS
|
---|
| 160 | # undef MSR_IA32_TSC
|
---|
| 161 | # undef MSR_IA32_TSC_ADJUST
|
---|
| 162 | # undef MSR_IA32_TSX_CTRL
|
---|
| 163 | # undef MSR_IA32_VMX_BASIC
|
---|
| 164 | # undef MSR_IA32_VMX_CR0_FIXED0
|
---|
| 165 | # undef MSR_IA32_VMX_CR0_FIXED1
|
---|
| 166 | # undef MSR_IA32_VMX_CR4_FIXED0
|
---|
| 167 | # undef MSR_IA32_VMX_CR4_FIXED1
|
---|
| 168 | # undef MSR_IA32_VMX_ENTRY_CTLS
|
---|
| 169 | # undef MSR_IA32_VMX_EPT_VPID_CAP
|
---|
| 170 | # undef MSR_IA32_VMX_EXIT_CTLS
|
---|
| 171 | # undef MSR_IA32_VMX_MISC
|
---|
| 172 | # undef MSR_IA32_VMX_PINBASED_CTLS
|
---|
| 173 | # undef MSR_IA32_VMX_PROCBASED_CTLS
|
---|
| 174 | # undef MSR_IA32_VMX_PROCBASED_CTLS2
|
---|
| 175 | # undef MSR_IA32_VMX_TRUE_ENTRY_CTLS
|
---|
| 176 | # undef MSR_IA32_VMX_TRUE_EXIT_CTLS
|
---|
| 177 | # undef MSR_IA32_VMX_TRUE_PINBASED_CTLS
|
---|
| 178 | # undef MSR_IA32_VMX_TRUE_PROCBASED_CTLS
|
---|
| 179 | # undef MSR_IA32_VMX_VMCS_ENUM
|
---|
| 180 | # undef MSR_IA32_VMX_VMFUNC
|
---|
| 181 | # undef MSR_K6_PFIR
|
---|
| 182 | # undef MSR_K6_PSOR
|
---|
| 183 | # undef MSR_K6_UWCCR
|
---|
| 184 | # undef MSR_K6_WHCR
|
---|
| 185 | # undef MSR_K7_EVNTSEL0
|
---|
| 186 | # undef MSR_K7_EVNTSEL1
|
---|
| 187 | # undef MSR_K7_EVNTSEL2
|
---|
| 188 | # undef MSR_K7_EVNTSEL3
|
---|
| 189 | # undef MSR_K7_PERFCTR0
|
---|
| 190 | # undef MSR_K7_PERFCTR1
|
---|
| 191 | # undef MSR_K7_PERFCTR2
|
---|
| 192 | # undef MSR_K7_PERFCTR3
|
---|
| 193 | # undef MSR_K8_SYSCFG
|
---|
| 194 | # undef MSR_K8_TOP_MEM1
|
---|
| 195 | # undef MSR_K8_TOP_MEM2
|
---|
| 196 | # undef MSR_OFFCORE_RSP_0
|
---|
| 197 | # undef MSR_OFFCORE_RSP_1
|
---|
| 198 | # undef MSR_PKG_C10_RESIDENCY
|
---|
| 199 | # undef MSR_PKG_C2_RESIDENCY
|
---|
| 200 | # undef MSR_PKG_CST_CONFIG_CONTROL
|
---|
| 201 | # undef MSR_PKG_ENERGY_STATUS
|
---|
| 202 | # undef MSR_PKG_PERF_STATUS
|
---|
| 203 | # undef MSR_PKG_POWER_INFO
|
---|
| 204 | # undef MSR_PKG_POWER_LIMIT
|
---|
| 205 | # undef MSR_PKGC3_IRTL
|
---|
| 206 | # undef MSR_PP0_ENERGY_STATUS
|
---|
| 207 | # undef MSR_PP1_ENERGY_STATUS
|
---|
| 208 | # undef MSR_RAPL_POWER_UNIT
|
---|
| 209 | # undef MSR_TURBO_ACTIVATION_RATIO
|
---|
| 210 | # undef VMX_BASIC_MEM_TYPE_WB
|
---|
| 211 | # undef X86_CR0_AM
|
---|
| 212 | # undef X86_CR0_CD
|
---|
| 213 | # undef X86_CR0_EM
|
---|
| 214 | # undef X86_CR0_ET
|
---|
| 215 | # undef X86_CR0_MP
|
---|
| 216 | # undef X86_CR0_NE
|
---|
| 217 | # undef X86_CR0_NW
|
---|
| 218 | # undef X86_CR0_PE
|
---|
| 219 | # undef X86_CR0_PG
|
---|
| 220 | # undef X86_CR0_TS
|
---|
| 221 | # undef X86_CR0_WP
|
---|
| 222 | # undef X86_CR3_PCD
|
---|
| 223 | # undef X86_CR3_PWT
|
---|
| 224 | # undef X86_CR4_DE
|
---|
| 225 | # undef X86_CR4_FSGSBASE
|
---|
| 226 | # undef X86_CR4_MCE
|
---|
| 227 | # undef X86_CR4_OSFXSR
|
---|
| 228 | # undef X86_CR4_OSXSAVE
|
---|
| 229 | # undef X86_CR4_PAE
|
---|
| 230 | # undef X86_CR4_PCE
|
---|
| 231 | # undef X86_CR4_PCIDE
|
---|
| 232 | # undef X86_CR4_PGE
|
---|
| 233 | # undef X86_CR4_PKE
|
---|
| 234 | # undef X86_CR4_PSE
|
---|
| 235 | # undef X86_CR4_PVI
|
---|
| 236 | # undef X86_CR4_SMAP
|
---|
| 237 | # undef X86_CR4_SMEP
|
---|
| 238 | # undef X86_CR4_SMXE
|
---|
| 239 | # undef X86_CR4_TSD
|
---|
| 240 | # undef X86_CR4_UMIP
|
---|
| 241 | # undef X86_CR4_VME
|
---|
| 242 | # undef X86_CR4_VMXE
|
---|
| 243 | # endif
|
---|
[87700] | 244 | # endif
|
---|
| 245 | # define SUPR0_EXPORT_SYMBOL(a_Name) EXPORT_SYMBOL(a_Name)
|
---|
[1] | 246 |
|
---|
[3672] | 247 | #elif defined(RT_OS_DARWIN)
|
---|
[1] | 248 | # include <libkern/libkern.h>
|
---|
| 249 | # include <iprt/string.h>
|
---|
| 250 |
|
---|
[3672] | 251 | #elif defined(RT_OS_OS2)
|
---|
[1193] | 252 |
|
---|
[3672] | 253 | #elif defined(RT_OS_FREEBSD)
|
---|
[16029] | 254 | # define memset libkern_memset /** @todo these are just hacks to get it compiling, check out later. */
|
---|
| 255 | # define memcmp libkern_memcmp
|
---|
| 256 | # define strchr libkern_strchr
|
---|
| 257 | # define strrchr libkern_strrchr
|
---|
| 258 | # define ffsl libkern_ffsl
|
---|
| 259 | # define fls libkern_fls
|
---|
| 260 | # define flsl libkern_flsl
|
---|
[3621] | 261 | # include <sys/libkern.h>
|
---|
[16029] | 262 | # undef memset
|
---|
| 263 | # undef memcmp
|
---|
| 264 | # undef strchr
|
---|
| 265 | # undef strrchr
|
---|
| 266 | # undef ffs
|
---|
| 267 | # undef ffsl
|
---|
| 268 | # undef fls
|
---|
| 269 | # undef flsl
|
---|
[3621] | 270 | # include <iprt/string.h>
|
---|
| 271 |
|
---|
[3888] | 272 | #elif defined(RT_OS_SOLARIS)
|
---|
[4474] | 273 | # include <sys/cmn_err.h>
|
---|
[3888] | 274 | # include <iprt/string.h>
|
---|
| 275 |
|
---|
[1] | 276 | #else
|
---|
| 277 | # error "unsupported OS."
|
---|
| 278 | #endif
|
---|
| 279 |
|
---|
[10256] | 280 | #include "SUPDrvIOC.h"
|
---|
[10263] | 281 | #include "SUPDrvIDC.h"
|
---|
[1] | 282 |
|
---|
| 283 |
|
---|
| 284 |
|
---|
[85174] | 285 | /*********************************************************************************************************************************
|
---|
| 286 | * Defined Constants And Macros *
|
---|
| 287 | *********************************************************************************************************************************/
|
---|
[1] | 288 | /*
|
---|
| 289 | * Hardcoded cookies.
|
---|
| 290 | */
|
---|
| 291 | #define BIRD 0x64726962 /* 'bird' */
|
---|
| 292 | #define BIRD_INV 0x62697264 /* 'drib' */
|
---|
| 293 |
|
---|
| 294 |
|
---|
[25465] | 295 | #ifdef RT_OS_WINDOWS
|
---|
[25307] | 296 | /** Use a normal mutex for the loader so we remain at the same IRQL after
|
---|
| 297 | * taking it.
|
---|
| 298 | * @todo fix the mutex implementation on linux and make this the default. */
|
---|
| 299 | # define SUPDRV_USE_MUTEX_FOR_LDR
|
---|
[1] | 300 |
|
---|
[25461] | 301 | /** Use a normal mutex for the GIP so we remain at the same IRQL after
|
---|
| 302 | * taking it.
|
---|
| 303 | * @todo fix the mutex implementation on linux and make this the default. */
|
---|
| 304 | # define SUPDRV_USE_MUTEX_FOR_GIP
|
---|
[1] | 305 | #endif
|
---|
| 306 |
|
---|
[87700] | 307 | #ifndef SUPR0_EXPORT_SYMBOL
|
---|
| 308 | # define SUPR0_EXPORT_SYMBOL(a_Name) extern int g_supDrvExportSymbolDummyVariable
|
---|
| 309 | #endif
|
---|
[85507] | 310 |
|
---|
[25465] | 311 | /**
|
---|
| 312 | * OS debug print macro.
|
---|
[1] | 313 | */
|
---|
[25465] | 314 | #define OSDBGPRINT(a) SUPR0Printf a
|
---|
[1] | 315 |
|
---|
| 316 |
|
---|
[19866] | 317 | /** @name Context values for the per-session handle tables.
|
---|
[33540] | 318 | * The context value is used to distinguish between the different kinds of
|
---|
[19866] | 319 | * handles, making the handle table API do all the work.
|
---|
| 320 | * @{ */
|
---|
| 321 | /** Handle context value for single release event handles. */
|
---|
| 322 | #define SUPDRV_HANDLE_CTX_EVENT ((void *)(uintptr_t)(SUPDRVOBJTYPE_SEM_EVENT))
|
---|
| 323 | /** Handle context value for multiple release event handles. */
|
---|
| 324 | #define SUPDRV_HANDLE_CTX_EVENT_MULTI ((void *)(uintptr_t)(SUPDRVOBJTYPE_SEM_EVENT_MULTI))
|
---|
| 325 | /** @} */
|
---|
[1] | 326 |
|
---|
[19866] | 327 |
|
---|
[23726] | 328 | /**
|
---|
| 329 | * Validates a session pointer.
|
---|
| 330 | *
|
---|
| 331 | * @returns true/false accordingly.
|
---|
| 332 | * @param pSession The session.
|
---|
| 333 | */
|
---|
| 334 | #define SUP_IS_SESSION_VALID(pSession) \
|
---|
[90780] | 335 | ( RT_VALID_PTR(pSession) \
|
---|
[23726] | 336 | && pSession->u32Cookie == BIRD_INV)
|
---|
| 337 |
|
---|
[44188] | 338 | /**
|
---|
| 339 | * Validates a device extension pointer.
|
---|
| 340 | *
|
---|
| 341 | * @returns true/false accordingly.
|
---|
| 342 | * @param pDevExt The device extension.
|
---|
| 343 | */
|
---|
| 344 | #define SUP_IS_DEVEXT_VALID(pDevExt) \
|
---|
[90780] | 345 | ( RT_VALID_PTR(pDevExt) \
|
---|
[44188] | 346 | && pDevExt->u32Cookie == BIRD)
|
---|
[23726] | 347 |
|
---|
[44188] | 348 |
|
---|
[49634] | 349 | /** @def SUPDRV_WITH_MSR_PROBER
|
---|
| 350 | * Enables the SUP_IOCTL_MSR_PROBER function.
|
---|
| 351 | * By default, only enabled in DEBUG builds as it's a sensitive feature.
|
---|
| 352 | */
|
---|
| 353 | #if defined(DEBUG) && !defined(SUPDRV_WITH_MSR_PROBER) && !defined(SUPDRV_WITHOUT_MSR_PROBER)
|
---|
| 354 | # define SUPDRV_WITH_MSR_PROBER
|
---|
| 355 | #endif
|
---|
| 356 |
|
---|
| 357 | /** @def SUPDRV_WITHOUT_MSR_PROBER
|
---|
| 358 | * Executive overide for disabling the SUP_IOCTL_MSR_PROBER function.
|
---|
| 359 | */
|
---|
| 360 | #ifdef SUPDRV_WITHOUT_MSR_PROBER
|
---|
| 361 | # undef SUPDRV_WITH_MSR_PROBER
|
---|
| 362 | #endif
|
---|
| 363 |
|
---|
[58340] | 364 | #ifdef DOXYGEN_RUNNING
|
---|
| 365 | # define SUPDRV_WITH_MSR_PROBER
|
---|
| 366 | # define SUPDRV_WITHOUT_MSR_PROBER
|
---|
| 367 | #endif
|
---|
| 368 |
|
---|
[54306] | 369 | #if 1
|
---|
[58340] | 370 | /** @def SUPDRV_USE_TSC_DELTA_THREAD
|
---|
| 371 | * Use a dedicated kernel thread to service TSC-delta measurement requests.
|
---|
| 372 | * @todo Test on servers with many CPUs and sockets. */
|
---|
| 373 | # define SUPDRV_USE_TSC_DELTA_THREAD
|
---|
[53054] | 374 | #endif
|
---|
[49634] | 375 |
|
---|
[58340] | 376 |
|
---|
[85174] | 377 | /*********************************************************************************************************************************
|
---|
| 378 | * Structures and Typedefs *
|
---|
| 379 | *********************************************************************************************************************************/
|
---|
[1] | 380 | /** Pointer to the device extension. */
|
---|
| 381 | typedef struct SUPDRVDEVEXT *PSUPDRVDEVEXT;
|
---|
| 382 |
|
---|
[53054] | 383 | #ifdef SUPDRV_USE_TSC_DELTA_THREAD
|
---|
| 384 | /**
|
---|
| 385 | * TSC-delta measurement thread state machine.
|
---|
| 386 | */
|
---|
[54290] | 387 | typedef enum SUPDRVTSCDELTATHREADSTATE
|
---|
[53054] | 388 | {
|
---|
| 389 | /** Uninitialized/invalid value. */
|
---|
[54290] | 390 | kTscDeltaThreadState_Invalid = 0,
|
---|
[54315] | 391 | /** The thread is being created.
|
---|
| 392 | * Next state: Listening, Butchered, Terminating */
|
---|
[54290] | 393 | kTscDeltaThreadState_Creating,
|
---|
[54315] | 394 | /** The thread is listening for events.
|
---|
| 395 | * Previous state: Creating, Measuring
|
---|
| 396 | * Next state: WaitAndMeasure, Butchered, Terminated */
|
---|
[54290] | 397 | kTscDeltaThreadState_Listening,
|
---|
[54315] | 398 | /** The thread is sleeping before starting a measurement.
|
---|
| 399 | * Previous state: Listening, Measuring
|
---|
| 400 | * Next state: Measuring, Butchered, Terminating
|
---|
| 401 | * @remarks The thread won't enter this state on its own, it is put into this
|
---|
| 402 | * state by the GIP timer, the CPU online callback and by the
|
---|
| 403 | * SUP_IOCTL_TSC_DELTA_MEASURE code. */
|
---|
[54290] | 404 | kTscDeltaThreadState_WaitAndMeasure,
|
---|
[54315] | 405 | /** The thread is currently servicing a measurement request.
|
---|
| 406 | * Previous state: WaitAndMeasure
|
---|
| 407 | * Next state: Listening, WaitAndMeasure, Terminate */
|
---|
[54290] | 408 | kTscDeltaThreadState_Measuring,
|
---|
[54315] | 409 | /** The thread is terminating.
|
---|
| 410 | * @remarks The thread won't enter this state on its own, is put into this state
|
---|
| 411 | * by supdrvTscDeltaTerm. */
|
---|
[54290] | 412 | kTscDeltaThreadState_Terminating,
|
---|
[54315] | 413 | /** The thread is butchered due to an unexpected error.
|
---|
| 414 | * Previous State: Creating, Listening, WaitAndMeasure */
|
---|
[54290] | 415 | kTscDeltaThreadState_Butchered,
|
---|
[54315] | 416 | /** The thread is destroyed (final).
|
---|
| 417 | * Previous state: Terminating */
|
---|
[54290] | 418 | kTscDeltaThreadState_Destroyed,
|
---|
[53054] | 419 | /** The usual 32-bit blowup hack. */
|
---|
[54290] | 420 | kTscDeltaThreadState_32BitHack = 0x7fffffff
|
---|
[54315] | 421 | } SUPDRVTSCDELTATHREADSTATE;
|
---|
| 422 | #endif /* SUPDRV_USE_TSC_DELTA_THREAD */
|
---|
[1] | 423 |
|
---|
| 424 | /**
|
---|
| 425 | * Memory reference types.
|
---|
| 426 | */
|
---|
| 427 | typedef enum
|
---|
| 428 | {
|
---|
| 429 | /** Unused entry */
|
---|
| 430 | MEMREF_TYPE_UNUSED = 0,
|
---|
| 431 | /** Locked memory (r3 mapping only). */
|
---|
| 432 | MEMREF_TYPE_LOCKED,
|
---|
[33540] | 433 | /** Continuous memory block (r3 and r0 mapping). */
|
---|
[1] | 434 | MEMREF_TYPE_CONT,
|
---|
| 435 | /** Low memory block (r3 and r0 mapping). */
|
---|
| 436 | MEMREF_TYPE_LOW,
|
---|
| 437 | /** Memory block (r3 and r0 mapping). */
|
---|
| 438 | MEMREF_TYPE_MEM,
|
---|
[4755] | 439 | /** Locked memory (r3 mapping only) allocated by the support driver. */
|
---|
[14575] | 440 | MEMREF_TYPE_PAGE,
|
---|
[1] | 441 | /** Blow the type up to 32-bit and mark the end. */
|
---|
[35494] | 442 | MEMREF_TYPE_32BIT_HACK = 0x7fffffff
|
---|
[1] | 443 | } SUPDRVMEMREFTYPE, *PSUPDRVMEMREFTYPE;
|
---|
| 444 |
|
---|
| 445 |
|
---|
| 446 | /**
|
---|
| 447 | * Structure used for tracking memory a session
|
---|
| 448 | * references in one way or another.
|
---|
| 449 | */
|
---|
| 450 | typedef struct SUPDRVMEMREF
|
---|
| 451 | {
|
---|
| 452 | /** The memory object handle. */
|
---|
[14332] | 453 | RTR0MEMOBJ MemObj;
|
---|
[1] | 454 | /** The ring-3 mapping memory object handle. */
|
---|
[14332] | 455 | RTR0MEMOBJ MapObjR3;
|
---|
[1] | 456 | /** Type of memory. */
|
---|
[14332] | 457 | SUPDRVMEMREFTYPE eType;
|
---|
[1] | 458 | } SUPDRVMEMREF, *PSUPDRVMEMREF;
|
---|
| 459 |
|
---|
| 460 |
|
---|
| 461 | /**
|
---|
| 462 | * Bundle of locked memory ranges.
|
---|
| 463 | */
|
---|
| 464 | typedef struct SUPDRVBUNDLE
|
---|
| 465 | {
|
---|
| 466 | /** Pointer to the next bundle. */
|
---|
[14332] | 467 | struct SUPDRVBUNDLE * volatile pNext;
|
---|
[1] | 468 | /** Referenced memory. */
|
---|
[14332] | 469 | SUPDRVMEMREF aMem[64];
|
---|
[1] | 470 | /** Number of entries used. */
|
---|
| 471 | uint32_t volatile cUsed;
|
---|
| 472 | } SUPDRVBUNDLE, *PSUPDRVBUNDLE;
|
---|
| 473 |
|
---|
| 474 |
|
---|
| 475 | /**
|
---|
| 476 | * Loaded image.
|
---|
| 477 | */
|
---|
| 478 | typedef struct SUPDRVLDRIMAGE
|
---|
| 479 | {
|
---|
| 480 | /** Next in chain. */
|
---|
| 481 | struct SUPDRVLDRIMAGE * volatile pNext;
|
---|
| 482 | /** Pointer to the image. */
|
---|
[14332] | 483 | void *pvImage;
|
---|
[85507] | 484 | /** The memory object for the module allocation. */
|
---|
| 485 | RTR0MEMOBJ hMemObjImage;
|
---|
[80531] | 486 | /** Magic value (SUPDRVLDRIMAGE_MAGIC). */
|
---|
| 487 | uint32_t uMagic;
|
---|
[25258] | 488 | /** Size of the image including the tables. This is mainly for verification
|
---|
| 489 | * of the load request. */
|
---|
[85507] | 490 | uint32_t cbImageWithEverything;
|
---|
[25258] | 491 | /** Size of the image. */
|
---|
| 492 | uint32_t cbImageBits;
|
---|
| 493 | /** The number of entries in the symbol table. */
|
---|
| 494 | uint32_t cSymbols;
|
---|
| 495 | /** Pointer to the symbol table. */
|
---|
| 496 | PSUPLDRSYM paSymbols;
|
---|
| 497 | /** The offset of the string table. */
|
---|
| 498 | char *pachStrTab;
|
---|
| 499 | /** Size of the string table. */
|
---|
| 500 | uint32_t cbStrTab;
|
---|
[85507] | 501 | /** Number of segments. */
|
---|
| 502 | uint32_t cSegments;
|
---|
| 503 | /** Segments (for memory protection). */
|
---|
| 504 | PSUPLDRSEG paSegments;
|
---|
[1] | 505 | /** Pointer to the optional module initialization callback. */
|
---|
[14332] | 506 | PFNR0MODULEINIT pfnModuleInit;
|
---|
[1] | 507 | /** Pointer to the optional module termination callback. */
|
---|
[14332] | 508 | PFNR0MODULETERM pfnModuleTerm;
|
---|
| 509 | /** Service request handler. This is NULL for non-service modules. */
|
---|
| 510 | PFNSUPR0SERVICEREQHANDLER pfnServiceReqHandler;
|
---|
[33540] | 511 | /** The ldr image state. (IOCtl code of last operation.) */
|
---|
[14332] | 512 | uint32_t uState;
|
---|
[1] | 513 | /** Usage count. */
|
---|
[87700] | 514 | uint32_t volatile cImgUsage;
|
---|
[40636] | 515 | /** Pointer to the device extension. */
|
---|
| 516 | struct SUPDRVDEVEXT *pDevExt;
|
---|
[86512] | 517 | /** Image (VMMR0.r0) containing functions/data that this one uses. */
|
---|
| 518 | struct SUPDRVLDRIMAGE *pImageImport;
|
---|
[25278] | 519 | #ifdef RT_OS_WINDOWS
|
---|
[25262] | 520 | /** The section object for the loaded image (fNative=true). */
|
---|
| 521 | void *pvNtSectionObj;
|
---|
[25308] | 522 | /** Lock object. */
|
---|
| 523 | RTR0MEMOBJ hMemLock;
|
---|
[25278] | 524 | #endif
|
---|
[37228] | 525 | #if defined(RT_OS_SOLARIS) && defined(VBOX_WITH_NATIVE_SOLARIS_LOADING)
|
---|
| 526 | /** The Solaris module ID. */
|
---|
| 527 | int idSolMod;
|
---|
| 528 | /** Pointer to the module control structure. */
|
---|
| 529 | struct modctl *pSolModCtl;
|
---|
| 530 | #endif
|
---|
[58872] | 531 | #ifdef RT_OS_LINUX
|
---|
| 532 | /** Hack for seeing the module in perf, dtrace and other stack crawlers. */
|
---|
| 533 | struct module *pLnxModHack;
|
---|
[87700] | 534 | /** The wrapper module. */
|
---|
| 535 | struct module *pLnxWrapperModule;
|
---|
| 536 | /** Set if we're holding a reference to the wrapper module. */
|
---|
| 537 | bool fLnxWrapperRef;
|
---|
[58872] | 538 | #endif
|
---|
[75053] | 539 | #if defined(RT_OS_DARWIN) && defined(VBOX_WITH_DARWIN_R0_DARWIN_IMAGE_VERIFICATION)
|
---|
[75049] | 540 | /** Load module handle. */
|
---|
| 541 | RTLDRMOD hLdrMod;
|
---|
| 542 | /** Allocate object. */
|
---|
| 543 | RTR0MEMOBJ hMemAlloc;
|
---|
| 544 | #endif
|
---|
[87700] | 545 | /** This points to the module info if the image is a wrapped up in a native one. */
|
---|
| 546 | PCSUPLDRWRAPPEDMODULE pWrappedModInfo;
|
---|
| 547 | /** OS specific information for wrapped modules. */
|
---|
| 548 | void *pvWrappedNative;
|
---|
[25258] | 549 | /** Whether it's loaded by the native loader or not. */
|
---|
| 550 | bool fNative;
|
---|
[1] | 551 | /** Image name. */
|
---|
[14332] | 552 | char szName[32];
|
---|
[1] | 553 | } SUPDRVLDRIMAGE, *PSUPDRVLDRIMAGE;
|
---|
| 554 |
|
---|
[80531] | 555 | /** Magic value for SUPDRVLDRIMAGE::uMagic (Charlotte Bronte). */
|
---|
| 556 | #define SUPDRVLDRIMAGE_MAGIC UINT32_C(0x18160421)
|
---|
| 557 | /** Magic value for SUPDRVLDRIMAGE::uMagic when freed. */
|
---|
| 558 | #define SUPDRVLDRIMAGE_MAGIC_DEAD UINT32_C(0x18550331)
|
---|
[1] | 559 |
|
---|
[80531] | 560 |
|
---|
[1] | 561 | /** Image usage record. */
|
---|
| 562 | typedef struct SUPDRVLDRUSAGE
|
---|
| 563 | {
|
---|
| 564 | /** Next in chain. */
|
---|
| 565 | struct SUPDRVLDRUSAGE * volatile pNext;
|
---|
| 566 | /** The image. */
|
---|
[14332] | 567 | PSUPDRVLDRIMAGE pImage;
|
---|
[80531] | 568 | /** Load count (ring-3). */
|
---|
| 569 | uint32_t volatile cRing3Usage;
|
---|
| 570 | /** Ring-0 usage counter. */
|
---|
| 571 | uint32_t volatile cRing0Usage;
|
---|
[1] | 572 | } SUPDRVLDRUSAGE, *PSUPDRVLDRUSAGE;
|
---|
| 573 |
|
---|
| 574 |
|
---|
| 575 | /**
|
---|
[10377] | 576 | * Component factory registration record.
|
---|
| 577 | */
|
---|
| 578 | typedef struct SUPDRVFACTORYREG
|
---|
| 579 | {
|
---|
| 580 | /** Pointer to the next registration. */
|
---|
[14332] | 581 | struct SUPDRVFACTORYREG *pNext;
|
---|
[10377] | 582 | /** Pointer to the registered factory. */
|
---|
[14332] | 583 | PCSUPDRVFACTORY pFactory;
|
---|
[10377] | 584 | /** The session owning the factory.
|
---|
| 585 | * Used for deregistration and session cleanup. */
|
---|
[14332] | 586 | PSUPDRVSESSION pSession;
|
---|
[10377] | 587 | /** Length of the name. */
|
---|
[14332] | 588 | size_t cchName;
|
---|
[10377] | 589 | } SUPDRVFACTORYREG;
|
---|
| 590 | /** Pointer to a component factory registration record. */
|
---|
| 591 | typedef SUPDRVFACTORYREG *PSUPDRVFACTORYREG;
|
---|
| 592 | /** Pointer to a const component factory registration record. */
|
---|
| 593 | typedef SUPDRVFACTORYREG const *PCSUPDRVFACTORYREG;
|
---|
| 594 |
|
---|
| 595 |
|
---|
| 596 | /**
|
---|
[1] | 597 | * Registered object.
|
---|
| 598 | * This takes care of reference counting and tracking data for access checks.
|
---|
| 599 | */
|
---|
| 600 | typedef struct SUPDRVOBJ
|
---|
| 601 | {
|
---|
| 602 | /** Magic value (SUPDRVOBJ_MAGIC). */
|
---|
| 603 | uint32_t u32Magic;
|
---|
| 604 | /** The object type. */
|
---|
| 605 | SUPDRVOBJTYPE enmType;
|
---|
| 606 | /** Pointer to the next in the global list. */
|
---|
| 607 | struct SUPDRVOBJ * volatile pNext;
|
---|
[4971] | 608 | /** Pointer to the object destructor.
|
---|
| 609 | * This may be set to NULL if the image containing the destructor get unloaded. */
|
---|
[1] | 610 | PFNSUPDRVDESTRUCTOR pfnDestructor;
|
---|
| 611 | /** User argument 1. */
|
---|
| 612 | void *pvUser1;
|
---|
| 613 | /** User argument 2. */
|
---|
| 614 | void *pvUser2;
|
---|
| 615 | /** The total sum of all per-session usage. */
|
---|
| 616 | uint32_t volatile cUsage;
|
---|
| 617 | /** The creator user id. */
|
---|
| 618 | RTUID CreatorUid;
|
---|
| 619 | /** The creator group id. */
|
---|
| 620 | RTGID CreatorGid;
|
---|
| 621 | /** The creator process id. */
|
---|
| 622 | RTPROCESS CreatorProcess;
|
---|
| 623 | } SUPDRVOBJ, *PSUPDRVOBJ;
|
---|
| 624 |
|
---|
| 625 | /** Magic number for SUPDRVOBJ::u32Magic. (Dame Agatha Mary Clarissa Christie). */
|
---|
[45188] | 626 | #define SUPDRVOBJ_MAGIC UINT32_C(0x18900915)
|
---|
[15841] | 627 | /** Dead number magic for SUPDRVOBJ::u32Magic. */
|
---|
[45188] | 628 | #define SUPDRVOBJ_MAGIC_DEAD UINT32_C(0x19760112)
|
---|
[1] | 629 |
|
---|
| 630 | /**
|
---|
| 631 | * The per-session object usage record.
|
---|
| 632 | */
|
---|
| 633 | typedef struct SUPDRVUSAGE
|
---|
| 634 | {
|
---|
| 635 | /** Pointer to the next in the list. */
|
---|
| 636 | struct SUPDRVUSAGE * volatile pNext;
|
---|
| 637 | /** Pointer to the object we're recording usage for. */
|
---|
| 638 | PSUPDRVOBJ pObj;
|
---|
| 639 | /** The usage count. */
|
---|
| 640 | uint32_t volatile cUsage;
|
---|
| 641 | } SUPDRVUSAGE, *PSUPDRVUSAGE;
|
---|
| 642 |
|
---|
| 643 |
|
---|
| 644 | /**
|
---|
[71136] | 645 | * I/O control context.
|
---|
| 646 | */
|
---|
| 647 | typedef struct SUPR0IOCTLCTX
|
---|
| 648 | {
|
---|
| 649 | /** Magic value (SUPR0IOCTLCTX_MAGIC). */
|
---|
| 650 | uint32_t u32Magic;
|
---|
| 651 | /** Reference counter. */
|
---|
| 652 | uint32_t volatile cRefs;
|
---|
| 653 | #ifdef RT_OS_WINDOWS
|
---|
| 654 | # ifndef SUPDRV_AGNOSTIC
|
---|
| 655 | /** The file object, referenced. */
|
---|
| 656 | PFILE_OBJECT pFileObject;
|
---|
| 657 | /** The device object, not referenced. */
|
---|
| 658 | PDEVICE_OBJECT pDeviceObject;
|
---|
| 659 | /** Pointer to fast I/O routine if available. */
|
---|
| 660 | FAST_IO_DEVICE_CONTROL *pfnFastIoDeviceControl;
|
---|
| 661 | # else
|
---|
| 662 | void *apvPadding[3];
|
---|
| 663 | # endif
|
---|
| 664 | #endif
|
---|
| 665 | } SUPR0IOCTLCTX;
|
---|
| 666 | /** Magic value for SUPR0IOCTLCTX (Ahmad Jamal). */
|
---|
| 667 | #define SUPR0IOCTLCTX_MAGIC UINT32_C(0x19300702)
|
---|
| 668 |
|
---|
| 669 |
|
---|
| 670 | /**
|
---|
[1] | 671 | * Per session data.
|
---|
| 672 | * This is mainly for memory tracking.
|
---|
| 673 | */
|
---|
| 674 | typedef struct SUPDRVSESSION
|
---|
| 675 | {
|
---|
| 676 | /** Pointer to the device extension. */
|
---|
[14332] | 677 | PSUPDRVDEVEXT pDevExt;
|
---|
[1] | 678 | /** Session Cookie. */
|
---|
[14332] | 679 | uint32_t u32Cookie;
|
---|
[44173] | 680 | /** Set if is an unrestricted session, clear if restricted. */
|
---|
| 681 | bool fUnrestricted;
|
---|
[51770] | 682 |
|
---|
| 683 | /** Set if we're in the hash table, clear if not. Protected by the hash
|
---|
| 684 | * table spinlock. */
|
---|
| 685 | bool fInHashTable;
|
---|
| 686 | /** Reference counter. */
|
---|
[47537] | 687 | uint32_t volatile cRefs;
|
---|
[51770] | 688 | /** Pointer to the next session with the same hash (common hash table).
|
---|
| 689 | * Protected by the hash table spinlock. */
|
---|
| 690 | PSUPDRVSESSION pCommonNextHash;
|
---|
| 691 | /** Pointer to the OS specific session pointer, if available and in use.
|
---|
| 692 | * This is atomically set and cleared as the session is inserted and removed
|
---|
| 693 | * from the hash table (protected by the session hash table spinlock). */
|
---|
| 694 | PSUPDRVSESSION *ppOsSessionPtr;
|
---|
| 695 | /** The process (id) of the session. */
|
---|
| 696 | RTPROCESS Process;
|
---|
| 697 | /** Which process this session is associated with.
|
---|
| 698 | * This is NIL_RTR0PROCESS for kernel sessions and valid for user ones. */
|
---|
| 699 | RTR0PROCESS R0Process;
|
---|
[1] | 700 |
|
---|
[67955] | 701 | /** The GVM associated with the session.
|
---|
| 702 | * This is set by VMMR0. */
|
---|
| 703 | PGVM pSessionGVM;
|
---|
| 704 | /** The VM associated with the session.
|
---|
| 705 | * This is set by VMMR0. */
|
---|
| 706 | PVM pSessionVM;
|
---|
| 707 | /** Set to pSessionVM if fast I/O controlls are enabled. */
|
---|
| 708 | PVM pFastIoCtrlVM;
|
---|
[19866] | 709 | /** Handle table for IPRT semaphore wrapper APIs.
|
---|
[45188] | 710 | * This takes care of its own locking in an IRQ safe manner. */
|
---|
[19866] | 711 | RTHANDLETABLE hHandleTable;
|
---|
[86512] | 712 | /** Load usage records (LIFO!). (protected by SUPDRVDEVEXT::mtxLdr) */
|
---|
[14332] | 713 | PSUPDRVLDRUSAGE volatile pLdrUsage;
|
---|
[1] | 714 |
|
---|
[51770] | 715 | /** Spinlock protecting the bundles, the GIP members and the
|
---|
| 716 | * fProcessCleanupDone flag. It continues to be valid until the last
|
---|
| 717 | * reference to the session is released. */
|
---|
[14332] | 718 | RTSPINLOCK Spinlock;
|
---|
[1] | 719 | /** The ring-3 mapping of the GIP (readonly). */
|
---|
[14332] | 720 | RTR0MEMOBJ GipMapObjR3;
|
---|
[1] | 721 | /** Set if the session is using the GIP. */
|
---|
[14332] | 722 | uint32_t fGipReferenced;
|
---|
[1] | 723 | /** Bundle of locked memory objects. */
|
---|
[14332] | 724 | SUPDRVBUNDLE Bundle;
|
---|
[19866] | 725 | /** List of generic usage records. (protected by SUPDRVDEVEXT::SpinLock) */
|
---|
| 726 | PSUPDRVUSAGE volatile pUsage;
|
---|
[1] | 727 |
|
---|
[91551] | 728 | /** The user id of the session - set by the OS part or NIL_RTUID.
|
---|
| 729 | * This should be unique accross namespace/zones/whatever. */
|
---|
[14332] | 730 | RTUID Uid;
|
---|
[91551] | 731 | /** The group id of the session - set by the OS part or NIL_RTGID.
|
---|
| 732 | * This should be unique accross namespace/zones/whatever. */
|
---|
[14332] | 733 | RTGID Gid;
|
---|
[40759] | 734 | /** Per session tracer specfic data. */
|
---|
| 735 | uintptr_t uTracerData;
|
---|
[40819] | 736 | /** The thread currently actively talking to the tracer. (One at the time!) */
|
---|
| 737 | RTNATIVETHREAD hTracerCaller;
|
---|
[41117] | 738 | /** List of tracepoint providers associated with the session
|
---|
| 739 | * (SUPDRVTPPROVIDER). */
|
---|
| 740 | RTLISTANCHOR TpProviders;
|
---|
| 741 | /** The number of providers in TpProviders. */
|
---|
| 742 | uint32_t cTpProviders;
|
---|
| 743 | /** The number of threads active in supdrvIOCtl_TracerUmodProbeFire or
|
---|
| 744 | * SUPR0TracerUmodProbeFire. */
|
---|
| 745 | uint32_t volatile cTpProbesFiring;
|
---|
| 746 | /** User tracepoint modules (PSUPDRVTRACKERUMOD). */
|
---|
| 747 | RTLISTANCHOR TpUmods;
|
---|
| 748 | /** The user tracepoint module lookup table. */
|
---|
| 749 | struct SUPDRVTRACERUMOD *apTpLookupTable[32];
|
---|
[57218] | 750 | /** Whether this is a GIP test-mode client session or not. */
|
---|
| 751 | bool fGipTestMode;
|
---|
[23725] | 752 | #ifndef SUPDRV_AGNOSTIC
|
---|
| 753 | # if defined(RT_OS_DARWIN)
|
---|
[10836] | 754 | /** Pointer to the associated org_virtualbox_SupDrvClient object. */
|
---|
[14332] | 755 | void *pvSupDrvClient;
|
---|
[10836] | 756 | /** Whether this session has been opened or not. */
|
---|
[14332] | 757 | bool fOpened;
|
---|
[23725] | 758 | # endif
|
---|
| 759 | # if defined(RT_OS_OS2)
|
---|
[1193] | 760 | /** The system file number of this session. */
|
---|
[14332] | 761 | uint16_t sfn;
|
---|
| 762 | uint16_t Alignment; /**< Alignment */
|
---|
[23725] | 763 | # endif
|
---|
| 764 | # if defined(RT_OS_DARWIN) || defined(RT_OS_OS2) || defined(RT_OS_SOLARIS)
|
---|
[3189] | 765 | /** Pointer to the next session with the same hash. */
|
---|
[14332] | 766 | PSUPDRVSESSION pNextHash;
|
---|
[23725] | 767 | # endif
|
---|
[51770] | 768 | # if defined(RT_OS_WINDOWS) && defined(VBOX_WITH_HARDENING)
|
---|
| 769 | /** Pointer to the process protection structure for this session. */
|
---|
| 770 | struct SUPDRVNTPROTECT *pNtProtect;
|
---|
| 771 | # endif
|
---|
[91559] | 772 | # if defined(RT_OS_WINDOWS)
|
---|
| 773 | /** Reference to the user ID structure corresponding to the Uid member. */
|
---|
| 774 | struct SUPDRVNTUSERID *pNtUserId;
|
---|
| 775 | # endif
|
---|
[23725] | 776 | #endif /* !SUPDRV_AGNOSTIC */
|
---|
[1] | 777 | } SUPDRVSESSION;
|
---|
| 778 |
|
---|
| 779 |
|
---|
| 780 | /**
|
---|
| 781 | * Device extension.
|
---|
| 782 | */
|
---|
| 783 | typedef struct SUPDRVDEVEXT
|
---|
| 784 | {
|
---|
[44188] | 785 | /** Global cookie. */
|
---|
| 786 | uint32_t u32Cookie;
|
---|
| 787 | /** The actual size of SUPDRVSESSION. (SUPDRV_AGNOSTIC) */
|
---|
| 788 | uint32_t cbSession;
|
---|
| 789 |
|
---|
[45188] | 790 | /** Spinlock to serialize the initialization, usage counting and objects.
|
---|
| 791 | * This is IRQ safe because we want to be able signal semaphores from the
|
---|
| 792 | * special HM context (and later maybe interrupt handlers), so we must be able
|
---|
| 793 | * to reference and dereference handles when IRQs are disabled. */
|
---|
[14332] | 794 | RTSPINLOCK Spinlock;
|
---|
[1] | 795 |
|
---|
[4971] | 796 | /** List of registered objects. Protected by the spinlock. */
|
---|
[14332] | 797 | PSUPDRVOBJ volatile pObjs;
|
---|
[1] | 798 | /** List of free object usage records. */
|
---|
[14332] | 799 | PSUPDRVUSAGE volatile pUsageFree;
|
---|
[1] | 800 |
|
---|
| 801 | /** Loader mutex.
|
---|
| 802 | * This protects pvVMMR0, pvVMMR0Entry, pImages and SUPDRVSESSION::pLdrUsage. */
|
---|
[25307] | 803 | #ifdef SUPDRV_USE_MUTEX_FOR_LDR
|
---|
| 804 | RTSEMMUTEX mtxLdr;
|
---|
| 805 | #else
|
---|
[14332] | 806 | RTSEMFASTMUTEX mtxLdr;
|
---|
[25307] | 807 | #endif
|
---|
[1] | 808 |
|
---|
| 809 | /** VMM Module 'handle'.
|
---|
| 810 | * 0 if the code VMM isn't loaded and Idt are nops. */
|
---|
[14332] | 811 | void * volatile pvVMMR0;
|
---|
[4811] | 812 | /** VMMR0EntryFast() pointer. */
|
---|
[67955] | 813 | DECLR0CALLBACKMEMBER(void, pfnVMMR0EntryFast, (PGVM pGVM, PVM pVM, VMCPUID idCpu, uint32_t uOperation));
|
---|
[4811] | 814 | /** VMMR0EntryEx() pointer. */
|
---|
[67955] | 815 | DECLR0CALLBACKMEMBER(int, pfnVMMR0EntryEx, (PGVM pGVM, PVM pVM, VMCPUID idCpu, uint32_t uOperation,
|
---|
| 816 | PSUPVMMR0REQHDR pReq, uint64_t u64Arg, PSUPDRVSESSION pSession));
|
---|
[1] | 817 |
|
---|
| 818 | /** Linked list of loaded code. */
|
---|
[14332] | 819 | PSUPDRVLDRIMAGE volatile pLdrImages;
|
---|
[54013] | 820 | /** Set if the image loading interface got disabled after loading all needed images */
|
---|
| 821 | bool fLdrLockedDown;
|
---|
[1] | 822 |
|
---|
[40636] | 823 | /** @name These members for detecting whether an API caller is in ModuleInit.
|
---|
[40756] | 824 | * Certain APIs are only permitted from ModuleInit, like for instance tracepoint
|
---|
| 825 | * registration.
|
---|
[40636] | 826 | * @{ */
|
---|
| 827 | /** The image currently executing its ModuleInit. */
|
---|
| 828 | PSUPDRVLDRIMAGE volatile pLdrInitImage;
|
---|
| 829 | /** The thread currently executing a ModuleInit function. */
|
---|
| 830 | RTNATIVETHREAD volatile hLdrInitThread;
|
---|
[80531] | 831 | /** The thread currently executing a ModuleTerm function. */
|
---|
| 832 | RTNATIVETHREAD volatile hLdrTermThread;
|
---|
[40636] | 833 | /** @} */
|
---|
| 834 |
|
---|
[57229] | 835 | /** Number of times someone reported bad execution context via SUPR0BadContext.
|
---|
| 836 | * (This is times EFLAGS.AC is zero when we expected it to be 1.) */
|
---|
| 837 | uint32_t volatile cBadContextCalls;
|
---|
[40636] | 838 |
|
---|
[1] | 839 | /** GIP mutex.
|
---|
| 840 | * Any changes to any of the GIP members requires ownership of this mutex,
|
---|
| 841 | * except on driver init and termination. */
|
---|
[25461] | 842 | #ifdef SUPDRV_USE_MUTEX_FOR_GIP
|
---|
| 843 | RTSEMMUTEX mtxGip;
|
---|
| 844 | #else
|
---|
[14332] | 845 | RTSEMFASTMUTEX mtxGip;
|
---|
[25461] | 846 | #endif
|
---|
[45188] | 847 | /** GIP spinlock protecting GIP members during Mp events.
|
---|
| 848 | * This is IRQ safe since be may get MP callbacks in contexts where IRQs are
|
---|
| 849 | * disabled (on some platforms). */
|
---|
[40806] | 850 | RTSPINLOCK hGipSpinlock;
|
---|
[1] | 851 | /** Pointer to the Global Info Page (GIP). */
|
---|
[14332] | 852 | PSUPGLOBALINFOPAGE pGip;
|
---|
[1] | 853 | /** The physical address of the GIP. */
|
---|
[14332] | 854 | RTHCPHYS HCPhysGip;
|
---|
[1] | 855 | /** Number of processes using the GIP.
|
---|
| 856 | * (The updates are suspend while cGipUsers is 0.)*/
|
---|
[14332] | 857 | uint32_t volatile cGipUsers;
|
---|
[1] | 858 | /** The ring-0 memory object handle for the GIP page. */
|
---|
[14332] | 859 | RTR0MEMOBJ GipMemObj;
|
---|
[1] | 860 | /** The GIP timer handle. */
|
---|
[14332] | 861 | PRTTIMER pGipTimer;
|
---|
[1] | 862 | /** If non-zero we've successfully called RTTimerRequestSystemGranularity(). */
|
---|
[14332] | 863 | uint32_t u32SystemTimerGranularityGrant;
|
---|
[9470] | 864 | /** The CPU id of the GIP master.
|
---|
[54315] | 865 | * This CPU is responsible for the updating the common GIP data and it is
|
---|
| 866 | * the one used to calculate TSC deltas relative to.
|
---|
| 867 | * (The initial master will have a 0 zero value, but it it goes offline the
|
---|
| 868 | * new master may have a non-zero value.) */
|
---|
[14332] | 869 | RTCPUID volatile idGipMaster;
|
---|
[10377] | 870 |
|
---|
[23725] | 871 | /** Component factory mutex.
|
---|
| 872 | * This protects pComponentFactoryHead and component factory querying. */
|
---|
| 873 | RTSEMFASTMUTEX mtxComponentFactory;
|
---|
| 874 | /** The head of the list of registered component factories. */
|
---|
| 875 | PSUPDRVFACTORYREG pComponentFactoryHead;
|
---|
| 876 |
|
---|
[40756] | 877 | /** Lock protecting The tracer members. */
|
---|
| 878 | RTSEMFASTMUTEX mtxTracer;
|
---|
| 879 | /** List of tracer providers (SUPDRVTPPROVIDER). */
|
---|
| 880 | RTLISTANCHOR TracerProviderList;
|
---|
| 881 | /** List of zombie tracer providers (SUPDRVTPPROVIDER). */
|
---|
| 882 | RTLISTANCHOR TracerProviderZombieList;
|
---|
| 883 | /** Pointer to the tracer registration record. */
|
---|
| 884 | PCSUPDRVTRACERREG pTracerOps;
|
---|
| 885 | /** The ring-0 session of a native tracer provider. */
|
---|
| 886 | PSUPDRVSESSION pTracerSession;
|
---|
| 887 | /** The image containing the tracer. */
|
---|
| 888 | PSUPDRVLDRIMAGE pTracerImage;
|
---|
| 889 | /** The tracer helpers. */
|
---|
| 890 | SUPDRVTRACERHLP TracerHlp;
|
---|
[40819] | 891 | /** The number of session having opened the tracer currently. */
|
---|
| 892 | uint32_t cTracerOpens;
|
---|
[41117] | 893 | /** The number of threads currently calling into the tracer. */
|
---|
| 894 | uint32_t volatile cTracerCallers;
|
---|
[40756] | 895 | /** Set if the tracer is being unloaded. */
|
---|
| 896 | bool fTracerUnloading;
|
---|
[41117] | 897 | /** Hash table for user tracer modules (SUPDRVVTGCOPY). */
|
---|
| 898 | RTLISTANCHOR aTrackerUmodHash[128];
|
---|
[40756] | 899 |
|
---|
[51770] | 900 | /** @name Session Handle Table.
|
---|
| 901 | * @{ */
|
---|
| 902 | /** Spinlock protecting apSessionHashTab, cSessions,
|
---|
| 903 | * SUPDRVSESSION::ppOsSessionPtr, SUPDRVSESSION::pCommonNextHash, and possibly
|
---|
| 904 | * others depending on the OS. */
|
---|
| 905 | RTSPINLOCK hSessionHashTabSpinlock;
|
---|
| 906 | /** Session hash table hash table. The size of this table must make sense in
|
---|
| 907 | * comparison to GVMM_MAX_HANDLES. */
|
---|
| 908 | PSUPDRVSESSION apSessionHashTab[HC_ARCH_BITS == 64 ? 8191 : 127];
|
---|
| 909 | /** The number of open sessions. */
|
---|
| 910 | int32_t cSessions;
|
---|
| 911 | /** @} */
|
---|
| 912 |
|
---|
[54352] | 913 | /** @name Invariant TSC frequency refinement.
|
---|
| 914 | * @{ */
|
---|
| 915 | /** Nanosecond timestamp at the start of the TSC frequency refinement phase. */
|
---|
| 916 | uint64_t nsStartInvarTscRefine;
|
---|
| 917 | /** TSC reading at the start of the TSC frequency refinement phase. */
|
---|
| 918 | uint64_t uTscStartInvarTscRefine;
|
---|
| 919 | /** The CPU id of the CPU that u64TscAnchor was measured on. */
|
---|
| 920 | RTCPUID idCpuInvarTscRefine;
|
---|
| 921 | /** Pointer to the timer used to refine the TSC frequency. */
|
---|
| 922 | PRTTIMER pInvarTscRefineTimer;
|
---|
[54448] | 923 | /** Stop the timer on the next tick because we saw a power event. */
|
---|
| 924 | bool volatile fInvTscRefinePowerEvent;
|
---|
[54352] | 925 | /** @} */
|
---|
| 926 |
|
---|
[53054] | 927 | /** @name TSC-delta measurement.
|
---|
| 928 | * @{ */
|
---|
[54448] | 929 | /** Number of online/offline events, incremented each time a CPU goes online
|
---|
| 930 | * or offline. */
|
---|
| 931 | uint32_t volatile cMpOnOffEvents;
|
---|
[54375] | 932 | /** TSC-delta measurement mutext.
|
---|
| 933 | * At the moment, we don't want to have more than one measurement going on at
|
---|
| 934 | * any one time. We might be using broadcast IPIs which are heavy and could
|
---|
| 935 | * perhaps get in each others way. */
|
---|
| 936 | #ifdef SUPDRV_USE_MUTEX_FOR_GIP
|
---|
| 937 | RTSEMMUTEX mtxTscDelta;
|
---|
| 938 | #else
|
---|
| 939 | RTSEMFASTMUTEX mtxTscDelta;
|
---|
| 940 | #endif
|
---|
[54306] | 941 | /** The set of CPUs we need to take measurements for. */
|
---|
| 942 | RTCPUSET TscDeltaCpuSet;
|
---|
| 943 | /** The set of CPUs we have completed taken measurements for. */
|
---|
| 944 | RTCPUSET TscDeltaObtainedCpuSet;
|
---|
[53464] | 945 | /** @} */
|
---|
| 946 |
|
---|
| 947 | #ifdef SUPDRV_USE_TSC_DELTA_THREAD
|
---|
| 948 | /** @name TSC-delta measurement thread.
|
---|
| 949 | * @{ */
|
---|
[54290] | 950 | /** Spinlock protecting enmTscDeltaThreadState. */
|
---|
[53054] | 951 | RTSPINLOCK hTscDeltaSpinlock;
|
---|
| 952 | /** TSC-delta measurement thread. */
|
---|
| 953 | RTTHREAD hTscDeltaThread;
|
---|
| 954 | /** The event signalled during state changes to the TSC-delta thread. */
|
---|
| 955 | RTSEMEVENT hTscDeltaEvent;
|
---|
| 956 | /** The state of the TSC-delta measurement thread. */
|
---|
[54290] | 957 | SUPDRVTSCDELTATHREADSTATE enmTscDeltaThreadState;
|
---|
[53054] | 958 | /** Thread timeout time before rechecking state in ms. */
|
---|
| 959 | RTMSINTERVAL cMsTscDeltaTimeout;
|
---|
| 960 | /** Whether the TSC-delta measurement was successful. */
|
---|
[54262] | 961 | int32_t volatile rcTscDelta;
|
---|
[54578] | 962 | /** Tell the thread we want TSC-deltas for all CPUs with retries. */
|
---|
| 963 | bool fTscThreadRecomputeAllDeltas;
|
---|
[53054] | 964 | /** @} */
|
---|
| 965 | #endif
|
---|
| 966 |
|
---|
[57218] | 967 | /** @name GIP test mode.
|
---|
| 968 | * @{ */
|
---|
| 969 | /** Reference counter for GIP test-mode sessions. */
|
---|
[57224] | 970 | uint32_t cGipTestModeRefs;
|
---|
[57218] | 971 | /** Cache of TSC frequency before enabling test-mode on invariant GIP systems. */
|
---|
| 972 | uint64_t uGipTestModeInvariantCpuHz;
|
---|
| 973 | /** @} */
|
---|
| 974 |
|
---|
[40602] | 975 | /*
|
---|
[51770] | 976 | * Note! The non-agnostic bits must be at the very end of the structure!
|
---|
[40518] | 977 | */
|
---|
[23725] | 978 | #ifndef SUPDRV_AGNOSTIC
|
---|
| 979 | # ifdef RT_OS_WINDOWS
|
---|
[40518] | 980 | /** Callback object returned by ExCreateCallback. */
|
---|
[14332] | 981 | PCALLBACK_OBJECT pObjPowerCallback;
|
---|
[40518] | 982 | /** Callback handle returned by ExRegisterCallback. */
|
---|
[14332] | 983 | PVOID hPowerCallback;
|
---|
[75053] | 984 | # elif defined(RT_OS_DARWIN) && defined(VBOX_WITH_DARWIN_R0_DARWIN_IMAGE_VERIFICATION)
|
---|
[75052] | 985 | /** Trusted root certificates for code signing validation. */
|
---|
| 986 | RTCRSTORE hRootStore;
|
---|
| 987 | /** Intermedite certificates for code signing validation. */
|
---|
| 988 | RTCRSTORE hAdditionalStore;
|
---|
[23725] | 989 | # endif
|
---|
[13494] | 990 | #endif
|
---|
[1] | 991 | } SUPDRVDEVEXT;
|
---|
| 992 |
|
---|
[51770] | 993 | /** Calculates the index into g_apSessionHashTab.*/
|
---|
| 994 | #define SUPDRV_SESSION_HASH(a_pid) ( (a_pid) % RT_ELEMENTS(((SUPDRVDEVEXT *)NULL)->apSessionHashTab) )
|
---|
[1] | 995 |
|
---|
[51770] | 996 |
|
---|
[20374] | 997 | RT_C_DECLS_BEGIN
|
---|
[1] | 998 |
|
---|
| 999 | /*******************************************************************************
|
---|
| 1000 | * OS Specific Functions *
|
---|
| 1001 | *******************************************************************************/
|
---|
[51770] | 1002 | /**
|
---|
| 1003 | * Called to clean up the session structure before it's freed.
|
---|
| 1004 | *
|
---|
| 1005 | * @param pDevExt The device globals.
|
---|
| 1006 | * @param pSession The session that's being cleaned up.
|
---|
| 1007 | */
|
---|
| 1008 | void VBOXCALL supdrvOSCleanupSession(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession);
|
---|
| 1009 |
|
---|
| 1010 | /**
|
---|
| 1011 | * Called to let the OS specfic code perform additional insertion work while
|
---|
| 1012 | * still under the protection of the hash table spinlock.
|
---|
| 1013 | *
|
---|
| 1014 | * @param pDevExt The device globals.
|
---|
| 1015 | * @param pSession The session that was inserted.
|
---|
| 1016 | * @param pvUser User context specified to the insert call.
|
---|
| 1017 | */
|
---|
| 1018 | void VBOXCALL supdrvOSSessionHashTabInserted(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, void *pvUser);
|
---|
| 1019 |
|
---|
| 1020 | /**
|
---|
| 1021 | * Called to let the OS specfic code perform additional removal work while still
|
---|
| 1022 | * under the protection of the hash table spinlock.
|
---|
| 1023 | *
|
---|
| 1024 | * @param pDevExt The device globals.
|
---|
| 1025 | * @param pSession The session that was removed.
|
---|
| 1026 | * @param pvUser User context specified to the remove call.
|
---|
| 1027 | */
|
---|
| 1028 | void VBOXCALL supdrvOSSessionHashTabRemoved(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, void *pvUser);
|
---|
| 1029 |
|
---|
[64255] | 1030 | /**
|
---|
[64281] | 1031 | * Called during GIP initializtion to calc the CPU group table size.
|
---|
| 1032 | *
|
---|
| 1033 | * This is currently only implemented on windows [lazy bird].
|
---|
| 1034 | *
|
---|
| 1035 | * @returns Number of bytes needed for SUPGIPCPUGROUP structures.
|
---|
| 1036 | * @param pDevExt The device globals.
|
---|
| 1037 | */
|
---|
| 1038 | size_t VBOXCALL supdrvOSGipGetGroupTableSize(PSUPDRVDEVEXT pDevExt);
|
---|
| 1039 |
|
---|
| 1040 | /**
|
---|
[64255] | 1041 | * Called during GIP initialization to set up the group table and group count.
|
---|
| 1042 | *
|
---|
| 1043 | * This is currently only implemented on windows [lazy bird].
|
---|
| 1044 | *
|
---|
| 1045 | * @param pDevExt The device globals.
|
---|
| 1046 | * @param pGip The GIP which group table needs initialization.
|
---|
| 1047 | * It's only partially initialized at this point.
|
---|
[64281] | 1048 | * @param cbGipCpuGroups What supdrvOSGipGetGroupTableSize returned.
|
---|
[64255] | 1049 | */
|
---|
[64281] | 1050 | int VBOXCALL supdrvOSInitGipGroupTable(PSUPDRVDEVEXT pDevExt, PSUPGLOBALINFOPAGE pGip, size_t cbGipCpuGroups);
|
---|
[64255] | 1051 |
|
---|
| 1052 | /**
|
---|
[64281] | 1053 | * Initializes the group related members when a CPU is added to the GIP.
|
---|
[64255] | 1054 | *
|
---|
[64281] | 1055 | * This is called both during GIP initalization and during an CPU online event.
|
---|
| 1056 | *
|
---|
[64255] | 1057 | * This is currently only implemented on windows [lazy bird].
|
---|
| 1058 | *
|
---|
| 1059 | * @param pDevExt The device globals.
|
---|
[64284] | 1060 | * @param pGip The GIP.
|
---|
| 1061 | * @param pGipCpu The GIP CPU structure being initialized.
|
---|
[64255] | 1062 | */
|
---|
[64281] | 1063 | void VBOXCALL supdrvOSGipInitGroupBitsForCpu(PSUPDRVDEVEXT pDevExt, PSUPGLOBALINFOPAGE pGip, PSUPGIPCPU pGipCpu);
|
---|
[64255] | 1064 |
|
---|
[1] | 1065 | void VBOXCALL supdrvOSObjInitCreator(PSUPDRVOBJ pObj, PSUPDRVSESSION pSession);
|
---|
| 1066 | bool VBOXCALL supdrvOSObjCanAccess(PSUPDRVOBJ pObj, PSUPDRVSESSION pSession, const char *pszObjName, int *prc);
|
---|
[8789] | 1067 | bool VBOXCALL supdrvOSGetForcedAsyncTscMode(PSUPDRVDEVEXT pDevExt);
|
---|
[54581] | 1068 | bool VBOXCALL supdrvOSAreCpusOfflinedOnSuspend(void);
|
---|
[53396] | 1069 | bool VBOXCALL supdrvOSAreTscDeltasInSync(void);
|
---|
[14901] | 1070 | int VBOXCALL supdrvOSEnableVTx(bool fEnabled);
|
---|
[54650] | 1071 | RTCCUINTREG VBOXCALL supdrvOSChangeCR4(RTCCUINTREG fOrMask, RTCCUINTREG fAndMask);
|
---|
[43379] | 1072 | bool VBOXCALL supdrvOSSuspendVTxOnCpu(void);
|
---|
| 1073 | void VBOXCALL supdrvOSResumeVTxOnCpu(bool fSuspended);
|
---|
[67137] | 1074 | int VBOXCALL supdrvOSGetCurrentGdtRw(RTHCUINTPTR *pGdtRw);
|
---|
[1] | 1075 |
|
---|
[25258] | 1076 | /**
|
---|
| 1077 | * Try open the image using the native loader.
|
---|
| 1078 | *
|
---|
| 1079 | * @returns IPRT status code.
|
---|
| 1080 | * @retval VERR_NOT_SUPPORTED if native loading isn't supported.
|
---|
| 1081 | *
|
---|
| 1082 | * @param pDevExt The device globals.
|
---|
| 1083 | * @param pImage The image handle. pvImage should be set on
|
---|
| 1084 | * success, pvImageAlloc can also be set if
|
---|
| 1085 | * appropriate.
|
---|
[33540] | 1086 | * @param pszFilename The file name - UTF-8, may containing UNIX
|
---|
[25258] | 1087 | * slashes on non-UNIX systems.
|
---|
| 1088 | */
|
---|
| 1089 | int VBOXCALL supdrvOSLdrOpen(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, const char *pszFilename);
|
---|
| 1090 |
|
---|
| 1091 | /**
|
---|
[41067] | 1092 | * Notification call indicating that a image is being opened for the first time.
|
---|
| 1093 | *
|
---|
[58872] | 1094 | * Called for both native and non-native images (after supdrvOSLdrOpen). Can be
|
---|
| 1095 | * used to log the load address of the image or inform the kernel about the
|
---|
| 1096 | * alien image.
|
---|
[41067] | 1097 | *
|
---|
| 1098 | * @param pDevExt The device globals.
|
---|
| 1099 | * @param pImage The image handle.
|
---|
[58872] | 1100 | * @param pszFilename The file name - UTF-8, may containing UNIX
|
---|
| 1101 | * slashes on non-UNIX systems.
|
---|
[41067] | 1102 | */
|
---|
[58872] | 1103 | void VBOXCALL supdrvOSLdrNotifyOpened(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, const char *pszFilename);
|
---|
[41067] | 1104 |
|
---|
| 1105 | /**
|
---|
[25258] | 1106 | * Validates an entry point address.
|
---|
| 1107 | *
|
---|
| 1108 | * Called before supdrvOSLdrLoad.
|
---|
| 1109 | *
|
---|
| 1110 | * @returns IPRT status code.
|
---|
| 1111 | * @param pDevExt The device globals.
|
---|
| 1112 | * @param pImage The image data (still in the open state).
|
---|
| 1113 | * @param pv The address within the image.
|
---|
| 1114 | * @param pbImageBits The image bits as loaded by ring-3.
|
---|
[75003] | 1115 | * @param pszSymbol The name of the entrypoint being checked.
|
---|
[25258] | 1116 | */
|
---|
| 1117 | int VBOXCALL supdrvOSLdrValidatePointer(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage,
|
---|
[75003] | 1118 | void *pv, const uint8_t *pbImageBits, const char *pszSymbol);
|
---|
[25258] | 1119 |
|
---|
| 1120 | /**
|
---|
| 1121 | * Load the image.
|
---|
| 1122 | *
|
---|
| 1123 | * @returns IPRT status code.
|
---|
| 1124 | * @param pDevExt The device globals.
|
---|
[37249] | 1125 | * @param pImage The image data (up to date). Adjust entrypoints
|
---|
| 1126 | * and exports if necessary.
|
---|
[25258] | 1127 | * @param pbImageBits The image bits as loaded by ring-3.
|
---|
[37249] | 1128 | * @param pReq Pointer to the request packet so that the VMMR0
|
---|
| 1129 | * entry points can be adjusted.
|
---|
[25258] | 1130 | */
|
---|
[37249] | 1131 | int VBOXCALL supdrvOSLdrLoad(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, const uint8_t *pbImageBits, PSUPLDRLOAD pReq);
|
---|
[25258] | 1132 |
|
---|
| 1133 | /**
|
---|
[58872] | 1134 | * Unload the image (only called if supdrvOSLdrOpen returned success).
|
---|
[25258] | 1135 | *
|
---|
| 1136 | * @param pDevExt The device globals.
|
---|
| 1137 | * @param pImage The image data (mostly still valid).
|
---|
| 1138 | */
|
---|
| 1139 | void VBOXCALL supdrvOSLdrUnload(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage);
|
---|
| 1140 |
|
---|
[58872] | 1141 | /**
|
---|
| 1142 | * Notification call indicating that a image is being unloaded.
|
---|
| 1143 | *
|
---|
| 1144 | * Called for both native and non-native images. In the former case, it's
|
---|
| 1145 | * called after supdrvOSLdrUnload.
|
---|
| 1146 | *
|
---|
| 1147 | * @param pDevExt The device globals.
|
---|
| 1148 | * @param pImage The image handle.
|
---|
| 1149 | */
|
---|
| 1150 | void VBOXCALL supdrvOSLdrNotifyUnloaded(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage);
|
---|
[25258] | 1151 |
|
---|
[75282] | 1152 | /**
|
---|
| 1153 | * Queries a symbol address is a native module.
|
---|
| 1154 | *
|
---|
| 1155 | * @returns IPRT status code.
|
---|
| 1156 | * @param pDevExt The device globals.
|
---|
| 1157 | * @param pImage The image to search.
|
---|
| 1158 | * @param pszSymbol The symbol to search for.
|
---|
| 1159 | * @param cchSymbol The length of the symbol.
|
---|
| 1160 | * @param ppvSymbol Where to return the symbol address if found.
|
---|
| 1161 | */
|
---|
| 1162 | int VBOXCALL supdrvOSLdrQuerySymbol(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage,
|
---|
| 1163 | const char *pszSymbol, size_t cchSymbol, void **ppvSymbol);
|
---|
[58872] | 1164 |
|
---|
[87700] | 1165 | /**
|
---|
| 1166 | * Retains a native wrapper module when it is first being used.
|
---|
| 1167 | *
|
---|
| 1168 | * This will be call when pImage->cImgUsage is incremented to 2.
|
---|
| 1169 | *
|
---|
| 1170 | * @param pDevExt The device globals.
|
---|
| 1171 | * @param pImage The wrapped image.
|
---|
| 1172 | */
|
---|
| 1173 | void VBOXCALL supdrvOSLdrRetainWrapperModule(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage);
|
---|
[75282] | 1174 |
|
---|
[87700] | 1175 | /**
|
---|
| 1176 | * Release a native wrapper module when it is no longer being used.
|
---|
| 1177 | *
|
---|
| 1178 | * This will be call when pImage->cImgUsage is decremented to 1.
|
---|
| 1179 | *
|
---|
| 1180 | * @param pDevExt The device globals.
|
---|
| 1181 | * @param pImage The wrapped image.
|
---|
| 1182 | */
|
---|
| 1183 | void VBOXCALL supdrvOSLdrReleaseWrapperModule(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage);
|
---|
| 1184 |
|
---|
[49634] | 1185 | #ifdef SUPDRV_WITH_MSR_PROBER
|
---|
| 1186 |
|
---|
| 1187 | /**
|
---|
| 1188 | * Tries to read an MSR.
|
---|
| 1189 | *
|
---|
| 1190 | * @returns One of the listed VBox status codes.
|
---|
| 1191 | * @retval VINF_SUCCESS if read successfully, value in *puValue.
|
---|
| 1192 | * @retval VERR_ACCESS_DENIED if we couldn't read it (GP).
|
---|
| 1193 | * @retval VERR_NOT_SUPPORTED if not supported.
|
---|
| 1194 | *
|
---|
| 1195 | * @param uMsr The MSR to read from.
|
---|
| 1196 | * @param idCpu The CPU to read the MSR on. NIL_RTCPUID
|
---|
| 1197 | * indicates any suitable CPU.
|
---|
| 1198 | * @param puValue Where to return the value.
|
---|
| 1199 | */
|
---|
| 1200 | int VBOXCALL supdrvOSMsrProberRead(uint32_t uMsr, RTCPUID idCpu, uint64_t *puValue);
|
---|
| 1201 |
|
---|
| 1202 | /**
|
---|
| 1203 | * Tries to write an MSR.
|
---|
| 1204 | *
|
---|
| 1205 | * @returns One of the listed VBox status codes.
|
---|
| 1206 | * @retval VINF_SUCCESS if written successfully.
|
---|
| 1207 | * @retval VERR_ACCESS_DENIED if we couldn't write the value to it (GP).
|
---|
| 1208 | * @retval VERR_NOT_SUPPORTED if not supported.
|
---|
| 1209 | *
|
---|
| 1210 | * @param uMsr The MSR to write to.
|
---|
| 1211 | * @param idCpu The CPU to write the MSR on. NIL_RTCPUID
|
---|
| 1212 | * indicates any suitable CPU.
|
---|
| 1213 | * @param uValue The value to write.
|
---|
| 1214 | */
|
---|
| 1215 | int VBOXCALL supdrvOSMsrProberWrite(uint32_t uMsr, RTCPUID idCpu, uint64_t uValue);
|
---|
| 1216 |
|
---|
| 1217 | /**
|
---|
| 1218 | * Tries to modify an MSR value.
|
---|
| 1219 | *
|
---|
| 1220 | * @returns One of the listed VBox status codes.
|
---|
| 1221 | * @retval VINF_SUCCESS if succeeded.
|
---|
| 1222 | * @retval VERR_NOT_SUPPORTED if not supported.
|
---|
| 1223 | *
|
---|
| 1224 | * @param idCpu The CPU to modify the MSR on. NIL_RTCPUID
|
---|
| 1225 | * indicates any suitable CPU.
|
---|
| 1226 | * @param pReq The request packet with input arguments and
|
---|
| 1227 | * where to store the results.
|
---|
| 1228 | */
|
---|
| 1229 | int VBOXCALL supdrvOSMsrProberModify(RTCPUID idCpu, PSUPMSRPROBER pReq);
|
---|
| 1230 |
|
---|
| 1231 | #endif /* SUPDRV_WITH_MSR_PROBER */
|
---|
| 1232 |
|
---|
[49787] | 1233 | #if defined(RT_OS_DARWIN)
|
---|
[49965] | 1234 | int VBOXCALL supdrvDarwinResumeSuspendedKbds(void);
|
---|
[49787] | 1235 | #endif
|
---|
[49634] | 1236 |
|
---|
[85174] | 1237 |
|
---|
| 1238 | /*********************************************************************************************************************************
|
---|
| 1239 | * Shared Functions *
|
---|
| 1240 | *********************************************************************************************************************************/
|
---|
[23725] | 1241 | /* SUPDrv.c */
|
---|
[52575] | 1242 | int VBOXCALL supdrvIOCtl(uintptr_t uIOCtl, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPREQHDR pReqHdr, size_t cbReq);
|
---|
[71198] | 1243 | int VBOXCALL supdrvIOCtlFast(uintptr_t uOperation, VMCPUID idCpu, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession);
|
---|
[10263] | 1244 | int VBOXCALL supdrvIDC(uintptr_t uIOCtl, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPDRVIDCREQHDR pReqHdr);
|
---|
[25484] | 1245 | int VBOXCALL supdrvInitDevExt(PSUPDRVDEVEXT pDevExt, size_t cbSession);
|
---|
[4800] | 1246 | void VBOXCALL supdrvDeleteDevExt(PSUPDRVDEVEXT pDevExt);
|
---|
[44173] | 1247 | int VBOXCALL supdrvCreateSession(PSUPDRVDEVEXT pDevExt, bool fUser, bool fUnrestricted, PSUPDRVSESSION *ppSession);
|
---|
[51770] | 1248 | int VBOXCALL supdrvSessionHashTabInsert(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPDRVSESSION *ppOsSessionPtr, void *pvUser);
|
---|
| 1249 | int VBOXCALL supdrvSessionHashTabRemove(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, void *pvUser);
|
---|
| 1250 | PSUPDRVSESSION VBOXCALL supdrvSessionHashTabLookup(PSUPDRVDEVEXT pDevExt, RTPROCESS Process, RTR0PROCESS R0Process,
|
---|
| 1251 | PSUPDRVSESSION *ppOsSessionPtr);
|
---|
[47537] | 1252 | uint32_t VBOXCALL supdrvSessionRetain(PSUPDRVSESSION pSession);
|
---|
| 1253 | uint32_t VBOXCALL supdrvSessionRelease(PSUPDRVSESSION pSession);
|
---|
[57229] | 1254 | void VBOXCALL supdrvBadContext(PSUPDRVDEVEXT pDevExt, const char *pszFile, uint32_t uLine, const char *pszExtra);
|
---|
[56558] | 1255 | int VBOXCALL supdrvQueryVTCapsInternal(uint32_t *pfCaps);
|
---|
[57378] | 1256 | int VBOXCALL supdrvLdrLoadError(int rc, PSUPLDRLOAD pReq, const char *pszFormat, ...);
|
---|
[75049] | 1257 | int VBOXCALL supdrvLdrGetExportedSymbol(const char *pszSymbol, uintptr_t *puValue);
|
---|
[87700] | 1258 | int VBOXCALL supdrvLdrRegisterWrappedModule(PSUPDRVDEVEXT pDevExt, PCSUPLDRWRAPPEDMODULE pWrappedModInfo,
|
---|
| 1259 | void *pvNative, void **phMod);
|
---|
| 1260 | int VBOXCALL supdrvLdrDeregisterWrappedModule(PSUPDRVDEVEXT pDevExt, PCSUPLDRWRAPPEDMODULE pWrappedModInfo, void **phMod);
|
---|
[1] | 1261 |
|
---|
[87700] | 1262 |
|
---|
[54327] | 1263 | /* SUPDrvGip.cpp */
|
---|
| 1264 | int VBOXCALL supdrvGipCreate(PSUPDRVDEVEXT pDevExt);
|
---|
| 1265 | void VBOXCALL supdrvGipDestroy(PSUPDRVDEVEXT pDevExt);
|
---|
| 1266 | int VBOXCALL supdrvIOCtl_TscDeltaMeasure(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPTSCDELTAMEASURE pReq);
|
---|
| 1267 | int VBOXCALL supdrvIOCtl_TscRead(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPTSCREAD pReq);
|
---|
[57218] | 1268 | int VBOXCALL supdrvIOCtl_GipSetFlags(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, uint32_t fOrMask, uint32_t fAndMask);
|
---|
[54327] | 1269 |
|
---|
[57218] | 1270 |
|
---|
[54327] | 1271 | /* SUPDrvTracer.cpp */
|
---|
[40756] | 1272 | int VBOXCALL supdrvTracerInit(PSUPDRVDEVEXT pDevExt);
|
---|
| 1273 | void VBOXCALL supdrvTracerTerm(PSUPDRVDEVEXT pDevExt);
|
---|
| 1274 | void VBOXCALL supdrvTracerModuleUnloading(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage);
|
---|
| 1275 | void VBOXCALL supdrvTracerCleanupSession(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession);
|
---|
[41117] | 1276 | int VBOXCALL supdrvIOCtl_TracerUmodRegister(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession,
|
---|
| 1277 | RTR3PTR R3PtrVtgHdr, RTUINTPTR uVtgHdrAddr,
|
---|
| 1278 | RTR3PTR R3PtrStrTab, uint32_t cbStrTab,
|
---|
| 1279 | const char *pszModName, uint32_t fFlags);
|
---|
| 1280 | int VBOXCALL supdrvIOCtl_TracerUmodDeregister(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, RTR3PTR R3PtrVtgHdr);
|
---|
| 1281 | void VBOXCALL supdrvIOCtl_TracerUmodProbeFire(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPDRVTRACERUSRCTX pCtx);
|
---|
[40819] | 1282 | int VBOXCALL supdrvIOCtl_TracerOpen(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, uint32_t uCookie, uintptr_t uArg);
|
---|
| 1283 | int VBOXCALL supdrvIOCtl_TracerClose(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession);
|
---|
| 1284 | int VBOXCALL supdrvIOCtl_TracerIOCtl(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, uintptr_t uCmd, uintptr_t uArg, int32_t *piRetVal);
|
---|
[40777] | 1285 | extern PFNRT g_pfnSupdrvProbeFireKernel;
|
---|
| 1286 | DECLASM(void) supdrvTracerProbeFireStub(void);
|
---|
[40611] | 1287 |
|
---|
[40975] | 1288 | #ifdef VBOX_WITH_NATIVE_DTRACE
|
---|
[40851] | 1289 | const SUPDRVTRACERREG * VBOXCALL supdrvDTraceInit(void);
|
---|
[85766] | 1290 | void VBOXCALL supdrvDTraceFini(void);
|
---|
[40851] | 1291 | #endif
|
---|
[40756] | 1292 |
|
---|
[20374] | 1293 | RT_C_DECLS_END
|
---|
[1] | 1294 |
|
---|
[76568] | 1295 | #endif /* !VBOX_INCLUDED_SRC_Support_SUPDrvInternal_h */
|
---|
[1] | 1296 |
|
---|