VirtualBox

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

Last change on this file since 51836 was 51770, checked in by vboxsync, 11 years ago

Merged in iprt++ dev branch.

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

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