VirtualBox

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

Last change on this file since 103914 was 101358, checked in by vboxsync, 14 months ago

Linux: vboxdrv: Replace SUPDRV_UNFORTIFIED_MEMCPY with RT_BCOPY_UNFORTIFIED, bugref:10209.

  • 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 101358 2023-10-05 15:24:57Z 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 * @param pDevExt The device globals.
1060 * @param pGip The GIP.
1061 * @param pGipCpu The GIP CPU structure being initialized.
1062 */
1063void VBOXCALL supdrvOSGipInitGroupBitsForCpu(PSUPDRVDEVEXT pDevExt, PSUPGLOBALINFOPAGE pGip, PSUPGIPCPU pGipCpu);
1064
1065void VBOXCALL supdrvOSObjInitCreator(PSUPDRVOBJ pObj, PSUPDRVSESSION pSession);
1066bool VBOXCALL supdrvOSObjCanAccess(PSUPDRVOBJ pObj, PSUPDRVSESSION pSession, const char *pszObjName, int *prc);
1067bool VBOXCALL supdrvOSGetForcedAsyncTscMode(PSUPDRVDEVEXT pDevExt);
1068bool VBOXCALL supdrvOSAreCpusOfflinedOnSuspend(void);
1069bool VBOXCALL supdrvOSAreTscDeltasInSync(void);
1070int VBOXCALL supdrvOSEnableVTx(bool fEnabled);
1071RTCCUINTREG VBOXCALL supdrvOSChangeCR4(RTCCUINTREG fOrMask, RTCCUINTREG fAndMask);
1072bool VBOXCALL supdrvOSSuspendVTxOnCpu(void);
1073void VBOXCALL supdrvOSResumeVTxOnCpu(bool fSuspended);
1074int VBOXCALL supdrvOSGetCurrentGdtRw(RTHCUINTPTR *pGdtRw);
1075
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.
1086 * @param pszFilename The file name - UTF-8, may containing UNIX
1087 * slashes on non-UNIX systems.
1088 */
1089int VBOXCALL supdrvOSLdrOpen(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, const char *pszFilename);
1090
1091/**
1092 * Notification call indicating that a image is being opened for the first time.
1093 *
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.
1097 *
1098 * @param pDevExt The device globals.
1099 * @param pImage The image handle.
1100 * @param pszFilename The file name - UTF-8, may containing UNIX
1101 * slashes on non-UNIX systems.
1102 */
1103void VBOXCALL supdrvOSLdrNotifyOpened(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, const char *pszFilename);
1104
1105/**
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.
1115 * @param pszSymbol The name of the entrypoint being checked.
1116 */
1117int VBOXCALL supdrvOSLdrValidatePointer(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage,
1118 void *pv, const uint8_t *pbImageBits, const char *pszSymbol);
1119
1120/**
1121 * Load the image.
1122 *
1123 * @returns IPRT status code.
1124 * @param pDevExt The device globals.
1125 * @param pImage The image data (up to date). Adjust entrypoints
1126 * and exports if necessary.
1127 * @param pbImageBits The image bits as loaded by ring-3.
1128 * @param pReq Pointer to the request packet so that the VMMR0
1129 * entry points can be adjusted.
1130 */
1131int VBOXCALL supdrvOSLdrLoad(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, const uint8_t *pbImageBits, PSUPLDRLOAD pReq);
1132
1133/**
1134 * Unload the image (only called if supdrvOSLdrOpen returned success).
1135 *
1136 * @param pDevExt The device globals.
1137 * @param pImage The image data (mostly still valid).
1138 */
1139void VBOXCALL supdrvOSLdrUnload(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage);
1140
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 */
1150void VBOXCALL supdrvOSLdrNotifyUnloaded(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage);
1151
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 */
1162int VBOXCALL supdrvOSLdrQuerySymbol(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage,
1163 const char *pszSymbol, size_t cchSymbol, void **ppvSymbol);
1164
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 */
1173void VBOXCALL supdrvOSLdrRetainWrapperModule(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage);
1174
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 */
1183void VBOXCALL supdrvOSLdrReleaseWrapperModule(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage);
1184
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 */
1200int 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 */
1215int 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 */
1229int VBOXCALL supdrvOSMsrProberModify(RTCPUID idCpu, PSUPMSRPROBER pReq);
1230
1231#endif /* SUPDRV_WITH_MSR_PROBER */
1232
1233#if defined(RT_OS_DARWIN)
1234int VBOXCALL supdrvDarwinResumeSuspendedKbds(void);
1235#endif
1236
1237
1238/*********************************************************************************************************************************
1239* Shared Functions *
1240*********************************************************************************************************************************/
1241/* SUPDrv.c */
1242int VBOXCALL supdrvIOCtl(uintptr_t uIOCtl, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPREQHDR pReqHdr, size_t cbReq);
1243int VBOXCALL supdrvIOCtlFast(uintptr_t uOperation, VMCPUID idCpu, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession);
1244int VBOXCALL supdrvIDC(uintptr_t uIOCtl, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPDRVIDCREQHDR pReqHdr);
1245int VBOXCALL supdrvInitDevExt(PSUPDRVDEVEXT pDevExt, size_t cbSession);
1246void VBOXCALL supdrvDeleteDevExt(PSUPDRVDEVEXT pDevExt);
1247int VBOXCALL supdrvCreateSession(PSUPDRVDEVEXT pDevExt, bool fUser, bool fUnrestricted, PSUPDRVSESSION *ppSession);
1248int VBOXCALL supdrvSessionHashTabInsert(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPDRVSESSION *ppOsSessionPtr, void *pvUser);
1249int VBOXCALL supdrvSessionHashTabRemove(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, void *pvUser);
1250PSUPDRVSESSION VBOXCALL supdrvSessionHashTabLookup(PSUPDRVDEVEXT pDevExt, RTPROCESS Process, RTR0PROCESS R0Process,
1251 PSUPDRVSESSION *ppOsSessionPtr);
1252uint32_t VBOXCALL supdrvSessionRetain(PSUPDRVSESSION pSession);
1253uint32_t VBOXCALL supdrvSessionRelease(PSUPDRVSESSION pSession);
1254void VBOXCALL supdrvBadContext(PSUPDRVDEVEXT pDevExt, const char *pszFile, uint32_t uLine, const char *pszExtra);
1255int VBOXCALL supdrvQueryVTCapsInternal(uint32_t *pfCaps);
1256int VBOXCALL supdrvLdrLoadError(int rc, PSUPLDRLOAD pReq, const char *pszFormat, ...);
1257int VBOXCALL supdrvLdrGetExportedSymbol(const char *pszSymbol, uintptr_t *puValue);
1258int VBOXCALL supdrvLdrRegisterWrappedModule(PSUPDRVDEVEXT pDevExt, PCSUPLDRWRAPPEDMODULE pWrappedModInfo,
1259 void *pvNative, void **phMod);
1260int VBOXCALL supdrvLdrDeregisterWrappedModule(PSUPDRVDEVEXT pDevExt, PCSUPLDRWRAPPEDMODULE pWrappedModInfo, void **phMod);
1261
1262
1263/* SUPDrvGip.cpp */
1264int VBOXCALL supdrvGipCreate(PSUPDRVDEVEXT pDevExt);
1265void VBOXCALL supdrvGipDestroy(PSUPDRVDEVEXT pDevExt);
1266int VBOXCALL supdrvIOCtl_TscDeltaMeasure(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPTSCDELTAMEASURE pReq);
1267int VBOXCALL supdrvIOCtl_TscRead(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPTSCREAD pReq);
1268int VBOXCALL supdrvIOCtl_GipSetFlags(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, uint32_t fOrMask, uint32_t fAndMask);
1269
1270
1271/* SUPDrvTracer.cpp */
1272int VBOXCALL supdrvTracerInit(PSUPDRVDEVEXT pDevExt);
1273void VBOXCALL supdrvTracerTerm(PSUPDRVDEVEXT pDevExt);
1274void VBOXCALL supdrvTracerModuleUnloading(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage);
1275void VBOXCALL supdrvTracerCleanupSession(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession);
1276int 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);
1280int VBOXCALL supdrvIOCtl_TracerUmodDeregister(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, RTR3PTR R3PtrVtgHdr);
1281void VBOXCALL supdrvIOCtl_TracerUmodProbeFire(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPDRVTRACERUSRCTX pCtx);
1282int VBOXCALL supdrvIOCtl_TracerOpen(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, uint32_t uCookie, uintptr_t uArg);
1283int VBOXCALL supdrvIOCtl_TracerClose(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession);
1284int VBOXCALL supdrvIOCtl_TracerIOCtl(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, uintptr_t uCmd, uintptr_t uArg, int32_t *piRetVal);
1285extern PFNRT g_pfnSupdrvProbeFireKernel;
1286DECLASM(void) supdrvTracerProbeFireStub(void);
1287
1288#ifdef VBOX_WITH_NATIVE_DTRACE
1289const SUPDRVTRACERREG * VBOXCALL supdrvDTraceInit(void);
1290void VBOXCALL supdrvDTraceFini(void);
1291#endif
1292
1293RT_C_DECLS_END
1294
1295#endif /* !VBOX_INCLUDED_SRC_Support_SUPDrvInternal_h */
1296
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