VirtualBox

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

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

SUPDrv,VMM: Tracepoints in raw-mode.

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