1 | /* $Revision: 10252 $ */
|
---|
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 ___SUPDRV_h
|
---|
32 | #define ___SUPDRV_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 | # include <asm/semaphore.h>
|
---|
101 | # include <linux/timer.h>
|
---|
102 |
|
---|
103 | # if 0
|
---|
104 | # include <linux/hrtimer.h>
|
---|
105 | # define VBOX_HRTIMER
|
---|
106 | # endif
|
---|
107 |
|
---|
108 | #elif defined(RT_OS_DARWIN)
|
---|
109 | # include <libkern/libkern.h>
|
---|
110 | # include <iprt/string.h>
|
---|
111 |
|
---|
112 | #elif defined(RT_OS_OS2)
|
---|
113 |
|
---|
114 | #elif defined(RT_OS_FREEBSD)
|
---|
115 | # include <sys/libkern.h>
|
---|
116 | # include <iprt/string.h>
|
---|
117 |
|
---|
118 | #elif defined(RT_OS_SOLARIS)
|
---|
119 | # include <sys/cmn_err.h>
|
---|
120 | # include <iprt/string.h>
|
---|
121 |
|
---|
122 | #else
|
---|
123 | # error "unsupported OS."
|
---|
124 | #endif
|
---|
125 |
|
---|
126 | #include "SUPDRVIOC.h"
|
---|
127 |
|
---|
128 |
|
---|
129 |
|
---|
130 | /*******************************************************************************
|
---|
131 | * Defined Constants And Macros *
|
---|
132 | *******************************************************************************/
|
---|
133 | /*
|
---|
134 | * Hardcoded cookies.
|
---|
135 | */
|
---|
136 | #define BIRD 0x64726962 /* 'bird' */
|
---|
137 | #define BIRD_INV 0x62697264 /* 'drib' */
|
---|
138 |
|
---|
139 |
|
---|
140 | /*
|
---|
141 | * Win32
|
---|
142 | */
|
---|
143 | #if defined(RT_OS_WINDOWS)
|
---|
144 |
|
---|
145 | /* debug printf */
|
---|
146 | # define OSDBGPRINT(a) DbgPrint a
|
---|
147 |
|
---|
148 | /** Maximum number of bytes we try to lock down in one go.
|
---|
149 | * This is supposed to have a limit right below 256MB, but this appears
|
---|
150 | * to actually be much lower. The values here have been determined experimentally.
|
---|
151 | */
|
---|
152 | #ifdef RT_ARCH_X86
|
---|
153 | # define MAX_LOCK_MEM_SIZE (32*1024*1024) /* 32mb */
|
---|
154 | #endif
|
---|
155 | #ifdef RT_ARCH_AMD64
|
---|
156 | # define MAX_LOCK_MEM_SIZE (24*1024*1024) /* 24mb */
|
---|
157 | #endif
|
---|
158 |
|
---|
159 |
|
---|
160 | /*
|
---|
161 | * Linux
|
---|
162 | */
|
---|
163 | #elif defined(RT_OS_LINUX)
|
---|
164 |
|
---|
165 | /* check kernel version */
|
---|
166 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 0)
|
---|
167 | # error Unsupported kernel version!
|
---|
168 | #endif
|
---|
169 |
|
---|
170 | __BEGIN_DECLS
|
---|
171 | int linux_dprintf(const char *format, ...);
|
---|
172 | __END_DECLS
|
---|
173 |
|
---|
174 | /* debug printf */
|
---|
175 | # define OSDBGPRINT(a) printk a
|
---|
176 |
|
---|
177 |
|
---|
178 | /*
|
---|
179 | * Darwin
|
---|
180 | */
|
---|
181 | #elif defined(RT_OS_DARWIN)
|
---|
182 |
|
---|
183 | /* debug printf */
|
---|
184 | # define OSDBGPRINT(a) printf a
|
---|
185 |
|
---|
186 |
|
---|
187 | /*
|
---|
188 | * OS/2
|
---|
189 | */
|
---|
190 | #elif defined(RT_OS_OS2)
|
---|
191 |
|
---|
192 | /* No log API in OS/2 only COM port. */
|
---|
193 | # define OSDBGPRINT(a) SUPR0Printf a
|
---|
194 |
|
---|
195 |
|
---|
196 | /*
|
---|
197 | * FreeBSD
|
---|
198 | */
|
---|
199 | #elif defined(RT_OS_FREEBSD)
|
---|
200 |
|
---|
201 | /* debug printf */
|
---|
202 | # define OSDBGPRINT(a) printf a
|
---|
203 |
|
---|
204 |
|
---|
205 | /*
|
---|
206 | * Solaris
|
---|
207 | */
|
---|
208 | #elif defined(RT_OS_SOLARIS)
|
---|
209 | # define OSDBGPRINT(a) SUPR0Printf a
|
---|
210 |
|
---|
211 |
|
---|
212 | #else
|
---|
213 | /** @todo other os'es */
|
---|
214 | # error "OS interface defines is not done for this OS!"
|
---|
215 | #endif
|
---|
216 |
|
---|
217 |
|
---|
218 | /* dprintf */
|
---|
219 | #if (defined(DEBUG) && !defined(NO_LOGGING)) || defined(RT_OS_FREEBSD)
|
---|
220 | # ifdef LOG_TO_COM
|
---|
221 | # include <VBox/log.h>
|
---|
222 | # define dprintf(a) RTLogComPrintf a
|
---|
223 | # else
|
---|
224 | # define dprintf(a) OSDBGPRINT(a)
|
---|
225 | # endif
|
---|
226 | #else
|
---|
227 | # define dprintf(a) do {} while (0)
|
---|
228 | #endif
|
---|
229 |
|
---|
230 | /* dprintf2 - extended logging. */
|
---|
231 | #if defined(RT_OS_DARWIN) || defined(RT_OS_OS2) || defined(RT_OS_FREEBSD)
|
---|
232 | # define dprintf2 dprintf
|
---|
233 | #else
|
---|
234 | # define dprintf2(a) do { } while (0)
|
---|
235 | #endif
|
---|
236 |
|
---|
237 |
|
---|
238 | /*
|
---|
239 | * Error codes.
|
---|
240 | */
|
---|
241 | /** Invalid parameter. */
|
---|
242 | #define SUPDRV_ERR_GENERAL_FAILURE (-1)
|
---|
243 | /** Invalid parameter. */
|
---|
244 | #define SUPDRV_ERR_INVALID_PARAM (-2)
|
---|
245 | /** Invalid magic or cookie. */
|
---|
246 | #define SUPDRV_ERR_INVALID_MAGIC (-3)
|
---|
247 | /** Invalid loader handle. */
|
---|
248 | #define SUPDRV_ERR_INVALID_HANDLE (-4)
|
---|
249 | /** Failed to lock the address range. */
|
---|
250 | #define SUPDRV_ERR_LOCK_FAILED (-5)
|
---|
251 | /** Invalid memory pointer. */
|
---|
252 | #define SUPDRV_ERR_INVALID_POINTER (-6)
|
---|
253 | /** Failed to patch the IDT. */
|
---|
254 | #define SUPDRV_ERR_IDT_FAILED (-7)
|
---|
255 | /** Memory allocation failed. */
|
---|
256 | #define SUPDRV_ERR_NO_MEMORY (-8)
|
---|
257 | /** Already loaded. */
|
---|
258 | #define SUPDRV_ERR_ALREADY_LOADED (-9)
|
---|
259 | /** Permission denied. */
|
---|
260 | #define SUPDRV_ERR_PERMISSION_DENIED (-10)
|
---|
261 | /** Version mismatch. */
|
---|
262 | #define SUPDRV_ERR_VERSION_MISMATCH (-11)
|
---|
263 |
|
---|
264 |
|
---|
265 |
|
---|
266 | /*******************************************************************************
|
---|
267 | * Structures and Typedefs *
|
---|
268 | *******************************************************************************/
|
---|
269 | /** Pointer to the device extension. */
|
---|
270 | typedef struct SUPDRVDEVEXT *PSUPDRVDEVEXT;
|
---|
271 |
|
---|
272 | #ifdef VBOX_WITH_IDT_PATCHING
|
---|
273 |
|
---|
274 | /**
|
---|
275 | * An IDT Entry.
|
---|
276 | */
|
---|
277 | typedef struct SUPDRVIDTE
|
---|
278 | {
|
---|
279 | /** Low offset word. */
|
---|
280 | uint32_t u16OffsetLow : 16;
|
---|
281 | /** Segment Selector. */
|
---|
282 | uint32_t u16SegSel : 16;
|
---|
283 | #ifdef RT_ARCH_AMD64
|
---|
284 | /** Interrupt Stack Table index. */
|
---|
285 | uint32_t u3IST : 3;
|
---|
286 | /** Reserved, ignored. */
|
---|
287 | uint32_t u5Reserved : 5;
|
---|
288 | #else
|
---|
289 | /** Reserved. */
|
---|
290 | uint32_t u5Reserved : 5;
|
---|
291 | /** IDT Type part one (not used for task gate). */
|
---|
292 | uint32_t u3Type1 : 3;
|
---|
293 | #endif
|
---|
294 | /** IDT Type part two. */
|
---|
295 | uint32_t u5Type2 : 5;
|
---|
296 | /** Descriptor Privilege level. */
|
---|
297 | uint32_t u2DPL : 2;
|
---|
298 | /** Present flag. */
|
---|
299 | uint32_t u1Present : 1;
|
---|
300 | /** High offset word. */
|
---|
301 | uint32_t u16OffsetHigh : 16;
|
---|
302 | #ifdef RT_ARCH_AMD64
|
---|
303 | /** The upper top part of the address. */
|
---|
304 | uint32_t u32OffsetTop;
|
---|
305 | /** Reserved dword for qword (aligning the struct), ignored. */
|
---|
306 | uint32_t u32Reserved;
|
---|
307 | #endif
|
---|
308 | } SUPDRVIDTE, *PSUPDRVIDTE;
|
---|
309 |
|
---|
310 | /** The u5Type2 value for an interrupt gate. */
|
---|
311 | #define SUPDRV_IDTE_TYPE2_INTERRUPT_GATE 0x0e
|
---|
312 |
|
---|
313 |
|
---|
314 | /**
|
---|
315 | * Patch code.
|
---|
316 | */
|
---|
317 | typedef struct SUPDRVPATCH
|
---|
318 | {
|
---|
319 | #define SUPDRV_PATCH_CODE_SIZE 0x50
|
---|
320 | /** Patch code. */
|
---|
321 | uint8_t auCode[SUPDRV_PATCH_CODE_SIZE];
|
---|
322 | /** Changed IDT entry (for parnoid UnpatchIdt()). */
|
---|
323 | SUPDRVIDTE ChangedIdt;
|
---|
324 | /** Saved IDT entry. */
|
---|
325 | SUPDRVIDTE SavedIdt;
|
---|
326 | /** Pointer to the IDT.
|
---|
327 | * We ASSUME the IDT is not re(al)located after bootup and use this as key
|
---|
328 | * for the patches rather than processor number. This prevents some
|
---|
329 | * stupid nesting stuff from happening in case of processors sharing the
|
---|
330 | * IDT.
|
---|
331 | * We're fucked if the processors have different physical mapping for
|
---|
332 | * the(se) page(s), but we'll find that out soon enough in VBOX_STRICT mode.
|
---|
333 | */
|
---|
334 | void *pvIdt;
|
---|
335 | /** Pointer to the IDT entry. */
|
---|
336 | SUPDRVIDTE volatile *pIdtEntry;
|
---|
337 | /** Usage counter. */
|
---|
338 | uint32_t volatile cUsage;
|
---|
339 | /** The offset into auCode of the VMMR0Entry fixup. */
|
---|
340 | uint16_t offVMMR0EntryFixup;
|
---|
341 | /** The offset into auCode of the stub function. */
|
---|
342 | uint16_t offStub;
|
---|
343 | /** Pointer to the next patch. */
|
---|
344 | struct SUPDRVPATCH * volatile pNext;
|
---|
345 | } SUPDRVPATCH, *PSUPDRVPATCH;
|
---|
346 |
|
---|
347 | /**
|
---|
348 | * Usage record for a patch.
|
---|
349 | */
|
---|
350 | typedef struct SUPDRVPATCHUSAGE
|
---|
351 | {
|
---|
352 | /** Next in the chain. */
|
---|
353 | struct SUPDRVPATCHUSAGE * volatile pNext;
|
---|
354 | /** The patch this usage applies to. */
|
---|
355 | PSUPDRVPATCH pPatch;
|
---|
356 | /** Usage count. */
|
---|
357 | uint32_t volatile cUsage;
|
---|
358 | } SUPDRVPATCHUSAGE, *PSUPDRVPATCHUSAGE;
|
---|
359 |
|
---|
360 | #endif /* VBOX_WITH_IDT_PATCHING */
|
---|
361 |
|
---|
362 |
|
---|
363 | /**
|
---|
364 | * Memory reference types.
|
---|
365 | */
|
---|
366 | typedef enum
|
---|
367 | {
|
---|
368 | /** Unused entry */
|
---|
369 | MEMREF_TYPE_UNUSED = 0,
|
---|
370 | /** Locked memory (r3 mapping only). */
|
---|
371 | MEMREF_TYPE_LOCKED,
|
---|
372 | /** Continous memory block (r3 and r0 mapping). */
|
---|
373 | MEMREF_TYPE_CONT,
|
---|
374 | /** Low memory block (r3 and r0 mapping). */
|
---|
375 | MEMREF_TYPE_LOW,
|
---|
376 | /** Memory block (r3 and r0 mapping). */
|
---|
377 | MEMREF_TYPE_MEM,
|
---|
378 | /** Locked memory (r3 mapping only) allocated by the support driver. */
|
---|
379 | MEMREF_TYPE_LOCKED_SUP,
|
---|
380 | /** Blow the type up to 32-bit and mark the end. */
|
---|
381 | MEMREG_TYPE_32BIT_HACK = 0x7fffffff
|
---|
382 | } SUPDRVMEMREFTYPE, *PSUPDRVMEMREFTYPE;
|
---|
383 |
|
---|
384 |
|
---|
385 | /**
|
---|
386 | * Structure used for tracking memory a session
|
---|
387 | * references in one way or another.
|
---|
388 | */
|
---|
389 | typedef struct SUPDRVMEMREF
|
---|
390 | {
|
---|
391 | /** The memory object handle. */
|
---|
392 | RTR0MEMOBJ MemObj;
|
---|
393 | /** The ring-3 mapping memory object handle. */
|
---|
394 | RTR0MEMOBJ MapObjR3;
|
---|
395 | /** Type of memory. */
|
---|
396 | SUPDRVMEMREFTYPE eType;
|
---|
397 | } SUPDRVMEMREF, *PSUPDRVMEMREF;
|
---|
398 |
|
---|
399 |
|
---|
400 | /**
|
---|
401 | * Bundle of locked memory ranges.
|
---|
402 | */
|
---|
403 | typedef struct SUPDRVBUNDLE
|
---|
404 | {
|
---|
405 | /** Pointer to the next bundle. */
|
---|
406 | struct SUPDRVBUNDLE * volatile pNext;
|
---|
407 | /** Referenced memory. */
|
---|
408 | SUPDRVMEMREF aMem[64];
|
---|
409 | /** Number of entries used. */
|
---|
410 | uint32_t volatile cUsed;
|
---|
411 | } SUPDRVBUNDLE, *PSUPDRVBUNDLE;
|
---|
412 |
|
---|
413 |
|
---|
414 | /**
|
---|
415 | * Loaded image.
|
---|
416 | */
|
---|
417 | typedef struct SUPDRVLDRIMAGE
|
---|
418 | {
|
---|
419 | /** Next in chain. */
|
---|
420 | struct SUPDRVLDRIMAGE * volatile pNext;
|
---|
421 | /** Pointer to the image. */
|
---|
422 | void *pvImage;
|
---|
423 | /** Pointer to the optional module initialization callback. */
|
---|
424 | PFNR0MODULEINIT pfnModuleInit;
|
---|
425 | /** Pointer to the optional module termination callback. */
|
---|
426 | PFNR0MODULETERM pfnModuleTerm;
|
---|
427 | /** Size of the image. */
|
---|
428 | uint32_t cbImage;
|
---|
429 | /** The offset of the symbol table. */
|
---|
430 | uint32_t offSymbols;
|
---|
431 | /** The number of entries in the symbol table. */
|
---|
432 | uint32_t cSymbols;
|
---|
433 | /** The offset of the string table. */
|
---|
434 | uint32_t offStrTab;
|
---|
435 | /** Size of the string table. */
|
---|
436 | uint32_t cbStrTab;
|
---|
437 | /** The ldr image state. (IOCtl code of last opration.) */
|
---|
438 | uint32_t uState;
|
---|
439 | /** Usage count. */
|
---|
440 | uint32_t volatile cUsage;
|
---|
441 | /** Image name. */
|
---|
442 | char szName[32];
|
---|
443 | } SUPDRVLDRIMAGE, *PSUPDRVLDRIMAGE;
|
---|
444 |
|
---|
445 |
|
---|
446 | /** Image usage record. */
|
---|
447 | typedef struct SUPDRVLDRUSAGE
|
---|
448 | {
|
---|
449 | /** Next in chain. */
|
---|
450 | struct SUPDRVLDRUSAGE * volatile pNext;
|
---|
451 | /** The image. */
|
---|
452 | PSUPDRVLDRIMAGE pImage;
|
---|
453 | /** Load count. */
|
---|
454 | uint32_t volatile cUsage;
|
---|
455 | } SUPDRVLDRUSAGE, *PSUPDRVLDRUSAGE;
|
---|
456 |
|
---|
457 |
|
---|
458 | /**
|
---|
459 | * Registered object.
|
---|
460 | * This takes care of reference counting and tracking data for access checks.
|
---|
461 | */
|
---|
462 | typedef struct SUPDRVOBJ
|
---|
463 | {
|
---|
464 | /** Magic value (SUPDRVOBJ_MAGIC). */
|
---|
465 | uint32_t u32Magic;
|
---|
466 | /** The object type. */
|
---|
467 | SUPDRVOBJTYPE enmType;
|
---|
468 | /** Pointer to the next in the global list. */
|
---|
469 | struct SUPDRVOBJ * volatile pNext;
|
---|
470 | /** Pointer to the object destructor.
|
---|
471 | * This may be set to NULL if the image containing the destructor get unloaded. */
|
---|
472 | PFNSUPDRVDESTRUCTOR pfnDestructor;
|
---|
473 | /** User argument 1. */
|
---|
474 | void *pvUser1;
|
---|
475 | /** User argument 2. */
|
---|
476 | void *pvUser2;
|
---|
477 | /** The total sum of all per-session usage. */
|
---|
478 | uint32_t volatile cUsage;
|
---|
479 | /** The creator user id. */
|
---|
480 | RTUID CreatorUid;
|
---|
481 | /** The creator group id. */
|
---|
482 | RTGID CreatorGid;
|
---|
483 | /** The creator process id. */
|
---|
484 | RTPROCESS CreatorProcess;
|
---|
485 | } SUPDRVOBJ, *PSUPDRVOBJ;
|
---|
486 |
|
---|
487 | /** Magic number for SUPDRVOBJ::u32Magic. (Dame Agatha Mary Clarissa Christie). */
|
---|
488 | #define SUPDRVOBJ_MAGIC 0x18900915
|
---|
489 |
|
---|
490 | /**
|
---|
491 | * The per-session object usage record.
|
---|
492 | */
|
---|
493 | typedef struct SUPDRVUSAGE
|
---|
494 | {
|
---|
495 | /** Pointer to the next in the list. */
|
---|
496 | struct SUPDRVUSAGE * volatile pNext;
|
---|
497 | /** Pointer to the object we're recording usage for. */
|
---|
498 | PSUPDRVOBJ pObj;
|
---|
499 | /** The usage count. */
|
---|
500 | uint32_t volatile cUsage;
|
---|
501 | } SUPDRVUSAGE, *PSUPDRVUSAGE;
|
---|
502 |
|
---|
503 |
|
---|
504 | /**
|
---|
505 | * Per session data.
|
---|
506 | * This is mainly for memory tracking.
|
---|
507 | */
|
---|
508 | typedef struct SUPDRVSESSION
|
---|
509 | {
|
---|
510 | /** Pointer to the device extension. */
|
---|
511 | PSUPDRVDEVEXT pDevExt;
|
---|
512 | /** Session Cookie. */
|
---|
513 | uint32_t u32Cookie;
|
---|
514 |
|
---|
515 | /** Load usage records. (protected by SUPDRVDEVEXT::mtxLdr) */
|
---|
516 | PSUPDRVLDRUSAGE volatile pLdrUsage;
|
---|
517 | #ifdef VBOX_WITH_IDT_PATCHING
|
---|
518 | /** Patch usage records. (protected by SUPDRVDEVEXT::SpinLock) */
|
---|
519 | PSUPDRVPATCHUSAGE volatile pPatchUsage;
|
---|
520 | #endif
|
---|
521 | /** The VM associated with the session. */
|
---|
522 | PVM pVM;
|
---|
523 | /** List of generic usage records. (protected by SUPDRVDEVEXT::SpinLock) */
|
---|
524 | PSUPDRVUSAGE volatile pUsage;
|
---|
525 |
|
---|
526 | /** Spinlock protecting the bundles and the GIP members. */
|
---|
527 | RTSPINLOCK Spinlock;
|
---|
528 | /** The ring-3 mapping of the GIP (readonly). */
|
---|
529 | RTR0MEMOBJ GipMapObjR3;
|
---|
530 | /** Set if the session is using the GIP. */
|
---|
531 | uint32_t fGipReferenced;
|
---|
532 | /** Bundle of locked memory objects. */
|
---|
533 | SUPDRVBUNDLE Bundle;
|
---|
534 |
|
---|
535 | /** The user id of the session. (Set by the OS part.) */
|
---|
536 | RTUID Uid;
|
---|
537 | /** The group id of the session. (Set by the OS part.) */
|
---|
538 | RTGID Gid;
|
---|
539 | /** The process (id) of the session. (Set by the OS part.) */
|
---|
540 | RTPROCESS Process;
|
---|
541 | /** Which process this session is associated with. */
|
---|
542 | RTR0PROCESS R0Process;
|
---|
543 | #if defined(RT_OS_OS2)
|
---|
544 | /** The system file number of this session. */
|
---|
545 | uint16_t sfn;
|
---|
546 | uint16_t Alignment; /**< Alignment */
|
---|
547 | #endif
|
---|
548 | #if defined(RT_OS_DARWIN) || defined(RT_OS_OS2) || defined(RT_OS_SOLARIS)
|
---|
549 | /** Pointer to the next session with the same hash. */
|
---|
550 | PSUPDRVSESSION pNextHash;
|
---|
551 | #endif
|
---|
552 | } SUPDRVSESSION;
|
---|
553 |
|
---|
554 |
|
---|
555 | /**
|
---|
556 | * Device extension.
|
---|
557 | */
|
---|
558 | typedef struct SUPDRVDEVEXT
|
---|
559 | {
|
---|
560 | /** Spinlock to serialize the initialization,
|
---|
561 | * usage counting and destruction of the IDT entry override and objects. */
|
---|
562 | RTSPINLOCK Spinlock;
|
---|
563 |
|
---|
564 | #ifdef VBOX_WITH_IDT_PATCHING
|
---|
565 | /** List of patches. */
|
---|
566 | PSUPDRVPATCH volatile pIdtPatches;
|
---|
567 | /** List of patches Free. */
|
---|
568 | PSUPDRVPATCH volatile pIdtPatchesFree;
|
---|
569 | #endif
|
---|
570 |
|
---|
571 | /** List of registered objects. Protected by the spinlock. */
|
---|
572 | PSUPDRVOBJ volatile pObjs;
|
---|
573 | /** List of free object usage records. */
|
---|
574 | PSUPDRVUSAGE volatile pUsageFree;
|
---|
575 |
|
---|
576 | /** Global cookie. */
|
---|
577 | uint32_t u32Cookie;
|
---|
578 |
|
---|
579 | /** The IDT entry number.
|
---|
580 | * Only valid if pIdtPatches is set. */
|
---|
581 | uint8_t volatile u8Idt;
|
---|
582 |
|
---|
583 | /** Loader mutex.
|
---|
584 | * This protects pvVMMR0, pvVMMR0Entry, pImages and SUPDRVSESSION::pLdrUsage. */
|
---|
585 | RTSEMFASTMUTEX mtxLdr;
|
---|
586 |
|
---|
587 | /** VMM Module 'handle'.
|
---|
588 | * 0 if the code VMM isn't loaded and Idt are nops. */
|
---|
589 | void * volatile pvVMMR0;
|
---|
590 | /** VMMR0EntryInt() pointer. */
|
---|
591 | DECLR0CALLBACKMEMBER(int, pfnVMMR0EntryInt, (PVM pVM, unsigned uOperation, void *pvArg));
|
---|
592 | /** VMMR0EntryFast() pointer. */
|
---|
593 | DECLR0CALLBACKMEMBER(int, pfnVMMR0EntryFast, (PVM pVM, unsigned uOperation));
|
---|
594 | /** VMMR0EntryEx() pointer. */
|
---|
595 | DECLR0CALLBACKMEMBER(int, pfnVMMR0EntryEx, (PVM pVM, unsigned uOperation, PSUPVMMR0REQHDR pReq, uint64_t u64Arg));
|
---|
596 |
|
---|
597 | /** Linked list of loaded code. */
|
---|
598 | PSUPDRVLDRIMAGE volatile pLdrImages;
|
---|
599 |
|
---|
600 | /** GIP mutex.
|
---|
601 | * Any changes to any of the GIP members requires ownership of this mutex,
|
---|
602 | * except on driver init and termination. */
|
---|
603 | RTSEMFASTMUTEX mtxGip;
|
---|
604 | /** Pointer to the Global Info Page (GIP). */
|
---|
605 | PSUPGLOBALINFOPAGE pGip;
|
---|
606 | /** The physical address of the GIP. */
|
---|
607 | RTHCPHYS HCPhysGip;
|
---|
608 | /** Number of processes using the GIP.
|
---|
609 | * (The updates are suspend while cGipUsers is 0.)*/
|
---|
610 | uint32_t volatile cGipUsers;
|
---|
611 | /** The ring-0 memory object handle for the GIP page. */
|
---|
612 | RTR0MEMOBJ GipMemObj;
|
---|
613 | /** The GIP timer handle. */
|
---|
614 | PRTTIMER pGipTimer;
|
---|
615 | /** If non-zero we've successfully called RTTimerRequestSystemGranularity(). */
|
---|
616 | uint32_t u32SystemTimerGranularityGrant;
|
---|
617 | /** The CPU id of the GIP master.
|
---|
618 | * This CPU is responsible for the updating the common GIP data. */
|
---|
619 | RTCPUID volatile idGipMaster;
|
---|
620 | } SUPDRVDEVEXT;
|
---|
621 |
|
---|
622 |
|
---|
623 | __BEGIN_DECLS
|
---|
624 |
|
---|
625 | /*******************************************************************************
|
---|
626 | * OS Specific Functions *
|
---|
627 | *******************************************************************************/
|
---|
628 | void VBOXCALL supdrvOSObjInitCreator(PSUPDRVOBJ pObj, PSUPDRVSESSION pSession);
|
---|
629 | bool VBOXCALL supdrvOSObjCanAccess(PSUPDRVOBJ pObj, PSUPDRVSESSION pSession, const char *pszObjName, int *prc);
|
---|
630 | bool VBOXCALL supdrvOSGetForcedAsyncTscMode(PSUPDRVDEVEXT pDevExt);
|
---|
631 |
|
---|
632 |
|
---|
633 | /*******************************************************************************
|
---|
634 | * Shared Functions *
|
---|
635 | *******************************************************************************/
|
---|
636 | int VBOXCALL supdrvIOCtl(uintptr_t uIOCtl, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPREQHDR pReqHdr);
|
---|
637 | int VBOXCALL supdrvIOCtlFast(uintptr_t uIOCtl, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession);
|
---|
638 | int VBOXCALL supdrvInitDevExt(PSUPDRVDEVEXT pDevExt);
|
---|
639 | void VBOXCALL supdrvDeleteDevExt(PSUPDRVDEVEXT pDevExt);
|
---|
640 | int VBOXCALL supdrvCreateSession(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION *ppSession);
|
---|
641 | void VBOXCALL supdrvCloseSession(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession);
|
---|
642 | void VBOXCALL supdrvCleanupSession(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession);
|
---|
643 | int VBOXCALL supdrvGipInit(PSUPDRVDEVEXT pDevExt, PSUPGLOBALINFOPAGE pGip, RTHCPHYS HCPhys, uint64_t u64NanoTS, unsigned uUpdateHz);
|
---|
644 | void VBOXCALL supdrvGipTerm(PSUPGLOBALINFOPAGE pGip);
|
---|
645 | void VBOXCALL supdrvGipUpdate(PSUPGLOBALINFOPAGE pGip, uint64_t u64NanoTS);
|
---|
646 | void VBOXCALL supdrvGipUpdatePerCpu(PSUPGLOBALINFOPAGE pGip, uint64_t u64NanoTS, unsigned iCpu);
|
---|
647 | bool VBOXCALL supdrvDetermineAsyncTsc(uint64_t *pu64DiffCores);
|
---|
648 |
|
---|
649 | __END_DECLS
|
---|
650 |
|
---|
651 | #endif
|
---|
652 |
|
---|