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