VirtualBox

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

Last change on this file since 95771 was 95124, checked in by vboxsync, 3 years ago

sup.h: bugref:10209 Fix comment clarifying SUPR0FpuEnd usage.

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

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