VirtualBox

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

Last change on this file since 21217 was 21217, checked in by vboxsync, 15 years ago

include/VBox/*.h: Mark which components the header files relate to.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 39.1 KB
Line 
1/** @file
2 * SUP - Support Library. (HDrv)
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
39RT_C_DECLS_BEGIN
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 SUPR3GetPagingMode() */
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/** Event semaphore handle. Ring-0 / ring-3. */
311typedef R0PTRTYPE(struct SUPSEMEVENTHANDLE *) SUPSEMEVENT;
312/** Pointer to an event semaphore handle. */
313typedef SUPSEMEVENT *PSUPSEMEVENT;
314/** Nil event semaphore handle. */
315#define NIL_SUPSEMEVENT ((SUPSEMEVENT)0)
316
317/**
318 * Creates a single release event semaphore.
319 *
320 * @returns VBox status code.
321 * @param pSession The session handle of the caller.
322 * @param phEvent Where to return the handle to the event semaphore.
323 */
324SUPDECL(int) SUPSemEventCreate(PSUPDRVSESSION pSession, PSUPSEMEVENT phEvent);
325
326/**
327 * Closes a single release event semaphore handle.
328 *
329 * @returns VBox status code.
330 * @retval VINF_OBJECT_DESTROYED if the semaphore was destroyed.
331 * @retval VINF_SUCCESS if the handle was successfully closed but the sempahore
332 * object remained alive because of other references.
333 *
334 * @param pSession The session handle of the caller.
335 * @param hEvent The handle. Nil is quietly ignored.
336 */
337SUPDECL(int) SUPSemEventClose(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent);
338
339/**
340 * Signals a single release event semaphore.
341 *
342 * @returns VBox status code.
343 * @param pSession The session handle of the caller.
344 * @param hEvent The semaphore handle.
345 */
346SUPDECL(int) SUPSemEventSignal(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent);
347
348#ifdef IN_RING0
349/**
350 * Waits on a single release event semaphore, not interruptible.
351 *
352 * @returns VBox status code.
353 * @param pSession The session handle of the caller.
354 * @param hEvent The semaphore handle.
355 * @param cMillies The number of milliseconds to wait.
356 * @remarks Not available in ring-3.
357 */
358SUPDECL(int) SUPSemEventWait(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent, uint32_t cMillies);
359#endif
360
361/**
362 * Waits on a single release event semaphore, interruptible.
363 *
364 * @returns VBox status code.
365 * @param pSession The session handle of the caller.
366 * @param hEvent The semaphore handle.
367 * @param cMillies The number of milliseconds to wait.
368 */
369SUPDECL(int) SUPSemEventWaitNoResume(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent, uint32_t cMillies);
370
371
372/** Multiple release event semaphore handle. Ring-0 / ring-3. */
373typedef R0PTRTYPE(struct SUPSEMEVENTMULTIHANDLE *) SUPSEMEVENTMULTI;
374/** Pointer to an multiple release event semaphore handle. */
375typedef SUPSEMEVENTMULTI *PSUPSEMEVENTMULTI;
376/** Nil multiple release event semaphore handle. */
377#define NIL_SUPSEMEVENTMULTI ((SUPSEMEVENTMULTI)0)
378
379/**
380 * Creates a multiple release event semaphore.
381 *
382 * @returns VBox status code.
383 * @param pSession The session handle of the caller.
384 * @param phEventMulti Where to return the handle to the event semaphore.
385 */
386SUPDECL(int) SUPSemEventMultiCreate(PSUPDRVSESSION pSession, PSUPSEMEVENTMULTI phEventMulti);
387
388/**
389 * Closes a multiple release event semaphore handle.
390 *
391 * @returns VBox status code.
392 * @retval VINF_OBJECT_DESTROYED if the semaphore was destroyed.
393 * @retval VINF_SUCCESS if the handle was successfully closed but the sempahore
394 * object remained alive because of other references.
395 *
396 * @param pSession The session handle of the caller.
397 * @param hEventMulti The handle. Nil is quietly ignored.
398 */
399SUPDECL(int) SUPSemEventMultiClose(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti);
400
401/**
402 * Signals a multiple release event semaphore.
403 *
404 * @returns VBox status code.
405 * @param pSession The session handle of the caller.
406 * @param hEventMulti The semaphore handle.
407 */
408SUPDECL(int) SUPSemEventMultiSignal(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti);
409
410/**
411 * Resets a multiple release event semaphore.
412 *
413 * @returns VBox status code.
414 * @param pSession The session handle of the caller.
415 * @param hEventMulti The semaphore handle.
416 */
417SUPDECL(int) SUPSemEventMultiReset(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti);
418
419#ifdef IN_RING0
420/**
421 * Waits on a multiple release event semaphore, not interruptible.
422 *
423 * @returns VBox status code.
424 * @param pSession The session handle of the caller.
425 * @param hEventMulti The semaphore handle.
426 * @param cMillies The number of milliseconds to wait.
427 * @remarks Not available in ring-3.
428 */
429SUPDECL(int) SUPSemEventMultiWait(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti, uint32_t cMillies);
430#endif
431
432/**
433 * Waits on a multiple release event semaphore, interruptible.
434 *
435 * @returns VBox status code.
436 * @param pSession The session handle of the caller.
437 * @param hEventMulti The semaphore handle.
438 * @param cMillies The number of milliseconds to wait.
439 */
440SUPDECL(int) SUPSemEventMultiWaitNoResume(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti, uint32_t cMillies);
441
442
443#ifdef IN_RING3
444
445/** @defgroup grp_sup_r3 SUP Host Context Ring 3 API
446 * @ingroup grp_sup
447 * @{
448 */
449
450/**
451 * Installs the support library.
452 *
453 * @returns VBox status code.
454 */
455SUPR3DECL(int) SUPR3Install(void);
456
457/**
458 * Uninstalls the support library.
459 *
460 * @returns VBox status code.
461 */
462SUPR3DECL(int) SUPR3Uninstall(void);
463
464/**
465 * Trusted main entry point.
466 *
467 * This is exported as "TrustedMain" by the dynamic libraries which contains the
468 * "real" application binary for which the hardened stub is built. The entry
469 * point is invoked upon successfull initialization of the support library and
470 * runtime.
471 *
472 * @returns main kind of exit code.
473 * @param argc The argument count.
474 * @param argv The argument vector.
475 * @param envp The environment vector.
476 */
477typedef DECLCALLBACK(int) FNSUPTRUSTEDMAIN(int argc, char **argv, char **envp);
478/** Pointer to FNSUPTRUSTEDMAIN(). */
479typedef FNSUPTRUSTEDMAIN *PFNSUPTRUSTEDMAIN;
480
481/** Which operation failed. */
482typedef enum SUPINITOP
483{
484 /** Invalid. */
485 kSupInitOp_Invalid = 0,
486 /** Installation integrity error. */
487 kSupInitOp_Integrity,
488 /** Setuid related. */
489 kSupInitOp_RootCheck,
490 /** Driver related. */
491 kSupInitOp_Driver,
492 /** IPRT init related. */
493 kSupInitOp_IPRT,
494 /** Place holder. */
495 kSupInitOp_End
496} SUPINITOP;
497
498/**
499 * Trusted error entry point, optional.
500 *
501 * This is exported as "TrustedError" by the dynamic libraries which contains
502 * the "real" application binary for which the hardened stub is built.
503 *
504 * @param pszWhere Where the error occured (function name).
505 * @param enmWhat Which operation went wrong.
506 * @param rc The status code.
507 * @param pszMsgFmt Error message format string.
508 * @param va The message format arguments.
509 */
510typedef DECLCALLBACK(void) FNSUPTRUSTEDERROR(const char *pszWhere, SUPINITOP enmWhat, int rc, const char *pszMsgFmt, va_list va);
511/** Pointer to FNSUPTRUSTEDERROR. */
512typedef FNSUPTRUSTEDERROR *PFNSUPTRUSTEDERROR;
513
514/**
515 * Secure main.
516 *
517 * This is used for the set-user-ID-on-execute binaries on unixy systems
518 * and when using the open-vboxdrv-via-root-service setup on Windows.
519 *
520 * This function will perform the integrity checks of the VirtualBox
521 * installation, open the support driver, open the root service (later),
522 * and load the DLL corresponding to \a pszProgName and execute its main
523 * function.
524 *
525 * @returns Return code appropriate for main().
526 *
527 * @param pszProgName The program name. This will be used to figure out which
528 * DLL/SO/DYLIB to load and execute.
529 * @param fFlags Flags.
530 * @param argc The argument count.
531 * @param argv The argument vector.
532 * @param envp The environment vector.
533 */
534DECLHIDDEN(int) SUPR3HardenedMain(const char *pszProgName, uint32_t fFlags, int argc, char **argv, char **envp);
535
536/** @name SUPR3SecureMain flags.
537 * @{ */
538/** Don't open the device. (Intended for VirtualBox without -startvm.) */
539#define SUPSECMAIN_FLAGS_DONT_OPEN_DEV RT_BIT_32(0)
540/** @} */
541
542/**
543 * Initializes the support library.
544 * Each succesful call to SUPR3Init() must be countered by a
545 * call to SUPR3Term(false).
546 *
547 * @returns VBox status code.
548 * @param ppSession Where to store the session handle. Defaults to NULL.
549 */
550SUPR3DECL(int) SUPR3Init(PSUPDRVSESSION *ppSession);
551
552/**
553 * Terminates the support library.
554 *
555 * @returns VBox status code.
556 * @param fForced Forced termination. This means to ignore the
557 * init call count and just terminated.
558 */
559#ifdef __cplusplus
560SUPR3DECL(int) SUPR3Term(bool fForced = false);
561#else
562SUPR3DECL(int) SUPR3Term(int fForced);
563#endif
564
565/**
566 * Sets the ring-0 VM handle for use with fast IOCtls.
567 *
568 * @returns VBox status code.
569 * @param pVMR0 The ring-0 VM handle.
570 * NIL_RTR0PTR can be used to unset the handle when the
571 * VM is about to be destroyed.
572 */
573SUPR3DECL(int) SUPR3SetVMForFastIOCtl(PVMR0 pVMR0);
574
575/**
576 * Calls the HC R0 VMM entry point.
577 * See VMMR0Entry() for more details.
578 *
579 * @returns error code specific to uFunction.
580 * @param pVMR0 Pointer to the Ring-0 (Host Context) mapping of the VM structure.
581 * @param idCpu The virtual CPU ID.
582 * @param uOperation Operation to execute.
583 * @param pvArg Argument.
584 */
585SUPR3DECL(int) SUPR3CallVMMR0(PVMR0 pVMR0, VMCPUID idCpu, unsigned uOperation, void *pvArg);
586
587/**
588 * Variant of SUPR3CallVMMR0, except that this takes the fast ioclt path
589 * regardsless of compile-time defaults.
590 *
591 * @returns VBox status code.
592 * @param pVMR0 The ring-0 VM handle.
593 * @param uOperation The operation; only the SUP_VMMR0_DO_* ones are valid.
594 * @param idCpu The virtual CPU ID.
595 */
596SUPR3DECL(int) SUPR3CallVMMR0Fast(PVMR0 pVMR0, unsigned uOperation, VMCPUID idCpu);
597
598/**
599 * Calls the HC R0 VMM entry point, in a safer but slower manner than
600 * SUPR3CallVMMR0. When entering using this call the R0 components can call
601 * into the host kernel (i.e. use the SUPR0 and RT APIs).
602 *
603 * See VMMR0Entry() for more details.
604 *
605 * @returns error code specific to uFunction.
606 * @param pVMR0 Pointer to the Ring-0 (Host Context) mapping of the VM structure.
607 * @param idCpu The virtual CPU ID.
608 * @param uOperation Operation to execute.
609 * @param u64Arg Constant argument.
610 * @param pReqHdr Pointer to a request header. Optional.
611 * This will be copied in and out of kernel space. There currently is a size
612 * limit on this, just below 4KB.
613 */
614SUPR3DECL(int) SUPR3CallVMMR0Ex(PVMR0 pVMR0, VMCPUID idCpu, unsigned uOperation, uint64_t u64Arg, PSUPVMMR0REQHDR pReqHdr);
615
616/**
617 * Calls a ring-0 service.
618 *
619 * The operation and the request packet is specific to the service.
620 *
621 * @returns error code specific to uFunction.
622 * @param pszService The service name.
623 * @param cchService The length of the service name.
624 * @param uReq The request number.
625 * @param u64Arg Constant argument.
626 * @param pReqHdr Pointer to a request header. Optional.
627 * This will be copied in and out of kernel space. There currently is a size
628 * limit on this, just below 4KB.
629 */
630SUPR3DECL(int) SUPR3CallR0Service(const char *pszService, size_t cchService, uint32_t uOperation, uint64_t u64Arg, PSUPR0SERVICEREQHDR pReqHdr);
631
632/** Which logger. */
633typedef enum SUPLOGGER
634{
635 SUPLOGGER_DEBUG = 1,
636 SUPLOGGER_RELEASE
637} SUPLOGGER;
638
639/**
640 * Changes the settings of the specified ring-0 logger.
641 *
642 * @returns VBox status code.
643 * @param enmWhich Which logger.
644 * @param pszFlags The flags settings.
645 * @param pszGroups The groups settings.
646 * @param pszDest The destionation specificier.
647 */
648SUPR3DECL(int) SUPR3LoggerSettings(SUPLOGGER enmWhich, const char *pszFlags, const char *pszGroups, const char *pszDest);
649
650/**
651 * Creates a ring-0 logger instance.
652 *
653 * @returns VBox status code.
654 * @param enmWhich Which logger to create.
655 * @param pszFlags The flags settings.
656 * @param pszGroups The groups settings.
657 * @param pszDest The destionation specificier.
658 */
659SUPR3DECL(int) SUPR3LoggerCreate(SUPLOGGER enmWhich, const char *pszFlags, const char *pszGroups, const char *pszDest);
660
661/**
662 * Destroys a ring-0 logger instance.
663 *
664 * @returns VBox status code.
665 * @param enmWhich Which logger.
666 */
667SUPR3DECL(int) SUPR3LoggerDestroy(SUPLOGGER enmWhich);
668
669/**
670 * Queries the paging mode of the host OS.
671 *
672 * @returns The paging mode.
673 */
674SUPR3DECL(SUPPAGINGMODE) SUPR3GetPagingMode(void);
675
676/**
677 * Allocate zero-filled pages.
678 *
679 * Use this to allocate a number of pages suitable for seeding / locking.
680 * Call SUPR3PageFree() to free the pages once done with them.
681 *
682 * @returns VBox status.
683 * @param cPages Number of pages to allocate.
684 * @param ppvPages Where to store the base pointer to the allocated pages.
685 */
686SUPR3DECL(int) SUPR3PageAlloc(size_t cPages, void **ppvPages);
687
688/**
689 * Frees pages allocated with SUPR3PageAlloc().
690 *
691 * @returns VBox status.
692 * @param pvPages Pointer returned by SUPR3PageAlloc().
693 * @param cPages Number of pages that was allocated.
694 */
695SUPR3DECL(int) SUPR3PageFree(void *pvPages, size_t cPages);
696
697/**
698 * Allocate non-zeroed, locked, pages with user and, optionally, kernel
699 * mappings.
700 *
701 * Use SUPR3PageFreeEx() to free memory allocated with this function.
702 *
703 * @returns VBox status code.
704 * @param cPages The number of pages to allocate.
705 * @param fFlags Flags, reserved. Must be zero.
706 * @param ppvPages Where to store the address of the user mapping.
707 * @param pR0Ptr Where to store the address of the kernel mapping.
708 * NULL if no kernel mapping is desired.
709 * @param paPages Where to store the physical addresses of each page.
710 * Optional.
711 */
712SUPR3DECL(int) SUPR3PageAllocEx(size_t cPages, uint32_t fFlags, void **ppvPages, PRTR0PTR pR0Ptr, PSUPPAGE paPages);
713
714/**
715 * Maps a portion of a ring-3 only allocation into kernel space.
716 *
717 * @returns VBox status code.
718 *
719 * @param pvR3 The address SUPR3PageAllocEx return.
720 * @param off Offset to start mapping at. Must be page aligned.
721 * @param cb Number of bytes to map. Must be page aligned.
722 * @param fFlags Flags, must be zero.
723 * @param pR0Ptr Where to store the address on success.
724 *
725 */
726SUPR3DECL(int) SUPR3PageMapKernel(void *pvR3, uint32_t off, uint32_t cb, uint32_t fFlags, PRTR0PTR pR0Ptr);
727
728/**
729 * Changes the protection of
730 *
731 * @returns VBox status code.
732 * @retval VERR_NOT_SUPPORTED if the OS doesn't allow us to change page level
733 * protection. See also RTR0MemObjProtect.
734 *
735 * @param pvR3 The ring-3 address SUPR3PageAllocEx returned.
736 * @param R0Ptr The ring-0 address SUPR3PageAllocEx returned if it
737 * is desired that the corresponding ring-0 page
738 * mappings should change protection as well. Pass
739 * NIL_RTR0PTR if the ring-0 pages should remain
740 * unaffected.
741 * @param off Offset to start at which to start chagning the page
742 * level protection. Must be page aligned.
743 * @param cb Number of bytes to change. Must be page aligned.
744 * @param fProt The new page level protection, either a combination
745 * of RTMEM_PROT_READ, RTMEM_PROT_WRITE and
746 * RTMEM_PROT_EXEC, or just RTMEM_PROT_NONE.
747 */
748SUPR3DECL(int) SUPR3PageProtect(void *pvR3, RTR0PTR R0Ptr, uint32_t off, uint32_t cb, uint32_t fProt);
749
750/**
751 * Free pages allocated by SUPR3PageAllocEx.
752 *
753 * @returns VBox status code.
754 * @param pvPages The address of the user mapping.
755 * @param cPages The number of pages.
756 */
757SUPR3DECL(int) SUPR3PageFreeEx(void *pvPages, size_t cPages);
758
759/**
760 * Allocated memory with page aligned memory with a contiguous and locked physical
761 * memory backing below 4GB.
762 *
763 * @returns Pointer to the allocated memory (virtual address).
764 * *pHCPhys is set to the physical address of the memory.
765 * If ppvR0 isn't NULL, *ppvR0 is set to the ring-0 mapping.
766 * The returned memory must be freed using SUPR3ContFree().
767 * @returns NULL on failure.
768 * @param cPages Number of pages to allocate.
769 * @param pR0Ptr Where to store the ring-0 mapping of the allocation. (optional)
770 * @param pHCPhys Where to store the physical address of the memory block.
771 *
772 * @remark This 2nd version of this API exists because we're not able to map the
773 * ring-3 mapping executable on WIN64. This is a serious problem in regard to
774 * the world switchers.
775 */
776SUPR3DECL(void *) SUPR3ContAlloc(size_t cPages, PRTR0PTR pR0Ptr, PRTHCPHYS pHCPhys);
777
778/**
779 * Frees memory allocated with SUPR3ContAlloc().
780 *
781 * @returns VBox status code.
782 * @param pv Pointer to the memory block which should be freed.
783 * @param cPages Number of pages to be freed.
784 */
785SUPR3DECL(int) SUPR3ContFree(void *pv, size_t cPages);
786
787/**
788 * Allocated non contiguous physical memory below 4GB.
789 *
790 * The memory isn't zeroed.
791 *
792 * @returns VBox status code.
793 * @returns NULL on failure.
794 * @param cPages Number of pages to allocate.
795 * @param ppvPages Where to store the pointer to the allocated memory.
796 * The pointer stored here on success must be passed to
797 * SUPR3LowFree when the memory should be released.
798 * @param ppvPagesR0 Where to store the ring-0 pointer to the allocated memory. optional.
799 * @param paPages Where to store the physical addresses of the individual pages.
800 */
801SUPR3DECL(int) SUPR3LowAlloc(size_t cPages, void **ppvPages, PRTR0PTR ppvPagesR0, PSUPPAGE paPages);
802
803/**
804 * Frees memory allocated with SUPR3LowAlloc().
805 *
806 * @returns VBox status code.
807 * @param pv Pointer to the memory block which should be freed.
808 * @param cPages Number of pages that was allocated.
809 */
810SUPR3DECL(int) SUPR3LowFree(void *pv, size_t cPages);
811
812/**
813 * Load a module into R0 HC.
814 *
815 * This will verify the file integrity in a similar manner as
816 * SUPR3HardenedVerifyFile before loading it.
817 *
818 * @returns VBox status code.
819 * @param pszFilename The path to the image file.
820 * @param pszModule The module name. Max 32 bytes.
821 * @param ppvImageBase Where to store the image address.
822 */
823SUPR3DECL(int) SUPR3LoadModule(const char *pszFilename, const char *pszModule, void **ppvImageBase);
824
825/**
826 * Load a module into R0 HC.
827 *
828 * This will verify the file integrity in a similar manner as
829 * SUPR3HardenedVerifyFile before loading it.
830 *
831 * @returns VBox status code.
832 * @param pszFilename The path to the image file.
833 * @param pszModule The module name. Max 32 bytes.
834 * @param pszSrvReqHandler The name of the service request handler entry
835 * point. See FNSUPR0SERVICEREQHANDLER.
836 * @param ppvImageBase Where to store the image address.
837 */
838SUPR3DECL(int) SUPR3LoadServiceModule(const char *pszFilename, const char *pszModule,
839 const char *pszSrvReqHandler, void **ppvImageBase);
840
841/**
842 * Frees a R0 HC module.
843 *
844 * @returns VBox status code.
845 * @param pszModule The module to free.
846 * @remark This will not actually 'free' the module, there are of course usage counting.
847 */
848SUPR3DECL(int) SUPR3FreeModule(void *pvImageBase);
849
850/**
851 * Get the address of a symbol in a ring-0 module.
852 *
853 * @returns VBox status code.
854 * @param pszModule The module name.
855 * @param pszSymbol Symbol name. If it's value is less than 64k it's treated like a
856 * ordinal value rather than a string pointer.
857 * @param ppvValue Where to store the symbol value.
858 */
859SUPR3DECL(int) SUPR3GetSymbolR0(void *pvImageBase, const char *pszSymbol, void **ppvValue);
860
861/**
862 * Load R0 HC VMM code.
863 *
864 * @returns VBox status code.
865 * @deprecated Use SUPR3LoadModule(pszFilename, "VMMR0.r0", &pvImageBase)
866 */
867SUPR3DECL(int) SUPR3LoadVMM(const char *pszFilename);
868
869/**
870 * Unloads R0 HC VMM code.
871 *
872 * @returns VBox status code.
873 * @deprecated Use SUPR3FreeModule().
874 */
875SUPR3DECL(int) SUPR3UnloadVMM(void);
876
877/**
878 * Get the physical address of the GIP.
879 *
880 * @returns VBox status code.
881 * @param pHCPhys Where to store the physical address of the GIP.
882 */
883SUPR3DECL(int) SUPR3GipGetPhys(PRTHCPHYS pHCPhys);
884
885/**
886 * Verifies the integrity of a file, and optionally opens it.
887 *
888 * The integrity check is for whether the file is suitable for loading into
889 * the hypervisor or VM process. The integrity check may include verifying
890 * the authenticode/elfsign/whatever signature of the file, which can take
891 * a little while.
892 *
893 * @returns VBox status code. On failure it will have printed a LogRel message.
894 *
895 * @param pszFilename The file.
896 * @param pszWhat For the LogRel on failure.
897 * @param phFile Where to store the handle to the opened file. This is optional, pass NULL
898 * if the file should not be opened.
899 */
900SUPR3DECL(int) SUPR3HardenedVerifyFile(const char *pszFilename, const char *pszWhat, PRTFILE phFile);
901
902/**
903 * Same as RTLdrLoad() but will verify the files it loads (hardened builds).
904 *
905 * Will add dll suffix if missing and try load the file.
906 *
907 * @returns iprt status code.
908 * @param pszFilename Image filename. This must have a path.
909 * @param phLdrMod Where to store the handle to the loaded module.
910 */
911SUPR3DECL(int) SUPR3HardenedLdrLoad(const char *pszFilename, PRTLDRMOD phLdrMod);
912
913/**
914 * Same as RTLdrLoadAppPriv() but it will verify the files it loads (hardened
915 * builds).
916 *
917 * Will add dll suffix to the file if missing, then look for it in the
918 * architecture dependent application directory.
919 *
920 * @returns iprt status code.
921 * @param pszFilename Image filename.
922 * @param phLdrMod Where to store the handle to the loaded module.
923 */
924SUPR3DECL(int) SUPR3HardenedLdrLoadAppPriv(const char *pszFilename, PRTLDRMOD phLdrMod);
925
926/** @} */
927#endif /* IN_RING3 */
928
929
930#ifdef IN_RING0
931/** @defgroup grp_sup_r0 SUP Host Context Ring 0 API
932 * @ingroup grp_sup
933 * @{
934 */
935
936/**
937 * Security objectype.
938 */
939typedef enum SUPDRVOBJTYPE
940{
941 /** The usual invalid object. */
942 SUPDRVOBJTYPE_INVALID = 0,
943 /** A Virtual Machine instance. */
944 SUPDRVOBJTYPE_VM,
945 /** Internal network. */
946 SUPDRVOBJTYPE_INTERNAL_NETWORK,
947 /** Internal network interface. */
948 SUPDRVOBJTYPE_INTERNAL_NETWORK_INTERFACE,
949 /** Single release event semaphore. */
950 SUPDRVOBJTYPE_SEM_EVENT,
951 /** Multiple release event semaphore. */
952 SUPDRVOBJTYPE_SEM_EVENT_MULTI,
953 /** The first invalid object type in this end. */
954 SUPDRVOBJTYPE_END,
955 /** The usual 32-bit type size hack. */
956 SUPDRVOBJTYPE_32_BIT_HACK = 0x7ffffff
957} SUPDRVOBJTYPE;
958
959/**
960 * Object destructor callback.
961 * This is called for reference counted objectes when the count reaches 0.
962 *
963 * @param pvObj The object pointer.
964 * @param pvUser1 The first user argument.
965 * @param pvUser2 The second user argument.
966 */
967typedef DECLCALLBACK(void) FNSUPDRVDESTRUCTOR(void *pvObj, void *pvUser1, void *pvUser2);
968/** Pointer to a FNSUPDRVDESTRUCTOR(). */
969typedef FNSUPDRVDESTRUCTOR *PFNSUPDRVDESTRUCTOR;
970
971SUPR0DECL(void *) SUPR0ObjRegister(PSUPDRVSESSION pSession, SUPDRVOBJTYPE enmType, PFNSUPDRVDESTRUCTOR pfnDestructor, void *pvUser1, void *pvUser2);
972SUPR0DECL(int) SUPR0ObjAddRef(void *pvObj, PSUPDRVSESSION pSession);
973SUPR0DECL(int) SUPR0ObjAddRefEx(void *pvObj, PSUPDRVSESSION pSession, bool fNoBlocking);
974SUPR0DECL(int) SUPR0ObjRelease(void *pvObj, PSUPDRVSESSION pSession);
975SUPR0DECL(int) SUPR0ObjVerifyAccess(void *pvObj, PSUPDRVSESSION pSession, const char *pszObjName);
976
977SUPR0DECL(int) SUPR0LockMem(PSUPDRVSESSION pSession, RTR3PTR pvR3, uint32_t cPages, PRTHCPHYS paPages);
978SUPR0DECL(int) SUPR0UnlockMem(PSUPDRVSESSION pSession, RTR3PTR pvR3);
979SUPR0DECL(int) SUPR0ContAlloc(PSUPDRVSESSION pSession, uint32_t cPages, PRTR0PTR ppvR0, PRTR3PTR ppvR3, PRTHCPHYS pHCPhys);
980SUPR0DECL(int) SUPR0ContFree(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr);
981SUPR0DECL(int) SUPR0LowAlloc(PSUPDRVSESSION pSession, uint32_t cPages, PRTR0PTR ppvR0, PRTR3PTR ppvR3, PRTHCPHYS paPages);
982SUPR0DECL(int) SUPR0LowFree(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr);
983SUPR0DECL(int) SUPR0MemAlloc(PSUPDRVSESSION pSession, uint32_t cb, PRTR0PTR ppvR0, PRTR3PTR ppvR3);
984SUPR0DECL(int) SUPR0MemGetPhys(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr, PSUPPAGE paPages);
985SUPR0DECL(int) SUPR0MemFree(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr);
986SUPR0DECL(int) SUPR0PageAllocEx(PSUPDRVSESSION pSession, uint32_t cPages, uint32_t fFlags, PRTR3PTR ppvR3, PRTR0PTR ppvR0, PRTHCPHYS paPages);
987SUPR0DECL(int) SUPR0PageMapKernel(PSUPDRVSESSION pSession, RTR3PTR pvR3, uint32_t offSub, uint32_t cbSub, uint32_t fFlags, PRTR0PTR ppvR0);
988SUPR0DECL(int) SUPR0PageProtect(PSUPDRVSESSION pSession, RTR3PTR pvR3, RTR0PTR pvR0, uint32_t offSub, uint32_t cbSub, uint32_t fProt);
989SUPR0DECL(int) SUPR0PageFree(PSUPDRVSESSION pSession, RTR3PTR pvR3);
990SUPR0DECL(int) SUPR0GipMap(PSUPDRVSESSION pSession, PRTR3PTR ppGipR3, PRTHCPHYS pHCPhysGip);
991SUPR0DECL(int) SUPR0GipUnmap(PSUPDRVSESSION pSession);
992SUPR0DECL(int) SUPR0Printf(const char *pszFormat, ...);
993SUPR0DECL(SUPPAGINGMODE) SUPR0GetPagingMode(void);
994SUPR0DECL(int) SUPR0EnableVTx(bool fEnable);
995
996/** @name Absolute symbols
997 * Take the address of these, don't try call them.
998 * @{ */
999SUPR0DECL(void) SUPR0AbsIs64bit(void);
1000SUPR0DECL(void) SUPR0Abs64bitKernelCS(void);
1001SUPR0DECL(void) SUPR0Abs64bitKernelSS(void);
1002SUPR0DECL(void) SUPR0Abs64bitKernelDS(void);
1003SUPR0DECL(void) SUPR0AbsKernelCS(void);
1004SUPR0DECL(void) SUPR0AbsKernelSS(void);
1005SUPR0DECL(void) SUPR0AbsKernelDS(void);
1006SUPR0DECL(void) SUPR0AbsKernelES(void);
1007SUPR0DECL(void) SUPR0AbsKernelFS(void);
1008SUPR0DECL(void) SUPR0AbsKernelGS(void);
1009/** @} */
1010
1011/**
1012 * Support driver component factory.
1013 *
1014 * Component factories are registered by drivers that provides services
1015 * such as the host network interface filtering and access to the host
1016 * TCP/IP stack.
1017 *
1018 * @remark Module dependencies and making sure that a component doesn't
1019 * get unloaded while in use, is the sole responsibility of the
1020 * driver/kext/whatever implementing the component.
1021 */
1022typedef struct SUPDRVFACTORY
1023{
1024 /** The (unique) name of the component factory. */
1025 char szName[56];
1026 /**
1027 * Queries a factory interface.
1028 *
1029 * The factory interface is specific to each component and will be be
1030 * found in the header(s) for the component alongside its UUID.
1031 *
1032 * @returns Pointer to the factory interfaces on success, NULL on failure.
1033 *
1034 * @param pSupDrvFactory Pointer to this structure.
1035 * @param pSession The SUPDRV session making the query.
1036 * @param pszInterfaceUuid The UUID of the factory interface.
1037 */
1038 DECLR0CALLBACKMEMBER(void *, pfnQueryFactoryInterface,(struct SUPDRVFACTORY const *pSupDrvFactory, PSUPDRVSESSION pSession, const char *pszInterfaceUuid));
1039} SUPDRVFACTORY;
1040/** Pointer to a support driver factory. */
1041typedef SUPDRVFACTORY *PSUPDRVFACTORY;
1042/** Pointer to a const support driver factory. */
1043typedef SUPDRVFACTORY const *PCSUPDRVFACTORY;
1044
1045SUPR0DECL(int) SUPR0ComponentRegisterFactory(PSUPDRVSESSION pSession, PCSUPDRVFACTORY pFactory);
1046SUPR0DECL(int) SUPR0ComponentDeregisterFactory(PSUPDRVSESSION pSession, PCSUPDRVFACTORY pFactory);
1047SUPR0DECL(int) SUPR0ComponentQueryFactory(PSUPDRVSESSION pSession, const char *pszName, const char *pszInterfaceUuid, void **ppvFactoryIf);
1048
1049
1050/**
1051 * Service request callback function.
1052 *
1053 * @returns VBox status code.
1054 * @param pSession The caller's session.
1055 * @param u64Arg 64-bit integer argument.
1056 * @param pReqHdr The request header. Input / Output. Optional.
1057 */
1058typedef DECLCALLBACK(int) FNSUPR0SERVICEREQHANDLER(PSUPDRVSESSION pSession, uint32_t uOperation,
1059 uint64_t u64Arg, PSUPR0SERVICEREQHDR pReqHdr);
1060/** Pointer to a FNR0SERVICEREQHANDLER(). */
1061typedef R0PTRTYPE(FNSUPR0SERVICEREQHANDLER *) PFNSUPR0SERVICEREQHANDLER;
1062
1063
1064/** @defgroup grp_sup_r0_idc The IDC Interface
1065 * @ingroup grp_sup_r0
1066 * @{
1067 */
1068
1069/** The current SUPDRV IDC version.
1070 * This follows the usual high word / low word rules, i.e. high word is the
1071 * major number and it signifies incompatible interface changes. */
1072#define SUPDRV_IDC_VERSION UINT32_C(0x00010000)
1073
1074/**
1075 * Inter-Driver Communcation Handle.
1076 */
1077typedef union SUPDRVIDCHANDLE
1078{
1079 /** Padding for opaque usage.
1080 * Must be greater or equal in size than the private struct. */
1081 void *apvPadding[4];
1082#ifdef SUPDRVIDCHANDLEPRIVATE_DECLARED
1083 /** The private view. */
1084 struct SUPDRVIDCHANDLEPRIVATE s;
1085#endif
1086} SUPDRVIDCHANDLE;
1087/** Pointer to a handle. */
1088typedef SUPDRVIDCHANDLE *PSUPDRVIDCHANDLE;
1089
1090SUPR0DECL(int) SUPR0IdcOpen(PSUPDRVIDCHANDLE pHandle, uint32_t uReqVersion, uint32_t uMinVersion,
1091 uint32_t *puSessionVersion, uint32_t *puDriverVersion, uint32_t *puDriverRevision);
1092SUPR0DECL(int) SUPR0IdcCall(PSUPDRVIDCHANDLE pHandle, uint32_t iReq, void *pvReq, uint32_t cbReq);
1093SUPR0DECL(int) SUPR0IdcClose(PSUPDRVIDCHANDLE pHandle);
1094SUPR0DECL(PSUPDRVSESSION) SUPR0IdcGetSession(PSUPDRVIDCHANDLE pHandle);
1095SUPR0DECL(int) SUPR0IdcComponentRegisterFactory(PSUPDRVIDCHANDLE pHandle, PCSUPDRVFACTORY pFactory);
1096SUPR0DECL(int) SUPR0IdcComponentDeregisterFactory(PSUPDRVIDCHANDLE pHandle, PCSUPDRVFACTORY pFactory);
1097
1098/** @} */
1099
1100/** @} */
1101#endif
1102
1103/** @} */
1104
1105RT_C_DECLS_END
1106
1107#endif
1108
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use