VirtualBox

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

Last change on this file since 389 was 42, checked in by vboxsync, 18 years ago

Seems the _IO and _IOWR macros has changed.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 16.1 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_RUN_GC */
135#define SUP_IOCTL_FAST_DO_RAW_RUN SUP_CTL_CODE_FAST(64)
136/** Fast path IOCtl: VMMR0_HWACC_RUN_GUEST */
137#define SUP_IOCTL_FAST_DO_HWACC_RUN SUP_CTL_CODE_FAST(65)
138
139
140/*******************************************************************************
141* Structures and Typedefs *
142*******************************************************************************/
143#ifdef __AMD64__
144# pragma pack(8) /* paranoia. */
145#else
146# pragma pack(4) /* paranoia. */
147#endif
148
149#ifndef __WIN__
150/**
151 * Structure used by OSes with less advanced ioctl interfaces, i.e. most
152 * Unix like OSes :-)
153 */
154typedef struct SUPDRVIOCTLDATA
155{
156 void *pvIn;
157 unsigned long cbIn;
158 void *pvOut;
159 unsigned long cbOut;
160
161} SUPDRVIOCTLDATA, *PSUPDRVIOCTLDATA;
162#endif
163
164/** SUP_IOCTL_COOKIE Input. */
165typedef struct SUPCOOKIE_IN
166{
167 /** Magic word. */
168 char szMagic[16];
169 /** The requested version number. */
170 uint32_t u32Version;
171} SUPCOOKIE_IN, *PSUPCOOKIE_IN;
172
173/** SUPCOOKIE_IN magic word. */
174#define SUPCOOKIE_MAGIC "The Magic Word!"
175/** Current interface version. */
176#define SUPDRVIOC_VERSION 0x00030001
177
178/** SUP_IOCTL_COOKIE Output. */
179typedef struct SUPCOOKIE_OUT
180{
181 /** Cookie. */
182 uint32_t u32Cookie;
183 /** Session cookie. */
184 uint32_t u32SessionCookie;
185 /** Interface version. High word(=uint16) is major, low word is minor. */
186 uint32_t u32Version;
187 /** Number of functions available for the SUP_IOCTL_QUERY_FUNCS request. */
188 uint32_t cFunctions;
189 /** Session handle. */
190 PSUPDRVSESSION pSession;
191} SUPCOOKIE_OUT, *PSUPCOOKIE_OUT;
192
193/** SUP_IOCTL_QUERY_FUNCS Input. */
194typedef struct SUPQUERYFUNCS_IN
195{
196 /** Cookie. */
197 uint32_t u32Cookie;
198 /** Session cookie. */
199 uint32_t u32SessionCookie;
200} SUPQUERYFUNCS_IN, *PSUPQUERYFUNCS_IN;
201
202/** Function. */
203typedef struct SUPFUNC
204{
205 /** Name - mangled. */
206 char szName[32];
207 /** Address. */
208 void *pfn;
209} SUPFUNC, *PSUPFUNC;
210
211/** SUP_IOCTL_QUERY_FUNCS Output. */
212typedef struct SUPQUERYFUNCS_OUT
213{
214 /** Number of functions returned. */
215 uint32_t cFunctions;
216 /** Array of functions. */
217 SUPFUNC aFunctions[1];
218} SUPQUERYFUNCS_OUT, *PSUPQUERYFUNCS_OUT;
219
220
221/** SUP_IOCTL_IDT_INSTALL Input. */
222typedef struct SUPIDTINSTALL_IN
223{
224 /** Cookie. */
225 uint32_t u32Cookie;
226 /** Session cookie. */
227 uint32_t u32SessionCookie;
228} SUPIDTINSTALL_IN, *PSUPIDTINSTALL_IN;
229
230/** SUP_IOCTL_IDT_INSTALL Output. */
231typedef struct SUPIDTINSTALL_OUT
232{
233 /** Cookie. */
234 uint8_t u8Idt;
235} SUPIDTINSTALL_OUT, *PSUPIDTINSTALL_OUT;
236
237
238
239/** SUP_IOCTL_IDT_REMOVE Input. */
240typedef struct SUPIDTREMOVE_IN
241{
242 /** Cookie. */
243 uint32_t u32Cookie;
244 /** Session cookie. */
245 uint32_t u32SessionCookie;
246} SUPIDTREMOVE_IN, *PSUPIDTREMOVE_IN;
247
248
249
250/** SUP_IOCTL_PINPAGES Input. */
251typedef struct SUPPINPAGES_IN
252{
253 /** Cookie. */
254 uint32_t u32Cookie;
255 /** Session cookie. */
256 uint32_t u32SessionCookie;
257 /** Start of page range. Must be PAGE aligned. */
258 void *pv;
259 /** Size of the range. Must be PAGE aligned. */
260 uint32_t cb;
261} SUPPINPAGES_IN, *PSUPPINPAGES_IN;
262
263/** SUP_IOCTL_PINPAGES Output. */
264typedef struct SUPPINPAGES_OUT
265{
266 /** Array of pages. */
267 SUPPAGE aPages[1];
268} SUPPINPAGES_OUT, *PSUPPINPAGES_OUT;
269
270
271
272/** SUP_IOCTL_UNPINPAGES Input. */
273typedef struct SUPUNPINPAGES_IN
274{
275 /** Cookie. */
276 uint32_t u32Cookie;
277 /** Session cookie. */
278 uint32_t u32SessionCookie;
279 /** Start of page range of a range previuosly pinned. */
280 void *pv;
281} SUPUNPINPAGES_IN, *PSUPUNPINPAGES_IN;
282
283
284/** SUP_IOCTL_CONT_ALLOC Input. */
285typedef struct SUPCONTALLOC_IN
286{
287 /** Cookie. */
288 uint32_t u32Cookie;
289 /** Session cookie. */
290 uint32_t u32SessionCookie;
291 /** Number of bytes to allocate. */
292 uint32_t cb;
293} SUPCONTALLOC_IN, *PSUPCONTALLOC_IN;
294
295
296/** SUP_IOCTL_CONT_ALLOC Output. */
297typedef struct SUPCONTALLOC_OUT
298{
299 /** The address of the ring-0 mapping of the allocated memory. */
300 void *pvR0;
301 /** The address of the ring-3 mapping of the allocated memory. */
302 void *pvR3;
303 /** The physical address of the allocation. */
304 RTHCPHYS HCPhys;
305} SUPCONTALLOC_OUT, *PSUPCONTALLOC_OUT;
306
307
308/** SUP_IOCTL_CONT_FREE Input. */
309typedef struct SUPCONTFREE_IN
310{
311 /** Cookie. */
312 uint32_t u32Cookie;
313 /** Session cookie. */
314 uint32_t u32SessionCookie;
315 /** The address (virtual, not physical address) of the memory to free. */
316 void *pv;
317} SUPCONTFREE_IN, *PSUPCONTFREE_IN;
318
319
320/** SUP_IOCTL_LDR_OPEN Input. */
321typedef struct SUPLDROPEN_IN
322{
323 /** Cookie. */
324 uint32_t u32Cookie;
325 /** Session cookie. */
326 uint32_t u32SessionCookie;
327 /** Size of the image we'll be loading. */
328 uint32_t cbImage;
329 /** Image name.
330 * This is the NAME of the image, not the file name. It is used
331 * to share code with other processes. (Max len is 32 chars!) */
332 char szName[32];
333} SUPLDROPEN_IN, *PSUPLDROPEN_IN;
334
335/** SUP_IOCTL_LDR_OPEN Output. */
336typedef struct SUPLDROPEN_OUT
337{
338 /** The base address of the image. */
339 void *pvImageBase;
340 /** Indicate whether or not the image requires loading. */
341 bool fNeedsLoading;
342} SUPLDROPEN_OUT, *PSUPLDROPEN_OUT;
343
344
345/**
346 * Module initialization callback function.
347 * This is called once after the module has been loaded.
348 *
349 * @returns 0 on success.
350 * @returns Appropriate error code on failure.
351 */
352typedef DECLCALLBACK(int) FNR0MODULEINIT(void);
353/** Pointer to a FNR0MODULEINIT(). */
354typedef FNR0MODULEINIT *PFNR0MODULEINIT;
355
356/**
357 * Module termination callback function.
358 * This is called once right before the module is being unloaded.
359 */
360typedef DECLCALLBACK(void) FNR0MODULETERM(void);
361/** Pointer to a FNR0MODULETERM(). */
362typedef FNR0MODULETERM *PFNR0MODULETERM;
363
364/**
365 * Symbol table entry.
366 */
367typedef struct SUPLDRSYM
368{
369 /** Offset into of the string table. */
370 uint32_t offName;
371 /** Offset of the symbol relative to the image load address. */
372 uint32_t offSymbol;
373} SUPLDRSYM, *PSUPLDRSYM;
374
375/** SUP_IOCTL_LDR_LOAD Input. */
376typedef struct SUPLDRLOAD_IN
377{
378 /** Cookie. */
379 uint32_t u32Cookie;
380 /** Session cookie. */
381 uint32_t u32SessionCookie;
382 /** The address of module initialization function. Similar to _DLL_InitTerm(hmod, 0). */
383 PFNR0MODULEINIT pfnModuleInit;
384 /** The address of module termination function. Similar to _DLL_InitTerm(hmod, 1). */
385 PFNR0MODULETERM pfnModuleTerm;
386 /** Special entry points. */
387 union
388 {
389 struct
390 {
391 /** The module handle (i.e. address). */
392 void *pvVMMR0;
393 /** Address of VMMR0Entry function. */
394 void *pvVMMR0Entry;
395 } VMMR0;
396 } EP;
397 /** Address. */
398 void *pvImageBase;
399 /** Entry point type. */
400 enum { EP_NOTHING, EP_VMMR0 }
401 eEPType;
402 /** The offset of the symbol table. */
403 uint32_t offSymbols;
404 /** The number of entries in the symbol table. */
405 uint32_t cSymbols;
406 /** The offset of the string table. */
407 uint32_t offStrTab;
408 /** Size of the string table. */
409 uint32_t cbStrTab;
410 /** Size of image (including string and symbol tables). */
411 uint32_t cbImage;
412 /** The image data. */
413 char achImage[1];
414} SUPLDRLOAD_IN, *PSUPLDRLOAD_IN;
415
416
417/** SUP_IOCTL_LDR_FREE Input. */
418typedef struct SUPLDRFREE_IN
419{
420 /** Cookie. */
421 uint32_t u32Cookie;
422 /** Session cookie. */
423 uint32_t u32SessionCookie;
424 /** Address. */
425 void *pvImageBase;
426} SUPLDRFREE_IN, *PSUPLDRFREE_IN;
427
428
429/** SUP_IOCTL_LDR_GET_SYMBOL Input. */
430typedef struct SUPLDRGETSYMBOL_IN
431{
432 /** Cookie. */
433 uint32_t u32Cookie;
434 /** Session cookie. */
435 uint32_t u32SessionCookie;
436 /** Address. */
437 void *pvImageBase;
438 /** The symbol name (variable length). */
439 char szSymbol[1];
440} SUPLDRGETSYMBOL_IN, *PSUPLDRGETSYMBOL_IN;
441
442/** SUP_IOCTL_LDR_GET_SYMBOL Output. */
443typedef struct SUPLDRGETSYMBOL_OUT
444{
445 /** The symbol address. */
446 void *pvSymbol;
447} SUPLDRGETSYMBOL_OUT, *PSUPLDRGETSYMBOL_OUT;
448
449
450/** SUP_IOCTL_CALL_VMMR0 Input. */
451typedef struct SUPCALLVMMR0_IN
452{
453 /** Cookie. */
454 uint32_t u32Cookie;
455 /** Session cookie. */
456 uint32_t u32SessionCookie;
457 /** The VM handle. */
458 PVM pVM;
459 /** Which operation to execute. */
460 uint32_t uOperation;
461 /** The size of the buffer pointed to by pvArg. */
462 uint32_t cbArg;
463 /** Argument to that operation. */
464 void *pvArg;
465} SUPCALLVMMR0_IN, *PSUPCALLVMMR0_IN;
466
467/** SUP_IOCTL_CALL_VMMR0 Output. */
468typedef struct SUPCALLVMMR0_OUT
469{
470 /** The VBox status code for the operation. */
471 int32_t rc;
472} SUPCALLVMMR0_OUT, *PSUPCALLVMMR0_OUT;
473
474
475/** SUP_IOCTL_GET_PAGING_MODE Input. */
476typedef struct SUPGETPAGINGMODE_IN
477{
478 /** Cookie. */
479 uint32_t u32Cookie;
480 /** Session cookie. */
481 uint32_t u32SessionCookie;
482} SUPGETPAGINGMODE_IN, *PSUPGETPAGINGMODE_IN;
483
484/** SUP_IOCTL_GET_PAGING_MODE Output. */
485typedef struct SUPGETPAGINGMODE_OUT
486{
487 /** The paging mode. */
488 SUPPAGINGMODE enmMode;
489} SUPGETPAGINGMODE_OUT, *PSUPGETPAGINGMODE_OUT;
490
491
492/** SUP_IOCTL_LOW_ALLOC Input. */
493typedef struct SUPLOWALLOC_IN
494{
495 /** Cookie. */
496 uint32_t u32Cookie;
497 /** Session cookie. */
498 uint32_t u32SessionCookie;
499 /** Number of pages to allocate. */
500 uint32_t cPages;
501} SUPLOWALLOC_IN, *PSUPLOWALLOC_IN;
502
503/** SUP_IOCTL_LOW_ALLOC Output. */
504typedef struct SUPLOWALLOC_OUT
505{
506 /** The address (virtual & linear) of the allocated memory. */
507 void *pvVirt;
508 /** Array of pages. */
509 SUPPAGE aPages[1];
510} SUPLOWALLOC_OUT, *PSUPLOWALLOC_OUT;
511
512
513/** SUP_IOCTL_LOW_FREE Input. */
514typedef struct SUPLOWFREE_IN
515{
516 /** Cookie. */
517 uint32_t u32Cookie;
518 /** Session cookie. */
519 uint32_t u32SessionCookie;
520 /** The address (virtual, not physical address) of the memory to free. */
521 void *pv;
522} SUPLOWFREE_IN, *PSUPLOWFREE_IN;
523
524
525/** SUP_IOCTL_GIP_MAP Input. */
526typedef struct SUPGIPMAP_IN
527{
528 /** Cookie. */
529 uint32_t u32Cookie;
530 /** Session cookie. */
531 uint32_t u32SessionCookie;
532} SUPGIPMAP_IN, *PSUPGIPMAP_IN;
533
534/** SUP_IOCTL_GIP_MAP Output. */
535typedef struct SUPGIPMAP_OUT
536{
537 /** Pointer to the read-only usermode GIP mapping for this session. */
538 PCSUPGLOBALINFOPAGE pGipR3;
539 /** Pointer to the supervisor mode GIP mapping. */
540 PCSUPGLOBALINFOPAGE pGipR0;
541 /** The physical address of the GIP. */
542 RTHCPHYS HCPhysGip;
543} SUPGIPMAP_OUT, *PSUPGIPMAP_OUT;
544
545
546/** SUP_IOCTL_GIP_UNMAP Input. */
547typedef struct SUPGIPUNMAP_IN
548{
549 /** Cookie. */
550 uint32_t u32Cookie;
551 /** Session cookie. */
552 uint32_t u32SessionCookie;
553} SUPGIPUNMAP_IN, *PSUPGIPUNMAP_IN;
554
555
556/** SUP_IOCTL_SET_VM_FOR_FAST Input. */
557typedef struct SUPSETVMFORFAST_IN
558{
559 /** Cookie. */
560 uint32_t u32Cookie;
561 /** Session cookie. */
562 uint32_t u32SessionCookie;
563 /** The ring-0 VM handle (pointer). */
564 PVMR0 pVMR0;
565} SUPSETVMFORFAST_IN, *PSUPSETVMFORFAST_IN;
566
567#pragma pack() /* paranoia */
568
569#endif
570
Note: See TracBrowser for help on using the repository browser.

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