VirtualBox

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

Last change on this file since 91551 was 91551, checked in by vboxsync, 3 years ago

SUPDrV: The SUPDRVSESSION::Uid & Gid members should be the kernel versions, not the within-current-namespace stuff we've been using thus far on linux.

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

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