VirtualBox

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

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

SUPDrv/win: Added mapping of NT security IDs to 32-bit UID values - not enabled yet. bugref:10093

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 51.0 KB
Line 
1/* $Id: SUPDrvInternal.h 91559 2021-10-05 08:28:55Z 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# if defined(RT_OS_WINDOWS)
776 /** Reference to the user ID structure corresponding to the Uid member. */
777 struct SUPDRVNTUSERID *pNtUserId;
778# endif
779#endif /* !SUPDRV_AGNOSTIC */
780} SUPDRVSESSION;
781
782
783/**
784 * Device extension.
785 */
786typedef struct SUPDRVDEVEXT
787{
788 /** Global cookie. */
789 uint32_t u32Cookie;
790 /** The actual size of SUPDRVSESSION. (SUPDRV_AGNOSTIC) */
791 uint32_t cbSession;
792
793 /** Spinlock to serialize the initialization, usage counting and objects.
794 * This is IRQ safe because we want to be able signal semaphores from the
795 * special HM context (and later maybe interrupt handlers), so we must be able
796 * to reference and dereference handles when IRQs are disabled. */
797 RTSPINLOCK Spinlock;
798
799 /** List of registered objects. Protected by the spinlock. */
800 PSUPDRVOBJ volatile pObjs;
801 /** List of free object usage records. */
802 PSUPDRVUSAGE volatile pUsageFree;
803
804 /** Loader mutex.
805 * This protects pvVMMR0, pvVMMR0Entry, pImages and SUPDRVSESSION::pLdrUsage. */
806#ifdef SUPDRV_USE_MUTEX_FOR_LDR
807 RTSEMMUTEX mtxLdr;
808#else
809 RTSEMFASTMUTEX mtxLdr;
810#endif
811
812 /** VMM Module 'handle'.
813 * 0 if the code VMM isn't loaded and Idt are nops. */
814 void * volatile pvVMMR0;
815 /** VMMR0EntryFast() pointer. */
816 DECLR0CALLBACKMEMBER(void, pfnVMMR0EntryFast, (PGVM pGVM, PVM pVM, VMCPUID idCpu, uint32_t uOperation));
817 /** VMMR0EntryEx() pointer. */
818 DECLR0CALLBACKMEMBER(int, pfnVMMR0EntryEx, (PGVM pGVM, PVM pVM, VMCPUID idCpu, uint32_t uOperation,
819 PSUPVMMR0REQHDR pReq, uint64_t u64Arg, PSUPDRVSESSION pSession));
820
821 /** Linked list of loaded code. */
822 PSUPDRVLDRIMAGE volatile pLdrImages;
823 /** Set if the image loading interface got disabled after loading all needed images */
824 bool fLdrLockedDown;
825
826 /** @name These members for detecting whether an API caller is in ModuleInit.
827 * Certain APIs are only permitted from ModuleInit, like for instance tracepoint
828 * registration.
829 * @{ */
830 /** The image currently executing its ModuleInit. */
831 PSUPDRVLDRIMAGE volatile pLdrInitImage;
832 /** The thread currently executing a ModuleInit function. */
833 RTNATIVETHREAD volatile hLdrInitThread;
834 /** The thread currently executing a ModuleTerm function. */
835 RTNATIVETHREAD volatile hLdrTermThread;
836 /** @} */
837
838 /** Number of times someone reported bad execution context via SUPR0BadContext.
839 * (This is times EFLAGS.AC is zero when we expected it to be 1.) */
840 uint32_t volatile cBadContextCalls;
841
842 /** GIP mutex.
843 * Any changes to any of the GIP members requires ownership of this mutex,
844 * except on driver init and termination. */
845#ifdef SUPDRV_USE_MUTEX_FOR_GIP
846 RTSEMMUTEX mtxGip;
847#else
848 RTSEMFASTMUTEX mtxGip;
849#endif
850 /** GIP spinlock protecting GIP members during Mp events.
851 * This is IRQ safe since be may get MP callbacks in contexts where IRQs are
852 * disabled (on some platforms). */
853 RTSPINLOCK hGipSpinlock;
854 /** Pointer to the Global Info Page (GIP). */
855 PSUPGLOBALINFOPAGE pGip;
856 /** The physical address of the GIP. */
857 RTHCPHYS HCPhysGip;
858 /** Number of processes using the GIP.
859 * (The updates are suspend while cGipUsers is 0.)*/
860 uint32_t volatile cGipUsers;
861 /** The ring-0 memory object handle for the GIP page. */
862 RTR0MEMOBJ GipMemObj;
863 /** The GIP timer handle. */
864 PRTTIMER pGipTimer;
865 /** If non-zero we've successfully called RTTimerRequestSystemGranularity(). */
866 uint32_t u32SystemTimerGranularityGrant;
867 /** The CPU id of the GIP master.
868 * This CPU is responsible for the updating the common GIP data and it is
869 * the one used to calculate TSC deltas relative to.
870 * (The initial master will have a 0 zero value, but it it goes offline the
871 * new master may have a non-zero value.) */
872 RTCPUID volatile idGipMaster;
873
874 /** Component factory mutex.
875 * This protects pComponentFactoryHead and component factory querying. */
876 RTSEMFASTMUTEX mtxComponentFactory;
877 /** The head of the list of registered component factories. */
878 PSUPDRVFACTORYREG pComponentFactoryHead;
879
880 /** Lock protecting The tracer members. */
881 RTSEMFASTMUTEX mtxTracer;
882 /** List of tracer providers (SUPDRVTPPROVIDER). */
883 RTLISTANCHOR TracerProviderList;
884 /** List of zombie tracer providers (SUPDRVTPPROVIDER). */
885 RTLISTANCHOR TracerProviderZombieList;
886 /** Pointer to the tracer registration record. */
887 PCSUPDRVTRACERREG pTracerOps;
888 /** The ring-0 session of a native tracer provider. */
889 PSUPDRVSESSION pTracerSession;
890 /** The image containing the tracer. */
891 PSUPDRVLDRIMAGE pTracerImage;
892 /** The tracer helpers. */
893 SUPDRVTRACERHLP TracerHlp;
894 /** The number of session having opened the tracer currently. */
895 uint32_t cTracerOpens;
896 /** The number of threads currently calling into the tracer. */
897 uint32_t volatile cTracerCallers;
898 /** Set if the tracer is being unloaded. */
899 bool fTracerUnloading;
900 /** Hash table for user tracer modules (SUPDRVVTGCOPY). */
901 RTLISTANCHOR aTrackerUmodHash[128];
902
903 /** @name Session Handle Table.
904 * @{ */
905 /** Spinlock protecting apSessionHashTab, cSessions,
906 * SUPDRVSESSION::ppOsSessionPtr, SUPDRVSESSION::pCommonNextHash, and possibly
907 * others depending on the OS. */
908 RTSPINLOCK hSessionHashTabSpinlock;
909 /** Session hash table hash table. The size of this table must make sense in
910 * comparison to GVMM_MAX_HANDLES. */
911 PSUPDRVSESSION apSessionHashTab[HC_ARCH_BITS == 64 ? 8191 : 127];
912 /** The number of open sessions. */
913 int32_t cSessions;
914 /** @} */
915
916 /** @name Invariant TSC frequency refinement.
917 * @{ */
918 /** Nanosecond timestamp at the start of the TSC frequency refinement phase. */
919 uint64_t nsStartInvarTscRefine;
920 /** TSC reading at the start of the TSC frequency refinement phase. */
921 uint64_t uTscStartInvarTscRefine;
922 /** The CPU id of the CPU that u64TscAnchor was measured on. */
923 RTCPUID idCpuInvarTscRefine;
924 /** Pointer to the timer used to refine the TSC frequency. */
925 PRTTIMER pInvarTscRefineTimer;
926 /** Stop the timer on the next tick because we saw a power event. */
927 bool volatile fInvTscRefinePowerEvent;
928 /** @} */
929
930 /** @name TSC-delta measurement.
931 * @{ */
932 /** Number of online/offline events, incremented each time a CPU goes online
933 * or offline. */
934 uint32_t volatile cMpOnOffEvents;
935 /** TSC-delta measurement mutext.
936 * At the moment, we don't want to have more than one measurement going on at
937 * any one time. We might be using broadcast IPIs which are heavy and could
938 * perhaps get in each others way. */
939#ifdef SUPDRV_USE_MUTEX_FOR_GIP
940 RTSEMMUTEX mtxTscDelta;
941#else
942 RTSEMFASTMUTEX mtxTscDelta;
943#endif
944 /** The set of CPUs we need to take measurements for. */
945 RTCPUSET TscDeltaCpuSet;
946 /** The set of CPUs we have completed taken measurements for. */
947 RTCPUSET TscDeltaObtainedCpuSet;
948 /** @} */
949
950#ifdef SUPDRV_USE_TSC_DELTA_THREAD
951 /** @name TSC-delta measurement thread.
952 * @{ */
953 /** Spinlock protecting enmTscDeltaThreadState. */
954 RTSPINLOCK hTscDeltaSpinlock;
955 /** TSC-delta measurement thread. */
956 RTTHREAD hTscDeltaThread;
957 /** The event signalled during state changes to the TSC-delta thread. */
958 RTSEMEVENT hTscDeltaEvent;
959 /** The state of the TSC-delta measurement thread. */
960 SUPDRVTSCDELTATHREADSTATE enmTscDeltaThreadState;
961 /** Thread timeout time before rechecking state in ms. */
962 RTMSINTERVAL cMsTscDeltaTimeout;
963 /** Whether the TSC-delta measurement was successful. */
964 int32_t volatile rcTscDelta;
965 /** Tell the thread we want TSC-deltas for all CPUs with retries. */
966 bool fTscThreadRecomputeAllDeltas;
967 /** @} */
968#endif
969
970 /** @name GIP test mode.
971 * @{ */
972 /** Reference counter for GIP test-mode sessions. */
973 uint32_t cGipTestModeRefs;
974 /** Cache of TSC frequency before enabling test-mode on invariant GIP systems. */
975 uint64_t uGipTestModeInvariantCpuHz;
976 /** @} */
977
978 /*
979 * Note! The non-agnostic bits must be at the very end of the structure!
980 */
981#ifndef SUPDRV_AGNOSTIC
982# ifdef RT_OS_WINDOWS
983 /** Callback object returned by ExCreateCallback. */
984 PCALLBACK_OBJECT pObjPowerCallback;
985 /** Callback handle returned by ExRegisterCallback. */
986 PVOID hPowerCallback;
987# elif defined(RT_OS_DARWIN) && defined(VBOX_WITH_DARWIN_R0_DARWIN_IMAGE_VERIFICATION)
988 /** Trusted root certificates for code signing validation. */
989 RTCRSTORE hRootStore;
990 /** Intermedite certificates for code signing validation. */
991 RTCRSTORE hAdditionalStore;
992# endif
993#endif
994} SUPDRVDEVEXT;
995
996/** Calculates the index into g_apSessionHashTab.*/
997#define SUPDRV_SESSION_HASH(a_pid) ( (a_pid) % RT_ELEMENTS(((SUPDRVDEVEXT *)NULL)->apSessionHashTab) )
998
999
1000RT_C_DECLS_BEGIN
1001
1002/*******************************************************************************
1003* OS Specific Functions *
1004*******************************************************************************/
1005/**
1006 * Called to clean up the session structure before it's freed.
1007 *
1008 * @param pDevExt The device globals.
1009 * @param pSession The session that's being cleaned up.
1010 */
1011void VBOXCALL supdrvOSCleanupSession(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession);
1012
1013/**
1014 * Called to let the OS specfic code perform additional insertion work while
1015 * still under the protection of the hash table spinlock.
1016 *
1017 * @param pDevExt The device globals.
1018 * @param pSession The session that was inserted.
1019 * @param pvUser User context specified to the insert call.
1020 */
1021void VBOXCALL supdrvOSSessionHashTabInserted(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, void *pvUser);
1022
1023/**
1024 * Called to let the OS specfic code perform additional removal work while still
1025 * under the protection of the hash table spinlock.
1026 *
1027 * @param pDevExt The device globals.
1028 * @param pSession The session that was removed.
1029 * @param pvUser User context specified to the remove call.
1030 */
1031void VBOXCALL supdrvOSSessionHashTabRemoved(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, void *pvUser);
1032
1033/**
1034 * Called during GIP initializtion to calc the CPU group table size.
1035 *
1036 * This is currently only implemented on windows [lazy bird].
1037 *
1038 * @returns Number of bytes needed for SUPGIPCPUGROUP structures.
1039 * @param pDevExt The device globals.
1040 */
1041size_t VBOXCALL supdrvOSGipGetGroupTableSize(PSUPDRVDEVEXT pDevExt);
1042
1043/**
1044 * Called during GIP initialization to set up the group table and group count.
1045 *
1046 * This is currently only implemented on windows [lazy bird].
1047 *
1048 * @param pDevExt The device globals.
1049 * @param pGip The GIP which group table needs initialization.
1050 * It's only partially initialized at this point.
1051 * @param cbGipCpuGroups What supdrvOSGipGetGroupTableSize returned.
1052 */
1053int VBOXCALL supdrvOSInitGipGroupTable(PSUPDRVDEVEXT pDevExt, PSUPGLOBALINFOPAGE pGip, size_t cbGipCpuGroups);
1054
1055/**
1056 * Initializes the group related members when a CPU is added to the GIP.
1057 *
1058 * This is called both during GIP initalization and during an CPU online event.
1059 *
1060 * This is currently only implemented on windows [lazy bird].
1061 *
1062 * @returns CPU group number.
1063 * @param pDevExt The device globals.
1064 * @param pGip The GIP.
1065 * @param pGipCpu The GIP CPU structure being initialized.
1066 */
1067void VBOXCALL supdrvOSGipInitGroupBitsForCpu(PSUPDRVDEVEXT pDevExt, PSUPGLOBALINFOPAGE pGip, PSUPGIPCPU pGipCpu);
1068
1069void VBOXCALL supdrvOSObjInitCreator(PSUPDRVOBJ pObj, PSUPDRVSESSION pSession);
1070bool VBOXCALL supdrvOSObjCanAccess(PSUPDRVOBJ pObj, PSUPDRVSESSION pSession, const char *pszObjName, int *prc);
1071bool VBOXCALL supdrvOSGetForcedAsyncTscMode(PSUPDRVDEVEXT pDevExt);
1072bool VBOXCALL supdrvOSAreCpusOfflinedOnSuspend(void);
1073bool VBOXCALL supdrvOSAreTscDeltasInSync(void);
1074int VBOXCALL supdrvOSEnableVTx(bool fEnabled);
1075RTCCUINTREG VBOXCALL supdrvOSChangeCR4(RTCCUINTREG fOrMask, RTCCUINTREG fAndMask);
1076bool VBOXCALL supdrvOSSuspendVTxOnCpu(void);
1077void VBOXCALL supdrvOSResumeVTxOnCpu(bool fSuspended);
1078int VBOXCALL supdrvOSGetCurrentGdtRw(RTHCUINTPTR *pGdtRw);
1079
1080/**
1081 * Try open the image using the native loader.
1082 *
1083 * @returns IPRT status code.
1084 * @retval VERR_NOT_SUPPORTED if native loading isn't supported.
1085 *
1086 * @param pDevExt The device globals.
1087 * @param pImage The image handle. pvImage should be set on
1088 * success, pvImageAlloc can also be set if
1089 * appropriate.
1090 * @param pszFilename The file name - UTF-8, may containing UNIX
1091 * slashes on non-UNIX systems.
1092 */
1093int VBOXCALL supdrvOSLdrOpen(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, const char *pszFilename);
1094
1095/**
1096 * Notification call indicating that a image is being opened for the first time.
1097 *
1098 * Called for both native and non-native images (after supdrvOSLdrOpen). Can be
1099 * used to log the load address of the image or inform the kernel about the
1100 * alien image.
1101 *
1102 * @param pDevExt The device globals.
1103 * @param pImage The image handle.
1104 * @param pszFilename The file name - UTF-8, may containing UNIX
1105 * slashes on non-UNIX systems.
1106 */
1107void VBOXCALL supdrvOSLdrNotifyOpened(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, const char *pszFilename);
1108
1109/**
1110 * Validates an entry point address.
1111 *
1112 * Called before supdrvOSLdrLoad.
1113 *
1114 * @returns IPRT status code.
1115 * @param pDevExt The device globals.
1116 * @param pImage The image data (still in the open state).
1117 * @param pv The address within the image.
1118 * @param pbImageBits The image bits as loaded by ring-3.
1119 * @param pszSymbol The name of the entrypoint being checked.
1120 */
1121int VBOXCALL supdrvOSLdrValidatePointer(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage,
1122 void *pv, const uint8_t *pbImageBits, const char *pszSymbol);
1123
1124/**
1125 * Load the image.
1126 *
1127 * @returns IPRT status code.
1128 * @param pDevExt The device globals.
1129 * @param pImage The image data (up to date). Adjust entrypoints
1130 * and exports if necessary.
1131 * @param pbImageBits The image bits as loaded by ring-3.
1132 * @param pReq Pointer to the request packet so that the VMMR0
1133 * entry points can be adjusted.
1134 */
1135int VBOXCALL supdrvOSLdrLoad(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, const uint8_t *pbImageBits, PSUPLDRLOAD pReq);
1136
1137/**
1138 * Unload the image (only called if supdrvOSLdrOpen returned success).
1139 *
1140 * @param pDevExt The device globals.
1141 * @param pImage The image data (mostly still valid).
1142 */
1143void VBOXCALL supdrvOSLdrUnload(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage);
1144
1145/**
1146 * Notification call indicating that a image is being unloaded.
1147 *
1148 * Called for both native and non-native images. In the former case, it's
1149 * called after supdrvOSLdrUnload.
1150 *
1151 * @param pDevExt The device globals.
1152 * @param pImage The image handle.
1153 */
1154void VBOXCALL supdrvOSLdrNotifyUnloaded(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage);
1155
1156/**
1157 * Queries a symbol address is a native module.
1158 *
1159 * @returns IPRT status code.
1160 * @param pDevExt The device globals.
1161 * @param pImage The image to search.
1162 * @param pszSymbol The symbol to search for.
1163 * @param cchSymbol The length of the symbol.
1164 * @param ppvSymbol Where to return the symbol address if found.
1165 */
1166int VBOXCALL supdrvOSLdrQuerySymbol(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage,
1167 const char *pszSymbol, size_t cchSymbol, void **ppvSymbol);
1168
1169/**
1170 * Retains a native wrapper module when it is first being used.
1171 *
1172 * This will be call when pImage->cImgUsage is incremented to 2.
1173 *
1174 * @param pDevExt The device globals.
1175 * @param pImage The wrapped image.
1176 */
1177void VBOXCALL supdrvOSLdrRetainWrapperModule(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage);
1178
1179/**
1180 * Release a native wrapper module when it is no longer being used.
1181 *
1182 * This will be call when pImage->cImgUsage is decremented to 1.
1183 *
1184 * @param pDevExt The device globals.
1185 * @param pImage The wrapped image.
1186 */
1187void VBOXCALL supdrvOSLdrReleaseWrapperModule(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage);
1188
1189#ifdef SUPDRV_WITH_MSR_PROBER
1190
1191/**
1192 * Tries to read an MSR.
1193 *
1194 * @returns One of the listed VBox status codes.
1195 * @retval VINF_SUCCESS if read successfully, value in *puValue.
1196 * @retval VERR_ACCESS_DENIED if we couldn't read it (GP).
1197 * @retval VERR_NOT_SUPPORTED if not supported.
1198 *
1199 * @param uMsr The MSR to read from.
1200 * @param idCpu The CPU to read the MSR on. NIL_RTCPUID
1201 * indicates any suitable CPU.
1202 * @param puValue Where to return the value.
1203 */
1204int VBOXCALL supdrvOSMsrProberRead(uint32_t uMsr, RTCPUID idCpu, uint64_t *puValue);
1205
1206/**
1207 * Tries to write an MSR.
1208 *
1209 * @returns One of the listed VBox status codes.
1210 * @retval VINF_SUCCESS if written successfully.
1211 * @retval VERR_ACCESS_DENIED if we couldn't write the value to it (GP).
1212 * @retval VERR_NOT_SUPPORTED if not supported.
1213 *
1214 * @param uMsr The MSR to write to.
1215 * @param idCpu The CPU to write the MSR on. NIL_RTCPUID
1216 * indicates any suitable CPU.
1217 * @param uValue The value to write.
1218 */
1219int VBOXCALL supdrvOSMsrProberWrite(uint32_t uMsr, RTCPUID idCpu, uint64_t uValue);
1220
1221/**
1222 * Tries to modify an MSR value.
1223 *
1224 * @returns One of the listed VBox status codes.
1225 * @retval VINF_SUCCESS if succeeded.
1226 * @retval VERR_NOT_SUPPORTED if not supported.
1227 *
1228 * @param idCpu The CPU to modify the MSR on. NIL_RTCPUID
1229 * indicates any suitable CPU.
1230 * @param pReq The request packet with input arguments and
1231 * where to store the results.
1232 */
1233int VBOXCALL supdrvOSMsrProberModify(RTCPUID idCpu, PSUPMSRPROBER pReq);
1234
1235#endif /* SUPDRV_WITH_MSR_PROBER */
1236
1237#if defined(RT_OS_DARWIN)
1238int VBOXCALL supdrvDarwinResumeSuspendedKbds(void);
1239#endif
1240
1241
1242/*********************************************************************************************************************************
1243* Shared Functions *
1244*********************************************************************************************************************************/
1245/* SUPDrv.c */
1246int VBOXCALL supdrvIOCtl(uintptr_t uIOCtl, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPREQHDR pReqHdr, size_t cbReq);
1247int VBOXCALL supdrvIOCtlFast(uintptr_t uOperation, VMCPUID idCpu, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession);
1248int VBOXCALL supdrvIDC(uintptr_t uIOCtl, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPDRVIDCREQHDR pReqHdr);
1249int VBOXCALL supdrvInitDevExt(PSUPDRVDEVEXT pDevExt, size_t cbSession);
1250void VBOXCALL supdrvDeleteDevExt(PSUPDRVDEVEXT pDevExt);
1251int VBOXCALL supdrvCreateSession(PSUPDRVDEVEXT pDevExt, bool fUser, bool fUnrestricted, PSUPDRVSESSION *ppSession);
1252int VBOXCALL supdrvSessionHashTabInsert(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPDRVSESSION *ppOsSessionPtr, void *pvUser);
1253int VBOXCALL supdrvSessionHashTabRemove(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, void *pvUser);
1254PSUPDRVSESSION VBOXCALL supdrvSessionHashTabLookup(PSUPDRVDEVEXT pDevExt, RTPROCESS Process, RTR0PROCESS R0Process,
1255 PSUPDRVSESSION *ppOsSessionPtr);
1256uint32_t VBOXCALL supdrvSessionRetain(PSUPDRVSESSION pSession);
1257uint32_t VBOXCALL supdrvSessionRelease(PSUPDRVSESSION pSession);
1258void VBOXCALL supdrvBadContext(PSUPDRVDEVEXT pDevExt, const char *pszFile, uint32_t uLine, const char *pszExtra);
1259int VBOXCALL supdrvQueryVTCapsInternal(uint32_t *pfCaps);
1260int VBOXCALL supdrvLdrLoadError(int rc, PSUPLDRLOAD pReq, const char *pszFormat, ...);
1261int VBOXCALL supdrvLdrGetExportedSymbol(const char *pszSymbol, uintptr_t *puValue);
1262int VBOXCALL supdrvLdrRegisterWrappedModule(PSUPDRVDEVEXT pDevExt, PCSUPLDRWRAPPEDMODULE pWrappedModInfo,
1263 void *pvNative, void **phMod);
1264int VBOXCALL supdrvLdrDeregisterWrappedModule(PSUPDRVDEVEXT pDevExt, PCSUPLDRWRAPPEDMODULE pWrappedModInfo, void **phMod);
1265
1266
1267/* SUPDrvGip.cpp */
1268int VBOXCALL supdrvGipCreate(PSUPDRVDEVEXT pDevExt);
1269void VBOXCALL supdrvGipDestroy(PSUPDRVDEVEXT pDevExt);
1270int VBOXCALL supdrvIOCtl_TscDeltaMeasure(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPTSCDELTAMEASURE pReq);
1271int VBOXCALL supdrvIOCtl_TscRead(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPTSCREAD pReq);
1272int VBOXCALL supdrvIOCtl_GipSetFlags(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, uint32_t fOrMask, uint32_t fAndMask);
1273
1274
1275/* SUPDrvTracer.cpp */
1276int VBOXCALL supdrvTracerInit(PSUPDRVDEVEXT pDevExt);
1277void VBOXCALL supdrvTracerTerm(PSUPDRVDEVEXT pDevExt);
1278void VBOXCALL supdrvTracerModuleUnloading(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage);
1279void VBOXCALL supdrvTracerCleanupSession(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession);
1280int VBOXCALL supdrvIOCtl_TracerUmodRegister(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession,
1281 RTR3PTR R3PtrVtgHdr, RTUINTPTR uVtgHdrAddr,
1282 RTR3PTR R3PtrStrTab, uint32_t cbStrTab,
1283 const char *pszModName, uint32_t fFlags);
1284int VBOXCALL supdrvIOCtl_TracerUmodDeregister(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, RTR3PTR R3PtrVtgHdr);
1285void VBOXCALL supdrvIOCtl_TracerUmodProbeFire(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPDRVTRACERUSRCTX pCtx);
1286int VBOXCALL supdrvIOCtl_TracerOpen(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, uint32_t uCookie, uintptr_t uArg);
1287int VBOXCALL supdrvIOCtl_TracerClose(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession);
1288int VBOXCALL supdrvIOCtl_TracerIOCtl(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, uintptr_t uCmd, uintptr_t uArg, int32_t *piRetVal);
1289extern PFNRT g_pfnSupdrvProbeFireKernel;
1290DECLASM(void) supdrvTracerProbeFireStub(void);
1291
1292#ifdef VBOX_WITH_NATIVE_DTRACE
1293const SUPDRVTRACERREG * VBOXCALL supdrvDTraceInit(void);
1294void VBOXCALL supdrvDTraceFini(void);
1295#endif
1296
1297RT_C_DECLS_END
1298
1299#endif /* !VBOX_INCLUDED_SRC_Support_SUPDrvInternal_h */
1300
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