VirtualBox

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

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

SUPDrv: Build fix for older kernels, 3rd attempt. bugref:9937

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