VirtualBox

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

Last change on this file since 106703 was 106635, checked in by vboxsync, 5 months ago

SUPDrv: Making it build on win.arm64... jiraref:VBP-1253

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