VirtualBox

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

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

r=bird: some cleanup of the cPages change.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use