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 puting ifdefs if
5    necessary */
6 
7 #include "syscall_nr.h"
8 
9 #define SOCKOP_socket           1
10 #define SOCKOP_bind             2
11 #define SOCKOP_connect          3
12 #define SOCKOP_listen           4
13 #define SOCKOP_accept           5
14 #define SOCKOP_getsockname      6
15 #define SOCKOP_getpeername      7
16 #define SOCKOP_socketpair       8
17 #define SOCKOP_send             9
18 #define SOCKOP_recv             10
19 #define SOCKOP_sendto           11
20 #define SOCKOP_recvfrom         12
21 #define SOCKOP_shutdown         13
22 #define SOCKOP_setsockopt       14
23 #define SOCKOP_getsockopt       15
24 #define SOCKOP_sendmsg          16
25 #define SOCKOP_recvmsg          17
26 
27 #define IPCOP_semop		1
28 #define IPCOP_semget		2
29 #define IPCOP_semctl		3
30 #define IPCOP_semtimedop	4
31 #define IPCOP_msgsnd		11
32 #define IPCOP_msgrcv		12
33 #define IPCOP_msgget		13
34 #define IPCOP_msgctl		14
35 #define IPCOP_shmat		21
36 #define IPCOP_shmdt		22
37 #define IPCOP_shmget		23
38 #define IPCOP_shmctl		24
39 
40 /*
41  * The following is for compatibility across the various Linux
42  * platforms.  The i386 ioctl numbering scheme doesn't really enforce
43  * a type field.  De facto, however, the top 8 bits of the lower 16
44  * bits are indeed used as a type field, so we might just as well make
45  * this explicit here.  Please be sure to use the decoding macros
46  * below from now on.
47  */
48 #define TARGET_IOC_NRBITS	8
49 #define TARGET_IOC_TYPEBITS	8
50 
51 #if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_SPARC) \
52     || defined(TARGET_M68K) || defined(TARGET_SH4) || defined(TARGET_CRIS) || defined(TARGET_PPC) || defined(TARGET_MIPS)
53     /* 16 bit uid wrappers emulation */
54 #define USE_UID16
55 #endif
56 
57 #if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_SH4) \
58     || defined(TARGET_M68K) || defined(TARGET_CRIS)
59 
60 #define TARGET_IOC_SIZEBITS	14
61 #define TARGET_IOC_DIRBITS	2
62 
63 #define TARGET_IOC_NONE	  0U
64 #define TARGET_IOC_WRITE  1U
65 #define TARGET_IOC_READ	  2U
66 
67 #elif defined(TARGET_PPC) || defined(TARGET_ALPHA) || \
68       defined(TARGET_SPARC) || defined(TARGET_MICROBLAZE) || \
69       defined(TARGET_MIPS)
70 
71 #define TARGET_IOC_SIZEBITS	13
72 #define TARGET_IOC_DIRBITS	3
73 
74 #define TARGET_IOC_NONE	  1U
75 #define TARGET_IOC_READ	  2U
76 #define TARGET_IOC_WRITE  4U
77 
78 #else
79 #error unsupported CPU
80 #endif
81 
82 #define TARGET_IOC_NRMASK	((1 << TARGET_IOC_NRBITS)-1)
83 #define TARGET_IOC_TYPEMASK	((1 << TARGET_IOC_TYPEBITS)-1)
84 #define TARGET_IOC_SIZEMASK	((1 << TARGET_IOC_SIZEBITS)-1)
85 #define TARGET_IOC_DIRMASK	((1 << TARGET_IOC_DIRBITS)-1)
86 
87 #define TARGET_IOC_NRSHIFT	0
88 #define TARGET_IOC_TYPESHIFT	(TARGET_IOC_NRSHIFT+TARGET_IOC_NRBITS)
89 #define TARGET_IOC_SIZESHIFT	(TARGET_IOC_TYPESHIFT+TARGET_IOC_TYPEBITS)
90 #define TARGET_IOC_DIRSHIFT	(TARGET_IOC_SIZESHIFT+TARGET_IOC_SIZEBITS)
91 
92 #define TARGET_IOC(dir,type,nr,size) \
93 	(((dir)  << TARGET_IOC_DIRSHIFT) | \
94 	 ((type) << TARGET_IOC_TYPESHIFT) | \
95 	 ((nr)   << TARGET_IOC_NRSHIFT) | \
96 	 ((size) << TARGET_IOC_SIZESHIFT))
97 
98 /* used to create numbers */
99 #define TARGET_IO(type,nr)		TARGET_IOC(TARGET_IOC_NONE,(type),(nr),0)
100 #define TARGET_IOR(type,nr,size)	TARGET_IOC(TARGET_IOC_READ,(type),(nr),sizeof(size))
101 #define TARGET_IOW(type,nr,size)	TARGET_IOC(TARGET_IOC_WRITE,(type),(nr),sizeof(size))
102 #define TARGET_IOWR(type,nr,size)	TARGET_IOC(TARGET_IOC_READ|TARGET_IOC_WRITE,(type),(nr),sizeof(size))
103 
104 /* the size is automatically computed for these defines */
105 #define TARGET_IORU(type,nr)	TARGET_IOC(TARGET_IOC_READ,(type),(nr),TARGET_IOC_SIZEMASK)
106 #define TARGET_IOWU(type,nr)	TARGET_IOC(TARGET_IOC_WRITE,(type),(nr),TARGET_IOC_SIZEMASK)
107 #define TARGET_IOWRU(type,nr)	TARGET_IOC(TARGET_IOC_READ|TARGET_IOC_WRITE,(type),(nr),TARGET_IOC_SIZEMASK)
108 
109 struct target_sockaddr {
110     uint16_t sa_family;
111     uint8_t sa_data[14];
112 };
113 
114 struct target_in_addr {
115     uint32_t s_addr; /* big endian */
116 };
117 
118 struct target_ip_mreq {
119     struct target_in_addr imr_multiaddr;
120     struct target_in_addr imr_address;
121 };
122 
123 struct target_ip_mreqn {
124     struct target_in_addr imr_multiaddr;
125     struct target_in_addr imr_address;
126     abi_long imr_ifindex;
127 };
128 
129 struct target_ip_mreq_source {
130     /* big endian */
131     uint32_t imr_multiaddr;
132     uint32_t imr_interface;
133     uint32_t imr_sourceaddr;
134 };
135 
136 struct target_timeval {
137     abi_long tv_sec;
138     abi_long tv_usec;
139 };
140 
141 struct target_timespec {
142     abi_long tv_sec;
143     abi_long tv_nsec;
144 };
145 
146 struct target_itimerval {
147     struct target_timeval it_interval;
148     struct target_timeval it_value;
149 };
150 
151 typedef abi_long target_clock_t;
152 
153 #define TARGET_HZ 100
154 
155 struct target_tms {
156     target_clock_t tms_utime;
157     target_clock_t tms_stime;
158     target_clock_t tms_cutime;
159     target_clock_t tms_cstime;
160 };
161 
162 struct target_utimbuf {
163     abi_long actime;
164     abi_long modtime;
165 };
166 
167 struct target_sel_arg_struct {
168     abi_long n;
169     abi_long inp, outp, exp;
170     abi_long tvp;
171 };
172 
173 struct target_iovec {
174     abi_long iov_base;   /* Starting address */
175     abi_long iov_len;   /* Number of bytes */
176 };
177 
178 struct target_msghdr {
179     abi_long	 msg_name;	 /* Socket name			*/
180     int		 msg_namelen;	 /* Length of name		*/
181     abi_long	 msg_iov;	 /* Data blocks			*/
182     abi_long	 msg_iovlen;	 /* Number of blocks		*/
183     abi_long     msg_control;	 /* Per protocol magic (eg BSD file descriptor passing) */
184     abi_long	 msg_controllen; /* Length of cmsg list */
185     unsigned int msg_flags;
186 };
187 
188 struct target_cmsghdr {
189     abi_long     cmsg_len;
190     int          cmsg_level;
191     int          cmsg_type;
192 };
193 
194 #define TARGET_CMSG_DATA(cmsg) ((unsigned char *) ((struct target_cmsghdr *) (cmsg) + 1))
195 #define TARGET_CMSG_NXTHDR(mhdr, cmsg) __target_cmsg_nxthdr (mhdr, cmsg)
196 #define TARGET_CMSG_ALIGN(len) (((len) + sizeof (abi_long) - 1) \
197                                & (size_t) ~(sizeof (abi_long) - 1))
198 #define TARGET_CMSG_SPACE(len) (TARGET_CMSG_ALIGN (len) \
199                                + TARGET_CMSG_ALIGN (sizeof (struct target_cmsghdr)))
200 #define TARGET_CMSG_LEN(len)   (TARGET_CMSG_ALIGN (sizeof (struct target_cmsghdr)) + (len))
201 
202 static __inline__ struct target_cmsghdr *
__target_cmsg_nxthdr(struct target_msghdr * __mhdr,struct target_cmsghdr * __cmsg)203 __target_cmsg_nxthdr (struct target_msghdr *__mhdr, struct target_cmsghdr *__cmsg)
204 {
205   struct target_cmsghdr *__ptr;
206 
207   __ptr = (struct target_cmsghdr *)((unsigned char *) __cmsg
208                                     + TARGET_CMSG_ALIGN (tswapl(__cmsg->cmsg_len)));
209   if ((unsigned long)((char *)(__ptr+1) - (char *)(size_t)tswapl(__mhdr->msg_control))
210       > tswapl(__mhdr->msg_controllen))
211     /* No more entries.  */
212     return (struct target_cmsghdr *)0;
213   return __cmsg;
214 }
215 
216 
217 struct  target_rusage {
218         struct target_timeval ru_utime;        /* user time used */
219         struct target_timeval ru_stime;        /* system time used */
220         abi_long    ru_maxrss;                 /* maximum resident set size */
221         abi_long    ru_ixrss;                  /* integral shared memory size */
222         abi_long    ru_idrss;                  /* integral unshared data size */
223         abi_long    ru_isrss;                  /* integral unshared stack size */
224         abi_long    ru_minflt;                 /* page reclaims */
225         abi_long    ru_majflt;                 /* page faults */
226         abi_long    ru_nswap;                  /* swaps */
227         abi_long    ru_inblock;                /* block input operations */
228         abi_long    ru_oublock;                /* block output operations */
229         abi_long    ru_msgsnd;                 /* messages sent */
230         abi_long    ru_msgrcv;                 /* messages received */
231         abi_long    ru_nsignals;               /* signals received */
232         abi_long    ru_nvcsw;                  /* voluntary context switches */
233         abi_long    ru_nivcsw;                 /* involuntary " */
234 };
235 
236 typedef struct {
237         int     val[2];
238 } kernel_fsid_t;
239 
240 struct kernel_statfs {
241 	int f_type;
242 	int f_bsize;
243 	int f_blocks;
244 	int f_bfree;
245 	int f_bavail;
246 	int f_files;
247 	int f_ffree;
248         kernel_fsid_t f_fsid;
249 	int f_namelen;
250 	int f_spare[6];
251 };
252 
253 struct target_dirent {
254 	abi_long	d_ino;
255 	abi_long	d_off;
256 	unsigned short	d_reclen;
257 	char		d_name[256]; /* We must not include limits.h! */
258 };
259 
260 struct target_dirent64 {
261 	uint64_t	d_ino;
262 	int64_t		d_off;
263 	unsigned short	d_reclen;
264 	unsigned char	d_type;
265 	char		d_name[256];
266 };
267 
268 
269 /* mostly generic signal stuff */
270 #define TARGET_SIG_DFL	((abi_long)0)	/* default signal handling */
271 #define TARGET_SIG_IGN	((abi_long)1)	/* ignore signal */
272 #define TARGET_SIG_ERR	((abi_long)-1)	/* error return from signal */
273 
274 #ifdef TARGET_MIPS
275 #define TARGET_NSIG	   128
276 #else
277 #define TARGET_NSIG	   64
278 #endif
279 #define TARGET_NSIG_BPW	   TARGET_ABI_BITS
280 #define TARGET_NSIG_WORDS  (TARGET_NSIG / TARGET_NSIG_BPW)
281 
282 typedef struct {
283     abi_ulong sig[TARGET_NSIG_WORDS];
284 } target_sigset_t;
285 
286 #ifdef BSWAP_NEEDED
tswap_sigset(target_sigset_t * d,const target_sigset_t * s)287 static inline void tswap_sigset(target_sigset_t *d, const target_sigset_t *s)
288 {
289     int i;
290     for(i = 0;i < TARGET_NSIG_WORDS; i++)
291         d->sig[i] = tswapl(s->sig[i]);
292 }
293 #else
tswap_sigset(target_sigset_t * d,const target_sigset_t * s)294 static inline void tswap_sigset(target_sigset_t *d, const target_sigset_t *s)
295 {
296     *d = *s;
297 }
298 #endif
299 
target_siginitset(target_sigset_t * d,abi_ulong set)300 static inline void target_siginitset(target_sigset_t *d, abi_ulong set)
301 {
302     int i;
303     d->sig[0] = set;
304     for(i = 1;i < TARGET_NSIG_WORDS; i++)
305         d->sig[i] = 0;
306 }
307 
308 void host_to_target_sigset(target_sigset_t *d, const sigset_t *s);
309 void target_to_host_sigset(sigset_t *d, const target_sigset_t *s);
310 void host_to_target_old_sigset(abi_ulong *old_sigset,
311                                const sigset_t *sigset);
312 void target_to_host_old_sigset(sigset_t *sigset,
313                                const abi_ulong *old_sigset);
314 struct target_sigaction;
315 int do_sigaction(int sig, const struct target_sigaction *act,
316                  struct target_sigaction *oact);
317 
318 #if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_SPARC) || defined(TARGET_PPC) || defined(TARGET_MIPS) || defined (TARGET_SH4) || defined(TARGET_M68K) || defined(TARGET_ALPHA) || defined(TARGET_CRIS) || defined(TARGET_MICROBLAZE)
319 
320 #if defined(TARGET_SPARC)
321 #define TARGET_SA_NOCLDSTOP    8u
322 #define TARGET_SA_NOCLDWAIT    0x100u
323 #define TARGET_SA_SIGINFO      0x200u
324 #define TARGET_SA_ONSTACK      1u
325 #define TARGET_SA_RESTART      2u
326 #define TARGET_SA_NODEFER      0x20u
327 #define TARGET_SA_RESETHAND    4u
328 #elif defined(TARGET_MIPS)
329 #define TARGET_SA_NOCLDSTOP	0x00000001
330 #define TARGET_SA_NOCLDWAIT	0x00010000
331 #define TARGET_SA_SIGINFO	0x00000008
332 #define TARGET_SA_ONSTACK	0x08000000
333 #define TARGET_SA_NODEFER	0x40000000
334 #define TARGET_SA_RESTART	0x10000000
335 #define TARGET_SA_RESETHAND	0x80000000
336 #if !defined(TARGET_ABI_MIPSN32) && !defined(TARGET_ABI_MIPSN64)
337 #define TARGET_SA_RESTORER	0x04000000	/* Only for O32 */
338 #endif
339 #elif defined(TARGET_ALPHA)
340 #define TARGET_SA_ONSTACK	0x00000001
341 #define TARGET_SA_RESTART	0x00000002
342 #define TARGET_SA_NOCLDSTOP	0x00000004
343 #define TARGET_SA_NODEFER	0x00000008
344 #define TARGET_SA_RESETHAND	0x00000010
345 #define TARGET_SA_NOCLDWAIT	0x00000020 /* not supported yet */
346 #define TARGET_SA_SIGINFO	0x00000040
347 #else
348 #define TARGET_SA_NOCLDSTOP	0x00000001
349 #define TARGET_SA_NOCLDWAIT	0x00000002 /* not supported yet */
350 #define TARGET_SA_SIGINFO	0x00000004
351 #define TARGET_SA_ONSTACK	0x08000000
352 #define TARGET_SA_RESTART	0x10000000
353 #define TARGET_SA_NODEFER	0x40000000
354 #define TARGET_SA_RESETHAND	0x80000000
355 #define TARGET_SA_RESTORER	0x04000000
356 #endif
357 
358 #if defined(TARGET_SPARC)
359 
360 #define TARGET_SIGHUP		 1
361 #define TARGET_SIGINT		 2
362 #define TARGET_SIGQUIT		 3
363 #define TARGET_SIGILL		 4
364 #define TARGET_SIGTRAP		 5
365 #define TARGET_SIGABRT		 6
366 #define TARGET_SIGIOT		 6
367 #define TARGET_SIGSTKFLT	 7 /* actually EMT */
368 #define TARGET_SIGFPE		 8
369 #define TARGET_SIGKILL		 9
370 #define TARGET_SIGBUS		10
371 #define TARGET_SIGSEGV		11
372 #define TARGET_SIGSYS		12
373 #define TARGET_SIGPIPE		13
374 #define TARGET_SIGALRM		14
375 #define TARGET_SIGTERM		15
376 #define TARGET_SIGURG		16
377 #define TARGET_SIGSTOP		17
378 #define TARGET_SIGTSTP		18
379 #define TARGET_SIGCONT		19
380 #define TARGET_SIGCHLD		20
381 #define TARGET_SIGTTIN		21
382 #define TARGET_SIGTTOU		22
383 #define TARGET_SIGIO		23
384 #define TARGET_SIGXCPU		24
385 #define TARGET_SIGXFSZ		25
386 #define TARGET_SIGVTALRM	26
387 #define TARGET_SIGPROF		27
388 #define TARGET_SIGWINCH	        28
389 #define TARGET_SIGPWR		29
390 #define TARGET_SIGUSR1		30
391 #define TARGET_SIGUSR2		31
392 #define TARGET_SIGRTMIN         32
393 
394 #define TARGET_SIG_BLOCK          0x01 /* for blocking signals */
395 #define TARGET_SIG_UNBLOCK        0x02 /* for unblocking signals */
396 #define TARGET_SIG_SETMASK        0x04 /* for setting the signal mask */
397 
398 #elif defined(TARGET_MIPS)
399 
400 #define TARGET_SIGHUP		 1	/* Hangup (POSIX).  */
401 #define TARGET_SIGINT		 2	/* Interrupt (ANSI).  */
402 #define TARGET_SIGQUIT		 3	/* Quit (POSIX).  */
403 #define TARGET_SIGILL		 4	/* Illegal instruction (ANSI).  */
404 #define TARGET_SIGTRAP		 5	/* Trace trap (POSIX).  */
405 #define TARGET_SIGIOT		 6	/* IOT trap (4.2 BSD).  */
406 #define TARGET_SIGABRT		 TARGET_SIGIOT	/* Abort (ANSI).  */
407 #define TARGET_SIGEMT		 7
408 #define TARGET_SIGSTKFLT	 7 /* XXX: incorrect */
409 #define TARGET_SIGFPE		 8	/* Floating-point exception (ANSI).  */
410 #define TARGET_SIGKILL		 9	/* Kill, unblockable (POSIX).  */
411 #define TARGET_SIGBUS		10	/* BUS error (4.2 BSD).  */
412 #define TARGET_SIGSEGV		11	/* Segmentation violation (ANSI).  */
413 #define TARGET_SIGSYS		12
414 #define TARGET_SIGPIPE		13	/* Broken pipe (POSIX).  */
415 #define TARGET_SIGALRM		14	/* Alarm clock (POSIX).  */
416 #define TARGET_SIGTERM		15	/* Termination (ANSI).  */
417 #define TARGET_SIGUSR1		16	/* User-defined signal 1 (POSIX).  */
418 #define TARGET_SIGUSR2		17	/* User-defined signal 2 (POSIX).  */
419 #define TARGET_SIGCHLD		18	/* Child status has changed (POSIX).  */
420 #define TARGET_SIGCLD		TARGET_SIGCHLD	/* Same as TARGET_SIGCHLD (System V).  */
421 #define TARGET_SIGPWR		19	/* Power failure restart (System V).  */
422 #define TARGET_SIGWINCH	20	/* Window size change (4.3 BSD, Sun).  */
423 #define TARGET_SIGURG		21	/* Urgent condition on socket (4.2 BSD).  */
424 #define TARGET_SIGIO		22	/* I/O now possible (4.2 BSD).  */
425 #define TARGET_SIGPOLL		TARGET_SIGIO	/* Pollable event occurred (System V).  */
426 #define TARGET_SIGSTOP		23	/* Stop, unblockable (POSIX).  */
427 #define TARGET_SIGTSTP		24	/* Keyboard stop (POSIX).  */
428 #define TARGET_SIGCONT		25	/* Continue (POSIX).  */
429 #define TARGET_SIGTTIN		26	/* Background read from tty (POSIX).  */
430 #define TARGET_SIGTTOU		27	/* Background write to tty (POSIX).  */
431 #define TARGET_SIGVTALRM	28	/* Virtual alarm clock (4.2 BSD).  */
432 #define TARGET_SIGPROF		29	/* Profiling alarm clock (4.2 BSD).  */
433 #define TARGET_SIGXCPU		30	/* CPU limit exceeded (4.2 BSD).  */
434 #define TARGET_SIGXFSZ		31	/* File size limit exceeded (4.2 BSD).  */
435 #define TARGET_SIGRTMIN         32
436 
437 #define TARGET_SIG_BLOCK	1	/* for blocking signals */
438 #define TARGET_SIG_UNBLOCK	2	/* for unblocking signals */
439 #define TARGET_SIG_SETMASK	3	/* for setting the signal mask */
440 
441 #else
442 
443 #define TARGET_SIGHUP		 1
444 #define TARGET_SIGINT		 2
445 #define TARGET_SIGQUIT		 3
446 #define TARGET_SIGILL		 4
447 #define TARGET_SIGTRAP		 5
448 #define TARGET_SIGABRT		 6
449 #define TARGET_SIGIOT		 6
450 #define TARGET_SIGBUS		 7
451 #define TARGET_SIGFPE		 8
452 #define TARGET_SIGKILL		 9
453 #define TARGET_SIGUSR1		10
454 #define TARGET_SIGSEGV		11
455 #define TARGET_SIGUSR2		12
456 #define TARGET_SIGPIPE		13
457 #define TARGET_SIGALRM		14
458 #define TARGET_SIGTERM		15
459 #define TARGET_SIGSTKFLT	16
460 #define TARGET_SIGCHLD		17
461 #define TARGET_SIGCONT		18
462 #define TARGET_SIGSTOP		19
463 #define TARGET_SIGTSTP		20
464 #define TARGET_SIGTTIN		21
465 #define TARGET_SIGTTOU		22
466 #define TARGET_SIGURG		23
467 #define TARGET_SIGXCPU		24
468 #define TARGET_SIGXFSZ		25
469 #define TARGET_SIGVTALRM	26
470 #define TARGET_SIGPROF		27
471 #define TARGET_SIGWINCH	        28
472 #define TARGET_SIGIO		29
473 #define TARGET_SIGPWR		30
474 #define TARGET_SIGSYS		31
475 #define TARGET_SIGRTMIN         32
476 
477 #define TARGET_SIG_BLOCK          0    /* for blocking signals */
478 #define TARGET_SIG_UNBLOCK        1    /* for unblocking signals */
479 #define TARGET_SIG_SETMASK        2    /* for setting the signal mask */
480 
481 #endif
482 
483 #if defined(TARGET_ALPHA)
484 struct target_old_sigaction {
485     abi_ulong _sa_handler;
486     abi_ulong sa_mask;
487     abi_ulong sa_flags;
488 };
489 
490 struct target_rt_sigaction {
491     abi_ulong _sa_handler;
492     abi_ulong sa_flags;
493     target_sigset_t sa_mask;
494 };
495 
496 /* This is the struct used inside the kernel.  The ka_restorer
497    field comes from the 5th argument to sys_rt_sigaction.  */
498 struct target_sigaction {
499     abi_ulong _sa_handler;
500     abi_ulong sa_flags;
501     target_sigset_t sa_mask;
502     abi_ulong sa_restorer;
503 };
504 #elif defined(TARGET_MIPS)
505 struct target_sigaction {
506 	uint32_t	sa_flags;
507 #if defined(TARGET_ABI_MIPSN32)
508 	uint32_t	_sa_handler;
509 #else
510 	abi_ulong	_sa_handler;
511 #endif
512 	target_sigset_t	sa_mask;
513 };
514 #else
515 struct target_old_sigaction {
516         abi_ulong _sa_handler;
517         abi_ulong sa_mask;
518         abi_ulong sa_flags;
519         abi_ulong sa_restorer;
520 };
521 
522 struct target_sigaction {
523         abi_ulong _sa_handler;
524         abi_ulong sa_flags;
525         abi_ulong sa_restorer;
526         target_sigset_t sa_mask;
527 };
528 #endif
529 
530 typedef union target_sigval {
531 	int sival_int;
532         abi_ulong sival_ptr;
533 } target_sigval_t;
534 #if 0
535 #if defined (TARGET_SPARC)
536 typedef struct {
537 	struct {
538 		abi_ulong psr;
539 		abi_ulong pc;
540 		abi_ulong npc;
541 		abi_ulong y;
542 		abi_ulong u_regs[16]; /* globals and ins */
543 	}		si_regs;
544 	int		si_mask;
545 } __siginfo_t;
546 
547 typedef struct {
548 	unsigned   long si_float_regs [32];
549 	unsigned   long si_fsr;
550 	unsigned   long si_fpqdepth;
551 	struct {
552 		unsigned long *insn_addr;
553 		unsigned long insn;
554 	} si_fpqueue [16];
555 } __siginfo_fpu_t;
556 #endif
557 #endif
558 
559 #define TARGET_SI_MAX_SIZE	128
560 #define TARGET_SI_PAD_SIZE	((TARGET_SI_MAX_SIZE/sizeof(int)) - 3)
561 
562 typedef struct target_siginfo {
563 #ifdef TARGET_MIPS
564 	int si_signo;
565 	int si_code;
566 	int si_errno;
567 #else
568 	int si_signo;
569 	int si_errno;
570 	int si_code;
571 #endif
572 
573 	union {
574 		int _pad[TARGET_SI_PAD_SIZE];
575 
576 		/* kill() */
577 		struct {
578 			pid_t _pid;		/* sender's pid */
579 			uid_t _uid;		/* sender's uid */
580 		} _kill;
581 
582 		/* POSIX.1b timers */
583 		struct {
584 			unsigned int _timer1;
585 			unsigned int _timer2;
586 		} _timer;
587 
588 		/* POSIX.1b signals */
589 		struct {
590 			pid_t _pid;		/* sender's pid */
591 			uid_t _uid;		/* sender's uid */
592 			target_sigval_t _sigval;
593 		} _rt;
594 
595 		/* SIGCHLD */
596 		struct {
597 			pid_t _pid;		/* which child */
598 			uid_t _uid;		/* sender's uid */
599 			int _status;		/* exit code */
600 			target_clock_t _utime;
601                         target_clock_t _stime;
602 		} _sigchld;
603 
604 		/* SIGILL, SIGFPE, SIGSEGV, SIGBUS */
605 		struct {
606 			abi_ulong _addr; /* faulting insn/memory ref. */
607 		} _sigfault;
608 
609 		/* SIGPOLL */
610 		struct {
611 			int _band;	/* POLL_IN, POLL_OUT, POLL_MSG */
612 			int _fd;
613 		} _sigpoll;
614 	} _sifields;
615 } target_siginfo_t;
616 
617 /*
618  * si_code values
619  * Digital reserves positive values for kernel-generated signals.
620  */
621 #define TARGET_SI_USER		0	/* sent by kill, sigsend, raise */
622 #define TARGET_SI_KERNEL	0x80	/* sent by the kernel from somewhere */
623 #define TARGET_SI_QUEUE	-1		/* sent by sigqueue */
624 #define TARGET_SI_TIMER -2              /* sent by timer expiration */
625 #define TARGET_SI_MESGQ	-3		/* sent by real time mesq state change */
626 #define TARGET_SI_ASYNCIO	-4	/* sent by AIO completion */
627 #define TARGET_SI_SIGIO	-5		/* sent by queued SIGIO */
628 
629 /*
630  * SIGILL si_codes
631  */
632 #define TARGET_ILL_ILLOPC	(1)	/* illegal opcode */
633 #define TARGET_ILL_ILLOPN	(2)	/* illegal operand */
634 #define TARGET_ILL_ILLADR	(3)	/* illegal addressing mode */
635 #define TARGET_ILL_ILLTRP	(4)	/* illegal trap */
636 #define TARGET_ILL_PRVOPC	(5)	/* privileged opcode */
637 #define TARGET_ILL_PRVREG	(6)	/* privileged register */
638 #define TARGET_ILL_COPROC	(7)	/* coprocessor error */
639 #define TARGET_ILL_BADSTK	(8)	/* internal stack error */
640 
641 /*
642  * SIGFPE si_codes
643  */
644 #define TARGET_FPE_INTDIV      (1)  /* integer divide by zero */
645 #define TARGET_FPE_INTOVF      (2)  /* integer overflow */
646 #define TARGET_FPE_FLTDIV      (3)  /* floating point divide by zero */
647 #define TARGET_FPE_FLTOVF      (4)  /* floating point overflow */
648 #define TARGET_FPE_FLTUND      (5)  /* floating point underflow */
649 #define TARGET_FPE_FLTRES      (6)  /* floating point inexact result */
650 #define TARGET_FPE_FLTINV      (7)  /* floating point invalid operation */
651 #define TARGET_FPE_FLTSUB      (8)  /* subscript out of range */
652 #define TARGET_NSIGFPE         8
653 
654 /*
655  * SIGSEGV si_codes
656  */
657 #define TARGET_SEGV_MAPERR     (1)  /* address not mapped to object */
658 #define TARGET_SEGV_ACCERR     (2)  /* invalid permissions for mapped object */
659 
660 /*
661  * SIGBUS si_codes
662  */
663 #define TARGET_BUS_ADRALN       (1)	/* invalid address alignment */
664 #define TARGET_BUS_ADRERR       (2)	/* non-existant physical address */
665 #define TARGET_BUS_OBJERR       (3)	/* object specific hardware error */
666 
667 /*
668  * SIGTRAP si_codes
669  */
670 #define TARGET_TRAP_BRKPT	(1)	/* process breakpoint */
671 #define TARGET_TRAP_TRACE	(2)	/* process trace trap */
672 
673 #endif /* defined(TARGET_I386) || defined(TARGET_ARM) */
674 
675 struct target_rlimit {
676         abi_ulong   rlim_cur;
677         abi_ulong   rlim_max;
678 };
679 
680 #if defined(TARGET_ALPHA)
681 #define TARGET_RLIM_INFINITY	0x7fffffffffffffffull
682 #elif defined(TARGET_MIPS) || defined(TARGET_SPARC)
683 #define TARGET_RLIM_INFINITY	0x7fffffffUL
684 #else
685 #define TARGET_RLIM_INFINITY	((target_ulong)~0UL)
686 #endif
687 
688 struct target_pollfd {
689     int fd;           /* file descriptor */
690     short events;     /* requested events */
691     short revents;    /* returned events */
692 };
693 
694 /* virtual terminal ioctls */
695 #define TARGET_KIOCSOUND       0x4B2F	/* start sound generation (0 for off) */
696 #define TARGET_KDMKTONE	       0x4B30	/* generate tone */
697 #define TARGET_KDGKBTYPE       0x4b33
698 #define TARGET_KDSETMODE       0x4b3a
699 #define TARGET_KDGKBMODE       0x4b44
700 #define TARGET_KDSKBMODE       0x4b45
701 #define TARGET_KDGKBENT	       0x4B46	/* gets one entry in translation table */
702 #define TARGET_KDGKBSENT       0x4B48	/* gets one function key string entry */
703 
704 #define TARGET_SIOCATMARK      0x8905
705 
706 /* Networking ioctls */
707 #define TARGET_SIOCADDRT       0x890B          /* add routing table entry */
708 #define TARGET_SIOCDELRT       0x890C          /* delete routing table entry */
709 #define TARGET_SIOCGIFNAME     0x8910          /* get iface name               */
710 #define TARGET_SIOCSIFLINK     0x8911          /* set iface channel            */
711 #define TARGET_SIOCGIFCONF     0x8912          /* get iface list               */
712 #define TARGET_SIOCGIFFLAGS    0x8913          /* get flags                    */
713 #define TARGET_SIOCSIFFLAGS    0x8914          /* set flags                    */
714 #define TARGET_SIOCGIFADDR     0x8915          /* get PA address               */
715 #define TARGET_SIOCSIFADDR     0x8916          /* set PA address               */
716 #define TARGET_SIOCGIFDSTADDR  0x8917          /* get remote PA address        */
717 #define TARGET_SIOCSIFDSTADDR  0x8918          /* set remote PA address        */
718 #define TARGET_SIOCGIFBRDADDR  0x8919          /* get broadcast PA address     */
719 #define TARGET_SIOCSIFBRDADDR  0x891a          /* set broadcast PA address     */
720 #define TARGET_SIOCGIFNETMASK  0x891b          /* get network PA mask          */
721 #define TARGET_SIOCSIFNETMASK  0x891c          /* set network PA mask          */
722 #define TARGET_SIOCGIFMETRIC   0x891d          /* get metric                   */
723 #define TARGET_SIOCSIFMETRIC   0x891e          /* set metric                   */
724 #define TARGET_SIOCGIFMEM      0x891f          /* get memory address (BSD)     */
725 #define TARGET_SIOCSIFMEM      0x8920          /* set memory address (BSD)     */
726 #define TARGET_SIOCGIFMTU      0x8921          /* get MTU size                 */
727 #define TARGET_SIOCSIFMTU      0x8922          /* set MTU size                 */
728 #define TARGET_SIOCSIFHWADDR   0x8924          /* set hardware address (NI)    */
729 #define TARGET_SIOCGIFENCAP    0x8925          /* get/set slip encapsulation   */
730 #define TARGET_SIOCSIFENCAP    0x8926
731 #define TARGET_SIOCGIFHWADDR   0x8927          /* Get hardware address         */
732 #define TARGET_SIOCGIFSLAVE    0x8929          /* Driver slaving support       */
733 #define TARGET_SIOCSIFSLAVE    0x8930
734 #define TARGET_SIOCADDMULTI    0x8931          /* Multicast address lists      */
735 #define TARGET_SIOCDELMULTI    0x8932
736 
737 /* Bridging control calls */
738 #define TARGET_SIOCGIFBR       0x8940          /* Bridging support             */
739 #define TARGET_SIOCSIFBR       0x8941          /* Set bridging options         */
740 
741 #define TARGET_SIOCGIFTXQLEN   0x8942          /* Get the tx queue length      */
742 #define TARGET_SIOCSIFTXQLEN   0x8943          /* Set the tx queue length      */
743 
744 /* ARP cache control calls. */
745 #define TARGET_OLD_SIOCDARP    0x8950          /* old delete ARP table entry   */
746 #define TARGET_OLD_SIOCGARP    0x8951          /* old get ARP table entry      */
747 #define TARGET_OLD_SIOCSARP    0x8952          /* old set ARP table entry      */
748 #define TARGET_SIOCDARP        0x8953          /* delete ARP table entry       */
749 #define TARGET_SIOCGARP        0x8954          /* get ARP table entry          */
750 #define TARGET_SIOCSARP        0x8955          /* set ARP table entry          */
751 
752 /* RARP cache control calls. */
753 #define TARGET_SIOCDRARP       0x8960          /* delete RARP table entry      */
754 #define TARGET_SIOCGRARP       0x8961          /* get RARP table entry         */
755 #define TARGET_SIOCSRARP       0x8962          /* set RARP table entry         */
756 
757 /* Driver configuration calls */
758 #define TARGET_SIOCGIFMAP      0x8970          /* Get device parameters        */
759 #define TARGET_SIOCSIFMAP      0x8971          /* Set device parameters        */
760 
761 /* DLCI configuration calls */
762 #define TARGET_SIOCADDDLCI     0x8980          /* Create new DLCI device       */
763 #define TARGET_SIOCDELDLCI     0x8981          /* Delete DLCI device           */
764 
765 
766 /* From <linux/fs.h> */
767 
768 #define TARGET_BLKROSET   TARGET_IO(0x12,93) /* set device read-only (0 = read-write) */
769 #define TARGET_BLKROGET   TARGET_IO(0x12,94) /* get read-only status (0 = read_write) */
770 #define TARGET_BLKRRPART  TARGET_IO(0x12,95) /* re-read partition table */
771 #define TARGET_BLKGETSIZE TARGET_IO(0x12,96) /* return device size /512 (long *arg) */
772 #define TARGET_BLKFLSBUF  TARGET_IO(0x12,97) /* flush buffer cache */
773 #define TARGET_BLKRASET   TARGET_IO(0x12,98) /* Set read ahead for block device */
774 #define TARGET_BLKRAGET   TARGET_IO(0x12,99) /* get current read ahead setting */
775 #define TARGET_BLKFRASET  TARGET_IO(0x12,100)/* set filesystem (mm/filemap.c) read-ahead */
776 #define TARGET_BLKFRAGET  TARGET_IO(0x12,101)/* get filesystem (mm/filemap.c) read-ahead */
777 #define TARGET_BLKSECTSET TARGET_IO(0x12,102)/* set max sectors per request (ll_rw_blk.c) */
778 #define TARGET_BLKSECTGET TARGET_IO(0x12,103)/* get max sectors per request (ll_rw_blk.c) */
779 #define TARGET_BLKSSZGET  TARGET_IO(0x12,104)/* get block device sector size */
780 /* A jump here: 108-111 have been used for various private purposes. */
781 #define TARGET_BLKBSZGET  TARGET_IOR(0x12,112,sizeof(int))
782 #define TARGET_BLKBSZSET  TARGET_IOW(0x12,113,sizeof(int))
783 #define TARGET_BLKGETSIZE64 TARGET_IOR(0x12,114,sizeof(uint64_t)) /* return device size in bytes (u64 *arg) */
784 #define TARGET_FIBMAP     TARGET_IO(0x00,1)  /* bmap access */
785 #define TARGET_FIGETBSZ   TARGET_IO(0x00,2)  /* get the block size used for bmap */
786 #define TARGET_FS_IOC_FIEMAP TARGET_IOWR('f',11,struct fiemap)
787 
788 /* cdrom commands */
789 #define TARGET_CDROMPAUSE		0x5301 /* Pause Audio Operation */
790 #define TARGET_CDROMRESUME		0x5302 /* Resume paused Audio Operation */
791 #define TARGET_CDROMPLAYMSF		0x5303 /* Play Audio MSF (struct cdrom_msf) */
792 #define TARGET_CDROMPLAYTRKIND		0x5304 /* Play Audio Track/index
793                                            (struct cdrom_ti) */
794 #define TARGET_CDROMREADTOCHDR		0x5305 /* Read TOC header
795                                            (struct cdrom_tochdr) */
796 #define TARGET_CDROMREADTOCENTRY	0x5306 /* Read TOC entry
797                                            (struct cdrom_tocentry) */
798 #define TARGET_CDROMSTOP		0x5307 /* Stop the cdrom drive */
799 #define TARGET_CDROMSTART		0x5308 /* Start the cdrom drive */
800 #define TARGET_CDROMEJECT		0x5309 /* Ejects the cdrom media */
801 #define TARGET_CDROMVOLCTRL		0x530a /* Control output volume
802                                            (struct cdrom_volctrl) */
803 #define TARGET_CDROMSUBCHNL		0x530b /* Read subchannel data
804                                            (struct cdrom_subchnl) */
805 #define TARGET_CDROMREADMODE2		0x530c /* Read TARGET_CDROM mode 2 data (2336 Bytes)
806                                            (struct cdrom_read) */
807 #define TARGET_CDROMREADMODE1		0x530d /* Read TARGET_CDROM mode 1 data (2048 Bytes)
808                                            (struct cdrom_read) */
809 #define TARGET_CDROMREADAUDIO		0x530e /* (struct cdrom_read_audio) */
810 #define TARGET_CDROMEJECT_SW		0x530f /* enable(1)/disable(0) auto-ejecting */
811 #define TARGET_CDROMMULTISESSION	0x5310 /* Obtain the start-of-last-session
812                                            address of multi session disks
813                                            (struct cdrom_multisession) */
814 #define TARGET_CDROM_GET_MCN		0x5311 /* Obtain the "Universal Product Code"
815                                            if available (struct cdrom_mcn) */
816 #define TARGET_CDROM_GET_UPC		TARGET_CDROM_GET_MCN  /* This one is depricated,
817                                           but here anyway for compatability */
818 #define TARGET_CDROMRESET		0x5312 /* hard-reset the drive */
819 #define TARGET_CDROMVOLREAD		0x5313 /* Get the drive's volume setting
820                                           (struct cdrom_volctrl) */
821 #define TARGET_CDROMREADRAW		0x5314	/* read data in raw mode (2352 Bytes)
822                                            (struct cdrom_read) */
823 /*
824  * These ioctls are used only used in aztcd.c and optcd.c
825  */
826 #define TARGET_CDROMREADCOOKED		0x5315	/* read data in cooked mode */
827 #define TARGET_CDROMSEEK		0x5316  /* seek msf address */
828 
829 /*
830  * This ioctl is only used by the scsi-cd driver.
831    It is for playing audio in logical block addressing mode.
832  */
833 #define TARGET_CDROMPLAYBLK		0x5317	/* (struct cdrom_blk) */
834 
835 /*
836  * These ioctls are only used in optcd.c
837  */
838 #define TARGET_CDROMREADALL		0x5318	/* read all 2646 bytes */
839 
840 /*
841  * These ioctls are (now) only in ide-cd.c for controlling
842  * drive spindown time.  They should be implemented in the
843  * Uniform driver, via generic packet commands, GPCMD_MODE_SELECT_10,
844  * GPCMD_MODE_SENSE_10 and the GPMODE_POWER_PAGE...
845  *  -Erik
846  */
847 #define TARGET_CDROMGETSPINDOWN        0x531d
848 #define TARGET_CDROMSETSPINDOWN        0x531e
849 
850 /*
851  * These ioctls are implemented through the uniform CD-ROM driver
852  * They _will_ be adopted by all CD-ROM drivers, when all the CD-ROM
853  * drivers are eventually ported to the uniform CD-ROM driver interface.
854  */
855 #define TARGET_CDROMCLOSETRAY		0x5319	/* pendant of CDROMEJECT */
856 #define TARGET_CDROM_SET_OPTIONS	0x5320  /* Set behavior options */
857 #define TARGET_CDROM_CLEAR_OPTIONS	0x5321  /* Clear behavior options */
858 #define TARGET_CDROM_SELECT_SPEED	0x5322  /* Set the CD-ROM speed */
859 #define TARGET_CDROM_SELECT_DISC	0x5323  /* Select disc (for juke-boxes) */
860 #define TARGET_CDROM_MEDIA_CHANGED	0x5325  /* Check is media changed  */
861 #define TARGET_CDROM_DRIVE_STATUS	0x5326  /* Get tray position, etc. */
862 #define TARGET_CDROM_DISC_STATUS	0x5327  /* Get disc type, etc. */
863 #define TARGET_CDROM_CHANGER_NSLOTS    0x5328  /* Get number of slots */
864 #define TARGET_CDROM_LOCKDOOR		0x5329  /* lock or unlock door */
865 #define TARGET_CDROM_DEBUG		0x5330	/* Turn debug messages on/off */
866 #define TARGET_CDROM_GET_CAPABILITY	0x5331	/* get capabilities */
867 
868 /* Note that scsi/scsi_ioctl.h also uses 0x5382 - 0x5386.
869  * Future CDROM ioctls should be kept below 0x537F
870  */
871 
872 /* This ioctl is only used by sbpcd at the moment */
873 #define TARGET_CDROMAUDIOBUFSIZ        0x5382	/* set the audio buffer size */
874 					/* conflict with SCSI_IOCTL_GET_IDLUN */
875 
876 /* DVD-ROM Specific ioctls */
877 #define TARGET_DVD_READ_STRUCT		0x5390  /* Read structure */
878 #define TARGET_DVD_WRITE_STRUCT	0x5391  /* Write structure */
879 #define TARGET_DVD_AUTH		0x5392  /* Authentication */
880 
881 #define TARGET_CDROM_SEND_PACKET	0x5393	/* send a packet to the drive */
882 #define TARGET_CDROM_NEXT_WRITABLE	0x5394	/* get next writable block */
883 #define TARGET_CDROM_LAST_WRITTEN	0x5395	/* get last block written on disc */
884 
885 /* HD commands */
886 
887 /* hd/ide ctl's that pass (arg) ptrs to user space are numbered 0x030n/0x031n */
888 #define TARGET_HDIO_GETGEO            0x0301  /* get device geometry */
889 #define TARGET_HDIO_GET_UNMASKINTR    0x0302  /* get current unmask setting */
890 #define TARGET_HDIO_GET_MULTCOUNT     0x0304  /* get current IDE blockmode setting */
891 #define TARGET_HDIO_GET_KEEPSETTINGS  0x0308  /* get keep-settings-on-reset flag */
892 #define TARGET_HDIO_GET_32BIT         0x0309  /* get current io_32bit setting */
893 #define TARGET_HDIO_GET_NOWERR        0x030a  /* get ignore-write-error flag */
894 #define TARGET_HDIO_GET_DMA           0x030b  /* get use-dma flag */
895 #define TARGET_HDIO_GET_IDENTITY      0x030d  /* get IDE identification info */
896 #define TARGET_HDIO_DRIVE_CMD         0x031f  /* execute a special drive command */
897 
898 /* hd/ide ctl's that pass (arg) non-ptr values are numbered 0x032n/0x033n */
899 #define TARGET_HDIO_SET_MULTCOUNT     0x0321  /* change IDE blockmode */
900 #define TARGET_HDIO_SET_UNMASKINTR    0x0322  /* permit other irqs during I/O */
901 #define TARGET_HDIO_SET_KEEPSETTINGS  0x0323  /* keep ioctl settings on reset */
902 #define TARGET_HDIO_SET_32BIT         0x0324  /* change io_32bit flags */
903 #define TARGET_HDIO_SET_NOWERR        0x0325  /* change ignore-write-error flag */
904 #define TARGET_HDIO_SET_DMA           0x0326  /* change use-dma flag */
905 #define TARGET_HDIO_SET_PIO_MODE      0x0327  /* reconfig interface to new speed */
906 
907 /* loop ioctls */
908 #define TARGET_LOOP_SET_FD            0x4C00
909 #define TARGET_LOOP_CLR_FD            0x4C01
910 #define TARGET_LOOP_SET_STATUS        0x4C02
911 #define TARGET_LOOP_GET_STATUS        0x4C03
912 #define TARGET_LOOP_SET_STATUS64      0x4C04
913 #define TARGET_LOOP_GET_STATUS64      0x4C05
914 #define TARGET_LOOP_CHANGE_FD         0x4C06
915 
916 /* fb ioctls */
917 #define TARGET_FBIOGET_VSCREENINFO    0x4600
918 #define TARGET_FBIOPUT_VSCREENINFO    0x4601
919 #define TARGET_FBIOGET_FSCREENINFO    0x4602
920 
921 /* vt ioctls */
922 #define TARGET_VT_OPENQRY             0x5600
923 #define TARGET_VT_GETSTATE            0x5603
924 #define TARGET_VT_ACTIVATE            0x5606
925 #define TARGET_VT_WAITACTIVE          0x5607
926 #define TARGET_VT_LOCKSWITCH          0x560b
927 #define TARGET_VT_UNLOCKSWITCH        0x560c
928 
929 /* from asm/termbits.h */
930 
931 #define TARGET_NCC 8
932 struct target_termio {
933 	unsigned short c_iflag;		/* input mode flags */
934 	unsigned short c_oflag;		/* output mode flags */
935 	unsigned short c_cflag;		/* control mode flags */
936 	unsigned short c_lflag;		/* local mode flags */
937 	unsigned char c_line;		/* line discipline */
938 	unsigned char c_cc[TARGET_NCC];	/* control characters */
939 };
940 
941 struct target_winsize {
942 	unsigned short ws_row;
943 	unsigned short ws_col;
944 	unsigned short ws_xpixel;
945 	unsigned short ws_ypixel;
946 };
947 
948 #include "termbits.h"
949 
950 #if defined(TARGET_MIPS)
951 #define TARGET_PROT_SEM         0x10
952 #else
953 #define TARGET_PROT_SEM         0x08
954 #endif
955 
956 /* Common */
957 #define TARGET_MAP_SHARED	0x01		/* Share changes */
958 #define TARGET_MAP_PRIVATE	0x02		/* Changes are private */
959 #define TARGET_MAP_TYPE		0x0f		/* Mask for type of mapping */
960 
961 /* Target specific */
962 #if defined(TARGET_MIPS)
963 #define TARGET_MAP_FIXED	0x10		/* Interpret addr exactly */
964 #define TARGET_MAP_ANONYMOUS	0x0800		/* don't use a file */
965 #define TARGET_MAP_GROWSDOWN	0x1000		/* stack-like segment */
966 #define TARGET_MAP_DENYWRITE	0x2000		/* ETXTBSY */
967 #define TARGET_MAP_EXECUTABLE	0x4000		/* mark it as an executable */
968 #define TARGET_MAP_LOCKED	0x8000		/* pages are locked */
969 #define TARGET_MAP_NORESERVE	0x0400		/* don't check for reservations */
970 #define TARGET_MAP_POPULATE	0x10000		/* populate (prefault) pagetables */
971 #define TARGET_MAP_NONBLOCK	0x20000		/* do not block on IO */
972 #elif defined(TARGET_PPC)
973 #define TARGET_MAP_FIXED	0x10		/* Interpret addr exactly */
974 #define TARGET_MAP_ANONYMOUS	0x20		/* don't use a file */
975 #define TARGET_MAP_GROWSDOWN	0x0100		/* stack-like segment */
976 #define TARGET_MAP_DENYWRITE	0x0800		/* ETXTBSY */
977 #define TARGET_MAP_EXECUTABLE	0x1000		/* mark it as an executable */
978 #define TARGET_MAP_LOCKED	0x0080		/* pages are locked */
979 #define TARGET_MAP_NORESERVE	0x0040		/* don't check for reservations */
980 #define TARGET_MAP_POPULATE	0x8000		/* populate (prefault) pagetables */
981 #define TARGET_MAP_NONBLOCK	0x10000		/* do not block on IO */
982 #elif defined(TARGET_ALPHA)
983 #define TARGET_MAP_ANONYMOUS	0x10		/* don't use a file */
984 #define TARGET_MAP_FIXED	0x100		/* Interpret addr exactly */
985 #define TARGET_MAP_GROWSDOWN	0x01000		/* stack-like segment */
986 #define TARGET_MAP_DENYWRITE	0x02000		/* ETXTBSY */
987 #define TARGET_MAP_EXECUTABLE	0x04000		/* mark it as an executable */
988 #define TARGET_MAP_LOCKED	0x08000		/* lock the mapping */
989 #define TARGET_MAP_NORESERVE	0x10000		/* no check for reservations */
990 #define TARGET_MAP_POPULATE	0x20000		/* pop (prefault) pagetables */
991 #define TARGET_MAP_NONBLOCK	0x40000		/* do not block on IO */
992 #else
993 #define TARGET_MAP_FIXED	0x10		/* Interpret addr exactly */
994 #define TARGET_MAP_ANONYMOUS	0x20		/* don't use a file */
995 #define TARGET_MAP_GROWSDOWN	0x0100		/* stack-like segment */
996 #define TARGET_MAP_DENYWRITE	0x0800		/* ETXTBSY */
997 #define TARGET_MAP_EXECUTABLE	0x1000		/* mark it as an executable */
998 #define TARGET_MAP_LOCKED	0x2000		/* pages are locked */
999 #define TARGET_MAP_NORESERVE	0x4000		/* don't check for reservations */
1000 #define TARGET_MAP_POPULATE	0x8000		/* populate (prefault) pagetables */
1001 #define TARGET_MAP_NONBLOCK	0x10000		/* do not block on IO */
1002 #endif
1003 
1004 #if (defined(TARGET_I386) && defined(TARGET_ABI32)) || defined(TARGET_ARM) || defined(TARGET_CRIS)
1005 struct target_stat {
1006 	unsigned short st_dev;
1007 	unsigned short __pad1;
1008 	abi_ulong st_ino;
1009 	unsigned short st_mode;
1010 	unsigned short st_nlink;
1011 	unsigned short st_uid;
1012 	unsigned short st_gid;
1013 	unsigned short st_rdev;
1014 	unsigned short __pad2;
1015 	abi_ulong  st_size;
1016 	abi_ulong  st_blksize;
1017 	abi_ulong  st_blocks;
1018 	abi_ulong  target_st_atime;
1019 	abi_ulong  __unused1;
1020 	abi_ulong  target_st_mtime;
1021 	abi_ulong  __unused2;
1022 	abi_ulong  target_st_ctime;
1023 	abi_ulong  __unused3;
1024 	abi_ulong  __unused4;
1025 	abi_ulong  __unused5;
1026 };
1027 
1028 /* This matches struct stat64 in glibc2.1, hence the absolutely
1029  * insane amounts of padding around dev_t's.
1030  */
1031 struct target_stat64 {
1032 	unsigned short	st_dev;
1033 	unsigned char	__pad0[10];
1034 
1035 #define TARGET_STAT64_HAS_BROKEN_ST_INO	1
1036 	abi_ulong	__st_ino;
1037 
1038 	unsigned int	st_mode;
1039 	unsigned int	st_nlink;
1040 
1041 	abi_ulong	st_uid;
1042 	abi_ulong	st_gid;
1043 
1044 	unsigned short	st_rdev;
1045 	unsigned char	__pad3[10];
1046 
1047 	long long	st_size;
1048 	abi_ulong	st_blksize;
1049 
1050 	abi_ulong	st_blocks;	/* Number 512-byte blocks allocated. */
1051 	abi_ulong	__pad4;		/* future possible st_blocks high bits */
1052 
1053 	abi_ulong	target_st_atime;
1054 	abi_ulong	__pad5;
1055 
1056 	abi_ulong	target_st_mtime;
1057 	abi_ulong	__pad6;
1058 
1059 	abi_ulong	target_st_ctime;
1060 	abi_ulong	__pad7;		/* will be high 32 bits of ctime someday */
1061 
1062 	unsigned long long	st_ino;
1063 } __attribute__((packed));
1064 
1065 #ifdef TARGET_ARM
1066 struct target_eabi_stat64 {
1067         unsigned long long st_dev;
1068         unsigned int    __pad1;
1069         abi_ulong    __st_ino;
1070         unsigned int    st_mode;
1071         unsigned int    st_nlink;
1072 
1073         abi_ulong    st_uid;
1074         abi_ulong    st_gid;
1075 
1076         unsigned long long st_rdev;
1077         unsigned int    __pad2[2];
1078 
1079         long long       st_size;
1080         abi_ulong    st_blksize;
1081         unsigned int    __pad3;
1082         unsigned long long st_blocks;
1083 
1084         abi_ulong    target_st_atime;
1085         abi_ulong    target_st_atime_nsec;
1086 
1087         abi_ulong    target_st_mtime;
1088         abi_ulong    target_st_mtime_nsec;
1089 
1090         abi_ulong    target_st_ctime;
1091         abi_ulong    target_st_ctime_nsec;
1092 
1093         unsigned long long st_ino;
1094 } __attribute__ ((packed));
1095 #endif
1096 
1097 #elif defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
1098 struct target_stat {
1099 	unsigned int	st_dev;
1100 	abi_ulong	st_ino;
1101 	unsigned int	st_mode;
1102 	unsigned int	st_nlink;
1103 	unsigned int	st_uid;
1104 	unsigned int	st_gid;
1105 	unsigned int	st_rdev;
1106 	abi_long	st_size;
1107 	abi_long	target_st_atime;
1108 	abi_long	target_st_mtime;
1109 	abi_long	target_st_ctime;
1110 	abi_long	st_blksize;
1111 	abi_long	st_blocks;
1112 	abi_ulong	__unused4[2];
1113 };
1114 
1115 struct target_stat64 {
1116 	unsigned char	__pad0[6];
1117 	unsigned short	st_dev;
1118 
1119 	uint64_t	st_ino;
1120 	uint64_t	st_nlink;
1121 
1122 	unsigned int	st_mode;
1123 
1124 	unsigned int	st_uid;
1125 	unsigned int	st_gid;
1126 
1127 	unsigned char	__pad2[6];
1128 	unsigned short	st_rdev;
1129 
1130         int64_t		st_size;
1131 	int64_t		st_blksize;
1132 
1133 	unsigned char	__pad4[4];
1134 	unsigned int	st_blocks;
1135 
1136 	abi_ulong	target_st_atime;
1137 	abi_ulong	__unused1;
1138 
1139 	abi_ulong	target_st_mtime;
1140 	abi_ulong	__unused2;
1141 
1142 	abi_ulong	target_st_ctime;
1143 	abi_ulong	__unused3;
1144 
1145 	abi_ulong	__unused4[3];
1146 };
1147 
1148 #elif defined(TARGET_SPARC)
1149 
1150 struct target_stat {
1151 	unsigned short	st_dev;
1152 	abi_ulong	st_ino;
1153 	unsigned short	st_mode;
1154 	short		st_nlink;
1155 	unsigned short	st_uid;
1156 	unsigned short	st_gid;
1157 	unsigned short	st_rdev;
1158 	abi_long	st_size;
1159 	abi_long	target_st_atime;
1160 	abi_ulong	__unused1;
1161 	abi_long	target_st_mtime;
1162 	abi_ulong	__unused2;
1163 	abi_long	target_st_ctime;
1164 	abi_ulong	__unused3;
1165 	abi_long	st_blksize;
1166 	abi_long	st_blocks;
1167 	abi_ulong	__unused4[2];
1168 };
1169 
1170 struct target_stat64 {
1171 	unsigned char	__pad0[6];
1172 	unsigned short	st_dev;
1173 
1174 	uint64_t st_ino;
1175 
1176 	unsigned int	st_mode;
1177 	unsigned int	st_nlink;
1178 
1179 	unsigned int	st_uid;
1180 	unsigned int	st_gid;
1181 
1182 	unsigned char	__pad2[6];
1183 	unsigned short	st_rdev;
1184 
1185 	unsigned char	__pad3[8];
1186 
1187         int64_t	st_size;
1188 	unsigned int	st_blksize;
1189 
1190 	unsigned char	__pad4[8];
1191 	unsigned int	st_blocks;
1192 
1193 	unsigned int	target_st_atime;
1194 	unsigned int	__unused1;
1195 
1196 	unsigned int	target_st_mtime;
1197 	unsigned int	__unused2;
1198 
1199 	unsigned int	target_st_ctime;
1200 	unsigned int	__unused3;
1201 
1202 	unsigned int	__unused4;
1203 	unsigned int	__unused5;
1204 };
1205 
1206 #elif defined(TARGET_PPC)
1207 
1208 struct target_stat {
1209 	abi_ulong st_dev;
1210 	abi_ulong st_ino;
1211 #if defined(TARGET_PPC64) && !defined(TARGET_ABI32)
1212 	abi_ulong st_nlink;
1213 	unsigned int st_mode;
1214 #else
1215 	unsigned int st_mode;
1216 	unsigned short st_nlink;
1217 #endif
1218 	unsigned int st_uid;
1219 	unsigned int st_gid;
1220 	abi_ulong  st_rdev;
1221 	abi_ulong  st_size;
1222 	abi_ulong  st_blksize;
1223 	abi_ulong  st_blocks;
1224 	abi_ulong  target_st_atime;
1225 	abi_ulong  target_st_atime_nsec;
1226 	abi_ulong  target_st_mtime;
1227 	abi_ulong  target_st_mtime_nsec;
1228 	abi_ulong  target_st_ctime;
1229 	abi_ulong  target_st_ctime_nsec;
1230 	abi_ulong  __unused4;
1231 	abi_ulong  __unused5;
1232 #if defined(TARGET_PPC64) && !defined(TARGET_ABI32)
1233 	abi_ulong  __unused6;
1234 #endif
1235 };
1236 
1237 struct __attribute__((__packed__)) target_stat64 {
1238 	unsigned long long st_dev;
1239         unsigned long long st_ino;
1240 	unsigned int st_mode;
1241 	unsigned int st_nlink;
1242 	unsigned int st_uid;
1243 	unsigned int st_gid;
1244 	unsigned long long st_rdev;
1245 	unsigned long long __pad0;
1246 	long long      st_size;
1247 	int	       st_blksize;
1248 	unsigned int   __pad1;
1249 	long long      st_blocks;	/* Number 512-byte blocks allocated. */
1250 	int	       target_st_atime;
1251         unsigned int   target_st_atime_nsec;
1252 	int	       target_st_mtime;
1253         unsigned int   target_st_mtime_nsec;
1254 	int            target_st_ctime;
1255         unsigned int   target_st_ctime_nsec;
1256         unsigned int   __unused4;
1257         unsigned int   __unused5;
1258 };
1259 
1260 #elif defined(TARGET_MICROBLAZE)
1261 
1262 struct target_stat {
1263 	abi_ulong st_dev;
1264 	abi_ulong st_ino;
1265 	unsigned int st_mode;
1266 	unsigned short st_nlink;
1267 	unsigned int st_uid;
1268 	unsigned int st_gid;
1269 	abi_ulong  st_rdev;
1270 	abi_ulong  st_size;
1271 	abi_ulong  st_blksize;
1272 	abi_ulong  st_blocks;
1273 	abi_ulong  target_st_atime;
1274 	abi_ulong  target_st_atime_nsec;
1275 	abi_ulong  target_st_mtime;
1276 	abi_ulong  target_st_mtime_nsec;
1277 	abi_ulong  target_st_ctime;
1278 	abi_ulong  target_st_ctime_nsec;
1279 	abi_ulong  __unused4;
1280 	abi_ulong  __unused5;
1281 };
1282 
1283 /* FIXME: Microblaze no-mmu user-space has a difference stat64 layout...  */
1284 struct __attribute__((__packed__)) target_stat64 {
1285 	uint64_t st_dev;
1286 #define TARGET_STAT64_HAS_BROKEN_ST_INO 1
1287 	uint32_t pad0;
1288 	uint32_t __st_ino;
1289 
1290 	uint32_t st_mode;
1291 	uint32_t st_nlink;
1292 	uint32_t st_uid;
1293 	uint32_t st_gid;
1294 	uint64_t st_rdev;
1295 	uint64_t __pad1;
1296 
1297 	int64_t  st_size;
1298 	int32_t  st_blksize;
1299 	uint32_t __pad2;
1300 	int64_t st_blocks;	/* Number 512-byte blocks allocated. */
1301 
1302 	int	       target_st_atime;
1303 	unsigned int   target_st_atime_nsec;
1304 	int	       target_st_mtime;
1305 	unsigned int   target_st_mtime_nsec;
1306 	int            target_st_ctime;
1307 	unsigned int   target_st_ctime_nsec;
1308 	uint64_t st_ino;
1309 };
1310 
1311 #elif defined(TARGET_M68K)
1312 
1313 struct target_stat {
1314 	unsigned short st_dev;
1315 	unsigned short __pad1;
1316 	abi_ulong st_ino;
1317 	unsigned short st_mode;
1318 	unsigned short st_nlink;
1319 	unsigned short st_uid;
1320 	unsigned short st_gid;
1321 	unsigned short st_rdev;
1322 	unsigned short __pad2;
1323 	abi_ulong  st_size;
1324 	abi_ulong  st_blksize;
1325 	abi_ulong  st_blocks;
1326 	abi_ulong  target_st_atime;
1327 	abi_ulong  __unused1;
1328 	abi_ulong  target_st_mtime;
1329 	abi_ulong  __unused2;
1330 	abi_ulong  target_st_ctime;
1331 	abi_ulong  __unused3;
1332 	abi_ulong  __unused4;
1333 	abi_ulong  __unused5;
1334 };
1335 
1336 /* This matches struct stat64 in glibc2.1, hence the absolutely
1337  * insane amounts of padding around dev_t's.
1338  */
1339 struct target_stat64 {
1340 	unsigned long long	st_dev;
1341 	unsigned char	__pad1[2];
1342 
1343 #define TARGET_STAT64_HAS_BROKEN_ST_INO	1
1344 	abi_ulong	__st_ino;
1345 
1346 	unsigned int	st_mode;
1347 	unsigned int	st_nlink;
1348 
1349 	abi_ulong	st_uid;
1350 	abi_ulong	st_gid;
1351 
1352 	unsigned long long	st_rdev;
1353 	unsigned char	__pad3[2];
1354 
1355 	long long	st_size;
1356 	abi_ulong	st_blksize;
1357 
1358 	abi_ulong	__pad4;		/* future possible st_blocks high bits */
1359 	abi_ulong	st_blocks;	/* Number 512-byte blocks allocated. */
1360 
1361 	abi_ulong	target_st_atime;
1362 	abi_ulong	target_st_atime_nsec;
1363 
1364 	abi_ulong	target_st_mtime;
1365 	abi_ulong	target_st_mtime_nsec;
1366 
1367 	abi_ulong	target_st_ctime;
1368 	abi_ulong	target_st_ctime_nsec;
1369 
1370 	unsigned long long	st_ino;
1371 } __attribute__((packed));
1372 
1373 #elif defined(TARGET_ABI_MIPSN64)
1374 
1375 /* The memory layout is the same as of struct stat64 of the 32-bit kernel.  */
1376 struct target_stat {
1377 	unsigned int		st_dev;
1378 	unsigned int		st_pad0[3]; /* Reserved for st_dev expansion */
1379 
1380 	abi_ulong		st_ino;
1381 
1382 	unsigned int		st_mode;
1383 	unsigned int		st_nlink;
1384 
1385 	int			st_uid;
1386 	int			st_gid;
1387 
1388 	unsigned int		st_rdev;
1389 	unsigned int		st_pad1[3]; /* Reserved for st_rdev expansion */
1390 
1391 	abi_ulong		st_size;
1392 
1393 	/*
1394 	 * Actually this should be timestruc_t st_atime, st_mtime and st_ctime
1395 	 * but we don't have it under Linux.
1396 	 */
1397 	unsigned int		target_st_atime;
1398 	unsigned int		target_st_atime_nsec;
1399 
1400 	unsigned int		target_st_mtime;
1401 	unsigned int		target_st_mtime_nsec;
1402 
1403 	unsigned int		target_st_ctime;
1404 	unsigned int		target_st_ctime_nsec;
1405 
1406 	unsigned int		st_blksize;
1407 	unsigned int		st_pad2;
1408 
1409 	abi_ulong		st_blocks;
1410 };
1411 
1412 #elif defined(TARGET_ABI_MIPSN32)
1413 
1414 struct target_stat {
1415 	unsigned	st_dev;
1416 	int		st_pad1[3];		/* Reserved for network id */
1417 	unsigned int	st_ino;
1418 	unsigned int	st_mode;
1419 	unsigned int	st_nlink;
1420 	int		st_uid;
1421 	int		st_gid;
1422 	unsigned 	st_rdev;
1423 	unsigned int	st_pad2[2];
1424 	unsigned int	st_size;
1425 	unsigned int	st_pad3;
1426 	/*
1427 	 * Actually this should be timestruc_t st_atime, st_mtime and st_ctime
1428 	 * but we don't have it under Linux.
1429 	 */
1430 	unsigned int		target_st_atime;
1431 	unsigned int		target_st_atime_nsec;
1432 	unsigned int		target_st_mtime;
1433 	unsigned int		target_st_mtime_nsec;
1434 	unsigned int		target_st_ctime;
1435 	unsigned int		target_st_ctime_nsec;
1436 	unsigned int		st_blksize;
1437 	unsigned int		st_blocks;
1438 	unsigned int		st_pad4[14];
1439 };
1440 
1441 /*
1442  * This matches struct stat64 in glibc2.1, hence the absolutely insane
1443  * amounts of padding around dev_t's.  The memory layout is the same as of
1444  * struct stat of the 64-bit kernel.
1445  */
1446 
1447 struct target_stat64 {
1448 	unsigned int	st_dev;
1449 	unsigned int	st_pad0[3];	/* Reserved for st_dev expansion  */
1450 
1451 	target_ulong	st_ino;
1452 
1453         unsigned int	st_mode;
1454         unsigned int	st_nlink;
1455 
1456 	int		st_uid;
1457 	int		st_gid;
1458 
1459 	unsigned int	st_rdev;
1460 	unsigned int	st_pad1[3];	/* Reserved for st_rdev expansion  */
1461 
1462 	int		st_size;
1463 
1464 	/*
1465 	 * Actually this should be timestruc_t st_atime, st_mtime and st_ctime
1466 	 * but we don't have it under Linux.
1467 	 */
1468 	int		target_st_atime;
1469 	unsigned int	target_st_atime_nsec;	/* Reserved for st_atime expansion  */
1470 
1471 	int		target_st_mtime;
1472 	unsigned int	target_st_mtime_nsec;	/* Reserved for st_mtime expansion  */
1473 
1474 	int		target_st_ctime;
1475 	unsigned int	target_st_ctime_nsec;	/* Reserved for st_ctime expansion  */
1476 
1477 	unsigned int	st_blksize;
1478 	unsigned int	st_pad2;
1479 
1480 	int		st_blocks;
1481 };
1482 
1483 #elif defined(TARGET_ABI_MIPSO32)
1484 
1485 struct target_stat {
1486 	unsigned	st_dev;
1487 	abi_long	st_pad1[3];		/* Reserved for network id */
1488 	abi_ulong	st_ino;
1489 	unsigned int	st_mode;
1490 	unsigned int	st_nlink;
1491 	int		st_uid;
1492 	int		st_gid;
1493 	unsigned 	st_rdev;
1494 	abi_long	st_pad2[2];
1495 	abi_long	st_size;
1496 	abi_long	st_pad3;
1497 	/*
1498 	 * Actually this should be timestruc_t st_atime, st_mtime and st_ctime
1499 	 * but we don't have it under Linux.
1500 	 */
1501 	abi_long		target_st_atime;
1502 	abi_long		target_st_atime_nsec;
1503 	abi_long		target_st_mtime;
1504 	abi_long		target_st_mtime_nsec;
1505 	abi_long		target_st_ctime;
1506 	abi_long		target_st_ctime_nsec;
1507 	abi_long		st_blksize;
1508 	abi_long		st_blocks;
1509 	abi_long		st_pad4[14];
1510 };
1511 
1512 /*
1513  * This matches struct stat64 in glibc2.1, hence the absolutely insane
1514  * amounts of padding around dev_t's.  The memory layout is the same as of
1515  * struct stat of the 64-bit kernel.
1516  */
1517 
1518 struct target_stat64 {
1519 	abi_ulong	st_dev;
1520 	abi_ulong	st_pad0[3];	/* Reserved for st_dev expansion  */
1521 
1522 	uint64_t	st_ino;
1523 
1524         unsigned int	st_mode;
1525         unsigned int	st_nlink;
1526 
1527 	int		st_uid;
1528 	int		st_gid;
1529 
1530 	abi_ulong	st_rdev;
1531 	abi_ulong	st_pad1[3];	/* Reserved for st_rdev expansion  */
1532 
1533 	int64_t 	st_size;
1534 
1535 	/*
1536 	 * Actually this should be timestruc_t st_atime, st_mtime and st_ctime
1537 	 * but we don't have it under Linux.
1538 	 */
1539 	abi_long	target_st_atime;
1540 	abi_ulong	target_st_atime_nsec;	/* Reserved for st_atime expansion  */
1541 
1542 	abi_long	target_st_mtime;
1543 	abi_ulong	target_st_mtime_nsec;	/* Reserved for st_mtime expansion  */
1544 
1545 	abi_long	target_st_ctime;
1546 	abi_ulong	target_st_ctime_nsec;	/* Reserved for st_ctime expansion  */
1547 
1548 	abi_ulong	st_blksize;
1549 	abi_ulong	st_pad2;
1550 
1551 	int64_t  	st_blocks;
1552 };
1553 
1554 #elif defined(TARGET_ALPHA)
1555 
1556 struct target_stat {
1557        unsigned int    st_dev;
1558        unsigned int    st_ino;
1559        unsigned int    st_mode;
1560        unsigned int    st_nlink;
1561        unsigned int    st_uid;
1562        unsigned int    st_gid;
1563        unsigned int    st_rdev;
1564        abi_long     st_size;
1565        abi_ulong    target_st_atime;
1566        abi_ulong    target_st_mtime;
1567        abi_ulong    target_st_ctime;
1568        unsigned int    st_blksize;
1569        unsigned int    st_blocks;
1570        unsigned int    st_flags;
1571        unsigned int    st_gen;
1572 };
1573 
1574 struct target_stat64 {
1575        abi_ulong    st_dev;
1576        abi_ulong    st_ino;
1577        abi_ulong    st_rdev;
1578        abi_long     st_size;
1579        abi_ulong    st_blocks;
1580 
1581        unsigned int    st_mode;
1582        unsigned int    st_uid;
1583        unsigned int    st_gid;
1584        unsigned int    st_blksize;
1585        unsigned int    st_nlink;
1586        unsigned int    __pad0;
1587 
1588        abi_ulong    target_st_atime;
1589        abi_ulong    target_st_atime_nsec;
1590        abi_ulong    target_st_mtime;
1591        abi_ulong    target_st_mtime_nsec;
1592        abi_ulong    target_st_ctime;
1593        abi_ulong    target_st_ctime_nsec;
1594        abi_long     __unused[3];
1595 };
1596 
1597 #elif defined(TARGET_SH4)
1598 
1599 struct target_stat {
1600 	abi_ulong  st_dev;
1601 	abi_ulong  st_ino;
1602 	unsigned short st_mode;
1603 	unsigned short st_nlink;
1604 	unsigned short st_uid;
1605 	unsigned short st_gid;
1606 	abi_ulong  st_rdev;
1607 	abi_ulong  st_size;
1608 	abi_ulong  st_blksize;
1609 	abi_ulong  st_blocks;
1610 	abi_ulong  target_st_atime;
1611 	abi_ulong  target_st_atime_nsec;
1612 	abi_ulong  target_st_mtime;
1613 	abi_ulong  target_st_mtime_nsec;
1614 	abi_ulong  target_st_ctime;
1615 	abi_ulong  target_st_ctime_nsec;
1616 	abi_ulong  __unused4;
1617 	abi_ulong  __unused5;
1618 };
1619 
1620 /* This matches struct stat64 in glibc2.1, hence the absolutely
1621  * insane amounts of padding around dev_t's.
1622  */
1623 struct __attribute__((__packed__)) target_stat64 {
1624 	unsigned long long	st_dev;
1625 	unsigned char	__pad0[4];
1626 
1627 #define TARGET_STAT64_HAS_BROKEN_ST_INO	1
1628 	abi_ulong	__st_ino;
1629 
1630 	unsigned int	st_mode;
1631 	unsigned int	st_nlink;
1632 
1633 	abi_ulong	st_uid;
1634 	abi_ulong	st_gid;
1635 
1636 	unsigned long long	st_rdev;
1637 	unsigned char	__pad3[4];
1638 
1639 	long long	st_size;
1640 	abi_ulong	st_blksize;
1641 
1642 	unsigned long long	st_blocks;	/* Number 512-byte blocks allocated. */
1643 
1644 	abi_ulong	target_st_atime;
1645 	abi_ulong	target_st_atime_nsec;
1646 
1647 	abi_ulong	target_st_mtime;
1648 	abi_ulong	target_st_mtime_nsec;
1649 
1650 	abi_ulong	target_st_ctime;
1651 	abi_ulong	target_st_ctime_nsec;
1652 
1653 	unsigned long long	st_ino;
1654 };
1655 
1656 #elif defined(TARGET_I386) && !defined(TARGET_ABI32)
1657 struct target_stat {
1658 	abi_ulong	st_dev;
1659 	abi_ulong	st_ino;
1660 	abi_ulong	st_nlink;
1661 
1662 	unsigned int	st_mode;
1663 	unsigned int	st_uid;
1664 	unsigned int	st_gid;
1665 	unsigned int	__pad0;
1666 	abi_ulong	st_rdev;
1667 	abi_long	st_size;
1668 	abi_long	st_blksize;
1669     	abi_long	st_blocks;	/* Number 512-byte blocks allocated. */
1670 
1671 	abi_ulong	target_st_atime;
1672 	abi_ulong 	target_st_atime_nsec;
1673 	abi_ulong	target_st_mtime;
1674 	abi_ulong	target_st_mtime_nsec;
1675 	abi_ulong	target_st_ctime;
1676 	abi_ulong       target_st_ctime_nsec;
1677 
1678   	abi_long	__unused[3];
1679 };
1680 #else
1681 #error unsupported CPU
1682 #endif
1683 
1684 typedef struct {
1685         int     val[2];
1686 } target_fsid_t;
1687 
1688 #ifdef TARGET_MIPS
1689 #ifdef TARGET_ABI_MIPSN32
1690 struct target_statfs {
1691 	int32_t			f_type;
1692 	int32_t			f_bsize;
1693 	int32_t			f_frsize;	/* Fragment size - unsupported */
1694 	int32_t			f_blocks;
1695 	int32_t			f_bfree;
1696 	int32_t			f_files;
1697 	int32_t			f_ffree;
1698 	int32_t			f_bavail;
1699 
1700 	/* Linux specials */
1701 	target_fsid_t		f_fsid;
1702 	int32_t			f_namelen;
1703 	int32_t			f_spare[6];
1704 };
1705 #else
1706 struct target_statfs {
1707 	abi_long		f_type;
1708 	abi_long		f_bsize;
1709 	abi_long		f_frsize;	/* Fragment size - unsupported */
1710 	abi_long		f_blocks;
1711 	abi_long		f_bfree;
1712 	abi_long		f_files;
1713 	abi_long		f_ffree;
1714 	abi_long		f_bavail;
1715 
1716 	/* Linux specials */
1717 	target_fsid_t		f_fsid;
1718 	abi_long		f_namelen;
1719 	abi_long		f_spare[6];
1720 };
1721 #endif
1722 
1723 struct target_statfs64 {
1724 	uint32_t	f_type;
1725 	uint32_t	f_bsize;
1726 	uint32_t	f_frsize;	/* Fragment size - unsupported */
1727 	uint32_t	__pad;
1728 	uint64_t	f_blocks;
1729 	uint64_t	f_bfree;
1730 	uint64_t	f_files;
1731 	uint64_t	f_ffree;
1732 	uint64_t	f_bavail;
1733 	target_fsid_t	f_fsid;
1734 	uint32_t	f_namelen;
1735 	uint32_t	f_spare[6];
1736 };
1737 #elif (defined(TARGET_PPC64) || defined(TARGET_X86_64) || \
1738        defined(TARGET_SPARC64)) && !defined(TARGET_ABI32)
1739 struct target_statfs {
1740 	abi_long f_type;
1741 	abi_long f_bsize;
1742 	abi_long f_blocks;
1743 	abi_long f_bfree;
1744 	abi_long f_bavail;
1745 	abi_long f_files;
1746 	abi_long f_ffree;
1747 	target_fsid_t f_fsid;
1748 	abi_long f_namelen;
1749 	abi_long f_frsize;
1750 	abi_long f_spare[5];
1751 };
1752 
1753 struct target_statfs64 {
1754 	abi_long f_type;
1755 	abi_long f_bsize;
1756 	abi_long f_blocks;
1757 	abi_long f_bfree;
1758 	abi_long f_bavail;
1759 	abi_long f_files;
1760 	abi_long f_ffree;
1761 	target_fsid_t f_fsid;
1762 	abi_long f_namelen;
1763 	abi_long f_frsize;
1764 	abi_long f_spare[5];
1765 };
1766 #else
1767 struct target_statfs {
1768 	uint32_t f_type;
1769 	uint32_t f_bsize;
1770 	uint32_t f_blocks;
1771 	uint32_t f_bfree;
1772 	uint32_t f_bavail;
1773 	uint32_t f_files;
1774 	uint32_t f_ffree;
1775 	target_fsid_t f_fsid;
1776 	uint32_t f_namelen;
1777 	uint32_t f_frsize;
1778 	uint32_t f_spare[5];
1779 };
1780 
1781 struct target_statfs64 {
1782 	uint32_t f_type;
1783 	uint32_t f_bsize;
1784 	uint64_t f_blocks;
1785 	uint64_t f_bfree;
1786 	uint64_t f_bavail;
1787 	uint64_t f_files;
1788 	uint64_t f_ffree;
1789 	target_fsid_t f_fsid;
1790         uint32_t f_namelen;
1791 	uint32_t f_frsize;
1792 	uint32_t f_spare[5];
1793 };
1794 #endif
1795 
1796 
1797 #define TARGET_F_DUPFD         0       /* dup */
1798 #define TARGET_F_GETFD         1       /* get close_on_exec */
1799 #define TARGET_F_SETFD         2       /* set/clear close_on_exec */
1800 #define TARGET_F_GETFL         3       /* get file->f_flags */
1801 #define TARGET_F_SETFL         4       /* set file->f_flags */
1802 
1803 #if defined(TARGET_ALPHA)
1804 #define TARGET_F_GETLK         7
1805 #define TARGET_F_SETLK         8
1806 #define TARGET_F_SETLKW        9
1807 #define TARGET_F_SETOWN        5       /*  for sockets. */
1808 #define TARGET_F_GETOWN        6       /*  for sockets. */
1809 #elif defined(TARGET_MIPS)
1810 #define TARGET_F_GETLK         14
1811 #define TARGET_F_SETLK         6
1812 #define TARGET_F_SETLKW        7
1813 #define TARGET_F_SETOWN        24       /*  for sockets. */
1814 #define TARGET_F_GETOWN        25       /*  for sockets. */
1815 #else
1816 #define TARGET_F_GETLK         5
1817 #define TARGET_F_SETLK         6
1818 #define TARGET_F_SETLKW        7
1819 #define TARGET_F_SETOWN        8       /*  for sockets. */
1820 #define TARGET_F_GETOWN        9       /*  for sockets. */
1821 #endif
1822 
1823 #define TARGET_F_SETSIG        10      /*  for sockets. */
1824 #define TARGET_F_GETSIG        11      /*  for sockets. */
1825 
1826 #if defined(TARGET_MIPS)
1827 #define TARGET_F_GETLK64       33      /*  using 'struct flock64' */
1828 #define TARGET_F_SETLK64       34
1829 #define TARGET_F_SETLKW64      35
1830 #else
1831 #define TARGET_F_GETLK64       12      /*  using 'struct flock64' */
1832 #define TARGET_F_SETLK64       13
1833 #define TARGET_F_SETLKW64      14
1834 #endif
1835 
1836 #define TARGET_F_LINUX_SPECIFIC_BASE 1024
1837 #define TARGET_F_SETLEASE (TARGET_F_LINUX_SPECIFIC_BASE + 0)
1838 #define TARGET_F_GETLEASE (TARGET_F_LINUX_SPECIFIC_BASE + 1)
1839 #define TARGET_F_DUPFD_CLOEXEC (TARGET_F_LINUX_SPECIFIC_BASE + 6)
1840 #define TARGET_F_NOTIFY  (TARGET_F_LINUX_SPECIFIC_BASE+2)
1841 
1842 #if defined (TARGET_ARM)
1843 #define TARGET_O_ACCMODE          0003
1844 #define TARGET_O_RDONLY             00
1845 #define TARGET_O_WRONLY             01
1846 #define TARGET_O_RDWR               02
1847 #define TARGET_O_CREAT            0100 /* not fcntl */
1848 #define TARGET_O_EXCL             0200 /* not fcntl */
1849 #define TARGET_O_NOCTTY           0400 /* not fcntl */
1850 #define TARGET_O_TRUNC           01000 /* not fcntl */
1851 #define TARGET_O_APPEND          02000
1852 #define TARGET_O_NONBLOCK        04000
1853 #define TARGET_O_NDELAY        TARGET_O_NONBLOCK
1854 #define TARGET_O_SYNC           010000
1855 #define TARGET_FASYNC           020000 /* fcntl, for BSD compatibility */
1856 #define TARGET_O_DIRECTORY      040000 /* must be a directory */
1857 #define TARGET_O_NOFOLLOW      0100000 /* don't follow links */
1858 #define TARGET_O_DIRECT        0200000 /* direct disk access hint */
1859 #define TARGET_O_LARGEFILE     0400000
1860 #elif defined (TARGET_PPC)
1861 #define TARGET_O_ACCMODE          0003
1862 #define TARGET_O_RDONLY             00
1863 #define TARGET_O_WRONLY             01
1864 #define TARGET_O_RDWR               02
1865 #define TARGET_O_CREAT            0100 /* not fcntl */
1866 #define TARGET_O_EXCL             0200 /* not fcntl */
1867 #define TARGET_O_NOCTTY           0400 /* not fcntl */
1868 #define TARGET_O_TRUNC           01000 /* not fcntl */
1869 #define TARGET_O_APPEND          02000
1870 #define TARGET_O_NONBLOCK        04000
1871 #define TARGET_O_NDELAY        TARGET_O_NONBLOCK
1872 #define TARGET_O_SYNC           010000
1873 #define TARGET_FASYNC           020000 /* fcntl, for BSD compatibility */
1874 #define TARGET_O_DIRECTORY      040000 /* must be a directory */
1875 #define TARGET_O_NOFOLLOW      0100000 /* don't follow links */
1876 #define TARGET_O_LARGEFILE     0200000
1877 #define TARGET_O_DIRECT        0400000 /* direct disk access hint */
1878 #elif defined (TARGET_MICROBLAZE)
1879 #define TARGET_O_ACCMODE          0003
1880 #define TARGET_O_RDONLY             00
1881 #define TARGET_O_WRONLY             01
1882 #define TARGET_O_RDWR               02
1883 #define TARGET_O_CREAT            0100 /* not fcntl */
1884 #define TARGET_O_EXCL             0200 /* not fcntl */
1885 #define TARGET_O_NOCTTY           0400 /* not fcntl */
1886 #define TARGET_O_TRUNC           01000 /* not fcntl */
1887 #define TARGET_O_APPEND          02000
1888 #define TARGET_O_NONBLOCK        04000
1889 #define TARGET_O_NDELAY        TARGET_O_NONBLOCK
1890 #define TARGET_O_SYNC           010000
1891 #define TARGET_FASYNC           020000 /* fcntl, for BSD compatibility */
1892 #define TARGET_O_DIRECTORY      040000 /* must be a directory */
1893 #define TARGET_O_NOFOLLOW      0100000 /* don't follow links */
1894 #define TARGET_O_LARGEFILE     0200000
1895 #define TARGET_O_DIRECT        0400000 /* direct disk access hint */
1896 #elif defined (TARGET_SPARC)
1897 #define TARGET_O_RDONLY        0x0000
1898 #define TARGET_O_WRONLY        0x0001
1899 #define TARGET_O_RDWR          0x0002
1900 #define TARGET_O_ACCMODE       0x0003
1901 #define TARGET_O_APPEND        0x0008
1902 #define TARGET_FASYNC          0x0040  /* fcntl, for BSD compatibility */
1903 #define TARGET_O_CREAT         0x0200  /* not fcntl */
1904 #define TARGET_O_TRUNC         0x0400  /* not fcntl */
1905 #define TARGET_O_EXCL          0x0800  /* not fcntl */
1906 #define TARGET_O_SYNC          0x2000
1907 #define TARGET_O_NONBLOCK      0x4000
1908 #define TARGET_O_NDELAY        (0x0004 | TARGET_O_NONBLOCK)
1909 #define TARGET_O_NOCTTY        0x8000  /* not fcntl */
1910 #define TARGET_O_DIRECTORY     0x10000 /* must be a directory */
1911 #define TARGET_O_NOFOLLOW      0x20000 /* don't follow links */
1912 #define TARGET_O_LARGEFILE     0x40000
1913 #define TARGET_O_DIRECT        0x100000 /* direct disk access hint */
1914 #elif defined(TARGET_MIPS)
1915 #define TARGET_O_ACCMODE	0x0003
1916 #define TARGET_O_RDONLY	0x0000
1917 #define TARGET_O_WRONLY	0x0001
1918 #define TARGET_O_RDWR		0x0002
1919 #define TARGET_O_APPEND	0x0008
1920 #define TARGET_O_SYNC		0x0010
1921 #define TARGET_O_NONBLOCK	0x0080
1922 #define TARGET_O_CREAT         0x0100	/* not fcntl */
1923 #define TARGET_O_TRUNC		0x0200	/* not fcntl */
1924 #define TARGET_O_EXCL		0x0400	/* not fcntl */
1925 #define TARGET_O_NOCTTY	0x0800	/* not fcntl */
1926 #define TARGET_FASYNC		0x1000	/* fcntl, for BSD compatibility */
1927 #define TARGET_O_LARGEFILE	0x2000	/* allow large file opens */
1928 #define TARGET_O_DIRECT	0x8000	/* direct disk access hint */
1929 #define TARGET_O_DIRECTORY	0x10000	/* must be a directory */
1930 #define TARGET_O_NOFOLLOW	0x20000	/* don't follow links */
1931 #define TARGET_O_NOATIME	0x40000
1932 #define TARGET_O_NDELAY	TARGET_O_NONBLOCK
1933 #elif defined(TARGET_ALPHA)
1934 #define TARGET_O_ACCMODE	0x0003
1935 #define TARGET_O_RDONLY	0x0000
1936 #define TARGET_O_WRONLY	0x0001
1937 #define TARGET_O_RDWR		0x0002
1938 #define TARGET_O_APPEND	0x0008
1939 #define TARGET_O_SYNC		0x4000
1940 #define TARGET_O_NONBLOCK	0x0004
1941 #define TARGET_O_CREAT         0x0200	/* not fcntl */
1942 #define TARGET_O_TRUNC		0x0400	/* not fcntl */
1943 #define TARGET_O_EXCL		0x0800	/* not fcntl */
1944 #define TARGET_O_NOCTTY	0x1000	/* not fcntl */
1945 #define TARGET_FASYNC		0x2000	/* fcntl, for BSD compatibility */
1946 #define TARGET_O_LARGEFILE	0x0000	/* not necessary, always 64-bit */
1947 #define TARGET_O_DIRECT	0x80000	/* direct disk access hint */
1948 #define TARGET_O_DIRECTORY	0x8000	/* must be a directory */
1949 #define TARGET_O_NOFOLLOW	0x10000	/* don't follow links */
1950 #define TARGET_O_NOATIME	0x100000
1951 #define TARGET_O_NDELAY	TARGET_O_NONBLOCK
1952 #else
1953 #define TARGET_O_ACCMODE          0003
1954 #define TARGET_O_RDONLY             00
1955 #define TARGET_O_WRONLY             01
1956 #define TARGET_O_RDWR               02
1957 #define TARGET_O_CREAT            0100 /* not fcntl */
1958 #define TARGET_O_EXCL             0200 /* not fcntl */
1959 #define TARGET_O_NOCTTY           0400 /* not fcntl */
1960 #define TARGET_O_TRUNC           01000 /* not fcntl */
1961 #define TARGET_O_APPEND          02000
1962 #define TARGET_O_NONBLOCK        04000
1963 #define TARGET_O_NDELAY        TARGET_O_NONBLOCK
1964 #define TARGET_O_SYNC           010000
1965 #define TARGET_FASYNC           020000 /* fcntl, for BSD compatibility */
1966 #define TARGET_O_DIRECT         040000 /* direct disk access hint */
1967 #define TARGET_O_LARGEFILE     0100000
1968 #define TARGET_O_DIRECTORY     0200000 /* must be a directory */
1969 #define TARGET_O_NOFOLLOW      0400000 /* don't follow links */
1970 #endif
1971 
1972 struct target_flock {
1973 	short l_type;
1974 	short l_whence;
1975 	abi_ulong l_start;
1976 	abi_ulong l_len;
1977 	int l_pid;
1978 };
1979 
1980 struct target_flock64 {
1981 	short  l_type;
1982 	short  l_whence;
1983 #if defined(TARGET_PPC) || defined(TARGET_X86_64) || defined(TARGET_MIPS) || defined(TARGET_SPARC) || defined(TARGET_HPPA) || defined (TARGET_MICROBLAZE)
1984         int __pad;
1985 #endif
1986 	unsigned long long l_start;
1987 	unsigned long long l_len;
1988 	int  l_pid;
1989 }__attribute__((packed));
1990 
1991 #ifdef TARGET_ARM
1992 struct target_eabi_flock64 {
1993 	short  l_type;
1994 	short  l_whence;
1995         int __pad;
1996 	unsigned long long l_start;
1997 	unsigned long long l_len;
1998 	int  l_pid;
1999 }__attribute__((packed));
2000 #endif
2001 
2002 /* soundcard defines */
2003 /* XXX: convert them all to arch indepedent entries */
2004 #define TARGET_SNDCTL_COPR_HALT           TARGET_IOWR('C',  7, int);
2005 #define TARGET_SNDCTL_COPR_LOAD           0xcfb04301
2006 #define TARGET_SNDCTL_COPR_RCODE          0xc0144303
2007 #define TARGET_SNDCTL_COPR_RCVMSG         0x8fa44309
2008 #define TARGET_SNDCTL_COPR_RDATA          0xc0144302
2009 #define TARGET_SNDCTL_COPR_RESET          0x00004300
2010 #define TARGET_SNDCTL_COPR_RUN            0xc0144306
2011 #define TARGET_SNDCTL_COPR_SENDMSG        0xcfa44308
2012 #define TARGET_SNDCTL_COPR_WCODE          0x40144305
2013 #define TARGET_SNDCTL_COPR_WDATA          0x40144304
2014 #define TARGET_SNDCTL_DSP_RESET           TARGET_IO('P', 0)
2015 #define TARGET_SNDCTL_DSP_SYNC            TARGET_IO('P', 1)
2016 #define TARGET_SNDCTL_DSP_SPEED           TARGET_IOWR('P', 2, int)
2017 #define TARGET_SNDCTL_DSP_STEREO          TARGET_IOWR('P', 3, int)
2018 #define TARGET_SNDCTL_DSP_GETBLKSIZE      TARGET_IOWR('P', 4, int)
2019 #define TARGET_SNDCTL_DSP_SETFMT          TARGET_IOWR('P', 5, int)
2020 #define TARGET_SNDCTL_DSP_CHANNELS        TARGET_IOWR('P', 6, int)
2021 #define TARGET_SOUND_PCM_WRITE_FILTER     TARGET_IOWR('P', 7, int)
2022 #define TARGET_SNDCTL_DSP_POST            TARGET_IO('P', 8)
2023 #define TARGET_SNDCTL_DSP_SUBDIVIDE       TARGET_IOWR('P', 9, int)
2024 #define TARGET_SNDCTL_DSP_SETFRAGMENT     TARGET_IOWR('P',10, int)
2025 #define TARGET_SNDCTL_DSP_GETFMTS         TARGET_IOR('P', 11, int)
2026 #define TARGET_SNDCTL_DSP_GETOSPACE       TARGET_IORU('P',12)
2027 #define TARGET_SNDCTL_DSP_GETISPACE       TARGET_IORU('P',13)
2028 #define TARGET_SNDCTL_DSP_GETCAPS         TARGET_IOR('P', 15, int)
2029 #define TARGET_SNDCTL_DSP_GETTRIGGER      TARGET_IOR('P',16, int)
2030 #define TARGET_SNDCTL_DSP_GETIPTR         TARGET_IORU('P',17)
2031 #define TARGET_SNDCTL_DSP_GETOPTR         TARGET_IORU('P',18)
2032 #define TARGET_SNDCTL_DSP_MAPINBUF        0x80085013
2033 #define TARGET_SNDCTL_DSP_MAPOUTBUF       0x80085014
2034 #define TARGET_SNDCTL_DSP_NONBLOCK        0x0000500e
2035 #define TARGET_SNDCTL_DSP_SAMPLESIZE      0xc0045005
2036 #define TARGET_SNDCTL_DSP_SETDUPLEX       0x00005016
2037 #define TARGET_SNDCTL_DSP_SETSYNCRO       0x00005015
2038 #define TARGET_SNDCTL_DSP_SETTRIGGER      0x40045010
2039 #define TARGET_SNDCTL_FM_4OP_ENABLE       0x4004510f
2040 #define TARGET_SNDCTL_FM_LOAD_INSTR       0x40285107
2041 #define TARGET_SNDCTL_MIDI_INFO           0xc074510c
2042 #define TARGET_SNDCTL_MIDI_MPUCMD         0xc0216d02
2043 #define TARGET_SNDCTL_MIDI_MPUMODE        0xc0046d01
2044 #define TARGET_SNDCTL_MIDI_PRETIME        0xc0046d00
2045 #define TARGET_SNDCTL_PMGR_ACCESS         0xcfb85110
2046 #define TARGET_SNDCTL_PMGR_IFACE          0xcfb85001
2047 #define TARGET_SNDCTL_SEQ_CTRLRATE        0xc0045103
2048 #define TARGET_SNDCTL_SEQ_GETINCOUNT      0x80045105
2049 #define TARGET_SNDCTL_SEQ_GETOUTCOUNT     0x80045104
2050 #define TARGET_SNDCTL_SEQ_NRMIDIS         0x8004510b
2051 #define TARGET_SNDCTL_SEQ_NRSYNTHS        0x8004510a
2052 #define TARGET_SNDCTL_SEQ_OUTOFBAND       0x40085112
2053 #define TARGET_SNDCTL_SEQ_PANIC           0x00005111
2054 #define TARGET_SNDCTL_SEQ_PERCMODE        0x40045106
2055 #define TARGET_SNDCTL_SEQ_RESET           0x00005100
2056 #define TARGET_SNDCTL_SEQ_RESETSAMPLES    0x40045109
2057 #define TARGET_SNDCTL_SEQ_SYNC            0x00005101
2058 #define TARGET_SNDCTL_SEQ_TESTMIDI        0x40045108
2059 #define TARGET_SNDCTL_SEQ_THRESHOLD       0x4004510d
2060 #define TARGET_SNDCTL_SEQ_TRESHOLD        0x4004510d
2061 #define TARGET_SNDCTL_SYNTH_INFO          0xc08c5102
2062 #define TARGET_SNDCTL_SYNTH_MEMAVL        0xc004510e
2063 #define TARGET_SNDCTL_TMR_CONTINUE        0x00005404
2064 #define TARGET_SNDCTL_TMR_METRONOME       0x40045407
2065 #define TARGET_SNDCTL_TMR_SELECT          0x40045408
2066 #define TARGET_SNDCTL_TMR_SOURCE          0xc0045406
2067 #define TARGET_SNDCTL_TMR_START           0x00005402
2068 #define TARGET_SNDCTL_TMR_STOP            0x00005403
2069 #define TARGET_SNDCTL_TMR_TEMPO           0xc0045405
2070 #define TARGET_SNDCTL_TMR_TIMEBASE        0xc0045401
2071 #define TARGET_SOUND_PCM_READ_RATE        0x80045002
2072 #define TARGET_SOUND_PCM_READ_CHANNELS    0x80045006
2073 #define TARGET_SOUND_PCM_READ_BITS        0x80045005
2074 #define TARGET_SOUND_PCM_READ_FILTER      0x80045007
2075 #define TARGET_SOUND_MIXER_INFO           TARGET_IOR ('M', 101, mixer_info)
2076 #define TARGET_SOUND_MIXER_ACCESS         0xc0804d66
2077 #define TARGET_SOUND_MIXER_PRIVATE1       TARGET_IOWR('M', 111, int)
2078 #define TARGET_SOUND_MIXER_PRIVATE2       TARGET_IOWR('M', 112, int)
2079 #define TARGET_SOUND_MIXER_PRIVATE3       TARGET_IOWR('M', 113, int)
2080 #define TARGET_SOUND_MIXER_PRIVATE4       TARGET_IOWR('M', 114, int)
2081 #define TARGET_SOUND_MIXER_PRIVATE5       TARGET_IOWR('M', 115, int)
2082 
2083 #define TARGET_MIXER_READ(dev)	TARGET_IOR('M', dev, int)
2084 
2085 #define TARGET_SOUND_MIXER_READ_VOLUME		TARGET_MIXER_READ(SOUND_MIXER_VOLUME)
2086 #define TARGET_SOUND_MIXER_READ_BASS		TARGET_MIXER_READ(SOUND_MIXER_BASS)
2087 #define TARGET_SOUND_MIXER_READ_TREBLE		TARGET_MIXER_READ(SOUND_MIXER_TREBLE)
2088 #define TARGET_SOUND_MIXER_READ_SYNTH		TARGET_MIXER_READ(SOUND_MIXER_SYNTH)
2089 #define TARGET_SOUND_MIXER_READ_PCM		TARGET_MIXER_READ(SOUND_MIXER_PCM)
2090 #define TARGET_SOUND_MIXER_READ_SPEAKER	        TARGET_MIXER_READ(SOUND_MIXER_SPEAKER)
2091 #define TARGET_SOUND_MIXER_READ_LINE		TARGET_MIXER_READ(SOUND_MIXER_LINE)
2092 #define TARGET_SOUND_MIXER_READ_MIC		TARGET_MIXER_READ(SOUND_MIXER_MIC)
2093 #define TARGET_SOUND_MIXER_READ_CD		TARGET_MIXER_READ(SOUND_MIXER_CD)
2094 #define TARGET_SOUND_MIXER_READ_IMIX		TARGET_MIXER_READ(SOUND_MIXER_IMIX)
2095 #define TARGET_SOUND_MIXER_READ_ALTPCM		TARGET_MIXER_READ(SOUND_MIXER_ALTPCM)
2096 #define TARGET_SOUND_MIXER_READ_RECLEV		TARGET_MIXER_READ(SOUND_MIXER_RECLEV)
2097 #define TARGET_SOUND_MIXER_READ_IGAIN		TARGET_MIXER_READ(SOUND_MIXER_IGAIN)
2098 #define TARGET_SOUND_MIXER_READ_OGAIN		TARGET_MIXER_READ(SOUND_MIXER_OGAIN)
2099 #define TARGET_SOUND_MIXER_READ_LINE1		TARGET_MIXER_READ(SOUND_MIXER_LINE1)
2100 #define TARGET_SOUND_MIXER_READ_LINE2		TARGET_MIXER_READ(SOUND_MIXER_LINE2)
2101 #define TARGET_SOUND_MIXER_READ_LINE3		TARGET_MIXER_READ(SOUND_MIXER_LINE3)
2102 
2103 /* Obsolete macros */
2104 #define TARGET_SOUND_MIXER_READ_MUTE		TARGET_MIXER_READ(SOUND_MIXER_MUTE)
2105 #define TARGET_SOUND_MIXER_READ_ENHANCE	        TARGET_MIXER_READ(SOUND_MIXER_ENHANCE)
2106 #define TARGET_SOUND_MIXER_READ_LOUD		TARGET_MIXER_READ(SOUND_MIXER_LOUD)
2107 
2108 #define TARGET_SOUND_MIXER_READ_RECSRC		TARGET_MIXER_READ(SOUND_MIXER_RECSRC)
2109 #define TARGET_SOUND_MIXER_READ_DEVMASK	        TARGET_MIXER_READ(SOUND_MIXER_DEVMASK)
2110 #define TARGET_SOUND_MIXER_READ_RECMASK	        TARGET_MIXER_READ(SOUND_MIXER_RECMASK)
2111 #define TARGET_SOUND_MIXER_READ_STEREODEVS	TARGET_MIXER_READ(SOUND_MIXER_STEREODEVS)
2112 #define TARGET_SOUND_MIXER_READ_CAPS		TARGET_MIXER_READ(SOUND_MIXER_CAPS)
2113 
2114 #define TARGET_MIXER_WRITE(dev)		TARGET_IOWR('M', dev, int)
2115 
2116 #define TARGET_SOUND_MIXER_WRITE_VOLUME	TARGET_MIXER_WRITE(SOUND_MIXER_VOLUME)
2117 #define TARGET_SOUND_MIXER_WRITE_BASS		TARGET_MIXER_WRITE(SOUND_MIXER_BASS)
2118 #define TARGET_SOUND_MIXER_WRITE_TREBLE	TARGET_MIXER_WRITE(SOUND_MIXER_TREBLE)
2119 #define TARGET_SOUND_MIXER_WRITE_SYNTH		TARGET_MIXER_WRITE(SOUND_MIXER_SYNTH)
2120 #define TARGET_SOUND_MIXER_WRITE_PCM		TARGET_MIXER_WRITE(SOUND_MIXER_PCM)
2121 #define TARGET_SOUND_MIXER_WRITE_SPEAKER	TARGET_MIXER_WRITE(SOUND_MIXER_SPEAKER)
2122 #define TARGET_SOUND_MIXER_WRITE_LINE		TARGET_MIXER_WRITE(SOUND_MIXER_LINE)
2123 #define TARGET_SOUND_MIXER_WRITE_MIC		TARGET_MIXER_WRITE(SOUND_MIXER_MIC)
2124 #define TARGET_SOUND_MIXER_WRITE_CD		TARGET_MIXER_WRITE(SOUND_MIXER_CD)
2125 #define TARGET_SOUND_MIXER_WRITE_IMIX		TARGET_MIXER_WRITE(SOUND_MIXER_IMIX)
2126 #define TARGET_SOUND_MIXER_WRITE_ALTPCM	TARGET_MIXER_WRITE(SOUND_MIXER_ALTPCM)
2127 #define TARGET_SOUND_MIXER_WRITE_RECLEV	TARGET_MIXER_WRITE(SOUND_MIXER_RECLEV)
2128 #define TARGET_SOUND_MIXER_WRITE_IGAIN		TARGET_MIXER_WRITE(SOUND_MIXER_IGAIN)
2129 #define TARGET_SOUND_MIXER_WRITE_OGAIN		TARGET_MIXER_WRITE(SOUND_MIXER_OGAIN)
2130 #define TARGET_SOUND_MIXER_WRITE_LINE1		TARGET_MIXER_WRITE(SOUND_MIXER_LINE1)
2131 #define TARGET_SOUND_MIXER_WRITE_LINE2		TARGET_MIXER_WRITE(SOUND_MIXER_LINE2)
2132 #define TARGET_SOUND_MIXER_WRITE_LINE3		TARGET_MIXER_WRITE(SOUND_MIXER_LINE3)
2133 
2134 /* Obsolete macros */
2135 #define TARGET_SOUND_MIXER_WRITE_MUTE		TARGET_MIXER_WRITE(SOUND_MIXER_MUTE)
2136 #define TARGET_SOUND_MIXER_WRITE_ENHANCE	TARGET_MIXER_WRITE(SOUND_MIXER_ENHANCE)
2137 #define TARGET_SOUND_MIXER_WRITE_LOUD		TARGET_MIXER_WRITE(SOUND_MIXER_LOUD)
2138 
2139 #define TARGET_SOUND_MIXER_WRITE_RECSRC	TARGET_MIXER_WRITE(SOUND_MIXER_RECSRC)
2140 
2141 /* vfat ioctls */
2142 #define TARGET_VFAT_IOCTL_READDIR_BOTH    TARGET_IORU('r', 1)
2143 #define TARGET_VFAT_IOCTL_READDIR_SHORT   TARGET_IORU('r', 2)
2144 
2145 #define TARGET_MTIOCTOP        TARGET_IOW('m', 1, struct mtop)
2146 #define TARGET_MTIOCGET        TARGET_IOR('m', 2, struct mtget)
2147 #define TARGET_MTIOCPOS        TARGET_IOR('m', 3, struct mtpos)
2148 
2149 struct target_sysinfo {
2150     abi_long uptime;                /* Seconds since boot */
2151     abi_ulong loads[3];             /* 1, 5, and 15 minute load averages */
2152     abi_ulong totalram;             /* Total usable main memory size */
2153     abi_ulong freeram;              /* Available memory size */
2154     abi_ulong sharedram;            /* Amount of shared memory */
2155     abi_ulong bufferram;            /* Memory used by buffers */
2156     abi_ulong totalswap;            /* Total swap space size */
2157     abi_ulong freeswap;             /* swap space still available */
2158     unsigned short procs;           /* Number of current processes */
2159     unsigned short pad;             /* explicit padding for m68k */
2160     abi_ulong totalhigh;            /* Total high memory size */
2161     abi_ulong freehigh;             /* Available high memory size */
2162     unsigned int mem_unit;          /* Memory unit size in bytes */
2163     char _f[20-2*sizeof(abi_long)-sizeof(int)]; /* Padding: libc5 uses this.. */
2164 };
2165 
2166 struct linux_dirent {
2167     long            d_ino;
2168     unsigned long   d_off;
2169     unsigned short  d_reclen;
2170     char            d_name[256]; /* We must not include limits.h! */
2171 };
2172 
2173 struct linux_dirent64 {
2174     uint64_t        d_ino;
2175     int64_t         d_off;
2176     unsigned short  d_reclen;
2177     unsigned char   d_type;
2178     char            d_name[256];
2179 };
2180 
2181 struct target_mq_attr {
2182     abi_long mq_flags;
2183     abi_long mq_maxmsg;
2184     abi_long mq_msgsize;
2185     abi_long mq_curmsgs;
2186 };
2187 
2188 #include "socket.h"
2189 
2190 #include "errno_defs.h"
2191 
2192 #define FUTEX_WAIT              0
2193 #define FUTEX_WAKE              1
2194 #define FUTEX_FD                2
2195 #define FUTEX_REQUEUE           3
2196 #define FUTEX_CMP_REQUEUE       4
2197 #define FUTEX_WAKE_OP           5
2198 #define FUTEX_LOCK_PI           6
2199 #define FUTEX_UNLOCK_PI         7
2200 #define FUTEX_TRYLOCK_PI        8
2201 #define FUTEX_WAIT_BITSET       9
2202 #define FUTEX_WAKE_BITSET       10
2203 
2204 #define FUTEX_PRIVATE_FLAG      128
2205 #define FUTEX_CLOCK_REALTIME    256
2206 #define FUTEX_CMD_MASK          ~(FUTEX_PRIVATE_FLAG | FUTEX_CLOCK_REALTIME)
2207 
2208