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