VirtualBox

source: vbox/trunk/include/VBox/sup.h@ 40740

Last change on this file since 40740 was 40740, checked in by vboxsync, 13 years ago

SUPDrv: Update GIP data behind a spinlock for online/offline race conditions.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 48.7 KB
Line 
1/** @file
2 * SUP - Support Library. (HDrv)
3 */
4
5/*
6 * Copyright (C) 2006-2007 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef ___VBox_sup_h
27#define ___VBox_sup_h
28
29#include <VBox/cdefs.h>
30#include <VBox/types.h>
31#include <iprt/assert.h>
32#include <iprt/stdarg.h>
33#include <iprt/cpuset.h>
34
35RT_C_DECLS_BEGIN
36
37/** @defgroup grp_sup The Support Library API
38 * @{
39 */
40
41/**
42 * Physical page descriptor.
43 */
44#pragma pack(4) /* space is more important. */
45typedef struct SUPPAGE
46{
47 /** Physical memory address. */
48 RTHCPHYS Phys;
49 /** Reserved entry for internal use by the caller. */
50 RTHCUINTPTR uReserved;
51} SUPPAGE;
52#pragma pack()
53/** Pointer to a page descriptor. */
54typedef SUPPAGE *PSUPPAGE;
55/** Pointer to a const page descriptor. */
56typedef const SUPPAGE *PCSUPPAGE;
57
58/**
59 * The paging mode.
60 *
61 * @remarks Users are making assumptions about the order here!
62 */
63typedef enum SUPPAGINGMODE
64{
65 /** The usual invalid entry.
66 * This is returned by SUPR3GetPagingMode() */
67 SUPPAGINGMODE_INVALID = 0,
68 /** Normal 32-bit paging, no global pages */
69 SUPPAGINGMODE_32_BIT,
70 /** Normal 32-bit paging with global pages. */
71 SUPPAGINGMODE_32_BIT_GLOBAL,
72 /** PAE mode, no global pages, no NX. */
73 SUPPAGINGMODE_PAE,
74 /** PAE mode with global pages. */
75 SUPPAGINGMODE_PAE_GLOBAL,
76 /** PAE mode with NX, no global pages. */
77 SUPPAGINGMODE_PAE_NX,
78 /** PAE mode with global pages and NX. */
79 SUPPAGINGMODE_PAE_GLOBAL_NX,
80 /** AMD64 mode, no global pages. */
81 SUPPAGINGMODE_AMD64,
82 /** AMD64 mode with global pages, no NX. */
83 SUPPAGINGMODE_AMD64_GLOBAL,
84 /** AMD64 mode with NX, no global pages. */
85 SUPPAGINGMODE_AMD64_NX,
86 /** AMD64 mode with global pages and NX. */
87 SUPPAGINGMODE_AMD64_GLOBAL_NX
88} SUPPAGINGMODE;
89
90
91/**
92 * The CPU state.
93 */
94typedef enum SUPGIPCPUSTATE
95{
96 /** Invalid CPU state / unused CPU entry. */
97 SUPGIPCPUSTATE_INVALID = 0,
98 /** The CPU is not present. */
99 SUPGIPCPUSTATE_ABSENT,
100 /** The CPU is offline. */
101 SUPGIPCPUSTATE_OFFLINE,
102 /** The CPU is online. */
103 SUPGIPCPUSTATE_ONLINE,
104 /** Force 32-bit enum type. */
105 SUPGIPCPUSTATE_32_BIT_HACK = 0x7fffffff
106} SUPGIPCPUSTATE;
107
108/**
109 * Per CPU data.
110 */
111typedef struct SUPGIPCPU
112{
113 /** Update transaction number.
114 * This number is incremented at the start and end of each update. It follows
115 * thusly that odd numbers indicates update in progress, while even numbers
116 * indicate stable data. Use this to make sure that the data items you fetch
117 * are consistent. */
118 volatile uint32_t u32TransactionId;
119 /** The interval in TSC ticks between two NanoTS updates.
120 * This is the average interval over the last 2, 4 or 8 updates + a little slack.
121 * The slack makes the time go a tiny tiny bit slower and extends the interval enough
122 * to avoid ending up with too many 1ns increments. */
123 volatile uint32_t u32UpdateIntervalTSC;
124 /** Current nanosecond timestamp. */
125 volatile uint64_t u64NanoTS;
126 /** The TSC at the time of u64NanoTS. */
127 volatile uint64_t u64TSC;
128 /** Current CPU Frequency. */
129 volatile uint64_t u64CpuHz;
130 /** Number of errors during updating.
131 * Typical errors are under/overflows. */
132 volatile uint32_t cErrors;
133 /** Index of the head item in au32TSCHistory. */
134 volatile uint32_t iTSCHistoryHead;
135 /** Array of recent TSC interval deltas.
136 * The most recent item is at index iTSCHistoryHead.
137 * This history is used to calculate u32UpdateIntervalTSC.
138 */
139 volatile uint32_t au32TSCHistory[8];
140 /** The interval between the last two NanoTS updates. (experiment for now) */
141 volatile uint32_t u32PrevUpdateIntervalNS;
142
143 /** Reserved for future per processor data. */
144 volatile uint32_t au32Reserved[5+5];
145
146 /** @todo Add topology/NUMA info. */
147 /** The CPU state. */
148 SUPGIPCPUSTATE volatile enmState;
149 /** The host CPU ID of this CPU (the SUPGIPCPU is indexed by APIC ID). */
150 RTCPUID idCpu;
151 /** The CPU set index of this CPU. */
152 int16_t iCpuSet;
153 /** The APIC ID of this CPU. */
154 uint16_t idApic;
155} SUPGIPCPU;
156AssertCompileSize(RTCPUID, 4);
157AssertCompileSize(SUPGIPCPU, 128);
158AssertCompileMemberAlignment(SUPGIPCPU, u64NanoTS, 8);
159AssertCompileMemberAlignment(SUPGIPCPU, u64TSC, 8);
160
161/** Pointer to per cpu data.
162 * @remark there is no const version of this typedef, see g_pSUPGlobalInfoPage for details. */
163typedef SUPGIPCPU *PSUPGIPCPU;
164
165
166
167/**
168 * Global Information Page.
169 *
170 * This page contains useful information and can be mapped into any
171 * process or VM. It can be accessed thru the g_pSUPGlobalInfoPage
172 * pointer when a session is open.
173 */
174typedef struct SUPGLOBALINFOPAGE
175{
176 /** Magic (SUPGLOBALINFOPAGE_MAGIC). */
177 uint32_t u32Magic;
178 /** The GIP version. */
179 uint32_t u32Version;
180
181 /** The GIP update mode, see SUPGIPMODE. */
182 uint32_t u32Mode;
183 /** The number of entries in the CPU table.
184 * (This can work as RTMpGetArraySize().) */
185 uint16_t cCpus;
186 /** The size of the GIP in pages. */
187 uint16_t cPages;
188 /** The update frequency of the of the NanoTS. */
189 volatile uint32_t u32UpdateHz;
190 /** The update interval in nanoseconds. (10^9 / u32UpdateHz) */
191 volatile uint32_t u32UpdateIntervalNS;
192 /** The timestamp of the last time we update the update frequency. */
193 volatile uint64_t u64NanoTSLastUpdateHz;
194 /** The set of online CPUs. */
195 RTCPUSET OnlineCpuSet;
196 /** The set of present CPUs. */
197 RTCPUSET PresentCpuSet;
198 /** The set of possible CPUs. */
199 RTCPUSET PossibleCpuSet;
200 /** The number of CPUs that are online. */
201 volatile uint16_t cOnlineCpus;
202 /** The number of CPUs present in the system. */
203 volatile uint16_t cPresentCpus;
204 /** The highest number of CPUs possible. */
205 uint16_t cPossibleCpus;
206 /** The highest number of CPUs possible. */
207 uint16_t u16Padding0;
208 /** The max CPU ID (RTMpGetMaxCpuId). */
209 RTCPUID idCpuMax;
210 /** Padding to 8 byte alignment. */
211 uint16_t au16Padding1[2];
212 /** Spinlock protecting the GIP array members. */
213 RTSPINLOCK Spinlock; /* 144 */
214
215 /** Padding / reserved space for future data. */
216 uint32_t au32Padding1[26];
217
218 /** Table indexed by the CPU APIC ID to get the CPU table index. */
219 uint16_t aiCpuFromApicId[256];
220 /** CPU set index to CPU table index. */
221 uint16_t aiCpuFromCpuSetIdx[RTCPUSET_MAX_CPUS];
222
223 /** Array of per-cpu data.
224 * This is index by ApicId via the aiCpuFromApicId table.
225 *
226 * The clock and frequency information is updated for all CPUs if u32Mode
227 * is SUPGIPMODE_ASYNC_TSC, otherwise (SUPGIPMODE_SYNC_TSC) only the first
228 * entry is updated. */
229 SUPGIPCPU aCPUs[1];
230} SUPGLOBALINFOPAGE;
231AssertCompileMemberAlignment(SUPGLOBALINFOPAGE, u64NanoTSLastUpdateHz, 8);
232AssertCompileMemberAlignment(SUPGLOBALINFOPAGE, aCPUs, 256);
233
234/** Pointer to the global info page.
235 * @remark there is no const version of this typedef, see g_pSUPGlobalInfoPage for details. */
236typedef SUPGLOBALINFOPAGE *PSUPGLOBALINFOPAGE;
237
238
239/** The value of the SUPGLOBALINFOPAGE::u32Magic field. (Soryo Fuyumi) */
240#define SUPGLOBALINFOPAGE_MAGIC 0x19590106
241/** The GIP version.
242 * Upper 16 bits is the major version. Major version is only changed with
243 * incompatible changes in the GIP. */
244#define SUPGLOBALINFOPAGE_VERSION 0x00030000
245
246/**
247 * SUPGLOBALINFOPAGE::u32Mode values.
248 */
249typedef enum SUPGIPMODE
250{
251 /** The usual invalid null entry. */
252 SUPGIPMODE_INVALID = 0,
253 /** The TSC of the cores and cpus in the system is in sync. */
254 SUPGIPMODE_SYNC_TSC,
255 /** Each core has it's own TSC. */
256 SUPGIPMODE_ASYNC_TSC,
257 /** The usual 32-bit hack. */
258 SUPGIPMODE_32BIT_HACK = 0x7fffffff
259} SUPGIPMODE;
260
261/** Pointer to the Global Information Page.
262 *
263 * This pointer is valid as long as SUPLib has a open session. Anyone using
264 * the page must treat this pointer as highly volatile and not trust it beyond
265 * one transaction.
266 *
267 * @remark The GIP page is read-only to everyone but the support driver and
268 * is actually mapped read only everywhere but in ring-0. However
269 * it is not marked 'const' as this might confuse compilers into
270 * thinking that values doesn't change even if members are marked
271 * as volatile. Thus, there is no PCSUPGLOBALINFOPAGE type.
272 */
273#if defined(IN_SUP_R0) || defined(IN_SUP_R3) || defined(IN_SUP_RC)
274extern DECLEXPORT(PSUPGLOBALINFOPAGE) g_pSUPGlobalInfoPage;
275
276#elif !defined(IN_RING0) || defined(RT_OS_WINDOWS) || defined(RT_OS_SOLARIS)
277extern DECLIMPORT(PSUPGLOBALINFOPAGE) g_pSUPGlobalInfoPage;
278
279#else /* IN_RING0 && !RT_OS_WINDOWS */
280# if !defined(__GNUC__) || defined(RT_OS_DARWIN) || !defined(RT_ARCH_AMD64)
281# define g_pSUPGlobalInfoPage (&g_SUPGlobalInfoPage)
282# else
283# define g_pSUPGlobalInfoPage (SUPGetGIPHlp())
284/** Workaround for ELF+GCC problem on 64-bit hosts.
285 * (GCC emits a mov with a R_X86_64_32 reloc, we need R_X86_64_64.) */
286DECLINLINE(PSUPGLOBALINFOPAGE) SUPGetGIPHlp(void)
287{
288 PSUPGLOBALINFOPAGE pGIP;
289 __asm__ __volatile__ ("movabs $g_SUPGlobalInfoPage,%0\n\t"
290 : "=a" (pGIP));
291 return pGIP;
292}
293# endif
294/** The GIP.
295 * We save a level of indirection by exporting the GIP instead of a variable
296 * pointing to it. */
297extern DECLIMPORT(SUPGLOBALINFOPAGE) g_SUPGlobalInfoPage;
298#endif
299
300/**
301 * Gets the GIP pointer.
302 *
303 * @returns Pointer to the GIP or NULL.
304 */
305SUPDECL(PSUPGLOBALINFOPAGE) SUPGetGIP(void);
306
307#ifdef ___iprt_asm_amd64_x86_h
308/**
309 * Gets the TSC frequency of the calling CPU.
310 *
311 * @returns TSC frequency, UINT64_MAX on failure.
312 * @param pGip The GIP pointer.
313 */
314DECLINLINE(uint64_t) SUPGetCpuHzFromGIP(PSUPGLOBALINFOPAGE pGip)
315{
316 unsigned iCpu;
317
318 if (RT_UNLIKELY(!pGip || pGip->u32Magic != SUPGLOBALINFOPAGE_MAGIC))
319 return UINT64_MAX;
320
321 if (pGip->u32Mode != SUPGIPMODE_ASYNC_TSC)
322 iCpu = 0;
323 else
324 {
325 iCpu = pGip->aiCpuFromApicId[ASMGetApicId()];
326 if (iCpu >= pGip->cCpus)
327 return UINT64_MAX;
328 }
329
330 return pGip->aCPUs[iCpu].u64CpuHz;
331}
332#endif
333
334/**
335 * Request for generic VMMR0Entry calls.
336 */
337typedef struct SUPVMMR0REQHDR
338{
339 /** The magic. (SUPVMMR0REQHDR_MAGIC) */
340 uint32_t u32Magic;
341 /** The size of the request. */
342 uint32_t cbReq;
343} SUPVMMR0REQHDR;
344/** Pointer to a ring-0 request header. */
345typedef SUPVMMR0REQHDR *PSUPVMMR0REQHDR;
346/** the SUPVMMR0REQHDR::u32Magic value (Ethan Iverson - The Bad Plus). */
347#define SUPVMMR0REQHDR_MAGIC UINT32_C(0x19730211)
348
349
350/** For the fast ioctl path.
351 * @{
352 */
353/** @see VMMR0_DO_RAW_RUN. */
354#define SUP_VMMR0_DO_RAW_RUN 0
355/** @see VMMR0_DO_HWACC_RUN. */
356#define SUP_VMMR0_DO_HWACC_RUN 1
357/** @see VMMR0_DO_NOP */
358#define SUP_VMMR0_DO_NOP 2
359/** @} */
360
361/** SUPR3QueryVTCaps capability flags
362 * @{
363 */
364#define SUPVTCAPS_AMD_V RT_BIT(0)
365#define SUPVTCAPS_VT_X RT_BIT(1)
366#define SUPVTCAPS_NESTED_PAGING RT_BIT(2)
367/** @} */
368
369/**
370 * Request for generic FNSUPR0SERVICEREQHANDLER calls.
371 */
372typedef struct SUPR0SERVICEREQHDR
373{
374 /** The magic. (SUPR0SERVICEREQHDR_MAGIC) */
375 uint32_t u32Magic;
376 /** The size of the request. */
377 uint32_t cbReq;
378} SUPR0SERVICEREQHDR;
379/** Pointer to a ring-0 service request header. */
380typedef SUPR0SERVICEREQHDR *PSUPR0SERVICEREQHDR;
381/** the SUPVMMR0REQHDR::u32Magic value (Esbjoern Svensson - E.S.P.). */
382#define SUPR0SERVICEREQHDR_MAGIC UINT32_C(0x19640416)
383
384
385/** Event semaphore handle. Ring-0 / ring-3. */
386typedef R0PTRTYPE(struct SUPSEMEVENTHANDLE *) SUPSEMEVENT;
387/** Pointer to an event semaphore handle. */
388typedef SUPSEMEVENT *PSUPSEMEVENT;
389/** Nil event semaphore handle. */
390#define NIL_SUPSEMEVENT ((SUPSEMEVENT)0)
391
392/**
393 * Creates a single release event semaphore.
394 *
395 * @returns VBox status code.
396 * @param pSession The session handle of the caller.
397 * @param phEvent Where to return the handle to the event semaphore.
398 */
399SUPDECL(int) SUPSemEventCreate(PSUPDRVSESSION pSession, PSUPSEMEVENT phEvent);
400
401/**
402 * Closes a single release event semaphore handle.
403 *
404 * @returns VBox status code.
405 * @retval VINF_OBJECT_DESTROYED if the semaphore was destroyed.
406 * @retval VINF_SUCCESS if the handle was successfully closed but the semaphore
407 * object remained alive because of other references.
408 *
409 * @param pSession The session handle of the caller.
410 * @param hEvent The handle. Nil is quietly ignored.
411 */
412SUPDECL(int) SUPSemEventClose(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent);
413
414/**
415 * Signals a single release event semaphore.
416 *
417 * @returns VBox status code.
418 * @param pSession The session handle of the caller.
419 * @param hEvent The semaphore handle.
420 */
421SUPDECL(int) SUPSemEventSignal(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent);
422
423#ifdef IN_RING0
424/**
425 * Waits on a single release event semaphore, not interruptible.
426 *
427 * @returns VBox status code.
428 * @param pSession The session handle of the caller.
429 * @param hEvent The semaphore handle.
430 * @param cMillies The number of milliseconds to wait.
431 * @remarks Not available in ring-3.
432 */
433SUPDECL(int) SUPSemEventWait(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent, uint32_t cMillies);
434#endif
435
436/**
437 * Waits on a single release event semaphore, interruptible.
438 *
439 * @returns VBox status code.
440 * @param pSession The session handle of the caller.
441 * @param hEvent The semaphore handle.
442 * @param cMillies The number of milliseconds to wait.
443 */
444SUPDECL(int) SUPSemEventWaitNoResume(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent, uint32_t cMillies);
445
446/**
447 * Waits on a single release event semaphore, interruptible.
448 *
449 * @returns VBox status code.
450 * @param pSession The session handle of the caller.
451 * @param hEvent The semaphore handle.
452 * @param uNsTimeout The deadline given on the RTTimeNanoTS() clock.
453 */
454SUPDECL(int) SUPSemEventWaitNsAbsIntr(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent, uint64_t uNsTimeout);
455
456/**
457 * Waits on a single release event semaphore, interruptible.
458 *
459 * @returns VBox status code.
460 * @param pSession The session handle of the caller.
461 * @param hEvent The semaphore handle.
462 * @param cNsTimeout The number of nanoseconds to wait.
463 */
464SUPDECL(int) SUPSemEventWaitNsRelIntr(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent, uint64_t cNsTimeout);
465
466/**
467 * Gets the best timeout resolution that SUPSemEventWaitNsAbsIntr and
468 * SUPSemEventWaitNsAbsIntr can do.
469 *
470 * @returns The resolution in nanoseconds.
471 * @param pSession The session handle of the caller.
472 */
473SUPDECL(uint32_t) SUPSemEventGetResolution(PSUPDRVSESSION pSession);
474
475
476/** Multiple release event semaphore handle. Ring-0 / ring-3. */
477typedef R0PTRTYPE(struct SUPSEMEVENTMULTIHANDLE *) SUPSEMEVENTMULTI;
478/** Pointer to an multiple release event semaphore handle. */
479typedef SUPSEMEVENTMULTI *PSUPSEMEVENTMULTI;
480/** Nil multiple release event semaphore handle. */
481#define NIL_SUPSEMEVENTMULTI ((SUPSEMEVENTMULTI)0)
482
483/**
484 * Creates a multiple release event semaphore.
485 *
486 * @returns VBox status code.
487 * @param pSession The session handle of the caller.
488 * @param phEventMulti Where to return the handle to the event semaphore.
489 */
490SUPDECL(int) SUPSemEventMultiCreate(PSUPDRVSESSION pSession, PSUPSEMEVENTMULTI phEventMulti);
491
492/**
493 * Closes a multiple release event semaphore handle.
494 *
495 * @returns VBox status code.
496 * @retval VINF_OBJECT_DESTROYED if the semaphore was destroyed.
497 * @retval VINF_SUCCESS if the handle was successfully closed but the semaphore
498 * object remained alive because of other references.
499 *
500 * @param pSession The session handle of the caller.
501 * @param hEventMulti The handle. Nil is quietly ignored.
502 */
503SUPDECL(int) SUPSemEventMultiClose(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti);
504
505/**
506 * Signals a multiple release event semaphore.
507 *
508 * @returns VBox status code.
509 * @param pSession The session handle of the caller.
510 * @param hEventMulti The semaphore handle.
511 */
512SUPDECL(int) SUPSemEventMultiSignal(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti);
513
514/**
515 * Resets a multiple release event semaphore.
516 *
517 * @returns VBox status code.
518 * @param pSession The session handle of the caller.
519 * @param hEventMulti The semaphore handle.
520 */
521SUPDECL(int) SUPSemEventMultiReset(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti);
522
523#ifdef IN_RING0
524/**
525 * Waits on a multiple release event semaphore, not interruptible.
526 *
527 * @returns VBox status code.
528 * @param pSession The session handle of the caller.
529 * @param hEventMulti The semaphore handle.
530 * @param cMillies The number of milliseconds to wait.
531 * @remarks Not available in ring-3.
532 */
533SUPDECL(int) SUPSemEventMultiWait(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti, uint32_t cMillies);
534#endif
535
536/**
537 * Waits on a multiple release event semaphore, interruptible.
538 *
539 * @returns VBox status code.
540 * @param pSession The session handle of the caller.
541 * @param hEventMulti The semaphore handle.
542 * @param cMillies The number of milliseconds to wait.
543 */
544SUPDECL(int) SUPSemEventMultiWaitNoResume(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti, uint32_t cMillies);
545
546/**
547 * Waits on a multiple release event semaphore, interruptible.
548 *
549 * @returns VBox status code.
550 * @param pSession The session handle of the caller.
551 * @param hEventMulti The semaphore handle.
552 * @param uNsTimeout The deadline given on the RTTimeNanoTS() clock.
553 */
554SUPDECL(int) SUPSemEventMultiWaitNsAbsIntr(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti, uint64_t uNsTimeout);
555
556/**
557 * Waits on a multiple release event semaphore, interruptible.
558 *
559 * @returns VBox status code.
560 * @param pSession The session handle of the caller.
561 * @param hEventMulti The semaphore handle.
562 * @param cNsTimeout The number of nanoseconds to wait.
563 */
564SUPDECL(int) SUPSemEventMultiWaitNsRelIntr(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti, uint64_t cNsTimeout);
565
566/**
567 * Gets the best timeout resolution that SUPSemEventMultiWaitNsAbsIntr and
568 * SUPSemEventMultiWaitNsRelIntr can do.
569 *
570 * @returns The resolution in nanoseconds.
571 * @param pSession The session handle of the caller.
572 */
573SUPDECL(uint32_t) SUPSemEventMultiGetResolution(PSUPDRVSESSION pSession);
574
575
576#ifdef IN_RING3
577
578/** @defgroup grp_sup_r3 SUP Host Context Ring-3 API
579 * @ingroup grp_sup
580 * @{
581 */
582
583/**
584 * Installs the support library.
585 *
586 * @returns VBox status code.
587 */
588SUPR3DECL(int) SUPR3Install(void);
589
590/**
591 * Uninstalls the support library.
592 *
593 * @returns VBox status code.
594 */
595SUPR3DECL(int) SUPR3Uninstall(void);
596
597/**
598 * Trusted main entry point.
599 *
600 * This is exported as "TrustedMain" by the dynamic libraries which contains the
601 * "real" application binary for which the hardened stub is built. The entry
602 * point is invoked upon successful initialization of the support library and
603 * runtime.
604 *
605 * @returns main kind of exit code.
606 * @param argc The argument count.
607 * @param argv The argument vector.
608 * @param envp The environment vector.
609 */
610typedef DECLCALLBACK(int) FNSUPTRUSTEDMAIN(int argc, char **argv, char **envp);
611/** Pointer to FNSUPTRUSTEDMAIN(). */
612typedef FNSUPTRUSTEDMAIN *PFNSUPTRUSTEDMAIN;
613
614/** Which operation failed. */
615typedef enum SUPINITOP
616{
617 /** Invalid. */
618 kSupInitOp_Invalid = 0,
619 /** Installation integrity error. */
620 kSupInitOp_Integrity,
621 /** Setuid related. */
622 kSupInitOp_RootCheck,
623 /** Driver related. */
624 kSupInitOp_Driver,
625 /** IPRT init related. */
626 kSupInitOp_IPRT,
627 /** Place holder. */
628 kSupInitOp_End
629} SUPINITOP;
630
631/**
632 * Trusted error entry point, optional.
633 *
634 * This is exported as "TrustedError" by the dynamic libraries which contains
635 * the "real" application binary for which the hardened stub is built.
636 *
637 * @param pszWhere Where the error occurred (function name).
638 * @param enmWhat Which operation went wrong.
639 * @param rc The status code.
640 * @param pszMsgFmt Error message format string.
641 * @param va The message format arguments.
642 */
643typedef DECLCALLBACK(void) FNSUPTRUSTEDERROR(const char *pszWhere, SUPINITOP enmWhat, int rc, const char *pszMsgFmt, va_list va);
644/** Pointer to FNSUPTRUSTEDERROR. */
645typedef FNSUPTRUSTEDERROR *PFNSUPTRUSTEDERROR;
646
647/**
648 * Secure main.
649 *
650 * This is used for the set-user-ID-on-execute binaries on unixy systems
651 * and when using the open-vboxdrv-via-root-service setup on Windows.
652 *
653 * This function will perform the integrity checks of the VirtualBox
654 * installation, open the support driver, open the root service (later),
655 * and load the DLL corresponding to \a pszProgName and execute its main
656 * function.
657 *
658 * @returns Return code appropriate for main().
659 *
660 * @param pszProgName The program name. This will be used to figure out which
661 * DLL/SO/DYLIB to load and execute.
662 * @param fFlags Flags.
663 * @param argc The argument count.
664 * @param argv The argument vector.
665 * @param envp The environment vector.
666 */
667DECLHIDDEN(int) SUPR3HardenedMain(const char *pszProgName, uint32_t fFlags, int argc, char **argv, char **envp);
668
669/** @name SUPR3SecureMain flags.
670 * @{ */
671/** Don't open the device. (Intended for VirtualBox without -startvm.) */
672#define SUPSECMAIN_FLAGS_DONT_OPEN_DEV RT_BIT_32(0)
673/** @} */
674
675/**
676 * Initializes the support library.
677 * Each successful call to SUPR3Init() must be countered by a
678 * call to SUPR3Term(false).
679 *
680 * @returns VBox status code.
681 * @param ppSession Where to store the session handle. Defaults to NULL.
682 */
683SUPR3DECL(int) SUPR3Init(PSUPDRVSESSION *ppSession);
684
685/**
686 * Terminates the support library.
687 *
688 * @returns VBox status code.
689 * @param fForced Forced termination. This means to ignore the
690 * init call count and just terminated.
691 */
692#ifdef __cplusplus
693SUPR3DECL(int) SUPR3Term(bool fForced = false);
694#else
695SUPR3DECL(int) SUPR3Term(int fForced);
696#endif
697
698/**
699 * Sets the ring-0 VM handle for use with fast IOCtls.
700 *
701 * @returns VBox status code.
702 * @param pVMR0 The ring-0 VM handle.
703 * NIL_RTR0PTR can be used to unset the handle when the
704 * VM is about to be destroyed.
705 */
706SUPR3DECL(int) SUPR3SetVMForFastIOCtl(PVMR0 pVMR0);
707
708/**
709 * Calls the HC R0 VMM entry point.
710 * See VMMR0Entry() for more details.
711 *
712 * @returns error code specific to uFunction.
713 * @param pVMR0 Pointer to the Ring-0 (Host Context) mapping of the VM structure.
714 * @param idCpu The virtual CPU ID.
715 * @param uOperation Operation to execute.
716 * @param pvArg Argument.
717 */
718SUPR3DECL(int) SUPR3CallVMMR0(PVMR0 pVMR0, VMCPUID idCpu, unsigned uOperation, void *pvArg);
719
720/**
721 * Variant of SUPR3CallVMMR0, except that this takes the fast ioclt path
722 * regardsless of compile-time defaults.
723 *
724 * @returns VBox status code.
725 * @param pVMR0 The ring-0 VM handle.
726 * @param uOperation The operation; only the SUP_VMMR0_DO_* ones are valid.
727 * @param idCpu The virtual CPU ID.
728 */
729SUPR3DECL(int) SUPR3CallVMMR0Fast(PVMR0 pVMR0, unsigned uOperation, VMCPUID idCpu);
730
731/**
732 * Calls the HC R0 VMM entry point, in a safer but slower manner than
733 * SUPR3CallVMMR0. When entering using this call the R0 components can call
734 * into the host kernel (i.e. use the SUPR0 and RT APIs).
735 *
736 * See VMMR0Entry() for more details.
737 *
738 * @returns error code specific to uFunction.
739 * @param pVMR0 Pointer to the Ring-0 (Host Context) mapping of the VM structure.
740 * @param idCpu The virtual CPU ID.
741 * @param uOperation Operation to execute.
742 * @param u64Arg Constant argument.
743 * @param pReqHdr Pointer to a request header. Optional.
744 * This will be copied in and out of kernel space. There currently is a size
745 * limit on this, just below 4KB.
746 */
747SUPR3DECL(int) SUPR3CallVMMR0Ex(PVMR0 pVMR0, VMCPUID idCpu, unsigned uOperation, uint64_t u64Arg, PSUPVMMR0REQHDR pReqHdr);
748
749/**
750 * Calls a ring-0 service.
751 *
752 * The operation and the request packet is specific to the service.
753 *
754 * @returns error code specific to uFunction.
755 * @param pszService The service name.
756 * @param cchService The length of the service name.
757 * @param uReq The request number.
758 * @param u64Arg Constant argument.
759 * @param pReqHdr Pointer to a request header. Optional.
760 * This will be copied in and out of kernel space. There currently is a size
761 * limit on this, just below 4KB.
762 */
763SUPR3DECL(int) SUPR3CallR0Service(const char *pszService, size_t cchService, uint32_t uOperation, uint64_t u64Arg, PSUPR0SERVICEREQHDR pReqHdr);
764
765/** Which logger. */
766typedef enum SUPLOGGER
767{
768 SUPLOGGER_DEBUG = 1,
769 SUPLOGGER_RELEASE
770} SUPLOGGER;
771
772/**
773 * Changes the settings of the specified ring-0 logger.
774 *
775 * @returns VBox status code.
776 * @param enmWhich Which logger.
777 * @param pszFlags The flags settings.
778 * @param pszGroups The groups settings.
779 * @param pszDest The destination specificier.
780 */
781SUPR3DECL(int) SUPR3LoggerSettings(SUPLOGGER enmWhich, const char *pszFlags, const char *pszGroups, const char *pszDest);
782
783/**
784 * Creates a ring-0 logger instance.
785 *
786 * @returns VBox status code.
787 * @param enmWhich Which logger to create.
788 * @param pszFlags The flags settings.
789 * @param pszGroups The groups settings.
790 * @param pszDest The destination specificier.
791 */
792SUPR3DECL(int) SUPR3LoggerCreate(SUPLOGGER enmWhich, const char *pszFlags, const char *pszGroups, const char *pszDest);
793
794/**
795 * Destroys a ring-0 logger instance.
796 *
797 * @returns VBox status code.
798 * @param enmWhich Which logger.
799 */
800SUPR3DECL(int) SUPR3LoggerDestroy(SUPLOGGER enmWhich);
801
802/**
803 * Queries the paging mode of the host OS.
804 *
805 * @returns The paging mode.
806 */
807SUPR3DECL(SUPPAGINGMODE) SUPR3GetPagingMode(void);
808
809/**
810 * Allocate zero-filled pages.
811 *
812 * Use this to allocate a number of pages suitable for seeding / locking.
813 * Call SUPR3PageFree() to free the pages once done with them.
814 *
815 * @returns VBox status.
816 * @param cPages Number of pages to allocate.
817 * @param ppvPages Where to store the base pointer to the allocated pages.
818 */
819SUPR3DECL(int) SUPR3PageAlloc(size_t cPages, void **ppvPages);
820
821/**
822 * Frees pages allocated with SUPR3PageAlloc().
823 *
824 * @returns VBox status.
825 * @param pvPages Pointer returned by SUPR3PageAlloc().
826 * @param cPages Number of pages that was allocated.
827 */
828SUPR3DECL(int) SUPR3PageFree(void *pvPages, size_t cPages);
829
830/**
831 * Allocate non-zeroed, locked, pages with user and, optionally, kernel
832 * mappings.
833 *
834 * Use SUPR3PageFreeEx() to free memory allocated with this function.
835 *
836 * @returns VBox status code.
837 * @param cPages The number of pages to allocate.
838 * @param fFlags Flags, reserved. Must be zero.
839 * @param ppvPages Where to store the address of the user mapping.
840 * @param pR0Ptr Where to store the address of the kernel mapping.
841 * NULL if no kernel mapping is desired.
842 * @param paPages Where to store the physical addresses of each page.
843 * Optional.
844 */
845SUPR3DECL(int) SUPR3PageAllocEx(size_t cPages, uint32_t fFlags, void **ppvPages, PRTR0PTR pR0Ptr, PSUPPAGE paPages);
846
847/**
848 * Maps a portion of a ring-3 only allocation into kernel space.
849 *
850 * @returns VBox status code.
851 *
852 * @param pvR3 The address SUPR3PageAllocEx return.
853 * @param off Offset to start mapping at. Must be page aligned.
854 * @param cb Number of bytes to map. Must be page aligned.
855 * @param fFlags Flags, must be zero.
856 * @param pR0Ptr Where to store the address on success.
857 *
858 */
859SUPR3DECL(int) SUPR3PageMapKernel(void *pvR3, uint32_t off, uint32_t cb, uint32_t fFlags, PRTR0PTR pR0Ptr);
860
861/**
862 * Changes the protection of
863 *
864 * @returns VBox status code.
865 * @retval VERR_NOT_SUPPORTED if the OS doesn't allow us to change page level
866 * protection. See also RTR0MemObjProtect.
867 *
868 * @param pvR3 The ring-3 address SUPR3PageAllocEx returned.
869 * @param R0Ptr The ring-0 address SUPR3PageAllocEx returned if it
870 * is desired that the corresponding ring-0 page
871 * mappings should change protection as well. Pass
872 * NIL_RTR0PTR if the ring-0 pages should remain
873 * unaffected.
874 * @param off Offset to start at which to start chagning the page
875 * level protection. Must be page aligned.
876 * @param cb Number of bytes to change. Must be page aligned.
877 * @param fProt The new page level protection, either a combination
878 * of RTMEM_PROT_READ, RTMEM_PROT_WRITE and
879 * RTMEM_PROT_EXEC, or just RTMEM_PROT_NONE.
880 */
881SUPR3DECL(int) SUPR3PageProtect(void *pvR3, RTR0PTR R0Ptr, uint32_t off, uint32_t cb, uint32_t fProt);
882
883/**
884 * Free pages allocated by SUPR3PageAllocEx.
885 *
886 * @returns VBox status code.
887 * @param pvPages The address of the user mapping.
888 * @param cPages The number of pages.
889 */
890SUPR3DECL(int) SUPR3PageFreeEx(void *pvPages, size_t cPages);
891
892/**
893 * Allocated memory with page aligned memory with a contiguous and locked physical
894 * memory backing below 4GB.
895 *
896 * @returns Pointer to the allocated memory (virtual address).
897 * *pHCPhys is set to the physical address of the memory.
898 * If ppvR0 isn't NULL, *ppvR0 is set to the ring-0 mapping.
899 * The returned memory must be freed using SUPR3ContFree().
900 * @returns NULL on failure.
901 * @param cPages Number of pages to allocate.
902 * @param pR0Ptr Where to store the ring-0 mapping of the allocation. (optional)
903 * @param pHCPhys Where to store the physical address of the memory block.
904 *
905 * @remark This 2nd version of this API exists because we're not able to map the
906 * ring-3 mapping executable on WIN64. This is a serious problem in regard to
907 * the world switchers.
908 */
909SUPR3DECL(void *) SUPR3ContAlloc(size_t cPages, PRTR0PTR pR0Ptr, PRTHCPHYS pHCPhys);
910
911/**
912 * Frees memory allocated with SUPR3ContAlloc().
913 *
914 * @returns VBox status code.
915 * @param pv Pointer to the memory block which should be freed.
916 * @param cPages Number of pages to be freed.
917 */
918SUPR3DECL(int) SUPR3ContFree(void *pv, size_t cPages);
919
920/**
921 * Allocated non contiguous physical memory below 4GB.
922 *
923 * The memory isn't zeroed.
924 *
925 * @returns VBox status code.
926 * @returns NULL on failure.
927 * @param cPages Number of pages to allocate.
928 * @param ppvPages Where to store the pointer to the allocated memory.
929 * The pointer stored here on success must be passed to
930 * SUPR3LowFree when the memory should be released.
931 * @param ppvPagesR0 Where to store the ring-0 pointer to the allocated memory. optional.
932 * @param paPages Where to store the physical addresses of the individual pages.
933 */
934SUPR3DECL(int) SUPR3LowAlloc(size_t cPages, void **ppvPages, PRTR0PTR ppvPagesR0, PSUPPAGE paPages);
935
936/**
937 * Frees memory allocated with SUPR3LowAlloc().
938 *
939 * @returns VBox status code.
940 * @param pv Pointer to the memory block which should be freed.
941 * @param cPages Number of pages that was allocated.
942 */
943SUPR3DECL(int) SUPR3LowFree(void *pv, size_t cPages);
944
945/**
946 * Load a module into R0 HC.
947 *
948 * This will verify the file integrity in a similar manner as
949 * SUPR3HardenedVerifyFile before loading it.
950 *
951 * @returns VBox status code.
952 * @param pszFilename The path to the image file.
953 * @param pszModule The module name. Max 32 bytes.
954 * @param ppvImageBase Where to store the image address.
955 * @param pErrInfo Where to return extended error information.
956 * Optional.
957 */
958SUPR3DECL(int) SUPR3LoadModule(const char *pszFilename, const char *pszModule, void **ppvImageBase, PRTERRINFO pErrInfo);
959
960/**
961 * Load a module into R0 HC.
962 *
963 * This will verify the file integrity in a similar manner as
964 * SUPR3HardenedVerifyFile before loading it.
965 *
966 * @returns VBox status code.
967 * @param pszFilename The path to the image file.
968 * @param pszModule The module name. Max 32 bytes.
969 * @param pszSrvReqHandler The name of the service request handler entry
970 * point. See FNSUPR0SERVICEREQHANDLER.
971 * @param ppvImageBase Where to store the image address.
972 */
973SUPR3DECL(int) SUPR3LoadServiceModule(const char *pszFilename, const char *pszModule,
974 const char *pszSrvReqHandler, void **ppvImageBase);
975
976/**
977 * Frees a R0 HC module.
978 *
979 * @returns VBox status code.
980 * @param pszModule The module to free.
981 * @remark This will not actually 'free' the module, there are of course usage counting.
982 */
983SUPR3DECL(int) SUPR3FreeModule(void *pvImageBase);
984
985/**
986 * Get the address of a symbol in a ring-0 module.
987 *
988 * @returns VBox status code.
989 * @param pszModule The module name.
990 * @param pszSymbol Symbol name. If it's value is less than 64k it's treated like a
991 * ordinal value rather than a string pointer.
992 * @param ppvValue Where to store the symbol value.
993 */
994SUPR3DECL(int) SUPR3GetSymbolR0(void *pvImageBase, const char *pszSymbol, void **ppvValue);
995
996/**
997 * Load R0 HC VMM code.
998 *
999 * @returns VBox status code.
1000 * @deprecated Use SUPR3LoadModule(pszFilename, "VMMR0.r0", &pvImageBase)
1001 */
1002SUPR3DECL(int) SUPR3LoadVMM(const char *pszFilename);
1003
1004/**
1005 * Unloads R0 HC VMM code.
1006 *
1007 * @returns VBox status code.
1008 * @deprecated Use SUPR3FreeModule().
1009 */
1010SUPR3DECL(int) SUPR3UnloadVMM(void);
1011
1012/**
1013 * Get the physical address of the GIP.
1014 *
1015 * @returns VBox status code.
1016 * @param pHCPhys Where to store the physical address of the GIP.
1017 */
1018SUPR3DECL(int) SUPR3GipGetPhys(PRTHCPHYS pHCPhys);
1019
1020/**
1021 * Verifies the integrity of a file, and optionally opens it.
1022 *
1023 * The integrity check is for whether the file is suitable for loading into
1024 * the hypervisor or VM process. The integrity check may include verifying
1025 * the authenticode/elfsign/whatever signature of the file, which can take
1026 * a little while.
1027 *
1028 * @returns VBox status code. On failure it will have printed a LogRel message.
1029 *
1030 * @param pszFilename The file.
1031 * @param pszWhat For the LogRel on failure.
1032 * @param phFile Where to store the handle to the opened file. This is optional, pass NULL
1033 * if the file should not be opened.
1034 * @deprecated Write a new one.
1035 */
1036SUPR3DECL(int) SUPR3HardenedVerifyFile(const char *pszFilename, const char *pszWhat, PRTFILE phFile);
1037
1038/**
1039 * Verifies the integrity of a the current process, including the image
1040 * location and that the invocation was absolute.
1041 *
1042 * This must currently be called after initializing the runtime. The intended
1043 * audience is set-uid-to-root applications, root services and similar.
1044 *
1045 * @returns VBox status code. On failure
1046 * message.
1047 * @param pszArgv0 The first argument to main().
1048 * @param fInternal Set this to @c true if this is an internal
1049 * VirtualBox application. Otherwise pass @c false.
1050 * @param pErrInfo Where to return extended error information.
1051 */
1052SUPR3DECL(int) SUPR3HardenedVerifySelf(const char *pszArgv0, bool fInternal, PRTERRINFO pErrInfo);
1053
1054/**
1055 * Verifies the integrity of an installation directory.
1056 *
1057 * The integrity check verifies that the directory cannot be tampered with by
1058 * normal users on the system. On Unix this translates to root ownership and
1059 * no symbolic linking.
1060 *
1061 * @returns VBox status code. On failure a message will be stored in @a pszErr.
1062 *
1063 * @param pszDirPath The directory path.
1064 * @param fRecursive Whether the check should be recursive or
1065 * not. When set, all sub-directores will be checked,
1066 * including files (@a fCheckFiles is ignored).
1067 * @param fCheckFiles Whether to apply the same basic integrity check to
1068 * the files in the directory as the directory itself.
1069 * @param pErrInfo Where to return extended error information.
1070 * Optional.
1071 */
1072SUPR3DECL(int) SUPR3HardenedVerifyDir(const char *pszDirPath, bool fRecursive, bool fCheckFiles, PRTERRINFO pErrInfo);
1073
1074/**
1075 * Verifies the integrity of a plug-in module.
1076 *
1077 * This is similar to SUPR3HardenedLdrLoad, except it does not load the module
1078 * and that the module does not have to be shipped with VirtualBox.
1079 *
1080 * @returns VBox status code. On failure a message will be stored in @a pszErr.
1081 *
1082 * @param pszFilename The filename of the plug-in module (nothing can be
1083 * omitted here).
1084 * @param pErrInfo Where to return extended error information.
1085 * Optional.
1086 */
1087SUPR3DECL(int) SUPR3HardenedVerifyPlugIn(const char *pszFilename, PRTERRINFO pErrInfo);
1088
1089/**
1090 * Same as RTLdrLoad() but will verify the files it loads (hardened builds).
1091 *
1092 * Will add dll suffix if missing and try load the file.
1093 *
1094 * @returns iprt status code.
1095 * @param pszFilename Image filename. This must have a path.
1096 * @param phLdrMod Where to store the handle to the loaded module.
1097 * @param fFlags See RTLDRLOAD_FLAGS_XXX.
1098 * @param pErrInfo Where to return extended error information.
1099 * Optional.
1100 */
1101SUPR3DECL(int) SUPR3HardenedLdrLoad(const char *pszFilename, PRTLDRMOD phLdrMod, uint32_t fFlags, PRTERRINFO pErrInfo);
1102
1103/**
1104 * Same as RTLdrLoadAppPriv() but it will verify the files it loads (hardened
1105 * builds).
1106 *
1107 * Will add dll suffix to the file if missing, then look for it in the
1108 * architecture dependent application directory.
1109 *
1110 * @returns iprt status code.
1111 * @param pszFilename Image filename.
1112 * @param phLdrMod Where to store the handle to the loaded module.
1113 * @param fFlags See RTLDRLOAD_FLAGS_XXX.
1114 * @param pErrInfo Where to return extended error information.
1115 * Optional.
1116 */
1117SUPR3DECL(int) SUPR3HardenedLdrLoadAppPriv(const char *pszFilename, PRTLDRMOD phLdrMod, uint32_t fFlags, PRTERRINFO pErrInfo);
1118
1119/**
1120 * Same as RTLdrLoad() but will verify the files it loads (hardened builds).
1121 *
1122 * This differs from SUPR3HardenedLdrLoad() in that it can load modules from
1123 * extension packs and anything else safely installed on the system, provided
1124 * they pass the hardening tests.
1125 *
1126 * @returns iprt status code.
1127 * @param pszFilename The full path to the module, with extension.
1128 * @param phLdrMod Where to store the handle to the loaded module.
1129 * @param pErrInfo Where to return extended error information.
1130 * Optional.
1131 */
1132SUPR3DECL(int) SUPR3HardenedLdrLoadPlugIn(const char *pszFilename, PRTLDRMOD phLdrMod, PRTERRINFO pErrInfo);
1133
1134/**
1135 * Check if the host kernel can run in VMX root mode.
1136 *
1137 * @returns VINF_SUCCESS if supported, error code indicating why if not.
1138 */
1139SUPR3DECL(int) SUPR3QueryVTxSupported(void);
1140
1141/**
1142 * Return VT-x/AMD-V capabilities.
1143 *
1144 * @returns VINF_SUCCESS if supported, error code indicating why if not.
1145 * @param pfCaps Pointer to capability dword (out).
1146 * @todo Intended for main, which means we need to relax the privilege requires
1147 * when accessing certain vboxdrv functions.
1148 */
1149SUPR3DECL(int) SUPR3QueryVTCaps(uint32_t *pfCaps);
1150
1151/** @} */
1152#endif /* IN_RING3 */
1153
1154
1155#ifdef IN_RING0
1156/** @defgroup grp_sup_r0 SUP Host Context Ring-0 API
1157 * @ingroup grp_sup
1158 * @{
1159 */
1160
1161/**
1162 * Security objectype.
1163 */
1164typedef enum SUPDRVOBJTYPE
1165{
1166 /** The usual invalid object. */
1167 SUPDRVOBJTYPE_INVALID = 0,
1168 /** A Virtual Machine instance. */
1169 SUPDRVOBJTYPE_VM,
1170 /** Internal network. */
1171 SUPDRVOBJTYPE_INTERNAL_NETWORK,
1172 /** Internal network interface. */
1173 SUPDRVOBJTYPE_INTERNAL_NETWORK_INTERFACE,
1174 /** Single release event semaphore. */
1175 SUPDRVOBJTYPE_SEM_EVENT,
1176 /** Multiple release event semaphore. */
1177 SUPDRVOBJTYPE_SEM_EVENT_MULTI,
1178 /** Raw PCI device. */
1179 SUPDRVOBJTYPE_RAW_PCI_DEVICE,
1180 /** The first invalid object type in this end. */
1181 SUPDRVOBJTYPE_END,
1182 /** The usual 32-bit type size hack. */
1183 SUPDRVOBJTYPE_32_BIT_HACK = 0x7ffffff
1184} SUPDRVOBJTYPE;
1185
1186/**
1187 * Object destructor callback.
1188 * This is called for reference counted objectes when the count reaches 0.
1189 *
1190 * @param pvObj The object pointer.
1191 * @param pvUser1 The first user argument.
1192 * @param pvUser2 The second user argument.
1193 */
1194typedef DECLCALLBACK(void) FNSUPDRVDESTRUCTOR(void *pvObj, void *pvUser1, void *pvUser2);
1195/** Pointer to a FNSUPDRVDESTRUCTOR(). */
1196typedef FNSUPDRVDESTRUCTOR *PFNSUPDRVDESTRUCTOR;
1197
1198SUPR0DECL(void *) SUPR0ObjRegister(PSUPDRVSESSION pSession, SUPDRVOBJTYPE enmType, PFNSUPDRVDESTRUCTOR pfnDestructor, void *pvUser1, void *pvUser2);
1199SUPR0DECL(int) SUPR0ObjAddRef(void *pvObj, PSUPDRVSESSION pSession);
1200SUPR0DECL(int) SUPR0ObjAddRefEx(void *pvObj, PSUPDRVSESSION pSession, bool fNoBlocking);
1201SUPR0DECL(int) SUPR0ObjRelease(void *pvObj, PSUPDRVSESSION pSession);
1202SUPR0DECL(int) SUPR0ObjVerifyAccess(void *pvObj, PSUPDRVSESSION pSession, const char *pszObjName);
1203
1204SUPR0DECL(int) SUPR0LockMem(PSUPDRVSESSION pSession, RTR3PTR pvR3, uint32_t cPages, PRTHCPHYS paPages);
1205SUPR0DECL(int) SUPR0UnlockMem(PSUPDRVSESSION pSession, RTR3PTR pvR3);
1206SUPR0DECL(int) SUPR0ContAlloc(PSUPDRVSESSION pSession, uint32_t cPages, PRTR0PTR ppvR0, PRTR3PTR ppvR3, PRTHCPHYS pHCPhys);
1207SUPR0DECL(int) SUPR0ContFree(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr);
1208SUPR0DECL(int) SUPR0LowAlloc(PSUPDRVSESSION pSession, uint32_t cPages, PRTR0PTR ppvR0, PRTR3PTR ppvR3, PRTHCPHYS paPages);
1209SUPR0DECL(int) SUPR0LowFree(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr);
1210SUPR0DECL(int) SUPR0MemAlloc(PSUPDRVSESSION pSession, uint32_t cb, PRTR0PTR ppvR0, PRTR3PTR ppvR3);
1211SUPR0DECL(int) SUPR0MemGetPhys(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr, PSUPPAGE paPages);
1212SUPR0DECL(int) SUPR0MemFree(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr);
1213SUPR0DECL(int) SUPR0PageAllocEx(PSUPDRVSESSION pSession, uint32_t cPages, uint32_t fFlags, PRTR3PTR ppvR3, PRTR0PTR ppvR0, PRTHCPHYS paPages);
1214SUPR0DECL(int) SUPR0PageMapKernel(PSUPDRVSESSION pSession, RTR3PTR pvR3, uint32_t offSub, uint32_t cbSub, uint32_t fFlags, PRTR0PTR ppvR0);
1215SUPR0DECL(int) SUPR0PageProtect(PSUPDRVSESSION pSession, RTR3PTR pvR3, RTR0PTR pvR0, uint32_t offSub, uint32_t cbSub, uint32_t fProt);
1216SUPR0DECL(int) SUPR0PageFree(PSUPDRVSESSION pSession, RTR3PTR pvR3);
1217SUPR0DECL(int) SUPR0GipMap(PSUPDRVSESSION pSession, PRTR3PTR ppGipR3, PRTHCPHYS pHCPhysGip);
1218SUPR0DECL(int) SUPR0QueryVTCaps(PSUPDRVSESSION pSession, uint32_t *pfCaps);
1219SUPR0DECL(int) SUPR0GipUnmap(PSUPDRVSESSION pSession);
1220SUPR0DECL(int) SUPR0Printf(const char *pszFormat, ...);
1221SUPR0DECL(SUPPAGINGMODE) SUPR0GetPagingMode(void);
1222SUPR0DECL(int) SUPR0EnableVTx(bool fEnable);
1223
1224/** @name Absolute symbols
1225 * Take the address of these, don't try call them.
1226 * @{ */
1227SUPR0DECL(void) SUPR0AbsIs64bit(void);
1228SUPR0DECL(void) SUPR0Abs64bitKernelCS(void);
1229SUPR0DECL(void) SUPR0Abs64bitKernelSS(void);
1230SUPR0DECL(void) SUPR0Abs64bitKernelDS(void);
1231SUPR0DECL(void) SUPR0AbsKernelCS(void);
1232SUPR0DECL(void) SUPR0AbsKernelSS(void);
1233SUPR0DECL(void) SUPR0AbsKernelDS(void);
1234SUPR0DECL(void) SUPR0AbsKernelES(void);
1235SUPR0DECL(void) SUPR0AbsKernelFS(void);
1236SUPR0DECL(void) SUPR0AbsKernelGS(void);
1237/** @} */
1238
1239/**
1240 * Support driver component factory.
1241 *
1242 * Component factories are registered by drivers that provides services
1243 * such as the host network interface filtering and access to the host
1244 * TCP/IP stack.
1245 *
1246 * @remark Module dependencies and making sure that a component doesn't
1247 * get unloaded while in use, is the sole responsibility of the
1248 * driver/kext/whatever implementing the component.
1249 */
1250typedef struct SUPDRVFACTORY
1251{
1252 /** The (unique) name of the component factory. */
1253 char szName[56];
1254 /**
1255 * Queries a factory interface.
1256 *
1257 * The factory interface is specific to each component and will be be
1258 * found in the header(s) for the component alongside its UUID.
1259 *
1260 * @returns Pointer to the factory interfaces on success, NULL on failure.
1261 *
1262 * @param pSupDrvFactory Pointer to this structure.
1263 * @param pSession The SUPDRV session making the query.
1264 * @param pszInterfaceUuid The UUID of the factory interface.
1265 */
1266 DECLR0CALLBACKMEMBER(void *, pfnQueryFactoryInterface,(struct SUPDRVFACTORY const *pSupDrvFactory, PSUPDRVSESSION pSession, const char *pszInterfaceUuid));
1267} SUPDRVFACTORY;
1268/** Pointer to a support driver factory. */
1269typedef SUPDRVFACTORY *PSUPDRVFACTORY;
1270/** Pointer to a const support driver factory. */
1271typedef SUPDRVFACTORY const *PCSUPDRVFACTORY;
1272
1273SUPR0DECL(int) SUPR0ComponentRegisterFactory(PSUPDRVSESSION pSession, PCSUPDRVFACTORY pFactory);
1274SUPR0DECL(int) SUPR0ComponentDeregisterFactory(PSUPDRVSESSION pSession, PCSUPDRVFACTORY pFactory);
1275SUPR0DECL(int) SUPR0ComponentQueryFactory(PSUPDRVSESSION pSession, const char *pszName, const char *pszInterfaceUuid, void **ppvFactoryIf);
1276
1277
1278struct VTGOBJHDR;
1279SUPR0DECL(int) SUPR0VtgRegisterDrv(PSUPDRVSESSION pSession, struct VTGOBJHDR *pVtgHdr, const char *pszName);
1280SUPR0DECL(void) SUPR0VtgDeregisterDrv(PSUPDRVSESSION pSession);
1281SUPR0DECL(void) SUPR0VtgFireProbe(uint32_t idProbe, uintptr_t uArg0, uintptr_t uArg1, uintptr_t uArg2,
1282 uintptr_t uArg3, uintptr_t uArg4);
1283SUPR0DECL(int) SUPR0VtgRegisterModule(void *hMod, struct VTGOBJHDR *pVtgHdr);
1284
1285/**
1286 * Service request callback function.
1287 *
1288 * @returns VBox status code.
1289 * @param pSession The caller's session.
1290 * @param u64Arg 64-bit integer argument.
1291 * @param pReqHdr The request header. Input / Output. Optional.
1292 */
1293typedef DECLCALLBACK(int) FNSUPR0SERVICEREQHANDLER(PSUPDRVSESSION pSession, uint32_t uOperation,
1294 uint64_t u64Arg, PSUPR0SERVICEREQHDR pReqHdr);
1295/** Pointer to a FNR0SERVICEREQHANDLER(). */
1296typedef R0PTRTYPE(FNSUPR0SERVICEREQHANDLER *) PFNSUPR0SERVICEREQHANDLER;
1297
1298
1299/** @defgroup grp_sup_r0_idc The IDC Interface
1300 * @ingroup grp_sup_r0
1301 * @{
1302 */
1303
1304/** The current SUPDRV IDC version.
1305 * This follows the usual high word / low word rules, i.e. high word is the
1306 * major number and it signifies incompatible interface changes. */
1307#define SUPDRV_IDC_VERSION UINT32_C(0x00010000)
1308
1309/**
1310 * Inter-Driver Communication Handle.
1311 */
1312typedef union SUPDRVIDCHANDLE
1313{
1314 /** Padding for opaque usage.
1315 * Must be greater or equal in size than the private struct. */
1316 void *apvPadding[4];
1317#ifdef SUPDRVIDCHANDLEPRIVATE_DECLARED
1318 /** The private view. */
1319 struct SUPDRVIDCHANDLEPRIVATE s;
1320#endif
1321} SUPDRVIDCHANDLE;
1322/** Pointer to a handle. */
1323typedef SUPDRVIDCHANDLE *PSUPDRVIDCHANDLE;
1324
1325SUPR0DECL(int) SUPR0IdcOpen(PSUPDRVIDCHANDLE pHandle, uint32_t uReqVersion, uint32_t uMinVersion,
1326 uint32_t *puSessionVersion, uint32_t *puDriverVersion, uint32_t *puDriverRevision);
1327SUPR0DECL(int) SUPR0IdcCall(PSUPDRVIDCHANDLE pHandle, uint32_t iReq, void *pvReq, uint32_t cbReq);
1328SUPR0DECL(int) SUPR0IdcClose(PSUPDRVIDCHANDLE pHandle);
1329SUPR0DECL(PSUPDRVSESSION) SUPR0IdcGetSession(PSUPDRVIDCHANDLE pHandle);
1330SUPR0DECL(int) SUPR0IdcComponentRegisterFactory(PSUPDRVIDCHANDLE pHandle, PCSUPDRVFACTORY pFactory);
1331SUPR0DECL(int) SUPR0IdcComponentDeregisterFactory(PSUPDRVIDCHANDLE pHandle, PCSUPDRVFACTORY pFactory);
1332
1333/** @} */
1334
1335/** @name Ring-0 module entry points.
1336 *
1337 * These can be exported by ring-0 modules SUP are told to load.
1338 *
1339 * @{ */
1340DECLEXPORT(int) ModuleInit(void *hMod);
1341DECLEXPORT(void) ModuleTerm(void *hMod);
1342/** @} */
1343
1344
1345/** @} */
1346#endif
1347
1348
1349/** @} */
1350
1351RT_C_DECLS_END
1352
1353#endif
1354
Note: See TracBrowser for help on using the repository browser.

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