VirtualBox

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

Last change on this file since 25274 was 25262, checked in by vboxsync, 15 years ago

SUPDrv: Works on vista...

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