VirtualBox

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

Last change on this file since 100108 was 99861, checked in by vboxsync, 19 months ago

Linux: vboxdrv: suppress false-positive warning caused by CONFIG_FORTIFY_SOURCE kernel config option (for RHEL 9.3 kernel), bugref:10209, ticketref:21671.

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