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 <qemu-common.h>
67 #include <sys/eventfd.h>
70 #define termios host_termios
71 #define winsize host_winsize
72 #define termio host_termio
73 #define sgttyb host_sgttyb /* same as target */
74 #define tchars host_tchars /* same as target */
75 #define ltchars host_ltchars /* same as target */
77 #include <linux/termios.h>
78 #include <linux/unistd.h>
79 #include <linux/utsname.h>
80 #include <linux/cdrom.h>
81 #include <linux/hdreg.h>
82 #include <linux/soundcard.h>
84 #include <linux/mtio.h>
88 #include "linux_loop.h"
89 #include "cpu-uname.h"
92 #include "qemu-common.h"
94 #if defined(CONFIG_USE_NPTL)
95 #define CLONE_NPTL_FLAGS2 (CLONE_SETTLS | \
96 CLONE_PARENT_SETTID | CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID)
98 /* XXX: Hardcode the above values. */
99 #define CLONE_NPTL_FLAGS2 0
104 //#include <linux/msdos_fs.h>
105 #define VFAT_IOCTL_READDIR_BOTH _IOR('r', 1, struct linux_dirent [2])
106 #define VFAT_IOCTL_READDIR_SHORT _IOR('r', 2, struct linux_dirent [2])
117 #define _syscall0(type,name) \
118 static type name (void) \
120 return syscall(__NR_##name); \
123 #define _syscall1(type,name,type1,arg1) \
124 static type name (type1 arg1) \
126 return syscall(__NR_##name, arg1); \
129 #define _syscall2(type,name,type1,arg1,type2,arg2) \
130 static type name (type1 arg1,type2 arg2) \
132 return syscall(__NR_##name, arg1, arg2); \
135 #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
136 static type name (type1 arg1,type2 arg2,type3 arg3) \
138 return syscall(__NR_##name, arg1, arg2, arg3); \
141 #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
142 static type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4) \
144 return syscall(__NR_##name, arg1, arg2, arg3, arg4); \
147 #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
149 static type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \
151 return syscall(__NR_##name, arg1, arg2, arg3, arg4, arg5); \
155 #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
156 type5,arg5,type6,arg6) \
157 static type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5, \
160 return syscall(__NR_##name, arg1, arg2, arg3, arg4, arg5, arg6); \
164 #define __NR_sys_uname __NR_uname
165 #define __NR_sys_faccessat __NR_faccessat
166 #define __NR_sys_fchmodat __NR_fchmodat
167 #define __NR_sys_fchownat __NR_fchownat
168 #define __NR_sys_fstatat64 __NR_fstatat64
169 #define __NR_sys_futimesat __NR_futimesat
170 #define __NR_sys_getcwd1 __NR_getcwd
171 #define __NR_sys_getdents __NR_getdents
172 #define __NR_sys_getdents64 __NR_getdents64
173 #define __NR_sys_getpriority __NR_getpriority
174 #define __NR_sys_linkat __NR_linkat
175 #define __NR_sys_mkdirat __NR_mkdirat
176 #define __NR_sys_mknodat __NR_mknodat
177 #define __NR_sys_newfstatat __NR_newfstatat
178 #define __NR_sys_openat __NR_openat
179 #define __NR_sys_readlinkat __NR_readlinkat
180 #define __NR_sys_renameat __NR_renameat
181 #define __NR_sys_rt_sigqueueinfo __NR_rt_sigqueueinfo
182 #define __NR_sys_symlinkat __NR_symlinkat
183 #define __NR_sys_syslog __NR_syslog
184 #define __NR_sys_tgkill __NR_tgkill
185 #define __NR_sys_tkill __NR_tkill
186 #define __NR_sys_unlinkat __NR_unlinkat
187 #define __NR_sys_utimensat __NR_utimensat
188 #define __NR_sys_futex __NR_futex
189 #define __NR_sys_inotify_init __NR_inotify_init
190 #define __NR_sys_inotify_add_watch __NR_inotify_add_watch
191 #define __NR_sys_inotify_rm_watch __NR_inotify_rm_watch
193 #if defined(__alpha__) || defined (__ia64__) || defined(__x86_64__)
194 #define __NR__llseek __NR_lseek
198 _syscall0(int, gettid
)
200 /* This is a replacement for the host gettid() and must return a host
202 static int gettid(void) {
206 _syscall3(int, sys_getdents
, uint
, fd
, struct linux_dirent
*, dirp
, uint
, count
);
207 #if defined(TARGET_NR_getdents64) && defined(__NR_getdents64)
208 _syscall3(int, sys_getdents64
, uint
, fd
, struct linux_dirent64
*, dirp
, uint
, count
);
210 _syscall2(int, sys_getpriority
, int, which
, int, who
);
211 #if defined(TARGET_NR__llseek) && !defined (__x86_64__)
212 _syscall5(int, _llseek
, uint
, fd
, ulong
, hi
, ulong
, lo
,
213 loff_t
*, res
, uint
, wh
);
215 _syscall3(int,sys_rt_sigqueueinfo
,int,pid
,int,sig
,siginfo_t
*,uinfo
)
216 _syscall3(int,sys_syslog
,int,type
,char*,bufp
,int,len
)
217 #if defined(TARGET_NR_tgkill) && defined(__NR_tgkill)
218 _syscall3(int,sys_tgkill
,int,tgid
,int,pid
,int,sig
)
220 #if defined(TARGET_NR_tkill) && defined(__NR_tkill)
221 _syscall2(int,sys_tkill
,int,tid
,int,sig
)
223 #ifdef __NR_exit_group
224 _syscall1(int,exit_group
,int,error_code
)
226 #if defined(TARGET_NR_set_tid_address) && defined(__NR_set_tid_address)
227 _syscall1(int,set_tid_address
,int *,tidptr
)
229 #if defined(CONFIG_USE_NPTL)
230 #if defined(TARGET_NR_futex) && defined(__NR_futex)
231 _syscall6(int,sys_futex
,int *,uaddr
,int,op
,int,val
,
232 const struct timespec
*,timeout
,int *,uaddr2
,int,val3
)
236 static bitmask_transtbl fcntl_flags_tbl
[] = {
237 { TARGET_O_ACCMODE
, TARGET_O_WRONLY
, O_ACCMODE
, O_WRONLY
, },
238 { TARGET_O_ACCMODE
, TARGET_O_RDWR
, O_ACCMODE
, O_RDWR
, },
239 { TARGET_O_CREAT
, TARGET_O_CREAT
, O_CREAT
, O_CREAT
, },
240 { TARGET_O_EXCL
, TARGET_O_EXCL
, O_EXCL
, O_EXCL
, },
241 { TARGET_O_NOCTTY
, TARGET_O_NOCTTY
, O_NOCTTY
, O_NOCTTY
, },
242 { TARGET_O_TRUNC
, TARGET_O_TRUNC
, O_TRUNC
, O_TRUNC
, },
243 { TARGET_O_APPEND
, TARGET_O_APPEND
, O_APPEND
, O_APPEND
, },
244 { TARGET_O_NONBLOCK
, TARGET_O_NONBLOCK
, O_NONBLOCK
, O_NONBLOCK
, },
245 { TARGET_O_SYNC
, TARGET_O_SYNC
, O_SYNC
, O_SYNC
, },
246 { TARGET_FASYNC
, TARGET_FASYNC
, FASYNC
, FASYNC
, },
247 { TARGET_O_DIRECTORY
, TARGET_O_DIRECTORY
, O_DIRECTORY
, O_DIRECTORY
, },
248 { TARGET_O_NOFOLLOW
, TARGET_O_NOFOLLOW
, O_NOFOLLOW
, O_NOFOLLOW
, },
249 { TARGET_O_LARGEFILE
, TARGET_O_LARGEFILE
, O_LARGEFILE
, O_LARGEFILE
, },
250 #if defined(O_DIRECT)
251 { TARGET_O_DIRECT
, TARGET_O_DIRECT
, O_DIRECT
, O_DIRECT
, },
256 #define COPY_UTSNAME_FIELD(dest, src) \
258 /* __NEW_UTS_LEN doesn't include terminating null */ \
259 (void) strncpy((dest), (src), __NEW_UTS_LEN); \
260 (dest)[__NEW_UTS_LEN] = '\0'; \
263 static int sys_uname(struct new_utsname
*buf
)
265 struct utsname uts_buf
;
267 if (uname(&uts_buf
) < 0)
271 * Just in case these have some differences, we
272 * translate utsname to new_utsname (which is the
273 * struct linux kernel uses).
276 bzero(buf
, sizeof (*buf
));
277 COPY_UTSNAME_FIELD(buf
->sysname
, uts_buf
.sysname
);
278 COPY_UTSNAME_FIELD(buf
->nodename
, uts_buf
.nodename
);
279 COPY_UTSNAME_FIELD(buf
->release
, uts_buf
.release
);
280 COPY_UTSNAME_FIELD(buf
->version
, uts_buf
.version
);
281 COPY_UTSNAME_FIELD(buf
->machine
, uts_buf
.machine
);
283 COPY_UTSNAME_FIELD(buf
->domainname
, uts_buf
.domainname
);
287 #undef COPY_UTSNAME_FIELD
290 static int sys_getcwd1(char *buf
, size_t size
)
292 if (getcwd(buf
, size
) == NULL
) {
293 /* getcwd() sets errno */
296 return strlen(buf
)+1;
301 * Host system seems to have atfile syscall stubs available. We
302 * now enable them one by one as specified by target syscall_nr.h.
305 #ifdef TARGET_NR_faccessat
306 static int sys_faccessat(int dirfd
, const char *pathname
, int mode
)
308 return (faccessat(dirfd
, pathname
, mode
, 0));
311 #ifdef TARGET_NR_fchmodat
312 static int sys_fchmodat(int dirfd
, const char *pathname
, mode_t mode
)
314 return (fchmodat(dirfd
, pathname
, mode
, 0));
317 #if defined(TARGET_NR_fchownat) && defined(USE_UID16)
318 static int sys_fchownat(int dirfd
, const char *pathname
, uid_t owner
,
319 gid_t group
, int flags
)
321 return (fchownat(dirfd
, pathname
, owner
, group
, flags
));
324 #ifdef __NR_fstatat64
325 static int sys_fstatat64(int dirfd
, const char *pathname
, struct stat
*buf
,
328 return (fstatat(dirfd
, pathname
, buf
, flags
));
331 #ifdef __NR_newfstatat
332 static int sys_newfstatat(int dirfd
, const char *pathname
, struct stat
*buf
,
335 return (fstatat(dirfd
, pathname
, buf
, flags
));
338 #ifdef TARGET_NR_futimesat
339 static int sys_futimesat(int dirfd
, const char *pathname
,
340 const struct timeval times
[2])
342 return (futimesat(dirfd
, pathname
, times
));
345 #ifdef TARGET_NR_linkat
346 static int sys_linkat(int olddirfd
, const char *oldpath
,
347 int newdirfd
, const char *newpath
, int flags
)
349 return (linkat(olddirfd
, oldpath
, newdirfd
, newpath
, flags
));
352 #ifdef TARGET_NR_mkdirat
353 static int sys_mkdirat(int dirfd
, const char *pathname
, mode_t mode
)
355 return (mkdirat(dirfd
, pathname
, mode
));
358 #ifdef TARGET_NR_mknodat
359 static int sys_mknodat(int dirfd
, const char *pathname
, mode_t mode
,
362 return (mknodat(dirfd
, pathname
, mode
, dev
));
365 #ifdef TARGET_NR_openat
366 static int sys_openat(int dirfd
, const char *pathname
, int flags
, ...)
369 * open(2) has extra parameter 'mode' when called with
372 if ((flags
& O_CREAT
) != 0) {
377 * Get the 'mode' parameter and translate it to
381 mode
= va_arg(ap
, mode_t
);
382 mode
= target_to_host_bitmask(mode
, fcntl_flags_tbl
);
385 return (openat(dirfd
, pathname
, flags
, mode
));
387 return (openat(dirfd
, pathname
, flags
));
390 #ifdef TARGET_NR_readlinkat
391 static int sys_readlinkat(int dirfd
, const char *pathname
, char *buf
, size_t bufsiz
)
393 return (readlinkat(dirfd
, pathname
, buf
, bufsiz
));
396 #ifdef TARGET_NR_renameat
397 static int sys_renameat(int olddirfd
, const char *oldpath
,
398 int newdirfd
, const char *newpath
)
400 return (renameat(olddirfd
, oldpath
, newdirfd
, newpath
));
403 #ifdef TARGET_NR_symlinkat
404 static int sys_symlinkat(const char *oldpath
, int newdirfd
, const char *newpath
)
406 return (symlinkat(oldpath
, newdirfd
, newpath
));
409 #ifdef TARGET_NR_unlinkat
410 static int sys_unlinkat(int dirfd
, const char *pathname
, int flags
)
412 return (unlinkat(dirfd
, pathname
, flags
));
415 #else /* !CONFIG_ATFILE */
418 * Try direct syscalls instead
420 #if defined(TARGET_NR_faccessat) && defined(__NR_faccessat)
421 _syscall3(int,sys_faccessat
,int,dirfd
,const char *,pathname
,int,mode
)
423 #if defined(TARGET_NR_fchmodat) && defined(__NR_fchmodat)
424 _syscall3(int,sys_fchmodat
,int,dirfd
,const char *,pathname
, mode_t
,mode
)
426 #if defined(TARGET_NR_fchownat) && defined(__NR_fchownat) && defined(USE_UID16)
427 _syscall5(int,sys_fchownat
,int,dirfd
,const char *,pathname
,
428 uid_t
,owner
,gid_t
,group
,int,flags
)
430 #if (defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat)) && \
431 defined(__NR_fstatat64)
432 _syscall4(int,sys_fstatat64
,int,dirfd
,const char *,pathname
,
433 struct stat
*,buf
,int,flags
)
435 #if defined(TARGET_NR_futimesat) && defined(__NR_futimesat)
436 _syscall3(int,sys_futimesat
,int,dirfd
,const char *,pathname
,
437 const struct timeval
*,times
)
439 #if (defined(TARGET_NR_newfstatat) || defined(TARGET_NR_fstatat64) ) && \
440 defined(__NR_newfstatat)
441 _syscall4(int,sys_newfstatat
,int,dirfd
,const char *,pathname
,
442 struct stat
*,buf
,int,flags
)
444 #if defined(TARGET_NR_linkat) && defined(__NR_linkat)
445 _syscall5(int,sys_linkat
,int,olddirfd
,const char *,oldpath
,
446 int,newdirfd
,const char *,newpath
,int,flags
)
448 #if defined(TARGET_NR_mkdirat) && defined(__NR_mkdirat)
449 _syscall3(int,sys_mkdirat
,int,dirfd
,const char *,pathname
,mode_t
,mode
)
451 #if defined(TARGET_NR_mknodat) && defined(__NR_mknodat)
452 _syscall4(int,sys_mknodat
,int,dirfd
,const char *,pathname
,
453 mode_t
,mode
,dev_t
,dev
)
455 #if defined(TARGET_NR_openat) && defined(__NR_openat)
456 _syscall4(int,sys_openat
,int,dirfd
,const char *,pathname
,int,flags
,mode_t
,mode
)
458 #if defined(TARGET_NR_readlinkat) && defined(__NR_readlinkat)
459 _syscall4(int,sys_readlinkat
,int,dirfd
,const char *,pathname
,
460 char *,buf
,size_t,bufsize
)
462 #if defined(TARGET_NR_renameat) && defined(__NR_renameat)
463 _syscall4(int,sys_renameat
,int,olddirfd
,const char *,oldpath
,
464 int,newdirfd
,const char *,newpath
)
466 #if defined(TARGET_NR_symlinkat) && defined(__NR_symlinkat)
467 _syscall3(int,sys_symlinkat
,const char *,oldpath
,
468 int,newdirfd
,const char *,newpath
)
470 #if defined(TARGET_NR_unlinkat) && defined(__NR_unlinkat)
471 _syscall3(int,sys_unlinkat
,int,dirfd
,const char *,pathname
,int,flags
)
474 #endif /* CONFIG_ATFILE */
476 #ifdef CONFIG_UTIMENSAT
477 static int sys_utimensat(int dirfd
, const char *pathname
,
478 const struct timespec times
[2], int flags
)
480 if (pathname
== NULL
)
481 return futimens(dirfd
, times
);
483 return utimensat(dirfd
, pathname
, times
, flags
);
486 #if defined(TARGET_NR_utimensat) && defined(__NR_utimensat)
487 _syscall4(int,sys_utimensat
,int,dirfd
,const char *,pathname
,
488 const struct timespec
*,tsp
,int,flags
)
490 #endif /* CONFIG_UTIMENSAT */
492 #ifdef CONFIG_INOTIFY
493 #include <sys/inotify.h>
495 #if defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init)
496 static int sys_inotify_init(void)
498 return (inotify_init());
501 #if defined(TARGET_NR_inotify_add_watch) && defined(__NR_inotify_add_watch)
502 static int sys_inotify_add_watch(int fd
,const char *pathname
, int32_t mask
)
504 return (inotify_add_watch(fd
, pathname
, mask
));
507 #if defined(TARGET_NR_inotify_rm_watch) && defined(__NR_inotify_rm_watch)
508 static int sys_inotify_rm_watch(int fd
, int32_t wd
)
510 return (inotify_rm_watch(fd
, wd
));
513 #ifdef CONFIG_INOTIFY1
514 #if defined(TARGET_NR_inotify_init1) && defined(__NR_inotify_init1)
515 static int sys_inotify_init1(int flags
)
517 return (inotify_init1(flags
));
522 /* Userspace can usually survive runtime without inotify */
523 #undef TARGET_NR_inotify_init
524 #undef TARGET_NR_inotify_init1
525 #undef TARGET_NR_inotify_add_watch
526 #undef TARGET_NR_inotify_rm_watch
527 #endif /* CONFIG_INOTIFY */
530 extern int personality(int);
531 extern int flock(int, int);
532 extern int setfsuid(int);
533 extern int setfsgid(int);
534 extern int setgroups(int, gid_t
*);
536 #define ERRNO_TABLE_SIZE 1200
538 /* target_to_host_errno_table[] is initialized from
539 * host_to_target_errno_table[] in syscall_init(). */
540 static uint16_t target_to_host_errno_table
[ERRNO_TABLE_SIZE
] = {
544 * This list is the union of errno values overridden in asm-<arch>/errno.h
545 * minus the errnos that are not actually generic to all archs.
547 static uint16_t host_to_target_errno_table
[ERRNO_TABLE_SIZE
] = {
548 [EIDRM
] = TARGET_EIDRM
,
549 [ECHRNG
] = TARGET_ECHRNG
,
550 [EL2NSYNC
] = TARGET_EL2NSYNC
,
551 [EL3HLT
] = TARGET_EL3HLT
,
552 [EL3RST
] = TARGET_EL3RST
,
553 [ELNRNG
] = TARGET_ELNRNG
,
554 [EUNATCH
] = TARGET_EUNATCH
,
555 [ENOCSI
] = TARGET_ENOCSI
,
556 [EL2HLT
] = TARGET_EL2HLT
,
557 [EDEADLK
] = TARGET_EDEADLK
,
558 [ENOLCK
] = TARGET_ENOLCK
,
559 [EBADE
] = TARGET_EBADE
,
560 [EBADR
] = TARGET_EBADR
,
561 [EXFULL
] = TARGET_EXFULL
,
562 [ENOANO
] = TARGET_ENOANO
,
563 [EBADRQC
] = TARGET_EBADRQC
,
564 [EBADSLT
] = TARGET_EBADSLT
,
565 [EBFONT
] = TARGET_EBFONT
,
566 [ENOSTR
] = TARGET_ENOSTR
,
567 [ENODATA
] = TARGET_ENODATA
,
568 [ETIME
] = TARGET_ETIME
,
569 [ENOSR
] = TARGET_ENOSR
,
570 [ENONET
] = TARGET_ENONET
,
571 [ENOPKG
] = TARGET_ENOPKG
,
572 [EREMOTE
] = TARGET_EREMOTE
,
573 [ENOLINK
] = TARGET_ENOLINK
,
574 [EADV
] = TARGET_EADV
,
575 [ESRMNT
] = TARGET_ESRMNT
,
576 [ECOMM
] = TARGET_ECOMM
,
577 [EPROTO
] = TARGET_EPROTO
,
578 [EDOTDOT
] = TARGET_EDOTDOT
,
579 [EMULTIHOP
] = TARGET_EMULTIHOP
,
580 [EBADMSG
] = TARGET_EBADMSG
,
581 [ENAMETOOLONG
] = TARGET_ENAMETOOLONG
,
582 [EOVERFLOW
] = TARGET_EOVERFLOW
,
583 [ENOTUNIQ
] = TARGET_ENOTUNIQ
,
584 [EBADFD
] = TARGET_EBADFD
,
585 [EREMCHG
] = TARGET_EREMCHG
,
586 [ELIBACC
] = TARGET_ELIBACC
,
587 [ELIBBAD
] = TARGET_ELIBBAD
,
588 [ELIBSCN
] = TARGET_ELIBSCN
,
589 [ELIBMAX
] = TARGET_ELIBMAX
,
590 [ELIBEXEC
] = TARGET_ELIBEXEC
,
591 [EILSEQ
] = TARGET_EILSEQ
,
592 [ENOSYS
] = TARGET_ENOSYS
,
593 [ELOOP
] = TARGET_ELOOP
,
594 [ERESTART
] = TARGET_ERESTART
,
595 [ESTRPIPE
] = TARGET_ESTRPIPE
,
596 [ENOTEMPTY
] = TARGET_ENOTEMPTY
,
597 [EUSERS
] = TARGET_EUSERS
,
598 [ENOTSOCK
] = TARGET_ENOTSOCK
,
599 [EDESTADDRREQ
] = TARGET_EDESTADDRREQ
,
600 [EMSGSIZE
] = TARGET_EMSGSIZE
,
601 [EPROTOTYPE
] = TARGET_EPROTOTYPE
,
602 [ENOPROTOOPT
] = TARGET_ENOPROTOOPT
,
603 [EPROTONOSUPPORT
] = TARGET_EPROTONOSUPPORT
,
604 [ESOCKTNOSUPPORT
] = TARGET_ESOCKTNOSUPPORT
,
605 [EOPNOTSUPP
] = TARGET_EOPNOTSUPP
,
606 [EPFNOSUPPORT
] = TARGET_EPFNOSUPPORT
,
607 [EAFNOSUPPORT
] = TARGET_EAFNOSUPPORT
,
608 [EADDRINUSE
] = TARGET_EADDRINUSE
,
609 [EADDRNOTAVAIL
] = TARGET_EADDRNOTAVAIL
,
610 [ENETDOWN
] = TARGET_ENETDOWN
,
611 [ENETUNREACH
] = TARGET_ENETUNREACH
,
612 [ENETRESET
] = TARGET_ENETRESET
,
613 [ECONNABORTED
] = TARGET_ECONNABORTED
,
614 [ECONNRESET
] = TARGET_ECONNRESET
,
615 [ENOBUFS
] = TARGET_ENOBUFS
,
616 [EISCONN
] = TARGET_EISCONN
,
617 [ENOTCONN
] = TARGET_ENOTCONN
,
618 [EUCLEAN
] = TARGET_EUCLEAN
,
619 [ENOTNAM
] = TARGET_ENOTNAM
,
620 [ENAVAIL
] = TARGET_ENAVAIL
,
621 [EISNAM
] = TARGET_EISNAM
,
622 [EREMOTEIO
] = TARGET_EREMOTEIO
,
623 [ESHUTDOWN
] = TARGET_ESHUTDOWN
,
624 [ETOOMANYREFS
] = TARGET_ETOOMANYREFS
,
625 [ETIMEDOUT
] = TARGET_ETIMEDOUT
,
626 [ECONNREFUSED
] = TARGET_ECONNREFUSED
,
627 [EHOSTDOWN
] = TARGET_EHOSTDOWN
,
628 [EHOSTUNREACH
] = TARGET_EHOSTUNREACH
,
629 [EALREADY
] = TARGET_EALREADY
,
630 [EINPROGRESS
] = TARGET_EINPROGRESS
,
631 [ESTALE
] = TARGET_ESTALE
,
632 [ECANCELED
] = TARGET_ECANCELED
,
633 [ENOMEDIUM
] = TARGET_ENOMEDIUM
,
634 [EMEDIUMTYPE
] = TARGET_EMEDIUMTYPE
,
636 [ENOKEY
] = TARGET_ENOKEY
,
639 [EKEYEXPIRED
] = TARGET_EKEYEXPIRED
,
642 [EKEYREVOKED
] = TARGET_EKEYREVOKED
,
645 [EKEYREJECTED
] = TARGET_EKEYREJECTED
,
648 [EOWNERDEAD
] = TARGET_EOWNERDEAD
,
650 #ifdef ENOTRECOVERABLE
651 [ENOTRECOVERABLE
] = TARGET_ENOTRECOVERABLE
,
655 static inline int host_to_target_errno(int err
)
657 if(host_to_target_errno_table
[err
])
658 return host_to_target_errno_table
[err
];
662 static inline int target_to_host_errno(int err
)
664 if (target_to_host_errno_table
[err
])
665 return target_to_host_errno_table
[err
];
669 static inline abi_long
get_errno(abi_long ret
)
672 return -host_to_target_errno(errno
);
677 static inline int is_error(abi_long ret
)
679 return (abi_ulong
)ret
>= (abi_ulong
)(-4096);
682 char *target_strerror(int err
)
684 return strerror(target_to_host_errno(err
));
687 static abi_ulong target_brk
;
688 static abi_ulong target_original_brk
;
690 void target_set_brk(abi_ulong new_brk
)
692 target_original_brk
= target_brk
= HOST_PAGE_ALIGN(new_brk
);
695 /* do_brk() must return target values and target errnos. */
696 abi_long
do_brk(abi_ulong new_brk
)
699 abi_long mapped_addr
;
704 if (new_brk
< target_original_brk
)
707 brk_page
= HOST_PAGE_ALIGN(target_brk
);
709 /* If the new brk is less than this, set it and we're done... */
710 if (new_brk
< brk_page
) {
711 target_brk
= new_brk
;
715 /* We need to allocate more memory after the brk... */
716 new_alloc_size
= HOST_PAGE_ALIGN(new_brk
- brk_page
+ 1);
717 mapped_addr
= get_errno(target_mmap(brk_page
, new_alloc_size
,
718 PROT_READ
|PROT_WRITE
,
719 MAP_ANON
|MAP_FIXED
|MAP_PRIVATE
, 0, 0));
721 if (!is_error(mapped_addr
))
722 target_brk
= new_brk
;
727 static inline abi_long
copy_from_user_fdset(fd_set
*fds
,
728 abi_ulong target_fds_addr
,
732 abi_ulong b
, *target_fds
;
734 nw
= (n
+ TARGET_ABI_BITS
- 1) / TARGET_ABI_BITS
;
735 if (!(target_fds
= lock_user(VERIFY_READ
,
737 sizeof(abi_ulong
) * nw
,
739 return -TARGET_EFAULT
;
743 for (i
= 0; i
< nw
; i
++) {
744 /* grab the abi_ulong */
745 __get_user(b
, &target_fds
[i
]);
746 for (j
= 0; j
< TARGET_ABI_BITS
; j
++) {
747 /* check the bit inside the abi_ulong */
754 unlock_user(target_fds
, target_fds_addr
, 0);
759 static inline abi_long
copy_to_user_fdset(abi_ulong target_fds_addr
,
765 abi_ulong
*target_fds
;
767 nw
= (n
+ TARGET_ABI_BITS
- 1) / TARGET_ABI_BITS
;
768 if (!(target_fds
= lock_user(VERIFY_WRITE
,
770 sizeof(abi_ulong
) * nw
,
772 return -TARGET_EFAULT
;
775 for (i
= 0; i
< nw
; i
++) {
777 for (j
= 0; j
< TARGET_ABI_BITS
; j
++) {
778 v
|= ((FD_ISSET(k
, fds
) != 0) << j
);
781 __put_user(v
, &target_fds
[i
]);
784 unlock_user(target_fds
, target_fds_addr
, sizeof(abi_ulong
) * nw
);
789 #if defined(__alpha__)
795 static inline abi_long
host_to_target_clock_t(long ticks
)
797 #if HOST_HZ == TARGET_HZ
800 return ((int64_t)ticks
* TARGET_HZ
) / HOST_HZ
;
804 static inline abi_long
host_to_target_rusage(abi_ulong target_addr
,
805 const struct rusage
*rusage
)
807 struct target_rusage
*target_rusage
;
809 if (!lock_user_struct(VERIFY_WRITE
, target_rusage
, target_addr
, 0))
810 return -TARGET_EFAULT
;
811 target_rusage
->ru_utime
.tv_sec
= tswapl(rusage
->ru_utime
.tv_sec
);
812 target_rusage
->ru_utime
.tv_usec
= tswapl(rusage
->ru_utime
.tv_usec
);
813 target_rusage
->ru_stime
.tv_sec
= tswapl(rusage
->ru_stime
.tv_sec
);
814 target_rusage
->ru_stime
.tv_usec
= tswapl(rusage
->ru_stime
.tv_usec
);
815 target_rusage
->ru_maxrss
= tswapl(rusage
->ru_maxrss
);
816 target_rusage
->ru_ixrss
= tswapl(rusage
->ru_ixrss
);
817 target_rusage
->ru_idrss
= tswapl(rusage
->ru_idrss
);
818 target_rusage
->ru_isrss
= tswapl(rusage
->ru_isrss
);
819 target_rusage
->ru_minflt
= tswapl(rusage
->ru_minflt
);
820 target_rusage
->ru_majflt
= tswapl(rusage
->ru_majflt
);
821 target_rusage
->ru_nswap
= tswapl(rusage
->ru_nswap
);
822 target_rusage
->ru_inblock
= tswapl(rusage
->ru_inblock
);
823 target_rusage
->ru_oublock
= tswapl(rusage
->ru_oublock
);
824 target_rusage
->ru_msgsnd
= tswapl(rusage
->ru_msgsnd
);
825 target_rusage
->ru_msgrcv
= tswapl(rusage
->ru_msgrcv
);
826 target_rusage
->ru_nsignals
= tswapl(rusage
->ru_nsignals
);
827 target_rusage
->ru_nvcsw
= tswapl(rusage
->ru_nvcsw
);
828 target_rusage
->ru_nivcsw
= tswapl(rusage
->ru_nivcsw
);
829 unlock_user_struct(target_rusage
, target_addr
, 1);
834 static inline rlim_t
target_to_host_rlim(target_ulong target_rlim
)
836 if (target_rlim
== TARGET_RLIM_INFINITY
)
837 return RLIM_INFINITY
;
839 return tswapl(target_rlim
);
842 static inline target_ulong
host_to_target_rlim(rlim_t rlim
)
844 if (rlim
== RLIM_INFINITY
|| rlim
!= (target_long
)rlim
)
845 return TARGET_RLIM_INFINITY
;
850 static inline abi_long
copy_from_user_timeval(struct timeval
*tv
,
851 abi_ulong target_tv_addr
)
853 struct target_timeval
*target_tv
;
855 if (!lock_user_struct(VERIFY_READ
, target_tv
, target_tv_addr
, 1))
856 return -TARGET_EFAULT
;
858 __get_user(tv
->tv_sec
, &target_tv
->tv_sec
);
859 __get_user(tv
->tv_usec
, &target_tv
->tv_usec
);
861 unlock_user_struct(target_tv
, target_tv_addr
, 0);
866 static inline abi_long
copy_to_user_timeval(abi_ulong target_tv_addr
,
867 const struct timeval
*tv
)
869 struct target_timeval
*target_tv
;
871 if (!lock_user_struct(VERIFY_WRITE
, target_tv
, target_tv_addr
, 0))
872 return -TARGET_EFAULT
;
874 __put_user(tv
->tv_sec
, &target_tv
->tv_sec
);
875 __put_user(tv
->tv_usec
, &target_tv
->tv_usec
);
877 unlock_user_struct(target_tv
, target_tv_addr
, 1);
882 #if defined(TARGET_NR_mq_open) && defined(__NR_mq_open)
885 static inline abi_long
copy_from_user_mq_attr(struct mq_attr
*attr
,
886 abi_ulong target_mq_attr_addr
)
888 struct target_mq_attr
*target_mq_attr
;
890 if (!lock_user_struct(VERIFY_READ
, target_mq_attr
,
891 target_mq_attr_addr
, 1))
892 return -TARGET_EFAULT
;
894 __get_user(attr
->mq_flags
, &target_mq_attr
->mq_flags
);
895 __get_user(attr
->mq_maxmsg
, &target_mq_attr
->mq_maxmsg
);
896 __get_user(attr
->mq_msgsize
, &target_mq_attr
->mq_msgsize
);
897 __get_user(attr
->mq_curmsgs
, &target_mq_attr
->mq_curmsgs
);
899 unlock_user_struct(target_mq_attr
, target_mq_attr_addr
, 0);
904 static inline abi_long
copy_to_user_mq_attr(abi_ulong target_mq_attr_addr
,
905 const struct mq_attr
*attr
)
907 struct target_mq_attr
*target_mq_attr
;
909 if (!lock_user_struct(VERIFY_WRITE
, target_mq_attr
,
910 target_mq_attr_addr
, 0))
911 return -TARGET_EFAULT
;
913 __put_user(attr
->mq_flags
, &target_mq_attr
->mq_flags
);
914 __put_user(attr
->mq_maxmsg
, &target_mq_attr
->mq_maxmsg
);
915 __put_user(attr
->mq_msgsize
, &target_mq_attr
->mq_msgsize
);
916 __put_user(attr
->mq_curmsgs
, &target_mq_attr
->mq_curmsgs
);
918 unlock_user_struct(target_mq_attr
, target_mq_attr_addr
, 1);
924 /* do_select() must return target values and target errnos. */
925 static abi_long
do_select(int n
,
926 abi_ulong rfd_addr
, abi_ulong wfd_addr
,
927 abi_ulong efd_addr
, abi_ulong target_tv_addr
)
929 fd_set rfds
, wfds
, efds
;
930 fd_set
*rfds_ptr
, *wfds_ptr
, *efds_ptr
;
931 struct timeval tv
, *tv_ptr
;
935 if (copy_from_user_fdset(&rfds
, rfd_addr
, n
))
936 return -TARGET_EFAULT
;
942 if (copy_from_user_fdset(&wfds
, wfd_addr
, n
))
943 return -TARGET_EFAULT
;
949 if (copy_from_user_fdset(&efds
, efd_addr
, n
))
950 return -TARGET_EFAULT
;
956 if (target_tv_addr
) {
957 if (copy_from_user_timeval(&tv
, target_tv_addr
))
958 return -TARGET_EFAULT
;
964 ret
= get_errno(select(n
, rfds_ptr
, wfds_ptr
, efds_ptr
, tv_ptr
));
966 if (!is_error(ret
)) {
967 if (rfd_addr
&& copy_to_user_fdset(rfd_addr
, &rfds
, n
))
968 return -TARGET_EFAULT
;
969 if (wfd_addr
&& copy_to_user_fdset(wfd_addr
, &wfds
, n
))
970 return -TARGET_EFAULT
;
971 if (efd_addr
&& copy_to_user_fdset(efd_addr
, &efds
, n
))
972 return -TARGET_EFAULT
;
974 if (target_tv_addr
&& copy_to_user_timeval(target_tv_addr
, &tv
))
975 return -TARGET_EFAULT
;
981 static abi_long
do_pipe2(int host_pipe
[], int flags
)
984 return pipe2(host_pipe
, flags
);
990 static abi_long
do_pipe(void *cpu_env
, abi_ulong pipedes
, int flags
)
994 ret
= flags
? do_pipe2(host_pipe
, flags
) : pipe(host_pipe
);
997 return get_errno(ret
);
998 #if defined(TARGET_MIPS)
999 ((CPUMIPSState
*)cpu_env
)->active_tc
.gpr
[3] = host_pipe
[1];
1002 #if defined(TARGET_SH4)
1004 ((CPUSH4State
*)cpu_env
)->gregs
[1] = host_pipe
[1];
1008 if (put_user_s32(host_pipe
[0], pipedes
)
1009 || put_user_s32(host_pipe
[1], pipedes
+ sizeof(host_pipe
[0])))
1010 return -TARGET_EFAULT
;
1012 return get_errno(ret
);
1015 static inline abi_long
target_to_host_ip_mreq(struct ip_mreqn
*mreqn
,
1016 abi_ulong target_addr
,
1019 struct target_ip_mreqn
*target_smreqn
;
1021 target_smreqn
= lock_user(VERIFY_READ
, target_addr
, len
, 1);
1023 return -TARGET_EFAULT
;
1024 mreqn
->imr_multiaddr
.s_addr
= target_smreqn
->imr_multiaddr
.s_addr
;
1025 mreqn
->imr_address
.s_addr
= target_smreqn
->imr_address
.s_addr
;
1026 if (len
== sizeof(struct target_ip_mreqn
))
1027 mreqn
->imr_ifindex
= tswapl(target_smreqn
->imr_ifindex
);
1028 unlock_user(target_smreqn
, target_addr
, 0);
1033 static inline abi_long
target_to_host_sockaddr(struct sockaddr
*addr
,
1034 abi_ulong target_addr
,
1037 const socklen_t unix_maxlen
= sizeof (struct sockaddr_un
);
1038 sa_family_t sa_family
;
1039 struct target_sockaddr
*target_saddr
;
1041 target_saddr
= lock_user(VERIFY_READ
, target_addr
, len
, 1);
1043 return -TARGET_EFAULT
;
1045 sa_family
= tswap16(target_saddr
->sa_family
);
1047 /* Oops. The caller might send a incomplete sun_path; sun_path
1048 * must be terminated by \0 (see the manual page), but
1049 * unfortunately it is quite common to specify sockaddr_un
1050 * length as "strlen(x->sun_path)" while it should be
1051 * "strlen(...) + 1". We'll fix that here if needed.
1052 * Linux kernel has a similar feature.
1055 if (sa_family
== AF_UNIX
) {
1056 if (len
< unix_maxlen
&& len
> 0) {
1057 char *cp
= (char*)target_saddr
;
1059 if ( cp
[len
-1] && !cp
[len
] )
1062 if (len
> unix_maxlen
)
1066 memcpy(addr
, target_saddr
, len
);
1067 addr
->sa_family
= sa_family
;
1068 unlock_user(target_saddr
, target_addr
, 0);
1073 static inline abi_long
host_to_target_sockaddr(abi_ulong target_addr
,
1074 struct sockaddr
*addr
,
1077 struct target_sockaddr
*target_saddr
;
1079 target_saddr
= lock_user(VERIFY_WRITE
, target_addr
, len
, 0);
1081 return -TARGET_EFAULT
;
1082 memcpy(target_saddr
, addr
, len
);
1083 target_saddr
->sa_family
= tswap16(addr
->sa_family
);
1084 unlock_user(target_saddr
, target_addr
, len
);
1089 /* ??? Should this also swap msgh->name? */
1090 static inline abi_long
target_to_host_cmsg(struct msghdr
*msgh
,
1091 struct target_msghdr
*target_msgh
)
1093 struct cmsghdr
*cmsg
= CMSG_FIRSTHDR(msgh
);
1094 abi_long msg_controllen
;
1095 abi_ulong target_cmsg_addr
;
1096 struct target_cmsghdr
*target_cmsg
;
1097 socklen_t space
= 0;
1099 msg_controllen
= tswapl(target_msgh
->msg_controllen
);
1100 if (msg_controllen
< sizeof (struct target_cmsghdr
))
1102 target_cmsg_addr
= tswapl(target_msgh
->msg_control
);
1103 target_cmsg
= lock_user(VERIFY_READ
, target_cmsg_addr
, msg_controllen
, 1);
1105 return -TARGET_EFAULT
;
1107 while (cmsg
&& target_cmsg
) {
1108 void *data
= CMSG_DATA(cmsg
);
1109 void *target_data
= TARGET_CMSG_DATA(target_cmsg
);
1111 int len
= tswapl(target_cmsg
->cmsg_len
)
1112 - TARGET_CMSG_ALIGN(sizeof (struct target_cmsghdr
));
1114 space
+= CMSG_SPACE(len
);
1115 if (space
> msgh
->msg_controllen
) {
1116 space
-= CMSG_SPACE(len
);
1117 gemu_log("Host cmsg overflow\n");
1121 cmsg
->cmsg_level
= tswap32(target_cmsg
->cmsg_level
);
1122 cmsg
->cmsg_type
= tswap32(target_cmsg
->cmsg_type
);
1123 cmsg
->cmsg_len
= CMSG_LEN(len
);
1125 if (cmsg
->cmsg_level
!= TARGET_SOL_SOCKET
|| cmsg
->cmsg_type
!= SCM_RIGHTS
) {
1126 gemu_log("Unsupported ancillary data: %d/%d\n", cmsg
->cmsg_level
, cmsg
->cmsg_type
);
1127 memcpy(data
, target_data
, len
);
1129 int *fd
= (int *)data
;
1130 int *target_fd
= (int *)target_data
;
1131 int i
, numfds
= len
/ sizeof(int);
1133 for (i
= 0; i
< numfds
; i
++)
1134 fd
[i
] = tswap32(target_fd
[i
]);
1137 cmsg
= CMSG_NXTHDR(msgh
, cmsg
);
1138 target_cmsg
= TARGET_CMSG_NXTHDR(target_msgh
, target_cmsg
);
1140 unlock_user(target_cmsg
, target_cmsg_addr
, 0);
1142 msgh
->msg_controllen
= space
;
1146 /* ??? Should this also swap msgh->name? */
1147 static inline abi_long
host_to_target_cmsg(struct target_msghdr
*target_msgh
,
1148 struct msghdr
*msgh
)
1150 struct cmsghdr
*cmsg
= CMSG_FIRSTHDR(msgh
);
1151 abi_long msg_controllen
;
1152 abi_ulong target_cmsg_addr
;
1153 struct target_cmsghdr
*target_cmsg
;
1154 socklen_t space
= 0;
1156 msg_controllen
= tswapl(target_msgh
->msg_controllen
);
1157 if (msg_controllen
< sizeof (struct target_cmsghdr
))
1159 target_cmsg_addr
= tswapl(target_msgh
->msg_control
);
1160 target_cmsg
= lock_user(VERIFY_WRITE
, target_cmsg_addr
, msg_controllen
, 0);
1162 return -TARGET_EFAULT
;
1164 while (cmsg
&& target_cmsg
) {
1165 void *data
= CMSG_DATA(cmsg
);
1166 void *target_data
= TARGET_CMSG_DATA(target_cmsg
);
1168 int len
= cmsg
->cmsg_len
- CMSG_ALIGN(sizeof (struct cmsghdr
));
1170 space
+= TARGET_CMSG_SPACE(len
);
1171 if (space
> msg_controllen
) {
1172 space
-= TARGET_CMSG_SPACE(len
);
1173 gemu_log("Target cmsg overflow\n");
1177 target_cmsg
->cmsg_level
= tswap32(cmsg
->cmsg_level
);
1178 target_cmsg
->cmsg_type
= tswap32(cmsg
->cmsg_type
);
1179 target_cmsg
->cmsg_len
= tswapl(TARGET_CMSG_LEN(len
));
1181 if (cmsg
->cmsg_level
!= TARGET_SOL_SOCKET
|| cmsg
->cmsg_type
!= SCM_RIGHTS
) {
1182 gemu_log("Unsupported ancillary data: %d/%d\n", cmsg
->cmsg_level
, cmsg
->cmsg_type
);
1183 memcpy(target_data
, data
, len
);
1185 int *fd
= (int *)data
;
1186 int *target_fd
= (int *)target_data
;
1187 int i
, numfds
= len
/ sizeof(int);
1189 for (i
= 0; i
< numfds
; i
++)
1190 target_fd
[i
] = tswap32(fd
[i
]);
1193 cmsg
= CMSG_NXTHDR(msgh
, cmsg
);
1194 target_cmsg
= TARGET_CMSG_NXTHDR(target_msgh
, target_cmsg
);
1196 unlock_user(target_cmsg
, target_cmsg_addr
, space
);
1198 target_msgh
->msg_controllen
= tswapl(space
);
1202 /* do_setsockopt() Must return target values and target errnos. */
1203 static abi_long
do_setsockopt(int sockfd
, int level
, int optname
,
1204 abi_ulong optval_addr
, socklen_t optlen
)
1208 struct ip_mreqn
*ip_mreq
;
1209 struct ip_mreq_source
*ip_mreq_source
;
1213 /* TCP options all take an 'int' value. */
1214 if (optlen
< sizeof(uint32_t))
1215 return -TARGET_EINVAL
;
1217 if (get_user_u32(val
, optval_addr
))
1218 return -TARGET_EFAULT
;
1219 ret
= get_errno(setsockopt(sockfd
, level
, optname
, &val
, sizeof(val
)));
1226 case IP_ROUTER_ALERT
:
1230 case IP_MTU_DISCOVER
:
1236 case IP_MULTICAST_TTL
:
1237 case IP_MULTICAST_LOOP
:
1239 if (optlen
>= sizeof(uint32_t)) {
1240 if (get_user_u32(val
, optval_addr
))
1241 return -TARGET_EFAULT
;
1242 } else if (optlen
>= 1) {
1243 if (get_user_u8(val
, optval_addr
))
1244 return -TARGET_EFAULT
;
1246 ret
= get_errno(setsockopt(sockfd
, level
, optname
, &val
, sizeof(val
)));
1248 case IP_ADD_MEMBERSHIP
:
1249 case IP_DROP_MEMBERSHIP
:
1250 if (optlen
< sizeof (struct target_ip_mreq
) ||
1251 optlen
> sizeof (struct target_ip_mreqn
))
1252 return -TARGET_EINVAL
;
1254 ip_mreq
= (struct ip_mreqn
*) alloca(optlen
);
1255 target_to_host_ip_mreq(ip_mreq
, optval_addr
, optlen
);
1256 ret
= get_errno(setsockopt(sockfd
, level
, optname
, ip_mreq
, optlen
));
1259 case IP_BLOCK_SOURCE
:
1260 case IP_UNBLOCK_SOURCE
:
1261 case IP_ADD_SOURCE_MEMBERSHIP
:
1262 case IP_DROP_SOURCE_MEMBERSHIP
:
1263 if (optlen
!= sizeof (struct target_ip_mreq_source
))
1264 return -TARGET_EINVAL
;
1266 ip_mreq_source
= lock_user(VERIFY_READ
, optval_addr
, optlen
, 1);
1267 ret
= get_errno(setsockopt(sockfd
, level
, optname
, ip_mreq_source
, optlen
));
1268 unlock_user (ip_mreq_source
, optval_addr
, 0);
1275 case TARGET_SOL_SOCKET
:
1277 /* Options with 'int' argument. */
1278 case TARGET_SO_DEBUG
:
1281 case TARGET_SO_REUSEADDR
:
1282 optname
= SO_REUSEADDR
;
1284 case TARGET_SO_TYPE
:
1287 case TARGET_SO_ERROR
:
1290 case TARGET_SO_DONTROUTE
:
1291 optname
= SO_DONTROUTE
;
1293 case TARGET_SO_BROADCAST
:
1294 optname
= SO_BROADCAST
;
1296 case TARGET_SO_SNDBUF
:
1297 optname
= SO_SNDBUF
;
1299 case TARGET_SO_RCVBUF
:
1300 optname
= SO_RCVBUF
;
1302 case TARGET_SO_KEEPALIVE
:
1303 optname
= SO_KEEPALIVE
;
1305 case TARGET_SO_OOBINLINE
:
1306 optname
= SO_OOBINLINE
;
1308 case TARGET_SO_NO_CHECK
:
1309 optname
= SO_NO_CHECK
;
1311 case TARGET_SO_PRIORITY
:
1312 optname
= SO_PRIORITY
;
1315 case TARGET_SO_BSDCOMPAT
:
1316 optname
= SO_BSDCOMPAT
;
1319 case TARGET_SO_PASSCRED
:
1320 optname
= SO_PASSCRED
;
1322 case TARGET_SO_TIMESTAMP
:
1323 optname
= SO_TIMESTAMP
;
1325 case TARGET_SO_RCVLOWAT
:
1326 optname
= SO_RCVLOWAT
;
1328 case TARGET_SO_RCVTIMEO
:
1329 optname
= SO_RCVTIMEO
;
1331 case TARGET_SO_SNDTIMEO
:
1332 optname
= SO_SNDTIMEO
;
1338 if (optlen
< sizeof(uint32_t))
1339 return -TARGET_EINVAL
;
1341 if (get_user_u32(val
, optval_addr
))
1342 return -TARGET_EFAULT
;
1343 ret
= get_errno(setsockopt(sockfd
, SOL_SOCKET
, optname
, &val
, sizeof(val
)));
1347 gemu_log("Unsupported setsockopt level=%d optname=%d \n", level
, optname
);
1348 ret
= -TARGET_ENOPROTOOPT
;
1353 /* do_getsockopt() Must return target values and target errnos. */
1354 static abi_long
do_getsockopt(int sockfd
, int level
, int optname
,
1355 abi_ulong optval_addr
, abi_ulong optlen
)
1362 case TARGET_SOL_SOCKET
:
1365 case TARGET_SO_LINGER
:
1366 case TARGET_SO_RCVTIMEO
:
1367 case TARGET_SO_SNDTIMEO
:
1368 case TARGET_SO_PEERCRED
:
1369 case TARGET_SO_PEERNAME
:
1370 /* These don't just return a single integer */
1377 /* TCP options all take an 'int' value. */
1379 if (get_user_u32(len
, optlen
))
1380 return -TARGET_EFAULT
;
1382 return -TARGET_EINVAL
;
1384 ret
= get_errno(getsockopt(sockfd
, level
, optname
, &val
, &lv
));
1390 if (put_user_u32(val
, optval_addr
))
1391 return -TARGET_EFAULT
;
1393 if (put_user_u8(val
, optval_addr
))
1394 return -TARGET_EFAULT
;
1396 if (put_user_u32(len
, optlen
))
1397 return -TARGET_EFAULT
;
1404 case IP_ROUTER_ALERT
:
1408 case IP_MTU_DISCOVER
:
1414 case IP_MULTICAST_TTL
:
1415 case IP_MULTICAST_LOOP
:
1416 if (get_user_u32(len
, optlen
))
1417 return -TARGET_EFAULT
;
1419 return -TARGET_EINVAL
;
1421 ret
= get_errno(getsockopt(sockfd
, level
, optname
, &val
, &lv
));
1424 if (len
< sizeof(int) && len
> 0 && val
>= 0 && val
< 255) {
1426 if (put_user_u32(len
, optlen
)
1427 || put_user_u8(val
, optval_addr
))
1428 return -TARGET_EFAULT
;
1430 if (len
> sizeof(int))
1432 if (put_user_u32(len
, optlen
)
1433 || put_user_u32(val
, optval_addr
))
1434 return -TARGET_EFAULT
;
1438 ret
= -TARGET_ENOPROTOOPT
;
1444 gemu_log("getsockopt level=%d optname=%d not yet supported\n",
1446 ret
= -TARGET_EOPNOTSUPP
;
1453 * lock_iovec()/unlock_iovec() have a return code of 0 for success where
1454 * other lock functions have a return code of 0 for failure.
1456 static abi_long
lock_iovec(int type
, struct iovec
*vec
, abi_ulong target_addr
,
1457 int count
, int copy
)
1459 struct target_iovec
*target_vec
;
1463 target_vec
= lock_user(VERIFY_READ
, target_addr
, count
* sizeof(struct target_iovec
), 1);
1465 return -TARGET_EFAULT
;
1466 for(i
= 0;i
< count
; i
++) {
1467 base
= tswapl(target_vec
[i
].iov_base
);
1468 vec
[i
].iov_len
= tswapl(target_vec
[i
].iov_len
);
1469 if (vec
[i
].iov_len
!= 0) {
1470 vec
[i
].iov_base
= lock_user(type
, base
, vec
[i
].iov_len
, copy
);
1471 /* Don't check lock_user return value. We must call writev even
1472 if a element has invalid base address. */
1474 /* zero length pointer is ignored */
1475 vec
[i
].iov_base
= NULL
;
1478 unlock_user (target_vec
, target_addr
, 0);
1482 static abi_long
unlock_iovec(struct iovec
*vec
, abi_ulong target_addr
,
1483 int count
, int copy
)
1485 struct target_iovec
*target_vec
;
1489 target_vec
= lock_user(VERIFY_READ
, target_addr
, count
* sizeof(struct target_iovec
), 1);
1491 return -TARGET_EFAULT
;
1492 for(i
= 0;i
< count
; i
++) {
1493 if (target_vec
[i
].iov_base
) {
1494 base
= tswapl(target_vec
[i
].iov_base
);
1495 unlock_user(vec
[i
].iov_base
, base
, copy
? vec
[i
].iov_len
: 0);
1498 unlock_user (target_vec
, target_addr
, 0);
1503 /* do_socket() Must return target values and target errnos. */
1504 static abi_long
do_socket(int domain
, int type
, int protocol
)
1506 #if defined(TARGET_MIPS)
1508 case TARGET_SOCK_DGRAM
:
1511 case TARGET_SOCK_STREAM
:
1514 case TARGET_SOCK_RAW
:
1517 case TARGET_SOCK_RDM
:
1520 case TARGET_SOCK_SEQPACKET
:
1521 type
= SOCK_SEQPACKET
;
1523 case TARGET_SOCK_PACKET
:
1528 if (domain
== PF_NETLINK
)
1529 return -EAFNOSUPPORT
; /* do not NETLINK socket connections possible */
1530 return get_errno(socket(domain
, type
, protocol
));
1533 /* do_bind() Must return target values and target errnos. */
1534 static abi_long
do_bind(int sockfd
, abi_ulong target_addr
,
1541 return -TARGET_EINVAL
;
1543 addr
= alloca(addrlen
+1);
1545 ret
= target_to_host_sockaddr(addr
, target_addr
, addrlen
);
1549 return get_errno(bind(sockfd
, addr
, addrlen
));
1552 /* do_connect() Must return target values and target errnos. */
1553 static abi_long
do_connect(int sockfd
, abi_ulong target_addr
,
1560 return -TARGET_EINVAL
;
1562 addr
= alloca(addrlen
);
1564 ret
= target_to_host_sockaddr(addr
, target_addr
, addrlen
);
1568 return get_errno(connect(sockfd
, addr
, addrlen
));
1571 /* do_sendrecvmsg() Must return target values and target errnos. */
1572 static abi_long
do_sendrecvmsg(int fd
, abi_ulong target_msg
,
1573 int flags
, int send
)
1576 struct target_msghdr
*msgp
;
1580 abi_ulong target_vec
;
1583 if (!lock_user_struct(send
? VERIFY_READ
: VERIFY_WRITE
,
1587 return -TARGET_EFAULT
;
1588 if (msgp
->msg_name
) {
1589 msg
.msg_namelen
= tswap32(msgp
->msg_namelen
);
1590 msg
.msg_name
= alloca(msg
.msg_namelen
);
1591 ret
= target_to_host_sockaddr(msg
.msg_name
, tswapl(msgp
->msg_name
),
1594 unlock_user_struct(msgp
, target_msg
, send
? 0 : 1);
1598 msg
.msg_name
= NULL
;
1599 msg
.msg_namelen
= 0;
1601 msg
.msg_controllen
= 2 * tswapl(msgp
->msg_controllen
);
1602 msg
.msg_control
= alloca(msg
.msg_controllen
);
1603 msg
.msg_flags
= tswap32(msgp
->msg_flags
);
1605 count
= tswapl(msgp
->msg_iovlen
);
1606 vec
= alloca(count
* sizeof(struct iovec
));
1607 target_vec
= tswapl(msgp
->msg_iov
);
1608 lock_iovec(send
? VERIFY_READ
: VERIFY_WRITE
, vec
, target_vec
, count
, send
);
1609 msg
.msg_iovlen
= count
;
1613 ret
= target_to_host_cmsg(&msg
, msgp
);
1615 ret
= get_errno(sendmsg(fd
, &msg
, flags
));
1617 ret
= get_errno(recvmsg(fd
, &msg
, flags
));
1618 if (!is_error(ret
)) {
1620 ret
= host_to_target_cmsg(msgp
, &msg
);
1625 unlock_iovec(vec
, target_vec
, count
, !send
);
1626 unlock_user_struct(msgp
, target_msg
, send
? 0 : 1);
1630 /* do_accept() Must return target values and target errnos. */
1631 static abi_long
do_accept(int fd
, abi_ulong target_addr
,
1632 abi_ulong target_addrlen_addr
)
1638 if (target_addr
== 0)
1639 return get_errno(accept(fd
, NULL
, NULL
));
1641 /* linux returns EINVAL if addrlen pointer is invalid */
1642 if (get_user_u32(addrlen
, target_addrlen_addr
))
1643 return -TARGET_EINVAL
;
1646 return -TARGET_EINVAL
;
1648 if (!access_ok(VERIFY_WRITE
, target_addr
, addrlen
))
1649 return -TARGET_EINVAL
;
1651 addr
= alloca(addrlen
);
1653 ret
= get_errno(accept(fd
, addr
, &addrlen
));
1654 if (!is_error(ret
)) {
1655 host_to_target_sockaddr(target_addr
, addr
, addrlen
);
1656 if (put_user_u32(addrlen
, target_addrlen_addr
))
1657 ret
= -TARGET_EFAULT
;
1662 /* do_getpeername() Must return target values and target errnos. */
1663 static abi_long
do_getpeername(int fd
, abi_ulong target_addr
,
1664 abi_ulong target_addrlen_addr
)
1670 if (get_user_u32(addrlen
, target_addrlen_addr
))
1671 return -TARGET_EFAULT
;
1674 return -TARGET_EINVAL
;
1676 if (!access_ok(VERIFY_WRITE
, target_addr
, addrlen
))
1677 return -TARGET_EFAULT
;
1679 addr
= alloca(addrlen
);
1681 ret
= get_errno(getpeername(fd
, addr
, &addrlen
));
1682 if (!is_error(ret
)) {
1683 host_to_target_sockaddr(target_addr
, addr
, addrlen
);
1684 if (put_user_u32(addrlen
, target_addrlen_addr
))
1685 ret
= -TARGET_EFAULT
;
1690 /* do_getsockname() Must return target values and target errnos. */
1691 static abi_long
do_getsockname(int fd
, abi_ulong target_addr
,
1692 abi_ulong target_addrlen_addr
)
1698 if (get_user_u32(addrlen
, target_addrlen_addr
))
1699 return -TARGET_EFAULT
;
1702 return -TARGET_EINVAL
;
1704 if (!access_ok(VERIFY_WRITE
, target_addr
, addrlen
))
1705 return -TARGET_EFAULT
;
1707 addr
= alloca(addrlen
);
1709 ret
= get_errno(getsockname(fd
, addr
, &addrlen
));
1710 if (!is_error(ret
)) {
1711 host_to_target_sockaddr(target_addr
, addr
, addrlen
);
1712 if (put_user_u32(addrlen
, target_addrlen_addr
))
1713 ret
= -TARGET_EFAULT
;
1718 /* do_socketpair() Must return target values and target errnos. */
1719 static abi_long
do_socketpair(int domain
, int type
, int protocol
,
1720 abi_ulong target_tab_addr
)
1725 ret
= get_errno(socketpair(domain
, type
, protocol
, tab
));
1726 if (!is_error(ret
)) {
1727 if (put_user_s32(tab
[0], target_tab_addr
)
1728 || put_user_s32(tab
[1], target_tab_addr
+ sizeof(tab
[0])))
1729 ret
= -TARGET_EFAULT
;
1734 /* do_sendto() Must return target values and target errnos. */
1735 static abi_long
do_sendto(int fd
, abi_ulong msg
, size_t len
, int flags
,
1736 abi_ulong target_addr
, socklen_t addrlen
)
1743 return -TARGET_EINVAL
;
1745 host_msg
= lock_user(VERIFY_READ
, msg
, len
, 1);
1747 return -TARGET_EFAULT
;
1749 addr
= alloca(addrlen
);
1750 ret
= target_to_host_sockaddr(addr
, target_addr
, addrlen
);
1752 unlock_user(host_msg
, msg
, 0);
1755 ret
= get_errno(sendto(fd
, host_msg
, len
, flags
, addr
, addrlen
));
1757 ret
= get_errno(send(fd
, host_msg
, len
, flags
));
1759 unlock_user(host_msg
, msg
, 0);
1763 /* do_recvfrom() Must return target values and target errnos. */
1764 static abi_long
do_recvfrom(int fd
, abi_ulong msg
, size_t len
, int flags
,
1765 abi_ulong target_addr
,
1766 abi_ulong target_addrlen
)
1773 host_msg
= lock_user(VERIFY_WRITE
, msg
, len
, 0);
1775 return -TARGET_EFAULT
;
1777 if (get_user_u32(addrlen
, target_addrlen
)) {
1778 ret
= -TARGET_EFAULT
;
1782 ret
= -TARGET_EINVAL
;
1785 addr
= alloca(addrlen
);
1786 ret
= get_errno(recvfrom(fd
, host_msg
, len
, flags
, addr
, &addrlen
));
1788 addr
= NULL
; /* To keep compiler quiet. */
1789 ret
= get_errno(recv(fd
, host_msg
, len
, flags
));
1791 if (!is_error(ret
)) {
1793 host_to_target_sockaddr(target_addr
, addr
, addrlen
);
1794 if (put_user_u32(addrlen
, target_addrlen
)) {
1795 ret
= -TARGET_EFAULT
;
1799 unlock_user(host_msg
, msg
, len
);
1802 unlock_user(host_msg
, msg
, 0);
1807 #ifdef TARGET_NR_socketcall
1808 /* do_socketcall() Must return target values and target errnos. */
1809 static abi_long
do_socketcall(int num
, abi_ulong vptr
)
1812 const int n
= sizeof(abi_ulong
);
1817 abi_ulong domain
, type
, protocol
;
1819 if (get_user_ual(domain
, vptr
)
1820 || get_user_ual(type
, vptr
+ n
)
1821 || get_user_ual(protocol
, vptr
+ 2 * n
))
1822 return -TARGET_EFAULT
;
1824 ret
= do_socket(domain
, type
, protocol
);
1830 abi_ulong target_addr
;
1833 if (get_user_ual(sockfd
, vptr
)
1834 || get_user_ual(target_addr
, vptr
+ n
)
1835 || get_user_ual(addrlen
, vptr
+ 2 * n
))
1836 return -TARGET_EFAULT
;
1838 ret
= do_bind(sockfd
, target_addr
, addrlen
);
1841 case SOCKOP_connect
:
1844 abi_ulong target_addr
;
1847 if (get_user_ual(sockfd
, vptr
)
1848 || get_user_ual(target_addr
, vptr
+ n
)
1849 || get_user_ual(addrlen
, vptr
+ 2 * n
))
1850 return -TARGET_EFAULT
;
1852 ret
= do_connect(sockfd
, target_addr
, addrlen
);
1857 abi_ulong sockfd
, backlog
;
1859 if (get_user_ual(sockfd
, vptr
)
1860 || get_user_ual(backlog
, vptr
+ n
))
1861 return -TARGET_EFAULT
;
1863 ret
= get_errno(listen(sockfd
, backlog
));
1869 abi_ulong target_addr
, target_addrlen
;
1871 if (get_user_ual(sockfd
, vptr
)
1872 || get_user_ual(target_addr
, vptr
+ n
)
1873 || get_user_ual(target_addrlen
, vptr
+ 2 * n
))
1874 return -TARGET_EFAULT
;
1876 ret
= do_accept(sockfd
, target_addr
, target_addrlen
);
1879 case SOCKOP_getsockname
:
1882 abi_ulong target_addr
, target_addrlen
;
1884 if (get_user_ual(sockfd
, vptr
)
1885 || get_user_ual(target_addr
, vptr
+ n
)
1886 || get_user_ual(target_addrlen
, vptr
+ 2 * n
))
1887 return -TARGET_EFAULT
;
1889 ret
= do_getsockname(sockfd
, target_addr
, target_addrlen
);
1892 case SOCKOP_getpeername
:
1895 abi_ulong target_addr
, target_addrlen
;
1897 if (get_user_ual(sockfd
, vptr
)
1898 || get_user_ual(target_addr
, vptr
+ n
)
1899 || get_user_ual(target_addrlen
, vptr
+ 2 * n
))
1900 return -TARGET_EFAULT
;
1902 ret
= do_getpeername(sockfd
, target_addr
, target_addrlen
);
1905 case SOCKOP_socketpair
:
1907 abi_ulong domain
, type
, protocol
;
1910 if (get_user_ual(domain
, vptr
)
1911 || get_user_ual(type
, vptr
+ n
)
1912 || get_user_ual(protocol
, vptr
+ 2 * n
)
1913 || get_user_ual(tab
, vptr
+ 3 * n
))
1914 return -TARGET_EFAULT
;
1916 ret
= do_socketpair(domain
, type
, protocol
, tab
);
1926 if (get_user_ual(sockfd
, vptr
)
1927 || get_user_ual(msg
, vptr
+ n
)
1928 || get_user_ual(len
, vptr
+ 2 * n
)
1929 || get_user_ual(flags
, vptr
+ 3 * n
))
1930 return -TARGET_EFAULT
;
1932 ret
= do_sendto(sockfd
, msg
, len
, flags
, 0, 0);
1942 if (get_user_ual(sockfd
, vptr
)
1943 || get_user_ual(msg
, vptr
+ n
)
1944 || get_user_ual(len
, vptr
+ 2 * n
)
1945 || get_user_ual(flags
, vptr
+ 3 * n
))
1946 return -TARGET_EFAULT
;
1948 ret
= do_recvfrom(sockfd
, msg
, len
, flags
, 0, 0);
1960 if (get_user_ual(sockfd
, vptr
)
1961 || get_user_ual(msg
, vptr
+ n
)
1962 || get_user_ual(len
, vptr
+ 2 * n
)
1963 || get_user_ual(flags
, vptr
+ 3 * n
)
1964 || get_user_ual(addr
, vptr
+ 4 * n
)
1965 || get_user_ual(addrlen
, vptr
+ 5 * n
))
1966 return -TARGET_EFAULT
;
1968 ret
= do_sendto(sockfd
, msg
, len
, flags
, addr
, addrlen
);
1971 case SOCKOP_recvfrom
:
1980 if (get_user_ual(sockfd
, vptr
)
1981 || get_user_ual(msg
, vptr
+ n
)
1982 || get_user_ual(len
, vptr
+ 2 * n
)
1983 || get_user_ual(flags
, vptr
+ 3 * n
)
1984 || get_user_ual(addr
, vptr
+ 4 * n
)
1985 || get_user_ual(addrlen
, vptr
+ 5 * n
))
1986 return -TARGET_EFAULT
;
1988 ret
= do_recvfrom(sockfd
, msg
, len
, flags
, addr
, addrlen
);
1991 case SOCKOP_shutdown
:
1993 abi_ulong sockfd
, how
;
1995 if (get_user_ual(sockfd
, vptr
)
1996 || get_user_ual(how
, vptr
+ n
))
1997 return -TARGET_EFAULT
;
1999 ret
= get_errno(shutdown(sockfd
, how
));
2002 case SOCKOP_sendmsg
:
2003 case SOCKOP_recvmsg
:
2006 abi_ulong target_msg
;
2009 if (get_user_ual(fd
, vptr
)
2010 || get_user_ual(target_msg
, vptr
+ n
)
2011 || get_user_ual(flags
, vptr
+ 2 * n
))
2012 return -TARGET_EFAULT
;
2014 ret
= do_sendrecvmsg(fd
, target_msg
, flags
,
2015 (num
== SOCKOP_sendmsg
));
2018 case SOCKOP_setsockopt
:
2026 if (get_user_ual(sockfd
, vptr
)
2027 || get_user_ual(level
, vptr
+ n
)
2028 || get_user_ual(optname
, vptr
+ 2 * n
)
2029 || get_user_ual(optval
, vptr
+ 3 * n
)
2030 || get_user_ual(optlen
, vptr
+ 4 * n
))
2031 return -TARGET_EFAULT
;
2033 ret
= do_setsockopt(sockfd
, level
, optname
, optval
, optlen
);
2036 case SOCKOP_getsockopt
:
2044 if (get_user_ual(sockfd
, vptr
)
2045 || get_user_ual(level
, vptr
+ n
)
2046 || get_user_ual(optname
, vptr
+ 2 * n
)
2047 || get_user_ual(optval
, vptr
+ 3 * n
)
2048 || get_user_ual(optlen
, vptr
+ 4 * n
))
2049 return -TARGET_EFAULT
;
2051 ret
= do_getsockopt(sockfd
, level
, optname
, optval
, optlen
);
2055 gemu_log("Unsupported socketcall: %d\n", num
);
2056 ret
= -TARGET_ENOSYS
;
2063 #define N_SHM_REGIONS 32
2065 static struct shm_region
{
2068 } shm_regions
[N_SHM_REGIONS
];
2070 struct target_ipc_perm
2077 unsigned short int mode
;
2078 unsigned short int __pad1
;
2079 unsigned short int __seq
;
2080 unsigned short int __pad2
;
2081 abi_ulong __unused1
;
2082 abi_ulong __unused2
;
2085 struct target_semid_ds
2087 struct target_ipc_perm sem_perm
;
2088 abi_ulong sem_otime
;
2089 abi_ulong __unused1
;
2090 abi_ulong sem_ctime
;
2091 abi_ulong __unused2
;
2092 abi_ulong sem_nsems
;
2093 abi_ulong __unused3
;
2094 abi_ulong __unused4
;
2097 static inline abi_long
target_to_host_ipc_perm(struct ipc_perm
*host_ip
,
2098 abi_ulong target_addr
)
2100 struct target_ipc_perm
*target_ip
;
2101 struct target_semid_ds
*target_sd
;
2103 if (!lock_user_struct(VERIFY_READ
, target_sd
, target_addr
, 1))
2104 return -TARGET_EFAULT
;
2105 target_ip
= &(target_sd
->sem_perm
);
2106 host_ip
->__key
= tswapl(target_ip
->__key
);
2107 host_ip
->uid
= tswapl(target_ip
->uid
);
2108 host_ip
->gid
= tswapl(target_ip
->gid
);
2109 host_ip
->cuid
= tswapl(target_ip
->cuid
);
2110 host_ip
->cgid
= tswapl(target_ip
->cgid
);
2111 host_ip
->mode
= tswapl(target_ip
->mode
);
2112 unlock_user_struct(target_sd
, target_addr
, 0);
2116 static inline abi_long
host_to_target_ipc_perm(abi_ulong target_addr
,
2117 struct ipc_perm
*host_ip
)
2119 struct target_ipc_perm
*target_ip
;
2120 struct target_semid_ds
*target_sd
;
2122 if (!lock_user_struct(VERIFY_WRITE
, target_sd
, target_addr
, 0))
2123 return -TARGET_EFAULT
;
2124 target_ip
= &(target_sd
->sem_perm
);
2125 target_ip
->__key
= tswapl(host_ip
->__key
);
2126 target_ip
->uid
= tswapl(host_ip
->uid
);
2127 target_ip
->gid
= tswapl(host_ip
->gid
);
2128 target_ip
->cuid
= tswapl(host_ip
->cuid
);
2129 target_ip
->cgid
= tswapl(host_ip
->cgid
);
2130 target_ip
->mode
= tswapl(host_ip
->mode
);
2131 unlock_user_struct(target_sd
, target_addr
, 1);
2135 static inline abi_long
target_to_host_semid_ds(struct semid_ds
*host_sd
,
2136 abi_ulong target_addr
)
2138 struct target_semid_ds
*target_sd
;
2140 if (!lock_user_struct(VERIFY_READ
, target_sd
, target_addr
, 1))
2141 return -TARGET_EFAULT
;
2142 if (target_to_host_ipc_perm(&(host_sd
->sem_perm
),target_addr
))
2143 return -TARGET_EFAULT
;
2144 host_sd
->sem_nsems
= tswapl(target_sd
->sem_nsems
);
2145 host_sd
->sem_otime
= tswapl(target_sd
->sem_otime
);
2146 host_sd
->sem_ctime
= tswapl(target_sd
->sem_ctime
);
2147 unlock_user_struct(target_sd
, target_addr
, 0);
2151 static inline abi_long
host_to_target_semid_ds(abi_ulong target_addr
,
2152 struct semid_ds
*host_sd
)
2154 struct target_semid_ds
*target_sd
;
2156 if (!lock_user_struct(VERIFY_WRITE
, target_sd
, target_addr
, 0))
2157 return -TARGET_EFAULT
;
2158 if (host_to_target_ipc_perm(target_addr
,&(host_sd
->sem_perm
)))
2159 return -TARGET_EFAULT
;;
2160 target_sd
->sem_nsems
= tswapl(host_sd
->sem_nsems
);
2161 target_sd
->sem_otime
= tswapl(host_sd
->sem_otime
);
2162 target_sd
->sem_ctime
= tswapl(host_sd
->sem_ctime
);
2163 unlock_user_struct(target_sd
, target_addr
, 1);
2167 struct target_seminfo
{
2180 static inline abi_long
host_to_target_seminfo(abi_ulong target_addr
,
2181 struct seminfo
*host_seminfo
)
2183 struct target_seminfo
*target_seminfo
;
2184 if (!lock_user_struct(VERIFY_WRITE
, target_seminfo
, target_addr
, 0))
2185 return -TARGET_EFAULT
;
2186 __put_user(host_seminfo
->semmap
, &target_seminfo
->semmap
);
2187 __put_user(host_seminfo
->semmni
, &target_seminfo
->semmni
);
2188 __put_user(host_seminfo
->semmns
, &target_seminfo
->semmns
);
2189 __put_user(host_seminfo
->semmnu
, &target_seminfo
->semmnu
);
2190 __put_user(host_seminfo
->semmsl
, &target_seminfo
->semmsl
);
2191 __put_user(host_seminfo
->semopm
, &target_seminfo
->semopm
);
2192 __put_user(host_seminfo
->semume
, &target_seminfo
->semume
);
2193 __put_user(host_seminfo
->semusz
, &target_seminfo
->semusz
);
2194 __put_user(host_seminfo
->semvmx
, &target_seminfo
->semvmx
);
2195 __put_user(host_seminfo
->semaem
, &target_seminfo
->semaem
);
2196 unlock_user_struct(target_seminfo
, target_addr
, 1);
2202 struct semid_ds
*buf
;
2203 unsigned short *array
;
2204 struct seminfo
*__buf
;
2207 union target_semun
{
2214 static inline abi_long
target_to_host_semarray(int semid
, unsigned short **host_array
,
2215 abi_ulong target_addr
)
2218 unsigned short *array
;
2220 struct semid_ds semid_ds
;
2223 semun
.buf
= &semid_ds
;
2225 ret
= semctl(semid
, 0, IPC_STAT
, semun
);
2227 return get_errno(ret
);
2229 nsems
= semid_ds
.sem_nsems
;
2231 *host_array
= malloc(nsems
*sizeof(unsigned short));
2232 array
= lock_user(VERIFY_READ
, target_addr
,
2233 nsems
*sizeof(unsigned short), 1);
2235 return -TARGET_EFAULT
;
2237 for(i
=0; i
<nsems
; i
++) {
2238 __get_user((*host_array
)[i
], &array
[i
]);
2240 unlock_user(array
, target_addr
, 0);
2245 static inline abi_long
host_to_target_semarray(int semid
, abi_ulong target_addr
,
2246 unsigned short **host_array
)
2249 unsigned short *array
;
2251 struct semid_ds semid_ds
;
2254 semun
.buf
= &semid_ds
;
2256 ret
= semctl(semid
, 0, IPC_STAT
, semun
);
2258 return get_errno(ret
);
2260 nsems
= semid_ds
.sem_nsems
;
2262 array
= lock_user(VERIFY_WRITE
, target_addr
,
2263 nsems
*sizeof(unsigned short), 0);
2265 return -TARGET_EFAULT
;
2267 for(i
=0; i
<nsems
; i
++) {
2268 __put_user((*host_array
)[i
], &array
[i
]);
2271 unlock_user(array
, target_addr
, 1);
2276 static inline abi_long
do_semctl(int semid
, int semnum
, int cmd
,
2277 union target_semun target_su
)
2280 struct semid_ds dsarg
;
2281 unsigned short *array
= NULL
;
2282 struct seminfo seminfo
;
2283 abi_long ret
= -TARGET_EINVAL
;
2290 arg
.val
= tswapl(target_su
.val
);
2291 ret
= get_errno(semctl(semid
, semnum
, cmd
, arg
));
2292 target_su
.val
= tswapl(arg
.val
);
2296 err
= target_to_host_semarray(semid
, &array
, target_su
.array
);
2300 ret
= get_errno(semctl(semid
, semnum
, cmd
, arg
));
2301 err
= host_to_target_semarray(semid
, target_su
.array
, &array
);
2308 err
= target_to_host_semid_ds(&dsarg
, target_su
.buf
);
2312 ret
= get_errno(semctl(semid
, semnum
, cmd
, arg
));
2313 err
= host_to_target_semid_ds(target_su
.buf
, &dsarg
);
2319 arg
.__buf
= &seminfo
;
2320 ret
= get_errno(semctl(semid
, semnum
, cmd
, arg
));
2321 err
= host_to_target_seminfo(target_su
.__buf
, &seminfo
);
2329 ret
= get_errno(semctl(semid
, semnum
, cmd
, NULL
));
2336 struct target_sembuf
{
2337 unsigned short sem_num
;
2342 static inline abi_long
target_to_host_sembuf(struct sembuf
*host_sembuf
,
2343 abi_ulong target_addr
,
2346 struct target_sembuf
*target_sembuf
;
2349 target_sembuf
= lock_user(VERIFY_READ
, target_addr
,
2350 nsops
*sizeof(struct target_sembuf
), 1);
2352 return -TARGET_EFAULT
;
2354 for(i
=0; i
<nsops
; i
++) {
2355 __get_user(host_sembuf
[i
].sem_num
, &target_sembuf
[i
].sem_num
);
2356 __get_user(host_sembuf
[i
].sem_op
, &target_sembuf
[i
].sem_op
);
2357 __get_user(host_sembuf
[i
].sem_flg
, &target_sembuf
[i
].sem_flg
);
2360 unlock_user(target_sembuf
, target_addr
, 0);
2365 static inline abi_long
do_semop(int semid
, abi_long ptr
, unsigned nsops
)
2367 struct sembuf sops
[nsops
];
2369 if (target_to_host_sembuf(sops
, ptr
, nsops
))
2370 return -TARGET_EFAULT
;
2372 return semop(semid
, sops
, nsops
);
2375 struct target_msqid_ds
2377 struct target_ipc_perm msg_perm
;
2378 abi_ulong msg_stime
;
2379 #if TARGET_ABI_BITS == 32
2380 abi_ulong __unused1
;
2382 abi_ulong msg_rtime
;
2383 #if TARGET_ABI_BITS == 32
2384 abi_ulong __unused2
;
2386 abi_ulong msg_ctime
;
2387 #if TARGET_ABI_BITS == 32
2388 abi_ulong __unused3
;
2390 abi_ulong __msg_cbytes
;
2392 abi_ulong msg_qbytes
;
2393 abi_ulong msg_lspid
;
2394 abi_ulong msg_lrpid
;
2395 abi_ulong __unused4
;
2396 abi_ulong __unused5
;
2399 static inline abi_long
target_to_host_msqid_ds(struct msqid_ds
*host_md
,
2400 abi_ulong target_addr
)
2402 struct target_msqid_ds
*target_md
;
2404 if (!lock_user_struct(VERIFY_READ
, target_md
, target_addr
, 1))
2405 return -TARGET_EFAULT
;
2406 if (target_to_host_ipc_perm(&(host_md
->msg_perm
),target_addr
))
2407 return -TARGET_EFAULT
;
2408 host_md
->msg_stime
= tswapl(target_md
->msg_stime
);
2409 host_md
->msg_rtime
= tswapl(target_md
->msg_rtime
);
2410 host_md
->msg_ctime
= tswapl(target_md
->msg_ctime
);
2411 host_md
->__msg_cbytes
= tswapl(target_md
->__msg_cbytes
);
2412 host_md
->msg_qnum
= tswapl(target_md
->msg_qnum
);
2413 host_md
->msg_qbytes
= tswapl(target_md
->msg_qbytes
);
2414 host_md
->msg_lspid
= tswapl(target_md
->msg_lspid
);
2415 host_md
->msg_lrpid
= tswapl(target_md
->msg_lrpid
);
2416 unlock_user_struct(target_md
, target_addr
, 0);
2420 static inline abi_long
host_to_target_msqid_ds(abi_ulong target_addr
,
2421 struct msqid_ds
*host_md
)
2423 struct target_msqid_ds
*target_md
;
2425 if (!lock_user_struct(VERIFY_WRITE
, target_md
, target_addr
, 0))
2426 return -TARGET_EFAULT
;
2427 if (host_to_target_ipc_perm(target_addr
,&(host_md
->msg_perm
)))
2428 return -TARGET_EFAULT
;
2429 target_md
->msg_stime
= tswapl(host_md
->msg_stime
);
2430 target_md
->msg_rtime
= tswapl(host_md
->msg_rtime
);
2431 target_md
->msg_ctime
= tswapl(host_md
->msg_ctime
);
2432 target_md
->__msg_cbytes
= tswapl(host_md
->__msg_cbytes
);
2433 target_md
->msg_qnum
= tswapl(host_md
->msg_qnum
);
2434 target_md
->msg_qbytes
= tswapl(host_md
->msg_qbytes
);
2435 target_md
->msg_lspid
= tswapl(host_md
->msg_lspid
);
2436 target_md
->msg_lrpid
= tswapl(host_md
->msg_lrpid
);
2437 unlock_user_struct(target_md
, target_addr
, 1);
2441 struct target_msginfo
{
2449 unsigned short int msgseg
;
2452 static inline abi_long
host_to_target_msginfo(abi_ulong target_addr
,
2453 struct msginfo
*host_msginfo
)
2455 struct target_msginfo
*target_msginfo
;
2456 if (!lock_user_struct(VERIFY_WRITE
, target_msginfo
, target_addr
, 0))
2457 return -TARGET_EFAULT
;
2458 __put_user(host_msginfo
->msgpool
, &target_msginfo
->msgpool
);
2459 __put_user(host_msginfo
->msgmap
, &target_msginfo
->msgmap
);
2460 __put_user(host_msginfo
->msgmax
, &target_msginfo
->msgmax
);
2461 __put_user(host_msginfo
->msgmnb
, &target_msginfo
->msgmnb
);
2462 __put_user(host_msginfo
->msgmni
, &target_msginfo
->msgmni
);
2463 __put_user(host_msginfo
->msgssz
, &target_msginfo
->msgssz
);
2464 __put_user(host_msginfo
->msgtql
, &target_msginfo
->msgtql
);
2465 __put_user(host_msginfo
->msgseg
, &target_msginfo
->msgseg
);
2466 unlock_user_struct(target_msginfo
, target_addr
, 1);
2470 static inline abi_long
do_msgctl(int msgid
, int cmd
, abi_long ptr
)
2472 struct msqid_ds dsarg
;
2473 struct msginfo msginfo
;
2474 abi_long ret
= -TARGET_EINVAL
;
2482 if (target_to_host_msqid_ds(&dsarg
,ptr
))
2483 return -TARGET_EFAULT
;
2484 ret
= get_errno(msgctl(msgid
, cmd
, &dsarg
));
2485 if (host_to_target_msqid_ds(ptr
,&dsarg
))
2486 return -TARGET_EFAULT
;
2489 ret
= get_errno(msgctl(msgid
, cmd
, NULL
));
2493 ret
= get_errno(msgctl(msgid
, cmd
, (struct msqid_ds
*)&msginfo
));
2494 if (host_to_target_msginfo(ptr
, &msginfo
))
2495 return -TARGET_EFAULT
;
2502 struct target_msgbuf
{
2507 static inline abi_long
do_msgsnd(int msqid
, abi_long msgp
,
2508 unsigned int msgsz
, int msgflg
)
2510 struct target_msgbuf
*target_mb
;
2511 struct msgbuf
*host_mb
;
2514 if (!lock_user_struct(VERIFY_READ
, target_mb
, msgp
, 0))
2515 return -TARGET_EFAULT
;
2516 host_mb
= malloc(msgsz
+sizeof(long));
2517 host_mb
->mtype
= (abi_long
) tswapl(target_mb
->mtype
);
2518 memcpy(host_mb
->mtext
, target_mb
->mtext
, msgsz
);
2519 ret
= get_errno(msgsnd(msqid
, host_mb
, msgsz
, msgflg
));
2521 unlock_user_struct(target_mb
, msgp
, 0);
2526 static inline abi_long
do_msgrcv(int msqid
, abi_long msgp
,
2527 unsigned int msgsz
, abi_long msgtyp
,
2530 struct target_msgbuf
*target_mb
;
2532 struct msgbuf
*host_mb
;
2535 if (!lock_user_struct(VERIFY_WRITE
, target_mb
, msgp
, 0))
2536 return -TARGET_EFAULT
;
2538 host_mb
= malloc(msgsz
+sizeof(long));
2539 ret
= get_errno(msgrcv(msqid
, host_mb
, msgsz
, tswapl(msgtyp
), msgflg
));
2542 abi_ulong target_mtext_addr
= msgp
+ sizeof(abi_ulong
);
2543 target_mtext
= lock_user(VERIFY_WRITE
, target_mtext_addr
, ret
, 0);
2544 if (!target_mtext
) {
2545 ret
= -TARGET_EFAULT
;
2548 memcpy(target_mb
->mtext
, host_mb
->mtext
, ret
);
2549 unlock_user(target_mtext
, target_mtext_addr
, ret
);
2552 target_mb
->mtype
= tswapl(host_mb
->mtype
);
2557 unlock_user_struct(target_mb
, msgp
, 1);
2561 struct target_shmid_ds
2563 struct target_ipc_perm shm_perm
;
2564 abi_ulong shm_segsz
;
2565 abi_ulong shm_atime
;
2566 #if TARGET_ABI_BITS == 32
2567 abi_ulong __unused1
;
2569 abi_ulong shm_dtime
;
2570 #if TARGET_ABI_BITS == 32
2571 abi_ulong __unused2
;
2573 abi_ulong shm_ctime
;
2574 #if TARGET_ABI_BITS == 32
2575 abi_ulong __unused3
;
2579 abi_ulong shm_nattch
;
2580 unsigned long int __unused4
;
2581 unsigned long int __unused5
;
2584 static inline abi_long
target_to_host_shmid_ds(struct shmid_ds
*host_sd
,
2585 abi_ulong target_addr
)
2587 struct target_shmid_ds
*target_sd
;
2589 if (!lock_user_struct(VERIFY_READ
, target_sd
, target_addr
, 1))
2590 return -TARGET_EFAULT
;
2591 if (target_to_host_ipc_perm(&(host_sd
->shm_perm
), target_addr
))
2592 return -TARGET_EFAULT
;
2593 __get_user(host_sd
->shm_segsz
, &target_sd
->shm_segsz
);
2594 __get_user(host_sd
->shm_atime
, &target_sd
->shm_atime
);
2595 __get_user(host_sd
->shm_dtime
, &target_sd
->shm_dtime
);
2596 __get_user(host_sd
->shm_ctime
, &target_sd
->shm_ctime
);
2597 __get_user(host_sd
->shm_cpid
, &target_sd
->shm_cpid
);
2598 __get_user(host_sd
->shm_lpid
, &target_sd
->shm_lpid
);
2599 __get_user(host_sd
->shm_nattch
, &target_sd
->shm_nattch
);
2600 unlock_user_struct(target_sd
, target_addr
, 0);
2604 static inline abi_long
host_to_target_shmid_ds(abi_ulong target_addr
,
2605 struct shmid_ds
*host_sd
)
2607 struct target_shmid_ds
*target_sd
;
2609 if (!lock_user_struct(VERIFY_WRITE
, target_sd
, target_addr
, 0))
2610 return -TARGET_EFAULT
;
2611 if (host_to_target_ipc_perm(target_addr
, &(host_sd
->shm_perm
)))
2612 return -TARGET_EFAULT
;
2613 __put_user(host_sd
->shm_segsz
, &target_sd
->shm_segsz
);
2614 __put_user(host_sd
->shm_atime
, &target_sd
->shm_atime
);
2615 __put_user(host_sd
->shm_dtime
, &target_sd
->shm_dtime
);
2616 __put_user(host_sd
->shm_ctime
, &target_sd
->shm_ctime
);
2617 __put_user(host_sd
->shm_cpid
, &target_sd
->shm_cpid
);
2618 __put_user(host_sd
->shm_lpid
, &target_sd
->shm_lpid
);
2619 __put_user(host_sd
->shm_nattch
, &target_sd
->shm_nattch
);
2620 unlock_user_struct(target_sd
, target_addr
, 1);
2624 struct target_shminfo
{
2632 static inline abi_long
host_to_target_shminfo(abi_ulong target_addr
,
2633 struct shminfo
*host_shminfo
)
2635 struct target_shminfo
*target_shminfo
;
2636 if (!lock_user_struct(VERIFY_WRITE
, target_shminfo
, target_addr
, 0))
2637 return -TARGET_EFAULT
;
2638 __put_user(host_shminfo
->shmmax
, &target_shminfo
->shmmax
);
2639 __put_user(host_shminfo
->shmmin
, &target_shminfo
->shmmin
);
2640 __put_user(host_shminfo
->shmmni
, &target_shminfo
->shmmni
);
2641 __put_user(host_shminfo
->shmseg
, &target_shminfo
->shmseg
);
2642 __put_user(host_shminfo
->shmall
, &target_shminfo
->shmall
);
2643 unlock_user_struct(target_shminfo
, target_addr
, 1);
2647 struct target_shm_info
{
2652 abi_ulong swap_attempts
;
2653 abi_ulong swap_successes
;
2656 static inline abi_long
host_to_target_shm_info(abi_ulong target_addr
,
2657 struct shm_info
*host_shm_info
)
2659 struct target_shm_info
*target_shm_info
;
2660 if (!lock_user_struct(VERIFY_WRITE
, target_shm_info
, target_addr
, 0))
2661 return -TARGET_EFAULT
;
2662 __put_user(host_shm_info
->used_ids
, &target_shm_info
->used_ids
);
2663 __put_user(host_shm_info
->shm_tot
, &target_shm_info
->shm_tot
);
2664 __put_user(host_shm_info
->shm_rss
, &target_shm_info
->shm_rss
);
2665 __put_user(host_shm_info
->shm_swp
, &target_shm_info
->shm_swp
);
2666 __put_user(host_shm_info
->swap_attempts
, &target_shm_info
->swap_attempts
);
2667 __put_user(host_shm_info
->swap_successes
, &target_shm_info
->swap_successes
);
2668 unlock_user_struct(target_shm_info
, target_addr
, 1);
2672 static inline abi_long
do_shmctl(int shmid
, int cmd
, abi_long buf
)
2674 struct shmid_ds dsarg
;
2675 struct shminfo shminfo
;
2676 struct shm_info shm_info
;
2677 abi_long ret
= -TARGET_EINVAL
;
2685 if (target_to_host_shmid_ds(&dsarg
, buf
))
2686 return -TARGET_EFAULT
;
2687 ret
= get_errno(shmctl(shmid
, cmd
, &dsarg
));
2688 if (host_to_target_shmid_ds(buf
, &dsarg
))
2689 return -TARGET_EFAULT
;
2692 ret
= get_errno(shmctl(shmid
, cmd
, (struct shmid_ds
*)&shminfo
));
2693 if (host_to_target_shminfo(buf
, &shminfo
))
2694 return -TARGET_EFAULT
;
2697 ret
= get_errno(shmctl(shmid
, cmd
, (struct shmid_ds
*)&shm_info
));
2698 if (host_to_target_shm_info(buf
, &shm_info
))
2699 return -TARGET_EFAULT
;
2704 ret
= get_errno(shmctl(shmid
, cmd
, NULL
));
2711 static inline abi_ulong
do_shmat(int shmid
, abi_ulong shmaddr
, int shmflg
)
2715 struct shmid_ds shm_info
;
2718 /* find out the length of the shared memory segment */
2719 ret
= get_errno(shmctl(shmid
, IPC_STAT
, &shm_info
));
2720 if (is_error(ret
)) {
2721 /* can't get length, bail out */
2728 host_raddr
= shmat(shmid
, (void *)g2h(shmaddr
), shmflg
);
2730 abi_ulong mmap_start
;
2732 mmap_start
= mmap_find_vma(0, shm_info
.shm_segsz
);
2734 if (mmap_start
== -1) {
2736 host_raddr
= (void *)-1;
2738 host_raddr
= shmat(shmid
, g2h(mmap_start
), shmflg
| SHM_REMAP
);
2741 if (host_raddr
== (void *)-1) {
2743 return get_errno((long)host_raddr
);
2745 raddr
=h2g((unsigned long)host_raddr
);
2747 page_set_flags(raddr
, raddr
+ shm_info
.shm_segsz
,
2748 PAGE_VALID
| PAGE_READ
|
2749 ((shmflg
& SHM_RDONLY
)? 0 : PAGE_WRITE
));
2751 for (i
= 0; i
< N_SHM_REGIONS
; i
++) {
2752 if (shm_regions
[i
].start
== 0) {
2753 shm_regions
[i
].start
= raddr
;
2754 shm_regions
[i
].size
= shm_info
.shm_segsz
;
2764 static inline abi_long
do_shmdt(abi_ulong shmaddr
)
2768 for (i
= 0; i
< N_SHM_REGIONS
; ++i
) {
2769 if (shm_regions
[i
].start
== shmaddr
) {
2770 shm_regions
[i
].start
= 0;
2771 page_set_flags(shmaddr
, shmaddr
+ shm_regions
[i
].size
, 0);
2776 return get_errno(shmdt(g2h(shmaddr
)));
2779 #ifdef TARGET_NR_ipc
2780 /* ??? This only works with linear mappings. */
2781 /* do_ipc() must return target values and target errnos. */
2782 static abi_long
do_ipc(unsigned int call
, int first
,
2783 int second
, int third
,
2784 abi_long ptr
, abi_long fifth
)
2789 version
= call
>> 16;
2794 ret
= do_semop(first
, ptr
, second
);
2798 ret
= get_errno(semget(first
, second
, third
));
2802 ret
= do_semctl(first
, second
, third
, (union target_semun
)(abi_ulong
) ptr
);
2806 ret
= get_errno(msgget(first
, second
));
2810 ret
= do_msgsnd(first
, ptr
, second
, third
);
2814 ret
= do_msgctl(first
, second
, ptr
);
2821 struct target_ipc_kludge
{
2826 if (!lock_user_struct(VERIFY_READ
, tmp
, ptr
, 1)) {
2827 ret
= -TARGET_EFAULT
;
2831 ret
= do_msgrcv(first
, tmp
->msgp
, second
, tmp
->msgtyp
, third
);
2833 unlock_user_struct(tmp
, ptr
, 0);
2837 ret
= do_msgrcv(first
, ptr
, second
, fifth
, third
);
2846 raddr
= do_shmat(first
, ptr
, second
);
2847 if (is_error(raddr
))
2848 return get_errno(raddr
);
2849 if (put_user_ual(raddr
, third
))
2850 return -TARGET_EFAULT
;
2854 ret
= -TARGET_EINVAL
;
2859 ret
= do_shmdt(ptr
);
2863 /* IPC_* flag values are the same on all linux platforms */
2864 ret
= get_errno(shmget(first
, second
, third
));
2867 /* IPC_* and SHM_* command values are the same on all linux platforms */
2869 ret
= do_shmctl(first
, second
, third
);
2872 gemu_log("Unsupported ipc call: %d (version %d)\n", call
, version
);
2873 ret
= -TARGET_ENOSYS
;
2880 /* kernel structure types definitions */
2883 #define STRUCT(name, ...) STRUCT_ ## name,
2884 #define STRUCT_SPECIAL(name) STRUCT_ ## name,
2886 #include "syscall_types.h"
2889 #undef STRUCT_SPECIAL
2891 #define STRUCT(name, ...) static const argtype struct_ ## name ## _def[] = { __VA_ARGS__, TYPE_NULL };
2892 #define STRUCT_SPECIAL(name)
2893 #include "syscall_types.h"
2895 #undef STRUCT_SPECIAL
2897 typedef struct IOCTLEntry
{
2898 unsigned int target_cmd
;
2899 unsigned int host_cmd
;
2902 const argtype arg_type
[5];
2905 #define IOC_R 0x0001
2906 #define IOC_W 0x0002
2907 #define IOC_RW (IOC_R | IOC_W)
2909 #define MAX_STRUCT_SIZE 4096
2911 static IOCTLEntry ioctl_entries
[] = {
2912 #define IOCTL(cmd, access, ...) \
2913 { TARGET_ ## cmd, cmd, #cmd, access, { __VA_ARGS__ } },
2918 /* ??? Implement proper locking for ioctls. */
2919 /* do_ioctl() Must return target values and target errnos. */
2920 static abi_long
do_ioctl(int fd
, abi_long cmd
, abi_long arg
)
2922 const IOCTLEntry
*ie
;
2923 const argtype
*arg_type
;
2925 uint8_t buf_temp
[MAX_STRUCT_SIZE
];
2931 if (ie
->target_cmd
== 0) {
2932 gemu_log("Unsupported ioctl: cmd=0x%04lx\n", (long)cmd
);
2933 return -TARGET_ENOSYS
;
2935 if (ie
->target_cmd
== cmd
)
2939 arg_type
= ie
->arg_type
;
2941 gemu_log("ioctl: cmd=0x%04lx (%s)\n", (long)cmd
, ie
->name
);
2943 switch(arg_type
[0]) {
2946 ret
= get_errno(ioctl(fd
, ie
->host_cmd
));
2951 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, arg
));
2955 target_size
= thunk_type_size(arg_type
, 0);
2956 switch(ie
->access
) {
2958 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, buf_temp
));
2959 if (!is_error(ret
)) {
2960 argptr
= lock_user(VERIFY_WRITE
, arg
, target_size
, 0);
2962 return -TARGET_EFAULT
;
2963 thunk_convert(argptr
, buf_temp
, arg_type
, THUNK_TARGET
);
2964 unlock_user(argptr
, arg
, target_size
);
2968 argptr
= lock_user(VERIFY_READ
, arg
, target_size
, 1);
2970 return -TARGET_EFAULT
;
2971 thunk_convert(buf_temp
, argptr
, arg_type
, THUNK_HOST
);
2972 unlock_user(argptr
, arg
, 0);
2973 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, buf_temp
));
2977 argptr
= lock_user(VERIFY_READ
, arg
, target_size
, 1);
2979 return -TARGET_EFAULT
;
2980 thunk_convert(buf_temp
, argptr
, arg_type
, THUNK_HOST
);
2981 unlock_user(argptr
, arg
, 0);
2982 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, buf_temp
));
2983 if (!is_error(ret
)) {
2984 argptr
= lock_user(VERIFY_WRITE
, arg
, target_size
, 0);
2986 return -TARGET_EFAULT
;
2987 thunk_convert(argptr
, buf_temp
, arg_type
, THUNK_TARGET
);
2988 unlock_user(argptr
, arg
, target_size
);
2994 gemu_log("Unsupported ioctl type: cmd=0x%04lx type=%d\n",
2995 (long)cmd
, arg_type
[0]);
2996 ret
= -TARGET_ENOSYS
;
3002 static const bitmask_transtbl iflag_tbl
[] = {
3003 { TARGET_IGNBRK
, TARGET_IGNBRK
, IGNBRK
, IGNBRK
},
3004 { TARGET_BRKINT
, TARGET_BRKINT
, BRKINT
, BRKINT
},
3005 { TARGET_IGNPAR
, TARGET_IGNPAR
, IGNPAR
, IGNPAR
},
3006 { TARGET_PARMRK
, TARGET_PARMRK
, PARMRK
, PARMRK
},
3007 { TARGET_INPCK
, TARGET_INPCK
, INPCK
, INPCK
},
3008 { TARGET_ISTRIP
, TARGET_ISTRIP
, ISTRIP
, ISTRIP
},
3009 { TARGET_INLCR
, TARGET_INLCR
, INLCR
, INLCR
},
3010 { TARGET_IGNCR
, TARGET_IGNCR
, IGNCR
, IGNCR
},
3011 { TARGET_ICRNL
, TARGET_ICRNL
, ICRNL
, ICRNL
},
3012 { TARGET_IUCLC
, TARGET_IUCLC
, IUCLC
, IUCLC
},
3013 { TARGET_IXON
, TARGET_IXON
, IXON
, IXON
},
3014 { TARGET_IXANY
, TARGET_IXANY
, IXANY
, IXANY
},
3015 { TARGET_IXOFF
, TARGET_IXOFF
, IXOFF
, IXOFF
},
3016 { TARGET_IMAXBEL
, TARGET_IMAXBEL
, IMAXBEL
, IMAXBEL
},
3020 static const bitmask_transtbl oflag_tbl
[] = {
3021 { TARGET_OPOST
, TARGET_OPOST
, OPOST
, OPOST
},
3022 { TARGET_OLCUC
, TARGET_OLCUC
, OLCUC
, OLCUC
},
3023 { TARGET_ONLCR
, TARGET_ONLCR
, ONLCR
, ONLCR
},
3024 { TARGET_OCRNL
, TARGET_OCRNL
, OCRNL
, OCRNL
},
3025 { TARGET_ONOCR
, TARGET_ONOCR
, ONOCR
, ONOCR
},
3026 { TARGET_ONLRET
, TARGET_ONLRET
, ONLRET
, ONLRET
},
3027 { TARGET_OFILL
, TARGET_OFILL
, OFILL
, OFILL
},
3028 { TARGET_OFDEL
, TARGET_OFDEL
, OFDEL
, OFDEL
},
3029 { TARGET_NLDLY
, TARGET_NL0
, NLDLY
, NL0
},
3030 { TARGET_NLDLY
, TARGET_NL1
, NLDLY
, NL1
},
3031 { TARGET_CRDLY
, TARGET_CR0
, CRDLY
, CR0
},
3032 { TARGET_CRDLY
, TARGET_CR1
, CRDLY
, CR1
},
3033 { TARGET_CRDLY
, TARGET_CR2
, CRDLY
, CR2
},
3034 { TARGET_CRDLY
, TARGET_CR3
, CRDLY
, CR3
},
3035 { TARGET_TABDLY
, TARGET_TAB0
, TABDLY
, TAB0
},
3036 { TARGET_TABDLY
, TARGET_TAB1
, TABDLY
, TAB1
},
3037 { TARGET_TABDLY
, TARGET_TAB2
, TABDLY
, TAB2
},
3038 { TARGET_TABDLY
, TARGET_TAB3
, TABDLY
, TAB3
},
3039 { TARGET_BSDLY
, TARGET_BS0
, BSDLY
, BS0
},
3040 { TARGET_BSDLY
, TARGET_BS1
, BSDLY
, BS1
},
3041 { TARGET_VTDLY
, TARGET_VT0
, VTDLY
, VT0
},
3042 { TARGET_VTDLY
, TARGET_VT1
, VTDLY
, VT1
},
3043 { TARGET_FFDLY
, TARGET_FF0
, FFDLY
, FF0
},
3044 { TARGET_FFDLY
, TARGET_FF1
, FFDLY
, FF1
},
3048 static const bitmask_transtbl cflag_tbl
[] = {
3049 { TARGET_CBAUD
, TARGET_B0
, CBAUD
, B0
},
3050 { TARGET_CBAUD
, TARGET_B50
, CBAUD
, B50
},
3051 { TARGET_CBAUD
, TARGET_B75
, CBAUD
, B75
},
3052 { TARGET_CBAUD
, TARGET_B110
, CBAUD
, B110
},
3053 { TARGET_CBAUD
, TARGET_B134
, CBAUD
, B134
},
3054 { TARGET_CBAUD
, TARGET_B150
, CBAUD
, B150
},
3055 { TARGET_CBAUD
, TARGET_B200
, CBAUD
, B200
},
3056 { TARGET_CBAUD
, TARGET_B300
, CBAUD
, B300
},
3057 { TARGET_CBAUD
, TARGET_B600
, CBAUD
, B600
},
3058 { TARGET_CBAUD
, TARGET_B1200
, CBAUD
, B1200
},
3059 { TARGET_CBAUD
, TARGET_B1800
, CBAUD
, B1800
},
3060 { TARGET_CBAUD
, TARGET_B2400
, CBAUD
, B2400
},
3061 { TARGET_CBAUD
, TARGET_B4800
, CBAUD
, B4800
},
3062 { TARGET_CBAUD
, TARGET_B9600
, CBAUD
, B9600
},
3063 { TARGET_CBAUD
, TARGET_B19200
, CBAUD
, B19200
},
3064 { TARGET_CBAUD
, TARGET_B38400
, CBAUD
, B38400
},
3065 { TARGET_CBAUD
, TARGET_B57600
, CBAUD
, B57600
},
3066 { TARGET_CBAUD
, TARGET_B115200
, CBAUD
, B115200
},
3067 { TARGET_CBAUD
, TARGET_B230400
, CBAUD
, B230400
},
3068 { TARGET_CBAUD
, TARGET_B460800
, CBAUD
, B460800
},
3069 { TARGET_CSIZE
, TARGET_CS5
, CSIZE
, CS5
},
3070 { TARGET_CSIZE
, TARGET_CS6
, CSIZE
, CS6
},
3071 { TARGET_CSIZE
, TARGET_CS7
, CSIZE
, CS7
},
3072 { TARGET_CSIZE
, TARGET_CS8
, CSIZE
, CS8
},
3073 { TARGET_CSTOPB
, TARGET_CSTOPB
, CSTOPB
, CSTOPB
},
3074 { TARGET_CREAD
, TARGET_CREAD
, CREAD
, CREAD
},
3075 { TARGET_PARENB
, TARGET_PARENB
, PARENB
, PARENB
},
3076 { TARGET_PARODD
, TARGET_PARODD
, PARODD
, PARODD
},
3077 { TARGET_HUPCL
, TARGET_HUPCL
, HUPCL
, HUPCL
},
3078 { TARGET_CLOCAL
, TARGET_CLOCAL
, CLOCAL
, CLOCAL
},
3079 { TARGET_CRTSCTS
, TARGET_CRTSCTS
, CRTSCTS
, CRTSCTS
},
3083 static const bitmask_transtbl lflag_tbl
[] = {
3084 { TARGET_ISIG
, TARGET_ISIG
, ISIG
, ISIG
},
3085 { TARGET_ICANON
, TARGET_ICANON
, ICANON
, ICANON
},
3086 { TARGET_XCASE
, TARGET_XCASE
, XCASE
, XCASE
},
3087 { TARGET_ECHO
, TARGET_ECHO
, ECHO
, ECHO
},
3088 { TARGET_ECHOE
, TARGET_ECHOE
, ECHOE
, ECHOE
},
3089 { TARGET_ECHOK
, TARGET_ECHOK
, ECHOK
, ECHOK
},
3090 { TARGET_ECHONL
, TARGET_ECHONL
, ECHONL
, ECHONL
},
3091 { TARGET_NOFLSH
, TARGET_NOFLSH
, NOFLSH
, NOFLSH
},
3092 { TARGET_TOSTOP
, TARGET_TOSTOP
, TOSTOP
, TOSTOP
},
3093 { TARGET_ECHOCTL
, TARGET_ECHOCTL
, ECHOCTL
, ECHOCTL
},
3094 { TARGET_ECHOPRT
, TARGET_ECHOPRT
, ECHOPRT
, ECHOPRT
},
3095 { TARGET_ECHOKE
, TARGET_ECHOKE
, ECHOKE
, ECHOKE
},
3096 { TARGET_FLUSHO
, TARGET_FLUSHO
, FLUSHO
, FLUSHO
},
3097 { TARGET_PENDIN
, TARGET_PENDIN
, PENDIN
, PENDIN
},
3098 { TARGET_IEXTEN
, TARGET_IEXTEN
, IEXTEN
, IEXTEN
},
3102 static void target_to_host_termios (void *dst
, const void *src
)
3104 struct host_termios
*host
= dst
;
3105 const struct target_termios
*target
= src
;
3108 target_to_host_bitmask(tswap32(target
->c_iflag
), iflag_tbl
);
3110 target_to_host_bitmask(tswap32(target
->c_oflag
), oflag_tbl
);
3112 target_to_host_bitmask(tswap32(target
->c_cflag
), cflag_tbl
);
3114 target_to_host_bitmask(tswap32(target
->c_lflag
), lflag_tbl
);
3115 host
->c_line
= target
->c_line
;
3117 memset(host
->c_cc
, 0, sizeof(host
->c_cc
));
3118 host
->c_cc
[VINTR
] = target
->c_cc
[TARGET_VINTR
];
3119 host
->c_cc
[VQUIT
] = target
->c_cc
[TARGET_VQUIT
];
3120 host
->c_cc
[VERASE
] = target
->c_cc
[TARGET_VERASE
];
3121 host
->c_cc
[VKILL
] = target
->c_cc
[TARGET_VKILL
];
3122 host
->c_cc
[VEOF
] = target
->c_cc
[TARGET_VEOF
];
3123 host
->c_cc
[VTIME
] = target
->c_cc
[TARGET_VTIME
];
3124 host
->c_cc
[VMIN
] = target
->c_cc
[TARGET_VMIN
];
3125 host
->c_cc
[VSWTC
] = target
->c_cc
[TARGET_VSWTC
];
3126 host
->c_cc
[VSTART
] = target
->c_cc
[TARGET_VSTART
];
3127 host
->c_cc
[VSTOP
] = target
->c_cc
[TARGET_VSTOP
];
3128 host
->c_cc
[VSUSP
] = target
->c_cc
[TARGET_VSUSP
];
3129 host
->c_cc
[VEOL
] = target
->c_cc
[TARGET_VEOL
];
3130 host
->c_cc
[VREPRINT
] = target
->c_cc
[TARGET_VREPRINT
];
3131 host
->c_cc
[VDISCARD
] = target
->c_cc
[TARGET_VDISCARD
];
3132 host
->c_cc
[VWERASE
] = target
->c_cc
[TARGET_VWERASE
];
3133 host
->c_cc
[VLNEXT
] = target
->c_cc
[TARGET_VLNEXT
];
3134 host
->c_cc
[VEOL2
] = target
->c_cc
[TARGET_VEOL2
];
3137 static void host_to_target_termios (void *dst
, const void *src
)
3139 struct target_termios
*target
= dst
;
3140 const struct host_termios
*host
= src
;
3143 tswap32(host_to_target_bitmask(host
->c_iflag
, iflag_tbl
));
3145 tswap32(host_to_target_bitmask(host
->c_oflag
, oflag_tbl
));
3147 tswap32(host_to_target_bitmask(host
->c_cflag
, cflag_tbl
));
3149 tswap32(host_to_target_bitmask(host
->c_lflag
, lflag_tbl
));
3150 target
->c_line
= host
->c_line
;
3152 memset(target
->c_cc
, 0, sizeof(target
->c_cc
));
3153 target
->c_cc
[TARGET_VINTR
] = host
->c_cc
[VINTR
];
3154 target
->c_cc
[TARGET_VQUIT
] = host
->c_cc
[VQUIT
];
3155 target
->c_cc
[TARGET_VERASE
] = host
->c_cc
[VERASE
];
3156 target
->c_cc
[TARGET_VKILL
] = host
->c_cc
[VKILL
];
3157 target
->c_cc
[TARGET_VEOF
] = host
->c_cc
[VEOF
];
3158 target
->c_cc
[TARGET_VTIME
] = host
->c_cc
[VTIME
];
3159 target
->c_cc
[TARGET_VMIN
] = host
->c_cc
[VMIN
];
3160 target
->c_cc
[TARGET_VSWTC
] = host
->c_cc
[VSWTC
];
3161 target
->c_cc
[TARGET_VSTART
] = host
->c_cc
[VSTART
];
3162 target
->c_cc
[TARGET_VSTOP
] = host
->c_cc
[VSTOP
];
3163 target
->c_cc
[TARGET_VSUSP
] = host
->c_cc
[VSUSP
];
3164 target
->c_cc
[TARGET_VEOL
] = host
->c_cc
[VEOL
];
3165 target
->c_cc
[TARGET_VREPRINT
] = host
->c_cc
[VREPRINT
];
3166 target
->c_cc
[TARGET_VDISCARD
] = host
->c_cc
[VDISCARD
];
3167 target
->c_cc
[TARGET_VWERASE
] = host
->c_cc
[VWERASE
];
3168 target
->c_cc
[TARGET_VLNEXT
] = host
->c_cc
[VLNEXT
];
3169 target
->c_cc
[TARGET_VEOL2
] = host
->c_cc
[VEOL2
];
3172 static const StructEntry struct_termios_def
= {
3173 .convert
= { host_to_target_termios
, target_to_host_termios
},
3174 .size
= { sizeof(struct target_termios
), sizeof(struct host_termios
) },
3175 .align
= { __alignof__(struct target_termios
), __alignof__(struct host_termios
) },
3178 static bitmask_transtbl mmap_flags_tbl
[] = {
3179 { TARGET_MAP_SHARED
, TARGET_MAP_SHARED
, MAP_SHARED
, MAP_SHARED
},
3180 { TARGET_MAP_PRIVATE
, TARGET_MAP_PRIVATE
, MAP_PRIVATE
, MAP_PRIVATE
},
3181 { TARGET_MAP_FIXED
, TARGET_MAP_FIXED
, MAP_FIXED
, MAP_FIXED
},
3182 { TARGET_MAP_ANONYMOUS
, TARGET_MAP_ANONYMOUS
, MAP_ANONYMOUS
, MAP_ANONYMOUS
},
3183 { TARGET_MAP_GROWSDOWN
, TARGET_MAP_GROWSDOWN
, MAP_GROWSDOWN
, MAP_GROWSDOWN
},
3184 { TARGET_MAP_DENYWRITE
, TARGET_MAP_DENYWRITE
, MAP_DENYWRITE
, MAP_DENYWRITE
},
3185 { TARGET_MAP_EXECUTABLE
, TARGET_MAP_EXECUTABLE
, MAP_EXECUTABLE
, MAP_EXECUTABLE
},
3186 { TARGET_MAP_LOCKED
, TARGET_MAP_LOCKED
, MAP_LOCKED
, MAP_LOCKED
},
3190 #if defined(TARGET_I386)
3192 /* NOTE: there is really one LDT for all the threads */
3193 static uint8_t *ldt_table
;
3195 static abi_long
read_ldt(abi_ulong ptr
, unsigned long bytecount
)
3202 size
= TARGET_LDT_ENTRIES
* TARGET_LDT_ENTRY_SIZE
;
3203 if (size
> bytecount
)
3205 p
= lock_user(VERIFY_WRITE
, ptr
, size
, 0);
3207 return -TARGET_EFAULT
;
3208 /* ??? Should this by byteswapped? */
3209 memcpy(p
, ldt_table
, size
);
3210 unlock_user(p
, ptr
, size
);
3214 /* XXX: add locking support */
3215 static abi_long
write_ldt(CPUX86State
*env
,
3216 abi_ulong ptr
, unsigned long bytecount
, int oldmode
)
3218 struct target_modify_ldt_ldt_s ldt_info
;
3219 struct target_modify_ldt_ldt_s
*target_ldt_info
;
3220 int seg_32bit
, contents
, read_exec_only
, limit_in_pages
;
3221 int seg_not_present
, useable
, lm
;
3222 uint32_t *lp
, entry_1
, entry_2
;
3224 if (bytecount
!= sizeof(ldt_info
))
3225 return -TARGET_EINVAL
;
3226 if (!lock_user_struct(VERIFY_READ
, target_ldt_info
, ptr
, 1))
3227 return -TARGET_EFAULT
;
3228 ldt_info
.entry_number
= tswap32(target_ldt_info
->entry_number
);
3229 ldt_info
.base_addr
= tswapl(target_ldt_info
->base_addr
);
3230 ldt_info
.limit
= tswap32(target_ldt_info
->limit
);
3231 ldt_info
.flags
= tswap32(target_ldt_info
->flags
);
3232 unlock_user_struct(target_ldt_info
, ptr
, 0);
3234 if (ldt_info
.entry_number
>= TARGET_LDT_ENTRIES
)
3235 return -TARGET_EINVAL
;
3236 seg_32bit
= ldt_info
.flags
& 1;
3237 contents
= (ldt_info
.flags
>> 1) & 3;
3238 read_exec_only
= (ldt_info
.flags
>> 3) & 1;
3239 limit_in_pages
= (ldt_info
.flags
>> 4) & 1;
3240 seg_not_present
= (ldt_info
.flags
>> 5) & 1;
3241 useable
= (ldt_info
.flags
>> 6) & 1;
3245 lm
= (ldt_info
.flags
>> 7) & 1;
3247 if (contents
== 3) {
3249 return -TARGET_EINVAL
;
3250 if (seg_not_present
== 0)
3251 return -TARGET_EINVAL
;
3253 /* allocate the LDT */
3255 env
->ldt
.base
= target_mmap(0,
3256 TARGET_LDT_ENTRIES
* TARGET_LDT_ENTRY_SIZE
,
3257 PROT_READ
|PROT_WRITE
,
3258 MAP_ANONYMOUS
|MAP_PRIVATE
, -1, 0);
3259 if (env
->ldt
.base
== -1)
3260 return -TARGET_ENOMEM
;
3261 memset(g2h(env
->ldt
.base
), 0,
3262 TARGET_LDT_ENTRIES
* TARGET_LDT_ENTRY_SIZE
);
3263 env
->ldt
.limit
= 0xffff;
3264 ldt_table
= g2h(env
->ldt
.base
);
3267 /* NOTE: same code as Linux kernel */
3268 /* Allow LDTs to be cleared by the user. */
3269 if (ldt_info
.base_addr
== 0 && ldt_info
.limit
== 0) {
3272 read_exec_only
== 1 &&
3274 limit_in_pages
== 0 &&
3275 seg_not_present
== 1 &&
3283 entry_1
= ((ldt_info
.base_addr
& 0x0000ffff) << 16) |
3284 (ldt_info
.limit
& 0x0ffff);
3285 entry_2
= (ldt_info
.base_addr
& 0xff000000) |
3286 ((ldt_info
.base_addr
& 0x00ff0000) >> 16) |
3287 (ldt_info
.limit
& 0xf0000) |
3288 ((read_exec_only
^ 1) << 9) |
3290 ((seg_not_present
^ 1) << 15) |
3292 (limit_in_pages
<< 23) |
3296 entry_2
|= (useable
<< 20);
3298 /* Install the new entry ... */
3300 lp
= (uint32_t *)(ldt_table
+ (ldt_info
.entry_number
<< 3));
3301 lp
[0] = tswap32(entry_1
);
3302 lp
[1] = tswap32(entry_2
);
3306 /* specific and weird i386 syscalls */
3307 static abi_long
do_modify_ldt(CPUX86State
*env
, int func
, abi_ulong ptr
,
3308 unsigned long bytecount
)
3314 ret
= read_ldt(ptr
, bytecount
);
3317 ret
= write_ldt(env
, ptr
, bytecount
, 1);
3320 ret
= write_ldt(env
, ptr
, bytecount
, 0);
3323 ret
= -TARGET_ENOSYS
;
3329 #if defined(TARGET_I386) && defined(TARGET_ABI32)
3330 static abi_long
do_set_thread_area(CPUX86State
*env
, abi_ulong ptr
)
3332 uint64_t *gdt_table
= g2h(env
->gdt
.base
);
3333 struct target_modify_ldt_ldt_s ldt_info
;
3334 struct target_modify_ldt_ldt_s
*target_ldt_info
;
3335 int seg_32bit
, contents
, read_exec_only
, limit_in_pages
;
3336 int seg_not_present
, useable
, lm
;
3337 uint32_t *lp
, entry_1
, entry_2
;
3340 lock_user_struct(VERIFY_WRITE
, target_ldt_info
, ptr
, 1);
3341 if (!target_ldt_info
)
3342 return -TARGET_EFAULT
;
3343 ldt_info
.entry_number
= tswap32(target_ldt_info
->entry_number
);
3344 ldt_info
.base_addr
= tswapl(target_ldt_info
->base_addr
);
3345 ldt_info
.limit
= tswap32(target_ldt_info
->limit
);
3346 ldt_info
.flags
= tswap32(target_ldt_info
->flags
);
3347 if (ldt_info
.entry_number
== -1) {
3348 for (i
=TARGET_GDT_ENTRY_TLS_MIN
; i
<=TARGET_GDT_ENTRY_TLS_MAX
; i
++) {
3349 if (gdt_table
[i
] == 0) {
3350 ldt_info
.entry_number
= i
;
3351 target_ldt_info
->entry_number
= tswap32(i
);
3356 unlock_user_struct(target_ldt_info
, ptr
, 1);
3358 if (ldt_info
.entry_number
< TARGET_GDT_ENTRY_TLS_MIN
||
3359 ldt_info
.entry_number
> TARGET_GDT_ENTRY_TLS_MAX
)
3360 return -TARGET_EINVAL
;
3361 seg_32bit
= ldt_info
.flags
& 1;
3362 contents
= (ldt_info
.flags
>> 1) & 3;
3363 read_exec_only
= (ldt_info
.flags
>> 3) & 1;
3364 limit_in_pages
= (ldt_info
.flags
>> 4) & 1;
3365 seg_not_present
= (ldt_info
.flags
>> 5) & 1;
3366 useable
= (ldt_info
.flags
>> 6) & 1;
3370 lm
= (ldt_info
.flags
>> 7) & 1;
3373 if (contents
== 3) {
3374 if (seg_not_present
== 0)
3375 return -TARGET_EINVAL
;
3378 /* NOTE: same code as Linux kernel */
3379 /* Allow LDTs to be cleared by the user. */
3380 if (ldt_info
.base_addr
== 0 && ldt_info
.limit
== 0) {
3381 if ((contents
== 0 &&
3382 read_exec_only
== 1 &&
3384 limit_in_pages
== 0 &&
3385 seg_not_present
== 1 &&
3393 entry_1
= ((ldt_info
.base_addr
& 0x0000ffff) << 16) |
3394 (ldt_info
.limit
& 0x0ffff);
3395 entry_2
= (ldt_info
.base_addr
& 0xff000000) |
3396 ((ldt_info
.base_addr
& 0x00ff0000) >> 16) |
3397 (ldt_info
.limit
& 0xf0000) |
3398 ((read_exec_only
^ 1) << 9) |
3400 ((seg_not_present
^ 1) << 15) |
3402 (limit_in_pages
<< 23) |
3407 /* Install the new entry ... */
3409 lp
= (uint32_t *)(gdt_table
+ ldt_info
.entry_number
);
3410 lp
[0] = tswap32(entry_1
);
3411 lp
[1] = tswap32(entry_2
);
3415 static abi_long
do_get_thread_area(CPUX86State
*env
, abi_ulong ptr
)
3417 struct target_modify_ldt_ldt_s
*target_ldt_info
;
3418 uint64_t *gdt_table
= g2h(env
->gdt
.base
);
3419 uint32_t base_addr
, limit
, flags
;
3420 int seg_32bit
, contents
, read_exec_only
, limit_in_pages
, idx
;
3421 int seg_not_present
, useable
, lm
;
3422 uint32_t *lp
, entry_1
, entry_2
;
3424 lock_user_struct(VERIFY_WRITE
, target_ldt_info
, ptr
, 1);
3425 if (!target_ldt_info
)
3426 return -TARGET_EFAULT
;
3427 idx
= tswap32(target_ldt_info
->entry_number
);
3428 if (idx
< TARGET_GDT_ENTRY_TLS_MIN
||
3429 idx
> TARGET_GDT_ENTRY_TLS_MAX
) {
3430 unlock_user_struct(target_ldt_info
, ptr
, 1);
3431 return -TARGET_EINVAL
;
3433 lp
= (uint32_t *)(gdt_table
+ idx
);
3434 entry_1
= tswap32(lp
[0]);
3435 entry_2
= tswap32(lp
[1]);
3437 read_exec_only
= ((entry_2
>> 9) & 1) ^ 1;
3438 contents
= (entry_2
>> 10) & 3;
3439 seg_not_present
= ((entry_2
>> 15) & 1) ^ 1;
3440 seg_32bit
= (entry_2
>> 22) & 1;
3441 limit_in_pages
= (entry_2
>> 23) & 1;
3442 useable
= (entry_2
>> 20) & 1;
3446 lm
= (entry_2
>> 21) & 1;
3448 flags
= (seg_32bit
<< 0) | (contents
<< 1) |
3449 (read_exec_only
<< 3) | (limit_in_pages
<< 4) |
3450 (seg_not_present
<< 5) | (useable
<< 6) | (lm
<< 7);
3451 limit
= (entry_1
& 0xffff) | (entry_2
& 0xf0000);
3452 base_addr
= (entry_1
>> 16) |
3453 (entry_2
& 0xff000000) |
3454 ((entry_2
& 0xff) << 16);
3455 target_ldt_info
->base_addr
= tswapl(base_addr
);
3456 target_ldt_info
->limit
= tswap32(limit
);
3457 target_ldt_info
->flags
= tswap32(flags
);
3458 unlock_user_struct(target_ldt_info
, ptr
, 1);
3461 #endif /* TARGET_I386 && TARGET_ABI32 */
3463 #ifndef TARGET_ABI32
3464 static abi_long
do_arch_prctl(CPUX86State
*env
, int code
, abi_ulong addr
)
3471 case TARGET_ARCH_SET_GS
:
3472 case TARGET_ARCH_SET_FS
:
3473 if (code
== TARGET_ARCH_SET_GS
)
3477 cpu_x86_load_seg(env
, idx
, 0);
3478 env
->segs
[idx
].base
= addr
;
3480 case TARGET_ARCH_GET_GS
:
3481 case TARGET_ARCH_GET_FS
:
3482 if (code
== TARGET_ARCH_GET_GS
)
3486 val
= env
->segs
[idx
].base
;
3487 if (put_user(val
, addr
, abi_ulong
))
3488 return -TARGET_EFAULT
;
3491 ret
= -TARGET_EINVAL
;
3498 #endif /* defined(TARGET_I386) */
3500 #if defined(CONFIG_USE_NPTL)
3502 #define NEW_STACK_SIZE PTHREAD_STACK_MIN
3504 static pthread_mutex_t clone_lock
= PTHREAD_MUTEX_INITIALIZER
;
3507 pthread_mutex_t mutex
;
3508 pthread_cond_t cond
;
3511 abi_ulong child_tidptr
;
3512 abi_ulong parent_tidptr
;
3516 static void *clone_func(void *arg
)
3518 new_thread_info
*info
= arg
;
3524 ts
= (TaskState
*)thread_env
->opaque
;
3525 info
->tid
= gettid();
3526 env
->host_tid
= info
->tid
;
3528 if (info
->child_tidptr
)
3529 put_user_u32(info
->tid
, info
->child_tidptr
);
3530 if (info
->parent_tidptr
)
3531 put_user_u32(info
->tid
, info
->parent_tidptr
);
3532 /* Enable signals. */
3533 sigprocmask(SIG_SETMASK
, &info
->sigmask
, NULL
);
3534 /* Signal to the parent that we're ready. */
3535 pthread_mutex_lock(&info
->mutex
);
3536 pthread_cond_broadcast(&info
->cond
);
3537 pthread_mutex_unlock(&info
->mutex
);
3538 /* Wait until the parent has finshed initializing the tls state. */
3539 pthread_mutex_lock(&clone_lock
);
3540 pthread_mutex_unlock(&clone_lock
);
3546 /* this stack is the equivalent of the kernel stack associated with a
3548 #define NEW_STACK_SIZE 8192
3550 static int clone_func(void *arg
)
3552 CPUState
*env
= arg
;
3559 /* do_fork() Must return host values and target errnos (unlike most
3560 do_*() functions). */
3561 static int do_fork(CPUState
*env
, unsigned int flags
, abi_ulong newsp
,
3562 abi_ulong parent_tidptr
, target_ulong newtls
,
3563 abi_ulong child_tidptr
)
3569 #if defined(CONFIG_USE_NPTL)
3570 unsigned int nptl_flags
;
3574 /* Emulate vfork() with fork() */
3575 if (flags
& CLONE_VFORK
)
3576 flags
&= ~(CLONE_VFORK
| CLONE_VM
);
3578 if (flags
& CLONE_VM
) {
3579 TaskState
*parent_ts
= (TaskState
*)env
->opaque
;
3580 #if defined(CONFIG_USE_NPTL)
3581 new_thread_info info
;
3582 pthread_attr_t attr
;
3584 ts
= qemu_mallocz(sizeof(TaskState
) + NEW_STACK_SIZE
);
3585 init_task_state(ts
);
3586 new_stack
= ts
->stack
;
3587 /* we create a new CPU instance. */
3588 new_env
= cpu_copy(env
);
3589 #if defined(TARGET_I386) || defined(TARGET_SPARC) || defined(TARGET_PPC)
3592 /* Init regs that differ from the parent. */
3593 cpu_clone_regs(new_env
, newsp
);
3594 new_env
->opaque
= ts
;
3595 ts
->bprm
= parent_ts
->bprm
;
3596 ts
->info
= parent_ts
->info
;
3597 #if defined(CONFIG_USE_NPTL)
3599 flags
&= ~CLONE_NPTL_FLAGS2
;
3601 if (nptl_flags
& CLONE_CHILD_CLEARTID
) {
3602 ts
->child_tidptr
= child_tidptr
;
3605 if (nptl_flags
& CLONE_SETTLS
)
3606 cpu_set_tls (new_env
, newtls
);
3608 /* Grab a mutex so that thread setup appears atomic. */
3609 pthread_mutex_lock(&clone_lock
);
3611 memset(&info
, 0, sizeof(info
));
3612 pthread_mutex_init(&info
.mutex
, NULL
);
3613 pthread_mutex_lock(&info
.mutex
);
3614 pthread_cond_init(&info
.cond
, NULL
);
3616 if (nptl_flags
& CLONE_CHILD_SETTID
)
3617 info
.child_tidptr
= child_tidptr
;
3618 if (nptl_flags
& CLONE_PARENT_SETTID
)
3619 info
.parent_tidptr
= parent_tidptr
;
3621 ret
= pthread_attr_init(&attr
);
3622 ret
= pthread_attr_setstack(&attr
, new_stack
, NEW_STACK_SIZE
);
3623 /* It is not safe to deliver signals until the child has finished
3624 initializing, so temporarily block all signals. */
3625 sigfillset(&sigmask
);
3626 sigprocmask(SIG_BLOCK
, &sigmask
, &info
.sigmask
);
3628 ret
= pthread_create(&info
.thread
, &attr
, clone_func
, &info
);
3629 /* TODO: Free new CPU state if thread creation failed. */
3631 sigprocmask(SIG_SETMASK
, &info
.sigmask
, NULL
);
3632 pthread_attr_destroy(&attr
);
3634 /* Wait for the child to initialize. */
3635 pthread_cond_wait(&info
.cond
, &info
.mutex
);
3637 if (flags
& CLONE_PARENT_SETTID
)
3638 put_user_u32(ret
, parent_tidptr
);
3642 pthread_mutex_unlock(&info
.mutex
);
3643 pthread_cond_destroy(&info
.cond
);
3644 pthread_mutex_destroy(&info
.mutex
);
3645 pthread_mutex_unlock(&clone_lock
);
3647 if (flags
& CLONE_NPTL_FLAGS2
)
3649 /* This is probably going to die very quickly, but do it anyway. */
3651 ret
= __clone2(clone_func
, new_stack
, NEW_STACK_SIZE
, flags
, new_env
);
3653 ret
= clone(clone_func
, new_stack
+ NEW_STACK_SIZE
, flags
, new_env
);
3657 /* if no CLONE_VM, we consider it is a fork */
3658 if ((flags
& ~(CSIGNAL
| CLONE_NPTL_FLAGS2
)) != 0)
3663 /* Child Process. */
3664 cpu_clone_regs(env
, newsp
);
3666 #if defined(CONFIG_USE_NPTL)
3667 /* There is a race condition here. The parent process could
3668 theoretically read the TID in the child process before the child
3669 tid is set. This would require using either ptrace
3670 (not implemented) or having *_tidptr to point at a shared memory
3671 mapping. We can't repeat the spinlock hack used above because
3672 the child process gets its own copy of the lock. */
3673 if (flags
& CLONE_CHILD_SETTID
)
3674 put_user_u32(gettid(), child_tidptr
);
3675 if (flags
& CLONE_PARENT_SETTID
)
3676 put_user_u32(gettid(), parent_tidptr
);
3677 ts
= (TaskState
*)env
->opaque
;
3678 if (flags
& CLONE_SETTLS
)
3679 cpu_set_tls (env
, newtls
);
3680 if (flags
& CLONE_CHILD_CLEARTID
)
3681 ts
->child_tidptr
= child_tidptr
;
3690 /* warning : doesn't handle linux specific flags... */
3691 static int target_to_host_fcntl_cmd(int cmd
)
3694 case TARGET_F_DUPFD
:
3695 case TARGET_F_GETFD
:
3696 case TARGET_F_SETFD
:
3697 case TARGET_F_GETFL
:
3698 case TARGET_F_SETFL
:
3700 case TARGET_F_GETLK
:
3702 case TARGET_F_SETLK
:
3704 case TARGET_F_SETLKW
:
3706 case TARGET_F_GETOWN
:
3708 case TARGET_F_SETOWN
:
3710 case TARGET_F_GETSIG
:
3712 case TARGET_F_SETSIG
:
3714 #if TARGET_ABI_BITS == 32
3715 case TARGET_F_GETLK64
:
3717 case TARGET_F_SETLK64
:
3719 case TARGET_F_SETLKW64
:
3722 case TARGET_F_SETLEASE
:
3724 case TARGET_F_GETLEASE
:
3726 #ifdef F_DUPFD_CLOEXEC
3727 case TARGET_F_DUPFD_CLOEXEC
:
3728 return F_DUPFD_CLOEXEC
;
3730 case TARGET_F_NOTIFY
:
3733 return -TARGET_EINVAL
;
3735 return -TARGET_EINVAL
;
3738 static abi_long
do_fcntl(int fd
, int cmd
, abi_ulong arg
)
3741 struct target_flock
*target_fl
;
3742 struct flock64 fl64
;
3743 struct target_flock64
*target_fl64
;
3745 int host_cmd
= target_to_host_fcntl_cmd(cmd
);
3747 if (host_cmd
== -TARGET_EINVAL
)
3751 case TARGET_F_GETLK
:
3752 if (!lock_user_struct(VERIFY_READ
, target_fl
, arg
, 1))
3753 return -TARGET_EFAULT
;
3754 fl
.l_type
= tswap16(target_fl
->l_type
);
3755 fl
.l_whence
= tswap16(target_fl
->l_whence
);
3756 fl
.l_start
= tswapl(target_fl
->l_start
);
3757 fl
.l_len
= tswapl(target_fl
->l_len
);
3758 fl
.l_pid
= tswap32(target_fl
->l_pid
);
3759 unlock_user_struct(target_fl
, arg
, 0);
3760 ret
= get_errno(fcntl(fd
, host_cmd
, &fl
));
3762 if (!lock_user_struct(VERIFY_WRITE
, target_fl
, arg
, 0))
3763 return -TARGET_EFAULT
;
3764 target_fl
->l_type
= tswap16(fl
.l_type
);
3765 target_fl
->l_whence
= tswap16(fl
.l_whence
);
3766 target_fl
->l_start
= tswapl(fl
.l_start
);
3767 target_fl
->l_len
= tswapl(fl
.l_len
);
3768 target_fl
->l_pid
= tswap32(fl
.l_pid
);
3769 unlock_user_struct(target_fl
, arg
, 1);
3773 case TARGET_F_SETLK
:
3774 case TARGET_F_SETLKW
:
3775 if (!lock_user_struct(VERIFY_READ
, target_fl
, arg
, 1))
3776 return -TARGET_EFAULT
;
3777 fl
.l_type
= tswap16(target_fl
->l_type
);
3778 fl
.l_whence
= tswap16(target_fl
->l_whence
);
3779 fl
.l_start
= tswapl(target_fl
->l_start
);
3780 fl
.l_len
= tswapl(target_fl
->l_len
);
3781 fl
.l_pid
= tswap32(target_fl
->l_pid
);
3782 unlock_user_struct(target_fl
, arg
, 0);
3783 ret
= get_errno(fcntl(fd
, host_cmd
, &fl
));
3786 case TARGET_F_GETLK64
:
3787 if (!lock_user_struct(VERIFY_READ
, target_fl64
, arg
, 1))
3788 return -TARGET_EFAULT
;
3789 fl64
.l_type
= tswap16(target_fl64
->l_type
) >> 1;
3790 fl64
.l_whence
= tswap16(target_fl64
->l_whence
);
3791 fl64
.l_start
= tswapl(target_fl64
->l_start
);
3792 fl64
.l_len
= tswapl(target_fl64
->l_len
);
3793 fl64
.l_pid
= tswap32(target_fl64
->l_pid
);
3794 unlock_user_struct(target_fl64
, arg
, 0);
3795 ret
= get_errno(fcntl(fd
, host_cmd
, &fl64
));
3797 if (!lock_user_struct(VERIFY_WRITE
, target_fl64
, arg
, 0))
3798 return -TARGET_EFAULT
;
3799 target_fl64
->l_type
= tswap16(fl64
.l_type
) >> 1;
3800 target_fl64
->l_whence
= tswap16(fl64
.l_whence
);
3801 target_fl64
->l_start
= tswapl(fl64
.l_start
);
3802 target_fl64
->l_len
= tswapl(fl64
.l_len
);
3803 target_fl64
->l_pid
= tswap32(fl64
.l_pid
);
3804 unlock_user_struct(target_fl64
, arg
, 1);
3807 case TARGET_F_SETLK64
:
3808 case TARGET_F_SETLKW64
:
3809 if (!lock_user_struct(VERIFY_READ
, target_fl64
, arg
, 1))
3810 return -TARGET_EFAULT
;
3811 fl64
.l_type
= tswap16(target_fl64
->l_type
) >> 1;
3812 fl64
.l_whence
= tswap16(target_fl64
->l_whence
);
3813 fl64
.l_start
= tswapl(target_fl64
->l_start
);
3814 fl64
.l_len
= tswapl(target_fl64
->l_len
);
3815 fl64
.l_pid
= tswap32(target_fl64
->l_pid
);
3816 unlock_user_struct(target_fl64
, arg
, 0);
3817 ret
= get_errno(fcntl(fd
, host_cmd
, &fl64
));
3820 case TARGET_F_GETFL
:
3821 ret
= get_errno(fcntl(fd
, host_cmd
, arg
));
3823 ret
= host_to_target_bitmask(ret
, fcntl_flags_tbl
);
3827 case TARGET_F_SETFL
:
3828 ret
= get_errno(fcntl(fd
, host_cmd
, target_to_host_bitmask(arg
, fcntl_flags_tbl
)));
3831 case TARGET_F_SETOWN
:
3832 case TARGET_F_GETOWN
:
3833 case TARGET_F_SETSIG
:
3834 case TARGET_F_GETSIG
:
3835 case TARGET_F_SETLEASE
:
3836 case TARGET_F_GETLEASE
:
3837 ret
= get_errno(fcntl(fd
, host_cmd
, arg
));
3841 ret
= get_errno(fcntl(fd
, cmd
, arg
));
3849 static inline int high2lowuid(int uid
)
3857 static inline int high2lowgid(int gid
)
3865 static inline int low2highuid(int uid
)
3867 if ((int16_t)uid
== -1)
3873 static inline int low2highgid(int gid
)
3875 if ((int16_t)gid
== -1)
3881 #endif /* USE_UID16 */
3883 void syscall_init(void)
3886 const argtype
*arg_type
;
3890 #define STRUCT(name, ...) thunk_register_struct(STRUCT_ ## name, #name, struct_ ## name ## _def);
3891 #define STRUCT_SPECIAL(name) thunk_register_struct_direct(STRUCT_ ## name, #name, &struct_ ## name ## _def);
3892 #include "syscall_types.h"
3894 #undef STRUCT_SPECIAL
3896 /* we patch the ioctl size if necessary. We rely on the fact that
3897 no ioctl has all the bits at '1' in the size field */
3899 while (ie
->target_cmd
!= 0) {
3900 if (((ie
->target_cmd
>> TARGET_IOC_SIZESHIFT
) & TARGET_IOC_SIZEMASK
) ==
3901 TARGET_IOC_SIZEMASK
) {
3902 arg_type
= ie
->arg_type
;
3903 if (arg_type
[0] != TYPE_PTR
) {
3904 fprintf(stderr
, "cannot patch size for ioctl 0x%x\n",
3909 size
= thunk_type_size(arg_type
, 0);
3910 ie
->target_cmd
= (ie
->target_cmd
&
3911 ~(TARGET_IOC_SIZEMASK
<< TARGET_IOC_SIZESHIFT
)) |
3912 (size
<< TARGET_IOC_SIZESHIFT
);
3915 /* Build target_to_host_errno_table[] table from
3916 * host_to_target_errno_table[]. */
3917 for (i
=0; i
< ERRNO_TABLE_SIZE
; i
++)
3918 target_to_host_errno_table
[host_to_target_errno_table
[i
]] = i
;
3920 /* automatic consistency check if same arch */
3921 #if (defined(__i386__) && defined(TARGET_I386) && defined(TARGET_ABI32)) || \
3922 (defined(__x86_64__) && defined(TARGET_X86_64))
3923 if (unlikely(ie
->target_cmd
!= ie
->host_cmd
)) {
3924 fprintf(stderr
, "ERROR: ioctl(%s): target=0x%x host=0x%x\n",
3925 ie
->name
, ie
->target_cmd
, ie
->host_cmd
);
3932 #if TARGET_ABI_BITS == 32
3933 static inline uint64_t target_offset64(uint32_t word0
, uint32_t word1
)
3935 #ifdef TARGET_WORDS_BIGENDIAN
3936 return ((uint64_t)word0
<< 32) | word1
;
3938 return ((uint64_t)word1
<< 32) | word0
;
3941 #else /* TARGET_ABI_BITS == 32 */
3942 static inline uint64_t target_offset64(uint64_t word0
, uint64_t word1
)
3946 #endif /* TARGET_ABI_BITS != 32 */
3948 #ifdef TARGET_NR_truncate64
3949 static inline abi_long
target_truncate64(void *cpu_env
, const char *arg1
,
3955 if (((CPUARMState
*)cpu_env
)->eabi
)
3961 return get_errno(truncate64(arg1
, target_offset64(arg2
, arg3
)));
3965 #ifdef TARGET_NR_ftruncate64
3966 static inline abi_long
target_ftruncate64(void *cpu_env
, abi_long arg1
,
3972 if (((CPUARMState
*)cpu_env
)->eabi
)
3978 return get_errno(ftruncate64(arg1
, target_offset64(arg2
, arg3
)));
3982 static inline abi_long
target_to_host_timespec(struct timespec
*host_ts
,
3983 abi_ulong target_addr
)
3985 struct target_timespec
*target_ts
;
3987 if (!lock_user_struct(VERIFY_READ
, target_ts
, target_addr
, 1))
3988 return -TARGET_EFAULT
;
3989 host_ts
->tv_sec
= tswapl(target_ts
->tv_sec
);
3990 host_ts
->tv_nsec
= tswapl(target_ts
->tv_nsec
);
3991 unlock_user_struct(target_ts
, target_addr
, 0);
3995 static inline abi_long
host_to_target_timespec(abi_ulong target_addr
,
3996 struct timespec
*host_ts
)
3998 struct target_timespec
*target_ts
;
4000 if (!lock_user_struct(VERIFY_WRITE
, target_ts
, target_addr
, 0))
4001 return -TARGET_EFAULT
;
4002 target_ts
->tv_sec
= tswapl(host_ts
->tv_sec
);
4003 target_ts
->tv_nsec
= tswapl(host_ts
->tv_nsec
);
4004 unlock_user_struct(target_ts
, target_addr
, 1);
4008 #if defined(TARGET_NR_stat64) || defined(TARGET_NR_newfstatat)
4009 static inline abi_long
host_to_target_stat64(void *cpu_env
,
4010 abi_ulong target_addr
,
4011 struct stat
*host_st
)
4014 if (((CPUARMState
*)cpu_env
)->eabi
) {
4015 struct target_eabi_stat64
*target_st
;
4017 if (!lock_user_struct(VERIFY_WRITE
, target_st
, target_addr
, 0))
4018 return -TARGET_EFAULT
;
4019 memset(target_st
, 0, sizeof(struct target_eabi_stat64
));
4020 __put_user(host_st
->st_dev
, &target_st
->st_dev
);
4021 __put_user(host_st
->st_ino
, &target_st
->st_ino
);
4022 #ifdef TARGET_STAT64_HAS_BROKEN_ST_INO
4023 __put_user(host_st
->st_ino
, &target_st
->__st_ino
);
4025 __put_user(host_st
->st_mode
, &target_st
->st_mode
);
4026 __put_user(host_st
->st_nlink
, &target_st
->st_nlink
);
4027 __put_user(host_st
->st_uid
, &target_st
->st_uid
);
4028 __put_user(host_st
->st_gid
, &target_st
->st_gid
);
4029 __put_user(host_st
->st_rdev
, &target_st
->st_rdev
);
4030 __put_user(host_st
->st_size
, &target_st
->st_size
);
4031 __put_user(host_st
->st_blksize
, &target_st
->st_blksize
);
4032 __put_user(host_st
->st_blocks
, &target_st
->st_blocks
);
4033 __put_user(host_st
->st_atime
, &target_st
->target_st_atime
);
4034 __put_user(host_st
->st_mtime
, &target_st
->target_st_mtime
);
4035 __put_user(host_st
->st_ctime
, &target_st
->target_st_ctime
);
4036 unlock_user_struct(target_st
, target_addr
, 1);
4040 #if TARGET_ABI_BITS == 64 && !defined(TARGET_ALPHA)
4041 struct target_stat
*target_st
;
4043 struct target_stat64
*target_st
;
4046 if (!lock_user_struct(VERIFY_WRITE
, target_st
, target_addr
, 0))
4047 return -TARGET_EFAULT
;
4048 memset(target_st
, 0, sizeof(*target_st
));
4049 __put_user(host_st
->st_dev
, &target_st
->st_dev
);
4050 __put_user(host_st
->st_ino
, &target_st
->st_ino
);
4051 #ifdef TARGET_STAT64_HAS_BROKEN_ST_INO
4052 __put_user(host_st
->st_ino
, &target_st
->__st_ino
);
4054 __put_user(host_st
->st_mode
, &target_st
->st_mode
);
4055 __put_user(host_st
->st_nlink
, &target_st
->st_nlink
);
4056 __put_user(host_st
->st_uid
, &target_st
->st_uid
);
4057 __put_user(host_st
->st_gid
, &target_st
->st_gid
);
4058 __put_user(host_st
->st_rdev
, &target_st
->st_rdev
);
4059 /* XXX: better use of kernel struct */
4060 __put_user(host_st
->st_size
, &target_st
->st_size
);
4061 __put_user(host_st
->st_blksize
, &target_st
->st_blksize
);
4062 __put_user(host_st
->st_blocks
, &target_st
->st_blocks
);
4063 __put_user(host_st
->st_atime
, &target_st
->target_st_atime
);
4064 __put_user(host_st
->st_mtime
, &target_st
->target_st_mtime
);
4065 __put_user(host_st
->st_ctime
, &target_st
->target_st_ctime
);
4066 unlock_user_struct(target_st
, target_addr
, 1);
4073 #if defined(CONFIG_USE_NPTL)
4074 /* ??? Using host futex calls even when target atomic operations
4075 are not really atomic probably breaks things. However implementing
4076 futexes locally would make futexes shared between multiple processes
4077 tricky. However they're probably useless because guest atomic
4078 operations won't work either. */
4079 static int do_futex(target_ulong uaddr
, int op
, int val
, target_ulong timeout
,
4080 target_ulong uaddr2
, int val3
)
4082 struct timespec ts
, *pts
;
4085 /* ??? We assume FUTEX_* constants are the same on both host
4087 #ifdef FUTEX_CMD_MASK
4088 base_op
= op
& FUTEX_CMD_MASK
;
4096 target_to_host_timespec(pts
, timeout
);
4100 return get_errno(sys_futex(g2h(uaddr
), op
, tswap32(val
),
4103 return get_errno(sys_futex(g2h(uaddr
), op
, val
, NULL
, NULL
, 0));
4105 return get_errno(sys_futex(g2h(uaddr
), op
, val
, NULL
, NULL
, 0));
4107 case FUTEX_CMP_REQUEUE
:
4109 /* For FUTEX_REQUEUE, FUTEX_CMP_REQUEUE, and FUTEX_WAKE_OP, the
4110 TIMEOUT parameter is interpreted as a uint32_t by the kernel.
4111 But the prototype takes a `struct timespec *'; insert casts
4112 to satisfy the compiler. We do not need to tswap TIMEOUT
4113 since it's not compared to guest memory. */
4114 pts
= (struct timespec
*)(uintptr_t) timeout
;
4115 return get_errno(sys_futex(g2h(uaddr
), op
, val
, pts
,
4117 (base_op
== FUTEX_CMP_REQUEUE
4121 return -TARGET_ENOSYS
;
4126 /* Map host to target signal numbers for the wait family of syscalls.
4127 Assume all other status bits are the same. */
4128 static int host_to_target_waitstatus(int status
)
4130 if (WIFSIGNALED(status
)) {
4131 return host_to_target_signal(WTERMSIG(status
)) | (status
& ~0x7f);
4133 if (WIFSTOPPED(status
)) {
4134 return (host_to_target_signal(WSTOPSIG(status
)) << 8)
4140 int get_osversion(void)
4142 static int osversion
;
4143 struct new_utsname buf
;
4148 if (qemu_uname_release
&& *qemu_uname_release
) {
4149 s
= qemu_uname_release
;
4151 if (sys_uname(&buf
))
4156 for (i
= 0; i
< 3; i
++) {
4158 while (*s
>= '0' && *s
<= '9') {
4163 tmp
= (tmp
<< 8) + n
;
4171 /* do_syscall() should always have a single exit point at the end so
4172 that actions, such as logging of syscall results, can be performed.
4173 All errnos that do_syscall() returns must be -TARGET_<errcode>. */
4174 abi_long
do_syscall(void *cpu_env
, int num
, abi_long arg1
,
4175 abi_long arg2
, abi_long arg3
, abi_long arg4
,
4176 abi_long arg5
, abi_long arg6
)
4184 gemu_log("syscall %d", num
);
4187 print_syscall(num
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
4190 case TARGET_NR_exit
:
4191 #ifdef CONFIG_USE_NPTL
4192 /* In old applications this may be used to implement _exit(2).
4193 However in threaded applictions it is used for thread termination,
4194 and _exit_group is used for application termination.
4195 Do thread termination if we have more then one thread. */
4196 /* FIXME: This probably breaks if a signal arrives. We should probably
4197 be disabling signals. */
4198 if (first_cpu
->next_cpu
) {
4206 while (p
&& p
!= (CPUState
*)cpu_env
) {
4207 lastp
= &p
->next_cpu
;
4210 /* If we didn't find the CPU for this thread then something is
4214 /* Remove the CPU from the list. */
4215 *lastp
= p
->next_cpu
;
4217 ts
= ((CPUState
*)cpu_env
)->opaque
;
4218 if (ts
->child_tidptr
) {
4219 put_user_u32(0, ts
->child_tidptr
);
4220 sys_futex(g2h(ts
->child_tidptr
), FUTEX_WAKE
, INT_MAX
,
4223 /* TODO: Free CPU state. */
4230 gdb_exit(cpu_env
, arg1
);
4232 ret
= 0; /* avoid warning */
4234 case TARGET_NR_read
:
4238 if (!(p
= lock_user(VERIFY_WRITE
, arg2
, arg3
, 0)))
4240 ret
= get_errno(read(arg1
, p
, arg3
));
4241 unlock_user(p
, arg2
, ret
);
4244 case TARGET_NR_write
:
4245 if (!(p
= lock_user(VERIFY_READ
, arg2
, arg3
, 1)))
4247 ret
= get_errno(write(arg1
, p
, arg3
));
4248 unlock_user(p
, arg2
, 0);
4250 case TARGET_NR_open
:
4251 if (!(p
= lock_user_string(arg1
)))
4253 ret
= get_errno(open(path(p
),
4254 target_to_host_bitmask(arg2
, fcntl_flags_tbl
),
4256 unlock_user(p
, arg1
, 0);
4258 #if defined(TARGET_NR_openat) && defined(__NR_openat)
4259 case TARGET_NR_openat
:
4260 if (!(p
= lock_user_string(arg2
)))
4262 ret
= get_errno(sys_openat(arg1
,
4264 target_to_host_bitmask(arg3
, fcntl_flags_tbl
),
4266 unlock_user(p
, arg2
, 0);
4269 case TARGET_NR_close
:
4270 ret
= get_errno(close(arg1
));
4275 case TARGET_NR_fork
:
4276 ret
= get_errno(do_fork(cpu_env
, SIGCHLD
, 0, 0, 0, 0));
4278 #ifdef TARGET_NR_waitpid
4279 case TARGET_NR_waitpid
:
4282 ret
= get_errno(waitpid(arg1
, &status
, arg3
));
4283 if (!is_error(ret
) && arg2
4284 && put_user_s32(host_to_target_waitstatus(status
), arg2
))
4289 #ifdef TARGET_NR_waitid
4290 case TARGET_NR_waitid
:
4294 ret
= get_errno(waitid(arg1
, arg2
, &info
, arg4
));
4295 if (!is_error(ret
) && arg3
&& info
.si_pid
!= 0) {
4296 if (!(p
= lock_user(VERIFY_WRITE
, arg3
, sizeof(target_siginfo_t
), 0)))
4298 host_to_target_siginfo(p
, &info
);
4299 unlock_user(p
, arg3
, sizeof(target_siginfo_t
));
4304 #ifdef TARGET_NR_creat /* not on alpha */
4305 case TARGET_NR_creat
:
4306 if (!(p
= lock_user_string(arg1
)))
4308 ret
= get_errno(creat(p
, arg2
));
4309 unlock_user(p
, arg1
, 0);
4312 case TARGET_NR_link
:
4315 p
= lock_user_string(arg1
);
4316 p2
= lock_user_string(arg2
);
4318 ret
= -TARGET_EFAULT
;
4320 ret
= get_errno(link(p
, p2
));
4321 unlock_user(p2
, arg2
, 0);
4322 unlock_user(p
, arg1
, 0);
4325 #if defined(TARGET_NR_linkat) && defined(__NR_linkat)
4326 case TARGET_NR_linkat
:
4331 p
= lock_user_string(arg2
);
4332 p2
= lock_user_string(arg4
);
4334 ret
= -TARGET_EFAULT
;
4336 ret
= get_errno(sys_linkat(arg1
, p
, arg3
, p2
, arg5
));
4337 unlock_user(p
, arg2
, 0);
4338 unlock_user(p2
, arg4
, 0);
4342 case TARGET_NR_unlink
:
4343 if (!(p
= lock_user_string(arg1
)))
4345 ret
= get_errno(unlink(p
));
4346 unlock_user(p
, arg1
, 0);
4348 #if defined(TARGET_NR_unlinkat) && defined(__NR_unlinkat)
4349 case TARGET_NR_unlinkat
:
4350 if (!(p
= lock_user_string(arg2
)))
4352 ret
= get_errno(sys_unlinkat(arg1
, p
, arg3
));
4353 unlock_user(p
, arg2
, 0);
4356 case TARGET_NR_execve
:
4358 char **argp
, **envp
;
4361 abi_ulong guest_argp
;
4362 abi_ulong guest_envp
;
4368 for (gp
= guest_argp
; gp
; gp
+= sizeof(abi_ulong
)) {
4369 if (get_user_ual(addr
, gp
))
4377 for (gp
= guest_envp
; gp
; gp
+= sizeof(abi_ulong
)) {
4378 if (get_user_ual(addr
, gp
))
4385 argp
= alloca((argc
+ 1) * sizeof(void *));
4386 envp
= alloca((envc
+ 1) * sizeof(void *));
4388 for (gp
= guest_argp
, q
= argp
; gp
;
4389 gp
+= sizeof(abi_ulong
), q
++) {
4390 if (get_user_ual(addr
, gp
))
4394 if (!(*q
= lock_user_string(addr
)))
4399 for (gp
= guest_envp
, q
= envp
; gp
;
4400 gp
+= sizeof(abi_ulong
), q
++) {
4401 if (get_user_ual(addr
, gp
))
4405 if (!(*q
= lock_user_string(addr
)))
4410 if (!(p
= lock_user_string(arg1
)))
4412 ret
= get_errno(execve(p
, argp
, envp
));
4413 unlock_user(p
, arg1
, 0);
4418 ret
= -TARGET_EFAULT
;
4421 for (gp
= guest_argp
, q
= argp
; *q
;
4422 gp
+= sizeof(abi_ulong
), q
++) {
4423 if (get_user_ual(addr
, gp
)
4426 unlock_user(*q
, addr
, 0);
4428 for (gp
= guest_envp
, q
= envp
; *q
;
4429 gp
+= sizeof(abi_ulong
), q
++) {
4430 if (get_user_ual(addr
, gp
)
4433 unlock_user(*q
, addr
, 0);
4437 case TARGET_NR_chdir
:
4438 if (!(p
= lock_user_string(arg1
)))
4440 ret
= get_errno(chdir(p
));
4441 unlock_user(p
, arg1
, 0);
4443 #ifdef TARGET_NR_time
4444 case TARGET_NR_time
:
4447 ret
= get_errno(time(&host_time
));
4450 && put_user_sal(host_time
, arg1
))
4455 case TARGET_NR_mknod
:
4456 if (!(p
= lock_user_string(arg1
)))
4458 ret
= get_errno(mknod(p
, arg2
, arg3
));
4459 unlock_user(p
, arg1
, 0);
4461 #if defined(TARGET_NR_mknodat) && defined(__NR_mknodat)
4462 case TARGET_NR_mknodat
:
4463 if (!(p
= lock_user_string(arg2
)))
4465 ret
= get_errno(sys_mknodat(arg1
, p
, arg3
, arg4
));
4466 unlock_user(p
, arg2
, 0);
4469 case TARGET_NR_chmod
:
4470 if (!(p
= lock_user_string(arg1
)))
4472 ret
= get_errno(chmod(p
, arg2
));
4473 unlock_user(p
, arg1
, 0);
4475 #ifdef TARGET_NR_break
4476 case TARGET_NR_break
:
4479 #ifdef TARGET_NR_oldstat
4480 case TARGET_NR_oldstat
:
4483 case TARGET_NR_lseek
:
4484 ret
= get_errno(lseek(arg1
, arg2
, arg3
));
4486 #ifdef TARGET_NR_getxpid
4487 case TARGET_NR_getxpid
:
4489 case TARGET_NR_getpid
:
4491 ret
= get_errno(getpid());
4493 case TARGET_NR_mount
:
4495 /* need to look at the data field */
4497 p
= lock_user_string(arg1
);
4498 p2
= lock_user_string(arg2
);
4499 p3
= lock_user_string(arg3
);
4500 if (!p
|| !p2
|| !p3
)
4501 ret
= -TARGET_EFAULT
;
4503 /* FIXME - arg5 should be locked, but it isn't clear how to
4504 * do that since it's not guaranteed to be a NULL-terminated
4508 ret
= get_errno(mount(p
, p2
, p3
, (unsigned long)arg4
, NULL
));
4510 ret
= get_errno(mount(p
, p2
, p3
, (unsigned long)arg4
, g2h(arg5
)));
4512 unlock_user(p
, arg1
, 0);
4513 unlock_user(p2
, arg2
, 0);
4514 unlock_user(p3
, arg3
, 0);
4517 #ifdef TARGET_NR_umount
4518 case TARGET_NR_umount
:
4519 if (!(p
= lock_user_string(arg1
)))
4521 ret
= get_errno(umount(p
));
4522 unlock_user(p
, arg1
, 0);
4525 #ifdef TARGET_NR_stime /* not on alpha */
4526 case TARGET_NR_stime
:
4529 if (get_user_sal(host_time
, arg1
))
4531 ret
= get_errno(stime(&host_time
));
4535 case TARGET_NR_ptrace
:
4537 #ifdef TARGET_NR_alarm /* not on alpha */
4538 case TARGET_NR_alarm
:
4542 #ifdef TARGET_NR_oldfstat
4543 case TARGET_NR_oldfstat
:
4546 #ifdef TARGET_NR_pause /* not on alpha */
4547 case TARGET_NR_pause
:
4548 ret
= get_errno(pause());
4551 #ifdef TARGET_NR_utime
4552 case TARGET_NR_utime
:
4554 struct utimbuf tbuf
, *host_tbuf
;
4555 struct target_utimbuf
*target_tbuf
;
4557 if (!lock_user_struct(VERIFY_READ
, target_tbuf
, arg2
, 1))
4559 tbuf
.actime
= tswapl(target_tbuf
->actime
);
4560 tbuf
.modtime
= tswapl(target_tbuf
->modtime
);
4561 unlock_user_struct(target_tbuf
, arg2
, 0);
4566 if (!(p
= lock_user_string(arg1
)))
4568 ret
= get_errno(utime(p
, host_tbuf
));
4569 unlock_user(p
, arg1
, 0);
4573 case TARGET_NR_utimes
:
4575 struct timeval
*tvp
, tv
[2];
4577 if (copy_from_user_timeval(&tv
[0], arg2
)
4578 || copy_from_user_timeval(&tv
[1],
4579 arg2
+ sizeof(struct target_timeval
)))
4585 if (!(p
= lock_user_string(arg1
)))
4587 ret
= get_errno(utimes(p
, tvp
));
4588 unlock_user(p
, arg1
, 0);
4591 #if defined(TARGET_NR_futimesat) && defined(__NR_futimesat)
4592 case TARGET_NR_futimesat
:
4594 struct timeval
*tvp
, tv
[2];
4596 if (copy_from_user_timeval(&tv
[0], arg3
)
4597 || copy_from_user_timeval(&tv
[1],
4598 arg3
+ sizeof(struct target_timeval
)))
4604 if (!(p
= lock_user_string(arg2
)))
4606 ret
= get_errno(sys_futimesat(arg1
, path(p
), tvp
));
4607 unlock_user(p
, arg2
, 0);
4611 #ifdef TARGET_NR_stty
4612 case TARGET_NR_stty
:
4615 #ifdef TARGET_NR_gtty
4616 case TARGET_NR_gtty
:
4619 case TARGET_NR_access
:
4620 if (!(p
= lock_user_string(arg1
)))
4622 ret
= get_errno(access(path(p
), arg2
));
4623 unlock_user(p
, arg1
, 0);
4625 #if defined(TARGET_NR_faccessat) && defined(__NR_faccessat)
4626 case TARGET_NR_faccessat
:
4627 if (!(p
= lock_user_string(arg2
)))
4629 ret
= get_errno(sys_faccessat(arg1
, p
, arg3
));
4630 unlock_user(p
, arg2
, 0);
4633 #ifdef TARGET_NR_nice /* not on alpha */
4634 case TARGET_NR_nice
:
4635 ret
= get_errno(nice(arg1
));
4638 #ifdef TARGET_NR_ftime
4639 case TARGET_NR_ftime
:
4642 case TARGET_NR_sync
:
4646 case TARGET_NR_kill
:
4647 ret
= get_errno(kill(arg1
, target_to_host_signal(arg2
)));
4649 case TARGET_NR_rename
:
4652 p
= lock_user_string(arg1
);
4653 p2
= lock_user_string(arg2
);
4655 ret
= -TARGET_EFAULT
;
4657 ret
= get_errno(rename(p
, p2
));
4658 unlock_user(p2
, arg2
, 0);
4659 unlock_user(p
, arg1
, 0);
4662 #if defined(TARGET_NR_renameat) && defined(__NR_renameat)
4663 case TARGET_NR_renameat
:
4666 p
= lock_user_string(arg2
);
4667 p2
= lock_user_string(arg4
);
4669 ret
= -TARGET_EFAULT
;
4671 ret
= get_errno(sys_renameat(arg1
, p
, arg3
, p2
));
4672 unlock_user(p2
, arg4
, 0);
4673 unlock_user(p
, arg2
, 0);
4677 case TARGET_NR_mkdir
:
4678 if (!(p
= lock_user_string(arg1
)))
4680 ret
= get_errno(mkdir(p
, arg2
));
4681 unlock_user(p
, arg1
, 0);
4683 #if defined(TARGET_NR_mkdirat) && defined(__NR_mkdirat)
4684 case TARGET_NR_mkdirat
:
4685 if (!(p
= lock_user_string(arg2
)))
4687 ret
= get_errno(sys_mkdirat(arg1
, p
, arg3
));
4688 unlock_user(p
, arg2
, 0);
4691 case TARGET_NR_rmdir
:
4692 if (!(p
= lock_user_string(arg1
)))
4694 ret
= get_errno(rmdir(p
));
4695 unlock_user(p
, arg1
, 0);
4698 ret
= get_errno(dup(arg1
));
4700 case TARGET_NR_pipe
:
4701 ret
= do_pipe(cpu_env
, arg1
, 0);
4703 #ifdef TARGET_NR_pipe2
4704 case TARGET_NR_pipe2
:
4705 ret
= do_pipe(cpu_env
, arg1
, arg2
);
4708 case TARGET_NR_times
:
4710 struct target_tms
*tmsp
;
4712 ret
= get_errno(times(&tms
));
4714 tmsp
= lock_user(VERIFY_WRITE
, arg1
, sizeof(struct target_tms
), 0);
4717 tmsp
->tms_utime
= tswapl(host_to_target_clock_t(tms
.tms_utime
));
4718 tmsp
->tms_stime
= tswapl(host_to_target_clock_t(tms
.tms_stime
));
4719 tmsp
->tms_cutime
= tswapl(host_to_target_clock_t(tms
.tms_cutime
));
4720 tmsp
->tms_cstime
= tswapl(host_to_target_clock_t(tms
.tms_cstime
));
4723 ret
= host_to_target_clock_t(ret
);
4726 #ifdef TARGET_NR_prof
4727 case TARGET_NR_prof
:
4730 #ifdef TARGET_NR_signal
4731 case TARGET_NR_signal
:
4734 case TARGET_NR_acct
:
4736 ret
= get_errno(acct(NULL
));
4738 if (!(p
= lock_user_string(arg1
)))
4740 ret
= get_errno(acct(path(p
)));
4741 unlock_user(p
, arg1
, 0);
4744 #ifdef TARGET_NR_umount2 /* not on alpha */
4745 case TARGET_NR_umount2
:
4746 if (!(p
= lock_user_string(arg1
)))
4748 ret
= get_errno(umount2(p
, arg2
));
4749 unlock_user(p
, arg1
, 0);
4752 #ifdef TARGET_NR_lock
4753 case TARGET_NR_lock
:
4756 case TARGET_NR_ioctl
:
4757 ret
= do_ioctl(arg1
, arg2
, arg3
);
4759 case TARGET_NR_fcntl
:
4760 ret
= do_fcntl(arg1
, arg2
, arg3
);
4762 #ifdef TARGET_NR_mpx
4766 case TARGET_NR_setpgid
:
4767 ret
= get_errno(setpgid(arg1
, arg2
));
4769 #ifdef TARGET_NR_ulimit
4770 case TARGET_NR_ulimit
:
4773 #ifdef TARGET_NR_oldolduname
4774 case TARGET_NR_oldolduname
:
4777 case TARGET_NR_umask
:
4778 ret
= get_errno(umask(arg1
));
4780 case TARGET_NR_chroot
:
4781 if (!(p
= lock_user_string(arg1
)))
4783 ret
= get_errno(chroot(p
));
4784 unlock_user(p
, arg1
, 0);
4786 case TARGET_NR_ustat
:
4788 case TARGET_NR_dup2
:
4789 ret
= get_errno(dup2(arg1
, arg2
));
4791 #if defined(CONFIG_DUP3) && defined(TARGET_NR_dup3)
4792 case TARGET_NR_dup3
:
4793 ret
= get_errno(dup3(arg1
, arg2
, arg3
));
4796 #ifdef TARGET_NR_getppid /* not on alpha */
4797 case TARGET_NR_getppid
:
4798 ret
= get_errno(getppid());
4801 case TARGET_NR_getpgrp
:
4802 ret
= get_errno(getpgrp());
4804 case TARGET_NR_setsid
:
4805 ret
= get_errno(setsid());
4807 #ifdef TARGET_NR_sigaction
4808 case TARGET_NR_sigaction
:
4810 #if defined(TARGET_ALPHA)
4811 struct target_sigaction act
, oact
, *pact
= 0;
4812 struct target_old_sigaction
*old_act
;
4814 if (!lock_user_struct(VERIFY_READ
, old_act
, arg2
, 1))
4816 act
._sa_handler
= old_act
->_sa_handler
;
4817 target_siginitset(&act
.sa_mask
, old_act
->sa_mask
);
4818 act
.sa_flags
= old_act
->sa_flags
;
4819 act
.sa_restorer
= 0;
4820 unlock_user_struct(old_act
, arg2
, 0);
4823 ret
= get_errno(do_sigaction(arg1
, pact
, &oact
));
4824 if (!is_error(ret
) && arg3
) {
4825 if (!lock_user_struct(VERIFY_WRITE
, old_act
, arg3
, 0))
4827 old_act
->_sa_handler
= oact
._sa_handler
;
4828 old_act
->sa_mask
= oact
.sa_mask
.sig
[0];
4829 old_act
->sa_flags
= oact
.sa_flags
;
4830 unlock_user_struct(old_act
, arg3
, 1);
4832 #elif defined(TARGET_MIPS)
4833 struct target_sigaction act
, oact
, *pact
, *old_act
;
4836 if (!lock_user_struct(VERIFY_READ
, old_act
, arg2
, 1))
4838 act
._sa_handler
= old_act
->_sa_handler
;
4839 target_siginitset(&act
.sa_mask
, old_act
->sa_mask
.sig
[0]);
4840 act
.sa_flags
= old_act
->sa_flags
;
4841 unlock_user_struct(old_act
, arg2
, 0);
4847 ret
= get_errno(do_sigaction(arg1
, pact
, &oact
));
4849 if (!is_error(ret
) && arg3
) {
4850 if (!lock_user_struct(VERIFY_WRITE
, old_act
, arg3
, 0))
4852 old_act
->_sa_handler
= oact
._sa_handler
;
4853 old_act
->sa_flags
= oact
.sa_flags
;
4854 old_act
->sa_mask
.sig
[0] = oact
.sa_mask
.sig
[0];
4855 old_act
->sa_mask
.sig
[1] = 0;
4856 old_act
->sa_mask
.sig
[2] = 0;
4857 old_act
->sa_mask
.sig
[3] = 0;
4858 unlock_user_struct(old_act
, arg3
, 1);
4861 struct target_old_sigaction
*old_act
;
4862 struct target_sigaction act
, oact
, *pact
;
4864 if (!lock_user_struct(VERIFY_READ
, old_act
, arg2
, 1))
4866 act
._sa_handler
= old_act
->_sa_handler
;
4867 target_siginitset(&act
.sa_mask
, old_act
->sa_mask
);
4868 act
.sa_flags
= old_act
->sa_flags
;
4869 act
.sa_restorer
= old_act
->sa_restorer
;
4870 unlock_user_struct(old_act
, arg2
, 0);
4875 ret
= get_errno(do_sigaction(arg1
, pact
, &oact
));
4876 if (!is_error(ret
) && arg3
) {
4877 if (!lock_user_struct(VERIFY_WRITE
, old_act
, arg3
, 0))
4879 old_act
->_sa_handler
= oact
._sa_handler
;
4880 old_act
->sa_mask
= oact
.sa_mask
.sig
[0];
4881 old_act
->sa_flags
= oact
.sa_flags
;
4882 old_act
->sa_restorer
= oact
.sa_restorer
;
4883 unlock_user_struct(old_act
, arg3
, 1);
4889 case TARGET_NR_rt_sigaction
:
4891 #if defined(TARGET_ALPHA)
4892 struct target_sigaction act
, oact
, *pact
= 0;
4893 struct target_rt_sigaction
*rt_act
;
4894 /* ??? arg4 == sizeof(sigset_t). */
4896 if (!lock_user_struct(VERIFY_READ
, rt_act
, arg2
, 1))
4898 act
._sa_handler
= rt_act
->_sa_handler
;
4899 act
.sa_mask
= rt_act
->sa_mask
;
4900 act
.sa_flags
= rt_act
->sa_flags
;
4901 act
.sa_restorer
= arg5
;
4902 unlock_user_struct(rt_act
, arg2
, 0);
4905 ret
= get_errno(do_sigaction(arg1
, pact
, &oact
));
4906 if (!is_error(ret
) && arg3
) {
4907 if (!lock_user_struct(VERIFY_WRITE
, rt_act
, arg3
, 0))
4909 rt_act
->_sa_handler
= oact
._sa_handler
;
4910 rt_act
->sa_mask
= oact
.sa_mask
;
4911 rt_act
->sa_flags
= oact
.sa_flags
;
4912 unlock_user_struct(rt_act
, arg3
, 1);
4915 struct target_sigaction
*act
;
4916 struct target_sigaction
*oact
;
4919 if (!lock_user_struct(VERIFY_READ
, act
, arg2
, 1))
4924 if (!lock_user_struct(VERIFY_WRITE
, oact
, arg3
, 0)) {
4925 ret
= -TARGET_EFAULT
;
4926 goto rt_sigaction_fail
;
4930 ret
= get_errno(do_sigaction(arg1
, act
, oact
));
4933 unlock_user_struct(act
, arg2
, 0);
4935 unlock_user_struct(oact
, arg3
, 1);
4939 #ifdef TARGET_NR_sgetmask /* not on alpha */
4940 case TARGET_NR_sgetmask
:
4943 abi_ulong target_set
;
4944 sigprocmask(0, NULL
, &cur_set
);
4945 host_to_target_old_sigset(&target_set
, &cur_set
);
4950 #ifdef TARGET_NR_ssetmask /* not on alpha */
4951 case TARGET_NR_ssetmask
:
4953 sigset_t set
, oset
, cur_set
;
4954 abi_ulong target_set
= arg1
;
4955 sigprocmask(0, NULL
, &cur_set
);
4956 target_to_host_old_sigset(&set
, &target_set
);
4957 sigorset(&set
, &set
, &cur_set
);
4958 sigprocmask(SIG_SETMASK
, &set
, &oset
);
4959 host_to_target_old_sigset(&target_set
, &oset
);
4964 #ifdef TARGET_NR_sigprocmask
4965 case TARGET_NR_sigprocmask
:
4968 sigset_t set
, oldset
, *set_ptr
;
4972 case TARGET_SIG_BLOCK
:
4975 case TARGET_SIG_UNBLOCK
:
4978 case TARGET_SIG_SETMASK
:
4982 ret
= -TARGET_EINVAL
;
4985 if (!(p
= lock_user(VERIFY_READ
, arg2
, sizeof(target_sigset_t
), 1)))
4987 target_to_host_old_sigset(&set
, p
);
4988 unlock_user(p
, arg2
, 0);
4994 ret
= get_errno(sigprocmask(arg1
, set_ptr
, &oldset
));
4995 if (!is_error(ret
) && arg3
) {
4996 if (!(p
= lock_user(VERIFY_WRITE
, arg3
, sizeof(target_sigset_t
), 0)))
4998 host_to_target_old_sigset(p
, &oldset
);
4999 unlock_user(p
, arg3
, sizeof(target_sigset_t
));
5004 case TARGET_NR_rt_sigprocmask
:
5007 sigset_t set
, oldset
, *set_ptr
;
5011 case TARGET_SIG_BLOCK
:
5014 case TARGET_SIG_UNBLOCK
:
5017 case TARGET_SIG_SETMASK
:
5021 ret
= -TARGET_EINVAL
;
5024 if (!(p
= lock_user(VERIFY_READ
, arg2
, sizeof(target_sigset_t
), 1)))
5026 target_to_host_sigset(&set
, p
);
5027 unlock_user(p
, arg2
, 0);
5033 ret
= get_errno(sigprocmask(how
, set_ptr
, &oldset
));
5034 if (!is_error(ret
) && arg3
) {
5035 if (!(p
= lock_user(VERIFY_WRITE
, arg3
, sizeof(target_sigset_t
), 0)))
5037 host_to_target_sigset(p
, &oldset
);
5038 unlock_user(p
, arg3
, sizeof(target_sigset_t
));
5042 #ifdef TARGET_NR_sigpending
5043 case TARGET_NR_sigpending
:
5046 ret
= get_errno(sigpending(&set
));
5047 if (!is_error(ret
)) {
5048 if (!(p
= lock_user(VERIFY_WRITE
, arg1
, sizeof(target_sigset_t
), 0)))
5050 host_to_target_old_sigset(p
, &set
);
5051 unlock_user(p
, arg1
, sizeof(target_sigset_t
));
5056 case TARGET_NR_rt_sigpending
:
5059 ret
= get_errno(sigpending(&set
));
5060 if (!is_error(ret
)) {
5061 if (!(p
= lock_user(VERIFY_WRITE
, arg1
, sizeof(target_sigset_t
), 0)))
5063 host_to_target_sigset(p
, &set
);
5064 unlock_user(p
, arg1
, sizeof(target_sigset_t
));
5068 #ifdef TARGET_NR_sigsuspend
5069 case TARGET_NR_sigsuspend
:
5072 if (!(p
= lock_user(VERIFY_READ
, arg1
, sizeof(target_sigset_t
), 1)))
5074 target_to_host_old_sigset(&set
, p
);
5075 unlock_user(p
, arg1
, 0);
5076 ret
= get_errno(sigsuspend(&set
));
5080 case TARGET_NR_rt_sigsuspend
:
5083 if (!(p
= lock_user(VERIFY_READ
, arg1
, sizeof(target_sigset_t
), 1)))
5085 target_to_host_sigset(&set
, p
);
5086 unlock_user(p
, arg1
, 0);
5087 ret
= get_errno(sigsuspend(&set
));
5090 case TARGET_NR_rt_sigtimedwait
:
5093 struct timespec uts
, *puts
;
5096 if (!(p
= lock_user(VERIFY_READ
, arg1
, sizeof(target_sigset_t
), 1)))
5098 target_to_host_sigset(&set
, p
);
5099 unlock_user(p
, arg1
, 0);
5102 target_to_host_timespec(puts
, arg3
);
5106 ret
= get_errno(sigtimedwait(&set
, &uinfo
, puts
));
5107 if (!is_error(ret
) && arg2
) {
5108 if (!(p
= lock_user(VERIFY_WRITE
, arg2
, sizeof(target_siginfo_t
), 0)))
5110 host_to_target_siginfo(p
, &uinfo
);
5111 unlock_user(p
, arg2
, sizeof(target_siginfo_t
));
5115 case TARGET_NR_rt_sigqueueinfo
:
5118 if (!(p
= lock_user(VERIFY_READ
, arg3
, sizeof(target_sigset_t
), 1)))
5120 target_to_host_siginfo(&uinfo
, p
);
5121 unlock_user(p
, arg1
, 0);
5122 ret
= get_errno(sys_rt_sigqueueinfo(arg1
, arg2
, &uinfo
));
5125 #ifdef TARGET_NR_sigreturn
5126 case TARGET_NR_sigreturn
:
5127 /* NOTE: ret is eax, so not transcoding must be done */
5128 ret
= do_sigreturn(cpu_env
);
5131 case TARGET_NR_rt_sigreturn
:
5132 /* NOTE: ret is eax, so not transcoding must be done */
5133 ret
= do_rt_sigreturn(cpu_env
);
5135 case TARGET_NR_sethostname
:
5136 if (!(p
= lock_user_string(arg1
)))
5138 ret
= get_errno(sethostname(p
, arg2
));
5139 unlock_user(p
, arg1
, 0);
5141 case TARGET_NR_setrlimit
:
5143 int resource
= arg1
;
5144 struct target_rlimit
*target_rlim
;
5146 if (!lock_user_struct(VERIFY_READ
, target_rlim
, arg2
, 1))
5148 rlim
.rlim_cur
= target_to_host_rlim(target_rlim
->rlim_cur
);
5149 rlim
.rlim_max
= target_to_host_rlim(target_rlim
->rlim_max
);
5150 unlock_user_struct(target_rlim
, arg2
, 0);
5151 ret
= get_errno(setrlimit(resource
, &rlim
));
5154 case TARGET_NR_getrlimit
:
5156 int resource
= arg1
;
5157 struct target_rlimit
*target_rlim
;
5160 ret
= get_errno(getrlimit(resource
, &rlim
));
5161 if (!is_error(ret
)) {
5162 if (!lock_user_struct(VERIFY_WRITE
, target_rlim
, arg2
, 0))
5164 target_rlim
->rlim_cur
= host_to_target_rlim(rlim
.rlim_cur
);
5165 target_rlim
->rlim_max
= host_to_target_rlim(rlim
.rlim_max
);
5166 unlock_user_struct(target_rlim
, arg2
, 1);
5170 case TARGET_NR_getrusage
:
5172 struct rusage rusage
;
5173 ret
= get_errno(getrusage(arg1
, &rusage
));
5174 if (!is_error(ret
)) {
5175 host_to_target_rusage(arg2
, &rusage
);
5179 case TARGET_NR_gettimeofday
:
5182 ret
= get_errno(gettimeofday(&tv
, NULL
));
5183 if (!is_error(ret
)) {
5184 if (copy_to_user_timeval(arg1
, &tv
))
5189 case TARGET_NR_settimeofday
:
5192 if (copy_from_user_timeval(&tv
, arg1
))
5194 ret
= get_errno(settimeofday(&tv
, NULL
));
5197 #ifdef TARGET_NR_select
5198 case TARGET_NR_select
:
5200 struct target_sel_arg_struct
*sel
;
5201 abi_ulong inp
, outp
, exp
, tvp
;
5204 if (!lock_user_struct(VERIFY_READ
, sel
, arg1
, 1))
5206 nsel
= tswapl(sel
->n
);
5207 inp
= tswapl(sel
->inp
);
5208 outp
= tswapl(sel
->outp
);
5209 exp
= tswapl(sel
->exp
);
5210 tvp
= tswapl(sel
->tvp
);
5211 unlock_user_struct(sel
, arg1
, 0);
5212 ret
= do_select(nsel
, inp
, outp
, exp
, tvp
);
5216 case TARGET_NR_symlink
:
5219 p
= lock_user_string(arg1
);
5220 p2
= lock_user_string(arg2
);
5222 ret
= -TARGET_EFAULT
;
5224 ret
= get_errno(symlink(p
, p2
));
5225 unlock_user(p2
, arg2
, 0);
5226 unlock_user(p
, arg1
, 0);
5229 #if defined(TARGET_NR_symlinkat) && defined(__NR_symlinkat)
5230 case TARGET_NR_symlinkat
:
5233 p
= lock_user_string(arg1
);
5234 p2
= lock_user_string(arg3
);
5236 ret
= -TARGET_EFAULT
;
5238 ret
= get_errno(sys_symlinkat(p
, arg2
, p2
));
5239 unlock_user(p2
, arg3
, 0);
5240 unlock_user(p
, arg1
, 0);
5244 #ifdef TARGET_NR_oldlstat
5245 case TARGET_NR_oldlstat
:
5248 case TARGET_NR_readlink
:
5251 p
= lock_user_string(arg1
);
5252 p2
= lock_user(VERIFY_WRITE
, arg2
, arg3
, 0);
5254 ret
= -TARGET_EFAULT
;
5256 if (strncmp((const char *)p
, "/proc/self/exe", 14) == 0) {
5257 char real
[PATH_MAX
];
5258 temp
= realpath(exec_path
,real
);
5259 ret
= (temp
==NULL
) ? get_errno(-1) : strlen(real
) ;
5260 snprintf((char *)p2
, arg3
, "%s", real
);
5263 ret
= get_errno(readlink(path(p
), p2
, arg3
));
5265 unlock_user(p2
, arg2
, ret
);
5266 unlock_user(p
, arg1
, 0);
5269 #if defined(TARGET_NR_readlinkat) && defined(__NR_readlinkat)
5270 case TARGET_NR_readlinkat
:
5273 p
= lock_user_string(arg2
);
5274 p2
= lock_user(VERIFY_WRITE
, arg3
, arg4
, 0);
5276 ret
= -TARGET_EFAULT
;
5278 ret
= get_errno(sys_readlinkat(arg1
, path(p
), p2
, arg4
));
5279 unlock_user(p2
, arg3
, ret
);
5280 unlock_user(p
, arg2
, 0);
5284 #ifdef TARGET_NR_uselib
5285 case TARGET_NR_uselib
:
5288 #ifdef TARGET_NR_swapon
5289 case TARGET_NR_swapon
:
5290 if (!(p
= lock_user_string(arg1
)))
5292 ret
= get_errno(swapon(p
, arg2
));
5293 unlock_user(p
, arg1
, 0);
5296 case TARGET_NR_reboot
:
5298 #ifdef TARGET_NR_readdir
5299 case TARGET_NR_readdir
:
5302 #ifdef TARGET_NR_mmap
5303 case TARGET_NR_mmap
:
5304 #if (defined(TARGET_I386) && defined(TARGET_ABI32)) || defined(TARGET_ARM) || defined(TARGET_M68K) || defined(TARGET_CRIS) || defined(TARGET_MICROBLAZE)
5307 abi_ulong v1
, v2
, v3
, v4
, v5
, v6
;
5308 if (!(v
= lock_user(VERIFY_READ
, arg1
, 6 * sizeof(abi_ulong
), 1)))
5316 unlock_user(v
, arg1
, 0);
5317 ret
= get_errno(target_mmap(v1
, v2
, v3
,
5318 target_to_host_bitmask(v4
, mmap_flags_tbl
),
5322 ret
= get_errno(target_mmap(arg1
, arg2
, arg3
,
5323 target_to_host_bitmask(arg4
, mmap_flags_tbl
),
5329 #ifdef TARGET_NR_mmap2
5330 case TARGET_NR_mmap2
:
5332 #define MMAP_SHIFT 12
5334 ret
= get_errno(target_mmap(arg1
, arg2
, arg3
,
5335 target_to_host_bitmask(arg4
, mmap_flags_tbl
),
5337 arg6
<< MMAP_SHIFT
));
5340 case TARGET_NR_munmap
:
5341 ret
= get_errno(target_munmap(arg1
, arg2
));
5343 case TARGET_NR_mprotect
:
5344 ret
= get_errno(target_mprotect(arg1
, arg2
, arg3
));
5346 #ifdef TARGET_NR_mremap
5347 case TARGET_NR_mremap
:
5348 ret
= get_errno(target_mremap(arg1
, arg2
, arg3
, arg4
, arg5
));
5351 /* ??? msync/mlock/munlock are broken for softmmu. */
5352 #ifdef TARGET_NR_msync
5353 case TARGET_NR_msync
:
5354 ret
= get_errno(msync(g2h(arg1
), arg2
, arg3
));
5357 #ifdef TARGET_NR_mlock
5358 case TARGET_NR_mlock
:
5359 ret
= get_errno(mlock(g2h(arg1
), arg2
));
5362 #ifdef TARGET_NR_munlock
5363 case TARGET_NR_munlock
:
5364 ret
= get_errno(munlock(g2h(arg1
), arg2
));
5367 #ifdef TARGET_NR_mlockall
5368 case TARGET_NR_mlockall
:
5369 ret
= get_errno(mlockall(arg1
));
5372 #ifdef TARGET_NR_munlockall
5373 case TARGET_NR_munlockall
:
5374 ret
= get_errno(munlockall());
5377 case TARGET_NR_truncate
:
5378 if (!(p
= lock_user_string(arg1
)))
5380 ret
= get_errno(truncate(p
, arg2
));
5381 unlock_user(p
, arg1
, 0);
5383 case TARGET_NR_ftruncate
:
5384 ret
= get_errno(ftruncate(arg1
, arg2
));
5386 case TARGET_NR_fchmod
:
5387 ret
= get_errno(fchmod(arg1
, arg2
));
5389 #if defined(TARGET_NR_fchmodat) && defined(__NR_fchmodat)
5390 case TARGET_NR_fchmodat
:
5391 if (!(p
= lock_user_string(arg2
)))
5393 ret
= get_errno(sys_fchmodat(arg1
, p
, arg3
));
5394 unlock_user(p
, arg2
, 0);
5397 case TARGET_NR_getpriority
:
5398 /* libc does special remapping of the return value of
5399 * sys_getpriority() so it's just easiest to call
5400 * sys_getpriority() directly rather than through libc. */
5401 ret
= get_errno(sys_getpriority(arg1
, arg2
));
5403 case TARGET_NR_setpriority
:
5404 ret
= get_errno(setpriority(arg1
, arg2
, arg3
));
5406 #ifdef TARGET_NR_profil
5407 case TARGET_NR_profil
:
5410 case TARGET_NR_statfs
:
5411 if (!(p
= lock_user_string(arg1
)))
5413 ret
= get_errno(statfs(path(p
), &stfs
));
5414 unlock_user(p
, arg1
, 0);
5416 if (!is_error(ret
)) {
5417 struct target_statfs
*target_stfs
;
5419 if (!lock_user_struct(VERIFY_WRITE
, target_stfs
, arg2
, 0))
5421 __put_user(stfs
.f_type
, &target_stfs
->f_type
);
5422 __put_user(stfs
.f_bsize
, &target_stfs
->f_bsize
);
5423 __put_user(stfs
.f_blocks
, &target_stfs
->f_blocks
);
5424 __put_user(stfs
.f_bfree
, &target_stfs
->f_bfree
);
5425 __put_user(stfs
.f_bavail
, &target_stfs
->f_bavail
);
5426 __put_user(stfs
.f_files
, &target_stfs
->f_files
);
5427 __put_user(stfs
.f_ffree
, &target_stfs
->f_ffree
);
5428 __put_user(stfs
.f_fsid
.__val
[0], &target_stfs
->f_fsid
.val
[0]);
5429 __put_user(stfs
.f_fsid
.__val
[1], &target_stfs
->f_fsid
.val
[1]);
5430 __put_user(stfs
.f_namelen
, &target_stfs
->f_namelen
);
5431 unlock_user_struct(target_stfs
, arg2
, 1);
5434 case TARGET_NR_fstatfs
:
5435 ret
= get_errno(fstatfs(arg1
, &stfs
));
5436 goto convert_statfs
;
5437 #ifdef TARGET_NR_statfs64
5438 case TARGET_NR_statfs64
:
5439 if (!(p
= lock_user_string(arg1
)))
5441 ret
= get_errno(statfs(path(p
), &stfs
));
5442 unlock_user(p
, arg1
, 0);
5444 if (!is_error(ret
)) {
5445 struct target_statfs64
*target_stfs
;
5447 if (!lock_user_struct(VERIFY_WRITE
, target_stfs
, arg3
, 0))
5449 __put_user(stfs
.f_type
, &target_stfs
->f_type
);
5450 __put_user(stfs
.f_bsize
, &target_stfs
->f_bsize
);
5451 __put_user(stfs
.f_blocks
, &target_stfs
->f_blocks
);
5452 __put_user(stfs
.f_bfree
, &target_stfs
->f_bfree
);
5453 __put_user(stfs
.f_bavail
, &target_stfs
->f_bavail
);
5454 __put_user(stfs
.f_files
, &target_stfs
->f_files
);
5455 __put_user(stfs
.f_ffree
, &target_stfs
->f_ffree
);
5456 __put_user(stfs
.f_fsid
.__val
[0], &target_stfs
->f_fsid
.val
[0]);
5457 __put_user(stfs
.f_fsid
.__val
[1], &target_stfs
->f_fsid
.val
[1]);
5458 __put_user(stfs
.f_namelen
, &target_stfs
->f_namelen
);
5459 unlock_user_struct(target_stfs
, arg3
, 1);
5462 case TARGET_NR_fstatfs64
:
5463 ret
= get_errno(fstatfs(arg1
, &stfs
));
5464 goto convert_statfs64
;
5466 #ifdef TARGET_NR_ioperm
5467 case TARGET_NR_ioperm
:
5470 #ifdef TARGET_NR_socketcall
5471 case TARGET_NR_socketcall
:
5472 ret
= do_socketcall(arg1
, arg2
);
5475 #ifdef TARGET_NR_accept
5476 case TARGET_NR_accept
:
5477 ret
= do_accept(arg1
, arg2
, arg3
);
5480 #ifdef TARGET_NR_bind
5481 case TARGET_NR_bind
:
5482 ret
= do_bind(arg1
, arg2
, arg3
);
5485 #ifdef TARGET_NR_connect
5486 case TARGET_NR_connect
:
5487 ret
= do_connect(arg1
, arg2
, arg3
);
5490 #ifdef TARGET_NR_getpeername
5491 case TARGET_NR_getpeername
:
5492 ret
= do_getpeername(arg1
, arg2
, arg3
);
5495 #ifdef TARGET_NR_getsockname
5496 case TARGET_NR_getsockname
:
5497 ret
= do_getsockname(arg1
, arg2
, arg3
);
5500 #ifdef TARGET_NR_getsockopt
5501 case TARGET_NR_getsockopt
:
5502 ret
= do_getsockopt(arg1
, arg2
, arg3
, arg4
, arg5
);
5505 #ifdef TARGET_NR_listen
5506 case TARGET_NR_listen
:
5507 ret
= get_errno(listen(arg1
, arg2
));
5510 #ifdef TARGET_NR_recv
5511 case TARGET_NR_recv
:
5512 ret
= do_recvfrom(arg1
, arg2
, arg3
, arg4
, 0, 0);
5515 #ifdef TARGET_NR_recvfrom
5516 case TARGET_NR_recvfrom
:
5517 ret
= do_recvfrom(arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
5520 #ifdef TARGET_NR_recvmsg
5521 case TARGET_NR_recvmsg
:
5522 ret
= do_sendrecvmsg(arg1
, arg2
, arg3
, 0);
5525 #ifdef TARGET_NR_send
5526 case TARGET_NR_send
:
5527 ret
= do_sendto(arg1
, arg2
, arg3
, arg4
, 0, 0);
5530 #ifdef TARGET_NR_sendmsg
5531 case TARGET_NR_sendmsg
:
5532 ret
= do_sendrecvmsg(arg1
, arg2
, arg3
, 1);
5535 #ifdef TARGET_NR_sendto
5536 case TARGET_NR_sendto
:
5537 ret
= do_sendto(arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
5540 #ifdef TARGET_NR_shutdown
5541 case TARGET_NR_shutdown
:
5542 ret
= get_errno(shutdown(arg1
, arg2
));
5545 #ifdef TARGET_NR_socket
5546 case TARGET_NR_socket
:
5547 ret
= do_socket(arg1
, arg2
, arg3
);
5550 #ifdef TARGET_NR_socketpair
5551 case TARGET_NR_socketpair
:
5552 ret
= do_socketpair(arg1
, arg2
, arg3
, arg4
);
5555 #ifdef TARGET_NR_setsockopt
5556 case TARGET_NR_setsockopt
:
5557 ret
= do_setsockopt(arg1
, arg2
, arg3
, arg4
, (socklen_t
) arg5
);
5561 case TARGET_NR_syslog
:
5562 if (!(p
= lock_user_string(arg2
)))
5564 ret
= get_errno(sys_syslog((int)arg1
, p
, (int)arg3
));
5565 unlock_user(p
, arg2
, 0);
5568 case TARGET_NR_setitimer
:
5570 struct itimerval value
, ovalue
, *pvalue
;
5574 if (copy_from_user_timeval(&pvalue
->it_interval
, arg2
)
5575 || copy_from_user_timeval(&pvalue
->it_value
,
5576 arg2
+ sizeof(struct target_timeval
)))
5581 ret
= get_errno(setitimer(arg1
, pvalue
, &ovalue
));
5582 if (!is_error(ret
) && arg3
) {
5583 if (copy_to_user_timeval(arg3
,
5584 &ovalue
.it_interval
)
5585 || copy_to_user_timeval(arg3
+ sizeof(struct target_timeval
),
5591 case TARGET_NR_getitimer
:
5593 struct itimerval value
;
5595 ret
= get_errno(getitimer(arg1
, &value
));
5596 if (!is_error(ret
) && arg2
) {
5597 if (copy_to_user_timeval(arg2
,
5599 || copy_to_user_timeval(arg2
+ sizeof(struct target_timeval
),
5605 case TARGET_NR_stat
:
5606 if (!(p
= lock_user_string(arg1
)))
5608 ret
= get_errno(stat(path(p
), &st
));
5609 unlock_user(p
, arg1
, 0);
5611 case TARGET_NR_lstat
:
5612 if (!(p
= lock_user_string(arg1
)))
5614 ret
= get_errno(lstat(path(p
), &st
));
5615 unlock_user(p
, arg1
, 0);
5617 case TARGET_NR_fstat
:
5619 ret
= get_errno(fstat(arg1
, &st
));
5621 if (!is_error(ret
)) {
5622 struct target_stat
*target_st
;
5624 if (!lock_user_struct(VERIFY_WRITE
, target_st
, arg2
, 0))
5626 memset(target_st
, 0, sizeof(*target_st
));
5627 __put_user(st
.st_dev
, &target_st
->st_dev
);
5628 __put_user(st
.st_ino
, &target_st
->st_ino
);
5629 __put_user(st
.st_mode
, &target_st
->st_mode
);
5630 __put_user(st
.st_uid
, &target_st
->st_uid
);
5631 __put_user(st
.st_gid
, &target_st
->st_gid
);
5632 __put_user(st
.st_nlink
, &target_st
->st_nlink
);
5633 __put_user(st
.st_rdev
, &target_st
->st_rdev
);
5634 __put_user(st
.st_size
, &target_st
->st_size
);
5635 __put_user(st
.st_blksize
, &target_st
->st_blksize
);
5636 __put_user(st
.st_blocks
, &target_st
->st_blocks
);
5637 __put_user(st
.st_atime
, &target_st
->target_st_atime
);
5638 __put_user(st
.st_mtime
, &target_st
->target_st_mtime
);
5639 __put_user(st
.st_ctime
, &target_st
->target_st_ctime
);
5640 unlock_user_struct(target_st
, arg2
, 1);
5644 #ifdef TARGET_NR_olduname
5645 case TARGET_NR_olduname
:
5648 #ifdef TARGET_NR_iopl
5649 case TARGET_NR_iopl
:
5652 case TARGET_NR_vhangup
:
5653 ret
= get_errno(vhangup());
5655 #ifdef TARGET_NR_idle
5656 case TARGET_NR_idle
:
5659 #ifdef TARGET_NR_syscall
5660 case TARGET_NR_syscall
:
5661 ret
= do_syscall(cpu_env
,arg1
& 0xffff,arg2
,arg3
,arg4
,arg5
,arg6
,0);
5664 case TARGET_NR_wait4
:
5667 abi_long status_ptr
= arg2
;
5668 struct rusage rusage
, *rusage_ptr
;
5669 abi_ulong target_rusage
= arg4
;
5671 rusage_ptr
= &rusage
;
5674 ret
= get_errno(wait4(arg1
, &status
, arg3
, rusage_ptr
));
5675 if (!is_error(ret
)) {
5677 status
= host_to_target_waitstatus(status
);
5678 if (put_user_s32(status
, status_ptr
))
5682 host_to_target_rusage(target_rusage
, &rusage
);
5686 #ifdef TARGET_NR_swapoff
5687 case TARGET_NR_swapoff
:
5688 if (!(p
= lock_user_string(arg1
)))
5690 ret
= get_errno(swapoff(p
));
5691 unlock_user(p
, arg1
, 0);
5694 case TARGET_NR_sysinfo
:
5696 struct target_sysinfo
*target_value
;
5697 struct sysinfo value
;
5698 ret
= get_errno(sysinfo(&value
));
5699 if (!is_error(ret
) && arg1
)
5701 if (!lock_user_struct(VERIFY_WRITE
, target_value
, arg1
, 0))
5703 __put_user(value
.uptime
, &target_value
->uptime
);
5704 __put_user(value
.loads
[0], &target_value
->loads
[0]);
5705 __put_user(value
.loads
[1], &target_value
->loads
[1]);
5706 __put_user(value
.loads
[2], &target_value
->loads
[2]);
5707 __put_user(value
.totalram
, &target_value
->totalram
);
5708 __put_user(value
.freeram
, &target_value
->freeram
);
5709 __put_user(value
.sharedram
, &target_value
->sharedram
);
5710 __put_user(value
.bufferram
, &target_value
->bufferram
);
5711 __put_user(value
.totalswap
, &target_value
->totalswap
);
5712 __put_user(value
.freeswap
, &target_value
->freeswap
);
5713 __put_user(value
.procs
, &target_value
->procs
);
5714 __put_user(value
.totalhigh
, &target_value
->totalhigh
);
5715 __put_user(value
.freehigh
, &target_value
->freehigh
);
5716 __put_user(value
.mem_unit
, &target_value
->mem_unit
);
5717 unlock_user_struct(target_value
, arg1
, 1);
5721 #ifdef TARGET_NR_ipc
5723 ret
= do_ipc(arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
5726 #ifdef TARGET_NR_semget
5727 case TARGET_NR_semget
:
5728 ret
= get_errno(semget(arg1
, arg2
, arg3
));
5731 #ifdef TARGET_NR_semop
5732 case TARGET_NR_semop
:
5733 ret
= get_errno(do_semop(arg1
, arg2
, arg3
));
5736 #ifdef TARGET_NR_semctl
5737 case TARGET_NR_semctl
:
5738 ret
= do_semctl(arg1
, arg2
, arg3
, (union target_semun
)(abi_ulong
)arg4
);
5741 #ifdef TARGET_NR_msgctl
5742 case TARGET_NR_msgctl
:
5743 ret
= do_msgctl(arg1
, arg2
, arg3
);
5746 #ifdef TARGET_NR_msgget
5747 case TARGET_NR_msgget
:
5748 ret
= get_errno(msgget(arg1
, arg2
));
5751 #ifdef TARGET_NR_msgrcv
5752 case TARGET_NR_msgrcv
:
5753 ret
= do_msgrcv(arg1
, arg2
, arg3
, arg4
, arg5
);
5756 #ifdef TARGET_NR_msgsnd
5757 case TARGET_NR_msgsnd
:
5758 ret
= do_msgsnd(arg1
, arg2
, arg3
, arg4
);
5761 #ifdef TARGET_NR_shmget
5762 case TARGET_NR_shmget
:
5763 ret
= get_errno(shmget(arg1
, arg2
, arg3
));
5766 #ifdef TARGET_NR_shmctl
5767 case TARGET_NR_shmctl
:
5768 ret
= do_shmctl(arg1
, arg2
, arg3
);
5771 #ifdef TARGET_NR_shmat
5772 case TARGET_NR_shmat
:
5773 ret
= do_shmat(arg1
, arg2
, arg3
);
5776 #ifdef TARGET_NR_shmdt
5777 case TARGET_NR_shmdt
:
5778 ret
= do_shmdt(arg1
);
5781 case TARGET_NR_fsync
:
5782 ret
= get_errno(fsync(arg1
));
5784 case TARGET_NR_clone
:
5785 #if defined(TARGET_SH4) || defined(TARGET_ALPHA)
5786 ret
= get_errno(do_fork(cpu_env
, arg1
, arg2
, arg3
, arg5
, arg4
));
5787 #elif defined(TARGET_CRIS)
5788 ret
= get_errno(do_fork(cpu_env
, arg2
, arg1
, arg3
, arg4
, arg5
));
5790 ret
= get_errno(do_fork(cpu_env
, arg1
, arg2
, arg3
, arg4
, arg5
));
5793 #ifdef __NR_exit_group
5794 /* new thread calls */
5795 case TARGET_NR_exit_group
:
5799 gdb_exit(cpu_env
, arg1
);
5800 ret
= get_errno(exit_group(arg1
));
5803 case TARGET_NR_setdomainname
:
5804 if (!(p
= lock_user_string(arg1
)))
5806 ret
= get_errno(setdomainname(p
, arg2
));
5807 unlock_user(p
, arg1
, 0);
5809 case TARGET_NR_uname
:
5810 /* no need to transcode because we use the linux syscall */
5812 struct new_utsname
* buf
;
5814 if (!lock_user_struct(VERIFY_WRITE
, buf
, arg1
, 0))
5816 ret
= get_errno(sys_uname(buf
));
5817 if (!is_error(ret
)) {
5818 /* Overrite the native machine name with whatever is being
5820 strcpy (buf
->machine
, cpu_to_uname_machine(cpu_env
));
5821 /* Allow the user to override the reported release. */
5822 if (qemu_uname_release
&& *qemu_uname_release
)
5823 strcpy (buf
->release
, qemu_uname_release
);
5825 unlock_user_struct(buf
, arg1
, 1);
5829 case TARGET_NR_modify_ldt
:
5830 ret
= do_modify_ldt(cpu_env
, arg1
, arg2
, arg3
);
5832 #if !defined(TARGET_X86_64)
5833 case TARGET_NR_vm86old
:
5835 case TARGET_NR_vm86
:
5836 ret
= do_vm86(cpu_env
, arg1
, arg2
);
5840 case TARGET_NR_adjtimex
:
5842 #ifdef TARGET_NR_create_module
5843 case TARGET_NR_create_module
:
5845 case TARGET_NR_init_module
:
5846 case TARGET_NR_delete_module
:
5847 #ifdef TARGET_NR_get_kernel_syms
5848 case TARGET_NR_get_kernel_syms
:
5851 case TARGET_NR_quotactl
:
5853 case TARGET_NR_getpgid
:
5854 ret
= get_errno(getpgid(arg1
));
5856 case TARGET_NR_fchdir
:
5857 ret
= get_errno(fchdir(arg1
));
5859 #ifdef TARGET_NR_bdflush /* not on x86_64 */
5860 case TARGET_NR_bdflush
:
5863 #ifdef TARGET_NR_sysfs
5864 case TARGET_NR_sysfs
:
5867 case TARGET_NR_personality
:
5868 ret
= get_errno(personality(arg1
));
5870 #ifdef TARGET_NR_afs_syscall
5871 case TARGET_NR_afs_syscall
:
5874 #ifdef TARGET_NR__llseek /* Not on alpha */
5875 case TARGET_NR__llseek
:
5877 #if defined (__x86_64__)
5878 ret
= get_errno(lseek(arg1
, ((uint64_t )arg2
<< 32) | arg3
, arg5
));
5879 if (put_user_s64(ret
, arg4
))
5883 ret
= get_errno(_llseek(arg1
, arg2
, arg3
, &res
, arg5
));
5884 if (put_user_s64(res
, arg4
))
5890 case TARGET_NR_getdents
:
5891 #if TARGET_ABI_BITS == 32 && HOST_LONG_BITS == 64
5893 struct target_dirent
*target_dirp
;
5894 struct linux_dirent
*dirp
;
5895 abi_long count
= arg3
;
5897 dirp
= malloc(count
);
5899 ret
= -TARGET_ENOMEM
;
5903 ret
= get_errno(sys_getdents(arg1
, dirp
, count
));
5904 if (!is_error(ret
)) {
5905 struct linux_dirent
*de
;
5906 struct target_dirent
*tde
;
5908 int reclen
, treclen
;
5909 int count1
, tnamelen
;
5913 if (!(target_dirp
= lock_user(VERIFY_WRITE
, arg2
, count
, 0)))
5917 reclen
= de
->d_reclen
;
5918 treclen
= reclen
- (2 * (sizeof(long) - sizeof(abi_long
)));
5919 tde
->d_reclen
= tswap16(treclen
);
5920 tde
->d_ino
= tswapl(de
->d_ino
);
5921 tde
->d_off
= tswapl(de
->d_off
);
5922 tnamelen
= treclen
- (2 * sizeof(abi_long
) + 2);
5925 /* XXX: may not be correct */
5926 pstrcpy(tde
->d_name
, tnamelen
, de
->d_name
);
5927 de
= (struct linux_dirent
*)((char *)de
+ reclen
);
5929 tde
= (struct target_dirent
*)((char *)tde
+ treclen
);
5933 unlock_user(target_dirp
, arg2
, ret
);
5939 struct linux_dirent
*dirp
;
5940 abi_long count
= arg3
;
5942 if (!(dirp
= lock_user(VERIFY_WRITE
, arg2
, count
, 0)))
5944 ret
= get_errno(sys_getdents(arg1
, dirp
, count
));
5945 if (!is_error(ret
)) {
5946 struct linux_dirent
*de
;
5951 reclen
= de
->d_reclen
;
5954 de
->d_reclen
= tswap16(reclen
);
5955 tswapls(&de
->d_ino
);
5956 tswapls(&de
->d_off
);
5957 de
= (struct linux_dirent
*)((char *)de
+ reclen
);
5961 unlock_user(dirp
, arg2
, ret
);
5965 #if defined(TARGET_NR_getdents64) && defined(__NR_getdents64)
5966 case TARGET_NR_getdents64
:
5968 struct linux_dirent64
*dirp
;
5969 abi_long count
= arg3
;
5970 if (!(dirp
= lock_user(VERIFY_WRITE
, arg2
, count
, 0)))
5972 ret
= get_errno(sys_getdents64(arg1
, dirp
, count
));
5973 if (!is_error(ret
)) {
5974 struct linux_dirent64
*de
;
5979 reclen
= de
->d_reclen
;
5982 de
->d_reclen
= tswap16(reclen
);
5983 tswap64s((uint64_t *)&de
->d_ino
);
5984 tswap64s((uint64_t *)&de
->d_off
);
5985 de
= (struct linux_dirent64
*)((char *)de
+ reclen
);
5989 unlock_user(dirp
, arg2
, ret
);
5992 #endif /* TARGET_NR_getdents64 */
5993 #ifdef TARGET_NR__newselect
5994 case TARGET_NR__newselect
:
5995 ret
= do_select(arg1
, arg2
, arg3
, arg4
, arg5
);
5998 #ifdef TARGET_NR_poll
5999 case TARGET_NR_poll
:
6001 struct target_pollfd
*target_pfd
;
6002 unsigned int nfds
= arg2
;
6007 target_pfd
= lock_user(VERIFY_WRITE
, arg1
, sizeof(struct target_pollfd
) * nfds
, 1);
6010 pfd
= alloca(sizeof(struct pollfd
) * nfds
);
6011 for(i
= 0; i
< nfds
; i
++) {
6012 pfd
[i
].fd
= tswap32(target_pfd
[i
].fd
);
6013 pfd
[i
].events
= tswap16(target_pfd
[i
].events
);
6015 ret
= get_errno(poll(pfd
, nfds
, timeout
));
6016 if (!is_error(ret
)) {
6017 for(i
= 0; i
< nfds
; i
++) {
6018 target_pfd
[i
].revents
= tswap16(pfd
[i
].revents
);
6020 ret
+= nfds
* (sizeof(struct target_pollfd
)
6021 - sizeof(struct pollfd
));
6023 unlock_user(target_pfd
, arg1
, ret
);
6027 case TARGET_NR_flock
:
6028 /* NOTE: the flock constant seems to be the same for every
6030 ret
= get_errno(flock(arg1
, arg2
));
6032 case TARGET_NR_readv
:
6037 vec
= alloca(count
* sizeof(struct iovec
));
6038 if (lock_iovec(VERIFY_WRITE
, vec
, arg2
, count
, 0) < 0)
6040 ret
= get_errno(readv(arg1
, vec
, count
));
6041 unlock_iovec(vec
, arg2
, count
, 1);
6044 case TARGET_NR_writev
:
6049 vec
= alloca(count
* sizeof(struct iovec
));
6050 if (lock_iovec(VERIFY_READ
, vec
, arg2
, count
, 1) < 0)
6052 ret
= get_errno(writev(arg1
, vec
, count
));
6053 unlock_iovec(vec
, arg2
, count
, 0);
6056 case TARGET_NR_getsid
:
6057 ret
= get_errno(getsid(arg1
));
6059 #if defined(TARGET_NR_fdatasync) /* Not on alpha (osf_datasync ?) */
6060 case TARGET_NR_fdatasync
:
6061 ret
= get_errno(fdatasync(arg1
));
6064 case TARGET_NR__sysctl
:
6065 /* We don't implement this, but ENOTDIR is always a safe
6067 ret
= -TARGET_ENOTDIR
;
6069 case TARGET_NR_sched_setparam
:
6071 struct sched_param
*target_schp
;
6072 struct sched_param schp
;
6074 if (!lock_user_struct(VERIFY_READ
, target_schp
, arg2
, 1))
6076 schp
.sched_priority
= tswap32(target_schp
->sched_priority
);
6077 unlock_user_struct(target_schp
, arg2
, 0);
6078 ret
= get_errno(sched_setparam(arg1
, &schp
));
6081 case TARGET_NR_sched_getparam
:
6083 struct sched_param
*target_schp
;
6084 struct sched_param schp
;
6085 ret
= get_errno(sched_getparam(arg1
, &schp
));
6086 if (!is_error(ret
)) {
6087 if (!lock_user_struct(VERIFY_WRITE
, target_schp
, arg2
, 0))
6089 target_schp
->sched_priority
= tswap32(schp
.sched_priority
);
6090 unlock_user_struct(target_schp
, arg2
, 1);
6094 case TARGET_NR_sched_setscheduler
:
6096 struct sched_param
*target_schp
;
6097 struct sched_param schp
;
6098 if (!lock_user_struct(VERIFY_READ
, target_schp
, arg3
, 1))
6100 schp
.sched_priority
= tswap32(target_schp
->sched_priority
);
6101 unlock_user_struct(target_schp
, arg3
, 0);
6102 ret
= get_errno(sched_setscheduler(arg1
, arg2
, &schp
));
6105 case TARGET_NR_sched_getscheduler
:
6106 ret
= get_errno(sched_getscheduler(arg1
));
6108 case TARGET_NR_sched_yield
:
6109 ret
= get_errno(sched_yield());
6111 case TARGET_NR_sched_get_priority_max
:
6112 ret
= get_errno(sched_get_priority_max(arg1
));
6114 case TARGET_NR_sched_get_priority_min
:
6115 ret
= get_errno(sched_get_priority_min(arg1
));
6117 case TARGET_NR_sched_rr_get_interval
:
6120 ret
= get_errno(sched_rr_get_interval(arg1
, &ts
));
6121 if (!is_error(ret
)) {
6122 host_to_target_timespec(arg2
, &ts
);
6126 case TARGET_NR_nanosleep
:
6128 struct timespec req
, rem
;
6129 target_to_host_timespec(&req
, arg1
);
6130 ret
= get_errno(nanosleep(&req
, &rem
));
6131 if (is_error(ret
) && arg2
) {
6132 host_to_target_timespec(arg2
, &rem
);
6136 #ifdef TARGET_NR_query_module
6137 case TARGET_NR_query_module
:
6140 #ifdef TARGET_NR_nfsservctl
6141 case TARGET_NR_nfsservctl
:
6144 case TARGET_NR_prctl
:
6147 case PR_GET_PDEATHSIG
:
6150 ret
= get_errno(prctl(arg1
, &deathsig
, arg3
, arg4
, arg5
));
6151 if (!is_error(ret
) && arg2
6152 && put_user_ual(deathsig
, arg2
))
6157 ret
= get_errno(prctl(arg1
, arg2
, arg3
, arg4
, arg5
));
6161 #ifdef TARGET_NR_arch_prctl
6162 case TARGET_NR_arch_prctl
:
6163 #if defined(TARGET_I386) && !defined(TARGET_ABI32)
6164 ret
= do_arch_prctl(cpu_env
, arg1
, arg2
);
6170 #ifdef TARGET_NR_pread
6171 case TARGET_NR_pread
:
6173 if (((CPUARMState
*)cpu_env
)->eabi
)
6176 if (!(p
= lock_user(VERIFY_WRITE
, arg2
, arg3
, 0)))
6178 ret
= get_errno(pread(arg1
, p
, arg3
, arg4
));
6179 unlock_user(p
, arg2
, ret
);
6181 case TARGET_NR_pwrite
:
6183 if (((CPUARMState
*)cpu_env
)->eabi
)
6186 if (!(p
= lock_user(VERIFY_READ
, arg2
, arg3
, 1)))
6188 ret
= get_errno(pwrite(arg1
, p
, arg3
, arg4
));
6189 unlock_user(p
, arg2
, 0);
6192 #ifdef TARGET_NR_pread64
6193 case TARGET_NR_pread64
:
6194 if (!(p
= lock_user(VERIFY_WRITE
, arg2
, arg3
, 0)))
6196 ret
= get_errno(pread64(arg1
, p
, arg3
, target_offset64(arg4
, arg5
)));
6197 unlock_user(p
, arg2
, ret
);
6199 case TARGET_NR_pwrite64
:
6200 if (!(p
= lock_user(VERIFY_READ
, arg2
, arg3
, 1)))
6202 ret
= get_errno(pwrite64(arg1
, p
, arg3
, target_offset64(arg4
, arg5
)));
6203 unlock_user(p
, arg2
, 0);
6206 case TARGET_NR_getcwd
:
6207 if (!(p
= lock_user(VERIFY_WRITE
, arg1
, arg2
, 0)))
6209 ret
= get_errno(sys_getcwd1(p
, arg2
));
6210 unlock_user(p
, arg1
, ret
);
6212 case TARGET_NR_capget
:
6214 case TARGET_NR_capset
:
6216 case TARGET_NR_sigaltstack
:
6217 #if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_MIPS) || \
6218 defined(TARGET_SPARC) || defined(TARGET_PPC) || defined(TARGET_ALPHA) || \
6219 defined(TARGET_M68K)
6220 ret
= do_sigaltstack(arg1
, arg2
, get_sp_from_cpustate((CPUState
*)cpu_env
));
6225 case TARGET_NR_sendfile
:
6227 #ifdef TARGET_NR_getpmsg
6228 case TARGET_NR_getpmsg
:
6231 #ifdef TARGET_NR_putpmsg
6232 case TARGET_NR_putpmsg
:
6235 #ifdef TARGET_NR_vfork
6236 case TARGET_NR_vfork
:
6237 ret
= get_errno(do_fork(cpu_env
, CLONE_VFORK
| CLONE_VM
| SIGCHLD
,
6241 #ifdef TARGET_NR_ugetrlimit
6242 case TARGET_NR_ugetrlimit
:
6245 ret
= get_errno(getrlimit(arg1
, &rlim
));
6246 if (!is_error(ret
)) {
6247 struct target_rlimit
*target_rlim
;
6248 if (!lock_user_struct(VERIFY_WRITE
, target_rlim
, arg2
, 0))
6250 target_rlim
->rlim_cur
= host_to_target_rlim(rlim
.rlim_cur
);
6251 target_rlim
->rlim_max
= host_to_target_rlim(rlim
.rlim_max
);
6252 unlock_user_struct(target_rlim
, arg2
, 1);
6257 #ifdef TARGET_NR_truncate64
6258 case TARGET_NR_truncate64
:
6259 if (!(p
= lock_user_string(arg1
)))
6261 ret
= target_truncate64(cpu_env
, p
, arg2
, arg3
, arg4
);
6262 unlock_user(p
, arg1
, 0);
6265 #ifdef TARGET_NR_ftruncate64
6266 case TARGET_NR_ftruncate64
:
6267 ret
= target_ftruncate64(cpu_env
, arg1
, arg2
, arg3
, arg4
);
6270 #ifdef TARGET_NR_stat64
6271 case TARGET_NR_stat64
:
6272 if (!(p
= lock_user_string(arg1
)))
6274 ret
= get_errno(stat(path(p
), &st
));
6275 unlock_user(p
, arg1
, 0);
6277 ret
= host_to_target_stat64(cpu_env
, arg2
, &st
);
6280 #ifdef TARGET_NR_lstat64
6281 case TARGET_NR_lstat64
:
6282 if (!(p
= lock_user_string(arg1
)))
6284 ret
= get_errno(lstat(path(p
), &st
));
6285 unlock_user(p
, arg1
, 0);
6287 ret
= host_to_target_stat64(cpu_env
, arg2
, &st
);
6290 #ifdef TARGET_NR_fstat64
6291 case TARGET_NR_fstat64
:
6292 ret
= get_errno(fstat(arg1
, &st
));
6294 ret
= host_to_target_stat64(cpu_env
, arg2
, &st
);
6297 #if (defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat)) && \
6298 (defined(__NR_fstatat64) || defined(__NR_newfstatat))
6299 #ifdef TARGET_NR_fstatat64
6300 case TARGET_NR_fstatat64
:
6302 #ifdef TARGET_NR_newfstatat
6303 case TARGET_NR_newfstatat
:
6305 if (!(p
= lock_user_string(arg2
)))
6307 #ifdef __NR_fstatat64
6308 ret
= get_errno(sys_fstatat64(arg1
, path(p
), &st
, arg4
));
6310 ret
= get_errno(sys_newfstatat(arg1
, path(p
), &st
, arg4
));
6313 ret
= host_to_target_stat64(cpu_env
, arg3
, &st
);
6317 case TARGET_NR_lchown
:
6318 if (!(p
= lock_user_string(arg1
)))
6320 ret
= get_errno(lchown(p
, low2highuid(arg2
), low2highgid(arg3
)));
6321 unlock_user(p
, arg1
, 0);
6323 case TARGET_NR_getuid
:
6324 ret
= get_errno(high2lowuid(getuid()));
6326 case TARGET_NR_getgid
:
6327 ret
= get_errno(high2lowgid(getgid()));
6329 case TARGET_NR_geteuid
:
6330 ret
= get_errno(high2lowuid(geteuid()));
6332 case TARGET_NR_getegid
:
6333 ret
= get_errno(high2lowgid(getegid()));
6335 case TARGET_NR_setreuid
:
6336 ret
= get_errno(setreuid(low2highuid(arg1
), low2highuid(arg2
)));
6338 case TARGET_NR_setregid
:
6339 ret
= get_errno(setregid(low2highgid(arg1
), low2highgid(arg2
)));
6341 case TARGET_NR_getgroups
:
6343 int gidsetsize
= arg1
;
6344 uint16_t *target_grouplist
;
6348 grouplist
= alloca(gidsetsize
* sizeof(gid_t
));
6349 ret
= get_errno(getgroups(gidsetsize
, grouplist
));
6350 if (gidsetsize
== 0)
6352 if (!is_error(ret
)) {
6353 target_grouplist
= lock_user(VERIFY_WRITE
, arg2
, gidsetsize
* 2, 0);
6354 if (!target_grouplist
)
6356 for(i
= 0;i
< ret
; i
++)
6357 target_grouplist
[i
] = tswap16(grouplist
[i
]);
6358 unlock_user(target_grouplist
, arg2
, gidsetsize
* 2);
6362 case TARGET_NR_setgroups
:
6364 int gidsetsize
= arg1
;
6365 uint16_t *target_grouplist
;
6369 grouplist
= alloca(gidsetsize
* sizeof(gid_t
));
6370 target_grouplist
= lock_user(VERIFY_READ
, arg2
, gidsetsize
* 2, 1);
6371 if (!target_grouplist
) {
6372 ret
= -TARGET_EFAULT
;
6375 for(i
= 0;i
< gidsetsize
; i
++)
6376 grouplist
[i
] = tswap16(target_grouplist
[i
]);
6377 unlock_user(target_grouplist
, arg2
, 0);
6378 ret
= get_errno(setgroups(gidsetsize
, grouplist
));
6381 case TARGET_NR_fchown
:
6382 ret
= get_errno(fchown(arg1
, low2highuid(arg2
), low2highgid(arg3
)));
6384 #if defined(TARGET_NR_fchownat) && defined(__NR_fchownat)
6385 case TARGET_NR_fchownat
:
6386 if (!(p
= lock_user_string(arg2
)))
6388 ret
= get_errno(sys_fchownat(arg1
, p
, low2highuid(arg3
), low2highgid(arg4
), arg5
));
6389 unlock_user(p
, arg2
, 0);
6392 #ifdef TARGET_NR_setresuid
6393 case TARGET_NR_setresuid
:
6394 ret
= get_errno(setresuid(low2highuid(arg1
),
6396 low2highuid(arg3
)));
6399 #ifdef TARGET_NR_getresuid
6400 case TARGET_NR_getresuid
:
6402 uid_t ruid
, euid
, suid
;
6403 ret
= get_errno(getresuid(&ruid
, &euid
, &suid
));
6404 if (!is_error(ret
)) {
6405 if (put_user_u16(high2lowuid(ruid
), arg1
)
6406 || put_user_u16(high2lowuid(euid
), arg2
)
6407 || put_user_u16(high2lowuid(suid
), arg3
))
6413 #ifdef TARGET_NR_getresgid
6414 case TARGET_NR_setresgid
:
6415 ret
= get_errno(setresgid(low2highgid(arg1
),
6417 low2highgid(arg3
)));
6420 #ifdef TARGET_NR_getresgid
6421 case TARGET_NR_getresgid
:
6423 gid_t rgid
, egid
, sgid
;
6424 ret
= get_errno(getresgid(&rgid
, &egid
, &sgid
));
6425 if (!is_error(ret
)) {
6426 if (put_user_u16(high2lowgid(rgid
), arg1
)
6427 || put_user_u16(high2lowgid(egid
), arg2
)
6428 || put_user_u16(high2lowgid(sgid
), arg3
))
6434 case TARGET_NR_chown
:
6435 if (!(p
= lock_user_string(arg1
)))
6437 ret
= get_errno(chown(p
, low2highuid(arg2
), low2highgid(arg3
)));
6438 unlock_user(p
, arg1
, 0);
6440 case TARGET_NR_setuid
:
6441 ret
= get_errno(setuid(low2highuid(arg1
)));
6443 case TARGET_NR_setgid
:
6444 ret
= get_errno(setgid(low2highgid(arg1
)));
6446 case TARGET_NR_setfsuid
:
6447 ret
= get_errno(setfsuid(arg1
));
6449 case TARGET_NR_setfsgid
:
6450 ret
= get_errno(setfsgid(arg1
));
6452 #endif /* USE_UID16 */
6454 #ifdef TARGET_NR_lchown32
6455 case TARGET_NR_lchown32
:
6456 if (!(p
= lock_user_string(arg1
)))
6458 ret
= get_errno(lchown(p
, arg2
, arg3
));
6459 unlock_user(p
, arg1
, 0);
6462 #ifdef TARGET_NR_getuid32
6463 case TARGET_NR_getuid32
:
6464 ret
= get_errno(getuid());
6468 #if defined(TARGET_NR_getxuid) && defined(TARGET_ALPHA)
6469 /* Alpha specific */
6470 case TARGET_NR_getxuid
:
6474 ((CPUAlphaState
*)cpu_env
)->ir
[IR_A4
]=euid
;
6476 ret
= get_errno(getuid());
6479 #if defined(TARGET_NR_getxgid) && defined(TARGET_ALPHA)
6480 /* Alpha specific */
6481 case TARGET_NR_getxgid
:
6485 ((CPUAlphaState
*)cpu_env
)->ir
[IR_A4
]=egid
;
6487 ret
= get_errno(getgid());
6490 #if defined(TARGET_NR_osf_getsysinfo) && defined(TARGET_ALPHA)
6491 /* Alpha specific */
6492 case TARGET_NR_osf_getsysinfo
:
6493 ret
= -TARGET_EOPNOTSUPP
;
6495 case TARGET_GSI_IEEE_FP_CONTROL
:
6497 uint64_t swcr
, fpcr
= cpu_alpha_load_fpcr (cpu_env
);
6499 /* Copied from linux ieee_fpcr_to_swcr. */
6500 swcr
= (fpcr
>> 35) & SWCR_STATUS_MASK
;
6501 swcr
|= (fpcr
>> 36) & SWCR_MAP_DMZ
;
6502 swcr
|= (~fpcr
>> 48) & (SWCR_TRAP_ENABLE_INV
6503 | SWCR_TRAP_ENABLE_DZE
6504 | SWCR_TRAP_ENABLE_OVF
);
6505 swcr
|= (~fpcr
>> 57) & (SWCR_TRAP_ENABLE_UNF
6506 | SWCR_TRAP_ENABLE_INE
);
6507 swcr
|= (fpcr
>> 47) & SWCR_MAP_UMZ
;
6508 swcr
|= (~fpcr
>> 41) & SWCR_TRAP_ENABLE_DNO
;
6510 if (put_user_u64 (swcr
, arg2
))
6516 /* case GSI_IEEE_STATE_AT_SIGNAL:
6517 -- Not implemented in linux kernel.
6519 -- Retrieves current unaligned access state; not much used.
6521 -- Retrieves implver information; surely not used.
6523 -- Grabs a copy of the HWRPB; surely not used.
6528 #if defined(TARGET_NR_osf_setsysinfo) && defined(TARGET_ALPHA)
6529 /* Alpha specific */
6530 case TARGET_NR_osf_setsysinfo
:
6531 ret
= -TARGET_EOPNOTSUPP
;
6533 case TARGET_SSI_IEEE_FP_CONTROL
:
6534 case TARGET_SSI_IEEE_RAISE_EXCEPTION
:
6536 uint64_t swcr
, fpcr
, orig_fpcr
;
6538 if (get_user_u64 (swcr
, arg2
))
6540 orig_fpcr
= cpu_alpha_load_fpcr (cpu_env
);
6541 fpcr
= orig_fpcr
& FPCR_DYN_MASK
;
6543 /* Copied from linux ieee_swcr_to_fpcr. */
6544 fpcr
|= (swcr
& SWCR_STATUS_MASK
) << 35;
6545 fpcr
|= (swcr
& SWCR_MAP_DMZ
) << 36;
6546 fpcr
|= (~swcr
& (SWCR_TRAP_ENABLE_INV
6547 | SWCR_TRAP_ENABLE_DZE
6548 | SWCR_TRAP_ENABLE_OVF
)) << 48;
6549 fpcr
|= (~swcr
& (SWCR_TRAP_ENABLE_UNF
6550 | SWCR_TRAP_ENABLE_INE
)) << 57;
6551 fpcr
|= (swcr
& SWCR_MAP_UMZ
? FPCR_UNDZ
| FPCR_UNFD
: 0);
6552 fpcr
|= (~swcr
& SWCR_TRAP_ENABLE_DNO
) << 41;
6554 cpu_alpha_store_fpcr (cpu_env
, fpcr
);
6557 if (arg1
== TARGET_SSI_IEEE_RAISE_EXCEPTION
) {
6558 /* Old exceptions are not signaled. */
6559 fpcr
&= ~(orig_fpcr
& FPCR_STATUS_MASK
);
6561 /* If any exceptions set by this call, and are unmasked,
6568 /* case SSI_NVPAIRS:
6569 -- Used with SSIN_UACPROC to enable unaligned accesses.
6570 case SSI_IEEE_STATE_AT_SIGNAL:
6571 case SSI_IEEE_IGNORE_STATE_AT_SIGNAL:
6572 -- Not implemented in linux kernel
6577 #ifdef TARGET_NR_osf_sigprocmask
6578 /* Alpha specific. */
6579 case TARGET_NR_osf_sigprocmask
:
6583 sigset_t set
, oldset
;
6586 case TARGET_SIG_BLOCK
:
6589 case TARGET_SIG_UNBLOCK
:
6592 case TARGET_SIG_SETMASK
:
6596 ret
= -TARGET_EINVAL
;
6600 target_to_host_old_sigset(&set
, &mask
);
6601 sigprocmask(arg1
, &set
, &oldset
);
6602 host_to_target_old_sigset(&mask
, &oldset
);
6608 #ifdef TARGET_NR_getgid32
6609 case TARGET_NR_getgid32
:
6610 ret
= get_errno(getgid());
6613 #ifdef TARGET_NR_geteuid32
6614 case TARGET_NR_geteuid32
:
6615 ret
= get_errno(geteuid());
6618 #ifdef TARGET_NR_getegid32
6619 case TARGET_NR_getegid32
:
6620 ret
= get_errno(getegid());
6623 #ifdef TARGET_NR_setreuid32
6624 case TARGET_NR_setreuid32
:
6625 ret
= get_errno(setreuid(arg1
, arg2
));
6628 #ifdef TARGET_NR_setregid32
6629 case TARGET_NR_setregid32
:
6630 ret
= get_errno(setregid(arg1
, arg2
));
6633 #ifdef TARGET_NR_getgroups32
6634 case TARGET_NR_getgroups32
:
6636 int gidsetsize
= arg1
;
6637 uint32_t *target_grouplist
;
6641 grouplist
= alloca(gidsetsize
* sizeof(gid_t
));
6642 ret
= get_errno(getgroups(gidsetsize
, grouplist
));
6643 if (gidsetsize
== 0)
6645 if (!is_error(ret
)) {
6646 target_grouplist
= lock_user(VERIFY_WRITE
, arg2
, gidsetsize
* 4, 0);
6647 if (!target_grouplist
) {
6648 ret
= -TARGET_EFAULT
;
6651 for(i
= 0;i
< ret
; i
++)
6652 target_grouplist
[i
] = tswap32(grouplist
[i
]);
6653 unlock_user(target_grouplist
, arg2
, gidsetsize
* 4);
6658 #ifdef TARGET_NR_setgroups32
6659 case TARGET_NR_setgroups32
:
6661 int gidsetsize
= arg1
;
6662 uint32_t *target_grouplist
;
6666 grouplist
= alloca(gidsetsize
* sizeof(gid_t
));
6667 target_grouplist
= lock_user(VERIFY_READ
, arg2
, gidsetsize
* 4, 1);
6668 if (!target_grouplist
) {
6669 ret
= -TARGET_EFAULT
;
6672 for(i
= 0;i
< gidsetsize
; i
++)
6673 grouplist
[i
] = tswap32(target_grouplist
[i
]);
6674 unlock_user(target_grouplist
, arg2
, 0);
6675 ret
= get_errno(setgroups(gidsetsize
, grouplist
));
6679 #ifdef TARGET_NR_fchown32
6680 case TARGET_NR_fchown32
:
6681 ret
= get_errno(fchown(arg1
, arg2
, arg3
));
6684 #ifdef TARGET_NR_setresuid32
6685 case TARGET_NR_setresuid32
:
6686 ret
= get_errno(setresuid(arg1
, arg2
, arg3
));
6689 #ifdef TARGET_NR_getresuid32
6690 case TARGET_NR_getresuid32
:
6692 uid_t ruid
, euid
, suid
;
6693 ret
= get_errno(getresuid(&ruid
, &euid
, &suid
));
6694 if (!is_error(ret
)) {
6695 if (put_user_u32(ruid
, arg1
)
6696 || put_user_u32(euid
, arg2
)
6697 || put_user_u32(suid
, arg3
))
6703 #ifdef TARGET_NR_setresgid32
6704 case TARGET_NR_setresgid32
:
6705 ret
= get_errno(setresgid(arg1
, arg2
, arg3
));
6708 #ifdef TARGET_NR_getresgid32
6709 case TARGET_NR_getresgid32
:
6711 gid_t rgid
, egid
, sgid
;
6712 ret
= get_errno(getresgid(&rgid
, &egid
, &sgid
));
6713 if (!is_error(ret
)) {
6714 if (put_user_u32(rgid
, arg1
)
6715 || put_user_u32(egid
, arg2
)
6716 || put_user_u32(sgid
, arg3
))
6722 #ifdef TARGET_NR_chown32
6723 case TARGET_NR_chown32
:
6724 if (!(p
= lock_user_string(arg1
)))
6726 ret
= get_errno(chown(p
, arg2
, arg3
));
6727 unlock_user(p
, arg1
, 0);
6730 #ifdef TARGET_NR_setuid32
6731 case TARGET_NR_setuid32
:
6732 ret
= get_errno(setuid(arg1
));
6735 #ifdef TARGET_NR_setgid32
6736 case TARGET_NR_setgid32
:
6737 ret
= get_errno(setgid(arg1
));
6740 #ifdef TARGET_NR_setfsuid32
6741 case TARGET_NR_setfsuid32
:
6742 ret
= get_errno(setfsuid(arg1
));
6745 #ifdef TARGET_NR_setfsgid32
6746 case TARGET_NR_setfsgid32
:
6747 ret
= get_errno(setfsgid(arg1
));
6751 case TARGET_NR_pivot_root
:
6753 #ifdef TARGET_NR_mincore
6754 case TARGET_NR_mincore
:
6757 ret
= -TARGET_EFAULT
;
6758 if (!(a
= lock_user(VERIFY_READ
, arg1
,arg2
, 0)))
6760 if (!(p
= lock_user_string(arg3
)))
6762 ret
= get_errno(mincore(a
, arg2
, p
));
6763 unlock_user(p
, arg3
, ret
);
6765 unlock_user(a
, arg1
, 0);
6769 #ifdef TARGET_NR_arm_fadvise64_64
6770 case TARGET_NR_arm_fadvise64_64
:
6773 * arm_fadvise64_64 looks like fadvise64_64 but
6774 * with different argument order
6782 #if defined(TARGET_NR_fadvise64_64) || defined(TARGET_NR_arm_fadvise64_64) || defined(TARGET_NR_fadvise64)
6783 #ifdef TARGET_NR_fadvise64_64
6784 case TARGET_NR_fadvise64_64
:
6786 #ifdef TARGET_NR_fadvise64
6787 case TARGET_NR_fadvise64
:
6791 case 4: arg4
= POSIX_FADV_NOREUSE
+ 1; break; /* make sure it's an invalid value */
6792 case 5: arg4
= POSIX_FADV_NOREUSE
+ 2; break; /* ditto */
6793 case 6: arg4
= POSIX_FADV_DONTNEED
; break;
6794 case 7: arg4
= POSIX_FADV_NOREUSE
; break;
6798 ret
= -posix_fadvise(arg1
, arg2
, arg3
, arg4
);
6801 #ifdef TARGET_NR_madvise
6802 case TARGET_NR_madvise
:
6803 /* A straight passthrough may not be safe because qemu sometimes
6804 turns private flie-backed mappings into anonymous mappings.
6805 This will break MADV_DONTNEED.
6806 This is a hint, so ignoring and returning success is ok. */
6810 #if TARGET_ABI_BITS == 32
6811 case TARGET_NR_fcntl64
:
6815 struct target_flock64
*target_fl
;
6817 struct target_eabi_flock64
*target_efl
;
6820 cmd
= target_to_host_fcntl_cmd(arg2
);
6821 if (cmd
== -TARGET_EINVAL
)
6825 case TARGET_F_GETLK64
:
6827 if (((CPUARMState
*)cpu_env
)->eabi
) {
6828 if (!lock_user_struct(VERIFY_READ
, target_efl
, arg3
, 1))
6830 fl
.l_type
= tswap16(target_efl
->l_type
);
6831 fl
.l_whence
= tswap16(target_efl
->l_whence
);
6832 fl
.l_start
= tswap64(target_efl
->l_start
);
6833 fl
.l_len
= tswap64(target_efl
->l_len
);
6834 fl
.l_pid
= tswap32(target_efl
->l_pid
);
6835 unlock_user_struct(target_efl
, arg3
, 0);
6839 if (!lock_user_struct(VERIFY_READ
, target_fl
, arg3
, 1))
6841 fl
.l_type
= tswap16(target_fl
->l_type
);
6842 fl
.l_whence
= tswap16(target_fl
->l_whence
);
6843 fl
.l_start
= tswap64(target_fl
->l_start
);
6844 fl
.l_len
= tswap64(target_fl
->l_len
);
6845 fl
.l_pid
= tswap32(target_fl
->l_pid
);
6846 unlock_user_struct(target_fl
, arg3
, 0);
6848 ret
= get_errno(fcntl(arg1
, cmd
, &fl
));
6851 if (((CPUARMState
*)cpu_env
)->eabi
) {
6852 if (!lock_user_struct(VERIFY_WRITE
, target_efl
, arg3
, 0))
6854 target_efl
->l_type
= tswap16(fl
.l_type
);
6855 target_efl
->l_whence
= tswap16(fl
.l_whence
);
6856 target_efl
->l_start
= tswap64(fl
.l_start
);
6857 target_efl
->l_len
= tswap64(fl
.l_len
);
6858 target_efl
->l_pid
= tswap32(fl
.l_pid
);
6859 unlock_user_struct(target_efl
, arg3
, 1);
6863 if (!lock_user_struct(VERIFY_WRITE
, target_fl
, arg3
, 0))
6865 target_fl
->l_type
= tswap16(fl
.l_type
);
6866 target_fl
->l_whence
= tswap16(fl
.l_whence
);
6867 target_fl
->l_start
= tswap64(fl
.l_start
);
6868 target_fl
->l_len
= tswap64(fl
.l_len
);
6869 target_fl
->l_pid
= tswap32(fl
.l_pid
);
6870 unlock_user_struct(target_fl
, arg3
, 1);
6875 case TARGET_F_SETLK64
:
6876 case TARGET_F_SETLKW64
:
6878 if (((CPUARMState
*)cpu_env
)->eabi
) {
6879 if (!lock_user_struct(VERIFY_READ
, target_efl
, arg3
, 1))
6881 fl
.l_type
= tswap16(target_efl
->l_type
);
6882 fl
.l_whence
= tswap16(target_efl
->l_whence
);
6883 fl
.l_start
= tswap64(target_efl
->l_start
);
6884 fl
.l_len
= tswap64(target_efl
->l_len
);
6885 fl
.l_pid
= tswap32(target_efl
->l_pid
);
6886 unlock_user_struct(target_efl
, arg3
, 0);
6890 if (!lock_user_struct(VERIFY_READ
, target_fl
, arg3
, 1))
6892 fl
.l_type
= tswap16(target_fl
->l_type
);
6893 fl
.l_whence
= tswap16(target_fl
->l_whence
);
6894 fl
.l_start
= tswap64(target_fl
->l_start
);
6895 fl
.l_len
= tswap64(target_fl
->l_len
);
6896 fl
.l_pid
= tswap32(target_fl
->l_pid
);
6897 unlock_user_struct(target_fl
, arg3
, 0);
6899 ret
= get_errno(fcntl(arg1
, cmd
, &fl
));
6902 ret
= do_fcntl(arg1
, arg2
, arg3
);
6908 #ifdef TARGET_NR_cacheflush
6909 case TARGET_NR_cacheflush
:
6910 /* self-modifying code is handled automatically, so nothing needed */
6914 #ifdef TARGET_NR_security
6915 case TARGET_NR_security
:
6918 #ifdef TARGET_NR_getpagesize
6919 case TARGET_NR_getpagesize
:
6920 ret
= TARGET_PAGE_SIZE
;
6923 case TARGET_NR_gettid
:
6924 ret
= get_errno(gettid());
6926 #ifdef TARGET_NR_readahead
6927 case TARGET_NR_readahead
:
6928 #if TARGET_ABI_BITS == 32
6930 if (((CPUARMState
*)cpu_env
)->eabi
)
6937 ret
= get_errno(readahead(arg1
, ((off64_t
)arg3
<< 32) | arg2
, arg4
));
6939 ret
= get_errno(readahead(arg1
, arg2
, arg3
));
6943 #ifdef TARGET_NR_setxattr
6944 case TARGET_NR_setxattr
:
6945 case TARGET_NR_lsetxattr
:
6946 case TARGET_NR_fsetxattr
:
6947 case TARGET_NR_getxattr
:
6948 case TARGET_NR_lgetxattr
:
6949 case TARGET_NR_fgetxattr
:
6950 case TARGET_NR_listxattr
:
6951 case TARGET_NR_llistxattr
:
6952 case TARGET_NR_flistxattr
:
6953 case TARGET_NR_removexattr
:
6954 case TARGET_NR_lremovexattr
:
6955 case TARGET_NR_fremovexattr
:
6956 ret
= -TARGET_EOPNOTSUPP
;
6959 #ifdef TARGET_NR_set_thread_area
6960 case TARGET_NR_set_thread_area
:
6961 #if defined(TARGET_MIPS)
6962 ((CPUMIPSState
*) cpu_env
)->tls_value
= arg1
;
6965 #elif defined(TARGET_CRIS)
6967 ret
= -TARGET_EINVAL
;
6969 ((CPUCRISState
*) cpu_env
)->pregs
[PR_PID
] = arg1
;
6973 #elif defined(TARGET_I386) && defined(TARGET_ABI32)
6974 ret
= do_set_thread_area(cpu_env
, arg1
);
6977 goto unimplemented_nowarn
;
6980 #ifdef TARGET_NR_get_thread_area
6981 case TARGET_NR_get_thread_area
:
6982 #if defined(TARGET_I386) && defined(TARGET_ABI32)
6983 ret
= do_get_thread_area(cpu_env
, arg1
);
6985 goto unimplemented_nowarn
;
6988 #ifdef TARGET_NR_getdomainname
6989 case TARGET_NR_getdomainname
:
6990 goto unimplemented_nowarn
;
6993 #ifdef TARGET_NR_clock_gettime
6994 case TARGET_NR_clock_gettime
:
6997 ret
= get_errno(clock_gettime(arg1
, &ts
));
6998 if (!is_error(ret
)) {
6999 host_to_target_timespec(arg2
, &ts
);
7004 #ifdef TARGET_NR_clock_getres
7005 case TARGET_NR_clock_getres
:
7008 ret
= get_errno(clock_getres(arg1
, &ts
));
7009 if (!is_error(ret
)) {
7010 host_to_target_timespec(arg2
, &ts
);
7015 #ifdef TARGET_NR_clock_nanosleep
7016 case TARGET_NR_clock_nanosleep
:
7019 target_to_host_timespec(&ts
, arg3
);
7020 ret
= get_errno(clock_nanosleep(arg1
, arg2
, &ts
, arg4
? &ts
: NULL
));
7022 host_to_target_timespec(arg4
, &ts
);
7027 #if defined(TARGET_NR_set_tid_address) && defined(__NR_set_tid_address)
7028 case TARGET_NR_set_tid_address
:
7029 ret
= get_errno(set_tid_address((int *)g2h(arg1
)));
7033 #if defined(TARGET_NR_tkill) && defined(__NR_tkill)
7034 case TARGET_NR_tkill
:
7035 ret
= get_errno(sys_tkill((int)arg1
, target_to_host_signal(arg2
)));
7039 #if defined(TARGET_NR_tgkill) && defined(__NR_tgkill)
7040 case TARGET_NR_tgkill
:
7041 ret
= get_errno(sys_tgkill((int)arg1
, (int)arg2
,
7042 target_to_host_signal(arg3
)));
7046 #ifdef TARGET_NR_set_robust_list
7047 case TARGET_NR_set_robust_list
:
7048 goto unimplemented_nowarn
;
7051 #if defined(TARGET_NR_utimensat) && defined(__NR_utimensat)
7052 case TARGET_NR_utimensat
:
7054 struct timespec
*tsp
, ts
[2];
7058 target_to_host_timespec(ts
, arg3
);
7059 target_to_host_timespec(ts
+1, arg3
+sizeof(struct target_timespec
));
7063 ret
= get_errno(sys_utimensat(arg1
, NULL
, tsp
, arg4
));
7065 if (!(p
= lock_user_string(arg2
))) {
7066 ret
= -TARGET_EFAULT
;
7069 ret
= get_errno(sys_utimensat(arg1
, path(p
), tsp
, arg4
));
7070 unlock_user(p
, arg2
, 0);
7075 #if defined(CONFIG_USE_NPTL)
7076 case TARGET_NR_futex
:
7077 ret
= do_futex(arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
7080 #if defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init)
7081 case TARGET_NR_inotify_init
:
7082 ret
= get_errno(sys_inotify_init());
7085 #ifdef CONFIG_INOTIFY1
7086 #if defined(TARGET_NR_inotify_init1) && defined(__NR_inotify_init1)
7087 case TARGET_NR_inotify_init1
:
7088 ret
= get_errno(sys_inotify_init1(arg1
));
7092 #if defined(TARGET_NR_inotify_add_watch) && defined(__NR_inotify_add_watch)
7093 case TARGET_NR_inotify_add_watch
:
7094 p
= lock_user_string(arg2
);
7095 ret
= get_errno(sys_inotify_add_watch(arg1
, path(p
), arg3
));
7096 unlock_user(p
, arg2
, 0);
7099 #if defined(TARGET_NR_inotify_rm_watch) && defined(__NR_inotify_rm_watch)
7100 case TARGET_NR_inotify_rm_watch
:
7101 ret
= get_errno(sys_inotify_rm_watch(arg1
, arg2
));
7105 #if defined(TARGET_NR_mq_open) && defined(__NR_mq_open)
7106 case TARGET_NR_mq_open
:
7108 struct mq_attr posix_mq_attr
;
7110 p
= lock_user_string(arg1
- 1);
7112 copy_from_user_mq_attr (&posix_mq_attr
, arg4
);
7113 ret
= get_errno(mq_open(p
, arg2
, arg3
, &posix_mq_attr
));
7114 unlock_user (p
, arg1
, 0);
7118 case TARGET_NR_mq_unlink
:
7119 p
= lock_user_string(arg1
- 1);
7120 ret
= get_errno(mq_unlink(p
));
7121 unlock_user (p
, arg1
, 0);
7124 case TARGET_NR_mq_timedsend
:
7128 p
= lock_user (VERIFY_READ
, arg2
, arg3
, 1);
7130 target_to_host_timespec(&ts
, arg5
);
7131 ret
= get_errno(mq_timedsend(arg1
, p
, arg3
, arg4
, &ts
));
7132 host_to_target_timespec(arg5
, &ts
);
7135 ret
= get_errno(mq_send(arg1
, p
, arg3
, arg4
));
7136 unlock_user (p
, arg2
, arg3
);
7140 case TARGET_NR_mq_timedreceive
:
7145 p
= lock_user (VERIFY_READ
, arg2
, arg3
, 1);
7147 target_to_host_timespec(&ts
, arg5
);
7148 ret
= get_errno(mq_timedreceive(arg1
, p
, arg3
, &prio
, &ts
));
7149 host_to_target_timespec(arg5
, &ts
);
7152 ret
= get_errno(mq_receive(arg1
, p
, arg3
, &prio
));
7153 unlock_user (p
, arg2
, arg3
);
7155 put_user_u32(prio
, arg4
);
7159 /* Not implemented for now... */
7160 /* case TARGET_NR_mq_notify: */
7163 case TARGET_NR_mq_getsetattr
:
7165 struct mq_attr posix_mq_attr_in
, posix_mq_attr_out
;
7168 ret
= mq_getattr(arg1
, &posix_mq_attr_out
);
7169 copy_to_user_mq_attr(arg3
, &posix_mq_attr_out
);
7172 copy_from_user_mq_attr(&posix_mq_attr_in
, arg2
);
7173 ret
|= mq_setattr(arg1
, &posix_mq_attr_in
, &posix_mq_attr_out
);
7180 #ifdef CONFIG_SPLICE
7181 #ifdef TARGET_NR_tee
7184 ret
= get_errno(tee(arg1
,arg2
,arg3
,arg4
));
7188 #ifdef TARGET_NR_splice
7189 case TARGET_NR_splice
:
7191 loff_t loff_in
, loff_out
;
7192 loff_t
*ploff_in
= NULL
, *ploff_out
= NULL
;
7194 get_user_u64(loff_in
, arg2
);
7195 ploff_in
= &loff_in
;
7198 get_user_u64(loff_out
, arg2
);
7199 ploff_out
= &loff_out
;
7201 ret
= get_errno(splice(arg1
, ploff_in
, arg3
, ploff_out
, arg5
, arg6
));
7205 #ifdef TARGET_NR_vmsplice
7206 case TARGET_NR_vmsplice
:
7211 vec
= alloca(count
* sizeof(struct iovec
));
7212 if (lock_iovec(VERIFY_READ
, vec
, arg2
, count
, 1) < 0)
7214 ret
= get_errno(vmsplice(arg1
, vec
, count
, arg4
));
7215 unlock_iovec(vec
, arg2
, count
, 0);
7219 #endif /* CONFIG_SPLICE */
7220 #ifdef CONFIG_EVENTFD
7221 #if defined(TARGET_NR_eventfd)
7222 case TARGET_NR_eventfd
:
7223 ret
= get_errno(eventfd(arg1
, 0));
7226 #if defined(TARGET_NR_eventfd2)
7227 case TARGET_NR_eventfd2
:
7228 ret
= get_errno(eventfd(arg1
, arg2
));
7231 #endif /* CONFIG_EVENTFD */
7232 #if defined(CONFIG_FALLOCATE) && defined(TARGET_NR_fallocate)
7233 case TARGET_NR_fallocate
:
7234 ret
= get_errno(fallocate(arg1
, arg2
, arg3
, arg4
));
7239 gemu_log("qemu: Unsupported syscall: %d\n", num
);
7240 #if defined(TARGET_NR_setxattr) || defined(TARGET_NR_get_thread_area) || defined(TARGET_NR_getdomainname) || defined(TARGET_NR_set_robust_list)
7241 unimplemented_nowarn
:
7243 ret
= -TARGET_ENOSYS
;
7248 gemu_log(" = " TARGET_ABI_FMT_ld
"\n", ret
);
7251 print_syscall_ret(num
, ret
);
7254 ret
= -TARGET_EFAULT
;