VirtualBox

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

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

SUP: SUPInit(ppSession=NULL, cbReserved=0) -> SUPR3Init(ppSession)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 26.3 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 * Load a module into R0 HC.
569 *
570 * @returns VBox status code.
571 * @param pszFilename The path to the image file.
572 * @param pszModule The module name. Max 32 bytes.
573 */
574SUPR3DECL(int) SUPLoadModule(const char *pszFilename, const char *pszModule, void **ppvImageBase);
575
576/**
577 * Frees a R0 HC module.
578 *
579 * @returns VBox status code.
580 * @param pszModule The module to free.
581 * @remark This will not actually 'free' the module, there are of course usage counting.
582 */
583SUPR3DECL(int) SUPFreeModule(void *pvImageBase);
584
585/**
586 * Get the address of a symbol in a ring-0 module.
587 *
588 * @returns VBox status code.
589 * @param pszModule The module name.
590 * @param pszSymbol Symbol name. If it's value is less than 64k it's treated like a
591 * ordinal value rather than a string pointer.
592 * @param ppvValue Where to store the symbol value.
593 */
594SUPR3DECL(int) SUPGetSymbolR0(void *pvImageBase, const char *pszSymbol, void **ppvValue);
595
596/**
597 * Load R0 HC VMM code.
598 *
599 * @returns VBox status code.
600 * @deprecated Use SUPLoadModule(pszFilename, "VMMR0.r0", &pvImageBase)
601 */
602SUPR3DECL(int) SUPLoadVMM(const char *pszFilename);
603
604/**
605 * Unloads R0 HC VMM code.
606 *
607 * @returns VBox status code.
608 * @deprecated Use SUPFreeModule().
609 */
610SUPR3DECL(int) SUPUnloadVMM(void);
611
612/**
613 * Get the physical address of the GIP.
614 *
615 * @returns VBox status code.
616 * @param pHCPhys Where to store the physical address of the GIP.
617 */
618SUPR3DECL(int) SUPGipGetPhys(PRTHCPHYS pHCPhys);
619
620/** @} */
621#endif /* IN_RING3 */
622
623
624#ifdef IN_RING0
625/** @defgroup grp_sup_r0 SUP Host Context Ring 0 API
626 * @ingroup grp_sup
627 * @{
628 */
629
630/**
631 * Execute callback on all cpus/cores (SUPR0ExecuteCallback)
632 */
633#define SUPDRVEXECCALLBACK_CPU_ALL (~0)
634
635/**
636 * Security objectype.
637 */
638typedef enum SUPDRVOBJTYPE
639{
640 /** The usual invalid object. */
641 SUPDRVOBJTYPE_INVALID = 0,
642 /** A Virtual Machine instance. */
643 SUPDRVOBJTYPE_VM,
644 /** Internal network. */
645 SUPDRVOBJTYPE_INTERNAL_NETWORK,
646 /** Internal network interface. */
647 SUPDRVOBJTYPE_INTERNAL_NETWORK_INTERFACE,
648 /** The first invalid object type in this end. */
649 SUPDRVOBJTYPE_END,
650 /** The usual 32-bit type size hack. */
651 SUPDRVOBJTYPE_32_BIT_HACK = 0x7ffffff
652} SUPDRVOBJTYPE;
653
654/**
655 * Object destructor callback.
656 * This is called for reference counted objectes when the count reaches 0.
657 *
658 * @param pvObj The object pointer.
659 * @param pvUser1 The first user argument.
660 * @param pvUser2 The second user argument.
661 */
662typedef DECLCALLBACK(void) FNSUPDRVDESTRUCTOR(void *pvObj, void *pvUser1, void *pvUser2);
663/** Pointer to a FNSUPDRVDESTRUCTOR(). */
664typedef FNSUPDRVDESTRUCTOR *PFNSUPDRVDESTRUCTOR;
665
666SUPR0DECL(void *) SUPR0ObjRegister(PSUPDRVSESSION pSession, SUPDRVOBJTYPE enmType, PFNSUPDRVDESTRUCTOR pfnDestructor, void *pvUser1, void *pvUser2);
667SUPR0DECL(int) SUPR0ObjAddRef(void *pvObj, PSUPDRVSESSION pSession);
668SUPR0DECL(int) SUPR0ObjRelease(void *pvObj, PSUPDRVSESSION pSession);
669SUPR0DECL(int) SUPR0ObjVerifyAccess(void *pvObj, PSUPDRVSESSION pSession, const char *pszObjName);
670
671SUPR0DECL(int) SUPR0LockMem(PSUPDRVSESSION pSession, RTR3PTR pvR3, uint32_t cPages, PRTHCPHYS paPages);
672SUPR0DECL(int) SUPR0UnlockMem(PSUPDRVSESSION pSession, RTR3PTR pvR3);
673SUPR0DECL(int) SUPR0ContAlloc(PSUPDRVSESSION pSession, uint32_t cPages, PRTR0PTR ppvR0, PRTR3PTR ppvR3, PRTHCPHYS pHCPhys);
674SUPR0DECL(int) SUPR0ContFree(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr);
675SUPR0DECL(int) SUPR0LowAlloc(PSUPDRVSESSION pSession, uint32_t cPages, PRTR0PTR ppvR0, PRTR3PTR ppvR3, PRTHCPHYS paPages);
676SUPR0DECL(int) SUPR0LowFree(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr);
677SUPR0DECL(int) SUPR0MemAlloc(PSUPDRVSESSION pSession, uint32_t cb, PRTR0PTR ppvR0, PRTR3PTR ppvR3);
678SUPR0DECL(int) SUPR0MemGetPhys(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr, PSUPPAGE paPages);
679SUPR0DECL(int) SUPR0MemFree(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr);
680SUPR0DECL(int) SUPR0PageAlloc(PSUPDRVSESSION pSession, uint32_t cPages, PRTR3PTR ppvR3, PRTHCPHYS paPages);
681SUPR0DECL(int) SUPR0PageFree(PSUPDRVSESSION pSession, RTR3PTR pvR3);
682SUPR0DECL(int) SUPR0GipMap(PSUPDRVSESSION pSession, PRTR3PTR ppGipR3, PRTHCPHYS pHCPhysGip);
683SUPR0DECL(int) SUPR0GipUnmap(PSUPDRVSESSION pSession);
684SUPR0DECL(int) SUPR0Printf(const char *pszFormat, ...);
685
686
687/**
688 * Support driver component factory.
689 *
690 * Component factories are registered by drivers that provides services
691 * such as the host network interface filtering and access to the host
692 * TCP/IP stack.
693 *
694 * @remark Module dependencies and making sure that a component doesn't
695 * get unloaded while in use, is the sole responsibility of the
696 * driver/kext/whatever implementing the component.
697 */
698typedef struct SUPDRVFACTORY
699{
700 /** The (unique) name of the component factory. */
701 char szName[56];
702 /**
703 * Queries a factory interface.
704 *
705 * The factory interface is specific to each component and will be be
706 * found in the header(s) for the component alongside its UUID.
707 *
708 * @returns Pointer to the factory interfaces on success, NULL on failure.
709 *
710 * @param pSupDrvFactory Pointer to this structure.
711 * @param pSession The SUPDRV session making the query.
712 * @param pszInterfaceUuid The UUID of the factory interface.
713 */
714 DECLR0CALLBACKMEMBER(void *, pfnQueryFactoryInterface,(struct SUPDRVFACTORY const *pSupDrvFactory, PSUPDRVSESSION pSession, const char *pszInterfaceUuid));
715} SUPDRVFACTORY;
716/** Pointer to a support driver factory. */
717typedef SUPDRVFACTORY *PSUPDRVFACTORY;
718/** Pointer to a const support driver factory. */
719typedef SUPDRVFACTORY const *PCSUPDRVFACTORY;
720
721SUPR0DECL(int) SUPR0ComponentRegisterFactory(PSUPDRVSESSION pSession, PCSUPDRVFACTORY pFactory);
722SUPR0DECL(int) SUPR0ComponentDeregisterFactory(PSUPDRVSESSION pSession, PCSUPDRVFACTORY pFactory);
723SUPR0DECL(int) SUPR0ComponentQueryFactory(PSUPDRVSESSION pSession, const char *pszName, const char *pszInterfaceUuid, void **ppvFactoryIf);
724
725
726/** @defgroup grp_sup_r0_idc The IDC Interface
727 * @ingroup grp_sup_r0
728 * @{
729 */
730
731/** The current SUPDRV IDC version.
732 * This follows the usual high word / low word rules, i.e. high word is the
733 * major number and it signifies incompatible interface changes. */
734#define SUPDRV_IDC_VERSION UINT32_C(0x00010000)
735
736/**
737 * Inter-Driver Communcation Handle.
738 */
739typedef union SUPDRVIDCHANDLE
740{
741 /** Padding for opaque usage.
742 * Must be greater or equal in size than the private struct. */
743 void *apvPadding[4];
744#ifdef SUPDRVIDCHANDLEPRIVATE_DECLARED
745 /** The private view. */
746 struct SUPDRVIDCHANDLEPRIVATE s;
747#endif
748} SUPDRVIDCHANDLE;
749/** Pointer to a handle. */
750typedef SUPDRVIDCHANDLE *PSUPDRVIDCHANDLE;
751
752SUPR0DECL(int) SUPR0IdcOpen(PSUPDRVIDCHANDLE pHandle, uint32_t uReqVersion, uint32_t uMinVersion,
753 uint32_t *puSessionVersion, uint32_t *puDriverVersion, uint32_t *puDriverRevision);
754SUPR0DECL(int) SUPR0IdcCall(PSUPDRVIDCHANDLE pHandle, uint32_t iReq, void *pvReq, uint32_t cbReq);
755SUPR0DECL(int) SUPR0IdcClose(PSUPDRVIDCHANDLE pHandle);
756SUPR0DECL(PSUPDRVSESSION) SUPR0IdcGetSession(PSUPDRVIDCHANDLE pHandle);
757SUPR0DECL(int) SUPR0IdcComponentRegisterFactory(PSUPDRVIDCHANDLE pHandle, PCSUPDRVFACTORY pFactory);
758SUPR0DECL(int) SUPR0IdcComponentDeregisterFactory(PSUPDRVIDCHANDLE pHandle, PCSUPDRVFACTORY pFactory);
759
760/** @} */
761
762/** @} */
763#endif
764
765/** @} */
766
767__END_DECLS
768
769#endif
770
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