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