1 
2 /*--------------------------------------------------------------------*/
3 /*--- Linux-specific kernel interface.                 vki-linux.h ---*/
4 /*--------------------------------------------------------------------*/
5 
6 /*
7    This file is part of Valgrind, a dynamic binary instrumentation
8    framework.
9 
10    Copyright (C) 2000-2013 Julian Seward
11       jseward@acm.org
12 
13    This program is free software; you can redistribute it and/or
14    modify it under the terms of the GNU General Public License as
15    published by the Free Software Foundation; either version 2 of the
16    License, or (at your option) any later version.
17 
18    This program is distributed in the hope that it will be useful, but
19    WITHOUT ANY WARRANTY; without even the implied warranty of
20    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21    General Public License for more details.
22 
23    You should have received a copy of the GNU General Public License
24    along with this program; if not, write to the Free Software
25    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
26    02111-1307, USA.
27 
28    The GNU General Public License is contained in the file COPYING.
29 */
30 
31 /* This file defines types and constants for the kernel interface, and to
32    make that clear everything is prefixed VKI_/vki_.
33 
34    All code is copied verbatim from kernel source files, except that:
35    - VKI_/vki_ prefixes are added
36    - some extra explanatory comments are included;  they are all within
37      "[[ ]]"
38    - for some types, we only care about the size;  for a few of them (big
39      ones that are painful to fully drag in here), a VKI_SIZEOF_* constant
40      is used.
41 
42    The files the code is taken from is indicated.
43 
44    Note especially that the types are not the glibc versions, many of which
45    are different to those in here.
46 
47    Also note that this file contains all the generic header info, ie. that
48    from linux/include/linux/ *.h.  The arch-specific header info, eg. that
49    from linux/include/asm-i386/ *.h, is in vki-$PLATFORM.h and
50    vki_posixtypes-$PLATFORM.h.  (Two files are required to avoid
51    circular dependencies between the generic VKI header and the
52    arch-specific VKI header.  It's possible in the future, as more stuff
53    gets pulled in, that we might have to split files up some more to avoid
54    further circular dependencies.)
55 
56    Finally, note that it is assumed that __KERNEL__ is set for all these
57    definitions, which affects some of them.
58 */
59 
60 /* The structure is (aiui, jrs 20060504):
61 
62      #include plat-specific posix types (vki-posixtypes-ARCH-linux.h)
63 
64      Lots more types, structs, consts, in this file
65 
66      #include other plat-specific stuff (vki-ARCH-linux.h)
67 
68      Even more types, structs, consts, in this file
69 
70    The system call numbers are dealt with by
71    pub_{core,tool}_vkiscnums.h, not via pub_{core,tool}_vki.h, which
72    is what this file is part of.
73 */
74 
75 #ifndef __VKI_LINUX_H
76 #define __VKI_LINUX_H
77 
78 //----------------------------------------------------------------------
79 // Arch-specific POSIX types
80 //----------------------------------------------------------------------
81 
82 #if defined(VGA_x86)
83 #  include "vki-posixtypes-x86-linux.h"
84 #elif defined(VGA_amd64)
85 #  include "vki-posixtypes-amd64-linux.h"
86 #elif defined(VGA_ppc32)
87 #  include "vki-posixtypes-ppc32-linux.h"
88 #elif defined(VGA_ppc64be) || defined(VGA_ppc64le)
89 #  include "vki-posixtypes-ppc64-linux.h"
90 #elif defined(VGA_arm)
91 #  include "vki-posixtypes-arm-linux.h"
92 #elif defined(VGA_arm64)
93 #  include "vki-posixtypes-arm64-linux.h"
94 #elif defined(VGA_s390x)
95 #  include "vki-posixtypes-s390x-linux.h"
96 #elif defined(VGA_mips32)
97 #  include "vki-posixtypes-mips32-linux.h"
98 #elif defined(VGA_mips64)
99 #  include "vki-posixtypes-mips64-linux.h"
100 #elif defined(VGA_tilegx)
101 #  include "vki-posixtypes-tilegx-linux.h"
102 #else
103 #  error Unknown platform
104 #endif
105 
106 //----------------------------------------------------------------------
107 // VKI_STATIC_ASSERT(). Inspired by BUILD_BUG_ON() from
108 // linux-2.6.34/include/linux/kernel.h
109 //----------------------------------------------------------------------
110 
111 /*
112  * Evaluates to zero if 'expr' is true and forces a compilation error if
113  * 'expr' is false. Can be used in a context where no comma expressions
114  * are allowed.
115  */
116 #ifdef __cplusplus
117 template <bool b> struct vki_static_assert { int m_bitfield:(2*b-1); };
118 #define VKI_STATIC_ASSERT(expr)                         \
119     (sizeof(vki_static_assert<(expr)>) - sizeof(int))
120 #else
121 #define VKI_STATIC_ASSERT(expr) (sizeof(struct { int:-!(expr); }))
122 #endif
123 
124 //----------------------------------------------------------------------
125 // Based on _IOC_TYPECHECK() from linux-2.6.34/asm-generic/ioctl.h
126 //----------------------------------------------------------------------
127 
128 /* provoke compile error for invalid uses of size argument */
129 #define _VKI_IOC_TYPECHECK(t)                                           \
130     (VKI_STATIC_ASSERT((sizeof(t) == sizeof(t[1])                       \
131                         && sizeof(t) < (1 << _VKI_IOC_SIZEBITS)))       \
132      + sizeof(t))
133 
134 //----------------------------------------------------------------------
135 // From linux-2.6.8.1/include/linux/compiler.h
136 //----------------------------------------------------------------------
137 
138 # define __user
139 
140 //----------------------------------------------------------------------
141 // From linux/include/linux/compiler-gcc.h
142 //----------------------------------------------------------------------
143 
144 #ifdef __GNUC__
145 #define __vki_packed			__attribute__((packed))
146 #endif
147 
148 //----------------------------------------------------------------------
149 // From linux-2.6.8.1/include/linux/posix_types.h
150 //----------------------------------------------------------------------
151 
152 #undef __VKI_NFDBITS
153 #define __VKI_NFDBITS	(8 * sizeof(unsigned long))
154 
155 #undef __VKI_FD_SETSIZE
156 #define __VKI_FD_SETSIZE	1024
157 
158 #undef __VKI_FDSET_LONGS
159 #define __VKI_FDSET_LONGS	(__VKI_FD_SETSIZE/__VKI_NFDBITS)
160 
161 #undef __VKI_FDELT
162 #define	__VKI_FDELT(d)	((d) / __VKI_NFDBITS)
163 
164 #undef __VKI_FDMASK
165 #define	__VKI_FDMASK(d)	(1UL << ((d) % __VKI_NFDBITS))
166 
167 typedef struct {
168 	unsigned long fds_bits [__VKI_FDSET_LONGS];
169 } __vki_kernel_fd_set;
170 
171 typedef int __vki_kernel_key_t;
172 typedef int __vki_kernel_mqd_t;
173 
174 //----------------------------------------------------------------------
175 // From linux-2.6.8.1/include/linux/types.h
176 //----------------------------------------------------------------------
177 
178 typedef __vki_kernel_fd_set	vki_fd_set;
179 typedef __vki_kernel_mode_t	vki_mode_t;
180 typedef __vki_kernel_off_t	vki_off_t;
181 typedef __vki_kernel_pid_t	vki_pid_t;
182 typedef __vki_kernel_key_t	vki_key_t;
183 typedef __vki_kernel_suseconds_t	vki_suseconds_t;
184 typedef __vki_kernel_timer_t	vki_timer_t;
185 typedef __vki_kernel_clockid_t	vki_clockid_t;
186 typedef __vki_kernel_mqd_t	vki_mqd_t;
187 
188 // [[Nb: it's a bit unclear due to a #ifdef, but I think this is right. --njn]]
189 typedef __vki_kernel_uid32_t	vki_uid_t;
190 typedef __vki_kernel_gid32_t	vki_gid_t;
191 
192 typedef __vki_kernel_old_uid_t	vki_old_uid_t;
193 typedef __vki_kernel_old_gid_t	vki_old_gid_t;
194 
195 typedef __vki_kernel_loff_t	vki_loff_t;
196 
197 typedef __vki_kernel_size_t	vki_size_t;
198 typedef __vki_kernel_time_t	vki_time_t;
199 typedef __vki_kernel_clock_t	vki_clock_t;
200 typedef __vki_kernel_caddr_t	vki_caddr_t;
201 
202 typedef unsigned long           vki_u_long;
203 
204 typedef unsigned int	        vki_uint;
205 
206 //----------------------------------------------------------------------
207 // Now the rest of the arch-specific stuff
208 //----------------------------------------------------------------------
209 
210 #if defined(VGA_x86)
211 #  include "vki-x86-linux.h"
212 #elif defined(VGA_amd64)
213 #  include "vki-amd64-linux.h"
214 #elif defined(VGA_ppc32)
215 #  include "vki-ppc32-linux.h"
216 #elif defined(VGA_ppc64be) || defined(VGA_ppc64le)
217 #  include "vki-ppc64-linux.h"
218 #elif defined(VGA_arm)
219 #  include "vki-arm-linux.h"
220 #elif defined(VGA_arm64)
221 #  include "vki-arm64-linux.h"
222 #elif defined(VGA_s390x)
223 #  include "vki-s390x-linux.h"
224 #elif defined(VGA_mips32)
225 #  include "vki-mips32-linux.h"
226 #elif defined(VGA_mips64)
227 #  include "vki-mips64-linux.h"
228 #elif defined(VGA_tilegx)
229 #  include "vki-tilegx-linux.h"
230 #else
231 #  error Unknown platform
232 #endif
233 
234 //----------------------------------------------------------------------
235 // From linux-2.6.20.1/include/linux/types.h
236 //----------------------------------------------------------------------
237 
238 typedef		__vki_s32	vki_int32_t;
239 typedef		__vki_s16	vki_int16_t;
240 typedef		__vki_s64	vki_int64_t;
241 
242 typedef		__vki_u8	vki_uint8_t;
243 typedef		__vki_u16	vki_uint16_t;
244 typedef		__vki_u32	vki_uint32_t;
245 typedef		__vki_u64	vki_uint64_t;
246 
247 typedef		__vki_u16	__vki_le16;
248 
249 //----------------------------------------------------------------------
250 // From linux-2.6.8.1/include/linux/limits.h
251 //----------------------------------------------------------------------
252 
253 #define VKI_PATH_MAX       4096	/* # chars in a path name including nul */
254 
255 //----------------------------------------------------------------------
256 // From linux-2.6.8.1/include/linux/kernel.h
257 //----------------------------------------------------------------------
258 
259 struct vki_sysinfo {
260 	long uptime;			/* Seconds since boot */
261 	unsigned long loads[3];		/* 1, 5, and 15 minute load averages */
262 	unsigned long totalram;		/* Total usable main memory size */
263 	unsigned long freeram;		/* Available memory size */
264 	unsigned long sharedram;	/* Amount of shared memory */
265 	unsigned long bufferram;	/* Memory used by buffers */
266 	unsigned long totalswap;	/* Total swap space size */
267 	unsigned long freeswap;		/* swap space still available */
268 	unsigned short procs;		/* Number of current processes */
269 	unsigned short pad;		/* explicit padding for m68k */
270 	unsigned long totalhigh;	/* Total high memory size */
271 	unsigned long freehigh;		/* Available high memory size */
272 	unsigned int mem_unit;		/* Memory unit size in bytes */
273 	char _f[20-2*sizeof(long)-sizeof(int)];	/* Padding: libc5 uses this.. */
274 };
275 
276 //----------------------------------------------------------------------
277 // From linux-2.6.8.1/include/linux/time.h
278 //----------------------------------------------------------------------
279 
280 #define VKI_CLOCK_REALTIME            0
281 #define VKI_CLOCK_MONOTONIC           1
282 #define VKI_CLOCK_PROCESS_CPUTIME_ID  2
283 #define VKI_CLOCK_THREAD_CPUTIME_ID   3
284 
285 struct vki_timespec {
286 	vki_time_t	tv_sec;		/* seconds */
287 	long		tv_nsec;	/* nanoseconds */
288 };
289 
290 struct vki_timeval {
291 	vki_time_t	tv_sec;		/* seconds */
292 	vki_suseconds_t	tv_usec;	/* microseconds */
293 };
294 
295 struct vki_timezone {
296 	int	tz_minuteswest;	/* minutes west of Greenwich */
297 	int	tz_dsttime;	/* type of dst correction */
298 };
299 
300 struct  vki_itimerspec {
301         struct  vki_timespec it_interval;    /* timer period */
302         struct  vki_timespec it_value;       /* timer expiration */
303 };
304 
305 struct	vki_itimerval {
306 	struct	vki_timeval it_interval;	/* timer interval */
307 	struct	vki_timeval it_value;	/* current value */
308 };
309 
310 //----------------------------------------------------------------------
311 // From linux-2.6.8.1/include/linux/timex.h
312 //----------------------------------------------------------------------
313 
314 struct vki_timex {
315 	unsigned int modes;	/* mode selector */
316 	long offset;		/* time offset (usec) */
317 	long freq;		/* frequency offset (scaled ppm) */
318 	long maxerror;		/* maximum error (usec) */
319 	long esterror;		/* estimated error (usec) */
320 	int status;		/* clock command/status */
321 	long constant;		/* pll time constant */
322 	long precision;		/* clock precision (usec) (read only) */
323 	long tolerance;		/* clock frequency tolerance (ppm)
324 				 * (read only)
325 				 */
326 	struct vki_timeval time;	/* (read only) */
327 	long tick;		/* (modified) usecs between clock ticks */
328 
329 	long ppsfreq;           /* pps frequency (scaled ppm) (ro) */
330 	long jitter;            /* pps jitter (us) (ro) */
331 	int shift;              /* interval duration (s) (shift) (ro) */
332 	long stabil;            /* pps stability (scaled ppm) (ro) */
333 	long jitcnt;            /* jitter limit exceeded (ro) */
334 	long calcnt;            /* calibration intervals (ro) */
335 	long errcnt;            /* calibration errors (ro) */
336 	long stbcnt;            /* stability limit exceeded (ro) */
337 
338 	int  :32; int  :32; int  :32; int  :32;
339 	int  :32; int  :32; int  :32; int  :32;
340 	int  :32; int  :32; int  :32; int  :32;
341 };
342 
343 #define VKI_ADJ_OFFSET			0x0001	/* time offset */
344 #define VKI_ADJ_FREQUENCY		0x0002	/* frequency offset */
345 #define VKI_ADJ_MAXERROR		0x0004	/* maximum time error */
346 #define VKI_ADJ_ESTERROR		0x0008	/* estimated time error */
347 #define VKI_ADJ_STATUS			0x0010	/* clock status */
348 #define VKI_ADJ_TIMECONST		0x0020	/* pll time constant */
349 #define VKI_ADJ_TAI			0x0080	/* set TAI offset */
350 #define VKI_ADJ_TICK			0x4000	/* tick value */
351 #define VKI_ADJ_ADJTIME			0x8000	/* switch between adjtime/adjtimex modes */
352 //#define VKI_ADJ_OFFSET_SINGLESHOT	0x8001	/* old-fashioned adjtime */
353 #define VKI_ADJ_OFFSET_READONLY		0x2000	/* read-only adjtime */
354 
355 //----------------------------------------------------------------------
356 // From linux-2.6.8.1/include/linux/times.h
357 //----------------------------------------------------------------------
358 
359 struct vki_tms {
360 	vki_clock_t tms_utime;
361 	vki_clock_t tms_stime;
362 	vki_clock_t tms_cutime;
363 	vki_clock_t tms_cstime;
364 };
365 
366 //----------------------------------------------------------------------
367 // From linux-2.6.8.1/include/linux/utime.h
368 //----------------------------------------------------------------------
369 
370 struct vki_utimbuf {
371 	vki_time_t actime;
372 	vki_time_t modtime;
373 };
374 
375 //----------------------------------------------------------------------
376 // From linux-2.6.8.1/include/linux/sched.h
377 //----------------------------------------------------------------------
378 
379 #define VKI_CSIGNAL		0x000000ff	/* signal mask to be sent at exit */
380 #define VKI_CLONE_VM		0x00000100	/* set if VM shared between processes */
381 #define VKI_CLONE_FS		0x00000200	/* set if fs info shared between processes */
382 #define VKI_CLONE_FILES		0x00000400	/* set if open files shared between processes */
383 #define VKI_CLONE_SIGHAND	0x00000800	/* set if signal handlers and blocked signals shared */
384 #define VKI_CLONE_VFORK		0x00004000	/* set if the parent wants the child to wake it up on mm_release */
385 #define VKI_CLONE_PARENT	0x00008000	/* set if we want to have the same parent as the cloner */
386 #define VKI_CLONE_THREAD	0x00010000	/* Same thread group? */
387 #define VKI_CLONE_SYSVSEM	0x00040000	/* share system V SEM_UNDO semantics */
388 #define VKI_CLONE_SETTLS	0x00080000	/* create a new TLS for the child */
389 #define VKI_CLONE_PARENT_SETTID	0x00100000	/* set the TID in the parent */
390 #define VKI_CLONE_CHILD_CLEARTID	0x00200000	/* clear the TID in the child */
391 #define VKI_CLONE_DETACHED	0x00400000	/* Unused, ignored */
392 #define VKI_CLONE_CHILD_SETTID	0x01000000	/* set the TID in the child */
393 
394 struct vki_sched_param {
395 	int sched_priority;
396 };
397 
398 #define VKI_TASK_COMM_LEN 16
399 
400 //----------------------------------------------------------------------
401 // From linux-2.6.8.1/include/asm-generic/siginfo.h
402 //----------------------------------------------------------------------
403 
404 // Some archs, such as MIPS, have non-standard vki_siginfo.
405 #ifndef HAVE_ARCH_SIGINFO_T
406 typedef union vki_sigval {
407 	int sival_int;
408 	void __user *sival_ptr;
409 } vki_sigval_t;
410 
411 #ifndef __VKI_ARCH_SI_PREAMBLE_SIZE
412 #define __VKI_ARCH_SI_PREAMBLE_SIZE	(3 * sizeof(int))
413 #endif
414 
415 #define VKI_SI_MAX_SIZE	128
416 
417 #ifndef VKI_SI_PAD_SIZE
418 #define VKI_SI_PAD_SIZE	((VKI_SI_MAX_SIZE - __VKI_ARCH_SI_PREAMBLE_SIZE) / sizeof(int))
419 #endif
420 
421 #ifndef __VKI_ARCH_SI_UID_T
422 #define __VKI_ARCH_SI_UID_T	vki_uid_t
423 #endif
424 
425 #ifndef __VKI_ARCH_SI_BAND_T
426 #define __VKI_ARCH_SI_BAND_T long
427 #endif
428 
429 // [[Nb: this type changed between 2.4 and 2.6, but not in a way that
430 // affects Valgrind.]]
431 typedef struct vki_siginfo {
432 	int si_signo;
433 	int si_errno;
434 	int si_code;
435 
436 	union {
437 		int _pad[VKI_SI_PAD_SIZE];
438 
439 		/* kill() */
440 		struct {
441 			vki_pid_t _pid;		/* sender's pid */
442 			__VKI_ARCH_SI_UID_T _uid;	/* sender's uid */
443 		} _kill;
444 
445 		/* POSIX.1b timers */
446 		struct {
447 			vki_timer_t _tid;		/* timer id */
448 			int _overrun;		/* overrun count */
449 			char _pad[sizeof( __VKI_ARCH_SI_UID_T) - sizeof(int)];
450 			vki_sigval_t _sigval;	/* same as below */
451 			int _sys_private;       /* not to be passed to user */
452 		} _timer;
453 
454 		/* POSIX.1b signals */
455 		struct {
456 			vki_pid_t _pid;		/* sender's pid */
457 			__VKI_ARCH_SI_UID_T _uid;	/* sender's uid */
458 			vki_sigval_t _sigval;
459 		} _rt;
460 
461 		/* SIGCHLD */
462 		struct {
463 			vki_pid_t _pid;		/* which child */
464 			__VKI_ARCH_SI_UID_T _uid;	/* sender's uid */
465 			int _status;		/* exit code */
466 			vki_clock_t _utime;
467 			vki_clock_t _stime;
468 		} _sigchld;
469 
470 		/* SIGILL, SIGFPE, SIGSEGV, SIGBUS */
471 		struct {
472 			void __user *_addr; /* faulting insn/memory ref. */
473 #ifdef __ARCH_SI_TRAPNO
474 			int _trapno;	/* TRAP # which caused the signal */
475 #endif
476 		} _sigfault;
477 
478 		/* SIGPOLL */
479 		struct {
480 			__VKI_ARCH_SI_BAND_T _band;	/* POLL_IN, POLL_OUT, POLL_MSG */
481 			int _fd;
482 		} _sigpoll;
483 	} _sifields;
484 } vki_siginfo_t;
485 #endif
486 
487 #define __VKI_SI_FAULT	0
488 
489 /*
490  * si_code values
491  * Digital reserves positive values for kernel-generated signals.
492  */
493 #define VKI_SI_USER	0		/* sent by kill, sigsend, raise */
494 #define VKI_SI_TKILL	-6		/* sent by tkill system call */
495 
496 /*
497  * SIGILL si_codes
498  */
499 #define VKI_ILL_ILLOPC	(__VKI_SI_FAULT|1)	/* illegal opcode */
500 #define VKI_ILL_ILLOPN	(__VKI_SI_FAULT|2)	/* illegal operand */
501 #define VKI_ILL_ILLADR	(__VKI_SI_FAULT|3)	/* illegal addressing mode */
502 #define VKI_ILL_ILLTRP	(__VKI_SI_FAULT|4)	/* illegal trap */
503 #define VKI_ILL_PRVOPC	(__VKI_SI_FAULT|5)	/* privileged opcode */
504 #define VKI_ILL_PRVREG	(__VKI_SI_FAULT|6)	/* privileged register */
505 #define VKI_ILL_COPROC	(__VKI_SI_FAULT|7)	/* coprocessor error */
506 #define VKI_ILL_BADSTK	(__VKI_SI_FAULT|8)	/* internal stack error */
507 
508 /*
509  * SIGFPE si_codes
510  */
511 #define VKI_FPE_INTDIV	(__VKI_SI_FAULT|1)	/* integer divide by zero */
512 #define VKI_FPE_INTOVF	(__VKI_SI_FAULT|2)	/* integer overflow */
513 #define VKI_FPE_FLTDIV	(__VKI_SI_FAULT|3)	/* floating point divide by zero */
514 #define VKI_FPE_FLTOVF	(__VKI_SI_FAULT|4)	/* floating point overflow */
515 #define VKI_FPE_FLTUND	(__VKI_SI_FAULT|5)	/* floating point underflow */
516 #define VKI_FPE_FLTRES	(__VKI_SI_FAULT|6)	/* floating point inexact result */
517 #define VKI_FPE_FLTINV	(__VKI_SI_FAULT|7)	/* floating point invalid operation */
518 #define VKI_FPE_FLTSUB	(__VKI_SI_FAULT|8)	/* subscript out of range */
519 
520 /*
521  * SIGSEGV si_codes
522  */
523 #define VKI_SEGV_MAPERR	(__VKI_SI_FAULT|1)	/* address not mapped to object */
524 #define VKI_SEGV_ACCERR	(__VKI_SI_FAULT|2)	/* invalid permissions for mapped object */
525 
526 /*
527  * SIGBUS si_codes
528  */
529 #define VKI_BUS_ADRALN	(__VKI_SI_FAULT|1)	/* invalid address alignment */
530 #define VKI_BUS_ADRERR	(__VKI_SI_FAULT|2)	/* non-existant physical address */
531 #define VKI_BUS_OBJERR	(__VKI_SI_FAULT|3)	/* object specific hardware error */
532 
533 /*
534  * SIGTRAP si_codes
535  */
536 #define VKI_TRAP_BRKPT      (__VKI_SI_FAULT|1)  /* process breakpoint */
537 #define VKI_TRAP_TRACE      (__VKI_SI_FAULT|2)  /* process trace trap */
538 
539 /*
540  * This works because the alignment is ok on all current architectures
541  * but we leave open this being overridden in the future
542  */
543 #ifndef VKI___ARCH_SIGEV_PREAMBLE_SIZE
544 #define VKI___ARCH_SIGEV_PREAMBLE_SIZE	(sizeof(int) * 2 + sizeof(vki_sigval_t))
545 #endif
546 
547 #define VKI_SIGEV_MAX_SIZE	64
548 #define VKI_SIGEV_PAD_SIZE	((VKI_SIGEV_MAX_SIZE - VKI___ARCH_SIGEV_PREAMBLE_SIZE) \
549 		/ sizeof(int))
550 
551 /* This is the flag the kernel handles, userspace/glibc handles SEGEV_THEAD. */
552 #define VKI_SIGEV_THREAD_ID	4
553 
554 typedef struct vki_sigevent {
555 	vki_sigval_t sigev_value;
556 	int sigev_signo;
557 	int sigev_notify;
558 	union {
559 		int _pad[VKI_SIGEV_PAD_SIZE];
560 		 int _tid;
561 
562 		struct {
563 			void (*_function)(vki_sigval_t);
564 			void *_attribute;	/* really pthread_attr_t */
565 		} _sigev_thread;
566 	} _sigev_un;
567 } vki_sigevent_t;
568 
569 #define vki_sigev_notify_thread_id	_sigev_un._tid
570 
571 //----------------------------------------------------------------------
572 // From elsewhere...
573 //----------------------------------------------------------------------
574 
575 // [[The kernel actually uses the numbers 0,1,2 directly here, believe it or
576 // not.  So we introduce our own constants, based on the glibc ones.]]
577 #define VKI_SEEK_SET              0
578 #define VKI_SEEK_CUR              1
579 #define VKI_SEEK_END              2
580 
581 //----------------------------------------------------------------------
582 // From linux-2.6.8.1/include/linux/net.h
583 //----------------------------------------------------------------------
584 
585 #define VKI_SYS_SOCKET		1	/* sys_socket(2)		*/
586 #define VKI_SYS_BIND		2	/* sys_bind(2)			*/
587 #define VKI_SYS_CONNECT		3	/* sys_connect(2)		*/
588 #define VKI_SYS_LISTEN		4	/* sys_listen(2)		*/
589 #define VKI_SYS_ACCEPT		5	/* sys_accept(2)		*/
590 #define VKI_SYS_GETSOCKNAME	6	/* sys_getsockname(2)		*/
591 #define VKI_SYS_GETPEERNAME	7	/* sys_getpeername(2)		*/
592 #define VKI_SYS_SOCKETPAIR	8	/* sys_socketpair(2)		*/
593 #define VKI_SYS_SEND		9	/* sys_send(2)			*/
594 #define VKI_SYS_RECV		10	/* sys_recv(2)			*/
595 #define VKI_SYS_SENDTO		11	/* sys_sendto(2)		*/
596 #define VKI_SYS_RECVFROM	12	/* sys_recvfrom(2)		*/
597 #define VKI_SYS_SHUTDOWN	13	/* sys_shutdown(2)		*/
598 #define VKI_SYS_SETSOCKOPT	14	/* sys_setsockopt(2)		*/
599 #define VKI_SYS_GETSOCKOPT	15	/* sys_getsockopt(2)		*/
600 #define VKI_SYS_SENDMSG		16	/* sys_sendmsg(2)		*/
601 #define VKI_SYS_RECVMSG		17	/* sys_recvmsg(2)		*/
602 #define VKI_SYS_ACCEPT4		18	/* sys_accept4(2)		*/
603 #define VKI_SYS_RECVMMSG	19	/* sys_recvmmsg(2)              */
604 #define VKI_SYS_SENDMMSG	20	/* sys_sendmmsg(2)              */
605 
606 #ifndef ARCH_HAS_SOCKET_TYPES
607 enum vki_sock_type {
608 	VKI_SOCK_STREAM	= 1,
609 	// [[others omitted]]
610 };
611 #endif /* ARCH_HAS_SOCKET_TYPES */
612 
613 //----------------------------------------------------------------------
614 // From linux-2.6.8.1/include/linux/uio.h
615 //----------------------------------------------------------------------
616 
617 struct vki_iovec
618 {
619 	void __user *iov_base;	/* BSD uses caddr_t (1003.1g requires void *) */
620 	__vki_kernel_size_t iov_len; /* Must be size_t (1003.1g) */
621 };
622 
623 //----------------------------------------------------------------------
624 // From linux-2.6.8.1/include/linux/socket.h
625 //----------------------------------------------------------------------
626 
627 // [[Resolved arbitrarily;  doesn't really matter whether it's '__inline__'
628 //   or 'inline']]
629 #define __KINLINE static __inline__
630 
631 typedef unsigned short	vki_sa_family_t;
632 
633 struct vki_sockaddr {
634 	vki_sa_family_t	sa_family;	/* address family, AF_xxx	*/
635 	char		sa_data[14];	/* 14 bytes of protocol address	*/
636 };
637 
638 struct vki_msghdr {
639 	void	*	msg_name;	/* Socket name			*/
640 	int		msg_namelen;	/* Length of name		*/
641 	struct vki_iovec *	msg_iov;	/* Data blocks			*/
642 	__vki_kernel_size_t	msg_iovlen;	/* Number of blocks		*/
643 	void 	*	msg_control;	/* Per protocol magic (eg BSD file descriptor passing) */
644 	__vki_kernel_size_t	msg_controllen;	/* Length of cmsg list */
645 	unsigned	msg_flags;
646 };
647 
648 struct vki_mmsghdr {
649 	struct vki_msghdr   msg_hdr;
650 	unsigned        msg_len;
651 };
652 
653 struct vki_cmsghdr {
654 	__vki_kernel_size_t	cmsg_len;	/* data byte count, including hdr */
655         int		cmsg_level;	/* originating protocol */
656         int		cmsg_type;	/* protocol-specific type */
657 };
658 
659 #define __VKI_CMSG_NXTHDR(ctl, len, cmsg) __vki_cmsg_nxthdr((ctl),(len),(cmsg))
660 #define VKI_CMSG_NXTHDR(mhdr, cmsg) vki_cmsg_nxthdr((mhdr), (cmsg))
661 
662 #define VKI_CMSG_ALIGN(len) ( ((len)+sizeof(long)-1) & ~(sizeof(long)-1) )
663 
664 #define VKI_CMSG_DATA(cmsg)	((void *)((char *)(cmsg) + VKI_CMSG_ALIGN(sizeof(struct vki_cmsghdr))))
665 
666 #define __VKI_CMSG_FIRSTHDR(ctl,len) ((len) >= sizeof(struct vki_cmsghdr) ? \
667 				  (struct vki_cmsghdr *)(ctl) : \
668 				  (struct vki_cmsghdr *)NULL)
669 #define VKI_CMSG_FIRSTHDR(msg)	__VKI_CMSG_FIRSTHDR((msg)->msg_control, (msg)->msg_controllen)
670 
671 // [[Urgh, this is revolting...]
__vki_cmsg_nxthdr(void * __ctl,__vki_kernel_size_t __size,struct vki_cmsghdr * __cmsg)672 __KINLINE struct vki_cmsghdr * __vki_cmsg_nxthdr(void *__ctl, __vki_kernel_size_t __size,
673 					       struct vki_cmsghdr *__cmsg)
674 {
675 	struct vki_cmsghdr * __ptr;
676 
677 	__ptr = (struct vki_cmsghdr*)(((unsigned char *) __cmsg) +  VKI_CMSG_ALIGN(__cmsg->cmsg_len));
678 	if ((unsigned long)((char*)(__ptr+1) - (char *) __ctl) > __size)
679 		return (struct vki_cmsghdr *)0;
680 
681 	return __ptr;
682 }
683 
vki_cmsg_nxthdr(struct vki_msghdr * __msg,struct vki_cmsghdr * __cmsg)684 __KINLINE struct vki_cmsghdr * vki_cmsg_nxthdr (struct vki_msghdr *__msg, struct vki_cmsghdr *__cmsg)
685 {
686 	return __vki_cmsg_nxthdr(__msg->msg_control, __msg->msg_controllen, __cmsg);
687 }
688 
689 #define	VKI_SCM_RIGHTS	0x01		/* rw: access rights (array of int) */
690 
691 #define VKI_AF_UNSPEC   0
692 #define VKI_AF_UNIX	1	/* Unix domain sockets 		*/
693 #define VKI_AF_INET	2	/* Internet IP Protocol		*/
694 #define VKI_AF_INET6	10	/* IP version 6			*/
695 #define VKI_AF_NETLINK  16
696 #define VKI_AF_BLUETOOTH 31	/* Bluetooth sockets		*/
697 
698 #define VKI_MSG_NOSIGNAL	0x4000	/* Do not generate SIGPIPE */
699 
700 #define VKI_SOL_SCTP	132
701 
702 //----------------------------------------------------------------------
703 // From linux-2.6.8.1/include/linux/in.h
704 //----------------------------------------------------------------------
705 
706 struct vki_in_addr {
707 	__vki_u32	s_addr;
708 };
709 
710 /* Structure describing an Internet (IP) socket address. */
711 #define __VKI_SOCK_SIZE__	16	/* sizeof(struct sockaddr)	*/
712 struct vki_sockaddr_in {
713   vki_sa_family_t	sin_family;	/* Address family		*/
714   unsigned short int	sin_port;	/* Port number			*/
715   struct vki_in_addr	sin_addr;	/* Internet address		*/
716 
717   /* Pad to size of `struct sockaddr'. */
718   unsigned char		__pad[__VKI_SOCK_SIZE__ - sizeof(short int) -
719 			sizeof(unsigned short int) - sizeof(struct vki_in_addr)];
720 };
721 
722 #define VKI_IPPROTO_TCP 6       /* Transmission Control Protocol        */
723 
724 //----------------------------------------------------------------------
725 // From linux-2.6.8.1/include/linux/in6.h
726 //----------------------------------------------------------------------
727 
728 struct vki_in6_addr
729 {
730 	union
731 	{
732 		__vki_u8	u6_addr8[16];
733 		__vki_u16	u6_addr16[8];
734 		__vki_u32	u6_addr32[4];
735 	} vki_in6_u;
736 #define vki_s6_addr		vki_in6_u.u6_addr8
737 #define vki_s6_addr16		vki_in6_u.u6_addr16
738 #define vki_s6_addr32		vki_in6_u.u6_addr32
739 };
740 
741 struct vki_sockaddr_in6 {
742 	unsigned short int	sin6_family;    /* AF_INET6 */
743 	__vki_u16		sin6_port;      /* Transport layer port # */
744 	__vki_u32		sin6_flowinfo;  /* IPv6 flow information */
745 	struct vki_in6_addr	sin6_addr;      /* IPv6 address */
746 	__vki_u32		sin6_scope_id;  /* scope id (new in RFC2553) */
747 };
748 
749 //----------------------------------------------------------------------
750 // From linux-2.6.8.1/include/linux/tcp.h
751 //----------------------------------------------------------------------
752 
753 #define VKI_TCP_NODELAY    1       /* Turn off Nagle's algorithm. */
754 
755 
756 //----------------------------------------------------------------------
757 // From linux-2.6.8.1/include/linux/un.h
758 //----------------------------------------------------------------------
759 
760 #define VKI_UNIX_PATH_MAX	108
761 
762 struct vki_sockaddr_un {
763 	vki_sa_family_t sun_family;	/* AF_UNIX */
764 	char sun_path[VKI_UNIX_PATH_MAX];	/* pathname */
765 };
766 
767 //----------------------------------------------------------------------
768 // From linux-3.15.8/include/uapi/linux/netlink.h
769 //----------------------------------------------------------------------
770 
771 struct vki_sockaddr_nl {
772         vki_sa_family_t    nl_family;      /* AF_NETLINK   */
773         unsigned short     nl_pad;         /* zero         */
774         __vki_u32          nl_pid;         /* port ID      */
775         __vki_u32          nl_groups;      /* multicast groups mask */
776 };
777 
778 //----------------------------------------------------------------------
779 // From linux-2.6.8.1/include/linux/if.h
780 //----------------------------------------------------------------------
781 
782 #define	VKI_IFNAMSIZ	16
783 
784 struct vki_ifmap
785 {
786 	unsigned long mem_start;
787 	unsigned long mem_end;
788 	unsigned short base_addr;
789 	unsigned char irq;
790 	unsigned char dma;
791 	unsigned char port;
792 	/* 3 bytes spare */
793 };
794 
795 struct vki_if_settings
796 {
797 	unsigned int type;	/* Type of physical device or protocol */
798 	unsigned int size;	/* Size of the data allocated by the caller */
799 	union {
800                 // [[Nb: converted these all to void* to avoid pulling in
801                 //   unnecessary headers]]]
802 		/* {atm/eth/dsl}_settings anyone ? */
803 		void /*raw_hdlc_proto		*/__user *raw_hdlc;
804 		void /*cisco_proto		*/__user *cisco;
805 		void /*fr_proto			*/__user *fr;
806 		void /*fr_proto_pvc		*/__user *fr_pvc;
807 		void /*fr_proto_pvc_info	*/__user *fr_pvc_info;
808 
809 		/* interface settings */
810 		void /*sync_serial_settings	*/__user *sync;
811 		void /*te1_settings		*/__user *te1;
812 	} ifs_ifsu;
813 };
814 
815 struct vki_ifreq
816 {
817 #define VKI_IFHWADDRLEN	6
818 	union
819 	{
820 		char	ifrn_name[VKI_IFNAMSIZ];		/* if name, e.g. "en0" */
821 	} ifr_ifrn;
822 
823 	union {
824 		struct	vki_sockaddr ifru_addr;
825 		struct	vki_sockaddr ifru_dstaddr;
826 		struct	vki_sockaddr ifru_broadaddr;
827 		struct	vki_sockaddr ifru_netmask;
828 		struct  vki_sockaddr ifru_hwaddr;
829 		short	ifru_flags;
830 		int	ifru_ivalue;
831 		int	ifru_mtu;
832 		struct  vki_ifmap ifru_map;
833 		char	ifru_slave[VKI_IFNAMSIZ];	/* Just fits the size */
834 		char	ifru_newname[VKI_IFNAMSIZ];
835 		void __user *	ifru_data;
836 		struct	vki_if_settings ifru_settings;
837 	} ifr_ifru;
838 };
839 
840 #define vki_ifr_name	ifr_ifrn.ifrn_name	/* interface name 	*/
841 #define ifr_hwaddr	ifr_ifru.ifru_hwaddr	/* MAC address 		*/
842 #define	ifr_addr	ifr_ifru.ifru_addr	/* address		*/
843 #define	ifr_dstaddr	ifr_ifru.ifru_dstaddr	/* other end of p-p lnk	*/
844 #define	ifr_broadaddr	ifr_ifru.ifru_broadaddr	/* broadcast address	*/
845 #define	ifr_netmask	ifr_ifru.ifru_netmask	/* interface net mask	*/
846 #define	vki_ifr_flags	ifr_ifru.ifru_flags	/* flags		*/
847 #define	vki_ifr_metric	ifr_ifru.ifru_ivalue	/* metric		*/
848 #define	vki_ifr_mtu		ifr_ifru.ifru_mtu	/* mtu			*/
849 #define ifr_map		ifr_ifru.ifru_map	/* device map		*/
850 #define ifr_slave	ifr_ifru.ifru_slave	/* slave device		*/
851 #define	vki_ifr_data	ifr_ifru.ifru_data	/* for use by interface	*/
852 #define vki_ifr_ifindex	ifr_ifru.ifru_ivalue	/* interface index	*/
853 #define ifr_bandwidth	ifr_ifru.ifru_ivalue    /* link bandwidth	*/
854 #define ifr_qlen	ifr_ifru.ifru_ivalue	/* Queue length 	*/
855 #define ifr_newname	ifr_ifru.ifru_newname	/* New name		*/
856 #define ifr_settings	ifr_ifru.ifru_settings	/* Device/proto settings*/
857 
858 struct vki_ifconf
859 {
860 	int	ifc_len;			/* size of buffer	*/
861 	union
862 	{
863 		char __user *ifcu_buf;
864 		struct vki_ifreq __user *ifcu_req;
865 	} ifc_ifcu;
866 };
867 #define	vki_ifc_buf	ifc_ifcu.ifcu_buf	/* buffer address	*/
868 
869 //----------------------------------------------------------------------
870 // From linux-2.6.8.1/include/linux/if_arp.h
871 //----------------------------------------------------------------------
872 
873 struct vki_arpreq {
874   struct vki_sockaddr	arp_pa;		/* protocol address		*/
875   struct vki_sockaddr	arp_ha;		/* hardware address		*/
876   int			arp_flags;	/* flags			*/
877   struct vki_sockaddr   arp_netmask;    /* netmask (only for proxy arps) */
878   char			arp_dev[16];
879 };
880 
881 //----------------------------------------------------------------------
882 // From linux-2.6.8.1/include/linux/route.h
883 //----------------------------------------------------------------------
884 
885 struct vki_rtentry
886 {
887 	unsigned long	rt_pad1;
888 	struct vki_sockaddr	rt_dst;		/* target address		*/
889 	struct vki_sockaddr	rt_gateway;	/* gateway addr (RTF_GATEWAY)	*/
890 	struct vki_sockaddr	rt_genmask;	/* target network mask (IP)	*/
891 	unsigned short	rt_flags;
892 	short		rt_pad2;
893 	unsigned long	rt_pad3;
894 	void		*rt_pad4;
895 	short		rt_metric;	/* +1 for binary compatibility!	*/
896 	char __user	*rt_dev;	/* forcing the device at add	*/
897 	unsigned long	rt_mtu;		/* per route MTU/Window 	*/
898 // [[Not important for Valgrind]]
899 //#ifndef __KERNEL__
900 //#define rt_mss	rt_mtu		/* Compatibility :-(            */
901 //#endif
902 	unsigned long	rt_window;	/* Window clamping 		*/
903 	unsigned short	rt_irtt;	/* Initial RTT			*/
904 };
905 
906 //----------------------------------------------------------------------
907 // From linux-2.6.13-rc5/include/net/sctp/user.h
908 //----------------------------------------------------------------------
909 
910 typedef __vki_s32 vki_sctp_assoc_t;
911 
912 enum vki_sctp_optname {
913 	VKI_SCTP_RTOINFO,
914 #define VKI_SCTP_RTOINFO VKI_SCTP_RTOINFO
915 	VKI_SCTP_ASSOCINFO,
916 #define VKI_SCTP_ASSOCINFO VKI_SCTP_ASSOCINFO
917 	VKI_SCTP_INITMSG,
918 #define VKI_SCTP_INITMSG VKI_SCTP_INITMSG
919 	VKI_SCTP_NODELAY, 	/* Get/set nodelay option. */
920 #define VKI_SCTP_NODELAY	VKI_SCTP_NODELAY
921 	VKI_SCTP_AUTOCLOSE,
922 #define VKI_SCTP_AUTOCLOSE VKI_SCTP_AUTOCLOSE
923 	VKI_SCTP_SET_PEER_PRIMARY_ADDR,
924 #define VKI_SCTP_SET_PEER_PRIMARY_ADDR VKI_SCTP_SET_PEER_PRIMARY_ADDR
925 	VKI_SCTP_PRIMARY_ADDR,
926 #define VKI_SCTP_PRIMARY_ADDR VKI_SCTP_PRIMARY_ADDR
927 	VKI_SCTP_ADAPTION_LAYER,
928 #define VKI_SCTP_ADAPTION_LAYER VKI_SCTP_ADAPTION_LAYER
929 	VKI_SCTP_DISABLE_FRAGMENTS,
930 #define VKI_SCTP_DISABLE_FRAGMENTS VKI_SCTP_DISABLE_FRAGMENTS
931 	VKI_SCTP_PEER_ADDR_PARAMS,
932 #define VKI_SCTP_PEER_ADDR_PARAMS VKI_SCTP_PEER_ADDR_PARAMS
933 	VKI_SCTP_DEFAULT_SEND_PARAM,
934 #define VKI_SCTP_DEFAULT_SEND_PARAM VKI_SCTP_DEFAULT_SEND_PARAM
935 	VKI_SCTP_EVENTS,
936 #define VKI_SCTP_EVENTS VKI_SCTP_EVENTS
937 	VKI_SCTP_I_WANT_MAPPED_V4_ADDR,  /* Turn on/off mapped v4 addresses  */
938 #define VKI_SCTP_I_WANT_MAPPED_V4_ADDR VKI_SCTP_I_WANT_MAPPED_V4_ADDR
939 	VKI_SCTP_MAXSEG, 	/* Get/set maximum fragment. */
940 #define VKI_SCTP_MAXSEG 	VKI_SCTP_MAXSEG
941 	VKI_SCTP_STATUS,
942 #define VKI_SCTP_STATUS VKI_SCTP_STATUS
943 	VKI_SCTP_GET_PEER_ADDR_INFO,
944 #define VKI_SCTP_GET_PEER_ADDR_INFO VKI_SCTP_GET_PEER_ADDR_INFO
945 
946 	/* Internal Socket Options. Some of the sctp library functions are
947 	 * implemented using these socket options.
948 	 */
949 	VKI_SCTP_SOCKOPT_BINDX_ADD = 100,/* BINDX requests for adding addresses. */
950 #define VKI_SCTP_SOCKOPT_BINDX_ADD	VKI_SCTP_SOCKOPT_BINDX_ADD
951 	VKI_SCTP_SOCKOPT_BINDX_REM, /* BINDX requests for removing addresses. */
952 #define VKI_SCTP_SOCKOPT_BINDX_REM	VKI_SCTP_SOCKOPT_BINDX_REM
953 	VKI_SCTP_SOCKOPT_PEELOFF, 	/* peel off association. */
954 #define VKI_SCTP_SOCKOPT_PEELOFF	VKI_SCTP_SOCKOPT_PEELOFF
955 	VKI_SCTP_GET_PEER_ADDRS_NUM, 	/* Get number of peer addresss. */
956 #define VKI_SCTP_GET_PEER_ADDRS_NUM	VKI_SCTP_GET_PEER_ADDRS_NUM
957 	VKI_SCTP_GET_PEER_ADDRS, 	/* Get all peer addresss. */
958 #define VKI_SCTP_GET_PEER_ADDRS	VKI_SCTP_GET_PEER_ADDRS
959 	VKI_SCTP_GET_LOCAL_ADDRS_NUM, 	/* Get number of local addresss. */
960 #define VKI_SCTP_GET_LOCAL_ADDRS_NUM	VKI_SCTP_GET_LOCAL_ADDRS_NUM
961 	VKI_SCTP_GET_LOCAL_ADDRS, 	/* Get all local addresss. */
962 #define VKI_SCTP_GET_LOCAL_ADDRS	VKI_SCTP_GET_LOCAL_ADDRS
963 	VKI_SCTP_SOCKOPT_CONNECTX, /* CONNECTX requests. */
964 #define VKI_SCTP_SOCKOPT_CONNECTX	VKI_SCTP_SOCKOPT_CONNECTX
965 };
966 
967 struct vki_sctp_getaddrs {
968 	vki_sctp_assoc_t        assoc_id;
969 	int			addr_num;
970 	struct vki_sockaddr	*addrs;
971 };
972 
973 //----------------------------------------------------------------------
974 // From linux-2.6.8.1/include/linux/resource.h
975 //----------------------------------------------------------------------
976 
977 struct	vki_rusage {
978 	struct vki_timeval ru_utime;	/* user time used */
979 	struct vki_timeval ru_stime;	/* system time used */
980 	long	ru_maxrss;		/* maximum resident set size */
981 	long	ru_ixrss;		/* integral shared memory size */
982 	long	ru_idrss;		/* integral unshared data size */
983 	long	ru_isrss;		/* integral unshared stack size */
984 	long	ru_minflt;		/* page reclaims */
985 	long	ru_majflt;		/* page faults */
986 	long	ru_nswap;		/* swaps */
987 	long	ru_inblock;		/* block input operations */
988 	long	ru_oublock;		/* block output operations */
989 	long	ru_msgsnd;		/* messages sent */
990 	long	ru_msgrcv;		/* messages received */
991 	long	ru_nsignals;		/* signals received */
992 	long	ru_nvcsw;		/* voluntary context switches */
993 	long	ru_nivcsw;		/* involuntary " */
994 };
995 
996 struct vki_rlimit {
997 	unsigned long	rlim_cur;
998 	unsigned long	rlim_max;
999 };
1000 
1001 struct vki_rlimit64 {
1002 	__vki_u64 rlim_cur;
1003 	__vki_u64 rlim_max;
1004 };
1005 
1006 //----------------------------------------------------------------------
1007 // From linux-2.6.8.1/include/linux/elfcore.h
1008 //----------------------------------------------------------------------
1009 
1010 struct vki_elf_siginfo
1011 {
1012 	int	si_signo;			/* signal number */
1013 	int	si_code;			/* extra code */
1014 	int	si_errno;			/* errno */
1015 };
1016 
1017 // [[Removed some commented out lines here]]
1018 struct vki_elf_prstatus
1019 {
1020 	struct vki_elf_siginfo pr_info;	/* Info associated with signal */
1021 	short	pr_cursig;		/* Current signal */
1022 	unsigned long pr_sigpend;	/* Set of pending signals */
1023 	unsigned long pr_sighold;	/* Set of held signals */
1024 	vki_pid_t	pr_pid;
1025 	vki_pid_t	pr_ppid;
1026 	vki_pid_t	pr_pgrp;
1027 	vki_pid_t	pr_sid;
1028 	struct vki_timeval pr_utime;	/* User time */
1029 	struct vki_timeval pr_stime;	/* System time */
1030 	struct vki_timeval pr_cutime;	/* Cumulative user time */
1031 	struct vki_timeval pr_cstime;	/* Cumulative system time */
1032 	vki_elf_gregset_t pr_reg;	/* GP registers */
1033 	int pr_fpvalid;		/* True if math co-processor being used.  */
1034 };
1035 
1036 #define VKI_ELF_PRARGSZ	(80)	/* Number of chars for args */
1037 
1038 struct vki_elf_prpsinfo
1039 {
1040 	char	pr_state;	/* numeric process state */
1041 	char	pr_sname;	/* char for pr_state */
1042 	char	pr_zomb;	/* zombie */
1043 	char	pr_nice;	/* nice val */
1044 	unsigned long pr_flag;	/* flags */
1045 	__vki_kernel_uid_t	pr_uid;
1046 	__vki_kernel_gid_t	pr_gid;
1047 	vki_pid_t	pr_pid, pr_ppid, pr_pgrp, pr_sid;
1048 	/* Lots missing */
1049 	char	pr_fname[16];	/* filename of executable */
1050 	char	pr_psargs[VKI_ELF_PRARGSZ];	/* initial part of arg list */
1051 };
1052 
1053 //----------------------------------------------------------------------
1054 // From linux-2.6.12.1/include/linux/eventpoll.h
1055 //----------------------------------------------------------------------
1056 
1057 /* Valid opcodes to issue to sys_epoll_ctl() */
1058 #define VKI_EPOLL_CTL_ADD 1
1059 #define VKI_EPOLL_CTL_DEL 2
1060 #define VKI_EPOLL_CTL_MOD 3
1061 
1062 #ifdef __x86_64__
1063 #define VKI_EPOLL_PACKED __attribute__((packed))
1064 #else
1065 #define VKI_EPOLL_PACKED
1066 #endif
1067 
1068 struct vki_epoll_event {
1069 	__vki_u32 events;
1070 	__vki_u64 data;
1071 } VKI_EPOLL_PACKED;
1072 
1073 
1074 //----------------------------------------------------------------------
1075 // From linux-2.6.8.1/include/linux/mqueue.h
1076 //----------------------------------------------------------------------
1077 
1078 struct vki_mq_attr {
1079 	long	mq_flags;	/* message queue flags			*/
1080 	long	mq_maxmsg;	/* maximum number of messages		*/
1081 	long	mq_msgsize;	/* maximum message size			*/
1082 	long	mq_curmsgs;	/* number of messages currently queued	*/
1083 	long	__reserved[4];	/* ignored for input, zeroed for output */
1084 };
1085 
1086 //----------------------------------------------------------------------
1087 // From linux-2.6.8.1/include/linux/utsname.h
1088 //----------------------------------------------------------------------
1089 
1090 struct vki_new_utsname {
1091 	char sysname[65];
1092 	char nodename[65];
1093 	char release[65];
1094 	char version[65];
1095 	char machine[65];
1096 	char domainname[65];
1097 };
1098 
1099 //----------------------------------------------------------------------
1100 // From linux-2.6.8.1/include/linux/mii.h
1101 //----------------------------------------------------------------------
1102 
1103 /* This structure is used in all SIOCxMIIxxx ioctl calls */
1104 struct vki_mii_ioctl_data {
1105 	vki_u16		phy_id;
1106 	vki_u16		reg_num;
1107 	vki_u16		val_in;
1108 	vki_u16		val_out;
1109 };
1110 
1111 //----------------------------------------------------------------------
1112 // From linux-2.6.8.1/include/linux/capability.h
1113 //----------------------------------------------------------------------
1114 
1115 // [[capget()/capset() man page says this, ominously:
1116 //
1117 //   The kernel API is likely to change and use of these functions  (in
1118 //   particular the format of the cap_user_*_t types) is subject to
1119 //   change with each kernel revision.
1120 //
1121 // However, the format hasn't changed since at least Linux 2.4.6.]]
1122 
1123 typedef struct __vki_user_cap_header_struct {
1124 	__vki_u32 version;
1125 	int pid;
1126 } __user *vki_cap_user_header_t;
1127 
1128 typedef struct __vki_user_cap_data_struct {
1129         __vki_u32 effective;
1130         __vki_u32 permitted;
1131         __vki_u32 inheritable;
1132 } __user *vki_cap_user_data_t;
1133 
1134 
1135 //----------------------------------------------------------------------
1136 // From linux-2.6.8.1/include/linux/module.h
1137 //----------------------------------------------------------------------
1138 
1139 // [[We do a VKI_SIZEOF_* here because this type is so big, and its size
1140 //   depends on the word size, so see vki_arch.h]]
1141 
1142 //----------------------------------------------------------------------
1143 // From linux-2.6.8.1/include/linux/ipc.h
1144 //----------------------------------------------------------------------
1145 
1146 /* Obsolete, used only for backwards compatibility and libc5 compiles */
1147 struct vki_ipc_perm
1148 {
1149 	__vki_kernel_key_t	key;
1150 	__vki_kernel_uid_t	uid;
1151 	__vki_kernel_gid_t	gid;
1152 	__vki_kernel_uid_t	cuid;
1153 	__vki_kernel_gid_t	cgid;
1154 	__vki_kernel_mode_t	mode;
1155 	unsigned short	seq;
1156 };
1157 
1158 #define VKI_IPC_CREAT  00001000   /* create if key is nonexistent */
1159 #define VKI_IPC_EXCL   00002000   /* fail if key exists */
1160 #define VKI_IPC_NOWAIT 00004000   /* return error on wait */
1161 
1162 //#define VKI_IPC_RMID 0     /* remove resource */
1163 #define VKI_IPC_SET  1     /* set ipc_perm options */
1164 #define VKI_IPC_STAT 2     /* get ipc_perm options */
1165 #define VKI_IPC_INFO 3     /* see ipcs */
1166 
1167 #define VKI_IPC_64  0x0100  /* New version (support 32-bit UIDs, bigger
1168 			       message sizes, etc. */
1169 // From /usr/include/bits/shm.h
1170 # define VKI_SHM_HUGETLB   04000
1171 
1172 
1173 //----------------------------------------------------------------------
1174 // From linux-2.6.8.1/include/linux/sem.h
1175 //----------------------------------------------------------------------
1176 
1177 #define VKI_GETALL  13       /* get all semval's */
1178 #define VKI_SETVAL  16       /* set semval */
1179 #define VKI_SETALL  17       /* set all semval's */
1180 
1181 #define VKI_SEM_STAT 18
1182 #define VKI_SEM_INFO 19
1183 
1184 /* Obsolete, used only for backwards compatibility and libc5 compiles */
1185 struct vki_semid_ds {
1186 	struct vki_ipc_perm	sem_perm;		/* permissions .. see ipc.h */
1187 	__vki_kernel_time_t	sem_otime;		/* last semop time */
1188 	__vki_kernel_time_t	sem_ctime;		/* last change time */
1189         // [[Use void* to avoid excess header copying]]
1190 	void/*struct sem	*/*sem_base;		/* ptr to first semaphore in array */
1191 	void/*struct sem_queue */*sem_pending;		/* pending operations to be processed */
1192 	void/*struct sem_queue */**sem_pending_last;	/* last pending operation */
1193 	void/*struct sem_undo	*/*undo;			/* undo requests on this array */
1194 	unsigned short	sem_nsems;		/* no. of semaphores in array */
1195 };
1196 
1197 struct vki_sembuf {
1198 	unsigned short  sem_num;	/* semaphore index in array */
1199 	short		sem_op;		/* semaphore operation */
1200 	short		sem_flg;	/* operation flags */
1201 };
1202 
1203 union vki_semun {
1204 	int val;			/* value for SETVAL */
1205 	struct vki_semid_ds __user *buf;	/* buffer for IPC_STAT & IPC_SET */
1206 	unsigned short __user *array;	/* array for GETALL & SETALL */
1207 	struct vki_seminfo __user *__buf;	/* buffer for IPC_INFO */
1208 	void __user *__pad;
1209 };
1210 
1211 struct  vki_seminfo {
1212 	int semmap;
1213 	int semmni;
1214 	int semmns;
1215 	int semmnu;
1216 	int semmsl;
1217 	int semopm;
1218 	int semume;
1219 	int semusz;
1220 	int semvmx;
1221 	int semaem;
1222 };
1223 
1224 //----------------------------------------------------------------------
1225 // From linux-2.6.8.1/include/asm-generic/errno-base.h
1226 //----------------------------------------------------------------------
1227 
1228 #define	VKI_EPERM		 1	/* Operation not permitted */
1229 #define	VKI_ENOENT		 2	/* No such file or directory */
1230 #define	VKI_ESRCH		 3	/* No such process */
1231 #define	VKI_EINTR		 4	/* Interrupted system call */
1232 #define	VKI_EIO			 5	/* I/O error */
1233 #define	VKI_ENXIO		 6	/* No such device or address */
1234 #define	VKI_E2BIG		 7	/* Argument list too long */
1235 #define	VKI_ENOEXEC		 8	/* Exec format error */
1236 #define	VKI_EBADF		 9	/* Bad file number */
1237 #define	VKI_ECHILD		10	/* No child processes */
1238 #define	VKI_EAGAIN		11	/* Try again */
1239 #define	VKI_ENOMEM		12	/* Out of memory */
1240 #define	VKI_EACCES		13	/* Permission denied */
1241 #define	VKI_EFAULT		14	/* Bad address */
1242 #define	VKI_ENOTBLK		15	/* Block device required */
1243 #define	VKI_EBUSY		16	/* Device or resource busy */
1244 #define	VKI_EEXIST		17	/* File exists */
1245 #define	VKI_EXDEV		18	/* Cross-device link */
1246 #define	VKI_ENODEV		19	/* No such device */
1247 #define	VKI_ENOTDIR		20	/* Not a directory */
1248 #define	VKI_EISDIR		21	/* Is a directory */
1249 #define	VKI_EINVAL		22	/* Invalid argument */
1250 #define	VKI_ENFILE		23	/* File table overflow */
1251 #define	VKI_EMFILE		24	/* Too many open files */
1252 #define	VKI_ENOTTY		25	/* Not a typewriter */
1253 #define	VKI_ETXTBSY		26	/* Text file busy */
1254 #define	VKI_EFBIG		27	/* File too large */
1255 #define	VKI_ENOSPC		28	/* No space left on device */
1256 #define	VKI_ESPIPE		29	/* Illegal seek */
1257 #define	VKI_EROFS		30	/* Read-only file system */
1258 #define	VKI_EMLINK		31	/* Too many links */
1259 #define	VKI_EPIPE		32	/* Broken pipe */
1260 #define	VKI_EDOM		33	/* Math argument out of domain of func */
1261 #define	VKI_ERANGE		34	/* Math result not representable */
1262 
1263 //----------------------------------------------------------------------
1264 // From linux-2.6.8.1/include/asm-generic/errno.h
1265 //----------------------------------------------------------------------
1266 
1267 #define VKI_EWOULDBLOCK		VKI_EAGAIN
1268 
1269 //----------------------------------------------------------------------
1270 // From linux-2.6.8.1/include/linux/wait.h
1271 //----------------------------------------------------------------------
1272 
1273 #define VKI_WNOHANG	0x00000001
1274 
1275 #define __VKI_WALL	0x40000000	/* Wait on all children, regardless of type */
1276 #define __VKI_WCLONE	0x80000000	/* Wait only on non-SIGCHLD children */
1277 
1278 //----------------------------------------------------------------------
1279 // From linux-2.6.8.1/include/linux/mman.h
1280 //----------------------------------------------------------------------
1281 
1282 #define VKI_MREMAP_MAYMOVE	1
1283 #define VKI_MREMAP_FIXED	2
1284 
1285 //----------------------------------------------------------------------
1286 // From linux-2.6.31-rc4/include/linux/futex.h
1287 //----------------------------------------------------------------------
1288 
1289 #define VKI_FUTEX_WAIT (0)
1290 #define VKI_FUTEX_WAKE (1)
1291 #define VKI_FUTEX_FD (2)
1292 #define VKI_FUTEX_REQUEUE (3)
1293 #define VKI_FUTEX_CMP_REQUEUE (4)
1294 #define VKI_FUTEX_WAKE_OP (5)
1295 #define VKI_FUTEX_LOCK_PI (6)
1296 #define VKI_FUTEX_UNLOCK_PI (7)
1297 #define VKI_FUTEX_TRYLOCK_PI (8)
1298 #define VKI_FUTEX_WAIT_BITSET (9)
1299 #define VKI_FUTEX_WAKE_BITSET (10)
1300 #define VKI_FUTEX_WAIT_REQUEUE_PI (11)
1301 #define VKI_FUTEX_CMP_REQUEUE_PI (12)
1302 #define VKI_FUTEX_PRIVATE_FLAG (128)
1303 #define VKI_FUTEX_CLOCK_REALTIME (256)
1304 
1305 struct vki_robust_list {
1306 	struct vki_robust_list __user *next;
1307 };
1308 
1309 struct vki_robust_list_head {
1310 	/*
1311 	 * The head of the list. Points back to itself if empty:
1312 	 */
1313 	struct vki_robust_list list;
1314 
1315 	/*
1316 	 * This relative offset is set by user-space, it gives the kernel
1317 	 * the relative position of the futex field to examine. This way
1318 	 * we keep userspace flexible, to freely shape its data-structure,
1319 	 * without hardcoding any particular offset into the kernel:
1320 	 */
1321 	long futex_offset;
1322 
1323 	/*
1324 	 * The death of the thread may race with userspace setting
1325 	 * up a lock's links. So to handle this race, userspace first
1326 	 * sets this field to the address of the to-be-taken lock,
1327 	 * then does the lock acquire, and then adds itself to the
1328 	 * list, and then clears this field. Hence the kernel will
1329 	 * always have full knowledge of all locks that the thread
1330 	 * _might_ have taken. We check the owner TID in any case,
1331 	 * so only truly owned locks will be handled.
1332 	 */
1333 	struct vki_robust_list __user *list_op_pending;
1334 };
1335 
1336 //----------------------------------------------------------------------
1337 // From linux-2.6.8.1/include/linux/errno.h
1338 //----------------------------------------------------------------------
1339 
1340 #define VKI_ERESTARTSYS	512
1341 
1342 //----------------------------------------------------------------------
1343 // From linux-2.6.8.1/include/linux/stat.h
1344 //----------------------------------------------------------------------
1345 
1346 #define VKI_S_IFMT  00170000
1347 #define VKI_S_IFSOCK 0140000
1348 #define VKI_S_IFLNK  0120000
1349 #define VKI_S_IFREG  0100000
1350 #define VKI_S_IFBLK  0060000
1351 #define VKI_S_IFDIR  0040000
1352 #define VKI_S_IFCHR  0020000
1353 #define VKI_S_IFIFO  0010000
1354 #define VKI_S_ISUID  0004000
1355 #define VKI_S_ISGID  0002000
1356 #define VKI_S_ISVTX  0001000
1357 
1358 #define VKI_S_ISLNK(m)	(((m) & VKI_S_IFMT) == VKI_S_IFLNK)
1359 #define VKI_S_ISREG(m)	(((m) & VKI_S_IFMT) == VKI_S_IFREG)
1360 #define VKI_S_ISDIR(m)	(((m) & VKI_S_IFMT) == VKI_S_IFDIR)
1361 #define VKI_S_ISCHR(m)	(((m) & VKI_S_IFMT) == VKI_S_IFCHR)
1362 #define VKI_S_ISBLK(m)	(((m) & VKI_S_IFMT) == VKI_S_IFBLK)
1363 #define VKI_S_ISFIFO(m)	(((m) & VKI_S_IFMT) == VKI_S_IFIFO)
1364 #define VKI_S_ISSOCK(m)	(((m) & VKI_S_IFMT) == VKI_S_IFSOCK)
1365 
1366 #define VKI_S_IRWXU 00700
1367 #define VKI_S_IRUSR 00400
1368 #define VKI_S_IWUSR 00200
1369 #define VKI_S_IXUSR 00100
1370 
1371 #define VKI_S_IRWXG 00070
1372 #define VKI_S_IRGRP 00040
1373 #define VKI_S_IWGRP 00020
1374 #define VKI_S_IXGRP 00010
1375 
1376 #define VKI_S_IRWXO 00007
1377 #define VKI_S_IROTH 00004
1378 #define VKI_S_IWOTH 00002
1379 #define VKI_S_IXOTH 00001
1380 
1381 //----------------------------------------------------------------------
1382 // From linux-2.6.8.1/include/linux/dirent.h
1383 //----------------------------------------------------------------------
1384 
1385 /* This is the old compat structure to use with the old dirent syscall. */
1386 struct vki_dirent {
1387 	long		d_ino;
1388 	__vki_kernel_off_t	d_off;
1389 	unsigned short	d_reclen;
1390 	char		d_name[256]; /* We must not include limits.h! */
1391 };
1392 
1393 /* This is the new structure to use with the dirent64 syscall. */
1394 struct vki_dirent64 {
1395 	__vki_u64 d_ino;
1396 	__vki_s64 d_off;
1397 	unsigned short d_reclen;
1398 	unsigned char d_type;
1399 	char d_name[256]; /* Note we hard code a max file length here. */
1400 };
1401 
1402 //----------------------------------------------------------------------
1403 // From linux-2.6.8.1/include/linux/fcntl.h
1404 //----------------------------------------------------------------------
1405 
1406 #define VKI_F_SETLEASE      (VKI_F_LINUX_SPECIFIC_BASE + 0)
1407 #define VKI_F_GETLEASE      (VKI_F_LINUX_SPECIFIC_BASE + 1)
1408 
1409 #define VKI_F_CANCELLK      (VKI_F_LINUX_SPECIFIC_BASE + 5)
1410 
1411 #define VKI_F_DUPFD_CLOEXEC (VKI_F_LINUX_SPECIFIC_BASE + 6)
1412 
1413 #define VKI_F_NOTIFY        (VKI_F_LINUX_SPECIFIC_BASE + 2)
1414 
1415 #define VKI_F_SETPIPE_SZ    (VKI_F_LINUX_SPECIFIC_BASE + 7)
1416 #define VKI_F_GETPIPE_SZ    (VKI_F_LINUX_SPECIFIC_BASE + 8)
1417 
1418 //----------------------------------------------------------------------
1419 // From linux-2.6.8.1/include/linux/sysctl.h
1420 //----------------------------------------------------------------------
1421 
1422 struct __vki_sysctl_args {
1423 	int __user *name;
1424 	int nlen;
1425 	void __user *oldval;
1426 	vki_size_t __user *oldlenp;
1427 	void __user *newval;
1428 	vki_size_t newlen;
1429 	unsigned long __unused0[4];
1430 };
1431 
1432 //----------------------------------------------------------------------
1433 // From linux-2.6.8.1/include/linux/aio_abi.h
1434 //----------------------------------------------------------------------
1435 
1436 typedef unsigned long	vki_aio_context_t;
1437 
1438 enum {
1439 	VKI_IOCB_CMD_PREAD = 0,
1440 	VKI_IOCB_CMD_PWRITE = 1,
1441 	VKI_IOCB_CMD_FSYNC = 2,
1442 	VKI_IOCB_CMD_FDSYNC = 3,
1443 	VKI_IOCB_CMD_PREADV = 7,
1444 	VKI_IOCB_CMD_PWRITEV = 8,
1445 };
1446 
1447 /* read() from /dev/aio returns these structures. */
1448 struct vki_io_event {
1449 	__vki_u64	data;		/* the data field from the iocb */
1450 	__vki_u64	obj;		/* what iocb this event came from */
1451         // [[Nb: These fields renamed from 'res' and 'res2' because 'res' is
1452         //   a macro in vg_syscalls.c!]]
1453 	__vki_s64	result;		/* result code for this event */
1454 	__vki_s64	result2;	/* secondary result */
1455 };
1456 
1457 #if defined(VKI_LITTLE_ENDIAN)
1458 #  define VKI_PADDED(x,y)	x, y
1459 #elif defined(VKI_BIG_ENDIAN)
1460 #  define VKI_PADDED(x,y)	y, x
1461 #else
1462 #error edit for your odd byteorder.
1463 #endif
1464 
1465 struct vki_iocb {
1466 	/* these are internal to the kernel/libc. */
1467 	__vki_u64	aio_data;	/* data to be returned in event's data */
1468 	__vki_u32	VKI_PADDED(aio_key, aio_reserved1);
1469 				/* the kernel sets aio_key to the req # */
1470 
1471 	/* common fields */
1472 	__vki_u16	aio_lio_opcode;	/* see IOCB_CMD_ above */
1473 	__vki_s16	aio_reqprio;
1474 	__vki_u32	aio_fildes;
1475 
1476 	__vki_u64	aio_buf;
1477 	__vki_u64	aio_nbytes;
1478 	__vki_s64	aio_offset;
1479 
1480 	/* extra parameters */
1481 	__vki_u64	aio_reserved2;	/* TODO: use this for a (struct sigevent *) */
1482 	__vki_u64	aio_reserved3;
1483 }; /* 64 bytes */
1484 
1485 //----------------------------------------------------------------------
1486 // From linux-2.6.8.1/include/linux/aio.h
1487 //----------------------------------------------------------------------
1488 
1489 struct vki_aio_ring {
1490 	unsigned	id;	/* kernel internal index number */
1491 	unsigned	nr;	/* number of io_events */
1492 	unsigned	head;
1493 	unsigned	tail;
1494 
1495 	unsigned	magic;
1496 	unsigned	compat_features;
1497 	unsigned	incompat_features;
1498 	unsigned	header_length;	/* size of aio_ring */
1499 
1500 	struct vki_io_event		io_events[0];
1501 }; /* 128 bytes + ring size */
1502 
1503 //----------------------------------------------------------------------
1504 // From linux-2.6.8.1/include/linux/msg.h
1505 //----------------------------------------------------------------------
1506 
1507 #define VKI_MSG_STAT 11
1508 #define VKI_MSG_INFO 12
1509 
1510 struct vki_msqid_ds {
1511 	struct vki_ipc_perm msg_perm;
1512 	struct vki_msg *msg_first;		/* first message on queue,unused  */
1513 	struct vki_msg *msg_last;		/* last message in queue,unused */
1514 	__vki_kernel_time_t msg_stime;	/* last msgsnd time */
1515 	__vki_kernel_time_t msg_rtime;	/* last msgrcv time */
1516 	__vki_kernel_time_t msg_ctime;	/* last change time */
1517 	unsigned long  msg_lcbytes;	/* Reuse junk fields for 32 bit */
1518 	unsigned long  msg_lqbytes;	/* ditto */
1519 	unsigned short msg_cbytes;	/* current number of bytes on queue */
1520 	unsigned short msg_qnum;	/* number of messages in queue */
1521 	unsigned short msg_qbytes;	/* max number of bytes on queue */
1522 	__vki_kernel_ipc_pid_t msg_lspid;	/* pid of last msgsnd */
1523 	__vki_kernel_ipc_pid_t msg_lrpid;	/* last receive pid */
1524 };
1525 
1526 struct vki_msgbuf {
1527 	long mtype;         /* type of message */
1528 	char mtext[1];      /* message text */
1529 };
1530 
1531 struct vki_msginfo {
1532 	int msgpool;
1533 	int msgmap;
1534 	int msgmax;
1535 	int msgmnb;
1536 	int msgmni;
1537 	int msgssz;
1538 	int msgtql;
1539 	unsigned short  msgseg;
1540 };
1541 
1542 //----------------------------------------------------------------------
1543 // From linux-2.6.8.1/include/linux/shm.h
1544 //----------------------------------------------------------------------
1545 
1546 struct vki_shmid_ds {
1547 	struct vki_ipc_perm		shm_perm;	/* operation perms */
1548 	int			shm_segsz;	/* size of segment (bytes) */
1549 	__vki_kernel_time_t		shm_atime;	/* last attach time */
1550 	__vki_kernel_time_t		shm_dtime;	/* last detach time */
1551 	__vki_kernel_time_t		shm_ctime;	/* last change time */
1552 	__vki_kernel_ipc_pid_t	shm_cpid;	/* pid of creator */
1553 	__vki_kernel_ipc_pid_t	shm_lpid;	/* pid of last operator */
1554 	unsigned short		shm_nattch;	/* no. of current attaches */
1555 	unsigned short 		shm_unused;	/* compatibility */
1556 	void 			*shm_unused2;	/* ditto - used by DIPC */
1557 	void			*shm_unused3;	/* unused */
1558 };
1559 
1560 #define VKI_SHM_RDONLY  010000  /* read-only access */
1561 #define VKI_SHM_RND     020000  /* round attach address to SHMLBA boundary */
1562 
1563 #define VKI_SHM_STAT 	13
1564 #define VKI_SHM_INFO 	14
1565 
1566 /* Obsolete, used only for backwards compatibility */
1567 struct	vki_shminfo {
1568 	int shmmax;
1569 	int shmmin;
1570 	int shmmni;
1571 	int shmseg;
1572 	int shmall;
1573 };
1574 
1575 struct vki_shm_info {
1576 	int used_ids;
1577 	unsigned long shm_tot;	/* total allocated shm */
1578 	unsigned long shm_rss;	/* total resident shm */
1579 	unsigned long shm_swp;	/* total swapped shm */
1580 	unsigned long swap_attempts;
1581 	unsigned long swap_successes;
1582 };
1583 
1584 //----------------------------------------------------------------------
1585 // From linux-2.6.8.1/include/linux/rtc.h
1586 //----------------------------------------------------------------------
1587 
1588 struct vki_rtc_time {
1589 	int tm_sec;
1590 	int tm_min;
1591 	int tm_hour;
1592 	int tm_mday;
1593 	int tm_mon;
1594 	int tm_year;
1595 	int tm_wday;
1596 	int tm_yday;
1597 	int tm_isdst;
1598 };
1599 
1600 #define VKI_RTC_AIE_ON	_VKI_IO('p', 0x01)	/* Alarm int. enable on	*/
1601 #define VKI_RTC_AIE_OFF	_VKI_IO('p', 0x02)	/* ... off		*/
1602 #define VKI_RTC_UIE_ON	_VKI_IO('p', 0x03)	/* Update int. enable on*/
1603 #define VKI_RTC_UIE_OFF	_VKI_IO('p', 0x04)	/* ... off		*/
1604 #define VKI_RTC_PIE_ON	_VKI_IO('p', 0x05)	/* Periodic int. enable on*/
1605 #define VKI_RTC_PIE_OFF	_VKI_IO('p', 0x06)	/* ... off		*/
1606 
1607 #define VKI_RTC_ALM_SET		_VKI_IOW('p', 0x07, struct vki_rtc_time) /* Set alarm time  */
1608 #define VKI_RTC_ALM_READ	_VKI_IOR('p', 0x08, struct vki_rtc_time) /* Read alarm time */
1609 #define VKI_RTC_RD_TIME		_VKI_IOR('p', 0x09, struct vki_rtc_time) /* Read RTC time   */
1610 //#define RTC_SET_TIME	_IOW('p', 0x0a, struct rtc_time) /* Set RTC time    */
1611 #define VKI_RTC_IRQP_READ	_VKI_IOR('p', 0x0b, unsigned long)	 /* Read IRQ rate   */
1612 #define VKI_RTC_IRQP_SET	_VKI_IOW('p', 0x0c, unsigned long)	 /* Set IRQ rate    */
1613 
1614 //----------------------------------------------------------------------
1615 // From linux-2.6.8.1/include/linux/isdn.h
1616 //----------------------------------------------------------------------
1617 
1618 // [[Nb: Resolved this for the common case where CONFIG_COBALT_MICRO_SERVER
1619 //   is not defined]]
1620 #define VKI_ISDN_MAX_CHANNELS   64
1621 
1622 #define VKI_IIOCGETCPS  _VKI_IO('I',21)
1623 
1624 #define VKI_IIOCNETGPN  _VKI_IO('I',34)
1625 
1626 #define VKI_ISDN_MSNLEN          32
1627 
1628 typedef struct {
1629   char name[10];
1630   char phone[VKI_ISDN_MSNLEN];
1631   int  outgoing;
1632 } vki_isdn_net_ioctl_phone;
1633 
1634 //----------------------------------------------------------------------
1635 // From linux-2.6.8.1/include/linux/sockios.h
1636 //----------------------------------------------------------------------
1637 
1638 #define VKI_SIOCOUTQ		VKI_TIOCOUTQ
1639 
1640 #define VKI_SIOCADDRT		0x890B	/* add routing table entry	*/
1641 #define VKI_SIOCDELRT		0x890C	/* delete routing table entry	*/
1642 
1643 #define VKI_SIOCGIFNAME		0x8910	/* get iface name		*/
1644 #define VKI_SIOCGIFCONF		0x8912	/* get iface list		*/
1645 #define VKI_SIOCGIFFLAGS	0x8913	/* get flags			*/
1646 #define VKI_SIOCSIFFLAGS	0x8914	/* set flags			*/
1647 #define VKI_SIOCGIFADDR		0x8915	/* get PA address		*/
1648 #define VKI_SIOCSIFADDR		0x8916	/* set PA address		*/
1649 #define VKI_SIOCGIFDSTADDR	0x8917	/* get remote PA address	*/
1650 #define VKI_SIOCSIFDSTADDR	0x8918	/* set remote PA address	*/
1651 #define VKI_SIOCGIFBRDADDR	0x8919	/* get broadcast PA address	*/
1652 #define VKI_SIOCSIFBRDADDR	0x891a	/* set broadcast PA address	*/
1653 #define VKI_SIOCGIFNETMASK	0x891b	/* get network PA mask		*/
1654 #define VKI_SIOCSIFNETMASK	0x891c	/* set network PA mask		*/
1655 #define VKI_SIOCGIFMETRIC	0x891d	/* get metric			*/
1656 #define VKI_SIOCSIFMETRIC	0x891e	/* set metric			*/
1657 #define VKI_SIOCGIFMTU		0x8921	/* get MTU size			*/
1658 #define VKI_SIOCSIFMTU		0x8922	/* set MTU size			*/
1659 #define	VKI_SIOCSIFHWADDR	0x8924	/* set hardware address 	*/
1660 #define VKI_SIOCGIFHWADDR	0x8927	/* Get hardware address		*/
1661 #define VKI_SIOCGIFINDEX	0x8933	/* name -> if_index mapping	*/
1662 
1663 #define VKI_SIOCGIFTXQLEN	0x8942	/* Get the tx queue length	*/
1664 #define VKI_SIOCSIFTXQLEN	0x8943	/* Set the tx queue length 	*/
1665 
1666 #define VKI_SIOCETHTOOL		0x8946	/* Ethtool interface		*/
1667 
1668 #define VKI_SIOCGMIIPHY		0x8947	/* Get address of MII PHY in use. */
1669 #define VKI_SIOCGMIIREG		0x8948	/* Read MII PHY register.	*/
1670 #define VKI_SIOCSMIIREG		0x8949	/* Write MII PHY register.	*/
1671 
1672 #define VKI_SIOCDARP		0x8953	/* delete ARP table entry	*/
1673 #define VKI_SIOCGARP		0x8954	/* get ARP table entry		*/
1674 #define VKI_SIOCSARP		0x8955	/* set ARP table entry		*/
1675 
1676 #define VKI_SIOCDRARP		0x8960	/* delete RARP table entry	*/
1677 #define VKI_SIOCGRARP		0x8961	/* get RARP table entry		*/
1678 #define VKI_SIOCSRARP		0x8962	/* set RARP table entry		*/
1679 
1680 #define VKI_SIOCGIFMAP		0x8970	/* Get device parameters	*/
1681 #define VKI_SIOCSIFMAP		0x8971	/* Set device parameters	*/
1682 
1683 #define VKI_SIOCSHWTSTAMP	0x89B0	/* Set hardware time stamping */
1684 
1685 //----------------------------------------------------------------------
1686 // From linux-2.6.8.1/include/linux/ppdev.h
1687 //----------------------------------------------------------------------
1688 
1689 #define VKI_PP_MAJOR	99
1690 
1691 #define VKI_PP_IOCTL	'p'
1692 
1693 /* Set mode for read/write (e.g. IEEE1284_MODE_EPP) */
1694 #define VKI_PPSETMODE	_VKI_IOW(VKI_PP_IOCTL, 0x80, int)
1695 
1696 /* Read status */
1697 #define VKI_PPRSTATUS	_VKI_IOR(VKI_PP_IOCTL, 0x81, unsigned char)
1698 //#define PPWSTATUS	OBSOLETE__IOW(PP_IOCTL, 0x82, unsigned char)
1699 
1700 /* Read/write control */
1701 #define VKI_PPRCONTROL	_VKI_IOR(VKI_PP_IOCTL, 0x83, unsigned char)
1702 #define VKI_PPWCONTROL	_VKI_IOW(VKI_PP_IOCTL, 0x84, unsigned char)
1703 
1704 struct vki_ppdev_frob_struct {
1705 	unsigned char mask;
1706 	unsigned char val;
1707 };
1708 #define VKI_PPFCONTROL      _VKI_IOW(VKI_PP_IOCTL, 0x8e, struct vki_ppdev_frob_struct)
1709 
1710 /* Read/write data */
1711 #define VKI_PPRDATA		_VKI_IOR(VKI_PP_IOCTL, 0x85, unsigned char)
1712 #define VKI_PPWDATA		_VKI_IOW(VKI_PP_IOCTL, 0x86, unsigned char)
1713 
1714 /* Claim the port to start using it */
1715 #define VKI_PPCLAIM		_VKI_IO(VKI_PP_IOCTL, 0x8b)
1716 
1717 /* Release the port when you aren't using it */
1718 #define VKI_PPRELEASE	_VKI_IO(VKI_PP_IOCTL, 0x8c)
1719 
1720 /* Yield the port (release it if another driver is waiting,
1721  * then reclaim) */
1722 #define VKI_PPYIELD		_VKI_IO(VKI_PP_IOCTL, 0x8d)
1723 
1724 /* Register device exclusively (must be before PPCLAIM). */
1725 #define VKI_PPEXCL		_VKI_IO(VKI_PP_IOCTL, 0x8f)
1726 
1727 /* Data line direction: non-zero for input mode. */
1728 #define VKI_PPDATADIR	_VKI_IOW(VKI_PP_IOCTL, 0x90, int)
1729 
1730 /* Negotiate a particular IEEE 1284 mode. */
1731 #define VKI_PPNEGOT	_VKI_IOW(VKI_PP_IOCTL, 0x91, int)
1732 
1733 /* Set control lines when an interrupt occurs. */
1734 #define VKI_PPWCTLONIRQ	_VKI_IOW(VKI_PP_IOCTL, 0x92, unsigned char)
1735 
1736 /* Clear (and return) interrupt count. */
1737 #define VKI_PPCLRIRQ	_VKI_IOR(VKI_PP_IOCTL, 0x93, int)
1738 
1739 /* Set the IEEE 1284 phase that we're in (e.g. IEEE1284_PH_FWD_IDLE) */
1740 #define VKI_PPSETPHASE	_VKI_IOW(VKI_PP_IOCTL, 0x94, int)
1741 
1742 /* Set and get port timeout (struct timeval's) */
1743 #define VKI_PPGETTIME	_VKI_IOR(VKI_PP_IOCTL, 0x95, struct vki_timeval)
1744 #define VKI_PPSETTIME	_VKI_IOW(VKI_PP_IOCTL, 0x96, struct vki_timeval)
1745 
1746 #define VKI_PPGETMODES	_VKI_IOR(VKI_PP_IOCTL, 0x97, unsigned int)
1747 
1748 #define VKI_PPGETMODE	_VKI_IOR(VKI_PP_IOCTL, 0x98, int)
1749 #define VKI_PPGETPHASE	_VKI_IOR(VKI_PP_IOCTL, 0x99, int)
1750 
1751 #define VKI_PPGETFLAGS	_VKI_IOR(VKI_PP_IOCTL, 0x9a, int)
1752 #define VKI_PPSETFLAGS	_VKI_IOW(VKI_PP_IOCTL, 0x9b, int)
1753 
1754 //----------------------------------------------------------------------
1755 // From linux-3.16/include/uapi/linux/fs.h
1756 //----------------------------------------------------------------------
1757 
1758 #define VKI_BLKROSET   _VKI_IO(0x12,93)	/* set device read-only (0 = read-write) */
1759 #define VKI_BLKROGET   _VKI_IO(0x12,94)	/* get read-only status (0 = read_write) */
1760 #define VKI_BLKGETSIZE _VKI_IO(0x12,96) /* return device size /512 (long *arg) */
1761 #define VKI_BLKRASET   _VKI_IO(0x12,98)	/* set read ahead for block device */
1762 #define VKI_BLKRAGET   _VKI_IO(0x12,99)	/* get current read ahead setting */
1763 #define VKI_BLKFRASET  _VKI_IO(0x12,100)/* set filesystem (mm/filemap.c) read-ahead */
1764 #define VKI_BLKFRAGET  _VKI_IO(0x12,101)/* get filesystem (mm/filemap.c) read-ahead */
1765 #define VKI_BLKSECTGET _VKI_IO(0x12,103)/* get max sectors per request (ll_rw_blk.c) */
1766 #define VKI_BLKSSZGET  _VKI_IO(0x12,104)/* get block device sector size */
1767 #define VKI_BLKBSZGET  _VKI_IOR(0x12,112,vki_size_t)
1768 #define VKI_BLKBSZSET  _VKI_IOW(0x12,113,vki_size_t)
1769 #define VKI_BLKGETSIZE64 _VKI_IOR(0x12,114,vki_size_t) /* return device size in bytes (u64 *arg) */
1770 #define VKI_BLKPBSZGET _VKI_IO(0x12,123)
1771 #define VKI_BLKDISCARDZEROES _VKI_IO(0x12,124)
1772 
1773 #define VKI_FIBMAP	_VKI_IO(0x00,1)	/* bmap access */
1774 #define VKI_FIGETBSZ    _VKI_IO(0x00,2)	/* get the block size used for bmap */
1775 
1776 //----------------------------------------------------------------------
1777 // From linux-2.6.8.1/include/scsi/sg.h
1778 //----------------------------------------------------------------------
1779 
1780 typedef struct vki_sg_io_hdr
1781 {
1782     int interface_id;           /* [i] 'S' for SCSI generic (required) */
1783     int dxfer_direction;        /* [i] data transfer direction  */
1784     unsigned char cmd_len;      /* [i] SCSI command length ( <= 16 bytes) */
1785     unsigned char mx_sb_len;    /* [i] max length to write to sbp */
1786     unsigned short iovec_count; /* [i] 0 implies no scatter gather */
1787     unsigned int dxfer_len;     /* [i] byte count of data transfer */
1788     void __user *dxferp;	/* [i], [*io] points to data transfer memory
1789 					      or scatter gather list */
1790     unsigned char __user *cmdp; /* [i], [*i] points to command to perform */
1791     void __user *sbp;		/* [i], [*o] points to sense_buffer memory */
1792     unsigned int timeout;       /* [i] MAX_UINT->no timeout (unit: millisec) */
1793     unsigned int flags;         /* [i] 0 -> default, see SG_FLAG... */
1794     int pack_id;                /* [i->o] unused internally (normally) */
1795     void __user * usr_ptr;      /* [i->o] unused internally */
1796     unsigned char status;       /* [o] scsi status */
1797     unsigned char masked_status;/* [o] shifted, masked scsi status */
1798     unsigned char msg_status;   /* [o] messaging level data (optional) */
1799     unsigned char sb_len_wr;    /* [o] byte count actually written to sbp */
1800     unsigned short host_status; /* [o] errors from host adapter */
1801     unsigned short driver_status;/* [o] errors from software driver */
1802     int resid;                  /* [o] dxfer_len - actual_transferred */
1803     unsigned int duration;      /* [o] time taken by cmd (unit: millisec) */
1804     unsigned int info;          /* [o] auxiliary information */
1805 } vki_sg_io_hdr_t;  /* 64 bytes long (on i386) */
1806 
1807 #define VKI_SG_DXFER_NONE -1        /* e.g. a SCSI Test Unit Ready command */
1808 #define VKI_SG_DXFER_TO_DEV -2      /* e.g. a SCSI WRITE command */
1809 #define VKI_SG_DXFER_FROM_DEV -3    /* e.g. a SCSI READ command */
1810 #define VKI_SG_DXFER_TO_FROM_DEV -4 /* treated like SG_DXFER_FROM_DEV with the
1811 				   additional property than during indirect
1812 				   IO the user buffer is copied into the
1813 				   kernel buffers before the transfer */
1814 
1815 typedef struct vki_sg_scsi_id { /* used by SG_GET_SCSI_ID ioctl() */
1816     int host_no;        /* as in "scsi<n>" where 'n' is one of 0, 1, 2 etc */
1817     int channel;
1818     int scsi_id;        /* scsi id of target device */
1819     int lun;
1820     int scsi_type;      /* TYPE_... defined in scsi/scsi.h */
1821     short h_cmd_per_lun;/* host (adapter) maximum commands per lun */
1822     short d_queue_depth;/* device (or adapter) maximum queue length */
1823     int unused[2];      /* probably find a good use, set 0 for now */
1824 } vki_sg_scsi_id_t; /* 32 bytes long on i386 */
1825 
1826 #define VKI_SG_EMULATED_HOST 0x2203 /* true for emulated host adapter (ATAPI) */
1827 
1828 #define VKI_SG_SET_RESERVED_SIZE 0x2275  /* request a new reserved buffer size */
1829 #define VKI_SG_GET_RESERVED_SIZE 0x2272  /* actual size of reserved buffer */
1830 
1831 #define VKI_SG_GET_SCSI_ID 0x2276   /* Yields fd's bus, chan, dev, lun + type */
1832 
1833 #define VKI_SG_GET_SG_TABLESIZE 0x227F  /* 0 implies can't do scatter gather */
1834 
1835 #define VKI_SG_GET_VERSION_NUM 0x2282 /* Example: version 2.1.34 yields 20134 */
1836 
1837 #define VKI_SG_IO 0x2285   /* similar effect as write() followed by read() */
1838 
1839 #define VKI_SG_SET_TIMEOUT 0x2201  /* unit: jiffies (10ms on i386) */
1840 #define VKI_SG_GET_TIMEOUT 0x2202  /* yield timeout as _return_ value */
1841 
1842 //#define SG_GET_COMMAND_Q 0x2270   /* Yields 0 (queuing off) or 1 (on) */
1843 #define VKI_SG_SET_COMMAND_Q 0x2271   /* Change queuing state with 0 or 1 */
1844 
1845 //----------------------------------------------------------------------
1846 // From linux-2.6.34/include/scsi/scsi.h and scsi/scsi_ioctl.h
1847 //----------------------------------------------------------------------
1848 
1849 #define VKI_SCSI_IOCTL_DOORLOCK		0x5380 /* Lock the eject mechanism.  */
1850 #define VKI_SCSI_IOCTL_DOORUNLOCK	0x5381 /* Unlock the mechanism.  */
1851 #define VKI_SCSI_IOCTL_GET_IDLUN	0x5382
1852 #define VKI_SCSI_IOCTL_GET_BUS_NUMBER	0x5386
1853 
1854 struct vki_scsi_idlun {
1855 	__vki_u32 dev_id;
1856 	__vki_u32 host_unique_id;
1857 };
1858 
1859 //----------------------------------------------------------------------
1860 // From linux-2.6.8.1/include/linux/cdrom.h
1861 //----------------------------------------------------------------------
1862 
1863 #define VKI_CDROMPLAYMSF		0x5303 /* Play Audio MSF (struct cdrom_msf) */
1864 #define VKI_CDROMREADTOCHDR		0x5305 /* Read TOC header
1865                                 	           (struct cdrom_tochdr) */
1866 #define VKI_CDROMREADTOCENTRY		0x5306 /* Read TOC entry
1867                                 	           (struct cdrom_tocentry) */
1868 #define VKI_CDROMSUBCHNL		0x530b /* Read subchannel data
1869                                 	           (struct cdrom_subchnl) */
1870 #define VKI_CDROMREADMODE2		0x530c /* Read CDROM mode 2 data (2336 Bytes)
1871                                 	           (struct cdrom_read) */
1872 #define VKI_CDROMREADAUDIO		0x530e /* (struct cdrom_read_audio) */
1873 #define VKI_CDROMMULTISESSION		0x5310 /* Obtain the start-of-last-session
1874                                 	           address of multi session disks
1875                                 	           (struct cdrom_multisession) */
1876 #define VKI_CDROM_GET_MCN		0x5311 /* Obtain the "Universal Product Code"
1877                                 	           if available (struct cdrom_mcn) */
1878 #define VKI_CDROMVOLREAD		0x5313 /* Get the drive's volume setting
1879                                 	          (struct cdrom_volctrl) */
1880 #define VKI_CDROMREADRAW		0x5314	/* read data in raw mode (2352 Bytes)
1881                                 	           (struct cdrom_read) */
1882 #define VKI_CDROM_CLEAR_OPTIONS		0x5321  /* Clear behavior options */
1883 #define VKI_CDROM_DRIVE_STATUS		0x5326  /* Get tray position, etc. */
1884 #define VKI_CDROM_DISC_STATUS		0x5327	/* get CD type information */
1885 #define VKI_CDROM_GET_CAPABILITY	0x5331	/* get capabilities */
1886 
1887 #define VKI_CDROM_SEND_PACKET		0x5393	/* send a packet to the drive */
1888 
1889 struct vki_cdrom_msf0
1890 {
1891 	__vki_u8	minute;
1892 	__vki_u8	second;
1893 	__vki_u8	frame;
1894 };
1895 
1896 union vki_cdrom_addr
1897 {
1898 	struct vki_cdrom_msf0	msf;
1899 	int			lba;
1900 };
1901 
1902 struct vki_cdrom_msf
1903 {
1904 	__vki_u8	cdmsf_min0;	/* start minute */
1905 	__vki_u8	cdmsf_sec0;	/* start second */
1906 	__vki_u8	cdmsf_frame0;	/* start frame */
1907 	__vki_u8	cdmsf_min1;	/* end minute */
1908 	__vki_u8	cdmsf_sec1;	/* end second */
1909 	__vki_u8	cdmsf_frame1;	/* end frame */
1910 };
1911 
1912 struct vki_cdrom_tochdr
1913 {
1914 	__vki_u8	cdth_trk0;	/* start track */
1915 	__vki_u8	cdth_trk1;	/* end track */
1916 };
1917 
1918 struct vki_cdrom_volctrl
1919 {
1920 	__vki_u8	channel0;
1921 	__vki_u8	channel1;
1922 	__vki_u8	channel2;
1923 	__vki_u8	channel3;
1924 };
1925 
1926 struct vki_cdrom_subchnl
1927 {
1928 	__vki_u8	cdsc_format;
1929 	__vki_u8	cdsc_audiostatus;
1930 	__vki_u8	cdsc_adr:	4;
1931 	__vki_u8	cdsc_ctrl:	4;
1932 	__vki_u8	cdsc_trk;
1933 	__vki_u8	cdsc_ind;
1934 	union vki_cdrom_addr cdsc_absaddr;
1935 	union vki_cdrom_addr cdsc_reladdr;
1936 };
1937 
1938 struct vki_cdrom_tocentry
1939 {
1940 	__vki_u8	cdte_track;
1941 	__vki_u8	cdte_adr	:4;
1942 	__vki_u8	cdte_ctrl	:4;
1943 	__vki_u8	cdte_format;
1944 	union vki_cdrom_addr cdte_addr;
1945 	__vki_u8	cdte_datamode;
1946 };
1947 
1948 struct vki_cdrom_read
1949 {
1950 	int	cdread_lba;
1951 	char 	*cdread_bufaddr;
1952 	int	cdread_buflen;
1953 };
1954 
1955 struct vki_cdrom_read_audio
1956 {
1957 	union vki_cdrom_addr addr; /* frame address */
1958 	__vki_u8 addr_format;      /* CDROM_LBA or CDROM_MSF */
1959 	int nframes;           /* number of 2352-byte-frames to read at once */
1960 	__vki_u8 __user *buf;      /* frame buffer (size: nframes*2352 bytes) */
1961 };
1962 
1963 struct vki_cdrom_multisession
1964 {
1965 	union vki_cdrom_addr addr; /* frame address: start-of-last-session
1966 	                           (not the new "frame 16"!).  Only valid
1967 	                           if the "xa_flag" is true. */
1968 	__vki_u8 xa_flag;        /* 1: "is XA disk" */
1969 	__vki_u8 addr_format;    /* CDROM_LBA or CDROM_MSF */
1970 };
1971 
1972 struct vki_cdrom_mcn
1973 {
1974   __vki_u8 medium_catalog_number[14]; /* 13 ASCII digits, null-terminated */
1975 };
1976 
1977 #define VKI_CDROM_PACKET_SIZE	12
1978 
1979 struct vki_cdrom_generic_command
1980 {
1981 	unsigned char 		cmd[VKI_CDROM_PACKET_SIZE];
1982 	unsigned char		__user *buffer;
1983 	unsigned int 		buflen;
1984 	int			stat;
1985         // [[replace with void* to reduce inclusion amounts]]
1986 	void/*struct vki_request_sense	*/__user *sense;
1987 	unsigned char		data_direction;
1988 	int			quiet;
1989 	int			timeout;
1990 	void			__user *reserved[1];	/* unused, actually */
1991 };
1992 
1993 #define VKI_CD_SYNC_SIZE         12 /* 12 sync bytes per raw data frame */
1994 #define VKI_CD_HEAD_SIZE          4 /* header (address) bytes per raw data frame */
1995 #define VKI_CD_FRAMESIZE_RAW   2352 /* bytes per frame, "raw" mode */
1996 #define VKI_CD_FRAMESIZE_RAW0 (VKI_CD_FRAMESIZE_RAW-VKI_CD_SYNC_SIZE-VKI_CD_HEAD_SIZE) /*2336*/
1997 
1998 //----------------------------------------------------------------------
1999 // From linux-2.6.8.1/include/linux/soundcard.h
2000 //----------------------------------------------------------------------
2001 
2002 #ifndef _VKI_SIOWR
2003 #if defined(_VKI_IOWR) && (defined(_AIX) || (!defined(sun) && !defined(sparc) && !defined(__sparc__) && !defined(__INCioctlh) && !defined(__Lynx__)))
2004 /* Use already defined ioctl defines if they exist (except with Sun or Sparc) */
2005 #define	_VKI_SIO		_VKI_IO
2006 #define	_VKI_SIOR		_VKI_IOR
2007 #define	_VKI_SIOW		_VKI_IOW
2008 #define	_VKI_SIOWR		_VKI_IOWR
2009 #else
2010 // [[Valgrind: Install this case if/when necessary]
2011 #error Valgrind: Cannot handle sparc/sun case yet...
2012 #  endif /* _IOWR */
2013 #endif  /* !_VKI_SIOWR */
2014 
2015 #define VKI_SNDCTL_SEQ_CTRLRATE		_VKI_SIOWR('Q', 3, int)	/* Set/get timer resolution (HZ) */
2016 #define VKI_SNDCTL_SEQ_GETOUTCOUNT	_VKI_SIOR ('Q', 4, int)
2017 #define VKI_SNDCTL_SEQ_GETINCOUNT	_VKI_SIOR ('Q', 5, int)
2018 #define VKI_SNDCTL_SEQ_PERCMODE		_VKI_SIOW ('Q', 6, int)
2019 #define VKI_SNDCTL_SEQ_TESTMIDI		_VKI_SIOW ('Q', 8, int)
2020 #define VKI_SNDCTL_SEQ_RESETSAMPLES	_VKI_SIOW ('Q', 9, int)
2021 #define VKI_SNDCTL_SEQ_NRSYNTHS		_VKI_SIOR ('Q',10, int)
2022 #define VKI_SNDCTL_SEQ_NRMIDIS		_VKI_SIOR ('Q',11, int)
2023 #define VKI_SNDCTL_SEQ_GETTIME		_VKI_SIOR ('Q',19, int)
2024 
2025 #define VKI_SNDCTL_TMR_TIMEBASE		_VKI_SIOWR('T', 1, int)
2026 #define VKI_SNDCTL_TMR_TEMPO		_VKI_SIOWR('T', 5, int)
2027 #define VKI_SNDCTL_TMR_SOURCE		_VKI_SIOWR('T', 6, int)
2028 
2029 #define VKI_SNDCTL_MIDI_PRETIME		_VKI_SIOWR('m', 0, int)
2030 #define VKI_SNDCTL_MIDI_MPUMODE		_VKI_SIOWR('m', 1, int)
2031 
2032 #define VKI_SNDCTL_DSP_RESET		_VKI_SIO  ('P', 0)
2033 #define VKI_SNDCTL_DSP_SYNC		_VKI_SIO  ('P', 1)
2034 #define VKI_SNDCTL_DSP_SPEED		_VKI_SIOWR('P', 2, int)
2035 #define VKI_SNDCTL_DSP_STEREO		_VKI_SIOWR('P', 3, int)
2036 #define VKI_SNDCTL_DSP_GETBLKSIZE	_VKI_SIOWR('P', 4, int)
2037 #define VKI_SNDCTL_DSP_CHANNELS		_VKI_SIOWR('P', 6, int)
2038 #define VKI_SOUND_PCM_WRITE_FILTER	_VKI_SIOWR('P', 7, int)
2039 #define VKI_SNDCTL_DSP_POST		_VKI_SIO  ('P', 8)
2040 #define VKI_SNDCTL_DSP_SUBDIVIDE	_VKI_SIOWR('P', 9, int)
2041 #define VKI_SNDCTL_DSP_SETFRAGMENT	_VKI_SIOWR('P',10, int)
2042 
2043 #define VKI_SNDCTL_DSP_GETFMTS		_VKI_SIOR ('P',11, int) /* Returns a mask */
2044 #define VKI_SNDCTL_DSP_SETFMT		_VKI_SIOWR('P', 5, int) /* Selects ONE fmt */
2045 
2046 typedef struct vki_audio_buf_info {
2047 			int fragments;	/* # of available fragments (partially usend ones not counted) */
2048 			int fragstotal;	/* Total # of fragments allocated */
2049 			int fragsize;	/* Size of a fragment in bytes */
2050 
2051 			int bytes;	/* Available space in bytes (includes partially used fragments) */
2052 			/* Note! 'bytes' could be more than fragments*fragsize */
2053 		} vki_audio_buf_info;
2054 
2055 #define VKI_SNDCTL_DSP_GETOSPACE	_VKI_SIOR ('P',12, vki_audio_buf_info)
2056 #define VKI_SNDCTL_DSP_GETISPACE	_VKI_SIOR ('P',13, vki_audio_buf_info)
2057 #define VKI_SNDCTL_DSP_NONBLOCK		_VKI_SIO  ('P',14)
2058 #define VKI_SNDCTL_DSP_GETCAPS		_VKI_SIOR ('P',15, int)
2059 
2060 #define VKI_SNDCTL_DSP_GETTRIGGER	_VKI_SIOR ('P',16, int)
2061 #define VKI_SNDCTL_DSP_SETTRIGGER	_VKI_SIOW ('P',16, int)
2062 
2063 #define VKI_SNDCTL_DSP_SETSYNCRO	_VKI_SIO  ('P', 21)
2064 #define VKI_SNDCTL_DSP_SETDUPLEX	_VKI_SIO  ('P', 22)
2065 #define VKI_SNDCTL_DSP_GETODELAY	_VKI_SIOR ('P', 23, int)
2066 
2067 #define VKI_SNDCTL_DSP_GETCHANNELMASK	_VKI_SIOWR('P', 64, int)
2068 #define VKI_SNDCTL_DSP_BIND_CHANNEL	_VKI_SIOWR('P', 65, int)
2069 
2070 #define VKI_SNDCTL_DSP_SETSPDIF		_VKI_SIOW ('P', 66, int)
2071 #define VKI_SNDCTL_DSP_GETSPDIF		_VKI_SIOR ('P', 67, int)
2072 
2073 #define VKI_SOUND_PCM_READ_RATE		_VKI_SIOR ('P', 2, int)
2074 #define VKI_SOUND_PCM_READ_CHANNELS	_VKI_SIOR ('P', 6, int)
2075 #define VKI_SOUND_PCM_READ_BITS		_VKI_SIOR ('P', 5, int)
2076 #define VKI_SOUND_PCM_READ_FILTER	_VKI_SIOR ('P', 7, int)
2077 
2078 
2079 //----------------------------------------------------------------------
2080 // From linux-2.6.8.1/include/linux/hdreg.h
2081 //----------------------------------------------------------------------
2082 
2083 struct vki_hd_geometry {
2084       unsigned char heads;
2085       unsigned char sectors;
2086       unsigned short cylinders;
2087       unsigned long start;
2088 };
2089 
2090 #define VKI_HDIO_GETGEO		0x0301	/* get device geometry */
2091 #define VKI_HDIO_GET_DMA	0x030b	/* get use-dma flag */
2092 #define VKI_HDIO_GET_IDENTITY	0x030d	/* get IDE identification info */
2093 
2094 // [[Nb: done like this because the original type is a huge struct that will
2095 //   always be the same size.]]
2096 #define VKI_SIZEOF_STRUCT_HD_DRIVEID   512
2097 
2098 //----------------------------------------------------------------------
2099 // From linux-2.6.8.1/include/linux/fb.h
2100 //----------------------------------------------------------------------
2101 
2102 #define VKI_FBIOGET_VSCREENINFO	0x4600
2103 #define VKI_FBIOPUT_VSCREENINFO	0x4601
2104 #define VKI_FBIOGET_FSCREENINFO	0x4602
2105 #define VKI_FBIOPAN_DISPLAY	0x4606
2106 
2107 struct vki_fb_fix_screeninfo {
2108 	char id[16];			/* identification string eg "TT Builtin" */
2109 	unsigned long smem_start;	/* Start of frame buffer mem */
2110 					/* (physical address) */
2111 	__vki_u32 smem_len;			/* Length of frame buffer mem */
2112 	__vki_u32 type;			/* see FB_TYPE_*		*/
2113 	__vki_u32 type_aux;		/* Interleave for interleaved Planes */
2114 	__vki_u32 visual;		/* see FB_VISUAL_*		*/
2115 	__vki_u16 xpanstep;		/* zero if no hardware panning  */
2116 	__vki_u16 ypanstep;		/* zero if no hardware panning  */
2117 	__vki_u16 ywrapstep;		/* zero if no hardware ywrap    */
2118 	__vki_u32 line_length;		/* length of a line in bytes    */
2119 	unsigned long mmio_start;	/* Start of Memory Mapped I/O   */
2120 					/* (physical address) */
2121 	__vki_u32 mmio_len;		/* Length of Memory Mapped I/O  */
2122 	__vki_u32 accel;		/* Indicate to driver which	*/
2123 					/*  specific chip/card we have	*/
2124 	__vki_u16 reserved[3];		/* Reserved for future compatibility */
2125 };
2126 
2127 struct vki_fb_bitfield {
2128 	__vki_u32 offset;		/* beginning of bitfield	*/
2129 	__vki_u32 length;		/* length of bitfield		*/
2130 	__vki_u32 msb_right;		/* != 0 : Most significant bit is */
2131 					/* right */
2132 };
2133 
2134 struct vki_fb_var_screeninfo {
2135 	__vki_u32 xres;			/* visible resolution		*/
2136 	__vki_u32 yres;
2137 	__vki_u32 xres_virtual;		/* virtual resolution		*/
2138 	__vki_u32 yres_virtual;
2139 	__vki_u32 xoffset;		/* offset from virtual to visible */
2140 	__vki_u32 yoffset;		/* resolution			*/
2141 
2142 	__vki_u32 bits_per_pixel;	/* guess what			*/
2143 	__vki_u32 grayscale;		/* != 0 Graylevels instead of colors */
2144 
2145 	struct vki_fb_bitfield red;	/* bitfield in fb mem if true color, */
2146 	struct vki_fb_bitfield green;	/* else only length is significant */
2147 	struct vki_fb_bitfield blue;
2148 	struct vki_fb_bitfield transp;	/* transparency			*/
2149 
2150 	__vki_u32 nonstd;		/* != 0 Non standard pixel format */
2151 
2152 	__vki_u32 activate;		/* see FB_ACTIVATE_*		*/
2153 
2154 	__vki_u32 height;		/* height of picture in mm    */
2155 	__vki_u32 width;		/* width of picture in mm     */
2156 
2157 	__vki_u32 accel_flags;		/* (OBSOLETE) see fb_info.flags */
2158 
2159 	/* Timing: All values in pixclocks, except pixclock (of course) */
2160 	__vki_u32 pixclock;		/* pixel clock in ps (pico seconds) */
2161 	__vki_u32 left_margin;		/* time from sync to picture	*/
2162 	__vki_u32 right_margin;		/* time from picture to sync	*/
2163 	__vki_u32 upper_margin;		/* time from sync to picture	*/
2164 	__vki_u32 lower_margin;
2165 	__vki_u32 hsync_len;		/* length of horizontal sync	*/
2166 	__vki_u32 vsync_len;		/* length of vertical sync	*/
2167 	__vki_u32 sync;			/* see FB_SYNC_*		*/
2168 	__vki_u32 vmode;		/* see FB_VMODE_*		*/
2169 	__vki_u32 rotate;		/* angle we rotate counter clockwise */
2170 	__vki_u32 reserved[5];		/* Reserved for future compatibility */
2171 };
2172 
2173 //----------------------------------------------------------------------
2174 // From linux-2.6.9/include/linux/kd.h
2175 //----------------------------------------------------------------------
2176 
2177 #define VKI_GIO_FONT       0x4B60  /* gets font in expanded form */
2178 #define VKI_PIO_FONT       0x4B61  /* use font in expanded form */
2179 
2180 #define VKI_GIO_FONTX      0x4B6B  /* get font using struct consolefontdesc */
2181 #define VKI_PIO_FONTX      0x4B6C  /* set font using struct consolefontdesc */
2182 struct vki_consolefontdesc {
2183 	unsigned short charcount;	/* characters in font (256 or 512) */
2184 	unsigned short charheight;	/* scan lines per character (1-32) */
2185 	char __user *chardata;		/* font data in expanded form */
2186 };
2187 
2188 #define VKI_PIO_FONTRESET  0x4B6D  /* reset to default font */
2189 
2190 #define VKI_GIO_CMAP       0x4B70  /* gets colour palette on VGA+ */
2191 #define VKI_PIO_CMAP       0x4B71  /* sets colour palette on VGA+ */
2192 
2193 #define VKI_KIOCSOUND      0x4B2F  /* start sound generation (0 for off) */
2194 #define VKI_KDMKTONE       0x4B30  /* generate tone */
2195 
2196 #define VKI_KDGETLED       0x4B31  /* return current led state */
2197 #define VKI_KDSETLED       0x4B32  /* set led state [lights, not flags] */
2198 
2199 #define VKI_KDGKBTYPE      0x4B33  /* get keyboard type */
2200 
2201 #define VKI_KDADDIO        0x4B34  /* add i/o port as valid */
2202 #define VKI_KDDELIO        0x4B35  /* del i/o port as valid */
2203 #define VKI_KDENABIO       0x4B36  /* enable i/o to video board */
2204 #define VKI_KDDISABIO      0x4B37  /* disable i/o to video board */
2205 
2206 #define VKI_KDSETMODE      0x4B3A  /* set text/graphics mode */
2207 #define VKI_KDGETMODE      0x4B3B  /* get current mode */
2208 
2209 #define VKI_KDMAPDISP      0x4B3C  /* map display into address space */
2210 #define VKI_KDUNMAPDISP    0x4B3D  /* unmap display from address space */
2211 
2212 #define		VKI_E_TABSZ		256
2213 #define VKI_GIO_SCRNMAP    0x4B40  /* get screen mapping from kernel */
2214 #define VKI_PIO_SCRNMAP	   0x4B41  /* put screen mapping table in kernel */
2215 #define VKI_GIO_UNISCRNMAP 0x4B69  /* get full Unicode screen mapping */
2216 #define VKI_PIO_UNISCRNMAP 0x4B6A  /* set full Unicode screen mapping */
2217 
2218 #define VKI_GIO_UNIMAP     0x4B66  /* get unicode-to-font mapping from kernel */
2219 struct vki_unipair {
2220 	unsigned short unicode;
2221 	unsigned short fontpos;
2222 };
2223 struct vki_unimapdesc {
2224 	unsigned short entry_ct;
2225 	struct vki_unipair __user *entries;
2226 };
2227 #define VKI_PIO_UNIMAP     0x4B67  /* put unicode-to-font mapping in kernel */
2228 #define VKI_PIO_UNIMAPCLR  0x4B68  /* clear table, possibly advise hash algorithm */
2229 struct vki_unimapinit {
2230 	unsigned short advised_hashsize;  /* 0 if no opinion */
2231 	unsigned short advised_hashstep;  /* 0 if no opinion */
2232 	unsigned short advised_hashlevel; /* 0 if no opinion */
2233 };
2234 
2235 #define VKI_KDGKBMODE      0x4B44  /* gets current keyboard mode */
2236 #define VKI_KDSKBMODE      0x4B45  /* sets current keyboard mode */
2237 
2238 #define VKI_KDGKBMETA      0x4B62  /* gets meta key handling mode */
2239 #define VKI_KDSKBMETA      0x4B63  /* sets meta key handling mode */
2240 
2241 #define VKI_KDGKBLED       0x4B64  /* get led flags (not lights) */
2242 #define VKI_KDSKBLED       0x4B65  /* set led flags (not lights) */
2243 
2244 struct vki_kbentry {
2245 	unsigned char kb_table;
2246 	unsigned char kb_index;
2247 	unsigned short kb_value;
2248 };
2249 #define VKI_KDGKBENT       0x4B46  /* gets one entry in translation table */
2250 #define VKI_KDSKBENT       0x4B47  /* sets one entry in translation table */
2251 
2252 struct vki_kbsentry {
2253 	unsigned char kb_func;
2254 	unsigned char kb_string[512];
2255 };
2256 #define VKI_KDGKBSENT      0x4B48  /* gets one function key string entry */
2257 #define VKI_KDSKBSENT      0x4B49  /* sets one function key string entry */
2258 
2259 struct vki_kbdiacr {
2260         unsigned char diacr, base, result;
2261 };
2262 struct vki_kbdiacrs {
2263         unsigned int kb_cnt;    /* number of entries in following array */
2264 	struct vki_kbdiacr kbdiacr[256];    /* MAX_DIACR from keyboard.h */
2265 };
2266 #define VKI_KDGKBDIACR     0x4B4A  /* read kernel accent table */
2267 #define VKI_KDSKBDIACR     0x4B4B  /* write kernel accent table */
2268 
2269 struct vki_kbkeycode {
2270 	unsigned int scancode, keycode;
2271 };
2272 #define VKI_KDGETKEYCODE   0x4B4C  /* read kernel keycode table entry */
2273 #define VKI_KDSETKEYCODE   0x4B4D  /* write kernel keycode table entry */
2274 
2275 #define VKI_KDSIGACCEPT    0x4B4E  /* accept kbd generated signals */
2276 
2277 struct vki_kbd_repeat {
2278 	int delay;	/* in msec; <= 0: don't change */
2279 	int period;	/* in msec; <= 0: don't change */
2280 			/* earlier this field was misnamed "rate" */
2281 };
2282 #define VKI_KDKBDREP       0x4B52  /* set keyboard delay/repeat rate;
2283                                     * actually used values are returned */
2284 
2285 #define VKI_KDFONTOP       0x4B72  /* font operations */
2286 
2287 struct vki_console_font_op {
2288 	unsigned int op;	/* operation code KD_FONT_OP_* */
2289 	unsigned int flags;	/* KD_FONT_FLAG_* */
2290 	unsigned int width, height;	/* font size */
2291 	unsigned int charcount;
2292 	unsigned char __user *data;	/* font data with height fixed to 32 */
2293 };
2294 
2295 #define VKI_KD_FONT_OP_SET		0	/* Set font */
2296 #define VKI_KD_FONT_OP_GET		1	/* Get font */
2297 #define VKI_KD_FONT_OP_SET_DEFAULT	2	/* Set font to default, data points to name / NULL */
2298 #define VKI_KD_FONT_OP_COPY		3	/* Copy from another console */
2299 
2300 //----------------------------------------------------------------------
2301 // From linux-2.6.9/include/linux/kb.h
2302 //----------------------------------------------------------------------
2303 
2304 typedef __vki_kernel_uid32_t vki_qid_t; /* Type in which we store ids in memory */
2305 
2306 //----------------------------------------------------------------------
2307 // From linux-2.6.20.1/include/linux/ptrace.h
2308 //----------------------------------------------------------------------
2309 
2310 #define VKI_PTRACE_TRACEME         0
2311 #define VKI_PTRACE_PEEKTEXT	   1
2312 #define VKI_PTRACE_PEEKDATA	   2
2313 #define VKI_PTRACE_PEEKUSR	   3
2314 #define VKI_PTRACE_POKEUSR	   6
2315 
2316 #define VKI_PTRACE_DETACH         17
2317 
2318 #define VKI_PTRACE_GETEVENTMSG	0x4201
2319 #define VKI_PTRACE_GETSIGINFO	0x4202
2320 #define VKI_PTRACE_SETSIGINFO	0x4203
2321 #define VKI_PTRACE_GETREGSET	0x4204
2322 #define VKI_PTRACE_SETREGSET	0x4205
2323 
2324 //----------------------------------------------------------------------
2325 // From linux-2.6.14/include/sound/asound.h
2326 //----------------------------------------------------------------------
2327 
2328 enum {
2329 	VKI_SNDRV_PCM_IOCTL_HW_FREE = _VKI_IO('A', 0x12),
2330 	VKI_SNDRV_PCM_IOCTL_HWSYNC = _VKI_IO('A', 0x22),
2331 	VKI_SNDRV_PCM_IOCTL_PREPARE = _VKI_IO('A', 0x40),
2332 	VKI_SNDRV_PCM_IOCTL_RESET = _VKI_IO('A', 0x41),
2333 	VKI_SNDRV_PCM_IOCTL_START = _VKI_IO('A', 0x42),
2334 	VKI_SNDRV_PCM_IOCTL_DROP = _VKI_IO('A', 0x43),
2335 	VKI_SNDRV_PCM_IOCTL_DRAIN = _VKI_IO('A', 0x44),
2336 	VKI_SNDRV_PCM_IOCTL_PAUSE = _VKI_IOW('A', 0x45, int),
2337 	VKI_SNDRV_PCM_IOCTL_RESUME = _VKI_IO('A', 0x47),
2338 	VKI_SNDRV_PCM_IOCTL_XRUN = _VKI_IO('A', 0x48),
2339 	VKI_SNDRV_PCM_IOCTL_LINK = _VKI_IOW('A', 0x60, int),
2340 	VKI_SNDRV_PCM_IOCTL_UNLINK = _VKI_IO('A', 0x61),
2341 };
2342 
2343 enum {
2344 	VKI_SNDRV_TIMER_IOCTL_START = _VKI_IO('T', 0xa0),
2345 	VKI_SNDRV_TIMER_IOCTL_STOP = _VKI_IO('T', 0xa1),
2346 	VKI_SNDRV_TIMER_IOCTL_CONTINUE = _VKI_IO('T', 0xa2),
2347 	VKI_SNDRV_TIMER_IOCTL_PAUSE = _VKI_IO('T', 0xa3),
2348 };
2349 
2350 struct vki_snd_ctl_card_info {
2351 	int card;			/* card number */
2352 	int pad;			/* reserved for future (was type) */
2353 	unsigned char id[16];		/* ID of card (user selectable) */
2354 	unsigned char driver[16];	/* Driver name */
2355 	unsigned char name[32];		/* Short name of soundcard */
2356 	unsigned char longname[80];	/* name + info text about soundcard */
2357 	unsigned char reserved_[16];	/* reserved for future (was ID of mixer) */
2358 	unsigned char mixername[80];	/* visual mixer identification */
2359 	unsigned char components[128];	/* card components / fine identification, delimited with one space (AC97 etc..) */
2360 };
2361 
2362 typedef int vki_snd_ctl_elem_iface_t;
2363 #define	VKI_SNDRV_CTL_ELEM_IFACE_CARD		((vki_snd_ctl_elem_iface_t) 0) /* global control */
2364 #define	VKI_SNDRV_CTL_ELEM_IFACE_HWDEP		((vki_snd_ctl_elem_iface_t) 1) /* hardware dependent device */
2365 #define	VKI_SNDRV_CTL_ELEM_IFACE_MIXER		((vki_snd_ctl_elem_iface_t) 2) /* virtual mixer device */
2366 #define	VKI_SNDRV_CTL_ELEM_IFACE_PCM		((vki_snd_ctl_elem_iface_t) 3) /* PCM device */
2367 #define	VKI_SNDRV_CTL_ELEM_IFACE_RAWMIDI	((vki_snd_ctl_elem_iface_t) 4) /* RawMidi device */
2368 #define	VKI_SNDRV_CTL_ELEM_IFACE_TIMER		((vki_snd_ctl_elem_iface_t) 5) /* timer device */
2369 #define	VKI_SNDRV_CTL_ELEM_IFACE_SEQUENCER	((vki_snd_ctl_elem_iface_t) 6) /* sequencer client */
2370 #define	VKI_SNDRV_CTL_ELEM_IFACE_LAST		VKI_SNDRV_CTL_ELEM_IFACE_SEQUENCER
2371 
2372 struct vki_snd_ctl_elem_id {
2373 	unsigned int numid;		/* numeric identifier, zero = invalid */
2374 	vki_snd_ctl_elem_iface_t iface;	/* interface identifier */
2375 	unsigned int device;		/* device/client number */
2376 	unsigned int subdevice;		/* subdevice (substream) number */
2377 	unsigned char name[44];		/* ASCII name of item */
2378 	unsigned int index;		/* index of item */
2379 };
2380 
2381 struct vki_snd_ctl_elem_list {
2382 	unsigned int offset;		/* W: first element ID to get */
2383 	unsigned int space;		/* W: count of element IDs to get */
2384 	unsigned int used;		/* R: count of element IDs set */
2385 	unsigned int count;		/* R: count of all elements */
2386 	struct vki_snd_ctl_elem_id __user *pids; /* R: IDs */
2387 	unsigned char reserved[50];
2388 };
2389 
2390 struct vki_snd_ctl_tlv {
2391     unsigned int numid;	/* control element numeric identification */
2392     unsigned int length;	/* in bytes aligned to 4 */
2393     unsigned int tlv[0];	/* first TLV */
2394 };
2395 
2396 #define VKI_SNDRV_CTL_IOCTL_PVERSION	_VKI_IOR('U', 0x00, int)
2397 #define VKI_SNDRV_CTL_IOCTL_CARD_INFO	_VKI_IOR('U', 0x01, struct vki_snd_ctl_card_info)
2398 #define VKI_SNDRV_CTL_IOCTL_ELEM_LIST	_VKI_IOWR('U', 0x10, struct vki_snd_ctl_elem_list)
2399 #define VKI_SNDRV_CTL_IOCTL_TLV_READ	_VKI_IOWR('U', 0x1a, struct vki_snd_ctl_tlv)
2400 #define VKI_SNDRV_CTL_IOCTL_TLV_WRITE	_VKI_IOWR('U', 0x1b, struct vki_snd_ctl_tlv)
2401 #define VKI_SNDRV_CTL_IOCTL_TLV_COMMAND	_VKI_IOWR('U', 0x1c, struct vki_snd_ctl_tlv)
2402 
2403 //----------------------------------------------------------------------
2404 // From linux-2.6.15.4/include/linux/serial.h
2405 //----------------------------------------------------------------------
2406 
2407 struct vki_serial_icounter_struct {
2408 	int cts, dsr, rng, dcd;
2409 	int rx, tx;
2410 	int frame, overrun, parity, brk;
2411 	int buf_overrun;
2412 	int reserved[9];
2413 };
2414 
2415 //----------------------------------------------------------------------
2416 // From linux-2.6.16/include/linux/vt.h
2417 //----------------------------------------------------------------------
2418 
2419 #define VKI_VT_OPENQRY	0x5600	/* find available vt */
2420 
2421 struct vki_vt_mode {
2422 	char mode;		/* vt mode */
2423 	char waitv;		/* if set, hang on writes if not active */
2424 	short relsig;		/* signal to raise on release req */
2425 	short acqsig;		/* signal to raise on acquisition */
2426 	short frsig;		/* unused (set to 0) */
2427 };
2428 #define VKI_VT_GETMODE	0x5601	/* get mode of active vt */
2429 #define VKI_VT_SETMODE	0x5602	/* set mode of active vt */
2430 
2431 struct vki_vt_stat {
2432 	unsigned short v_active;	/* active vt */
2433 	unsigned short v_signal;	/* signal to send */
2434 	unsigned short v_state;		/* vt bitmask */
2435 };
2436 #define VKI_VT_GETSTATE	0x5603	/* get global vt state info */
2437 #define VKI_VT_SENDSIG	0x5604	/* signal to send to bitmask of vts */
2438 
2439 #define VKI_VT_RELDISP	0x5605	/* release display */
2440 
2441 #define VKI_VT_ACTIVATE	0x5606	/* make vt active */
2442 #define VKI_VT_WAITACTIVE	0x5607	/* wait for vt active */
2443 #define VKI_VT_DISALLOCATE	0x5608  /* free memory associated to vt */
2444 
2445 struct vki_vt_sizes {
2446 	unsigned short v_rows;		/* number of rows */
2447 	unsigned short v_cols;		/* number of columns */
2448 	unsigned short v_scrollsize;	/* number of lines of scrollback */
2449 };
2450 #define VKI_VT_RESIZE	0x5609	/* set kernel's idea of screensize */
2451 
2452 struct vki_vt_consize {
2453 	unsigned short v_rows;	/* number of rows */
2454 	unsigned short v_cols;	/* number of columns */
2455 	unsigned short v_vlin;	/* number of pixel rows on screen */
2456 	unsigned short v_clin;	/* number of pixel rows per character */
2457 	unsigned short v_vcol;	/* number of pixel columns on screen */
2458 	unsigned short v_ccol;	/* number of pixel columns per character */
2459 };
2460 #define VKI_VT_RESIZEX      0x560A  /* set kernel's idea of screensize + more */
2461 #define VKI_VT_LOCKSWITCH   0x560B  /* disallow vt switching */
2462 #define VKI_VT_UNLOCKSWITCH 0x560C  /* allow vt switching */
2463 
2464 //----------------------------------------------------------------------
2465 // From linux-2.6.19/include/linux/prctl.h
2466 //----------------------------------------------------------------------
2467 
2468 #define VKI_PR_SET_PDEATHSIG  1  /* Second arg is a signal */
2469 #define VKI_PR_GET_PDEATHSIG  2  /* Second arg is a ptr to return the signal */
2470 
2471 #define VKI_PR_GET_DUMPABLE   3
2472 #define VKI_PR_SET_DUMPABLE   4
2473 
2474 #define VKI_PR_GET_UNALIGN	  5
2475 #define VKI_PR_SET_UNALIGN	  6
2476 # define VKI_PR_UNALIGN_NOPRINT	1	/* silently fix up unaligned user accesses */
2477 # define VKI_PR_UNALIGN_SIGBUS	2	/* generate SIGBUS on unaligned user access */
2478 
2479 #define VKI_PR_GET_KEEPCAPS   7
2480 #define VKI_PR_SET_KEEPCAPS   8
2481 
2482 #define VKI_PR_GET_FPEMU  9
2483 #define VKI_PR_SET_FPEMU 10
2484 # define VKI_PR_FPEMU_NOPRINT	1	/* silently emulate fp operations accesses */
2485 # define VKI_PR_FPEMU_SIGFPE	2	/* don't emulate fp operations, send SIGFPE instead */
2486 
2487 #define VKI_PR_GET_FPEXC	11
2488 #define VKI_PR_SET_FPEXC	12
2489 # define VKI_PR_FP_EXC_SW_ENABLE	0x80	/* Use FPEXC for FP exception enables */
2490 # define VKI_PR_FP_EXC_DIV		0x010000	/* floating point divide by zero */
2491 # define VKI_PR_FP_EXC_OVF		0x020000	/* floating point overflow */
2492 # define VKI_PR_FP_EXC_UND		0x040000	/* floating point underflow */
2493 # define VKI_PR_FP_EXC_RES		0x080000	/* floating point inexact result */
2494 # define VKI_PR_FP_EXC_INV		0x100000	/* floating point invalid operation */
2495 # define VKI_PR_FP_EXC_DISABLED	0	/* FP exceptions disabled */
2496 # define VKI_PR_FP_EXC_NONRECOV	1	/* async non-recoverable exc. mode */
2497 # define VKI_PR_FP_EXC_ASYNC	2	/* async recoverable exception mode */
2498 # define VKI_PR_FP_EXC_PRECISE	3	/* precise exception mode */
2499 
2500 #define VKI_PR_GET_TIMING   13
2501 #define VKI_PR_SET_TIMING   14
2502 # define VKI_PR_TIMING_STATISTICAL  0       /* Normal, traditional,
2503                                                    statistical process timing */
2504 # define VKI_PR_TIMING_TIMESTAMP    1       /* Accurate timestamp based
2505                                                    process timing */
2506 
2507 #define VKI_PR_SET_NAME    15		/* Set process name */
2508 #define VKI_PR_GET_NAME    16		/* Get process name */
2509 
2510 #define VKI_PR_GET_ENDIAN	19
2511 #define VKI_PR_SET_ENDIAN	20
2512 # define VKI_PR_ENDIAN_BIG		0
2513 # define VKI_PR_ENDIAN_LITTLE	1	/* True little endian mode */
2514 # define VKI_PR_ENDIAN_PPC_LITTLE	2	/* "PowerPC" pseudo little endian */
2515 
2516 #define VKI_PR_SET_SECCOMP 22
2517 
2518 #define VKI_PR_SET_PTRACER 0x59616d61
2519 
2520 //----------------------------------------------------------------------
2521 // From linux-2.6.19/include/linux/usbdevice_fs.h
2522 //----------------------------------------------------------------------
2523 
2524 struct vki_usbdevfs_ctrltransfer {
2525 	__vki_u8 bRequestType;
2526 	__vki_u8 bRequest;
2527 	__vki_u16 wValue;
2528 	__vki_u16 wIndex;
2529 	__vki_u16 wLength;
2530 	__vki_u32 timeout;  /* in milliseconds */
2531  	void __user *data;
2532 };
2533 
2534 struct vki_usbdevfs_bulktransfer {
2535 	unsigned int ep;
2536 	unsigned int len;
2537 	unsigned int timeout; /* in milliseconds */
2538 	void __user *data;
2539 };
2540 
2541 #define VKI_USBDEVFS_MAXDRIVERNAME 255
2542 
2543 struct vki_usbdevfs_getdriver {
2544 	unsigned int interface;
2545 	char driver[VKI_USBDEVFS_MAXDRIVERNAME + 1];
2546 };
2547 
2548 struct vki_usbdevfs_connectinfo {
2549 	unsigned int devnum;
2550 	unsigned char slow;
2551 };
2552 
2553 struct vki_usbdevfs_iso_packet_desc {
2554 	unsigned int length;
2555 	unsigned int actual_length;
2556 	unsigned int status;
2557 };
2558 
2559 struct vki_usbdevfs_urb {
2560 	unsigned char type;
2561 	unsigned char endpoint;
2562 	int status;
2563 	unsigned int flags;
2564 	void __user *buffer;
2565 	int buffer_length;
2566 	int actual_length;
2567 	int start_frame;
2568 	int number_of_packets;
2569 	int error_count;
2570 	unsigned int signr;  /* signal to be sent on error, -1 if none should be sent */
2571 	void *usercontext;
2572 	struct vki_usbdevfs_iso_packet_desc iso_frame_desc[0];
2573 };
2574 
2575 struct vki_usbdevfs_ioctl {
2576 	int	ifno;		/* interface 0..N ; negative numbers reserved */
2577 	int	ioctl_code;	/* MUST encode size + direction of data so the
2578 				 * macros in <asm/ioctl.h> give correct values */
2579 	void __user *data;	/* param buffer (in, or out) */
2580 };
2581 
2582 #define VKI_USBDEVFS_CONTROL           _VKI_IOWR('U', 0, struct vki_usbdevfs_ctrltransfer)
2583 #define VKI_USBDEVFS_BULK              _VKI_IOWR('U', 2, struct vki_usbdevfs_bulktransfer)
2584 #define VKI_USBDEVFS_GETDRIVER         _VKI_IOW('U', 8, struct vki_usbdevfs_getdriver)
2585 #define VKI_USBDEVFS_SUBMITURB         _VKI_IOR('U', 10, struct vki_usbdevfs_urb)
2586 #define VKI_USBDEVFS_DISCARDURB        _VKI_IO('U', 11)
2587 #define VKI_USBDEVFS_REAPURB           _VKI_IOW('U', 12, void *)
2588 #define VKI_USBDEVFS_REAPURBNDELAY     _VKI_IOW('U', 13, void *)
2589 #define VKI_USBDEVFS_CONNECTINFO       _VKI_IOW('U', 17, struct vki_usbdevfs_connectinfo)
2590 #define VKI_USBDEVFS_IOCTL             _VKI_IOWR('U', 18, struct vki_usbdevfs_ioctl)
2591 #define VKI_USBDEVFS_RESET             _VKI_IO('U', 20)
2592 
2593 #define VKI_USBDEVFS_URB_TYPE_ISO              0
2594 #define VKI_USBDEVFS_URB_TYPE_INTERRUPT        1
2595 #define VKI_USBDEVFS_URB_TYPE_CONTROL          2
2596 #define VKI_USBDEVFS_URB_TYPE_BULK             3
2597 
2598 // [[this is missing in usbdevice_fs.h]]
2599 struct vki_usbdevfs_setuppacket {
2600        __vki_u8 bRequestType;
2601        __vki_u8 bRequest;
2602        __vki_u16 wValue;
2603        __vki_u16 wIndex;
2604        __vki_u16 wLength;
2605 };
2606 
2607 //----------------------------------------------------------------------
2608 // From linux-2.6.20.1/include/linux/i2c.h
2609 //----------------------------------------------------------------------
2610 
2611 #define VKI_I2C_SMBUS_QUICK             0
2612 #define VKI_I2C_SMBUS_BYTE              1
2613 #define VKI_I2C_SMBUS_BYTE_DATA         2
2614 #define VKI_I2C_SMBUS_WORD_DATA         3
2615 #define VKI_I2C_SMBUS_PROC_CALL         4
2616 #define VKI_I2C_SMBUS_BLOCK_DATA        5
2617 #define VKI_I2C_SMBUS_I2C_BLOCK_BROKEN  6
2618 #define VKI_I2C_SMBUS_BLOCK_PROC_CALL   7           /* SMBus 2.0 */
2619 #define VKI_I2C_SMBUS_I2C_BLOCK_DATA    8
2620 
2621 /* smbus_access read or write markers */
2622 #define VKI_I2C_SMBUS_READ  1
2623 #define VKI_I2C_SMBUS_WRITE 0
2624 
2625 #define VKI_I2C_SLAVE        0x0703  /* Change slave address                 */
2626                                      /* Attn.: Slave address is 7 or 10 bits */
2627 #define VKI_I2C_SLAVE_FORCE  0x0706  /* Change slave address                 */
2628                                      /* Attn.: Slave address is 7 or 10 bits */
2629                                      /* This changes the address, even if it */
2630                                      /* is already taken!                    */
2631 #define VKI_I2C_TENBIT       0x0704  /* 0 for 7 bit addrs, != 0 for 10 bit   */
2632 #define VKI_I2C_FUNCS        0x0705  /* Get the adapter functionality */
2633 #define VKI_I2C_RDWR         0x0707  /* Combined R/W transfer (one STOP only) */
2634 #define VKI_I2C_PEC          0x0708  /* != 0 for SMBus PEC                   */
2635 #define VKI_I2C_SMBUS        0x0720  /* SMBus transfer */
2636 
2637 #define VKI_I2C_SMBUS_BLOCK_MAX  32  /* As specified in SMBus standard */
2638 union vki_i2c_smbus_data {
2639         __vki_u8 byte;
2640         __vki_u16 word;
2641         __vki_u8 block[VKI_I2C_SMBUS_BLOCK_MAX + 2];
2642                  /* block[0] is used for length */
2643                  /* and one more for PEC */
2644 };
2645 
2646 /* This is the structure as used in the I2C_SMBUS ioctl call */
2647 struct vki_i2c_smbus_ioctl_data {
2648         __vki_u8 read_write;
2649         __vki_u8 command;
2650         __vki_u32 size;
2651         union vki_i2c_smbus_data __user *data;
2652 };
2653 
2654 struct vki_i2c_msg {
2655 	__vki_u16 addr;		/* slave address			*/
2656 	__vki_u16 flags;
2657 #define VKI_I2C_M_TEN		0x0010	/* this is a ten bit chip address */
2658 #define VKI_I2C_M_RD		0x0001	/* read data, from slave to master */
2659 #define VKI_I2C_M_NOSTART	0x4000	/* if I2C_FUNC_PROTOCOL_MANGLING */
2660 #define VKI_I2C_M_REV_DIR_ADDR	0x2000	/* if I2C_FUNC_PROTOCOL_MANGLING */
2661 #define VKI_I2C_M_IGNORE_NAK	0x1000	/* if I2C_FUNC_PROTOCOL_MANGLING */
2662 #define VKI_I2C_M_NO_RD_ACK	0x0800	/* if I2C_FUNC_PROTOCOL_MANGLING */
2663 #define VKI_I2C_M_RECV_LEN	0x0400	/* length will be first received byte */
2664 	__vki_u16 len;		/* msg length				*/
2665 	__vki_u8 *buf;		/* pointer to msg data			*/
2666 };
2667 
2668 struct vki_i2c_rdwr_ioctl_data {
2669 	struct vki_i2c_msg *msgs;	/* pointers to i2c_msgs */
2670 	__vki_u32 nmsgs;		/* number of i2c_msgs */
2671 };
2672 
2673 //----------------------------------------------------------------------
2674 // From linux-2.6.20.1/include/linux/keyctl.h
2675 //----------------------------------------------------------------------
2676 
2677 /* keyctl commands */
2678 #define VKI_KEYCTL_GET_KEYRING_ID	0	/* ask for a keyring's ID */
2679 #define VKI_KEYCTL_JOIN_SESSION_KEYRING	1	/* join or start named session keyring */
2680 #define VKI_KEYCTL_UPDATE		2	/* update a key */
2681 #define VKI_KEYCTL_REVOKE		3	/* revoke a key */
2682 #define VKI_KEYCTL_CHOWN		4	/* set ownership of a key */
2683 #define VKI_KEYCTL_SETPERM		5	/* set perms on a key */
2684 #define VKI_KEYCTL_DESCRIBE		6	/* describe a key */
2685 #define VKI_KEYCTL_CLEAR		7	/* clear contents of a keyring */
2686 #define VKI_KEYCTL_LINK			8	/* link a key into a keyring */
2687 #define VKI_KEYCTL_UNLINK		9	/* unlink a key from a keyring */
2688 #define VKI_KEYCTL_SEARCH		10	/* search for a key in a keyring */
2689 #define VKI_KEYCTL_READ			11	/* read a key or keyring's contents */
2690 #define VKI_KEYCTL_INSTANTIATE		12	/* instantiate a partially constructed key */
2691 #define VKI_KEYCTL_NEGATE		13	/* negate a partially constructed key */
2692 #define VKI_KEYCTL_SET_REQKEY_KEYRING	14	/* set default request-key keyring */
2693 #define VKI_KEYCTL_SET_TIMEOUT		15	/* set key timeout */
2694 #define VKI_KEYCTL_ASSUME_AUTHORITY	16	/* assume request_key() authorisation */
2695 
2696 /*--------------------------------------------------------------------*/
2697 // From linux-2.6.20.1/include/linux/key.h
2698 /*--------------------------------------------------------------------*/
2699 
2700 /* key handle serial number */
2701 typedef vki_int32_t vki_key_serial_t;
2702 
2703 /* key handle permissions mask */
2704 typedef vki_uint32_t vki_key_perm_t;
2705 
2706 //----------------------------------------------------------------------
2707 // From linux-2.6.24.7/include/linux/wireless.h
2708 // (wireless extensions version 22, 2007-03-16)
2709 //----------------------------------------------------------------------
2710 
2711 /*
2712  * [[Wireless extensions ioctls.]]
2713  */
2714 
2715 /* Wireless Identification */
2716 #define VKI_SIOCSIWCOMMIT	0x8B00	/* Commit pending changes to driver */
2717 #define VKI_SIOCGIWNAME		0x8B01	/* get name == wireless protocol */
2718 
2719 /* Basic operations */
2720 #define VKI_SIOCSIWNWID		0x8B02	/* set network id (pre-802.11) */
2721 #define VKI_SIOCGIWNWID		0x8B03	/* get network id (the cell) */
2722 #define VKI_SIOCSIWFREQ		0x8B04	/* set channel/frequency (Hz) */
2723 #define VKI_SIOCGIWFREQ		0x8B05	/* get channel/frequency (Hz) */
2724 #define VKI_SIOCSIWMODE		0x8B06	/* set operation mode */
2725 #define VKI_SIOCGIWMODE		0x8B07	/* get operation mode */
2726 #define VKI_SIOCSIWSENS		0x8B08	/* set sensitivity (dBm) */
2727 #define VKI_SIOCGIWSENS		0x8B09	/* get sensitivity (dBm) */
2728 
2729 /* Informative stuff */
2730 #define VKI_SIOCSIWRANGE	0x8B0A	/* Unused */
2731 #define VKI_SIOCGIWRANGE	0x8B0B	/* Get range of parameters */
2732 #define VKI_SIOCSIWPRIV		0x8B0C	/* Unused */
2733 #define VKI_SIOCGIWPRIV		0x8B0D	/* get private ioctl interface info */
2734 #define VKI_SIOCSIWSTATS	0x8B0E	/* Unused */
2735 #define VKI_SIOCGIWSTATS	0x8B0F	/* Get /proc/net/wireless stats */
2736 
2737 /* Spy support (statistics per MAC address - used for Mobile IP support) */
2738 #define VKI_SIOCSIWSPY		0x8B10	/* set spy addresses */
2739 #define VKI_SIOCGIWSPY		0x8B11	/* get spy info (quality of link) */
2740 #define VKI_SIOCSIWTHRSPY	0x8B12	/* set spy threshold (spy event) */
2741 #define VKI_SIOCGIWTHRSPY	0x8B13	/* get spy threshold */
2742 
2743 /* Access Point manipulation */
2744 #define VKI_SIOCSIWAP		0x8B14	/* set access point MAC addresses */
2745 #define VKI_SIOCGIWAP		0x8B15	/* get access point MAC addresses */
2746 #define VKI_SIOCGIWAPLIST	0x8B17	/* Deprecated in favor of scanning */
2747 #define VKI_SIOCSIWSCAN         0x8B18	/* trigger scanning (list cells) */
2748 #define VKI_SIOCGIWSCAN         0x8B19	/* get scanning results */
2749 
2750 /* 802.11 specific support */
2751 #define VKI_SIOCSIWESSID	0x8B1A	/* set ESSID (network name) */
2752 #define VKI_SIOCGIWESSID	0x8B1B	/* get ESSID */
2753 #define VKI_SIOCSIWNICKN	0x8B1C	/* set node name/nickname */
2754 #define VKI_SIOCGIWNICKN	0x8B1D	/* get node name/nickname */
2755 
2756 /* Other parameters useful in 802.11 and some other devices */
2757 #define VKI_SIOCSIWRATE		0x8B20	/* set default bit rate (bps) */
2758 #define VKI_SIOCGIWRATE		0x8B21	/* get default bit rate (bps) */
2759 #define VKI_SIOCSIWRTS		0x8B22	/* set RTS/CTS threshold (bytes) */
2760 #define VKI_SIOCGIWRTS		0x8B23	/* get RTS/CTS threshold (bytes) */
2761 #define VKI_SIOCSIWFRAG		0x8B24	/* set fragmentation thr (bytes) */
2762 #define VKI_SIOCGIWFRAG		0x8B25	/* get fragmentation thr (bytes) */
2763 #define VKI_SIOCSIWTXPOW	0x8B26	/* set transmit power (dBm) */
2764 #define VKI_SIOCGIWTXPOW	0x8B27	/* get transmit power (dBm) */
2765 #define VKI_SIOCSIWRETRY	0x8B28	/* set retry limits and lifetime */
2766 #define VKI_SIOCGIWRETRY	0x8B29	/* get retry limits and lifetime */
2767 
2768 /* Encoding stuff (scrambling, hardware security, WEP...) */
2769 #define VKI_SIOCSIWENCODE	0x8B2A	/* set encoding token & mode */
2770 #define VKI_SIOCGIWENCODE	0x8B2B	/* get encoding token & mode */
2771 
2772 /* Power saving stuff (power management, unicast and multicast) */
2773 #define VKI_SIOCSIWPOWER	0x8B2C	/* set Power Management settings */
2774 #define VKI_SIOCGIWPOWER	0x8B2D	/* get Power Management settings */
2775 
2776 /* WPA : Generic IEEE 802.11 informatiom element (e.g., for WPA/RSN/WMM). */
2777 #define VKI_SIOCSIWGENIE	0x8B30		/* set generic IE */
2778 #define VKI_SIOCGIWGENIE	0x8B31		/* get generic IE */
2779 
2780 /* WPA : IEEE 802.11 MLME requests */
2781 #define VKI_SIOCSIWMLME		0x8B16	/* request MLME operation; uses
2782 					 * struct iw_mlme */
2783 /* WPA : Authentication mode parameters */
2784 #define VKI_SIOCSIWAUTH		0x8B32	/* set authentication mode params */
2785 #define VKI_SIOCGIWAUTH		0x8B33	/* get authentication mode params */
2786 
2787 /* WPA : Extended version of encoding configuration */
2788 #define VKI_SIOCSIWENCODEEXT	0x8B34	/* set encoding token & mode */
2789 #define VKI_SIOCGIWENCODEEXT	0x8B35	/* get encoding token & mode */
2790 
2791 /* WPA2 : PMKSA cache management */
2792 #define VKI_SIOCSIWPMKSA	0x8B36	/* PMKSA cache operation */
2793 
2794 /*
2795  * [[Payload for the wireless extensions ioctls.]]
2796  */
2797 
2798 struct	vki_iw_param
2799 {
2800   __vki_s32	value;		/* The value of the parameter itself */
2801   __vki_u8	fixed;		/* Hardware should not use auto select */
2802   __vki_u8	disabled;	/* Disable the feature */
2803   __vki_u16	flags;		/* Various specifc flags (if any) */
2804 };
2805 
2806 struct	vki_iw_point
2807 {
2808   void __user	*pointer;	/* Pointer to the data  (in user space) */
2809   __vki_u16	length;		/* number of fields or size in bytes */
2810   __vki_u16	flags;		/* Optional params */
2811 };
2812 
2813 struct	vki_iw_freq
2814 {
2815 	__vki_s32	m;		/* Mantissa */
2816 	__vki_s16	e;		/* Exponent */
2817 	__vki_u8	i;		/* List index (when in range struct) */
2818 	__vki_u8	flags;		/* Flags (fixed/auto) */
2819 };
2820 
2821 struct	vki_iw_quality
2822 {
2823 	__vki_u8	qual;		/* link quality (%retries, SNR,
2824 					   %missed beacons or better...) */
2825 	__vki_u8	level;		/* signal level (dBm) */
2826 	__vki_u8	noise;		/* noise level (dBm) */
2827 	__vki_u8	updated;	/* Flags to know if updated */
2828 };
2829 
2830 union	vki_iwreq_data
2831 {
2832 	/* Config - generic */
2833 	char		name[VKI_IFNAMSIZ];
2834 	/* Name : used to verify the presence of  wireless extensions.
2835 	 * Name of the protocol/provider... */
2836 
2837 	struct vki_iw_point	essid;	/* Extended network name */
2838 	struct vki_iw_param	nwid;	/* network id (or domain - the cell) */
2839 	struct vki_iw_freq	freq;	/* frequency or channel :
2840 					 * 0-1000 = channel
2841 					 * > 1000 = frequency in Hz */
2842 
2843 	struct vki_iw_param	sens;	/* signal level threshold */
2844 	struct vki_iw_param	bitrate;/* default bit rate */
2845 	struct vki_iw_param	txpower;/* default transmit power */
2846 	struct vki_iw_param	rts;	/* RTS threshold threshold */
2847 	struct vki_iw_param	frag;	/* Fragmentation threshold */
2848 	__vki_u32		mode;	/* Operation mode */
2849 	struct vki_iw_param	retry;	/* Retry limits & lifetime */
2850 
2851 	struct vki_iw_point	encoding; /* Encoding stuff : tokens */
2852 	struct vki_iw_param	power;	/* PM duration/timeout */
2853 	struct vki_iw_quality	qual;	/* Quality part of statistics */
2854 
2855 	struct vki_sockaddr ap_addr;	/* Access point address */
2856 	struct vki_sockaddr addr;	/* Destination address (hw/mac) */
2857 
2858 	struct vki_iw_param	param;	/* Other small parameters */
2859 	struct vki_iw_point	data;	/* Other large parameters */
2860 };
2861 
2862 struct	vki_iwreq
2863 {
2864 	union
2865 	{
2866 		char ifrn_name[VKI_IFNAMSIZ];	/* if name, e.g. "eth0" */
2867 	} ifr_ifrn;
2868 
2869 	/* Data part (defined just above) */
2870 	union	vki_iwreq_data	u;
2871 };
2872 
2873 /*--------------------------------------------------------------------*/
2874 // From linux-2.6.31.5/include/linux/perf_event.h
2875 /*--------------------------------------------------------------------*/
2876 
2877 struct vki_perf_event_attr {
2878 
2879 	/*
2880 	 * Major type: hardware/software/tracepoint/etc.
2881 	 */
2882 	__vki_u32			type;
2883 
2884 	/*
2885 	 * Size of the attr structure, for fwd/bwd compat.
2886 	 */
2887 	__vki_u32			size;
2888 
2889 	/*
2890 	 * Type specific configuration information.
2891 	 */
2892 	__vki_u64			config;
2893 
2894 	union {
2895 		__vki_u64		sample_period;
2896 		__vki_u64		sample_freq;
2897 	};
2898 
2899 	__vki_u64			sample_type;
2900 	__vki_u64			read_format;
2901 
2902 	__vki_u64			disabled       :  1, /* off by default        */
2903 					inherit	       :  1, /* children inherit it   */
2904 					pinned	       :  1, /* must always be on PMU */
2905 					exclusive      :  1, /* only group on PMU     */
2906 					exclude_user   :  1, /* don't count user      */
2907 					exclude_kernel :  1, /* ditto kernel          */
2908 					exclude_hv     :  1, /* ditto hypervisor      */
2909 					exclude_idle   :  1, /* don't count when idle */
2910 					mmap           :  1, /* include mmap data     */
2911 					comm	       :  1, /* include comm data     */
2912 					freq           :  1, /* use freq, not period  */
2913 					inherit_stat   :  1, /* per task counts       */
2914 					enable_on_exec :  1, /* next exec enables     */
2915 					task           :  1, /* trace fork/exit       */
2916 					watermark      :  1, /* wakeup_watermark      */
2917 					/*
2918 					 * precise_ip:
2919 					 *
2920 					 *  0 - SAMPLE_IP can have arbitrary skid
2921 					 *  1 - SAMPLE_IP must have constant skid
2922 					 *  2 - SAMPLE_IP requested to have 0 skid
2923 					 *  3 - SAMPLE_IP must have 0 skid
2924 					 *
2925 					 *  See also PERF_RECORD_MISC_EXACT_IP
2926 					 */
2927 					precise_ip     :  2, /* skid constraint       */
2928 					mmap_data      :  1, /* non-exec mmap data    */
2929 					sample_id_all  :  1, /* sample_type all events */
2930 
2931 					__reserved_1   : 45;
2932 
2933 	union {
2934 		__vki_u32		wakeup_events;	  /* wakeup every n events */
2935 		__vki_u32		wakeup_watermark; /* bytes before wakeup   */
2936 	};
2937 
2938 	__vki_u32			bp_type;
2939 	union {
2940 		__vki_u64		bp_addr;
2941 		__vki_u64		config1; /* extension of config */
2942 	};
2943 	union {
2944 		__vki_u64		bp_len;
2945 		__vki_u64		config2; /* extension of config1 */
2946 	};
2947 };
2948 
2949 /*--------------------------------------------------------------------*/
2950 // From linux-2.6.32.4/include/linux/getcpu.h
2951 /*--------------------------------------------------------------------*/
2952 
2953 struct vki_getcpu_cache {
2954 	unsigned long blob[128 / sizeof(long)];
2955 };
2956 
2957 //----------------------------------------------------------------------
2958 // From linux-2.6.33.3/include/linux/input.h
2959 //----------------------------------------------------------------------
2960 
2961 /*
2962  * IOCTLs (0x00 - 0x7f)
2963  */
2964 
2965 #define VKI_EVIOCGNAME(len)	_VKI_IOC(_VKI_IOC_READ, 'E', 0x06, len)		/* get device name */
2966 #define VKI_EVIOCGPHYS(len)	_VKI_IOC(_VKI_IOC_READ, 'E', 0x07, len)		/* get physical location */
2967 #define VKI_EVIOCGUNIQ(len)	_VKI_IOC(_VKI_IOC_READ, 'E', 0x08, len)		/* get unique identifier */
2968 
2969 #define VKI_EVIOCGKEY(len)	_VKI_IOC(_VKI_IOC_READ, 'E', 0x18, len)		/* get global keystate */
2970 #define VKI_EVIOCGLED(len)	_VKI_IOC(_VKI_IOC_READ, 'E', 0x19, len)		/* get all LEDs */
2971 #define VKI_EVIOCGSND(len)	_VKI_IOC(_VKI_IOC_READ, 'E', 0x1a, len)		/* get all sounds status */
2972 #define VKI_EVIOCGSW(len)	_VKI_IOC(_VKI_IOC_READ, 'E', 0x1b, len)		/* get all switch states */
2973 
2974 #define VKI_EVIOCGBIT(ev,len)	_VKI_IOC(_VKI_IOC_READ, 'E', 0x20 + ev, len)	/* get event bits */
2975 
2976 /*
2977  * Event types
2978  */
2979 
2980 #define VKI_EV_SYN		0x00
2981 #define VKI_EV_KEY		0x01
2982 #define VKI_EV_REL		0x02
2983 #define VKI_EV_ABS		0x03
2984 #define VKI_EV_MSC		0x04
2985 #define VKI_EV_SW		0x05
2986 #define VKI_EV_LED		0x11
2987 #define VKI_EV_SND		0x12
2988 #define VKI_EV_REP		0x14
2989 #define VKI_EV_FF		0x15
2990 #define VKI_EV_PWR		0x16
2991 #define VKI_EV_FF_STATUS	0x17
2992 #define VKI_EV_MAX		0x1f
2993 #define VKI_EV_CNT		(VKI_EV_MAX+1)
2994 
2995 //----------------------------------------------------------------------
2996 // From linux-2.6.39-rc2/include/asm_generic/ioctls.h
2997 //----------------------------------------------------------------------
2998 
2999 #ifndef VKI_FIOQSIZE
3000 #define VKI_FIOQSIZE 0x5460     /* Value differs on some platforms */
3001 #endif
3002 
3003 #ifndef VKI_TIOCSIG
3004 #define VKI_TIOCSIG _VKI_IOW('T', 0x36, int) /* Value differs on some platforms */
3005 #endif
3006 
3007 //----------------------------------------------------------------------
3008 // From kernel/common/include/linux/ashmem.h
3009 //----------------------------------------------------------------------
3010 
3011 #if defined(VGPV_arm_linux_android) || defined(VGPV_x86_linux_android) \
3012     || defined(VGPV_mips32_linux_android)
3013 
3014 #define VKI_ASHMEM_NAME_LEN 256
3015 
3016 #define VKI_ASHMEM_NAME_DEF "dev/ashmem"
3017 
3018 #define VKI_ASHMEM_NOT_PURGED 0
3019 #define VKI_ASHMEM_WAS_PURGED 1
3020 
3021 #define VKI_ASHMEM_IS_UNPINNED 0
3022 #define VKI_ASHMEM_IS_PINNED 1
3023 
3024 struct vki_ashmem_pin {
3025    vki_uint32_t offset;
3026    vki_uint32_t len;
3027 };
3028 
3029 #define __VKI_ASHMEMIOC 0x77
3030 
3031 #define VKI_ASHMEM_SET_NAME _VKI_IOW(__VKI_ASHMEMIOC, 1, char[VKI_ASHMEM_NAME_LEN])
3032 #define VKI_ASHMEM_GET_NAME _VKI_IOR(__VKI_ASHMEMIOC, 2, char[VKI_ASHMEM_NAME_LEN])
3033 #define VKI_ASHMEM_SET_SIZE _VKI_IOW(__VKI_ASHMEMIOC, 3, vki_size_t)
3034 #define VKI_ASHMEM_GET_SIZE _VKI_IO(__VKI_ASHMEMIOC, 4)
3035 #define VKI_ASHMEM_SET_PROT_MASK _VKI_IOW(__VKI_ASHMEMIOC, 5, unsigned long)
3036 #define VKI_ASHMEM_GET_PROT_MASK _VKI_IO(__VKI_ASHMEMIOC, 6)
3037 #define VKI_ASHMEM_PIN _VKI_IOW(__VKI_ASHMEMIOC, 7, struct vki_ashmem_pin)
3038 #define VKI_ASHMEM_UNPIN _VKI_IOW(__VKI_ASHMEMIOC, 8, struct vki_ashmem_pin)
3039 #define VKI_ASHMEM_GET_PIN_STATUS _VKI_IO(__VKI_ASHMEMIOC, 9)
3040 #define VKI_ASHMEM_PURGE_ALL_CACHES _VKI_IO(__VKI_ASHMEMIOC, 10)
3041 
3042 //----------------------------------------------------------------------
3043 // From kernel/common/include/linux/binder.h
3044 //----------------------------------------------------------------------
3045 
3046 struct vki_binder_write_read {
3047  signed long write_size;
3048  signed long write_consumed;
3049  unsigned long write_buffer;
3050  signed long read_size;
3051  signed long read_consumed;
3052  unsigned long read_buffer;
3053 };
3054 
3055 struct vki_binder_version {
3056  signed long protocol_version;
3057 };
3058 
3059 #define VKI_BINDER_WRITE_READ _VKI_IOWR('b', 1, struct vki_binder_write_read)
3060 #define VKI_BINDER_SET_IDLE_TIMEOUT _VKI_IOW('b', 3, vki_int64_t)
3061 #define VKI_BINDER_SET_MAX_THREADS _VKI_IOW('b', 5, vki_size_t)
3062 #define VKI_BINDER_SET_IDLE_PRIORITY _VKI_IOW('b', 6, int)
3063 #define VKI_BINDER_SET_CONTEXT_MGR _VKI_IOW('b', 7, int)
3064 #define VKI_BINDER_THREAD_EXIT _VKI_IOW('b', 8, int)
3065 #define VKI_BINDER_VERSION _VKI_IOWR('b', 9, struct vki_binder_version)
3066 
3067 #endif /* defined(VGPV_*_linux_android) */
3068 
3069 //----------------------------------------------------------------------
3070 // From linux-3.0.4/include/net/bluetooth/bluetooth.h
3071 //----------------------------------------------------------------------
3072 
3073 typedef struct {
3074    __vki_u8 b[6];
3075 } __vki_packed vki_bdaddr_t;
3076 
3077 //----------------------------------------------------------------------
3078 // From linux-3.0.4/include/net/bluetooth/hci.h
3079 //----------------------------------------------------------------------
3080 
3081 #define VKI_HCIDEVUP        _VKI_IOW('H', 201, int)
3082 #define VKI_HCIDEVDOWN      _VKI_IOW('H', 202, int)
3083 #define VKI_HCIDEVRESET     _VKI_IOW('H', 203, int)
3084 #define VKI_HCIDEVRESTAT    _VKI_IOW('H', 204, int)
3085 
3086 #define VKI_HCIGETDEVLIST   _VKI_IOR('H', 210, int)
3087 
3088 struct vki_hci_dev_req {
3089 	__vki_u16  dev_id;
3090 	__vki_u32  dev_opt;
3091 };
3092 
3093 struct vki_hci_dev_list_req {
3094 	__vki_u16  dev_num;
3095 	struct vki_hci_dev_req dev_req[0];	/* hci_dev_req structures */
3096 };
3097 
3098 #define VKI_HCIGETDEVINFO   _VKI_IOR('H', 211, int)
3099 #define VKI_HCIGETCONNLIST  _VKI_IOR('H', 212, int)
3100 #define VKI_HCIGETCONNINFO  _VKI_IOR('H', 213, int)
3101 #define VKI_HCIGETAUTHINFO  _VKI_IOR('H', 215, int)
3102 
3103 #define VKI_HCISETRAW       _VKI_IOW('H', 220, int)
3104 #define VKI_HCISETSCAN      _VKI_IOW('H', 221, int)
3105 #define VKI_HCISETAUTH      _VKI_IOW('H', 222, int)
3106 #define VKI_HCISETENCRYPT   _VKI_IOW('H', 223, int)
3107 #define VKI_HCISETPTYPE     _VKI_IOW('H', 224, int)
3108 #define VKI_HCISETLINKPOL   _VKI_IOW('H', 225, int)
3109 #define VKI_HCISETLINKMODE  _VKI_IOW('H', 226, int)
3110 #define VKI_HCISETACLMTU    _VKI_IOW('H', 227, int)
3111 #define VKI_HCISETSCOMTU    _VKI_IOW('H', 228, int)
3112 
3113 #define VKI_HCIBLOCKADDR    _VKI_IOW('H', 230, int)
3114 #define VKI_HCIUNBLOCKADDR  _VKI_IOW('H', 231, int)
3115 
3116 #define VKI_HCIINQUIRY      _VKI_IOR('H', 240, int)
3117 
3118 struct vki_inquiry_info {
3119    vki_bdaddr_t bdaddr;
3120    __vki_u8     pscan_rep_mode;
3121    __vki_u8     pscan_period_mode;
3122    __vki_u8     pscan_mode;
3123    __vki_u8     dev_class[3];
3124    __vki_le16   clock_offset;
3125 } __vki_packed;
3126 
3127 struct vki_hci_inquiry_req {
3128    __vki_u16 dev_id;
3129    __vki_u16 flags;
3130    __vki_u8  lap[3];
3131    __vki_u8  length;
3132    __vki_u8  num_rsp;
3133 };
3134 
3135 //----------------------------------------------------------------------
3136 // From linux-3.9.2/include/net/bluetooth/rfcomm.h
3137 //----------------------------------------------------------------------
3138 
3139 struct vki_sockaddr_rc {
3140         vki_sa_family_t     rc_family;
3141         vki_bdaddr_t        rc_bdaddr;
3142         __vki_u8            rc_channel;
3143 };
3144 
3145 //----------------------------------------------------------------------
3146 // From linux-3.4/include/linux/kvm.h
3147 //----------------------------------------------------------------------
3148 #define KVMIO 0xAE
3149 
3150 #define VKI_KVM_GET_API_VERSION       _VKI_IO(KVMIO,   0x00)
3151 #define VKI_KVM_CREATE_VM             _VKI_IO(KVMIO,   0x01) /* returns a VM fd */
3152 #define VKI_KVM_CHECK_EXTENSION       _VKI_IO(KVMIO,   0x03)
3153 #define VKI_KVM_GET_VCPU_MMAP_SIZE    _VKI_IO(KVMIO,   0x04) /* in bytes */
3154 #define VKI_KVM_S390_ENABLE_SIE       _VKI_IO(KVMIO,   0x06)
3155 #define VKI_KVM_CREATE_VCPU           _VKI_IO(KVMIO,   0x41)
3156 #define VKI_KVM_SET_NR_MMU_PAGES      _VKI_IO(KVMIO,   0x44)
3157 #define VKI_KVM_GET_NR_MMU_PAGES      _VKI_IO(KVMIO,   0x45)
3158 #define VKI_KVM_SET_TSS_ADDR          _VKI_IO(KVMIO,   0x47)
3159 #define VKI_KVM_CREATE_IRQCHIP        _VKI_IO(KVMIO,   0x60)
3160 #define VKI_KVM_CREATE_PIT            _VKI_IO(KVMIO,   0x64)
3161 #define VKI_KVM_REINJECT_CONTROL      _VKI_IO(KVMIO,   0x71)
3162 #define VKI_KVM_SET_BOOT_CPU_ID       _VKI_IO(KVMIO,   0x78)
3163 #define VKI_KVM_SET_TSC_KHZ           _VKI_IO(KVMIO,  0xa2)
3164 #define VKI_KVM_GET_TSC_KHZ           _VKI_IO(KVMIO,  0xa3)
3165 #define VKI_KVM_RUN                   _VKI_IO(KVMIO,   0x80)
3166 #define VKI_KVM_S390_INITIAL_RESET    _VKI_IO(KVMIO,   0x97)
3167 #define VKI_KVM_NMI                   _VKI_IO(KVMIO,   0x9a)
3168 #define VKI_KVM_KVMCLOCK_CTRL         _VKI_IO(KVMIO,   0xad)
3169 
3170 //----------------------------------------------------------------------
3171 // From linux-2.6/include/linux/net_stamp.h
3172 //----------------------------------------------------------------------
3173 
3174 struct vki_hwtstamp_config {
3175 	int flags;
3176 	int tx_type;
3177 	int rx_filter;
3178 };
3179 
3180 //----------------------------------------------------------------------
3181 // From linux-2.6.12-rc2/include/linux/uinput.h
3182 //----------------------------------------------------------------------
3183 
3184 #define VKI_UINPUT_IOCTL_BASE       'U'
3185 #define VKI_UI_DEV_CREATE		_VKI_IO(VKI_UINPUT_IOCTL_BASE, 1)
3186 #define VKI_UI_DEV_DESTROY		_VKI_IO(VKI_UINPUT_IOCTL_BASE, 2)
3187 
3188 #define VKI_UI_SET_EVBIT		_VKI_IOW(VKI_UINPUT_IOCTL_BASE, 100, int)
3189 #define VKI_UI_SET_KEYBIT		_VKI_IOW(VKI_UINPUT_IOCTL_BASE, 101, int)
3190 #define VKI_UI_SET_RELBIT		_VKI_IOW(VKI_UINPUT_IOCTL_BASE, 102, int)
3191 #define VKI_UI_SET_ABSBIT		_VKI_IOW(VKI_UINPUT_IOCTL_BASE, 103, int)
3192 #define VKI_UI_SET_MSCBIT		_VKI_IOW(VKI_UINPUT_IOCTL_BASE, 104, int)
3193 #define VKI_UI_SET_LEDBIT		_VKI_IOW(VKI_UINPUT_IOCTL_BASE, 105, int)
3194 #define VKI_UI_SET_SNDBIT		_VKI_IOW(VKI_UINPUT_IOCTL_BASE, 106, int)
3195 #define VKI_UI_SET_FFBIT		_VKI_IOW(VKI_UINPUT_IOCTL_BASE, 107, int)
3196 #define VKI_UI_SET_SWBIT		_VKI_IOW(VKI_UINPUT_IOCTL_BASE, 109, int)
3197 #define VKI_UI_SET_PROPBIT		_VKI_IOW(VKI_UINPUT_IOCTL_BASE, 110, int)
3198 
3199 //----------------------------------------------------------------------
3200 // From linux-2.6/include/uapi/rdma/ib_user_mad.h
3201 //----------------------------------------------------------------------
3202 
3203 #define VKI_IB_IOCTL_MAGIC          0x1b
3204 
3205 #define VKI_IB_USER_MAD_REGISTER_AGENT    _VKI_IOWR(VKI_IB_IOCTL_MAGIC, 1, \
3206                                               struct ib_user_mad_reg_req)
3207 
3208 #define VKI_IB_USER_MAD_UNREGISTER_AGENT  _VKI_IOW(VKI_IB_IOCTL_MAGIC, 2, __u32)
3209 
3210 #define VKI_IB_USER_MAD_ENABLE_PKEY       _VKI_IO(VKI_IB_IOCTL_MAGIC, 3)
3211 
3212 //----------------------------------------------------------------------
3213 // From linux-3.8/include/uapi/linux/if_tun.h
3214 //----------------------------------------------------------------------
3215 
3216 #define VKI_TUNSETNOCSUM  _VKI_IOW('T', 200, int)
3217 #define VKI_TUNSETDEBUG   _VKI_IOW('T', 201, int)
3218 #define VKI_TUNSETIFF     _VKI_IOW('T', 202, int)
3219 #define VKI_TUNSETPERSIST _VKI_IOW('T', 203, int)
3220 #define VKI_TUNSETOWNER   _VKI_IOW('T', 204, int)
3221 #define VKI_TUNSETLINK    _VKI_IOW('T', 205, int)
3222 #define VKI_TUNSETGROUP   _VKI_IOW('T', 206, int)
3223 #define VKI_TUNGETFEATURES _VKI_IOR('T', 207, unsigned int)
3224 #define VKI_TUNSETOFFLOAD  _VKI_IOW('T', 208, unsigned int)
3225 #define VKI_TUNSETTXFILTER _VKI_IOW('T', 209, unsigned int)
3226 #define VKI_TUNGETIFF      _VKI_IOR('T', 210, unsigned int)
3227 #define VKI_TUNGETSNDBUF   _VKI_IOR('T', 211, int)
3228 #define VKI_TUNSETSNDBUF   _VKI_IOW('T', 212, int)
3229 //#define VKI_TUNATTACHFILTER _VKI_IOW('T', 213, struct sock_fprog)
3230 //#define VKI_TUNDETACHFILTER _VKI_IOW('T', 214, struct sock_fprog)
3231 #define VKI_TUNGETVNETHDRSZ _VKI_IOR('T', 215, int)
3232 #define VKI_TUNSETVNETHDRSZ _VKI_IOW('T', 216, int)
3233 #define VKI_TUNSETQUEUE  _VKI_IOW('T', 217, int)
3234 #define VKI_TUNSETIFINDEX	_VKI_IOW('T', 218, unsigned int)
3235 //#define VKI_TUNGETFILTER _VKI_IOR('T', 219, struct sock_fprog)
3236 
3237 //----------------------------------------------------------------------
3238 // From linux-3.8/include/uapi/linux/vhost.h
3239 //----------------------------------------------------------------------
3240 
3241 #define VKI_VHOST_VIRTIO 0xAF
3242 #define VKI_VHOST_SET_OWNER _VKI_IO(VKI_VHOST_VIRTIO, 0x01)
3243 #define VKI_VHOST_RESET_OWNER _VKI_IO(VKI_VHOST_VIRTIO, 0x02)
3244 
3245 //----------------------------------------------------------------------
3246 // Xen privcmd IOCTL
3247 //----------------------------------------------------------------------
3248 
3249 typedef unsigned long __vki_xen_pfn_t;
3250 
3251 struct vki_xen_privcmd_hypercall {
3252        __vki_u64 op;
3253        __vki_u64 arg[5];
3254 };
3255 
3256 struct vki_xen_privcmd_mmap_entry {
3257         __vki_u64 va;
3258         __vki_u64 mfn;
3259         __vki_u64 npages;
3260 };
3261 
3262 struct vki_xen_privcmd_mmap {
3263         int num;
3264         __vki_u16 dom; /* target domain */
3265         struct vki_xen_privcmd_mmap_entry *entry;
3266 };
3267 
3268 struct vki_xen_privcmd_mmapbatch {
3269         int num;     /* number of pages to populate */
3270         __vki_u16 dom; /* target domain */
3271         __vki_u64 addr;  /* virtual address */
3272         __vki_xen_pfn_t *arr; /* array of mfns - top nibble set on err */
3273 };
3274 
3275 struct vki_xen_privcmd_mmapbatch_v2 {
3276         unsigned int num; /* number of pages to populate */
3277         __vki_u16 dom;      /* target domain */
3278         __vki_u64 addr;       /* virtual address */
3279         const __vki_xen_pfn_t *arr; /* array of mfns */
3280         int __user *err;  /* array of error codes */
3281 };
3282 
3283 #define VKI_XEN_IOCTL_PRIVCMD_HYPERCALL    _VKI_IOC(_VKI_IOC_NONE, 'P', 0, sizeof(struct vki_xen_privcmd_hypercall))
3284 #define VKI_XEN_IOCTL_PRIVCMD_MMAP         _VKI_IOC(_VKI_IOC_NONE, 'P', 2, sizeof(struct vki_xen_privcmd_mmap))
3285 
3286 #define VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH    _VKI_IOC(_VKI_IOC_NONE, 'P', 3, sizeof(struct vki_xen_privcmd_mmapbatch))
3287 #define VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH_V2 _VKI_IOC(_VKI_IOC_NONE, 'P', 4, sizeof(struct vki_xen_privcmd_mmapbatch_v2))
3288 
3289 //----------------------------------------------------------------------
3290 // Xen evtchn IOCTL
3291 //----------------------------------------------------------------------
3292 
3293 #define VKI_XEN_IOCTL_EVTCHN_BIND_VIRQ				\
3294 	_VKI_IOC(_VKI_IOC_NONE, 'E', 0, sizeof(struct vki_xen_ioctl_evtchn_bind_virq))
3295 struct vki_xen_ioctl_evtchn_bind_virq {
3296 	vki_uint32_t virq;
3297 	vki_uint32_t port;
3298 };
3299 
3300 #define VKI_XEN_IOCTL_EVTCHN_BIND_INTERDOMAIN			\
3301 	_VKI_IOC(_VKI_IOC_NONE, 'E', 1, sizeof(struct vki_xen_ioctl_evtchn_bind_interdomain))
3302 struct vki_xen_ioctl_evtchn_bind_interdomain {
3303 	vki_uint32_t remote_domain;
3304 	vki_uint32_t remote_port;
3305 };
3306 
3307 #define VKI_XEN_IOCTL_EVTCHN_BIND_UNBOUND_PORT			\
3308 	_VKI_IOC(_VKI_IOC_NONE, 'E', 2, sizeof(struct vki_xen_ioctl_evtchn_bind_unbound_port))
3309 struct vki_xen_ioctl_evtchn_bind_unbound_port {
3310 	vki_uint32_t remote_domain;
3311 };
3312 
3313 #define VKI_XEN_IOCTL_EVTCHN_UNBIND				\
3314 	_VKI_IOC(_VKI_IOC_NONE, 'E', 3, sizeof(struct vki_xen_ioctl_evtchn_unbind))
3315 struct vki_xen_ioctl_evtchn_unbind {
3316 	vki_uint32_t port;
3317 };
3318 
3319 #define VKI_XEN_IOCTL_EVTCHN_NOTIFY				\
3320 	_VKI_IOC(_VKI_IOC_NONE, 'E', 4, sizeof(struct vki_xen_ioctl_evtchn_notify))
3321 struct vki_xen_ioctl_evtchn_notify {
3322 	vki_uint32_t port;
3323 };
3324 
3325 #define VKI_XEN_IOCTL_EVTCHN_RESET				\
3326 	_VKI_IOC(_VKI_IOC_NONE, 'E', 5, 0)
3327 
3328 
3329 //----------------------------------------------------------------------
3330 // From linux-3.4.0/include/linux/fs.h
3331 //----------------------------------------------------------------------
3332 
3333 struct vki_file_handle {
3334    __vki_u32 handle_bytes;
3335    int handle_type;
3336    /* file identifier */
3337    unsigned char f_handle[0];
3338 };
3339 
3340 //----------------------------------------------------------------------
3341 // From linux-3.2.0/include/linux/filter.h
3342 //----------------------------------------------------------------------
3343 
3344 struct vki_sock_filter {
3345 	__vki_u16 code; /* Actual filter code */
3346 	__vki_u8 jt;    /* Jump true */
3347 	__vki_u8 jf;    /* Jump false */
3348 	__vki_u32 k;    /* Generic multiuse field */
3349 };
3350 
3351 struct vki_sock_fprog {
3352 	__vki_u16 len;  /* actually unsigned short */
3353 	struct vki_sock_filter *filter;
3354 };
3355 
3356 //----------------------------------------------------------------------
3357 // From linux/include/uapi/linux/ethtool.h
3358 //----------------------------------------------------------------------
3359 
3360 struct vki_ethtool_cmd {
3361 	__vki_u32	cmd;
3362 	__vki_u32	supported;
3363 	__vki_u32	advertising;
3364 	__vki_u16	speed;
3365 	__vki_u8	duplex;
3366 	__vki_u8	port;
3367 	__vki_u8	phy_address;
3368 	__vki_u8	transceiver;
3369 	__vki_u8	autoneg;
3370 	__vki_u8	mdio_support;
3371 	__vki_u32	maxtxpkt;
3372 	__vki_u32	maxrxpkt;
3373 	__vki_u16	speed_hi;
3374 	__vki_u8	eth_tp_mdix;
3375 	__vki_u8	eth_tp_mdix_ctrl;
3376 	__vki_u32	lp_advertising;
3377 	__vki_u32	reserved[2];
3378 };
3379 
3380 #define VKI_ETHTOOL_FWVERS_LEN	32
3381 #define VKI_ETHTOOL_BUSINFO_LEN	32
3382 
3383 struct vki_ethtool_drvinfo {
3384 	__vki_u32	cmd;
3385 	char	driver[32];
3386 	char	version[32];
3387 	char	fw_version[VKI_ETHTOOL_FWVERS_LEN];
3388 	char	bus_info[VKI_ETHTOOL_BUSINFO_LEN];
3389 	char	reserved1[32];
3390 	char	reserved2[12];
3391 	__vki_u32	n_priv_flags;
3392 	__vki_u32	n_stats;
3393 	__vki_u32	testinfo_len;
3394 	__vki_u32	eedump_len;
3395 	__vki_u32	regdump_len;
3396 };
3397 
3398 #define VKI_SOPASS_MAX	6
3399 
3400 struct vki_ethtool_wolinfo {
3401 	__vki_u32	cmd;
3402 	__vki_u32	supported;
3403 	__vki_u32	wolopts;
3404 	__vki_u8	sopass[VKI_SOPASS_MAX];
3405 };
3406 
3407 struct vki_ethtool_value {
3408 	__vki_u32	cmd;
3409 	__vki_u32	data;
3410 };
3411 
3412 struct vki_ethtool_regs {
3413 	__vki_u32	cmd;
3414 	__vki_u32	version;
3415 	__vki_u32	len;
3416 	__vki_u8	data[0];
3417 };
3418 
3419 struct vki_ethtool_ringparam {
3420 	__vki_u32	cmd;
3421 	__vki_u32	rx_max_pending;
3422 	__vki_u32	rx_mini_max_pending;
3423 	__vki_u32	rx_jumbo_max_pending;
3424 	__vki_u32	tx_max_pending;
3425 	__vki_u32	rx_pending;
3426 	__vki_u32	rx_mini_pending;
3427 	__vki_u32	rx_jumbo_pending;
3428 	__vki_u32	tx_pending;
3429 };
3430 
3431 struct vki_ethtool_channels {
3432 	__vki_u32	cmd;
3433 	__vki_u32	max_rx;
3434 	__vki_u32	max_tx;
3435 	__vki_u32	max_other;
3436 	__vki_u32	max_combined;
3437 	__vki_u32	rx_count;
3438 	__vki_u32	tx_count;
3439 	__vki_u32	other_count;
3440 	__vki_u32	combined_count;
3441 };
3442 
3443 struct vki_ethtool_sset_info {
3444 	__vki_u32	cmd;
3445 	__vki_u32	reserved;
3446 	__vki_u64	sset_mask;
3447 	__vki_u32	data[0];
3448 };
3449 
3450 struct vki_ethtool_test {
3451 	__vki_u32	cmd;
3452 	__vki_u32	flags;
3453 	__vki_u32	reserved;
3454 	__vki_u32	len;
3455 	__vki_u64	data[0];
3456 };
3457 
3458 struct vki_ethtool_perm_addr {
3459 	__vki_u32	cmd;
3460 	__vki_u32	size;
3461 	__vki_u8	data[0];
3462 };
3463 
3464 struct vki_ethtool_get_features_block {
3465 	__vki_u32	available;
3466 	__vki_u32	requested;
3467 	__vki_u32	active;
3468 	__vki_u32	never_changed;
3469 };
3470 
3471 struct vki_ethtool_gfeatures {
3472 	__vki_u32	cmd;
3473 	__vki_u32	size;
3474 	struct vki_ethtool_get_features_block features[0];
3475 };
3476 
3477 struct vki_ethtool_set_features_block {
3478 	__vki_u32	valid;
3479 	__vki_u32	requested;
3480 };
3481 
3482 struct vki_ethtool_sfeatures {
3483 	__vki_u32	cmd;
3484 	__vki_u32	size;
3485 	struct vki_ethtool_set_features_block features[0];
3486 };
3487 
3488 struct vki_ethtool_ts_info {
3489 	__vki_u32	cmd;
3490 	__vki_u32	so_timestamping;
3491 	__vki_s32	phc_index;
3492 	__vki_u32	tx_types;
3493 	__vki_u32	tx_reserved[3];
3494 	__vki_u32	rx_filters;
3495 	__vki_u32	rx_reserved[3];
3496 };
3497 
3498 #define VKI_ETHTOOL_GSET	0x00000001 /* Get settings. */
3499 #define VKI_ETHTOOL_SSET	0x00000002 /* Set settings. */
3500 #define VKI_ETHTOOL_GDRVINFO	0x00000003 /* Get driver info. */
3501 #define VKI_ETHTOOL_GREGS	0x00000004 /* Get NIC registers. */
3502 #define VKI_ETHTOOL_GWOL	0x00000005 /* Get wake-on-lan options. */
3503 #define VKI_ETHTOOL_SWOL	0x00000006 /* Set wake-on-lan options. */
3504 #define VKI_ETHTOOL_GMSGLVL	0x00000007 /* Get driver message level */
3505 #define VKI_ETHTOOL_SMSGLVL	0x00000008 /* Set driver msg level. */
3506 #define VKI_ETHTOOL_NWAY_RST	0x00000009 /* Restart autonegotiation. */
3507 #define VKI_ETHTOOL_GLINK	0x0000000a
3508 #define VKI_ETHTOOL_GRINGPARAM	0x00000010 /* Get ring parameters */
3509 #define VKI_ETHTOOL_SRINGPARAM	0x00000011 /* Set ring parameters. */
3510 #define VKI_ETHTOOL_GRXCSUM	0x00000014 /* Get RX hw csum enable (ethtool_value) */
3511 #define VKI_ETHTOOL_SRXCSUM	0x00000015 /* Set RX hw csum enable (ethtool_value) */
3512 #define VKI_ETHTOOL_GTXCSUM	0x00000016 /* Get TX hw csum enable (ethtool_value) */
3513 #define VKI_ETHTOOL_STXCSUM	0x00000017 /* Set TX hw csum enable (ethtool_value) */
3514 #define VKI_ETHTOOL_GSG		0x00000018 /* Get scatter-gather enable
3515 					    * (ethtool_value) */
3516 #define VKI_ETHTOOL_SSG		0x00000019 /* Set scatter-gather enable
3517 					    * (ethtool_value). */
3518 #define VKI_ETHTOOL_TEST	0x0000001a /* execute NIC self-test. */
3519 #define VKI_ETHTOOL_PHYS_ID	0x0000001c /* identify the NIC */
3520 #define VKI_ETHTOOL_GTSO	0x0000001e /* Get TSO enable (ethtool_value) */
3521 #define VKI_ETHTOOL_STSO	0x0000001f /* Set TSO enable (ethtool_value) */
3522 #define VKI_ETHTOOL_GPERMADDR	0x00000020 /* Get permanent hardware address */
3523 #define VKI_ETHTOOL_GUFO	0x00000021 /* Get UFO enable (ethtool_value) */
3524 #define VKI_ETHTOOL_SUFO	0x00000022 /* Set UFO enable (ethtool_value) */
3525 #define VKI_ETHTOOL_GGSO	0x00000023 /* Get GSO enable (ethtool_value) */
3526 #define VKI_ETHTOOL_SGSO	0x00000024 /* Set GSO enable (ethtool_value) */
3527 #define VKI_ETHTOOL_GFLAGS	0x00000025 /* Get flags bitmap(ethtool_value) */
3528 #define VKI_ETHTOOL_SFLAGS	0x00000026 /* Set flags bitmap(ethtool_value) */
3529 #define VKI_ETHTOOL_GGRO	0x0000002b /* Get GRO enable (ethtool_value) */
3530 #define VKI_ETHTOOL_SGRO	0x0000002c /* Set GRO enable (ethtool_value) */
3531 #define VKI_ETHTOOL_RESET	0x00000034 /* Reset hardware */
3532 #define VKI_ETHTOOL_GSSET_INFO	0x00000037 /* Get string set info */
3533 #define VKI_ETHTOOL_GFEATURES	0x0000003a /* Get device offload settings */
3534 #define VKI_ETHTOOL_SFEATURES	0x0000003b /* Change device offload settings */
3535 #define VKI_ETHTOOL_GCHANNELS	0x0000003c /* Get no of channels */
3536 #define VKI_ETHTOOL_SCHANNELS	0x0000003d /* Set no of channels */
3537 #define VKI_ETHTOOL_GET_TS_INFO	0x00000041 /* Get time stamping and PHC info */
3538 
3539 //----------------------------------------------------------------------
3540 // From linux-3.15.8/drivers/staging/android/uapi/ion.h
3541 //----------------------------------------------------------------------
3542 
3543 typedef int vki_ion_user_handle_t;
3544 
3545 struct vki_ion_allocation_data {
3546         vki_size_t len;
3547         vki_size_t align;
3548         unsigned int heap_id_mask;
3549         unsigned int flags;
3550         vki_ion_user_handle_t handle;
3551 };
3552 
3553 struct vki_ion_fd_data {
3554         vki_ion_user_handle_t handle;
3555         int fd;
3556 };
3557 
3558 struct vki_ion_handle_data {
3559         vki_ion_user_handle_t handle;
3560 };
3561 
3562 struct vki_ion_custom_data {
3563         unsigned int cmd;
3564         unsigned long arg;
3565 };
3566 
3567 #define VKI_ION_IOC_MAGIC   'I'
3568 
3569 #define VKI_ION_IOC_ALLOC \
3570    _VKI_IOWR(VKI_ION_IOC_MAGIC, 0, struct vki_ion_allocation_data)
3571 
3572 #define VKI_ION_IOC_FREE \
3573    _VKI_IOWR(VKI_ION_IOC_MAGIC, 1, struct vki_ion_handle_data)
3574 
3575 #define VKI_ION_IOC_MAP \
3576    _VKI_IOWR(VKI_ION_IOC_MAGIC, 2, struct vki_ion_fd_data)
3577 
3578 #define VKI_ION_IOC_SHARE \
3579    _VKI_IOWR(VKI_ION_IOC_MAGIC, 4, struct vki_ion_fd_data)
3580 
3581 #define VKI_ION_IOC_IMPORT \
3582    _VKI_IOWR(VKI_ION_IOC_MAGIC, 5, struct vki_ion_fd_data)
3583 
3584 #define VKI_ION_IOC_SYNC \
3585    _VKI_IOWR(VKI_ION_IOC_MAGIC, 7, struct vki_ion_fd_data)
3586 
3587 #define VKI_ION_IOC_CUSTOM \
3588    _VKI_IOWR(VKI_ION_IOC_MAGIC, 6, struct vki_ion_custom_data)
3589 
3590 //----------------------------------------------------------------------
3591 // From linux-3.19-rc5/drivers/staging/android/uapi/sync.h
3592 //----------------------------------------------------------------------
3593 
3594 struct vki_sync_merge_data {
3595         __vki_s32 fd2;
3596         char      name[32];
3597         __vki_s32 fence;
3598 };
3599 
3600 struct vki_sync_pt_info {
3601         __vki_u32 len;
3602         char      obj_name[32];
3603         char      driver_name[32];
3604         __vki_s32 status;
3605         __vki_u64 timestamp_ns;
3606         __vki_u8  driver_data[0];
3607 };
3608 
3609 struct vki_sync_fence_info_data {
3610         __vki_u32 len;
3611         char      name[32];
3612         __vki_s32 status;
3613         __vki_u8  pt_info[0];
3614 };
3615 
3616 #define VKI_SYNC_IOC_MAGIC   '>'
3617 
3618 #define VKI_SYNC_IOC_WAIT \
3619    _VKI_IOW(VKI_SYNC_IOC_MAGIC, 0, __vki_s32)
3620 
3621 #define VKI_SYNC_IOC_MERGE \
3622    _VKI_IOWR(VKI_SYNC_IOC_MAGIC, 1, struct vki_sync_merge_data)
3623 
3624 #define VKI_SYNC_IOC_FENCE_INFO \
3625    _VKI_IOWR(VKI_SYNC_IOC_MAGIC, 2, struct vki_sync_fence_info_data)
3626 
3627 //----------------------------------------------------------------------
3628 // From drivers/staging/lustre/lustre/include/lustre/lustre_user.h
3629 //----------------------------------------------------------------------
3630 
3631 struct vki_lu_fid {
3632 	__vki_u64	f_seq;
3633 	__vki_u32	f_oid;
3634 	__vki_u32	f_ver;
3635 };
3636 
3637 //----------------------------------------------------------------------
3638 // From drivers/staging/lustre/lustre/include/lustre/lustre_idl.h
3639 //----------------------------------------------------------------------
3640 
3641 struct vki_getinfo_fid2path {
3642 	struct vki_lu_fid	gf_fid;
3643 	__vki_u64		gf_recno;
3644 	__vki_u32		gf_linkno;
3645 	__vki_u32		gf_pathlen;
3646 	char			gf_path[0];
3647 } __attribute__((packed));
3648 
3649 //----------------------------------------------------------------------
3650 // From drivers/staging/lustre/lustre/include/linux/lustre_lib.h
3651 //----------------------------------------------------------------------
3652 
3653 #define VKI_OBD_IOC_DATA_TYPE               long
3654 
3655 //----------------------------------------------------------------------
3656 // From drivers/staging/lustre/lustre/include/lustre_lib.h
3657 //----------------------------------------------------------------------
3658 
3659 #define VKI_OBD_IOC_FID2PATH \
3660            _VKI_IOWR ('f', 150, VKI_OBD_IOC_DATA_TYPE)
3661 #define VKI_LL_IOC_PATH2FID \
3662            _VKI_IOR ('f', 173, long)
3663 
3664 //----------------------------------------------------------------------
3665 // From lustre/include/lustre/lustre_idl.h
3666 //----------------------------------------------------------------------
3667 
3668 struct vki_getparent {
3669     struct vki_lu_fid   gp_fid;
3670     __vki_u32       gp_linkno;
3671     __vki_u32       gp_name_size;
3672     char            gp_name[0];
3673 } __attribute__((packed));
3674 
3675 //----------------------------------------------------------------------
3676 // From Lustre's lustre/include/lustre/lustre_user.h
3677 //----------------------------------------------------------------------
3678 #define VKI_LL_IOC_GETPARENT \
3679            _VKI_IOWR('f', 249, struct vki_getparent)
3680 
3681 
3682 struct vki_v4l2_rect {
3683 	__vki_s32   left;
3684 	__vki_s32   top;
3685 	__vki_u32   width;
3686 	__vki_u32   height;
3687 };
3688 
3689 struct vki_v4l2_fract {
3690 	__vki_u32   numerator;
3691 	__vki_u32   denominator;
3692 };
3693 
3694 struct vki_v4l2_capability {
3695 	__vki_u8	driver[16];
3696 	__vki_u8	card[32];
3697 	__vki_u8	bus_info[32];
3698 	__vki_u32   version;
3699 	__vki_u32	capabilities;
3700 	__vki_u32	device_caps;
3701 	__vki_u32	reserved[3];
3702 };
3703 
3704 struct vki_v4l2_pix_format {
3705 	__vki_u32         		width;
3706 	__vki_u32			height;
3707 	__vki_u32			pixelformat;
3708 	__vki_u32			field;		/* enum vki_v4l2_field */
3709 	__vki_u32            	bytesperline;	/* for padding, zero if unused */
3710 	__vki_u32          		sizeimage;
3711 	__vki_u32			colorspace;	/* enum vki_v4l2_colorspace */
3712 	__vki_u32			priv;		/* private data, depends on pixelformat */
3713 	__vki_u32			flags;		/* format flags (VKI_V4L2_PIX_FMT_FLAG_*) */
3714 	__vki_u32			ycbcr_enc;
3715 	__vki_u32			quantization;
3716 };
3717 
3718 struct vki_v4l2_fmtdesc {
3719 	__vki_u32		    index;             /* Format number      */
3720 	__vki_u32		    type;              /* enum vki_v4l2_buf_type */
3721 	__vki_u32               flags;
3722 	__vki_u8		    description[32];   /* Description string */
3723 	__vki_u32		    pixelformat;       /* Format fourcc      */
3724 	__vki_u32		    reserved[4];
3725 };
3726 
3727 struct vki_v4l2_frmsize_discrete {
3728 	__vki_u32			width;		/* Frame width [pixel] */
3729 	__vki_u32			height;		/* Frame height [pixel] */
3730 };
3731 
3732 struct vki_v4l2_frmsize_stepwise {
3733 	__vki_u32			min_width;	/* Minimum frame width [pixel] */
3734 	__vki_u32			max_width;	/* Maximum frame width [pixel] */
3735 	__vki_u32			step_width;	/* Frame width step size [pixel] */
3736 	__vki_u32			min_height;	/* Minimum frame height [pixel] */
3737 	__vki_u32			max_height;	/* Maximum frame height [pixel] */
3738 	__vki_u32			step_height;	/* Frame height step size [pixel] */
3739 };
3740 
3741 struct vki_v4l2_frmsizeenum {
3742 	__vki_u32			index;		/* Frame size number */
3743 	__vki_u32			pixel_format;	/* Pixel format */
3744 	__vki_u32			type;		/* Frame size type the device supports. */
3745 
3746 	union {					/* Frame size */
3747 		struct vki_v4l2_frmsize_discrete	discrete;
3748 		struct vki_v4l2_frmsize_stepwise	stepwise;
3749 	};
3750 
3751 	__vki_u32   reserved[2];			/* Reserved space for future use */
3752 };
3753 
3754 struct vki_v4l2_frmival_stepwise {
3755 	struct vki_v4l2_fract	min;
3756 	struct vki_v4l2_fract	max;
3757 	struct vki_v4l2_fract	step;
3758 };
3759 
3760 struct vki_v4l2_frmivalenum {
3761 	__vki_u32			index;
3762 	__vki_u32			pixel_format;
3763 	__vki_u32			width;
3764 	__vki_u32			height;
3765 	__vki_u32			type;
3766 
3767 	union {
3768 		struct vki_v4l2_fract		discrete;
3769 		struct vki_v4l2_frmival_stepwise	stepwise;
3770 	};
3771 
3772 	__vki_u32	reserved[2];
3773 };
3774 
3775 struct vki_v4l2_timecode {
3776 	__vki_u32	type;
3777 	__vki_u32	flags;
3778 	__vki_u8	frames;
3779 	__vki_u8	seconds;
3780 	__vki_u8	minutes;
3781 	__vki_u8	hours;
3782 	__vki_u8	userbits[4];
3783 };
3784 
3785 struct vki_v4l2_jpegcompression {
3786 	int quality;
3787 	int  APPn;
3788 	int  APP_len;
3789 	char APP_data[60];
3790 	int  COM_len;
3791 	char COM_data[60];
3792 	__vki_u32 jpeg_markers;
3793 };
3794 
3795 struct vki_v4l2_requestbuffers {
3796 	__vki_u32			count;
3797 	__vki_u32			type;
3798 	__vki_u32			memory;
3799 	__vki_u32			reserved[2];
3800 };
3801 
3802 struct vki_v4l2_plane {
3803 	__vki_u32			bytesused;
3804 	__vki_u32			length;
3805 	union {
3806 		__vki_u32		mem_offset;
3807 		unsigned long	userptr;
3808 		__vki_s32		fd;
3809 	} m;
3810 	__vki_u32			data_offset;
3811 	__vki_u32			reserved[11];
3812 };
3813 
3814 #define VKI_V4L2_MEMORY_MMAP             1
3815 #define VKI_V4L2_MEMORY_DMABUF           4
3816 #define VKI_V4L2_BUF_FLAG_TIMESTAMP_MASK		0x0000e000
3817 #define VKI_V4L2_BUF_FLAG_TIMESTAMP_COPY		0x00004000
3818 struct vki_v4l2_buffer {
3819 	__vki_u32			index;
3820 	__vki_u32			type;
3821 	__vki_u32			bytesused;
3822 	__vki_u32			flags;
3823 	__vki_u32			field;
3824 	struct vki_timeval		timestamp;
3825 	struct vki_v4l2_timecode	timecode;
3826 	__vki_u32			sequence;
3827 
3828 	/* memory location */
3829 	__vki_u32			memory;
3830 	union {
3831 		__vki_u32           offset;
3832 		unsigned long   userptr;
3833 		struct vki_v4l2_plane *planes;
3834 		__vki_s32		fd;
3835 	} m;
3836 	__vki_u32			length;
3837 	__vki_u32			reserved2;
3838 	__vki_u32			reserved;
3839 };
3840 
3841 struct vki_v4l2_exportbuffer {
3842 	__vki_u32		type; /* enum vki_v4l2_buf_type */
3843 	__vki_u32		index;
3844 	__vki_u32		plane;
3845 	__vki_u32		flags;
3846 	__vki_s32		fd;
3847 	__vki_u32		reserved[11];
3848 };
3849 
3850 struct vki_v4l2_framebuffer {
3851 	__vki_u32			capability;
3852 	__vki_u32			flags;
3853 	void                    *base;
3854 	struct {
3855 		__vki_u32		width;
3856 		__vki_u32		height;
3857 		__vki_u32		pixelformat;
3858 		__vki_u32		field;		/* enum vki_v4l2_field */
3859 		__vki_u32		bytesperline;	/* for padding, zero if unused */
3860 		__vki_u32		sizeimage;
3861 		__vki_u32		colorspace;	/* enum vki_v4l2_colorspace */
3862 		__vki_u32		priv;		/* reserved field, set to 0 */
3863 	} fmt;
3864 };
3865 
3866 struct vki_v4l2_clip {
3867 	struct vki_v4l2_rect        c;
3868 	struct vki_v4l2_clip	__user *next;
3869 };
3870 
3871 struct vki_v4l2_window {
3872 	struct vki_v4l2_rect        w;
3873 	__vki_u32			field;	 /* enum vki_v4l2_field */
3874 	__vki_u32			chromakey;
3875 	struct vki_v4l2_clip	__user *clips;
3876 	__vki_u32			clipcount;
3877 	void			__user *bitmap;
3878 	__vki_u8                    global_alpha;
3879 };
3880 
3881 struct vki_v4l2_captureparm {
3882 	__vki_u32		   capability;	  /*  Supported modes */
3883 	__vki_u32		   capturemode;	  /*  Current mode */
3884 	struct vki_v4l2_fract  timeperframe;  /*  Time per frame in seconds */
3885 	__vki_u32		   extendedmode;  /*  Driver-specific extensions */
3886 	__vki_u32              readbuffers;   /*  # of buffers for read */
3887 	__vki_u32		   reserved[4];
3888 };
3889 
3890 struct vki_v4l2_outputparm {
3891 	__vki_u32		   capability;	 /*  Supported modes */
3892 	__vki_u32		   outputmode;	 /*  Current mode */
3893 	struct vki_v4l2_fract  timeperframe; /*  Time per frame in seconds */
3894 	__vki_u32		   extendedmode; /*  Driver-specific extensions */
3895 	__vki_u32              writebuffers; /*  # of buffers for write */
3896 	__vki_u32		   reserved[4];
3897 };
3898 
3899 struct vki_v4l2_cropcap {
3900 	__vki_u32			type;	/* enum vki_v4l2_buf_type */
3901 	struct vki_v4l2_rect        bounds;
3902 	struct vki_v4l2_rect        defrect;
3903 	struct vki_v4l2_fract       pixelaspect;
3904 };
3905 
3906 struct vki_v4l2_crop {
3907 	__vki_u32			type;	/* enum vki_v4l2_buf_type */
3908 	struct vki_v4l2_rect        c;
3909 };
3910 
3911 struct vki_v4l2_selection {
3912 	__vki_u32			type;
3913 	__vki_u32			target;
3914 	__vki_u32                   flags;
3915 	struct vki_v4l2_rect        r;
3916 	__vki_u32                   reserved[9];
3917 };
3918 
3919 typedef __vki_u64 vki_v4l2_std_id;
3920 
3921 struct vki_v4l2_standard {
3922 	__vki_u32		     index;
3923 	vki_v4l2_std_id          id;
3924 	__vki_u8		     name[24];
3925 	struct vki_v4l2_fract    frameperiod; /* Frames, not fields */
3926 	__vki_u32		     framelines;
3927 	__vki_u32		     reserved[4];
3928 };
3929 
3930 struct vki_v4l2_bt_timings {
3931 	__vki_u32	width;
3932 	__vki_u32	height;
3933 	__vki_u32	interlaced;
3934 	__vki_u32	polarities;
3935 	__vki_u64	pixelclock;
3936 	__vki_u32	hfrontporch;
3937 	__vki_u32	hsync;
3938 	__vki_u32	hbackporch;
3939 	__vki_u32	vfrontporch;
3940 	__vki_u32	vsync;
3941 	__vki_u32	vbackporch;
3942 	__vki_u32	il_vfrontporch;
3943 	__vki_u32	il_vsync;
3944 	__vki_u32	il_vbackporch;
3945 	__vki_u32	standards;
3946 	__vki_u32	flags;
3947 	__vki_u32	reserved[14];
3948 } __attribute__ ((packed));
3949 
3950 struct vki_v4l2_dv_timings {
3951 	__vki_u32 type;
3952 	union {
3953 		struct vki_v4l2_bt_timings	bt;
3954 		__vki_u32	reserved[32];
3955 	};
3956 } __attribute__ ((packed));
3957 
3958 struct vki_v4l2_enum_dv_timings {
3959 	__vki_u32 index;
3960 	__vki_u32 pad;
3961 	__vki_u32 reserved[2];
3962 	struct vki_v4l2_dv_timings timings;
3963 };
3964 
3965 struct vki_v4l2_bt_timings_cap {
3966 	__vki_u32	min_width;
3967 	__vki_u32	max_width;
3968 	__vki_u32	min_height;
3969 	__vki_u32	max_height;
3970 	__vki_u64	min_pixelclock;
3971 	__vki_u64	max_pixelclock;
3972 	__vki_u32	standards;
3973 	__vki_u32	capabilities;
3974 	__vki_u32	reserved[16];
3975 } __attribute__ ((packed));
3976 
3977 struct vki_v4l2_dv_timings_cap {
3978 	__vki_u32 type;
3979 	__vki_u32 pad;
3980 	__vki_u32 reserved[2];
3981 	union {
3982 		struct vki_v4l2_bt_timings_cap bt;
3983 		__vki_u32 raw_data[32];
3984 	};
3985 };
3986 
3987 struct vki_v4l2_input {
3988 	__vki_u32	     index;		/*  Which input */
3989 	__vki_u8	     name[32];		/*  Label */
3990 	__vki_u32	     type;		/*  Type of input */
3991 	__vki_u32	     audioset;		/*  Associated audios (bitfield) */
3992 	__vki_u32        tuner;             /*  enum vki_v4l2_tuner_type */
3993 	vki_v4l2_std_id  std;
3994 	__vki_u32	     status;
3995 	__vki_u32	     capabilities;
3996 	__vki_u32	     reserved[3];
3997 };
3998 
3999 struct vki_v4l2_output {
4000 	__vki_u32	     index;		/*  Which output */
4001 	__vki_u8	     name[32];		/*  Label */
4002 	__vki_u32	     type;		/*  Type of output */
4003 	__vki_u32	     audioset;		/*  Associated audios (bitfield) */
4004 	__vki_u32	     modulator;         /*  Associated modulator */
4005 	vki_v4l2_std_id  std;
4006 	__vki_u32	     capabilities;
4007 	__vki_u32	     reserved[3];
4008 };
4009 
4010 struct vki_v4l2_control {
4011 	__vki_u32		     id;
4012 	__vki_s32		     value;
4013 };
4014 
4015 struct vki_v4l2_ext_control {
4016 	__vki_u32 id;
4017 	__vki_u32 size;
4018 	__vki_u32 reserved2[1];
4019 	union {
4020 		__vki_s32 value;
4021 		__vki_s64 value64;
4022 		char *string;
4023 		__vki_u8 *p_u8;
4024 		__vki_u16 *p_u16;
4025 		__vki_u32 *p_u32;
4026 		void *ptr;
4027 	};
4028 } __attribute__ ((packed));
4029 
4030 struct vki_v4l2_ext_controls {
4031 	__vki_u32 ctrl_class;
4032 	__vki_u32 count;
4033 	__vki_u32 error_idx;
4034 	__vki_u32 reserved[2];
4035 	struct vki_v4l2_ext_control *controls;
4036 };
4037 
4038 struct vki_v4l2_queryctrl {
4039 	__vki_u32		     id;
4040 	__vki_u32		     type;	/* enum vki_v4l2_ctrl_type */
4041 	__vki_u8		     name[32];	/* Whatever */
4042 	__vki_s32		     minimum;	/* Note signedness */
4043 	__vki_s32		     maximum;
4044 	__vki_s32		     step;
4045 	__vki_s32		     default_value;
4046 	__vki_u32                flags;
4047 	__vki_u32		     reserved[2];
4048 };
4049 
4050 #define VKI_V4L2_CTRL_MAX_DIMS	  (4)
4051 struct vki_v4l2_query_ext_ctrl {
4052 	__vki_u32		     id;
4053 	__vki_u32		     type;
4054 	char		     name[32];
4055 	__vki_s64		     minimum;
4056 	__vki_s64		     maximum;
4057 	__vki_u64		     step;
4058 	__vki_s64		     default_value;
4059 	__vki_u32                flags;
4060 	__vki_u32                elem_size;
4061 	__vki_u32                elems;
4062 	__vki_u32                nr_of_dims;
4063 	__vki_u32                dims[VKI_V4L2_CTRL_MAX_DIMS];
4064 	__vki_u32		     reserved[32];
4065 };
4066 
4067 struct vki_v4l2_querymenu {
4068 	__vki_u32		id;
4069 	__vki_u32		index;
4070 	union {
4071 		__vki_u8	name[32];	/* Whatever */
4072 		__vki_s64	value;
4073 	};
4074 	__vki_u32		reserved;
4075 } __attribute__ ((packed));
4076 
4077 struct vki_v4l2_tuner {
4078 	__vki_u32                   index;
4079 	__vki_u8			name[32];
4080 	__vki_u32			type;	/* enum vki_v4l2_tuner_type */
4081 	__vki_u32			capability;
4082 	__vki_u32			rangelow;
4083 	__vki_u32			rangehigh;
4084 	__vki_u32			rxsubchans;
4085 	__vki_u32			audmode;
4086 	__vki_s32			signal;
4087 	__vki_s32			afc;
4088 	__vki_u32			reserved[4];
4089 };
4090 
4091 struct vki_v4l2_modulator {
4092 	__vki_u32			index;
4093 	__vki_u8			name[32];
4094 	__vki_u32			capability;
4095 	__vki_u32			rangelow;
4096 	__vki_u32			rangehigh;
4097 	__vki_u32			txsubchans;
4098 	__vki_u32			reserved[4];
4099 };
4100 
4101 struct vki_v4l2_frequency {
4102 	__vki_u32	tuner;
4103 	__vki_u32	type;	/* enum vki_v4l2_tuner_type */
4104 	__vki_u32	frequency;
4105 	__vki_u32	reserved[8];
4106 };
4107 
4108 struct vki_v4l2_frequency_band {
4109 	__vki_u32	tuner;
4110 	__vki_u32	type;	/* enum vki_v4l2_tuner_type */
4111 	__vki_u32	index;
4112 	__vki_u32	capability;
4113 	__vki_u32	rangelow;
4114 	__vki_u32	rangehigh;
4115 	__vki_u32	modulation;
4116 	__vki_u32	reserved[9];
4117 };
4118 
4119 struct vki_v4l2_hw_freq_seek {
4120 	__vki_u32	tuner;
4121 	__vki_u32	type;	/* enum vki_v4l2_tuner_type */
4122 	__vki_u32	seek_upward;
4123 	__vki_u32	wrap_around;
4124 	__vki_u32	spacing;
4125 	__vki_u32	rangelow;
4126 	__vki_u32	rangehigh;
4127 	__vki_u32	reserved[5];
4128 };
4129 
4130 struct vki_v4l2_audio {
4131 	__vki_u32	index;
4132 	__vki_u8	name[32];
4133 	__vki_u32	capability;
4134 	__vki_u32	mode;
4135 	__vki_u32	reserved[2];
4136 };
4137 
4138 struct vki_v4l2_audioout {
4139 	__vki_u32	index;
4140 	__vki_u8	name[32];
4141 	__vki_u32	capability;
4142 	__vki_u32	mode;
4143 	__vki_u32	reserved[2];
4144 };
4145 
4146 struct vki_v4l2_enc_idx_entry {
4147 	__vki_u64 offset;
4148 	__vki_u64 pts;
4149 	__vki_u32 length;
4150 	__vki_u32 flags;
4151 	__vki_u32 reserved[2];
4152 };
4153 
4154 #define VKI_V4L2_ENC_IDX_ENTRIES (64)
4155 struct vki_v4l2_enc_idx {
4156 	__vki_u32 entries;
4157 	__vki_u32 entries_cap;
4158 	__vki_u32 reserved[4];
4159 	struct vki_v4l2_enc_idx_entry entry[VKI_V4L2_ENC_IDX_ENTRIES];
4160 };
4161 
4162 struct vki_v4l2_encoder_cmd {
4163 	__vki_u32 cmd;
4164 	__vki_u32 flags;
4165 	union {
4166 		struct {
4167 			__vki_u32 data[8];
4168 		} raw;
4169 	};
4170 };
4171 
4172 struct vki_v4l2_decoder_cmd {
4173 	__vki_u32 cmd;
4174 	__vki_u32 flags;
4175 	union {
4176 		struct {
4177 			__vki_u64 pts;
4178 		} stop;
4179 
4180 		struct {
4181 			__vki_s32 speed;
4182 			__vki_u32 format;
4183 		} start;
4184 
4185 		struct {
4186 			__vki_u32 data[16];
4187 		} raw;
4188 	};
4189 };
4190 
4191 struct vki_v4l2_vbi_format {
4192 	__vki_u32	sampling_rate;		/* in 1 Hz */
4193 	__vki_u32	offset;
4194 	__vki_u32	samples_per_line;
4195 	__vki_u32	sample_format;		/* VKI_V4L2_PIX_FMT_* */
4196 	__vki_s32	start[2];
4197 	__vki_u32	count[2];
4198 	__vki_u32	flags;			/* VKI_V4L2_VBI_* */
4199 	__vki_u32	reserved[2];		/* must be zero */
4200 };
4201 
4202 struct vki_v4l2_sliced_vbi_format {
4203 	__vki_u16   service_set;
4204 	__vki_u16   service_lines[2][24];
4205 	__vki_u32   io_size;
4206 	__vki_u32   reserved[2];            /* must be zero */
4207 };
4208 
4209 struct vki_v4l2_sliced_vbi_cap {
4210 	__vki_u16   service_set;
4211 	__vki_u16   service_lines[2][24];
4212 	__vki_u32	type;		/* enum vki_v4l2_buf_type */
4213 	__vki_u32   reserved[3];    /* must be 0 */
4214 };
4215 
4216 struct vki_v4l2_sliced_vbi_data {
4217 	__vki_u32   id;
4218 	__vki_u32   field;          /* 0: first field, 1: second field */
4219 	__vki_u32   line;           /* 1-23 */
4220 	__vki_u32   reserved;       /* must be 0 */
4221 	__vki_u8    data[48];
4222 };
4223 
4224 struct vki_v4l2_plane_pix_format {
4225 	__vki_u32		sizeimage;
4226 	__vki_u16		bytesperline;
4227 	__vki_u16		reserved[7];
4228 } __attribute__ ((packed));
4229 
4230 #define VKI_VIDEO_MAX_PLANES               8
4231 
4232 struct vki_v4l2_pix_format_mplane {
4233 	__vki_u32				width;
4234 	__vki_u32				height;
4235 	__vki_u32				pixelformat;
4236 	__vki_u32				field;
4237 	__vki_u32				colorspace;
4238 
4239 	struct vki_v4l2_plane_pix_format	plane_fmt[VKI_VIDEO_MAX_PLANES];
4240 	__vki_u8				num_planes;
4241 	__vki_u8				flags;
4242 	__vki_u8				ycbcr_enc;
4243 	__vki_u8				quantization;
4244 	__vki_u8				reserved[8];
4245 } __attribute__ ((packed));
4246 
4247 struct vki_v4l2_sdr_format {
4248 	__vki_u32				pixelformat;
4249 	__vki_u32				buffersize;
4250 	__vki_u8				reserved[24];
4251 } __attribute__ ((packed));
4252 
4253 enum vki_v4l2_buf_type {
4254 	VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE        = 1,
4255 	VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT         = 2,
4256 	VKI_V4L2_BUF_TYPE_VIDEO_OVERLAY        = 3,
4257 	VKI_V4L2_BUF_TYPE_VBI_CAPTURE          = 4,
4258 	VKI_V4L2_BUF_TYPE_VBI_OUTPUT           = 5,
4259 	VKI_V4L2_BUF_TYPE_SLICED_VBI_CAPTURE   = 6,
4260 	VKI_V4L2_BUF_TYPE_SLICED_VBI_OUTPUT    = 7,
4261 	VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY = 8,
4262 	VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE = 9,
4263 	VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE  = 10,
4264 	VKI_V4L2_BUF_TYPE_SDR_CAPTURE          = 11,
4265 };
4266 
4267 struct vki_v4l2_format {
4268 	__vki_u32	 type;
4269 	union {
4270 		struct vki_v4l2_pix_format		pix;
4271 		struct vki_v4l2_pix_format_mplane	pix_mp;
4272 		struct vki_v4l2_window		win;
4273 		struct vki_v4l2_vbi_format		vbi;
4274 		struct vki_v4l2_sliced_vbi_format	sliced;
4275 		struct vki_v4l2_sdr_format		sdr;
4276 		__vki_u8	raw_data[200];
4277 	} fmt;
4278 };
4279 
4280 struct vki_v4l2_streamparm {
4281 	__vki_u32	 type;
4282 	union {
4283 		struct vki_v4l2_captureparm	capture;
4284 		struct vki_v4l2_outputparm	output;
4285 		__vki_u8	raw_data[200];  /* user-defined */
4286 	} parm;
4287 };
4288 
4289 struct vki_v4l2_event_vsync {
4290 	__vki_u8 field;
4291 } __attribute__ ((packed));
4292 
4293 struct vki_v4l2_event_ctrl {
4294 	__vki_u32 changes;
4295 	__vki_u32 type;
4296 	union {
4297 		__vki_s32 value;
4298 		__vki_s64 value64;
4299 	};
4300 	__vki_u32 flags;
4301 	__vki_s32 minimum;
4302 	__vki_s32 maximum;
4303 	__vki_s32 step;
4304 	__vki_s32 default_value;
4305 };
4306 
4307 struct vki_v4l2_event_frame_sync {
4308 	__vki_u32 frame_sequence;
4309 };
4310 
4311 struct vki_v4l2_event_src_change {
4312 	__vki_u32 changes;
4313 };
4314 
4315 struct vki_v4l2_event_motion_det {
4316 	__vki_u32 flags;
4317 	__vki_u32 frame_sequence;
4318 	__vki_u32 region_mask;
4319 };
4320 
4321 struct vki_v4l2_event {
4322 	__vki_u32				type;
4323 	union {
4324 		struct vki_v4l2_event_vsync		vsync;
4325 		struct vki_v4l2_event_ctrl		ctrl;
4326 		struct vki_v4l2_event_frame_sync	frame_sync;
4327 		struct vki_v4l2_event_src_change	src_change;
4328 		struct vki_v4l2_event_motion_det	motion_det;
4329 		__vki_u8				data[64];
4330 	} u;
4331 	__vki_u32				pending;
4332 	__vki_u32				sequence;
4333 	struct vki_timespec			timestamp;
4334 	__vki_u32				id;
4335 	__vki_u32				reserved[8];
4336 };
4337 
4338 struct vki_v4l2_event_subscription {
4339 	__vki_u32				type;
4340 	__vki_u32				id;
4341 	__vki_u32				flags;
4342 	__vki_u32				reserved[5];
4343 };
4344 
4345 struct vki_v4l2_dbg_match {
4346 	__vki_u32 type; /* Match type */
4347 	union {     /* Match this chip, meaning determined by type */
4348 		__vki_u32 addr;
4349 		char name[32];
4350 	};
4351 } __attribute__ ((packed));
4352 
4353 struct vki_v4l2_dbg_register {
4354 	struct vki_v4l2_dbg_match match;
4355 	__vki_u32 size;	/* register size in bytes */
4356 	__vki_u64 reg;
4357 	__vki_u64 val;
4358 } __attribute__ ((packed));
4359 
4360 struct vki_v4l2_dbg_chip_info {
4361 	struct vki_v4l2_dbg_match match;
4362 	char name[32];
4363 	__vki_u32 flags;
4364 	__vki_u32 reserved[32];
4365 } __attribute__ ((packed));
4366 
4367 struct vki_v4l2_create_buffers {
4368 	__vki_u32			index;
4369 	__vki_u32			count;
4370 	__vki_u32			memory;
4371 	struct vki_v4l2_format	format;
4372 	__vki_u32			reserved[8];
4373 };
4374 
4375 struct vki_v4l2_edid {
4376 	__vki_u32 pad;
4377 	__vki_u32 start_block;
4378 	__vki_u32 blocks;
4379 	__vki_u32 reserved[5];
4380 	__vki_u8  *edid;
4381 };
4382 
4383 #define VKI_V4L2_QUERYCAP		_VKI_IOR('V',  0, struct vki_v4l2_capability)
4384 #define VKI_V4L2_ENUM_FMT		_VKI_IOWR('V',  2, struct vki_v4l2_fmtdesc)
4385 #define VKI_V4L2_G_FMT			_VKI_IOWR('V',  4, struct vki_v4l2_format)
4386 #define VKI_V4L2_S_FMT			_VKI_IOWR('V',  5, struct vki_v4l2_format)
4387 #define VKI_V4L2_REQBUFS		_VKI_IOWR('V',  8, struct vki_v4l2_requestbuffers)
4388 #define VKI_V4L2_QUERYBUF		_VKI_IOWR('V',  9, struct vki_v4l2_buffer)
4389 #define VKI_V4L2_G_FBUF		 	_VKI_IOR('V', 10, struct vki_v4l2_framebuffer)
4390 #define VKI_V4L2_S_FBUF		 	_VKI_IOW('V', 11, struct vki_v4l2_framebuffer)
4391 #define VKI_V4L2_OVERLAY	 	_VKI_IOW('V', 14, int)
4392 #define VKI_V4L2_QBUF			_VKI_IOWR('V', 15, struct vki_v4l2_buffer)
4393 #define VKI_V4L2_EXPBUF			_VKI_IOWR('V', 16, struct vki_v4l2_exportbuffer)
4394 #define VKI_V4L2_DQBUF			_VKI_IOWR('V', 17, struct vki_v4l2_buffer)
4395 #define VKI_V4L2_STREAMON	 	_VKI_IOW('V', 18, int)
4396 #define VKI_V4L2_STREAMOFF	 	_VKI_IOW('V', 19, int)
4397 #define VKI_V4L2_G_PARM			_VKI_IOWR('V', 21, struct vki_v4l2_streamparm)
4398 #define VKI_V4L2_S_PARM			_VKI_IOWR('V', 22, struct vki_v4l2_streamparm)
4399 #define VKI_V4L2_G_STD			_VKI_IOR('V', 23, vki_v4l2_std_id)
4400 #define VKI_V4L2_S_STD			_VKI_IOW('V', 24, vki_v4l2_std_id)
4401 #define VKI_V4L2_ENUMSTD		_VKI_IOWR('V', 25, struct vki_v4l2_standard)
4402 #define VKI_V4L2_ENUMINPUT		_VKI_IOWR('V', 26, struct vki_v4l2_input)
4403 #define VKI_V4L2_G_CTRL			_VKI_IOWR('V', 27, struct vki_v4l2_control)
4404 #define VKI_V4L2_S_CTRL			_VKI_IOWR('V', 28, struct vki_v4l2_control)
4405 #define VKI_V4L2_G_TUNER		_VKI_IOWR('V', 29, struct vki_v4l2_tuner)
4406 #define VKI_V4L2_S_TUNER		_VKI_IOW('V', 30, struct vki_v4l2_tuner)
4407 #define VKI_V4L2_G_AUDIO		_VKI_IOR('V', 33, struct vki_v4l2_audio)
4408 #define VKI_V4L2_S_AUDIO		_VKI_IOW('V', 34, struct vki_v4l2_audio)
4409 #define VKI_V4L2_QUERYCTRL		_VKI_IOWR('V', 36, struct vki_v4l2_queryctrl)
4410 #define VKI_V4L2_QUERYMENU		_VKI_IOWR('V', 37, struct vki_v4l2_querymenu)
4411 #define VKI_V4L2_G_INPUT		_VKI_IOR('V', 38, int)
4412 #define VKI_V4L2_S_INPUT		_VKI_IOWR('V', 39, int)
4413 #define VKI_V4L2_G_EDID			_VKI_IOWR('V', 40, struct vki_v4l2_edid)
4414 #define VKI_V4L2_S_EDID			_VKI_IOWR('V', 41, struct vki_v4l2_edid)
4415 #define VKI_V4L2_G_OUTPUT		_VKI_IOR('V', 46, int)
4416 #define VKI_V4L2_S_OUTPUT		_VKI_IOWR('V', 47, int)
4417 #define VKI_V4L2_ENUMOUTPUT		_VKI_IOWR('V', 48, struct vki_v4l2_output)
4418 #define VKI_V4L2_G_AUDOUT		_VKI_IOR('V', 49, struct vki_v4l2_audioout)
4419 #define VKI_V4L2_S_AUDOUT		_VKI_IOW('V', 50, struct vki_v4l2_audioout)
4420 #define VKI_V4L2_G_MODULATOR		_VKI_IOWR('V', 54, struct vki_v4l2_modulator)
4421 #define VKI_V4L2_S_MODULATOR		_VKI_IOW('V', 55, struct vki_v4l2_modulator)
4422 #define VKI_V4L2_G_FREQUENCY		_VKI_IOWR('V', 56, struct vki_v4l2_frequency)
4423 #define VKI_V4L2_S_FREQUENCY		_VKI_IOW('V', 57, struct vki_v4l2_frequency)
4424 #define VKI_V4L2_CROPCAP		_VKI_IOWR('V', 58, struct vki_v4l2_cropcap)
4425 #define VKI_V4L2_G_CROP			_VKI_IOWR('V', 59, struct vki_v4l2_crop)
4426 #define VKI_V4L2_S_CROP			_VKI_IOW('V', 60, struct vki_v4l2_crop)
4427 #define VKI_V4L2_G_JPEGCOMP		_VKI_IOR('V', 61, struct vki_v4l2_jpegcompression)
4428 #define VKI_V4L2_S_JPEGCOMP		_VKI_IOW('V', 62, struct vki_v4l2_jpegcompression)
4429 #define VKI_V4L2_QUERYSTD      		_VKI_IOR('V', 63, vki_v4l2_std_id)
4430 #define VKI_V4L2_TRY_FMT      		_VKI_IOWR('V', 64, struct vki_v4l2_format)
4431 #define VKI_V4L2_ENUMAUDIO		_VKI_IOWR('V', 65, struct vki_v4l2_audio)
4432 #define VKI_V4L2_ENUMAUDOUT		_VKI_IOWR('V', 66, struct vki_v4l2_audioout)
4433 #define VKI_V4L2_G_PRIORITY		_VKI_IOR('V', 67, __vki_u32)
4434 #define VKI_V4L2_S_PRIORITY		_VKI_IOW('V', 68, __vki_u32)
4435 #define VKI_V4L2_G_SLICED_VBI_CAP 	_VKI_IOWR('V', 69, struct vki_v4l2_sliced_vbi_cap)
4436 #define VKI_V4L2_LOG_STATUS     	_VKI_IO('V', 70)
4437 #define VKI_V4L2_G_EXT_CTRLS		_VKI_IOWR('V', 71, struct vki_v4l2_ext_controls)
4438 #define VKI_V4L2_S_EXT_CTRLS		_VKI_IOWR('V', 72, struct vki_v4l2_ext_controls)
4439 #define VKI_V4L2_TRY_EXT_CTRLS		_VKI_IOWR('V', 73, struct vki_v4l2_ext_controls)
4440 #define VKI_V4L2_ENUM_FRAMESIZES	_VKI_IOWR('V', 74, struct vki_v4l2_frmsizeenum)
4441 #define VKI_V4L2_ENUM_FRAMEINTERVALS 	_VKI_IOWR('V', 75, struct vki_v4l2_frmivalenum)
4442 #define VKI_V4L2_G_ENC_INDEX    	_VKI_IOR('V', 76, struct vki_v4l2_enc_idx)
4443 #define VKI_V4L2_ENCODER_CMD    	_VKI_IOWR('V', 77, struct vki_v4l2_encoder_cmd)
4444 #define VKI_V4L2_TRY_ENCODER_CMD 	_VKI_IOWR('V', 78, struct vki_v4l2_encoder_cmd)
4445 #define	VKI_V4L2_DBG_S_REGISTER 	_VKI_IOW('V', 79, struct vki_v4l2_dbg_register)
4446 #define	VKI_V4L2_DBG_G_REGISTER 	_VKI_IOWR('V', 80, struct vki_v4l2_dbg_register)
4447 #define VKI_V4L2_S_HW_FREQ_SEEK		_VKI_IOW('V', 82, struct vki_v4l2_hw_freq_seek)
4448 #define	VKI_V4L2_S_DV_TIMINGS		_VKI_IOWR('V', 87, struct vki_v4l2_dv_timings)
4449 #define	VKI_V4L2_G_DV_TIMINGS		_VKI_IOWR('V', 88, struct vki_v4l2_dv_timings)
4450 #define	VKI_V4L2_DQEVENT		_VKI_IOR('V', 89, struct vki_v4l2_event)
4451 #define	VKI_V4L2_SUBSCRIBE_EVENT	_VKI_IOW('V', 90, struct vki_v4l2_event_subscription)
4452 #define	VKI_V4L2_UNSUBSCRIBE_EVENT 	_VKI_IOW('V', 91, struct vki_v4l2_event_subscription)
4453 #define VKI_V4L2_CREATE_BUFS		_VKI_IOWR('V', 92, struct vki_v4l2_create_buffers)
4454 #define VKI_V4L2_PREPARE_BUF		_VKI_IOWR('V', 93, struct vki_v4l2_buffer)
4455 #define VKI_V4L2_G_SELECTION		_VKI_IOWR('V', 94, struct vki_v4l2_selection)
4456 #define VKI_V4L2_S_SELECTION		_VKI_IOWR('V', 95, struct vki_v4l2_selection)
4457 #define VKI_V4L2_DECODER_CMD		_VKI_IOWR('V', 96, struct vki_v4l2_decoder_cmd)
4458 #define VKI_V4L2_TRY_DECODER_CMD	_VKI_IOWR('V', 97, struct vki_v4l2_decoder_cmd)
4459 #define VKI_V4L2_ENUM_DV_TIMINGS 	_VKI_IOWR('V', 98, struct vki_v4l2_enum_dv_timings)
4460 #define VKI_V4L2_QUERY_DV_TIMINGS 	_VKI_IOR('V', 99, struct vki_v4l2_dv_timings)
4461 #define VKI_V4L2_DV_TIMINGS_CAP   	_VKI_IOWR('V', 100, struct vki_v4l2_dv_timings_cap)
4462 #define VKI_V4L2_ENUM_FREQ_BANDS	_VKI_IOWR('V', 101, struct vki_v4l2_frequency_band)
4463 #define VKI_V4L2_DBG_G_CHIP_INFO 	_VKI_IOWR('V', 102, struct vki_v4l2_dbg_chip_info)
4464 #define VKI_V4L2_QUERY_EXT_CTRL		_VKI_IOWR('V', 103, struct vki_v4l2_query_ext_ctrl)
4465 
4466 struct vki_v4l2_mbus_framefmt {
4467 	__vki_u32			width;
4468 	__vki_u32			height;
4469 	__vki_u32			code;
4470 	__vki_u32			field;
4471 	__vki_u32			colorspace;
4472 	__vki_u16			ycbcr_enc;
4473 	__vki_u16			quantization;
4474 	__vki_u32			reserved[6];
4475 };
4476 
4477 struct vki_v4l2_subdev_format {
4478 	__vki_u32 which;
4479 	__vki_u32 pad;
4480 	struct vki_v4l2_mbus_framefmt format;
4481 	__vki_u32 reserved[8];
4482 };
4483 
4484 struct vki_v4l2_subdev_crop {
4485 	__vki_u32 which;
4486 	__vki_u32 pad;
4487 	struct vki_v4l2_rect rect;
4488 	__vki_u32 reserved[8];
4489 };
4490 
4491 struct vki_v4l2_subdev_mbus_code_enum {
4492 	__vki_u32 pad;
4493 	__vki_u32 index;
4494 	__vki_u32 code;
4495 	__vki_u32 reserved[9];
4496 };
4497 
4498 struct vki_v4l2_subdev_frame_size_enum {
4499 	__vki_u32 index;
4500 	__vki_u32 pad;
4501 	__vki_u32 code;
4502 	__vki_u32 min_width;
4503 	__vki_u32 max_width;
4504 	__vki_u32 min_height;
4505 	__vki_u32 max_height;
4506 	__vki_u32 reserved[9];
4507 };
4508 
4509 struct vki_v4l2_subdev_frame_interval {
4510 	__vki_u32 pad;
4511 	struct vki_v4l2_fract interval;
4512 	__vki_u32 reserved[9];
4513 };
4514 
4515 struct vki_v4l2_subdev_frame_interval_enum {
4516 	__vki_u32 index;
4517 	__vki_u32 pad;
4518 	__vki_u32 code;
4519 	__vki_u32 width;
4520 	__vki_u32 height;
4521 	struct vki_v4l2_fract interval;
4522 	__vki_u32 reserved[9];
4523 };
4524 
4525 struct vki_v4l2_subdev_selection {
4526 	__vki_u32 which;
4527 	__vki_u32 pad;
4528 	__vki_u32 target;
4529 	__vki_u32 flags;
4530 	struct vki_v4l2_rect r;
4531 	__vki_u32 reserved[8];
4532 };
4533 
4534 #define VKI_V4L2_SUBDEV_G_FMT			_VKI_IOWR('V',  4, struct vki_v4l2_subdev_format)
4535 #define VKI_V4L2_SUBDEV_S_FMT			_VKI_IOWR('V',  5, struct vki_v4l2_subdev_format)
4536 #define VKI_V4L2_SUBDEV_G_FRAME_INTERVAL	_VKI_IOWR('V', 21, struct vki_v4l2_subdev_frame_interval)
4537 #define VKI_V4L2_SUBDEV_S_FRAME_INTERVAL	_VKI_IOWR('V', 22, struct vki_v4l2_subdev_frame_interval)
4538 #define VKI_V4L2_SUBDEV_ENUM_MBUS_CODE		_VKI_IOWR('V',  2, struct vki_v4l2_subdev_mbus_code_enum)
4539 #define VKI_V4L2_SUBDEV_ENUM_FRAME_SIZE		_VKI_IOWR('V', 74, struct vki_v4l2_subdev_frame_size_enum)
4540 #define VKI_V4L2_SUBDEV_ENUM_FRAME_INTERVAL	_VKI_IOWR('V', 75, struct vki_v4l2_subdev_frame_interval_enum)
4541 #define VKI_V4L2_SUBDEV_G_CROP			_VKI_IOWR('V', 59, struct vki_v4l2_subdev_crop)
4542 #define VKI_V4L2_SUBDEV_S_CROP			_VKI_IOWR('V', 60, struct vki_v4l2_subdev_crop)
4543 #define VKI_V4L2_SUBDEV_G_SELECTION		_VKI_IOWR('V', 61, struct vki_v4l2_subdev_selection)
4544 #define VKI_V4L2_SUBDEV_S_SELECTION		_VKI_IOWR('V', 62, struct vki_v4l2_subdev_selection)
4545 
4546 struct vki_media_device_info {
4547 	char driver[16];
4548 	char model[32];
4549 	char serial[40];
4550 	char bus_info[32];
4551 	__vki_u32 media_version;
4552 	__vki_u32 hw_revision;
4553 	__vki_u32 driver_version;
4554 	__vki_u32 reserved[31];
4555 };
4556 
4557 struct vki_media_entity_desc {
4558 	__vki_u32 id;
4559 	char name[32];
4560 	__vki_u32 type;
4561 	__vki_u32 revision;
4562 	__vki_u32 flags;
4563 	__vki_u32 group_id;
4564 	__vki_u16 pads;
4565 	__vki_u16 links;
4566 
4567 	__vki_u32 reserved[4];
4568 
4569 	union {
4570 		/* Node specifications */
4571 		struct {
4572 			__vki_u32 major;
4573 			__vki_u32 minor;
4574 		} v4l;
4575 		struct {
4576 			__vki_u32 major;
4577 			__vki_u32 minor;
4578 		} fb;
4579 		struct {
4580 			__vki_u32 card;
4581 			__vki_u32 device;
4582 			__vki_u32 subdevice;
4583 		} alsa;
4584 		int dvb;
4585 
4586 		/* Sub-device specifications */
4587 		/* Nothing needed yet */
4588 		__vki_u8 raw[184];
4589 	};
4590 };
4591 
4592 struct vki_media_pad_desc {
4593 	__vki_u32 entity;		/* entity ID */
4594 	__vki_u16 index;		/* pad index */
4595 	__vki_u32 flags;		/* pad flags */
4596 	__vki_u32 reserved[2];
4597 };
4598 
4599 struct vki_media_link_desc {
4600 	struct vki_media_pad_desc source;
4601 	struct vki_media_pad_desc sink;
4602 	__vki_u32 flags;
4603 	__vki_u32 reserved[2];
4604 };
4605 
4606 struct vki_media_links_enum {
4607 	__vki_u32 entity;
4608 	struct vki_media_pad_desc __user *pads;
4609 	struct vki_media_link_desc __user *links;
4610 	__vki_u32 reserved[4];
4611 };
4612 
4613 #define VKI_MEDIA_IOC_DEVICE_INFO		_VKI_IOWR('|', 0x00, struct vki_media_device_info)
4614 #define VKI_MEDIA_IOC_ENUM_ENTITIES		_VKI_IOWR('|', 0x01, struct vki_media_entity_desc)
4615 #define VKI_MEDIA_IOC_ENUM_LINKS		_VKI_IOWR('|', 0x02, struct vki_media_links_enum)
4616 #define VKI_MEDIA_IOC_SETUP_LINK		_VKI_IOWR('|', 0x03, struct vki_media_link_desc)
4617 
4618 /* Comparison type */
4619 enum vki_kcmp_type {
4620    VKI_KCMP_FILE,
4621    VKI_KCMP_VM,
4622    VKI_KCMP_FILES,
4623    VKI_KCMP_FS,
4624    VKI_KCMP_SIGHAND,
4625    VKI_KCMP_IO,
4626    VKI_KCMP_SYSVSEM,
4627 
4628    VKI_KCMP_TYPES
4629 };
4630 
4631 //----------------------------------------------------------------------
4632 // From linux-3.19-rc5/include/uapi/linux/seccomp.h
4633 //----------------------------------------------------------------------
4634 
4635 #define VKI_SECCOMP_MODE_FILTER 2
4636 
4637 //----------------------------------------------------------------------
4638 // From linux-3.19.3/include/uapi/linux/binfmts.h
4639 //----------------------------------------------------------------------
4640 #define VKI_BINPRM_BUF_SIZE 128
4641 
4642 #endif // __VKI_LINUX_H
4643 
4644 /*--------------------------------------------------------------------*/
4645 /*--- end                                                          ---*/
4646 /*--------------------------------------------------------------------*/
4647