VirtualBox

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

Last change on this file since 71136 was 71136, checked in by vboxsync, 7 years ago

SUPDrv,VMM/NEM/win: Abstracted kernel I/O control work in SUPDrv, currently only implemented & needed on windows. Made first I/O control call to VID from ring-0. bugref:9044

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 89.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 <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/** @} */
813
814/** SUPR3QueryVTCaps capability flags
815 * @{
816 */
817/** AMD-V support. */
818#define SUPVTCAPS_AMD_V RT_BIT(0)
819/** VT-x support. */
820#define SUPVTCAPS_VT_X RT_BIT(1)
821/** Nested paging is supported. */
822#define SUPVTCAPS_NESTED_PAGING RT_BIT(2)
823/** VT-x: Unrestricted guest execution is supported. */
824#define SUPVTCAPS_VTX_UNRESTRICTED_GUEST RT_BIT(3)
825/** @} */
826
827/**
828 * Request for generic FNSUPR0SERVICEREQHANDLER calls.
829 */
830typedef struct SUPR0SERVICEREQHDR
831{
832 /** The magic. (SUPR0SERVICEREQHDR_MAGIC) */
833 uint32_t u32Magic;
834 /** The size of the request. */
835 uint32_t cbReq;
836} SUPR0SERVICEREQHDR;
837/** Pointer to a ring-0 service request header. */
838typedef SUPR0SERVICEREQHDR *PSUPR0SERVICEREQHDR;
839/** the SUPVMMR0REQHDR::u32Magic value (Esbjoern Svensson - E.S.P.). */
840#define SUPR0SERVICEREQHDR_MAGIC UINT32_C(0x19640416)
841
842
843/**
844 * Creates a single release event semaphore.
845 *
846 * @returns VBox status code.
847 * @param pSession The session handle of the caller.
848 * @param phEvent Where to return the handle to the event semaphore.
849 */
850SUPDECL(int) SUPSemEventCreate(PSUPDRVSESSION pSession, PSUPSEMEVENT phEvent);
851
852/**
853 * Closes a single release event semaphore handle.
854 *
855 * @returns VBox status code.
856 * @retval VINF_OBJECT_DESTROYED if the semaphore was destroyed.
857 * @retval VINF_SUCCESS if the handle was successfully closed but the semaphore
858 * object remained alive because of other references.
859 *
860 * @param pSession The session handle of the caller.
861 * @param hEvent The handle. Nil is quietly ignored.
862 */
863SUPDECL(int) SUPSemEventClose(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent);
864
865/**
866 * Signals a single release event semaphore.
867 *
868 * @returns VBox status code.
869 * @param pSession The session handle of the caller.
870 * @param hEvent The semaphore handle.
871 */
872SUPDECL(int) SUPSemEventSignal(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent);
873
874#ifdef IN_RING0
875/**
876 * Waits on a single release event semaphore, not interruptible.
877 *
878 * @returns VBox status code.
879 * @param pSession The session handle of the caller.
880 * @param hEvent The semaphore handle.
881 * @param cMillies The number of milliseconds to wait.
882 * @remarks Not available in ring-3.
883 */
884SUPDECL(int) SUPSemEventWait(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent, uint32_t cMillies);
885#endif
886
887/**
888 * Waits on a single release event semaphore, interruptible.
889 *
890 * @returns VBox status code.
891 * @param pSession The session handle of the caller.
892 * @param hEvent The semaphore handle.
893 * @param cMillies The number of milliseconds to wait.
894 */
895SUPDECL(int) SUPSemEventWaitNoResume(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent, uint32_t cMillies);
896
897/**
898 * Waits on a single release event semaphore, interruptible.
899 *
900 * @returns VBox status code.
901 * @param pSession The session handle of the caller.
902 * @param hEvent The semaphore handle.
903 * @param uNsTimeout The deadline given on the RTTimeNanoTS() clock.
904 */
905SUPDECL(int) SUPSemEventWaitNsAbsIntr(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent, uint64_t uNsTimeout);
906
907/**
908 * Waits on a single release event semaphore, interruptible.
909 *
910 * @returns VBox status code.
911 * @param pSession The session handle of the caller.
912 * @param hEvent The semaphore handle.
913 * @param cNsTimeout The number of nanoseconds to wait.
914 */
915SUPDECL(int) SUPSemEventWaitNsRelIntr(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent, uint64_t cNsTimeout);
916
917/**
918 * Gets the best timeout resolution that SUPSemEventWaitNsAbsIntr and
919 * SUPSemEventWaitNsAbsIntr can do.
920 *
921 * @returns The resolution in nanoseconds.
922 * @param pSession The session handle of the caller.
923 */
924SUPDECL(uint32_t) SUPSemEventGetResolution(PSUPDRVSESSION pSession);
925
926
927/**
928 * Creates a multiple release event semaphore.
929 *
930 * @returns VBox status code.
931 * @param pSession The session handle of the caller.
932 * @param phEventMulti Where to return the handle to the event semaphore.
933 */
934SUPDECL(int) SUPSemEventMultiCreate(PSUPDRVSESSION pSession, PSUPSEMEVENTMULTI phEventMulti);
935
936/**
937 * Closes a multiple release event semaphore handle.
938 *
939 * @returns VBox status code.
940 * @retval VINF_OBJECT_DESTROYED if the semaphore was destroyed.
941 * @retval VINF_SUCCESS if the handle was successfully closed but the semaphore
942 * object remained alive because of other references.
943 *
944 * @param pSession The session handle of the caller.
945 * @param hEventMulti The handle. Nil is quietly ignored.
946 */
947SUPDECL(int) SUPSemEventMultiClose(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti);
948
949/**
950 * Signals a multiple release event semaphore.
951 *
952 * @returns VBox status code.
953 * @param pSession The session handle of the caller.
954 * @param hEventMulti The semaphore handle.
955 */
956SUPDECL(int) SUPSemEventMultiSignal(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti);
957
958/**
959 * Resets a multiple release event semaphore.
960 *
961 * @returns VBox status code.
962 * @param pSession The session handle of the caller.
963 * @param hEventMulti The semaphore handle.
964 */
965SUPDECL(int) SUPSemEventMultiReset(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti);
966
967#ifdef IN_RING0
968/**
969 * Waits on a multiple release event semaphore, not interruptible.
970 *
971 * @returns VBox status code.
972 * @param pSession The session handle of the caller.
973 * @param hEventMulti The semaphore handle.
974 * @param cMillies The number of milliseconds to wait.
975 * @remarks Not available in ring-3.
976 */
977SUPDECL(int) SUPSemEventMultiWait(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti, uint32_t cMillies);
978#endif
979
980/**
981 * Waits on a multiple release event semaphore, interruptible.
982 *
983 * @returns VBox status code.
984 * @param pSession The session handle of the caller.
985 * @param hEventMulti The semaphore handle.
986 * @param cMillies The number of milliseconds to wait.
987 */
988SUPDECL(int) SUPSemEventMultiWaitNoResume(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti, uint32_t cMillies);
989
990/**
991 * Waits on a multiple release event semaphore, interruptible.
992 *
993 * @returns VBox status code.
994 * @param pSession The session handle of the caller.
995 * @param hEventMulti The semaphore handle.
996 * @param uNsTimeout The deadline given on the RTTimeNanoTS() clock.
997 */
998SUPDECL(int) SUPSemEventMultiWaitNsAbsIntr(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti, uint64_t uNsTimeout);
999
1000/**
1001 * Waits on a multiple release event semaphore, interruptible.
1002 *
1003 * @returns VBox status code.
1004 * @param pSession The session handle of the caller.
1005 * @param hEventMulti The semaphore handle.
1006 * @param cNsTimeout The number of nanoseconds to wait.
1007 */
1008SUPDECL(int) SUPSemEventMultiWaitNsRelIntr(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti, uint64_t cNsTimeout);
1009
1010/**
1011 * Gets the best timeout resolution that SUPSemEventMultiWaitNsAbsIntr and
1012 * SUPSemEventMultiWaitNsRelIntr can do.
1013 *
1014 * @returns The resolution in nanoseconds.
1015 * @param pSession The session handle of the caller.
1016 */
1017SUPDECL(uint32_t) SUPSemEventMultiGetResolution(PSUPDRVSESSION pSession);
1018
1019
1020#ifdef IN_RING3
1021
1022/** @defgroup grp_sup_r3 SUP Host Context Ring-3 API
1023 * @{
1024 */
1025
1026/**
1027 * Installs the support library.
1028 *
1029 * @returns VBox status code.
1030 */
1031SUPR3DECL(int) SUPR3Install(void);
1032
1033/**
1034 * Uninstalls the support library.
1035 *
1036 * @returns VBox status code.
1037 */
1038SUPR3DECL(int) SUPR3Uninstall(void);
1039
1040/**
1041 * Trusted main entry point.
1042 *
1043 * This is exported as "TrustedMain" by the dynamic libraries which contains the
1044 * "real" application binary for which the hardened stub is built. The entry
1045 * point is invoked upon successful initialization of the support library and
1046 * runtime.
1047 *
1048 * @returns main kind of exit code.
1049 * @param argc The argument count.
1050 * @param argv The argument vector.
1051 * @param envp The environment vector.
1052 */
1053typedef DECLCALLBACK(int) FNSUPTRUSTEDMAIN(int argc, char **argv, char **envp);
1054/** Pointer to FNSUPTRUSTEDMAIN(). */
1055typedef FNSUPTRUSTEDMAIN *PFNSUPTRUSTEDMAIN;
1056
1057/** Which operation failed. */
1058typedef enum SUPINITOP
1059{
1060 /** Invalid. */
1061 kSupInitOp_Invalid = 0,
1062 /** Installation integrity error. */
1063 kSupInitOp_Integrity,
1064 /** Setuid related. */
1065 kSupInitOp_RootCheck,
1066 /** Driver related. */
1067 kSupInitOp_Driver,
1068 /** IPRT init related. */
1069 kSupInitOp_IPRT,
1070 /** Miscellaneous. */
1071 kSupInitOp_Misc,
1072 /** Place holder. */
1073 kSupInitOp_End
1074} SUPINITOP;
1075
1076/**
1077 * Trusted error entry point, optional.
1078 *
1079 * This is exported as "TrustedError" by the dynamic libraries which contains
1080 * the "real" application binary for which the hardened stub is built. The
1081 * hardened main() must specify SUPSECMAIN_FLAGS_TRUSTED_ERROR when calling
1082 * SUPR3HardenedMain.
1083 *
1084 * @param pszWhere Where the error occurred (function name).
1085 * @param enmWhat Which operation went wrong.
1086 * @param rc The status code.
1087 * @param pszMsgFmt Error message format string.
1088 * @param va The message format arguments.
1089 */
1090typedef DECLCALLBACK(void) FNSUPTRUSTEDERROR(const char *pszWhere, SUPINITOP enmWhat, int rc,
1091 const char *pszMsgFmt, va_list va) RT_IPRT_FORMAT_ATTR(4, 0);
1092/** Pointer to FNSUPTRUSTEDERROR. */
1093typedef FNSUPTRUSTEDERROR *PFNSUPTRUSTEDERROR;
1094
1095/**
1096 * Secure main.
1097 *
1098 * This is used for the set-user-ID-on-execute binaries on unixy systems
1099 * and when using the open-vboxdrv-via-root-service setup on Windows.
1100 *
1101 * This function will perform the integrity checks of the VirtualBox
1102 * installation, open the support driver, open the root service (later),
1103 * and load the DLL corresponding to \a pszProgName and execute its main
1104 * function.
1105 *
1106 * @returns Return code appropriate for main().
1107 *
1108 * @param pszProgName The program name. This will be used to figure out which
1109 * DLL/SO/DYLIB to load and execute.
1110 * @param fFlags Flags.
1111 * @param argc The argument count.
1112 * @param argv The argument vector.
1113 * @param envp The environment vector.
1114 */
1115DECLHIDDEN(int) SUPR3HardenedMain(const char *pszProgName, uint32_t fFlags, int argc, char **argv, char **envp);
1116
1117/** @name SUPR3HardenedMain flags.
1118 * @{ */
1119/** Don't open the device. (Intended for VirtualBox without -startvm.) */
1120#define SUPSECMAIN_FLAGS_DONT_OPEN_DEV RT_BIT_32(0)
1121/** The hardened DLL has a "TrustedError" function (see FNSUPTRUSTEDERROR). */
1122#define SUPSECMAIN_FLAGS_TRUSTED_ERROR RT_BIT_32(1)
1123/** Hack for making VirtualBoxVM use VirtualBox.dylib on Mac OS X. */
1124#define SUPSECMAIN_FLAGS_OSX_VM_APP RT_BIT_32(2)
1125/** Program binary location mask. */
1126#define SUPSECMAIN_FLAGS_LOC_MASK UINT32_C(0x00000010)
1127/** Default binary location is the application binary directory. Does
1128 * not need to be given explicitly (it's 0). */
1129#define SUPSECMAIN_FLAGS_LOC_APP_BIN UINT32_C(0x00000000)
1130/** The binary is located in the testcase directory instead of the
1131 * default application binary directory. */
1132#define SUPSECMAIN_FLAGS_LOC_TESTCASE UINT32_C(0x00000010)
1133/** @} */
1134
1135/**
1136 * Initializes the support library.
1137 *
1138 * Each successful call to SUPR3Init() or SUPR3InitEx must be countered by a
1139 * call to SUPR3Term(false).
1140 *
1141 * @returns VBox status code.
1142 * @param ppSession Where to store the session handle. Defaults to NULL.
1143 */
1144SUPR3DECL(int) SUPR3Init(PSUPDRVSESSION *ppSession);
1145
1146/**
1147 * Initializes the support library, extended version.
1148 *
1149 * Each successful call to SUPR3Init() or SUPR3InitEx must be countered by a
1150 * call to SUPR3Term(false).
1151 *
1152 * @returns VBox status code.
1153 * @param fUnrestricted The desired access.
1154 * @param ppSession Where to store the session handle. Defaults to NULL.
1155 */
1156SUPR3DECL(int) SUPR3InitEx(bool fUnrestricted, PSUPDRVSESSION *ppSession);
1157
1158/**
1159 * Terminates the support library.
1160 *
1161 * @returns VBox status code.
1162 * @param fForced Forced termination. This means to ignore the
1163 * init call count and just terminated.
1164 */
1165#ifdef __cplusplus
1166SUPR3DECL(int) SUPR3Term(bool fForced = false);
1167#else
1168SUPR3DECL(int) SUPR3Term(int fForced);
1169#endif
1170
1171/**
1172 * Sets the ring-0 VM handle for use with fast IOCtls.
1173 *
1174 * @returns VBox status code.
1175 * @param pVMR0 The ring-0 VM handle.
1176 * NIL_RTR0PTR can be used to unset the handle when the
1177 * VM is about to be destroyed.
1178 */
1179SUPR3DECL(int) SUPR3SetVMForFastIOCtl(PVMR0 pVMR0);
1180
1181/**
1182 * Calls the HC R0 VMM entry point.
1183 * See VMMR0Entry() for more details.
1184 *
1185 * @returns error code specific to uFunction.
1186 * @param pVMR0 Pointer to the Ring-0 (Host Context) mapping of the VM structure.
1187 * @param idCpu The virtual CPU ID.
1188 * @param uOperation Operation to execute.
1189 * @param pvArg Argument.
1190 */
1191SUPR3DECL(int) SUPR3CallVMMR0(PVMR0 pVMR0, VMCPUID idCpu, unsigned uOperation, void *pvArg);
1192
1193/**
1194 * Variant of SUPR3CallVMMR0, except that this takes the fast ioclt path
1195 * regardsless of compile-time defaults.
1196 *
1197 * @returns VBox status code.
1198 * @param pVMR0 The ring-0 VM handle.
1199 * @param uOperation The operation; only the SUP_VMMR0_DO_* ones are valid.
1200 * @param idCpu The virtual CPU ID.
1201 */
1202SUPR3DECL(int) SUPR3CallVMMR0Fast(PVMR0 pVMR0, unsigned uOperation, VMCPUID idCpu);
1203
1204/**
1205 * Calls the HC R0 VMM entry point, in a safer but slower manner than
1206 * SUPR3CallVMMR0. When entering using this call the R0 components can call
1207 * into the host kernel (i.e. use the SUPR0 and RT APIs).
1208 *
1209 * See VMMR0Entry() for more details.
1210 *
1211 * @returns error code specific to uFunction.
1212 * @param pVMR0 Pointer to the Ring-0 (Host Context) mapping of the VM structure.
1213 * @param idCpu The virtual CPU ID.
1214 * @param uOperation Operation to execute.
1215 * @param u64Arg Constant argument.
1216 * @param pReqHdr Pointer to a request header. Optional.
1217 * This will be copied in and out of kernel space. There currently is a size
1218 * limit on this, just below 4KB.
1219 */
1220SUPR3DECL(int) SUPR3CallVMMR0Ex(PVMR0 pVMR0, VMCPUID idCpu, unsigned uOperation, uint64_t u64Arg, PSUPVMMR0REQHDR pReqHdr);
1221
1222/**
1223 * Calls a ring-0 service.
1224 *
1225 * The operation and the request packet is specific to the service.
1226 *
1227 * @returns error code specific to uFunction.
1228 * @param pszService The service name.
1229 * @param cchService The length of the service name.
1230 * @param uOperation The request number.
1231 * @param u64Arg Constant argument.
1232 * @param pReqHdr Pointer to a request header. Optional.
1233 * This will be copied in and out of kernel space. There currently is a size
1234 * limit on this, just below 4KB.
1235 */
1236SUPR3DECL(int) SUPR3CallR0Service(const char *pszService, size_t cchService, uint32_t uOperation, uint64_t u64Arg, PSUPR0SERVICEREQHDR pReqHdr);
1237
1238/** Which logger. */
1239typedef enum SUPLOGGER
1240{
1241 SUPLOGGER_DEBUG = 1,
1242 SUPLOGGER_RELEASE
1243} SUPLOGGER;
1244
1245/**
1246 * Changes the settings of the specified ring-0 logger.
1247 *
1248 * @returns VBox status code.
1249 * @param enmWhich Which logger.
1250 * @param pszFlags The flags settings.
1251 * @param pszGroups The groups settings.
1252 * @param pszDest The destination specificier.
1253 */
1254SUPR3DECL(int) SUPR3LoggerSettings(SUPLOGGER enmWhich, const char *pszFlags, const char *pszGroups, const char *pszDest);
1255
1256/**
1257 * Creates a ring-0 logger instance.
1258 *
1259 * @returns VBox status code.
1260 * @param enmWhich Which logger to create.
1261 * @param pszFlags The flags settings.
1262 * @param pszGroups The groups settings.
1263 * @param pszDest The destination specificier.
1264 */
1265SUPR3DECL(int) SUPR3LoggerCreate(SUPLOGGER enmWhich, const char *pszFlags, const char *pszGroups, const char *pszDest);
1266
1267/**
1268 * Destroys a ring-0 logger instance.
1269 *
1270 * @returns VBox status code.
1271 * @param enmWhich Which logger.
1272 */
1273SUPR3DECL(int) SUPR3LoggerDestroy(SUPLOGGER enmWhich);
1274
1275/**
1276 * Queries the paging mode of the host OS.
1277 *
1278 * @returns The paging mode.
1279 */
1280SUPR3DECL(SUPPAGINGMODE) SUPR3GetPagingMode(void);
1281
1282/**
1283 * Allocate zero-filled pages.
1284 *
1285 * Use this to allocate a number of pages suitable for seeding / locking.
1286 * Call SUPR3PageFree() to free the pages once done with them.
1287 *
1288 * @returns VBox status.
1289 * @param cPages Number of pages to allocate.
1290 * @param ppvPages Where to store the base pointer to the allocated pages.
1291 */
1292SUPR3DECL(int) SUPR3PageAlloc(size_t cPages, void **ppvPages);
1293
1294/**
1295 * Frees pages allocated with SUPR3PageAlloc().
1296 *
1297 * @returns VBox status.
1298 * @param pvPages Pointer returned by SUPR3PageAlloc().
1299 * @param cPages Number of pages that was allocated.
1300 */
1301SUPR3DECL(int) SUPR3PageFree(void *pvPages, size_t cPages);
1302
1303/**
1304 * Allocate non-zeroed, locked, pages with user and, optionally, kernel
1305 * mappings.
1306 *
1307 * Use SUPR3PageFreeEx() to free memory allocated with this function.
1308 *
1309 * @returns VBox status code.
1310 * @param cPages The number of pages to allocate.
1311 * @param fFlags Flags, reserved. Must be zero.
1312 * @param ppvPages Where to store the address of the user mapping.
1313 * @param pR0Ptr Where to store the address of the kernel mapping.
1314 * NULL if no kernel mapping is desired.
1315 * @param paPages Where to store the physical addresses of each page.
1316 * Optional.
1317 */
1318SUPR3DECL(int) SUPR3PageAllocEx(size_t cPages, uint32_t fFlags, void **ppvPages, PRTR0PTR pR0Ptr, PSUPPAGE paPages);
1319
1320/**
1321 * Maps a portion of a ring-3 only allocation into kernel space.
1322 *
1323 * @returns VBox status code.
1324 *
1325 * @param pvR3 The address SUPR3PageAllocEx return.
1326 * @param off Offset to start mapping at. Must be page aligned.
1327 * @param cb Number of bytes to map. Must be page aligned.
1328 * @param fFlags Flags, must be zero.
1329 * @param pR0Ptr Where to store the address on success.
1330 *
1331 */
1332SUPR3DECL(int) SUPR3PageMapKernel(void *pvR3, uint32_t off, uint32_t cb, uint32_t fFlags, PRTR0PTR pR0Ptr);
1333
1334/**
1335 * Changes the protection of
1336 *
1337 * @returns VBox status code.
1338 * @retval VERR_NOT_SUPPORTED if the OS doesn't allow us to change page level
1339 * protection. See also RTR0MemObjProtect.
1340 *
1341 * @param pvR3 The ring-3 address SUPR3PageAllocEx returned.
1342 * @param R0Ptr The ring-0 address SUPR3PageAllocEx returned if it
1343 * is desired that the corresponding ring-0 page
1344 * mappings should change protection as well. Pass
1345 * NIL_RTR0PTR if the ring-0 pages should remain
1346 * unaffected.
1347 * @param off Offset to start at which to start chagning the page
1348 * level protection. Must be page aligned.
1349 * @param cb Number of bytes to change. Must be page aligned.
1350 * @param fProt The new page level protection, either a combination
1351 * of RTMEM_PROT_READ, RTMEM_PROT_WRITE and
1352 * RTMEM_PROT_EXEC, or just RTMEM_PROT_NONE.
1353 */
1354SUPR3DECL(int) SUPR3PageProtect(void *pvR3, RTR0PTR R0Ptr, uint32_t off, uint32_t cb, uint32_t fProt);
1355
1356/**
1357 * Free pages allocated by SUPR3PageAllocEx.
1358 *
1359 * @returns VBox status code.
1360 * @param pvPages The address of the user mapping.
1361 * @param cPages The number of pages.
1362 */
1363SUPR3DECL(int) SUPR3PageFreeEx(void *pvPages, size_t cPages);
1364
1365/**
1366 * Allocated memory with page aligned memory with a contiguous and locked physical
1367 * memory backing below 4GB.
1368 *
1369 * @returns Pointer to the allocated memory (virtual address).
1370 * *pHCPhys is set to the physical address of the memory.
1371 * If ppvR0 isn't NULL, *ppvR0 is set to the ring-0 mapping.
1372 * The returned memory must be freed using SUPR3ContFree().
1373 * @returns NULL on failure.
1374 * @param cPages Number of pages to allocate.
1375 * @param pR0Ptr Where to store the ring-0 mapping of the allocation. (optional)
1376 * @param pHCPhys Where to store the physical address of the memory block.
1377 *
1378 * @remark This 2nd version of this API exists because we're not able to map the
1379 * ring-3 mapping executable on WIN64. This is a serious problem in regard to
1380 * the world switchers.
1381 */
1382SUPR3DECL(void *) SUPR3ContAlloc(size_t cPages, PRTR0PTR pR0Ptr, PRTHCPHYS pHCPhys);
1383
1384/**
1385 * Frees memory allocated with SUPR3ContAlloc().
1386 *
1387 * @returns VBox status code.
1388 * @param pv Pointer to the memory block which should be freed.
1389 * @param cPages Number of pages to be freed.
1390 */
1391SUPR3DECL(int) SUPR3ContFree(void *pv, size_t cPages);
1392
1393/**
1394 * Allocated non contiguous physical memory below 4GB.
1395 *
1396 * The memory isn't zeroed.
1397 *
1398 * @returns VBox status code.
1399 * @returns NULL on failure.
1400 * @param cPages Number of pages to allocate.
1401 * @param ppvPages Where to store the pointer to the allocated memory.
1402 * The pointer stored here on success must be passed to
1403 * SUPR3LowFree when the memory should be released.
1404 * @param ppvPagesR0 Where to store the ring-0 pointer to the allocated memory. optional.
1405 * @param paPages Where to store the physical addresses of the individual pages.
1406 */
1407SUPR3DECL(int) SUPR3LowAlloc(size_t cPages, void **ppvPages, PRTR0PTR ppvPagesR0, PSUPPAGE paPages);
1408
1409/**
1410 * Frees memory allocated with SUPR3LowAlloc().
1411 *
1412 * @returns VBox status code.
1413 * @param pv Pointer to the memory block which should be freed.
1414 * @param cPages Number of pages that was allocated.
1415 */
1416SUPR3DECL(int) SUPR3LowFree(void *pv, size_t cPages);
1417
1418/**
1419 * Load a module into R0 HC.
1420 *
1421 * This will verify the file integrity in a similar manner as
1422 * SUPR3HardenedVerifyFile before loading it.
1423 *
1424 * @returns VBox status code.
1425 * @param pszFilename The path to the image file.
1426 * @param pszModule The module name. Max 32 bytes.
1427 * @param ppvImageBase Where to store the image address.
1428 * @param pErrInfo Where to return extended error information.
1429 * Optional.
1430 */
1431SUPR3DECL(int) SUPR3LoadModule(const char *pszFilename, const char *pszModule, void **ppvImageBase, PRTERRINFO pErrInfo);
1432
1433/**
1434 * Load a module into R0 HC.
1435 *
1436 * This will verify the file integrity in a similar manner as
1437 * SUPR3HardenedVerifyFile before loading it.
1438 *
1439 * @returns VBox status code.
1440 * @param pszFilename The path to the image file.
1441 * @param pszModule The module name. Max 32 bytes.
1442 * @param pszSrvReqHandler The name of the service request handler entry
1443 * point. See FNSUPR0SERVICEREQHANDLER.
1444 * @param ppvImageBase Where to store the image address.
1445 */
1446SUPR3DECL(int) SUPR3LoadServiceModule(const char *pszFilename, const char *pszModule,
1447 const char *pszSrvReqHandler, void **ppvImageBase);
1448
1449/**
1450 * Frees a R0 HC module.
1451 *
1452 * @returns VBox status code.
1453 * @param pvImageBase The base address of the image to free.
1454 * @remark This will not actually 'free' the module, there are of course usage counting.
1455 */
1456SUPR3DECL(int) SUPR3FreeModule(void *pvImageBase);
1457
1458/**
1459 * Lock down the module loader interface.
1460 *
1461 * This will lock down the module loader interface. No new modules can be
1462 * loaded and all loaded modules can no longer be freed.
1463 *
1464 * @returns VBox status code.
1465 * @param pErrInfo Where to return extended error information.
1466 * Optional.
1467 */
1468SUPR3DECL(int) SUPR3LockDownLoader(PRTERRINFO pErrInfo);
1469
1470/**
1471 * Get the address of a symbol in a ring-0 module.
1472 *
1473 * @returns VBox status code.
1474 * @param pvImageBase The base address of the image to search.
1475 * @param pszSymbol Symbol name. If it's value is less than 64k it's treated like a
1476 * ordinal value rather than a string pointer.
1477 * @param ppvValue Where to store the symbol value.
1478 */
1479SUPR3DECL(int) SUPR3GetSymbolR0(void *pvImageBase, const char *pszSymbol, void **ppvValue);
1480
1481/**
1482 * Load R0 HC VMM code.
1483 *
1484 * @returns VBox status code.
1485 * @deprecated Use SUPR3LoadModule(pszFilename, "VMMR0.r0", &pvImageBase)
1486 */
1487SUPR3DECL(int) SUPR3LoadVMM(const char *pszFilename);
1488
1489/**
1490 * Unloads R0 HC VMM code.
1491 *
1492 * @returns VBox status code.
1493 * @deprecated Use SUPR3FreeModule().
1494 */
1495SUPR3DECL(int) SUPR3UnloadVMM(void);
1496
1497/**
1498 * Get the physical address of the GIP.
1499 *
1500 * @returns VBox status code.
1501 * @param pHCPhys Where to store the physical address of the GIP.
1502 */
1503SUPR3DECL(int) SUPR3GipGetPhys(PRTHCPHYS pHCPhys);
1504
1505/**
1506 * Initializes only the bits relevant for the SUPR3HardenedVerify* APIs.
1507 *
1508 * This is for users that don't necessarily need to initialize the whole of
1509 * SUPLib. There is no harm in calling this one more time.
1510 *
1511 * @returns VBox status code.
1512 * @remarks Currently not counted, so only call once.
1513 */
1514SUPR3DECL(int) SUPR3HardenedVerifyInit(void);
1515
1516/**
1517 * Reverses the effect of SUPR3HardenedVerifyInit if SUPR3InitEx hasn't been
1518 * called.
1519 *
1520 * Ignored if the support library was initialized using SUPR3Init or
1521 * SUPR3InitEx.
1522 *
1523 * @returns VBox status code.
1524 */
1525SUPR3DECL(int) SUPR3HardenedVerifyTerm(void);
1526
1527/**
1528 * Verifies the integrity of a file, and optionally opens it.
1529 *
1530 * The integrity check is for whether the file is suitable for loading into
1531 * the hypervisor or VM process. The integrity check may include verifying
1532 * the authenticode/elfsign/whatever signature of the file, which can take
1533 * a little while.
1534 *
1535 * @returns VBox status code. On failure it will have printed a LogRel message.
1536 *
1537 * @param pszFilename The file.
1538 * @param pszWhat For the LogRel on failure.
1539 * @param phFile Where to store the handle to the opened file. This is optional, pass NULL
1540 * if the file should not be opened.
1541 * @deprecated Write a new one.
1542 */
1543SUPR3DECL(int) SUPR3HardenedVerifyFile(const char *pszFilename, const char *pszWhat, PRTFILE phFile);
1544
1545/**
1546 * Verifies the integrity of a the current process, including the image
1547 * location and that the invocation was absolute.
1548 *
1549 * This must currently be called after initializing the runtime. The intended
1550 * audience is set-uid-to-root applications, root services and similar.
1551 *
1552 * @returns VBox status code. On failure
1553 * message.
1554 * @param pszArgv0 The first argument to main().
1555 * @param fInternal Set this to @c true if this is an internal
1556 * VirtualBox application. Otherwise pass @c false.
1557 * @param pErrInfo Where to return extended error information.
1558 */
1559SUPR3DECL(int) SUPR3HardenedVerifySelf(const char *pszArgv0, bool fInternal, PRTERRINFO pErrInfo);
1560
1561/**
1562 * Verifies the integrity of an installation directory.
1563 *
1564 * The integrity check verifies that the directory cannot be tampered with by
1565 * normal users on the system. On Unix this translates to root ownership and
1566 * no symbolic linking.
1567 *
1568 * @returns VBox status code. On failure a message will be stored in @a pszErr.
1569 *
1570 * @param pszDirPath The directory path.
1571 * @param fRecursive Whether the check should be recursive or
1572 * not. When set, all sub-directores will be checked,
1573 * including files (@a fCheckFiles is ignored).
1574 * @param fCheckFiles Whether to apply the same basic integrity check to
1575 * the files in the directory as the directory itself.
1576 * @param pErrInfo Where to return extended error information.
1577 * Optional.
1578 */
1579SUPR3DECL(int) SUPR3HardenedVerifyDir(const char *pszDirPath, bool fRecursive, bool fCheckFiles, PRTERRINFO pErrInfo);
1580
1581/**
1582 * Verifies the integrity of a plug-in module.
1583 *
1584 * This is similar to SUPR3HardenedLdrLoad, except it does not load the module
1585 * and that the module does not have to be shipped with VirtualBox.
1586 *
1587 * @returns VBox status code. On failure a message will be stored in @a pszErr.
1588 *
1589 * @param pszFilename The filename of the plug-in module (nothing can be
1590 * omitted here).
1591 * @param pErrInfo Where to return extended error information.
1592 * Optional.
1593 */
1594SUPR3DECL(int) SUPR3HardenedVerifyPlugIn(const char *pszFilename, PRTERRINFO pErrInfo);
1595
1596/**
1597 * Same as RTLdrLoad() but will verify the files it loads (hardened builds).
1598 *
1599 * Will add dll suffix if missing and try load the file.
1600 *
1601 * @returns iprt status code.
1602 * @param pszFilename Image filename. This must have a path.
1603 * @param phLdrMod Where to store the handle to the loaded module.
1604 * @param fFlags See RTLDRLOAD_FLAGS_XXX.
1605 * @param pErrInfo Where to return extended error information.
1606 * Optional.
1607 */
1608SUPR3DECL(int) SUPR3HardenedLdrLoad(const char *pszFilename, PRTLDRMOD phLdrMod, uint32_t fFlags, PRTERRINFO pErrInfo);
1609
1610/**
1611 * Same as RTLdrLoadAppPriv() but it will verify the files it loads (hardened
1612 * builds).
1613 *
1614 * Will add dll suffix to the file if missing, then look for it in the
1615 * architecture dependent application directory.
1616 *
1617 * @returns iprt status code.
1618 * @param pszFilename Image filename.
1619 * @param phLdrMod Where to store the handle to the loaded module.
1620 * @param fFlags See RTLDRLOAD_FLAGS_XXX.
1621 * @param pErrInfo Where to return extended error information.
1622 * Optional.
1623 */
1624SUPR3DECL(int) SUPR3HardenedLdrLoadAppPriv(const char *pszFilename, PRTLDRMOD phLdrMod, uint32_t fFlags, PRTERRINFO pErrInfo);
1625
1626/**
1627 * Same as RTLdrLoad() but will verify the files it loads (hardened builds).
1628 *
1629 * This differs from SUPR3HardenedLdrLoad() in that it can load modules from
1630 * extension packs and anything else safely installed on the system, provided
1631 * they pass the hardening tests.
1632 *
1633 * @returns iprt status code.
1634 * @param pszFilename The full path to the module, with extension.
1635 * @param phLdrMod Where to store the handle to the loaded module.
1636 * @param pErrInfo Where to return extended error information.
1637 * Optional.
1638 */
1639SUPR3DECL(int) SUPR3HardenedLdrLoadPlugIn(const char *pszFilename, PRTLDRMOD phLdrMod, PRTERRINFO pErrInfo);
1640
1641/**
1642 * Check if the host kernel can run in VMX root mode.
1643 *
1644 * @returns VINF_SUCCESS if supported, error code indicating why if not.
1645 * @param ppszWhy Where to return an explanatory message on failure.
1646 */
1647SUPR3DECL(int) SUPR3QueryVTxSupported(const char **ppszWhy);
1648
1649/**
1650 * Return VT-x/AMD-V capabilities.
1651 *
1652 * @returns VINF_SUCCESS if supported, error code indicating why if not.
1653 * @param pfCaps Pointer to capability dword (out).
1654 * @todo Intended for main, which means we need to relax the privilege requires
1655 * when accessing certain vboxdrv functions.
1656 */
1657SUPR3DECL(int) SUPR3QueryVTCaps(uint32_t *pfCaps);
1658
1659/**
1660 * Open the tracer.
1661 *
1662 * @returns VBox status code.
1663 * @param uCookie Cookie identifying the tracer we expect to talk to.
1664 * @param uArg Tracer specific open argument.
1665 */
1666SUPR3DECL(int) SUPR3TracerOpen(uint32_t uCookie, uintptr_t uArg);
1667
1668/**
1669 * Closes the tracer.
1670 *
1671 * @returns VBox status code.
1672 */
1673SUPR3DECL(int) SUPR3TracerClose(void);
1674
1675/**
1676 * Perform an I/O request on the tracer.
1677 *
1678 * @returns VBox status.
1679 * @param uCmd The tracer command.
1680 * @param uArg The argument.
1681 * @param piRetVal Where to store the tracer return value.
1682 */
1683SUPR3DECL(int) SUPR3TracerIoCtl(uintptr_t uCmd, uintptr_t uArg, int32_t *piRetVal);
1684
1685/**
1686 * Registers the user module with the tracer.
1687 *
1688 * @returns VBox status code.
1689 * @param hModNative Native module handle. Pass ~(uintptr_t)0 if not
1690 * at hand.
1691 * @param pszModule The module name.
1692 * @param pVtgHdr The VTG header.
1693 * @param uVtgHdrAddr The address to which the VTG header is loaded
1694 * in the relevant execution context.
1695 * @param fFlags See SUP_TRACER_UMOD_FLAGS_XXX
1696 */
1697SUPR3DECL(int) SUPR3TracerRegisterModule(uintptr_t hModNative, const char *pszModule, struct VTGOBJHDR *pVtgHdr,
1698 RTUINTPTR uVtgHdrAddr, uint32_t fFlags);
1699
1700/**
1701 * Deregisters the user module.
1702 *
1703 * @returns VBox status code.
1704 * @param pVtgHdr The VTG header.
1705 */
1706SUPR3DECL(int) SUPR3TracerDeregisterModule(struct VTGOBJHDR *pVtgHdr);
1707
1708/**
1709 * Fire the probe.
1710 *
1711 * @param pVtgProbeLoc The probe location record.
1712 * @param uArg0 Raw probe argument 0.
1713 * @param uArg1 Raw probe argument 1.
1714 * @param uArg2 Raw probe argument 2.
1715 * @param uArg3 Raw probe argument 3.
1716 * @param uArg4 Raw probe argument 4.
1717 */
1718SUPDECL(void) SUPTracerFireProbe(struct VTGPROBELOC *pVtgProbeLoc, uintptr_t uArg0, uintptr_t uArg1, uintptr_t uArg2,
1719 uintptr_t uArg3, uintptr_t uArg4);
1720
1721/**
1722 * Attempts to read the value of an MSR.
1723 *
1724 * @returns VBox status code.
1725 * @param uMsr The MSR to read.
1726 * @param idCpu The CPU to read it on, NIL_RTCPUID if it doesn't
1727 * matter which CPU.
1728 * @param puValue Where to return the value.
1729 * @param pfGp Where to store the \#GP indicator for the read
1730 * operation.
1731 */
1732SUPR3DECL(int) SUPR3MsrProberRead(uint32_t uMsr, RTCPUID idCpu, uint64_t *puValue, bool *pfGp);
1733
1734/**
1735 * Attempts to write to an MSR.
1736 *
1737 * @returns VBox status code.
1738 * @param uMsr The MSR to write to.
1739 * @param idCpu The CPU to wrtie it on, NIL_RTCPUID if it
1740 * doesn't matter which CPU.
1741 * @param uValue The value to write.
1742 * @param pfGp Where to store the \#GP indicator for the write
1743 * operation.
1744 */
1745SUPR3DECL(int) SUPR3MsrProberWrite(uint32_t uMsr, RTCPUID idCpu, uint64_t uValue, bool *pfGp);
1746
1747/**
1748 * Attempts to modify the value of an MSR.
1749 *
1750 * @returns VBox status code.
1751 * @param uMsr The MSR to modify.
1752 * @param idCpu The CPU to modify it on, NIL_RTCPUID if it
1753 * doesn't matter which CPU.
1754 * @param fAndMask The bits to keep in the current MSR value.
1755 * @param fOrMask The bits to set before writing.
1756 * @param pResult The result buffer.
1757 */
1758SUPR3DECL(int) SUPR3MsrProberModify(uint32_t uMsr, RTCPUID idCpu, uint64_t fAndMask, uint64_t fOrMask,
1759 PSUPMSRPROBERMODIFYRESULT pResult);
1760
1761/**
1762 * Attempts to modify the value of an MSR, extended version.
1763 *
1764 * @returns VBox status code.
1765 * @param uMsr The MSR to modify.
1766 * @param idCpu The CPU to modify it on, NIL_RTCPUID if it
1767 * doesn't matter which CPU.
1768 * @param fAndMask The bits to keep in the current MSR value.
1769 * @param fOrMask The bits to set before writing.
1770 * @param fFaster If set to @c true some cache/tlb invalidation is
1771 * skipped, otherwise behave like
1772 * SUPR3MsrProberModify.
1773 * @param pResult The result buffer.
1774 */
1775SUPR3DECL(int) SUPR3MsrProberModifyEx(uint32_t uMsr, RTCPUID idCpu, uint64_t fAndMask, uint64_t fOrMask, bool fFaster,
1776 PSUPMSRPROBERMODIFYRESULT pResult);
1777
1778/**
1779 * Resume built-in keyboard on MacBook Air and Pro hosts.
1780 *
1781 * @returns VBox status code.
1782 */
1783SUPR3DECL(int) SUPR3ResumeSuspendedKeyboards(void);
1784
1785/**
1786 * Measure the TSC-delta for the specified CPU.
1787 *
1788 * @returns VBox status code.
1789 * @param idCpu The CPU to measure the TSC-delta for.
1790 * @param fAsync Whether the measurement is asynchronous, returns
1791 * immediately after signalling a measurement
1792 * request.
1793 * @param fForce Whether to perform a measurement even if the
1794 * specified CPU has a (possibly) valid TSC delta.
1795 * @param cRetries Number of times to retry failed delta
1796 * measurements.
1797 * @param cMsWaitRetry Number of milliseconds to wait between retries.
1798 */
1799SUPR3DECL(int) SUPR3TscDeltaMeasure(RTCPUID idCpu, bool fAsync, bool fForce, uint8_t cRetries, uint8_t cMsWaitRetry);
1800
1801/**
1802 * Reads the delta-adjust TSC value.
1803 *
1804 * @returns VBox status code.
1805 * @param puTsc Where to store the read TSC value.
1806 * @param pidApic Where to store the APIC ID of the CPU where the TSC
1807 * was read (optional, can be NULL).
1808 */
1809SUPR3DECL(int) SUPR3ReadTsc(uint64_t *puTsc, uint16_t *pidApic);
1810
1811/**
1812 * Modifies the GIP flags.
1813 *
1814 * @returns VBox status code.
1815 * @param fOrMask The OR mask of the GIP flags, see SUPGIP_FLAGS_XXX.
1816 * @param fAndMask The AND mask of the GIP flags, see SUPGIP_FLAGS_XXX.
1817 */
1818SUPR3DECL(int) SUPR3GipSetFlags(uint32_t fOrMask, uint32_t fAndMask);
1819
1820/**
1821 * Return processor microcode revision, if applicable.
1822 *
1823 * @returns VINF_SUCCESS if supported, error code indicating why if not.
1824 * @param puMicrocodeRev Pointer to microcode revision dword (out).
1825 */
1826SUPR3DECL(int) SUPR3QueryMicrocodeRev(uint32_t *puMicrocodeRev);
1827
1828/** @} */
1829#endif /* IN_RING3 */
1830
1831
1832/** @name User mode module flags (SUPR3TracerRegisterModule & SUP_IOCTL_TRACER_UMOD_REG).
1833 * @{ */
1834/** Executable image. */
1835#define SUP_TRACER_UMOD_FLAGS_EXE UINT32_C(1)
1836/** Shared library (DLL, DYLIB, SO, etc). */
1837#define SUP_TRACER_UMOD_FLAGS_SHARED UINT32_C(2)
1838/** Image type mask. */
1839#define SUP_TRACER_UMOD_FLAGS_TYPE_MASK UINT32_C(3)
1840/** @} */
1841
1842
1843#ifdef IN_RING0
1844/** @defgroup grp_sup_r0 SUP Host Context Ring-0 API
1845 * @{
1846 */
1847
1848/**
1849 * Security objectype.
1850 */
1851typedef enum SUPDRVOBJTYPE
1852{
1853 /** The usual invalid object. */
1854 SUPDRVOBJTYPE_INVALID = 0,
1855 /** A Virtual Machine instance. */
1856 SUPDRVOBJTYPE_VM,
1857 /** Internal network. */
1858 SUPDRVOBJTYPE_INTERNAL_NETWORK,
1859 /** Internal network interface. */
1860 SUPDRVOBJTYPE_INTERNAL_NETWORK_INTERFACE,
1861 /** Single release event semaphore. */
1862 SUPDRVOBJTYPE_SEM_EVENT,
1863 /** Multiple release event semaphore. */
1864 SUPDRVOBJTYPE_SEM_EVENT_MULTI,
1865 /** Raw PCI device. */
1866 SUPDRVOBJTYPE_RAW_PCI_DEVICE,
1867 /** The first invalid object type in this end. */
1868 SUPDRVOBJTYPE_END,
1869 /** The usual 32-bit type size hack. */
1870 SUPDRVOBJTYPE_32_BIT_HACK = 0x7ffffff
1871} SUPDRVOBJTYPE;
1872
1873/**
1874 * Object destructor callback.
1875 * This is called for reference counted objectes when the count reaches 0.
1876 *
1877 * @param pvObj The object pointer.
1878 * @param pvUser1 The first user argument.
1879 * @param pvUser2 The second user argument.
1880 */
1881typedef DECLCALLBACK(void) FNSUPDRVDESTRUCTOR(void *pvObj, void *pvUser1, void *pvUser2);
1882/** Pointer to a FNSUPDRVDESTRUCTOR(). */
1883typedef FNSUPDRVDESTRUCTOR *PFNSUPDRVDESTRUCTOR;
1884
1885SUPR0DECL(void *) SUPR0ObjRegister(PSUPDRVSESSION pSession, SUPDRVOBJTYPE enmType, PFNSUPDRVDESTRUCTOR pfnDestructor, void *pvUser1, void *pvUser2);
1886SUPR0DECL(int) SUPR0ObjAddRef(void *pvObj, PSUPDRVSESSION pSession);
1887SUPR0DECL(int) SUPR0ObjAddRefEx(void *pvObj, PSUPDRVSESSION pSession, bool fNoBlocking);
1888SUPR0DECL(int) SUPR0ObjRelease(void *pvObj, PSUPDRVSESSION pSession);
1889SUPR0DECL(int) SUPR0ObjVerifyAccess(void *pvObj, PSUPDRVSESSION pSession, const char *pszObjName);
1890
1891SUPR0DECL(PVM) SUPR0GetSessionVM(PSUPDRVSESSION pSession);
1892SUPR0DECL(PGVM) SUPR0GetSessionGVM(PSUPDRVSESSION pSession);
1893SUPR0DECL(int) SUPR0SetSessionVM(PSUPDRVSESSION pSession, PGVM pGVM, PVM pVM);
1894
1895SUPR0DECL(int) SUPR0LockMem(PSUPDRVSESSION pSession, RTR3PTR pvR3, uint32_t cPages, PRTHCPHYS paPages);
1896SUPR0DECL(int) SUPR0UnlockMem(PSUPDRVSESSION pSession, RTR3PTR pvR3);
1897SUPR0DECL(int) SUPR0ContAlloc(PSUPDRVSESSION pSession, uint32_t cPages, PRTR0PTR ppvR0, PRTR3PTR ppvR3, PRTHCPHYS pHCPhys);
1898SUPR0DECL(int) SUPR0ContFree(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr);
1899SUPR0DECL(int) SUPR0LowAlloc(PSUPDRVSESSION pSession, uint32_t cPages, PRTR0PTR ppvR0, PRTR3PTR ppvR3, PRTHCPHYS paPages);
1900SUPR0DECL(int) SUPR0LowFree(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr);
1901SUPR0DECL(int) SUPR0MemAlloc(PSUPDRVSESSION pSession, uint32_t cb, PRTR0PTR ppvR0, PRTR3PTR ppvR3);
1902SUPR0DECL(int) SUPR0MemGetPhys(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr, PSUPPAGE paPages);
1903SUPR0DECL(int) SUPR0MemFree(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr);
1904SUPR0DECL(int) SUPR0PageAllocEx(PSUPDRVSESSION pSession, uint32_t cPages, uint32_t fFlags, PRTR3PTR ppvR3, PRTR0PTR ppvR0, PRTHCPHYS paPages);
1905SUPR0DECL(int) SUPR0PageMapKernel(PSUPDRVSESSION pSession, RTR3PTR pvR3, uint32_t offSub, uint32_t cbSub, uint32_t fFlags, PRTR0PTR ppvR0);
1906SUPR0DECL(int) SUPR0PageProtect(PSUPDRVSESSION pSession, RTR3PTR pvR3, RTR0PTR pvR0, uint32_t offSub, uint32_t cbSub, uint32_t fProt);
1907SUPR0DECL(int) SUPR0PageFree(PSUPDRVSESSION pSession, RTR3PTR pvR3);
1908SUPR0DECL(int) SUPR0GipMap(PSUPDRVSESSION pSession, PRTR3PTR ppGipR3, PRTHCPHYS pHCPhysGip);
1909SUPR0DECL(int) SUPR0GetSvmUsability(bool fInitSvm);
1910SUPR0DECL(int) SUPR0GetVmxUsability(bool *pfIsSmxModeAmbiguous);
1911SUPR0DECL(int) SUPR0GetRawModeUsability(void);
1912SUPR0DECL(int) SUPR0GetCurrentGdtRw(RTHCUINTPTR *pGdtRw);
1913SUPR0DECL(int) SUPR0QueryVTCaps(PSUPDRVSESSION pSession, uint32_t *pfCaps);
1914SUPR0DECL(int) SUPR0GipUnmap(PSUPDRVSESSION pSession);
1915SUPR0DECL(int) SUPR0QueryUcodeRev(PSUPDRVSESSION pSession, uint32_t *puMicrocodeRev);
1916SUPR0DECL(SUPPAGINGMODE) SUPR0GetPagingMode(void);
1917SUPR0DECL(RTCCUINTREG) SUPR0ChangeCR4(RTCCUINTREG fOrMask, RTCCUINTREG fAndMask);
1918SUPR0DECL(int) SUPR0EnableVTx(bool fEnable);
1919SUPR0DECL(bool) SUPR0SuspendVTxOnCpu(void);
1920SUPR0DECL(void) SUPR0ResumeVTxOnCpu(bool fSuspended);
1921#define SUP_TSCDELTA_MEASURE_F_FORCE RT_BIT_32(0)
1922#define SUP_TSCDELTA_MEASURE_F_ASYNC RT_BIT_32(1)
1923#define SUP_TSCDELTA_MEASURE_F_VALID_MASK UINT32_C(0x00000003)
1924SUPR0DECL(int) SUPR0TscDeltaMeasureBySetIndex(PSUPDRVSESSION pSession, uint32_t iCpuSet, uint32_t fFlags,
1925 RTMSINTERVAL cMsWaitRetry, RTMSINTERVAL cMsWaitThread, uint32_t cTries);
1926
1927SUPR0DECL(void) SUPR0BadContext(PSUPDRVSESSION pSession, const char *pszFile, uint32_t uLine, const char *pszExpr);
1928
1929/** Context structure returned by SUPR0IoCtlSetup for use with
1930 * SUPR0IoCtlPerform and cleaned up by SUPR0IoCtlCleanup. */
1931typedef struct SUPR0IOCTLCTX *PSUPR0IOCTLCTX;
1932
1933/**
1934 * Sets up a I/O control context for the given handle.
1935 *
1936 * @returns VBox status code.
1937 * @param pSession The support driver session.
1938 * @param hHandle The handle.
1939 * @param fFlags Flag, MBZ.
1940 * @param ppCtx Where the context is returned.
1941 */
1942SUPR0DECL(int) SUPR0IoCtlSetupForHandle(PSUPDRVSESSION pSession, intptr_t hHandle, uint32_t fFlags, PSUPR0IOCTLCTX *ppCtx);
1943
1944/**
1945 * Cleans up the I/O control context when done.
1946 *
1947 * This won't close the handle passed to SUPR0IoCtlSetupForHandle.
1948 *
1949 * @returns VBox status code.
1950 * @param pCtx The I/O control context to cleanup.
1951 */
1952SUPR0DECL(int) SUPR0IoCtlCleanup(PSUPR0IOCTLCTX pCtx);
1953
1954/**
1955 * Performs an I/O control operation.
1956 *
1957 * @returns VBox status code.
1958 * @param pCtx The I/O control context returned by
1959 * SUPR0IoCtlSetupForHandle.
1960 * @param uFunction The I/O control function to perform.
1961 * @param pvInput Pointer to input buffer (ring-0).
1962 * @param pvInputUser Ring-3 pointer corresponding to @a pvInput.
1963 * @param cbInput The amount of input. If zero, both input pointers
1964 * are expected to be NULL.
1965 * @param pvOutput Pointer to output buffer (ring-0).
1966 * @param pvOutputUser Ring-3 pointer corresponding to @a pvInput.
1967 * @param cbOutput The amount of input. If zero, both input pointers
1968 * are expected to be NULL.
1969 * @param piNativeRc Where to return the native return code. When
1970 * specified the VBox status code will typically be
1971 * VINF_SUCCESS and the caller have to consult this for
1972 * the actual result of the operation. (This saves
1973 * pointless status code conversion.) Optional.
1974 *
1975 * @note On unix systems where there is only one set of buffers possible,
1976 * pass the same pointers as input and output.
1977 */
1978SUPR0DECL(int) SUPR0IoCtlPerform(PSUPR0IOCTLCTX pCtx, uintptr_t uFunction,
1979 void *pvInput, RTR3PTR pvInputUser, size_t cbInput,
1980 void *pvOutput, RTR3PTR pvOutputUser, size_t cbOutput,
1981 int32_t *piNativeRc);
1982
1983/**
1984 * Writes to the debugger and/or kernel log.
1985 *
1986 * The length of the formatted message is somewhat limited, so keep things short
1987 * and to the point.
1988 *
1989 * @returns Number of bytes written, mabye.
1990 * @param pszFormat IPRT format string.
1991 * @param ... Arguments referenced by the format string.
1992 */
1993SUPR0DECL(int) SUPR0Printf(const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
1994
1995/**
1996 * Returns configuration flags of the host kernel.
1997 *
1998 * @returns Combination of SUPKERNELFEATURES_XXX flags.
1999 */
2000SUPR0DECL(uint32_t) SUPR0GetKernelFeatures(void);
2001
2002
2003/** @name Absolute symbols
2004 * Take the address of these, don't try call them.
2005 * @{ */
2006SUPR0DECL(void) SUPR0AbsIs64bit(void);
2007SUPR0DECL(void) SUPR0Abs64bitKernelCS(void);
2008SUPR0DECL(void) SUPR0Abs64bitKernelSS(void);
2009SUPR0DECL(void) SUPR0Abs64bitKernelDS(void);
2010SUPR0DECL(void) SUPR0AbsKernelCS(void);
2011SUPR0DECL(void) SUPR0AbsKernelSS(void);
2012SUPR0DECL(void) SUPR0AbsKernelDS(void);
2013SUPR0DECL(void) SUPR0AbsKernelES(void);
2014SUPR0DECL(void) SUPR0AbsKernelFS(void);
2015SUPR0DECL(void) SUPR0AbsKernelGS(void);
2016/** @} */
2017
2018/**
2019 * Support driver component factory.
2020 *
2021 * Component factories are registered by drivers that provides services
2022 * such as the host network interface filtering and access to the host
2023 * TCP/IP stack.
2024 *
2025 * @remark Module dependencies and making sure that a component doesn't
2026 * get unloaded while in use, is the sole responsibility of the
2027 * driver/kext/whatever implementing the component.
2028 */
2029typedef struct SUPDRVFACTORY
2030{
2031 /** The (unique) name of the component factory. */
2032 char szName[56];
2033 /**
2034 * Queries a factory interface.
2035 *
2036 * The factory interface is specific to each component and will be be
2037 * found in the header(s) for the component alongside its UUID.
2038 *
2039 * @returns Pointer to the factory interfaces on success, NULL on failure.
2040 *
2041 * @param pSupDrvFactory Pointer to this structure.
2042 * @param pSession The SUPDRV session making the query.
2043 * @param pszInterfaceUuid The UUID of the factory interface.
2044 */
2045 DECLR0CALLBACKMEMBER(void *, pfnQueryFactoryInterface,(struct SUPDRVFACTORY const *pSupDrvFactory, PSUPDRVSESSION pSession, const char *pszInterfaceUuid));
2046} SUPDRVFACTORY;
2047/** Pointer to a support driver factory. */
2048typedef SUPDRVFACTORY *PSUPDRVFACTORY;
2049/** Pointer to a const support driver factory. */
2050typedef SUPDRVFACTORY const *PCSUPDRVFACTORY;
2051
2052SUPR0DECL(int) SUPR0ComponentRegisterFactory(PSUPDRVSESSION pSession, PCSUPDRVFACTORY pFactory);
2053SUPR0DECL(int) SUPR0ComponentDeregisterFactory(PSUPDRVSESSION pSession, PCSUPDRVFACTORY pFactory);
2054SUPR0DECL(int) SUPR0ComponentQueryFactory(PSUPDRVSESSION pSession, const char *pszName, const char *pszInterfaceUuid, void **ppvFactoryIf);
2055
2056
2057/** @name Tracing
2058 * @{ */
2059
2060/**
2061 * Tracer data associated with a provider.
2062 */
2063typedef union SUPDRVTRACERDATA
2064{
2065 /** Generic */
2066 uint64_t au64[2];
2067
2068 /** DTrace data. */
2069 struct
2070 {
2071 /** Provider ID. */
2072 uintptr_t idProvider;
2073 /** The number of trace points provided. */
2074 uint32_t volatile cProvidedProbes;
2075 /** Whether we've invalidated this bugger. */
2076 bool fZombie;
2077 } DTrace;
2078} SUPDRVTRACERDATA;
2079/** Pointer to the tracer data associated with a provider. */
2080typedef SUPDRVTRACERDATA *PSUPDRVTRACERDATA;
2081
2082/**
2083 * Probe location info for ring-0.
2084 *
2085 * Since we cannot trust user tracepoint modules, we need to duplicate the probe
2086 * ID and enabled flag in ring-0.
2087 */
2088typedef struct SUPDRVPROBELOC
2089{
2090 /** The probe ID. */
2091 uint32_t idProbe;
2092 /** Whether it's enabled or not. */
2093 bool fEnabled;
2094} SUPDRVPROBELOC;
2095/** Pointer to a ring-0 probe location record. */
2096typedef SUPDRVPROBELOC *PSUPDRVPROBELOC;
2097
2098/**
2099 * Probe info for ring-0.
2100 *
2101 * Since we cannot trust user tracepoint modules, we need to duplicate the
2102 * probe enable count.
2103 */
2104typedef struct SUPDRVPROBEINFO
2105{
2106 /** The number of times this probe has been enabled. */
2107 uint32_t volatile cEnabled;
2108} SUPDRVPROBEINFO;
2109/** Pointer to a ring-0 probe info record. */
2110typedef SUPDRVPROBEINFO *PSUPDRVPROBEINFO;
2111
2112/**
2113 * Support driver tracepoint provider core.
2114 */
2115typedef struct SUPDRVVDTPROVIDERCORE
2116{
2117 /** The tracer data member. */
2118 SUPDRVTRACERDATA TracerData;
2119 /** Pointer to the provider name (a copy that's always available). */
2120 const char *pszName;
2121 /** Pointer to the module name (a copy that's always available). */
2122 const char *pszModName;
2123
2124 /** The provider descriptor. */
2125 struct VTGDESCPROVIDER *pDesc;
2126 /** The VTG header. */
2127 struct VTGOBJHDR *pHdr;
2128
2129 /** The size of the entries in the pvProbeLocsEn table. */
2130 uint8_t cbProbeLocsEn;
2131 /** The actual module bit count (corresponds to cbProbeLocsEn). */
2132 uint8_t cBits;
2133 /** Set if this is a Umod, otherwise clear. */
2134 bool fUmod;
2135 /** Explicit alignment padding (paranoia). */
2136 uint8_t abAlignment[ARCH_BITS == 32 ? 1 : 5];
2137
2138 /** The probe locations used for descriptive purposes. */
2139 struct VTGPROBELOC const *paProbeLocsRO;
2140 /** Pointer to the probe location array where the enable flag needs
2141 * flipping. For kernel providers, this will always be SUPDRVPROBELOC,
2142 * while user providers can either be 32-bit or 64-bit. Use
2143 * cbProbeLocsEn to calculate the address of an entry. */
2144 void *pvProbeLocsEn;
2145 /** Pointer to the probe array containing the enabled counts. */
2146 uint32_t *pacProbeEnabled;
2147
2148 /** The ring-0 probe location info for user tracepoint modules.
2149 * This is NULL if fUmod is false. */
2150 PSUPDRVPROBELOC paR0ProbeLocs;
2151 /** The ring-0 probe info for user tracepoint modules.
2152 * This is NULL if fUmod is false. */
2153 PSUPDRVPROBEINFO paR0Probes;
2154
2155} SUPDRVVDTPROVIDERCORE;
2156/** Pointer to a tracepoint provider core structure. */
2157typedef SUPDRVVDTPROVIDERCORE *PSUPDRVVDTPROVIDERCORE;
2158
2159/** Pointer to a tracer registration record. */
2160typedef struct SUPDRVTRACERREG const *PCSUPDRVTRACERREG;
2161/**
2162 * Support driver tracer registration record.
2163 */
2164typedef struct SUPDRVTRACERREG
2165{
2166 /** Magic value (SUPDRVTRACERREG_MAGIC). */
2167 uint32_t u32Magic;
2168 /** Version (SUPDRVTRACERREG_VERSION). */
2169 uint32_t u32Version;
2170
2171 /**
2172 * Fire off a kernel probe.
2173 *
2174 * @param pVtgProbeLoc The probe location record.
2175 * @param uArg0 The first raw probe argument.
2176 * @param uArg1 The second raw probe argument.
2177 * @param uArg2 The third raw probe argument.
2178 * @param uArg3 The fourth raw probe argument.
2179 * @param uArg4 The fifth raw probe argument.
2180 *
2181 * @remarks SUPR0TracerFireProbe will do a tail jump thru this member, so
2182 * no extra stack frames will be added.
2183 * @remarks This does not take a 'this' pointer argument because it doesn't map
2184 * well onto VTG or DTrace.
2185 *
2186 */
2187 DECLR0CALLBACKMEMBER(void, pfnProbeFireKernel, (struct VTGPROBELOC *pVtgProbeLoc, uintptr_t uArg0, uintptr_t uArg1, uintptr_t uArg2,
2188 uintptr_t uArg3, uintptr_t uArg4));
2189
2190 /**
2191 * Fire off a user-mode probe.
2192 *
2193 * @param pThis Pointer to the registration record.
2194 *
2195 * @param pVtgProbeLoc The probe location record.
2196 * @param pSession The user session.
2197 * @param pCtx The usermode context info.
2198 * @param pVtgHdr The VTG header (read-only).
2199 * @param pProbeLocRO The read-only probe location record .
2200 */
2201 DECLR0CALLBACKMEMBER(void, pfnProbeFireUser, (PCSUPDRVTRACERREG pThis, PSUPDRVSESSION pSession, PCSUPDRVTRACERUSRCTX pCtx,
2202 struct VTGOBJHDR const *pVtgHdr, struct VTGPROBELOC const *pProbeLocRO));
2203
2204 /**
2205 * Opens up the tracer.
2206 *
2207 * @returns VBox status code.
2208 * @param pThis Pointer to the registration record.
2209 * @param pSession The session doing the opening.
2210 * @param uCookie A cookie (magic) unique to the tracer, so it can
2211 * fend off incompatible clients.
2212 * @param uArg Tracer specific argument.
2213 * @param puSessionData Pointer to the session data variable. This must be
2214 * set to a non-zero value on success.
2215 */
2216 DECLR0CALLBACKMEMBER(int, pfnTracerOpen, (PCSUPDRVTRACERREG pThis, PSUPDRVSESSION pSession, uint32_t uCookie, uintptr_t uArg,
2217 uintptr_t *puSessionData));
2218
2219 /**
2220 * I/O control style tracer communication method.
2221 *
2222 *
2223 * @returns VBox status code.
2224 * @param pThis Pointer to the registration record.
2225 * @param pSession The session.
2226 * @param uSessionData The session data value.
2227 * @param uCmd The tracer specific command.
2228 * @param uArg The tracer command specific argument.
2229 * @param piRetVal The tracer specific return value.
2230 */
2231 DECLR0CALLBACKMEMBER(int, pfnTracerIoCtl, (PCSUPDRVTRACERREG pThis, PSUPDRVSESSION pSession, uintptr_t uSessionData,
2232 uintptr_t uCmd, uintptr_t uArg, int32_t *piRetVal));
2233
2234 /**
2235 * Cleans up data the tracer has associated with a session.
2236 *
2237 * @param pThis Pointer to the registration record.
2238 * @param pSession The session handle.
2239 * @param uSessionData The data assoicated with the session.
2240 */
2241 DECLR0CALLBACKMEMBER(void, pfnTracerClose, (PCSUPDRVTRACERREG pThis, PSUPDRVSESSION pSession, uintptr_t uSessionData));
2242
2243 /**
2244 * Registers a provider.
2245 *
2246 * @returns VBox status code.
2247 * @param pThis Pointer to the registration record.
2248 * @param pCore The provider core data.
2249 *
2250 * @todo Kernel vs. Userland providers.
2251 */
2252 DECLR0CALLBACKMEMBER(int, pfnProviderRegister, (PCSUPDRVTRACERREG pThis, PSUPDRVVDTPROVIDERCORE pCore));
2253
2254 /**
2255 * Attempts to deregisters a provider.
2256 *
2257 * @returns VINF_SUCCESS or VERR_TRY_AGAIN. If the latter, the provider
2258 * should be made as harmless as possible before returning as the
2259 * VTG object and associated code will be unloaded upon return.
2260 *
2261 * @param pThis Pointer to the registration record.
2262 * @param pCore The provider core data.
2263 */
2264 DECLR0CALLBACKMEMBER(int, pfnProviderDeregister, (PCSUPDRVTRACERREG pThis, PSUPDRVVDTPROVIDERCORE pCore));
2265
2266 /**
2267 * Make another attempt at unregister a busy provider.
2268 *
2269 * @returns VINF_SUCCESS or VERR_TRY_AGAIN.
2270 * @param pThis Pointer to the registration record.
2271 * @param pCore The provider core data.
2272 */
2273 DECLR0CALLBACKMEMBER(int, pfnProviderDeregisterZombie, (PCSUPDRVTRACERREG pThis, PSUPDRVVDTPROVIDERCORE pCore));
2274
2275 /** End marker (SUPDRVTRACERREG_MAGIC). */
2276 uintptr_t uEndMagic;
2277} SUPDRVTRACERREG;
2278
2279/** Tracer magic (Kenny Garrett). */
2280#define SUPDRVTRACERREG_MAGIC UINT32_C(0x19601009)
2281/** Tracer registration structure version. */
2282#define SUPDRVTRACERREG_VERSION RT_MAKE_U32(0, 1)
2283
2284/** Pointer to a trace helper structure. */
2285typedef struct SUPDRVTRACERHLP const *PCSUPDRVTRACERHLP;
2286/**
2287 * Helper structure.
2288 */
2289typedef struct SUPDRVTRACERHLP
2290{
2291 /** The structure version (SUPDRVTRACERHLP_VERSION). */
2292 uintptr_t uVersion;
2293
2294 /** @todo ... */
2295
2296 /** End marker (SUPDRVTRACERHLP_VERSION) */
2297 uintptr_t uEndVersion;
2298} SUPDRVTRACERHLP;
2299/** Tracer helper structure version. */
2300#define SUPDRVTRACERHLP_VERSION RT_MAKE_U32(0, 1)
2301
2302SUPR0DECL(int) SUPR0TracerRegisterImpl(void *hMod, PSUPDRVSESSION pSession, PCSUPDRVTRACERREG pReg, PCSUPDRVTRACERHLP *ppHlp);
2303SUPR0DECL(int) SUPR0TracerDeregisterImpl(void *hMod, PSUPDRVSESSION pSession);
2304SUPR0DECL(int) SUPR0TracerRegisterDrv(PSUPDRVSESSION pSession, struct VTGOBJHDR *pVtgHdr, const char *pszName);
2305SUPR0DECL(void) SUPR0TracerDeregisterDrv(PSUPDRVSESSION pSession);
2306SUPR0DECL(int) SUPR0TracerRegisterModule(void *hMod, struct VTGOBJHDR *pVtgHdr);
2307SUPR0DECL(void) SUPR0TracerFireProbe(struct VTGPROBELOC *pVtgProbeLoc, uintptr_t uArg0, uintptr_t uArg1, uintptr_t uArg2,
2308 uintptr_t uArg3, uintptr_t uArg4);
2309SUPR0DECL(void) SUPR0TracerUmodProbeFire(PSUPDRVSESSION pSession, PSUPDRVTRACERUSRCTX pCtx);
2310/** @} */
2311
2312
2313/**
2314 * Service request callback function.
2315 *
2316 * @returns VBox status code.
2317 * @param pSession The caller's session.
2318 * @param uOperation The operation identifier.
2319 * @param u64Arg 64-bit integer argument.
2320 * @param pReqHdr The request header. Input / Output. Optional.
2321 */
2322typedef DECLCALLBACK(int) FNSUPR0SERVICEREQHANDLER(PSUPDRVSESSION pSession, uint32_t uOperation,
2323 uint64_t u64Arg, PSUPR0SERVICEREQHDR pReqHdr);
2324/** Pointer to a FNR0SERVICEREQHANDLER(). */
2325typedef R0PTRTYPE(FNSUPR0SERVICEREQHANDLER *) PFNSUPR0SERVICEREQHANDLER;
2326
2327
2328/** @defgroup grp_sup_r0_idc The IDC Interface
2329 * @{
2330 */
2331
2332/** The current SUPDRV IDC version.
2333 * This follows the usual high word / low word rules, i.e. high word is the
2334 * major number and it signifies incompatible interface changes. */
2335#define SUPDRV_IDC_VERSION UINT32_C(0x00010000)
2336
2337/**
2338 * Inter-Driver Communication Handle.
2339 */
2340typedef union SUPDRVIDCHANDLE
2341{
2342 /** Padding for opaque usage.
2343 * Must be greater or equal in size than the private struct. */
2344 void *apvPadding[4];
2345#ifdef SUPDRVIDCHANDLEPRIVATE_DECLARED
2346 /** The private view. */
2347 struct SUPDRVIDCHANDLEPRIVATE s;
2348#endif
2349} SUPDRVIDCHANDLE;
2350/** Pointer to a handle. */
2351typedef SUPDRVIDCHANDLE *PSUPDRVIDCHANDLE;
2352
2353SUPR0DECL(int) SUPR0IdcOpen(PSUPDRVIDCHANDLE pHandle, uint32_t uReqVersion, uint32_t uMinVersion,
2354 uint32_t *puSessionVersion, uint32_t *puDriverVersion, uint32_t *puDriverRevision);
2355SUPR0DECL(int) SUPR0IdcCall(PSUPDRVIDCHANDLE pHandle, uint32_t iReq, void *pvReq, uint32_t cbReq);
2356SUPR0DECL(int) SUPR0IdcClose(PSUPDRVIDCHANDLE pHandle);
2357SUPR0DECL(PSUPDRVSESSION) SUPR0IdcGetSession(PSUPDRVIDCHANDLE pHandle);
2358SUPR0DECL(int) SUPR0IdcComponentRegisterFactory(PSUPDRVIDCHANDLE pHandle, PCSUPDRVFACTORY pFactory);
2359SUPR0DECL(int) SUPR0IdcComponentDeregisterFactory(PSUPDRVIDCHANDLE pHandle, PCSUPDRVFACTORY pFactory);
2360
2361/** @} */
2362
2363/** @name Ring-0 module entry points.
2364 *
2365 * These can be exported by ring-0 modules SUP are told to load.
2366 *
2367 * @{ */
2368DECLEXPORT(int) ModuleInit(void *hMod);
2369DECLEXPORT(void) ModuleTerm(void *hMod);
2370/** @} */
2371
2372
2373/** @} */
2374#endif
2375
2376
2377/** @name Trust Anchors and Certificates
2378 * @{ */
2379
2380/**
2381 * Trust anchor table entry (in generated Certificates.cpp).
2382 */
2383typedef struct SUPTAENTRY
2384{
2385 /** Pointer to the raw bytes. */
2386 const unsigned char *pch;
2387 /** Number of bytes. */
2388 unsigned cb;
2389} SUPTAENTRY;
2390/** Pointer to a trust anchor table entry. */
2391typedef SUPTAENTRY const *PCSUPTAENTRY;
2392
2393/** Macro for simplifying generating the trust anchor tables. */
2394#define SUPTAENTRY_GEN(a_abTA) { &a_abTA[0], sizeof(a_abTA) }
2395
2396/** All certificates we know. */
2397extern SUPTAENTRY const g_aSUPAllTAs[];
2398/** Number of entries in g_aSUPAllTAs. */
2399extern unsigned const g_cSUPAllTAs;
2400
2401/** Software publisher certificate roots (Authenticode). */
2402extern SUPTAENTRY const g_aSUPSpcRootTAs[];
2403/** Number of entries in g_aSUPSpcRootTAs. */
2404extern unsigned const g_cSUPSpcRootTAs;
2405
2406/** Kernel root certificates used by Windows. */
2407extern SUPTAENTRY const g_aSUPNtKernelRootTAs[];
2408/** Number of entries in g_aSUPNtKernelRootTAs. */
2409extern unsigned const g_cSUPNtKernelRootTAs;
2410
2411/** Timestamp root certificates trusted by Windows. */
2412extern SUPTAENTRY const g_aSUPTimestampTAs[];
2413/** Number of entries in g_aSUPTimestampTAs. */
2414extern unsigned const g_cSUPTimestampTAs;
2415
2416/** TAs we trust (the build certificate, Oracle VirtualBox). */
2417extern SUPTAENTRY const g_aSUPTrustedTAs[];
2418/** Number of entries in g_aSUPTrustedTAs. */
2419extern unsigned const g_cSUPTrustedTAs;
2420
2421/** Supplemental certificates, like cross signing certificates. */
2422extern SUPTAENTRY const g_aSUPSupplementalTAs[];
2423/** Number of entries in g_aSUPTrustedTAs. */
2424extern unsigned const g_cSUPSupplementalTAs;
2425
2426/** The build certificate. */
2427extern const unsigned char g_abSUPBuildCert[];
2428/** The size of the build certificate. */
2429extern const unsigned g_cbSUPBuildCert;
2430
2431/** @} */
2432
2433
2434/** @} */
2435
2436RT_C_DECLS_END
2437
2438#endif
2439
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