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