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