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