VirtualBox

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

Last change on this file was 109029, checked in by vboxsync, 2 weeks ago

SUP,VBoxCpuReport,VMM/CPUM: Deal with core variations on arm CPUs when generating reports for them. jiraref:VBP-1598

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

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