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 |
|
---|
39 | RT_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. */
|
---|
49 | typedef 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. */
|
---|
58 | typedef SUPPAGE *PSUPPAGE;
|
---|
59 | /** Pointer to a const page descriptor. */
|
---|
60 | typedef const SUPPAGE *PCSUPPAGE;
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * The paging mode.
|
---|
64 | *
|
---|
65 | * @remarks Users are making assumptions about the order here!
|
---|
66 | */
|
---|
67 | typedef 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 | */
|
---|
101 | typedef 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 | /** The interval between the last two NanoTS updates. (experiment for now) */
|
---|
131 | volatile uint32_t u32PrevUpdateIntervalNS;
|
---|
132 | /** Reserved for future per processor data. */
|
---|
133 | volatile uint32_t au32Reserved[5];
|
---|
134 | } SUPGIPCPU;
|
---|
135 | AssertCompileSize(SUPGIPCPU, 96);
|
---|
136 | /*AssertCompileMemberAlignment(SUPGIPCPU, u64TSC, 8); -fixme */
|
---|
137 |
|
---|
138 | /** Pointer to per cpu data.
|
---|
139 | * @remark there is no const version of this typedef, see g_pSUPGlobalInfoPage for details. */
|
---|
140 | typedef SUPGIPCPU *PSUPGIPCPU;
|
---|
141 |
|
---|
142 | /**
|
---|
143 | * Global Information Page.
|
---|
144 | *
|
---|
145 | * This page contains useful information and can be mapped into any
|
---|
146 | * process or VM. It can be accessed thru the g_pSUPGlobalInfoPage
|
---|
147 | * pointer when a session is open.
|
---|
148 | */
|
---|
149 | typedef struct SUPGLOBALINFOPAGE
|
---|
150 | {
|
---|
151 | /** Magic (SUPGLOBALINFOPAGE_MAGIC). */
|
---|
152 | uint32_t u32Magic;
|
---|
153 | /** The GIP version. */
|
---|
154 | uint32_t u32Version;
|
---|
155 |
|
---|
156 | /** The GIP update mode, see SUPGIPMODE. */
|
---|
157 | uint32_t u32Mode;
|
---|
158 | /** Reserved / padding. */
|
---|
159 | uint32_t u32Padding0;
|
---|
160 | /** The update frequency of the of the NanoTS. */
|
---|
161 | volatile uint32_t u32UpdateHz;
|
---|
162 | /** The update interval in nanoseconds. (10^9 / u32UpdateHz) */
|
---|
163 | volatile uint32_t u32UpdateIntervalNS;
|
---|
164 | /** The timestamp of the last time we update the update frequency. */
|
---|
165 | volatile uint64_t u64NanoTSLastUpdateHz;
|
---|
166 |
|
---|
167 | /** Padding / reserved space for future data. */
|
---|
168 | uint32_t au32Padding1[56];
|
---|
169 |
|
---|
170 | /** Array of per-cpu data.
|
---|
171 | * If u32Mode == SUPGIPMODE_SYNC_TSC then only the first entry is used.
|
---|
172 | * If u32Mode == SUPGIPMODE_ASYNC_TSC then the CPU ACPI ID is used as an
|
---|
173 | * index into the array. */
|
---|
174 | SUPGIPCPU aCPUs[32];
|
---|
175 | } SUPGLOBALINFOPAGE;
|
---|
176 | AssertCompile(sizeof(SUPGLOBALINFOPAGE) <= 0x1000);
|
---|
177 | /* AssertCompileMemberAlignment(SUPGLOBALINFOPAGE, aCPU, 32); - fixme */
|
---|
178 |
|
---|
179 | /** Pointer to the global info page.
|
---|
180 | * @remark there is no const version of this typedef, see g_pSUPGlobalInfoPage for details. */
|
---|
181 | typedef SUPGLOBALINFOPAGE *PSUPGLOBALINFOPAGE;
|
---|
182 |
|
---|
183 | #pragma pack() /* end of paranoia */
|
---|
184 |
|
---|
185 | /** The value of the SUPGLOBALINFOPAGE::u32Magic field. (Soryo Fuyumi) */
|
---|
186 | #define SUPGLOBALINFOPAGE_MAGIC 0x19590106
|
---|
187 | /** The GIP version.
|
---|
188 | * Upper 16 bits is the major version. Major version is only changed with
|
---|
189 | * incompatible changes in the GIP. */
|
---|
190 | #define SUPGLOBALINFOPAGE_VERSION 0x00020000
|
---|
191 |
|
---|
192 | /**
|
---|
193 | * SUPGLOBALINFOPAGE::u32Mode values.
|
---|
194 | */
|
---|
195 | typedef enum SUPGIPMODE
|
---|
196 | {
|
---|
197 | /** The usual invalid null entry. */
|
---|
198 | SUPGIPMODE_INVALID = 0,
|
---|
199 | /** The TSC of the cores and cpus in the system is in sync. */
|
---|
200 | SUPGIPMODE_SYNC_TSC,
|
---|
201 | /** Each core has it's own TSC. */
|
---|
202 | SUPGIPMODE_ASYNC_TSC,
|
---|
203 | /** The usual 32-bit hack. */
|
---|
204 | SUPGIPMODE_32BIT_HACK = 0x7fffffff
|
---|
205 | } SUPGIPMODE;
|
---|
206 |
|
---|
207 | /** Pointer to the Global Information Page.
|
---|
208 | *
|
---|
209 | * This pointer is valid as long as SUPLib has a open session. Anyone using
|
---|
210 | * the page must treat this pointer as higly volatile and not trust it beyond
|
---|
211 | * one transaction.
|
---|
212 | *
|
---|
213 | * @remark The GIP page is read-only to everyone but the support driver and
|
---|
214 | * is actually mapped read only everywhere but in ring-0. However
|
---|
215 | * it is not marked 'const' as this might confuse compilers into
|
---|
216 | * thinking that values doesn't change even if members are marked
|
---|
217 | * as volatile. Thus, there is no PCSUPGLOBALINFOPAGE type.
|
---|
218 | */
|
---|
219 | #if defined(IN_SUP_R0) || defined(IN_SUP_R3) || defined(IN_SUP_RC)
|
---|
220 | extern DECLEXPORT(PSUPGLOBALINFOPAGE) g_pSUPGlobalInfoPage;
|
---|
221 |
|
---|
222 | #elif !defined(IN_RING0) || defined(RT_OS_WINDOWS)
|
---|
223 | extern DECLIMPORT(PSUPGLOBALINFOPAGE) g_pSUPGlobalInfoPage;
|
---|
224 |
|
---|
225 | #else /* IN_RING0 && !RT_OS_WINDOWS */
|
---|
226 | # if !defined(__GNUC__) || defined(RT_OS_DARWIN) || !defined(RT_ARCH_AMD64)
|
---|
227 | # define g_pSUPGlobalInfoPage (&g_SUPGlobalInfoPage)
|
---|
228 | # else
|
---|
229 | # define g_pSUPGlobalInfoPage (SUPGetGIPHlp())
|
---|
230 | /** Workaround for ELF+GCC problem on 64-bit hosts.
|
---|
231 | * (GCC emits a mov with a R_X86_64_32 reloc, we need R_X86_64_64.) */
|
---|
232 | DECLINLINE(PSUPGLOBALINFOPAGE) SUPGetGIPHlp(void)
|
---|
233 | {
|
---|
234 | PSUPGLOBALINFOPAGE pGIP;
|
---|
235 | __asm__ __volatile__ ("movabs $g_SUPGlobalInfoPage,%0\n\t"
|
---|
236 | : "=a" (pGIP));
|
---|
237 | return pGIP;
|
---|
238 | }
|
---|
239 | # endif
|
---|
240 | /** The GIP.
|
---|
241 | * We save a level of indirection by exporting the GIP instead of a variable
|
---|
242 | * pointing to it. */
|
---|
243 | extern DECLIMPORT(SUPGLOBALINFOPAGE) g_SUPGlobalInfoPage;
|
---|
244 | #endif
|
---|
245 |
|
---|
246 | /**
|
---|
247 | * Gets the GIP pointer.
|
---|
248 | *
|
---|
249 | * @returns Pointer to the GIP or NULL.
|
---|
250 | */
|
---|
251 | SUPDECL(PSUPGLOBALINFOPAGE) SUPGetGIP(void);
|
---|
252 |
|
---|
253 | /**
|
---|
254 | * Gets the TSC frequency of the calling CPU.
|
---|
255 | *
|
---|
256 | * @returns TSC frequency.
|
---|
257 | * @param pGip The GIP pointer.
|
---|
258 | */
|
---|
259 | DECLINLINE(uint64_t) SUPGetCpuHzFromGIP(PSUPGLOBALINFOPAGE pGip)
|
---|
260 | {
|
---|
261 | unsigned iCpu;
|
---|
262 |
|
---|
263 | if (RT_UNLIKELY(!pGip || pGip->u32Magic != SUPGLOBALINFOPAGE_MAGIC))
|
---|
264 | return ~(uint64_t)0;
|
---|
265 |
|
---|
266 | if (pGip->u32Mode != SUPGIPMODE_ASYNC_TSC)
|
---|
267 | iCpu = 0;
|
---|
268 | else
|
---|
269 | {
|
---|
270 | iCpu = ASMGetApicId();
|
---|
271 | if (RT_UNLIKELY(iCpu >= RT_ELEMENTS(pGip->aCPUs)))
|
---|
272 | return ~(uint64_t)0;
|
---|
273 | }
|
---|
274 |
|
---|
275 | return pGip->aCPUs[iCpu].u64CpuHz;
|
---|
276 | }
|
---|
277 |
|
---|
278 |
|
---|
279 | /**
|
---|
280 | * Request for generic VMMR0Entry calls.
|
---|
281 | */
|
---|
282 | typedef struct SUPVMMR0REQHDR
|
---|
283 | {
|
---|
284 | /** The magic. (SUPVMMR0REQHDR_MAGIC) */
|
---|
285 | uint32_t u32Magic;
|
---|
286 | /** The size of the request. */
|
---|
287 | uint32_t cbReq;
|
---|
288 | } SUPVMMR0REQHDR;
|
---|
289 | /** Pointer to a ring-0 request header. */
|
---|
290 | typedef SUPVMMR0REQHDR *PSUPVMMR0REQHDR;
|
---|
291 | /** the SUPVMMR0REQHDR::u32Magic value (Ethan Iverson - The Bad Plus). */
|
---|
292 | #define SUPVMMR0REQHDR_MAGIC UINT32_C(0x19730211)
|
---|
293 |
|
---|
294 |
|
---|
295 | /** For the fast ioctl path.
|
---|
296 | * @{
|
---|
297 | */
|
---|
298 | /** @see VMMR0_DO_RAW_RUN. */
|
---|
299 | #define SUP_VMMR0_DO_RAW_RUN 0
|
---|
300 | /** @see VMMR0_DO_HWACC_RUN. */
|
---|
301 | #define SUP_VMMR0_DO_HWACC_RUN 1
|
---|
302 | /** @see VMMR0_DO_NOP */
|
---|
303 | #define SUP_VMMR0_DO_NOP 2
|
---|
304 | /** @} */
|
---|
305 |
|
---|
306 | /** SUPR3QueryVTCaps capability flags
|
---|
307 | * @{
|
---|
308 | */
|
---|
309 | #define SUPVTCAPS_AMD_V RT_BIT(0)
|
---|
310 | #define SUPVTCAPS_VT_X RT_BIT(1)
|
---|
311 | #define SUPVTCAPS_NESTED_PAGING RT_BIT(2)
|
---|
312 | /** @} */
|
---|
313 |
|
---|
314 | /**
|
---|
315 | * Request for generic FNSUPR0SERVICEREQHANDLER calls.
|
---|
316 | */
|
---|
317 | typedef struct SUPR0SERVICEREQHDR
|
---|
318 | {
|
---|
319 | /** The magic. (SUPR0SERVICEREQHDR_MAGIC) */
|
---|
320 | uint32_t u32Magic;
|
---|
321 | /** The size of the request. */
|
---|
322 | uint32_t cbReq;
|
---|
323 | } SUPR0SERVICEREQHDR;
|
---|
324 | /** Pointer to a ring-0 service request header. */
|
---|
325 | typedef SUPR0SERVICEREQHDR *PSUPR0SERVICEREQHDR;
|
---|
326 | /** the SUPVMMR0REQHDR::u32Magic value (Esbjoern Svensson - E.S.P.). */
|
---|
327 | #define SUPR0SERVICEREQHDR_MAGIC UINT32_C(0x19640416)
|
---|
328 |
|
---|
329 |
|
---|
330 | /** Event semaphore handle. Ring-0 / ring-3. */
|
---|
331 | typedef R0PTRTYPE(struct SUPSEMEVENTHANDLE *) SUPSEMEVENT;
|
---|
332 | /** Pointer to an event semaphore handle. */
|
---|
333 | typedef SUPSEMEVENT *PSUPSEMEVENT;
|
---|
334 | /** Nil event semaphore handle. */
|
---|
335 | #define NIL_SUPSEMEVENT ((SUPSEMEVENT)0)
|
---|
336 |
|
---|
337 | /**
|
---|
338 | * Creates a single release event semaphore.
|
---|
339 | *
|
---|
340 | * @returns VBox status code.
|
---|
341 | * @param pSession The session handle of the caller.
|
---|
342 | * @param phEvent Where to return the handle to the event semaphore.
|
---|
343 | */
|
---|
344 | SUPDECL(int) SUPSemEventCreate(PSUPDRVSESSION pSession, PSUPSEMEVENT phEvent);
|
---|
345 |
|
---|
346 | /**
|
---|
347 | * Closes a single release event semaphore handle.
|
---|
348 | *
|
---|
349 | * @returns VBox status code.
|
---|
350 | * @retval VINF_OBJECT_DESTROYED if the semaphore was destroyed.
|
---|
351 | * @retval VINF_SUCCESS if the handle was successfully closed but the sempahore
|
---|
352 | * object remained alive because of other references.
|
---|
353 | *
|
---|
354 | * @param pSession The session handle of the caller.
|
---|
355 | * @param hEvent The handle. Nil is quietly ignored.
|
---|
356 | */
|
---|
357 | SUPDECL(int) SUPSemEventClose(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent);
|
---|
358 |
|
---|
359 | /**
|
---|
360 | * Signals a single release event semaphore.
|
---|
361 | *
|
---|
362 | * @returns VBox status code.
|
---|
363 | * @param pSession The session handle of the caller.
|
---|
364 | * @param hEvent The semaphore handle.
|
---|
365 | */
|
---|
366 | SUPDECL(int) SUPSemEventSignal(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent);
|
---|
367 |
|
---|
368 | #ifdef IN_RING0
|
---|
369 | /**
|
---|
370 | * Waits on a single release event semaphore, not interruptible.
|
---|
371 | *
|
---|
372 | * @returns VBox status code.
|
---|
373 | * @param pSession The session handle of the caller.
|
---|
374 | * @param hEvent The semaphore handle.
|
---|
375 | * @param cMillies The number of milliseconds to wait.
|
---|
376 | * @remarks Not available in ring-3.
|
---|
377 | */
|
---|
378 | SUPDECL(int) SUPSemEventWait(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent, uint32_t cMillies);
|
---|
379 | #endif
|
---|
380 |
|
---|
381 | /**
|
---|
382 | * Waits on a single release event semaphore, interruptible.
|
---|
383 | *
|
---|
384 | * @returns VBox status code.
|
---|
385 | * @param pSession The session handle of the caller.
|
---|
386 | * @param hEvent The semaphore handle.
|
---|
387 | * @param cMillies The number of milliseconds to wait.
|
---|
388 | */
|
---|
389 | SUPDECL(int) SUPSemEventWaitNoResume(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent, uint32_t cMillies);
|
---|
390 |
|
---|
391 |
|
---|
392 | /** Multiple release event semaphore handle. Ring-0 / ring-3. */
|
---|
393 | typedef R0PTRTYPE(struct SUPSEMEVENTMULTIHANDLE *) SUPSEMEVENTMULTI;
|
---|
394 | /** Pointer to an multiple release event semaphore handle. */
|
---|
395 | typedef SUPSEMEVENTMULTI *PSUPSEMEVENTMULTI;
|
---|
396 | /** Nil multiple release event semaphore handle. */
|
---|
397 | #define NIL_SUPSEMEVENTMULTI ((SUPSEMEVENTMULTI)0)
|
---|
398 |
|
---|
399 | /**
|
---|
400 | * Creates a multiple release event semaphore.
|
---|
401 | *
|
---|
402 | * @returns VBox status code.
|
---|
403 | * @param pSession The session handle of the caller.
|
---|
404 | * @param phEventMulti Where to return the handle to the event semaphore.
|
---|
405 | */
|
---|
406 | SUPDECL(int) SUPSemEventMultiCreate(PSUPDRVSESSION pSession, PSUPSEMEVENTMULTI phEventMulti);
|
---|
407 |
|
---|
408 | /**
|
---|
409 | * Closes a multiple release event semaphore handle.
|
---|
410 | *
|
---|
411 | * @returns VBox status code.
|
---|
412 | * @retval VINF_OBJECT_DESTROYED if the semaphore was destroyed.
|
---|
413 | * @retval VINF_SUCCESS if the handle was successfully closed but the sempahore
|
---|
414 | * object remained alive because of other references.
|
---|
415 | *
|
---|
416 | * @param pSession The session handle of the caller.
|
---|
417 | * @param hEventMulti The handle. Nil is quietly ignored.
|
---|
418 | */
|
---|
419 | SUPDECL(int) SUPSemEventMultiClose(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti);
|
---|
420 |
|
---|
421 | /**
|
---|
422 | * Signals a multiple release event semaphore.
|
---|
423 | *
|
---|
424 | * @returns VBox status code.
|
---|
425 | * @param pSession The session handle of the caller.
|
---|
426 | * @param hEventMulti The semaphore handle.
|
---|
427 | */
|
---|
428 | SUPDECL(int) SUPSemEventMultiSignal(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti);
|
---|
429 |
|
---|
430 | /**
|
---|
431 | * Resets a multiple release event semaphore.
|
---|
432 | *
|
---|
433 | * @returns VBox status code.
|
---|
434 | * @param pSession The session handle of the caller.
|
---|
435 | * @param hEventMulti The semaphore handle.
|
---|
436 | */
|
---|
437 | SUPDECL(int) SUPSemEventMultiReset(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti);
|
---|
438 |
|
---|
439 | #ifdef IN_RING0
|
---|
440 | /**
|
---|
441 | * Waits on a multiple release event semaphore, not interruptible.
|
---|
442 | *
|
---|
443 | * @returns VBox status code.
|
---|
444 | * @param pSession The session handle of the caller.
|
---|
445 | * @param hEventMulti The semaphore handle.
|
---|
446 | * @param cMillies The number of milliseconds to wait.
|
---|
447 | * @remarks Not available in ring-3.
|
---|
448 | */
|
---|
449 | SUPDECL(int) SUPSemEventMultiWait(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti, uint32_t cMillies);
|
---|
450 | #endif
|
---|
451 |
|
---|
452 | /**
|
---|
453 | * Waits on a multiple release event semaphore, interruptible.
|
---|
454 | *
|
---|
455 | * @returns VBox status code.
|
---|
456 | * @param pSession The session handle of the caller.
|
---|
457 | * @param hEventMulti The semaphore handle.
|
---|
458 | * @param cMillies The number of milliseconds to wait.
|
---|
459 | */
|
---|
460 | SUPDECL(int) SUPSemEventMultiWaitNoResume(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti, uint32_t cMillies);
|
---|
461 |
|
---|
462 |
|
---|
463 | #ifdef IN_RING3
|
---|
464 |
|
---|
465 | /** @defgroup grp_sup_r3 SUP Host Context Ring-3 API
|
---|
466 | * @ingroup grp_sup
|
---|
467 | * @{
|
---|
468 | */
|
---|
469 |
|
---|
470 | /**
|
---|
471 | * Installs the support library.
|
---|
472 | *
|
---|
473 | * @returns VBox status code.
|
---|
474 | */
|
---|
475 | SUPR3DECL(int) SUPR3Install(void);
|
---|
476 |
|
---|
477 | /**
|
---|
478 | * Uninstalls the support library.
|
---|
479 | *
|
---|
480 | * @returns VBox status code.
|
---|
481 | */
|
---|
482 | SUPR3DECL(int) SUPR3Uninstall(void);
|
---|
483 |
|
---|
484 | /**
|
---|
485 | * Trusted main entry point.
|
---|
486 | *
|
---|
487 | * This is exported as "TrustedMain" by the dynamic libraries which contains the
|
---|
488 | * "real" application binary for which the hardened stub is built. The entry
|
---|
489 | * point is invoked upon successfull initialization of the support library and
|
---|
490 | * runtime.
|
---|
491 | *
|
---|
492 | * @returns main kind of exit code.
|
---|
493 | * @param argc The argument count.
|
---|
494 | * @param argv The argument vector.
|
---|
495 | * @param envp The environment vector.
|
---|
496 | */
|
---|
497 | typedef DECLCALLBACK(int) FNSUPTRUSTEDMAIN(int argc, char **argv, char **envp);
|
---|
498 | /** Pointer to FNSUPTRUSTEDMAIN(). */
|
---|
499 | typedef FNSUPTRUSTEDMAIN *PFNSUPTRUSTEDMAIN;
|
---|
500 |
|
---|
501 | /** Which operation failed. */
|
---|
502 | typedef enum SUPINITOP
|
---|
503 | {
|
---|
504 | /** Invalid. */
|
---|
505 | kSupInitOp_Invalid = 0,
|
---|
506 | /** Installation integrity error. */
|
---|
507 | kSupInitOp_Integrity,
|
---|
508 | /** Setuid related. */
|
---|
509 | kSupInitOp_RootCheck,
|
---|
510 | /** Driver related. */
|
---|
511 | kSupInitOp_Driver,
|
---|
512 | /** IPRT init related. */
|
---|
513 | kSupInitOp_IPRT,
|
---|
514 | /** Place holder. */
|
---|
515 | kSupInitOp_End
|
---|
516 | } SUPINITOP;
|
---|
517 |
|
---|
518 | /**
|
---|
519 | * Trusted error entry point, optional.
|
---|
520 | *
|
---|
521 | * This is exported as "TrustedError" by the dynamic libraries which contains
|
---|
522 | * the "real" application binary for which the hardened stub is built.
|
---|
523 | *
|
---|
524 | * @param pszWhere Where the error occured (function name).
|
---|
525 | * @param enmWhat Which operation went wrong.
|
---|
526 | * @param rc The status code.
|
---|
527 | * @param pszMsgFmt Error message format string.
|
---|
528 | * @param va The message format arguments.
|
---|
529 | */
|
---|
530 | typedef DECLCALLBACK(void) FNSUPTRUSTEDERROR(const char *pszWhere, SUPINITOP enmWhat, int rc, const char *pszMsgFmt, va_list va);
|
---|
531 | /** Pointer to FNSUPTRUSTEDERROR. */
|
---|
532 | typedef FNSUPTRUSTEDERROR *PFNSUPTRUSTEDERROR;
|
---|
533 |
|
---|
534 | /**
|
---|
535 | * Secure main.
|
---|
536 | *
|
---|
537 | * This is used for the set-user-ID-on-execute binaries on unixy systems
|
---|
538 | * and when using the open-vboxdrv-via-root-service setup on Windows.
|
---|
539 | *
|
---|
540 | * This function will perform the integrity checks of the VirtualBox
|
---|
541 | * installation, open the support driver, open the root service (later),
|
---|
542 | * and load the DLL corresponding to \a pszProgName and execute its main
|
---|
543 | * function.
|
---|
544 | *
|
---|
545 | * @returns Return code appropriate for main().
|
---|
546 | *
|
---|
547 | * @param pszProgName The program name. This will be used to figure out which
|
---|
548 | * DLL/SO/DYLIB to load and execute.
|
---|
549 | * @param fFlags Flags.
|
---|
550 | * @param argc The argument count.
|
---|
551 | * @param argv The argument vector.
|
---|
552 | * @param envp The environment vector.
|
---|
553 | */
|
---|
554 | DECLHIDDEN(int) SUPR3HardenedMain(const char *pszProgName, uint32_t fFlags, int argc, char **argv, char **envp);
|
---|
555 |
|
---|
556 | /** @name SUPR3SecureMain flags.
|
---|
557 | * @{ */
|
---|
558 | /** Don't open the device. (Intended for VirtualBox without -startvm.) */
|
---|
559 | #define SUPSECMAIN_FLAGS_DONT_OPEN_DEV RT_BIT_32(0)
|
---|
560 | /** @} */
|
---|
561 |
|
---|
562 | /**
|
---|
563 | * Initializes the support library.
|
---|
564 | * Each succesful call to SUPR3Init() must be countered by a
|
---|
565 | * call to SUPR3Term(false).
|
---|
566 | *
|
---|
567 | * @returns VBox status code.
|
---|
568 | * @param ppSession Where to store the session handle. Defaults to NULL.
|
---|
569 | */
|
---|
570 | SUPR3DECL(int) SUPR3Init(PSUPDRVSESSION *ppSession);
|
---|
571 |
|
---|
572 | /**
|
---|
573 | * Terminates the support library.
|
---|
574 | *
|
---|
575 | * @returns VBox status code.
|
---|
576 | * @param fForced Forced termination. This means to ignore the
|
---|
577 | * init call count and just terminated.
|
---|
578 | */
|
---|
579 | #ifdef __cplusplus
|
---|
580 | SUPR3DECL(int) SUPR3Term(bool fForced = false);
|
---|
581 | #else
|
---|
582 | SUPR3DECL(int) SUPR3Term(int fForced);
|
---|
583 | #endif
|
---|
584 |
|
---|
585 | /**
|
---|
586 | * Sets the ring-0 VM handle for use with fast IOCtls.
|
---|
587 | *
|
---|
588 | * @returns VBox status code.
|
---|
589 | * @param pVMR0 The ring-0 VM handle.
|
---|
590 | * NIL_RTR0PTR can be used to unset the handle when the
|
---|
591 | * VM is about to be destroyed.
|
---|
592 | */
|
---|
593 | SUPR3DECL(int) SUPR3SetVMForFastIOCtl(PVMR0 pVMR0);
|
---|
594 |
|
---|
595 | /**
|
---|
596 | * Calls the HC R0 VMM entry point.
|
---|
597 | * See VMMR0Entry() for more details.
|
---|
598 | *
|
---|
599 | * @returns error code specific to uFunction.
|
---|
600 | * @param pVMR0 Pointer to the Ring-0 (Host Context) mapping of the VM structure.
|
---|
601 | * @param idCpu The virtual CPU ID.
|
---|
602 | * @param uOperation Operation to execute.
|
---|
603 | * @param pvArg Argument.
|
---|
604 | */
|
---|
605 | SUPR3DECL(int) SUPR3CallVMMR0(PVMR0 pVMR0, VMCPUID idCpu, unsigned uOperation, void *pvArg);
|
---|
606 |
|
---|
607 | /**
|
---|
608 | * Variant of SUPR3CallVMMR0, except that this takes the fast ioclt path
|
---|
609 | * regardsless of compile-time defaults.
|
---|
610 | *
|
---|
611 | * @returns VBox status code.
|
---|
612 | * @param pVMR0 The ring-0 VM handle.
|
---|
613 | * @param uOperation The operation; only the SUP_VMMR0_DO_* ones are valid.
|
---|
614 | * @param idCpu The virtual CPU ID.
|
---|
615 | */
|
---|
616 | SUPR3DECL(int) SUPR3CallVMMR0Fast(PVMR0 pVMR0, unsigned uOperation, VMCPUID idCpu);
|
---|
617 |
|
---|
618 | /**
|
---|
619 | * Calls the HC R0 VMM entry point, in a safer but slower manner than
|
---|
620 | * SUPR3CallVMMR0. When entering using this call the R0 components can call
|
---|
621 | * into the host kernel (i.e. use the SUPR0 and RT APIs).
|
---|
622 | *
|
---|
623 | * See VMMR0Entry() for more details.
|
---|
624 | *
|
---|
625 | * @returns error code specific to uFunction.
|
---|
626 | * @param pVMR0 Pointer to the Ring-0 (Host Context) mapping of the VM structure.
|
---|
627 | * @param idCpu The virtual CPU ID.
|
---|
628 | * @param uOperation Operation to execute.
|
---|
629 | * @param u64Arg Constant argument.
|
---|
630 | * @param pReqHdr Pointer to a request header. Optional.
|
---|
631 | * This will be copied in and out of kernel space. There currently is a size
|
---|
632 | * limit on this, just below 4KB.
|
---|
633 | */
|
---|
634 | SUPR3DECL(int) SUPR3CallVMMR0Ex(PVMR0 pVMR0, VMCPUID idCpu, unsigned uOperation, uint64_t u64Arg, PSUPVMMR0REQHDR pReqHdr);
|
---|
635 |
|
---|
636 | /**
|
---|
637 | * Calls a ring-0 service.
|
---|
638 | *
|
---|
639 | * The operation and the request packet is specific to the service.
|
---|
640 | *
|
---|
641 | * @returns error code specific to uFunction.
|
---|
642 | * @param pszService The service name.
|
---|
643 | * @param cchService The length of the service name.
|
---|
644 | * @param uReq The request number.
|
---|
645 | * @param u64Arg Constant argument.
|
---|
646 | * @param pReqHdr Pointer to a request header. Optional.
|
---|
647 | * This will be copied in and out of kernel space. There currently is a size
|
---|
648 | * limit on this, just below 4KB.
|
---|
649 | */
|
---|
650 | SUPR3DECL(int) SUPR3CallR0Service(const char *pszService, size_t cchService, uint32_t uOperation, uint64_t u64Arg, PSUPR0SERVICEREQHDR pReqHdr);
|
---|
651 |
|
---|
652 | /** Which logger. */
|
---|
653 | typedef enum SUPLOGGER
|
---|
654 | {
|
---|
655 | SUPLOGGER_DEBUG = 1,
|
---|
656 | SUPLOGGER_RELEASE
|
---|
657 | } SUPLOGGER;
|
---|
658 |
|
---|
659 | /**
|
---|
660 | * Changes the settings of the specified ring-0 logger.
|
---|
661 | *
|
---|
662 | * @returns VBox status code.
|
---|
663 | * @param enmWhich Which logger.
|
---|
664 | * @param pszFlags The flags settings.
|
---|
665 | * @param pszGroups The groups settings.
|
---|
666 | * @param pszDest The destionation specificier.
|
---|
667 | */
|
---|
668 | SUPR3DECL(int) SUPR3LoggerSettings(SUPLOGGER enmWhich, const char *pszFlags, const char *pszGroups, const char *pszDest);
|
---|
669 |
|
---|
670 | /**
|
---|
671 | * Creates a ring-0 logger instance.
|
---|
672 | *
|
---|
673 | * @returns VBox status code.
|
---|
674 | * @param enmWhich Which logger to create.
|
---|
675 | * @param pszFlags The flags settings.
|
---|
676 | * @param pszGroups The groups settings.
|
---|
677 | * @param pszDest The destionation specificier.
|
---|
678 | */
|
---|
679 | SUPR3DECL(int) SUPR3LoggerCreate(SUPLOGGER enmWhich, const char *pszFlags, const char *pszGroups, const char *pszDest);
|
---|
680 |
|
---|
681 | /**
|
---|
682 | * Destroys a ring-0 logger instance.
|
---|
683 | *
|
---|
684 | * @returns VBox status code.
|
---|
685 | * @param enmWhich Which logger.
|
---|
686 | */
|
---|
687 | SUPR3DECL(int) SUPR3LoggerDestroy(SUPLOGGER enmWhich);
|
---|
688 |
|
---|
689 | /**
|
---|
690 | * Queries the paging mode of the host OS.
|
---|
691 | *
|
---|
692 | * @returns The paging mode.
|
---|
693 | */
|
---|
694 | SUPR3DECL(SUPPAGINGMODE) SUPR3GetPagingMode(void);
|
---|
695 |
|
---|
696 | /**
|
---|
697 | * Allocate zero-filled pages.
|
---|
698 | *
|
---|
699 | * Use this to allocate a number of pages suitable for seeding / locking.
|
---|
700 | * Call SUPR3PageFree() to free the pages once done with them.
|
---|
701 | *
|
---|
702 | * @returns VBox status.
|
---|
703 | * @param cPages Number of pages to allocate.
|
---|
704 | * @param ppvPages Where to store the base pointer to the allocated pages.
|
---|
705 | */
|
---|
706 | SUPR3DECL(int) SUPR3PageAlloc(size_t cPages, void **ppvPages);
|
---|
707 |
|
---|
708 | /**
|
---|
709 | * Frees pages allocated with SUPR3PageAlloc().
|
---|
710 | *
|
---|
711 | * @returns VBox status.
|
---|
712 | * @param pvPages Pointer returned by SUPR3PageAlloc().
|
---|
713 | * @param cPages Number of pages that was allocated.
|
---|
714 | */
|
---|
715 | SUPR3DECL(int) SUPR3PageFree(void *pvPages, size_t cPages);
|
---|
716 |
|
---|
717 | /**
|
---|
718 | * Allocate non-zeroed, locked, pages with user and, optionally, kernel
|
---|
719 | * mappings.
|
---|
720 | *
|
---|
721 | * Use SUPR3PageFreeEx() to free memory allocated with this function.
|
---|
722 | *
|
---|
723 | * @returns VBox status code.
|
---|
724 | * @param cPages The number of pages to allocate.
|
---|
725 | * @param fFlags Flags, reserved. Must be zero.
|
---|
726 | * @param ppvPages Where to store the address of the user mapping.
|
---|
727 | * @param pR0Ptr Where to store the address of the kernel mapping.
|
---|
728 | * NULL if no kernel mapping is desired.
|
---|
729 | * @param paPages Where to store the physical addresses of each page.
|
---|
730 | * Optional.
|
---|
731 | */
|
---|
732 | SUPR3DECL(int) SUPR3PageAllocEx(size_t cPages, uint32_t fFlags, void **ppvPages, PRTR0PTR pR0Ptr, PSUPPAGE paPages);
|
---|
733 |
|
---|
734 | /**
|
---|
735 | * Maps a portion of a ring-3 only allocation into kernel space.
|
---|
736 | *
|
---|
737 | * @returns VBox status code.
|
---|
738 | *
|
---|
739 | * @param pvR3 The address SUPR3PageAllocEx return.
|
---|
740 | * @param off Offset to start mapping at. Must be page aligned.
|
---|
741 | * @param cb Number of bytes to map. Must be page aligned.
|
---|
742 | * @param fFlags Flags, must be zero.
|
---|
743 | * @param pR0Ptr Where to store the address on success.
|
---|
744 | *
|
---|
745 | */
|
---|
746 | SUPR3DECL(int) SUPR3PageMapKernel(void *pvR3, uint32_t off, uint32_t cb, uint32_t fFlags, PRTR0PTR pR0Ptr);
|
---|
747 |
|
---|
748 | /**
|
---|
749 | * Changes the protection of
|
---|
750 | *
|
---|
751 | * @returns VBox status code.
|
---|
752 | * @retval VERR_NOT_SUPPORTED if the OS doesn't allow us to change page level
|
---|
753 | * protection. See also RTR0MemObjProtect.
|
---|
754 | *
|
---|
755 | * @param pvR3 The ring-3 address SUPR3PageAllocEx returned.
|
---|
756 | * @param R0Ptr The ring-0 address SUPR3PageAllocEx returned if it
|
---|
757 | * is desired that the corresponding ring-0 page
|
---|
758 | * mappings should change protection as well. Pass
|
---|
759 | * NIL_RTR0PTR if the ring-0 pages should remain
|
---|
760 | * unaffected.
|
---|
761 | * @param off Offset to start at which to start chagning the page
|
---|
762 | * level protection. Must be page aligned.
|
---|
763 | * @param cb Number of bytes to change. Must be page aligned.
|
---|
764 | * @param fProt The new page level protection, either a combination
|
---|
765 | * of RTMEM_PROT_READ, RTMEM_PROT_WRITE and
|
---|
766 | * RTMEM_PROT_EXEC, or just RTMEM_PROT_NONE.
|
---|
767 | */
|
---|
768 | SUPR3DECL(int) SUPR3PageProtect(void *pvR3, RTR0PTR R0Ptr, uint32_t off, uint32_t cb, uint32_t fProt);
|
---|
769 |
|
---|
770 | /**
|
---|
771 | * Free pages allocated by SUPR3PageAllocEx.
|
---|
772 | *
|
---|
773 | * @returns VBox status code.
|
---|
774 | * @param pvPages The address of the user mapping.
|
---|
775 | * @param cPages The number of pages.
|
---|
776 | */
|
---|
777 | SUPR3DECL(int) SUPR3PageFreeEx(void *pvPages, size_t cPages);
|
---|
778 |
|
---|
779 | /**
|
---|
780 | * Allocated memory with page aligned memory with a contiguous and locked physical
|
---|
781 | * memory backing below 4GB.
|
---|
782 | *
|
---|
783 | * @returns Pointer to the allocated memory (virtual address).
|
---|
784 | * *pHCPhys is set to the physical address of the memory.
|
---|
785 | * If ppvR0 isn't NULL, *ppvR0 is set to the ring-0 mapping.
|
---|
786 | * The returned memory must be freed using SUPR3ContFree().
|
---|
787 | * @returns NULL on failure.
|
---|
788 | * @param cPages Number of pages to allocate.
|
---|
789 | * @param pR0Ptr Where to store the ring-0 mapping of the allocation. (optional)
|
---|
790 | * @param pHCPhys Where to store the physical address of the memory block.
|
---|
791 | *
|
---|
792 | * @remark This 2nd version of this API exists because we're not able to map the
|
---|
793 | * ring-3 mapping executable on WIN64. This is a serious problem in regard to
|
---|
794 | * the world switchers.
|
---|
795 | */
|
---|
796 | SUPR3DECL(void *) SUPR3ContAlloc(size_t cPages, PRTR0PTR pR0Ptr, PRTHCPHYS pHCPhys);
|
---|
797 |
|
---|
798 | /**
|
---|
799 | * Frees memory allocated with SUPR3ContAlloc().
|
---|
800 | *
|
---|
801 | * @returns VBox status code.
|
---|
802 | * @param pv Pointer to the memory block which should be freed.
|
---|
803 | * @param cPages Number of pages to be freed.
|
---|
804 | */
|
---|
805 | SUPR3DECL(int) SUPR3ContFree(void *pv, size_t cPages);
|
---|
806 |
|
---|
807 | /**
|
---|
808 | * Allocated non contiguous physical memory below 4GB.
|
---|
809 | *
|
---|
810 | * The memory isn't zeroed.
|
---|
811 | *
|
---|
812 | * @returns VBox status code.
|
---|
813 | * @returns NULL on failure.
|
---|
814 | * @param cPages Number of pages to allocate.
|
---|
815 | * @param ppvPages Where to store the pointer to the allocated memory.
|
---|
816 | * The pointer stored here on success must be passed to
|
---|
817 | * SUPR3LowFree when the memory should be released.
|
---|
818 | * @param ppvPagesR0 Where to store the ring-0 pointer to the allocated memory. optional.
|
---|
819 | * @param paPages Where to store the physical addresses of the individual pages.
|
---|
820 | */
|
---|
821 | SUPR3DECL(int) SUPR3LowAlloc(size_t cPages, void **ppvPages, PRTR0PTR ppvPagesR0, PSUPPAGE paPages);
|
---|
822 |
|
---|
823 | /**
|
---|
824 | * Frees memory allocated with SUPR3LowAlloc().
|
---|
825 | *
|
---|
826 | * @returns VBox status code.
|
---|
827 | * @param pv Pointer to the memory block which should be freed.
|
---|
828 | * @param cPages Number of pages that was allocated.
|
---|
829 | */
|
---|
830 | SUPR3DECL(int) SUPR3LowFree(void *pv, size_t cPages);
|
---|
831 |
|
---|
832 | /**
|
---|
833 | * Load a module into R0 HC.
|
---|
834 | *
|
---|
835 | * This will verify the file integrity in a similar manner as
|
---|
836 | * SUPR3HardenedVerifyFile before loading it.
|
---|
837 | *
|
---|
838 | * @returns VBox status code.
|
---|
839 | * @param pszFilename The path to the image file.
|
---|
840 | * @param pszModule The module name. Max 32 bytes.
|
---|
841 | * @param ppvImageBase Where to store the image address.
|
---|
842 | */
|
---|
843 | SUPR3DECL(int) SUPR3LoadModule(const char *pszFilename, const char *pszModule, void **ppvImageBase);
|
---|
844 |
|
---|
845 | /**
|
---|
846 | * Load a module into R0 HC.
|
---|
847 | *
|
---|
848 | * This will verify the file integrity in a similar manner as
|
---|
849 | * SUPR3HardenedVerifyFile before loading it.
|
---|
850 | *
|
---|
851 | * @returns VBox status code.
|
---|
852 | * @param pszFilename The path to the image file.
|
---|
853 | * @param pszModule The module name. Max 32 bytes.
|
---|
854 | * @param pszSrvReqHandler The name of the service request handler entry
|
---|
855 | * point. See FNSUPR0SERVICEREQHANDLER.
|
---|
856 | * @param ppvImageBase Where to store the image address.
|
---|
857 | */
|
---|
858 | SUPR3DECL(int) SUPR3LoadServiceModule(const char *pszFilename, const char *pszModule,
|
---|
859 | const char *pszSrvReqHandler, void **ppvImageBase);
|
---|
860 |
|
---|
861 | /**
|
---|
862 | * Frees a R0 HC module.
|
---|
863 | *
|
---|
864 | * @returns VBox status code.
|
---|
865 | * @param pszModule The module to free.
|
---|
866 | * @remark This will not actually 'free' the module, there are of course usage counting.
|
---|
867 | */
|
---|
868 | SUPR3DECL(int) SUPR3FreeModule(void *pvImageBase);
|
---|
869 |
|
---|
870 | /**
|
---|
871 | * Get the address of a symbol in a ring-0 module.
|
---|
872 | *
|
---|
873 | * @returns VBox status code.
|
---|
874 | * @param pszModule The module name.
|
---|
875 | * @param pszSymbol Symbol name. If it's value is less than 64k it's treated like a
|
---|
876 | * ordinal value rather than a string pointer.
|
---|
877 | * @param ppvValue Where to store the symbol value.
|
---|
878 | */
|
---|
879 | SUPR3DECL(int) SUPR3GetSymbolR0(void *pvImageBase, const char *pszSymbol, void **ppvValue);
|
---|
880 |
|
---|
881 | /**
|
---|
882 | * Load R0 HC VMM code.
|
---|
883 | *
|
---|
884 | * @returns VBox status code.
|
---|
885 | * @deprecated Use SUPR3LoadModule(pszFilename, "VMMR0.r0", &pvImageBase)
|
---|
886 | */
|
---|
887 | SUPR3DECL(int) SUPR3LoadVMM(const char *pszFilename);
|
---|
888 |
|
---|
889 | /**
|
---|
890 | * Unloads R0 HC VMM code.
|
---|
891 | *
|
---|
892 | * @returns VBox status code.
|
---|
893 | * @deprecated Use SUPR3FreeModule().
|
---|
894 | */
|
---|
895 | SUPR3DECL(int) SUPR3UnloadVMM(void);
|
---|
896 |
|
---|
897 | /**
|
---|
898 | * Get the physical address of the GIP.
|
---|
899 | *
|
---|
900 | * @returns VBox status code.
|
---|
901 | * @param pHCPhys Where to store the physical address of the GIP.
|
---|
902 | */
|
---|
903 | SUPR3DECL(int) SUPR3GipGetPhys(PRTHCPHYS pHCPhys);
|
---|
904 |
|
---|
905 | /**
|
---|
906 | * Verifies the integrity of a file, and optionally opens it.
|
---|
907 | *
|
---|
908 | * The integrity check is for whether the file is suitable for loading into
|
---|
909 | * the hypervisor or VM process. The integrity check may include verifying
|
---|
910 | * the authenticode/elfsign/whatever signature of the file, which can take
|
---|
911 | * a little while.
|
---|
912 | *
|
---|
913 | * @returns VBox status code. On failure it will have printed a LogRel message.
|
---|
914 | *
|
---|
915 | * @param pszFilename The file.
|
---|
916 | * @param pszWhat For the LogRel on failure.
|
---|
917 | * @param phFile Where to store the handle to the opened file. This is optional, pass NULL
|
---|
918 | * if the file should not be opened.
|
---|
919 | */
|
---|
920 | SUPR3DECL(int) SUPR3HardenedVerifyFile(const char *pszFilename, const char *pszWhat, PRTFILE phFile);
|
---|
921 |
|
---|
922 | /**
|
---|
923 | * Same as RTLdrLoad() but will verify the files it loads (hardened builds).
|
---|
924 | *
|
---|
925 | * Will add dll suffix if missing and try load the file.
|
---|
926 | *
|
---|
927 | * @returns iprt status code.
|
---|
928 | * @param pszFilename Image filename. This must have a path.
|
---|
929 | * @param phLdrMod Where to store the handle to the loaded module.
|
---|
930 | */
|
---|
931 | SUPR3DECL(int) SUPR3HardenedLdrLoad(const char *pszFilename, PRTLDRMOD phLdrMod);
|
---|
932 |
|
---|
933 | /**
|
---|
934 | * Same as RTLdrLoadAppPriv() but it will verify the files it loads (hardened
|
---|
935 | * builds).
|
---|
936 | *
|
---|
937 | * Will add dll suffix to the file if missing, then look for it in the
|
---|
938 | * architecture dependent application directory.
|
---|
939 | *
|
---|
940 | * @returns iprt status code.
|
---|
941 | * @param pszFilename Image filename.
|
---|
942 | * @param phLdrMod Where to store the handle to the loaded module.
|
---|
943 | */
|
---|
944 | SUPR3DECL(int) SUPR3HardenedLdrLoadAppPriv(const char *pszFilename, PRTLDRMOD phLdrMod);
|
---|
945 |
|
---|
946 |
|
---|
947 | /**
|
---|
948 | * Check if the host kernel can run in VMX root mode.
|
---|
949 | *
|
---|
950 | * @returns VINF_SUCCESS if supported, error code indicating why if not.
|
---|
951 | */
|
---|
952 | SUPR3DECL(int) SUPR3QueryVTxSupported(void);
|
---|
953 |
|
---|
954 |
|
---|
955 | /**
|
---|
956 | * Return VT-x/AMD-V capabilities.
|
---|
957 | *
|
---|
958 | * @returns VINF_SUCCESS if supported, error code indicating why if not.
|
---|
959 | * @param pfCaps Pointer to capability dword (out).
|
---|
960 | */
|
---|
961 | SUPR3DECL(int) SUPR3QueryVTCaps(uint32_t *pfCaps);
|
---|
962 |
|
---|
963 | /** @} */
|
---|
964 | #endif /* IN_RING3 */
|
---|
965 |
|
---|
966 |
|
---|
967 | #ifdef IN_RING0
|
---|
968 | /** @defgroup grp_sup_r0 SUP Host Context Ring-0 API
|
---|
969 | * @ingroup grp_sup
|
---|
970 | * @{
|
---|
971 | */
|
---|
972 |
|
---|
973 | /**
|
---|
974 | * Security objectype.
|
---|
975 | */
|
---|
976 | typedef enum SUPDRVOBJTYPE
|
---|
977 | {
|
---|
978 | /** The usual invalid object. */
|
---|
979 | SUPDRVOBJTYPE_INVALID = 0,
|
---|
980 | /** A Virtual Machine instance. */
|
---|
981 | SUPDRVOBJTYPE_VM,
|
---|
982 | /** Internal network. */
|
---|
983 | SUPDRVOBJTYPE_INTERNAL_NETWORK,
|
---|
984 | /** Internal network interface. */
|
---|
985 | SUPDRVOBJTYPE_INTERNAL_NETWORK_INTERFACE,
|
---|
986 | /** Single release event semaphore. */
|
---|
987 | SUPDRVOBJTYPE_SEM_EVENT,
|
---|
988 | /** Multiple release event semaphore. */
|
---|
989 | SUPDRVOBJTYPE_SEM_EVENT_MULTI,
|
---|
990 | /** The first invalid object type in this end. */
|
---|
991 | SUPDRVOBJTYPE_END,
|
---|
992 | /** The usual 32-bit type size hack. */
|
---|
993 | SUPDRVOBJTYPE_32_BIT_HACK = 0x7ffffff
|
---|
994 | } SUPDRVOBJTYPE;
|
---|
995 |
|
---|
996 | /**
|
---|
997 | * Object destructor callback.
|
---|
998 | * This is called for reference counted objectes when the count reaches 0.
|
---|
999 | *
|
---|
1000 | * @param pvObj The object pointer.
|
---|
1001 | * @param pvUser1 The first user argument.
|
---|
1002 | * @param pvUser2 The second user argument.
|
---|
1003 | */
|
---|
1004 | typedef DECLCALLBACK(void) FNSUPDRVDESTRUCTOR(void *pvObj, void *pvUser1, void *pvUser2);
|
---|
1005 | /** Pointer to a FNSUPDRVDESTRUCTOR(). */
|
---|
1006 | typedef FNSUPDRVDESTRUCTOR *PFNSUPDRVDESTRUCTOR;
|
---|
1007 |
|
---|
1008 | SUPR0DECL(void *) SUPR0ObjRegister(PSUPDRVSESSION pSession, SUPDRVOBJTYPE enmType, PFNSUPDRVDESTRUCTOR pfnDestructor, void *pvUser1, void *pvUser2);
|
---|
1009 | SUPR0DECL(int) SUPR0ObjAddRef(void *pvObj, PSUPDRVSESSION pSession);
|
---|
1010 | SUPR0DECL(int) SUPR0ObjAddRefEx(void *pvObj, PSUPDRVSESSION pSession, bool fNoBlocking);
|
---|
1011 | SUPR0DECL(int) SUPR0ObjRelease(void *pvObj, PSUPDRVSESSION pSession);
|
---|
1012 | SUPR0DECL(int) SUPR0ObjVerifyAccess(void *pvObj, PSUPDRVSESSION pSession, const char *pszObjName);
|
---|
1013 |
|
---|
1014 | SUPR0DECL(int) SUPR0LockMem(PSUPDRVSESSION pSession, RTR3PTR pvR3, uint32_t cPages, PRTHCPHYS paPages);
|
---|
1015 | SUPR0DECL(int) SUPR0UnlockMem(PSUPDRVSESSION pSession, RTR3PTR pvR3);
|
---|
1016 | SUPR0DECL(int) SUPR0ContAlloc(PSUPDRVSESSION pSession, uint32_t cPages, PRTR0PTR ppvR0, PRTR3PTR ppvR3, PRTHCPHYS pHCPhys);
|
---|
1017 | SUPR0DECL(int) SUPR0ContFree(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr);
|
---|
1018 | SUPR0DECL(int) SUPR0LowAlloc(PSUPDRVSESSION pSession, uint32_t cPages, PRTR0PTR ppvR0, PRTR3PTR ppvR3, PRTHCPHYS paPages);
|
---|
1019 | SUPR0DECL(int) SUPR0LowFree(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr);
|
---|
1020 | SUPR0DECL(int) SUPR0MemAlloc(PSUPDRVSESSION pSession, uint32_t cb, PRTR0PTR ppvR0, PRTR3PTR ppvR3);
|
---|
1021 | SUPR0DECL(int) SUPR0MemGetPhys(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr, PSUPPAGE paPages);
|
---|
1022 | SUPR0DECL(int) SUPR0MemFree(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr);
|
---|
1023 | SUPR0DECL(int) SUPR0PageAllocEx(PSUPDRVSESSION pSession, uint32_t cPages, uint32_t fFlags, PRTR3PTR ppvR3, PRTR0PTR ppvR0, PRTHCPHYS paPages);
|
---|
1024 | SUPR0DECL(int) SUPR0PageMapKernel(PSUPDRVSESSION pSession, RTR3PTR pvR3, uint32_t offSub, uint32_t cbSub, uint32_t fFlags, PRTR0PTR ppvR0);
|
---|
1025 | SUPR0DECL(int) SUPR0PageProtect(PSUPDRVSESSION pSession, RTR3PTR pvR3, RTR0PTR pvR0, uint32_t offSub, uint32_t cbSub, uint32_t fProt);
|
---|
1026 | SUPR0DECL(int) SUPR0PageFree(PSUPDRVSESSION pSession, RTR3PTR pvR3);
|
---|
1027 | SUPR0DECL(int) SUPR0GipMap(PSUPDRVSESSION pSession, PRTR3PTR ppGipR3, PRTHCPHYS pHCPhysGip);
|
---|
1028 | SUPR0DECL(int) SUPR0QueryVTCaps(PSUPDRVSESSION pSession, uint32_t *pfCaps);
|
---|
1029 | SUPR0DECL(int) SUPR0GipUnmap(PSUPDRVSESSION pSession);
|
---|
1030 | SUPR0DECL(int) SUPR0Printf(const char *pszFormat, ...);
|
---|
1031 | SUPR0DECL(SUPPAGINGMODE) SUPR0GetPagingMode(void);
|
---|
1032 | SUPR0DECL(int) SUPR0EnableVTx(bool fEnable);
|
---|
1033 |
|
---|
1034 | /** @name Absolute symbols
|
---|
1035 | * Take the address of these, don't try call them.
|
---|
1036 | * @{ */
|
---|
1037 | SUPR0DECL(void) SUPR0AbsIs64bit(void);
|
---|
1038 | SUPR0DECL(void) SUPR0Abs64bitKernelCS(void);
|
---|
1039 | SUPR0DECL(void) SUPR0Abs64bitKernelSS(void);
|
---|
1040 | SUPR0DECL(void) SUPR0Abs64bitKernelDS(void);
|
---|
1041 | SUPR0DECL(void) SUPR0AbsKernelCS(void);
|
---|
1042 | SUPR0DECL(void) SUPR0AbsKernelSS(void);
|
---|
1043 | SUPR0DECL(void) SUPR0AbsKernelDS(void);
|
---|
1044 | SUPR0DECL(void) SUPR0AbsKernelES(void);
|
---|
1045 | SUPR0DECL(void) SUPR0AbsKernelFS(void);
|
---|
1046 | SUPR0DECL(void) SUPR0AbsKernelGS(void);
|
---|
1047 | /** @} */
|
---|
1048 |
|
---|
1049 | /**
|
---|
1050 | * Support driver component factory.
|
---|
1051 | *
|
---|
1052 | * Component factories are registered by drivers that provides services
|
---|
1053 | * such as the host network interface filtering and access to the host
|
---|
1054 | * TCP/IP stack.
|
---|
1055 | *
|
---|
1056 | * @remark Module dependencies and making sure that a component doesn't
|
---|
1057 | * get unloaded while in use, is the sole responsibility of the
|
---|
1058 | * driver/kext/whatever implementing the component.
|
---|
1059 | */
|
---|
1060 | typedef struct SUPDRVFACTORY
|
---|
1061 | {
|
---|
1062 | /** The (unique) name of the component factory. */
|
---|
1063 | char szName[56];
|
---|
1064 | /**
|
---|
1065 | * Queries a factory interface.
|
---|
1066 | *
|
---|
1067 | * The factory interface is specific to each component and will be be
|
---|
1068 | * found in the header(s) for the component alongside its UUID.
|
---|
1069 | *
|
---|
1070 | * @returns Pointer to the factory interfaces on success, NULL on failure.
|
---|
1071 | *
|
---|
1072 | * @param pSupDrvFactory Pointer to this structure.
|
---|
1073 | * @param pSession The SUPDRV session making the query.
|
---|
1074 | * @param pszInterfaceUuid The UUID of the factory interface.
|
---|
1075 | */
|
---|
1076 | DECLR0CALLBACKMEMBER(void *, pfnQueryFactoryInterface,(struct SUPDRVFACTORY const *pSupDrvFactory, PSUPDRVSESSION pSession, const char *pszInterfaceUuid));
|
---|
1077 | } SUPDRVFACTORY;
|
---|
1078 | /** Pointer to a support driver factory. */
|
---|
1079 | typedef SUPDRVFACTORY *PSUPDRVFACTORY;
|
---|
1080 | /** Pointer to a const support driver factory. */
|
---|
1081 | typedef SUPDRVFACTORY const *PCSUPDRVFACTORY;
|
---|
1082 |
|
---|
1083 | SUPR0DECL(int) SUPR0ComponentRegisterFactory(PSUPDRVSESSION pSession, PCSUPDRVFACTORY pFactory);
|
---|
1084 | SUPR0DECL(int) SUPR0ComponentDeregisterFactory(PSUPDRVSESSION pSession, PCSUPDRVFACTORY pFactory);
|
---|
1085 | SUPR0DECL(int) SUPR0ComponentQueryFactory(PSUPDRVSESSION pSession, const char *pszName, const char *pszInterfaceUuid, void **ppvFactoryIf);
|
---|
1086 |
|
---|
1087 |
|
---|
1088 | /**
|
---|
1089 | * Service request callback function.
|
---|
1090 | *
|
---|
1091 | * @returns VBox status code.
|
---|
1092 | * @param pSession The caller's session.
|
---|
1093 | * @param u64Arg 64-bit integer argument.
|
---|
1094 | * @param pReqHdr The request header. Input / Output. Optional.
|
---|
1095 | */
|
---|
1096 | typedef DECLCALLBACK(int) FNSUPR0SERVICEREQHANDLER(PSUPDRVSESSION pSession, uint32_t uOperation,
|
---|
1097 | uint64_t u64Arg, PSUPR0SERVICEREQHDR pReqHdr);
|
---|
1098 | /** Pointer to a FNR0SERVICEREQHANDLER(). */
|
---|
1099 | typedef R0PTRTYPE(FNSUPR0SERVICEREQHANDLER *) PFNSUPR0SERVICEREQHANDLER;
|
---|
1100 |
|
---|
1101 |
|
---|
1102 | /** @defgroup grp_sup_r0_idc The IDC Interface
|
---|
1103 | * @ingroup grp_sup_r0
|
---|
1104 | * @{
|
---|
1105 | */
|
---|
1106 |
|
---|
1107 | /** The current SUPDRV IDC version.
|
---|
1108 | * This follows the usual high word / low word rules, i.e. high word is the
|
---|
1109 | * major number and it signifies incompatible interface changes. */
|
---|
1110 | #define SUPDRV_IDC_VERSION UINT32_C(0x00010000)
|
---|
1111 |
|
---|
1112 | /**
|
---|
1113 | * Inter-Driver Communcation Handle.
|
---|
1114 | */
|
---|
1115 | typedef union SUPDRVIDCHANDLE
|
---|
1116 | {
|
---|
1117 | /** Padding for opaque usage.
|
---|
1118 | * Must be greater or equal in size than the private struct. */
|
---|
1119 | void *apvPadding[4];
|
---|
1120 | #ifdef SUPDRVIDCHANDLEPRIVATE_DECLARED
|
---|
1121 | /** The private view. */
|
---|
1122 | struct SUPDRVIDCHANDLEPRIVATE s;
|
---|
1123 | #endif
|
---|
1124 | } SUPDRVIDCHANDLE;
|
---|
1125 | /** Pointer to a handle. */
|
---|
1126 | typedef SUPDRVIDCHANDLE *PSUPDRVIDCHANDLE;
|
---|
1127 |
|
---|
1128 | SUPR0DECL(int) SUPR0IdcOpen(PSUPDRVIDCHANDLE pHandle, uint32_t uReqVersion, uint32_t uMinVersion,
|
---|
1129 | uint32_t *puSessionVersion, uint32_t *puDriverVersion, uint32_t *puDriverRevision);
|
---|
1130 | SUPR0DECL(int) SUPR0IdcCall(PSUPDRVIDCHANDLE pHandle, uint32_t iReq, void *pvReq, uint32_t cbReq);
|
---|
1131 | SUPR0DECL(int) SUPR0IdcClose(PSUPDRVIDCHANDLE pHandle);
|
---|
1132 | SUPR0DECL(PSUPDRVSESSION) SUPR0IdcGetSession(PSUPDRVIDCHANDLE pHandle);
|
---|
1133 | SUPR0DECL(int) SUPR0IdcComponentRegisterFactory(PSUPDRVIDCHANDLE pHandle, PCSUPDRVFACTORY pFactory);
|
---|
1134 | SUPR0DECL(int) SUPR0IdcComponentDeregisterFactory(PSUPDRVIDCHANDLE pHandle, PCSUPDRVFACTORY pFactory);
|
---|
1135 |
|
---|
1136 | /** @} */
|
---|
1137 |
|
---|
1138 | /** @} */
|
---|
1139 | #endif
|
---|
1140 |
|
---|
1141 | /** @} */
|
---|
1142 |
|
---|
1143 | RT_C_DECLS_END
|
---|
1144 |
|
---|
1145 | #endif
|
---|
1146 |
|
---|