VirtualBox

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

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

Bad commit, reverted with following changeset

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