VirtualBox

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

Last change on this file since 92703 was 92697, checked in by vboxsync, 3 years ago

SUP: Added SUPR3INIT_F_DRIVERLESS as a forced driverless option and an associated SUPR3IsDriverless(). The SUPR3INIT_F_DRIVERLESS flag requires the host specific init code to allow driverless, only done so on linux thus far. Started adjusting some of the SUPR3 APIs for driverless operation. bugref:10138

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

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