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