4 * Copyright (c) 2003 Fabrice Bellard
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
19 #define _ATFILE_SOURCE
31 #include <sys/types.h>
37 #include <sys/mount.h>
38 #include <sys/prctl.h>
39 #include <sys/resource.h>
45 int __clone2(int (*fn
)(void *), void *child_stack_base
,
46 size_t stack_size
, int flags
, void *arg
, ...);
48 #include <sys/socket.h>
52 #include <sys/times.h>
55 #include <sys/statfs.h>
57 #include <sys/sysinfo.h>
58 #include <sys/utsname.h>
59 //#include <sys/user.h>
60 #include <netinet/ip.h>
61 #include <netinet/tcp.h>
62 #include <linux/wireless.h>
63 #include "qemu-common.h"
68 #include <sys/eventfd.h>
71 #include <sys/epoll.h>
74 #include "qemu-xattr.h"
77 #define termios host_termios
78 #define winsize host_winsize
79 #define termio host_termio
80 #define sgttyb host_sgttyb /* same as target */
81 #define tchars host_tchars /* same as target */
82 #define ltchars host_ltchars /* same as target */
84 #include <linux/termios.h>
85 #include <linux/unistd.h>
86 #include <linux/utsname.h>
87 #include <linux/cdrom.h>
88 #include <linux/hdreg.h>
89 #include <linux/soundcard.h>
91 #include <linux/mtio.h>
93 #if defined(CONFIG_FIEMAP)
94 #include <linux/fiemap.h>
98 #include <linux/dm-ioctl.h>
99 #include "linux_loop.h"
100 #include "cpu-uname.h"
104 #if defined(CONFIG_USE_NPTL)
105 #define CLONE_NPTL_FLAGS2 (CLONE_SETTLS | \
106 CLONE_PARENT_SETTID | CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID)
108 /* XXX: Hardcode the above values. */
109 #define CLONE_NPTL_FLAGS2 0
114 //#include <linux/msdos_fs.h>
115 #define VFAT_IOCTL_READDIR_BOTH _IOR('r', 1, struct linux_dirent [2])
116 #define VFAT_IOCTL_READDIR_SHORT _IOR('r', 2, struct linux_dirent [2])
127 #define _syscall0(type,name) \
128 static type name (void) \
130 return syscall(__NR_##name); \
133 #define _syscall1(type,name,type1,arg1) \
134 static type name (type1 arg1) \
136 return syscall(__NR_##name, arg1); \
139 #define _syscall2(type,name,type1,arg1,type2,arg2) \
140 static type name (type1 arg1,type2 arg2) \
142 return syscall(__NR_##name, arg1, arg2); \
145 #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
146 static type name (type1 arg1,type2 arg2,type3 arg3) \
148 return syscall(__NR_##name, arg1, arg2, arg3); \
151 #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
152 static type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4) \
154 return syscall(__NR_##name, arg1, arg2, arg3, arg4); \
157 #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
159 static type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \
161 return syscall(__NR_##name, arg1, arg2, arg3, arg4, arg5); \
165 #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
166 type5,arg5,type6,arg6) \
167 static type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5, \
170 return syscall(__NR_##name, arg1, arg2, arg3, arg4, arg5, arg6); \
174 #define __NR_sys_uname __NR_uname
175 #define __NR_sys_faccessat __NR_faccessat
176 #define __NR_sys_fchmodat __NR_fchmodat
177 #define __NR_sys_fchownat __NR_fchownat
178 #define __NR_sys_fstatat64 __NR_fstatat64
179 #define __NR_sys_futimesat __NR_futimesat
180 #define __NR_sys_getcwd1 __NR_getcwd
181 #define __NR_sys_getdents __NR_getdents
182 #define __NR_sys_getdents64 __NR_getdents64
183 #define __NR_sys_getpriority __NR_getpriority
184 #define __NR_sys_linkat __NR_linkat
185 #define __NR_sys_mkdirat __NR_mkdirat
186 #define __NR_sys_mknodat __NR_mknodat
187 #define __NR_sys_newfstatat __NR_newfstatat
188 #define __NR_sys_openat __NR_openat
189 #define __NR_sys_readlinkat __NR_readlinkat
190 #define __NR_sys_renameat __NR_renameat
191 #define __NR_sys_rt_sigqueueinfo __NR_rt_sigqueueinfo
192 #define __NR_sys_symlinkat __NR_symlinkat
193 #define __NR_sys_syslog __NR_syslog
194 #define __NR_sys_tgkill __NR_tgkill
195 #define __NR_sys_tkill __NR_tkill
196 #define __NR_sys_unlinkat __NR_unlinkat
197 #define __NR_sys_utimensat __NR_utimensat
198 #define __NR_sys_futex __NR_futex
199 #define __NR_sys_inotify_init __NR_inotify_init
200 #define __NR_sys_inotify_add_watch __NR_inotify_add_watch
201 #define __NR_sys_inotify_rm_watch __NR_inotify_rm_watch
203 #if defined(__alpha__) || defined (__ia64__) || defined(__x86_64__) || \
205 #define __NR__llseek __NR_lseek
209 _syscall0(int, gettid
)
211 /* This is a replacement for the host gettid() and must return a host
213 static int gettid(void) {
217 _syscall3(int, sys_getdents
, uint
, fd
, struct linux_dirent
*, dirp
, uint
, count
);
218 #if defined(TARGET_NR_getdents64) && defined(__NR_getdents64)
219 _syscall3(int, sys_getdents64
, uint
, fd
, struct linux_dirent64
*, dirp
, uint
, count
);
221 #if defined(TARGET_NR__llseek) && defined(__NR_llseek)
222 _syscall5(int, _llseek
, uint
, fd
, ulong
, hi
, ulong
, lo
,
223 loff_t
*, res
, uint
, wh
);
225 _syscall3(int,sys_rt_sigqueueinfo
,int,pid
,int,sig
,siginfo_t
*,uinfo
)
226 _syscall3(int,sys_syslog
,int,type
,char*,bufp
,int,len
)
227 #if defined(TARGET_NR_tgkill) && defined(__NR_tgkill)
228 _syscall3(int,sys_tgkill
,int,tgid
,int,pid
,int,sig
)
230 #if defined(TARGET_NR_tkill) && defined(__NR_tkill)
231 _syscall2(int,sys_tkill
,int,tid
,int,sig
)
233 #ifdef __NR_exit_group
234 _syscall1(int,exit_group
,int,error_code
)
236 #if defined(TARGET_NR_set_tid_address) && defined(__NR_set_tid_address)
237 _syscall1(int,set_tid_address
,int *,tidptr
)
239 #if defined(CONFIG_USE_NPTL)
240 #if defined(TARGET_NR_futex) && defined(__NR_futex)
241 _syscall6(int,sys_futex
,int *,uaddr
,int,op
,int,val
,
242 const struct timespec
*,timeout
,int *,uaddr2
,int,val3
)
245 #define __NR_sys_sched_getaffinity __NR_sched_getaffinity
246 _syscall3(int, sys_sched_getaffinity
, pid_t
, pid
, unsigned int, len
,
247 unsigned long *, user_mask_ptr
);
248 #define __NR_sys_sched_setaffinity __NR_sched_setaffinity
249 _syscall3(int, sys_sched_setaffinity
, pid_t
, pid
, unsigned int, len
,
250 unsigned long *, user_mask_ptr
);
251 _syscall4(int, reboot
, int, magic1
, int, magic2
, unsigned int, cmd
,
254 static bitmask_transtbl fcntl_flags_tbl
[] = {
255 { TARGET_O_ACCMODE
, TARGET_O_WRONLY
, O_ACCMODE
, O_WRONLY
, },
256 { TARGET_O_ACCMODE
, TARGET_O_RDWR
, O_ACCMODE
, O_RDWR
, },
257 { TARGET_O_CREAT
, TARGET_O_CREAT
, O_CREAT
, O_CREAT
, },
258 { TARGET_O_EXCL
, TARGET_O_EXCL
, O_EXCL
, O_EXCL
, },
259 { TARGET_O_NOCTTY
, TARGET_O_NOCTTY
, O_NOCTTY
, O_NOCTTY
, },
260 { TARGET_O_TRUNC
, TARGET_O_TRUNC
, O_TRUNC
, O_TRUNC
, },
261 { TARGET_O_APPEND
, TARGET_O_APPEND
, O_APPEND
, O_APPEND
, },
262 { TARGET_O_NONBLOCK
, TARGET_O_NONBLOCK
, O_NONBLOCK
, O_NONBLOCK
, },
263 { TARGET_O_SYNC
, TARGET_O_DSYNC
, O_SYNC
, O_DSYNC
, },
264 { TARGET_O_SYNC
, TARGET_O_SYNC
, O_SYNC
, O_SYNC
, },
265 { TARGET_FASYNC
, TARGET_FASYNC
, FASYNC
, FASYNC
, },
266 { TARGET_O_DIRECTORY
, TARGET_O_DIRECTORY
, O_DIRECTORY
, O_DIRECTORY
, },
267 { TARGET_O_NOFOLLOW
, TARGET_O_NOFOLLOW
, O_NOFOLLOW
, O_NOFOLLOW
, },
268 #if defined(O_DIRECT)
269 { TARGET_O_DIRECT
, TARGET_O_DIRECT
, O_DIRECT
, O_DIRECT
, },
271 #if defined(O_NOATIME)
272 { TARGET_O_NOATIME
, TARGET_O_NOATIME
, O_NOATIME
, O_NOATIME
},
274 #if defined(O_CLOEXEC)
275 { TARGET_O_CLOEXEC
, TARGET_O_CLOEXEC
, O_CLOEXEC
, O_CLOEXEC
},
278 { TARGET_O_PATH
, TARGET_O_PATH
, O_PATH
, O_PATH
},
280 /* Don't terminate the list prematurely on 64-bit host+guest. */
281 #if TARGET_O_LARGEFILE != 0 || O_LARGEFILE != 0
282 { TARGET_O_LARGEFILE
, TARGET_O_LARGEFILE
, O_LARGEFILE
, O_LARGEFILE
, },
287 #define COPY_UTSNAME_FIELD(dest, src) \
289 /* __NEW_UTS_LEN doesn't include terminating null */ \
290 (void) strncpy((dest), (src), __NEW_UTS_LEN); \
291 (dest)[__NEW_UTS_LEN] = '\0'; \
294 static int sys_uname(struct new_utsname
*buf
)
296 struct utsname uts_buf
;
298 if (uname(&uts_buf
) < 0)
302 * Just in case these have some differences, we
303 * translate utsname to new_utsname (which is the
304 * struct linux kernel uses).
307 memset(buf
, 0, sizeof(*buf
));
308 COPY_UTSNAME_FIELD(buf
->sysname
, uts_buf
.sysname
);
309 COPY_UTSNAME_FIELD(buf
->nodename
, uts_buf
.nodename
);
310 COPY_UTSNAME_FIELD(buf
->release
, uts_buf
.release
);
311 COPY_UTSNAME_FIELD(buf
->version
, uts_buf
.version
);
312 COPY_UTSNAME_FIELD(buf
->machine
, uts_buf
.machine
);
314 COPY_UTSNAME_FIELD(buf
->domainname
, uts_buf
.domainname
);
318 #undef COPY_UTSNAME_FIELD
321 static int sys_getcwd1(char *buf
, size_t size
)
323 if (getcwd(buf
, size
) == NULL
) {
324 /* getcwd() sets errno */
327 return strlen(buf
)+1;
332 * Host system seems to have atfile syscall stubs available. We
333 * now enable them one by one as specified by target syscall_nr.h.
336 #ifdef TARGET_NR_faccessat
337 static int sys_faccessat(int dirfd
, const char *pathname
, int mode
)
339 return (faccessat(dirfd
, pathname
, mode
, 0));
342 #ifdef TARGET_NR_fchmodat
343 static int sys_fchmodat(int dirfd
, const char *pathname
, mode_t mode
)
345 return (fchmodat(dirfd
, pathname
, mode
, 0));
348 #if defined(TARGET_NR_fchownat)
349 static int sys_fchownat(int dirfd
, const char *pathname
, uid_t owner
,
350 gid_t group
, int flags
)
352 return (fchownat(dirfd
, pathname
, owner
, group
, flags
));
355 #ifdef __NR_fstatat64
356 static int sys_fstatat64(int dirfd
, const char *pathname
, struct stat
*buf
,
359 return (fstatat(dirfd
, pathname
, buf
, flags
));
362 #ifdef __NR_newfstatat
363 static int sys_newfstatat(int dirfd
, const char *pathname
, struct stat
*buf
,
366 return (fstatat(dirfd
, pathname
, buf
, flags
));
369 #ifdef TARGET_NR_futimesat
370 static int sys_futimesat(int dirfd
, const char *pathname
,
371 const struct timeval times
[2])
373 return (futimesat(dirfd
, pathname
, times
));
376 #ifdef TARGET_NR_linkat
377 static int sys_linkat(int olddirfd
, const char *oldpath
,
378 int newdirfd
, const char *newpath
, int flags
)
380 return (linkat(olddirfd
, oldpath
, newdirfd
, newpath
, flags
));
383 #ifdef TARGET_NR_mkdirat
384 static int sys_mkdirat(int dirfd
, const char *pathname
, mode_t mode
)
386 return (mkdirat(dirfd
, pathname
, mode
));
389 #ifdef TARGET_NR_mknodat
390 static int sys_mknodat(int dirfd
, const char *pathname
, mode_t mode
,
393 return (mknodat(dirfd
, pathname
, mode
, dev
));
396 #ifdef TARGET_NR_openat
397 static int sys_openat(int dirfd
, const char *pathname
, int flags
, mode_t mode
)
400 * open(2) has extra parameter 'mode' when called with
403 if ((flags
& O_CREAT
) != 0) {
404 return (openat(dirfd
, pathname
, flags
, mode
));
406 return (openat(dirfd
, pathname
, flags
));
409 #ifdef TARGET_NR_readlinkat
410 static int sys_readlinkat(int dirfd
, const char *pathname
, char *buf
, size_t bufsiz
)
412 return (readlinkat(dirfd
, pathname
, buf
, bufsiz
));
415 #ifdef TARGET_NR_renameat
416 static int sys_renameat(int olddirfd
, const char *oldpath
,
417 int newdirfd
, const char *newpath
)
419 return (renameat(olddirfd
, oldpath
, newdirfd
, newpath
));
422 #ifdef TARGET_NR_symlinkat
423 static int sys_symlinkat(const char *oldpath
, int newdirfd
, const char *newpath
)
425 return (symlinkat(oldpath
, newdirfd
, newpath
));
428 #ifdef TARGET_NR_unlinkat
429 static int sys_unlinkat(int dirfd
, const char *pathname
, int flags
)
431 return (unlinkat(dirfd
, pathname
, flags
));
434 #else /* !CONFIG_ATFILE */
437 * Try direct syscalls instead
439 #if defined(TARGET_NR_faccessat) && defined(__NR_faccessat)
440 _syscall3(int,sys_faccessat
,int,dirfd
,const char *,pathname
,int,mode
)
442 #if defined(TARGET_NR_fchmodat) && defined(__NR_fchmodat)
443 _syscall3(int,sys_fchmodat
,int,dirfd
,const char *,pathname
, mode_t
,mode
)
445 #if defined(TARGET_NR_fchownat) && defined(__NR_fchownat)
446 _syscall5(int,sys_fchownat
,int,dirfd
,const char *,pathname
,
447 uid_t
,owner
,gid_t
,group
,int,flags
)
449 #if (defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat)) && \
450 defined(__NR_fstatat64)
451 _syscall4(int,sys_fstatat64
,int,dirfd
,const char *,pathname
,
452 struct stat
*,buf
,int,flags
)
454 #if defined(TARGET_NR_futimesat) && defined(__NR_futimesat)
455 _syscall3(int,sys_futimesat
,int,dirfd
,const char *,pathname
,
456 const struct timeval
*,times
)
458 #if (defined(TARGET_NR_newfstatat) || defined(TARGET_NR_fstatat64) ) && \
459 defined(__NR_newfstatat)
460 _syscall4(int,sys_newfstatat
,int,dirfd
,const char *,pathname
,
461 struct stat
*,buf
,int,flags
)
463 #if defined(TARGET_NR_linkat) && defined(__NR_linkat)
464 _syscall5(int,sys_linkat
,int,olddirfd
,const char *,oldpath
,
465 int,newdirfd
,const char *,newpath
,int,flags
)
467 #if defined(TARGET_NR_mkdirat) && defined(__NR_mkdirat)
468 _syscall3(int,sys_mkdirat
,int,dirfd
,const char *,pathname
,mode_t
,mode
)
470 #if defined(TARGET_NR_mknodat) && defined(__NR_mknodat)
471 _syscall4(int,sys_mknodat
,int,dirfd
,const char *,pathname
,
472 mode_t
,mode
,dev_t
,dev
)
474 #if defined(TARGET_NR_openat) && defined(__NR_openat)
475 _syscall4(int,sys_openat
,int,dirfd
,const char *,pathname
,int,flags
,mode_t
,mode
)
477 #if defined(TARGET_NR_readlinkat) && defined(__NR_readlinkat)
478 _syscall4(int,sys_readlinkat
,int,dirfd
,const char *,pathname
,
479 char *,buf
,size_t,bufsize
)
481 #if defined(TARGET_NR_renameat) && defined(__NR_renameat)
482 _syscall4(int,sys_renameat
,int,olddirfd
,const char *,oldpath
,
483 int,newdirfd
,const char *,newpath
)
485 #if defined(TARGET_NR_symlinkat) && defined(__NR_symlinkat)
486 _syscall3(int,sys_symlinkat
,const char *,oldpath
,
487 int,newdirfd
,const char *,newpath
)
489 #if defined(TARGET_NR_unlinkat) && defined(__NR_unlinkat)
490 _syscall3(int,sys_unlinkat
,int,dirfd
,const char *,pathname
,int,flags
)
493 #endif /* CONFIG_ATFILE */
495 #ifdef CONFIG_UTIMENSAT
496 static int sys_utimensat(int dirfd
, const char *pathname
,
497 const struct timespec times
[2], int flags
)
499 if (pathname
== NULL
)
500 return futimens(dirfd
, times
);
502 return utimensat(dirfd
, pathname
, times
, flags
);
505 #if defined(TARGET_NR_utimensat) && defined(__NR_utimensat)
506 _syscall4(int,sys_utimensat
,int,dirfd
,const char *,pathname
,
507 const struct timespec
*,tsp
,int,flags
)
509 #endif /* CONFIG_UTIMENSAT */
511 #ifdef CONFIG_INOTIFY
512 #include <sys/inotify.h>
514 #if defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init)
515 static int sys_inotify_init(void)
517 return (inotify_init());
520 #if defined(TARGET_NR_inotify_add_watch) && defined(__NR_inotify_add_watch)
521 static int sys_inotify_add_watch(int fd
,const char *pathname
, int32_t mask
)
523 return (inotify_add_watch(fd
, pathname
, mask
));
526 #if defined(TARGET_NR_inotify_rm_watch) && defined(__NR_inotify_rm_watch)
527 static int sys_inotify_rm_watch(int fd
, int32_t wd
)
529 return (inotify_rm_watch(fd
, wd
));
532 #ifdef CONFIG_INOTIFY1
533 #if defined(TARGET_NR_inotify_init1) && defined(__NR_inotify_init1)
534 static int sys_inotify_init1(int flags
)
536 return (inotify_init1(flags
));
541 /* Userspace can usually survive runtime without inotify */
542 #undef TARGET_NR_inotify_init
543 #undef TARGET_NR_inotify_init1
544 #undef TARGET_NR_inotify_add_watch
545 #undef TARGET_NR_inotify_rm_watch
546 #endif /* CONFIG_INOTIFY */
548 #if defined(TARGET_NR_ppoll)
550 # define __NR_ppoll -1
552 #define __NR_sys_ppoll __NR_ppoll
553 _syscall5(int, sys_ppoll
, struct pollfd
*, fds
, nfds_t
, nfds
,
554 struct timespec
*, timeout
, const __sigset_t
*, sigmask
,
558 #if defined(TARGET_NR_pselect6)
559 #ifndef __NR_pselect6
560 # define __NR_pselect6 -1
562 #define __NR_sys_pselect6 __NR_pselect6
563 _syscall6(int, sys_pselect6
, int, nfds
, fd_set
*, readfds
, fd_set
*, writefds
,
564 fd_set
*, exceptfds
, struct timespec
*, timeout
, void *, sig
);
567 #if defined(TARGET_NR_prlimit64)
568 #ifndef __NR_prlimit64
569 # define __NR_prlimit64 -1
571 #define __NR_sys_prlimit64 __NR_prlimit64
572 /* The glibc rlimit structure may not be that used by the underlying syscall */
573 struct host_rlimit64
{
577 _syscall4(int, sys_prlimit64
, pid_t
, pid
, int, resource
,
578 const struct host_rlimit64
*, new_limit
,
579 struct host_rlimit64
*, old_limit
)
582 extern int personality(int);
583 extern int flock(int, int);
584 extern int setfsuid(int);
585 extern int setfsgid(int);
586 extern int setgroups(int, gid_t
*);
588 /* ARM EABI and MIPS expect 64bit types aligned even on pairs or registers */
590 static inline int regpairs_aligned(void *cpu_env
) {
591 return ((((CPUARMState
*)cpu_env
)->eabi
) == 1) ;
593 #elif defined(TARGET_MIPS)
594 static inline int regpairs_aligned(void *cpu_env
) { return 1; }
596 static inline int regpairs_aligned(void *cpu_env
) { return 0; }
599 #define ERRNO_TABLE_SIZE 1200
601 /* target_to_host_errno_table[] is initialized from
602 * host_to_target_errno_table[] in syscall_init(). */
603 static uint16_t target_to_host_errno_table
[ERRNO_TABLE_SIZE
] = {
607 * This list is the union of errno values overridden in asm-<arch>/errno.h
608 * minus the errnos that are not actually generic to all archs.
610 static uint16_t host_to_target_errno_table
[ERRNO_TABLE_SIZE
] = {
611 [EIDRM
] = TARGET_EIDRM
,
612 [ECHRNG
] = TARGET_ECHRNG
,
613 [EL2NSYNC
] = TARGET_EL2NSYNC
,
614 [EL3HLT
] = TARGET_EL3HLT
,
615 [EL3RST
] = TARGET_EL3RST
,
616 [ELNRNG
] = TARGET_ELNRNG
,
617 [EUNATCH
] = TARGET_EUNATCH
,
618 [ENOCSI
] = TARGET_ENOCSI
,
619 [EL2HLT
] = TARGET_EL2HLT
,
620 [EDEADLK
] = TARGET_EDEADLK
,
621 [ENOLCK
] = TARGET_ENOLCK
,
622 [EBADE
] = TARGET_EBADE
,
623 [EBADR
] = TARGET_EBADR
,
624 [EXFULL
] = TARGET_EXFULL
,
625 [ENOANO
] = TARGET_ENOANO
,
626 [EBADRQC
] = TARGET_EBADRQC
,
627 [EBADSLT
] = TARGET_EBADSLT
,
628 [EBFONT
] = TARGET_EBFONT
,
629 [ENOSTR
] = TARGET_ENOSTR
,
630 [ENODATA
] = TARGET_ENODATA
,
631 [ETIME
] = TARGET_ETIME
,
632 [ENOSR
] = TARGET_ENOSR
,
633 [ENONET
] = TARGET_ENONET
,
634 [ENOPKG
] = TARGET_ENOPKG
,
635 [EREMOTE
] = TARGET_EREMOTE
,
636 [ENOLINK
] = TARGET_ENOLINK
,
637 [EADV
] = TARGET_EADV
,
638 [ESRMNT
] = TARGET_ESRMNT
,
639 [ECOMM
] = TARGET_ECOMM
,
640 [EPROTO
] = TARGET_EPROTO
,
641 [EDOTDOT
] = TARGET_EDOTDOT
,
642 [EMULTIHOP
] = TARGET_EMULTIHOP
,
643 [EBADMSG
] = TARGET_EBADMSG
,
644 [ENAMETOOLONG
] = TARGET_ENAMETOOLONG
,
645 [EOVERFLOW
] = TARGET_EOVERFLOW
,
646 [ENOTUNIQ
] = TARGET_ENOTUNIQ
,
647 [EBADFD
] = TARGET_EBADFD
,
648 [EREMCHG
] = TARGET_EREMCHG
,
649 [ELIBACC
] = TARGET_ELIBACC
,
650 [ELIBBAD
] = TARGET_ELIBBAD
,
651 [ELIBSCN
] = TARGET_ELIBSCN
,
652 [ELIBMAX
] = TARGET_ELIBMAX
,
653 [ELIBEXEC
] = TARGET_ELIBEXEC
,
654 [EILSEQ
] = TARGET_EILSEQ
,
655 [ENOSYS
] = TARGET_ENOSYS
,
656 [ELOOP
] = TARGET_ELOOP
,
657 [ERESTART
] = TARGET_ERESTART
,
658 [ESTRPIPE
] = TARGET_ESTRPIPE
,
659 [ENOTEMPTY
] = TARGET_ENOTEMPTY
,
660 [EUSERS
] = TARGET_EUSERS
,
661 [ENOTSOCK
] = TARGET_ENOTSOCK
,
662 [EDESTADDRREQ
] = TARGET_EDESTADDRREQ
,
663 [EMSGSIZE
] = TARGET_EMSGSIZE
,
664 [EPROTOTYPE
] = TARGET_EPROTOTYPE
,
665 [ENOPROTOOPT
] = TARGET_ENOPROTOOPT
,
666 [EPROTONOSUPPORT
] = TARGET_EPROTONOSUPPORT
,
667 [ESOCKTNOSUPPORT
] = TARGET_ESOCKTNOSUPPORT
,
668 [EOPNOTSUPP
] = TARGET_EOPNOTSUPP
,
669 [EPFNOSUPPORT
] = TARGET_EPFNOSUPPORT
,
670 [EAFNOSUPPORT
] = TARGET_EAFNOSUPPORT
,
671 [EADDRINUSE
] = TARGET_EADDRINUSE
,
672 [EADDRNOTAVAIL
] = TARGET_EADDRNOTAVAIL
,
673 [ENETDOWN
] = TARGET_ENETDOWN
,
674 [ENETUNREACH
] = TARGET_ENETUNREACH
,
675 [ENETRESET
] = TARGET_ENETRESET
,
676 [ECONNABORTED
] = TARGET_ECONNABORTED
,
677 [ECONNRESET
] = TARGET_ECONNRESET
,
678 [ENOBUFS
] = TARGET_ENOBUFS
,
679 [EISCONN
] = TARGET_EISCONN
,
680 [ENOTCONN
] = TARGET_ENOTCONN
,
681 [EUCLEAN
] = TARGET_EUCLEAN
,
682 [ENOTNAM
] = TARGET_ENOTNAM
,
683 [ENAVAIL
] = TARGET_ENAVAIL
,
684 [EISNAM
] = TARGET_EISNAM
,
685 [EREMOTEIO
] = TARGET_EREMOTEIO
,
686 [ESHUTDOWN
] = TARGET_ESHUTDOWN
,
687 [ETOOMANYREFS
] = TARGET_ETOOMANYREFS
,
688 [ETIMEDOUT
] = TARGET_ETIMEDOUT
,
689 [ECONNREFUSED
] = TARGET_ECONNREFUSED
,
690 [EHOSTDOWN
] = TARGET_EHOSTDOWN
,
691 [EHOSTUNREACH
] = TARGET_EHOSTUNREACH
,
692 [EALREADY
] = TARGET_EALREADY
,
693 [EINPROGRESS
] = TARGET_EINPROGRESS
,
694 [ESTALE
] = TARGET_ESTALE
,
695 [ECANCELED
] = TARGET_ECANCELED
,
696 [ENOMEDIUM
] = TARGET_ENOMEDIUM
,
697 [EMEDIUMTYPE
] = TARGET_EMEDIUMTYPE
,
699 [ENOKEY
] = TARGET_ENOKEY
,
702 [EKEYEXPIRED
] = TARGET_EKEYEXPIRED
,
705 [EKEYREVOKED
] = TARGET_EKEYREVOKED
,
708 [EKEYREJECTED
] = TARGET_EKEYREJECTED
,
711 [EOWNERDEAD
] = TARGET_EOWNERDEAD
,
713 #ifdef ENOTRECOVERABLE
714 [ENOTRECOVERABLE
] = TARGET_ENOTRECOVERABLE
,
718 static inline int host_to_target_errno(int err
)
720 if(host_to_target_errno_table
[err
])
721 return host_to_target_errno_table
[err
];
725 static inline int target_to_host_errno(int err
)
727 if (target_to_host_errno_table
[err
])
728 return target_to_host_errno_table
[err
];
732 static inline abi_long
get_errno(abi_long ret
)
735 return -host_to_target_errno(errno
);
740 static inline int is_error(abi_long ret
)
742 return (abi_ulong
)ret
>= (abi_ulong
)(-4096);
745 char *target_strerror(int err
)
747 if ((err
>= ERRNO_TABLE_SIZE
) || (err
< 0)) {
750 return strerror(target_to_host_errno(err
));
753 static abi_ulong target_brk
;
754 static abi_ulong target_original_brk
;
755 static abi_ulong brk_page
;
757 void target_set_brk(abi_ulong new_brk
)
759 target_original_brk
= target_brk
= HOST_PAGE_ALIGN(new_brk
);
760 brk_page
= HOST_PAGE_ALIGN(target_brk
);
763 //#define DEBUGF_BRK(message, args...) do { fprintf(stderr, (message), ## args); } while (0)
764 #define DEBUGF_BRK(message, args...)
766 /* do_brk() must return target values and target errnos. */
767 abi_long
do_brk(abi_ulong new_brk
)
769 abi_long mapped_addr
;
772 DEBUGF_BRK("do_brk(" TARGET_ABI_FMT_lx
") -> ", new_brk
);
775 DEBUGF_BRK(TARGET_ABI_FMT_lx
" (!new_brk)\n", target_brk
);
778 if (new_brk
< target_original_brk
) {
779 DEBUGF_BRK(TARGET_ABI_FMT_lx
" (new_brk < target_original_brk)\n",
784 /* If the new brk is less than the highest page reserved to the
785 * target heap allocation, set it and we're almost done... */
786 if (new_brk
<= brk_page
) {
787 /* Heap contents are initialized to zero, as for anonymous
789 if (new_brk
> target_brk
) {
790 memset(g2h(target_brk
), 0, new_brk
- target_brk
);
792 target_brk
= new_brk
;
793 DEBUGF_BRK(TARGET_ABI_FMT_lx
" (new_brk <= brk_page)\n", target_brk
);
797 /* We need to allocate more memory after the brk... Note that
798 * we don't use MAP_FIXED because that will map over the top of
799 * any existing mapping (like the one with the host libc or qemu
800 * itself); instead we treat "mapped but at wrong address" as
801 * a failure and unmap again.
803 new_alloc_size
= HOST_PAGE_ALIGN(new_brk
- brk_page
);
804 mapped_addr
= get_errno(target_mmap(brk_page
, new_alloc_size
,
805 PROT_READ
|PROT_WRITE
,
806 MAP_ANON
|MAP_PRIVATE
, 0, 0));
808 if (mapped_addr
== brk_page
) {
809 /* Heap contents are initialized to zero, as for anonymous
810 * mapped pages. Technically the new pages are already
811 * initialized to zero since they *are* anonymous mapped
812 * pages, however we have to take care with the contents that
813 * come from the remaining part of the previous page: it may
814 * contains garbage data due to a previous heap usage (grown
816 memset(g2h(target_brk
), 0, brk_page
- target_brk
);
818 target_brk
= new_brk
;
819 brk_page
= HOST_PAGE_ALIGN(target_brk
);
820 DEBUGF_BRK(TARGET_ABI_FMT_lx
" (mapped_addr == brk_page)\n",
823 } else if (mapped_addr
!= -1) {
824 /* Mapped but at wrong address, meaning there wasn't actually
825 * enough space for this brk.
827 target_munmap(mapped_addr
, new_alloc_size
);
829 DEBUGF_BRK(TARGET_ABI_FMT_lx
" (mapped_addr != -1)\n", target_brk
);
832 DEBUGF_BRK(TARGET_ABI_FMT_lx
" (otherwise)\n", target_brk
);
835 #if defined(TARGET_ALPHA)
836 /* We (partially) emulate OSF/1 on Alpha, which requires we
837 return a proper errno, not an unchanged brk value. */
838 return -TARGET_ENOMEM
;
840 /* For everything else, return the previous break. */
844 static inline abi_long
copy_from_user_fdset(fd_set
*fds
,
845 abi_ulong target_fds_addr
,
849 abi_ulong b
, *target_fds
;
851 nw
= (n
+ TARGET_ABI_BITS
- 1) / TARGET_ABI_BITS
;
852 if (!(target_fds
= lock_user(VERIFY_READ
,
854 sizeof(abi_ulong
) * nw
,
856 return -TARGET_EFAULT
;
860 for (i
= 0; i
< nw
; i
++) {
861 /* grab the abi_ulong */
862 __get_user(b
, &target_fds
[i
]);
863 for (j
= 0; j
< TARGET_ABI_BITS
; j
++) {
864 /* check the bit inside the abi_ulong */
871 unlock_user(target_fds
, target_fds_addr
, 0);
876 static inline abi_ulong
copy_from_user_fdset_ptr(fd_set
*fds
, fd_set
**fds_ptr
,
877 abi_ulong target_fds_addr
,
880 if (target_fds_addr
) {
881 if (copy_from_user_fdset(fds
, target_fds_addr
, n
))
882 return -TARGET_EFAULT
;
890 static inline abi_long
copy_to_user_fdset(abi_ulong target_fds_addr
,
896 abi_ulong
*target_fds
;
898 nw
= (n
+ TARGET_ABI_BITS
- 1) / TARGET_ABI_BITS
;
899 if (!(target_fds
= lock_user(VERIFY_WRITE
,
901 sizeof(abi_ulong
) * nw
,
903 return -TARGET_EFAULT
;
906 for (i
= 0; i
< nw
; i
++) {
908 for (j
= 0; j
< TARGET_ABI_BITS
; j
++) {
909 v
|= ((FD_ISSET(k
, fds
) != 0) << j
);
912 __put_user(v
, &target_fds
[i
]);
915 unlock_user(target_fds
, target_fds_addr
, sizeof(abi_ulong
) * nw
);
920 #if defined(__alpha__)
926 static inline abi_long
host_to_target_clock_t(long ticks
)
928 #if HOST_HZ == TARGET_HZ
931 return ((int64_t)ticks
* TARGET_HZ
) / HOST_HZ
;
935 static inline abi_long
host_to_target_rusage(abi_ulong target_addr
,
936 const struct rusage
*rusage
)
938 struct target_rusage
*target_rusage
;
940 if (!lock_user_struct(VERIFY_WRITE
, target_rusage
, target_addr
, 0))
941 return -TARGET_EFAULT
;
942 target_rusage
->ru_utime
.tv_sec
= tswapal(rusage
->ru_utime
.tv_sec
);
943 target_rusage
->ru_utime
.tv_usec
= tswapal(rusage
->ru_utime
.tv_usec
);
944 target_rusage
->ru_stime
.tv_sec
= tswapal(rusage
->ru_stime
.tv_sec
);
945 target_rusage
->ru_stime
.tv_usec
= tswapal(rusage
->ru_stime
.tv_usec
);
946 target_rusage
->ru_maxrss
= tswapal(rusage
->ru_maxrss
);
947 target_rusage
->ru_ixrss
= tswapal(rusage
->ru_ixrss
);
948 target_rusage
->ru_idrss
= tswapal(rusage
->ru_idrss
);
949 target_rusage
->ru_isrss
= tswapal(rusage
->ru_isrss
);
950 target_rusage
->ru_minflt
= tswapal(rusage
->ru_minflt
);
951 target_rusage
->ru_majflt
= tswapal(rusage
->ru_majflt
);
952 target_rusage
->ru_nswap
= tswapal(rusage
->ru_nswap
);
953 target_rusage
->ru_inblock
= tswapal(rusage
->ru_inblock
);
954 target_rusage
->ru_oublock
= tswapal(rusage
->ru_oublock
);
955 target_rusage
->ru_msgsnd
= tswapal(rusage
->ru_msgsnd
);
956 target_rusage
->ru_msgrcv
= tswapal(rusage
->ru_msgrcv
);
957 target_rusage
->ru_nsignals
= tswapal(rusage
->ru_nsignals
);
958 target_rusage
->ru_nvcsw
= tswapal(rusage
->ru_nvcsw
);
959 target_rusage
->ru_nivcsw
= tswapal(rusage
->ru_nivcsw
);
960 unlock_user_struct(target_rusage
, target_addr
, 1);
965 static inline rlim_t
target_to_host_rlim(abi_ulong target_rlim
)
967 abi_ulong target_rlim_swap
;
970 target_rlim_swap
= tswapal(target_rlim
);
971 if (target_rlim_swap
== TARGET_RLIM_INFINITY
)
972 return RLIM_INFINITY
;
974 result
= target_rlim_swap
;
975 if (target_rlim_swap
!= (rlim_t
)result
)
976 return RLIM_INFINITY
;
981 static inline abi_ulong
host_to_target_rlim(rlim_t rlim
)
983 abi_ulong target_rlim_swap
;
986 if (rlim
== RLIM_INFINITY
|| rlim
!= (abi_long
)rlim
)
987 target_rlim_swap
= TARGET_RLIM_INFINITY
;
989 target_rlim_swap
= rlim
;
990 result
= tswapal(target_rlim_swap
);
995 static inline int target_to_host_resource(int code
)
998 case TARGET_RLIMIT_AS
:
1000 case TARGET_RLIMIT_CORE
:
1002 case TARGET_RLIMIT_CPU
:
1004 case TARGET_RLIMIT_DATA
:
1006 case TARGET_RLIMIT_FSIZE
:
1007 return RLIMIT_FSIZE
;
1008 case TARGET_RLIMIT_LOCKS
:
1009 return RLIMIT_LOCKS
;
1010 case TARGET_RLIMIT_MEMLOCK
:
1011 return RLIMIT_MEMLOCK
;
1012 case TARGET_RLIMIT_MSGQUEUE
:
1013 return RLIMIT_MSGQUEUE
;
1014 case TARGET_RLIMIT_NICE
:
1016 case TARGET_RLIMIT_NOFILE
:
1017 return RLIMIT_NOFILE
;
1018 case TARGET_RLIMIT_NPROC
:
1019 return RLIMIT_NPROC
;
1020 case TARGET_RLIMIT_RSS
:
1022 case TARGET_RLIMIT_RTPRIO
:
1023 return RLIMIT_RTPRIO
;
1024 case TARGET_RLIMIT_SIGPENDING
:
1025 return RLIMIT_SIGPENDING
;
1026 case TARGET_RLIMIT_STACK
:
1027 return RLIMIT_STACK
;
1033 static inline abi_long
copy_from_user_timeval(struct timeval
*tv
,
1034 abi_ulong target_tv_addr
)
1036 struct target_timeval
*target_tv
;
1038 if (!lock_user_struct(VERIFY_READ
, target_tv
, target_tv_addr
, 1))
1039 return -TARGET_EFAULT
;
1041 __get_user(tv
->tv_sec
, &target_tv
->tv_sec
);
1042 __get_user(tv
->tv_usec
, &target_tv
->tv_usec
);
1044 unlock_user_struct(target_tv
, target_tv_addr
, 0);
1049 static inline abi_long
copy_to_user_timeval(abi_ulong target_tv_addr
,
1050 const struct timeval
*tv
)
1052 struct target_timeval
*target_tv
;
1054 if (!lock_user_struct(VERIFY_WRITE
, target_tv
, target_tv_addr
, 0))
1055 return -TARGET_EFAULT
;
1057 __put_user(tv
->tv_sec
, &target_tv
->tv_sec
);
1058 __put_user(tv
->tv_usec
, &target_tv
->tv_usec
);
1060 unlock_user_struct(target_tv
, target_tv_addr
, 1);
1065 #if defined(TARGET_NR_mq_open) && defined(__NR_mq_open)
1068 static inline abi_long
copy_from_user_mq_attr(struct mq_attr
*attr
,
1069 abi_ulong target_mq_attr_addr
)
1071 struct target_mq_attr
*target_mq_attr
;
1073 if (!lock_user_struct(VERIFY_READ
, target_mq_attr
,
1074 target_mq_attr_addr
, 1))
1075 return -TARGET_EFAULT
;
1077 __get_user(attr
->mq_flags
, &target_mq_attr
->mq_flags
);
1078 __get_user(attr
->mq_maxmsg
, &target_mq_attr
->mq_maxmsg
);
1079 __get_user(attr
->mq_msgsize
, &target_mq_attr
->mq_msgsize
);
1080 __get_user(attr
->mq_curmsgs
, &target_mq_attr
->mq_curmsgs
);
1082 unlock_user_struct(target_mq_attr
, target_mq_attr_addr
, 0);
1087 static inline abi_long
copy_to_user_mq_attr(abi_ulong target_mq_attr_addr
,
1088 const struct mq_attr
*attr
)
1090 struct target_mq_attr
*target_mq_attr
;
1092 if (!lock_user_struct(VERIFY_WRITE
, target_mq_attr
,
1093 target_mq_attr_addr
, 0))
1094 return -TARGET_EFAULT
;
1096 __put_user(attr
->mq_flags
, &target_mq_attr
->mq_flags
);
1097 __put_user(attr
->mq_maxmsg
, &target_mq_attr
->mq_maxmsg
);
1098 __put_user(attr
->mq_msgsize
, &target_mq_attr
->mq_msgsize
);
1099 __put_user(attr
->mq_curmsgs
, &target_mq_attr
->mq_curmsgs
);
1101 unlock_user_struct(target_mq_attr
, target_mq_attr_addr
, 1);
1107 #if defined(TARGET_NR_select) || defined(TARGET_NR__newselect)
1108 /* do_select() must return target values and target errnos. */
1109 static abi_long
do_select(int n
,
1110 abi_ulong rfd_addr
, abi_ulong wfd_addr
,
1111 abi_ulong efd_addr
, abi_ulong target_tv_addr
)
1113 fd_set rfds
, wfds
, efds
;
1114 fd_set
*rfds_ptr
, *wfds_ptr
, *efds_ptr
;
1115 struct timeval tv
, *tv_ptr
;
1118 ret
= copy_from_user_fdset_ptr(&rfds
, &rfds_ptr
, rfd_addr
, n
);
1122 ret
= copy_from_user_fdset_ptr(&wfds
, &wfds_ptr
, wfd_addr
, n
);
1126 ret
= copy_from_user_fdset_ptr(&efds
, &efds_ptr
, efd_addr
, n
);
1131 if (target_tv_addr
) {
1132 if (copy_from_user_timeval(&tv
, target_tv_addr
))
1133 return -TARGET_EFAULT
;
1139 ret
= get_errno(select(n
, rfds_ptr
, wfds_ptr
, efds_ptr
, tv_ptr
));
1141 if (!is_error(ret
)) {
1142 if (rfd_addr
&& copy_to_user_fdset(rfd_addr
, &rfds
, n
))
1143 return -TARGET_EFAULT
;
1144 if (wfd_addr
&& copy_to_user_fdset(wfd_addr
, &wfds
, n
))
1145 return -TARGET_EFAULT
;
1146 if (efd_addr
&& copy_to_user_fdset(efd_addr
, &efds
, n
))
1147 return -TARGET_EFAULT
;
1149 if (target_tv_addr
&& copy_to_user_timeval(target_tv_addr
, &tv
))
1150 return -TARGET_EFAULT
;
1157 static abi_long
do_pipe2(int host_pipe
[], int flags
)
1160 return pipe2(host_pipe
, flags
);
1166 static abi_long
do_pipe(void *cpu_env
, abi_ulong pipedes
,
1167 int flags
, int is_pipe2
)
1171 ret
= flags
? do_pipe2(host_pipe
, flags
) : pipe(host_pipe
);
1174 return get_errno(ret
);
1176 /* Several targets have special calling conventions for the original
1177 pipe syscall, but didn't replicate this into the pipe2 syscall. */
1179 #if defined(TARGET_ALPHA)
1180 ((CPUAlphaState
*)cpu_env
)->ir
[IR_A4
] = host_pipe
[1];
1181 return host_pipe
[0];
1182 #elif defined(TARGET_MIPS)
1183 ((CPUMIPSState
*)cpu_env
)->active_tc
.gpr
[3] = host_pipe
[1];
1184 return host_pipe
[0];
1185 #elif defined(TARGET_SH4)
1186 ((CPUSH4State
*)cpu_env
)->gregs
[1] = host_pipe
[1];
1187 return host_pipe
[0];
1191 if (put_user_s32(host_pipe
[0], pipedes
)
1192 || put_user_s32(host_pipe
[1], pipedes
+ sizeof(host_pipe
[0])))
1193 return -TARGET_EFAULT
;
1194 return get_errno(ret
);
1197 static inline abi_long
target_to_host_ip_mreq(struct ip_mreqn
*mreqn
,
1198 abi_ulong target_addr
,
1201 struct target_ip_mreqn
*target_smreqn
;
1203 target_smreqn
= lock_user(VERIFY_READ
, target_addr
, len
, 1);
1205 return -TARGET_EFAULT
;
1206 mreqn
->imr_multiaddr
.s_addr
= target_smreqn
->imr_multiaddr
.s_addr
;
1207 mreqn
->imr_address
.s_addr
= target_smreqn
->imr_address
.s_addr
;
1208 if (len
== sizeof(struct target_ip_mreqn
))
1209 mreqn
->imr_ifindex
= tswapal(target_smreqn
->imr_ifindex
);
1210 unlock_user(target_smreqn
, target_addr
, 0);
1215 static inline abi_long
target_to_host_sockaddr(struct sockaddr
*addr
,
1216 abi_ulong target_addr
,
1219 const socklen_t unix_maxlen
= sizeof (struct sockaddr_un
);
1220 sa_family_t sa_family
;
1221 struct target_sockaddr
*target_saddr
;
1223 target_saddr
= lock_user(VERIFY_READ
, target_addr
, len
, 1);
1225 return -TARGET_EFAULT
;
1227 sa_family
= tswap16(target_saddr
->sa_family
);
1229 /* Oops. The caller might send a incomplete sun_path; sun_path
1230 * must be terminated by \0 (see the manual page), but
1231 * unfortunately it is quite common to specify sockaddr_un
1232 * length as "strlen(x->sun_path)" while it should be
1233 * "strlen(...) + 1". We'll fix that here if needed.
1234 * Linux kernel has a similar feature.
1237 if (sa_family
== AF_UNIX
) {
1238 if (len
< unix_maxlen
&& len
> 0) {
1239 char *cp
= (char*)target_saddr
;
1241 if ( cp
[len
-1] && !cp
[len
] )
1244 if (len
> unix_maxlen
)
1248 memcpy(addr
, target_saddr
, len
);
1249 addr
->sa_family
= sa_family
;
1250 unlock_user(target_saddr
, target_addr
, 0);
1255 static inline abi_long
host_to_target_sockaddr(abi_ulong target_addr
,
1256 struct sockaddr
*addr
,
1259 struct target_sockaddr
*target_saddr
;
1261 target_saddr
= lock_user(VERIFY_WRITE
, target_addr
, len
, 0);
1263 return -TARGET_EFAULT
;
1264 memcpy(target_saddr
, addr
, len
);
1265 target_saddr
->sa_family
= tswap16(addr
->sa_family
);
1266 unlock_user(target_saddr
, target_addr
, len
);
1271 static inline abi_long
target_to_host_cmsg(struct msghdr
*msgh
,
1272 struct target_msghdr
*target_msgh
)
1274 struct cmsghdr
*cmsg
= CMSG_FIRSTHDR(msgh
);
1275 abi_long msg_controllen
;
1276 abi_ulong target_cmsg_addr
;
1277 struct target_cmsghdr
*target_cmsg
;
1278 socklen_t space
= 0;
1280 msg_controllen
= tswapal(target_msgh
->msg_controllen
);
1281 if (msg_controllen
< sizeof (struct target_cmsghdr
))
1283 target_cmsg_addr
= tswapal(target_msgh
->msg_control
);
1284 target_cmsg
= lock_user(VERIFY_READ
, target_cmsg_addr
, msg_controllen
, 1);
1286 return -TARGET_EFAULT
;
1288 while (cmsg
&& target_cmsg
) {
1289 void *data
= CMSG_DATA(cmsg
);
1290 void *target_data
= TARGET_CMSG_DATA(target_cmsg
);
1292 int len
= tswapal(target_cmsg
->cmsg_len
)
1293 - TARGET_CMSG_ALIGN(sizeof (struct target_cmsghdr
));
1295 space
+= CMSG_SPACE(len
);
1296 if (space
> msgh
->msg_controllen
) {
1297 space
-= CMSG_SPACE(len
);
1298 gemu_log("Host cmsg overflow\n");
1302 cmsg
->cmsg_level
= tswap32(target_cmsg
->cmsg_level
);
1303 cmsg
->cmsg_type
= tswap32(target_cmsg
->cmsg_type
);
1304 cmsg
->cmsg_len
= CMSG_LEN(len
);
1306 if (cmsg
->cmsg_level
!= TARGET_SOL_SOCKET
|| cmsg
->cmsg_type
!= SCM_RIGHTS
) {
1307 gemu_log("Unsupported ancillary data: %d/%d\n", cmsg
->cmsg_level
, cmsg
->cmsg_type
);
1308 memcpy(data
, target_data
, len
);
1310 int *fd
= (int *)data
;
1311 int *target_fd
= (int *)target_data
;
1312 int i
, numfds
= len
/ sizeof(int);
1314 for (i
= 0; i
< numfds
; i
++)
1315 fd
[i
] = tswap32(target_fd
[i
]);
1318 cmsg
= CMSG_NXTHDR(msgh
, cmsg
);
1319 target_cmsg
= TARGET_CMSG_NXTHDR(target_msgh
, target_cmsg
);
1321 unlock_user(target_cmsg
, target_cmsg_addr
, 0);
1323 msgh
->msg_controllen
= space
;
1327 static inline abi_long
host_to_target_cmsg(struct target_msghdr
*target_msgh
,
1328 struct msghdr
*msgh
)
1330 struct cmsghdr
*cmsg
= CMSG_FIRSTHDR(msgh
);
1331 abi_long msg_controllen
;
1332 abi_ulong target_cmsg_addr
;
1333 struct target_cmsghdr
*target_cmsg
;
1334 socklen_t space
= 0;
1336 msg_controllen
= tswapal(target_msgh
->msg_controllen
);
1337 if (msg_controllen
< sizeof (struct target_cmsghdr
))
1339 target_cmsg_addr
= tswapal(target_msgh
->msg_control
);
1340 target_cmsg
= lock_user(VERIFY_WRITE
, target_cmsg_addr
, msg_controllen
, 0);
1342 return -TARGET_EFAULT
;
1344 while (cmsg
&& target_cmsg
) {
1345 void *data
= CMSG_DATA(cmsg
);
1346 void *target_data
= TARGET_CMSG_DATA(target_cmsg
);
1348 int len
= cmsg
->cmsg_len
- CMSG_ALIGN(sizeof (struct cmsghdr
));
1350 space
+= TARGET_CMSG_SPACE(len
);
1351 if (space
> msg_controllen
) {
1352 space
-= TARGET_CMSG_SPACE(len
);
1353 gemu_log("Target cmsg overflow\n");
1357 target_cmsg
->cmsg_level
= tswap32(cmsg
->cmsg_level
);
1358 target_cmsg
->cmsg_type
= tswap32(cmsg
->cmsg_type
);
1359 target_cmsg
->cmsg_len
= tswapal(TARGET_CMSG_LEN(len
));
1361 if (cmsg
->cmsg_level
!= TARGET_SOL_SOCKET
|| cmsg
->cmsg_type
!= SCM_RIGHTS
) {
1362 gemu_log("Unsupported ancillary data: %d/%d\n", cmsg
->cmsg_level
, cmsg
->cmsg_type
);
1363 memcpy(target_data
, data
, len
);
1365 int *fd
= (int *)data
;
1366 int *target_fd
= (int *)target_data
;
1367 int i
, numfds
= len
/ sizeof(int);
1369 for (i
= 0; i
< numfds
; i
++)
1370 target_fd
[i
] = tswap32(fd
[i
]);
1373 cmsg
= CMSG_NXTHDR(msgh
, cmsg
);
1374 target_cmsg
= TARGET_CMSG_NXTHDR(target_msgh
, target_cmsg
);
1376 unlock_user(target_cmsg
, target_cmsg_addr
, space
);
1378 target_msgh
->msg_controllen
= tswapal(space
);
1382 /* do_setsockopt() Must return target values and target errnos. */
1383 static abi_long
do_setsockopt(int sockfd
, int level
, int optname
,
1384 abi_ulong optval_addr
, socklen_t optlen
)
1388 struct ip_mreqn
*ip_mreq
;
1389 struct ip_mreq_source
*ip_mreq_source
;
1393 /* TCP options all take an 'int' value. */
1394 if (optlen
< sizeof(uint32_t))
1395 return -TARGET_EINVAL
;
1397 if (get_user_u32(val
, optval_addr
))
1398 return -TARGET_EFAULT
;
1399 ret
= get_errno(setsockopt(sockfd
, level
, optname
, &val
, sizeof(val
)));
1406 case IP_ROUTER_ALERT
:
1410 case IP_MTU_DISCOVER
:
1416 case IP_MULTICAST_TTL
:
1417 case IP_MULTICAST_LOOP
:
1419 if (optlen
>= sizeof(uint32_t)) {
1420 if (get_user_u32(val
, optval_addr
))
1421 return -TARGET_EFAULT
;
1422 } else if (optlen
>= 1) {
1423 if (get_user_u8(val
, optval_addr
))
1424 return -TARGET_EFAULT
;
1426 ret
= get_errno(setsockopt(sockfd
, level
, optname
, &val
, sizeof(val
)));
1428 case IP_ADD_MEMBERSHIP
:
1429 case IP_DROP_MEMBERSHIP
:
1430 if (optlen
< sizeof (struct target_ip_mreq
) ||
1431 optlen
> sizeof (struct target_ip_mreqn
))
1432 return -TARGET_EINVAL
;
1434 ip_mreq
= (struct ip_mreqn
*) alloca(optlen
);
1435 target_to_host_ip_mreq(ip_mreq
, optval_addr
, optlen
);
1436 ret
= get_errno(setsockopt(sockfd
, level
, optname
, ip_mreq
, optlen
));
1439 case IP_BLOCK_SOURCE
:
1440 case IP_UNBLOCK_SOURCE
:
1441 case IP_ADD_SOURCE_MEMBERSHIP
:
1442 case IP_DROP_SOURCE_MEMBERSHIP
:
1443 if (optlen
!= sizeof (struct target_ip_mreq_source
))
1444 return -TARGET_EINVAL
;
1446 ip_mreq_source
= lock_user(VERIFY_READ
, optval_addr
, optlen
, 1);
1447 ret
= get_errno(setsockopt(sockfd
, level
, optname
, ip_mreq_source
, optlen
));
1448 unlock_user (ip_mreq_source
, optval_addr
, 0);
1455 case TARGET_SOL_SOCKET
:
1457 /* Options with 'int' argument. */
1458 case TARGET_SO_DEBUG
:
1461 case TARGET_SO_REUSEADDR
:
1462 optname
= SO_REUSEADDR
;
1464 case TARGET_SO_TYPE
:
1467 case TARGET_SO_ERROR
:
1470 case TARGET_SO_DONTROUTE
:
1471 optname
= SO_DONTROUTE
;
1473 case TARGET_SO_BROADCAST
:
1474 optname
= SO_BROADCAST
;
1476 case TARGET_SO_SNDBUF
:
1477 optname
= SO_SNDBUF
;
1479 case TARGET_SO_RCVBUF
:
1480 optname
= SO_RCVBUF
;
1482 case TARGET_SO_KEEPALIVE
:
1483 optname
= SO_KEEPALIVE
;
1485 case TARGET_SO_OOBINLINE
:
1486 optname
= SO_OOBINLINE
;
1488 case TARGET_SO_NO_CHECK
:
1489 optname
= SO_NO_CHECK
;
1491 case TARGET_SO_PRIORITY
:
1492 optname
= SO_PRIORITY
;
1495 case TARGET_SO_BSDCOMPAT
:
1496 optname
= SO_BSDCOMPAT
;
1499 case TARGET_SO_PASSCRED
:
1500 optname
= SO_PASSCRED
;
1502 case TARGET_SO_TIMESTAMP
:
1503 optname
= SO_TIMESTAMP
;
1505 case TARGET_SO_RCVLOWAT
:
1506 optname
= SO_RCVLOWAT
;
1508 case TARGET_SO_RCVTIMEO
:
1509 optname
= SO_RCVTIMEO
;
1511 case TARGET_SO_SNDTIMEO
:
1512 optname
= SO_SNDTIMEO
;
1518 if (optlen
< sizeof(uint32_t))
1519 return -TARGET_EINVAL
;
1521 if (get_user_u32(val
, optval_addr
))
1522 return -TARGET_EFAULT
;
1523 ret
= get_errno(setsockopt(sockfd
, SOL_SOCKET
, optname
, &val
, sizeof(val
)));
1527 gemu_log("Unsupported setsockopt level=%d optname=%d\n", level
, optname
);
1528 ret
= -TARGET_ENOPROTOOPT
;
1533 /* do_getsockopt() Must return target values and target errnos. */
1534 static abi_long
do_getsockopt(int sockfd
, int level
, int optname
,
1535 abi_ulong optval_addr
, abi_ulong optlen
)
1542 case TARGET_SOL_SOCKET
:
1545 /* These don't just return a single integer */
1546 case TARGET_SO_LINGER
:
1547 case TARGET_SO_RCVTIMEO
:
1548 case TARGET_SO_SNDTIMEO
:
1549 case TARGET_SO_PEERNAME
:
1551 case TARGET_SO_PEERCRED
: {
1554 struct target_ucred
*tcr
;
1556 if (get_user_u32(len
, optlen
)) {
1557 return -TARGET_EFAULT
;
1560 return -TARGET_EINVAL
;
1564 ret
= get_errno(getsockopt(sockfd
, level
, SO_PEERCRED
,
1572 if (!lock_user_struct(VERIFY_WRITE
, tcr
, optval_addr
, 0)) {
1573 return -TARGET_EFAULT
;
1575 __put_user(cr
.pid
, &tcr
->pid
);
1576 __put_user(cr
.uid
, &tcr
->uid
);
1577 __put_user(cr
.gid
, &tcr
->gid
);
1578 unlock_user_struct(tcr
, optval_addr
, 1);
1579 if (put_user_u32(len
, optlen
)) {
1580 return -TARGET_EFAULT
;
1584 /* Options with 'int' argument. */
1585 case TARGET_SO_DEBUG
:
1588 case TARGET_SO_REUSEADDR
:
1589 optname
= SO_REUSEADDR
;
1591 case TARGET_SO_TYPE
:
1594 case TARGET_SO_ERROR
:
1597 case TARGET_SO_DONTROUTE
:
1598 optname
= SO_DONTROUTE
;
1600 case TARGET_SO_BROADCAST
:
1601 optname
= SO_BROADCAST
;
1603 case TARGET_SO_SNDBUF
:
1604 optname
= SO_SNDBUF
;
1606 case TARGET_SO_RCVBUF
:
1607 optname
= SO_RCVBUF
;
1609 case TARGET_SO_KEEPALIVE
:
1610 optname
= SO_KEEPALIVE
;
1612 case TARGET_SO_OOBINLINE
:
1613 optname
= SO_OOBINLINE
;
1615 case TARGET_SO_NO_CHECK
:
1616 optname
= SO_NO_CHECK
;
1618 case TARGET_SO_PRIORITY
:
1619 optname
= SO_PRIORITY
;
1622 case TARGET_SO_BSDCOMPAT
:
1623 optname
= SO_BSDCOMPAT
;
1626 case TARGET_SO_PASSCRED
:
1627 optname
= SO_PASSCRED
;
1629 case TARGET_SO_TIMESTAMP
:
1630 optname
= SO_TIMESTAMP
;
1632 case TARGET_SO_RCVLOWAT
:
1633 optname
= SO_RCVLOWAT
;
1640 /* TCP options all take an 'int' value. */
1642 if (get_user_u32(len
, optlen
))
1643 return -TARGET_EFAULT
;
1645 return -TARGET_EINVAL
;
1647 ret
= get_errno(getsockopt(sockfd
, level
, optname
, &val
, &lv
));
1653 if (put_user_u32(val
, optval_addr
))
1654 return -TARGET_EFAULT
;
1656 if (put_user_u8(val
, optval_addr
))
1657 return -TARGET_EFAULT
;
1659 if (put_user_u32(len
, optlen
))
1660 return -TARGET_EFAULT
;
1667 case IP_ROUTER_ALERT
:
1671 case IP_MTU_DISCOVER
:
1677 case IP_MULTICAST_TTL
:
1678 case IP_MULTICAST_LOOP
:
1679 if (get_user_u32(len
, optlen
))
1680 return -TARGET_EFAULT
;
1682 return -TARGET_EINVAL
;
1684 ret
= get_errno(getsockopt(sockfd
, level
, optname
, &val
, &lv
));
1687 if (len
< sizeof(int) && len
> 0 && val
>= 0 && val
< 255) {
1689 if (put_user_u32(len
, optlen
)
1690 || put_user_u8(val
, optval_addr
))
1691 return -TARGET_EFAULT
;
1693 if (len
> sizeof(int))
1695 if (put_user_u32(len
, optlen
)
1696 || put_user_u32(val
, optval_addr
))
1697 return -TARGET_EFAULT
;
1701 ret
= -TARGET_ENOPROTOOPT
;
1707 gemu_log("getsockopt level=%d optname=%d not yet supported\n",
1709 ret
= -TARGET_EOPNOTSUPP
;
1716 * lock_iovec()/unlock_iovec() have a return code of 0 for success where
1717 * other lock functions have a return code of 0 for failure.
1719 static abi_long
lock_iovec(int type
, struct iovec
*vec
, abi_ulong target_addr
,
1720 int count
, int copy
)
1722 struct target_iovec
*target_vec
;
1726 target_vec
= lock_user(VERIFY_READ
, target_addr
, count
* sizeof(struct target_iovec
), 1);
1728 return -TARGET_EFAULT
;
1729 for(i
= 0;i
< count
; i
++) {
1730 base
= tswapal(target_vec
[i
].iov_base
);
1731 vec
[i
].iov_len
= tswapal(target_vec
[i
].iov_len
);
1732 if (vec
[i
].iov_len
!= 0) {
1733 vec
[i
].iov_base
= lock_user(type
, base
, vec
[i
].iov_len
, copy
);
1734 /* Don't check lock_user return value. We must call writev even
1735 if a element has invalid base address. */
1737 /* zero length pointer is ignored */
1738 vec
[i
].iov_base
= NULL
;
1741 unlock_user (target_vec
, target_addr
, 0);
1745 static abi_long
unlock_iovec(struct iovec
*vec
, abi_ulong target_addr
,
1746 int count
, int copy
)
1748 struct target_iovec
*target_vec
;
1752 target_vec
= lock_user(VERIFY_READ
, target_addr
, count
* sizeof(struct target_iovec
), 1);
1754 return -TARGET_EFAULT
;
1755 for(i
= 0;i
< count
; i
++) {
1756 if (target_vec
[i
].iov_base
) {
1757 base
= tswapal(target_vec
[i
].iov_base
);
1758 unlock_user(vec
[i
].iov_base
, base
, copy
? vec
[i
].iov_len
: 0);
1761 unlock_user (target_vec
, target_addr
, 0);
1766 /* do_socket() Must return target values and target errnos. */
1767 static abi_long
do_socket(int domain
, int type
, int protocol
)
1769 #if defined(TARGET_MIPS)
1771 case TARGET_SOCK_DGRAM
:
1774 case TARGET_SOCK_STREAM
:
1777 case TARGET_SOCK_RAW
:
1780 case TARGET_SOCK_RDM
:
1783 case TARGET_SOCK_SEQPACKET
:
1784 type
= SOCK_SEQPACKET
;
1786 case TARGET_SOCK_PACKET
:
1791 if (domain
== PF_NETLINK
)
1792 return -EAFNOSUPPORT
; /* do not NETLINK socket connections possible */
1793 return get_errno(socket(domain
, type
, protocol
));
1796 /* do_bind() Must return target values and target errnos. */
1797 static abi_long
do_bind(int sockfd
, abi_ulong target_addr
,
1803 if ((int)addrlen
< 0) {
1804 return -TARGET_EINVAL
;
1807 addr
= alloca(addrlen
+1);
1809 ret
= target_to_host_sockaddr(addr
, target_addr
, addrlen
);
1813 return get_errno(bind(sockfd
, addr
, addrlen
));
1816 /* do_connect() Must return target values and target errnos. */
1817 static abi_long
do_connect(int sockfd
, abi_ulong target_addr
,
1823 if ((int)addrlen
< 0) {
1824 return -TARGET_EINVAL
;
1827 addr
= alloca(addrlen
);
1829 ret
= target_to_host_sockaddr(addr
, target_addr
, addrlen
);
1833 return get_errno(connect(sockfd
, addr
, addrlen
));
1836 /* do_sendrecvmsg() Must return target values and target errnos. */
1837 static abi_long
do_sendrecvmsg(int fd
, abi_ulong target_msg
,
1838 int flags
, int send
)
1841 struct target_msghdr
*msgp
;
1845 abi_ulong target_vec
;
1848 if (!lock_user_struct(send
? VERIFY_READ
: VERIFY_WRITE
,
1852 return -TARGET_EFAULT
;
1853 if (msgp
->msg_name
) {
1854 msg
.msg_namelen
= tswap32(msgp
->msg_namelen
);
1855 msg
.msg_name
= alloca(msg
.msg_namelen
);
1856 ret
= target_to_host_sockaddr(msg
.msg_name
, tswapal(msgp
->msg_name
),
1859 unlock_user_struct(msgp
, target_msg
, send
? 0 : 1);
1863 msg
.msg_name
= NULL
;
1864 msg
.msg_namelen
= 0;
1866 msg
.msg_controllen
= 2 * tswapal(msgp
->msg_controllen
);
1867 msg
.msg_control
= alloca(msg
.msg_controllen
);
1868 msg
.msg_flags
= tswap32(msgp
->msg_flags
);
1870 count
= tswapal(msgp
->msg_iovlen
);
1871 vec
= alloca(count
* sizeof(struct iovec
));
1872 target_vec
= tswapal(msgp
->msg_iov
);
1873 lock_iovec(send
? VERIFY_READ
: VERIFY_WRITE
, vec
, target_vec
, count
, send
);
1874 msg
.msg_iovlen
= count
;
1878 ret
= target_to_host_cmsg(&msg
, msgp
);
1880 ret
= get_errno(sendmsg(fd
, &msg
, flags
));
1882 ret
= get_errno(recvmsg(fd
, &msg
, flags
));
1883 if (!is_error(ret
)) {
1885 ret
= host_to_target_cmsg(msgp
, &msg
);
1886 if (!is_error(ret
)) {
1887 msgp
->msg_namelen
= tswap32(msg
.msg_namelen
);
1888 if (msg
.msg_name
!= NULL
) {
1889 ret
= host_to_target_sockaddr(tswapal(msgp
->msg_name
),
1890 msg
.msg_name
, msg
.msg_namelen
);
1902 unlock_iovec(vec
, target_vec
, count
, !send
);
1903 unlock_user_struct(msgp
, target_msg
, send
? 0 : 1);
1907 /* do_accept() Must return target values and target errnos. */
1908 static abi_long
do_accept(int fd
, abi_ulong target_addr
,
1909 abi_ulong target_addrlen_addr
)
1915 if (target_addr
== 0)
1916 return get_errno(accept(fd
, NULL
, NULL
));
1918 /* linux returns EINVAL if addrlen pointer is invalid */
1919 if (get_user_u32(addrlen
, target_addrlen_addr
))
1920 return -TARGET_EINVAL
;
1922 if ((int)addrlen
< 0) {
1923 return -TARGET_EINVAL
;
1926 if (!access_ok(VERIFY_WRITE
, target_addr
, addrlen
))
1927 return -TARGET_EINVAL
;
1929 addr
= alloca(addrlen
);
1931 ret
= get_errno(accept(fd
, addr
, &addrlen
));
1932 if (!is_error(ret
)) {
1933 host_to_target_sockaddr(target_addr
, addr
, addrlen
);
1934 if (put_user_u32(addrlen
, target_addrlen_addr
))
1935 ret
= -TARGET_EFAULT
;
1940 /* do_getpeername() Must return target values and target errnos. */
1941 static abi_long
do_getpeername(int fd
, abi_ulong target_addr
,
1942 abi_ulong target_addrlen_addr
)
1948 if (get_user_u32(addrlen
, target_addrlen_addr
))
1949 return -TARGET_EFAULT
;
1951 if ((int)addrlen
< 0) {
1952 return -TARGET_EINVAL
;
1955 if (!access_ok(VERIFY_WRITE
, target_addr
, addrlen
))
1956 return -TARGET_EFAULT
;
1958 addr
= alloca(addrlen
);
1960 ret
= get_errno(getpeername(fd
, addr
, &addrlen
));
1961 if (!is_error(ret
)) {
1962 host_to_target_sockaddr(target_addr
, addr
, addrlen
);
1963 if (put_user_u32(addrlen
, target_addrlen_addr
))
1964 ret
= -TARGET_EFAULT
;
1969 /* do_getsockname() Must return target values and target errnos. */
1970 static abi_long
do_getsockname(int fd
, abi_ulong target_addr
,
1971 abi_ulong target_addrlen_addr
)
1977 if (get_user_u32(addrlen
, target_addrlen_addr
))
1978 return -TARGET_EFAULT
;
1980 if ((int)addrlen
< 0) {
1981 return -TARGET_EINVAL
;
1984 if (!access_ok(VERIFY_WRITE
, target_addr
, addrlen
))
1985 return -TARGET_EFAULT
;
1987 addr
= alloca(addrlen
);
1989 ret
= get_errno(getsockname(fd
, addr
, &addrlen
));
1990 if (!is_error(ret
)) {
1991 host_to_target_sockaddr(target_addr
, addr
, addrlen
);
1992 if (put_user_u32(addrlen
, target_addrlen_addr
))
1993 ret
= -TARGET_EFAULT
;
1998 /* do_socketpair() Must return target values and target errnos. */
1999 static abi_long
do_socketpair(int domain
, int type
, int protocol
,
2000 abi_ulong target_tab_addr
)
2005 ret
= get_errno(socketpair(domain
, type
, protocol
, tab
));
2006 if (!is_error(ret
)) {
2007 if (put_user_s32(tab
[0], target_tab_addr
)
2008 || put_user_s32(tab
[1], target_tab_addr
+ sizeof(tab
[0])))
2009 ret
= -TARGET_EFAULT
;
2014 /* do_sendto() Must return target values and target errnos. */
2015 static abi_long
do_sendto(int fd
, abi_ulong msg
, size_t len
, int flags
,
2016 abi_ulong target_addr
, socklen_t addrlen
)
2022 if ((int)addrlen
< 0) {
2023 return -TARGET_EINVAL
;
2026 host_msg
= lock_user(VERIFY_READ
, msg
, len
, 1);
2028 return -TARGET_EFAULT
;
2030 addr
= alloca(addrlen
);
2031 ret
= target_to_host_sockaddr(addr
, target_addr
, addrlen
);
2033 unlock_user(host_msg
, msg
, 0);
2036 ret
= get_errno(sendto(fd
, host_msg
, len
, flags
, addr
, addrlen
));
2038 ret
= get_errno(send(fd
, host_msg
, len
, flags
));
2040 unlock_user(host_msg
, msg
, 0);
2044 /* do_recvfrom() Must return target values and target errnos. */
2045 static abi_long
do_recvfrom(int fd
, abi_ulong msg
, size_t len
, int flags
,
2046 abi_ulong target_addr
,
2047 abi_ulong target_addrlen
)
2054 host_msg
= lock_user(VERIFY_WRITE
, msg
, len
, 0);
2056 return -TARGET_EFAULT
;
2058 if (get_user_u32(addrlen
, target_addrlen
)) {
2059 ret
= -TARGET_EFAULT
;
2062 if ((int)addrlen
< 0) {
2063 ret
= -TARGET_EINVAL
;
2066 addr
= alloca(addrlen
);
2067 ret
= get_errno(recvfrom(fd
, host_msg
, len
, flags
, addr
, &addrlen
));
2069 addr
= NULL
; /* To keep compiler quiet. */
2070 ret
= get_errno(qemu_recv(fd
, host_msg
, len
, flags
));
2072 if (!is_error(ret
)) {
2074 host_to_target_sockaddr(target_addr
, addr
, addrlen
);
2075 if (put_user_u32(addrlen
, target_addrlen
)) {
2076 ret
= -TARGET_EFAULT
;
2080 unlock_user(host_msg
, msg
, len
);
2083 unlock_user(host_msg
, msg
, 0);
2088 #ifdef TARGET_NR_socketcall
2089 /* do_socketcall() Must return target values and target errnos. */
2090 static abi_long
do_socketcall(int num
, abi_ulong vptr
)
2093 const int n
= sizeof(abi_ulong
);
2098 abi_ulong domain
, type
, protocol
;
2100 if (get_user_ual(domain
, vptr
)
2101 || get_user_ual(type
, vptr
+ n
)
2102 || get_user_ual(protocol
, vptr
+ 2 * n
))
2103 return -TARGET_EFAULT
;
2105 ret
= do_socket(domain
, type
, protocol
);
2111 abi_ulong target_addr
;
2114 if (get_user_ual(sockfd
, vptr
)
2115 || get_user_ual(target_addr
, vptr
+ n
)
2116 || get_user_ual(addrlen
, vptr
+ 2 * n
))
2117 return -TARGET_EFAULT
;
2119 ret
= do_bind(sockfd
, target_addr
, addrlen
);
2122 case SOCKOP_connect
:
2125 abi_ulong target_addr
;
2128 if (get_user_ual(sockfd
, vptr
)
2129 || get_user_ual(target_addr
, vptr
+ n
)
2130 || get_user_ual(addrlen
, vptr
+ 2 * n
))
2131 return -TARGET_EFAULT
;
2133 ret
= do_connect(sockfd
, target_addr
, addrlen
);
2138 abi_ulong sockfd
, backlog
;
2140 if (get_user_ual(sockfd
, vptr
)
2141 || get_user_ual(backlog
, vptr
+ n
))
2142 return -TARGET_EFAULT
;
2144 ret
= get_errno(listen(sockfd
, backlog
));
2150 abi_ulong target_addr
, target_addrlen
;
2152 if (get_user_ual(sockfd
, vptr
)
2153 || get_user_ual(target_addr
, vptr
+ n
)
2154 || get_user_ual(target_addrlen
, vptr
+ 2 * n
))
2155 return -TARGET_EFAULT
;
2157 ret
= do_accept(sockfd
, target_addr
, target_addrlen
);
2160 case SOCKOP_getsockname
:
2163 abi_ulong target_addr
, target_addrlen
;
2165 if (get_user_ual(sockfd
, vptr
)
2166 || get_user_ual(target_addr
, vptr
+ n
)
2167 || get_user_ual(target_addrlen
, vptr
+ 2 * n
))
2168 return -TARGET_EFAULT
;
2170 ret
= do_getsockname(sockfd
, target_addr
, target_addrlen
);
2173 case SOCKOP_getpeername
:
2176 abi_ulong target_addr
, target_addrlen
;
2178 if (get_user_ual(sockfd
, vptr
)
2179 || get_user_ual(target_addr
, vptr
+ n
)
2180 || get_user_ual(target_addrlen
, vptr
+ 2 * n
))
2181 return -TARGET_EFAULT
;
2183 ret
= do_getpeername(sockfd
, target_addr
, target_addrlen
);
2186 case SOCKOP_socketpair
:
2188 abi_ulong domain
, type
, protocol
;
2191 if (get_user_ual(domain
, vptr
)
2192 || get_user_ual(type
, vptr
+ n
)
2193 || get_user_ual(protocol
, vptr
+ 2 * n
)
2194 || get_user_ual(tab
, vptr
+ 3 * n
))
2195 return -TARGET_EFAULT
;
2197 ret
= do_socketpair(domain
, type
, protocol
, tab
);
2207 if (get_user_ual(sockfd
, vptr
)
2208 || get_user_ual(msg
, vptr
+ n
)
2209 || get_user_ual(len
, vptr
+ 2 * n
)
2210 || get_user_ual(flags
, vptr
+ 3 * n
))
2211 return -TARGET_EFAULT
;
2213 ret
= do_sendto(sockfd
, msg
, len
, flags
, 0, 0);
2223 if (get_user_ual(sockfd
, vptr
)
2224 || get_user_ual(msg
, vptr
+ n
)
2225 || get_user_ual(len
, vptr
+ 2 * n
)
2226 || get_user_ual(flags
, vptr
+ 3 * n
))
2227 return -TARGET_EFAULT
;
2229 ret
= do_recvfrom(sockfd
, msg
, len
, flags
, 0, 0);
2241 if (get_user_ual(sockfd
, vptr
)
2242 || get_user_ual(msg
, vptr
+ n
)
2243 || get_user_ual(len
, vptr
+ 2 * n
)
2244 || get_user_ual(flags
, vptr
+ 3 * n
)
2245 || get_user_ual(addr
, vptr
+ 4 * n
)
2246 || get_user_ual(addrlen
, vptr
+ 5 * n
))
2247 return -TARGET_EFAULT
;
2249 ret
= do_sendto(sockfd
, msg
, len
, flags
, addr
, addrlen
);
2252 case SOCKOP_recvfrom
:
2261 if (get_user_ual(sockfd
, vptr
)
2262 || get_user_ual(msg
, vptr
+ n
)
2263 || get_user_ual(len
, vptr
+ 2 * n
)
2264 || get_user_ual(flags
, vptr
+ 3 * n
)
2265 || get_user_ual(addr
, vptr
+ 4 * n
)
2266 || get_user_ual(addrlen
, vptr
+ 5 * n
))
2267 return -TARGET_EFAULT
;
2269 ret
= do_recvfrom(sockfd
, msg
, len
, flags
, addr
, addrlen
);
2272 case SOCKOP_shutdown
:
2274 abi_ulong sockfd
, how
;
2276 if (get_user_ual(sockfd
, vptr
)
2277 || get_user_ual(how
, vptr
+ n
))
2278 return -TARGET_EFAULT
;
2280 ret
= get_errno(shutdown(sockfd
, how
));
2283 case SOCKOP_sendmsg
:
2284 case SOCKOP_recvmsg
:
2287 abi_ulong target_msg
;
2290 if (get_user_ual(fd
, vptr
)
2291 || get_user_ual(target_msg
, vptr
+ n
)
2292 || get_user_ual(flags
, vptr
+ 2 * n
))
2293 return -TARGET_EFAULT
;
2295 ret
= do_sendrecvmsg(fd
, target_msg
, flags
,
2296 (num
== SOCKOP_sendmsg
));
2299 case SOCKOP_setsockopt
:
2307 if (get_user_ual(sockfd
, vptr
)
2308 || get_user_ual(level
, vptr
+ n
)
2309 || get_user_ual(optname
, vptr
+ 2 * n
)
2310 || get_user_ual(optval
, vptr
+ 3 * n
)
2311 || get_user_ual(optlen
, vptr
+ 4 * n
))
2312 return -TARGET_EFAULT
;
2314 ret
= do_setsockopt(sockfd
, level
, optname
, optval
, optlen
);
2317 case SOCKOP_getsockopt
:
2325 if (get_user_ual(sockfd
, vptr
)
2326 || get_user_ual(level
, vptr
+ n
)
2327 || get_user_ual(optname
, vptr
+ 2 * n
)
2328 || get_user_ual(optval
, vptr
+ 3 * n
)
2329 || get_user_ual(optlen
, vptr
+ 4 * n
))
2330 return -TARGET_EFAULT
;
2332 ret
= do_getsockopt(sockfd
, level
, optname
, optval
, optlen
);
2336 gemu_log("Unsupported socketcall: %d\n", num
);
2337 ret
= -TARGET_ENOSYS
;
2344 #define N_SHM_REGIONS 32
2346 static struct shm_region
{
2349 } shm_regions
[N_SHM_REGIONS
];
2351 struct target_ipc_perm
2358 unsigned short int mode
;
2359 unsigned short int __pad1
;
2360 unsigned short int __seq
;
2361 unsigned short int __pad2
;
2362 abi_ulong __unused1
;
2363 abi_ulong __unused2
;
2366 struct target_semid_ds
2368 struct target_ipc_perm sem_perm
;
2369 abi_ulong sem_otime
;
2370 abi_ulong __unused1
;
2371 abi_ulong sem_ctime
;
2372 abi_ulong __unused2
;
2373 abi_ulong sem_nsems
;
2374 abi_ulong __unused3
;
2375 abi_ulong __unused4
;
2378 static inline abi_long
target_to_host_ipc_perm(struct ipc_perm
*host_ip
,
2379 abi_ulong target_addr
)
2381 struct target_ipc_perm
*target_ip
;
2382 struct target_semid_ds
*target_sd
;
2384 if (!lock_user_struct(VERIFY_READ
, target_sd
, target_addr
, 1))
2385 return -TARGET_EFAULT
;
2386 target_ip
= &(target_sd
->sem_perm
);
2387 host_ip
->__key
= tswapal(target_ip
->__key
);
2388 host_ip
->uid
= tswapal(target_ip
->uid
);
2389 host_ip
->gid
= tswapal(target_ip
->gid
);
2390 host_ip
->cuid
= tswapal(target_ip
->cuid
);
2391 host_ip
->cgid
= tswapal(target_ip
->cgid
);
2392 host_ip
->mode
= tswap16(target_ip
->mode
);
2393 unlock_user_struct(target_sd
, target_addr
, 0);
2397 static inline abi_long
host_to_target_ipc_perm(abi_ulong target_addr
,
2398 struct ipc_perm
*host_ip
)
2400 struct target_ipc_perm
*target_ip
;
2401 struct target_semid_ds
*target_sd
;
2403 if (!lock_user_struct(VERIFY_WRITE
, target_sd
, target_addr
, 0))
2404 return -TARGET_EFAULT
;
2405 target_ip
= &(target_sd
->sem_perm
);
2406 target_ip
->__key
= tswapal(host_ip
->__key
);
2407 target_ip
->uid
= tswapal(host_ip
->uid
);
2408 target_ip
->gid
= tswapal(host_ip
->gid
);
2409 target_ip
->cuid
= tswapal(host_ip
->cuid
);
2410 target_ip
->cgid
= tswapal(host_ip
->cgid
);
2411 target_ip
->mode
= tswap16(host_ip
->mode
);
2412 unlock_user_struct(target_sd
, target_addr
, 1);
2416 static inline abi_long
target_to_host_semid_ds(struct semid_ds
*host_sd
,
2417 abi_ulong target_addr
)
2419 struct target_semid_ds
*target_sd
;
2421 if (!lock_user_struct(VERIFY_READ
, target_sd
, target_addr
, 1))
2422 return -TARGET_EFAULT
;
2423 if (target_to_host_ipc_perm(&(host_sd
->sem_perm
),target_addr
))
2424 return -TARGET_EFAULT
;
2425 host_sd
->sem_nsems
= tswapal(target_sd
->sem_nsems
);
2426 host_sd
->sem_otime
= tswapal(target_sd
->sem_otime
);
2427 host_sd
->sem_ctime
= tswapal(target_sd
->sem_ctime
);
2428 unlock_user_struct(target_sd
, target_addr
, 0);
2432 static inline abi_long
host_to_target_semid_ds(abi_ulong target_addr
,
2433 struct semid_ds
*host_sd
)
2435 struct target_semid_ds
*target_sd
;
2437 if (!lock_user_struct(VERIFY_WRITE
, target_sd
, target_addr
, 0))
2438 return -TARGET_EFAULT
;
2439 if (host_to_target_ipc_perm(target_addr
,&(host_sd
->sem_perm
)))
2440 return -TARGET_EFAULT
;
2441 target_sd
->sem_nsems
= tswapal(host_sd
->sem_nsems
);
2442 target_sd
->sem_otime
= tswapal(host_sd
->sem_otime
);
2443 target_sd
->sem_ctime
= tswapal(host_sd
->sem_ctime
);
2444 unlock_user_struct(target_sd
, target_addr
, 1);
2448 struct target_seminfo
{
2461 static inline abi_long
host_to_target_seminfo(abi_ulong target_addr
,
2462 struct seminfo
*host_seminfo
)
2464 struct target_seminfo
*target_seminfo
;
2465 if (!lock_user_struct(VERIFY_WRITE
, target_seminfo
, target_addr
, 0))
2466 return -TARGET_EFAULT
;
2467 __put_user(host_seminfo
->semmap
, &target_seminfo
->semmap
);
2468 __put_user(host_seminfo
->semmni
, &target_seminfo
->semmni
);
2469 __put_user(host_seminfo
->semmns
, &target_seminfo
->semmns
);
2470 __put_user(host_seminfo
->semmnu
, &target_seminfo
->semmnu
);
2471 __put_user(host_seminfo
->semmsl
, &target_seminfo
->semmsl
);
2472 __put_user(host_seminfo
->semopm
, &target_seminfo
->semopm
);
2473 __put_user(host_seminfo
->semume
, &target_seminfo
->semume
);
2474 __put_user(host_seminfo
->semusz
, &target_seminfo
->semusz
);
2475 __put_user(host_seminfo
->semvmx
, &target_seminfo
->semvmx
);
2476 __put_user(host_seminfo
->semaem
, &target_seminfo
->semaem
);
2477 unlock_user_struct(target_seminfo
, target_addr
, 1);
2483 struct semid_ds
*buf
;
2484 unsigned short *array
;
2485 struct seminfo
*__buf
;
2488 union target_semun
{
2495 static inline abi_long
target_to_host_semarray(int semid
, unsigned short **host_array
,
2496 abi_ulong target_addr
)
2499 unsigned short *array
;
2501 struct semid_ds semid_ds
;
2504 semun
.buf
= &semid_ds
;
2506 ret
= semctl(semid
, 0, IPC_STAT
, semun
);
2508 return get_errno(ret
);
2510 nsems
= semid_ds
.sem_nsems
;
2512 *host_array
= malloc(nsems
*sizeof(unsigned short));
2513 array
= lock_user(VERIFY_READ
, target_addr
,
2514 nsems
*sizeof(unsigned short), 1);
2516 return -TARGET_EFAULT
;
2518 for(i
=0; i
<nsems
; i
++) {
2519 __get_user((*host_array
)[i
], &array
[i
]);
2521 unlock_user(array
, target_addr
, 0);
2526 static inline abi_long
host_to_target_semarray(int semid
, abi_ulong target_addr
,
2527 unsigned short **host_array
)
2530 unsigned short *array
;
2532 struct semid_ds semid_ds
;
2535 semun
.buf
= &semid_ds
;
2537 ret
= semctl(semid
, 0, IPC_STAT
, semun
);
2539 return get_errno(ret
);
2541 nsems
= semid_ds
.sem_nsems
;
2543 array
= lock_user(VERIFY_WRITE
, target_addr
,
2544 nsems
*sizeof(unsigned short), 0);
2546 return -TARGET_EFAULT
;
2548 for(i
=0; i
<nsems
; i
++) {
2549 __put_user((*host_array
)[i
], &array
[i
]);
2552 unlock_user(array
, target_addr
, 1);
2557 static inline abi_long
do_semctl(int semid
, int semnum
, int cmd
,
2558 union target_semun target_su
)
2561 struct semid_ds dsarg
;
2562 unsigned short *array
= NULL
;
2563 struct seminfo seminfo
;
2564 abi_long ret
= -TARGET_EINVAL
;
2571 arg
.val
= tswap32(target_su
.val
);
2572 ret
= get_errno(semctl(semid
, semnum
, cmd
, arg
));
2573 target_su
.val
= tswap32(arg
.val
);
2577 err
= target_to_host_semarray(semid
, &array
, target_su
.array
);
2581 ret
= get_errno(semctl(semid
, semnum
, cmd
, arg
));
2582 err
= host_to_target_semarray(semid
, target_su
.array
, &array
);
2589 err
= target_to_host_semid_ds(&dsarg
, target_su
.buf
);
2593 ret
= get_errno(semctl(semid
, semnum
, cmd
, arg
));
2594 err
= host_to_target_semid_ds(target_su
.buf
, &dsarg
);
2600 arg
.__buf
= &seminfo
;
2601 ret
= get_errno(semctl(semid
, semnum
, cmd
, arg
));
2602 err
= host_to_target_seminfo(target_su
.__buf
, &seminfo
);
2610 ret
= get_errno(semctl(semid
, semnum
, cmd
, NULL
));
2617 struct target_sembuf
{
2618 unsigned short sem_num
;
2623 static inline abi_long
target_to_host_sembuf(struct sembuf
*host_sembuf
,
2624 abi_ulong target_addr
,
2627 struct target_sembuf
*target_sembuf
;
2630 target_sembuf
= lock_user(VERIFY_READ
, target_addr
,
2631 nsops
*sizeof(struct target_sembuf
), 1);
2633 return -TARGET_EFAULT
;
2635 for(i
=0; i
<nsops
; i
++) {
2636 __get_user(host_sembuf
[i
].sem_num
, &target_sembuf
[i
].sem_num
);
2637 __get_user(host_sembuf
[i
].sem_op
, &target_sembuf
[i
].sem_op
);
2638 __get_user(host_sembuf
[i
].sem_flg
, &target_sembuf
[i
].sem_flg
);
2641 unlock_user(target_sembuf
, target_addr
, 0);
2646 static inline abi_long
do_semop(int semid
, abi_long ptr
, unsigned nsops
)
2648 struct sembuf sops
[nsops
];
2650 if (target_to_host_sembuf(sops
, ptr
, nsops
))
2651 return -TARGET_EFAULT
;
2653 return semop(semid
, sops
, nsops
);
2656 struct target_msqid_ds
2658 struct target_ipc_perm msg_perm
;
2659 abi_ulong msg_stime
;
2660 #if TARGET_ABI_BITS == 32
2661 abi_ulong __unused1
;
2663 abi_ulong msg_rtime
;
2664 #if TARGET_ABI_BITS == 32
2665 abi_ulong __unused2
;
2667 abi_ulong msg_ctime
;
2668 #if TARGET_ABI_BITS == 32
2669 abi_ulong __unused3
;
2671 abi_ulong __msg_cbytes
;
2673 abi_ulong msg_qbytes
;
2674 abi_ulong msg_lspid
;
2675 abi_ulong msg_lrpid
;
2676 abi_ulong __unused4
;
2677 abi_ulong __unused5
;
2680 static inline abi_long
target_to_host_msqid_ds(struct msqid_ds
*host_md
,
2681 abi_ulong target_addr
)
2683 struct target_msqid_ds
*target_md
;
2685 if (!lock_user_struct(VERIFY_READ
, target_md
, target_addr
, 1))
2686 return -TARGET_EFAULT
;
2687 if (target_to_host_ipc_perm(&(host_md
->msg_perm
),target_addr
))
2688 return -TARGET_EFAULT
;
2689 host_md
->msg_stime
= tswapal(target_md
->msg_stime
);
2690 host_md
->msg_rtime
= tswapal(target_md
->msg_rtime
);
2691 host_md
->msg_ctime
= tswapal(target_md
->msg_ctime
);
2692 host_md
->__msg_cbytes
= tswapal(target_md
->__msg_cbytes
);
2693 host_md
->msg_qnum
= tswapal(target_md
->msg_qnum
);
2694 host_md
->msg_qbytes
= tswapal(target_md
->msg_qbytes
);
2695 host_md
->msg_lspid
= tswapal(target_md
->msg_lspid
);
2696 host_md
->msg_lrpid
= tswapal(target_md
->msg_lrpid
);
2697 unlock_user_struct(target_md
, target_addr
, 0);
2701 static inline abi_long
host_to_target_msqid_ds(abi_ulong target_addr
,
2702 struct msqid_ds
*host_md
)
2704 struct target_msqid_ds
*target_md
;
2706 if (!lock_user_struct(VERIFY_WRITE
, target_md
, target_addr
, 0))
2707 return -TARGET_EFAULT
;
2708 if (host_to_target_ipc_perm(target_addr
,&(host_md
->msg_perm
)))
2709 return -TARGET_EFAULT
;
2710 target_md
->msg_stime
= tswapal(host_md
->msg_stime
);
2711 target_md
->msg_rtime
= tswapal(host_md
->msg_rtime
);
2712 target_md
->msg_ctime
= tswapal(host_md
->msg_ctime
);
2713 target_md
->__msg_cbytes
= tswapal(host_md
->__msg_cbytes
);
2714 target_md
->msg_qnum
= tswapal(host_md
->msg_qnum
);
2715 target_md
->msg_qbytes
= tswapal(host_md
->msg_qbytes
);
2716 target_md
->msg_lspid
= tswapal(host_md
->msg_lspid
);
2717 target_md
->msg_lrpid
= tswapal(host_md
->msg_lrpid
);
2718 unlock_user_struct(target_md
, target_addr
, 1);
2722 struct target_msginfo
{
2730 unsigned short int msgseg
;
2733 static inline abi_long
host_to_target_msginfo(abi_ulong target_addr
,
2734 struct msginfo
*host_msginfo
)
2736 struct target_msginfo
*target_msginfo
;
2737 if (!lock_user_struct(VERIFY_WRITE
, target_msginfo
, target_addr
, 0))
2738 return -TARGET_EFAULT
;
2739 __put_user(host_msginfo
->msgpool
, &target_msginfo
->msgpool
);
2740 __put_user(host_msginfo
->msgmap
, &target_msginfo
->msgmap
);
2741 __put_user(host_msginfo
->msgmax
, &target_msginfo
->msgmax
);
2742 __put_user(host_msginfo
->msgmnb
, &target_msginfo
->msgmnb
);
2743 __put_user(host_msginfo
->msgmni
, &target_msginfo
->msgmni
);
2744 __put_user(host_msginfo
->msgssz
, &target_msginfo
->msgssz
);
2745 __put_user(host_msginfo
->msgtql
, &target_msginfo
->msgtql
);
2746 __put_user(host_msginfo
->msgseg
, &target_msginfo
->msgseg
);
2747 unlock_user_struct(target_msginfo
, target_addr
, 1);
2751 static inline abi_long
do_msgctl(int msgid
, int cmd
, abi_long ptr
)
2753 struct msqid_ds dsarg
;
2754 struct msginfo msginfo
;
2755 abi_long ret
= -TARGET_EINVAL
;
2763 if (target_to_host_msqid_ds(&dsarg
,ptr
))
2764 return -TARGET_EFAULT
;
2765 ret
= get_errno(msgctl(msgid
, cmd
, &dsarg
));
2766 if (host_to_target_msqid_ds(ptr
,&dsarg
))
2767 return -TARGET_EFAULT
;
2770 ret
= get_errno(msgctl(msgid
, cmd
, NULL
));
2774 ret
= get_errno(msgctl(msgid
, cmd
, (struct msqid_ds
*)&msginfo
));
2775 if (host_to_target_msginfo(ptr
, &msginfo
))
2776 return -TARGET_EFAULT
;
2783 struct target_msgbuf
{
2788 static inline abi_long
do_msgsnd(int msqid
, abi_long msgp
,
2789 unsigned int msgsz
, int msgflg
)
2791 struct target_msgbuf
*target_mb
;
2792 struct msgbuf
*host_mb
;
2795 if (!lock_user_struct(VERIFY_READ
, target_mb
, msgp
, 0))
2796 return -TARGET_EFAULT
;
2797 host_mb
= malloc(msgsz
+sizeof(long));
2798 host_mb
->mtype
= (abi_long
) tswapal(target_mb
->mtype
);
2799 memcpy(host_mb
->mtext
, target_mb
->mtext
, msgsz
);
2800 ret
= get_errno(msgsnd(msqid
, host_mb
, msgsz
, msgflg
));
2802 unlock_user_struct(target_mb
, msgp
, 0);
2807 static inline abi_long
do_msgrcv(int msqid
, abi_long msgp
,
2808 unsigned int msgsz
, abi_long msgtyp
,
2811 struct target_msgbuf
*target_mb
;
2813 struct msgbuf
*host_mb
;
2816 if (!lock_user_struct(VERIFY_WRITE
, target_mb
, msgp
, 0))
2817 return -TARGET_EFAULT
;
2819 host_mb
= malloc(msgsz
+sizeof(long));
2820 ret
= get_errno(msgrcv(msqid
, host_mb
, msgsz
, tswapal(msgtyp
), msgflg
));
2823 abi_ulong target_mtext_addr
= msgp
+ sizeof(abi_ulong
);
2824 target_mtext
= lock_user(VERIFY_WRITE
, target_mtext_addr
, ret
, 0);
2825 if (!target_mtext
) {
2826 ret
= -TARGET_EFAULT
;
2829 memcpy(target_mb
->mtext
, host_mb
->mtext
, ret
);
2830 unlock_user(target_mtext
, target_mtext_addr
, ret
);
2833 target_mb
->mtype
= tswapal(host_mb
->mtype
);
2838 unlock_user_struct(target_mb
, msgp
, 1);
2842 struct target_shmid_ds
2844 struct target_ipc_perm shm_perm
;
2845 abi_ulong shm_segsz
;
2846 abi_ulong shm_atime
;
2847 #if TARGET_ABI_BITS == 32
2848 abi_ulong __unused1
;
2850 abi_ulong shm_dtime
;
2851 #if TARGET_ABI_BITS == 32
2852 abi_ulong __unused2
;
2854 abi_ulong shm_ctime
;
2855 #if TARGET_ABI_BITS == 32
2856 abi_ulong __unused3
;
2860 abi_ulong shm_nattch
;
2861 unsigned long int __unused4
;
2862 unsigned long int __unused5
;
2865 static inline abi_long
target_to_host_shmid_ds(struct shmid_ds
*host_sd
,
2866 abi_ulong target_addr
)
2868 struct target_shmid_ds
*target_sd
;
2870 if (!lock_user_struct(VERIFY_READ
, target_sd
, target_addr
, 1))
2871 return -TARGET_EFAULT
;
2872 if (target_to_host_ipc_perm(&(host_sd
->shm_perm
), target_addr
))
2873 return -TARGET_EFAULT
;
2874 __get_user(host_sd
->shm_segsz
, &target_sd
->shm_segsz
);
2875 __get_user(host_sd
->shm_atime
, &target_sd
->shm_atime
);
2876 __get_user(host_sd
->shm_dtime
, &target_sd
->shm_dtime
);
2877 __get_user(host_sd
->shm_ctime
, &target_sd
->shm_ctime
);
2878 __get_user(host_sd
->shm_cpid
, &target_sd
->shm_cpid
);
2879 __get_user(host_sd
->shm_lpid
, &target_sd
->shm_lpid
);
2880 __get_user(host_sd
->shm_nattch
, &target_sd
->shm_nattch
);
2881 unlock_user_struct(target_sd
, target_addr
, 0);
2885 static inline abi_long
host_to_target_shmid_ds(abi_ulong target_addr
,
2886 struct shmid_ds
*host_sd
)
2888 struct target_shmid_ds
*target_sd
;
2890 if (!lock_user_struct(VERIFY_WRITE
, target_sd
, target_addr
, 0))
2891 return -TARGET_EFAULT
;
2892 if (host_to_target_ipc_perm(target_addr
, &(host_sd
->shm_perm
)))
2893 return -TARGET_EFAULT
;
2894 __put_user(host_sd
->shm_segsz
, &target_sd
->shm_segsz
);
2895 __put_user(host_sd
->shm_atime
, &target_sd
->shm_atime
);
2896 __put_user(host_sd
->shm_dtime
, &target_sd
->shm_dtime
);
2897 __put_user(host_sd
->shm_ctime
, &target_sd
->shm_ctime
);
2898 __put_user(host_sd
->shm_cpid
, &target_sd
->shm_cpid
);
2899 __put_user(host_sd
->shm_lpid
, &target_sd
->shm_lpid
);
2900 __put_user(host_sd
->shm_nattch
, &target_sd
->shm_nattch
);
2901 unlock_user_struct(target_sd
, target_addr
, 1);
2905 struct target_shminfo
{
2913 static inline abi_long
host_to_target_shminfo(abi_ulong target_addr
,
2914 struct shminfo
*host_shminfo
)
2916 struct target_shminfo
*target_shminfo
;
2917 if (!lock_user_struct(VERIFY_WRITE
, target_shminfo
, target_addr
, 0))
2918 return -TARGET_EFAULT
;
2919 __put_user(host_shminfo
->shmmax
, &target_shminfo
->shmmax
);
2920 __put_user(host_shminfo
->shmmin
, &target_shminfo
->shmmin
);
2921 __put_user(host_shminfo
->shmmni
, &target_shminfo
->shmmni
);
2922 __put_user(host_shminfo
->shmseg
, &target_shminfo
->shmseg
);
2923 __put_user(host_shminfo
->shmall
, &target_shminfo
->shmall
);
2924 unlock_user_struct(target_shminfo
, target_addr
, 1);
2928 struct target_shm_info
{
2933 abi_ulong swap_attempts
;
2934 abi_ulong swap_successes
;
2937 static inline abi_long
host_to_target_shm_info(abi_ulong target_addr
,
2938 struct shm_info
*host_shm_info
)
2940 struct target_shm_info
*target_shm_info
;
2941 if (!lock_user_struct(VERIFY_WRITE
, target_shm_info
, target_addr
, 0))
2942 return -TARGET_EFAULT
;
2943 __put_user(host_shm_info
->used_ids
, &target_shm_info
->used_ids
);
2944 __put_user(host_shm_info
->shm_tot
, &target_shm_info
->shm_tot
);
2945 __put_user(host_shm_info
->shm_rss
, &target_shm_info
->shm_rss
);
2946 __put_user(host_shm_info
->shm_swp
, &target_shm_info
->shm_swp
);
2947 __put_user(host_shm_info
->swap_attempts
, &target_shm_info
->swap_attempts
);
2948 __put_user(host_shm_info
->swap_successes
, &target_shm_info
->swap_successes
);
2949 unlock_user_struct(target_shm_info
, target_addr
, 1);
2953 static inline abi_long
do_shmctl(int shmid
, int cmd
, abi_long buf
)
2955 struct shmid_ds dsarg
;
2956 struct shminfo shminfo
;
2957 struct shm_info shm_info
;
2958 abi_long ret
= -TARGET_EINVAL
;
2966 if (target_to_host_shmid_ds(&dsarg
, buf
))
2967 return -TARGET_EFAULT
;
2968 ret
= get_errno(shmctl(shmid
, cmd
, &dsarg
));
2969 if (host_to_target_shmid_ds(buf
, &dsarg
))
2970 return -TARGET_EFAULT
;
2973 ret
= get_errno(shmctl(shmid
, cmd
, (struct shmid_ds
*)&shminfo
));
2974 if (host_to_target_shminfo(buf
, &shminfo
))
2975 return -TARGET_EFAULT
;
2978 ret
= get_errno(shmctl(shmid
, cmd
, (struct shmid_ds
*)&shm_info
));
2979 if (host_to_target_shm_info(buf
, &shm_info
))
2980 return -TARGET_EFAULT
;
2985 ret
= get_errno(shmctl(shmid
, cmd
, NULL
));
2992 static inline abi_ulong
do_shmat(int shmid
, abi_ulong shmaddr
, int shmflg
)
2996 struct shmid_ds shm_info
;
2999 /* find out the length of the shared memory segment */
3000 ret
= get_errno(shmctl(shmid
, IPC_STAT
, &shm_info
));
3001 if (is_error(ret
)) {
3002 /* can't get length, bail out */
3009 host_raddr
= shmat(shmid
, (void *)g2h(shmaddr
), shmflg
);
3011 abi_ulong mmap_start
;
3013 mmap_start
= mmap_find_vma(0, shm_info
.shm_segsz
);
3015 if (mmap_start
== -1) {
3017 host_raddr
= (void *)-1;
3019 host_raddr
= shmat(shmid
, g2h(mmap_start
), shmflg
| SHM_REMAP
);
3022 if (host_raddr
== (void *)-1) {
3024 return get_errno((long)host_raddr
);
3026 raddr
=h2g((unsigned long)host_raddr
);
3028 page_set_flags(raddr
, raddr
+ shm_info
.shm_segsz
,
3029 PAGE_VALID
| PAGE_READ
|
3030 ((shmflg
& SHM_RDONLY
)? 0 : PAGE_WRITE
));
3032 for (i
= 0; i
< N_SHM_REGIONS
; i
++) {
3033 if (shm_regions
[i
].start
== 0) {
3034 shm_regions
[i
].start
= raddr
;
3035 shm_regions
[i
].size
= shm_info
.shm_segsz
;
3045 static inline abi_long
do_shmdt(abi_ulong shmaddr
)
3049 for (i
= 0; i
< N_SHM_REGIONS
; ++i
) {
3050 if (shm_regions
[i
].start
== shmaddr
) {
3051 shm_regions
[i
].start
= 0;
3052 page_set_flags(shmaddr
, shmaddr
+ shm_regions
[i
].size
, 0);
3057 return get_errno(shmdt(g2h(shmaddr
)));
3060 #ifdef TARGET_NR_ipc
3061 /* ??? This only works with linear mappings. */
3062 /* do_ipc() must return target values and target errnos. */
3063 static abi_long
do_ipc(unsigned int call
, int first
,
3064 int second
, int third
,
3065 abi_long ptr
, abi_long fifth
)
3070 version
= call
>> 16;
3075 ret
= do_semop(first
, ptr
, second
);
3079 ret
= get_errno(semget(first
, second
, third
));
3083 ret
= do_semctl(first
, second
, third
, (union target_semun
)(abi_ulong
) ptr
);
3087 ret
= get_errno(msgget(first
, second
));
3091 ret
= do_msgsnd(first
, ptr
, second
, third
);
3095 ret
= do_msgctl(first
, second
, ptr
);
3102 struct target_ipc_kludge
{
3107 if (!lock_user_struct(VERIFY_READ
, tmp
, ptr
, 1)) {
3108 ret
= -TARGET_EFAULT
;
3112 ret
= do_msgrcv(first
, tmp
->msgp
, second
, tmp
->msgtyp
, third
);
3114 unlock_user_struct(tmp
, ptr
, 0);
3118 ret
= do_msgrcv(first
, ptr
, second
, fifth
, third
);
3127 raddr
= do_shmat(first
, ptr
, second
);
3128 if (is_error(raddr
))
3129 return get_errno(raddr
);
3130 if (put_user_ual(raddr
, third
))
3131 return -TARGET_EFAULT
;
3135 ret
= -TARGET_EINVAL
;
3140 ret
= do_shmdt(ptr
);
3144 /* IPC_* flag values are the same on all linux platforms */
3145 ret
= get_errno(shmget(first
, second
, third
));
3148 /* IPC_* and SHM_* command values are the same on all linux platforms */
3150 ret
= do_shmctl(first
, second
, third
);
3153 gemu_log("Unsupported ipc call: %d (version %d)\n", call
, version
);
3154 ret
= -TARGET_ENOSYS
;
3161 /* kernel structure types definitions */
3163 #define STRUCT(name, ...) STRUCT_ ## name,
3164 #define STRUCT_SPECIAL(name) STRUCT_ ## name,
3166 #include "syscall_types.h"
3169 #undef STRUCT_SPECIAL
3171 #define STRUCT(name, ...) static const argtype struct_ ## name ## _def[] = { __VA_ARGS__, TYPE_NULL };
3172 #define STRUCT_SPECIAL(name)
3173 #include "syscall_types.h"
3175 #undef STRUCT_SPECIAL
3177 typedef struct IOCTLEntry IOCTLEntry
;
3179 typedef abi_long
do_ioctl_fn(const IOCTLEntry
*ie
, uint8_t *buf_temp
,
3180 int fd
, abi_long cmd
, abi_long arg
);
3183 unsigned int target_cmd
;
3184 unsigned int host_cmd
;
3187 do_ioctl_fn
*do_ioctl
;
3188 const argtype arg_type
[5];
3191 #define IOC_R 0x0001
3192 #define IOC_W 0x0002
3193 #define IOC_RW (IOC_R | IOC_W)
3195 #define MAX_STRUCT_SIZE 4096
3197 #ifdef CONFIG_FIEMAP
3198 /* So fiemap access checks don't overflow on 32 bit systems.
3199 * This is very slightly smaller than the limit imposed by
3200 * the underlying kernel.
3202 #define FIEMAP_MAX_EXTENTS ((UINT_MAX - sizeof(struct fiemap)) \
3203 / sizeof(struct fiemap_extent))
3205 static abi_long
do_ioctl_fs_ioc_fiemap(const IOCTLEntry
*ie
, uint8_t *buf_temp
,
3206 int fd
, abi_long cmd
, abi_long arg
)
3208 /* The parameter for this ioctl is a struct fiemap followed
3209 * by an array of struct fiemap_extent whose size is set
3210 * in fiemap->fm_extent_count. The array is filled in by the
3213 int target_size_in
, target_size_out
;
3215 const argtype
*arg_type
= ie
->arg_type
;
3216 const argtype extent_arg_type
[] = { MK_STRUCT(STRUCT_fiemap_extent
) };
3219 int i
, extent_size
= thunk_type_size(extent_arg_type
, 0);
3223 assert(arg_type
[0] == TYPE_PTR
);
3224 assert(ie
->access
== IOC_RW
);
3226 target_size_in
= thunk_type_size(arg_type
, 0);
3227 argptr
= lock_user(VERIFY_READ
, arg
, target_size_in
, 1);
3229 return -TARGET_EFAULT
;
3231 thunk_convert(buf_temp
, argptr
, arg_type
, THUNK_HOST
);
3232 unlock_user(argptr
, arg
, 0);
3233 fm
= (struct fiemap
*)buf_temp
;
3234 if (fm
->fm_extent_count
> FIEMAP_MAX_EXTENTS
) {
3235 return -TARGET_EINVAL
;
3238 outbufsz
= sizeof (*fm
) +
3239 (sizeof(struct fiemap_extent
) * fm
->fm_extent_count
);
3241 if (outbufsz
> MAX_STRUCT_SIZE
) {
3242 /* We can't fit all the extents into the fixed size buffer.
3243 * Allocate one that is large enough and use it instead.
3245 fm
= malloc(outbufsz
);
3247 return -TARGET_ENOMEM
;
3249 memcpy(fm
, buf_temp
, sizeof(struct fiemap
));
3252 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, fm
));
3253 if (!is_error(ret
)) {
3254 target_size_out
= target_size_in
;
3255 /* An extent_count of 0 means we were only counting the extents
3256 * so there are no structs to copy
3258 if (fm
->fm_extent_count
!= 0) {
3259 target_size_out
+= fm
->fm_mapped_extents
* extent_size
;
3261 argptr
= lock_user(VERIFY_WRITE
, arg
, target_size_out
, 0);
3263 ret
= -TARGET_EFAULT
;
3265 /* Convert the struct fiemap */
3266 thunk_convert(argptr
, fm
, arg_type
, THUNK_TARGET
);
3267 if (fm
->fm_extent_count
!= 0) {
3268 p
= argptr
+ target_size_in
;
3269 /* ...and then all the struct fiemap_extents */
3270 for (i
= 0; i
< fm
->fm_mapped_extents
; i
++) {
3271 thunk_convert(p
, &fm
->fm_extents
[i
], extent_arg_type
,
3276 unlock_user(argptr
, arg
, target_size_out
);
3286 static abi_long
do_ioctl_ifconf(const IOCTLEntry
*ie
, uint8_t *buf_temp
,
3287 int fd
, abi_long cmd
, abi_long arg
)
3289 const argtype
*arg_type
= ie
->arg_type
;
3293 struct ifconf
*host_ifconf
;
3295 const argtype ifreq_arg_type
[] = { MK_STRUCT(STRUCT_sockaddr_ifreq
) };
3296 int target_ifreq_size
;
3301 abi_long target_ifc_buf
;
3305 assert(arg_type
[0] == TYPE_PTR
);
3306 assert(ie
->access
== IOC_RW
);
3309 target_size
= thunk_type_size(arg_type
, 0);
3311 argptr
= lock_user(VERIFY_READ
, arg
, target_size
, 1);
3313 return -TARGET_EFAULT
;
3314 thunk_convert(buf_temp
, argptr
, arg_type
, THUNK_HOST
);
3315 unlock_user(argptr
, arg
, 0);
3317 host_ifconf
= (struct ifconf
*)(unsigned long)buf_temp
;
3318 target_ifc_len
= host_ifconf
->ifc_len
;
3319 target_ifc_buf
= (abi_long
)(unsigned long)host_ifconf
->ifc_buf
;
3321 target_ifreq_size
= thunk_type_size(ifreq_arg_type
, 0);
3322 nb_ifreq
= target_ifc_len
/ target_ifreq_size
;
3323 host_ifc_len
= nb_ifreq
* sizeof(struct ifreq
);
3325 outbufsz
= sizeof(*host_ifconf
) + host_ifc_len
;
3326 if (outbufsz
> MAX_STRUCT_SIZE
) {
3327 /* We can't fit all the extents into the fixed size buffer.
3328 * Allocate one that is large enough and use it instead.
3330 host_ifconf
= malloc(outbufsz
);
3332 return -TARGET_ENOMEM
;
3334 memcpy(host_ifconf
, buf_temp
, sizeof(*host_ifconf
));
3337 host_ifc_buf
= (char*)host_ifconf
+ sizeof(*host_ifconf
);
3339 host_ifconf
->ifc_len
= host_ifc_len
;
3340 host_ifconf
->ifc_buf
= host_ifc_buf
;
3342 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, host_ifconf
));
3343 if (!is_error(ret
)) {
3344 /* convert host ifc_len to target ifc_len */
3346 nb_ifreq
= host_ifconf
->ifc_len
/ sizeof(struct ifreq
);
3347 target_ifc_len
= nb_ifreq
* target_ifreq_size
;
3348 host_ifconf
->ifc_len
= target_ifc_len
;
3350 /* restore target ifc_buf */
3352 host_ifconf
->ifc_buf
= (char *)(unsigned long)target_ifc_buf
;
3354 /* copy struct ifconf to target user */
3356 argptr
= lock_user(VERIFY_WRITE
, arg
, target_size
, 0);
3358 return -TARGET_EFAULT
;
3359 thunk_convert(argptr
, host_ifconf
, arg_type
, THUNK_TARGET
);
3360 unlock_user(argptr
, arg
, target_size
);
3362 /* copy ifreq[] to target user */
3364 argptr
= lock_user(VERIFY_WRITE
, target_ifc_buf
, target_ifc_len
, 0);
3365 for (i
= 0; i
< nb_ifreq
; i
++) {
3366 thunk_convert(argptr
+ i
* target_ifreq_size
,
3367 host_ifc_buf
+ i
* sizeof(struct ifreq
),
3368 ifreq_arg_type
, THUNK_TARGET
);
3370 unlock_user(argptr
, target_ifc_buf
, target_ifc_len
);
3380 static abi_long
do_ioctl_dm(const IOCTLEntry
*ie
, uint8_t *buf_temp
, int fd
,
3381 abi_long cmd
, abi_long arg
)
3384 struct dm_ioctl
*host_dm
;
3385 abi_long guest_data
;
3386 uint32_t guest_data_size
;
3388 const argtype
*arg_type
= ie
->arg_type
;
3390 void *big_buf
= NULL
;
3394 target_size
= thunk_type_size(arg_type
, 0);
3395 argptr
= lock_user(VERIFY_READ
, arg
, target_size
, 1);
3397 ret
= -TARGET_EFAULT
;
3400 thunk_convert(buf_temp
, argptr
, arg_type
, THUNK_HOST
);
3401 unlock_user(argptr
, arg
, 0);
3403 /* buf_temp is too small, so fetch things into a bigger buffer */
3404 big_buf
= g_malloc0(((struct dm_ioctl
*)buf_temp
)->data_size
* 2);
3405 memcpy(big_buf
, buf_temp
, target_size
);
3409 guest_data
= arg
+ host_dm
->data_start
;
3410 if ((guest_data
- arg
) < 0) {
3414 guest_data_size
= host_dm
->data_size
- host_dm
->data_start
;
3415 host_data
= (char*)host_dm
+ host_dm
->data_start
;
3417 argptr
= lock_user(VERIFY_READ
, guest_data
, guest_data_size
, 1);
3418 switch (ie
->host_cmd
) {
3420 case DM_LIST_DEVICES
:
3423 case DM_DEV_SUSPEND
:
3426 case DM_TABLE_STATUS
:
3427 case DM_TABLE_CLEAR
:
3429 case DM_LIST_VERSIONS
:
3433 case DM_DEV_SET_GEOMETRY
:
3434 /* data contains only strings */
3435 memcpy(host_data
, argptr
, guest_data_size
);
3438 memcpy(host_data
, argptr
, guest_data_size
);
3439 *(uint64_t*)host_data
= tswap64(*(uint64_t*)argptr
);
3443 void *gspec
= argptr
;
3444 void *cur_data
= host_data
;
3445 const argtype arg_type
[] = { MK_STRUCT(STRUCT_dm_target_spec
) };
3446 int spec_size
= thunk_type_size(arg_type
, 0);
3449 for (i
= 0; i
< host_dm
->target_count
; i
++) {
3450 struct dm_target_spec
*spec
= cur_data
;
3454 thunk_convert(spec
, gspec
, arg_type
, THUNK_HOST
);
3455 slen
= strlen((char*)gspec
+ spec_size
) + 1;
3457 spec
->next
= sizeof(*spec
) + slen
;
3458 strcpy((char*)&spec
[1], gspec
+ spec_size
);
3460 cur_data
+= spec
->next
;
3465 ret
= -TARGET_EINVAL
;
3468 unlock_user(argptr
, guest_data
, 0);
3470 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, buf_temp
));
3471 if (!is_error(ret
)) {
3472 guest_data
= arg
+ host_dm
->data_start
;
3473 guest_data_size
= host_dm
->data_size
- host_dm
->data_start
;
3474 argptr
= lock_user(VERIFY_WRITE
, guest_data
, guest_data_size
, 0);
3475 switch (ie
->host_cmd
) {
3480 case DM_DEV_SUSPEND
:
3483 case DM_TABLE_CLEAR
:
3485 case DM_DEV_SET_GEOMETRY
:
3486 /* no return data */
3488 case DM_LIST_DEVICES
:
3490 struct dm_name_list
*nl
= (void*)host_dm
+ host_dm
->data_start
;
3491 uint32_t remaining_data
= guest_data_size
;
3492 void *cur_data
= argptr
;
3493 const argtype arg_type
[] = { MK_STRUCT(STRUCT_dm_name_list
) };
3494 int nl_size
= 12; /* can't use thunk_size due to alignment */
3497 uint32_t next
= nl
->next
;
3499 nl
->next
= nl_size
+ (strlen(nl
->name
) + 1);
3501 if (remaining_data
< nl
->next
) {
3502 host_dm
->flags
|= DM_BUFFER_FULL_FLAG
;
3505 thunk_convert(cur_data
, nl
, arg_type
, THUNK_TARGET
);
3506 strcpy(cur_data
+ nl_size
, nl
->name
);
3507 cur_data
+= nl
->next
;
3508 remaining_data
-= nl
->next
;
3512 nl
= (void*)nl
+ next
;
3517 case DM_TABLE_STATUS
:
3519 struct dm_target_spec
*spec
= (void*)host_dm
+ host_dm
->data_start
;
3520 void *cur_data
= argptr
;
3521 const argtype arg_type
[] = { MK_STRUCT(STRUCT_dm_target_spec
) };
3522 int spec_size
= thunk_type_size(arg_type
, 0);
3525 for (i
= 0; i
< host_dm
->target_count
; i
++) {
3526 uint32_t next
= spec
->next
;
3527 int slen
= strlen((char*)&spec
[1]) + 1;
3528 spec
->next
= (cur_data
- argptr
) + spec_size
+ slen
;
3529 if (guest_data_size
< spec
->next
) {
3530 host_dm
->flags
|= DM_BUFFER_FULL_FLAG
;
3533 thunk_convert(cur_data
, spec
, arg_type
, THUNK_TARGET
);
3534 strcpy(cur_data
+ spec_size
, (char*)&spec
[1]);
3535 cur_data
= argptr
+ spec
->next
;
3536 spec
= (void*)host_dm
+ host_dm
->data_start
+ next
;
3542 void *hdata
= (void*)host_dm
+ host_dm
->data_start
;
3543 int count
= *(uint32_t*)hdata
;
3544 uint64_t *hdev
= hdata
+ 8;
3545 uint64_t *gdev
= argptr
+ 8;
3548 *(uint32_t*)argptr
= tswap32(count
);
3549 for (i
= 0; i
< count
; i
++) {
3550 *gdev
= tswap64(*hdev
);
3556 case DM_LIST_VERSIONS
:
3558 struct dm_target_versions
*vers
= (void*)host_dm
+ host_dm
->data_start
;
3559 uint32_t remaining_data
= guest_data_size
;
3560 void *cur_data
= argptr
;
3561 const argtype arg_type
[] = { MK_STRUCT(STRUCT_dm_target_versions
) };
3562 int vers_size
= thunk_type_size(arg_type
, 0);
3565 uint32_t next
= vers
->next
;
3567 vers
->next
= vers_size
+ (strlen(vers
->name
) + 1);
3569 if (remaining_data
< vers
->next
) {
3570 host_dm
->flags
|= DM_BUFFER_FULL_FLAG
;
3573 thunk_convert(cur_data
, vers
, arg_type
, THUNK_TARGET
);
3574 strcpy(cur_data
+ vers_size
, vers
->name
);
3575 cur_data
+= vers
->next
;
3576 remaining_data
-= vers
->next
;
3580 vers
= (void*)vers
+ next
;
3585 ret
= -TARGET_EINVAL
;
3588 unlock_user(argptr
, guest_data
, guest_data_size
);
3590 argptr
= lock_user(VERIFY_WRITE
, arg
, target_size
, 0);
3592 ret
= -TARGET_EFAULT
;
3595 thunk_convert(argptr
, buf_temp
, arg_type
, THUNK_TARGET
);
3596 unlock_user(argptr
, arg
, target_size
);
3605 static IOCTLEntry ioctl_entries
[] = {
3606 #define IOCTL(cmd, access, ...) \
3607 { TARGET_ ## cmd, cmd, #cmd, access, 0, { __VA_ARGS__ } },
3608 #define IOCTL_SPECIAL(cmd, access, dofn, ...) \
3609 { TARGET_ ## cmd, cmd, #cmd, access, dofn, { __VA_ARGS__ } },
3614 /* ??? Implement proper locking for ioctls. */
3615 /* do_ioctl() Must return target values and target errnos. */
3616 static abi_long
do_ioctl(int fd
, abi_long cmd
, abi_long arg
)
3618 const IOCTLEntry
*ie
;
3619 const argtype
*arg_type
;
3621 uint8_t buf_temp
[MAX_STRUCT_SIZE
];
3627 if (ie
->target_cmd
== 0) {
3628 gemu_log("Unsupported ioctl: cmd=0x%04lx\n", (long)cmd
);
3629 return -TARGET_ENOSYS
;
3631 if (ie
->target_cmd
== cmd
)
3635 arg_type
= ie
->arg_type
;
3637 gemu_log("ioctl: cmd=0x%04lx (%s)\n", (long)cmd
, ie
->name
);
3640 return ie
->do_ioctl(ie
, buf_temp
, fd
, cmd
, arg
);
3643 switch(arg_type
[0]) {
3646 ret
= get_errno(ioctl(fd
, ie
->host_cmd
));
3651 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, arg
));
3655 target_size
= thunk_type_size(arg_type
, 0);
3656 switch(ie
->access
) {
3658 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, buf_temp
));
3659 if (!is_error(ret
)) {
3660 argptr
= lock_user(VERIFY_WRITE
, arg
, target_size
, 0);
3662 return -TARGET_EFAULT
;
3663 thunk_convert(argptr
, buf_temp
, arg_type
, THUNK_TARGET
);
3664 unlock_user(argptr
, arg
, target_size
);
3668 argptr
= lock_user(VERIFY_READ
, arg
, target_size
, 1);
3670 return -TARGET_EFAULT
;
3671 thunk_convert(buf_temp
, argptr
, arg_type
, THUNK_HOST
);
3672 unlock_user(argptr
, arg
, 0);
3673 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, buf_temp
));
3677 argptr
= lock_user(VERIFY_READ
, arg
, target_size
, 1);
3679 return -TARGET_EFAULT
;
3680 thunk_convert(buf_temp
, argptr
, arg_type
, THUNK_HOST
);
3681 unlock_user(argptr
, arg
, 0);
3682 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, buf_temp
));
3683 if (!is_error(ret
)) {
3684 argptr
= lock_user(VERIFY_WRITE
, arg
, target_size
, 0);
3686 return -TARGET_EFAULT
;
3687 thunk_convert(argptr
, buf_temp
, arg_type
, THUNK_TARGET
);
3688 unlock_user(argptr
, arg
, target_size
);
3694 gemu_log("Unsupported ioctl type: cmd=0x%04lx type=%d\n",
3695 (long)cmd
, arg_type
[0]);
3696 ret
= -TARGET_ENOSYS
;
3702 static const bitmask_transtbl iflag_tbl
[] = {
3703 { TARGET_IGNBRK
, TARGET_IGNBRK
, IGNBRK
, IGNBRK
},
3704 { TARGET_BRKINT
, TARGET_BRKINT
, BRKINT
, BRKINT
},
3705 { TARGET_IGNPAR
, TARGET_IGNPAR
, IGNPAR
, IGNPAR
},
3706 { TARGET_PARMRK
, TARGET_PARMRK
, PARMRK
, PARMRK
},
3707 { TARGET_INPCK
, TARGET_INPCK
, INPCK
, INPCK
},
3708 { TARGET_ISTRIP
, TARGET_ISTRIP
, ISTRIP
, ISTRIP
},
3709 { TARGET_INLCR
, TARGET_INLCR
, INLCR
, INLCR
},
3710 { TARGET_IGNCR
, TARGET_IGNCR
, IGNCR
, IGNCR
},
3711 { TARGET_ICRNL
, TARGET_ICRNL
, ICRNL
, ICRNL
},
3712 { TARGET_IUCLC
, TARGET_IUCLC
, IUCLC
, IUCLC
},
3713 { TARGET_IXON
, TARGET_IXON
, IXON
, IXON
},
3714 { TARGET_IXANY
, TARGET_IXANY
, IXANY
, IXANY
},
3715 { TARGET_IXOFF
, TARGET_IXOFF
, IXOFF
, IXOFF
},
3716 { TARGET_IMAXBEL
, TARGET_IMAXBEL
, IMAXBEL
, IMAXBEL
},
3720 static const bitmask_transtbl oflag_tbl
[] = {
3721 { TARGET_OPOST
, TARGET_OPOST
, OPOST
, OPOST
},
3722 { TARGET_OLCUC
, TARGET_OLCUC
, OLCUC
, OLCUC
},
3723 { TARGET_ONLCR
, TARGET_ONLCR
, ONLCR
, ONLCR
},
3724 { TARGET_OCRNL
, TARGET_OCRNL
, OCRNL
, OCRNL
},
3725 { TARGET_ONOCR
, TARGET_ONOCR
, ONOCR
, ONOCR
},
3726 { TARGET_ONLRET
, TARGET_ONLRET
, ONLRET
, ONLRET
},
3727 { TARGET_OFILL
, TARGET_OFILL
, OFILL
, OFILL
},
3728 { TARGET_OFDEL
, TARGET_OFDEL
, OFDEL
, OFDEL
},
3729 { TARGET_NLDLY
, TARGET_NL0
, NLDLY
, NL0
},
3730 { TARGET_NLDLY
, TARGET_NL1
, NLDLY
, NL1
},
3731 { TARGET_CRDLY
, TARGET_CR0
, CRDLY
, CR0
},
3732 { TARGET_CRDLY
, TARGET_CR1
, CRDLY
, CR1
},
3733 { TARGET_CRDLY
, TARGET_CR2
, CRDLY
, CR2
},
3734 { TARGET_CRDLY
, TARGET_CR3
, CRDLY
, CR3
},
3735 { TARGET_TABDLY
, TARGET_TAB0
, TABDLY
, TAB0
},
3736 { TARGET_TABDLY
, TARGET_TAB1
, TABDLY
, TAB1
},
3737 { TARGET_TABDLY
, TARGET_TAB2
, TABDLY
, TAB2
},
3738 { TARGET_TABDLY
, TARGET_TAB3
, TABDLY
, TAB3
},
3739 { TARGET_BSDLY
, TARGET_BS0
, BSDLY
, BS0
},
3740 { TARGET_BSDLY
, TARGET_BS1
, BSDLY
, BS1
},
3741 { TARGET_VTDLY
, TARGET_VT0
, VTDLY
, VT0
},
3742 { TARGET_VTDLY
, TARGET_VT1
, VTDLY
, VT1
},
3743 { TARGET_FFDLY
, TARGET_FF0
, FFDLY
, FF0
},
3744 { TARGET_FFDLY
, TARGET_FF1
, FFDLY
, FF1
},
3748 static const bitmask_transtbl cflag_tbl
[] = {
3749 { TARGET_CBAUD
, TARGET_B0
, CBAUD
, B0
},
3750 { TARGET_CBAUD
, TARGET_B50
, CBAUD
, B50
},
3751 { TARGET_CBAUD
, TARGET_B75
, CBAUD
, B75
},
3752 { TARGET_CBAUD
, TARGET_B110
, CBAUD
, B110
},
3753 { TARGET_CBAUD
, TARGET_B134
, CBAUD
, B134
},
3754 { TARGET_CBAUD
, TARGET_B150
, CBAUD
, B150
},
3755 { TARGET_CBAUD
, TARGET_B200
, CBAUD
, B200
},
3756 { TARGET_CBAUD
, TARGET_B300
, CBAUD
, B300
},
3757 { TARGET_CBAUD
, TARGET_B600
, CBAUD
, B600
},
3758 { TARGET_CBAUD
, TARGET_B1200
, CBAUD
, B1200
},
3759 { TARGET_CBAUD
, TARGET_B1800
, CBAUD
, B1800
},
3760 { TARGET_CBAUD
, TARGET_B2400
, CBAUD
, B2400
},
3761 { TARGET_CBAUD
, TARGET_B4800
, CBAUD
, B4800
},
3762 { TARGET_CBAUD
, TARGET_B9600
, CBAUD
, B9600
},
3763 { TARGET_CBAUD
, TARGET_B19200
, CBAUD
, B19200
},
3764 { TARGET_CBAUD
, TARGET_B38400
, CBAUD
, B38400
},
3765 { TARGET_CBAUD
, TARGET_B57600
, CBAUD
, B57600
},
3766 { TARGET_CBAUD
, TARGET_B115200
, CBAUD
, B115200
},
3767 { TARGET_CBAUD
, TARGET_B230400
, CBAUD
, B230400
},
3768 { TARGET_CBAUD
, TARGET_B460800
, CBAUD
, B460800
},
3769 { TARGET_CSIZE
, TARGET_CS5
, CSIZE
, CS5
},
3770 { TARGET_CSIZE
, TARGET_CS6
, CSIZE
, CS6
},
3771 { TARGET_CSIZE
, TARGET_CS7
, CSIZE
, CS7
},
3772 { TARGET_CSIZE
, TARGET_CS8
, CSIZE
, CS8
},
3773 { TARGET_CSTOPB
, TARGET_CSTOPB
, CSTOPB
, CSTOPB
},
3774 { TARGET_CREAD
, TARGET_CREAD
, CREAD
, CREAD
},
3775 { TARGET_PARENB
, TARGET_PARENB
, PARENB
, PARENB
},
3776 { TARGET_PARODD
, TARGET_PARODD
, PARODD
, PARODD
},
3777 { TARGET_HUPCL
, TARGET_HUPCL
, HUPCL
, HUPCL
},
3778 { TARGET_CLOCAL
, TARGET_CLOCAL
, CLOCAL
, CLOCAL
},
3779 { TARGET_CRTSCTS
, TARGET_CRTSCTS
, CRTSCTS
, CRTSCTS
},
3783 static const bitmask_transtbl lflag_tbl
[] = {
3784 { TARGET_ISIG
, TARGET_ISIG
, ISIG
, ISIG
},
3785 { TARGET_ICANON
, TARGET_ICANON
, ICANON
, ICANON
},
3786 { TARGET_XCASE
, TARGET_XCASE
, XCASE
, XCASE
},
3787 { TARGET_ECHO
, TARGET_ECHO
, ECHO
, ECHO
},
3788 { TARGET_ECHOE
, TARGET_ECHOE
, ECHOE
, ECHOE
},
3789 { TARGET_ECHOK
, TARGET_ECHOK
, ECHOK
, ECHOK
},
3790 { TARGET_ECHONL
, TARGET_ECHONL
, ECHONL
, ECHONL
},
3791 { TARGET_NOFLSH
, TARGET_NOFLSH
, NOFLSH
, NOFLSH
},
3792 { TARGET_TOSTOP
, TARGET_TOSTOP
, TOSTOP
, TOSTOP
},
3793 { TARGET_ECHOCTL
, TARGET_ECHOCTL
, ECHOCTL
, ECHOCTL
},
3794 { TARGET_ECHOPRT
, TARGET_ECHOPRT
, ECHOPRT
, ECHOPRT
},
3795 { TARGET_ECHOKE
, TARGET_ECHOKE
, ECHOKE
, ECHOKE
},
3796 { TARGET_FLUSHO
, TARGET_FLUSHO
, FLUSHO
, FLUSHO
},
3797 { TARGET_PENDIN
, TARGET_PENDIN
, PENDIN
, PENDIN
},
3798 { TARGET_IEXTEN
, TARGET_IEXTEN
, IEXTEN
, IEXTEN
},
3802 static void target_to_host_termios (void *dst
, const void *src
)
3804 struct host_termios
*host
= dst
;
3805 const struct target_termios
*target
= src
;
3808 target_to_host_bitmask(tswap32(target
->c_iflag
), iflag_tbl
);
3810 target_to_host_bitmask(tswap32(target
->c_oflag
), oflag_tbl
);
3812 target_to_host_bitmask(tswap32(target
->c_cflag
), cflag_tbl
);
3814 target_to_host_bitmask(tswap32(target
->c_lflag
), lflag_tbl
);
3815 host
->c_line
= target
->c_line
;
3817 memset(host
->c_cc
, 0, sizeof(host
->c_cc
));
3818 host
->c_cc
[VINTR
] = target
->c_cc
[TARGET_VINTR
];
3819 host
->c_cc
[VQUIT
] = target
->c_cc
[TARGET_VQUIT
];
3820 host
->c_cc
[VERASE
] = target
->c_cc
[TARGET_VERASE
];
3821 host
->c_cc
[VKILL
] = target
->c_cc
[TARGET_VKILL
];
3822 host
->c_cc
[VEOF
] = target
->c_cc
[TARGET_VEOF
];
3823 host
->c_cc
[VTIME
] = target
->c_cc
[TARGET_VTIME
];
3824 host
->c_cc
[VMIN
] = target
->c_cc
[TARGET_VMIN
];
3825 host
->c_cc
[VSWTC
] = target
->c_cc
[TARGET_VSWTC
];
3826 host
->c_cc
[VSTART
] = target
->c_cc
[TARGET_VSTART
];
3827 host
->c_cc
[VSTOP
] = target
->c_cc
[TARGET_VSTOP
];
3828 host
->c_cc
[VSUSP
] = target
->c_cc
[TARGET_VSUSP
];
3829 host
->c_cc
[VEOL
] = target
->c_cc
[TARGET_VEOL
];
3830 host
->c_cc
[VREPRINT
] = target
->c_cc
[TARGET_VREPRINT
];
3831 host
->c_cc
[VDISCARD
] = target
->c_cc
[TARGET_VDISCARD
];
3832 host
->c_cc
[VWERASE
] = target
->c_cc
[TARGET_VWERASE
];
3833 host
->c_cc
[VLNEXT
] = target
->c_cc
[TARGET_VLNEXT
];
3834 host
->c_cc
[VEOL2
] = target
->c_cc
[TARGET_VEOL2
];
3837 static void host_to_target_termios (void *dst
, const void *src
)
3839 struct target_termios
*target
= dst
;
3840 const struct host_termios
*host
= src
;
3843 tswap32(host_to_target_bitmask(host
->c_iflag
, iflag_tbl
));
3845 tswap32(host_to_target_bitmask(host
->c_oflag
, oflag_tbl
));
3847 tswap32(host_to_target_bitmask(host
->c_cflag
, cflag_tbl
));
3849 tswap32(host_to_target_bitmask(host
->c_lflag
, lflag_tbl
));
3850 target
->c_line
= host
->c_line
;
3852 memset(target
->c_cc
, 0, sizeof(target
->c_cc
));
3853 target
->c_cc
[TARGET_VINTR
] = host
->c_cc
[VINTR
];
3854 target
->c_cc
[TARGET_VQUIT
] = host
->c_cc
[VQUIT
];
3855 target
->c_cc
[TARGET_VERASE
] = host
->c_cc
[VERASE
];
3856 target
->c_cc
[TARGET_VKILL
] = host
->c_cc
[VKILL
];
3857 target
->c_cc
[TARGET_VEOF
] = host
->c_cc
[VEOF
];
3858 target
->c_cc
[TARGET_VTIME
] = host
->c_cc
[VTIME
];
3859 target
->c_cc
[TARGET_VMIN
] = host
->c_cc
[VMIN
];
3860 target
->c_cc
[TARGET_VSWTC
] = host
->c_cc
[VSWTC
];
3861 target
->c_cc
[TARGET_VSTART
] = host
->c_cc
[VSTART
];
3862 target
->c_cc
[TARGET_VSTOP
] = host
->c_cc
[VSTOP
];
3863 target
->c_cc
[TARGET_VSUSP
] = host
->c_cc
[VSUSP
];
3864 target
->c_cc
[TARGET_VEOL
] = host
->c_cc
[VEOL
];
3865 target
->c_cc
[TARGET_VREPRINT
] = host
->c_cc
[VREPRINT
];
3866 target
->c_cc
[TARGET_VDISCARD
] = host
->c_cc
[VDISCARD
];
3867 target
->c_cc
[TARGET_VWERASE
] = host
->c_cc
[VWERASE
];
3868 target
->c_cc
[TARGET_VLNEXT
] = host
->c_cc
[VLNEXT
];
3869 target
->c_cc
[TARGET_VEOL2
] = host
->c_cc
[VEOL2
];
3872 static const StructEntry struct_termios_def
= {
3873 .convert
= { host_to_target_termios
, target_to_host_termios
},
3874 .size
= { sizeof(struct target_termios
), sizeof(struct host_termios
) },
3875 .align
= { __alignof__(struct target_termios
), __alignof__(struct host_termios
) },
3878 static bitmask_transtbl mmap_flags_tbl
[] = {
3879 { TARGET_MAP_SHARED
, TARGET_MAP_SHARED
, MAP_SHARED
, MAP_SHARED
},
3880 { TARGET_MAP_PRIVATE
, TARGET_MAP_PRIVATE
, MAP_PRIVATE
, MAP_PRIVATE
},
3881 { TARGET_MAP_FIXED
, TARGET_MAP_FIXED
, MAP_FIXED
, MAP_FIXED
},
3882 { TARGET_MAP_ANONYMOUS
, TARGET_MAP_ANONYMOUS
, MAP_ANONYMOUS
, MAP_ANONYMOUS
},
3883 { TARGET_MAP_GROWSDOWN
, TARGET_MAP_GROWSDOWN
, MAP_GROWSDOWN
, MAP_GROWSDOWN
},
3884 { TARGET_MAP_DENYWRITE
, TARGET_MAP_DENYWRITE
, MAP_DENYWRITE
, MAP_DENYWRITE
},
3885 { TARGET_MAP_EXECUTABLE
, TARGET_MAP_EXECUTABLE
, MAP_EXECUTABLE
, MAP_EXECUTABLE
},
3886 { TARGET_MAP_LOCKED
, TARGET_MAP_LOCKED
, MAP_LOCKED
, MAP_LOCKED
},
3890 #if defined(TARGET_I386)
3892 /* NOTE: there is really one LDT for all the threads */
3893 static uint8_t *ldt_table
;
3895 static abi_long
read_ldt(abi_ulong ptr
, unsigned long bytecount
)
3902 size
= TARGET_LDT_ENTRIES
* TARGET_LDT_ENTRY_SIZE
;
3903 if (size
> bytecount
)
3905 p
= lock_user(VERIFY_WRITE
, ptr
, size
, 0);
3907 return -TARGET_EFAULT
;
3908 /* ??? Should this by byteswapped? */
3909 memcpy(p
, ldt_table
, size
);
3910 unlock_user(p
, ptr
, size
);
3914 /* XXX: add locking support */
3915 static abi_long
write_ldt(CPUX86State
*env
,
3916 abi_ulong ptr
, unsigned long bytecount
, int oldmode
)
3918 struct target_modify_ldt_ldt_s ldt_info
;
3919 struct target_modify_ldt_ldt_s
*target_ldt_info
;
3920 int seg_32bit
, contents
, read_exec_only
, limit_in_pages
;
3921 int seg_not_present
, useable
, lm
;
3922 uint32_t *lp
, entry_1
, entry_2
;
3924 if (bytecount
!= sizeof(ldt_info
))
3925 return -TARGET_EINVAL
;
3926 if (!lock_user_struct(VERIFY_READ
, target_ldt_info
, ptr
, 1))
3927 return -TARGET_EFAULT
;
3928 ldt_info
.entry_number
= tswap32(target_ldt_info
->entry_number
);
3929 ldt_info
.base_addr
= tswapal(target_ldt_info
->base_addr
);
3930 ldt_info
.limit
= tswap32(target_ldt_info
->limit
);
3931 ldt_info
.flags
= tswap32(target_ldt_info
->flags
);
3932 unlock_user_struct(target_ldt_info
, ptr
, 0);
3934 if (ldt_info
.entry_number
>= TARGET_LDT_ENTRIES
)
3935 return -TARGET_EINVAL
;
3936 seg_32bit
= ldt_info
.flags
& 1;
3937 contents
= (ldt_info
.flags
>> 1) & 3;
3938 read_exec_only
= (ldt_info
.flags
>> 3) & 1;
3939 limit_in_pages
= (ldt_info
.flags
>> 4) & 1;
3940 seg_not_present
= (ldt_info
.flags
>> 5) & 1;
3941 useable
= (ldt_info
.flags
>> 6) & 1;
3945 lm
= (ldt_info
.flags
>> 7) & 1;
3947 if (contents
== 3) {
3949 return -TARGET_EINVAL
;
3950 if (seg_not_present
== 0)
3951 return -TARGET_EINVAL
;
3953 /* allocate the LDT */
3955 env
->ldt
.base
= target_mmap(0,
3956 TARGET_LDT_ENTRIES
* TARGET_LDT_ENTRY_SIZE
,
3957 PROT_READ
|PROT_WRITE
,
3958 MAP_ANONYMOUS
|MAP_PRIVATE
, -1, 0);
3959 if (env
->ldt
.base
== -1)
3960 return -TARGET_ENOMEM
;
3961 memset(g2h(env
->ldt
.base
), 0,
3962 TARGET_LDT_ENTRIES
* TARGET_LDT_ENTRY_SIZE
);
3963 env
->ldt
.limit
= 0xffff;
3964 ldt_table
= g2h(env
->ldt
.base
);
3967 /* NOTE: same code as Linux kernel */
3968 /* Allow LDTs to be cleared by the user. */
3969 if (ldt_info
.base_addr
== 0 && ldt_info
.limit
== 0) {
3972 read_exec_only
== 1 &&
3974 limit_in_pages
== 0 &&
3975 seg_not_present
== 1 &&
3983 entry_1
= ((ldt_info
.base_addr
& 0x0000ffff) << 16) |
3984 (ldt_info
.limit
& 0x0ffff);
3985 entry_2
= (ldt_info
.base_addr
& 0xff000000) |
3986 ((ldt_info
.base_addr
& 0x00ff0000) >> 16) |
3987 (ldt_info
.limit
& 0xf0000) |
3988 ((read_exec_only
^ 1) << 9) |
3990 ((seg_not_present
^ 1) << 15) |
3992 (limit_in_pages
<< 23) |
3996 entry_2
|= (useable
<< 20);
3998 /* Install the new entry ... */
4000 lp
= (uint32_t *)(ldt_table
+ (ldt_info
.entry_number
<< 3));
4001 lp
[0] = tswap32(entry_1
);
4002 lp
[1] = tswap32(entry_2
);
4006 /* specific and weird i386 syscalls */
4007 static abi_long
do_modify_ldt(CPUX86State
*env
, int func
, abi_ulong ptr
,
4008 unsigned long bytecount
)
4014 ret
= read_ldt(ptr
, bytecount
);
4017 ret
= write_ldt(env
, ptr
, bytecount
, 1);
4020 ret
= write_ldt(env
, ptr
, bytecount
, 0);
4023 ret
= -TARGET_ENOSYS
;
4029 #if defined(TARGET_I386) && defined(TARGET_ABI32)
4030 static abi_long
do_set_thread_area(CPUX86State
*env
, abi_ulong ptr
)
4032 uint64_t *gdt_table
= g2h(env
->gdt
.base
);
4033 struct target_modify_ldt_ldt_s ldt_info
;
4034 struct target_modify_ldt_ldt_s
*target_ldt_info
;
4035 int seg_32bit
, contents
, read_exec_only
, limit_in_pages
;
4036 int seg_not_present
, useable
, lm
;
4037 uint32_t *lp
, entry_1
, entry_2
;
4040 lock_user_struct(VERIFY_WRITE
, target_ldt_info
, ptr
, 1);
4041 if (!target_ldt_info
)
4042 return -TARGET_EFAULT
;
4043 ldt_info
.entry_number
= tswap32(target_ldt_info
->entry_number
);
4044 ldt_info
.base_addr
= tswapal(target_ldt_info
->base_addr
);
4045 ldt_info
.limit
= tswap32(target_ldt_info
->limit
);
4046 ldt_info
.flags
= tswap32(target_ldt_info
->flags
);
4047 if (ldt_info
.entry_number
== -1) {
4048 for (i
=TARGET_GDT_ENTRY_TLS_MIN
; i
<=TARGET_GDT_ENTRY_TLS_MAX
; i
++) {
4049 if (gdt_table
[i
] == 0) {
4050 ldt_info
.entry_number
= i
;
4051 target_ldt_info
->entry_number
= tswap32(i
);
4056 unlock_user_struct(target_ldt_info
, ptr
, 1);
4058 if (ldt_info
.entry_number
< TARGET_GDT_ENTRY_TLS_MIN
||
4059 ldt_info
.entry_number
> TARGET_GDT_ENTRY_TLS_MAX
)
4060 return -TARGET_EINVAL
;
4061 seg_32bit
= ldt_info
.flags
& 1;
4062 contents
= (ldt_info
.flags
>> 1) & 3;
4063 read_exec_only
= (ldt_info
.flags
>> 3) & 1;
4064 limit_in_pages
= (ldt_info
.flags
>> 4) & 1;
4065 seg_not_present
= (ldt_info
.flags
>> 5) & 1;
4066 useable
= (ldt_info
.flags
>> 6) & 1;
4070 lm
= (ldt_info
.flags
>> 7) & 1;
4073 if (contents
== 3) {
4074 if (seg_not_present
== 0)
4075 return -TARGET_EINVAL
;
4078 /* NOTE: same code as Linux kernel */
4079 /* Allow LDTs to be cleared by the user. */
4080 if (ldt_info
.base_addr
== 0 && ldt_info
.limit
== 0) {
4081 if ((contents
== 0 &&
4082 read_exec_only
== 1 &&
4084 limit_in_pages
== 0 &&
4085 seg_not_present
== 1 &&
4093 entry_1
= ((ldt_info
.base_addr
& 0x0000ffff) << 16) |
4094 (ldt_info
.limit
& 0x0ffff);
4095 entry_2
= (ldt_info
.base_addr
& 0xff000000) |
4096 ((ldt_info
.base_addr
& 0x00ff0000) >> 16) |
4097 (ldt_info
.limit
& 0xf0000) |
4098 ((read_exec_only
^ 1) << 9) |
4100 ((seg_not_present
^ 1) << 15) |
4102 (limit_in_pages
<< 23) |
4107 /* Install the new entry ... */
4109 lp
= (uint32_t *)(gdt_table
+ ldt_info
.entry_number
);
4110 lp
[0] = tswap32(entry_1
);
4111 lp
[1] = tswap32(entry_2
);
4115 static abi_long
do_get_thread_area(CPUX86State
*env
, abi_ulong ptr
)
4117 struct target_modify_ldt_ldt_s
*target_ldt_info
;
4118 uint64_t *gdt_table
= g2h(env
->gdt
.base
);
4119 uint32_t base_addr
, limit
, flags
;
4120 int seg_32bit
, contents
, read_exec_only
, limit_in_pages
, idx
;
4121 int seg_not_present
, useable
, lm
;
4122 uint32_t *lp
, entry_1
, entry_2
;
4124 lock_user_struct(VERIFY_WRITE
, target_ldt_info
, ptr
, 1);
4125 if (!target_ldt_info
)
4126 return -TARGET_EFAULT
;
4127 idx
= tswap32(target_ldt_info
->entry_number
);
4128 if (idx
< TARGET_GDT_ENTRY_TLS_MIN
||
4129 idx
> TARGET_GDT_ENTRY_TLS_MAX
) {
4130 unlock_user_struct(target_ldt_info
, ptr
, 1);
4131 return -TARGET_EINVAL
;
4133 lp
= (uint32_t *)(gdt_table
+ idx
);
4134 entry_1
= tswap32(lp
[0]);
4135 entry_2
= tswap32(lp
[1]);
4137 read_exec_only
= ((entry_2
>> 9) & 1) ^ 1;
4138 contents
= (entry_2
>> 10) & 3;
4139 seg_not_present
= ((entry_2
>> 15) & 1) ^ 1;
4140 seg_32bit
= (entry_2
>> 22) & 1;
4141 limit_in_pages
= (entry_2
>> 23) & 1;
4142 useable
= (entry_2
>> 20) & 1;
4146 lm
= (entry_2
>> 21) & 1;
4148 flags
= (seg_32bit
<< 0) | (contents
<< 1) |
4149 (read_exec_only
<< 3) | (limit_in_pages
<< 4) |
4150 (seg_not_present
<< 5) | (useable
<< 6) | (lm
<< 7);
4151 limit
= (entry_1
& 0xffff) | (entry_2
& 0xf0000);
4152 base_addr
= (entry_1
>> 16) |
4153 (entry_2
& 0xff000000) |
4154 ((entry_2
& 0xff) << 16);
4155 target_ldt_info
->base_addr
= tswapal(base_addr
);
4156 target_ldt_info
->limit
= tswap32(limit
);
4157 target_ldt_info
->flags
= tswap32(flags
);
4158 unlock_user_struct(target_ldt_info
, ptr
, 1);
4161 #endif /* TARGET_I386 && TARGET_ABI32 */
4163 #ifndef TARGET_ABI32
4164 static abi_long
do_arch_prctl(CPUX86State
*env
, int code
, abi_ulong addr
)
4171 case TARGET_ARCH_SET_GS
:
4172 case TARGET_ARCH_SET_FS
:
4173 if (code
== TARGET_ARCH_SET_GS
)
4177 cpu_x86_load_seg(env
, idx
, 0);
4178 env
->segs
[idx
].base
= addr
;
4180 case TARGET_ARCH_GET_GS
:
4181 case TARGET_ARCH_GET_FS
:
4182 if (code
== TARGET_ARCH_GET_GS
)
4186 val
= env
->segs
[idx
].base
;
4187 if (put_user(val
, addr
, abi_ulong
))
4188 ret
= -TARGET_EFAULT
;
4191 ret
= -TARGET_EINVAL
;
4198 #endif /* defined(TARGET_I386) */
4200 #define NEW_STACK_SIZE 0x40000
4202 #if defined(CONFIG_USE_NPTL)
4204 static pthread_mutex_t clone_lock
= PTHREAD_MUTEX_INITIALIZER
;
4207 pthread_mutex_t mutex
;
4208 pthread_cond_t cond
;
4211 abi_ulong child_tidptr
;
4212 abi_ulong parent_tidptr
;
4216 static void *clone_func(void *arg
)
4218 new_thread_info
*info
= arg
;
4224 ts
= (TaskState
*)thread_env
->opaque
;
4225 info
->tid
= gettid();
4226 env
->host_tid
= info
->tid
;
4228 if (info
->child_tidptr
)
4229 put_user_u32(info
->tid
, info
->child_tidptr
);
4230 if (info
->parent_tidptr
)
4231 put_user_u32(info
->tid
, info
->parent_tidptr
);
4232 /* Enable signals. */
4233 sigprocmask(SIG_SETMASK
, &info
->sigmask
, NULL
);
4234 /* Signal to the parent that we're ready. */
4235 pthread_mutex_lock(&info
->mutex
);
4236 pthread_cond_broadcast(&info
->cond
);
4237 pthread_mutex_unlock(&info
->mutex
);
4238 /* Wait until the parent has finshed initializing the tls state. */
4239 pthread_mutex_lock(&clone_lock
);
4240 pthread_mutex_unlock(&clone_lock
);
4247 static int clone_func(void *arg
)
4249 CPUArchState
*env
= arg
;
4256 /* do_fork() Must return host values and target errnos (unlike most
4257 do_*() functions). */
4258 static int do_fork(CPUArchState
*env
, unsigned int flags
, abi_ulong newsp
,
4259 abi_ulong parent_tidptr
, target_ulong newtls
,
4260 abi_ulong child_tidptr
)
4264 CPUArchState
*new_env
;
4265 #if defined(CONFIG_USE_NPTL)
4266 unsigned int nptl_flags
;
4272 /* Emulate vfork() with fork() */
4273 if (flags
& CLONE_VFORK
)
4274 flags
&= ~(CLONE_VFORK
| CLONE_VM
);
4276 if (flags
& CLONE_VM
) {
4277 TaskState
*parent_ts
= (TaskState
*)env
->opaque
;
4278 #if defined(CONFIG_USE_NPTL)
4279 new_thread_info info
;
4280 pthread_attr_t attr
;
4282 ts
= g_malloc0(sizeof(TaskState
));
4283 init_task_state(ts
);
4284 /* we create a new CPU instance. */
4285 new_env
= cpu_copy(env
);
4286 #if defined(TARGET_I386) || defined(TARGET_SPARC) || defined(TARGET_PPC)
4287 cpu_reset(ENV_GET_CPU(new_env
));
4289 /* Init regs that differ from the parent. */
4290 cpu_clone_regs(new_env
, newsp
);
4291 new_env
->opaque
= ts
;
4292 ts
->bprm
= parent_ts
->bprm
;
4293 ts
->info
= parent_ts
->info
;
4294 #if defined(CONFIG_USE_NPTL)
4296 flags
&= ~CLONE_NPTL_FLAGS2
;
4298 if (nptl_flags
& CLONE_CHILD_CLEARTID
) {
4299 ts
->child_tidptr
= child_tidptr
;
4302 if (nptl_flags
& CLONE_SETTLS
)
4303 cpu_set_tls (new_env
, newtls
);
4305 /* Grab a mutex so that thread setup appears atomic. */
4306 pthread_mutex_lock(&clone_lock
);
4308 memset(&info
, 0, sizeof(info
));
4309 pthread_mutex_init(&info
.mutex
, NULL
);
4310 pthread_mutex_lock(&info
.mutex
);
4311 pthread_cond_init(&info
.cond
, NULL
);
4313 if (nptl_flags
& CLONE_CHILD_SETTID
)
4314 info
.child_tidptr
= child_tidptr
;
4315 if (nptl_flags
& CLONE_PARENT_SETTID
)
4316 info
.parent_tidptr
= parent_tidptr
;
4318 ret
= pthread_attr_init(&attr
);
4319 ret
= pthread_attr_setstacksize(&attr
, NEW_STACK_SIZE
);
4320 ret
= pthread_attr_setdetachstate(&attr
, PTHREAD_CREATE_DETACHED
);
4321 /* It is not safe to deliver signals until the child has finished
4322 initializing, so temporarily block all signals. */
4323 sigfillset(&sigmask
);
4324 sigprocmask(SIG_BLOCK
, &sigmask
, &info
.sigmask
);
4326 ret
= pthread_create(&info
.thread
, &attr
, clone_func
, &info
);
4327 /* TODO: Free new CPU state if thread creation failed. */
4329 sigprocmask(SIG_SETMASK
, &info
.sigmask
, NULL
);
4330 pthread_attr_destroy(&attr
);
4332 /* Wait for the child to initialize. */
4333 pthread_cond_wait(&info
.cond
, &info
.mutex
);
4335 if (flags
& CLONE_PARENT_SETTID
)
4336 put_user_u32(ret
, parent_tidptr
);
4340 pthread_mutex_unlock(&info
.mutex
);
4341 pthread_cond_destroy(&info
.cond
);
4342 pthread_mutex_destroy(&info
.mutex
);
4343 pthread_mutex_unlock(&clone_lock
);
4345 if (flags
& CLONE_NPTL_FLAGS2
)
4347 /* This is probably going to die very quickly, but do it anyway. */
4348 new_stack
= g_malloc0 (NEW_STACK_SIZE
);
4350 ret
= __clone2(clone_func
, new_stack
, NEW_STACK_SIZE
, flags
, new_env
);
4352 ret
= clone(clone_func
, new_stack
+ NEW_STACK_SIZE
, flags
, new_env
);
4356 /* if no CLONE_VM, we consider it is a fork */
4357 if ((flags
& ~(CSIGNAL
| CLONE_NPTL_FLAGS2
)) != 0)
4362 /* Child Process. */
4363 cpu_clone_regs(env
, newsp
);
4365 #if defined(CONFIG_USE_NPTL)
4366 /* There is a race condition here. The parent process could
4367 theoretically read the TID in the child process before the child
4368 tid is set. This would require using either ptrace
4369 (not implemented) or having *_tidptr to point at a shared memory
4370 mapping. We can't repeat the spinlock hack used above because
4371 the child process gets its own copy of the lock. */
4372 if (flags
& CLONE_CHILD_SETTID
)
4373 put_user_u32(gettid(), child_tidptr
);
4374 if (flags
& CLONE_PARENT_SETTID
)
4375 put_user_u32(gettid(), parent_tidptr
);
4376 ts
= (TaskState
*)env
->opaque
;
4377 if (flags
& CLONE_SETTLS
)
4378 cpu_set_tls (env
, newtls
);
4379 if (flags
& CLONE_CHILD_CLEARTID
)
4380 ts
->child_tidptr
= child_tidptr
;
4389 /* warning : doesn't handle linux specific flags... */
4390 static int target_to_host_fcntl_cmd(int cmd
)
4393 case TARGET_F_DUPFD
:
4394 case TARGET_F_GETFD
:
4395 case TARGET_F_SETFD
:
4396 case TARGET_F_GETFL
:
4397 case TARGET_F_SETFL
:
4399 case TARGET_F_GETLK
:
4401 case TARGET_F_SETLK
:
4403 case TARGET_F_SETLKW
:
4405 case TARGET_F_GETOWN
:
4407 case TARGET_F_SETOWN
:
4409 case TARGET_F_GETSIG
:
4411 case TARGET_F_SETSIG
:
4413 #if TARGET_ABI_BITS == 32
4414 case TARGET_F_GETLK64
:
4416 case TARGET_F_SETLK64
:
4418 case TARGET_F_SETLKW64
:
4421 case TARGET_F_SETLEASE
:
4423 case TARGET_F_GETLEASE
:
4425 #ifdef F_DUPFD_CLOEXEC
4426 case TARGET_F_DUPFD_CLOEXEC
:
4427 return F_DUPFD_CLOEXEC
;
4429 case TARGET_F_NOTIFY
:
4432 return -TARGET_EINVAL
;
4434 return -TARGET_EINVAL
;
4437 static abi_long
do_fcntl(int fd
, int cmd
, abi_ulong arg
)
4440 struct target_flock
*target_fl
;
4441 struct flock64 fl64
;
4442 struct target_flock64
*target_fl64
;
4444 int host_cmd
= target_to_host_fcntl_cmd(cmd
);
4446 if (host_cmd
== -TARGET_EINVAL
)
4450 case TARGET_F_GETLK
:
4451 if (!lock_user_struct(VERIFY_READ
, target_fl
, arg
, 1))
4452 return -TARGET_EFAULT
;
4453 fl
.l_type
= tswap16(target_fl
->l_type
);
4454 fl
.l_whence
= tswap16(target_fl
->l_whence
);
4455 fl
.l_start
= tswapal(target_fl
->l_start
);
4456 fl
.l_len
= tswapal(target_fl
->l_len
);
4457 fl
.l_pid
= tswap32(target_fl
->l_pid
);
4458 unlock_user_struct(target_fl
, arg
, 0);
4459 ret
= get_errno(fcntl(fd
, host_cmd
, &fl
));
4461 if (!lock_user_struct(VERIFY_WRITE
, target_fl
, arg
, 0))
4462 return -TARGET_EFAULT
;
4463 target_fl
->l_type
= tswap16(fl
.l_type
);
4464 target_fl
->l_whence
= tswap16(fl
.l_whence
);
4465 target_fl
->l_start
= tswapal(fl
.l_start
);
4466 target_fl
->l_len
= tswapal(fl
.l_len
);
4467 target_fl
->l_pid
= tswap32(fl
.l_pid
);
4468 unlock_user_struct(target_fl
, arg
, 1);
4472 case TARGET_F_SETLK
:
4473 case TARGET_F_SETLKW
:
4474 if (!lock_user_struct(VERIFY_READ
, target_fl
, arg
, 1))
4475 return -TARGET_EFAULT
;
4476 fl
.l_type
= tswap16(target_fl
->l_type
);
4477 fl
.l_whence
= tswap16(target_fl
->l_whence
);
4478 fl
.l_start
= tswapal(target_fl
->l_start
);
4479 fl
.l_len
= tswapal(target_fl
->l_len
);
4480 fl
.l_pid
= tswap32(target_fl
->l_pid
);
4481 unlock_user_struct(target_fl
, arg
, 0);
4482 ret
= get_errno(fcntl(fd
, host_cmd
, &fl
));
4485 case TARGET_F_GETLK64
:
4486 if (!lock_user_struct(VERIFY_READ
, target_fl64
, arg
, 1))
4487 return -TARGET_EFAULT
;
4488 fl64
.l_type
= tswap16(target_fl64
->l_type
) >> 1;
4489 fl64
.l_whence
= tswap16(target_fl64
->l_whence
);
4490 fl64
.l_start
= tswap64(target_fl64
->l_start
);
4491 fl64
.l_len
= tswap64(target_fl64
->l_len
);
4492 fl64
.l_pid
= tswap32(target_fl64
->l_pid
);
4493 unlock_user_struct(target_fl64
, arg
, 0);
4494 ret
= get_errno(fcntl(fd
, host_cmd
, &fl64
));
4496 if (!lock_user_struct(VERIFY_WRITE
, target_fl64
, arg
, 0))
4497 return -TARGET_EFAULT
;
4498 target_fl64
->l_type
= tswap16(fl64
.l_type
) >> 1;
4499 target_fl64
->l_whence
= tswap16(fl64
.l_whence
);
4500 target_fl64
->l_start
= tswap64(fl64
.l_start
);
4501 target_fl64
->l_len
= tswap64(fl64
.l_len
);
4502 target_fl64
->l_pid
= tswap32(fl64
.l_pid
);
4503 unlock_user_struct(target_fl64
, arg
, 1);
4506 case TARGET_F_SETLK64
:
4507 case TARGET_F_SETLKW64
:
4508 if (!lock_user_struct(VERIFY_READ
, target_fl64
, arg
, 1))
4509 return -TARGET_EFAULT
;
4510 fl64
.l_type
= tswap16(target_fl64
->l_type
) >> 1;
4511 fl64
.l_whence
= tswap16(target_fl64
->l_whence
);
4512 fl64
.l_start
= tswap64(target_fl64
->l_start
);
4513 fl64
.l_len
= tswap64(target_fl64
->l_len
);
4514 fl64
.l_pid
= tswap32(target_fl64
->l_pid
);
4515 unlock_user_struct(target_fl64
, arg
, 0);
4516 ret
= get_errno(fcntl(fd
, host_cmd
, &fl64
));
4519 case TARGET_F_GETFL
:
4520 ret
= get_errno(fcntl(fd
, host_cmd
, arg
));
4522 ret
= host_to_target_bitmask(ret
, fcntl_flags_tbl
);
4526 case TARGET_F_SETFL
:
4527 ret
= get_errno(fcntl(fd
, host_cmd
, target_to_host_bitmask(arg
, fcntl_flags_tbl
)));
4530 case TARGET_F_SETOWN
:
4531 case TARGET_F_GETOWN
:
4532 case TARGET_F_SETSIG
:
4533 case TARGET_F_GETSIG
:
4534 case TARGET_F_SETLEASE
:
4535 case TARGET_F_GETLEASE
:
4536 ret
= get_errno(fcntl(fd
, host_cmd
, arg
));
4540 ret
= get_errno(fcntl(fd
, cmd
, arg
));
4548 static inline int high2lowuid(int uid
)
4556 static inline int high2lowgid(int gid
)
4564 static inline int low2highuid(int uid
)
4566 if ((int16_t)uid
== -1)
4572 static inline int low2highgid(int gid
)
4574 if ((int16_t)gid
== -1)
4579 static inline int tswapid(int id
)
4583 #else /* !USE_UID16 */
4584 static inline int high2lowuid(int uid
)
4588 static inline int high2lowgid(int gid
)
4592 static inline int low2highuid(int uid
)
4596 static inline int low2highgid(int gid
)
4600 static inline int tswapid(int id
)
4604 #endif /* USE_UID16 */
4606 void syscall_init(void)
4609 const argtype
*arg_type
;
4613 #define STRUCT(name, ...) thunk_register_struct(STRUCT_ ## name, #name, struct_ ## name ## _def);
4614 #define STRUCT_SPECIAL(name) thunk_register_struct_direct(STRUCT_ ## name, #name, &struct_ ## name ## _def);
4615 #include "syscall_types.h"
4617 #undef STRUCT_SPECIAL
4619 /* Build target_to_host_errno_table[] table from
4620 * host_to_target_errno_table[]. */
4621 for (i
= 0; i
< ERRNO_TABLE_SIZE
; i
++) {
4622 target_to_host_errno_table
[host_to_target_errno_table
[i
]] = i
;
4625 /* we patch the ioctl size if necessary. We rely on the fact that
4626 no ioctl has all the bits at '1' in the size field */
4628 while (ie
->target_cmd
!= 0) {
4629 if (((ie
->target_cmd
>> TARGET_IOC_SIZESHIFT
) & TARGET_IOC_SIZEMASK
) ==
4630 TARGET_IOC_SIZEMASK
) {
4631 arg_type
= ie
->arg_type
;
4632 if (arg_type
[0] != TYPE_PTR
) {
4633 fprintf(stderr
, "cannot patch size for ioctl 0x%x\n",
4638 size
= thunk_type_size(arg_type
, 0);
4639 ie
->target_cmd
= (ie
->target_cmd
&
4640 ~(TARGET_IOC_SIZEMASK
<< TARGET_IOC_SIZESHIFT
)) |
4641 (size
<< TARGET_IOC_SIZESHIFT
);
4644 /* automatic consistency check if same arch */
4645 #if (defined(__i386__) && defined(TARGET_I386) && defined(TARGET_ABI32)) || \
4646 (defined(__x86_64__) && defined(TARGET_X86_64))
4647 if (unlikely(ie
->target_cmd
!= ie
->host_cmd
)) {
4648 fprintf(stderr
, "ERROR: ioctl(%s): target=0x%x host=0x%x\n",
4649 ie
->name
, ie
->target_cmd
, ie
->host_cmd
);
4656 #if TARGET_ABI_BITS == 32
4657 static inline uint64_t target_offset64(uint32_t word0
, uint32_t word1
)
4659 #ifdef TARGET_WORDS_BIGENDIAN
4660 return ((uint64_t)word0
<< 32) | word1
;
4662 return ((uint64_t)word1
<< 32) | word0
;
4665 #else /* TARGET_ABI_BITS == 32 */
4666 static inline uint64_t target_offset64(uint64_t word0
, uint64_t word1
)
4670 #endif /* TARGET_ABI_BITS != 32 */
4672 #ifdef TARGET_NR_truncate64
4673 static inline abi_long
target_truncate64(void *cpu_env
, const char *arg1
,
4678 if (regpairs_aligned(cpu_env
)) {
4682 return get_errno(truncate64(arg1
, target_offset64(arg2
, arg3
)));
4686 #ifdef TARGET_NR_ftruncate64
4687 static inline abi_long
target_ftruncate64(void *cpu_env
, abi_long arg1
,
4692 if (regpairs_aligned(cpu_env
)) {
4696 return get_errno(ftruncate64(arg1
, target_offset64(arg2
, arg3
)));
4700 static inline abi_long
target_to_host_timespec(struct timespec
*host_ts
,
4701 abi_ulong target_addr
)
4703 struct target_timespec
*target_ts
;
4705 if (!lock_user_struct(VERIFY_READ
, target_ts
, target_addr
, 1))
4706 return -TARGET_EFAULT
;
4707 host_ts
->tv_sec
= tswapal(target_ts
->tv_sec
);
4708 host_ts
->tv_nsec
= tswapal(target_ts
->tv_nsec
);
4709 unlock_user_struct(target_ts
, target_addr
, 0);
4713 static inline abi_long
host_to_target_timespec(abi_ulong target_addr
,
4714 struct timespec
*host_ts
)
4716 struct target_timespec
*target_ts
;
4718 if (!lock_user_struct(VERIFY_WRITE
, target_ts
, target_addr
, 0))
4719 return -TARGET_EFAULT
;
4720 target_ts
->tv_sec
= tswapal(host_ts
->tv_sec
);
4721 target_ts
->tv_nsec
= tswapal(host_ts
->tv_nsec
);
4722 unlock_user_struct(target_ts
, target_addr
, 1);
4726 #if defined(TARGET_NR_stat64) || defined(TARGET_NR_newfstatat)
4727 static inline abi_long
host_to_target_stat64(void *cpu_env
,
4728 abi_ulong target_addr
,
4729 struct stat
*host_st
)
4732 if (((CPUARMState
*)cpu_env
)->eabi
) {
4733 struct target_eabi_stat64
*target_st
;
4735 if (!lock_user_struct(VERIFY_WRITE
, target_st
, target_addr
, 0))
4736 return -TARGET_EFAULT
;
4737 memset(target_st
, 0, sizeof(struct target_eabi_stat64
));
4738 __put_user(host_st
->st_dev
, &target_st
->st_dev
);
4739 __put_user(host_st
->st_ino
, &target_st
->st_ino
);
4740 #ifdef TARGET_STAT64_HAS_BROKEN_ST_INO
4741 __put_user(host_st
->st_ino
, &target_st
->__st_ino
);
4743 __put_user(host_st
->st_mode
, &target_st
->st_mode
);
4744 __put_user(host_st
->st_nlink
, &target_st
->st_nlink
);
4745 __put_user(host_st
->st_uid
, &target_st
->st_uid
);
4746 __put_user(host_st
->st_gid
, &target_st
->st_gid
);
4747 __put_user(host_st
->st_rdev
, &target_st
->st_rdev
);
4748 __put_user(host_st
->st_size
, &target_st
->st_size
);
4749 __put_user(host_st
->st_blksize
, &target_st
->st_blksize
);
4750 __put_user(host_st
->st_blocks
, &target_st
->st_blocks
);
4751 __put_user(host_st
->st_atime
, &target_st
->target_st_atime
);
4752 __put_user(host_st
->st_mtime
, &target_st
->target_st_mtime
);
4753 __put_user(host_st
->st_ctime
, &target_st
->target_st_ctime
);
4754 unlock_user_struct(target_st
, target_addr
, 1);
4758 #if TARGET_ABI_BITS == 64 && !defined(TARGET_ALPHA)
4759 struct target_stat
*target_st
;
4761 struct target_stat64
*target_st
;
4764 if (!lock_user_struct(VERIFY_WRITE
, target_st
, target_addr
, 0))
4765 return -TARGET_EFAULT
;
4766 memset(target_st
, 0, sizeof(*target_st
));
4767 __put_user(host_st
->st_dev
, &target_st
->st_dev
);
4768 __put_user(host_st
->st_ino
, &target_st
->st_ino
);
4769 #ifdef TARGET_STAT64_HAS_BROKEN_ST_INO
4770 __put_user(host_st
->st_ino
, &target_st
->__st_ino
);
4772 __put_user(host_st
->st_mode
, &target_st
->st_mode
);
4773 __put_user(host_st
->st_nlink
, &target_st
->st_nlink
);
4774 __put_user(host_st
->st_uid
, &target_st
->st_uid
);
4775 __put_user(host_st
->st_gid
, &target_st
->st_gid
);
4776 __put_user(host_st
->st_rdev
, &target_st
->st_rdev
);
4777 /* XXX: better use of kernel struct */
4778 __put_user(host_st
->st_size
, &target_st
->st_size
);
4779 __put_user(host_st
->st_blksize
, &target_st
->st_blksize
);
4780 __put_user(host_st
->st_blocks
, &target_st
->st_blocks
);
4781 __put_user(host_st
->st_atime
, &target_st
->target_st_atime
);
4782 __put_user(host_st
->st_mtime
, &target_st
->target_st_mtime
);
4783 __put_user(host_st
->st_ctime
, &target_st
->target_st_ctime
);
4784 unlock_user_struct(target_st
, target_addr
, 1);
4791 #if defined(CONFIG_USE_NPTL)
4792 /* ??? Using host futex calls even when target atomic operations
4793 are not really atomic probably breaks things. However implementing
4794 futexes locally would make futexes shared between multiple processes
4795 tricky. However they're probably useless because guest atomic
4796 operations won't work either. */
4797 static int do_futex(target_ulong uaddr
, int op
, int val
, target_ulong timeout
,
4798 target_ulong uaddr2
, int val3
)
4800 struct timespec ts
, *pts
;
4803 /* ??? We assume FUTEX_* constants are the same on both host
4805 #ifdef FUTEX_CMD_MASK
4806 base_op
= op
& FUTEX_CMD_MASK
;
4814 target_to_host_timespec(pts
, timeout
);
4818 return get_errno(sys_futex(g2h(uaddr
), op
, tswap32(val
),
4821 return get_errno(sys_futex(g2h(uaddr
), op
, val
, NULL
, NULL
, 0));
4823 return get_errno(sys_futex(g2h(uaddr
), op
, val
, NULL
, NULL
, 0));
4825 case FUTEX_CMP_REQUEUE
:
4827 /* For FUTEX_REQUEUE, FUTEX_CMP_REQUEUE, and FUTEX_WAKE_OP, the
4828 TIMEOUT parameter is interpreted as a uint32_t by the kernel.
4829 But the prototype takes a `struct timespec *'; insert casts
4830 to satisfy the compiler. We do not need to tswap TIMEOUT
4831 since it's not compared to guest memory. */
4832 pts
= (struct timespec
*)(uintptr_t) timeout
;
4833 return get_errno(sys_futex(g2h(uaddr
), op
, val
, pts
,
4835 (base_op
== FUTEX_CMP_REQUEUE
4839 return -TARGET_ENOSYS
;
4844 /* Map host to target signal numbers for the wait family of syscalls.
4845 Assume all other status bits are the same. */
4846 static int host_to_target_waitstatus(int status
)
4848 if (WIFSIGNALED(status
)) {
4849 return host_to_target_signal(WTERMSIG(status
)) | (status
& ~0x7f);
4851 if (WIFSTOPPED(status
)) {
4852 return (host_to_target_signal(WSTOPSIG(status
)) << 8)
4858 int get_osversion(void)
4860 static int osversion
;
4861 struct new_utsname buf
;
4866 if (qemu_uname_release
&& *qemu_uname_release
) {
4867 s
= qemu_uname_release
;
4869 if (sys_uname(&buf
))
4874 for (i
= 0; i
< 3; i
++) {
4876 while (*s
>= '0' && *s
<= '9') {
4881 tmp
= (tmp
<< 8) + n
;
4890 static int open_self_maps(void *cpu_env
, int fd
)
4892 #if defined(TARGET_ARM) || defined(TARGET_M68K) || defined(TARGET_UNICORE32)
4893 TaskState
*ts
= ((CPUArchState
*)cpu_env
)->opaque
;
4900 fp
= fopen("/proc/self/maps", "r");
4905 while ((read
= getline(&line
, &len
, fp
)) != -1) {
4906 int fields
, dev_maj
, dev_min
, inode
;
4907 uint64_t min
, max
, offset
;
4908 char flag_r
, flag_w
, flag_x
, flag_p
;
4909 char path
[512] = "";
4910 fields
= sscanf(line
, "%"PRIx64
"-%"PRIx64
" %c%c%c%c %"PRIx64
" %x:%x %d"
4911 " %512s", &min
, &max
, &flag_r
, &flag_w
, &flag_x
,
4912 &flag_p
, &offset
, &dev_maj
, &dev_min
, &inode
, path
);
4914 if ((fields
< 10) || (fields
> 11)) {
4917 if (!strncmp(path
, "[stack]", 7)) {
4920 if (h2g_valid(min
) && h2g_valid(max
)) {
4921 dprintf(fd
, TARGET_ABI_FMT_lx
"-" TARGET_ABI_FMT_lx
4922 " %c%c%c%c %08" PRIx64
" %02x:%02x %d%s%s\n",
4923 h2g(min
), h2g(max
), flag_r
, flag_w
,
4924 flag_x
, flag_p
, offset
, dev_maj
, dev_min
, inode
,
4925 path
[0] ? " " : "", path
);
4932 #if defined(TARGET_ARM) || defined(TARGET_M68K) || defined(TARGET_UNICORE32)
4933 dprintf(fd
, "%08llx-%08llx rw-p %08llx 00:00 0 [stack]\n",
4934 (unsigned long long)ts
->info
->stack_limit
,
4935 (unsigned long long)(ts
->stack_base
+ (TARGET_PAGE_SIZE
- 1))
4937 (unsigned long long)0);
4943 static int open_self_stat(void *cpu_env
, int fd
)
4945 TaskState
*ts
= ((CPUArchState
*)cpu_env
)->opaque
;
4946 abi_ulong start_stack
= ts
->info
->start_stack
;
4949 for (i
= 0; i
< 44; i
++) {
4957 snprintf(buf
, sizeof(buf
), "%"PRId64
" ", val
);
4958 } else if (i
== 1) {
4960 snprintf(buf
, sizeof(buf
), "(%s) ", ts
->bprm
->argv
[0]);
4961 } else if (i
== 27) {
4964 snprintf(buf
, sizeof(buf
), "%"PRId64
" ", val
);
4966 /* for the rest, there is MasterCard */
4967 snprintf(buf
, sizeof(buf
), "0%c", i
== 43 ? '\n' : ' ');
4971 if (write(fd
, buf
, len
) != len
) {
4979 static int open_self_auxv(void *cpu_env
, int fd
)
4981 TaskState
*ts
= ((CPUArchState
*)cpu_env
)->opaque
;
4982 abi_ulong auxv
= ts
->info
->saved_auxv
;
4983 abi_ulong len
= ts
->info
->auxv_len
;
4987 * Auxiliary vector is stored in target process stack.
4988 * read in whole auxv vector and copy it to file
4990 ptr
= lock_user(VERIFY_READ
, auxv
, len
, 0);
4994 r
= write(fd
, ptr
, len
);
5001 lseek(fd
, 0, SEEK_SET
);
5002 unlock_user(ptr
, auxv
, len
);
5008 static int do_open(void *cpu_env
, const char *pathname
, int flags
, mode_t mode
)
5011 const char *filename
;
5012 int (*fill
)(void *cpu_env
, int fd
);
5014 const struct fake_open
*fake_open
;
5015 static const struct fake_open fakes
[] = {
5016 { "/proc/self/maps", open_self_maps
},
5017 { "/proc/self/stat", open_self_stat
},
5018 { "/proc/self/auxv", open_self_auxv
},
5022 for (fake_open
= fakes
; fake_open
->filename
; fake_open
++) {
5023 if (!strncmp(pathname
, fake_open
->filename
,
5024 strlen(fake_open
->filename
))) {
5029 if (fake_open
->filename
) {
5031 char filename
[PATH_MAX
];
5034 /* create temporary file to map stat to */
5035 tmpdir
= getenv("TMPDIR");
5038 snprintf(filename
, sizeof(filename
), "%s/qemu-open.XXXXXX", tmpdir
);
5039 fd
= mkstemp(filename
);
5045 if ((r
= fake_open
->fill(cpu_env
, fd
))) {
5049 lseek(fd
, 0, SEEK_SET
);
5054 return get_errno(open(path(pathname
), flags
, mode
));
5057 /* do_syscall() should always have a single exit point at the end so
5058 that actions, such as logging of syscall results, can be performed.
5059 All errnos that do_syscall() returns must be -TARGET_<errcode>. */
5060 abi_long
do_syscall(void *cpu_env
, int num
, abi_long arg1
,
5061 abi_long arg2
, abi_long arg3
, abi_long arg4
,
5062 abi_long arg5
, abi_long arg6
, abi_long arg7
,
5071 gemu_log("syscall %d", num
);
5074 print_syscall(num
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
5077 case TARGET_NR_exit
:
5078 #ifdef CONFIG_USE_NPTL
5079 /* In old applications this may be used to implement _exit(2).
5080 However in threaded applictions it is used for thread termination,
5081 and _exit_group is used for application termination.
5082 Do thread termination if we have more then one thread. */
5083 /* FIXME: This probably breaks if a signal arrives. We should probably
5084 be disabling signals. */
5085 if (first_cpu
->next_cpu
) {
5087 CPUArchState
**lastp
;
5093 while (p
&& p
!= (CPUArchState
*)cpu_env
) {
5094 lastp
= &p
->next_cpu
;
5097 /* If we didn't find the CPU for this thread then something is
5101 /* Remove the CPU from the list. */
5102 *lastp
= p
->next_cpu
;
5104 ts
= ((CPUArchState
*)cpu_env
)->opaque
;
5105 if (ts
->child_tidptr
) {
5106 put_user_u32(0, ts
->child_tidptr
);
5107 sys_futex(g2h(ts
->child_tidptr
), FUTEX_WAKE
, INT_MAX
,
5111 object_delete(OBJECT(ENV_GET_CPU(cpu_env
)));
5119 gdb_exit(cpu_env
, arg1
);
5121 ret
= 0; /* avoid warning */
5123 case TARGET_NR_read
:
5127 if (!(p
= lock_user(VERIFY_WRITE
, arg2
, arg3
, 0)))
5129 ret
= get_errno(read(arg1
, p
, arg3
));
5130 unlock_user(p
, arg2
, ret
);
5133 case TARGET_NR_write
:
5134 if (!(p
= lock_user(VERIFY_READ
, arg2
, arg3
, 1)))
5136 ret
= get_errno(write(arg1
, p
, arg3
));
5137 unlock_user(p
, arg2
, 0);
5139 case TARGET_NR_open
:
5140 if (!(p
= lock_user_string(arg1
)))
5142 ret
= get_errno(do_open(cpu_env
, p
,
5143 target_to_host_bitmask(arg2
, fcntl_flags_tbl
),
5145 unlock_user(p
, arg1
, 0);
5147 #if defined(TARGET_NR_openat) && defined(__NR_openat)
5148 case TARGET_NR_openat
:
5149 if (!(p
= lock_user_string(arg2
)))
5151 ret
= get_errno(sys_openat(arg1
,
5153 target_to_host_bitmask(arg3
, fcntl_flags_tbl
),
5155 unlock_user(p
, arg2
, 0);
5158 case TARGET_NR_close
:
5159 ret
= get_errno(close(arg1
));
5164 case TARGET_NR_fork
:
5165 ret
= get_errno(do_fork(cpu_env
, SIGCHLD
, 0, 0, 0, 0));
5167 #ifdef TARGET_NR_waitpid
5168 case TARGET_NR_waitpid
:
5171 ret
= get_errno(waitpid(arg1
, &status
, arg3
));
5172 if (!is_error(ret
) && arg2
&& ret
5173 && put_user_s32(host_to_target_waitstatus(status
), arg2
))
5178 #ifdef TARGET_NR_waitid
5179 case TARGET_NR_waitid
:
5183 ret
= get_errno(waitid(arg1
, arg2
, &info
, arg4
));
5184 if (!is_error(ret
) && arg3
&& info
.si_pid
!= 0) {
5185 if (!(p
= lock_user(VERIFY_WRITE
, arg3
, sizeof(target_siginfo_t
), 0)))
5187 host_to_target_siginfo(p
, &info
);
5188 unlock_user(p
, arg3
, sizeof(target_siginfo_t
));
5193 #ifdef TARGET_NR_creat /* not on alpha */
5194 case TARGET_NR_creat
:
5195 if (!(p
= lock_user_string(arg1
)))
5197 ret
= get_errno(creat(p
, arg2
));
5198 unlock_user(p
, arg1
, 0);
5201 case TARGET_NR_link
:
5204 p
= lock_user_string(arg1
);
5205 p2
= lock_user_string(arg2
);
5207 ret
= -TARGET_EFAULT
;
5209 ret
= get_errno(link(p
, p2
));
5210 unlock_user(p2
, arg2
, 0);
5211 unlock_user(p
, arg1
, 0);
5214 #if defined(TARGET_NR_linkat) && defined(__NR_linkat)
5215 case TARGET_NR_linkat
:
5220 p
= lock_user_string(arg2
);
5221 p2
= lock_user_string(arg4
);
5223 ret
= -TARGET_EFAULT
;
5225 ret
= get_errno(sys_linkat(arg1
, p
, arg3
, p2
, arg5
));
5226 unlock_user(p
, arg2
, 0);
5227 unlock_user(p2
, arg4
, 0);
5231 case TARGET_NR_unlink
:
5232 if (!(p
= lock_user_string(arg1
)))
5234 ret
= get_errno(unlink(p
));
5235 unlock_user(p
, arg1
, 0);
5237 #if defined(TARGET_NR_unlinkat) && defined(__NR_unlinkat)
5238 case TARGET_NR_unlinkat
:
5239 if (!(p
= lock_user_string(arg2
)))
5241 ret
= get_errno(sys_unlinkat(arg1
, p
, arg3
));
5242 unlock_user(p
, arg2
, 0);
5245 case TARGET_NR_execve
:
5247 char **argp
, **envp
;
5250 abi_ulong guest_argp
;
5251 abi_ulong guest_envp
;
5258 for (gp
= guest_argp
; gp
; gp
+= sizeof(abi_ulong
)) {
5259 if (get_user_ual(addr
, gp
))
5267 for (gp
= guest_envp
; gp
; gp
+= sizeof(abi_ulong
)) {
5268 if (get_user_ual(addr
, gp
))
5275 argp
= alloca((argc
+ 1) * sizeof(void *));
5276 envp
= alloca((envc
+ 1) * sizeof(void *));
5278 for (gp
= guest_argp
, q
= argp
; gp
;
5279 gp
+= sizeof(abi_ulong
), q
++) {
5280 if (get_user_ual(addr
, gp
))
5284 if (!(*q
= lock_user_string(addr
)))
5286 total_size
+= strlen(*q
) + 1;
5290 for (gp
= guest_envp
, q
= envp
; gp
;
5291 gp
+= sizeof(abi_ulong
), q
++) {
5292 if (get_user_ual(addr
, gp
))
5296 if (!(*q
= lock_user_string(addr
)))
5298 total_size
+= strlen(*q
) + 1;
5302 /* This case will not be caught by the host's execve() if its
5303 page size is bigger than the target's. */
5304 if (total_size
> MAX_ARG_PAGES
* TARGET_PAGE_SIZE
) {
5305 ret
= -TARGET_E2BIG
;
5308 if (!(p
= lock_user_string(arg1
)))
5310 ret
= get_errno(execve(p
, argp
, envp
));
5311 unlock_user(p
, arg1
, 0);
5316 ret
= -TARGET_EFAULT
;
5319 for (gp
= guest_argp
, q
= argp
; *q
;
5320 gp
+= sizeof(abi_ulong
), q
++) {
5321 if (get_user_ual(addr
, gp
)
5324 unlock_user(*q
, addr
, 0);
5326 for (gp
= guest_envp
, q
= envp
; *q
;
5327 gp
+= sizeof(abi_ulong
), q
++) {
5328 if (get_user_ual(addr
, gp
)
5331 unlock_user(*q
, addr
, 0);
5335 case TARGET_NR_chdir
:
5336 if (!(p
= lock_user_string(arg1
)))
5338 ret
= get_errno(chdir(p
));
5339 unlock_user(p
, arg1
, 0);
5341 #ifdef TARGET_NR_time
5342 case TARGET_NR_time
:
5345 ret
= get_errno(time(&host_time
));
5348 && put_user_sal(host_time
, arg1
))
5353 case TARGET_NR_mknod
:
5354 if (!(p
= lock_user_string(arg1
)))
5356 ret
= get_errno(mknod(p
, arg2
, arg3
));
5357 unlock_user(p
, arg1
, 0);
5359 #if defined(TARGET_NR_mknodat) && defined(__NR_mknodat)
5360 case TARGET_NR_mknodat
:
5361 if (!(p
= lock_user_string(arg2
)))
5363 ret
= get_errno(sys_mknodat(arg1
, p
, arg3
, arg4
));
5364 unlock_user(p
, arg2
, 0);
5367 case TARGET_NR_chmod
:
5368 if (!(p
= lock_user_string(arg1
)))
5370 ret
= get_errno(chmod(p
, arg2
));
5371 unlock_user(p
, arg1
, 0);
5373 #ifdef TARGET_NR_break
5374 case TARGET_NR_break
:
5377 #ifdef TARGET_NR_oldstat
5378 case TARGET_NR_oldstat
:
5381 case TARGET_NR_lseek
:
5382 ret
= get_errno(lseek(arg1
, arg2
, arg3
));
5384 #if defined(TARGET_NR_getxpid) && defined(TARGET_ALPHA)
5385 /* Alpha specific */
5386 case TARGET_NR_getxpid
:
5387 ((CPUAlphaState
*)cpu_env
)->ir
[IR_A4
] = getppid();
5388 ret
= get_errno(getpid());
5391 #ifdef TARGET_NR_getpid
5392 case TARGET_NR_getpid
:
5393 ret
= get_errno(getpid());
5396 case TARGET_NR_mount
:
5398 /* need to look at the data field */
5400 p
= lock_user_string(arg1
);
5401 p2
= lock_user_string(arg2
);
5402 p3
= lock_user_string(arg3
);
5403 if (!p
|| !p2
|| !p3
)
5404 ret
= -TARGET_EFAULT
;
5406 /* FIXME - arg5 should be locked, but it isn't clear how to
5407 * do that since it's not guaranteed to be a NULL-terminated
5411 ret
= get_errno(mount(p
, p2
, p3
, (unsigned long)arg4
, NULL
));
5413 ret
= get_errno(mount(p
, p2
, p3
, (unsigned long)arg4
, g2h(arg5
)));
5415 unlock_user(p
, arg1
, 0);
5416 unlock_user(p2
, arg2
, 0);
5417 unlock_user(p3
, arg3
, 0);
5420 #ifdef TARGET_NR_umount
5421 case TARGET_NR_umount
:
5422 if (!(p
= lock_user_string(arg1
)))
5424 ret
= get_errno(umount(p
));
5425 unlock_user(p
, arg1
, 0);
5428 #ifdef TARGET_NR_stime /* not on alpha */
5429 case TARGET_NR_stime
:
5432 if (get_user_sal(host_time
, arg1
))
5434 ret
= get_errno(stime(&host_time
));
5438 case TARGET_NR_ptrace
:
5440 #ifdef TARGET_NR_alarm /* not on alpha */
5441 case TARGET_NR_alarm
:
5445 #ifdef TARGET_NR_oldfstat
5446 case TARGET_NR_oldfstat
:
5449 #ifdef TARGET_NR_pause /* not on alpha */
5450 case TARGET_NR_pause
:
5451 ret
= get_errno(pause());
5454 #ifdef TARGET_NR_utime
5455 case TARGET_NR_utime
:
5457 struct utimbuf tbuf
, *host_tbuf
;
5458 struct target_utimbuf
*target_tbuf
;
5460 if (!lock_user_struct(VERIFY_READ
, target_tbuf
, arg2
, 1))
5462 tbuf
.actime
= tswapal(target_tbuf
->actime
);
5463 tbuf
.modtime
= tswapal(target_tbuf
->modtime
);
5464 unlock_user_struct(target_tbuf
, arg2
, 0);
5469 if (!(p
= lock_user_string(arg1
)))
5471 ret
= get_errno(utime(p
, host_tbuf
));
5472 unlock_user(p
, arg1
, 0);
5476 case TARGET_NR_utimes
:
5478 struct timeval
*tvp
, tv
[2];
5480 if (copy_from_user_timeval(&tv
[0], arg2
)
5481 || copy_from_user_timeval(&tv
[1],
5482 arg2
+ sizeof(struct target_timeval
)))
5488 if (!(p
= lock_user_string(arg1
)))
5490 ret
= get_errno(utimes(p
, tvp
));
5491 unlock_user(p
, arg1
, 0);
5494 #if defined(TARGET_NR_futimesat) && defined(__NR_futimesat)
5495 case TARGET_NR_futimesat
:
5497 struct timeval
*tvp
, tv
[2];
5499 if (copy_from_user_timeval(&tv
[0], arg3
)
5500 || copy_from_user_timeval(&tv
[1],
5501 arg3
+ sizeof(struct target_timeval
)))
5507 if (!(p
= lock_user_string(arg2
)))
5509 ret
= get_errno(sys_futimesat(arg1
, path(p
), tvp
));
5510 unlock_user(p
, arg2
, 0);
5514 #ifdef TARGET_NR_stty
5515 case TARGET_NR_stty
:
5518 #ifdef TARGET_NR_gtty
5519 case TARGET_NR_gtty
:
5522 case TARGET_NR_access
:
5523 if (!(p
= lock_user_string(arg1
)))
5525 ret
= get_errno(access(path(p
), arg2
));
5526 unlock_user(p
, arg1
, 0);
5528 #if defined(TARGET_NR_faccessat) && defined(__NR_faccessat)
5529 case TARGET_NR_faccessat
:
5530 if (!(p
= lock_user_string(arg2
)))
5532 ret
= get_errno(sys_faccessat(arg1
, p
, arg3
));
5533 unlock_user(p
, arg2
, 0);
5536 #ifdef TARGET_NR_nice /* not on alpha */
5537 case TARGET_NR_nice
:
5538 ret
= get_errno(nice(arg1
));
5541 #ifdef TARGET_NR_ftime
5542 case TARGET_NR_ftime
:
5545 case TARGET_NR_sync
:
5549 case TARGET_NR_kill
:
5550 ret
= get_errno(kill(arg1
, target_to_host_signal(arg2
)));
5552 case TARGET_NR_rename
:
5555 p
= lock_user_string(arg1
);
5556 p2
= lock_user_string(arg2
);
5558 ret
= -TARGET_EFAULT
;
5560 ret
= get_errno(rename(p
, p2
));
5561 unlock_user(p2
, arg2
, 0);
5562 unlock_user(p
, arg1
, 0);
5565 #if defined(TARGET_NR_renameat) && defined(__NR_renameat)
5566 case TARGET_NR_renameat
:
5569 p
= lock_user_string(arg2
);
5570 p2
= lock_user_string(arg4
);
5572 ret
= -TARGET_EFAULT
;
5574 ret
= get_errno(sys_renameat(arg1
, p
, arg3
, p2
));
5575 unlock_user(p2
, arg4
, 0);
5576 unlock_user(p
, arg2
, 0);
5580 case TARGET_NR_mkdir
:
5581 if (!(p
= lock_user_string(arg1
)))
5583 ret
= get_errno(mkdir(p
, arg2
));
5584 unlock_user(p
, arg1
, 0);
5586 #if defined(TARGET_NR_mkdirat) && defined(__NR_mkdirat)
5587 case TARGET_NR_mkdirat
:
5588 if (!(p
= lock_user_string(arg2
)))
5590 ret
= get_errno(sys_mkdirat(arg1
, p
, arg3
));
5591 unlock_user(p
, arg2
, 0);
5594 case TARGET_NR_rmdir
:
5595 if (!(p
= lock_user_string(arg1
)))
5597 ret
= get_errno(rmdir(p
));
5598 unlock_user(p
, arg1
, 0);
5601 ret
= get_errno(dup(arg1
));
5603 case TARGET_NR_pipe
:
5604 ret
= do_pipe(cpu_env
, arg1
, 0, 0);
5606 #ifdef TARGET_NR_pipe2
5607 case TARGET_NR_pipe2
:
5608 ret
= do_pipe(cpu_env
, arg1
,
5609 target_to_host_bitmask(arg2
, fcntl_flags_tbl
), 1);
5612 case TARGET_NR_times
:
5614 struct target_tms
*tmsp
;
5616 ret
= get_errno(times(&tms
));
5618 tmsp
= lock_user(VERIFY_WRITE
, arg1
, sizeof(struct target_tms
), 0);
5621 tmsp
->tms_utime
= tswapal(host_to_target_clock_t(tms
.tms_utime
));
5622 tmsp
->tms_stime
= tswapal(host_to_target_clock_t(tms
.tms_stime
));
5623 tmsp
->tms_cutime
= tswapal(host_to_target_clock_t(tms
.tms_cutime
));
5624 tmsp
->tms_cstime
= tswapal(host_to_target_clock_t(tms
.tms_cstime
));
5627 ret
= host_to_target_clock_t(ret
);
5630 #ifdef TARGET_NR_prof
5631 case TARGET_NR_prof
:
5634 #ifdef TARGET_NR_signal
5635 case TARGET_NR_signal
:
5638 case TARGET_NR_acct
:
5640 ret
= get_errno(acct(NULL
));
5642 if (!(p
= lock_user_string(arg1
)))
5644 ret
= get_errno(acct(path(p
)));
5645 unlock_user(p
, arg1
, 0);
5648 #ifdef TARGET_NR_umount2 /* not on alpha */
5649 case TARGET_NR_umount2
:
5650 if (!(p
= lock_user_string(arg1
)))
5652 ret
= get_errno(umount2(p
, arg2
));
5653 unlock_user(p
, arg1
, 0);
5656 #ifdef TARGET_NR_lock
5657 case TARGET_NR_lock
:
5660 case TARGET_NR_ioctl
:
5661 ret
= do_ioctl(arg1
, arg2
, arg3
);
5663 case TARGET_NR_fcntl
:
5664 ret
= do_fcntl(arg1
, arg2
, arg3
);
5666 #ifdef TARGET_NR_mpx
5670 case TARGET_NR_setpgid
:
5671 ret
= get_errno(setpgid(arg1
, arg2
));
5673 #ifdef TARGET_NR_ulimit
5674 case TARGET_NR_ulimit
:
5677 #ifdef TARGET_NR_oldolduname
5678 case TARGET_NR_oldolduname
:
5681 case TARGET_NR_umask
:
5682 ret
= get_errno(umask(arg1
));
5684 case TARGET_NR_chroot
:
5685 if (!(p
= lock_user_string(arg1
)))
5687 ret
= get_errno(chroot(p
));
5688 unlock_user(p
, arg1
, 0);
5690 case TARGET_NR_ustat
:
5692 case TARGET_NR_dup2
:
5693 ret
= get_errno(dup2(arg1
, arg2
));
5695 #if defined(CONFIG_DUP3) && defined(TARGET_NR_dup3)
5696 case TARGET_NR_dup3
:
5697 ret
= get_errno(dup3(arg1
, arg2
, arg3
));
5700 #ifdef TARGET_NR_getppid /* not on alpha */
5701 case TARGET_NR_getppid
:
5702 ret
= get_errno(getppid());
5705 case TARGET_NR_getpgrp
:
5706 ret
= get_errno(getpgrp());
5708 case TARGET_NR_setsid
:
5709 ret
= get_errno(setsid());
5711 #ifdef TARGET_NR_sigaction
5712 case TARGET_NR_sigaction
:
5714 #if defined(TARGET_ALPHA)
5715 struct target_sigaction act
, oact
, *pact
= 0;
5716 struct target_old_sigaction
*old_act
;
5718 if (!lock_user_struct(VERIFY_READ
, old_act
, arg2
, 1))
5720 act
._sa_handler
= old_act
->_sa_handler
;
5721 target_siginitset(&act
.sa_mask
, old_act
->sa_mask
);
5722 act
.sa_flags
= old_act
->sa_flags
;
5723 act
.sa_restorer
= 0;
5724 unlock_user_struct(old_act
, arg2
, 0);
5727 ret
= get_errno(do_sigaction(arg1
, pact
, &oact
));
5728 if (!is_error(ret
) && arg3
) {
5729 if (!lock_user_struct(VERIFY_WRITE
, old_act
, arg3
, 0))
5731 old_act
->_sa_handler
= oact
._sa_handler
;
5732 old_act
->sa_mask
= oact
.sa_mask
.sig
[0];
5733 old_act
->sa_flags
= oact
.sa_flags
;
5734 unlock_user_struct(old_act
, arg3
, 1);
5736 #elif defined(TARGET_MIPS)
5737 struct target_sigaction act
, oact
, *pact
, *old_act
;
5740 if (!lock_user_struct(VERIFY_READ
, old_act
, arg2
, 1))
5742 act
._sa_handler
= old_act
->_sa_handler
;
5743 target_siginitset(&act
.sa_mask
, old_act
->sa_mask
.sig
[0]);
5744 act
.sa_flags
= old_act
->sa_flags
;
5745 unlock_user_struct(old_act
, arg2
, 0);
5751 ret
= get_errno(do_sigaction(arg1
, pact
, &oact
));
5753 if (!is_error(ret
) && arg3
) {
5754 if (!lock_user_struct(VERIFY_WRITE
, old_act
, arg3
, 0))
5756 old_act
->_sa_handler
= oact
._sa_handler
;
5757 old_act
->sa_flags
= oact
.sa_flags
;
5758 old_act
->sa_mask
.sig
[0] = oact
.sa_mask
.sig
[0];
5759 old_act
->sa_mask
.sig
[1] = 0;
5760 old_act
->sa_mask
.sig
[2] = 0;
5761 old_act
->sa_mask
.sig
[3] = 0;
5762 unlock_user_struct(old_act
, arg3
, 1);
5765 struct target_old_sigaction
*old_act
;
5766 struct target_sigaction act
, oact
, *pact
;
5768 if (!lock_user_struct(VERIFY_READ
, old_act
, arg2
, 1))
5770 act
._sa_handler
= old_act
->_sa_handler
;
5771 target_siginitset(&act
.sa_mask
, old_act
->sa_mask
);
5772 act
.sa_flags
= old_act
->sa_flags
;
5773 act
.sa_restorer
= old_act
->sa_restorer
;
5774 unlock_user_struct(old_act
, arg2
, 0);
5779 ret
= get_errno(do_sigaction(arg1
, pact
, &oact
));
5780 if (!is_error(ret
) && arg3
) {
5781 if (!lock_user_struct(VERIFY_WRITE
, old_act
, arg3
, 0))
5783 old_act
->_sa_handler
= oact
._sa_handler
;
5784 old_act
->sa_mask
= oact
.sa_mask
.sig
[0];
5785 old_act
->sa_flags
= oact
.sa_flags
;
5786 old_act
->sa_restorer
= oact
.sa_restorer
;
5787 unlock_user_struct(old_act
, arg3
, 1);
5793 case TARGET_NR_rt_sigaction
:
5795 #if defined(TARGET_ALPHA)
5796 struct target_sigaction act
, oact
, *pact
= 0;
5797 struct target_rt_sigaction
*rt_act
;
5798 /* ??? arg4 == sizeof(sigset_t). */
5800 if (!lock_user_struct(VERIFY_READ
, rt_act
, arg2
, 1))
5802 act
._sa_handler
= rt_act
->_sa_handler
;
5803 act
.sa_mask
= rt_act
->sa_mask
;
5804 act
.sa_flags
= rt_act
->sa_flags
;
5805 act
.sa_restorer
= arg5
;
5806 unlock_user_struct(rt_act
, arg2
, 0);
5809 ret
= get_errno(do_sigaction(arg1
, pact
, &oact
));
5810 if (!is_error(ret
) && arg3
) {
5811 if (!lock_user_struct(VERIFY_WRITE
, rt_act
, arg3
, 0))
5813 rt_act
->_sa_handler
= oact
._sa_handler
;
5814 rt_act
->sa_mask
= oact
.sa_mask
;
5815 rt_act
->sa_flags
= oact
.sa_flags
;
5816 unlock_user_struct(rt_act
, arg3
, 1);
5819 struct target_sigaction
*act
;
5820 struct target_sigaction
*oact
;
5823 if (!lock_user_struct(VERIFY_READ
, act
, arg2
, 1))
5828 if (!lock_user_struct(VERIFY_WRITE
, oact
, arg3
, 0)) {
5829 ret
= -TARGET_EFAULT
;
5830 goto rt_sigaction_fail
;
5834 ret
= get_errno(do_sigaction(arg1
, act
, oact
));
5837 unlock_user_struct(act
, arg2
, 0);
5839 unlock_user_struct(oact
, arg3
, 1);
5843 #ifdef TARGET_NR_sgetmask /* not on alpha */
5844 case TARGET_NR_sgetmask
:
5847 abi_ulong target_set
;
5848 sigprocmask(0, NULL
, &cur_set
);
5849 host_to_target_old_sigset(&target_set
, &cur_set
);
5854 #ifdef TARGET_NR_ssetmask /* not on alpha */
5855 case TARGET_NR_ssetmask
:
5857 sigset_t set
, oset
, cur_set
;
5858 abi_ulong target_set
= arg1
;
5859 sigprocmask(0, NULL
, &cur_set
);
5860 target_to_host_old_sigset(&set
, &target_set
);
5861 sigorset(&set
, &set
, &cur_set
);
5862 sigprocmask(SIG_SETMASK
, &set
, &oset
);
5863 host_to_target_old_sigset(&target_set
, &oset
);
5868 #ifdef TARGET_NR_sigprocmask
5869 case TARGET_NR_sigprocmask
:
5871 #if defined(TARGET_ALPHA)
5872 sigset_t set
, oldset
;
5877 case TARGET_SIG_BLOCK
:
5880 case TARGET_SIG_UNBLOCK
:
5883 case TARGET_SIG_SETMASK
:
5887 ret
= -TARGET_EINVAL
;
5891 target_to_host_old_sigset(&set
, &mask
);
5893 ret
= get_errno(sigprocmask(how
, &set
, &oldset
));
5894 if (!is_error(ret
)) {
5895 host_to_target_old_sigset(&mask
, &oldset
);
5897 ((CPUAlphaState
*)cpu_env
)->ir
[IR_V0
] = 0; /* force no error */
5900 sigset_t set
, oldset
, *set_ptr
;
5905 case TARGET_SIG_BLOCK
:
5908 case TARGET_SIG_UNBLOCK
:
5911 case TARGET_SIG_SETMASK
:
5915 ret
= -TARGET_EINVAL
;
5918 if (!(p
= lock_user(VERIFY_READ
, arg2
, sizeof(target_sigset_t
), 1)))
5920 target_to_host_old_sigset(&set
, p
);
5921 unlock_user(p
, arg2
, 0);
5927 ret
= get_errno(sigprocmask(how
, set_ptr
, &oldset
));
5928 if (!is_error(ret
) && arg3
) {
5929 if (!(p
= lock_user(VERIFY_WRITE
, arg3
, sizeof(target_sigset_t
), 0)))
5931 host_to_target_old_sigset(p
, &oldset
);
5932 unlock_user(p
, arg3
, sizeof(target_sigset_t
));
5938 case TARGET_NR_rt_sigprocmask
:
5941 sigset_t set
, oldset
, *set_ptr
;
5945 case TARGET_SIG_BLOCK
:
5948 case TARGET_SIG_UNBLOCK
:
5951 case TARGET_SIG_SETMASK
:
5955 ret
= -TARGET_EINVAL
;
5958 if (!(p
= lock_user(VERIFY_READ
, arg2
, sizeof(target_sigset_t
), 1)))
5960 target_to_host_sigset(&set
, p
);
5961 unlock_user(p
, arg2
, 0);
5967 ret
= get_errno(sigprocmask(how
, set_ptr
, &oldset
));
5968 if (!is_error(ret
) && arg3
) {
5969 if (!(p
= lock_user(VERIFY_WRITE
, arg3
, sizeof(target_sigset_t
), 0)))
5971 host_to_target_sigset(p
, &oldset
);
5972 unlock_user(p
, arg3
, sizeof(target_sigset_t
));
5976 #ifdef TARGET_NR_sigpending
5977 case TARGET_NR_sigpending
:
5980 ret
= get_errno(sigpending(&set
));
5981 if (!is_error(ret
)) {
5982 if (!(p
= lock_user(VERIFY_WRITE
, arg1
, sizeof(target_sigset_t
), 0)))
5984 host_to_target_old_sigset(p
, &set
);
5985 unlock_user(p
, arg1
, sizeof(target_sigset_t
));
5990 case TARGET_NR_rt_sigpending
:
5993 ret
= get_errno(sigpending(&set
));
5994 if (!is_error(ret
)) {
5995 if (!(p
= lock_user(VERIFY_WRITE
, arg1
, sizeof(target_sigset_t
), 0)))
5997 host_to_target_sigset(p
, &set
);
5998 unlock_user(p
, arg1
, sizeof(target_sigset_t
));
6002 #ifdef TARGET_NR_sigsuspend
6003 case TARGET_NR_sigsuspend
:
6006 #if defined(TARGET_ALPHA)
6007 abi_ulong mask
= arg1
;
6008 target_to_host_old_sigset(&set
, &mask
);
6010 if (!(p
= lock_user(VERIFY_READ
, arg1
, sizeof(target_sigset_t
), 1)))
6012 target_to_host_old_sigset(&set
, p
);
6013 unlock_user(p
, arg1
, 0);
6015 ret
= get_errno(sigsuspend(&set
));
6019 case TARGET_NR_rt_sigsuspend
:
6022 if (!(p
= lock_user(VERIFY_READ
, arg1
, sizeof(target_sigset_t
), 1)))
6024 target_to_host_sigset(&set
, p
);
6025 unlock_user(p
, arg1
, 0);
6026 ret
= get_errno(sigsuspend(&set
));
6029 case TARGET_NR_rt_sigtimedwait
:
6032 struct timespec uts
, *puts
;
6035 if (!(p
= lock_user(VERIFY_READ
, arg1
, sizeof(target_sigset_t
), 1)))
6037 target_to_host_sigset(&set
, p
);
6038 unlock_user(p
, arg1
, 0);
6041 target_to_host_timespec(puts
, arg3
);
6045 ret
= get_errno(sigtimedwait(&set
, &uinfo
, puts
));
6046 if (!is_error(ret
) && arg2
) {
6047 if (!(p
= lock_user(VERIFY_WRITE
, arg2
, sizeof(target_siginfo_t
), 0)))
6049 host_to_target_siginfo(p
, &uinfo
);
6050 unlock_user(p
, arg2
, sizeof(target_siginfo_t
));
6054 case TARGET_NR_rt_sigqueueinfo
:
6057 if (!(p
= lock_user(VERIFY_READ
, arg3
, sizeof(target_sigset_t
), 1)))
6059 target_to_host_siginfo(&uinfo
, p
);
6060 unlock_user(p
, arg1
, 0);
6061 ret
= get_errno(sys_rt_sigqueueinfo(arg1
, arg2
, &uinfo
));
6064 #ifdef TARGET_NR_sigreturn
6065 case TARGET_NR_sigreturn
:
6066 /* NOTE: ret is eax, so not transcoding must be done */
6067 ret
= do_sigreturn(cpu_env
);
6070 case TARGET_NR_rt_sigreturn
:
6071 /* NOTE: ret is eax, so not transcoding must be done */
6072 ret
= do_rt_sigreturn(cpu_env
);
6074 case TARGET_NR_sethostname
:
6075 if (!(p
= lock_user_string(arg1
)))
6077 ret
= get_errno(sethostname(p
, arg2
));
6078 unlock_user(p
, arg1
, 0);
6080 case TARGET_NR_setrlimit
:
6082 int resource
= target_to_host_resource(arg1
);
6083 struct target_rlimit
*target_rlim
;
6085 if (!lock_user_struct(VERIFY_READ
, target_rlim
, arg2
, 1))
6087 rlim
.rlim_cur
= target_to_host_rlim(target_rlim
->rlim_cur
);
6088 rlim
.rlim_max
= target_to_host_rlim(target_rlim
->rlim_max
);
6089 unlock_user_struct(target_rlim
, arg2
, 0);
6090 ret
= get_errno(setrlimit(resource
, &rlim
));
6093 case TARGET_NR_getrlimit
:
6095 int resource
= target_to_host_resource(arg1
);
6096 struct target_rlimit
*target_rlim
;
6099 ret
= get_errno(getrlimit(resource
, &rlim
));
6100 if (!is_error(ret
)) {
6101 if (!lock_user_struct(VERIFY_WRITE
, target_rlim
, arg2
, 0))
6103 target_rlim
->rlim_cur
= host_to_target_rlim(rlim
.rlim_cur
);
6104 target_rlim
->rlim_max
= host_to_target_rlim(rlim
.rlim_max
);
6105 unlock_user_struct(target_rlim
, arg2
, 1);
6109 case TARGET_NR_getrusage
:
6111 struct rusage rusage
;
6112 ret
= get_errno(getrusage(arg1
, &rusage
));
6113 if (!is_error(ret
)) {
6114 host_to_target_rusage(arg2
, &rusage
);
6118 case TARGET_NR_gettimeofday
:
6121 ret
= get_errno(gettimeofday(&tv
, NULL
));
6122 if (!is_error(ret
)) {
6123 if (copy_to_user_timeval(arg1
, &tv
))
6128 case TARGET_NR_settimeofday
:
6131 if (copy_from_user_timeval(&tv
, arg1
))
6133 ret
= get_errno(settimeofday(&tv
, NULL
));
6136 #if defined(TARGET_NR_select) && !defined(TARGET_S390X) && !defined(TARGET_S390)
6137 case TARGET_NR_select
:
6139 struct target_sel_arg_struct
*sel
;
6140 abi_ulong inp
, outp
, exp
, tvp
;
6143 if (!lock_user_struct(VERIFY_READ
, sel
, arg1
, 1))
6145 nsel
= tswapal(sel
->n
);
6146 inp
= tswapal(sel
->inp
);
6147 outp
= tswapal(sel
->outp
);
6148 exp
= tswapal(sel
->exp
);
6149 tvp
= tswapal(sel
->tvp
);
6150 unlock_user_struct(sel
, arg1
, 0);
6151 ret
= do_select(nsel
, inp
, outp
, exp
, tvp
);
6155 #ifdef TARGET_NR_pselect6
6156 case TARGET_NR_pselect6
:
6158 abi_long rfd_addr
, wfd_addr
, efd_addr
, n
, ts_addr
;
6159 fd_set rfds
, wfds
, efds
;
6160 fd_set
*rfds_ptr
, *wfds_ptr
, *efds_ptr
;
6161 struct timespec ts
, *ts_ptr
;
6164 * The 6th arg is actually two args smashed together,
6165 * so we cannot use the C library.
6173 abi_ulong arg_sigset
, arg_sigsize
, *arg7
;
6174 target_sigset_t
*target_sigset
;
6182 ret
= copy_from_user_fdset_ptr(&rfds
, &rfds_ptr
, rfd_addr
, n
);
6186 ret
= copy_from_user_fdset_ptr(&wfds
, &wfds_ptr
, wfd_addr
, n
);
6190 ret
= copy_from_user_fdset_ptr(&efds
, &efds_ptr
, efd_addr
, n
);
6196 * This takes a timespec, and not a timeval, so we cannot
6197 * use the do_select() helper ...
6200 if (target_to_host_timespec(&ts
, ts_addr
)) {
6208 /* Extract the two packed args for the sigset */
6211 sig
.size
= _NSIG
/ 8;
6213 arg7
= lock_user(VERIFY_READ
, arg6
, sizeof(*arg7
) * 2, 1);
6217 arg_sigset
= tswapal(arg7
[0]);
6218 arg_sigsize
= tswapal(arg7
[1]);
6219 unlock_user(arg7
, arg6
, 0);
6223 if (arg_sigsize
!= sizeof(*target_sigset
)) {
6224 /* Like the kernel, we enforce correct size sigsets */
6225 ret
= -TARGET_EINVAL
;
6228 target_sigset
= lock_user(VERIFY_READ
, arg_sigset
,
6229 sizeof(*target_sigset
), 1);
6230 if (!target_sigset
) {
6233 target_to_host_sigset(&set
, target_sigset
);
6234 unlock_user(target_sigset
, arg_sigset
, 0);
6242 ret
= get_errno(sys_pselect6(n
, rfds_ptr
, wfds_ptr
, efds_ptr
,
6245 if (!is_error(ret
)) {
6246 if (rfd_addr
&& copy_to_user_fdset(rfd_addr
, &rfds
, n
))
6248 if (wfd_addr
&& copy_to_user_fdset(wfd_addr
, &wfds
, n
))
6250 if (efd_addr
&& copy_to_user_fdset(efd_addr
, &efds
, n
))
6253 if (ts_addr
&& host_to_target_timespec(ts_addr
, &ts
))
6259 case TARGET_NR_symlink
:
6262 p
= lock_user_string(arg1
);
6263 p2
= lock_user_string(arg2
);
6265 ret
= -TARGET_EFAULT
;
6267 ret
= get_errno(symlink(p
, p2
));
6268 unlock_user(p2
, arg2
, 0);
6269 unlock_user(p
, arg1
, 0);
6272 #if defined(TARGET_NR_symlinkat) && defined(__NR_symlinkat)
6273 case TARGET_NR_symlinkat
:
6276 p
= lock_user_string(arg1
);
6277 p2
= lock_user_string(arg3
);
6279 ret
= -TARGET_EFAULT
;
6281 ret
= get_errno(sys_symlinkat(p
, arg2
, p2
));
6282 unlock_user(p2
, arg3
, 0);
6283 unlock_user(p
, arg1
, 0);
6287 #ifdef TARGET_NR_oldlstat
6288 case TARGET_NR_oldlstat
:
6291 case TARGET_NR_readlink
:
6294 p
= lock_user_string(arg1
);
6295 p2
= lock_user(VERIFY_WRITE
, arg2
, arg3
, 0);
6297 ret
= -TARGET_EFAULT
;
6299 if (strncmp((const char *)p
, "/proc/self/exe", 14) == 0) {
6300 char real
[PATH_MAX
];
6301 temp
= realpath(exec_path
,real
);
6302 ret
= (temp
==NULL
) ? get_errno(-1) : strlen(real
) ;
6303 snprintf((char *)p2
, arg3
, "%s", real
);
6306 ret
= get_errno(readlink(path(p
), p2
, arg3
));
6308 unlock_user(p2
, arg2
, ret
);
6309 unlock_user(p
, arg1
, 0);
6312 #if defined(TARGET_NR_readlinkat) && defined(__NR_readlinkat)
6313 case TARGET_NR_readlinkat
:
6316 p
= lock_user_string(arg2
);
6317 p2
= lock_user(VERIFY_WRITE
, arg3
, arg4
, 0);
6319 ret
= -TARGET_EFAULT
;
6321 ret
= get_errno(sys_readlinkat(arg1
, path(p
), p2
, arg4
));
6322 unlock_user(p2
, arg3
, ret
);
6323 unlock_user(p
, arg2
, 0);
6327 #ifdef TARGET_NR_uselib
6328 case TARGET_NR_uselib
:
6331 #ifdef TARGET_NR_swapon
6332 case TARGET_NR_swapon
:
6333 if (!(p
= lock_user_string(arg1
)))
6335 ret
= get_errno(swapon(p
, arg2
));
6336 unlock_user(p
, arg1
, 0);
6339 case TARGET_NR_reboot
:
6340 if (!(p
= lock_user_string(arg4
)))
6342 ret
= reboot(arg1
, arg2
, arg3
, p
);
6343 unlock_user(p
, arg4
, 0);
6345 #ifdef TARGET_NR_readdir
6346 case TARGET_NR_readdir
:
6349 #ifdef TARGET_NR_mmap
6350 case TARGET_NR_mmap
:
6351 #if (defined(TARGET_I386) && defined(TARGET_ABI32)) || defined(TARGET_ARM) || \
6352 defined(TARGET_M68K) || defined(TARGET_CRIS) || defined(TARGET_MICROBLAZE) \
6353 || defined(TARGET_S390X)
6356 abi_ulong v1
, v2
, v3
, v4
, v5
, v6
;
6357 if (!(v
= lock_user(VERIFY_READ
, arg1
, 6 * sizeof(abi_ulong
), 1)))
6365 unlock_user(v
, arg1
, 0);
6366 ret
= get_errno(target_mmap(v1
, v2
, v3
,
6367 target_to_host_bitmask(v4
, mmap_flags_tbl
),
6371 ret
= get_errno(target_mmap(arg1
, arg2
, arg3
,
6372 target_to_host_bitmask(arg4
, mmap_flags_tbl
),
6378 #ifdef TARGET_NR_mmap2
6379 case TARGET_NR_mmap2
:
6381 #define MMAP_SHIFT 12
6383 ret
= get_errno(target_mmap(arg1
, arg2
, arg3
,
6384 target_to_host_bitmask(arg4
, mmap_flags_tbl
),
6386 arg6
<< MMAP_SHIFT
));
6389 case TARGET_NR_munmap
:
6390 ret
= get_errno(target_munmap(arg1
, arg2
));
6392 case TARGET_NR_mprotect
:
6394 TaskState
*ts
= ((CPUArchState
*)cpu_env
)->opaque
;
6395 /* Special hack to detect libc making the stack executable. */
6396 if ((arg3
& PROT_GROWSDOWN
)
6397 && arg1
>= ts
->info
->stack_limit
6398 && arg1
<= ts
->info
->start_stack
) {
6399 arg3
&= ~PROT_GROWSDOWN
;
6400 arg2
= arg2
+ arg1
- ts
->info
->stack_limit
;
6401 arg1
= ts
->info
->stack_limit
;
6404 ret
= get_errno(target_mprotect(arg1
, arg2
, arg3
));
6406 #ifdef TARGET_NR_mremap
6407 case TARGET_NR_mremap
:
6408 ret
= get_errno(target_mremap(arg1
, arg2
, arg3
, arg4
, arg5
));
6411 /* ??? msync/mlock/munlock are broken for softmmu. */
6412 #ifdef TARGET_NR_msync
6413 case TARGET_NR_msync
:
6414 ret
= get_errno(msync(g2h(arg1
), arg2
, arg3
));
6417 #ifdef TARGET_NR_mlock
6418 case TARGET_NR_mlock
:
6419 ret
= get_errno(mlock(g2h(arg1
), arg2
));
6422 #ifdef TARGET_NR_munlock
6423 case TARGET_NR_munlock
:
6424 ret
= get_errno(munlock(g2h(arg1
), arg2
));
6427 #ifdef TARGET_NR_mlockall
6428 case TARGET_NR_mlockall
:
6429 ret
= get_errno(mlockall(arg1
));
6432 #ifdef TARGET_NR_munlockall
6433 case TARGET_NR_munlockall
:
6434 ret
= get_errno(munlockall());
6437 case TARGET_NR_truncate
:
6438 if (!(p
= lock_user_string(arg1
)))
6440 ret
= get_errno(truncate(p
, arg2
));
6441 unlock_user(p
, arg1
, 0);
6443 case TARGET_NR_ftruncate
:
6444 ret
= get_errno(ftruncate(arg1
, arg2
));
6446 case TARGET_NR_fchmod
:
6447 ret
= get_errno(fchmod(arg1
, arg2
));
6449 #if defined(TARGET_NR_fchmodat) && defined(__NR_fchmodat)
6450 case TARGET_NR_fchmodat
:
6451 if (!(p
= lock_user_string(arg2
)))
6453 ret
= get_errno(sys_fchmodat(arg1
, p
, arg3
));
6454 unlock_user(p
, arg2
, 0);
6457 case TARGET_NR_getpriority
:
6458 /* Note that negative values are valid for getpriority, so we must
6459 differentiate based on errno settings. */
6461 ret
= getpriority(arg1
, arg2
);
6462 if (ret
== -1 && errno
!= 0) {
6463 ret
= -host_to_target_errno(errno
);
6467 /* Return value is the unbiased priority. Signal no error. */
6468 ((CPUAlphaState
*)cpu_env
)->ir
[IR_V0
] = 0;
6470 /* Return value is a biased priority to avoid negative numbers. */
6474 case TARGET_NR_setpriority
:
6475 ret
= get_errno(setpriority(arg1
, arg2
, arg3
));
6477 #ifdef TARGET_NR_profil
6478 case TARGET_NR_profil
:
6481 case TARGET_NR_statfs
:
6482 if (!(p
= lock_user_string(arg1
)))
6484 ret
= get_errno(statfs(path(p
), &stfs
));
6485 unlock_user(p
, arg1
, 0);
6487 if (!is_error(ret
)) {
6488 struct target_statfs
*target_stfs
;
6490 if (!lock_user_struct(VERIFY_WRITE
, target_stfs
, arg2
, 0))
6492 __put_user(stfs
.f_type
, &target_stfs
->f_type
);
6493 __put_user(stfs
.f_bsize
, &target_stfs
->f_bsize
);
6494 __put_user(stfs
.f_blocks
, &target_stfs
->f_blocks
);
6495 __put_user(stfs
.f_bfree
, &target_stfs
->f_bfree
);
6496 __put_user(stfs
.f_bavail
, &target_stfs
->f_bavail
);
6497 __put_user(stfs
.f_files
, &target_stfs
->f_files
);
6498 __put_user(stfs
.f_ffree
, &target_stfs
->f_ffree
);
6499 __put_user(stfs
.f_fsid
.__val
[0], &target_stfs
->f_fsid
.val
[0]);
6500 __put_user(stfs
.f_fsid
.__val
[1], &target_stfs
->f_fsid
.val
[1]);
6501 __put_user(stfs
.f_namelen
, &target_stfs
->f_namelen
);
6502 unlock_user_struct(target_stfs
, arg2
, 1);
6505 case TARGET_NR_fstatfs
:
6506 ret
= get_errno(fstatfs(arg1
, &stfs
));
6507 goto convert_statfs
;
6508 #ifdef TARGET_NR_statfs64
6509 case TARGET_NR_statfs64
:
6510 if (!(p
= lock_user_string(arg1
)))
6512 ret
= get_errno(statfs(path(p
), &stfs
));
6513 unlock_user(p
, arg1
, 0);
6515 if (!is_error(ret
)) {
6516 struct target_statfs64
*target_stfs
;
6518 if (!lock_user_struct(VERIFY_WRITE
, target_stfs
, arg3
, 0))
6520 __put_user(stfs
.f_type
, &target_stfs
->f_type
);
6521 __put_user(stfs
.f_bsize
, &target_stfs
->f_bsize
);
6522 __put_user(stfs
.f_blocks
, &target_stfs
->f_blocks
);
6523 __put_user(stfs
.f_bfree
, &target_stfs
->f_bfree
);
6524 __put_user(stfs
.f_bavail
, &target_stfs
->f_bavail
);
6525 __put_user(stfs
.f_files
, &target_stfs
->f_files
);
6526 __put_user(stfs
.f_ffree
, &target_stfs
->f_ffree
);
6527 __put_user(stfs
.f_fsid
.__val
[0], &target_stfs
->f_fsid
.val
[0]);
6528 __put_user(stfs
.f_fsid
.__val
[1], &target_stfs
->f_fsid
.val
[1]);
6529 __put_user(stfs
.f_namelen
, &target_stfs
->f_namelen
);
6530 unlock_user_struct(target_stfs
, arg3
, 1);
6533 case TARGET_NR_fstatfs64
:
6534 ret
= get_errno(fstatfs(arg1
, &stfs
));
6535 goto convert_statfs64
;
6537 #ifdef TARGET_NR_ioperm
6538 case TARGET_NR_ioperm
:
6541 #ifdef TARGET_NR_socketcall
6542 case TARGET_NR_socketcall
:
6543 ret
= do_socketcall(arg1
, arg2
);
6546 #ifdef TARGET_NR_accept
6547 case TARGET_NR_accept
:
6548 ret
= do_accept(arg1
, arg2
, arg3
);
6551 #ifdef TARGET_NR_bind
6552 case TARGET_NR_bind
:
6553 ret
= do_bind(arg1
, arg2
, arg3
);
6556 #ifdef TARGET_NR_connect
6557 case TARGET_NR_connect
:
6558 ret
= do_connect(arg1
, arg2
, arg3
);
6561 #ifdef TARGET_NR_getpeername
6562 case TARGET_NR_getpeername
:
6563 ret
= do_getpeername(arg1
, arg2
, arg3
);
6566 #ifdef TARGET_NR_getsockname
6567 case TARGET_NR_getsockname
:
6568 ret
= do_getsockname(arg1
, arg2
, arg3
);
6571 #ifdef TARGET_NR_getsockopt
6572 case TARGET_NR_getsockopt
:
6573 ret
= do_getsockopt(arg1
, arg2
, arg3
, arg4
, arg5
);
6576 #ifdef TARGET_NR_listen
6577 case TARGET_NR_listen
:
6578 ret
= get_errno(listen(arg1
, arg2
));
6581 #ifdef TARGET_NR_recv
6582 case TARGET_NR_recv
:
6583 ret
= do_recvfrom(arg1
, arg2
, arg3
, arg4
, 0, 0);
6586 #ifdef TARGET_NR_recvfrom
6587 case TARGET_NR_recvfrom
:
6588 ret
= do_recvfrom(arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
6591 #ifdef TARGET_NR_recvmsg
6592 case TARGET_NR_recvmsg
:
6593 ret
= do_sendrecvmsg(arg1
, arg2
, arg3
, 0);
6596 #ifdef TARGET_NR_send
6597 case TARGET_NR_send
:
6598 ret
= do_sendto(arg1
, arg2
, arg3
, arg4
, 0, 0);
6601 #ifdef TARGET_NR_sendmsg
6602 case TARGET_NR_sendmsg
:
6603 ret
= do_sendrecvmsg(arg1
, arg2
, arg3
, 1);
6606 #ifdef TARGET_NR_sendto
6607 case TARGET_NR_sendto
:
6608 ret
= do_sendto(arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
6611 #ifdef TARGET_NR_shutdown
6612 case TARGET_NR_shutdown
:
6613 ret
= get_errno(shutdown(arg1
, arg2
));
6616 #ifdef TARGET_NR_socket
6617 case TARGET_NR_socket
:
6618 ret
= do_socket(arg1
, arg2
, arg3
);
6621 #ifdef TARGET_NR_socketpair
6622 case TARGET_NR_socketpair
:
6623 ret
= do_socketpair(arg1
, arg2
, arg3
, arg4
);
6626 #ifdef TARGET_NR_setsockopt
6627 case TARGET_NR_setsockopt
:
6628 ret
= do_setsockopt(arg1
, arg2
, arg3
, arg4
, (socklen_t
) arg5
);
6632 case TARGET_NR_syslog
:
6633 if (!(p
= lock_user_string(arg2
)))
6635 ret
= get_errno(sys_syslog((int)arg1
, p
, (int)arg3
));
6636 unlock_user(p
, arg2
, 0);
6639 case TARGET_NR_setitimer
:
6641 struct itimerval value
, ovalue
, *pvalue
;
6645 if (copy_from_user_timeval(&pvalue
->it_interval
, arg2
)
6646 || copy_from_user_timeval(&pvalue
->it_value
,
6647 arg2
+ sizeof(struct target_timeval
)))
6652 ret
= get_errno(setitimer(arg1
, pvalue
, &ovalue
));
6653 if (!is_error(ret
) && arg3
) {
6654 if (copy_to_user_timeval(arg3
,
6655 &ovalue
.it_interval
)
6656 || copy_to_user_timeval(arg3
+ sizeof(struct target_timeval
),
6662 case TARGET_NR_getitimer
:
6664 struct itimerval value
;
6666 ret
= get_errno(getitimer(arg1
, &value
));
6667 if (!is_error(ret
) && arg2
) {
6668 if (copy_to_user_timeval(arg2
,
6670 || copy_to_user_timeval(arg2
+ sizeof(struct target_timeval
),
6676 case TARGET_NR_stat
:
6677 if (!(p
= lock_user_string(arg1
)))
6679 ret
= get_errno(stat(path(p
), &st
));
6680 unlock_user(p
, arg1
, 0);
6682 case TARGET_NR_lstat
:
6683 if (!(p
= lock_user_string(arg1
)))
6685 ret
= get_errno(lstat(path(p
), &st
));
6686 unlock_user(p
, arg1
, 0);
6688 case TARGET_NR_fstat
:
6690 ret
= get_errno(fstat(arg1
, &st
));
6692 if (!is_error(ret
)) {
6693 struct target_stat
*target_st
;
6695 if (!lock_user_struct(VERIFY_WRITE
, target_st
, arg2
, 0))
6697 memset(target_st
, 0, sizeof(*target_st
));
6698 __put_user(st
.st_dev
, &target_st
->st_dev
);
6699 __put_user(st
.st_ino
, &target_st
->st_ino
);
6700 __put_user(st
.st_mode
, &target_st
->st_mode
);
6701 __put_user(st
.st_uid
, &target_st
->st_uid
);
6702 __put_user(st
.st_gid
, &target_st
->st_gid
);
6703 __put_user(st
.st_nlink
, &target_st
->st_nlink
);
6704 __put_user(st
.st_rdev
, &target_st
->st_rdev
);
6705 __put_user(st
.st_size
, &target_st
->st_size
);
6706 __put_user(st
.st_blksize
, &target_st
->st_blksize
);
6707 __put_user(st
.st_blocks
, &target_st
->st_blocks
);
6708 __put_user(st
.st_atime
, &target_st
->target_st_atime
);
6709 __put_user(st
.st_mtime
, &target_st
->target_st_mtime
);
6710 __put_user(st
.st_ctime
, &target_st
->target_st_ctime
);
6711 unlock_user_struct(target_st
, arg2
, 1);
6715 #ifdef TARGET_NR_olduname
6716 case TARGET_NR_olduname
:
6719 #ifdef TARGET_NR_iopl
6720 case TARGET_NR_iopl
:
6723 case TARGET_NR_vhangup
:
6724 ret
= get_errno(vhangup());
6726 #ifdef TARGET_NR_idle
6727 case TARGET_NR_idle
:
6730 #ifdef TARGET_NR_syscall
6731 case TARGET_NR_syscall
:
6732 ret
= do_syscall(cpu_env
, arg1
& 0xffff, arg2
, arg3
, arg4
, arg5
,
6733 arg6
, arg7
, arg8
, 0);
6736 case TARGET_NR_wait4
:
6739 abi_long status_ptr
= arg2
;
6740 struct rusage rusage
, *rusage_ptr
;
6741 abi_ulong target_rusage
= arg4
;
6743 rusage_ptr
= &rusage
;
6746 ret
= get_errno(wait4(arg1
, &status
, arg3
, rusage_ptr
));
6747 if (!is_error(ret
)) {
6748 if (status_ptr
&& ret
) {
6749 status
= host_to_target_waitstatus(status
);
6750 if (put_user_s32(status
, status_ptr
))
6754 host_to_target_rusage(target_rusage
, &rusage
);
6758 #ifdef TARGET_NR_swapoff
6759 case TARGET_NR_swapoff
:
6760 if (!(p
= lock_user_string(arg1
)))
6762 ret
= get_errno(swapoff(p
));
6763 unlock_user(p
, arg1
, 0);
6766 case TARGET_NR_sysinfo
:
6768 struct target_sysinfo
*target_value
;
6769 struct sysinfo value
;
6770 ret
= get_errno(sysinfo(&value
));
6771 if (!is_error(ret
) && arg1
)
6773 if (!lock_user_struct(VERIFY_WRITE
, target_value
, arg1
, 0))
6775 __put_user(value
.uptime
, &target_value
->uptime
);
6776 __put_user(value
.loads
[0], &target_value
->loads
[0]);
6777 __put_user(value
.loads
[1], &target_value
->loads
[1]);
6778 __put_user(value
.loads
[2], &target_value
->loads
[2]);
6779 __put_user(value
.totalram
, &target_value
->totalram
);
6780 __put_user(value
.freeram
, &target_value
->freeram
);
6781 __put_user(value
.sharedram
, &target_value
->sharedram
);
6782 __put_user(value
.bufferram
, &target_value
->bufferram
);
6783 __put_user(value
.totalswap
, &target_value
->totalswap
);
6784 __put_user(value
.freeswap
, &target_value
->freeswap
);
6785 __put_user(value
.procs
, &target_value
->procs
);
6786 __put_user(value
.totalhigh
, &target_value
->totalhigh
);
6787 __put_user(value
.freehigh
, &target_value
->freehigh
);
6788 __put_user(value
.mem_unit
, &target_value
->mem_unit
);
6789 unlock_user_struct(target_value
, arg1
, 1);
6793 #ifdef TARGET_NR_ipc
6795 ret
= do_ipc(arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
6798 #ifdef TARGET_NR_semget
6799 case TARGET_NR_semget
:
6800 ret
= get_errno(semget(arg1
, arg2
, arg3
));
6803 #ifdef TARGET_NR_semop
6804 case TARGET_NR_semop
:
6805 ret
= get_errno(do_semop(arg1
, arg2
, arg3
));
6808 #ifdef TARGET_NR_semctl
6809 case TARGET_NR_semctl
:
6810 ret
= do_semctl(arg1
, arg2
, arg3
, (union target_semun
)(abi_ulong
)arg4
);
6813 #ifdef TARGET_NR_msgctl
6814 case TARGET_NR_msgctl
:
6815 ret
= do_msgctl(arg1
, arg2
, arg3
);
6818 #ifdef TARGET_NR_msgget
6819 case TARGET_NR_msgget
:
6820 ret
= get_errno(msgget(arg1
, arg2
));
6823 #ifdef TARGET_NR_msgrcv
6824 case TARGET_NR_msgrcv
:
6825 ret
= do_msgrcv(arg1
, arg2
, arg3
, arg4
, arg5
);
6828 #ifdef TARGET_NR_msgsnd
6829 case TARGET_NR_msgsnd
:
6830 ret
= do_msgsnd(arg1
, arg2
, arg3
, arg4
);
6833 #ifdef TARGET_NR_shmget
6834 case TARGET_NR_shmget
:
6835 ret
= get_errno(shmget(arg1
, arg2
, arg3
));
6838 #ifdef TARGET_NR_shmctl
6839 case TARGET_NR_shmctl
:
6840 ret
= do_shmctl(arg1
, arg2
, arg3
);
6843 #ifdef TARGET_NR_shmat
6844 case TARGET_NR_shmat
:
6845 ret
= do_shmat(arg1
, arg2
, arg3
);
6848 #ifdef TARGET_NR_shmdt
6849 case TARGET_NR_shmdt
:
6850 ret
= do_shmdt(arg1
);
6853 case TARGET_NR_fsync
:
6854 ret
= get_errno(fsync(arg1
));
6856 case TARGET_NR_clone
:
6857 #if defined(TARGET_SH4) || defined(TARGET_ALPHA)
6858 ret
= get_errno(do_fork(cpu_env
, arg1
, arg2
, arg3
, arg5
, arg4
));
6859 #elif defined(TARGET_CRIS)
6860 ret
= get_errno(do_fork(cpu_env
, arg2
, arg1
, arg3
, arg4
, arg5
));
6861 #elif defined(TARGET_S390X)
6862 ret
= get_errno(do_fork(cpu_env
, arg2
, arg1
, arg3
, arg5
, arg4
));
6864 ret
= get_errno(do_fork(cpu_env
, arg1
, arg2
, arg3
, arg4
, arg5
));
6867 #ifdef __NR_exit_group
6868 /* new thread calls */
6869 case TARGET_NR_exit_group
:
6873 gdb_exit(cpu_env
, arg1
);
6874 ret
= get_errno(exit_group(arg1
));
6877 case TARGET_NR_setdomainname
:
6878 if (!(p
= lock_user_string(arg1
)))
6880 ret
= get_errno(setdomainname(p
, arg2
));
6881 unlock_user(p
, arg1
, 0);
6883 case TARGET_NR_uname
:
6884 /* no need to transcode because we use the linux syscall */
6886 struct new_utsname
* buf
;
6888 if (!lock_user_struct(VERIFY_WRITE
, buf
, arg1
, 0))
6890 ret
= get_errno(sys_uname(buf
));
6891 if (!is_error(ret
)) {
6892 /* Overrite the native machine name with whatever is being
6894 strcpy (buf
->machine
, cpu_to_uname_machine(cpu_env
));
6895 /* Allow the user to override the reported release. */
6896 if (qemu_uname_release
&& *qemu_uname_release
)
6897 strcpy (buf
->release
, qemu_uname_release
);
6899 unlock_user_struct(buf
, arg1
, 1);
6903 case TARGET_NR_modify_ldt
:
6904 ret
= do_modify_ldt(cpu_env
, arg1
, arg2
, arg3
);
6906 #if !defined(TARGET_X86_64)
6907 case TARGET_NR_vm86old
:
6909 case TARGET_NR_vm86
:
6910 ret
= do_vm86(cpu_env
, arg1
, arg2
);
6914 case TARGET_NR_adjtimex
:
6916 #ifdef TARGET_NR_create_module
6917 case TARGET_NR_create_module
:
6919 case TARGET_NR_init_module
:
6920 case TARGET_NR_delete_module
:
6921 #ifdef TARGET_NR_get_kernel_syms
6922 case TARGET_NR_get_kernel_syms
:
6925 case TARGET_NR_quotactl
:
6927 case TARGET_NR_getpgid
:
6928 ret
= get_errno(getpgid(arg1
));
6930 case TARGET_NR_fchdir
:
6931 ret
= get_errno(fchdir(arg1
));
6933 #ifdef TARGET_NR_bdflush /* not on x86_64 */
6934 case TARGET_NR_bdflush
:
6937 #ifdef TARGET_NR_sysfs
6938 case TARGET_NR_sysfs
:
6941 case TARGET_NR_personality
:
6942 ret
= get_errno(personality(arg1
));
6944 #ifdef TARGET_NR_afs_syscall
6945 case TARGET_NR_afs_syscall
:
6948 #ifdef TARGET_NR__llseek /* Not on alpha */
6949 case TARGET_NR__llseek
:
6952 #if !defined(__NR_llseek)
6953 res
= lseek(arg1
, ((uint64_t)arg2
<< 32) | arg3
, arg5
);
6955 ret
= get_errno(res
);
6960 ret
= get_errno(_llseek(arg1
, arg2
, arg3
, &res
, arg5
));
6962 if ((ret
== 0) && put_user_s64(res
, arg4
)) {
6968 case TARGET_NR_getdents
:
6969 #if TARGET_ABI_BITS == 32 && HOST_LONG_BITS == 64
6971 struct target_dirent
*target_dirp
;
6972 struct linux_dirent
*dirp
;
6973 abi_long count
= arg3
;
6975 dirp
= malloc(count
);
6977 ret
= -TARGET_ENOMEM
;
6981 ret
= get_errno(sys_getdents(arg1
, dirp
, count
));
6982 if (!is_error(ret
)) {
6983 struct linux_dirent
*de
;
6984 struct target_dirent
*tde
;
6986 int reclen
, treclen
;
6987 int count1
, tnamelen
;
6991 if (!(target_dirp
= lock_user(VERIFY_WRITE
, arg2
, count
, 0)))
6995 reclen
= de
->d_reclen
;
6996 treclen
= reclen
- (2 * (sizeof(long) - sizeof(abi_long
)));
6997 tde
->d_reclen
= tswap16(treclen
);
6998 tde
->d_ino
= tswapal(de
->d_ino
);
6999 tde
->d_off
= tswapal(de
->d_off
);
7000 tnamelen
= treclen
- (2 * sizeof(abi_long
) + 2);
7003 /* XXX: may not be correct */
7004 pstrcpy(tde
->d_name
, tnamelen
, de
->d_name
);
7005 de
= (struct linux_dirent
*)((char *)de
+ reclen
);
7007 tde
= (struct target_dirent
*)((char *)tde
+ treclen
);
7011 unlock_user(target_dirp
, arg2
, ret
);
7017 struct linux_dirent
*dirp
;
7018 abi_long count
= arg3
;
7020 if (!(dirp
= lock_user(VERIFY_WRITE
, arg2
, count
, 0)))
7022 ret
= get_errno(sys_getdents(arg1
, dirp
, count
));
7023 if (!is_error(ret
)) {
7024 struct linux_dirent
*de
;
7029 reclen
= de
->d_reclen
;
7032 de
->d_reclen
= tswap16(reclen
);
7033 tswapls(&de
->d_ino
);
7034 tswapls(&de
->d_off
);
7035 de
= (struct linux_dirent
*)((char *)de
+ reclen
);
7039 unlock_user(dirp
, arg2
, ret
);
7043 #if defined(TARGET_NR_getdents64) && defined(__NR_getdents64)
7044 case TARGET_NR_getdents64
:
7046 struct linux_dirent64
*dirp
;
7047 abi_long count
= arg3
;
7048 if (!(dirp
= lock_user(VERIFY_WRITE
, arg2
, count
, 0)))
7050 ret
= get_errno(sys_getdents64(arg1
, dirp
, count
));
7051 if (!is_error(ret
)) {
7052 struct linux_dirent64
*de
;
7057 reclen
= de
->d_reclen
;
7060 de
->d_reclen
= tswap16(reclen
);
7061 tswap64s((uint64_t *)&de
->d_ino
);
7062 tswap64s((uint64_t *)&de
->d_off
);
7063 de
= (struct linux_dirent64
*)((char *)de
+ reclen
);
7067 unlock_user(dirp
, arg2
, ret
);
7070 #endif /* TARGET_NR_getdents64 */
7071 #if defined(TARGET_NR__newselect) || defined(TARGET_S390X)
7073 case TARGET_NR_select
:
7075 case TARGET_NR__newselect
:
7077 ret
= do_select(arg1
, arg2
, arg3
, arg4
, arg5
);
7080 #if defined(TARGET_NR_poll) || defined(TARGET_NR_ppoll)
7081 # ifdef TARGET_NR_poll
7082 case TARGET_NR_poll
:
7084 # ifdef TARGET_NR_ppoll
7085 case TARGET_NR_ppoll
:
7088 struct target_pollfd
*target_pfd
;
7089 unsigned int nfds
= arg2
;
7094 target_pfd
= lock_user(VERIFY_WRITE
, arg1
, sizeof(struct target_pollfd
) * nfds
, 1);
7098 pfd
= alloca(sizeof(struct pollfd
) * nfds
);
7099 for(i
= 0; i
< nfds
; i
++) {
7100 pfd
[i
].fd
= tswap32(target_pfd
[i
].fd
);
7101 pfd
[i
].events
= tswap16(target_pfd
[i
].events
);
7104 # ifdef TARGET_NR_ppoll
7105 if (num
== TARGET_NR_ppoll
) {
7106 struct timespec _timeout_ts
, *timeout_ts
= &_timeout_ts
;
7107 target_sigset_t
*target_set
;
7108 sigset_t _set
, *set
= &_set
;
7111 if (target_to_host_timespec(timeout_ts
, arg3
)) {
7112 unlock_user(target_pfd
, arg1
, 0);
7120 target_set
= lock_user(VERIFY_READ
, arg4
, sizeof(target_sigset_t
), 1);
7122 unlock_user(target_pfd
, arg1
, 0);
7125 target_to_host_sigset(set
, target_set
);
7130 ret
= get_errno(sys_ppoll(pfd
, nfds
, timeout_ts
, set
, _NSIG
/8));
7132 if (!is_error(ret
) && arg3
) {
7133 host_to_target_timespec(arg3
, timeout_ts
);
7136 unlock_user(target_set
, arg4
, 0);
7140 ret
= get_errno(poll(pfd
, nfds
, timeout
));
7142 if (!is_error(ret
)) {
7143 for(i
= 0; i
< nfds
; i
++) {
7144 target_pfd
[i
].revents
= tswap16(pfd
[i
].revents
);
7147 unlock_user(target_pfd
, arg1
, sizeof(struct target_pollfd
) * nfds
);
7151 case TARGET_NR_flock
:
7152 /* NOTE: the flock constant seems to be the same for every
7154 ret
= get_errno(flock(arg1
, arg2
));
7156 case TARGET_NR_readv
:
7161 vec
= alloca(count
* sizeof(struct iovec
));
7162 if (lock_iovec(VERIFY_WRITE
, vec
, arg2
, count
, 0) < 0)
7164 ret
= get_errno(readv(arg1
, vec
, count
));
7165 unlock_iovec(vec
, arg2
, count
, 1);
7168 case TARGET_NR_writev
:
7173 vec
= alloca(count
* sizeof(struct iovec
));
7174 if (lock_iovec(VERIFY_READ
, vec
, arg2
, count
, 1) < 0)
7176 ret
= get_errno(writev(arg1
, vec
, count
));
7177 unlock_iovec(vec
, arg2
, count
, 0);
7180 case TARGET_NR_getsid
:
7181 ret
= get_errno(getsid(arg1
));
7183 #if defined(TARGET_NR_fdatasync) /* Not on alpha (osf_datasync ?) */
7184 case TARGET_NR_fdatasync
:
7185 ret
= get_errno(fdatasync(arg1
));
7188 case TARGET_NR__sysctl
:
7189 /* We don't implement this, but ENOTDIR is always a safe
7191 ret
= -TARGET_ENOTDIR
;
7193 case TARGET_NR_sched_getaffinity
:
7195 unsigned int mask_size
;
7196 unsigned long *mask
;
7199 * sched_getaffinity needs multiples of ulong, so need to take
7200 * care of mismatches between target ulong and host ulong sizes.
7202 if (arg2
& (sizeof(abi_ulong
) - 1)) {
7203 ret
= -TARGET_EINVAL
;
7206 mask_size
= (arg2
+ (sizeof(*mask
) - 1)) & ~(sizeof(*mask
) - 1);
7208 mask
= alloca(mask_size
);
7209 ret
= get_errno(sys_sched_getaffinity(arg1
, mask_size
, mask
));
7211 if (!is_error(ret
)) {
7212 if (copy_to_user(arg3
, mask
, ret
)) {
7218 case TARGET_NR_sched_setaffinity
:
7220 unsigned int mask_size
;
7221 unsigned long *mask
;
7224 * sched_setaffinity needs multiples of ulong, so need to take
7225 * care of mismatches between target ulong and host ulong sizes.
7227 if (arg2
& (sizeof(abi_ulong
) - 1)) {
7228 ret
= -TARGET_EINVAL
;
7231 mask_size
= (arg2
+ (sizeof(*mask
) - 1)) & ~(sizeof(*mask
) - 1);
7233 mask
= alloca(mask_size
);
7234 if (!lock_user_struct(VERIFY_READ
, p
, arg3
, 1)) {
7237 memcpy(mask
, p
, arg2
);
7238 unlock_user_struct(p
, arg2
, 0);
7240 ret
= get_errno(sys_sched_setaffinity(arg1
, mask_size
, mask
));
7243 case TARGET_NR_sched_setparam
:
7245 struct sched_param
*target_schp
;
7246 struct sched_param schp
;
7248 if (!lock_user_struct(VERIFY_READ
, target_schp
, arg2
, 1))
7250 schp
.sched_priority
= tswap32(target_schp
->sched_priority
);
7251 unlock_user_struct(target_schp
, arg2
, 0);
7252 ret
= get_errno(sched_setparam(arg1
, &schp
));
7255 case TARGET_NR_sched_getparam
:
7257 struct sched_param
*target_schp
;
7258 struct sched_param schp
;
7259 ret
= get_errno(sched_getparam(arg1
, &schp
));
7260 if (!is_error(ret
)) {
7261 if (!lock_user_struct(VERIFY_WRITE
, target_schp
, arg2
, 0))
7263 target_schp
->sched_priority
= tswap32(schp
.sched_priority
);
7264 unlock_user_struct(target_schp
, arg2
, 1);
7268 case TARGET_NR_sched_setscheduler
:
7270 struct sched_param
*target_schp
;
7271 struct sched_param schp
;
7272 if (!lock_user_struct(VERIFY_READ
, target_schp
, arg3
, 1))
7274 schp
.sched_priority
= tswap32(target_schp
->sched_priority
);
7275 unlock_user_struct(target_schp
, arg3
, 0);
7276 ret
= get_errno(sched_setscheduler(arg1
, arg2
, &schp
));
7279 case TARGET_NR_sched_getscheduler
:
7280 ret
= get_errno(sched_getscheduler(arg1
));
7282 case TARGET_NR_sched_yield
:
7283 ret
= get_errno(sched_yield());
7285 case TARGET_NR_sched_get_priority_max
:
7286 ret
= get_errno(sched_get_priority_max(arg1
));
7288 case TARGET_NR_sched_get_priority_min
:
7289 ret
= get_errno(sched_get_priority_min(arg1
));
7291 case TARGET_NR_sched_rr_get_interval
:
7294 ret
= get_errno(sched_rr_get_interval(arg1
, &ts
));
7295 if (!is_error(ret
)) {
7296 host_to_target_timespec(arg2
, &ts
);
7300 case TARGET_NR_nanosleep
:
7302 struct timespec req
, rem
;
7303 target_to_host_timespec(&req
, arg1
);
7304 ret
= get_errno(nanosleep(&req
, &rem
));
7305 if (is_error(ret
) && arg2
) {
7306 host_to_target_timespec(arg2
, &rem
);
7310 #ifdef TARGET_NR_query_module
7311 case TARGET_NR_query_module
:
7314 #ifdef TARGET_NR_nfsservctl
7315 case TARGET_NR_nfsservctl
:
7318 case TARGET_NR_prctl
:
7320 case PR_GET_PDEATHSIG
:
7323 ret
= get_errno(prctl(arg1
, &deathsig
, arg3
, arg4
, arg5
));
7324 if (!is_error(ret
) && arg2
7325 && put_user_ual(deathsig
, arg2
)) {
7333 void *name
= lock_user(VERIFY_WRITE
, arg2
, 16, 1);
7337 ret
= get_errno(prctl(arg1
, (unsigned long)name
,
7339 unlock_user(name
, arg2
, 16);
7344 void *name
= lock_user(VERIFY_READ
, arg2
, 16, 1);
7348 ret
= get_errno(prctl(arg1
, (unsigned long)name
,
7350 unlock_user(name
, arg2
, 0);
7355 /* Most prctl options have no pointer arguments */
7356 ret
= get_errno(prctl(arg1
, arg2
, arg3
, arg4
, arg5
));
7360 #ifdef TARGET_NR_arch_prctl
7361 case TARGET_NR_arch_prctl
:
7362 #if defined(TARGET_I386) && !defined(TARGET_ABI32)
7363 ret
= do_arch_prctl(cpu_env
, arg1
, arg2
);
7369 #ifdef TARGET_NR_pread
7370 case TARGET_NR_pread
:
7371 if (regpairs_aligned(cpu_env
))
7373 if (!(p
= lock_user(VERIFY_WRITE
, arg2
, arg3
, 0)))
7375 ret
= get_errno(pread(arg1
, p
, arg3
, arg4
));
7376 unlock_user(p
, arg2
, ret
);
7378 case TARGET_NR_pwrite
:
7379 if (regpairs_aligned(cpu_env
))
7381 if (!(p
= lock_user(VERIFY_READ
, arg2
, arg3
, 1)))
7383 ret
= get_errno(pwrite(arg1
, p
, arg3
, arg4
));
7384 unlock_user(p
, arg2
, 0);
7387 #ifdef TARGET_NR_pread64
7388 case TARGET_NR_pread64
:
7389 if (!(p
= lock_user(VERIFY_WRITE
, arg2
, arg3
, 0)))
7391 ret
= get_errno(pread64(arg1
, p
, arg3
, target_offset64(arg4
, arg5
)));
7392 unlock_user(p
, arg2
, ret
);
7394 case TARGET_NR_pwrite64
:
7395 if (!(p
= lock_user(VERIFY_READ
, arg2
, arg3
, 1)))
7397 ret
= get_errno(pwrite64(arg1
, p
, arg3
, target_offset64(arg4
, arg5
)));
7398 unlock_user(p
, arg2
, 0);
7401 case TARGET_NR_getcwd
:
7402 if (!(p
= lock_user(VERIFY_WRITE
, arg1
, arg2
, 0)))
7404 ret
= get_errno(sys_getcwd1(p
, arg2
));
7405 unlock_user(p
, arg1
, ret
);
7407 case TARGET_NR_capget
:
7409 case TARGET_NR_capset
:
7411 case TARGET_NR_sigaltstack
:
7412 #if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_MIPS) || \
7413 defined(TARGET_SPARC) || defined(TARGET_PPC) || defined(TARGET_ALPHA) || \
7414 defined(TARGET_M68K) || defined(TARGET_S390X) || defined(TARGET_OPENRISC)
7415 ret
= do_sigaltstack(arg1
, arg2
, get_sp_from_cpustate((CPUArchState
*)cpu_env
));
7420 case TARGET_NR_sendfile
:
7422 #ifdef TARGET_NR_getpmsg
7423 case TARGET_NR_getpmsg
:
7426 #ifdef TARGET_NR_putpmsg
7427 case TARGET_NR_putpmsg
:
7430 #ifdef TARGET_NR_vfork
7431 case TARGET_NR_vfork
:
7432 ret
= get_errno(do_fork(cpu_env
, CLONE_VFORK
| CLONE_VM
| SIGCHLD
,
7436 #ifdef TARGET_NR_ugetrlimit
7437 case TARGET_NR_ugetrlimit
:
7440 int resource
= target_to_host_resource(arg1
);
7441 ret
= get_errno(getrlimit(resource
, &rlim
));
7442 if (!is_error(ret
)) {
7443 struct target_rlimit
*target_rlim
;
7444 if (!lock_user_struct(VERIFY_WRITE
, target_rlim
, arg2
, 0))
7446 target_rlim
->rlim_cur
= host_to_target_rlim(rlim
.rlim_cur
);
7447 target_rlim
->rlim_max
= host_to_target_rlim(rlim
.rlim_max
);
7448 unlock_user_struct(target_rlim
, arg2
, 1);
7453 #ifdef TARGET_NR_truncate64
7454 case TARGET_NR_truncate64
:
7455 if (!(p
= lock_user_string(arg1
)))
7457 ret
= target_truncate64(cpu_env
, p
, arg2
, arg3
, arg4
);
7458 unlock_user(p
, arg1
, 0);
7461 #ifdef TARGET_NR_ftruncate64
7462 case TARGET_NR_ftruncate64
:
7463 ret
= target_ftruncate64(cpu_env
, arg1
, arg2
, arg3
, arg4
);
7466 #ifdef TARGET_NR_stat64
7467 case TARGET_NR_stat64
:
7468 if (!(p
= lock_user_string(arg1
)))
7470 ret
= get_errno(stat(path(p
), &st
));
7471 unlock_user(p
, arg1
, 0);
7473 ret
= host_to_target_stat64(cpu_env
, arg2
, &st
);
7476 #ifdef TARGET_NR_lstat64
7477 case TARGET_NR_lstat64
:
7478 if (!(p
= lock_user_string(arg1
)))
7480 ret
= get_errno(lstat(path(p
), &st
));
7481 unlock_user(p
, arg1
, 0);
7483 ret
= host_to_target_stat64(cpu_env
, arg2
, &st
);
7486 #ifdef TARGET_NR_fstat64
7487 case TARGET_NR_fstat64
:
7488 ret
= get_errno(fstat(arg1
, &st
));
7490 ret
= host_to_target_stat64(cpu_env
, arg2
, &st
);
7493 #if (defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat)) && \
7494 (defined(__NR_fstatat64) || defined(__NR_newfstatat))
7495 #ifdef TARGET_NR_fstatat64
7496 case TARGET_NR_fstatat64
:
7498 #ifdef TARGET_NR_newfstatat
7499 case TARGET_NR_newfstatat
:
7501 if (!(p
= lock_user_string(arg2
)))
7503 #ifdef __NR_fstatat64
7504 ret
= get_errno(sys_fstatat64(arg1
, path(p
), &st
, arg4
));
7506 ret
= get_errno(sys_newfstatat(arg1
, path(p
), &st
, arg4
));
7509 ret
= host_to_target_stat64(cpu_env
, arg3
, &st
);
7512 case TARGET_NR_lchown
:
7513 if (!(p
= lock_user_string(arg1
)))
7515 ret
= get_errno(lchown(p
, low2highuid(arg2
), low2highgid(arg3
)));
7516 unlock_user(p
, arg1
, 0);
7518 #ifdef TARGET_NR_getuid
7519 case TARGET_NR_getuid
:
7520 ret
= get_errno(high2lowuid(getuid()));
7523 #ifdef TARGET_NR_getgid
7524 case TARGET_NR_getgid
:
7525 ret
= get_errno(high2lowgid(getgid()));
7528 #ifdef TARGET_NR_geteuid
7529 case TARGET_NR_geteuid
:
7530 ret
= get_errno(high2lowuid(geteuid()));
7533 #ifdef TARGET_NR_getegid
7534 case TARGET_NR_getegid
:
7535 ret
= get_errno(high2lowgid(getegid()));
7538 case TARGET_NR_setreuid
:
7539 ret
= get_errno(setreuid(low2highuid(arg1
), low2highuid(arg2
)));
7541 case TARGET_NR_setregid
:
7542 ret
= get_errno(setregid(low2highgid(arg1
), low2highgid(arg2
)));
7544 case TARGET_NR_getgroups
:
7546 int gidsetsize
= arg1
;
7547 target_id
*target_grouplist
;
7551 grouplist
= alloca(gidsetsize
* sizeof(gid_t
));
7552 ret
= get_errno(getgroups(gidsetsize
, grouplist
));
7553 if (gidsetsize
== 0)
7555 if (!is_error(ret
)) {
7556 target_grouplist
= lock_user(VERIFY_WRITE
, arg2
, gidsetsize
* 2, 0);
7557 if (!target_grouplist
)
7559 for(i
= 0;i
< ret
; i
++)
7560 target_grouplist
[i
] = tswapid(high2lowgid(grouplist
[i
]));
7561 unlock_user(target_grouplist
, arg2
, gidsetsize
* 2);
7565 case TARGET_NR_setgroups
:
7567 int gidsetsize
= arg1
;
7568 target_id
*target_grouplist
;
7572 grouplist
= alloca(gidsetsize
* sizeof(gid_t
));
7573 target_grouplist
= lock_user(VERIFY_READ
, arg2
, gidsetsize
* 2, 1);
7574 if (!target_grouplist
) {
7575 ret
= -TARGET_EFAULT
;
7578 for(i
= 0;i
< gidsetsize
; i
++)
7579 grouplist
[i
] = low2highgid(tswapid(target_grouplist
[i
]));
7580 unlock_user(target_grouplist
, arg2
, 0);
7581 ret
= get_errno(setgroups(gidsetsize
, grouplist
));
7584 case TARGET_NR_fchown
:
7585 ret
= get_errno(fchown(arg1
, low2highuid(arg2
), low2highgid(arg3
)));
7587 #if defined(TARGET_NR_fchownat) && defined(__NR_fchownat)
7588 case TARGET_NR_fchownat
:
7589 if (!(p
= lock_user_string(arg2
)))
7591 ret
= get_errno(sys_fchownat(arg1
, p
, low2highuid(arg3
), low2highgid(arg4
), arg5
));
7592 unlock_user(p
, arg2
, 0);
7595 #ifdef TARGET_NR_setresuid
7596 case TARGET_NR_setresuid
:
7597 ret
= get_errno(setresuid(low2highuid(arg1
),
7599 low2highuid(arg3
)));
7602 #ifdef TARGET_NR_getresuid
7603 case TARGET_NR_getresuid
:
7605 uid_t ruid
, euid
, suid
;
7606 ret
= get_errno(getresuid(&ruid
, &euid
, &suid
));
7607 if (!is_error(ret
)) {
7608 if (put_user_u16(high2lowuid(ruid
), arg1
)
7609 || put_user_u16(high2lowuid(euid
), arg2
)
7610 || put_user_u16(high2lowuid(suid
), arg3
))
7616 #ifdef TARGET_NR_getresgid
7617 case TARGET_NR_setresgid
:
7618 ret
= get_errno(setresgid(low2highgid(arg1
),
7620 low2highgid(arg3
)));
7623 #ifdef TARGET_NR_getresgid
7624 case TARGET_NR_getresgid
:
7626 gid_t rgid
, egid
, sgid
;
7627 ret
= get_errno(getresgid(&rgid
, &egid
, &sgid
));
7628 if (!is_error(ret
)) {
7629 if (put_user_u16(high2lowgid(rgid
), arg1
)
7630 || put_user_u16(high2lowgid(egid
), arg2
)
7631 || put_user_u16(high2lowgid(sgid
), arg3
))
7637 case TARGET_NR_chown
:
7638 if (!(p
= lock_user_string(arg1
)))
7640 ret
= get_errno(chown(p
, low2highuid(arg2
), low2highgid(arg3
)));
7641 unlock_user(p
, arg1
, 0);
7643 case TARGET_NR_setuid
:
7644 ret
= get_errno(setuid(low2highuid(arg1
)));
7646 case TARGET_NR_setgid
:
7647 ret
= get_errno(setgid(low2highgid(arg1
)));
7649 case TARGET_NR_setfsuid
:
7650 ret
= get_errno(setfsuid(arg1
));
7652 case TARGET_NR_setfsgid
:
7653 ret
= get_errno(setfsgid(arg1
));
7656 #ifdef TARGET_NR_lchown32
7657 case TARGET_NR_lchown32
:
7658 if (!(p
= lock_user_string(arg1
)))
7660 ret
= get_errno(lchown(p
, arg2
, arg3
));
7661 unlock_user(p
, arg1
, 0);
7664 #ifdef TARGET_NR_getuid32
7665 case TARGET_NR_getuid32
:
7666 ret
= get_errno(getuid());
7670 #if defined(TARGET_NR_getxuid) && defined(TARGET_ALPHA)
7671 /* Alpha specific */
7672 case TARGET_NR_getxuid
:
7676 ((CPUAlphaState
*)cpu_env
)->ir
[IR_A4
]=euid
;
7678 ret
= get_errno(getuid());
7681 #if defined(TARGET_NR_getxgid) && defined(TARGET_ALPHA)
7682 /* Alpha specific */
7683 case TARGET_NR_getxgid
:
7687 ((CPUAlphaState
*)cpu_env
)->ir
[IR_A4
]=egid
;
7689 ret
= get_errno(getgid());
7692 #if defined(TARGET_NR_osf_getsysinfo) && defined(TARGET_ALPHA)
7693 /* Alpha specific */
7694 case TARGET_NR_osf_getsysinfo
:
7695 ret
= -TARGET_EOPNOTSUPP
;
7697 case TARGET_GSI_IEEE_FP_CONTROL
:
7699 uint64_t swcr
, fpcr
= cpu_alpha_load_fpcr (cpu_env
);
7701 /* Copied from linux ieee_fpcr_to_swcr. */
7702 swcr
= (fpcr
>> 35) & SWCR_STATUS_MASK
;
7703 swcr
|= (fpcr
>> 36) & SWCR_MAP_DMZ
;
7704 swcr
|= (~fpcr
>> 48) & (SWCR_TRAP_ENABLE_INV
7705 | SWCR_TRAP_ENABLE_DZE
7706 | SWCR_TRAP_ENABLE_OVF
);
7707 swcr
|= (~fpcr
>> 57) & (SWCR_TRAP_ENABLE_UNF
7708 | SWCR_TRAP_ENABLE_INE
);
7709 swcr
|= (fpcr
>> 47) & SWCR_MAP_UMZ
;
7710 swcr
|= (~fpcr
>> 41) & SWCR_TRAP_ENABLE_DNO
;
7712 if (put_user_u64 (swcr
, arg2
))
7718 /* case GSI_IEEE_STATE_AT_SIGNAL:
7719 -- Not implemented in linux kernel.
7721 -- Retrieves current unaligned access state; not much used.
7723 -- Retrieves implver information; surely not used.
7725 -- Grabs a copy of the HWRPB; surely not used.
7730 #if defined(TARGET_NR_osf_setsysinfo) && defined(TARGET_ALPHA)
7731 /* Alpha specific */
7732 case TARGET_NR_osf_setsysinfo
:
7733 ret
= -TARGET_EOPNOTSUPP
;
7735 case TARGET_SSI_IEEE_FP_CONTROL
:
7737 uint64_t swcr
, fpcr
, orig_fpcr
;
7739 if (get_user_u64 (swcr
, arg2
)) {
7742 orig_fpcr
= cpu_alpha_load_fpcr(cpu_env
);
7743 fpcr
= orig_fpcr
& FPCR_DYN_MASK
;
7745 /* Copied from linux ieee_swcr_to_fpcr. */
7746 fpcr
|= (swcr
& SWCR_STATUS_MASK
) << 35;
7747 fpcr
|= (swcr
& SWCR_MAP_DMZ
) << 36;
7748 fpcr
|= (~swcr
& (SWCR_TRAP_ENABLE_INV
7749 | SWCR_TRAP_ENABLE_DZE
7750 | SWCR_TRAP_ENABLE_OVF
)) << 48;
7751 fpcr
|= (~swcr
& (SWCR_TRAP_ENABLE_UNF
7752 | SWCR_TRAP_ENABLE_INE
)) << 57;
7753 fpcr
|= (swcr
& SWCR_MAP_UMZ
? FPCR_UNDZ
| FPCR_UNFD
: 0);
7754 fpcr
|= (~swcr
& SWCR_TRAP_ENABLE_DNO
) << 41;
7756 cpu_alpha_store_fpcr(cpu_env
, fpcr
);
7761 case TARGET_SSI_IEEE_RAISE_EXCEPTION
:
7763 uint64_t exc
, fpcr
, orig_fpcr
;
7766 if (get_user_u64(exc
, arg2
)) {
7770 orig_fpcr
= cpu_alpha_load_fpcr(cpu_env
);
7772 /* We only add to the exception status here. */
7773 fpcr
= orig_fpcr
| ((exc
& SWCR_STATUS_MASK
) << 35);
7775 cpu_alpha_store_fpcr(cpu_env
, fpcr
);
7778 /* Old exceptions are not signaled. */
7779 fpcr
&= ~(orig_fpcr
& FPCR_STATUS_MASK
);
7781 /* If any exceptions set by this call,
7782 and are unmasked, send a signal. */
7784 if ((fpcr
& (FPCR_INE
| FPCR_INED
)) == FPCR_INE
) {
7785 si_code
= TARGET_FPE_FLTRES
;
7787 if ((fpcr
& (FPCR_UNF
| FPCR_UNFD
)) == FPCR_UNF
) {
7788 si_code
= TARGET_FPE_FLTUND
;
7790 if ((fpcr
& (FPCR_OVF
| FPCR_OVFD
)) == FPCR_OVF
) {
7791 si_code
= TARGET_FPE_FLTOVF
;
7793 if ((fpcr
& (FPCR_DZE
| FPCR_DZED
)) == FPCR_DZE
) {
7794 si_code
= TARGET_FPE_FLTDIV
;
7796 if ((fpcr
& (FPCR_INV
| FPCR_INVD
)) == FPCR_INV
) {
7797 si_code
= TARGET_FPE_FLTINV
;
7800 target_siginfo_t info
;
7801 info
.si_signo
= SIGFPE
;
7803 info
.si_code
= si_code
;
7804 info
._sifields
._sigfault
._addr
7805 = ((CPUArchState
*)cpu_env
)->pc
;
7806 queue_signal((CPUArchState
*)cpu_env
, info
.si_signo
, &info
);
7811 /* case SSI_NVPAIRS:
7812 -- Used with SSIN_UACPROC to enable unaligned accesses.
7813 case SSI_IEEE_STATE_AT_SIGNAL:
7814 case SSI_IEEE_IGNORE_STATE_AT_SIGNAL:
7815 -- Not implemented in linux kernel
7820 #ifdef TARGET_NR_osf_sigprocmask
7821 /* Alpha specific. */
7822 case TARGET_NR_osf_sigprocmask
:
7826 sigset_t set
, oldset
;
7829 case TARGET_SIG_BLOCK
:
7832 case TARGET_SIG_UNBLOCK
:
7835 case TARGET_SIG_SETMASK
:
7839 ret
= -TARGET_EINVAL
;
7843 target_to_host_old_sigset(&set
, &mask
);
7844 sigprocmask(how
, &set
, &oldset
);
7845 host_to_target_old_sigset(&mask
, &oldset
);
7851 #ifdef TARGET_NR_getgid32
7852 case TARGET_NR_getgid32
:
7853 ret
= get_errno(getgid());
7856 #ifdef TARGET_NR_geteuid32
7857 case TARGET_NR_geteuid32
:
7858 ret
= get_errno(geteuid());
7861 #ifdef TARGET_NR_getegid32
7862 case TARGET_NR_getegid32
:
7863 ret
= get_errno(getegid());
7866 #ifdef TARGET_NR_setreuid32
7867 case TARGET_NR_setreuid32
:
7868 ret
= get_errno(setreuid(arg1
, arg2
));
7871 #ifdef TARGET_NR_setregid32
7872 case TARGET_NR_setregid32
:
7873 ret
= get_errno(setregid(arg1
, arg2
));
7876 #ifdef TARGET_NR_getgroups32
7877 case TARGET_NR_getgroups32
:
7879 int gidsetsize
= arg1
;
7880 uint32_t *target_grouplist
;
7884 grouplist
= alloca(gidsetsize
* sizeof(gid_t
));
7885 ret
= get_errno(getgroups(gidsetsize
, grouplist
));
7886 if (gidsetsize
== 0)
7888 if (!is_error(ret
)) {
7889 target_grouplist
= lock_user(VERIFY_WRITE
, arg2
, gidsetsize
* 4, 0);
7890 if (!target_grouplist
) {
7891 ret
= -TARGET_EFAULT
;
7894 for(i
= 0;i
< ret
; i
++)
7895 target_grouplist
[i
] = tswap32(grouplist
[i
]);
7896 unlock_user(target_grouplist
, arg2
, gidsetsize
* 4);
7901 #ifdef TARGET_NR_setgroups32
7902 case TARGET_NR_setgroups32
:
7904 int gidsetsize
= arg1
;
7905 uint32_t *target_grouplist
;
7909 grouplist
= alloca(gidsetsize
* sizeof(gid_t
));
7910 target_grouplist
= lock_user(VERIFY_READ
, arg2
, gidsetsize
* 4, 1);
7911 if (!target_grouplist
) {
7912 ret
= -TARGET_EFAULT
;
7915 for(i
= 0;i
< gidsetsize
; i
++)
7916 grouplist
[i
] = tswap32(target_grouplist
[i
]);
7917 unlock_user(target_grouplist
, arg2
, 0);
7918 ret
= get_errno(setgroups(gidsetsize
, grouplist
));
7922 #ifdef TARGET_NR_fchown32
7923 case TARGET_NR_fchown32
:
7924 ret
= get_errno(fchown(arg1
, arg2
, arg3
));
7927 #ifdef TARGET_NR_setresuid32
7928 case TARGET_NR_setresuid32
:
7929 ret
= get_errno(setresuid(arg1
, arg2
, arg3
));
7932 #ifdef TARGET_NR_getresuid32
7933 case TARGET_NR_getresuid32
:
7935 uid_t ruid
, euid
, suid
;
7936 ret
= get_errno(getresuid(&ruid
, &euid
, &suid
));
7937 if (!is_error(ret
)) {
7938 if (put_user_u32(ruid
, arg1
)
7939 || put_user_u32(euid
, arg2
)
7940 || put_user_u32(suid
, arg3
))
7946 #ifdef TARGET_NR_setresgid32
7947 case TARGET_NR_setresgid32
:
7948 ret
= get_errno(setresgid(arg1
, arg2
, arg3
));
7951 #ifdef TARGET_NR_getresgid32
7952 case TARGET_NR_getresgid32
:
7954 gid_t rgid
, egid
, sgid
;
7955 ret
= get_errno(getresgid(&rgid
, &egid
, &sgid
));
7956 if (!is_error(ret
)) {
7957 if (put_user_u32(rgid
, arg1
)
7958 || put_user_u32(egid
, arg2
)
7959 || put_user_u32(sgid
, arg3
))
7965 #ifdef TARGET_NR_chown32
7966 case TARGET_NR_chown32
:
7967 if (!(p
= lock_user_string(arg1
)))
7969 ret
= get_errno(chown(p
, arg2
, arg3
));
7970 unlock_user(p
, arg1
, 0);
7973 #ifdef TARGET_NR_setuid32
7974 case TARGET_NR_setuid32
:
7975 ret
= get_errno(setuid(arg1
));
7978 #ifdef TARGET_NR_setgid32
7979 case TARGET_NR_setgid32
:
7980 ret
= get_errno(setgid(arg1
));
7983 #ifdef TARGET_NR_setfsuid32
7984 case TARGET_NR_setfsuid32
:
7985 ret
= get_errno(setfsuid(arg1
));
7988 #ifdef TARGET_NR_setfsgid32
7989 case TARGET_NR_setfsgid32
:
7990 ret
= get_errno(setfsgid(arg1
));
7994 case TARGET_NR_pivot_root
:
7996 #ifdef TARGET_NR_mincore
7997 case TARGET_NR_mincore
:
8000 ret
= -TARGET_EFAULT
;
8001 if (!(a
= lock_user(VERIFY_READ
, arg1
,arg2
, 0)))
8003 if (!(p
= lock_user_string(arg3
)))
8005 ret
= get_errno(mincore(a
, arg2
, p
));
8006 unlock_user(p
, arg3
, ret
);
8008 unlock_user(a
, arg1
, 0);
8012 #ifdef TARGET_NR_arm_fadvise64_64
8013 case TARGET_NR_arm_fadvise64_64
:
8016 * arm_fadvise64_64 looks like fadvise64_64 but
8017 * with different argument order
8025 #if defined(TARGET_NR_fadvise64_64) || defined(TARGET_NR_arm_fadvise64_64) || defined(TARGET_NR_fadvise64)
8026 #ifdef TARGET_NR_fadvise64_64
8027 case TARGET_NR_fadvise64_64
:
8029 #ifdef TARGET_NR_fadvise64
8030 case TARGET_NR_fadvise64
:
8034 case 4: arg4
= POSIX_FADV_NOREUSE
+ 1; break; /* make sure it's an invalid value */
8035 case 5: arg4
= POSIX_FADV_NOREUSE
+ 2; break; /* ditto */
8036 case 6: arg4
= POSIX_FADV_DONTNEED
; break;
8037 case 7: arg4
= POSIX_FADV_NOREUSE
; break;
8041 ret
= -posix_fadvise(arg1
, arg2
, arg3
, arg4
);
8044 #ifdef TARGET_NR_madvise
8045 case TARGET_NR_madvise
:
8046 /* A straight passthrough may not be safe because qemu sometimes
8047 turns private flie-backed mappings into anonymous mappings.
8048 This will break MADV_DONTNEED.
8049 This is a hint, so ignoring and returning success is ok. */
8053 #if TARGET_ABI_BITS == 32
8054 case TARGET_NR_fcntl64
:
8058 struct target_flock64
*target_fl
;
8060 struct target_eabi_flock64
*target_efl
;
8063 cmd
= target_to_host_fcntl_cmd(arg2
);
8064 if (cmd
== -TARGET_EINVAL
) {
8070 case TARGET_F_GETLK64
:
8072 if (((CPUARMState
*)cpu_env
)->eabi
) {
8073 if (!lock_user_struct(VERIFY_READ
, target_efl
, arg3
, 1))
8075 fl
.l_type
= tswap16(target_efl
->l_type
);
8076 fl
.l_whence
= tswap16(target_efl
->l_whence
);
8077 fl
.l_start
= tswap64(target_efl
->l_start
);
8078 fl
.l_len
= tswap64(target_efl
->l_len
);
8079 fl
.l_pid
= tswap32(target_efl
->l_pid
);
8080 unlock_user_struct(target_efl
, arg3
, 0);
8084 if (!lock_user_struct(VERIFY_READ
, target_fl
, arg3
, 1))
8086 fl
.l_type
= tswap16(target_fl
->l_type
);
8087 fl
.l_whence
= tswap16(target_fl
->l_whence
);
8088 fl
.l_start
= tswap64(target_fl
->l_start
);
8089 fl
.l_len
= tswap64(target_fl
->l_len
);
8090 fl
.l_pid
= tswap32(target_fl
->l_pid
);
8091 unlock_user_struct(target_fl
, arg3
, 0);
8093 ret
= get_errno(fcntl(arg1
, cmd
, &fl
));
8096 if (((CPUARMState
*)cpu_env
)->eabi
) {
8097 if (!lock_user_struct(VERIFY_WRITE
, target_efl
, arg3
, 0))
8099 target_efl
->l_type
= tswap16(fl
.l_type
);
8100 target_efl
->l_whence
= tswap16(fl
.l_whence
);
8101 target_efl
->l_start
= tswap64(fl
.l_start
);
8102 target_efl
->l_len
= tswap64(fl
.l_len
);
8103 target_efl
->l_pid
= tswap32(fl
.l_pid
);
8104 unlock_user_struct(target_efl
, arg3
, 1);
8108 if (!lock_user_struct(VERIFY_WRITE
, target_fl
, arg3
, 0))
8110 target_fl
->l_type
= tswap16(fl
.l_type
);
8111 target_fl
->l_whence
= tswap16(fl
.l_whence
);
8112 target_fl
->l_start
= tswap64(fl
.l_start
);
8113 target_fl
->l_len
= tswap64(fl
.l_len
);
8114 target_fl
->l_pid
= tswap32(fl
.l_pid
);
8115 unlock_user_struct(target_fl
, arg3
, 1);
8120 case TARGET_F_SETLK64
:
8121 case TARGET_F_SETLKW64
:
8123 if (((CPUARMState
*)cpu_env
)->eabi
) {
8124 if (!lock_user_struct(VERIFY_READ
, target_efl
, arg3
, 1))
8126 fl
.l_type
= tswap16(target_efl
->l_type
);
8127 fl
.l_whence
= tswap16(target_efl
->l_whence
);
8128 fl
.l_start
= tswap64(target_efl
->l_start
);
8129 fl
.l_len
= tswap64(target_efl
->l_len
);
8130 fl
.l_pid
= tswap32(target_efl
->l_pid
);
8131 unlock_user_struct(target_efl
, arg3
, 0);
8135 if (!lock_user_struct(VERIFY_READ
, target_fl
, arg3
, 1))
8137 fl
.l_type
= tswap16(target_fl
->l_type
);
8138 fl
.l_whence
= tswap16(target_fl
->l_whence
);
8139 fl
.l_start
= tswap64(target_fl
->l_start
);
8140 fl
.l_len
= tswap64(target_fl
->l_len
);
8141 fl
.l_pid
= tswap32(target_fl
->l_pid
);
8142 unlock_user_struct(target_fl
, arg3
, 0);
8144 ret
= get_errno(fcntl(arg1
, cmd
, &fl
));
8147 ret
= do_fcntl(arg1
, arg2
, arg3
);
8153 #ifdef TARGET_NR_cacheflush
8154 case TARGET_NR_cacheflush
:
8155 /* self-modifying code is handled automatically, so nothing needed */
8159 #ifdef TARGET_NR_security
8160 case TARGET_NR_security
:
8163 #ifdef TARGET_NR_getpagesize
8164 case TARGET_NR_getpagesize
:
8165 ret
= TARGET_PAGE_SIZE
;
8168 case TARGET_NR_gettid
:
8169 ret
= get_errno(gettid());
8171 #ifdef TARGET_NR_readahead
8172 case TARGET_NR_readahead
:
8173 #if TARGET_ABI_BITS == 32
8174 if (regpairs_aligned(cpu_env
)) {
8179 ret
= get_errno(readahead(arg1
, ((off64_t
)arg3
<< 32) | arg2
, arg4
));
8181 ret
= get_errno(readahead(arg1
, arg2
, arg3
));
8186 #ifdef TARGET_NR_setxattr
8187 case TARGET_NR_listxattr
:
8188 case TARGET_NR_llistxattr
:
8192 b
= lock_user(VERIFY_WRITE
, arg2
, arg3
, 0);
8194 ret
= -TARGET_EFAULT
;
8198 p
= lock_user_string(arg1
);
8200 if (num
== TARGET_NR_listxattr
) {
8201 ret
= get_errno(listxattr(p
, b
, arg3
));
8203 ret
= get_errno(llistxattr(p
, b
, arg3
));
8206 ret
= -TARGET_EFAULT
;
8208 unlock_user(p
, arg1
, 0);
8209 unlock_user(b
, arg2
, arg3
);
8212 case TARGET_NR_flistxattr
:
8216 b
= lock_user(VERIFY_WRITE
, arg2
, arg3
, 0);
8218 ret
= -TARGET_EFAULT
;
8222 ret
= get_errno(flistxattr(arg1
, b
, arg3
));
8223 unlock_user(b
, arg2
, arg3
);
8226 case TARGET_NR_setxattr
:
8227 case TARGET_NR_lsetxattr
:
8229 void *p
, *n
, *v
= 0;
8231 v
= lock_user(VERIFY_READ
, arg3
, arg4
, 1);
8233 ret
= -TARGET_EFAULT
;
8237 p
= lock_user_string(arg1
);
8238 n
= lock_user_string(arg2
);
8240 if (num
== TARGET_NR_setxattr
) {
8241 ret
= get_errno(setxattr(p
, n
, v
, arg4
, arg5
));
8243 ret
= get_errno(lsetxattr(p
, n
, v
, arg4
, arg5
));
8246 ret
= -TARGET_EFAULT
;
8248 unlock_user(p
, arg1
, 0);
8249 unlock_user(n
, arg2
, 0);
8250 unlock_user(v
, arg3
, 0);
8253 case TARGET_NR_fsetxattr
:
8257 v
= lock_user(VERIFY_READ
, arg3
, arg4
, 1);
8259 ret
= -TARGET_EFAULT
;
8263 n
= lock_user_string(arg2
);
8265 ret
= get_errno(fsetxattr(arg1
, n
, v
, arg4
, arg5
));
8267 ret
= -TARGET_EFAULT
;
8269 unlock_user(n
, arg2
, 0);
8270 unlock_user(v
, arg3
, 0);
8273 case TARGET_NR_getxattr
:
8274 case TARGET_NR_lgetxattr
:
8276 void *p
, *n
, *v
= 0;
8278 v
= lock_user(VERIFY_WRITE
, arg3
, arg4
, 0);
8280 ret
= -TARGET_EFAULT
;
8284 p
= lock_user_string(arg1
);
8285 n
= lock_user_string(arg2
);
8287 if (num
== TARGET_NR_getxattr
) {
8288 ret
= get_errno(getxattr(p
, n
, v
, arg4
));
8290 ret
= get_errno(lgetxattr(p
, n
, v
, arg4
));
8293 ret
= -TARGET_EFAULT
;
8295 unlock_user(p
, arg1
, 0);
8296 unlock_user(n
, arg2
, 0);
8297 unlock_user(v
, arg3
, arg4
);
8300 case TARGET_NR_fgetxattr
:
8304 v
= lock_user(VERIFY_WRITE
, arg3
, arg4
, 0);
8306 ret
= -TARGET_EFAULT
;
8310 n
= lock_user_string(arg2
);
8312 ret
= get_errno(fgetxattr(arg1
, n
, v
, arg4
));
8314 ret
= -TARGET_EFAULT
;
8316 unlock_user(n
, arg2
, 0);
8317 unlock_user(v
, arg3
, arg4
);
8320 case TARGET_NR_removexattr
:
8321 case TARGET_NR_lremovexattr
:
8324 p
= lock_user_string(arg1
);
8325 n
= lock_user_string(arg2
);
8327 if (num
== TARGET_NR_removexattr
) {
8328 ret
= get_errno(removexattr(p
, n
));
8330 ret
= get_errno(lremovexattr(p
, n
));
8333 ret
= -TARGET_EFAULT
;
8335 unlock_user(p
, arg1
, 0);
8336 unlock_user(n
, arg2
, 0);
8339 case TARGET_NR_fremovexattr
:
8342 n
= lock_user_string(arg2
);
8344 ret
= get_errno(fremovexattr(arg1
, n
));
8346 ret
= -TARGET_EFAULT
;
8348 unlock_user(n
, arg2
, 0);
8352 #endif /* CONFIG_ATTR */
8353 #ifdef TARGET_NR_set_thread_area
8354 case TARGET_NR_set_thread_area
:
8355 #if defined(TARGET_MIPS)
8356 ((CPUMIPSState
*) cpu_env
)->tls_value
= arg1
;
8359 #elif defined(TARGET_CRIS)
8361 ret
= -TARGET_EINVAL
;
8363 ((CPUCRISState
*) cpu_env
)->pregs
[PR_PID
] = arg1
;
8367 #elif defined(TARGET_I386) && defined(TARGET_ABI32)
8368 ret
= do_set_thread_area(cpu_env
, arg1
);
8371 goto unimplemented_nowarn
;
8374 #ifdef TARGET_NR_get_thread_area
8375 case TARGET_NR_get_thread_area
:
8376 #if defined(TARGET_I386) && defined(TARGET_ABI32)
8377 ret
= do_get_thread_area(cpu_env
, arg1
);
8379 goto unimplemented_nowarn
;
8382 #ifdef TARGET_NR_getdomainname
8383 case TARGET_NR_getdomainname
:
8384 goto unimplemented_nowarn
;
8387 #ifdef TARGET_NR_clock_gettime
8388 case TARGET_NR_clock_gettime
:
8391 ret
= get_errno(clock_gettime(arg1
, &ts
));
8392 if (!is_error(ret
)) {
8393 host_to_target_timespec(arg2
, &ts
);
8398 #ifdef TARGET_NR_clock_getres
8399 case TARGET_NR_clock_getres
:
8402 ret
= get_errno(clock_getres(arg1
, &ts
));
8403 if (!is_error(ret
)) {
8404 host_to_target_timespec(arg2
, &ts
);
8409 #ifdef TARGET_NR_clock_nanosleep
8410 case TARGET_NR_clock_nanosleep
:
8413 target_to_host_timespec(&ts
, arg3
);
8414 ret
= get_errno(clock_nanosleep(arg1
, arg2
, &ts
, arg4
? &ts
: NULL
));
8416 host_to_target_timespec(arg4
, &ts
);
8421 #if defined(TARGET_NR_set_tid_address) && defined(__NR_set_tid_address)
8422 case TARGET_NR_set_tid_address
:
8423 ret
= get_errno(set_tid_address((int *)g2h(arg1
)));
8427 #if defined(TARGET_NR_tkill) && defined(__NR_tkill)
8428 case TARGET_NR_tkill
:
8429 ret
= get_errno(sys_tkill((int)arg1
, target_to_host_signal(arg2
)));
8433 #if defined(TARGET_NR_tgkill) && defined(__NR_tgkill)
8434 case TARGET_NR_tgkill
:
8435 ret
= get_errno(sys_tgkill((int)arg1
, (int)arg2
,
8436 target_to_host_signal(arg3
)));
8440 #ifdef TARGET_NR_set_robust_list
8441 case TARGET_NR_set_robust_list
:
8442 goto unimplemented_nowarn
;
8445 #if defined(TARGET_NR_utimensat) && defined(__NR_utimensat)
8446 case TARGET_NR_utimensat
:
8448 struct timespec
*tsp
, ts
[2];
8452 target_to_host_timespec(ts
, arg3
);
8453 target_to_host_timespec(ts
+1, arg3
+sizeof(struct target_timespec
));
8457 ret
= get_errno(sys_utimensat(arg1
, NULL
, tsp
, arg4
));
8459 if (!(p
= lock_user_string(arg2
))) {
8460 ret
= -TARGET_EFAULT
;
8463 ret
= get_errno(sys_utimensat(arg1
, path(p
), tsp
, arg4
));
8464 unlock_user(p
, arg2
, 0);
8469 #if defined(CONFIG_USE_NPTL)
8470 case TARGET_NR_futex
:
8471 ret
= do_futex(arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
8474 #if defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init)
8475 case TARGET_NR_inotify_init
:
8476 ret
= get_errno(sys_inotify_init());
8479 #ifdef CONFIG_INOTIFY1
8480 #if defined(TARGET_NR_inotify_init1) && defined(__NR_inotify_init1)
8481 case TARGET_NR_inotify_init1
:
8482 ret
= get_errno(sys_inotify_init1(arg1
));
8486 #if defined(TARGET_NR_inotify_add_watch) && defined(__NR_inotify_add_watch)
8487 case TARGET_NR_inotify_add_watch
:
8488 p
= lock_user_string(arg2
);
8489 ret
= get_errno(sys_inotify_add_watch(arg1
, path(p
), arg3
));
8490 unlock_user(p
, arg2
, 0);
8493 #if defined(TARGET_NR_inotify_rm_watch) && defined(__NR_inotify_rm_watch)
8494 case TARGET_NR_inotify_rm_watch
:
8495 ret
= get_errno(sys_inotify_rm_watch(arg1
, arg2
));
8499 #if defined(TARGET_NR_mq_open) && defined(__NR_mq_open)
8500 case TARGET_NR_mq_open
:
8502 struct mq_attr posix_mq_attr
;
8504 p
= lock_user_string(arg1
- 1);
8506 copy_from_user_mq_attr (&posix_mq_attr
, arg4
);
8507 ret
= get_errno(mq_open(p
, arg2
, arg3
, &posix_mq_attr
));
8508 unlock_user (p
, arg1
, 0);
8512 case TARGET_NR_mq_unlink
:
8513 p
= lock_user_string(arg1
- 1);
8514 ret
= get_errno(mq_unlink(p
));
8515 unlock_user (p
, arg1
, 0);
8518 case TARGET_NR_mq_timedsend
:
8522 p
= lock_user (VERIFY_READ
, arg2
, arg3
, 1);
8524 target_to_host_timespec(&ts
, arg5
);
8525 ret
= get_errno(mq_timedsend(arg1
, p
, arg3
, arg4
, &ts
));
8526 host_to_target_timespec(arg5
, &ts
);
8529 ret
= get_errno(mq_send(arg1
, p
, arg3
, arg4
));
8530 unlock_user (p
, arg2
, arg3
);
8534 case TARGET_NR_mq_timedreceive
:
8539 p
= lock_user (VERIFY_READ
, arg2
, arg3
, 1);
8541 target_to_host_timespec(&ts
, arg5
);
8542 ret
= get_errno(mq_timedreceive(arg1
, p
, arg3
, &prio
, &ts
));
8543 host_to_target_timespec(arg5
, &ts
);
8546 ret
= get_errno(mq_receive(arg1
, p
, arg3
, &prio
));
8547 unlock_user (p
, arg2
, arg3
);
8549 put_user_u32(prio
, arg4
);
8553 /* Not implemented for now... */
8554 /* case TARGET_NR_mq_notify: */
8557 case TARGET_NR_mq_getsetattr
:
8559 struct mq_attr posix_mq_attr_in
, posix_mq_attr_out
;
8562 ret
= mq_getattr(arg1
, &posix_mq_attr_out
);
8563 copy_to_user_mq_attr(arg3
, &posix_mq_attr_out
);
8566 copy_from_user_mq_attr(&posix_mq_attr_in
, arg2
);
8567 ret
|= mq_setattr(arg1
, &posix_mq_attr_in
, &posix_mq_attr_out
);
8574 #ifdef CONFIG_SPLICE
8575 #ifdef TARGET_NR_tee
8578 ret
= get_errno(tee(arg1
,arg2
,arg3
,arg4
));
8582 #ifdef TARGET_NR_splice
8583 case TARGET_NR_splice
:
8585 loff_t loff_in
, loff_out
;
8586 loff_t
*ploff_in
= NULL
, *ploff_out
= NULL
;
8588 get_user_u64(loff_in
, arg2
);
8589 ploff_in
= &loff_in
;
8592 get_user_u64(loff_out
, arg2
);
8593 ploff_out
= &loff_out
;
8595 ret
= get_errno(splice(arg1
, ploff_in
, arg3
, ploff_out
, arg5
, arg6
));
8599 #ifdef TARGET_NR_vmsplice
8600 case TARGET_NR_vmsplice
:
8605 vec
= alloca(count
* sizeof(struct iovec
));
8606 if (lock_iovec(VERIFY_READ
, vec
, arg2
, count
, 1) < 0)
8608 ret
= get_errno(vmsplice(arg1
, vec
, count
, arg4
));
8609 unlock_iovec(vec
, arg2
, count
, 0);
8613 #endif /* CONFIG_SPLICE */
8614 #ifdef CONFIG_EVENTFD
8615 #if defined(TARGET_NR_eventfd)
8616 case TARGET_NR_eventfd
:
8617 ret
= get_errno(eventfd(arg1
, 0));
8620 #if defined(TARGET_NR_eventfd2)
8621 case TARGET_NR_eventfd2
:
8622 ret
= get_errno(eventfd(arg1
, arg2
));
8625 #endif /* CONFIG_EVENTFD */
8626 #if defined(CONFIG_FALLOCATE) && defined(TARGET_NR_fallocate)
8627 case TARGET_NR_fallocate
:
8628 #if TARGET_ABI_BITS == 32
8629 ret
= get_errno(fallocate(arg1
, arg2
, target_offset64(arg3
, arg4
),
8630 target_offset64(arg5
, arg6
)));
8632 ret
= get_errno(fallocate(arg1
, arg2
, arg3
, arg4
));
8636 #if defined(CONFIG_SYNC_FILE_RANGE)
8637 #if defined(TARGET_NR_sync_file_range)
8638 case TARGET_NR_sync_file_range
:
8639 #if TARGET_ABI_BITS == 32
8640 #if defined(TARGET_MIPS)
8641 ret
= get_errno(sync_file_range(arg1
, target_offset64(arg3
, arg4
),
8642 target_offset64(arg5
, arg6
), arg7
));
8644 ret
= get_errno(sync_file_range(arg1
, target_offset64(arg2
, arg3
),
8645 target_offset64(arg4
, arg5
), arg6
));
8646 #endif /* !TARGET_MIPS */
8648 ret
= get_errno(sync_file_range(arg1
, arg2
, arg3
, arg4
));
8652 #if defined(TARGET_NR_sync_file_range2)
8653 case TARGET_NR_sync_file_range2
:
8654 /* This is like sync_file_range but the arguments are reordered */
8655 #if TARGET_ABI_BITS == 32
8656 ret
= get_errno(sync_file_range(arg1
, target_offset64(arg3
, arg4
),
8657 target_offset64(arg5
, arg6
), arg2
));
8659 ret
= get_errno(sync_file_range(arg1
, arg3
, arg4
, arg2
));
8664 #if defined(CONFIG_EPOLL)
8665 #if defined(TARGET_NR_epoll_create)
8666 case TARGET_NR_epoll_create
:
8667 ret
= get_errno(epoll_create(arg1
));
8670 #if defined(TARGET_NR_epoll_create1) && defined(CONFIG_EPOLL_CREATE1)
8671 case TARGET_NR_epoll_create1
:
8672 ret
= get_errno(epoll_create1(arg1
));
8675 #if defined(TARGET_NR_epoll_ctl)
8676 case TARGET_NR_epoll_ctl
:
8678 struct epoll_event ep
;
8679 struct epoll_event
*epp
= 0;
8681 struct target_epoll_event
*target_ep
;
8682 if (!lock_user_struct(VERIFY_READ
, target_ep
, arg4
, 1)) {
8685 ep
.events
= tswap32(target_ep
->events
);
8686 /* The epoll_data_t union is just opaque data to the kernel,
8687 * so we transfer all 64 bits across and need not worry what
8688 * actual data type it is.
8690 ep
.data
.u64
= tswap64(target_ep
->data
.u64
);
8691 unlock_user_struct(target_ep
, arg4
, 0);
8694 ret
= get_errno(epoll_ctl(arg1
, arg2
, arg3
, epp
));
8699 #if defined(TARGET_NR_epoll_pwait) && defined(CONFIG_EPOLL_PWAIT)
8700 #define IMPLEMENT_EPOLL_PWAIT
8702 #if defined(TARGET_NR_epoll_wait) || defined(IMPLEMENT_EPOLL_PWAIT)
8703 #if defined(TARGET_NR_epoll_wait)
8704 case TARGET_NR_epoll_wait
:
8706 #if defined(IMPLEMENT_EPOLL_PWAIT)
8707 case TARGET_NR_epoll_pwait
:
8710 struct target_epoll_event
*target_ep
;
8711 struct epoll_event
*ep
;
8713 int maxevents
= arg3
;
8716 target_ep
= lock_user(VERIFY_WRITE
, arg2
,
8717 maxevents
* sizeof(struct target_epoll_event
), 1);
8722 ep
= alloca(maxevents
* sizeof(struct epoll_event
));
8725 #if defined(IMPLEMENT_EPOLL_PWAIT)
8726 case TARGET_NR_epoll_pwait
:
8728 target_sigset_t
*target_set
;
8729 sigset_t _set
, *set
= &_set
;
8732 target_set
= lock_user(VERIFY_READ
, arg5
,
8733 sizeof(target_sigset_t
), 1);
8735 unlock_user(target_ep
, arg2
, 0);
8738 target_to_host_sigset(set
, target_set
);
8739 unlock_user(target_set
, arg5
, 0);
8744 ret
= get_errno(epoll_pwait(epfd
, ep
, maxevents
, timeout
, set
));
8748 #if defined(TARGET_NR_epoll_wait)
8749 case TARGET_NR_epoll_wait
:
8750 ret
= get_errno(epoll_wait(epfd
, ep
, maxevents
, timeout
));
8754 ret
= -TARGET_ENOSYS
;
8756 if (!is_error(ret
)) {
8758 for (i
= 0; i
< ret
; i
++) {
8759 target_ep
[i
].events
= tswap32(ep
[i
].events
);
8760 target_ep
[i
].data
.u64
= tswap64(ep
[i
].data
.u64
);
8763 unlock_user(target_ep
, arg2
, ret
* sizeof(struct target_epoll_event
));
8768 #ifdef TARGET_NR_prlimit64
8769 case TARGET_NR_prlimit64
:
8771 /* args: pid, resource number, ptr to new rlimit, ptr to old rlimit */
8772 struct target_rlimit64
*target_rnew
, *target_rold
;
8773 struct host_rlimit64 rnew
, rold
, *rnewp
= 0;
8775 if (!lock_user_struct(VERIFY_READ
, target_rnew
, arg3
, 1)) {
8778 rnew
.rlim_cur
= tswap64(target_rnew
->rlim_cur
);
8779 rnew
.rlim_max
= tswap64(target_rnew
->rlim_max
);
8780 unlock_user_struct(target_rnew
, arg3
, 0);
8784 ret
= get_errno(sys_prlimit64(arg1
, arg2
, rnewp
, arg4
? &rold
: 0));
8785 if (!is_error(ret
) && arg4
) {
8786 if (!lock_user_struct(VERIFY_WRITE
, target_rold
, arg4
, 1)) {
8789 target_rold
->rlim_cur
= tswap64(rold
.rlim_cur
);
8790 target_rold
->rlim_max
= tswap64(rold
.rlim_max
);
8791 unlock_user_struct(target_rold
, arg4
, 1);
8798 gemu_log("qemu: Unsupported syscall: %d\n", num
);
8799 #if defined(TARGET_NR_setxattr) || defined(TARGET_NR_get_thread_area) || defined(TARGET_NR_getdomainname) || defined(TARGET_NR_set_robust_list)
8800 unimplemented_nowarn
:
8802 ret
= -TARGET_ENOSYS
;
8807 gemu_log(" = " TARGET_ABI_FMT_ld
"\n", ret
);
8810 print_syscall_ret(num
, ret
);
8813 ret
= -TARGET_EFAULT
;