VirtualBox

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

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

SUPR0QueryVTCaps: Added SUPVTCAPS_VTX_UNRESTRICTED_GUEST return flag. Increased the minor SUPDrv version number.

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