VirtualBox

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

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

IPRT/SUP: Renamed RTLdrOpenAppSharedLib to RTLdrOpenAppPriv. Hardend versions of RTLdrOpen and RTLdrOpenAppPriv. Use the hardend versions where appropriate.

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