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