VirtualBox

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

Last change on this file since 87706 was 87706, checked in by vboxsync, 4 years ago

SUPDrv: Build fix for older kernels, 2nd attempt. bugref:9937

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