VirtualBox

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

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

PDM: Added search paths to the device and driver DLL CFGM nodes so that VBoxEhciR0.r0/RC.rc can be found.

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