VirtualBox

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

Last change on this file since 15382 was 14901, checked in by vboxsync, 16 years ago

SUPDrv,SUPLib: SUPR0NativeEnableHwVirtExt -> SUPR0EnableVTx and darwin implementation - version changed again.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 34.2 KB
Line 
1/** @file
2 * SUP - Support Library.
3 */
4
5/*
6 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 *
25 * 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.
28 */
29
30#ifndef ___VBox_sup_h
31#define ___VBox_sup_h
32
33#include <VBox/cdefs.h>
34#include <VBox/types.h>
35#include <iprt/assert.h>
36#include <iprt/stdarg.h>
37#include <iprt/asm.h>
38
39__BEGIN_DECLS
40
41/** @defgroup grp_sup The Support Library API
42 * @{
43 */
44
45/**
46 * Physical page descriptor.
47 */
48#pragma pack(4) /* space is more important. */
49typedef struct SUPPAGE
50{
51 /** Physical memory address. */
52 RTHCPHYS Phys;
53 /** Reserved entry for internal use by the caller. */
54 RTHCUINTPTR uReserved;
55} SUPPAGE;
56#pragma pack()
57/** Pointer to a page descriptor. */
58typedef SUPPAGE *PSUPPAGE;
59/** Pointer to a const page descriptor. */
60typedef const SUPPAGE *PCSUPPAGE;
61
62/**
63 * The paging mode.
64 */
65typedef enum SUPPAGINGMODE
66{
67 /** The usual invalid entry.
68 * This is returned by SUPGetPagingMode() */
69 SUPPAGINGMODE_INVALID = 0,
70 /** Normal 32-bit paging, no global pages */
71 SUPPAGINGMODE_32_BIT,
72 /** Normal 32-bit paging with global pages. */
73 SUPPAGINGMODE_32_BIT_GLOBAL,
74 /** PAE mode, no global pages, no NX. */
75 SUPPAGINGMODE_PAE,
76 /** PAE mode with global pages. */
77 SUPPAGINGMODE_PAE_GLOBAL,
78 /** PAE mode with NX, no global pages. */
79 SUPPAGINGMODE_PAE_NX,
80 /** PAE mode with global pages and NX. */
81 SUPPAGINGMODE_PAE_GLOBAL_NX,
82 /** AMD64 mode, no global pages. */
83 SUPPAGINGMODE_AMD64,
84 /** AMD64 mode with global pages, no NX. */
85 SUPPAGINGMODE_AMD64_GLOBAL,
86 /** AMD64 mode with NX, no global pages. */
87 SUPPAGINGMODE_AMD64_NX,
88 /** AMD64 mode with global pages and NX. */
89 SUPPAGINGMODE_AMD64_GLOBAL_NX
90} SUPPAGINGMODE;
91
92
93#pragma pack(1) /* paranoia */
94
95/**
96 * Per CPU data.
97 * This is only used when
98 */
99typedef struct SUPGIPCPU
100{
101 /** Update transaction number.
102 * This number is incremented at the start and end of each update. It follows
103 * thusly that odd numbers indicates update in progress, while even numbers
104 * indicate stable data. Use this to make sure that the data items you fetch
105 * are consistent. */
106 volatile uint32_t u32TransactionId;
107 /** The interval in TSC ticks between two NanoTS updates.
108 * This is the average interval over the last 2, 4 or 8 updates + a little slack.
109 * The slack makes the time go a tiny tiny bit slower and extends the interval enough
110 * to avoid ending up with too many 1ns increments. */
111 volatile uint32_t u32UpdateIntervalTSC;
112 /** Current nanosecond timestamp. */
113 volatile uint64_t u64NanoTS;
114 /** The TSC at the time of u64NanoTS. */
115 volatile uint64_t u64TSC;
116 /** Current CPU Frequency. */
117 volatile uint64_t u64CpuHz;
118 /** Number of errors during updating.
119 * Typical errors are under/overflows. */
120 volatile uint32_t cErrors;
121 /** Index of the head item in au32TSCHistory. */
122 volatile uint32_t iTSCHistoryHead;
123 /** Array of recent TSC interval deltas.
124 * The most recent item is at index iTSCHistoryHead.
125 * This history is used to calculate u32UpdateIntervalTSC.
126 */
127 volatile uint32_t au32TSCHistory[8];
128 /** Reserved for future per processor data. */
129 volatile uint32_t au32Reserved[6];
130} SUPGIPCPU;
131AssertCompileSize(SUPGIPCPU, 96);
132/*AssertCompileMemberAlignment(SUPGIPCPU, u64TSC, 8); -fixme */
133
134/** Pointer to per cpu data.
135 * @remark there is no const version of this typedef, see g_pSUPGlobalInfoPage for details. */
136typedef SUPGIPCPU *PSUPGIPCPU;
137
138/**
139 * Global Information Page.
140 *
141 * This page contains useful information and can be mapped into any
142 * process or VM. It can be accessed thru the g_pSUPGlobalInfoPage
143 * pointer when a session is open.
144 */
145typedef struct SUPGLOBALINFOPAGE
146{
147 /** Magic (SUPGLOBALINFOPAGE_MAGIC). */
148 uint32_t u32Magic;
149 /** The GIP version. */
150 uint32_t u32Version;
151
152 /** The GIP update mode, see SUPGIPMODE. */
153 uint32_t u32Mode;
154 /** Reserved / padding. */
155 uint32_t u32Padding0;
156 /** The update frequency of the of the NanoTS. */
157 volatile uint32_t u32UpdateHz;
158 /** The update interval in nanoseconds. (10^9 / u32UpdateHz) */
159 volatile uint32_t u32UpdateIntervalNS;
160 /** The timestamp of the last time we update the update frequency. */
161 volatile uint64_t u64NanoTSLastUpdateHz;
162
163 /** Padding / reserved space for future data. */
164 uint32_t au32Padding1[56];
165
166 /** Array of per-cpu data.
167 * If u32Mode == SUPGIPMODE_SYNC_TSC then only the first entry is used.
168 * If u32Mode == SUPGIPMODE_ASYNC_TSC then the CPU ACPI ID is used as an
169 * index into the array. */
170 SUPGIPCPU aCPUs[32];
171} SUPGLOBALINFOPAGE;
172AssertCompile(sizeof(SUPGLOBALINFOPAGE) <= 0x1000);
173/* AssertCompileMemberAlignment(SUPGLOBALINFOPAGE, aCPU, 32); - fixme */
174
175/** Pointer to the global info page.
176 * @remark there is no const version of this typedef, see g_pSUPGlobalInfoPage for details. */
177typedef SUPGLOBALINFOPAGE *PSUPGLOBALINFOPAGE;
178
179#pragma pack() /* end of paranoia */
180
181/** The value of the SUPGLOBALINFOPAGE::u32Magic field. (Soryo Fuyumi) */
182#define SUPGLOBALINFOPAGE_MAGIC 0x19590106
183/** The GIP version.
184 * Upper 16 bits is the major version. Major version is only changed with
185 * incompatible changes in the GIP. */
186#define SUPGLOBALINFOPAGE_VERSION 0x00020000
187
188/**
189 * SUPGLOBALINFOPAGE::u32Mode values.
190 */
191typedef enum SUPGIPMODE
192{
193 /** The usual invalid null entry. */
194 SUPGIPMODE_INVALID = 0,
195 /** The TSC of the cores and cpus in the system is in sync. */
196 SUPGIPMODE_SYNC_TSC,
197 /** Each core has it's own TSC. */
198 SUPGIPMODE_ASYNC_TSC,
199 /** The usual 32-bit hack. */
200 SUPGIPMODE_32BIT_HACK = 0x7fffffff
201} SUPGIPMODE;
202
203/** Pointer to the Global Information Page.
204 *
205 * This pointer is valid as long as SUPLib has a open session. Anyone using
206 * the page must treat this pointer as higly volatile and not trust it beyond
207 * one transaction.
208 *
209 * @remark The GIP page is read-only to everyone but the support driver and
210 * is actually mapped read only everywhere but in ring-0. However
211 * it is not marked 'const' as this might confuse compilers into
212 * thinking that values doesn't change even if members are marked
213 * as volatile. Thus, there is no PCSUPGLOBALINFOPAGE type.
214 */
215#if defined(IN_SUP_R0) || defined(IN_SUP_R3) || defined(IN_SUP_GC)
216extern DECLEXPORT(PSUPGLOBALINFOPAGE) g_pSUPGlobalInfoPage;
217#elif defined(IN_RING0)
218extern DECLIMPORT(SUPGLOBALINFOPAGE) g_SUPGlobalInfoPage;
219# if defined(__GNUC__) && !defined(RT_OS_DARWIN) && defined(RT_ARCH_AMD64)
220/** Workaround for ELF+GCC problem on 64-bit hosts.
221 * (GCC emits a mov with a R_X86_64_32 reloc, we need R_X86_64_64.) */
222DECLINLINE(PSUPGLOBALINFOPAGE) SUPGetGIP(void)
223{
224 PSUPGLOBALINFOPAGE pGIP;
225 __asm__ __volatile__ ("movabs $g_SUPGlobalInfoPage,%0\n\t"
226 : "=a" (pGIP));
227 return pGIP;
228}
229# define g_pSUPGlobalInfoPage (SUPGetGIP())
230# else
231# define g_pSUPGlobalInfoPage (&g_SUPGlobalInfoPage)
232# endif
233#else
234extern DECLIMPORT(PSUPGLOBALINFOPAGE) g_pSUPGlobalInfoPage;
235#endif
236
237
238/**
239 * Gets the TSC frequency of the calling CPU.
240 *
241 * @returns TSC frequency.
242 * @param pGip The GIP pointer.
243 */
244DECLINLINE(uint64_t) SUPGetCpuHzFromGIP(PSUPGLOBALINFOPAGE pGip)
245{
246 unsigned iCpu;
247
248 if (RT_UNLIKELY(!pGip || pGip->u32Magic != SUPGLOBALINFOPAGE_MAGIC))
249 return ~(uint64_t)0;
250
251 if (pGip->u32Mode != SUPGIPMODE_ASYNC_TSC)
252 iCpu = 0;
253 else
254 {
255 iCpu = ASMGetApicId();
256 if (RT_UNLIKELY(iCpu >= RT_ELEMENTS(pGip->aCPUs)))
257 return ~(uint64_t)0;
258 }
259
260 return pGip->aCPUs[iCpu].u64CpuHz;
261}
262
263
264/**
265 * Request for generic VMMR0Entry calls.
266 */
267typedef struct SUPVMMR0REQHDR
268{
269 /** The magic. (SUPVMMR0REQHDR_MAGIC) */
270 uint32_t u32Magic;
271 /** The size of the request. */
272 uint32_t cbReq;
273} SUPVMMR0REQHDR;
274/** Pointer to a ring-0 request header. */
275typedef SUPVMMR0REQHDR *PSUPVMMR0REQHDR;
276/** the SUPVMMR0REQHDR::u32Magic value (Ethan Iverson - The Bad Plus). */
277#define SUPVMMR0REQHDR_MAGIC UINT32_C(0x19730211)
278
279
280/** For the fast ioctl path.
281 * @{
282 */
283/** @see VMMR0_DO_RAW_RUN. */
284#define SUP_VMMR0_DO_RAW_RUN 0
285/** @see VMMR0_DO_HWACC_RUN. */
286#define SUP_VMMR0_DO_HWACC_RUN 1
287/** @see VMMR0_DO_NOP */
288#define SUP_VMMR0_DO_NOP 2
289/** @} */
290
291
292/**
293 * Request for generic FNSUPR0SERVICEREQHANDLER calls.
294 */
295typedef struct SUPR0SERVICEREQHDR
296{
297 /** The magic. (SUPR0SERVICEREQHDR_MAGIC) */
298 uint32_t u32Magic;
299 /** The size of the request. */
300 uint32_t cbReq;
301} SUPR0SERVICEREQHDR;
302/** Pointer to a ring-0 service request header. */
303typedef SUPR0SERVICEREQHDR *PSUPR0SERVICEREQHDR;
304/** the SUPVMMR0REQHDR::u32Magic value (Esbjoern Svensson - E.S.P.). */
305#define SUPR0SERVICEREQHDR_MAGIC UINT32_C(0x19640416)
306
307
308
309#ifdef IN_RING3
310
311/** @defgroup grp_sup_r3 SUP Host Context Ring 3 API
312 * @ingroup grp_sup
313 * @{
314 */
315
316/**
317 * Installs the support library.
318 *
319 * @returns VBox status code.
320 */
321SUPR3DECL(int) SUPInstall(void);
322
323/**
324 * Uninstalls the support library.
325 *
326 * @returns VBox status code.
327 */
328SUPR3DECL(int) SUPUninstall(void);
329
330/**
331 * Trusted main entry point.
332 *
333 * This is exported as "TrustedMain" by the dynamic libraries which contains the
334 * "real" application binary for which the hardened stub is built. The entry
335 * point is invoked upon successfull initialization of the support library and
336 * runtime.
337 *
338 * @returns main kind of exit code.
339 * @param argc The argument count.
340 * @param argv The argument vector.
341 * @param envp The environment vector.
342 */
343typedef DECLCALLBACK(int) FNSUPTRUSTEDMAIN(int argc, char **argv, char **envp);
344/** Pointer to FNSUPTRUSTEDMAIN(). */
345typedef FNSUPTRUSTEDMAIN *PFNSUPTRUSTEDMAIN;
346
347/** Which operation failed. */
348typedef enum SUPINITOP
349{
350 /** Invalid. */
351 kSupInitOp_Invalid = 0,
352 /** Installation integrity error. */
353 kSupInitOp_Integrity,
354 /** Setuid related. */
355 kSupInitOp_RootCheck,
356 /** Driver related. */
357 kSupInitOp_Driver,
358 /** IPRT init related. */
359 kSupInitOp_IPRT,
360 /** Place holder. */
361 kSupInitOp_End
362} SUPINITOP;
363
364/**
365 * Trusted error entry point, optional.
366 *
367 * This is exported as "TrustedError" by the dynamic libraries which contains
368 * the "real" application binary for which the hardened stub is built.
369 *
370 * @param pszWhere Where the error occured (function name).
371 * @param enmWhat Which operation went wrong.
372 * @param rc The status code.
373 * @param pszMsgFmt Error message format string.
374 * @param va The message format arguments.
375 */
376typedef DECLCALLBACK(void) FNSUPTRUSTEDERROR(const char *pszWhere, SUPINITOP enmWhat, int rc, const char *pszMsgFmt, va_list va);
377/** Pointer to FNSUPTRUSTEDERROR. */
378typedef FNSUPTRUSTEDERROR *PFNSUPTRUSTEDERROR;
379
380/**
381 * Secure main.
382 *
383 * This is used for the set-user-ID-on-execute binaries on unixy systems
384 * and when using the open-vboxdrv-via-root-service setup on Windows.
385 *
386 * This function will perform the integrity checks of the VirtualBox
387 * installation, open the support driver, open the root service (later),
388 * and load the DLL corresponding to \a pszProgName and execute its main
389 * function.
390 *
391 * @returns Return code appropriate for main().
392 *
393 * @param pszProgName The program name. This will be used to figure out which
394 * DLL/SO/DYLIB to load and execute.
395 * @param fFlags Flags.
396 * @param argc The argument count.
397 * @param argv The argument vector.
398 * @param envp The environment vector.
399 */
400DECLHIDDEN(int) SUPR3HardenedMain(const char *pszProgName, uint32_t fFlags, int argc, char **argv, char **envp);
401
402/** @name SUPR3SecureMain flags.
403 * @{ */
404/** Don't open the device. (Intended for VirtualBox without -startvm.) */
405#define SUPSECMAIN_FLAGS_DONT_OPEN_DEV RT_BIT_32(0)
406/** @} */
407
408/**
409 * Initializes the support library.
410 * Each succesful call to SUPR3Init() must be countered by a
411 * call to SUPTerm(false).
412 *
413 * @returns VBox status code.
414 * @param ppSession Where to store the session handle. Defaults to NULL.
415 */
416SUPR3DECL(int) SUPR3Init(PSUPDRVSESSION *ppSession);
417
418/**
419 * Terminates the support library.
420 *
421 * @returns VBox status code.
422 * @param fForced Forced termination. This means to ignore the
423 * init call count and just terminated.
424 */
425#ifdef __cplusplus
426SUPR3DECL(int) SUPTerm(bool fForced = false);
427#else
428SUPR3DECL(int) SUPTerm(int fForced);
429#endif
430
431/**
432 * Sets the ring-0 VM handle for use with fast IOCtls.
433 *
434 * @returns VBox status code.
435 * @param pVMR0 The ring-0 VM handle.
436 * NIL_RTR0PTR can be used to unset the handle when the
437 * VM is about to be destroyed.
438 */
439SUPR3DECL(int) SUPSetVMForFastIOCtl(PVMR0 pVMR0);
440
441/**
442 * Calls the HC R0 VMM entry point.
443 * See VMMR0Entry() for more details.
444 *
445 * @returns error code specific to uFunction.
446 * @param pVMR0 Pointer to the Ring-0 (Host Context) mapping of the VM structure.
447 * @param uOperation Operation to execute.
448 * @param pvArg Argument.
449 */
450SUPR3DECL(int) SUPCallVMMR0(PVMR0 pVMR0, unsigned uOperation, void *pvArg);
451
452/**
453 * Variant of SUPCallVMMR0, except that this takes the fast ioclt path
454 * regardsless of compile-time defaults.
455 *
456 * @returns VBox status code.
457 * @param pVMR0 The ring-0 VM handle.
458 * @param uOperation The operation; only the SUP_VMMR0_DO_* ones are valid.
459 * @param idCPU VMCPU id.
460 */
461SUPR3DECL(int) SUPCallVMMR0Fast(PVMR0 pVMR0, unsigned uOperation, unsigned idCPU);
462
463/**
464 * Calls the HC R0 VMM entry point, in a safer but slower manner than SUPCallVMMR0.
465 * When entering using this call the R0 components can call into the host kernel
466 * (i.e. use the SUPR0 and RT APIs).
467 *
468 * See VMMR0Entry() for more details.
469 *
470 * @returns error code specific to uFunction.
471 * @param pVMR0 Pointer to the Ring-0 (Host Context) mapping of the VM structure.
472 * @param uOperation Operation to execute.
473 * @param u64Arg Constant argument.
474 * @param pReqHdr Pointer to a request header. Optional.
475 * This will be copied in and out of kernel space. There currently is a size
476 * limit on this, just below 4KB.
477 */
478SUPR3DECL(int) SUPCallVMMR0Ex(PVMR0 pVMR0, unsigned uOperation, uint64_t u64Arg, PSUPVMMR0REQHDR pReqHdr);
479
480/**
481 * Calls a ring-0 service.
482 *
483 * The operation and the request packet is specific to the service.
484 *
485 * @returns error code specific to uFunction.
486 * @param pszService The service name.
487 * @param cchService The length of the service name.
488 * @param uReq The request number.
489 * @param u64Arg Constant argument.
490 * @param pReqHdr Pointer to a request header. Optional.
491 * This will be copied in and out of kernel space. There currently is a size
492 * limit on this, just below 4KB.
493 */
494SUPR3DECL(int) SUPR3CallR0Service(const char *pszService, size_t cchService, uint32_t uOperation, uint64_t u64Arg, PSUPR0SERVICEREQHDR pReqHdr);
495
496/**
497 * Queries the paging mode of the host OS.
498 *
499 * @returns The paging mode.
500 */
501SUPR3DECL(SUPPAGINGMODE) SUPGetPagingMode(void);
502
503/**
504 * Allocate zero-filled pages.
505 *
506 * Use this to allocate a number of pages rather than using RTMem*() and mess with
507 * alignment. The returned address is of course page aligned. Call SUPPageFree()
508 * to free the pages once done with them.
509 *
510 * @returns VBox status.
511 * @param cPages Number of pages to allocate.
512 * @param ppvPages Where to store the base pointer to the allocated pages.
513 */
514SUPR3DECL(int) SUPPageAlloc(size_t cPages, void **ppvPages);
515
516/**
517 * Frees pages allocated with SUPPageAlloc().
518 *
519 * @returns VBox status.
520 * @param pvPages Pointer returned by SUPPageAlloc().
521 * @param cPages Number of pages that was allocated.
522 */
523SUPR3DECL(int) SUPPageFree(void *pvPages, size_t cPages);
524
525/**
526 * Locks down the physical memory backing a virtual memory
527 * range in the current process.
528 *
529 * @returns VBox status code.
530 * @param pvStart Start of virtual memory range.
531 * Must be page aligned.
532 * @param cPages Number of pages.
533 * @param paPages Where to store the physical page addresses returned.
534 * On entry this will point to an array of with cbMemory >> PAGE_SHIFT entries.
535 */
536SUPR3DECL(int) SUPPageLock(void *pvStart, size_t cPages, PSUPPAGE paPages);
537
538/**
539 * Releases locked down pages.
540 *
541 * @returns VBox status code.
542 * @param pvStart Start of virtual memory range previously locked
543 * down by SUPPageLock().
544 */
545SUPR3DECL(int) SUPPageUnlock(void *pvStart);
546
547/**
548 * Allocate non-zeroed, locked, pages with user and, optionally, kernel
549 * mappings.
550 *
551 * Use SUPR3PageFreeEx() to free memory allocated with this function.
552 *
553 * This SUPR3PageAllocEx and SUPR3PageFreeEx replaces SUPPageAllocLocked,
554 * SUPPageAllocLockedEx, SUPPageFreeLocked, SUPPageAlloc, SUPPageLock,
555 * SUPPageUnlock and SUPPageFree.
556 *
557 * @returns VBox status code.
558 * @param cPages The number of pages to allocate.
559 * @param fFlags Flags, reserved. Must be zero.
560 * @param ppvPages Where to store the address of the user mapping.
561 * @param pR0Ptr Where to store the address of the kernel mapping.
562 * NULL if no kernel mapping is desired.
563 * @param paPages Where to store the physical addresses of each page.
564 * Optional.
565 */
566SUPR3DECL(int) SUPR3PageAllocEx(size_t cPages, uint32_t fFlags, void **ppvPages, PRTR0PTR pR0Ptr, PSUPPAGE paPages);
567
568/**
569 * Maps a portion of a ring-3 only allocation into kernel space.
570 *
571 * @return VBox status code.
572 *
573 * @param pvR3 The address SUPR3PageAllocEx return.
574 * @param off Offset to start mapping at. Must be page aligned.
575 * @param cb Number of bytes to map. Must be page aligned.
576 * @param fFlags Flags, must be zero.
577 * @param pR0Ptr Where to store the address on success.
578 *
579 */
580SUPR3DECL(int) SUPR3PageMapKernel(void *pvR3, uint32_t off, uint32_t cb, uint32_t fFlags, PRTR0PTR pR0Ptr);
581
582/**
583 * Free pages allocated by SUPR3PageAllocEx.
584 *
585 * @returns VBox status code.
586 * @param pvPages The address of the user mapping.
587 * @param cPages The number of pages.
588 */
589SUPR3DECL(int) SUPR3PageFreeEx(void *pvPages, size_t cPages);
590
591/**
592 * Allocate non-zeroed locked pages.
593 *
594 * Use this to allocate a number of pages rather than using RTMem*() and mess with
595 * alignment. The returned address is of course page aligned. Call SUPPageFreeLocked()
596 * to free the pages once done with them.
597 *
598 * @returns VBox status code.
599 * @param cPages Number of pages to allocate.
600 * @param ppvPages Where to store the base pointer to the allocated pages.
601 * @param paPages Where to store the physical page addresses returned.
602 * On entry this will point to an array of with cbMemory >> PAGE_SHIFT entries.
603 * NULL is allowed.
604 */
605SUPR3DECL(int) SUPPageAllocLockedEx(size_t cPages, void **ppvPages, PSUPPAGE paPages);
606
607/**
608 * Frees locked pages allocated with SUPPageAllocLocked().
609 *
610 * @returns VBox status.
611 * @param pvPages Pointer returned by SUPPageAlloc().
612 * @param cPages Number of pages that was allocated.
613 */
614SUPR3DECL(int) SUPPageFreeLocked(void *pvPages, size_t cPages);
615
616/**
617 * Allocated memory with page aligned memory with a contiguous and locked physical
618 * memory backing below 4GB.
619 *
620 * @returns Pointer to the allocated memory (virtual address).
621 * *pHCPhys is set to the physical address of the memory.
622 * The returned memory must be freed using SUPContFree().
623 * @returns NULL on failure.
624 * @param cPages Number of pages to allocate.
625 * @param pHCPhys Where to store the physical address of the memory block.
626 */
627SUPR3DECL(void *) SUPContAlloc(size_t cPages, PRTHCPHYS pHCPhys);
628
629/**
630 * Allocated memory with page aligned memory with a contiguous and locked physical
631 * memory backing below 4GB.
632 *
633 * @returns Pointer to the allocated memory (virtual address).
634 * *pHCPhys is set to the physical address of the memory.
635 * If ppvR0 isn't NULL, *ppvR0 is set to the ring-0 mapping.
636 * The returned memory must be freed using SUPContFree().
637 * @returns NULL on failure.
638 * @param cPages Number of pages to allocate.
639 * @param pR0Ptr Where to store the ring-0 mapping of the allocation. (optional)
640 * @param pHCPhys Where to store the physical address of the memory block.
641 *
642 * @remark This 2nd version of this API exists because we're not able to map the
643 * ring-3 mapping executable on WIN64. This is a serious problem in regard to
644 * the world switchers.
645 */
646SUPR3DECL(void *) SUPContAlloc2(size_t cPages, PRTR0PTR pR0Ptr, PRTHCPHYS pHCPhys);
647
648/**
649 * Frees memory allocated with SUPContAlloc().
650 *
651 * @returns VBox status code.
652 * @param pv Pointer to the memory block which should be freed.
653 * @param cPages Number of pages to be freed.
654 */
655SUPR3DECL(int) SUPContFree(void *pv, size_t cPages);
656
657/**
658 * Allocated non contiguous physical memory below 4GB.
659 *
660 * The memory isn't zeroed.
661 *
662 * @returns VBox status code.
663 * @returns NULL on failure.
664 * @param cPages Number of pages to allocate.
665 * @param ppvPages Where to store the pointer to the allocated memory.
666 * The pointer stored here on success must be passed to SUPLowFree when
667 * the memory should be released.
668 * @param ppvPagesR0 Where to store the ring-0 pointer to the allocated memory. optional.
669 * @param paPages Where to store the physical addresses of the individual pages.
670 */
671SUPR3DECL(int) SUPLowAlloc(size_t cPages, void **ppvPages, PRTR0PTR ppvPagesR0, PSUPPAGE paPages);
672
673/**
674 * Frees memory allocated with SUPLowAlloc().
675 *
676 * @returns VBox status code.
677 * @param pv Pointer to the memory block which should be freed.
678 * @param cPages Number of pages that was allocated.
679 */
680SUPR3DECL(int) SUPLowFree(void *pv, size_t cPages);
681
682/**
683 * Load a module into R0 HC.
684 *
685 * This will verify the file integrity in a similar manner as
686 * SUPR3HardenedVerifyFile before loading it.
687 *
688 * @returns VBox status code.
689 * @param pszFilename The path to the image file.
690 * @param pszModule The module name. Max 32 bytes.
691 * @param ppvImageBase Where to store the image address.
692 */
693SUPR3DECL(int) SUPLoadModule(const char *pszFilename, const char *pszModule, void **ppvImageBase);
694
695/**
696 * Load a module into R0 HC.
697 *
698 * This will verify the file integrity in a similar manner as
699 * SUPR3HardenedVerifyFile before loading it.
700 *
701 * @returns VBox status code.
702 * @param pszFilename The path to the image file.
703 * @param pszModule The module name. Max 32 bytes.
704 * @param pszSrvReqHandler The name of the service request handler entry
705 * point. See FNSUPR0SERVICEREQHANDLER.
706 * @param ppvImageBase Where to store the image address.
707 */
708SUPR3DECL(int) SUPR3LoadServiceModule(const char *pszFilename, const char *pszModule,
709 const char *pszSrvReqHandler, void **ppvImageBase);
710
711/**
712 * Frees a R0 HC module.
713 *
714 * @returns VBox status code.
715 * @param pszModule The module to free.
716 * @remark This will not actually 'free' the module, there are of course usage counting.
717 */
718SUPR3DECL(int) SUPFreeModule(void *pvImageBase);
719
720/**
721 * Get the address of a symbol in a ring-0 module.
722 *
723 * @returns VBox status code.
724 * @param pszModule The module name.
725 * @param pszSymbol Symbol name. If it's value is less than 64k it's treated like a
726 * ordinal value rather than a string pointer.
727 * @param ppvValue Where to store the symbol value.
728 */
729SUPR3DECL(int) SUPGetSymbolR0(void *pvImageBase, const char *pszSymbol, void **ppvValue);
730
731/**
732 * Load R0 HC VMM code.
733 *
734 * @returns VBox status code.
735 * @deprecated Use SUPLoadModule(pszFilename, "VMMR0.r0", &pvImageBase)
736 */
737SUPR3DECL(int) SUPLoadVMM(const char *pszFilename);
738
739/**
740 * Unloads R0 HC VMM code.
741 *
742 * @returns VBox status code.
743 * @deprecated Use SUPFreeModule().
744 */
745SUPR3DECL(int) SUPUnloadVMM(void);
746
747/**
748 * Get the physical address of the GIP.
749 *
750 * @returns VBox status code.
751 * @param pHCPhys Where to store the physical address of the GIP.
752 */
753SUPR3DECL(int) SUPGipGetPhys(PRTHCPHYS pHCPhys);
754
755/**
756 * Verifies the integrity of a file, and optionally opens it.
757 *
758 * The integrity check is for whether the file is suitable for loading into
759 * the hypervisor or VM process. The integrity check may include verifying
760 * the authenticode/elfsign/whatever signature of the file, which can take
761 * a little while.
762 *
763 * @returns VBox status code. On failure it will have printed a LogRel message.
764 *
765 * @param pszFilename The file.
766 * @param pszWhat For the LogRel on failure.
767 * @param phFile Where to store the handle to the opened file. This is optional, pass NULL
768 * if the file should not be opened.
769 */
770SUPR3DECL(int) SUPR3HardenedVerifyFile(const char *pszFilename, const char *pszWhat, PRTFILE phFile);
771
772/**
773 * Same as RTLdrLoad() but will verify the files it loads (hardened builds).
774 *
775 * Will add dll suffix if missing and try load the file.
776 *
777 * @returns iprt status code.
778 * @param pszFilename Image filename. This must have a path.
779 * @param phLdrMod Where to store the handle to the loaded module.
780 */
781SUPR3DECL(int) SUPR3HardenedLdrLoad(const char *pszFilename, PRTLDRMOD phLdrMod);
782
783/**
784 * Same as RTLdrLoadAppPriv() but it will verify the files it loads (hardened
785 * builds).
786 *
787 * Will add dll suffix to the file if missing, then look for it in the
788 * architecture dependent application directory.
789 *
790 * @returns iprt status code.
791 * @param pszFilename Image filename.
792 * @param phLdrMod Where to store the handle to the loaded module.
793 */
794SUPR3DECL(int) SUPR3HardenedLdrLoadAppPriv(const char *pszFilename, PRTLDRMOD phLdrMod);
795
796/** @} */
797#endif /* IN_RING3 */
798
799
800#ifdef IN_RING0
801/** @defgroup grp_sup_r0 SUP Host Context Ring 0 API
802 * @ingroup grp_sup
803 * @{
804 */
805
806/**
807 * Security objectype.
808 */
809typedef enum SUPDRVOBJTYPE
810{
811 /** The usual invalid object. */
812 SUPDRVOBJTYPE_INVALID = 0,
813 /** A Virtual Machine instance. */
814 SUPDRVOBJTYPE_VM,
815 /** Internal network. */
816 SUPDRVOBJTYPE_INTERNAL_NETWORK,
817 /** Internal network interface. */
818 SUPDRVOBJTYPE_INTERNAL_NETWORK_INTERFACE,
819 /** The first invalid object type in this end. */
820 SUPDRVOBJTYPE_END,
821 /** The usual 32-bit type size hack. */
822 SUPDRVOBJTYPE_32_BIT_HACK = 0x7ffffff
823} SUPDRVOBJTYPE;
824
825/**
826 * Object destructor callback.
827 * This is called for reference counted objectes when the count reaches 0.
828 *
829 * @param pvObj The object pointer.
830 * @param pvUser1 The first user argument.
831 * @param pvUser2 The second user argument.
832 */
833typedef DECLCALLBACK(void) FNSUPDRVDESTRUCTOR(void *pvObj, void *pvUser1, void *pvUser2);
834/** Pointer to a FNSUPDRVDESTRUCTOR(). */
835typedef FNSUPDRVDESTRUCTOR *PFNSUPDRVDESTRUCTOR;
836
837SUPR0DECL(void *) SUPR0ObjRegister(PSUPDRVSESSION pSession, SUPDRVOBJTYPE enmType, PFNSUPDRVDESTRUCTOR pfnDestructor, void *pvUser1, void *pvUser2);
838SUPR0DECL(int) SUPR0ObjAddRef(void *pvObj, PSUPDRVSESSION pSession);
839SUPR0DECL(int) SUPR0ObjRelease(void *pvObj, PSUPDRVSESSION pSession);
840SUPR0DECL(int) SUPR0ObjVerifyAccess(void *pvObj, PSUPDRVSESSION pSession, const char *pszObjName);
841
842SUPR0DECL(int) SUPR0LockMem(PSUPDRVSESSION pSession, RTR3PTR pvR3, uint32_t cPages, PRTHCPHYS paPages);
843SUPR0DECL(int) SUPR0UnlockMem(PSUPDRVSESSION pSession, RTR3PTR pvR3);
844SUPR0DECL(int) SUPR0ContAlloc(PSUPDRVSESSION pSession, uint32_t cPages, PRTR0PTR ppvR0, PRTR3PTR ppvR3, PRTHCPHYS pHCPhys);
845SUPR0DECL(int) SUPR0ContFree(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr);
846SUPR0DECL(int) SUPR0LowAlloc(PSUPDRVSESSION pSession, uint32_t cPages, PRTR0PTR ppvR0, PRTR3PTR ppvR3, PRTHCPHYS paPages);
847SUPR0DECL(int) SUPR0LowFree(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr);
848SUPR0DECL(int) SUPR0MemAlloc(PSUPDRVSESSION pSession, uint32_t cb, PRTR0PTR ppvR0, PRTR3PTR ppvR3);
849SUPR0DECL(int) SUPR0MemGetPhys(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr, PSUPPAGE paPages);
850SUPR0DECL(int) SUPR0MemFree(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr);
851SUPR0DECL(int) SUPR0PageAlloc(PSUPDRVSESSION pSession, uint32_t cPages, PRTR3PTR ppvR3, PRTHCPHYS paPages);
852SUPR0DECL(int) SUPR0PageAllocEx(PSUPDRVSESSION pSession, uint32_t cPages, uint32_t fFlags, PRTR3PTR ppvR3, PRTR0PTR ppvR0, PRTHCPHYS paPages);
853SUPR0DECL(int) SUPR0PageMapKernel(PSUPDRVSESSION pSession, RTR3PTR pvR3, uint32_t offSub, uint32_t cbSub, uint32_t fFlags, PRTR0PTR ppvR0);
854SUPR0DECL(int) SUPR0PageFree(PSUPDRVSESSION pSession, RTR3PTR pvR3);
855SUPR0DECL(int) SUPR0GipMap(PSUPDRVSESSION pSession, PRTR3PTR ppGipR3, PRTHCPHYS pHCPhysGip);
856SUPR0DECL(int) SUPR0GipUnmap(PSUPDRVSESSION pSession);
857SUPR0DECL(int) SUPR0Printf(const char *pszFormat, ...);
858SUPR0DECL(SUPPAGINGMODE) SUPR0GetPagingMode(void);
859SUPR0DECL(int) SUPR0EnableVTx(bool fEnable);
860
861/** @name Absolute symbols
862 * Take the address of these, don't try call them.
863 * @{ */
864SUPR0DECL(void) SUPR0AbsIs64bit(void);
865SUPR0DECL(void) SUPR0Abs64bitKernelCS(void);
866SUPR0DECL(void) SUPR0Abs64bitKernelSS(void);
867SUPR0DECL(void) SUPR0Abs64bitKernelDS(void);
868SUPR0DECL(void) SUPR0AbsKernelCS(void);
869SUPR0DECL(void) SUPR0AbsKernelSS(void);
870SUPR0DECL(void) SUPR0AbsKernelDS(void);
871SUPR0DECL(void) SUPR0AbsKernelES(void);
872SUPR0DECL(void) SUPR0AbsKernelFS(void);
873SUPR0DECL(void) SUPR0AbsKernelGS(void);
874/** @} */
875
876/**
877 * Support driver component factory.
878 *
879 * Component factories are registered by drivers that provides services
880 * such as the host network interface filtering and access to the host
881 * TCP/IP stack.
882 *
883 * @remark Module dependencies and making sure that a component doesn't
884 * get unloaded while in use, is the sole responsibility of the
885 * driver/kext/whatever implementing the component.
886 */
887typedef struct SUPDRVFACTORY
888{
889 /** The (unique) name of the component factory. */
890 char szName[56];
891 /**
892 * Queries a factory interface.
893 *
894 * The factory interface is specific to each component and will be be
895 * found in the header(s) for the component alongside its UUID.
896 *
897 * @returns Pointer to the factory interfaces on success, NULL on failure.
898 *
899 * @param pSupDrvFactory Pointer to this structure.
900 * @param pSession The SUPDRV session making the query.
901 * @param pszInterfaceUuid The UUID of the factory interface.
902 */
903 DECLR0CALLBACKMEMBER(void *, pfnQueryFactoryInterface,(struct SUPDRVFACTORY const *pSupDrvFactory, PSUPDRVSESSION pSession, const char *pszInterfaceUuid));
904} SUPDRVFACTORY;
905/** Pointer to a support driver factory. */
906typedef SUPDRVFACTORY *PSUPDRVFACTORY;
907/** Pointer to a const support driver factory. */
908typedef SUPDRVFACTORY const *PCSUPDRVFACTORY;
909
910SUPR0DECL(int) SUPR0ComponentRegisterFactory(PSUPDRVSESSION pSession, PCSUPDRVFACTORY pFactory);
911SUPR0DECL(int) SUPR0ComponentDeregisterFactory(PSUPDRVSESSION pSession, PCSUPDRVFACTORY pFactory);
912SUPR0DECL(int) SUPR0ComponentQueryFactory(PSUPDRVSESSION pSession, const char *pszName, const char *pszInterfaceUuid, void **ppvFactoryIf);
913
914
915/**
916 * Service request callback function.
917 *
918 * @returns VBox status code.
919 * @param pSession The caller's session.
920 * @param u64Arg 64-bit integer argument.
921 * @param pReqHdr The request header. Input / Output. Optional.
922 */
923typedef DECLCALLBACK(int) FNSUPR0SERVICEREQHANDLER(PSUPDRVSESSION pSession, uint32_t uOperation,
924 uint64_t u64Arg, PSUPR0SERVICEREQHDR pReqHdr);
925/** Pointer to a FNR0SERVICEREQHANDLER(). */
926typedef R0PTRTYPE(FNSUPR0SERVICEREQHANDLER *) PFNSUPR0SERVICEREQHANDLER;
927
928
929/** @defgroup grp_sup_r0_idc The IDC Interface
930 * @ingroup grp_sup_r0
931 * @{
932 */
933
934/** The current SUPDRV IDC version.
935 * This follows the usual high word / low word rules, i.e. high word is the
936 * major number and it signifies incompatible interface changes. */
937#define SUPDRV_IDC_VERSION UINT32_C(0x00010000)
938
939/**
940 * Inter-Driver Communcation Handle.
941 */
942typedef union SUPDRVIDCHANDLE
943{
944 /** Padding for opaque usage.
945 * Must be greater or equal in size than the private struct. */
946 void *apvPadding[4];
947#ifdef SUPDRVIDCHANDLEPRIVATE_DECLARED
948 /** The private view. */
949 struct SUPDRVIDCHANDLEPRIVATE s;
950#endif
951} SUPDRVIDCHANDLE;
952/** Pointer to a handle. */
953typedef SUPDRVIDCHANDLE *PSUPDRVIDCHANDLE;
954
955SUPR0DECL(int) SUPR0IdcOpen(PSUPDRVIDCHANDLE pHandle, uint32_t uReqVersion, uint32_t uMinVersion,
956 uint32_t *puSessionVersion, uint32_t *puDriverVersion, uint32_t *puDriverRevision);
957SUPR0DECL(int) SUPR0IdcCall(PSUPDRVIDCHANDLE pHandle, uint32_t iReq, void *pvReq, uint32_t cbReq);
958SUPR0DECL(int) SUPR0IdcClose(PSUPDRVIDCHANDLE pHandle);
959SUPR0DECL(PSUPDRVSESSION) SUPR0IdcGetSession(PSUPDRVIDCHANDLE pHandle);
960SUPR0DECL(int) SUPR0IdcComponentRegisterFactory(PSUPDRVIDCHANDLE pHandle, PCSUPDRVFACTORY pFactory);
961SUPR0DECL(int) SUPR0IdcComponentDeregisterFactory(PSUPDRVIDCHANDLE pHandle, PCSUPDRVFACTORY pFactory);
962
963/** @} */
964
965/** @} */
966#endif
967
968/** @} */
969
970__END_DECLS
971
972#endif
973
Note: See TracBrowser for help on using the repository browser.

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