VirtualBox

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

Last change on this file was 103684, checked in by vboxsync, 2 months ago

Linux kernel modules: Fix UBSAN warnings by switching to flexible arrays where possible, bugref:10585.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use