VirtualBox

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

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

SUPDrv,IPRT,++: Enabled the code for supporting up to 256 host CPUs/cores/threads.

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