1 | /* $Revision: 19255 $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox Support Driver - Internal header.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
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 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
27 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
28 | * additional information or have any questions.
|
---|
29 | */
|
---|
30 |
|
---|
31 | #ifndef ___SUPDrvInternal_h
|
---|
32 | #define ___SUPDrvInternal_h
|
---|
33 |
|
---|
34 |
|
---|
35 | /*******************************************************************************
|
---|
36 | * Header Files *
|
---|
37 | *******************************************************************************/
|
---|
38 | #include <VBox/cdefs.h>
|
---|
39 | #include <VBox/types.h>
|
---|
40 | #include <iprt/assert.h>
|
---|
41 | #include <iprt/asm.h>
|
---|
42 | #include <VBox/sup.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 |
|
---|
50 | #if defined(RT_OS_WINDOWS)
|
---|
51 | __BEGIN_DECLS
|
---|
52 | # if (_MSC_VER >= 1400) && !defined(VBOX_WITH_PATCHED_DDK)
|
---|
53 | # define _InterlockedExchange _InterlockedExchange_StupidDDKVsCompilerCrap
|
---|
54 | # define _InterlockedExchangeAdd _InterlockedExchangeAdd_StupidDDKVsCompilerCrap
|
---|
55 | # define _InterlockedCompareExchange _InterlockedCompareExchange_StupidDDKVsCompilerCrap
|
---|
56 | # define _InterlockedAddLargeStatistic _InterlockedAddLargeStatistic_StupidDDKVsCompilerCrap
|
---|
57 | # define _interlockedbittestandset _interlockedbittestandset_StupidDDKVsCompilerCrap
|
---|
58 | # define _interlockedbittestandreset _interlockedbittestandreset_StupidDDKVsCompilerCrap
|
---|
59 | # define _interlockedbittestandset64 _interlockedbittestandset64_StupidDDKVsCompilerCrap
|
---|
60 | # define _interlockedbittestandreset64 _interlockedbittestandreset64_StupidDDKVsCompilerCrap
|
---|
61 | # pragma warning(disable : 4163)
|
---|
62 | # include <ntddk.h>
|
---|
63 | # pragma warning(default : 4163)
|
---|
64 | # undef _InterlockedExchange
|
---|
65 | # undef _InterlockedExchangeAdd
|
---|
66 | # undef _InterlockedCompareExchange
|
---|
67 | # undef _InterlockedAddLargeStatistic
|
---|
68 | # undef _interlockedbittestandset
|
---|
69 | # undef _interlockedbittestandreset
|
---|
70 | # undef _interlockedbittestandset64
|
---|
71 | # undef _interlockedbittestandreset64
|
---|
72 | # else
|
---|
73 | # include <ntddk.h>
|
---|
74 | # endif
|
---|
75 | # include <memory.h>
|
---|
76 | # define memcmp(a,b,c) mymemcmp(a,b,c)
|
---|
77 | int VBOXCALL mymemcmp(const void *, const void *, size_t);
|
---|
78 | __END_DECLS
|
---|
79 |
|
---|
80 | #elif defined(RT_OS_LINUX)
|
---|
81 | # include <linux/autoconf.h>
|
---|
82 | # include <linux/version.h>
|
---|
83 | # if defined(CONFIG_MODVERSIONS) && !defined(MODVERSIONS)
|
---|
84 | # define MODVERSIONS
|
---|
85 | # if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 71)
|
---|
86 | # include <linux/modversions.h>
|
---|
87 | # endif
|
---|
88 | # endif
|
---|
89 | # if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 0)
|
---|
90 | # undef ALIGN
|
---|
91 | # endif
|
---|
92 | # ifndef KBUILD_STR
|
---|
93 | # if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 16)
|
---|
94 | # define KBUILD_STR(s) s
|
---|
95 | # else
|
---|
96 | # define KBUILD_STR(s) #s
|
---|
97 | # endif
|
---|
98 | # endif
|
---|
99 | # include <linux/string.h>
|
---|
100 | # include <linux/spinlock.h>
|
---|
101 | # include <linux/slab.h>
|
---|
102 | # if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)
|
---|
103 | # include <linux/semaphore.h>
|
---|
104 | # else /* older kernels */
|
---|
105 | # include <asm/semaphore.h>
|
---|
106 | # endif /* older kernels */
|
---|
107 | # include <linux/timer.h>
|
---|
108 |
|
---|
109 | # if 0
|
---|
110 | # include <linux/hrtimer.h>
|
---|
111 | # define VBOX_HRTIMER
|
---|
112 | # endif
|
---|
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 ffs libkern_ffs
|
---|
126 | # define ffsl libkern_ffsl
|
---|
127 | # define fls libkern_fls
|
---|
128 | # define flsl libkern_flsl
|
---|
129 | # include <sys/libkern.h>
|
---|
130 | # undef memset
|
---|
131 | # undef memcmp
|
---|
132 | # undef strchr
|
---|
133 | # undef strrchr
|
---|
134 | # undef ffs
|
---|
135 | # undef ffsl
|
---|
136 | # undef fls
|
---|
137 | # undef flsl
|
---|
138 | # include <iprt/string.h>
|
---|
139 |
|
---|
140 | #elif defined(RT_OS_SOLARIS)
|
---|
141 | # include <sys/cmn_err.h>
|
---|
142 | # include <iprt/string.h>
|
---|
143 |
|
---|
144 | #else
|
---|
145 | # error "unsupported OS."
|
---|
146 | #endif
|
---|
147 |
|
---|
148 | #include "SUPDrvIOC.h"
|
---|
149 | #include "SUPDrvIDC.h"
|
---|
150 |
|
---|
151 |
|
---|
152 |
|
---|
153 | /*******************************************************************************
|
---|
154 | * Defined Constants And Macros *
|
---|
155 | *******************************************************************************/
|
---|
156 | /*
|
---|
157 | * Hardcoded cookies.
|
---|
158 | */
|
---|
159 | #define BIRD 0x64726962 /* 'bird' */
|
---|
160 | #define BIRD_INV 0x62697264 /* 'drib' */
|
---|
161 |
|
---|
162 |
|
---|
163 | /*
|
---|
164 | * Win32
|
---|
165 | */
|
---|
166 | #if defined(RT_OS_WINDOWS)
|
---|
167 |
|
---|
168 | /* debug printf */
|
---|
169 | # define OSDBGPRINT(a) DbgPrint a
|
---|
170 |
|
---|
171 | /** Maximum number of bytes we try to lock down in one go.
|
---|
172 | * This is supposed to have a limit right below 256MB, but this appears
|
---|
173 | * to actually be much lower. The values here have been determined experimentally.
|
---|
174 | */
|
---|
175 | #ifdef RT_ARCH_X86
|
---|
176 | # define MAX_LOCK_MEM_SIZE (32*1024*1024) /* 32mb */
|
---|
177 | #endif
|
---|
178 | #ifdef RT_ARCH_AMD64
|
---|
179 | # define MAX_LOCK_MEM_SIZE (24*1024*1024) /* 24mb */
|
---|
180 | #endif
|
---|
181 |
|
---|
182 |
|
---|
183 | /*
|
---|
184 | * Linux
|
---|
185 | */
|
---|
186 | #elif defined(RT_OS_LINUX)
|
---|
187 |
|
---|
188 | /* check kernel version */
|
---|
189 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
|
---|
190 | # error Unsupported kernel version!
|
---|
191 | #endif
|
---|
192 |
|
---|
193 | __BEGIN_DECLS
|
---|
194 | int linux_dprintf(const char *format, ...);
|
---|
195 | __END_DECLS
|
---|
196 |
|
---|
197 | /* debug printf */
|
---|
198 | # define OSDBGPRINT(a) printk a
|
---|
199 |
|
---|
200 |
|
---|
201 | /*
|
---|
202 | * Darwin
|
---|
203 | */
|
---|
204 | #elif defined(RT_OS_DARWIN)
|
---|
205 |
|
---|
206 | /* debug printf */
|
---|
207 | # define OSDBGPRINT(a) printf a
|
---|
208 |
|
---|
209 |
|
---|
210 | /*
|
---|
211 | * OS/2
|
---|
212 | */
|
---|
213 | #elif defined(RT_OS_OS2)
|
---|
214 |
|
---|
215 | /* No log API in OS/2 only COM port. */
|
---|
216 | # define OSDBGPRINT(a) SUPR0Printf a
|
---|
217 |
|
---|
218 |
|
---|
219 | /*
|
---|
220 | * FreeBSD
|
---|
221 | */
|
---|
222 | #elif defined(RT_OS_FREEBSD)
|
---|
223 |
|
---|
224 | /* debug printf */
|
---|
225 | # define OSDBGPRINT(a) printf a
|
---|
226 |
|
---|
227 |
|
---|
228 | /*
|
---|
229 | * Solaris
|
---|
230 | */
|
---|
231 | #elif defined(RT_OS_SOLARIS)
|
---|
232 | # define OSDBGPRINT(a) SUPR0Printf a
|
---|
233 |
|
---|
234 |
|
---|
235 | #else
|
---|
236 | /** @todo other os'es */
|
---|
237 | # error "OS interface defines is not done for this OS!"
|
---|
238 | #endif
|
---|
239 |
|
---|
240 |
|
---|
241 | /* dprintf */
|
---|
242 | #if (defined(DEBUG) && !defined(NO_LOGGING)) || defined(RT_OS_FREEBSD)
|
---|
243 | # ifdef LOG_TO_COM
|
---|
244 | # include <VBox/log.h>
|
---|
245 | # define dprintf(a) RTLogComPrintf a
|
---|
246 | # else
|
---|
247 | # define dprintf(a) OSDBGPRINT(a)
|
---|
248 | # endif
|
---|
249 | #else
|
---|
250 | # define dprintf(a) do {} while (0)
|
---|
251 | #endif
|
---|
252 |
|
---|
253 | /* dprintf2 - extended logging. */
|
---|
254 | #if defined(RT_OS_DARWIN) || defined(RT_OS_OS2) || defined(RT_OS_FREEBSD)
|
---|
255 | # define dprintf2 dprintf
|
---|
256 | #else
|
---|
257 | # define dprintf2(a) do { } while (0)
|
---|
258 | #endif
|
---|
259 |
|
---|
260 |
|
---|
261 | /** @def RT_WITH_W64_UNWIND_HACK
|
---|
262 | * Changes a function name into the wrapped version if we've
|
---|
263 | * enabled the unwind hack.
|
---|
264 | *
|
---|
265 | * The unwind hack is for making the NT unwind procedures skip
|
---|
266 | * our dynamically loaded code when they try to walk the call
|
---|
267 | * stack. Needless to say, they kind of don't expect what
|
---|
268 | * we're doing here and get kind of confused and may BSOD. */
|
---|
269 | #ifdef DOXYGEN_RUNNING
|
---|
270 | # define RT_WITH_W64_UNWIND_HACK
|
---|
271 | #endif
|
---|
272 | /** @def UNWIND_WRAP
|
---|
273 | * If RT_WITH_W64_UNWIND_HACK is defined, the name will be prefixed with
|
---|
274 | * 'supdrvNtWrap'.
|
---|
275 | * @param Name The function to wrapper. */
|
---|
276 | #ifdef RT_WITH_W64_UNWIND_HACK
|
---|
277 | # define UNWIND_WRAP(Name) supdrvNtWrap##Name
|
---|
278 | #else
|
---|
279 | # define UNWIND_WRAP(Name) Name
|
---|
280 | #endif
|
---|
281 |
|
---|
282 |
|
---|
283 | /*
|
---|
284 | * Error codes.
|
---|
285 | */
|
---|
286 | /** @todo retire the SUPDRV_ERR_* stuff, we ship err.h now. */
|
---|
287 | /** Invalid parameter. */
|
---|
288 | #define SUPDRV_ERR_GENERAL_FAILURE (-1)
|
---|
289 | /** Invalid parameter. */
|
---|
290 | #define SUPDRV_ERR_INVALID_PARAM (-2)
|
---|
291 | /** Invalid magic or cookie. */
|
---|
292 | #define SUPDRV_ERR_INVALID_MAGIC (-3)
|
---|
293 | /** Invalid loader handle. */
|
---|
294 | #define SUPDRV_ERR_INVALID_HANDLE (-4)
|
---|
295 | /** Failed to lock the address range. */
|
---|
296 | #define SUPDRV_ERR_LOCK_FAILED (-5)
|
---|
297 | /** Invalid memory pointer. */
|
---|
298 | #define SUPDRV_ERR_INVALID_POINTER (-6)
|
---|
299 | /** Failed to patch the IDT. */
|
---|
300 | #define SUPDRV_ERR_IDT_FAILED (-7)
|
---|
301 | /** Memory allocation failed. */
|
---|
302 | #define SUPDRV_ERR_NO_MEMORY (-8)
|
---|
303 | /** Already loaded. */
|
---|
304 | #define SUPDRV_ERR_ALREADY_LOADED (-9)
|
---|
305 | /** Permission denied. */
|
---|
306 | #define SUPDRV_ERR_PERMISSION_DENIED (-10)
|
---|
307 | /** Version mismatch. */
|
---|
308 | #define SUPDRV_ERR_VERSION_MISMATCH (-11)
|
---|
309 |
|
---|
310 |
|
---|
311 |
|
---|
312 | /*******************************************************************************
|
---|
313 | * Structures and Typedefs *
|
---|
314 | *******************************************************************************/
|
---|
315 | /** Pointer to the device extension. */
|
---|
316 | typedef struct SUPDRVDEVEXT *PSUPDRVDEVEXT;
|
---|
317 |
|
---|
318 |
|
---|
319 | /**
|
---|
320 | * Memory reference types.
|
---|
321 | */
|
---|
322 | typedef enum
|
---|
323 | {
|
---|
324 | /** Unused entry */
|
---|
325 | MEMREF_TYPE_UNUSED = 0,
|
---|
326 | /** Locked memory (r3 mapping only). */
|
---|
327 | MEMREF_TYPE_LOCKED,
|
---|
328 | /** Continous memory block (r3 and r0 mapping). */
|
---|
329 | MEMREF_TYPE_CONT,
|
---|
330 | /** Low memory block (r3 and r0 mapping). */
|
---|
331 | MEMREF_TYPE_LOW,
|
---|
332 | /** Memory block (r3 and r0 mapping). */
|
---|
333 | MEMREF_TYPE_MEM,
|
---|
334 | /** Locked memory (r3 mapping only) allocated by the support driver. */
|
---|
335 | MEMREF_TYPE_PAGE,
|
---|
336 | /** Blow the type up to 32-bit and mark the end. */
|
---|
337 | MEMREG_TYPE_32BIT_HACK = 0x7fffffff
|
---|
338 | } SUPDRVMEMREFTYPE, *PSUPDRVMEMREFTYPE;
|
---|
339 |
|
---|
340 |
|
---|
341 | /**
|
---|
342 | * Structure used for tracking memory a session
|
---|
343 | * references in one way or another.
|
---|
344 | */
|
---|
345 | typedef struct SUPDRVMEMREF
|
---|
346 | {
|
---|
347 | /** The memory object handle. */
|
---|
348 | RTR0MEMOBJ MemObj;
|
---|
349 | /** The ring-3 mapping memory object handle. */
|
---|
350 | RTR0MEMOBJ MapObjR3;
|
---|
351 | /** Type of memory. */
|
---|
352 | SUPDRVMEMREFTYPE eType;
|
---|
353 | } SUPDRVMEMREF, *PSUPDRVMEMREF;
|
---|
354 |
|
---|
355 |
|
---|
356 | /**
|
---|
357 | * Bundle of locked memory ranges.
|
---|
358 | */
|
---|
359 | typedef struct SUPDRVBUNDLE
|
---|
360 | {
|
---|
361 | /** Pointer to the next bundle. */
|
---|
362 | struct SUPDRVBUNDLE * volatile pNext;
|
---|
363 | /** Referenced memory. */
|
---|
364 | SUPDRVMEMREF aMem[64];
|
---|
365 | /** Number of entries used. */
|
---|
366 | uint32_t volatile cUsed;
|
---|
367 | } SUPDRVBUNDLE, *PSUPDRVBUNDLE;
|
---|
368 |
|
---|
369 |
|
---|
370 | /**
|
---|
371 | * Loaded image.
|
---|
372 | */
|
---|
373 | typedef struct SUPDRVLDRIMAGE
|
---|
374 | {
|
---|
375 | /** Next in chain. */
|
---|
376 | struct SUPDRVLDRIMAGE * volatile pNext;
|
---|
377 | /** Pointer to the image. */
|
---|
378 | void *pvImage;
|
---|
379 | /** Pointer to the optional module initialization callback. */
|
---|
380 | PFNR0MODULEINIT pfnModuleInit;
|
---|
381 | /** Pointer to the optional module termination callback. */
|
---|
382 | PFNR0MODULETERM pfnModuleTerm;
|
---|
383 | /** Service request handler. This is NULL for non-service modules. */
|
---|
384 | PFNSUPR0SERVICEREQHANDLER pfnServiceReqHandler;
|
---|
385 | /** Size of the image. */
|
---|
386 | uint32_t cbImage;
|
---|
387 | /** The offset of the symbol table. */
|
---|
388 | uint32_t offSymbols;
|
---|
389 | /** The number of entries in the symbol table. */
|
---|
390 | uint32_t cSymbols;
|
---|
391 | /** The offset of the string table. */
|
---|
392 | uint32_t offStrTab;
|
---|
393 | /** Size of the string table. */
|
---|
394 | uint32_t cbStrTab;
|
---|
395 | /** The ldr image state. (IOCtl code of last opration.) */
|
---|
396 | uint32_t uState;
|
---|
397 | /** Usage count. */
|
---|
398 | uint32_t volatile cUsage;
|
---|
399 | /** Image name. */
|
---|
400 | char szName[32];
|
---|
401 | } SUPDRVLDRIMAGE, *PSUPDRVLDRIMAGE;
|
---|
402 |
|
---|
403 |
|
---|
404 | /** Image usage record. */
|
---|
405 | typedef struct SUPDRVLDRUSAGE
|
---|
406 | {
|
---|
407 | /** Next in chain. */
|
---|
408 | struct SUPDRVLDRUSAGE * volatile pNext;
|
---|
409 | /** The image. */
|
---|
410 | PSUPDRVLDRIMAGE pImage;
|
---|
411 | /** Load count. */
|
---|
412 | uint32_t volatile cUsage;
|
---|
413 | } SUPDRVLDRUSAGE, *PSUPDRVLDRUSAGE;
|
---|
414 |
|
---|
415 |
|
---|
416 | /**
|
---|
417 | * Component factory registration record.
|
---|
418 | */
|
---|
419 | typedef struct SUPDRVFACTORYREG
|
---|
420 | {
|
---|
421 | /** Pointer to the next registration. */
|
---|
422 | struct SUPDRVFACTORYREG *pNext;
|
---|
423 | /** Pointer to the registered factory. */
|
---|
424 | PCSUPDRVFACTORY pFactory;
|
---|
425 | /** The session owning the factory.
|
---|
426 | * Used for deregistration and session cleanup. */
|
---|
427 | PSUPDRVSESSION pSession;
|
---|
428 | /** Length of the name. */
|
---|
429 | size_t cchName;
|
---|
430 | } SUPDRVFACTORYREG;
|
---|
431 | /** Pointer to a component factory registration record. */
|
---|
432 | typedef SUPDRVFACTORYREG *PSUPDRVFACTORYREG;
|
---|
433 | /** Pointer to a const component factory registration record. */
|
---|
434 | typedef SUPDRVFACTORYREG const *PCSUPDRVFACTORYREG;
|
---|
435 |
|
---|
436 |
|
---|
437 | /**
|
---|
438 | * Registered object.
|
---|
439 | * This takes care of reference counting and tracking data for access checks.
|
---|
440 | */
|
---|
441 | typedef struct SUPDRVOBJ
|
---|
442 | {
|
---|
443 | /** Magic value (SUPDRVOBJ_MAGIC). */
|
---|
444 | uint32_t u32Magic;
|
---|
445 | /** The object type. */
|
---|
446 | SUPDRVOBJTYPE enmType;
|
---|
447 | /** Pointer to the next in the global list. */
|
---|
448 | struct SUPDRVOBJ * volatile pNext;
|
---|
449 | /** Pointer to the object destructor.
|
---|
450 | * This may be set to NULL if the image containing the destructor get unloaded. */
|
---|
451 | PFNSUPDRVDESTRUCTOR pfnDestructor;
|
---|
452 | /** User argument 1. */
|
---|
453 | void *pvUser1;
|
---|
454 | /** User argument 2. */
|
---|
455 | void *pvUser2;
|
---|
456 | /** The total sum of all per-session usage. */
|
---|
457 | uint32_t volatile cUsage;
|
---|
458 | /** The creator user id. */
|
---|
459 | RTUID CreatorUid;
|
---|
460 | /** The creator group id. */
|
---|
461 | RTGID CreatorGid;
|
---|
462 | /** The creator process id. */
|
---|
463 | RTPROCESS CreatorProcess;
|
---|
464 | } SUPDRVOBJ, *PSUPDRVOBJ;
|
---|
465 |
|
---|
466 | /** Magic number for SUPDRVOBJ::u32Magic. (Dame Agatha Mary Clarissa Christie). */
|
---|
467 | #define SUPDRVOBJ_MAGIC 0x18900915
|
---|
468 | /** Dead number magic for SUPDRVOBJ::u32Magic. */
|
---|
469 | #define SUPDRVOBJ_MAGIC_DEAD 0x19760112
|
---|
470 |
|
---|
471 | /**
|
---|
472 | * The per-session object usage record.
|
---|
473 | */
|
---|
474 | typedef struct SUPDRVUSAGE
|
---|
475 | {
|
---|
476 | /** Pointer to the next in the list. */
|
---|
477 | struct SUPDRVUSAGE * volatile pNext;
|
---|
478 | /** Pointer to the object we're recording usage for. */
|
---|
479 | PSUPDRVOBJ pObj;
|
---|
480 | /** The usage count. */
|
---|
481 | uint32_t volatile cUsage;
|
---|
482 | } SUPDRVUSAGE, *PSUPDRVUSAGE;
|
---|
483 |
|
---|
484 |
|
---|
485 | /**
|
---|
486 | * Per session data.
|
---|
487 | * This is mainly for memory tracking.
|
---|
488 | */
|
---|
489 | typedef struct SUPDRVSESSION
|
---|
490 | {
|
---|
491 | /** Pointer to the device extension. */
|
---|
492 | PSUPDRVDEVEXT pDevExt;
|
---|
493 | /** Session Cookie. */
|
---|
494 | uint32_t u32Cookie;
|
---|
495 |
|
---|
496 | /** Load usage records. (protected by SUPDRVDEVEXT::mtxLdr) */
|
---|
497 | PSUPDRVLDRUSAGE volatile pLdrUsage;
|
---|
498 | /** The VM associated with the session. */
|
---|
499 | PVM pVM;
|
---|
500 | /** List of generic usage records. (protected by SUPDRVDEVEXT::SpinLock) */
|
---|
501 | PSUPDRVUSAGE volatile pUsage;
|
---|
502 |
|
---|
503 | /** Spinlock protecting the bundles and the GIP members. */
|
---|
504 | RTSPINLOCK Spinlock;
|
---|
505 | /** The ring-3 mapping of the GIP (readonly). */
|
---|
506 | RTR0MEMOBJ GipMapObjR3;
|
---|
507 | /** Set if the session is using the GIP. */
|
---|
508 | uint32_t fGipReferenced;
|
---|
509 | /** Bundle of locked memory objects. */
|
---|
510 | SUPDRVBUNDLE Bundle;
|
---|
511 |
|
---|
512 | /** The user id of the session. (Set by the OS part.) */
|
---|
513 | RTUID Uid;
|
---|
514 | /** The group id of the session. (Set by the OS part.) */
|
---|
515 | RTGID Gid;
|
---|
516 | /** The process (id) of the session. */
|
---|
517 | RTPROCESS Process;
|
---|
518 | /** Which process this session is associated with.
|
---|
519 | * This is NIL_RTR0PROCESS for kernel sessions and valid for user ones. */
|
---|
520 | RTR0PROCESS R0Process;
|
---|
521 | #if defined(RT_OS_DARWIN)
|
---|
522 | /** Pointer to the associated org_virtualbox_SupDrvClient object. */
|
---|
523 | void *pvSupDrvClient;
|
---|
524 | /** Whether this session has been opened or not. */
|
---|
525 | bool fOpened;
|
---|
526 | #endif
|
---|
527 | #if defined(RT_OS_OS2)
|
---|
528 | /** The system file number of this session. */
|
---|
529 | uint16_t sfn;
|
---|
530 | uint16_t Alignment; /**< Alignment */
|
---|
531 | #endif
|
---|
532 | #if defined(RT_OS_DARWIN) || defined(RT_OS_OS2) || defined(RT_OS_SOLARIS)
|
---|
533 | /** Pointer to the next session with the same hash. */
|
---|
534 | PSUPDRVSESSION pNextHash;
|
---|
535 | #endif
|
---|
536 | } SUPDRVSESSION;
|
---|
537 |
|
---|
538 |
|
---|
539 | /**
|
---|
540 | * Device extension.
|
---|
541 | */
|
---|
542 | typedef struct SUPDRVDEVEXT
|
---|
543 | {
|
---|
544 | /** Spinlock to serialize the initialization,
|
---|
545 | * usage counting and destruction of the IDT entry override and objects. */
|
---|
546 | RTSPINLOCK Spinlock;
|
---|
547 |
|
---|
548 | /** List of registered objects. Protected by the spinlock. */
|
---|
549 | PSUPDRVOBJ volatile pObjs;
|
---|
550 | /** List of free object usage records. */
|
---|
551 | PSUPDRVUSAGE volatile pUsageFree;
|
---|
552 |
|
---|
553 | /** Global cookie. */
|
---|
554 | uint32_t u32Cookie;
|
---|
555 |
|
---|
556 | /** The IDT entry number.
|
---|
557 | * Only valid if pIdtPatches is set. */
|
---|
558 | uint8_t volatile u8Idt;
|
---|
559 |
|
---|
560 | /** Loader mutex.
|
---|
561 | * This protects pvVMMR0, pvVMMR0Entry, pImages and SUPDRVSESSION::pLdrUsage. */
|
---|
562 | RTSEMFASTMUTEX mtxLdr;
|
---|
563 |
|
---|
564 | /** VMM Module 'handle'.
|
---|
565 | * 0 if the code VMM isn't loaded and Idt are nops. */
|
---|
566 | void * volatile pvVMMR0;
|
---|
567 | /** VMMR0EntryInt() pointer. */
|
---|
568 | DECLR0CALLBACKMEMBER(int, pfnVMMR0EntryInt, (PVM pVM, unsigned uOperation, void *pvArg));
|
---|
569 | /** VMMR0EntryFast() pointer. */
|
---|
570 | DECLR0CALLBACKMEMBER(void, pfnVMMR0EntryFast, (PVM pVM, unsigned idCpu, unsigned uOperation));
|
---|
571 | /** VMMR0EntryEx() pointer. */
|
---|
572 | DECLR0CALLBACKMEMBER(int, pfnVMMR0EntryEx, (PVM pVM, unsigned uOperation, PSUPVMMR0REQHDR pReq, uint64_t u64Arg, PSUPDRVSESSION pSession));
|
---|
573 |
|
---|
574 | /** Linked list of loaded code. */
|
---|
575 | PSUPDRVLDRIMAGE volatile pLdrImages;
|
---|
576 |
|
---|
577 | /** GIP mutex.
|
---|
578 | * Any changes to any of the GIP members requires ownership of this mutex,
|
---|
579 | * except on driver init and termination. */
|
---|
580 | RTSEMFASTMUTEX mtxGip;
|
---|
581 | /** Pointer to the Global Info Page (GIP). */
|
---|
582 | PSUPGLOBALINFOPAGE pGip;
|
---|
583 | /** The physical address of the GIP. */
|
---|
584 | RTHCPHYS HCPhysGip;
|
---|
585 | /** Number of processes using the GIP.
|
---|
586 | * (The updates are suspend while cGipUsers is 0.)*/
|
---|
587 | uint32_t volatile cGipUsers;
|
---|
588 | /** The ring-0 memory object handle for the GIP page. */
|
---|
589 | RTR0MEMOBJ GipMemObj;
|
---|
590 | /** The GIP timer handle. */
|
---|
591 | PRTTIMER pGipTimer;
|
---|
592 | /** If non-zero we've successfully called RTTimerRequestSystemGranularity(). */
|
---|
593 | uint32_t u32SystemTimerGranularityGrant;
|
---|
594 | /** The CPU id of the GIP master.
|
---|
595 | * This CPU is responsible for the updating the common GIP data. */
|
---|
596 | RTCPUID volatile idGipMaster;
|
---|
597 |
|
---|
598 | #ifdef RT_OS_WINDOWS
|
---|
599 | /* Callback object returned by ExCreateCallback. */
|
---|
600 | PCALLBACK_OBJECT pObjPowerCallback;
|
---|
601 | /* Callback handle returned by ExRegisterCallback. */
|
---|
602 | PVOID hPowerCallback;
|
---|
603 | #endif
|
---|
604 |
|
---|
605 | /** Component factory mutex.
|
---|
606 | * This protects pComponentFactoryHead and component factory querying. */
|
---|
607 | RTSEMFASTMUTEX mtxComponentFactory;
|
---|
608 | /** The head of the list of registered component factories. */
|
---|
609 | PSUPDRVFACTORYREG pComponentFactoryHead;
|
---|
610 | } SUPDRVDEVEXT;
|
---|
611 |
|
---|
612 |
|
---|
613 | __BEGIN_DECLS
|
---|
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 |
|
---|
623 | /*******************************************************************************
|
---|
624 | * Shared Functions *
|
---|
625 | *******************************************************************************/
|
---|
626 | int VBOXCALL supdrvIOCtl(uintptr_t uIOCtl, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPREQHDR pReqHdr);
|
---|
627 | int VBOXCALL supdrvIOCtlFast(uintptr_t uIOCtl, unsigned idCpu, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession);
|
---|
628 | int VBOXCALL supdrvIDC(uintptr_t uIOCtl, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPDRVIDCREQHDR pReqHdr);
|
---|
629 | int VBOXCALL supdrvInitDevExt(PSUPDRVDEVEXT pDevExt);
|
---|
630 | void VBOXCALL supdrvDeleteDevExt(PSUPDRVDEVEXT pDevExt);
|
---|
631 | int VBOXCALL supdrvCreateSession(PSUPDRVDEVEXT pDevExt, bool fUser, PSUPDRVSESSION *ppSession);
|
---|
632 | void VBOXCALL supdrvCloseSession(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession);
|
---|
633 | void VBOXCALL supdrvCleanupSession(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession);
|
---|
634 | int VBOXCALL supdrvGipInit(PSUPDRVDEVEXT pDevExt, PSUPGLOBALINFOPAGE pGip, RTHCPHYS HCPhys, uint64_t u64NanoTS, unsigned uUpdateHz);
|
---|
635 | void VBOXCALL supdrvGipTerm(PSUPGLOBALINFOPAGE pGip);
|
---|
636 | void VBOXCALL supdrvGipUpdate(PSUPGLOBALINFOPAGE pGip, uint64_t u64NanoTS);
|
---|
637 | void VBOXCALL supdrvGipUpdatePerCpu(PSUPGLOBALINFOPAGE pGip, uint64_t u64NanoTS, unsigned iCpu);
|
---|
638 | bool VBOXCALL supdrvDetermineAsyncTsc(uint64_t *pu64DiffCores);
|
---|
639 |
|
---|
640 | __END_DECLS
|
---|
641 |
|
---|
642 | #endif
|
---|
643 |
|
---|