VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/Support/SUPDRVIOC.h@ 674

Last change on this file since 674 was 397, checked in by vboxsync, 18 years ago

Completed most of VBOX_WITHOUT_IDT_PATCHING. (hope I didn't break anything...) TODO: IST support on AMD64.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 16.2 KB
Line 
1/** @file
2 *
3 * VBox host drivers - Ring-0 support drivers - Shared code:
4 * IOCtl definitions
5 */
6
7/*
8 * Copyright (C) 2006 InnoTek Systemberatung GmbH
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License as published by the Free Software Foundation,
14 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
15 * distribution. VirtualBox OSE is distributed in the hope that it will
16 * be useful, but WITHOUT ANY WARRANTY of any kind.
17 *
18 * If you received this file as part of a commercial VirtualBox
19 * distribution, then only the terms of your commercial VirtualBox
20 * license agreement apply instead of the previous paragraph.
21 */
22
23#ifndef __SUPDRVIOC_h__
24#define __SUPDRVIOC_h__
25
26/*
27 * Basic types.
28 */
29#include <iprt/stdint.h>
30
31/*
32 * IOCtl numbers.
33 * We're using the Win32 type of numbers here, thus the macros below.
34 * The SUP_IOCTL_FLAG macro is used to separate requests from 32-bit
35 * and 64-bit processes.
36 */
37#ifdef __AMD64__
38# define SUP_IOCTL_FLAG 128
39#elif defined(__X86__)
40# define SUP_IOCTL_FLAG 0
41#else
42# error "dunno which arch this is!"
43#endif
44
45#ifdef __WIN__
46# define SUP_CTL_CODE(Function) CTL_CODE(FILE_DEVICE_UNKNOWN, (Function) | SUP_IOCTL_FLAG, METHOD_BUFFERED, FILE_WRITE_ACCESS)
47# define SUP_CTL_CODE_FAST(Function) CTL_CODE(FILE_DEVICE_UNKNOWN, (Function) | SUP_IOCTL_FLAG, METHOD_NEITHER, FILE_WRITE_ACCESS)
48
49/** @todo get rid of this duplication of window header #defines! */
50# ifndef CTL_CODE
51# define CTL_CODE(DeviceType, Function, Method, Access) \
52 ( ((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) )
53# endif
54# ifndef METHOD_BUFFERED
55# define METHOD_BUFFERED 0
56# endif
57# ifndef METHOD_NEITHER
58# define METHOD_NEITHER 3
59# endif
60# ifndef FILE_WRITE_ACCESS
61# define FILE_WRITE_ACCESS 0x0002
62# endif
63# ifndef FILE_DEVICE_UNKNOWN
64# define FILE_DEVICE_UNKNOWN 0x00000022
65# endif
66
67#elif defined(__OS2__)
68# define SUP_CTL_CATEGORY ((unsigned short)'V')
69# define SUP_CTL_CODE(Function) ((unsigned short)(Function))
70
71#elif defined(__LINUX__) || defined(__L4__)
72# ifdef __X86__ /** @todo With the next major version change, drop this branch. */
73# define SUP_CTL_CODE(Function) \
74 ( (3U << 30) | ((0x22) << 8) | ((Function) | SUP_IOCTL_FLAG) | (sizeof(SUPDRVIOCTLDATA) << 16) )
75# define SUP_CTL_CODE_FAST(Function) \
76 ( (3U << 30) | ((0x22) << 8) | ((Function) | SUP_IOCTL_FLAG) | (0 << 16) )
77# else
78# include <linux/ioctl.h>
79# if 1 /* figure out when this changed. */
80# define SUP_CTL_CODE(Function) _IOWR('V', (Function) | SUP_IOCTL_FLAG, SUPDRVIOCTLDATA)
81# define SUP_CTL_CODE_FAST(Function) _IO( 'V', (Function) | SUP_IOCTL_FLAG)
82# else /* now: _IO_BAD and _IOWR_BAD */
83# define SUP_CTL_CODE(Function) _IOWR('V', (Function) | SUP_IOCTL_FLAG, sizeof(SUPDRVIOCTLDATA))
84# define SUP_CTL_CODE_FAST(Function) _IO( 'V', (Function) | SUP_IOCTL_FLAG)
85# endif
86# endif
87
88#else /* BSD */
89# include <sys/ioccom.h>
90# define SUP_CTL_CODE(Function) _IOWR('V', (Function) | SUP_IOCTL_FLAG, SUPDRVIOCTLDATA)
91# define SUP_CTL_CODE_FAST(Function) _IO( 'V', (Function) | SUP_IOCTL_FLAG)
92#endif
93
94
95/** Negotiate cookie. */
96#define SUP_IOCTL_COOKIE SUP_CTL_CODE( 1)
97/** Query SUPR0 functions. */
98#define SUP_IOCTL_QUERY_FUNCS SUP_CTL_CODE( 2)
99/** Install IDT patch for calling processor. */
100#define SUP_IOCTL_IDT_INSTALL SUP_CTL_CODE( 3)
101/** Remove IDT patch for calling processor. */
102#define SUP_IOCTL_IDT_REMOVE SUP_CTL_CODE( 4)
103/** Pin down physical pages. */
104#define SUP_IOCTL_PINPAGES SUP_CTL_CODE( 5)
105/** Unpin physical pages. */
106#define SUP_IOCTL_UNPINPAGES SUP_CTL_CODE( 6)
107/** Allocate contious memory. */
108#define SUP_IOCTL_CONT_ALLOC SUP_CTL_CODE( 7)
109/** Free contious memory. */
110#define SUP_IOCTL_CONT_FREE SUP_CTL_CODE( 8)
111/** Open an image. */
112#define SUP_IOCTL_LDR_OPEN SUP_CTL_CODE( 9)
113/** Upload the image bits. */
114#define SUP_IOCTL_LDR_LOAD SUP_CTL_CODE(10)
115/** Free an image. */
116#define SUP_IOCTL_LDR_FREE SUP_CTL_CODE(11)
117/** Get address of a symbol within an image. */
118#define SUP_IOCTL_LDR_GET_SYMBOL SUP_CTL_CODE(12)
119/** Call the R0 VMM Entry point. */
120#define SUP_IOCTL_CALL_VMMR0 SUP_CTL_CODE(14)
121/** Get the host paging mode. */
122#define SUP_IOCTL_GET_PAGING_MODE SUP_CTL_CODE(15)
123/** Allocate memory below 4GB (physically). */
124#define SUP_IOCTL_LOW_ALLOC SUP_CTL_CODE(16)
125/** Free low memory. */
126#define SUP_IOCTL_LOW_FREE SUP_CTL_CODE(17)
127/** Map the GIP into user space. */
128#define SUP_IOCTL_GIP_MAP SUP_CTL_CODE(18)
129/** Unmap the GIP. */
130#define SUP_IOCTL_GIP_UNMAP SUP_CTL_CODE(19)
131/** Set the VM handle for doing fast call ioctl calls. */
132#define SUP_IOCTL_SET_VM_FOR_FAST SUP_CTL_CODE(20)
133
134/** Fast path IOCtl: VMMR0_DO_RAW_RUN */
135#define SUP_IOCTL_FAST_DO_RAW_RUN SUP_CTL_CODE_FAST(64)
136/** Fast path IOCtl: VMMR0_DO_HWACC_RUN */
137#define SUP_IOCTL_FAST_DO_HWACC_RUN SUP_CTL_CODE_FAST(65)
138/** Just a NOP call for profiling the latency of a fast ioctl call to VMMR0. */
139#define SUP_IOCTL_FAST_DO_NOP SUP_CTL_CODE_FAST(66)
140
141
142/*******************************************************************************
143* Structures and Typedefs *
144*******************************************************************************/
145#ifdef __AMD64__
146# pragma pack(8) /* paranoia. */
147#else
148# pragma pack(4) /* paranoia. */
149#endif
150
151#ifndef __WIN__
152/**
153 * Structure used by OSes with less advanced ioctl interfaces, i.e. most
154 * Unix like OSes :-)
155 */
156typedef struct SUPDRVIOCTLDATA
157{
158 void *pvIn;
159 unsigned long cbIn;
160 void *pvOut;
161 unsigned long cbOut;
162
163} SUPDRVIOCTLDATA, *PSUPDRVIOCTLDATA;
164#endif
165
166/** SUP_IOCTL_COOKIE Input. */
167typedef struct SUPCOOKIE_IN
168{
169 /** Magic word. */
170 char szMagic[16];
171 /** The requested version number. */
172 uint32_t u32Version;
173} SUPCOOKIE_IN, *PSUPCOOKIE_IN;
174
175/** SUPCOOKIE_IN magic word. */
176#define SUPCOOKIE_MAGIC "The Magic Word!"
177/** Current interface version. */
178#define SUPDRVIOC_VERSION 0x00030001
179
180/** SUP_IOCTL_COOKIE Output. */
181typedef struct SUPCOOKIE_OUT
182{
183 /** Cookie. */
184 uint32_t u32Cookie;
185 /** Session cookie. */
186 uint32_t u32SessionCookie;
187 /** Interface version. High word(=uint16) is major, low word is minor. */
188 uint32_t u32Version;
189 /** Number of functions available for the SUP_IOCTL_QUERY_FUNCS request. */
190 uint32_t cFunctions;
191 /** Session handle. */
192 PSUPDRVSESSION pSession;
193} SUPCOOKIE_OUT, *PSUPCOOKIE_OUT;
194
195/** SUP_IOCTL_QUERY_FUNCS Input. */
196typedef struct SUPQUERYFUNCS_IN
197{
198 /** Cookie. */
199 uint32_t u32Cookie;
200 /** Session cookie. */
201 uint32_t u32SessionCookie;
202} SUPQUERYFUNCS_IN, *PSUPQUERYFUNCS_IN;
203
204/** Function. */
205typedef struct SUPFUNC
206{
207 /** Name - mangled. */
208 char szName[32];
209 /** Address. */
210 void *pfn;
211} SUPFUNC, *PSUPFUNC;
212
213/** SUP_IOCTL_QUERY_FUNCS Output. */
214typedef struct SUPQUERYFUNCS_OUT
215{
216 /** Number of functions returned. */
217 uint32_t cFunctions;
218 /** Array of functions. */
219 SUPFUNC aFunctions[1];
220} SUPQUERYFUNCS_OUT, *PSUPQUERYFUNCS_OUT;
221
222
223/** SUP_IOCTL_IDT_INSTALL Input. */
224typedef struct SUPIDTINSTALL_IN
225{
226 /** Cookie. */
227 uint32_t u32Cookie;
228 /** Session cookie. */
229 uint32_t u32SessionCookie;
230} SUPIDTINSTALL_IN, *PSUPIDTINSTALL_IN;
231
232/** SUP_IOCTL_IDT_INSTALL Output. */
233typedef struct SUPIDTINSTALL_OUT
234{
235 /** Cookie. */
236 uint8_t u8Idt;
237} SUPIDTINSTALL_OUT, *PSUPIDTINSTALL_OUT;
238
239
240
241/** SUP_IOCTL_IDT_REMOVE Input. */
242typedef struct SUPIDTREMOVE_IN
243{
244 /** Cookie. */
245 uint32_t u32Cookie;
246 /** Session cookie. */
247 uint32_t u32SessionCookie;
248} SUPIDTREMOVE_IN, *PSUPIDTREMOVE_IN;
249
250
251
252/** SUP_IOCTL_PINPAGES Input. */
253typedef struct SUPPINPAGES_IN
254{
255 /** Cookie. */
256 uint32_t u32Cookie;
257 /** Session cookie. */
258 uint32_t u32SessionCookie;
259 /** Start of page range. Must be PAGE aligned. */
260 void *pv;
261 /** Size of the range. Must be PAGE aligned. */
262 uint32_t cb;
263} SUPPINPAGES_IN, *PSUPPINPAGES_IN;
264
265/** SUP_IOCTL_PINPAGES Output. */
266typedef struct SUPPINPAGES_OUT
267{
268 /** Array of pages. */
269 SUPPAGE aPages[1];
270} SUPPINPAGES_OUT, *PSUPPINPAGES_OUT;
271
272
273
274/** SUP_IOCTL_UNPINPAGES Input. */
275typedef struct SUPUNPINPAGES_IN
276{
277 /** Cookie. */
278 uint32_t u32Cookie;
279 /** Session cookie. */
280 uint32_t u32SessionCookie;
281 /** Start of page range of a range previuosly pinned. */
282 void *pv;
283} SUPUNPINPAGES_IN, *PSUPUNPINPAGES_IN;
284
285
286/** SUP_IOCTL_CONT_ALLOC Input. */
287typedef struct SUPCONTALLOC_IN
288{
289 /** Cookie. */
290 uint32_t u32Cookie;
291 /** Session cookie. */
292 uint32_t u32SessionCookie;
293 /** Number of bytes to allocate. */
294 uint32_t cb;
295} SUPCONTALLOC_IN, *PSUPCONTALLOC_IN;
296
297
298/** SUP_IOCTL_CONT_ALLOC Output. */
299typedef struct SUPCONTALLOC_OUT
300{
301 /** The address of the ring-0 mapping of the allocated memory. */
302 void *pvR0;
303 /** The address of the ring-3 mapping of the allocated memory. */
304 void *pvR3;
305 /** The physical address of the allocation. */
306 RTHCPHYS HCPhys;
307} SUPCONTALLOC_OUT, *PSUPCONTALLOC_OUT;
308
309
310/** SUP_IOCTL_CONT_FREE Input. */
311typedef struct SUPCONTFREE_IN
312{
313 /** Cookie. */
314 uint32_t u32Cookie;
315 /** Session cookie. */
316 uint32_t u32SessionCookie;
317 /** The address (virtual, not physical address) of the memory to free. */
318 void *pv;
319} SUPCONTFREE_IN, *PSUPCONTFREE_IN;
320
321
322/** SUP_IOCTL_LDR_OPEN Input. */
323typedef struct SUPLDROPEN_IN
324{
325 /** Cookie. */
326 uint32_t u32Cookie;
327 /** Session cookie. */
328 uint32_t u32SessionCookie;
329 /** Size of the image we'll be loading. */
330 uint32_t cbImage;
331 /** Image name.
332 * This is the NAME of the image, not the file name. It is used
333 * to share code with other processes. (Max len is 32 chars!) */
334 char szName[32];
335} SUPLDROPEN_IN, *PSUPLDROPEN_IN;
336
337/** SUP_IOCTL_LDR_OPEN Output. */
338typedef struct SUPLDROPEN_OUT
339{
340 /** The base address of the image. */
341 void *pvImageBase;
342 /** Indicate whether or not the image requires loading. */
343 bool fNeedsLoading;
344} SUPLDROPEN_OUT, *PSUPLDROPEN_OUT;
345
346
347/**
348 * Module initialization callback function.
349 * This is called once after the module has been loaded.
350 *
351 * @returns 0 on success.
352 * @returns Appropriate error code on failure.
353 */
354typedef DECLCALLBACK(int) FNR0MODULEINIT(void);
355/** Pointer to a FNR0MODULEINIT(). */
356typedef FNR0MODULEINIT *PFNR0MODULEINIT;
357
358/**
359 * Module termination callback function.
360 * This is called once right before the module is being unloaded.
361 */
362typedef DECLCALLBACK(void) FNR0MODULETERM(void);
363/** Pointer to a FNR0MODULETERM(). */
364typedef FNR0MODULETERM *PFNR0MODULETERM;
365
366/**
367 * Symbol table entry.
368 */
369typedef struct SUPLDRSYM
370{
371 /** Offset into of the string table. */
372 uint32_t offName;
373 /** Offset of the symbol relative to the image load address. */
374 uint32_t offSymbol;
375} SUPLDRSYM, *PSUPLDRSYM;
376
377/** SUP_IOCTL_LDR_LOAD Input. */
378typedef struct SUPLDRLOAD_IN
379{
380 /** Cookie. */
381 uint32_t u32Cookie;
382 /** Session cookie. */
383 uint32_t u32SessionCookie;
384 /** The address of module initialization function. Similar to _DLL_InitTerm(hmod, 0). */
385 PFNR0MODULEINIT pfnModuleInit;
386 /** The address of module termination function. Similar to _DLL_InitTerm(hmod, 1). */
387 PFNR0MODULETERM pfnModuleTerm;
388 /** Special entry points. */
389 union
390 {
391 struct
392 {
393 /** The module handle (i.e. address). */
394 void *pvVMMR0;
395 /** Address of VMMR0Entry function. */
396 void *pvVMMR0Entry;
397 } VMMR0;
398 } EP;
399 /** Address. */
400 void *pvImageBase;
401 /** Entry point type. */
402 enum { EP_NOTHING, EP_VMMR0 }
403 eEPType;
404 /** The offset of the symbol table. */
405 uint32_t offSymbols;
406 /** The number of entries in the symbol table. */
407 uint32_t cSymbols;
408 /** The offset of the string table. */
409 uint32_t offStrTab;
410 /** Size of the string table. */
411 uint32_t cbStrTab;
412 /** Size of image (including string and symbol tables). */
413 uint32_t cbImage;
414 /** The image data. */
415 char achImage[1];
416} SUPLDRLOAD_IN, *PSUPLDRLOAD_IN;
417
418
419/** SUP_IOCTL_LDR_FREE Input. */
420typedef struct SUPLDRFREE_IN
421{
422 /** Cookie. */
423 uint32_t u32Cookie;
424 /** Session cookie. */
425 uint32_t u32SessionCookie;
426 /** Address. */
427 void *pvImageBase;
428} SUPLDRFREE_IN, *PSUPLDRFREE_IN;
429
430
431/** SUP_IOCTL_LDR_GET_SYMBOL Input. */
432typedef struct SUPLDRGETSYMBOL_IN
433{
434 /** Cookie. */
435 uint32_t u32Cookie;
436 /** Session cookie. */
437 uint32_t u32SessionCookie;
438 /** Address. */
439 void *pvImageBase;
440 /** The symbol name (variable length). */
441 char szSymbol[1];
442} SUPLDRGETSYMBOL_IN, *PSUPLDRGETSYMBOL_IN;
443
444/** SUP_IOCTL_LDR_GET_SYMBOL Output. */
445typedef struct SUPLDRGETSYMBOL_OUT
446{
447 /** The symbol address. */
448 void *pvSymbol;
449} SUPLDRGETSYMBOL_OUT, *PSUPLDRGETSYMBOL_OUT;
450
451
452/** SUP_IOCTL_CALL_VMMR0 Input. */
453typedef struct SUPCALLVMMR0_IN
454{
455 /** Cookie. */
456 uint32_t u32Cookie;
457 /** Session cookie. */
458 uint32_t u32SessionCookie;
459 /** The VM handle. */
460 PVM pVM;
461 /** Which operation to execute. */
462 uint32_t uOperation;
463 /** The size of the buffer pointed to by pvArg. */
464 uint32_t cbArg;
465 /** Argument to that operation. */
466 void *pvArg;
467} SUPCALLVMMR0_IN, *PSUPCALLVMMR0_IN;
468
469/** SUP_IOCTL_CALL_VMMR0 Output. */
470typedef struct SUPCALLVMMR0_OUT
471{
472 /** The VBox status code for the operation. */
473 int32_t rc;
474} SUPCALLVMMR0_OUT, *PSUPCALLVMMR0_OUT;
475
476
477/** SUP_IOCTL_GET_PAGING_MODE Input. */
478typedef struct SUPGETPAGINGMODE_IN
479{
480 /** Cookie. */
481 uint32_t u32Cookie;
482 /** Session cookie. */
483 uint32_t u32SessionCookie;
484} SUPGETPAGINGMODE_IN, *PSUPGETPAGINGMODE_IN;
485
486/** SUP_IOCTL_GET_PAGING_MODE Output. */
487typedef struct SUPGETPAGINGMODE_OUT
488{
489 /** The paging mode. */
490 SUPPAGINGMODE enmMode;
491} SUPGETPAGINGMODE_OUT, *PSUPGETPAGINGMODE_OUT;
492
493
494/** SUP_IOCTL_LOW_ALLOC Input. */
495typedef struct SUPLOWALLOC_IN
496{
497 /** Cookie. */
498 uint32_t u32Cookie;
499 /** Session cookie. */
500 uint32_t u32SessionCookie;
501 /** Number of pages to allocate. */
502 uint32_t cPages;
503} SUPLOWALLOC_IN, *PSUPLOWALLOC_IN;
504
505/** SUP_IOCTL_LOW_ALLOC Output. */
506typedef struct SUPLOWALLOC_OUT
507{
508 /** The address (virtual & linear) of the allocated memory. */
509 void *pvVirt;
510 /** Array of pages. */
511 SUPPAGE aPages[1];
512} SUPLOWALLOC_OUT, *PSUPLOWALLOC_OUT;
513
514
515/** SUP_IOCTL_LOW_FREE Input. */
516typedef struct SUPLOWFREE_IN
517{
518 /** Cookie. */
519 uint32_t u32Cookie;
520 /** Session cookie. */
521 uint32_t u32SessionCookie;
522 /** The address (virtual, not physical address) of the memory to free. */
523 void *pv;
524} SUPLOWFREE_IN, *PSUPLOWFREE_IN;
525
526
527/** SUP_IOCTL_GIP_MAP Input. */
528typedef struct SUPGIPMAP_IN
529{
530 /** Cookie. */
531 uint32_t u32Cookie;
532 /** Session cookie. */
533 uint32_t u32SessionCookie;
534} SUPGIPMAP_IN, *PSUPGIPMAP_IN;
535
536/** SUP_IOCTL_GIP_MAP Output. */
537typedef struct SUPGIPMAP_OUT
538{
539 /** Pointer to the read-only usermode GIP mapping for this session. */
540 PCSUPGLOBALINFOPAGE pGipR3;
541 /** Pointer to the supervisor mode GIP mapping. */
542 PCSUPGLOBALINFOPAGE pGipR0;
543 /** The physical address of the GIP. */
544 RTHCPHYS HCPhysGip;
545} SUPGIPMAP_OUT, *PSUPGIPMAP_OUT;
546
547
548/** SUP_IOCTL_GIP_UNMAP Input. */
549typedef struct SUPGIPUNMAP_IN
550{
551 /** Cookie. */
552 uint32_t u32Cookie;
553 /** Session cookie. */
554 uint32_t u32SessionCookie;
555} SUPGIPUNMAP_IN, *PSUPGIPUNMAP_IN;
556
557
558/** SUP_IOCTL_SET_VM_FOR_FAST Input. */
559typedef struct SUPSETVMFORFAST_IN
560{
561 /** Cookie. */
562 uint32_t u32Cookie;
563 /** Session cookie. */
564 uint32_t u32SessionCookie;
565 /** The ring-0 VM handle (pointer). */
566 PVMR0 pVMR0;
567} SUPSETVMFORFAST_IN, *PSUPSETVMFORFAST_IN;
568
569#pragma pack() /* paranoia */
570
571#endif
572
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette