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