VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/Support/SUPDrvInternal.h@ 98110

Last change on this file since 98110 was 98103, checked in by vboxsync, 23 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 50.8 KB
Line 
1/* $Id: SUPDrvInternal.h 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * VirtualBox Support Driver - Internal header.
4 */
5
6/*
7 * Copyright (C) 2006-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
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 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
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
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.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37#ifndef VBOX_INCLUDED_SRC_Support_SUPDrvInternal_h
38#define VBOX_INCLUDED_SRC_Support_SUPDrvInternal_h
39#ifndef RT_WITHOUT_PRAGMA_ONCE
40# pragma once
41#endif
42
43
44/*********************************************************************************************************************************
45* Header Files *
46*********************************************************************************************************************************/
47#include <VBox/cdefs.h>
48#include <VBox/types.h>
49#include <VBox/sup.h>
50
51#include <iprt/assert.h>
52#include <iprt/list.h>
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>
58
59#if defined(SUPDRV_AGNOSTIC) && !defined(RT_OS_LINUX)
60/* do nothing */
61
62#elif defined(RT_OS_WINDOWS)
63# include <iprt/nt/nt.h>
64# include <memory.h>
65
66#elif defined(RT_OS_LINUX)
67# include <iprt/linux/version.h>
68# if RTLNX_VER_MIN(2,6,33)
69# include <generated/autoconf.h>
70# else
71# ifndef AUTOCONF_INCLUDED
72# include <linux/autoconf.h>
73# endif
74# endif
75# if defined(CONFIG_MODVERSIONS) && !defined(MODVERSIONS)
76# define MODVERSIONS
77# if RTLNX_VER_MAX(2,5,71)
78# include <linux/modversions.h>
79# endif
80# endif
81# ifndef KBUILD_STR
82# if RTLNX_VER_MAX(2,6,16)
83# define KBUILD_STR(s) s
84# else
85# define KBUILD_STR(s) #s
86# endif
87# endif
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
99# if RTLNX_VER_MIN(3,2,0)
100# include <linux/export.h>
101# else
102# include <linux/module.h>
103# if (defined(RT_ARCH_X86) || defined(RT_ARCH_AMD64)) && defined(SUPDRV_AGNOSTIC) /* fix conflicts with iprt/x86.h */
104# undef CS
105# undef DS
106# undef ES
107# undef FS
108# undef GS
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
244# endif
245# define SUPR0_EXPORT_SYMBOL(a_Name) EXPORT_SYMBOL(a_Name)
246
247#elif defined(RT_OS_DARWIN)
248# include <libkern/libkern.h>
249# include <iprt/string.h>
250
251#elif defined(RT_OS_OS2)
252
253#elif defined(RT_OS_FREEBSD)
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
261# include <sys/libkern.h>
262# undef memset
263# undef memcmp
264# undef strchr
265# undef strrchr
266# undef ffs
267# undef ffsl
268# undef fls
269# undef flsl
270# include <iprt/string.h>
271
272#elif defined(RT_OS_SOLARIS)
273# include <sys/cmn_err.h>
274# include <iprt/string.h>
275
276#else
277# error "unsupported OS."
278#endif
279
280#include "SUPDrvIOC.h"
281#include "SUPDrvIDC.h"
282
283
284
285/*********************************************************************************************************************************
286* Defined Constants And Macros *
287*********************************************************************************************************************************/
288/*
289 * Hardcoded cookies.
290 */
291#define BIRD 0x64726962 /* 'bird' */
292#define BIRD_INV 0x62697264 /* 'drib' */
293
294
295#ifdef RT_OS_WINDOWS
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
300
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
305#endif
306
307#ifndef SUPR0_EXPORT_SYMBOL
308# define SUPR0_EXPORT_SYMBOL(a_Name) extern int g_supDrvExportSymbolDummyVariable
309#endif
310
311/**
312 * OS debug print macro.
313 */
314#define OSDBGPRINT(a) SUPR0Printf a
315
316
317/** @name Context values for the per-session handle tables.
318 * The context value is used to distinguish between the different kinds of
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/** @} */
326
327
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) \
335 ( RT_VALID_PTR(pSession) \
336 && pSession->u32Cookie == BIRD_INV)
337
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) \
345 ( RT_VALID_PTR(pDevExt) \
346 && pDevExt->u32Cookie == BIRD)
347
348
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
364#ifdef DOXYGEN_RUNNING
365# define SUPDRV_WITH_MSR_PROBER
366# define SUPDRV_WITHOUT_MSR_PROBER
367#endif
368
369#if 1
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
374#endif
375
376
377/*********************************************************************************************************************************
378* Structures and Typedefs *
379*********************************************************************************************************************************/
380/** Pointer to the device extension. */
381typedef struct SUPDRVDEVEXT *PSUPDRVDEVEXT;
382
383#ifdef SUPDRV_USE_TSC_DELTA_THREAD
384/**
385 * TSC-delta measurement thread state machine.
386 */
387typedef enum SUPDRVTSCDELTATHREADSTATE
388{
389 /** Uninitialized/invalid value. */
390 kTscDeltaThreadState_Invalid = 0,
391 /** The thread is being created.
392 * Next state: Listening, Butchered, Terminating */
393 kTscDeltaThreadState_Creating,
394 /** The thread is listening for events.
395 * Previous state: Creating, Measuring
396 * Next state: WaitAndMeasure, Butchered, Terminated */
397 kTscDeltaThreadState_Listening,
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. */
404 kTscDeltaThreadState_WaitAndMeasure,
405 /** The thread is currently servicing a measurement request.
406 * Previous state: WaitAndMeasure
407 * Next state: Listening, WaitAndMeasure, Terminate */
408 kTscDeltaThreadState_Measuring,
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. */
412 kTscDeltaThreadState_Terminating,
413 /** The thread is butchered due to an unexpected error.
414 * Previous State: Creating, Listening, WaitAndMeasure */
415 kTscDeltaThreadState_Butchered,
416 /** The thread is destroyed (final).
417 * Previous state: Terminating */
418 kTscDeltaThreadState_Destroyed,
419 /** The usual 32-bit blowup hack. */
420 kTscDeltaThreadState_32BitHack = 0x7fffffff
421} SUPDRVTSCDELTATHREADSTATE;
422#endif /* SUPDRV_USE_TSC_DELTA_THREAD */
423
424/**
425 * Memory reference types.
426 */
427typedef enum
428{
429 /** Unused entry */
430 MEMREF_TYPE_UNUSED = 0,
431 /** Locked memory (r3 mapping only). */
432 MEMREF_TYPE_LOCKED,
433 /** Continuous memory block (r3 and r0 mapping). */
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,
439 /** Locked memory (r3 mapping only) allocated by the support driver. */
440 MEMREF_TYPE_PAGE,
441 /** Blow the type up to 32-bit and mark the end. */
442 MEMREF_TYPE_32BIT_HACK = 0x7fffffff
443} SUPDRVMEMREFTYPE, *PSUPDRVMEMREFTYPE;
444
445
446/**
447 * Structure used for tracking memory a session
448 * references in one way or another.
449 */
450typedef struct SUPDRVMEMREF
451{
452 /** The memory object handle. */
453 RTR0MEMOBJ MemObj;
454 /** The ring-3 mapping memory object handle. */
455 RTR0MEMOBJ MapObjR3;
456 /** Type of memory. */
457 SUPDRVMEMREFTYPE eType;
458} SUPDRVMEMREF, *PSUPDRVMEMREF;
459
460
461/**
462 * Bundle of locked memory ranges.
463 */
464typedef struct SUPDRVBUNDLE
465{
466 /** Pointer to the next bundle. */
467 struct SUPDRVBUNDLE * volatile pNext;
468 /** Referenced memory. */
469 SUPDRVMEMREF aMem[64];
470 /** Number of entries used. */
471 uint32_t volatile cUsed;
472} SUPDRVBUNDLE, *PSUPDRVBUNDLE;
473
474
475/**
476 * Loaded image.
477 */
478typedef struct SUPDRVLDRIMAGE
479{
480 /** Next in chain. */
481 struct SUPDRVLDRIMAGE * volatile pNext;
482 /** Pointer to the image. */
483 void *pvImage;
484 /** The memory object for the module allocation. */
485 RTR0MEMOBJ hMemObjImage;
486 /** Magic value (SUPDRVLDRIMAGE_MAGIC). */
487 uint32_t uMagic;
488 /** Size of the image including the tables. This is mainly for verification
489 * of the load request. */
490 uint32_t cbImageWithEverything;
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;
501 /** Number of segments. */
502 uint32_t cSegments;
503 /** Segments (for memory protection). */
504 PSUPLDRSEG paSegments;
505 /** Pointer to the optional module initialization callback. */
506 PFNR0MODULEINIT pfnModuleInit;
507 /** Pointer to the optional module termination callback. */
508 PFNR0MODULETERM pfnModuleTerm;
509 /** Service request handler. This is NULL for non-service modules. */
510 PFNSUPR0SERVICEREQHANDLER pfnServiceReqHandler;
511 /** The ldr image state. (IOCtl code of last operation.) */
512 uint32_t uState;
513 /** Usage count. */
514 uint32_t volatile cImgUsage;
515 /** Pointer to the device extension. */
516 struct SUPDRVDEVEXT *pDevExt;
517 /** Image (VMMR0.r0) containing functions/data that this one uses. */
518 struct SUPDRVLDRIMAGE *pImageImport;
519#ifdef RT_OS_WINDOWS
520 /** The section object for the loaded image (fNative=true). */
521 void *pvNtSectionObj;
522 /** Lock object. */
523 RTR0MEMOBJ hMemLock;
524#endif
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
531#ifdef RT_OS_LINUX
532 /** Hack for seeing the module in perf, dtrace and other stack crawlers. */
533 struct module *pLnxModHack;
534 /** The wrapper module. */
535 struct module *pLnxWrapperModule;
536 /** Set if we're holding a reference to the wrapper module. */
537 bool fLnxWrapperRef;
538#endif
539#if defined(RT_OS_DARWIN) && defined(VBOX_WITH_DARWIN_R0_DARWIN_IMAGE_VERIFICATION)
540 /** Load module handle. */
541 RTLDRMOD hLdrMod;
542 /** Allocate object. */
543 RTR0MEMOBJ hMemAlloc;
544#endif
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;
549 /** Whether it's loaded by the native loader or not. */
550 bool fNative;
551 /** Image name. */
552 char szName[32];
553} SUPDRVLDRIMAGE, *PSUPDRVLDRIMAGE;
554
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)
559
560
561/** Image usage record. */
562typedef struct SUPDRVLDRUSAGE
563{
564 /** Next in chain. */
565 struct SUPDRVLDRUSAGE * volatile pNext;
566 /** The image. */
567 PSUPDRVLDRIMAGE pImage;
568 /** Load count (ring-3). */
569 uint32_t volatile cRing3Usage;
570 /** Ring-0 usage counter. */
571 uint32_t volatile cRing0Usage;
572} SUPDRVLDRUSAGE, *PSUPDRVLDRUSAGE;
573
574
575/**
576 * Component factory registration record.
577 */
578typedef struct SUPDRVFACTORYREG
579{
580 /** Pointer to the next registration. */
581 struct SUPDRVFACTORYREG *pNext;
582 /** Pointer to the registered factory. */
583 PCSUPDRVFACTORY pFactory;
584 /** The session owning the factory.
585 * Used for deregistration and session cleanup. */
586 PSUPDRVSESSION pSession;
587 /** Length of the name. */
588 size_t cchName;
589} SUPDRVFACTORYREG;
590/** Pointer to a component factory registration record. */
591typedef SUPDRVFACTORYREG *PSUPDRVFACTORYREG;
592/** Pointer to a const component factory registration record. */
593typedef SUPDRVFACTORYREG const *PCSUPDRVFACTORYREG;
594
595
596/**
597 * Registered object.
598 * This takes care of reference counting and tracking data for access checks.
599 */
600typedef 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;
608 /** Pointer to the object destructor.
609 * This may be set to NULL if the image containing the destructor get unloaded. */
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). */
626#define SUPDRVOBJ_MAGIC UINT32_C(0x18900915)
627/** Dead number magic for SUPDRVOBJ::u32Magic. */
628#define SUPDRVOBJ_MAGIC_DEAD UINT32_C(0x19760112)
629
630/**
631 * The per-session object usage record.
632 */
633typedef 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/**
645 * I/O control context.
646 */
647typedef 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/**
671 * Per session data.
672 * This is mainly for memory tracking.
673 */
674typedef struct SUPDRVSESSION
675{
676 /** Pointer to the device extension. */
677 PSUPDRVDEVEXT pDevExt;
678 /** Session Cookie. */
679 uint32_t u32Cookie;
680 /** Set if is an unrestricted session, clear if restricted. */
681 bool fUnrestricted;
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. */
687 uint32_t volatile cRefs;
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;
700
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;
709 /** Handle table for IPRT semaphore wrapper APIs.
710 * This takes care of its own locking in an IRQ safe manner. */
711 RTHANDLETABLE hHandleTable;
712 /** Load usage records (LIFO!). (protected by SUPDRVDEVEXT::mtxLdr) */
713 PSUPDRVLDRUSAGE volatile pLdrUsage;
714
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. */
718 RTSPINLOCK Spinlock;
719 /** The ring-3 mapping of the GIP (readonly). */
720 RTR0MEMOBJ GipMapObjR3;
721 /** Set if the session is using the GIP. */
722 uint32_t fGipReferenced;
723 /** Bundle of locked memory objects. */
724 SUPDRVBUNDLE Bundle;
725 /** List of generic usage records. (protected by SUPDRVDEVEXT::SpinLock) */
726 PSUPDRVUSAGE volatile pUsage;
727
728 /** The user id of the session - set by the OS part or NIL_RTUID.
729 * This should be unique accross namespace/zones/whatever. */
730 RTUID Uid;
731 /** The group id of the session - set by the OS part or NIL_RTGID.
732 * This should be unique accross namespace/zones/whatever. */
733 RTGID Gid;
734 /** Per session tracer specfic data. */
735 uintptr_t uTracerData;
736 /** The thread currently actively talking to the tracer. (One at the time!) */
737 RTNATIVETHREAD hTracerCaller;
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];
750 /** Whether this is a GIP test-mode client session or not. */
751 bool fGipTestMode;
752#ifndef SUPDRV_AGNOSTIC
753# if defined(RT_OS_DARWIN)
754 /** Pointer to the associated org_virtualbox_SupDrvClient object. */
755 void *pvSupDrvClient;
756 /** Whether this session has been opened or not. */
757 bool fOpened;
758# endif
759# if defined(RT_OS_OS2)
760 /** The system file number of this session. */
761 uint16_t sfn;
762 uint16_t Alignment; /**< Alignment */
763# endif
764# if defined(RT_OS_DARWIN) || defined(RT_OS_OS2) || defined(RT_OS_SOLARIS)
765 /** Pointer to the next session with the same hash. */
766 PSUPDRVSESSION pNextHash;
767# endif
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
772# if defined(RT_OS_WINDOWS)
773 /** Reference to the user ID structure corresponding to the Uid member. */
774 struct SUPDRVNTUSERID *pNtUserId;
775# endif
776#endif /* !SUPDRV_AGNOSTIC */
777} SUPDRVSESSION;
778
779
780/**
781 * Device extension.
782 */
783typedef struct SUPDRVDEVEXT
784{
785 /** Global cookie. */
786 uint32_t u32Cookie;
787 /** The actual size of SUPDRVSESSION. (SUPDRV_AGNOSTIC) */
788 uint32_t cbSession;
789
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. */
794 RTSPINLOCK Spinlock;
795
796 /** List of registered objects. Protected by the spinlock. */
797 PSUPDRVOBJ volatile pObjs;
798 /** List of free object usage records. */
799 PSUPDRVUSAGE volatile pUsageFree;
800
801 /** Loader mutex.
802 * This protects pvVMMR0, pvVMMR0Entry, pImages and SUPDRVSESSION::pLdrUsage. */
803#ifdef SUPDRV_USE_MUTEX_FOR_LDR
804 RTSEMMUTEX mtxLdr;
805#else
806 RTSEMFASTMUTEX mtxLdr;
807#endif
808
809 /** VMM Module 'handle'.
810 * 0 if the code VMM isn't loaded and Idt are nops. */
811 void * volatile pvVMMR0;
812 /** VMMR0EntryFast() pointer. */
813 DECLR0CALLBACKMEMBER(void, pfnVMMR0EntryFast, (PGVM pGVM, PVM pVM, VMCPUID idCpu, uint32_t uOperation));
814 /** VMMR0EntryEx() pointer. */
815 DECLR0CALLBACKMEMBER(int, pfnVMMR0EntryEx, (PGVM pGVM, PVM pVM, VMCPUID idCpu, uint32_t uOperation,
816 PSUPVMMR0REQHDR pReq, uint64_t u64Arg, PSUPDRVSESSION pSession));
817
818 /** Linked list of loaded code. */
819 PSUPDRVLDRIMAGE volatile pLdrImages;
820 /** Set if the image loading interface got disabled after loading all needed images */
821 bool fLdrLockedDown;
822
823 /** @name These members for detecting whether an API caller is in ModuleInit.
824 * Certain APIs are only permitted from ModuleInit, like for instance tracepoint
825 * registration.
826 * @{ */
827 /** The image currently executing its ModuleInit. */
828 PSUPDRVLDRIMAGE volatile pLdrInitImage;
829 /** The thread currently executing a ModuleInit function. */
830 RTNATIVETHREAD volatile hLdrInitThread;
831 /** The thread currently executing a ModuleTerm function. */
832 RTNATIVETHREAD volatile hLdrTermThread;
833 /** @} */
834
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;
838
839 /** GIP mutex.
840 * Any changes to any of the GIP members requires ownership of this mutex,
841 * except on driver init and termination. */
842#ifdef SUPDRV_USE_MUTEX_FOR_GIP
843 RTSEMMUTEX mtxGip;
844#else
845 RTSEMFASTMUTEX mtxGip;
846#endif
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). */
850 RTSPINLOCK hGipSpinlock;
851 /** Pointer to the Global Info Page (GIP). */
852 PSUPGLOBALINFOPAGE pGip;
853 /** The physical address of the GIP. */
854 RTHCPHYS HCPhysGip;
855 /** Number of processes using the GIP.
856 * (The updates are suspend while cGipUsers is 0.)*/
857 uint32_t volatile cGipUsers;
858 /** The ring-0 memory object handle for the GIP page. */
859 RTR0MEMOBJ GipMemObj;
860 /** The GIP timer handle. */
861 PRTTIMER pGipTimer;
862 /** If non-zero we've successfully called RTTimerRequestSystemGranularity(). */
863 uint32_t u32SystemTimerGranularityGrant;
864 /** The CPU id of the GIP master.
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.) */
869 RTCPUID volatile idGipMaster;
870
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
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;
891 /** The number of session having opened the tracer currently. */
892 uint32_t cTracerOpens;
893 /** The number of threads currently calling into the tracer. */
894 uint32_t volatile cTracerCallers;
895 /** Set if the tracer is being unloaded. */
896 bool fTracerUnloading;
897 /** Hash table for user tracer modules (SUPDRVVTGCOPY). */
898 RTLISTANCHOR aTrackerUmodHash[128];
899
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
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;
923 /** Stop the timer on the next tick because we saw a power event. */
924 bool volatile fInvTscRefinePowerEvent;
925 /** @} */
926
927 /** @name TSC-delta measurement.
928 * @{ */
929 /** Number of online/offline events, incremented each time a CPU goes online
930 * or offline. */
931 uint32_t volatile cMpOnOffEvents;
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
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;
945 /** @} */
946
947#ifdef SUPDRV_USE_TSC_DELTA_THREAD
948 /** @name TSC-delta measurement thread.
949 * @{ */
950 /** Spinlock protecting enmTscDeltaThreadState. */
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. */
957 SUPDRVTSCDELTATHREADSTATE enmTscDeltaThreadState;
958 /** Thread timeout time before rechecking state in ms. */
959 RTMSINTERVAL cMsTscDeltaTimeout;
960 /** Whether the TSC-delta measurement was successful. */
961 int32_t volatile rcTscDelta;
962 /** Tell the thread we want TSC-deltas for all CPUs with retries. */
963 bool fTscThreadRecomputeAllDeltas;
964 /** @} */
965#endif
966
967 /** @name GIP test mode.
968 * @{ */
969 /** Reference counter for GIP test-mode sessions. */
970 uint32_t cGipTestModeRefs;
971 /** Cache of TSC frequency before enabling test-mode on invariant GIP systems. */
972 uint64_t uGipTestModeInvariantCpuHz;
973 /** @} */
974
975 /*
976 * Note! The non-agnostic bits must be at the very end of the structure!
977 */
978#ifndef SUPDRV_AGNOSTIC
979# ifdef RT_OS_WINDOWS
980 /** Callback object returned by ExCreateCallback. */
981 PCALLBACK_OBJECT pObjPowerCallback;
982 /** Callback handle returned by ExRegisterCallback. */
983 PVOID hPowerCallback;
984# elif defined(RT_OS_DARWIN) && defined(VBOX_WITH_DARWIN_R0_DARWIN_IMAGE_VERIFICATION)
985 /** Trusted root certificates for code signing validation. */
986 RTCRSTORE hRootStore;
987 /** Intermedite certificates for code signing validation. */
988 RTCRSTORE hAdditionalStore;
989# endif
990#endif
991} SUPDRVDEVEXT;
992
993/** Calculates the index into g_apSessionHashTab.*/
994#define SUPDRV_SESSION_HASH(a_pid) ( (a_pid) % RT_ELEMENTS(((SUPDRVDEVEXT *)NULL)->apSessionHashTab) )
995
996
997RT_C_DECLS_BEGIN
998
999/*******************************************************************************
1000* OS Specific Functions *
1001*******************************************************************************/
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 */
1008void 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 */
1018void 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 */
1028void VBOXCALL supdrvOSSessionHashTabRemoved(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, void *pvUser);
1029
1030/**
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 */
1038size_t VBOXCALL supdrvOSGipGetGroupTableSize(PSUPDRVDEVEXT pDevExt);
1039
1040/**
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.
1048 * @param cbGipCpuGroups What supdrvOSGipGetGroupTableSize returned.
1049 */
1050int VBOXCALL supdrvOSInitGipGroupTable(PSUPDRVDEVEXT pDevExt, PSUPGLOBALINFOPAGE pGip, size_t cbGipCpuGroups);
1051
1052/**
1053 * Initializes the group related members when a CPU is added to the GIP.
1054 *
1055 * This is called both during GIP initalization and during an CPU online event.
1056 *
1057 * This is currently only implemented on windows [lazy bird].
1058 *
1059 * @returns CPU group number.
1060 * @param pDevExt The device globals.
1061 * @param pGip The GIP.
1062 * @param pGipCpu The GIP CPU structure being initialized.
1063 */
1064void VBOXCALL supdrvOSGipInitGroupBitsForCpu(PSUPDRVDEVEXT pDevExt, PSUPGLOBALINFOPAGE pGip, PSUPGIPCPU pGipCpu);
1065
1066void VBOXCALL supdrvOSObjInitCreator(PSUPDRVOBJ pObj, PSUPDRVSESSION pSession);
1067bool VBOXCALL supdrvOSObjCanAccess(PSUPDRVOBJ pObj, PSUPDRVSESSION pSession, const char *pszObjName, int *prc);
1068bool VBOXCALL supdrvOSGetForcedAsyncTscMode(PSUPDRVDEVEXT pDevExt);
1069bool VBOXCALL supdrvOSAreCpusOfflinedOnSuspend(void);
1070bool VBOXCALL supdrvOSAreTscDeltasInSync(void);
1071int VBOXCALL supdrvOSEnableVTx(bool fEnabled);
1072RTCCUINTREG VBOXCALL supdrvOSChangeCR4(RTCCUINTREG fOrMask, RTCCUINTREG fAndMask);
1073bool VBOXCALL supdrvOSSuspendVTxOnCpu(void);
1074void VBOXCALL supdrvOSResumeVTxOnCpu(bool fSuspended);
1075int VBOXCALL supdrvOSGetCurrentGdtRw(RTHCUINTPTR *pGdtRw);
1076
1077/**
1078 * Try open the image using the native loader.
1079 *
1080 * @returns IPRT status code.
1081 * @retval VERR_NOT_SUPPORTED if native loading isn't supported.
1082 *
1083 * @param pDevExt The device globals.
1084 * @param pImage The image handle. pvImage should be set on
1085 * success, pvImageAlloc can also be set if
1086 * appropriate.
1087 * @param pszFilename The file name - UTF-8, may containing UNIX
1088 * slashes on non-UNIX systems.
1089 */
1090int VBOXCALL supdrvOSLdrOpen(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, const char *pszFilename);
1091
1092/**
1093 * Notification call indicating that a image is being opened for the first time.
1094 *
1095 * Called for both native and non-native images (after supdrvOSLdrOpen). Can be
1096 * used to log the load address of the image or inform the kernel about the
1097 * alien image.
1098 *
1099 * @param pDevExt The device globals.
1100 * @param pImage The image handle.
1101 * @param pszFilename The file name - UTF-8, may containing UNIX
1102 * slashes on non-UNIX systems.
1103 */
1104void VBOXCALL supdrvOSLdrNotifyOpened(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, const char *pszFilename);
1105
1106/**
1107 * Validates an entry point address.
1108 *
1109 * Called before supdrvOSLdrLoad.
1110 *
1111 * @returns IPRT status code.
1112 * @param pDevExt The device globals.
1113 * @param pImage The image data (still in the open state).
1114 * @param pv The address within the image.
1115 * @param pbImageBits The image bits as loaded by ring-3.
1116 * @param pszSymbol The name of the entrypoint being checked.
1117 */
1118int VBOXCALL supdrvOSLdrValidatePointer(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage,
1119 void *pv, const uint8_t *pbImageBits, const char *pszSymbol);
1120
1121/**
1122 * Load the image.
1123 *
1124 * @returns IPRT status code.
1125 * @param pDevExt The device globals.
1126 * @param pImage The image data (up to date). Adjust entrypoints
1127 * and exports if necessary.
1128 * @param pbImageBits The image bits as loaded by ring-3.
1129 * @param pReq Pointer to the request packet so that the VMMR0
1130 * entry points can be adjusted.
1131 */
1132int VBOXCALL supdrvOSLdrLoad(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, const uint8_t *pbImageBits, PSUPLDRLOAD pReq);
1133
1134/**
1135 * Unload the image (only called if supdrvOSLdrOpen returned success).
1136 *
1137 * @param pDevExt The device globals.
1138 * @param pImage The image data (mostly still valid).
1139 */
1140void VBOXCALL supdrvOSLdrUnload(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage);
1141
1142/**
1143 * Notification call indicating that a image is being unloaded.
1144 *
1145 * Called for both native and non-native images. In the former case, it's
1146 * called after supdrvOSLdrUnload.
1147 *
1148 * @param pDevExt The device globals.
1149 * @param pImage The image handle.
1150 */
1151void VBOXCALL supdrvOSLdrNotifyUnloaded(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage);
1152
1153/**
1154 * Queries a symbol address is a native module.
1155 *
1156 * @returns IPRT status code.
1157 * @param pDevExt The device globals.
1158 * @param pImage The image to search.
1159 * @param pszSymbol The symbol to search for.
1160 * @param cchSymbol The length of the symbol.
1161 * @param ppvSymbol Where to return the symbol address if found.
1162 */
1163int VBOXCALL supdrvOSLdrQuerySymbol(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage,
1164 const char *pszSymbol, size_t cchSymbol, void **ppvSymbol);
1165
1166/**
1167 * Retains a native wrapper module when it is first being used.
1168 *
1169 * This will be call when pImage->cImgUsage is incremented to 2.
1170 *
1171 * @param pDevExt The device globals.
1172 * @param pImage The wrapped image.
1173 */
1174void VBOXCALL supdrvOSLdrRetainWrapperModule(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage);
1175
1176/**
1177 * Release a native wrapper module when it is no longer being used.
1178 *
1179 * This will be call when pImage->cImgUsage is decremented to 1.
1180 *
1181 * @param pDevExt The device globals.
1182 * @param pImage The wrapped image.
1183 */
1184void VBOXCALL supdrvOSLdrReleaseWrapperModule(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage);
1185
1186#ifdef SUPDRV_WITH_MSR_PROBER
1187
1188/**
1189 * Tries to read an MSR.
1190 *
1191 * @returns One of the listed VBox status codes.
1192 * @retval VINF_SUCCESS if read successfully, value in *puValue.
1193 * @retval VERR_ACCESS_DENIED if we couldn't read it (GP).
1194 * @retval VERR_NOT_SUPPORTED if not supported.
1195 *
1196 * @param uMsr The MSR to read from.
1197 * @param idCpu The CPU to read the MSR on. NIL_RTCPUID
1198 * indicates any suitable CPU.
1199 * @param puValue Where to return the value.
1200 */
1201int VBOXCALL supdrvOSMsrProberRead(uint32_t uMsr, RTCPUID idCpu, uint64_t *puValue);
1202
1203/**
1204 * Tries to write an MSR.
1205 *
1206 * @returns One of the listed VBox status codes.
1207 * @retval VINF_SUCCESS if written successfully.
1208 * @retval VERR_ACCESS_DENIED if we couldn't write the value to it (GP).
1209 * @retval VERR_NOT_SUPPORTED if not supported.
1210 *
1211 * @param uMsr The MSR to write to.
1212 * @param idCpu The CPU to write the MSR on. NIL_RTCPUID
1213 * indicates any suitable CPU.
1214 * @param uValue The value to write.
1215 */
1216int VBOXCALL supdrvOSMsrProberWrite(uint32_t uMsr, RTCPUID idCpu, uint64_t uValue);
1217
1218/**
1219 * Tries to modify an MSR value.
1220 *
1221 * @returns One of the listed VBox status codes.
1222 * @retval VINF_SUCCESS if succeeded.
1223 * @retval VERR_NOT_SUPPORTED if not supported.
1224 *
1225 * @param idCpu The CPU to modify the MSR on. NIL_RTCPUID
1226 * indicates any suitable CPU.
1227 * @param pReq The request packet with input arguments and
1228 * where to store the results.
1229 */
1230int VBOXCALL supdrvOSMsrProberModify(RTCPUID idCpu, PSUPMSRPROBER pReq);
1231
1232#endif /* SUPDRV_WITH_MSR_PROBER */
1233
1234#if defined(RT_OS_DARWIN)
1235int VBOXCALL supdrvDarwinResumeSuspendedKbds(void);
1236#endif
1237
1238
1239/*********************************************************************************************************************************
1240* Shared Functions *
1241*********************************************************************************************************************************/
1242/* SUPDrv.c */
1243int VBOXCALL supdrvIOCtl(uintptr_t uIOCtl, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPREQHDR pReqHdr, size_t cbReq);
1244int VBOXCALL supdrvIOCtlFast(uintptr_t uOperation, VMCPUID idCpu, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession);
1245int VBOXCALL supdrvIDC(uintptr_t uIOCtl, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPDRVIDCREQHDR pReqHdr);
1246int VBOXCALL supdrvInitDevExt(PSUPDRVDEVEXT pDevExt, size_t cbSession);
1247void VBOXCALL supdrvDeleteDevExt(PSUPDRVDEVEXT pDevExt);
1248int VBOXCALL supdrvCreateSession(PSUPDRVDEVEXT pDevExt, bool fUser, bool fUnrestricted, PSUPDRVSESSION *ppSession);
1249int VBOXCALL supdrvSessionHashTabInsert(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPDRVSESSION *ppOsSessionPtr, void *pvUser);
1250int VBOXCALL supdrvSessionHashTabRemove(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, void *pvUser);
1251PSUPDRVSESSION VBOXCALL supdrvSessionHashTabLookup(PSUPDRVDEVEXT pDevExt, RTPROCESS Process, RTR0PROCESS R0Process,
1252 PSUPDRVSESSION *ppOsSessionPtr);
1253uint32_t VBOXCALL supdrvSessionRetain(PSUPDRVSESSION pSession);
1254uint32_t VBOXCALL supdrvSessionRelease(PSUPDRVSESSION pSession);
1255void VBOXCALL supdrvBadContext(PSUPDRVDEVEXT pDevExt, const char *pszFile, uint32_t uLine, const char *pszExtra);
1256int VBOXCALL supdrvQueryVTCapsInternal(uint32_t *pfCaps);
1257int VBOXCALL supdrvLdrLoadError(int rc, PSUPLDRLOAD pReq, const char *pszFormat, ...);
1258int VBOXCALL supdrvLdrGetExportedSymbol(const char *pszSymbol, uintptr_t *puValue);
1259int VBOXCALL supdrvLdrRegisterWrappedModule(PSUPDRVDEVEXT pDevExt, PCSUPLDRWRAPPEDMODULE pWrappedModInfo,
1260 void *pvNative, void **phMod);
1261int VBOXCALL supdrvLdrDeregisterWrappedModule(PSUPDRVDEVEXT pDevExt, PCSUPLDRWRAPPEDMODULE pWrappedModInfo, void **phMod);
1262
1263
1264/* SUPDrvGip.cpp */
1265int VBOXCALL supdrvGipCreate(PSUPDRVDEVEXT pDevExt);
1266void VBOXCALL supdrvGipDestroy(PSUPDRVDEVEXT pDevExt);
1267int VBOXCALL supdrvIOCtl_TscDeltaMeasure(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPTSCDELTAMEASURE pReq);
1268int VBOXCALL supdrvIOCtl_TscRead(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPTSCREAD pReq);
1269int VBOXCALL supdrvIOCtl_GipSetFlags(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, uint32_t fOrMask, uint32_t fAndMask);
1270
1271
1272/* SUPDrvTracer.cpp */
1273int VBOXCALL supdrvTracerInit(PSUPDRVDEVEXT pDevExt);
1274void VBOXCALL supdrvTracerTerm(PSUPDRVDEVEXT pDevExt);
1275void VBOXCALL supdrvTracerModuleUnloading(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage);
1276void VBOXCALL supdrvTracerCleanupSession(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession);
1277int VBOXCALL supdrvIOCtl_TracerUmodRegister(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession,
1278 RTR3PTR R3PtrVtgHdr, RTUINTPTR uVtgHdrAddr,
1279 RTR3PTR R3PtrStrTab, uint32_t cbStrTab,
1280 const char *pszModName, uint32_t fFlags);
1281int VBOXCALL supdrvIOCtl_TracerUmodDeregister(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, RTR3PTR R3PtrVtgHdr);
1282void VBOXCALL supdrvIOCtl_TracerUmodProbeFire(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPDRVTRACERUSRCTX pCtx);
1283int VBOXCALL supdrvIOCtl_TracerOpen(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, uint32_t uCookie, uintptr_t uArg);
1284int VBOXCALL supdrvIOCtl_TracerClose(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession);
1285int VBOXCALL supdrvIOCtl_TracerIOCtl(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, uintptr_t uCmd, uintptr_t uArg, int32_t *piRetVal);
1286extern PFNRT g_pfnSupdrvProbeFireKernel;
1287DECLASM(void) supdrvTracerProbeFireStub(void);
1288
1289#ifdef VBOX_WITH_NATIVE_DTRACE
1290const SUPDRVTRACERREG * VBOXCALL supdrvDTraceInit(void);
1291void VBOXCALL supdrvDTraceFini(void);
1292#endif
1293
1294RT_C_DECLS_END
1295
1296#endif /* !VBOX_INCLUDED_SRC_Support_SUPDrvInternal_h */
1297
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette