VirtualBox

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

Last change on this file since 36220 was 36220, checked in by vboxsync, 14 years ago

GIP: Force a couple of aCPUs accesses within bounds.

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