VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/Support/SUPDrvInternal.h@ 25331

Last change on this file since 25331 was 25308, checked in by vboxsync, 15 years ago

SUPDrv: Lock down the natively loaded image.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 25.0 KB
Line 
1/* $Revision: 25308 $ */
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# include <linux/autoconf.h>
84# include <linux/version.h>
85# if defined(CONFIG_MODVERSIONS) && !defined(MODVERSIONS)
86# define MODVERSIONS
87# if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 71)
88# include <linux/modversions.h>
89# endif
90# endif
91# if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 0)
92# undef ALIGN
93# endif
94# ifndef KBUILD_STR
95# if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 16)
96# define KBUILD_STR(s) s
97# else
98# define KBUILD_STR(s) #s
99# endif
100# endif
101# include <linux/string.h>
102# include <linux/spinlock.h>
103# include <linux/slab.h>
104# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)
105# include <linux/semaphore.h>
106# else /* older kernels */
107# include <asm/semaphore.h>
108# endif /* older kernels */
109# include <linux/timer.h>
110
111# if 0
112# include <linux/hrtimer.h>
113# define VBOX_HRTIMER
114# endif
115
116#elif defined(RT_OS_DARWIN)
117# include <libkern/libkern.h>
118# include <iprt/string.h>
119
120#elif defined(RT_OS_OS2)
121
122#elif defined(RT_OS_FREEBSD)
123# define memset libkern_memset /** @todo these are just hacks to get it compiling, check out later. */
124# define memcmp libkern_memcmp
125# define strchr libkern_strchr
126# define strrchr libkern_strrchr
127# define ffsl libkern_ffsl
128# define fls libkern_fls
129# define flsl libkern_flsl
130# include <sys/libkern.h>
131# undef memset
132# undef memcmp
133# undef strchr
134# undef strrchr
135# undef ffs
136# undef ffsl
137# undef fls
138# undef flsl
139# include <iprt/string.h>
140
141#elif defined(RT_OS_SOLARIS)
142# include <sys/cmn_err.h>
143# include <iprt/string.h>
144
145#else
146# error "unsupported OS."
147#endif
148
149#include "SUPDrvIOC.h"
150#include "SUPDrvIDC.h"
151
152
153
154/*******************************************************************************
155* Defined Constants And Macros *
156*******************************************************************************/
157/*
158 * Hardcoded cookies.
159 */
160#define BIRD 0x64726962 /* 'bird' */
161#define BIRD_INV 0x62697264 /* 'drib' */
162
163
164/*
165 * Win32
166 */
167#if defined(RT_OS_WINDOWS)
168
169/* debug printf */
170# define OSDBGPRINT(a) DbgPrint a
171
172/** Maximum number of bytes we try to lock down in one go.
173 * This is supposed to have a limit right below 256MB, but this appears
174 * to actually be much lower. The values here have been determined experimentally.
175 */
176# ifdef RT_ARCH_X86
177# define MAX_LOCK_MEM_SIZE (32*1024*1024) /* 32mb */
178# endif
179# ifdef RT_ARCH_AMD64
180# define MAX_LOCK_MEM_SIZE (24*1024*1024) /* 24mb */
181# endif
182
183/** Use a normal mutex for the loader so we remain at the same IRQL after
184 * taking it.
185 * @todo fix the mutex implementation on linux and make this the default. */
186# define SUPDRV_USE_MUTEX_FOR_LDR
187
188/*
189 * Linux
190 */
191#elif defined(RT_OS_LINUX)
192
193/* check kernel version */
194# ifndef SUPDRV_AGNOSTIC
195# if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
196# error Unsupported kernel version!
197# endif
198# endif
199
200RT_C_DECLS_BEGIN
201int linux_dprintf(const char *format, ...);
202RT_C_DECLS_END
203
204/* debug printf */
205# define OSDBGPRINT(a) printk a
206
207
208/*
209 * Darwin
210 */
211#elif defined(RT_OS_DARWIN)
212
213/* debug printf */
214# define OSDBGPRINT(a) printf a
215
216
217/*
218 * OS/2
219 */
220#elif defined(RT_OS_OS2)
221
222/* No log API in OS/2 only COM port. */
223# define OSDBGPRINT(a) SUPR0Printf a
224
225
226/*
227 * FreeBSD
228 */
229#elif defined(RT_OS_FREEBSD)
230
231/* debug printf */
232# define OSDBGPRINT(a) printf a
233
234
235/*
236 * Solaris
237 */
238#elif defined(RT_OS_SOLARIS)
239# define OSDBGPRINT(a) SUPR0Printf a
240
241
242#else
243/** @todo other os'es */
244# error "OS interface defines is not done for this OS!"
245#endif
246
247
248/* dprintf */
249#if (defined(DEBUG) && !defined(NO_LOGGING))
250# ifdef LOG_TO_COM
251# include <VBox/log.h>
252# define dprintf(a) RTLogComPrintf a
253# else
254# define dprintf(a) OSDBGPRINT(a)
255# endif
256#else
257# define dprintf(a) do {} while (0)
258#endif
259
260/* dprintf2 - extended logging. */
261#if defined(RT_OS_DARWIN) || defined(RT_OS_OS2) || defined(RT_OS_FREEBSD)
262# define dprintf2 dprintf
263#else
264# define dprintf2(a) do { } while (0)
265#endif
266
267
268/** @def RT_WITH_W64_UNWIND_HACK
269 * Changes a function name into the wrapped version if we've
270 * enabled the unwind hack.
271 *
272 * The unwind hack is for making the NT unwind procedures skip
273 * our dynamically loaded code when they try to walk the call
274 * stack. Needless to say, they kind of don't expect what
275 * we're doing here and get kind of confused and may BSOD. */
276#ifdef DOXYGEN_RUNNING
277# define RT_WITH_W64_UNWIND_HACK
278#endif
279/** @def UNWIND_WRAP
280 * If RT_WITH_W64_UNWIND_HACK is defined, the name will be prefixed with
281 * 'supdrvNtWrap'.
282 * @param Name The function to wrapper. */
283#ifdef RT_WITH_W64_UNWIND_HACK
284# define UNWIND_WRAP(Name) supdrvNtWrap##Name
285#else
286# define UNWIND_WRAP(Name) Name
287#endif
288
289
290/*
291 * Error codes.
292 */
293/** @todo retire the SUPDRV_ERR_* stuff, we ship err.h now. */
294/** Invalid parameter. */
295#define SUPDRV_ERR_GENERAL_FAILURE (-1)
296/** Invalid parameter. */
297#define SUPDRV_ERR_INVALID_PARAM (-2)
298/** Invalid magic or cookie. */
299#define SUPDRV_ERR_INVALID_MAGIC (-3)
300/** Invalid loader handle. */
301#define SUPDRV_ERR_INVALID_HANDLE (-4)
302/** Failed to lock the address range. */
303#define SUPDRV_ERR_LOCK_FAILED (-5)
304/** Invalid memory pointer. */
305#define SUPDRV_ERR_INVALID_POINTER (-6)
306/** Failed to patch the IDT. */
307#define SUPDRV_ERR_IDT_FAILED (-7)
308/** Memory allocation failed. */
309#define SUPDRV_ERR_NO_MEMORY (-8)
310/** Already loaded. */
311#define SUPDRV_ERR_ALREADY_LOADED (-9)
312/** Permission denied. */
313#define SUPDRV_ERR_PERMISSION_DENIED (-10)
314/** Version mismatch. */
315#define SUPDRV_ERR_VERSION_MISMATCH (-11)
316
317
318/** @name Context values for the per-session handle tables.
319 * The context value is used to distiguish between the different kinds of
320 * handles, making the handle table API do all the work.
321 * @{ */
322/** Handle context value for single release event handles. */
323#define SUPDRV_HANDLE_CTX_EVENT ((void *)(uintptr_t)(SUPDRVOBJTYPE_SEM_EVENT))
324/** Handle context value for multiple release event handles. */
325#define SUPDRV_HANDLE_CTX_EVENT_MULTI ((void *)(uintptr_t)(SUPDRVOBJTYPE_SEM_EVENT_MULTI))
326/** @} */
327
328
329/**
330 * Validates a session pointer.
331 *
332 * @returns true/false accordingly.
333 * @param pSession The session.
334 */
335#define SUP_IS_SESSION_VALID(pSession) \
336 ( VALID_PTR(pSession) \
337 && pSession->u32Cookie == BIRD_INV)
338
339
340/*******************************************************************************
341* Structures and Typedefs *
342*******************************************************************************/
343/** Pointer to the device extension. */
344typedef struct SUPDRVDEVEXT *PSUPDRVDEVEXT;
345
346
347/**
348 * Memory reference types.
349 */
350typedef enum
351{
352 /** Unused entry */
353 MEMREF_TYPE_UNUSED = 0,
354 /** Locked memory (r3 mapping only). */
355 MEMREF_TYPE_LOCKED,
356 /** Continous memory block (r3 and r0 mapping). */
357 MEMREF_TYPE_CONT,
358 /** Low memory block (r3 and r0 mapping). */
359 MEMREF_TYPE_LOW,
360 /** Memory block (r3 and r0 mapping). */
361 MEMREF_TYPE_MEM,
362 /** Locked memory (r3 mapping only) allocated by the support driver. */
363 MEMREF_TYPE_PAGE,
364 /** Blow the type up to 32-bit and mark the end. */
365 MEMREG_TYPE_32BIT_HACK = 0x7fffffff
366} SUPDRVMEMREFTYPE, *PSUPDRVMEMREFTYPE;
367
368
369/**
370 * Structure used for tracking memory a session
371 * references in one way or another.
372 */
373typedef struct SUPDRVMEMREF
374{
375 /** The memory object handle. */
376 RTR0MEMOBJ MemObj;
377 /** The ring-3 mapping memory object handle. */
378 RTR0MEMOBJ MapObjR3;
379 /** Type of memory. */
380 SUPDRVMEMREFTYPE eType;
381} SUPDRVMEMREF, *PSUPDRVMEMREF;
382
383
384/**
385 * Bundle of locked memory ranges.
386 */
387typedef struct SUPDRVBUNDLE
388{
389 /** Pointer to the next bundle. */
390 struct SUPDRVBUNDLE * volatile pNext;
391 /** Referenced memory. */
392 SUPDRVMEMREF aMem[64];
393 /** Number of entries used. */
394 uint32_t volatile cUsed;
395} SUPDRVBUNDLE, *PSUPDRVBUNDLE;
396
397
398/**
399 * Loaded image.
400 */
401typedef struct SUPDRVLDRIMAGE
402{
403 /** Next in chain. */
404 struct SUPDRVLDRIMAGE * volatile pNext;
405 /** Pointer to the image. */
406 void *pvImage;
407 /** Pointer to the allocated image buffer.
408 * pvImage is 32-byte aligned or it may governed by the native loader (this
409 * member is NULL then). */
410 void *pvImageAlloc;
411 /** Size of the image including the tables. This is mainly for verification
412 * of the load request. */
413 uint32_t cbImageWithTabs;
414 /** Size of the image. */
415 uint32_t cbImageBits;
416 /** The number of entries in the symbol table. */
417 uint32_t cSymbols;
418 /** Pointer to the symbol table. */
419 PSUPLDRSYM paSymbols;
420 /** The offset of the string table. */
421 char *pachStrTab;
422 /** Size of the string table. */
423 uint32_t cbStrTab;
424 /** Pointer to the optional module initialization callback. */
425 PFNR0MODULEINIT pfnModuleInit;
426 /** Pointer to the optional module termination callback. */
427 PFNR0MODULETERM pfnModuleTerm;
428 /** Service request handler. This is NULL for non-service modules. */
429 PFNSUPR0SERVICEREQHANDLER pfnServiceReqHandler;
430 /** The ldr image state. (IOCtl code of last opration.) */
431 uint32_t uState;
432 /** Usage count. */
433 uint32_t volatile cUsage;
434#ifdef RT_OS_WINDOWS
435 /** The section object for the loaded image (fNative=true). */
436 void *pvNtSectionObj;
437 /** Lock object. */
438 RTR0MEMOBJ hMemLock;
439#endif
440 /** Whether it's loaded by the native loader or not. */
441 bool fNative;
442 /** Image name. */
443 char szName[32];
444} SUPDRVLDRIMAGE, *PSUPDRVLDRIMAGE;
445
446
447/** Image usage record. */
448typedef struct SUPDRVLDRUSAGE
449{
450 /** Next in chain. */
451 struct SUPDRVLDRUSAGE * volatile pNext;
452 /** The image. */
453 PSUPDRVLDRIMAGE pImage;
454 /** Load count. */
455 uint32_t volatile cUsage;
456} SUPDRVLDRUSAGE, *PSUPDRVLDRUSAGE;
457
458
459/**
460 * Component factory registration record.
461 */
462typedef struct SUPDRVFACTORYREG
463{
464 /** Pointer to the next registration. */
465 struct SUPDRVFACTORYREG *pNext;
466 /** Pointer to the registered factory. */
467 PCSUPDRVFACTORY pFactory;
468 /** The session owning the factory.
469 * Used for deregistration and session cleanup. */
470 PSUPDRVSESSION pSession;
471 /** Length of the name. */
472 size_t cchName;
473} SUPDRVFACTORYREG;
474/** Pointer to a component factory registration record. */
475typedef SUPDRVFACTORYREG *PSUPDRVFACTORYREG;
476/** Pointer to a const component factory registration record. */
477typedef SUPDRVFACTORYREG const *PCSUPDRVFACTORYREG;
478
479
480/**
481 * Registered object.
482 * This takes care of reference counting and tracking data for access checks.
483 */
484typedef struct SUPDRVOBJ
485{
486 /** Magic value (SUPDRVOBJ_MAGIC). */
487 uint32_t u32Magic;
488 /** The object type. */
489 SUPDRVOBJTYPE enmType;
490 /** Pointer to the next in the global list. */
491 struct SUPDRVOBJ * volatile pNext;
492 /** Pointer to the object destructor.
493 * This may be set to NULL if the image containing the destructor get unloaded. */
494 PFNSUPDRVDESTRUCTOR pfnDestructor;
495 /** User argument 1. */
496 void *pvUser1;
497 /** User argument 2. */
498 void *pvUser2;
499 /** The total sum of all per-session usage. */
500 uint32_t volatile cUsage;
501 /** The creator user id. */
502 RTUID CreatorUid;
503 /** The creator group id. */
504 RTGID CreatorGid;
505 /** The creator process id. */
506 RTPROCESS CreatorProcess;
507} SUPDRVOBJ, *PSUPDRVOBJ;
508
509/** Magic number for SUPDRVOBJ::u32Magic. (Dame Agatha Mary Clarissa Christie). */
510#define SUPDRVOBJ_MAGIC 0x18900915
511/** Dead number magic for SUPDRVOBJ::u32Magic. */
512#define SUPDRVOBJ_MAGIC_DEAD 0x19760112
513
514/**
515 * The per-session object usage record.
516 */
517typedef struct SUPDRVUSAGE
518{
519 /** Pointer to the next in the list. */
520 struct SUPDRVUSAGE * volatile pNext;
521 /** Pointer to the object we're recording usage for. */
522 PSUPDRVOBJ pObj;
523 /** The usage count. */
524 uint32_t volatile cUsage;
525} SUPDRVUSAGE, *PSUPDRVUSAGE;
526
527
528/**
529 * Per session data.
530 * This is mainly for memory tracking.
531 */
532typedef struct SUPDRVSESSION
533{
534 /** Pointer to the device extension. */
535 PSUPDRVDEVEXT pDevExt;
536 /** Session Cookie. */
537 uint32_t u32Cookie;
538
539 /** The VM associated with the session. */
540 PVM pVM;
541 /** Handle table for IPRT semaphore wrapper APIs.
542 * Programmable from R0 and R3. */
543 RTHANDLETABLE hHandleTable;
544 /** Load usage records. (protected by SUPDRVDEVEXT::mtxLdr) */
545 PSUPDRVLDRUSAGE volatile pLdrUsage;
546
547 /** Spinlock protecting the bundles and the GIP members. */
548 RTSPINLOCK Spinlock;
549 /** The ring-3 mapping of the GIP (readonly). */
550 RTR0MEMOBJ GipMapObjR3;
551 /** Set if the session is using the GIP. */
552 uint32_t fGipReferenced;
553 /** Bundle of locked memory objects. */
554 SUPDRVBUNDLE Bundle;
555 /** List of generic usage records. (protected by SUPDRVDEVEXT::SpinLock) */
556 PSUPDRVUSAGE volatile pUsage;
557
558 /** The user id of the session. (Set by the OS part.) */
559 RTUID Uid;
560 /** The group id of the session. (Set by the OS part.) */
561 RTGID Gid;
562 /** The process (id) of the session. */
563 RTPROCESS Process;
564 /** Which process this session is associated with.
565 * This is NIL_RTR0PROCESS for kernel sessions and valid for user ones. */
566 RTR0PROCESS R0Process;
567#ifndef SUPDRV_AGNOSTIC
568# if defined(RT_OS_DARWIN)
569 /** Pointer to the associated org_virtualbox_SupDrvClient object. */
570 void *pvSupDrvClient;
571 /** Whether this session has been opened or not. */
572 bool fOpened;
573# endif
574# if defined(RT_OS_OS2)
575 /** The system file number of this session. */
576 uint16_t sfn;
577 uint16_t Alignment; /**< Alignment */
578# endif
579# if defined(RT_OS_DARWIN) || defined(RT_OS_OS2) || defined(RT_OS_SOLARIS)
580 /** Pointer to the next session with the same hash. */
581 PSUPDRVSESSION pNextHash;
582# endif
583#endif /* !SUPDRV_AGNOSTIC */
584} SUPDRVSESSION;
585
586
587/**
588 * Device extension.
589 */
590typedef struct SUPDRVDEVEXT
591{
592 /** Spinlock to serialize the initialization, usage counting and objects. */
593 RTSPINLOCK Spinlock;
594
595 /** List of registered objects. Protected by the spinlock. */
596 PSUPDRVOBJ volatile pObjs;
597 /** List of free object usage records. */
598 PSUPDRVUSAGE volatile pUsageFree;
599
600 /** Global cookie. */
601 uint32_t u32Cookie;
602
603 /** The IDT entry number.
604 * Only valid if pIdtPatches is set. */
605 uint8_t volatile u8Idt;
606
607 /** Loader mutex.
608 * This protects pvVMMR0, pvVMMR0Entry, pImages and SUPDRVSESSION::pLdrUsage. */
609#ifdef SUPDRV_USE_MUTEX_FOR_LDR
610 RTSEMMUTEX mtxLdr;
611#else
612 RTSEMFASTMUTEX mtxLdr;
613#endif
614
615 /** VMM Module 'handle'.
616 * 0 if the code VMM isn't loaded and Idt are nops. */
617 void * volatile pvVMMR0;
618 /** VMMR0EntryInt() pointer. */
619 DECLR0CALLBACKMEMBER(int, pfnVMMR0EntryInt, (PVM pVM, unsigned uOperation, void *pvArg));
620 /** VMMR0EntryFast() pointer. */
621 DECLR0CALLBACKMEMBER(void, pfnVMMR0EntryFast, (PVM pVM, VMCPUID idCpu, unsigned uOperation));
622 /** VMMR0EntryEx() pointer. */
623 DECLR0CALLBACKMEMBER(int, pfnVMMR0EntryEx, (PVM pVM, VMCPUID idCpu, unsigned uOperation, PSUPVMMR0REQHDR pReq, uint64_t u64Arg, PSUPDRVSESSION pSession));
624
625 /** Linked list of loaded code. */
626 PSUPDRVLDRIMAGE volatile pLdrImages;
627
628 /** GIP mutex.
629 * Any changes to any of the GIP members requires ownership of this mutex,
630 * except on driver init and termination. */
631 RTSEMFASTMUTEX mtxGip;
632 /** Pointer to the Global Info Page (GIP). */
633 PSUPGLOBALINFOPAGE pGip;
634 /** The physical address of the GIP. */
635 RTHCPHYS HCPhysGip;
636 /** Number of processes using the GIP.
637 * (The updates are suspend while cGipUsers is 0.)*/
638 uint32_t volatile cGipUsers;
639 /** The ring-0 memory object handle for the GIP page. */
640 RTR0MEMOBJ GipMemObj;
641 /** The GIP timer handle. */
642 PRTTIMER pGipTimer;
643 /** If non-zero we've successfully called RTTimerRequestSystemGranularity(). */
644 uint32_t u32SystemTimerGranularityGrant;
645 /** The CPU id of the GIP master.
646 * This CPU is responsible for the updating the common GIP data. */
647 RTCPUID volatile idGipMaster;
648
649 /** Component factory mutex.
650 * This protects pComponentFactoryHead and component factory querying. */
651 RTSEMFASTMUTEX mtxComponentFactory;
652 /** The head of the list of registered component factories. */
653 PSUPDRVFACTORYREG pComponentFactoryHead;
654
655#ifndef SUPDRV_AGNOSTIC
656# ifdef RT_OS_WINDOWS
657 /* Callback object returned by ExCreateCallback. */
658 PCALLBACK_OBJECT pObjPowerCallback;
659 /* Callback handle returned by ExRegisterCallback. */
660 PVOID hPowerCallback;
661# endif
662#endif
663} SUPDRVDEVEXT;
664
665
666RT_C_DECLS_BEGIN
667
668/*******************************************************************************
669* OS Specific Functions *
670*******************************************************************************/
671void VBOXCALL supdrvOSObjInitCreator(PSUPDRVOBJ pObj, PSUPDRVSESSION pSession);
672bool VBOXCALL supdrvOSObjCanAccess(PSUPDRVOBJ pObj, PSUPDRVSESSION pSession, const char *pszObjName, int *prc);
673bool VBOXCALL supdrvOSGetForcedAsyncTscMode(PSUPDRVDEVEXT pDevExt);
674int VBOXCALL supdrvOSEnableVTx(bool fEnabled);
675
676/**
677 * Try open the image using the native loader.
678 *
679 * @returns IPRT status code.
680 * @retval VERR_NOT_SUPPORTED if native loading isn't supported.
681 *
682 * @param pDevExt The device globals.
683 * @param pImage The image handle. pvImage should be set on
684 * success, pvImageAlloc can also be set if
685 * appropriate.
686 * @param pszFilename The file name - UTF-8, may containg UNIX
687 * slashes on non-UNIX systems.
688 */
689int VBOXCALL supdrvOSLdrOpen(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, const char *pszFilename);
690
691/**
692 * Validates an entry point address.
693 *
694 * Called before supdrvOSLdrLoad.
695 *
696 * @returns IPRT status code.
697 * @param pDevExt The device globals.
698 * @param pImage The image data (still in the open state).
699 * @param pv The address within the image.
700 * @param pbImageBits The image bits as loaded by ring-3.
701 */
702int VBOXCALL supdrvOSLdrValidatePointer(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage,
703 void *pv, const uint8_t *pbImageBits);
704
705/**
706 * Load the image.
707 *
708 * @returns IPRT status code.
709 * @param pDevExt The device globals.
710 * @param pImage The image data (up to date except for some
711 * entry point pointers).
712 * @param pbImageBits The image bits as loaded by ring-3.
713 */
714int VBOXCALL supdrvOSLdrLoad(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, const uint8_t *pbImageBits);
715
716
717/**
718 * Unload the image.
719 *
720 * @param pDevExt The device globals.
721 * @param pImage The image data (mostly still valid).
722 */
723void VBOXCALL supdrvOSLdrUnload(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage);
724
725
726/*******************************************************************************
727* Shared Functions *
728*******************************************************************************/
729/* SUPDrv.c */
730int VBOXCALL supdrvIOCtl(uintptr_t uIOCtl, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPREQHDR pReqHdr);
731int VBOXCALL supdrvIOCtlFast(uintptr_t uIOCtl, VMCPUID idCpu, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession);
732int VBOXCALL supdrvIDC(uintptr_t uIOCtl, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPDRVIDCREQHDR pReqHdr);
733int VBOXCALL supdrvInitDevExt(PSUPDRVDEVEXT pDevExt);
734void VBOXCALL supdrvDeleteDevExt(PSUPDRVDEVEXT pDevExt);
735int VBOXCALL supdrvCreateSession(PSUPDRVDEVEXT pDevExt, bool fUser, PSUPDRVSESSION *ppSession);
736void VBOXCALL supdrvCloseSession(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession);
737void VBOXCALL supdrvCleanupSession(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession);
738int VBOXCALL supdrvGipInit(PSUPDRVDEVEXT pDevExt, PSUPGLOBALINFOPAGE pGip, RTHCPHYS HCPhys, uint64_t u64NanoTS, unsigned uUpdateHz);
739void VBOXCALL supdrvGipTerm(PSUPGLOBALINFOPAGE pGip);
740void VBOXCALL supdrvGipUpdate(PSUPGLOBALINFOPAGE pGip, uint64_t u64NanoTS, uint64_t u64TSC);
741void VBOXCALL supdrvGipUpdatePerCpu(PSUPGLOBALINFOPAGE pGip, uint64_t u64NanoTS, uint64_t u64TSC, unsigned iCpu);
742bool VBOXCALL supdrvDetermineAsyncTsc(uint64_t *pu64DiffCores);
743
744/* SUPDrvAgnostic.c */
745SUPGIPMODE VBOXCALL supdrvGipDeterminTscMode(PSUPDRVDEVEXT pDevExt);
746
747RT_C_DECLS_END
748
749#endif
750
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette