4 * Copyright (c) 2003 Fabrice Bellard
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
19 #define _ATFILE_SOURCE
31 #include <sys/types.h>
37 #include <sys/mount.h>
38 #include <sys/prctl.h>
39 #include <sys/resource.h>
44 #include <sys/socket.h>
48 #include <sys/times.h>
51 #include <sys/statfs.h>
53 #include <sys/sysinfo.h>
54 #include <sys/utsname.h>
55 //#include <sys/user.h>
56 #include <netinet/ip.h>
57 #include <netinet/tcp.h>
58 #include <qemu-common.h>
63 #include <sys/eventfd.h>
66 #define termios host_termios
67 #define winsize host_winsize
68 #define termio host_termio
69 #define sgttyb host_sgttyb /* same as target */
70 #define tchars host_tchars /* same as target */
71 #define ltchars host_ltchars /* same as target */
73 #include <linux/termios.h>
74 #include <linux/unistd.h>
75 #include <linux/utsname.h>
76 #include <linux/cdrom.h>
77 #include <linux/hdreg.h>
78 #include <linux/soundcard.h>
80 #include <linux/mtio.h>
84 #include "linux_loop.h"
87 #include "qemu-common.h"
89 #if defined(CONFIG_USE_NPTL)
90 #define CLONE_NPTL_FLAGS2 (CLONE_SETTLS | \
91 CLONE_PARENT_SETTID | CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID)
93 /* XXX: Hardcode the above values. */
94 #define CLONE_NPTL_FLAGS2 0
99 //#include <linux/msdos_fs.h>
100 #define VFAT_IOCTL_READDIR_BOTH _IOR('r', 1, struct linux_dirent [2])
101 #define VFAT_IOCTL_READDIR_SHORT _IOR('r', 2, struct linux_dirent [2])
112 #define _syscall0(type,name) \
113 static type name (void) \
115 return syscall(__NR_##name); \
118 #define _syscall1(type,name,type1,arg1) \
119 static type name (type1 arg1) \
121 return syscall(__NR_##name, arg1); \
124 #define _syscall2(type,name,type1,arg1,type2,arg2) \
125 static type name (type1 arg1,type2 arg2) \
127 return syscall(__NR_##name, arg1, arg2); \
130 #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
131 static type name (type1 arg1,type2 arg2,type3 arg3) \
133 return syscall(__NR_##name, arg1, arg2, arg3); \
136 #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
137 static type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4) \
139 return syscall(__NR_##name, arg1, arg2, arg3, arg4); \
142 #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
144 static type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \
146 return syscall(__NR_##name, arg1, arg2, arg3, arg4, arg5); \
150 #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
151 type5,arg5,type6,arg6) \
152 static type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5, \
155 return syscall(__NR_##name, arg1, arg2, arg3, arg4, arg5, arg6); \
159 #define __NR_sys_uname __NR_uname
160 #define __NR_sys_faccessat __NR_faccessat
161 #define __NR_sys_fchmodat __NR_fchmodat
162 #define __NR_sys_fchownat __NR_fchownat
163 #define __NR_sys_fstatat64 __NR_fstatat64
164 #define __NR_sys_futimesat __NR_futimesat
165 #define __NR_sys_getcwd1 __NR_getcwd
166 #define __NR_sys_getdents __NR_getdents
167 #define __NR_sys_getdents64 __NR_getdents64
168 #define __NR_sys_getpriority __NR_getpriority
169 #define __NR_sys_linkat __NR_linkat
170 #define __NR_sys_mkdirat __NR_mkdirat
171 #define __NR_sys_mknodat __NR_mknodat
172 #define __NR_sys_newfstatat __NR_newfstatat
173 #define __NR_sys_openat __NR_openat
174 #define __NR_sys_readlinkat __NR_readlinkat
175 #define __NR_sys_renameat __NR_renameat
176 #define __NR_sys_rt_sigqueueinfo __NR_rt_sigqueueinfo
177 #define __NR_sys_symlinkat __NR_symlinkat
178 #define __NR_sys_syslog __NR_syslog
179 #define __NR_sys_tgkill __NR_tgkill
180 #define __NR_sys_tkill __NR_tkill
181 #define __NR_sys_unlinkat __NR_unlinkat
182 #define __NR_sys_utimensat __NR_utimensat
183 #define __NR_sys_futex __NR_futex
184 #define __NR_sys_inotify_init __NR_inotify_init
185 #define __NR_sys_inotify_add_watch __NR_inotify_add_watch
186 #define __NR_sys_inotify_rm_watch __NR_inotify_rm_watch
188 #if defined(__alpha__) || defined (__ia64__) || defined(__x86_64__)
189 #define __NR__llseek __NR_lseek
193 _syscall0(int, gettid
)
195 /* This is a replacement for the host gettid() and must return a host
197 static int gettid(void) {
201 _syscall3(int, sys_getdents
, uint
, fd
, struct linux_dirent
*, dirp
, uint
, count
);
202 #if defined(TARGET_NR_getdents64) && defined(__NR_getdents64)
203 _syscall3(int, sys_getdents64
, uint
, fd
, struct linux_dirent64
*, dirp
, uint
, count
);
205 _syscall2(int, sys_getpriority
, int, which
, int, who
);
206 #if defined(TARGET_NR__llseek) && !defined (__x86_64__)
207 _syscall5(int, _llseek
, uint
, fd
, ulong
, hi
, ulong
, lo
,
208 loff_t
*, res
, uint
, wh
);
210 _syscall3(int,sys_rt_sigqueueinfo
,int,pid
,int,sig
,siginfo_t
*,uinfo
)
211 _syscall3(int,sys_syslog
,int,type
,char*,bufp
,int,len
)
212 #if defined(TARGET_NR_tgkill) && defined(__NR_tgkill)
213 _syscall3(int,sys_tgkill
,int,tgid
,int,pid
,int,sig
)
215 #if defined(TARGET_NR_tkill) && defined(__NR_tkill)
216 _syscall2(int,sys_tkill
,int,tid
,int,sig
)
218 #ifdef __NR_exit_group
219 _syscall1(int,exit_group
,int,error_code
)
221 #if defined(TARGET_NR_set_tid_address) && defined(__NR_set_tid_address)
222 _syscall1(int,set_tid_address
,int *,tidptr
)
224 #if defined(CONFIG_USE_NPTL)
225 #if defined(TARGET_NR_futex) && defined(__NR_futex)
226 _syscall6(int,sys_futex
,int *,uaddr
,int,op
,int,val
,
227 const struct timespec
*,timeout
,int *,uaddr2
,int,val3
)
231 static bitmask_transtbl fcntl_flags_tbl
[] = {
232 { TARGET_O_ACCMODE
, TARGET_O_WRONLY
, O_ACCMODE
, O_WRONLY
, },
233 { TARGET_O_ACCMODE
, TARGET_O_RDWR
, O_ACCMODE
, O_RDWR
, },
234 { TARGET_O_CREAT
, TARGET_O_CREAT
, O_CREAT
, O_CREAT
, },
235 { TARGET_O_EXCL
, TARGET_O_EXCL
, O_EXCL
, O_EXCL
, },
236 { TARGET_O_NOCTTY
, TARGET_O_NOCTTY
, O_NOCTTY
, O_NOCTTY
, },
237 { TARGET_O_TRUNC
, TARGET_O_TRUNC
, O_TRUNC
, O_TRUNC
, },
238 { TARGET_O_APPEND
, TARGET_O_APPEND
, O_APPEND
, O_APPEND
, },
239 { TARGET_O_NONBLOCK
, TARGET_O_NONBLOCK
, O_NONBLOCK
, O_NONBLOCK
, },
240 { TARGET_O_SYNC
, TARGET_O_SYNC
, O_SYNC
, O_SYNC
, },
241 { TARGET_FASYNC
, TARGET_FASYNC
, FASYNC
, FASYNC
, },
242 { TARGET_O_DIRECTORY
, TARGET_O_DIRECTORY
, O_DIRECTORY
, O_DIRECTORY
, },
243 { TARGET_O_NOFOLLOW
, TARGET_O_NOFOLLOW
, O_NOFOLLOW
, O_NOFOLLOW
, },
244 { TARGET_O_LARGEFILE
, TARGET_O_LARGEFILE
, O_LARGEFILE
, O_LARGEFILE
, },
245 #if defined(O_DIRECT)
246 { TARGET_O_DIRECT
, TARGET_O_DIRECT
, O_DIRECT
, O_DIRECT
, },
251 #define COPY_UTSNAME_FIELD(dest, src) \
253 /* __NEW_UTS_LEN doesn't include terminating null */ \
254 (void) strncpy((dest), (src), __NEW_UTS_LEN); \
255 (dest)[__NEW_UTS_LEN] = '\0'; \
258 static int sys_uname(struct new_utsname
*buf
)
260 struct utsname uts_buf
;
262 if (uname(&uts_buf
) < 0)
266 * Just in case these have some differences, we
267 * translate utsname to new_utsname (which is the
268 * struct linux kernel uses).
271 bzero(buf
, sizeof (*buf
));
272 COPY_UTSNAME_FIELD(buf
->sysname
, uts_buf
.sysname
);
273 COPY_UTSNAME_FIELD(buf
->nodename
, uts_buf
.nodename
);
274 COPY_UTSNAME_FIELD(buf
->release
, uts_buf
.release
);
275 COPY_UTSNAME_FIELD(buf
->version
, uts_buf
.version
);
276 COPY_UTSNAME_FIELD(buf
->machine
, uts_buf
.machine
);
278 COPY_UTSNAME_FIELD(buf
->domainname
, uts_buf
.domainname
);
282 #undef COPY_UTSNAME_FIELD
285 static int sys_getcwd1(char *buf
, size_t size
)
287 if (getcwd(buf
, size
) == NULL
) {
288 /* getcwd() sets errno */
291 return strlen(buf
)+1;
296 * Host system seems to have atfile syscall stubs available. We
297 * now enable them one by one as specified by target syscall_nr.h.
300 #ifdef TARGET_NR_faccessat
301 static int sys_faccessat(int dirfd
, const char *pathname
, int mode
)
303 return (faccessat(dirfd
, pathname
, mode
, 0));
306 #ifdef TARGET_NR_fchmodat
307 static int sys_fchmodat(int dirfd
, const char *pathname
, mode_t mode
)
309 return (fchmodat(dirfd
, pathname
, mode
, 0));
312 #if defined(TARGET_NR_fchownat) && defined(USE_UID16)
313 static int sys_fchownat(int dirfd
, const char *pathname
, uid_t owner
,
314 gid_t group
, int flags
)
316 return (fchownat(dirfd
, pathname
, owner
, group
, flags
));
319 #ifdef __NR_fstatat64
320 static int sys_fstatat64(int dirfd
, const char *pathname
, struct stat
*buf
,
323 return (fstatat(dirfd
, pathname
, buf
, flags
));
326 #ifdef __NR_newfstatat
327 static int sys_newfstatat(int dirfd
, const char *pathname
, struct stat
*buf
,
330 return (fstatat(dirfd
, pathname
, buf
, flags
));
333 #ifdef TARGET_NR_futimesat
334 static int sys_futimesat(int dirfd
, const char *pathname
,
335 const struct timeval times
[2])
337 return (futimesat(dirfd
, pathname
, times
));
340 #ifdef TARGET_NR_linkat
341 static int sys_linkat(int olddirfd
, const char *oldpath
,
342 int newdirfd
, const char *newpath
, int flags
)
344 return (linkat(olddirfd
, oldpath
, newdirfd
, newpath
, flags
));
347 #ifdef TARGET_NR_mkdirat
348 static int sys_mkdirat(int dirfd
, const char *pathname
, mode_t mode
)
350 return (mkdirat(dirfd
, pathname
, mode
));
353 #ifdef TARGET_NR_mknodat
354 static int sys_mknodat(int dirfd
, const char *pathname
, mode_t mode
,
357 return (mknodat(dirfd
, pathname
, mode
, dev
));
360 #ifdef TARGET_NR_openat
361 static int sys_openat(int dirfd
, const char *pathname
, int flags
, ...)
364 * open(2) has extra parameter 'mode' when called with
367 if ((flags
& O_CREAT
) != 0) {
372 * Get the 'mode' parameter and translate it to
376 mode
= va_arg(ap
, mode_t
);
377 mode
= target_to_host_bitmask(mode
, fcntl_flags_tbl
);
380 return (openat(dirfd
, pathname
, flags
, mode
));
382 return (openat(dirfd
, pathname
, flags
));
385 #ifdef TARGET_NR_readlinkat
386 static int sys_readlinkat(int dirfd
, const char *pathname
, char *buf
, size_t bufsiz
)
388 return (readlinkat(dirfd
, pathname
, buf
, bufsiz
));
391 #ifdef TARGET_NR_renameat
392 static int sys_renameat(int olddirfd
, const char *oldpath
,
393 int newdirfd
, const char *newpath
)
395 return (renameat(olddirfd
, oldpath
, newdirfd
, newpath
));
398 #ifdef TARGET_NR_symlinkat
399 static int sys_symlinkat(const char *oldpath
, int newdirfd
, const char *newpath
)
401 return (symlinkat(oldpath
, newdirfd
, newpath
));
404 #ifdef TARGET_NR_unlinkat
405 static int sys_unlinkat(int dirfd
, const char *pathname
, int flags
)
407 return (unlinkat(dirfd
, pathname
, flags
));
410 #else /* !CONFIG_ATFILE */
413 * Try direct syscalls instead
415 #if defined(TARGET_NR_faccessat) && defined(__NR_faccessat)
416 _syscall3(int,sys_faccessat
,int,dirfd
,const char *,pathname
,int,mode
)
418 #if defined(TARGET_NR_fchmodat) && defined(__NR_fchmodat)
419 _syscall3(int,sys_fchmodat
,int,dirfd
,const char *,pathname
, mode_t
,mode
)
421 #if defined(TARGET_NR_fchownat) && defined(__NR_fchownat) && defined(USE_UID16)
422 _syscall5(int,sys_fchownat
,int,dirfd
,const char *,pathname
,
423 uid_t
,owner
,gid_t
,group
,int,flags
)
425 #if (defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat)) && \
426 defined(__NR_fstatat64)
427 _syscall4(int,sys_fstatat64
,int,dirfd
,const char *,pathname
,
428 struct stat
*,buf
,int,flags
)
430 #if defined(TARGET_NR_futimesat) && defined(__NR_futimesat)
431 _syscall3(int,sys_futimesat
,int,dirfd
,const char *,pathname
,
432 const struct timeval
*,times
)
434 #if (defined(TARGET_NR_newfstatat) || defined(TARGET_NR_fstatat64) ) && \
435 defined(__NR_newfstatat)
436 _syscall4(int,sys_newfstatat
,int,dirfd
,const char *,pathname
,
437 struct stat
*,buf
,int,flags
)
439 #if defined(TARGET_NR_linkat) && defined(__NR_linkat)
440 _syscall5(int,sys_linkat
,int,olddirfd
,const char *,oldpath
,
441 int,newdirfd
,const char *,newpath
,int,flags
)
443 #if defined(TARGET_NR_mkdirat) && defined(__NR_mkdirat)
444 _syscall3(int,sys_mkdirat
,int,dirfd
,const char *,pathname
,mode_t
,mode
)
446 #if defined(TARGET_NR_mknodat) && defined(__NR_mknodat)
447 _syscall4(int,sys_mknodat
,int,dirfd
,const char *,pathname
,
448 mode_t
,mode
,dev_t
,dev
)
450 #if defined(TARGET_NR_openat) && defined(__NR_openat)
451 _syscall4(int,sys_openat
,int,dirfd
,const char *,pathname
,int,flags
,mode_t
,mode
)
453 #if defined(TARGET_NR_readlinkat) && defined(__NR_readlinkat)
454 _syscall4(int,sys_readlinkat
,int,dirfd
,const char *,pathname
,
455 char *,buf
,size_t,bufsize
)
457 #if defined(TARGET_NR_renameat) && defined(__NR_renameat)
458 _syscall4(int,sys_renameat
,int,olddirfd
,const char *,oldpath
,
459 int,newdirfd
,const char *,newpath
)
461 #if defined(TARGET_NR_symlinkat) && defined(__NR_symlinkat)
462 _syscall3(int,sys_symlinkat
,const char *,oldpath
,
463 int,newdirfd
,const char *,newpath
)
465 #if defined(TARGET_NR_unlinkat) && defined(__NR_unlinkat)
466 _syscall3(int,sys_unlinkat
,int,dirfd
,const char *,pathname
,int,flags
)
469 #endif /* CONFIG_ATFILE */
471 #ifdef CONFIG_UTIMENSAT
472 static int sys_utimensat(int dirfd
, const char *pathname
,
473 const struct timespec times
[2], int flags
)
475 if (pathname
== NULL
)
476 return futimens(dirfd
, times
);
478 return utimensat(dirfd
, pathname
, times
, flags
);
481 #if defined(TARGET_NR_utimensat) && defined(__NR_utimensat)
482 _syscall4(int,sys_utimensat
,int,dirfd
,const char *,pathname
,
483 const struct timespec
*,tsp
,int,flags
)
485 #endif /* CONFIG_UTIMENSAT */
487 #ifdef CONFIG_INOTIFY
488 #include <sys/inotify.h>
490 #if defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init)
491 static int sys_inotify_init(void)
493 return (inotify_init());
496 #if defined(TARGET_NR_inotify_add_watch) && defined(__NR_inotify_add_watch)
497 static int sys_inotify_add_watch(int fd
,const char *pathname
, int32_t mask
)
499 return (inotify_add_watch(fd
, pathname
, mask
));
502 #if defined(TARGET_NR_inotify_rm_watch) && defined(__NR_inotify_rm_watch)
503 static int sys_inotify_rm_watch(int fd
, int32_t wd
)
505 return (inotify_rm_watch(fd
, wd
));
509 /* Userspace can usually survive runtime without inotify */
510 #undef TARGET_NR_inotify_init
511 #undef TARGET_NR_inotify_add_watch
512 #undef TARGET_NR_inotify_rm_watch
513 #endif /* CONFIG_INOTIFY */
516 extern int personality(int);
517 extern int flock(int, int);
518 extern int setfsuid(int);
519 extern int setfsgid(int);
520 extern int setgroups(int, gid_t
*);
522 #define ERRNO_TABLE_SIZE 1200
524 /* target_to_host_errno_table[] is initialized from
525 * host_to_target_errno_table[] in syscall_init(). */
526 static uint16_t target_to_host_errno_table
[ERRNO_TABLE_SIZE
] = {
530 * This list is the union of errno values overridden in asm-<arch>/errno.h
531 * minus the errnos that are not actually generic to all archs.
533 static uint16_t host_to_target_errno_table
[ERRNO_TABLE_SIZE
] = {
534 [EIDRM
] = TARGET_EIDRM
,
535 [ECHRNG
] = TARGET_ECHRNG
,
536 [EL2NSYNC
] = TARGET_EL2NSYNC
,
537 [EL3HLT
] = TARGET_EL3HLT
,
538 [EL3RST
] = TARGET_EL3RST
,
539 [ELNRNG
] = TARGET_ELNRNG
,
540 [EUNATCH
] = TARGET_EUNATCH
,
541 [ENOCSI
] = TARGET_ENOCSI
,
542 [EL2HLT
] = TARGET_EL2HLT
,
543 [EDEADLK
] = TARGET_EDEADLK
,
544 [ENOLCK
] = TARGET_ENOLCK
,
545 [EBADE
] = TARGET_EBADE
,
546 [EBADR
] = TARGET_EBADR
,
547 [EXFULL
] = TARGET_EXFULL
,
548 [ENOANO
] = TARGET_ENOANO
,
549 [EBADRQC
] = TARGET_EBADRQC
,
550 [EBADSLT
] = TARGET_EBADSLT
,
551 [EBFONT
] = TARGET_EBFONT
,
552 [ENOSTR
] = TARGET_ENOSTR
,
553 [ENODATA
] = TARGET_ENODATA
,
554 [ETIME
] = TARGET_ETIME
,
555 [ENOSR
] = TARGET_ENOSR
,
556 [ENONET
] = TARGET_ENONET
,
557 [ENOPKG
] = TARGET_ENOPKG
,
558 [EREMOTE
] = TARGET_EREMOTE
,
559 [ENOLINK
] = TARGET_ENOLINK
,
560 [EADV
] = TARGET_EADV
,
561 [ESRMNT
] = TARGET_ESRMNT
,
562 [ECOMM
] = TARGET_ECOMM
,
563 [EPROTO
] = TARGET_EPROTO
,
564 [EDOTDOT
] = TARGET_EDOTDOT
,
565 [EMULTIHOP
] = TARGET_EMULTIHOP
,
566 [EBADMSG
] = TARGET_EBADMSG
,
567 [ENAMETOOLONG
] = TARGET_ENAMETOOLONG
,
568 [EOVERFLOW
] = TARGET_EOVERFLOW
,
569 [ENOTUNIQ
] = TARGET_ENOTUNIQ
,
570 [EBADFD
] = TARGET_EBADFD
,
571 [EREMCHG
] = TARGET_EREMCHG
,
572 [ELIBACC
] = TARGET_ELIBACC
,
573 [ELIBBAD
] = TARGET_ELIBBAD
,
574 [ELIBSCN
] = TARGET_ELIBSCN
,
575 [ELIBMAX
] = TARGET_ELIBMAX
,
576 [ELIBEXEC
] = TARGET_ELIBEXEC
,
577 [EILSEQ
] = TARGET_EILSEQ
,
578 [ENOSYS
] = TARGET_ENOSYS
,
579 [ELOOP
] = TARGET_ELOOP
,
580 [ERESTART
] = TARGET_ERESTART
,
581 [ESTRPIPE
] = TARGET_ESTRPIPE
,
582 [ENOTEMPTY
] = TARGET_ENOTEMPTY
,
583 [EUSERS
] = TARGET_EUSERS
,
584 [ENOTSOCK
] = TARGET_ENOTSOCK
,
585 [EDESTADDRREQ
] = TARGET_EDESTADDRREQ
,
586 [EMSGSIZE
] = TARGET_EMSGSIZE
,
587 [EPROTOTYPE
] = TARGET_EPROTOTYPE
,
588 [ENOPROTOOPT
] = TARGET_ENOPROTOOPT
,
589 [EPROTONOSUPPORT
] = TARGET_EPROTONOSUPPORT
,
590 [ESOCKTNOSUPPORT
] = TARGET_ESOCKTNOSUPPORT
,
591 [EOPNOTSUPP
] = TARGET_EOPNOTSUPP
,
592 [EPFNOSUPPORT
] = TARGET_EPFNOSUPPORT
,
593 [EAFNOSUPPORT
] = TARGET_EAFNOSUPPORT
,
594 [EADDRINUSE
] = TARGET_EADDRINUSE
,
595 [EADDRNOTAVAIL
] = TARGET_EADDRNOTAVAIL
,
596 [ENETDOWN
] = TARGET_ENETDOWN
,
597 [ENETUNREACH
] = TARGET_ENETUNREACH
,
598 [ENETRESET
] = TARGET_ENETRESET
,
599 [ECONNABORTED
] = TARGET_ECONNABORTED
,
600 [ECONNRESET
] = TARGET_ECONNRESET
,
601 [ENOBUFS
] = TARGET_ENOBUFS
,
602 [EISCONN
] = TARGET_EISCONN
,
603 [ENOTCONN
] = TARGET_ENOTCONN
,
604 [EUCLEAN
] = TARGET_EUCLEAN
,
605 [ENOTNAM
] = TARGET_ENOTNAM
,
606 [ENAVAIL
] = TARGET_ENAVAIL
,
607 [EISNAM
] = TARGET_EISNAM
,
608 [EREMOTEIO
] = TARGET_EREMOTEIO
,
609 [ESHUTDOWN
] = TARGET_ESHUTDOWN
,
610 [ETOOMANYREFS
] = TARGET_ETOOMANYREFS
,
611 [ETIMEDOUT
] = TARGET_ETIMEDOUT
,
612 [ECONNREFUSED
] = TARGET_ECONNREFUSED
,
613 [EHOSTDOWN
] = TARGET_EHOSTDOWN
,
614 [EHOSTUNREACH
] = TARGET_EHOSTUNREACH
,
615 [EALREADY
] = TARGET_EALREADY
,
616 [EINPROGRESS
] = TARGET_EINPROGRESS
,
617 [ESTALE
] = TARGET_ESTALE
,
618 [ECANCELED
] = TARGET_ECANCELED
,
619 [ENOMEDIUM
] = TARGET_ENOMEDIUM
,
620 [EMEDIUMTYPE
] = TARGET_EMEDIUMTYPE
,
622 [ENOKEY
] = TARGET_ENOKEY
,
625 [EKEYEXPIRED
] = TARGET_EKEYEXPIRED
,
628 [EKEYREVOKED
] = TARGET_EKEYREVOKED
,
631 [EKEYREJECTED
] = TARGET_EKEYREJECTED
,
634 [EOWNERDEAD
] = TARGET_EOWNERDEAD
,
636 #ifdef ENOTRECOVERABLE
637 [ENOTRECOVERABLE
] = TARGET_ENOTRECOVERABLE
,
641 static inline int host_to_target_errno(int err
)
643 if(host_to_target_errno_table
[err
])
644 return host_to_target_errno_table
[err
];
648 static inline int target_to_host_errno(int err
)
650 if (target_to_host_errno_table
[err
])
651 return target_to_host_errno_table
[err
];
655 static inline abi_long
get_errno(abi_long ret
)
658 return -host_to_target_errno(errno
);
663 static inline int is_error(abi_long ret
)
665 return (abi_ulong
)ret
>= (abi_ulong
)(-4096);
668 char *target_strerror(int err
)
670 return strerror(target_to_host_errno(err
));
673 static abi_ulong target_brk
;
674 static abi_ulong target_original_brk
;
676 void target_set_brk(abi_ulong new_brk
)
678 target_original_brk
= target_brk
= HOST_PAGE_ALIGN(new_brk
);
681 /* do_brk() must return target values and target errnos. */
682 abi_long
do_brk(abi_ulong new_brk
)
685 abi_long mapped_addr
;
690 if (new_brk
< target_original_brk
)
693 brk_page
= HOST_PAGE_ALIGN(target_brk
);
695 /* If the new brk is less than this, set it and we're done... */
696 if (new_brk
< brk_page
) {
697 target_brk
= new_brk
;
701 /* We need to allocate more memory after the brk... */
702 new_alloc_size
= HOST_PAGE_ALIGN(new_brk
- brk_page
+ 1);
703 mapped_addr
= get_errno(target_mmap(brk_page
, new_alloc_size
,
704 PROT_READ
|PROT_WRITE
,
705 MAP_ANON
|MAP_FIXED
|MAP_PRIVATE
, 0, 0));
707 if (!is_error(mapped_addr
))
708 target_brk
= new_brk
;
713 static inline abi_long
copy_from_user_fdset(fd_set
*fds
,
714 abi_ulong target_fds_addr
,
718 abi_ulong b
, *target_fds
;
720 nw
= (n
+ TARGET_ABI_BITS
- 1) / TARGET_ABI_BITS
;
721 if (!(target_fds
= lock_user(VERIFY_READ
,
723 sizeof(abi_ulong
) * nw
,
725 return -TARGET_EFAULT
;
729 for (i
= 0; i
< nw
; i
++) {
730 /* grab the abi_ulong */
731 __get_user(b
, &target_fds
[i
]);
732 for (j
= 0; j
< TARGET_ABI_BITS
; j
++) {
733 /* check the bit inside the abi_ulong */
740 unlock_user(target_fds
, target_fds_addr
, 0);
745 static inline abi_long
copy_to_user_fdset(abi_ulong target_fds_addr
,
751 abi_ulong
*target_fds
;
753 nw
= (n
+ TARGET_ABI_BITS
- 1) / TARGET_ABI_BITS
;
754 if (!(target_fds
= lock_user(VERIFY_WRITE
,
756 sizeof(abi_ulong
) * nw
,
758 return -TARGET_EFAULT
;
761 for (i
= 0; i
< nw
; i
++) {
763 for (j
= 0; j
< TARGET_ABI_BITS
; j
++) {
764 v
|= ((FD_ISSET(k
, fds
) != 0) << j
);
767 __put_user(v
, &target_fds
[i
]);
770 unlock_user(target_fds
, target_fds_addr
, sizeof(abi_ulong
) * nw
);
775 #if defined(__alpha__)
781 static inline abi_long
host_to_target_clock_t(long ticks
)
783 #if HOST_HZ == TARGET_HZ
786 return ((int64_t)ticks
* TARGET_HZ
) / HOST_HZ
;
790 static inline abi_long
host_to_target_rusage(abi_ulong target_addr
,
791 const struct rusage
*rusage
)
793 struct target_rusage
*target_rusage
;
795 if (!lock_user_struct(VERIFY_WRITE
, target_rusage
, target_addr
, 0))
796 return -TARGET_EFAULT
;
797 target_rusage
->ru_utime
.tv_sec
= tswapl(rusage
->ru_utime
.tv_sec
);
798 target_rusage
->ru_utime
.tv_usec
= tswapl(rusage
->ru_utime
.tv_usec
);
799 target_rusage
->ru_stime
.tv_sec
= tswapl(rusage
->ru_stime
.tv_sec
);
800 target_rusage
->ru_stime
.tv_usec
= tswapl(rusage
->ru_stime
.tv_usec
);
801 target_rusage
->ru_maxrss
= tswapl(rusage
->ru_maxrss
);
802 target_rusage
->ru_ixrss
= tswapl(rusage
->ru_ixrss
);
803 target_rusage
->ru_idrss
= tswapl(rusage
->ru_idrss
);
804 target_rusage
->ru_isrss
= tswapl(rusage
->ru_isrss
);
805 target_rusage
->ru_minflt
= tswapl(rusage
->ru_minflt
);
806 target_rusage
->ru_majflt
= tswapl(rusage
->ru_majflt
);
807 target_rusage
->ru_nswap
= tswapl(rusage
->ru_nswap
);
808 target_rusage
->ru_inblock
= tswapl(rusage
->ru_inblock
);
809 target_rusage
->ru_oublock
= tswapl(rusage
->ru_oublock
);
810 target_rusage
->ru_msgsnd
= tswapl(rusage
->ru_msgsnd
);
811 target_rusage
->ru_msgrcv
= tswapl(rusage
->ru_msgrcv
);
812 target_rusage
->ru_nsignals
= tswapl(rusage
->ru_nsignals
);
813 target_rusage
->ru_nvcsw
= tswapl(rusage
->ru_nvcsw
);
814 target_rusage
->ru_nivcsw
= tswapl(rusage
->ru_nivcsw
);
815 unlock_user_struct(target_rusage
, target_addr
, 1);
820 static inline abi_long
copy_from_user_timeval(struct timeval
*tv
,
821 abi_ulong target_tv_addr
)
823 struct target_timeval
*target_tv
;
825 if (!lock_user_struct(VERIFY_READ
, target_tv
, target_tv_addr
, 1))
826 return -TARGET_EFAULT
;
828 __get_user(tv
->tv_sec
, &target_tv
->tv_sec
);
829 __get_user(tv
->tv_usec
, &target_tv
->tv_usec
);
831 unlock_user_struct(target_tv
, target_tv_addr
, 0);
836 static inline abi_long
copy_to_user_timeval(abi_ulong target_tv_addr
,
837 const struct timeval
*tv
)
839 struct target_timeval
*target_tv
;
841 if (!lock_user_struct(VERIFY_WRITE
, target_tv
, target_tv_addr
, 0))
842 return -TARGET_EFAULT
;
844 __put_user(tv
->tv_sec
, &target_tv
->tv_sec
);
845 __put_user(tv
->tv_usec
, &target_tv
->tv_usec
);
847 unlock_user_struct(target_tv
, target_tv_addr
, 1);
852 #if defined(TARGET_NR_mq_open) && defined(__NR_mq_open)
855 static inline abi_long
copy_from_user_mq_attr(struct mq_attr
*attr
,
856 abi_ulong target_mq_attr_addr
)
858 struct target_mq_attr
*target_mq_attr
;
860 if (!lock_user_struct(VERIFY_READ
, target_mq_attr
,
861 target_mq_attr_addr
, 1))
862 return -TARGET_EFAULT
;
864 __get_user(attr
->mq_flags
, &target_mq_attr
->mq_flags
);
865 __get_user(attr
->mq_maxmsg
, &target_mq_attr
->mq_maxmsg
);
866 __get_user(attr
->mq_msgsize
, &target_mq_attr
->mq_msgsize
);
867 __get_user(attr
->mq_curmsgs
, &target_mq_attr
->mq_curmsgs
);
869 unlock_user_struct(target_mq_attr
, target_mq_attr_addr
, 0);
874 static inline abi_long
copy_to_user_mq_attr(abi_ulong target_mq_attr_addr
,
875 const struct mq_attr
*attr
)
877 struct target_mq_attr
*target_mq_attr
;
879 if (!lock_user_struct(VERIFY_WRITE
, target_mq_attr
,
880 target_mq_attr_addr
, 0))
881 return -TARGET_EFAULT
;
883 __put_user(attr
->mq_flags
, &target_mq_attr
->mq_flags
);
884 __put_user(attr
->mq_maxmsg
, &target_mq_attr
->mq_maxmsg
);
885 __put_user(attr
->mq_msgsize
, &target_mq_attr
->mq_msgsize
);
886 __put_user(attr
->mq_curmsgs
, &target_mq_attr
->mq_curmsgs
);
888 unlock_user_struct(target_mq_attr
, target_mq_attr_addr
, 1);
894 /* do_select() must return target values and target errnos. */
895 static abi_long
do_select(int n
,
896 abi_ulong rfd_addr
, abi_ulong wfd_addr
,
897 abi_ulong efd_addr
, abi_ulong target_tv_addr
)
899 fd_set rfds
, wfds
, efds
;
900 fd_set
*rfds_ptr
, *wfds_ptr
, *efds_ptr
;
901 struct timeval tv
, *tv_ptr
;
905 if (copy_from_user_fdset(&rfds
, rfd_addr
, n
))
906 return -TARGET_EFAULT
;
912 if (copy_from_user_fdset(&wfds
, wfd_addr
, n
))
913 return -TARGET_EFAULT
;
919 if (copy_from_user_fdset(&efds
, efd_addr
, n
))
920 return -TARGET_EFAULT
;
926 if (target_tv_addr
) {
927 if (copy_from_user_timeval(&tv
, target_tv_addr
))
928 return -TARGET_EFAULT
;
934 ret
= get_errno(select(n
, rfds_ptr
, wfds_ptr
, efds_ptr
, tv_ptr
));
936 if (!is_error(ret
)) {
937 if (rfd_addr
&& copy_to_user_fdset(rfd_addr
, &rfds
, n
))
938 return -TARGET_EFAULT
;
939 if (wfd_addr
&& copy_to_user_fdset(wfd_addr
, &wfds
, n
))
940 return -TARGET_EFAULT
;
941 if (efd_addr
&& copy_to_user_fdset(efd_addr
, &efds
, n
))
942 return -TARGET_EFAULT
;
944 if (target_tv_addr
&& copy_to_user_timeval(target_tv_addr
, &tv
))
945 return -TARGET_EFAULT
;
951 static abi_long
do_pipe2(int host_pipe
[], int flags
)
954 return pipe2(host_pipe
, flags
);
960 static abi_long
do_pipe(void *cpu_env
, abi_ulong pipedes
, int flags
)
964 ret
= flags
? do_pipe2(host_pipe
, flags
) : pipe(host_pipe
);
967 return get_errno(ret
);
968 #if defined(TARGET_MIPS)
969 ((CPUMIPSState
*)cpu_env
)->active_tc
.gpr
[3] = host_pipe
[1];
971 #elif defined(TARGET_SH4)
972 ((CPUSH4State
*)cpu_env
)->gregs
[1] = host_pipe
[1];
975 if (put_user_s32(host_pipe
[0], pipedes
)
976 || put_user_s32(host_pipe
[1], pipedes
+ sizeof(host_pipe
[0])))
977 return -TARGET_EFAULT
;
979 return get_errno(ret
);
982 static inline abi_long
target_to_host_ip_mreq(struct ip_mreqn
*mreqn
,
983 abi_ulong target_addr
,
986 struct target_ip_mreqn
*target_smreqn
;
988 target_smreqn
= lock_user(VERIFY_READ
, target_addr
, len
, 1);
990 return -TARGET_EFAULT
;
991 mreqn
->imr_multiaddr
.s_addr
= target_smreqn
->imr_multiaddr
.s_addr
;
992 mreqn
->imr_address
.s_addr
= target_smreqn
->imr_address
.s_addr
;
993 if (len
== sizeof(struct target_ip_mreqn
))
994 mreqn
->imr_ifindex
= tswapl(target_smreqn
->imr_ifindex
);
995 unlock_user(target_smreqn
, target_addr
, 0);
1000 static inline abi_long
target_to_host_sockaddr(struct sockaddr
*addr
,
1001 abi_ulong target_addr
,
1004 const socklen_t unix_maxlen
= sizeof (struct sockaddr_un
);
1005 sa_family_t sa_family
;
1006 struct target_sockaddr
*target_saddr
;
1008 target_saddr
= lock_user(VERIFY_READ
, target_addr
, len
, 1);
1010 return -TARGET_EFAULT
;
1012 sa_family
= tswap16(target_saddr
->sa_family
);
1014 /* Oops. The caller might send a incomplete sun_path; sun_path
1015 * must be terminated by \0 (see the manual page), but
1016 * unfortunately it is quite common to specify sockaddr_un
1017 * length as "strlen(x->sun_path)" while it should be
1018 * "strlen(...) + 1". We'll fix that here if needed.
1019 * Linux kernel has a similar feature.
1022 if (sa_family
== AF_UNIX
) {
1023 if (len
< unix_maxlen
&& len
> 0) {
1024 char *cp
= (char*)target_saddr
;
1026 if ( cp
[len
-1] && !cp
[len
] )
1029 if (len
> unix_maxlen
)
1033 memcpy(addr
, target_saddr
, len
);
1034 addr
->sa_family
= sa_family
;
1035 unlock_user(target_saddr
, target_addr
, 0);
1040 static inline abi_long
host_to_target_sockaddr(abi_ulong target_addr
,
1041 struct sockaddr
*addr
,
1044 struct target_sockaddr
*target_saddr
;
1046 target_saddr
= lock_user(VERIFY_WRITE
, target_addr
, len
, 0);
1048 return -TARGET_EFAULT
;
1049 memcpy(target_saddr
, addr
, len
);
1050 target_saddr
->sa_family
= tswap16(addr
->sa_family
);
1051 unlock_user(target_saddr
, target_addr
, len
);
1056 /* ??? Should this also swap msgh->name? */
1057 static inline abi_long
target_to_host_cmsg(struct msghdr
*msgh
,
1058 struct target_msghdr
*target_msgh
)
1060 struct cmsghdr
*cmsg
= CMSG_FIRSTHDR(msgh
);
1061 abi_long msg_controllen
;
1062 abi_ulong target_cmsg_addr
;
1063 struct target_cmsghdr
*target_cmsg
;
1064 socklen_t space
= 0;
1066 msg_controllen
= tswapl(target_msgh
->msg_controllen
);
1067 if (msg_controllen
< sizeof (struct target_cmsghdr
))
1069 target_cmsg_addr
= tswapl(target_msgh
->msg_control
);
1070 target_cmsg
= lock_user(VERIFY_READ
, target_cmsg_addr
, msg_controllen
, 1);
1072 return -TARGET_EFAULT
;
1074 while (cmsg
&& target_cmsg
) {
1075 void *data
= CMSG_DATA(cmsg
);
1076 void *target_data
= TARGET_CMSG_DATA(target_cmsg
);
1078 int len
= tswapl(target_cmsg
->cmsg_len
)
1079 - TARGET_CMSG_ALIGN(sizeof (struct target_cmsghdr
));
1081 space
+= CMSG_SPACE(len
);
1082 if (space
> msgh
->msg_controllen
) {
1083 space
-= CMSG_SPACE(len
);
1084 gemu_log("Host cmsg overflow\n");
1088 cmsg
->cmsg_level
= tswap32(target_cmsg
->cmsg_level
);
1089 cmsg
->cmsg_type
= tswap32(target_cmsg
->cmsg_type
);
1090 cmsg
->cmsg_len
= CMSG_LEN(len
);
1092 if (cmsg
->cmsg_level
!= TARGET_SOL_SOCKET
|| cmsg
->cmsg_type
!= SCM_RIGHTS
) {
1093 gemu_log("Unsupported ancillary data: %d/%d\n", cmsg
->cmsg_level
, cmsg
->cmsg_type
);
1094 memcpy(data
, target_data
, len
);
1096 int *fd
= (int *)data
;
1097 int *target_fd
= (int *)target_data
;
1098 int i
, numfds
= len
/ sizeof(int);
1100 for (i
= 0; i
< numfds
; i
++)
1101 fd
[i
] = tswap32(target_fd
[i
]);
1104 cmsg
= CMSG_NXTHDR(msgh
, cmsg
);
1105 target_cmsg
= TARGET_CMSG_NXTHDR(target_msgh
, target_cmsg
);
1107 unlock_user(target_cmsg
, target_cmsg_addr
, 0);
1109 msgh
->msg_controllen
= space
;
1113 /* ??? Should this also swap msgh->name? */
1114 static inline abi_long
host_to_target_cmsg(struct target_msghdr
*target_msgh
,
1115 struct msghdr
*msgh
)
1117 struct cmsghdr
*cmsg
= CMSG_FIRSTHDR(msgh
);
1118 abi_long msg_controllen
;
1119 abi_ulong target_cmsg_addr
;
1120 struct target_cmsghdr
*target_cmsg
;
1121 socklen_t space
= 0;
1123 msg_controllen
= tswapl(target_msgh
->msg_controllen
);
1124 if (msg_controllen
< sizeof (struct target_cmsghdr
))
1126 target_cmsg_addr
= tswapl(target_msgh
->msg_control
);
1127 target_cmsg
= lock_user(VERIFY_WRITE
, target_cmsg_addr
, msg_controllen
, 0);
1129 return -TARGET_EFAULT
;
1131 while (cmsg
&& target_cmsg
) {
1132 void *data
= CMSG_DATA(cmsg
);
1133 void *target_data
= TARGET_CMSG_DATA(target_cmsg
);
1135 int len
= cmsg
->cmsg_len
- CMSG_ALIGN(sizeof (struct cmsghdr
));
1137 space
+= TARGET_CMSG_SPACE(len
);
1138 if (space
> msg_controllen
) {
1139 space
-= TARGET_CMSG_SPACE(len
);
1140 gemu_log("Target cmsg overflow\n");
1144 target_cmsg
->cmsg_level
= tswap32(cmsg
->cmsg_level
);
1145 target_cmsg
->cmsg_type
= tswap32(cmsg
->cmsg_type
);
1146 target_cmsg
->cmsg_len
= tswapl(TARGET_CMSG_LEN(len
));
1148 if (cmsg
->cmsg_level
!= TARGET_SOL_SOCKET
|| cmsg
->cmsg_type
!= SCM_RIGHTS
) {
1149 gemu_log("Unsupported ancillary data: %d/%d\n", cmsg
->cmsg_level
, cmsg
->cmsg_type
);
1150 memcpy(target_data
, data
, len
);
1152 int *fd
= (int *)data
;
1153 int *target_fd
= (int *)target_data
;
1154 int i
, numfds
= len
/ sizeof(int);
1156 for (i
= 0; i
< numfds
; i
++)
1157 target_fd
[i
] = tswap32(fd
[i
]);
1160 cmsg
= CMSG_NXTHDR(msgh
, cmsg
);
1161 target_cmsg
= TARGET_CMSG_NXTHDR(target_msgh
, target_cmsg
);
1163 unlock_user(target_cmsg
, target_cmsg_addr
, space
);
1165 target_msgh
->msg_controllen
= tswapl(space
);
1169 /* do_setsockopt() Must return target values and target errnos. */
1170 static abi_long
do_setsockopt(int sockfd
, int level
, int optname
,
1171 abi_ulong optval_addr
, socklen_t optlen
)
1175 struct ip_mreqn
*ip_mreq
;
1176 struct ip_mreq_source
*ip_mreq_source
;
1180 /* TCP options all take an 'int' value. */
1181 if (optlen
< sizeof(uint32_t))
1182 return -TARGET_EINVAL
;
1184 if (get_user_u32(val
, optval_addr
))
1185 return -TARGET_EFAULT
;
1186 ret
= get_errno(setsockopt(sockfd
, level
, optname
, &val
, sizeof(val
)));
1193 case IP_ROUTER_ALERT
:
1197 case IP_MTU_DISCOVER
:
1203 case IP_MULTICAST_TTL
:
1204 case IP_MULTICAST_LOOP
:
1206 if (optlen
>= sizeof(uint32_t)) {
1207 if (get_user_u32(val
, optval_addr
))
1208 return -TARGET_EFAULT
;
1209 } else if (optlen
>= 1) {
1210 if (get_user_u8(val
, optval_addr
))
1211 return -TARGET_EFAULT
;
1213 ret
= get_errno(setsockopt(sockfd
, level
, optname
, &val
, sizeof(val
)));
1215 case IP_ADD_MEMBERSHIP
:
1216 case IP_DROP_MEMBERSHIP
:
1217 if (optlen
< sizeof (struct target_ip_mreq
) ||
1218 optlen
> sizeof (struct target_ip_mreqn
))
1219 return -TARGET_EINVAL
;
1221 ip_mreq
= (struct ip_mreqn
*) alloca(optlen
);
1222 target_to_host_ip_mreq(ip_mreq
, optval_addr
, optlen
);
1223 ret
= get_errno(setsockopt(sockfd
, level
, optname
, ip_mreq
, optlen
));
1226 case IP_BLOCK_SOURCE
:
1227 case IP_UNBLOCK_SOURCE
:
1228 case IP_ADD_SOURCE_MEMBERSHIP
:
1229 case IP_DROP_SOURCE_MEMBERSHIP
:
1230 if (optlen
!= sizeof (struct target_ip_mreq_source
))
1231 return -TARGET_EINVAL
;
1233 ip_mreq_source
= lock_user(VERIFY_READ
, optval_addr
, optlen
, 1);
1234 ret
= get_errno(setsockopt(sockfd
, level
, optname
, ip_mreq_source
, optlen
));
1235 unlock_user (ip_mreq_source
, optval_addr
, 0);
1242 case TARGET_SOL_SOCKET
:
1244 /* Options with 'int' argument. */
1245 case TARGET_SO_DEBUG
:
1248 case TARGET_SO_REUSEADDR
:
1249 optname
= SO_REUSEADDR
;
1251 case TARGET_SO_TYPE
:
1254 case TARGET_SO_ERROR
:
1257 case TARGET_SO_DONTROUTE
:
1258 optname
= SO_DONTROUTE
;
1260 case TARGET_SO_BROADCAST
:
1261 optname
= SO_BROADCAST
;
1263 case TARGET_SO_SNDBUF
:
1264 optname
= SO_SNDBUF
;
1266 case TARGET_SO_RCVBUF
:
1267 optname
= SO_RCVBUF
;
1269 case TARGET_SO_KEEPALIVE
:
1270 optname
= SO_KEEPALIVE
;
1272 case TARGET_SO_OOBINLINE
:
1273 optname
= SO_OOBINLINE
;
1275 case TARGET_SO_NO_CHECK
:
1276 optname
= SO_NO_CHECK
;
1278 case TARGET_SO_PRIORITY
:
1279 optname
= SO_PRIORITY
;
1282 case TARGET_SO_BSDCOMPAT
:
1283 optname
= SO_BSDCOMPAT
;
1286 case TARGET_SO_PASSCRED
:
1287 optname
= SO_PASSCRED
;
1289 case TARGET_SO_TIMESTAMP
:
1290 optname
= SO_TIMESTAMP
;
1292 case TARGET_SO_RCVLOWAT
:
1293 optname
= SO_RCVLOWAT
;
1295 case TARGET_SO_RCVTIMEO
:
1296 optname
= SO_RCVTIMEO
;
1298 case TARGET_SO_SNDTIMEO
:
1299 optname
= SO_SNDTIMEO
;
1305 if (optlen
< sizeof(uint32_t))
1306 return -TARGET_EINVAL
;
1308 if (get_user_u32(val
, optval_addr
))
1309 return -TARGET_EFAULT
;
1310 ret
= get_errno(setsockopt(sockfd
, SOL_SOCKET
, optname
, &val
, sizeof(val
)));
1314 gemu_log("Unsupported setsockopt level=%d optname=%d \n", level
, optname
);
1315 ret
= -TARGET_ENOPROTOOPT
;
1320 /* do_getsockopt() Must return target values and target errnos. */
1321 static abi_long
do_getsockopt(int sockfd
, int level
, int optname
,
1322 abi_ulong optval_addr
, abi_ulong optlen
)
1329 case TARGET_SOL_SOCKET
:
1332 case TARGET_SO_LINGER
:
1333 case TARGET_SO_RCVTIMEO
:
1334 case TARGET_SO_SNDTIMEO
:
1335 case TARGET_SO_PEERCRED
:
1336 case TARGET_SO_PEERNAME
:
1337 /* These don't just return a single integer */
1344 /* TCP options all take an 'int' value. */
1346 if (get_user_u32(len
, optlen
))
1347 return -TARGET_EFAULT
;
1349 return -TARGET_EINVAL
;
1351 ret
= get_errno(getsockopt(sockfd
, level
, optname
, &val
, &lv
));
1357 if (put_user_u32(val
, optval_addr
))
1358 return -TARGET_EFAULT
;
1360 if (put_user_u8(val
, optval_addr
))
1361 return -TARGET_EFAULT
;
1363 if (put_user_u32(len
, optlen
))
1364 return -TARGET_EFAULT
;
1371 case IP_ROUTER_ALERT
:
1375 case IP_MTU_DISCOVER
:
1381 case IP_MULTICAST_TTL
:
1382 case IP_MULTICAST_LOOP
:
1383 if (get_user_u32(len
, optlen
))
1384 return -TARGET_EFAULT
;
1386 return -TARGET_EINVAL
;
1388 ret
= get_errno(getsockopt(sockfd
, level
, optname
, &val
, &lv
));
1391 if (len
< sizeof(int) && len
> 0 && val
>= 0 && val
< 255) {
1393 if (put_user_u32(len
, optlen
)
1394 || put_user_u8(val
, optval_addr
))
1395 return -TARGET_EFAULT
;
1397 if (len
> sizeof(int))
1399 if (put_user_u32(len
, optlen
)
1400 || put_user_u32(val
, optval_addr
))
1401 return -TARGET_EFAULT
;
1405 ret
= -TARGET_ENOPROTOOPT
;
1411 gemu_log("getsockopt level=%d optname=%d not yet supported\n",
1413 ret
= -TARGET_EOPNOTSUPP
;
1420 * lock_iovec()/unlock_iovec() have a return code of 0 for success where
1421 * other lock functions have a return code of 0 for failure.
1423 static abi_long
lock_iovec(int type
, struct iovec
*vec
, abi_ulong target_addr
,
1424 int count
, int copy
)
1426 struct target_iovec
*target_vec
;
1430 target_vec
= lock_user(VERIFY_READ
, target_addr
, count
* sizeof(struct target_iovec
), 1);
1432 return -TARGET_EFAULT
;
1433 for(i
= 0;i
< count
; i
++) {
1434 base
= tswapl(target_vec
[i
].iov_base
);
1435 vec
[i
].iov_len
= tswapl(target_vec
[i
].iov_len
);
1436 if (vec
[i
].iov_len
!= 0) {
1437 vec
[i
].iov_base
= lock_user(type
, base
, vec
[i
].iov_len
, copy
);
1438 /* Don't check lock_user return value. We must call writev even
1439 if a element has invalid base address. */
1441 /* zero length pointer is ignored */
1442 vec
[i
].iov_base
= NULL
;
1445 unlock_user (target_vec
, target_addr
, 0);
1449 static abi_long
unlock_iovec(struct iovec
*vec
, abi_ulong target_addr
,
1450 int count
, int copy
)
1452 struct target_iovec
*target_vec
;
1456 target_vec
= lock_user(VERIFY_READ
, target_addr
, count
* sizeof(struct target_iovec
), 1);
1458 return -TARGET_EFAULT
;
1459 for(i
= 0;i
< count
; i
++) {
1460 if (target_vec
[i
].iov_base
) {
1461 base
= tswapl(target_vec
[i
].iov_base
);
1462 unlock_user(vec
[i
].iov_base
, base
, copy
? vec
[i
].iov_len
: 0);
1465 unlock_user (target_vec
, target_addr
, 0);
1470 /* do_socket() Must return target values and target errnos. */
1471 static abi_long
do_socket(int domain
, int type
, int protocol
)
1473 #if defined(TARGET_MIPS)
1475 case TARGET_SOCK_DGRAM
:
1478 case TARGET_SOCK_STREAM
:
1481 case TARGET_SOCK_RAW
:
1484 case TARGET_SOCK_RDM
:
1487 case TARGET_SOCK_SEQPACKET
:
1488 type
= SOCK_SEQPACKET
;
1490 case TARGET_SOCK_PACKET
:
1495 if (domain
== PF_NETLINK
)
1496 return -EAFNOSUPPORT
; /* do not NETLINK socket connections possible */
1497 return get_errno(socket(domain
, type
, protocol
));
1500 /* do_bind() Must return target values and target errnos. */
1501 static abi_long
do_bind(int sockfd
, abi_ulong target_addr
,
1508 return -TARGET_EINVAL
;
1510 addr
= alloca(addrlen
+1);
1512 ret
= target_to_host_sockaddr(addr
, target_addr
, addrlen
);
1516 return get_errno(bind(sockfd
, addr
, addrlen
));
1519 /* do_connect() Must return target values and target errnos. */
1520 static abi_long
do_connect(int sockfd
, abi_ulong target_addr
,
1527 return -TARGET_EINVAL
;
1529 addr
= alloca(addrlen
);
1531 ret
= target_to_host_sockaddr(addr
, target_addr
, addrlen
);
1535 return get_errno(connect(sockfd
, addr
, addrlen
));
1538 /* do_sendrecvmsg() Must return target values and target errnos. */
1539 static abi_long
do_sendrecvmsg(int fd
, abi_ulong target_msg
,
1540 int flags
, int send
)
1543 struct target_msghdr
*msgp
;
1547 abi_ulong target_vec
;
1550 if (!lock_user_struct(send
? VERIFY_READ
: VERIFY_WRITE
,
1554 return -TARGET_EFAULT
;
1555 if (msgp
->msg_name
) {
1556 msg
.msg_namelen
= tswap32(msgp
->msg_namelen
);
1557 msg
.msg_name
= alloca(msg
.msg_namelen
);
1558 ret
= target_to_host_sockaddr(msg
.msg_name
, tswapl(msgp
->msg_name
),
1561 unlock_user_struct(msgp
, target_msg
, send
? 0 : 1);
1565 msg
.msg_name
= NULL
;
1566 msg
.msg_namelen
= 0;
1568 msg
.msg_controllen
= 2 * tswapl(msgp
->msg_controllen
);
1569 msg
.msg_control
= alloca(msg
.msg_controllen
);
1570 msg
.msg_flags
= tswap32(msgp
->msg_flags
);
1572 count
= tswapl(msgp
->msg_iovlen
);
1573 vec
= alloca(count
* sizeof(struct iovec
));
1574 target_vec
= tswapl(msgp
->msg_iov
);
1575 lock_iovec(send
? VERIFY_READ
: VERIFY_WRITE
, vec
, target_vec
, count
, send
);
1576 msg
.msg_iovlen
= count
;
1580 ret
= target_to_host_cmsg(&msg
, msgp
);
1582 ret
= get_errno(sendmsg(fd
, &msg
, flags
));
1584 ret
= get_errno(recvmsg(fd
, &msg
, flags
));
1585 if (!is_error(ret
)) {
1587 ret
= host_to_target_cmsg(msgp
, &msg
);
1592 unlock_iovec(vec
, target_vec
, count
, !send
);
1593 unlock_user_struct(msgp
, target_msg
, send
? 0 : 1);
1597 /* do_accept() Must return target values and target errnos. */
1598 static abi_long
do_accept(int fd
, abi_ulong target_addr
,
1599 abi_ulong target_addrlen_addr
)
1605 if (target_addr
== 0)
1606 return get_errno(accept(fd
, NULL
, NULL
));
1608 /* linux returns EINVAL if addrlen pointer is invalid */
1609 if (get_user_u32(addrlen
, target_addrlen_addr
))
1610 return -TARGET_EINVAL
;
1613 return -TARGET_EINVAL
;
1615 if (!access_ok(VERIFY_WRITE
, target_addr
, addrlen
))
1616 return -TARGET_EINVAL
;
1618 addr
= alloca(addrlen
);
1620 ret
= get_errno(accept(fd
, addr
, &addrlen
));
1621 if (!is_error(ret
)) {
1622 host_to_target_sockaddr(target_addr
, addr
, addrlen
);
1623 if (put_user_u32(addrlen
, target_addrlen_addr
))
1624 ret
= -TARGET_EFAULT
;
1629 /* do_getpeername() Must return target values and target errnos. */
1630 static abi_long
do_getpeername(int fd
, abi_ulong target_addr
,
1631 abi_ulong target_addrlen_addr
)
1637 if (get_user_u32(addrlen
, target_addrlen_addr
))
1638 return -TARGET_EFAULT
;
1641 return -TARGET_EINVAL
;
1643 if (!access_ok(VERIFY_WRITE
, target_addr
, addrlen
))
1644 return -TARGET_EFAULT
;
1646 addr
= alloca(addrlen
);
1648 ret
= get_errno(getpeername(fd
, addr
, &addrlen
));
1649 if (!is_error(ret
)) {
1650 host_to_target_sockaddr(target_addr
, addr
, addrlen
);
1651 if (put_user_u32(addrlen
, target_addrlen_addr
))
1652 ret
= -TARGET_EFAULT
;
1657 /* do_getsockname() Must return target values and target errnos. */
1658 static abi_long
do_getsockname(int fd
, abi_ulong target_addr
,
1659 abi_ulong target_addrlen_addr
)
1665 if (get_user_u32(addrlen
, target_addrlen_addr
))
1666 return -TARGET_EFAULT
;
1669 return -TARGET_EINVAL
;
1671 if (!access_ok(VERIFY_WRITE
, target_addr
, addrlen
))
1672 return -TARGET_EFAULT
;
1674 addr
= alloca(addrlen
);
1676 ret
= get_errno(getsockname(fd
, addr
, &addrlen
));
1677 if (!is_error(ret
)) {
1678 host_to_target_sockaddr(target_addr
, addr
, addrlen
);
1679 if (put_user_u32(addrlen
, target_addrlen_addr
))
1680 ret
= -TARGET_EFAULT
;
1685 /* do_socketpair() Must return target values and target errnos. */
1686 static abi_long
do_socketpair(int domain
, int type
, int protocol
,
1687 abi_ulong target_tab_addr
)
1692 ret
= get_errno(socketpair(domain
, type
, protocol
, tab
));
1693 if (!is_error(ret
)) {
1694 if (put_user_s32(tab
[0], target_tab_addr
)
1695 || put_user_s32(tab
[1], target_tab_addr
+ sizeof(tab
[0])))
1696 ret
= -TARGET_EFAULT
;
1701 /* do_sendto() Must return target values and target errnos. */
1702 static abi_long
do_sendto(int fd
, abi_ulong msg
, size_t len
, int flags
,
1703 abi_ulong target_addr
, socklen_t addrlen
)
1710 return -TARGET_EINVAL
;
1712 host_msg
= lock_user(VERIFY_READ
, msg
, len
, 1);
1714 return -TARGET_EFAULT
;
1716 addr
= alloca(addrlen
);
1717 ret
= target_to_host_sockaddr(addr
, target_addr
, addrlen
);
1719 unlock_user(host_msg
, msg
, 0);
1722 ret
= get_errno(sendto(fd
, host_msg
, len
, flags
, addr
, addrlen
));
1724 ret
= get_errno(send(fd
, host_msg
, len
, flags
));
1726 unlock_user(host_msg
, msg
, 0);
1730 /* do_recvfrom() Must return target values and target errnos. */
1731 static abi_long
do_recvfrom(int fd
, abi_ulong msg
, size_t len
, int flags
,
1732 abi_ulong target_addr
,
1733 abi_ulong target_addrlen
)
1740 host_msg
= lock_user(VERIFY_WRITE
, msg
, len
, 0);
1742 return -TARGET_EFAULT
;
1744 if (get_user_u32(addrlen
, target_addrlen
)) {
1745 ret
= -TARGET_EFAULT
;
1749 ret
= -TARGET_EINVAL
;
1752 addr
= alloca(addrlen
);
1753 ret
= get_errno(recvfrom(fd
, host_msg
, len
, flags
, addr
, &addrlen
));
1755 addr
= NULL
; /* To keep compiler quiet. */
1756 ret
= get_errno(recv(fd
, host_msg
, len
, flags
));
1758 if (!is_error(ret
)) {
1760 host_to_target_sockaddr(target_addr
, addr
, addrlen
);
1761 if (put_user_u32(addrlen
, target_addrlen
)) {
1762 ret
= -TARGET_EFAULT
;
1766 unlock_user(host_msg
, msg
, len
);
1769 unlock_user(host_msg
, msg
, 0);
1774 #ifdef TARGET_NR_socketcall
1775 /* do_socketcall() Must return target values and target errnos. */
1776 static abi_long
do_socketcall(int num
, abi_ulong vptr
)
1779 const int n
= sizeof(abi_ulong
);
1784 abi_ulong domain
, type
, protocol
;
1786 if (get_user_ual(domain
, vptr
)
1787 || get_user_ual(type
, vptr
+ n
)
1788 || get_user_ual(protocol
, vptr
+ 2 * n
))
1789 return -TARGET_EFAULT
;
1791 ret
= do_socket(domain
, type
, protocol
);
1797 abi_ulong target_addr
;
1800 if (get_user_ual(sockfd
, vptr
)
1801 || get_user_ual(target_addr
, vptr
+ n
)
1802 || get_user_ual(addrlen
, vptr
+ 2 * n
))
1803 return -TARGET_EFAULT
;
1805 ret
= do_bind(sockfd
, target_addr
, addrlen
);
1808 case SOCKOP_connect
:
1811 abi_ulong target_addr
;
1814 if (get_user_ual(sockfd
, vptr
)
1815 || get_user_ual(target_addr
, vptr
+ n
)
1816 || get_user_ual(addrlen
, vptr
+ 2 * n
))
1817 return -TARGET_EFAULT
;
1819 ret
= do_connect(sockfd
, target_addr
, addrlen
);
1824 abi_ulong sockfd
, backlog
;
1826 if (get_user_ual(sockfd
, vptr
)
1827 || get_user_ual(backlog
, vptr
+ n
))
1828 return -TARGET_EFAULT
;
1830 ret
= get_errno(listen(sockfd
, backlog
));
1836 abi_ulong target_addr
, target_addrlen
;
1838 if (get_user_ual(sockfd
, vptr
)
1839 || get_user_ual(target_addr
, vptr
+ n
)
1840 || get_user_ual(target_addrlen
, vptr
+ 2 * n
))
1841 return -TARGET_EFAULT
;
1843 ret
= do_accept(sockfd
, target_addr
, target_addrlen
);
1846 case SOCKOP_getsockname
:
1849 abi_ulong target_addr
, target_addrlen
;
1851 if (get_user_ual(sockfd
, vptr
)
1852 || get_user_ual(target_addr
, vptr
+ n
)
1853 || get_user_ual(target_addrlen
, vptr
+ 2 * n
))
1854 return -TARGET_EFAULT
;
1856 ret
= do_getsockname(sockfd
, target_addr
, target_addrlen
);
1859 case SOCKOP_getpeername
:
1862 abi_ulong target_addr
, target_addrlen
;
1864 if (get_user_ual(sockfd
, vptr
)
1865 || get_user_ual(target_addr
, vptr
+ n
)
1866 || get_user_ual(target_addrlen
, vptr
+ 2 * n
))
1867 return -TARGET_EFAULT
;
1869 ret
= do_getpeername(sockfd
, target_addr
, target_addrlen
);
1872 case SOCKOP_socketpair
:
1874 abi_ulong domain
, type
, protocol
;
1877 if (get_user_ual(domain
, vptr
)
1878 || get_user_ual(type
, vptr
+ n
)
1879 || get_user_ual(protocol
, vptr
+ 2 * n
)
1880 || get_user_ual(tab
, vptr
+ 3 * n
))
1881 return -TARGET_EFAULT
;
1883 ret
= do_socketpair(domain
, type
, protocol
, tab
);
1893 if (get_user_ual(sockfd
, vptr
)
1894 || get_user_ual(msg
, vptr
+ n
)
1895 || get_user_ual(len
, vptr
+ 2 * n
)
1896 || get_user_ual(flags
, vptr
+ 3 * n
))
1897 return -TARGET_EFAULT
;
1899 ret
= do_sendto(sockfd
, msg
, len
, flags
, 0, 0);
1909 if (get_user_ual(sockfd
, vptr
)
1910 || get_user_ual(msg
, vptr
+ n
)
1911 || get_user_ual(len
, vptr
+ 2 * n
)
1912 || get_user_ual(flags
, vptr
+ 3 * n
))
1913 return -TARGET_EFAULT
;
1915 ret
= do_recvfrom(sockfd
, msg
, len
, flags
, 0, 0);
1927 if (get_user_ual(sockfd
, vptr
)
1928 || get_user_ual(msg
, vptr
+ n
)
1929 || get_user_ual(len
, vptr
+ 2 * n
)
1930 || get_user_ual(flags
, vptr
+ 3 * n
)
1931 || get_user_ual(addr
, vptr
+ 4 * n
)
1932 || get_user_ual(addrlen
, vptr
+ 5 * n
))
1933 return -TARGET_EFAULT
;
1935 ret
= do_sendto(sockfd
, msg
, len
, flags
, addr
, addrlen
);
1938 case SOCKOP_recvfrom
:
1947 if (get_user_ual(sockfd
, vptr
)
1948 || get_user_ual(msg
, vptr
+ n
)
1949 || get_user_ual(len
, vptr
+ 2 * n
)
1950 || get_user_ual(flags
, vptr
+ 3 * n
)
1951 || get_user_ual(addr
, vptr
+ 4 * n
)
1952 || get_user_ual(addrlen
, vptr
+ 5 * n
))
1953 return -TARGET_EFAULT
;
1955 ret
= do_recvfrom(sockfd
, msg
, len
, flags
, addr
, addrlen
);
1958 case SOCKOP_shutdown
:
1960 abi_ulong sockfd
, how
;
1962 if (get_user_ual(sockfd
, vptr
)
1963 || get_user_ual(how
, vptr
+ n
))
1964 return -TARGET_EFAULT
;
1966 ret
= get_errno(shutdown(sockfd
, how
));
1969 case SOCKOP_sendmsg
:
1970 case SOCKOP_recvmsg
:
1973 abi_ulong target_msg
;
1976 if (get_user_ual(fd
, vptr
)
1977 || get_user_ual(target_msg
, vptr
+ n
)
1978 || get_user_ual(flags
, vptr
+ 2 * n
))
1979 return -TARGET_EFAULT
;
1981 ret
= do_sendrecvmsg(fd
, target_msg
, flags
,
1982 (num
== SOCKOP_sendmsg
));
1985 case SOCKOP_setsockopt
:
1993 if (get_user_ual(sockfd
, vptr
)
1994 || get_user_ual(level
, vptr
+ n
)
1995 || get_user_ual(optname
, vptr
+ 2 * n
)
1996 || get_user_ual(optval
, vptr
+ 3 * n
)
1997 || get_user_ual(optlen
, vptr
+ 4 * n
))
1998 return -TARGET_EFAULT
;
2000 ret
= do_setsockopt(sockfd
, level
, optname
, optval
, optlen
);
2003 case SOCKOP_getsockopt
:
2011 if (get_user_ual(sockfd
, vptr
)
2012 || get_user_ual(level
, vptr
+ n
)
2013 || get_user_ual(optname
, vptr
+ 2 * n
)
2014 || get_user_ual(optval
, vptr
+ 3 * n
)
2015 || get_user_ual(optlen
, vptr
+ 4 * n
))
2016 return -TARGET_EFAULT
;
2018 ret
= do_getsockopt(sockfd
, level
, optname
, optval
, optlen
);
2022 gemu_log("Unsupported socketcall: %d\n", num
);
2023 ret
= -TARGET_ENOSYS
;
2030 #define N_SHM_REGIONS 32
2032 static struct shm_region
{
2035 } shm_regions
[N_SHM_REGIONS
];
2037 struct target_ipc_perm
2044 unsigned short int mode
;
2045 unsigned short int __pad1
;
2046 unsigned short int __seq
;
2047 unsigned short int __pad2
;
2048 abi_ulong __unused1
;
2049 abi_ulong __unused2
;
2052 struct target_semid_ds
2054 struct target_ipc_perm sem_perm
;
2055 abi_ulong sem_otime
;
2056 abi_ulong __unused1
;
2057 abi_ulong sem_ctime
;
2058 abi_ulong __unused2
;
2059 abi_ulong sem_nsems
;
2060 abi_ulong __unused3
;
2061 abi_ulong __unused4
;
2064 static inline abi_long
target_to_host_ipc_perm(struct ipc_perm
*host_ip
,
2065 abi_ulong target_addr
)
2067 struct target_ipc_perm
*target_ip
;
2068 struct target_semid_ds
*target_sd
;
2070 if (!lock_user_struct(VERIFY_READ
, target_sd
, target_addr
, 1))
2071 return -TARGET_EFAULT
;
2072 target_ip
= &(target_sd
->sem_perm
);
2073 host_ip
->__key
= tswapl(target_ip
->__key
);
2074 host_ip
->uid
= tswapl(target_ip
->uid
);
2075 host_ip
->gid
= tswapl(target_ip
->gid
);
2076 host_ip
->cuid
= tswapl(target_ip
->cuid
);
2077 host_ip
->cgid
= tswapl(target_ip
->cgid
);
2078 host_ip
->mode
= tswapl(target_ip
->mode
);
2079 unlock_user_struct(target_sd
, target_addr
, 0);
2083 static inline abi_long
host_to_target_ipc_perm(abi_ulong target_addr
,
2084 struct ipc_perm
*host_ip
)
2086 struct target_ipc_perm
*target_ip
;
2087 struct target_semid_ds
*target_sd
;
2089 if (!lock_user_struct(VERIFY_WRITE
, target_sd
, target_addr
, 0))
2090 return -TARGET_EFAULT
;
2091 target_ip
= &(target_sd
->sem_perm
);
2092 target_ip
->__key
= tswapl(host_ip
->__key
);
2093 target_ip
->uid
= tswapl(host_ip
->uid
);
2094 target_ip
->gid
= tswapl(host_ip
->gid
);
2095 target_ip
->cuid
= tswapl(host_ip
->cuid
);
2096 target_ip
->cgid
= tswapl(host_ip
->cgid
);
2097 target_ip
->mode
= tswapl(host_ip
->mode
);
2098 unlock_user_struct(target_sd
, target_addr
, 1);
2102 static inline abi_long
target_to_host_semid_ds(struct semid_ds
*host_sd
,
2103 abi_ulong target_addr
)
2105 struct target_semid_ds
*target_sd
;
2107 if (!lock_user_struct(VERIFY_READ
, target_sd
, target_addr
, 1))
2108 return -TARGET_EFAULT
;
2109 if (target_to_host_ipc_perm(&(host_sd
->sem_perm
),target_addr
))
2110 return -TARGET_EFAULT
;
2111 host_sd
->sem_nsems
= tswapl(target_sd
->sem_nsems
);
2112 host_sd
->sem_otime
= tswapl(target_sd
->sem_otime
);
2113 host_sd
->sem_ctime
= tswapl(target_sd
->sem_ctime
);
2114 unlock_user_struct(target_sd
, target_addr
, 0);
2118 static inline abi_long
host_to_target_semid_ds(abi_ulong target_addr
,
2119 struct semid_ds
*host_sd
)
2121 struct target_semid_ds
*target_sd
;
2123 if (!lock_user_struct(VERIFY_WRITE
, target_sd
, target_addr
, 0))
2124 return -TARGET_EFAULT
;
2125 if (host_to_target_ipc_perm(target_addr
,&(host_sd
->sem_perm
)))
2126 return -TARGET_EFAULT
;;
2127 target_sd
->sem_nsems
= tswapl(host_sd
->sem_nsems
);
2128 target_sd
->sem_otime
= tswapl(host_sd
->sem_otime
);
2129 target_sd
->sem_ctime
= tswapl(host_sd
->sem_ctime
);
2130 unlock_user_struct(target_sd
, target_addr
, 1);
2134 struct target_seminfo
{
2147 static inline abi_long
host_to_target_seminfo(abi_ulong target_addr
,
2148 struct seminfo
*host_seminfo
)
2150 struct target_seminfo
*target_seminfo
;
2151 if (!lock_user_struct(VERIFY_WRITE
, target_seminfo
, target_addr
, 0))
2152 return -TARGET_EFAULT
;
2153 __put_user(host_seminfo
->semmap
, &target_seminfo
->semmap
);
2154 __put_user(host_seminfo
->semmni
, &target_seminfo
->semmni
);
2155 __put_user(host_seminfo
->semmns
, &target_seminfo
->semmns
);
2156 __put_user(host_seminfo
->semmnu
, &target_seminfo
->semmnu
);
2157 __put_user(host_seminfo
->semmsl
, &target_seminfo
->semmsl
);
2158 __put_user(host_seminfo
->semopm
, &target_seminfo
->semopm
);
2159 __put_user(host_seminfo
->semume
, &target_seminfo
->semume
);
2160 __put_user(host_seminfo
->semusz
, &target_seminfo
->semusz
);
2161 __put_user(host_seminfo
->semvmx
, &target_seminfo
->semvmx
);
2162 __put_user(host_seminfo
->semaem
, &target_seminfo
->semaem
);
2163 unlock_user_struct(target_seminfo
, target_addr
, 1);
2169 struct semid_ds
*buf
;
2170 unsigned short *array
;
2171 struct seminfo
*__buf
;
2174 union target_semun
{
2181 static inline abi_long
target_to_host_semarray(int semid
, unsigned short **host_array
,
2182 abi_ulong target_addr
)
2185 unsigned short *array
;
2187 struct semid_ds semid_ds
;
2190 semun
.buf
= &semid_ds
;
2192 ret
= semctl(semid
, 0, IPC_STAT
, semun
);
2194 return get_errno(ret
);
2196 nsems
= semid_ds
.sem_nsems
;
2198 *host_array
= malloc(nsems
*sizeof(unsigned short));
2199 array
= lock_user(VERIFY_READ
, target_addr
,
2200 nsems
*sizeof(unsigned short), 1);
2202 return -TARGET_EFAULT
;
2204 for(i
=0; i
<nsems
; i
++) {
2205 __get_user((*host_array
)[i
], &array
[i
]);
2207 unlock_user(array
, target_addr
, 0);
2212 static inline abi_long
host_to_target_semarray(int semid
, abi_ulong target_addr
,
2213 unsigned short **host_array
)
2216 unsigned short *array
;
2218 struct semid_ds semid_ds
;
2221 semun
.buf
= &semid_ds
;
2223 ret
= semctl(semid
, 0, IPC_STAT
, semun
);
2225 return get_errno(ret
);
2227 nsems
= semid_ds
.sem_nsems
;
2229 array
= lock_user(VERIFY_WRITE
, target_addr
,
2230 nsems
*sizeof(unsigned short), 0);
2232 return -TARGET_EFAULT
;
2234 for(i
=0; i
<nsems
; i
++) {
2235 __put_user((*host_array
)[i
], &array
[i
]);
2238 unlock_user(array
, target_addr
, 1);
2243 static inline abi_long
do_semctl(int semid
, int semnum
, int cmd
,
2244 union target_semun target_su
)
2247 struct semid_ds dsarg
;
2248 unsigned short *array
= NULL
;
2249 struct seminfo seminfo
;
2250 abi_long ret
= -TARGET_EINVAL
;
2257 arg
.val
= tswapl(target_su
.val
);
2258 ret
= get_errno(semctl(semid
, semnum
, cmd
, arg
));
2259 target_su
.val
= tswapl(arg
.val
);
2263 err
= target_to_host_semarray(semid
, &array
, target_su
.array
);
2267 ret
= get_errno(semctl(semid
, semnum
, cmd
, arg
));
2268 err
= host_to_target_semarray(semid
, target_su
.array
, &array
);
2275 err
= target_to_host_semid_ds(&dsarg
, target_su
.buf
);
2279 ret
= get_errno(semctl(semid
, semnum
, cmd
, arg
));
2280 err
= host_to_target_semid_ds(target_su
.buf
, &dsarg
);
2286 arg
.__buf
= &seminfo
;
2287 ret
= get_errno(semctl(semid
, semnum
, cmd
, arg
));
2288 err
= host_to_target_seminfo(target_su
.__buf
, &seminfo
);
2296 ret
= get_errno(semctl(semid
, semnum
, cmd
, NULL
));
2303 struct target_sembuf
{
2304 unsigned short sem_num
;
2309 static inline abi_long
target_to_host_sembuf(struct sembuf
*host_sembuf
,
2310 abi_ulong target_addr
,
2313 struct target_sembuf
*target_sembuf
;
2316 target_sembuf
= lock_user(VERIFY_READ
, target_addr
,
2317 nsops
*sizeof(struct target_sembuf
), 1);
2319 return -TARGET_EFAULT
;
2321 for(i
=0; i
<nsops
; i
++) {
2322 __get_user(host_sembuf
[i
].sem_num
, &target_sembuf
[i
].sem_num
);
2323 __get_user(host_sembuf
[i
].sem_op
, &target_sembuf
[i
].sem_op
);
2324 __get_user(host_sembuf
[i
].sem_flg
, &target_sembuf
[i
].sem_flg
);
2327 unlock_user(target_sembuf
, target_addr
, 0);
2332 static inline abi_long
do_semop(int semid
, abi_long ptr
, unsigned nsops
)
2334 struct sembuf sops
[nsops
];
2336 if (target_to_host_sembuf(sops
, ptr
, nsops
))
2337 return -TARGET_EFAULT
;
2339 return semop(semid
, sops
, nsops
);
2342 struct target_msqid_ds
2344 struct target_ipc_perm msg_perm
;
2345 abi_ulong msg_stime
;
2346 #if TARGET_ABI_BITS == 32
2347 abi_ulong __unused1
;
2349 abi_ulong msg_rtime
;
2350 #if TARGET_ABI_BITS == 32
2351 abi_ulong __unused2
;
2353 abi_ulong msg_ctime
;
2354 #if TARGET_ABI_BITS == 32
2355 abi_ulong __unused3
;
2357 abi_ulong __msg_cbytes
;
2359 abi_ulong msg_qbytes
;
2360 abi_ulong msg_lspid
;
2361 abi_ulong msg_lrpid
;
2362 abi_ulong __unused4
;
2363 abi_ulong __unused5
;
2366 static inline abi_long
target_to_host_msqid_ds(struct msqid_ds
*host_md
,
2367 abi_ulong target_addr
)
2369 struct target_msqid_ds
*target_md
;
2371 if (!lock_user_struct(VERIFY_READ
, target_md
, target_addr
, 1))
2372 return -TARGET_EFAULT
;
2373 if (target_to_host_ipc_perm(&(host_md
->msg_perm
),target_addr
))
2374 return -TARGET_EFAULT
;
2375 host_md
->msg_stime
= tswapl(target_md
->msg_stime
);
2376 host_md
->msg_rtime
= tswapl(target_md
->msg_rtime
);
2377 host_md
->msg_ctime
= tswapl(target_md
->msg_ctime
);
2378 host_md
->__msg_cbytes
= tswapl(target_md
->__msg_cbytes
);
2379 host_md
->msg_qnum
= tswapl(target_md
->msg_qnum
);
2380 host_md
->msg_qbytes
= tswapl(target_md
->msg_qbytes
);
2381 host_md
->msg_lspid
= tswapl(target_md
->msg_lspid
);
2382 host_md
->msg_lrpid
= tswapl(target_md
->msg_lrpid
);
2383 unlock_user_struct(target_md
, target_addr
, 0);
2387 static inline abi_long
host_to_target_msqid_ds(abi_ulong target_addr
,
2388 struct msqid_ds
*host_md
)
2390 struct target_msqid_ds
*target_md
;
2392 if (!lock_user_struct(VERIFY_WRITE
, target_md
, target_addr
, 0))
2393 return -TARGET_EFAULT
;
2394 if (host_to_target_ipc_perm(target_addr
,&(host_md
->msg_perm
)))
2395 return -TARGET_EFAULT
;
2396 target_md
->msg_stime
= tswapl(host_md
->msg_stime
);
2397 target_md
->msg_rtime
= tswapl(host_md
->msg_rtime
);
2398 target_md
->msg_ctime
= tswapl(host_md
->msg_ctime
);
2399 target_md
->__msg_cbytes
= tswapl(host_md
->__msg_cbytes
);
2400 target_md
->msg_qnum
= tswapl(host_md
->msg_qnum
);
2401 target_md
->msg_qbytes
= tswapl(host_md
->msg_qbytes
);
2402 target_md
->msg_lspid
= tswapl(host_md
->msg_lspid
);
2403 target_md
->msg_lrpid
= tswapl(host_md
->msg_lrpid
);
2404 unlock_user_struct(target_md
, target_addr
, 1);
2408 struct target_msginfo
{
2416 unsigned short int msgseg
;
2419 static inline abi_long
host_to_target_msginfo(abi_ulong target_addr
,
2420 struct msginfo
*host_msginfo
)
2422 struct target_msginfo
*target_msginfo
;
2423 if (!lock_user_struct(VERIFY_WRITE
, target_msginfo
, target_addr
, 0))
2424 return -TARGET_EFAULT
;
2425 __put_user(host_msginfo
->msgpool
, &target_msginfo
->msgpool
);
2426 __put_user(host_msginfo
->msgmap
, &target_msginfo
->msgmap
);
2427 __put_user(host_msginfo
->msgmax
, &target_msginfo
->msgmax
);
2428 __put_user(host_msginfo
->msgmnb
, &target_msginfo
->msgmnb
);
2429 __put_user(host_msginfo
->msgmni
, &target_msginfo
->msgmni
);
2430 __put_user(host_msginfo
->msgssz
, &target_msginfo
->msgssz
);
2431 __put_user(host_msginfo
->msgtql
, &target_msginfo
->msgtql
);
2432 __put_user(host_msginfo
->msgseg
, &target_msginfo
->msgseg
);
2433 unlock_user_struct(target_msginfo
, target_addr
, 1);
2437 static inline abi_long
do_msgctl(int msgid
, int cmd
, abi_long ptr
)
2439 struct msqid_ds dsarg
;
2440 struct msginfo msginfo
;
2441 abi_long ret
= -TARGET_EINVAL
;
2449 if (target_to_host_msqid_ds(&dsarg
,ptr
))
2450 return -TARGET_EFAULT
;
2451 ret
= get_errno(msgctl(msgid
, cmd
, &dsarg
));
2452 if (host_to_target_msqid_ds(ptr
,&dsarg
))
2453 return -TARGET_EFAULT
;
2456 ret
= get_errno(msgctl(msgid
, cmd
, NULL
));
2460 ret
= get_errno(msgctl(msgid
, cmd
, (struct msqid_ds
*)&msginfo
));
2461 if (host_to_target_msginfo(ptr
, &msginfo
))
2462 return -TARGET_EFAULT
;
2469 struct target_msgbuf
{
2474 static inline abi_long
do_msgsnd(int msqid
, abi_long msgp
,
2475 unsigned int msgsz
, int msgflg
)
2477 struct target_msgbuf
*target_mb
;
2478 struct msgbuf
*host_mb
;
2481 if (!lock_user_struct(VERIFY_READ
, target_mb
, msgp
, 0))
2482 return -TARGET_EFAULT
;
2483 host_mb
= malloc(msgsz
+sizeof(long));
2484 host_mb
->mtype
= (abi_long
) tswapl(target_mb
->mtype
);
2485 memcpy(host_mb
->mtext
, target_mb
->mtext
, msgsz
);
2486 ret
= get_errno(msgsnd(msqid
, host_mb
, msgsz
, msgflg
));
2488 unlock_user_struct(target_mb
, msgp
, 0);
2493 static inline abi_long
do_msgrcv(int msqid
, abi_long msgp
,
2494 unsigned int msgsz
, abi_long msgtyp
,
2497 struct target_msgbuf
*target_mb
;
2499 struct msgbuf
*host_mb
;
2502 if (!lock_user_struct(VERIFY_WRITE
, target_mb
, msgp
, 0))
2503 return -TARGET_EFAULT
;
2505 host_mb
= malloc(msgsz
+sizeof(long));
2506 ret
= get_errno(msgrcv(msqid
, host_mb
, msgsz
, tswapl(msgtyp
), msgflg
));
2509 abi_ulong target_mtext_addr
= msgp
+ sizeof(abi_ulong
);
2510 target_mtext
= lock_user(VERIFY_WRITE
, target_mtext_addr
, ret
, 0);
2511 if (!target_mtext
) {
2512 ret
= -TARGET_EFAULT
;
2515 memcpy(target_mb
->mtext
, host_mb
->mtext
, ret
);
2516 unlock_user(target_mtext
, target_mtext_addr
, ret
);
2519 target_mb
->mtype
= tswapl(host_mb
->mtype
);
2524 unlock_user_struct(target_mb
, msgp
, 1);
2528 struct target_shmid_ds
2530 struct target_ipc_perm shm_perm
;
2531 abi_ulong shm_segsz
;
2532 abi_ulong shm_atime
;
2533 #if TARGET_ABI_BITS == 32
2534 abi_ulong __unused1
;
2536 abi_ulong shm_dtime
;
2537 #if TARGET_ABI_BITS == 32
2538 abi_ulong __unused2
;
2540 abi_ulong shm_ctime
;
2541 #if TARGET_ABI_BITS == 32
2542 abi_ulong __unused3
;
2546 abi_ulong shm_nattch
;
2547 unsigned long int __unused4
;
2548 unsigned long int __unused5
;
2551 static inline abi_long
target_to_host_shmid_ds(struct shmid_ds
*host_sd
,
2552 abi_ulong target_addr
)
2554 struct target_shmid_ds
*target_sd
;
2556 if (!lock_user_struct(VERIFY_READ
, target_sd
, target_addr
, 1))
2557 return -TARGET_EFAULT
;
2558 if (target_to_host_ipc_perm(&(host_sd
->shm_perm
), target_addr
))
2559 return -TARGET_EFAULT
;
2560 __get_user(host_sd
->shm_segsz
, &target_sd
->shm_segsz
);
2561 __get_user(host_sd
->shm_atime
, &target_sd
->shm_atime
);
2562 __get_user(host_sd
->shm_dtime
, &target_sd
->shm_dtime
);
2563 __get_user(host_sd
->shm_ctime
, &target_sd
->shm_ctime
);
2564 __get_user(host_sd
->shm_cpid
, &target_sd
->shm_cpid
);
2565 __get_user(host_sd
->shm_lpid
, &target_sd
->shm_lpid
);
2566 __get_user(host_sd
->shm_nattch
, &target_sd
->shm_nattch
);
2567 unlock_user_struct(target_sd
, target_addr
, 0);
2571 static inline abi_long
host_to_target_shmid_ds(abi_ulong target_addr
,
2572 struct shmid_ds
*host_sd
)
2574 struct target_shmid_ds
*target_sd
;
2576 if (!lock_user_struct(VERIFY_WRITE
, target_sd
, target_addr
, 0))
2577 return -TARGET_EFAULT
;
2578 if (host_to_target_ipc_perm(target_addr
, &(host_sd
->shm_perm
)))
2579 return -TARGET_EFAULT
;
2580 __put_user(host_sd
->shm_segsz
, &target_sd
->shm_segsz
);
2581 __put_user(host_sd
->shm_atime
, &target_sd
->shm_atime
);
2582 __put_user(host_sd
->shm_dtime
, &target_sd
->shm_dtime
);
2583 __put_user(host_sd
->shm_ctime
, &target_sd
->shm_ctime
);
2584 __put_user(host_sd
->shm_cpid
, &target_sd
->shm_cpid
);
2585 __put_user(host_sd
->shm_lpid
, &target_sd
->shm_lpid
);
2586 __put_user(host_sd
->shm_nattch
, &target_sd
->shm_nattch
);
2587 unlock_user_struct(target_sd
, target_addr
, 1);
2591 struct target_shminfo
{
2599 static inline abi_long
host_to_target_shminfo(abi_ulong target_addr
,
2600 struct shminfo
*host_shminfo
)
2602 struct target_shminfo
*target_shminfo
;
2603 if (!lock_user_struct(VERIFY_WRITE
, target_shminfo
, target_addr
, 0))
2604 return -TARGET_EFAULT
;
2605 __put_user(host_shminfo
->shmmax
, &target_shminfo
->shmmax
);
2606 __put_user(host_shminfo
->shmmin
, &target_shminfo
->shmmin
);
2607 __put_user(host_shminfo
->shmmni
, &target_shminfo
->shmmni
);
2608 __put_user(host_shminfo
->shmseg
, &target_shminfo
->shmseg
);
2609 __put_user(host_shminfo
->shmall
, &target_shminfo
->shmall
);
2610 unlock_user_struct(target_shminfo
, target_addr
, 1);
2614 struct target_shm_info
{
2619 abi_ulong swap_attempts
;
2620 abi_ulong swap_successes
;
2623 static inline abi_long
host_to_target_shm_info(abi_ulong target_addr
,
2624 struct shm_info
*host_shm_info
)
2626 struct target_shm_info
*target_shm_info
;
2627 if (!lock_user_struct(VERIFY_WRITE
, target_shm_info
, target_addr
, 0))
2628 return -TARGET_EFAULT
;
2629 __put_user(host_shm_info
->used_ids
, &target_shm_info
->used_ids
);
2630 __put_user(host_shm_info
->shm_tot
, &target_shm_info
->shm_tot
);
2631 __put_user(host_shm_info
->shm_rss
, &target_shm_info
->shm_rss
);
2632 __put_user(host_shm_info
->shm_swp
, &target_shm_info
->shm_swp
);
2633 __put_user(host_shm_info
->swap_attempts
, &target_shm_info
->swap_attempts
);
2634 __put_user(host_shm_info
->swap_successes
, &target_shm_info
->swap_successes
);
2635 unlock_user_struct(target_shm_info
, target_addr
, 1);
2639 static inline abi_long
do_shmctl(int shmid
, int cmd
, abi_long buf
)
2641 struct shmid_ds dsarg
;
2642 struct shminfo shminfo
;
2643 struct shm_info shm_info
;
2644 abi_long ret
= -TARGET_EINVAL
;
2652 if (target_to_host_shmid_ds(&dsarg
, buf
))
2653 return -TARGET_EFAULT
;
2654 ret
= get_errno(shmctl(shmid
, cmd
, &dsarg
));
2655 if (host_to_target_shmid_ds(buf
, &dsarg
))
2656 return -TARGET_EFAULT
;
2659 ret
= get_errno(shmctl(shmid
, cmd
, (struct shmid_ds
*)&shminfo
));
2660 if (host_to_target_shminfo(buf
, &shminfo
))
2661 return -TARGET_EFAULT
;
2664 ret
= get_errno(shmctl(shmid
, cmd
, (struct shmid_ds
*)&shm_info
));
2665 if (host_to_target_shm_info(buf
, &shm_info
))
2666 return -TARGET_EFAULT
;
2671 ret
= get_errno(shmctl(shmid
, cmd
, NULL
));
2678 static inline abi_ulong
do_shmat(int shmid
, abi_ulong shmaddr
, int shmflg
)
2682 struct shmid_ds shm_info
;
2685 /* find out the length of the shared memory segment */
2686 ret
= get_errno(shmctl(shmid
, IPC_STAT
, &shm_info
));
2687 if (is_error(ret
)) {
2688 /* can't get length, bail out */
2695 host_raddr
= shmat(shmid
, (void *)g2h(shmaddr
), shmflg
);
2697 abi_ulong mmap_start
;
2699 mmap_start
= mmap_find_vma(0, shm_info
.shm_segsz
);
2701 if (mmap_start
== -1) {
2703 host_raddr
= (void *)-1;
2705 host_raddr
= shmat(shmid
, g2h(mmap_start
), shmflg
| SHM_REMAP
);
2708 if (host_raddr
== (void *)-1) {
2710 return get_errno((long)host_raddr
);
2712 raddr
=h2g((unsigned long)host_raddr
);
2714 page_set_flags(raddr
, raddr
+ shm_info
.shm_segsz
,
2715 PAGE_VALID
| PAGE_READ
|
2716 ((shmflg
& SHM_RDONLY
)? 0 : PAGE_WRITE
));
2718 for (i
= 0; i
< N_SHM_REGIONS
; i
++) {
2719 if (shm_regions
[i
].start
== 0) {
2720 shm_regions
[i
].start
= raddr
;
2721 shm_regions
[i
].size
= shm_info
.shm_segsz
;
2731 static inline abi_long
do_shmdt(abi_ulong shmaddr
)
2735 for (i
= 0; i
< N_SHM_REGIONS
; ++i
) {
2736 if (shm_regions
[i
].start
== shmaddr
) {
2737 shm_regions
[i
].start
= 0;
2738 page_set_flags(shmaddr
, shm_regions
[i
].size
, 0);
2743 return get_errno(shmdt(g2h(shmaddr
)));
2746 #ifdef TARGET_NR_ipc
2747 /* ??? This only works with linear mappings. */
2748 /* do_ipc() must return target values and target errnos. */
2749 static abi_long
do_ipc(unsigned int call
, int first
,
2750 int second
, int third
,
2751 abi_long ptr
, abi_long fifth
)
2756 version
= call
>> 16;
2761 ret
= do_semop(first
, ptr
, second
);
2765 ret
= get_errno(semget(first
, second
, third
));
2769 ret
= do_semctl(first
, second
, third
, (union target_semun
)(abi_ulong
) ptr
);
2773 ret
= get_errno(msgget(first
, second
));
2777 ret
= do_msgsnd(first
, ptr
, second
, third
);
2781 ret
= do_msgctl(first
, second
, ptr
);
2788 struct target_ipc_kludge
{
2793 if (!lock_user_struct(VERIFY_READ
, tmp
, ptr
, 1)) {
2794 ret
= -TARGET_EFAULT
;
2798 ret
= do_msgrcv(first
, tmp
->msgp
, second
, tmp
->msgtyp
, third
);
2800 unlock_user_struct(tmp
, ptr
, 0);
2804 ret
= do_msgrcv(first
, ptr
, second
, fifth
, third
);
2813 raddr
= do_shmat(first
, ptr
, second
);
2814 if (is_error(raddr
))
2815 return get_errno(raddr
);
2816 if (put_user_ual(raddr
, third
))
2817 return -TARGET_EFAULT
;
2821 ret
= -TARGET_EINVAL
;
2826 ret
= do_shmdt(ptr
);
2830 /* IPC_* flag values are the same on all linux platforms */
2831 ret
= get_errno(shmget(first
, second
, third
));
2834 /* IPC_* and SHM_* command values are the same on all linux platforms */
2836 ret
= do_shmctl(first
, second
, third
);
2839 gemu_log("Unsupported ipc call: %d (version %d)\n", call
, version
);
2840 ret
= -TARGET_ENOSYS
;
2847 /* kernel structure types definitions */
2850 #define STRUCT(name, ...) STRUCT_ ## name,
2851 #define STRUCT_SPECIAL(name) STRUCT_ ## name,
2853 #include "syscall_types.h"
2856 #undef STRUCT_SPECIAL
2858 #define STRUCT(name, ...) static const argtype struct_ ## name ## _def[] = { __VA_ARGS__, TYPE_NULL };
2859 #define STRUCT_SPECIAL(name)
2860 #include "syscall_types.h"
2862 #undef STRUCT_SPECIAL
2864 typedef struct IOCTLEntry
{
2865 unsigned int target_cmd
;
2866 unsigned int host_cmd
;
2869 const argtype arg_type
[5];
2872 #define IOC_R 0x0001
2873 #define IOC_W 0x0002
2874 #define IOC_RW (IOC_R | IOC_W)
2876 #define MAX_STRUCT_SIZE 4096
2878 static IOCTLEntry ioctl_entries
[] = {
2879 #define IOCTL(cmd, access, ...) \
2880 { TARGET_ ## cmd, cmd, #cmd, access, { __VA_ARGS__ } },
2885 /* ??? Implement proper locking for ioctls. */
2886 /* do_ioctl() Must return target values and target errnos. */
2887 static abi_long
do_ioctl(int fd
, abi_long cmd
, abi_long arg
)
2889 const IOCTLEntry
*ie
;
2890 const argtype
*arg_type
;
2892 uint8_t buf_temp
[MAX_STRUCT_SIZE
];
2898 if (ie
->target_cmd
== 0) {
2899 gemu_log("Unsupported ioctl: cmd=0x%04lx\n", (long)cmd
);
2900 return -TARGET_ENOSYS
;
2902 if (ie
->target_cmd
== cmd
)
2906 arg_type
= ie
->arg_type
;
2908 gemu_log("ioctl: cmd=0x%04lx (%s)\n", (long)cmd
, ie
->name
);
2910 switch(arg_type
[0]) {
2913 ret
= get_errno(ioctl(fd
, ie
->host_cmd
));
2918 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, arg
));
2922 target_size
= thunk_type_size(arg_type
, 0);
2923 switch(ie
->access
) {
2925 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, buf_temp
));
2926 if (!is_error(ret
)) {
2927 argptr
= lock_user(VERIFY_WRITE
, arg
, target_size
, 0);
2929 return -TARGET_EFAULT
;
2930 thunk_convert(argptr
, buf_temp
, arg_type
, THUNK_TARGET
);
2931 unlock_user(argptr
, arg
, target_size
);
2935 argptr
= lock_user(VERIFY_READ
, arg
, target_size
, 1);
2937 return -TARGET_EFAULT
;
2938 thunk_convert(buf_temp
, argptr
, arg_type
, THUNK_HOST
);
2939 unlock_user(argptr
, arg
, 0);
2940 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, buf_temp
));
2944 argptr
= lock_user(VERIFY_READ
, arg
, target_size
, 1);
2946 return -TARGET_EFAULT
;
2947 thunk_convert(buf_temp
, argptr
, arg_type
, THUNK_HOST
);
2948 unlock_user(argptr
, arg
, 0);
2949 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, buf_temp
));
2950 if (!is_error(ret
)) {
2951 argptr
= lock_user(VERIFY_WRITE
, arg
, target_size
, 0);
2953 return -TARGET_EFAULT
;
2954 thunk_convert(argptr
, buf_temp
, arg_type
, THUNK_TARGET
);
2955 unlock_user(argptr
, arg
, target_size
);
2961 gemu_log("Unsupported ioctl type: cmd=0x%04lx type=%d\n",
2962 (long)cmd
, arg_type
[0]);
2963 ret
= -TARGET_ENOSYS
;
2969 static const bitmask_transtbl iflag_tbl
[] = {
2970 { TARGET_IGNBRK
, TARGET_IGNBRK
, IGNBRK
, IGNBRK
},
2971 { TARGET_BRKINT
, TARGET_BRKINT
, BRKINT
, BRKINT
},
2972 { TARGET_IGNPAR
, TARGET_IGNPAR
, IGNPAR
, IGNPAR
},
2973 { TARGET_PARMRK
, TARGET_PARMRK
, PARMRK
, PARMRK
},
2974 { TARGET_INPCK
, TARGET_INPCK
, INPCK
, INPCK
},
2975 { TARGET_ISTRIP
, TARGET_ISTRIP
, ISTRIP
, ISTRIP
},
2976 { TARGET_INLCR
, TARGET_INLCR
, INLCR
, INLCR
},
2977 { TARGET_IGNCR
, TARGET_IGNCR
, IGNCR
, IGNCR
},
2978 { TARGET_ICRNL
, TARGET_ICRNL
, ICRNL
, ICRNL
},
2979 { TARGET_IUCLC
, TARGET_IUCLC
, IUCLC
, IUCLC
},
2980 { TARGET_IXON
, TARGET_IXON
, IXON
, IXON
},
2981 { TARGET_IXANY
, TARGET_IXANY
, IXANY
, IXANY
},
2982 { TARGET_IXOFF
, TARGET_IXOFF
, IXOFF
, IXOFF
},
2983 { TARGET_IMAXBEL
, TARGET_IMAXBEL
, IMAXBEL
, IMAXBEL
},
2987 static const bitmask_transtbl oflag_tbl
[] = {
2988 { TARGET_OPOST
, TARGET_OPOST
, OPOST
, OPOST
},
2989 { TARGET_OLCUC
, TARGET_OLCUC
, OLCUC
, OLCUC
},
2990 { TARGET_ONLCR
, TARGET_ONLCR
, ONLCR
, ONLCR
},
2991 { TARGET_OCRNL
, TARGET_OCRNL
, OCRNL
, OCRNL
},
2992 { TARGET_ONOCR
, TARGET_ONOCR
, ONOCR
, ONOCR
},
2993 { TARGET_ONLRET
, TARGET_ONLRET
, ONLRET
, ONLRET
},
2994 { TARGET_OFILL
, TARGET_OFILL
, OFILL
, OFILL
},
2995 { TARGET_OFDEL
, TARGET_OFDEL
, OFDEL
, OFDEL
},
2996 { TARGET_NLDLY
, TARGET_NL0
, NLDLY
, NL0
},
2997 { TARGET_NLDLY
, TARGET_NL1
, NLDLY
, NL1
},
2998 { TARGET_CRDLY
, TARGET_CR0
, CRDLY
, CR0
},
2999 { TARGET_CRDLY
, TARGET_CR1
, CRDLY
, CR1
},
3000 { TARGET_CRDLY
, TARGET_CR2
, CRDLY
, CR2
},
3001 { TARGET_CRDLY
, TARGET_CR3
, CRDLY
, CR3
},
3002 { TARGET_TABDLY
, TARGET_TAB0
, TABDLY
, TAB0
},
3003 { TARGET_TABDLY
, TARGET_TAB1
, TABDLY
, TAB1
},
3004 { TARGET_TABDLY
, TARGET_TAB2
, TABDLY
, TAB2
},
3005 { TARGET_TABDLY
, TARGET_TAB3
, TABDLY
, TAB3
},
3006 { TARGET_BSDLY
, TARGET_BS0
, BSDLY
, BS0
},
3007 { TARGET_BSDLY
, TARGET_BS1
, BSDLY
, BS1
},
3008 { TARGET_VTDLY
, TARGET_VT0
, VTDLY
, VT0
},
3009 { TARGET_VTDLY
, TARGET_VT1
, VTDLY
, VT1
},
3010 { TARGET_FFDLY
, TARGET_FF0
, FFDLY
, FF0
},
3011 { TARGET_FFDLY
, TARGET_FF1
, FFDLY
, FF1
},
3015 static const bitmask_transtbl cflag_tbl
[] = {
3016 { TARGET_CBAUD
, TARGET_B0
, CBAUD
, B0
},
3017 { TARGET_CBAUD
, TARGET_B50
, CBAUD
, B50
},
3018 { TARGET_CBAUD
, TARGET_B75
, CBAUD
, B75
},
3019 { TARGET_CBAUD
, TARGET_B110
, CBAUD
, B110
},
3020 { TARGET_CBAUD
, TARGET_B134
, CBAUD
, B134
},
3021 { TARGET_CBAUD
, TARGET_B150
, CBAUD
, B150
},
3022 { TARGET_CBAUD
, TARGET_B200
, CBAUD
, B200
},
3023 { TARGET_CBAUD
, TARGET_B300
, CBAUD
, B300
},
3024 { TARGET_CBAUD
, TARGET_B600
, CBAUD
, B600
},
3025 { TARGET_CBAUD
, TARGET_B1200
, CBAUD
, B1200
},
3026 { TARGET_CBAUD
, TARGET_B1800
, CBAUD
, B1800
},
3027 { TARGET_CBAUD
, TARGET_B2400
, CBAUD
, B2400
},
3028 { TARGET_CBAUD
, TARGET_B4800
, CBAUD
, B4800
},
3029 { TARGET_CBAUD
, TARGET_B9600
, CBAUD
, B9600
},
3030 { TARGET_CBAUD
, TARGET_B19200
, CBAUD
, B19200
},
3031 { TARGET_CBAUD
, TARGET_B38400
, CBAUD
, B38400
},
3032 { TARGET_CBAUD
, TARGET_B57600
, CBAUD
, B57600
},
3033 { TARGET_CBAUD
, TARGET_B115200
, CBAUD
, B115200
},
3034 { TARGET_CBAUD
, TARGET_B230400
, CBAUD
, B230400
},
3035 { TARGET_CBAUD
, TARGET_B460800
, CBAUD
, B460800
},
3036 { TARGET_CSIZE
, TARGET_CS5
, CSIZE
, CS5
},
3037 { TARGET_CSIZE
, TARGET_CS6
, CSIZE
, CS6
},
3038 { TARGET_CSIZE
, TARGET_CS7
, CSIZE
, CS7
},
3039 { TARGET_CSIZE
, TARGET_CS8
, CSIZE
, CS8
},
3040 { TARGET_CSTOPB
, TARGET_CSTOPB
, CSTOPB
, CSTOPB
},
3041 { TARGET_CREAD
, TARGET_CREAD
, CREAD
, CREAD
},
3042 { TARGET_PARENB
, TARGET_PARENB
, PARENB
, PARENB
},
3043 { TARGET_PARODD
, TARGET_PARODD
, PARODD
, PARODD
},
3044 { TARGET_HUPCL
, TARGET_HUPCL
, HUPCL
, HUPCL
},
3045 { TARGET_CLOCAL
, TARGET_CLOCAL
, CLOCAL
, CLOCAL
},
3046 { TARGET_CRTSCTS
, TARGET_CRTSCTS
, CRTSCTS
, CRTSCTS
},
3050 static const bitmask_transtbl lflag_tbl
[] = {
3051 { TARGET_ISIG
, TARGET_ISIG
, ISIG
, ISIG
},
3052 { TARGET_ICANON
, TARGET_ICANON
, ICANON
, ICANON
},
3053 { TARGET_XCASE
, TARGET_XCASE
, XCASE
, XCASE
},
3054 { TARGET_ECHO
, TARGET_ECHO
, ECHO
, ECHO
},
3055 { TARGET_ECHOE
, TARGET_ECHOE
, ECHOE
, ECHOE
},
3056 { TARGET_ECHOK
, TARGET_ECHOK
, ECHOK
, ECHOK
},
3057 { TARGET_ECHONL
, TARGET_ECHONL
, ECHONL
, ECHONL
},
3058 { TARGET_NOFLSH
, TARGET_NOFLSH
, NOFLSH
, NOFLSH
},
3059 { TARGET_TOSTOP
, TARGET_TOSTOP
, TOSTOP
, TOSTOP
},
3060 { TARGET_ECHOCTL
, TARGET_ECHOCTL
, ECHOCTL
, ECHOCTL
},
3061 { TARGET_ECHOPRT
, TARGET_ECHOPRT
, ECHOPRT
, ECHOPRT
},
3062 { TARGET_ECHOKE
, TARGET_ECHOKE
, ECHOKE
, ECHOKE
},
3063 { TARGET_FLUSHO
, TARGET_FLUSHO
, FLUSHO
, FLUSHO
},
3064 { TARGET_PENDIN
, TARGET_PENDIN
, PENDIN
, PENDIN
},
3065 { TARGET_IEXTEN
, TARGET_IEXTEN
, IEXTEN
, IEXTEN
},
3069 static void target_to_host_termios (void *dst
, const void *src
)
3071 struct host_termios
*host
= dst
;
3072 const struct target_termios
*target
= src
;
3075 target_to_host_bitmask(tswap32(target
->c_iflag
), iflag_tbl
);
3077 target_to_host_bitmask(tswap32(target
->c_oflag
), oflag_tbl
);
3079 target_to_host_bitmask(tswap32(target
->c_cflag
), cflag_tbl
);
3081 target_to_host_bitmask(tswap32(target
->c_lflag
), lflag_tbl
);
3082 host
->c_line
= target
->c_line
;
3084 memset(host
->c_cc
, 0, sizeof(host
->c_cc
));
3085 host
->c_cc
[VINTR
] = target
->c_cc
[TARGET_VINTR
];
3086 host
->c_cc
[VQUIT
] = target
->c_cc
[TARGET_VQUIT
];
3087 host
->c_cc
[VERASE
] = target
->c_cc
[TARGET_VERASE
];
3088 host
->c_cc
[VKILL
] = target
->c_cc
[TARGET_VKILL
];
3089 host
->c_cc
[VEOF
] = target
->c_cc
[TARGET_VEOF
];
3090 host
->c_cc
[VTIME
] = target
->c_cc
[TARGET_VTIME
];
3091 host
->c_cc
[VMIN
] = target
->c_cc
[TARGET_VMIN
];
3092 host
->c_cc
[VSWTC
] = target
->c_cc
[TARGET_VSWTC
];
3093 host
->c_cc
[VSTART
] = target
->c_cc
[TARGET_VSTART
];
3094 host
->c_cc
[VSTOP
] = target
->c_cc
[TARGET_VSTOP
];
3095 host
->c_cc
[VSUSP
] = target
->c_cc
[TARGET_VSUSP
];
3096 host
->c_cc
[VEOL
] = target
->c_cc
[TARGET_VEOL
];
3097 host
->c_cc
[VREPRINT
] = target
->c_cc
[TARGET_VREPRINT
];
3098 host
->c_cc
[VDISCARD
] = target
->c_cc
[TARGET_VDISCARD
];
3099 host
->c_cc
[VWERASE
] = target
->c_cc
[TARGET_VWERASE
];
3100 host
->c_cc
[VLNEXT
] = target
->c_cc
[TARGET_VLNEXT
];
3101 host
->c_cc
[VEOL2
] = target
->c_cc
[TARGET_VEOL2
];
3104 static void host_to_target_termios (void *dst
, const void *src
)
3106 struct target_termios
*target
= dst
;
3107 const struct host_termios
*host
= src
;
3110 tswap32(host_to_target_bitmask(host
->c_iflag
, iflag_tbl
));
3112 tswap32(host_to_target_bitmask(host
->c_oflag
, oflag_tbl
));
3114 tswap32(host_to_target_bitmask(host
->c_cflag
, cflag_tbl
));
3116 tswap32(host_to_target_bitmask(host
->c_lflag
, lflag_tbl
));
3117 target
->c_line
= host
->c_line
;
3119 memset(target
->c_cc
, 0, sizeof(target
->c_cc
));
3120 target
->c_cc
[TARGET_VINTR
] = host
->c_cc
[VINTR
];
3121 target
->c_cc
[TARGET_VQUIT
] = host
->c_cc
[VQUIT
];
3122 target
->c_cc
[TARGET_VERASE
] = host
->c_cc
[VERASE
];
3123 target
->c_cc
[TARGET_VKILL
] = host
->c_cc
[VKILL
];
3124 target
->c_cc
[TARGET_VEOF
] = host
->c_cc
[VEOF
];
3125 target
->c_cc
[TARGET_VTIME
] = host
->c_cc
[VTIME
];
3126 target
->c_cc
[TARGET_VMIN
] = host
->c_cc
[VMIN
];
3127 target
->c_cc
[TARGET_VSWTC
] = host
->c_cc
[VSWTC
];
3128 target
->c_cc
[TARGET_VSTART
] = host
->c_cc
[VSTART
];
3129 target
->c_cc
[TARGET_VSTOP
] = host
->c_cc
[VSTOP
];
3130 target
->c_cc
[TARGET_VSUSP
] = host
->c_cc
[VSUSP
];
3131 target
->c_cc
[TARGET_VEOL
] = host
->c_cc
[VEOL
];
3132 target
->c_cc
[TARGET_VREPRINT
] = host
->c_cc
[VREPRINT
];
3133 target
->c_cc
[TARGET_VDISCARD
] = host
->c_cc
[VDISCARD
];
3134 target
->c_cc
[TARGET_VWERASE
] = host
->c_cc
[VWERASE
];
3135 target
->c_cc
[TARGET_VLNEXT
] = host
->c_cc
[VLNEXT
];
3136 target
->c_cc
[TARGET_VEOL2
] = host
->c_cc
[VEOL2
];
3139 static const StructEntry struct_termios_def
= {
3140 .convert
= { host_to_target_termios
, target_to_host_termios
},
3141 .size
= { sizeof(struct target_termios
), sizeof(struct host_termios
) },
3142 .align
= { __alignof__(struct target_termios
), __alignof__(struct host_termios
) },
3145 static bitmask_transtbl mmap_flags_tbl
[] = {
3146 { TARGET_MAP_SHARED
, TARGET_MAP_SHARED
, MAP_SHARED
, MAP_SHARED
},
3147 { TARGET_MAP_PRIVATE
, TARGET_MAP_PRIVATE
, MAP_PRIVATE
, MAP_PRIVATE
},
3148 { TARGET_MAP_FIXED
, TARGET_MAP_FIXED
, MAP_FIXED
, MAP_FIXED
},
3149 { TARGET_MAP_ANONYMOUS
, TARGET_MAP_ANONYMOUS
, MAP_ANONYMOUS
, MAP_ANONYMOUS
},
3150 { TARGET_MAP_GROWSDOWN
, TARGET_MAP_GROWSDOWN
, MAP_GROWSDOWN
, MAP_GROWSDOWN
},
3151 { TARGET_MAP_DENYWRITE
, TARGET_MAP_DENYWRITE
, MAP_DENYWRITE
, MAP_DENYWRITE
},
3152 { TARGET_MAP_EXECUTABLE
, TARGET_MAP_EXECUTABLE
, MAP_EXECUTABLE
, MAP_EXECUTABLE
},
3153 { TARGET_MAP_LOCKED
, TARGET_MAP_LOCKED
, MAP_LOCKED
, MAP_LOCKED
},
3157 #if defined(TARGET_I386)
3159 /* NOTE: there is really one LDT for all the threads */
3160 static uint8_t *ldt_table
;
3162 static abi_long
read_ldt(abi_ulong ptr
, unsigned long bytecount
)
3169 size
= TARGET_LDT_ENTRIES
* TARGET_LDT_ENTRY_SIZE
;
3170 if (size
> bytecount
)
3172 p
= lock_user(VERIFY_WRITE
, ptr
, size
, 0);
3174 return -TARGET_EFAULT
;
3175 /* ??? Should this by byteswapped? */
3176 memcpy(p
, ldt_table
, size
);
3177 unlock_user(p
, ptr
, size
);
3181 /* XXX: add locking support */
3182 static abi_long
write_ldt(CPUX86State
*env
,
3183 abi_ulong ptr
, unsigned long bytecount
, int oldmode
)
3185 struct target_modify_ldt_ldt_s ldt_info
;
3186 struct target_modify_ldt_ldt_s
*target_ldt_info
;
3187 int seg_32bit
, contents
, read_exec_only
, limit_in_pages
;
3188 int seg_not_present
, useable
, lm
;
3189 uint32_t *lp
, entry_1
, entry_2
;
3191 if (bytecount
!= sizeof(ldt_info
))
3192 return -TARGET_EINVAL
;
3193 if (!lock_user_struct(VERIFY_READ
, target_ldt_info
, ptr
, 1))
3194 return -TARGET_EFAULT
;
3195 ldt_info
.entry_number
= tswap32(target_ldt_info
->entry_number
);
3196 ldt_info
.base_addr
= tswapl(target_ldt_info
->base_addr
);
3197 ldt_info
.limit
= tswap32(target_ldt_info
->limit
);
3198 ldt_info
.flags
= tswap32(target_ldt_info
->flags
);
3199 unlock_user_struct(target_ldt_info
, ptr
, 0);
3201 if (ldt_info
.entry_number
>= TARGET_LDT_ENTRIES
)
3202 return -TARGET_EINVAL
;
3203 seg_32bit
= ldt_info
.flags
& 1;
3204 contents
= (ldt_info
.flags
>> 1) & 3;
3205 read_exec_only
= (ldt_info
.flags
>> 3) & 1;
3206 limit_in_pages
= (ldt_info
.flags
>> 4) & 1;
3207 seg_not_present
= (ldt_info
.flags
>> 5) & 1;
3208 useable
= (ldt_info
.flags
>> 6) & 1;
3212 lm
= (ldt_info
.flags
>> 7) & 1;
3214 if (contents
== 3) {
3216 return -TARGET_EINVAL
;
3217 if (seg_not_present
== 0)
3218 return -TARGET_EINVAL
;
3220 /* allocate the LDT */
3222 env
->ldt
.base
= target_mmap(0,
3223 TARGET_LDT_ENTRIES
* TARGET_LDT_ENTRY_SIZE
,
3224 PROT_READ
|PROT_WRITE
,
3225 MAP_ANONYMOUS
|MAP_PRIVATE
, -1, 0);
3226 if (env
->ldt
.base
== -1)
3227 return -TARGET_ENOMEM
;
3228 memset(g2h(env
->ldt
.base
), 0,
3229 TARGET_LDT_ENTRIES
* TARGET_LDT_ENTRY_SIZE
);
3230 env
->ldt
.limit
= 0xffff;
3231 ldt_table
= g2h(env
->ldt
.base
);
3234 /* NOTE: same code as Linux kernel */
3235 /* Allow LDTs to be cleared by the user. */
3236 if (ldt_info
.base_addr
== 0 && ldt_info
.limit
== 0) {
3239 read_exec_only
== 1 &&
3241 limit_in_pages
== 0 &&
3242 seg_not_present
== 1 &&
3250 entry_1
= ((ldt_info
.base_addr
& 0x0000ffff) << 16) |
3251 (ldt_info
.limit
& 0x0ffff);
3252 entry_2
= (ldt_info
.base_addr
& 0xff000000) |
3253 ((ldt_info
.base_addr
& 0x00ff0000) >> 16) |
3254 (ldt_info
.limit
& 0xf0000) |
3255 ((read_exec_only
^ 1) << 9) |
3257 ((seg_not_present
^ 1) << 15) |
3259 (limit_in_pages
<< 23) |
3263 entry_2
|= (useable
<< 20);
3265 /* Install the new entry ... */
3267 lp
= (uint32_t *)(ldt_table
+ (ldt_info
.entry_number
<< 3));
3268 lp
[0] = tswap32(entry_1
);
3269 lp
[1] = tswap32(entry_2
);
3273 /* specific and weird i386 syscalls */
3274 static abi_long
do_modify_ldt(CPUX86State
*env
, int func
, abi_ulong ptr
,
3275 unsigned long bytecount
)
3281 ret
= read_ldt(ptr
, bytecount
);
3284 ret
= write_ldt(env
, ptr
, bytecount
, 1);
3287 ret
= write_ldt(env
, ptr
, bytecount
, 0);
3290 ret
= -TARGET_ENOSYS
;
3296 #if defined(TARGET_I386) && defined(TARGET_ABI32)
3297 static abi_long
do_set_thread_area(CPUX86State
*env
, abi_ulong ptr
)
3299 uint64_t *gdt_table
= g2h(env
->gdt
.base
);
3300 struct target_modify_ldt_ldt_s ldt_info
;
3301 struct target_modify_ldt_ldt_s
*target_ldt_info
;
3302 int seg_32bit
, contents
, read_exec_only
, limit_in_pages
;
3303 int seg_not_present
, useable
, lm
;
3304 uint32_t *lp
, entry_1
, entry_2
;
3307 lock_user_struct(VERIFY_WRITE
, target_ldt_info
, ptr
, 1);
3308 if (!target_ldt_info
)
3309 return -TARGET_EFAULT
;
3310 ldt_info
.entry_number
= tswap32(target_ldt_info
->entry_number
);
3311 ldt_info
.base_addr
= tswapl(target_ldt_info
->base_addr
);
3312 ldt_info
.limit
= tswap32(target_ldt_info
->limit
);
3313 ldt_info
.flags
= tswap32(target_ldt_info
->flags
);
3314 if (ldt_info
.entry_number
== -1) {
3315 for (i
=TARGET_GDT_ENTRY_TLS_MIN
; i
<=TARGET_GDT_ENTRY_TLS_MAX
; i
++) {
3316 if (gdt_table
[i
] == 0) {
3317 ldt_info
.entry_number
= i
;
3318 target_ldt_info
->entry_number
= tswap32(i
);
3323 unlock_user_struct(target_ldt_info
, ptr
, 1);
3325 if (ldt_info
.entry_number
< TARGET_GDT_ENTRY_TLS_MIN
||
3326 ldt_info
.entry_number
> TARGET_GDT_ENTRY_TLS_MAX
)
3327 return -TARGET_EINVAL
;
3328 seg_32bit
= ldt_info
.flags
& 1;
3329 contents
= (ldt_info
.flags
>> 1) & 3;
3330 read_exec_only
= (ldt_info
.flags
>> 3) & 1;
3331 limit_in_pages
= (ldt_info
.flags
>> 4) & 1;
3332 seg_not_present
= (ldt_info
.flags
>> 5) & 1;
3333 useable
= (ldt_info
.flags
>> 6) & 1;
3337 lm
= (ldt_info
.flags
>> 7) & 1;
3340 if (contents
== 3) {
3341 if (seg_not_present
== 0)
3342 return -TARGET_EINVAL
;
3345 /* NOTE: same code as Linux kernel */
3346 /* Allow LDTs to be cleared by the user. */
3347 if (ldt_info
.base_addr
== 0 && ldt_info
.limit
== 0) {
3348 if ((contents
== 0 &&
3349 read_exec_only
== 1 &&
3351 limit_in_pages
== 0 &&
3352 seg_not_present
== 1 &&
3360 entry_1
= ((ldt_info
.base_addr
& 0x0000ffff) << 16) |
3361 (ldt_info
.limit
& 0x0ffff);
3362 entry_2
= (ldt_info
.base_addr
& 0xff000000) |
3363 ((ldt_info
.base_addr
& 0x00ff0000) >> 16) |
3364 (ldt_info
.limit
& 0xf0000) |
3365 ((read_exec_only
^ 1) << 9) |
3367 ((seg_not_present
^ 1) << 15) |
3369 (limit_in_pages
<< 23) |
3374 /* Install the new entry ... */
3376 lp
= (uint32_t *)(gdt_table
+ ldt_info
.entry_number
);
3377 lp
[0] = tswap32(entry_1
);
3378 lp
[1] = tswap32(entry_2
);
3382 static abi_long
do_get_thread_area(CPUX86State
*env
, abi_ulong ptr
)
3384 struct target_modify_ldt_ldt_s
*target_ldt_info
;
3385 uint64_t *gdt_table
= g2h(env
->gdt
.base
);
3386 uint32_t base_addr
, limit
, flags
;
3387 int seg_32bit
, contents
, read_exec_only
, limit_in_pages
, idx
;
3388 int seg_not_present
, useable
, lm
;
3389 uint32_t *lp
, entry_1
, entry_2
;
3391 lock_user_struct(VERIFY_WRITE
, target_ldt_info
, ptr
, 1);
3392 if (!target_ldt_info
)
3393 return -TARGET_EFAULT
;
3394 idx
= tswap32(target_ldt_info
->entry_number
);
3395 if (idx
< TARGET_GDT_ENTRY_TLS_MIN
||
3396 idx
> TARGET_GDT_ENTRY_TLS_MAX
) {
3397 unlock_user_struct(target_ldt_info
, ptr
, 1);
3398 return -TARGET_EINVAL
;
3400 lp
= (uint32_t *)(gdt_table
+ idx
);
3401 entry_1
= tswap32(lp
[0]);
3402 entry_2
= tswap32(lp
[1]);
3404 read_exec_only
= ((entry_2
>> 9) & 1) ^ 1;
3405 contents
= (entry_2
>> 10) & 3;
3406 seg_not_present
= ((entry_2
>> 15) & 1) ^ 1;
3407 seg_32bit
= (entry_2
>> 22) & 1;
3408 limit_in_pages
= (entry_2
>> 23) & 1;
3409 useable
= (entry_2
>> 20) & 1;
3413 lm
= (entry_2
>> 21) & 1;
3415 flags
= (seg_32bit
<< 0) | (contents
<< 1) |
3416 (read_exec_only
<< 3) | (limit_in_pages
<< 4) |
3417 (seg_not_present
<< 5) | (useable
<< 6) | (lm
<< 7);
3418 limit
= (entry_1
& 0xffff) | (entry_2
& 0xf0000);
3419 base_addr
= (entry_1
>> 16) |
3420 (entry_2
& 0xff000000) |
3421 ((entry_2
& 0xff) << 16);
3422 target_ldt_info
->base_addr
= tswapl(base_addr
);
3423 target_ldt_info
->limit
= tswap32(limit
);
3424 target_ldt_info
->flags
= tswap32(flags
);
3425 unlock_user_struct(target_ldt_info
, ptr
, 1);
3428 #endif /* TARGET_I386 && TARGET_ABI32 */
3430 #ifndef TARGET_ABI32
3431 static abi_long
do_arch_prctl(CPUX86State
*env
, int code
, abi_ulong addr
)
3438 case TARGET_ARCH_SET_GS
:
3439 case TARGET_ARCH_SET_FS
:
3440 if (code
== TARGET_ARCH_SET_GS
)
3444 cpu_x86_load_seg(env
, idx
, 0);
3445 env
->segs
[idx
].base
= addr
;
3447 case TARGET_ARCH_GET_GS
:
3448 case TARGET_ARCH_GET_FS
:
3449 if (code
== TARGET_ARCH_GET_GS
)
3453 val
= env
->segs
[idx
].base
;
3454 if (put_user(val
, addr
, abi_ulong
))
3455 return -TARGET_EFAULT
;
3458 ret
= -TARGET_EINVAL
;
3465 #endif /* defined(TARGET_I386) */
3467 #if defined(CONFIG_USE_NPTL)
3469 #define NEW_STACK_SIZE PTHREAD_STACK_MIN
3471 static pthread_mutex_t clone_lock
= PTHREAD_MUTEX_INITIALIZER
;
3474 pthread_mutex_t mutex
;
3475 pthread_cond_t cond
;
3478 abi_ulong child_tidptr
;
3479 abi_ulong parent_tidptr
;
3483 static void *clone_func(void *arg
)
3485 new_thread_info
*info
= arg
;
3491 ts
= (TaskState
*)thread_env
->opaque
;
3492 info
->tid
= gettid();
3493 env
->host_tid
= info
->tid
;
3495 if (info
->child_tidptr
)
3496 put_user_u32(info
->tid
, info
->child_tidptr
);
3497 if (info
->parent_tidptr
)
3498 put_user_u32(info
->tid
, info
->parent_tidptr
);
3499 /* Enable signals. */
3500 sigprocmask(SIG_SETMASK
, &info
->sigmask
, NULL
);
3501 /* Signal to the parent that we're ready. */
3502 pthread_mutex_lock(&info
->mutex
);
3503 pthread_cond_broadcast(&info
->cond
);
3504 pthread_mutex_unlock(&info
->mutex
);
3505 /* Wait until the parent has finshed initializing the tls state. */
3506 pthread_mutex_lock(&clone_lock
);
3507 pthread_mutex_unlock(&clone_lock
);
3513 /* this stack is the equivalent of the kernel stack associated with a
3515 #define NEW_STACK_SIZE 8192
3517 static int clone_func(void *arg
)
3519 CPUState
*env
= arg
;
3526 /* do_fork() Must return host values and target errnos (unlike most
3527 do_*() functions). */
3528 static int do_fork(CPUState
*env
, unsigned int flags
, abi_ulong newsp
,
3529 abi_ulong parent_tidptr
, target_ulong newtls
,
3530 abi_ulong child_tidptr
)
3536 #if defined(CONFIG_USE_NPTL)
3537 unsigned int nptl_flags
;
3541 /* Emulate vfork() with fork() */
3542 if (flags
& CLONE_VFORK
)
3543 flags
&= ~(CLONE_VFORK
| CLONE_VM
);
3545 if (flags
& CLONE_VM
) {
3546 TaskState
*parent_ts
= (TaskState
*)env
->opaque
;
3547 #if defined(CONFIG_USE_NPTL)
3548 new_thread_info info
;
3549 pthread_attr_t attr
;
3551 ts
= qemu_mallocz(sizeof(TaskState
) + NEW_STACK_SIZE
);
3552 init_task_state(ts
);
3553 new_stack
= ts
->stack
;
3554 /* we create a new CPU instance. */
3555 new_env
= cpu_copy(env
);
3556 /* Init regs that differ from the parent. */
3557 cpu_clone_regs(new_env
, newsp
);
3558 new_env
->opaque
= ts
;
3559 ts
->bprm
= parent_ts
->bprm
;
3560 ts
->info
= parent_ts
->info
;
3561 #if defined(CONFIG_USE_NPTL)
3563 flags
&= ~CLONE_NPTL_FLAGS2
;
3565 if (nptl_flags
& CLONE_CHILD_CLEARTID
) {
3566 ts
->child_tidptr
= child_tidptr
;
3569 if (nptl_flags
& CLONE_SETTLS
)
3570 cpu_set_tls (new_env
, newtls
);
3572 /* Grab a mutex so that thread setup appears atomic. */
3573 pthread_mutex_lock(&clone_lock
);
3575 memset(&info
, 0, sizeof(info
));
3576 pthread_mutex_init(&info
.mutex
, NULL
);
3577 pthread_mutex_lock(&info
.mutex
);
3578 pthread_cond_init(&info
.cond
, NULL
);
3580 if (nptl_flags
& CLONE_CHILD_SETTID
)
3581 info
.child_tidptr
= child_tidptr
;
3582 if (nptl_flags
& CLONE_PARENT_SETTID
)
3583 info
.parent_tidptr
= parent_tidptr
;
3585 ret
= pthread_attr_init(&attr
);
3586 ret
= pthread_attr_setstack(&attr
, new_stack
, NEW_STACK_SIZE
);
3587 /* It is not safe to deliver signals until the child has finished
3588 initializing, so temporarily block all signals. */
3589 sigfillset(&sigmask
);
3590 sigprocmask(SIG_BLOCK
, &sigmask
, &info
.sigmask
);
3592 ret
= pthread_create(&info
.thread
, &attr
, clone_func
, &info
);
3593 /* TODO: Free new CPU state if thread creation failed. */
3595 sigprocmask(SIG_SETMASK
, &info
.sigmask
, NULL
);
3596 pthread_attr_destroy(&attr
);
3598 /* Wait for the child to initialize. */
3599 pthread_cond_wait(&info
.cond
, &info
.mutex
);
3601 if (flags
& CLONE_PARENT_SETTID
)
3602 put_user_u32(ret
, parent_tidptr
);
3606 pthread_mutex_unlock(&info
.mutex
);
3607 pthread_cond_destroy(&info
.cond
);
3608 pthread_mutex_destroy(&info
.mutex
);
3609 pthread_mutex_unlock(&clone_lock
);
3611 if (flags
& CLONE_NPTL_FLAGS2
)
3613 /* This is probably going to die very quickly, but do it anyway. */
3615 ret
= __clone2(clone_func
, new_stack
+ NEW_STACK_SIZE
, flags
, new_env
);
3617 ret
= clone(clone_func
, new_stack
+ NEW_STACK_SIZE
, flags
, new_env
);
3621 /* if no CLONE_VM, we consider it is a fork */
3622 if ((flags
& ~(CSIGNAL
| CLONE_NPTL_FLAGS2
)) != 0)
3627 /* Child Process. */
3628 cpu_clone_regs(env
, newsp
);
3630 #if defined(CONFIG_USE_NPTL)
3631 /* There is a race condition here. The parent process could
3632 theoretically read the TID in the child process before the child
3633 tid is set. This would require using either ptrace
3634 (not implemented) or having *_tidptr to point at a shared memory
3635 mapping. We can't repeat the spinlock hack used above because
3636 the child process gets its own copy of the lock. */
3637 if (flags
& CLONE_CHILD_SETTID
)
3638 put_user_u32(gettid(), child_tidptr
);
3639 if (flags
& CLONE_PARENT_SETTID
)
3640 put_user_u32(gettid(), parent_tidptr
);
3641 ts
= (TaskState
*)env
->opaque
;
3642 if (flags
& CLONE_SETTLS
)
3643 cpu_set_tls (env
, newtls
);
3644 if (flags
& CLONE_CHILD_CLEARTID
)
3645 ts
->child_tidptr
= child_tidptr
;
3654 /* warning : doesn't handle linux specific flags... */
3655 static int target_to_host_fcntl_cmd(int cmd
)
3658 case TARGET_F_DUPFD
:
3659 case TARGET_F_GETFD
:
3660 case TARGET_F_SETFD
:
3661 case TARGET_F_GETFL
:
3662 case TARGET_F_SETFL
:
3664 case TARGET_F_GETLK
:
3666 case TARGET_F_SETLK
:
3668 case TARGET_F_SETLKW
:
3670 case TARGET_F_GETOWN
:
3672 case TARGET_F_SETOWN
:
3674 case TARGET_F_GETSIG
:
3676 case TARGET_F_SETSIG
:
3678 #if TARGET_ABI_BITS == 32
3679 case TARGET_F_GETLK64
:
3681 case TARGET_F_SETLK64
:
3683 case TARGET_F_SETLKW64
:
3686 case TARGET_F_SETLEASE
:
3688 case TARGET_F_GETLEASE
:
3690 #ifdef F_DUPFD_CLOEXEC
3691 case TARGET_F_DUPFD_CLOEXEC
:
3692 return F_DUPFD_CLOEXEC
;
3694 case TARGET_F_NOTIFY
:
3697 return -TARGET_EINVAL
;
3699 return -TARGET_EINVAL
;
3702 static abi_long
do_fcntl(int fd
, int cmd
, abi_ulong arg
)
3705 struct target_flock
*target_fl
;
3706 struct flock64 fl64
;
3707 struct target_flock64
*target_fl64
;
3709 int host_cmd
= target_to_host_fcntl_cmd(cmd
);
3711 if (host_cmd
== -TARGET_EINVAL
)
3715 case TARGET_F_GETLK
:
3716 if (!lock_user_struct(VERIFY_READ
, target_fl
, arg
, 1))
3717 return -TARGET_EFAULT
;
3718 fl
.l_type
= tswap16(target_fl
->l_type
);
3719 fl
.l_whence
= tswap16(target_fl
->l_whence
);
3720 fl
.l_start
= tswapl(target_fl
->l_start
);
3721 fl
.l_len
= tswapl(target_fl
->l_len
);
3722 fl
.l_pid
= tswap32(target_fl
->l_pid
);
3723 unlock_user_struct(target_fl
, arg
, 0);
3724 ret
= get_errno(fcntl(fd
, host_cmd
, &fl
));
3726 if (!lock_user_struct(VERIFY_WRITE
, target_fl
, arg
, 0))
3727 return -TARGET_EFAULT
;
3728 target_fl
->l_type
= tswap16(fl
.l_type
);
3729 target_fl
->l_whence
= tswap16(fl
.l_whence
);
3730 target_fl
->l_start
= tswapl(fl
.l_start
);
3731 target_fl
->l_len
= tswapl(fl
.l_len
);
3732 target_fl
->l_pid
= tswap32(fl
.l_pid
);
3733 unlock_user_struct(target_fl
, arg
, 1);
3737 case TARGET_F_SETLK
:
3738 case TARGET_F_SETLKW
:
3739 if (!lock_user_struct(VERIFY_READ
, target_fl
, arg
, 1))
3740 return -TARGET_EFAULT
;
3741 fl
.l_type
= tswap16(target_fl
->l_type
);
3742 fl
.l_whence
= tswap16(target_fl
->l_whence
);
3743 fl
.l_start
= tswapl(target_fl
->l_start
);
3744 fl
.l_len
= tswapl(target_fl
->l_len
);
3745 fl
.l_pid
= tswap32(target_fl
->l_pid
);
3746 unlock_user_struct(target_fl
, arg
, 0);
3747 ret
= get_errno(fcntl(fd
, host_cmd
, &fl
));
3750 case TARGET_F_GETLK64
:
3751 if (!lock_user_struct(VERIFY_READ
, target_fl64
, arg
, 1))
3752 return -TARGET_EFAULT
;
3753 fl64
.l_type
= tswap16(target_fl64
->l_type
) >> 1;
3754 fl64
.l_whence
= tswap16(target_fl64
->l_whence
);
3755 fl64
.l_start
= tswapl(target_fl64
->l_start
);
3756 fl64
.l_len
= tswapl(target_fl64
->l_len
);
3757 fl64
.l_pid
= tswap32(target_fl64
->l_pid
);
3758 unlock_user_struct(target_fl64
, arg
, 0);
3759 ret
= get_errno(fcntl(fd
, host_cmd
, &fl64
));
3761 if (!lock_user_struct(VERIFY_WRITE
, target_fl64
, arg
, 0))
3762 return -TARGET_EFAULT
;
3763 target_fl64
->l_type
= tswap16(fl64
.l_type
) >> 1;
3764 target_fl64
->l_whence
= tswap16(fl64
.l_whence
);
3765 target_fl64
->l_start
= tswapl(fl64
.l_start
);
3766 target_fl64
->l_len
= tswapl(fl64
.l_len
);
3767 target_fl64
->l_pid
= tswap32(fl64
.l_pid
);
3768 unlock_user_struct(target_fl64
, arg
, 1);
3771 case TARGET_F_SETLK64
:
3772 case TARGET_F_SETLKW64
:
3773 if (!lock_user_struct(VERIFY_READ
, target_fl64
, arg
, 1))
3774 return -TARGET_EFAULT
;
3775 fl64
.l_type
= tswap16(target_fl64
->l_type
) >> 1;
3776 fl64
.l_whence
= tswap16(target_fl64
->l_whence
);
3777 fl64
.l_start
= tswapl(target_fl64
->l_start
);
3778 fl64
.l_len
= tswapl(target_fl64
->l_len
);
3779 fl64
.l_pid
= tswap32(target_fl64
->l_pid
);
3780 unlock_user_struct(target_fl64
, arg
, 0);
3781 ret
= get_errno(fcntl(fd
, host_cmd
, &fl64
));
3784 case TARGET_F_GETFL
:
3785 ret
= get_errno(fcntl(fd
, host_cmd
, arg
));
3787 ret
= host_to_target_bitmask(ret
, fcntl_flags_tbl
);
3791 case TARGET_F_SETFL
:
3792 ret
= get_errno(fcntl(fd
, host_cmd
, target_to_host_bitmask(arg
, fcntl_flags_tbl
)));
3795 case TARGET_F_SETOWN
:
3796 case TARGET_F_GETOWN
:
3797 case TARGET_F_SETSIG
:
3798 case TARGET_F_GETSIG
:
3799 case TARGET_F_SETLEASE
:
3800 case TARGET_F_GETLEASE
:
3801 ret
= get_errno(fcntl(fd
, host_cmd
, arg
));
3805 ret
= get_errno(fcntl(fd
, cmd
, arg
));
3813 static inline int high2lowuid(int uid
)
3821 static inline int high2lowgid(int gid
)
3829 static inline int low2highuid(int uid
)
3831 if ((int16_t)uid
== -1)
3837 static inline int low2highgid(int gid
)
3839 if ((int16_t)gid
== -1)
3845 #endif /* USE_UID16 */
3847 void syscall_init(void)
3850 const argtype
*arg_type
;
3854 #define STRUCT(name, ...) thunk_register_struct(STRUCT_ ## name, #name, struct_ ## name ## _def);
3855 #define STRUCT_SPECIAL(name) thunk_register_struct_direct(STRUCT_ ## name, #name, &struct_ ## name ## _def);
3856 #include "syscall_types.h"
3858 #undef STRUCT_SPECIAL
3860 /* we patch the ioctl size if necessary. We rely on the fact that
3861 no ioctl has all the bits at '1' in the size field */
3863 while (ie
->target_cmd
!= 0) {
3864 if (((ie
->target_cmd
>> TARGET_IOC_SIZESHIFT
) & TARGET_IOC_SIZEMASK
) ==
3865 TARGET_IOC_SIZEMASK
) {
3866 arg_type
= ie
->arg_type
;
3867 if (arg_type
[0] != TYPE_PTR
) {
3868 fprintf(stderr
, "cannot patch size for ioctl 0x%x\n",
3873 size
= thunk_type_size(arg_type
, 0);
3874 ie
->target_cmd
= (ie
->target_cmd
&
3875 ~(TARGET_IOC_SIZEMASK
<< TARGET_IOC_SIZESHIFT
)) |
3876 (size
<< TARGET_IOC_SIZESHIFT
);
3879 /* Build target_to_host_errno_table[] table from
3880 * host_to_target_errno_table[]. */
3881 for (i
=0; i
< ERRNO_TABLE_SIZE
; i
++)
3882 target_to_host_errno_table
[host_to_target_errno_table
[i
]] = i
;
3884 /* automatic consistency check if same arch */
3885 #if (defined(__i386__) && defined(TARGET_I386) && defined(TARGET_ABI32)) || \
3886 (defined(__x86_64__) && defined(TARGET_X86_64))
3887 if (unlikely(ie
->target_cmd
!= ie
->host_cmd
)) {
3888 fprintf(stderr
, "ERROR: ioctl(%s): target=0x%x host=0x%x\n",
3889 ie
->name
, ie
->target_cmd
, ie
->host_cmd
);
3896 #if TARGET_ABI_BITS == 32
3897 static inline uint64_t target_offset64(uint32_t word0
, uint32_t word1
)
3899 #ifdef TARGET_WORDS_BIGENDIAN
3900 return ((uint64_t)word0
<< 32) | word1
;
3902 return ((uint64_t)word1
<< 32) | word0
;
3905 #else /* TARGET_ABI_BITS == 32 */
3906 static inline uint64_t target_offset64(uint64_t word0
, uint64_t word1
)
3910 #endif /* TARGET_ABI_BITS != 32 */
3912 #ifdef TARGET_NR_truncate64
3913 static inline abi_long
target_truncate64(void *cpu_env
, const char *arg1
,
3919 if (((CPUARMState
*)cpu_env
)->eabi
)
3925 return get_errno(truncate64(arg1
, target_offset64(arg2
, arg3
)));
3929 #ifdef TARGET_NR_ftruncate64
3930 static inline abi_long
target_ftruncate64(void *cpu_env
, abi_long arg1
,
3936 if (((CPUARMState
*)cpu_env
)->eabi
)
3942 return get_errno(ftruncate64(arg1
, target_offset64(arg2
, arg3
)));
3946 static inline abi_long
target_to_host_timespec(struct timespec
*host_ts
,
3947 abi_ulong target_addr
)
3949 struct target_timespec
*target_ts
;
3951 if (!lock_user_struct(VERIFY_READ
, target_ts
, target_addr
, 1))
3952 return -TARGET_EFAULT
;
3953 host_ts
->tv_sec
= tswapl(target_ts
->tv_sec
);
3954 host_ts
->tv_nsec
= tswapl(target_ts
->tv_nsec
);
3955 unlock_user_struct(target_ts
, target_addr
, 0);
3959 static inline abi_long
host_to_target_timespec(abi_ulong target_addr
,
3960 struct timespec
*host_ts
)
3962 struct target_timespec
*target_ts
;
3964 if (!lock_user_struct(VERIFY_WRITE
, target_ts
, target_addr
, 0))
3965 return -TARGET_EFAULT
;
3966 target_ts
->tv_sec
= tswapl(host_ts
->tv_sec
);
3967 target_ts
->tv_nsec
= tswapl(host_ts
->tv_nsec
);
3968 unlock_user_struct(target_ts
, target_addr
, 1);
3972 #if defined(TARGET_NR_stat64) || defined(TARGET_NR_newfstatat)
3973 static inline abi_long
host_to_target_stat64(void *cpu_env
,
3974 abi_ulong target_addr
,
3975 struct stat
*host_st
)
3978 if (((CPUARMState
*)cpu_env
)->eabi
) {
3979 struct target_eabi_stat64
*target_st
;
3981 if (!lock_user_struct(VERIFY_WRITE
, target_st
, target_addr
, 0))
3982 return -TARGET_EFAULT
;
3983 memset(target_st
, 0, sizeof(struct target_eabi_stat64
));
3984 __put_user(host_st
->st_dev
, &target_st
->st_dev
);
3985 __put_user(host_st
->st_ino
, &target_st
->st_ino
);
3986 #ifdef TARGET_STAT64_HAS_BROKEN_ST_INO
3987 __put_user(host_st
->st_ino
, &target_st
->__st_ino
);
3989 __put_user(host_st
->st_mode
, &target_st
->st_mode
);
3990 __put_user(host_st
->st_nlink
, &target_st
->st_nlink
);
3991 __put_user(host_st
->st_uid
, &target_st
->st_uid
);
3992 __put_user(host_st
->st_gid
, &target_st
->st_gid
);
3993 __put_user(host_st
->st_rdev
, &target_st
->st_rdev
);
3994 __put_user(host_st
->st_size
, &target_st
->st_size
);
3995 __put_user(host_st
->st_blksize
, &target_st
->st_blksize
);
3996 __put_user(host_st
->st_blocks
, &target_st
->st_blocks
);
3997 __put_user(host_st
->st_atime
, &target_st
->target_st_atime
);
3998 __put_user(host_st
->st_mtime
, &target_st
->target_st_mtime
);
3999 __put_user(host_st
->st_ctime
, &target_st
->target_st_ctime
);
4000 unlock_user_struct(target_st
, target_addr
, 1);
4004 #if TARGET_LONG_BITS == 64
4005 struct target_stat
*target_st
;
4007 struct target_stat64
*target_st
;
4010 if (!lock_user_struct(VERIFY_WRITE
, target_st
, target_addr
, 0))
4011 return -TARGET_EFAULT
;
4012 memset(target_st
, 0, sizeof(*target_st
));
4013 __put_user(host_st
->st_dev
, &target_st
->st_dev
);
4014 __put_user(host_st
->st_ino
, &target_st
->st_ino
);
4015 #ifdef TARGET_STAT64_HAS_BROKEN_ST_INO
4016 __put_user(host_st
->st_ino
, &target_st
->__st_ino
);
4018 __put_user(host_st
->st_mode
, &target_st
->st_mode
);
4019 __put_user(host_st
->st_nlink
, &target_st
->st_nlink
);
4020 __put_user(host_st
->st_uid
, &target_st
->st_uid
);
4021 __put_user(host_st
->st_gid
, &target_st
->st_gid
);
4022 __put_user(host_st
->st_rdev
, &target_st
->st_rdev
);
4023 /* XXX: better use of kernel struct */
4024 __put_user(host_st
->st_size
, &target_st
->st_size
);
4025 __put_user(host_st
->st_blksize
, &target_st
->st_blksize
);
4026 __put_user(host_st
->st_blocks
, &target_st
->st_blocks
);
4027 __put_user(host_st
->st_atime
, &target_st
->target_st_atime
);
4028 __put_user(host_st
->st_mtime
, &target_st
->target_st_mtime
);
4029 __put_user(host_st
->st_ctime
, &target_st
->target_st_ctime
);
4030 unlock_user_struct(target_st
, target_addr
, 1);
4037 #if defined(CONFIG_USE_NPTL)
4038 /* ??? Using host futex calls even when target atomic operations
4039 are not really atomic probably breaks things. However implementing
4040 futexes locally would make futexes shared between multiple processes
4041 tricky. However they're probably useless because guest atomic
4042 operations won't work either. */
4043 static int do_futex(target_ulong uaddr
, int op
, int val
, target_ulong timeout
,
4044 target_ulong uaddr2
, int val3
)
4046 struct timespec ts
, *pts
;
4049 /* ??? We assume FUTEX_* constants are the same on both host
4051 #ifdef FUTEX_CMD_MASK
4052 base_op
= op
& FUTEX_CMD_MASK
;
4060 target_to_host_timespec(pts
, timeout
);
4064 return get_errno(sys_futex(g2h(uaddr
), op
, tswap32(val
),
4067 return get_errno(sys_futex(g2h(uaddr
), op
, val
, NULL
, NULL
, 0));
4069 return get_errno(sys_futex(g2h(uaddr
), op
, val
, NULL
, NULL
, 0));
4071 case FUTEX_CMP_REQUEUE
:
4073 /* For FUTEX_REQUEUE, FUTEX_CMP_REQUEUE, and FUTEX_WAKE_OP, the
4074 TIMEOUT parameter is interpreted as a uint32_t by the kernel.
4075 But the prototype takes a `struct timespec *'; insert casts
4076 to satisfy the compiler. We do not need to tswap TIMEOUT
4077 since it's not compared to guest memory. */
4078 pts
= (struct timespec
*)(uintptr_t) timeout
;
4079 return get_errno(sys_futex(g2h(uaddr
), op
, val
, pts
,
4081 (base_op
== FUTEX_CMP_REQUEUE
4085 return -TARGET_ENOSYS
;
4090 /* Map host to target signal numbers for the wait family of syscalls.
4091 Assume all other status bits are the same. */
4092 static int host_to_target_waitstatus(int status
)
4094 if (WIFSIGNALED(status
)) {
4095 return host_to_target_signal(WTERMSIG(status
)) | (status
& ~0x7f);
4097 if (WIFSTOPPED(status
)) {
4098 return (host_to_target_signal(WSTOPSIG(status
)) << 8)
4104 int get_osversion(void)
4106 static int osversion
;
4107 struct new_utsname buf
;
4112 if (qemu_uname_release
&& *qemu_uname_release
) {
4113 s
= qemu_uname_release
;
4115 if (sys_uname(&buf
))
4120 for (i
= 0; i
< 3; i
++) {
4122 while (*s
>= '0' && *s
<= '9') {
4127 tmp
= (tmp
<< 8) + n
;
4135 /* do_syscall() should always have a single exit point at the end so
4136 that actions, such as logging of syscall results, can be performed.
4137 All errnos that do_syscall() returns must be -TARGET_<errcode>. */
4138 abi_long
do_syscall(void *cpu_env
, int num
, abi_long arg1
,
4139 abi_long arg2
, abi_long arg3
, abi_long arg4
,
4140 abi_long arg5
, abi_long arg6
)
4148 gemu_log("syscall %d", num
);
4151 print_syscall(num
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
4154 case TARGET_NR_exit
:
4155 #ifdef CONFIG_USE_NPTL
4156 /* In old applications this may be used to implement _exit(2).
4157 However in threaded applictions it is used for thread termination,
4158 and _exit_group is used for application termination.
4159 Do thread termination if we have more then one thread. */
4160 /* FIXME: This probably breaks if a signal arrives. We should probably
4161 be disabling signals. */
4162 if (first_cpu
->next_cpu
) {
4170 while (p
&& p
!= (CPUState
*)cpu_env
) {
4171 lastp
= &p
->next_cpu
;
4174 /* If we didn't find the CPU for this thread then something is
4178 /* Remove the CPU from the list. */
4179 *lastp
= p
->next_cpu
;
4181 ts
= ((CPUState
*)cpu_env
)->opaque
;
4182 if (ts
->child_tidptr
) {
4183 put_user_u32(0, ts
->child_tidptr
);
4184 sys_futex(g2h(ts
->child_tidptr
), FUTEX_WAKE
, INT_MAX
,
4187 /* TODO: Free CPU state. */
4194 gdb_exit(cpu_env
, arg1
);
4196 ret
= 0; /* avoid warning */
4198 case TARGET_NR_read
:
4202 if (!(p
= lock_user(VERIFY_WRITE
, arg2
, arg3
, 0)))
4204 ret
= get_errno(read(arg1
, p
, arg3
));
4205 unlock_user(p
, arg2
, ret
);
4208 case TARGET_NR_write
:
4209 if (!(p
= lock_user(VERIFY_READ
, arg2
, arg3
, 1)))
4211 ret
= get_errno(write(arg1
, p
, arg3
));
4212 unlock_user(p
, arg2
, 0);
4214 case TARGET_NR_open
:
4215 if (!(p
= lock_user_string(arg1
)))
4217 ret
= get_errno(open(path(p
),
4218 target_to_host_bitmask(arg2
, fcntl_flags_tbl
),
4220 unlock_user(p
, arg1
, 0);
4222 #if defined(TARGET_NR_openat) && defined(__NR_openat)
4223 case TARGET_NR_openat
:
4224 if (!(p
= lock_user_string(arg2
)))
4226 ret
= get_errno(sys_openat(arg1
,
4228 target_to_host_bitmask(arg3
, fcntl_flags_tbl
),
4230 unlock_user(p
, arg2
, 0);
4233 case TARGET_NR_close
:
4234 ret
= get_errno(close(arg1
));
4239 case TARGET_NR_fork
:
4240 ret
= get_errno(do_fork(cpu_env
, SIGCHLD
, 0, 0, 0, 0));
4242 #ifdef TARGET_NR_waitpid
4243 case TARGET_NR_waitpid
:
4246 ret
= get_errno(waitpid(arg1
, &status
, arg3
));
4247 if (!is_error(ret
) && arg2
4248 && put_user_s32(host_to_target_waitstatus(status
), arg2
))
4253 #ifdef TARGET_NR_waitid
4254 case TARGET_NR_waitid
:
4258 ret
= get_errno(waitid(arg1
, arg2
, &info
, arg4
));
4259 if (!is_error(ret
) && arg3
&& info
.si_pid
!= 0) {
4260 if (!(p
= lock_user(VERIFY_WRITE
, arg3
, sizeof(target_siginfo_t
), 0)))
4262 host_to_target_siginfo(p
, &info
);
4263 unlock_user(p
, arg3
, sizeof(target_siginfo_t
));
4268 #ifdef TARGET_NR_creat /* not on alpha */
4269 case TARGET_NR_creat
:
4270 if (!(p
= lock_user_string(arg1
)))
4272 ret
= get_errno(creat(p
, arg2
));
4273 unlock_user(p
, arg1
, 0);
4276 case TARGET_NR_link
:
4279 p
= lock_user_string(arg1
);
4280 p2
= lock_user_string(arg2
);
4282 ret
= -TARGET_EFAULT
;
4284 ret
= get_errno(link(p
, p2
));
4285 unlock_user(p2
, arg2
, 0);
4286 unlock_user(p
, arg1
, 0);
4289 #if defined(TARGET_NR_linkat) && defined(__NR_linkat)
4290 case TARGET_NR_linkat
:
4295 p
= lock_user_string(arg2
);
4296 p2
= lock_user_string(arg4
);
4298 ret
= -TARGET_EFAULT
;
4300 ret
= get_errno(sys_linkat(arg1
, p
, arg3
, p2
, arg5
));
4301 unlock_user(p
, arg2
, 0);
4302 unlock_user(p2
, arg4
, 0);
4306 case TARGET_NR_unlink
:
4307 if (!(p
= lock_user_string(arg1
)))
4309 ret
= get_errno(unlink(p
));
4310 unlock_user(p
, arg1
, 0);
4312 #if defined(TARGET_NR_unlinkat) && defined(__NR_unlinkat)
4313 case TARGET_NR_unlinkat
:
4314 if (!(p
= lock_user_string(arg2
)))
4316 ret
= get_errno(sys_unlinkat(arg1
, p
, arg3
));
4317 unlock_user(p
, arg2
, 0);
4320 case TARGET_NR_execve
:
4322 char **argp
, **envp
;
4325 abi_ulong guest_argp
;
4326 abi_ulong guest_envp
;
4332 for (gp
= guest_argp
; gp
; gp
+= sizeof(abi_ulong
)) {
4333 if (get_user_ual(addr
, gp
))
4341 for (gp
= guest_envp
; gp
; gp
+= sizeof(abi_ulong
)) {
4342 if (get_user_ual(addr
, gp
))
4349 argp
= alloca((argc
+ 1) * sizeof(void *));
4350 envp
= alloca((envc
+ 1) * sizeof(void *));
4352 for (gp
= guest_argp
, q
= argp
; gp
;
4353 gp
+= sizeof(abi_ulong
), q
++) {
4354 if (get_user_ual(addr
, gp
))
4358 if (!(*q
= lock_user_string(addr
)))
4363 for (gp
= guest_envp
, q
= envp
; gp
;
4364 gp
+= sizeof(abi_ulong
), q
++) {
4365 if (get_user_ual(addr
, gp
))
4369 if (!(*q
= lock_user_string(addr
)))
4374 if (!(p
= lock_user_string(arg1
)))
4376 ret
= get_errno(execve(p
, argp
, envp
));
4377 unlock_user(p
, arg1
, 0);
4382 ret
= -TARGET_EFAULT
;
4385 for (gp
= guest_argp
, q
= argp
; *q
;
4386 gp
+= sizeof(abi_ulong
), q
++) {
4387 if (get_user_ual(addr
, gp
)
4390 unlock_user(*q
, addr
, 0);
4392 for (gp
= guest_envp
, q
= envp
; *q
;
4393 gp
+= sizeof(abi_ulong
), q
++) {
4394 if (get_user_ual(addr
, gp
)
4397 unlock_user(*q
, addr
, 0);
4401 case TARGET_NR_chdir
:
4402 if (!(p
= lock_user_string(arg1
)))
4404 ret
= get_errno(chdir(p
));
4405 unlock_user(p
, arg1
, 0);
4407 #ifdef TARGET_NR_time
4408 case TARGET_NR_time
:
4411 ret
= get_errno(time(&host_time
));
4414 && put_user_sal(host_time
, arg1
))
4419 case TARGET_NR_mknod
:
4420 if (!(p
= lock_user_string(arg1
)))
4422 ret
= get_errno(mknod(p
, arg2
, arg3
));
4423 unlock_user(p
, arg1
, 0);
4425 #if defined(TARGET_NR_mknodat) && defined(__NR_mknodat)
4426 case TARGET_NR_mknodat
:
4427 if (!(p
= lock_user_string(arg2
)))
4429 ret
= get_errno(sys_mknodat(arg1
, p
, arg3
, arg4
));
4430 unlock_user(p
, arg2
, 0);
4433 case TARGET_NR_chmod
:
4434 if (!(p
= lock_user_string(arg1
)))
4436 ret
= get_errno(chmod(p
, arg2
));
4437 unlock_user(p
, arg1
, 0);
4439 #ifdef TARGET_NR_break
4440 case TARGET_NR_break
:
4443 #ifdef TARGET_NR_oldstat
4444 case TARGET_NR_oldstat
:
4447 case TARGET_NR_lseek
:
4448 ret
= get_errno(lseek(arg1
, arg2
, arg3
));
4450 #ifdef TARGET_NR_getxpid
4451 case TARGET_NR_getxpid
:
4453 case TARGET_NR_getpid
:
4455 ret
= get_errno(getpid());
4457 case TARGET_NR_mount
:
4459 /* need to look at the data field */
4461 p
= lock_user_string(arg1
);
4462 p2
= lock_user_string(arg2
);
4463 p3
= lock_user_string(arg3
);
4464 if (!p
|| !p2
|| !p3
)
4465 ret
= -TARGET_EFAULT
;
4467 /* FIXME - arg5 should be locked, but it isn't clear how to
4468 * do that since it's not guaranteed to be a NULL-terminated
4472 ret
= get_errno(mount(p
, p2
, p3
, (unsigned long)arg4
, NULL
));
4474 ret
= get_errno(mount(p
, p2
, p3
, (unsigned long)arg4
, g2h(arg5
)));
4476 unlock_user(p
, arg1
, 0);
4477 unlock_user(p2
, arg2
, 0);
4478 unlock_user(p3
, arg3
, 0);
4481 #ifdef TARGET_NR_umount
4482 case TARGET_NR_umount
:
4483 if (!(p
= lock_user_string(arg1
)))
4485 ret
= get_errno(umount(p
));
4486 unlock_user(p
, arg1
, 0);
4489 #ifdef TARGET_NR_stime /* not on alpha */
4490 case TARGET_NR_stime
:
4493 if (get_user_sal(host_time
, arg1
))
4495 ret
= get_errno(stime(&host_time
));
4499 case TARGET_NR_ptrace
:
4501 #ifdef TARGET_NR_alarm /* not on alpha */
4502 case TARGET_NR_alarm
:
4506 #ifdef TARGET_NR_oldfstat
4507 case TARGET_NR_oldfstat
:
4510 #ifdef TARGET_NR_pause /* not on alpha */
4511 case TARGET_NR_pause
:
4512 ret
= get_errno(pause());
4515 #ifdef TARGET_NR_utime
4516 case TARGET_NR_utime
:
4518 struct utimbuf tbuf
, *host_tbuf
;
4519 struct target_utimbuf
*target_tbuf
;
4521 if (!lock_user_struct(VERIFY_READ
, target_tbuf
, arg2
, 1))
4523 tbuf
.actime
= tswapl(target_tbuf
->actime
);
4524 tbuf
.modtime
= tswapl(target_tbuf
->modtime
);
4525 unlock_user_struct(target_tbuf
, arg2
, 0);
4530 if (!(p
= lock_user_string(arg1
)))
4532 ret
= get_errno(utime(p
, host_tbuf
));
4533 unlock_user(p
, arg1
, 0);
4537 case TARGET_NR_utimes
:
4539 struct timeval
*tvp
, tv
[2];
4541 if (copy_from_user_timeval(&tv
[0], arg2
)
4542 || copy_from_user_timeval(&tv
[1],
4543 arg2
+ sizeof(struct target_timeval
)))
4549 if (!(p
= lock_user_string(arg1
)))
4551 ret
= get_errno(utimes(p
, tvp
));
4552 unlock_user(p
, arg1
, 0);
4555 #if defined(TARGET_NR_futimesat) && defined(__NR_futimesat)
4556 case TARGET_NR_futimesat
:
4558 struct timeval
*tvp
, tv
[2];
4560 if (copy_from_user_timeval(&tv
[0], arg3
)
4561 || copy_from_user_timeval(&tv
[1],
4562 arg3
+ sizeof(struct target_timeval
)))
4568 if (!(p
= lock_user_string(arg2
)))
4570 ret
= get_errno(sys_futimesat(arg1
, path(p
), tvp
));
4571 unlock_user(p
, arg2
, 0);
4575 #ifdef TARGET_NR_stty
4576 case TARGET_NR_stty
:
4579 #ifdef TARGET_NR_gtty
4580 case TARGET_NR_gtty
:
4583 case TARGET_NR_access
:
4584 if (!(p
= lock_user_string(arg1
)))
4586 ret
= get_errno(access(path(p
), arg2
));
4587 unlock_user(p
, arg1
, 0);
4589 #if defined(TARGET_NR_faccessat) && defined(__NR_faccessat)
4590 case TARGET_NR_faccessat
:
4591 if (!(p
= lock_user_string(arg2
)))
4593 ret
= get_errno(sys_faccessat(arg1
, p
, arg3
));
4594 unlock_user(p
, arg2
, 0);
4597 #ifdef TARGET_NR_nice /* not on alpha */
4598 case TARGET_NR_nice
:
4599 ret
= get_errno(nice(arg1
));
4602 #ifdef TARGET_NR_ftime
4603 case TARGET_NR_ftime
:
4606 case TARGET_NR_sync
:
4610 case TARGET_NR_kill
:
4611 ret
= get_errno(kill(arg1
, target_to_host_signal(arg2
)));
4613 case TARGET_NR_rename
:
4616 p
= lock_user_string(arg1
);
4617 p2
= lock_user_string(arg2
);
4619 ret
= -TARGET_EFAULT
;
4621 ret
= get_errno(rename(p
, p2
));
4622 unlock_user(p2
, arg2
, 0);
4623 unlock_user(p
, arg1
, 0);
4626 #if defined(TARGET_NR_renameat) && defined(__NR_renameat)
4627 case TARGET_NR_renameat
:
4630 p
= lock_user_string(arg2
);
4631 p2
= lock_user_string(arg4
);
4633 ret
= -TARGET_EFAULT
;
4635 ret
= get_errno(sys_renameat(arg1
, p
, arg3
, p2
));
4636 unlock_user(p2
, arg4
, 0);
4637 unlock_user(p
, arg2
, 0);
4641 case TARGET_NR_mkdir
:
4642 if (!(p
= lock_user_string(arg1
)))
4644 ret
= get_errno(mkdir(p
, arg2
));
4645 unlock_user(p
, arg1
, 0);
4647 #if defined(TARGET_NR_mkdirat) && defined(__NR_mkdirat)
4648 case TARGET_NR_mkdirat
:
4649 if (!(p
= lock_user_string(arg2
)))
4651 ret
= get_errno(sys_mkdirat(arg1
, p
, arg3
));
4652 unlock_user(p
, arg2
, 0);
4655 case TARGET_NR_rmdir
:
4656 if (!(p
= lock_user_string(arg1
)))
4658 ret
= get_errno(rmdir(p
));
4659 unlock_user(p
, arg1
, 0);
4662 ret
= get_errno(dup(arg1
));
4664 case TARGET_NR_pipe
:
4665 ret
= do_pipe(cpu_env
, arg1
, 0);
4667 #ifdef TARGET_NR_pipe2
4668 case TARGET_NR_pipe2
:
4669 ret
= do_pipe(cpu_env
, arg1
, arg2
);
4672 case TARGET_NR_times
:
4674 struct target_tms
*tmsp
;
4676 ret
= get_errno(times(&tms
));
4678 tmsp
= lock_user(VERIFY_WRITE
, arg1
, sizeof(struct target_tms
), 0);
4681 tmsp
->tms_utime
= tswapl(host_to_target_clock_t(tms
.tms_utime
));
4682 tmsp
->tms_stime
= tswapl(host_to_target_clock_t(tms
.tms_stime
));
4683 tmsp
->tms_cutime
= tswapl(host_to_target_clock_t(tms
.tms_cutime
));
4684 tmsp
->tms_cstime
= tswapl(host_to_target_clock_t(tms
.tms_cstime
));
4687 ret
= host_to_target_clock_t(ret
);
4690 #ifdef TARGET_NR_prof
4691 case TARGET_NR_prof
:
4694 #ifdef TARGET_NR_signal
4695 case TARGET_NR_signal
:
4698 case TARGET_NR_acct
:
4700 ret
= get_errno(acct(NULL
));
4702 if (!(p
= lock_user_string(arg1
)))
4704 ret
= get_errno(acct(path(p
)));
4705 unlock_user(p
, arg1
, 0);
4708 #ifdef TARGET_NR_umount2 /* not on alpha */
4709 case TARGET_NR_umount2
:
4710 if (!(p
= lock_user_string(arg1
)))
4712 ret
= get_errno(umount2(p
, arg2
));
4713 unlock_user(p
, arg1
, 0);
4716 #ifdef TARGET_NR_lock
4717 case TARGET_NR_lock
:
4720 case TARGET_NR_ioctl
:
4721 ret
= do_ioctl(arg1
, arg2
, arg3
);
4723 case TARGET_NR_fcntl
:
4724 ret
= do_fcntl(arg1
, arg2
, arg3
);
4726 #ifdef TARGET_NR_mpx
4730 case TARGET_NR_setpgid
:
4731 ret
= get_errno(setpgid(arg1
, arg2
));
4733 #ifdef TARGET_NR_ulimit
4734 case TARGET_NR_ulimit
:
4737 #ifdef TARGET_NR_oldolduname
4738 case TARGET_NR_oldolduname
:
4741 case TARGET_NR_umask
:
4742 ret
= get_errno(umask(arg1
));
4744 case TARGET_NR_chroot
:
4745 if (!(p
= lock_user_string(arg1
)))
4747 ret
= get_errno(chroot(p
));
4748 unlock_user(p
, arg1
, 0);
4750 case TARGET_NR_ustat
:
4752 case TARGET_NR_dup2
:
4753 ret
= get_errno(dup2(arg1
, arg2
));
4755 #if defined(CONFIG_DUP3) && defined(TARGET_NR_dup3)
4756 case TARGET_NR_dup3
:
4757 ret
= get_errno(dup3(arg1
, arg2
, arg3
));
4760 #ifdef TARGET_NR_getppid /* not on alpha */
4761 case TARGET_NR_getppid
:
4762 ret
= get_errno(getppid());
4765 case TARGET_NR_getpgrp
:
4766 ret
= get_errno(getpgrp());
4768 case TARGET_NR_setsid
:
4769 ret
= get_errno(setsid());
4771 #ifdef TARGET_NR_sigaction
4772 case TARGET_NR_sigaction
:
4774 #if !defined(TARGET_MIPS)
4775 struct target_old_sigaction
*old_act
;
4776 struct target_sigaction act
, oact
, *pact
;
4778 if (!lock_user_struct(VERIFY_READ
, old_act
, arg2
, 1))
4780 act
._sa_handler
= old_act
->_sa_handler
;
4781 target_siginitset(&act
.sa_mask
, old_act
->sa_mask
);
4782 act
.sa_flags
= old_act
->sa_flags
;
4783 act
.sa_restorer
= old_act
->sa_restorer
;
4784 unlock_user_struct(old_act
, arg2
, 0);
4789 ret
= get_errno(do_sigaction(arg1
, pact
, &oact
));
4790 if (!is_error(ret
) && arg3
) {
4791 if (!lock_user_struct(VERIFY_WRITE
, old_act
, arg3
, 0))
4793 old_act
->_sa_handler
= oact
._sa_handler
;
4794 old_act
->sa_mask
= oact
.sa_mask
.sig
[0];
4795 old_act
->sa_flags
= oact
.sa_flags
;
4796 old_act
->sa_restorer
= oact
.sa_restorer
;
4797 unlock_user_struct(old_act
, arg3
, 1);
4800 struct target_sigaction act
, oact
, *pact
, *old_act
;
4803 if (!lock_user_struct(VERIFY_READ
, old_act
, arg2
, 1))
4805 act
._sa_handler
= old_act
->_sa_handler
;
4806 target_siginitset(&act
.sa_mask
, old_act
->sa_mask
.sig
[0]);
4807 act
.sa_flags
= old_act
->sa_flags
;
4808 unlock_user_struct(old_act
, arg2
, 0);
4814 ret
= get_errno(do_sigaction(arg1
, pact
, &oact
));
4816 if (!is_error(ret
) && arg3
) {
4817 if (!lock_user_struct(VERIFY_WRITE
, old_act
, arg3
, 0))
4819 old_act
->_sa_handler
= oact
._sa_handler
;
4820 old_act
->sa_flags
= oact
.sa_flags
;
4821 old_act
->sa_mask
.sig
[0] = oact
.sa_mask
.sig
[0];
4822 old_act
->sa_mask
.sig
[1] = 0;
4823 old_act
->sa_mask
.sig
[2] = 0;
4824 old_act
->sa_mask
.sig
[3] = 0;
4825 unlock_user_struct(old_act
, arg3
, 1);
4831 case TARGET_NR_rt_sigaction
:
4833 struct target_sigaction
*act
;
4834 struct target_sigaction
*oact
;
4837 if (!lock_user_struct(VERIFY_READ
, act
, arg2
, 1))
4842 if (!lock_user_struct(VERIFY_WRITE
, oact
, arg3
, 0)) {
4843 ret
= -TARGET_EFAULT
;
4844 goto rt_sigaction_fail
;
4848 ret
= get_errno(do_sigaction(arg1
, act
, oact
));
4851 unlock_user_struct(act
, arg2
, 0);
4853 unlock_user_struct(oact
, arg3
, 1);
4856 #ifdef TARGET_NR_sgetmask /* not on alpha */
4857 case TARGET_NR_sgetmask
:
4860 abi_ulong target_set
;
4861 sigprocmask(0, NULL
, &cur_set
);
4862 host_to_target_old_sigset(&target_set
, &cur_set
);
4867 #ifdef TARGET_NR_ssetmask /* not on alpha */
4868 case TARGET_NR_ssetmask
:
4870 sigset_t set
, oset
, cur_set
;
4871 abi_ulong target_set
= arg1
;
4872 sigprocmask(0, NULL
, &cur_set
);
4873 target_to_host_old_sigset(&set
, &target_set
);
4874 sigorset(&set
, &set
, &cur_set
);
4875 sigprocmask(SIG_SETMASK
, &set
, &oset
);
4876 host_to_target_old_sigset(&target_set
, &oset
);
4881 #ifdef TARGET_NR_sigprocmask
4882 case TARGET_NR_sigprocmask
:
4885 sigset_t set
, oldset
, *set_ptr
;
4889 case TARGET_SIG_BLOCK
:
4892 case TARGET_SIG_UNBLOCK
:
4895 case TARGET_SIG_SETMASK
:
4899 ret
= -TARGET_EINVAL
;
4902 if (!(p
= lock_user(VERIFY_READ
, arg2
, sizeof(target_sigset_t
), 1)))
4904 target_to_host_old_sigset(&set
, p
);
4905 unlock_user(p
, arg2
, 0);
4911 ret
= get_errno(sigprocmask(arg1
, set_ptr
, &oldset
));
4912 if (!is_error(ret
) && arg3
) {
4913 if (!(p
= lock_user(VERIFY_WRITE
, arg3
, sizeof(target_sigset_t
), 0)))
4915 host_to_target_old_sigset(p
, &oldset
);
4916 unlock_user(p
, arg3
, sizeof(target_sigset_t
));
4921 case TARGET_NR_rt_sigprocmask
:
4924 sigset_t set
, oldset
, *set_ptr
;
4928 case TARGET_SIG_BLOCK
:
4931 case TARGET_SIG_UNBLOCK
:
4934 case TARGET_SIG_SETMASK
:
4938 ret
= -TARGET_EINVAL
;
4941 if (!(p
= lock_user(VERIFY_READ
, arg2
, sizeof(target_sigset_t
), 1)))
4943 target_to_host_sigset(&set
, p
);
4944 unlock_user(p
, arg2
, 0);
4950 ret
= get_errno(sigprocmask(how
, set_ptr
, &oldset
));
4951 if (!is_error(ret
) && arg3
) {
4952 if (!(p
= lock_user(VERIFY_WRITE
, arg3
, sizeof(target_sigset_t
), 0)))
4954 host_to_target_sigset(p
, &oldset
);
4955 unlock_user(p
, arg3
, sizeof(target_sigset_t
));
4959 #ifdef TARGET_NR_sigpending
4960 case TARGET_NR_sigpending
:
4963 ret
= get_errno(sigpending(&set
));
4964 if (!is_error(ret
)) {
4965 if (!(p
= lock_user(VERIFY_WRITE
, arg1
, sizeof(target_sigset_t
), 0)))
4967 host_to_target_old_sigset(p
, &set
);
4968 unlock_user(p
, arg1
, sizeof(target_sigset_t
));
4973 case TARGET_NR_rt_sigpending
:
4976 ret
= get_errno(sigpending(&set
));
4977 if (!is_error(ret
)) {
4978 if (!(p
= lock_user(VERIFY_WRITE
, arg1
, sizeof(target_sigset_t
), 0)))
4980 host_to_target_sigset(p
, &set
);
4981 unlock_user(p
, arg1
, sizeof(target_sigset_t
));
4985 #ifdef TARGET_NR_sigsuspend
4986 case TARGET_NR_sigsuspend
:
4989 if (!(p
= lock_user(VERIFY_READ
, arg1
, sizeof(target_sigset_t
), 1)))
4991 target_to_host_old_sigset(&set
, p
);
4992 unlock_user(p
, arg1
, 0);
4993 ret
= get_errno(sigsuspend(&set
));
4997 case TARGET_NR_rt_sigsuspend
:
5000 if (!(p
= lock_user(VERIFY_READ
, arg1
, sizeof(target_sigset_t
), 1)))
5002 target_to_host_sigset(&set
, p
);
5003 unlock_user(p
, arg1
, 0);
5004 ret
= get_errno(sigsuspend(&set
));
5007 case TARGET_NR_rt_sigtimedwait
:
5010 struct timespec uts
, *puts
;
5013 if (!(p
= lock_user(VERIFY_READ
, arg1
, sizeof(target_sigset_t
), 1)))
5015 target_to_host_sigset(&set
, p
);
5016 unlock_user(p
, arg1
, 0);
5019 target_to_host_timespec(puts
, arg3
);
5023 ret
= get_errno(sigtimedwait(&set
, &uinfo
, puts
));
5024 if (!is_error(ret
) && arg2
) {
5025 if (!(p
= lock_user(VERIFY_WRITE
, arg2
, sizeof(target_siginfo_t
), 0)))
5027 host_to_target_siginfo(p
, &uinfo
);
5028 unlock_user(p
, arg2
, sizeof(target_siginfo_t
));
5032 case TARGET_NR_rt_sigqueueinfo
:
5035 if (!(p
= lock_user(VERIFY_READ
, arg3
, sizeof(target_sigset_t
), 1)))
5037 target_to_host_siginfo(&uinfo
, p
);
5038 unlock_user(p
, arg1
, 0);
5039 ret
= get_errno(sys_rt_sigqueueinfo(arg1
, arg2
, &uinfo
));
5042 #ifdef TARGET_NR_sigreturn
5043 case TARGET_NR_sigreturn
:
5044 /* NOTE: ret is eax, so not transcoding must be done */
5045 ret
= do_sigreturn(cpu_env
);
5048 case TARGET_NR_rt_sigreturn
:
5049 /* NOTE: ret is eax, so not transcoding must be done */
5050 ret
= do_rt_sigreturn(cpu_env
);
5052 case TARGET_NR_sethostname
:
5053 if (!(p
= lock_user_string(arg1
)))
5055 ret
= get_errno(sethostname(p
, arg2
));
5056 unlock_user(p
, arg1
, 0);
5058 case TARGET_NR_setrlimit
:
5060 /* XXX: convert resource ? */
5061 int resource
= arg1
;
5062 struct target_rlimit
*target_rlim
;
5064 if (!lock_user_struct(VERIFY_READ
, target_rlim
, arg2
, 1))
5066 rlim
.rlim_cur
= tswapl(target_rlim
->rlim_cur
);
5067 rlim
.rlim_max
= tswapl(target_rlim
->rlim_max
);
5068 unlock_user_struct(target_rlim
, arg2
, 0);
5069 ret
= get_errno(setrlimit(resource
, &rlim
));
5072 case TARGET_NR_getrlimit
:
5074 /* XXX: convert resource ? */
5075 int resource
= arg1
;
5076 struct target_rlimit
*target_rlim
;
5079 ret
= get_errno(getrlimit(resource
, &rlim
));
5080 if (!is_error(ret
)) {
5081 if (!lock_user_struct(VERIFY_WRITE
, target_rlim
, arg2
, 0))
5083 target_rlim
->rlim_cur
= tswapl(rlim
.rlim_cur
);
5084 target_rlim
->rlim_max
= tswapl(rlim
.rlim_max
);
5085 unlock_user_struct(target_rlim
, arg2
, 1);
5089 case TARGET_NR_getrusage
:
5091 struct rusage rusage
;
5092 ret
= get_errno(getrusage(arg1
, &rusage
));
5093 if (!is_error(ret
)) {
5094 host_to_target_rusage(arg2
, &rusage
);
5098 case TARGET_NR_gettimeofday
:
5101 ret
= get_errno(gettimeofday(&tv
, NULL
));
5102 if (!is_error(ret
)) {
5103 if (copy_to_user_timeval(arg1
, &tv
))
5108 case TARGET_NR_settimeofday
:
5111 if (copy_from_user_timeval(&tv
, arg1
))
5113 ret
= get_errno(settimeofday(&tv
, NULL
));
5116 #ifdef TARGET_NR_select
5117 case TARGET_NR_select
:
5119 struct target_sel_arg_struct
*sel
;
5120 abi_ulong inp
, outp
, exp
, tvp
;
5123 if (!lock_user_struct(VERIFY_READ
, sel
, arg1
, 1))
5125 nsel
= tswapl(sel
->n
);
5126 inp
= tswapl(sel
->inp
);
5127 outp
= tswapl(sel
->outp
);
5128 exp
= tswapl(sel
->exp
);
5129 tvp
= tswapl(sel
->tvp
);
5130 unlock_user_struct(sel
, arg1
, 0);
5131 ret
= do_select(nsel
, inp
, outp
, exp
, tvp
);
5135 case TARGET_NR_symlink
:
5138 p
= lock_user_string(arg1
);
5139 p2
= lock_user_string(arg2
);
5141 ret
= -TARGET_EFAULT
;
5143 ret
= get_errno(symlink(p
, p2
));
5144 unlock_user(p2
, arg2
, 0);
5145 unlock_user(p
, arg1
, 0);
5148 #if defined(TARGET_NR_symlinkat) && defined(__NR_symlinkat)
5149 case TARGET_NR_symlinkat
:
5152 p
= lock_user_string(arg1
);
5153 p2
= lock_user_string(arg3
);
5155 ret
= -TARGET_EFAULT
;
5157 ret
= get_errno(sys_symlinkat(p
, arg2
, p2
));
5158 unlock_user(p2
, arg3
, 0);
5159 unlock_user(p
, arg1
, 0);
5163 #ifdef TARGET_NR_oldlstat
5164 case TARGET_NR_oldlstat
:
5167 case TARGET_NR_readlink
:
5170 p
= lock_user_string(arg1
);
5171 p2
= lock_user(VERIFY_WRITE
, arg2
, arg3
, 0);
5173 ret
= -TARGET_EFAULT
;
5175 if (strncmp((const char *)p
, "/proc/self/exe", 14) == 0) {
5176 char real
[PATH_MAX
];
5177 temp
= realpath(exec_path
,real
);
5178 ret
= (temp
==NULL
) ? get_errno(-1) : strlen(real
) ;
5179 snprintf((char *)p2
, arg3
, "%s", real
);
5182 ret
= get_errno(readlink(path(p
), p2
, arg3
));
5184 unlock_user(p2
, arg2
, ret
);
5185 unlock_user(p
, arg1
, 0);
5188 #if defined(TARGET_NR_readlinkat) && defined(__NR_readlinkat)
5189 case TARGET_NR_readlinkat
:
5192 p
= lock_user_string(arg2
);
5193 p2
= lock_user(VERIFY_WRITE
, arg3
, arg4
, 0);
5195 ret
= -TARGET_EFAULT
;
5197 ret
= get_errno(sys_readlinkat(arg1
, path(p
), p2
, arg4
));
5198 unlock_user(p2
, arg3
, ret
);
5199 unlock_user(p
, arg2
, 0);
5203 #ifdef TARGET_NR_uselib
5204 case TARGET_NR_uselib
:
5207 #ifdef TARGET_NR_swapon
5208 case TARGET_NR_swapon
:
5209 if (!(p
= lock_user_string(arg1
)))
5211 ret
= get_errno(swapon(p
, arg2
));
5212 unlock_user(p
, arg1
, 0);
5215 case TARGET_NR_reboot
:
5217 #ifdef TARGET_NR_readdir
5218 case TARGET_NR_readdir
:
5221 #ifdef TARGET_NR_mmap
5222 case TARGET_NR_mmap
:
5223 #if (defined(TARGET_I386) && defined(TARGET_ABI32)) || defined(TARGET_ARM) || defined(TARGET_M68K) || defined(TARGET_CRIS) || defined(TARGET_MICROBLAZE)
5226 abi_ulong v1
, v2
, v3
, v4
, v5
, v6
;
5227 if (!(v
= lock_user(VERIFY_READ
, arg1
, 6 * sizeof(abi_ulong
), 1)))
5235 unlock_user(v
, arg1
, 0);
5236 ret
= get_errno(target_mmap(v1
, v2
, v3
,
5237 target_to_host_bitmask(v4
, mmap_flags_tbl
),
5241 ret
= get_errno(target_mmap(arg1
, arg2
, arg3
,
5242 target_to_host_bitmask(arg4
, mmap_flags_tbl
),
5248 #ifdef TARGET_NR_mmap2
5249 case TARGET_NR_mmap2
:
5251 #define MMAP_SHIFT 12
5253 ret
= get_errno(target_mmap(arg1
, arg2
, arg3
,
5254 target_to_host_bitmask(arg4
, mmap_flags_tbl
),
5256 arg6
<< MMAP_SHIFT
));
5259 case TARGET_NR_munmap
:
5260 ret
= get_errno(target_munmap(arg1
, arg2
));
5262 case TARGET_NR_mprotect
:
5263 ret
= get_errno(target_mprotect(arg1
, arg2
, arg3
));
5265 #ifdef TARGET_NR_mremap
5266 case TARGET_NR_mremap
:
5267 ret
= get_errno(target_mremap(arg1
, arg2
, arg3
, arg4
, arg5
));
5270 /* ??? msync/mlock/munlock are broken for softmmu. */
5271 #ifdef TARGET_NR_msync
5272 case TARGET_NR_msync
:
5273 ret
= get_errno(msync(g2h(arg1
), arg2
, arg3
));
5276 #ifdef TARGET_NR_mlock
5277 case TARGET_NR_mlock
:
5278 ret
= get_errno(mlock(g2h(arg1
), arg2
));
5281 #ifdef TARGET_NR_munlock
5282 case TARGET_NR_munlock
:
5283 ret
= get_errno(munlock(g2h(arg1
), arg2
));
5286 #ifdef TARGET_NR_mlockall
5287 case TARGET_NR_mlockall
:
5288 ret
= get_errno(mlockall(arg1
));
5291 #ifdef TARGET_NR_munlockall
5292 case TARGET_NR_munlockall
:
5293 ret
= get_errno(munlockall());
5296 case TARGET_NR_truncate
:
5297 if (!(p
= lock_user_string(arg1
)))
5299 ret
= get_errno(truncate(p
, arg2
));
5300 unlock_user(p
, arg1
, 0);
5302 case TARGET_NR_ftruncate
:
5303 ret
= get_errno(ftruncate(arg1
, arg2
));
5305 case TARGET_NR_fchmod
:
5306 ret
= get_errno(fchmod(arg1
, arg2
));
5308 #if defined(TARGET_NR_fchmodat) && defined(__NR_fchmodat)
5309 case TARGET_NR_fchmodat
:
5310 if (!(p
= lock_user_string(arg2
)))
5312 ret
= get_errno(sys_fchmodat(arg1
, p
, arg3
));
5313 unlock_user(p
, arg2
, 0);
5316 case TARGET_NR_getpriority
:
5317 /* libc does special remapping of the return value of
5318 * sys_getpriority() so it's just easiest to call
5319 * sys_getpriority() directly rather than through libc. */
5320 ret
= get_errno(sys_getpriority(arg1
, arg2
));
5322 case TARGET_NR_setpriority
:
5323 ret
= get_errno(setpriority(arg1
, arg2
, arg3
));
5325 #ifdef TARGET_NR_profil
5326 case TARGET_NR_profil
:
5329 case TARGET_NR_statfs
:
5330 if (!(p
= lock_user_string(arg1
)))
5332 ret
= get_errno(statfs(path(p
), &stfs
));
5333 unlock_user(p
, arg1
, 0);
5335 if (!is_error(ret
)) {
5336 struct target_statfs
*target_stfs
;
5338 if (!lock_user_struct(VERIFY_WRITE
, target_stfs
, arg2
, 0))
5340 __put_user(stfs
.f_type
, &target_stfs
->f_type
);
5341 __put_user(stfs
.f_bsize
, &target_stfs
->f_bsize
);
5342 __put_user(stfs
.f_blocks
, &target_stfs
->f_blocks
);
5343 __put_user(stfs
.f_bfree
, &target_stfs
->f_bfree
);
5344 __put_user(stfs
.f_bavail
, &target_stfs
->f_bavail
);
5345 __put_user(stfs
.f_files
, &target_stfs
->f_files
);
5346 __put_user(stfs
.f_ffree
, &target_stfs
->f_ffree
);
5347 __put_user(stfs
.f_fsid
.__val
[0], &target_stfs
->f_fsid
.val
[0]);
5348 __put_user(stfs
.f_fsid
.__val
[1], &target_stfs
->f_fsid
.val
[1]);
5349 __put_user(stfs
.f_namelen
, &target_stfs
->f_namelen
);
5350 unlock_user_struct(target_stfs
, arg2
, 1);
5353 case TARGET_NR_fstatfs
:
5354 ret
= get_errno(fstatfs(arg1
, &stfs
));
5355 goto convert_statfs
;
5356 #ifdef TARGET_NR_statfs64
5357 case TARGET_NR_statfs64
:
5358 if (!(p
= lock_user_string(arg1
)))
5360 ret
= get_errno(statfs(path(p
), &stfs
));
5361 unlock_user(p
, arg1
, 0);
5363 if (!is_error(ret
)) {
5364 struct target_statfs64
*target_stfs
;
5366 if (!lock_user_struct(VERIFY_WRITE
, target_stfs
, arg3
, 0))
5368 __put_user(stfs
.f_type
, &target_stfs
->f_type
);
5369 __put_user(stfs
.f_bsize
, &target_stfs
->f_bsize
);
5370 __put_user(stfs
.f_blocks
, &target_stfs
->f_blocks
);
5371 __put_user(stfs
.f_bfree
, &target_stfs
->f_bfree
);
5372 __put_user(stfs
.f_bavail
, &target_stfs
->f_bavail
);
5373 __put_user(stfs
.f_files
, &target_stfs
->f_files
);
5374 __put_user(stfs
.f_ffree
, &target_stfs
->f_ffree
);
5375 __put_user(stfs
.f_fsid
.__val
[0], &target_stfs
->f_fsid
.val
[0]);
5376 __put_user(stfs
.f_fsid
.__val
[1], &target_stfs
->f_fsid
.val
[1]);
5377 __put_user(stfs
.f_namelen
, &target_stfs
->f_namelen
);
5378 unlock_user_struct(target_stfs
, arg3
, 1);
5381 case TARGET_NR_fstatfs64
:
5382 ret
= get_errno(fstatfs(arg1
, &stfs
));
5383 goto convert_statfs64
;
5385 #ifdef TARGET_NR_ioperm
5386 case TARGET_NR_ioperm
:
5389 #ifdef TARGET_NR_socketcall
5390 case TARGET_NR_socketcall
:
5391 ret
= do_socketcall(arg1
, arg2
);
5394 #ifdef TARGET_NR_accept
5395 case TARGET_NR_accept
:
5396 ret
= do_accept(arg1
, arg2
, arg3
);
5399 #ifdef TARGET_NR_bind
5400 case TARGET_NR_bind
:
5401 ret
= do_bind(arg1
, arg2
, arg3
);
5404 #ifdef TARGET_NR_connect
5405 case TARGET_NR_connect
:
5406 ret
= do_connect(arg1
, arg2
, arg3
);
5409 #ifdef TARGET_NR_getpeername
5410 case TARGET_NR_getpeername
:
5411 ret
= do_getpeername(arg1
, arg2
, arg3
);
5414 #ifdef TARGET_NR_getsockname
5415 case TARGET_NR_getsockname
:
5416 ret
= do_getsockname(arg1
, arg2
, arg3
);
5419 #ifdef TARGET_NR_getsockopt
5420 case TARGET_NR_getsockopt
:
5421 ret
= do_getsockopt(arg1
, arg2
, arg3
, arg4
, arg5
);
5424 #ifdef TARGET_NR_listen
5425 case TARGET_NR_listen
:
5426 ret
= get_errno(listen(arg1
, arg2
));
5429 #ifdef TARGET_NR_recv
5430 case TARGET_NR_recv
:
5431 ret
= do_recvfrom(arg1
, arg2
, arg3
, arg4
, 0, 0);
5434 #ifdef TARGET_NR_recvfrom
5435 case TARGET_NR_recvfrom
:
5436 ret
= do_recvfrom(arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
5439 #ifdef TARGET_NR_recvmsg
5440 case TARGET_NR_recvmsg
:
5441 ret
= do_sendrecvmsg(arg1
, arg2
, arg3
, 0);
5444 #ifdef TARGET_NR_send
5445 case TARGET_NR_send
:
5446 ret
= do_sendto(arg1
, arg2
, arg3
, arg4
, 0, 0);
5449 #ifdef TARGET_NR_sendmsg
5450 case TARGET_NR_sendmsg
:
5451 ret
= do_sendrecvmsg(arg1
, arg2
, arg3
, 1);
5454 #ifdef TARGET_NR_sendto
5455 case TARGET_NR_sendto
:
5456 ret
= do_sendto(arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
5459 #ifdef TARGET_NR_shutdown
5460 case TARGET_NR_shutdown
:
5461 ret
= get_errno(shutdown(arg1
, arg2
));
5464 #ifdef TARGET_NR_socket
5465 case TARGET_NR_socket
:
5466 ret
= do_socket(arg1
, arg2
, arg3
);
5469 #ifdef TARGET_NR_socketpair
5470 case TARGET_NR_socketpair
:
5471 ret
= do_socketpair(arg1
, arg2
, arg3
, arg4
);
5474 #ifdef TARGET_NR_setsockopt
5475 case TARGET_NR_setsockopt
:
5476 ret
= do_setsockopt(arg1
, arg2
, arg3
, arg4
, (socklen_t
) arg5
);
5480 case TARGET_NR_syslog
:
5481 if (!(p
= lock_user_string(arg2
)))
5483 ret
= get_errno(sys_syslog((int)arg1
, p
, (int)arg3
));
5484 unlock_user(p
, arg2
, 0);
5487 case TARGET_NR_setitimer
:
5489 struct itimerval value
, ovalue
, *pvalue
;
5493 if (copy_from_user_timeval(&pvalue
->it_interval
, arg2
)
5494 || copy_from_user_timeval(&pvalue
->it_value
,
5495 arg2
+ sizeof(struct target_timeval
)))
5500 ret
= get_errno(setitimer(arg1
, pvalue
, &ovalue
));
5501 if (!is_error(ret
) && arg3
) {
5502 if (copy_to_user_timeval(arg3
,
5503 &ovalue
.it_interval
)
5504 || copy_to_user_timeval(arg3
+ sizeof(struct target_timeval
),
5510 case TARGET_NR_getitimer
:
5512 struct itimerval value
;
5514 ret
= get_errno(getitimer(arg1
, &value
));
5515 if (!is_error(ret
) && arg2
) {
5516 if (copy_to_user_timeval(arg2
,
5518 || copy_to_user_timeval(arg2
+ sizeof(struct target_timeval
),
5524 case TARGET_NR_stat
:
5525 if (!(p
= lock_user_string(arg1
)))
5527 ret
= get_errno(stat(path(p
), &st
));
5528 unlock_user(p
, arg1
, 0);
5530 case TARGET_NR_lstat
:
5531 if (!(p
= lock_user_string(arg1
)))
5533 ret
= get_errno(lstat(path(p
), &st
));
5534 unlock_user(p
, arg1
, 0);
5536 case TARGET_NR_fstat
:
5538 ret
= get_errno(fstat(arg1
, &st
));
5540 if (!is_error(ret
)) {
5541 struct target_stat
*target_st
;
5543 if (!lock_user_struct(VERIFY_WRITE
, target_st
, arg2
, 0))
5545 memset(target_st
, 0, sizeof(*target_st
));
5546 __put_user(st
.st_dev
, &target_st
->st_dev
);
5547 __put_user(st
.st_ino
, &target_st
->st_ino
);
5548 __put_user(st
.st_mode
, &target_st
->st_mode
);
5549 __put_user(st
.st_uid
, &target_st
->st_uid
);
5550 __put_user(st
.st_gid
, &target_st
->st_gid
);
5551 __put_user(st
.st_nlink
, &target_st
->st_nlink
);
5552 __put_user(st
.st_rdev
, &target_st
->st_rdev
);
5553 __put_user(st
.st_size
, &target_st
->st_size
);
5554 __put_user(st
.st_blksize
, &target_st
->st_blksize
);
5555 __put_user(st
.st_blocks
, &target_st
->st_blocks
);
5556 __put_user(st
.st_atime
, &target_st
->target_st_atime
);
5557 __put_user(st
.st_mtime
, &target_st
->target_st_mtime
);
5558 __put_user(st
.st_ctime
, &target_st
->target_st_ctime
);
5559 unlock_user_struct(target_st
, arg2
, 1);
5563 #ifdef TARGET_NR_olduname
5564 case TARGET_NR_olduname
:
5567 #ifdef TARGET_NR_iopl
5568 case TARGET_NR_iopl
:
5571 case TARGET_NR_vhangup
:
5572 ret
= get_errno(vhangup());
5574 #ifdef TARGET_NR_idle
5575 case TARGET_NR_idle
:
5578 #ifdef TARGET_NR_syscall
5579 case TARGET_NR_syscall
:
5580 ret
= do_syscall(cpu_env
,arg1
& 0xffff,arg2
,arg3
,arg4
,arg5
,arg6
,0);
5583 case TARGET_NR_wait4
:
5586 abi_long status_ptr
= arg2
;
5587 struct rusage rusage
, *rusage_ptr
;
5588 abi_ulong target_rusage
= arg4
;
5590 rusage_ptr
= &rusage
;
5593 ret
= get_errno(wait4(arg1
, &status
, arg3
, rusage_ptr
));
5594 if (!is_error(ret
)) {
5596 status
= host_to_target_waitstatus(status
);
5597 if (put_user_s32(status
, status_ptr
))
5601 host_to_target_rusage(target_rusage
, &rusage
);
5605 #ifdef TARGET_NR_swapoff
5606 case TARGET_NR_swapoff
:
5607 if (!(p
= lock_user_string(arg1
)))
5609 ret
= get_errno(swapoff(p
));
5610 unlock_user(p
, arg1
, 0);
5613 case TARGET_NR_sysinfo
:
5615 struct target_sysinfo
*target_value
;
5616 struct sysinfo value
;
5617 ret
= get_errno(sysinfo(&value
));
5618 if (!is_error(ret
) && arg1
)
5620 if (!lock_user_struct(VERIFY_WRITE
, target_value
, arg1
, 0))
5622 __put_user(value
.uptime
, &target_value
->uptime
);
5623 __put_user(value
.loads
[0], &target_value
->loads
[0]);
5624 __put_user(value
.loads
[1], &target_value
->loads
[1]);
5625 __put_user(value
.loads
[2], &target_value
->loads
[2]);
5626 __put_user(value
.totalram
, &target_value
->totalram
);
5627 __put_user(value
.freeram
, &target_value
->freeram
);
5628 __put_user(value
.sharedram
, &target_value
->sharedram
);
5629 __put_user(value
.bufferram
, &target_value
->bufferram
);
5630 __put_user(value
.totalswap
, &target_value
->totalswap
);
5631 __put_user(value
.freeswap
, &target_value
->freeswap
);
5632 __put_user(value
.procs
, &target_value
->procs
);
5633 __put_user(value
.totalhigh
, &target_value
->totalhigh
);
5634 __put_user(value
.freehigh
, &target_value
->freehigh
);
5635 __put_user(value
.mem_unit
, &target_value
->mem_unit
);
5636 unlock_user_struct(target_value
, arg1
, 1);
5640 #ifdef TARGET_NR_ipc
5642 ret
= do_ipc(arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
5645 #ifdef TARGET_NR_semget
5646 case TARGET_NR_semget
:
5647 ret
= get_errno(semget(arg1
, arg2
, arg3
));
5650 #ifdef TARGET_NR_semop
5651 case TARGET_NR_semop
:
5652 ret
= get_errno(do_semop(arg1
, arg2
, arg3
));
5655 #ifdef TARGET_NR_semctl
5656 case TARGET_NR_semctl
:
5657 ret
= do_semctl(arg1
, arg2
, arg3
, (union target_semun
)(abi_ulong
)arg4
);
5660 #ifdef TARGET_NR_msgctl
5661 case TARGET_NR_msgctl
:
5662 ret
= do_msgctl(arg1
, arg2
, arg3
);
5665 #ifdef TARGET_NR_msgget
5666 case TARGET_NR_msgget
:
5667 ret
= get_errno(msgget(arg1
, arg2
));
5670 #ifdef TARGET_NR_msgrcv
5671 case TARGET_NR_msgrcv
:
5672 ret
= do_msgrcv(arg1
, arg2
, arg3
, arg4
, arg5
);
5675 #ifdef TARGET_NR_msgsnd
5676 case TARGET_NR_msgsnd
:
5677 ret
= do_msgsnd(arg1
, arg2
, arg3
, arg4
);
5680 #ifdef TARGET_NR_shmget
5681 case TARGET_NR_shmget
:
5682 ret
= get_errno(shmget(arg1
, arg2
, arg3
));
5685 #ifdef TARGET_NR_shmctl
5686 case TARGET_NR_shmctl
:
5687 ret
= do_shmctl(arg1
, arg2
, arg3
);
5690 #ifdef TARGET_NR_shmat
5691 case TARGET_NR_shmat
:
5692 ret
= do_shmat(arg1
, arg2
, arg3
);
5695 #ifdef TARGET_NR_shmdt
5696 case TARGET_NR_shmdt
:
5697 ret
= do_shmdt(arg1
);
5700 case TARGET_NR_fsync
:
5701 ret
= get_errno(fsync(arg1
));
5703 case TARGET_NR_clone
:
5704 #if defined(TARGET_SH4)
5705 ret
= get_errno(do_fork(cpu_env
, arg1
, arg2
, arg3
, arg5
, arg4
));
5706 #elif defined(TARGET_CRIS)
5707 ret
= get_errno(do_fork(cpu_env
, arg2
, arg1
, arg3
, arg4
, arg5
));
5709 ret
= get_errno(do_fork(cpu_env
, arg1
, arg2
, arg3
, arg4
, arg5
));
5712 #ifdef __NR_exit_group
5713 /* new thread calls */
5714 case TARGET_NR_exit_group
:
5718 gdb_exit(cpu_env
, arg1
);
5719 ret
= get_errno(exit_group(arg1
));
5722 case TARGET_NR_setdomainname
:
5723 if (!(p
= lock_user_string(arg1
)))
5725 ret
= get_errno(setdomainname(p
, arg2
));
5726 unlock_user(p
, arg1
, 0);
5728 case TARGET_NR_uname
:
5729 /* no need to transcode because we use the linux syscall */
5731 struct new_utsname
* buf
;
5733 if (!lock_user_struct(VERIFY_WRITE
, buf
, arg1
, 0))
5735 ret
= get_errno(sys_uname(buf
));
5736 if (!is_error(ret
)) {
5737 /* Overrite the native machine name with whatever is being
5739 strcpy (buf
->machine
, UNAME_MACHINE
);
5740 /* Allow the user to override the reported release. */
5741 if (qemu_uname_release
&& *qemu_uname_release
)
5742 strcpy (buf
->release
, qemu_uname_release
);
5744 unlock_user_struct(buf
, arg1
, 1);
5748 case TARGET_NR_modify_ldt
:
5749 ret
= do_modify_ldt(cpu_env
, arg1
, arg2
, arg3
);
5751 #if !defined(TARGET_X86_64)
5752 case TARGET_NR_vm86old
:
5754 case TARGET_NR_vm86
:
5755 ret
= do_vm86(cpu_env
, arg1
, arg2
);
5759 case TARGET_NR_adjtimex
:
5761 #ifdef TARGET_NR_create_module
5762 case TARGET_NR_create_module
:
5764 case TARGET_NR_init_module
:
5765 case TARGET_NR_delete_module
:
5766 #ifdef TARGET_NR_get_kernel_syms
5767 case TARGET_NR_get_kernel_syms
:
5770 case TARGET_NR_quotactl
:
5772 case TARGET_NR_getpgid
:
5773 ret
= get_errno(getpgid(arg1
));
5775 case TARGET_NR_fchdir
:
5776 ret
= get_errno(fchdir(arg1
));
5778 #ifdef TARGET_NR_bdflush /* not on x86_64 */
5779 case TARGET_NR_bdflush
:
5782 #ifdef TARGET_NR_sysfs
5783 case TARGET_NR_sysfs
:
5786 case TARGET_NR_personality
:
5787 ret
= get_errno(personality(arg1
));
5789 #ifdef TARGET_NR_afs_syscall
5790 case TARGET_NR_afs_syscall
:
5793 #ifdef TARGET_NR__llseek /* Not on alpha */
5794 case TARGET_NR__llseek
:
5796 #if defined (__x86_64__)
5797 ret
= get_errno(lseek(arg1
, ((uint64_t )arg2
<< 32) | arg3
, arg5
));
5798 if (put_user_s64(ret
, arg4
))
5802 ret
= get_errno(_llseek(arg1
, arg2
, arg3
, &res
, arg5
));
5803 if (put_user_s64(res
, arg4
))
5809 case TARGET_NR_getdents
:
5810 #if TARGET_ABI_BITS == 32 && HOST_LONG_BITS == 64
5812 struct target_dirent
*target_dirp
;
5813 struct linux_dirent
*dirp
;
5814 abi_long count
= arg3
;
5816 dirp
= malloc(count
);
5818 ret
= -TARGET_ENOMEM
;
5822 ret
= get_errno(sys_getdents(arg1
, dirp
, count
));
5823 if (!is_error(ret
)) {
5824 struct linux_dirent
*de
;
5825 struct target_dirent
*tde
;
5827 int reclen
, treclen
;
5828 int count1
, tnamelen
;
5832 if (!(target_dirp
= lock_user(VERIFY_WRITE
, arg2
, count
, 0)))
5836 reclen
= de
->d_reclen
;
5837 treclen
= reclen
- (2 * (sizeof(long) - sizeof(abi_long
)));
5838 tde
->d_reclen
= tswap16(treclen
);
5839 tde
->d_ino
= tswapl(de
->d_ino
);
5840 tde
->d_off
= tswapl(de
->d_off
);
5841 tnamelen
= treclen
- (2 * sizeof(abi_long
) + 2);
5844 /* XXX: may not be correct */
5845 pstrcpy(tde
->d_name
, tnamelen
, de
->d_name
);
5846 de
= (struct linux_dirent
*)((char *)de
+ reclen
);
5848 tde
= (struct target_dirent
*)((char *)tde
+ treclen
);
5852 unlock_user(target_dirp
, arg2
, ret
);
5858 struct linux_dirent
*dirp
;
5859 abi_long count
= arg3
;
5861 if (!(dirp
= lock_user(VERIFY_WRITE
, arg2
, count
, 0)))
5863 ret
= get_errno(sys_getdents(arg1
, dirp
, count
));
5864 if (!is_error(ret
)) {
5865 struct linux_dirent
*de
;
5870 reclen
= de
->d_reclen
;
5873 de
->d_reclen
= tswap16(reclen
);
5874 tswapls(&de
->d_ino
);
5875 tswapls(&de
->d_off
);
5876 de
= (struct linux_dirent
*)((char *)de
+ reclen
);
5880 unlock_user(dirp
, arg2
, ret
);
5884 #if defined(TARGET_NR_getdents64) && defined(__NR_getdents64)
5885 case TARGET_NR_getdents64
:
5887 struct linux_dirent64
*dirp
;
5888 abi_long count
= arg3
;
5889 if (!(dirp
= lock_user(VERIFY_WRITE
, arg2
, count
, 0)))
5891 ret
= get_errno(sys_getdents64(arg1
, dirp
, count
));
5892 if (!is_error(ret
)) {
5893 struct linux_dirent64
*de
;
5898 reclen
= de
->d_reclen
;
5901 de
->d_reclen
= tswap16(reclen
);
5902 tswap64s((uint64_t *)&de
->d_ino
);
5903 tswap64s((uint64_t *)&de
->d_off
);
5904 de
= (struct linux_dirent64
*)((char *)de
+ reclen
);
5908 unlock_user(dirp
, arg2
, ret
);
5911 #endif /* TARGET_NR_getdents64 */
5912 #ifdef TARGET_NR__newselect
5913 case TARGET_NR__newselect
:
5914 ret
= do_select(arg1
, arg2
, arg3
, arg4
, arg5
);
5917 #ifdef TARGET_NR_poll
5918 case TARGET_NR_poll
:
5920 struct target_pollfd
*target_pfd
;
5921 unsigned int nfds
= arg2
;
5926 target_pfd
= lock_user(VERIFY_WRITE
, arg1
, sizeof(struct target_pollfd
) * nfds
, 1);
5929 pfd
= alloca(sizeof(struct pollfd
) * nfds
);
5930 for(i
= 0; i
< nfds
; i
++) {
5931 pfd
[i
].fd
= tswap32(target_pfd
[i
].fd
);
5932 pfd
[i
].events
= tswap16(target_pfd
[i
].events
);
5934 ret
= get_errno(poll(pfd
, nfds
, timeout
));
5935 if (!is_error(ret
)) {
5936 for(i
= 0; i
< nfds
; i
++) {
5937 target_pfd
[i
].revents
= tswap16(pfd
[i
].revents
);
5939 ret
+= nfds
* (sizeof(struct target_pollfd
)
5940 - sizeof(struct pollfd
));
5942 unlock_user(target_pfd
, arg1
, ret
);
5946 case TARGET_NR_flock
:
5947 /* NOTE: the flock constant seems to be the same for every
5949 ret
= get_errno(flock(arg1
, arg2
));
5951 case TARGET_NR_readv
:
5956 vec
= alloca(count
* sizeof(struct iovec
));
5957 if (lock_iovec(VERIFY_WRITE
, vec
, arg2
, count
, 0) < 0)
5959 ret
= get_errno(readv(arg1
, vec
, count
));
5960 unlock_iovec(vec
, arg2
, count
, 1);
5963 case TARGET_NR_writev
:
5968 vec
= alloca(count
* sizeof(struct iovec
));
5969 if (lock_iovec(VERIFY_READ
, vec
, arg2
, count
, 1) < 0)
5971 ret
= get_errno(writev(arg1
, vec
, count
));
5972 unlock_iovec(vec
, arg2
, count
, 0);
5975 case TARGET_NR_getsid
:
5976 ret
= get_errno(getsid(arg1
));
5978 #if defined(TARGET_NR_fdatasync) /* Not on alpha (osf_datasync ?) */
5979 case TARGET_NR_fdatasync
:
5980 ret
= get_errno(fdatasync(arg1
));
5983 case TARGET_NR__sysctl
:
5984 /* We don't implement this, but ENOTDIR is always a safe
5986 ret
= -TARGET_ENOTDIR
;
5988 case TARGET_NR_sched_setparam
:
5990 struct sched_param
*target_schp
;
5991 struct sched_param schp
;
5993 if (!lock_user_struct(VERIFY_READ
, target_schp
, arg2
, 1))
5995 schp
.sched_priority
= tswap32(target_schp
->sched_priority
);
5996 unlock_user_struct(target_schp
, arg2
, 0);
5997 ret
= get_errno(sched_setparam(arg1
, &schp
));
6000 case TARGET_NR_sched_getparam
:
6002 struct sched_param
*target_schp
;
6003 struct sched_param schp
;
6004 ret
= get_errno(sched_getparam(arg1
, &schp
));
6005 if (!is_error(ret
)) {
6006 if (!lock_user_struct(VERIFY_WRITE
, target_schp
, arg2
, 0))
6008 target_schp
->sched_priority
= tswap32(schp
.sched_priority
);
6009 unlock_user_struct(target_schp
, arg2
, 1);
6013 case TARGET_NR_sched_setscheduler
:
6015 struct sched_param
*target_schp
;
6016 struct sched_param schp
;
6017 if (!lock_user_struct(VERIFY_READ
, target_schp
, arg3
, 1))
6019 schp
.sched_priority
= tswap32(target_schp
->sched_priority
);
6020 unlock_user_struct(target_schp
, arg3
, 0);
6021 ret
= get_errno(sched_setscheduler(arg1
, arg2
, &schp
));
6024 case TARGET_NR_sched_getscheduler
:
6025 ret
= get_errno(sched_getscheduler(arg1
));
6027 case TARGET_NR_sched_yield
:
6028 ret
= get_errno(sched_yield());
6030 case TARGET_NR_sched_get_priority_max
:
6031 ret
= get_errno(sched_get_priority_max(arg1
));
6033 case TARGET_NR_sched_get_priority_min
:
6034 ret
= get_errno(sched_get_priority_min(arg1
));
6036 case TARGET_NR_sched_rr_get_interval
:
6039 ret
= get_errno(sched_rr_get_interval(arg1
, &ts
));
6040 if (!is_error(ret
)) {
6041 host_to_target_timespec(arg2
, &ts
);
6045 case TARGET_NR_nanosleep
:
6047 struct timespec req
, rem
;
6048 target_to_host_timespec(&req
, arg1
);
6049 ret
= get_errno(nanosleep(&req
, &rem
));
6050 if (is_error(ret
) && arg2
) {
6051 host_to_target_timespec(arg2
, &rem
);
6055 #ifdef TARGET_NR_query_module
6056 case TARGET_NR_query_module
:
6059 #ifdef TARGET_NR_nfsservctl
6060 case TARGET_NR_nfsservctl
:
6063 case TARGET_NR_prctl
:
6066 case PR_GET_PDEATHSIG
:
6069 ret
= get_errno(prctl(arg1
, &deathsig
, arg3
, arg4
, arg5
));
6070 if (!is_error(ret
) && arg2
6071 && put_user_ual(deathsig
, arg2
))
6076 ret
= get_errno(prctl(arg1
, arg2
, arg3
, arg4
, arg5
));
6080 #ifdef TARGET_NR_arch_prctl
6081 case TARGET_NR_arch_prctl
:
6082 #if defined(TARGET_I386) && !defined(TARGET_ABI32)
6083 ret
= do_arch_prctl(cpu_env
, arg1
, arg2
);
6089 #ifdef TARGET_NR_pread
6090 case TARGET_NR_pread
:
6092 if (((CPUARMState
*)cpu_env
)->eabi
)
6095 if (!(p
= lock_user(VERIFY_WRITE
, arg2
, arg3
, 0)))
6097 ret
= get_errno(pread(arg1
, p
, arg3
, arg4
));
6098 unlock_user(p
, arg2
, ret
);
6100 case TARGET_NR_pwrite
:
6102 if (((CPUARMState
*)cpu_env
)->eabi
)
6105 if (!(p
= lock_user(VERIFY_READ
, arg2
, arg3
, 1)))
6107 ret
= get_errno(pwrite(arg1
, p
, arg3
, arg4
));
6108 unlock_user(p
, arg2
, 0);
6111 #ifdef TARGET_NR_pread64
6112 case TARGET_NR_pread64
:
6113 if (!(p
= lock_user(VERIFY_WRITE
, arg2
, arg3
, 0)))
6115 ret
= get_errno(pread64(arg1
, p
, arg3
, target_offset64(arg4
, arg5
)));
6116 unlock_user(p
, arg2
, ret
);
6118 case TARGET_NR_pwrite64
:
6119 if (!(p
= lock_user(VERIFY_READ
, arg2
, arg3
, 1)))
6121 ret
= get_errno(pwrite64(arg1
, p
, arg3
, target_offset64(arg4
, arg5
)));
6122 unlock_user(p
, arg2
, 0);
6125 case TARGET_NR_getcwd
:
6126 if (!(p
= lock_user(VERIFY_WRITE
, arg1
, arg2
, 0)))
6128 ret
= get_errno(sys_getcwd1(p
, arg2
));
6129 unlock_user(p
, arg1
, ret
);
6131 case TARGET_NR_capget
:
6133 case TARGET_NR_capset
:
6135 case TARGET_NR_sigaltstack
:
6136 #if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_MIPS) || \
6137 defined(TARGET_SPARC) || defined(TARGET_PPC) || defined(TARGET_ALPHA) || \
6138 defined(TARGET_M68K)
6139 ret
= do_sigaltstack(arg1
, arg2
, get_sp_from_cpustate((CPUState
*)cpu_env
));
6144 case TARGET_NR_sendfile
:
6146 #ifdef TARGET_NR_getpmsg
6147 case TARGET_NR_getpmsg
:
6150 #ifdef TARGET_NR_putpmsg
6151 case TARGET_NR_putpmsg
:
6154 #ifdef TARGET_NR_vfork
6155 case TARGET_NR_vfork
:
6156 ret
= get_errno(do_fork(cpu_env
, CLONE_VFORK
| CLONE_VM
| SIGCHLD
,
6160 #ifdef TARGET_NR_ugetrlimit
6161 case TARGET_NR_ugetrlimit
:
6164 ret
= get_errno(getrlimit(arg1
, &rlim
));
6165 if (!is_error(ret
)) {
6166 struct target_rlimit
*target_rlim
;
6167 if (!lock_user_struct(VERIFY_WRITE
, target_rlim
, arg2
, 0))
6169 target_rlim
->rlim_cur
= tswapl(rlim
.rlim_cur
);
6170 target_rlim
->rlim_max
= tswapl(rlim
.rlim_max
);
6171 unlock_user_struct(target_rlim
, arg2
, 1);
6176 #ifdef TARGET_NR_truncate64
6177 case TARGET_NR_truncate64
:
6178 if (!(p
= lock_user_string(arg1
)))
6180 ret
= target_truncate64(cpu_env
, p
, arg2
, arg3
, arg4
);
6181 unlock_user(p
, arg1
, 0);
6184 #ifdef TARGET_NR_ftruncate64
6185 case TARGET_NR_ftruncate64
:
6186 ret
= target_ftruncate64(cpu_env
, arg1
, arg2
, arg3
, arg4
);
6189 #ifdef TARGET_NR_stat64
6190 case TARGET_NR_stat64
:
6191 if (!(p
= lock_user_string(arg1
)))
6193 ret
= get_errno(stat(path(p
), &st
));
6194 unlock_user(p
, arg1
, 0);
6196 ret
= host_to_target_stat64(cpu_env
, arg2
, &st
);
6199 #ifdef TARGET_NR_lstat64
6200 case TARGET_NR_lstat64
:
6201 if (!(p
= lock_user_string(arg1
)))
6203 ret
= get_errno(lstat(path(p
), &st
));
6204 unlock_user(p
, arg1
, 0);
6206 ret
= host_to_target_stat64(cpu_env
, arg2
, &st
);
6209 #ifdef TARGET_NR_fstat64
6210 case TARGET_NR_fstat64
:
6211 ret
= get_errno(fstat(arg1
, &st
));
6213 ret
= host_to_target_stat64(cpu_env
, arg2
, &st
);
6216 #if (defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat)) && \
6217 (defined(__NR_fstatat64) || defined(__NR_newfstatat))
6218 #ifdef TARGET_NR_fstatat64
6219 case TARGET_NR_fstatat64
:
6221 #ifdef TARGET_NR_newfstatat
6222 case TARGET_NR_newfstatat
:
6224 if (!(p
= lock_user_string(arg2
)))
6226 #ifdef __NR_fstatat64
6227 ret
= get_errno(sys_fstatat64(arg1
, path(p
), &st
, arg4
));
6229 ret
= get_errno(sys_newfstatat(arg1
, path(p
), &st
, arg4
));
6232 ret
= host_to_target_stat64(cpu_env
, arg3
, &st
);
6236 case TARGET_NR_lchown
:
6237 if (!(p
= lock_user_string(arg1
)))
6239 ret
= get_errno(lchown(p
, low2highuid(arg2
), low2highgid(arg3
)));
6240 unlock_user(p
, arg1
, 0);
6242 case TARGET_NR_getuid
:
6243 ret
= get_errno(high2lowuid(getuid()));
6245 case TARGET_NR_getgid
:
6246 ret
= get_errno(high2lowgid(getgid()));
6248 case TARGET_NR_geteuid
:
6249 ret
= get_errno(high2lowuid(geteuid()));
6251 case TARGET_NR_getegid
:
6252 ret
= get_errno(high2lowgid(getegid()));
6254 case TARGET_NR_setreuid
:
6255 ret
= get_errno(setreuid(low2highuid(arg1
), low2highuid(arg2
)));
6257 case TARGET_NR_setregid
:
6258 ret
= get_errno(setregid(low2highgid(arg1
), low2highgid(arg2
)));
6260 case TARGET_NR_getgroups
:
6262 int gidsetsize
= arg1
;
6263 uint16_t *target_grouplist
;
6267 grouplist
= alloca(gidsetsize
* sizeof(gid_t
));
6268 ret
= get_errno(getgroups(gidsetsize
, grouplist
));
6269 if (gidsetsize
== 0)
6271 if (!is_error(ret
)) {
6272 target_grouplist
= lock_user(VERIFY_WRITE
, arg2
, gidsetsize
* 2, 0);
6273 if (!target_grouplist
)
6275 for(i
= 0;i
< ret
; i
++)
6276 target_grouplist
[i
] = tswap16(grouplist
[i
]);
6277 unlock_user(target_grouplist
, arg2
, gidsetsize
* 2);
6281 case TARGET_NR_setgroups
:
6283 int gidsetsize
= arg1
;
6284 uint16_t *target_grouplist
;
6288 grouplist
= alloca(gidsetsize
* sizeof(gid_t
));
6289 target_grouplist
= lock_user(VERIFY_READ
, arg2
, gidsetsize
* 2, 1);
6290 if (!target_grouplist
) {
6291 ret
= -TARGET_EFAULT
;
6294 for(i
= 0;i
< gidsetsize
; i
++)
6295 grouplist
[i
] = tswap16(target_grouplist
[i
]);
6296 unlock_user(target_grouplist
, arg2
, 0);
6297 ret
= get_errno(setgroups(gidsetsize
, grouplist
));
6300 case TARGET_NR_fchown
:
6301 ret
= get_errno(fchown(arg1
, low2highuid(arg2
), low2highgid(arg3
)));
6303 #if defined(TARGET_NR_fchownat) && defined(__NR_fchownat)
6304 case TARGET_NR_fchownat
:
6305 if (!(p
= lock_user_string(arg2
)))
6307 ret
= get_errno(sys_fchownat(arg1
, p
, low2highuid(arg3
), low2highgid(arg4
), arg5
));
6308 unlock_user(p
, arg2
, 0);
6311 #ifdef TARGET_NR_setresuid
6312 case TARGET_NR_setresuid
:
6313 ret
= get_errno(setresuid(low2highuid(arg1
),
6315 low2highuid(arg3
)));
6318 #ifdef TARGET_NR_getresuid
6319 case TARGET_NR_getresuid
:
6321 uid_t ruid
, euid
, suid
;
6322 ret
= get_errno(getresuid(&ruid
, &euid
, &suid
));
6323 if (!is_error(ret
)) {
6324 if (put_user_u16(high2lowuid(ruid
), arg1
)
6325 || put_user_u16(high2lowuid(euid
), arg2
)
6326 || put_user_u16(high2lowuid(suid
), arg3
))
6332 #ifdef TARGET_NR_getresgid
6333 case TARGET_NR_setresgid
:
6334 ret
= get_errno(setresgid(low2highgid(arg1
),
6336 low2highgid(arg3
)));
6339 #ifdef TARGET_NR_getresgid
6340 case TARGET_NR_getresgid
:
6342 gid_t rgid
, egid
, sgid
;
6343 ret
= get_errno(getresgid(&rgid
, &egid
, &sgid
));
6344 if (!is_error(ret
)) {
6345 if (put_user_u16(high2lowgid(rgid
), arg1
)
6346 || put_user_u16(high2lowgid(egid
), arg2
)
6347 || put_user_u16(high2lowgid(sgid
), arg3
))
6353 case TARGET_NR_chown
:
6354 if (!(p
= lock_user_string(arg1
)))
6356 ret
= get_errno(chown(p
, low2highuid(arg2
), low2highgid(arg3
)));
6357 unlock_user(p
, arg1
, 0);
6359 case TARGET_NR_setuid
:
6360 ret
= get_errno(setuid(low2highuid(arg1
)));
6362 case TARGET_NR_setgid
:
6363 ret
= get_errno(setgid(low2highgid(arg1
)));
6365 case TARGET_NR_setfsuid
:
6366 ret
= get_errno(setfsuid(arg1
));
6368 case TARGET_NR_setfsgid
:
6369 ret
= get_errno(setfsgid(arg1
));
6371 #endif /* USE_UID16 */
6373 #ifdef TARGET_NR_lchown32
6374 case TARGET_NR_lchown32
:
6375 if (!(p
= lock_user_string(arg1
)))
6377 ret
= get_errno(lchown(p
, arg2
, arg3
));
6378 unlock_user(p
, arg1
, 0);
6381 #ifdef TARGET_NR_getuid32
6382 case TARGET_NR_getuid32
:
6383 ret
= get_errno(getuid());
6387 #if defined(TARGET_NR_getxuid) && defined(TARGET_ALPHA)
6388 /* Alpha specific */
6389 case TARGET_NR_getxuid
:
6393 ((CPUAlphaState
*)cpu_env
)->ir
[IR_A4
]=euid
;
6395 ret
= get_errno(getuid());
6398 #if defined(TARGET_NR_getxgid) && defined(TARGET_ALPHA)
6399 /* Alpha specific */
6400 case TARGET_NR_getxgid
:
6404 ((CPUAlphaState
*)cpu_env
)->ir
[IR_A4
]=egid
;
6406 ret
= get_errno(getgid());
6410 #ifdef TARGET_NR_getgid32
6411 case TARGET_NR_getgid32
:
6412 ret
= get_errno(getgid());
6415 #ifdef TARGET_NR_geteuid32
6416 case TARGET_NR_geteuid32
:
6417 ret
= get_errno(geteuid());
6420 #ifdef TARGET_NR_getegid32
6421 case TARGET_NR_getegid32
:
6422 ret
= get_errno(getegid());
6425 #ifdef TARGET_NR_setreuid32
6426 case TARGET_NR_setreuid32
:
6427 ret
= get_errno(setreuid(arg1
, arg2
));
6430 #ifdef TARGET_NR_setregid32
6431 case TARGET_NR_setregid32
:
6432 ret
= get_errno(setregid(arg1
, arg2
));
6435 #ifdef TARGET_NR_getgroups32
6436 case TARGET_NR_getgroups32
:
6438 int gidsetsize
= arg1
;
6439 uint32_t *target_grouplist
;
6443 grouplist
= alloca(gidsetsize
* sizeof(gid_t
));
6444 ret
= get_errno(getgroups(gidsetsize
, grouplist
));
6445 if (gidsetsize
== 0)
6447 if (!is_error(ret
)) {
6448 target_grouplist
= lock_user(VERIFY_WRITE
, arg2
, gidsetsize
* 4, 0);
6449 if (!target_grouplist
) {
6450 ret
= -TARGET_EFAULT
;
6453 for(i
= 0;i
< ret
; i
++)
6454 target_grouplist
[i
] = tswap32(grouplist
[i
]);
6455 unlock_user(target_grouplist
, arg2
, gidsetsize
* 4);
6460 #ifdef TARGET_NR_setgroups32
6461 case TARGET_NR_setgroups32
:
6463 int gidsetsize
= arg1
;
6464 uint32_t *target_grouplist
;
6468 grouplist
= alloca(gidsetsize
* sizeof(gid_t
));
6469 target_grouplist
= lock_user(VERIFY_READ
, arg2
, gidsetsize
* 4, 1);
6470 if (!target_grouplist
) {
6471 ret
= -TARGET_EFAULT
;
6474 for(i
= 0;i
< gidsetsize
; i
++)
6475 grouplist
[i
] = tswap32(target_grouplist
[i
]);
6476 unlock_user(target_grouplist
, arg2
, 0);
6477 ret
= get_errno(setgroups(gidsetsize
, grouplist
));
6481 #ifdef TARGET_NR_fchown32
6482 case TARGET_NR_fchown32
:
6483 ret
= get_errno(fchown(arg1
, arg2
, arg3
));
6486 #ifdef TARGET_NR_setresuid32
6487 case TARGET_NR_setresuid32
:
6488 ret
= get_errno(setresuid(arg1
, arg2
, arg3
));
6491 #ifdef TARGET_NR_getresuid32
6492 case TARGET_NR_getresuid32
:
6494 uid_t ruid
, euid
, suid
;
6495 ret
= get_errno(getresuid(&ruid
, &euid
, &suid
));
6496 if (!is_error(ret
)) {
6497 if (put_user_u32(ruid
, arg1
)
6498 || put_user_u32(euid
, arg2
)
6499 || put_user_u32(suid
, arg3
))
6505 #ifdef TARGET_NR_setresgid32
6506 case TARGET_NR_setresgid32
:
6507 ret
= get_errno(setresgid(arg1
, arg2
, arg3
));
6510 #ifdef TARGET_NR_getresgid32
6511 case TARGET_NR_getresgid32
:
6513 gid_t rgid
, egid
, sgid
;
6514 ret
= get_errno(getresgid(&rgid
, &egid
, &sgid
));
6515 if (!is_error(ret
)) {
6516 if (put_user_u32(rgid
, arg1
)
6517 || put_user_u32(egid
, arg2
)
6518 || put_user_u32(sgid
, arg3
))
6524 #ifdef TARGET_NR_chown32
6525 case TARGET_NR_chown32
:
6526 if (!(p
= lock_user_string(arg1
)))
6528 ret
= get_errno(chown(p
, arg2
, arg3
));
6529 unlock_user(p
, arg1
, 0);
6532 #ifdef TARGET_NR_setuid32
6533 case TARGET_NR_setuid32
:
6534 ret
= get_errno(setuid(arg1
));
6537 #ifdef TARGET_NR_setgid32
6538 case TARGET_NR_setgid32
:
6539 ret
= get_errno(setgid(arg1
));
6542 #ifdef TARGET_NR_setfsuid32
6543 case TARGET_NR_setfsuid32
:
6544 ret
= get_errno(setfsuid(arg1
));
6547 #ifdef TARGET_NR_setfsgid32
6548 case TARGET_NR_setfsgid32
:
6549 ret
= get_errno(setfsgid(arg1
));
6553 case TARGET_NR_pivot_root
:
6555 #ifdef TARGET_NR_mincore
6556 case TARGET_NR_mincore
:
6559 ret
= -TARGET_EFAULT
;
6560 if (!(a
= lock_user(VERIFY_READ
, arg1
,arg2
, 0)))
6562 if (!(p
= lock_user_string(arg3
)))
6564 ret
= get_errno(mincore(a
, arg2
, p
));
6565 unlock_user(p
, arg3
, ret
);
6567 unlock_user(a
, arg1
, 0);
6571 #ifdef TARGET_NR_arm_fadvise64_64
6572 case TARGET_NR_arm_fadvise64_64
:
6575 * arm_fadvise64_64 looks like fadvise64_64 but
6576 * with different argument order
6584 #if defined(TARGET_NR_fadvise64_64) || defined(TARGET_NR_arm_fadvise64_64) || defined(TARGET_NR_fadvise64)
6585 #ifdef TARGET_NR_fadvise64_64
6586 case TARGET_NR_fadvise64_64
:
6588 #ifdef TARGET_NR_fadvise64
6589 case TARGET_NR_fadvise64
:
6593 case 4: arg4
= POSIX_FADV_NOREUSE
+ 1; break; /* make sure it's an invalid value */
6594 case 5: arg4
= POSIX_FADV_NOREUSE
+ 2; break; /* ditto */
6595 case 6: arg4
= POSIX_FADV_DONTNEED
; break;
6596 case 7: arg4
= POSIX_FADV_NOREUSE
; break;
6600 ret
= -posix_fadvise(arg1
, arg2
, arg3
, arg4
);
6603 #ifdef TARGET_NR_madvise
6604 case TARGET_NR_madvise
:
6605 /* A straight passthrough may not be safe because qemu sometimes
6606 turns private flie-backed mappings into anonymous mappings.
6607 This will break MADV_DONTNEED.
6608 This is a hint, so ignoring and returning success is ok. */
6612 #if TARGET_ABI_BITS == 32
6613 case TARGET_NR_fcntl64
:
6617 struct target_flock64
*target_fl
;
6619 struct target_eabi_flock64
*target_efl
;
6622 cmd
= target_to_host_fcntl_cmd(arg2
);
6623 if (cmd
== -TARGET_EINVAL
)
6627 case TARGET_F_GETLK64
:
6629 if (((CPUARMState
*)cpu_env
)->eabi
) {
6630 if (!lock_user_struct(VERIFY_READ
, target_efl
, arg3
, 1))
6632 fl
.l_type
= tswap16(target_efl
->l_type
);
6633 fl
.l_whence
= tswap16(target_efl
->l_whence
);
6634 fl
.l_start
= tswap64(target_efl
->l_start
);
6635 fl
.l_len
= tswap64(target_efl
->l_len
);
6636 fl
.l_pid
= tswap32(target_efl
->l_pid
);
6637 unlock_user_struct(target_efl
, arg3
, 0);
6641 if (!lock_user_struct(VERIFY_READ
, target_fl
, arg3
, 1))
6643 fl
.l_type
= tswap16(target_fl
->l_type
);
6644 fl
.l_whence
= tswap16(target_fl
->l_whence
);
6645 fl
.l_start
= tswap64(target_fl
->l_start
);
6646 fl
.l_len
= tswap64(target_fl
->l_len
);
6647 fl
.l_pid
= tswap32(target_fl
->l_pid
);
6648 unlock_user_struct(target_fl
, arg3
, 0);
6650 ret
= get_errno(fcntl(arg1
, cmd
, &fl
));
6653 if (((CPUARMState
*)cpu_env
)->eabi
) {
6654 if (!lock_user_struct(VERIFY_WRITE
, target_efl
, arg3
, 0))
6656 target_efl
->l_type
= tswap16(fl
.l_type
);
6657 target_efl
->l_whence
= tswap16(fl
.l_whence
);
6658 target_efl
->l_start
= tswap64(fl
.l_start
);
6659 target_efl
->l_len
= tswap64(fl
.l_len
);
6660 target_efl
->l_pid
= tswap32(fl
.l_pid
);
6661 unlock_user_struct(target_efl
, arg3
, 1);
6665 if (!lock_user_struct(VERIFY_WRITE
, target_fl
, arg3
, 0))
6667 target_fl
->l_type
= tswap16(fl
.l_type
);
6668 target_fl
->l_whence
= tswap16(fl
.l_whence
);
6669 target_fl
->l_start
= tswap64(fl
.l_start
);
6670 target_fl
->l_len
= tswap64(fl
.l_len
);
6671 target_fl
->l_pid
= tswap32(fl
.l_pid
);
6672 unlock_user_struct(target_fl
, arg3
, 1);
6677 case TARGET_F_SETLK64
:
6678 case TARGET_F_SETLKW64
:
6680 if (((CPUARMState
*)cpu_env
)->eabi
) {
6681 if (!lock_user_struct(VERIFY_READ
, target_efl
, arg3
, 1))
6683 fl
.l_type
= tswap16(target_efl
->l_type
);
6684 fl
.l_whence
= tswap16(target_efl
->l_whence
);
6685 fl
.l_start
= tswap64(target_efl
->l_start
);
6686 fl
.l_len
= tswap64(target_efl
->l_len
);
6687 fl
.l_pid
= tswap32(target_efl
->l_pid
);
6688 unlock_user_struct(target_efl
, arg3
, 0);
6692 if (!lock_user_struct(VERIFY_READ
, target_fl
, arg3
, 1))
6694 fl
.l_type
= tswap16(target_fl
->l_type
);
6695 fl
.l_whence
= tswap16(target_fl
->l_whence
);
6696 fl
.l_start
= tswap64(target_fl
->l_start
);
6697 fl
.l_len
= tswap64(target_fl
->l_len
);
6698 fl
.l_pid
= tswap32(target_fl
->l_pid
);
6699 unlock_user_struct(target_fl
, arg3
, 0);
6701 ret
= get_errno(fcntl(arg1
, cmd
, &fl
));
6704 ret
= do_fcntl(arg1
, arg2
, arg3
);
6710 #ifdef TARGET_NR_cacheflush
6711 case TARGET_NR_cacheflush
:
6712 /* self-modifying code is handled automatically, so nothing needed */
6716 #ifdef TARGET_NR_security
6717 case TARGET_NR_security
:
6720 #ifdef TARGET_NR_getpagesize
6721 case TARGET_NR_getpagesize
:
6722 ret
= TARGET_PAGE_SIZE
;
6725 case TARGET_NR_gettid
:
6726 ret
= get_errno(gettid());
6728 #ifdef TARGET_NR_readahead
6729 case TARGET_NR_readahead
:
6730 #if TARGET_ABI_BITS == 32
6732 if (((CPUARMState
*)cpu_env
)->eabi
)
6739 ret
= get_errno(readahead(arg1
, ((off64_t
)arg3
<< 32) | arg2
, arg4
));
6741 ret
= get_errno(readahead(arg1
, arg2
, arg3
));
6745 #ifdef TARGET_NR_setxattr
6746 case TARGET_NR_setxattr
:
6747 case TARGET_NR_lsetxattr
:
6748 case TARGET_NR_fsetxattr
:
6749 case TARGET_NR_getxattr
:
6750 case TARGET_NR_lgetxattr
:
6751 case TARGET_NR_fgetxattr
:
6752 case TARGET_NR_listxattr
:
6753 case TARGET_NR_llistxattr
:
6754 case TARGET_NR_flistxattr
:
6755 case TARGET_NR_removexattr
:
6756 case TARGET_NR_lremovexattr
:
6757 case TARGET_NR_fremovexattr
:
6758 ret
= -TARGET_EOPNOTSUPP
;
6761 #ifdef TARGET_NR_set_thread_area
6762 case TARGET_NR_set_thread_area
:
6763 #if defined(TARGET_MIPS)
6764 ((CPUMIPSState
*) cpu_env
)->tls_value
= arg1
;
6767 #elif defined(TARGET_CRIS)
6769 ret
= -TARGET_EINVAL
;
6771 ((CPUCRISState
*) cpu_env
)->pregs
[PR_PID
] = arg1
;
6775 #elif defined(TARGET_I386) && defined(TARGET_ABI32)
6776 ret
= do_set_thread_area(cpu_env
, arg1
);
6779 goto unimplemented_nowarn
;
6782 #ifdef TARGET_NR_get_thread_area
6783 case TARGET_NR_get_thread_area
:
6784 #if defined(TARGET_I386) && defined(TARGET_ABI32)
6785 ret
= do_get_thread_area(cpu_env
, arg1
);
6787 goto unimplemented_nowarn
;
6790 #ifdef TARGET_NR_getdomainname
6791 case TARGET_NR_getdomainname
:
6792 goto unimplemented_nowarn
;
6795 #ifdef TARGET_NR_clock_gettime
6796 case TARGET_NR_clock_gettime
:
6799 ret
= get_errno(clock_gettime(arg1
, &ts
));
6800 if (!is_error(ret
)) {
6801 host_to_target_timespec(arg2
, &ts
);
6806 #ifdef TARGET_NR_clock_getres
6807 case TARGET_NR_clock_getres
:
6810 ret
= get_errno(clock_getres(arg1
, &ts
));
6811 if (!is_error(ret
)) {
6812 host_to_target_timespec(arg2
, &ts
);
6817 #ifdef TARGET_NR_clock_nanosleep
6818 case TARGET_NR_clock_nanosleep
:
6821 target_to_host_timespec(&ts
, arg3
);
6822 ret
= get_errno(clock_nanosleep(arg1
, arg2
, &ts
, arg4
? &ts
: NULL
));
6824 host_to_target_timespec(arg4
, &ts
);
6829 #if defined(TARGET_NR_set_tid_address) && defined(__NR_set_tid_address)
6830 case TARGET_NR_set_tid_address
:
6831 ret
= get_errno(set_tid_address((int *)g2h(arg1
)));
6835 #if defined(TARGET_NR_tkill) && defined(__NR_tkill)
6836 case TARGET_NR_tkill
:
6837 ret
= get_errno(sys_tkill((int)arg1
, target_to_host_signal(arg2
)));
6841 #if defined(TARGET_NR_tgkill) && defined(__NR_tgkill)
6842 case TARGET_NR_tgkill
:
6843 ret
= get_errno(sys_tgkill((int)arg1
, (int)arg2
,
6844 target_to_host_signal(arg3
)));
6848 #ifdef TARGET_NR_set_robust_list
6849 case TARGET_NR_set_robust_list
:
6850 goto unimplemented_nowarn
;
6853 #if defined(TARGET_NR_utimensat) && defined(__NR_utimensat)
6854 case TARGET_NR_utimensat
:
6856 struct timespec
*tsp
, ts
[2];
6860 target_to_host_timespec(ts
, arg3
);
6861 target_to_host_timespec(ts
+1, arg3
+sizeof(struct target_timespec
));
6865 ret
= get_errno(sys_utimensat(arg1
, NULL
, tsp
, arg4
));
6867 if (!(p
= lock_user_string(arg2
))) {
6868 ret
= -TARGET_EFAULT
;
6871 ret
= get_errno(sys_utimensat(arg1
, path(p
), tsp
, arg4
));
6872 unlock_user(p
, arg2
, 0);
6877 #if defined(CONFIG_USE_NPTL)
6878 case TARGET_NR_futex
:
6879 ret
= do_futex(arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
6882 #if defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init)
6883 case TARGET_NR_inotify_init
:
6884 ret
= get_errno(sys_inotify_init());
6887 #if defined(TARGET_NR_inotify_add_watch) && defined(__NR_inotify_add_watch)
6888 case TARGET_NR_inotify_add_watch
:
6889 p
= lock_user_string(arg2
);
6890 ret
= get_errno(sys_inotify_add_watch(arg1
, path(p
), arg3
));
6891 unlock_user(p
, arg2
, 0);
6894 #if defined(TARGET_NR_inotify_rm_watch) && defined(__NR_inotify_rm_watch)
6895 case TARGET_NR_inotify_rm_watch
:
6896 ret
= get_errno(sys_inotify_rm_watch(arg1
, arg2
));
6900 #if defined(TARGET_NR_mq_open) && defined(__NR_mq_open)
6901 case TARGET_NR_mq_open
:
6903 struct mq_attr posix_mq_attr
;
6905 p
= lock_user_string(arg1
- 1);
6907 copy_from_user_mq_attr (&posix_mq_attr
, arg4
);
6908 ret
= get_errno(mq_open(p
, arg2
, arg3
, &posix_mq_attr
));
6909 unlock_user (p
, arg1
, 0);
6913 case TARGET_NR_mq_unlink
:
6914 p
= lock_user_string(arg1
- 1);
6915 ret
= get_errno(mq_unlink(p
));
6916 unlock_user (p
, arg1
, 0);
6919 case TARGET_NR_mq_timedsend
:
6923 p
= lock_user (VERIFY_READ
, arg2
, arg3
, 1);
6925 target_to_host_timespec(&ts
, arg5
);
6926 ret
= get_errno(mq_timedsend(arg1
, p
, arg3
, arg4
, &ts
));
6927 host_to_target_timespec(arg5
, &ts
);
6930 ret
= get_errno(mq_send(arg1
, p
, arg3
, arg4
));
6931 unlock_user (p
, arg2
, arg3
);
6935 case TARGET_NR_mq_timedreceive
:
6940 p
= lock_user (VERIFY_READ
, arg2
, arg3
, 1);
6942 target_to_host_timespec(&ts
, arg5
);
6943 ret
= get_errno(mq_timedreceive(arg1
, p
, arg3
, &prio
, &ts
));
6944 host_to_target_timespec(arg5
, &ts
);
6947 ret
= get_errno(mq_receive(arg1
, p
, arg3
, &prio
));
6948 unlock_user (p
, arg2
, arg3
);
6950 put_user_u32(prio
, arg4
);
6954 /* Not implemented for now... */
6955 /* case TARGET_NR_mq_notify: */
6958 case TARGET_NR_mq_getsetattr
:
6960 struct mq_attr posix_mq_attr_in
, posix_mq_attr_out
;
6963 ret
= mq_getattr(arg1
, &posix_mq_attr_out
);
6964 copy_to_user_mq_attr(arg3
, &posix_mq_attr_out
);
6967 copy_from_user_mq_attr(&posix_mq_attr_in
, arg2
);
6968 ret
|= mq_setattr(arg1
, &posix_mq_attr_in
, &posix_mq_attr_out
);
6975 #ifdef CONFIG_SPLICE
6976 #ifdef TARGET_NR_tee
6979 ret
= get_errno(tee(arg1
,arg2
,arg3
,arg4
));
6983 #ifdef TARGET_NR_splice
6984 case TARGET_NR_splice
:
6986 loff_t loff_in
, loff_out
;
6987 loff_t
*ploff_in
= NULL
, *ploff_out
= NULL
;
6989 get_user_u64(loff_in
, arg2
);
6990 ploff_in
= &loff_in
;
6993 get_user_u64(loff_out
, arg2
);
6994 ploff_out
= &loff_out
;
6996 ret
= get_errno(splice(arg1
, ploff_in
, arg3
, ploff_out
, arg5
, arg6
));
7000 #ifdef TARGET_NR_vmsplice
7001 case TARGET_NR_vmsplice
:
7006 vec
= alloca(count
* sizeof(struct iovec
));
7007 if (lock_iovec(VERIFY_READ
, vec
, arg2
, count
, 1) < 0)
7009 ret
= get_errno(vmsplice(arg1
, vec
, count
, arg4
));
7010 unlock_iovec(vec
, arg2
, count
, 0);
7014 #endif /* CONFIG_SPLICE */
7015 #ifdef CONFIG_EVENTFD
7016 #if defined(TARGET_NR_eventfd)
7017 case TARGET_NR_eventfd
:
7018 ret
= get_errno(eventfd(arg1
, 0));
7021 #if defined(TARGET_NR_eventfd2)
7022 case TARGET_NR_eventfd2
:
7023 ret
= get_errno(eventfd(arg1
, arg2
));
7026 #endif /* CONFIG_EVENTFD */
7027 #if defined(CONFIG_FALLOCATE) && defined(TARGET_NR_fallocate)
7028 case TARGET_NR_fallocate
:
7029 ret
= get_errno(fallocate(arg1
, arg2
, arg3
, arg4
));
7034 gemu_log("qemu: Unsupported syscall: %d\n", num
);
7035 #if defined(TARGET_NR_setxattr) || defined(TARGET_NR_get_thread_area) || defined(TARGET_NR_getdomainname) || defined(TARGET_NR_set_robust_list)
7036 unimplemented_nowarn
:
7038 ret
= -TARGET_ENOSYS
;
7043 gemu_log(" = " TARGET_ABI_FMT_ld
"\n", ret
);
7046 print_syscall_ret(num
, ret
);
7049 ret
= -TARGET_EFAULT
;