1 | /* $Revision: 25591 $ */
|
---|
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 | #ifdef SUPDRV_AGNOSTIC
|
---|
50 | /* do nothing */
|
---|
51 |
|
---|
52 | #elif defined(RT_OS_WINDOWS)
|
---|
53 | RT_C_DECLS_BEGIN
|
---|
54 | # if (_MSC_VER >= 1400) && !defined(VBOX_WITH_PATCHED_DDK)
|
---|
55 | # define _InterlockedExchange _InterlockedExchange_StupidDDKVsCompilerCrap
|
---|
56 | # define _InterlockedExchangeAdd _InterlockedExchangeAdd_StupidDDKVsCompilerCrap
|
---|
57 | # define _InterlockedCompareExchange _InterlockedCompareExchange_StupidDDKVsCompilerCrap
|
---|
58 | # define _InterlockedAddLargeStatistic _InterlockedAddLargeStatistic_StupidDDKVsCompilerCrap
|
---|
59 | # define _interlockedbittestandset _interlockedbittestandset_StupidDDKVsCompilerCrap
|
---|
60 | # define _interlockedbittestandreset _interlockedbittestandreset_StupidDDKVsCompilerCrap
|
---|
61 | # define _interlockedbittestandset64 _interlockedbittestandset64_StupidDDKVsCompilerCrap
|
---|
62 | # define _interlockedbittestandreset64 _interlockedbittestandreset64_StupidDDKVsCompilerCrap
|
---|
63 | # pragma warning(disable : 4163)
|
---|
64 | # include <ntddk.h>
|
---|
65 | # pragma warning(default : 4163)
|
---|
66 | # undef _InterlockedExchange
|
---|
67 | # undef _InterlockedExchangeAdd
|
---|
68 | # undef _InterlockedCompareExchange
|
---|
69 | # undef _InterlockedAddLargeStatistic
|
---|
70 | # undef _interlockedbittestandset
|
---|
71 | # undef _interlockedbittestandreset
|
---|
72 | # undef _interlockedbittestandset64
|
---|
73 | # undef _interlockedbittestandreset64
|
---|
74 | # else
|
---|
75 | # include <ntddk.h>
|
---|
76 | # endif
|
---|
77 | # include <memory.h>
|
---|
78 | # define memcmp(a,b,c) mymemcmp(a,b,c)
|
---|
79 | int VBOXCALL mymemcmp(const void *, const void *, size_t);
|
---|
80 | RT_C_DECLS_END
|
---|
81 |
|
---|
82 | #elif defined(RT_OS_LINUX)
|
---|
83 | # ifndef AUTOCONF_INCLUDED
|
---|
84 | # include <linux/autoconf.h>
|
---|
85 | # endif
|
---|
86 | # include <linux/version.h>
|
---|
87 | # if defined(CONFIG_MODVERSIONS) && !defined(MODVERSIONS)
|
---|
88 | # define MODVERSIONS
|
---|
89 | # if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 71)
|
---|
90 | # include <linux/modversions.h>
|
---|
91 | # endif
|
---|
92 | # endif
|
---|
93 | # if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 0)
|
---|
94 | # undef ALIGN
|
---|
95 | # endif
|
---|
96 | # ifndef KBUILD_STR
|
---|
97 | # if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 16)
|
---|
98 | # define KBUILD_STR(s) s
|
---|
99 | # else
|
---|
100 | # define KBUILD_STR(s) #s
|
---|
101 | # endif
|
---|
102 | # endif
|
---|
103 | # include <linux/string.h>
|
---|
104 | # include <linux/spinlock.h>
|
---|
105 | # include <linux/slab.h>
|
---|
106 | # if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)
|
---|
107 | # include <linux/semaphore.h>
|
---|
108 | # else /* older kernels */
|
---|
109 | # include <asm/semaphore.h>
|
---|
110 | # endif /* older kernels */
|
---|
111 | # include <linux/timer.h>
|
---|
112 |
|
---|
113 | # if 0
|
---|
114 | # include <linux/hrtimer.h>
|
---|
115 | # define VBOX_HRTIMER
|
---|
116 | # endif
|
---|
117 |
|
---|
118 | #elif defined(RT_OS_DARWIN)
|
---|
119 | # include <libkern/libkern.h>
|
---|
120 | # include <iprt/string.h>
|
---|
121 |
|
---|
122 | #elif defined(RT_OS_OS2)
|
---|
123 |
|
---|
124 | #elif defined(RT_OS_FREEBSD)
|
---|
125 | # define memset libkern_memset /** @todo these are just hacks to get it compiling, check out later. */
|
---|
126 | # define memcmp libkern_memcmp
|
---|
127 | # define strchr libkern_strchr
|
---|
128 | # define strrchr libkern_strrchr
|
---|
129 | # define ffsl libkern_ffsl
|
---|
130 | # define fls libkern_fls
|
---|
131 | # define flsl libkern_flsl
|
---|
132 | # include <sys/libkern.h>
|
---|
133 | # undef memset
|
---|
134 | # undef memcmp
|
---|
135 | # undef strchr
|
---|
136 | # undef strrchr
|
---|
137 | # undef ffs
|
---|
138 | # undef ffsl
|
---|
139 | # undef fls
|
---|
140 | # undef flsl
|
---|
141 | # include <iprt/string.h>
|
---|
142 |
|
---|
143 | #elif defined(RT_OS_SOLARIS)
|
---|
144 | # include <sys/cmn_err.h>
|
---|
145 | # include <iprt/string.h>
|
---|
146 |
|
---|
147 | #else
|
---|
148 | # error "unsupported OS."
|
---|
149 | #endif
|
---|
150 |
|
---|
151 | #include "SUPDrvIOC.h"
|
---|
152 | #include "SUPDrvIDC.h"
|
---|
153 |
|
---|
154 |
|
---|
155 |
|
---|
156 | /*******************************************************************************
|
---|
157 | * Defined Constants And Macros *
|
---|
158 | *******************************************************************************/
|
---|
159 | /*
|
---|
160 | * Hardcoded cookies.
|
---|
161 | */
|
---|
162 | #define BIRD 0x64726962 /* 'bird' */
|
---|
163 | #define BIRD_INV 0x62697264 /* 'drib' */
|
---|
164 |
|
---|
165 |
|
---|
166 | #ifdef RT_OS_WINDOWS
|
---|
167 | /** Use a normal mutex for the loader so we remain at the same IRQL after
|
---|
168 | * taking it.
|
---|
169 | * @todo fix the mutex implementation on linux and make this the default. */
|
---|
170 | # define SUPDRV_USE_MUTEX_FOR_LDR
|
---|
171 |
|
---|
172 | /** Use a normal mutex for the GIP so we remain at the same IRQL after
|
---|
173 | * taking it.
|
---|
174 | * @todo fix the mutex implementation on linux and make this the default. */
|
---|
175 | # define SUPDRV_USE_MUTEX_FOR_GIP
|
---|
176 | #endif
|
---|
177 |
|
---|
178 |
|
---|
179 | /**
|
---|
180 | * OS debug print macro.
|
---|
181 | */
|
---|
182 | #define OSDBGPRINT(a) SUPR0Printf a
|
---|
183 |
|
---|
184 |
|
---|
185 | /** @name Context values for the per-session handle tables.
|
---|
186 | * The context value is used to distiguish between the different kinds of
|
---|
187 | * handles, making the handle table API do all the work.
|
---|
188 | * @{ */
|
---|
189 | /** Handle context value for single release event handles. */
|
---|
190 | #define SUPDRV_HANDLE_CTX_EVENT ((void *)(uintptr_t)(SUPDRVOBJTYPE_SEM_EVENT))
|
---|
191 | /** Handle context value for multiple release event handles. */
|
---|
192 | #define SUPDRV_HANDLE_CTX_EVENT_MULTI ((void *)(uintptr_t)(SUPDRVOBJTYPE_SEM_EVENT_MULTI))
|
---|
193 | /** @} */
|
---|
194 |
|
---|
195 |
|
---|
196 | /**
|
---|
197 | * Validates a session pointer.
|
---|
198 | *
|
---|
199 | * @returns true/false accordingly.
|
---|
200 | * @param pSession The session.
|
---|
201 | */
|
---|
202 | #define SUP_IS_SESSION_VALID(pSession) \
|
---|
203 | ( VALID_PTR(pSession) \
|
---|
204 | && pSession->u32Cookie == BIRD_INV)
|
---|
205 |
|
---|
206 |
|
---|
207 | /*******************************************************************************
|
---|
208 | * Structures and Typedefs *
|
---|
209 | *******************************************************************************/
|
---|
210 | /** Pointer to the device extension. */
|
---|
211 | typedef struct SUPDRVDEVEXT *PSUPDRVDEVEXT;
|
---|
212 |
|
---|
213 |
|
---|
214 | /**
|
---|
215 | * Memory reference types.
|
---|
216 | */
|
---|
217 | typedef enum
|
---|
218 | {
|
---|
219 | /** Unused entry */
|
---|
220 | MEMREF_TYPE_UNUSED = 0,
|
---|
221 | /** Locked memory (r3 mapping only). */
|
---|
222 | MEMREF_TYPE_LOCKED,
|
---|
223 | /** Continous memory block (r3 and r0 mapping). */
|
---|
224 | MEMREF_TYPE_CONT,
|
---|
225 | /** Low memory block (r3 and r0 mapping). */
|
---|
226 | MEMREF_TYPE_LOW,
|
---|
227 | /** Memory block (r3 and r0 mapping). */
|
---|
228 | MEMREF_TYPE_MEM,
|
---|
229 | /** Locked memory (r3 mapping only) allocated by the support driver. */
|
---|
230 | MEMREF_TYPE_PAGE,
|
---|
231 | /** Blow the type up to 32-bit and mark the end. */
|
---|
232 | MEMREG_TYPE_32BIT_HACK = 0x7fffffff
|
---|
233 | } SUPDRVMEMREFTYPE, *PSUPDRVMEMREFTYPE;
|
---|
234 |
|
---|
235 |
|
---|
236 | /**
|
---|
237 | * Structure used for tracking memory a session
|
---|
238 | * references in one way or another.
|
---|
239 | */
|
---|
240 | typedef struct SUPDRVMEMREF
|
---|
241 | {
|
---|
242 | /** The memory object handle. */
|
---|
243 | RTR0MEMOBJ MemObj;
|
---|
244 | /** The ring-3 mapping memory object handle. */
|
---|
245 | RTR0MEMOBJ MapObjR3;
|
---|
246 | /** Type of memory. */
|
---|
247 | SUPDRVMEMREFTYPE eType;
|
---|
248 | } SUPDRVMEMREF, *PSUPDRVMEMREF;
|
---|
249 |
|
---|
250 |
|
---|
251 | /**
|
---|
252 | * Bundle of locked memory ranges.
|
---|
253 | */
|
---|
254 | typedef struct SUPDRVBUNDLE
|
---|
255 | {
|
---|
256 | /** Pointer to the next bundle. */
|
---|
257 | struct SUPDRVBUNDLE * volatile pNext;
|
---|
258 | /** Referenced memory. */
|
---|
259 | SUPDRVMEMREF aMem[64];
|
---|
260 | /** Number of entries used. */
|
---|
261 | uint32_t volatile cUsed;
|
---|
262 | } SUPDRVBUNDLE, *PSUPDRVBUNDLE;
|
---|
263 |
|
---|
264 |
|
---|
265 | /**
|
---|
266 | * Loaded image.
|
---|
267 | */
|
---|
268 | typedef struct SUPDRVLDRIMAGE
|
---|
269 | {
|
---|
270 | /** Next in chain. */
|
---|
271 | struct SUPDRVLDRIMAGE * volatile pNext;
|
---|
272 | /** Pointer to the image. */
|
---|
273 | void *pvImage;
|
---|
274 | /** Pointer to the allocated image buffer.
|
---|
275 | * pvImage is 32-byte aligned or it may governed by the native loader (this
|
---|
276 | * member is NULL then). */
|
---|
277 | void *pvImageAlloc;
|
---|
278 | /** Size of the image including the tables. This is mainly for verification
|
---|
279 | * of the load request. */
|
---|
280 | uint32_t cbImageWithTabs;
|
---|
281 | /** Size of the image. */
|
---|
282 | uint32_t cbImageBits;
|
---|
283 | /** The number of entries in the symbol table. */
|
---|
284 | uint32_t cSymbols;
|
---|
285 | /** Pointer to the symbol table. */
|
---|
286 | PSUPLDRSYM paSymbols;
|
---|
287 | /** The offset of the string table. */
|
---|
288 | char *pachStrTab;
|
---|
289 | /** Size of the string table. */
|
---|
290 | uint32_t cbStrTab;
|
---|
291 | /** Pointer to the optional module initialization callback. */
|
---|
292 | PFNR0MODULEINIT pfnModuleInit;
|
---|
293 | /** Pointer to the optional module termination callback. */
|
---|
294 | PFNR0MODULETERM pfnModuleTerm;
|
---|
295 | /** Service request handler. This is NULL for non-service modules. */
|
---|
296 | PFNSUPR0SERVICEREQHANDLER pfnServiceReqHandler;
|
---|
297 | /** The ldr image state. (IOCtl code of last opration.) */
|
---|
298 | uint32_t uState;
|
---|
299 | /** Usage count. */
|
---|
300 | uint32_t volatile cUsage;
|
---|
301 | #ifdef RT_OS_WINDOWS
|
---|
302 | /** The section object for the loaded image (fNative=true). */
|
---|
303 | void *pvNtSectionObj;
|
---|
304 | /** Lock object. */
|
---|
305 | RTR0MEMOBJ hMemLock;
|
---|
306 | #endif
|
---|
307 | /** Whether it's loaded by the native loader or not. */
|
---|
308 | bool fNative;
|
---|
309 | /** Image name. */
|
---|
310 | char szName[32];
|
---|
311 | } SUPDRVLDRIMAGE, *PSUPDRVLDRIMAGE;
|
---|
312 |
|
---|
313 |
|
---|
314 | /** Image usage record. */
|
---|
315 | typedef struct SUPDRVLDRUSAGE
|
---|
316 | {
|
---|
317 | /** Next in chain. */
|
---|
318 | struct SUPDRVLDRUSAGE * volatile pNext;
|
---|
319 | /** The image. */
|
---|
320 | PSUPDRVLDRIMAGE pImage;
|
---|
321 | /** Load count. */
|
---|
322 | uint32_t volatile cUsage;
|
---|
323 | } SUPDRVLDRUSAGE, *PSUPDRVLDRUSAGE;
|
---|
324 |
|
---|
325 |
|
---|
326 | /**
|
---|
327 | * Component factory registration record.
|
---|
328 | */
|
---|
329 | typedef struct SUPDRVFACTORYREG
|
---|
330 | {
|
---|
331 | /** Pointer to the next registration. */
|
---|
332 | struct SUPDRVFACTORYREG *pNext;
|
---|
333 | /** Pointer to the registered factory. */
|
---|
334 | PCSUPDRVFACTORY pFactory;
|
---|
335 | /** The session owning the factory.
|
---|
336 | * Used for deregistration and session cleanup. */
|
---|
337 | PSUPDRVSESSION pSession;
|
---|
338 | /** Length of the name. */
|
---|
339 | size_t cchName;
|
---|
340 | } SUPDRVFACTORYREG;
|
---|
341 | /** Pointer to a component factory registration record. */
|
---|
342 | typedef SUPDRVFACTORYREG *PSUPDRVFACTORYREG;
|
---|
343 | /** Pointer to a const component factory registration record. */
|
---|
344 | typedef SUPDRVFACTORYREG const *PCSUPDRVFACTORYREG;
|
---|
345 |
|
---|
346 |
|
---|
347 | /**
|
---|
348 | * Registered object.
|
---|
349 | * This takes care of reference counting and tracking data for access checks.
|
---|
350 | */
|
---|
351 | typedef struct SUPDRVOBJ
|
---|
352 | {
|
---|
353 | /** Magic value (SUPDRVOBJ_MAGIC). */
|
---|
354 | uint32_t u32Magic;
|
---|
355 | /** The object type. */
|
---|
356 | SUPDRVOBJTYPE enmType;
|
---|
357 | /** Pointer to the next in the global list. */
|
---|
358 | struct SUPDRVOBJ * volatile pNext;
|
---|
359 | /** Pointer to the object destructor.
|
---|
360 | * This may be set to NULL if the image containing the destructor get unloaded. */
|
---|
361 | PFNSUPDRVDESTRUCTOR pfnDestructor;
|
---|
362 | /** User argument 1. */
|
---|
363 | void *pvUser1;
|
---|
364 | /** User argument 2. */
|
---|
365 | void *pvUser2;
|
---|
366 | /** The total sum of all per-session usage. */
|
---|
367 | uint32_t volatile cUsage;
|
---|
368 | /** The creator user id. */
|
---|
369 | RTUID CreatorUid;
|
---|
370 | /** The creator group id. */
|
---|
371 | RTGID CreatorGid;
|
---|
372 | /** The creator process id. */
|
---|
373 | RTPROCESS CreatorProcess;
|
---|
374 | } SUPDRVOBJ, *PSUPDRVOBJ;
|
---|
375 |
|
---|
376 | /** Magic number for SUPDRVOBJ::u32Magic. (Dame Agatha Mary Clarissa Christie). */
|
---|
377 | #define SUPDRVOBJ_MAGIC 0x18900915
|
---|
378 | /** Dead number magic for SUPDRVOBJ::u32Magic. */
|
---|
379 | #define SUPDRVOBJ_MAGIC_DEAD 0x19760112
|
---|
380 |
|
---|
381 | /**
|
---|
382 | * The per-session object usage record.
|
---|
383 | */
|
---|
384 | typedef struct SUPDRVUSAGE
|
---|
385 | {
|
---|
386 | /** Pointer to the next in the list. */
|
---|
387 | struct SUPDRVUSAGE * volatile pNext;
|
---|
388 | /** Pointer to the object we're recording usage for. */
|
---|
389 | PSUPDRVOBJ pObj;
|
---|
390 | /** The usage count. */
|
---|
391 | uint32_t volatile cUsage;
|
---|
392 | } SUPDRVUSAGE, *PSUPDRVUSAGE;
|
---|
393 |
|
---|
394 |
|
---|
395 | /**
|
---|
396 | * Per session data.
|
---|
397 | * This is mainly for memory tracking.
|
---|
398 | */
|
---|
399 | typedef struct SUPDRVSESSION
|
---|
400 | {
|
---|
401 | /** Pointer to the device extension. */
|
---|
402 | PSUPDRVDEVEXT pDevExt;
|
---|
403 | /** Session Cookie. */
|
---|
404 | uint32_t u32Cookie;
|
---|
405 |
|
---|
406 | /** The VM associated with the session. */
|
---|
407 | PVM pVM;
|
---|
408 | /** Handle table for IPRT semaphore wrapper APIs.
|
---|
409 | * Programmable from R0 and R3. */
|
---|
410 | RTHANDLETABLE hHandleTable;
|
---|
411 | /** Load usage records. (protected by SUPDRVDEVEXT::mtxLdr) */
|
---|
412 | PSUPDRVLDRUSAGE volatile pLdrUsage;
|
---|
413 |
|
---|
414 | /** Spinlock protecting the bundles and the GIP members. */
|
---|
415 | RTSPINLOCK Spinlock;
|
---|
416 | /** The ring-3 mapping of the GIP (readonly). */
|
---|
417 | RTR0MEMOBJ GipMapObjR3;
|
---|
418 | /** Set if the session is using the GIP. */
|
---|
419 | uint32_t fGipReferenced;
|
---|
420 | /** Bundle of locked memory objects. */
|
---|
421 | SUPDRVBUNDLE Bundle;
|
---|
422 | /** List of generic usage records. (protected by SUPDRVDEVEXT::SpinLock) */
|
---|
423 | PSUPDRVUSAGE volatile pUsage;
|
---|
424 |
|
---|
425 | /** The user id of the session. (Set by the OS part.) */
|
---|
426 | RTUID Uid;
|
---|
427 | /** The group id of the session. (Set by the OS part.) */
|
---|
428 | RTGID Gid;
|
---|
429 | /** The process (id) of the session. */
|
---|
430 | RTPROCESS Process;
|
---|
431 | /** Which process this session is associated with.
|
---|
432 | * This is NIL_RTR0PROCESS for kernel sessions and valid for user ones. */
|
---|
433 | RTR0PROCESS R0Process;
|
---|
434 | #ifndef SUPDRV_AGNOSTIC
|
---|
435 | # if defined(RT_OS_DARWIN)
|
---|
436 | /** Pointer to the associated org_virtualbox_SupDrvClient object. */
|
---|
437 | void *pvSupDrvClient;
|
---|
438 | /** Whether this session has been opened or not. */
|
---|
439 | bool fOpened;
|
---|
440 | # endif
|
---|
441 | # if defined(RT_OS_OS2)
|
---|
442 | /** The system file number of this session. */
|
---|
443 | uint16_t sfn;
|
---|
444 | uint16_t Alignment; /**< Alignment */
|
---|
445 | # endif
|
---|
446 | # if defined(RT_OS_DARWIN) || defined(RT_OS_OS2) || defined(RT_OS_SOLARIS)
|
---|
447 | /** Pointer to the next session with the same hash. */
|
---|
448 | PSUPDRVSESSION pNextHash;
|
---|
449 | # endif
|
---|
450 | #endif /* !SUPDRV_AGNOSTIC */
|
---|
451 | } SUPDRVSESSION;
|
---|
452 |
|
---|
453 |
|
---|
454 | /**
|
---|
455 | * Device extension.
|
---|
456 | */
|
---|
457 | typedef struct SUPDRVDEVEXT
|
---|
458 | {
|
---|
459 | /** Spinlock to serialize the initialization, usage counting and objects. */
|
---|
460 | RTSPINLOCK Spinlock;
|
---|
461 |
|
---|
462 | /** List of registered objects. Protected by the spinlock. */
|
---|
463 | PSUPDRVOBJ volatile pObjs;
|
---|
464 | /** List of free object usage records. */
|
---|
465 | PSUPDRVUSAGE volatile pUsageFree;
|
---|
466 |
|
---|
467 | /** Global cookie. */
|
---|
468 | uint32_t u32Cookie;
|
---|
469 | /** The actual size of SUPDRVSESSION. (SUPDRV_AGNOSTIC) */
|
---|
470 | uint32_t cbSession;
|
---|
471 |
|
---|
472 | /** Loader mutex.
|
---|
473 | * This protects pvVMMR0, pvVMMR0Entry, pImages and SUPDRVSESSION::pLdrUsage. */
|
---|
474 | #ifdef SUPDRV_USE_MUTEX_FOR_LDR
|
---|
475 | RTSEMMUTEX mtxLdr;
|
---|
476 | #else
|
---|
477 | RTSEMFASTMUTEX mtxLdr;
|
---|
478 | #endif
|
---|
479 |
|
---|
480 | /** VMM Module 'handle'.
|
---|
481 | * 0 if the code VMM isn't loaded and Idt are nops. */
|
---|
482 | void * volatile pvVMMR0;
|
---|
483 | /** VMMR0EntryInt() pointer. */
|
---|
484 | DECLR0CALLBACKMEMBER(int, pfnVMMR0EntryInt, (PVM pVM, unsigned uOperation, void *pvArg));
|
---|
485 | /** VMMR0EntryFast() pointer. */
|
---|
486 | DECLR0CALLBACKMEMBER(void, pfnVMMR0EntryFast, (PVM pVM, VMCPUID idCpu, unsigned uOperation));
|
---|
487 | /** VMMR0EntryEx() pointer. */
|
---|
488 | DECLR0CALLBACKMEMBER(int, pfnVMMR0EntryEx, (PVM pVM, VMCPUID idCpu, unsigned uOperation, PSUPVMMR0REQHDR pReq, uint64_t u64Arg, PSUPDRVSESSION pSession));
|
---|
489 |
|
---|
490 | /** Linked list of loaded code. */
|
---|
491 | PSUPDRVLDRIMAGE volatile pLdrImages;
|
---|
492 |
|
---|
493 | /** GIP mutex.
|
---|
494 | * Any changes to any of the GIP members requires ownership of this mutex,
|
---|
495 | * except on driver init and termination. */
|
---|
496 | #ifdef SUPDRV_USE_MUTEX_FOR_GIP
|
---|
497 | RTSEMMUTEX mtxGip;
|
---|
498 | #else
|
---|
499 | RTSEMFASTMUTEX mtxGip;
|
---|
500 | #endif
|
---|
501 | /** Pointer to the Global Info Page (GIP). */
|
---|
502 | PSUPGLOBALINFOPAGE pGip;
|
---|
503 | /** The physical address of the GIP. */
|
---|
504 | RTHCPHYS HCPhysGip;
|
---|
505 | /** Number of processes using the GIP.
|
---|
506 | * (The updates are suspend while cGipUsers is 0.)*/
|
---|
507 | uint32_t volatile cGipUsers;
|
---|
508 | /** The ring-0 memory object handle for the GIP page. */
|
---|
509 | RTR0MEMOBJ GipMemObj;
|
---|
510 | /** The GIP timer handle. */
|
---|
511 | PRTTIMER pGipTimer;
|
---|
512 | /** If non-zero we've successfully called RTTimerRequestSystemGranularity(). */
|
---|
513 | uint32_t u32SystemTimerGranularityGrant;
|
---|
514 | /** The CPU id of the GIP master.
|
---|
515 | * This CPU is responsible for the updating the common GIP data. */
|
---|
516 | RTCPUID volatile idGipMaster;
|
---|
517 |
|
---|
518 | /** Component factory mutex.
|
---|
519 | * This protects pComponentFactoryHead and component factory querying. */
|
---|
520 | RTSEMFASTMUTEX mtxComponentFactory;
|
---|
521 | /** The head of the list of registered component factories. */
|
---|
522 | PSUPDRVFACTORYREG pComponentFactoryHead;
|
---|
523 |
|
---|
524 | #ifndef SUPDRV_AGNOSTIC
|
---|
525 | # ifdef RT_OS_WINDOWS
|
---|
526 | /* Callback object returned by ExCreateCallback. */
|
---|
527 | PCALLBACK_OBJECT pObjPowerCallback;
|
---|
528 | /* Callback handle returned by ExRegisterCallback. */
|
---|
529 | PVOID hPowerCallback;
|
---|
530 | # endif
|
---|
531 | #endif
|
---|
532 | } SUPDRVDEVEXT;
|
---|
533 |
|
---|
534 |
|
---|
535 | RT_C_DECLS_BEGIN
|
---|
536 |
|
---|
537 | /*******************************************************************************
|
---|
538 | * OS Specific Functions *
|
---|
539 | *******************************************************************************/
|
---|
540 | void VBOXCALL supdrvOSObjInitCreator(PSUPDRVOBJ pObj, PSUPDRVSESSION pSession);
|
---|
541 | bool VBOXCALL supdrvOSObjCanAccess(PSUPDRVOBJ pObj, PSUPDRVSESSION pSession, const char *pszObjName, int *prc);
|
---|
542 | bool VBOXCALL supdrvOSGetForcedAsyncTscMode(PSUPDRVDEVEXT pDevExt);
|
---|
543 | int VBOXCALL supdrvOSEnableVTx(bool fEnabled);
|
---|
544 |
|
---|
545 | /**
|
---|
546 | * Try open the image using the native loader.
|
---|
547 | *
|
---|
548 | * @returns IPRT status code.
|
---|
549 | * @retval VERR_NOT_SUPPORTED if native loading isn't supported.
|
---|
550 | *
|
---|
551 | * @param pDevExt The device globals.
|
---|
552 | * @param pImage The image handle. pvImage should be set on
|
---|
553 | * success, pvImageAlloc can also be set if
|
---|
554 | * appropriate.
|
---|
555 | * @param pszFilename The file name - UTF-8, may containg UNIX
|
---|
556 | * slashes on non-UNIX systems.
|
---|
557 | */
|
---|
558 | int VBOXCALL supdrvOSLdrOpen(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, const char *pszFilename);
|
---|
559 |
|
---|
560 | /**
|
---|
561 | * Validates an entry point address.
|
---|
562 | *
|
---|
563 | * Called before supdrvOSLdrLoad.
|
---|
564 | *
|
---|
565 | * @returns IPRT status code.
|
---|
566 | * @param pDevExt The device globals.
|
---|
567 | * @param pImage The image data (still in the open state).
|
---|
568 | * @param pv The address within the image.
|
---|
569 | * @param pbImageBits The image bits as loaded by ring-3.
|
---|
570 | */
|
---|
571 | int VBOXCALL supdrvOSLdrValidatePointer(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage,
|
---|
572 | void *pv, const uint8_t *pbImageBits);
|
---|
573 |
|
---|
574 | /**
|
---|
575 | * Load the image.
|
---|
576 | *
|
---|
577 | * @returns IPRT status code.
|
---|
578 | * @param pDevExt The device globals.
|
---|
579 | * @param pImage The image data (up to date except for some
|
---|
580 | * entry point pointers).
|
---|
581 | * @param pbImageBits The image bits as loaded by ring-3.
|
---|
582 | */
|
---|
583 | int VBOXCALL supdrvOSLdrLoad(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, const uint8_t *pbImageBits);
|
---|
584 |
|
---|
585 |
|
---|
586 | /**
|
---|
587 | * Unload the image.
|
---|
588 | *
|
---|
589 | * @param pDevExt The device globals.
|
---|
590 | * @param pImage The image data (mostly still valid).
|
---|
591 | */
|
---|
592 | void VBOXCALL supdrvOSLdrUnload(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage);
|
---|
593 |
|
---|
594 |
|
---|
595 | /*******************************************************************************
|
---|
596 | * Shared Functions *
|
---|
597 | *******************************************************************************/
|
---|
598 | /* SUPDrv.c */
|
---|
599 | int VBOXCALL supdrvIOCtl(uintptr_t uIOCtl, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPREQHDR pReqHdr);
|
---|
600 | int VBOXCALL supdrvIOCtlFast(uintptr_t uIOCtl, VMCPUID idCpu, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession);
|
---|
601 | int VBOXCALL supdrvIDC(uintptr_t uIOCtl, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPDRVIDCREQHDR pReqHdr);
|
---|
602 | int VBOXCALL supdrvInitDevExt(PSUPDRVDEVEXT pDevExt, size_t cbSession);
|
---|
603 | void VBOXCALL supdrvDeleteDevExt(PSUPDRVDEVEXT pDevExt);
|
---|
604 | int VBOXCALL supdrvCreateSession(PSUPDRVDEVEXT pDevExt, bool fUser, PSUPDRVSESSION *ppSession);
|
---|
605 | void VBOXCALL supdrvCloseSession(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession);
|
---|
606 | void VBOXCALL supdrvCleanupSession(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession);
|
---|
607 |
|
---|
608 | RT_C_DECLS_END
|
---|
609 |
|
---|
610 | #endif
|
---|
611 |
|
---|