[1] | 1 | /** @file
|
---|
| 2 | * SUP - Support Library.
|
---|
| 3 | */
|
---|
| 4 |
|
---|
| 5 | /*
|
---|
[2981] | 6 | * Copyright (C) 2006-2007 innotek GmbH
|
---|
[1] | 7 | *
|
---|
| 8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
| 9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
| 10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
[5999] | 11 | * General Public License (GPL) as published by the Free Software
|
---|
| 12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
| 13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
| 14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
| 15 | *
|
---|
| 16 | * The contents of this file may alternatively be used under the terms
|
---|
| 17 | * of the Common Development and Distribution License Version 1.0
|
---|
| 18 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
| 19 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
| 20 | * CDDL are applicable instead of those of the GPL.
|
---|
| 21 | *
|
---|
| 22 | * You may elect to license modified versions of this file under the
|
---|
| 23 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
[1] | 24 | */
|
---|
| 25 |
|
---|
[3632] | 26 | #ifndef ___VBox_sup_h
|
---|
| 27 | #define ___VBox_sup_h
|
---|
[1] | 28 |
|
---|
| 29 | #include <VBox/cdefs.h>
|
---|
| 30 | #include <VBox/types.h>
|
---|
[1027] | 31 | #include <iprt/assert.h>
|
---|
| 32 | #include <iprt/asm.h>
|
---|
[1] | 33 |
|
---|
| 34 | __BEGIN_DECLS
|
---|
| 35 |
|
---|
| 36 | /** @defgroup grp_sup The Support Library API
|
---|
| 37 | * @{
|
---|
| 38 | */
|
---|
| 39 |
|
---|
[3393] | 40 | /**
|
---|
[1480] | 41 | * Physical page descriptor.
|
---|
[1] | 42 | */
|
---|
| 43 | #pragma pack(4) /* space is more important. */
|
---|
| 44 | typedef struct SUPPAGE
|
---|
| 45 | {
|
---|
| 46 | /** Physical memory address. */
|
---|
| 47 | RTHCPHYS Phys;
|
---|
| 48 | /** Reserved entry for internal use by the caller. */
|
---|
| 49 | RTHCUINTPTR uReserved;
|
---|
[1480] | 50 | } SUPPAGE;
|
---|
[1] | 51 | #pragma pack()
|
---|
[1480] | 52 | /** Pointer to a page descriptor. */
|
---|
| 53 | typedef SUPPAGE *PSUPPAGE;
|
---|
| 54 | /** Pointer to a const page descriptor. */
|
---|
| 55 | typedef const SUPPAGE *PCSUPPAGE;
|
---|
[1] | 56 |
|
---|
| 57 | /**
|
---|
| 58 | * The paging mode.
|
---|
| 59 | */
|
---|
| 60 | typedef enum SUPPAGINGMODE
|
---|
| 61 | {
|
---|
| 62 | /** The usual invalid entry.
|
---|
| 63 | * This is returned by SUPGetPagingMode() */
|
---|
| 64 | SUPPAGINGMODE_INVALID = 0,
|
---|
| 65 | /** Normal 32-bit paging, no global pages */
|
---|
| 66 | SUPPAGINGMODE_32_BIT,
|
---|
| 67 | /** Normal 32-bit paging with global pages. */
|
---|
| 68 | SUPPAGINGMODE_32_BIT_GLOBAL,
|
---|
| 69 | /** PAE mode, no global pages, no NX. */
|
---|
| 70 | SUPPAGINGMODE_PAE,
|
---|
| 71 | /** PAE mode with global pages. */
|
---|
| 72 | SUPPAGINGMODE_PAE_GLOBAL,
|
---|
| 73 | /** PAE mode with NX, no global pages. */
|
---|
| 74 | SUPPAGINGMODE_PAE_NX,
|
---|
| 75 | /** PAE mode with global pages and NX. */
|
---|
| 76 | SUPPAGINGMODE_PAE_GLOBAL_NX,
|
---|
| 77 | /** AMD64 mode, no global pages. */
|
---|
| 78 | SUPPAGINGMODE_AMD64,
|
---|
| 79 | /** AMD64 mode with global pages, no NX. */
|
---|
| 80 | SUPPAGINGMODE_AMD64_GLOBAL,
|
---|
| 81 | /** AMD64 mode with NX, no global pages. */
|
---|
| 82 | SUPPAGINGMODE_AMD64_NX,
|
---|
| 83 | /** AMD64 mode with global pages and NX. */
|
---|
| 84 | SUPPAGINGMODE_AMD64_GLOBAL_NX
|
---|
| 85 | } SUPPAGINGMODE;
|
---|
| 86 |
|
---|
| 87 |
|
---|
[1027] | 88 | #pragma pack(1) /* paranoia */
|
---|
| 89 |
|
---|
[1] | 90 | /**
|
---|
[1027] | 91 | * Per CPU data.
|
---|
[3393] | 92 | * This is only used when
|
---|
[1] | 93 | */
|
---|
[1027] | 94 | typedef struct SUPGIPCPU
|
---|
[1] | 95 | {
|
---|
| 96 | /** Update transaction number.
|
---|
| 97 | * This number is incremented at the start and end of each update. It follows
|
---|
| 98 | * thusly that odd numbers indicates update in progress, while even numbers
|
---|
| 99 | * indicate stable data. Use this to make sure that the data items you fetch
|
---|
[1027] | 100 | * are consistent. */
|
---|
[1] | 101 | volatile uint32_t u32TransactionId;
|
---|
| 102 | /** The interval in TSC ticks between two NanoTS updates.
|
---|
| 103 | * This is the average interval over the last 2, 4 or 8 updates + a little slack.
|
---|
| 104 | * The slack makes the time go a tiny tiny bit slower and extends the interval enough
|
---|
[1027] | 105 | * to avoid ending up with too many 1ns increments. */
|
---|
[1] | 106 | volatile uint32_t u32UpdateIntervalTSC;
|
---|
| 107 | /** Current nanosecond timestamp. */
|
---|
| 108 | volatile uint64_t u64NanoTS;
|
---|
| 109 | /** The TSC at the time of u64NanoTS. */
|
---|
| 110 | volatile uint64_t u64TSC;
|
---|
| 111 | /** Current CPU Frequency. */
|
---|
| 112 | volatile uint64_t u64CpuHz;
|
---|
| 113 | /** Number of errors during updating.
|
---|
| 114 | * Typical errors are under/overflows. */
|
---|
| 115 | volatile uint32_t cErrors;
|
---|
| 116 | /** Index of the head item in au32TSCHistory. */
|
---|
| 117 | volatile uint32_t iTSCHistoryHead;
|
---|
| 118 | /** Array of recent TSC interval deltas.
|
---|
| 119 | * The most recent item is at index iTSCHistoryHead.
|
---|
| 120 | * This history is used to calculate u32UpdateIntervalTSC.
|
---|
| 121 | */
|
---|
| 122 | volatile uint32_t au32TSCHistory[8];
|
---|
[1027] | 123 | /** Reserved for future per processor data. */
|
---|
| 124 | volatile uint32_t au32Reserved[6];
|
---|
| 125 | } SUPGIPCPU;
|
---|
| 126 | AssertCompileSize(SUPGIPCPU, 96);
|
---|
| 127 | /*AssertCompileMemberAlignment(SUPGIPCPU, u64TSC, 8); -fixme */
|
---|
| 128 |
|
---|
[3393] | 129 | /** Pointer to per cpu data.
|
---|
| 130 | * @remark there is no const version of this typedef, see g_pSUPGlobalInfoPage for details. */
|
---|
[1027] | 131 | typedef SUPGIPCPU *PSUPGIPCPU;
|
---|
| 132 |
|
---|
| 133 | /**
|
---|
| 134 | * Global Information Page.
|
---|
| 135 | *
|
---|
| 136 | * This page contains useful information and can be mapped into any
|
---|
| 137 | * process or VM. It can be accessed thru the g_pSUPGlobalInfoPage
|
---|
| 138 | * pointer when a session is open.
|
---|
| 139 | */
|
---|
| 140 | typedef struct SUPGLOBALINFOPAGE
|
---|
| 141 | {
|
---|
| 142 | /** Magic (SUPGLOBALINFOPAGE_MAGIC). */
|
---|
| 143 | uint32_t u32Magic;
|
---|
[1840] | 144 | /** The GIP version. */
|
---|
| 145 | uint32_t u32Version;
|
---|
[1027] | 146 |
|
---|
| 147 | /** The GIP update mode, see SUPGIPMODE. */
|
---|
| 148 | uint32_t u32Mode;
|
---|
[1862] | 149 | /** Reserved / padding. */
|
---|
| 150 | uint32_t u32Padding0;
|
---|
[1027] | 151 | /** The update frequency of the of the NanoTS. */
|
---|
| 152 | volatile uint32_t u32UpdateHz;
|
---|
| 153 | /** The update interval in nanoseconds. (10^9 / u32UpdateHz) */
|
---|
| 154 | volatile uint32_t u32UpdateIntervalNS;
|
---|
[1] | 155 | /** The timestamp of the last time we update the update frequency. */
|
---|
| 156 | volatile uint64_t u64NanoTSLastUpdateHz;
|
---|
[1027] | 157 |
|
---|
| 158 | /** Padding / reserved space for future data. */
|
---|
[1862] | 159 | uint32_t au32Padding1[56];
|
---|
[1027] | 160 |
|
---|
| 161 | /** Array of per-cpu data.
|
---|
| 162 | * If u32Mode == SUPGIPMODE_SYNC_TSC then only the first entry is used.
|
---|
| 163 | * If u32Mode == SUPGIPMODE_ASYNC_TSC then the CPU ACPI ID is used as an
|
---|
| 164 | * index into the array. */
|
---|
| 165 | SUPGIPCPU aCPUs[32];
|
---|
[1] | 166 | } SUPGLOBALINFOPAGE;
|
---|
[1027] | 167 | AssertCompile(sizeof(SUPGLOBALINFOPAGE) <= 0x1000);
|
---|
| 168 | /* AssertCompileMemberAlignment(SUPGLOBALINFOPAGE, aCPU, 32); - fixme */
|
---|
| 169 |
|
---|
[3393] | 170 | /** Pointer to the global info page.
|
---|
| 171 | * @remark there is no const version of this typedef, see g_pSUPGlobalInfoPage for details. */
|
---|
[1] | 172 | typedef SUPGLOBALINFOPAGE *PSUPGLOBALINFOPAGE;
|
---|
| 173 |
|
---|
[1027] | 174 | #pragma pack() /* end of paranoia */
|
---|
[1] | 175 |
|
---|
[1027] | 176 | /** The value of the SUPGLOBALINFOPAGE::u32Magic field. (Soryo Fuyumi) */
|
---|
| 177 | #define SUPGLOBALINFOPAGE_MAGIC 0x19590106
|
---|
[3393] | 178 | /** The GIP version.
|
---|
| 179 | * Upper 16 bits is the major version. Major version is only changed with
|
---|
[1840] | 180 | * incompatible changes in the GIP. */
|
---|
| 181 | #define SUPGLOBALINFOPAGE_VERSION 0x00020000
|
---|
[1027] | 182 |
|
---|
[3393] | 183 | /**
|
---|
[1027] | 184 | * SUPGLOBALINFOPAGE::u32Mode values.
|
---|
| 185 | */
|
---|
| 186 | typedef enum SUPGIPMODE
|
---|
| 187 | {
|
---|
| 188 | /** The usual invalid null entry. */
|
---|
| 189 | SUPGIPMODE_INVALID = 0,
|
---|
| 190 | /** The TSC of the cores and cpus in the system is in sync. */
|
---|
| 191 | SUPGIPMODE_SYNC_TSC,
|
---|
| 192 | /** Each core has it's own TSC. */
|
---|
| 193 | SUPGIPMODE_ASYNC_TSC,
|
---|
| 194 | /** The usual 32-bit hack. */
|
---|
| 195 | SUPGIPMODE_32BIT_HACK = 0x7fffffff
|
---|
| 196 | } SUPGIPMODE;
|
---|
| 197 |
|
---|
[1] | 198 | /** Pointer to the Global Information Page.
|
---|
| 199 | *
|
---|
| 200 | * This pointer is valid as long as SUPLib has a open session. Anyone using
|
---|
| 201 | * the page must treat this pointer as higly volatile and not trust it beyond
|
---|
| 202 | * one transaction.
|
---|
[3393] | 203 | *
|
---|
| 204 | * @remark The GIP page is read-only to everyone but the support driver and
|
---|
| 205 | * is actually mapped read only everywhere but in ring-0. However
|
---|
| 206 | * it is not marked 'const' as this might confuse compilers into
|
---|
| 207 | * thinking that values doesn't change even if members are marked
|
---|
| 208 | * as volatile. Thus, there is no PCSUPGLOBALINFOPAGE type.
|
---|
[1] | 209 | */
|
---|
| 210 | #if defined(IN_SUP_R0) || defined(IN_SUP_R3) || defined(IN_SUP_GC)
|
---|
[3393] | 211 | extern DECLEXPORT(PSUPGLOBALINFOPAGE) g_pSUPGlobalInfoPage;
|
---|
[1] | 212 | #elif defined(IN_RING0)
|
---|
[3393] | 213 | extern DECLIMPORT(SUPGLOBALINFOPAGE) g_SUPGlobalInfoPage;
|
---|
[3641] | 214 | # if defined(__GNUC__) && !defined(RT_OS_DARWIN) && defined(RT_ARCH_AMD64)
|
---|
[335] | 215 | /** Workaround for ELF+GCC problem on 64-bit hosts.
|
---|
| 216 | * (GCC emits a mov with a R_X86_64_32 reloc, we need R_X86_64_64.) */
|
---|
[3393] | 217 | DECLINLINE(PSUPGLOBALINFOPAGE) SUPGetGIP(void)
|
---|
[335] | 218 | {
|
---|
[3393] | 219 | PSUPGLOBALINFOPAGE pGIP;
|
---|
[3283] | 220 | __asm__ __volatile__ ("movabs $g_SUPGlobalInfoPage,%0\n\t"
|
---|
[335] | 221 | : "=a" (pGIP));
|
---|
| 222 | return pGIP;
|
---|
| 223 | }
|
---|
[3393] | 224 | # define g_pSUPGlobalInfoPage (SUPGetGIP())
|
---|
[335] | 225 | # else
|
---|
[3393] | 226 | # define g_pSUPGlobalInfoPage (&g_SUPGlobalInfoPage)
|
---|
[3363] | 227 | # endif
|
---|
[1] | 228 | #else
|
---|
[3393] | 229 | extern DECLIMPORT(PSUPGLOBALINFOPAGE) g_pSUPGlobalInfoPage;
|
---|
[1] | 230 | #endif
|
---|
| 231 |
|
---|
| 232 |
|
---|
[1027] | 233 | /**
|
---|
| 234 | * Gets the TSC frequency of the calling CPU.
|
---|
[3393] | 235 | *
|
---|
[1027] | 236 | * @returns TSC frequency.
|
---|
| 237 | * @param pGip The GIP pointer.
|
---|
| 238 | */
|
---|
[3393] | 239 | DECLINLINE(uint64_t) SUPGetCpuHzFromGIP(PSUPGLOBALINFOPAGE pGip)
|
---|
[1027] | 240 | {
|
---|
| 241 | unsigned iCpu;
|
---|
[1] | 242 |
|
---|
[1027] | 243 | if (RT_UNLIKELY(!pGip || pGip->u32Magic != SUPGLOBALINFOPAGE_MAGIC))
|
---|
| 244 | return ~(uint64_t)0;
|
---|
| 245 |
|
---|
| 246 | if (pGip->u32Mode != SUPGIPMODE_ASYNC_TSC)
|
---|
| 247 | iCpu = 0;
|
---|
| 248 | else
|
---|
| 249 | {
|
---|
| 250 | iCpu = ASMGetApicId();
|
---|
| 251 | if (RT_UNLIKELY(iCpu >= RT_ELEMENTS(pGip->aCPUs)))
|
---|
| 252 | return ~(uint64_t)0;
|
---|
| 253 | }
|
---|
| 254 |
|
---|
| 255 | return pGip->aCPUs[iCpu].u64CpuHz;
|
---|
| 256 | }
|
---|
| 257 |
|
---|
| 258 |
|
---|
[4800] | 259 | /**
|
---|
| 260 | * Request for generic VMMR0Entry calls.
|
---|
| 261 | */
|
---|
| 262 | typedef struct SUPVMMR0REQHDR
|
---|
| 263 | {
|
---|
| 264 | /** The magic. (SUPVMMR0REQHDR_MAGIC) */
|
---|
| 265 | uint32_t u32Magic;
|
---|
| 266 | /** The size of the request. */
|
---|
| 267 | uint32_t cbReq;
|
---|
| 268 | } SUPVMMR0REQHDR;
|
---|
| 269 | /** Pointer to a ring-0 request header. */
|
---|
| 270 | typedef SUPVMMR0REQHDR *PSUPVMMR0REQHDR;
|
---|
| 271 | /** the SUPVMMR0REQHDR::u32Magic value (Ethan Iverson - The Bad Plus). */
|
---|
| 272 | #define SUPVMMR0REQHDR_MAGIC UINT32_C(0x19730211)
|
---|
| 273 |
|
---|
| 274 |
|
---|
[4811] | 275 | /** For the fast ioctl path.
|
---|
| 276 | * @{
|
---|
| 277 | */
|
---|
| 278 | /** @see VMMR0_DO_RAW_RUN. */
|
---|
| 279 | #define SUP_VMMR0_DO_RAW_RUN 0
|
---|
| 280 | /** @see VMMR0_DO_HWACC_RUN. */
|
---|
| 281 | #define SUP_VMMR0_DO_HWACC_RUN 1
|
---|
| 282 | /** @see VMMR0_DO_NOP */
|
---|
| 283 | #define SUP_VMMR0_DO_NOP 2
|
---|
| 284 | /** @} */
|
---|
[4800] | 285 |
|
---|
[4811] | 286 |
|
---|
| 287 |
|
---|
[1] | 288 | #ifdef IN_RING3
|
---|
| 289 |
|
---|
| 290 | /** @defgroup grp_sup_r3 SUP Host Context Ring 3 API
|
---|
| 291 | * @ingroup grp_sup
|
---|
| 292 | * @{
|
---|
| 293 | */
|
---|
| 294 |
|
---|
| 295 | /**
|
---|
| 296 | * Installs the support library.
|
---|
| 297 | *
|
---|
| 298 | * @returns VBox status code.
|
---|
| 299 | */
|
---|
| 300 | SUPR3DECL(int) SUPInstall(void);
|
---|
| 301 |
|
---|
| 302 | /**
|
---|
| 303 | * Uninstalls the support library.
|
---|
| 304 | *
|
---|
| 305 | * @returns VBox status code.
|
---|
| 306 | */
|
---|
| 307 | SUPR3DECL(int) SUPUninstall(void);
|
---|
| 308 |
|
---|
| 309 | /**
|
---|
| 310 | * Initializes the support library.
|
---|
| 311 | * Each succesful call to SUPInit() must be countered by a
|
---|
| 312 | * call to SUPTerm(false).
|
---|
| 313 | *
|
---|
| 314 | * @returns VBox status code.
|
---|
| 315 | * @param ppSession Where to store the session handle. Defaults to NULL.
|
---|
| 316 | * @param cbReserve The number of bytes of contiguous memory that should be reserved by
|
---|
| 317 | * the runtime / support library.
|
---|
| 318 | * Set this to 0 if no reservation is required. (default)
|
---|
| 319 | * Set this to ~0 if the maximum amount supported by the VM is to be
|
---|
| 320 | * attempted reserved, or the maximum available.
|
---|
| 321 | */
|
---|
| 322 | #ifdef __cplusplus
|
---|
| 323 | SUPR3DECL(int) SUPInit(PSUPDRVSESSION *ppSession = NULL, size_t cbReserve = 0);
|
---|
| 324 | #else
|
---|
| 325 | SUPR3DECL(int) SUPInit(PSUPDRVSESSION *ppSession, size_t cbReserve);
|
---|
| 326 | #endif
|
---|
| 327 |
|
---|
| 328 | /**
|
---|
| 329 | * Terminates the support library.
|
---|
| 330 | *
|
---|
| 331 | * @returns VBox status code.
|
---|
| 332 | * @param fForced Forced termination. This means to ignore the
|
---|
| 333 | * init call count and just terminated.
|
---|
| 334 | */
|
---|
| 335 | #ifdef __cplusplus
|
---|
| 336 | SUPR3DECL(int) SUPTerm(bool fForced = false);
|
---|
| 337 | #else
|
---|
| 338 | SUPR3DECL(int) SUPTerm(int fForced);
|
---|
| 339 | #endif
|
---|
| 340 |
|
---|
| 341 | /**
|
---|
| 342 | * Sets the ring-0 VM handle for use with fast IOCtls.
|
---|
| 343 | *
|
---|
| 344 | * @returns VBox status code.
|
---|
| 345 | * @param pVMR0 The ring-0 VM handle.
|
---|
| 346 | * NIL_RTR0PTR can be used to unset the handle when the
|
---|
| 347 | * VM is about to be destroyed.
|
---|
| 348 | */
|
---|
| 349 | SUPR3DECL(int) SUPSetVMForFastIOCtl(PVMR0 pVMR0);
|
---|
| 350 |
|
---|
| 351 | /**
|
---|
| 352 | * Calls the HC R0 VMM entry point.
|
---|
| 353 | * See VMMR0Entry() for more details.
|
---|
| 354 | *
|
---|
| 355 | * @returns error code specific to uFunction.
|
---|
[914] | 356 | * @param pVMR0 Pointer to the Ring-0 (Host Context) mapping of the VM structure.
|
---|
[1] | 357 | * @param uOperation Operation to execute.
|
---|
| 358 | * @param pvArg Argument.
|
---|
| 359 | */
|
---|
[914] | 360 | SUPR3DECL(int) SUPCallVMMR0(PVMR0 pVMR0, unsigned uOperation, void *pvArg);
|
---|
[1] | 361 |
|
---|
| 362 | /**
|
---|
[4811] | 363 | * Variant of SUPCallVMMR0, except that this takes the fast ioclt path
|
---|
| 364 | * regardsless of compile-time defaults.
|
---|
| 365 | *
|
---|
| 366 | * @returns VBox status code.
|
---|
| 367 | * @param pVMR0 The ring-0 VM handle.
|
---|
| 368 | * @param uOperation The operation; only the SUP_VMMR0_DO_* ones are valid.
|
---|
| 369 | */
|
---|
| 370 | SUPR3DECL(int) SUPCallVMMR0Fast(PVMR0 pVMR0, unsigned uOperation);
|
---|
| 371 |
|
---|
| 372 | /**
|
---|
[1] | 373 | * Calls the HC R0 VMM entry point, in a safer but slower manner than SUPCallVMMR0.
|
---|
| 374 | * When entering using this call the R0 components can call into the host kernel
|
---|
| 375 | * (i.e. use the SUPR0 and RT APIs).
|
---|
| 376 | *
|
---|
| 377 | * See VMMR0Entry() for more details.
|
---|
| 378 | *
|
---|
| 379 | * @returns error code specific to uFunction.
|
---|
[914] | 380 | * @param pVMR0 Pointer to the Ring-0 (Host Context) mapping of the VM structure.
|
---|
[1] | 381 | * @param uOperation Operation to execute.
|
---|
[4811] | 382 | * @param u64Arg Constant argument.
|
---|
| 383 | * @param pReqHdr Pointer to a request header. Optional.
|
---|
| 384 | * This will be copied in and out of kernel space. There currently is a size
|
---|
| 385 | * limit on this, just below 4KB.
|
---|
[1] | 386 | */
|
---|
[4811] | 387 | SUPR3DECL(int) SUPCallVMMR0Ex(PVMR0 pVMR0, unsigned uOperation, uint64_t u64Arg, PSUPVMMR0REQHDR pReqHdr);
|
---|
[1] | 388 |
|
---|
| 389 | /**
|
---|
| 390 | * Queries the paging mode of the host OS.
|
---|
| 391 | *
|
---|
| 392 | * @returns The paging mode.
|
---|
| 393 | */
|
---|
| 394 | SUPR3DECL(SUPPAGINGMODE) SUPGetPagingMode(void);
|
---|
| 395 |
|
---|
| 396 | /**
|
---|
| 397 | * Allocate zero-filled pages.
|
---|
| 398 | *
|
---|
| 399 | * Use this to allocate a number of pages rather than using RTMem*() and mess with
|
---|
| 400 | * alignment. The returned address is of course page aligned. Call SUPPageFree()
|
---|
| 401 | * to free the pages once done with them.
|
---|
| 402 | *
|
---|
| 403 | * @returns VBox status.
|
---|
[4800] | 404 | * @param cPages Number of pages to allocate.
|
---|
| 405 | * @param ppvPages Where to store the base pointer to the allocated pages.
|
---|
[1] | 406 | */
|
---|
| 407 | SUPR3DECL(int) SUPPageAlloc(size_t cPages, void **ppvPages);
|
---|
| 408 |
|
---|
| 409 | /**
|
---|
| 410 | * Frees pages allocated with SUPPageAlloc().
|
---|
| 411 | *
|
---|
| 412 | * @returns VBox status.
|
---|
[4800] | 413 | * @param pvPages Pointer returned by SUPPageAlloc().
|
---|
| 414 | * @param cPages Number of pages that was allocated.
|
---|
[1] | 415 | */
|
---|
[1890] | 416 | SUPR3DECL(int) SUPPageFree(void *pvPages, size_t cPages);
|
---|
[1] | 417 |
|
---|
| 418 | /**
|
---|
[4765] | 419 | * Allocate zero-filled locked pages.
|
---|
| 420 | *
|
---|
| 421 | * Use this to allocate a number of pages rather than using RTMem*() and mess with
|
---|
| 422 | * alignment. The returned address is of course page aligned. Call SUPPageFreeLocked()
|
---|
| 423 | * to free the pages once done with them.
|
---|
| 424 | *
|
---|
| 425 | * @returns VBox status.
|
---|
[4800] | 426 | * @param cPages Number of pages to allocate.
|
---|
| 427 | * @param ppvPages Where to store the base pointer to the allocated pages.
|
---|
[4765] | 428 | */
|
---|
| 429 | SUPR3DECL(int) SUPPageAllocLocked(size_t cPages, void **ppvPages);
|
---|
| 430 |
|
---|
| 431 | /**
|
---|
[4800] | 432 | * Allocate zero-filled locked pages.
|
---|
| 433 | *
|
---|
| 434 | * Use this to allocate a number of pages rather than using RTMem*() and mess with
|
---|
| 435 | * alignment. The returned address is of course page aligned. Call SUPPageFreeLocked()
|
---|
| 436 | * to free the pages once done with them.
|
---|
| 437 | *
|
---|
| 438 | * @returns VBox status code.
|
---|
| 439 | * @param cPages Number of pages to allocate.
|
---|
| 440 | * @param ppvPages Where to store the base pointer to the allocated pages.
|
---|
| 441 | * @param paPages Where to store the physical page addresses returned.
|
---|
| 442 | * On entry this will point to an array of with cbMemory >> PAGE_SHIFT entries.
|
---|
| 443 | * NULL is allowed.
|
---|
| 444 | */
|
---|
| 445 | SUPR3DECL(int) SUPPageAllocLockedEx(size_t cPages, void **ppvPages, PSUPPAGE paPages);
|
---|
| 446 |
|
---|
| 447 | /**
|
---|
[4765] | 448 | * Frees locked pages allocated with SUPPageAllocLocked().
|
---|
| 449 | *
|
---|
| 450 | * @returns VBox status.
|
---|
[4800] | 451 | * @param pvPages Pointer returned by SUPPageAlloc().
|
---|
| 452 | * @param cPages Number of pages that was allocated.
|
---|
[4765] | 453 | */
|
---|
| 454 | SUPR3DECL(int) SUPPageFreeLocked(void *pvPages, size_t cPages);
|
---|
| 455 |
|
---|
| 456 | /**
|
---|
[1] | 457 | * Locks down the physical memory backing a virtual memory
|
---|
| 458 | * range in the current process.
|
---|
| 459 | *
|
---|
| 460 | * @returns VBox status code.
|
---|
| 461 | * @param pvStart Start of virtual memory range.
|
---|
| 462 | * Must be page aligned.
|
---|
[1890] | 463 | * @param cPages Number of pages.
|
---|
[1] | 464 | * @param paPages Where to store the physical page addresses returned.
|
---|
| 465 | * On entry this will point to an array of with cbMemory >> PAGE_SHIFT entries.
|
---|
| 466 | */
|
---|
[1890] | 467 | SUPR3DECL(int) SUPPageLock(void *pvStart, size_t cPages, PSUPPAGE paPages);
|
---|
[1] | 468 |
|
---|
| 469 | /**
|
---|
| 470 | * Releases locked down pages.
|
---|
| 471 | *
|
---|
| 472 | * @returns VBox status code.
|
---|
| 473 | * @param pvStart Start of virtual memory range previously locked
|
---|
| 474 | * down by SUPPageLock().
|
---|
| 475 | */
|
---|
| 476 | SUPR3DECL(int) SUPPageUnlock(void *pvStart);
|
---|
| 477 |
|
---|
| 478 | /**
|
---|
| 479 | * Allocated memory with page aligned memory with a contiguous and locked physical
|
---|
| 480 | * memory backing below 4GB.
|
---|
| 481 | *
|
---|
| 482 | * @returns Pointer to the allocated memory (virtual address).
|
---|
| 483 | * *pHCPhys is set to the physical address of the memory.
|
---|
| 484 | * The returned memory must be freed using SUPContFree().
|
---|
| 485 | * @returns NULL on failure.
|
---|
[1890] | 486 | * @param cPages Number of pages to allocate.
|
---|
[1] | 487 | * @param pHCPhys Where to store the physical address of the memory block.
|
---|
| 488 | */
|
---|
[1890] | 489 | SUPR3DECL(void *) SUPContAlloc(size_t cPages, PRTHCPHYS pHCPhys);
|
---|
[1] | 490 |
|
---|
| 491 | /**
|
---|
| 492 | * Allocated memory with page aligned memory with a contiguous and locked physical
|
---|
| 493 | * memory backing below 4GB.
|
---|
| 494 | *
|
---|
| 495 | * @returns Pointer to the allocated memory (virtual address).
|
---|
| 496 | * *pHCPhys is set to the physical address of the memory.
|
---|
| 497 | * If ppvR0 isn't NULL, *ppvR0 is set to the ring-0 mapping.
|
---|
| 498 | * The returned memory must be freed using SUPContFree().
|
---|
| 499 | * @returns NULL on failure.
|
---|
[1890] | 500 | * @param cPages Number of pages to allocate.
|
---|
[914] | 501 | * @param pR0Ptr Where to store the ring-0 mapping of the allocation. (optional)
|
---|
[1] | 502 | * @param pHCPhys Where to store the physical address of the memory block.
|
---|
| 503 | *
|
---|
| 504 | * @remark This 2nd version of this API exists because we're not able to map the
|
---|
| 505 | * ring-3 mapping executable on WIN64. This is a serious problem in regard to
|
---|
| 506 | * the world switchers.
|
---|
| 507 | */
|
---|
[1890] | 508 | SUPR3DECL(void *) SUPContAlloc2(size_t cPages, PRTR0PTR pR0Ptr, PRTHCPHYS pHCPhys);
|
---|
[1] | 509 |
|
---|
| 510 | /**
|
---|
| 511 | * Frees memory allocated with SUPContAlloc().
|
---|
| 512 | *
|
---|
| 513 | * @returns VBox status code.
|
---|
[1890] | 514 | * @param pv Pointer to the memory block which should be freed.
|
---|
| 515 | * @param cPages Number of pages to be freed.
|
---|
[1] | 516 | */
|
---|
[1890] | 517 | SUPR3DECL(int) SUPContFree(void *pv, size_t cPages);
|
---|
[1] | 518 |
|
---|
| 519 | /**
|
---|
| 520 | * Allocated non contiguous physical memory below 4GB.
|
---|
| 521 | *
|
---|
[6791] | 522 | * The memory isn't zeroed.
|
---|
| 523 | *
|
---|
[1] | 524 | * @returns VBox status code.
|
---|
| 525 | * @returns NULL on failure.
|
---|
| 526 | * @param cPages Number of pages to allocate.
|
---|
| 527 | * @param ppvPages Where to store the pointer to the allocated memory.
|
---|
| 528 | * The pointer stored here on success must be passed to SUPLowFree when
|
---|
| 529 | * the memory should be released.
|
---|
[1480] | 530 | * @param ppvPagesR0 Where to store the ring-0 pointer to the allocated memory. optional.
|
---|
[1] | 531 | * @param paPages Where to store the physical addresses of the individual pages.
|
---|
| 532 | */
|
---|
[1890] | 533 | SUPR3DECL(int) SUPLowAlloc(size_t cPages, void **ppvPages, PRTR0PTR ppvPagesR0, PSUPPAGE paPages);
|
---|
[1] | 534 |
|
---|
| 535 | /**
|
---|
| 536 | * Frees memory allocated with SUPLowAlloc().
|
---|
| 537 | *
|
---|
| 538 | * @returns VBox status code.
|
---|
[1890] | 539 | * @param pv Pointer to the memory block which should be freed.
|
---|
[2014] | 540 | * @param cPages Number of pages that was allocated.
|
---|
[1] | 541 | */
|
---|
[1890] | 542 | SUPR3DECL(int) SUPLowFree(void *pv, size_t cPages);
|
---|
[1] | 543 |
|
---|
| 544 | /**
|
---|
| 545 | * Load a module into R0 HC.
|
---|
| 546 | *
|
---|
| 547 | * @returns VBox status code.
|
---|
| 548 | * @param pszFilename The path to the image file.
|
---|
| 549 | * @param pszModule The module name. Max 32 bytes.
|
---|
| 550 | */
|
---|
| 551 | SUPR3DECL(int) SUPLoadModule(const char *pszFilename, const char *pszModule, void **ppvImageBase);
|
---|
| 552 |
|
---|
| 553 | /**
|
---|
| 554 | * Frees a R0 HC module.
|
---|
| 555 | *
|
---|
| 556 | * @returns VBox status code.
|
---|
| 557 | * @param pszModule The module to free.
|
---|
| 558 | * @remark This will not actually 'free' the module, there are of course usage counting.
|
---|
| 559 | */
|
---|
| 560 | SUPR3DECL(int) SUPFreeModule(void *pvImageBase);
|
---|
| 561 |
|
---|
| 562 | /**
|
---|
| 563 | * Get the address of a symbol in a ring-0 module.
|
---|
| 564 | *
|
---|
| 565 | * @returns VBox status code.
|
---|
| 566 | * @param pszModule The module name.
|
---|
| 567 | * @param pszSymbol Symbol name. If it's value is less than 64k it's treated like a
|
---|
| 568 | * ordinal value rather than a string pointer.
|
---|
| 569 | * @param ppvValue Where to store the symbol value.
|
---|
| 570 | */
|
---|
| 571 | SUPR3DECL(int) SUPGetSymbolR0(void *pvImageBase, const char *pszSymbol, void **ppvValue);
|
---|
| 572 |
|
---|
| 573 | /**
|
---|
| 574 | * Load R0 HC VMM code.
|
---|
| 575 | *
|
---|
| 576 | * @returns VBox status code.
|
---|
| 577 | * @deprecated Use SUPLoadModule(pszFilename, "VMMR0.r0", &pvImageBase)
|
---|
| 578 | */
|
---|
| 579 | SUPR3DECL(int) SUPLoadVMM(const char *pszFilename);
|
---|
| 580 |
|
---|
| 581 | /**
|
---|
| 582 | * Unloads R0 HC VMM code.
|
---|
| 583 | *
|
---|
| 584 | * @returns VBox status code.
|
---|
| 585 | * @deprecated Use SUPFreeModule().
|
---|
| 586 | */
|
---|
| 587 | SUPR3DECL(int) SUPUnloadVMM(void);
|
---|
| 588 |
|
---|
| 589 | /**
|
---|
| 590 | * Get the physical address of the GIP.
|
---|
| 591 | *
|
---|
| 592 | * @returns VBox status code.
|
---|
| 593 | * @param pHCPhys Where to store the physical address of the GIP.
|
---|
| 594 | */
|
---|
| 595 | SUPR3DECL(int) SUPGipGetPhys(PRTHCPHYS pHCPhys);
|
---|
| 596 |
|
---|
| 597 | /** @} */
|
---|
| 598 | #endif /* IN_RING3 */
|
---|
| 599 |
|
---|
| 600 |
|
---|
| 601 | #ifdef IN_RING0
|
---|
| 602 | /** @defgroup grp_sup_r0 SUP Host Context Ring 0 API
|
---|
| 603 | * @ingroup grp_sup
|
---|
| 604 | * @{
|
---|
| 605 | */
|
---|
| 606 |
|
---|
| 607 | /**
|
---|
[7206] | 608 | * Execute callback on all cpus/cores (SUPR0ExecuteCallback)
|
---|
| 609 | */
|
---|
| 610 | #define SUPDRVEXECCALLBACK_CPU_ALL (~0)
|
---|
| 611 |
|
---|
| 612 | /**
|
---|
[1] | 613 | * Security objectype.
|
---|
| 614 | */
|
---|
| 615 | typedef enum SUPDRVOBJTYPE
|
---|
| 616 | {
|
---|
| 617 | /** The usual invalid object. */
|
---|
| 618 | SUPDRVOBJTYPE_INVALID = 0,
|
---|
[4971] | 619 | /** A Virtual Machine instance. */
|
---|
| 620 | SUPDRVOBJTYPE_VM,
|
---|
[1] | 621 | /** Internal network. */
|
---|
| 622 | SUPDRVOBJTYPE_INTERNAL_NETWORK,
|
---|
| 623 | /** Internal network interface. */
|
---|
| 624 | SUPDRVOBJTYPE_INTERNAL_NETWORK_INTERFACE,
|
---|
| 625 | /** The first invalid object type in this end. */
|
---|
| 626 | SUPDRVOBJTYPE_END,
|
---|
| 627 | /** The usual 32-bit type size hack. */
|
---|
| 628 | SUPDRVOBJTYPE_32_BIT_HACK = 0x7ffffff
|
---|
| 629 | } SUPDRVOBJTYPE;
|
---|
| 630 |
|
---|
| 631 | /**
|
---|
| 632 | * Object destructor callback.
|
---|
| 633 | * This is called for reference counted objectes when the count reaches 0.
|
---|
| 634 | *
|
---|
| 635 | * @param pvObj The object pointer.
|
---|
| 636 | * @param pvUser1 The first user argument.
|
---|
| 637 | * @param pvUser2 The second user argument.
|
---|
| 638 | */
|
---|
| 639 | typedef DECLCALLBACK(void) FNSUPDRVDESTRUCTOR(void *pvObj, void *pvUser1, void *pvUser2);
|
---|
| 640 | /** Pointer to a FNSUPDRVDESTRUCTOR(). */
|
---|
| 641 | typedef FNSUPDRVDESTRUCTOR *PFNSUPDRVDESTRUCTOR;
|
---|
| 642 |
|
---|
| 643 | SUPR0DECL(void *) SUPR0ObjRegister(PSUPDRVSESSION pSession, SUPDRVOBJTYPE enmType, PFNSUPDRVDESTRUCTOR pfnDestructor, void *pvUser1, void *pvUser2);
|
---|
| 644 | SUPR0DECL(int) SUPR0ObjAddRef(void *pvObj, PSUPDRVSESSION pSession);
|
---|
| 645 | SUPR0DECL(int) SUPR0ObjRelease(void *pvObj, PSUPDRVSESSION pSession);
|
---|
| 646 | SUPR0DECL(int) SUPR0ObjVerifyAccess(void *pvObj, PSUPDRVSESSION pSession, const char *pszObjName);
|
---|
| 647 |
|
---|
[4800] | 648 | SUPR0DECL(int) SUPR0LockMem(PSUPDRVSESSION pSession, RTR3PTR pvR3, uint32_t cPages, PRTHCPHYS paPages);
|
---|
[1480] | 649 | SUPR0DECL(int) SUPR0UnlockMem(PSUPDRVSESSION pSession, RTR3PTR pvR3);
|
---|
[1890] | 650 | SUPR0DECL(int) SUPR0ContAlloc(PSUPDRVSESSION pSession, uint32_t cPages, PRTR0PTR ppvR0, PRTR3PTR ppvR3, PRTHCPHYS pHCPhys);
|
---|
[1480] | 651 | SUPR0DECL(int) SUPR0ContFree(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr);
|
---|
[4800] | 652 | SUPR0DECL(int) SUPR0LowAlloc(PSUPDRVSESSION pSession, uint32_t cPages, PRTR0PTR ppvR0, PRTR3PTR ppvR3, PRTHCPHYS paPages);
|
---|
[1480] | 653 | SUPR0DECL(int) SUPR0LowFree(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr);
|
---|
| 654 | SUPR0DECL(int) SUPR0MemAlloc(PSUPDRVSESSION pSession, uint32_t cb, PRTR0PTR ppvR0, PRTR3PTR ppvR3);
|
---|
| 655 | SUPR0DECL(int) SUPR0MemGetPhys(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr, PSUPPAGE paPages);
|
---|
| 656 | SUPR0DECL(int) SUPR0MemFree(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr);
|
---|
[4800] | 657 | SUPR0DECL(int) SUPR0PageAlloc(PSUPDRVSESSION pSession, uint32_t cPages, PRTR3PTR ppvR3, PRTHCPHYS paPages);
|
---|
| 658 | SUPR0DECL(int) SUPR0PageFree(PSUPDRVSESSION pSession, RTR3PTR pvR3);
|
---|
| 659 | SUPR0DECL(int) SUPR0GipMap(PSUPDRVSESSION pSession, PRTR3PTR ppGipR3, PRTHCPHYS pHCPhysGip);
|
---|
[1] | 660 | SUPR0DECL(int) SUPR0GipUnmap(PSUPDRVSESSION pSession);
|
---|
| 661 | SUPR0DECL(int) SUPR0Printf(const char *pszFormat, ...);
|
---|
| 662 |
|
---|
| 663 | /** @} */
|
---|
| 664 | #endif
|
---|
| 665 |
|
---|
| 666 | /** @} */
|
---|
| 667 |
|
---|
| 668 | __END_DECLS
|
---|
| 669 |
|
---|
| 670 | #endif
|
---|
| 671 |
|
---|