VirtualBox

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

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

VBox/sup.h: Don't include VBox/err.h for no good reason. bugref:9344

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