VirtualBox

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

Last change on this file since 97964 was 97262, checked in by vboxsync, 2 years ago

VMM: Nested VMX: bugref:10092 Added fetching VM-exit secondary MSR from the support driver. Updated the virtual VMCS with latest VMCS fields (HLAT prefix size, HLAT ptr, secondary VM-exit controls and PCONFIG-exiting bitmap).

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

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