VirtualBox

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

Last change on this file since 73768 was 73362, checked in by vboxsync, 6 years ago

sup.h: nit.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use