VirtualBox

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

Last change on this file since 36254 was 36254, checked in by vboxsync, 14 years ago

GIP,++: Lots of CPUs (disabled).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 49.2 KB
Line 
1/** @file
2 * SUP - Support Library. (HDrv)
3 */
4
5/*
6 * Copyright (C) 2006-2007 Oracle Corporation
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
26#ifndef ___VBox_sup_h
27#define ___VBox_sup_h
28
29#include <VBox/cdefs.h>
30#include <VBox/types.h>
31#include <iprt/assert.h>
32#include <iprt/stdarg.h>
33#include <iprt/cpuset.h>
34
35RT_C_DECLS_BEGIN
36
37/** @defgroup grp_sup The Support Library API
38 * @{
39 */
40
41/**
42 * Physical page descriptor.
43 */
44#pragma pack(4) /* space is more important. */
45typedef struct SUPPAGE
46{
47 /** Physical memory address. */
48 RTHCPHYS Phys;
49 /** Reserved entry for internal use by the caller. */
50 RTHCUINTPTR uReserved;
51} SUPPAGE;
52#pragma pack()
53/** Pointer to a page descriptor. */
54typedef SUPPAGE *PSUPPAGE;
55/** Pointer to a const page descriptor. */
56typedef const SUPPAGE *PCSUPPAGE;
57
58/**
59 * The paging mode.
60 *
61 * @remarks Users are making assumptions about the order here!
62 */
63typedef enum SUPPAGINGMODE
64{
65 /** The usual invalid entry.
66 * This is returned by SUPR3GetPagingMode() */
67 SUPPAGINGMODE_INVALID = 0,
68 /** Normal 32-bit paging, no global pages */
69 SUPPAGINGMODE_32_BIT,
70 /** Normal 32-bit paging with global pages. */
71 SUPPAGINGMODE_32_BIT_GLOBAL,
72 /** PAE mode, no global pages, no NX. */
73 SUPPAGINGMODE_PAE,
74 /** PAE mode with global pages. */
75 SUPPAGINGMODE_PAE_GLOBAL,
76 /** PAE mode with NX, no global pages. */
77 SUPPAGINGMODE_PAE_NX,
78 /** PAE mode with global pages and NX. */
79 SUPPAGINGMODE_PAE_GLOBAL_NX,
80 /** AMD64 mode, no global pages. */
81 SUPPAGINGMODE_AMD64,
82 /** AMD64 mode with global pages, no NX. */
83 SUPPAGINGMODE_AMD64_GLOBAL,
84 /** AMD64 mode with NX, no global pages. */
85 SUPPAGINGMODE_AMD64_NX,
86 /** AMD64 mode with global pages and NX. */
87 SUPPAGINGMODE_AMD64_GLOBAL_NX
88} SUPPAGINGMODE;
89
90#ifdef SUP_WITH_LOTS_OF_CPUS
91# ifndef RT_WITH_LOTS_OF_CPUS
92# error "RT_WITH_LOTS_OF_CPUS must be defined with SUP_WITH_LOTS_OF_CPUS"
93# endif
94#endif
95
96/**
97 * The CPU state.
98 */
99typedef enum SUPGIPCPUSTATE
100{
101 /** Invalid CPU state / unused CPU entry. */
102 SUPGIPCPUSTATE_INVALID = 0,
103 /** The CPU is not present. */
104 SUPGIPCPUSTATE_ABSENT,
105 /** The CPU is offline. */
106 SUPGIPCPUSTATE_OFFLINE,
107 /** The CPU is online. */
108 SUPGIPCPUSTATE_ONLINE,
109 /** Force 32-bit enum type. */
110 SUPGIPCPUSTATE_32_BIT_HACK = 0x7fffffff
111} SUPGIPCPUSTATE;
112
113/**
114 * Per CPU data.
115 */
116typedef struct SUPGIPCPU
117{
118 /** Update transaction number.
119 * This number is incremented at the start and end of each update. It follows
120 * thusly that odd numbers indicates update in progress, while even numbers
121 * indicate stable data. Use this to make sure that the data items you fetch
122 * are consistent. */
123 volatile uint32_t u32TransactionId;
124 /** The interval in TSC ticks between two NanoTS updates.
125 * This is the average interval over the last 2, 4 or 8 updates + a little slack.
126 * The slack makes the time go a tiny tiny bit slower and extends the interval enough
127 * to avoid ending up with too many 1ns increments. */
128 volatile uint32_t u32UpdateIntervalTSC;
129 /** Current nanosecond timestamp. */
130 volatile uint64_t u64NanoTS;
131 /** The TSC at the time of u64NanoTS. */
132 volatile uint64_t u64TSC;
133 /** Current CPU Frequency. */
134 volatile uint64_t u64CpuHz;
135 /** Number of errors during updating.
136 * Typical errors are under/overflows. */
137 volatile uint32_t cErrors;
138 /** Index of the head item in au32TSCHistory. */
139 volatile uint32_t iTSCHistoryHead;
140 /** Array of recent TSC interval deltas.
141 * The most recent item is at index iTSCHistoryHead.
142 * This history is used to calculate u32UpdateIntervalTSC.
143 */
144 volatile uint32_t au32TSCHistory[8];
145 /** The interval between the last two NanoTS updates. (experiment for now) */
146 volatile uint32_t u32PrevUpdateIntervalNS;
147
148 /** Reserved for future per processor data. */
149#ifdef SUP_WITH_LOTS_OF_CPUS
150 volatile uint32_t au32Reserved[5+5];
151#else
152 volatile uint32_t au32Reserved[5];
153#endif
154
155 /** @todo Add topology/NUMA info. */
156#ifdef SUP_WITH_LOTS_OF_CPUS
157 /** The CPU state. */
158 SUPGIPCPUSTATE volatile enmState;
159 /** The host CPU ID of this CPU (the SUPGIPCPU is indexed by APIC ID). */
160 RTCPUID idCpu;
161 /** The CPU set index of this CPU. */
162 int16_t iCpuSet;
163 /** The APIC ID of this CPU. */
164 uint16_t idApic;
165#endif
166} SUPGIPCPU;
167#ifdef SUP_WITH_LOTS_OF_CPUS
168AssertCompileSize(RTCPUID, 4);
169AssertCompileSize(SUPGIPCPU, 128);
170#else
171AssertCompileSize(SUPGIPCPU, 96);
172#endif
173AssertCompileMemberAlignment(SUPGIPCPU, u64NanoTS, 8);
174AssertCompileMemberAlignment(SUPGIPCPU, u64TSC, 8);
175
176/** Pointer to per cpu data.
177 * @remark there is no const version of this typedef, see g_pSUPGlobalInfoPage for details. */
178typedef SUPGIPCPU *PSUPGIPCPU;
179
180
181
182#ifndef SUP_WITH_LOTS_OF_CPUS
183/** The number of CPUs covered by the GIP.
184 * @remarks Must be a power of two! */
185# define SUPGLOBALINFOPAGE_CPUS 32
186#endif
187
188/**
189 * Global Information Page.
190 *
191 * This page contains useful information and can be mapped into any
192 * process or VM. It can be accessed thru the g_pSUPGlobalInfoPage
193 * pointer when a session is open.
194 */
195typedef struct SUPGLOBALINFOPAGE
196{
197 /** Magic (SUPGLOBALINFOPAGE_MAGIC). */
198 uint32_t u32Magic;
199 /** The GIP version. */
200 uint32_t u32Version;
201
202 /** The GIP update mode, see SUPGIPMODE. */
203 uint32_t u32Mode;
204#ifdef SUP_WITH_LOTS_OF_CPUS
205 /** The number of entries in the CPU table.
206 * (This can work as RTMpGetArraySize().) */
207 uint16_t cCpus;
208 /** The size of the GIP in pages. */
209 uint16_t cPages;
210#else
211 /** Reserved / padding. */
212 uint32_t u32Padding0;
213#endif
214 /** The update frequency of the of the NanoTS. */
215 volatile uint32_t u32UpdateHz;
216 /** The update interval in nanoseconds. (10^9 / u32UpdateHz) */
217 volatile uint32_t u32UpdateIntervalNS;
218 /** The timestamp of the last time we update the update frequency. */
219 volatile uint64_t u64NanoTSLastUpdateHz;
220#ifdef SUP_WITH_LOTS_OF_CPUS
221 /** The set of online CPUs. */
222 RTCPUSET OnlineCpuSet;
223 /** The number of CPUs that are online. */
224 volatile uint32_t cOnlineCpus;
225 /** The number of CPUs present in the system. */
226 volatile uint32_t cPresentCpus;
227 /** The set of present CPUs. */
228 RTCPUSET PresentCpuSet;
229 /** The set of possible CPUs. */
230 RTCPUSET PossibleCpuSet;
231 /** The highest number of CPUs possible. */
232 uint32_t cPossibleCpus;
233 /** The max CPU ID (RTMpGetMaxCpuId). */
234 RTCPUID idCpuMax;
235#endif
236
237 /** Padding / reserved space for future data. */
238#ifdef SUP_WITH_LOTS_OF_CPUS
239 uint32_t au32Padding1[28];
240#else
241 uint32_t au32Padding1[56];
242#endif
243
244#ifdef SUP_WITH_LOTS_OF_CPUS
245 /** Table indexed by the CPU APIC ID to get the CPU table index. */
246 uint16_t aiCpuFromApicId[256];
247 /** CPU set index to CPU table index. */
248 uint16_t aiCpuFromCpuSetIdx[RTCPUSET_MAX_CPUS];
249#endif
250
251#ifdef SUP_WITH_LOTS_OF_CPUS
252 /** Array of per-cpu data.
253 * This is index by ApicId via the aiCpuFromApicId table.
254 *
255 * The clock and frequency information is updated for all CPUs if u32Mode
256 * is SUPGIPMODE_ASYNC_TSC, otherwise (SUPGIPMODE_SYNC_TSC) only the first
257 * entry is updated. */
258 SUPGIPCPU aCPUs[1];
259#else
260 /** Array of per-cpu data.
261 * If u32Mode == SUPGIPMODE_SYNC_TSC then only the first entry is used.
262 * If u32Mode == SUPGIPMODE_ASYNC_TSC then the CPU ACPI ID is used as an
263 * index into the array. */
264 SUPGIPCPU aCPUs[SUPGLOBALINFOPAGE_CPUS];
265#endif
266} SUPGLOBALINFOPAGE;
267#ifndef SUP_WITH_LOTS_OF_CPUS
268AssertCompile(sizeof(SUPGLOBALINFOPAGE) <= 0x1000);
269#endif
270#ifdef SUP_WITH_LOTS_OF_CPUS
271AssertCompileMemberAlignment(SUPGLOBALINFOPAGE, u64NanoTSLastUpdateHz, 8);
272AssertCompileMemberAlignment(SUPGLOBALINFOPAGE, aCPUs[0], 256);
273AssertCompileMemberAlignment(SUPGLOBALINFOPAGE, aCPUs[1], 128);
274#endif
275
276/** Pointer to the global info page.
277 * @remark there is no const version of this typedef, see g_pSUPGlobalInfoPage for details. */
278typedef SUPGLOBALINFOPAGE *PSUPGLOBALINFOPAGE;
279
280
281/** The value of the SUPGLOBALINFOPAGE::u32Magic field. (Soryo Fuyumi) */
282#define SUPGLOBALINFOPAGE_MAGIC 0x19590106
283/** The GIP version.
284 * Upper 16 bits is the major version. Major version is only changed with
285 * incompatible changes in the GIP. */
286#ifdef SUP_WITH_LOTS_OF_CPUS
287# define SUPGLOBALINFOPAGE_VERSION 0x00030000
288#else
289# define SUPGLOBALINFOPAGE_VERSION 0x00020000
290#endif
291
292/**
293 * SUPGLOBALINFOPAGE::u32Mode values.
294 */
295typedef enum SUPGIPMODE
296{
297 /** The usual invalid null entry. */
298 SUPGIPMODE_INVALID = 0,
299 /** The TSC of the cores and cpus in the system is in sync. */
300 SUPGIPMODE_SYNC_TSC,
301 /** Each core has it's own TSC. */
302 SUPGIPMODE_ASYNC_TSC,
303 /** The usual 32-bit hack. */
304 SUPGIPMODE_32BIT_HACK = 0x7fffffff
305} SUPGIPMODE;
306
307/** Pointer to the Global Information Page.
308 *
309 * This pointer is valid as long as SUPLib has a open session. Anyone using
310 * the page must treat this pointer as highly volatile and not trust it beyond
311 * one transaction.
312 *
313 * @remark The GIP page is read-only to everyone but the support driver and
314 * is actually mapped read only everywhere but in ring-0. However
315 * it is not marked 'const' as this might confuse compilers into
316 * thinking that values doesn't change even if members are marked
317 * as volatile. Thus, there is no PCSUPGLOBALINFOPAGE type.
318 */
319#if defined(IN_SUP_R0) || defined(IN_SUP_R3) || defined(IN_SUP_RC)
320extern DECLEXPORT(PSUPGLOBALINFOPAGE) g_pSUPGlobalInfoPage;
321
322#elif !defined(IN_RING0) || defined(RT_OS_WINDOWS)
323extern DECLIMPORT(PSUPGLOBALINFOPAGE) g_pSUPGlobalInfoPage;
324
325#else /* IN_RING0 && !RT_OS_WINDOWS */
326# if !defined(__GNUC__) || defined(RT_OS_DARWIN) || !defined(RT_ARCH_AMD64)
327# define g_pSUPGlobalInfoPage (&g_SUPGlobalInfoPage)
328# else
329# define g_pSUPGlobalInfoPage (SUPGetGIPHlp())
330/** Workaround for ELF+GCC problem on 64-bit hosts.
331 * (GCC emits a mov with a R_X86_64_32 reloc, we need R_X86_64_64.) */
332DECLINLINE(PSUPGLOBALINFOPAGE) SUPGetGIPHlp(void)
333{
334 PSUPGLOBALINFOPAGE pGIP;
335 __asm__ __volatile__ ("movabs $g_SUPGlobalInfoPage,%0\n\t"
336 : "=a" (pGIP));
337 return pGIP;
338}
339# endif
340/** The GIP.
341 * We save a level of indirection by exporting the GIP instead of a variable
342 * pointing to it. */
343extern DECLIMPORT(SUPGLOBALINFOPAGE) g_SUPGlobalInfoPage;
344#endif
345
346/**
347 * Gets the GIP pointer.
348 *
349 * @returns Pointer to the GIP or NULL.
350 */
351SUPDECL(PSUPGLOBALINFOPAGE) SUPGetGIP(void);
352
353#ifdef ___iprt_asm_amd64_x86_h
354/**
355 * Gets the TSC frequency of the calling CPU.
356 *
357 * @returns TSC frequency, UINT64_MAX on failure.
358 * @param pGip The GIP pointer.
359 */
360DECLINLINE(uint64_t) SUPGetCpuHzFromGIP(PSUPGLOBALINFOPAGE pGip)
361{
362 unsigned iCpu;
363
364 if (RT_UNLIKELY(!pGip || pGip->u32Magic != SUPGLOBALINFOPAGE_MAGIC))
365 return UINT64_MAX;
366
367 if (pGip->u32Mode != SUPGIPMODE_ASYNC_TSC)
368 iCpu = 0;
369 else
370 {
371# ifdef SUP_WITH_LOTS_OF_CPUS
372 iCpu = pGip->aiCpuFromApicId[ASMGetApicId()];
373 if (iCpu >= pGip->cCpus)
374 return UINT64_MAX;
375# else
376 iCpu = ASMGetApicId();
377 if (RT_UNLIKELY(iCpu >= RT_ELEMENTS(pGip->aCPUs)))
378 return UINT64_MAX;
379# endif
380 }
381
382 return pGip->aCPUs[iCpu].u64CpuHz;
383}
384#endif
385
386/**
387 * Request for generic VMMR0Entry calls.
388 */
389typedef struct SUPVMMR0REQHDR
390{
391 /** The magic. (SUPVMMR0REQHDR_MAGIC) */
392 uint32_t u32Magic;
393 /** The size of the request. */
394 uint32_t cbReq;
395} SUPVMMR0REQHDR;
396/** Pointer to a ring-0 request header. */
397typedef SUPVMMR0REQHDR *PSUPVMMR0REQHDR;
398/** the SUPVMMR0REQHDR::u32Magic value (Ethan Iverson - The Bad Plus). */
399#define SUPVMMR0REQHDR_MAGIC UINT32_C(0x19730211)
400
401
402/** For the fast ioctl path.
403 * @{
404 */
405/** @see VMMR0_DO_RAW_RUN. */
406#define SUP_VMMR0_DO_RAW_RUN 0
407/** @see VMMR0_DO_HWACC_RUN. */
408#define SUP_VMMR0_DO_HWACC_RUN 1
409/** @see VMMR0_DO_NOP */
410#define SUP_VMMR0_DO_NOP 2
411/** @} */
412
413/** SUPR3QueryVTCaps capability flags
414 * @{
415 */
416#define SUPVTCAPS_AMD_V RT_BIT(0)
417#define SUPVTCAPS_VT_X RT_BIT(1)
418#define SUPVTCAPS_NESTED_PAGING RT_BIT(2)
419/** @} */
420
421/**
422 * Request for generic FNSUPR0SERVICEREQHANDLER calls.
423 */
424typedef struct SUPR0SERVICEREQHDR
425{
426 /** The magic. (SUPR0SERVICEREQHDR_MAGIC) */
427 uint32_t u32Magic;
428 /** The size of the request. */
429 uint32_t cbReq;
430} SUPR0SERVICEREQHDR;
431/** Pointer to a ring-0 service request header. */
432typedef SUPR0SERVICEREQHDR *PSUPR0SERVICEREQHDR;
433/** the SUPVMMR0REQHDR::u32Magic value (Esbjoern Svensson - E.S.P.). */
434#define SUPR0SERVICEREQHDR_MAGIC UINT32_C(0x19640416)
435
436
437/** Event semaphore handle. Ring-0 / ring-3. */
438typedef R0PTRTYPE(struct SUPSEMEVENTHANDLE *) SUPSEMEVENT;
439/** Pointer to an event semaphore handle. */
440typedef SUPSEMEVENT *PSUPSEMEVENT;
441/** Nil event semaphore handle. */
442#define NIL_SUPSEMEVENT ((SUPSEMEVENT)0)
443
444/**
445 * Creates a single release event semaphore.
446 *
447 * @returns VBox status code.
448 * @param pSession The session handle of the caller.
449 * @param phEvent Where to return the handle to the event semaphore.
450 */
451SUPDECL(int) SUPSemEventCreate(PSUPDRVSESSION pSession, PSUPSEMEVENT phEvent);
452
453/**
454 * Closes a single release event semaphore handle.
455 *
456 * @returns VBox status code.
457 * @retval VINF_OBJECT_DESTROYED if the semaphore was destroyed.
458 * @retval VINF_SUCCESS if the handle was successfully closed but the semaphore
459 * object remained alive because of other references.
460 *
461 * @param pSession The session handle of the caller.
462 * @param hEvent The handle. Nil is quietly ignored.
463 */
464SUPDECL(int) SUPSemEventClose(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent);
465
466/**
467 * Signals a single release event semaphore.
468 *
469 * @returns VBox status code.
470 * @param pSession The session handle of the caller.
471 * @param hEvent The semaphore handle.
472 */
473SUPDECL(int) SUPSemEventSignal(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent);
474
475#ifdef IN_RING0
476/**
477 * Waits on a single release event semaphore, not interruptible.
478 *
479 * @returns VBox status code.
480 * @param pSession The session handle of the caller.
481 * @param hEvent The semaphore handle.
482 * @param cMillies The number of milliseconds to wait.
483 * @remarks Not available in ring-3.
484 */
485SUPDECL(int) SUPSemEventWait(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent, uint32_t cMillies);
486#endif
487
488/**
489 * Waits on a single release event semaphore, interruptible.
490 *
491 * @returns VBox status code.
492 * @param pSession The session handle of the caller.
493 * @param hEvent The semaphore handle.
494 * @param cMillies The number of milliseconds to wait.
495 */
496SUPDECL(int) SUPSemEventWaitNoResume(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent, uint32_t cMillies);
497
498/**
499 * Waits on a single release event semaphore, interruptible.
500 *
501 * @returns VBox status code.
502 * @param pSession The session handle of the caller.
503 * @param hEvent The semaphore handle.
504 * @param uNsTimeout The deadline given on the RTTimeNanoTS() clock.
505 */
506SUPDECL(int) SUPSemEventWaitNsAbsIntr(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent, uint64_t uNsTimeout);
507
508/**
509 * Waits on a single release event semaphore, interruptible.
510 *
511 * @returns VBox status code.
512 * @param pSession The session handle of the caller.
513 * @param hEvent The semaphore handle.
514 * @param cNsTimeout The number of nanoseconds to wait.
515 */
516SUPDECL(int) SUPSemEventWaitNsRelIntr(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent, uint64_t cNsTimeout);
517
518/**
519 * Gets the best timeout resolution that SUPSemEventWaitNsAbsIntr and
520 * SUPSemEventWaitNsAbsIntr can do.
521 *
522 * @returns The resolution in nanoseconds.
523 * @param pSession The session handle of the caller.
524 */
525SUPDECL(uint32_t) SUPSemEventGetResolution(PSUPDRVSESSION pSession);
526
527
528/** Multiple release event semaphore handle. Ring-0 / ring-3. */
529typedef R0PTRTYPE(struct SUPSEMEVENTMULTIHANDLE *) SUPSEMEVENTMULTI;
530/** Pointer to an multiple release event semaphore handle. */
531typedef SUPSEMEVENTMULTI *PSUPSEMEVENTMULTI;
532/** Nil multiple release event semaphore handle. */
533#define NIL_SUPSEMEVENTMULTI ((SUPSEMEVENTMULTI)0)
534
535/**
536 * Creates a multiple release event semaphore.
537 *
538 * @returns VBox status code.
539 * @param pSession The session handle of the caller.
540 * @param phEventMulti Where to return the handle to the event semaphore.
541 */
542SUPDECL(int) SUPSemEventMultiCreate(PSUPDRVSESSION pSession, PSUPSEMEVENTMULTI phEventMulti);
543
544/**
545 * Closes a multiple release event semaphore handle.
546 *
547 * @returns VBox status code.
548 * @retval VINF_OBJECT_DESTROYED if the semaphore was destroyed.
549 * @retval VINF_SUCCESS if the handle was successfully closed but the semaphore
550 * object remained alive because of other references.
551 *
552 * @param pSession The session handle of the caller.
553 * @param hEventMulti The handle. Nil is quietly ignored.
554 */
555SUPDECL(int) SUPSemEventMultiClose(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti);
556
557/**
558 * Signals a multiple release event semaphore.
559 *
560 * @returns VBox status code.
561 * @param pSession The session handle of the caller.
562 * @param hEventMulti The semaphore handle.
563 */
564SUPDECL(int) SUPSemEventMultiSignal(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti);
565
566/**
567 * Resets a multiple release event semaphore.
568 *
569 * @returns VBox status code.
570 * @param pSession The session handle of the caller.
571 * @param hEventMulti The semaphore handle.
572 */
573SUPDECL(int) SUPSemEventMultiReset(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti);
574
575#ifdef IN_RING0
576/**
577 * Waits on a multiple release event semaphore, not interruptible.
578 *
579 * @returns VBox status code.
580 * @param pSession The session handle of the caller.
581 * @param hEventMulti The semaphore handle.
582 * @param cMillies The number of milliseconds to wait.
583 * @remarks Not available in ring-3.
584 */
585SUPDECL(int) SUPSemEventMultiWait(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti, uint32_t cMillies);
586#endif
587
588/**
589 * Waits on a multiple release event semaphore, interruptible.
590 *
591 * @returns VBox status code.
592 * @param pSession The session handle of the caller.
593 * @param hEventMulti The semaphore handle.
594 * @param cMillies The number of milliseconds to wait.
595 */
596SUPDECL(int) SUPSemEventMultiWaitNoResume(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti, uint32_t cMillies);
597
598/**
599 * Waits on a multiple release event semaphore, interruptible.
600 *
601 * @returns VBox status code.
602 * @param pSession The session handle of the caller.
603 * @param hEventMulti The semaphore handle.
604 * @param uNsTimeout The deadline given on the RTTimeNanoTS() clock.
605 */
606SUPDECL(int) SUPSemEventMultiWaitNsAbsIntr(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti, uint64_t uNsTimeout);
607
608/**
609 * Waits on a multiple release event semaphore, interruptible.
610 *
611 * @returns VBox status code.
612 * @param pSession The session handle of the caller.
613 * @param hEventMulti The semaphore handle.
614 * @param cNsTimeout The number of nanoseconds to wait.
615 */
616SUPDECL(int) SUPSemEventMultiWaitNsRelIntr(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti, uint64_t cNsTimeout);
617
618/**
619 * Gets the best timeout resolution that SUPSemEventMultiWaitNsAbsIntr and
620 * SUPSemEventMultiWaitNsRelIntr can do.
621 *
622 * @returns The resolution in nanoseconds.
623 * @param pSession The session handle of the caller.
624 */
625SUPDECL(uint32_t) SUPSemEventMultiGetResolution(PSUPDRVSESSION pSession);
626
627
628#ifdef IN_RING3
629
630/** @defgroup grp_sup_r3 SUP Host Context Ring-3 API
631 * @ingroup grp_sup
632 * @{
633 */
634
635/**
636 * Installs the support library.
637 *
638 * @returns VBox status code.
639 */
640SUPR3DECL(int) SUPR3Install(void);
641
642/**
643 * Uninstalls the support library.
644 *
645 * @returns VBox status code.
646 */
647SUPR3DECL(int) SUPR3Uninstall(void);
648
649/**
650 * Trusted main entry point.
651 *
652 * This is exported as "TrustedMain" by the dynamic libraries which contains the
653 * "real" application binary for which the hardened stub is built. The entry
654 * point is invoked upon successful initialization of the support library and
655 * runtime.
656 *
657 * @returns main kind of exit code.
658 * @param argc The argument count.
659 * @param argv The argument vector.
660 * @param envp The environment vector.
661 */
662typedef DECLCALLBACK(int) FNSUPTRUSTEDMAIN(int argc, char **argv, char **envp);
663/** Pointer to FNSUPTRUSTEDMAIN(). */
664typedef FNSUPTRUSTEDMAIN *PFNSUPTRUSTEDMAIN;
665
666/** Which operation failed. */
667typedef enum SUPINITOP
668{
669 /** Invalid. */
670 kSupInitOp_Invalid = 0,
671 /** Installation integrity error. */
672 kSupInitOp_Integrity,
673 /** Setuid related. */
674 kSupInitOp_RootCheck,
675 /** Driver related. */
676 kSupInitOp_Driver,
677 /** IPRT init related. */
678 kSupInitOp_IPRT,
679 /** Place holder. */
680 kSupInitOp_End
681} SUPINITOP;
682
683/**
684 * Trusted error entry point, optional.
685 *
686 * This is exported as "TrustedError" by the dynamic libraries which contains
687 * the "real" application binary for which the hardened stub is built.
688 *
689 * @param pszWhere Where the error occurred (function name).
690 * @param enmWhat Which operation went wrong.
691 * @param rc The status code.
692 * @param pszMsgFmt Error message format string.
693 * @param va The message format arguments.
694 */
695typedef DECLCALLBACK(void) FNSUPTRUSTEDERROR(const char *pszWhere, SUPINITOP enmWhat, int rc, const char *pszMsgFmt, va_list va);
696/** Pointer to FNSUPTRUSTEDERROR. */
697typedef FNSUPTRUSTEDERROR *PFNSUPTRUSTEDERROR;
698
699/**
700 * Secure main.
701 *
702 * This is used for the set-user-ID-on-execute binaries on unixy systems
703 * and when using the open-vboxdrv-via-root-service setup on Windows.
704 *
705 * This function will perform the integrity checks of the VirtualBox
706 * installation, open the support driver, open the root service (later),
707 * and load the DLL corresponding to \a pszProgName and execute its main
708 * function.
709 *
710 * @returns Return code appropriate for main().
711 *
712 * @param pszProgName The program name. This will be used to figure out which
713 * DLL/SO/DYLIB to load and execute.
714 * @param fFlags Flags.
715 * @param argc The argument count.
716 * @param argv The argument vector.
717 * @param envp The environment vector.
718 */
719DECLHIDDEN(int) SUPR3HardenedMain(const char *pszProgName, uint32_t fFlags, int argc, char **argv, char **envp);
720
721/** @name SUPR3SecureMain flags.
722 * @{ */
723/** Don't open the device. (Intended for VirtualBox without -startvm.) */
724#define SUPSECMAIN_FLAGS_DONT_OPEN_DEV RT_BIT_32(0)
725/** @} */
726
727/**
728 * Initializes the support library.
729 * Each successful call to SUPR3Init() must be countered by a
730 * call to SUPR3Term(false).
731 *
732 * @returns VBox status code.
733 * @param ppSession Where to store the session handle. Defaults to NULL.
734 */
735SUPR3DECL(int) SUPR3Init(PSUPDRVSESSION *ppSession);
736
737/**
738 * Terminates the support library.
739 *
740 * @returns VBox status code.
741 * @param fForced Forced termination. This means to ignore the
742 * init call count and just terminated.
743 */
744#ifdef __cplusplus
745SUPR3DECL(int) SUPR3Term(bool fForced = false);
746#else
747SUPR3DECL(int) SUPR3Term(int fForced);
748#endif
749
750/**
751 * Sets the ring-0 VM handle for use with fast IOCtls.
752 *
753 * @returns VBox status code.
754 * @param pVMR0 The ring-0 VM handle.
755 * NIL_RTR0PTR can be used to unset the handle when the
756 * VM is about to be destroyed.
757 */
758SUPR3DECL(int) SUPR3SetVMForFastIOCtl(PVMR0 pVMR0);
759
760/**
761 * Calls the HC R0 VMM entry point.
762 * See VMMR0Entry() for more details.
763 *
764 * @returns error code specific to uFunction.
765 * @param pVMR0 Pointer to the Ring-0 (Host Context) mapping of the VM structure.
766 * @param idCpu The virtual CPU ID.
767 * @param uOperation Operation to execute.
768 * @param pvArg Argument.
769 */
770SUPR3DECL(int) SUPR3CallVMMR0(PVMR0 pVMR0, VMCPUID idCpu, unsigned uOperation, void *pvArg);
771
772/**
773 * Variant of SUPR3CallVMMR0, except that this takes the fast ioclt path
774 * regardsless of compile-time defaults.
775 *
776 * @returns VBox status code.
777 * @param pVMR0 The ring-0 VM handle.
778 * @param uOperation The operation; only the SUP_VMMR0_DO_* ones are valid.
779 * @param idCpu The virtual CPU ID.
780 */
781SUPR3DECL(int) SUPR3CallVMMR0Fast(PVMR0 pVMR0, unsigned uOperation, VMCPUID idCpu);
782
783/**
784 * Calls the HC R0 VMM entry point, in a safer but slower manner than
785 * SUPR3CallVMMR0. When entering using this call the R0 components can call
786 * into the host kernel (i.e. use the SUPR0 and RT APIs).
787 *
788 * See VMMR0Entry() for more details.
789 *
790 * @returns error code specific to uFunction.
791 * @param pVMR0 Pointer to the Ring-0 (Host Context) mapping of the VM structure.
792 * @param idCpu The virtual CPU ID.
793 * @param uOperation Operation to execute.
794 * @param u64Arg Constant argument.
795 * @param pReqHdr Pointer to a request header. Optional.
796 * This will be copied in and out of kernel space. There currently is a size
797 * limit on this, just below 4KB.
798 */
799SUPR3DECL(int) SUPR3CallVMMR0Ex(PVMR0 pVMR0, VMCPUID idCpu, unsigned uOperation, uint64_t u64Arg, PSUPVMMR0REQHDR pReqHdr);
800
801/**
802 * Calls a ring-0 service.
803 *
804 * The operation and the request packet is specific to the service.
805 *
806 * @returns error code specific to uFunction.
807 * @param pszService The service name.
808 * @param cchService The length of the service name.
809 * @param uReq The request number.
810 * @param u64Arg Constant argument.
811 * @param pReqHdr Pointer to a request header. Optional.
812 * This will be copied in and out of kernel space. There currently is a size
813 * limit on this, just below 4KB.
814 */
815SUPR3DECL(int) SUPR3CallR0Service(const char *pszService, size_t cchService, uint32_t uOperation, uint64_t u64Arg, PSUPR0SERVICEREQHDR pReqHdr);
816
817/** Which logger. */
818typedef enum SUPLOGGER
819{
820 SUPLOGGER_DEBUG = 1,
821 SUPLOGGER_RELEASE
822} SUPLOGGER;
823
824/**
825 * Changes the settings of the specified ring-0 logger.
826 *
827 * @returns VBox status code.
828 * @param enmWhich Which logger.
829 * @param pszFlags The flags settings.
830 * @param pszGroups The groups settings.
831 * @param pszDest The destination specificier.
832 */
833SUPR3DECL(int) SUPR3LoggerSettings(SUPLOGGER enmWhich, const char *pszFlags, const char *pszGroups, const char *pszDest);
834
835/**
836 * Creates a ring-0 logger instance.
837 *
838 * @returns VBox status code.
839 * @param enmWhich Which logger to create.
840 * @param pszFlags The flags settings.
841 * @param pszGroups The groups settings.
842 * @param pszDest The destination specificier.
843 */
844SUPR3DECL(int) SUPR3LoggerCreate(SUPLOGGER enmWhich, const char *pszFlags, const char *pszGroups, const char *pszDest);
845
846/**
847 * Destroys a ring-0 logger instance.
848 *
849 * @returns VBox status code.
850 * @param enmWhich Which logger.
851 */
852SUPR3DECL(int) SUPR3LoggerDestroy(SUPLOGGER enmWhich);
853
854/**
855 * Queries the paging mode of the host OS.
856 *
857 * @returns The paging mode.
858 */
859SUPR3DECL(SUPPAGINGMODE) SUPR3GetPagingMode(void);
860
861/**
862 * Allocate zero-filled pages.
863 *
864 * Use this to allocate a number of pages suitable for seeding / locking.
865 * Call SUPR3PageFree() to free the pages once done with them.
866 *
867 * @returns VBox status.
868 * @param cPages Number of pages to allocate.
869 * @param ppvPages Where to store the base pointer to the allocated pages.
870 */
871SUPR3DECL(int) SUPR3PageAlloc(size_t cPages, void **ppvPages);
872
873/**
874 * Frees pages allocated with SUPR3PageAlloc().
875 *
876 * @returns VBox status.
877 * @param pvPages Pointer returned by SUPR3PageAlloc().
878 * @param cPages Number of pages that was allocated.
879 */
880SUPR3DECL(int) SUPR3PageFree(void *pvPages, size_t cPages);
881
882/**
883 * Allocate non-zeroed, locked, pages with user and, optionally, kernel
884 * mappings.
885 *
886 * Use SUPR3PageFreeEx() to free memory allocated with this function.
887 *
888 * @returns VBox status code.
889 * @param cPages The number of pages to allocate.
890 * @param fFlags Flags, reserved. Must be zero.
891 * @param ppvPages Where to store the address of the user mapping.
892 * @param pR0Ptr Where to store the address of the kernel mapping.
893 * NULL if no kernel mapping is desired.
894 * @param paPages Where to store the physical addresses of each page.
895 * Optional.
896 */
897SUPR3DECL(int) SUPR3PageAllocEx(size_t cPages, uint32_t fFlags, void **ppvPages, PRTR0PTR pR0Ptr, PSUPPAGE paPages);
898
899/**
900 * Maps a portion of a ring-3 only allocation into kernel space.
901 *
902 * @returns VBox status code.
903 *
904 * @param pvR3 The address SUPR3PageAllocEx return.
905 * @param off Offset to start mapping at. Must be page aligned.
906 * @param cb Number of bytes to map. Must be page aligned.
907 * @param fFlags Flags, must be zero.
908 * @param pR0Ptr Where to store the address on success.
909 *
910 */
911SUPR3DECL(int) SUPR3PageMapKernel(void *pvR3, uint32_t off, uint32_t cb, uint32_t fFlags, PRTR0PTR pR0Ptr);
912
913/**
914 * Changes the protection of
915 *
916 * @returns VBox status code.
917 * @retval VERR_NOT_SUPPORTED if the OS doesn't allow us to change page level
918 * protection. See also RTR0MemObjProtect.
919 *
920 * @param pvR3 The ring-3 address SUPR3PageAllocEx returned.
921 * @param R0Ptr The ring-0 address SUPR3PageAllocEx returned if it
922 * is desired that the corresponding ring-0 page
923 * mappings should change protection as well. Pass
924 * NIL_RTR0PTR if the ring-0 pages should remain
925 * unaffected.
926 * @param off Offset to start at which to start chagning the page
927 * level protection. Must be page aligned.
928 * @param cb Number of bytes to change. Must be page aligned.
929 * @param fProt The new page level protection, either a combination
930 * of RTMEM_PROT_READ, RTMEM_PROT_WRITE and
931 * RTMEM_PROT_EXEC, or just RTMEM_PROT_NONE.
932 */
933SUPR3DECL(int) SUPR3PageProtect(void *pvR3, RTR0PTR R0Ptr, uint32_t off, uint32_t cb, uint32_t fProt);
934
935/**
936 * Free pages allocated by SUPR3PageAllocEx.
937 *
938 * @returns VBox status code.
939 * @param pvPages The address of the user mapping.
940 * @param cPages The number of pages.
941 */
942SUPR3DECL(int) SUPR3PageFreeEx(void *pvPages, size_t cPages);
943
944/**
945 * Allocated memory with page aligned memory with a contiguous and locked physical
946 * memory backing below 4GB.
947 *
948 * @returns Pointer to the allocated memory (virtual address).
949 * *pHCPhys is set to the physical address of the memory.
950 * If ppvR0 isn't NULL, *ppvR0 is set to the ring-0 mapping.
951 * The returned memory must be freed using SUPR3ContFree().
952 * @returns NULL on failure.
953 * @param cPages Number of pages to allocate.
954 * @param pR0Ptr Where to store the ring-0 mapping of the allocation. (optional)
955 * @param pHCPhys Where to store the physical address of the memory block.
956 *
957 * @remark This 2nd version of this API exists because we're not able to map the
958 * ring-3 mapping executable on WIN64. This is a serious problem in regard to
959 * the world switchers.
960 */
961SUPR3DECL(void *) SUPR3ContAlloc(size_t cPages, PRTR0PTR pR0Ptr, PRTHCPHYS pHCPhys);
962
963/**
964 * Frees memory allocated with SUPR3ContAlloc().
965 *
966 * @returns VBox status code.
967 * @param pv Pointer to the memory block which should be freed.
968 * @param cPages Number of pages to be freed.
969 */
970SUPR3DECL(int) SUPR3ContFree(void *pv, size_t cPages);
971
972/**
973 * Allocated non contiguous physical memory below 4GB.
974 *
975 * The memory isn't zeroed.
976 *
977 * @returns VBox status code.
978 * @returns NULL on failure.
979 * @param cPages Number of pages to allocate.
980 * @param ppvPages Where to store the pointer to the allocated memory.
981 * The pointer stored here on success must be passed to
982 * SUPR3LowFree when the memory should be released.
983 * @param ppvPagesR0 Where to store the ring-0 pointer to the allocated memory. optional.
984 * @param paPages Where to store the physical addresses of the individual pages.
985 */
986SUPR3DECL(int) SUPR3LowAlloc(size_t cPages, void **ppvPages, PRTR0PTR ppvPagesR0, PSUPPAGE paPages);
987
988/**
989 * Frees memory allocated with SUPR3LowAlloc().
990 *
991 * @returns VBox status code.
992 * @param pv Pointer to the memory block which should be freed.
993 * @param cPages Number of pages that was allocated.
994 */
995SUPR3DECL(int) SUPR3LowFree(void *pv, size_t cPages);
996
997/**
998 * Load a module into R0 HC.
999 *
1000 * This will verify the file integrity in a similar manner as
1001 * SUPR3HardenedVerifyFile before loading it.
1002 *
1003 * @returns VBox status code.
1004 * @param pszFilename The path to the image file.
1005 * @param pszModule The module name. Max 32 bytes.
1006 * @param ppvImageBase Where to store the image address.
1007 * @param pErrInfo Where to return extended error information.
1008 * Optional.
1009 */
1010SUPR3DECL(int) SUPR3LoadModule(const char *pszFilename, const char *pszModule, void **ppvImageBase, PRTERRINFO pErrInfo);
1011
1012/**
1013 * Load a module into R0 HC.
1014 *
1015 * This will verify the file integrity in a similar manner as
1016 * SUPR3HardenedVerifyFile before loading it.
1017 *
1018 * @returns VBox status code.
1019 * @param pszFilename The path to the image file.
1020 * @param pszModule The module name. Max 32 bytes.
1021 * @param pszSrvReqHandler The name of the service request handler entry
1022 * point. See FNSUPR0SERVICEREQHANDLER.
1023 * @param ppvImageBase Where to store the image address.
1024 */
1025SUPR3DECL(int) SUPR3LoadServiceModule(const char *pszFilename, const char *pszModule,
1026 const char *pszSrvReqHandler, void **ppvImageBase);
1027
1028/**
1029 * Frees a R0 HC module.
1030 *
1031 * @returns VBox status code.
1032 * @param pszModule The module to free.
1033 * @remark This will not actually 'free' the module, there are of course usage counting.
1034 */
1035SUPR3DECL(int) SUPR3FreeModule(void *pvImageBase);
1036
1037/**
1038 * Get the address of a symbol in a ring-0 module.
1039 *
1040 * @returns VBox status code.
1041 * @param pszModule The module name.
1042 * @param pszSymbol Symbol name. If it's value is less than 64k it's treated like a
1043 * ordinal value rather than a string pointer.
1044 * @param ppvValue Where to store the symbol value.
1045 */
1046SUPR3DECL(int) SUPR3GetSymbolR0(void *pvImageBase, const char *pszSymbol, void **ppvValue);
1047
1048/**
1049 * Load R0 HC VMM code.
1050 *
1051 * @returns VBox status code.
1052 * @deprecated Use SUPR3LoadModule(pszFilename, "VMMR0.r0", &pvImageBase)
1053 */
1054SUPR3DECL(int) SUPR3LoadVMM(const char *pszFilename);
1055
1056/**
1057 * Unloads R0 HC VMM code.
1058 *
1059 * @returns VBox status code.
1060 * @deprecated Use SUPR3FreeModule().
1061 */
1062SUPR3DECL(int) SUPR3UnloadVMM(void);
1063
1064/**
1065 * Get the physical address of the GIP.
1066 *
1067 * @returns VBox status code.
1068 * @param pHCPhys Where to store the physical address of the GIP.
1069 */
1070SUPR3DECL(int) SUPR3GipGetPhys(PRTHCPHYS pHCPhys);
1071
1072/**
1073 * Verifies the integrity of a file, and optionally opens it.
1074 *
1075 * The integrity check is for whether the file is suitable for loading into
1076 * the hypervisor or VM process. The integrity check may include verifying
1077 * the authenticode/elfsign/whatever signature of the file, which can take
1078 * a little while.
1079 *
1080 * @returns VBox status code. On failure it will have printed a LogRel message.
1081 *
1082 * @param pszFilename The file.
1083 * @param pszWhat For the LogRel on failure.
1084 * @param phFile Where to store the handle to the opened file. This is optional, pass NULL
1085 * if the file should not be opened.
1086 * @deprecated Write a new one.
1087 */
1088SUPR3DECL(int) SUPR3HardenedVerifyFile(const char *pszFilename, const char *pszWhat, PRTFILE phFile);
1089
1090/**
1091 * Verifies the integrity of a the current process, including the image
1092 * location and that the invocation was absolute.
1093 *
1094 * This must currently be called after initializing the runtime. The intended
1095 * audience is set-uid-to-root applications, root services and similar.
1096 *
1097 * @returns VBox status code. On failure
1098 * message.
1099 * @param pszArgv0 The first argument to main().
1100 * @param fInternal Set this to @c true if this is an internal
1101 * VirtualBox application. Otherwise pass @c false.
1102 * @param pErrInfo Where to return extended error information.
1103 */
1104SUPR3DECL(int) SUPR3HardenedVerifySelf(const char *pszArgv0, bool fInternal, PRTERRINFO pErrInfo);
1105
1106/**
1107 * Verifies the integrity of an installation directory.
1108 *
1109 * The integrity check verifies that the directory cannot be tampered with by
1110 * normal users on the system. On Unix this translates to root ownership and
1111 * no symbolic linking.
1112 *
1113 * @returns VBox status code. On failure a message will be stored in @a pszErr.
1114 *
1115 * @param pszDirPath The directory path.
1116 * @param fRecursive Whether the check should be recursive or
1117 * not. When set, all sub-directores will be checked,
1118 * including files (@a fCheckFiles is ignored).
1119 * @param fCheckFiles Whether to apply the same basic integrity check to
1120 * the files in the directory as the directory itself.
1121 * @param pErrInfo Where to return extended error information.
1122 * Optional.
1123 */
1124SUPR3DECL(int) SUPR3HardenedVerifyDir(const char *pszDirPath, bool fRecursive, bool fCheckFiles, PRTERRINFO pErrInfo);
1125
1126/**
1127 * Verifies the integrity of a plug-in module.
1128 *
1129 * This is similar to SUPR3HardenedLdrLoad, except it does not load the module
1130 * and that the module does not have to be shipped with VirtualBox.
1131 *
1132 * @returns VBox status code. On failure a message will be stored in @a pszErr.
1133 *
1134 * @param pszFilename The filename of the plug-in module (nothing can be
1135 * omitted here).
1136 * @param pErrInfo Where to return extended error information.
1137 * Optional.
1138 */
1139SUPR3DECL(int) SUPR3HardenedVerifyPlugIn(const char *pszFilename, PRTERRINFO pErrInfo);
1140
1141/**
1142 * Same as RTLdrLoad() but will verify the files it loads (hardened builds).
1143 *
1144 * Will add dll suffix if missing and try load the file.
1145 *
1146 * @returns iprt status code.
1147 * @param pszFilename Image filename. This must have a path.
1148 * @param phLdrMod Where to store the handle to the loaded module.
1149 * @param fFlags See RTLDRLOAD_FLAGS_XXX.
1150 * @param pErrInfo Where to return extended error information.
1151 * Optional.
1152 */
1153SUPR3DECL(int) SUPR3HardenedLdrLoad(const char *pszFilename, PRTLDRMOD phLdrMod, uint32_t fFlags, PRTERRINFO pErrInfo);
1154
1155/**
1156 * Same as RTLdrLoadAppPriv() but it will verify the files it loads (hardened
1157 * builds).
1158 *
1159 * Will add dll suffix to the file if missing, then look for it in the
1160 * architecture dependent application directory.
1161 *
1162 * @returns iprt status code.
1163 * @param pszFilename Image filename.
1164 * @param phLdrMod Where to store the handle to the loaded module.
1165 * @param fFlags See RTLDRLOAD_FLAGS_XXX.
1166 * @param pErrInfo Where to return extended error information.
1167 * Optional.
1168 */
1169SUPR3DECL(int) SUPR3HardenedLdrLoadAppPriv(const char *pszFilename, PRTLDRMOD phLdrMod, uint32_t fFlags, PRTERRINFO pErrInfo);
1170
1171/**
1172 * Same as RTLdrLoad() but will verify the files it loads (hardened builds).
1173 *
1174 * This differs from SUPR3HardenedLdrLoad() in that it can load modules from
1175 * extension packs and anything else safely installed on the system, provided
1176 * they pass the hardening tests.
1177 *
1178 * @returns iprt status code.
1179 * @param pszFilename The full path to the module, with extension.
1180 * @param phLdrMod Where to store the handle to the loaded module.
1181 * @param pErrInfo Where to return extended error information.
1182 * Optional.
1183 */
1184SUPR3DECL(int) SUPR3HardenedLdrLoadPlugIn(const char *pszFilename, PRTLDRMOD phLdrMod, PRTERRINFO pErrInfo);
1185
1186/**
1187 * Check if the host kernel can run in VMX root mode.
1188 *
1189 * @returns VINF_SUCCESS if supported, error code indicating why if not.
1190 */
1191SUPR3DECL(int) SUPR3QueryVTxSupported(void);
1192
1193/**
1194 * Return VT-x/AMD-V capabilities.
1195 *
1196 * @returns VINF_SUCCESS if supported, error code indicating why if not.
1197 * @param pfCaps Pointer to capability dword (out).
1198 * @todo Intended for main, which means we need to relax the privilege requires
1199 * when accessing certain vboxdrv functions.
1200 */
1201SUPR3DECL(int) SUPR3QueryVTCaps(uint32_t *pfCaps);
1202
1203/** @} */
1204#endif /* IN_RING3 */
1205
1206
1207#ifdef IN_RING0
1208/** @defgroup grp_sup_r0 SUP Host Context Ring-0 API
1209 * @ingroup grp_sup
1210 * @{
1211 */
1212
1213/**
1214 * Security objectype.
1215 */
1216typedef enum SUPDRVOBJTYPE
1217{
1218 /** The usual invalid object. */
1219 SUPDRVOBJTYPE_INVALID = 0,
1220 /** A Virtual Machine instance. */
1221 SUPDRVOBJTYPE_VM,
1222 /** Internal network. */
1223 SUPDRVOBJTYPE_INTERNAL_NETWORK,
1224 /** Internal network interface. */
1225 SUPDRVOBJTYPE_INTERNAL_NETWORK_INTERFACE,
1226 /** Single release event semaphore. */
1227 SUPDRVOBJTYPE_SEM_EVENT,
1228 /** Multiple release event semaphore. */
1229 SUPDRVOBJTYPE_SEM_EVENT_MULTI,
1230 /** Raw PCI device. */
1231 SUPDRVOBJTYPE_RAW_PCI_DEVICE,
1232 /** The first invalid object type in this end. */
1233 SUPDRVOBJTYPE_END,
1234 /** The usual 32-bit type size hack. */
1235 SUPDRVOBJTYPE_32_BIT_HACK = 0x7ffffff
1236} SUPDRVOBJTYPE;
1237
1238/**
1239 * Object destructor callback.
1240 * This is called for reference counted objectes when the count reaches 0.
1241 *
1242 * @param pvObj The object pointer.
1243 * @param pvUser1 The first user argument.
1244 * @param pvUser2 The second user argument.
1245 */
1246typedef DECLCALLBACK(void) FNSUPDRVDESTRUCTOR(void *pvObj, void *pvUser1, void *pvUser2);
1247/** Pointer to a FNSUPDRVDESTRUCTOR(). */
1248typedef FNSUPDRVDESTRUCTOR *PFNSUPDRVDESTRUCTOR;
1249
1250SUPR0DECL(void *) SUPR0ObjRegister(PSUPDRVSESSION pSession, SUPDRVOBJTYPE enmType, PFNSUPDRVDESTRUCTOR pfnDestructor, void *pvUser1, void *pvUser2);
1251SUPR0DECL(int) SUPR0ObjAddRef(void *pvObj, PSUPDRVSESSION pSession);
1252SUPR0DECL(int) SUPR0ObjAddRefEx(void *pvObj, PSUPDRVSESSION pSession, bool fNoBlocking);
1253SUPR0DECL(int) SUPR0ObjRelease(void *pvObj, PSUPDRVSESSION pSession);
1254SUPR0DECL(int) SUPR0ObjVerifyAccess(void *pvObj, PSUPDRVSESSION pSession, const char *pszObjName);
1255
1256SUPR0DECL(int) SUPR0LockMem(PSUPDRVSESSION pSession, RTR3PTR pvR3, uint32_t cPages, PRTHCPHYS paPages);
1257SUPR0DECL(int) SUPR0UnlockMem(PSUPDRVSESSION pSession, RTR3PTR pvR3);
1258SUPR0DECL(int) SUPR0ContAlloc(PSUPDRVSESSION pSession, uint32_t cPages, PRTR0PTR ppvR0, PRTR3PTR ppvR3, PRTHCPHYS pHCPhys);
1259SUPR0DECL(int) SUPR0ContFree(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr);
1260SUPR0DECL(int) SUPR0LowAlloc(PSUPDRVSESSION pSession, uint32_t cPages, PRTR0PTR ppvR0, PRTR3PTR ppvR3, PRTHCPHYS paPages);
1261SUPR0DECL(int) SUPR0LowFree(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr);
1262SUPR0DECL(int) SUPR0MemAlloc(PSUPDRVSESSION pSession, uint32_t cb, PRTR0PTR ppvR0, PRTR3PTR ppvR3);
1263SUPR0DECL(int) SUPR0MemGetPhys(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr, PSUPPAGE paPages);
1264SUPR0DECL(int) SUPR0MemFree(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr);
1265SUPR0DECL(int) SUPR0PageAllocEx(PSUPDRVSESSION pSession, uint32_t cPages, uint32_t fFlags, PRTR3PTR ppvR3, PRTR0PTR ppvR0, PRTHCPHYS paPages);
1266SUPR0DECL(int) SUPR0PageMapKernel(PSUPDRVSESSION pSession, RTR3PTR pvR3, uint32_t offSub, uint32_t cbSub, uint32_t fFlags, PRTR0PTR ppvR0);
1267SUPR0DECL(int) SUPR0PageProtect(PSUPDRVSESSION pSession, RTR3PTR pvR3, RTR0PTR pvR0, uint32_t offSub, uint32_t cbSub, uint32_t fProt);
1268SUPR0DECL(int) SUPR0PageFree(PSUPDRVSESSION pSession, RTR3PTR pvR3);
1269SUPR0DECL(int) SUPR0GipMap(PSUPDRVSESSION pSession, PRTR3PTR ppGipR3, PRTHCPHYS pHCPhysGip);
1270SUPR0DECL(int) SUPR0QueryVTCaps(PSUPDRVSESSION pSession, uint32_t *pfCaps);
1271SUPR0DECL(int) SUPR0GipUnmap(PSUPDRVSESSION pSession);
1272SUPR0DECL(int) SUPR0Printf(const char *pszFormat, ...);
1273SUPR0DECL(SUPPAGINGMODE) SUPR0GetPagingMode(void);
1274SUPR0DECL(int) SUPR0EnableVTx(bool fEnable);
1275
1276/** @name Absolute symbols
1277 * Take the address of these, don't try call them.
1278 * @{ */
1279SUPR0DECL(void) SUPR0AbsIs64bit(void);
1280SUPR0DECL(void) SUPR0Abs64bitKernelCS(void);
1281SUPR0DECL(void) SUPR0Abs64bitKernelSS(void);
1282SUPR0DECL(void) SUPR0Abs64bitKernelDS(void);
1283SUPR0DECL(void) SUPR0AbsKernelCS(void);
1284SUPR0DECL(void) SUPR0AbsKernelSS(void);
1285SUPR0DECL(void) SUPR0AbsKernelDS(void);
1286SUPR0DECL(void) SUPR0AbsKernelES(void);
1287SUPR0DECL(void) SUPR0AbsKernelFS(void);
1288SUPR0DECL(void) SUPR0AbsKernelGS(void);
1289/** @} */
1290
1291/**
1292 * Support driver component factory.
1293 *
1294 * Component factories are registered by drivers that provides services
1295 * such as the host network interface filtering and access to the host
1296 * TCP/IP stack.
1297 *
1298 * @remark Module dependencies and making sure that a component doesn't
1299 * get unloaded while in use, is the sole responsibility of the
1300 * driver/kext/whatever implementing the component.
1301 */
1302typedef struct SUPDRVFACTORY
1303{
1304 /** The (unique) name of the component factory. */
1305 char szName[56];
1306 /**
1307 * Queries a factory interface.
1308 *
1309 * The factory interface is specific to each component and will be be
1310 * found in the header(s) for the component alongside its UUID.
1311 *
1312 * @returns Pointer to the factory interfaces on success, NULL on failure.
1313 *
1314 * @param pSupDrvFactory Pointer to this structure.
1315 * @param pSession The SUPDRV session making the query.
1316 * @param pszInterfaceUuid The UUID of the factory interface.
1317 */
1318 DECLR0CALLBACKMEMBER(void *, pfnQueryFactoryInterface,(struct SUPDRVFACTORY const *pSupDrvFactory, PSUPDRVSESSION pSession, const char *pszInterfaceUuid));
1319} SUPDRVFACTORY;
1320/** Pointer to a support driver factory. */
1321typedef SUPDRVFACTORY *PSUPDRVFACTORY;
1322/** Pointer to a const support driver factory. */
1323typedef SUPDRVFACTORY const *PCSUPDRVFACTORY;
1324
1325SUPR0DECL(int) SUPR0ComponentRegisterFactory(PSUPDRVSESSION pSession, PCSUPDRVFACTORY pFactory);
1326SUPR0DECL(int) SUPR0ComponentDeregisterFactory(PSUPDRVSESSION pSession, PCSUPDRVFACTORY pFactory);
1327SUPR0DECL(int) SUPR0ComponentQueryFactory(PSUPDRVSESSION pSession, const char *pszName, const char *pszInterfaceUuid, void **ppvFactoryIf);
1328
1329
1330/**
1331 * Service request callback function.
1332 *
1333 * @returns VBox status code.
1334 * @param pSession The caller's session.
1335 * @param u64Arg 64-bit integer argument.
1336 * @param pReqHdr The request header. Input / Output. Optional.
1337 */
1338typedef DECLCALLBACK(int) FNSUPR0SERVICEREQHANDLER(PSUPDRVSESSION pSession, uint32_t uOperation,
1339 uint64_t u64Arg, PSUPR0SERVICEREQHDR pReqHdr);
1340/** Pointer to a FNR0SERVICEREQHANDLER(). */
1341typedef R0PTRTYPE(FNSUPR0SERVICEREQHANDLER *) PFNSUPR0SERVICEREQHANDLER;
1342
1343
1344/** @defgroup grp_sup_r0_idc The IDC Interface
1345 * @ingroup grp_sup_r0
1346 * @{
1347 */
1348
1349/** The current SUPDRV IDC version.
1350 * This follows the usual high word / low word rules, i.e. high word is the
1351 * major number and it signifies incompatible interface changes. */
1352#define SUPDRV_IDC_VERSION UINT32_C(0x00010000)
1353
1354/**
1355 * Inter-Driver Communication Handle.
1356 */
1357typedef union SUPDRVIDCHANDLE
1358{
1359 /** Padding for opaque usage.
1360 * Must be greater or equal in size than the private struct. */
1361 void *apvPadding[4];
1362#ifdef SUPDRVIDCHANDLEPRIVATE_DECLARED
1363 /** The private view. */
1364 struct SUPDRVIDCHANDLEPRIVATE s;
1365#endif
1366} SUPDRVIDCHANDLE;
1367/** Pointer to a handle. */
1368typedef SUPDRVIDCHANDLE *PSUPDRVIDCHANDLE;
1369
1370SUPR0DECL(int) SUPR0IdcOpen(PSUPDRVIDCHANDLE pHandle, uint32_t uReqVersion, uint32_t uMinVersion,
1371 uint32_t *puSessionVersion, uint32_t *puDriverVersion, uint32_t *puDriverRevision);
1372SUPR0DECL(int) SUPR0IdcCall(PSUPDRVIDCHANDLE pHandle, uint32_t iReq, void *pvReq, uint32_t cbReq);
1373SUPR0DECL(int) SUPR0IdcClose(PSUPDRVIDCHANDLE pHandle);
1374SUPR0DECL(PSUPDRVSESSION) SUPR0IdcGetSession(PSUPDRVIDCHANDLE pHandle);
1375SUPR0DECL(int) SUPR0IdcComponentRegisterFactory(PSUPDRVIDCHANDLE pHandle, PCSUPDRVFACTORY pFactory);
1376SUPR0DECL(int) SUPR0IdcComponentDeregisterFactory(PSUPDRVIDCHANDLE pHandle, PCSUPDRVFACTORY pFactory);
1377
1378/** @} */
1379
1380/** @} */
1381#endif
1382
1383/** @} */
1384
1385RT_C_DECLS_END
1386
1387#endif
1388
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