VirtualBox

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

Last change on this file since 96407 was 96407, checked in by vboxsync, 22 months ago

scm copyright and license note update

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

© 2023 Oracle
ContactPrivacy policyTerms of Use