VirtualBox

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

Last change on this file since 97902 was 97902, checked in by vboxsync, 2 years ago

SUPDrv: Enable SUPDRV_USE_MEMOBJ_FOR_LDR_IMAGE for all hosts.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 51.3 KB
Line 
1/* $Id: SUPDrvInternal.h 97902 2022-12-29 18:05:46Z vboxsync $ */
2/** @file
3 * VirtualBox Support Driver - Internal header.
4 */
5
6/*
7 * Copyright (C) 2006-2022 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/** Use the RTR0MemObj API rather than the RTMemExecAlloc for the images.
308 * This is a good idea in general, but a necessity for @bugref{9801}. */
309#define SUPDRV_USE_MEMOBJ_FOR_LDR_IMAGE
310
311#ifndef SUPR0_EXPORT_SYMBOL
312# define SUPR0_EXPORT_SYMBOL(a_Name) extern int g_supDrvExportSymbolDummyVariable
313#endif
314
315/**
316 * OS debug print macro.
317 */
318#define OSDBGPRINT(a) SUPR0Printf a
319
320
321/** @name Context values for the per-session handle tables.
322 * The context value is used to distinguish between the different kinds of
323 * handles, making the handle table API do all the work.
324 * @{ */
325/** Handle context value for single release event handles. */
326#define SUPDRV_HANDLE_CTX_EVENT ((void *)(uintptr_t)(SUPDRVOBJTYPE_SEM_EVENT))
327/** Handle context value for multiple release event handles. */
328#define SUPDRV_HANDLE_CTX_EVENT_MULTI ((void *)(uintptr_t)(SUPDRVOBJTYPE_SEM_EVENT_MULTI))
329/** @} */
330
331
332/**
333 * Validates a session pointer.
334 *
335 * @returns true/false accordingly.
336 * @param pSession The session.
337 */
338#define SUP_IS_SESSION_VALID(pSession) \
339 ( RT_VALID_PTR(pSession) \
340 && pSession->u32Cookie == BIRD_INV)
341
342/**
343 * Validates a device extension pointer.
344 *
345 * @returns true/false accordingly.
346 * @param pDevExt The device extension.
347 */
348#define SUP_IS_DEVEXT_VALID(pDevExt) \
349 ( RT_VALID_PTR(pDevExt) \
350 && pDevExt->u32Cookie == BIRD)
351
352
353/** @def SUPDRV_WITH_MSR_PROBER
354 * Enables the SUP_IOCTL_MSR_PROBER function.
355 * By default, only enabled in DEBUG builds as it's a sensitive feature.
356 */
357#if defined(DEBUG) && !defined(SUPDRV_WITH_MSR_PROBER) && !defined(SUPDRV_WITHOUT_MSR_PROBER)
358# define SUPDRV_WITH_MSR_PROBER
359#endif
360
361/** @def SUPDRV_WITHOUT_MSR_PROBER
362 * Executive overide for disabling the SUP_IOCTL_MSR_PROBER function.
363 */
364#ifdef SUPDRV_WITHOUT_MSR_PROBER
365# undef SUPDRV_WITH_MSR_PROBER
366#endif
367
368#ifdef DOXYGEN_RUNNING
369# define SUPDRV_WITH_MSR_PROBER
370# define SUPDRV_WITHOUT_MSR_PROBER
371#endif
372
373#if 1
374/** @def SUPDRV_USE_TSC_DELTA_THREAD
375 * Use a dedicated kernel thread to service TSC-delta measurement requests.
376 * @todo Test on servers with many CPUs and sockets. */
377# define SUPDRV_USE_TSC_DELTA_THREAD
378#endif
379
380
381/*********************************************************************************************************************************
382* Structures and Typedefs *
383*********************************************************************************************************************************/
384/** Pointer to the device extension. */
385typedef struct SUPDRVDEVEXT *PSUPDRVDEVEXT;
386
387#ifdef SUPDRV_USE_TSC_DELTA_THREAD
388/**
389 * TSC-delta measurement thread state machine.
390 */
391typedef enum SUPDRVTSCDELTATHREADSTATE
392{
393 /** Uninitialized/invalid value. */
394 kTscDeltaThreadState_Invalid = 0,
395 /** The thread is being created.
396 * Next state: Listening, Butchered, Terminating */
397 kTscDeltaThreadState_Creating,
398 /** The thread is listening for events.
399 * Previous state: Creating, Measuring
400 * Next state: WaitAndMeasure, Butchered, Terminated */
401 kTscDeltaThreadState_Listening,
402 /** The thread is sleeping before starting a measurement.
403 * Previous state: Listening, Measuring
404 * Next state: Measuring, Butchered, Terminating
405 * @remarks The thread won't enter this state on its own, it is put into this
406 * state by the GIP timer, the CPU online callback and by the
407 * SUP_IOCTL_TSC_DELTA_MEASURE code. */
408 kTscDeltaThreadState_WaitAndMeasure,
409 /** The thread is currently servicing a measurement request.
410 * Previous state: WaitAndMeasure
411 * Next state: Listening, WaitAndMeasure, Terminate */
412 kTscDeltaThreadState_Measuring,
413 /** The thread is terminating.
414 * @remarks The thread won't enter this state on its own, is put into this state
415 * by supdrvTscDeltaTerm. */
416 kTscDeltaThreadState_Terminating,
417 /** The thread is butchered due to an unexpected error.
418 * Previous State: Creating, Listening, WaitAndMeasure */
419 kTscDeltaThreadState_Butchered,
420 /** The thread is destroyed (final).
421 * Previous state: Terminating */
422 kTscDeltaThreadState_Destroyed,
423 /** The usual 32-bit blowup hack. */
424 kTscDeltaThreadState_32BitHack = 0x7fffffff
425} SUPDRVTSCDELTATHREADSTATE;
426#endif /* SUPDRV_USE_TSC_DELTA_THREAD */
427
428/**
429 * Memory reference types.
430 */
431typedef enum
432{
433 /** Unused entry */
434 MEMREF_TYPE_UNUSED = 0,
435 /** Locked memory (r3 mapping only). */
436 MEMREF_TYPE_LOCKED,
437 /** Continuous memory block (r3 and r0 mapping). */
438 MEMREF_TYPE_CONT,
439 /** Low memory block (r3 and r0 mapping). */
440 MEMREF_TYPE_LOW,
441 /** Memory block (r3 and r0 mapping). */
442 MEMREF_TYPE_MEM,
443 /** Locked memory (r3 mapping only) allocated by the support driver. */
444 MEMREF_TYPE_PAGE,
445 /** Blow the type up to 32-bit and mark the end. */
446 MEMREF_TYPE_32BIT_HACK = 0x7fffffff
447} SUPDRVMEMREFTYPE, *PSUPDRVMEMREFTYPE;
448
449
450/**
451 * Structure used for tracking memory a session
452 * references in one way or another.
453 */
454typedef struct SUPDRVMEMREF
455{
456 /** The memory object handle. */
457 RTR0MEMOBJ MemObj;
458 /** The ring-3 mapping memory object handle. */
459 RTR0MEMOBJ MapObjR3;
460 /** Type of memory. */
461 SUPDRVMEMREFTYPE eType;
462} SUPDRVMEMREF, *PSUPDRVMEMREF;
463
464
465/**
466 * Bundle of locked memory ranges.
467 */
468typedef struct SUPDRVBUNDLE
469{
470 /** Pointer to the next bundle. */
471 struct SUPDRVBUNDLE * volatile pNext;
472 /** Referenced memory. */
473 SUPDRVMEMREF aMem[64];
474 /** Number of entries used. */
475 uint32_t volatile cUsed;
476} SUPDRVBUNDLE, *PSUPDRVBUNDLE;
477
478
479/**
480 * Loaded image.
481 */
482typedef struct SUPDRVLDRIMAGE
483{
484 /** Next in chain. */
485 struct SUPDRVLDRIMAGE * volatile pNext;
486 /** Pointer to the image. */
487 void *pvImage;
488#ifdef SUPDRV_USE_MEMOBJ_FOR_LDR_IMAGE
489 /** The memory object for the module allocation. */
490 RTR0MEMOBJ hMemObjImage;
491#else
492 /** Pointer to the allocated image buffer.
493 * pvImage is 32-byte aligned or it may governed by the native loader (this
494 * member is NULL then). */
495 void *pvImageAlloc;
496#endif
497 /** Magic value (SUPDRVLDRIMAGE_MAGIC). */
498 uint32_t uMagic;
499 /** Size of the image including the tables. This is mainly for verification
500 * of the load request. */
501 uint32_t cbImageWithEverything;
502 /** Size of the image. */
503 uint32_t cbImageBits;
504 /** The number of entries in the symbol table. */
505 uint32_t cSymbols;
506 /** Pointer to the symbol table. */
507 PSUPLDRSYM paSymbols;
508 /** The offset of the string table. */
509 char *pachStrTab;
510 /** Size of the string table. */
511 uint32_t cbStrTab;
512 /** Number of segments. */
513 uint32_t cSegments;
514 /** Segments (for memory protection). */
515 PSUPLDRSEG paSegments;
516 /** Pointer to the optional module initialization callback. */
517 PFNR0MODULEINIT pfnModuleInit;
518 /** Pointer to the optional module termination callback. */
519 PFNR0MODULETERM pfnModuleTerm;
520 /** Service request handler. This is NULL for non-service modules. */
521 PFNSUPR0SERVICEREQHANDLER pfnServiceReqHandler;
522 /** The ldr image state. (IOCtl code of last operation.) */
523 uint32_t uState;
524 /** Usage count. */
525 uint32_t volatile cImgUsage;
526 /** Pointer to the device extension. */
527 struct SUPDRVDEVEXT *pDevExt;
528 /** Image (VMMR0.r0) containing functions/data that this one uses. */
529 struct SUPDRVLDRIMAGE *pImageImport;
530#ifdef RT_OS_WINDOWS
531 /** The section object for the loaded image (fNative=true). */
532 void *pvNtSectionObj;
533 /** Lock object. */
534 RTR0MEMOBJ hMemLock;
535#endif
536#if defined(RT_OS_SOLARIS) && defined(VBOX_WITH_NATIVE_SOLARIS_LOADING)
537 /** The Solaris module ID. */
538 int idSolMod;
539 /** Pointer to the module control structure. */
540 struct modctl *pSolModCtl;
541#endif
542#ifdef RT_OS_LINUX
543 /** Hack for seeing the module in perf, dtrace and other stack crawlers. */
544 struct module *pLnxModHack;
545 /** The wrapper module. */
546 struct module *pLnxWrapperModule;
547 /** Set if we're holding a reference to the wrapper module. */
548 bool fLnxWrapperRef;
549#endif
550#if defined(RT_OS_DARWIN) && defined(VBOX_WITH_DARWIN_R0_DARWIN_IMAGE_VERIFICATION)
551 /** Load module handle. */
552 RTLDRMOD hLdrMod;
553 /** Allocate object. */
554 RTR0MEMOBJ hMemAlloc;
555#endif
556 /** This points to the module info if the image is a wrapped up in a native one. */
557 PCSUPLDRWRAPPEDMODULE pWrappedModInfo;
558 /** OS specific information for wrapped modules. */
559 void *pvWrappedNative;
560 /** Whether it's loaded by the native loader or not. */
561 bool fNative;
562 /** Image name. */
563 char szName[32];
564} SUPDRVLDRIMAGE, *PSUPDRVLDRIMAGE;
565
566/** Magic value for SUPDRVLDRIMAGE::uMagic (Charlotte Bronte). */
567#define SUPDRVLDRIMAGE_MAGIC UINT32_C(0x18160421)
568/** Magic value for SUPDRVLDRIMAGE::uMagic when freed. */
569#define SUPDRVLDRIMAGE_MAGIC_DEAD UINT32_C(0x18550331)
570
571
572/** Image usage record. */
573typedef struct SUPDRVLDRUSAGE
574{
575 /** Next in chain. */
576 struct SUPDRVLDRUSAGE * volatile pNext;
577 /** The image. */
578 PSUPDRVLDRIMAGE pImage;
579 /** Load count (ring-3). */
580 uint32_t volatile cRing3Usage;
581 /** Ring-0 usage counter. */
582 uint32_t volatile cRing0Usage;
583} SUPDRVLDRUSAGE, *PSUPDRVLDRUSAGE;
584
585
586/**
587 * Component factory registration record.
588 */
589typedef struct SUPDRVFACTORYREG
590{
591 /** Pointer to the next registration. */
592 struct SUPDRVFACTORYREG *pNext;
593 /** Pointer to the registered factory. */
594 PCSUPDRVFACTORY pFactory;
595 /** The session owning the factory.
596 * Used for deregistration and session cleanup. */
597 PSUPDRVSESSION pSession;
598 /** Length of the name. */
599 size_t cchName;
600} SUPDRVFACTORYREG;
601/** Pointer to a component factory registration record. */
602typedef SUPDRVFACTORYREG *PSUPDRVFACTORYREG;
603/** Pointer to a const component factory registration record. */
604typedef SUPDRVFACTORYREG const *PCSUPDRVFACTORYREG;
605
606
607/**
608 * Registered object.
609 * This takes care of reference counting and tracking data for access checks.
610 */
611typedef struct SUPDRVOBJ
612{
613 /** Magic value (SUPDRVOBJ_MAGIC). */
614 uint32_t u32Magic;
615 /** The object type. */
616 SUPDRVOBJTYPE enmType;
617 /** Pointer to the next in the global list. */
618 struct SUPDRVOBJ * volatile pNext;
619 /** Pointer to the object destructor.
620 * This may be set to NULL if the image containing the destructor get unloaded. */
621 PFNSUPDRVDESTRUCTOR pfnDestructor;
622 /** User argument 1. */
623 void *pvUser1;
624 /** User argument 2. */
625 void *pvUser2;
626 /** The total sum of all per-session usage. */
627 uint32_t volatile cUsage;
628 /** The creator user id. */
629 RTUID CreatorUid;
630 /** The creator group id. */
631 RTGID CreatorGid;
632 /** The creator process id. */
633 RTPROCESS CreatorProcess;
634} SUPDRVOBJ, *PSUPDRVOBJ;
635
636/** Magic number for SUPDRVOBJ::u32Magic. (Dame Agatha Mary Clarissa Christie). */
637#define SUPDRVOBJ_MAGIC UINT32_C(0x18900915)
638/** Dead number magic for SUPDRVOBJ::u32Magic. */
639#define SUPDRVOBJ_MAGIC_DEAD UINT32_C(0x19760112)
640
641/**
642 * The per-session object usage record.
643 */
644typedef struct SUPDRVUSAGE
645{
646 /** Pointer to the next in the list. */
647 struct SUPDRVUSAGE * volatile pNext;
648 /** Pointer to the object we're recording usage for. */
649 PSUPDRVOBJ pObj;
650 /** The usage count. */
651 uint32_t volatile cUsage;
652} SUPDRVUSAGE, *PSUPDRVUSAGE;
653
654
655/**
656 * I/O control context.
657 */
658typedef struct SUPR0IOCTLCTX
659{
660 /** Magic value (SUPR0IOCTLCTX_MAGIC). */
661 uint32_t u32Magic;
662 /** Reference counter. */
663 uint32_t volatile cRefs;
664#ifdef RT_OS_WINDOWS
665# ifndef SUPDRV_AGNOSTIC
666 /** The file object, referenced. */
667 PFILE_OBJECT pFileObject;
668 /** The device object, not referenced. */
669 PDEVICE_OBJECT pDeviceObject;
670 /** Pointer to fast I/O routine if available. */
671 FAST_IO_DEVICE_CONTROL *pfnFastIoDeviceControl;
672# else
673 void *apvPadding[3];
674# endif
675#endif
676} SUPR0IOCTLCTX;
677/** Magic value for SUPR0IOCTLCTX (Ahmad Jamal). */
678#define SUPR0IOCTLCTX_MAGIC UINT32_C(0x19300702)
679
680
681/**
682 * Per session data.
683 * This is mainly for memory tracking.
684 */
685typedef struct SUPDRVSESSION
686{
687 /** Pointer to the device extension. */
688 PSUPDRVDEVEXT pDevExt;
689 /** Session Cookie. */
690 uint32_t u32Cookie;
691 /** Set if is an unrestricted session, clear if restricted. */
692 bool fUnrestricted;
693
694 /** Set if we're in the hash table, clear if not. Protected by the hash
695 * table spinlock. */
696 bool fInHashTable;
697 /** Reference counter. */
698 uint32_t volatile cRefs;
699 /** Pointer to the next session with the same hash (common hash table).
700 * Protected by the hash table spinlock. */
701 PSUPDRVSESSION pCommonNextHash;
702 /** Pointer to the OS specific session pointer, if available and in use.
703 * This is atomically set and cleared as the session is inserted and removed
704 * from the hash table (protected by the session hash table spinlock). */
705 PSUPDRVSESSION *ppOsSessionPtr;
706 /** The process (id) of the session. */
707 RTPROCESS Process;
708 /** Which process this session is associated with.
709 * This is NIL_RTR0PROCESS for kernel sessions and valid for user ones. */
710 RTR0PROCESS R0Process;
711
712 /** The GVM associated with the session.
713 * This is set by VMMR0. */
714 PGVM pSessionGVM;
715 /** The VM associated with the session.
716 * This is set by VMMR0. */
717 PVM pSessionVM;
718 /** Set to pSessionVM if fast I/O controlls are enabled. */
719 PVM pFastIoCtrlVM;
720 /** Handle table for IPRT semaphore wrapper APIs.
721 * This takes care of its own locking in an IRQ safe manner. */
722 RTHANDLETABLE hHandleTable;
723 /** Load usage records (LIFO!). (protected by SUPDRVDEVEXT::mtxLdr) */
724 PSUPDRVLDRUSAGE volatile pLdrUsage;
725
726 /** Spinlock protecting the bundles, the GIP members and the
727 * fProcessCleanupDone flag. It continues to be valid until the last
728 * reference to the session is released. */
729 RTSPINLOCK Spinlock;
730 /** The ring-3 mapping of the GIP (readonly). */
731 RTR0MEMOBJ GipMapObjR3;
732 /** Set if the session is using the GIP. */
733 uint32_t fGipReferenced;
734 /** Bundle of locked memory objects. */
735 SUPDRVBUNDLE Bundle;
736 /** List of generic usage records. (protected by SUPDRVDEVEXT::SpinLock) */
737 PSUPDRVUSAGE volatile pUsage;
738
739 /** The user id of the session - set by the OS part or NIL_RTUID.
740 * This should be unique accross namespace/zones/whatever. */
741 RTUID Uid;
742 /** The group id of the session - set by the OS part or NIL_RTGID.
743 * This should be unique accross namespace/zones/whatever. */
744 RTGID Gid;
745 /** Per session tracer specfic data. */
746 uintptr_t uTracerData;
747 /** The thread currently actively talking to the tracer. (One at the time!) */
748 RTNATIVETHREAD hTracerCaller;
749 /** List of tracepoint providers associated with the session
750 * (SUPDRVTPPROVIDER). */
751 RTLISTANCHOR TpProviders;
752 /** The number of providers in TpProviders. */
753 uint32_t cTpProviders;
754 /** The number of threads active in supdrvIOCtl_TracerUmodProbeFire or
755 * SUPR0TracerUmodProbeFire. */
756 uint32_t volatile cTpProbesFiring;
757 /** User tracepoint modules (PSUPDRVTRACKERUMOD). */
758 RTLISTANCHOR TpUmods;
759 /** The user tracepoint module lookup table. */
760 struct SUPDRVTRACERUMOD *apTpLookupTable[32];
761 /** Whether this is a GIP test-mode client session or not. */
762 bool fGipTestMode;
763#ifndef SUPDRV_AGNOSTIC
764# if defined(RT_OS_DARWIN)
765 /** Pointer to the associated org_virtualbox_SupDrvClient object. */
766 void *pvSupDrvClient;
767 /** Whether this session has been opened or not. */
768 bool fOpened;
769# endif
770# if defined(RT_OS_OS2)
771 /** The system file number of this session. */
772 uint16_t sfn;
773 uint16_t Alignment; /**< Alignment */
774# endif
775# if defined(RT_OS_DARWIN) || defined(RT_OS_OS2) || defined(RT_OS_SOLARIS)
776 /** Pointer to the next session with the same hash. */
777 PSUPDRVSESSION pNextHash;
778# endif
779# if defined(RT_OS_WINDOWS) && defined(VBOX_WITH_HARDENING)
780 /** Pointer to the process protection structure for this session. */
781 struct SUPDRVNTPROTECT *pNtProtect;
782# endif
783# if defined(RT_OS_WINDOWS)
784 /** Reference to the user ID structure corresponding to the Uid member. */
785 struct SUPDRVNTUSERID *pNtUserId;
786# endif
787#endif /* !SUPDRV_AGNOSTIC */
788} SUPDRVSESSION;
789
790
791/**
792 * Device extension.
793 */
794typedef struct SUPDRVDEVEXT
795{
796 /** Global cookie. */
797 uint32_t u32Cookie;
798 /** The actual size of SUPDRVSESSION. (SUPDRV_AGNOSTIC) */
799 uint32_t cbSession;
800
801 /** Spinlock to serialize the initialization, usage counting and objects.
802 * This is IRQ safe because we want to be able signal semaphores from the
803 * special HM context (and later maybe interrupt handlers), so we must be able
804 * to reference and dereference handles when IRQs are disabled. */
805 RTSPINLOCK Spinlock;
806
807 /** List of registered objects. Protected by the spinlock. */
808 PSUPDRVOBJ volatile pObjs;
809 /** List of free object usage records. */
810 PSUPDRVUSAGE volatile pUsageFree;
811
812 /** Loader mutex.
813 * This protects pvVMMR0, pvVMMR0Entry, pImages and SUPDRVSESSION::pLdrUsage. */
814#ifdef SUPDRV_USE_MUTEX_FOR_LDR
815 RTSEMMUTEX mtxLdr;
816#else
817 RTSEMFASTMUTEX mtxLdr;
818#endif
819
820 /** VMM Module 'handle'.
821 * 0 if the code VMM isn't loaded and Idt are nops. */
822 void * volatile pvVMMR0;
823 /** VMMR0EntryFast() pointer. */
824 DECLR0CALLBACKMEMBER(void, pfnVMMR0EntryFast, (PGVM pGVM, PVM pVM, VMCPUID idCpu, uint32_t uOperation));
825 /** VMMR0EntryEx() pointer. */
826 DECLR0CALLBACKMEMBER(int, pfnVMMR0EntryEx, (PGVM pGVM, PVM pVM, VMCPUID idCpu, uint32_t uOperation,
827 PSUPVMMR0REQHDR pReq, uint64_t u64Arg, PSUPDRVSESSION pSession));
828
829 /** Linked list of loaded code. */
830 PSUPDRVLDRIMAGE volatile pLdrImages;
831 /** Set if the image loading interface got disabled after loading all needed images */
832 bool fLdrLockedDown;
833
834 /** @name These members for detecting whether an API caller is in ModuleInit.
835 * Certain APIs are only permitted from ModuleInit, like for instance tracepoint
836 * registration.
837 * @{ */
838 /** The image currently executing its ModuleInit. */
839 PSUPDRVLDRIMAGE volatile pLdrInitImage;
840 /** The thread currently executing a ModuleInit function. */
841 RTNATIVETHREAD volatile hLdrInitThread;
842 /** The thread currently executing a ModuleTerm function. */
843 RTNATIVETHREAD volatile hLdrTermThread;
844 /** @} */
845
846 /** Number of times someone reported bad execution context via SUPR0BadContext.
847 * (This is times EFLAGS.AC is zero when we expected it to be 1.) */
848 uint32_t volatile cBadContextCalls;
849
850 /** GIP mutex.
851 * Any changes to any of the GIP members requires ownership of this mutex,
852 * except on driver init and termination. */
853#ifdef SUPDRV_USE_MUTEX_FOR_GIP
854 RTSEMMUTEX mtxGip;
855#else
856 RTSEMFASTMUTEX mtxGip;
857#endif
858 /** GIP spinlock protecting GIP members during Mp events.
859 * This is IRQ safe since be may get MP callbacks in contexts where IRQs are
860 * disabled (on some platforms). */
861 RTSPINLOCK hGipSpinlock;
862 /** Pointer to the Global Info Page (GIP). */
863 PSUPGLOBALINFOPAGE pGip;
864 /** The physical address of the GIP. */
865 RTHCPHYS HCPhysGip;
866 /** Number of processes using the GIP.
867 * (The updates are suspend while cGipUsers is 0.)*/
868 uint32_t volatile cGipUsers;
869 /** The ring-0 memory object handle for the GIP page. */
870 RTR0MEMOBJ GipMemObj;
871 /** The GIP timer handle. */
872 PRTTIMER pGipTimer;
873 /** If non-zero we've successfully called RTTimerRequestSystemGranularity(). */
874 uint32_t u32SystemTimerGranularityGrant;
875 /** The CPU id of the GIP master.
876 * This CPU is responsible for the updating the common GIP data and it is
877 * the one used to calculate TSC deltas relative to.
878 * (The initial master will have a 0 zero value, but it it goes offline the
879 * new master may have a non-zero value.) */
880 RTCPUID volatile idGipMaster;
881
882 /** Component factory mutex.
883 * This protects pComponentFactoryHead and component factory querying. */
884 RTSEMFASTMUTEX mtxComponentFactory;
885 /** The head of the list of registered component factories. */
886 PSUPDRVFACTORYREG pComponentFactoryHead;
887
888 /** Lock protecting The tracer members. */
889 RTSEMFASTMUTEX mtxTracer;
890 /** List of tracer providers (SUPDRVTPPROVIDER). */
891 RTLISTANCHOR TracerProviderList;
892 /** List of zombie tracer providers (SUPDRVTPPROVIDER). */
893 RTLISTANCHOR TracerProviderZombieList;
894 /** Pointer to the tracer registration record. */
895 PCSUPDRVTRACERREG pTracerOps;
896 /** The ring-0 session of a native tracer provider. */
897 PSUPDRVSESSION pTracerSession;
898 /** The image containing the tracer. */
899 PSUPDRVLDRIMAGE pTracerImage;
900 /** The tracer helpers. */
901 SUPDRVTRACERHLP TracerHlp;
902 /** The number of session having opened the tracer currently. */
903 uint32_t cTracerOpens;
904 /** The number of threads currently calling into the tracer. */
905 uint32_t volatile cTracerCallers;
906 /** Set if the tracer is being unloaded. */
907 bool fTracerUnloading;
908 /** Hash table for user tracer modules (SUPDRVVTGCOPY). */
909 RTLISTANCHOR aTrackerUmodHash[128];
910
911 /** @name Session Handle Table.
912 * @{ */
913 /** Spinlock protecting apSessionHashTab, cSessions,
914 * SUPDRVSESSION::ppOsSessionPtr, SUPDRVSESSION::pCommonNextHash, and possibly
915 * others depending on the OS. */
916 RTSPINLOCK hSessionHashTabSpinlock;
917 /** Session hash table hash table. The size of this table must make sense in
918 * comparison to GVMM_MAX_HANDLES. */
919 PSUPDRVSESSION apSessionHashTab[HC_ARCH_BITS == 64 ? 8191 : 127];
920 /** The number of open sessions. */
921 int32_t cSessions;
922 /** @} */
923
924 /** @name Invariant TSC frequency refinement.
925 * @{ */
926 /** Nanosecond timestamp at the start of the TSC frequency refinement phase. */
927 uint64_t nsStartInvarTscRefine;
928 /** TSC reading at the start of the TSC frequency refinement phase. */
929 uint64_t uTscStartInvarTscRefine;
930 /** The CPU id of the CPU that u64TscAnchor was measured on. */
931 RTCPUID idCpuInvarTscRefine;
932 /** Pointer to the timer used to refine the TSC frequency. */
933 PRTTIMER pInvarTscRefineTimer;
934 /** Stop the timer on the next tick because we saw a power event. */
935 bool volatile fInvTscRefinePowerEvent;
936 /** @} */
937
938 /** @name TSC-delta measurement.
939 * @{ */
940 /** Number of online/offline events, incremented each time a CPU goes online
941 * or offline. */
942 uint32_t volatile cMpOnOffEvents;
943 /** TSC-delta measurement mutext.
944 * At the moment, we don't want to have more than one measurement going on at
945 * any one time. We might be using broadcast IPIs which are heavy and could
946 * perhaps get in each others way. */
947#ifdef SUPDRV_USE_MUTEX_FOR_GIP
948 RTSEMMUTEX mtxTscDelta;
949#else
950 RTSEMFASTMUTEX mtxTscDelta;
951#endif
952 /** The set of CPUs we need to take measurements for. */
953 RTCPUSET TscDeltaCpuSet;
954 /** The set of CPUs we have completed taken measurements for. */
955 RTCPUSET TscDeltaObtainedCpuSet;
956 /** @} */
957
958#ifdef SUPDRV_USE_TSC_DELTA_THREAD
959 /** @name TSC-delta measurement thread.
960 * @{ */
961 /** Spinlock protecting enmTscDeltaThreadState. */
962 RTSPINLOCK hTscDeltaSpinlock;
963 /** TSC-delta measurement thread. */
964 RTTHREAD hTscDeltaThread;
965 /** The event signalled during state changes to the TSC-delta thread. */
966 RTSEMEVENT hTscDeltaEvent;
967 /** The state of the TSC-delta measurement thread. */
968 SUPDRVTSCDELTATHREADSTATE enmTscDeltaThreadState;
969 /** Thread timeout time before rechecking state in ms. */
970 RTMSINTERVAL cMsTscDeltaTimeout;
971 /** Whether the TSC-delta measurement was successful. */
972 int32_t volatile rcTscDelta;
973 /** Tell the thread we want TSC-deltas for all CPUs with retries. */
974 bool fTscThreadRecomputeAllDeltas;
975 /** @} */
976#endif
977
978 /** @name GIP test mode.
979 * @{ */
980 /** Reference counter for GIP test-mode sessions. */
981 uint32_t cGipTestModeRefs;
982 /** Cache of TSC frequency before enabling test-mode on invariant GIP systems. */
983 uint64_t uGipTestModeInvariantCpuHz;
984 /** @} */
985
986 /*
987 * Note! The non-agnostic bits must be at the very end of the structure!
988 */
989#ifndef SUPDRV_AGNOSTIC
990# ifdef RT_OS_WINDOWS
991 /** Callback object returned by ExCreateCallback. */
992 PCALLBACK_OBJECT pObjPowerCallback;
993 /** Callback handle returned by ExRegisterCallback. */
994 PVOID hPowerCallback;
995# elif defined(RT_OS_DARWIN) && defined(VBOX_WITH_DARWIN_R0_DARWIN_IMAGE_VERIFICATION)
996 /** Trusted root certificates for code signing validation. */
997 RTCRSTORE hRootStore;
998 /** Intermedite certificates for code signing validation. */
999 RTCRSTORE hAdditionalStore;
1000# endif
1001#endif
1002} SUPDRVDEVEXT;
1003
1004/** Calculates the index into g_apSessionHashTab.*/
1005#define SUPDRV_SESSION_HASH(a_pid) ( (a_pid) % RT_ELEMENTS(((SUPDRVDEVEXT *)NULL)->apSessionHashTab) )
1006
1007
1008RT_C_DECLS_BEGIN
1009
1010/*******************************************************************************
1011* OS Specific Functions *
1012*******************************************************************************/
1013/**
1014 * Called to clean up the session structure before it's freed.
1015 *
1016 * @param pDevExt The device globals.
1017 * @param pSession The session that's being cleaned up.
1018 */
1019void VBOXCALL supdrvOSCleanupSession(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession);
1020
1021/**
1022 * Called to let the OS specfic code perform additional insertion work while
1023 * still under the protection of the hash table spinlock.
1024 *
1025 * @param pDevExt The device globals.
1026 * @param pSession The session that was inserted.
1027 * @param pvUser User context specified to the insert call.
1028 */
1029void VBOXCALL supdrvOSSessionHashTabInserted(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, void *pvUser);
1030
1031/**
1032 * Called to let the OS specfic code perform additional removal work while still
1033 * under the protection of the hash table spinlock.
1034 *
1035 * @param pDevExt The device globals.
1036 * @param pSession The session that was removed.
1037 * @param pvUser User context specified to the remove call.
1038 */
1039void VBOXCALL supdrvOSSessionHashTabRemoved(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, void *pvUser);
1040
1041/**
1042 * Called during GIP initializtion to calc the CPU group table size.
1043 *
1044 * This is currently only implemented on windows [lazy bird].
1045 *
1046 * @returns Number of bytes needed for SUPGIPCPUGROUP structures.
1047 * @param pDevExt The device globals.
1048 */
1049size_t VBOXCALL supdrvOSGipGetGroupTableSize(PSUPDRVDEVEXT pDevExt);
1050
1051/**
1052 * Called during GIP initialization to set up the group table and group count.
1053 *
1054 * This is currently only implemented on windows [lazy bird].
1055 *
1056 * @param pDevExt The device globals.
1057 * @param pGip The GIP which group table needs initialization.
1058 * It's only partially initialized at this point.
1059 * @param cbGipCpuGroups What supdrvOSGipGetGroupTableSize returned.
1060 */
1061int VBOXCALL supdrvOSInitGipGroupTable(PSUPDRVDEVEXT pDevExt, PSUPGLOBALINFOPAGE pGip, size_t cbGipCpuGroups);
1062
1063/**
1064 * Initializes the group related members when a CPU is added to the GIP.
1065 *
1066 * This is called both during GIP initalization and during an CPU online event.
1067 *
1068 * This is currently only implemented on windows [lazy bird].
1069 *
1070 * @returns CPU group number.
1071 * @param pDevExt The device globals.
1072 * @param pGip The GIP.
1073 * @param pGipCpu The GIP CPU structure being initialized.
1074 */
1075void VBOXCALL supdrvOSGipInitGroupBitsForCpu(PSUPDRVDEVEXT pDevExt, PSUPGLOBALINFOPAGE pGip, PSUPGIPCPU pGipCpu);
1076
1077void VBOXCALL supdrvOSObjInitCreator(PSUPDRVOBJ pObj, PSUPDRVSESSION pSession);
1078bool VBOXCALL supdrvOSObjCanAccess(PSUPDRVOBJ pObj, PSUPDRVSESSION pSession, const char *pszObjName, int *prc);
1079bool VBOXCALL supdrvOSGetForcedAsyncTscMode(PSUPDRVDEVEXT pDevExt);
1080bool VBOXCALL supdrvOSAreCpusOfflinedOnSuspend(void);
1081bool VBOXCALL supdrvOSAreTscDeltasInSync(void);
1082int VBOXCALL supdrvOSEnableVTx(bool fEnabled);
1083RTCCUINTREG VBOXCALL supdrvOSChangeCR4(RTCCUINTREG fOrMask, RTCCUINTREG fAndMask);
1084bool VBOXCALL supdrvOSSuspendVTxOnCpu(void);
1085void VBOXCALL supdrvOSResumeVTxOnCpu(bool fSuspended);
1086int VBOXCALL supdrvOSGetCurrentGdtRw(RTHCUINTPTR *pGdtRw);
1087
1088/**
1089 * Try open the image using the native loader.
1090 *
1091 * @returns IPRT status code.
1092 * @retval VERR_NOT_SUPPORTED if native loading isn't supported.
1093 *
1094 * @param pDevExt The device globals.
1095 * @param pImage The image handle. pvImage should be set on
1096 * success, pvImageAlloc can also be set if
1097 * appropriate.
1098 * @param pszFilename The file name - UTF-8, may containing UNIX
1099 * slashes on non-UNIX systems.
1100 */
1101int VBOXCALL supdrvOSLdrOpen(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, const char *pszFilename);
1102
1103/**
1104 * Notification call indicating that a image is being opened for the first time.
1105 *
1106 * Called for both native and non-native images (after supdrvOSLdrOpen). Can be
1107 * used to log the load address of the image or inform the kernel about the
1108 * alien image.
1109 *
1110 * @param pDevExt The device globals.
1111 * @param pImage The image handle.
1112 * @param pszFilename The file name - UTF-8, may containing UNIX
1113 * slashes on non-UNIX systems.
1114 */
1115void VBOXCALL supdrvOSLdrNotifyOpened(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, const char *pszFilename);
1116
1117/**
1118 * Validates an entry point address.
1119 *
1120 * Called before supdrvOSLdrLoad.
1121 *
1122 * @returns IPRT status code.
1123 * @param pDevExt The device globals.
1124 * @param pImage The image data (still in the open state).
1125 * @param pv The address within the image.
1126 * @param pbImageBits The image bits as loaded by ring-3.
1127 * @param pszSymbol The name of the entrypoint being checked.
1128 */
1129int VBOXCALL supdrvOSLdrValidatePointer(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage,
1130 void *pv, const uint8_t *pbImageBits, const char *pszSymbol);
1131
1132/**
1133 * Load the image.
1134 *
1135 * @returns IPRT status code.
1136 * @param pDevExt The device globals.
1137 * @param pImage The image data (up to date). Adjust entrypoints
1138 * and exports if necessary.
1139 * @param pbImageBits The image bits as loaded by ring-3.
1140 * @param pReq Pointer to the request packet so that the VMMR0
1141 * entry points can be adjusted.
1142 */
1143int VBOXCALL supdrvOSLdrLoad(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, const uint8_t *pbImageBits, PSUPLDRLOAD pReq);
1144
1145/**
1146 * Unload the image (only called if supdrvOSLdrOpen returned success).
1147 *
1148 * @param pDevExt The device globals.
1149 * @param pImage The image data (mostly still valid).
1150 */
1151void VBOXCALL supdrvOSLdrUnload(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage);
1152
1153/**
1154 * Notification call indicating that a image is being unloaded.
1155 *
1156 * Called for both native and non-native images. In the former case, it's
1157 * called after supdrvOSLdrUnload.
1158 *
1159 * @param pDevExt The device globals.
1160 * @param pImage The image handle.
1161 */
1162void VBOXCALL supdrvOSLdrNotifyUnloaded(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage);
1163
1164/**
1165 * Queries a symbol address is a native module.
1166 *
1167 * @returns IPRT status code.
1168 * @param pDevExt The device globals.
1169 * @param pImage The image to search.
1170 * @param pszSymbol The symbol to search for.
1171 * @param cchSymbol The length of the symbol.
1172 * @param ppvSymbol Where to return the symbol address if found.
1173 */
1174int VBOXCALL supdrvOSLdrQuerySymbol(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage,
1175 const char *pszSymbol, size_t cchSymbol, void **ppvSymbol);
1176
1177/**
1178 * Retains a native wrapper module when it is first being used.
1179 *
1180 * This will be call when pImage->cImgUsage is incremented to 2.
1181 *
1182 * @param pDevExt The device globals.
1183 * @param pImage The wrapped image.
1184 */
1185void VBOXCALL supdrvOSLdrRetainWrapperModule(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage);
1186
1187/**
1188 * Release a native wrapper module when it is no longer being used.
1189 *
1190 * This will be call when pImage->cImgUsage is decremented to 1.
1191 *
1192 * @param pDevExt The device globals.
1193 * @param pImage The wrapped image.
1194 */
1195void VBOXCALL supdrvOSLdrReleaseWrapperModule(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage);
1196
1197#ifdef SUPDRV_WITH_MSR_PROBER
1198
1199/**
1200 * Tries to read an MSR.
1201 *
1202 * @returns One of the listed VBox status codes.
1203 * @retval VINF_SUCCESS if read successfully, value in *puValue.
1204 * @retval VERR_ACCESS_DENIED if we couldn't read it (GP).
1205 * @retval VERR_NOT_SUPPORTED if not supported.
1206 *
1207 * @param uMsr The MSR to read from.
1208 * @param idCpu The CPU to read the MSR on. NIL_RTCPUID
1209 * indicates any suitable CPU.
1210 * @param puValue Where to return the value.
1211 */
1212int VBOXCALL supdrvOSMsrProberRead(uint32_t uMsr, RTCPUID idCpu, uint64_t *puValue);
1213
1214/**
1215 * Tries to write an MSR.
1216 *
1217 * @returns One of the listed VBox status codes.
1218 * @retval VINF_SUCCESS if written successfully.
1219 * @retval VERR_ACCESS_DENIED if we couldn't write the value to it (GP).
1220 * @retval VERR_NOT_SUPPORTED if not supported.
1221 *
1222 * @param uMsr The MSR to write to.
1223 * @param idCpu The CPU to write the MSR on. NIL_RTCPUID
1224 * indicates any suitable CPU.
1225 * @param uValue The value to write.
1226 */
1227int VBOXCALL supdrvOSMsrProberWrite(uint32_t uMsr, RTCPUID idCpu, uint64_t uValue);
1228
1229/**
1230 * Tries to modify an MSR value.
1231 *
1232 * @returns One of the listed VBox status codes.
1233 * @retval VINF_SUCCESS if succeeded.
1234 * @retval VERR_NOT_SUPPORTED if not supported.
1235 *
1236 * @param idCpu The CPU to modify the MSR on. NIL_RTCPUID
1237 * indicates any suitable CPU.
1238 * @param pReq The request packet with input arguments and
1239 * where to store the results.
1240 */
1241int VBOXCALL supdrvOSMsrProberModify(RTCPUID idCpu, PSUPMSRPROBER pReq);
1242
1243#endif /* SUPDRV_WITH_MSR_PROBER */
1244
1245#if defined(RT_OS_DARWIN)
1246int VBOXCALL supdrvDarwinResumeSuspendedKbds(void);
1247#endif
1248
1249
1250/*********************************************************************************************************************************
1251* Shared Functions *
1252*********************************************************************************************************************************/
1253/* SUPDrv.c */
1254int VBOXCALL supdrvIOCtl(uintptr_t uIOCtl, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPREQHDR pReqHdr, size_t cbReq);
1255int VBOXCALL supdrvIOCtlFast(uintptr_t uOperation, VMCPUID idCpu, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession);
1256int VBOXCALL supdrvIDC(uintptr_t uIOCtl, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPDRVIDCREQHDR pReqHdr);
1257int VBOXCALL supdrvInitDevExt(PSUPDRVDEVEXT pDevExt, size_t cbSession);
1258void VBOXCALL supdrvDeleteDevExt(PSUPDRVDEVEXT pDevExt);
1259int VBOXCALL supdrvCreateSession(PSUPDRVDEVEXT pDevExt, bool fUser, bool fUnrestricted, PSUPDRVSESSION *ppSession);
1260int VBOXCALL supdrvSessionHashTabInsert(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPDRVSESSION *ppOsSessionPtr, void *pvUser);
1261int VBOXCALL supdrvSessionHashTabRemove(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, void *pvUser);
1262PSUPDRVSESSION VBOXCALL supdrvSessionHashTabLookup(PSUPDRVDEVEXT pDevExt, RTPROCESS Process, RTR0PROCESS R0Process,
1263 PSUPDRVSESSION *ppOsSessionPtr);
1264uint32_t VBOXCALL supdrvSessionRetain(PSUPDRVSESSION pSession);
1265uint32_t VBOXCALL supdrvSessionRelease(PSUPDRVSESSION pSession);
1266void VBOXCALL supdrvBadContext(PSUPDRVDEVEXT pDevExt, const char *pszFile, uint32_t uLine, const char *pszExtra);
1267int VBOXCALL supdrvQueryVTCapsInternal(uint32_t *pfCaps);
1268int VBOXCALL supdrvLdrLoadError(int rc, PSUPLDRLOAD pReq, const char *pszFormat, ...);
1269int VBOXCALL supdrvLdrGetExportedSymbol(const char *pszSymbol, uintptr_t *puValue);
1270int VBOXCALL supdrvLdrRegisterWrappedModule(PSUPDRVDEVEXT pDevExt, PCSUPLDRWRAPPEDMODULE pWrappedModInfo,
1271 void *pvNative, void **phMod);
1272int VBOXCALL supdrvLdrDeregisterWrappedModule(PSUPDRVDEVEXT pDevExt, PCSUPLDRWRAPPEDMODULE pWrappedModInfo, void **phMod);
1273
1274
1275/* SUPDrvGip.cpp */
1276int VBOXCALL supdrvGipCreate(PSUPDRVDEVEXT pDevExt);
1277void VBOXCALL supdrvGipDestroy(PSUPDRVDEVEXT pDevExt);
1278int VBOXCALL supdrvIOCtl_TscDeltaMeasure(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPTSCDELTAMEASURE pReq);
1279int VBOXCALL supdrvIOCtl_TscRead(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPTSCREAD pReq);
1280int VBOXCALL supdrvIOCtl_GipSetFlags(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, uint32_t fOrMask, uint32_t fAndMask);
1281
1282
1283/* SUPDrvTracer.cpp */
1284int VBOXCALL supdrvTracerInit(PSUPDRVDEVEXT pDevExt);
1285void VBOXCALL supdrvTracerTerm(PSUPDRVDEVEXT pDevExt);
1286void VBOXCALL supdrvTracerModuleUnloading(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage);
1287void VBOXCALL supdrvTracerCleanupSession(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession);
1288int VBOXCALL supdrvIOCtl_TracerUmodRegister(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession,
1289 RTR3PTR R3PtrVtgHdr, RTUINTPTR uVtgHdrAddr,
1290 RTR3PTR R3PtrStrTab, uint32_t cbStrTab,
1291 const char *pszModName, uint32_t fFlags);
1292int VBOXCALL supdrvIOCtl_TracerUmodDeregister(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, RTR3PTR R3PtrVtgHdr);
1293void VBOXCALL supdrvIOCtl_TracerUmodProbeFire(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPDRVTRACERUSRCTX pCtx);
1294int VBOXCALL supdrvIOCtl_TracerOpen(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, uint32_t uCookie, uintptr_t uArg);
1295int VBOXCALL supdrvIOCtl_TracerClose(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession);
1296int VBOXCALL supdrvIOCtl_TracerIOCtl(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, uintptr_t uCmd, uintptr_t uArg, int32_t *piRetVal);
1297extern PFNRT g_pfnSupdrvProbeFireKernel;
1298DECLASM(void) supdrvTracerProbeFireStub(void);
1299
1300#ifdef VBOX_WITH_NATIVE_DTRACE
1301const SUPDRVTRACERREG * VBOXCALL supdrvDTraceInit(void);
1302void VBOXCALL supdrvDTraceFini(void);
1303#endif
1304
1305RT_C_DECLS_END
1306
1307#endif /* !VBOX_INCLUDED_SRC_Support_SUPDrvInternal_h */
1308
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