xref: /openbmc/qemu/linux-user/syscall_defs.h (revision 6a094d62)
1 /* common syscall defines for all architectures */
2 
3 /* Note: although the syscall numbers change between architectures,
4    most of them stay the same, so we handle it by putting ifdefs if
5    necessary */
6 
7 #ifndef SYSCALL_DEFS_H
8 #define SYSCALL_DEFS_H
9 
10 #include "syscall_nr.h"
11 
12 
13 /* socket operations for socketcall() */
14 #define TARGET_SYS_SOCKET       1         /* socket()              */
15 #define TARGET_SYS_BIND         2         /* bind()                */
16 #define TARGET_SYS_CONNECT      3         /* connect()             */
17 #define TARGET_SYS_LISTEN       4         /* listen()              */
18 #define TARGET_SYS_ACCEPT       5         /* accept()              */
19 #define TARGET_SYS_GETSOCKNAME  6         /* getsockname()         */
20 #define TARGET_SYS_GETPEERNAME  7         /* getpeername()         */
21 #define TARGET_SYS_SOCKETPAIR   8         /* socketpair()          */
22 #define TARGET_SYS_SEND         9         /* send()                */
23 #define TARGET_SYS_RECV         10        /* recv()                */
24 #define TARGET_SYS_SENDTO       11        /* sendto()              */
25 #define TARGET_SYS_RECVFROM     12        /* recvfrom()            */
26 #define TARGET_SYS_SHUTDOWN     13        /* shutdown()            */
27 #define TARGET_SYS_SETSOCKOPT   14        /* setsockopt()          */
28 #define TARGET_SYS_GETSOCKOPT   15        /* getsockopt()          */
29 #define TARGET_SYS_SENDMSG      16        /* sendmsg()             */
30 #define TARGET_SYS_RECVMSG      17        /* recvmsg()             */
31 #define TARGET_SYS_ACCEPT4      18        /* accept4()             */
32 #define TARGET_SYS_RECVMMSG     19        /* recvmmsg()            */
33 #define TARGET_SYS_SENDMMSG     20        /* sendmmsg()            */
34 
35 #define IPCOP_CALL(VERSION, OP) ((VERSION) << 16 | (OP))
36 #define IPCOP_semop		1
37 #define IPCOP_semget		2
38 #define IPCOP_semctl		3
39 #define IPCOP_semtimedop	4
40 #define IPCOP_msgsnd		11
41 #define IPCOP_msgrcv		12
42 #define IPCOP_msgget		13
43 #define IPCOP_msgctl		14
44 #define IPCOP_shmat		21
45 #define IPCOP_shmdt		22
46 #define IPCOP_shmget		23
47 #define IPCOP_shmctl		24
48 
49 #define TARGET_SEMOPM     500
50 
51 /*
52  * The following is for compatibility across the various Linux
53  * platforms.  The i386 ioctl numbering scheme doesn't really enforce
54  * a type field.  De facto, however, the top 8 bits of the lower 16
55  * bits are indeed used as a type field, so we might just as well make
56  * this explicit here.  Please be sure to use the decoding macros
57  * below from now on.
58  */
59 #define TARGET_IOC_NRBITS	8
60 #define TARGET_IOC_TYPEBITS	8
61 
62 #if (defined(TARGET_I386) && defined(TARGET_ABI32)) \
63     || (defined(TARGET_ARM) && defined(TARGET_ABI32)) \
64     || defined(TARGET_SPARC) \
65     || defined(TARGET_M68K) || defined(TARGET_SH4) || defined(TARGET_CRIS)
66     /* 16 bit uid wrappers emulation */
67 #define USE_UID16
68 #define target_id uint16_t
69 #else
70 #define target_id uint32_t
71 #endif
72 
73 #if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_SH4) \
74     || defined(TARGET_M68K) || defined(TARGET_CRIS) \
75     || defined(TARGET_S390X) || defined(TARGET_OPENRISC) \
76     || defined(TARGET_NIOS2) || defined(TARGET_RISCV) \
77     || defined(TARGET_XTENSA)
78 
79 #define TARGET_IOC_SIZEBITS	14
80 #define TARGET_IOC_DIRBITS	2
81 
82 #define TARGET_IOC_NONE	  0U
83 #define TARGET_IOC_WRITE  1U
84 #define TARGET_IOC_READ	  2U
85 
86 #elif defined(TARGET_PPC) || defined(TARGET_ALPHA) || \
87       defined(TARGET_SPARC) || defined(TARGET_MICROBLAZE) || \
88       defined(TARGET_MIPS)
89 
90 #define TARGET_IOC_SIZEBITS	13
91 #define TARGET_IOC_DIRBITS	3
92 
93 #define TARGET_IOC_NONE	  1U
94 #define TARGET_IOC_READ	  2U
95 #define TARGET_IOC_WRITE  4U
96 
97 #elif defined(TARGET_HPPA)
98 
99 #define TARGET_IOC_SIZEBITS  14
100 #define TARGET_IOC_DIRBITS    2
101 
102 #define TARGET_IOC_NONE   0U
103 #define TARGET_IOC_WRITE  2U
104 #define TARGET_IOC_READ   1U
105 
106 #elif defined(TARGET_HEXAGON)
107 
108 #define TARGET_IOC_SIZEBITS     14
109 
110 #define TARGET_IOC_NONE   0U
111 #define TARGET_IOC_WRITE  1U
112 #define TARGET_IOC_READ          2U
113 
114 #else
115 #error unsupported CPU
116 #endif
117 
118 #define TARGET_IOC_NRMASK	((1 << TARGET_IOC_NRBITS)-1)
119 #define TARGET_IOC_TYPEMASK	((1 << TARGET_IOC_TYPEBITS)-1)
120 #define TARGET_IOC_SIZEMASK	((1 << TARGET_IOC_SIZEBITS)-1)
121 #define TARGET_IOC_DIRMASK	((1 << TARGET_IOC_DIRBITS)-1)
122 
123 #define TARGET_IOC_NRSHIFT	0
124 #define TARGET_IOC_TYPESHIFT	(TARGET_IOC_NRSHIFT+TARGET_IOC_NRBITS)
125 #define TARGET_IOC_SIZESHIFT	(TARGET_IOC_TYPESHIFT+TARGET_IOC_TYPEBITS)
126 #define TARGET_IOC_DIRSHIFT	(TARGET_IOC_SIZESHIFT+TARGET_IOC_SIZEBITS)
127 
128 #define TARGET_IOC(dir,type,nr,size) \
129 	(((dir)  << TARGET_IOC_DIRSHIFT) | \
130 	 ((type) << TARGET_IOC_TYPESHIFT) | \
131 	 ((nr)   << TARGET_IOC_NRSHIFT) | \
132 	 ((size) << TARGET_IOC_SIZESHIFT))
133 
134 /* used to create numbers */
135 #define TARGET_IO(type,nr)		TARGET_IOC(TARGET_IOC_NONE,(type),(nr),0)
136 #define TARGET_IOR(type,nr,size)	TARGET_IOC(TARGET_IOC_READ,(type),(nr),sizeof(size))
137 #define TARGET_IOW(type,nr,size)	TARGET_IOC(TARGET_IOC_WRITE,(type),(nr),sizeof(size))
138 #define TARGET_IOWR(type,nr,size)	TARGET_IOC(TARGET_IOC_READ|TARGET_IOC_WRITE,(type),(nr),sizeof(size))
139 
140 /* the size is automatically computed for these defines */
141 #define TARGET_IORU(type,nr)	TARGET_IOC(TARGET_IOC_READ,(type),(nr),TARGET_IOC_SIZEMASK)
142 #define TARGET_IOWU(type,nr)	TARGET_IOC(TARGET_IOC_WRITE,(type),(nr),TARGET_IOC_SIZEMASK)
143 #define TARGET_IOWRU(type,nr)	TARGET_IOC(TARGET_IOC_READ|TARGET_IOC_WRITE,(type),(nr),TARGET_IOC_SIZEMASK)
144 
145 struct target_sockaddr {
146     abi_ushort sa_family;
147     uint8_t sa_data[14];
148 };
149 
150 struct target_sockaddr_ll {
151     abi_ushort sll_family;   /* Always AF_PACKET */
152     abi_ushort sll_protocol; /* Physical layer protocol */
153     abi_int    sll_ifindex;  /* Interface number */
154     abi_ushort sll_hatype;   /* ARP hardware type */
155     uint8_t    sll_pkttype;  /* Packet type */
156     uint8_t    sll_halen;    /* Length of address */
157     uint8_t    sll_addr[8];  /* Physical layer address */
158 };
159 
160 struct target_sockaddr_un {
161     abi_ushort su_family;
162     uint8_t sun_path[108];
163 };
164 
165 struct target_sockaddr_nl {
166     abi_ushort nl_family;   /* AF_NETLINK */
167     abi_ushort __pad;
168     abi_uint nl_pid;
169     abi_uint nl_groups;
170 };
171 
172 struct target_in_addr {
173     abi_uint s_addr; /* big endian */
174 };
175 
176 struct target_sockaddr_in {
177   abi_ushort sin_family;
178   abi_short sin_port; /* big endian */
179   struct target_in_addr sin_addr;
180   uint8_t __pad[sizeof(struct target_sockaddr) -
181                 sizeof(abi_ushort) - sizeof(abi_short) -
182                 sizeof(struct target_in_addr)];
183 };
184 
185 struct target_sockaddr_in6 {
186     abi_ushort sin6_family;
187     abi_ushort sin6_port; /* big endian */
188     abi_uint sin6_flowinfo; /* big endian */
189     struct in6_addr sin6_addr; /* IPv6 address, big endian */
190     abi_uint sin6_scope_id;
191 };
192 
193 struct target_sock_filter {
194     abi_ushort code;
195     uint8_t jt;
196     uint8_t jf;
197     abi_uint k;
198 };
199 
200 struct target_sock_fprog {
201     abi_ushort len;
202     abi_ulong filter;
203 };
204 
205 struct target_ip_mreq {
206     struct target_in_addr imr_multiaddr;
207     struct target_in_addr imr_address;
208 };
209 
210 struct target_ip_mreqn {
211     struct target_in_addr imr_multiaddr;
212     struct target_in_addr imr_address;
213     abi_long imr_ifindex;
214 };
215 
216 struct target_ip_mreq_source {
217     /* big endian */
218     uint32_t imr_multiaddr;
219     uint32_t imr_interface;
220     uint32_t imr_sourceaddr;
221 };
222 
223 struct target_linger {
224     abi_int l_onoff;        /* Linger active                */
225     abi_int l_linger;       /* How long to linger for       */
226 };
227 
228 #if defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
229 struct target_timeval {
230     abi_long tv_sec;
231     abi_int tv_usec;
232 };
233 #define target__kernel_sock_timeval target_timeval
234 #else
235 struct target_timeval {
236     abi_long tv_sec;
237     abi_long tv_usec;
238 };
239 
240 struct target__kernel_sock_timeval {
241     abi_llong tv_sec;
242     abi_llong tv_usec;
243 };
244 #endif
245 
246 struct target_timespec {
247     abi_long tv_sec;
248     abi_long tv_nsec;
249 };
250 
251 struct target__kernel_timespec {
252     abi_llong tv_sec;
253     abi_llong tv_nsec;
254 };
255 
256 struct target_timezone {
257     abi_int tz_minuteswest;
258     abi_int tz_dsttime;
259 };
260 
261 struct target_itimerval {
262     struct target_timeval it_interval;
263     struct target_timeval it_value;
264 };
265 
266 struct target_itimerspec {
267     struct target_timespec it_interval;
268     struct target_timespec it_value;
269 };
270 
271 struct target__kernel_itimerspec {
272     struct target__kernel_timespec it_interval;
273     struct target__kernel_timespec it_value;
274 };
275 
276 struct target_timex {
277     abi_uint modes;              /* Mode selector */
278     abi_long offset;             /* Time offset */
279     abi_long freq;               /* Frequency offset */
280     abi_long maxerror;           /* Maximum error (microseconds) */
281     abi_long esterror;           /* Estimated error (microseconds) */
282     abi_int status;              /* Clock command/status */
283     abi_long constant;           /* PLL (phase-locked loop) time constant */
284     abi_long precision;          /* Clock precision (microseconds, ro) */
285     abi_long tolerance;          /* Clock freq. tolerance (ppm, ro) */
286     struct target_timeval time;  /* Current time */
287     abi_long tick;               /* Microseconds between clock ticks */
288     abi_long ppsfreq;            /* PPS (pulse per second) frequency */
289     abi_long jitter;             /* PPS jitter (ro); nanoseconds */
290     abi_int shift;               /* PPS interval duration (seconds) */
291     abi_long stabil;             /* PPS stability */
292     abi_long jitcnt;             /* PPS jitter limit exceeded (ro) */
293     abi_long calcnt;             /* PPS calibration intervals */
294     abi_long errcnt;             /* PPS calibration errors */
295     abi_long stbcnt;             /* PPS stability limit exceeded */
296     abi_int tai;                 /* TAI offset */
297 
298     /* Further padding bytes to allow for future expansion */
299     abi_int:32; abi_int:32; abi_int:32; abi_int:32;
300     abi_int:32; abi_int:32; abi_int:32; abi_int:32;
301     abi_int:32; abi_int:32; abi_int:32;
302 };
303 
304 struct target__kernel_timex {
305     abi_uint modes;               /* Mode selector */
306     abi_int: 32;                  /* pad */
307     abi_llong offset;             /* Time offset */
308     abi_llong freq;               /* Frequency offset */
309     abi_llong maxerror;           /* Maximum error (microseconds) */
310     abi_llong esterror;           /* Estimated error (microseconds) */
311     abi_int status;               /* Clock command/status */
312     abi_int: 32;                  /* pad */
313     abi_llong constant;           /* PLL (phase-locked loop) time constant */
314     abi_llong precision;          /* Clock precision (microseconds, ro) */
315     abi_llong tolerance;          /* Clock freq. tolerance (ppm, ro) */
316     struct target__kernel_sock_timeval time;  /* Current time */
317     abi_llong tick;               /* Microseconds between clock ticks */
318     abi_llong ppsfreq;            /* PPS (pulse per second) frequency */
319     abi_llong jitter;             /* PPS jitter (ro); nanoseconds */
320     abi_int shift;                /* PPS interval duration (seconds) */
321     abi_int: 32;                  /* pad */
322     abi_llong stabil;             /* PPS stability */
323     abi_llong jitcnt;             /* PPS jitter limit exceeded (ro) */
324     abi_llong calcnt;             /* PPS calibration intervals */
325     abi_llong errcnt;             /* PPS calibration errors */
326     abi_llong stbcnt;             /* PPS stability limit exceeded */
327     abi_int tai;                  /* TAI offset */
328 
329     /* Further padding bytes to allow for future expansion */
330     abi_int:32; abi_int:32; abi_int:32; abi_int:32;
331     abi_int:32; abi_int:32; abi_int:32; abi_int:32;
332     abi_int:32; abi_int:32; abi_int:32;
333 };
334 
335 typedef abi_long target_clock_t;
336 
337 #define TARGET_HZ 100
338 
339 struct target_tms {
340     target_clock_t tms_utime;
341     target_clock_t tms_stime;
342     target_clock_t tms_cutime;
343     target_clock_t tms_cstime;
344 };
345 
346 struct target_utimbuf {
347     abi_long actime;
348     abi_long modtime;
349 };
350 
351 struct target_sel_arg_struct {
352     abi_long n;
353     abi_long inp, outp, exp;
354     abi_long tvp;
355 };
356 
357 struct target_iovec {
358     abi_long iov_base;   /* Starting address */
359     abi_long iov_len;   /* Number of bytes */
360 };
361 
362 struct target_msghdr {
363     abi_long	 msg_name;	 /* Socket name			*/
364     int		 msg_namelen;	 /* Length of name		*/
365     abi_long	 msg_iov;	 /* Data blocks			*/
366     abi_long	 msg_iovlen;	 /* Number of blocks		*/
367     abi_long     msg_control;	 /* Per protocol magic (eg BSD file descriptor passing) */
368     abi_long	 msg_controllen; /* Length of cmsg list */
369     unsigned int msg_flags;
370 };
371 
372 struct target_cmsghdr {
373     abi_long     cmsg_len;
374     int          cmsg_level;
375     int          cmsg_type;
376 };
377 
378 #define TARGET_CMSG_DATA(cmsg) ((unsigned char *) ((struct target_cmsghdr *) (cmsg) + 1))
379 #define TARGET_CMSG_NXTHDR(mhdr, cmsg, cmsg_start) \
380                                __target_cmsg_nxthdr(mhdr, cmsg, cmsg_start)
381 #define TARGET_CMSG_ALIGN(len) (((len) + sizeof (abi_long) - 1) \
382                                & (size_t) ~(sizeof (abi_long) - 1))
383 #define TARGET_CMSG_SPACE(len) (sizeof(struct target_cmsghdr) + \
384                                 TARGET_CMSG_ALIGN(len))
385 #define TARGET_CMSG_LEN(len) (sizeof(struct target_cmsghdr) + (len))
386 
387 static __inline__ struct target_cmsghdr *
388 __target_cmsg_nxthdr(struct target_msghdr *__mhdr,
389                      struct target_cmsghdr *__cmsg,
390                      struct target_cmsghdr *__cmsg_start)
391 {
392   struct target_cmsghdr *__ptr;
393 
394   __ptr = (struct target_cmsghdr *)((unsigned char *) __cmsg
395                                     + TARGET_CMSG_ALIGN (tswapal(__cmsg->cmsg_len)));
396   if ((unsigned long)((char *)(__ptr+1) - (char *)__cmsg_start)
397       > tswapal(__mhdr->msg_controllen)) {
398     /* No more entries.  */
399     return (struct target_cmsghdr *)0;
400   }
401   return __ptr;
402 }
403 
404 struct target_mmsghdr {
405     struct target_msghdr msg_hdr;              /* Message header */
406     unsigned int         msg_len;              /* Number of bytes transmitted */
407 };
408 
409 struct  target_rusage {
410         struct target_timeval ru_utime;        /* user time used */
411         struct target_timeval ru_stime;        /* system time used */
412         abi_long    ru_maxrss;                 /* maximum resident set size */
413         abi_long    ru_ixrss;                  /* integral shared memory size */
414         abi_long    ru_idrss;                  /* integral unshared data size */
415         abi_long    ru_isrss;                  /* integral unshared stack size */
416         abi_long    ru_minflt;                 /* page reclaims */
417         abi_long    ru_majflt;                 /* page faults */
418         abi_long    ru_nswap;                  /* swaps */
419         abi_long    ru_inblock;                /* block input operations */
420         abi_long    ru_oublock;                /* block output operations */
421         abi_long    ru_msgsnd;                 /* messages sent */
422         abi_long    ru_msgrcv;                 /* messages received */
423         abi_long    ru_nsignals;               /* signals received */
424         abi_long    ru_nvcsw;                  /* voluntary context switches */
425         abi_long    ru_nivcsw;                 /* involuntary " */
426 };
427 
428 typedef struct {
429         int     val[2];
430 } kernel_fsid_t;
431 
432 struct target_dirent {
433         abi_long        d_ino;
434         abi_long        d_off;
435         unsigned short  d_reclen;
436         char            d_name[];
437 };
438 
439 struct target_dirent64 {
440 	abi_ullong      d_ino;
441 	abi_llong       d_off;
442 	abi_ushort      d_reclen;
443 	unsigned char	d_type;
444 	char		d_name[];
445 };
446 
447 
448 /* mostly generic signal stuff */
449 #define TARGET_SIG_DFL	((abi_long)0)	/* default signal handling */
450 #define TARGET_SIG_IGN	((abi_long)1)	/* ignore signal */
451 #define TARGET_SIG_ERR	((abi_long)-1)	/* error return from signal */
452 
453 #ifdef TARGET_MIPS
454 #define TARGET_NSIG	   128
455 #else
456 #define TARGET_NSIG	   64
457 #endif
458 #define TARGET_NSIG_BPW	   TARGET_ABI_BITS
459 #define TARGET_NSIG_WORDS  (TARGET_NSIG / TARGET_NSIG_BPW)
460 
461 typedef struct {
462     abi_ulong sig[TARGET_NSIG_WORDS];
463 } target_sigset_t;
464 
465 #ifdef BSWAP_NEEDED
466 static inline void tswap_sigset(target_sigset_t *d, const target_sigset_t *s)
467 {
468     int i;
469     for(i = 0;i < TARGET_NSIG_WORDS; i++)
470         d->sig[i] = tswapal(s->sig[i]);
471 }
472 #else
473 static inline void tswap_sigset(target_sigset_t *d, const target_sigset_t *s)
474 {
475     *d = *s;
476 }
477 #endif
478 
479 static inline void target_siginitset(target_sigset_t *d, abi_ulong set)
480 {
481     int i;
482     d->sig[0] = set;
483     for(i = 1;i < TARGET_NSIG_WORDS; i++)
484         d->sig[i] = 0;
485 }
486 
487 void host_to_target_sigset(target_sigset_t *d, const sigset_t *s);
488 void target_to_host_sigset(sigset_t *d, const target_sigset_t *s);
489 void host_to_target_old_sigset(abi_ulong *old_sigset,
490                                const sigset_t *sigset);
491 void target_to_host_old_sigset(sigset_t *sigset,
492                                const abi_ulong *old_sigset);
493 struct target_sigaction;
494 int do_sigaction(int sig, const struct target_sigaction *act,
495                  struct target_sigaction *oact, abi_ulong ka_restorer);
496 
497 #include "target_signal.h"
498 
499 #ifdef TARGET_SA_RESTORER
500 #define TARGET_ARCH_HAS_SA_RESTORER 1
501 #endif
502 
503 #if defined(TARGET_ALPHA)
504 typedef int32_t target_old_sa_flags;
505 #else
506 typedef abi_ulong target_old_sa_flags;
507 #endif
508 
509 #if defined(TARGET_MIPS)
510 struct target_sigaction {
511 	uint32_t	sa_flags;
512 #if defined(TARGET_ABI_MIPSN32)
513 	uint32_t	_sa_handler;
514 #else
515 	abi_ulong	_sa_handler;
516 #endif
517 	target_sigset_t	sa_mask;
518 #ifdef TARGET_ARCH_HAS_SA_RESTORER
519         /* ??? This is always present, but ignored unless O32.  */
520         abi_ulong sa_restorer;
521 #endif
522 };
523 #else
524 struct target_old_sigaction {
525         abi_ulong _sa_handler;
526         abi_ulong sa_mask;
527         target_old_sa_flags sa_flags;
528 #ifdef TARGET_ARCH_HAS_SA_RESTORER
529         abi_ulong sa_restorer;
530 #endif
531 };
532 
533 struct target_sigaction {
534         abi_ulong _sa_handler;
535         abi_ulong sa_flags;
536 #ifdef TARGET_ARCH_HAS_SA_RESTORER
537         abi_ulong sa_restorer;
538 #endif
539         target_sigset_t sa_mask;
540 #ifdef TARGET_ARCH_HAS_KA_RESTORER
541         abi_ulong ka_restorer;
542 #endif
543 };
544 #endif
545 
546 typedef union target_sigval {
547 	int sival_int;
548         abi_ulong sival_ptr;
549 } target_sigval_t;
550 #if 0
551 #if defined (TARGET_SPARC)
552 typedef struct {
553 	struct {
554 		abi_ulong psr;
555 		abi_ulong pc;
556 		abi_ulong npc;
557 		abi_ulong y;
558 		abi_ulong u_regs[16]; /* globals and ins */
559 	}		si_regs;
560 	int		si_mask;
561 } __siginfo_t;
562 
563 typedef struct {
564 	unsigned   long si_float_regs [32];
565 	unsigned   long si_fsr;
566 	unsigned   long si_fpqdepth;
567 	struct {
568 		unsigned long *insn_addr;
569 		unsigned long insn;
570 	} si_fpqueue [16];
571 } __siginfo_fpu_t;
572 #endif
573 #endif
574 
575 #define TARGET_SI_MAX_SIZE	128
576 
577 #if TARGET_ABI_BITS == 32
578 #define TARGET_SI_PREAMBLE_SIZE (3 * sizeof(int))
579 #else
580 #define TARGET_SI_PREAMBLE_SIZE (4 * sizeof(int))
581 #endif
582 
583 #define TARGET_SI_PAD_SIZE ((TARGET_SI_MAX_SIZE - TARGET_SI_PREAMBLE_SIZE) / sizeof(int))
584 
585 /* Within QEMU the top 16 bits of si_code indicate which of the parts of
586  * the union in target_siginfo is valid. This only applies between
587  * host_to_target_siginfo_noswap() and tswap_siginfo(); it does not
588  * appear either within host siginfo_t or in target_siginfo structures
589  * which we get from the guest userspace program. (The Linux kernel
590  * does a similar thing with using the top bits for its own internal
591  * purposes but not letting them be visible to userspace.)
592  */
593 #define QEMU_SI_KILL 0
594 #define QEMU_SI_TIMER 1
595 #define QEMU_SI_POLL 2
596 #define QEMU_SI_FAULT 3
597 #define QEMU_SI_CHLD 4
598 #define QEMU_SI_RT 5
599 
600 typedef struct target_siginfo {
601 #ifdef TARGET_MIPS
602 	int si_signo;
603 	int si_code;
604 	int si_errno;
605 #else
606 	int si_signo;
607 	int si_errno;
608 	int si_code;
609 #endif
610 
611 	union {
612 		int _pad[TARGET_SI_PAD_SIZE];
613 
614 		/* kill() */
615 		struct {
616 			pid_t _pid;		/* sender's pid */
617 			uid_t _uid;		/* sender's uid */
618 		} _kill;
619 
620 		/* POSIX.1b timers */
621 		struct {
622 			unsigned int _timer1;
623 			unsigned int _timer2;
624 		} _timer;
625 
626 		/* POSIX.1b signals */
627 		struct {
628 			pid_t _pid;		/* sender's pid */
629 			uid_t _uid;		/* sender's uid */
630 			target_sigval_t _sigval;
631 		} _rt;
632 
633 		/* SIGCHLD */
634 		struct {
635 			pid_t _pid;		/* which child */
636 			uid_t _uid;		/* sender's uid */
637 			int _status;		/* exit code */
638 			target_clock_t _utime;
639                         target_clock_t _stime;
640 		} _sigchld;
641 
642 		/* SIGILL, SIGFPE, SIGSEGV, SIGBUS */
643 		struct {
644 			abi_ulong _addr; /* faulting insn/memory ref. */
645 		} _sigfault;
646 
647 		/* SIGPOLL */
648 		struct {
649 			int _band;	/* POLL_IN, POLL_OUT, POLL_MSG */
650 			int _fd;
651 		} _sigpoll;
652 	} _sifields;
653 } target_siginfo_t;
654 
655 /*
656  * si_code values
657  * Digital reserves positive values for kernel-generated signals.
658  */
659 #define TARGET_SI_USER		0	/* sent by kill, sigsend, raise */
660 #define TARGET_SI_KERNEL	0x80	/* sent by the kernel from somewhere */
661 #define TARGET_SI_QUEUE	-1		/* sent by sigqueue */
662 #define TARGET_SI_TIMER -2              /* sent by timer expiration */
663 #define TARGET_SI_MESGQ	-3		/* sent by real time mesq state change */
664 #define TARGET_SI_ASYNCIO	-4	/* sent by AIO completion */
665 #define TARGET_SI_SIGIO	-5		/* sent by queued SIGIO */
666 
667 /*
668  * SIGILL si_codes
669  */
670 #define TARGET_ILL_ILLOPC	(1)	/* illegal opcode */
671 #define TARGET_ILL_ILLOPN	(2)	/* illegal operand */
672 #define TARGET_ILL_ILLADR	(3)	/* illegal addressing mode */
673 #define TARGET_ILL_ILLTRP	(4)	/* illegal trap */
674 #define TARGET_ILL_PRVOPC	(5)	/* privileged opcode */
675 #define TARGET_ILL_PRVREG	(6)	/* privileged register */
676 #define TARGET_ILL_COPROC	(7)	/* coprocessor error */
677 #define TARGET_ILL_BADSTK	(8)	/* internal stack error */
678 
679 /*
680  * SIGFPE si_codes
681  */
682 #define TARGET_FPE_INTDIV      (1)  /* integer divide by zero */
683 #define TARGET_FPE_INTOVF      (2)  /* integer overflow */
684 #define TARGET_FPE_FLTDIV      (3)  /* floating point divide by zero */
685 #define TARGET_FPE_FLTOVF      (4)  /* floating point overflow */
686 #define TARGET_FPE_FLTUND      (5)  /* floating point underflow */
687 #define TARGET_FPE_FLTRES      (6)  /* floating point inexact result */
688 #define TARGET_FPE_FLTINV      (7)  /* floating point invalid operation */
689 #define TARGET_FPE_FLTSUB      (8)  /* subscript out of range */
690 #define TARGET_FPE_FLTUNK      (14) /* undiagnosed fp exception */
691 #define TARGET_FPE_CONDTRAP    (15) /* trap on condition */
692 
693 /*
694  * SIGSEGV si_codes
695  */
696 #define TARGET_SEGV_MAPERR     (1)  /* address not mapped to object */
697 #define TARGET_SEGV_ACCERR     (2)  /* invalid permissions for mapped object */
698 #define TARGET_SEGV_BNDERR     (3)  /* failed address bound checks */
699 
700 /*
701  * SIGBUS si_codes
702  */
703 #define TARGET_BUS_ADRALN       (1)	/* invalid address alignment */
704 #define TARGET_BUS_ADRERR       (2)	/* non-existent physical address */
705 #define TARGET_BUS_OBJERR       (3)	/* object specific hardware error */
706 /* hardware memory error consumed on a machine check: action required */
707 #define TARGET_BUS_MCEERR_AR    (4)
708 /* hardware memory error detected in process but not consumed: action optional*/
709 #define TARGET_BUS_MCEERR_AO    (5)
710 
711 /*
712  * SIGTRAP si_codes
713  */
714 #define TARGET_TRAP_BRKPT	(1)	/* process breakpoint */
715 #define TARGET_TRAP_TRACE	(2)	/* process trace trap */
716 #define TARGET_TRAP_BRANCH      (3)     /* process taken branch trap */
717 #define TARGET_TRAP_HWBKPT      (4)     /* hardware breakpoint/watchpoint */
718 #define TARGET_TRAP_UNK         (5)     /* undiagnosed trap */
719 
720 struct target_rlimit {
721         abi_ulong   rlim_cur;
722         abi_ulong   rlim_max;
723 };
724 
725 #if defined(TARGET_ALPHA)
726 #define TARGET_RLIM_INFINITY	0x7fffffffffffffffull
727 #elif defined(TARGET_MIPS) || (defined(TARGET_SPARC) && TARGET_ABI_BITS == 32)
728 #define TARGET_RLIM_INFINITY	0x7fffffffUL
729 #else
730 #define TARGET_RLIM_INFINITY	((abi_ulong)-1)
731 #endif
732 
733 #if defined(TARGET_MIPS)
734 #define TARGET_RLIMIT_CPU		0
735 #define TARGET_RLIMIT_FSIZE		1
736 #define TARGET_RLIMIT_DATA		2
737 #define TARGET_RLIMIT_STACK		3
738 #define TARGET_RLIMIT_CORE		4
739 #define TARGET_RLIMIT_RSS		7
740 #define TARGET_RLIMIT_NPROC		8
741 #define TARGET_RLIMIT_NOFILE		5
742 #define TARGET_RLIMIT_MEMLOCK		9
743 #define TARGET_RLIMIT_AS		6
744 #define TARGET_RLIMIT_LOCKS		10
745 #define TARGET_RLIMIT_SIGPENDING	11
746 #define TARGET_RLIMIT_MSGQUEUE		12
747 #define TARGET_RLIMIT_NICE		13
748 #define TARGET_RLIMIT_RTPRIO		14
749 #else
750 #define TARGET_RLIMIT_CPU		0
751 #define TARGET_RLIMIT_FSIZE		1
752 #define TARGET_RLIMIT_DATA		2
753 #define TARGET_RLIMIT_STACK		3
754 #define TARGET_RLIMIT_CORE		4
755 #define TARGET_RLIMIT_RSS		5
756 #if defined(TARGET_SPARC)
757 #define TARGET_RLIMIT_NOFILE		6
758 #define TARGET_RLIMIT_NPROC		7
759 #else
760 #define TARGET_RLIMIT_NPROC		6
761 #define TARGET_RLIMIT_NOFILE		7
762 #endif
763 #define TARGET_RLIMIT_MEMLOCK		8
764 #define TARGET_RLIMIT_AS		9
765 #define TARGET_RLIMIT_LOCKS		10
766 #define TARGET_RLIMIT_SIGPENDING	11
767 #define TARGET_RLIMIT_MSGQUEUE		12
768 #define TARGET_RLIMIT_NICE		13
769 #define TARGET_RLIMIT_RTPRIO		14
770 #endif
771 
772 struct target_pollfd {
773     int fd;           /* file descriptor */
774     short events;     /* requested events */
775     short revents;    /* returned events */
776 };
777 
778 /* virtual terminal ioctls */
779 #define TARGET_KIOCSOUND       0x4B2F	/* start sound generation (0 for off) */
780 #define TARGET_KDMKTONE	       0x4B30	/* generate tone */
781 #define TARGET_KDGKBTYPE       0x4b33
782 #define TARGET_KDSETMODE       0x4b3a
783 #define TARGET_KDGKBMODE       0x4b44
784 #define TARGET_KDSKBMODE       0x4b45
785 #define TARGET_KDGKBENT	       0x4B46	/* gets one entry in translation table */
786 #define TARGET_KDGKBSENT       0x4B48	/* gets one function key string entry */
787 #define TARGET_KDGKBLED        0x4B64	/* get led flags (not lights) */
788 #define TARGET_KDSKBLED        0x4B65	/* set led flags (not lights) */
789 #define TARGET_KDGETLED        0x4B31	/* return current led state */
790 #define TARGET_KDSETLED        0x4B32	/* set led state [lights, not flags] */
791 #define TARGET_KDSIGACCEPT     0x4B4E
792 
793 struct target_rtc_pll_info {
794     int pll_ctrl;
795     int pll_value;
796     int pll_max;
797     int pll_min;
798     int pll_posmult;
799     int pll_negmult;
800     abi_long pll_clock;
801 };
802 
803 /* real time clock ioctls */
804 #define TARGET_RTC_AIE_ON           TARGET_IO('p', 0x01)
805 #define TARGET_RTC_AIE_OFF          TARGET_IO('p', 0x02)
806 #define TARGET_RTC_UIE_ON           TARGET_IO('p', 0x03)
807 #define TARGET_RTC_UIE_OFF          TARGET_IO('p', 0x04)
808 #define TARGET_RTC_PIE_ON           TARGET_IO('p', 0x05)
809 #define TARGET_RTC_PIE_OFF          TARGET_IO('p', 0x06)
810 #define TARGET_RTC_WIE_ON           TARGET_IO('p', 0x0f)
811 #define TARGET_RTC_WIE_OFF          TARGET_IO('p', 0x10)
812 #define TARGET_RTC_ALM_READ         TARGET_IOR('p', 0x08, struct rtc_time)
813 #define TARGET_RTC_ALM_SET          TARGET_IOW('p', 0x07, struct rtc_time)
814 #define TARGET_RTC_RD_TIME          TARGET_IOR('p', 0x09, struct rtc_time)
815 #define TARGET_RTC_SET_TIME         TARGET_IOW('p', 0x0a, struct rtc_time)
816 #define TARGET_RTC_IRQP_READ        TARGET_IOR('p', 0x0b, abi_ulong)
817 #define TARGET_RTC_IRQP_SET         TARGET_IOW('p', 0x0c, abi_ulong)
818 #define TARGET_RTC_EPOCH_READ       TARGET_IOR('p', 0x0d, abi_ulong)
819 #define TARGET_RTC_EPOCH_SET        TARGET_IOW('p', 0x0e, abi_ulong)
820 #define TARGET_RTC_WKALM_RD         TARGET_IOR('p', 0x10, struct rtc_wkalrm)
821 #define TARGET_RTC_WKALM_SET        TARGET_IOW('p', 0x0f, struct rtc_wkalrm)
822 #define TARGET_RTC_PLL_GET          TARGET_IOR('p', 0x11,                      \
823                                                struct target_rtc_pll_info)
824 #define TARGET_RTC_PLL_SET          TARGET_IOW('p', 0x12,                      \
825                                                struct target_rtc_pll_info)
826 #define TARGET_RTC_VL_READ          TARGET_IOR('p', 0x13, int)
827 #define TARGET_RTC_VL_CLR           TARGET_IO('p', 0x14)
828 
829 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SH4) ||    \
830        defined(TARGET_XTENSA)
831 #define TARGET_FIOGETOWN       TARGET_IOR('f', 123, int)
832 #define TARGET_FIOSETOWN       TARGET_IOW('f', 124, int)
833 #define TARGET_SIOCATMARK      TARGET_IOR('s', 7, int)
834 #define TARGET_SIOCSPGRP       TARGET_IOW('s', 8, pid_t)
835 #define TARGET_SIOCGPGRP       TARGET_IOR('s', 9, pid_t)
836 #else
837 #define TARGET_FIOGETOWN       0x8903
838 #define TARGET_FIOSETOWN       0x8901
839 #define TARGET_SIOCATMARK      0x8905
840 #define TARGET_SIOCSPGRP       0x8902
841 #define TARGET_SIOCGPGRP       0x8904
842 #endif
843 
844 #if defined(TARGET_SH4)
845 #define TARGET_SIOCGSTAMP_OLD   TARGET_IOR('s', 100, struct target_timeval)
846 #define TARGET_SIOCGSTAMPNS_OLD TARGET_IOR('s', 101, struct target_timespec)
847 #else
848 #define TARGET_SIOCGSTAMP_OLD   0x8906
849 #define TARGET_SIOCGSTAMPNS_OLD 0x8907
850 #endif
851 
852 #define TARGET_SIOCGSTAMP_NEW   TARGET_IOR(0x89, 0x06, abi_llong[2])
853 #define TARGET_SIOCGSTAMPNS_NEW TARGET_IOR(0x89, 0x07, abi_llong[2])
854 
855 /* Networking ioctls */
856 #define TARGET_SIOCADDRT       0x890B          /* add routing table entry */
857 #define TARGET_SIOCDELRT       0x890C          /* delete routing table entry */
858 #define TARGET_SIOCGIFNAME     0x8910          /* get iface name               */
859 #define TARGET_SIOCSIFLINK     0x8911          /* set iface channel            */
860 #define TARGET_SIOCGIFCONF     0x8912          /* get iface list               */
861 #define TARGET_SIOCGIFFLAGS    0x8913          /* get flags                    */
862 #define TARGET_SIOCSIFFLAGS    0x8914          /* set flags                    */
863 #define TARGET_SIOCGIFADDR     0x8915          /* get PA address               */
864 #define TARGET_SIOCSIFADDR     0x8916          /* set PA address               */
865 #define TARGET_SIOCGIFDSTADDR  0x8917          /* get remote PA address        */
866 #define TARGET_SIOCSIFDSTADDR  0x8918          /* set remote PA address        */
867 #define TARGET_SIOCGIFBRDADDR  0x8919          /* get broadcast PA address     */
868 #define TARGET_SIOCSIFBRDADDR  0x891a          /* set broadcast PA address     */
869 #define TARGET_SIOCGIFNETMASK  0x891b          /* get network PA mask          */
870 #define TARGET_SIOCSIFNETMASK  0x891c          /* set network PA mask          */
871 #define TARGET_SIOCGIFMETRIC   0x891d          /* get metric                   */
872 #define TARGET_SIOCSIFMETRIC   0x891e          /* set metric                   */
873 #define TARGET_SIOCGIFMEM      0x891f          /* get memory address (BSD)     */
874 #define TARGET_SIOCSIFMEM      0x8920          /* set memory address (BSD)     */
875 #define TARGET_SIOCGIFMTU      0x8921          /* get MTU size                 */
876 #define TARGET_SIOCSIFMTU      0x8922          /* set MTU size                 */
877 #define TARGET_SIOCSIFHWADDR   0x8924          /* set hardware address (NI)    */
878 #define TARGET_SIOCGIFENCAP    0x8925          /* get/set slip encapsulation   */
879 #define TARGET_SIOCSIFENCAP    0x8926
880 #define TARGET_SIOCGIFHWADDR   0x8927          /* Get hardware address         */
881 #define TARGET_SIOCGIFSLAVE    0x8929          /* Driver slaving support       */
882 #define TARGET_SIOCSIFSLAVE    0x8930
883 #define TARGET_SIOCADDMULTI    0x8931          /* Multicast address lists      */
884 #define TARGET_SIOCDELMULTI    0x8932
885 #define TARGET_SIOCGIFINDEX    0x8933
886 #define TARGET_SIOCSIFPFLAGS   0x8934          /* set extended flags          */
887 #define TARGET_SIOCGIFPFLAGS   0x8935          /* get extended flags          */
888 
889 /* Bridging control calls */
890 #define TARGET_SIOCGIFBR       0x8940          /* Bridging support             */
891 #define TARGET_SIOCSIFBR       0x8941          /* Set bridging options         */
892 
893 #define TARGET_SIOCGIFTXQLEN   0x8942          /* Get the tx queue length      */
894 #define TARGET_SIOCSIFTXQLEN   0x8943          /* Set the tx queue length      */
895 
896 /* ARP cache control calls. */
897 #define TARGET_OLD_SIOCDARP    0x8950          /* old delete ARP table entry   */
898 #define TARGET_OLD_SIOCGARP    0x8951          /* old get ARP table entry      */
899 #define TARGET_OLD_SIOCSARP    0x8952          /* old set ARP table entry      */
900 #define TARGET_SIOCDARP        0x8953          /* delete ARP table entry       */
901 #define TARGET_SIOCGARP        0x8954          /* get ARP table entry          */
902 #define TARGET_SIOCSARP        0x8955          /* set ARP table entry          */
903 
904 /* RARP cache control calls. */
905 #define TARGET_SIOCDRARP       0x8960          /* delete RARP table entry      */
906 #define TARGET_SIOCGRARP       0x8961          /* get RARP table entry         */
907 #define TARGET_SIOCSRARP       0x8962          /* set RARP table entry         */
908 
909 /* Driver configuration calls */
910 #define TARGET_SIOCGIFMAP      0x8970          /* Get device parameters        */
911 #define TARGET_SIOCSIFMAP      0x8971          /* Set device parameters        */
912 
913 /* DLCI configuration calls */
914 #define TARGET_SIOCADDDLCI     0x8980          /* Create new DLCI device       */
915 #define TARGET_SIOCDELDLCI     0x8981          /* Delete DLCI device           */
916 
917 /* From <linux/wireless.h> */
918 
919 #define TARGET_SIOCGIWNAME     0x8B01          /* get name == wireless protocol */
920 
921 /* From <linux/if_tun.h> */
922 
923 #define TARGET_TUNSETDEBUG        TARGET_IOW('T', 201, int)
924 #define TARGET_TUNSETIFF          TARGET_IOW('T', 202, int)
925 #define TARGET_TUNSETPERSIST      TARGET_IOW('T', 203, int)
926 #define TARGET_TUNSETOWNER        TARGET_IOW('T', 204, int)
927 #define TARGET_TUNSETLINK         TARGET_IOW('T', 205, int)
928 #define TARGET_TUNSETGROUP        TARGET_IOW('T', 206, int)
929 #define TARGET_TUNGETFEATURES     TARGET_IOR('T', 207, unsigned int)
930 #define TARGET_TUNSETOFFLOAD      TARGET_IOW('T', 208, unsigned int)
931 #define TARGET_TUNSETTXFILTER     TARGET_IOW('T', 209, unsigned int)
932 #define TARGET_TUNGETIFF          TARGET_IOR('T', 210, unsigned int)
933 #define TARGET_TUNGETSNDBUF       TARGET_IOR('T', 211, int)
934 #define TARGET_TUNSETSNDBUF       TARGET_IOW('T', 212, int)
935 /*
936  * TUNATTACHFILTER and TUNDETACHFILTER are not supported. Linux kernel keeps a
937  * user pointer in TUNATTACHFILTER, which we are not able to correctly handle.
938  */
939 #define TARGET_TUNGETVNETHDRSZ    TARGET_IOR('T', 215, int)
940 #define TARGET_TUNSETVNETHDRSZ    TARGET_IOW('T', 216, int)
941 #define TARGET_TUNSETQUEUE        TARGET_IOW('T', 217, int)
942 #define TARGET_TUNSETIFINDEX      TARGET_IOW('T', 218, unsigned int)
943 /* TUNGETFILTER is not supported: see TUNATTACHFILTER. */
944 #define TARGET_TUNSETVNETLE       TARGET_IOW('T', 220, int)
945 #define TARGET_TUNGETVNETLE       TARGET_IOR('T', 221, int)
946 #define TARGET_TUNSETVNETBE       TARGET_IOW('T', 222, int)
947 #define TARGET_TUNGETVNETBE       TARGET_IOR('T', 223, int)
948 #define TARGET_TUNSETSTEERINGEBPF TARGET_IOR('T', 224, int)
949 #define TARGET_TUNSETFILTEREBPF   TARGET_IOR('T', 225, int)
950 #define TARGET_TUNSETCARRIER      TARGET_IOW('T', 226, int)
951 #define TARGET_TUNGETDEVNETNS     TARGET_IO('T', 227)
952 
953 /* From <linux/random.h> */
954 
955 #define TARGET_RNDGETENTCNT    TARGET_IOR('R', 0x00, int)
956 #define TARGET_RNDADDTOENTCNT  TARGET_IOW('R', 0x01, int)
957 #define TARGET_RNDZAPENTCNT    TARGET_IO('R', 0x04)
958 #define TARGET_RNDCLEARPOOL    TARGET_IO('R', 0x06)
959 #define TARGET_RNDRESEEDCRNG   TARGET_IO('R', 0x07)
960 
961 /* From <linux/fs.h> */
962 
963 #define TARGET_BLKROSET   TARGET_IO(0x12,93) /* set device read-only (0 = read-write) */
964 #define TARGET_BLKROGET   TARGET_IO(0x12,94) /* get read-only status (0 = read_write) */
965 #define TARGET_BLKRRPART  TARGET_IO(0x12,95) /* re-read partition table */
966 #define TARGET_BLKGETSIZE TARGET_IO(0x12,96) /* return device size /512 (long *arg) */
967 #define TARGET_BLKFLSBUF  TARGET_IO(0x12,97) /* flush buffer cache */
968 #define TARGET_BLKRASET   TARGET_IO(0x12,98) /* Set read ahead for block device */
969 #define TARGET_BLKRAGET   TARGET_IO(0x12,99) /* get current read ahead setting */
970 #define TARGET_BLKFRASET  TARGET_IO(0x12,100)/* set filesystem (mm/filemap.c) read-ahead */
971 #define TARGET_BLKFRAGET  TARGET_IO(0x12,101)/* get filesystem (mm/filemap.c) read-ahead */
972 #define TARGET_BLKSECTSET TARGET_IO(0x12,102)/* set max sectors per request (ll_rw_blk.c) */
973 #define TARGET_BLKSECTGET TARGET_IO(0x12,103)/* get max sectors per request (ll_rw_blk.c) */
974 #define TARGET_BLKSSZGET  TARGET_IO(0x12,104)/* get block device sector size */
975 #define TARGET_BLKPG      TARGET_IO(0x12,105)/* Partition table and disk geometry handling */
976 /* A jump here: 108-111 have been used for various private purposes. */
977 #define TARGET_BLKBSZGET  TARGET_IOR(0x12, 112, abi_ulong)
978 #define TARGET_BLKBSZSET  TARGET_IOW(0x12, 113, abi_ulong)
979 #define TARGET_BLKGETSIZE64 TARGET_IOR(0x12,114,abi_ulong)
980                                              /* return device size in bytes
981                                                 (u64 *arg) */
982 
983 #define TARGET_BLKDISCARD TARGET_IO(0x12, 119)
984 #define TARGET_BLKIOMIN TARGET_IO(0x12, 120)
985 #define TARGET_BLKIOOPT TARGET_IO(0x12, 121)
986 #define TARGET_BLKALIGNOFF TARGET_IO(0x12, 122)
987 #define TARGET_BLKPBSZGET TARGET_IO(0x12, 123)
988 #define TARGET_BLKDISCARDZEROES TARGET_IO(0x12, 124)
989 #define TARGET_BLKSECDISCARD TARGET_IO(0x12, 125)
990 #define TARGET_BLKROTATIONAL TARGET_IO(0x12, 126)
991 #define TARGET_BLKZEROOUT TARGET_IO(0x12, 127)
992 
993 /* From <linux/fd.h> */
994 
995 #define TARGET_FDMSGON        TARGET_IO(2, 0x45)
996 #define TARGET_FDMSGOFF       TARGET_IO(2, 0x46)
997 #define TARGET_FDFMTBEG       TARGET_IO(2, 0x47)
998 #define TARGET_FDFMTTRK      TARGET_IOW(2, 0x48, struct format_descr)
999 #define TARGET_FDFMTEND       TARGET_IO(2, 0x49)
1000 #define TARGET_FDSETEMSGTRESH TARGET_IO(2, 0x4a)
1001 #define TARGET_FDFLUSH        TARGET_IO(2, 0x4b)
1002 #define TARGET_FDSETMAXERRS  TARGET_IOW(2, 0x4c, struct floppy_max_errors)
1003 #define TARGET_FDGETMAXERRS  TARGET_IOR(2, 0x0e, struct floppy_max_errors)
1004 #define TARGET_FDRESET        TARGET_IO(2, 0x54)
1005 #define TARGET_FDRAWCMD       TARGET_IO(2, 0x58)
1006 #define TARGET_FDTWADDLE      TARGET_IO(2, 0x59)
1007 #define TARGET_FDEJECT        TARGET_IO(2, 0x5a)
1008 
1009 #define TARGET_FIBMAP     TARGET_IO(0x00,1)  /* bmap access */
1010 #define TARGET_FIGETBSZ   TARGET_IO(0x00,2)  /* get the block size used for bmap */
1011 
1012 #define TARGET_FICLONE    TARGET_IOW(0x94, 9, int)
1013 #define TARGET_FICLONERANGE TARGET_IOW(0x94, 13, struct file_clone_range)
1014 
1015 /*
1016  * Note that the ioctl numbers for FS_IOC_<GET|SET><FLAGS|VERSION>
1017  * claim type "long" but the actual type used by the kernel is "int".
1018  */
1019 #define TARGET_FS_IOC_GETFLAGS TARGET_IOR('f', 1, abi_long)
1020 #define TARGET_FS_IOC_SETFLAGS TARGET_IOW('f', 2, abi_long)
1021 #define TARGET_FS_IOC_GETVERSION TARGET_IOR('v', 1, abi_long)
1022 #define TARGET_FS_IOC_SETVERSION TARGET_IOW('v', 2, abi_long)
1023 #define TARGET_FS_IOC_FIEMAP TARGET_IOWR('f',11,struct fiemap)
1024 #define TARGET_FS_IOC32_GETFLAGS TARGET_IOR('f', 1, int)
1025 #define TARGET_FS_IOC32_SETFLAGS TARGET_IOW('f', 2, int)
1026 #define TARGET_FS_IOC32_GETVERSION TARGET_IOR('v', 1, int)
1027 #define TARGET_FS_IOC32_SETVERSION TARGET_IOW('v', 2, int)
1028 
1029 /* btrfs ioctls */
1030 #ifdef HAVE_BTRFS_H
1031 #define TARGET_BTRFS_IOC_SNAP_CREATE            TARGET_IOWU(BTRFS_IOCTL_MAGIC, 1)
1032 #define TARGET_BTRFS_IOC_SCAN_DEV               TARGET_IOWU(BTRFS_IOCTL_MAGIC, 4)
1033 #define TARGET_BTRFS_IOC_FORGET_DEV             TARGET_IOWU(BTRFS_IOCTL_MAGIC, 5)
1034 #define TARGET_BTRFS_IOC_ADD_DEV                TARGET_IOWU(BTRFS_IOCTL_MAGIC, 10)
1035 #define TARGET_BTRFS_IOC_RM_DEV                 TARGET_IOWU(BTRFS_IOCTL_MAGIC, 11)
1036 #define TARGET_BTRFS_IOC_SUBVOL_CREATE          TARGET_IOWU(BTRFS_IOCTL_MAGIC, 14)
1037 #define TARGET_BTRFS_IOC_SNAP_DESTROY           TARGET_IOWU(BTRFS_IOCTL_MAGIC, 15)
1038 #define TARGET_BTRFS_IOC_INO_LOOKUP             TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 18)
1039 #define TARGET_BTRFS_IOC_DEFAULT_SUBVOL         TARGET_IOW(BTRFS_IOCTL_MAGIC, 19,\
1040                                                            abi_ullong)
1041 #define TARGET_BTRFS_IOC_SUBVOL_GETFLAGS        TARGET_IOR(BTRFS_IOCTL_MAGIC, 25,\
1042                                                            abi_ullong)
1043 #define TARGET_BTRFS_IOC_SUBVOL_SETFLAGS        TARGET_IOW(BTRFS_IOCTL_MAGIC, 26,\
1044                                                            abi_ullong)
1045 #define TARGET_BTRFS_IOC_SCRUB                  TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 27)
1046 #define TARGET_BTRFS_IOC_SCRUB_CANCEL           TARGET_IO(BTRFS_IOCTL_MAGIC, 28)
1047 #define TARGET_BTRFS_IOC_SCRUB_PROGRESS         TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 29)
1048 #define TARGET_BTRFS_IOC_DEV_INFO               TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 30)
1049 #define TARGET_BTRFS_IOC_INO_PATHS              TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 35)
1050 #define TARGET_BTRFS_IOC_LOGICAL_INO            TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 36)
1051 #define TARGET_BTRFS_IOC_QUOTA_CTL              TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 40)
1052 #define TARGET_BTRFS_IOC_QGROUP_ASSIGN          TARGET_IOWU(BTRFS_IOCTL_MAGIC, 41)
1053 #define TARGET_BTRFS_IOC_QGROUP_CREATE          TARGET_IOWU(BTRFS_IOCTL_MAGIC, 42)
1054 #define TARGET_BTRFS_IOC_QGROUP_LIMIT           TARGET_IORU(BTRFS_IOCTL_MAGIC, 43)
1055 #define TARGET_BTRFS_IOC_QUOTA_RESCAN           TARGET_IOWU(BTRFS_IOCTL_MAGIC, 44)
1056 #define TARGET_BTRFS_IOC_QUOTA_RESCAN_STATUS    TARGET_IORU(BTRFS_IOCTL_MAGIC, 45)
1057 #define TARGET_BTRFS_IOC_QUOTA_RESCAN_WAIT      TARGET_IO(BTRFS_IOCTL_MAGIC, 46)
1058 #define TARGET_BTRFS_IOC_GET_DEV_STATS          TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 52)
1059 #define TARGET_BTRFS_IOC_GET_FEATURES           TARGET_IORU(BTRFS_IOCTL_MAGIC, 57)
1060 #define TARGET_BTRFS_IOC_SET_FEATURES           TARGET_IOWU(BTRFS_IOCTL_MAGIC, 57)
1061 #define TARGET_BTRFS_IOC_GET_SUPPORTED_FEATURES TARGET_IORU(BTRFS_IOCTL_MAGIC, 57)
1062 #define TARGET_BTRFS_IOC_LOGICAL_INO_V2         TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 59)
1063 #define TARGET_BTRFS_IOC_GET_SUBVOL_INFO        TARGET_IORU(BTRFS_IOCTL_MAGIC, 60)
1064 #define TARGET_BTRFS_IOC_GET_SUBVOL_ROOTREF     TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 61)
1065 #define TARGET_BTRFS_IOC_INO_LOOKUP_USER        TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 62)
1066 #endif
1067 
1068 /* usb ioctls */
1069 #define TARGET_USBDEVFS_CONTROL TARGET_IOWRU('U', 0)
1070 #define TARGET_USBDEVFS_BULK TARGET_IOWRU('U', 2)
1071 #define TARGET_USBDEVFS_RESETEP TARGET_IORU('U', 3)
1072 #define TARGET_USBDEVFS_SETINTERFACE TARGET_IORU('U', 4)
1073 #define TARGET_USBDEVFS_SETCONFIGURATION TARGET_IORU('U',  5)
1074 #define TARGET_USBDEVFS_GETDRIVER TARGET_IOWU('U', 8)
1075 #define TARGET_USBDEVFS_SUBMITURB TARGET_IORU('U', 10)
1076 #define TARGET_USBDEVFS_DISCARDURB TARGET_IO('U', 11)
1077 #define TARGET_USBDEVFS_REAPURB TARGET_IOWU('U', 12)
1078 #define TARGET_USBDEVFS_REAPURBNDELAY TARGET_IOWU('U', 13)
1079 #define TARGET_USBDEVFS_DISCSIGNAL TARGET_IORU('U', 14)
1080 #define TARGET_USBDEVFS_CLAIMINTERFACE TARGET_IORU('U', 15)
1081 #define TARGET_USBDEVFS_RELEASEINTERFACE TARGET_IORU('U', 16)
1082 #define TARGET_USBDEVFS_CONNECTINFO TARGET_IOWU('U', 17)
1083 #define TARGET_USBDEVFS_IOCTL TARGET_IOWRU('U', 18)
1084 #define TARGET_USBDEVFS_HUB_PORTINFO TARGET_IORU('U', 19)
1085 #define TARGET_USBDEVFS_RESET TARGET_IO('U', 20)
1086 #define TARGET_USBDEVFS_CLEAR_HALT TARGET_IORU('U', 21)
1087 #define TARGET_USBDEVFS_DISCONNECT TARGET_IO('U', 22)
1088 #define TARGET_USBDEVFS_CONNECT TARGET_IO('U', 23)
1089 #define TARGET_USBDEVFS_CLAIM_PORT TARGET_IORU('U', 24)
1090 #define TARGET_USBDEVFS_RELEASE_PORT TARGET_IORU('U', 25)
1091 #define TARGET_USBDEVFS_GET_CAPABILITIES TARGET_IORU('U', 26)
1092 #define TARGET_USBDEVFS_DISCONNECT_CLAIM TARGET_IORU('U', 27)
1093 #define TARGET_USBDEVFS_DROP_PRIVILEGES TARGET_IOWU('U', 30)
1094 #define TARGET_USBDEVFS_GET_SPEED TARGET_IO('U', 31)
1095 
1096 /* cdrom commands */
1097 #define TARGET_CDROMPAUSE		0x5301 /* Pause Audio Operation */
1098 #define TARGET_CDROMRESUME		0x5302 /* Resume paused Audio Operation */
1099 #define TARGET_CDROMPLAYMSF		0x5303 /* Play Audio MSF (struct cdrom_msf) */
1100 #define TARGET_CDROMPLAYTRKIND		0x5304 /* Play Audio Track/index
1101                                            (struct cdrom_ti) */
1102 #define TARGET_CDROMREADTOCHDR		0x5305 /* Read TOC header
1103                                            (struct cdrom_tochdr) */
1104 #define TARGET_CDROMREADTOCENTRY	0x5306 /* Read TOC entry
1105                                            (struct cdrom_tocentry) */
1106 #define TARGET_CDROMSTOP		0x5307 /* Stop the cdrom drive */
1107 #define TARGET_CDROMSTART		0x5308 /* Start the cdrom drive */
1108 #define TARGET_CDROMEJECT		0x5309 /* Ejects the cdrom media */
1109 #define TARGET_CDROMVOLCTRL		0x530a /* Control output volume
1110                                            (struct cdrom_volctrl) */
1111 #define TARGET_CDROMSUBCHNL		0x530b /* Read subchannel data
1112                                            (struct cdrom_subchnl) */
1113 #define TARGET_CDROMREADMODE2		0x530c /* Read TARGET_CDROM mode 2 data (2336 Bytes)
1114                                            (struct cdrom_read) */
1115 #define TARGET_CDROMREADMODE1		0x530d /* Read TARGET_CDROM mode 1 data (2048 Bytes)
1116                                            (struct cdrom_read) */
1117 #define TARGET_CDROMREADAUDIO		0x530e /* (struct cdrom_read_audio) */
1118 #define TARGET_CDROMEJECT_SW		0x530f /* enable(1)/disable(0) auto-ejecting */
1119 #define TARGET_CDROMMULTISESSION	0x5310 /* Obtain the start-of-last-session
1120                                            address of multi session disks
1121                                            (struct cdrom_multisession) */
1122 #define TARGET_CDROM_GET_MCN		0x5311 /* Obtain the "Universal Product Code"
1123                                            if available (struct cdrom_mcn) */
1124 #define TARGET_CDROM_GET_UPC		TARGET_CDROM_GET_MCN  /* This one is deprecated,
1125                                           but here anyway for compatibility */
1126 #define TARGET_CDROMRESET		0x5312 /* hard-reset the drive */
1127 #define TARGET_CDROMVOLREAD		0x5313 /* Get the drive's volume setting
1128                                           (struct cdrom_volctrl) */
1129 #define TARGET_CDROMREADRAW		0x5314	/* read data in raw mode (2352 Bytes)
1130                                            (struct cdrom_read) */
1131 /*
1132  * These ioctls are used only used in aztcd.c and optcd.c
1133  */
1134 #define TARGET_CDROMREADCOOKED		0x5315	/* read data in cooked mode */
1135 #define TARGET_CDROMSEEK		0x5316  /* seek msf address */
1136 
1137 /*
1138  * This ioctl is only used by the scsi-cd driver.
1139    It is for playing audio in logical block addressing mode.
1140  */
1141 #define TARGET_CDROMPLAYBLK		0x5317	/* (struct cdrom_blk) */
1142 
1143 /*
1144  * These ioctls are only used in optcd.c
1145  */
1146 #define TARGET_CDROMREADALL		0x5318	/* read all 2646 bytes */
1147 
1148 /*
1149  * These ioctls are (now) only in ide-cd.c for controlling
1150  * drive spindown time.  They should be implemented in the
1151  * Uniform driver, via generic packet commands, GPCMD_MODE_SELECT_10,
1152  * GPCMD_MODE_SENSE_10 and the GPMODE_POWER_PAGE...
1153  *  -Erik
1154  */
1155 #define TARGET_CDROMGETSPINDOWN        0x531d
1156 #define TARGET_CDROMSETSPINDOWN        0x531e
1157 
1158 /*
1159  * These ioctls are implemented through the uniform CD-ROM driver
1160  * They _will_ be adopted by all CD-ROM drivers, when all the CD-ROM
1161  * drivers are eventually ported to the uniform CD-ROM driver interface.
1162  */
1163 #define TARGET_CDROMCLOSETRAY		0x5319	/* pendant of CDROMEJECT */
1164 #define TARGET_CDROM_SET_OPTIONS	0x5320  /* Set behavior options */
1165 #define TARGET_CDROM_CLEAR_OPTIONS	0x5321  /* Clear behavior options */
1166 #define TARGET_CDROM_SELECT_SPEED	0x5322  /* Set the CD-ROM speed */
1167 #define TARGET_CDROM_SELECT_DISC	0x5323  /* Select disc (for juke-boxes) */
1168 #define TARGET_CDROM_MEDIA_CHANGED	0x5325  /* Check is media changed  */
1169 #define TARGET_CDROM_DRIVE_STATUS	0x5326  /* Get tray position, etc. */
1170 #define TARGET_CDROM_DISC_STATUS	0x5327  /* Get disc type, etc. */
1171 #define TARGET_CDROM_CHANGER_NSLOTS    0x5328  /* Get number of slots */
1172 #define TARGET_CDROM_LOCKDOOR		0x5329  /* lock or unlock door */
1173 #define TARGET_CDROM_DEBUG		0x5330	/* Turn debug messages on/off */
1174 #define TARGET_CDROM_GET_CAPABILITY	0x5331	/* get capabilities */
1175 
1176 /* Note that scsi/scsi_ioctl.h also uses 0x5382 - 0x5386.
1177  * Future CDROM ioctls should be kept below 0x537F
1178  */
1179 
1180 /* This ioctl is only used by sbpcd at the moment */
1181 #define TARGET_CDROMAUDIOBUFSIZ        0x5382	/* set the audio buffer size */
1182 					/* conflict with SCSI_IOCTL_GET_IDLUN */
1183 
1184 /* DVD-ROM Specific ioctls */
1185 #define TARGET_DVD_READ_STRUCT		0x5390  /* Read structure */
1186 #define TARGET_DVD_WRITE_STRUCT	0x5391  /* Write structure */
1187 #define TARGET_DVD_AUTH		0x5392  /* Authentication */
1188 
1189 #define TARGET_CDROM_SEND_PACKET	0x5393	/* send a packet to the drive */
1190 #define TARGET_CDROM_NEXT_WRITABLE	0x5394	/* get next writable block */
1191 #define TARGET_CDROM_LAST_WRITTEN	0x5395	/* get last block written on disc */
1192 
1193 /* HD commands */
1194 
1195 /* hd/ide ctl's that pass (arg) ptrs to user space are numbered 0x030n/0x031n */
1196 #define TARGET_HDIO_GETGEO            0x0301  /* get device geometry */
1197 #define TARGET_HDIO_GET_UNMASKINTR    0x0302  /* get current unmask setting */
1198 #define TARGET_HDIO_GET_MULTCOUNT     0x0304  /* get current IDE blockmode setting */
1199 #define TARGET_HDIO_GET_KEEPSETTINGS  0x0308  /* get keep-settings-on-reset flag */
1200 #define TARGET_HDIO_GET_32BIT         0x0309  /* get current io_32bit setting */
1201 #define TARGET_HDIO_GET_NOWERR        0x030a  /* get ignore-write-error flag */
1202 #define TARGET_HDIO_GET_DMA           0x030b  /* get use-dma flag */
1203 #define TARGET_HDIO_GET_IDENTITY      0x030d  /* get IDE identification info */
1204 #define TARGET_HDIO_DRIVE_CMD         0x031f  /* execute a special drive command */
1205 
1206 /* hd/ide ctl's that pass (arg) non-ptr values are numbered 0x032n/0x033n */
1207 #define TARGET_HDIO_SET_MULTCOUNT     0x0321  /* change IDE blockmode */
1208 #define TARGET_HDIO_SET_UNMASKINTR    0x0322  /* permit other irqs during I/O */
1209 #define TARGET_HDIO_SET_KEEPSETTINGS  0x0323  /* keep ioctl settings on reset */
1210 #define TARGET_HDIO_SET_32BIT         0x0324  /* change io_32bit flags */
1211 #define TARGET_HDIO_SET_NOWERR        0x0325  /* change ignore-write-error flag */
1212 #define TARGET_HDIO_SET_DMA           0x0326  /* change use-dma flag */
1213 #define TARGET_HDIO_SET_PIO_MODE      0x0327  /* reconfig interface to new speed */
1214 
1215 /* loop ioctls */
1216 #define TARGET_LOOP_SET_FD            0x4C00
1217 #define TARGET_LOOP_CLR_FD            0x4C01
1218 #define TARGET_LOOP_SET_STATUS        0x4C02
1219 #define TARGET_LOOP_GET_STATUS        0x4C03
1220 #define TARGET_LOOP_SET_STATUS64      0x4C04
1221 #define TARGET_LOOP_GET_STATUS64      0x4C05
1222 #define TARGET_LOOP_CHANGE_FD         0x4C06
1223 #define TARGET_LOOP_SET_CAPACITY      0x4C07
1224 #define TARGET_LOOP_SET_DIRECT_IO     0x4C08
1225 #define TARGET_LOOP_SET_BLOCK_SIZE    0x4C09
1226 #define TARGET_LOOP_CONFIGURE         0x4C0A
1227 
1228 #define TARGET_LOOP_CTL_ADD           0x4C80
1229 #define TARGET_LOOP_CTL_REMOVE        0x4C81
1230 #define TARGET_LOOP_CTL_GET_FREE      0x4C82
1231 
1232 /* fb ioctls */
1233 #define TARGET_FBIOGET_VSCREENINFO    0x4600
1234 #define TARGET_FBIOPUT_VSCREENINFO    0x4601
1235 #define TARGET_FBIOGET_FSCREENINFO    0x4602
1236 #define TARGET_FBIOGETCMAP            0x4604
1237 #define TARGET_FBIOPUTCMAP            0x4605
1238 #define TARGET_FBIOPAN_DISPLAY        0x4606
1239 #define TARGET_FBIOGET_CON2FBMAP      0x460F
1240 #define TARGET_FBIOPUT_CON2FBMAP      0x4610
1241 
1242 /* vt ioctls */
1243 #define TARGET_VT_OPENQRY             0x5600
1244 #define TARGET_VT_GETSTATE            0x5603
1245 #define TARGET_VT_ACTIVATE            0x5606
1246 #define TARGET_VT_WAITACTIVE          0x5607
1247 #define TARGET_VT_LOCKSWITCH          0x560b
1248 #define TARGET_VT_UNLOCKSWITCH        0x560c
1249 #define TARGET_VT_GETMODE             0x5601
1250 #define TARGET_VT_SETMODE             0x5602
1251 #define TARGET_VT_RELDISP             0x5605
1252 #define TARGET_VT_DISALLOCATE         0x5608
1253 
1254 /* device mapper */
1255 #define TARGET_DM_VERSION             TARGET_IOWRU(0xfd, 0x00)
1256 #define TARGET_DM_REMOVE_ALL          TARGET_IOWRU(0xfd, 0x01)
1257 #define TARGET_DM_LIST_DEVICES        TARGET_IOWRU(0xfd, 0x02)
1258 #define TARGET_DM_DEV_CREATE          TARGET_IOWRU(0xfd, 0x03)
1259 #define TARGET_DM_DEV_REMOVE          TARGET_IOWRU(0xfd, 0x04)
1260 #define TARGET_DM_DEV_RENAME          TARGET_IOWRU(0xfd, 0x05)
1261 #define TARGET_DM_DEV_SUSPEND         TARGET_IOWRU(0xfd, 0x06)
1262 #define TARGET_DM_DEV_STATUS          TARGET_IOWRU(0xfd, 0x07)
1263 #define TARGET_DM_DEV_WAIT            TARGET_IOWRU(0xfd, 0x08)
1264 #define TARGET_DM_TABLE_LOAD          TARGET_IOWRU(0xfd, 0x09)
1265 #define TARGET_DM_TABLE_CLEAR         TARGET_IOWRU(0xfd, 0x0a)
1266 #define TARGET_DM_TABLE_DEPS          TARGET_IOWRU(0xfd, 0x0b)
1267 #define TARGET_DM_TABLE_STATUS        TARGET_IOWRU(0xfd, 0x0c)
1268 #define TARGET_DM_LIST_VERSIONS       TARGET_IOWRU(0xfd, 0x0d)
1269 #define TARGET_DM_TARGET_MSG          TARGET_IOWRU(0xfd, 0x0e)
1270 #define TARGET_DM_DEV_SET_GEOMETRY    TARGET_IOWRU(0xfd, 0x0f)
1271 
1272 /* drm ioctls */
1273 #define TARGET_DRM_IOCTL_VERSION      TARGET_IOWRU('d', 0x00)
1274 
1275 /* drm i915 ioctls */
1276 #define TARGET_DRM_IOCTL_I915_GETPARAM              TARGET_IOWRU('d', 0x46)
1277 
1278 /* from asm/termbits.h */
1279 
1280 #define TARGET_NCC 8
1281 struct target_termio {
1282 	unsigned short c_iflag;		/* input mode flags */
1283 	unsigned short c_oflag;		/* output mode flags */
1284 	unsigned short c_cflag;		/* control mode flags */
1285 	unsigned short c_lflag;		/* local mode flags */
1286 	unsigned char c_line;		/* line discipline */
1287 	unsigned char c_cc[TARGET_NCC];	/* control characters */
1288 };
1289 
1290 struct target_winsize {
1291 	unsigned short ws_row;
1292 	unsigned short ws_col;
1293 	unsigned short ws_xpixel;
1294 	unsigned short ws_ypixel;
1295 };
1296 
1297 #include "termbits.h"
1298 
1299 #if defined(TARGET_MIPS)
1300 #define TARGET_PROT_SEM         0x10
1301 #else
1302 #define TARGET_PROT_SEM         0x08
1303 #endif
1304 
1305 #ifdef TARGET_AARCH64
1306 #define TARGET_PROT_BTI         0x10
1307 #define TARGET_PROT_MTE         0x20
1308 #endif
1309 
1310 /* Common */
1311 #define TARGET_MAP_SHARED	0x01		/* Share changes */
1312 #define TARGET_MAP_PRIVATE	0x02		/* Changes are private */
1313 #if defined(TARGET_HPPA)
1314 #define TARGET_MAP_TYPE         0x03		/* Mask for type of mapping */
1315 #else
1316 #define TARGET_MAP_TYPE         0x0f		/* Mask for type of mapping */
1317 #endif
1318 
1319 /* Target specific */
1320 #if defined(TARGET_MIPS)
1321 #define TARGET_MAP_FIXED	0x10		/* Interpret addr exactly */
1322 #define TARGET_MAP_ANONYMOUS	0x0800		/* don't use a file */
1323 #define TARGET_MAP_GROWSDOWN	0x1000		/* stack-like segment */
1324 #define TARGET_MAP_DENYWRITE	0x2000		/* ETXTBSY */
1325 #define TARGET_MAP_EXECUTABLE	0x4000		/* mark it as an executable */
1326 #define TARGET_MAP_LOCKED	0x8000		/* pages are locked */
1327 #define TARGET_MAP_NORESERVE	0x0400		/* don't check for reservations */
1328 #define TARGET_MAP_POPULATE	0x10000		/* populate (prefault) pagetables */
1329 #define TARGET_MAP_NONBLOCK	0x20000		/* do not block on IO */
1330 #define TARGET_MAP_STACK        0x40000         /* ignored */
1331 #define TARGET_MAP_HUGETLB      0x80000         /* create a huge page mapping */
1332 #elif defined(TARGET_PPC)
1333 #define TARGET_MAP_FIXED	0x10		/* Interpret addr exactly */
1334 #define TARGET_MAP_ANONYMOUS	0x20		/* don't use a file */
1335 #define TARGET_MAP_GROWSDOWN	0x0100		/* stack-like segment */
1336 #define TARGET_MAP_DENYWRITE	0x0800		/* ETXTBSY */
1337 #define TARGET_MAP_EXECUTABLE	0x1000		/* mark it as an executable */
1338 #define TARGET_MAP_LOCKED	0x0080		/* pages are locked */
1339 #define TARGET_MAP_NORESERVE	0x0040		/* don't check for reservations */
1340 #define TARGET_MAP_POPULATE	0x8000		/* populate (prefault) pagetables */
1341 #define TARGET_MAP_NONBLOCK	0x10000		/* do not block on IO */
1342 #define TARGET_MAP_STACK        0x20000         /* ignored */
1343 #define TARGET_MAP_HUGETLB      0x40000         /* create a huge page mapping */
1344 #elif defined(TARGET_ALPHA)
1345 #define TARGET_MAP_ANONYMOUS	0x10		/* don't use a file */
1346 #define TARGET_MAP_FIXED	0x100		/* Interpret addr exactly */
1347 #define TARGET_MAP_GROWSDOWN	0x01000		/* stack-like segment */
1348 #define TARGET_MAP_DENYWRITE	0x02000		/* ETXTBSY */
1349 #define TARGET_MAP_EXECUTABLE	0x04000		/* mark it as an executable */
1350 #define TARGET_MAP_LOCKED	0x08000		/* lock the mapping */
1351 #define TARGET_MAP_NORESERVE	0x10000		/* no check for reservations */
1352 #define TARGET_MAP_POPULATE	0x20000		/* pop (prefault) pagetables */
1353 #define TARGET_MAP_NONBLOCK	0x40000		/* do not block on IO */
1354 #define TARGET_MAP_STACK        0x80000         /* ignored */
1355 #define TARGET_MAP_HUGETLB      0x100000        /* create a huge page mapping */
1356 #elif defined(TARGET_HPPA)
1357 #define TARGET_MAP_ANONYMOUS	0x10		/* don't use a file */
1358 #define TARGET_MAP_FIXED	0x04		/* Interpret addr exactly */
1359 #define TARGET_MAP_GROWSDOWN	0x08000		/* stack-like segment */
1360 #define TARGET_MAP_DENYWRITE	0x00800		/* ETXTBSY */
1361 #define TARGET_MAP_EXECUTABLE	0x01000		/* mark it as an executable */
1362 #define TARGET_MAP_LOCKED	0x02000		/* lock the mapping */
1363 #define TARGET_MAP_NORESERVE	0x04000		/* no check for reservations */
1364 #define TARGET_MAP_POPULATE	0x10000		/* pop (prefault) pagetables */
1365 #define TARGET_MAP_NONBLOCK	0x20000		/* do not block on IO */
1366 #define TARGET_MAP_STACK        0x40000         /* ignored */
1367 #define TARGET_MAP_HUGETLB      0x80000         /* create a huge page mapping */
1368 #elif defined(TARGET_XTENSA)
1369 #define TARGET_MAP_FIXED	0x10		/* Interpret addr exactly */
1370 #define TARGET_MAP_ANONYMOUS	0x0800		/* don't use a file */
1371 #define TARGET_MAP_GROWSDOWN	0x1000		/* stack-like segment */
1372 #define TARGET_MAP_DENYWRITE	0x2000		/* ETXTBSY */
1373 #define TARGET_MAP_EXECUTABLE	0x4000		/* mark it as an executable */
1374 #define TARGET_MAP_LOCKED	0x8000		/* pages are locked */
1375 #define TARGET_MAP_NORESERVE	0x0400		/* don't check for reservations */
1376 #define TARGET_MAP_POPULATE	0x10000		/* populate (prefault) pagetables */
1377 #define TARGET_MAP_NONBLOCK	0x20000		/* do not block on IO */
1378 #define TARGET_MAP_STACK	0x40000
1379 #define TARGET_MAP_HUGETLB  0x80000         /* create a huge page mapping */
1380 #else
1381 #define TARGET_MAP_FIXED	0x10		/* Interpret addr exactly */
1382 #define TARGET_MAP_ANONYMOUS	0x20		/* don't use a file */
1383 #define TARGET_MAP_GROWSDOWN	0x0100		/* stack-like segment */
1384 #define TARGET_MAP_DENYWRITE	0x0800		/* ETXTBSY */
1385 #define TARGET_MAP_EXECUTABLE	0x1000		/* mark it as an executable */
1386 #define TARGET_MAP_LOCKED	0x2000		/* pages are locked */
1387 #define TARGET_MAP_NORESERVE	0x4000		/* don't check for reservations */
1388 #define TARGET_MAP_POPULATE	0x8000		/* populate (prefault) pagetables */
1389 #define TARGET_MAP_NONBLOCK	0x10000		/* do not block on IO */
1390 #define TARGET_MAP_STACK        0x20000         /* ignored */
1391 #define TARGET_MAP_HUGETLB      0x40000         /* create a huge page mapping */
1392 #define TARGET_MAP_UNINITIALIZED 0x4000000	/* for anonymous mmap, memory could be uninitialized */
1393 #endif
1394 
1395 #if (defined(TARGET_I386) && defined(TARGET_ABI32)) \
1396     || (defined(TARGET_ARM) && defined(TARGET_ABI32)) \
1397     || defined(TARGET_CRIS)
1398 #define TARGET_STAT_HAVE_NSEC
1399 struct target_stat {
1400 	unsigned short st_dev;
1401 	unsigned short __pad1;
1402 	abi_ulong st_ino;
1403 	unsigned short st_mode;
1404 	unsigned short st_nlink;
1405 	unsigned short st_uid;
1406 	unsigned short st_gid;
1407 	unsigned short st_rdev;
1408 	unsigned short __pad2;
1409 	abi_ulong  st_size;
1410 	abi_ulong  st_blksize;
1411 	abi_ulong  st_blocks;
1412 	abi_ulong  target_st_atime;
1413 	abi_ulong  target_st_atime_nsec;
1414 	abi_ulong  target_st_mtime;
1415 	abi_ulong  target_st_mtime_nsec;
1416 	abi_ulong  target_st_ctime;
1417 	abi_ulong  target_st_ctime_nsec;
1418 	abi_ulong  __unused4;
1419 	abi_ulong  __unused5;
1420 };
1421 
1422 /* This matches struct stat64 in glibc2.1, hence the absolutely
1423  * insane amounts of padding around dev_t's.
1424  */
1425 #define TARGET_HAS_STRUCT_STAT64
1426 struct target_stat64 {
1427 	unsigned short	st_dev;
1428 	unsigned char	__pad0[10];
1429 
1430 #define TARGET_STAT64_HAS_BROKEN_ST_INO	1
1431 	abi_ulong	__st_ino;
1432 
1433 	unsigned int	st_mode;
1434 	unsigned int	st_nlink;
1435 
1436 	abi_ulong	st_uid;
1437 	abi_ulong	st_gid;
1438 
1439 	unsigned short	st_rdev;
1440 	unsigned char	__pad3[10];
1441 
1442 	long long	st_size;
1443 	abi_ulong	st_blksize;
1444 
1445 	abi_ulong	st_blocks;	/* Number 512-byte blocks allocated. */
1446 	abi_ulong	__pad4;		/* future possible st_blocks high bits */
1447 
1448 	abi_ulong	target_st_atime;
1449 	abi_ulong	target_st_atime_nsec;
1450 
1451 	abi_ulong	target_st_mtime;
1452 	abi_ulong	target_st_mtime_nsec;
1453 
1454 	abi_ulong	target_st_ctime;
1455 	abi_ulong	target_st_ctime_nsec;
1456 
1457 	unsigned long long	st_ino;
1458 } QEMU_PACKED;
1459 
1460 #ifdef TARGET_ARM
1461 #define TARGET_HAS_STRUCT_STAT64
1462 struct target_eabi_stat64 {
1463         unsigned long long st_dev;
1464         unsigned int    __pad1;
1465         abi_ulong    __st_ino;
1466         unsigned int    st_mode;
1467         unsigned int    st_nlink;
1468 
1469         abi_ulong    st_uid;
1470         abi_ulong    st_gid;
1471 
1472         unsigned long long st_rdev;
1473         unsigned int    __pad2[2];
1474 
1475         long long       st_size;
1476         abi_ulong    st_blksize;
1477         unsigned int    __pad3;
1478         unsigned long long st_blocks;
1479 
1480         abi_ulong    target_st_atime;
1481         abi_ulong    target_st_atime_nsec;
1482 
1483         abi_ulong    target_st_mtime;
1484         abi_ulong    target_st_mtime_nsec;
1485 
1486         abi_ulong    target_st_ctime;
1487         abi_ulong    target_st_ctime_nsec;
1488 
1489         unsigned long long st_ino;
1490 } QEMU_PACKED;
1491 #endif
1492 
1493 #elif defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
1494 struct target_stat {
1495 	unsigned int	st_dev;
1496 	abi_ulong	st_ino;
1497 	unsigned int	st_mode;
1498 	unsigned int	st_nlink;
1499 	unsigned int	st_uid;
1500 	unsigned int	st_gid;
1501 	unsigned int	st_rdev;
1502 	abi_long	st_size;
1503 	abi_long	target_st_atime;
1504 	abi_long	target_st_mtime;
1505 	abi_long	target_st_ctime;
1506 	abi_long	st_blksize;
1507 	abi_long	st_blocks;
1508 	abi_ulong	__unused4[2];
1509 };
1510 
1511 #define TARGET_HAS_STRUCT_STAT64
1512 struct target_stat64 {
1513 	unsigned char	__pad0[6];
1514 	unsigned short	st_dev;
1515 
1516 	uint64_t	st_ino;
1517 	uint64_t	st_nlink;
1518 
1519 	unsigned int	st_mode;
1520 
1521 	unsigned int	st_uid;
1522 	unsigned int	st_gid;
1523 
1524 	unsigned char	__pad2[6];
1525 	unsigned short	st_rdev;
1526 
1527         int64_t		st_size;
1528 	int64_t		st_blksize;
1529 
1530 	unsigned char	__pad4[4];
1531 	unsigned int	st_blocks;
1532 
1533 	abi_ulong	target_st_atime;
1534 	abi_ulong	target_st_atime_nsec;
1535 
1536 	abi_ulong	target_st_mtime;
1537 	abi_ulong	target_st_mtime_nsec;
1538 
1539 	abi_ulong	target_st_ctime;
1540 	abi_ulong	target_st_ctime_nsec;
1541 
1542 	abi_ulong	__unused4[3];
1543 };
1544 
1545 #elif defined(TARGET_SPARC)
1546 
1547 #define TARGET_STAT_HAVE_NSEC
1548 struct target_stat {
1549 	unsigned short	st_dev;
1550 	abi_ulong	st_ino;
1551 	unsigned short	st_mode;
1552 	short		st_nlink;
1553 	unsigned short	st_uid;
1554 	unsigned short	st_gid;
1555 	unsigned short	st_rdev;
1556 	abi_long	st_size;
1557 	abi_long	target_st_atime;
1558 	abi_ulong	target_st_atime_nsec;
1559 	abi_long	target_st_mtime;
1560 	abi_ulong	target_st_mtime_nsec;
1561 	abi_long	target_st_ctime;
1562 	abi_ulong	target_st_ctime_nsec;
1563 	abi_long	st_blksize;
1564 	abi_long	st_blocks;
1565 	abi_ulong	__unused1[2];
1566 };
1567 
1568 #define TARGET_HAS_STRUCT_STAT64
1569 struct target_stat64 {
1570 	unsigned char	__pad0[6];
1571 	unsigned short	st_dev;
1572 
1573 	uint64_t st_ino;
1574 
1575 	unsigned int	st_mode;
1576 	unsigned int	st_nlink;
1577 
1578 	unsigned int	st_uid;
1579 	unsigned int	st_gid;
1580 
1581 	unsigned char	__pad2[6];
1582 	unsigned short	st_rdev;
1583 
1584 	unsigned char	__pad3[8];
1585 
1586         int64_t	st_size;
1587 	unsigned int	st_blksize;
1588 
1589 	unsigned char	__pad4[8];
1590 	unsigned int	st_blocks;
1591 
1592 	unsigned int	target_st_atime;
1593 	unsigned int	target_st_atime_nsec;
1594 
1595 	unsigned int	target_st_mtime;
1596 	unsigned int	target_st_mtime_nsec;
1597 
1598 	unsigned int	target_st_ctime;
1599 	unsigned int	target_st_ctime_nsec;
1600 
1601 	unsigned int	__unused1;
1602 	unsigned int	__unused2;
1603 };
1604 
1605 #elif defined(TARGET_PPC)
1606 
1607 #define TARGET_STAT_HAVE_NSEC
1608 struct target_stat {
1609 	abi_ulong st_dev;
1610 	abi_ulong st_ino;
1611 #if defined(TARGET_PPC64) && !defined(TARGET_ABI32)
1612 	abi_ulong st_nlink;
1613 	unsigned int st_mode;
1614 #else
1615 	unsigned int st_mode;
1616 	unsigned short st_nlink;
1617 #endif
1618 	unsigned int st_uid;
1619 	unsigned int st_gid;
1620 	abi_ulong  st_rdev;
1621 	abi_ulong  st_size;
1622 	abi_ulong  st_blksize;
1623 	abi_ulong  st_blocks;
1624 	abi_ulong  target_st_atime;
1625 	abi_ulong  target_st_atime_nsec;
1626 	abi_ulong  target_st_mtime;
1627 	abi_ulong  target_st_mtime_nsec;
1628 	abi_ulong  target_st_ctime;
1629 	abi_ulong  target_st_ctime_nsec;
1630 	abi_ulong  __unused4;
1631 	abi_ulong  __unused5;
1632 #if defined(TARGET_PPC64) && !defined(TARGET_ABI32)
1633 	abi_ulong  __unused6;
1634 #endif
1635 };
1636 
1637 #if !defined(TARGET_PPC64) || defined(TARGET_ABI32)
1638 #define TARGET_HAS_STRUCT_STAT64
1639 struct QEMU_PACKED target_stat64 {
1640 	unsigned long long st_dev;
1641         unsigned long long st_ino;
1642 	unsigned int st_mode;
1643 	unsigned int st_nlink;
1644 	unsigned int st_uid;
1645 	unsigned int st_gid;
1646 	unsigned long long st_rdev;
1647 	unsigned long long __pad0;
1648 	long long      st_size;
1649 	int	       st_blksize;
1650 	unsigned int   __pad1;
1651 	long long      st_blocks;	/* Number 512-byte blocks allocated. */
1652 	int	       target_st_atime;
1653         unsigned int   target_st_atime_nsec;
1654 	int	       target_st_mtime;
1655         unsigned int   target_st_mtime_nsec;
1656 	int            target_st_ctime;
1657         unsigned int   target_st_ctime_nsec;
1658         unsigned int   __unused4;
1659         unsigned int   __unused5;
1660 };
1661 #endif
1662 
1663 #elif defined(TARGET_MICROBLAZE)
1664 
1665 #define TARGET_STAT_HAVE_NSEC
1666 struct target_stat {
1667 	abi_ulong st_dev;
1668 	abi_ulong st_ino;
1669 	unsigned int st_mode;
1670 	unsigned short st_nlink;
1671 	unsigned int st_uid;
1672 	unsigned int st_gid;
1673 	abi_ulong  st_rdev;
1674 	abi_ulong  st_size;
1675 	abi_ulong  st_blksize;
1676 	abi_ulong  st_blocks;
1677 	abi_ulong  target_st_atime;
1678 	abi_ulong  target_st_atime_nsec;
1679 	abi_ulong  target_st_mtime;
1680 	abi_ulong  target_st_mtime_nsec;
1681 	abi_ulong  target_st_ctime;
1682 	abi_ulong  target_st_ctime_nsec;
1683 	abi_ulong  __unused4;
1684 	abi_ulong  __unused5;
1685 };
1686 
1687 /* FIXME: Microblaze no-mmu user-space has a difference stat64 layout...  */
1688 #define TARGET_HAS_STRUCT_STAT64
1689 struct QEMU_PACKED target_stat64 {
1690 	uint64_t st_dev;
1691 #define TARGET_STAT64_HAS_BROKEN_ST_INO 1
1692 	uint32_t pad0;
1693 	uint32_t __st_ino;
1694 
1695 	uint32_t st_mode;
1696 	uint32_t st_nlink;
1697 	uint32_t st_uid;
1698 	uint32_t st_gid;
1699 	uint64_t st_rdev;
1700 	uint64_t __pad1;
1701 
1702 	int64_t  st_size;
1703 	int32_t  st_blksize;
1704 	uint32_t __pad2;
1705 	int64_t st_blocks;	/* Number 512-byte blocks allocated. */
1706 
1707 	int	       target_st_atime;
1708 	unsigned int   target_st_atime_nsec;
1709 	int	       target_st_mtime;
1710 	unsigned int   target_st_mtime_nsec;
1711 	int            target_st_ctime;
1712 	unsigned int   target_st_ctime_nsec;
1713 	uint64_t st_ino;
1714 };
1715 
1716 #elif defined(TARGET_M68K)
1717 
1718 struct target_stat {
1719 	unsigned short st_dev;
1720 	unsigned short __pad1;
1721 	abi_ulong st_ino;
1722 	unsigned short st_mode;
1723 	unsigned short st_nlink;
1724 	unsigned short st_uid;
1725 	unsigned short st_gid;
1726 	unsigned short st_rdev;
1727 	unsigned short __pad2;
1728 	abi_ulong  st_size;
1729 	abi_ulong  st_blksize;
1730 	abi_ulong  st_blocks;
1731 	abi_ulong  target_st_atime;
1732 	abi_ulong  __unused1;
1733 	abi_ulong  target_st_mtime;
1734 	abi_ulong  __unused2;
1735 	abi_ulong  target_st_ctime;
1736 	abi_ulong  __unused3;
1737 	abi_ulong  __unused4;
1738 	abi_ulong  __unused5;
1739 };
1740 
1741 /* This matches struct stat64 in glibc2.1, hence the absolutely
1742  * insane amounts of padding around dev_t's.
1743  */
1744 #define TARGET_HAS_STRUCT_STAT64
1745 struct target_stat64 {
1746 	unsigned long long	st_dev;
1747 	unsigned char	__pad1[2];
1748 
1749 #define TARGET_STAT64_HAS_BROKEN_ST_INO	1
1750 	abi_ulong	__st_ino;
1751 
1752 	unsigned int	st_mode;
1753 	unsigned int	st_nlink;
1754 
1755 	abi_ulong	st_uid;
1756 	abi_ulong	st_gid;
1757 
1758 	unsigned long long	st_rdev;
1759 	unsigned char	__pad3[2];
1760 
1761 	long long	st_size;
1762 	abi_ulong	st_blksize;
1763 
1764 	abi_ulong	__pad4;		/* future possible st_blocks high bits */
1765 	abi_ulong	st_blocks;	/* Number 512-byte blocks allocated. */
1766 
1767 	abi_ulong	target_st_atime;
1768 	abi_ulong	target_st_atime_nsec;
1769 
1770 	abi_ulong	target_st_mtime;
1771 	abi_ulong	target_st_mtime_nsec;
1772 
1773 	abi_ulong	target_st_ctime;
1774 	abi_ulong	target_st_ctime_nsec;
1775 
1776 	unsigned long long	st_ino;
1777 } QEMU_PACKED;
1778 
1779 #elif defined(TARGET_ABI_MIPSN64)
1780 
1781 #define TARGET_STAT_HAVE_NSEC
1782 /* The memory layout is the same as of struct stat64 of the 32-bit kernel.  */
1783 struct target_stat {
1784 	unsigned int		st_dev;
1785 	unsigned int		st_pad0[3]; /* Reserved for st_dev expansion */
1786 
1787 	abi_ulong		st_ino;
1788 
1789 	unsigned int		st_mode;
1790 	unsigned int		st_nlink;
1791 
1792 	int			st_uid;
1793 	int			st_gid;
1794 
1795 	unsigned int		st_rdev;
1796 	unsigned int		st_pad1[3]; /* Reserved for st_rdev expansion */
1797 
1798 	abi_ulong		st_size;
1799 
1800 	/*
1801 	 * Actually this should be timestruc_t st_atime, st_mtime and st_ctime
1802 	 * but we don't have it under Linux.
1803 	 */
1804 	unsigned int		target_st_atime;
1805 	unsigned int		target_st_atime_nsec;
1806 
1807 	unsigned int		target_st_mtime;
1808 	unsigned int		target_st_mtime_nsec;
1809 
1810 	unsigned int		target_st_ctime;
1811 	unsigned int		target_st_ctime_nsec;
1812 
1813 	unsigned int		st_blksize;
1814 	unsigned int		st_pad2;
1815 
1816 	abi_ulong		st_blocks;
1817 };
1818 
1819 #elif defined(TARGET_ABI_MIPSN32)
1820 
1821 #define TARGET_STAT_HAVE_NSEC
1822 struct target_stat {
1823         abi_ulong    st_dev;
1824         abi_ulong    st_pad0[3]; /* Reserved for st_dev expansion */
1825         uint64_t     st_ino;
1826         unsigned int st_mode;
1827         unsigned int st_nlink;
1828         int          st_uid;
1829         int          st_gid;
1830         abi_ulong    st_rdev;
1831         abi_ulong    st_pad1[3]; /* Reserved for st_rdev expansion */
1832         int64_t      st_size;
1833         abi_long     target_st_atime;
1834         abi_ulong    target_st_atime_nsec; /* Reserved for st_atime expansion */
1835         abi_long     target_st_mtime;
1836         abi_ulong    target_st_mtime_nsec; /* Reserved for st_mtime expansion */
1837         abi_long     target_st_ctime;
1838         abi_ulong    target_st_ctime_nsec; /* Reserved for st_ctime expansion */
1839         abi_ulong    st_blksize;
1840         abi_ulong    st_pad2;
1841         int64_t      st_blocks;
1842 };
1843 
1844 #elif defined(TARGET_ABI_MIPSO32)
1845 
1846 #define TARGET_STAT_HAVE_NSEC
1847 struct target_stat {
1848 	unsigned	st_dev;
1849 	abi_long	st_pad1[3];		/* Reserved for network id */
1850 	abi_ulong	st_ino;
1851 	unsigned int	st_mode;
1852 	unsigned int	st_nlink;
1853 	int		st_uid;
1854 	int		st_gid;
1855 	unsigned 	st_rdev;
1856 	abi_long	st_pad2[2];
1857 	abi_long	st_size;
1858 	abi_long	st_pad3;
1859 	/*
1860 	 * Actually this should be timestruc_t st_atime, st_mtime and st_ctime
1861 	 * but we don't have it under Linux.
1862 	 */
1863 	abi_long		target_st_atime;
1864 	abi_long		target_st_atime_nsec;
1865 	abi_long		target_st_mtime;
1866 	abi_long		target_st_mtime_nsec;
1867 	abi_long		target_st_ctime;
1868 	abi_long		target_st_ctime_nsec;
1869 	abi_long		st_blksize;
1870 	abi_long		st_blocks;
1871 	abi_long		st_pad4[14];
1872 };
1873 
1874 /*
1875  * This matches struct stat64 in glibc2.1, hence the absolutely insane
1876  * amounts of padding around dev_t's.  The memory layout is the same as of
1877  * struct stat of the 64-bit kernel.
1878  */
1879 
1880 #define TARGET_HAS_STRUCT_STAT64
1881 struct target_stat64 {
1882 	abi_ulong	st_dev;
1883 	abi_ulong	st_pad0[3];	/* Reserved for st_dev expansion  */
1884 
1885 	uint64_t	st_ino;
1886 
1887         unsigned int	st_mode;
1888         unsigned int	st_nlink;
1889 
1890 	int		st_uid;
1891 	int		st_gid;
1892 
1893 	abi_ulong	st_rdev;
1894 	abi_ulong	st_pad1[3];	/* Reserved for st_rdev expansion  */
1895 
1896 	int64_t 	st_size;
1897 
1898 	/*
1899 	 * Actually this should be timestruc_t st_atime, st_mtime and st_ctime
1900 	 * but we don't have it under Linux.
1901 	 */
1902 	abi_long	target_st_atime;
1903 	abi_ulong	target_st_atime_nsec;	/* Reserved for st_atime expansion  */
1904 
1905 	abi_long	target_st_mtime;
1906 	abi_ulong	target_st_mtime_nsec;	/* Reserved for st_mtime expansion  */
1907 
1908 	abi_long	target_st_ctime;
1909 	abi_ulong	target_st_ctime_nsec;	/* Reserved for st_ctime expansion  */
1910 
1911 	abi_ulong	st_blksize;
1912 	abi_ulong	st_pad2;
1913 
1914 	int64_t  	st_blocks;
1915 };
1916 
1917 #elif defined(TARGET_ALPHA)
1918 
1919 struct target_stat {
1920        unsigned int    st_dev;
1921        unsigned int    st_ino;
1922        unsigned int    st_mode;
1923        unsigned int    st_nlink;
1924        unsigned int    st_uid;
1925        unsigned int    st_gid;
1926        unsigned int    st_rdev;
1927        abi_long     st_size;
1928        abi_ulong    target_st_atime;
1929        abi_ulong    target_st_mtime;
1930        abi_ulong    target_st_ctime;
1931        unsigned int    st_blksize;
1932        unsigned int    st_blocks;
1933        unsigned int    st_flags;
1934        unsigned int    st_gen;
1935 };
1936 
1937 #define TARGET_HAS_STRUCT_STAT64
1938 struct target_stat64 {
1939        abi_ulong    st_dev;
1940        abi_ulong    st_ino;
1941        abi_ulong    st_rdev;
1942        abi_long     st_size;
1943        abi_ulong    st_blocks;
1944 
1945        unsigned int    st_mode;
1946        unsigned int    st_uid;
1947        unsigned int    st_gid;
1948        unsigned int    st_blksize;
1949        unsigned int    st_nlink;
1950        unsigned int    __pad0;
1951 
1952        abi_ulong    target_st_atime;
1953        abi_ulong    target_st_atime_nsec;
1954        abi_ulong    target_st_mtime;
1955        abi_ulong    target_st_mtime_nsec;
1956        abi_ulong    target_st_ctime;
1957        abi_ulong    target_st_ctime_nsec;
1958        abi_long     __unused[3];
1959 };
1960 
1961 #elif defined(TARGET_SH4)
1962 
1963 #define TARGET_STAT_HAVE_NSEC
1964 struct target_stat {
1965 	abi_ulong  st_dev;
1966 	abi_ulong  st_ino;
1967 	unsigned short st_mode;
1968 	unsigned short st_nlink;
1969 	unsigned short st_uid;
1970 	unsigned short st_gid;
1971 	abi_ulong  st_rdev;
1972 	abi_ulong  st_size;
1973 	abi_ulong  st_blksize;
1974 	abi_ulong  st_blocks;
1975 	abi_ulong  target_st_atime;
1976 	abi_ulong  target_st_atime_nsec;
1977 	abi_ulong  target_st_mtime;
1978 	abi_ulong  target_st_mtime_nsec;
1979 	abi_ulong  target_st_ctime;
1980 	abi_ulong  target_st_ctime_nsec;
1981 	abi_ulong  __unused4;
1982 	abi_ulong  __unused5;
1983 };
1984 
1985 /* This matches struct stat64 in glibc2.1, hence the absolutely
1986  * insane amounts of padding around dev_t's.
1987  */
1988 #define TARGET_HAS_STRUCT_STAT64
1989 struct QEMU_PACKED target_stat64 {
1990 	unsigned long long	st_dev;
1991 	unsigned char	__pad0[4];
1992 
1993 #define TARGET_STAT64_HAS_BROKEN_ST_INO	1
1994 	abi_ulong	__st_ino;
1995 
1996 	unsigned int	st_mode;
1997 	unsigned int	st_nlink;
1998 
1999 	abi_ulong	st_uid;
2000 	abi_ulong	st_gid;
2001 
2002 	unsigned long long	st_rdev;
2003 	unsigned char	__pad3[4];
2004 
2005 	long long	st_size;
2006 	abi_ulong	st_blksize;
2007 
2008 	unsigned long long	st_blocks;	/* Number 512-byte blocks allocated. */
2009 
2010 	abi_ulong	target_st_atime;
2011 	abi_ulong	target_st_atime_nsec;
2012 
2013 	abi_ulong	target_st_mtime;
2014 	abi_ulong	target_st_mtime_nsec;
2015 
2016 	abi_ulong	target_st_ctime;
2017 	abi_ulong	target_st_ctime_nsec;
2018 
2019 	unsigned long long	st_ino;
2020 };
2021 
2022 #elif defined(TARGET_I386) && !defined(TARGET_ABI32)
2023 #define TARGET_STAT_HAVE_NSEC
2024 struct target_stat {
2025 	abi_ulong	st_dev;
2026 	abi_ulong	st_ino;
2027 	abi_ulong	st_nlink;
2028 
2029 	unsigned int	st_mode;
2030 	unsigned int	st_uid;
2031 	unsigned int	st_gid;
2032 	unsigned int	__pad0;
2033 	abi_ulong	st_rdev;
2034 	abi_long	st_size;
2035 	abi_long	st_blksize;
2036 	abi_long	st_blocks;	/* Number 512-byte blocks allocated. */
2037 
2038 	abi_ulong	target_st_atime;
2039 	abi_ulong 	target_st_atime_nsec;
2040 	abi_ulong	target_st_mtime;
2041 	abi_ulong	target_st_mtime_nsec;
2042 	abi_ulong	target_st_ctime;
2043 	abi_ulong       target_st_ctime_nsec;
2044 
2045 	abi_long	__unused[3];
2046 };
2047 #elif defined(TARGET_S390X)
2048 struct target_stat {
2049     abi_ulong  st_dev;
2050     abi_ulong  st_ino;
2051     abi_ulong  st_nlink;
2052     unsigned int   st_mode;
2053     unsigned int   st_uid;
2054     unsigned int   st_gid;
2055     unsigned int   __pad1;
2056     abi_ulong  st_rdev;
2057     abi_ulong  st_size;
2058     abi_ulong  target_st_atime;
2059     abi_ulong  target_st_atime_nsec;
2060     abi_ulong  target_st_mtime;
2061     abi_ulong  target_st_mtime_nsec;
2062     abi_ulong  target_st_ctime;
2063     abi_ulong  target_st_ctime_nsec;
2064     abi_ulong  st_blksize;
2065     abi_long       st_blocks;
2066     abi_ulong  __unused[3];
2067 };
2068 #elif defined(TARGET_AARCH64)
2069 #define TARGET_STAT_HAVE_NSEC
2070 struct target_stat {
2071     abi_ulong  st_dev;
2072     abi_ulong  st_ino;
2073     unsigned int st_mode;
2074     unsigned int st_nlink;
2075     unsigned int   st_uid;
2076     unsigned int   st_gid;
2077     abi_ulong  st_rdev;
2078     abi_ulong  _pad1;
2079     abi_long  st_size;
2080     int        st_blksize;
2081     int        __pad2;
2082     abi_long   st_blocks;
2083     abi_long  target_st_atime;
2084     abi_ulong  target_st_atime_nsec;
2085     abi_long  target_st_mtime;
2086     abi_ulong  target_st_mtime_nsec;
2087     abi_long  target_st_ctime;
2088     abi_ulong  target_st_ctime_nsec;
2089     unsigned int __unused[2];
2090 };
2091 #elif defined(TARGET_XTENSA)
2092 #define TARGET_STAT_HAVE_NSEC
2093 struct target_stat {
2094     abi_ulong       st_dev;
2095     abi_ulong       st_ino;
2096     unsigned int    st_mode;
2097     unsigned int    st_nlink;
2098     unsigned int    st_uid;
2099     unsigned int    st_gid;
2100     abi_ulong       st_rdev;
2101     abi_long        st_size;
2102     abi_ulong       st_blksize;
2103     abi_ulong       st_blocks;
2104     abi_ulong       target_st_atime;
2105     abi_ulong       target_st_atime_nsec;
2106     abi_ulong       target_st_mtime;
2107     abi_ulong       target_st_mtime_nsec;
2108     abi_ulong       target_st_ctime;
2109     abi_ulong       target_st_ctime_nsec;
2110     abi_ulong       __unused4;
2111     abi_ulong       __unused5;
2112 };
2113 
2114 #define TARGET_HAS_STRUCT_STAT64
2115 struct target_stat64  {
2116     uint64_t st_dev;            /* Device */
2117     uint64_t st_ino;            /* File serial number */
2118     unsigned int  st_mode;      /* File mode. */
2119     unsigned int  st_nlink;     /* Link count. */
2120     unsigned int  st_uid;       /* User ID of the file's owner. */
2121     unsigned int  st_gid;       /* Group ID of the file's group. */
2122     uint64_t st_rdev;           /* Device number, if device. */
2123     int64_t st_size;            /* Size of file, in bytes. */
2124     abi_ulong st_blksize;       /* Optimal block size for I/O. */
2125     abi_ulong __unused2;
2126     uint64_t st_blocks;         /* Number 512-byte blocks allocated. */
2127     abi_ulong target_st_atime;  /* Time of last access. */
2128     abi_ulong target_st_atime_nsec;
2129     abi_ulong target_st_mtime;  /* Time of last modification. */
2130     abi_ulong target_st_mtime_nsec;
2131     abi_ulong target_st_ctime;  /* Time of last status change. */
2132     abi_ulong target_st_ctime_nsec;
2133     abi_ulong __unused4;
2134     abi_ulong __unused5;
2135 };
2136 
2137 #elif defined(TARGET_OPENRISC) || defined(TARGET_NIOS2) \
2138         || defined(TARGET_RISCV) || defined(TARGET_HEXAGON)
2139 
2140 /* These are the asm-generic versions of the stat and stat64 structures */
2141 
2142 #define TARGET_STAT_HAVE_NSEC
2143 struct target_stat {
2144     abi_ulong st_dev;
2145     abi_ulong st_ino;
2146     unsigned int st_mode;
2147     unsigned int st_nlink;
2148     unsigned int st_uid;
2149     unsigned int st_gid;
2150     abi_ulong st_rdev;
2151     abi_ulong __pad1;
2152     abi_long st_size;
2153     int st_blksize;
2154     int __pad2;
2155     abi_long st_blocks;
2156     abi_long target_st_atime;
2157     abi_ulong target_st_atime_nsec;
2158     abi_long target_st_mtime;
2159     abi_ulong target_st_mtime_nsec;
2160     abi_long target_st_ctime;
2161     abi_ulong target_st_ctime_nsec;
2162     unsigned int __unused4;
2163     unsigned int __unused5;
2164 };
2165 
2166 #if !defined(TARGET_RISCV64)
2167 #define TARGET_HAS_STRUCT_STAT64
2168 struct target_stat64 {
2169     uint64_t st_dev;
2170     uint64_t st_ino;
2171     unsigned int st_mode;
2172     unsigned int st_nlink;
2173     unsigned int st_uid;
2174     unsigned int st_gid;
2175     uint64_t st_rdev;
2176     uint64_t __pad1;
2177     int64_t st_size;
2178     int st_blksize;
2179     int __pad2;
2180     int64_t st_blocks;
2181     int target_st_atime;
2182     unsigned int target_st_atime_nsec;
2183     int target_st_mtime;
2184     unsigned int target_st_mtime_nsec;
2185     int target_st_ctime;
2186     unsigned int target_st_ctime_nsec;
2187     unsigned int __unused4;
2188     unsigned int __unused5;
2189 };
2190 #endif
2191 
2192 #elif defined(TARGET_HPPA)
2193 
2194 #define TARGET_STAT_HAVE_NSEC
2195 struct target_stat {
2196     abi_uint   st_dev;
2197     abi_uint   st_ino;
2198     abi_ushort st_mode;
2199     abi_ushort st_nlink;
2200     abi_ushort _res1;
2201     abi_ushort _res2;
2202     abi_uint   st_rdev;
2203     abi_int    st_size;
2204     abi_int    target_st_atime;
2205     abi_uint   target_st_atime_nsec;
2206     abi_int    target_st_mtime;
2207     abi_uint   target_st_mtime_nsec;
2208     abi_int    target_st_ctime;
2209     abi_uint   target_st_ctime_nsec;
2210     abi_int    st_blksize;
2211     abi_int    st_blocks;
2212     abi_uint   _unused1;
2213     abi_uint   _unused2;
2214     abi_uint   _unused3;
2215     abi_uint   _unused4;
2216     abi_ushort _unused5;
2217     abi_short  st_fstype;
2218     abi_uint   st_realdev;
2219     abi_ushort st_basemode;
2220     abi_ushort _unused6;
2221     abi_uint   st_uid;
2222     abi_uint   st_gid;
2223     abi_uint   _unused7[3];
2224 };
2225 
2226 #define TARGET_HAS_STRUCT_STAT64
2227 struct target_stat64 {
2228     uint64_t   st_dev;
2229     abi_uint   _pad1;
2230     abi_uint   _res1;
2231     abi_uint   st_mode;
2232     abi_uint   st_nlink;
2233     abi_uint   st_uid;
2234     abi_uint   st_gid;
2235     uint64_t   st_rdev;
2236     abi_uint   _pad2;
2237     int64_t    st_size;
2238     abi_int    st_blksize;
2239     int64_t    st_blocks;
2240     abi_int    target_st_atime;
2241     abi_uint   target_st_atime_nsec;
2242     abi_int    target_st_mtime;
2243     abi_uint   target_st_mtime_nsec;
2244     abi_int    target_st_ctime;
2245     abi_uint   target_st_ctime_nsec;
2246     uint64_t   st_ino;
2247 };
2248 
2249 #else
2250 #error unsupported CPU
2251 #endif
2252 
2253 typedef struct {
2254         int     val[2];
2255 } target_fsid_t;
2256 
2257 #ifdef TARGET_MIPS
2258 #ifdef TARGET_ABI_MIPSN32
2259 struct target_statfs {
2260 	int32_t			f_type;
2261 	int32_t			f_bsize;
2262 	int32_t			f_frsize;	/* Fragment size - unsupported */
2263 	int32_t			f_blocks;
2264 	int32_t			f_bfree;
2265 	int32_t			f_files;
2266 	int32_t			f_ffree;
2267 	int32_t			f_bavail;
2268 
2269 	/* Linux specials */
2270 	target_fsid_t		f_fsid;
2271 	int32_t			f_namelen;
2272 	int32_t			f_flags;
2273 	int32_t			f_spare[5];
2274 };
2275 #else
2276 struct target_statfs {
2277 	abi_long		f_type;
2278 	abi_long		f_bsize;
2279 	abi_long		f_frsize;	/* Fragment size - unsupported */
2280 	abi_long		f_blocks;
2281 	abi_long		f_bfree;
2282 	abi_long		f_files;
2283 	abi_long		f_ffree;
2284 	abi_long		f_bavail;
2285 
2286 	/* Linux specials */
2287 	target_fsid_t		f_fsid;
2288 	abi_long		f_namelen;
2289 	abi_long		f_flags;
2290 	abi_long		f_spare[5];
2291 };
2292 #endif
2293 
2294 struct target_statfs64 {
2295 	uint32_t	f_type;
2296 	uint32_t	f_bsize;
2297 	uint32_t	f_frsize;	/* Fragment size - unsupported */
2298 	uint32_t	__pad;
2299 	uint64_t	f_blocks;
2300 	uint64_t	f_bfree;
2301 	uint64_t	f_files;
2302 	uint64_t	f_ffree;
2303 	uint64_t	f_bavail;
2304 	target_fsid_t	f_fsid;
2305 	uint32_t	f_namelen;
2306 	uint32_t	f_flags;
2307 	uint32_t	f_spare[5];
2308 };
2309 #elif (defined(TARGET_PPC64) || defined(TARGET_X86_64) || \
2310        defined(TARGET_SPARC64) || defined(TARGET_AARCH64) || \
2311        defined(TARGET_RISCV)) && !defined(TARGET_ABI32)
2312 struct target_statfs {
2313 	abi_long f_type;
2314 	abi_long f_bsize;
2315 	abi_long f_blocks;
2316 	abi_long f_bfree;
2317 	abi_long f_bavail;
2318 	abi_long f_files;
2319 	abi_long f_ffree;
2320 	target_fsid_t f_fsid;
2321 	abi_long f_namelen;
2322 	abi_long f_frsize;
2323 	abi_long f_flags;
2324 	abi_long f_spare[4];
2325 };
2326 
2327 struct target_statfs64 {
2328 	abi_long f_type;
2329 	abi_long f_bsize;
2330 	abi_long f_blocks;
2331 	abi_long f_bfree;
2332 	abi_long f_bavail;
2333 	abi_long f_files;
2334 	abi_long f_ffree;
2335 	target_fsid_t f_fsid;
2336 	abi_long f_namelen;
2337 	abi_long f_frsize;
2338 	abi_long f_flags;
2339 	abi_long f_spare[4];
2340 };
2341 #elif defined(TARGET_S390X)
2342 struct target_statfs {
2343     int32_t  f_type;
2344     int32_t  f_bsize;
2345     abi_long f_blocks;
2346     abi_long f_bfree;
2347     abi_long f_bavail;
2348     abi_long f_files;
2349     abi_long f_ffree;
2350     kernel_fsid_t f_fsid;
2351     int32_t  f_namelen;
2352     int32_t  f_frsize;
2353     int32_t  f_flags;
2354     int32_t  f_spare[4];
2355 
2356 };
2357 
2358 struct target_statfs64 {
2359     int32_t  f_type;
2360     int32_t  f_bsize;
2361     abi_long f_blocks;
2362     abi_long f_bfree;
2363     abi_long f_bavail;
2364     abi_long f_files;
2365     abi_long f_ffree;
2366     kernel_fsid_t f_fsid;
2367     int32_t  f_namelen;
2368     int32_t  f_frsize;
2369     int32_t  f_flags;
2370     int32_t  f_spare[4];
2371 };
2372 #else
2373 struct target_statfs {
2374 	uint32_t f_type;
2375 	uint32_t f_bsize;
2376 	uint32_t f_blocks;
2377 	uint32_t f_bfree;
2378 	uint32_t f_bavail;
2379 	uint32_t f_files;
2380 	uint32_t f_ffree;
2381 	target_fsid_t f_fsid;
2382 	uint32_t f_namelen;
2383 	uint32_t f_frsize;
2384 	uint32_t f_flags;
2385 	uint32_t f_spare[4];
2386 };
2387 
2388 struct target_statfs64 {
2389 	uint32_t f_type;
2390 	uint32_t f_bsize;
2391 	uint64_t f_blocks;
2392 	uint64_t f_bfree;
2393 	uint64_t f_bavail;
2394 	uint64_t f_files;
2395 	uint64_t f_ffree;
2396 	target_fsid_t f_fsid;
2397         uint32_t f_namelen;
2398 	uint32_t f_frsize;
2399 	uint32_t f_flags;
2400 	uint32_t f_spare[4];
2401 };
2402 #endif
2403 
2404 #define TARGET_F_LINUX_SPECIFIC_BASE 1024
2405 #define TARGET_F_SETLEASE            (TARGET_F_LINUX_SPECIFIC_BASE + 0)
2406 #define TARGET_F_GETLEASE            (TARGET_F_LINUX_SPECIFIC_BASE + 1)
2407 #define TARGET_F_DUPFD_CLOEXEC       (TARGET_F_LINUX_SPECIFIC_BASE + 6)
2408 #define TARGET_F_NOTIFY              (TARGET_F_LINUX_SPECIFIC_BASE + 2)
2409 #define TARGET_F_SETPIPE_SZ          (TARGET_F_LINUX_SPECIFIC_BASE + 7)
2410 #define TARGET_F_GETPIPE_SZ          (TARGET_F_LINUX_SPECIFIC_BASE + 8)
2411 #define TARGET_F_ADD_SEALS           (TARGET_F_LINUX_SPECIFIC_BASE + 9)
2412 #define TARGET_F_GET_SEALS           (TARGET_F_LINUX_SPECIFIC_BASE + 10)
2413 
2414 #include "target_fcntl.h"
2415 
2416 /* soundcard defines */
2417 /* XXX: convert them all to arch independent entries */
2418 #define TARGET_SNDCTL_COPR_HALT           TARGET_IOWR('C',  7, int);
2419 #define TARGET_SNDCTL_COPR_LOAD           0xcfb04301
2420 #define TARGET_SNDCTL_COPR_RCODE          0xc0144303
2421 #define TARGET_SNDCTL_COPR_RCVMSG         0x8fa44309
2422 #define TARGET_SNDCTL_COPR_RDATA          0xc0144302
2423 #define TARGET_SNDCTL_COPR_RESET          0x00004300
2424 #define TARGET_SNDCTL_COPR_RUN            0xc0144306
2425 #define TARGET_SNDCTL_COPR_SENDMSG        0xcfa44308
2426 #define TARGET_SNDCTL_COPR_WCODE          0x40144305
2427 #define TARGET_SNDCTL_COPR_WDATA          0x40144304
2428 #define TARGET_SNDCTL_DSP_RESET           TARGET_IO('P', 0)
2429 #define TARGET_SNDCTL_DSP_SYNC            TARGET_IO('P', 1)
2430 #define TARGET_SNDCTL_DSP_SPEED           TARGET_IOWR('P', 2, int)
2431 #define TARGET_SNDCTL_DSP_STEREO          TARGET_IOWR('P', 3, int)
2432 #define TARGET_SNDCTL_DSP_GETBLKSIZE      TARGET_IOWR('P', 4, int)
2433 #define TARGET_SNDCTL_DSP_SETFMT          TARGET_IOWR('P', 5, int)
2434 #define TARGET_SNDCTL_DSP_CHANNELS        TARGET_IOWR('P', 6, int)
2435 #define TARGET_SOUND_PCM_WRITE_FILTER     TARGET_IOWR('P', 7, int)
2436 #define TARGET_SNDCTL_DSP_POST            TARGET_IO('P', 8)
2437 #define TARGET_SNDCTL_DSP_SUBDIVIDE       TARGET_IOWR('P', 9, int)
2438 #define TARGET_SNDCTL_DSP_SETFRAGMENT     TARGET_IOWR('P',10, int)
2439 #define TARGET_SNDCTL_DSP_GETFMTS         TARGET_IOR('P', 11, int)
2440 #define TARGET_SNDCTL_DSP_GETOSPACE       TARGET_IORU('P',12)
2441 #define TARGET_SNDCTL_DSP_GETISPACE       TARGET_IORU('P',13)
2442 #define TARGET_SNDCTL_DSP_GETCAPS         TARGET_IOR('P', 15, int)
2443 #define TARGET_SNDCTL_DSP_GETTRIGGER      TARGET_IOR('P',16, int)
2444 #define TARGET_SNDCTL_DSP_GETIPTR         TARGET_IORU('P',17)
2445 #define TARGET_SNDCTL_DSP_GETOPTR         TARGET_IORU('P',18)
2446 #define TARGET_SNDCTL_DSP_MAPINBUF        TARGET_IORU('P', 19)
2447 #define TARGET_SNDCTL_DSP_MAPOUTBUF       TARGET_IORU('P', 20)
2448 #define TARGET_SNDCTL_DSP_NONBLOCK        0x0000500e
2449 #define TARGET_SNDCTL_DSP_SAMPLESIZE      0xc0045005
2450 #define TARGET_SNDCTL_DSP_SETDUPLEX       0x00005016
2451 #define TARGET_SNDCTL_DSP_SETSYNCRO       0x00005015
2452 #define TARGET_SNDCTL_DSP_SETTRIGGER      0x40045010
2453 #define TARGET_SNDCTL_FM_4OP_ENABLE       0x4004510f
2454 #define TARGET_SNDCTL_FM_LOAD_INSTR       0x40285107
2455 #define TARGET_SNDCTL_MIDI_INFO           0xc074510c
2456 #define TARGET_SNDCTL_MIDI_MPUCMD         0xc0216d02
2457 #define TARGET_SNDCTL_MIDI_MPUMODE        0xc0046d01
2458 #define TARGET_SNDCTL_MIDI_PRETIME        0xc0046d00
2459 #define TARGET_SNDCTL_PMGR_ACCESS         0xcfb85110
2460 #define TARGET_SNDCTL_PMGR_IFACE          0xcfb85001
2461 #define TARGET_SNDCTL_SEQ_CTRLRATE        0xc0045103
2462 #define TARGET_SNDCTL_SEQ_GETINCOUNT      0x80045105
2463 #define TARGET_SNDCTL_SEQ_GETOUTCOUNT     0x80045104
2464 #define TARGET_SNDCTL_SEQ_NRMIDIS         0x8004510b
2465 #define TARGET_SNDCTL_SEQ_NRSYNTHS        0x8004510a
2466 #define TARGET_SNDCTL_SEQ_OUTOFBAND       0x40085112
2467 #define TARGET_SNDCTL_SEQ_PANIC           0x00005111
2468 #define TARGET_SNDCTL_SEQ_PERCMODE        0x40045106
2469 #define TARGET_SNDCTL_SEQ_RESET           0x00005100
2470 #define TARGET_SNDCTL_SEQ_RESETSAMPLES    0x40045109
2471 #define TARGET_SNDCTL_SEQ_SYNC            0x00005101
2472 #define TARGET_SNDCTL_SEQ_TESTMIDI        0x40045108
2473 #define TARGET_SNDCTL_SEQ_THRESHOLD       0x4004510d
2474 #define TARGET_SNDCTL_SEQ_TRESHOLD        0x4004510d
2475 #define TARGET_SNDCTL_SYNTH_INFO          0xc08c5102
2476 #define TARGET_SNDCTL_SYNTH_MEMAVL        0xc004510e
2477 #define TARGET_SNDCTL_TMR_CONTINUE        0x00005404
2478 #define TARGET_SNDCTL_TMR_METRONOME       0x40045407
2479 #define TARGET_SNDCTL_TMR_SELECT          0x40045408
2480 #define TARGET_SNDCTL_TMR_SOURCE          0xc0045406
2481 #define TARGET_SNDCTL_TMR_START           0x00005402
2482 #define TARGET_SNDCTL_TMR_STOP            0x00005403
2483 #define TARGET_SNDCTL_TMR_TEMPO           0xc0045405
2484 #define TARGET_SNDCTL_TMR_TIMEBASE        0xc0045401
2485 #define TARGET_SOUND_PCM_READ_RATE        0x80045002
2486 #define TARGET_SOUND_PCM_READ_CHANNELS    0x80045006
2487 #define TARGET_SOUND_PCM_READ_BITS        0x80045005
2488 #define TARGET_SOUND_PCM_READ_FILTER      0x80045007
2489 #define TARGET_SOUND_MIXER_INFO           TARGET_IOR ('M', 101, mixer_info)
2490 #define TARGET_SOUND_MIXER_ACCESS         0xc0804d66
2491 #define TARGET_SOUND_MIXER_PRIVATE1       TARGET_IOWR('M', 111, int)
2492 #define TARGET_SOUND_MIXER_PRIVATE2       TARGET_IOWR('M', 112, int)
2493 #define TARGET_SOUND_MIXER_PRIVATE3       TARGET_IOWR('M', 113, int)
2494 #define TARGET_SOUND_MIXER_PRIVATE4       TARGET_IOWR('M', 114, int)
2495 #define TARGET_SOUND_MIXER_PRIVATE5       TARGET_IOWR('M', 115, int)
2496 
2497 #define TARGET_MIXER_READ(dev)	TARGET_IOR('M', dev, int)
2498 
2499 #define TARGET_SOUND_MIXER_READ_VOLUME		TARGET_MIXER_READ(SOUND_MIXER_VOLUME)
2500 #define TARGET_SOUND_MIXER_READ_BASS		TARGET_MIXER_READ(SOUND_MIXER_BASS)
2501 #define TARGET_SOUND_MIXER_READ_TREBLE		TARGET_MIXER_READ(SOUND_MIXER_TREBLE)
2502 #define TARGET_SOUND_MIXER_READ_SYNTH		TARGET_MIXER_READ(SOUND_MIXER_SYNTH)
2503 #define TARGET_SOUND_MIXER_READ_PCM		TARGET_MIXER_READ(SOUND_MIXER_PCM)
2504 #define TARGET_SOUND_MIXER_READ_SPEAKER	        TARGET_MIXER_READ(SOUND_MIXER_SPEAKER)
2505 #define TARGET_SOUND_MIXER_READ_LINE		TARGET_MIXER_READ(SOUND_MIXER_LINE)
2506 #define TARGET_SOUND_MIXER_READ_MIC		TARGET_MIXER_READ(SOUND_MIXER_MIC)
2507 #define TARGET_SOUND_MIXER_READ_CD		TARGET_MIXER_READ(SOUND_MIXER_CD)
2508 #define TARGET_SOUND_MIXER_READ_IMIX		TARGET_MIXER_READ(SOUND_MIXER_IMIX)
2509 #define TARGET_SOUND_MIXER_READ_ALTPCM		TARGET_MIXER_READ(SOUND_MIXER_ALTPCM)
2510 #define TARGET_SOUND_MIXER_READ_RECLEV		TARGET_MIXER_READ(SOUND_MIXER_RECLEV)
2511 #define TARGET_SOUND_MIXER_READ_IGAIN		TARGET_MIXER_READ(SOUND_MIXER_IGAIN)
2512 #define TARGET_SOUND_MIXER_READ_OGAIN		TARGET_MIXER_READ(SOUND_MIXER_OGAIN)
2513 #define TARGET_SOUND_MIXER_READ_LINE1		TARGET_MIXER_READ(SOUND_MIXER_LINE1)
2514 #define TARGET_SOUND_MIXER_READ_LINE2		TARGET_MIXER_READ(SOUND_MIXER_LINE2)
2515 #define TARGET_SOUND_MIXER_READ_LINE3		TARGET_MIXER_READ(SOUND_MIXER_LINE3)
2516 
2517 /* Obsolete macros */
2518 #define TARGET_SOUND_MIXER_READ_MUTE		TARGET_MIXER_READ(SOUND_MIXER_MUTE)
2519 #define TARGET_SOUND_MIXER_READ_ENHANCE	        TARGET_MIXER_READ(SOUND_MIXER_ENHANCE)
2520 #define TARGET_SOUND_MIXER_READ_LOUD		TARGET_MIXER_READ(SOUND_MIXER_LOUD)
2521 
2522 #define TARGET_SOUND_MIXER_READ_RECSRC		TARGET_MIXER_READ(SOUND_MIXER_RECSRC)
2523 #define TARGET_SOUND_MIXER_READ_DEVMASK	        TARGET_MIXER_READ(SOUND_MIXER_DEVMASK)
2524 #define TARGET_SOUND_MIXER_READ_RECMASK	        TARGET_MIXER_READ(SOUND_MIXER_RECMASK)
2525 #define TARGET_SOUND_MIXER_READ_STEREODEVS	TARGET_MIXER_READ(SOUND_MIXER_STEREODEVS)
2526 #define TARGET_SOUND_MIXER_READ_CAPS		TARGET_MIXER_READ(SOUND_MIXER_CAPS)
2527 
2528 #define TARGET_MIXER_WRITE(dev)		TARGET_IOWR('M', dev, int)
2529 
2530 #define TARGET_SOUND_MIXER_WRITE_VOLUME	TARGET_MIXER_WRITE(SOUND_MIXER_VOLUME)
2531 #define TARGET_SOUND_MIXER_WRITE_BASS		TARGET_MIXER_WRITE(SOUND_MIXER_BASS)
2532 #define TARGET_SOUND_MIXER_WRITE_TREBLE	TARGET_MIXER_WRITE(SOUND_MIXER_TREBLE)
2533 #define TARGET_SOUND_MIXER_WRITE_SYNTH		TARGET_MIXER_WRITE(SOUND_MIXER_SYNTH)
2534 #define TARGET_SOUND_MIXER_WRITE_PCM		TARGET_MIXER_WRITE(SOUND_MIXER_PCM)
2535 #define TARGET_SOUND_MIXER_WRITE_SPEAKER	TARGET_MIXER_WRITE(SOUND_MIXER_SPEAKER)
2536 #define TARGET_SOUND_MIXER_WRITE_LINE		TARGET_MIXER_WRITE(SOUND_MIXER_LINE)
2537 #define TARGET_SOUND_MIXER_WRITE_MIC		TARGET_MIXER_WRITE(SOUND_MIXER_MIC)
2538 #define TARGET_SOUND_MIXER_WRITE_CD		TARGET_MIXER_WRITE(SOUND_MIXER_CD)
2539 #define TARGET_SOUND_MIXER_WRITE_IMIX		TARGET_MIXER_WRITE(SOUND_MIXER_IMIX)
2540 #define TARGET_SOUND_MIXER_WRITE_ALTPCM	TARGET_MIXER_WRITE(SOUND_MIXER_ALTPCM)
2541 #define TARGET_SOUND_MIXER_WRITE_RECLEV	TARGET_MIXER_WRITE(SOUND_MIXER_RECLEV)
2542 #define TARGET_SOUND_MIXER_WRITE_IGAIN		TARGET_MIXER_WRITE(SOUND_MIXER_IGAIN)
2543 #define TARGET_SOUND_MIXER_WRITE_OGAIN		TARGET_MIXER_WRITE(SOUND_MIXER_OGAIN)
2544 #define TARGET_SOUND_MIXER_WRITE_LINE1		TARGET_MIXER_WRITE(SOUND_MIXER_LINE1)
2545 #define TARGET_SOUND_MIXER_WRITE_LINE2		TARGET_MIXER_WRITE(SOUND_MIXER_LINE2)
2546 #define TARGET_SOUND_MIXER_WRITE_LINE3		TARGET_MIXER_WRITE(SOUND_MIXER_LINE3)
2547 
2548 /* Obsolete macros */
2549 #define TARGET_SOUND_MIXER_WRITE_MUTE		TARGET_MIXER_WRITE(SOUND_MIXER_MUTE)
2550 #define TARGET_SOUND_MIXER_WRITE_ENHANCE	TARGET_MIXER_WRITE(SOUND_MIXER_ENHANCE)
2551 #define TARGET_SOUND_MIXER_WRITE_LOUD		TARGET_MIXER_WRITE(SOUND_MIXER_LOUD)
2552 
2553 #define TARGET_SOUND_MIXER_WRITE_RECSRC	TARGET_MIXER_WRITE(SOUND_MIXER_RECSRC)
2554 
2555 struct target_snd_timer_id {
2556     int dev_class;
2557     int dev_sclass;
2558     int card;
2559     int device;
2560     int subdevice;
2561 };
2562 
2563 struct target_snd_timer_ginfo {
2564     struct target_snd_timer_id tid;
2565     unsigned int flags;
2566     int card;
2567     unsigned char id[64];
2568     unsigned char name[80];
2569     abi_ulong reserved0;
2570     abi_ulong resolution;
2571     abi_ulong resolution_min;
2572     abi_ulong resolution_max;
2573     unsigned int clients;
2574     unsigned char reserved[32];
2575 };
2576 
2577 struct target_snd_timer_gparams {
2578     struct target_snd_timer_id tid;
2579     abi_ulong period_num;
2580     abi_ulong period_den;
2581     unsigned char reserved[32];
2582 };
2583 
2584 struct target_snd_timer_gstatus {
2585     struct target_snd_timer_id tid;
2586     abi_ulong resolution;
2587     abi_ulong resolution_num;
2588     abi_ulong resolution_den;
2589     unsigned char reserved[32];
2590 };
2591 
2592 struct target_snd_timer_select {
2593     struct target_snd_timer_id id;
2594     unsigned char reserved[32];
2595 };
2596 
2597 struct target_snd_timer_info {
2598     unsigned int flags;
2599     int card;
2600     unsigned char id[64];
2601     unsigned char name[80];
2602     abi_ulong reserved0;
2603     abi_ulong resolution;
2604     unsigned char reserved[64];
2605 };
2606 
2607 struct target_snd_timer_status {
2608     struct target_timespec tstamp;
2609     unsigned int resolution;
2610     unsigned int lost;
2611     unsigned int overrun;
2612     unsigned int queue;
2613     unsigned char reserved[64];
2614 };
2615 
2616 /* alsa timer ioctls */
2617 #define TARGET_SNDRV_TIMER_IOCTL_PVERSION     TARGET_IOR('T', 0x00, int)
2618 #define TARGET_SNDRV_TIMER_IOCTL_NEXT_DEVICE  TARGET_IOWR('T', 0x01,           \
2619                                                 struct snd_timer_id)
2620 #define TARGET_SNDRV_TIMER_IOCTL_GINFO        TARGET_IOWR('T', 0x03,           \
2621                                                 struct target_snd_timer_ginfo)
2622 #define TARGET_SNDRV_TIMER_IOCTL_GPARAMS      TARGET_IOW('T', 0x04,            \
2623                                                 struct target_snd_timer_gparams)
2624 #define TARGET_SNDRV_TIMER_IOCTL_GSTATUS      TARGET_IOWR('T', 0x05,           \
2625                                                 struct target_snd_timer_gstatus)
2626 #define TARGET_SNDRV_TIMER_IOCTL_SELECT       TARGET_IOW('T', 0x10,            \
2627                                                 struct target_snd_timer_select)
2628 #define TARGET_SNDRV_TIMER_IOCTL_INFO         TARGET_IOR('T', 0x11,            \
2629                                                 struct target_snd_timer_info)
2630 #define TARGET_SNDRV_TIMER_IOCTL_PARAMS       TARGET_IOW('T', 0x12,            \
2631                                                 struct snd_timer_params)
2632 #define TARGET_SNDRV_TIMER_IOCTL_STATUS       TARGET_IOR('T', 0x14,            \
2633                                                 struct target_snd_timer_status)
2634 #define TARGET_SNDRV_TIMER_IOCTL_START        TARGET_IO('T', 0xa0)
2635 #define TARGET_SNDRV_TIMER_IOCTL_STOP         TARGET_IO('T', 0xa1)
2636 #define TARGET_SNDRV_TIMER_IOCTL_CONTINUE     TARGET_IO('T', 0xa2)
2637 #define TARGET_SNDRV_TIMER_IOCTL_PAUSE        TARGET_IO('T', 0xa3)
2638 
2639 /* vfat ioctls */
2640 #define TARGET_VFAT_IOCTL_READDIR_BOTH    TARGET_IORU('r', 1)
2641 #define TARGET_VFAT_IOCTL_READDIR_SHORT   TARGET_IORU('r', 2)
2642 
2643 struct target_mtop {
2644     abi_short mt_op;
2645     abi_int mt_count;
2646 };
2647 
2648 #if defined(TARGET_SPARC) || defined(TARGET_MIPS)
2649 typedef abi_long target_kernel_daddr_t;
2650 #else
2651 typedef abi_int target_kernel_daddr_t;
2652 #endif
2653 
2654 struct target_mtget {
2655     abi_long mt_type;
2656     abi_long mt_resid;
2657     abi_long mt_dsreg;
2658     abi_long mt_gstat;
2659     abi_long mt_erreg;
2660     target_kernel_daddr_t mt_fileno;
2661     target_kernel_daddr_t mt_blkno;
2662 };
2663 
2664 struct target_mtpos {
2665     abi_long mt_blkno;
2666 };
2667 
2668 #define TARGET_MTIOCTOP        TARGET_IOW('m', 1, struct target_mtop)
2669 #define TARGET_MTIOCGET        TARGET_IOR('m', 2, struct target_mtget)
2670 #define TARGET_MTIOCPOS        TARGET_IOR('m', 3, struct target_mtpos)
2671 
2672 /* kcov ioctls */
2673 #define TARGET_KCOV_ENABLE     TARGET_IO('c', 100)
2674 #define TARGET_KCOV_DISABLE    TARGET_IO('c', 101)
2675 #define TARGET_KCOV_INIT_TRACE TARGET_IOR('c', 1, abi_ulong)
2676 
2677 struct target_sysinfo {
2678     abi_long uptime;                /* Seconds since boot */
2679     abi_ulong loads[3];             /* 1, 5, and 15 minute load averages */
2680     abi_ulong totalram;             /* Total usable main memory size */
2681     abi_ulong freeram;              /* Available memory size */
2682     abi_ulong sharedram;            /* Amount of shared memory */
2683     abi_ulong bufferram;            /* Memory used by buffers */
2684     abi_ulong totalswap;            /* Total swap space size */
2685     abi_ulong freeswap;             /* swap space still available */
2686     unsigned short procs;           /* Number of current processes */
2687     unsigned short pad;             /* explicit padding for m68k */
2688     abi_ulong totalhigh;            /* Total high memory size */
2689     abi_ulong freehigh;             /* Available high memory size */
2690     unsigned int mem_unit;          /* Memory unit size in bytes */
2691     char _f[20-2*sizeof(abi_long)-sizeof(int)]; /* Padding: libc5 uses this.. */
2692 };
2693 
2694 struct linux_dirent {
2695     long            d_ino;
2696     unsigned long   d_off;
2697     unsigned short  d_reclen;
2698     char            d_name[];
2699 };
2700 
2701 struct linux_dirent64 {
2702     uint64_t        d_ino;
2703     int64_t         d_off;
2704     unsigned short  d_reclen;
2705     unsigned char   d_type;
2706     char            d_name[];
2707 };
2708 
2709 struct target_mq_attr {
2710     abi_long mq_flags;
2711     abi_long mq_maxmsg;
2712     abi_long mq_msgsize;
2713     abi_long mq_curmsgs;
2714 };
2715 
2716 struct target_drm_version {
2717     int version_major;
2718     int version_minor;
2719     int version_patchlevel;
2720     abi_ulong name_len;
2721     abi_ulong name;
2722     abi_ulong date_len;
2723     abi_ulong date;
2724     abi_ulong desc_len;
2725     abi_ulong desc;
2726 };
2727 
2728 struct target_drm_i915_getparam {
2729     int param;
2730     abi_ulong value;
2731 };
2732 
2733 #include "socket.h"
2734 
2735 #include "target_errno_defs.h"
2736 
2737 #define FUTEX_WAIT              0
2738 #define FUTEX_WAKE              1
2739 #define FUTEX_FD                2
2740 #define FUTEX_REQUEUE           3
2741 #define FUTEX_CMP_REQUEUE       4
2742 #define FUTEX_WAKE_OP           5
2743 #define FUTEX_LOCK_PI           6
2744 #define FUTEX_UNLOCK_PI         7
2745 #define FUTEX_TRYLOCK_PI        8
2746 #define FUTEX_WAIT_BITSET       9
2747 #define FUTEX_WAKE_BITSET       10
2748 
2749 #define FUTEX_PRIVATE_FLAG      128
2750 #define FUTEX_CLOCK_REALTIME    256
2751 #define FUTEX_CMD_MASK          ~(FUTEX_PRIVATE_FLAG | FUTEX_CLOCK_REALTIME)
2752 
2753 #ifdef CONFIG_EPOLL
2754 #if defined(TARGET_X86_64)
2755 #define TARGET_EPOLL_PACKED QEMU_PACKED
2756 #else
2757 #define TARGET_EPOLL_PACKED
2758 #endif
2759 
2760 typedef union target_epoll_data {
2761     abi_ulong ptr;
2762     abi_int fd;
2763     abi_uint u32;
2764     abi_ullong u64;
2765 } target_epoll_data_t;
2766 
2767 struct target_epoll_event {
2768     abi_uint events;
2769     target_epoll_data_t data;
2770 } TARGET_EPOLL_PACKED;
2771 
2772 #define TARGET_EP_MAX_EVENTS (INT_MAX / sizeof(struct target_epoll_event))
2773 
2774 #endif
2775 struct target_rlimit64 {
2776     uint64_t rlim_cur;
2777     uint64_t rlim_max;
2778 };
2779 
2780 struct target_ucred {
2781     uint32_t pid;
2782     uint32_t uid;
2783     uint32_t gid;
2784 };
2785 
2786 typedef int32_t target_timer_t;
2787 
2788 #define TARGET_SIGEV_MAX_SIZE 64
2789 
2790 /* This is architecture-specific but most architectures use the default */
2791 #ifdef TARGET_MIPS
2792 #define TARGET_SIGEV_PREAMBLE_SIZE (sizeof(int32_t) * 2 + sizeof(abi_long))
2793 #else
2794 #define TARGET_SIGEV_PREAMBLE_SIZE (sizeof(int32_t) * 2 \
2795                                     + sizeof(target_sigval_t))
2796 #endif
2797 
2798 #define TARGET_SIGEV_PAD_SIZE ((TARGET_SIGEV_MAX_SIZE \
2799                                 - TARGET_SIGEV_PREAMBLE_SIZE) \
2800                                / sizeof(int32_t))
2801 
2802 struct target_sigevent {
2803     target_sigval_t sigev_value;
2804     abi_int sigev_signo;
2805     abi_int sigev_notify;
2806     union {
2807         abi_int _pad[TARGET_SIGEV_PAD_SIZE];
2808         abi_int _tid;
2809 
2810         /* The kernel (and thus QEMU) never looks at these;
2811          * they're only used as part of the ABI between a
2812          * userspace program and libc.
2813          */
2814         struct {
2815             abi_ulong _function;
2816             abi_ulong _attribute;
2817         } _sigev_thread;
2818     } _sigev_un;
2819 };
2820 
2821 struct target_user_cap_header {
2822     uint32_t version;
2823     int pid;
2824 };
2825 
2826 struct target_user_cap_data {
2827     uint32_t effective;
2828     uint32_t permitted;
2829     uint32_t inheritable;
2830 };
2831 
2832 /* from kernel's include/linux/syslog.h */
2833 
2834 /* Close the log.  Currently a NOP. */
2835 #define TARGET_SYSLOG_ACTION_CLOSE          0
2836 /* Open the log. Currently a NOP. */
2837 #define TARGET_SYSLOG_ACTION_OPEN           1
2838 /* Read from the log. */
2839 #define TARGET_SYSLOG_ACTION_READ           2
2840 /* Read all messages remaining in the ring buffer. */
2841 #define TARGET_SYSLOG_ACTION_READ_ALL       3
2842 /* Read and clear all messages remaining in the ring buffer */
2843 #define TARGET_SYSLOG_ACTION_READ_CLEAR     4
2844 /* Clear ring buffer. */
2845 #define TARGET_SYSLOG_ACTION_CLEAR          5
2846 /* Disable printk's to console */
2847 #define TARGET_SYSLOG_ACTION_CONSOLE_OFF    6
2848 /* Enable printk's to console */
2849 #define TARGET_SYSLOG_ACTION_CONSOLE_ON     7
2850 /* Set level of messages printed to console */
2851 #define TARGET_SYSLOG_ACTION_CONSOLE_LEVEL  8
2852 /* Return number of unread characters in the log buffer */
2853 #define TARGET_SYSLOG_ACTION_SIZE_UNREAD    9
2854 /* Return size of the log buffer */
2855 #define TARGET_SYSLOG_ACTION_SIZE_BUFFER   10
2856 
2857 struct target_statx_timestamp {
2858    int64_t tv_sec;
2859    uint32_t tv_nsec;
2860    int32_t __reserved;
2861 };
2862 
2863 struct target_statx {
2864    /* 0x00 */
2865    uint32_t stx_mask;       /* What results were written [uncond] */
2866    uint32_t stx_blksize;    /* Preferred general I/O size [uncond] */
2867    uint64_t stx_attributes; /* Flags conveying information about the file */
2868    /* 0x10 */
2869    uint32_t stx_nlink;      /* Number of hard links */
2870    uint32_t stx_uid;        /* User ID of owner */
2871    uint32_t stx_gid;        /* Group ID of owner */
2872    uint16_t stx_mode;       /* File mode */
2873    uint16_t __spare0[1];
2874    /* 0x20 */
2875    uint64_t stx_ino;        /* Inode number */
2876    uint64_t stx_size;       /* File size */
2877    uint64_t stx_blocks;     /* Number of 512-byte blocks allocated */
2878    uint64_t stx_attributes_mask; /* Mask to show what is supported */
2879    /* 0x40 */
2880    struct target_statx_timestamp  stx_atime;  /* Last access time */
2881    struct target_statx_timestamp  stx_btime;  /* File creation time */
2882    struct target_statx_timestamp  stx_ctime;  /* Last attribute change time */
2883    struct target_statx_timestamp  stx_mtime;  /* Last data modification time */
2884    /* 0x80 */
2885    uint32_t stx_rdev_major;   /* Device ID of special file [if bdev/cdev] */
2886    uint32_t stx_rdev_minor;
2887    uint32_t stx_dev_major; /* ID of device containing file [uncond] */
2888    uint32_t stx_dev_minor;
2889    /* 0x90 */
2890    uint64_t __spare2[14];  /* Spare space for future expansion */
2891    /* 0x100 */
2892 };
2893 
2894 /* from kernel's include/linux/sched/types.h */
2895 struct target_sched_attr {
2896     abi_uint size;
2897     abi_uint sched_policy;
2898     abi_ullong sched_flags;
2899     abi_int sched_nice;
2900     abi_uint sched_priority;
2901     abi_ullong sched_runtime;
2902     abi_ullong sched_deadline;
2903     abi_ullong sched_period;
2904     abi_uint sched_util_min;
2905     abi_uint sched_util_max;
2906 };
2907 
2908 struct target_sched_param {
2909     abi_int sched_priority;
2910 };
2911 
2912 #endif
2913