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
32 #include <sys/types.h>
38 #include <sys/mount.h>
40 #include <sys/fsuid.h>
41 #include <sys/personality.h>
42 #include <sys/prctl.h>
43 #include <sys/resource.h>
49 int __clone2(int (*fn
)(void *), void *child_stack_base
,
50 size_t stack_size
, int flags
, void *arg
, ...);
52 #include <sys/socket.h>
56 #include <sys/times.h>
59 #include <sys/statfs.h>
61 #include <sys/sysinfo.h>
62 #include <sys/utsname.h>
63 //#include <sys/user.h>
64 #include <netinet/ip.h>
65 #include <netinet/tcp.h>
66 #include <linux/wireless.h>
67 #include <linux/icmp.h>
68 #include "qemu-common.h"
73 #include <sys/eventfd.h>
76 #include <sys/epoll.h>
79 #include "qemu/xattr.h"
81 #ifdef CONFIG_SENDFILE
82 #include <sys/sendfile.h>
85 #define termios host_termios
86 #define winsize host_winsize
87 #define termio host_termio
88 #define sgttyb host_sgttyb /* same as target */
89 #define tchars host_tchars /* same as target */
90 #define ltchars host_ltchars /* same as target */
92 #include <linux/termios.h>
93 #include <linux/unistd.h>
94 #include <linux/utsname.h>
95 #include <linux/cdrom.h>
96 #include <linux/hdreg.h>
97 #include <linux/soundcard.h>
99 #include <linux/mtio.h>
100 #include <linux/fs.h>
101 #if defined(CONFIG_FIEMAP)
102 #include <linux/fiemap.h>
104 #include <linux/fb.h>
105 #include <linux/vt.h>
106 #include <linux/dm-ioctl.h>
107 #include <linux/reboot.h>
108 #include <linux/route.h>
109 #include <linux/filter.h>
110 #include "linux_loop.h"
111 #include "cpu-uname.h"
115 #define CLONE_NPTL_FLAGS2 (CLONE_SETTLS | \
116 CLONE_PARENT_SETTID | CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID)
120 //#include <linux/msdos_fs.h>
121 #define VFAT_IOCTL_READDIR_BOTH _IOR('r', 1, struct linux_dirent [2])
122 #define VFAT_IOCTL_READDIR_SHORT _IOR('r', 2, struct linux_dirent [2])
133 #define _syscall0(type,name) \
134 static type name (void) \
136 return syscall(__NR_##name); \
139 #define _syscall1(type,name,type1,arg1) \
140 static type name (type1 arg1) \
142 return syscall(__NR_##name, arg1); \
145 #define _syscall2(type,name,type1,arg1,type2,arg2) \
146 static type name (type1 arg1,type2 arg2) \
148 return syscall(__NR_##name, arg1, arg2); \
151 #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
152 static type name (type1 arg1,type2 arg2,type3 arg3) \
154 return syscall(__NR_##name, arg1, arg2, arg3); \
157 #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
158 static type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4) \
160 return syscall(__NR_##name, arg1, arg2, arg3, arg4); \
163 #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
165 static type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \
167 return syscall(__NR_##name, arg1, arg2, arg3, arg4, arg5); \
171 #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
172 type5,arg5,type6,arg6) \
173 static type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5, \
176 return syscall(__NR_##name, arg1, arg2, arg3, arg4, arg5, arg6); \
180 #define __NR_sys_uname __NR_uname
181 #define __NR_sys_getcwd1 __NR_getcwd
182 #define __NR_sys_getdents __NR_getdents
183 #define __NR_sys_getdents64 __NR_getdents64
184 #define __NR_sys_getpriority __NR_getpriority
185 #define __NR_sys_rt_sigqueueinfo __NR_rt_sigqueueinfo
186 #define __NR_sys_syslog __NR_syslog
187 #define __NR_sys_tgkill __NR_tgkill
188 #define __NR_sys_tkill __NR_tkill
189 #define __NR_sys_futex __NR_futex
190 #define __NR_sys_inotify_init __NR_inotify_init
191 #define __NR_sys_inotify_add_watch __NR_inotify_add_watch
192 #define __NR_sys_inotify_rm_watch __NR_inotify_rm_watch
194 #if defined(__alpha__) || defined (__ia64__) || defined(__x86_64__) || \
196 #define __NR__llseek __NR_lseek
200 _syscall0(int, gettid
)
202 /* This is a replacement for the host gettid() and must return a host
204 static int gettid(void) {
209 _syscall3(int, sys_getdents
, uint
, fd
, struct linux_dirent
*, dirp
, uint
, count
);
211 #if !defined(__NR_getdents) || \
212 (defined(TARGET_NR_getdents64) && defined(__NR_getdents64))
213 _syscall3(int, sys_getdents64
, uint
, fd
, struct linux_dirent64
*, dirp
, uint
, count
);
215 #if defined(TARGET_NR__llseek) && defined(__NR_llseek)
216 _syscall5(int, _llseek
, uint
, fd
, ulong
, hi
, ulong
, lo
,
217 loff_t
*, res
, uint
, wh
);
219 _syscall3(int,sys_rt_sigqueueinfo
,int,pid
,int,sig
,siginfo_t
*,uinfo
)
220 _syscall3(int,sys_syslog
,int,type
,char*,bufp
,int,len
)
221 #if defined(TARGET_NR_tgkill) && defined(__NR_tgkill)
222 _syscall3(int,sys_tgkill
,int,tgid
,int,pid
,int,sig
)
224 #if defined(TARGET_NR_tkill) && defined(__NR_tkill)
225 _syscall2(int,sys_tkill
,int,tid
,int,sig
)
227 #ifdef __NR_exit_group
228 _syscall1(int,exit_group
,int,error_code
)
230 #if defined(TARGET_NR_set_tid_address) && defined(__NR_set_tid_address)
231 _syscall1(int,set_tid_address
,int *,tidptr
)
233 #if defined(TARGET_NR_futex) && defined(__NR_futex)
234 _syscall6(int,sys_futex
,int *,uaddr
,int,op
,int,val
,
235 const struct timespec
*,timeout
,int *,uaddr2
,int,val3
)
237 #define __NR_sys_sched_getaffinity __NR_sched_getaffinity
238 _syscall3(int, sys_sched_getaffinity
, pid_t
, pid
, unsigned int, len
,
239 unsigned long *, user_mask_ptr
);
240 #define __NR_sys_sched_setaffinity __NR_sched_setaffinity
241 _syscall3(int, sys_sched_setaffinity
, pid_t
, pid
, unsigned int, len
,
242 unsigned long *, user_mask_ptr
);
243 _syscall4(int, reboot
, int, magic1
, int, magic2
, unsigned int, cmd
,
246 static bitmask_transtbl fcntl_flags_tbl
[] = {
247 { TARGET_O_ACCMODE
, TARGET_O_WRONLY
, O_ACCMODE
, O_WRONLY
, },
248 { TARGET_O_ACCMODE
, TARGET_O_RDWR
, O_ACCMODE
, O_RDWR
, },
249 { TARGET_O_CREAT
, TARGET_O_CREAT
, O_CREAT
, O_CREAT
, },
250 { TARGET_O_EXCL
, TARGET_O_EXCL
, O_EXCL
, O_EXCL
, },
251 { TARGET_O_NOCTTY
, TARGET_O_NOCTTY
, O_NOCTTY
, O_NOCTTY
, },
252 { TARGET_O_TRUNC
, TARGET_O_TRUNC
, O_TRUNC
, O_TRUNC
, },
253 { TARGET_O_APPEND
, TARGET_O_APPEND
, O_APPEND
, O_APPEND
, },
254 { TARGET_O_NONBLOCK
, TARGET_O_NONBLOCK
, O_NONBLOCK
, O_NONBLOCK
, },
255 { TARGET_O_SYNC
, TARGET_O_DSYNC
, O_SYNC
, O_DSYNC
, },
256 { TARGET_O_SYNC
, TARGET_O_SYNC
, O_SYNC
, O_SYNC
, },
257 { TARGET_FASYNC
, TARGET_FASYNC
, FASYNC
, FASYNC
, },
258 { TARGET_O_DIRECTORY
, TARGET_O_DIRECTORY
, O_DIRECTORY
, O_DIRECTORY
, },
259 { TARGET_O_NOFOLLOW
, TARGET_O_NOFOLLOW
, O_NOFOLLOW
, O_NOFOLLOW
, },
260 #if defined(O_DIRECT)
261 { TARGET_O_DIRECT
, TARGET_O_DIRECT
, O_DIRECT
, O_DIRECT
, },
263 #if defined(O_NOATIME)
264 { TARGET_O_NOATIME
, TARGET_O_NOATIME
, O_NOATIME
, O_NOATIME
},
266 #if defined(O_CLOEXEC)
267 { TARGET_O_CLOEXEC
, TARGET_O_CLOEXEC
, O_CLOEXEC
, O_CLOEXEC
},
270 { TARGET_O_PATH
, TARGET_O_PATH
, O_PATH
, O_PATH
},
272 /* Don't terminate the list prematurely on 64-bit host+guest. */
273 #if TARGET_O_LARGEFILE != 0 || O_LARGEFILE != 0
274 { TARGET_O_LARGEFILE
, TARGET_O_LARGEFILE
, O_LARGEFILE
, O_LARGEFILE
, },
279 #define COPY_UTSNAME_FIELD(dest, src) \
281 /* __NEW_UTS_LEN doesn't include terminating null */ \
282 (void) strncpy((dest), (src), __NEW_UTS_LEN); \
283 (dest)[__NEW_UTS_LEN] = '\0'; \
286 static int sys_uname(struct new_utsname
*buf
)
288 struct utsname uts_buf
;
290 if (uname(&uts_buf
) < 0)
294 * Just in case these have some differences, we
295 * translate utsname to new_utsname (which is the
296 * struct linux kernel uses).
299 memset(buf
, 0, sizeof(*buf
));
300 COPY_UTSNAME_FIELD(buf
->sysname
, uts_buf
.sysname
);
301 COPY_UTSNAME_FIELD(buf
->nodename
, uts_buf
.nodename
);
302 COPY_UTSNAME_FIELD(buf
->release
, uts_buf
.release
);
303 COPY_UTSNAME_FIELD(buf
->version
, uts_buf
.version
);
304 COPY_UTSNAME_FIELD(buf
->machine
, uts_buf
.machine
);
306 COPY_UTSNAME_FIELD(buf
->domainname
, uts_buf
.domainname
);
310 #undef COPY_UTSNAME_FIELD
313 static int sys_getcwd1(char *buf
, size_t size
)
315 if (getcwd(buf
, size
) == NULL
) {
316 /* getcwd() sets errno */
319 return strlen(buf
)+1;
322 #ifdef TARGET_NR_openat
323 static int sys_openat(int dirfd
, const char *pathname
, int flags
, mode_t mode
)
326 * open(2) has extra parameter 'mode' when called with
329 if ((flags
& O_CREAT
) != 0) {
330 return (openat(dirfd
, pathname
, flags
, mode
));
332 return (openat(dirfd
, pathname
, flags
));
336 #ifdef TARGET_NR_utimensat
337 #ifdef CONFIG_UTIMENSAT
338 static int sys_utimensat(int dirfd
, const char *pathname
,
339 const struct timespec times
[2], int flags
)
341 if (pathname
== NULL
)
342 return futimens(dirfd
, times
);
344 return utimensat(dirfd
, pathname
, times
, flags
);
346 #elif defined(__NR_utimensat)
347 #define __NR_sys_utimensat __NR_utimensat
348 _syscall4(int,sys_utimensat
,int,dirfd
,const char *,pathname
,
349 const struct timespec
*,tsp
,int,flags
)
351 static int sys_utimensat(int dirfd
, const char *pathname
,
352 const struct timespec times
[2], int flags
)
358 #endif /* TARGET_NR_utimensat */
360 #ifdef CONFIG_INOTIFY
361 #include <sys/inotify.h>
363 #if defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init)
364 static int sys_inotify_init(void)
366 return (inotify_init());
369 #if defined(TARGET_NR_inotify_add_watch) && defined(__NR_inotify_add_watch)
370 static int sys_inotify_add_watch(int fd
,const char *pathname
, int32_t mask
)
372 return (inotify_add_watch(fd
, pathname
, mask
));
375 #if defined(TARGET_NR_inotify_rm_watch) && defined(__NR_inotify_rm_watch)
376 static int sys_inotify_rm_watch(int fd
, int32_t wd
)
378 return (inotify_rm_watch(fd
, wd
));
381 #ifdef CONFIG_INOTIFY1
382 #if defined(TARGET_NR_inotify_init1) && defined(__NR_inotify_init1)
383 static int sys_inotify_init1(int flags
)
385 return (inotify_init1(flags
));
390 /* Userspace can usually survive runtime without inotify */
391 #undef TARGET_NR_inotify_init
392 #undef TARGET_NR_inotify_init1
393 #undef TARGET_NR_inotify_add_watch
394 #undef TARGET_NR_inotify_rm_watch
395 #endif /* CONFIG_INOTIFY */
397 #if defined(TARGET_NR_ppoll)
399 # define __NR_ppoll -1
401 #define __NR_sys_ppoll __NR_ppoll
402 _syscall5(int, sys_ppoll
, struct pollfd
*, fds
, nfds_t
, nfds
,
403 struct timespec
*, timeout
, const __sigset_t
*, sigmask
,
407 #if defined(TARGET_NR_pselect6)
408 #ifndef __NR_pselect6
409 # define __NR_pselect6 -1
411 #define __NR_sys_pselect6 __NR_pselect6
412 _syscall6(int, sys_pselect6
, int, nfds
, fd_set
*, readfds
, fd_set
*, writefds
,
413 fd_set
*, exceptfds
, struct timespec
*, timeout
, void *, sig
);
416 #if defined(TARGET_NR_prlimit64)
417 #ifndef __NR_prlimit64
418 # define __NR_prlimit64 -1
420 #define __NR_sys_prlimit64 __NR_prlimit64
421 /* The glibc rlimit structure may not be that used by the underlying syscall */
422 struct host_rlimit64
{
426 _syscall4(int, sys_prlimit64
, pid_t
, pid
, int, resource
,
427 const struct host_rlimit64
*, new_limit
,
428 struct host_rlimit64
*, old_limit
)
432 #if defined(TARGET_NR_timer_create)
433 /* Maxiumum of 32 active POSIX timers allowed at any one time. */
434 static timer_t g_posix_timers
[32] = { 0, } ;
436 static inline int next_free_host_timer(void)
439 /* FIXME: Does finding the next free slot require a lock? */
440 for (k
= 0; k
< ARRAY_SIZE(g_posix_timers
); k
++) {
441 if (g_posix_timers
[k
] == 0) {
442 g_posix_timers
[k
] = (timer_t
) 1;
450 /* ARM EABI and MIPS expect 64bit types aligned even on pairs or registers */
452 static inline int regpairs_aligned(void *cpu_env
) {
453 return ((((CPUARMState
*)cpu_env
)->eabi
) == 1) ;
455 #elif defined(TARGET_MIPS)
456 static inline int regpairs_aligned(void *cpu_env
) { return 1; }
457 #elif defined(TARGET_PPC) && !defined(TARGET_PPC64)
458 /* SysV AVI for PPC32 expects 64bit parameters to be passed on odd/even pairs
459 * of registers which translates to the same as ARM/MIPS, because we start with
461 static inline int regpairs_aligned(void *cpu_env
) { return 1; }
463 static inline int regpairs_aligned(void *cpu_env
) { return 0; }
466 #define ERRNO_TABLE_SIZE 1200
468 /* target_to_host_errno_table[] is initialized from
469 * host_to_target_errno_table[] in syscall_init(). */
470 static uint16_t target_to_host_errno_table
[ERRNO_TABLE_SIZE
] = {
474 * This list is the union of errno values overridden in asm-<arch>/errno.h
475 * minus the errnos that are not actually generic to all archs.
477 static uint16_t host_to_target_errno_table
[ERRNO_TABLE_SIZE
] = {
478 [EIDRM
] = TARGET_EIDRM
,
479 [ECHRNG
] = TARGET_ECHRNG
,
480 [EL2NSYNC
] = TARGET_EL2NSYNC
,
481 [EL3HLT
] = TARGET_EL3HLT
,
482 [EL3RST
] = TARGET_EL3RST
,
483 [ELNRNG
] = TARGET_ELNRNG
,
484 [EUNATCH
] = TARGET_EUNATCH
,
485 [ENOCSI
] = TARGET_ENOCSI
,
486 [EL2HLT
] = TARGET_EL2HLT
,
487 [EDEADLK
] = TARGET_EDEADLK
,
488 [ENOLCK
] = TARGET_ENOLCK
,
489 [EBADE
] = TARGET_EBADE
,
490 [EBADR
] = TARGET_EBADR
,
491 [EXFULL
] = TARGET_EXFULL
,
492 [ENOANO
] = TARGET_ENOANO
,
493 [EBADRQC
] = TARGET_EBADRQC
,
494 [EBADSLT
] = TARGET_EBADSLT
,
495 [EBFONT
] = TARGET_EBFONT
,
496 [ENOSTR
] = TARGET_ENOSTR
,
497 [ENODATA
] = TARGET_ENODATA
,
498 [ETIME
] = TARGET_ETIME
,
499 [ENOSR
] = TARGET_ENOSR
,
500 [ENONET
] = TARGET_ENONET
,
501 [ENOPKG
] = TARGET_ENOPKG
,
502 [EREMOTE
] = TARGET_EREMOTE
,
503 [ENOLINK
] = TARGET_ENOLINK
,
504 [EADV
] = TARGET_EADV
,
505 [ESRMNT
] = TARGET_ESRMNT
,
506 [ECOMM
] = TARGET_ECOMM
,
507 [EPROTO
] = TARGET_EPROTO
,
508 [EDOTDOT
] = TARGET_EDOTDOT
,
509 [EMULTIHOP
] = TARGET_EMULTIHOP
,
510 [EBADMSG
] = TARGET_EBADMSG
,
511 [ENAMETOOLONG
] = TARGET_ENAMETOOLONG
,
512 [EOVERFLOW
] = TARGET_EOVERFLOW
,
513 [ENOTUNIQ
] = TARGET_ENOTUNIQ
,
514 [EBADFD
] = TARGET_EBADFD
,
515 [EREMCHG
] = TARGET_EREMCHG
,
516 [ELIBACC
] = TARGET_ELIBACC
,
517 [ELIBBAD
] = TARGET_ELIBBAD
,
518 [ELIBSCN
] = TARGET_ELIBSCN
,
519 [ELIBMAX
] = TARGET_ELIBMAX
,
520 [ELIBEXEC
] = TARGET_ELIBEXEC
,
521 [EILSEQ
] = TARGET_EILSEQ
,
522 [ENOSYS
] = TARGET_ENOSYS
,
523 [ELOOP
] = TARGET_ELOOP
,
524 [ERESTART
] = TARGET_ERESTART
,
525 [ESTRPIPE
] = TARGET_ESTRPIPE
,
526 [ENOTEMPTY
] = TARGET_ENOTEMPTY
,
527 [EUSERS
] = TARGET_EUSERS
,
528 [ENOTSOCK
] = TARGET_ENOTSOCK
,
529 [EDESTADDRREQ
] = TARGET_EDESTADDRREQ
,
530 [EMSGSIZE
] = TARGET_EMSGSIZE
,
531 [EPROTOTYPE
] = TARGET_EPROTOTYPE
,
532 [ENOPROTOOPT
] = TARGET_ENOPROTOOPT
,
533 [EPROTONOSUPPORT
] = TARGET_EPROTONOSUPPORT
,
534 [ESOCKTNOSUPPORT
] = TARGET_ESOCKTNOSUPPORT
,
535 [EOPNOTSUPP
] = TARGET_EOPNOTSUPP
,
536 [EPFNOSUPPORT
] = TARGET_EPFNOSUPPORT
,
537 [EAFNOSUPPORT
] = TARGET_EAFNOSUPPORT
,
538 [EADDRINUSE
] = TARGET_EADDRINUSE
,
539 [EADDRNOTAVAIL
] = TARGET_EADDRNOTAVAIL
,
540 [ENETDOWN
] = TARGET_ENETDOWN
,
541 [ENETUNREACH
] = TARGET_ENETUNREACH
,
542 [ENETRESET
] = TARGET_ENETRESET
,
543 [ECONNABORTED
] = TARGET_ECONNABORTED
,
544 [ECONNRESET
] = TARGET_ECONNRESET
,
545 [ENOBUFS
] = TARGET_ENOBUFS
,
546 [EISCONN
] = TARGET_EISCONN
,
547 [ENOTCONN
] = TARGET_ENOTCONN
,
548 [EUCLEAN
] = TARGET_EUCLEAN
,
549 [ENOTNAM
] = TARGET_ENOTNAM
,
550 [ENAVAIL
] = TARGET_ENAVAIL
,
551 [EISNAM
] = TARGET_EISNAM
,
552 [EREMOTEIO
] = TARGET_EREMOTEIO
,
553 [ESHUTDOWN
] = TARGET_ESHUTDOWN
,
554 [ETOOMANYREFS
] = TARGET_ETOOMANYREFS
,
555 [ETIMEDOUT
] = TARGET_ETIMEDOUT
,
556 [ECONNREFUSED
] = TARGET_ECONNREFUSED
,
557 [EHOSTDOWN
] = TARGET_EHOSTDOWN
,
558 [EHOSTUNREACH
] = TARGET_EHOSTUNREACH
,
559 [EALREADY
] = TARGET_EALREADY
,
560 [EINPROGRESS
] = TARGET_EINPROGRESS
,
561 [ESTALE
] = TARGET_ESTALE
,
562 [ECANCELED
] = TARGET_ECANCELED
,
563 [ENOMEDIUM
] = TARGET_ENOMEDIUM
,
564 [EMEDIUMTYPE
] = TARGET_EMEDIUMTYPE
,
566 [ENOKEY
] = TARGET_ENOKEY
,
569 [EKEYEXPIRED
] = TARGET_EKEYEXPIRED
,
572 [EKEYREVOKED
] = TARGET_EKEYREVOKED
,
575 [EKEYREJECTED
] = TARGET_EKEYREJECTED
,
578 [EOWNERDEAD
] = TARGET_EOWNERDEAD
,
580 #ifdef ENOTRECOVERABLE
581 [ENOTRECOVERABLE
] = TARGET_ENOTRECOVERABLE
,
585 static inline int host_to_target_errno(int err
)
587 if(host_to_target_errno_table
[err
])
588 return host_to_target_errno_table
[err
];
592 static inline int target_to_host_errno(int err
)
594 if (target_to_host_errno_table
[err
])
595 return target_to_host_errno_table
[err
];
599 static inline abi_long
get_errno(abi_long ret
)
602 return -host_to_target_errno(errno
);
607 static inline int is_error(abi_long ret
)
609 return (abi_ulong
)ret
>= (abi_ulong
)(-4096);
612 char *target_strerror(int err
)
614 if ((err
>= ERRNO_TABLE_SIZE
) || (err
< 0)) {
617 return strerror(target_to_host_errno(err
));
620 static abi_ulong target_brk
;
621 static abi_ulong target_original_brk
;
622 static abi_ulong brk_page
;
624 void target_set_brk(abi_ulong new_brk
)
626 target_original_brk
= target_brk
= HOST_PAGE_ALIGN(new_brk
);
627 brk_page
= HOST_PAGE_ALIGN(target_brk
);
630 //#define DEBUGF_BRK(message, args...) do { fprintf(stderr, (message), ## args); } while (0)
631 #define DEBUGF_BRK(message, args...)
633 /* do_brk() must return target values and target errnos. */
634 abi_long
do_brk(abi_ulong new_brk
)
636 abi_long mapped_addr
;
639 DEBUGF_BRK("do_brk(" TARGET_ABI_FMT_lx
") -> ", new_brk
);
642 DEBUGF_BRK(TARGET_ABI_FMT_lx
" (!new_brk)\n", target_brk
);
645 if (new_brk
< target_original_brk
) {
646 DEBUGF_BRK(TARGET_ABI_FMT_lx
" (new_brk < target_original_brk)\n",
651 /* If the new brk is less than the highest page reserved to the
652 * target heap allocation, set it and we're almost done... */
653 if (new_brk
<= brk_page
) {
654 /* Heap contents are initialized to zero, as for anonymous
656 if (new_brk
> target_brk
) {
657 memset(g2h(target_brk
), 0, new_brk
- target_brk
);
659 target_brk
= new_brk
;
660 DEBUGF_BRK(TARGET_ABI_FMT_lx
" (new_brk <= brk_page)\n", target_brk
);
664 /* We need to allocate more memory after the brk... Note that
665 * we don't use MAP_FIXED because that will map over the top of
666 * any existing mapping (like the one with the host libc or qemu
667 * itself); instead we treat "mapped but at wrong address" as
668 * a failure and unmap again.
670 new_alloc_size
= HOST_PAGE_ALIGN(new_brk
- brk_page
);
671 mapped_addr
= get_errno(target_mmap(brk_page
, new_alloc_size
,
672 PROT_READ
|PROT_WRITE
,
673 MAP_ANON
|MAP_PRIVATE
, 0, 0));
675 if (mapped_addr
== brk_page
) {
676 /* Heap contents are initialized to zero, as for anonymous
677 * mapped pages. Technically the new pages are already
678 * initialized to zero since they *are* anonymous mapped
679 * pages, however we have to take care with the contents that
680 * come from the remaining part of the previous page: it may
681 * contains garbage data due to a previous heap usage (grown
683 memset(g2h(target_brk
), 0, brk_page
- target_brk
);
685 target_brk
= new_brk
;
686 brk_page
= HOST_PAGE_ALIGN(target_brk
);
687 DEBUGF_BRK(TARGET_ABI_FMT_lx
" (mapped_addr == brk_page)\n",
690 } else if (mapped_addr
!= -1) {
691 /* Mapped but at wrong address, meaning there wasn't actually
692 * enough space for this brk.
694 target_munmap(mapped_addr
, new_alloc_size
);
696 DEBUGF_BRK(TARGET_ABI_FMT_lx
" (mapped_addr != -1)\n", target_brk
);
699 DEBUGF_BRK(TARGET_ABI_FMT_lx
" (otherwise)\n", target_brk
);
702 #if defined(TARGET_ALPHA)
703 /* We (partially) emulate OSF/1 on Alpha, which requires we
704 return a proper errno, not an unchanged brk value. */
705 return -TARGET_ENOMEM
;
707 /* For everything else, return the previous break. */
711 static inline abi_long
copy_from_user_fdset(fd_set
*fds
,
712 abi_ulong target_fds_addr
,
716 abi_ulong b
, *target_fds
;
718 nw
= (n
+ TARGET_ABI_BITS
- 1) / TARGET_ABI_BITS
;
719 if (!(target_fds
= lock_user(VERIFY_READ
,
721 sizeof(abi_ulong
) * nw
,
723 return -TARGET_EFAULT
;
727 for (i
= 0; i
< nw
; i
++) {
728 /* grab the abi_ulong */
729 __get_user(b
, &target_fds
[i
]);
730 for (j
= 0; j
< TARGET_ABI_BITS
; j
++) {
731 /* check the bit inside the abi_ulong */
738 unlock_user(target_fds
, target_fds_addr
, 0);
743 static inline abi_ulong
copy_from_user_fdset_ptr(fd_set
*fds
, fd_set
**fds_ptr
,
744 abi_ulong target_fds_addr
,
747 if (target_fds_addr
) {
748 if (copy_from_user_fdset(fds
, target_fds_addr
, n
))
749 return -TARGET_EFAULT
;
757 static inline abi_long
copy_to_user_fdset(abi_ulong target_fds_addr
,
763 abi_ulong
*target_fds
;
765 nw
= (n
+ TARGET_ABI_BITS
- 1) / TARGET_ABI_BITS
;
766 if (!(target_fds
= lock_user(VERIFY_WRITE
,
768 sizeof(abi_ulong
) * nw
,
770 return -TARGET_EFAULT
;
773 for (i
= 0; i
< nw
; i
++) {
775 for (j
= 0; j
< TARGET_ABI_BITS
; j
++) {
776 v
|= ((abi_ulong
)(FD_ISSET(k
, fds
) != 0) << j
);
779 __put_user(v
, &target_fds
[i
]);
782 unlock_user(target_fds
, target_fds_addr
, sizeof(abi_ulong
) * nw
);
787 #if defined(__alpha__)
793 static inline abi_long
host_to_target_clock_t(long ticks
)
795 #if HOST_HZ == TARGET_HZ
798 return ((int64_t)ticks
* TARGET_HZ
) / HOST_HZ
;
802 static inline abi_long
host_to_target_rusage(abi_ulong target_addr
,
803 const struct rusage
*rusage
)
805 struct target_rusage
*target_rusage
;
807 if (!lock_user_struct(VERIFY_WRITE
, target_rusage
, target_addr
, 0))
808 return -TARGET_EFAULT
;
809 target_rusage
->ru_utime
.tv_sec
= tswapal(rusage
->ru_utime
.tv_sec
);
810 target_rusage
->ru_utime
.tv_usec
= tswapal(rusage
->ru_utime
.tv_usec
);
811 target_rusage
->ru_stime
.tv_sec
= tswapal(rusage
->ru_stime
.tv_sec
);
812 target_rusage
->ru_stime
.tv_usec
= tswapal(rusage
->ru_stime
.tv_usec
);
813 target_rusage
->ru_maxrss
= tswapal(rusage
->ru_maxrss
);
814 target_rusage
->ru_ixrss
= tswapal(rusage
->ru_ixrss
);
815 target_rusage
->ru_idrss
= tswapal(rusage
->ru_idrss
);
816 target_rusage
->ru_isrss
= tswapal(rusage
->ru_isrss
);
817 target_rusage
->ru_minflt
= tswapal(rusage
->ru_minflt
);
818 target_rusage
->ru_majflt
= tswapal(rusage
->ru_majflt
);
819 target_rusage
->ru_nswap
= tswapal(rusage
->ru_nswap
);
820 target_rusage
->ru_inblock
= tswapal(rusage
->ru_inblock
);
821 target_rusage
->ru_oublock
= tswapal(rusage
->ru_oublock
);
822 target_rusage
->ru_msgsnd
= tswapal(rusage
->ru_msgsnd
);
823 target_rusage
->ru_msgrcv
= tswapal(rusage
->ru_msgrcv
);
824 target_rusage
->ru_nsignals
= tswapal(rusage
->ru_nsignals
);
825 target_rusage
->ru_nvcsw
= tswapal(rusage
->ru_nvcsw
);
826 target_rusage
->ru_nivcsw
= tswapal(rusage
->ru_nivcsw
);
827 unlock_user_struct(target_rusage
, target_addr
, 1);
832 static inline rlim_t
target_to_host_rlim(abi_ulong target_rlim
)
834 abi_ulong target_rlim_swap
;
837 target_rlim_swap
= tswapal(target_rlim
);
838 if (target_rlim_swap
== TARGET_RLIM_INFINITY
)
839 return RLIM_INFINITY
;
841 result
= target_rlim_swap
;
842 if (target_rlim_swap
!= (rlim_t
)result
)
843 return RLIM_INFINITY
;
848 static inline abi_ulong
host_to_target_rlim(rlim_t rlim
)
850 abi_ulong target_rlim_swap
;
853 if (rlim
== RLIM_INFINITY
|| rlim
!= (abi_long
)rlim
)
854 target_rlim_swap
= TARGET_RLIM_INFINITY
;
856 target_rlim_swap
= rlim
;
857 result
= tswapal(target_rlim_swap
);
862 static inline int target_to_host_resource(int code
)
865 case TARGET_RLIMIT_AS
:
867 case TARGET_RLIMIT_CORE
:
869 case TARGET_RLIMIT_CPU
:
871 case TARGET_RLIMIT_DATA
:
873 case TARGET_RLIMIT_FSIZE
:
875 case TARGET_RLIMIT_LOCKS
:
877 case TARGET_RLIMIT_MEMLOCK
:
878 return RLIMIT_MEMLOCK
;
879 case TARGET_RLIMIT_MSGQUEUE
:
880 return RLIMIT_MSGQUEUE
;
881 case TARGET_RLIMIT_NICE
:
883 case TARGET_RLIMIT_NOFILE
:
884 return RLIMIT_NOFILE
;
885 case TARGET_RLIMIT_NPROC
:
887 case TARGET_RLIMIT_RSS
:
889 case TARGET_RLIMIT_RTPRIO
:
890 return RLIMIT_RTPRIO
;
891 case TARGET_RLIMIT_SIGPENDING
:
892 return RLIMIT_SIGPENDING
;
893 case TARGET_RLIMIT_STACK
:
900 static inline abi_long
copy_from_user_timeval(struct timeval
*tv
,
901 abi_ulong target_tv_addr
)
903 struct target_timeval
*target_tv
;
905 if (!lock_user_struct(VERIFY_READ
, target_tv
, target_tv_addr
, 1))
906 return -TARGET_EFAULT
;
908 __get_user(tv
->tv_sec
, &target_tv
->tv_sec
);
909 __get_user(tv
->tv_usec
, &target_tv
->tv_usec
);
911 unlock_user_struct(target_tv
, target_tv_addr
, 0);
916 static inline abi_long
copy_to_user_timeval(abi_ulong target_tv_addr
,
917 const struct timeval
*tv
)
919 struct target_timeval
*target_tv
;
921 if (!lock_user_struct(VERIFY_WRITE
, target_tv
, target_tv_addr
, 0))
922 return -TARGET_EFAULT
;
924 __put_user(tv
->tv_sec
, &target_tv
->tv_sec
);
925 __put_user(tv
->tv_usec
, &target_tv
->tv_usec
);
927 unlock_user_struct(target_tv
, target_tv_addr
, 1);
932 #if defined(TARGET_NR_mq_open) && defined(__NR_mq_open)
935 static inline abi_long
copy_from_user_mq_attr(struct mq_attr
*attr
,
936 abi_ulong target_mq_attr_addr
)
938 struct target_mq_attr
*target_mq_attr
;
940 if (!lock_user_struct(VERIFY_READ
, target_mq_attr
,
941 target_mq_attr_addr
, 1))
942 return -TARGET_EFAULT
;
944 __get_user(attr
->mq_flags
, &target_mq_attr
->mq_flags
);
945 __get_user(attr
->mq_maxmsg
, &target_mq_attr
->mq_maxmsg
);
946 __get_user(attr
->mq_msgsize
, &target_mq_attr
->mq_msgsize
);
947 __get_user(attr
->mq_curmsgs
, &target_mq_attr
->mq_curmsgs
);
949 unlock_user_struct(target_mq_attr
, target_mq_attr_addr
, 0);
954 static inline abi_long
copy_to_user_mq_attr(abi_ulong target_mq_attr_addr
,
955 const struct mq_attr
*attr
)
957 struct target_mq_attr
*target_mq_attr
;
959 if (!lock_user_struct(VERIFY_WRITE
, target_mq_attr
,
960 target_mq_attr_addr
, 0))
961 return -TARGET_EFAULT
;
963 __put_user(attr
->mq_flags
, &target_mq_attr
->mq_flags
);
964 __put_user(attr
->mq_maxmsg
, &target_mq_attr
->mq_maxmsg
);
965 __put_user(attr
->mq_msgsize
, &target_mq_attr
->mq_msgsize
);
966 __put_user(attr
->mq_curmsgs
, &target_mq_attr
->mq_curmsgs
);
968 unlock_user_struct(target_mq_attr
, target_mq_attr_addr
, 1);
974 #if defined(TARGET_NR_select) || defined(TARGET_NR__newselect)
975 /* do_select() must return target values and target errnos. */
976 static abi_long
do_select(int n
,
977 abi_ulong rfd_addr
, abi_ulong wfd_addr
,
978 abi_ulong efd_addr
, abi_ulong target_tv_addr
)
980 fd_set rfds
, wfds
, efds
;
981 fd_set
*rfds_ptr
, *wfds_ptr
, *efds_ptr
;
982 struct timeval tv
, *tv_ptr
;
985 ret
= copy_from_user_fdset_ptr(&rfds
, &rfds_ptr
, rfd_addr
, n
);
989 ret
= copy_from_user_fdset_ptr(&wfds
, &wfds_ptr
, wfd_addr
, n
);
993 ret
= copy_from_user_fdset_ptr(&efds
, &efds_ptr
, efd_addr
, n
);
998 if (target_tv_addr
) {
999 if (copy_from_user_timeval(&tv
, target_tv_addr
))
1000 return -TARGET_EFAULT
;
1006 ret
= get_errno(select(n
, rfds_ptr
, wfds_ptr
, efds_ptr
, tv_ptr
));
1008 if (!is_error(ret
)) {
1009 if (rfd_addr
&& copy_to_user_fdset(rfd_addr
, &rfds
, n
))
1010 return -TARGET_EFAULT
;
1011 if (wfd_addr
&& copy_to_user_fdset(wfd_addr
, &wfds
, n
))
1012 return -TARGET_EFAULT
;
1013 if (efd_addr
&& copy_to_user_fdset(efd_addr
, &efds
, n
))
1014 return -TARGET_EFAULT
;
1016 if (target_tv_addr
&& copy_to_user_timeval(target_tv_addr
, &tv
))
1017 return -TARGET_EFAULT
;
1024 static abi_long
do_pipe2(int host_pipe
[], int flags
)
1027 return pipe2(host_pipe
, flags
);
1033 static abi_long
do_pipe(void *cpu_env
, abi_ulong pipedes
,
1034 int flags
, int is_pipe2
)
1038 ret
= flags
? do_pipe2(host_pipe
, flags
) : pipe(host_pipe
);
1041 return get_errno(ret
);
1043 /* Several targets have special calling conventions for the original
1044 pipe syscall, but didn't replicate this into the pipe2 syscall. */
1046 #if defined(TARGET_ALPHA)
1047 ((CPUAlphaState
*)cpu_env
)->ir
[IR_A4
] = host_pipe
[1];
1048 return host_pipe
[0];
1049 #elif defined(TARGET_MIPS)
1050 ((CPUMIPSState
*)cpu_env
)->active_tc
.gpr
[3] = host_pipe
[1];
1051 return host_pipe
[0];
1052 #elif defined(TARGET_SH4)
1053 ((CPUSH4State
*)cpu_env
)->gregs
[1] = host_pipe
[1];
1054 return host_pipe
[0];
1055 #elif defined(TARGET_SPARC)
1056 ((CPUSPARCState
*)cpu_env
)->regwptr
[1] = host_pipe
[1];
1057 return host_pipe
[0];
1061 if (put_user_s32(host_pipe
[0], pipedes
)
1062 || put_user_s32(host_pipe
[1], pipedes
+ sizeof(host_pipe
[0])))
1063 return -TARGET_EFAULT
;
1064 return get_errno(ret
);
1067 static inline abi_long
target_to_host_ip_mreq(struct ip_mreqn
*mreqn
,
1068 abi_ulong target_addr
,
1071 struct target_ip_mreqn
*target_smreqn
;
1073 target_smreqn
= lock_user(VERIFY_READ
, target_addr
, len
, 1);
1075 return -TARGET_EFAULT
;
1076 mreqn
->imr_multiaddr
.s_addr
= target_smreqn
->imr_multiaddr
.s_addr
;
1077 mreqn
->imr_address
.s_addr
= target_smreqn
->imr_address
.s_addr
;
1078 if (len
== sizeof(struct target_ip_mreqn
))
1079 mreqn
->imr_ifindex
= tswapal(target_smreqn
->imr_ifindex
);
1080 unlock_user(target_smreqn
, target_addr
, 0);
1085 static inline abi_long
target_to_host_sockaddr(struct sockaddr
*addr
,
1086 abi_ulong target_addr
,
1089 const socklen_t unix_maxlen
= sizeof (struct sockaddr_un
);
1090 sa_family_t sa_family
;
1091 struct target_sockaddr
*target_saddr
;
1093 target_saddr
= lock_user(VERIFY_READ
, target_addr
, len
, 1);
1095 return -TARGET_EFAULT
;
1097 sa_family
= tswap16(target_saddr
->sa_family
);
1099 /* Oops. The caller might send a incomplete sun_path; sun_path
1100 * must be terminated by \0 (see the manual page), but
1101 * unfortunately it is quite common to specify sockaddr_un
1102 * length as "strlen(x->sun_path)" while it should be
1103 * "strlen(...) + 1". We'll fix that here if needed.
1104 * Linux kernel has a similar feature.
1107 if (sa_family
== AF_UNIX
) {
1108 if (len
< unix_maxlen
&& len
> 0) {
1109 char *cp
= (char*)target_saddr
;
1111 if ( cp
[len
-1] && !cp
[len
] )
1114 if (len
> unix_maxlen
)
1118 memcpy(addr
, target_saddr
, len
);
1119 addr
->sa_family
= sa_family
;
1120 unlock_user(target_saddr
, target_addr
, 0);
1125 static inline abi_long
host_to_target_sockaddr(abi_ulong target_addr
,
1126 struct sockaddr
*addr
,
1129 struct target_sockaddr
*target_saddr
;
1131 target_saddr
= lock_user(VERIFY_WRITE
, target_addr
, len
, 0);
1133 return -TARGET_EFAULT
;
1134 memcpy(target_saddr
, addr
, len
);
1135 target_saddr
->sa_family
= tswap16(addr
->sa_family
);
1136 unlock_user(target_saddr
, target_addr
, len
);
1141 static inline abi_long
target_to_host_cmsg(struct msghdr
*msgh
,
1142 struct target_msghdr
*target_msgh
)
1144 struct cmsghdr
*cmsg
= CMSG_FIRSTHDR(msgh
);
1145 abi_long msg_controllen
;
1146 abi_ulong target_cmsg_addr
;
1147 struct target_cmsghdr
*target_cmsg
;
1148 socklen_t space
= 0;
1150 msg_controllen
= tswapal(target_msgh
->msg_controllen
);
1151 if (msg_controllen
< sizeof (struct target_cmsghdr
))
1153 target_cmsg_addr
= tswapal(target_msgh
->msg_control
);
1154 target_cmsg
= lock_user(VERIFY_READ
, target_cmsg_addr
, msg_controllen
, 1);
1156 return -TARGET_EFAULT
;
1158 while (cmsg
&& target_cmsg
) {
1159 void *data
= CMSG_DATA(cmsg
);
1160 void *target_data
= TARGET_CMSG_DATA(target_cmsg
);
1162 int len
= tswapal(target_cmsg
->cmsg_len
)
1163 - TARGET_CMSG_ALIGN(sizeof (struct target_cmsghdr
));
1165 space
+= CMSG_SPACE(len
);
1166 if (space
> msgh
->msg_controllen
) {
1167 space
-= CMSG_SPACE(len
);
1168 gemu_log("Host cmsg overflow\n");
1172 if (tswap32(target_cmsg
->cmsg_level
) == TARGET_SOL_SOCKET
) {
1173 cmsg
->cmsg_level
= SOL_SOCKET
;
1175 cmsg
->cmsg_level
= tswap32(target_cmsg
->cmsg_level
);
1177 cmsg
->cmsg_type
= tswap32(target_cmsg
->cmsg_type
);
1178 cmsg
->cmsg_len
= CMSG_LEN(len
);
1180 if (cmsg
->cmsg_level
!= SOL_SOCKET
|| cmsg
->cmsg_type
!= SCM_RIGHTS
) {
1181 gemu_log("Unsupported ancillary data: %d/%d\n", cmsg
->cmsg_level
, cmsg
->cmsg_type
);
1182 memcpy(data
, target_data
, len
);
1184 int *fd
= (int *)data
;
1185 int *target_fd
= (int *)target_data
;
1186 int i
, numfds
= len
/ sizeof(int);
1188 for (i
= 0; i
< numfds
; i
++)
1189 fd
[i
] = tswap32(target_fd
[i
]);
1192 cmsg
= CMSG_NXTHDR(msgh
, cmsg
);
1193 target_cmsg
= TARGET_CMSG_NXTHDR(target_msgh
, target_cmsg
);
1195 unlock_user(target_cmsg
, target_cmsg_addr
, 0);
1197 msgh
->msg_controllen
= space
;
1201 static inline abi_long
host_to_target_cmsg(struct target_msghdr
*target_msgh
,
1202 struct msghdr
*msgh
)
1204 struct cmsghdr
*cmsg
= CMSG_FIRSTHDR(msgh
);
1205 abi_long msg_controllen
;
1206 abi_ulong target_cmsg_addr
;
1207 struct target_cmsghdr
*target_cmsg
;
1208 socklen_t space
= 0;
1210 msg_controllen
= tswapal(target_msgh
->msg_controllen
);
1211 if (msg_controllen
< sizeof (struct target_cmsghdr
))
1213 target_cmsg_addr
= tswapal(target_msgh
->msg_control
);
1214 target_cmsg
= lock_user(VERIFY_WRITE
, target_cmsg_addr
, msg_controllen
, 0);
1216 return -TARGET_EFAULT
;
1218 while (cmsg
&& target_cmsg
) {
1219 void *data
= CMSG_DATA(cmsg
);
1220 void *target_data
= TARGET_CMSG_DATA(target_cmsg
);
1222 int len
= cmsg
->cmsg_len
- CMSG_ALIGN(sizeof (struct cmsghdr
));
1224 space
+= TARGET_CMSG_SPACE(len
);
1225 if (space
> msg_controllen
) {
1226 space
-= TARGET_CMSG_SPACE(len
);
1227 gemu_log("Target cmsg overflow\n");
1231 if (cmsg
->cmsg_level
== SOL_SOCKET
) {
1232 target_cmsg
->cmsg_level
= tswap32(TARGET_SOL_SOCKET
);
1234 target_cmsg
->cmsg_level
= tswap32(cmsg
->cmsg_level
);
1236 target_cmsg
->cmsg_type
= tswap32(cmsg
->cmsg_type
);
1237 target_cmsg
->cmsg_len
= tswapal(TARGET_CMSG_LEN(len
));
1239 if ((cmsg
->cmsg_level
== SOL_SOCKET
) &&
1240 (cmsg
->cmsg_type
== SCM_RIGHTS
)) {
1241 int *fd
= (int *)data
;
1242 int *target_fd
= (int *)target_data
;
1243 int i
, numfds
= len
/ sizeof(int);
1245 for (i
= 0; i
< numfds
; i
++)
1246 target_fd
[i
] = tswap32(fd
[i
]);
1247 } else if ((cmsg
->cmsg_level
== SOL_SOCKET
) &&
1248 (cmsg
->cmsg_type
== SO_TIMESTAMP
) &&
1249 (len
== sizeof(struct timeval
))) {
1250 /* copy struct timeval to target */
1251 struct timeval
*tv
= (struct timeval
*)data
;
1252 struct target_timeval
*target_tv
=
1253 (struct target_timeval
*)target_data
;
1255 target_tv
->tv_sec
= tswapal(tv
->tv_sec
);
1256 target_tv
->tv_usec
= tswapal(tv
->tv_usec
);
1258 gemu_log("Unsupported ancillary data: %d/%d\n",
1259 cmsg
->cmsg_level
, cmsg
->cmsg_type
);
1260 memcpy(target_data
, data
, len
);
1263 cmsg
= CMSG_NXTHDR(msgh
, cmsg
);
1264 target_cmsg
= TARGET_CMSG_NXTHDR(target_msgh
, target_cmsg
);
1266 unlock_user(target_cmsg
, target_cmsg_addr
, space
);
1268 target_msgh
->msg_controllen
= tswapal(space
);
1272 /* do_setsockopt() Must return target values and target errnos. */
1273 static abi_long
do_setsockopt(int sockfd
, int level
, int optname
,
1274 abi_ulong optval_addr
, socklen_t optlen
)
1278 struct ip_mreqn
*ip_mreq
;
1279 struct ip_mreq_source
*ip_mreq_source
;
1283 /* TCP options all take an 'int' value. */
1284 if (optlen
< sizeof(uint32_t))
1285 return -TARGET_EINVAL
;
1287 if (get_user_u32(val
, optval_addr
))
1288 return -TARGET_EFAULT
;
1289 ret
= get_errno(setsockopt(sockfd
, level
, optname
, &val
, sizeof(val
)));
1296 case IP_ROUTER_ALERT
:
1300 case IP_MTU_DISCOVER
:
1306 case IP_MULTICAST_TTL
:
1307 case IP_MULTICAST_LOOP
:
1309 if (optlen
>= sizeof(uint32_t)) {
1310 if (get_user_u32(val
, optval_addr
))
1311 return -TARGET_EFAULT
;
1312 } else if (optlen
>= 1) {
1313 if (get_user_u8(val
, optval_addr
))
1314 return -TARGET_EFAULT
;
1316 ret
= get_errno(setsockopt(sockfd
, level
, optname
, &val
, sizeof(val
)));
1318 case IP_ADD_MEMBERSHIP
:
1319 case IP_DROP_MEMBERSHIP
:
1320 if (optlen
< sizeof (struct target_ip_mreq
) ||
1321 optlen
> sizeof (struct target_ip_mreqn
))
1322 return -TARGET_EINVAL
;
1324 ip_mreq
= (struct ip_mreqn
*) alloca(optlen
);
1325 target_to_host_ip_mreq(ip_mreq
, optval_addr
, optlen
);
1326 ret
= get_errno(setsockopt(sockfd
, level
, optname
, ip_mreq
, optlen
));
1329 case IP_BLOCK_SOURCE
:
1330 case IP_UNBLOCK_SOURCE
:
1331 case IP_ADD_SOURCE_MEMBERSHIP
:
1332 case IP_DROP_SOURCE_MEMBERSHIP
:
1333 if (optlen
!= sizeof (struct target_ip_mreq_source
))
1334 return -TARGET_EINVAL
;
1336 ip_mreq_source
= lock_user(VERIFY_READ
, optval_addr
, optlen
, 1);
1337 ret
= get_errno(setsockopt(sockfd
, level
, optname
, ip_mreq_source
, optlen
));
1338 unlock_user (ip_mreq_source
, optval_addr
, 0);
1347 case IPV6_MTU_DISCOVER
:
1350 case IPV6_RECVPKTINFO
:
1352 if (optlen
< sizeof(uint32_t)) {
1353 return -TARGET_EINVAL
;
1355 if (get_user_u32(val
, optval_addr
)) {
1356 return -TARGET_EFAULT
;
1358 ret
= get_errno(setsockopt(sockfd
, level
, optname
,
1359 &val
, sizeof(val
)));
1368 /* struct icmp_filter takes an u32 value */
1369 if (optlen
< sizeof(uint32_t)) {
1370 return -TARGET_EINVAL
;
1373 if (get_user_u32(val
, optval_addr
)) {
1374 return -TARGET_EFAULT
;
1376 ret
= get_errno(setsockopt(sockfd
, level
, optname
,
1377 &val
, sizeof(val
)));
1384 case TARGET_SOL_SOCKET
:
1386 case TARGET_SO_RCVTIMEO
:
1390 optname
= SO_RCVTIMEO
;
1393 if (optlen
!= sizeof(struct target_timeval
)) {
1394 return -TARGET_EINVAL
;
1397 if (copy_from_user_timeval(&tv
, optval_addr
)) {
1398 return -TARGET_EFAULT
;
1401 ret
= get_errno(setsockopt(sockfd
, SOL_SOCKET
, optname
,
1405 case TARGET_SO_SNDTIMEO
:
1406 optname
= SO_SNDTIMEO
;
1408 case TARGET_SO_ATTACH_FILTER
:
1410 struct target_sock_fprog
*tfprog
;
1411 struct target_sock_filter
*tfilter
;
1412 struct sock_fprog fprog
;
1413 struct sock_filter
*filter
;
1416 if (optlen
!= sizeof(*tfprog
)) {
1417 return -TARGET_EINVAL
;
1419 if (!lock_user_struct(VERIFY_READ
, tfprog
, optval_addr
, 0)) {
1420 return -TARGET_EFAULT
;
1422 if (!lock_user_struct(VERIFY_READ
, tfilter
,
1423 tswapal(tfprog
->filter
), 0)) {
1424 unlock_user_struct(tfprog
, optval_addr
, 1);
1425 return -TARGET_EFAULT
;
1428 fprog
.len
= tswap16(tfprog
->len
);
1429 filter
= malloc(fprog
.len
* sizeof(*filter
));
1430 if (filter
== NULL
) {
1431 unlock_user_struct(tfilter
, tfprog
->filter
, 1);
1432 unlock_user_struct(tfprog
, optval_addr
, 1);
1433 return -TARGET_ENOMEM
;
1435 for (i
= 0; i
< fprog
.len
; i
++) {
1436 filter
[i
].code
= tswap16(tfilter
[i
].code
);
1437 filter
[i
].jt
= tfilter
[i
].jt
;
1438 filter
[i
].jf
= tfilter
[i
].jf
;
1439 filter
[i
].k
= tswap32(tfilter
[i
].k
);
1441 fprog
.filter
= filter
;
1443 ret
= get_errno(setsockopt(sockfd
, SOL_SOCKET
,
1444 SO_ATTACH_FILTER
, &fprog
, sizeof(fprog
)));
1447 unlock_user_struct(tfilter
, tfprog
->filter
, 1);
1448 unlock_user_struct(tfprog
, optval_addr
, 1);
1451 /* Options with 'int' argument. */
1452 case TARGET_SO_DEBUG
:
1455 case TARGET_SO_REUSEADDR
:
1456 optname
= SO_REUSEADDR
;
1458 case TARGET_SO_TYPE
:
1461 case TARGET_SO_ERROR
:
1464 case TARGET_SO_DONTROUTE
:
1465 optname
= SO_DONTROUTE
;
1467 case TARGET_SO_BROADCAST
:
1468 optname
= SO_BROADCAST
;
1470 case TARGET_SO_SNDBUF
:
1471 optname
= SO_SNDBUF
;
1473 case TARGET_SO_RCVBUF
:
1474 optname
= SO_RCVBUF
;
1476 case TARGET_SO_KEEPALIVE
:
1477 optname
= SO_KEEPALIVE
;
1479 case TARGET_SO_OOBINLINE
:
1480 optname
= SO_OOBINLINE
;
1482 case TARGET_SO_NO_CHECK
:
1483 optname
= SO_NO_CHECK
;
1485 case TARGET_SO_PRIORITY
:
1486 optname
= SO_PRIORITY
;
1489 case TARGET_SO_BSDCOMPAT
:
1490 optname
= SO_BSDCOMPAT
;
1493 case TARGET_SO_PASSCRED
:
1494 optname
= SO_PASSCRED
;
1496 case TARGET_SO_TIMESTAMP
:
1497 optname
= SO_TIMESTAMP
;
1499 case TARGET_SO_RCVLOWAT
:
1500 optname
= SO_RCVLOWAT
;
1506 if (optlen
< sizeof(uint32_t))
1507 return -TARGET_EINVAL
;
1509 if (get_user_u32(val
, optval_addr
))
1510 return -TARGET_EFAULT
;
1511 ret
= get_errno(setsockopt(sockfd
, SOL_SOCKET
, optname
, &val
, sizeof(val
)));
1515 gemu_log("Unsupported setsockopt level=%d optname=%d\n", level
, optname
);
1516 ret
= -TARGET_ENOPROTOOPT
;
1521 /* do_getsockopt() Must return target values and target errnos. */
1522 static abi_long
do_getsockopt(int sockfd
, int level
, int optname
,
1523 abi_ulong optval_addr
, abi_ulong optlen
)
1530 case TARGET_SOL_SOCKET
:
1533 /* These don't just return a single integer */
1534 case TARGET_SO_LINGER
:
1535 case TARGET_SO_RCVTIMEO
:
1536 case TARGET_SO_SNDTIMEO
:
1537 case TARGET_SO_PEERNAME
:
1539 case TARGET_SO_PEERCRED
: {
1542 struct target_ucred
*tcr
;
1544 if (get_user_u32(len
, optlen
)) {
1545 return -TARGET_EFAULT
;
1548 return -TARGET_EINVAL
;
1552 ret
= get_errno(getsockopt(sockfd
, level
, SO_PEERCRED
,
1560 if (!lock_user_struct(VERIFY_WRITE
, tcr
, optval_addr
, 0)) {
1561 return -TARGET_EFAULT
;
1563 __put_user(cr
.pid
, &tcr
->pid
);
1564 __put_user(cr
.uid
, &tcr
->uid
);
1565 __put_user(cr
.gid
, &tcr
->gid
);
1566 unlock_user_struct(tcr
, optval_addr
, 1);
1567 if (put_user_u32(len
, optlen
)) {
1568 return -TARGET_EFAULT
;
1572 /* Options with 'int' argument. */
1573 case TARGET_SO_DEBUG
:
1576 case TARGET_SO_REUSEADDR
:
1577 optname
= SO_REUSEADDR
;
1579 case TARGET_SO_TYPE
:
1582 case TARGET_SO_ERROR
:
1585 case TARGET_SO_DONTROUTE
:
1586 optname
= SO_DONTROUTE
;
1588 case TARGET_SO_BROADCAST
:
1589 optname
= SO_BROADCAST
;
1591 case TARGET_SO_SNDBUF
:
1592 optname
= SO_SNDBUF
;
1594 case TARGET_SO_RCVBUF
:
1595 optname
= SO_RCVBUF
;
1597 case TARGET_SO_KEEPALIVE
:
1598 optname
= SO_KEEPALIVE
;
1600 case TARGET_SO_OOBINLINE
:
1601 optname
= SO_OOBINLINE
;
1603 case TARGET_SO_NO_CHECK
:
1604 optname
= SO_NO_CHECK
;
1606 case TARGET_SO_PRIORITY
:
1607 optname
= SO_PRIORITY
;
1610 case TARGET_SO_BSDCOMPAT
:
1611 optname
= SO_BSDCOMPAT
;
1614 case TARGET_SO_PASSCRED
:
1615 optname
= SO_PASSCRED
;
1617 case TARGET_SO_TIMESTAMP
:
1618 optname
= SO_TIMESTAMP
;
1620 case TARGET_SO_RCVLOWAT
:
1621 optname
= SO_RCVLOWAT
;
1628 /* TCP options all take an 'int' value. */
1630 if (get_user_u32(len
, optlen
))
1631 return -TARGET_EFAULT
;
1633 return -TARGET_EINVAL
;
1635 ret
= get_errno(getsockopt(sockfd
, level
, optname
, &val
, &lv
));
1641 if (put_user_u32(val
, optval_addr
))
1642 return -TARGET_EFAULT
;
1644 if (put_user_u8(val
, optval_addr
))
1645 return -TARGET_EFAULT
;
1647 if (put_user_u32(len
, optlen
))
1648 return -TARGET_EFAULT
;
1655 case IP_ROUTER_ALERT
:
1659 case IP_MTU_DISCOVER
:
1665 case IP_MULTICAST_TTL
:
1666 case IP_MULTICAST_LOOP
:
1667 if (get_user_u32(len
, optlen
))
1668 return -TARGET_EFAULT
;
1670 return -TARGET_EINVAL
;
1672 ret
= get_errno(getsockopt(sockfd
, level
, optname
, &val
, &lv
));
1675 if (len
< sizeof(int) && len
> 0 && val
>= 0 && val
< 255) {
1677 if (put_user_u32(len
, optlen
)
1678 || put_user_u8(val
, optval_addr
))
1679 return -TARGET_EFAULT
;
1681 if (len
> sizeof(int))
1683 if (put_user_u32(len
, optlen
)
1684 || put_user_u32(val
, optval_addr
))
1685 return -TARGET_EFAULT
;
1689 ret
= -TARGET_ENOPROTOOPT
;
1695 gemu_log("getsockopt level=%d optname=%d not yet supported\n",
1697 ret
= -TARGET_EOPNOTSUPP
;
1703 static struct iovec
*lock_iovec(int type
, abi_ulong target_addr
,
1704 int count
, int copy
)
1706 struct target_iovec
*target_vec
;
1708 abi_ulong total_len
, max_len
;
1715 if (count
< 0 || count
> IOV_MAX
) {
1720 vec
= calloc(count
, sizeof(struct iovec
));
1726 target_vec
= lock_user(VERIFY_READ
, target_addr
,
1727 count
* sizeof(struct target_iovec
), 1);
1728 if (target_vec
== NULL
) {
1733 /* ??? If host page size > target page size, this will result in a
1734 value larger than what we can actually support. */
1735 max_len
= 0x7fffffff & TARGET_PAGE_MASK
;
1738 for (i
= 0; i
< count
; i
++) {
1739 abi_ulong base
= tswapal(target_vec
[i
].iov_base
);
1740 abi_long len
= tswapal(target_vec
[i
].iov_len
);
1745 } else if (len
== 0) {
1746 /* Zero length pointer is ignored. */
1747 vec
[i
].iov_base
= 0;
1749 vec
[i
].iov_base
= lock_user(type
, base
, len
, copy
);
1750 if (!vec
[i
].iov_base
) {
1754 if (len
> max_len
- total_len
) {
1755 len
= max_len
- total_len
;
1758 vec
[i
].iov_len
= len
;
1762 unlock_user(target_vec
, target_addr
, 0);
1768 unlock_user(target_vec
, target_addr
, 0);
1772 static void unlock_iovec(struct iovec
*vec
, abi_ulong target_addr
,
1773 int count
, int copy
)
1775 struct target_iovec
*target_vec
;
1778 target_vec
= lock_user(VERIFY_READ
, target_addr
,
1779 count
* sizeof(struct target_iovec
), 1);
1781 for (i
= 0; i
< count
; i
++) {
1782 abi_ulong base
= tswapal(target_vec
[i
].iov_base
);
1783 abi_long len
= tswapal(target_vec
[i
].iov_base
);
1787 unlock_user(vec
[i
].iov_base
, base
, copy
? vec
[i
].iov_len
: 0);
1789 unlock_user(target_vec
, target_addr
, 0);
1795 static inline int target_to_host_sock_type(int *type
)
1798 int target_type
= *type
;
1800 switch (target_type
& TARGET_SOCK_TYPE_MASK
) {
1801 case TARGET_SOCK_DGRAM
:
1802 host_type
= SOCK_DGRAM
;
1804 case TARGET_SOCK_STREAM
:
1805 host_type
= SOCK_STREAM
;
1808 host_type
= target_type
& TARGET_SOCK_TYPE_MASK
;
1811 if (target_type
& TARGET_SOCK_CLOEXEC
) {
1812 #if defined(SOCK_CLOEXEC)
1813 host_type
|= SOCK_CLOEXEC
;
1815 return -TARGET_EINVAL
;
1818 if (target_type
& TARGET_SOCK_NONBLOCK
) {
1819 #if defined(SOCK_NONBLOCK)
1820 host_type
|= SOCK_NONBLOCK
;
1821 #elif !defined(O_NONBLOCK)
1822 return -TARGET_EINVAL
;
1829 /* Try to emulate socket type flags after socket creation. */
1830 static int sock_flags_fixup(int fd
, int target_type
)
1832 #if !defined(SOCK_NONBLOCK) && defined(O_NONBLOCK)
1833 if (target_type
& TARGET_SOCK_NONBLOCK
) {
1834 int flags
= fcntl(fd
, F_GETFL
);
1835 if (fcntl(fd
, F_SETFL
, O_NONBLOCK
| flags
) == -1) {
1837 return -TARGET_EINVAL
;
1844 /* do_socket() Must return target values and target errnos. */
1845 static abi_long
do_socket(int domain
, int type
, int protocol
)
1847 int target_type
= type
;
1850 ret
= target_to_host_sock_type(&type
);
1855 if (domain
== PF_NETLINK
)
1856 return -EAFNOSUPPORT
; /* do not NETLINK socket connections possible */
1857 ret
= get_errno(socket(domain
, type
, protocol
));
1859 ret
= sock_flags_fixup(ret
, target_type
);
1864 /* do_bind() Must return target values and target errnos. */
1865 static abi_long
do_bind(int sockfd
, abi_ulong target_addr
,
1871 if ((int)addrlen
< 0) {
1872 return -TARGET_EINVAL
;
1875 addr
= alloca(addrlen
+1);
1877 ret
= target_to_host_sockaddr(addr
, target_addr
, addrlen
);
1881 return get_errno(bind(sockfd
, addr
, addrlen
));
1884 /* do_connect() Must return target values and target errnos. */
1885 static abi_long
do_connect(int sockfd
, abi_ulong target_addr
,
1891 if ((int)addrlen
< 0) {
1892 return -TARGET_EINVAL
;
1895 addr
= alloca(addrlen
);
1897 ret
= target_to_host_sockaddr(addr
, target_addr
, addrlen
);
1901 return get_errno(connect(sockfd
, addr
, addrlen
));
1904 /* do_sendrecvmsg() Must return target values and target errnos. */
1905 static abi_long
do_sendrecvmsg(int fd
, abi_ulong target_msg
,
1906 int flags
, int send
)
1909 struct target_msghdr
*msgp
;
1913 abi_ulong target_vec
;
1916 if (!lock_user_struct(send
? VERIFY_READ
: VERIFY_WRITE
,
1920 return -TARGET_EFAULT
;
1921 if (msgp
->msg_name
) {
1922 msg
.msg_namelen
= tswap32(msgp
->msg_namelen
);
1923 msg
.msg_name
= alloca(msg
.msg_namelen
);
1924 ret
= target_to_host_sockaddr(msg
.msg_name
, tswapal(msgp
->msg_name
),
1930 msg
.msg_name
= NULL
;
1931 msg
.msg_namelen
= 0;
1933 msg
.msg_controllen
= 2 * tswapal(msgp
->msg_controllen
);
1934 msg
.msg_control
= alloca(msg
.msg_controllen
);
1935 msg
.msg_flags
= tswap32(msgp
->msg_flags
);
1937 count
= tswapal(msgp
->msg_iovlen
);
1938 target_vec
= tswapal(msgp
->msg_iov
);
1939 vec
= lock_iovec(send
? VERIFY_READ
: VERIFY_WRITE
,
1940 target_vec
, count
, send
);
1942 ret
= -host_to_target_errno(errno
);
1945 msg
.msg_iovlen
= count
;
1949 ret
= target_to_host_cmsg(&msg
, msgp
);
1951 ret
= get_errno(sendmsg(fd
, &msg
, flags
));
1953 ret
= get_errno(recvmsg(fd
, &msg
, flags
));
1954 if (!is_error(ret
)) {
1956 ret
= host_to_target_cmsg(msgp
, &msg
);
1957 if (!is_error(ret
)) {
1958 msgp
->msg_namelen
= tswap32(msg
.msg_namelen
);
1959 if (msg
.msg_name
!= NULL
) {
1960 ret
= host_to_target_sockaddr(tswapal(msgp
->msg_name
),
1961 msg
.msg_name
, msg
.msg_namelen
);
1973 unlock_iovec(vec
, target_vec
, count
, !send
);
1975 unlock_user_struct(msgp
, target_msg
, send
? 0 : 1);
1979 /* If we don't have a system accept4() then just call accept.
1980 * The callsites to do_accept4() will ensure that they don't
1981 * pass a non-zero flags argument in this config.
1983 #ifndef CONFIG_ACCEPT4
1984 static inline int accept4(int sockfd
, struct sockaddr
*addr
,
1985 socklen_t
*addrlen
, int flags
)
1988 return accept(sockfd
, addr
, addrlen
);
1992 /* do_accept4() Must return target values and target errnos. */
1993 static abi_long
do_accept4(int fd
, abi_ulong target_addr
,
1994 abi_ulong target_addrlen_addr
, int flags
)
2000 if (target_addr
== 0) {
2001 return get_errno(accept4(fd
, NULL
, NULL
, flags
));
2004 /* linux returns EINVAL if addrlen pointer is invalid */
2005 if (get_user_u32(addrlen
, target_addrlen_addr
))
2006 return -TARGET_EINVAL
;
2008 if ((int)addrlen
< 0) {
2009 return -TARGET_EINVAL
;
2012 if (!access_ok(VERIFY_WRITE
, target_addr
, addrlen
))
2013 return -TARGET_EINVAL
;
2015 addr
= alloca(addrlen
);
2017 ret
= get_errno(accept4(fd
, addr
, &addrlen
, flags
));
2018 if (!is_error(ret
)) {
2019 host_to_target_sockaddr(target_addr
, addr
, addrlen
);
2020 if (put_user_u32(addrlen
, target_addrlen_addr
))
2021 ret
= -TARGET_EFAULT
;
2026 /* do_getpeername() Must return target values and target errnos. */
2027 static abi_long
do_getpeername(int fd
, abi_ulong target_addr
,
2028 abi_ulong target_addrlen_addr
)
2034 if (get_user_u32(addrlen
, target_addrlen_addr
))
2035 return -TARGET_EFAULT
;
2037 if ((int)addrlen
< 0) {
2038 return -TARGET_EINVAL
;
2041 if (!access_ok(VERIFY_WRITE
, target_addr
, addrlen
))
2042 return -TARGET_EFAULT
;
2044 addr
= alloca(addrlen
);
2046 ret
= get_errno(getpeername(fd
, addr
, &addrlen
));
2047 if (!is_error(ret
)) {
2048 host_to_target_sockaddr(target_addr
, addr
, addrlen
);
2049 if (put_user_u32(addrlen
, target_addrlen_addr
))
2050 ret
= -TARGET_EFAULT
;
2055 /* do_getsockname() Must return target values and target errnos. */
2056 static abi_long
do_getsockname(int fd
, abi_ulong target_addr
,
2057 abi_ulong target_addrlen_addr
)
2063 if (get_user_u32(addrlen
, target_addrlen_addr
))
2064 return -TARGET_EFAULT
;
2066 if ((int)addrlen
< 0) {
2067 return -TARGET_EINVAL
;
2070 if (!access_ok(VERIFY_WRITE
, target_addr
, addrlen
))
2071 return -TARGET_EFAULT
;
2073 addr
= alloca(addrlen
);
2075 ret
= get_errno(getsockname(fd
, addr
, &addrlen
));
2076 if (!is_error(ret
)) {
2077 host_to_target_sockaddr(target_addr
, addr
, addrlen
);
2078 if (put_user_u32(addrlen
, target_addrlen_addr
))
2079 ret
= -TARGET_EFAULT
;
2084 /* do_socketpair() Must return target values and target errnos. */
2085 static abi_long
do_socketpair(int domain
, int type
, int protocol
,
2086 abi_ulong target_tab_addr
)
2091 target_to_host_sock_type(&type
);
2093 ret
= get_errno(socketpair(domain
, type
, protocol
, tab
));
2094 if (!is_error(ret
)) {
2095 if (put_user_s32(tab
[0], target_tab_addr
)
2096 || put_user_s32(tab
[1], target_tab_addr
+ sizeof(tab
[0])))
2097 ret
= -TARGET_EFAULT
;
2102 /* do_sendto() Must return target values and target errnos. */
2103 static abi_long
do_sendto(int fd
, abi_ulong msg
, size_t len
, int flags
,
2104 abi_ulong target_addr
, socklen_t addrlen
)
2110 if ((int)addrlen
< 0) {
2111 return -TARGET_EINVAL
;
2114 host_msg
= lock_user(VERIFY_READ
, msg
, len
, 1);
2116 return -TARGET_EFAULT
;
2118 addr
= alloca(addrlen
);
2119 ret
= target_to_host_sockaddr(addr
, target_addr
, addrlen
);
2121 unlock_user(host_msg
, msg
, 0);
2124 ret
= get_errno(sendto(fd
, host_msg
, len
, flags
, addr
, addrlen
));
2126 ret
= get_errno(send(fd
, host_msg
, len
, flags
));
2128 unlock_user(host_msg
, msg
, 0);
2132 /* do_recvfrom() Must return target values and target errnos. */
2133 static abi_long
do_recvfrom(int fd
, abi_ulong msg
, size_t len
, int flags
,
2134 abi_ulong target_addr
,
2135 abi_ulong target_addrlen
)
2142 host_msg
= lock_user(VERIFY_WRITE
, msg
, len
, 0);
2144 return -TARGET_EFAULT
;
2146 if (get_user_u32(addrlen
, target_addrlen
)) {
2147 ret
= -TARGET_EFAULT
;
2150 if ((int)addrlen
< 0) {
2151 ret
= -TARGET_EINVAL
;
2154 addr
= alloca(addrlen
);
2155 ret
= get_errno(recvfrom(fd
, host_msg
, len
, flags
, addr
, &addrlen
));
2157 addr
= NULL
; /* To keep compiler quiet. */
2158 ret
= get_errno(qemu_recv(fd
, host_msg
, len
, flags
));
2160 if (!is_error(ret
)) {
2162 host_to_target_sockaddr(target_addr
, addr
, addrlen
);
2163 if (put_user_u32(addrlen
, target_addrlen
)) {
2164 ret
= -TARGET_EFAULT
;
2168 unlock_user(host_msg
, msg
, len
);
2171 unlock_user(host_msg
, msg
, 0);
2176 #ifdef TARGET_NR_socketcall
2177 /* do_socketcall() Must return target values and target errnos. */
2178 static abi_long
do_socketcall(int num
, abi_ulong vptr
)
2181 const int n
= sizeof(abi_ulong
);
2186 abi_ulong domain
, type
, protocol
;
2188 if (get_user_ual(domain
, vptr
)
2189 || get_user_ual(type
, vptr
+ n
)
2190 || get_user_ual(protocol
, vptr
+ 2 * n
))
2191 return -TARGET_EFAULT
;
2193 ret
= do_socket(domain
, type
, protocol
);
2199 abi_ulong target_addr
;
2202 if (get_user_ual(sockfd
, vptr
)
2203 || get_user_ual(target_addr
, vptr
+ n
)
2204 || get_user_ual(addrlen
, vptr
+ 2 * n
))
2205 return -TARGET_EFAULT
;
2207 ret
= do_bind(sockfd
, target_addr
, addrlen
);
2210 case SOCKOP_connect
:
2213 abi_ulong target_addr
;
2216 if (get_user_ual(sockfd
, vptr
)
2217 || get_user_ual(target_addr
, vptr
+ n
)
2218 || get_user_ual(addrlen
, vptr
+ 2 * n
))
2219 return -TARGET_EFAULT
;
2221 ret
= do_connect(sockfd
, target_addr
, addrlen
);
2226 abi_ulong sockfd
, backlog
;
2228 if (get_user_ual(sockfd
, vptr
)
2229 || get_user_ual(backlog
, vptr
+ n
))
2230 return -TARGET_EFAULT
;
2232 ret
= get_errno(listen(sockfd
, backlog
));
2238 abi_ulong target_addr
, target_addrlen
;
2240 if (get_user_ual(sockfd
, vptr
)
2241 || get_user_ual(target_addr
, vptr
+ n
)
2242 || get_user_ual(target_addrlen
, vptr
+ 2 * n
))
2243 return -TARGET_EFAULT
;
2245 ret
= do_accept4(sockfd
, target_addr
, target_addrlen
, 0);
2248 case SOCKOP_accept4
:
2251 abi_ulong target_addr
, target_addrlen
;
2254 if (get_user_ual(sockfd
, vptr
)
2255 || get_user_ual(target_addr
, vptr
+ n
)
2256 || get_user_ual(target_addrlen
, vptr
+ 2 * n
)
2257 || get_user_ual(flags
, vptr
+ 3 * n
)) {
2258 return -TARGET_EFAULT
;
2261 ret
= do_accept4(sockfd
, target_addr
, target_addrlen
, flags
);
2264 case SOCKOP_getsockname
:
2267 abi_ulong target_addr
, target_addrlen
;
2269 if (get_user_ual(sockfd
, vptr
)
2270 || get_user_ual(target_addr
, vptr
+ n
)
2271 || get_user_ual(target_addrlen
, vptr
+ 2 * n
))
2272 return -TARGET_EFAULT
;
2274 ret
= do_getsockname(sockfd
, target_addr
, target_addrlen
);
2277 case SOCKOP_getpeername
:
2280 abi_ulong target_addr
, target_addrlen
;
2282 if (get_user_ual(sockfd
, vptr
)
2283 || get_user_ual(target_addr
, vptr
+ n
)
2284 || get_user_ual(target_addrlen
, vptr
+ 2 * n
))
2285 return -TARGET_EFAULT
;
2287 ret
= do_getpeername(sockfd
, target_addr
, target_addrlen
);
2290 case SOCKOP_socketpair
:
2292 abi_ulong domain
, type
, protocol
;
2295 if (get_user_ual(domain
, vptr
)
2296 || get_user_ual(type
, vptr
+ n
)
2297 || get_user_ual(protocol
, vptr
+ 2 * n
)
2298 || get_user_ual(tab
, vptr
+ 3 * n
))
2299 return -TARGET_EFAULT
;
2301 ret
= do_socketpair(domain
, type
, protocol
, tab
);
2311 if (get_user_ual(sockfd
, vptr
)
2312 || get_user_ual(msg
, vptr
+ n
)
2313 || get_user_ual(len
, vptr
+ 2 * n
)
2314 || get_user_ual(flags
, vptr
+ 3 * n
))
2315 return -TARGET_EFAULT
;
2317 ret
= do_sendto(sockfd
, msg
, len
, flags
, 0, 0);
2327 if (get_user_ual(sockfd
, vptr
)
2328 || get_user_ual(msg
, vptr
+ n
)
2329 || get_user_ual(len
, vptr
+ 2 * n
)
2330 || get_user_ual(flags
, vptr
+ 3 * n
))
2331 return -TARGET_EFAULT
;
2333 ret
= do_recvfrom(sockfd
, msg
, len
, flags
, 0, 0);
2345 if (get_user_ual(sockfd
, vptr
)
2346 || get_user_ual(msg
, vptr
+ n
)
2347 || get_user_ual(len
, vptr
+ 2 * n
)
2348 || get_user_ual(flags
, vptr
+ 3 * n
)
2349 || get_user_ual(addr
, vptr
+ 4 * n
)
2350 || get_user_ual(addrlen
, vptr
+ 5 * n
))
2351 return -TARGET_EFAULT
;
2353 ret
= do_sendto(sockfd
, msg
, len
, flags
, addr
, addrlen
);
2356 case SOCKOP_recvfrom
:
2365 if (get_user_ual(sockfd
, vptr
)
2366 || get_user_ual(msg
, vptr
+ n
)
2367 || get_user_ual(len
, vptr
+ 2 * n
)
2368 || get_user_ual(flags
, vptr
+ 3 * n
)
2369 || get_user_ual(addr
, vptr
+ 4 * n
)
2370 || get_user_ual(addrlen
, vptr
+ 5 * n
))
2371 return -TARGET_EFAULT
;
2373 ret
= do_recvfrom(sockfd
, msg
, len
, flags
, addr
, addrlen
);
2376 case SOCKOP_shutdown
:
2378 abi_ulong sockfd
, how
;
2380 if (get_user_ual(sockfd
, vptr
)
2381 || get_user_ual(how
, vptr
+ n
))
2382 return -TARGET_EFAULT
;
2384 ret
= get_errno(shutdown(sockfd
, how
));
2387 case SOCKOP_sendmsg
:
2388 case SOCKOP_recvmsg
:
2391 abi_ulong target_msg
;
2394 if (get_user_ual(fd
, vptr
)
2395 || get_user_ual(target_msg
, vptr
+ n
)
2396 || get_user_ual(flags
, vptr
+ 2 * n
))
2397 return -TARGET_EFAULT
;
2399 ret
= do_sendrecvmsg(fd
, target_msg
, flags
,
2400 (num
== SOCKOP_sendmsg
));
2403 case SOCKOP_setsockopt
:
2411 if (get_user_ual(sockfd
, vptr
)
2412 || get_user_ual(level
, vptr
+ n
)
2413 || get_user_ual(optname
, vptr
+ 2 * n
)
2414 || get_user_ual(optval
, vptr
+ 3 * n
)
2415 || get_user_ual(optlen
, vptr
+ 4 * n
))
2416 return -TARGET_EFAULT
;
2418 ret
= do_setsockopt(sockfd
, level
, optname
, optval
, optlen
);
2421 case SOCKOP_getsockopt
:
2429 if (get_user_ual(sockfd
, vptr
)
2430 || get_user_ual(level
, vptr
+ n
)
2431 || get_user_ual(optname
, vptr
+ 2 * n
)
2432 || get_user_ual(optval
, vptr
+ 3 * n
)
2433 || get_user_ual(optlen
, vptr
+ 4 * n
))
2434 return -TARGET_EFAULT
;
2436 ret
= do_getsockopt(sockfd
, level
, optname
, optval
, optlen
);
2440 gemu_log("Unsupported socketcall: %d\n", num
);
2441 ret
= -TARGET_ENOSYS
;
2448 #define N_SHM_REGIONS 32
2450 static struct shm_region
{
2453 } shm_regions
[N_SHM_REGIONS
];
2455 struct target_semid_ds
2457 struct target_ipc_perm sem_perm
;
2458 abi_ulong sem_otime
;
2459 abi_ulong __unused1
;
2460 abi_ulong sem_ctime
;
2461 abi_ulong __unused2
;
2462 abi_ulong sem_nsems
;
2463 abi_ulong __unused3
;
2464 abi_ulong __unused4
;
2467 static inline abi_long
target_to_host_ipc_perm(struct ipc_perm
*host_ip
,
2468 abi_ulong target_addr
)
2470 struct target_ipc_perm
*target_ip
;
2471 struct target_semid_ds
*target_sd
;
2473 if (!lock_user_struct(VERIFY_READ
, target_sd
, target_addr
, 1))
2474 return -TARGET_EFAULT
;
2475 target_ip
= &(target_sd
->sem_perm
);
2476 host_ip
->__key
= tswap32(target_ip
->__key
);
2477 host_ip
->uid
= tswap32(target_ip
->uid
);
2478 host_ip
->gid
= tswap32(target_ip
->gid
);
2479 host_ip
->cuid
= tswap32(target_ip
->cuid
);
2480 host_ip
->cgid
= tswap32(target_ip
->cgid
);
2481 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_PPC)
2482 host_ip
->mode
= tswap32(target_ip
->mode
);
2484 host_ip
->mode
= tswap16(target_ip
->mode
);
2486 #if defined(TARGET_PPC)
2487 host_ip
->__seq
= tswap32(target_ip
->__seq
);
2489 host_ip
->__seq
= tswap16(target_ip
->__seq
);
2491 unlock_user_struct(target_sd
, target_addr
, 0);
2495 static inline abi_long
host_to_target_ipc_perm(abi_ulong target_addr
,
2496 struct ipc_perm
*host_ip
)
2498 struct target_ipc_perm
*target_ip
;
2499 struct target_semid_ds
*target_sd
;
2501 if (!lock_user_struct(VERIFY_WRITE
, target_sd
, target_addr
, 0))
2502 return -TARGET_EFAULT
;
2503 target_ip
= &(target_sd
->sem_perm
);
2504 target_ip
->__key
= tswap32(host_ip
->__key
);
2505 target_ip
->uid
= tswap32(host_ip
->uid
);
2506 target_ip
->gid
= tswap32(host_ip
->gid
);
2507 target_ip
->cuid
= tswap32(host_ip
->cuid
);
2508 target_ip
->cgid
= tswap32(host_ip
->cgid
);
2509 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_PPC)
2510 target_ip
->mode
= tswap32(host_ip
->mode
);
2512 target_ip
->mode
= tswap16(host_ip
->mode
);
2514 #if defined(TARGET_PPC)
2515 target_ip
->__seq
= tswap32(host_ip
->__seq
);
2517 target_ip
->__seq
= tswap16(host_ip
->__seq
);
2519 unlock_user_struct(target_sd
, target_addr
, 1);
2523 static inline abi_long
target_to_host_semid_ds(struct semid_ds
*host_sd
,
2524 abi_ulong target_addr
)
2526 struct target_semid_ds
*target_sd
;
2528 if (!lock_user_struct(VERIFY_READ
, target_sd
, target_addr
, 1))
2529 return -TARGET_EFAULT
;
2530 if (target_to_host_ipc_perm(&(host_sd
->sem_perm
),target_addr
))
2531 return -TARGET_EFAULT
;
2532 host_sd
->sem_nsems
= tswapal(target_sd
->sem_nsems
);
2533 host_sd
->sem_otime
= tswapal(target_sd
->sem_otime
);
2534 host_sd
->sem_ctime
= tswapal(target_sd
->sem_ctime
);
2535 unlock_user_struct(target_sd
, target_addr
, 0);
2539 static inline abi_long
host_to_target_semid_ds(abi_ulong target_addr
,
2540 struct semid_ds
*host_sd
)
2542 struct target_semid_ds
*target_sd
;
2544 if (!lock_user_struct(VERIFY_WRITE
, target_sd
, target_addr
, 0))
2545 return -TARGET_EFAULT
;
2546 if (host_to_target_ipc_perm(target_addr
,&(host_sd
->sem_perm
)))
2547 return -TARGET_EFAULT
;
2548 target_sd
->sem_nsems
= tswapal(host_sd
->sem_nsems
);
2549 target_sd
->sem_otime
= tswapal(host_sd
->sem_otime
);
2550 target_sd
->sem_ctime
= tswapal(host_sd
->sem_ctime
);
2551 unlock_user_struct(target_sd
, target_addr
, 1);
2555 struct target_seminfo
{
2568 static inline abi_long
host_to_target_seminfo(abi_ulong target_addr
,
2569 struct seminfo
*host_seminfo
)
2571 struct target_seminfo
*target_seminfo
;
2572 if (!lock_user_struct(VERIFY_WRITE
, target_seminfo
, target_addr
, 0))
2573 return -TARGET_EFAULT
;
2574 __put_user(host_seminfo
->semmap
, &target_seminfo
->semmap
);
2575 __put_user(host_seminfo
->semmni
, &target_seminfo
->semmni
);
2576 __put_user(host_seminfo
->semmns
, &target_seminfo
->semmns
);
2577 __put_user(host_seminfo
->semmnu
, &target_seminfo
->semmnu
);
2578 __put_user(host_seminfo
->semmsl
, &target_seminfo
->semmsl
);
2579 __put_user(host_seminfo
->semopm
, &target_seminfo
->semopm
);
2580 __put_user(host_seminfo
->semume
, &target_seminfo
->semume
);
2581 __put_user(host_seminfo
->semusz
, &target_seminfo
->semusz
);
2582 __put_user(host_seminfo
->semvmx
, &target_seminfo
->semvmx
);
2583 __put_user(host_seminfo
->semaem
, &target_seminfo
->semaem
);
2584 unlock_user_struct(target_seminfo
, target_addr
, 1);
2590 struct semid_ds
*buf
;
2591 unsigned short *array
;
2592 struct seminfo
*__buf
;
2595 union target_semun
{
2602 static inline abi_long
target_to_host_semarray(int semid
, unsigned short **host_array
,
2603 abi_ulong target_addr
)
2606 unsigned short *array
;
2608 struct semid_ds semid_ds
;
2611 semun
.buf
= &semid_ds
;
2613 ret
= semctl(semid
, 0, IPC_STAT
, semun
);
2615 return get_errno(ret
);
2617 nsems
= semid_ds
.sem_nsems
;
2619 *host_array
= malloc(nsems
*sizeof(unsigned short));
2620 array
= lock_user(VERIFY_READ
, target_addr
,
2621 nsems
*sizeof(unsigned short), 1);
2623 return -TARGET_EFAULT
;
2625 for(i
=0; i
<nsems
; i
++) {
2626 __get_user((*host_array
)[i
], &array
[i
]);
2628 unlock_user(array
, target_addr
, 0);
2633 static inline abi_long
host_to_target_semarray(int semid
, abi_ulong target_addr
,
2634 unsigned short **host_array
)
2637 unsigned short *array
;
2639 struct semid_ds semid_ds
;
2642 semun
.buf
= &semid_ds
;
2644 ret
= semctl(semid
, 0, IPC_STAT
, semun
);
2646 return get_errno(ret
);
2648 nsems
= semid_ds
.sem_nsems
;
2650 array
= lock_user(VERIFY_WRITE
, target_addr
,
2651 nsems
*sizeof(unsigned short), 0);
2653 return -TARGET_EFAULT
;
2655 for(i
=0; i
<nsems
; i
++) {
2656 __put_user((*host_array
)[i
], &array
[i
]);
2659 unlock_user(array
, target_addr
, 1);
2664 static inline abi_long
do_semctl(int semid
, int semnum
, int cmd
,
2665 union target_semun target_su
)
2668 struct semid_ds dsarg
;
2669 unsigned short *array
= NULL
;
2670 struct seminfo seminfo
;
2671 abi_long ret
= -TARGET_EINVAL
;
2678 arg
.val
= tswap32(target_su
.val
);
2679 ret
= get_errno(semctl(semid
, semnum
, cmd
, arg
));
2680 target_su
.val
= tswap32(arg
.val
);
2684 err
= target_to_host_semarray(semid
, &array
, target_su
.array
);
2688 ret
= get_errno(semctl(semid
, semnum
, cmd
, arg
));
2689 err
= host_to_target_semarray(semid
, target_su
.array
, &array
);
2696 err
= target_to_host_semid_ds(&dsarg
, target_su
.buf
);
2700 ret
= get_errno(semctl(semid
, semnum
, cmd
, arg
));
2701 err
= host_to_target_semid_ds(target_su
.buf
, &dsarg
);
2707 arg
.__buf
= &seminfo
;
2708 ret
= get_errno(semctl(semid
, semnum
, cmd
, arg
));
2709 err
= host_to_target_seminfo(target_su
.__buf
, &seminfo
);
2717 ret
= get_errno(semctl(semid
, semnum
, cmd
, NULL
));
2724 struct target_sembuf
{
2725 unsigned short sem_num
;
2730 static inline abi_long
target_to_host_sembuf(struct sembuf
*host_sembuf
,
2731 abi_ulong target_addr
,
2734 struct target_sembuf
*target_sembuf
;
2737 target_sembuf
= lock_user(VERIFY_READ
, target_addr
,
2738 nsops
*sizeof(struct target_sembuf
), 1);
2740 return -TARGET_EFAULT
;
2742 for(i
=0; i
<nsops
; i
++) {
2743 __get_user(host_sembuf
[i
].sem_num
, &target_sembuf
[i
].sem_num
);
2744 __get_user(host_sembuf
[i
].sem_op
, &target_sembuf
[i
].sem_op
);
2745 __get_user(host_sembuf
[i
].sem_flg
, &target_sembuf
[i
].sem_flg
);
2748 unlock_user(target_sembuf
, target_addr
, 0);
2753 static inline abi_long
do_semop(int semid
, abi_long ptr
, unsigned nsops
)
2755 struct sembuf sops
[nsops
];
2757 if (target_to_host_sembuf(sops
, ptr
, nsops
))
2758 return -TARGET_EFAULT
;
2760 return get_errno(semop(semid
, sops
, nsops
));
2763 struct target_msqid_ds
2765 struct target_ipc_perm msg_perm
;
2766 abi_ulong msg_stime
;
2767 #if TARGET_ABI_BITS == 32
2768 abi_ulong __unused1
;
2770 abi_ulong msg_rtime
;
2771 #if TARGET_ABI_BITS == 32
2772 abi_ulong __unused2
;
2774 abi_ulong msg_ctime
;
2775 #if TARGET_ABI_BITS == 32
2776 abi_ulong __unused3
;
2778 abi_ulong __msg_cbytes
;
2780 abi_ulong msg_qbytes
;
2781 abi_ulong msg_lspid
;
2782 abi_ulong msg_lrpid
;
2783 abi_ulong __unused4
;
2784 abi_ulong __unused5
;
2787 static inline abi_long
target_to_host_msqid_ds(struct msqid_ds
*host_md
,
2788 abi_ulong target_addr
)
2790 struct target_msqid_ds
*target_md
;
2792 if (!lock_user_struct(VERIFY_READ
, target_md
, target_addr
, 1))
2793 return -TARGET_EFAULT
;
2794 if (target_to_host_ipc_perm(&(host_md
->msg_perm
),target_addr
))
2795 return -TARGET_EFAULT
;
2796 host_md
->msg_stime
= tswapal(target_md
->msg_stime
);
2797 host_md
->msg_rtime
= tswapal(target_md
->msg_rtime
);
2798 host_md
->msg_ctime
= tswapal(target_md
->msg_ctime
);
2799 host_md
->__msg_cbytes
= tswapal(target_md
->__msg_cbytes
);
2800 host_md
->msg_qnum
= tswapal(target_md
->msg_qnum
);
2801 host_md
->msg_qbytes
= tswapal(target_md
->msg_qbytes
);
2802 host_md
->msg_lspid
= tswapal(target_md
->msg_lspid
);
2803 host_md
->msg_lrpid
= tswapal(target_md
->msg_lrpid
);
2804 unlock_user_struct(target_md
, target_addr
, 0);
2808 static inline abi_long
host_to_target_msqid_ds(abi_ulong target_addr
,
2809 struct msqid_ds
*host_md
)
2811 struct target_msqid_ds
*target_md
;
2813 if (!lock_user_struct(VERIFY_WRITE
, target_md
, target_addr
, 0))
2814 return -TARGET_EFAULT
;
2815 if (host_to_target_ipc_perm(target_addr
,&(host_md
->msg_perm
)))
2816 return -TARGET_EFAULT
;
2817 target_md
->msg_stime
= tswapal(host_md
->msg_stime
);
2818 target_md
->msg_rtime
= tswapal(host_md
->msg_rtime
);
2819 target_md
->msg_ctime
= tswapal(host_md
->msg_ctime
);
2820 target_md
->__msg_cbytes
= tswapal(host_md
->__msg_cbytes
);
2821 target_md
->msg_qnum
= tswapal(host_md
->msg_qnum
);
2822 target_md
->msg_qbytes
= tswapal(host_md
->msg_qbytes
);
2823 target_md
->msg_lspid
= tswapal(host_md
->msg_lspid
);
2824 target_md
->msg_lrpid
= tswapal(host_md
->msg_lrpid
);
2825 unlock_user_struct(target_md
, target_addr
, 1);
2829 struct target_msginfo
{
2837 unsigned short int msgseg
;
2840 static inline abi_long
host_to_target_msginfo(abi_ulong target_addr
,
2841 struct msginfo
*host_msginfo
)
2843 struct target_msginfo
*target_msginfo
;
2844 if (!lock_user_struct(VERIFY_WRITE
, target_msginfo
, target_addr
, 0))
2845 return -TARGET_EFAULT
;
2846 __put_user(host_msginfo
->msgpool
, &target_msginfo
->msgpool
);
2847 __put_user(host_msginfo
->msgmap
, &target_msginfo
->msgmap
);
2848 __put_user(host_msginfo
->msgmax
, &target_msginfo
->msgmax
);
2849 __put_user(host_msginfo
->msgmnb
, &target_msginfo
->msgmnb
);
2850 __put_user(host_msginfo
->msgmni
, &target_msginfo
->msgmni
);
2851 __put_user(host_msginfo
->msgssz
, &target_msginfo
->msgssz
);
2852 __put_user(host_msginfo
->msgtql
, &target_msginfo
->msgtql
);
2853 __put_user(host_msginfo
->msgseg
, &target_msginfo
->msgseg
);
2854 unlock_user_struct(target_msginfo
, target_addr
, 1);
2858 static inline abi_long
do_msgctl(int msgid
, int cmd
, abi_long ptr
)
2860 struct msqid_ds dsarg
;
2861 struct msginfo msginfo
;
2862 abi_long ret
= -TARGET_EINVAL
;
2870 if (target_to_host_msqid_ds(&dsarg
,ptr
))
2871 return -TARGET_EFAULT
;
2872 ret
= get_errno(msgctl(msgid
, cmd
, &dsarg
));
2873 if (host_to_target_msqid_ds(ptr
,&dsarg
))
2874 return -TARGET_EFAULT
;
2877 ret
= get_errno(msgctl(msgid
, cmd
, NULL
));
2881 ret
= get_errno(msgctl(msgid
, cmd
, (struct msqid_ds
*)&msginfo
));
2882 if (host_to_target_msginfo(ptr
, &msginfo
))
2883 return -TARGET_EFAULT
;
2890 struct target_msgbuf
{
2895 static inline abi_long
do_msgsnd(int msqid
, abi_long msgp
,
2896 unsigned int msgsz
, int msgflg
)
2898 struct target_msgbuf
*target_mb
;
2899 struct msgbuf
*host_mb
;
2902 if (!lock_user_struct(VERIFY_READ
, target_mb
, msgp
, 0))
2903 return -TARGET_EFAULT
;
2904 host_mb
= malloc(msgsz
+sizeof(long));
2905 host_mb
->mtype
= (abi_long
) tswapal(target_mb
->mtype
);
2906 memcpy(host_mb
->mtext
, target_mb
->mtext
, msgsz
);
2907 ret
= get_errno(msgsnd(msqid
, host_mb
, msgsz
, msgflg
));
2909 unlock_user_struct(target_mb
, msgp
, 0);
2914 static inline abi_long
do_msgrcv(int msqid
, abi_long msgp
,
2915 unsigned int msgsz
, abi_long msgtyp
,
2918 struct target_msgbuf
*target_mb
;
2920 struct msgbuf
*host_mb
;
2923 if (!lock_user_struct(VERIFY_WRITE
, target_mb
, msgp
, 0))
2924 return -TARGET_EFAULT
;
2926 host_mb
= g_malloc(msgsz
+sizeof(long));
2927 ret
= get_errno(msgrcv(msqid
, host_mb
, msgsz
, msgtyp
, msgflg
));
2930 abi_ulong target_mtext_addr
= msgp
+ sizeof(abi_ulong
);
2931 target_mtext
= lock_user(VERIFY_WRITE
, target_mtext_addr
, ret
, 0);
2932 if (!target_mtext
) {
2933 ret
= -TARGET_EFAULT
;
2936 memcpy(target_mb
->mtext
, host_mb
->mtext
, ret
);
2937 unlock_user(target_mtext
, target_mtext_addr
, ret
);
2940 target_mb
->mtype
= tswapal(host_mb
->mtype
);
2944 unlock_user_struct(target_mb
, msgp
, 1);
2949 static inline abi_long
target_to_host_shmid_ds(struct shmid_ds
*host_sd
,
2950 abi_ulong target_addr
)
2952 struct target_shmid_ds
*target_sd
;
2954 if (!lock_user_struct(VERIFY_READ
, target_sd
, target_addr
, 1))
2955 return -TARGET_EFAULT
;
2956 if (target_to_host_ipc_perm(&(host_sd
->shm_perm
), target_addr
))
2957 return -TARGET_EFAULT
;
2958 __get_user(host_sd
->shm_segsz
, &target_sd
->shm_segsz
);
2959 __get_user(host_sd
->shm_atime
, &target_sd
->shm_atime
);
2960 __get_user(host_sd
->shm_dtime
, &target_sd
->shm_dtime
);
2961 __get_user(host_sd
->shm_ctime
, &target_sd
->shm_ctime
);
2962 __get_user(host_sd
->shm_cpid
, &target_sd
->shm_cpid
);
2963 __get_user(host_sd
->shm_lpid
, &target_sd
->shm_lpid
);
2964 __get_user(host_sd
->shm_nattch
, &target_sd
->shm_nattch
);
2965 unlock_user_struct(target_sd
, target_addr
, 0);
2969 static inline abi_long
host_to_target_shmid_ds(abi_ulong target_addr
,
2970 struct shmid_ds
*host_sd
)
2972 struct target_shmid_ds
*target_sd
;
2974 if (!lock_user_struct(VERIFY_WRITE
, target_sd
, target_addr
, 0))
2975 return -TARGET_EFAULT
;
2976 if (host_to_target_ipc_perm(target_addr
, &(host_sd
->shm_perm
)))
2977 return -TARGET_EFAULT
;
2978 __put_user(host_sd
->shm_segsz
, &target_sd
->shm_segsz
);
2979 __put_user(host_sd
->shm_atime
, &target_sd
->shm_atime
);
2980 __put_user(host_sd
->shm_dtime
, &target_sd
->shm_dtime
);
2981 __put_user(host_sd
->shm_ctime
, &target_sd
->shm_ctime
);
2982 __put_user(host_sd
->shm_cpid
, &target_sd
->shm_cpid
);
2983 __put_user(host_sd
->shm_lpid
, &target_sd
->shm_lpid
);
2984 __put_user(host_sd
->shm_nattch
, &target_sd
->shm_nattch
);
2985 unlock_user_struct(target_sd
, target_addr
, 1);
2989 struct target_shminfo
{
2997 static inline abi_long
host_to_target_shminfo(abi_ulong target_addr
,
2998 struct shminfo
*host_shminfo
)
3000 struct target_shminfo
*target_shminfo
;
3001 if (!lock_user_struct(VERIFY_WRITE
, target_shminfo
, target_addr
, 0))
3002 return -TARGET_EFAULT
;
3003 __put_user(host_shminfo
->shmmax
, &target_shminfo
->shmmax
);
3004 __put_user(host_shminfo
->shmmin
, &target_shminfo
->shmmin
);
3005 __put_user(host_shminfo
->shmmni
, &target_shminfo
->shmmni
);
3006 __put_user(host_shminfo
->shmseg
, &target_shminfo
->shmseg
);
3007 __put_user(host_shminfo
->shmall
, &target_shminfo
->shmall
);
3008 unlock_user_struct(target_shminfo
, target_addr
, 1);
3012 struct target_shm_info
{
3017 abi_ulong swap_attempts
;
3018 abi_ulong swap_successes
;
3021 static inline abi_long
host_to_target_shm_info(abi_ulong target_addr
,
3022 struct shm_info
*host_shm_info
)
3024 struct target_shm_info
*target_shm_info
;
3025 if (!lock_user_struct(VERIFY_WRITE
, target_shm_info
, target_addr
, 0))
3026 return -TARGET_EFAULT
;
3027 __put_user(host_shm_info
->used_ids
, &target_shm_info
->used_ids
);
3028 __put_user(host_shm_info
->shm_tot
, &target_shm_info
->shm_tot
);
3029 __put_user(host_shm_info
->shm_rss
, &target_shm_info
->shm_rss
);
3030 __put_user(host_shm_info
->shm_swp
, &target_shm_info
->shm_swp
);
3031 __put_user(host_shm_info
->swap_attempts
, &target_shm_info
->swap_attempts
);
3032 __put_user(host_shm_info
->swap_successes
, &target_shm_info
->swap_successes
);
3033 unlock_user_struct(target_shm_info
, target_addr
, 1);
3037 static inline abi_long
do_shmctl(int shmid
, int cmd
, abi_long buf
)
3039 struct shmid_ds dsarg
;
3040 struct shminfo shminfo
;
3041 struct shm_info shm_info
;
3042 abi_long ret
= -TARGET_EINVAL
;
3050 if (target_to_host_shmid_ds(&dsarg
, buf
))
3051 return -TARGET_EFAULT
;
3052 ret
= get_errno(shmctl(shmid
, cmd
, &dsarg
));
3053 if (host_to_target_shmid_ds(buf
, &dsarg
))
3054 return -TARGET_EFAULT
;
3057 ret
= get_errno(shmctl(shmid
, cmd
, (struct shmid_ds
*)&shminfo
));
3058 if (host_to_target_shminfo(buf
, &shminfo
))
3059 return -TARGET_EFAULT
;
3062 ret
= get_errno(shmctl(shmid
, cmd
, (struct shmid_ds
*)&shm_info
));
3063 if (host_to_target_shm_info(buf
, &shm_info
))
3064 return -TARGET_EFAULT
;
3069 ret
= get_errno(shmctl(shmid
, cmd
, NULL
));
3076 static inline abi_ulong
do_shmat(int shmid
, abi_ulong shmaddr
, int shmflg
)
3080 struct shmid_ds shm_info
;
3083 /* find out the length of the shared memory segment */
3084 ret
= get_errno(shmctl(shmid
, IPC_STAT
, &shm_info
));
3085 if (is_error(ret
)) {
3086 /* can't get length, bail out */
3093 host_raddr
= shmat(shmid
, (void *)g2h(shmaddr
), shmflg
);
3095 abi_ulong mmap_start
;
3097 mmap_start
= mmap_find_vma(0, shm_info
.shm_segsz
);
3099 if (mmap_start
== -1) {
3101 host_raddr
= (void *)-1;
3103 host_raddr
= shmat(shmid
, g2h(mmap_start
), shmflg
| SHM_REMAP
);
3106 if (host_raddr
== (void *)-1) {
3108 return get_errno((long)host_raddr
);
3110 raddr
=h2g((unsigned long)host_raddr
);
3112 page_set_flags(raddr
, raddr
+ shm_info
.shm_segsz
,
3113 PAGE_VALID
| PAGE_READ
|
3114 ((shmflg
& SHM_RDONLY
)? 0 : PAGE_WRITE
));
3116 for (i
= 0; i
< N_SHM_REGIONS
; i
++) {
3117 if (shm_regions
[i
].start
== 0) {
3118 shm_regions
[i
].start
= raddr
;
3119 shm_regions
[i
].size
= shm_info
.shm_segsz
;
3129 static inline abi_long
do_shmdt(abi_ulong shmaddr
)
3133 for (i
= 0; i
< N_SHM_REGIONS
; ++i
) {
3134 if (shm_regions
[i
].start
== shmaddr
) {
3135 shm_regions
[i
].start
= 0;
3136 page_set_flags(shmaddr
, shmaddr
+ shm_regions
[i
].size
, 0);
3141 return get_errno(shmdt(g2h(shmaddr
)));
3144 #ifdef TARGET_NR_ipc
3145 /* ??? This only works with linear mappings. */
3146 /* do_ipc() must return target values and target errnos. */
3147 static abi_long
do_ipc(unsigned int call
, int first
,
3148 int second
, int third
,
3149 abi_long ptr
, abi_long fifth
)
3154 version
= call
>> 16;
3159 ret
= do_semop(first
, ptr
, second
);
3163 ret
= get_errno(semget(first
, second
, third
));
3167 ret
= do_semctl(first
, second
, third
, (union target_semun
)(abi_ulong
) ptr
);
3171 ret
= get_errno(msgget(first
, second
));
3175 ret
= do_msgsnd(first
, ptr
, second
, third
);
3179 ret
= do_msgctl(first
, second
, ptr
);
3186 struct target_ipc_kludge
{
3191 if (!lock_user_struct(VERIFY_READ
, tmp
, ptr
, 1)) {
3192 ret
= -TARGET_EFAULT
;
3196 ret
= do_msgrcv(first
, tswapal(tmp
->msgp
), second
, tswapal(tmp
->msgtyp
), third
);
3198 unlock_user_struct(tmp
, ptr
, 0);
3202 ret
= do_msgrcv(first
, ptr
, second
, fifth
, third
);
3211 raddr
= do_shmat(first
, ptr
, second
);
3212 if (is_error(raddr
))
3213 return get_errno(raddr
);
3214 if (put_user_ual(raddr
, third
))
3215 return -TARGET_EFAULT
;
3219 ret
= -TARGET_EINVAL
;
3224 ret
= do_shmdt(ptr
);
3228 /* IPC_* flag values are the same on all linux platforms */
3229 ret
= get_errno(shmget(first
, second
, third
));
3232 /* IPC_* and SHM_* command values are the same on all linux platforms */
3234 ret
= do_shmctl(first
, second
, ptr
);
3237 gemu_log("Unsupported ipc call: %d (version %d)\n", call
, version
);
3238 ret
= -TARGET_ENOSYS
;
3245 /* kernel structure types definitions */
3247 #define STRUCT(name, ...) STRUCT_ ## name,
3248 #define STRUCT_SPECIAL(name) STRUCT_ ## name,
3250 #include "syscall_types.h"
3253 #undef STRUCT_SPECIAL
3255 #define STRUCT(name, ...) static const argtype struct_ ## name ## _def[] = { __VA_ARGS__, TYPE_NULL };
3256 #define STRUCT_SPECIAL(name)
3257 #include "syscall_types.h"
3259 #undef STRUCT_SPECIAL
3261 typedef struct IOCTLEntry IOCTLEntry
;
3263 typedef abi_long
do_ioctl_fn(const IOCTLEntry
*ie
, uint8_t *buf_temp
,
3264 int fd
, abi_long cmd
, abi_long arg
);
3267 unsigned int target_cmd
;
3268 unsigned int host_cmd
;
3271 do_ioctl_fn
*do_ioctl
;
3272 const argtype arg_type
[5];
3275 #define IOC_R 0x0001
3276 #define IOC_W 0x0002
3277 #define IOC_RW (IOC_R | IOC_W)
3279 #define MAX_STRUCT_SIZE 4096
3281 #ifdef CONFIG_FIEMAP
3282 /* So fiemap access checks don't overflow on 32 bit systems.
3283 * This is very slightly smaller than the limit imposed by
3284 * the underlying kernel.
3286 #define FIEMAP_MAX_EXTENTS ((UINT_MAX - sizeof(struct fiemap)) \
3287 / sizeof(struct fiemap_extent))
3289 static abi_long
do_ioctl_fs_ioc_fiemap(const IOCTLEntry
*ie
, uint8_t *buf_temp
,
3290 int fd
, abi_long cmd
, abi_long arg
)
3292 /* The parameter for this ioctl is a struct fiemap followed
3293 * by an array of struct fiemap_extent whose size is set
3294 * in fiemap->fm_extent_count. The array is filled in by the
3297 int target_size_in
, target_size_out
;
3299 const argtype
*arg_type
= ie
->arg_type
;
3300 const argtype extent_arg_type
[] = { MK_STRUCT(STRUCT_fiemap_extent
) };
3303 int i
, extent_size
= thunk_type_size(extent_arg_type
, 0);
3307 assert(arg_type
[0] == TYPE_PTR
);
3308 assert(ie
->access
== IOC_RW
);
3310 target_size_in
= thunk_type_size(arg_type
, 0);
3311 argptr
= lock_user(VERIFY_READ
, arg
, target_size_in
, 1);
3313 return -TARGET_EFAULT
;
3315 thunk_convert(buf_temp
, argptr
, arg_type
, THUNK_HOST
);
3316 unlock_user(argptr
, arg
, 0);
3317 fm
= (struct fiemap
*)buf_temp
;
3318 if (fm
->fm_extent_count
> FIEMAP_MAX_EXTENTS
) {
3319 return -TARGET_EINVAL
;
3322 outbufsz
= sizeof (*fm
) +
3323 (sizeof(struct fiemap_extent
) * fm
->fm_extent_count
);
3325 if (outbufsz
> MAX_STRUCT_SIZE
) {
3326 /* We can't fit all the extents into the fixed size buffer.
3327 * Allocate one that is large enough and use it instead.
3329 fm
= malloc(outbufsz
);
3331 return -TARGET_ENOMEM
;
3333 memcpy(fm
, buf_temp
, sizeof(struct fiemap
));
3336 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, fm
));
3337 if (!is_error(ret
)) {
3338 target_size_out
= target_size_in
;
3339 /* An extent_count of 0 means we were only counting the extents
3340 * so there are no structs to copy
3342 if (fm
->fm_extent_count
!= 0) {
3343 target_size_out
+= fm
->fm_mapped_extents
* extent_size
;
3345 argptr
= lock_user(VERIFY_WRITE
, arg
, target_size_out
, 0);
3347 ret
= -TARGET_EFAULT
;
3349 /* Convert the struct fiemap */
3350 thunk_convert(argptr
, fm
, arg_type
, THUNK_TARGET
);
3351 if (fm
->fm_extent_count
!= 0) {
3352 p
= argptr
+ target_size_in
;
3353 /* ...and then all the struct fiemap_extents */
3354 for (i
= 0; i
< fm
->fm_mapped_extents
; i
++) {
3355 thunk_convert(p
, &fm
->fm_extents
[i
], extent_arg_type
,
3360 unlock_user(argptr
, arg
, target_size_out
);
3370 static abi_long
do_ioctl_ifconf(const IOCTLEntry
*ie
, uint8_t *buf_temp
,
3371 int fd
, abi_long cmd
, abi_long arg
)
3373 const argtype
*arg_type
= ie
->arg_type
;
3377 struct ifconf
*host_ifconf
;
3379 const argtype ifreq_arg_type
[] = { MK_STRUCT(STRUCT_sockaddr_ifreq
) };
3380 int target_ifreq_size
;
3385 abi_long target_ifc_buf
;
3389 assert(arg_type
[0] == TYPE_PTR
);
3390 assert(ie
->access
== IOC_RW
);
3393 target_size
= thunk_type_size(arg_type
, 0);
3395 argptr
= lock_user(VERIFY_READ
, arg
, target_size
, 1);
3397 return -TARGET_EFAULT
;
3398 thunk_convert(buf_temp
, argptr
, arg_type
, THUNK_HOST
);
3399 unlock_user(argptr
, arg
, 0);
3401 host_ifconf
= (struct ifconf
*)(unsigned long)buf_temp
;
3402 target_ifc_len
= host_ifconf
->ifc_len
;
3403 target_ifc_buf
= (abi_long
)(unsigned long)host_ifconf
->ifc_buf
;
3405 target_ifreq_size
= thunk_type_size(ifreq_arg_type
, 0);
3406 nb_ifreq
= target_ifc_len
/ target_ifreq_size
;
3407 host_ifc_len
= nb_ifreq
* sizeof(struct ifreq
);
3409 outbufsz
= sizeof(*host_ifconf
) + host_ifc_len
;
3410 if (outbufsz
> MAX_STRUCT_SIZE
) {
3411 /* We can't fit all the extents into the fixed size buffer.
3412 * Allocate one that is large enough and use it instead.
3414 host_ifconf
= malloc(outbufsz
);
3416 return -TARGET_ENOMEM
;
3418 memcpy(host_ifconf
, buf_temp
, sizeof(*host_ifconf
));
3421 host_ifc_buf
= (char*)host_ifconf
+ sizeof(*host_ifconf
);
3423 host_ifconf
->ifc_len
= host_ifc_len
;
3424 host_ifconf
->ifc_buf
= host_ifc_buf
;
3426 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, host_ifconf
));
3427 if (!is_error(ret
)) {
3428 /* convert host ifc_len to target ifc_len */
3430 nb_ifreq
= host_ifconf
->ifc_len
/ sizeof(struct ifreq
);
3431 target_ifc_len
= nb_ifreq
* target_ifreq_size
;
3432 host_ifconf
->ifc_len
= target_ifc_len
;
3434 /* restore target ifc_buf */
3436 host_ifconf
->ifc_buf
= (char *)(unsigned long)target_ifc_buf
;
3438 /* copy struct ifconf to target user */
3440 argptr
= lock_user(VERIFY_WRITE
, arg
, target_size
, 0);
3442 return -TARGET_EFAULT
;
3443 thunk_convert(argptr
, host_ifconf
, arg_type
, THUNK_TARGET
);
3444 unlock_user(argptr
, arg
, target_size
);
3446 /* copy ifreq[] to target user */
3448 argptr
= lock_user(VERIFY_WRITE
, target_ifc_buf
, target_ifc_len
, 0);
3449 for (i
= 0; i
< nb_ifreq
; i
++) {
3450 thunk_convert(argptr
+ i
* target_ifreq_size
,
3451 host_ifc_buf
+ i
* sizeof(struct ifreq
),
3452 ifreq_arg_type
, THUNK_TARGET
);
3454 unlock_user(argptr
, target_ifc_buf
, target_ifc_len
);
3464 static abi_long
do_ioctl_dm(const IOCTLEntry
*ie
, uint8_t *buf_temp
, int fd
,
3465 abi_long cmd
, abi_long arg
)
3468 struct dm_ioctl
*host_dm
;
3469 abi_long guest_data
;
3470 uint32_t guest_data_size
;
3472 const argtype
*arg_type
= ie
->arg_type
;
3474 void *big_buf
= NULL
;
3478 target_size
= thunk_type_size(arg_type
, 0);
3479 argptr
= lock_user(VERIFY_READ
, arg
, target_size
, 1);
3481 ret
= -TARGET_EFAULT
;
3484 thunk_convert(buf_temp
, argptr
, arg_type
, THUNK_HOST
);
3485 unlock_user(argptr
, arg
, 0);
3487 /* buf_temp is too small, so fetch things into a bigger buffer */
3488 big_buf
= g_malloc0(((struct dm_ioctl
*)buf_temp
)->data_size
* 2);
3489 memcpy(big_buf
, buf_temp
, target_size
);
3493 guest_data
= arg
+ host_dm
->data_start
;
3494 if ((guest_data
- arg
) < 0) {
3498 guest_data_size
= host_dm
->data_size
- host_dm
->data_start
;
3499 host_data
= (char*)host_dm
+ host_dm
->data_start
;
3501 argptr
= lock_user(VERIFY_READ
, guest_data
, guest_data_size
, 1);
3502 switch (ie
->host_cmd
) {
3504 case DM_LIST_DEVICES
:
3507 case DM_DEV_SUSPEND
:
3510 case DM_TABLE_STATUS
:
3511 case DM_TABLE_CLEAR
:
3513 case DM_LIST_VERSIONS
:
3517 case DM_DEV_SET_GEOMETRY
:
3518 /* data contains only strings */
3519 memcpy(host_data
, argptr
, guest_data_size
);
3522 memcpy(host_data
, argptr
, guest_data_size
);
3523 *(uint64_t*)host_data
= tswap64(*(uint64_t*)argptr
);
3527 void *gspec
= argptr
;
3528 void *cur_data
= host_data
;
3529 const argtype arg_type
[] = { MK_STRUCT(STRUCT_dm_target_spec
) };
3530 int spec_size
= thunk_type_size(arg_type
, 0);
3533 for (i
= 0; i
< host_dm
->target_count
; i
++) {
3534 struct dm_target_spec
*spec
= cur_data
;
3538 thunk_convert(spec
, gspec
, arg_type
, THUNK_HOST
);
3539 slen
= strlen((char*)gspec
+ spec_size
) + 1;
3541 spec
->next
= sizeof(*spec
) + slen
;
3542 strcpy((char*)&spec
[1], gspec
+ spec_size
);
3544 cur_data
+= spec
->next
;
3549 ret
= -TARGET_EINVAL
;
3552 unlock_user(argptr
, guest_data
, 0);
3554 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, buf_temp
));
3555 if (!is_error(ret
)) {
3556 guest_data
= arg
+ host_dm
->data_start
;
3557 guest_data_size
= host_dm
->data_size
- host_dm
->data_start
;
3558 argptr
= lock_user(VERIFY_WRITE
, guest_data
, guest_data_size
, 0);
3559 switch (ie
->host_cmd
) {
3564 case DM_DEV_SUSPEND
:
3567 case DM_TABLE_CLEAR
:
3569 case DM_DEV_SET_GEOMETRY
:
3570 /* no return data */
3572 case DM_LIST_DEVICES
:
3574 struct dm_name_list
*nl
= (void*)host_dm
+ host_dm
->data_start
;
3575 uint32_t remaining_data
= guest_data_size
;
3576 void *cur_data
= argptr
;
3577 const argtype arg_type
[] = { MK_STRUCT(STRUCT_dm_name_list
) };
3578 int nl_size
= 12; /* can't use thunk_size due to alignment */
3581 uint32_t next
= nl
->next
;
3583 nl
->next
= nl_size
+ (strlen(nl
->name
) + 1);
3585 if (remaining_data
< nl
->next
) {
3586 host_dm
->flags
|= DM_BUFFER_FULL_FLAG
;
3589 thunk_convert(cur_data
, nl
, arg_type
, THUNK_TARGET
);
3590 strcpy(cur_data
+ nl_size
, nl
->name
);
3591 cur_data
+= nl
->next
;
3592 remaining_data
-= nl
->next
;
3596 nl
= (void*)nl
+ next
;
3601 case DM_TABLE_STATUS
:
3603 struct dm_target_spec
*spec
= (void*)host_dm
+ host_dm
->data_start
;
3604 void *cur_data
= argptr
;
3605 const argtype arg_type
[] = { MK_STRUCT(STRUCT_dm_target_spec
) };
3606 int spec_size
= thunk_type_size(arg_type
, 0);
3609 for (i
= 0; i
< host_dm
->target_count
; i
++) {
3610 uint32_t next
= spec
->next
;
3611 int slen
= strlen((char*)&spec
[1]) + 1;
3612 spec
->next
= (cur_data
- argptr
) + spec_size
+ slen
;
3613 if (guest_data_size
< spec
->next
) {
3614 host_dm
->flags
|= DM_BUFFER_FULL_FLAG
;
3617 thunk_convert(cur_data
, spec
, arg_type
, THUNK_TARGET
);
3618 strcpy(cur_data
+ spec_size
, (char*)&spec
[1]);
3619 cur_data
= argptr
+ spec
->next
;
3620 spec
= (void*)host_dm
+ host_dm
->data_start
+ next
;
3626 void *hdata
= (void*)host_dm
+ host_dm
->data_start
;
3627 int count
= *(uint32_t*)hdata
;
3628 uint64_t *hdev
= hdata
+ 8;
3629 uint64_t *gdev
= argptr
+ 8;
3632 *(uint32_t*)argptr
= tswap32(count
);
3633 for (i
= 0; i
< count
; i
++) {
3634 *gdev
= tswap64(*hdev
);
3640 case DM_LIST_VERSIONS
:
3642 struct dm_target_versions
*vers
= (void*)host_dm
+ host_dm
->data_start
;
3643 uint32_t remaining_data
= guest_data_size
;
3644 void *cur_data
= argptr
;
3645 const argtype arg_type
[] = { MK_STRUCT(STRUCT_dm_target_versions
) };
3646 int vers_size
= thunk_type_size(arg_type
, 0);
3649 uint32_t next
= vers
->next
;
3651 vers
->next
= vers_size
+ (strlen(vers
->name
) + 1);
3653 if (remaining_data
< vers
->next
) {
3654 host_dm
->flags
|= DM_BUFFER_FULL_FLAG
;
3657 thunk_convert(cur_data
, vers
, arg_type
, THUNK_TARGET
);
3658 strcpy(cur_data
+ vers_size
, vers
->name
);
3659 cur_data
+= vers
->next
;
3660 remaining_data
-= vers
->next
;
3664 vers
= (void*)vers
+ next
;
3669 ret
= -TARGET_EINVAL
;
3672 unlock_user(argptr
, guest_data
, guest_data_size
);
3674 argptr
= lock_user(VERIFY_WRITE
, arg
, target_size
, 0);
3676 ret
= -TARGET_EFAULT
;
3679 thunk_convert(argptr
, buf_temp
, arg_type
, THUNK_TARGET
);
3680 unlock_user(argptr
, arg
, target_size
);
3687 static abi_long
do_ioctl_rt(const IOCTLEntry
*ie
, uint8_t *buf_temp
,
3688 int fd
, abi_long cmd
, abi_long arg
)
3690 const argtype
*arg_type
= ie
->arg_type
;
3691 const StructEntry
*se
;
3692 const argtype
*field_types
;
3693 const int *dst_offsets
, *src_offsets
;
3696 abi_ulong
*target_rt_dev_ptr
;
3697 unsigned long *host_rt_dev_ptr
;
3701 assert(ie
->access
== IOC_W
);
3702 assert(*arg_type
== TYPE_PTR
);
3704 assert(*arg_type
== TYPE_STRUCT
);
3705 target_size
= thunk_type_size(arg_type
, 0);
3706 argptr
= lock_user(VERIFY_READ
, arg
, target_size
, 1);
3708 return -TARGET_EFAULT
;
3711 assert(*arg_type
== (int)STRUCT_rtentry
);
3712 se
= struct_entries
+ *arg_type
++;
3713 assert(se
->convert
[0] == NULL
);
3714 /* convert struct here to be able to catch rt_dev string */
3715 field_types
= se
->field_types
;
3716 dst_offsets
= se
->field_offsets
[THUNK_HOST
];
3717 src_offsets
= se
->field_offsets
[THUNK_TARGET
];
3718 for (i
= 0; i
< se
->nb_fields
; i
++) {
3719 if (dst_offsets
[i
] == offsetof(struct rtentry
, rt_dev
)) {
3720 assert(*field_types
== TYPE_PTRVOID
);
3721 target_rt_dev_ptr
= (abi_ulong
*)(argptr
+ src_offsets
[i
]);
3722 host_rt_dev_ptr
= (unsigned long *)(buf_temp
+ dst_offsets
[i
]);
3723 if (*target_rt_dev_ptr
!= 0) {
3724 *host_rt_dev_ptr
= (unsigned long)lock_user_string(
3725 tswapal(*target_rt_dev_ptr
));
3726 if (!*host_rt_dev_ptr
) {
3727 unlock_user(argptr
, arg
, 0);
3728 return -TARGET_EFAULT
;
3731 *host_rt_dev_ptr
= 0;
3736 field_types
= thunk_convert(buf_temp
+ dst_offsets
[i
],
3737 argptr
+ src_offsets
[i
],
3738 field_types
, THUNK_HOST
);
3740 unlock_user(argptr
, arg
, 0);
3742 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, buf_temp
));
3743 if (*host_rt_dev_ptr
!= 0) {
3744 unlock_user((void *)*host_rt_dev_ptr
,
3745 *target_rt_dev_ptr
, 0);
3750 static IOCTLEntry ioctl_entries
[] = {
3751 #define IOCTL(cmd, access, ...) \
3752 { TARGET_ ## cmd, cmd, #cmd, access, 0, { __VA_ARGS__ } },
3753 #define IOCTL_SPECIAL(cmd, access, dofn, ...) \
3754 { TARGET_ ## cmd, cmd, #cmd, access, dofn, { __VA_ARGS__ } },
3759 /* ??? Implement proper locking for ioctls. */
3760 /* do_ioctl() Must return target values and target errnos. */
3761 static abi_long
do_ioctl(int fd
, abi_long cmd
, abi_long arg
)
3763 const IOCTLEntry
*ie
;
3764 const argtype
*arg_type
;
3766 uint8_t buf_temp
[MAX_STRUCT_SIZE
];
3772 if (ie
->target_cmd
== 0) {
3773 gemu_log("Unsupported ioctl: cmd=0x%04lx\n", (long)cmd
);
3774 return -TARGET_ENOSYS
;
3776 if (ie
->target_cmd
== cmd
)
3780 arg_type
= ie
->arg_type
;
3782 gemu_log("ioctl: cmd=0x%04lx (%s)\n", (long)cmd
, ie
->name
);
3785 return ie
->do_ioctl(ie
, buf_temp
, fd
, cmd
, arg
);
3788 switch(arg_type
[0]) {
3791 ret
= get_errno(ioctl(fd
, ie
->host_cmd
));
3796 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, arg
));
3800 target_size
= thunk_type_size(arg_type
, 0);
3801 switch(ie
->access
) {
3803 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, buf_temp
));
3804 if (!is_error(ret
)) {
3805 argptr
= lock_user(VERIFY_WRITE
, arg
, target_size
, 0);
3807 return -TARGET_EFAULT
;
3808 thunk_convert(argptr
, buf_temp
, arg_type
, THUNK_TARGET
);
3809 unlock_user(argptr
, arg
, target_size
);
3813 argptr
= lock_user(VERIFY_READ
, arg
, target_size
, 1);
3815 return -TARGET_EFAULT
;
3816 thunk_convert(buf_temp
, argptr
, arg_type
, THUNK_HOST
);
3817 unlock_user(argptr
, arg
, 0);
3818 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, buf_temp
));
3822 argptr
= lock_user(VERIFY_READ
, arg
, target_size
, 1);
3824 return -TARGET_EFAULT
;
3825 thunk_convert(buf_temp
, argptr
, arg_type
, THUNK_HOST
);
3826 unlock_user(argptr
, arg
, 0);
3827 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, buf_temp
));
3828 if (!is_error(ret
)) {
3829 argptr
= lock_user(VERIFY_WRITE
, arg
, target_size
, 0);
3831 return -TARGET_EFAULT
;
3832 thunk_convert(argptr
, buf_temp
, arg_type
, THUNK_TARGET
);
3833 unlock_user(argptr
, arg
, target_size
);
3839 gemu_log("Unsupported ioctl type: cmd=0x%04lx type=%d\n",
3840 (long)cmd
, arg_type
[0]);
3841 ret
= -TARGET_ENOSYS
;
3847 static const bitmask_transtbl iflag_tbl
[] = {
3848 { TARGET_IGNBRK
, TARGET_IGNBRK
, IGNBRK
, IGNBRK
},
3849 { TARGET_BRKINT
, TARGET_BRKINT
, BRKINT
, BRKINT
},
3850 { TARGET_IGNPAR
, TARGET_IGNPAR
, IGNPAR
, IGNPAR
},
3851 { TARGET_PARMRK
, TARGET_PARMRK
, PARMRK
, PARMRK
},
3852 { TARGET_INPCK
, TARGET_INPCK
, INPCK
, INPCK
},
3853 { TARGET_ISTRIP
, TARGET_ISTRIP
, ISTRIP
, ISTRIP
},
3854 { TARGET_INLCR
, TARGET_INLCR
, INLCR
, INLCR
},
3855 { TARGET_IGNCR
, TARGET_IGNCR
, IGNCR
, IGNCR
},
3856 { TARGET_ICRNL
, TARGET_ICRNL
, ICRNL
, ICRNL
},
3857 { TARGET_IUCLC
, TARGET_IUCLC
, IUCLC
, IUCLC
},
3858 { TARGET_IXON
, TARGET_IXON
, IXON
, IXON
},
3859 { TARGET_IXANY
, TARGET_IXANY
, IXANY
, IXANY
},
3860 { TARGET_IXOFF
, TARGET_IXOFF
, IXOFF
, IXOFF
},
3861 { TARGET_IMAXBEL
, TARGET_IMAXBEL
, IMAXBEL
, IMAXBEL
},
3865 static const bitmask_transtbl oflag_tbl
[] = {
3866 { TARGET_OPOST
, TARGET_OPOST
, OPOST
, OPOST
},
3867 { TARGET_OLCUC
, TARGET_OLCUC
, OLCUC
, OLCUC
},
3868 { TARGET_ONLCR
, TARGET_ONLCR
, ONLCR
, ONLCR
},
3869 { TARGET_OCRNL
, TARGET_OCRNL
, OCRNL
, OCRNL
},
3870 { TARGET_ONOCR
, TARGET_ONOCR
, ONOCR
, ONOCR
},
3871 { TARGET_ONLRET
, TARGET_ONLRET
, ONLRET
, ONLRET
},
3872 { TARGET_OFILL
, TARGET_OFILL
, OFILL
, OFILL
},
3873 { TARGET_OFDEL
, TARGET_OFDEL
, OFDEL
, OFDEL
},
3874 { TARGET_NLDLY
, TARGET_NL0
, NLDLY
, NL0
},
3875 { TARGET_NLDLY
, TARGET_NL1
, NLDLY
, NL1
},
3876 { TARGET_CRDLY
, TARGET_CR0
, CRDLY
, CR0
},
3877 { TARGET_CRDLY
, TARGET_CR1
, CRDLY
, CR1
},
3878 { TARGET_CRDLY
, TARGET_CR2
, CRDLY
, CR2
},
3879 { TARGET_CRDLY
, TARGET_CR3
, CRDLY
, CR3
},
3880 { TARGET_TABDLY
, TARGET_TAB0
, TABDLY
, TAB0
},
3881 { TARGET_TABDLY
, TARGET_TAB1
, TABDLY
, TAB1
},
3882 { TARGET_TABDLY
, TARGET_TAB2
, TABDLY
, TAB2
},
3883 { TARGET_TABDLY
, TARGET_TAB3
, TABDLY
, TAB3
},
3884 { TARGET_BSDLY
, TARGET_BS0
, BSDLY
, BS0
},
3885 { TARGET_BSDLY
, TARGET_BS1
, BSDLY
, BS1
},
3886 { TARGET_VTDLY
, TARGET_VT0
, VTDLY
, VT0
},
3887 { TARGET_VTDLY
, TARGET_VT1
, VTDLY
, VT1
},
3888 { TARGET_FFDLY
, TARGET_FF0
, FFDLY
, FF0
},
3889 { TARGET_FFDLY
, TARGET_FF1
, FFDLY
, FF1
},
3893 static const bitmask_transtbl cflag_tbl
[] = {
3894 { TARGET_CBAUD
, TARGET_B0
, CBAUD
, B0
},
3895 { TARGET_CBAUD
, TARGET_B50
, CBAUD
, B50
},
3896 { TARGET_CBAUD
, TARGET_B75
, CBAUD
, B75
},
3897 { TARGET_CBAUD
, TARGET_B110
, CBAUD
, B110
},
3898 { TARGET_CBAUD
, TARGET_B134
, CBAUD
, B134
},
3899 { TARGET_CBAUD
, TARGET_B150
, CBAUD
, B150
},
3900 { TARGET_CBAUD
, TARGET_B200
, CBAUD
, B200
},
3901 { TARGET_CBAUD
, TARGET_B300
, CBAUD
, B300
},
3902 { TARGET_CBAUD
, TARGET_B600
, CBAUD
, B600
},
3903 { TARGET_CBAUD
, TARGET_B1200
, CBAUD
, B1200
},
3904 { TARGET_CBAUD
, TARGET_B1800
, CBAUD
, B1800
},
3905 { TARGET_CBAUD
, TARGET_B2400
, CBAUD
, B2400
},
3906 { TARGET_CBAUD
, TARGET_B4800
, CBAUD
, B4800
},
3907 { TARGET_CBAUD
, TARGET_B9600
, CBAUD
, B9600
},
3908 { TARGET_CBAUD
, TARGET_B19200
, CBAUD
, B19200
},
3909 { TARGET_CBAUD
, TARGET_B38400
, CBAUD
, B38400
},
3910 { TARGET_CBAUD
, TARGET_B57600
, CBAUD
, B57600
},
3911 { TARGET_CBAUD
, TARGET_B115200
, CBAUD
, B115200
},
3912 { TARGET_CBAUD
, TARGET_B230400
, CBAUD
, B230400
},
3913 { TARGET_CBAUD
, TARGET_B460800
, CBAUD
, B460800
},
3914 { TARGET_CSIZE
, TARGET_CS5
, CSIZE
, CS5
},
3915 { TARGET_CSIZE
, TARGET_CS6
, CSIZE
, CS6
},
3916 { TARGET_CSIZE
, TARGET_CS7
, CSIZE
, CS7
},
3917 { TARGET_CSIZE
, TARGET_CS8
, CSIZE
, CS8
},
3918 { TARGET_CSTOPB
, TARGET_CSTOPB
, CSTOPB
, CSTOPB
},
3919 { TARGET_CREAD
, TARGET_CREAD
, CREAD
, CREAD
},
3920 { TARGET_PARENB
, TARGET_PARENB
, PARENB
, PARENB
},
3921 { TARGET_PARODD
, TARGET_PARODD
, PARODD
, PARODD
},
3922 { TARGET_HUPCL
, TARGET_HUPCL
, HUPCL
, HUPCL
},
3923 { TARGET_CLOCAL
, TARGET_CLOCAL
, CLOCAL
, CLOCAL
},
3924 { TARGET_CRTSCTS
, TARGET_CRTSCTS
, CRTSCTS
, CRTSCTS
},
3928 static const bitmask_transtbl lflag_tbl
[] = {
3929 { TARGET_ISIG
, TARGET_ISIG
, ISIG
, ISIG
},
3930 { TARGET_ICANON
, TARGET_ICANON
, ICANON
, ICANON
},
3931 { TARGET_XCASE
, TARGET_XCASE
, XCASE
, XCASE
},
3932 { TARGET_ECHO
, TARGET_ECHO
, ECHO
, ECHO
},
3933 { TARGET_ECHOE
, TARGET_ECHOE
, ECHOE
, ECHOE
},
3934 { TARGET_ECHOK
, TARGET_ECHOK
, ECHOK
, ECHOK
},
3935 { TARGET_ECHONL
, TARGET_ECHONL
, ECHONL
, ECHONL
},
3936 { TARGET_NOFLSH
, TARGET_NOFLSH
, NOFLSH
, NOFLSH
},
3937 { TARGET_TOSTOP
, TARGET_TOSTOP
, TOSTOP
, TOSTOP
},
3938 { TARGET_ECHOCTL
, TARGET_ECHOCTL
, ECHOCTL
, ECHOCTL
},
3939 { TARGET_ECHOPRT
, TARGET_ECHOPRT
, ECHOPRT
, ECHOPRT
},
3940 { TARGET_ECHOKE
, TARGET_ECHOKE
, ECHOKE
, ECHOKE
},
3941 { TARGET_FLUSHO
, TARGET_FLUSHO
, FLUSHO
, FLUSHO
},
3942 { TARGET_PENDIN
, TARGET_PENDIN
, PENDIN
, PENDIN
},
3943 { TARGET_IEXTEN
, TARGET_IEXTEN
, IEXTEN
, IEXTEN
},
3947 static void target_to_host_termios (void *dst
, const void *src
)
3949 struct host_termios
*host
= dst
;
3950 const struct target_termios
*target
= src
;
3953 target_to_host_bitmask(tswap32(target
->c_iflag
), iflag_tbl
);
3955 target_to_host_bitmask(tswap32(target
->c_oflag
), oflag_tbl
);
3957 target_to_host_bitmask(tswap32(target
->c_cflag
), cflag_tbl
);
3959 target_to_host_bitmask(tswap32(target
->c_lflag
), lflag_tbl
);
3960 host
->c_line
= target
->c_line
;
3962 memset(host
->c_cc
, 0, sizeof(host
->c_cc
));
3963 host
->c_cc
[VINTR
] = target
->c_cc
[TARGET_VINTR
];
3964 host
->c_cc
[VQUIT
] = target
->c_cc
[TARGET_VQUIT
];
3965 host
->c_cc
[VERASE
] = target
->c_cc
[TARGET_VERASE
];
3966 host
->c_cc
[VKILL
] = target
->c_cc
[TARGET_VKILL
];
3967 host
->c_cc
[VEOF
] = target
->c_cc
[TARGET_VEOF
];
3968 host
->c_cc
[VTIME
] = target
->c_cc
[TARGET_VTIME
];
3969 host
->c_cc
[VMIN
] = target
->c_cc
[TARGET_VMIN
];
3970 host
->c_cc
[VSWTC
] = target
->c_cc
[TARGET_VSWTC
];
3971 host
->c_cc
[VSTART
] = target
->c_cc
[TARGET_VSTART
];
3972 host
->c_cc
[VSTOP
] = target
->c_cc
[TARGET_VSTOP
];
3973 host
->c_cc
[VSUSP
] = target
->c_cc
[TARGET_VSUSP
];
3974 host
->c_cc
[VEOL
] = target
->c_cc
[TARGET_VEOL
];
3975 host
->c_cc
[VREPRINT
] = target
->c_cc
[TARGET_VREPRINT
];
3976 host
->c_cc
[VDISCARD
] = target
->c_cc
[TARGET_VDISCARD
];
3977 host
->c_cc
[VWERASE
] = target
->c_cc
[TARGET_VWERASE
];
3978 host
->c_cc
[VLNEXT
] = target
->c_cc
[TARGET_VLNEXT
];
3979 host
->c_cc
[VEOL2
] = target
->c_cc
[TARGET_VEOL2
];
3982 static void host_to_target_termios (void *dst
, const void *src
)
3984 struct target_termios
*target
= dst
;
3985 const struct host_termios
*host
= src
;
3988 tswap32(host_to_target_bitmask(host
->c_iflag
, iflag_tbl
));
3990 tswap32(host_to_target_bitmask(host
->c_oflag
, oflag_tbl
));
3992 tswap32(host_to_target_bitmask(host
->c_cflag
, cflag_tbl
));
3994 tswap32(host_to_target_bitmask(host
->c_lflag
, lflag_tbl
));
3995 target
->c_line
= host
->c_line
;
3997 memset(target
->c_cc
, 0, sizeof(target
->c_cc
));
3998 target
->c_cc
[TARGET_VINTR
] = host
->c_cc
[VINTR
];
3999 target
->c_cc
[TARGET_VQUIT
] = host
->c_cc
[VQUIT
];
4000 target
->c_cc
[TARGET_VERASE
] = host
->c_cc
[VERASE
];
4001 target
->c_cc
[TARGET_VKILL
] = host
->c_cc
[VKILL
];
4002 target
->c_cc
[TARGET_VEOF
] = host
->c_cc
[VEOF
];
4003 target
->c_cc
[TARGET_VTIME
] = host
->c_cc
[VTIME
];
4004 target
->c_cc
[TARGET_VMIN
] = host
->c_cc
[VMIN
];
4005 target
->c_cc
[TARGET_VSWTC
] = host
->c_cc
[VSWTC
];
4006 target
->c_cc
[TARGET_VSTART
] = host
->c_cc
[VSTART
];
4007 target
->c_cc
[TARGET_VSTOP
] = host
->c_cc
[VSTOP
];
4008 target
->c_cc
[TARGET_VSUSP
] = host
->c_cc
[VSUSP
];
4009 target
->c_cc
[TARGET_VEOL
] = host
->c_cc
[VEOL
];
4010 target
->c_cc
[TARGET_VREPRINT
] = host
->c_cc
[VREPRINT
];
4011 target
->c_cc
[TARGET_VDISCARD
] = host
->c_cc
[VDISCARD
];
4012 target
->c_cc
[TARGET_VWERASE
] = host
->c_cc
[VWERASE
];
4013 target
->c_cc
[TARGET_VLNEXT
] = host
->c_cc
[VLNEXT
];
4014 target
->c_cc
[TARGET_VEOL2
] = host
->c_cc
[VEOL2
];
4017 static const StructEntry struct_termios_def
= {
4018 .convert
= { host_to_target_termios
, target_to_host_termios
},
4019 .size
= { sizeof(struct target_termios
), sizeof(struct host_termios
) },
4020 .align
= { __alignof__(struct target_termios
), __alignof__(struct host_termios
) },
4023 static bitmask_transtbl mmap_flags_tbl
[] = {
4024 { TARGET_MAP_SHARED
, TARGET_MAP_SHARED
, MAP_SHARED
, MAP_SHARED
},
4025 { TARGET_MAP_PRIVATE
, TARGET_MAP_PRIVATE
, MAP_PRIVATE
, MAP_PRIVATE
},
4026 { TARGET_MAP_FIXED
, TARGET_MAP_FIXED
, MAP_FIXED
, MAP_FIXED
},
4027 { TARGET_MAP_ANONYMOUS
, TARGET_MAP_ANONYMOUS
, MAP_ANONYMOUS
, MAP_ANONYMOUS
},
4028 { TARGET_MAP_GROWSDOWN
, TARGET_MAP_GROWSDOWN
, MAP_GROWSDOWN
, MAP_GROWSDOWN
},
4029 { TARGET_MAP_DENYWRITE
, TARGET_MAP_DENYWRITE
, MAP_DENYWRITE
, MAP_DENYWRITE
},
4030 { TARGET_MAP_EXECUTABLE
, TARGET_MAP_EXECUTABLE
, MAP_EXECUTABLE
, MAP_EXECUTABLE
},
4031 { TARGET_MAP_LOCKED
, TARGET_MAP_LOCKED
, MAP_LOCKED
, MAP_LOCKED
},
4035 #if defined(TARGET_I386)
4037 /* NOTE: there is really one LDT for all the threads */
4038 static uint8_t *ldt_table
;
4040 static abi_long
read_ldt(abi_ulong ptr
, unsigned long bytecount
)
4047 size
= TARGET_LDT_ENTRIES
* TARGET_LDT_ENTRY_SIZE
;
4048 if (size
> bytecount
)
4050 p
= lock_user(VERIFY_WRITE
, ptr
, size
, 0);
4052 return -TARGET_EFAULT
;
4053 /* ??? Should this by byteswapped? */
4054 memcpy(p
, ldt_table
, size
);
4055 unlock_user(p
, ptr
, size
);
4059 /* XXX: add locking support */
4060 static abi_long
write_ldt(CPUX86State
*env
,
4061 abi_ulong ptr
, unsigned long bytecount
, int oldmode
)
4063 struct target_modify_ldt_ldt_s ldt_info
;
4064 struct target_modify_ldt_ldt_s
*target_ldt_info
;
4065 int seg_32bit
, contents
, read_exec_only
, limit_in_pages
;
4066 int seg_not_present
, useable
, lm
;
4067 uint32_t *lp
, entry_1
, entry_2
;
4069 if (bytecount
!= sizeof(ldt_info
))
4070 return -TARGET_EINVAL
;
4071 if (!lock_user_struct(VERIFY_READ
, target_ldt_info
, ptr
, 1))
4072 return -TARGET_EFAULT
;
4073 ldt_info
.entry_number
= tswap32(target_ldt_info
->entry_number
);
4074 ldt_info
.base_addr
= tswapal(target_ldt_info
->base_addr
);
4075 ldt_info
.limit
= tswap32(target_ldt_info
->limit
);
4076 ldt_info
.flags
= tswap32(target_ldt_info
->flags
);
4077 unlock_user_struct(target_ldt_info
, ptr
, 0);
4079 if (ldt_info
.entry_number
>= TARGET_LDT_ENTRIES
)
4080 return -TARGET_EINVAL
;
4081 seg_32bit
= ldt_info
.flags
& 1;
4082 contents
= (ldt_info
.flags
>> 1) & 3;
4083 read_exec_only
= (ldt_info
.flags
>> 3) & 1;
4084 limit_in_pages
= (ldt_info
.flags
>> 4) & 1;
4085 seg_not_present
= (ldt_info
.flags
>> 5) & 1;
4086 useable
= (ldt_info
.flags
>> 6) & 1;
4090 lm
= (ldt_info
.flags
>> 7) & 1;
4092 if (contents
== 3) {
4094 return -TARGET_EINVAL
;
4095 if (seg_not_present
== 0)
4096 return -TARGET_EINVAL
;
4098 /* allocate the LDT */
4100 env
->ldt
.base
= target_mmap(0,
4101 TARGET_LDT_ENTRIES
* TARGET_LDT_ENTRY_SIZE
,
4102 PROT_READ
|PROT_WRITE
,
4103 MAP_ANONYMOUS
|MAP_PRIVATE
, -1, 0);
4104 if (env
->ldt
.base
== -1)
4105 return -TARGET_ENOMEM
;
4106 memset(g2h(env
->ldt
.base
), 0,
4107 TARGET_LDT_ENTRIES
* TARGET_LDT_ENTRY_SIZE
);
4108 env
->ldt
.limit
= 0xffff;
4109 ldt_table
= g2h(env
->ldt
.base
);
4112 /* NOTE: same code as Linux kernel */
4113 /* Allow LDTs to be cleared by the user. */
4114 if (ldt_info
.base_addr
== 0 && ldt_info
.limit
== 0) {
4117 read_exec_only
== 1 &&
4119 limit_in_pages
== 0 &&
4120 seg_not_present
== 1 &&
4128 entry_1
= ((ldt_info
.base_addr
& 0x0000ffff) << 16) |
4129 (ldt_info
.limit
& 0x0ffff);
4130 entry_2
= (ldt_info
.base_addr
& 0xff000000) |
4131 ((ldt_info
.base_addr
& 0x00ff0000) >> 16) |
4132 (ldt_info
.limit
& 0xf0000) |
4133 ((read_exec_only
^ 1) << 9) |
4135 ((seg_not_present
^ 1) << 15) |
4137 (limit_in_pages
<< 23) |
4141 entry_2
|= (useable
<< 20);
4143 /* Install the new entry ... */
4145 lp
= (uint32_t *)(ldt_table
+ (ldt_info
.entry_number
<< 3));
4146 lp
[0] = tswap32(entry_1
);
4147 lp
[1] = tswap32(entry_2
);
4151 /* specific and weird i386 syscalls */
4152 static abi_long
do_modify_ldt(CPUX86State
*env
, int func
, abi_ulong ptr
,
4153 unsigned long bytecount
)
4159 ret
= read_ldt(ptr
, bytecount
);
4162 ret
= write_ldt(env
, ptr
, bytecount
, 1);
4165 ret
= write_ldt(env
, ptr
, bytecount
, 0);
4168 ret
= -TARGET_ENOSYS
;
4174 #if defined(TARGET_I386) && defined(TARGET_ABI32)
4175 abi_long
do_set_thread_area(CPUX86State
*env
, abi_ulong ptr
)
4177 uint64_t *gdt_table
= g2h(env
->gdt
.base
);
4178 struct target_modify_ldt_ldt_s ldt_info
;
4179 struct target_modify_ldt_ldt_s
*target_ldt_info
;
4180 int seg_32bit
, contents
, read_exec_only
, limit_in_pages
;
4181 int seg_not_present
, useable
, lm
;
4182 uint32_t *lp
, entry_1
, entry_2
;
4185 lock_user_struct(VERIFY_WRITE
, target_ldt_info
, ptr
, 1);
4186 if (!target_ldt_info
)
4187 return -TARGET_EFAULT
;
4188 ldt_info
.entry_number
= tswap32(target_ldt_info
->entry_number
);
4189 ldt_info
.base_addr
= tswapal(target_ldt_info
->base_addr
);
4190 ldt_info
.limit
= tswap32(target_ldt_info
->limit
);
4191 ldt_info
.flags
= tswap32(target_ldt_info
->flags
);
4192 if (ldt_info
.entry_number
== -1) {
4193 for (i
=TARGET_GDT_ENTRY_TLS_MIN
; i
<=TARGET_GDT_ENTRY_TLS_MAX
; i
++) {
4194 if (gdt_table
[i
] == 0) {
4195 ldt_info
.entry_number
= i
;
4196 target_ldt_info
->entry_number
= tswap32(i
);
4201 unlock_user_struct(target_ldt_info
, ptr
, 1);
4203 if (ldt_info
.entry_number
< TARGET_GDT_ENTRY_TLS_MIN
||
4204 ldt_info
.entry_number
> TARGET_GDT_ENTRY_TLS_MAX
)
4205 return -TARGET_EINVAL
;
4206 seg_32bit
= ldt_info
.flags
& 1;
4207 contents
= (ldt_info
.flags
>> 1) & 3;
4208 read_exec_only
= (ldt_info
.flags
>> 3) & 1;
4209 limit_in_pages
= (ldt_info
.flags
>> 4) & 1;
4210 seg_not_present
= (ldt_info
.flags
>> 5) & 1;
4211 useable
= (ldt_info
.flags
>> 6) & 1;
4215 lm
= (ldt_info
.flags
>> 7) & 1;
4218 if (contents
== 3) {
4219 if (seg_not_present
== 0)
4220 return -TARGET_EINVAL
;
4223 /* NOTE: same code as Linux kernel */
4224 /* Allow LDTs to be cleared by the user. */
4225 if (ldt_info
.base_addr
== 0 && ldt_info
.limit
== 0) {
4226 if ((contents
== 0 &&
4227 read_exec_only
== 1 &&
4229 limit_in_pages
== 0 &&
4230 seg_not_present
== 1 &&
4238 entry_1
= ((ldt_info
.base_addr
& 0x0000ffff) << 16) |
4239 (ldt_info
.limit
& 0x0ffff);
4240 entry_2
= (ldt_info
.base_addr
& 0xff000000) |
4241 ((ldt_info
.base_addr
& 0x00ff0000) >> 16) |
4242 (ldt_info
.limit
& 0xf0000) |
4243 ((read_exec_only
^ 1) << 9) |
4245 ((seg_not_present
^ 1) << 15) |
4247 (limit_in_pages
<< 23) |
4252 /* Install the new entry ... */
4254 lp
= (uint32_t *)(gdt_table
+ ldt_info
.entry_number
);
4255 lp
[0] = tswap32(entry_1
);
4256 lp
[1] = tswap32(entry_2
);
4260 static abi_long
do_get_thread_area(CPUX86State
*env
, abi_ulong ptr
)
4262 struct target_modify_ldt_ldt_s
*target_ldt_info
;
4263 uint64_t *gdt_table
= g2h(env
->gdt
.base
);
4264 uint32_t base_addr
, limit
, flags
;
4265 int seg_32bit
, contents
, read_exec_only
, limit_in_pages
, idx
;
4266 int seg_not_present
, useable
, lm
;
4267 uint32_t *lp
, entry_1
, entry_2
;
4269 lock_user_struct(VERIFY_WRITE
, target_ldt_info
, ptr
, 1);
4270 if (!target_ldt_info
)
4271 return -TARGET_EFAULT
;
4272 idx
= tswap32(target_ldt_info
->entry_number
);
4273 if (idx
< TARGET_GDT_ENTRY_TLS_MIN
||
4274 idx
> TARGET_GDT_ENTRY_TLS_MAX
) {
4275 unlock_user_struct(target_ldt_info
, ptr
, 1);
4276 return -TARGET_EINVAL
;
4278 lp
= (uint32_t *)(gdt_table
+ idx
);
4279 entry_1
= tswap32(lp
[0]);
4280 entry_2
= tswap32(lp
[1]);
4282 read_exec_only
= ((entry_2
>> 9) & 1) ^ 1;
4283 contents
= (entry_2
>> 10) & 3;
4284 seg_not_present
= ((entry_2
>> 15) & 1) ^ 1;
4285 seg_32bit
= (entry_2
>> 22) & 1;
4286 limit_in_pages
= (entry_2
>> 23) & 1;
4287 useable
= (entry_2
>> 20) & 1;
4291 lm
= (entry_2
>> 21) & 1;
4293 flags
= (seg_32bit
<< 0) | (contents
<< 1) |
4294 (read_exec_only
<< 3) | (limit_in_pages
<< 4) |
4295 (seg_not_present
<< 5) | (useable
<< 6) | (lm
<< 7);
4296 limit
= (entry_1
& 0xffff) | (entry_2
& 0xf0000);
4297 base_addr
= (entry_1
>> 16) |
4298 (entry_2
& 0xff000000) |
4299 ((entry_2
& 0xff) << 16);
4300 target_ldt_info
->base_addr
= tswapal(base_addr
);
4301 target_ldt_info
->limit
= tswap32(limit
);
4302 target_ldt_info
->flags
= tswap32(flags
);
4303 unlock_user_struct(target_ldt_info
, ptr
, 1);
4306 #endif /* TARGET_I386 && TARGET_ABI32 */
4308 #ifndef TARGET_ABI32
4309 abi_long
do_arch_prctl(CPUX86State
*env
, int code
, abi_ulong addr
)
4316 case TARGET_ARCH_SET_GS
:
4317 case TARGET_ARCH_SET_FS
:
4318 if (code
== TARGET_ARCH_SET_GS
)
4322 cpu_x86_load_seg(env
, idx
, 0);
4323 env
->segs
[idx
].base
= addr
;
4325 case TARGET_ARCH_GET_GS
:
4326 case TARGET_ARCH_GET_FS
:
4327 if (code
== TARGET_ARCH_GET_GS
)
4331 val
= env
->segs
[idx
].base
;
4332 if (put_user(val
, addr
, abi_ulong
))
4333 ret
= -TARGET_EFAULT
;
4336 ret
= -TARGET_EINVAL
;
4343 #endif /* defined(TARGET_I386) */
4345 #define NEW_STACK_SIZE 0x40000
4348 static pthread_mutex_t clone_lock
= PTHREAD_MUTEX_INITIALIZER
;
4351 pthread_mutex_t mutex
;
4352 pthread_cond_t cond
;
4355 abi_ulong child_tidptr
;
4356 abi_ulong parent_tidptr
;
4360 static void *clone_func(void *arg
)
4362 new_thread_info
*info
= arg
;
4368 cpu
= ENV_GET_CPU(env
);
4370 ts
= (TaskState
*)env
->opaque
;
4371 info
->tid
= gettid();
4372 cpu
->host_tid
= info
->tid
;
4374 if (info
->child_tidptr
)
4375 put_user_u32(info
->tid
, info
->child_tidptr
);
4376 if (info
->parent_tidptr
)
4377 put_user_u32(info
->tid
, info
->parent_tidptr
);
4378 /* Enable signals. */
4379 sigprocmask(SIG_SETMASK
, &info
->sigmask
, NULL
);
4380 /* Signal to the parent that we're ready. */
4381 pthread_mutex_lock(&info
->mutex
);
4382 pthread_cond_broadcast(&info
->cond
);
4383 pthread_mutex_unlock(&info
->mutex
);
4384 /* Wait until the parent has finshed initializing the tls state. */
4385 pthread_mutex_lock(&clone_lock
);
4386 pthread_mutex_unlock(&clone_lock
);
4392 /* do_fork() Must return host values and target errnos (unlike most
4393 do_*() functions). */
4394 static int do_fork(CPUArchState
*env
, unsigned int flags
, abi_ulong newsp
,
4395 abi_ulong parent_tidptr
, target_ulong newtls
,
4396 abi_ulong child_tidptr
)
4400 CPUArchState
*new_env
;
4401 unsigned int nptl_flags
;
4404 /* Emulate vfork() with fork() */
4405 if (flags
& CLONE_VFORK
)
4406 flags
&= ~(CLONE_VFORK
| CLONE_VM
);
4408 if (flags
& CLONE_VM
) {
4409 TaskState
*parent_ts
= (TaskState
*)env
->opaque
;
4410 new_thread_info info
;
4411 pthread_attr_t attr
;
4413 ts
= g_malloc0(sizeof(TaskState
));
4414 init_task_state(ts
);
4415 /* we create a new CPU instance. */
4416 new_env
= cpu_copy(env
);
4417 /* Init regs that differ from the parent. */
4418 cpu_clone_regs(new_env
, newsp
);
4419 new_env
->opaque
= ts
;
4420 ts
->bprm
= parent_ts
->bprm
;
4421 ts
->info
= parent_ts
->info
;
4423 flags
&= ~CLONE_NPTL_FLAGS2
;
4425 if (nptl_flags
& CLONE_CHILD_CLEARTID
) {
4426 ts
->child_tidptr
= child_tidptr
;
4429 if (nptl_flags
& CLONE_SETTLS
)
4430 cpu_set_tls (new_env
, newtls
);
4432 /* Grab a mutex so that thread setup appears atomic. */
4433 pthread_mutex_lock(&clone_lock
);
4435 memset(&info
, 0, sizeof(info
));
4436 pthread_mutex_init(&info
.mutex
, NULL
);
4437 pthread_mutex_lock(&info
.mutex
);
4438 pthread_cond_init(&info
.cond
, NULL
);
4440 if (nptl_flags
& CLONE_CHILD_SETTID
)
4441 info
.child_tidptr
= child_tidptr
;
4442 if (nptl_flags
& CLONE_PARENT_SETTID
)
4443 info
.parent_tidptr
= parent_tidptr
;
4445 ret
= pthread_attr_init(&attr
);
4446 ret
= pthread_attr_setstacksize(&attr
, NEW_STACK_SIZE
);
4447 ret
= pthread_attr_setdetachstate(&attr
, PTHREAD_CREATE_DETACHED
);
4448 /* It is not safe to deliver signals until the child has finished
4449 initializing, so temporarily block all signals. */
4450 sigfillset(&sigmask
);
4451 sigprocmask(SIG_BLOCK
, &sigmask
, &info
.sigmask
);
4453 ret
= pthread_create(&info
.thread
, &attr
, clone_func
, &info
);
4454 /* TODO: Free new CPU state if thread creation failed. */
4456 sigprocmask(SIG_SETMASK
, &info
.sigmask
, NULL
);
4457 pthread_attr_destroy(&attr
);
4459 /* Wait for the child to initialize. */
4460 pthread_cond_wait(&info
.cond
, &info
.mutex
);
4462 if (flags
& CLONE_PARENT_SETTID
)
4463 put_user_u32(ret
, parent_tidptr
);
4467 pthread_mutex_unlock(&info
.mutex
);
4468 pthread_cond_destroy(&info
.cond
);
4469 pthread_mutex_destroy(&info
.mutex
);
4470 pthread_mutex_unlock(&clone_lock
);
4472 /* if no CLONE_VM, we consider it is a fork */
4473 if ((flags
& ~(CSIGNAL
| CLONE_NPTL_FLAGS2
)) != 0)
4478 /* Child Process. */
4479 cpu_clone_regs(env
, newsp
);
4481 /* There is a race condition here. The parent process could
4482 theoretically read the TID in the child process before the child
4483 tid is set. This would require using either ptrace
4484 (not implemented) or having *_tidptr to point at a shared memory
4485 mapping. We can't repeat the spinlock hack used above because
4486 the child process gets its own copy of the lock. */
4487 if (flags
& CLONE_CHILD_SETTID
)
4488 put_user_u32(gettid(), child_tidptr
);
4489 if (flags
& CLONE_PARENT_SETTID
)
4490 put_user_u32(gettid(), parent_tidptr
);
4491 ts
= (TaskState
*)env
->opaque
;
4492 if (flags
& CLONE_SETTLS
)
4493 cpu_set_tls (env
, newtls
);
4494 if (flags
& CLONE_CHILD_CLEARTID
)
4495 ts
->child_tidptr
= child_tidptr
;
4503 /* warning : doesn't handle linux specific flags... */
4504 static int target_to_host_fcntl_cmd(int cmd
)
4507 case TARGET_F_DUPFD
:
4508 case TARGET_F_GETFD
:
4509 case TARGET_F_SETFD
:
4510 case TARGET_F_GETFL
:
4511 case TARGET_F_SETFL
:
4513 case TARGET_F_GETLK
:
4515 case TARGET_F_SETLK
:
4517 case TARGET_F_SETLKW
:
4519 case TARGET_F_GETOWN
:
4521 case TARGET_F_SETOWN
:
4523 case TARGET_F_GETSIG
:
4525 case TARGET_F_SETSIG
:
4527 #if TARGET_ABI_BITS == 32
4528 case TARGET_F_GETLK64
:
4530 case TARGET_F_SETLK64
:
4532 case TARGET_F_SETLKW64
:
4535 case TARGET_F_SETLEASE
:
4537 case TARGET_F_GETLEASE
:
4539 #ifdef F_DUPFD_CLOEXEC
4540 case TARGET_F_DUPFD_CLOEXEC
:
4541 return F_DUPFD_CLOEXEC
;
4543 case TARGET_F_NOTIFY
:
4546 return -TARGET_EINVAL
;
4548 return -TARGET_EINVAL
;
4551 #define TRANSTBL_CONVERT(a) { -1, TARGET_##a, -1, a }
4552 static const bitmask_transtbl flock_tbl
[] = {
4553 TRANSTBL_CONVERT(F_RDLCK
),
4554 TRANSTBL_CONVERT(F_WRLCK
),
4555 TRANSTBL_CONVERT(F_UNLCK
),
4556 TRANSTBL_CONVERT(F_EXLCK
),
4557 TRANSTBL_CONVERT(F_SHLCK
),
4561 static abi_long
do_fcntl(int fd
, int cmd
, abi_ulong arg
)
4564 struct target_flock
*target_fl
;
4565 struct flock64 fl64
;
4566 struct target_flock64
*target_fl64
;
4568 int host_cmd
= target_to_host_fcntl_cmd(cmd
);
4570 if (host_cmd
== -TARGET_EINVAL
)
4574 case TARGET_F_GETLK
:
4575 if (!lock_user_struct(VERIFY_READ
, target_fl
, arg
, 1))
4576 return -TARGET_EFAULT
;
4578 target_to_host_bitmask(tswap16(target_fl
->l_type
), flock_tbl
);
4579 fl
.l_whence
= tswap16(target_fl
->l_whence
);
4580 fl
.l_start
= tswapal(target_fl
->l_start
);
4581 fl
.l_len
= tswapal(target_fl
->l_len
);
4582 fl
.l_pid
= tswap32(target_fl
->l_pid
);
4583 unlock_user_struct(target_fl
, arg
, 0);
4584 ret
= get_errno(fcntl(fd
, host_cmd
, &fl
));
4586 if (!lock_user_struct(VERIFY_WRITE
, target_fl
, arg
, 0))
4587 return -TARGET_EFAULT
;
4589 host_to_target_bitmask(tswap16(fl
.l_type
), flock_tbl
);
4590 target_fl
->l_whence
= tswap16(fl
.l_whence
);
4591 target_fl
->l_start
= tswapal(fl
.l_start
);
4592 target_fl
->l_len
= tswapal(fl
.l_len
);
4593 target_fl
->l_pid
= tswap32(fl
.l_pid
);
4594 unlock_user_struct(target_fl
, arg
, 1);
4598 case TARGET_F_SETLK
:
4599 case TARGET_F_SETLKW
:
4600 if (!lock_user_struct(VERIFY_READ
, target_fl
, arg
, 1))
4601 return -TARGET_EFAULT
;
4603 target_to_host_bitmask(tswap16(target_fl
->l_type
), flock_tbl
);
4604 fl
.l_whence
= tswap16(target_fl
->l_whence
);
4605 fl
.l_start
= tswapal(target_fl
->l_start
);
4606 fl
.l_len
= tswapal(target_fl
->l_len
);
4607 fl
.l_pid
= tswap32(target_fl
->l_pid
);
4608 unlock_user_struct(target_fl
, arg
, 0);
4609 ret
= get_errno(fcntl(fd
, host_cmd
, &fl
));
4612 case TARGET_F_GETLK64
:
4613 if (!lock_user_struct(VERIFY_READ
, target_fl64
, arg
, 1))
4614 return -TARGET_EFAULT
;
4616 target_to_host_bitmask(tswap16(target_fl64
->l_type
), flock_tbl
) >> 1;
4617 fl64
.l_whence
= tswap16(target_fl64
->l_whence
);
4618 fl64
.l_start
= tswap64(target_fl64
->l_start
);
4619 fl64
.l_len
= tswap64(target_fl64
->l_len
);
4620 fl64
.l_pid
= tswap32(target_fl64
->l_pid
);
4621 unlock_user_struct(target_fl64
, arg
, 0);
4622 ret
= get_errno(fcntl(fd
, host_cmd
, &fl64
));
4624 if (!lock_user_struct(VERIFY_WRITE
, target_fl64
, arg
, 0))
4625 return -TARGET_EFAULT
;
4626 target_fl64
->l_type
=
4627 host_to_target_bitmask(tswap16(fl64
.l_type
), flock_tbl
) >> 1;
4628 target_fl64
->l_whence
= tswap16(fl64
.l_whence
);
4629 target_fl64
->l_start
= tswap64(fl64
.l_start
);
4630 target_fl64
->l_len
= tswap64(fl64
.l_len
);
4631 target_fl64
->l_pid
= tswap32(fl64
.l_pid
);
4632 unlock_user_struct(target_fl64
, arg
, 1);
4635 case TARGET_F_SETLK64
:
4636 case TARGET_F_SETLKW64
:
4637 if (!lock_user_struct(VERIFY_READ
, target_fl64
, arg
, 1))
4638 return -TARGET_EFAULT
;
4640 target_to_host_bitmask(tswap16(target_fl64
->l_type
), flock_tbl
) >> 1;
4641 fl64
.l_whence
= tswap16(target_fl64
->l_whence
);
4642 fl64
.l_start
= tswap64(target_fl64
->l_start
);
4643 fl64
.l_len
= tswap64(target_fl64
->l_len
);
4644 fl64
.l_pid
= tswap32(target_fl64
->l_pid
);
4645 unlock_user_struct(target_fl64
, arg
, 0);
4646 ret
= get_errno(fcntl(fd
, host_cmd
, &fl64
));
4649 case TARGET_F_GETFL
:
4650 ret
= get_errno(fcntl(fd
, host_cmd
, arg
));
4652 ret
= host_to_target_bitmask(ret
, fcntl_flags_tbl
);
4656 case TARGET_F_SETFL
:
4657 ret
= get_errno(fcntl(fd
, host_cmd
, target_to_host_bitmask(arg
, fcntl_flags_tbl
)));
4660 case TARGET_F_SETOWN
:
4661 case TARGET_F_GETOWN
:
4662 case TARGET_F_SETSIG
:
4663 case TARGET_F_GETSIG
:
4664 case TARGET_F_SETLEASE
:
4665 case TARGET_F_GETLEASE
:
4666 ret
= get_errno(fcntl(fd
, host_cmd
, arg
));
4670 ret
= get_errno(fcntl(fd
, cmd
, arg
));
4678 static inline int high2lowuid(int uid
)
4686 static inline int high2lowgid(int gid
)
4694 static inline int low2highuid(int uid
)
4696 if ((int16_t)uid
== -1)
4702 static inline int low2highgid(int gid
)
4704 if ((int16_t)gid
== -1)
4709 static inline int tswapid(int id
)
4713 #else /* !USE_UID16 */
4714 static inline int high2lowuid(int uid
)
4718 static inline int high2lowgid(int gid
)
4722 static inline int low2highuid(int uid
)
4726 static inline int low2highgid(int gid
)
4730 static inline int tswapid(int id
)
4734 #endif /* USE_UID16 */
4736 void syscall_init(void)
4739 const argtype
*arg_type
;
4743 #define STRUCT(name, ...) thunk_register_struct(STRUCT_ ## name, #name, struct_ ## name ## _def);
4744 #define STRUCT_SPECIAL(name) thunk_register_struct_direct(STRUCT_ ## name, #name, &struct_ ## name ## _def);
4745 #include "syscall_types.h"
4747 #undef STRUCT_SPECIAL
4749 /* Build target_to_host_errno_table[] table from
4750 * host_to_target_errno_table[]. */
4751 for (i
= 0; i
< ERRNO_TABLE_SIZE
; i
++) {
4752 target_to_host_errno_table
[host_to_target_errno_table
[i
]] = i
;
4755 /* we patch the ioctl size if necessary. We rely on the fact that
4756 no ioctl has all the bits at '1' in the size field */
4758 while (ie
->target_cmd
!= 0) {
4759 if (((ie
->target_cmd
>> TARGET_IOC_SIZESHIFT
) & TARGET_IOC_SIZEMASK
) ==
4760 TARGET_IOC_SIZEMASK
) {
4761 arg_type
= ie
->arg_type
;
4762 if (arg_type
[0] != TYPE_PTR
) {
4763 fprintf(stderr
, "cannot patch size for ioctl 0x%x\n",
4768 size
= thunk_type_size(arg_type
, 0);
4769 ie
->target_cmd
= (ie
->target_cmd
&
4770 ~(TARGET_IOC_SIZEMASK
<< TARGET_IOC_SIZESHIFT
)) |
4771 (size
<< TARGET_IOC_SIZESHIFT
);
4774 /* automatic consistency check if same arch */
4775 #if (defined(__i386__) && defined(TARGET_I386) && defined(TARGET_ABI32)) || \
4776 (defined(__x86_64__) && defined(TARGET_X86_64))
4777 if (unlikely(ie
->target_cmd
!= ie
->host_cmd
)) {
4778 fprintf(stderr
, "ERROR: ioctl(%s): target=0x%x host=0x%x\n",
4779 ie
->name
, ie
->target_cmd
, ie
->host_cmd
);
4786 #if TARGET_ABI_BITS == 32
4787 static inline uint64_t target_offset64(uint32_t word0
, uint32_t word1
)
4789 #ifdef TARGET_WORDS_BIGENDIAN
4790 return ((uint64_t)word0
<< 32) | word1
;
4792 return ((uint64_t)word1
<< 32) | word0
;
4795 #else /* TARGET_ABI_BITS == 32 */
4796 static inline uint64_t target_offset64(uint64_t word0
, uint64_t word1
)
4800 #endif /* TARGET_ABI_BITS != 32 */
4802 #ifdef TARGET_NR_truncate64
4803 static inline abi_long
target_truncate64(void *cpu_env
, const char *arg1
,
4808 if (regpairs_aligned(cpu_env
)) {
4812 return get_errno(truncate64(arg1
, target_offset64(arg2
, arg3
)));
4816 #ifdef TARGET_NR_ftruncate64
4817 static inline abi_long
target_ftruncate64(void *cpu_env
, abi_long arg1
,
4822 if (regpairs_aligned(cpu_env
)) {
4826 return get_errno(ftruncate64(arg1
, target_offset64(arg2
, arg3
)));
4830 static inline abi_long
target_to_host_timespec(struct timespec
*host_ts
,
4831 abi_ulong target_addr
)
4833 struct target_timespec
*target_ts
;
4835 if (!lock_user_struct(VERIFY_READ
, target_ts
, target_addr
, 1))
4836 return -TARGET_EFAULT
;
4837 host_ts
->tv_sec
= tswapal(target_ts
->tv_sec
);
4838 host_ts
->tv_nsec
= tswapal(target_ts
->tv_nsec
);
4839 unlock_user_struct(target_ts
, target_addr
, 0);
4843 static inline abi_long
host_to_target_timespec(abi_ulong target_addr
,
4844 struct timespec
*host_ts
)
4846 struct target_timespec
*target_ts
;
4848 if (!lock_user_struct(VERIFY_WRITE
, target_ts
, target_addr
, 0))
4849 return -TARGET_EFAULT
;
4850 target_ts
->tv_sec
= tswapal(host_ts
->tv_sec
);
4851 target_ts
->tv_nsec
= tswapal(host_ts
->tv_nsec
);
4852 unlock_user_struct(target_ts
, target_addr
, 1);
4856 static inline abi_long
target_to_host_itimerspec(struct itimerspec
*host_itspec
,
4857 abi_ulong target_addr
)
4859 struct target_itimerspec
*target_itspec
;
4861 if (!lock_user_struct(VERIFY_READ
, target_itspec
, target_addr
, 1)) {
4862 return -TARGET_EFAULT
;
4865 host_itspec
->it_interval
.tv_sec
=
4866 tswapal(target_itspec
->it_interval
.tv_sec
);
4867 host_itspec
->it_interval
.tv_nsec
=
4868 tswapal(target_itspec
->it_interval
.tv_nsec
);
4869 host_itspec
->it_value
.tv_sec
= tswapal(target_itspec
->it_value
.tv_sec
);
4870 host_itspec
->it_value
.tv_nsec
= tswapal(target_itspec
->it_value
.tv_nsec
);
4872 unlock_user_struct(target_itspec
, target_addr
, 1);
4876 static inline abi_long
host_to_target_itimerspec(abi_ulong target_addr
,
4877 struct itimerspec
*host_its
)
4879 struct target_itimerspec
*target_itspec
;
4881 if (!lock_user_struct(VERIFY_WRITE
, target_itspec
, target_addr
, 0)) {
4882 return -TARGET_EFAULT
;
4885 target_itspec
->it_interval
.tv_sec
= tswapal(host_its
->it_interval
.tv_sec
);
4886 target_itspec
->it_interval
.tv_nsec
= tswapal(host_its
->it_interval
.tv_nsec
);
4888 target_itspec
->it_value
.tv_sec
= tswapal(host_its
->it_value
.tv_sec
);
4889 target_itspec
->it_value
.tv_nsec
= tswapal(host_its
->it_value
.tv_nsec
);
4891 unlock_user_struct(target_itspec
, target_addr
, 0);
4895 #if defined(TARGET_NR_stat64) || defined(TARGET_NR_newfstatat)
4896 static inline abi_long
host_to_target_stat64(void *cpu_env
,
4897 abi_ulong target_addr
,
4898 struct stat
*host_st
)
4900 #if defined(TARGET_ARM) && defined(TARGET_ABI32)
4901 if (((CPUARMState
*)cpu_env
)->eabi
) {
4902 struct target_eabi_stat64
*target_st
;
4904 if (!lock_user_struct(VERIFY_WRITE
, target_st
, target_addr
, 0))
4905 return -TARGET_EFAULT
;
4906 memset(target_st
, 0, sizeof(struct target_eabi_stat64
));
4907 __put_user(host_st
->st_dev
, &target_st
->st_dev
);
4908 __put_user(host_st
->st_ino
, &target_st
->st_ino
);
4909 #ifdef TARGET_STAT64_HAS_BROKEN_ST_INO
4910 __put_user(host_st
->st_ino
, &target_st
->__st_ino
);
4912 __put_user(host_st
->st_mode
, &target_st
->st_mode
);
4913 __put_user(host_st
->st_nlink
, &target_st
->st_nlink
);
4914 __put_user(host_st
->st_uid
, &target_st
->st_uid
);
4915 __put_user(host_st
->st_gid
, &target_st
->st_gid
);
4916 __put_user(host_st
->st_rdev
, &target_st
->st_rdev
);
4917 __put_user(host_st
->st_size
, &target_st
->st_size
);
4918 __put_user(host_st
->st_blksize
, &target_st
->st_blksize
);
4919 __put_user(host_st
->st_blocks
, &target_st
->st_blocks
);
4920 __put_user(host_st
->st_atime
, &target_st
->target_st_atime
);
4921 __put_user(host_st
->st_mtime
, &target_st
->target_st_mtime
);
4922 __put_user(host_st
->st_ctime
, &target_st
->target_st_ctime
);
4923 unlock_user_struct(target_st
, target_addr
, 1);
4927 #if defined(TARGET_HAS_STRUCT_STAT64)
4928 struct target_stat64
*target_st
;
4930 struct target_stat
*target_st
;
4933 if (!lock_user_struct(VERIFY_WRITE
, target_st
, target_addr
, 0))
4934 return -TARGET_EFAULT
;
4935 memset(target_st
, 0, sizeof(*target_st
));
4936 __put_user(host_st
->st_dev
, &target_st
->st_dev
);
4937 __put_user(host_st
->st_ino
, &target_st
->st_ino
);
4938 #ifdef TARGET_STAT64_HAS_BROKEN_ST_INO
4939 __put_user(host_st
->st_ino
, &target_st
->__st_ino
);
4941 __put_user(host_st
->st_mode
, &target_st
->st_mode
);
4942 __put_user(host_st
->st_nlink
, &target_st
->st_nlink
);
4943 __put_user(host_st
->st_uid
, &target_st
->st_uid
);
4944 __put_user(host_st
->st_gid
, &target_st
->st_gid
);
4945 __put_user(host_st
->st_rdev
, &target_st
->st_rdev
);
4946 /* XXX: better use of kernel struct */
4947 __put_user(host_st
->st_size
, &target_st
->st_size
);
4948 __put_user(host_st
->st_blksize
, &target_st
->st_blksize
);
4949 __put_user(host_st
->st_blocks
, &target_st
->st_blocks
);
4950 __put_user(host_st
->st_atime
, &target_st
->target_st_atime
);
4951 __put_user(host_st
->st_mtime
, &target_st
->target_st_mtime
);
4952 __put_user(host_st
->st_ctime
, &target_st
->target_st_ctime
);
4953 unlock_user_struct(target_st
, target_addr
, 1);
4960 /* ??? Using host futex calls even when target atomic operations
4961 are not really atomic probably breaks things. However implementing
4962 futexes locally would make futexes shared between multiple processes
4963 tricky. However they're probably useless because guest atomic
4964 operations won't work either. */
4965 static int do_futex(target_ulong uaddr
, int op
, int val
, target_ulong timeout
,
4966 target_ulong uaddr2
, int val3
)
4968 struct timespec ts
, *pts
;
4971 /* ??? We assume FUTEX_* constants are the same on both host
4973 #ifdef FUTEX_CMD_MASK
4974 base_op
= op
& FUTEX_CMD_MASK
;
4980 case FUTEX_WAIT_BITSET
:
4983 target_to_host_timespec(pts
, timeout
);
4987 return get_errno(sys_futex(g2h(uaddr
), op
, tswap32(val
),
4990 return get_errno(sys_futex(g2h(uaddr
), op
, val
, NULL
, NULL
, 0));
4992 return get_errno(sys_futex(g2h(uaddr
), op
, val
, NULL
, NULL
, 0));
4994 case FUTEX_CMP_REQUEUE
:
4996 /* For FUTEX_REQUEUE, FUTEX_CMP_REQUEUE, and FUTEX_WAKE_OP, the
4997 TIMEOUT parameter is interpreted as a uint32_t by the kernel.
4998 But the prototype takes a `struct timespec *'; insert casts
4999 to satisfy the compiler. We do not need to tswap TIMEOUT
5000 since it's not compared to guest memory. */
5001 pts
= (struct timespec
*)(uintptr_t) timeout
;
5002 return get_errno(sys_futex(g2h(uaddr
), op
, val
, pts
,
5004 (base_op
== FUTEX_CMP_REQUEUE
5008 return -TARGET_ENOSYS
;
5012 /* Map host to target signal numbers for the wait family of syscalls.
5013 Assume all other status bits are the same. */
5014 int host_to_target_waitstatus(int status
)
5016 if (WIFSIGNALED(status
)) {
5017 return host_to_target_signal(WTERMSIG(status
)) | (status
& ~0x7f);
5019 if (WIFSTOPPED(status
)) {
5020 return (host_to_target_signal(WSTOPSIG(status
)) << 8)
5026 static int relstr_to_int(const char *s
)
5028 /* Convert a uname release string like "2.6.18" to an integer
5029 * of the form 0x020612. (Beware that 0x020612 is *not* 2.6.12.)
5034 for (i
= 0; i
< 3; i
++) {
5036 while (*s
>= '0' && *s
<= '9') {
5041 tmp
= (tmp
<< 8) + n
;
5049 int get_osversion(void)
5051 static int osversion
;
5052 struct new_utsname buf
;
5057 if (qemu_uname_release
&& *qemu_uname_release
) {
5058 s
= qemu_uname_release
;
5060 if (sys_uname(&buf
))
5064 osversion
= relstr_to_int(s
);
5068 void init_qemu_uname_release(void)
5070 /* Initialize qemu_uname_release for later use.
5071 * If the host kernel is too old and the user hasn't asked for
5072 * a specific fake version number, we might want to fake a minimum
5073 * target kernel version.
5075 #ifdef UNAME_MINIMUM_RELEASE
5076 struct new_utsname buf
;
5078 if (qemu_uname_release
&& *qemu_uname_release
) {
5082 if (sys_uname(&buf
)) {
5086 if (relstr_to_int(buf
.release
) < relstr_to_int(UNAME_MINIMUM_RELEASE
)) {
5087 qemu_uname_release
= UNAME_MINIMUM_RELEASE
;
5092 static int open_self_maps(void *cpu_env
, int fd
)
5094 #if defined(TARGET_ARM) || defined(TARGET_M68K) || defined(TARGET_UNICORE32)
5095 TaskState
*ts
= ((CPUArchState
*)cpu_env
)->opaque
;
5102 fp
= fopen("/proc/self/maps", "r");
5107 while ((read
= getline(&line
, &len
, fp
)) != -1) {
5108 int fields
, dev_maj
, dev_min
, inode
;
5109 uint64_t min
, max
, offset
;
5110 char flag_r
, flag_w
, flag_x
, flag_p
;
5111 char path
[512] = "";
5112 fields
= sscanf(line
, "%"PRIx64
"-%"PRIx64
" %c%c%c%c %"PRIx64
" %x:%x %d"
5113 " %512s", &min
, &max
, &flag_r
, &flag_w
, &flag_x
,
5114 &flag_p
, &offset
, &dev_maj
, &dev_min
, &inode
, path
);
5116 if ((fields
< 10) || (fields
> 11)) {
5119 if (!strncmp(path
, "[stack]", 7)) {
5122 if (h2g_valid(min
) && h2g_valid(max
)) {
5123 dprintf(fd
, TARGET_ABI_FMT_lx
"-" TARGET_ABI_FMT_lx
5124 " %c%c%c%c %08" PRIx64
" %02x:%02x %d %s%s\n",
5125 h2g(min
), h2g(max
), flag_r
, flag_w
,
5126 flag_x
, flag_p
, offset
, dev_maj
, dev_min
, inode
,
5127 path
[0] ? " " : "", path
);
5134 #if defined(TARGET_ARM) || defined(TARGET_M68K) || defined(TARGET_UNICORE32)
5135 dprintf(fd
, "%08llx-%08llx rw-p %08llx 00:00 0 [stack]\n",
5136 (unsigned long long)ts
->info
->stack_limit
,
5137 (unsigned long long)(ts
->info
->start_stack
+
5138 (TARGET_PAGE_SIZE
- 1)) & TARGET_PAGE_MASK
,
5139 (unsigned long long)0);
5145 static int open_self_stat(void *cpu_env
, int fd
)
5147 TaskState
*ts
= ((CPUArchState
*)cpu_env
)->opaque
;
5148 abi_ulong start_stack
= ts
->info
->start_stack
;
5151 for (i
= 0; i
< 44; i
++) {
5159 snprintf(buf
, sizeof(buf
), "%"PRId64
" ", val
);
5160 } else if (i
== 1) {
5162 snprintf(buf
, sizeof(buf
), "(%s) ", ts
->bprm
->argv
[0]);
5163 } else if (i
== 27) {
5166 snprintf(buf
, sizeof(buf
), "%"PRId64
" ", val
);
5168 /* for the rest, there is MasterCard */
5169 snprintf(buf
, sizeof(buf
), "0%c", i
== 43 ? '\n' : ' ');
5173 if (write(fd
, buf
, len
) != len
) {
5181 static int open_self_auxv(void *cpu_env
, int fd
)
5183 TaskState
*ts
= ((CPUArchState
*)cpu_env
)->opaque
;
5184 abi_ulong auxv
= ts
->info
->saved_auxv
;
5185 abi_ulong len
= ts
->info
->auxv_len
;
5189 * Auxiliary vector is stored in target process stack.
5190 * read in whole auxv vector and copy it to file
5192 ptr
= lock_user(VERIFY_READ
, auxv
, len
, 0);
5196 r
= write(fd
, ptr
, len
);
5203 lseek(fd
, 0, SEEK_SET
);
5204 unlock_user(ptr
, auxv
, len
);
5210 static int is_proc_myself(const char *filename
, const char *entry
)
5212 if (!strncmp(filename
, "/proc/", strlen("/proc/"))) {
5213 filename
+= strlen("/proc/");
5214 if (!strncmp(filename
, "self/", strlen("self/"))) {
5215 filename
+= strlen("self/");
5216 } else if (*filename
>= '1' && *filename
<= '9') {
5218 snprintf(myself
, sizeof(myself
), "%d/", getpid());
5219 if (!strncmp(filename
, myself
, strlen(myself
))) {
5220 filename
+= strlen(myself
);
5227 if (!strcmp(filename
, entry
)) {
5234 #if defined(HOST_WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN)
5235 static int is_proc(const char *filename
, const char *entry
)
5237 return strcmp(filename
, entry
) == 0;
5240 static int open_net_route(void *cpu_env
, int fd
)
5247 fp
= fopen("/proc/net/route", "r");
5254 read
= getline(&line
, &len
, fp
);
5255 dprintf(fd
, "%s", line
);
5259 while ((read
= getline(&line
, &len
, fp
)) != -1) {
5261 uint32_t dest
, gw
, mask
;
5262 unsigned int flags
, refcnt
, use
, metric
, mtu
, window
, irtt
;
5263 sscanf(line
, "%s\t%08x\t%08x\t%04x\t%d\t%d\t%d\t%08x\t%d\t%u\t%u\n",
5264 iface
, &dest
, &gw
, &flags
, &refcnt
, &use
, &metric
,
5265 &mask
, &mtu
, &window
, &irtt
);
5266 dprintf(fd
, "%s\t%08x\t%08x\t%04x\t%d\t%d\t%d\t%08x\t%d\t%u\t%u\n",
5267 iface
, tswap32(dest
), tswap32(gw
), flags
, refcnt
, use
,
5268 metric
, tswap32(mask
), mtu
, window
, irtt
);
5278 static int do_open(void *cpu_env
, const char *pathname
, int flags
, mode_t mode
)
5281 const char *filename
;
5282 int (*fill
)(void *cpu_env
, int fd
);
5283 int (*cmp
)(const char *s1
, const char *s2
);
5285 const struct fake_open
*fake_open
;
5286 static const struct fake_open fakes
[] = {
5287 { "maps", open_self_maps
, is_proc_myself
},
5288 { "stat", open_self_stat
, is_proc_myself
},
5289 { "auxv", open_self_auxv
, is_proc_myself
},
5290 #if defined(HOST_WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN)
5291 { "/proc/net/route", open_net_route
, is_proc
},
5293 { NULL
, NULL
, NULL
}
5296 for (fake_open
= fakes
; fake_open
->filename
; fake_open
++) {
5297 if (fake_open
->cmp(pathname
, fake_open
->filename
)) {
5302 if (fake_open
->filename
) {
5304 char filename
[PATH_MAX
];
5307 /* create temporary file to map stat to */
5308 tmpdir
= getenv("TMPDIR");
5311 snprintf(filename
, sizeof(filename
), "%s/qemu-open.XXXXXX", tmpdir
);
5312 fd
= mkstemp(filename
);
5318 if ((r
= fake_open
->fill(cpu_env
, fd
))) {
5322 lseek(fd
, 0, SEEK_SET
);
5327 return get_errno(open(path(pathname
), flags
, mode
));
5330 /* do_syscall() should always have a single exit point at the end so
5331 that actions, such as logging of syscall results, can be performed.
5332 All errnos that do_syscall() returns must be -TARGET_<errcode>. */
5333 abi_long
do_syscall(void *cpu_env
, int num
, abi_long arg1
,
5334 abi_long arg2
, abi_long arg3
, abi_long arg4
,
5335 abi_long arg5
, abi_long arg6
, abi_long arg7
,
5338 CPUState
*cpu
= ENV_GET_CPU(cpu_env
);
5345 gemu_log("syscall %d", num
);
5348 print_syscall(num
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
5351 case TARGET_NR_exit
:
5352 /* In old applications this may be used to implement _exit(2).
5353 However in threaded applictions it is used for thread termination,
5354 and _exit_group is used for application termination.
5355 Do thread termination if we have more then one thread. */
5356 /* FIXME: This probably breaks if a signal arrives. We should probably
5357 be disabling signals. */
5358 if (CPU_NEXT(first_cpu
)) {
5362 /* Remove the CPU from the list. */
5363 QTAILQ_REMOVE(&cpus
, cpu
, node
);
5365 ts
= ((CPUArchState
*)cpu_env
)->opaque
;
5366 if (ts
->child_tidptr
) {
5367 put_user_u32(0, ts
->child_tidptr
);
5368 sys_futex(g2h(ts
->child_tidptr
), FUTEX_WAKE
, INT_MAX
,
5372 object_unref(OBJECT(ENV_GET_CPU(cpu_env
)));
5379 gdb_exit(cpu_env
, arg1
);
5381 ret
= 0; /* avoid warning */
5383 case TARGET_NR_read
:
5387 if (!(p
= lock_user(VERIFY_WRITE
, arg2
, arg3
, 0)))
5389 ret
= get_errno(read(arg1
, p
, arg3
));
5390 unlock_user(p
, arg2
, ret
);
5393 case TARGET_NR_write
:
5394 if (!(p
= lock_user(VERIFY_READ
, arg2
, arg3
, 1)))
5396 ret
= get_errno(write(arg1
, p
, arg3
));
5397 unlock_user(p
, arg2
, 0);
5399 case TARGET_NR_open
:
5400 if (!(p
= lock_user_string(arg1
)))
5402 ret
= get_errno(do_open(cpu_env
, p
,
5403 target_to_host_bitmask(arg2
, fcntl_flags_tbl
),
5405 unlock_user(p
, arg1
, 0);
5407 #if defined(TARGET_NR_openat) && defined(__NR_openat)
5408 case TARGET_NR_openat
:
5409 if (!(p
= lock_user_string(arg2
)))
5411 ret
= get_errno(sys_openat(arg1
,
5413 target_to_host_bitmask(arg3
, fcntl_flags_tbl
),
5415 unlock_user(p
, arg2
, 0);
5418 case TARGET_NR_close
:
5419 ret
= get_errno(close(arg1
));
5424 case TARGET_NR_fork
:
5425 ret
= get_errno(do_fork(cpu_env
, SIGCHLD
, 0, 0, 0, 0));
5427 #ifdef TARGET_NR_waitpid
5428 case TARGET_NR_waitpid
:
5431 ret
= get_errno(waitpid(arg1
, &status
, arg3
));
5432 if (!is_error(ret
) && arg2
&& ret
5433 && put_user_s32(host_to_target_waitstatus(status
), arg2
))
5438 #ifdef TARGET_NR_waitid
5439 case TARGET_NR_waitid
:
5443 ret
= get_errno(waitid(arg1
, arg2
, &info
, arg4
));
5444 if (!is_error(ret
) && arg3
&& info
.si_pid
!= 0) {
5445 if (!(p
= lock_user(VERIFY_WRITE
, arg3
, sizeof(target_siginfo_t
), 0)))
5447 host_to_target_siginfo(p
, &info
);
5448 unlock_user(p
, arg3
, sizeof(target_siginfo_t
));
5453 #ifdef TARGET_NR_creat /* not on alpha */
5454 case TARGET_NR_creat
:
5455 if (!(p
= lock_user_string(arg1
)))
5457 ret
= get_errno(creat(p
, arg2
));
5458 unlock_user(p
, arg1
, 0);
5461 case TARGET_NR_link
:
5464 p
= lock_user_string(arg1
);
5465 p2
= lock_user_string(arg2
);
5467 ret
= -TARGET_EFAULT
;
5469 ret
= get_errno(link(p
, p2
));
5470 unlock_user(p2
, arg2
, 0);
5471 unlock_user(p
, arg1
, 0);
5474 #if defined(TARGET_NR_linkat)
5475 case TARGET_NR_linkat
:
5480 p
= lock_user_string(arg2
);
5481 p2
= lock_user_string(arg4
);
5483 ret
= -TARGET_EFAULT
;
5485 ret
= get_errno(linkat(arg1
, p
, arg3
, p2
, arg5
));
5486 unlock_user(p
, arg2
, 0);
5487 unlock_user(p2
, arg4
, 0);
5491 case TARGET_NR_unlink
:
5492 if (!(p
= lock_user_string(arg1
)))
5494 ret
= get_errno(unlink(p
));
5495 unlock_user(p
, arg1
, 0);
5497 #if defined(TARGET_NR_unlinkat)
5498 case TARGET_NR_unlinkat
:
5499 if (!(p
= lock_user_string(arg2
)))
5501 ret
= get_errno(unlinkat(arg1
, p
, arg3
));
5502 unlock_user(p
, arg2
, 0);
5505 case TARGET_NR_execve
:
5507 char **argp
, **envp
;
5510 abi_ulong guest_argp
;
5511 abi_ulong guest_envp
;
5518 for (gp
= guest_argp
; gp
; gp
+= sizeof(abi_ulong
)) {
5519 if (get_user_ual(addr
, gp
))
5527 for (gp
= guest_envp
; gp
; gp
+= sizeof(abi_ulong
)) {
5528 if (get_user_ual(addr
, gp
))
5535 argp
= alloca((argc
+ 1) * sizeof(void *));
5536 envp
= alloca((envc
+ 1) * sizeof(void *));
5538 for (gp
= guest_argp
, q
= argp
; gp
;
5539 gp
+= sizeof(abi_ulong
), q
++) {
5540 if (get_user_ual(addr
, gp
))
5544 if (!(*q
= lock_user_string(addr
)))
5546 total_size
+= strlen(*q
) + 1;
5550 for (gp
= guest_envp
, q
= envp
; gp
;
5551 gp
+= sizeof(abi_ulong
), q
++) {
5552 if (get_user_ual(addr
, gp
))
5556 if (!(*q
= lock_user_string(addr
)))
5558 total_size
+= strlen(*q
) + 1;
5562 /* This case will not be caught by the host's execve() if its
5563 page size is bigger than the target's. */
5564 if (total_size
> MAX_ARG_PAGES
* TARGET_PAGE_SIZE
) {
5565 ret
= -TARGET_E2BIG
;
5568 if (!(p
= lock_user_string(arg1
)))
5570 ret
= get_errno(execve(p
, argp
, envp
));
5571 unlock_user(p
, arg1
, 0);
5576 ret
= -TARGET_EFAULT
;
5579 for (gp
= guest_argp
, q
= argp
; *q
;
5580 gp
+= sizeof(abi_ulong
), q
++) {
5581 if (get_user_ual(addr
, gp
)
5584 unlock_user(*q
, addr
, 0);
5586 for (gp
= guest_envp
, q
= envp
; *q
;
5587 gp
+= sizeof(abi_ulong
), q
++) {
5588 if (get_user_ual(addr
, gp
)
5591 unlock_user(*q
, addr
, 0);
5595 case TARGET_NR_chdir
:
5596 if (!(p
= lock_user_string(arg1
)))
5598 ret
= get_errno(chdir(p
));
5599 unlock_user(p
, arg1
, 0);
5601 #ifdef TARGET_NR_time
5602 case TARGET_NR_time
:
5605 ret
= get_errno(time(&host_time
));
5608 && put_user_sal(host_time
, arg1
))
5613 case TARGET_NR_mknod
:
5614 if (!(p
= lock_user_string(arg1
)))
5616 ret
= get_errno(mknod(p
, arg2
, arg3
));
5617 unlock_user(p
, arg1
, 0);
5619 #if defined(TARGET_NR_mknodat)
5620 case TARGET_NR_mknodat
:
5621 if (!(p
= lock_user_string(arg2
)))
5623 ret
= get_errno(mknodat(arg1
, p
, arg3
, arg4
));
5624 unlock_user(p
, arg2
, 0);
5627 case TARGET_NR_chmod
:
5628 if (!(p
= lock_user_string(arg1
)))
5630 ret
= get_errno(chmod(p
, arg2
));
5631 unlock_user(p
, arg1
, 0);
5633 #ifdef TARGET_NR_break
5634 case TARGET_NR_break
:
5637 #ifdef TARGET_NR_oldstat
5638 case TARGET_NR_oldstat
:
5641 case TARGET_NR_lseek
:
5642 ret
= get_errno(lseek(arg1
, arg2
, arg3
));
5644 #if defined(TARGET_NR_getxpid) && defined(TARGET_ALPHA)
5645 /* Alpha specific */
5646 case TARGET_NR_getxpid
:
5647 ((CPUAlphaState
*)cpu_env
)->ir
[IR_A4
] = getppid();
5648 ret
= get_errno(getpid());
5651 #ifdef TARGET_NR_getpid
5652 case TARGET_NR_getpid
:
5653 ret
= get_errno(getpid());
5656 case TARGET_NR_mount
:
5658 /* need to look at the data field */
5660 p
= lock_user_string(arg1
);
5661 p2
= lock_user_string(arg2
);
5662 p3
= lock_user_string(arg3
);
5663 if (!p
|| !p2
|| !p3
)
5664 ret
= -TARGET_EFAULT
;
5666 /* FIXME - arg5 should be locked, but it isn't clear how to
5667 * do that since it's not guaranteed to be a NULL-terminated
5671 ret
= get_errno(mount(p
, p2
, p3
, (unsigned long)arg4
, NULL
));
5673 ret
= get_errno(mount(p
, p2
, p3
, (unsigned long)arg4
, g2h(arg5
)));
5675 unlock_user(p
, arg1
, 0);
5676 unlock_user(p2
, arg2
, 0);
5677 unlock_user(p3
, arg3
, 0);
5680 #ifdef TARGET_NR_umount
5681 case TARGET_NR_umount
:
5682 if (!(p
= lock_user_string(arg1
)))
5684 ret
= get_errno(umount(p
));
5685 unlock_user(p
, arg1
, 0);
5688 #ifdef TARGET_NR_stime /* not on alpha */
5689 case TARGET_NR_stime
:
5692 if (get_user_sal(host_time
, arg1
))
5694 ret
= get_errno(stime(&host_time
));
5698 case TARGET_NR_ptrace
:
5700 #ifdef TARGET_NR_alarm /* not on alpha */
5701 case TARGET_NR_alarm
:
5705 #ifdef TARGET_NR_oldfstat
5706 case TARGET_NR_oldfstat
:
5709 #ifdef TARGET_NR_pause /* not on alpha */
5710 case TARGET_NR_pause
:
5711 ret
= get_errno(pause());
5714 #ifdef TARGET_NR_utime
5715 case TARGET_NR_utime
:
5717 struct utimbuf tbuf
, *host_tbuf
;
5718 struct target_utimbuf
*target_tbuf
;
5720 if (!lock_user_struct(VERIFY_READ
, target_tbuf
, arg2
, 1))
5722 tbuf
.actime
= tswapal(target_tbuf
->actime
);
5723 tbuf
.modtime
= tswapal(target_tbuf
->modtime
);
5724 unlock_user_struct(target_tbuf
, arg2
, 0);
5729 if (!(p
= lock_user_string(arg1
)))
5731 ret
= get_errno(utime(p
, host_tbuf
));
5732 unlock_user(p
, arg1
, 0);
5736 case TARGET_NR_utimes
:
5738 struct timeval
*tvp
, tv
[2];
5740 if (copy_from_user_timeval(&tv
[0], arg2
)
5741 || copy_from_user_timeval(&tv
[1],
5742 arg2
+ sizeof(struct target_timeval
)))
5748 if (!(p
= lock_user_string(arg1
)))
5750 ret
= get_errno(utimes(p
, tvp
));
5751 unlock_user(p
, arg1
, 0);
5754 #if defined(TARGET_NR_futimesat)
5755 case TARGET_NR_futimesat
:
5757 struct timeval
*tvp
, tv
[2];
5759 if (copy_from_user_timeval(&tv
[0], arg3
)
5760 || copy_from_user_timeval(&tv
[1],
5761 arg3
+ sizeof(struct target_timeval
)))
5767 if (!(p
= lock_user_string(arg2
)))
5769 ret
= get_errno(futimesat(arg1
, path(p
), tvp
));
5770 unlock_user(p
, arg2
, 0);
5774 #ifdef TARGET_NR_stty
5775 case TARGET_NR_stty
:
5778 #ifdef TARGET_NR_gtty
5779 case TARGET_NR_gtty
:
5782 case TARGET_NR_access
:
5783 if (!(p
= lock_user_string(arg1
)))
5785 ret
= get_errno(access(path(p
), arg2
));
5786 unlock_user(p
, arg1
, 0);
5788 #if defined(TARGET_NR_faccessat) && defined(__NR_faccessat)
5789 case TARGET_NR_faccessat
:
5790 if (!(p
= lock_user_string(arg2
)))
5792 ret
= get_errno(faccessat(arg1
, p
, arg3
, 0));
5793 unlock_user(p
, arg2
, 0);
5796 #ifdef TARGET_NR_nice /* not on alpha */
5797 case TARGET_NR_nice
:
5798 ret
= get_errno(nice(arg1
));
5801 #ifdef TARGET_NR_ftime
5802 case TARGET_NR_ftime
:
5805 case TARGET_NR_sync
:
5809 case TARGET_NR_kill
:
5810 ret
= get_errno(kill(arg1
, target_to_host_signal(arg2
)));
5812 case TARGET_NR_rename
:
5815 p
= lock_user_string(arg1
);
5816 p2
= lock_user_string(arg2
);
5818 ret
= -TARGET_EFAULT
;
5820 ret
= get_errno(rename(p
, p2
));
5821 unlock_user(p2
, arg2
, 0);
5822 unlock_user(p
, arg1
, 0);
5825 #if defined(TARGET_NR_renameat)
5826 case TARGET_NR_renameat
:
5829 p
= lock_user_string(arg2
);
5830 p2
= lock_user_string(arg4
);
5832 ret
= -TARGET_EFAULT
;
5834 ret
= get_errno(renameat(arg1
, p
, arg3
, p2
));
5835 unlock_user(p2
, arg4
, 0);
5836 unlock_user(p
, arg2
, 0);
5840 case TARGET_NR_mkdir
:
5841 if (!(p
= lock_user_string(arg1
)))
5843 ret
= get_errno(mkdir(p
, arg2
));
5844 unlock_user(p
, arg1
, 0);
5846 #if defined(TARGET_NR_mkdirat)
5847 case TARGET_NR_mkdirat
:
5848 if (!(p
= lock_user_string(arg2
)))
5850 ret
= get_errno(mkdirat(arg1
, p
, arg3
));
5851 unlock_user(p
, arg2
, 0);
5854 case TARGET_NR_rmdir
:
5855 if (!(p
= lock_user_string(arg1
)))
5857 ret
= get_errno(rmdir(p
));
5858 unlock_user(p
, arg1
, 0);
5861 ret
= get_errno(dup(arg1
));
5863 case TARGET_NR_pipe
:
5864 ret
= do_pipe(cpu_env
, arg1
, 0, 0);
5866 #ifdef TARGET_NR_pipe2
5867 case TARGET_NR_pipe2
:
5868 ret
= do_pipe(cpu_env
, arg1
,
5869 target_to_host_bitmask(arg2
, fcntl_flags_tbl
), 1);
5872 case TARGET_NR_times
:
5874 struct target_tms
*tmsp
;
5876 ret
= get_errno(times(&tms
));
5878 tmsp
= lock_user(VERIFY_WRITE
, arg1
, sizeof(struct target_tms
), 0);
5881 tmsp
->tms_utime
= tswapal(host_to_target_clock_t(tms
.tms_utime
));
5882 tmsp
->tms_stime
= tswapal(host_to_target_clock_t(tms
.tms_stime
));
5883 tmsp
->tms_cutime
= tswapal(host_to_target_clock_t(tms
.tms_cutime
));
5884 tmsp
->tms_cstime
= tswapal(host_to_target_clock_t(tms
.tms_cstime
));
5887 ret
= host_to_target_clock_t(ret
);
5890 #ifdef TARGET_NR_prof
5891 case TARGET_NR_prof
:
5894 #ifdef TARGET_NR_signal
5895 case TARGET_NR_signal
:
5898 case TARGET_NR_acct
:
5900 ret
= get_errno(acct(NULL
));
5902 if (!(p
= lock_user_string(arg1
)))
5904 ret
= get_errno(acct(path(p
)));
5905 unlock_user(p
, arg1
, 0);
5908 #ifdef TARGET_NR_umount2
5909 case TARGET_NR_umount2
:
5910 if (!(p
= lock_user_string(arg1
)))
5912 ret
= get_errno(umount2(p
, arg2
));
5913 unlock_user(p
, arg1
, 0);
5916 #ifdef TARGET_NR_lock
5917 case TARGET_NR_lock
:
5920 case TARGET_NR_ioctl
:
5921 ret
= do_ioctl(arg1
, arg2
, arg3
);
5923 case TARGET_NR_fcntl
:
5924 ret
= do_fcntl(arg1
, arg2
, arg3
);
5926 #ifdef TARGET_NR_mpx
5930 case TARGET_NR_setpgid
:
5931 ret
= get_errno(setpgid(arg1
, arg2
));
5933 #ifdef TARGET_NR_ulimit
5934 case TARGET_NR_ulimit
:
5937 #ifdef TARGET_NR_oldolduname
5938 case TARGET_NR_oldolduname
:
5941 case TARGET_NR_umask
:
5942 ret
= get_errno(umask(arg1
));
5944 case TARGET_NR_chroot
:
5945 if (!(p
= lock_user_string(arg1
)))
5947 ret
= get_errno(chroot(p
));
5948 unlock_user(p
, arg1
, 0);
5950 case TARGET_NR_ustat
:
5952 case TARGET_NR_dup2
:
5953 ret
= get_errno(dup2(arg1
, arg2
));
5955 #if defined(CONFIG_DUP3) && defined(TARGET_NR_dup3)
5956 case TARGET_NR_dup3
:
5957 ret
= get_errno(dup3(arg1
, arg2
, arg3
));
5960 #ifdef TARGET_NR_getppid /* not on alpha */
5961 case TARGET_NR_getppid
:
5962 ret
= get_errno(getppid());
5965 case TARGET_NR_getpgrp
:
5966 ret
= get_errno(getpgrp());
5968 case TARGET_NR_setsid
:
5969 ret
= get_errno(setsid());
5971 #ifdef TARGET_NR_sigaction
5972 case TARGET_NR_sigaction
:
5974 #if defined(TARGET_ALPHA)
5975 struct target_sigaction act
, oact
, *pact
= 0;
5976 struct target_old_sigaction
*old_act
;
5978 if (!lock_user_struct(VERIFY_READ
, old_act
, arg2
, 1))
5980 act
._sa_handler
= old_act
->_sa_handler
;
5981 target_siginitset(&act
.sa_mask
, old_act
->sa_mask
);
5982 act
.sa_flags
= old_act
->sa_flags
;
5983 act
.sa_restorer
= 0;
5984 unlock_user_struct(old_act
, arg2
, 0);
5987 ret
= get_errno(do_sigaction(arg1
, pact
, &oact
));
5988 if (!is_error(ret
) && arg3
) {
5989 if (!lock_user_struct(VERIFY_WRITE
, old_act
, arg3
, 0))
5991 old_act
->_sa_handler
= oact
._sa_handler
;
5992 old_act
->sa_mask
= oact
.sa_mask
.sig
[0];
5993 old_act
->sa_flags
= oact
.sa_flags
;
5994 unlock_user_struct(old_act
, arg3
, 1);
5996 #elif defined(TARGET_MIPS)
5997 struct target_sigaction act
, oact
, *pact
, *old_act
;
6000 if (!lock_user_struct(VERIFY_READ
, old_act
, arg2
, 1))
6002 act
._sa_handler
= old_act
->_sa_handler
;
6003 target_siginitset(&act
.sa_mask
, old_act
->sa_mask
.sig
[0]);
6004 act
.sa_flags
= old_act
->sa_flags
;
6005 unlock_user_struct(old_act
, arg2
, 0);
6011 ret
= get_errno(do_sigaction(arg1
, pact
, &oact
));
6013 if (!is_error(ret
) && arg3
) {
6014 if (!lock_user_struct(VERIFY_WRITE
, old_act
, arg3
, 0))
6016 old_act
->_sa_handler
= oact
._sa_handler
;
6017 old_act
->sa_flags
= oact
.sa_flags
;
6018 old_act
->sa_mask
.sig
[0] = oact
.sa_mask
.sig
[0];
6019 old_act
->sa_mask
.sig
[1] = 0;
6020 old_act
->sa_mask
.sig
[2] = 0;
6021 old_act
->sa_mask
.sig
[3] = 0;
6022 unlock_user_struct(old_act
, arg3
, 1);
6025 struct target_old_sigaction
*old_act
;
6026 struct target_sigaction act
, oact
, *pact
;
6028 if (!lock_user_struct(VERIFY_READ
, old_act
, arg2
, 1))
6030 act
._sa_handler
= old_act
->_sa_handler
;
6031 target_siginitset(&act
.sa_mask
, old_act
->sa_mask
);
6032 act
.sa_flags
= old_act
->sa_flags
;
6033 act
.sa_restorer
= old_act
->sa_restorer
;
6034 unlock_user_struct(old_act
, arg2
, 0);
6039 ret
= get_errno(do_sigaction(arg1
, pact
, &oact
));
6040 if (!is_error(ret
) && arg3
) {
6041 if (!lock_user_struct(VERIFY_WRITE
, old_act
, arg3
, 0))
6043 old_act
->_sa_handler
= oact
._sa_handler
;
6044 old_act
->sa_mask
= oact
.sa_mask
.sig
[0];
6045 old_act
->sa_flags
= oact
.sa_flags
;
6046 old_act
->sa_restorer
= oact
.sa_restorer
;
6047 unlock_user_struct(old_act
, arg3
, 1);
6053 case TARGET_NR_rt_sigaction
:
6055 #if defined(TARGET_ALPHA)
6056 struct target_sigaction act
, oact
, *pact
= 0;
6057 struct target_rt_sigaction
*rt_act
;
6058 /* ??? arg4 == sizeof(sigset_t). */
6060 if (!lock_user_struct(VERIFY_READ
, rt_act
, arg2
, 1))
6062 act
._sa_handler
= rt_act
->_sa_handler
;
6063 act
.sa_mask
= rt_act
->sa_mask
;
6064 act
.sa_flags
= rt_act
->sa_flags
;
6065 act
.sa_restorer
= arg5
;
6066 unlock_user_struct(rt_act
, arg2
, 0);
6069 ret
= get_errno(do_sigaction(arg1
, pact
, &oact
));
6070 if (!is_error(ret
) && arg3
) {
6071 if (!lock_user_struct(VERIFY_WRITE
, rt_act
, arg3
, 0))
6073 rt_act
->_sa_handler
= oact
._sa_handler
;
6074 rt_act
->sa_mask
= oact
.sa_mask
;
6075 rt_act
->sa_flags
= oact
.sa_flags
;
6076 unlock_user_struct(rt_act
, arg3
, 1);
6079 struct target_sigaction
*act
;
6080 struct target_sigaction
*oact
;
6083 if (!lock_user_struct(VERIFY_READ
, act
, arg2
, 1))
6088 if (!lock_user_struct(VERIFY_WRITE
, oact
, arg3
, 0)) {
6089 ret
= -TARGET_EFAULT
;
6090 goto rt_sigaction_fail
;
6094 ret
= get_errno(do_sigaction(arg1
, act
, oact
));
6097 unlock_user_struct(act
, arg2
, 0);
6099 unlock_user_struct(oact
, arg3
, 1);
6103 #ifdef TARGET_NR_sgetmask /* not on alpha */
6104 case TARGET_NR_sgetmask
:
6107 abi_ulong target_set
;
6108 sigprocmask(0, NULL
, &cur_set
);
6109 host_to_target_old_sigset(&target_set
, &cur_set
);
6114 #ifdef TARGET_NR_ssetmask /* not on alpha */
6115 case TARGET_NR_ssetmask
:
6117 sigset_t set
, oset
, cur_set
;
6118 abi_ulong target_set
= arg1
;
6119 sigprocmask(0, NULL
, &cur_set
);
6120 target_to_host_old_sigset(&set
, &target_set
);
6121 sigorset(&set
, &set
, &cur_set
);
6122 sigprocmask(SIG_SETMASK
, &set
, &oset
);
6123 host_to_target_old_sigset(&target_set
, &oset
);
6128 #ifdef TARGET_NR_sigprocmask
6129 case TARGET_NR_sigprocmask
:
6131 #if defined(TARGET_ALPHA)
6132 sigset_t set
, oldset
;
6137 case TARGET_SIG_BLOCK
:
6140 case TARGET_SIG_UNBLOCK
:
6143 case TARGET_SIG_SETMASK
:
6147 ret
= -TARGET_EINVAL
;
6151 target_to_host_old_sigset(&set
, &mask
);
6153 ret
= get_errno(sigprocmask(how
, &set
, &oldset
));
6154 if (!is_error(ret
)) {
6155 host_to_target_old_sigset(&mask
, &oldset
);
6157 ((CPUAlphaState
*)cpu_env
)->ir
[IR_V0
] = 0; /* force no error */
6160 sigset_t set
, oldset
, *set_ptr
;
6165 case TARGET_SIG_BLOCK
:
6168 case TARGET_SIG_UNBLOCK
:
6171 case TARGET_SIG_SETMASK
:
6175 ret
= -TARGET_EINVAL
;
6178 if (!(p
= lock_user(VERIFY_READ
, arg2
, sizeof(target_sigset_t
), 1)))
6180 target_to_host_old_sigset(&set
, p
);
6181 unlock_user(p
, arg2
, 0);
6187 ret
= get_errno(sigprocmask(how
, set_ptr
, &oldset
));
6188 if (!is_error(ret
) && arg3
) {
6189 if (!(p
= lock_user(VERIFY_WRITE
, arg3
, sizeof(target_sigset_t
), 0)))
6191 host_to_target_old_sigset(p
, &oldset
);
6192 unlock_user(p
, arg3
, sizeof(target_sigset_t
));
6198 case TARGET_NR_rt_sigprocmask
:
6201 sigset_t set
, oldset
, *set_ptr
;
6205 case TARGET_SIG_BLOCK
:
6208 case TARGET_SIG_UNBLOCK
:
6211 case TARGET_SIG_SETMASK
:
6215 ret
= -TARGET_EINVAL
;
6218 if (!(p
= lock_user(VERIFY_READ
, arg2
, sizeof(target_sigset_t
), 1)))
6220 target_to_host_sigset(&set
, p
);
6221 unlock_user(p
, arg2
, 0);
6227 ret
= get_errno(sigprocmask(how
, set_ptr
, &oldset
));
6228 if (!is_error(ret
) && arg3
) {
6229 if (!(p
= lock_user(VERIFY_WRITE
, arg3
, sizeof(target_sigset_t
), 0)))
6231 host_to_target_sigset(p
, &oldset
);
6232 unlock_user(p
, arg3
, sizeof(target_sigset_t
));
6236 #ifdef TARGET_NR_sigpending
6237 case TARGET_NR_sigpending
:
6240 ret
= get_errno(sigpending(&set
));
6241 if (!is_error(ret
)) {
6242 if (!(p
= lock_user(VERIFY_WRITE
, arg1
, sizeof(target_sigset_t
), 0)))
6244 host_to_target_old_sigset(p
, &set
);
6245 unlock_user(p
, arg1
, sizeof(target_sigset_t
));
6250 case TARGET_NR_rt_sigpending
:
6253 ret
= get_errno(sigpending(&set
));
6254 if (!is_error(ret
)) {
6255 if (!(p
= lock_user(VERIFY_WRITE
, arg1
, sizeof(target_sigset_t
), 0)))
6257 host_to_target_sigset(p
, &set
);
6258 unlock_user(p
, arg1
, sizeof(target_sigset_t
));
6262 #ifdef TARGET_NR_sigsuspend
6263 case TARGET_NR_sigsuspend
:
6266 #if defined(TARGET_ALPHA)
6267 abi_ulong mask
= arg1
;
6268 target_to_host_old_sigset(&set
, &mask
);
6270 if (!(p
= lock_user(VERIFY_READ
, arg1
, sizeof(target_sigset_t
), 1)))
6272 target_to_host_old_sigset(&set
, p
);
6273 unlock_user(p
, arg1
, 0);
6275 ret
= get_errno(sigsuspend(&set
));
6279 case TARGET_NR_rt_sigsuspend
:
6282 if (!(p
= lock_user(VERIFY_READ
, arg1
, sizeof(target_sigset_t
), 1)))
6284 target_to_host_sigset(&set
, p
);
6285 unlock_user(p
, arg1
, 0);
6286 ret
= get_errno(sigsuspend(&set
));
6289 case TARGET_NR_rt_sigtimedwait
:
6292 struct timespec uts
, *puts
;
6295 if (!(p
= lock_user(VERIFY_READ
, arg1
, sizeof(target_sigset_t
), 1)))
6297 target_to_host_sigset(&set
, p
);
6298 unlock_user(p
, arg1
, 0);
6301 target_to_host_timespec(puts
, arg3
);
6305 ret
= get_errno(sigtimedwait(&set
, &uinfo
, puts
));
6306 if (!is_error(ret
) && arg2
) {
6307 if (!(p
= lock_user(VERIFY_WRITE
, arg2
, sizeof(target_siginfo_t
), 0)))
6309 host_to_target_siginfo(p
, &uinfo
);
6310 unlock_user(p
, arg2
, sizeof(target_siginfo_t
));
6314 case TARGET_NR_rt_sigqueueinfo
:
6317 if (!(p
= lock_user(VERIFY_READ
, arg3
, sizeof(target_sigset_t
), 1)))
6319 target_to_host_siginfo(&uinfo
, p
);
6320 unlock_user(p
, arg1
, 0);
6321 ret
= get_errno(sys_rt_sigqueueinfo(arg1
, arg2
, &uinfo
));
6324 #ifdef TARGET_NR_sigreturn
6325 case TARGET_NR_sigreturn
:
6326 /* NOTE: ret is eax, so not transcoding must be done */
6327 ret
= do_sigreturn(cpu_env
);
6330 case TARGET_NR_rt_sigreturn
:
6331 /* NOTE: ret is eax, so not transcoding must be done */
6332 ret
= do_rt_sigreturn(cpu_env
);
6334 case TARGET_NR_sethostname
:
6335 if (!(p
= lock_user_string(arg1
)))
6337 ret
= get_errno(sethostname(p
, arg2
));
6338 unlock_user(p
, arg1
, 0);
6340 case TARGET_NR_setrlimit
:
6342 int resource
= target_to_host_resource(arg1
);
6343 struct target_rlimit
*target_rlim
;
6345 if (!lock_user_struct(VERIFY_READ
, target_rlim
, arg2
, 1))
6347 rlim
.rlim_cur
= target_to_host_rlim(target_rlim
->rlim_cur
);
6348 rlim
.rlim_max
= target_to_host_rlim(target_rlim
->rlim_max
);
6349 unlock_user_struct(target_rlim
, arg2
, 0);
6350 ret
= get_errno(setrlimit(resource
, &rlim
));
6353 case TARGET_NR_getrlimit
:
6355 int resource
= target_to_host_resource(arg1
);
6356 struct target_rlimit
*target_rlim
;
6359 ret
= get_errno(getrlimit(resource
, &rlim
));
6360 if (!is_error(ret
)) {
6361 if (!lock_user_struct(VERIFY_WRITE
, target_rlim
, arg2
, 0))
6363 target_rlim
->rlim_cur
= host_to_target_rlim(rlim
.rlim_cur
);
6364 target_rlim
->rlim_max
= host_to_target_rlim(rlim
.rlim_max
);
6365 unlock_user_struct(target_rlim
, arg2
, 1);
6369 case TARGET_NR_getrusage
:
6371 struct rusage rusage
;
6372 ret
= get_errno(getrusage(arg1
, &rusage
));
6373 if (!is_error(ret
)) {
6374 host_to_target_rusage(arg2
, &rusage
);
6378 case TARGET_NR_gettimeofday
:
6381 ret
= get_errno(gettimeofday(&tv
, NULL
));
6382 if (!is_error(ret
)) {
6383 if (copy_to_user_timeval(arg1
, &tv
))
6388 case TARGET_NR_settimeofday
:
6391 if (copy_from_user_timeval(&tv
, arg1
))
6393 ret
= get_errno(settimeofday(&tv
, NULL
));
6396 #if defined(TARGET_NR_select)
6397 case TARGET_NR_select
:
6398 #if defined(TARGET_S390X) || defined(TARGET_ALPHA)
6399 ret
= do_select(arg1
, arg2
, arg3
, arg4
, arg5
);
6402 struct target_sel_arg_struct
*sel
;
6403 abi_ulong inp
, outp
, exp
, tvp
;
6406 if (!lock_user_struct(VERIFY_READ
, sel
, arg1
, 1))
6408 nsel
= tswapal(sel
->n
);
6409 inp
= tswapal(sel
->inp
);
6410 outp
= tswapal(sel
->outp
);
6411 exp
= tswapal(sel
->exp
);
6412 tvp
= tswapal(sel
->tvp
);
6413 unlock_user_struct(sel
, arg1
, 0);
6414 ret
= do_select(nsel
, inp
, outp
, exp
, tvp
);
6419 #ifdef TARGET_NR_pselect6
6420 case TARGET_NR_pselect6
:
6422 abi_long rfd_addr
, wfd_addr
, efd_addr
, n
, ts_addr
;
6423 fd_set rfds
, wfds
, efds
;
6424 fd_set
*rfds_ptr
, *wfds_ptr
, *efds_ptr
;
6425 struct timespec ts
, *ts_ptr
;
6428 * The 6th arg is actually two args smashed together,
6429 * so we cannot use the C library.
6437 abi_ulong arg_sigset
, arg_sigsize
, *arg7
;
6438 target_sigset_t
*target_sigset
;
6446 ret
= copy_from_user_fdset_ptr(&rfds
, &rfds_ptr
, rfd_addr
, n
);
6450 ret
= copy_from_user_fdset_ptr(&wfds
, &wfds_ptr
, wfd_addr
, n
);
6454 ret
= copy_from_user_fdset_ptr(&efds
, &efds_ptr
, efd_addr
, n
);
6460 * This takes a timespec, and not a timeval, so we cannot
6461 * use the do_select() helper ...
6464 if (target_to_host_timespec(&ts
, ts_addr
)) {
6472 /* Extract the two packed args for the sigset */
6475 sig
.size
= _NSIG
/ 8;
6477 arg7
= lock_user(VERIFY_READ
, arg6
, sizeof(*arg7
) * 2, 1);
6481 arg_sigset
= tswapal(arg7
[0]);
6482 arg_sigsize
= tswapal(arg7
[1]);
6483 unlock_user(arg7
, arg6
, 0);
6487 if (arg_sigsize
!= sizeof(*target_sigset
)) {
6488 /* Like the kernel, we enforce correct size sigsets */
6489 ret
= -TARGET_EINVAL
;
6492 target_sigset
= lock_user(VERIFY_READ
, arg_sigset
,
6493 sizeof(*target_sigset
), 1);
6494 if (!target_sigset
) {
6497 target_to_host_sigset(&set
, target_sigset
);
6498 unlock_user(target_sigset
, arg_sigset
, 0);
6506 ret
= get_errno(sys_pselect6(n
, rfds_ptr
, wfds_ptr
, efds_ptr
,
6509 if (!is_error(ret
)) {
6510 if (rfd_addr
&& copy_to_user_fdset(rfd_addr
, &rfds
, n
))
6512 if (wfd_addr
&& copy_to_user_fdset(wfd_addr
, &wfds
, n
))
6514 if (efd_addr
&& copy_to_user_fdset(efd_addr
, &efds
, n
))
6517 if (ts_addr
&& host_to_target_timespec(ts_addr
, &ts
))
6523 case TARGET_NR_symlink
:
6526 p
= lock_user_string(arg1
);
6527 p2
= lock_user_string(arg2
);
6529 ret
= -TARGET_EFAULT
;
6531 ret
= get_errno(symlink(p
, p2
));
6532 unlock_user(p2
, arg2
, 0);
6533 unlock_user(p
, arg1
, 0);
6536 #if defined(TARGET_NR_symlinkat)
6537 case TARGET_NR_symlinkat
:
6540 p
= lock_user_string(arg1
);
6541 p2
= lock_user_string(arg3
);
6543 ret
= -TARGET_EFAULT
;
6545 ret
= get_errno(symlinkat(p
, arg2
, p2
));
6546 unlock_user(p2
, arg3
, 0);
6547 unlock_user(p
, arg1
, 0);
6551 #ifdef TARGET_NR_oldlstat
6552 case TARGET_NR_oldlstat
:
6555 case TARGET_NR_readlink
:
6558 p
= lock_user_string(arg1
);
6559 p2
= lock_user(VERIFY_WRITE
, arg2
, arg3
, 0);
6561 ret
= -TARGET_EFAULT
;
6562 } else if (is_proc_myself((const char *)p
, "exe")) {
6563 char real
[PATH_MAX
], *temp
;
6564 temp
= realpath(exec_path
, real
);
6565 ret
= temp
== NULL
? get_errno(-1) : strlen(real
) ;
6566 snprintf((char *)p2
, arg3
, "%s", real
);
6568 ret
= get_errno(readlink(path(p
), p2
, arg3
));
6570 unlock_user(p2
, arg2
, ret
);
6571 unlock_user(p
, arg1
, 0);
6574 #if defined(TARGET_NR_readlinkat)
6575 case TARGET_NR_readlinkat
:
6578 p
= lock_user_string(arg2
);
6579 p2
= lock_user(VERIFY_WRITE
, arg3
, arg4
, 0);
6581 ret
= -TARGET_EFAULT
;
6582 } else if (is_proc_myself((const char *)p
, "exe")) {
6583 char real
[PATH_MAX
], *temp
;
6584 temp
= realpath(exec_path
, real
);
6585 ret
= temp
== NULL
? get_errno(-1) : strlen(real
) ;
6586 snprintf((char *)p2
, arg4
, "%s", real
);
6588 ret
= get_errno(readlinkat(arg1
, path(p
), p2
, arg4
));
6590 unlock_user(p2
, arg3
, ret
);
6591 unlock_user(p
, arg2
, 0);
6595 #ifdef TARGET_NR_uselib
6596 case TARGET_NR_uselib
:
6599 #ifdef TARGET_NR_swapon
6600 case TARGET_NR_swapon
:
6601 if (!(p
= lock_user_string(arg1
)))
6603 ret
= get_errno(swapon(p
, arg2
));
6604 unlock_user(p
, arg1
, 0);
6607 case TARGET_NR_reboot
:
6608 if (arg3
== LINUX_REBOOT_CMD_RESTART2
) {
6609 /* arg4 must be ignored in all other cases */
6610 p
= lock_user_string(arg4
);
6614 ret
= get_errno(reboot(arg1
, arg2
, arg3
, p
));
6615 unlock_user(p
, arg4
, 0);
6617 ret
= get_errno(reboot(arg1
, arg2
, arg3
, NULL
));
6620 #ifdef TARGET_NR_readdir
6621 case TARGET_NR_readdir
:
6624 #ifdef TARGET_NR_mmap
6625 case TARGET_NR_mmap
:
6626 #if (defined(TARGET_I386) && defined(TARGET_ABI32)) || \
6627 (defined(TARGET_ARM) && defined(TARGET_ABI32)) || \
6628 defined(TARGET_M68K) || defined(TARGET_CRIS) || defined(TARGET_MICROBLAZE) \
6629 || defined(TARGET_S390X)
6632 abi_ulong v1
, v2
, v3
, v4
, v5
, v6
;
6633 if (!(v
= lock_user(VERIFY_READ
, arg1
, 6 * sizeof(abi_ulong
), 1)))
6641 unlock_user(v
, arg1
, 0);
6642 ret
= get_errno(target_mmap(v1
, v2
, v3
,
6643 target_to_host_bitmask(v4
, mmap_flags_tbl
),
6647 ret
= get_errno(target_mmap(arg1
, arg2
, arg3
,
6648 target_to_host_bitmask(arg4
, mmap_flags_tbl
),
6654 #ifdef TARGET_NR_mmap2
6655 case TARGET_NR_mmap2
:
6657 #define MMAP_SHIFT 12
6659 ret
= get_errno(target_mmap(arg1
, arg2
, arg3
,
6660 target_to_host_bitmask(arg4
, mmap_flags_tbl
),
6662 arg6
<< MMAP_SHIFT
));
6665 case TARGET_NR_munmap
:
6666 ret
= get_errno(target_munmap(arg1
, arg2
));
6668 case TARGET_NR_mprotect
:
6670 TaskState
*ts
= ((CPUArchState
*)cpu_env
)->opaque
;
6671 /* Special hack to detect libc making the stack executable. */
6672 if ((arg3
& PROT_GROWSDOWN
)
6673 && arg1
>= ts
->info
->stack_limit
6674 && arg1
<= ts
->info
->start_stack
) {
6675 arg3
&= ~PROT_GROWSDOWN
;
6676 arg2
= arg2
+ arg1
- ts
->info
->stack_limit
;
6677 arg1
= ts
->info
->stack_limit
;
6680 ret
= get_errno(target_mprotect(arg1
, arg2
, arg3
));
6682 #ifdef TARGET_NR_mremap
6683 case TARGET_NR_mremap
:
6684 ret
= get_errno(target_mremap(arg1
, arg2
, arg3
, arg4
, arg5
));
6687 /* ??? msync/mlock/munlock are broken for softmmu. */
6688 #ifdef TARGET_NR_msync
6689 case TARGET_NR_msync
:
6690 ret
= get_errno(msync(g2h(arg1
), arg2
, arg3
));
6693 #ifdef TARGET_NR_mlock
6694 case TARGET_NR_mlock
:
6695 ret
= get_errno(mlock(g2h(arg1
), arg2
));
6698 #ifdef TARGET_NR_munlock
6699 case TARGET_NR_munlock
:
6700 ret
= get_errno(munlock(g2h(arg1
), arg2
));
6703 #ifdef TARGET_NR_mlockall
6704 case TARGET_NR_mlockall
:
6705 ret
= get_errno(mlockall(arg1
));
6708 #ifdef TARGET_NR_munlockall
6709 case TARGET_NR_munlockall
:
6710 ret
= get_errno(munlockall());
6713 case TARGET_NR_truncate
:
6714 if (!(p
= lock_user_string(arg1
)))
6716 ret
= get_errno(truncate(p
, arg2
));
6717 unlock_user(p
, arg1
, 0);
6719 case TARGET_NR_ftruncate
:
6720 ret
= get_errno(ftruncate(arg1
, arg2
));
6722 case TARGET_NR_fchmod
:
6723 ret
= get_errno(fchmod(arg1
, arg2
));
6725 #if defined(TARGET_NR_fchmodat)
6726 case TARGET_NR_fchmodat
:
6727 if (!(p
= lock_user_string(arg2
)))
6729 ret
= get_errno(fchmodat(arg1
, p
, arg3
, 0));
6730 unlock_user(p
, arg2
, 0);
6733 case TARGET_NR_getpriority
:
6734 /* Note that negative values are valid for getpriority, so we must
6735 differentiate based on errno settings. */
6737 ret
= getpriority(arg1
, arg2
);
6738 if (ret
== -1 && errno
!= 0) {
6739 ret
= -host_to_target_errno(errno
);
6743 /* Return value is the unbiased priority. Signal no error. */
6744 ((CPUAlphaState
*)cpu_env
)->ir
[IR_V0
] = 0;
6746 /* Return value is a biased priority to avoid negative numbers. */
6750 case TARGET_NR_setpriority
:
6751 ret
= get_errno(setpriority(arg1
, arg2
, arg3
));
6753 #ifdef TARGET_NR_profil
6754 case TARGET_NR_profil
:
6757 case TARGET_NR_statfs
:
6758 if (!(p
= lock_user_string(arg1
)))
6760 ret
= get_errno(statfs(path(p
), &stfs
));
6761 unlock_user(p
, arg1
, 0);
6763 if (!is_error(ret
)) {
6764 struct target_statfs
*target_stfs
;
6766 if (!lock_user_struct(VERIFY_WRITE
, target_stfs
, arg2
, 0))
6768 __put_user(stfs
.f_type
, &target_stfs
->f_type
);
6769 __put_user(stfs
.f_bsize
, &target_stfs
->f_bsize
);
6770 __put_user(stfs
.f_blocks
, &target_stfs
->f_blocks
);
6771 __put_user(stfs
.f_bfree
, &target_stfs
->f_bfree
);
6772 __put_user(stfs
.f_bavail
, &target_stfs
->f_bavail
);
6773 __put_user(stfs
.f_files
, &target_stfs
->f_files
);
6774 __put_user(stfs
.f_ffree
, &target_stfs
->f_ffree
);
6775 __put_user(stfs
.f_fsid
.__val
[0], &target_stfs
->f_fsid
.val
[0]);
6776 __put_user(stfs
.f_fsid
.__val
[1], &target_stfs
->f_fsid
.val
[1]);
6777 __put_user(stfs
.f_namelen
, &target_stfs
->f_namelen
);
6778 __put_user(stfs
.f_frsize
, &target_stfs
->f_frsize
);
6779 memset(target_stfs
->f_spare
, 0, sizeof(target_stfs
->f_spare
));
6780 unlock_user_struct(target_stfs
, arg2
, 1);
6783 case TARGET_NR_fstatfs
:
6784 ret
= get_errno(fstatfs(arg1
, &stfs
));
6785 goto convert_statfs
;
6786 #ifdef TARGET_NR_statfs64
6787 case TARGET_NR_statfs64
:
6788 if (!(p
= lock_user_string(arg1
)))
6790 ret
= get_errno(statfs(path(p
), &stfs
));
6791 unlock_user(p
, arg1
, 0);
6793 if (!is_error(ret
)) {
6794 struct target_statfs64
*target_stfs
;
6796 if (!lock_user_struct(VERIFY_WRITE
, target_stfs
, arg3
, 0))
6798 __put_user(stfs
.f_type
, &target_stfs
->f_type
);
6799 __put_user(stfs
.f_bsize
, &target_stfs
->f_bsize
);
6800 __put_user(stfs
.f_blocks
, &target_stfs
->f_blocks
);
6801 __put_user(stfs
.f_bfree
, &target_stfs
->f_bfree
);
6802 __put_user(stfs
.f_bavail
, &target_stfs
->f_bavail
);
6803 __put_user(stfs
.f_files
, &target_stfs
->f_files
);
6804 __put_user(stfs
.f_ffree
, &target_stfs
->f_ffree
);
6805 __put_user(stfs
.f_fsid
.__val
[0], &target_stfs
->f_fsid
.val
[0]);
6806 __put_user(stfs
.f_fsid
.__val
[1], &target_stfs
->f_fsid
.val
[1]);
6807 __put_user(stfs
.f_namelen
, &target_stfs
->f_namelen
);
6808 __put_user(stfs
.f_frsize
, &target_stfs
->f_frsize
);
6809 memset(target_stfs
->f_spare
, 0, sizeof(target_stfs
->f_spare
));
6810 unlock_user_struct(target_stfs
, arg3
, 1);
6813 case TARGET_NR_fstatfs64
:
6814 ret
= get_errno(fstatfs(arg1
, &stfs
));
6815 goto convert_statfs64
;
6817 #ifdef TARGET_NR_ioperm
6818 case TARGET_NR_ioperm
:
6821 #ifdef TARGET_NR_socketcall
6822 case TARGET_NR_socketcall
:
6823 ret
= do_socketcall(arg1
, arg2
);
6826 #ifdef TARGET_NR_accept
6827 case TARGET_NR_accept
:
6828 ret
= do_accept4(arg1
, arg2
, arg3
, 0);
6831 #ifdef TARGET_NR_accept4
6832 case TARGET_NR_accept4
:
6833 #ifdef CONFIG_ACCEPT4
6834 ret
= do_accept4(arg1
, arg2
, arg3
, arg4
);
6840 #ifdef TARGET_NR_bind
6841 case TARGET_NR_bind
:
6842 ret
= do_bind(arg1
, arg2
, arg3
);
6845 #ifdef TARGET_NR_connect
6846 case TARGET_NR_connect
:
6847 ret
= do_connect(arg1
, arg2
, arg3
);
6850 #ifdef TARGET_NR_getpeername
6851 case TARGET_NR_getpeername
:
6852 ret
= do_getpeername(arg1
, arg2
, arg3
);
6855 #ifdef TARGET_NR_getsockname
6856 case TARGET_NR_getsockname
:
6857 ret
= do_getsockname(arg1
, arg2
, arg3
);
6860 #ifdef TARGET_NR_getsockopt
6861 case TARGET_NR_getsockopt
:
6862 ret
= do_getsockopt(arg1
, arg2
, arg3
, arg4
, arg5
);
6865 #ifdef TARGET_NR_listen
6866 case TARGET_NR_listen
:
6867 ret
= get_errno(listen(arg1
, arg2
));
6870 #ifdef TARGET_NR_recv
6871 case TARGET_NR_recv
:
6872 ret
= do_recvfrom(arg1
, arg2
, arg3
, arg4
, 0, 0);
6875 #ifdef TARGET_NR_recvfrom
6876 case TARGET_NR_recvfrom
:
6877 ret
= do_recvfrom(arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
6880 #ifdef TARGET_NR_recvmsg
6881 case TARGET_NR_recvmsg
:
6882 ret
= do_sendrecvmsg(arg1
, arg2
, arg3
, 0);
6885 #ifdef TARGET_NR_send
6886 case TARGET_NR_send
:
6887 ret
= do_sendto(arg1
, arg2
, arg3
, arg4
, 0, 0);
6890 #ifdef TARGET_NR_sendmsg
6891 case TARGET_NR_sendmsg
:
6892 ret
= do_sendrecvmsg(arg1
, arg2
, arg3
, 1);
6895 #ifdef TARGET_NR_sendto
6896 case TARGET_NR_sendto
:
6897 ret
= do_sendto(arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
6900 #ifdef TARGET_NR_shutdown
6901 case TARGET_NR_shutdown
:
6902 ret
= get_errno(shutdown(arg1
, arg2
));
6905 #ifdef TARGET_NR_socket
6906 case TARGET_NR_socket
:
6907 ret
= do_socket(arg1
, arg2
, arg3
);
6910 #ifdef TARGET_NR_socketpair
6911 case TARGET_NR_socketpair
:
6912 ret
= do_socketpair(arg1
, arg2
, arg3
, arg4
);
6915 #ifdef TARGET_NR_setsockopt
6916 case TARGET_NR_setsockopt
:
6917 ret
= do_setsockopt(arg1
, arg2
, arg3
, arg4
, (socklen_t
) arg5
);
6921 case TARGET_NR_syslog
:
6922 if (!(p
= lock_user_string(arg2
)))
6924 ret
= get_errno(sys_syslog((int)arg1
, p
, (int)arg3
));
6925 unlock_user(p
, arg2
, 0);
6928 case TARGET_NR_setitimer
:
6930 struct itimerval value
, ovalue
, *pvalue
;
6934 if (copy_from_user_timeval(&pvalue
->it_interval
, arg2
)
6935 || copy_from_user_timeval(&pvalue
->it_value
,
6936 arg2
+ sizeof(struct target_timeval
)))
6941 ret
= get_errno(setitimer(arg1
, pvalue
, &ovalue
));
6942 if (!is_error(ret
) && arg3
) {
6943 if (copy_to_user_timeval(arg3
,
6944 &ovalue
.it_interval
)
6945 || copy_to_user_timeval(arg3
+ sizeof(struct target_timeval
),
6951 case TARGET_NR_getitimer
:
6953 struct itimerval value
;
6955 ret
= get_errno(getitimer(arg1
, &value
));
6956 if (!is_error(ret
) && arg2
) {
6957 if (copy_to_user_timeval(arg2
,
6959 || copy_to_user_timeval(arg2
+ sizeof(struct target_timeval
),
6965 case TARGET_NR_stat
:
6966 if (!(p
= lock_user_string(arg1
)))
6968 ret
= get_errno(stat(path(p
), &st
));
6969 unlock_user(p
, arg1
, 0);
6971 case TARGET_NR_lstat
:
6972 if (!(p
= lock_user_string(arg1
)))
6974 ret
= get_errno(lstat(path(p
), &st
));
6975 unlock_user(p
, arg1
, 0);
6977 case TARGET_NR_fstat
:
6979 ret
= get_errno(fstat(arg1
, &st
));
6981 if (!is_error(ret
)) {
6982 struct target_stat
*target_st
;
6984 if (!lock_user_struct(VERIFY_WRITE
, target_st
, arg2
, 0))
6986 memset(target_st
, 0, sizeof(*target_st
));
6987 __put_user(st
.st_dev
, &target_st
->st_dev
);
6988 __put_user(st
.st_ino
, &target_st
->st_ino
);
6989 __put_user(st
.st_mode
, &target_st
->st_mode
);
6990 __put_user(st
.st_uid
, &target_st
->st_uid
);
6991 __put_user(st
.st_gid
, &target_st
->st_gid
);
6992 __put_user(st
.st_nlink
, &target_st
->st_nlink
);
6993 __put_user(st
.st_rdev
, &target_st
->st_rdev
);
6994 __put_user(st
.st_size
, &target_st
->st_size
);
6995 __put_user(st
.st_blksize
, &target_st
->st_blksize
);
6996 __put_user(st
.st_blocks
, &target_st
->st_blocks
);
6997 __put_user(st
.st_atime
, &target_st
->target_st_atime
);
6998 __put_user(st
.st_mtime
, &target_st
->target_st_mtime
);
6999 __put_user(st
.st_ctime
, &target_st
->target_st_ctime
);
7000 unlock_user_struct(target_st
, arg2
, 1);
7004 #ifdef TARGET_NR_olduname
7005 case TARGET_NR_olduname
:
7008 #ifdef TARGET_NR_iopl
7009 case TARGET_NR_iopl
:
7012 case TARGET_NR_vhangup
:
7013 ret
= get_errno(vhangup());
7015 #ifdef TARGET_NR_idle
7016 case TARGET_NR_idle
:
7019 #ifdef TARGET_NR_syscall
7020 case TARGET_NR_syscall
:
7021 ret
= do_syscall(cpu_env
, arg1
& 0xffff, arg2
, arg3
, arg4
, arg5
,
7022 arg6
, arg7
, arg8
, 0);
7025 case TARGET_NR_wait4
:
7028 abi_long status_ptr
= arg2
;
7029 struct rusage rusage
, *rusage_ptr
;
7030 abi_ulong target_rusage
= arg4
;
7032 rusage_ptr
= &rusage
;
7035 ret
= get_errno(wait4(arg1
, &status
, arg3
, rusage_ptr
));
7036 if (!is_error(ret
)) {
7037 if (status_ptr
&& ret
) {
7038 status
= host_to_target_waitstatus(status
);
7039 if (put_user_s32(status
, status_ptr
))
7043 host_to_target_rusage(target_rusage
, &rusage
);
7047 #ifdef TARGET_NR_swapoff
7048 case TARGET_NR_swapoff
:
7049 if (!(p
= lock_user_string(arg1
)))
7051 ret
= get_errno(swapoff(p
));
7052 unlock_user(p
, arg1
, 0);
7055 case TARGET_NR_sysinfo
:
7057 struct target_sysinfo
*target_value
;
7058 struct sysinfo value
;
7059 ret
= get_errno(sysinfo(&value
));
7060 if (!is_error(ret
) && arg1
)
7062 if (!lock_user_struct(VERIFY_WRITE
, target_value
, arg1
, 0))
7064 __put_user(value
.uptime
, &target_value
->uptime
);
7065 __put_user(value
.loads
[0], &target_value
->loads
[0]);
7066 __put_user(value
.loads
[1], &target_value
->loads
[1]);
7067 __put_user(value
.loads
[2], &target_value
->loads
[2]);
7068 __put_user(value
.totalram
, &target_value
->totalram
);
7069 __put_user(value
.freeram
, &target_value
->freeram
);
7070 __put_user(value
.sharedram
, &target_value
->sharedram
);
7071 __put_user(value
.bufferram
, &target_value
->bufferram
);
7072 __put_user(value
.totalswap
, &target_value
->totalswap
);
7073 __put_user(value
.freeswap
, &target_value
->freeswap
);
7074 __put_user(value
.procs
, &target_value
->procs
);
7075 __put_user(value
.totalhigh
, &target_value
->totalhigh
);
7076 __put_user(value
.freehigh
, &target_value
->freehigh
);
7077 __put_user(value
.mem_unit
, &target_value
->mem_unit
);
7078 unlock_user_struct(target_value
, arg1
, 1);
7082 #ifdef TARGET_NR_ipc
7084 ret
= do_ipc(arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
7087 #ifdef TARGET_NR_semget
7088 case TARGET_NR_semget
:
7089 ret
= get_errno(semget(arg1
, arg2
, arg3
));
7092 #ifdef TARGET_NR_semop
7093 case TARGET_NR_semop
:
7094 ret
= do_semop(arg1
, arg2
, arg3
);
7097 #ifdef TARGET_NR_semctl
7098 case TARGET_NR_semctl
:
7099 ret
= do_semctl(arg1
, arg2
, arg3
, (union target_semun
)(abi_ulong
)arg4
);
7102 #ifdef TARGET_NR_msgctl
7103 case TARGET_NR_msgctl
:
7104 ret
= do_msgctl(arg1
, arg2
, arg3
);
7107 #ifdef TARGET_NR_msgget
7108 case TARGET_NR_msgget
:
7109 ret
= get_errno(msgget(arg1
, arg2
));
7112 #ifdef TARGET_NR_msgrcv
7113 case TARGET_NR_msgrcv
:
7114 ret
= do_msgrcv(arg1
, arg2
, arg3
, arg4
, arg5
);
7117 #ifdef TARGET_NR_msgsnd
7118 case TARGET_NR_msgsnd
:
7119 ret
= do_msgsnd(arg1
, arg2
, arg3
, arg4
);
7122 #ifdef TARGET_NR_shmget
7123 case TARGET_NR_shmget
:
7124 ret
= get_errno(shmget(arg1
, arg2
, arg3
));
7127 #ifdef TARGET_NR_shmctl
7128 case TARGET_NR_shmctl
:
7129 ret
= do_shmctl(arg1
, arg2
, arg3
);
7132 #ifdef TARGET_NR_shmat
7133 case TARGET_NR_shmat
:
7134 ret
= do_shmat(arg1
, arg2
, arg3
);
7137 #ifdef TARGET_NR_shmdt
7138 case TARGET_NR_shmdt
:
7139 ret
= do_shmdt(arg1
);
7142 case TARGET_NR_fsync
:
7143 ret
= get_errno(fsync(arg1
));
7145 case TARGET_NR_clone
:
7146 /* Linux manages to have three different orderings for its
7147 * arguments to clone(); the BACKWARDS and BACKWARDS2 defines
7148 * match the kernel's CONFIG_CLONE_* settings.
7149 * Microblaze is further special in that it uses a sixth
7150 * implicit argument to clone for the TLS pointer.
7152 #if defined(TARGET_MICROBLAZE)
7153 ret
= get_errno(do_fork(cpu_env
, arg1
, arg2
, arg4
, arg6
, arg5
));
7154 #elif defined(TARGET_CLONE_BACKWARDS)
7155 ret
= get_errno(do_fork(cpu_env
, arg1
, arg2
, arg3
, arg4
, arg5
));
7156 #elif defined(TARGET_CLONE_BACKWARDS2)
7157 ret
= get_errno(do_fork(cpu_env
, arg2
, arg1
, arg3
, arg5
, arg4
));
7159 ret
= get_errno(do_fork(cpu_env
, arg1
, arg2
, arg3
, arg5
, arg4
));
7162 #ifdef __NR_exit_group
7163 /* new thread calls */
7164 case TARGET_NR_exit_group
:
7168 gdb_exit(cpu_env
, arg1
);
7169 ret
= get_errno(exit_group(arg1
));
7172 case TARGET_NR_setdomainname
:
7173 if (!(p
= lock_user_string(arg1
)))
7175 ret
= get_errno(setdomainname(p
, arg2
));
7176 unlock_user(p
, arg1
, 0);
7178 case TARGET_NR_uname
:
7179 /* no need to transcode because we use the linux syscall */
7181 struct new_utsname
* buf
;
7183 if (!lock_user_struct(VERIFY_WRITE
, buf
, arg1
, 0))
7185 ret
= get_errno(sys_uname(buf
));
7186 if (!is_error(ret
)) {
7187 /* Overrite the native machine name with whatever is being
7189 strcpy (buf
->machine
, cpu_to_uname_machine(cpu_env
));
7190 /* Allow the user to override the reported release. */
7191 if (qemu_uname_release
&& *qemu_uname_release
)
7192 strcpy (buf
->release
, qemu_uname_release
);
7194 unlock_user_struct(buf
, arg1
, 1);
7198 case TARGET_NR_modify_ldt
:
7199 ret
= do_modify_ldt(cpu_env
, arg1
, arg2
, arg3
);
7201 #if !defined(TARGET_X86_64)
7202 case TARGET_NR_vm86old
:
7204 case TARGET_NR_vm86
:
7205 ret
= do_vm86(cpu_env
, arg1
, arg2
);
7209 case TARGET_NR_adjtimex
:
7211 #ifdef TARGET_NR_create_module
7212 case TARGET_NR_create_module
:
7214 case TARGET_NR_init_module
:
7215 case TARGET_NR_delete_module
:
7216 #ifdef TARGET_NR_get_kernel_syms
7217 case TARGET_NR_get_kernel_syms
:
7220 case TARGET_NR_quotactl
:
7222 case TARGET_NR_getpgid
:
7223 ret
= get_errno(getpgid(arg1
));
7225 case TARGET_NR_fchdir
:
7226 ret
= get_errno(fchdir(arg1
));
7228 #ifdef TARGET_NR_bdflush /* not on x86_64 */
7229 case TARGET_NR_bdflush
:
7232 #ifdef TARGET_NR_sysfs
7233 case TARGET_NR_sysfs
:
7236 case TARGET_NR_personality
:
7237 ret
= get_errno(personality(arg1
));
7239 #ifdef TARGET_NR_afs_syscall
7240 case TARGET_NR_afs_syscall
:
7243 #ifdef TARGET_NR__llseek /* Not on alpha */
7244 case TARGET_NR__llseek
:
7247 #if !defined(__NR_llseek)
7248 res
= lseek(arg1
, ((uint64_t)arg2
<< 32) | arg3
, arg5
);
7250 ret
= get_errno(res
);
7255 ret
= get_errno(_llseek(arg1
, arg2
, arg3
, &res
, arg5
));
7257 if ((ret
== 0) && put_user_s64(res
, arg4
)) {
7263 case TARGET_NR_getdents
:
7264 #ifdef __NR_getdents
7265 #if TARGET_ABI_BITS == 32 && HOST_LONG_BITS == 64
7267 struct target_dirent
*target_dirp
;
7268 struct linux_dirent
*dirp
;
7269 abi_long count
= arg3
;
7271 dirp
= malloc(count
);
7273 ret
= -TARGET_ENOMEM
;
7277 ret
= get_errno(sys_getdents(arg1
, dirp
, count
));
7278 if (!is_error(ret
)) {
7279 struct linux_dirent
*de
;
7280 struct target_dirent
*tde
;
7282 int reclen
, treclen
;
7283 int count1
, tnamelen
;
7287 if (!(target_dirp
= lock_user(VERIFY_WRITE
, arg2
, count
, 0)))
7291 reclen
= de
->d_reclen
;
7292 tnamelen
= reclen
- offsetof(struct linux_dirent
, d_name
);
7293 assert(tnamelen
>= 0);
7294 treclen
= tnamelen
+ offsetof(struct target_dirent
, d_name
);
7295 assert(count1
+ treclen
<= count
);
7296 tde
->d_reclen
= tswap16(treclen
);
7297 tde
->d_ino
= tswapal(de
->d_ino
);
7298 tde
->d_off
= tswapal(de
->d_off
);
7299 memcpy(tde
->d_name
, de
->d_name
, tnamelen
);
7300 de
= (struct linux_dirent
*)((char *)de
+ reclen
);
7302 tde
= (struct target_dirent
*)((char *)tde
+ treclen
);
7306 unlock_user(target_dirp
, arg2
, ret
);
7312 struct linux_dirent
*dirp
;
7313 abi_long count
= arg3
;
7315 if (!(dirp
= lock_user(VERIFY_WRITE
, arg2
, count
, 0)))
7317 ret
= get_errno(sys_getdents(arg1
, dirp
, count
));
7318 if (!is_error(ret
)) {
7319 struct linux_dirent
*de
;
7324 reclen
= de
->d_reclen
;
7327 de
->d_reclen
= tswap16(reclen
);
7328 tswapls(&de
->d_ino
);
7329 tswapls(&de
->d_off
);
7330 de
= (struct linux_dirent
*)((char *)de
+ reclen
);
7334 unlock_user(dirp
, arg2
, ret
);
7338 /* Implement getdents in terms of getdents64 */
7340 struct linux_dirent64
*dirp
;
7341 abi_long count
= arg3
;
7343 dirp
= lock_user(VERIFY_WRITE
, arg2
, count
, 0);
7347 ret
= get_errno(sys_getdents64(arg1
, dirp
, count
));
7348 if (!is_error(ret
)) {
7349 /* Convert the dirent64 structs to target dirent. We do this
7350 * in-place, since we can guarantee that a target_dirent is no
7351 * larger than a dirent64; however this means we have to be
7352 * careful to read everything before writing in the new format.
7354 struct linux_dirent64
*de
;
7355 struct target_dirent
*tde
;
7360 tde
= (struct target_dirent
*)dirp
;
7362 int namelen
, treclen
;
7363 int reclen
= de
->d_reclen
;
7364 uint64_t ino
= de
->d_ino
;
7365 int64_t off
= de
->d_off
;
7366 uint8_t type
= de
->d_type
;
7368 namelen
= strlen(de
->d_name
);
7369 treclen
= offsetof(struct target_dirent
, d_name
)
7371 treclen
= QEMU_ALIGN_UP(treclen
, sizeof(abi_long
));
7373 memmove(tde
->d_name
, de
->d_name
, namelen
+ 1);
7374 tde
->d_ino
= tswapal(ino
);
7375 tde
->d_off
= tswapal(off
);
7376 tde
->d_reclen
= tswap16(treclen
);
7377 /* The target_dirent type is in what was formerly a padding
7378 * byte at the end of the structure:
7380 *(((char *)tde
) + treclen
- 1) = type
;
7382 de
= (struct linux_dirent64
*)((char *)de
+ reclen
);
7383 tde
= (struct target_dirent
*)((char *)tde
+ treclen
);
7389 unlock_user(dirp
, arg2
, ret
);
7393 #if defined(TARGET_NR_getdents64) && defined(__NR_getdents64)
7394 case TARGET_NR_getdents64
:
7396 struct linux_dirent64
*dirp
;
7397 abi_long count
= arg3
;
7398 if (!(dirp
= lock_user(VERIFY_WRITE
, arg2
, count
, 0)))
7400 ret
= get_errno(sys_getdents64(arg1
, dirp
, count
));
7401 if (!is_error(ret
)) {
7402 struct linux_dirent64
*de
;
7407 reclen
= de
->d_reclen
;
7410 de
->d_reclen
= tswap16(reclen
);
7411 tswap64s((uint64_t *)&de
->d_ino
);
7412 tswap64s((uint64_t *)&de
->d_off
);
7413 de
= (struct linux_dirent64
*)((char *)de
+ reclen
);
7417 unlock_user(dirp
, arg2
, ret
);
7420 #endif /* TARGET_NR_getdents64 */
7421 #if defined(TARGET_NR__newselect)
7422 case TARGET_NR__newselect
:
7423 ret
= do_select(arg1
, arg2
, arg3
, arg4
, arg5
);
7426 #if defined(TARGET_NR_poll) || defined(TARGET_NR_ppoll)
7427 # ifdef TARGET_NR_poll
7428 case TARGET_NR_poll
:
7430 # ifdef TARGET_NR_ppoll
7431 case TARGET_NR_ppoll
:
7434 struct target_pollfd
*target_pfd
;
7435 unsigned int nfds
= arg2
;
7440 target_pfd
= lock_user(VERIFY_WRITE
, arg1
, sizeof(struct target_pollfd
) * nfds
, 1);
7444 pfd
= alloca(sizeof(struct pollfd
) * nfds
);
7445 for(i
= 0; i
< nfds
; i
++) {
7446 pfd
[i
].fd
= tswap32(target_pfd
[i
].fd
);
7447 pfd
[i
].events
= tswap16(target_pfd
[i
].events
);
7450 # ifdef TARGET_NR_ppoll
7451 if (num
== TARGET_NR_ppoll
) {
7452 struct timespec _timeout_ts
, *timeout_ts
= &_timeout_ts
;
7453 target_sigset_t
*target_set
;
7454 sigset_t _set
, *set
= &_set
;
7457 if (target_to_host_timespec(timeout_ts
, arg3
)) {
7458 unlock_user(target_pfd
, arg1
, 0);
7466 target_set
= lock_user(VERIFY_READ
, arg4
, sizeof(target_sigset_t
), 1);
7468 unlock_user(target_pfd
, arg1
, 0);
7471 target_to_host_sigset(set
, target_set
);
7476 ret
= get_errno(sys_ppoll(pfd
, nfds
, timeout_ts
, set
, _NSIG
/8));
7478 if (!is_error(ret
) && arg3
) {
7479 host_to_target_timespec(arg3
, timeout_ts
);
7482 unlock_user(target_set
, arg4
, 0);
7486 ret
= get_errno(poll(pfd
, nfds
, timeout
));
7488 if (!is_error(ret
)) {
7489 for(i
= 0; i
< nfds
; i
++) {
7490 target_pfd
[i
].revents
= tswap16(pfd
[i
].revents
);
7493 unlock_user(target_pfd
, arg1
, sizeof(struct target_pollfd
) * nfds
);
7497 case TARGET_NR_flock
:
7498 /* NOTE: the flock constant seems to be the same for every
7500 ret
= get_errno(flock(arg1
, arg2
));
7502 case TARGET_NR_readv
:
7504 struct iovec
*vec
= lock_iovec(VERIFY_WRITE
, arg2
, arg3
, 0);
7506 ret
= get_errno(readv(arg1
, vec
, arg3
));
7507 unlock_iovec(vec
, arg2
, arg3
, 1);
7509 ret
= -host_to_target_errno(errno
);
7513 case TARGET_NR_writev
:
7515 struct iovec
*vec
= lock_iovec(VERIFY_READ
, arg2
, arg3
, 1);
7517 ret
= get_errno(writev(arg1
, vec
, arg3
));
7518 unlock_iovec(vec
, arg2
, arg3
, 0);
7520 ret
= -host_to_target_errno(errno
);
7524 case TARGET_NR_getsid
:
7525 ret
= get_errno(getsid(arg1
));
7527 #if defined(TARGET_NR_fdatasync) /* Not on alpha (osf_datasync ?) */
7528 case TARGET_NR_fdatasync
:
7529 ret
= get_errno(fdatasync(arg1
));
7532 case TARGET_NR__sysctl
:
7533 /* We don't implement this, but ENOTDIR is always a safe
7535 ret
= -TARGET_ENOTDIR
;
7537 case TARGET_NR_sched_getaffinity
:
7539 unsigned int mask_size
;
7540 unsigned long *mask
;
7543 * sched_getaffinity needs multiples of ulong, so need to take
7544 * care of mismatches between target ulong and host ulong sizes.
7546 if (arg2
& (sizeof(abi_ulong
) - 1)) {
7547 ret
= -TARGET_EINVAL
;
7550 mask_size
= (arg2
+ (sizeof(*mask
) - 1)) & ~(sizeof(*mask
) - 1);
7552 mask
= alloca(mask_size
);
7553 ret
= get_errno(sys_sched_getaffinity(arg1
, mask_size
, mask
));
7555 if (!is_error(ret
)) {
7556 if (copy_to_user(arg3
, mask
, ret
)) {
7562 case TARGET_NR_sched_setaffinity
:
7564 unsigned int mask_size
;
7565 unsigned long *mask
;
7568 * sched_setaffinity needs multiples of ulong, so need to take
7569 * care of mismatches between target ulong and host ulong sizes.
7571 if (arg2
& (sizeof(abi_ulong
) - 1)) {
7572 ret
= -TARGET_EINVAL
;
7575 mask_size
= (arg2
+ (sizeof(*mask
) - 1)) & ~(sizeof(*mask
) - 1);
7577 mask
= alloca(mask_size
);
7578 if (!lock_user_struct(VERIFY_READ
, p
, arg3
, 1)) {
7581 memcpy(mask
, p
, arg2
);
7582 unlock_user_struct(p
, arg2
, 0);
7584 ret
= get_errno(sys_sched_setaffinity(arg1
, mask_size
, mask
));
7587 case TARGET_NR_sched_setparam
:
7589 struct sched_param
*target_schp
;
7590 struct sched_param schp
;
7592 if (!lock_user_struct(VERIFY_READ
, target_schp
, arg2
, 1))
7594 schp
.sched_priority
= tswap32(target_schp
->sched_priority
);
7595 unlock_user_struct(target_schp
, arg2
, 0);
7596 ret
= get_errno(sched_setparam(arg1
, &schp
));
7599 case TARGET_NR_sched_getparam
:
7601 struct sched_param
*target_schp
;
7602 struct sched_param schp
;
7603 ret
= get_errno(sched_getparam(arg1
, &schp
));
7604 if (!is_error(ret
)) {
7605 if (!lock_user_struct(VERIFY_WRITE
, target_schp
, arg2
, 0))
7607 target_schp
->sched_priority
= tswap32(schp
.sched_priority
);
7608 unlock_user_struct(target_schp
, arg2
, 1);
7612 case TARGET_NR_sched_setscheduler
:
7614 struct sched_param
*target_schp
;
7615 struct sched_param schp
;
7616 if (!lock_user_struct(VERIFY_READ
, target_schp
, arg3
, 1))
7618 schp
.sched_priority
= tswap32(target_schp
->sched_priority
);
7619 unlock_user_struct(target_schp
, arg3
, 0);
7620 ret
= get_errno(sched_setscheduler(arg1
, arg2
, &schp
));
7623 case TARGET_NR_sched_getscheduler
:
7624 ret
= get_errno(sched_getscheduler(arg1
));
7626 case TARGET_NR_sched_yield
:
7627 ret
= get_errno(sched_yield());
7629 case TARGET_NR_sched_get_priority_max
:
7630 ret
= get_errno(sched_get_priority_max(arg1
));
7632 case TARGET_NR_sched_get_priority_min
:
7633 ret
= get_errno(sched_get_priority_min(arg1
));
7635 case TARGET_NR_sched_rr_get_interval
:
7638 ret
= get_errno(sched_rr_get_interval(arg1
, &ts
));
7639 if (!is_error(ret
)) {
7640 host_to_target_timespec(arg2
, &ts
);
7644 case TARGET_NR_nanosleep
:
7646 struct timespec req
, rem
;
7647 target_to_host_timespec(&req
, arg1
);
7648 ret
= get_errno(nanosleep(&req
, &rem
));
7649 if (is_error(ret
) && arg2
) {
7650 host_to_target_timespec(arg2
, &rem
);
7654 #ifdef TARGET_NR_query_module
7655 case TARGET_NR_query_module
:
7658 #ifdef TARGET_NR_nfsservctl
7659 case TARGET_NR_nfsservctl
:
7662 case TARGET_NR_prctl
:
7664 case PR_GET_PDEATHSIG
:
7667 ret
= get_errno(prctl(arg1
, &deathsig
, arg3
, arg4
, arg5
));
7668 if (!is_error(ret
) && arg2
7669 && put_user_ual(deathsig
, arg2
)) {
7677 void *name
= lock_user(VERIFY_WRITE
, arg2
, 16, 1);
7681 ret
= get_errno(prctl(arg1
, (unsigned long)name
,
7683 unlock_user(name
, arg2
, 16);
7688 void *name
= lock_user(VERIFY_READ
, arg2
, 16, 1);
7692 ret
= get_errno(prctl(arg1
, (unsigned long)name
,
7694 unlock_user(name
, arg2
, 0);
7699 /* Most prctl options have no pointer arguments */
7700 ret
= get_errno(prctl(arg1
, arg2
, arg3
, arg4
, arg5
));
7704 #ifdef TARGET_NR_arch_prctl
7705 case TARGET_NR_arch_prctl
:
7706 #if defined(TARGET_I386) && !defined(TARGET_ABI32)
7707 ret
= do_arch_prctl(cpu_env
, arg1
, arg2
);
7713 #ifdef TARGET_NR_pread64
7714 case TARGET_NR_pread64
:
7715 if (regpairs_aligned(cpu_env
)) {
7719 if (!(p
= lock_user(VERIFY_WRITE
, arg2
, arg3
, 0)))
7721 ret
= get_errno(pread64(arg1
, p
, arg3
, target_offset64(arg4
, arg5
)));
7722 unlock_user(p
, arg2
, ret
);
7724 case TARGET_NR_pwrite64
:
7725 if (regpairs_aligned(cpu_env
)) {
7729 if (!(p
= lock_user(VERIFY_READ
, arg2
, arg3
, 1)))
7731 ret
= get_errno(pwrite64(arg1
, p
, arg3
, target_offset64(arg4
, arg5
)));
7732 unlock_user(p
, arg2
, 0);
7735 case TARGET_NR_getcwd
:
7736 if (!(p
= lock_user(VERIFY_WRITE
, arg1
, arg2
, 0)))
7738 ret
= get_errno(sys_getcwd1(p
, arg2
));
7739 unlock_user(p
, arg1
, ret
);
7741 case TARGET_NR_capget
:
7743 case TARGET_NR_capset
:
7745 case TARGET_NR_sigaltstack
:
7746 #if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_MIPS) || \
7747 defined(TARGET_SPARC) || defined(TARGET_PPC) || defined(TARGET_ALPHA) || \
7748 defined(TARGET_M68K) || defined(TARGET_S390X) || defined(TARGET_OPENRISC)
7749 ret
= do_sigaltstack(arg1
, arg2
, get_sp_from_cpustate((CPUArchState
*)cpu_env
));
7755 #ifdef CONFIG_SENDFILE
7756 case TARGET_NR_sendfile
:
7761 ret
= get_user_sal(off
, arg3
);
7762 if (is_error(ret
)) {
7767 ret
= get_errno(sendfile(arg1
, arg2
, offp
, arg4
));
7768 if (!is_error(ret
) && arg3
) {
7769 abi_long ret2
= put_user_sal(off
, arg3
);
7770 if (is_error(ret2
)) {
7776 #ifdef TARGET_NR_sendfile64
7777 case TARGET_NR_sendfile64
:
7782 ret
= get_user_s64(off
, arg3
);
7783 if (is_error(ret
)) {
7788 ret
= get_errno(sendfile(arg1
, arg2
, offp
, arg4
));
7789 if (!is_error(ret
) && arg3
) {
7790 abi_long ret2
= put_user_s64(off
, arg3
);
7791 if (is_error(ret2
)) {
7799 case TARGET_NR_sendfile
:
7800 #ifdef TARGET_NR_sendfile64
7801 case TARGET_NR_sendfile64
:
7806 #ifdef TARGET_NR_getpmsg
7807 case TARGET_NR_getpmsg
:
7810 #ifdef TARGET_NR_putpmsg
7811 case TARGET_NR_putpmsg
:
7814 #ifdef TARGET_NR_vfork
7815 case TARGET_NR_vfork
:
7816 ret
= get_errno(do_fork(cpu_env
, CLONE_VFORK
| CLONE_VM
| SIGCHLD
,
7820 #ifdef TARGET_NR_ugetrlimit
7821 case TARGET_NR_ugetrlimit
:
7824 int resource
= target_to_host_resource(arg1
);
7825 ret
= get_errno(getrlimit(resource
, &rlim
));
7826 if (!is_error(ret
)) {
7827 struct target_rlimit
*target_rlim
;
7828 if (!lock_user_struct(VERIFY_WRITE
, target_rlim
, arg2
, 0))
7830 target_rlim
->rlim_cur
= host_to_target_rlim(rlim
.rlim_cur
);
7831 target_rlim
->rlim_max
= host_to_target_rlim(rlim
.rlim_max
);
7832 unlock_user_struct(target_rlim
, arg2
, 1);
7837 #ifdef TARGET_NR_truncate64
7838 case TARGET_NR_truncate64
:
7839 if (!(p
= lock_user_string(arg1
)))
7841 ret
= target_truncate64(cpu_env
, p
, arg2
, arg3
, arg4
);
7842 unlock_user(p
, arg1
, 0);
7845 #ifdef TARGET_NR_ftruncate64
7846 case TARGET_NR_ftruncate64
:
7847 ret
= target_ftruncate64(cpu_env
, arg1
, arg2
, arg3
, arg4
);
7850 #ifdef TARGET_NR_stat64
7851 case TARGET_NR_stat64
:
7852 if (!(p
= lock_user_string(arg1
)))
7854 ret
= get_errno(stat(path(p
), &st
));
7855 unlock_user(p
, arg1
, 0);
7857 ret
= host_to_target_stat64(cpu_env
, arg2
, &st
);
7860 #ifdef TARGET_NR_lstat64
7861 case TARGET_NR_lstat64
:
7862 if (!(p
= lock_user_string(arg1
)))
7864 ret
= get_errno(lstat(path(p
), &st
));
7865 unlock_user(p
, arg1
, 0);
7867 ret
= host_to_target_stat64(cpu_env
, arg2
, &st
);
7870 #ifdef TARGET_NR_fstat64
7871 case TARGET_NR_fstat64
:
7872 ret
= get_errno(fstat(arg1
, &st
));
7874 ret
= host_to_target_stat64(cpu_env
, arg2
, &st
);
7877 #if (defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat))
7878 #ifdef TARGET_NR_fstatat64
7879 case TARGET_NR_fstatat64
:
7881 #ifdef TARGET_NR_newfstatat
7882 case TARGET_NR_newfstatat
:
7884 if (!(p
= lock_user_string(arg2
)))
7886 ret
= get_errno(fstatat(arg1
, path(p
), &st
, arg4
));
7888 ret
= host_to_target_stat64(cpu_env
, arg3
, &st
);
7891 case TARGET_NR_lchown
:
7892 if (!(p
= lock_user_string(arg1
)))
7894 ret
= get_errno(lchown(p
, low2highuid(arg2
), low2highgid(arg3
)));
7895 unlock_user(p
, arg1
, 0);
7897 #ifdef TARGET_NR_getuid
7898 case TARGET_NR_getuid
:
7899 ret
= get_errno(high2lowuid(getuid()));
7902 #ifdef TARGET_NR_getgid
7903 case TARGET_NR_getgid
:
7904 ret
= get_errno(high2lowgid(getgid()));
7907 #ifdef TARGET_NR_geteuid
7908 case TARGET_NR_geteuid
:
7909 ret
= get_errno(high2lowuid(geteuid()));
7912 #ifdef TARGET_NR_getegid
7913 case TARGET_NR_getegid
:
7914 ret
= get_errno(high2lowgid(getegid()));
7917 case TARGET_NR_setreuid
:
7918 ret
= get_errno(setreuid(low2highuid(arg1
), low2highuid(arg2
)));
7920 case TARGET_NR_setregid
:
7921 ret
= get_errno(setregid(low2highgid(arg1
), low2highgid(arg2
)));
7923 case TARGET_NR_getgroups
:
7925 int gidsetsize
= arg1
;
7926 target_id
*target_grouplist
;
7930 grouplist
= alloca(gidsetsize
* sizeof(gid_t
));
7931 ret
= get_errno(getgroups(gidsetsize
, grouplist
));
7932 if (gidsetsize
== 0)
7934 if (!is_error(ret
)) {
7935 target_grouplist
= lock_user(VERIFY_WRITE
, arg2
, gidsetsize
* sizeof(target_id
), 0);
7936 if (!target_grouplist
)
7938 for(i
= 0;i
< ret
; i
++)
7939 target_grouplist
[i
] = tswapid(high2lowgid(grouplist
[i
]));
7940 unlock_user(target_grouplist
, arg2
, gidsetsize
* sizeof(target_id
));
7944 case TARGET_NR_setgroups
:
7946 int gidsetsize
= arg1
;
7947 target_id
*target_grouplist
;
7948 gid_t
*grouplist
= NULL
;
7951 grouplist
= alloca(gidsetsize
* sizeof(gid_t
));
7952 target_grouplist
= lock_user(VERIFY_READ
, arg2
, gidsetsize
* sizeof(target_id
), 1);
7953 if (!target_grouplist
) {
7954 ret
= -TARGET_EFAULT
;
7957 for (i
= 0; i
< gidsetsize
; i
++) {
7958 grouplist
[i
] = low2highgid(tswapid(target_grouplist
[i
]));
7960 unlock_user(target_grouplist
, arg2
, 0);
7962 ret
= get_errno(setgroups(gidsetsize
, grouplist
));
7965 case TARGET_NR_fchown
:
7966 ret
= get_errno(fchown(arg1
, low2highuid(arg2
), low2highgid(arg3
)));
7968 #if defined(TARGET_NR_fchownat)
7969 case TARGET_NR_fchownat
:
7970 if (!(p
= lock_user_string(arg2
)))
7972 ret
= get_errno(fchownat(arg1
, p
, low2highuid(arg3
),
7973 low2highgid(arg4
), arg5
));
7974 unlock_user(p
, arg2
, 0);
7977 #ifdef TARGET_NR_setresuid
7978 case TARGET_NR_setresuid
:
7979 ret
= get_errno(setresuid(low2highuid(arg1
),
7981 low2highuid(arg3
)));
7984 #ifdef TARGET_NR_getresuid
7985 case TARGET_NR_getresuid
:
7987 uid_t ruid
, euid
, suid
;
7988 ret
= get_errno(getresuid(&ruid
, &euid
, &suid
));
7989 if (!is_error(ret
)) {
7990 if (put_user_u16(high2lowuid(ruid
), arg1
)
7991 || put_user_u16(high2lowuid(euid
), arg2
)
7992 || put_user_u16(high2lowuid(suid
), arg3
))
7998 #ifdef TARGET_NR_getresgid
7999 case TARGET_NR_setresgid
:
8000 ret
= get_errno(setresgid(low2highgid(arg1
),
8002 low2highgid(arg3
)));
8005 #ifdef TARGET_NR_getresgid
8006 case TARGET_NR_getresgid
:
8008 gid_t rgid
, egid
, sgid
;
8009 ret
= get_errno(getresgid(&rgid
, &egid
, &sgid
));
8010 if (!is_error(ret
)) {
8011 if (put_user_u16(high2lowgid(rgid
), arg1
)
8012 || put_user_u16(high2lowgid(egid
), arg2
)
8013 || put_user_u16(high2lowgid(sgid
), arg3
))
8019 case TARGET_NR_chown
:
8020 if (!(p
= lock_user_string(arg1
)))
8022 ret
= get_errno(chown(p
, low2highuid(arg2
), low2highgid(arg3
)));
8023 unlock_user(p
, arg1
, 0);
8025 case TARGET_NR_setuid
:
8026 ret
= get_errno(setuid(low2highuid(arg1
)));
8028 case TARGET_NR_setgid
:
8029 ret
= get_errno(setgid(low2highgid(arg1
)));
8031 case TARGET_NR_setfsuid
:
8032 ret
= get_errno(setfsuid(arg1
));
8034 case TARGET_NR_setfsgid
:
8035 ret
= get_errno(setfsgid(arg1
));
8038 #ifdef TARGET_NR_lchown32
8039 case TARGET_NR_lchown32
:
8040 if (!(p
= lock_user_string(arg1
)))
8042 ret
= get_errno(lchown(p
, arg2
, arg3
));
8043 unlock_user(p
, arg1
, 0);
8046 #ifdef TARGET_NR_getuid32
8047 case TARGET_NR_getuid32
:
8048 ret
= get_errno(getuid());
8052 #if defined(TARGET_NR_getxuid) && defined(TARGET_ALPHA)
8053 /* Alpha specific */
8054 case TARGET_NR_getxuid
:
8058 ((CPUAlphaState
*)cpu_env
)->ir
[IR_A4
]=euid
;
8060 ret
= get_errno(getuid());
8063 #if defined(TARGET_NR_getxgid) && defined(TARGET_ALPHA)
8064 /* Alpha specific */
8065 case TARGET_NR_getxgid
:
8069 ((CPUAlphaState
*)cpu_env
)->ir
[IR_A4
]=egid
;
8071 ret
= get_errno(getgid());
8074 #if defined(TARGET_NR_osf_getsysinfo) && defined(TARGET_ALPHA)
8075 /* Alpha specific */
8076 case TARGET_NR_osf_getsysinfo
:
8077 ret
= -TARGET_EOPNOTSUPP
;
8079 case TARGET_GSI_IEEE_FP_CONTROL
:
8081 uint64_t swcr
, fpcr
= cpu_alpha_load_fpcr (cpu_env
);
8083 /* Copied from linux ieee_fpcr_to_swcr. */
8084 swcr
= (fpcr
>> 35) & SWCR_STATUS_MASK
;
8085 swcr
|= (fpcr
>> 36) & SWCR_MAP_DMZ
;
8086 swcr
|= (~fpcr
>> 48) & (SWCR_TRAP_ENABLE_INV
8087 | SWCR_TRAP_ENABLE_DZE
8088 | SWCR_TRAP_ENABLE_OVF
);
8089 swcr
|= (~fpcr
>> 57) & (SWCR_TRAP_ENABLE_UNF
8090 | SWCR_TRAP_ENABLE_INE
);
8091 swcr
|= (fpcr
>> 47) & SWCR_MAP_UMZ
;
8092 swcr
|= (~fpcr
>> 41) & SWCR_TRAP_ENABLE_DNO
;
8094 if (put_user_u64 (swcr
, arg2
))
8100 /* case GSI_IEEE_STATE_AT_SIGNAL:
8101 -- Not implemented in linux kernel.
8103 -- Retrieves current unaligned access state; not much used.
8105 -- Retrieves implver information; surely not used.
8107 -- Grabs a copy of the HWRPB; surely not used.
8112 #if defined(TARGET_NR_osf_setsysinfo) && defined(TARGET_ALPHA)
8113 /* Alpha specific */
8114 case TARGET_NR_osf_setsysinfo
:
8115 ret
= -TARGET_EOPNOTSUPP
;
8117 case TARGET_SSI_IEEE_FP_CONTROL
:
8119 uint64_t swcr
, fpcr
, orig_fpcr
;
8121 if (get_user_u64 (swcr
, arg2
)) {
8124 orig_fpcr
= cpu_alpha_load_fpcr(cpu_env
);
8125 fpcr
= orig_fpcr
& FPCR_DYN_MASK
;
8127 /* Copied from linux ieee_swcr_to_fpcr. */
8128 fpcr
|= (swcr
& SWCR_STATUS_MASK
) << 35;
8129 fpcr
|= (swcr
& SWCR_MAP_DMZ
) << 36;
8130 fpcr
|= (~swcr
& (SWCR_TRAP_ENABLE_INV
8131 | SWCR_TRAP_ENABLE_DZE
8132 | SWCR_TRAP_ENABLE_OVF
)) << 48;
8133 fpcr
|= (~swcr
& (SWCR_TRAP_ENABLE_UNF
8134 | SWCR_TRAP_ENABLE_INE
)) << 57;
8135 fpcr
|= (swcr
& SWCR_MAP_UMZ
? FPCR_UNDZ
| FPCR_UNFD
: 0);
8136 fpcr
|= (~swcr
& SWCR_TRAP_ENABLE_DNO
) << 41;
8138 cpu_alpha_store_fpcr(cpu_env
, fpcr
);
8143 case TARGET_SSI_IEEE_RAISE_EXCEPTION
:
8145 uint64_t exc
, fpcr
, orig_fpcr
;
8148 if (get_user_u64(exc
, arg2
)) {
8152 orig_fpcr
= cpu_alpha_load_fpcr(cpu_env
);
8154 /* We only add to the exception status here. */
8155 fpcr
= orig_fpcr
| ((exc
& SWCR_STATUS_MASK
) << 35);
8157 cpu_alpha_store_fpcr(cpu_env
, fpcr
);
8160 /* Old exceptions are not signaled. */
8161 fpcr
&= ~(orig_fpcr
& FPCR_STATUS_MASK
);
8163 /* If any exceptions set by this call,
8164 and are unmasked, send a signal. */
8166 if ((fpcr
& (FPCR_INE
| FPCR_INED
)) == FPCR_INE
) {
8167 si_code
= TARGET_FPE_FLTRES
;
8169 if ((fpcr
& (FPCR_UNF
| FPCR_UNFD
)) == FPCR_UNF
) {
8170 si_code
= TARGET_FPE_FLTUND
;
8172 if ((fpcr
& (FPCR_OVF
| FPCR_OVFD
)) == FPCR_OVF
) {
8173 si_code
= TARGET_FPE_FLTOVF
;
8175 if ((fpcr
& (FPCR_DZE
| FPCR_DZED
)) == FPCR_DZE
) {
8176 si_code
= TARGET_FPE_FLTDIV
;
8178 if ((fpcr
& (FPCR_INV
| FPCR_INVD
)) == FPCR_INV
) {
8179 si_code
= TARGET_FPE_FLTINV
;
8182 target_siginfo_t info
;
8183 info
.si_signo
= SIGFPE
;
8185 info
.si_code
= si_code
;
8186 info
._sifields
._sigfault
._addr
8187 = ((CPUArchState
*)cpu_env
)->pc
;
8188 queue_signal((CPUArchState
*)cpu_env
, info
.si_signo
, &info
);
8193 /* case SSI_NVPAIRS:
8194 -- Used with SSIN_UACPROC to enable unaligned accesses.
8195 case SSI_IEEE_STATE_AT_SIGNAL:
8196 case SSI_IEEE_IGNORE_STATE_AT_SIGNAL:
8197 -- Not implemented in linux kernel
8202 #ifdef TARGET_NR_osf_sigprocmask
8203 /* Alpha specific. */
8204 case TARGET_NR_osf_sigprocmask
:
8208 sigset_t set
, oldset
;
8211 case TARGET_SIG_BLOCK
:
8214 case TARGET_SIG_UNBLOCK
:
8217 case TARGET_SIG_SETMASK
:
8221 ret
= -TARGET_EINVAL
;
8225 target_to_host_old_sigset(&set
, &mask
);
8226 sigprocmask(how
, &set
, &oldset
);
8227 host_to_target_old_sigset(&mask
, &oldset
);
8233 #ifdef TARGET_NR_getgid32
8234 case TARGET_NR_getgid32
:
8235 ret
= get_errno(getgid());
8238 #ifdef TARGET_NR_geteuid32
8239 case TARGET_NR_geteuid32
:
8240 ret
= get_errno(geteuid());
8243 #ifdef TARGET_NR_getegid32
8244 case TARGET_NR_getegid32
:
8245 ret
= get_errno(getegid());
8248 #ifdef TARGET_NR_setreuid32
8249 case TARGET_NR_setreuid32
:
8250 ret
= get_errno(setreuid(arg1
, arg2
));
8253 #ifdef TARGET_NR_setregid32
8254 case TARGET_NR_setregid32
:
8255 ret
= get_errno(setregid(arg1
, arg2
));
8258 #ifdef TARGET_NR_getgroups32
8259 case TARGET_NR_getgroups32
:
8261 int gidsetsize
= arg1
;
8262 uint32_t *target_grouplist
;
8266 grouplist
= alloca(gidsetsize
* sizeof(gid_t
));
8267 ret
= get_errno(getgroups(gidsetsize
, grouplist
));
8268 if (gidsetsize
== 0)
8270 if (!is_error(ret
)) {
8271 target_grouplist
= lock_user(VERIFY_WRITE
, arg2
, gidsetsize
* 4, 0);
8272 if (!target_grouplist
) {
8273 ret
= -TARGET_EFAULT
;
8276 for(i
= 0;i
< ret
; i
++)
8277 target_grouplist
[i
] = tswap32(grouplist
[i
]);
8278 unlock_user(target_grouplist
, arg2
, gidsetsize
* 4);
8283 #ifdef TARGET_NR_setgroups32
8284 case TARGET_NR_setgroups32
:
8286 int gidsetsize
= arg1
;
8287 uint32_t *target_grouplist
;
8291 grouplist
= alloca(gidsetsize
* sizeof(gid_t
));
8292 target_grouplist
= lock_user(VERIFY_READ
, arg2
, gidsetsize
* 4, 1);
8293 if (!target_grouplist
) {
8294 ret
= -TARGET_EFAULT
;
8297 for(i
= 0;i
< gidsetsize
; i
++)
8298 grouplist
[i
] = tswap32(target_grouplist
[i
]);
8299 unlock_user(target_grouplist
, arg2
, 0);
8300 ret
= get_errno(setgroups(gidsetsize
, grouplist
));
8304 #ifdef TARGET_NR_fchown32
8305 case TARGET_NR_fchown32
:
8306 ret
= get_errno(fchown(arg1
, arg2
, arg3
));
8309 #ifdef TARGET_NR_setresuid32
8310 case TARGET_NR_setresuid32
:
8311 ret
= get_errno(setresuid(arg1
, arg2
, arg3
));
8314 #ifdef TARGET_NR_getresuid32
8315 case TARGET_NR_getresuid32
:
8317 uid_t ruid
, euid
, suid
;
8318 ret
= get_errno(getresuid(&ruid
, &euid
, &suid
));
8319 if (!is_error(ret
)) {
8320 if (put_user_u32(ruid
, arg1
)
8321 || put_user_u32(euid
, arg2
)
8322 || put_user_u32(suid
, arg3
))
8328 #ifdef TARGET_NR_setresgid32
8329 case TARGET_NR_setresgid32
:
8330 ret
= get_errno(setresgid(arg1
, arg2
, arg3
));
8333 #ifdef TARGET_NR_getresgid32
8334 case TARGET_NR_getresgid32
:
8336 gid_t rgid
, egid
, sgid
;
8337 ret
= get_errno(getresgid(&rgid
, &egid
, &sgid
));
8338 if (!is_error(ret
)) {
8339 if (put_user_u32(rgid
, arg1
)
8340 || put_user_u32(egid
, arg2
)
8341 || put_user_u32(sgid
, arg3
))
8347 #ifdef TARGET_NR_chown32
8348 case TARGET_NR_chown32
:
8349 if (!(p
= lock_user_string(arg1
)))
8351 ret
= get_errno(chown(p
, arg2
, arg3
));
8352 unlock_user(p
, arg1
, 0);
8355 #ifdef TARGET_NR_setuid32
8356 case TARGET_NR_setuid32
:
8357 ret
= get_errno(setuid(arg1
));
8360 #ifdef TARGET_NR_setgid32
8361 case TARGET_NR_setgid32
:
8362 ret
= get_errno(setgid(arg1
));
8365 #ifdef TARGET_NR_setfsuid32
8366 case TARGET_NR_setfsuid32
:
8367 ret
= get_errno(setfsuid(arg1
));
8370 #ifdef TARGET_NR_setfsgid32
8371 case TARGET_NR_setfsgid32
:
8372 ret
= get_errno(setfsgid(arg1
));
8376 case TARGET_NR_pivot_root
:
8378 #ifdef TARGET_NR_mincore
8379 case TARGET_NR_mincore
:
8382 ret
= -TARGET_EFAULT
;
8383 if (!(a
= lock_user(VERIFY_READ
, arg1
,arg2
, 0)))
8385 if (!(p
= lock_user_string(arg3
)))
8387 ret
= get_errno(mincore(a
, arg2
, p
));
8388 unlock_user(p
, arg3
, ret
);
8390 unlock_user(a
, arg1
, 0);
8394 #ifdef TARGET_NR_arm_fadvise64_64
8395 case TARGET_NR_arm_fadvise64_64
:
8398 * arm_fadvise64_64 looks like fadvise64_64 but
8399 * with different argument order
8407 #if defined(TARGET_NR_fadvise64_64) || defined(TARGET_NR_arm_fadvise64_64) || defined(TARGET_NR_fadvise64)
8408 #ifdef TARGET_NR_fadvise64_64
8409 case TARGET_NR_fadvise64_64
:
8411 #ifdef TARGET_NR_fadvise64
8412 case TARGET_NR_fadvise64
:
8416 case 4: arg4
= POSIX_FADV_NOREUSE
+ 1; break; /* make sure it's an invalid value */
8417 case 5: arg4
= POSIX_FADV_NOREUSE
+ 2; break; /* ditto */
8418 case 6: arg4
= POSIX_FADV_DONTNEED
; break;
8419 case 7: arg4
= POSIX_FADV_NOREUSE
; break;
8423 ret
= -posix_fadvise(arg1
, arg2
, arg3
, arg4
);
8426 #ifdef TARGET_NR_madvise
8427 case TARGET_NR_madvise
:
8428 /* A straight passthrough may not be safe because qemu sometimes
8429 turns private file-backed mappings into anonymous mappings.
8430 This will break MADV_DONTNEED.
8431 This is a hint, so ignoring and returning success is ok. */
8435 #if TARGET_ABI_BITS == 32
8436 case TARGET_NR_fcntl64
:
8440 struct target_flock64
*target_fl
;
8442 struct target_eabi_flock64
*target_efl
;
8445 cmd
= target_to_host_fcntl_cmd(arg2
);
8446 if (cmd
== -TARGET_EINVAL
) {
8452 case TARGET_F_GETLK64
:
8454 if (((CPUARMState
*)cpu_env
)->eabi
) {
8455 if (!lock_user_struct(VERIFY_READ
, target_efl
, arg3
, 1))
8457 fl
.l_type
= tswap16(target_efl
->l_type
);
8458 fl
.l_whence
= tswap16(target_efl
->l_whence
);
8459 fl
.l_start
= tswap64(target_efl
->l_start
);
8460 fl
.l_len
= tswap64(target_efl
->l_len
);
8461 fl
.l_pid
= tswap32(target_efl
->l_pid
);
8462 unlock_user_struct(target_efl
, arg3
, 0);
8466 if (!lock_user_struct(VERIFY_READ
, target_fl
, arg3
, 1))
8468 fl
.l_type
= tswap16(target_fl
->l_type
);
8469 fl
.l_whence
= tswap16(target_fl
->l_whence
);
8470 fl
.l_start
= tswap64(target_fl
->l_start
);
8471 fl
.l_len
= tswap64(target_fl
->l_len
);
8472 fl
.l_pid
= tswap32(target_fl
->l_pid
);
8473 unlock_user_struct(target_fl
, arg3
, 0);
8475 ret
= get_errno(fcntl(arg1
, cmd
, &fl
));
8478 if (((CPUARMState
*)cpu_env
)->eabi
) {
8479 if (!lock_user_struct(VERIFY_WRITE
, target_efl
, arg3
, 0))
8481 target_efl
->l_type
= tswap16(fl
.l_type
);
8482 target_efl
->l_whence
= tswap16(fl
.l_whence
);
8483 target_efl
->l_start
= tswap64(fl
.l_start
);
8484 target_efl
->l_len
= tswap64(fl
.l_len
);
8485 target_efl
->l_pid
= tswap32(fl
.l_pid
);
8486 unlock_user_struct(target_efl
, arg3
, 1);
8490 if (!lock_user_struct(VERIFY_WRITE
, target_fl
, arg3
, 0))
8492 target_fl
->l_type
= tswap16(fl
.l_type
);
8493 target_fl
->l_whence
= tswap16(fl
.l_whence
);
8494 target_fl
->l_start
= tswap64(fl
.l_start
);
8495 target_fl
->l_len
= tswap64(fl
.l_len
);
8496 target_fl
->l_pid
= tswap32(fl
.l_pid
);
8497 unlock_user_struct(target_fl
, arg3
, 1);
8502 case TARGET_F_SETLK64
:
8503 case TARGET_F_SETLKW64
:
8505 if (((CPUARMState
*)cpu_env
)->eabi
) {
8506 if (!lock_user_struct(VERIFY_READ
, target_efl
, arg3
, 1))
8508 fl
.l_type
= tswap16(target_efl
->l_type
);
8509 fl
.l_whence
= tswap16(target_efl
->l_whence
);
8510 fl
.l_start
= tswap64(target_efl
->l_start
);
8511 fl
.l_len
= tswap64(target_efl
->l_len
);
8512 fl
.l_pid
= tswap32(target_efl
->l_pid
);
8513 unlock_user_struct(target_efl
, arg3
, 0);
8517 if (!lock_user_struct(VERIFY_READ
, target_fl
, arg3
, 1))
8519 fl
.l_type
= tswap16(target_fl
->l_type
);
8520 fl
.l_whence
= tswap16(target_fl
->l_whence
);
8521 fl
.l_start
= tswap64(target_fl
->l_start
);
8522 fl
.l_len
= tswap64(target_fl
->l_len
);
8523 fl
.l_pid
= tswap32(target_fl
->l_pid
);
8524 unlock_user_struct(target_fl
, arg3
, 0);
8526 ret
= get_errno(fcntl(arg1
, cmd
, &fl
));
8529 ret
= do_fcntl(arg1
, arg2
, arg3
);
8535 #ifdef TARGET_NR_cacheflush
8536 case TARGET_NR_cacheflush
:
8537 /* self-modifying code is handled automatically, so nothing needed */
8541 #ifdef TARGET_NR_security
8542 case TARGET_NR_security
:
8545 #ifdef TARGET_NR_getpagesize
8546 case TARGET_NR_getpagesize
:
8547 ret
= TARGET_PAGE_SIZE
;
8550 case TARGET_NR_gettid
:
8551 ret
= get_errno(gettid());
8553 #ifdef TARGET_NR_readahead
8554 case TARGET_NR_readahead
:
8555 #if TARGET_ABI_BITS == 32
8556 if (regpairs_aligned(cpu_env
)) {
8561 ret
= get_errno(readahead(arg1
, ((off64_t
)arg3
<< 32) | arg2
, arg4
));
8563 ret
= get_errno(readahead(arg1
, arg2
, arg3
));
8568 #ifdef TARGET_NR_setxattr
8569 case TARGET_NR_listxattr
:
8570 case TARGET_NR_llistxattr
:
8574 b
= lock_user(VERIFY_WRITE
, arg2
, arg3
, 0);
8576 ret
= -TARGET_EFAULT
;
8580 p
= lock_user_string(arg1
);
8582 if (num
== TARGET_NR_listxattr
) {
8583 ret
= get_errno(listxattr(p
, b
, arg3
));
8585 ret
= get_errno(llistxattr(p
, b
, arg3
));
8588 ret
= -TARGET_EFAULT
;
8590 unlock_user(p
, arg1
, 0);
8591 unlock_user(b
, arg2
, arg3
);
8594 case TARGET_NR_flistxattr
:
8598 b
= lock_user(VERIFY_WRITE
, arg2
, arg3
, 0);
8600 ret
= -TARGET_EFAULT
;
8604 ret
= get_errno(flistxattr(arg1
, b
, arg3
));
8605 unlock_user(b
, arg2
, arg3
);
8608 case TARGET_NR_setxattr
:
8609 case TARGET_NR_lsetxattr
:
8611 void *p
, *n
, *v
= 0;
8613 v
= lock_user(VERIFY_READ
, arg3
, arg4
, 1);
8615 ret
= -TARGET_EFAULT
;
8619 p
= lock_user_string(arg1
);
8620 n
= lock_user_string(arg2
);
8622 if (num
== TARGET_NR_setxattr
) {
8623 ret
= get_errno(setxattr(p
, n
, v
, arg4
, arg5
));
8625 ret
= get_errno(lsetxattr(p
, n
, v
, arg4
, arg5
));
8628 ret
= -TARGET_EFAULT
;
8630 unlock_user(p
, arg1
, 0);
8631 unlock_user(n
, arg2
, 0);
8632 unlock_user(v
, arg3
, 0);
8635 case TARGET_NR_fsetxattr
:
8639 v
= lock_user(VERIFY_READ
, arg3
, arg4
, 1);
8641 ret
= -TARGET_EFAULT
;
8645 n
= lock_user_string(arg2
);
8647 ret
= get_errno(fsetxattr(arg1
, n
, v
, arg4
, arg5
));
8649 ret
= -TARGET_EFAULT
;
8651 unlock_user(n
, arg2
, 0);
8652 unlock_user(v
, arg3
, 0);
8655 case TARGET_NR_getxattr
:
8656 case TARGET_NR_lgetxattr
:
8658 void *p
, *n
, *v
= 0;
8660 v
= lock_user(VERIFY_WRITE
, arg3
, arg4
, 0);
8662 ret
= -TARGET_EFAULT
;
8666 p
= lock_user_string(arg1
);
8667 n
= lock_user_string(arg2
);
8669 if (num
== TARGET_NR_getxattr
) {
8670 ret
= get_errno(getxattr(p
, n
, v
, arg4
));
8672 ret
= get_errno(lgetxattr(p
, n
, v
, arg4
));
8675 ret
= -TARGET_EFAULT
;
8677 unlock_user(p
, arg1
, 0);
8678 unlock_user(n
, arg2
, 0);
8679 unlock_user(v
, arg3
, arg4
);
8682 case TARGET_NR_fgetxattr
:
8686 v
= lock_user(VERIFY_WRITE
, arg3
, arg4
, 0);
8688 ret
= -TARGET_EFAULT
;
8692 n
= lock_user_string(arg2
);
8694 ret
= get_errno(fgetxattr(arg1
, n
, v
, arg4
));
8696 ret
= -TARGET_EFAULT
;
8698 unlock_user(n
, arg2
, 0);
8699 unlock_user(v
, arg3
, arg4
);
8702 case TARGET_NR_removexattr
:
8703 case TARGET_NR_lremovexattr
:
8706 p
= lock_user_string(arg1
);
8707 n
= lock_user_string(arg2
);
8709 if (num
== TARGET_NR_removexattr
) {
8710 ret
= get_errno(removexattr(p
, n
));
8712 ret
= get_errno(lremovexattr(p
, n
));
8715 ret
= -TARGET_EFAULT
;
8717 unlock_user(p
, arg1
, 0);
8718 unlock_user(n
, arg2
, 0);
8721 case TARGET_NR_fremovexattr
:
8724 n
= lock_user_string(arg2
);
8726 ret
= get_errno(fremovexattr(arg1
, n
));
8728 ret
= -TARGET_EFAULT
;
8730 unlock_user(n
, arg2
, 0);
8734 #endif /* CONFIG_ATTR */
8735 #ifdef TARGET_NR_set_thread_area
8736 case TARGET_NR_set_thread_area
:
8737 #if defined(TARGET_MIPS)
8738 ((CPUMIPSState
*) cpu_env
)->tls_value
= arg1
;
8741 #elif defined(TARGET_CRIS)
8743 ret
= -TARGET_EINVAL
;
8745 ((CPUCRISState
*) cpu_env
)->pregs
[PR_PID
] = arg1
;
8749 #elif defined(TARGET_I386) && defined(TARGET_ABI32)
8750 ret
= do_set_thread_area(cpu_env
, arg1
);
8752 #elif defined(TARGET_M68K)
8754 TaskState
*ts
= ((CPUArchState
*)cpu_env
)->opaque
;
8755 ts
->tp_value
= arg1
;
8760 goto unimplemented_nowarn
;
8763 #ifdef TARGET_NR_get_thread_area
8764 case TARGET_NR_get_thread_area
:
8765 #if defined(TARGET_I386) && defined(TARGET_ABI32)
8766 ret
= do_get_thread_area(cpu_env
, arg1
);
8768 #elif defined(TARGET_M68K)
8770 TaskState
*ts
= ((CPUArchState
*)cpu_env
)->opaque
;
8775 goto unimplemented_nowarn
;
8778 #ifdef TARGET_NR_getdomainname
8779 case TARGET_NR_getdomainname
:
8780 goto unimplemented_nowarn
;
8783 #ifdef TARGET_NR_clock_gettime
8784 case TARGET_NR_clock_gettime
:
8787 ret
= get_errno(clock_gettime(arg1
, &ts
));
8788 if (!is_error(ret
)) {
8789 host_to_target_timespec(arg2
, &ts
);
8794 #ifdef TARGET_NR_clock_getres
8795 case TARGET_NR_clock_getres
:
8798 ret
= get_errno(clock_getres(arg1
, &ts
));
8799 if (!is_error(ret
)) {
8800 host_to_target_timespec(arg2
, &ts
);
8805 #ifdef TARGET_NR_clock_nanosleep
8806 case TARGET_NR_clock_nanosleep
:
8809 target_to_host_timespec(&ts
, arg3
);
8810 ret
= get_errno(clock_nanosleep(arg1
, arg2
, &ts
, arg4
? &ts
: NULL
));
8812 host_to_target_timespec(arg4
, &ts
);
8817 #if defined(TARGET_NR_set_tid_address) && defined(__NR_set_tid_address)
8818 case TARGET_NR_set_tid_address
:
8819 ret
= get_errno(set_tid_address((int *)g2h(arg1
)));
8823 #if defined(TARGET_NR_tkill) && defined(__NR_tkill)
8824 case TARGET_NR_tkill
:
8825 ret
= get_errno(sys_tkill((int)arg1
, target_to_host_signal(arg2
)));
8829 #if defined(TARGET_NR_tgkill) && defined(__NR_tgkill)
8830 case TARGET_NR_tgkill
:
8831 ret
= get_errno(sys_tgkill((int)arg1
, (int)arg2
,
8832 target_to_host_signal(arg3
)));
8836 #ifdef TARGET_NR_set_robust_list
8837 case TARGET_NR_set_robust_list
:
8838 case TARGET_NR_get_robust_list
:
8839 /* The ABI for supporting robust futexes has userspace pass
8840 * the kernel a pointer to a linked list which is updated by
8841 * userspace after the syscall; the list is walked by the kernel
8842 * when the thread exits. Since the linked list in QEMU guest
8843 * memory isn't a valid linked list for the host and we have
8844 * no way to reliably intercept the thread-death event, we can't
8845 * support these. Silently return ENOSYS so that guest userspace
8846 * falls back to a non-robust futex implementation (which should
8847 * be OK except in the corner case of the guest crashing while
8848 * holding a mutex that is shared with another process via
8851 goto unimplemented_nowarn
;
8854 #if defined(TARGET_NR_utimensat)
8855 case TARGET_NR_utimensat
:
8857 struct timespec
*tsp
, ts
[2];
8861 target_to_host_timespec(ts
, arg3
);
8862 target_to_host_timespec(ts
+1, arg3
+sizeof(struct target_timespec
));
8866 ret
= get_errno(sys_utimensat(arg1
, NULL
, tsp
, arg4
));
8868 if (!(p
= lock_user_string(arg2
))) {
8869 ret
= -TARGET_EFAULT
;
8872 ret
= get_errno(sys_utimensat(arg1
, path(p
), tsp
, arg4
));
8873 unlock_user(p
, arg2
, 0);
8878 case TARGET_NR_futex
:
8879 ret
= do_futex(arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
8881 #if defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init)
8882 case TARGET_NR_inotify_init
:
8883 ret
= get_errno(sys_inotify_init());
8886 #ifdef CONFIG_INOTIFY1
8887 #if defined(TARGET_NR_inotify_init1) && defined(__NR_inotify_init1)
8888 case TARGET_NR_inotify_init1
:
8889 ret
= get_errno(sys_inotify_init1(arg1
));
8893 #if defined(TARGET_NR_inotify_add_watch) && defined(__NR_inotify_add_watch)
8894 case TARGET_NR_inotify_add_watch
:
8895 p
= lock_user_string(arg2
);
8896 ret
= get_errno(sys_inotify_add_watch(arg1
, path(p
), arg3
));
8897 unlock_user(p
, arg2
, 0);
8900 #if defined(TARGET_NR_inotify_rm_watch) && defined(__NR_inotify_rm_watch)
8901 case TARGET_NR_inotify_rm_watch
:
8902 ret
= get_errno(sys_inotify_rm_watch(arg1
, arg2
));
8906 #if defined(TARGET_NR_mq_open) && defined(__NR_mq_open)
8907 case TARGET_NR_mq_open
:
8909 struct mq_attr posix_mq_attr
;
8911 p
= lock_user_string(arg1
- 1);
8913 copy_from_user_mq_attr (&posix_mq_attr
, arg4
);
8914 ret
= get_errno(mq_open(p
, arg2
, arg3
, &posix_mq_attr
));
8915 unlock_user (p
, arg1
, 0);
8919 case TARGET_NR_mq_unlink
:
8920 p
= lock_user_string(arg1
- 1);
8921 ret
= get_errno(mq_unlink(p
));
8922 unlock_user (p
, arg1
, 0);
8925 case TARGET_NR_mq_timedsend
:
8929 p
= lock_user (VERIFY_READ
, arg2
, arg3
, 1);
8931 target_to_host_timespec(&ts
, arg5
);
8932 ret
= get_errno(mq_timedsend(arg1
, p
, arg3
, arg4
, &ts
));
8933 host_to_target_timespec(arg5
, &ts
);
8936 ret
= get_errno(mq_send(arg1
, p
, arg3
, arg4
));
8937 unlock_user (p
, arg2
, arg3
);
8941 case TARGET_NR_mq_timedreceive
:
8946 p
= lock_user (VERIFY_READ
, arg2
, arg3
, 1);
8948 target_to_host_timespec(&ts
, arg5
);
8949 ret
= get_errno(mq_timedreceive(arg1
, p
, arg3
, &prio
, &ts
));
8950 host_to_target_timespec(arg5
, &ts
);
8953 ret
= get_errno(mq_receive(arg1
, p
, arg3
, &prio
));
8954 unlock_user (p
, arg2
, arg3
);
8956 put_user_u32(prio
, arg4
);
8960 /* Not implemented for now... */
8961 /* case TARGET_NR_mq_notify: */
8964 case TARGET_NR_mq_getsetattr
:
8966 struct mq_attr posix_mq_attr_in
, posix_mq_attr_out
;
8969 ret
= mq_getattr(arg1
, &posix_mq_attr_out
);
8970 copy_to_user_mq_attr(arg3
, &posix_mq_attr_out
);
8973 copy_from_user_mq_attr(&posix_mq_attr_in
, arg2
);
8974 ret
|= mq_setattr(arg1
, &posix_mq_attr_in
, &posix_mq_attr_out
);
8981 #ifdef CONFIG_SPLICE
8982 #ifdef TARGET_NR_tee
8985 ret
= get_errno(tee(arg1
,arg2
,arg3
,arg4
));
8989 #ifdef TARGET_NR_splice
8990 case TARGET_NR_splice
:
8992 loff_t loff_in
, loff_out
;
8993 loff_t
*ploff_in
= NULL
, *ploff_out
= NULL
;
8995 get_user_u64(loff_in
, arg2
);
8996 ploff_in
= &loff_in
;
8999 get_user_u64(loff_out
, arg2
);
9000 ploff_out
= &loff_out
;
9002 ret
= get_errno(splice(arg1
, ploff_in
, arg3
, ploff_out
, arg5
, arg6
));
9006 #ifdef TARGET_NR_vmsplice
9007 case TARGET_NR_vmsplice
:
9009 struct iovec
*vec
= lock_iovec(VERIFY_READ
, arg2
, arg3
, 1);
9011 ret
= get_errno(vmsplice(arg1
, vec
, arg3
, arg4
));
9012 unlock_iovec(vec
, arg2
, arg3
, 0);
9014 ret
= -host_to_target_errno(errno
);
9019 #endif /* CONFIG_SPLICE */
9020 #ifdef CONFIG_EVENTFD
9021 #if defined(TARGET_NR_eventfd)
9022 case TARGET_NR_eventfd
:
9023 ret
= get_errno(eventfd(arg1
, 0));
9026 #if defined(TARGET_NR_eventfd2)
9027 case TARGET_NR_eventfd2
:
9029 int host_flags
= arg2
& (~(TARGET_O_NONBLOCK
| TARGET_O_CLOEXEC
));
9030 if (arg2
& TARGET_O_NONBLOCK
) {
9031 host_flags
|= O_NONBLOCK
;
9033 if (arg2
& TARGET_O_CLOEXEC
) {
9034 host_flags
|= O_CLOEXEC
;
9036 ret
= get_errno(eventfd(arg1
, host_flags
));
9040 #endif /* CONFIG_EVENTFD */
9041 #if defined(CONFIG_FALLOCATE) && defined(TARGET_NR_fallocate)
9042 case TARGET_NR_fallocate
:
9043 #if TARGET_ABI_BITS == 32
9044 ret
= get_errno(fallocate(arg1
, arg2
, target_offset64(arg3
, arg4
),
9045 target_offset64(arg5
, arg6
)));
9047 ret
= get_errno(fallocate(arg1
, arg2
, arg3
, arg4
));
9051 #if defined(CONFIG_SYNC_FILE_RANGE)
9052 #if defined(TARGET_NR_sync_file_range)
9053 case TARGET_NR_sync_file_range
:
9054 #if TARGET_ABI_BITS == 32
9055 #if defined(TARGET_MIPS)
9056 ret
= get_errno(sync_file_range(arg1
, target_offset64(arg3
, arg4
),
9057 target_offset64(arg5
, arg6
), arg7
));
9059 ret
= get_errno(sync_file_range(arg1
, target_offset64(arg2
, arg3
),
9060 target_offset64(arg4
, arg5
), arg6
));
9061 #endif /* !TARGET_MIPS */
9063 ret
= get_errno(sync_file_range(arg1
, arg2
, arg3
, arg4
));
9067 #if defined(TARGET_NR_sync_file_range2)
9068 case TARGET_NR_sync_file_range2
:
9069 /* This is like sync_file_range but the arguments are reordered */
9070 #if TARGET_ABI_BITS == 32
9071 ret
= get_errno(sync_file_range(arg1
, target_offset64(arg3
, arg4
),
9072 target_offset64(arg5
, arg6
), arg2
));
9074 ret
= get_errno(sync_file_range(arg1
, arg3
, arg4
, arg2
));
9079 #if defined(CONFIG_EPOLL)
9080 #if defined(TARGET_NR_epoll_create)
9081 case TARGET_NR_epoll_create
:
9082 ret
= get_errno(epoll_create(arg1
));
9085 #if defined(TARGET_NR_epoll_create1) && defined(CONFIG_EPOLL_CREATE1)
9086 case TARGET_NR_epoll_create1
:
9087 ret
= get_errno(epoll_create1(arg1
));
9090 #if defined(TARGET_NR_epoll_ctl)
9091 case TARGET_NR_epoll_ctl
:
9093 struct epoll_event ep
;
9094 struct epoll_event
*epp
= 0;
9096 struct target_epoll_event
*target_ep
;
9097 if (!lock_user_struct(VERIFY_READ
, target_ep
, arg4
, 1)) {
9100 ep
.events
= tswap32(target_ep
->events
);
9101 /* The epoll_data_t union is just opaque data to the kernel,
9102 * so we transfer all 64 bits across and need not worry what
9103 * actual data type it is.
9105 ep
.data
.u64
= tswap64(target_ep
->data
.u64
);
9106 unlock_user_struct(target_ep
, arg4
, 0);
9109 ret
= get_errno(epoll_ctl(arg1
, arg2
, arg3
, epp
));
9114 #if defined(TARGET_NR_epoll_pwait) && defined(CONFIG_EPOLL_PWAIT)
9115 #define IMPLEMENT_EPOLL_PWAIT
9117 #if defined(TARGET_NR_epoll_wait) || defined(IMPLEMENT_EPOLL_PWAIT)
9118 #if defined(TARGET_NR_epoll_wait)
9119 case TARGET_NR_epoll_wait
:
9121 #if defined(IMPLEMENT_EPOLL_PWAIT)
9122 case TARGET_NR_epoll_pwait
:
9125 struct target_epoll_event
*target_ep
;
9126 struct epoll_event
*ep
;
9128 int maxevents
= arg3
;
9131 target_ep
= lock_user(VERIFY_WRITE
, arg2
,
9132 maxevents
* sizeof(struct target_epoll_event
), 1);
9137 ep
= alloca(maxevents
* sizeof(struct epoll_event
));
9140 #if defined(IMPLEMENT_EPOLL_PWAIT)
9141 case TARGET_NR_epoll_pwait
:
9143 target_sigset_t
*target_set
;
9144 sigset_t _set
, *set
= &_set
;
9147 target_set
= lock_user(VERIFY_READ
, arg5
,
9148 sizeof(target_sigset_t
), 1);
9150 unlock_user(target_ep
, arg2
, 0);
9153 target_to_host_sigset(set
, target_set
);
9154 unlock_user(target_set
, arg5
, 0);
9159 ret
= get_errno(epoll_pwait(epfd
, ep
, maxevents
, timeout
, set
));
9163 #if defined(TARGET_NR_epoll_wait)
9164 case TARGET_NR_epoll_wait
:
9165 ret
= get_errno(epoll_wait(epfd
, ep
, maxevents
, timeout
));
9169 ret
= -TARGET_ENOSYS
;
9171 if (!is_error(ret
)) {
9173 for (i
= 0; i
< ret
; i
++) {
9174 target_ep
[i
].events
= tswap32(ep
[i
].events
);
9175 target_ep
[i
].data
.u64
= tswap64(ep
[i
].data
.u64
);
9178 unlock_user(target_ep
, arg2
, ret
* sizeof(struct target_epoll_event
));
9183 #ifdef TARGET_NR_prlimit64
9184 case TARGET_NR_prlimit64
:
9186 /* args: pid, resource number, ptr to new rlimit, ptr to old rlimit */
9187 struct target_rlimit64
*target_rnew
, *target_rold
;
9188 struct host_rlimit64 rnew
, rold
, *rnewp
= 0;
9190 if (!lock_user_struct(VERIFY_READ
, target_rnew
, arg3
, 1)) {
9193 rnew
.rlim_cur
= tswap64(target_rnew
->rlim_cur
);
9194 rnew
.rlim_max
= tswap64(target_rnew
->rlim_max
);
9195 unlock_user_struct(target_rnew
, arg3
, 0);
9199 ret
= get_errno(sys_prlimit64(arg1
, arg2
, rnewp
, arg4
? &rold
: 0));
9200 if (!is_error(ret
) && arg4
) {
9201 if (!lock_user_struct(VERIFY_WRITE
, target_rold
, arg4
, 1)) {
9204 target_rold
->rlim_cur
= tswap64(rold
.rlim_cur
);
9205 target_rold
->rlim_max
= tswap64(rold
.rlim_max
);
9206 unlock_user_struct(target_rold
, arg4
, 1);
9211 #ifdef TARGET_NR_gethostname
9212 case TARGET_NR_gethostname
:
9214 char *name
= lock_user(VERIFY_WRITE
, arg1
, arg2
, 0);
9216 ret
= get_errno(gethostname(name
, arg2
));
9217 unlock_user(name
, arg1
, arg2
);
9219 ret
= -TARGET_EFAULT
;
9224 #ifdef TARGET_NR_atomic_cmpxchg_32
9225 case TARGET_NR_atomic_cmpxchg_32
:
9227 /* should use start_exclusive from main.c */
9228 abi_ulong mem_value
;
9229 if (get_user_u32(mem_value
, arg6
)) {
9230 target_siginfo_t info
;
9231 info
.si_signo
= SIGSEGV
;
9233 info
.si_code
= TARGET_SEGV_MAPERR
;
9234 info
._sifields
._sigfault
._addr
= arg6
;
9235 queue_signal((CPUArchState
*)cpu_env
, info
.si_signo
, &info
);
9239 if (mem_value
== arg2
)
9240 put_user_u32(arg1
, arg6
);
9245 #ifdef TARGET_NR_atomic_barrier
9246 case TARGET_NR_atomic_barrier
:
9248 /* Like the kernel implementation and the qemu arm barrier, no-op this? */
9253 #ifdef TARGET_NR_timer_create
9254 case TARGET_NR_timer_create
:
9256 /* args: clockid_t clockid, struct sigevent *sevp, timer_t *timerid */
9258 struct sigevent host_sevp
= { {0}, }, *phost_sevp
= NULL
;
9259 struct target_sigevent
*ptarget_sevp
;
9260 struct target_timer_t
*ptarget_timer
;
9263 int timer_index
= next_free_host_timer();
9265 if (timer_index
< 0) {
9266 ret
= -TARGET_EAGAIN
;
9268 timer_t
*phtimer
= g_posix_timers
+ timer_index
;
9271 if (!lock_user_struct(VERIFY_READ
, ptarget_sevp
, arg2
, 1)) {
9275 host_sevp
.sigev_signo
= tswap32(ptarget_sevp
->sigev_signo
);
9276 host_sevp
.sigev_notify
= tswap32(ptarget_sevp
->sigev_notify
);
9278 phost_sevp
= &host_sevp
;
9281 ret
= get_errno(timer_create(clkid
, phost_sevp
, phtimer
));
9285 if (!lock_user_struct(VERIFY_WRITE
, ptarget_timer
, arg3
, 1)) {
9288 ptarget_timer
->ptr
= tswap32(0xcafe0000 | timer_index
);
9289 unlock_user_struct(ptarget_timer
, arg3
, 1);
9296 #ifdef TARGET_NR_timer_settime
9297 case TARGET_NR_timer_settime
:
9299 /* args: timer_t timerid, int flags, const struct itimerspec *new_value,
9300 * struct itimerspec * old_value */
9302 if (arg3
== 0 || arg1
< 0 || arg1
>= ARRAY_SIZE(g_posix_timers
)) {
9303 ret
= -TARGET_EINVAL
;
9305 timer_t htimer
= g_posix_timers
[arg1
];
9306 struct itimerspec hspec_new
= {{0},}, hspec_old
= {{0},};
9308 target_to_host_itimerspec(&hspec_new
, arg3
);
9310 timer_settime(htimer
, arg2
, &hspec_new
, &hspec_old
));
9311 host_to_target_itimerspec(arg2
, &hspec_old
);
9317 #ifdef TARGET_NR_timer_gettime
9318 case TARGET_NR_timer_gettime
:
9320 /* args: timer_t timerid, struct itimerspec *curr_value */
9323 return -TARGET_EFAULT
;
9324 } else if (arg1
< 0 || arg1
>= ARRAY_SIZE(g_posix_timers
)) {
9325 ret
= -TARGET_EINVAL
;
9327 timer_t htimer
= g_posix_timers
[arg1
];
9328 struct itimerspec hspec
;
9329 ret
= get_errno(timer_gettime(htimer
, &hspec
));
9331 if (host_to_target_itimerspec(arg2
, &hspec
)) {
9332 ret
= -TARGET_EFAULT
;
9339 #ifdef TARGET_NR_timer_getoverrun
9340 case TARGET_NR_timer_getoverrun
:
9342 /* args: timer_t timerid */
9344 if (arg1
< 0 || arg1
>= ARRAY_SIZE(g_posix_timers
)) {
9345 ret
= -TARGET_EINVAL
;
9347 timer_t htimer
= g_posix_timers
[arg1
];
9348 ret
= get_errno(timer_getoverrun(htimer
));
9354 #ifdef TARGET_NR_timer_delete
9355 case TARGET_NR_timer_delete
:
9357 /* args: timer_t timerid */
9359 if (arg1
< 0 || arg1
>= ARRAY_SIZE(g_posix_timers
)) {
9360 ret
= -TARGET_EINVAL
;
9362 timer_t htimer
= g_posix_timers
[arg1
];
9363 ret
= get_errno(timer_delete(htimer
));
9364 g_posix_timers
[arg1
] = 0;
9372 gemu_log("qemu: Unsupported syscall: %d\n", num
);
9373 #if defined(TARGET_NR_setxattr) || defined(TARGET_NR_get_thread_area) || defined(TARGET_NR_getdomainname) || defined(TARGET_NR_set_robust_list)
9374 unimplemented_nowarn
:
9376 ret
= -TARGET_ENOSYS
;
9381 gemu_log(" = " TARGET_ABI_FMT_ld
"\n", ret
);
9384 print_syscall_ret(num
, ret
);
9387 ret
= -TARGET_EFAULT
;