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>
45 int __clone2(int (*fn
)(void *), void *child_stack_base
,
46 size_t stack_size
, int flags
, void *arg
, ...);
48 #include <sys/socket.h>
52 #include <sys/times.h>
55 #include <sys/statfs.h>
57 #include <sys/sysinfo.h>
58 #include <sys/utsname.h>
59 //#include <sys/user.h>
60 #include <netinet/ip.h>
61 #include <netinet/tcp.h>
62 #include <linux/wireless.h>
63 #include <qemu-common.h>
68 #include <sys/eventfd.h>
71 #include <sys/epoll.h>
74 #define termios host_termios
75 #define winsize host_winsize
76 #define termio host_termio
77 #define sgttyb host_sgttyb /* same as target */
78 #define tchars host_tchars /* same as target */
79 #define ltchars host_ltchars /* same as target */
81 #include <linux/termios.h>
82 #include <linux/unistd.h>
83 #include <linux/utsname.h>
84 #include <linux/cdrom.h>
85 #include <linux/hdreg.h>
86 #include <linux/soundcard.h>
88 #include <linux/mtio.h>
90 #if defined(CONFIG_FIEMAP)
91 #include <linux/fiemap.h>
95 #include "linux_loop.h"
96 #include "cpu-uname.h"
99 #include "qemu-common.h"
101 #if defined(CONFIG_USE_NPTL)
102 #define CLONE_NPTL_FLAGS2 (CLONE_SETTLS | \
103 CLONE_PARENT_SETTID | CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID)
105 /* XXX: Hardcode the above values. */
106 #define CLONE_NPTL_FLAGS2 0
111 //#include <linux/msdos_fs.h>
112 #define VFAT_IOCTL_READDIR_BOTH _IOR('r', 1, struct linux_dirent [2])
113 #define VFAT_IOCTL_READDIR_SHORT _IOR('r', 2, struct linux_dirent [2])
124 #define _syscall0(type,name) \
125 static type name (void) \
127 return syscall(__NR_##name); \
130 #define _syscall1(type,name,type1,arg1) \
131 static type name (type1 arg1) \
133 return syscall(__NR_##name, arg1); \
136 #define _syscall2(type,name,type1,arg1,type2,arg2) \
137 static type name (type1 arg1,type2 arg2) \
139 return syscall(__NR_##name, arg1, arg2); \
142 #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
143 static type name (type1 arg1,type2 arg2,type3 arg3) \
145 return syscall(__NR_##name, arg1, arg2, arg3); \
148 #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
149 static type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4) \
151 return syscall(__NR_##name, arg1, arg2, arg3, arg4); \
154 #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
156 static type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \
158 return syscall(__NR_##name, arg1, arg2, arg3, arg4, arg5); \
162 #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
163 type5,arg5,type6,arg6) \
164 static type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5, \
167 return syscall(__NR_##name, arg1, arg2, arg3, arg4, arg5, arg6); \
171 #define __NR_sys_uname __NR_uname
172 #define __NR_sys_faccessat __NR_faccessat
173 #define __NR_sys_fchmodat __NR_fchmodat
174 #define __NR_sys_fchownat __NR_fchownat
175 #define __NR_sys_fstatat64 __NR_fstatat64
176 #define __NR_sys_futimesat __NR_futimesat
177 #define __NR_sys_getcwd1 __NR_getcwd
178 #define __NR_sys_getdents __NR_getdents
179 #define __NR_sys_getdents64 __NR_getdents64
180 #define __NR_sys_getpriority __NR_getpriority
181 #define __NR_sys_linkat __NR_linkat
182 #define __NR_sys_mkdirat __NR_mkdirat
183 #define __NR_sys_mknodat __NR_mknodat
184 #define __NR_sys_newfstatat __NR_newfstatat
185 #define __NR_sys_openat __NR_openat
186 #define __NR_sys_readlinkat __NR_readlinkat
187 #define __NR_sys_renameat __NR_renameat
188 #define __NR_sys_rt_sigqueueinfo __NR_rt_sigqueueinfo
189 #define __NR_sys_symlinkat __NR_symlinkat
190 #define __NR_sys_syslog __NR_syslog
191 #define __NR_sys_tgkill __NR_tgkill
192 #define __NR_sys_tkill __NR_tkill
193 #define __NR_sys_unlinkat __NR_unlinkat
194 #define __NR_sys_utimensat __NR_utimensat
195 #define __NR_sys_futex __NR_futex
196 #define __NR_sys_inotify_init __NR_inotify_init
197 #define __NR_sys_inotify_add_watch __NR_inotify_add_watch
198 #define __NR_sys_inotify_rm_watch __NR_inotify_rm_watch
200 #if defined(__alpha__) || defined (__ia64__) || defined(__x86_64__) || \
202 #define __NR__llseek __NR_lseek
206 _syscall0(int, gettid
)
208 /* This is a replacement for the host gettid() and must return a host
210 static int gettid(void) {
214 _syscall3(int, sys_getdents
, uint
, fd
, struct linux_dirent
*, dirp
, uint
, count
);
215 #if defined(TARGET_NR_getdents64) && defined(__NR_getdents64)
216 _syscall3(int, sys_getdents64
, uint
, fd
, struct linux_dirent64
*, dirp
, uint
, count
);
218 _syscall2(int, sys_getpriority
, int, which
, int, who
);
219 #if defined(TARGET_NR__llseek) && defined(__NR_llseek)
220 _syscall5(int, _llseek
, uint
, fd
, ulong
, hi
, ulong
, lo
,
221 loff_t
*, res
, uint
, wh
);
223 _syscall3(int,sys_rt_sigqueueinfo
,int,pid
,int,sig
,siginfo_t
*,uinfo
)
224 _syscall3(int,sys_syslog
,int,type
,char*,bufp
,int,len
)
225 #if defined(TARGET_NR_tgkill) && defined(__NR_tgkill)
226 _syscall3(int,sys_tgkill
,int,tgid
,int,pid
,int,sig
)
228 #if defined(TARGET_NR_tkill) && defined(__NR_tkill)
229 _syscall2(int,sys_tkill
,int,tid
,int,sig
)
231 #ifdef __NR_exit_group
232 _syscall1(int,exit_group
,int,error_code
)
234 #if defined(TARGET_NR_set_tid_address) && defined(__NR_set_tid_address)
235 _syscall1(int,set_tid_address
,int *,tidptr
)
237 #if defined(CONFIG_USE_NPTL)
238 #if defined(TARGET_NR_futex) && defined(__NR_futex)
239 _syscall6(int,sys_futex
,int *,uaddr
,int,op
,int,val
,
240 const struct timespec
*,timeout
,int *,uaddr2
,int,val3
)
243 #define __NR_sys_sched_getaffinity __NR_sched_getaffinity
244 _syscall3(int, sys_sched_getaffinity
, pid_t
, pid
, unsigned int, len
,
245 unsigned long *, user_mask_ptr
);
246 #define __NR_sys_sched_setaffinity __NR_sched_setaffinity
247 _syscall3(int, sys_sched_setaffinity
, pid_t
, pid
, unsigned int, len
,
248 unsigned long *, user_mask_ptr
);
250 static bitmask_transtbl fcntl_flags_tbl
[] = {
251 { TARGET_O_ACCMODE
, TARGET_O_WRONLY
, O_ACCMODE
, O_WRONLY
, },
252 { TARGET_O_ACCMODE
, TARGET_O_RDWR
, O_ACCMODE
, O_RDWR
, },
253 { TARGET_O_CREAT
, TARGET_O_CREAT
, O_CREAT
, O_CREAT
, },
254 { TARGET_O_EXCL
, TARGET_O_EXCL
, O_EXCL
, O_EXCL
, },
255 { TARGET_O_NOCTTY
, TARGET_O_NOCTTY
, O_NOCTTY
, O_NOCTTY
, },
256 { TARGET_O_TRUNC
, TARGET_O_TRUNC
, O_TRUNC
, O_TRUNC
, },
257 { TARGET_O_APPEND
, TARGET_O_APPEND
, O_APPEND
, O_APPEND
, },
258 { TARGET_O_NONBLOCK
, TARGET_O_NONBLOCK
, O_NONBLOCK
, O_NONBLOCK
, },
259 { TARGET_O_SYNC
, TARGET_O_SYNC
, O_SYNC
, O_SYNC
, },
260 { TARGET_FASYNC
, TARGET_FASYNC
, FASYNC
, FASYNC
, },
261 { TARGET_O_DIRECTORY
, TARGET_O_DIRECTORY
, O_DIRECTORY
, O_DIRECTORY
, },
262 { TARGET_O_NOFOLLOW
, TARGET_O_NOFOLLOW
, O_NOFOLLOW
, O_NOFOLLOW
, },
263 { TARGET_O_LARGEFILE
, TARGET_O_LARGEFILE
, O_LARGEFILE
, O_LARGEFILE
, },
264 #if defined(O_DIRECT)
265 { TARGET_O_DIRECT
, TARGET_O_DIRECT
, O_DIRECT
, O_DIRECT
, },
270 #define COPY_UTSNAME_FIELD(dest, src) \
272 /* __NEW_UTS_LEN doesn't include terminating null */ \
273 (void) strncpy((dest), (src), __NEW_UTS_LEN); \
274 (dest)[__NEW_UTS_LEN] = '\0'; \
277 static int sys_uname(struct new_utsname
*buf
)
279 struct utsname uts_buf
;
281 if (uname(&uts_buf
) < 0)
285 * Just in case these have some differences, we
286 * translate utsname to new_utsname (which is the
287 * struct linux kernel uses).
290 memset(buf
, 0, sizeof(*buf
));
291 COPY_UTSNAME_FIELD(buf
->sysname
, uts_buf
.sysname
);
292 COPY_UTSNAME_FIELD(buf
->nodename
, uts_buf
.nodename
);
293 COPY_UTSNAME_FIELD(buf
->release
, uts_buf
.release
);
294 COPY_UTSNAME_FIELD(buf
->version
, uts_buf
.version
);
295 COPY_UTSNAME_FIELD(buf
->machine
, uts_buf
.machine
);
297 COPY_UTSNAME_FIELD(buf
->domainname
, uts_buf
.domainname
);
301 #undef COPY_UTSNAME_FIELD
304 static int sys_getcwd1(char *buf
, size_t size
)
306 if (getcwd(buf
, size
) == NULL
) {
307 /* getcwd() sets errno */
310 return strlen(buf
)+1;
315 * Host system seems to have atfile syscall stubs available. We
316 * now enable them one by one as specified by target syscall_nr.h.
319 #ifdef TARGET_NR_faccessat
320 static int sys_faccessat(int dirfd
, const char *pathname
, int mode
)
322 return (faccessat(dirfd
, pathname
, mode
, 0));
325 #ifdef TARGET_NR_fchmodat
326 static int sys_fchmodat(int dirfd
, const char *pathname
, mode_t mode
)
328 return (fchmodat(dirfd
, pathname
, mode
, 0));
331 #if defined(TARGET_NR_fchownat)
332 static int sys_fchownat(int dirfd
, const char *pathname
, uid_t owner
,
333 gid_t group
, int flags
)
335 return (fchownat(dirfd
, pathname
, owner
, group
, flags
));
338 #ifdef __NR_fstatat64
339 static int sys_fstatat64(int dirfd
, const char *pathname
, struct stat
*buf
,
342 return (fstatat(dirfd
, pathname
, buf
, flags
));
345 #ifdef __NR_newfstatat
346 static int sys_newfstatat(int dirfd
, const char *pathname
, struct stat
*buf
,
349 return (fstatat(dirfd
, pathname
, buf
, flags
));
352 #ifdef TARGET_NR_futimesat
353 static int sys_futimesat(int dirfd
, const char *pathname
,
354 const struct timeval times
[2])
356 return (futimesat(dirfd
, pathname
, times
));
359 #ifdef TARGET_NR_linkat
360 static int sys_linkat(int olddirfd
, const char *oldpath
,
361 int newdirfd
, const char *newpath
, int flags
)
363 return (linkat(olddirfd
, oldpath
, newdirfd
, newpath
, flags
));
366 #ifdef TARGET_NR_mkdirat
367 static int sys_mkdirat(int dirfd
, const char *pathname
, mode_t mode
)
369 return (mkdirat(dirfd
, pathname
, mode
));
372 #ifdef TARGET_NR_mknodat
373 static int sys_mknodat(int dirfd
, const char *pathname
, mode_t mode
,
376 return (mknodat(dirfd
, pathname
, mode
, dev
));
379 #ifdef TARGET_NR_openat
380 static int sys_openat(int dirfd
, const char *pathname
, int flags
, ...)
383 * open(2) has extra parameter 'mode' when called with
386 if ((flags
& O_CREAT
) != 0) {
391 * Get the 'mode' parameter and translate it to
395 mode
= va_arg(ap
, mode_t
);
396 mode
= target_to_host_bitmask(mode
, fcntl_flags_tbl
);
399 return (openat(dirfd
, pathname
, flags
, mode
));
401 return (openat(dirfd
, pathname
, flags
));
404 #ifdef TARGET_NR_readlinkat
405 static int sys_readlinkat(int dirfd
, const char *pathname
, char *buf
, size_t bufsiz
)
407 return (readlinkat(dirfd
, pathname
, buf
, bufsiz
));
410 #ifdef TARGET_NR_renameat
411 static int sys_renameat(int olddirfd
, const char *oldpath
,
412 int newdirfd
, const char *newpath
)
414 return (renameat(olddirfd
, oldpath
, newdirfd
, newpath
));
417 #ifdef TARGET_NR_symlinkat
418 static int sys_symlinkat(const char *oldpath
, int newdirfd
, const char *newpath
)
420 return (symlinkat(oldpath
, newdirfd
, newpath
));
423 #ifdef TARGET_NR_unlinkat
424 static int sys_unlinkat(int dirfd
, const char *pathname
, int flags
)
426 return (unlinkat(dirfd
, pathname
, flags
));
429 #else /* !CONFIG_ATFILE */
432 * Try direct syscalls instead
434 #if defined(TARGET_NR_faccessat) && defined(__NR_faccessat)
435 _syscall3(int,sys_faccessat
,int,dirfd
,const char *,pathname
,int,mode
)
437 #if defined(TARGET_NR_fchmodat) && defined(__NR_fchmodat)
438 _syscall3(int,sys_fchmodat
,int,dirfd
,const char *,pathname
, mode_t
,mode
)
440 #if defined(TARGET_NR_fchownat) && defined(__NR_fchownat)
441 _syscall5(int,sys_fchownat
,int,dirfd
,const char *,pathname
,
442 uid_t
,owner
,gid_t
,group
,int,flags
)
444 #if (defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat)) && \
445 defined(__NR_fstatat64)
446 _syscall4(int,sys_fstatat64
,int,dirfd
,const char *,pathname
,
447 struct stat
*,buf
,int,flags
)
449 #if defined(TARGET_NR_futimesat) && defined(__NR_futimesat)
450 _syscall3(int,sys_futimesat
,int,dirfd
,const char *,pathname
,
451 const struct timeval
*,times
)
453 #if (defined(TARGET_NR_newfstatat) || defined(TARGET_NR_fstatat64) ) && \
454 defined(__NR_newfstatat)
455 _syscall4(int,sys_newfstatat
,int,dirfd
,const char *,pathname
,
456 struct stat
*,buf
,int,flags
)
458 #if defined(TARGET_NR_linkat) && defined(__NR_linkat)
459 _syscall5(int,sys_linkat
,int,olddirfd
,const char *,oldpath
,
460 int,newdirfd
,const char *,newpath
,int,flags
)
462 #if defined(TARGET_NR_mkdirat) && defined(__NR_mkdirat)
463 _syscall3(int,sys_mkdirat
,int,dirfd
,const char *,pathname
,mode_t
,mode
)
465 #if defined(TARGET_NR_mknodat) && defined(__NR_mknodat)
466 _syscall4(int,sys_mknodat
,int,dirfd
,const char *,pathname
,
467 mode_t
,mode
,dev_t
,dev
)
469 #if defined(TARGET_NR_openat) && defined(__NR_openat)
470 _syscall4(int,sys_openat
,int,dirfd
,const char *,pathname
,int,flags
,mode_t
,mode
)
472 #if defined(TARGET_NR_readlinkat) && defined(__NR_readlinkat)
473 _syscall4(int,sys_readlinkat
,int,dirfd
,const char *,pathname
,
474 char *,buf
,size_t,bufsize
)
476 #if defined(TARGET_NR_renameat) && defined(__NR_renameat)
477 _syscall4(int,sys_renameat
,int,olddirfd
,const char *,oldpath
,
478 int,newdirfd
,const char *,newpath
)
480 #if defined(TARGET_NR_symlinkat) && defined(__NR_symlinkat)
481 _syscall3(int,sys_symlinkat
,const char *,oldpath
,
482 int,newdirfd
,const char *,newpath
)
484 #if defined(TARGET_NR_unlinkat) && defined(__NR_unlinkat)
485 _syscall3(int,sys_unlinkat
,int,dirfd
,const char *,pathname
,int,flags
)
488 #endif /* CONFIG_ATFILE */
490 #ifdef CONFIG_UTIMENSAT
491 static int sys_utimensat(int dirfd
, const char *pathname
,
492 const struct timespec times
[2], int flags
)
494 if (pathname
== NULL
)
495 return futimens(dirfd
, times
);
497 return utimensat(dirfd
, pathname
, times
, flags
);
500 #if defined(TARGET_NR_utimensat) && defined(__NR_utimensat)
501 _syscall4(int,sys_utimensat
,int,dirfd
,const char *,pathname
,
502 const struct timespec
*,tsp
,int,flags
)
504 #endif /* CONFIG_UTIMENSAT */
506 #ifdef CONFIG_INOTIFY
507 #include <sys/inotify.h>
509 #if defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init)
510 static int sys_inotify_init(void)
512 return (inotify_init());
515 #if defined(TARGET_NR_inotify_add_watch) && defined(__NR_inotify_add_watch)
516 static int sys_inotify_add_watch(int fd
,const char *pathname
, int32_t mask
)
518 return (inotify_add_watch(fd
, pathname
, mask
));
521 #if defined(TARGET_NR_inotify_rm_watch) && defined(__NR_inotify_rm_watch)
522 static int sys_inotify_rm_watch(int fd
, int32_t wd
)
524 return (inotify_rm_watch(fd
, wd
));
527 #ifdef CONFIG_INOTIFY1
528 #if defined(TARGET_NR_inotify_init1) && defined(__NR_inotify_init1)
529 static int sys_inotify_init1(int flags
)
531 return (inotify_init1(flags
));
536 /* Userspace can usually survive runtime without inotify */
537 #undef TARGET_NR_inotify_init
538 #undef TARGET_NR_inotify_init1
539 #undef TARGET_NR_inotify_add_watch
540 #undef TARGET_NR_inotify_rm_watch
541 #endif /* CONFIG_INOTIFY */
543 #if defined(TARGET_NR_ppoll)
545 # define __NR_ppoll -1
547 #define __NR_sys_ppoll __NR_ppoll
548 _syscall5(int, sys_ppoll
, struct pollfd
*, fds
, nfds_t
, nfds
,
549 struct timespec
*, timeout
, const __sigset_t
*, sigmask
,
553 #if defined(TARGET_NR_pselect6)
554 #ifndef __NR_pselect6
555 # define __NR_pselect6 -1
557 #define __NR_sys_pselect6 __NR_pselect6
558 _syscall6(int, sys_pselect6
, int, nfds
, fd_set
*, readfds
, fd_set
*, writefds
,
559 fd_set
*, exceptfds
, struct timespec
*, timeout
, void *, sig
);
562 #if defined(TARGET_NR_prlimit64)
563 #ifndef __NR_prlimit64
564 # define __NR_prlimit64 -1
566 #define __NR_sys_prlimit64 __NR_prlimit64
567 /* The glibc rlimit structure may not be that used by the underlying syscall */
568 struct host_rlimit64
{
572 _syscall4(int, sys_prlimit64
, pid_t
, pid
, int, resource
,
573 const struct host_rlimit64
*, new_limit
,
574 struct host_rlimit64
*, old_limit
)
577 extern int personality(int);
578 extern int flock(int, int);
579 extern int setfsuid(int);
580 extern int setfsgid(int);
581 extern int setgroups(int, gid_t
*);
583 #define ERRNO_TABLE_SIZE 1200
585 /* target_to_host_errno_table[] is initialized from
586 * host_to_target_errno_table[] in syscall_init(). */
587 static uint16_t target_to_host_errno_table
[ERRNO_TABLE_SIZE
] = {
591 * This list is the union of errno values overridden in asm-<arch>/errno.h
592 * minus the errnos that are not actually generic to all archs.
594 static uint16_t host_to_target_errno_table
[ERRNO_TABLE_SIZE
] = {
595 [EIDRM
] = TARGET_EIDRM
,
596 [ECHRNG
] = TARGET_ECHRNG
,
597 [EL2NSYNC
] = TARGET_EL2NSYNC
,
598 [EL3HLT
] = TARGET_EL3HLT
,
599 [EL3RST
] = TARGET_EL3RST
,
600 [ELNRNG
] = TARGET_ELNRNG
,
601 [EUNATCH
] = TARGET_EUNATCH
,
602 [ENOCSI
] = TARGET_ENOCSI
,
603 [EL2HLT
] = TARGET_EL2HLT
,
604 [EDEADLK
] = TARGET_EDEADLK
,
605 [ENOLCK
] = TARGET_ENOLCK
,
606 [EBADE
] = TARGET_EBADE
,
607 [EBADR
] = TARGET_EBADR
,
608 [EXFULL
] = TARGET_EXFULL
,
609 [ENOANO
] = TARGET_ENOANO
,
610 [EBADRQC
] = TARGET_EBADRQC
,
611 [EBADSLT
] = TARGET_EBADSLT
,
612 [EBFONT
] = TARGET_EBFONT
,
613 [ENOSTR
] = TARGET_ENOSTR
,
614 [ENODATA
] = TARGET_ENODATA
,
615 [ETIME
] = TARGET_ETIME
,
616 [ENOSR
] = TARGET_ENOSR
,
617 [ENONET
] = TARGET_ENONET
,
618 [ENOPKG
] = TARGET_ENOPKG
,
619 [EREMOTE
] = TARGET_EREMOTE
,
620 [ENOLINK
] = TARGET_ENOLINK
,
621 [EADV
] = TARGET_EADV
,
622 [ESRMNT
] = TARGET_ESRMNT
,
623 [ECOMM
] = TARGET_ECOMM
,
624 [EPROTO
] = TARGET_EPROTO
,
625 [EDOTDOT
] = TARGET_EDOTDOT
,
626 [EMULTIHOP
] = TARGET_EMULTIHOP
,
627 [EBADMSG
] = TARGET_EBADMSG
,
628 [ENAMETOOLONG
] = TARGET_ENAMETOOLONG
,
629 [EOVERFLOW
] = TARGET_EOVERFLOW
,
630 [ENOTUNIQ
] = TARGET_ENOTUNIQ
,
631 [EBADFD
] = TARGET_EBADFD
,
632 [EREMCHG
] = TARGET_EREMCHG
,
633 [ELIBACC
] = TARGET_ELIBACC
,
634 [ELIBBAD
] = TARGET_ELIBBAD
,
635 [ELIBSCN
] = TARGET_ELIBSCN
,
636 [ELIBMAX
] = TARGET_ELIBMAX
,
637 [ELIBEXEC
] = TARGET_ELIBEXEC
,
638 [EILSEQ
] = TARGET_EILSEQ
,
639 [ENOSYS
] = TARGET_ENOSYS
,
640 [ELOOP
] = TARGET_ELOOP
,
641 [ERESTART
] = TARGET_ERESTART
,
642 [ESTRPIPE
] = TARGET_ESTRPIPE
,
643 [ENOTEMPTY
] = TARGET_ENOTEMPTY
,
644 [EUSERS
] = TARGET_EUSERS
,
645 [ENOTSOCK
] = TARGET_ENOTSOCK
,
646 [EDESTADDRREQ
] = TARGET_EDESTADDRREQ
,
647 [EMSGSIZE
] = TARGET_EMSGSIZE
,
648 [EPROTOTYPE
] = TARGET_EPROTOTYPE
,
649 [ENOPROTOOPT
] = TARGET_ENOPROTOOPT
,
650 [EPROTONOSUPPORT
] = TARGET_EPROTONOSUPPORT
,
651 [ESOCKTNOSUPPORT
] = TARGET_ESOCKTNOSUPPORT
,
652 [EOPNOTSUPP
] = TARGET_EOPNOTSUPP
,
653 [EPFNOSUPPORT
] = TARGET_EPFNOSUPPORT
,
654 [EAFNOSUPPORT
] = TARGET_EAFNOSUPPORT
,
655 [EADDRINUSE
] = TARGET_EADDRINUSE
,
656 [EADDRNOTAVAIL
] = TARGET_EADDRNOTAVAIL
,
657 [ENETDOWN
] = TARGET_ENETDOWN
,
658 [ENETUNREACH
] = TARGET_ENETUNREACH
,
659 [ENETRESET
] = TARGET_ENETRESET
,
660 [ECONNABORTED
] = TARGET_ECONNABORTED
,
661 [ECONNRESET
] = TARGET_ECONNRESET
,
662 [ENOBUFS
] = TARGET_ENOBUFS
,
663 [EISCONN
] = TARGET_EISCONN
,
664 [ENOTCONN
] = TARGET_ENOTCONN
,
665 [EUCLEAN
] = TARGET_EUCLEAN
,
666 [ENOTNAM
] = TARGET_ENOTNAM
,
667 [ENAVAIL
] = TARGET_ENAVAIL
,
668 [EISNAM
] = TARGET_EISNAM
,
669 [EREMOTEIO
] = TARGET_EREMOTEIO
,
670 [ESHUTDOWN
] = TARGET_ESHUTDOWN
,
671 [ETOOMANYREFS
] = TARGET_ETOOMANYREFS
,
672 [ETIMEDOUT
] = TARGET_ETIMEDOUT
,
673 [ECONNREFUSED
] = TARGET_ECONNREFUSED
,
674 [EHOSTDOWN
] = TARGET_EHOSTDOWN
,
675 [EHOSTUNREACH
] = TARGET_EHOSTUNREACH
,
676 [EALREADY
] = TARGET_EALREADY
,
677 [EINPROGRESS
] = TARGET_EINPROGRESS
,
678 [ESTALE
] = TARGET_ESTALE
,
679 [ECANCELED
] = TARGET_ECANCELED
,
680 [ENOMEDIUM
] = TARGET_ENOMEDIUM
,
681 [EMEDIUMTYPE
] = TARGET_EMEDIUMTYPE
,
683 [ENOKEY
] = TARGET_ENOKEY
,
686 [EKEYEXPIRED
] = TARGET_EKEYEXPIRED
,
689 [EKEYREVOKED
] = TARGET_EKEYREVOKED
,
692 [EKEYREJECTED
] = TARGET_EKEYREJECTED
,
695 [EOWNERDEAD
] = TARGET_EOWNERDEAD
,
697 #ifdef ENOTRECOVERABLE
698 [ENOTRECOVERABLE
] = TARGET_ENOTRECOVERABLE
,
702 static inline int host_to_target_errno(int err
)
704 if(host_to_target_errno_table
[err
])
705 return host_to_target_errno_table
[err
];
709 static inline int target_to_host_errno(int err
)
711 if (target_to_host_errno_table
[err
])
712 return target_to_host_errno_table
[err
];
716 static inline abi_long
get_errno(abi_long ret
)
719 return -host_to_target_errno(errno
);
724 static inline int is_error(abi_long ret
)
726 return (abi_ulong
)ret
>= (abi_ulong
)(-4096);
729 char *target_strerror(int err
)
731 return strerror(target_to_host_errno(err
));
734 static abi_ulong target_brk
;
735 static abi_ulong target_original_brk
;
736 static abi_ulong brk_page
;
738 void target_set_brk(abi_ulong new_brk
)
740 target_original_brk
= target_brk
= HOST_PAGE_ALIGN(new_brk
);
741 brk_page
= HOST_PAGE_ALIGN(target_brk
);
744 //#define DEBUGF_BRK(message, args...) do { fprintf(stderr, (message), ## args); } while (0)
745 #define DEBUGF_BRK(message, args...)
747 /* do_brk() must return target values and target errnos. */
748 abi_long
do_brk(abi_ulong new_brk
)
750 abi_long mapped_addr
;
753 DEBUGF_BRK("do_brk(%#010x) -> ", new_brk
);
756 DEBUGF_BRK("%#010x (!new_brk)\n", target_brk
);
759 if (new_brk
< target_original_brk
) {
760 DEBUGF_BRK("%#010x (new_brk < target_original_brk)\n", target_brk
);
764 /* If the new brk is less than the highest page reserved to the
765 * target heap allocation, set it and we're almost done... */
766 if (new_brk
<= brk_page
) {
767 /* Heap contents are initialized to zero, as for anonymous
769 if (new_brk
> target_brk
) {
770 memset(g2h(target_brk
), 0, new_brk
- target_brk
);
772 target_brk
= new_brk
;
773 DEBUGF_BRK("%#010x (new_brk <= brk_page)\n", target_brk
);
777 /* We need to allocate more memory after the brk... Note that
778 * we don't use MAP_FIXED because that will map over the top of
779 * any existing mapping (like the one with the host libc or qemu
780 * itself); instead we treat "mapped but at wrong address" as
781 * a failure and unmap again.
783 new_alloc_size
= HOST_PAGE_ALIGN(new_brk
- brk_page
);
784 mapped_addr
= get_errno(target_mmap(brk_page
, new_alloc_size
,
785 PROT_READ
|PROT_WRITE
,
786 MAP_ANON
|MAP_PRIVATE
, 0, 0));
788 if (mapped_addr
== brk_page
) {
789 target_brk
= new_brk
;
790 brk_page
= HOST_PAGE_ALIGN(target_brk
);
791 DEBUGF_BRK("%#010x (mapped_addr == brk_page)\n", target_brk
);
793 } else if (mapped_addr
!= -1) {
794 /* Mapped but at wrong address, meaning there wasn't actually
795 * enough space for this brk.
797 target_munmap(mapped_addr
, new_alloc_size
);
799 DEBUGF_BRK("%#010x (mapped_addr != -1)\n", target_brk
);
802 DEBUGF_BRK("%#010x (otherwise)\n", target_brk
);
805 #if defined(TARGET_ALPHA)
806 /* We (partially) emulate OSF/1 on Alpha, which requires we
807 return a proper errno, not an unchanged brk value. */
808 return -TARGET_ENOMEM
;
810 /* For everything else, return the previous break. */
814 static inline abi_long
copy_from_user_fdset(fd_set
*fds
,
815 abi_ulong target_fds_addr
,
819 abi_ulong b
, *target_fds
;
821 nw
= (n
+ TARGET_ABI_BITS
- 1) / TARGET_ABI_BITS
;
822 if (!(target_fds
= lock_user(VERIFY_READ
,
824 sizeof(abi_ulong
) * nw
,
826 return -TARGET_EFAULT
;
830 for (i
= 0; i
< nw
; i
++) {
831 /* grab the abi_ulong */
832 __get_user(b
, &target_fds
[i
]);
833 for (j
= 0; j
< TARGET_ABI_BITS
; j
++) {
834 /* check the bit inside the abi_ulong */
841 unlock_user(target_fds
, target_fds_addr
, 0);
846 static inline abi_ulong
copy_from_user_fdset_ptr(fd_set
*fds
, fd_set
**fds_ptr
,
847 abi_ulong target_fds_addr
,
850 if (target_fds_addr
) {
851 if (copy_from_user_fdset(fds
, target_fds_addr
, n
))
852 return -TARGET_EFAULT
;
860 static inline abi_long
copy_to_user_fdset(abi_ulong target_fds_addr
,
866 abi_ulong
*target_fds
;
868 nw
= (n
+ TARGET_ABI_BITS
- 1) / TARGET_ABI_BITS
;
869 if (!(target_fds
= lock_user(VERIFY_WRITE
,
871 sizeof(abi_ulong
) * nw
,
873 return -TARGET_EFAULT
;
876 for (i
= 0; i
< nw
; i
++) {
878 for (j
= 0; j
< TARGET_ABI_BITS
; j
++) {
879 v
|= ((FD_ISSET(k
, fds
) != 0) << j
);
882 __put_user(v
, &target_fds
[i
]);
885 unlock_user(target_fds
, target_fds_addr
, sizeof(abi_ulong
) * nw
);
890 #if defined(__alpha__)
896 static inline abi_long
host_to_target_clock_t(long ticks
)
898 #if HOST_HZ == TARGET_HZ
901 return ((int64_t)ticks
* TARGET_HZ
) / HOST_HZ
;
905 static inline abi_long
host_to_target_rusage(abi_ulong target_addr
,
906 const struct rusage
*rusage
)
908 struct target_rusage
*target_rusage
;
910 if (!lock_user_struct(VERIFY_WRITE
, target_rusage
, target_addr
, 0))
911 return -TARGET_EFAULT
;
912 target_rusage
->ru_utime
.tv_sec
= tswapl(rusage
->ru_utime
.tv_sec
);
913 target_rusage
->ru_utime
.tv_usec
= tswapl(rusage
->ru_utime
.tv_usec
);
914 target_rusage
->ru_stime
.tv_sec
= tswapl(rusage
->ru_stime
.tv_sec
);
915 target_rusage
->ru_stime
.tv_usec
= tswapl(rusage
->ru_stime
.tv_usec
);
916 target_rusage
->ru_maxrss
= tswapl(rusage
->ru_maxrss
);
917 target_rusage
->ru_ixrss
= tswapl(rusage
->ru_ixrss
);
918 target_rusage
->ru_idrss
= tswapl(rusage
->ru_idrss
);
919 target_rusage
->ru_isrss
= tswapl(rusage
->ru_isrss
);
920 target_rusage
->ru_minflt
= tswapl(rusage
->ru_minflt
);
921 target_rusage
->ru_majflt
= tswapl(rusage
->ru_majflt
);
922 target_rusage
->ru_nswap
= tswapl(rusage
->ru_nswap
);
923 target_rusage
->ru_inblock
= tswapl(rusage
->ru_inblock
);
924 target_rusage
->ru_oublock
= tswapl(rusage
->ru_oublock
);
925 target_rusage
->ru_msgsnd
= tswapl(rusage
->ru_msgsnd
);
926 target_rusage
->ru_msgrcv
= tswapl(rusage
->ru_msgrcv
);
927 target_rusage
->ru_nsignals
= tswapl(rusage
->ru_nsignals
);
928 target_rusage
->ru_nvcsw
= tswapl(rusage
->ru_nvcsw
);
929 target_rusage
->ru_nivcsw
= tswapl(rusage
->ru_nivcsw
);
930 unlock_user_struct(target_rusage
, target_addr
, 1);
935 static inline rlim_t
target_to_host_rlim(target_ulong target_rlim
)
937 target_ulong target_rlim_swap
;
940 target_rlim_swap
= tswapl(target_rlim
);
941 if (target_rlim_swap
== TARGET_RLIM_INFINITY
|| target_rlim_swap
!= (rlim_t
)target_rlim_swap
)
942 result
= RLIM_INFINITY
;
944 result
= target_rlim_swap
;
949 static inline target_ulong
host_to_target_rlim(rlim_t rlim
)
951 target_ulong target_rlim_swap
;
954 if (rlim
== RLIM_INFINITY
|| rlim
!= (target_long
)rlim
)
955 target_rlim_swap
= TARGET_RLIM_INFINITY
;
957 target_rlim_swap
= rlim
;
958 result
= tswapl(target_rlim_swap
);
963 static inline int target_to_host_resource(int code
)
966 case TARGET_RLIMIT_AS
:
968 case TARGET_RLIMIT_CORE
:
970 case TARGET_RLIMIT_CPU
:
972 case TARGET_RLIMIT_DATA
:
974 case TARGET_RLIMIT_FSIZE
:
976 case TARGET_RLIMIT_LOCKS
:
978 case TARGET_RLIMIT_MEMLOCK
:
979 return RLIMIT_MEMLOCK
;
980 case TARGET_RLIMIT_MSGQUEUE
:
981 return RLIMIT_MSGQUEUE
;
982 case TARGET_RLIMIT_NICE
:
984 case TARGET_RLIMIT_NOFILE
:
985 return RLIMIT_NOFILE
;
986 case TARGET_RLIMIT_NPROC
:
988 case TARGET_RLIMIT_RSS
:
990 case TARGET_RLIMIT_RTPRIO
:
991 return RLIMIT_RTPRIO
;
992 case TARGET_RLIMIT_SIGPENDING
:
993 return RLIMIT_SIGPENDING
;
994 case TARGET_RLIMIT_STACK
:
1001 static inline abi_long
copy_from_user_timeval(struct timeval
*tv
,
1002 abi_ulong target_tv_addr
)
1004 struct target_timeval
*target_tv
;
1006 if (!lock_user_struct(VERIFY_READ
, target_tv
, target_tv_addr
, 1))
1007 return -TARGET_EFAULT
;
1009 __get_user(tv
->tv_sec
, &target_tv
->tv_sec
);
1010 __get_user(tv
->tv_usec
, &target_tv
->tv_usec
);
1012 unlock_user_struct(target_tv
, target_tv_addr
, 0);
1017 static inline abi_long
copy_to_user_timeval(abi_ulong target_tv_addr
,
1018 const struct timeval
*tv
)
1020 struct target_timeval
*target_tv
;
1022 if (!lock_user_struct(VERIFY_WRITE
, target_tv
, target_tv_addr
, 0))
1023 return -TARGET_EFAULT
;
1025 __put_user(tv
->tv_sec
, &target_tv
->tv_sec
);
1026 __put_user(tv
->tv_usec
, &target_tv
->tv_usec
);
1028 unlock_user_struct(target_tv
, target_tv_addr
, 1);
1033 #if defined(TARGET_NR_mq_open) && defined(__NR_mq_open)
1036 static inline abi_long
copy_from_user_mq_attr(struct mq_attr
*attr
,
1037 abi_ulong target_mq_attr_addr
)
1039 struct target_mq_attr
*target_mq_attr
;
1041 if (!lock_user_struct(VERIFY_READ
, target_mq_attr
,
1042 target_mq_attr_addr
, 1))
1043 return -TARGET_EFAULT
;
1045 __get_user(attr
->mq_flags
, &target_mq_attr
->mq_flags
);
1046 __get_user(attr
->mq_maxmsg
, &target_mq_attr
->mq_maxmsg
);
1047 __get_user(attr
->mq_msgsize
, &target_mq_attr
->mq_msgsize
);
1048 __get_user(attr
->mq_curmsgs
, &target_mq_attr
->mq_curmsgs
);
1050 unlock_user_struct(target_mq_attr
, target_mq_attr_addr
, 0);
1055 static inline abi_long
copy_to_user_mq_attr(abi_ulong target_mq_attr_addr
,
1056 const struct mq_attr
*attr
)
1058 struct target_mq_attr
*target_mq_attr
;
1060 if (!lock_user_struct(VERIFY_WRITE
, target_mq_attr
,
1061 target_mq_attr_addr
, 0))
1062 return -TARGET_EFAULT
;
1064 __put_user(attr
->mq_flags
, &target_mq_attr
->mq_flags
);
1065 __put_user(attr
->mq_maxmsg
, &target_mq_attr
->mq_maxmsg
);
1066 __put_user(attr
->mq_msgsize
, &target_mq_attr
->mq_msgsize
);
1067 __put_user(attr
->mq_curmsgs
, &target_mq_attr
->mq_curmsgs
);
1069 unlock_user_struct(target_mq_attr
, target_mq_attr_addr
, 1);
1075 #if defined(TARGET_NR_select) || defined(TARGET_NR__newselect)
1076 /* do_select() must return target values and target errnos. */
1077 static abi_long
do_select(int n
,
1078 abi_ulong rfd_addr
, abi_ulong wfd_addr
,
1079 abi_ulong efd_addr
, abi_ulong target_tv_addr
)
1081 fd_set rfds
, wfds
, efds
;
1082 fd_set
*rfds_ptr
, *wfds_ptr
, *efds_ptr
;
1083 struct timeval tv
, *tv_ptr
;
1086 ret
= copy_from_user_fdset_ptr(&rfds
, &rfds_ptr
, rfd_addr
, n
);
1090 ret
= copy_from_user_fdset_ptr(&wfds
, &wfds_ptr
, wfd_addr
, n
);
1094 ret
= copy_from_user_fdset_ptr(&efds
, &efds_ptr
, efd_addr
, n
);
1099 if (target_tv_addr
) {
1100 if (copy_from_user_timeval(&tv
, target_tv_addr
))
1101 return -TARGET_EFAULT
;
1107 ret
= get_errno(select(n
, rfds_ptr
, wfds_ptr
, efds_ptr
, tv_ptr
));
1109 if (!is_error(ret
)) {
1110 if (rfd_addr
&& copy_to_user_fdset(rfd_addr
, &rfds
, n
))
1111 return -TARGET_EFAULT
;
1112 if (wfd_addr
&& copy_to_user_fdset(wfd_addr
, &wfds
, n
))
1113 return -TARGET_EFAULT
;
1114 if (efd_addr
&& copy_to_user_fdset(efd_addr
, &efds
, n
))
1115 return -TARGET_EFAULT
;
1117 if (target_tv_addr
&& copy_to_user_timeval(target_tv_addr
, &tv
))
1118 return -TARGET_EFAULT
;
1125 static abi_long
do_pipe2(int host_pipe
[], int flags
)
1128 return pipe2(host_pipe
, flags
);
1134 static abi_long
do_pipe(void *cpu_env
, abi_ulong pipedes
,
1135 int flags
, int is_pipe2
)
1139 ret
= flags
? do_pipe2(host_pipe
, flags
) : pipe(host_pipe
);
1142 return get_errno(ret
);
1144 /* Several targets have special calling conventions for the original
1145 pipe syscall, but didn't replicate this into the pipe2 syscall. */
1147 #if defined(TARGET_ALPHA)
1148 ((CPUAlphaState
*)cpu_env
)->ir
[IR_A4
] = host_pipe
[1];
1149 return host_pipe
[0];
1150 #elif defined(TARGET_MIPS)
1151 ((CPUMIPSState
*)cpu_env
)->active_tc
.gpr
[3] = host_pipe
[1];
1152 return host_pipe
[0];
1153 #elif defined(TARGET_SH4)
1154 ((CPUSH4State
*)cpu_env
)->gregs
[1] = host_pipe
[1];
1155 return host_pipe
[0];
1159 if (put_user_s32(host_pipe
[0], pipedes
)
1160 || put_user_s32(host_pipe
[1], pipedes
+ sizeof(host_pipe
[0])))
1161 return -TARGET_EFAULT
;
1162 return get_errno(ret
);
1165 static inline abi_long
target_to_host_ip_mreq(struct ip_mreqn
*mreqn
,
1166 abi_ulong target_addr
,
1169 struct target_ip_mreqn
*target_smreqn
;
1171 target_smreqn
= lock_user(VERIFY_READ
, target_addr
, len
, 1);
1173 return -TARGET_EFAULT
;
1174 mreqn
->imr_multiaddr
.s_addr
= target_smreqn
->imr_multiaddr
.s_addr
;
1175 mreqn
->imr_address
.s_addr
= target_smreqn
->imr_address
.s_addr
;
1176 if (len
== sizeof(struct target_ip_mreqn
))
1177 mreqn
->imr_ifindex
= tswapl(target_smreqn
->imr_ifindex
);
1178 unlock_user(target_smreqn
, target_addr
, 0);
1183 static inline abi_long
target_to_host_sockaddr(struct sockaddr
*addr
,
1184 abi_ulong target_addr
,
1187 const socklen_t unix_maxlen
= sizeof (struct sockaddr_un
);
1188 sa_family_t sa_family
;
1189 struct target_sockaddr
*target_saddr
;
1191 target_saddr
= lock_user(VERIFY_READ
, target_addr
, len
, 1);
1193 return -TARGET_EFAULT
;
1195 sa_family
= tswap16(target_saddr
->sa_family
);
1197 /* Oops. The caller might send a incomplete sun_path; sun_path
1198 * must be terminated by \0 (see the manual page), but
1199 * unfortunately it is quite common to specify sockaddr_un
1200 * length as "strlen(x->sun_path)" while it should be
1201 * "strlen(...) + 1". We'll fix that here if needed.
1202 * Linux kernel has a similar feature.
1205 if (sa_family
== AF_UNIX
) {
1206 if (len
< unix_maxlen
&& len
> 0) {
1207 char *cp
= (char*)target_saddr
;
1209 if ( cp
[len
-1] && !cp
[len
] )
1212 if (len
> unix_maxlen
)
1216 memcpy(addr
, target_saddr
, len
);
1217 addr
->sa_family
= sa_family
;
1218 unlock_user(target_saddr
, target_addr
, 0);
1223 static inline abi_long
host_to_target_sockaddr(abi_ulong target_addr
,
1224 struct sockaddr
*addr
,
1227 struct target_sockaddr
*target_saddr
;
1229 target_saddr
= lock_user(VERIFY_WRITE
, target_addr
, len
, 0);
1231 return -TARGET_EFAULT
;
1232 memcpy(target_saddr
, addr
, len
);
1233 target_saddr
->sa_family
= tswap16(addr
->sa_family
);
1234 unlock_user(target_saddr
, target_addr
, len
);
1239 /* ??? Should this also swap msgh->name? */
1240 static inline abi_long
target_to_host_cmsg(struct msghdr
*msgh
,
1241 struct target_msghdr
*target_msgh
)
1243 struct cmsghdr
*cmsg
= CMSG_FIRSTHDR(msgh
);
1244 abi_long msg_controllen
;
1245 abi_ulong target_cmsg_addr
;
1246 struct target_cmsghdr
*target_cmsg
;
1247 socklen_t space
= 0;
1249 msg_controllen
= tswapl(target_msgh
->msg_controllen
);
1250 if (msg_controllen
< sizeof (struct target_cmsghdr
))
1252 target_cmsg_addr
= tswapl(target_msgh
->msg_control
);
1253 target_cmsg
= lock_user(VERIFY_READ
, target_cmsg_addr
, msg_controllen
, 1);
1255 return -TARGET_EFAULT
;
1257 while (cmsg
&& target_cmsg
) {
1258 void *data
= CMSG_DATA(cmsg
);
1259 void *target_data
= TARGET_CMSG_DATA(target_cmsg
);
1261 int len
= tswapl(target_cmsg
->cmsg_len
)
1262 - TARGET_CMSG_ALIGN(sizeof (struct target_cmsghdr
));
1264 space
+= CMSG_SPACE(len
);
1265 if (space
> msgh
->msg_controllen
) {
1266 space
-= CMSG_SPACE(len
);
1267 gemu_log("Host cmsg overflow\n");
1271 cmsg
->cmsg_level
= tswap32(target_cmsg
->cmsg_level
);
1272 cmsg
->cmsg_type
= tswap32(target_cmsg
->cmsg_type
);
1273 cmsg
->cmsg_len
= CMSG_LEN(len
);
1275 if (cmsg
->cmsg_level
!= TARGET_SOL_SOCKET
|| cmsg
->cmsg_type
!= SCM_RIGHTS
) {
1276 gemu_log("Unsupported ancillary data: %d/%d\n", cmsg
->cmsg_level
, cmsg
->cmsg_type
);
1277 memcpy(data
, target_data
, len
);
1279 int *fd
= (int *)data
;
1280 int *target_fd
= (int *)target_data
;
1281 int i
, numfds
= len
/ sizeof(int);
1283 for (i
= 0; i
< numfds
; i
++)
1284 fd
[i
] = tswap32(target_fd
[i
]);
1287 cmsg
= CMSG_NXTHDR(msgh
, cmsg
);
1288 target_cmsg
= TARGET_CMSG_NXTHDR(target_msgh
, target_cmsg
);
1290 unlock_user(target_cmsg
, target_cmsg_addr
, 0);
1292 msgh
->msg_controllen
= space
;
1296 /* ??? Should this also swap msgh->name? */
1297 static inline abi_long
host_to_target_cmsg(struct target_msghdr
*target_msgh
,
1298 struct msghdr
*msgh
)
1300 struct cmsghdr
*cmsg
= CMSG_FIRSTHDR(msgh
);
1301 abi_long msg_controllen
;
1302 abi_ulong target_cmsg_addr
;
1303 struct target_cmsghdr
*target_cmsg
;
1304 socklen_t space
= 0;
1306 msg_controllen
= tswapl(target_msgh
->msg_controllen
);
1307 if (msg_controllen
< sizeof (struct target_cmsghdr
))
1309 target_cmsg_addr
= tswapl(target_msgh
->msg_control
);
1310 target_cmsg
= lock_user(VERIFY_WRITE
, target_cmsg_addr
, msg_controllen
, 0);
1312 return -TARGET_EFAULT
;
1314 while (cmsg
&& target_cmsg
) {
1315 void *data
= CMSG_DATA(cmsg
);
1316 void *target_data
= TARGET_CMSG_DATA(target_cmsg
);
1318 int len
= cmsg
->cmsg_len
- CMSG_ALIGN(sizeof (struct cmsghdr
));
1320 space
+= TARGET_CMSG_SPACE(len
);
1321 if (space
> msg_controllen
) {
1322 space
-= TARGET_CMSG_SPACE(len
);
1323 gemu_log("Target cmsg overflow\n");
1327 target_cmsg
->cmsg_level
= tswap32(cmsg
->cmsg_level
);
1328 target_cmsg
->cmsg_type
= tswap32(cmsg
->cmsg_type
);
1329 target_cmsg
->cmsg_len
= tswapl(TARGET_CMSG_LEN(len
));
1331 if (cmsg
->cmsg_level
!= TARGET_SOL_SOCKET
|| cmsg
->cmsg_type
!= SCM_RIGHTS
) {
1332 gemu_log("Unsupported ancillary data: %d/%d\n", cmsg
->cmsg_level
, cmsg
->cmsg_type
);
1333 memcpy(target_data
, data
, len
);
1335 int *fd
= (int *)data
;
1336 int *target_fd
= (int *)target_data
;
1337 int i
, numfds
= len
/ sizeof(int);
1339 for (i
= 0; i
< numfds
; i
++)
1340 target_fd
[i
] = tswap32(fd
[i
]);
1343 cmsg
= CMSG_NXTHDR(msgh
, cmsg
);
1344 target_cmsg
= TARGET_CMSG_NXTHDR(target_msgh
, target_cmsg
);
1346 unlock_user(target_cmsg
, target_cmsg_addr
, space
);
1348 target_msgh
->msg_controllen
= tswapl(space
);
1352 /* do_setsockopt() Must return target values and target errnos. */
1353 static abi_long
do_setsockopt(int sockfd
, int level
, int optname
,
1354 abi_ulong optval_addr
, socklen_t optlen
)
1358 struct ip_mreqn
*ip_mreq
;
1359 struct ip_mreq_source
*ip_mreq_source
;
1363 /* TCP options all take an 'int' value. */
1364 if (optlen
< sizeof(uint32_t))
1365 return -TARGET_EINVAL
;
1367 if (get_user_u32(val
, optval_addr
))
1368 return -TARGET_EFAULT
;
1369 ret
= get_errno(setsockopt(sockfd
, level
, optname
, &val
, sizeof(val
)));
1376 case IP_ROUTER_ALERT
:
1380 case IP_MTU_DISCOVER
:
1386 case IP_MULTICAST_TTL
:
1387 case IP_MULTICAST_LOOP
:
1389 if (optlen
>= sizeof(uint32_t)) {
1390 if (get_user_u32(val
, optval_addr
))
1391 return -TARGET_EFAULT
;
1392 } else if (optlen
>= 1) {
1393 if (get_user_u8(val
, optval_addr
))
1394 return -TARGET_EFAULT
;
1396 ret
= get_errno(setsockopt(sockfd
, level
, optname
, &val
, sizeof(val
)));
1398 case IP_ADD_MEMBERSHIP
:
1399 case IP_DROP_MEMBERSHIP
:
1400 if (optlen
< sizeof (struct target_ip_mreq
) ||
1401 optlen
> sizeof (struct target_ip_mreqn
))
1402 return -TARGET_EINVAL
;
1404 ip_mreq
= (struct ip_mreqn
*) alloca(optlen
);
1405 target_to_host_ip_mreq(ip_mreq
, optval_addr
, optlen
);
1406 ret
= get_errno(setsockopt(sockfd
, level
, optname
, ip_mreq
, optlen
));
1409 case IP_BLOCK_SOURCE
:
1410 case IP_UNBLOCK_SOURCE
:
1411 case IP_ADD_SOURCE_MEMBERSHIP
:
1412 case IP_DROP_SOURCE_MEMBERSHIP
:
1413 if (optlen
!= sizeof (struct target_ip_mreq_source
))
1414 return -TARGET_EINVAL
;
1416 ip_mreq_source
= lock_user(VERIFY_READ
, optval_addr
, optlen
, 1);
1417 ret
= get_errno(setsockopt(sockfd
, level
, optname
, ip_mreq_source
, optlen
));
1418 unlock_user (ip_mreq_source
, optval_addr
, 0);
1425 case TARGET_SOL_SOCKET
:
1427 /* Options with 'int' argument. */
1428 case TARGET_SO_DEBUG
:
1431 case TARGET_SO_REUSEADDR
:
1432 optname
= SO_REUSEADDR
;
1434 case TARGET_SO_TYPE
:
1437 case TARGET_SO_ERROR
:
1440 case TARGET_SO_DONTROUTE
:
1441 optname
= SO_DONTROUTE
;
1443 case TARGET_SO_BROADCAST
:
1444 optname
= SO_BROADCAST
;
1446 case TARGET_SO_SNDBUF
:
1447 optname
= SO_SNDBUF
;
1449 case TARGET_SO_RCVBUF
:
1450 optname
= SO_RCVBUF
;
1452 case TARGET_SO_KEEPALIVE
:
1453 optname
= SO_KEEPALIVE
;
1455 case TARGET_SO_OOBINLINE
:
1456 optname
= SO_OOBINLINE
;
1458 case TARGET_SO_NO_CHECK
:
1459 optname
= SO_NO_CHECK
;
1461 case TARGET_SO_PRIORITY
:
1462 optname
= SO_PRIORITY
;
1465 case TARGET_SO_BSDCOMPAT
:
1466 optname
= SO_BSDCOMPAT
;
1469 case TARGET_SO_PASSCRED
:
1470 optname
= SO_PASSCRED
;
1472 case TARGET_SO_TIMESTAMP
:
1473 optname
= SO_TIMESTAMP
;
1475 case TARGET_SO_RCVLOWAT
:
1476 optname
= SO_RCVLOWAT
;
1478 case TARGET_SO_RCVTIMEO
:
1479 optname
= SO_RCVTIMEO
;
1481 case TARGET_SO_SNDTIMEO
:
1482 optname
= SO_SNDTIMEO
;
1488 if (optlen
< sizeof(uint32_t))
1489 return -TARGET_EINVAL
;
1491 if (get_user_u32(val
, optval_addr
))
1492 return -TARGET_EFAULT
;
1493 ret
= get_errno(setsockopt(sockfd
, SOL_SOCKET
, optname
, &val
, sizeof(val
)));
1497 gemu_log("Unsupported setsockopt level=%d optname=%d \n", level
, optname
);
1498 ret
= -TARGET_ENOPROTOOPT
;
1503 /* do_getsockopt() Must return target values and target errnos. */
1504 static abi_long
do_getsockopt(int sockfd
, int level
, int optname
,
1505 abi_ulong optval_addr
, abi_ulong optlen
)
1512 case TARGET_SOL_SOCKET
:
1515 /* These don't just return a single integer */
1516 case TARGET_SO_LINGER
:
1517 case TARGET_SO_RCVTIMEO
:
1518 case TARGET_SO_SNDTIMEO
:
1519 case TARGET_SO_PEERCRED
:
1520 case TARGET_SO_PEERNAME
:
1522 /* Options with 'int' argument. */
1523 case TARGET_SO_DEBUG
:
1526 case TARGET_SO_REUSEADDR
:
1527 optname
= SO_REUSEADDR
;
1529 case TARGET_SO_TYPE
:
1532 case TARGET_SO_ERROR
:
1535 case TARGET_SO_DONTROUTE
:
1536 optname
= SO_DONTROUTE
;
1538 case TARGET_SO_BROADCAST
:
1539 optname
= SO_BROADCAST
;
1541 case TARGET_SO_SNDBUF
:
1542 optname
= SO_SNDBUF
;
1544 case TARGET_SO_RCVBUF
:
1545 optname
= SO_RCVBUF
;
1547 case TARGET_SO_KEEPALIVE
:
1548 optname
= SO_KEEPALIVE
;
1550 case TARGET_SO_OOBINLINE
:
1551 optname
= SO_OOBINLINE
;
1553 case TARGET_SO_NO_CHECK
:
1554 optname
= SO_NO_CHECK
;
1556 case TARGET_SO_PRIORITY
:
1557 optname
= SO_PRIORITY
;
1560 case TARGET_SO_BSDCOMPAT
:
1561 optname
= SO_BSDCOMPAT
;
1564 case TARGET_SO_PASSCRED
:
1565 optname
= SO_PASSCRED
;
1567 case TARGET_SO_TIMESTAMP
:
1568 optname
= SO_TIMESTAMP
;
1570 case TARGET_SO_RCVLOWAT
:
1571 optname
= SO_RCVLOWAT
;
1578 /* TCP options all take an 'int' value. */
1580 if (get_user_u32(len
, optlen
))
1581 return -TARGET_EFAULT
;
1583 return -TARGET_EINVAL
;
1585 ret
= get_errno(getsockopt(sockfd
, level
, optname
, &val
, &lv
));
1591 if (put_user_u32(val
, optval_addr
))
1592 return -TARGET_EFAULT
;
1594 if (put_user_u8(val
, optval_addr
))
1595 return -TARGET_EFAULT
;
1597 if (put_user_u32(len
, optlen
))
1598 return -TARGET_EFAULT
;
1605 case IP_ROUTER_ALERT
:
1609 case IP_MTU_DISCOVER
:
1615 case IP_MULTICAST_TTL
:
1616 case IP_MULTICAST_LOOP
:
1617 if (get_user_u32(len
, optlen
))
1618 return -TARGET_EFAULT
;
1620 return -TARGET_EINVAL
;
1622 ret
= get_errno(getsockopt(sockfd
, level
, optname
, &val
, &lv
));
1625 if (len
< sizeof(int) && len
> 0 && val
>= 0 && val
< 255) {
1627 if (put_user_u32(len
, optlen
)
1628 || put_user_u8(val
, optval_addr
))
1629 return -TARGET_EFAULT
;
1631 if (len
> sizeof(int))
1633 if (put_user_u32(len
, optlen
)
1634 || put_user_u32(val
, optval_addr
))
1635 return -TARGET_EFAULT
;
1639 ret
= -TARGET_ENOPROTOOPT
;
1645 gemu_log("getsockopt level=%d optname=%d not yet supported\n",
1647 ret
= -TARGET_EOPNOTSUPP
;
1654 * lock_iovec()/unlock_iovec() have a return code of 0 for success where
1655 * other lock functions have a return code of 0 for failure.
1657 static abi_long
lock_iovec(int type
, struct iovec
*vec
, abi_ulong target_addr
,
1658 int count
, int copy
)
1660 struct target_iovec
*target_vec
;
1664 target_vec
= lock_user(VERIFY_READ
, target_addr
, count
* sizeof(struct target_iovec
), 1);
1666 return -TARGET_EFAULT
;
1667 for(i
= 0;i
< count
; i
++) {
1668 base
= tswapl(target_vec
[i
].iov_base
);
1669 vec
[i
].iov_len
= tswapl(target_vec
[i
].iov_len
);
1670 if (vec
[i
].iov_len
!= 0) {
1671 vec
[i
].iov_base
= lock_user(type
, base
, vec
[i
].iov_len
, copy
);
1672 /* Don't check lock_user return value. We must call writev even
1673 if a element has invalid base address. */
1675 /* zero length pointer is ignored */
1676 vec
[i
].iov_base
= NULL
;
1679 unlock_user (target_vec
, target_addr
, 0);
1683 static abi_long
unlock_iovec(struct iovec
*vec
, abi_ulong target_addr
,
1684 int count
, int copy
)
1686 struct target_iovec
*target_vec
;
1690 target_vec
= lock_user(VERIFY_READ
, target_addr
, count
* sizeof(struct target_iovec
), 1);
1692 return -TARGET_EFAULT
;
1693 for(i
= 0;i
< count
; i
++) {
1694 if (target_vec
[i
].iov_base
) {
1695 base
= tswapl(target_vec
[i
].iov_base
);
1696 unlock_user(vec
[i
].iov_base
, base
, copy
? vec
[i
].iov_len
: 0);
1699 unlock_user (target_vec
, target_addr
, 0);
1704 /* do_socket() Must return target values and target errnos. */
1705 static abi_long
do_socket(int domain
, int type
, int protocol
)
1707 #if defined(TARGET_MIPS)
1709 case TARGET_SOCK_DGRAM
:
1712 case TARGET_SOCK_STREAM
:
1715 case TARGET_SOCK_RAW
:
1718 case TARGET_SOCK_RDM
:
1721 case TARGET_SOCK_SEQPACKET
:
1722 type
= SOCK_SEQPACKET
;
1724 case TARGET_SOCK_PACKET
:
1729 if (domain
== PF_NETLINK
)
1730 return -EAFNOSUPPORT
; /* do not NETLINK socket connections possible */
1731 return get_errno(socket(domain
, type
, protocol
));
1734 /* do_bind() Must return target values and target errnos. */
1735 static abi_long
do_bind(int sockfd
, abi_ulong target_addr
,
1741 if ((int)addrlen
< 0) {
1742 return -TARGET_EINVAL
;
1745 addr
= alloca(addrlen
+1);
1747 ret
= target_to_host_sockaddr(addr
, target_addr
, addrlen
);
1751 return get_errno(bind(sockfd
, addr
, addrlen
));
1754 /* do_connect() Must return target values and target errnos. */
1755 static abi_long
do_connect(int sockfd
, abi_ulong target_addr
,
1761 if ((int)addrlen
< 0) {
1762 return -TARGET_EINVAL
;
1765 addr
= alloca(addrlen
);
1767 ret
= target_to_host_sockaddr(addr
, target_addr
, addrlen
);
1771 return get_errno(connect(sockfd
, addr
, addrlen
));
1774 /* do_sendrecvmsg() Must return target values and target errnos. */
1775 static abi_long
do_sendrecvmsg(int fd
, abi_ulong target_msg
,
1776 int flags
, int send
)
1779 struct target_msghdr
*msgp
;
1783 abi_ulong target_vec
;
1786 if (!lock_user_struct(send
? VERIFY_READ
: VERIFY_WRITE
,
1790 return -TARGET_EFAULT
;
1791 if (msgp
->msg_name
) {
1792 msg
.msg_namelen
= tswap32(msgp
->msg_namelen
);
1793 msg
.msg_name
= alloca(msg
.msg_namelen
);
1794 ret
= target_to_host_sockaddr(msg
.msg_name
, tswapl(msgp
->msg_name
),
1797 unlock_user_struct(msgp
, target_msg
, send
? 0 : 1);
1801 msg
.msg_name
= NULL
;
1802 msg
.msg_namelen
= 0;
1804 msg
.msg_controllen
= 2 * tswapl(msgp
->msg_controllen
);
1805 msg
.msg_control
= alloca(msg
.msg_controllen
);
1806 msg
.msg_flags
= tswap32(msgp
->msg_flags
);
1808 count
= tswapl(msgp
->msg_iovlen
);
1809 vec
= alloca(count
* sizeof(struct iovec
));
1810 target_vec
= tswapl(msgp
->msg_iov
);
1811 lock_iovec(send
? VERIFY_READ
: VERIFY_WRITE
, vec
, target_vec
, count
, send
);
1812 msg
.msg_iovlen
= count
;
1816 ret
= target_to_host_cmsg(&msg
, msgp
);
1818 ret
= get_errno(sendmsg(fd
, &msg
, flags
));
1820 ret
= get_errno(recvmsg(fd
, &msg
, flags
));
1821 if (!is_error(ret
)) {
1823 ret
= host_to_target_cmsg(msgp
, &msg
);
1828 unlock_iovec(vec
, target_vec
, count
, !send
);
1829 unlock_user_struct(msgp
, target_msg
, send
? 0 : 1);
1833 /* do_accept() Must return target values and target errnos. */
1834 static abi_long
do_accept(int fd
, abi_ulong target_addr
,
1835 abi_ulong target_addrlen_addr
)
1841 if (target_addr
== 0)
1842 return get_errno(accept(fd
, NULL
, NULL
));
1844 /* linux returns EINVAL if addrlen pointer is invalid */
1845 if (get_user_u32(addrlen
, target_addrlen_addr
))
1846 return -TARGET_EINVAL
;
1848 if ((int)addrlen
< 0) {
1849 return -TARGET_EINVAL
;
1852 if (!access_ok(VERIFY_WRITE
, target_addr
, addrlen
))
1853 return -TARGET_EINVAL
;
1855 addr
= alloca(addrlen
);
1857 ret
= get_errno(accept(fd
, addr
, &addrlen
));
1858 if (!is_error(ret
)) {
1859 host_to_target_sockaddr(target_addr
, addr
, addrlen
);
1860 if (put_user_u32(addrlen
, target_addrlen_addr
))
1861 ret
= -TARGET_EFAULT
;
1866 /* do_getpeername() Must return target values and target errnos. */
1867 static abi_long
do_getpeername(int fd
, abi_ulong target_addr
,
1868 abi_ulong target_addrlen_addr
)
1874 if (get_user_u32(addrlen
, target_addrlen_addr
))
1875 return -TARGET_EFAULT
;
1877 if ((int)addrlen
< 0) {
1878 return -TARGET_EINVAL
;
1881 if (!access_ok(VERIFY_WRITE
, target_addr
, addrlen
))
1882 return -TARGET_EFAULT
;
1884 addr
= alloca(addrlen
);
1886 ret
= get_errno(getpeername(fd
, addr
, &addrlen
));
1887 if (!is_error(ret
)) {
1888 host_to_target_sockaddr(target_addr
, addr
, addrlen
);
1889 if (put_user_u32(addrlen
, target_addrlen_addr
))
1890 ret
= -TARGET_EFAULT
;
1895 /* do_getsockname() Must return target values and target errnos. */
1896 static abi_long
do_getsockname(int fd
, abi_ulong target_addr
,
1897 abi_ulong target_addrlen_addr
)
1903 if (get_user_u32(addrlen
, target_addrlen_addr
))
1904 return -TARGET_EFAULT
;
1906 if ((int)addrlen
< 0) {
1907 return -TARGET_EINVAL
;
1910 if (!access_ok(VERIFY_WRITE
, target_addr
, addrlen
))
1911 return -TARGET_EFAULT
;
1913 addr
= alloca(addrlen
);
1915 ret
= get_errno(getsockname(fd
, addr
, &addrlen
));
1916 if (!is_error(ret
)) {
1917 host_to_target_sockaddr(target_addr
, addr
, addrlen
);
1918 if (put_user_u32(addrlen
, target_addrlen_addr
))
1919 ret
= -TARGET_EFAULT
;
1924 /* do_socketpair() Must return target values and target errnos. */
1925 static abi_long
do_socketpair(int domain
, int type
, int protocol
,
1926 abi_ulong target_tab_addr
)
1931 ret
= get_errno(socketpair(domain
, type
, protocol
, tab
));
1932 if (!is_error(ret
)) {
1933 if (put_user_s32(tab
[0], target_tab_addr
)
1934 || put_user_s32(tab
[1], target_tab_addr
+ sizeof(tab
[0])))
1935 ret
= -TARGET_EFAULT
;
1940 /* do_sendto() Must return target values and target errnos. */
1941 static abi_long
do_sendto(int fd
, abi_ulong msg
, size_t len
, int flags
,
1942 abi_ulong target_addr
, socklen_t addrlen
)
1948 if ((int)addrlen
< 0) {
1949 return -TARGET_EINVAL
;
1952 host_msg
= lock_user(VERIFY_READ
, msg
, len
, 1);
1954 return -TARGET_EFAULT
;
1956 addr
= alloca(addrlen
);
1957 ret
= target_to_host_sockaddr(addr
, target_addr
, addrlen
);
1959 unlock_user(host_msg
, msg
, 0);
1962 ret
= get_errno(sendto(fd
, host_msg
, len
, flags
, addr
, addrlen
));
1964 ret
= get_errno(send(fd
, host_msg
, len
, flags
));
1966 unlock_user(host_msg
, msg
, 0);
1970 /* do_recvfrom() Must return target values and target errnos. */
1971 static abi_long
do_recvfrom(int fd
, abi_ulong msg
, size_t len
, int flags
,
1972 abi_ulong target_addr
,
1973 abi_ulong target_addrlen
)
1980 host_msg
= lock_user(VERIFY_WRITE
, msg
, len
, 0);
1982 return -TARGET_EFAULT
;
1984 if (get_user_u32(addrlen
, target_addrlen
)) {
1985 ret
= -TARGET_EFAULT
;
1988 if ((int)addrlen
< 0) {
1989 ret
= -TARGET_EINVAL
;
1992 addr
= alloca(addrlen
);
1993 ret
= get_errno(recvfrom(fd
, host_msg
, len
, flags
, addr
, &addrlen
));
1995 addr
= NULL
; /* To keep compiler quiet. */
1996 ret
= get_errno(recv(fd
, host_msg
, len
, flags
));
1998 if (!is_error(ret
)) {
2000 host_to_target_sockaddr(target_addr
, addr
, addrlen
);
2001 if (put_user_u32(addrlen
, target_addrlen
)) {
2002 ret
= -TARGET_EFAULT
;
2006 unlock_user(host_msg
, msg
, len
);
2009 unlock_user(host_msg
, msg
, 0);
2014 #ifdef TARGET_NR_socketcall
2015 /* do_socketcall() Must return target values and target errnos. */
2016 static abi_long
do_socketcall(int num
, abi_ulong vptr
)
2019 const int n
= sizeof(abi_ulong
);
2024 abi_ulong domain
, type
, protocol
;
2026 if (get_user_ual(domain
, vptr
)
2027 || get_user_ual(type
, vptr
+ n
)
2028 || get_user_ual(protocol
, vptr
+ 2 * n
))
2029 return -TARGET_EFAULT
;
2031 ret
= do_socket(domain
, type
, protocol
);
2037 abi_ulong target_addr
;
2040 if (get_user_ual(sockfd
, vptr
)
2041 || get_user_ual(target_addr
, vptr
+ n
)
2042 || get_user_ual(addrlen
, vptr
+ 2 * n
))
2043 return -TARGET_EFAULT
;
2045 ret
= do_bind(sockfd
, target_addr
, addrlen
);
2048 case SOCKOP_connect
:
2051 abi_ulong target_addr
;
2054 if (get_user_ual(sockfd
, vptr
)
2055 || get_user_ual(target_addr
, vptr
+ n
)
2056 || get_user_ual(addrlen
, vptr
+ 2 * n
))
2057 return -TARGET_EFAULT
;
2059 ret
= do_connect(sockfd
, target_addr
, addrlen
);
2064 abi_ulong sockfd
, backlog
;
2066 if (get_user_ual(sockfd
, vptr
)
2067 || get_user_ual(backlog
, vptr
+ n
))
2068 return -TARGET_EFAULT
;
2070 ret
= get_errno(listen(sockfd
, backlog
));
2076 abi_ulong target_addr
, target_addrlen
;
2078 if (get_user_ual(sockfd
, vptr
)
2079 || get_user_ual(target_addr
, vptr
+ n
)
2080 || get_user_ual(target_addrlen
, vptr
+ 2 * n
))
2081 return -TARGET_EFAULT
;
2083 ret
= do_accept(sockfd
, target_addr
, target_addrlen
);
2086 case SOCKOP_getsockname
:
2089 abi_ulong target_addr
, target_addrlen
;
2091 if (get_user_ual(sockfd
, vptr
)
2092 || get_user_ual(target_addr
, vptr
+ n
)
2093 || get_user_ual(target_addrlen
, vptr
+ 2 * n
))
2094 return -TARGET_EFAULT
;
2096 ret
= do_getsockname(sockfd
, target_addr
, target_addrlen
);
2099 case SOCKOP_getpeername
:
2102 abi_ulong target_addr
, target_addrlen
;
2104 if (get_user_ual(sockfd
, vptr
)
2105 || get_user_ual(target_addr
, vptr
+ n
)
2106 || get_user_ual(target_addrlen
, vptr
+ 2 * n
))
2107 return -TARGET_EFAULT
;
2109 ret
= do_getpeername(sockfd
, target_addr
, target_addrlen
);
2112 case SOCKOP_socketpair
:
2114 abi_ulong domain
, type
, protocol
;
2117 if (get_user_ual(domain
, vptr
)
2118 || get_user_ual(type
, vptr
+ n
)
2119 || get_user_ual(protocol
, vptr
+ 2 * n
)
2120 || get_user_ual(tab
, vptr
+ 3 * n
))
2121 return -TARGET_EFAULT
;
2123 ret
= do_socketpair(domain
, type
, protocol
, tab
);
2133 if (get_user_ual(sockfd
, vptr
)
2134 || get_user_ual(msg
, vptr
+ n
)
2135 || get_user_ual(len
, vptr
+ 2 * n
)
2136 || get_user_ual(flags
, vptr
+ 3 * n
))
2137 return -TARGET_EFAULT
;
2139 ret
= do_sendto(sockfd
, msg
, len
, flags
, 0, 0);
2149 if (get_user_ual(sockfd
, vptr
)
2150 || get_user_ual(msg
, vptr
+ n
)
2151 || get_user_ual(len
, vptr
+ 2 * n
)
2152 || get_user_ual(flags
, vptr
+ 3 * n
))
2153 return -TARGET_EFAULT
;
2155 ret
= do_recvfrom(sockfd
, msg
, len
, flags
, 0, 0);
2167 if (get_user_ual(sockfd
, vptr
)
2168 || get_user_ual(msg
, vptr
+ n
)
2169 || get_user_ual(len
, vptr
+ 2 * n
)
2170 || get_user_ual(flags
, vptr
+ 3 * n
)
2171 || get_user_ual(addr
, vptr
+ 4 * n
)
2172 || get_user_ual(addrlen
, vptr
+ 5 * n
))
2173 return -TARGET_EFAULT
;
2175 ret
= do_sendto(sockfd
, msg
, len
, flags
, addr
, addrlen
);
2178 case SOCKOP_recvfrom
:
2187 if (get_user_ual(sockfd
, vptr
)
2188 || get_user_ual(msg
, vptr
+ n
)
2189 || get_user_ual(len
, vptr
+ 2 * n
)
2190 || get_user_ual(flags
, vptr
+ 3 * n
)
2191 || get_user_ual(addr
, vptr
+ 4 * n
)
2192 || get_user_ual(addrlen
, vptr
+ 5 * n
))
2193 return -TARGET_EFAULT
;
2195 ret
= do_recvfrom(sockfd
, msg
, len
, flags
, addr
, addrlen
);
2198 case SOCKOP_shutdown
:
2200 abi_ulong sockfd
, how
;
2202 if (get_user_ual(sockfd
, vptr
)
2203 || get_user_ual(how
, vptr
+ n
))
2204 return -TARGET_EFAULT
;
2206 ret
= get_errno(shutdown(sockfd
, how
));
2209 case SOCKOP_sendmsg
:
2210 case SOCKOP_recvmsg
:
2213 abi_ulong target_msg
;
2216 if (get_user_ual(fd
, vptr
)
2217 || get_user_ual(target_msg
, vptr
+ n
)
2218 || get_user_ual(flags
, vptr
+ 2 * n
))
2219 return -TARGET_EFAULT
;
2221 ret
= do_sendrecvmsg(fd
, target_msg
, flags
,
2222 (num
== SOCKOP_sendmsg
));
2225 case SOCKOP_setsockopt
:
2233 if (get_user_ual(sockfd
, vptr
)
2234 || get_user_ual(level
, vptr
+ n
)
2235 || get_user_ual(optname
, vptr
+ 2 * n
)
2236 || get_user_ual(optval
, vptr
+ 3 * n
)
2237 || get_user_ual(optlen
, vptr
+ 4 * n
))
2238 return -TARGET_EFAULT
;
2240 ret
= do_setsockopt(sockfd
, level
, optname
, optval
, optlen
);
2243 case SOCKOP_getsockopt
:
2251 if (get_user_ual(sockfd
, vptr
)
2252 || get_user_ual(level
, vptr
+ n
)
2253 || get_user_ual(optname
, vptr
+ 2 * n
)
2254 || get_user_ual(optval
, vptr
+ 3 * n
)
2255 || get_user_ual(optlen
, vptr
+ 4 * n
))
2256 return -TARGET_EFAULT
;
2258 ret
= do_getsockopt(sockfd
, level
, optname
, optval
, optlen
);
2262 gemu_log("Unsupported socketcall: %d\n", num
);
2263 ret
= -TARGET_ENOSYS
;
2270 #define N_SHM_REGIONS 32
2272 static struct shm_region
{
2275 } shm_regions
[N_SHM_REGIONS
];
2277 struct target_ipc_perm
2284 unsigned short int mode
;
2285 unsigned short int __pad1
;
2286 unsigned short int __seq
;
2287 unsigned short int __pad2
;
2288 abi_ulong __unused1
;
2289 abi_ulong __unused2
;
2292 struct target_semid_ds
2294 struct target_ipc_perm sem_perm
;
2295 abi_ulong sem_otime
;
2296 abi_ulong __unused1
;
2297 abi_ulong sem_ctime
;
2298 abi_ulong __unused2
;
2299 abi_ulong sem_nsems
;
2300 abi_ulong __unused3
;
2301 abi_ulong __unused4
;
2304 static inline abi_long
target_to_host_ipc_perm(struct ipc_perm
*host_ip
,
2305 abi_ulong target_addr
)
2307 struct target_ipc_perm
*target_ip
;
2308 struct target_semid_ds
*target_sd
;
2310 if (!lock_user_struct(VERIFY_READ
, target_sd
, target_addr
, 1))
2311 return -TARGET_EFAULT
;
2312 target_ip
= &(target_sd
->sem_perm
);
2313 host_ip
->__key
= tswapl(target_ip
->__key
);
2314 host_ip
->uid
= tswapl(target_ip
->uid
);
2315 host_ip
->gid
= tswapl(target_ip
->gid
);
2316 host_ip
->cuid
= tswapl(target_ip
->cuid
);
2317 host_ip
->cgid
= tswapl(target_ip
->cgid
);
2318 host_ip
->mode
= tswapl(target_ip
->mode
);
2319 unlock_user_struct(target_sd
, target_addr
, 0);
2323 static inline abi_long
host_to_target_ipc_perm(abi_ulong target_addr
,
2324 struct ipc_perm
*host_ip
)
2326 struct target_ipc_perm
*target_ip
;
2327 struct target_semid_ds
*target_sd
;
2329 if (!lock_user_struct(VERIFY_WRITE
, target_sd
, target_addr
, 0))
2330 return -TARGET_EFAULT
;
2331 target_ip
= &(target_sd
->sem_perm
);
2332 target_ip
->__key
= tswapl(host_ip
->__key
);
2333 target_ip
->uid
= tswapl(host_ip
->uid
);
2334 target_ip
->gid
= tswapl(host_ip
->gid
);
2335 target_ip
->cuid
= tswapl(host_ip
->cuid
);
2336 target_ip
->cgid
= tswapl(host_ip
->cgid
);
2337 target_ip
->mode
= tswapl(host_ip
->mode
);
2338 unlock_user_struct(target_sd
, target_addr
, 1);
2342 static inline abi_long
target_to_host_semid_ds(struct semid_ds
*host_sd
,
2343 abi_ulong target_addr
)
2345 struct target_semid_ds
*target_sd
;
2347 if (!lock_user_struct(VERIFY_READ
, target_sd
, target_addr
, 1))
2348 return -TARGET_EFAULT
;
2349 if (target_to_host_ipc_perm(&(host_sd
->sem_perm
),target_addr
))
2350 return -TARGET_EFAULT
;
2351 host_sd
->sem_nsems
= tswapl(target_sd
->sem_nsems
);
2352 host_sd
->sem_otime
= tswapl(target_sd
->sem_otime
);
2353 host_sd
->sem_ctime
= tswapl(target_sd
->sem_ctime
);
2354 unlock_user_struct(target_sd
, target_addr
, 0);
2358 static inline abi_long
host_to_target_semid_ds(abi_ulong target_addr
,
2359 struct semid_ds
*host_sd
)
2361 struct target_semid_ds
*target_sd
;
2363 if (!lock_user_struct(VERIFY_WRITE
, target_sd
, target_addr
, 0))
2364 return -TARGET_EFAULT
;
2365 if (host_to_target_ipc_perm(target_addr
,&(host_sd
->sem_perm
)))
2366 return -TARGET_EFAULT
;;
2367 target_sd
->sem_nsems
= tswapl(host_sd
->sem_nsems
);
2368 target_sd
->sem_otime
= tswapl(host_sd
->sem_otime
);
2369 target_sd
->sem_ctime
= tswapl(host_sd
->sem_ctime
);
2370 unlock_user_struct(target_sd
, target_addr
, 1);
2374 struct target_seminfo
{
2387 static inline abi_long
host_to_target_seminfo(abi_ulong target_addr
,
2388 struct seminfo
*host_seminfo
)
2390 struct target_seminfo
*target_seminfo
;
2391 if (!lock_user_struct(VERIFY_WRITE
, target_seminfo
, target_addr
, 0))
2392 return -TARGET_EFAULT
;
2393 __put_user(host_seminfo
->semmap
, &target_seminfo
->semmap
);
2394 __put_user(host_seminfo
->semmni
, &target_seminfo
->semmni
);
2395 __put_user(host_seminfo
->semmns
, &target_seminfo
->semmns
);
2396 __put_user(host_seminfo
->semmnu
, &target_seminfo
->semmnu
);
2397 __put_user(host_seminfo
->semmsl
, &target_seminfo
->semmsl
);
2398 __put_user(host_seminfo
->semopm
, &target_seminfo
->semopm
);
2399 __put_user(host_seminfo
->semume
, &target_seminfo
->semume
);
2400 __put_user(host_seminfo
->semusz
, &target_seminfo
->semusz
);
2401 __put_user(host_seminfo
->semvmx
, &target_seminfo
->semvmx
);
2402 __put_user(host_seminfo
->semaem
, &target_seminfo
->semaem
);
2403 unlock_user_struct(target_seminfo
, target_addr
, 1);
2409 struct semid_ds
*buf
;
2410 unsigned short *array
;
2411 struct seminfo
*__buf
;
2414 union target_semun
{
2421 static inline abi_long
target_to_host_semarray(int semid
, unsigned short **host_array
,
2422 abi_ulong target_addr
)
2425 unsigned short *array
;
2427 struct semid_ds semid_ds
;
2430 semun
.buf
= &semid_ds
;
2432 ret
= semctl(semid
, 0, IPC_STAT
, semun
);
2434 return get_errno(ret
);
2436 nsems
= semid_ds
.sem_nsems
;
2438 *host_array
= malloc(nsems
*sizeof(unsigned short));
2439 array
= lock_user(VERIFY_READ
, target_addr
,
2440 nsems
*sizeof(unsigned short), 1);
2442 return -TARGET_EFAULT
;
2444 for(i
=0; i
<nsems
; i
++) {
2445 __get_user((*host_array
)[i
], &array
[i
]);
2447 unlock_user(array
, target_addr
, 0);
2452 static inline abi_long
host_to_target_semarray(int semid
, abi_ulong target_addr
,
2453 unsigned short **host_array
)
2456 unsigned short *array
;
2458 struct semid_ds semid_ds
;
2461 semun
.buf
= &semid_ds
;
2463 ret
= semctl(semid
, 0, IPC_STAT
, semun
);
2465 return get_errno(ret
);
2467 nsems
= semid_ds
.sem_nsems
;
2469 array
= lock_user(VERIFY_WRITE
, target_addr
,
2470 nsems
*sizeof(unsigned short), 0);
2472 return -TARGET_EFAULT
;
2474 for(i
=0; i
<nsems
; i
++) {
2475 __put_user((*host_array
)[i
], &array
[i
]);
2478 unlock_user(array
, target_addr
, 1);
2483 static inline abi_long
do_semctl(int semid
, int semnum
, int cmd
,
2484 union target_semun target_su
)
2487 struct semid_ds dsarg
;
2488 unsigned short *array
= NULL
;
2489 struct seminfo seminfo
;
2490 abi_long ret
= -TARGET_EINVAL
;
2497 arg
.val
= tswapl(target_su
.val
);
2498 ret
= get_errno(semctl(semid
, semnum
, cmd
, arg
));
2499 target_su
.val
= tswapl(arg
.val
);
2503 err
= target_to_host_semarray(semid
, &array
, target_su
.array
);
2507 ret
= get_errno(semctl(semid
, semnum
, cmd
, arg
));
2508 err
= host_to_target_semarray(semid
, target_su
.array
, &array
);
2515 err
= target_to_host_semid_ds(&dsarg
, target_su
.buf
);
2519 ret
= get_errno(semctl(semid
, semnum
, cmd
, arg
));
2520 err
= host_to_target_semid_ds(target_su
.buf
, &dsarg
);
2526 arg
.__buf
= &seminfo
;
2527 ret
= get_errno(semctl(semid
, semnum
, cmd
, arg
));
2528 err
= host_to_target_seminfo(target_su
.__buf
, &seminfo
);
2536 ret
= get_errno(semctl(semid
, semnum
, cmd
, NULL
));
2543 struct target_sembuf
{
2544 unsigned short sem_num
;
2549 static inline abi_long
target_to_host_sembuf(struct sembuf
*host_sembuf
,
2550 abi_ulong target_addr
,
2553 struct target_sembuf
*target_sembuf
;
2556 target_sembuf
= lock_user(VERIFY_READ
, target_addr
,
2557 nsops
*sizeof(struct target_sembuf
), 1);
2559 return -TARGET_EFAULT
;
2561 for(i
=0; i
<nsops
; i
++) {
2562 __get_user(host_sembuf
[i
].sem_num
, &target_sembuf
[i
].sem_num
);
2563 __get_user(host_sembuf
[i
].sem_op
, &target_sembuf
[i
].sem_op
);
2564 __get_user(host_sembuf
[i
].sem_flg
, &target_sembuf
[i
].sem_flg
);
2567 unlock_user(target_sembuf
, target_addr
, 0);
2572 static inline abi_long
do_semop(int semid
, abi_long ptr
, unsigned nsops
)
2574 struct sembuf sops
[nsops
];
2576 if (target_to_host_sembuf(sops
, ptr
, nsops
))
2577 return -TARGET_EFAULT
;
2579 return semop(semid
, sops
, nsops
);
2582 struct target_msqid_ds
2584 struct target_ipc_perm msg_perm
;
2585 abi_ulong msg_stime
;
2586 #if TARGET_ABI_BITS == 32
2587 abi_ulong __unused1
;
2589 abi_ulong msg_rtime
;
2590 #if TARGET_ABI_BITS == 32
2591 abi_ulong __unused2
;
2593 abi_ulong msg_ctime
;
2594 #if TARGET_ABI_BITS == 32
2595 abi_ulong __unused3
;
2597 abi_ulong __msg_cbytes
;
2599 abi_ulong msg_qbytes
;
2600 abi_ulong msg_lspid
;
2601 abi_ulong msg_lrpid
;
2602 abi_ulong __unused4
;
2603 abi_ulong __unused5
;
2606 static inline abi_long
target_to_host_msqid_ds(struct msqid_ds
*host_md
,
2607 abi_ulong target_addr
)
2609 struct target_msqid_ds
*target_md
;
2611 if (!lock_user_struct(VERIFY_READ
, target_md
, target_addr
, 1))
2612 return -TARGET_EFAULT
;
2613 if (target_to_host_ipc_perm(&(host_md
->msg_perm
),target_addr
))
2614 return -TARGET_EFAULT
;
2615 host_md
->msg_stime
= tswapl(target_md
->msg_stime
);
2616 host_md
->msg_rtime
= tswapl(target_md
->msg_rtime
);
2617 host_md
->msg_ctime
= tswapl(target_md
->msg_ctime
);
2618 host_md
->__msg_cbytes
= tswapl(target_md
->__msg_cbytes
);
2619 host_md
->msg_qnum
= tswapl(target_md
->msg_qnum
);
2620 host_md
->msg_qbytes
= tswapl(target_md
->msg_qbytes
);
2621 host_md
->msg_lspid
= tswapl(target_md
->msg_lspid
);
2622 host_md
->msg_lrpid
= tswapl(target_md
->msg_lrpid
);
2623 unlock_user_struct(target_md
, target_addr
, 0);
2627 static inline abi_long
host_to_target_msqid_ds(abi_ulong target_addr
,
2628 struct msqid_ds
*host_md
)
2630 struct target_msqid_ds
*target_md
;
2632 if (!lock_user_struct(VERIFY_WRITE
, target_md
, target_addr
, 0))
2633 return -TARGET_EFAULT
;
2634 if (host_to_target_ipc_perm(target_addr
,&(host_md
->msg_perm
)))
2635 return -TARGET_EFAULT
;
2636 target_md
->msg_stime
= tswapl(host_md
->msg_stime
);
2637 target_md
->msg_rtime
= tswapl(host_md
->msg_rtime
);
2638 target_md
->msg_ctime
= tswapl(host_md
->msg_ctime
);
2639 target_md
->__msg_cbytes
= tswapl(host_md
->__msg_cbytes
);
2640 target_md
->msg_qnum
= tswapl(host_md
->msg_qnum
);
2641 target_md
->msg_qbytes
= tswapl(host_md
->msg_qbytes
);
2642 target_md
->msg_lspid
= tswapl(host_md
->msg_lspid
);
2643 target_md
->msg_lrpid
= tswapl(host_md
->msg_lrpid
);
2644 unlock_user_struct(target_md
, target_addr
, 1);
2648 struct target_msginfo
{
2656 unsigned short int msgseg
;
2659 static inline abi_long
host_to_target_msginfo(abi_ulong target_addr
,
2660 struct msginfo
*host_msginfo
)
2662 struct target_msginfo
*target_msginfo
;
2663 if (!lock_user_struct(VERIFY_WRITE
, target_msginfo
, target_addr
, 0))
2664 return -TARGET_EFAULT
;
2665 __put_user(host_msginfo
->msgpool
, &target_msginfo
->msgpool
);
2666 __put_user(host_msginfo
->msgmap
, &target_msginfo
->msgmap
);
2667 __put_user(host_msginfo
->msgmax
, &target_msginfo
->msgmax
);
2668 __put_user(host_msginfo
->msgmnb
, &target_msginfo
->msgmnb
);
2669 __put_user(host_msginfo
->msgmni
, &target_msginfo
->msgmni
);
2670 __put_user(host_msginfo
->msgssz
, &target_msginfo
->msgssz
);
2671 __put_user(host_msginfo
->msgtql
, &target_msginfo
->msgtql
);
2672 __put_user(host_msginfo
->msgseg
, &target_msginfo
->msgseg
);
2673 unlock_user_struct(target_msginfo
, target_addr
, 1);
2677 static inline abi_long
do_msgctl(int msgid
, int cmd
, abi_long ptr
)
2679 struct msqid_ds dsarg
;
2680 struct msginfo msginfo
;
2681 abi_long ret
= -TARGET_EINVAL
;
2689 if (target_to_host_msqid_ds(&dsarg
,ptr
))
2690 return -TARGET_EFAULT
;
2691 ret
= get_errno(msgctl(msgid
, cmd
, &dsarg
));
2692 if (host_to_target_msqid_ds(ptr
,&dsarg
))
2693 return -TARGET_EFAULT
;
2696 ret
= get_errno(msgctl(msgid
, cmd
, NULL
));
2700 ret
= get_errno(msgctl(msgid
, cmd
, (struct msqid_ds
*)&msginfo
));
2701 if (host_to_target_msginfo(ptr
, &msginfo
))
2702 return -TARGET_EFAULT
;
2709 struct target_msgbuf
{
2714 static inline abi_long
do_msgsnd(int msqid
, abi_long msgp
,
2715 unsigned int msgsz
, int msgflg
)
2717 struct target_msgbuf
*target_mb
;
2718 struct msgbuf
*host_mb
;
2721 if (!lock_user_struct(VERIFY_READ
, target_mb
, msgp
, 0))
2722 return -TARGET_EFAULT
;
2723 host_mb
= malloc(msgsz
+sizeof(long));
2724 host_mb
->mtype
= (abi_long
) tswapl(target_mb
->mtype
);
2725 memcpy(host_mb
->mtext
, target_mb
->mtext
, msgsz
);
2726 ret
= get_errno(msgsnd(msqid
, host_mb
, msgsz
, msgflg
));
2728 unlock_user_struct(target_mb
, msgp
, 0);
2733 static inline abi_long
do_msgrcv(int msqid
, abi_long msgp
,
2734 unsigned int msgsz
, abi_long msgtyp
,
2737 struct target_msgbuf
*target_mb
;
2739 struct msgbuf
*host_mb
;
2742 if (!lock_user_struct(VERIFY_WRITE
, target_mb
, msgp
, 0))
2743 return -TARGET_EFAULT
;
2745 host_mb
= malloc(msgsz
+sizeof(long));
2746 ret
= get_errno(msgrcv(msqid
, host_mb
, msgsz
, tswapl(msgtyp
), msgflg
));
2749 abi_ulong target_mtext_addr
= msgp
+ sizeof(abi_ulong
);
2750 target_mtext
= lock_user(VERIFY_WRITE
, target_mtext_addr
, ret
, 0);
2751 if (!target_mtext
) {
2752 ret
= -TARGET_EFAULT
;
2755 memcpy(target_mb
->mtext
, host_mb
->mtext
, ret
);
2756 unlock_user(target_mtext
, target_mtext_addr
, ret
);
2759 target_mb
->mtype
= tswapl(host_mb
->mtype
);
2764 unlock_user_struct(target_mb
, msgp
, 1);
2768 struct target_shmid_ds
2770 struct target_ipc_perm shm_perm
;
2771 abi_ulong shm_segsz
;
2772 abi_ulong shm_atime
;
2773 #if TARGET_ABI_BITS == 32
2774 abi_ulong __unused1
;
2776 abi_ulong shm_dtime
;
2777 #if TARGET_ABI_BITS == 32
2778 abi_ulong __unused2
;
2780 abi_ulong shm_ctime
;
2781 #if TARGET_ABI_BITS == 32
2782 abi_ulong __unused3
;
2786 abi_ulong shm_nattch
;
2787 unsigned long int __unused4
;
2788 unsigned long int __unused5
;
2791 static inline abi_long
target_to_host_shmid_ds(struct shmid_ds
*host_sd
,
2792 abi_ulong target_addr
)
2794 struct target_shmid_ds
*target_sd
;
2796 if (!lock_user_struct(VERIFY_READ
, target_sd
, target_addr
, 1))
2797 return -TARGET_EFAULT
;
2798 if (target_to_host_ipc_perm(&(host_sd
->shm_perm
), target_addr
))
2799 return -TARGET_EFAULT
;
2800 __get_user(host_sd
->shm_segsz
, &target_sd
->shm_segsz
);
2801 __get_user(host_sd
->shm_atime
, &target_sd
->shm_atime
);
2802 __get_user(host_sd
->shm_dtime
, &target_sd
->shm_dtime
);
2803 __get_user(host_sd
->shm_ctime
, &target_sd
->shm_ctime
);
2804 __get_user(host_sd
->shm_cpid
, &target_sd
->shm_cpid
);
2805 __get_user(host_sd
->shm_lpid
, &target_sd
->shm_lpid
);
2806 __get_user(host_sd
->shm_nattch
, &target_sd
->shm_nattch
);
2807 unlock_user_struct(target_sd
, target_addr
, 0);
2811 static inline abi_long
host_to_target_shmid_ds(abi_ulong target_addr
,
2812 struct shmid_ds
*host_sd
)
2814 struct target_shmid_ds
*target_sd
;
2816 if (!lock_user_struct(VERIFY_WRITE
, target_sd
, target_addr
, 0))
2817 return -TARGET_EFAULT
;
2818 if (host_to_target_ipc_perm(target_addr
, &(host_sd
->shm_perm
)))
2819 return -TARGET_EFAULT
;
2820 __put_user(host_sd
->shm_segsz
, &target_sd
->shm_segsz
);
2821 __put_user(host_sd
->shm_atime
, &target_sd
->shm_atime
);
2822 __put_user(host_sd
->shm_dtime
, &target_sd
->shm_dtime
);
2823 __put_user(host_sd
->shm_ctime
, &target_sd
->shm_ctime
);
2824 __put_user(host_sd
->shm_cpid
, &target_sd
->shm_cpid
);
2825 __put_user(host_sd
->shm_lpid
, &target_sd
->shm_lpid
);
2826 __put_user(host_sd
->shm_nattch
, &target_sd
->shm_nattch
);
2827 unlock_user_struct(target_sd
, target_addr
, 1);
2831 struct target_shminfo
{
2839 static inline abi_long
host_to_target_shminfo(abi_ulong target_addr
,
2840 struct shminfo
*host_shminfo
)
2842 struct target_shminfo
*target_shminfo
;
2843 if (!lock_user_struct(VERIFY_WRITE
, target_shminfo
, target_addr
, 0))
2844 return -TARGET_EFAULT
;
2845 __put_user(host_shminfo
->shmmax
, &target_shminfo
->shmmax
);
2846 __put_user(host_shminfo
->shmmin
, &target_shminfo
->shmmin
);
2847 __put_user(host_shminfo
->shmmni
, &target_shminfo
->shmmni
);
2848 __put_user(host_shminfo
->shmseg
, &target_shminfo
->shmseg
);
2849 __put_user(host_shminfo
->shmall
, &target_shminfo
->shmall
);
2850 unlock_user_struct(target_shminfo
, target_addr
, 1);
2854 struct target_shm_info
{
2859 abi_ulong swap_attempts
;
2860 abi_ulong swap_successes
;
2863 static inline abi_long
host_to_target_shm_info(abi_ulong target_addr
,
2864 struct shm_info
*host_shm_info
)
2866 struct target_shm_info
*target_shm_info
;
2867 if (!lock_user_struct(VERIFY_WRITE
, target_shm_info
, target_addr
, 0))
2868 return -TARGET_EFAULT
;
2869 __put_user(host_shm_info
->used_ids
, &target_shm_info
->used_ids
);
2870 __put_user(host_shm_info
->shm_tot
, &target_shm_info
->shm_tot
);
2871 __put_user(host_shm_info
->shm_rss
, &target_shm_info
->shm_rss
);
2872 __put_user(host_shm_info
->shm_swp
, &target_shm_info
->shm_swp
);
2873 __put_user(host_shm_info
->swap_attempts
, &target_shm_info
->swap_attempts
);
2874 __put_user(host_shm_info
->swap_successes
, &target_shm_info
->swap_successes
);
2875 unlock_user_struct(target_shm_info
, target_addr
, 1);
2879 static inline abi_long
do_shmctl(int shmid
, int cmd
, abi_long buf
)
2881 struct shmid_ds dsarg
;
2882 struct shminfo shminfo
;
2883 struct shm_info shm_info
;
2884 abi_long ret
= -TARGET_EINVAL
;
2892 if (target_to_host_shmid_ds(&dsarg
, buf
))
2893 return -TARGET_EFAULT
;
2894 ret
= get_errno(shmctl(shmid
, cmd
, &dsarg
));
2895 if (host_to_target_shmid_ds(buf
, &dsarg
))
2896 return -TARGET_EFAULT
;
2899 ret
= get_errno(shmctl(shmid
, cmd
, (struct shmid_ds
*)&shminfo
));
2900 if (host_to_target_shminfo(buf
, &shminfo
))
2901 return -TARGET_EFAULT
;
2904 ret
= get_errno(shmctl(shmid
, cmd
, (struct shmid_ds
*)&shm_info
));
2905 if (host_to_target_shm_info(buf
, &shm_info
))
2906 return -TARGET_EFAULT
;
2911 ret
= get_errno(shmctl(shmid
, cmd
, NULL
));
2918 static inline abi_ulong
do_shmat(int shmid
, abi_ulong shmaddr
, int shmflg
)
2922 struct shmid_ds shm_info
;
2925 /* find out the length of the shared memory segment */
2926 ret
= get_errno(shmctl(shmid
, IPC_STAT
, &shm_info
));
2927 if (is_error(ret
)) {
2928 /* can't get length, bail out */
2935 host_raddr
= shmat(shmid
, (void *)g2h(shmaddr
), shmflg
);
2937 abi_ulong mmap_start
;
2939 mmap_start
= mmap_find_vma(0, shm_info
.shm_segsz
);
2941 if (mmap_start
== -1) {
2943 host_raddr
= (void *)-1;
2945 host_raddr
= shmat(shmid
, g2h(mmap_start
), shmflg
| SHM_REMAP
);
2948 if (host_raddr
== (void *)-1) {
2950 return get_errno((long)host_raddr
);
2952 raddr
=h2g((unsigned long)host_raddr
);
2954 page_set_flags(raddr
, raddr
+ shm_info
.shm_segsz
,
2955 PAGE_VALID
| PAGE_READ
|
2956 ((shmflg
& SHM_RDONLY
)? 0 : PAGE_WRITE
));
2958 for (i
= 0; i
< N_SHM_REGIONS
; i
++) {
2959 if (shm_regions
[i
].start
== 0) {
2960 shm_regions
[i
].start
= raddr
;
2961 shm_regions
[i
].size
= shm_info
.shm_segsz
;
2971 static inline abi_long
do_shmdt(abi_ulong shmaddr
)
2975 for (i
= 0; i
< N_SHM_REGIONS
; ++i
) {
2976 if (shm_regions
[i
].start
== shmaddr
) {
2977 shm_regions
[i
].start
= 0;
2978 page_set_flags(shmaddr
, shmaddr
+ shm_regions
[i
].size
, 0);
2983 return get_errno(shmdt(g2h(shmaddr
)));
2986 #ifdef TARGET_NR_ipc
2987 /* ??? This only works with linear mappings. */
2988 /* do_ipc() must return target values and target errnos. */
2989 static abi_long
do_ipc(unsigned int call
, int first
,
2990 int second
, int third
,
2991 abi_long ptr
, abi_long fifth
)
2996 version
= call
>> 16;
3001 ret
= do_semop(first
, ptr
, second
);
3005 ret
= get_errno(semget(first
, second
, third
));
3009 ret
= do_semctl(first
, second
, third
, (union target_semun
)(abi_ulong
) ptr
);
3013 ret
= get_errno(msgget(first
, second
));
3017 ret
= do_msgsnd(first
, ptr
, second
, third
);
3021 ret
= do_msgctl(first
, second
, ptr
);
3028 struct target_ipc_kludge
{
3033 if (!lock_user_struct(VERIFY_READ
, tmp
, ptr
, 1)) {
3034 ret
= -TARGET_EFAULT
;
3038 ret
= do_msgrcv(first
, tmp
->msgp
, second
, tmp
->msgtyp
, third
);
3040 unlock_user_struct(tmp
, ptr
, 0);
3044 ret
= do_msgrcv(first
, ptr
, second
, fifth
, third
);
3053 raddr
= do_shmat(first
, ptr
, second
);
3054 if (is_error(raddr
))
3055 return get_errno(raddr
);
3056 if (put_user_ual(raddr
, third
))
3057 return -TARGET_EFAULT
;
3061 ret
= -TARGET_EINVAL
;
3066 ret
= do_shmdt(ptr
);
3070 /* IPC_* flag values are the same on all linux platforms */
3071 ret
= get_errno(shmget(first
, second
, third
));
3074 /* IPC_* and SHM_* command values are the same on all linux platforms */
3076 ret
= do_shmctl(first
, second
, third
);
3079 gemu_log("Unsupported ipc call: %d (version %d)\n", call
, version
);
3080 ret
= -TARGET_ENOSYS
;
3087 /* kernel structure types definitions */
3089 #define STRUCT(name, ...) STRUCT_ ## name,
3090 #define STRUCT_SPECIAL(name) STRUCT_ ## name,
3092 #include "syscall_types.h"
3095 #undef STRUCT_SPECIAL
3097 #define STRUCT(name, ...) static const argtype struct_ ## name ## _def[] = { __VA_ARGS__, TYPE_NULL };
3098 #define STRUCT_SPECIAL(name)
3099 #include "syscall_types.h"
3101 #undef STRUCT_SPECIAL
3103 typedef struct IOCTLEntry IOCTLEntry
;
3105 typedef abi_long
do_ioctl_fn(const IOCTLEntry
*ie
, uint8_t *buf_temp
,
3106 int fd
, abi_long cmd
, abi_long arg
);
3109 unsigned int target_cmd
;
3110 unsigned int host_cmd
;
3113 do_ioctl_fn
*do_ioctl
;
3114 const argtype arg_type
[5];
3117 #define IOC_R 0x0001
3118 #define IOC_W 0x0002
3119 #define IOC_RW (IOC_R | IOC_W)
3121 #define MAX_STRUCT_SIZE 4096
3123 #ifdef CONFIG_FIEMAP
3124 /* So fiemap access checks don't overflow on 32 bit systems.
3125 * This is very slightly smaller than the limit imposed by
3126 * the underlying kernel.
3128 #define FIEMAP_MAX_EXTENTS ((UINT_MAX - sizeof(struct fiemap)) \
3129 / sizeof(struct fiemap_extent))
3131 static abi_long
do_ioctl_fs_ioc_fiemap(const IOCTLEntry
*ie
, uint8_t *buf_temp
,
3132 int fd
, abi_long cmd
, abi_long arg
)
3134 /* The parameter for this ioctl is a struct fiemap followed
3135 * by an array of struct fiemap_extent whose size is set
3136 * in fiemap->fm_extent_count. The array is filled in by the
3139 int target_size_in
, target_size_out
;
3141 const argtype
*arg_type
= ie
->arg_type
;
3142 const argtype extent_arg_type
[] = { MK_STRUCT(STRUCT_fiemap_extent
) };
3145 int i
, extent_size
= thunk_type_size(extent_arg_type
, 0);
3149 assert(arg_type
[0] == TYPE_PTR
);
3150 assert(ie
->access
== IOC_RW
);
3152 target_size_in
= thunk_type_size(arg_type
, 0);
3153 argptr
= lock_user(VERIFY_READ
, arg
, target_size_in
, 1);
3155 return -TARGET_EFAULT
;
3157 thunk_convert(buf_temp
, argptr
, arg_type
, THUNK_HOST
);
3158 unlock_user(argptr
, arg
, 0);
3159 fm
= (struct fiemap
*)buf_temp
;
3160 if (fm
->fm_extent_count
> FIEMAP_MAX_EXTENTS
) {
3161 return -TARGET_EINVAL
;
3164 outbufsz
= sizeof (*fm
) +
3165 (sizeof(struct fiemap_extent
) * fm
->fm_extent_count
);
3167 if (outbufsz
> MAX_STRUCT_SIZE
) {
3168 /* We can't fit all the extents into the fixed size buffer.
3169 * Allocate one that is large enough and use it instead.
3171 fm
= malloc(outbufsz
);
3173 return -TARGET_ENOMEM
;
3175 memcpy(fm
, buf_temp
, sizeof(struct fiemap
));
3178 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, fm
));
3179 if (!is_error(ret
)) {
3180 target_size_out
= target_size_in
;
3181 /* An extent_count of 0 means we were only counting the extents
3182 * so there are no structs to copy
3184 if (fm
->fm_extent_count
!= 0) {
3185 target_size_out
+= fm
->fm_mapped_extents
* extent_size
;
3187 argptr
= lock_user(VERIFY_WRITE
, arg
, target_size_out
, 0);
3189 ret
= -TARGET_EFAULT
;
3191 /* Convert the struct fiemap */
3192 thunk_convert(argptr
, fm
, arg_type
, THUNK_TARGET
);
3193 if (fm
->fm_extent_count
!= 0) {
3194 p
= argptr
+ target_size_in
;
3195 /* ...and then all the struct fiemap_extents */
3196 for (i
= 0; i
< fm
->fm_mapped_extents
; i
++) {
3197 thunk_convert(p
, &fm
->fm_extents
[i
], extent_arg_type
,
3202 unlock_user(argptr
, arg
, target_size_out
);
3212 static abi_long
do_ioctl_ifconf(const IOCTLEntry
*ie
, uint8_t *buf_temp
,
3213 int fd
, abi_long cmd
, abi_long arg
)
3215 const argtype
*arg_type
= ie
->arg_type
;
3219 struct ifconf
*host_ifconf
;
3221 const argtype ifreq_arg_type
[] = { MK_STRUCT(STRUCT_sockaddr_ifreq
) };
3222 int target_ifreq_size
;
3227 abi_long target_ifc_buf
;
3231 assert(arg_type
[0] == TYPE_PTR
);
3232 assert(ie
->access
== IOC_RW
);
3235 target_size
= thunk_type_size(arg_type
, 0);
3237 argptr
= lock_user(VERIFY_READ
, arg
, target_size
, 1);
3239 return -TARGET_EFAULT
;
3240 thunk_convert(buf_temp
, argptr
, arg_type
, THUNK_HOST
);
3241 unlock_user(argptr
, arg
, 0);
3243 host_ifconf
= (struct ifconf
*)(unsigned long)buf_temp
;
3244 target_ifc_len
= host_ifconf
->ifc_len
;
3245 target_ifc_buf
= (abi_long
)(unsigned long)host_ifconf
->ifc_buf
;
3247 target_ifreq_size
= thunk_type_size(ifreq_arg_type
, 0);
3248 nb_ifreq
= target_ifc_len
/ target_ifreq_size
;
3249 host_ifc_len
= nb_ifreq
* sizeof(struct ifreq
);
3251 outbufsz
= sizeof(*host_ifconf
) + host_ifc_len
;
3252 if (outbufsz
> MAX_STRUCT_SIZE
) {
3253 /* We can't fit all the extents into the fixed size buffer.
3254 * Allocate one that is large enough and use it instead.
3256 host_ifconf
= malloc(outbufsz
);
3258 return -TARGET_ENOMEM
;
3260 memcpy(host_ifconf
, buf_temp
, sizeof(*host_ifconf
));
3263 host_ifc_buf
= (char*)host_ifconf
+ sizeof(*host_ifconf
);
3265 host_ifconf
->ifc_len
= host_ifc_len
;
3266 host_ifconf
->ifc_buf
= host_ifc_buf
;
3268 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, host_ifconf
));
3269 if (!is_error(ret
)) {
3270 /* convert host ifc_len to target ifc_len */
3272 nb_ifreq
= host_ifconf
->ifc_len
/ sizeof(struct ifreq
);
3273 target_ifc_len
= nb_ifreq
* target_ifreq_size
;
3274 host_ifconf
->ifc_len
= target_ifc_len
;
3276 /* restore target ifc_buf */
3278 host_ifconf
->ifc_buf
= (char *)(unsigned long)target_ifc_buf
;
3280 /* copy struct ifconf to target user */
3282 argptr
= lock_user(VERIFY_WRITE
, arg
, target_size
, 0);
3284 return -TARGET_EFAULT
;
3285 thunk_convert(argptr
, host_ifconf
, arg_type
, THUNK_TARGET
);
3286 unlock_user(argptr
, arg
, target_size
);
3288 /* copy ifreq[] to target user */
3290 argptr
= lock_user(VERIFY_WRITE
, target_ifc_buf
, target_ifc_len
, 0);
3291 for (i
= 0; i
< nb_ifreq
; i
++) {
3292 thunk_convert(argptr
+ i
* target_ifreq_size
,
3293 host_ifc_buf
+ i
* sizeof(struct ifreq
),
3294 ifreq_arg_type
, THUNK_TARGET
);
3296 unlock_user(argptr
, target_ifc_buf
, target_ifc_len
);
3306 static IOCTLEntry ioctl_entries
[] = {
3307 #define IOCTL(cmd, access, ...) \
3308 { TARGET_ ## cmd, cmd, #cmd, access, 0, { __VA_ARGS__ } },
3309 #define IOCTL_SPECIAL(cmd, access, dofn, ...) \
3310 { TARGET_ ## cmd, cmd, #cmd, access, dofn, { __VA_ARGS__ } },
3315 /* ??? Implement proper locking for ioctls. */
3316 /* do_ioctl() Must return target values and target errnos. */
3317 static abi_long
do_ioctl(int fd
, abi_long cmd
, abi_long arg
)
3319 const IOCTLEntry
*ie
;
3320 const argtype
*arg_type
;
3322 uint8_t buf_temp
[MAX_STRUCT_SIZE
];
3328 if (ie
->target_cmd
== 0) {
3329 gemu_log("Unsupported ioctl: cmd=0x%04lx\n", (long)cmd
);
3330 return -TARGET_ENOSYS
;
3332 if (ie
->target_cmd
== cmd
)
3336 arg_type
= ie
->arg_type
;
3338 gemu_log("ioctl: cmd=0x%04lx (%s)\n", (long)cmd
, ie
->name
);
3341 return ie
->do_ioctl(ie
, buf_temp
, fd
, cmd
, arg
);
3344 switch(arg_type
[0]) {
3347 ret
= get_errno(ioctl(fd
, ie
->host_cmd
));
3352 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, arg
));
3356 target_size
= thunk_type_size(arg_type
, 0);
3357 switch(ie
->access
) {
3359 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, buf_temp
));
3360 if (!is_error(ret
)) {
3361 argptr
= lock_user(VERIFY_WRITE
, arg
, target_size
, 0);
3363 return -TARGET_EFAULT
;
3364 thunk_convert(argptr
, buf_temp
, arg_type
, THUNK_TARGET
);
3365 unlock_user(argptr
, arg
, target_size
);
3369 argptr
= lock_user(VERIFY_READ
, arg
, target_size
, 1);
3371 return -TARGET_EFAULT
;
3372 thunk_convert(buf_temp
, argptr
, arg_type
, THUNK_HOST
);
3373 unlock_user(argptr
, arg
, 0);
3374 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, buf_temp
));
3378 argptr
= lock_user(VERIFY_READ
, arg
, target_size
, 1);
3380 return -TARGET_EFAULT
;
3381 thunk_convert(buf_temp
, argptr
, arg_type
, THUNK_HOST
);
3382 unlock_user(argptr
, arg
, 0);
3383 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, buf_temp
));
3384 if (!is_error(ret
)) {
3385 argptr
= lock_user(VERIFY_WRITE
, arg
, target_size
, 0);
3387 return -TARGET_EFAULT
;
3388 thunk_convert(argptr
, buf_temp
, arg_type
, THUNK_TARGET
);
3389 unlock_user(argptr
, arg
, target_size
);
3395 gemu_log("Unsupported ioctl type: cmd=0x%04lx type=%d\n",
3396 (long)cmd
, arg_type
[0]);
3397 ret
= -TARGET_ENOSYS
;
3403 static const bitmask_transtbl iflag_tbl
[] = {
3404 { TARGET_IGNBRK
, TARGET_IGNBRK
, IGNBRK
, IGNBRK
},
3405 { TARGET_BRKINT
, TARGET_BRKINT
, BRKINT
, BRKINT
},
3406 { TARGET_IGNPAR
, TARGET_IGNPAR
, IGNPAR
, IGNPAR
},
3407 { TARGET_PARMRK
, TARGET_PARMRK
, PARMRK
, PARMRK
},
3408 { TARGET_INPCK
, TARGET_INPCK
, INPCK
, INPCK
},
3409 { TARGET_ISTRIP
, TARGET_ISTRIP
, ISTRIP
, ISTRIP
},
3410 { TARGET_INLCR
, TARGET_INLCR
, INLCR
, INLCR
},
3411 { TARGET_IGNCR
, TARGET_IGNCR
, IGNCR
, IGNCR
},
3412 { TARGET_ICRNL
, TARGET_ICRNL
, ICRNL
, ICRNL
},
3413 { TARGET_IUCLC
, TARGET_IUCLC
, IUCLC
, IUCLC
},
3414 { TARGET_IXON
, TARGET_IXON
, IXON
, IXON
},
3415 { TARGET_IXANY
, TARGET_IXANY
, IXANY
, IXANY
},
3416 { TARGET_IXOFF
, TARGET_IXOFF
, IXOFF
, IXOFF
},
3417 { TARGET_IMAXBEL
, TARGET_IMAXBEL
, IMAXBEL
, IMAXBEL
},
3421 static const bitmask_transtbl oflag_tbl
[] = {
3422 { TARGET_OPOST
, TARGET_OPOST
, OPOST
, OPOST
},
3423 { TARGET_OLCUC
, TARGET_OLCUC
, OLCUC
, OLCUC
},
3424 { TARGET_ONLCR
, TARGET_ONLCR
, ONLCR
, ONLCR
},
3425 { TARGET_OCRNL
, TARGET_OCRNL
, OCRNL
, OCRNL
},
3426 { TARGET_ONOCR
, TARGET_ONOCR
, ONOCR
, ONOCR
},
3427 { TARGET_ONLRET
, TARGET_ONLRET
, ONLRET
, ONLRET
},
3428 { TARGET_OFILL
, TARGET_OFILL
, OFILL
, OFILL
},
3429 { TARGET_OFDEL
, TARGET_OFDEL
, OFDEL
, OFDEL
},
3430 { TARGET_NLDLY
, TARGET_NL0
, NLDLY
, NL0
},
3431 { TARGET_NLDLY
, TARGET_NL1
, NLDLY
, NL1
},
3432 { TARGET_CRDLY
, TARGET_CR0
, CRDLY
, CR0
},
3433 { TARGET_CRDLY
, TARGET_CR1
, CRDLY
, CR1
},
3434 { TARGET_CRDLY
, TARGET_CR2
, CRDLY
, CR2
},
3435 { TARGET_CRDLY
, TARGET_CR3
, CRDLY
, CR3
},
3436 { TARGET_TABDLY
, TARGET_TAB0
, TABDLY
, TAB0
},
3437 { TARGET_TABDLY
, TARGET_TAB1
, TABDLY
, TAB1
},
3438 { TARGET_TABDLY
, TARGET_TAB2
, TABDLY
, TAB2
},
3439 { TARGET_TABDLY
, TARGET_TAB3
, TABDLY
, TAB3
},
3440 { TARGET_BSDLY
, TARGET_BS0
, BSDLY
, BS0
},
3441 { TARGET_BSDLY
, TARGET_BS1
, BSDLY
, BS1
},
3442 { TARGET_VTDLY
, TARGET_VT0
, VTDLY
, VT0
},
3443 { TARGET_VTDLY
, TARGET_VT1
, VTDLY
, VT1
},
3444 { TARGET_FFDLY
, TARGET_FF0
, FFDLY
, FF0
},
3445 { TARGET_FFDLY
, TARGET_FF1
, FFDLY
, FF1
},
3449 static const bitmask_transtbl cflag_tbl
[] = {
3450 { TARGET_CBAUD
, TARGET_B0
, CBAUD
, B0
},
3451 { TARGET_CBAUD
, TARGET_B50
, CBAUD
, B50
},
3452 { TARGET_CBAUD
, TARGET_B75
, CBAUD
, B75
},
3453 { TARGET_CBAUD
, TARGET_B110
, CBAUD
, B110
},
3454 { TARGET_CBAUD
, TARGET_B134
, CBAUD
, B134
},
3455 { TARGET_CBAUD
, TARGET_B150
, CBAUD
, B150
},
3456 { TARGET_CBAUD
, TARGET_B200
, CBAUD
, B200
},
3457 { TARGET_CBAUD
, TARGET_B300
, CBAUD
, B300
},
3458 { TARGET_CBAUD
, TARGET_B600
, CBAUD
, B600
},
3459 { TARGET_CBAUD
, TARGET_B1200
, CBAUD
, B1200
},
3460 { TARGET_CBAUD
, TARGET_B1800
, CBAUD
, B1800
},
3461 { TARGET_CBAUD
, TARGET_B2400
, CBAUD
, B2400
},
3462 { TARGET_CBAUD
, TARGET_B4800
, CBAUD
, B4800
},
3463 { TARGET_CBAUD
, TARGET_B9600
, CBAUD
, B9600
},
3464 { TARGET_CBAUD
, TARGET_B19200
, CBAUD
, B19200
},
3465 { TARGET_CBAUD
, TARGET_B38400
, CBAUD
, B38400
},
3466 { TARGET_CBAUD
, TARGET_B57600
, CBAUD
, B57600
},
3467 { TARGET_CBAUD
, TARGET_B115200
, CBAUD
, B115200
},
3468 { TARGET_CBAUD
, TARGET_B230400
, CBAUD
, B230400
},
3469 { TARGET_CBAUD
, TARGET_B460800
, CBAUD
, B460800
},
3470 { TARGET_CSIZE
, TARGET_CS5
, CSIZE
, CS5
},
3471 { TARGET_CSIZE
, TARGET_CS6
, CSIZE
, CS6
},
3472 { TARGET_CSIZE
, TARGET_CS7
, CSIZE
, CS7
},
3473 { TARGET_CSIZE
, TARGET_CS8
, CSIZE
, CS8
},
3474 { TARGET_CSTOPB
, TARGET_CSTOPB
, CSTOPB
, CSTOPB
},
3475 { TARGET_CREAD
, TARGET_CREAD
, CREAD
, CREAD
},
3476 { TARGET_PARENB
, TARGET_PARENB
, PARENB
, PARENB
},
3477 { TARGET_PARODD
, TARGET_PARODD
, PARODD
, PARODD
},
3478 { TARGET_HUPCL
, TARGET_HUPCL
, HUPCL
, HUPCL
},
3479 { TARGET_CLOCAL
, TARGET_CLOCAL
, CLOCAL
, CLOCAL
},
3480 { TARGET_CRTSCTS
, TARGET_CRTSCTS
, CRTSCTS
, CRTSCTS
},
3484 static const bitmask_transtbl lflag_tbl
[] = {
3485 { TARGET_ISIG
, TARGET_ISIG
, ISIG
, ISIG
},
3486 { TARGET_ICANON
, TARGET_ICANON
, ICANON
, ICANON
},
3487 { TARGET_XCASE
, TARGET_XCASE
, XCASE
, XCASE
},
3488 { TARGET_ECHO
, TARGET_ECHO
, ECHO
, ECHO
},
3489 { TARGET_ECHOE
, TARGET_ECHOE
, ECHOE
, ECHOE
},
3490 { TARGET_ECHOK
, TARGET_ECHOK
, ECHOK
, ECHOK
},
3491 { TARGET_ECHONL
, TARGET_ECHONL
, ECHONL
, ECHONL
},
3492 { TARGET_NOFLSH
, TARGET_NOFLSH
, NOFLSH
, NOFLSH
},
3493 { TARGET_TOSTOP
, TARGET_TOSTOP
, TOSTOP
, TOSTOP
},
3494 { TARGET_ECHOCTL
, TARGET_ECHOCTL
, ECHOCTL
, ECHOCTL
},
3495 { TARGET_ECHOPRT
, TARGET_ECHOPRT
, ECHOPRT
, ECHOPRT
},
3496 { TARGET_ECHOKE
, TARGET_ECHOKE
, ECHOKE
, ECHOKE
},
3497 { TARGET_FLUSHO
, TARGET_FLUSHO
, FLUSHO
, FLUSHO
},
3498 { TARGET_PENDIN
, TARGET_PENDIN
, PENDIN
, PENDIN
},
3499 { TARGET_IEXTEN
, TARGET_IEXTEN
, IEXTEN
, IEXTEN
},
3503 static void target_to_host_termios (void *dst
, const void *src
)
3505 struct host_termios
*host
= dst
;
3506 const struct target_termios
*target
= src
;
3509 target_to_host_bitmask(tswap32(target
->c_iflag
), iflag_tbl
);
3511 target_to_host_bitmask(tswap32(target
->c_oflag
), oflag_tbl
);
3513 target_to_host_bitmask(tswap32(target
->c_cflag
), cflag_tbl
);
3515 target_to_host_bitmask(tswap32(target
->c_lflag
), lflag_tbl
);
3516 host
->c_line
= target
->c_line
;
3518 memset(host
->c_cc
, 0, sizeof(host
->c_cc
));
3519 host
->c_cc
[VINTR
] = target
->c_cc
[TARGET_VINTR
];
3520 host
->c_cc
[VQUIT
] = target
->c_cc
[TARGET_VQUIT
];
3521 host
->c_cc
[VERASE
] = target
->c_cc
[TARGET_VERASE
];
3522 host
->c_cc
[VKILL
] = target
->c_cc
[TARGET_VKILL
];
3523 host
->c_cc
[VEOF
] = target
->c_cc
[TARGET_VEOF
];
3524 host
->c_cc
[VTIME
] = target
->c_cc
[TARGET_VTIME
];
3525 host
->c_cc
[VMIN
] = target
->c_cc
[TARGET_VMIN
];
3526 host
->c_cc
[VSWTC
] = target
->c_cc
[TARGET_VSWTC
];
3527 host
->c_cc
[VSTART
] = target
->c_cc
[TARGET_VSTART
];
3528 host
->c_cc
[VSTOP
] = target
->c_cc
[TARGET_VSTOP
];
3529 host
->c_cc
[VSUSP
] = target
->c_cc
[TARGET_VSUSP
];
3530 host
->c_cc
[VEOL
] = target
->c_cc
[TARGET_VEOL
];
3531 host
->c_cc
[VREPRINT
] = target
->c_cc
[TARGET_VREPRINT
];
3532 host
->c_cc
[VDISCARD
] = target
->c_cc
[TARGET_VDISCARD
];
3533 host
->c_cc
[VWERASE
] = target
->c_cc
[TARGET_VWERASE
];
3534 host
->c_cc
[VLNEXT
] = target
->c_cc
[TARGET_VLNEXT
];
3535 host
->c_cc
[VEOL2
] = target
->c_cc
[TARGET_VEOL2
];
3538 static void host_to_target_termios (void *dst
, const void *src
)
3540 struct target_termios
*target
= dst
;
3541 const struct host_termios
*host
= src
;
3544 tswap32(host_to_target_bitmask(host
->c_iflag
, iflag_tbl
));
3546 tswap32(host_to_target_bitmask(host
->c_oflag
, oflag_tbl
));
3548 tswap32(host_to_target_bitmask(host
->c_cflag
, cflag_tbl
));
3550 tswap32(host_to_target_bitmask(host
->c_lflag
, lflag_tbl
));
3551 target
->c_line
= host
->c_line
;
3553 memset(target
->c_cc
, 0, sizeof(target
->c_cc
));
3554 target
->c_cc
[TARGET_VINTR
] = host
->c_cc
[VINTR
];
3555 target
->c_cc
[TARGET_VQUIT
] = host
->c_cc
[VQUIT
];
3556 target
->c_cc
[TARGET_VERASE
] = host
->c_cc
[VERASE
];
3557 target
->c_cc
[TARGET_VKILL
] = host
->c_cc
[VKILL
];
3558 target
->c_cc
[TARGET_VEOF
] = host
->c_cc
[VEOF
];
3559 target
->c_cc
[TARGET_VTIME
] = host
->c_cc
[VTIME
];
3560 target
->c_cc
[TARGET_VMIN
] = host
->c_cc
[VMIN
];
3561 target
->c_cc
[TARGET_VSWTC
] = host
->c_cc
[VSWTC
];
3562 target
->c_cc
[TARGET_VSTART
] = host
->c_cc
[VSTART
];
3563 target
->c_cc
[TARGET_VSTOP
] = host
->c_cc
[VSTOP
];
3564 target
->c_cc
[TARGET_VSUSP
] = host
->c_cc
[VSUSP
];
3565 target
->c_cc
[TARGET_VEOL
] = host
->c_cc
[VEOL
];
3566 target
->c_cc
[TARGET_VREPRINT
] = host
->c_cc
[VREPRINT
];
3567 target
->c_cc
[TARGET_VDISCARD
] = host
->c_cc
[VDISCARD
];
3568 target
->c_cc
[TARGET_VWERASE
] = host
->c_cc
[VWERASE
];
3569 target
->c_cc
[TARGET_VLNEXT
] = host
->c_cc
[VLNEXT
];
3570 target
->c_cc
[TARGET_VEOL2
] = host
->c_cc
[VEOL2
];
3573 static const StructEntry struct_termios_def
= {
3574 .convert
= { host_to_target_termios
, target_to_host_termios
},
3575 .size
= { sizeof(struct target_termios
), sizeof(struct host_termios
) },
3576 .align
= { __alignof__(struct target_termios
), __alignof__(struct host_termios
) },
3579 static bitmask_transtbl mmap_flags_tbl
[] = {
3580 { TARGET_MAP_SHARED
, TARGET_MAP_SHARED
, MAP_SHARED
, MAP_SHARED
},
3581 { TARGET_MAP_PRIVATE
, TARGET_MAP_PRIVATE
, MAP_PRIVATE
, MAP_PRIVATE
},
3582 { TARGET_MAP_FIXED
, TARGET_MAP_FIXED
, MAP_FIXED
, MAP_FIXED
},
3583 { TARGET_MAP_ANONYMOUS
, TARGET_MAP_ANONYMOUS
, MAP_ANONYMOUS
, MAP_ANONYMOUS
},
3584 { TARGET_MAP_GROWSDOWN
, TARGET_MAP_GROWSDOWN
, MAP_GROWSDOWN
, MAP_GROWSDOWN
},
3585 { TARGET_MAP_DENYWRITE
, TARGET_MAP_DENYWRITE
, MAP_DENYWRITE
, MAP_DENYWRITE
},
3586 { TARGET_MAP_EXECUTABLE
, TARGET_MAP_EXECUTABLE
, MAP_EXECUTABLE
, MAP_EXECUTABLE
},
3587 { TARGET_MAP_LOCKED
, TARGET_MAP_LOCKED
, MAP_LOCKED
, MAP_LOCKED
},
3591 #if defined(TARGET_I386)
3593 /* NOTE: there is really one LDT for all the threads */
3594 static uint8_t *ldt_table
;
3596 static abi_long
read_ldt(abi_ulong ptr
, unsigned long bytecount
)
3603 size
= TARGET_LDT_ENTRIES
* TARGET_LDT_ENTRY_SIZE
;
3604 if (size
> bytecount
)
3606 p
= lock_user(VERIFY_WRITE
, ptr
, size
, 0);
3608 return -TARGET_EFAULT
;
3609 /* ??? Should this by byteswapped? */
3610 memcpy(p
, ldt_table
, size
);
3611 unlock_user(p
, ptr
, size
);
3615 /* XXX: add locking support */
3616 static abi_long
write_ldt(CPUX86State
*env
,
3617 abi_ulong ptr
, unsigned long bytecount
, int oldmode
)
3619 struct target_modify_ldt_ldt_s ldt_info
;
3620 struct target_modify_ldt_ldt_s
*target_ldt_info
;
3621 int seg_32bit
, contents
, read_exec_only
, limit_in_pages
;
3622 int seg_not_present
, useable
, lm
;
3623 uint32_t *lp
, entry_1
, entry_2
;
3625 if (bytecount
!= sizeof(ldt_info
))
3626 return -TARGET_EINVAL
;
3627 if (!lock_user_struct(VERIFY_READ
, target_ldt_info
, ptr
, 1))
3628 return -TARGET_EFAULT
;
3629 ldt_info
.entry_number
= tswap32(target_ldt_info
->entry_number
);
3630 ldt_info
.base_addr
= tswapl(target_ldt_info
->base_addr
);
3631 ldt_info
.limit
= tswap32(target_ldt_info
->limit
);
3632 ldt_info
.flags
= tswap32(target_ldt_info
->flags
);
3633 unlock_user_struct(target_ldt_info
, ptr
, 0);
3635 if (ldt_info
.entry_number
>= TARGET_LDT_ENTRIES
)
3636 return -TARGET_EINVAL
;
3637 seg_32bit
= ldt_info
.flags
& 1;
3638 contents
= (ldt_info
.flags
>> 1) & 3;
3639 read_exec_only
= (ldt_info
.flags
>> 3) & 1;
3640 limit_in_pages
= (ldt_info
.flags
>> 4) & 1;
3641 seg_not_present
= (ldt_info
.flags
>> 5) & 1;
3642 useable
= (ldt_info
.flags
>> 6) & 1;
3646 lm
= (ldt_info
.flags
>> 7) & 1;
3648 if (contents
== 3) {
3650 return -TARGET_EINVAL
;
3651 if (seg_not_present
== 0)
3652 return -TARGET_EINVAL
;
3654 /* allocate the LDT */
3656 env
->ldt
.base
= target_mmap(0,
3657 TARGET_LDT_ENTRIES
* TARGET_LDT_ENTRY_SIZE
,
3658 PROT_READ
|PROT_WRITE
,
3659 MAP_ANONYMOUS
|MAP_PRIVATE
, -1, 0);
3660 if (env
->ldt
.base
== -1)
3661 return -TARGET_ENOMEM
;
3662 memset(g2h(env
->ldt
.base
), 0,
3663 TARGET_LDT_ENTRIES
* TARGET_LDT_ENTRY_SIZE
);
3664 env
->ldt
.limit
= 0xffff;
3665 ldt_table
= g2h(env
->ldt
.base
);
3668 /* NOTE: same code as Linux kernel */
3669 /* Allow LDTs to be cleared by the user. */
3670 if (ldt_info
.base_addr
== 0 && ldt_info
.limit
== 0) {
3673 read_exec_only
== 1 &&
3675 limit_in_pages
== 0 &&
3676 seg_not_present
== 1 &&
3684 entry_1
= ((ldt_info
.base_addr
& 0x0000ffff) << 16) |
3685 (ldt_info
.limit
& 0x0ffff);
3686 entry_2
= (ldt_info
.base_addr
& 0xff000000) |
3687 ((ldt_info
.base_addr
& 0x00ff0000) >> 16) |
3688 (ldt_info
.limit
& 0xf0000) |
3689 ((read_exec_only
^ 1) << 9) |
3691 ((seg_not_present
^ 1) << 15) |
3693 (limit_in_pages
<< 23) |
3697 entry_2
|= (useable
<< 20);
3699 /* Install the new entry ... */
3701 lp
= (uint32_t *)(ldt_table
+ (ldt_info
.entry_number
<< 3));
3702 lp
[0] = tswap32(entry_1
);
3703 lp
[1] = tswap32(entry_2
);
3707 /* specific and weird i386 syscalls */
3708 static abi_long
do_modify_ldt(CPUX86State
*env
, int func
, abi_ulong ptr
,
3709 unsigned long bytecount
)
3715 ret
= read_ldt(ptr
, bytecount
);
3718 ret
= write_ldt(env
, ptr
, bytecount
, 1);
3721 ret
= write_ldt(env
, ptr
, bytecount
, 0);
3724 ret
= -TARGET_ENOSYS
;
3730 #if defined(TARGET_I386) && defined(TARGET_ABI32)
3731 static abi_long
do_set_thread_area(CPUX86State
*env
, abi_ulong ptr
)
3733 uint64_t *gdt_table
= g2h(env
->gdt
.base
);
3734 struct target_modify_ldt_ldt_s ldt_info
;
3735 struct target_modify_ldt_ldt_s
*target_ldt_info
;
3736 int seg_32bit
, contents
, read_exec_only
, limit_in_pages
;
3737 int seg_not_present
, useable
, lm
;
3738 uint32_t *lp
, entry_1
, entry_2
;
3741 lock_user_struct(VERIFY_WRITE
, target_ldt_info
, ptr
, 1);
3742 if (!target_ldt_info
)
3743 return -TARGET_EFAULT
;
3744 ldt_info
.entry_number
= tswap32(target_ldt_info
->entry_number
);
3745 ldt_info
.base_addr
= tswapl(target_ldt_info
->base_addr
);
3746 ldt_info
.limit
= tswap32(target_ldt_info
->limit
);
3747 ldt_info
.flags
= tswap32(target_ldt_info
->flags
);
3748 if (ldt_info
.entry_number
== -1) {
3749 for (i
=TARGET_GDT_ENTRY_TLS_MIN
; i
<=TARGET_GDT_ENTRY_TLS_MAX
; i
++) {
3750 if (gdt_table
[i
] == 0) {
3751 ldt_info
.entry_number
= i
;
3752 target_ldt_info
->entry_number
= tswap32(i
);
3757 unlock_user_struct(target_ldt_info
, ptr
, 1);
3759 if (ldt_info
.entry_number
< TARGET_GDT_ENTRY_TLS_MIN
||
3760 ldt_info
.entry_number
> TARGET_GDT_ENTRY_TLS_MAX
)
3761 return -TARGET_EINVAL
;
3762 seg_32bit
= ldt_info
.flags
& 1;
3763 contents
= (ldt_info
.flags
>> 1) & 3;
3764 read_exec_only
= (ldt_info
.flags
>> 3) & 1;
3765 limit_in_pages
= (ldt_info
.flags
>> 4) & 1;
3766 seg_not_present
= (ldt_info
.flags
>> 5) & 1;
3767 useable
= (ldt_info
.flags
>> 6) & 1;
3771 lm
= (ldt_info
.flags
>> 7) & 1;
3774 if (contents
== 3) {
3775 if (seg_not_present
== 0)
3776 return -TARGET_EINVAL
;
3779 /* NOTE: same code as Linux kernel */
3780 /* Allow LDTs to be cleared by the user. */
3781 if (ldt_info
.base_addr
== 0 && ldt_info
.limit
== 0) {
3782 if ((contents
== 0 &&
3783 read_exec_only
== 1 &&
3785 limit_in_pages
== 0 &&
3786 seg_not_present
== 1 &&
3794 entry_1
= ((ldt_info
.base_addr
& 0x0000ffff) << 16) |
3795 (ldt_info
.limit
& 0x0ffff);
3796 entry_2
= (ldt_info
.base_addr
& 0xff000000) |
3797 ((ldt_info
.base_addr
& 0x00ff0000) >> 16) |
3798 (ldt_info
.limit
& 0xf0000) |
3799 ((read_exec_only
^ 1) << 9) |
3801 ((seg_not_present
^ 1) << 15) |
3803 (limit_in_pages
<< 23) |
3808 /* Install the new entry ... */
3810 lp
= (uint32_t *)(gdt_table
+ ldt_info
.entry_number
);
3811 lp
[0] = tswap32(entry_1
);
3812 lp
[1] = tswap32(entry_2
);
3816 static abi_long
do_get_thread_area(CPUX86State
*env
, abi_ulong ptr
)
3818 struct target_modify_ldt_ldt_s
*target_ldt_info
;
3819 uint64_t *gdt_table
= g2h(env
->gdt
.base
);
3820 uint32_t base_addr
, limit
, flags
;
3821 int seg_32bit
, contents
, read_exec_only
, limit_in_pages
, idx
;
3822 int seg_not_present
, useable
, lm
;
3823 uint32_t *lp
, entry_1
, entry_2
;
3825 lock_user_struct(VERIFY_WRITE
, target_ldt_info
, ptr
, 1);
3826 if (!target_ldt_info
)
3827 return -TARGET_EFAULT
;
3828 idx
= tswap32(target_ldt_info
->entry_number
);
3829 if (idx
< TARGET_GDT_ENTRY_TLS_MIN
||
3830 idx
> TARGET_GDT_ENTRY_TLS_MAX
) {
3831 unlock_user_struct(target_ldt_info
, ptr
, 1);
3832 return -TARGET_EINVAL
;
3834 lp
= (uint32_t *)(gdt_table
+ idx
);
3835 entry_1
= tswap32(lp
[0]);
3836 entry_2
= tswap32(lp
[1]);
3838 read_exec_only
= ((entry_2
>> 9) & 1) ^ 1;
3839 contents
= (entry_2
>> 10) & 3;
3840 seg_not_present
= ((entry_2
>> 15) & 1) ^ 1;
3841 seg_32bit
= (entry_2
>> 22) & 1;
3842 limit_in_pages
= (entry_2
>> 23) & 1;
3843 useable
= (entry_2
>> 20) & 1;
3847 lm
= (entry_2
>> 21) & 1;
3849 flags
= (seg_32bit
<< 0) | (contents
<< 1) |
3850 (read_exec_only
<< 3) | (limit_in_pages
<< 4) |
3851 (seg_not_present
<< 5) | (useable
<< 6) | (lm
<< 7);
3852 limit
= (entry_1
& 0xffff) | (entry_2
& 0xf0000);
3853 base_addr
= (entry_1
>> 16) |
3854 (entry_2
& 0xff000000) |
3855 ((entry_2
& 0xff) << 16);
3856 target_ldt_info
->base_addr
= tswapl(base_addr
);
3857 target_ldt_info
->limit
= tswap32(limit
);
3858 target_ldt_info
->flags
= tswap32(flags
);
3859 unlock_user_struct(target_ldt_info
, ptr
, 1);
3862 #endif /* TARGET_I386 && TARGET_ABI32 */
3864 #ifndef TARGET_ABI32
3865 static abi_long
do_arch_prctl(CPUX86State
*env
, int code
, abi_ulong addr
)
3872 case TARGET_ARCH_SET_GS
:
3873 case TARGET_ARCH_SET_FS
:
3874 if (code
== TARGET_ARCH_SET_GS
)
3878 cpu_x86_load_seg(env
, idx
, 0);
3879 env
->segs
[idx
].base
= addr
;
3881 case TARGET_ARCH_GET_GS
:
3882 case TARGET_ARCH_GET_FS
:
3883 if (code
== TARGET_ARCH_GET_GS
)
3887 val
= env
->segs
[idx
].base
;
3888 if (put_user(val
, addr
, abi_ulong
))
3889 ret
= -TARGET_EFAULT
;
3892 ret
= -TARGET_EINVAL
;
3899 #endif /* defined(TARGET_I386) */
3901 #define NEW_STACK_SIZE 0x40000
3903 #if defined(CONFIG_USE_NPTL)
3905 static pthread_mutex_t clone_lock
= PTHREAD_MUTEX_INITIALIZER
;
3908 pthread_mutex_t mutex
;
3909 pthread_cond_t cond
;
3912 abi_ulong child_tidptr
;
3913 abi_ulong parent_tidptr
;
3917 static void *clone_func(void *arg
)
3919 new_thread_info
*info
= arg
;
3925 ts
= (TaskState
*)thread_env
->opaque
;
3926 info
->tid
= gettid();
3927 env
->host_tid
= info
->tid
;
3929 if (info
->child_tidptr
)
3930 put_user_u32(info
->tid
, info
->child_tidptr
);
3931 if (info
->parent_tidptr
)
3932 put_user_u32(info
->tid
, info
->parent_tidptr
);
3933 /* Enable signals. */
3934 sigprocmask(SIG_SETMASK
, &info
->sigmask
, NULL
);
3935 /* Signal to the parent that we're ready. */
3936 pthread_mutex_lock(&info
->mutex
);
3937 pthread_cond_broadcast(&info
->cond
);
3938 pthread_mutex_unlock(&info
->mutex
);
3939 /* Wait until the parent has finshed initializing the tls state. */
3940 pthread_mutex_lock(&clone_lock
);
3941 pthread_mutex_unlock(&clone_lock
);
3948 static int clone_func(void *arg
)
3950 CPUState
*env
= arg
;
3957 /* do_fork() Must return host values and target errnos (unlike most
3958 do_*() functions). */
3959 static int do_fork(CPUState
*env
, unsigned int flags
, abi_ulong newsp
,
3960 abi_ulong parent_tidptr
, target_ulong newtls
,
3961 abi_ulong child_tidptr
)
3966 #if defined(CONFIG_USE_NPTL)
3967 unsigned int nptl_flags
;
3973 /* Emulate vfork() with fork() */
3974 if (flags
& CLONE_VFORK
)
3975 flags
&= ~(CLONE_VFORK
| CLONE_VM
);
3977 if (flags
& CLONE_VM
) {
3978 TaskState
*parent_ts
= (TaskState
*)env
->opaque
;
3979 #if defined(CONFIG_USE_NPTL)
3980 new_thread_info info
;
3981 pthread_attr_t attr
;
3983 ts
= qemu_mallocz(sizeof(TaskState
));
3984 init_task_state(ts
);
3985 /* we create a new CPU instance. */
3986 new_env
= cpu_copy(env
);
3987 #if defined(TARGET_I386) || defined(TARGET_SPARC) || defined(TARGET_PPC)
3990 /* Init regs that differ from the parent. */
3991 cpu_clone_regs(new_env
, newsp
);
3992 new_env
->opaque
= ts
;
3993 ts
->bprm
= parent_ts
->bprm
;
3994 ts
->info
= parent_ts
->info
;
3995 #if defined(CONFIG_USE_NPTL)
3997 flags
&= ~CLONE_NPTL_FLAGS2
;
3999 if (nptl_flags
& CLONE_CHILD_CLEARTID
) {
4000 ts
->child_tidptr
= child_tidptr
;
4003 if (nptl_flags
& CLONE_SETTLS
)
4004 cpu_set_tls (new_env
, newtls
);
4006 /* Grab a mutex so that thread setup appears atomic. */
4007 pthread_mutex_lock(&clone_lock
);
4009 memset(&info
, 0, sizeof(info
));
4010 pthread_mutex_init(&info
.mutex
, NULL
);
4011 pthread_mutex_lock(&info
.mutex
);
4012 pthread_cond_init(&info
.cond
, NULL
);
4014 if (nptl_flags
& CLONE_CHILD_SETTID
)
4015 info
.child_tidptr
= child_tidptr
;
4016 if (nptl_flags
& CLONE_PARENT_SETTID
)
4017 info
.parent_tidptr
= parent_tidptr
;
4019 ret
= pthread_attr_init(&attr
);
4020 ret
= pthread_attr_setstacksize(&attr
, NEW_STACK_SIZE
);
4021 ret
= pthread_attr_setdetachstate(&attr
, PTHREAD_CREATE_DETACHED
);
4022 /* It is not safe to deliver signals until the child has finished
4023 initializing, so temporarily block all signals. */
4024 sigfillset(&sigmask
);
4025 sigprocmask(SIG_BLOCK
, &sigmask
, &info
.sigmask
);
4027 ret
= pthread_create(&info
.thread
, &attr
, clone_func
, &info
);
4028 /* TODO: Free new CPU state if thread creation failed. */
4030 sigprocmask(SIG_SETMASK
, &info
.sigmask
, NULL
);
4031 pthread_attr_destroy(&attr
);
4033 /* Wait for the child to initialize. */
4034 pthread_cond_wait(&info
.cond
, &info
.mutex
);
4036 if (flags
& CLONE_PARENT_SETTID
)
4037 put_user_u32(ret
, parent_tidptr
);
4041 pthread_mutex_unlock(&info
.mutex
);
4042 pthread_cond_destroy(&info
.cond
);
4043 pthread_mutex_destroy(&info
.mutex
);
4044 pthread_mutex_unlock(&clone_lock
);
4046 if (flags
& CLONE_NPTL_FLAGS2
)
4048 /* This is probably going to die very quickly, but do it anyway. */
4049 new_stack
= qemu_mallocz (NEW_STACK_SIZE
);
4051 ret
= __clone2(clone_func
, new_stack
, NEW_STACK_SIZE
, flags
, new_env
);
4053 ret
= clone(clone_func
, new_stack
+ NEW_STACK_SIZE
, flags
, new_env
);
4057 /* if no CLONE_VM, we consider it is a fork */
4058 if ((flags
& ~(CSIGNAL
| CLONE_NPTL_FLAGS2
)) != 0)
4063 /* Child Process. */
4064 cpu_clone_regs(env
, newsp
);
4066 #if defined(CONFIG_USE_NPTL)
4067 /* There is a race condition here. The parent process could
4068 theoretically read the TID in the child process before the child
4069 tid is set. This would require using either ptrace
4070 (not implemented) or having *_tidptr to point at a shared memory
4071 mapping. We can't repeat the spinlock hack used above because
4072 the child process gets its own copy of the lock. */
4073 if (flags
& CLONE_CHILD_SETTID
)
4074 put_user_u32(gettid(), child_tidptr
);
4075 if (flags
& CLONE_PARENT_SETTID
)
4076 put_user_u32(gettid(), parent_tidptr
);
4077 ts
= (TaskState
*)env
->opaque
;
4078 if (flags
& CLONE_SETTLS
)
4079 cpu_set_tls (env
, newtls
);
4080 if (flags
& CLONE_CHILD_CLEARTID
)
4081 ts
->child_tidptr
= child_tidptr
;
4090 /* warning : doesn't handle linux specific flags... */
4091 static int target_to_host_fcntl_cmd(int cmd
)
4094 case TARGET_F_DUPFD
:
4095 case TARGET_F_GETFD
:
4096 case TARGET_F_SETFD
:
4097 case TARGET_F_GETFL
:
4098 case TARGET_F_SETFL
:
4100 case TARGET_F_GETLK
:
4102 case TARGET_F_SETLK
:
4104 case TARGET_F_SETLKW
:
4106 case TARGET_F_GETOWN
:
4108 case TARGET_F_SETOWN
:
4110 case TARGET_F_GETSIG
:
4112 case TARGET_F_SETSIG
:
4114 #if TARGET_ABI_BITS == 32
4115 case TARGET_F_GETLK64
:
4117 case TARGET_F_SETLK64
:
4119 case TARGET_F_SETLKW64
:
4122 case TARGET_F_SETLEASE
:
4124 case TARGET_F_GETLEASE
:
4126 #ifdef F_DUPFD_CLOEXEC
4127 case TARGET_F_DUPFD_CLOEXEC
:
4128 return F_DUPFD_CLOEXEC
;
4130 case TARGET_F_NOTIFY
:
4133 return -TARGET_EINVAL
;
4135 return -TARGET_EINVAL
;
4138 static abi_long
do_fcntl(int fd
, int cmd
, abi_ulong arg
)
4141 struct target_flock
*target_fl
;
4142 struct flock64 fl64
;
4143 struct target_flock64
*target_fl64
;
4145 int host_cmd
= target_to_host_fcntl_cmd(cmd
);
4147 if (host_cmd
== -TARGET_EINVAL
)
4151 case TARGET_F_GETLK
:
4152 if (!lock_user_struct(VERIFY_READ
, target_fl
, arg
, 1))
4153 return -TARGET_EFAULT
;
4154 fl
.l_type
= tswap16(target_fl
->l_type
);
4155 fl
.l_whence
= tswap16(target_fl
->l_whence
);
4156 fl
.l_start
= tswapl(target_fl
->l_start
);
4157 fl
.l_len
= tswapl(target_fl
->l_len
);
4158 fl
.l_pid
= tswap32(target_fl
->l_pid
);
4159 unlock_user_struct(target_fl
, arg
, 0);
4160 ret
= get_errno(fcntl(fd
, host_cmd
, &fl
));
4162 if (!lock_user_struct(VERIFY_WRITE
, target_fl
, arg
, 0))
4163 return -TARGET_EFAULT
;
4164 target_fl
->l_type
= tswap16(fl
.l_type
);
4165 target_fl
->l_whence
= tswap16(fl
.l_whence
);
4166 target_fl
->l_start
= tswapl(fl
.l_start
);
4167 target_fl
->l_len
= tswapl(fl
.l_len
);
4168 target_fl
->l_pid
= tswap32(fl
.l_pid
);
4169 unlock_user_struct(target_fl
, arg
, 1);
4173 case TARGET_F_SETLK
:
4174 case TARGET_F_SETLKW
:
4175 if (!lock_user_struct(VERIFY_READ
, target_fl
, arg
, 1))
4176 return -TARGET_EFAULT
;
4177 fl
.l_type
= tswap16(target_fl
->l_type
);
4178 fl
.l_whence
= tswap16(target_fl
->l_whence
);
4179 fl
.l_start
= tswapl(target_fl
->l_start
);
4180 fl
.l_len
= tswapl(target_fl
->l_len
);
4181 fl
.l_pid
= tswap32(target_fl
->l_pid
);
4182 unlock_user_struct(target_fl
, arg
, 0);
4183 ret
= get_errno(fcntl(fd
, host_cmd
, &fl
));
4186 case TARGET_F_GETLK64
:
4187 if (!lock_user_struct(VERIFY_READ
, target_fl64
, arg
, 1))
4188 return -TARGET_EFAULT
;
4189 fl64
.l_type
= tswap16(target_fl64
->l_type
) >> 1;
4190 fl64
.l_whence
= tswap16(target_fl64
->l_whence
);
4191 fl64
.l_start
= tswapl(target_fl64
->l_start
);
4192 fl64
.l_len
= tswapl(target_fl64
->l_len
);
4193 fl64
.l_pid
= tswap32(target_fl64
->l_pid
);
4194 unlock_user_struct(target_fl64
, arg
, 0);
4195 ret
= get_errno(fcntl(fd
, host_cmd
, &fl64
));
4197 if (!lock_user_struct(VERIFY_WRITE
, target_fl64
, arg
, 0))
4198 return -TARGET_EFAULT
;
4199 target_fl64
->l_type
= tswap16(fl64
.l_type
) >> 1;
4200 target_fl64
->l_whence
= tswap16(fl64
.l_whence
);
4201 target_fl64
->l_start
= tswapl(fl64
.l_start
);
4202 target_fl64
->l_len
= tswapl(fl64
.l_len
);
4203 target_fl64
->l_pid
= tswap32(fl64
.l_pid
);
4204 unlock_user_struct(target_fl64
, arg
, 1);
4207 case TARGET_F_SETLK64
:
4208 case TARGET_F_SETLKW64
:
4209 if (!lock_user_struct(VERIFY_READ
, target_fl64
, arg
, 1))
4210 return -TARGET_EFAULT
;
4211 fl64
.l_type
= tswap16(target_fl64
->l_type
) >> 1;
4212 fl64
.l_whence
= tswap16(target_fl64
->l_whence
);
4213 fl64
.l_start
= tswapl(target_fl64
->l_start
);
4214 fl64
.l_len
= tswapl(target_fl64
->l_len
);
4215 fl64
.l_pid
= tswap32(target_fl64
->l_pid
);
4216 unlock_user_struct(target_fl64
, arg
, 0);
4217 ret
= get_errno(fcntl(fd
, host_cmd
, &fl64
));
4220 case TARGET_F_GETFL
:
4221 ret
= get_errno(fcntl(fd
, host_cmd
, arg
));
4223 ret
= host_to_target_bitmask(ret
, fcntl_flags_tbl
);
4227 case TARGET_F_SETFL
:
4228 ret
= get_errno(fcntl(fd
, host_cmd
, target_to_host_bitmask(arg
, fcntl_flags_tbl
)));
4231 case TARGET_F_SETOWN
:
4232 case TARGET_F_GETOWN
:
4233 case TARGET_F_SETSIG
:
4234 case TARGET_F_GETSIG
:
4235 case TARGET_F_SETLEASE
:
4236 case TARGET_F_GETLEASE
:
4237 ret
= get_errno(fcntl(fd
, host_cmd
, arg
));
4241 ret
= get_errno(fcntl(fd
, cmd
, arg
));
4249 static inline int high2lowuid(int uid
)
4257 static inline int high2lowgid(int gid
)
4265 static inline int low2highuid(int uid
)
4267 if ((int16_t)uid
== -1)
4273 static inline int low2highgid(int gid
)
4275 if ((int16_t)gid
== -1)
4280 static inline int tswapid(int id
)
4284 #else /* !USE_UID16 */
4285 static inline int high2lowuid(int uid
)
4289 static inline int high2lowgid(int gid
)
4293 static inline int low2highuid(int uid
)
4297 static inline int low2highgid(int gid
)
4301 static inline int tswapid(int id
)
4305 #endif /* USE_UID16 */
4307 void syscall_init(void)
4310 const argtype
*arg_type
;
4314 #define STRUCT(name, ...) thunk_register_struct(STRUCT_ ## name, #name, struct_ ## name ## _def);
4315 #define STRUCT_SPECIAL(name) thunk_register_struct_direct(STRUCT_ ## name, #name, &struct_ ## name ## _def);
4316 #include "syscall_types.h"
4318 #undef STRUCT_SPECIAL
4320 /* we patch the ioctl size if necessary. We rely on the fact that
4321 no ioctl has all the bits at '1' in the size field */
4323 while (ie
->target_cmd
!= 0) {
4324 if (((ie
->target_cmd
>> TARGET_IOC_SIZESHIFT
) & TARGET_IOC_SIZEMASK
) ==
4325 TARGET_IOC_SIZEMASK
) {
4326 arg_type
= ie
->arg_type
;
4327 if (arg_type
[0] != TYPE_PTR
) {
4328 fprintf(stderr
, "cannot patch size for ioctl 0x%x\n",
4333 size
= thunk_type_size(arg_type
, 0);
4334 ie
->target_cmd
= (ie
->target_cmd
&
4335 ~(TARGET_IOC_SIZEMASK
<< TARGET_IOC_SIZESHIFT
)) |
4336 (size
<< TARGET_IOC_SIZESHIFT
);
4339 /* Build target_to_host_errno_table[] table from
4340 * host_to_target_errno_table[]. */
4341 for (i
=0; i
< ERRNO_TABLE_SIZE
; i
++)
4342 target_to_host_errno_table
[host_to_target_errno_table
[i
]] = i
;
4344 /* automatic consistency check if same arch */
4345 #if (defined(__i386__) && defined(TARGET_I386) && defined(TARGET_ABI32)) || \
4346 (defined(__x86_64__) && defined(TARGET_X86_64))
4347 if (unlikely(ie
->target_cmd
!= ie
->host_cmd
)) {
4348 fprintf(stderr
, "ERROR: ioctl(%s): target=0x%x host=0x%x\n",
4349 ie
->name
, ie
->target_cmd
, ie
->host_cmd
);
4356 #if TARGET_ABI_BITS == 32
4357 static inline uint64_t target_offset64(uint32_t word0
, uint32_t word1
)
4359 #ifdef TARGET_WORDS_BIGENDIAN
4360 return ((uint64_t)word0
<< 32) | word1
;
4362 return ((uint64_t)word1
<< 32) | word0
;
4365 #else /* TARGET_ABI_BITS == 32 */
4366 static inline uint64_t target_offset64(uint64_t word0
, uint64_t word1
)
4370 #endif /* TARGET_ABI_BITS != 32 */
4372 #ifdef TARGET_NR_truncate64
4373 static inline abi_long
target_truncate64(void *cpu_env
, const char *arg1
,
4379 if (((CPUARMState
*)cpu_env
)->eabi
)
4385 return get_errno(truncate64(arg1
, target_offset64(arg2
, arg3
)));
4389 #ifdef TARGET_NR_ftruncate64
4390 static inline abi_long
target_ftruncate64(void *cpu_env
, abi_long arg1
,
4396 if (((CPUARMState
*)cpu_env
)->eabi
)
4402 return get_errno(ftruncate64(arg1
, target_offset64(arg2
, arg3
)));
4406 static inline abi_long
target_to_host_timespec(struct timespec
*host_ts
,
4407 abi_ulong target_addr
)
4409 struct target_timespec
*target_ts
;
4411 if (!lock_user_struct(VERIFY_READ
, target_ts
, target_addr
, 1))
4412 return -TARGET_EFAULT
;
4413 host_ts
->tv_sec
= tswapl(target_ts
->tv_sec
);
4414 host_ts
->tv_nsec
= tswapl(target_ts
->tv_nsec
);
4415 unlock_user_struct(target_ts
, target_addr
, 0);
4419 static inline abi_long
host_to_target_timespec(abi_ulong target_addr
,
4420 struct timespec
*host_ts
)
4422 struct target_timespec
*target_ts
;
4424 if (!lock_user_struct(VERIFY_WRITE
, target_ts
, target_addr
, 0))
4425 return -TARGET_EFAULT
;
4426 target_ts
->tv_sec
= tswapl(host_ts
->tv_sec
);
4427 target_ts
->tv_nsec
= tswapl(host_ts
->tv_nsec
);
4428 unlock_user_struct(target_ts
, target_addr
, 1);
4432 #if defined(TARGET_NR_stat64) || defined(TARGET_NR_newfstatat)
4433 static inline abi_long
host_to_target_stat64(void *cpu_env
,
4434 abi_ulong target_addr
,
4435 struct stat
*host_st
)
4438 if (((CPUARMState
*)cpu_env
)->eabi
) {
4439 struct target_eabi_stat64
*target_st
;
4441 if (!lock_user_struct(VERIFY_WRITE
, target_st
, target_addr
, 0))
4442 return -TARGET_EFAULT
;
4443 memset(target_st
, 0, sizeof(struct target_eabi_stat64
));
4444 __put_user(host_st
->st_dev
, &target_st
->st_dev
);
4445 __put_user(host_st
->st_ino
, &target_st
->st_ino
);
4446 #ifdef TARGET_STAT64_HAS_BROKEN_ST_INO
4447 __put_user(host_st
->st_ino
, &target_st
->__st_ino
);
4449 __put_user(host_st
->st_mode
, &target_st
->st_mode
);
4450 __put_user(host_st
->st_nlink
, &target_st
->st_nlink
);
4451 __put_user(host_st
->st_uid
, &target_st
->st_uid
);
4452 __put_user(host_st
->st_gid
, &target_st
->st_gid
);
4453 __put_user(host_st
->st_rdev
, &target_st
->st_rdev
);
4454 __put_user(host_st
->st_size
, &target_st
->st_size
);
4455 __put_user(host_st
->st_blksize
, &target_st
->st_blksize
);
4456 __put_user(host_st
->st_blocks
, &target_st
->st_blocks
);
4457 __put_user(host_st
->st_atime
, &target_st
->target_st_atime
);
4458 __put_user(host_st
->st_mtime
, &target_st
->target_st_mtime
);
4459 __put_user(host_st
->st_ctime
, &target_st
->target_st_ctime
);
4460 unlock_user_struct(target_st
, target_addr
, 1);
4464 #if TARGET_ABI_BITS == 64 && !defined(TARGET_ALPHA)
4465 struct target_stat
*target_st
;
4467 struct target_stat64
*target_st
;
4470 if (!lock_user_struct(VERIFY_WRITE
, target_st
, target_addr
, 0))
4471 return -TARGET_EFAULT
;
4472 memset(target_st
, 0, sizeof(*target_st
));
4473 __put_user(host_st
->st_dev
, &target_st
->st_dev
);
4474 __put_user(host_st
->st_ino
, &target_st
->st_ino
);
4475 #ifdef TARGET_STAT64_HAS_BROKEN_ST_INO
4476 __put_user(host_st
->st_ino
, &target_st
->__st_ino
);
4478 __put_user(host_st
->st_mode
, &target_st
->st_mode
);
4479 __put_user(host_st
->st_nlink
, &target_st
->st_nlink
);
4480 __put_user(host_st
->st_uid
, &target_st
->st_uid
);
4481 __put_user(host_st
->st_gid
, &target_st
->st_gid
);
4482 __put_user(host_st
->st_rdev
, &target_st
->st_rdev
);
4483 /* XXX: better use of kernel struct */
4484 __put_user(host_st
->st_size
, &target_st
->st_size
);
4485 __put_user(host_st
->st_blksize
, &target_st
->st_blksize
);
4486 __put_user(host_st
->st_blocks
, &target_st
->st_blocks
);
4487 __put_user(host_st
->st_atime
, &target_st
->target_st_atime
);
4488 __put_user(host_st
->st_mtime
, &target_st
->target_st_mtime
);
4489 __put_user(host_st
->st_ctime
, &target_st
->target_st_ctime
);
4490 unlock_user_struct(target_st
, target_addr
, 1);
4497 #if defined(CONFIG_USE_NPTL)
4498 /* ??? Using host futex calls even when target atomic operations
4499 are not really atomic probably breaks things. However implementing
4500 futexes locally would make futexes shared between multiple processes
4501 tricky. However they're probably useless because guest atomic
4502 operations won't work either. */
4503 static int do_futex(target_ulong uaddr
, int op
, int val
, target_ulong timeout
,
4504 target_ulong uaddr2
, int val3
)
4506 struct timespec ts
, *pts
;
4509 /* ??? We assume FUTEX_* constants are the same on both host
4511 #ifdef FUTEX_CMD_MASK
4512 base_op
= op
& FUTEX_CMD_MASK
;
4520 target_to_host_timespec(pts
, timeout
);
4524 return get_errno(sys_futex(g2h(uaddr
), op
, tswap32(val
),
4527 return get_errno(sys_futex(g2h(uaddr
), op
, val
, NULL
, NULL
, 0));
4529 return get_errno(sys_futex(g2h(uaddr
), op
, val
, NULL
, NULL
, 0));
4531 case FUTEX_CMP_REQUEUE
:
4533 /* For FUTEX_REQUEUE, FUTEX_CMP_REQUEUE, and FUTEX_WAKE_OP, the
4534 TIMEOUT parameter is interpreted as a uint32_t by the kernel.
4535 But the prototype takes a `struct timespec *'; insert casts
4536 to satisfy the compiler. We do not need to tswap TIMEOUT
4537 since it's not compared to guest memory. */
4538 pts
= (struct timespec
*)(uintptr_t) timeout
;
4539 return get_errno(sys_futex(g2h(uaddr
), op
, val
, pts
,
4541 (base_op
== FUTEX_CMP_REQUEUE
4545 return -TARGET_ENOSYS
;
4550 /* Map host to target signal numbers for the wait family of syscalls.
4551 Assume all other status bits are the same. */
4552 static int host_to_target_waitstatus(int status
)
4554 if (WIFSIGNALED(status
)) {
4555 return host_to_target_signal(WTERMSIG(status
)) | (status
& ~0x7f);
4557 if (WIFSTOPPED(status
)) {
4558 return (host_to_target_signal(WSTOPSIG(status
)) << 8)
4564 int get_osversion(void)
4566 static int osversion
;
4567 struct new_utsname buf
;
4572 if (qemu_uname_release
&& *qemu_uname_release
) {
4573 s
= qemu_uname_release
;
4575 if (sys_uname(&buf
))
4580 for (i
= 0; i
< 3; i
++) {
4582 while (*s
>= '0' && *s
<= '9') {
4587 tmp
= (tmp
<< 8) + n
;
4595 /* do_syscall() should always have a single exit point at the end so
4596 that actions, such as logging of syscall results, can be performed.
4597 All errnos that do_syscall() returns must be -TARGET_<errcode>. */
4598 abi_long
do_syscall(void *cpu_env
, int num
, abi_long arg1
,
4599 abi_long arg2
, abi_long arg3
, abi_long arg4
,
4600 abi_long arg5
, abi_long arg6
, abi_long arg7
,
4609 gemu_log("syscall %d", num
);
4612 print_syscall(num
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
4615 case TARGET_NR_exit
:
4616 #ifdef CONFIG_USE_NPTL
4617 /* In old applications this may be used to implement _exit(2).
4618 However in threaded applictions it is used for thread termination,
4619 and _exit_group is used for application termination.
4620 Do thread termination if we have more then one thread. */
4621 /* FIXME: This probably breaks if a signal arrives. We should probably
4622 be disabling signals. */
4623 if (first_cpu
->next_cpu
) {
4631 while (p
&& p
!= (CPUState
*)cpu_env
) {
4632 lastp
= &p
->next_cpu
;
4635 /* If we didn't find the CPU for this thread then something is
4639 /* Remove the CPU from the list. */
4640 *lastp
= p
->next_cpu
;
4642 ts
= ((CPUState
*)cpu_env
)->opaque
;
4643 if (ts
->child_tidptr
) {
4644 put_user_u32(0, ts
->child_tidptr
);
4645 sys_futex(g2h(ts
->child_tidptr
), FUTEX_WAKE
, INT_MAX
,
4657 gdb_exit(cpu_env
, arg1
);
4659 ret
= 0; /* avoid warning */
4661 case TARGET_NR_read
:
4665 if (!(p
= lock_user(VERIFY_WRITE
, arg2
, arg3
, 0)))
4667 ret
= get_errno(read(arg1
, p
, arg3
));
4668 unlock_user(p
, arg2
, ret
);
4671 case TARGET_NR_write
:
4672 if (!(p
= lock_user(VERIFY_READ
, arg2
, arg3
, 1)))
4674 ret
= get_errno(write(arg1
, p
, arg3
));
4675 unlock_user(p
, arg2
, 0);
4677 case TARGET_NR_open
:
4678 if (!(p
= lock_user_string(arg1
)))
4680 ret
= get_errno(open(path(p
),
4681 target_to_host_bitmask(arg2
, fcntl_flags_tbl
),
4683 unlock_user(p
, arg1
, 0);
4685 #if defined(TARGET_NR_openat) && defined(__NR_openat)
4686 case TARGET_NR_openat
:
4687 if (!(p
= lock_user_string(arg2
)))
4689 ret
= get_errno(sys_openat(arg1
,
4691 target_to_host_bitmask(arg3
, fcntl_flags_tbl
),
4693 unlock_user(p
, arg2
, 0);
4696 case TARGET_NR_close
:
4697 ret
= get_errno(close(arg1
));
4702 case TARGET_NR_fork
:
4703 ret
= get_errno(do_fork(cpu_env
, SIGCHLD
, 0, 0, 0, 0));
4705 #ifdef TARGET_NR_waitpid
4706 case TARGET_NR_waitpid
:
4709 ret
= get_errno(waitpid(arg1
, &status
, arg3
));
4710 if (!is_error(ret
) && arg2
4711 && put_user_s32(host_to_target_waitstatus(status
), arg2
))
4716 #ifdef TARGET_NR_waitid
4717 case TARGET_NR_waitid
:
4721 ret
= get_errno(waitid(arg1
, arg2
, &info
, arg4
));
4722 if (!is_error(ret
) && arg3
&& info
.si_pid
!= 0) {
4723 if (!(p
= lock_user(VERIFY_WRITE
, arg3
, sizeof(target_siginfo_t
), 0)))
4725 host_to_target_siginfo(p
, &info
);
4726 unlock_user(p
, arg3
, sizeof(target_siginfo_t
));
4731 #ifdef TARGET_NR_creat /* not on alpha */
4732 case TARGET_NR_creat
:
4733 if (!(p
= lock_user_string(arg1
)))
4735 ret
= get_errno(creat(p
, arg2
));
4736 unlock_user(p
, arg1
, 0);
4739 case TARGET_NR_link
:
4742 p
= lock_user_string(arg1
);
4743 p2
= lock_user_string(arg2
);
4745 ret
= -TARGET_EFAULT
;
4747 ret
= get_errno(link(p
, p2
));
4748 unlock_user(p2
, arg2
, 0);
4749 unlock_user(p
, arg1
, 0);
4752 #if defined(TARGET_NR_linkat) && defined(__NR_linkat)
4753 case TARGET_NR_linkat
:
4758 p
= lock_user_string(arg2
);
4759 p2
= lock_user_string(arg4
);
4761 ret
= -TARGET_EFAULT
;
4763 ret
= get_errno(sys_linkat(arg1
, p
, arg3
, p2
, arg5
));
4764 unlock_user(p
, arg2
, 0);
4765 unlock_user(p2
, arg4
, 0);
4769 case TARGET_NR_unlink
:
4770 if (!(p
= lock_user_string(arg1
)))
4772 ret
= get_errno(unlink(p
));
4773 unlock_user(p
, arg1
, 0);
4775 #if defined(TARGET_NR_unlinkat) && defined(__NR_unlinkat)
4776 case TARGET_NR_unlinkat
:
4777 if (!(p
= lock_user_string(arg2
)))
4779 ret
= get_errno(sys_unlinkat(arg1
, p
, arg3
));
4780 unlock_user(p
, arg2
, 0);
4783 case TARGET_NR_execve
:
4785 char **argp
, **envp
;
4788 abi_ulong guest_argp
;
4789 abi_ulong guest_envp
;
4795 for (gp
= guest_argp
; gp
; gp
+= sizeof(abi_ulong
)) {
4796 if (get_user_ual(addr
, gp
))
4804 for (gp
= guest_envp
; gp
; gp
+= sizeof(abi_ulong
)) {
4805 if (get_user_ual(addr
, gp
))
4812 argp
= alloca((argc
+ 1) * sizeof(void *));
4813 envp
= alloca((envc
+ 1) * sizeof(void *));
4815 for (gp
= guest_argp
, q
= argp
; gp
;
4816 gp
+= sizeof(abi_ulong
), q
++) {
4817 if (get_user_ual(addr
, gp
))
4821 if (!(*q
= lock_user_string(addr
)))
4826 for (gp
= guest_envp
, q
= envp
; gp
;
4827 gp
+= sizeof(abi_ulong
), q
++) {
4828 if (get_user_ual(addr
, gp
))
4832 if (!(*q
= lock_user_string(addr
)))
4837 if (!(p
= lock_user_string(arg1
)))
4839 ret
= get_errno(execve(p
, argp
, envp
));
4840 unlock_user(p
, arg1
, 0);
4845 ret
= -TARGET_EFAULT
;
4848 for (gp
= guest_argp
, q
= argp
; *q
;
4849 gp
+= sizeof(abi_ulong
), q
++) {
4850 if (get_user_ual(addr
, gp
)
4853 unlock_user(*q
, addr
, 0);
4855 for (gp
= guest_envp
, q
= envp
; *q
;
4856 gp
+= sizeof(abi_ulong
), q
++) {
4857 if (get_user_ual(addr
, gp
)
4860 unlock_user(*q
, addr
, 0);
4864 case TARGET_NR_chdir
:
4865 if (!(p
= lock_user_string(arg1
)))
4867 ret
= get_errno(chdir(p
));
4868 unlock_user(p
, arg1
, 0);
4870 #ifdef TARGET_NR_time
4871 case TARGET_NR_time
:
4874 ret
= get_errno(time(&host_time
));
4877 && put_user_sal(host_time
, arg1
))
4882 case TARGET_NR_mknod
:
4883 if (!(p
= lock_user_string(arg1
)))
4885 ret
= get_errno(mknod(p
, arg2
, arg3
));
4886 unlock_user(p
, arg1
, 0);
4888 #if defined(TARGET_NR_mknodat) && defined(__NR_mknodat)
4889 case TARGET_NR_mknodat
:
4890 if (!(p
= lock_user_string(arg2
)))
4892 ret
= get_errno(sys_mknodat(arg1
, p
, arg3
, arg4
));
4893 unlock_user(p
, arg2
, 0);
4896 case TARGET_NR_chmod
:
4897 if (!(p
= lock_user_string(arg1
)))
4899 ret
= get_errno(chmod(p
, arg2
));
4900 unlock_user(p
, arg1
, 0);
4902 #ifdef TARGET_NR_break
4903 case TARGET_NR_break
:
4906 #ifdef TARGET_NR_oldstat
4907 case TARGET_NR_oldstat
:
4910 case TARGET_NR_lseek
:
4911 ret
= get_errno(lseek(arg1
, arg2
, arg3
));
4913 #if defined(TARGET_NR_getxpid) && defined(TARGET_ALPHA)
4914 /* Alpha specific */
4915 case TARGET_NR_getxpid
:
4916 ((CPUAlphaState
*)cpu_env
)->ir
[IR_A4
] = getppid();
4917 ret
= get_errno(getpid());
4920 #ifdef TARGET_NR_getpid
4921 case TARGET_NR_getpid
:
4922 ret
= get_errno(getpid());
4925 case TARGET_NR_mount
:
4927 /* need to look at the data field */
4929 p
= lock_user_string(arg1
);
4930 p2
= lock_user_string(arg2
);
4931 p3
= lock_user_string(arg3
);
4932 if (!p
|| !p2
|| !p3
)
4933 ret
= -TARGET_EFAULT
;
4935 /* FIXME - arg5 should be locked, but it isn't clear how to
4936 * do that since it's not guaranteed to be a NULL-terminated
4940 ret
= get_errno(mount(p
, p2
, p3
, (unsigned long)arg4
, NULL
));
4942 ret
= get_errno(mount(p
, p2
, p3
, (unsigned long)arg4
, g2h(arg5
)));
4944 unlock_user(p
, arg1
, 0);
4945 unlock_user(p2
, arg2
, 0);
4946 unlock_user(p3
, arg3
, 0);
4949 #ifdef TARGET_NR_umount
4950 case TARGET_NR_umount
:
4951 if (!(p
= lock_user_string(arg1
)))
4953 ret
= get_errno(umount(p
));
4954 unlock_user(p
, arg1
, 0);
4957 #ifdef TARGET_NR_stime /* not on alpha */
4958 case TARGET_NR_stime
:
4961 if (get_user_sal(host_time
, arg1
))
4963 ret
= get_errno(stime(&host_time
));
4967 case TARGET_NR_ptrace
:
4969 #ifdef TARGET_NR_alarm /* not on alpha */
4970 case TARGET_NR_alarm
:
4974 #ifdef TARGET_NR_oldfstat
4975 case TARGET_NR_oldfstat
:
4978 #ifdef TARGET_NR_pause /* not on alpha */
4979 case TARGET_NR_pause
:
4980 ret
= get_errno(pause());
4983 #ifdef TARGET_NR_utime
4984 case TARGET_NR_utime
:
4986 struct utimbuf tbuf
, *host_tbuf
;
4987 struct target_utimbuf
*target_tbuf
;
4989 if (!lock_user_struct(VERIFY_READ
, target_tbuf
, arg2
, 1))
4991 tbuf
.actime
= tswapl(target_tbuf
->actime
);
4992 tbuf
.modtime
= tswapl(target_tbuf
->modtime
);
4993 unlock_user_struct(target_tbuf
, arg2
, 0);
4998 if (!(p
= lock_user_string(arg1
)))
5000 ret
= get_errno(utime(p
, host_tbuf
));
5001 unlock_user(p
, arg1
, 0);
5005 case TARGET_NR_utimes
:
5007 struct timeval
*tvp
, tv
[2];
5009 if (copy_from_user_timeval(&tv
[0], arg2
)
5010 || copy_from_user_timeval(&tv
[1],
5011 arg2
+ sizeof(struct target_timeval
)))
5017 if (!(p
= lock_user_string(arg1
)))
5019 ret
= get_errno(utimes(p
, tvp
));
5020 unlock_user(p
, arg1
, 0);
5023 #if defined(TARGET_NR_futimesat) && defined(__NR_futimesat)
5024 case TARGET_NR_futimesat
:
5026 struct timeval
*tvp
, tv
[2];
5028 if (copy_from_user_timeval(&tv
[0], arg3
)
5029 || copy_from_user_timeval(&tv
[1],
5030 arg3
+ sizeof(struct target_timeval
)))
5036 if (!(p
= lock_user_string(arg2
)))
5038 ret
= get_errno(sys_futimesat(arg1
, path(p
), tvp
));
5039 unlock_user(p
, arg2
, 0);
5043 #ifdef TARGET_NR_stty
5044 case TARGET_NR_stty
:
5047 #ifdef TARGET_NR_gtty
5048 case TARGET_NR_gtty
:
5051 case TARGET_NR_access
:
5052 if (!(p
= lock_user_string(arg1
)))
5054 ret
= get_errno(access(path(p
), arg2
));
5055 unlock_user(p
, arg1
, 0);
5057 #if defined(TARGET_NR_faccessat) && defined(__NR_faccessat)
5058 case TARGET_NR_faccessat
:
5059 if (!(p
= lock_user_string(arg2
)))
5061 ret
= get_errno(sys_faccessat(arg1
, p
, arg3
));
5062 unlock_user(p
, arg2
, 0);
5065 #ifdef TARGET_NR_nice /* not on alpha */
5066 case TARGET_NR_nice
:
5067 ret
= get_errno(nice(arg1
));
5070 #ifdef TARGET_NR_ftime
5071 case TARGET_NR_ftime
:
5074 case TARGET_NR_sync
:
5078 case TARGET_NR_kill
:
5079 ret
= get_errno(kill(arg1
, target_to_host_signal(arg2
)));
5081 case TARGET_NR_rename
:
5084 p
= lock_user_string(arg1
);
5085 p2
= lock_user_string(arg2
);
5087 ret
= -TARGET_EFAULT
;
5089 ret
= get_errno(rename(p
, p2
));
5090 unlock_user(p2
, arg2
, 0);
5091 unlock_user(p
, arg1
, 0);
5094 #if defined(TARGET_NR_renameat) && defined(__NR_renameat)
5095 case TARGET_NR_renameat
:
5098 p
= lock_user_string(arg2
);
5099 p2
= lock_user_string(arg4
);
5101 ret
= -TARGET_EFAULT
;
5103 ret
= get_errno(sys_renameat(arg1
, p
, arg3
, p2
));
5104 unlock_user(p2
, arg4
, 0);
5105 unlock_user(p
, arg2
, 0);
5109 case TARGET_NR_mkdir
:
5110 if (!(p
= lock_user_string(arg1
)))
5112 ret
= get_errno(mkdir(p
, arg2
));
5113 unlock_user(p
, arg1
, 0);
5115 #if defined(TARGET_NR_mkdirat) && defined(__NR_mkdirat)
5116 case TARGET_NR_mkdirat
:
5117 if (!(p
= lock_user_string(arg2
)))
5119 ret
= get_errno(sys_mkdirat(arg1
, p
, arg3
));
5120 unlock_user(p
, arg2
, 0);
5123 case TARGET_NR_rmdir
:
5124 if (!(p
= lock_user_string(arg1
)))
5126 ret
= get_errno(rmdir(p
));
5127 unlock_user(p
, arg1
, 0);
5130 ret
= get_errno(dup(arg1
));
5132 case TARGET_NR_pipe
:
5133 ret
= do_pipe(cpu_env
, arg1
, 0, 0);
5135 #ifdef TARGET_NR_pipe2
5136 case TARGET_NR_pipe2
:
5137 ret
= do_pipe(cpu_env
, arg1
, arg2
, 1);
5140 case TARGET_NR_times
:
5142 struct target_tms
*tmsp
;
5144 ret
= get_errno(times(&tms
));
5146 tmsp
= lock_user(VERIFY_WRITE
, arg1
, sizeof(struct target_tms
), 0);
5149 tmsp
->tms_utime
= tswapl(host_to_target_clock_t(tms
.tms_utime
));
5150 tmsp
->tms_stime
= tswapl(host_to_target_clock_t(tms
.tms_stime
));
5151 tmsp
->tms_cutime
= tswapl(host_to_target_clock_t(tms
.tms_cutime
));
5152 tmsp
->tms_cstime
= tswapl(host_to_target_clock_t(tms
.tms_cstime
));
5155 ret
= host_to_target_clock_t(ret
);
5158 #ifdef TARGET_NR_prof
5159 case TARGET_NR_prof
:
5162 #ifdef TARGET_NR_signal
5163 case TARGET_NR_signal
:
5166 case TARGET_NR_acct
:
5168 ret
= get_errno(acct(NULL
));
5170 if (!(p
= lock_user_string(arg1
)))
5172 ret
= get_errno(acct(path(p
)));
5173 unlock_user(p
, arg1
, 0);
5176 #ifdef TARGET_NR_umount2 /* not on alpha */
5177 case TARGET_NR_umount2
:
5178 if (!(p
= lock_user_string(arg1
)))
5180 ret
= get_errno(umount2(p
, arg2
));
5181 unlock_user(p
, arg1
, 0);
5184 #ifdef TARGET_NR_lock
5185 case TARGET_NR_lock
:
5188 case TARGET_NR_ioctl
:
5189 ret
= do_ioctl(arg1
, arg2
, arg3
);
5191 case TARGET_NR_fcntl
:
5192 ret
= do_fcntl(arg1
, arg2
, arg3
);
5194 #ifdef TARGET_NR_mpx
5198 case TARGET_NR_setpgid
:
5199 ret
= get_errno(setpgid(arg1
, arg2
));
5201 #ifdef TARGET_NR_ulimit
5202 case TARGET_NR_ulimit
:
5205 #ifdef TARGET_NR_oldolduname
5206 case TARGET_NR_oldolduname
:
5209 case TARGET_NR_umask
:
5210 ret
= get_errno(umask(arg1
));
5212 case TARGET_NR_chroot
:
5213 if (!(p
= lock_user_string(arg1
)))
5215 ret
= get_errno(chroot(p
));
5216 unlock_user(p
, arg1
, 0);
5218 case TARGET_NR_ustat
:
5220 case TARGET_NR_dup2
:
5221 ret
= get_errno(dup2(arg1
, arg2
));
5223 #if defined(CONFIG_DUP3) && defined(TARGET_NR_dup3)
5224 case TARGET_NR_dup3
:
5225 ret
= get_errno(dup3(arg1
, arg2
, arg3
));
5228 #ifdef TARGET_NR_getppid /* not on alpha */
5229 case TARGET_NR_getppid
:
5230 ret
= get_errno(getppid());
5233 case TARGET_NR_getpgrp
:
5234 ret
= get_errno(getpgrp());
5236 case TARGET_NR_setsid
:
5237 ret
= get_errno(setsid());
5239 #ifdef TARGET_NR_sigaction
5240 case TARGET_NR_sigaction
:
5242 #if defined(TARGET_ALPHA)
5243 struct target_sigaction act
, oact
, *pact
= 0;
5244 struct target_old_sigaction
*old_act
;
5246 if (!lock_user_struct(VERIFY_READ
, old_act
, arg2
, 1))
5248 act
._sa_handler
= old_act
->_sa_handler
;
5249 target_siginitset(&act
.sa_mask
, old_act
->sa_mask
);
5250 act
.sa_flags
= old_act
->sa_flags
;
5251 act
.sa_restorer
= 0;
5252 unlock_user_struct(old_act
, arg2
, 0);
5255 ret
= get_errno(do_sigaction(arg1
, pact
, &oact
));
5256 if (!is_error(ret
) && arg3
) {
5257 if (!lock_user_struct(VERIFY_WRITE
, old_act
, arg3
, 0))
5259 old_act
->_sa_handler
= oact
._sa_handler
;
5260 old_act
->sa_mask
= oact
.sa_mask
.sig
[0];
5261 old_act
->sa_flags
= oact
.sa_flags
;
5262 unlock_user_struct(old_act
, arg3
, 1);
5264 #elif defined(TARGET_MIPS)
5265 struct target_sigaction act
, oact
, *pact
, *old_act
;
5268 if (!lock_user_struct(VERIFY_READ
, old_act
, arg2
, 1))
5270 act
._sa_handler
= old_act
->_sa_handler
;
5271 target_siginitset(&act
.sa_mask
, old_act
->sa_mask
.sig
[0]);
5272 act
.sa_flags
= old_act
->sa_flags
;
5273 unlock_user_struct(old_act
, arg2
, 0);
5279 ret
= get_errno(do_sigaction(arg1
, pact
, &oact
));
5281 if (!is_error(ret
) && arg3
) {
5282 if (!lock_user_struct(VERIFY_WRITE
, old_act
, arg3
, 0))
5284 old_act
->_sa_handler
= oact
._sa_handler
;
5285 old_act
->sa_flags
= oact
.sa_flags
;
5286 old_act
->sa_mask
.sig
[0] = oact
.sa_mask
.sig
[0];
5287 old_act
->sa_mask
.sig
[1] = 0;
5288 old_act
->sa_mask
.sig
[2] = 0;
5289 old_act
->sa_mask
.sig
[3] = 0;
5290 unlock_user_struct(old_act
, arg3
, 1);
5293 struct target_old_sigaction
*old_act
;
5294 struct target_sigaction act
, oact
, *pact
;
5296 if (!lock_user_struct(VERIFY_READ
, old_act
, arg2
, 1))
5298 act
._sa_handler
= old_act
->_sa_handler
;
5299 target_siginitset(&act
.sa_mask
, old_act
->sa_mask
);
5300 act
.sa_flags
= old_act
->sa_flags
;
5301 act
.sa_restorer
= old_act
->sa_restorer
;
5302 unlock_user_struct(old_act
, arg2
, 0);
5307 ret
= get_errno(do_sigaction(arg1
, pact
, &oact
));
5308 if (!is_error(ret
) && arg3
) {
5309 if (!lock_user_struct(VERIFY_WRITE
, old_act
, arg3
, 0))
5311 old_act
->_sa_handler
= oact
._sa_handler
;
5312 old_act
->sa_mask
= oact
.sa_mask
.sig
[0];
5313 old_act
->sa_flags
= oact
.sa_flags
;
5314 old_act
->sa_restorer
= oact
.sa_restorer
;
5315 unlock_user_struct(old_act
, arg3
, 1);
5321 case TARGET_NR_rt_sigaction
:
5323 #if defined(TARGET_ALPHA)
5324 struct target_sigaction act
, oact
, *pact
= 0;
5325 struct target_rt_sigaction
*rt_act
;
5326 /* ??? arg4 == sizeof(sigset_t). */
5328 if (!lock_user_struct(VERIFY_READ
, rt_act
, arg2
, 1))
5330 act
._sa_handler
= rt_act
->_sa_handler
;
5331 act
.sa_mask
= rt_act
->sa_mask
;
5332 act
.sa_flags
= rt_act
->sa_flags
;
5333 act
.sa_restorer
= arg5
;
5334 unlock_user_struct(rt_act
, arg2
, 0);
5337 ret
= get_errno(do_sigaction(arg1
, pact
, &oact
));
5338 if (!is_error(ret
) && arg3
) {
5339 if (!lock_user_struct(VERIFY_WRITE
, rt_act
, arg3
, 0))
5341 rt_act
->_sa_handler
= oact
._sa_handler
;
5342 rt_act
->sa_mask
= oact
.sa_mask
;
5343 rt_act
->sa_flags
= oact
.sa_flags
;
5344 unlock_user_struct(rt_act
, arg3
, 1);
5347 struct target_sigaction
*act
;
5348 struct target_sigaction
*oact
;
5351 if (!lock_user_struct(VERIFY_READ
, act
, arg2
, 1))
5356 if (!lock_user_struct(VERIFY_WRITE
, oact
, arg3
, 0)) {
5357 ret
= -TARGET_EFAULT
;
5358 goto rt_sigaction_fail
;
5362 ret
= get_errno(do_sigaction(arg1
, act
, oact
));
5365 unlock_user_struct(act
, arg2
, 0);
5367 unlock_user_struct(oact
, arg3
, 1);
5371 #ifdef TARGET_NR_sgetmask /* not on alpha */
5372 case TARGET_NR_sgetmask
:
5375 abi_ulong target_set
;
5376 sigprocmask(0, NULL
, &cur_set
);
5377 host_to_target_old_sigset(&target_set
, &cur_set
);
5382 #ifdef TARGET_NR_ssetmask /* not on alpha */
5383 case TARGET_NR_ssetmask
:
5385 sigset_t set
, oset
, cur_set
;
5386 abi_ulong target_set
= arg1
;
5387 sigprocmask(0, NULL
, &cur_set
);
5388 target_to_host_old_sigset(&set
, &target_set
);
5389 sigorset(&set
, &set
, &cur_set
);
5390 sigprocmask(SIG_SETMASK
, &set
, &oset
);
5391 host_to_target_old_sigset(&target_set
, &oset
);
5396 #ifdef TARGET_NR_sigprocmask
5397 case TARGET_NR_sigprocmask
:
5399 #if defined(TARGET_ALPHA)
5400 sigset_t set
, oldset
;
5405 case TARGET_SIG_BLOCK
:
5408 case TARGET_SIG_UNBLOCK
:
5411 case TARGET_SIG_SETMASK
:
5415 ret
= -TARGET_EINVAL
;
5419 target_to_host_old_sigset(&set
, &mask
);
5421 ret
= get_errno(sigprocmask(how
, &set
, &oldset
));
5423 if (!is_error(ret
)) {
5424 host_to_target_old_sigset(&mask
, &oldset
);
5426 ((CPUAlphaState
*)cpu_env
)->[IR_V0
] = 0; /* force no error */
5429 sigset_t set
, oldset
, *set_ptr
;
5434 case TARGET_SIG_BLOCK
:
5437 case TARGET_SIG_UNBLOCK
:
5440 case TARGET_SIG_SETMASK
:
5444 ret
= -TARGET_EINVAL
;
5447 if (!(p
= lock_user(VERIFY_READ
, arg2
, sizeof(target_sigset_t
), 1)))
5449 target_to_host_old_sigset(&set
, p
);
5450 unlock_user(p
, arg2
, 0);
5456 ret
= get_errno(sigprocmask(how
, set_ptr
, &oldset
));
5457 if (!is_error(ret
) && arg3
) {
5458 if (!(p
= lock_user(VERIFY_WRITE
, arg3
, sizeof(target_sigset_t
), 0)))
5460 host_to_target_old_sigset(p
, &oldset
);
5461 unlock_user(p
, arg3
, sizeof(target_sigset_t
));
5467 case TARGET_NR_rt_sigprocmask
:
5470 sigset_t set
, oldset
, *set_ptr
;
5474 case TARGET_SIG_BLOCK
:
5477 case TARGET_SIG_UNBLOCK
:
5480 case TARGET_SIG_SETMASK
:
5484 ret
= -TARGET_EINVAL
;
5487 if (!(p
= lock_user(VERIFY_READ
, arg2
, sizeof(target_sigset_t
), 1)))
5489 target_to_host_sigset(&set
, p
);
5490 unlock_user(p
, arg2
, 0);
5496 ret
= get_errno(sigprocmask(how
, set_ptr
, &oldset
));
5497 if (!is_error(ret
) && arg3
) {
5498 if (!(p
= lock_user(VERIFY_WRITE
, arg3
, sizeof(target_sigset_t
), 0)))
5500 host_to_target_sigset(p
, &oldset
);
5501 unlock_user(p
, arg3
, sizeof(target_sigset_t
));
5505 #ifdef TARGET_NR_sigpending
5506 case TARGET_NR_sigpending
:
5509 ret
= get_errno(sigpending(&set
));
5510 if (!is_error(ret
)) {
5511 if (!(p
= lock_user(VERIFY_WRITE
, arg1
, sizeof(target_sigset_t
), 0)))
5513 host_to_target_old_sigset(p
, &set
);
5514 unlock_user(p
, arg1
, sizeof(target_sigset_t
));
5519 case TARGET_NR_rt_sigpending
:
5522 ret
= get_errno(sigpending(&set
));
5523 if (!is_error(ret
)) {
5524 if (!(p
= lock_user(VERIFY_WRITE
, arg1
, sizeof(target_sigset_t
), 0)))
5526 host_to_target_sigset(p
, &set
);
5527 unlock_user(p
, arg1
, sizeof(target_sigset_t
));
5531 #ifdef TARGET_NR_sigsuspend
5532 case TARGET_NR_sigsuspend
:
5535 #if defined(TARGET_ALPHA)
5536 abi_ulong mask
= arg1
;
5537 target_to_host_old_sigset(&set
, &mask
);
5539 if (!(p
= lock_user(VERIFY_READ
, arg1
, sizeof(target_sigset_t
), 1)))
5541 target_to_host_old_sigset(&set
, p
);
5542 unlock_user(p
, arg1
, 0);
5544 ret
= get_errno(sigsuspend(&set
));
5548 case TARGET_NR_rt_sigsuspend
:
5551 if (!(p
= lock_user(VERIFY_READ
, arg1
, sizeof(target_sigset_t
), 1)))
5553 target_to_host_sigset(&set
, p
);
5554 unlock_user(p
, arg1
, 0);
5555 ret
= get_errno(sigsuspend(&set
));
5558 case TARGET_NR_rt_sigtimedwait
:
5561 struct timespec uts
, *puts
;
5564 if (!(p
= lock_user(VERIFY_READ
, arg1
, sizeof(target_sigset_t
), 1)))
5566 target_to_host_sigset(&set
, p
);
5567 unlock_user(p
, arg1
, 0);
5570 target_to_host_timespec(puts
, arg3
);
5574 ret
= get_errno(sigtimedwait(&set
, &uinfo
, puts
));
5575 if (!is_error(ret
) && arg2
) {
5576 if (!(p
= lock_user(VERIFY_WRITE
, arg2
, sizeof(target_siginfo_t
), 0)))
5578 host_to_target_siginfo(p
, &uinfo
);
5579 unlock_user(p
, arg2
, sizeof(target_siginfo_t
));
5583 case TARGET_NR_rt_sigqueueinfo
:
5586 if (!(p
= lock_user(VERIFY_READ
, arg3
, sizeof(target_sigset_t
), 1)))
5588 target_to_host_siginfo(&uinfo
, p
);
5589 unlock_user(p
, arg1
, 0);
5590 ret
= get_errno(sys_rt_sigqueueinfo(arg1
, arg2
, &uinfo
));
5593 #ifdef TARGET_NR_sigreturn
5594 case TARGET_NR_sigreturn
:
5595 /* NOTE: ret is eax, so not transcoding must be done */
5596 ret
= do_sigreturn(cpu_env
);
5599 case TARGET_NR_rt_sigreturn
:
5600 /* NOTE: ret is eax, so not transcoding must be done */
5601 ret
= do_rt_sigreturn(cpu_env
);
5603 case TARGET_NR_sethostname
:
5604 if (!(p
= lock_user_string(arg1
)))
5606 ret
= get_errno(sethostname(p
, arg2
));
5607 unlock_user(p
, arg1
, 0);
5609 case TARGET_NR_setrlimit
:
5611 int resource
= target_to_host_resource(arg1
);
5612 struct target_rlimit
*target_rlim
;
5614 if (!lock_user_struct(VERIFY_READ
, target_rlim
, arg2
, 1))
5616 rlim
.rlim_cur
= target_to_host_rlim(target_rlim
->rlim_cur
);
5617 rlim
.rlim_max
= target_to_host_rlim(target_rlim
->rlim_max
);
5618 unlock_user_struct(target_rlim
, arg2
, 0);
5619 ret
= get_errno(setrlimit(resource
, &rlim
));
5622 case TARGET_NR_getrlimit
:
5624 int resource
= target_to_host_resource(arg1
);
5625 struct target_rlimit
*target_rlim
;
5628 ret
= get_errno(getrlimit(resource
, &rlim
));
5629 if (!is_error(ret
)) {
5630 if (!lock_user_struct(VERIFY_WRITE
, target_rlim
, arg2
, 0))
5632 target_rlim
->rlim_cur
= host_to_target_rlim(rlim
.rlim_cur
);
5633 target_rlim
->rlim_max
= host_to_target_rlim(rlim
.rlim_max
);
5634 unlock_user_struct(target_rlim
, arg2
, 1);
5638 case TARGET_NR_getrusage
:
5640 struct rusage rusage
;
5641 ret
= get_errno(getrusage(arg1
, &rusage
));
5642 if (!is_error(ret
)) {
5643 host_to_target_rusage(arg2
, &rusage
);
5647 case TARGET_NR_gettimeofday
:
5650 ret
= get_errno(gettimeofday(&tv
, NULL
));
5651 if (!is_error(ret
)) {
5652 if (copy_to_user_timeval(arg1
, &tv
))
5657 case TARGET_NR_settimeofday
:
5660 if (copy_from_user_timeval(&tv
, arg1
))
5662 ret
= get_errno(settimeofday(&tv
, NULL
));
5665 #if defined(TARGET_NR_select) && !defined(TARGET_S390X) && !defined(TARGET_S390)
5666 case TARGET_NR_select
:
5668 struct target_sel_arg_struct
*sel
;
5669 abi_ulong inp
, outp
, exp
, tvp
;
5672 if (!lock_user_struct(VERIFY_READ
, sel
, arg1
, 1))
5674 nsel
= tswapl(sel
->n
);
5675 inp
= tswapl(sel
->inp
);
5676 outp
= tswapl(sel
->outp
);
5677 exp
= tswapl(sel
->exp
);
5678 tvp
= tswapl(sel
->tvp
);
5679 unlock_user_struct(sel
, arg1
, 0);
5680 ret
= do_select(nsel
, inp
, outp
, exp
, tvp
);
5684 #ifdef TARGET_NR_pselect6
5685 case TARGET_NR_pselect6
:
5687 abi_long rfd_addr
, wfd_addr
, efd_addr
, n
, ts_addr
;
5688 fd_set rfds
, wfds
, efds
;
5689 fd_set
*rfds_ptr
, *wfds_ptr
, *efds_ptr
;
5690 struct timespec ts
, *ts_ptr
;
5693 * The 6th arg is actually two args smashed together,
5694 * so we cannot use the C library.
5702 abi_ulong arg_sigset
, arg_sigsize
, *arg7
;
5703 target_sigset_t
*target_sigset
;
5711 ret
= copy_from_user_fdset_ptr(&rfds
, &rfds_ptr
, rfd_addr
, n
);
5715 ret
= copy_from_user_fdset_ptr(&wfds
, &wfds_ptr
, wfd_addr
, n
);
5719 ret
= copy_from_user_fdset_ptr(&efds
, &efds_ptr
, efd_addr
, n
);
5725 * This takes a timespec, and not a timeval, so we cannot
5726 * use the do_select() helper ...
5729 if (target_to_host_timespec(&ts
, ts_addr
)) {
5737 /* Extract the two packed args for the sigset */
5740 sig
.size
= _NSIG
/ 8;
5742 arg7
= lock_user(VERIFY_READ
, arg6
, sizeof(*arg7
) * 2, 1);
5746 arg_sigset
= tswapl(arg7
[0]);
5747 arg_sigsize
= tswapl(arg7
[1]);
5748 unlock_user(arg7
, arg6
, 0);
5752 if (arg_sigsize
!= sizeof(*target_sigset
)) {
5753 /* Like the kernel, we enforce correct size sigsets */
5754 ret
= -TARGET_EINVAL
;
5757 target_sigset
= lock_user(VERIFY_READ
, arg_sigset
,
5758 sizeof(*target_sigset
), 1);
5759 if (!target_sigset
) {
5762 target_to_host_sigset(&set
, target_sigset
);
5763 unlock_user(target_sigset
, arg_sigset
, 0);
5771 ret
= get_errno(sys_pselect6(n
, rfds_ptr
, wfds_ptr
, efds_ptr
,
5774 if (!is_error(ret
)) {
5775 if (rfd_addr
&& copy_to_user_fdset(rfd_addr
, &rfds
, n
))
5777 if (wfd_addr
&& copy_to_user_fdset(wfd_addr
, &wfds
, n
))
5779 if (efd_addr
&& copy_to_user_fdset(efd_addr
, &efds
, n
))
5782 if (ts_addr
&& host_to_target_timespec(ts_addr
, &ts
))
5788 case TARGET_NR_symlink
:
5791 p
= lock_user_string(arg1
);
5792 p2
= lock_user_string(arg2
);
5794 ret
= -TARGET_EFAULT
;
5796 ret
= get_errno(symlink(p
, p2
));
5797 unlock_user(p2
, arg2
, 0);
5798 unlock_user(p
, arg1
, 0);
5801 #if defined(TARGET_NR_symlinkat) && defined(__NR_symlinkat)
5802 case TARGET_NR_symlinkat
:
5805 p
= lock_user_string(arg1
);
5806 p2
= lock_user_string(arg3
);
5808 ret
= -TARGET_EFAULT
;
5810 ret
= get_errno(sys_symlinkat(p
, arg2
, p2
));
5811 unlock_user(p2
, arg3
, 0);
5812 unlock_user(p
, arg1
, 0);
5816 #ifdef TARGET_NR_oldlstat
5817 case TARGET_NR_oldlstat
:
5820 case TARGET_NR_readlink
:
5823 p
= lock_user_string(arg1
);
5824 p2
= lock_user(VERIFY_WRITE
, arg2
, arg3
, 0);
5826 ret
= -TARGET_EFAULT
;
5828 if (strncmp((const char *)p
, "/proc/self/exe", 14) == 0) {
5829 char real
[PATH_MAX
];
5830 temp
= realpath(exec_path
,real
);
5831 ret
= (temp
==NULL
) ? get_errno(-1) : strlen(real
) ;
5832 snprintf((char *)p2
, arg3
, "%s", real
);
5835 ret
= get_errno(readlink(path(p
), p2
, arg3
));
5837 unlock_user(p2
, arg2
, ret
);
5838 unlock_user(p
, arg1
, 0);
5841 #if defined(TARGET_NR_readlinkat) && defined(__NR_readlinkat)
5842 case TARGET_NR_readlinkat
:
5845 p
= lock_user_string(arg2
);
5846 p2
= lock_user(VERIFY_WRITE
, arg3
, arg4
, 0);
5848 ret
= -TARGET_EFAULT
;
5850 ret
= get_errno(sys_readlinkat(arg1
, path(p
), p2
, arg4
));
5851 unlock_user(p2
, arg3
, ret
);
5852 unlock_user(p
, arg2
, 0);
5856 #ifdef TARGET_NR_uselib
5857 case TARGET_NR_uselib
:
5860 #ifdef TARGET_NR_swapon
5861 case TARGET_NR_swapon
:
5862 if (!(p
= lock_user_string(arg1
)))
5864 ret
= get_errno(swapon(p
, arg2
));
5865 unlock_user(p
, arg1
, 0);
5868 case TARGET_NR_reboot
:
5870 #ifdef TARGET_NR_readdir
5871 case TARGET_NR_readdir
:
5874 #ifdef TARGET_NR_mmap
5875 case TARGET_NR_mmap
:
5876 #if (defined(TARGET_I386) && defined(TARGET_ABI32)) || defined(TARGET_ARM) || \
5877 defined(TARGET_M68K) || defined(TARGET_CRIS) || defined(TARGET_MICROBLAZE) \
5878 || defined(TARGET_S390X)
5881 abi_ulong v1
, v2
, v3
, v4
, v5
, v6
;
5882 if (!(v
= lock_user(VERIFY_READ
, arg1
, 6 * sizeof(abi_ulong
), 1)))
5890 unlock_user(v
, arg1
, 0);
5891 ret
= get_errno(target_mmap(v1
, v2
, v3
,
5892 target_to_host_bitmask(v4
, mmap_flags_tbl
),
5896 ret
= get_errno(target_mmap(arg1
, arg2
, arg3
,
5897 target_to_host_bitmask(arg4
, mmap_flags_tbl
),
5903 #ifdef TARGET_NR_mmap2
5904 case TARGET_NR_mmap2
:
5906 #define MMAP_SHIFT 12
5908 ret
= get_errno(target_mmap(arg1
, arg2
, arg3
,
5909 target_to_host_bitmask(arg4
, mmap_flags_tbl
),
5911 arg6
<< MMAP_SHIFT
));
5914 case TARGET_NR_munmap
:
5915 ret
= get_errno(target_munmap(arg1
, arg2
));
5917 case TARGET_NR_mprotect
:
5919 TaskState
*ts
= ((CPUState
*)cpu_env
)->opaque
;
5920 /* Special hack to detect libc making the stack executable. */
5921 if ((arg3
& PROT_GROWSDOWN
)
5922 && arg1
>= ts
->info
->stack_limit
5923 && arg1
<= ts
->info
->start_stack
) {
5924 arg3
&= ~PROT_GROWSDOWN
;
5925 arg2
= arg2
+ arg1
- ts
->info
->stack_limit
;
5926 arg1
= ts
->info
->stack_limit
;
5929 ret
= get_errno(target_mprotect(arg1
, arg2
, arg3
));
5931 #ifdef TARGET_NR_mremap
5932 case TARGET_NR_mremap
:
5933 ret
= get_errno(target_mremap(arg1
, arg2
, arg3
, arg4
, arg5
));
5936 /* ??? msync/mlock/munlock are broken for softmmu. */
5937 #ifdef TARGET_NR_msync
5938 case TARGET_NR_msync
:
5939 ret
= get_errno(msync(g2h(arg1
), arg2
, arg3
));
5942 #ifdef TARGET_NR_mlock
5943 case TARGET_NR_mlock
:
5944 ret
= get_errno(mlock(g2h(arg1
), arg2
));
5947 #ifdef TARGET_NR_munlock
5948 case TARGET_NR_munlock
:
5949 ret
= get_errno(munlock(g2h(arg1
), arg2
));
5952 #ifdef TARGET_NR_mlockall
5953 case TARGET_NR_mlockall
:
5954 ret
= get_errno(mlockall(arg1
));
5957 #ifdef TARGET_NR_munlockall
5958 case TARGET_NR_munlockall
:
5959 ret
= get_errno(munlockall());
5962 case TARGET_NR_truncate
:
5963 if (!(p
= lock_user_string(arg1
)))
5965 ret
= get_errno(truncate(p
, arg2
));
5966 unlock_user(p
, arg1
, 0);
5968 case TARGET_NR_ftruncate
:
5969 ret
= get_errno(ftruncate(arg1
, arg2
));
5971 case TARGET_NR_fchmod
:
5972 ret
= get_errno(fchmod(arg1
, arg2
));
5974 #if defined(TARGET_NR_fchmodat) && defined(__NR_fchmodat)
5975 case TARGET_NR_fchmodat
:
5976 if (!(p
= lock_user_string(arg2
)))
5978 ret
= get_errno(sys_fchmodat(arg1
, p
, arg3
));
5979 unlock_user(p
, arg2
, 0);
5982 case TARGET_NR_getpriority
:
5983 /* libc does special remapping of the return value of
5984 * sys_getpriority() so it's just easiest to call
5985 * sys_getpriority() directly rather than through libc. */
5986 ret
= get_errno(sys_getpriority(arg1
, arg2
));
5988 case TARGET_NR_setpriority
:
5989 ret
= get_errno(setpriority(arg1
, arg2
, arg3
));
5991 #ifdef TARGET_NR_profil
5992 case TARGET_NR_profil
:
5995 case TARGET_NR_statfs
:
5996 if (!(p
= lock_user_string(arg1
)))
5998 ret
= get_errno(statfs(path(p
), &stfs
));
5999 unlock_user(p
, arg1
, 0);
6001 if (!is_error(ret
)) {
6002 struct target_statfs
*target_stfs
;
6004 if (!lock_user_struct(VERIFY_WRITE
, target_stfs
, arg2
, 0))
6006 __put_user(stfs
.f_type
, &target_stfs
->f_type
);
6007 __put_user(stfs
.f_bsize
, &target_stfs
->f_bsize
);
6008 __put_user(stfs
.f_blocks
, &target_stfs
->f_blocks
);
6009 __put_user(stfs
.f_bfree
, &target_stfs
->f_bfree
);
6010 __put_user(stfs
.f_bavail
, &target_stfs
->f_bavail
);
6011 __put_user(stfs
.f_files
, &target_stfs
->f_files
);
6012 __put_user(stfs
.f_ffree
, &target_stfs
->f_ffree
);
6013 __put_user(stfs
.f_fsid
.__val
[0], &target_stfs
->f_fsid
.val
[0]);
6014 __put_user(stfs
.f_fsid
.__val
[1], &target_stfs
->f_fsid
.val
[1]);
6015 __put_user(stfs
.f_namelen
, &target_stfs
->f_namelen
);
6016 unlock_user_struct(target_stfs
, arg2
, 1);
6019 case TARGET_NR_fstatfs
:
6020 ret
= get_errno(fstatfs(arg1
, &stfs
));
6021 goto convert_statfs
;
6022 #ifdef TARGET_NR_statfs64
6023 case TARGET_NR_statfs64
:
6024 if (!(p
= lock_user_string(arg1
)))
6026 ret
= get_errno(statfs(path(p
), &stfs
));
6027 unlock_user(p
, arg1
, 0);
6029 if (!is_error(ret
)) {
6030 struct target_statfs64
*target_stfs
;
6032 if (!lock_user_struct(VERIFY_WRITE
, target_stfs
, arg3
, 0))
6034 __put_user(stfs
.f_type
, &target_stfs
->f_type
);
6035 __put_user(stfs
.f_bsize
, &target_stfs
->f_bsize
);
6036 __put_user(stfs
.f_blocks
, &target_stfs
->f_blocks
);
6037 __put_user(stfs
.f_bfree
, &target_stfs
->f_bfree
);
6038 __put_user(stfs
.f_bavail
, &target_stfs
->f_bavail
);
6039 __put_user(stfs
.f_files
, &target_stfs
->f_files
);
6040 __put_user(stfs
.f_ffree
, &target_stfs
->f_ffree
);
6041 __put_user(stfs
.f_fsid
.__val
[0], &target_stfs
->f_fsid
.val
[0]);
6042 __put_user(stfs
.f_fsid
.__val
[1], &target_stfs
->f_fsid
.val
[1]);
6043 __put_user(stfs
.f_namelen
, &target_stfs
->f_namelen
);
6044 unlock_user_struct(target_stfs
, arg3
, 1);
6047 case TARGET_NR_fstatfs64
:
6048 ret
= get_errno(fstatfs(arg1
, &stfs
));
6049 goto convert_statfs64
;
6051 #ifdef TARGET_NR_ioperm
6052 case TARGET_NR_ioperm
:
6055 #ifdef TARGET_NR_socketcall
6056 case TARGET_NR_socketcall
:
6057 ret
= do_socketcall(arg1
, arg2
);
6060 #ifdef TARGET_NR_accept
6061 case TARGET_NR_accept
:
6062 ret
= do_accept(arg1
, arg2
, arg3
);
6065 #ifdef TARGET_NR_bind
6066 case TARGET_NR_bind
:
6067 ret
= do_bind(arg1
, arg2
, arg3
);
6070 #ifdef TARGET_NR_connect
6071 case TARGET_NR_connect
:
6072 ret
= do_connect(arg1
, arg2
, arg3
);
6075 #ifdef TARGET_NR_getpeername
6076 case TARGET_NR_getpeername
:
6077 ret
= do_getpeername(arg1
, arg2
, arg3
);
6080 #ifdef TARGET_NR_getsockname
6081 case TARGET_NR_getsockname
:
6082 ret
= do_getsockname(arg1
, arg2
, arg3
);
6085 #ifdef TARGET_NR_getsockopt
6086 case TARGET_NR_getsockopt
:
6087 ret
= do_getsockopt(arg1
, arg2
, arg3
, arg4
, arg5
);
6090 #ifdef TARGET_NR_listen
6091 case TARGET_NR_listen
:
6092 ret
= get_errno(listen(arg1
, arg2
));
6095 #ifdef TARGET_NR_recv
6096 case TARGET_NR_recv
:
6097 ret
= do_recvfrom(arg1
, arg2
, arg3
, arg4
, 0, 0);
6100 #ifdef TARGET_NR_recvfrom
6101 case TARGET_NR_recvfrom
:
6102 ret
= do_recvfrom(arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
6105 #ifdef TARGET_NR_recvmsg
6106 case TARGET_NR_recvmsg
:
6107 ret
= do_sendrecvmsg(arg1
, arg2
, arg3
, 0);
6110 #ifdef TARGET_NR_send
6111 case TARGET_NR_send
:
6112 ret
= do_sendto(arg1
, arg2
, arg3
, arg4
, 0, 0);
6115 #ifdef TARGET_NR_sendmsg
6116 case TARGET_NR_sendmsg
:
6117 ret
= do_sendrecvmsg(arg1
, arg2
, arg3
, 1);
6120 #ifdef TARGET_NR_sendto
6121 case TARGET_NR_sendto
:
6122 ret
= do_sendto(arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
6125 #ifdef TARGET_NR_shutdown
6126 case TARGET_NR_shutdown
:
6127 ret
= get_errno(shutdown(arg1
, arg2
));
6130 #ifdef TARGET_NR_socket
6131 case TARGET_NR_socket
:
6132 ret
= do_socket(arg1
, arg2
, arg3
);
6135 #ifdef TARGET_NR_socketpair
6136 case TARGET_NR_socketpair
:
6137 ret
= do_socketpair(arg1
, arg2
, arg3
, arg4
);
6140 #ifdef TARGET_NR_setsockopt
6141 case TARGET_NR_setsockopt
:
6142 ret
= do_setsockopt(arg1
, arg2
, arg3
, arg4
, (socklen_t
) arg5
);
6146 case TARGET_NR_syslog
:
6147 if (!(p
= lock_user_string(arg2
)))
6149 ret
= get_errno(sys_syslog((int)arg1
, p
, (int)arg3
));
6150 unlock_user(p
, arg2
, 0);
6153 case TARGET_NR_setitimer
:
6155 struct itimerval value
, ovalue
, *pvalue
;
6159 if (copy_from_user_timeval(&pvalue
->it_interval
, arg2
)
6160 || copy_from_user_timeval(&pvalue
->it_value
,
6161 arg2
+ sizeof(struct target_timeval
)))
6166 ret
= get_errno(setitimer(arg1
, pvalue
, &ovalue
));
6167 if (!is_error(ret
) && arg3
) {
6168 if (copy_to_user_timeval(arg3
,
6169 &ovalue
.it_interval
)
6170 || copy_to_user_timeval(arg3
+ sizeof(struct target_timeval
),
6176 case TARGET_NR_getitimer
:
6178 struct itimerval value
;
6180 ret
= get_errno(getitimer(arg1
, &value
));
6181 if (!is_error(ret
) && arg2
) {
6182 if (copy_to_user_timeval(arg2
,
6184 || copy_to_user_timeval(arg2
+ sizeof(struct target_timeval
),
6190 case TARGET_NR_stat
:
6191 if (!(p
= lock_user_string(arg1
)))
6193 ret
= get_errno(stat(path(p
), &st
));
6194 unlock_user(p
, arg1
, 0);
6196 case TARGET_NR_lstat
:
6197 if (!(p
= lock_user_string(arg1
)))
6199 ret
= get_errno(lstat(path(p
), &st
));
6200 unlock_user(p
, arg1
, 0);
6202 case TARGET_NR_fstat
:
6204 ret
= get_errno(fstat(arg1
, &st
));
6206 if (!is_error(ret
)) {
6207 struct target_stat
*target_st
;
6209 if (!lock_user_struct(VERIFY_WRITE
, target_st
, arg2
, 0))
6211 memset(target_st
, 0, sizeof(*target_st
));
6212 __put_user(st
.st_dev
, &target_st
->st_dev
);
6213 __put_user(st
.st_ino
, &target_st
->st_ino
);
6214 __put_user(st
.st_mode
, &target_st
->st_mode
);
6215 __put_user(st
.st_uid
, &target_st
->st_uid
);
6216 __put_user(st
.st_gid
, &target_st
->st_gid
);
6217 __put_user(st
.st_nlink
, &target_st
->st_nlink
);
6218 __put_user(st
.st_rdev
, &target_st
->st_rdev
);
6219 __put_user(st
.st_size
, &target_st
->st_size
);
6220 __put_user(st
.st_blksize
, &target_st
->st_blksize
);
6221 __put_user(st
.st_blocks
, &target_st
->st_blocks
);
6222 __put_user(st
.st_atime
, &target_st
->target_st_atime
);
6223 __put_user(st
.st_mtime
, &target_st
->target_st_mtime
);
6224 __put_user(st
.st_ctime
, &target_st
->target_st_ctime
);
6225 unlock_user_struct(target_st
, arg2
, 1);
6229 #ifdef TARGET_NR_olduname
6230 case TARGET_NR_olduname
:
6233 #ifdef TARGET_NR_iopl
6234 case TARGET_NR_iopl
:
6237 case TARGET_NR_vhangup
:
6238 ret
= get_errno(vhangup());
6240 #ifdef TARGET_NR_idle
6241 case TARGET_NR_idle
:
6244 #ifdef TARGET_NR_syscall
6245 case TARGET_NR_syscall
:
6246 ret
= do_syscall(cpu_env
, arg1
& 0xffff, arg2
, arg3
, arg4
, arg5
,
6247 arg6
, arg7
, arg8
, 0);
6250 case TARGET_NR_wait4
:
6253 abi_long status_ptr
= arg2
;
6254 struct rusage rusage
, *rusage_ptr
;
6255 abi_ulong target_rusage
= arg4
;
6257 rusage_ptr
= &rusage
;
6260 ret
= get_errno(wait4(arg1
, &status
, arg3
, rusage_ptr
));
6261 if (!is_error(ret
)) {
6263 status
= host_to_target_waitstatus(status
);
6264 if (put_user_s32(status
, status_ptr
))
6268 host_to_target_rusage(target_rusage
, &rusage
);
6272 #ifdef TARGET_NR_swapoff
6273 case TARGET_NR_swapoff
:
6274 if (!(p
= lock_user_string(arg1
)))
6276 ret
= get_errno(swapoff(p
));
6277 unlock_user(p
, arg1
, 0);
6280 case TARGET_NR_sysinfo
:
6282 struct target_sysinfo
*target_value
;
6283 struct sysinfo value
;
6284 ret
= get_errno(sysinfo(&value
));
6285 if (!is_error(ret
) && arg1
)
6287 if (!lock_user_struct(VERIFY_WRITE
, target_value
, arg1
, 0))
6289 __put_user(value
.uptime
, &target_value
->uptime
);
6290 __put_user(value
.loads
[0], &target_value
->loads
[0]);
6291 __put_user(value
.loads
[1], &target_value
->loads
[1]);
6292 __put_user(value
.loads
[2], &target_value
->loads
[2]);
6293 __put_user(value
.totalram
, &target_value
->totalram
);
6294 __put_user(value
.freeram
, &target_value
->freeram
);
6295 __put_user(value
.sharedram
, &target_value
->sharedram
);
6296 __put_user(value
.bufferram
, &target_value
->bufferram
);
6297 __put_user(value
.totalswap
, &target_value
->totalswap
);
6298 __put_user(value
.freeswap
, &target_value
->freeswap
);
6299 __put_user(value
.procs
, &target_value
->procs
);
6300 __put_user(value
.totalhigh
, &target_value
->totalhigh
);
6301 __put_user(value
.freehigh
, &target_value
->freehigh
);
6302 __put_user(value
.mem_unit
, &target_value
->mem_unit
);
6303 unlock_user_struct(target_value
, arg1
, 1);
6307 #ifdef TARGET_NR_ipc
6309 ret
= do_ipc(arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
6312 #ifdef TARGET_NR_semget
6313 case TARGET_NR_semget
:
6314 ret
= get_errno(semget(arg1
, arg2
, arg3
));
6317 #ifdef TARGET_NR_semop
6318 case TARGET_NR_semop
:
6319 ret
= get_errno(do_semop(arg1
, arg2
, arg3
));
6322 #ifdef TARGET_NR_semctl
6323 case TARGET_NR_semctl
:
6324 ret
= do_semctl(arg1
, arg2
, arg3
, (union target_semun
)(abi_ulong
)arg4
);
6327 #ifdef TARGET_NR_msgctl
6328 case TARGET_NR_msgctl
:
6329 ret
= do_msgctl(arg1
, arg2
, arg3
);
6332 #ifdef TARGET_NR_msgget
6333 case TARGET_NR_msgget
:
6334 ret
= get_errno(msgget(arg1
, arg2
));
6337 #ifdef TARGET_NR_msgrcv
6338 case TARGET_NR_msgrcv
:
6339 ret
= do_msgrcv(arg1
, arg2
, arg3
, arg4
, arg5
);
6342 #ifdef TARGET_NR_msgsnd
6343 case TARGET_NR_msgsnd
:
6344 ret
= do_msgsnd(arg1
, arg2
, arg3
, arg4
);
6347 #ifdef TARGET_NR_shmget
6348 case TARGET_NR_shmget
:
6349 ret
= get_errno(shmget(arg1
, arg2
, arg3
));
6352 #ifdef TARGET_NR_shmctl
6353 case TARGET_NR_shmctl
:
6354 ret
= do_shmctl(arg1
, arg2
, arg3
);
6357 #ifdef TARGET_NR_shmat
6358 case TARGET_NR_shmat
:
6359 ret
= do_shmat(arg1
, arg2
, arg3
);
6362 #ifdef TARGET_NR_shmdt
6363 case TARGET_NR_shmdt
:
6364 ret
= do_shmdt(arg1
);
6367 case TARGET_NR_fsync
:
6368 ret
= get_errno(fsync(arg1
));
6370 case TARGET_NR_clone
:
6371 #if defined(TARGET_SH4) || defined(TARGET_ALPHA)
6372 ret
= get_errno(do_fork(cpu_env
, arg1
, arg2
, arg3
, arg5
, arg4
));
6373 #elif defined(TARGET_CRIS)
6374 ret
= get_errno(do_fork(cpu_env
, arg2
, arg1
, arg3
, arg4
, arg5
));
6375 #elif defined(TARGET_S390X)
6376 ret
= get_errno(do_fork(cpu_env
, arg2
, arg1
, arg3
, arg5
, arg4
));
6378 ret
= get_errno(do_fork(cpu_env
, arg1
, arg2
, arg3
, arg4
, arg5
));
6381 #ifdef __NR_exit_group
6382 /* new thread calls */
6383 case TARGET_NR_exit_group
:
6387 gdb_exit(cpu_env
, arg1
);
6388 ret
= get_errno(exit_group(arg1
));
6391 case TARGET_NR_setdomainname
:
6392 if (!(p
= lock_user_string(arg1
)))
6394 ret
= get_errno(setdomainname(p
, arg2
));
6395 unlock_user(p
, arg1
, 0);
6397 case TARGET_NR_uname
:
6398 /* no need to transcode because we use the linux syscall */
6400 struct new_utsname
* buf
;
6402 if (!lock_user_struct(VERIFY_WRITE
, buf
, arg1
, 0))
6404 ret
= get_errno(sys_uname(buf
));
6405 if (!is_error(ret
)) {
6406 /* Overrite the native machine name with whatever is being
6408 strcpy (buf
->machine
, cpu_to_uname_machine(cpu_env
));
6409 /* Allow the user to override the reported release. */
6410 if (qemu_uname_release
&& *qemu_uname_release
)
6411 strcpy (buf
->release
, qemu_uname_release
);
6413 unlock_user_struct(buf
, arg1
, 1);
6417 case TARGET_NR_modify_ldt
:
6418 ret
= do_modify_ldt(cpu_env
, arg1
, arg2
, arg3
);
6420 #if !defined(TARGET_X86_64)
6421 case TARGET_NR_vm86old
:
6423 case TARGET_NR_vm86
:
6424 ret
= do_vm86(cpu_env
, arg1
, arg2
);
6428 case TARGET_NR_adjtimex
:
6430 #ifdef TARGET_NR_create_module
6431 case TARGET_NR_create_module
:
6433 case TARGET_NR_init_module
:
6434 case TARGET_NR_delete_module
:
6435 #ifdef TARGET_NR_get_kernel_syms
6436 case TARGET_NR_get_kernel_syms
:
6439 case TARGET_NR_quotactl
:
6441 case TARGET_NR_getpgid
:
6442 ret
= get_errno(getpgid(arg1
));
6444 case TARGET_NR_fchdir
:
6445 ret
= get_errno(fchdir(arg1
));
6447 #ifdef TARGET_NR_bdflush /* not on x86_64 */
6448 case TARGET_NR_bdflush
:
6451 #ifdef TARGET_NR_sysfs
6452 case TARGET_NR_sysfs
:
6455 case TARGET_NR_personality
:
6456 ret
= get_errno(personality(arg1
));
6458 #ifdef TARGET_NR_afs_syscall
6459 case TARGET_NR_afs_syscall
:
6462 #ifdef TARGET_NR__llseek /* Not on alpha */
6463 case TARGET_NR__llseek
:
6466 #if !defined(__NR_llseek)
6467 res
= lseek(arg1
, ((uint64_t)arg2
<< 32) | arg3
, arg5
);
6469 ret
= get_errno(res
);
6474 ret
= get_errno(_llseek(arg1
, arg2
, arg3
, &res
, arg5
));
6476 if ((ret
== 0) && put_user_s64(res
, arg4
)) {
6482 case TARGET_NR_getdents
:
6483 #if TARGET_ABI_BITS == 32 && HOST_LONG_BITS == 64
6485 struct target_dirent
*target_dirp
;
6486 struct linux_dirent
*dirp
;
6487 abi_long count
= arg3
;
6489 dirp
= malloc(count
);
6491 ret
= -TARGET_ENOMEM
;
6495 ret
= get_errno(sys_getdents(arg1
, dirp
, count
));
6496 if (!is_error(ret
)) {
6497 struct linux_dirent
*de
;
6498 struct target_dirent
*tde
;
6500 int reclen
, treclen
;
6501 int count1
, tnamelen
;
6505 if (!(target_dirp
= lock_user(VERIFY_WRITE
, arg2
, count
, 0)))
6509 reclen
= de
->d_reclen
;
6510 treclen
= reclen
- (2 * (sizeof(long) - sizeof(abi_long
)));
6511 tde
->d_reclen
= tswap16(treclen
);
6512 tde
->d_ino
= tswapl(de
->d_ino
);
6513 tde
->d_off
= tswapl(de
->d_off
);
6514 tnamelen
= treclen
- (2 * sizeof(abi_long
) + 2);
6517 /* XXX: may not be correct */
6518 pstrcpy(tde
->d_name
, tnamelen
, de
->d_name
);
6519 de
= (struct linux_dirent
*)((char *)de
+ reclen
);
6521 tde
= (struct target_dirent
*)((char *)tde
+ treclen
);
6525 unlock_user(target_dirp
, arg2
, ret
);
6531 struct linux_dirent
*dirp
;
6532 abi_long count
= arg3
;
6534 if (!(dirp
= lock_user(VERIFY_WRITE
, arg2
, count
, 0)))
6536 ret
= get_errno(sys_getdents(arg1
, dirp
, count
));
6537 if (!is_error(ret
)) {
6538 struct linux_dirent
*de
;
6543 reclen
= de
->d_reclen
;
6546 de
->d_reclen
= tswap16(reclen
);
6547 tswapls(&de
->d_ino
);
6548 tswapls(&de
->d_off
);
6549 de
= (struct linux_dirent
*)((char *)de
+ reclen
);
6553 unlock_user(dirp
, arg2
, ret
);
6557 #if defined(TARGET_NR_getdents64) && defined(__NR_getdents64)
6558 case TARGET_NR_getdents64
:
6560 struct linux_dirent64
*dirp
;
6561 abi_long count
= arg3
;
6562 if (!(dirp
= lock_user(VERIFY_WRITE
, arg2
, count
, 0)))
6564 ret
= get_errno(sys_getdents64(arg1
, dirp
, count
));
6565 if (!is_error(ret
)) {
6566 struct linux_dirent64
*de
;
6571 reclen
= de
->d_reclen
;
6574 de
->d_reclen
= tswap16(reclen
);
6575 tswap64s((uint64_t *)&de
->d_ino
);
6576 tswap64s((uint64_t *)&de
->d_off
);
6577 de
= (struct linux_dirent64
*)((char *)de
+ reclen
);
6581 unlock_user(dirp
, arg2
, ret
);
6584 #endif /* TARGET_NR_getdents64 */
6585 #if defined(TARGET_NR__newselect) || defined(TARGET_S390X)
6587 case TARGET_NR_select
:
6589 case TARGET_NR__newselect
:
6591 ret
= do_select(arg1
, arg2
, arg3
, arg4
, arg5
);
6594 #if defined(TARGET_NR_poll) || defined(TARGET_NR_ppoll)
6595 # ifdef TARGET_NR_poll
6596 case TARGET_NR_poll
:
6598 # ifdef TARGET_NR_ppoll
6599 case TARGET_NR_ppoll
:
6602 struct target_pollfd
*target_pfd
;
6603 unsigned int nfds
= arg2
;
6608 target_pfd
= lock_user(VERIFY_WRITE
, arg1
, sizeof(struct target_pollfd
) * nfds
, 1);
6612 pfd
= alloca(sizeof(struct pollfd
) * nfds
);
6613 for(i
= 0; i
< nfds
; i
++) {
6614 pfd
[i
].fd
= tswap32(target_pfd
[i
].fd
);
6615 pfd
[i
].events
= tswap16(target_pfd
[i
].events
);
6618 # ifdef TARGET_NR_ppoll
6619 if (num
== TARGET_NR_ppoll
) {
6620 struct timespec _timeout_ts
, *timeout_ts
= &_timeout_ts
;
6621 target_sigset_t
*target_set
;
6622 sigset_t _set
, *set
= &_set
;
6625 if (target_to_host_timespec(timeout_ts
, arg3
)) {
6626 unlock_user(target_pfd
, arg1
, 0);
6634 target_set
= lock_user(VERIFY_READ
, arg4
, sizeof(target_sigset_t
), 1);
6636 unlock_user(target_pfd
, arg1
, 0);
6639 target_to_host_sigset(set
, target_set
);
6644 ret
= get_errno(sys_ppoll(pfd
, nfds
, timeout_ts
, set
, _NSIG
/8));
6646 if (!is_error(ret
) && arg3
) {
6647 host_to_target_timespec(arg3
, timeout_ts
);
6650 unlock_user(target_set
, arg4
, 0);
6654 ret
= get_errno(poll(pfd
, nfds
, timeout
));
6656 if (!is_error(ret
)) {
6657 for(i
= 0; i
< nfds
; i
++) {
6658 target_pfd
[i
].revents
= tswap16(pfd
[i
].revents
);
6661 unlock_user(target_pfd
, arg1
, sizeof(struct target_pollfd
) * nfds
);
6665 case TARGET_NR_flock
:
6666 /* NOTE: the flock constant seems to be the same for every
6668 ret
= get_errno(flock(arg1
, arg2
));
6670 case TARGET_NR_readv
:
6675 vec
= alloca(count
* sizeof(struct iovec
));
6676 if (lock_iovec(VERIFY_WRITE
, vec
, arg2
, count
, 0) < 0)
6678 ret
= get_errno(readv(arg1
, vec
, count
));
6679 unlock_iovec(vec
, arg2
, count
, 1);
6682 case TARGET_NR_writev
:
6687 vec
= alloca(count
* sizeof(struct iovec
));
6688 if (lock_iovec(VERIFY_READ
, vec
, arg2
, count
, 1) < 0)
6690 ret
= get_errno(writev(arg1
, vec
, count
));
6691 unlock_iovec(vec
, arg2
, count
, 0);
6694 case TARGET_NR_getsid
:
6695 ret
= get_errno(getsid(arg1
));
6697 #if defined(TARGET_NR_fdatasync) /* Not on alpha (osf_datasync ?) */
6698 case TARGET_NR_fdatasync
:
6699 ret
= get_errno(fdatasync(arg1
));
6702 case TARGET_NR__sysctl
:
6703 /* We don't implement this, but ENOTDIR is always a safe
6705 ret
= -TARGET_ENOTDIR
;
6707 case TARGET_NR_sched_getaffinity
:
6709 unsigned int mask_size
;
6710 unsigned long *mask
;
6713 * sched_getaffinity needs multiples of ulong, so need to take
6714 * care of mismatches between target ulong and host ulong sizes.
6716 if (arg2
& (sizeof(abi_ulong
) - 1)) {
6717 ret
= -TARGET_EINVAL
;
6720 mask_size
= (arg2
+ (sizeof(*mask
) - 1)) & ~(sizeof(*mask
) - 1);
6722 mask
= alloca(mask_size
);
6723 ret
= get_errno(sys_sched_getaffinity(arg1
, mask_size
, mask
));
6725 if (!is_error(ret
)) {
6726 if (copy_to_user(arg3
, mask
, ret
)) {
6732 case TARGET_NR_sched_setaffinity
:
6734 unsigned int mask_size
;
6735 unsigned long *mask
;
6738 * sched_setaffinity needs multiples of ulong, so need to take
6739 * care of mismatches between target ulong and host ulong sizes.
6741 if (arg2
& (sizeof(abi_ulong
) - 1)) {
6742 ret
= -TARGET_EINVAL
;
6745 mask_size
= (arg2
+ (sizeof(*mask
) - 1)) & ~(sizeof(*mask
) - 1);
6747 mask
= alloca(mask_size
);
6748 if (!lock_user_struct(VERIFY_READ
, p
, arg3
, 1)) {
6751 memcpy(mask
, p
, arg2
);
6752 unlock_user_struct(p
, arg2
, 0);
6754 ret
= get_errno(sys_sched_setaffinity(arg1
, mask_size
, mask
));
6757 case TARGET_NR_sched_setparam
:
6759 struct sched_param
*target_schp
;
6760 struct sched_param schp
;
6762 if (!lock_user_struct(VERIFY_READ
, target_schp
, arg2
, 1))
6764 schp
.sched_priority
= tswap32(target_schp
->sched_priority
);
6765 unlock_user_struct(target_schp
, arg2
, 0);
6766 ret
= get_errno(sched_setparam(arg1
, &schp
));
6769 case TARGET_NR_sched_getparam
:
6771 struct sched_param
*target_schp
;
6772 struct sched_param schp
;
6773 ret
= get_errno(sched_getparam(arg1
, &schp
));
6774 if (!is_error(ret
)) {
6775 if (!lock_user_struct(VERIFY_WRITE
, target_schp
, arg2
, 0))
6777 target_schp
->sched_priority
= tswap32(schp
.sched_priority
);
6778 unlock_user_struct(target_schp
, arg2
, 1);
6782 case TARGET_NR_sched_setscheduler
:
6784 struct sched_param
*target_schp
;
6785 struct sched_param schp
;
6786 if (!lock_user_struct(VERIFY_READ
, target_schp
, arg3
, 1))
6788 schp
.sched_priority
= tswap32(target_schp
->sched_priority
);
6789 unlock_user_struct(target_schp
, arg3
, 0);
6790 ret
= get_errno(sched_setscheduler(arg1
, arg2
, &schp
));
6793 case TARGET_NR_sched_getscheduler
:
6794 ret
= get_errno(sched_getscheduler(arg1
));
6796 case TARGET_NR_sched_yield
:
6797 ret
= get_errno(sched_yield());
6799 case TARGET_NR_sched_get_priority_max
:
6800 ret
= get_errno(sched_get_priority_max(arg1
));
6802 case TARGET_NR_sched_get_priority_min
:
6803 ret
= get_errno(sched_get_priority_min(arg1
));
6805 case TARGET_NR_sched_rr_get_interval
:
6808 ret
= get_errno(sched_rr_get_interval(arg1
, &ts
));
6809 if (!is_error(ret
)) {
6810 host_to_target_timespec(arg2
, &ts
);
6814 case TARGET_NR_nanosleep
:
6816 struct timespec req
, rem
;
6817 target_to_host_timespec(&req
, arg1
);
6818 ret
= get_errno(nanosleep(&req
, &rem
));
6819 if (is_error(ret
) && arg2
) {
6820 host_to_target_timespec(arg2
, &rem
);
6824 #ifdef TARGET_NR_query_module
6825 case TARGET_NR_query_module
:
6828 #ifdef TARGET_NR_nfsservctl
6829 case TARGET_NR_nfsservctl
:
6832 case TARGET_NR_prctl
:
6835 case PR_GET_PDEATHSIG
:
6838 ret
= get_errno(prctl(arg1
, &deathsig
, arg3
, arg4
, arg5
));
6839 if (!is_error(ret
) && arg2
6840 && put_user_ual(deathsig
, arg2
))
6845 ret
= get_errno(prctl(arg1
, arg2
, arg3
, arg4
, arg5
));
6849 #ifdef TARGET_NR_arch_prctl
6850 case TARGET_NR_arch_prctl
:
6851 #if defined(TARGET_I386) && !defined(TARGET_ABI32)
6852 ret
= do_arch_prctl(cpu_env
, arg1
, arg2
);
6858 #ifdef TARGET_NR_pread
6859 case TARGET_NR_pread
:
6861 if (((CPUARMState
*)cpu_env
)->eabi
)
6864 if (!(p
= lock_user(VERIFY_WRITE
, arg2
, arg3
, 0)))
6866 ret
= get_errno(pread(arg1
, p
, arg3
, arg4
));
6867 unlock_user(p
, arg2
, ret
);
6869 case TARGET_NR_pwrite
:
6871 if (((CPUARMState
*)cpu_env
)->eabi
)
6874 if (!(p
= lock_user(VERIFY_READ
, arg2
, arg3
, 1)))
6876 ret
= get_errno(pwrite(arg1
, p
, arg3
, arg4
));
6877 unlock_user(p
, arg2
, 0);
6880 #ifdef TARGET_NR_pread64
6881 case TARGET_NR_pread64
:
6882 if (!(p
= lock_user(VERIFY_WRITE
, arg2
, arg3
, 0)))
6884 ret
= get_errno(pread64(arg1
, p
, arg3
, target_offset64(arg4
, arg5
)));
6885 unlock_user(p
, arg2
, ret
);
6887 case TARGET_NR_pwrite64
:
6888 if (!(p
= lock_user(VERIFY_READ
, arg2
, arg3
, 1)))
6890 ret
= get_errno(pwrite64(arg1
, p
, arg3
, target_offset64(arg4
, arg5
)));
6891 unlock_user(p
, arg2
, 0);
6894 case TARGET_NR_getcwd
:
6895 if (!(p
= lock_user(VERIFY_WRITE
, arg1
, arg2
, 0)))
6897 ret
= get_errno(sys_getcwd1(p
, arg2
));
6898 unlock_user(p
, arg1
, ret
);
6900 case TARGET_NR_capget
:
6902 case TARGET_NR_capset
:
6904 case TARGET_NR_sigaltstack
:
6905 #if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_MIPS) || \
6906 defined(TARGET_SPARC) || defined(TARGET_PPC) || defined(TARGET_ALPHA) || \
6907 defined(TARGET_M68K) || defined(TARGET_S390X)
6908 ret
= do_sigaltstack(arg1
, arg2
, get_sp_from_cpustate((CPUState
*)cpu_env
));
6913 case TARGET_NR_sendfile
:
6915 #ifdef TARGET_NR_getpmsg
6916 case TARGET_NR_getpmsg
:
6919 #ifdef TARGET_NR_putpmsg
6920 case TARGET_NR_putpmsg
:
6923 #ifdef TARGET_NR_vfork
6924 case TARGET_NR_vfork
:
6925 ret
= get_errno(do_fork(cpu_env
, CLONE_VFORK
| CLONE_VM
| SIGCHLD
,
6929 #ifdef TARGET_NR_ugetrlimit
6930 case TARGET_NR_ugetrlimit
:
6933 int resource
= target_to_host_resource(arg1
);
6934 ret
= get_errno(getrlimit(resource
, &rlim
));
6935 if (!is_error(ret
)) {
6936 struct target_rlimit
*target_rlim
;
6937 if (!lock_user_struct(VERIFY_WRITE
, target_rlim
, arg2
, 0))
6939 target_rlim
->rlim_cur
= host_to_target_rlim(rlim
.rlim_cur
);
6940 target_rlim
->rlim_max
= host_to_target_rlim(rlim
.rlim_max
);
6941 unlock_user_struct(target_rlim
, arg2
, 1);
6946 #ifdef TARGET_NR_truncate64
6947 case TARGET_NR_truncate64
:
6948 if (!(p
= lock_user_string(arg1
)))
6950 ret
= target_truncate64(cpu_env
, p
, arg2
, arg3
, arg4
);
6951 unlock_user(p
, arg1
, 0);
6954 #ifdef TARGET_NR_ftruncate64
6955 case TARGET_NR_ftruncate64
:
6956 ret
= target_ftruncate64(cpu_env
, arg1
, arg2
, arg3
, arg4
);
6959 #ifdef TARGET_NR_stat64
6960 case TARGET_NR_stat64
:
6961 if (!(p
= lock_user_string(arg1
)))
6963 ret
= get_errno(stat(path(p
), &st
));
6964 unlock_user(p
, arg1
, 0);
6966 ret
= host_to_target_stat64(cpu_env
, arg2
, &st
);
6969 #ifdef TARGET_NR_lstat64
6970 case TARGET_NR_lstat64
:
6971 if (!(p
= lock_user_string(arg1
)))
6973 ret
= get_errno(lstat(path(p
), &st
));
6974 unlock_user(p
, arg1
, 0);
6976 ret
= host_to_target_stat64(cpu_env
, arg2
, &st
);
6979 #ifdef TARGET_NR_fstat64
6980 case TARGET_NR_fstat64
:
6981 ret
= get_errno(fstat(arg1
, &st
));
6983 ret
= host_to_target_stat64(cpu_env
, arg2
, &st
);
6986 #if (defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat)) && \
6987 (defined(__NR_fstatat64) || defined(__NR_newfstatat))
6988 #ifdef TARGET_NR_fstatat64
6989 case TARGET_NR_fstatat64
:
6991 #ifdef TARGET_NR_newfstatat
6992 case TARGET_NR_newfstatat
:
6994 if (!(p
= lock_user_string(arg2
)))
6996 #ifdef __NR_fstatat64
6997 ret
= get_errno(sys_fstatat64(arg1
, path(p
), &st
, arg4
));
6999 ret
= get_errno(sys_newfstatat(arg1
, path(p
), &st
, arg4
));
7002 ret
= host_to_target_stat64(cpu_env
, arg3
, &st
);
7005 case TARGET_NR_lchown
:
7006 if (!(p
= lock_user_string(arg1
)))
7008 ret
= get_errno(lchown(p
, low2highuid(arg2
), low2highgid(arg3
)));
7009 unlock_user(p
, arg1
, 0);
7011 #ifdef TARGET_NR_getuid
7012 case TARGET_NR_getuid
:
7013 ret
= get_errno(high2lowuid(getuid()));
7016 #ifdef TARGET_NR_getgid
7017 case TARGET_NR_getgid
:
7018 ret
= get_errno(high2lowgid(getgid()));
7021 #ifdef TARGET_NR_geteuid
7022 case TARGET_NR_geteuid
:
7023 ret
= get_errno(high2lowuid(geteuid()));
7026 #ifdef TARGET_NR_getegid
7027 case TARGET_NR_getegid
:
7028 ret
= get_errno(high2lowgid(getegid()));
7031 case TARGET_NR_setreuid
:
7032 ret
= get_errno(setreuid(low2highuid(arg1
), low2highuid(arg2
)));
7034 case TARGET_NR_setregid
:
7035 ret
= get_errno(setregid(low2highgid(arg1
), low2highgid(arg2
)));
7037 case TARGET_NR_getgroups
:
7039 int gidsetsize
= arg1
;
7040 target_id
*target_grouplist
;
7044 grouplist
= alloca(gidsetsize
* sizeof(gid_t
));
7045 ret
= get_errno(getgroups(gidsetsize
, grouplist
));
7046 if (gidsetsize
== 0)
7048 if (!is_error(ret
)) {
7049 target_grouplist
= lock_user(VERIFY_WRITE
, arg2
, gidsetsize
* 2, 0);
7050 if (!target_grouplist
)
7052 for(i
= 0;i
< ret
; i
++)
7053 target_grouplist
[i
] = tswapid(high2lowgid(grouplist
[i
]));
7054 unlock_user(target_grouplist
, arg2
, gidsetsize
* 2);
7058 case TARGET_NR_setgroups
:
7060 int gidsetsize
= arg1
;
7061 target_id
*target_grouplist
;
7065 grouplist
= alloca(gidsetsize
* sizeof(gid_t
));
7066 target_grouplist
= lock_user(VERIFY_READ
, arg2
, gidsetsize
* 2, 1);
7067 if (!target_grouplist
) {
7068 ret
= -TARGET_EFAULT
;
7071 for(i
= 0;i
< gidsetsize
; i
++)
7072 grouplist
[i
] = low2highgid(tswapid(target_grouplist
[i
]));
7073 unlock_user(target_grouplist
, arg2
, 0);
7074 ret
= get_errno(setgroups(gidsetsize
, grouplist
));
7077 case TARGET_NR_fchown
:
7078 ret
= get_errno(fchown(arg1
, low2highuid(arg2
), low2highgid(arg3
)));
7080 #if defined(TARGET_NR_fchownat) && defined(__NR_fchownat)
7081 case TARGET_NR_fchownat
:
7082 if (!(p
= lock_user_string(arg2
)))
7084 ret
= get_errno(sys_fchownat(arg1
, p
, low2highuid(arg3
), low2highgid(arg4
), arg5
));
7085 unlock_user(p
, arg2
, 0);
7088 #ifdef TARGET_NR_setresuid
7089 case TARGET_NR_setresuid
:
7090 ret
= get_errno(setresuid(low2highuid(arg1
),
7092 low2highuid(arg3
)));
7095 #ifdef TARGET_NR_getresuid
7096 case TARGET_NR_getresuid
:
7098 uid_t ruid
, euid
, suid
;
7099 ret
= get_errno(getresuid(&ruid
, &euid
, &suid
));
7100 if (!is_error(ret
)) {
7101 if (put_user_u16(high2lowuid(ruid
), arg1
)
7102 || put_user_u16(high2lowuid(euid
), arg2
)
7103 || put_user_u16(high2lowuid(suid
), arg3
))
7109 #ifdef TARGET_NR_getresgid
7110 case TARGET_NR_setresgid
:
7111 ret
= get_errno(setresgid(low2highgid(arg1
),
7113 low2highgid(arg3
)));
7116 #ifdef TARGET_NR_getresgid
7117 case TARGET_NR_getresgid
:
7119 gid_t rgid
, egid
, sgid
;
7120 ret
= get_errno(getresgid(&rgid
, &egid
, &sgid
));
7121 if (!is_error(ret
)) {
7122 if (put_user_u16(high2lowgid(rgid
), arg1
)
7123 || put_user_u16(high2lowgid(egid
), arg2
)
7124 || put_user_u16(high2lowgid(sgid
), arg3
))
7130 case TARGET_NR_chown
:
7131 if (!(p
= lock_user_string(arg1
)))
7133 ret
= get_errno(chown(p
, low2highuid(arg2
), low2highgid(arg3
)));
7134 unlock_user(p
, arg1
, 0);
7136 case TARGET_NR_setuid
:
7137 ret
= get_errno(setuid(low2highuid(arg1
)));
7139 case TARGET_NR_setgid
:
7140 ret
= get_errno(setgid(low2highgid(arg1
)));
7142 case TARGET_NR_setfsuid
:
7143 ret
= get_errno(setfsuid(arg1
));
7145 case TARGET_NR_setfsgid
:
7146 ret
= get_errno(setfsgid(arg1
));
7149 #ifdef TARGET_NR_lchown32
7150 case TARGET_NR_lchown32
:
7151 if (!(p
= lock_user_string(arg1
)))
7153 ret
= get_errno(lchown(p
, arg2
, arg3
));
7154 unlock_user(p
, arg1
, 0);
7157 #ifdef TARGET_NR_getuid32
7158 case TARGET_NR_getuid32
:
7159 ret
= get_errno(getuid());
7163 #if defined(TARGET_NR_getxuid) && defined(TARGET_ALPHA)
7164 /* Alpha specific */
7165 case TARGET_NR_getxuid
:
7169 ((CPUAlphaState
*)cpu_env
)->ir
[IR_A4
]=euid
;
7171 ret
= get_errno(getuid());
7174 #if defined(TARGET_NR_getxgid) && defined(TARGET_ALPHA)
7175 /* Alpha specific */
7176 case TARGET_NR_getxgid
:
7180 ((CPUAlphaState
*)cpu_env
)->ir
[IR_A4
]=egid
;
7182 ret
= get_errno(getgid());
7185 #if defined(TARGET_NR_osf_getsysinfo) && defined(TARGET_ALPHA)
7186 /* Alpha specific */
7187 case TARGET_NR_osf_getsysinfo
:
7188 ret
= -TARGET_EOPNOTSUPP
;
7190 case TARGET_GSI_IEEE_FP_CONTROL
:
7192 uint64_t swcr
, fpcr
= cpu_alpha_load_fpcr (cpu_env
);
7194 /* Copied from linux ieee_fpcr_to_swcr. */
7195 swcr
= (fpcr
>> 35) & SWCR_STATUS_MASK
;
7196 swcr
|= (fpcr
>> 36) & SWCR_MAP_DMZ
;
7197 swcr
|= (~fpcr
>> 48) & (SWCR_TRAP_ENABLE_INV
7198 | SWCR_TRAP_ENABLE_DZE
7199 | SWCR_TRAP_ENABLE_OVF
);
7200 swcr
|= (~fpcr
>> 57) & (SWCR_TRAP_ENABLE_UNF
7201 | SWCR_TRAP_ENABLE_INE
);
7202 swcr
|= (fpcr
>> 47) & SWCR_MAP_UMZ
;
7203 swcr
|= (~fpcr
>> 41) & SWCR_TRAP_ENABLE_DNO
;
7205 if (put_user_u64 (swcr
, arg2
))
7211 /* case GSI_IEEE_STATE_AT_SIGNAL:
7212 -- Not implemented in linux kernel.
7214 -- Retrieves current unaligned access state; not much used.
7216 -- Retrieves implver information; surely not used.
7218 -- Grabs a copy of the HWRPB; surely not used.
7223 #if defined(TARGET_NR_osf_setsysinfo) && defined(TARGET_ALPHA)
7224 /* Alpha specific */
7225 case TARGET_NR_osf_setsysinfo
:
7226 ret
= -TARGET_EOPNOTSUPP
;
7228 case TARGET_SSI_IEEE_FP_CONTROL
:
7229 case TARGET_SSI_IEEE_RAISE_EXCEPTION
:
7231 uint64_t swcr
, fpcr
, orig_fpcr
;
7233 if (get_user_u64 (swcr
, arg2
))
7235 orig_fpcr
= cpu_alpha_load_fpcr (cpu_env
);
7236 fpcr
= orig_fpcr
& FPCR_DYN_MASK
;
7238 /* Copied from linux ieee_swcr_to_fpcr. */
7239 fpcr
|= (swcr
& SWCR_STATUS_MASK
) << 35;
7240 fpcr
|= (swcr
& SWCR_MAP_DMZ
) << 36;
7241 fpcr
|= (~swcr
& (SWCR_TRAP_ENABLE_INV
7242 | SWCR_TRAP_ENABLE_DZE
7243 | SWCR_TRAP_ENABLE_OVF
)) << 48;
7244 fpcr
|= (~swcr
& (SWCR_TRAP_ENABLE_UNF
7245 | SWCR_TRAP_ENABLE_INE
)) << 57;
7246 fpcr
|= (swcr
& SWCR_MAP_UMZ
? FPCR_UNDZ
| FPCR_UNFD
: 0);
7247 fpcr
|= (~swcr
& SWCR_TRAP_ENABLE_DNO
) << 41;
7249 cpu_alpha_store_fpcr (cpu_env
, fpcr
);
7252 if (arg1
== TARGET_SSI_IEEE_RAISE_EXCEPTION
) {
7253 /* Old exceptions are not signaled. */
7254 fpcr
&= ~(orig_fpcr
& FPCR_STATUS_MASK
);
7256 /* If any exceptions set by this call, and are unmasked,
7263 /* case SSI_NVPAIRS:
7264 -- Used with SSIN_UACPROC to enable unaligned accesses.
7265 case SSI_IEEE_STATE_AT_SIGNAL:
7266 case SSI_IEEE_IGNORE_STATE_AT_SIGNAL:
7267 -- Not implemented in linux kernel
7272 #ifdef TARGET_NR_osf_sigprocmask
7273 /* Alpha specific. */
7274 case TARGET_NR_osf_sigprocmask
:
7278 sigset_t set
, oldset
;
7281 case TARGET_SIG_BLOCK
:
7284 case TARGET_SIG_UNBLOCK
:
7287 case TARGET_SIG_SETMASK
:
7291 ret
= -TARGET_EINVAL
;
7295 target_to_host_old_sigset(&set
, &mask
);
7296 sigprocmask(how
, &set
, &oldset
);
7297 host_to_target_old_sigset(&mask
, &oldset
);
7303 #ifdef TARGET_NR_getgid32
7304 case TARGET_NR_getgid32
:
7305 ret
= get_errno(getgid());
7308 #ifdef TARGET_NR_geteuid32
7309 case TARGET_NR_geteuid32
:
7310 ret
= get_errno(geteuid());
7313 #ifdef TARGET_NR_getegid32
7314 case TARGET_NR_getegid32
:
7315 ret
= get_errno(getegid());
7318 #ifdef TARGET_NR_setreuid32
7319 case TARGET_NR_setreuid32
:
7320 ret
= get_errno(setreuid(arg1
, arg2
));
7323 #ifdef TARGET_NR_setregid32
7324 case TARGET_NR_setregid32
:
7325 ret
= get_errno(setregid(arg1
, arg2
));
7328 #ifdef TARGET_NR_getgroups32
7329 case TARGET_NR_getgroups32
:
7331 int gidsetsize
= arg1
;
7332 uint32_t *target_grouplist
;
7336 grouplist
= alloca(gidsetsize
* sizeof(gid_t
));
7337 ret
= get_errno(getgroups(gidsetsize
, grouplist
));
7338 if (gidsetsize
== 0)
7340 if (!is_error(ret
)) {
7341 target_grouplist
= lock_user(VERIFY_WRITE
, arg2
, gidsetsize
* 4, 0);
7342 if (!target_grouplist
) {
7343 ret
= -TARGET_EFAULT
;
7346 for(i
= 0;i
< ret
; i
++)
7347 target_grouplist
[i
] = tswap32(grouplist
[i
]);
7348 unlock_user(target_grouplist
, arg2
, gidsetsize
* 4);
7353 #ifdef TARGET_NR_setgroups32
7354 case TARGET_NR_setgroups32
:
7356 int gidsetsize
= arg1
;
7357 uint32_t *target_grouplist
;
7361 grouplist
= alloca(gidsetsize
* sizeof(gid_t
));
7362 target_grouplist
= lock_user(VERIFY_READ
, arg2
, gidsetsize
* 4, 1);
7363 if (!target_grouplist
) {
7364 ret
= -TARGET_EFAULT
;
7367 for(i
= 0;i
< gidsetsize
; i
++)
7368 grouplist
[i
] = tswap32(target_grouplist
[i
]);
7369 unlock_user(target_grouplist
, arg2
, 0);
7370 ret
= get_errno(setgroups(gidsetsize
, grouplist
));
7374 #ifdef TARGET_NR_fchown32
7375 case TARGET_NR_fchown32
:
7376 ret
= get_errno(fchown(arg1
, arg2
, arg3
));
7379 #ifdef TARGET_NR_setresuid32
7380 case TARGET_NR_setresuid32
:
7381 ret
= get_errno(setresuid(arg1
, arg2
, arg3
));
7384 #ifdef TARGET_NR_getresuid32
7385 case TARGET_NR_getresuid32
:
7387 uid_t ruid
, euid
, suid
;
7388 ret
= get_errno(getresuid(&ruid
, &euid
, &suid
));
7389 if (!is_error(ret
)) {
7390 if (put_user_u32(ruid
, arg1
)
7391 || put_user_u32(euid
, arg2
)
7392 || put_user_u32(suid
, arg3
))
7398 #ifdef TARGET_NR_setresgid32
7399 case TARGET_NR_setresgid32
:
7400 ret
= get_errno(setresgid(arg1
, arg2
, arg3
));
7403 #ifdef TARGET_NR_getresgid32
7404 case TARGET_NR_getresgid32
:
7406 gid_t rgid
, egid
, sgid
;
7407 ret
= get_errno(getresgid(&rgid
, &egid
, &sgid
));
7408 if (!is_error(ret
)) {
7409 if (put_user_u32(rgid
, arg1
)
7410 || put_user_u32(egid
, arg2
)
7411 || put_user_u32(sgid
, arg3
))
7417 #ifdef TARGET_NR_chown32
7418 case TARGET_NR_chown32
:
7419 if (!(p
= lock_user_string(arg1
)))
7421 ret
= get_errno(chown(p
, arg2
, arg3
));
7422 unlock_user(p
, arg1
, 0);
7425 #ifdef TARGET_NR_setuid32
7426 case TARGET_NR_setuid32
:
7427 ret
= get_errno(setuid(arg1
));
7430 #ifdef TARGET_NR_setgid32
7431 case TARGET_NR_setgid32
:
7432 ret
= get_errno(setgid(arg1
));
7435 #ifdef TARGET_NR_setfsuid32
7436 case TARGET_NR_setfsuid32
:
7437 ret
= get_errno(setfsuid(arg1
));
7440 #ifdef TARGET_NR_setfsgid32
7441 case TARGET_NR_setfsgid32
:
7442 ret
= get_errno(setfsgid(arg1
));
7446 case TARGET_NR_pivot_root
:
7448 #ifdef TARGET_NR_mincore
7449 case TARGET_NR_mincore
:
7452 ret
= -TARGET_EFAULT
;
7453 if (!(a
= lock_user(VERIFY_READ
, arg1
,arg2
, 0)))
7455 if (!(p
= lock_user_string(arg3
)))
7457 ret
= get_errno(mincore(a
, arg2
, p
));
7458 unlock_user(p
, arg3
, ret
);
7460 unlock_user(a
, arg1
, 0);
7464 #ifdef TARGET_NR_arm_fadvise64_64
7465 case TARGET_NR_arm_fadvise64_64
:
7468 * arm_fadvise64_64 looks like fadvise64_64 but
7469 * with different argument order
7477 #if defined(TARGET_NR_fadvise64_64) || defined(TARGET_NR_arm_fadvise64_64) || defined(TARGET_NR_fadvise64)
7478 #ifdef TARGET_NR_fadvise64_64
7479 case TARGET_NR_fadvise64_64
:
7481 #ifdef TARGET_NR_fadvise64
7482 case TARGET_NR_fadvise64
:
7486 case 4: arg4
= POSIX_FADV_NOREUSE
+ 1; break; /* make sure it's an invalid value */
7487 case 5: arg4
= POSIX_FADV_NOREUSE
+ 2; break; /* ditto */
7488 case 6: arg4
= POSIX_FADV_DONTNEED
; break;
7489 case 7: arg4
= POSIX_FADV_NOREUSE
; break;
7493 ret
= -posix_fadvise(arg1
, arg2
, arg3
, arg4
);
7496 #ifdef TARGET_NR_madvise
7497 case TARGET_NR_madvise
:
7498 /* A straight passthrough may not be safe because qemu sometimes
7499 turns private flie-backed mappings into anonymous mappings.
7500 This will break MADV_DONTNEED.
7501 This is a hint, so ignoring and returning success is ok. */
7505 #if TARGET_ABI_BITS == 32
7506 case TARGET_NR_fcntl64
:
7510 struct target_flock64
*target_fl
;
7512 struct target_eabi_flock64
*target_efl
;
7515 cmd
= target_to_host_fcntl_cmd(arg2
);
7516 if (cmd
== -TARGET_EINVAL
)
7520 case TARGET_F_GETLK64
:
7522 if (((CPUARMState
*)cpu_env
)->eabi
) {
7523 if (!lock_user_struct(VERIFY_READ
, target_efl
, arg3
, 1))
7525 fl
.l_type
= tswap16(target_efl
->l_type
);
7526 fl
.l_whence
= tswap16(target_efl
->l_whence
);
7527 fl
.l_start
= tswap64(target_efl
->l_start
);
7528 fl
.l_len
= tswap64(target_efl
->l_len
);
7529 fl
.l_pid
= tswap32(target_efl
->l_pid
);
7530 unlock_user_struct(target_efl
, arg3
, 0);
7534 if (!lock_user_struct(VERIFY_READ
, target_fl
, arg3
, 1))
7536 fl
.l_type
= tswap16(target_fl
->l_type
);
7537 fl
.l_whence
= tswap16(target_fl
->l_whence
);
7538 fl
.l_start
= tswap64(target_fl
->l_start
);
7539 fl
.l_len
= tswap64(target_fl
->l_len
);
7540 fl
.l_pid
= tswap32(target_fl
->l_pid
);
7541 unlock_user_struct(target_fl
, arg3
, 0);
7543 ret
= get_errno(fcntl(arg1
, cmd
, &fl
));
7546 if (((CPUARMState
*)cpu_env
)->eabi
) {
7547 if (!lock_user_struct(VERIFY_WRITE
, target_efl
, arg3
, 0))
7549 target_efl
->l_type
= tswap16(fl
.l_type
);
7550 target_efl
->l_whence
= tswap16(fl
.l_whence
);
7551 target_efl
->l_start
= tswap64(fl
.l_start
);
7552 target_efl
->l_len
= tswap64(fl
.l_len
);
7553 target_efl
->l_pid
= tswap32(fl
.l_pid
);
7554 unlock_user_struct(target_efl
, arg3
, 1);
7558 if (!lock_user_struct(VERIFY_WRITE
, target_fl
, arg3
, 0))
7560 target_fl
->l_type
= tswap16(fl
.l_type
);
7561 target_fl
->l_whence
= tswap16(fl
.l_whence
);
7562 target_fl
->l_start
= tswap64(fl
.l_start
);
7563 target_fl
->l_len
= tswap64(fl
.l_len
);
7564 target_fl
->l_pid
= tswap32(fl
.l_pid
);
7565 unlock_user_struct(target_fl
, arg3
, 1);
7570 case TARGET_F_SETLK64
:
7571 case TARGET_F_SETLKW64
:
7573 if (((CPUARMState
*)cpu_env
)->eabi
) {
7574 if (!lock_user_struct(VERIFY_READ
, target_efl
, arg3
, 1))
7576 fl
.l_type
= tswap16(target_efl
->l_type
);
7577 fl
.l_whence
= tswap16(target_efl
->l_whence
);
7578 fl
.l_start
= tswap64(target_efl
->l_start
);
7579 fl
.l_len
= tswap64(target_efl
->l_len
);
7580 fl
.l_pid
= tswap32(target_efl
->l_pid
);
7581 unlock_user_struct(target_efl
, arg3
, 0);
7585 if (!lock_user_struct(VERIFY_READ
, target_fl
, arg3
, 1))
7587 fl
.l_type
= tswap16(target_fl
->l_type
);
7588 fl
.l_whence
= tswap16(target_fl
->l_whence
);
7589 fl
.l_start
= tswap64(target_fl
->l_start
);
7590 fl
.l_len
= tswap64(target_fl
->l_len
);
7591 fl
.l_pid
= tswap32(target_fl
->l_pid
);
7592 unlock_user_struct(target_fl
, arg3
, 0);
7594 ret
= get_errno(fcntl(arg1
, cmd
, &fl
));
7597 ret
= do_fcntl(arg1
, arg2
, arg3
);
7603 #ifdef TARGET_NR_cacheflush
7604 case TARGET_NR_cacheflush
:
7605 /* self-modifying code is handled automatically, so nothing needed */
7609 #ifdef TARGET_NR_security
7610 case TARGET_NR_security
:
7613 #ifdef TARGET_NR_getpagesize
7614 case TARGET_NR_getpagesize
:
7615 ret
= TARGET_PAGE_SIZE
;
7618 case TARGET_NR_gettid
:
7619 ret
= get_errno(gettid());
7621 #ifdef TARGET_NR_readahead
7622 case TARGET_NR_readahead
:
7623 #if TARGET_ABI_BITS == 32
7625 if (((CPUARMState
*)cpu_env
)->eabi
)
7632 ret
= get_errno(readahead(arg1
, ((off64_t
)arg3
<< 32) | arg2
, arg4
));
7634 ret
= get_errno(readahead(arg1
, arg2
, arg3
));
7638 #ifdef TARGET_NR_setxattr
7639 case TARGET_NR_setxattr
:
7640 case TARGET_NR_lsetxattr
:
7641 case TARGET_NR_fsetxattr
:
7642 case TARGET_NR_getxattr
:
7643 case TARGET_NR_lgetxattr
:
7644 case TARGET_NR_fgetxattr
:
7645 case TARGET_NR_listxattr
:
7646 case TARGET_NR_llistxattr
:
7647 case TARGET_NR_flistxattr
:
7648 case TARGET_NR_removexattr
:
7649 case TARGET_NR_lremovexattr
:
7650 case TARGET_NR_fremovexattr
:
7651 ret
= -TARGET_EOPNOTSUPP
;
7654 #ifdef TARGET_NR_set_thread_area
7655 case TARGET_NR_set_thread_area
:
7656 #if defined(TARGET_MIPS)
7657 ((CPUMIPSState
*) cpu_env
)->tls_value
= arg1
;
7660 #elif defined(TARGET_CRIS)
7662 ret
= -TARGET_EINVAL
;
7664 ((CPUCRISState
*) cpu_env
)->pregs
[PR_PID
] = arg1
;
7668 #elif defined(TARGET_I386) && defined(TARGET_ABI32)
7669 ret
= do_set_thread_area(cpu_env
, arg1
);
7672 goto unimplemented_nowarn
;
7675 #ifdef TARGET_NR_get_thread_area
7676 case TARGET_NR_get_thread_area
:
7677 #if defined(TARGET_I386) && defined(TARGET_ABI32)
7678 ret
= do_get_thread_area(cpu_env
, arg1
);
7680 goto unimplemented_nowarn
;
7683 #ifdef TARGET_NR_getdomainname
7684 case TARGET_NR_getdomainname
:
7685 goto unimplemented_nowarn
;
7688 #ifdef TARGET_NR_clock_gettime
7689 case TARGET_NR_clock_gettime
:
7692 ret
= get_errno(clock_gettime(arg1
, &ts
));
7693 if (!is_error(ret
)) {
7694 host_to_target_timespec(arg2
, &ts
);
7699 #ifdef TARGET_NR_clock_getres
7700 case TARGET_NR_clock_getres
:
7703 ret
= get_errno(clock_getres(arg1
, &ts
));
7704 if (!is_error(ret
)) {
7705 host_to_target_timespec(arg2
, &ts
);
7710 #ifdef TARGET_NR_clock_nanosleep
7711 case TARGET_NR_clock_nanosleep
:
7714 target_to_host_timespec(&ts
, arg3
);
7715 ret
= get_errno(clock_nanosleep(arg1
, arg2
, &ts
, arg4
? &ts
: NULL
));
7717 host_to_target_timespec(arg4
, &ts
);
7722 #if defined(TARGET_NR_set_tid_address) && defined(__NR_set_tid_address)
7723 case TARGET_NR_set_tid_address
:
7724 ret
= get_errno(set_tid_address((int *)g2h(arg1
)));
7728 #if defined(TARGET_NR_tkill) && defined(__NR_tkill)
7729 case TARGET_NR_tkill
:
7730 ret
= get_errno(sys_tkill((int)arg1
, target_to_host_signal(arg2
)));
7734 #if defined(TARGET_NR_tgkill) && defined(__NR_tgkill)
7735 case TARGET_NR_tgkill
:
7736 ret
= get_errno(sys_tgkill((int)arg1
, (int)arg2
,
7737 target_to_host_signal(arg3
)));
7741 #ifdef TARGET_NR_set_robust_list
7742 case TARGET_NR_set_robust_list
:
7743 goto unimplemented_nowarn
;
7746 #if defined(TARGET_NR_utimensat) && defined(__NR_utimensat)
7747 case TARGET_NR_utimensat
:
7749 struct timespec
*tsp
, ts
[2];
7753 target_to_host_timespec(ts
, arg3
);
7754 target_to_host_timespec(ts
+1, arg3
+sizeof(struct target_timespec
));
7758 ret
= get_errno(sys_utimensat(arg1
, NULL
, tsp
, arg4
));
7760 if (!(p
= lock_user_string(arg2
))) {
7761 ret
= -TARGET_EFAULT
;
7764 ret
= get_errno(sys_utimensat(arg1
, path(p
), tsp
, arg4
));
7765 unlock_user(p
, arg2
, 0);
7770 #if defined(CONFIG_USE_NPTL)
7771 case TARGET_NR_futex
:
7772 ret
= do_futex(arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
7775 #if defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init)
7776 case TARGET_NR_inotify_init
:
7777 ret
= get_errno(sys_inotify_init());
7780 #ifdef CONFIG_INOTIFY1
7781 #if defined(TARGET_NR_inotify_init1) && defined(__NR_inotify_init1)
7782 case TARGET_NR_inotify_init1
:
7783 ret
= get_errno(sys_inotify_init1(arg1
));
7787 #if defined(TARGET_NR_inotify_add_watch) && defined(__NR_inotify_add_watch)
7788 case TARGET_NR_inotify_add_watch
:
7789 p
= lock_user_string(arg2
);
7790 ret
= get_errno(sys_inotify_add_watch(arg1
, path(p
), arg3
));
7791 unlock_user(p
, arg2
, 0);
7794 #if defined(TARGET_NR_inotify_rm_watch) && defined(__NR_inotify_rm_watch)
7795 case TARGET_NR_inotify_rm_watch
:
7796 ret
= get_errno(sys_inotify_rm_watch(arg1
, arg2
));
7800 #if defined(TARGET_NR_mq_open) && defined(__NR_mq_open)
7801 case TARGET_NR_mq_open
:
7803 struct mq_attr posix_mq_attr
;
7805 p
= lock_user_string(arg1
- 1);
7807 copy_from_user_mq_attr (&posix_mq_attr
, arg4
);
7808 ret
= get_errno(mq_open(p
, arg2
, arg3
, &posix_mq_attr
));
7809 unlock_user (p
, arg1
, 0);
7813 case TARGET_NR_mq_unlink
:
7814 p
= lock_user_string(arg1
- 1);
7815 ret
= get_errno(mq_unlink(p
));
7816 unlock_user (p
, arg1
, 0);
7819 case TARGET_NR_mq_timedsend
:
7823 p
= lock_user (VERIFY_READ
, arg2
, arg3
, 1);
7825 target_to_host_timespec(&ts
, arg5
);
7826 ret
= get_errno(mq_timedsend(arg1
, p
, arg3
, arg4
, &ts
));
7827 host_to_target_timespec(arg5
, &ts
);
7830 ret
= get_errno(mq_send(arg1
, p
, arg3
, arg4
));
7831 unlock_user (p
, arg2
, arg3
);
7835 case TARGET_NR_mq_timedreceive
:
7840 p
= lock_user (VERIFY_READ
, arg2
, arg3
, 1);
7842 target_to_host_timespec(&ts
, arg5
);
7843 ret
= get_errno(mq_timedreceive(arg1
, p
, arg3
, &prio
, &ts
));
7844 host_to_target_timespec(arg5
, &ts
);
7847 ret
= get_errno(mq_receive(arg1
, p
, arg3
, &prio
));
7848 unlock_user (p
, arg2
, arg3
);
7850 put_user_u32(prio
, arg4
);
7854 /* Not implemented for now... */
7855 /* case TARGET_NR_mq_notify: */
7858 case TARGET_NR_mq_getsetattr
:
7860 struct mq_attr posix_mq_attr_in
, posix_mq_attr_out
;
7863 ret
= mq_getattr(arg1
, &posix_mq_attr_out
);
7864 copy_to_user_mq_attr(arg3
, &posix_mq_attr_out
);
7867 copy_from_user_mq_attr(&posix_mq_attr_in
, arg2
);
7868 ret
|= mq_setattr(arg1
, &posix_mq_attr_in
, &posix_mq_attr_out
);
7875 #ifdef CONFIG_SPLICE
7876 #ifdef TARGET_NR_tee
7879 ret
= get_errno(tee(arg1
,arg2
,arg3
,arg4
));
7883 #ifdef TARGET_NR_splice
7884 case TARGET_NR_splice
:
7886 loff_t loff_in
, loff_out
;
7887 loff_t
*ploff_in
= NULL
, *ploff_out
= NULL
;
7889 get_user_u64(loff_in
, arg2
);
7890 ploff_in
= &loff_in
;
7893 get_user_u64(loff_out
, arg2
);
7894 ploff_out
= &loff_out
;
7896 ret
= get_errno(splice(arg1
, ploff_in
, arg3
, ploff_out
, arg5
, arg6
));
7900 #ifdef TARGET_NR_vmsplice
7901 case TARGET_NR_vmsplice
:
7906 vec
= alloca(count
* sizeof(struct iovec
));
7907 if (lock_iovec(VERIFY_READ
, vec
, arg2
, count
, 1) < 0)
7909 ret
= get_errno(vmsplice(arg1
, vec
, count
, arg4
));
7910 unlock_iovec(vec
, arg2
, count
, 0);
7914 #endif /* CONFIG_SPLICE */
7915 #ifdef CONFIG_EVENTFD
7916 #if defined(TARGET_NR_eventfd)
7917 case TARGET_NR_eventfd
:
7918 ret
= get_errno(eventfd(arg1
, 0));
7921 #if defined(TARGET_NR_eventfd2)
7922 case TARGET_NR_eventfd2
:
7923 ret
= get_errno(eventfd(arg1
, arg2
));
7926 #endif /* CONFIG_EVENTFD */
7927 #if defined(CONFIG_FALLOCATE) && defined(TARGET_NR_fallocate)
7928 case TARGET_NR_fallocate
:
7929 ret
= get_errno(fallocate(arg1
, arg2
, arg3
, arg4
));
7932 #if defined(CONFIG_SYNC_FILE_RANGE)
7933 #if defined(TARGET_NR_sync_file_range)
7934 case TARGET_NR_sync_file_range
:
7935 #if TARGET_ABI_BITS == 32
7936 #if defined(TARGET_MIPS)
7937 ret
= get_errno(sync_file_range(arg1
, target_offset64(arg3
, arg4
),
7938 target_offset64(arg5
, arg6
), arg7
));
7940 ret
= get_errno(sync_file_range(arg1
, target_offset64(arg2
, arg3
),
7941 target_offset64(arg4
, arg5
), arg6
));
7942 #endif /* !TARGET_MIPS */
7944 ret
= get_errno(sync_file_range(arg1
, arg2
, arg3
, arg4
));
7948 #if defined(TARGET_NR_sync_file_range2)
7949 case TARGET_NR_sync_file_range2
:
7950 /* This is like sync_file_range but the arguments are reordered */
7951 #if TARGET_ABI_BITS == 32
7952 ret
= get_errno(sync_file_range(arg1
, target_offset64(arg3
, arg4
),
7953 target_offset64(arg5
, arg6
), arg2
));
7955 ret
= get_errno(sync_file_range(arg1
, arg3
, arg4
, arg2
));
7960 #if defined(CONFIG_EPOLL)
7961 #if defined(TARGET_NR_epoll_create)
7962 case TARGET_NR_epoll_create
:
7963 ret
= get_errno(epoll_create(arg1
));
7966 #if defined(TARGET_NR_epoll_create1) && defined(CONFIG_EPOLL_CREATE1)
7967 case TARGET_NR_epoll_create1
:
7968 ret
= get_errno(epoll_create1(arg1
));
7971 #if defined(TARGET_NR_epoll_ctl)
7972 case TARGET_NR_epoll_ctl
:
7974 struct epoll_event ep
;
7975 struct epoll_event
*epp
= 0;
7977 struct target_epoll_event
*target_ep
;
7978 if (!lock_user_struct(VERIFY_READ
, target_ep
, arg4
, 1)) {
7981 ep
.events
= tswap32(target_ep
->events
);
7982 /* The epoll_data_t union is just opaque data to the kernel,
7983 * so we transfer all 64 bits across and need not worry what
7984 * actual data type it is.
7986 ep
.data
.u64
= tswap64(target_ep
->data
.u64
);
7987 unlock_user_struct(target_ep
, arg4
, 0);
7990 ret
= get_errno(epoll_ctl(arg1
, arg2
, arg3
, epp
));
7995 #if defined(TARGET_NR_epoll_pwait) && defined(CONFIG_EPOLL_PWAIT)
7996 #define IMPLEMENT_EPOLL_PWAIT
7998 #if defined(TARGET_NR_epoll_wait) || defined(IMPLEMENT_EPOLL_PWAIT)
7999 #if defined(TARGET_NR_epoll_wait)
8000 case TARGET_NR_epoll_wait
:
8002 #if defined(IMPLEMENT_EPOLL_PWAIT)
8003 case TARGET_NR_epoll_pwait
:
8006 struct target_epoll_event
*target_ep
;
8007 struct epoll_event
*ep
;
8009 int maxevents
= arg3
;
8012 target_ep
= lock_user(VERIFY_WRITE
, arg2
,
8013 maxevents
* sizeof(struct target_epoll_event
), 1);
8018 ep
= alloca(maxevents
* sizeof(struct epoll_event
));
8021 #if defined(IMPLEMENT_EPOLL_PWAIT)
8022 case TARGET_NR_epoll_pwait
:
8024 target_sigset_t
*target_set
;
8025 sigset_t _set
, *set
= &_set
;
8028 target_set
= lock_user(VERIFY_READ
, arg5
,
8029 sizeof(target_sigset_t
), 1);
8031 unlock_user(target_ep
, arg2
, 0);
8034 target_to_host_sigset(set
, target_set
);
8035 unlock_user(target_set
, arg5
, 0);
8040 ret
= get_errno(epoll_pwait(epfd
, ep
, maxevents
, timeout
, set
));
8044 #if defined(TARGET_NR_epoll_wait)
8045 case TARGET_NR_epoll_wait
:
8046 ret
= get_errno(epoll_wait(epfd
, ep
, maxevents
, timeout
));
8050 ret
= -TARGET_ENOSYS
;
8052 if (!is_error(ret
)) {
8054 for (i
= 0; i
< ret
; i
++) {
8055 target_ep
[i
].events
= tswap32(ep
[i
].events
);
8056 target_ep
[i
].data
.u64
= tswap64(ep
[i
].data
.u64
);
8059 unlock_user(target_ep
, arg2
, ret
* sizeof(struct target_epoll_event
));
8064 #ifdef TARGET_NR_prlimit64
8065 case TARGET_NR_prlimit64
:
8067 /* args: pid, resource number, ptr to new rlimit, ptr to old rlimit */
8068 struct target_rlimit64
*target_rnew
, *target_rold
;
8069 struct host_rlimit64 rnew
, rold
, *rnewp
= 0;
8071 if (!lock_user_struct(VERIFY_READ
, target_rnew
, arg3
, 1)) {
8074 rnew
.rlim_cur
= tswap64(target_rnew
->rlim_cur
);
8075 rnew
.rlim_max
= tswap64(target_rnew
->rlim_max
);
8076 unlock_user_struct(target_rnew
, arg3
, 0);
8080 ret
= get_errno(sys_prlimit64(arg1
, arg2
, rnewp
, arg4
? &rold
: 0));
8081 if (!is_error(ret
) && arg4
) {
8082 if (!lock_user_struct(VERIFY_WRITE
, target_rold
, arg4
, 1)) {
8085 target_rold
->rlim_cur
= tswap64(rold
.rlim_cur
);
8086 target_rold
->rlim_max
= tswap64(rold
.rlim_max
);
8087 unlock_user_struct(target_rold
, arg4
, 1);
8094 gemu_log("qemu: Unsupported syscall: %d\n", num
);
8095 #if defined(TARGET_NR_setxattr) || defined(TARGET_NR_get_thread_area) || defined(TARGET_NR_getdomainname) || defined(TARGET_NR_set_robust_list)
8096 unimplemented_nowarn
:
8098 ret
= -TARGET_ENOSYS
;
8103 gemu_log(" = " TARGET_ABI_FMT_ld
"\n", ret
);
8106 print_syscall_ret(num
, ret
);
8109 ret
= -TARGET_EFAULT
;