VirtualBox

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

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

VMM,*: Annotated format strings in the VMM APIs and dealt with the fallout.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 82.0 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/**
555 * Worker for SUPIsTscFreqCompatible().
556 *
557 * @param uBaseCpuHz The reference CPU frequency of the system.
558 * @param uCpuHz The CPU frequency to compare with the base.
559 *
560 * @returns true if it's compatible, false otherwise.
561 * @remarks Don't use directly, use SUPIsTscFreqCompatible() instead. This is
562 * to be used by tstGIP-2 (or the like).
563 */
564DECLINLINE(bool) SUPIsTscFreqCompatibleEx(uint64_t uBaseCpuHz, uint64_t uCpuHz)
565{
566 if (uBaseCpuHz != uCpuHz)
567 {
568 /* Arbitrary tolerance threshold, tweak later if required, perhaps
569 more tolerance on lower frequencies and less tolerance on higher. */
570 uint64_t uLo = (uBaseCpuHz << 11) / 2049;
571 uint64_t uHi = uBaseCpuHz + (uBaseCpuHz - uLo);
572 if ( uCpuHz < uLo
573 || uCpuHz > uHi)
574 return false;
575 }
576 return true;
577}
578
579
580/**
581 * Checks if the provided TSC frequency is close enough to the computed TSC
582 * frequency of the host.
583 *
584 * @param u64CpuHz The TSC frequency to check.
585 *
586 * @returns true if it's compatible, false otherwise.
587 */
588DECLINLINE(bool) SUPIsTscFreqCompatible(uint64_t u64CpuHz)
589{
590 PSUPGLOBALINFOPAGE pGip = g_pSUPGlobalInfoPage;
591 if ( pGip
592 && pGip->u32Mode == SUPGIPMODE_INVARIANT_TSC)
593 return SUPIsTscFreqCompatibleEx(pGip->u64CpuHz, u64CpuHz);
594 return false;
595}
596
597
598#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
599
600/** @internal */
601SUPDECL(uint64_t) SUPReadTscWithDelta(PSUPGLOBALINFOPAGE pGip);
602
603/**
604 * Read the host TSC value and applies the TSC delta if appropriate.
605 *
606 * @returns the TSC value.
607 * @remarks Requires GIP to be initialized and valid.
608 */
609DECLINLINE(uint64_t) SUPReadTsc(void)
610{
611 PSUPGLOBALINFOPAGE pGip = g_pSUPGlobalInfoPage;
612 if (pGip->enmUseTscDelta <= SUPGIPUSETSCDELTA_ROUGHLY_ZERO)
613 return ASMReadTSC();
614 return SUPReadTscWithDelta(pGip);
615}
616
617#endif /* X86 || AMD64 */
618
619/** @internal */
620SUPDECL(uint64_t) SUPGetTscDeltaSlow(PSUPGLOBALINFOPAGE pGip);
621
622/**
623 * Gets the TSC delta for the current CPU.
624 *
625 * @returns The TSC delta value (will not return the special INT64_MAX value).
626 * @remarks Requires GIP to be initialized and valid.
627 */
628DECLINLINE(int64_t) SUPGetTscDelta(void)
629{
630 PSUPGLOBALINFOPAGE pGip = g_pSUPGlobalInfoPage;
631 if (pGip->enmUseTscDelta <= SUPGIPUSETSCDELTA_ROUGHLY_ZERO)
632 return 0;
633 return SUPGetTscDeltaSlow(pGip);
634}
635
636
637/**
638 * Gets the TSC delta for a given CPU.
639 *
640 * @returns The TSC delta value (will not return the special INT64_MAX value).
641 * @param iCpuSet The CPU set index of the CPU which TSC delta we want.
642 * @remarks Requires GIP to be initialized and valid.
643 */
644DECLINLINE(int64_t) SUPGetTscDeltaByCpuSetIndex(uint32_t iCpuSet)
645{
646 PSUPGLOBALINFOPAGE pGip = g_pSUPGlobalInfoPage;
647 if (pGip->enmUseTscDelta <= SUPGIPUSETSCDELTA_ROUGHLY_ZERO)
648 return 0;
649 if (RT_LIKELY(iCpuSet < RT_ELEMENTS(pGip->aiCpuFromCpuSetIdx)))
650 {
651 uint16_t iCpu = pGip->aiCpuFromCpuSetIdx[iCpuSet];
652 if (RT_LIKELY(iCpu < pGip->cCpus))
653 {
654 int64_t iTscDelta = pGip->aCPUs[iCpu].i64TSCDelta;
655 if (iTscDelta != INT64_MAX)
656 return iTscDelta;
657 }
658 }
659 AssertFailed();
660 return 0;
661}
662
663
664/**
665 * Checks if the TSC delta is available for a given CPU (if TSC-deltas are
666 * relevant).
667 *
668 * @returns true if it's okay to read the TSC, false otherwise.
669 *
670 * @param iCpuSet The CPU set index of the CPU which TSC delta we check.
671 * @remarks Requires GIP to be initialized and valid.
672 */
673DECLINLINE(bool) SUPIsTscDeltaAvailableForCpuSetIndex(uint32_t iCpuSet)
674{
675 PSUPGLOBALINFOPAGE pGip = g_pSUPGlobalInfoPage;
676 if (pGip->enmUseTscDelta <= SUPGIPUSETSCDELTA_ROUGHLY_ZERO)
677 return true;
678 if (RT_LIKELY(iCpuSet < RT_ELEMENTS(pGip->aiCpuFromCpuSetIdx)))
679 {
680 uint16_t iCpu = pGip->aiCpuFromCpuSetIdx[iCpuSet];
681 if (RT_LIKELY(iCpu < pGip->cCpus))
682 {
683 int64_t iTscDelta = pGip->aCPUs[iCpu].i64TSCDelta;
684 if (iTscDelta != INT64_MAX)
685 return true;
686 }
687 }
688 return false;
689}
690
691
692/**
693 * Gets the descriptive GIP mode name.
694 *
695 * @returns The name.
696 * @param pGip Pointer to the GIP.
697 */
698DECLINLINE(const char *) SUPGetGIPModeName(PSUPGLOBALINFOPAGE pGip)
699{
700 AssertReturn(pGip, NULL);
701 switch (pGip->u32Mode)
702 {
703 case SUPGIPMODE_INVARIANT_TSC: return "Invariant";
704 case SUPGIPMODE_SYNC_TSC: return "Synchronous";
705 case SUPGIPMODE_ASYNC_TSC: return "Asynchronous";
706 case SUPGIPMODE_INVALID: return "Invalid";
707 default: return "???";
708 }
709}
710
711
712/**
713 * Gets the descriptive TSC-delta enum name.
714 *
715 * @returns The name.
716 * @param pGip Pointer to the GIP.
717 */
718DECLINLINE(const char *) SUPGetGIPTscDeltaModeName(PSUPGLOBALINFOPAGE pGip)
719{
720 AssertReturn(pGip, NULL);
721 switch (pGip->enmUseTscDelta)
722 {
723 case SUPGIPUSETSCDELTA_NOT_APPLICABLE: return "Not Applicable";
724 case SUPGIPUSETSCDELTA_ZERO_CLAIMED: return "Zero Claimed";
725 case SUPGIPUSETSCDELTA_PRACTICALLY_ZERO: return "Pratically Zero";
726 case SUPGIPUSETSCDELTA_ROUGHLY_ZERO: return "Roughly Zero";
727 case SUPGIPUSETSCDELTA_NOT_ZERO: return "Not Zero";
728 default: return "???";
729 }
730}
731
732
733/**
734 * Request for generic VMMR0Entry calls.
735 */
736typedef struct SUPVMMR0REQHDR
737{
738 /** The magic. (SUPVMMR0REQHDR_MAGIC) */
739 uint32_t u32Magic;
740 /** The size of the request. */
741 uint32_t cbReq;
742} SUPVMMR0REQHDR;
743/** Pointer to a ring-0 request header. */
744typedef SUPVMMR0REQHDR *PSUPVMMR0REQHDR;
745/** the SUPVMMR0REQHDR::u32Magic value (Ethan Iverson - The Bad Plus). */
746#define SUPVMMR0REQHDR_MAGIC UINT32_C(0x19730211)
747
748
749/** For the fast ioctl path.
750 * @{
751 */
752/** @see VMMR0_DO_RAW_RUN. */
753#define SUP_VMMR0_DO_RAW_RUN 0
754/** @see VMMR0_DO_HM_RUN. */
755#define SUP_VMMR0_DO_HM_RUN 1
756/** @see VMMR0_DO_NOP */
757#define SUP_VMMR0_DO_NOP 2
758/** @} */
759
760/** SUPR3QueryVTCaps capability flags
761 * @{
762 */
763/** AMD-V support. */
764#define SUPVTCAPS_AMD_V RT_BIT(0)
765/** VT-x support. */
766#define SUPVTCAPS_VT_X RT_BIT(1)
767/** Nested paging is supported. */
768#define SUPVTCAPS_NESTED_PAGING RT_BIT(2)
769/** VT-x: Unrestricted guest execution is supported. */
770#define SUPVTCAPS_VTX_UNRESTRICTED_GUEST RT_BIT(3)
771/** @} */
772
773/**
774 * Request for generic FNSUPR0SERVICEREQHANDLER calls.
775 */
776typedef struct SUPR0SERVICEREQHDR
777{
778 /** The magic. (SUPR0SERVICEREQHDR_MAGIC) */
779 uint32_t u32Magic;
780 /** The size of the request. */
781 uint32_t cbReq;
782} SUPR0SERVICEREQHDR;
783/** Pointer to a ring-0 service request header. */
784typedef SUPR0SERVICEREQHDR *PSUPR0SERVICEREQHDR;
785/** the SUPVMMR0REQHDR::u32Magic value (Esbjoern Svensson - E.S.P.). */
786#define SUPR0SERVICEREQHDR_MAGIC UINT32_C(0x19640416)
787
788
789/**
790 * Creates a single release event semaphore.
791 *
792 * @returns VBox status code.
793 * @param pSession The session handle of the caller.
794 * @param phEvent Where to return the handle to the event semaphore.
795 */
796SUPDECL(int) SUPSemEventCreate(PSUPDRVSESSION pSession, PSUPSEMEVENT phEvent);
797
798/**
799 * Closes a single release event semaphore handle.
800 *
801 * @returns VBox status code.
802 * @retval VINF_OBJECT_DESTROYED if the semaphore was destroyed.
803 * @retval VINF_SUCCESS if the handle was successfully closed but the semaphore
804 * object remained alive because of other references.
805 *
806 * @param pSession The session handle of the caller.
807 * @param hEvent The handle. Nil is quietly ignored.
808 */
809SUPDECL(int) SUPSemEventClose(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent);
810
811/**
812 * Signals a single release event semaphore.
813 *
814 * @returns VBox status code.
815 * @param pSession The session handle of the caller.
816 * @param hEvent The semaphore handle.
817 */
818SUPDECL(int) SUPSemEventSignal(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent);
819
820#ifdef IN_RING0
821/**
822 * Waits on a single release event semaphore, not interruptible.
823 *
824 * @returns VBox status code.
825 * @param pSession The session handle of the caller.
826 * @param hEvent The semaphore handle.
827 * @param cMillies The number of milliseconds to wait.
828 * @remarks Not available in ring-3.
829 */
830SUPDECL(int) SUPSemEventWait(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent, uint32_t cMillies);
831#endif
832
833/**
834 * Waits on a single release event semaphore, interruptible.
835 *
836 * @returns VBox status code.
837 * @param pSession The session handle of the caller.
838 * @param hEvent The semaphore handle.
839 * @param cMillies The number of milliseconds to wait.
840 */
841SUPDECL(int) SUPSemEventWaitNoResume(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent, uint32_t cMillies);
842
843/**
844 * Waits on a single release event semaphore, interruptible.
845 *
846 * @returns VBox status code.
847 * @param pSession The session handle of the caller.
848 * @param hEvent The semaphore handle.
849 * @param uNsTimeout The deadline given on the RTTimeNanoTS() clock.
850 */
851SUPDECL(int) SUPSemEventWaitNsAbsIntr(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent, uint64_t uNsTimeout);
852
853/**
854 * Waits on a single release event semaphore, interruptible.
855 *
856 * @returns VBox status code.
857 * @param pSession The session handle of the caller.
858 * @param hEvent The semaphore handle.
859 * @param cNsTimeout The number of nanoseconds to wait.
860 */
861SUPDECL(int) SUPSemEventWaitNsRelIntr(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent, uint64_t cNsTimeout);
862
863/**
864 * Gets the best timeout resolution that SUPSemEventWaitNsAbsIntr and
865 * SUPSemEventWaitNsAbsIntr can do.
866 *
867 * @returns The resolution in nanoseconds.
868 * @param pSession The session handle of the caller.
869 */
870SUPDECL(uint32_t) SUPSemEventGetResolution(PSUPDRVSESSION pSession);
871
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,
1037 const char *pszMsgFmt, va_list va) RT_IPRT_FORMAT_ATTR(4, 0);
1038/** Pointer to FNSUPTRUSTEDERROR. */
1039typedef FNSUPTRUSTEDERROR *PFNSUPTRUSTEDERROR;
1040
1041/**
1042 * Secure main.
1043 *
1044 * This is used for the set-user-ID-on-execute binaries on unixy systems
1045 * and when using the open-vboxdrv-via-root-service setup on Windows.
1046 *
1047 * This function will perform the integrity checks of the VirtualBox
1048 * installation, open the support driver, open the root service (later),
1049 * and load the DLL corresponding to \a pszProgName and execute its main
1050 * function.
1051 *
1052 * @returns Return code appropriate for main().
1053 *
1054 * @param pszProgName The program name. This will be used to figure out which
1055 * DLL/SO/DYLIB to load and execute.
1056 * @param fFlags Flags.
1057 * @param argc The argument count.
1058 * @param argv The argument vector.
1059 * @param envp The environment vector.
1060 */
1061DECLHIDDEN(int) SUPR3HardenedMain(const char *pszProgName, uint32_t fFlags, int argc, char **argv, char **envp);
1062
1063/** @name SUPR3HardenedMain flags.
1064 * @{ */
1065/** Don't open the device. (Intended for VirtualBox without -startvm.) */
1066#define SUPSECMAIN_FLAGS_DONT_OPEN_DEV RT_BIT_32(0)
1067/** The hardened DLL has a "TrustedError" function (see FNSUPTRUSTEDERROR). */
1068#define SUPSECMAIN_FLAGS_TRUSTED_ERROR RT_BIT_32(1)
1069/** Hack for making VirtualBoxVM use VirtualBox.dylib on Mac OS X. */
1070#define SUPSECMAIN_FLAGS_OSX_VM_APP RT_BIT_32(2)
1071/** Program binary location mask. */
1072#define SUPSECMAIN_FLAGS_LOC_MASK UINT32_C(0x00000010)
1073/** Default binary location is the application binary directory. Does
1074 * not need to be given explicitly (it's 0). */
1075#define SUPSECMAIN_FLAGS_LOC_APP_BIN UINT32_C(0x00000000)
1076/** The binary is located in the testcase directory instead of the
1077 * default application binary directory. */
1078#define SUPSECMAIN_FLAGS_LOC_TESTCASE UINT32_C(0x00000010)
1079/** @} */
1080
1081/**
1082 * Initializes the support library.
1083 *
1084 * Each successful call to SUPR3Init() or SUPR3InitEx must be countered by a
1085 * call to SUPR3Term(false).
1086 *
1087 * @returns VBox status code.
1088 * @param ppSession Where to store the session handle. Defaults to NULL.
1089 */
1090SUPR3DECL(int) SUPR3Init(PSUPDRVSESSION *ppSession);
1091
1092
1093/**
1094 * Initializes the support library, extended version.
1095 *
1096 * Each successful call to SUPR3Init() or SUPR3InitEx must be countered by a
1097 * call to SUPR3Term(false).
1098 *
1099 * @returns VBox status code.
1100 * @param fUnrestricted The desired access.
1101 * @param ppSession Where to store the session handle. Defaults to NULL.
1102 */
1103SUPR3DECL(int) SUPR3InitEx(bool fUnrestricted, PSUPDRVSESSION *ppSession);
1104
1105/**
1106 * Terminates the support library.
1107 *
1108 * @returns VBox status code.
1109 * @param fForced Forced termination. This means to ignore the
1110 * init call count and just terminated.
1111 */
1112#ifdef __cplusplus
1113SUPR3DECL(int) SUPR3Term(bool fForced = false);
1114#else
1115SUPR3DECL(int) SUPR3Term(int fForced);
1116#endif
1117
1118/**
1119 * Sets the ring-0 VM handle for use with fast IOCtls.
1120 *
1121 * @returns VBox status code.
1122 * @param pVMR0 The ring-0 VM handle.
1123 * NIL_RTR0PTR can be used to unset the handle when the
1124 * VM is about to be destroyed.
1125 */
1126SUPR3DECL(int) SUPR3SetVMForFastIOCtl(PVMR0 pVMR0);
1127
1128/**
1129 * Calls the HC R0 VMM entry point.
1130 * See VMMR0Entry() for more details.
1131 *
1132 * @returns error code specific to uFunction.
1133 * @param pVMR0 Pointer to the Ring-0 (Host Context) mapping of the VM structure.
1134 * @param idCpu The virtual CPU ID.
1135 * @param uOperation Operation to execute.
1136 * @param pvArg Argument.
1137 */
1138SUPR3DECL(int) SUPR3CallVMMR0(PVMR0 pVMR0, VMCPUID idCpu, unsigned uOperation, void *pvArg);
1139
1140/**
1141 * Variant of SUPR3CallVMMR0, except that this takes the fast ioclt path
1142 * regardsless of compile-time defaults.
1143 *
1144 * @returns VBox status code.
1145 * @param pVMR0 The ring-0 VM handle.
1146 * @param uOperation The operation; only the SUP_VMMR0_DO_* ones are valid.
1147 * @param idCpu The virtual CPU ID.
1148 */
1149SUPR3DECL(int) SUPR3CallVMMR0Fast(PVMR0 pVMR0, unsigned uOperation, VMCPUID idCpu);
1150
1151/**
1152 * Calls the HC R0 VMM entry point, in a safer but slower manner than
1153 * SUPR3CallVMMR0. When entering using this call the R0 components can call
1154 * into the host kernel (i.e. use the SUPR0 and RT APIs).
1155 *
1156 * See VMMR0Entry() for more details.
1157 *
1158 * @returns error code specific to uFunction.
1159 * @param pVMR0 Pointer to the Ring-0 (Host Context) mapping of the VM structure.
1160 * @param idCpu The virtual CPU ID.
1161 * @param uOperation Operation to execute.
1162 * @param u64Arg Constant argument.
1163 * @param pReqHdr Pointer to a request header. Optional.
1164 * This will be copied in and out of kernel space. There currently is a size
1165 * limit on this, just below 4KB.
1166 */
1167SUPR3DECL(int) SUPR3CallVMMR0Ex(PVMR0 pVMR0, VMCPUID idCpu, unsigned uOperation, uint64_t u64Arg, PSUPVMMR0REQHDR pReqHdr);
1168
1169/**
1170 * Calls a ring-0 service.
1171 *
1172 * The operation and the request packet is specific to the service.
1173 *
1174 * @returns error code specific to uFunction.
1175 * @param pszService The service name.
1176 * @param cchService The length of the service name.
1177 * @param uReq The request number.
1178 * @param u64Arg Constant argument.
1179 * @param pReqHdr Pointer to a request header. Optional.
1180 * This will be copied in and out of kernel space. There currently is a size
1181 * limit on this, just below 4KB.
1182 */
1183SUPR3DECL(int) SUPR3CallR0Service(const char *pszService, size_t cchService, uint32_t uOperation, uint64_t u64Arg, PSUPR0SERVICEREQHDR pReqHdr);
1184
1185/** Which logger. */
1186typedef enum SUPLOGGER
1187{
1188 SUPLOGGER_DEBUG = 1,
1189 SUPLOGGER_RELEASE
1190} SUPLOGGER;
1191
1192/**
1193 * Changes the settings of the specified ring-0 logger.
1194 *
1195 * @returns VBox status code.
1196 * @param enmWhich Which logger.
1197 * @param pszFlags The flags settings.
1198 * @param pszGroups The groups settings.
1199 * @param pszDest The destination specificier.
1200 */
1201SUPR3DECL(int) SUPR3LoggerSettings(SUPLOGGER enmWhich, const char *pszFlags, const char *pszGroups, const char *pszDest);
1202
1203/**
1204 * Creates a ring-0 logger instance.
1205 *
1206 * @returns VBox status code.
1207 * @param enmWhich Which logger to create.
1208 * @param pszFlags The flags settings.
1209 * @param pszGroups The groups settings.
1210 * @param pszDest The destination specificier.
1211 */
1212SUPR3DECL(int) SUPR3LoggerCreate(SUPLOGGER enmWhich, const char *pszFlags, const char *pszGroups, const char *pszDest);
1213
1214/**
1215 * Destroys a ring-0 logger instance.
1216 *
1217 * @returns VBox status code.
1218 * @param enmWhich Which logger.
1219 */
1220SUPR3DECL(int) SUPR3LoggerDestroy(SUPLOGGER enmWhich);
1221
1222/**
1223 * Queries the paging mode of the host OS.
1224 *
1225 * @returns The paging mode.
1226 */
1227SUPR3DECL(SUPPAGINGMODE) SUPR3GetPagingMode(void);
1228
1229/**
1230 * Allocate zero-filled pages.
1231 *
1232 * Use this to allocate a number of pages suitable for seeding / locking.
1233 * Call SUPR3PageFree() to free the pages once done with them.
1234 *
1235 * @returns VBox status.
1236 * @param cPages Number of pages to allocate.
1237 * @param ppvPages Where to store the base pointer to the allocated pages.
1238 */
1239SUPR3DECL(int) SUPR3PageAlloc(size_t cPages, void **ppvPages);
1240
1241/**
1242 * Frees pages allocated with SUPR3PageAlloc().
1243 *
1244 * @returns VBox status.
1245 * @param pvPages Pointer returned by SUPR3PageAlloc().
1246 * @param cPages Number of pages that was allocated.
1247 */
1248SUPR3DECL(int) SUPR3PageFree(void *pvPages, size_t cPages);
1249
1250/**
1251 * Allocate non-zeroed, locked, pages with user and, optionally, kernel
1252 * mappings.
1253 *
1254 * Use SUPR3PageFreeEx() to free memory allocated with this function.
1255 *
1256 * @returns VBox status code.
1257 * @param cPages The number of pages to allocate.
1258 * @param fFlags Flags, reserved. Must be zero.
1259 * @param ppvPages Where to store the address of the user mapping.
1260 * @param pR0Ptr Where to store the address of the kernel mapping.
1261 * NULL if no kernel mapping is desired.
1262 * @param paPages Where to store the physical addresses of each page.
1263 * Optional.
1264 */
1265SUPR3DECL(int) SUPR3PageAllocEx(size_t cPages, uint32_t fFlags, void **ppvPages, PRTR0PTR pR0Ptr, PSUPPAGE paPages);
1266
1267/**
1268 * Maps a portion of a ring-3 only allocation into kernel space.
1269 *
1270 * @returns VBox status code.
1271 *
1272 * @param pvR3 The address SUPR3PageAllocEx return.
1273 * @param off Offset to start mapping at. Must be page aligned.
1274 * @param cb Number of bytes to map. Must be page aligned.
1275 * @param fFlags Flags, must be zero.
1276 * @param pR0Ptr Where to store the address on success.
1277 *
1278 */
1279SUPR3DECL(int) SUPR3PageMapKernel(void *pvR3, uint32_t off, uint32_t cb, uint32_t fFlags, PRTR0PTR pR0Ptr);
1280
1281/**
1282 * Changes the protection of
1283 *
1284 * @returns VBox status code.
1285 * @retval VERR_NOT_SUPPORTED if the OS doesn't allow us to change page level
1286 * protection. See also RTR0MemObjProtect.
1287 *
1288 * @param pvR3 The ring-3 address SUPR3PageAllocEx returned.
1289 * @param R0Ptr The ring-0 address SUPR3PageAllocEx returned if it
1290 * is desired that the corresponding ring-0 page
1291 * mappings should change protection as well. Pass
1292 * NIL_RTR0PTR if the ring-0 pages should remain
1293 * unaffected.
1294 * @param off Offset to start at which to start chagning the page
1295 * level protection. Must be page aligned.
1296 * @param cb Number of bytes to change. Must be page aligned.
1297 * @param fProt The new page level protection, either a combination
1298 * of RTMEM_PROT_READ, RTMEM_PROT_WRITE and
1299 * RTMEM_PROT_EXEC, or just RTMEM_PROT_NONE.
1300 */
1301SUPR3DECL(int) SUPR3PageProtect(void *pvR3, RTR0PTR R0Ptr, uint32_t off, uint32_t cb, uint32_t fProt);
1302
1303/**
1304 * Free pages allocated by SUPR3PageAllocEx.
1305 *
1306 * @returns VBox status code.
1307 * @param pvPages The address of the user mapping.
1308 * @param cPages The number of pages.
1309 */
1310SUPR3DECL(int) SUPR3PageFreeEx(void *pvPages, size_t cPages);
1311
1312/**
1313 * Allocated memory with page aligned memory with a contiguous and locked physical
1314 * memory backing below 4GB.
1315 *
1316 * @returns Pointer to the allocated memory (virtual address).
1317 * *pHCPhys is set to the physical address of the memory.
1318 * If ppvR0 isn't NULL, *ppvR0 is set to the ring-0 mapping.
1319 * The returned memory must be freed using SUPR3ContFree().
1320 * @returns NULL on failure.
1321 * @param cPages Number of pages to allocate.
1322 * @param pR0Ptr Where to store the ring-0 mapping of the allocation. (optional)
1323 * @param pHCPhys Where to store the physical address of the memory block.
1324 *
1325 * @remark This 2nd version of this API exists because we're not able to map the
1326 * ring-3 mapping executable on WIN64. This is a serious problem in regard to
1327 * the world switchers.
1328 */
1329SUPR3DECL(void *) SUPR3ContAlloc(size_t cPages, PRTR0PTR pR0Ptr, PRTHCPHYS pHCPhys);
1330
1331/**
1332 * Frees memory allocated with SUPR3ContAlloc().
1333 *
1334 * @returns VBox status code.
1335 * @param pv Pointer to the memory block which should be freed.
1336 * @param cPages Number of pages to be freed.
1337 */
1338SUPR3DECL(int) SUPR3ContFree(void *pv, size_t cPages);
1339
1340/**
1341 * Allocated non contiguous physical memory below 4GB.
1342 *
1343 * The memory isn't zeroed.
1344 *
1345 * @returns VBox status code.
1346 * @returns NULL on failure.
1347 * @param cPages Number of pages to allocate.
1348 * @param ppvPages Where to store the pointer to the allocated memory.
1349 * The pointer stored here on success must be passed to
1350 * SUPR3LowFree when the memory should be released.
1351 * @param ppvPagesR0 Where to store the ring-0 pointer to the allocated memory. optional.
1352 * @param paPages Where to store the physical addresses of the individual pages.
1353 */
1354SUPR3DECL(int) SUPR3LowAlloc(size_t cPages, void **ppvPages, PRTR0PTR ppvPagesR0, PSUPPAGE paPages);
1355
1356/**
1357 * Frees memory allocated with SUPR3LowAlloc().
1358 *
1359 * @returns VBox status code.
1360 * @param pv Pointer to the memory block which should be freed.
1361 * @param cPages Number of pages that was allocated.
1362 */
1363SUPR3DECL(int) SUPR3LowFree(void *pv, size_t cPages);
1364
1365/**
1366 * Load a module into R0 HC.
1367 *
1368 * This will verify the file integrity in a similar manner as
1369 * SUPR3HardenedVerifyFile before loading it.
1370 *
1371 * @returns VBox status code.
1372 * @param pszFilename The path to the image file.
1373 * @param pszModule The module name. Max 32 bytes.
1374 * @param ppvImageBase Where to store the image address.
1375 * @param pErrInfo Where to return extended error information.
1376 * Optional.
1377 */
1378SUPR3DECL(int) SUPR3LoadModule(const char *pszFilename, const char *pszModule, void **ppvImageBase, PRTERRINFO pErrInfo);
1379
1380/**
1381 * Load a module into R0 HC.
1382 *
1383 * This will verify the file integrity in a similar manner as
1384 * SUPR3HardenedVerifyFile before loading it.
1385 *
1386 * @returns VBox status code.
1387 * @param pszFilename The path to the image file.
1388 * @param pszModule The module name. Max 32 bytes.
1389 * @param pszSrvReqHandler The name of the service request handler entry
1390 * point. See FNSUPR0SERVICEREQHANDLER.
1391 * @param ppvImageBase Where to store the image address.
1392 */
1393SUPR3DECL(int) SUPR3LoadServiceModule(const char *pszFilename, const char *pszModule,
1394 const char *pszSrvReqHandler, void **ppvImageBase);
1395
1396/**
1397 * Frees a R0 HC module.
1398 *
1399 * @returns VBox status code.
1400 * @param pszModule The module to free.
1401 * @remark This will not actually 'free' the module, there are of course usage counting.
1402 */
1403SUPR3DECL(int) SUPR3FreeModule(void *pvImageBase);
1404
1405/**
1406 * Lock down the module loader interface.
1407 *
1408 * This will lock down the module loader interface. No new modules can be
1409 * loaded and all loaded modules can no longer be freed.
1410 *
1411 * @returns VBox status code.
1412 * @param pErrInfo Where to return extended error information.
1413 * Optional.
1414 */
1415SUPR3DECL(int) SUPR3LockDownLoader(PRTERRINFO pErrInfo);
1416
1417/**
1418 * Get the address of a symbol in a ring-0 module.
1419 *
1420 * @returns VBox status code.
1421 * @param pszModule The module name.
1422 * @param pszSymbol Symbol name. If it's value is less than 64k it's treated like a
1423 * ordinal value rather than a string pointer.
1424 * @param ppvValue Where to store the symbol value.
1425 */
1426SUPR3DECL(int) SUPR3GetSymbolR0(void *pvImageBase, const char *pszSymbol, void **ppvValue);
1427
1428/**
1429 * Load R0 HC VMM code.
1430 *
1431 * @returns VBox status code.
1432 * @deprecated Use SUPR3LoadModule(pszFilename, "VMMR0.r0", &pvImageBase)
1433 */
1434SUPR3DECL(int) SUPR3LoadVMM(const char *pszFilename);
1435
1436/**
1437 * Unloads R0 HC VMM code.
1438 *
1439 * @returns VBox status code.
1440 * @deprecated Use SUPR3FreeModule().
1441 */
1442SUPR3DECL(int) SUPR3UnloadVMM(void);
1443
1444/**
1445 * Get the physical address of the GIP.
1446 *
1447 * @returns VBox status code.
1448 * @param pHCPhys Where to store the physical address of the GIP.
1449 */
1450SUPR3DECL(int) SUPR3GipGetPhys(PRTHCPHYS pHCPhys);
1451
1452/**
1453 * Initializes only the bits relevant for the SUPR3HardenedVerify* APIs.
1454 *
1455 * This is for users that don't necessarily need to initialize the whole of
1456 * SUPLib. There is no harm in calling this one more time.
1457 *
1458 * @returns VBox status code.
1459 * @remarks Currently not counted, so only call once.
1460 */
1461SUPR3DECL(int) SUPR3HardenedVerifyInit(void);
1462
1463/**
1464 * Reverses the effect of SUPR3HardenedVerifyInit if SUPR3InitEx hasn't been
1465 * called.
1466 *
1467 * Ignored if the support library was initialized using SUPR3Init or
1468 * SUPR3InitEx.
1469 *
1470 * @returns VBox status code.
1471 */
1472SUPR3DECL(int) SUPR3HardenedVerifyTerm(void);
1473
1474/**
1475 * Verifies the integrity of a file, and optionally opens it.
1476 *
1477 * The integrity check is for whether the file is suitable for loading into
1478 * the hypervisor or VM process. The integrity check may include verifying
1479 * the authenticode/elfsign/whatever signature of the file, which can take
1480 * a little while.
1481 *
1482 * @returns VBox status code. On failure it will have printed a LogRel message.
1483 *
1484 * @param pszFilename The file.
1485 * @param pszWhat For the LogRel on failure.
1486 * @param phFile Where to store the handle to the opened file. This is optional, pass NULL
1487 * if the file should not be opened.
1488 * @deprecated Write a new one.
1489 */
1490SUPR3DECL(int) SUPR3HardenedVerifyFile(const char *pszFilename, const char *pszWhat, PRTFILE phFile);
1491
1492/**
1493 * Verifies the integrity of a the current process, including the image
1494 * location and that the invocation was absolute.
1495 *
1496 * This must currently be called after initializing the runtime. The intended
1497 * audience is set-uid-to-root applications, root services and similar.
1498 *
1499 * @returns VBox status code. On failure
1500 * message.
1501 * @param pszArgv0 The first argument to main().
1502 * @param fInternal Set this to @c true if this is an internal
1503 * VirtualBox application. Otherwise pass @c false.
1504 * @param pErrInfo Where to return extended error information.
1505 */
1506SUPR3DECL(int) SUPR3HardenedVerifySelf(const char *pszArgv0, bool fInternal, PRTERRINFO pErrInfo);
1507
1508/**
1509 * Verifies the integrity of an installation directory.
1510 *
1511 * The integrity check verifies that the directory cannot be tampered with by
1512 * normal users on the system. On Unix this translates to root ownership and
1513 * no symbolic linking.
1514 *
1515 * @returns VBox status code. On failure a message will be stored in @a pszErr.
1516 *
1517 * @param pszDirPath The directory path.
1518 * @param fRecursive Whether the check should be recursive or
1519 * not. When set, all sub-directores will be checked,
1520 * including files (@a fCheckFiles is ignored).
1521 * @param fCheckFiles Whether to apply the same basic integrity check to
1522 * the files in the directory as the directory itself.
1523 * @param pErrInfo Where to return extended error information.
1524 * Optional.
1525 */
1526SUPR3DECL(int) SUPR3HardenedVerifyDir(const char *pszDirPath, bool fRecursive, bool fCheckFiles, PRTERRINFO pErrInfo);
1527
1528/**
1529 * Verifies the integrity of a plug-in module.
1530 *
1531 * This is similar to SUPR3HardenedLdrLoad, except it does not load the module
1532 * and that the module does not have to be shipped with VirtualBox.
1533 *
1534 * @returns VBox status code. On failure a message will be stored in @a pszErr.
1535 *
1536 * @param pszFilename The filename of the plug-in module (nothing can be
1537 * omitted here).
1538 * @param pErrInfo Where to return extended error information.
1539 * Optional.
1540 */
1541SUPR3DECL(int) SUPR3HardenedVerifyPlugIn(const char *pszFilename, PRTERRINFO pErrInfo);
1542
1543/**
1544 * Same as RTLdrLoad() but will verify the files it loads (hardened builds).
1545 *
1546 * Will add dll suffix if missing and try load the file.
1547 *
1548 * @returns iprt status code.
1549 * @param pszFilename Image filename. This must have a path.
1550 * @param phLdrMod Where to store the handle to the loaded module.
1551 * @param fFlags See RTLDRLOAD_FLAGS_XXX.
1552 * @param pErrInfo Where to return extended error information.
1553 * Optional.
1554 */
1555SUPR3DECL(int) SUPR3HardenedLdrLoad(const char *pszFilename, PRTLDRMOD phLdrMod, uint32_t fFlags, PRTERRINFO pErrInfo);
1556
1557/**
1558 * Same as RTLdrLoadAppPriv() but it will verify the files it loads (hardened
1559 * builds).
1560 *
1561 * Will add dll suffix to the file if missing, then look for it in the
1562 * architecture dependent application directory.
1563 *
1564 * @returns iprt status code.
1565 * @param pszFilename Image filename.
1566 * @param phLdrMod Where to store the handle to the loaded module.
1567 * @param fFlags See RTLDRLOAD_FLAGS_XXX.
1568 * @param pErrInfo Where to return extended error information.
1569 * Optional.
1570 */
1571SUPR3DECL(int) SUPR3HardenedLdrLoadAppPriv(const char *pszFilename, PRTLDRMOD phLdrMod, uint32_t fFlags, PRTERRINFO pErrInfo);
1572
1573/**
1574 * Same as RTLdrLoad() but will verify the files it loads (hardened builds).
1575 *
1576 * This differs from SUPR3HardenedLdrLoad() in that it can load modules from
1577 * extension packs and anything else safely installed on the system, provided
1578 * they pass the hardening tests.
1579 *
1580 * @returns iprt status code.
1581 * @param pszFilename The full path to the module, with extension.
1582 * @param phLdrMod Where to store the handle to the loaded module.
1583 * @param pErrInfo Where to return extended error information.
1584 * Optional.
1585 */
1586SUPR3DECL(int) SUPR3HardenedLdrLoadPlugIn(const char *pszFilename, PRTLDRMOD phLdrMod, PRTERRINFO pErrInfo);
1587
1588/**
1589 * Check if the host kernel can run in VMX root mode.
1590 *
1591 * @returns VINF_SUCCESS if supported, error code indicating why if not.
1592 */
1593SUPR3DECL(int) SUPR3QueryVTxSupported(void);
1594
1595/**
1596 * Return VT-x/AMD-V capabilities.
1597 *
1598 * @returns VINF_SUCCESS if supported, error code indicating why if not.
1599 * @param pfCaps Pointer to capability dword (out).
1600 * @todo Intended for main, which means we need to relax the privilege requires
1601 * when accessing certain vboxdrv functions.
1602 */
1603SUPR3DECL(int) SUPR3QueryVTCaps(uint32_t *pfCaps);
1604
1605/**
1606 * Open the tracer.
1607 *
1608 * @returns VBox status code.
1609 * @param uCookie Cookie identifying the tracer we expect to talk to.
1610 * @param uArg Tracer specific open argument.
1611 */
1612SUPR3DECL(int) SUPR3TracerOpen(uint32_t uCookie, uintptr_t uArg);
1613
1614/**
1615 * Closes the tracer.
1616 *
1617 * @returns VBox status code.
1618 */
1619SUPR3DECL(int) SUPR3TracerClose(void);
1620
1621/**
1622 * Perform an I/O request on the tracer.
1623 *
1624 * @returns VBox status.
1625 * @param uCmd The tracer command.
1626 * @param uArg The argument.
1627 * @param piRetVal Where to store the tracer return value.
1628 */
1629SUPR3DECL(int) SUPR3TracerIoCtl(uintptr_t uCmd, uintptr_t uArg, int32_t *piRetVal);
1630
1631/**
1632 * Registers the user module with the tracer.
1633 *
1634 * @returns VBox status code.
1635 * @param hModNative Native module handle. Pass ~(uintptr_t)0 if not
1636 * at hand.
1637 * @param pszModule The module name.
1638 * @param pVtgHdr The VTG header.
1639 * @param uVtgHdrAddr The address to which the VTG header is loaded
1640 * in the relevant execution context.
1641 * @param fFlags See SUP_TRACER_UMOD_FLAGS_XXX
1642 */
1643SUPR3DECL(int) SUPR3TracerRegisterModule(uintptr_t hModNative, const char *pszModule, struct VTGOBJHDR *pVtgHdr,
1644 RTUINTPTR uVtgHdrAddr, uint32_t fFlags);
1645
1646/**
1647 * Deregisters the user module.
1648 *
1649 * @returns VBox status code.
1650 * @param pVtgHdr The VTG header.
1651 */
1652SUPR3DECL(int) SUPR3TracerDeregisterModule(struct VTGOBJHDR *pVtgHdr);
1653
1654/**
1655 * Fire the probe.
1656 *
1657 * @param pVtgProbeLoc The probe location record.
1658 * @param uArg0 Raw probe argument 0.
1659 * @param uArg1 Raw probe argument 1.
1660 * @param uArg2 Raw probe argument 2.
1661 * @param uArg3 Raw probe argument 3.
1662 * @param uArg4 Raw probe argument 4.
1663 */
1664SUPDECL(void) SUPTracerFireProbe(struct VTGPROBELOC *pVtgProbeLoc, uintptr_t uArg0, uintptr_t uArg1, uintptr_t uArg2,
1665 uintptr_t uArg3, uintptr_t uArg4);
1666
1667
1668/**
1669 * Attempts to read the value of an MSR.
1670 *
1671 * @returns VBox status code.
1672 * @param uMsr The MSR to read.
1673 * @param idCpu The CPU to read it on, NIL_RTCPUID if it doesn't
1674 * matter which CPU.
1675 * @param puValue Where to return the value.
1676 * @param pfGp Where to store the \#GP indicator for the read
1677 * operation.
1678 */
1679SUPR3DECL(int) SUPR3MsrProberRead(uint32_t uMsr, RTCPUID idCpu, uint64_t *puValue, bool *pfGp);
1680
1681/**
1682 * Attempts to write to an MSR.
1683 *
1684 * @returns VBox status code.
1685 * @param uMsr The MSR to write to.
1686 * @param idCpu The CPU to wrtie it on, NIL_RTCPUID if it
1687 * doesn't matter which CPU.
1688 * @param uValue The value to write.
1689 * @param pfGp Where to store the \#GP indicator for the write
1690 * operation.
1691 */
1692SUPR3DECL(int) SUPR3MsrProberWrite(uint32_t uMsr, RTCPUID idCpu, uint64_t uValue, bool *pfGp);
1693
1694/**
1695 * Attempts to modify the value of an MSR.
1696 *
1697 * @returns VBox status code.
1698 * @param uMsr The MSR to modify.
1699 * @param idCpu The CPU to modify it on, NIL_RTCPUID if it
1700 * doesn't matter which CPU.
1701 * @param fAndMask The bits to keep in the current MSR value.
1702 * @param fOrMask The bits to set before writing.
1703 * @param pResult The result buffer.
1704 */
1705SUPR3DECL(int) SUPR3MsrProberModify(uint32_t uMsr, RTCPUID idCpu, uint64_t fAndMask, uint64_t fOrMask,
1706 PSUPMSRPROBERMODIFYRESULT pResult);
1707
1708/**
1709 * Attempts to modify the value of an MSR, extended version.
1710 *
1711 * @returns VBox status code.
1712 * @param uMsr The MSR to modify.
1713 * @param idCpu The CPU to modify it on, NIL_RTCPUID if it
1714 * doesn't matter which CPU.
1715 * @param fAndMask The bits to keep in the current MSR value.
1716 * @param fOrMask The bits to set before writing.
1717 * @param fFaster If set to @c true some cache/tlb invalidation is
1718 * skipped, otherwise behave like
1719 * SUPR3MsrProberModify.
1720 * @param pResult The result buffer.
1721 */
1722SUPR3DECL(int) SUPR3MsrProberModifyEx(uint32_t uMsr, RTCPUID idCpu, uint64_t fAndMask, uint64_t fOrMask, bool fFaster,
1723 PSUPMSRPROBERMODIFYRESULT pResult);
1724
1725/**
1726 * Resume built-in keyboard on MacBook Air and Pro hosts.
1727 *
1728 * @returns VBox status code.
1729 */
1730SUPR3DECL(int) SUPR3ResumeSuspendedKeyboards(void);
1731
1732
1733/**
1734 * Measure the TSC-delta for the specified CPU.
1735 *
1736 * @returns VBox status code.
1737 * @param idCpu The CPU to measure the TSC-delta for.
1738 * @param fAsync Whether the measurement is asynchronous, returns
1739 * immediately after signalling a measurement
1740 * request.
1741 * @param fForce Whether to perform a measurement even if the
1742 * specified CPU has a (possibly) valid TSC delta.
1743 * @param cRetries Number of times to retry failed delta
1744 * measurements.
1745 * @param cMsWaitRetry Number of milliseconds to wait between retries.
1746 */
1747SUPR3DECL(int) SUPR3TscDeltaMeasure(RTCPUID idCpu, bool fAsync, bool fForce, uint8_t cRetries, uint8_t cMsWaitRetry);
1748
1749/**
1750 * Reads the delta-adjust TSC value.
1751 *
1752 * @returns VBox status code.
1753 * @param puTsc Where to store the read TSC value.
1754 * @param pidApic Where to store the APIC ID of the CPU where the TSC
1755 * was read (optional, can be NULL).
1756 */
1757SUPR3DECL(int) SUPR3ReadTsc(uint64_t *puTsc, uint16_t *pidApic);
1758
1759/** @} */
1760#endif /* IN_RING3 */
1761
1762
1763/** @name User mode module flags (SUPR3TracerRegisterModule & SUP_IOCTL_TRACER_UMOD_REG).
1764 * @{ */
1765/** Executable image. */
1766#define SUP_TRACER_UMOD_FLAGS_EXE UINT32_C(1)
1767/** Shared library (DLL, DYLIB, SO, etc). */
1768#define SUP_TRACER_UMOD_FLAGS_SHARED UINT32_C(2)
1769/** Image type mask. */
1770#define SUP_TRACER_UMOD_FLAGS_TYPE_MASK UINT32_C(3)
1771/** @} */
1772
1773
1774#ifdef IN_RING0
1775/** @defgroup grp_sup_r0 SUP Host Context Ring-0 API
1776 * @{
1777 */
1778
1779/**
1780 * Security objectype.
1781 */
1782typedef enum SUPDRVOBJTYPE
1783{
1784 /** The usual invalid object. */
1785 SUPDRVOBJTYPE_INVALID = 0,
1786 /** A Virtual Machine instance. */
1787 SUPDRVOBJTYPE_VM,
1788 /** Internal network. */
1789 SUPDRVOBJTYPE_INTERNAL_NETWORK,
1790 /** Internal network interface. */
1791 SUPDRVOBJTYPE_INTERNAL_NETWORK_INTERFACE,
1792 /** Single release event semaphore. */
1793 SUPDRVOBJTYPE_SEM_EVENT,
1794 /** Multiple release event semaphore. */
1795 SUPDRVOBJTYPE_SEM_EVENT_MULTI,
1796 /** Raw PCI device. */
1797 SUPDRVOBJTYPE_RAW_PCI_DEVICE,
1798 /** The first invalid object type in this end. */
1799 SUPDRVOBJTYPE_END,
1800 /** The usual 32-bit type size hack. */
1801 SUPDRVOBJTYPE_32_BIT_HACK = 0x7ffffff
1802} SUPDRVOBJTYPE;
1803
1804/**
1805 * Object destructor callback.
1806 * This is called for reference counted objectes when the count reaches 0.
1807 *
1808 * @param pvObj The object pointer.
1809 * @param pvUser1 The first user argument.
1810 * @param pvUser2 The second user argument.
1811 */
1812typedef DECLCALLBACK(void) FNSUPDRVDESTRUCTOR(void *pvObj, void *pvUser1, void *pvUser2);
1813/** Pointer to a FNSUPDRVDESTRUCTOR(). */
1814typedef FNSUPDRVDESTRUCTOR *PFNSUPDRVDESTRUCTOR;
1815
1816SUPR0DECL(void *) SUPR0ObjRegister(PSUPDRVSESSION pSession, SUPDRVOBJTYPE enmType, PFNSUPDRVDESTRUCTOR pfnDestructor, void *pvUser1, void *pvUser2);
1817SUPR0DECL(int) SUPR0ObjAddRef(void *pvObj, PSUPDRVSESSION pSession);
1818SUPR0DECL(int) SUPR0ObjAddRefEx(void *pvObj, PSUPDRVSESSION pSession, bool fNoBlocking);
1819SUPR0DECL(int) SUPR0ObjRelease(void *pvObj, PSUPDRVSESSION pSession);
1820SUPR0DECL(int) SUPR0ObjVerifyAccess(void *pvObj, PSUPDRVSESSION pSession, const char *pszObjName);
1821
1822SUPR0DECL(int) SUPR0LockMem(PSUPDRVSESSION pSession, RTR3PTR pvR3, uint32_t cPages, PRTHCPHYS paPages);
1823SUPR0DECL(int) SUPR0UnlockMem(PSUPDRVSESSION pSession, RTR3PTR pvR3);
1824SUPR0DECL(int) SUPR0ContAlloc(PSUPDRVSESSION pSession, uint32_t cPages, PRTR0PTR ppvR0, PRTR3PTR ppvR3, PRTHCPHYS pHCPhys);
1825SUPR0DECL(int) SUPR0ContFree(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr);
1826SUPR0DECL(int) SUPR0LowAlloc(PSUPDRVSESSION pSession, uint32_t cPages, PRTR0PTR ppvR0, PRTR3PTR ppvR3, PRTHCPHYS paPages);
1827SUPR0DECL(int) SUPR0LowFree(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr);
1828SUPR0DECL(int) SUPR0MemAlloc(PSUPDRVSESSION pSession, uint32_t cb, PRTR0PTR ppvR0, PRTR3PTR ppvR3);
1829SUPR0DECL(int) SUPR0MemGetPhys(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr, PSUPPAGE paPages);
1830SUPR0DECL(int) SUPR0MemFree(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr);
1831SUPR0DECL(int) SUPR0PageAllocEx(PSUPDRVSESSION pSession, uint32_t cPages, uint32_t fFlags, PRTR3PTR ppvR3, PRTR0PTR ppvR0, PRTHCPHYS paPages);
1832SUPR0DECL(int) SUPR0PageMapKernel(PSUPDRVSESSION pSession, RTR3PTR pvR3, uint32_t offSub, uint32_t cbSub, uint32_t fFlags, PRTR0PTR ppvR0);
1833SUPR0DECL(int) SUPR0PageProtect(PSUPDRVSESSION pSession, RTR3PTR pvR3, RTR0PTR pvR0, uint32_t offSub, uint32_t cbSub, uint32_t fProt);
1834SUPR0DECL(int) SUPR0PageFree(PSUPDRVSESSION pSession, RTR3PTR pvR3);
1835SUPR0DECL(int) SUPR0GipMap(PSUPDRVSESSION pSession, PRTR3PTR ppGipR3, PRTHCPHYS pHCPhysGip);
1836SUPR0DECL(int) SUPR0GetSvmUsability(bool fInitSvm);
1837SUPR0DECL(int) SUPR0GetVmxUsability(bool *pfIsSmxModeAmbiguous);
1838SUPR0DECL(int) SUPR0QueryVTCaps(PSUPDRVSESSION pSession, uint32_t *pfCaps);
1839SUPR0DECL(int) SUPR0GipUnmap(PSUPDRVSESSION pSession);
1840SUPR0DECL(int) SUPR0Printf(const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
1841SUPR0DECL(SUPPAGINGMODE) SUPR0GetPagingMode(void);
1842SUPR0DECL(uint32_t) SUPR0GetKernelFeatures(void);
1843SUPR0DECL(RTCCUINTREG) SUPR0ChangeCR4(RTCCUINTREG fOrMask, RTCCUINTREG fAndMask);
1844SUPR0DECL(int) SUPR0EnableVTx(bool fEnable);
1845SUPR0DECL(bool) SUPR0SuspendVTxOnCpu(void);
1846SUPR0DECL(void) SUPR0ResumeVTxOnCpu(bool fSuspended);
1847#define SUP_TSCDELTA_MEASURE_F_FORCE RT_BIT_32(0)
1848#define SUP_TSCDELTA_MEASURE_F_ASYNC RT_BIT_32(1)
1849#define SUP_TSCDELTA_MEASURE_F_VALID_MASK UINT32_C(0x00000003)
1850SUPR0DECL(int) SUPR0TscDeltaMeasureBySetIndex(PSUPDRVSESSION pSession, uint32_t iCpuSet, uint32_t fFlags,
1851 RTMSINTERVAL cMsWaitRetry, RTMSINTERVAL cMsWaitThread, uint32_t cTries);
1852
1853/** @name Absolute symbols
1854 * Take the address of these, don't try call them.
1855 * @{ */
1856SUPR0DECL(void) SUPR0AbsIs64bit(void);
1857SUPR0DECL(void) SUPR0Abs64bitKernelCS(void);
1858SUPR0DECL(void) SUPR0Abs64bitKernelSS(void);
1859SUPR0DECL(void) SUPR0Abs64bitKernelDS(void);
1860SUPR0DECL(void) SUPR0AbsKernelCS(void);
1861SUPR0DECL(void) SUPR0AbsKernelSS(void);
1862SUPR0DECL(void) SUPR0AbsKernelDS(void);
1863SUPR0DECL(void) SUPR0AbsKernelES(void);
1864SUPR0DECL(void) SUPR0AbsKernelFS(void);
1865SUPR0DECL(void) SUPR0AbsKernelGS(void);
1866/** @} */
1867
1868/**
1869 * Support driver component factory.
1870 *
1871 * Component factories are registered by drivers that provides services
1872 * such as the host network interface filtering and access to the host
1873 * TCP/IP stack.
1874 *
1875 * @remark Module dependencies and making sure that a component doesn't
1876 * get unloaded while in use, is the sole responsibility of the
1877 * driver/kext/whatever implementing the component.
1878 */
1879typedef struct SUPDRVFACTORY
1880{
1881 /** The (unique) name of the component factory. */
1882 char szName[56];
1883 /**
1884 * Queries a factory interface.
1885 *
1886 * The factory interface is specific to each component and will be be
1887 * found in the header(s) for the component alongside its UUID.
1888 *
1889 * @returns Pointer to the factory interfaces on success, NULL on failure.
1890 *
1891 * @param pSupDrvFactory Pointer to this structure.
1892 * @param pSession The SUPDRV session making the query.
1893 * @param pszInterfaceUuid The UUID of the factory interface.
1894 */
1895 DECLR0CALLBACKMEMBER(void *, pfnQueryFactoryInterface,(struct SUPDRVFACTORY const *pSupDrvFactory, PSUPDRVSESSION pSession, const char *pszInterfaceUuid));
1896} SUPDRVFACTORY;
1897/** Pointer to a support driver factory. */
1898typedef SUPDRVFACTORY *PSUPDRVFACTORY;
1899/** Pointer to a const support driver factory. */
1900typedef SUPDRVFACTORY const *PCSUPDRVFACTORY;
1901
1902SUPR0DECL(int) SUPR0ComponentRegisterFactory(PSUPDRVSESSION pSession, PCSUPDRVFACTORY pFactory);
1903SUPR0DECL(int) SUPR0ComponentDeregisterFactory(PSUPDRVSESSION pSession, PCSUPDRVFACTORY pFactory);
1904SUPR0DECL(int) SUPR0ComponentQueryFactory(PSUPDRVSESSION pSession, const char *pszName, const char *pszInterfaceUuid, void **ppvFactoryIf);
1905
1906
1907/** @name Tracing
1908 * @{ */
1909
1910/**
1911 * Tracer data associated with a provider.
1912 */
1913typedef union SUPDRVTRACERDATA
1914{
1915 /** Generic */
1916 uint64_t au64[2];
1917
1918 /** DTrace data. */
1919 struct
1920 {
1921 /** Provider ID. */
1922 uintptr_t idProvider;
1923 /** The number of trace points provided. */
1924 uint32_t volatile cProvidedProbes;
1925 /** Whether we've invalidated this bugger. */
1926 bool fZombie;
1927 } DTrace;
1928} SUPDRVTRACERDATA;
1929/** Pointer to the tracer data associated with a provider. */
1930typedef SUPDRVTRACERDATA *PSUPDRVTRACERDATA;
1931
1932/**
1933 * Probe location info for ring-0.
1934 *
1935 * Since we cannot trust user tracepoint modules, we need to duplicate the probe
1936 * ID and enabled flag in ring-0.
1937 */
1938typedef struct SUPDRVPROBELOC
1939{
1940 /** The probe ID. */
1941 uint32_t idProbe;
1942 /** Whether it's enabled or not. */
1943 bool fEnabled;
1944} SUPDRVPROBELOC;
1945/** Pointer to a ring-0 probe location record. */
1946typedef SUPDRVPROBELOC *PSUPDRVPROBELOC;
1947
1948/**
1949 * Probe info for ring-0.
1950 *
1951 * Since we cannot trust user tracepoint modules, we need to duplicate the
1952 * probe enable count.
1953 */
1954typedef struct SUPDRVPROBEINFO
1955{
1956 /** The number of times this probe has been enabled. */
1957 uint32_t volatile cEnabled;
1958} SUPDRVPROBEINFO;
1959/** Pointer to a ring-0 probe info record. */
1960typedef SUPDRVPROBEINFO *PSUPDRVPROBEINFO;
1961
1962/**
1963 * Support driver tracepoint provider core.
1964 */
1965typedef struct SUPDRVVDTPROVIDERCORE
1966{
1967 /** The tracer data member. */
1968 SUPDRVTRACERDATA TracerData;
1969 /** Pointer to the provider name (a copy that's always available). */
1970 const char *pszName;
1971 /** Pointer to the module name (a copy that's always available). */
1972 const char *pszModName;
1973
1974 /** The provider descriptor. */
1975 struct VTGDESCPROVIDER *pDesc;
1976 /** The VTG header. */
1977 struct VTGOBJHDR *pHdr;
1978
1979 /** The size of the entries in the pvProbeLocsEn table. */
1980 uint8_t cbProbeLocsEn;
1981 /** The actual module bit count (corresponds to cbProbeLocsEn). */
1982 uint8_t cBits;
1983 /** Set if this is a Umod, otherwise clear.. */
1984 bool fUmod;
1985 /** Explicit alignment padding (paranoia). */
1986 uint8_t abAlignment[ARCH_BITS == 32 ? 1 : 5];
1987
1988 /** The probe locations used for descriptive purposes. */
1989 struct VTGPROBELOC const *paProbeLocsRO;
1990 /** Pointer to the probe location array where the enable flag needs
1991 * flipping. For kernel providers, this will always be SUPDRVPROBELOC,
1992 * while user providers can either be 32-bit or 64-bit. Use
1993 * cbProbeLocsEn to calculate the address of an entry. */
1994 void *pvProbeLocsEn;
1995 /** Pointer to the probe array containing the enabled counts. */
1996 uint32_t *pacProbeEnabled;
1997
1998 /** The ring-0 probe location info for user tracepoint modules.
1999 * This is NULL if fUmod is false. */
2000 PSUPDRVPROBELOC paR0ProbeLocs;
2001 /** The ring-0 probe info for user tracepoint modules.
2002 * This is NULL if fUmod is false. */
2003 PSUPDRVPROBEINFO paR0Probes;
2004
2005} SUPDRVVDTPROVIDERCORE;
2006/** Pointer to a tracepoint provider core structure. */
2007typedef SUPDRVVDTPROVIDERCORE *PSUPDRVVDTPROVIDERCORE;
2008
2009/** Pointer to a tracer registration record. */
2010typedef struct SUPDRVTRACERREG const *PCSUPDRVTRACERREG;
2011/**
2012 * Support driver tracer registration record.
2013 */
2014typedef struct SUPDRVTRACERREG
2015{
2016 /** Magic value (SUPDRVTRACERREG_MAGIC). */
2017 uint32_t u32Magic;
2018 /** Version (SUPDRVTRACERREG_VERSION). */
2019 uint32_t u32Version;
2020
2021 /**
2022 * Fire off a kernel probe.
2023 *
2024 * @param pVtgProbeLoc The probe location record.
2025 * @param uArg0 The first raw probe argument.
2026 * @param uArg1 The second raw probe argument.
2027 * @param uArg2 The third raw probe argument.
2028 * @param uArg3 The fourth raw probe argument.
2029 * @param uArg4 The fifth raw probe argument.
2030 *
2031 * @remarks SUPR0TracerFireProbe will do a tail jump thru this member, so
2032 * no extra stack frames will be added.
2033 * @remarks This does not take a 'this' pointer argument because it doesn't map
2034 * well onto VTG or DTrace.
2035 *
2036 */
2037 DECLR0CALLBACKMEMBER(void, pfnProbeFireKernel, (struct VTGPROBELOC *pVtgProbeLoc, uintptr_t uArg0, uintptr_t uArg1, uintptr_t uArg2,
2038 uintptr_t uArg3, uintptr_t uArg4));
2039
2040 /**
2041 * Fire off a user-mode probe.
2042 *
2043 * @param pThis Pointer to the registration record.
2044 *
2045 * @param pVtgProbeLoc The probe location record.
2046 * @param pSession The user session.
2047 * @param pCtx The usermode context info.
2048 * @param pVtgHdr The VTG header (read-only).
2049 * @param pProbeLocRO The read-only probe location record .
2050 */
2051 DECLR0CALLBACKMEMBER(void, pfnProbeFireUser, (PCSUPDRVTRACERREG pThis, PSUPDRVSESSION pSession, PCSUPDRVTRACERUSRCTX pCtx,
2052 struct VTGOBJHDR const *pVtgHdr, struct VTGPROBELOC const *pProbeLocRO));
2053
2054 /**
2055 * Opens up the tracer.
2056 *
2057 * @returns VBox status code.
2058 * @param pThis Pointer to the registration record.
2059 * @param pSession The session doing the opening.
2060 * @param uCookie A cookie (magic) unique to the tracer, so it can
2061 * fend off incompatible clients.
2062 * @param uArg Tracer specific argument.
2063 * @param puSessionData Pointer to the session data variable. This must be
2064 * set to a non-zero value on success.
2065 */
2066 DECLR0CALLBACKMEMBER(int, pfnTracerOpen, (PCSUPDRVTRACERREG pThis, PSUPDRVSESSION pSession, uint32_t uCookie, uintptr_t uArg,
2067 uintptr_t *puSessionData));
2068
2069 /**
2070 * I/O control style tracer communication method.
2071 *
2072 *
2073 * @returns VBox status code.
2074 * @param pThis Pointer to the registration record.
2075 * @param pSession The session.
2076 * @param uSessionData The session data value.
2077 * @param uCmd The tracer specific command.
2078 * @param uArg The tracer command specific argument.
2079 * @param piRetVal The tracer specific return value.
2080 */
2081 DECLR0CALLBACKMEMBER(int, pfnTracerIoCtl, (PCSUPDRVTRACERREG pThis, PSUPDRVSESSION pSession, uintptr_t uSessionData,
2082 uintptr_t uCmd, uintptr_t uArg, int32_t *piRetVal));
2083
2084 /**
2085 * Cleans up data the tracer has associated with a session.
2086 *
2087 * @param pThis Pointer to the registration record.
2088 * @param pSession The session handle.
2089 * @param uSessionData The data assoicated with the session.
2090 */
2091 DECLR0CALLBACKMEMBER(void, pfnTracerClose, (PCSUPDRVTRACERREG pThis, PSUPDRVSESSION pSession, uintptr_t uSessionData));
2092
2093 /**
2094 * Registers a provider.
2095 *
2096 * @returns VBox status code.
2097 * @param pThis Pointer to the registration record.
2098 * @param pCore The provider core data.
2099 *
2100 * @todo Kernel vs. Userland providers.
2101 */
2102 DECLR0CALLBACKMEMBER(int, pfnProviderRegister, (PCSUPDRVTRACERREG pThis, PSUPDRVVDTPROVIDERCORE pCore));
2103
2104 /**
2105 * Attempts to deregisters a provider.
2106 *
2107 * @returns VINF_SUCCESS or VERR_TRY_AGAIN. If the latter, the provider
2108 * should be made as harmless as possible before returning as the
2109 * VTG object and associated code will be unloaded upon return.
2110 *
2111 * @param pThis Pointer to the registration record.
2112 * @param pCore The provider core data.
2113 */
2114 DECLR0CALLBACKMEMBER(int, pfnProviderDeregister, (PCSUPDRVTRACERREG pThis, PSUPDRVVDTPROVIDERCORE pCore));
2115
2116 /**
2117 * Make another attempt at unregister a busy provider.
2118 *
2119 * @returns VINF_SUCCESS or VERR_TRY_AGAIN.
2120 * @param pThis Pointer to the registration record.
2121 * @param pCore The provider core data.
2122 */
2123 DECLR0CALLBACKMEMBER(int, pfnProviderDeregisterZombie, (PCSUPDRVTRACERREG pThis, PSUPDRVVDTPROVIDERCORE pCore));
2124
2125 /** End marker (SUPDRVTRACERREG_MAGIC). */
2126 uintptr_t uEndMagic;
2127} SUPDRVTRACERREG;
2128
2129/** Tracer magic (Kenny Garrett). */
2130#define SUPDRVTRACERREG_MAGIC UINT32_C(0x19601009)
2131/** Tracer registration structure version. */
2132#define SUPDRVTRACERREG_VERSION RT_MAKE_U32(0, 1)
2133
2134/** Pointer to a trace helper structure. */
2135typedef struct SUPDRVTRACERHLP const *PCSUPDRVTRACERHLP;
2136/**
2137 * Helper structure.
2138 */
2139typedef struct SUPDRVTRACERHLP
2140{
2141 /** The structure version (SUPDRVTRACERHLP_VERSION). */
2142 uintptr_t uVersion;
2143
2144 /** @todo ... */
2145
2146 /** End marker (SUPDRVTRACERHLP_VERSION) */
2147 uintptr_t uEndVersion;
2148} SUPDRVTRACERHLP;
2149/** Tracer helper structure version. */
2150#define SUPDRVTRACERHLP_VERSION RT_MAKE_U32(0, 1)
2151
2152SUPR0DECL(int) SUPR0TracerRegisterImpl(void *hMod, PSUPDRVSESSION pSession, PCSUPDRVTRACERREG pReg, PCSUPDRVTRACERHLP *ppHlp);
2153SUPR0DECL(int) SUPR0TracerDeregisterImpl(void *hMod, PSUPDRVSESSION pSession);
2154SUPR0DECL(int) SUPR0TracerRegisterDrv(PSUPDRVSESSION pSession, struct VTGOBJHDR *pVtgHdr, const char *pszName);
2155SUPR0DECL(void) SUPR0TracerDeregisterDrv(PSUPDRVSESSION pSession);
2156SUPR0DECL(int) SUPR0TracerRegisterModule(void *hMod, struct VTGOBJHDR *pVtgHdr);
2157SUPR0DECL(void) SUPR0TracerFireProbe(struct VTGPROBELOC *pVtgProbeLoc, uintptr_t uArg0, uintptr_t uArg1, uintptr_t uArg2,
2158 uintptr_t uArg3, uintptr_t uArg4);
2159SUPR0DECL(void) SUPR0TracerUmodProbeFire(PSUPDRVSESSION pSession, PSUPDRVTRACERUSRCTX pCtx);
2160/** @} */
2161
2162
2163/**
2164 * Service request callback function.
2165 *
2166 * @returns VBox status code.
2167 * @param pSession The caller's session.
2168 * @param u64Arg 64-bit integer argument.
2169 * @param pReqHdr The request header. Input / Output. Optional.
2170 */
2171typedef DECLCALLBACK(int) FNSUPR0SERVICEREQHANDLER(PSUPDRVSESSION pSession, uint32_t uOperation,
2172 uint64_t u64Arg, PSUPR0SERVICEREQHDR pReqHdr);
2173/** Pointer to a FNR0SERVICEREQHANDLER(). */
2174typedef R0PTRTYPE(FNSUPR0SERVICEREQHANDLER *) PFNSUPR0SERVICEREQHANDLER;
2175
2176
2177/** @defgroup grp_sup_r0_idc The IDC Interface
2178 * @{
2179 */
2180
2181/** The current SUPDRV IDC version.
2182 * This follows the usual high word / low word rules, i.e. high word is the
2183 * major number and it signifies incompatible interface changes. */
2184#define SUPDRV_IDC_VERSION UINT32_C(0x00010000)
2185
2186/**
2187 * Inter-Driver Communication Handle.
2188 */
2189typedef union SUPDRVIDCHANDLE
2190{
2191 /** Padding for opaque usage.
2192 * Must be greater or equal in size than the private struct. */
2193 void *apvPadding[4];
2194#ifdef SUPDRVIDCHANDLEPRIVATE_DECLARED
2195 /** The private view. */
2196 struct SUPDRVIDCHANDLEPRIVATE s;
2197#endif
2198} SUPDRVIDCHANDLE;
2199/** Pointer to a handle. */
2200typedef SUPDRVIDCHANDLE *PSUPDRVIDCHANDLE;
2201
2202SUPR0DECL(int) SUPR0IdcOpen(PSUPDRVIDCHANDLE pHandle, uint32_t uReqVersion, uint32_t uMinVersion,
2203 uint32_t *puSessionVersion, uint32_t *puDriverVersion, uint32_t *puDriverRevision);
2204SUPR0DECL(int) SUPR0IdcCall(PSUPDRVIDCHANDLE pHandle, uint32_t iReq, void *pvReq, uint32_t cbReq);
2205SUPR0DECL(int) SUPR0IdcClose(PSUPDRVIDCHANDLE pHandle);
2206SUPR0DECL(PSUPDRVSESSION) SUPR0IdcGetSession(PSUPDRVIDCHANDLE pHandle);
2207SUPR0DECL(int) SUPR0IdcComponentRegisterFactory(PSUPDRVIDCHANDLE pHandle, PCSUPDRVFACTORY pFactory);
2208SUPR0DECL(int) SUPR0IdcComponentDeregisterFactory(PSUPDRVIDCHANDLE pHandle, PCSUPDRVFACTORY pFactory);
2209
2210/** @} */
2211
2212/** @name Ring-0 module entry points.
2213 *
2214 * These can be exported by ring-0 modules SUP are told to load.
2215 *
2216 * @{ */
2217DECLEXPORT(int) ModuleInit(void *hMod);
2218DECLEXPORT(void) ModuleTerm(void *hMod);
2219/** @} */
2220
2221
2222/** @} */
2223#endif
2224
2225
2226/** @name Trust Anchors and Certificates
2227 * @{ */
2228
2229/**
2230 * Trust anchor table entry (in generated Certificates.cpp).
2231 */
2232typedef struct SUPTAENTRY
2233{
2234 /** Pointer to the raw bytes. */
2235 const unsigned char *pch;
2236 /** Number of bytes. */
2237 unsigned cb;
2238} SUPTAENTRY;
2239/** Pointer to a trust anchor table entry. */
2240typedef SUPTAENTRY const *PCSUPTAENTRY;
2241
2242/** Macro for simplifying generating the trust anchor tables. */
2243#define SUPTAENTRY_GEN(a_abTA) { &a_abTA[0], sizeof(a_abTA) }
2244
2245/** All certificates we know. */
2246extern SUPTAENTRY const g_aSUPAllTAs[];
2247/** Number of entries in g_aSUPAllTAs. */
2248extern unsigned const g_cSUPAllTAs;
2249
2250/** Software publisher certificate roots (Authenticode). */
2251extern SUPTAENTRY const g_aSUPSpcRootTAs[];
2252/** Number of entries in g_aSUPSpcRootTAs. */
2253extern unsigned const g_cSUPSpcRootTAs;
2254
2255/** Kernel root certificates used by Windows. */
2256extern SUPTAENTRY const g_aSUPNtKernelRootTAs[];
2257/** Number of entries in g_aSUPNtKernelRootTAs. */
2258extern unsigned const g_cSUPNtKernelRootTAs;
2259
2260/** Timestamp root certificates trusted by Windows. */
2261extern SUPTAENTRY const g_aSUPTimestampTAs[];
2262/** Number of entries in g_aSUPTimestampTAs. */
2263extern unsigned const g_cSUPTimestampTAs;
2264
2265/** TAs we trust (the build certificate, Oracle VirtualBox). */
2266extern SUPTAENTRY const g_aSUPTrustedTAs[];
2267/** Number of entries in g_aSUPTrustedTAs. */
2268extern unsigned const g_cSUPTrustedTAs;
2269
2270/** Supplemental certificates, like cross signing certificates. */
2271extern SUPTAENTRY const g_aSUPSupplementalTAs[];
2272/** Number of entries in g_aSUPTrustedTAs. */
2273extern unsigned const g_cSUPSupplementalTAs;
2274
2275/** The build certificate. */
2276extern const unsigned char g_abSUPBuildCert[];
2277/** The size of the build certificate. */
2278extern const unsigned g_cbSUPBuildCert;
2279
2280/** @} */
2281
2282
2283/** @} */
2284
2285RT_C_DECLS_END
2286
2287#endif
2288
Note: See TracBrowser for help on using the repository browser.

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