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