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