VirtualBox

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

Last change on this file since 3512 was 3512, checked in by vboxsync, 17 years ago

L4 support CTL codes without Linux ioctl

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