1 | /* $Id: SUPDrvInternal.h 47537 2013-08-05 10:00:02Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox Support Driver - Internal header.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2013 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 <ntddk.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 <ntddk.h>
|
---|
73 | # endif
|
---|
74 | # include <memory.h>
|
---|
75 | # define memcmp(a,b,c) mymemcmp(a,b,c)
|
---|
76 | int VBOXCALL mymemcmp(const void *, const void *, size_t);
|
---|
77 | RT_C_DECLS_END
|
---|
78 |
|
---|
79 | #elif defined(RT_OS_LINUX)
|
---|
80 | # include <linux/version.h>
|
---|
81 | # if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 33)
|
---|
82 | # include <generated/autoconf.h>
|
---|
83 | # else
|
---|
84 | # ifndef AUTOCONF_INCLUDED
|
---|
85 | # include <linux/autoconf.h>
|
---|
86 | # endif
|
---|
87 | # endif
|
---|
88 | # if defined(CONFIG_MODVERSIONS) && !defined(MODVERSIONS)
|
---|
89 | # define MODVERSIONS
|
---|
90 | # if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 71)
|
---|
91 | # include <linux/modversions.h>
|
---|
92 | # endif
|
---|
93 | # endif
|
---|
94 | # if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 0)
|
---|
95 | # undef ALIGN
|
---|
96 | # endif
|
---|
97 | # ifndef KBUILD_STR
|
---|
98 | # if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 16)
|
---|
99 | # define KBUILD_STR(s) s
|
---|
100 | # else
|
---|
101 | # define KBUILD_STR(s) #s
|
---|
102 | # endif
|
---|
103 | # endif
|
---|
104 | # include <linux/string.h>
|
---|
105 | # include <linux/spinlock.h>
|
---|
106 | # include <linux/slab.h>
|
---|
107 | # if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)
|
---|
108 | # include <linux/semaphore.h>
|
---|
109 | # else /* older kernels */
|
---|
110 | # include <asm/semaphore.h>
|
---|
111 | # endif /* older kernels */
|
---|
112 | # include <linux/timer.h>
|
---|
113 |
|
---|
114 | #elif defined(RT_OS_DARWIN)
|
---|
115 | # include <libkern/libkern.h>
|
---|
116 | # include <iprt/string.h>
|
---|
117 |
|
---|
118 | #elif defined(RT_OS_OS2)
|
---|
119 |
|
---|
120 | #elif defined(RT_OS_FREEBSD)
|
---|
121 | # define memset libkern_memset /** @todo these are just hacks to get it compiling, check out later. */
|
---|
122 | # define memcmp libkern_memcmp
|
---|
123 | # define strchr libkern_strchr
|
---|
124 | # define strrchr libkern_strrchr
|
---|
125 | # define ffsl libkern_ffsl
|
---|
126 | # define fls libkern_fls
|
---|
127 | # define flsl libkern_flsl
|
---|
128 | # include <sys/libkern.h>
|
---|
129 | # undef memset
|
---|
130 | # undef memcmp
|
---|
131 | # undef strchr
|
---|
132 | # undef strrchr
|
---|
133 | # undef ffs
|
---|
134 | # undef ffsl
|
---|
135 | # undef fls
|
---|
136 | # undef flsl
|
---|
137 | # include <iprt/string.h>
|
---|
138 |
|
---|
139 | #elif defined(RT_OS_SOLARIS)
|
---|
140 | # include <sys/cmn_err.h>
|
---|
141 | # include <iprt/string.h>
|
---|
142 |
|
---|
143 | #else
|
---|
144 | # error "unsupported OS."
|
---|
145 | #endif
|
---|
146 |
|
---|
147 | #include "SUPDrvIOC.h"
|
---|
148 | #include "SUPDrvIDC.h"
|
---|
149 |
|
---|
150 |
|
---|
151 |
|
---|
152 | /*******************************************************************************
|
---|
153 | * Defined Constants And Macros *
|
---|
154 | *******************************************************************************/
|
---|
155 | /*
|
---|
156 | * Hardcoded cookies.
|
---|
157 | */
|
---|
158 | #define BIRD 0x64726962 /* 'bird' */
|
---|
159 | #define BIRD_INV 0x62697264 /* 'drib' */
|
---|
160 |
|
---|
161 |
|
---|
162 | #ifdef RT_OS_WINDOWS
|
---|
163 | /** Use a normal mutex for the loader so we remain at the same IRQL after
|
---|
164 | * taking it.
|
---|
165 | * @todo fix the mutex implementation on linux and make this the default. */
|
---|
166 | # define SUPDRV_USE_MUTEX_FOR_LDR
|
---|
167 |
|
---|
168 | /** Use a normal mutex for the GIP so we remain at the same IRQL after
|
---|
169 | * taking it.
|
---|
170 | * @todo fix the mutex implementation on linux and make this the default. */
|
---|
171 | # define SUPDRV_USE_MUTEX_FOR_GIP
|
---|
172 | #endif
|
---|
173 |
|
---|
174 |
|
---|
175 | /**
|
---|
176 | * OS debug print macro.
|
---|
177 | */
|
---|
178 | #define OSDBGPRINT(a) SUPR0Printf a
|
---|
179 |
|
---|
180 |
|
---|
181 | /** @name Context values for the per-session handle tables.
|
---|
182 | * The context value is used to distinguish between the different kinds of
|
---|
183 | * handles, making the handle table API do all the work.
|
---|
184 | * @{ */
|
---|
185 | /** Handle context value for single release event handles. */
|
---|
186 | #define SUPDRV_HANDLE_CTX_EVENT ((void *)(uintptr_t)(SUPDRVOBJTYPE_SEM_EVENT))
|
---|
187 | /** Handle context value for multiple release event handles. */
|
---|
188 | #define SUPDRV_HANDLE_CTX_EVENT_MULTI ((void *)(uintptr_t)(SUPDRVOBJTYPE_SEM_EVENT_MULTI))
|
---|
189 | /** @} */
|
---|
190 |
|
---|
191 |
|
---|
192 | /**
|
---|
193 | * Validates a session pointer.
|
---|
194 | *
|
---|
195 | * @returns true/false accordingly.
|
---|
196 | * @param pSession The session.
|
---|
197 | */
|
---|
198 | #define SUP_IS_SESSION_VALID(pSession) \
|
---|
199 | ( VALID_PTR(pSession) \
|
---|
200 | && pSession->u32Cookie == BIRD_INV)
|
---|
201 |
|
---|
202 | /**
|
---|
203 | * Validates a device extension pointer.
|
---|
204 | *
|
---|
205 | * @returns true/false accordingly.
|
---|
206 | * @param pDevExt The device extension.
|
---|
207 | */
|
---|
208 | #define SUP_IS_DEVEXT_VALID(pDevExt) \
|
---|
209 | ( VALID_PTR(pDevExt)\
|
---|
210 | && pDevExt->u32Cookie == BIRD)
|
---|
211 |
|
---|
212 |
|
---|
213 | /*******************************************************************************
|
---|
214 | * Structures and Typedefs *
|
---|
215 | *******************************************************************************/
|
---|
216 | /** Pointer to the device extension. */
|
---|
217 | typedef struct SUPDRVDEVEXT *PSUPDRVDEVEXT;
|
---|
218 |
|
---|
219 |
|
---|
220 | /**
|
---|
221 | * Memory reference types.
|
---|
222 | */
|
---|
223 | typedef enum
|
---|
224 | {
|
---|
225 | /** Unused entry */
|
---|
226 | MEMREF_TYPE_UNUSED = 0,
|
---|
227 | /** Locked memory (r3 mapping only). */
|
---|
228 | MEMREF_TYPE_LOCKED,
|
---|
229 | /** Continuous memory block (r3 and r0 mapping). */
|
---|
230 | MEMREF_TYPE_CONT,
|
---|
231 | /** Low memory block (r3 and r0 mapping). */
|
---|
232 | MEMREF_TYPE_LOW,
|
---|
233 | /** Memory block (r3 and r0 mapping). */
|
---|
234 | MEMREF_TYPE_MEM,
|
---|
235 | /** Locked memory (r3 mapping only) allocated by the support driver. */
|
---|
236 | MEMREF_TYPE_PAGE,
|
---|
237 | /** Blow the type up to 32-bit and mark the end. */
|
---|
238 | MEMREF_TYPE_32BIT_HACK = 0x7fffffff
|
---|
239 | } SUPDRVMEMREFTYPE, *PSUPDRVMEMREFTYPE;
|
---|
240 |
|
---|
241 |
|
---|
242 | /**
|
---|
243 | * Structure used for tracking memory a session
|
---|
244 | * references in one way or another.
|
---|
245 | */
|
---|
246 | typedef struct SUPDRVMEMREF
|
---|
247 | {
|
---|
248 | /** The memory object handle. */
|
---|
249 | RTR0MEMOBJ MemObj;
|
---|
250 | /** The ring-3 mapping memory object handle. */
|
---|
251 | RTR0MEMOBJ MapObjR3;
|
---|
252 | /** Type of memory. */
|
---|
253 | SUPDRVMEMREFTYPE eType;
|
---|
254 | } SUPDRVMEMREF, *PSUPDRVMEMREF;
|
---|
255 |
|
---|
256 |
|
---|
257 | /**
|
---|
258 | * Bundle of locked memory ranges.
|
---|
259 | */
|
---|
260 | typedef struct SUPDRVBUNDLE
|
---|
261 | {
|
---|
262 | /** Pointer to the next bundle. */
|
---|
263 | struct SUPDRVBUNDLE * volatile pNext;
|
---|
264 | /** Referenced memory. */
|
---|
265 | SUPDRVMEMREF aMem[64];
|
---|
266 | /** Number of entries used. */
|
---|
267 | uint32_t volatile cUsed;
|
---|
268 | } SUPDRVBUNDLE, *PSUPDRVBUNDLE;
|
---|
269 |
|
---|
270 |
|
---|
271 | /**
|
---|
272 | * Loaded image.
|
---|
273 | */
|
---|
274 | typedef struct SUPDRVLDRIMAGE
|
---|
275 | {
|
---|
276 | /** Next in chain. */
|
---|
277 | struct SUPDRVLDRIMAGE * volatile pNext;
|
---|
278 | /** Pointer to the image. */
|
---|
279 | void *pvImage;
|
---|
280 | /** Pointer to the allocated image buffer.
|
---|
281 | * pvImage is 32-byte aligned or it may governed by the native loader (this
|
---|
282 | * member is NULL then). */
|
---|
283 | void *pvImageAlloc;
|
---|
284 | /** Size of the image including the tables. This is mainly for verification
|
---|
285 | * of the load request. */
|
---|
286 | uint32_t cbImageWithTabs;
|
---|
287 | /** Size of the image. */
|
---|
288 | uint32_t cbImageBits;
|
---|
289 | /** The number of entries in the symbol table. */
|
---|
290 | uint32_t cSymbols;
|
---|
291 | /** Pointer to the symbol table. */
|
---|
292 | PSUPLDRSYM paSymbols;
|
---|
293 | /** The offset of the string table. */
|
---|
294 | char *pachStrTab;
|
---|
295 | /** Size of the string table. */
|
---|
296 | uint32_t cbStrTab;
|
---|
297 | /** Pointer to the optional module initialization callback. */
|
---|
298 | PFNR0MODULEINIT pfnModuleInit;
|
---|
299 | /** Pointer to the optional module termination callback. */
|
---|
300 | PFNR0MODULETERM pfnModuleTerm;
|
---|
301 | /** Service request handler. This is NULL for non-service modules. */
|
---|
302 | PFNSUPR0SERVICEREQHANDLER pfnServiceReqHandler;
|
---|
303 | /** The ldr image state. (IOCtl code of last operation.) */
|
---|
304 | uint32_t uState;
|
---|
305 | /** Usage count. */
|
---|
306 | uint32_t volatile cUsage;
|
---|
307 | /** Pointer to the device extension. */
|
---|
308 | struct SUPDRVDEVEXT *pDevExt;
|
---|
309 | #ifdef RT_OS_WINDOWS
|
---|
310 | /** The section object for the loaded image (fNative=true). */
|
---|
311 | void *pvNtSectionObj;
|
---|
312 | /** Lock object. */
|
---|
313 | RTR0MEMOBJ hMemLock;
|
---|
314 | #endif
|
---|
315 | #if defined(RT_OS_SOLARIS) && defined(VBOX_WITH_NATIVE_SOLARIS_LOADING)
|
---|
316 | /** The Solaris module ID. */
|
---|
317 | int idSolMod;
|
---|
318 | /** Pointer to the module control structure. */
|
---|
319 | struct modctl *pSolModCtl;
|
---|
320 | #endif
|
---|
321 | /** Whether it's loaded by the native loader or not. */
|
---|
322 | bool fNative;
|
---|
323 | /** Image name. */
|
---|
324 | char szName[32];
|
---|
325 | } SUPDRVLDRIMAGE, *PSUPDRVLDRIMAGE;
|
---|
326 |
|
---|
327 |
|
---|
328 | /** Image usage record. */
|
---|
329 | typedef struct SUPDRVLDRUSAGE
|
---|
330 | {
|
---|
331 | /** Next in chain. */
|
---|
332 | struct SUPDRVLDRUSAGE * volatile pNext;
|
---|
333 | /** The image. */
|
---|
334 | PSUPDRVLDRIMAGE pImage;
|
---|
335 | /** Load count. */
|
---|
336 | uint32_t volatile cUsage;
|
---|
337 | } SUPDRVLDRUSAGE, *PSUPDRVLDRUSAGE;
|
---|
338 |
|
---|
339 |
|
---|
340 | /**
|
---|
341 | * Component factory registration record.
|
---|
342 | */
|
---|
343 | typedef struct SUPDRVFACTORYREG
|
---|
344 | {
|
---|
345 | /** Pointer to the next registration. */
|
---|
346 | struct SUPDRVFACTORYREG *pNext;
|
---|
347 | /** Pointer to the registered factory. */
|
---|
348 | PCSUPDRVFACTORY pFactory;
|
---|
349 | /** The session owning the factory.
|
---|
350 | * Used for deregistration and session cleanup. */
|
---|
351 | PSUPDRVSESSION pSession;
|
---|
352 | /** Length of the name. */
|
---|
353 | size_t cchName;
|
---|
354 | } SUPDRVFACTORYREG;
|
---|
355 | /** Pointer to a component factory registration record. */
|
---|
356 | typedef SUPDRVFACTORYREG *PSUPDRVFACTORYREG;
|
---|
357 | /** Pointer to a const component factory registration record. */
|
---|
358 | typedef SUPDRVFACTORYREG const *PCSUPDRVFACTORYREG;
|
---|
359 |
|
---|
360 |
|
---|
361 | /**
|
---|
362 | * Registered object.
|
---|
363 | * This takes care of reference counting and tracking data for access checks.
|
---|
364 | */
|
---|
365 | typedef struct SUPDRVOBJ
|
---|
366 | {
|
---|
367 | /** Magic value (SUPDRVOBJ_MAGIC). */
|
---|
368 | uint32_t u32Magic;
|
---|
369 | /** The object type. */
|
---|
370 | SUPDRVOBJTYPE enmType;
|
---|
371 | /** Pointer to the next in the global list. */
|
---|
372 | struct SUPDRVOBJ * volatile pNext;
|
---|
373 | /** Pointer to the object destructor.
|
---|
374 | * This may be set to NULL if the image containing the destructor get unloaded. */
|
---|
375 | PFNSUPDRVDESTRUCTOR pfnDestructor;
|
---|
376 | /** User argument 1. */
|
---|
377 | void *pvUser1;
|
---|
378 | /** User argument 2. */
|
---|
379 | void *pvUser2;
|
---|
380 | /** The total sum of all per-session usage. */
|
---|
381 | uint32_t volatile cUsage;
|
---|
382 | /** The creator user id. */
|
---|
383 | RTUID CreatorUid;
|
---|
384 | /** The creator group id. */
|
---|
385 | RTGID CreatorGid;
|
---|
386 | /** The creator process id. */
|
---|
387 | RTPROCESS CreatorProcess;
|
---|
388 | } SUPDRVOBJ, *PSUPDRVOBJ;
|
---|
389 |
|
---|
390 | /** Magic number for SUPDRVOBJ::u32Magic. (Dame Agatha Mary Clarissa Christie). */
|
---|
391 | #define SUPDRVOBJ_MAGIC UINT32_C(0x18900915)
|
---|
392 | /** Dead number magic for SUPDRVOBJ::u32Magic. */
|
---|
393 | #define SUPDRVOBJ_MAGIC_DEAD UINT32_C(0x19760112)
|
---|
394 |
|
---|
395 | /**
|
---|
396 | * The per-session object usage record.
|
---|
397 | */
|
---|
398 | typedef struct SUPDRVUSAGE
|
---|
399 | {
|
---|
400 | /** Pointer to the next in the list. */
|
---|
401 | struct SUPDRVUSAGE * volatile pNext;
|
---|
402 | /** Pointer to the object we're recording usage for. */
|
---|
403 | PSUPDRVOBJ pObj;
|
---|
404 | /** The usage count. */
|
---|
405 | uint32_t volatile cUsage;
|
---|
406 | } SUPDRVUSAGE, *PSUPDRVUSAGE;
|
---|
407 |
|
---|
408 |
|
---|
409 | /**
|
---|
410 | * Per session data.
|
---|
411 | * This is mainly for memory tracking.
|
---|
412 | */
|
---|
413 | typedef struct SUPDRVSESSION
|
---|
414 | {
|
---|
415 | /** Pointer to the device extension. */
|
---|
416 | PSUPDRVDEVEXT pDevExt;
|
---|
417 | /** Session Cookie. */
|
---|
418 | uint32_t u32Cookie;
|
---|
419 | /** Set if is an unrestricted session, clear if restricted. */
|
---|
420 | bool fUnrestricted;
|
---|
421 | /* Reference counter. */
|
---|
422 | uint32_t volatile cRefs;
|
---|
423 |
|
---|
424 | /** The VM associated with the session. */
|
---|
425 | PVM pVM;
|
---|
426 | /** Handle table for IPRT semaphore wrapper APIs.
|
---|
427 | * This takes care of its own locking in an IRQ safe manner. */
|
---|
428 | RTHANDLETABLE hHandleTable;
|
---|
429 | /** Load usage records. (protected by SUPDRVDEVEXT::mtxLdr) */
|
---|
430 | PSUPDRVLDRUSAGE volatile pLdrUsage;
|
---|
431 |
|
---|
432 | /** Spinlock protecting the bundles and the GIP members. */
|
---|
433 | RTSPINLOCK Spinlock;
|
---|
434 | /** The ring-3 mapping of the GIP (readonly). */
|
---|
435 | RTR0MEMOBJ GipMapObjR3;
|
---|
436 | /** Set if the session is using the GIP. */
|
---|
437 | uint32_t fGipReferenced;
|
---|
438 | /** Bundle of locked memory objects. */
|
---|
439 | SUPDRVBUNDLE Bundle;
|
---|
440 | /** List of generic usage records. (protected by SUPDRVDEVEXT::SpinLock) */
|
---|
441 | PSUPDRVUSAGE volatile pUsage;
|
---|
442 |
|
---|
443 | /** The user id of the session. (Set by the OS part.) */
|
---|
444 | RTUID Uid;
|
---|
445 | /** The group id of the session. (Set by the OS part.) */
|
---|
446 | RTGID Gid;
|
---|
447 | /** The process (id) of the session. */
|
---|
448 | RTPROCESS Process;
|
---|
449 | /** Which process this session is associated with.
|
---|
450 | * This is NIL_RTR0PROCESS for kernel sessions and valid for user ones. */
|
---|
451 | RTR0PROCESS R0Process;
|
---|
452 | /** Per session tracer specfic data. */
|
---|
453 | uintptr_t uTracerData;
|
---|
454 | /** The thread currently actively talking to the tracer. (One at the time!) */
|
---|
455 | RTNATIVETHREAD hTracerCaller;
|
---|
456 | /** List of tracepoint providers associated with the session
|
---|
457 | * (SUPDRVTPPROVIDER). */
|
---|
458 | RTLISTANCHOR TpProviders;
|
---|
459 | /** The number of providers in TpProviders. */
|
---|
460 | uint32_t cTpProviders;
|
---|
461 | /** The number of threads active in supdrvIOCtl_TracerUmodProbeFire or
|
---|
462 | * SUPR0TracerUmodProbeFire. */
|
---|
463 | uint32_t volatile cTpProbesFiring;
|
---|
464 | /** User tracepoint modules (PSUPDRVTRACKERUMOD). */
|
---|
465 | RTLISTANCHOR TpUmods;
|
---|
466 | /** The user tracepoint module lookup table. */
|
---|
467 | struct SUPDRVTRACERUMOD *apTpLookupTable[32];
|
---|
468 | #ifndef SUPDRV_AGNOSTIC
|
---|
469 | # if defined(RT_OS_DARWIN)
|
---|
470 | /** Pointer to the associated org_virtualbox_SupDrvClient object. */
|
---|
471 | void *pvSupDrvClient;
|
---|
472 | /** Whether this session has been opened or not. */
|
---|
473 | bool fOpened;
|
---|
474 | # endif
|
---|
475 | # if defined(RT_OS_OS2)
|
---|
476 | /** The system file number of this session. */
|
---|
477 | uint16_t sfn;
|
---|
478 | uint16_t Alignment; /**< Alignment */
|
---|
479 | # endif
|
---|
480 | # if defined(RT_OS_DARWIN) || defined(RT_OS_OS2) || defined(RT_OS_SOLARIS)
|
---|
481 | /** Pointer to the next session with the same hash. */
|
---|
482 | PSUPDRVSESSION pNextHash;
|
---|
483 | # endif
|
---|
484 | #endif /* !SUPDRV_AGNOSTIC */
|
---|
485 | } SUPDRVSESSION;
|
---|
486 |
|
---|
487 |
|
---|
488 | /**
|
---|
489 | * Device extension.
|
---|
490 | */
|
---|
491 | typedef struct SUPDRVDEVEXT
|
---|
492 | {
|
---|
493 | /** Global cookie. */
|
---|
494 | uint32_t u32Cookie;
|
---|
495 | /** The actual size of SUPDRVSESSION. (SUPDRV_AGNOSTIC) */
|
---|
496 | uint32_t cbSession;
|
---|
497 |
|
---|
498 | /** Spinlock to serialize the initialization, usage counting and objects.
|
---|
499 | * This is IRQ safe because we want to be able signal semaphores from the
|
---|
500 | * special HM context (and later maybe interrupt handlers), so we must be able
|
---|
501 | * to reference and dereference handles when IRQs are disabled. */
|
---|
502 | RTSPINLOCK Spinlock;
|
---|
503 |
|
---|
504 | /** List of registered objects. Protected by the spinlock. */
|
---|
505 | PSUPDRVOBJ volatile pObjs;
|
---|
506 | /** List of free object usage records. */
|
---|
507 | PSUPDRVUSAGE volatile pUsageFree;
|
---|
508 |
|
---|
509 | /** Loader mutex.
|
---|
510 | * This protects pvVMMR0, pvVMMR0Entry, pImages and SUPDRVSESSION::pLdrUsage. */
|
---|
511 | #ifdef SUPDRV_USE_MUTEX_FOR_LDR
|
---|
512 | RTSEMMUTEX mtxLdr;
|
---|
513 | #else
|
---|
514 | RTSEMFASTMUTEX mtxLdr;
|
---|
515 | #endif
|
---|
516 |
|
---|
517 | /** VMM Module 'handle'.
|
---|
518 | * 0 if the code VMM isn't loaded and Idt are nops. */
|
---|
519 | void * volatile pvVMMR0;
|
---|
520 | /** VMMR0EntryInt() pointer. */
|
---|
521 | DECLR0CALLBACKMEMBER(int, pfnVMMR0EntryInt, (PVM pVM, unsigned uOperation, void *pvArg));
|
---|
522 | /** VMMR0EntryFast() pointer. */
|
---|
523 | DECLR0CALLBACKMEMBER(void, pfnVMMR0EntryFast, (PVM pVM, VMCPUID idCpu, unsigned uOperation));
|
---|
524 | /** VMMR0EntryEx() pointer. */
|
---|
525 | DECLR0CALLBACKMEMBER(int, pfnVMMR0EntryEx, (PVM pVM, VMCPUID idCpu, unsigned uOperation, PSUPVMMR0REQHDR pReq, uint64_t u64Arg, PSUPDRVSESSION pSession));
|
---|
526 |
|
---|
527 | /** Linked list of loaded code. */
|
---|
528 | PSUPDRVLDRIMAGE volatile pLdrImages;
|
---|
529 |
|
---|
530 | /** @name These members for detecting whether an API caller is in ModuleInit.
|
---|
531 | * Certain APIs are only permitted from ModuleInit, like for instance tracepoint
|
---|
532 | * registration.
|
---|
533 | * @{ */
|
---|
534 | /** The image currently executing its ModuleInit. */
|
---|
535 | PSUPDRVLDRIMAGE volatile pLdrInitImage;
|
---|
536 | /** The thread currently executing a ModuleInit function. */
|
---|
537 | RTNATIVETHREAD volatile hLdrInitThread;
|
---|
538 | /** @} */
|
---|
539 |
|
---|
540 |
|
---|
541 | /** GIP mutex.
|
---|
542 | * Any changes to any of the GIP members requires ownership of this mutex,
|
---|
543 | * except on driver init and termination. */
|
---|
544 | #ifdef SUPDRV_USE_MUTEX_FOR_GIP
|
---|
545 | RTSEMMUTEX mtxGip;
|
---|
546 | #else
|
---|
547 | RTSEMFASTMUTEX mtxGip;
|
---|
548 | #endif
|
---|
549 | /** GIP spinlock protecting GIP members during Mp events.
|
---|
550 | * This is IRQ safe since be may get MP callbacks in contexts where IRQs are
|
---|
551 | * disabled (on some platforms). */
|
---|
552 | RTSPINLOCK hGipSpinlock;
|
---|
553 | /** Pointer to the Global Info Page (GIP). */
|
---|
554 | PSUPGLOBALINFOPAGE pGip;
|
---|
555 | /** The physical address of the GIP. */
|
---|
556 | RTHCPHYS HCPhysGip;
|
---|
557 | /** Number of processes using the GIP.
|
---|
558 | * (The updates are suspend while cGipUsers is 0.)*/
|
---|
559 | uint32_t volatile cGipUsers;
|
---|
560 | /** The ring-0 memory object handle for the GIP page. */
|
---|
561 | RTR0MEMOBJ GipMemObj;
|
---|
562 | /** The GIP timer handle. */
|
---|
563 | PRTTIMER pGipTimer;
|
---|
564 | /** If non-zero we've successfully called RTTimerRequestSystemGranularity(). */
|
---|
565 | uint32_t u32SystemTimerGranularityGrant;
|
---|
566 | /** The CPU id of the GIP master.
|
---|
567 | * This CPU is responsible for the updating the common GIP data. */
|
---|
568 | RTCPUID volatile idGipMaster;
|
---|
569 |
|
---|
570 | /** Component factory mutex.
|
---|
571 | * This protects pComponentFactoryHead and component factory querying. */
|
---|
572 | RTSEMFASTMUTEX mtxComponentFactory;
|
---|
573 | /** The head of the list of registered component factories. */
|
---|
574 | PSUPDRVFACTORYREG pComponentFactoryHead;
|
---|
575 |
|
---|
576 | /** Lock protecting The tracer members. */
|
---|
577 | RTSEMFASTMUTEX mtxTracer;
|
---|
578 | /** List of tracer providers (SUPDRVTPPROVIDER). */
|
---|
579 | RTLISTANCHOR TracerProviderList;
|
---|
580 | /** List of zombie tracer providers (SUPDRVTPPROVIDER). */
|
---|
581 | RTLISTANCHOR TracerProviderZombieList;
|
---|
582 | /** Pointer to the tracer registration record. */
|
---|
583 | PCSUPDRVTRACERREG pTracerOps;
|
---|
584 | /** The ring-0 session of a native tracer provider. */
|
---|
585 | PSUPDRVSESSION pTracerSession;
|
---|
586 | /** The image containing the tracer. */
|
---|
587 | PSUPDRVLDRIMAGE pTracerImage;
|
---|
588 | /** The tracer helpers. */
|
---|
589 | SUPDRVTRACERHLP TracerHlp;
|
---|
590 | /** The number of session having opened the tracer currently. */
|
---|
591 | uint32_t cTracerOpens;
|
---|
592 | /** The number of threads currently calling into the tracer. */
|
---|
593 | uint32_t volatile cTracerCallers;
|
---|
594 | /** Set if the tracer is being unloaded. */
|
---|
595 | bool fTracerUnloading;
|
---|
596 | /** Hash table for user tracer modules (SUPDRVVTGCOPY). */
|
---|
597 | RTLISTANCHOR aTrackerUmodHash[128];
|
---|
598 |
|
---|
599 | /*
|
---|
600 | * Note! The non-agnostic bits must be a the very end of the structure!
|
---|
601 | */
|
---|
602 | #ifndef SUPDRV_AGNOSTIC
|
---|
603 | # ifdef RT_OS_WINDOWS
|
---|
604 | /** Callback object returned by ExCreateCallback. */
|
---|
605 | PCALLBACK_OBJECT pObjPowerCallback;
|
---|
606 | /** Callback handle returned by ExRegisterCallback. */
|
---|
607 | PVOID hPowerCallback;
|
---|
608 | # endif
|
---|
609 | #endif
|
---|
610 | } SUPDRVDEVEXT;
|
---|
611 |
|
---|
612 |
|
---|
613 | RT_C_DECLS_BEGIN
|
---|
614 |
|
---|
615 | /*******************************************************************************
|
---|
616 | * OS Specific Functions *
|
---|
617 | *******************************************************************************/
|
---|
618 | void VBOXCALL supdrvOSObjInitCreator(PSUPDRVOBJ pObj, PSUPDRVSESSION pSession);
|
---|
619 | bool VBOXCALL supdrvOSObjCanAccess(PSUPDRVOBJ pObj, PSUPDRVSESSION pSession, const char *pszObjName, int *prc);
|
---|
620 | bool VBOXCALL supdrvOSGetForcedAsyncTscMode(PSUPDRVDEVEXT pDevExt);
|
---|
621 | int VBOXCALL supdrvOSEnableVTx(bool fEnabled);
|
---|
622 | bool VBOXCALL supdrvOSSuspendVTxOnCpu(void);
|
---|
623 | void VBOXCALL supdrvOSResumeVTxOnCpu(bool fSuspended);
|
---|
624 |
|
---|
625 | /**
|
---|
626 | * Try open the image using the native loader.
|
---|
627 | *
|
---|
628 | * @returns IPRT status code.
|
---|
629 | * @retval VERR_NOT_SUPPORTED if native loading isn't supported.
|
---|
630 | *
|
---|
631 | * @param pDevExt The device globals.
|
---|
632 | * @param pImage The image handle. pvImage should be set on
|
---|
633 | * success, pvImageAlloc can also be set if
|
---|
634 | * appropriate.
|
---|
635 | * @param pszFilename The file name - UTF-8, may containing UNIX
|
---|
636 | * slashes on non-UNIX systems.
|
---|
637 | */
|
---|
638 | int VBOXCALL supdrvOSLdrOpen(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, const char *pszFilename);
|
---|
639 |
|
---|
640 | /**
|
---|
641 | * Notification call indicating that a image is being opened for the first time.
|
---|
642 | *
|
---|
643 | * Can be used to log the load address of the image.
|
---|
644 | *
|
---|
645 | * @param pDevExt The device globals.
|
---|
646 | * @param pImage The image handle.
|
---|
647 | */
|
---|
648 | void VBOXCALL supdrvOSLdrNotifyOpened(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage);
|
---|
649 |
|
---|
650 | /**
|
---|
651 | * Validates an entry point address.
|
---|
652 | *
|
---|
653 | * Called before supdrvOSLdrLoad.
|
---|
654 | *
|
---|
655 | * @returns IPRT status code.
|
---|
656 | * @param pDevExt The device globals.
|
---|
657 | * @param pImage The image data (still in the open state).
|
---|
658 | * @param pv The address within the image.
|
---|
659 | * @param pbImageBits The image bits as loaded by ring-3.
|
---|
660 | */
|
---|
661 | int VBOXCALL supdrvOSLdrValidatePointer(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage,
|
---|
662 | void *pv, const uint8_t *pbImageBits);
|
---|
663 |
|
---|
664 | /**
|
---|
665 | * Load the image.
|
---|
666 | *
|
---|
667 | * @returns IPRT status code.
|
---|
668 | * @param pDevExt The device globals.
|
---|
669 | * @param pImage The image data (up to date). Adjust entrypoints
|
---|
670 | * and exports if necessary.
|
---|
671 | * @param pbImageBits The image bits as loaded by ring-3.
|
---|
672 | * @param pReq Pointer to the request packet so that the VMMR0
|
---|
673 | * entry points can be adjusted.
|
---|
674 | */
|
---|
675 | int VBOXCALL supdrvOSLdrLoad(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, const uint8_t *pbImageBits, PSUPLDRLOAD pReq);
|
---|
676 |
|
---|
677 |
|
---|
678 | /**
|
---|
679 | * Unload the image.
|
---|
680 | *
|
---|
681 | * @param pDevExt The device globals.
|
---|
682 | * @param pImage The image data (mostly still valid).
|
---|
683 | */
|
---|
684 | void VBOXCALL supdrvOSLdrUnload(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage);
|
---|
685 |
|
---|
686 |
|
---|
687 | /*******************************************************************************
|
---|
688 | * Shared Functions *
|
---|
689 | *******************************************************************************/
|
---|
690 | /* SUPDrv.c */
|
---|
691 | int VBOXCALL supdrvIOCtl(uintptr_t uIOCtl, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPREQHDR pReqHdr);
|
---|
692 | int VBOXCALL supdrvIOCtlFast(uintptr_t uIOCtl, VMCPUID idCpu, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession);
|
---|
693 | int VBOXCALL supdrvIDC(uintptr_t uIOCtl, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPDRVIDCREQHDR pReqHdr);
|
---|
694 | int VBOXCALL supdrvInitDevExt(PSUPDRVDEVEXT pDevExt, size_t cbSession);
|
---|
695 | void VBOXCALL supdrvDeleteDevExt(PSUPDRVDEVEXT pDevExt);
|
---|
696 | int VBOXCALL supdrvCreateSession(PSUPDRVDEVEXT pDevExt, bool fUser, bool fUnrestricted, PSUPDRVSESSION *ppSession);
|
---|
697 | uint32_t VBOXCALL supdrvSessionRetain(PSUPDRVSESSION pSession);
|
---|
698 | uint32_t VBOXCALL supdrvSessionRelease(PSUPDRVSESSION pSession);
|
---|
699 |
|
---|
700 | int VBOXCALL supdrvTracerInit(PSUPDRVDEVEXT pDevExt);
|
---|
701 | void VBOXCALL supdrvTracerTerm(PSUPDRVDEVEXT pDevExt);
|
---|
702 | void VBOXCALL supdrvTracerModuleUnloading(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage);
|
---|
703 | void VBOXCALL supdrvTracerCleanupSession(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession);
|
---|
704 | int VBOXCALL supdrvIOCtl_TracerUmodRegister(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession,
|
---|
705 | RTR3PTR R3PtrVtgHdr, RTUINTPTR uVtgHdrAddr,
|
---|
706 | RTR3PTR R3PtrStrTab, uint32_t cbStrTab,
|
---|
707 | const char *pszModName, uint32_t fFlags);
|
---|
708 | int VBOXCALL supdrvIOCtl_TracerUmodDeregister(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, RTR3PTR R3PtrVtgHdr);
|
---|
709 | void VBOXCALL supdrvIOCtl_TracerUmodProbeFire(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPDRVTRACERUSRCTX pCtx);
|
---|
710 | int VBOXCALL supdrvIOCtl_TracerOpen(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, uint32_t uCookie, uintptr_t uArg);
|
---|
711 | int VBOXCALL supdrvIOCtl_TracerClose(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession);
|
---|
712 | int VBOXCALL supdrvIOCtl_TracerIOCtl(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, uintptr_t uCmd, uintptr_t uArg, int32_t *piRetVal);
|
---|
713 | extern PFNRT g_pfnSupdrvProbeFireKernel;
|
---|
714 | DECLASM(void) supdrvTracerProbeFireStub(void);
|
---|
715 |
|
---|
716 | #ifdef VBOX_WITH_NATIVE_DTRACE
|
---|
717 | const SUPDRVTRACERREG * VBOXCALL supdrvDTraceInit(void);
|
---|
718 | #endif
|
---|
719 |
|
---|
720 | RT_C_DECLS_END
|
---|
721 |
|
---|
722 | #endif
|
---|
723 |
|
---|