VirtualBox

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

Last change on this file since 67107 was 64364, checked in by vboxsync, 8 years ago

sup.h: Doxygen

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