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