VirtualBox

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

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

VMM/SUP: Added SUPR3HardenedVerifyFile and use it to verify files we load.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 27.1 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/asm.h>
37
38__BEGIN_DECLS
39
40/** @defgroup grp_sup The Support Library API
41 * @{
42 */
43
44/**
45 * Physical page descriptor.
46 */
47#pragma pack(4) /* space is more important. */
48typedef struct SUPPAGE
49{
50 /** Physical memory address. */
51 RTHCPHYS Phys;
52 /** Reserved entry for internal use by the caller. */
53 RTHCUINTPTR uReserved;
54} SUPPAGE;
55#pragma pack()
56/** Pointer to a page descriptor. */
57typedef SUPPAGE *PSUPPAGE;
58/** Pointer to a const page descriptor. */
59typedef const SUPPAGE *PCSUPPAGE;
60
61/**
62 * The paging mode.
63 */
64typedef 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
92#pragma pack(1) /* paranoia */
93
94/**
95 * Per CPU data.
96 * This is only used when
97 */
98typedef struct SUPGIPCPU
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
104 * are consistent. */
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
109 * to avoid ending up with too many 1ns increments. */
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];
127 /** Reserved for future per processor data. */
128 volatile uint32_t au32Reserved[6];
129} SUPGIPCPU;
130AssertCompileSize(SUPGIPCPU, 96);
131/*AssertCompileMemberAlignment(SUPGIPCPU, u64TSC, 8); -fixme */
132
133/** Pointer to per cpu data.
134 * @remark there is no const version of this typedef, see g_pSUPGlobalInfoPage for details. */
135typedef 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 */
144typedef struct SUPGLOBALINFOPAGE
145{
146 /** Magic (SUPGLOBALINFOPAGE_MAGIC). */
147 uint32_t u32Magic;
148 /** The GIP version. */
149 uint32_t u32Version;
150
151 /** The GIP update mode, see SUPGIPMODE. */
152 uint32_t u32Mode;
153 /** Reserved / padding. */
154 uint32_t u32Padding0;
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;
159 /** The timestamp of the last time we update the update frequency. */
160 volatile uint64_t u64NanoTSLastUpdateHz;
161
162 /** Padding / reserved space for future data. */
163 uint32_t au32Padding1[56];
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];
170} SUPGLOBALINFOPAGE;
171AssertCompile(sizeof(SUPGLOBALINFOPAGE) <= 0x1000);
172/* AssertCompileMemberAlignment(SUPGLOBALINFOPAGE, aCPU, 32); - fixme */
173
174/** Pointer to the global info page.
175 * @remark there is no const version of this typedef, see g_pSUPGlobalInfoPage for details. */
176typedef SUPGLOBALINFOPAGE *PSUPGLOBALINFOPAGE;
177
178#pragma pack() /* end of paranoia */
179
180/** The value of the SUPGLOBALINFOPAGE::u32Magic field. (Soryo Fuyumi) */
181#define SUPGLOBALINFOPAGE_MAGIC 0x19590106
182/** The GIP version.
183 * Upper 16 bits is the major version. Major version is only changed with
184 * incompatible changes in the GIP. */
185#define SUPGLOBALINFOPAGE_VERSION 0x00020000
186
187/**
188 * SUPGLOBALINFOPAGE::u32Mode values.
189 */
190typedef 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
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.
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.
213 */
214#if defined(IN_SUP_R0) || defined(IN_SUP_R3) || defined(IN_SUP_GC)
215extern DECLEXPORT(PSUPGLOBALINFOPAGE) g_pSUPGlobalInfoPage;
216#elif defined(IN_RING0)
217extern DECLIMPORT(SUPGLOBALINFOPAGE) g_SUPGlobalInfoPage;
218# if defined(__GNUC__) && !defined(RT_OS_DARWIN) && defined(RT_ARCH_AMD64)
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.) */
221DECLINLINE(PSUPGLOBALINFOPAGE) SUPGetGIP(void)
222{
223 PSUPGLOBALINFOPAGE pGIP;
224 __asm__ __volatile__ ("movabs $g_SUPGlobalInfoPage,%0\n\t"
225 : "=a" (pGIP));
226 return pGIP;
227}
228# define g_pSUPGlobalInfoPage (SUPGetGIP())
229# else
230# define g_pSUPGlobalInfoPage (&g_SUPGlobalInfoPage)
231# endif
232#else
233extern DECLIMPORT(PSUPGLOBALINFOPAGE) g_pSUPGlobalInfoPage;
234#endif
235
236
237/**
238 * Gets the TSC frequency of the calling CPU.
239 *
240 * @returns TSC frequency.
241 * @param pGip The GIP pointer.
242 */
243DECLINLINE(uint64_t) SUPGetCpuHzFromGIP(PSUPGLOBALINFOPAGE pGip)
244{
245 unsigned iCpu;
246
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
263/**
264 * Request for generic VMMR0Entry calls.
265 */
266typedef 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. */
274typedef SUPVMMR0REQHDR *PSUPVMMR0REQHDR;
275/** the SUPVMMR0REQHDR::u32Magic value (Ethan Iverson - The Bad Plus). */
276#define SUPVMMR0REQHDR_MAGIC UINT32_C(0x19730211)
277
278
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/** @} */
289
290
291
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 */
304SUPR3DECL(int) SUPInstall(void);
305
306/**
307 * Uninstalls the support library.
308 *
309 * @returns VBox status code.
310 */
311SUPR3DECL(int) SUPUninstall(void);
312
313/**
314 * Secure main.
315 *
316 * This is used for the set-user-ID-on-execute binaries on unixy systems
317 * and when using the open-vboxdrv-via-root-service setup on Windows.
318 *
319 * This function will perform the integrity checks of the VirtualBox
320 * installation, open the support driver, open the root service (later),
321 * and load the DLL corresponding to \a pszProgName and execute its main
322 * function.
323 *
324 * @returns Return code appropriate for main().
325 *
326 * @param pszProgName The program name. This will be used to figure out which
327 * DLL/SO/DYLIB to load and execute.
328 * @param fFlags Flags.
329 * @param argc The argument count.
330 * @param argv The argument vector.
331 * @param envp The environment vector.
332 */
333DECLHIDDEN(int) SUPR3HardenedMain(const char *pszProgName, uint32_t fFlags, int argc, char **argv, char **envp);
334
335/** @name SUPR3SecureMain flags.
336 * @{ */
337/** Don't open the device. (Intended for VirtualBox without -startvm.) */
338#define SUPSECMAIN_FLAGS_DONT_OPEN_DEV RT_BIT_32(0)
339/** @} */
340
341/**
342 * Initializes the support library.
343 * Each succesful call to SUPR3Init() must be countered by a
344 * call to SUPTerm(false).
345 *
346 * @returns VBox status code.
347 * @param ppSession Where to store the session handle. Defaults to NULL.
348 */
349SUPR3DECL(int) SUPR3Init(PSUPDRVSESSION *ppSession);
350
351/**
352 * Terminates the support library.
353 *
354 * @returns VBox status code.
355 * @param fForced Forced termination. This means to ignore the
356 * init call count and just terminated.
357 */
358#ifdef __cplusplus
359SUPR3DECL(int) SUPTerm(bool fForced = false);
360#else
361SUPR3DECL(int) SUPTerm(int fForced);
362#endif
363
364/**
365 * Sets the ring-0 VM handle for use with fast IOCtls.
366 *
367 * @returns VBox status code.
368 * @param pVMR0 The ring-0 VM handle.
369 * NIL_RTR0PTR can be used to unset the handle when the
370 * VM is about to be destroyed.
371 */
372SUPR3DECL(int) SUPSetVMForFastIOCtl(PVMR0 pVMR0);
373
374/**
375 * Calls the HC R0 VMM entry point.
376 * See VMMR0Entry() for more details.
377 *
378 * @returns error code specific to uFunction.
379 * @param pVMR0 Pointer to the Ring-0 (Host Context) mapping of the VM structure.
380 * @param uOperation Operation to execute.
381 * @param pvArg Argument.
382 */
383SUPR3DECL(int) SUPCallVMMR0(PVMR0 pVMR0, unsigned uOperation, void *pvArg);
384
385/**
386 * Variant of SUPCallVMMR0, except that this takes the fast ioclt path
387 * regardsless of compile-time defaults.
388 *
389 * @returns VBox status code.
390 * @param pVMR0 The ring-0 VM handle.
391 * @param uOperation The operation; only the SUP_VMMR0_DO_* ones are valid.
392 */
393SUPR3DECL(int) SUPCallVMMR0Fast(PVMR0 pVMR0, unsigned uOperation);
394
395/**
396 * Calls the HC R0 VMM entry point, in a safer but slower manner than SUPCallVMMR0.
397 * When entering using this call the R0 components can call into the host kernel
398 * (i.e. use the SUPR0 and RT APIs).
399 *
400 * See VMMR0Entry() for more details.
401 *
402 * @returns error code specific to uFunction.
403 * @param pVMR0 Pointer to the Ring-0 (Host Context) mapping of the VM structure.
404 * @param uOperation Operation to execute.
405 * @param u64Arg Constant argument.
406 * @param pReqHdr Pointer to a request header. Optional.
407 * This will be copied in and out of kernel space. There currently is a size
408 * limit on this, just below 4KB.
409 */
410SUPR3DECL(int) SUPCallVMMR0Ex(PVMR0 pVMR0, unsigned uOperation, uint64_t u64Arg, PSUPVMMR0REQHDR pReqHdr);
411
412/**
413 * Queries the paging mode of the host OS.
414 *
415 * @returns The paging mode.
416 */
417SUPR3DECL(SUPPAGINGMODE) SUPGetPagingMode(void);
418
419/**
420 * Allocate zero-filled pages.
421 *
422 * Use this to allocate a number of pages rather than using RTMem*() and mess with
423 * alignment. The returned address is of course page aligned. Call SUPPageFree()
424 * to free the pages once done with them.
425 *
426 * @returns VBox status.
427 * @param cPages Number of pages to allocate.
428 * @param ppvPages Where to store the base pointer to the allocated pages.
429 */
430SUPR3DECL(int) SUPPageAlloc(size_t cPages, void **ppvPages);
431
432/**
433 * Frees pages allocated with SUPPageAlloc().
434 *
435 * @returns VBox status.
436 * @param pvPages Pointer returned by SUPPageAlloc().
437 * @param cPages Number of pages that was allocated.
438 */
439SUPR3DECL(int) SUPPageFree(void *pvPages, size_t cPages);
440
441/**
442 * Allocate zero-filled locked pages.
443 *
444 * Use this to allocate a number of pages rather than using RTMem*() and mess with
445 * alignment. The returned address is of course page aligned. Call SUPPageFreeLocked()
446 * to free the pages once done with them.
447 *
448 * @returns VBox status.
449 * @param cPages Number of pages to allocate.
450 * @param ppvPages Where to store the base pointer to the allocated pages.
451 */
452SUPR3DECL(int) SUPPageAllocLocked(size_t cPages, void **ppvPages);
453
454/**
455 * Allocate zero-filled locked pages.
456 *
457 * Use this to allocate a number of pages rather than using RTMem*() and mess with
458 * alignment. The returned address is of course page aligned. Call SUPPageFreeLocked()
459 * to free the pages once done with them.
460 *
461 * @returns VBox status code.
462 * @param cPages Number of pages to allocate.
463 * @param ppvPages Where to store the base pointer to the allocated pages.
464 * @param paPages Where to store the physical page addresses returned.
465 * On entry this will point to an array of with cbMemory >> PAGE_SHIFT entries.
466 * NULL is allowed.
467 */
468SUPR3DECL(int) SUPPageAllocLockedEx(size_t cPages, void **ppvPages, PSUPPAGE paPages);
469
470/**
471 * Frees locked pages allocated with SUPPageAllocLocked().
472 *
473 * @returns VBox status.
474 * @param pvPages Pointer returned by SUPPageAlloc().
475 * @param cPages Number of pages that was allocated.
476 */
477SUPR3DECL(int) SUPPageFreeLocked(void *pvPages, size_t cPages);
478
479/**
480 * Locks down the physical memory backing a virtual memory
481 * range in the current process.
482 *
483 * @returns VBox status code.
484 * @param pvStart Start of virtual memory range.
485 * Must be page aligned.
486 * @param cPages Number of pages.
487 * @param paPages Where to store the physical page addresses returned.
488 * On entry this will point to an array of with cbMemory >> PAGE_SHIFT entries.
489 */
490SUPR3DECL(int) SUPPageLock(void *pvStart, size_t cPages, PSUPPAGE paPages);
491
492/**
493 * Releases locked down pages.
494 *
495 * @returns VBox status code.
496 * @param pvStart Start of virtual memory range previously locked
497 * down by SUPPageLock().
498 */
499SUPR3DECL(int) SUPPageUnlock(void *pvStart);
500
501/**
502 * Allocated memory with page aligned memory with a contiguous and locked physical
503 * memory backing below 4GB.
504 *
505 * @returns Pointer to the allocated memory (virtual address).
506 * *pHCPhys is set to the physical address of the memory.
507 * The returned memory must be freed using SUPContFree().
508 * @returns NULL on failure.
509 * @param cPages Number of pages to allocate.
510 * @param pHCPhys Where to store the physical address of the memory block.
511 */
512SUPR3DECL(void *) SUPContAlloc(size_t cPages, PRTHCPHYS pHCPhys);
513
514/**
515 * Allocated memory with page aligned memory with a contiguous and locked physical
516 * memory backing below 4GB.
517 *
518 * @returns Pointer to the allocated memory (virtual address).
519 * *pHCPhys is set to the physical address of the memory.
520 * If ppvR0 isn't NULL, *ppvR0 is set to the ring-0 mapping.
521 * The returned memory must be freed using SUPContFree().
522 * @returns NULL on failure.
523 * @param cPages Number of pages to allocate.
524 * @param pR0Ptr Where to store the ring-0 mapping of the allocation. (optional)
525 * @param pHCPhys Where to store the physical address of the memory block.
526 *
527 * @remark This 2nd version of this API exists because we're not able to map the
528 * ring-3 mapping executable on WIN64. This is a serious problem in regard to
529 * the world switchers.
530 */
531SUPR3DECL(void *) SUPContAlloc2(size_t cPages, PRTR0PTR pR0Ptr, PRTHCPHYS pHCPhys);
532
533/**
534 * Frees memory allocated with SUPContAlloc().
535 *
536 * @returns VBox status code.
537 * @param pv Pointer to the memory block which should be freed.
538 * @param cPages Number of pages to be freed.
539 */
540SUPR3DECL(int) SUPContFree(void *pv, size_t cPages);
541
542/**
543 * Allocated non contiguous physical memory below 4GB.
544 *
545 * The memory isn't zeroed.
546 *
547 * @returns VBox status code.
548 * @returns NULL on failure.
549 * @param cPages Number of pages to allocate.
550 * @param ppvPages Where to store the pointer to the allocated memory.
551 * The pointer stored here on success must be passed to SUPLowFree when
552 * the memory should be released.
553 * @param ppvPagesR0 Where to store the ring-0 pointer to the allocated memory. optional.
554 * @param paPages Where to store the physical addresses of the individual pages.
555 */
556SUPR3DECL(int) SUPLowAlloc(size_t cPages, void **ppvPages, PRTR0PTR ppvPagesR0, PSUPPAGE paPages);
557
558/**
559 * Frees memory allocated with SUPLowAlloc().
560 *
561 * @returns VBox status code.
562 * @param pv Pointer to the memory block which should be freed.
563 * @param cPages Number of pages that was allocated.
564 */
565SUPR3DECL(int) SUPLowFree(void *pv, size_t cPages);
566
567/**
568 * Verifies the integrity of a file, and optionally opens it.
569 *
570 * The integrity check is for whether the file is suitable for loading into
571 * the hypervisor or VM process. The integrity check may include verifying
572 * the authenticode/elfsign/whatever signature of the file, which can take
573 * a little while.
574 *
575 * @returns VBox status code. On failure it will have printed a LogRel message.
576 *
577 * @param pszFilename The file.
578 * @param pszWhat For the LogRel on failure.
579 * @param phFile Where to store the handle to the opened file. This is optional, pass NULL
580 * if the file should not be opened.
581 */
582SUPR3DECL(int) SUPR3HardenedVerifyFile(const char *pszFilename, const char *pszWhat, PRTFILE phFile);
583
584/**
585 * Load a module into R0 HC.
586 *
587 * This will verify the file integrity in a similar manner as
588 * SUPR3HardenedVerifyFile before loading it.
589 *
590 * @returns VBox status code.
591 * @param pszFilename The path to the image file.
592 * @param pszModule The module name. Max 32 bytes.
593 */
594SUPR3DECL(int) SUPLoadModule(const char *pszFilename, const char *pszModule, void **ppvImageBase);
595
596/**
597 * Frees a R0 HC module.
598 *
599 * @returns VBox status code.
600 * @param pszModule The module to free.
601 * @remark This will not actually 'free' the module, there are of course usage counting.
602 */
603SUPR3DECL(int) SUPFreeModule(void *pvImageBase);
604
605/**
606 * Get the address of a symbol in a ring-0 module.
607 *
608 * @returns VBox status code.
609 * @param pszModule The module name.
610 * @param pszSymbol Symbol name. If it's value is less than 64k it's treated like a
611 * ordinal value rather than a string pointer.
612 * @param ppvValue Where to store the symbol value.
613 */
614SUPR3DECL(int) SUPGetSymbolR0(void *pvImageBase, const char *pszSymbol, void **ppvValue);
615
616/**
617 * Load R0 HC VMM code.
618 *
619 * @returns VBox status code.
620 * @deprecated Use SUPLoadModule(pszFilename, "VMMR0.r0", &pvImageBase)
621 */
622SUPR3DECL(int) SUPLoadVMM(const char *pszFilename);
623
624/**
625 * Unloads R0 HC VMM code.
626 *
627 * @returns VBox status code.
628 * @deprecated Use SUPFreeModule().
629 */
630SUPR3DECL(int) SUPUnloadVMM(void);
631
632/**
633 * Get the physical address of the GIP.
634 *
635 * @returns VBox status code.
636 * @param pHCPhys Where to store the physical address of the GIP.
637 */
638SUPR3DECL(int) SUPGipGetPhys(PRTHCPHYS pHCPhys);
639
640/** @} */
641#endif /* IN_RING3 */
642
643
644#ifdef IN_RING0
645/** @defgroup grp_sup_r0 SUP Host Context Ring 0 API
646 * @ingroup grp_sup
647 * @{
648 */
649
650/**
651 * Execute callback on all cpus/cores (SUPR0ExecuteCallback)
652 */
653#define SUPDRVEXECCALLBACK_CPU_ALL (~0)
654
655/**
656 * Security objectype.
657 */
658typedef enum SUPDRVOBJTYPE
659{
660 /** The usual invalid object. */
661 SUPDRVOBJTYPE_INVALID = 0,
662 /** A Virtual Machine instance. */
663 SUPDRVOBJTYPE_VM,
664 /** Internal network. */
665 SUPDRVOBJTYPE_INTERNAL_NETWORK,
666 /** Internal network interface. */
667 SUPDRVOBJTYPE_INTERNAL_NETWORK_INTERFACE,
668 /** The first invalid object type in this end. */
669 SUPDRVOBJTYPE_END,
670 /** The usual 32-bit type size hack. */
671 SUPDRVOBJTYPE_32_BIT_HACK = 0x7ffffff
672} SUPDRVOBJTYPE;
673
674/**
675 * Object destructor callback.
676 * This is called for reference counted objectes when the count reaches 0.
677 *
678 * @param pvObj The object pointer.
679 * @param pvUser1 The first user argument.
680 * @param pvUser2 The second user argument.
681 */
682typedef DECLCALLBACK(void) FNSUPDRVDESTRUCTOR(void *pvObj, void *pvUser1, void *pvUser2);
683/** Pointer to a FNSUPDRVDESTRUCTOR(). */
684typedef FNSUPDRVDESTRUCTOR *PFNSUPDRVDESTRUCTOR;
685
686SUPR0DECL(void *) SUPR0ObjRegister(PSUPDRVSESSION pSession, SUPDRVOBJTYPE enmType, PFNSUPDRVDESTRUCTOR pfnDestructor, void *pvUser1, void *pvUser2);
687SUPR0DECL(int) SUPR0ObjAddRef(void *pvObj, PSUPDRVSESSION pSession);
688SUPR0DECL(int) SUPR0ObjRelease(void *pvObj, PSUPDRVSESSION pSession);
689SUPR0DECL(int) SUPR0ObjVerifyAccess(void *pvObj, PSUPDRVSESSION pSession, const char *pszObjName);
690
691SUPR0DECL(int) SUPR0LockMem(PSUPDRVSESSION pSession, RTR3PTR pvR3, uint32_t cPages, PRTHCPHYS paPages);
692SUPR0DECL(int) SUPR0UnlockMem(PSUPDRVSESSION pSession, RTR3PTR pvR3);
693SUPR0DECL(int) SUPR0ContAlloc(PSUPDRVSESSION pSession, uint32_t cPages, PRTR0PTR ppvR0, PRTR3PTR ppvR3, PRTHCPHYS pHCPhys);
694SUPR0DECL(int) SUPR0ContFree(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr);
695SUPR0DECL(int) SUPR0LowAlloc(PSUPDRVSESSION pSession, uint32_t cPages, PRTR0PTR ppvR0, PRTR3PTR ppvR3, PRTHCPHYS paPages);
696SUPR0DECL(int) SUPR0LowFree(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr);
697SUPR0DECL(int) SUPR0MemAlloc(PSUPDRVSESSION pSession, uint32_t cb, PRTR0PTR ppvR0, PRTR3PTR ppvR3);
698SUPR0DECL(int) SUPR0MemGetPhys(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr, PSUPPAGE paPages);
699SUPR0DECL(int) SUPR0MemFree(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr);
700SUPR0DECL(int) SUPR0PageAlloc(PSUPDRVSESSION pSession, uint32_t cPages, PRTR3PTR ppvR3, PRTHCPHYS paPages);
701SUPR0DECL(int) SUPR0PageFree(PSUPDRVSESSION pSession, RTR3PTR pvR3);
702SUPR0DECL(int) SUPR0GipMap(PSUPDRVSESSION pSession, PRTR3PTR ppGipR3, PRTHCPHYS pHCPhysGip);
703SUPR0DECL(int) SUPR0GipUnmap(PSUPDRVSESSION pSession);
704SUPR0DECL(int) SUPR0Printf(const char *pszFormat, ...);
705
706
707/**
708 * Support driver component factory.
709 *
710 * Component factories are registered by drivers that provides services
711 * such as the host network interface filtering and access to the host
712 * TCP/IP stack.
713 *
714 * @remark Module dependencies and making sure that a component doesn't
715 * get unloaded while in use, is the sole responsibility of the
716 * driver/kext/whatever implementing the component.
717 */
718typedef struct SUPDRVFACTORY
719{
720 /** The (unique) name of the component factory. */
721 char szName[56];
722 /**
723 * Queries a factory interface.
724 *
725 * The factory interface is specific to each component and will be be
726 * found in the header(s) for the component alongside its UUID.
727 *
728 * @returns Pointer to the factory interfaces on success, NULL on failure.
729 *
730 * @param pSupDrvFactory Pointer to this structure.
731 * @param pSession The SUPDRV session making the query.
732 * @param pszInterfaceUuid The UUID of the factory interface.
733 */
734 DECLR0CALLBACKMEMBER(void *, pfnQueryFactoryInterface,(struct SUPDRVFACTORY const *pSupDrvFactory, PSUPDRVSESSION pSession, const char *pszInterfaceUuid));
735} SUPDRVFACTORY;
736/** Pointer to a support driver factory. */
737typedef SUPDRVFACTORY *PSUPDRVFACTORY;
738/** Pointer to a const support driver factory. */
739typedef SUPDRVFACTORY const *PCSUPDRVFACTORY;
740
741SUPR0DECL(int) SUPR0ComponentRegisterFactory(PSUPDRVSESSION pSession, PCSUPDRVFACTORY pFactory);
742SUPR0DECL(int) SUPR0ComponentDeregisterFactory(PSUPDRVSESSION pSession, PCSUPDRVFACTORY pFactory);
743SUPR0DECL(int) SUPR0ComponentQueryFactory(PSUPDRVSESSION pSession, const char *pszName, const char *pszInterfaceUuid, void **ppvFactoryIf);
744
745
746/** @defgroup grp_sup_r0_idc The IDC Interface
747 * @ingroup grp_sup_r0
748 * @{
749 */
750
751/** The current SUPDRV IDC version.
752 * This follows the usual high word / low word rules, i.e. high word is the
753 * major number and it signifies incompatible interface changes. */
754#define SUPDRV_IDC_VERSION UINT32_C(0x00010000)
755
756/**
757 * Inter-Driver Communcation Handle.
758 */
759typedef union SUPDRVIDCHANDLE
760{
761 /** Padding for opaque usage.
762 * Must be greater or equal in size than the private struct. */
763 void *apvPadding[4];
764#ifdef SUPDRVIDCHANDLEPRIVATE_DECLARED
765 /** The private view. */
766 struct SUPDRVIDCHANDLEPRIVATE s;
767#endif
768} SUPDRVIDCHANDLE;
769/** Pointer to a handle. */
770typedef SUPDRVIDCHANDLE *PSUPDRVIDCHANDLE;
771
772SUPR0DECL(int) SUPR0IdcOpen(PSUPDRVIDCHANDLE pHandle, uint32_t uReqVersion, uint32_t uMinVersion,
773 uint32_t *puSessionVersion, uint32_t *puDriverVersion, uint32_t *puDriverRevision);
774SUPR0DECL(int) SUPR0IdcCall(PSUPDRVIDCHANDLE pHandle, uint32_t iReq, void *pvReq, uint32_t cbReq);
775SUPR0DECL(int) SUPR0IdcClose(PSUPDRVIDCHANDLE pHandle);
776SUPR0DECL(PSUPDRVSESSION) SUPR0IdcGetSession(PSUPDRVIDCHANDLE pHandle);
777SUPR0DECL(int) SUPR0IdcComponentRegisterFactory(PSUPDRVIDCHANDLE pHandle, PCSUPDRVFACTORY pFactory);
778SUPR0DECL(int) SUPR0IdcComponentDeregisterFactory(PSUPDRVIDCHANDLE pHandle, PCSUPDRVFACTORY pFactory);
779
780/** @} */
781
782/** @} */
783#endif
784
785/** @} */
786
787__END_DECLS
788
789#endif
790
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