VirtualBox

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

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

Backed out 46655-57 for now

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