VirtualBox

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

Last change on this file since 52424 was 52424, checked in by vboxsync, 10 years ago

Only VirtualBox.dll has a TrustedError method, so add a flag to advertise it so we don't wast a lot of effort with VBoxHeadless, VBoxSDL and others that doesn't have it.

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