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