4 * Copyright (c) 2003 Fabrice Bellard
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
19 #define _ATFILE_SOURCE
31 #include <sys/types.h>
37 #include <sys/mount.h>
38 #include <sys/prctl.h>
39 #include <sys/resource.h>
44 #include <sys/socket.h>
48 #include <sys/times.h>
51 #include <sys/statfs.h>
53 #include <sys/sysinfo.h>
54 #include <sys/utsname.h>
55 //#include <sys/user.h>
56 #include <netinet/ip.h>
57 #include <netinet/tcp.h>
58 #include <qemu-common.h>
63 #include <sys/eventfd.h>
66 #define termios host_termios
67 #define winsize host_winsize
68 #define termio host_termio
69 #define sgttyb host_sgttyb /* same as target */
70 #define tchars host_tchars /* same as target */
71 #define ltchars host_ltchars /* same as target */
73 #include <linux/termios.h>
74 #include <linux/unistd.h>
75 #include <linux/utsname.h>
76 #include <linux/cdrom.h>
77 #include <linux/hdreg.h>
78 #include <linux/soundcard.h>
80 #include <linux/mtio.h>
82 #include "linux_loop.h"
85 #include "qemu-common.h"
87 #if defined(CONFIG_USE_NPTL)
88 #define CLONE_NPTL_FLAGS2 (CLONE_SETTLS | \
89 CLONE_PARENT_SETTID | CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID)
91 /* XXX: Hardcode the above values. */
92 #define CLONE_NPTL_FLAGS2 0
97 //#include <linux/msdos_fs.h>
98 #define VFAT_IOCTL_READDIR_BOTH _IOR('r', 1, struct linux_dirent [2])
99 #define VFAT_IOCTL_READDIR_SHORT _IOR('r', 2, struct linux_dirent [2])
110 #define _syscall0(type,name) \
111 static type name (void) \
113 return syscall(__NR_##name); \
116 #define _syscall1(type,name,type1,arg1) \
117 static type name (type1 arg1) \
119 return syscall(__NR_##name, arg1); \
122 #define _syscall2(type,name,type1,arg1,type2,arg2) \
123 static type name (type1 arg1,type2 arg2) \
125 return syscall(__NR_##name, arg1, arg2); \
128 #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
129 static type name (type1 arg1,type2 arg2,type3 arg3) \
131 return syscall(__NR_##name, arg1, arg2, arg3); \
134 #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
135 static type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4) \
137 return syscall(__NR_##name, arg1, arg2, arg3, arg4); \
140 #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
142 static type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \
144 return syscall(__NR_##name, arg1, arg2, arg3, arg4, arg5); \
148 #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
149 type5,arg5,type6,arg6) \
150 static type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5, \
153 return syscall(__NR_##name, arg1, arg2, arg3, arg4, arg5, arg6); \
157 #define __NR_sys_uname __NR_uname
158 #define __NR_sys_faccessat __NR_faccessat
159 #define __NR_sys_fchmodat __NR_fchmodat
160 #define __NR_sys_fchownat __NR_fchownat
161 #define __NR_sys_fstatat64 __NR_fstatat64
162 #define __NR_sys_futimesat __NR_futimesat
163 #define __NR_sys_getcwd1 __NR_getcwd
164 #define __NR_sys_getdents __NR_getdents
165 #define __NR_sys_getdents64 __NR_getdents64
166 #define __NR_sys_getpriority __NR_getpriority
167 #define __NR_sys_linkat __NR_linkat
168 #define __NR_sys_mkdirat __NR_mkdirat
169 #define __NR_sys_mknodat __NR_mknodat
170 #define __NR_sys_newfstatat __NR_newfstatat
171 #define __NR_sys_openat __NR_openat
172 #define __NR_sys_readlinkat __NR_readlinkat
173 #define __NR_sys_renameat __NR_renameat
174 #define __NR_sys_rt_sigqueueinfo __NR_rt_sigqueueinfo
175 #define __NR_sys_symlinkat __NR_symlinkat
176 #define __NR_sys_syslog __NR_syslog
177 #define __NR_sys_tgkill __NR_tgkill
178 #define __NR_sys_tkill __NR_tkill
179 #define __NR_sys_unlinkat __NR_unlinkat
180 #define __NR_sys_utimensat __NR_utimensat
181 #define __NR_sys_futex __NR_futex
182 #define __NR_sys_inotify_init __NR_inotify_init
183 #define __NR_sys_inotify_add_watch __NR_inotify_add_watch
184 #define __NR_sys_inotify_rm_watch __NR_inotify_rm_watch
186 #if defined(__alpha__) || defined (__ia64__) || defined(__x86_64__)
187 #define __NR__llseek __NR_lseek
191 _syscall0(int, gettid
)
193 /* This is a replacement for the host gettid() and must return a host
195 static int gettid(void) {
199 _syscall3(int, sys_getdents
, uint
, fd
, struct linux_dirent
*, dirp
, uint
, count
);
200 #if defined(TARGET_NR_getdents64) && defined(__NR_getdents64)
201 _syscall3(int, sys_getdents64
, uint
, fd
, struct linux_dirent64
*, dirp
, uint
, count
);
203 _syscall2(int, sys_getpriority
, int, which
, int, who
);
204 #if defined(TARGET_NR__llseek) && !defined (__x86_64__)
205 _syscall5(int, _llseek
, uint
, fd
, ulong
, hi
, ulong
, lo
,
206 loff_t
*, res
, uint
, wh
);
208 _syscall3(int,sys_rt_sigqueueinfo
,int,pid
,int,sig
,siginfo_t
*,uinfo
)
209 _syscall3(int,sys_syslog
,int,type
,char*,bufp
,int,len
)
210 #if defined(TARGET_NR_tgkill) && defined(__NR_tgkill)
211 _syscall3(int,sys_tgkill
,int,tgid
,int,pid
,int,sig
)
213 #if defined(TARGET_NR_tkill) && defined(__NR_tkill)
214 _syscall2(int,sys_tkill
,int,tid
,int,sig
)
216 #ifdef __NR_exit_group
217 _syscall1(int,exit_group
,int,error_code
)
219 #if defined(TARGET_NR_set_tid_address) && defined(__NR_set_tid_address)
220 _syscall1(int,set_tid_address
,int *,tidptr
)
222 #if defined(CONFIG_USE_NPTL)
223 #if defined(TARGET_NR_futex) && defined(__NR_futex)
224 _syscall6(int,sys_futex
,int *,uaddr
,int,op
,int,val
,
225 const struct timespec
*,timeout
,int *,uaddr2
,int,val3
)
229 static bitmask_transtbl fcntl_flags_tbl
[] = {
230 { TARGET_O_ACCMODE
, TARGET_O_WRONLY
, O_ACCMODE
, O_WRONLY
, },
231 { TARGET_O_ACCMODE
, TARGET_O_RDWR
, O_ACCMODE
, O_RDWR
, },
232 { TARGET_O_CREAT
, TARGET_O_CREAT
, O_CREAT
, O_CREAT
, },
233 { TARGET_O_EXCL
, TARGET_O_EXCL
, O_EXCL
, O_EXCL
, },
234 { TARGET_O_NOCTTY
, TARGET_O_NOCTTY
, O_NOCTTY
, O_NOCTTY
, },
235 { TARGET_O_TRUNC
, TARGET_O_TRUNC
, O_TRUNC
, O_TRUNC
, },
236 { TARGET_O_APPEND
, TARGET_O_APPEND
, O_APPEND
, O_APPEND
, },
237 { TARGET_O_NONBLOCK
, TARGET_O_NONBLOCK
, O_NONBLOCK
, O_NONBLOCK
, },
238 { TARGET_O_SYNC
, TARGET_O_SYNC
, O_SYNC
, O_SYNC
, },
239 { TARGET_FASYNC
, TARGET_FASYNC
, FASYNC
, FASYNC
, },
240 { TARGET_O_DIRECTORY
, TARGET_O_DIRECTORY
, O_DIRECTORY
, O_DIRECTORY
, },
241 { TARGET_O_NOFOLLOW
, TARGET_O_NOFOLLOW
, O_NOFOLLOW
, O_NOFOLLOW
, },
242 { TARGET_O_LARGEFILE
, TARGET_O_LARGEFILE
, O_LARGEFILE
, O_LARGEFILE
, },
243 #if defined(O_DIRECT)
244 { TARGET_O_DIRECT
, TARGET_O_DIRECT
, O_DIRECT
, O_DIRECT
, },
249 #define COPY_UTSNAME_FIELD(dest, src) \
251 /* __NEW_UTS_LEN doesn't include terminating null */ \
252 (void) strncpy((dest), (src), __NEW_UTS_LEN); \
253 (dest)[__NEW_UTS_LEN] = '\0'; \
256 static int sys_uname(struct new_utsname
*buf
)
258 struct utsname uts_buf
;
260 if (uname(&uts_buf
) < 0)
264 * Just in case these have some differences, we
265 * translate utsname to new_utsname (which is the
266 * struct linux kernel uses).
269 bzero(buf
, sizeof (*buf
));
270 COPY_UTSNAME_FIELD(buf
->sysname
, uts_buf
.sysname
);
271 COPY_UTSNAME_FIELD(buf
->nodename
, uts_buf
.nodename
);
272 COPY_UTSNAME_FIELD(buf
->release
, uts_buf
.release
);
273 COPY_UTSNAME_FIELD(buf
->version
, uts_buf
.version
);
274 COPY_UTSNAME_FIELD(buf
->machine
, uts_buf
.machine
);
276 COPY_UTSNAME_FIELD(buf
->domainname
, uts_buf
.domainname
);
280 #undef COPY_UTSNAME_FIELD
283 static int sys_getcwd1(char *buf
, size_t size
)
285 if (getcwd(buf
, size
) == NULL
) {
286 /* getcwd() sets errno */
289 return strlen(buf
)+1;
294 * Host system seems to have atfile syscall stubs available. We
295 * now enable them one by one as specified by target syscall_nr.h.
298 #ifdef TARGET_NR_faccessat
299 static int sys_faccessat(int dirfd
, const char *pathname
, int mode
)
301 return (faccessat(dirfd
, pathname
, mode
, 0));
304 #ifdef TARGET_NR_fchmodat
305 static int sys_fchmodat(int dirfd
, const char *pathname
, mode_t mode
)
307 return (fchmodat(dirfd
, pathname
, mode
, 0));
310 #if defined(TARGET_NR_fchownat) && defined(USE_UID16)
311 static int sys_fchownat(int dirfd
, const char *pathname
, uid_t owner
,
312 gid_t group
, int flags
)
314 return (fchownat(dirfd
, pathname
, owner
, group
, flags
));
317 #ifdef __NR_fstatat64
318 static int sys_fstatat64(int dirfd
, const char *pathname
, struct stat
*buf
,
321 return (fstatat(dirfd
, pathname
, buf
, flags
));
324 #ifdef __NR_newfstatat
325 static int sys_newfstatat(int dirfd
, const char *pathname
, struct stat
*buf
,
328 return (fstatat(dirfd
, pathname
, buf
, flags
));
331 #ifdef TARGET_NR_futimesat
332 static int sys_futimesat(int dirfd
, const char *pathname
,
333 const struct timeval times
[2])
335 return (futimesat(dirfd
, pathname
, times
));
338 #ifdef TARGET_NR_linkat
339 static int sys_linkat(int olddirfd
, const char *oldpath
,
340 int newdirfd
, const char *newpath
, int flags
)
342 return (linkat(olddirfd
, oldpath
, newdirfd
, newpath
, flags
));
345 #ifdef TARGET_NR_mkdirat
346 static int sys_mkdirat(int dirfd
, const char *pathname
, mode_t mode
)
348 return (mkdirat(dirfd
, pathname
, mode
));
351 #ifdef TARGET_NR_mknodat
352 static int sys_mknodat(int dirfd
, const char *pathname
, mode_t mode
,
355 return (mknodat(dirfd
, pathname
, mode
, dev
));
358 #ifdef TARGET_NR_openat
359 static int sys_openat(int dirfd
, const char *pathname
, int flags
, ...)
362 * open(2) has extra parameter 'mode' when called with
365 if ((flags
& O_CREAT
) != 0) {
370 * Get the 'mode' parameter and translate it to
374 mode
= va_arg(ap
, mode_t
);
375 mode
= target_to_host_bitmask(mode
, fcntl_flags_tbl
);
378 return (openat(dirfd
, pathname
, flags
, mode
));
380 return (openat(dirfd
, pathname
, flags
));
383 #ifdef TARGET_NR_readlinkat
384 static int sys_readlinkat(int dirfd
, const char *pathname
, char *buf
, size_t bufsiz
)
386 return (readlinkat(dirfd
, pathname
, buf
, bufsiz
));
389 #ifdef TARGET_NR_renameat
390 static int sys_renameat(int olddirfd
, const char *oldpath
,
391 int newdirfd
, const char *newpath
)
393 return (renameat(olddirfd
, oldpath
, newdirfd
, newpath
));
396 #ifdef TARGET_NR_symlinkat
397 static int sys_symlinkat(const char *oldpath
, int newdirfd
, const char *newpath
)
399 return (symlinkat(oldpath
, newdirfd
, newpath
));
402 #ifdef TARGET_NR_unlinkat
403 static int sys_unlinkat(int dirfd
, const char *pathname
, int flags
)
405 return (unlinkat(dirfd
, pathname
, flags
));
408 #else /* !CONFIG_ATFILE */
411 * Try direct syscalls instead
413 #if defined(TARGET_NR_faccessat) && defined(__NR_faccessat)
414 _syscall3(int,sys_faccessat
,int,dirfd
,const char *,pathname
,int,mode
)
416 #if defined(TARGET_NR_fchmodat) && defined(__NR_fchmodat)
417 _syscall3(int,sys_fchmodat
,int,dirfd
,const char *,pathname
, mode_t
,mode
)
419 #if defined(TARGET_NR_fchownat) && defined(__NR_fchownat) && defined(USE_UID16)
420 _syscall5(int,sys_fchownat
,int,dirfd
,const char *,pathname
,
421 uid_t
,owner
,gid_t
,group
,int,flags
)
423 #if (defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat)) && \
424 defined(__NR_fstatat64)
425 _syscall4(int,sys_fstatat64
,int,dirfd
,const char *,pathname
,
426 struct stat
*,buf
,int,flags
)
428 #if defined(TARGET_NR_futimesat) && defined(__NR_futimesat)
429 _syscall3(int,sys_futimesat
,int,dirfd
,const char *,pathname
,
430 const struct timeval
*,times
)
432 #if (defined(TARGET_NR_newfstatat) || defined(TARGET_NR_fstatat64) ) && \
433 defined(__NR_newfstatat)
434 _syscall4(int,sys_newfstatat
,int,dirfd
,const char *,pathname
,
435 struct stat
*,buf
,int,flags
)
437 #if defined(TARGET_NR_linkat) && defined(__NR_linkat)
438 _syscall5(int,sys_linkat
,int,olddirfd
,const char *,oldpath
,
439 int,newdirfd
,const char *,newpath
,int,flags
)
441 #if defined(TARGET_NR_mkdirat) && defined(__NR_mkdirat)
442 _syscall3(int,sys_mkdirat
,int,dirfd
,const char *,pathname
,mode_t
,mode
)
444 #if defined(TARGET_NR_mknodat) && defined(__NR_mknodat)
445 _syscall4(int,sys_mknodat
,int,dirfd
,const char *,pathname
,
446 mode_t
,mode
,dev_t
,dev
)
448 #if defined(TARGET_NR_openat) && defined(__NR_openat)
449 _syscall4(int,sys_openat
,int,dirfd
,const char *,pathname
,int,flags
,mode_t
,mode
)
451 #if defined(TARGET_NR_readlinkat) && defined(__NR_readlinkat)
452 _syscall4(int,sys_readlinkat
,int,dirfd
,const char *,pathname
,
453 char *,buf
,size_t,bufsize
)
455 #if defined(TARGET_NR_renameat) && defined(__NR_renameat)
456 _syscall4(int,sys_renameat
,int,olddirfd
,const char *,oldpath
,
457 int,newdirfd
,const char *,newpath
)
459 #if defined(TARGET_NR_symlinkat) && defined(__NR_symlinkat)
460 _syscall3(int,sys_symlinkat
,const char *,oldpath
,
461 int,newdirfd
,const char *,newpath
)
463 #if defined(TARGET_NR_unlinkat) && defined(__NR_unlinkat)
464 _syscall3(int,sys_unlinkat
,int,dirfd
,const char *,pathname
,int,flags
)
467 #endif /* CONFIG_ATFILE */
469 #ifdef CONFIG_UTIMENSAT
470 static int sys_utimensat(int dirfd
, const char *pathname
,
471 const struct timespec times
[2], int flags
)
473 if (pathname
== NULL
)
474 return futimens(dirfd
, times
);
476 return utimensat(dirfd
, pathname
, times
, flags
);
479 #if defined(TARGET_NR_utimensat) && defined(__NR_utimensat)
480 _syscall4(int,sys_utimensat
,int,dirfd
,const char *,pathname
,
481 const struct timespec
*,tsp
,int,flags
)
483 #endif /* CONFIG_UTIMENSAT */
485 #ifdef CONFIG_INOTIFY
486 #include <sys/inotify.h>
488 #if defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init)
489 static int sys_inotify_init(void)
491 return (inotify_init());
494 #if defined(TARGET_NR_inotify_add_watch) && defined(__NR_inotify_add_watch)
495 static int sys_inotify_add_watch(int fd
,const char *pathname
, int32_t mask
)
497 return (inotify_add_watch(fd
, pathname
, mask
));
500 #if defined(TARGET_NR_inotify_rm_watch) && defined(__NR_inotify_rm_watch)
501 static int sys_inotify_rm_watch(int fd
, int32_t wd
)
503 return (inotify_rm_watch(fd
, wd
));
507 /* Userspace can usually survive runtime without inotify */
508 #undef TARGET_NR_inotify_init
509 #undef TARGET_NR_inotify_add_watch
510 #undef TARGET_NR_inotify_rm_watch
511 #endif /* CONFIG_INOTIFY */
514 extern int personality(int);
515 extern int flock(int, int);
516 extern int setfsuid(int);
517 extern int setfsgid(int);
518 extern int setgroups(int, gid_t
*);
520 #define ERRNO_TABLE_SIZE 1200
522 /* target_to_host_errno_table[] is initialized from
523 * host_to_target_errno_table[] in syscall_init(). */
524 static uint16_t target_to_host_errno_table
[ERRNO_TABLE_SIZE
] = {
528 * This list is the union of errno values overridden in asm-<arch>/errno.h
529 * minus the errnos that are not actually generic to all archs.
531 static uint16_t host_to_target_errno_table
[ERRNO_TABLE_SIZE
] = {
532 [EIDRM
] = TARGET_EIDRM
,
533 [ECHRNG
] = TARGET_ECHRNG
,
534 [EL2NSYNC
] = TARGET_EL2NSYNC
,
535 [EL3HLT
] = TARGET_EL3HLT
,
536 [EL3RST
] = TARGET_EL3RST
,
537 [ELNRNG
] = TARGET_ELNRNG
,
538 [EUNATCH
] = TARGET_EUNATCH
,
539 [ENOCSI
] = TARGET_ENOCSI
,
540 [EL2HLT
] = TARGET_EL2HLT
,
541 [EDEADLK
] = TARGET_EDEADLK
,
542 [ENOLCK
] = TARGET_ENOLCK
,
543 [EBADE
] = TARGET_EBADE
,
544 [EBADR
] = TARGET_EBADR
,
545 [EXFULL
] = TARGET_EXFULL
,
546 [ENOANO
] = TARGET_ENOANO
,
547 [EBADRQC
] = TARGET_EBADRQC
,
548 [EBADSLT
] = TARGET_EBADSLT
,
549 [EBFONT
] = TARGET_EBFONT
,
550 [ENOSTR
] = TARGET_ENOSTR
,
551 [ENODATA
] = TARGET_ENODATA
,
552 [ETIME
] = TARGET_ETIME
,
553 [ENOSR
] = TARGET_ENOSR
,
554 [ENONET
] = TARGET_ENONET
,
555 [ENOPKG
] = TARGET_ENOPKG
,
556 [EREMOTE
] = TARGET_EREMOTE
,
557 [ENOLINK
] = TARGET_ENOLINK
,
558 [EADV
] = TARGET_EADV
,
559 [ESRMNT
] = TARGET_ESRMNT
,
560 [ECOMM
] = TARGET_ECOMM
,
561 [EPROTO
] = TARGET_EPROTO
,
562 [EDOTDOT
] = TARGET_EDOTDOT
,
563 [EMULTIHOP
] = TARGET_EMULTIHOP
,
564 [EBADMSG
] = TARGET_EBADMSG
,
565 [ENAMETOOLONG
] = TARGET_ENAMETOOLONG
,
566 [EOVERFLOW
] = TARGET_EOVERFLOW
,
567 [ENOTUNIQ
] = TARGET_ENOTUNIQ
,
568 [EBADFD
] = TARGET_EBADFD
,
569 [EREMCHG
] = TARGET_EREMCHG
,
570 [ELIBACC
] = TARGET_ELIBACC
,
571 [ELIBBAD
] = TARGET_ELIBBAD
,
572 [ELIBSCN
] = TARGET_ELIBSCN
,
573 [ELIBMAX
] = TARGET_ELIBMAX
,
574 [ELIBEXEC
] = TARGET_ELIBEXEC
,
575 [EILSEQ
] = TARGET_EILSEQ
,
576 [ENOSYS
] = TARGET_ENOSYS
,
577 [ELOOP
] = TARGET_ELOOP
,
578 [ERESTART
] = TARGET_ERESTART
,
579 [ESTRPIPE
] = TARGET_ESTRPIPE
,
580 [ENOTEMPTY
] = TARGET_ENOTEMPTY
,
581 [EUSERS
] = TARGET_EUSERS
,
582 [ENOTSOCK
] = TARGET_ENOTSOCK
,
583 [EDESTADDRREQ
] = TARGET_EDESTADDRREQ
,
584 [EMSGSIZE
] = TARGET_EMSGSIZE
,
585 [EPROTOTYPE
] = TARGET_EPROTOTYPE
,
586 [ENOPROTOOPT
] = TARGET_ENOPROTOOPT
,
587 [EPROTONOSUPPORT
] = TARGET_EPROTONOSUPPORT
,
588 [ESOCKTNOSUPPORT
] = TARGET_ESOCKTNOSUPPORT
,
589 [EOPNOTSUPP
] = TARGET_EOPNOTSUPP
,
590 [EPFNOSUPPORT
] = TARGET_EPFNOSUPPORT
,
591 [EAFNOSUPPORT
] = TARGET_EAFNOSUPPORT
,
592 [EADDRINUSE
] = TARGET_EADDRINUSE
,
593 [EADDRNOTAVAIL
] = TARGET_EADDRNOTAVAIL
,
594 [ENETDOWN
] = TARGET_ENETDOWN
,
595 [ENETUNREACH
] = TARGET_ENETUNREACH
,
596 [ENETRESET
] = TARGET_ENETRESET
,
597 [ECONNABORTED
] = TARGET_ECONNABORTED
,
598 [ECONNRESET
] = TARGET_ECONNRESET
,
599 [ENOBUFS
] = TARGET_ENOBUFS
,
600 [EISCONN
] = TARGET_EISCONN
,
601 [ENOTCONN
] = TARGET_ENOTCONN
,
602 [EUCLEAN
] = TARGET_EUCLEAN
,
603 [ENOTNAM
] = TARGET_ENOTNAM
,
604 [ENAVAIL
] = TARGET_ENAVAIL
,
605 [EISNAM
] = TARGET_EISNAM
,
606 [EREMOTEIO
] = TARGET_EREMOTEIO
,
607 [ESHUTDOWN
] = TARGET_ESHUTDOWN
,
608 [ETOOMANYREFS
] = TARGET_ETOOMANYREFS
,
609 [ETIMEDOUT
] = TARGET_ETIMEDOUT
,
610 [ECONNREFUSED
] = TARGET_ECONNREFUSED
,
611 [EHOSTDOWN
] = TARGET_EHOSTDOWN
,
612 [EHOSTUNREACH
] = TARGET_EHOSTUNREACH
,
613 [EALREADY
] = TARGET_EALREADY
,
614 [EINPROGRESS
] = TARGET_EINPROGRESS
,
615 [ESTALE
] = TARGET_ESTALE
,
616 [ECANCELED
] = TARGET_ECANCELED
,
617 [ENOMEDIUM
] = TARGET_ENOMEDIUM
,
618 [EMEDIUMTYPE
] = TARGET_EMEDIUMTYPE
,
620 [ENOKEY
] = TARGET_ENOKEY
,
623 [EKEYEXPIRED
] = TARGET_EKEYEXPIRED
,
626 [EKEYREVOKED
] = TARGET_EKEYREVOKED
,
629 [EKEYREJECTED
] = TARGET_EKEYREJECTED
,
632 [EOWNERDEAD
] = TARGET_EOWNERDEAD
,
634 #ifdef ENOTRECOVERABLE
635 [ENOTRECOVERABLE
] = TARGET_ENOTRECOVERABLE
,
639 static inline int host_to_target_errno(int err
)
641 if(host_to_target_errno_table
[err
])
642 return host_to_target_errno_table
[err
];
646 static inline int target_to_host_errno(int err
)
648 if (target_to_host_errno_table
[err
])
649 return target_to_host_errno_table
[err
];
653 static inline abi_long
get_errno(abi_long ret
)
656 return -host_to_target_errno(errno
);
661 static inline int is_error(abi_long ret
)
663 return (abi_ulong
)ret
>= (abi_ulong
)(-4096);
666 char *target_strerror(int err
)
668 return strerror(target_to_host_errno(err
));
671 static abi_ulong target_brk
;
672 static abi_ulong target_original_brk
;
674 void target_set_brk(abi_ulong new_brk
)
676 target_original_brk
= target_brk
= HOST_PAGE_ALIGN(new_brk
);
679 /* do_brk() must return target values and target errnos. */
680 abi_long
do_brk(abi_ulong new_brk
)
683 abi_long mapped_addr
;
688 if (new_brk
< target_original_brk
)
691 brk_page
= HOST_PAGE_ALIGN(target_brk
);
693 /* If the new brk is less than this, set it and we're done... */
694 if (new_brk
< brk_page
) {
695 target_brk
= new_brk
;
699 /* We need to allocate more memory after the brk... */
700 new_alloc_size
= HOST_PAGE_ALIGN(new_brk
- brk_page
+ 1);
701 mapped_addr
= get_errno(target_mmap(brk_page
, new_alloc_size
,
702 PROT_READ
|PROT_WRITE
,
703 MAP_ANON
|MAP_FIXED
|MAP_PRIVATE
, 0, 0));
705 if (!is_error(mapped_addr
))
706 target_brk
= new_brk
;
711 static inline abi_long
copy_from_user_fdset(fd_set
*fds
,
712 abi_ulong target_fds_addr
,
716 abi_ulong b
, *target_fds
;
718 nw
= (n
+ TARGET_ABI_BITS
- 1) / TARGET_ABI_BITS
;
719 if (!(target_fds
= lock_user(VERIFY_READ
,
721 sizeof(abi_ulong
) * nw
,
723 return -TARGET_EFAULT
;
727 for (i
= 0; i
< nw
; i
++) {
728 /* grab the abi_ulong */
729 __get_user(b
, &target_fds
[i
]);
730 for (j
= 0; j
< TARGET_ABI_BITS
; j
++) {
731 /* check the bit inside the abi_ulong */
738 unlock_user(target_fds
, target_fds_addr
, 0);
743 static inline abi_long
copy_to_user_fdset(abi_ulong target_fds_addr
,
749 abi_ulong
*target_fds
;
751 nw
= (n
+ TARGET_ABI_BITS
- 1) / TARGET_ABI_BITS
;
752 if (!(target_fds
= lock_user(VERIFY_WRITE
,
754 sizeof(abi_ulong
) * nw
,
756 return -TARGET_EFAULT
;
759 for (i
= 0; i
< nw
; i
++) {
761 for (j
= 0; j
< TARGET_ABI_BITS
; j
++) {
762 v
|= ((FD_ISSET(k
, fds
) != 0) << j
);
765 __put_user(v
, &target_fds
[i
]);
768 unlock_user(target_fds
, target_fds_addr
, sizeof(abi_ulong
) * nw
);
773 #if defined(__alpha__)
779 static inline abi_long
host_to_target_clock_t(long ticks
)
781 #if HOST_HZ == TARGET_HZ
784 return ((int64_t)ticks
* TARGET_HZ
) / HOST_HZ
;
788 static inline abi_long
host_to_target_rusage(abi_ulong target_addr
,
789 const struct rusage
*rusage
)
791 struct target_rusage
*target_rusage
;
793 if (!lock_user_struct(VERIFY_WRITE
, target_rusage
, target_addr
, 0))
794 return -TARGET_EFAULT
;
795 target_rusage
->ru_utime
.tv_sec
= tswapl(rusage
->ru_utime
.tv_sec
);
796 target_rusage
->ru_utime
.tv_usec
= tswapl(rusage
->ru_utime
.tv_usec
);
797 target_rusage
->ru_stime
.tv_sec
= tswapl(rusage
->ru_stime
.tv_sec
);
798 target_rusage
->ru_stime
.tv_usec
= tswapl(rusage
->ru_stime
.tv_usec
);
799 target_rusage
->ru_maxrss
= tswapl(rusage
->ru_maxrss
);
800 target_rusage
->ru_ixrss
= tswapl(rusage
->ru_ixrss
);
801 target_rusage
->ru_idrss
= tswapl(rusage
->ru_idrss
);
802 target_rusage
->ru_isrss
= tswapl(rusage
->ru_isrss
);
803 target_rusage
->ru_minflt
= tswapl(rusage
->ru_minflt
);
804 target_rusage
->ru_majflt
= tswapl(rusage
->ru_majflt
);
805 target_rusage
->ru_nswap
= tswapl(rusage
->ru_nswap
);
806 target_rusage
->ru_inblock
= tswapl(rusage
->ru_inblock
);
807 target_rusage
->ru_oublock
= tswapl(rusage
->ru_oublock
);
808 target_rusage
->ru_msgsnd
= tswapl(rusage
->ru_msgsnd
);
809 target_rusage
->ru_msgrcv
= tswapl(rusage
->ru_msgrcv
);
810 target_rusage
->ru_nsignals
= tswapl(rusage
->ru_nsignals
);
811 target_rusage
->ru_nvcsw
= tswapl(rusage
->ru_nvcsw
);
812 target_rusage
->ru_nivcsw
= tswapl(rusage
->ru_nivcsw
);
813 unlock_user_struct(target_rusage
, target_addr
, 1);
818 static inline abi_long
copy_from_user_timeval(struct timeval
*tv
,
819 abi_ulong target_tv_addr
)
821 struct target_timeval
*target_tv
;
823 if (!lock_user_struct(VERIFY_READ
, target_tv
, target_tv_addr
, 1))
824 return -TARGET_EFAULT
;
826 __get_user(tv
->tv_sec
, &target_tv
->tv_sec
);
827 __get_user(tv
->tv_usec
, &target_tv
->tv_usec
);
829 unlock_user_struct(target_tv
, target_tv_addr
, 0);
834 static inline abi_long
copy_to_user_timeval(abi_ulong target_tv_addr
,
835 const struct timeval
*tv
)
837 struct target_timeval
*target_tv
;
839 if (!lock_user_struct(VERIFY_WRITE
, target_tv
, target_tv_addr
, 0))
840 return -TARGET_EFAULT
;
842 __put_user(tv
->tv_sec
, &target_tv
->tv_sec
);
843 __put_user(tv
->tv_usec
, &target_tv
->tv_usec
);
845 unlock_user_struct(target_tv
, target_tv_addr
, 1);
850 #if defined(TARGET_NR_mq_open) && defined(__NR_mq_open)
853 static inline abi_long
copy_from_user_mq_attr(struct mq_attr
*attr
,
854 abi_ulong target_mq_attr_addr
)
856 struct target_mq_attr
*target_mq_attr
;
858 if (!lock_user_struct(VERIFY_READ
, target_mq_attr
,
859 target_mq_attr_addr
, 1))
860 return -TARGET_EFAULT
;
862 __get_user(attr
->mq_flags
, &target_mq_attr
->mq_flags
);
863 __get_user(attr
->mq_maxmsg
, &target_mq_attr
->mq_maxmsg
);
864 __get_user(attr
->mq_msgsize
, &target_mq_attr
->mq_msgsize
);
865 __get_user(attr
->mq_curmsgs
, &target_mq_attr
->mq_curmsgs
);
867 unlock_user_struct(target_mq_attr
, target_mq_attr_addr
, 0);
872 static inline abi_long
copy_to_user_mq_attr(abi_ulong target_mq_attr_addr
,
873 const struct mq_attr
*attr
)
875 struct target_mq_attr
*target_mq_attr
;
877 if (!lock_user_struct(VERIFY_WRITE
, target_mq_attr
,
878 target_mq_attr_addr
, 0))
879 return -TARGET_EFAULT
;
881 __put_user(attr
->mq_flags
, &target_mq_attr
->mq_flags
);
882 __put_user(attr
->mq_maxmsg
, &target_mq_attr
->mq_maxmsg
);
883 __put_user(attr
->mq_msgsize
, &target_mq_attr
->mq_msgsize
);
884 __put_user(attr
->mq_curmsgs
, &target_mq_attr
->mq_curmsgs
);
886 unlock_user_struct(target_mq_attr
, target_mq_attr_addr
, 1);
892 /* do_select() must return target values and target errnos. */
893 static abi_long
do_select(int n
,
894 abi_ulong rfd_addr
, abi_ulong wfd_addr
,
895 abi_ulong efd_addr
, abi_ulong target_tv_addr
)
897 fd_set rfds
, wfds
, efds
;
898 fd_set
*rfds_ptr
, *wfds_ptr
, *efds_ptr
;
899 struct timeval tv
, *tv_ptr
;
903 if (copy_from_user_fdset(&rfds
, rfd_addr
, n
))
904 return -TARGET_EFAULT
;
910 if (copy_from_user_fdset(&wfds
, wfd_addr
, n
))
911 return -TARGET_EFAULT
;
917 if (copy_from_user_fdset(&efds
, efd_addr
, n
))
918 return -TARGET_EFAULT
;
924 if (target_tv_addr
) {
925 if (copy_from_user_timeval(&tv
, target_tv_addr
))
926 return -TARGET_EFAULT
;
932 ret
= get_errno(select(n
, rfds_ptr
, wfds_ptr
, efds_ptr
, tv_ptr
));
934 if (!is_error(ret
)) {
935 if (rfd_addr
&& copy_to_user_fdset(rfd_addr
, &rfds
, n
))
936 return -TARGET_EFAULT
;
937 if (wfd_addr
&& copy_to_user_fdset(wfd_addr
, &wfds
, n
))
938 return -TARGET_EFAULT
;
939 if (efd_addr
&& copy_to_user_fdset(efd_addr
, &efds
, n
))
940 return -TARGET_EFAULT
;
942 if (target_tv_addr
&& copy_to_user_timeval(target_tv_addr
, &tv
))
943 return -TARGET_EFAULT
;
949 static abi_long
do_pipe2(int host_pipe
[], int flags
)
952 return pipe2(host_pipe
, flags
);
958 static abi_long
do_pipe(void *cpu_env
, abi_ulong pipedes
, int flags
)
962 ret
= flags
? do_pipe2(host_pipe
, flags
) : pipe(host_pipe
);
965 return get_errno(ret
);
966 #if defined(TARGET_MIPS)
967 ((CPUMIPSState
*)cpu_env
)->active_tc
.gpr
[3] = host_pipe
[1];
969 #elif defined(TARGET_SH4)
970 ((CPUSH4State
*)cpu_env
)->gregs
[1] = host_pipe
[1];
973 if (put_user_s32(host_pipe
[0], pipedes
)
974 || put_user_s32(host_pipe
[1], pipedes
+ sizeof(host_pipe
[0])))
975 return -TARGET_EFAULT
;
977 return get_errno(ret
);
980 static inline abi_long
target_to_host_ip_mreq(struct ip_mreqn
*mreqn
,
981 abi_ulong target_addr
,
984 struct target_ip_mreqn
*target_smreqn
;
986 target_smreqn
= lock_user(VERIFY_READ
, target_addr
, len
, 1);
988 return -TARGET_EFAULT
;
989 mreqn
->imr_multiaddr
.s_addr
= target_smreqn
->imr_multiaddr
.s_addr
;
990 mreqn
->imr_address
.s_addr
= target_smreqn
->imr_address
.s_addr
;
991 if (len
== sizeof(struct target_ip_mreqn
))
992 mreqn
->imr_ifindex
= tswapl(target_smreqn
->imr_ifindex
);
993 unlock_user(target_smreqn
, target_addr
, 0);
998 static inline abi_long
target_to_host_sockaddr(struct sockaddr
*addr
,
999 abi_ulong target_addr
,
1002 const socklen_t unix_maxlen
= sizeof (struct sockaddr_un
);
1003 sa_family_t sa_family
;
1004 struct target_sockaddr
*target_saddr
;
1006 target_saddr
= lock_user(VERIFY_READ
, target_addr
, len
, 1);
1008 return -TARGET_EFAULT
;
1010 sa_family
= tswap16(target_saddr
->sa_family
);
1012 /* Oops. The caller might send a incomplete sun_path; sun_path
1013 * must be terminated by \0 (see the manual page), but
1014 * unfortunately it is quite common to specify sockaddr_un
1015 * length as "strlen(x->sun_path)" while it should be
1016 * "strlen(...) + 1". We'll fix that here if needed.
1017 * Linux kernel has a similar feature.
1020 if (sa_family
== AF_UNIX
) {
1021 if (len
< unix_maxlen
&& len
> 0) {
1022 char *cp
= (char*)target_saddr
;
1024 if ( cp
[len
-1] && !cp
[len
] )
1027 if (len
> unix_maxlen
)
1031 memcpy(addr
, target_saddr
, len
);
1032 addr
->sa_family
= sa_family
;
1033 unlock_user(target_saddr
, target_addr
, 0);
1038 static inline abi_long
host_to_target_sockaddr(abi_ulong target_addr
,
1039 struct sockaddr
*addr
,
1042 struct target_sockaddr
*target_saddr
;
1044 target_saddr
= lock_user(VERIFY_WRITE
, target_addr
, len
, 0);
1046 return -TARGET_EFAULT
;
1047 memcpy(target_saddr
, addr
, len
);
1048 target_saddr
->sa_family
= tswap16(addr
->sa_family
);
1049 unlock_user(target_saddr
, target_addr
, len
);
1054 /* ??? Should this also swap msgh->name? */
1055 static inline abi_long
target_to_host_cmsg(struct msghdr
*msgh
,
1056 struct target_msghdr
*target_msgh
)
1058 struct cmsghdr
*cmsg
= CMSG_FIRSTHDR(msgh
);
1059 abi_long msg_controllen
;
1060 abi_ulong target_cmsg_addr
;
1061 struct target_cmsghdr
*target_cmsg
;
1062 socklen_t space
= 0;
1064 msg_controllen
= tswapl(target_msgh
->msg_controllen
);
1065 if (msg_controllen
< sizeof (struct target_cmsghdr
))
1067 target_cmsg_addr
= tswapl(target_msgh
->msg_control
);
1068 target_cmsg
= lock_user(VERIFY_READ
, target_cmsg_addr
, msg_controllen
, 1);
1070 return -TARGET_EFAULT
;
1072 while (cmsg
&& target_cmsg
) {
1073 void *data
= CMSG_DATA(cmsg
);
1074 void *target_data
= TARGET_CMSG_DATA(target_cmsg
);
1076 int len
= tswapl(target_cmsg
->cmsg_len
)
1077 - TARGET_CMSG_ALIGN(sizeof (struct target_cmsghdr
));
1079 space
+= CMSG_SPACE(len
);
1080 if (space
> msgh
->msg_controllen
) {
1081 space
-= CMSG_SPACE(len
);
1082 gemu_log("Host cmsg overflow\n");
1086 cmsg
->cmsg_level
= tswap32(target_cmsg
->cmsg_level
);
1087 cmsg
->cmsg_type
= tswap32(target_cmsg
->cmsg_type
);
1088 cmsg
->cmsg_len
= CMSG_LEN(len
);
1090 if (cmsg
->cmsg_level
!= TARGET_SOL_SOCKET
|| cmsg
->cmsg_type
!= SCM_RIGHTS
) {
1091 gemu_log("Unsupported ancillary data: %d/%d\n", cmsg
->cmsg_level
, cmsg
->cmsg_type
);
1092 memcpy(data
, target_data
, len
);
1094 int *fd
= (int *)data
;
1095 int *target_fd
= (int *)target_data
;
1096 int i
, numfds
= len
/ sizeof(int);
1098 for (i
= 0; i
< numfds
; i
++)
1099 fd
[i
] = tswap32(target_fd
[i
]);
1102 cmsg
= CMSG_NXTHDR(msgh
, cmsg
);
1103 target_cmsg
= TARGET_CMSG_NXTHDR(target_msgh
, target_cmsg
);
1105 unlock_user(target_cmsg
, target_cmsg_addr
, 0);
1107 msgh
->msg_controllen
= space
;
1111 /* ??? Should this also swap msgh->name? */
1112 static inline abi_long
host_to_target_cmsg(struct target_msghdr
*target_msgh
,
1113 struct msghdr
*msgh
)
1115 struct cmsghdr
*cmsg
= CMSG_FIRSTHDR(msgh
);
1116 abi_long msg_controllen
;
1117 abi_ulong target_cmsg_addr
;
1118 struct target_cmsghdr
*target_cmsg
;
1119 socklen_t space
= 0;
1121 msg_controllen
= tswapl(target_msgh
->msg_controllen
);
1122 if (msg_controllen
< sizeof (struct target_cmsghdr
))
1124 target_cmsg_addr
= tswapl(target_msgh
->msg_control
);
1125 target_cmsg
= lock_user(VERIFY_WRITE
, target_cmsg_addr
, msg_controllen
, 0);
1127 return -TARGET_EFAULT
;
1129 while (cmsg
&& target_cmsg
) {
1130 void *data
= CMSG_DATA(cmsg
);
1131 void *target_data
= TARGET_CMSG_DATA(target_cmsg
);
1133 int len
= cmsg
->cmsg_len
- CMSG_ALIGN(sizeof (struct cmsghdr
));
1135 space
+= TARGET_CMSG_SPACE(len
);
1136 if (space
> msg_controllen
) {
1137 space
-= TARGET_CMSG_SPACE(len
);
1138 gemu_log("Target cmsg overflow\n");
1142 target_cmsg
->cmsg_level
= tswap32(cmsg
->cmsg_level
);
1143 target_cmsg
->cmsg_type
= tswap32(cmsg
->cmsg_type
);
1144 target_cmsg
->cmsg_len
= tswapl(TARGET_CMSG_LEN(len
));
1146 if (cmsg
->cmsg_level
!= TARGET_SOL_SOCKET
|| cmsg
->cmsg_type
!= SCM_RIGHTS
) {
1147 gemu_log("Unsupported ancillary data: %d/%d\n", cmsg
->cmsg_level
, cmsg
->cmsg_type
);
1148 memcpy(target_data
, data
, len
);
1150 int *fd
= (int *)data
;
1151 int *target_fd
= (int *)target_data
;
1152 int i
, numfds
= len
/ sizeof(int);
1154 for (i
= 0; i
< numfds
; i
++)
1155 target_fd
[i
] = tswap32(fd
[i
]);
1158 cmsg
= CMSG_NXTHDR(msgh
, cmsg
);
1159 target_cmsg
= TARGET_CMSG_NXTHDR(target_msgh
, target_cmsg
);
1161 unlock_user(target_cmsg
, target_cmsg_addr
, space
);
1163 target_msgh
->msg_controllen
= tswapl(space
);
1167 /* do_setsockopt() Must return target values and target errnos. */
1168 static abi_long
do_setsockopt(int sockfd
, int level
, int optname
,
1169 abi_ulong optval_addr
, socklen_t optlen
)
1173 struct ip_mreqn
*ip_mreq
;
1174 struct ip_mreq_source
*ip_mreq_source
;
1178 /* TCP options all take an 'int' value. */
1179 if (optlen
< sizeof(uint32_t))
1180 return -TARGET_EINVAL
;
1182 if (get_user_u32(val
, optval_addr
))
1183 return -TARGET_EFAULT
;
1184 ret
= get_errno(setsockopt(sockfd
, level
, optname
, &val
, sizeof(val
)));
1191 case IP_ROUTER_ALERT
:
1195 case IP_MTU_DISCOVER
:
1201 case IP_MULTICAST_TTL
:
1202 case IP_MULTICAST_LOOP
:
1204 if (optlen
>= sizeof(uint32_t)) {
1205 if (get_user_u32(val
, optval_addr
))
1206 return -TARGET_EFAULT
;
1207 } else if (optlen
>= 1) {
1208 if (get_user_u8(val
, optval_addr
))
1209 return -TARGET_EFAULT
;
1211 ret
= get_errno(setsockopt(sockfd
, level
, optname
, &val
, sizeof(val
)));
1213 case IP_ADD_MEMBERSHIP
:
1214 case IP_DROP_MEMBERSHIP
:
1215 if (optlen
< sizeof (struct target_ip_mreq
) ||
1216 optlen
> sizeof (struct target_ip_mreqn
))
1217 return -TARGET_EINVAL
;
1219 ip_mreq
= (struct ip_mreqn
*) alloca(optlen
);
1220 target_to_host_ip_mreq(ip_mreq
, optval_addr
, optlen
);
1221 ret
= get_errno(setsockopt(sockfd
, level
, optname
, ip_mreq
, optlen
));
1224 case IP_BLOCK_SOURCE
:
1225 case IP_UNBLOCK_SOURCE
:
1226 case IP_ADD_SOURCE_MEMBERSHIP
:
1227 case IP_DROP_SOURCE_MEMBERSHIP
:
1228 if (optlen
!= sizeof (struct target_ip_mreq_source
))
1229 return -TARGET_EINVAL
;
1231 ip_mreq_source
= lock_user(VERIFY_READ
, optval_addr
, optlen
, 1);
1232 ret
= get_errno(setsockopt(sockfd
, level
, optname
, ip_mreq_source
, optlen
));
1233 unlock_user (ip_mreq_source
, optval_addr
, 0);
1240 case TARGET_SOL_SOCKET
:
1242 /* Options with 'int' argument. */
1243 case TARGET_SO_DEBUG
:
1246 case TARGET_SO_REUSEADDR
:
1247 optname
= SO_REUSEADDR
;
1249 case TARGET_SO_TYPE
:
1252 case TARGET_SO_ERROR
:
1255 case TARGET_SO_DONTROUTE
:
1256 optname
= SO_DONTROUTE
;
1258 case TARGET_SO_BROADCAST
:
1259 optname
= SO_BROADCAST
;
1261 case TARGET_SO_SNDBUF
:
1262 optname
= SO_SNDBUF
;
1264 case TARGET_SO_RCVBUF
:
1265 optname
= SO_RCVBUF
;
1267 case TARGET_SO_KEEPALIVE
:
1268 optname
= SO_KEEPALIVE
;
1270 case TARGET_SO_OOBINLINE
:
1271 optname
= SO_OOBINLINE
;
1273 case TARGET_SO_NO_CHECK
:
1274 optname
= SO_NO_CHECK
;
1276 case TARGET_SO_PRIORITY
:
1277 optname
= SO_PRIORITY
;
1280 case TARGET_SO_BSDCOMPAT
:
1281 optname
= SO_BSDCOMPAT
;
1284 case TARGET_SO_PASSCRED
:
1285 optname
= SO_PASSCRED
;
1287 case TARGET_SO_TIMESTAMP
:
1288 optname
= SO_TIMESTAMP
;
1290 case TARGET_SO_RCVLOWAT
:
1291 optname
= SO_RCVLOWAT
;
1293 case TARGET_SO_RCVTIMEO
:
1294 optname
= SO_RCVTIMEO
;
1296 case TARGET_SO_SNDTIMEO
:
1297 optname
= SO_SNDTIMEO
;
1303 if (optlen
< sizeof(uint32_t))
1304 return -TARGET_EINVAL
;
1306 if (get_user_u32(val
, optval_addr
))
1307 return -TARGET_EFAULT
;
1308 ret
= get_errno(setsockopt(sockfd
, SOL_SOCKET
, optname
, &val
, sizeof(val
)));
1312 gemu_log("Unsupported setsockopt level=%d optname=%d \n", level
, optname
);
1313 ret
= -TARGET_ENOPROTOOPT
;
1318 /* do_getsockopt() Must return target values and target errnos. */
1319 static abi_long
do_getsockopt(int sockfd
, int level
, int optname
,
1320 abi_ulong optval_addr
, abi_ulong optlen
)
1327 case TARGET_SOL_SOCKET
:
1330 case TARGET_SO_LINGER
:
1331 case TARGET_SO_RCVTIMEO
:
1332 case TARGET_SO_SNDTIMEO
:
1333 case TARGET_SO_PEERCRED
:
1334 case TARGET_SO_PEERNAME
:
1335 /* These don't just return a single integer */
1342 /* TCP options all take an 'int' value. */
1344 if (get_user_u32(len
, optlen
))
1345 return -TARGET_EFAULT
;
1347 return -TARGET_EINVAL
;
1349 ret
= get_errno(getsockopt(sockfd
, level
, optname
, &val
, &lv
));
1355 if (put_user_u32(val
, optval_addr
))
1356 return -TARGET_EFAULT
;
1358 if (put_user_u8(val
, optval_addr
))
1359 return -TARGET_EFAULT
;
1361 if (put_user_u32(len
, optlen
))
1362 return -TARGET_EFAULT
;
1369 case IP_ROUTER_ALERT
:
1373 case IP_MTU_DISCOVER
:
1379 case IP_MULTICAST_TTL
:
1380 case IP_MULTICAST_LOOP
:
1381 if (get_user_u32(len
, optlen
))
1382 return -TARGET_EFAULT
;
1384 return -TARGET_EINVAL
;
1386 ret
= get_errno(getsockopt(sockfd
, level
, optname
, &val
, &lv
));
1389 if (len
< sizeof(int) && len
> 0 && val
>= 0 && val
< 255) {
1391 if (put_user_u32(len
, optlen
)
1392 || put_user_u8(val
, optval_addr
))
1393 return -TARGET_EFAULT
;
1395 if (len
> sizeof(int))
1397 if (put_user_u32(len
, optlen
)
1398 || put_user_u32(val
, optval_addr
))
1399 return -TARGET_EFAULT
;
1403 ret
= -TARGET_ENOPROTOOPT
;
1409 gemu_log("getsockopt level=%d optname=%d not yet supported\n",
1411 ret
= -TARGET_EOPNOTSUPP
;
1418 * lock_iovec()/unlock_iovec() have a return code of 0 for success where
1419 * other lock functions have a return code of 0 for failure.
1421 static abi_long
lock_iovec(int type
, struct iovec
*vec
, abi_ulong target_addr
,
1422 int count
, int copy
)
1424 struct target_iovec
*target_vec
;
1428 target_vec
= lock_user(VERIFY_READ
, target_addr
, count
* sizeof(struct target_iovec
), 1);
1430 return -TARGET_EFAULT
;
1431 for(i
= 0;i
< count
; i
++) {
1432 base
= tswapl(target_vec
[i
].iov_base
);
1433 vec
[i
].iov_len
= tswapl(target_vec
[i
].iov_len
);
1434 if (vec
[i
].iov_len
!= 0) {
1435 vec
[i
].iov_base
= lock_user(type
, base
, vec
[i
].iov_len
, copy
);
1436 /* Don't check lock_user return value. We must call writev even
1437 if a element has invalid base address. */
1439 /* zero length pointer is ignored */
1440 vec
[i
].iov_base
= NULL
;
1443 unlock_user (target_vec
, target_addr
, 0);
1447 static abi_long
unlock_iovec(struct iovec
*vec
, abi_ulong target_addr
,
1448 int count
, int copy
)
1450 struct target_iovec
*target_vec
;
1454 target_vec
= lock_user(VERIFY_READ
, target_addr
, count
* sizeof(struct target_iovec
), 1);
1456 return -TARGET_EFAULT
;
1457 for(i
= 0;i
< count
; i
++) {
1458 if (target_vec
[i
].iov_base
) {
1459 base
= tswapl(target_vec
[i
].iov_base
);
1460 unlock_user(vec
[i
].iov_base
, base
, copy
? vec
[i
].iov_len
: 0);
1463 unlock_user (target_vec
, target_addr
, 0);
1468 /* do_socket() Must return target values and target errnos. */
1469 static abi_long
do_socket(int domain
, int type
, int protocol
)
1471 #if defined(TARGET_MIPS)
1473 case TARGET_SOCK_DGRAM
:
1476 case TARGET_SOCK_STREAM
:
1479 case TARGET_SOCK_RAW
:
1482 case TARGET_SOCK_RDM
:
1485 case TARGET_SOCK_SEQPACKET
:
1486 type
= SOCK_SEQPACKET
;
1488 case TARGET_SOCK_PACKET
:
1493 if (domain
== PF_NETLINK
)
1494 return -EAFNOSUPPORT
; /* do not NETLINK socket connections possible */
1495 return get_errno(socket(domain
, type
, protocol
));
1498 /* do_bind() Must return target values and target errnos. */
1499 static abi_long
do_bind(int sockfd
, abi_ulong target_addr
,
1506 return -TARGET_EINVAL
;
1508 addr
= alloca(addrlen
+1);
1510 ret
= target_to_host_sockaddr(addr
, target_addr
, addrlen
);
1514 return get_errno(bind(sockfd
, addr
, addrlen
));
1517 /* do_connect() Must return target values and target errnos. */
1518 static abi_long
do_connect(int sockfd
, abi_ulong target_addr
,
1525 return -TARGET_EINVAL
;
1527 addr
= alloca(addrlen
);
1529 ret
= target_to_host_sockaddr(addr
, target_addr
, addrlen
);
1533 return get_errno(connect(sockfd
, addr
, addrlen
));
1536 /* do_sendrecvmsg() Must return target values and target errnos. */
1537 static abi_long
do_sendrecvmsg(int fd
, abi_ulong target_msg
,
1538 int flags
, int send
)
1541 struct target_msghdr
*msgp
;
1545 abi_ulong target_vec
;
1548 if (!lock_user_struct(send
? VERIFY_READ
: VERIFY_WRITE
,
1552 return -TARGET_EFAULT
;
1553 if (msgp
->msg_name
) {
1554 msg
.msg_namelen
= tswap32(msgp
->msg_namelen
);
1555 msg
.msg_name
= alloca(msg
.msg_namelen
);
1556 ret
= target_to_host_sockaddr(msg
.msg_name
, tswapl(msgp
->msg_name
),
1559 unlock_user_struct(msgp
, target_msg
, send
? 0 : 1);
1563 msg
.msg_name
= NULL
;
1564 msg
.msg_namelen
= 0;
1566 msg
.msg_controllen
= 2 * tswapl(msgp
->msg_controllen
);
1567 msg
.msg_control
= alloca(msg
.msg_controllen
);
1568 msg
.msg_flags
= tswap32(msgp
->msg_flags
);
1570 count
= tswapl(msgp
->msg_iovlen
);
1571 vec
= alloca(count
* sizeof(struct iovec
));
1572 target_vec
= tswapl(msgp
->msg_iov
);
1573 lock_iovec(send
? VERIFY_READ
: VERIFY_WRITE
, vec
, target_vec
, count
, send
);
1574 msg
.msg_iovlen
= count
;
1578 ret
= target_to_host_cmsg(&msg
, msgp
);
1580 ret
= get_errno(sendmsg(fd
, &msg
, flags
));
1582 ret
= get_errno(recvmsg(fd
, &msg
, flags
));
1583 if (!is_error(ret
)) {
1585 ret
= host_to_target_cmsg(msgp
, &msg
);
1590 unlock_iovec(vec
, target_vec
, count
, !send
);
1591 unlock_user_struct(msgp
, target_msg
, send
? 0 : 1);
1595 /* do_accept() Must return target values and target errnos. */
1596 static abi_long
do_accept(int fd
, abi_ulong target_addr
,
1597 abi_ulong target_addrlen_addr
)
1603 if (target_addr
== 0)
1604 return get_errno(accept(fd
, NULL
, NULL
));
1606 /* linux returns EINVAL if addrlen pointer is invalid */
1607 if (get_user_u32(addrlen
, target_addrlen_addr
))
1608 return -TARGET_EINVAL
;
1611 return -TARGET_EINVAL
;
1613 if (!access_ok(VERIFY_WRITE
, target_addr
, addrlen
))
1614 return -TARGET_EINVAL
;
1616 addr
= alloca(addrlen
);
1618 ret
= get_errno(accept(fd
, addr
, &addrlen
));
1619 if (!is_error(ret
)) {
1620 host_to_target_sockaddr(target_addr
, addr
, addrlen
);
1621 if (put_user_u32(addrlen
, target_addrlen_addr
))
1622 ret
= -TARGET_EFAULT
;
1627 /* do_getpeername() Must return target values and target errnos. */
1628 static abi_long
do_getpeername(int fd
, abi_ulong target_addr
,
1629 abi_ulong target_addrlen_addr
)
1635 if (get_user_u32(addrlen
, target_addrlen_addr
))
1636 return -TARGET_EFAULT
;
1639 return -TARGET_EINVAL
;
1641 if (!access_ok(VERIFY_WRITE
, target_addr
, addrlen
))
1642 return -TARGET_EFAULT
;
1644 addr
= alloca(addrlen
);
1646 ret
= get_errno(getpeername(fd
, addr
, &addrlen
));
1647 if (!is_error(ret
)) {
1648 host_to_target_sockaddr(target_addr
, addr
, addrlen
);
1649 if (put_user_u32(addrlen
, target_addrlen_addr
))
1650 ret
= -TARGET_EFAULT
;
1655 /* do_getsockname() Must return target values and target errnos. */
1656 static abi_long
do_getsockname(int fd
, abi_ulong target_addr
,
1657 abi_ulong target_addrlen_addr
)
1663 if (get_user_u32(addrlen
, target_addrlen_addr
))
1664 return -TARGET_EFAULT
;
1667 return -TARGET_EINVAL
;
1669 if (!access_ok(VERIFY_WRITE
, target_addr
, addrlen
))
1670 return -TARGET_EFAULT
;
1672 addr
= alloca(addrlen
);
1674 ret
= get_errno(getsockname(fd
, addr
, &addrlen
));
1675 if (!is_error(ret
)) {
1676 host_to_target_sockaddr(target_addr
, addr
, addrlen
);
1677 if (put_user_u32(addrlen
, target_addrlen_addr
))
1678 ret
= -TARGET_EFAULT
;
1683 /* do_socketpair() Must return target values and target errnos. */
1684 static abi_long
do_socketpair(int domain
, int type
, int protocol
,
1685 abi_ulong target_tab_addr
)
1690 ret
= get_errno(socketpair(domain
, type
, protocol
, tab
));
1691 if (!is_error(ret
)) {
1692 if (put_user_s32(tab
[0], target_tab_addr
)
1693 || put_user_s32(tab
[1], target_tab_addr
+ sizeof(tab
[0])))
1694 ret
= -TARGET_EFAULT
;
1699 /* do_sendto() Must return target values and target errnos. */
1700 static abi_long
do_sendto(int fd
, abi_ulong msg
, size_t len
, int flags
,
1701 abi_ulong target_addr
, socklen_t addrlen
)
1708 return -TARGET_EINVAL
;
1710 host_msg
= lock_user(VERIFY_READ
, msg
, len
, 1);
1712 return -TARGET_EFAULT
;
1714 addr
= alloca(addrlen
);
1715 ret
= target_to_host_sockaddr(addr
, target_addr
, addrlen
);
1717 unlock_user(host_msg
, msg
, 0);
1720 ret
= get_errno(sendto(fd
, host_msg
, len
, flags
, addr
, addrlen
));
1722 ret
= get_errno(send(fd
, host_msg
, len
, flags
));
1724 unlock_user(host_msg
, msg
, 0);
1728 /* do_recvfrom() Must return target values and target errnos. */
1729 static abi_long
do_recvfrom(int fd
, abi_ulong msg
, size_t len
, int flags
,
1730 abi_ulong target_addr
,
1731 abi_ulong target_addrlen
)
1738 host_msg
= lock_user(VERIFY_WRITE
, msg
, len
, 0);
1740 return -TARGET_EFAULT
;
1742 if (get_user_u32(addrlen
, target_addrlen
)) {
1743 ret
= -TARGET_EFAULT
;
1747 ret
= -TARGET_EINVAL
;
1750 addr
= alloca(addrlen
);
1751 ret
= get_errno(recvfrom(fd
, host_msg
, len
, flags
, addr
, &addrlen
));
1753 addr
= NULL
; /* To keep compiler quiet. */
1754 ret
= get_errno(recv(fd
, host_msg
, len
, flags
));
1756 if (!is_error(ret
)) {
1758 host_to_target_sockaddr(target_addr
, addr
, addrlen
);
1759 if (put_user_u32(addrlen
, target_addrlen
)) {
1760 ret
= -TARGET_EFAULT
;
1764 unlock_user(host_msg
, msg
, len
);
1767 unlock_user(host_msg
, msg
, 0);
1772 #ifdef TARGET_NR_socketcall
1773 /* do_socketcall() Must return target values and target errnos. */
1774 static abi_long
do_socketcall(int num
, abi_ulong vptr
)
1777 const int n
= sizeof(abi_ulong
);
1782 abi_ulong domain
, type
, protocol
;
1784 if (get_user_ual(domain
, vptr
)
1785 || get_user_ual(type
, vptr
+ n
)
1786 || get_user_ual(protocol
, vptr
+ 2 * n
))
1787 return -TARGET_EFAULT
;
1789 ret
= do_socket(domain
, type
, protocol
);
1795 abi_ulong target_addr
;
1798 if (get_user_ual(sockfd
, vptr
)
1799 || get_user_ual(target_addr
, vptr
+ n
)
1800 || get_user_ual(addrlen
, vptr
+ 2 * n
))
1801 return -TARGET_EFAULT
;
1803 ret
= do_bind(sockfd
, target_addr
, addrlen
);
1806 case SOCKOP_connect
:
1809 abi_ulong target_addr
;
1812 if (get_user_ual(sockfd
, vptr
)
1813 || get_user_ual(target_addr
, vptr
+ n
)
1814 || get_user_ual(addrlen
, vptr
+ 2 * n
))
1815 return -TARGET_EFAULT
;
1817 ret
= do_connect(sockfd
, target_addr
, addrlen
);
1822 abi_ulong sockfd
, backlog
;
1824 if (get_user_ual(sockfd
, vptr
)
1825 || get_user_ual(backlog
, vptr
+ n
))
1826 return -TARGET_EFAULT
;
1828 ret
= get_errno(listen(sockfd
, backlog
));
1834 abi_ulong target_addr
, target_addrlen
;
1836 if (get_user_ual(sockfd
, vptr
)
1837 || get_user_ual(target_addr
, vptr
+ n
)
1838 || get_user_ual(target_addrlen
, vptr
+ 2 * n
))
1839 return -TARGET_EFAULT
;
1841 ret
= do_accept(sockfd
, target_addr
, target_addrlen
);
1844 case SOCKOP_getsockname
:
1847 abi_ulong target_addr
, target_addrlen
;
1849 if (get_user_ual(sockfd
, vptr
)
1850 || get_user_ual(target_addr
, vptr
+ n
)
1851 || get_user_ual(target_addrlen
, vptr
+ 2 * n
))
1852 return -TARGET_EFAULT
;
1854 ret
= do_getsockname(sockfd
, target_addr
, target_addrlen
);
1857 case SOCKOP_getpeername
:
1860 abi_ulong target_addr
, target_addrlen
;
1862 if (get_user_ual(sockfd
, vptr
)
1863 || get_user_ual(target_addr
, vptr
+ n
)
1864 || get_user_ual(target_addrlen
, vptr
+ 2 * n
))
1865 return -TARGET_EFAULT
;
1867 ret
= do_getpeername(sockfd
, target_addr
, target_addrlen
);
1870 case SOCKOP_socketpair
:
1872 abi_ulong domain
, type
, protocol
;
1875 if (get_user_ual(domain
, vptr
)
1876 || get_user_ual(type
, vptr
+ n
)
1877 || get_user_ual(protocol
, vptr
+ 2 * n
)
1878 || get_user_ual(tab
, vptr
+ 3 * n
))
1879 return -TARGET_EFAULT
;
1881 ret
= do_socketpair(domain
, type
, protocol
, tab
);
1891 if (get_user_ual(sockfd
, vptr
)
1892 || get_user_ual(msg
, vptr
+ n
)
1893 || get_user_ual(len
, vptr
+ 2 * n
)
1894 || get_user_ual(flags
, vptr
+ 3 * n
))
1895 return -TARGET_EFAULT
;
1897 ret
= do_sendto(sockfd
, msg
, len
, flags
, 0, 0);
1907 if (get_user_ual(sockfd
, vptr
)
1908 || get_user_ual(msg
, vptr
+ n
)
1909 || get_user_ual(len
, vptr
+ 2 * n
)
1910 || get_user_ual(flags
, vptr
+ 3 * n
))
1911 return -TARGET_EFAULT
;
1913 ret
= do_recvfrom(sockfd
, msg
, len
, flags
, 0, 0);
1925 if (get_user_ual(sockfd
, vptr
)
1926 || get_user_ual(msg
, vptr
+ n
)
1927 || get_user_ual(len
, vptr
+ 2 * n
)
1928 || get_user_ual(flags
, vptr
+ 3 * n
)
1929 || get_user_ual(addr
, vptr
+ 4 * n
)
1930 || get_user_ual(addrlen
, vptr
+ 5 * n
))
1931 return -TARGET_EFAULT
;
1933 ret
= do_sendto(sockfd
, msg
, len
, flags
, addr
, addrlen
);
1936 case SOCKOP_recvfrom
:
1945 if (get_user_ual(sockfd
, vptr
)
1946 || get_user_ual(msg
, vptr
+ n
)
1947 || get_user_ual(len
, vptr
+ 2 * n
)
1948 || get_user_ual(flags
, vptr
+ 3 * n
)
1949 || get_user_ual(addr
, vptr
+ 4 * n
)
1950 || get_user_ual(addrlen
, vptr
+ 5 * n
))
1951 return -TARGET_EFAULT
;
1953 ret
= do_recvfrom(sockfd
, msg
, len
, flags
, addr
, addrlen
);
1956 case SOCKOP_shutdown
:
1958 abi_ulong sockfd
, how
;
1960 if (get_user_ual(sockfd
, vptr
)
1961 || get_user_ual(how
, vptr
+ n
))
1962 return -TARGET_EFAULT
;
1964 ret
= get_errno(shutdown(sockfd
, how
));
1967 case SOCKOP_sendmsg
:
1968 case SOCKOP_recvmsg
:
1971 abi_ulong target_msg
;
1974 if (get_user_ual(fd
, vptr
)
1975 || get_user_ual(target_msg
, vptr
+ n
)
1976 || get_user_ual(flags
, vptr
+ 2 * n
))
1977 return -TARGET_EFAULT
;
1979 ret
= do_sendrecvmsg(fd
, target_msg
, flags
,
1980 (num
== SOCKOP_sendmsg
));
1983 case SOCKOP_setsockopt
:
1991 if (get_user_ual(sockfd
, vptr
)
1992 || get_user_ual(level
, vptr
+ n
)
1993 || get_user_ual(optname
, vptr
+ 2 * n
)
1994 || get_user_ual(optval
, vptr
+ 3 * n
)
1995 || get_user_ual(optlen
, vptr
+ 4 * n
))
1996 return -TARGET_EFAULT
;
1998 ret
= do_setsockopt(sockfd
, level
, optname
, optval
, optlen
);
2001 case SOCKOP_getsockopt
:
2009 if (get_user_ual(sockfd
, vptr
)
2010 || get_user_ual(level
, vptr
+ n
)
2011 || get_user_ual(optname
, vptr
+ 2 * n
)
2012 || get_user_ual(optval
, vptr
+ 3 * n
)
2013 || get_user_ual(optlen
, vptr
+ 4 * n
))
2014 return -TARGET_EFAULT
;
2016 ret
= do_getsockopt(sockfd
, level
, optname
, optval
, optlen
);
2020 gemu_log("Unsupported socketcall: %d\n", num
);
2021 ret
= -TARGET_ENOSYS
;
2028 #define N_SHM_REGIONS 32
2030 static struct shm_region
{
2033 } shm_regions
[N_SHM_REGIONS
];
2035 struct target_ipc_perm
2042 unsigned short int mode
;
2043 unsigned short int __pad1
;
2044 unsigned short int __seq
;
2045 unsigned short int __pad2
;
2046 abi_ulong __unused1
;
2047 abi_ulong __unused2
;
2050 struct target_semid_ds
2052 struct target_ipc_perm sem_perm
;
2053 abi_ulong sem_otime
;
2054 abi_ulong __unused1
;
2055 abi_ulong sem_ctime
;
2056 abi_ulong __unused2
;
2057 abi_ulong sem_nsems
;
2058 abi_ulong __unused3
;
2059 abi_ulong __unused4
;
2062 static inline abi_long
target_to_host_ipc_perm(struct ipc_perm
*host_ip
,
2063 abi_ulong target_addr
)
2065 struct target_ipc_perm
*target_ip
;
2066 struct target_semid_ds
*target_sd
;
2068 if (!lock_user_struct(VERIFY_READ
, target_sd
, target_addr
, 1))
2069 return -TARGET_EFAULT
;
2070 target_ip
=&(target_sd
->sem_perm
);
2071 host_ip
->__key
= tswapl(target_ip
->__key
);
2072 host_ip
->uid
= tswapl(target_ip
->uid
);
2073 host_ip
->gid
= tswapl(target_ip
->gid
);
2074 host_ip
->cuid
= tswapl(target_ip
->cuid
);
2075 host_ip
->cgid
= tswapl(target_ip
->cgid
);
2076 host_ip
->mode
= tswapl(target_ip
->mode
);
2077 unlock_user_struct(target_sd
, target_addr
, 0);
2081 static inline abi_long
host_to_target_ipc_perm(abi_ulong target_addr
,
2082 struct ipc_perm
*host_ip
)
2084 struct target_ipc_perm
*target_ip
;
2085 struct target_semid_ds
*target_sd
;
2087 if (!lock_user_struct(VERIFY_WRITE
, target_sd
, target_addr
, 0))
2088 return -TARGET_EFAULT
;
2089 target_ip
= &(target_sd
->sem_perm
);
2090 target_ip
->__key
= tswapl(host_ip
->__key
);
2091 target_ip
->uid
= tswapl(host_ip
->uid
);
2092 target_ip
->gid
= tswapl(host_ip
->gid
);
2093 target_ip
->cuid
= tswapl(host_ip
->cuid
);
2094 target_ip
->cgid
= tswapl(host_ip
->cgid
);
2095 target_ip
->mode
= tswapl(host_ip
->mode
);
2096 unlock_user_struct(target_sd
, target_addr
, 1);
2100 static inline abi_long
target_to_host_semid_ds(struct semid_ds
*host_sd
,
2101 abi_ulong target_addr
)
2103 struct target_semid_ds
*target_sd
;
2105 if (!lock_user_struct(VERIFY_READ
, target_sd
, target_addr
, 1))
2106 return -TARGET_EFAULT
;
2107 if (target_to_host_ipc_perm(&(host_sd
->sem_perm
),target_addr
))
2108 return -TARGET_EFAULT
;
2109 host_sd
->sem_nsems
= tswapl(target_sd
->sem_nsems
);
2110 host_sd
->sem_otime
= tswapl(target_sd
->sem_otime
);
2111 host_sd
->sem_ctime
= tswapl(target_sd
->sem_ctime
);
2112 unlock_user_struct(target_sd
, target_addr
, 0);
2116 static inline abi_long
host_to_target_semid_ds(abi_ulong target_addr
,
2117 struct semid_ds
*host_sd
)
2119 struct target_semid_ds
*target_sd
;
2121 if (!lock_user_struct(VERIFY_WRITE
, target_sd
, target_addr
, 0))
2122 return -TARGET_EFAULT
;
2123 if (host_to_target_ipc_perm(target_addr
,&(host_sd
->sem_perm
)))
2124 return -TARGET_EFAULT
;;
2125 target_sd
->sem_nsems
= tswapl(host_sd
->sem_nsems
);
2126 target_sd
->sem_otime
= tswapl(host_sd
->sem_otime
);
2127 target_sd
->sem_ctime
= tswapl(host_sd
->sem_ctime
);
2128 unlock_user_struct(target_sd
, target_addr
, 1);
2132 struct target_seminfo
{
2145 static inline abi_long
host_to_target_seminfo(abi_ulong target_addr
,
2146 struct seminfo
*host_seminfo
)
2148 struct target_seminfo
*target_seminfo
;
2149 if (!lock_user_struct(VERIFY_WRITE
, target_seminfo
, target_addr
, 0))
2150 return -TARGET_EFAULT
;
2151 __put_user(host_seminfo
->semmap
, &target_seminfo
->semmap
);
2152 __put_user(host_seminfo
->semmni
, &target_seminfo
->semmni
);
2153 __put_user(host_seminfo
->semmns
, &target_seminfo
->semmns
);
2154 __put_user(host_seminfo
->semmnu
, &target_seminfo
->semmnu
);
2155 __put_user(host_seminfo
->semmsl
, &target_seminfo
->semmsl
);
2156 __put_user(host_seminfo
->semopm
, &target_seminfo
->semopm
);
2157 __put_user(host_seminfo
->semume
, &target_seminfo
->semume
);
2158 __put_user(host_seminfo
->semusz
, &target_seminfo
->semusz
);
2159 __put_user(host_seminfo
->semvmx
, &target_seminfo
->semvmx
);
2160 __put_user(host_seminfo
->semaem
, &target_seminfo
->semaem
);
2161 unlock_user_struct(target_seminfo
, target_addr
, 1);
2167 struct semid_ds
*buf
;
2168 unsigned short *array
;
2169 struct seminfo
*__buf
;
2172 union target_semun
{
2179 static inline abi_long
target_to_host_semarray(int semid
, unsigned short **host_array
,
2180 abi_ulong target_addr
)
2183 unsigned short *array
;
2185 struct semid_ds semid_ds
;
2188 semun
.buf
= &semid_ds
;
2190 ret
= semctl(semid
, 0, IPC_STAT
, semun
);
2192 return get_errno(ret
);
2194 nsems
= semid_ds
.sem_nsems
;
2196 *host_array
= malloc(nsems
*sizeof(unsigned short));
2197 array
= lock_user(VERIFY_READ
, target_addr
,
2198 nsems
*sizeof(unsigned short), 1);
2200 return -TARGET_EFAULT
;
2202 for(i
=0; i
<nsems
; i
++) {
2203 __get_user((*host_array
)[i
], &array
[i
]);
2205 unlock_user(array
, target_addr
, 0);
2210 static inline abi_long
host_to_target_semarray(int semid
, abi_ulong target_addr
,
2211 unsigned short **host_array
)
2214 unsigned short *array
;
2216 struct semid_ds semid_ds
;
2219 semun
.buf
= &semid_ds
;
2221 ret
= semctl(semid
, 0, IPC_STAT
, semun
);
2223 return get_errno(ret
);
2225 nsems
= semid_ds
.sem_nsems
;
2227 array
= lock_user(VERIFY_WRITE
, target_addr
,
2228 nsems
*sizeof(unsigned short), 0);
2230 return -TARGET_EFAULT
;
2232 for(i
=0; i
<nsems
; i
++) {
2233 __put_user((*host_array
)[i
], &array
[i
]);
2236 unlock_user(array
, target_addr
, 1);
2241 static inline abi_long
do_semctl(int semid
, int semnum
, int cmd
,
2242 union target_semun target_su
)
2245 struct semid_ds dsarg
;
2246 unsigned short *array
= NULL
;
2247 struct seminfo seminfo
;
2248 abi_long ret
= -TARGET_EINVAL
;
2255 arg
.val
= tswapl(target_su
.val
);
2256 ret
= get_errno(semctl(semid
, semnum
, cmd
, arg
));
2257 target_su
.val
= tswapl(arg
.val
);
2261 err
= target_to_host_semarray(semid
, &array
, target_su
.array
);
2265 ret
= get_errno(semctl(semid
, semnum
, cmd
, arg
));
2266 err
= host_to_target_semarray(semid
, target_su
.array
, &array
);
2273 err
= target_to_host_semid_ds(&dsarg
, target_su
.buf
);
2277 ret
= get_errno(semctl(semid
, semnum
, cmd
, arg
));
2278 err
= host_to_target_semid_ds(target_su
.buf
, &dsarg
);
2284 arg
.__buf
= &seminfo
;
2285 ret
= get_errno(semctl(semid
, semnum
, cmd
, arg
));
2286 err
= host_to_target_seminfo(target_su
.__buf
, &seminfo
);
2294 ret
= get_errno(semctl(semid
, semnum
, cmd
, NULL
));
2301 struct target_sembuf
{
2302 unsigned short sem_num
;
2307 static inline abi_long
target_to_host_sembuf(struct sembuf
*host_sembuf
,
2308 abi_ulong target_addr
,
2311 struct target_sembuf
*target_sembuf
;
2314 target_sembuf
= lock_user(VERIFY_READ
, target_addr
,
2315 nsops
*sizeof(struct target_sembuf
), 1);
2317 return -TARGET_EFAULT
;
2319 for(i
=0; i
<nsops
; i
++) {
2320 __get_user(host_sembuf
[i
].sem_num
, &target_sembuf
[i
].sem_num
);
2321 __get_user(host_sembuf
[i
].sem_op
, &target_sembuf
[i
].sem_op
);
2322 __get_user(host_sembuf
[i
].sem_flg
, &target_sembuf
[i
].sem_flg
);
2325 unlock_user(target_sembuf
, target_addr
, 0);
2330 static inline abi_long
do_semop(int semid
, abi_long ptr
, unsigned nsops
)
2332 struct sembuf sops
[nsops
];
2334 if (target_to_host_sembuf(sops
, ptr
, nsops
))
2335 return -TARGET_EFAULT
;
2337 return semop(semid
, sops
, nsops
);
2340 struct target_msqid_ds
2342 struct target_ipc_perm msg_perm
;
2343 abi_ulong msg_stime
;
2344 #if TARGET_ABI_BITS == 32
2345 abi_ulong __unused1
;
2347 abi_ulong msg_rtime
;
2348 #if TARGET_ABI_BITS == 32
2349 abi_ulong __unused2
;
2351 abi_ulong msg_ctime
;
2352 #if TARGET_ABI_BITS == 32
2353 abi_ulong __unused3
;
2355 abi_ulong __msg_cbytes
;
2357 abi_ulong msg_qbytes
;
2358 abi_ulong msg_lspid
;
2359 abi_ulong msg_lrpid
;
2360 abi_ulong __unused4
;
2361 abi_ulong __unused5
;
2364 static inline abi_long
target_to_host_msqid_ds(struct msqid_ds
*host_md
,
2365 abi_ulong target_addr
)
2367 struct target_msqid_ds
*target_md
;
2369 if (!lock_user_struct(VERIFY_READ
, target_md
, target_addr
, 1))
2370 return -TARGET_EFAULT
;
2371 if (target_to_host_ipc_perm(&(host_md
->msg_perm
),target_addr
))
2372 return -TARGET_EFAULT
;
2373 host_md
->msg_stime
= tswapl(target_md
->msg_stime
);
2374 host_md
->msg_rtime
= tswapl(target_md
->msg_rtime
);
2375 host_md
->msg_ctime
= tswapl(target_md
->msg_ctime
);
2376 host_md
->__msg_cbytes
= tswapl(target_md
->__msg_cbytes
);
2377 host_md
->msg_qnum
= tswapl(target_md
->msg_qnum
);
2378 host_md
->msg_qbytes
= tswapl(target_md
->msg_qbytes
);
2379 host_md
->msg_lspid
= tswapl(target_md
->msg_lspid
);
2380 host_md
->msg_lrpid
= tswapl(target_md
->msg_lrpid
);
2381 unlock_user_struct(target_md
, target_addr
, 0);
2385 static inline abi_long
host_to_target_msqid_ds(abi_ulong target_addr
,
2386 struct msqid_ds
*host_md
)
2388 struct target_msqid_ds
*target_md
;
2390 if (!lock_user_struct(VERIFY_WRITE
, target_md
, target_addr
, 0))
2391 return -TARGET_EFAULT
;
2392 if (host_to_target_ipc_perm(target_addr
,&(host_md
->msg_perm
)))
2393 return -TARGET_EFAULT
;
2394 target_md
->msg_stime
= tswapl(host_md
->msg_stime
);
2395 target_md
->msg_rtime
= tswapl(host_md
->msg_rtime
);
2396 target_md
->msg_ctime
= tswapl(host_md
->msg_ctime
);
2397 target_md
->__msg_cbytes
= tswapl(host_md
->__msg_cbytes
);
2398 target_md
->msg_qnum
= tswapl(host_md
->msg_qnum
);
2399 target_md
->msg_qbytes
= tswapl(host_md
->msg_qbytes
);
2400 target_md
->msg_lspid
= tswapl(host_md
->msg_lspid
);
2401 target_md
->msg_lrpid
= tswapl(host_md
->msg_lrpid
);
2402 unlock_user_struct(target_md
, target_addr
, 1);
2406 struct target_msginfo
{
2414 unsigned short int msgseg
;
2417 static inline abi_long
host_to_target_msginfo(abi_ulong target_addr
,
2418 struct msginfo
*host_msginfo
)
2420 struct target_msginfo
*target_msginfo
;
2421 if (!lock_user_struct(VERIFY_WRITE
, target_msginfo
, target_addr
, 0))
2422 return -TARGET_EFAULT
;
2423 __put_user(host_msginfo
->msgpool
, &target_msginfo
->msgpool
);
2424 __put_user(host_msginfo
->msgmap
, &target_msginfo
->msgmap
);
2425 __put_user(host_msginfo
->msgmax
, &target_msginfo
->msgmax
);
2426 __put_user(host_msginfo
->msgmnb
, &target_msginfo
->msgmnb
);
2427 __put_user(host_msginfo
->msgmni
, &target_msginfo
->msgmni
);
2428 __put_user(host_msginfo
->msgssz
, &target_msginfo
->msgssz
);
2429 __put_user(host_msginfo
->msgtql
, &target_msginfo
->msgtql
);
2430 __put_user(host_msginfo
->msgseg
, &target_msginfo
->msgseg
);
2431 unlock_user_struct(target_msginfo
, target_addr
, 1);
2435 static inline abi_long
do_msgctl(int msgid
, int cmd
, abi_long ptr
)
2437 struct msqid_ds dsarg
;
2438 struct msginfo msginfo
;
2439 abi_long ret
= -TARGET_EINVAL
;
2447 if (target_to_host_msqid_ds(&dsarg
,ptr
))
2448 return -TARGET_EFAULT
;
2449 ret
= get_errno(msgctl(msgid
, cmd
, &dsarg
));
2450 if (host_to_target_msqid_ds(ptr
,&dsarg
))
2451 return -TARGET_EFAULT
;
2454 ret
= get_errno(msgctl(msgid
, cmd
, NULL
));
2458 ret
= get_errno(msgctl(msgid
, cmd
, (struct msqid_ds
*)&msginfo
));
2459 if (host_to_target_msginfo(ptr
, &msginfo
))
2460 return -TARGET_EFAULT
;
2467 struct target_msgbuf
{
2472 static inline abi_long
do_msgsnd(int msqid
, abi_long msgp
,
2473 unsigned int msgsz
, int msgflg
)
2475 struct target_msgbuf
*target_mb
;
2476 struct msgbuf
*host_mb
;
2479 if (!lock_user_struct(VERIFY_READ
, target_mb
, msgp
, 0))
2480 return -TARGET_EFAULT
;
2481 host_mb
= malloc(msgsz
+sizeof(long));
2482 host_mb
->mtype
= (abi_long
) tswapl(target_mb
->mtype
);
2483 memcpy(host_mb
->mtext
, target_mb
->mtext
, msgsz
);
2484 ret
= get_errno(msgsnd(msqid
, host_mb
, msgsz
, msgflg
));
2486 unlock_user_struct(target_mb
, msgp
, 0);
2491 static inline abi_long
do_msgrcv(int msqid
, abi_long msgp
,
2492 unsigned int msgsz
, abi_long msgtyp
,
2495 struct target_msgbuf
*target_mb
;
2497 struct msgbuf
*host_mb
;
2500 if (!lock_user_struct(VERIFY_WRITE
, target_mb
, msgp
, 0))
2501 return -TARGET_EFAULT
;
2503 host_mb
= malloc(msgsz
+sizeof(long));
2504 ret
= get_errno(msgrcv(msqid
, host_mb
, msgsz
, tswapl(msgtyp
), msgflg
));
2507 abi_ulong target_mtext_addr
= msgp
+ sizeof(abi_ulong
);
2508 target_mtext
= lock_user(VERIFY_WRITE
, target_mtext_addr
, ret
, 0);
2509 if (!target_mtext
) {
2510 ret
= -TARGET_EFAULT
;
2513 memcpy(target_mb
->mtext
, host_mb
->mtext
, ret
);
2514 unlock_user(target_mtext
, target_mtext_addr
, ret
);
2517 target_mb
->mtype
= tswapl(host_mb
->mtype
);
2522 unlock_user_struct(target_mb
, msgp
, 1);
2526 struct target_shmid_ds
2528 struct target_ipc_perm shm_perm
;
2529 abi_ulong shm_segsz
;
2530 abi_ulong shm_atime
;
2531 #if TARGET_ABI_BITS == 32
2532 abi_ulong __unused1
;
2534 abi_ulong shm_dtime
;
2535 #if TARGET_ABI_BITS == 32
2536 abi_ulong __unused2
;
2538 abi_ulong shm_ctime
;
2539 #if TARGET_ABI_BITS == 32
2540 abi_ulong __unused3
;
2544 abi_ulong shm_nattch
;
2545 unsigned long int __unused4
;
2546 unsigned long int __unused5
;
2549 static inline abi_long
target_to_host_shmid_ds(struct shmid_ds
*host_sd
,
2550 abi_ulong target_addr
)
2552 struct target_shmid_ds
*target_sd
;
2554 if (!lock_user_struct(VERIFY_READ
, target_sd
, target_addr
, 1))
2555 return -TARGET_EFAULT
;
2556 if (target_to_host_ipc_perm(&(host_sd
->shm_perm
), target_addr
))
2557 return -TARGET_EFAULT
;
2558 __get_user(host_sd
->shm_segsz
, &target_sd
->shm_segsz
);
2559 __get_user(host_sd
->shm_atime
, &target_sd
->shm_atime
);
2560 __get_user(host_sd
->shm_dtime
, &target_sd
->shm_dtime
);
2561 __get_user(host_sd
->shm_ctime
, &target_sd
->shm_ctime
);
2562 __get_user(host_sd
->shm_cpid
, &target_sd
->shm_cpid
);
2563 __get_user(host_sd
->shm_lpid
, &target_sd
->shm_lpid
);
2564 __get_user(host_sd
->shm_nattch
, &target_sd
->shm_nattch
);
2565 unlock_user_struct(target_sd
, target_addr
, 0);
2569 static inline abi_long
host_to_target_shmid_ds(abi_ulong target_addr
,
2570 struct shmid_ds
*host_sd
)
2572 struct target_shmid_ds
*target_sd
;
2574 if (!lock_user_struct(VERIFY_WRITE
, target_sd
, target_addr
, 0))
2575 return -TARGET_EFAULT
;
2576 if (host_to_target_ipc_perm(target_addr
, &(host_sd
->shm_perm
)))
2577 return -TARGET_EFAULT
;
2578 __put_user(host_sd
->shm_segsz
, &target_sd
->shm_segsz
);
2579 __put_user(host_sd
->shm_atime
, &target_sd
->shm_atime
);
2580 __put_user(host_sd
->shm_dtime
, &target_sd
->shm_dtime
);
2581 __put_user(host_sd
->shm_ctime
, &target_sd
->shm_ctime
);
2582 __put_user(host_sd
->shm_cpid
, &target_sd
->shm_cpid
);
2583 __put_user(host_sd
->shm_lpid
, &target_sd
->shm_lpid
);
2584 __put_user(host_sd
->shm_nattch
, &target_sd
->shm_nattch
);
2585 unlock_user_struct(target_sd
, target_addr
, 1);
2589 struct target_shminfo
{
2597 static inline abi_long
host_to_target_shminfo(abi_ulong target_addr
,
2598 struct shminfo
*host_shminfo
)
2600 struct target_shminfo
*target_shminfo
;
2601 if (!lock_user_struct(VERIFY_WRITE
, target_shminfo
, target_addr
, 0))
2602 return -TARGET_EFAULT
;
2603 __put_user(host_shminfo
->shmmax
, &target_shminfo
->shmmax
);
2604 __put_user(host_shminfo
->shmmin
, &target_shminfo
->shmmin
);
2605 __put_user(host_shminfo
->shmmni
, &target_shminfo
->shmmni
);
2606 __put_user(host_shminfo
->shmseg
, &target_shminfo
->shmseg
);
2607 __put_user(host_shminfo
->shmall
, &target_shminfo
->shmall
);
2608 unlock_user_struct(target_shminfo
, target_addr
, 1);
2612 struct target_shm_info
{
2617 abi_ulong swap_attempts
;
2618 abi_ulong swap_successes
;
2621 static inline abi_long
host_to_target_shm_info(abi_ulong target_addr
,
2622 struct shm_info
*host_shm_info
)
2624 struct target_shm_info
*target_shm_info
;
2625 if (!lock_user_struct(VERIFY_WRITE
, target_shm_info
, target_addr
, 0))
2626 return -TARGET_EFAULT
;
2627 __put_user(host_shm_info
->used_ids
, &target_shm_info
->used_ids
);
2628 __put_user(host_shm_info
->shm_tot
, &target_shm_info
->shm_tot
);
2629 __put_user(host_shm_info
->shm_rss
, &target_shm_info
->shm_rss
);
2630 __put_user(host_shm_info
->shm_swp
, &target_shm_info
->shm_swp
);
2631 __put_user(host_shm_info
->swap_attempts
, &target_shm_info
->swap_attempts
);
2632 __put_user(host_shm_info
->swap_successes
, &target_shm_info
->swap_successes
);
2633 unlock_user_struct(target_shm_info
, target_addr
, 1);
2637 static inline abi_long
do_shmctl(int shmid
, int cmd
, abi_long buf
)
2639 struct shmid_ds dsarg
;
2640 struct shminfo shminfo
;
2641 struct shm_info shm_info
;
2642 abi_long ret
= -TARGET_EINVAL
;
2650 if (target_to_host_shmid_ds(&dsarg
, buf
))
2651 return -TARGET_EFAULT
;
2652 ret
= get_errno(shmctl(shmid
, cmd
, &dsarg
));
2653 if (host_to_target_shmid_ds(buf
, &dsarg
))
2654 return -TARGET_EFAULT
;
2657 ret
= get_errno(shmctl(shmid
, cmd
, (struct shmid_ds
*)&shminfo
));
2658 if (host_to_target_shminfo(buf
, &shminfo
))
2659 return -TARGET_EFAULT
;
2662 ret
= get_errno(shmctl(shmid
, cmd
, (struct shmid_ds
*)&shm_info
));
2663 if (host_to_target_shm_info(buf
, &shm_info
))
2664 return -TARGET_EFAULT
;
2669 ret
= get_errno(shmctl(shmid
, cmd
, NULL
));
2676 static inline abi_ulong
do_shmat(int shmid
, abi_ulong shmaddr
, int shmflg
)
2680 struct shmid_ds shm_info
;
2683 /* find out the length of the shared memory segment */
2684 ret
= get_errno(shmctl(shmid
, IPC_STAT
, &shm_info
));
2685 if (is_error(ret
)) {
2686 /* can't get length, bail out */
2693 host_raddr
= shmat(shmid
, (void *)g2h(shmaddr
), shmflg
);
2695 abi_ulong mmap_start
;
2697 mmap_start
= mmap_find_vma(0, shm_info
.shm_segsz
);
2699 if (mmap_start
== -1) {
2701 host_raddr
= (void *)-1;
2703 host_raddr
= shmat(shmid
, g2h(mmap_start
), shmflg
| SHM_REMAP
);
2706 if (host_raddr
== (void *)-1) {
2708 return get_errno((long)host_raddr
);
2710 raddr
=h2g((unsigned long)host_raddr
);
2712 page_set_flags(raddr
, raddr
+ shm_info
.shm_segsz
,
2713 PAGE_VALID
| PAGE_READ
|
2714 ((shmflg
& SHM_RDONLY
)? 0 : PAGE_WRITE
));
2716 for (i
= 0; i
< N_SHM_REGIONS
; i
++) {
2717 if (shm_regions
[i
].start
== 0) {
2718 shm_regions
[i
].start
= raddr
;
2719 shm_regions
[i
].size
= shm_info
.shm_segsz
;
2729 static inline abi_long
do_shmdt(abi_ulong shmaddr
)
2733 for (i
= 0; i
< N_SHM_REGIONS
; ++i
) {
2734 if (shm_regions
[i
].start
== shmaddr
) {
2735 shm_regions
[i
].start
= 0;
2736 page_set_flags(shmaddr
, shm_regions
[i
].size
, 0);
2741 return get_errno(shmdt(g2h(shmaddr
)));
2744 #ifdef TARGET_NR_ipc
2745 /* ??? This only works with linear mappings. */
2746 /* do_ipc() must return target values and target errnos. */
2747 static abi_long
do_ipc(unsigned int call
, int first
,
2748 int second
, int third
,
2749 abi_long ptr
, abi_long fifth
)
2754 version
= call
>> 16;
2759 ret
= do_semop(first
, ptr
, second
);
2763 ret
= get_errno(semget(first
, second
, third
));
2767 ret
= do_semctl(first
, second
, third
, (union target_semun
)(abi_ulong
) ptr
);
2771 ret
= get_errno(msgget(first
, second
));
2775 ret
= do_msgsnd(first
, ptr
, second
, third
);
2779 ret
= do_msgctl(first
, second
, ptr
);
2786 struct target_ipc_kludge
{
2791 if (!lock_user_struct(VERIFY_READ
, tmp
, ptr
, 1)) {
2792 ret
= -TARGET_EFAULT
;
2796 ret
= do_msgrcv(first
, tmp
->msgp
, second
, tmp
->msgtyp
, third
);
2798 unlock_user_struct(tmp
, ptr
, 0);
2802 ret
= do_msgrcv(first
, ptr
, second
, fifth
, third
);
2811 raddr
= do_shmat(first
, ptr
, second
);
2812 if (is_error(raddr
))
2813 return get_errno(raddr
);
2814 if (put_user_ual(raddr
, third
))
2815 return -TARGET_EFAULT
;
2819 ret
= -TARGET_EINVAL
;
2824 ret
= do_shmdt(ptr
);
2828 /* IPC_* flag values are the same on all linux platforms */
2829 ret
= get_errno(shmget(first
, second
, third
));
2832 /* IPC_* and SHM_* command values are the same on all linux platforms */
2834 ret
= do_shmctl(first
, second
, third
);
2837 gemu_log("Unsupported ipc call: %d (version %d)\n", call
, version
);
2838 ret
= -TARGET_ENOSYS
;
2845 /* kernel structure types definitions */
2848 #define STRUCT(name, ...) STRUCT_ ## name,
2849 #define STRUCT_SPECIAL(name) STRUCT_ ## name,
2851 #include "syscall_types.h"
2854 #undef STRUCT_SPECIAL
2856 #define STRUCT(name, ...) static const argtype struct_ ## name ## _def[] = { __VA_ARGS__, TYPE_NULL };
2857 #define STRUCT_SPECIAL(name)
2858 #include "syscall_types.h"
2860 #undef STRUCT_SPECIAL
2862 typedef struct IOCTLEntry
{
2863 unsigned int target_cmd
;
2864 unsigned int host_cmd
;
2867 const argtype arg_type
[5];
2870 #define IOC_R 0x0001
2871 #define IOC_W 0x0002
2872 #define IOC_RW (IOC_R | IOC_W)
2874 #define MAX_STRUCT_SIZE 4096
2876 static IOCTLEntry ioctl_entries
[] = {
2877 #define IOCTL(cmd, access, ...) \
2878 { TARGET_ ## cmd, cmd, #cmd, access, { __VA_ARGS__ } },
2883 /* ??? Implement proper locking for ioctls. */
2884 /* do_ioctl() Must return target values and target errnos. */
2885 static abi_long
do_ioctl(int fd
, abi_long cmd
, abi_long arg
)
2887 const IOCTLEntry
*ie
;
2888 const argtype
*arg_type
;
2890 uint8_t buf_temp
[MAX_STRUCT_SIZE
];
2896 if (ie
->target_cmd
== 0) {
2897 gemu_log("Unsupported ioctl: cmd=0x%04lx\n", (long)cmd
);
2898 return -TARGET_ENOSYS
;
2900 if (ie
->target_cmd
== cmd
)
2904 arg_type
= ie
->arg_type
;
2906 gemu_log("ioctl: cmd=0x%04lx (%s)\n", (long)cmd
, ie
->name
);
2908 switch(arg_type
[0]) {
2911 ret
= get_errno(ioctl(fd
, ie
->host_cmd
));
2916 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, arg
));
2920 target_size
= thunk_type_size(arg_type
, 0);
2921 switch(ie
->access
) {
2923 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, buf_temp
));
2924 if (!is_error(ret
)) {
2925 argptr
= lock_user(VERIFY_WRITE
, arg
, target_size
, 0);
2927 return -TARGET_EFAULT
;
2928 thunk_convert(argptr
, buf_temp
, arg_type
, THUNK_TARGET
);
2929 unlock_user(argptr
, arg
, target_size
);
2933 argptr
= lock_user(VERIFY_READ
, arg
, target_size
, 1);
2935 return -TARGET_EFAULT
;
2936 thunk_convert(buf_temp
, argptr
, arg_type
, THUNK_HOST
);
2937 unlock_user(argptr
, arg
, 0);
2938 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, buf_temp
));
2942 argptr
= lock_user(VERIFY_READ
, arg
, target_size
, 1);
2944 return -TARGET_EFAULT
;
2945 thunk_convert(buf_temp
, argptr
, arg_type
, THUNK_HOST
);
2946 unlock_user(argptr
, arg
, 0);
2947 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, buf_temp
));
2948 if (!is_error(ret
)) {
2949 argptr
= lock_user(VERIFY_WRITE
, arg
, target_size
, 0);
2951 return -TARGET_EFAULT
;
2952 thunk_convert(argptr
, buf_temp
, arg_type
, THUNK_TARGET
);
2953 unlock_user(argptr
, arg
, target_size
);
2959 gemu_log("Unsupported ioctl type: cmd=0x%04lx type=%d\n",
2960 (long)cmd
, arg_type
[0]);
2961 ret
= -TARGET_ENOSYS
;
2967 static const bitmask_transtbl iflag_tbl
[] = {
2968 { TARGET_IGNBRK
, TARGET_IGNBRK
, IGNBRK
, IGNBRK
},
2969 { TARGET_BRKINT
, TARGET_BRKINT
, BRKINT
, BRKINT
},
2970 { TARGET_IGNPAR
, TARGET_IGNPAR
, IGNPAR
, IGNPAR
},
2971 { TARGET_PARMRK
, TARGET_PARMRK
, PARMRK
, PARMRK
},
2972 { TARGET_INPCK
, TARGET_INPCK
, INPCK
, INPCK
},
2973 { TARGET_ISTRIP
, TARGET_ISTRIP
, ISTRIP
, ISTRIP
},
2974 { TARGET_INLCR
, TARGET_INLCR
, INLCR
, INLCR
},
2975 { TARGET_IGNCR
, TARGET_IGNCR
, IGNCR
, IGNCR
},
2976 { TARGET_ICRNL
, TARGET_ICRNL
, ICRNL
, ICRNL
},
2977 { TARGET_IUCLC
, TARGET_IUCLC
, IUCLC
, IUCLC
},
2978 { TARGET_IXON
, TARGET_IXON
, IXON
, IXON
},
2979 { TARGET_IXANY
, TARGET_IXANY
, IXANY
, IXANY
},
2980 { TARGET_IXOFF
, TARGET_IXOFF
, IXOFF
, IXOFF
},
2981 { TARGET_IMAXBEL
, TARGET_IMAXBEL
, IMAXBEL
, IMAXBEL
},
2985 static const bitmask_transtbl oflag_tbl
[] = {
2986 { TARGET_OPOST
, TARGET_OPOST
, OPOST
, OPOST
},
2987 { TARGET_OLCUC
, TARGET_OLCUC
, OLCUC
, OLCUC
},
2988 { TARGET_ONLCR
, TARGET_ONLCR
, ONLCR
, ONLCR
},
2989 { TARGET_OCRNL
, TARGET_OCRNL
, OCRNL
, OCRNL
},
2990 { TARGET_ONOCR
, TARGET_ONOCR
, ONOCR
, ONOCR
},
2991 { TARGET_ONLRET
, TARGET_ONLRET
, ONLRET
, ONLRET
},
2992 { TARGET_OFILL
, TARGET_OFILL
, OFILL
, OFILL
},
2993 { TARGET_OFDEL
, TARGET_OFDEL
, OFDEL
, OFDEL
},
2994 { TARGET_NLDLY
, TARGET_NL0
, NLDLY
, NL0
},
2995 { TARGET_NLDLY
, TARGET_NL1
, NLDLY
, NL1
},
2996 { TARGET_CRDLY
, TARGET_CR0
, CRDLY
, CR0
},
2997 { TARGET_CRDLY
, TARGET_CR1
, CRDLY
, CR1
},
2998 { TARGET_CRDLY
, TARGET_CR2
, CRDLY
, CR2
},
2999 { TARGET_CRDLY
, TARGET_CR3
, CRDLY
, CR3
},
3000 { TARGET_TABDLY
, TARGET_TAB0
, TABDLY
, TAB0
},
3001 { TARGET_TABDLY
, TARGET_TAB1
, TABDLY
, TAB1
},
3002 { TARGET_TABDLY
, TARGET_TAB2
, TABDLY
, TAB2
},
3003 { TARGET_TABDLY
, TARGET_TAB3
, TABDLY
, TAB3
},
3004 { TARGET_BSDLY
, TARGET_BS0
, BSDLY
, BS0
},
3005 { TARGET_BSDLY
, TARGET_BS1
, BSDLY
, BS1
},
3006 { TARGET_VTDLY
, TARGET_VT0
, VTDLY
, VT0
},
3007 { TARGET_VTDLY
, TARGET_VT1
, VTDLY
, VT1
},
3008 { TARGET_FFDLY
, TARGET_FF0
, FFDLY
, FF0
},
3009 { TARGET_FFDLY
, TARGET_FF1
, FFDLY
, FF1
},
3013 static const bitmask_transtbl cflag_tbl
[] = {
3014 { TARGET_CBAUD
, TARGET_B0
, CBAUD
, B0
},
3015 { TARGET_CBAUD
, TARGET_B50
, CBAUD
, B50
},
3016 { TARGET_CBAUD
, TARGET_B75
, CBAUD
, B75
},
3017 { TARGET_CBAUD
, TARGET_B110
, CBAUD
, B110
},
3018 { TARGET_CBAUD
, TARGET_B134
, CBAUD
, B134
},
3019 { TARGET_CBAUD
, TARGET_B150
, CBAUD
, B150
},
3020 { TARGET_CBAUD
, TARGET_B200
, CBAUD
, B200
},
3021 { TARGET_CBAUD
, TARGET_B300
, CBAUD
, B300
},
3022 { TARGET_CBAUD
, TARGET_B600
, CBAUD
, B600
},
3023 { TARGET_CBAUD
, TARGET_B1200
, CBAUD
, B1200
},
3024 { TARGET_CBAUD
, TARGET_B1800
, CBAUD
, B1800
},
3025 { TARGET_CBAUD
, TARGET_B2400
, CBAUD
, B2400
},
3026 { TARGET_CBAUD
, TARGET_B4800
, CBAUD
, B4800
},
3027 { TARGET_CBAUD
, TARGET_B9600
, CBAUD
, B9600
},
3028 { TARGET_CBAUD
, TARGET_B19200
, CBAUD
, B19200
},
3029 { TARGET_CBAUD
, TARGET_B38400
, CBAUD
, B38400
},
3030 { TARGET_CBAUD
, TARGET_B57600
, CBAUD
, B57600
},
3031 { TARGET_CBAUD
, TARGET_B115200
, CBAUD
, B115200
},
3032 { TARGET_CBAUD
, TARGET_B230400
, CBAUD
, B230400
},
3033 { TARGET_CBAUD
, TARGET_B460800
, CBAUD
, B460800
},
3034 { TARGET_CSIZE
, TARGET_CS5
, CSIZE
, CS5
},
3035 { TARGET_CSIZE
, TARGET_CS6
, CSIZE
, CS6
},
3036 { TARGET_CSIZE
, TARGET_CS7
, CSIZE
, CS7
},
3037 { TARGET_CSIZE
, TARGET_CS8
, CSIZE
, CS8
},
3038 { TARGET_CSTOPB
, TARGET_CSTOPB
, CSTOPB
, CSTOPB
},
3039 { TARGET_CREAD
, TARGET_CREAD
, CREAD
, CREAD
},
3040 { TARGET_PARENB
, TARGET_PARENB
, PARENB
, PARENB
},
3041 { TARGET_PARODD
, TARGET_PARODD
, PARODD
, PARODD
},
3042 { TARGET_HUPCL
, TARGET_HUPCL
, HUPCL
, HUPCL
},
3043 { TARGET_CLOCAL
, TARGET_CLOCAL
, CLOCAL
, CLOCAL
},
3044 { TARGET_CRTSCTS
, TARGET_CRTSCTS
, CRTSCTS
, CRTSCTS
},
3048 static const bitmask_transtbl lflag_tbl
[] = {
3049 { TARGET_ISIG
, TARGET_ISIG
, ISIG
, ISIG
},
3050 { TARGET_ICANON
, TARGET_ICANON
, ICANON
, ICANON
},
3051 { TARGET_XCASE
, TARGET_XCASE
, XCASE
, XCASE
},
3052 { TARGET_ECHO
, TARGET_ECHO
, ECHO
, ECHO
},
3053 { TARGET_ECHOE
, TARGET_ECHOE
, ECHOE
, ECHOE
},
3054 { TARGET_ECHOK
, TARGET_ECHOK
, ECHOK
, ECHOK
},
3055 { TARGET_ECHONL
, TARGET_ECHONL
, ECHONL
, ECHONL
},
3056 { TARGET_NOFLSH
, TARGET_NOFLSH
, NOFLSH
, NOFLSH
},
3057 { TARGET_TOSTOP
, TARGET_TOSTOP
, TOSTOP
, TOSTOP
},
3058 { TARGET_ECHOCTL
, TARGET_ECHOCTL
, ECHOCTL
, ECHOCTL
},
3059 { TARGET_ECHOPRT
, TARGET_ECHOPRT
, ECHOPRT
, ECHOPRT
},
3060 { TARGET_ECHOKE
, TARGET_ECHOKE
, ECHOKE
, ECHOKE
},
3061 { TARGET_FLUSHO
, TARGET_FLUSHO
, FLUSHO
, FLUSHO
},
3062 { TARGET_PENDIN
, TARGET_PENDIN
, PENDIN
, PENDIN
},
3063 { TARGET_IEXTEN
, TARGET_IEXTEN
, IEXTEN
, IEXTEN
},
3067 static void target_to_host_termios (void *dst
, const void *src
)
3069 struct host_termios
*host
= dst
;
3070 const struct target_termios
*target
= src
;
3073 target_to_host_bitmask(tswap32(target
->c_iflag
), iflag_tbl
);
3075 target_to_host_bitmask(tswap32(target
->c_oflag
), oflag_tbl
);
3077 target_to_host_bitmask(tswap32(target
->c_cflag
), cflag_tbl
);
3079 target_to_host_bitmask(tswap32(target
->c_lflag
), lflag_tbl
);
3080 host
->c_line
= target
->c_line
;
3082 memset(host
->c_cc
, 0, sizeof(host
->c_cc
));
3083 host
->c_cc
[VINTR
] = target
->c_cc
[TARGET_VINTR
];
3084 host
->c_cc
[VQUIT
] = target
->c_cc
[TARGET_VQUIT
];
3085 host
->c_cc
[VERASE
] = target
->c_cc
[TARGET_VERASE
];
3086 host
->c_cc
[VKILL
] = target
->c_cc
[TARGET_VKILL
];
3087 host
->c_cc
[VEOF
] = target
->c_cc
[TARGET_VEOF
];
3088 host
->c_cc
[VTIME
] = target
->c_cc
[TARGET_VTIME
];
3089 host
->c_cc
[VMIN
] = target
->c_cc
[TARGET_VMIN
];
3090 host
->c_cc
[VSWTC
] = target
->c_cc
[TARGET_VSWTC
];
3091 host
->c_cc
[VSTART
] = target
->c_cc
[TARGET_VSTART
];
3092 host
->c_cc
[VSTOP
] = target
->c_cc
[TARGET_VSTOP
];
3093 host
->c_cc
[VSUSP
] = target
->c_cc
[TARGET_VSUSP
];
3094 host
->c_cc
[VEOL
] = target
->c_cc
[TARGET_VEOL
];
3095 host
->c_cc
[VREPRINT
] = target
->c_cc
[TARGET_VREPRINT
];
3096 host
->c_cc
[VDISCARD
] = target
->c_cc
[TARGET_VDISCARD
];
3097 host
->c_cc
[VWERASE
] = target
->c_cc
[TARGET_VWERASE
];
3098 host
->c_cc
[VLNEXT
] = target
->c_cc
[TARGET_VLNEXT
];
3099 host
->c_cc
[VEOL2
] = target
->c_cc
[TARGET_VEOL2
];
3102 static void host_to_target_termios (void *dst
, const void *src
)
3104 struct target_termios
*target
= dst
;
3105 const struct host_termios
*host
= src
;
3108 tswap32(host_to_target_bitmask(host
->c_iflag
, iflag_tbl
));
3110 tswap32(host_to_target_bitmask(host
->c_oflag
, oflag_tbl
));
3112 tswap32(host_to_target_bitmask(host
->c_cflag
, cflag_tbl
));
3114 tswap32(host_to_target_bitmask(host
->c_lflag
, lflag_tbl
));
3115 target
->c_line
= host
->c_line
;
3117 memset(target
->c_cc
, 0, sizeof(target
->c_cc
));
3118 target
->c_cc
[TARGET_VINTR
] = host
->c_cc
[VINTR
];
3119 target
->c_cc
[TARGET_VQUIT
] = host
->c_cc
[VQUIT
];
3120 target
->c_cc
[TARGET_VERASE
] = host
->c_cc
[VERASE
];
3121 target
->c_cc
[TARGET_VKILL
] = host
->c_cc
[VKILL
];
3122 target
->c_cc
[TARGET_VEOF
] = host
->c_cc
[VEOF
];
3123 target
->c_cc
[TARGET_VTIME
] = host
->c_cc
[VTIME
];
3124 target
->c_cc
[TARGET_VMIN
] = host
->c_cc
[VMIN
];
3125 target
->c_cc
[TARGET_VSWTC
] = host
->c_cc
[VSWTC
];
3126 target
->c_cc
[TARGET_VSTART
] = host
->c_cc
[VSTART
];
3127 target
->c_cc
[TARGET_VSTOP
] = host
->c_cc
[VSTOP
];
3128 target
->c_cc
[TARGET_VSUSP
] = host
->c_cc
[VSUSP
];
3129 target
->c_cc
[TARGET_VEOL
] = host
->c_cc
[VEOL
];
3130 target
->c_cc
[TARGET_VREPRINT
] = host
->c_cc
[VREPRINT
];
3131 target
->c_cc
[TARGET_VDISCARD
] = host
->c_cc
[VDISCARD
];
3132 target
->c_cc
[TARGET_VWERASE
] = host
->c_cc
[VWERASE
];
3133 target
->c_cc
[TARGET_VLNEXT
] = host
->c_cc
[VLNEXT
];
3134 target
->c_cc
[TARGET_VEOL2
] = host
->c_cc
[VEOL2
];
3137 static const StructEntry struct_termios_def
= {
3138 .convert
= { host_to_target_termios
, target_to_host_termios
},
3139 .size
= { sizeof(struct target_termios
), sizeof(struct host_termios
) },
3140 .align
= { __alignof__(struct target_termios
), __alignof__(struct host_termios
) },
3143 static bitmask_transtbl mmap_flags_tbl
[] = {
3144 { TARGET_MAP_SHARED
, TARGET_MAP_SHARED
, MAP_SHARED
, MAP_SHARED
},
3145 { TARGET_MAP_PRIVATE
, TARGET_MAP_PRIVATE
, MAP_PRIVATE
, MAP_PRIVATE
},
3146 { TARGET_MAP_FIXED
, TARGET_MAP_FIXED
, MAP_FIXED
, MAP_FIXED
},
3147 { TARGET_MAP_ANONYMOUS
, TARGET_MAP_ANONYMOUS
, MAP_ANONYMOUS
, MAP_ANONYMOUS
},
3148 { TARGET_MAP_GROWSDOWN
, TARGET_MAP_GROWSDOWN
, MAP_GROWSDOWN
, MAP_GROWSDOWN
},
3149 { TARGET_MAP_DENYWRITE
, TARGET_MAP_DENYWRITE
, MAP_DENYWRITE
, MAP_DENYWRITE
},
3150 { TARGET_MAP_EXECUTABLE
, TARGET_MAP_EXECUTABLE
, MAP_EXECUTABLE
, MAP_EXECUTABLE
},
3151 { TARGET_MAP_LOCKED
, TARGET_MAP_LOCKED
, MAP_LOCKED
, MAP_LOCKED
},
3155 #if defined(TARGET_I386)
3157 /* NOTE: there is really one LDT for all the threads */
3158 static uint8_t *ldt_table
;
3160 static abi_long
read_ldt(abi_ulong ptr
, unsigned long bytecount
)
3167 size
= TARGET_LDT_ENTRIES
* TARGET_LDT_ENTRY_SIZE
;
3168 if (size
> bytecount
)
3170 p
= lock_user(VERIFY_WRITE
, ptr
, size
, 0);
3172 return -TARGET_EFAULT
;
3173 /* ??? Should this by byteswapped? */
3174 memcpy(p
, ldt_table
, size
);
3175 unlock_user(p
, ptr
, size
);
3179 /* XXX: add locking support */
3180 static abi_long
write_ldt(CPUX86State
*env
,
3181 abi_ulong ptr
, unsigned long bytecount
, int oldmode
)
3183 struct target_modify_ldt_ldt_s ldt_info
;
3184 struct target_modify_ldt_ldt_s
*target_ldt_info
;
3185 int seg_32bit
, contents
, read_exec_only
, limit_in_pages
;
3186 int seg_not_present
, useable
, lm
;
3187 uint32_t *lp
, entry_1
, entry_2
;
3189 if (bytecount
!= sizeof(ldt_info
))
3190 return -TARGET_EINVAL
;
3191 if (!lock_user_struct(VERIFY_READ
, target_ldt_info
, ptr
, 1))
3192 return -TARGET_EFAULT
;
3193 ldt_info
.entry_number
= tswap32(target_ldt_info
->entry_number
);
3194 ldt_info
.base_addr
= tswapl(target_ldt_info
->base_addr
);
3195 ldt_info
.limit
= tswap32(target_ldt_info
->limit
);
3196 ldt_info
.flags
= tswap32(target_ldt_info
->flags
);
3197 unlock_user_struct(target_ldt_info
, ptr
, 0);
3199 if (ldt_info
.entry_number
>= TARGET_LDT_ENTRIES
)
3200 return -TARGET_EINVAL
;
3201 seg_32bit
= ldt_info
.flags
& 1;
3202 contents
= (ldt_info
.flags
>> 1) & 3;
3203 read_exec_only
= (ldt_info
.flags
>> 3) & 1;
3204 limit_in_pages
= (ldt_info
.flags
>> 4) & 1;
3205 seg_not_present
= (ldt_info
.flags
>> 5) & 1;
3206 useable
= (ldt_info
.flags
>> 6) & 1;
3210 lm
= (ldt_info
.flags
>> 7) & 1;
3212 if (contents
== 3) {
3214 return -TARGET_EINVAL
;
3215 if (seg_not_present
== 0)
3216 return -TARGET_EINVAL
;
3218 /* allocate the LDT */
3220 env
->ldt
.base
= target_mmap(0,
3221 TARGET_LDT_ENTRIES
* TARGET_LDT_ENTRY_SIZE
,
3222 PROT_READ
|PROT_WRITE
,
3223 MAP_ANONYMOUS
|MAP_PRIVATE
, -1, 0);
3224 if (env
->ldt
.base
== -1)
3225 return -TARGET_ENOMEM
;
3226 memset(g2h(env
->ldt
.base
), 0,
3227 TARGET_LDT_ENTRIES
* TARGET_LDT_ENTRY_SIZE
);
3228 env
->ldt
.limit
= 0xffff;
3229 ldt_table
= g2h(env
->ldt
.base
);
3232 /* NOTE: same code as Linux kernel */
3233 /* Allow LDTs to be cleared by the user. */
3234 if (ldt_info
.base_addr
== 0 && ldt_info
.limit
== 0) {
3237 read_exec_only
== 1 &&
3239 limit_in_pages
== 0 &&
3240 seg_not_present
== 1 &&
3248 entry_1
= ((ldt_info
.base_addr
& 0x0000ffff) << 16) |
3249 (ldt_info
.limit
& 0x0ffff);
3250 entry_2
= (ldt_info
.base_addr
& 0xff000000) |
3251 ((ldt_info
.base_addr
& 0x00ff0000) >> 16) |
3252 (ldt_info
.limit
& 0xf0000) |
3253 ((read_exec_only
^ 1) << 9) |
3255 ((seg_not_present
^ 1) << 15) |
3257 (limit_in_pages
<< 23) |
3261 entry_2
|= (useable
<< 20);
3263 /* Install the new entry ... */
3265 lp
= (uint32_t *)(ldt_table
+ (ldt_info
.entry_number
<< 3));
3266 lp
[0] = tswap32(entry_1
);
3267 lp
[1] = tswap32(entry_2
);
3271 /* specific and weird i386 syscalls */
3272 static abi_long
do_modify_ldt(CPUX86State
*env
, int func
, abi_ulong ptr
,
3273 unsigned long bytecount
)
3279 ret
= read_ldt(ptr
, bytecount
);
3282 ret
= write_ldt(env
, ptr
, bytecount
, 1);
3285 ret
= write_ldt(env
, ptr
, bytecount
, 0);
3288 ret
= -TARGET_ENOSYS
;
3294 #if defined(TARGET_I386) && defined(TARGET_ABI32)
3295 static abi_long
do_set_thread_area(CPUX86State
*env
, abi_ulong ptr
)
3297 uint64_t *gdt_table
= g2h(env
->gdt
.base
);
3298 struct target_modify_ldt_ldt_s ldt_info
;
3299 struct target_modify_ldt_ldt_s
*target_ldt_info
;
3300 int seg_32bit
, contents
, read_exec_only
, limit_in_pages
;
3301 int seg_not_present
, useable
, lm
;
3302 uint32_t *lp
, entry_1
, entry_2
;
3305 lock_user_struct(VERIFY_WRITE
, target_ldt_info
, ptr
, 1);
3306 if (!target_ldt_info
)
3307 return -TARGET_EFAULT
;
3308 ldt_info
.entry_number
= tswap32(target_ldt_info
->entry_number
);
3309 ldt_info
.base_addr
= tswapl(target_ldt_info
->base_addr
);
3310 ldt_info
.limit
= tswap32(target_ldt_info
->limit
);
3311 ldt_info
.flags
= tswap32(target_ldt_info
->flags
);
3312 if (ldt_info
.entry_number
== -1) {
3313 for (i
=TARGET_GDT_ENTRY_TLS_MIN
; i
<=TARGET_GDT_ENTRY_TLS_MAX
; i
++) {
3314 if (gdt_table
[i
] == 0) {
3315 ldt_info
.entry_number
= i
;
3316 target_ldt_info
->entry_number
= tswap32(i
);
3321 unlock_user_struct(target_ldt_info
, ptr
, 1);
3323 if (ldt_info
.entry_number
< TARGET_GDT_ENTRY_TLS_MIN
||
3324 ldt_info
.entry_number
> TARGET_GDT_ENTRY_TLS_MAX
)
3325 return -TARGET_EINVAL
;
3326 seg_32bit
= ldt_info
.flags
& 1;
3327 contents
= (ldt_info
.flags
>> 1) & 3;
3328 read_exec_only
= (ldt_info
.flags
>> 3) & 1;
3329 limit_in_pages
= (ldt_info
.flags
>> 4) & 1;
3330 seg_not_present
= (ldt_info
.flags
>> 5) & 1;
3331 useable
= (ldt_info
.flags
>> 6) & 1;
3335 lm
= (ldt_info
.flags
>> 7) & 1;
3338 if (contents
== 3) {
3339 if (seg_not_present
== 0)
3340 return -TARGET_EINVAL
;
3343 /* NOTE: same code as Linux kernel */
3344 /* Allow LDTs to be cleared by the user. */
3345 if (ldt_info
.base_addr
== 0 && ldt_info
.limit
== 0) {
3346 if ((contents
== 0 &&
3347 read_exec_only
== 1 &&
3349 limit_in_pages
== 0 &&
3350 seg_not_present
== 1 &&
3358 entry_1
= ((ldt_info
.base_addr
& 0x0000ffff) << 16) |
3359 (ldt_info
.limit
& 0x0ffff);
3360 entry_2
= (ldt_info
.base_addr
& 0xff000000) |
3361 ((ldt_info
.base_addr
& 0x00ff0000) >> 16) |
3362 (ldt_info
.limit
& 0xf0000) |
3363 ((read_exec_only
^ 1) << 9) |
3365 ((seg_not_present
^ 1) << 15) |
3367 (limit_in_pages
<< 23) |
3372 /* Install the new entry ... */
3374 lp
= (uint32_t *)(gdt_table
+ ldt_info
.entry_number
);
3375 lp
[0] = tswap32(entry_1
);
3376 lp
[1] = tswap32(entry_2
);
3380 static abi_long
do_get_thread_area(CPUX86State
*env
, abi_ulong ptr
)
3382 struct target_modify_ldt_ldt_s
*target_ldt_info
;
3383 uint64_t *gdt_table
= g2h(env
->gdt
.base
);
3384 uint32_t base_addr
, limit
, flags
;
3385 int seg_32bit
, contents
, read_exec_only
, limit_in_pages
, idx
;
3386 int seg_not_present
, useable
, lm
;
3387 uint32_t *lp
, entry_1
, entry_2
;
3389 lock_user_struct(VERIFY_WRITE
, target_ldt_info
, ptr
, 1);
3390 if (!target_ldt_info
)
3391 return -TARGET_EFAULT
;
3392 idx
= tswap32(target_ldt_info
->entry_number
);
3393 if (idx
< TARGET_GDT_ENTRY_TLS_MIN
||
3394 idx
> TARGET_GDT_ENTRY_TLS_MAX
) {
3395 unlock_user_struct(target_ldt_info
, ptr
, 1);
3396 return -TARGET_EINVAL
;
3398 lp
= (uint32_t *)(gdt_table
+ idx
);
3399 entry_1
= tswap32(lp
[0]);
3400 entry_2
= tswap32(lp
[1]);
3402 read_exec_only
= ((entry_2
>> 9) & 1) ^ 1;
3403 contents
= (entry_2
>> 10) & 3;
3404 seg_not_present
= ((entry_2
>> 15) & 1) ^ 1;
3405 seg_32bit
= (entry_2
>> 22) & 1;
3406 limit_in_pages
= (entry_2
>> 23) & 1;
3407 useable
= (entry_2
>> 20) & 1;
3411 lm
= (entry_2
>> 21) & 1;
3413 flags
= (seg_32bit
<< 0) | (contents
<< 1) |
3414 (read_exec_only
<< 3) | (limit_in_pages
<< 4) |
3415 (seg_not_present
<< 5) | (useable
<< 6) | (lm
<< 7);
3416 limit
= (entry_1
& 0xffff) | (entry_2
& 0xf0000);
3417 base_addr
= (entry_1
>> 16) |
3418 (entry_2
& 0xff000000) |
3419 ((entry_2
& 0xff) << 16);
3420 target_ldt_info
->base_addr
= tswapl(base_addr
);
3421 target_ldt_info
->limit
= tswap32(limit
);
3422 target_ldt_info
->flags
= tswap32(flags
);
3423 unlock_user_struct(target_ldt_info
, ptr
, 1);
3426 #endif /* TARGET_I386 && TARGET_ABI32 */
3428 #ifndef TARGET_ABI32
3429 static abi_long
do_arch_prctl(CPUX86State
*env
, int code
, abi_ulong addr
)
3436 case TARGET_ARCH_SET_GS
:
3437 case TARGET_ARCH_SET_FS
:
3438 if (code
== TARGET_ARCH_SET_GS
)
3442 cpu_x86_load_seg(env
, idx
, 0);
3443 env
->segs
[idx
].base
= addr
;
3445 case TARGET_ARCH_GET_GS
:
3446 case TARGET_ARCH_GET_FS
:
3447 if (code
== TARGET_ARCH_GET_GS
)
3451 val
= env
->segs
[idx
].base
;
3452 if (put_user(val
, addr
, abi_ulong
))
3453 return -TARGET_EFAULT
;
3456 ret
= -TARGET_EINVAL
;
3463 #endif /* defined(TARGET_I386) */
3465 #if defined(CONFIG_USE_NPTL)
3467 #define NEW_STACK_SIZE PTHREAD_STACK_MIN
3469 static pthread_mutex_t clone_lock
= PTHREAD_MUTEX_INITIALIZER
;
3472 pthread_mutex_t mutex
;
3473 pthread_cond_t cond
;
3476 abi_ulong child_tidptr
;
3477 abi_ulong parent_tidptr
;
3481 static void *clone_func(void *arg
)
3483 new_thread_info
*info
= arg
;
3489 ts
= (TaskState
*)thread_env
->opaque
;
3490 info
->tid
= gettid();
3491 env
->host_tid
= info
->tid
;
3493 if (info
->child_tidptr
)
3494 put_user_u32(info
->tid
, info
->child_tidptr
);
3495 if (info
->parent_tidptr
)
3496 put_user_u32(info
->tid
, info
->parent_tidptr
);
3497 /* Enable signals. */
3498 sigprocmask(SIG_SETMASK
, &info
->sigmask
, NULL
);
3499 /* Signal to the parent that we're ready. */
3500 pthread_mutex_lock(&info
->mutex
);
3501 pthread_cond_broadcast(&info
->cond
);
3502 pthread_mutex_unlock(&info
->mutex
);
3503 /* Wait until the parent has finshed initializing the tls state. */
3504 pthread_mutex_lock(&clone_lock
);
3505 pthread_mutex_unlock(&clone_lock
);
3511 /* this stack is the equivalent of the kernel stack associated with a
3513 #define NEW_STACK_SIZE 8192
3515 static int clone_func(void *arg
)
3517 CPUState
*env
= arg
;
3524 /* do_fork() Must return host values and target errnos (unlike most
3525 do_*() functions). */
3526 static int do_fork(CPUState
*env
, unsigned int flags
, abi_ulong newsp
,
3527 abi_ulong parent_tidptr
, target_ulong newtls
,
3528 abi_ulong child_tidptr
)
3534 #if defined(CONFIG_USE_NPTL)
3535 unsigned int nptl_flags
;
3539 /* Emulate vfork() with fork() */
3540 if (flags
& CLONE_VFORK
)
3541 flags
&= ~(CLONE_VFORK
| CLONE_VM
);
3543 if (flags
& CLONE_VM
) {
3544 TaskState
*parent_ts
= (TaskState
*)env
->opaque
;
3545 #if defined(CONFIG_USE_NPTL)
3546 new_thread_info info
;
3547 pthread_attr_t attr
;
3549 ts
= qemu_mallocz(sizeof(TaskState
) + NEW_STACK_SIZE
);
3550 init_task_state(ts
);
3551 new_stack
= ts
->stack
;
3552 /* we create a new CPU instance. */
3553 new_env
= cpu_copy(env
);
3554 /* Init regs that differ from the parent. */
3555 cpu_clone_regs(new_env
, newsp
);
3556 new_env
->opaque
= ts
;
3557 ts
->bprm
= parent_ts
->bprm
;
3558 ts
->info
= parent_ts
->info
;
3559 #if defined(CONFIG_USE_NPTL)
3561 flags
&= ~CLONE_NPTL_FLAGS2
;
3563 if (nptl_flags
& CLONE_CHILD_CLEARTID
) {
3564 ts
->child_tidptr
= child_tidptr
;
3567 if (nptl_flags
& CLONE_SETTLS
)
3568 cpu_set_tls (new_env
, newtls
);
3570 /* Grab a mutex so that thread setup appears atomic. */
3571 pthread_mutex_lock(&clone_lock
);
3573 memset(&info
, 0, sizeof(info
));
3574 pthread_mutex_init(&info
.mutex
, NULL
);
3575 pthread_mutex_lock(&info
.mutex
);
3576 pthread_cond_init(&info
.cond
, NULL
);
3578 if (nptl_flags
& CLONE_CHILD_SETTID
)
3579 info
.child_tidptr
= child_tidptr
;
3580 if (nptl_flags
& CLONE_PARENT_SETTID
)
3581 info
.parent_tidptr
= parent_tidptr
;
3583 ret
= pthread_attr_init(&attr
);
3584 ret
= pthread_attr_setstack(&attr
, new_stack
, NEW_STACK_SIZE
);
3585 /* It is not safe to deliver signals until the child has finished
3586 initializing, so temporarily block all signals. */
3587 sigfillset(&sigmask
);
3588 sigprocmask(SIG_BLOCK
, &sigmask
, &info
.sigmask
);
3590 ret
= pthread_create(&info
.thread
, &attr
, clone_func
, &info
);
3591 /* TODO: Free new CPU state if thread creation failed. */
3593 sigprocmask(SIG_SETMASK
, &info
.sigmask
, NULL
);
3594 pthread_attr_destroy(&attr
);
3596 /* Wait for the child to initialize. */
3597 pthread_cond_wait(&info
.cond
, &info
.mutex
);
3599 if (flags
& CLONE_PARENT_SETTID
)
3600 put_user_u32(ret
, parent_tidptr
);
3604 pthread_mutex_unlock(&info
.mutex
);
3605 pthread_cond_destroy(&info
.cond
);
3606 pthread_mutex_destroy(&info
.mutex
);
3607 pthread_mutex_unlock(&clone_lock
);
3609 if (flags
& CLONE_NPTL_FLAGS2
)
3611 /* This is probably going to die very quickly, but do it anyway. */
3613 ret
= __clone2(clone_func
, new_stack
+ NEW_STACK_SIZE
, flags
, new_env
);
3615 ret
= clone(clone_func
, new_stack
+ NEW_STACK_SIZE
, flags
, new_env
);
3619 /* if no CLONE_VM, we consider it is a fork */
3620 if ((flags
& ~(CSIGNAL
| CLONE_NPTL_FLAGS2
)) != 0)
3625 /* Child Process. */
3626 cpu_clone_regs(env
, newsp
);
3628 #if defined(CONFIG_USE_NPTL)
3629 /* There is a race condition here. The parent process could
3630 theoretically read the TID in the child process before the child
3631 tid is set. This would require using either ptrace
3632 (not implemented) or having *_tidptr to point at a shared memory
3633 mapping. We can't repeat the spinlock hack used above because
3634 the child process gets its own copy of the lock. */
3635 if (flags
& CLONE_CHILD_SETTID
)
3636 put_user_u32(gettid(), child_tidptr
);
3637 if (flags
& CLONE_PARENT_SETTID
)
3638 put_user_u32(gettid(), parent_tidptr
);
3639 ts
= (TaskState
*)env
->opaque
;
3640 if (flags
& CLONE_SETTLS
)
3641 cpu_set_tls (env
, newtls
);
3642 if (flags
& CLONE_CHILD_CLEARTID
)
3643 ts
->child_tidptr
= child_tidptr
;
3652 /* warning : doesn't handle linux specific flags... */
3653 static int target_to_host_fcntl_cmd(int cmd
)
3656 case TARGET_F_DUPFD
:
3657 case TARGET_F_GETFD
:
3658 case TARGET_F_SETFD
:
3659 case TARGET_F_GETFL
:
3660 case TARGET_F_SETFL
:
3662 case TARGET_F_GETLK
:
3664 case TARGET_F_SETLK
:
3666 case TARGET_F_SETLKW
:
3668 case TARGET_F_GETOWN
:
3670 case TARGET_F_SETOWN
:
3672 case TARGET_F_GETSIG
:
3674 case TARGET_F_SETSIG
:
3676 #if TARGET_ABI_BITS == 32
3677 case TARGET_F_GETLK64
:
3679 case TARGET_F_SETLK64
:
3681 case TARGET_F_SETLKW64
:
3684 case TARGET_F_SETLEASE
:
3686 case TARGET_F_GETLEASE
:
3688 case TARGET_F_DUPFD_CLOEXEC
:
3689 return F_DUPFD_CLOEXEC
;
3690 case TARGET_F_NOTIFY
:
3693 return -TARGET_EINVAL
;
3695 return -TARGET_EINVAL
;
3698 static abi_long
do_fcntl(int fd
, int cmd
, abi_ulong arg
)
3701 struct target_flock
*target_fl
;
3702 struct flock64 fl64
;
3703 struct target_flock64
*target_fl64
;
3705 int host_cmd
= target_to_host_fcntl_cmd(cmd
);
3707 if (host_cmd
== -TARGET_EINVAL
)
3711 case TARGET_F_GETLK
:
3712 if (!lock_user_struct(VERIFY_READ
, target_fl
, arg
, 1))
3713 return -TARGET_EFAULT
;
3714 fl
.l_type
= tswap16(target_fl
->l_type
);
3715 fl
.l_whence
= tswap16(target_fl
->l_whence
);
3716 fl
.l_start
= tswapl(target_fl
->l_start
);
3717 fl
.l_len
= tswapl(target_fl
->l_len
);
3718 fl
.l_pid
= tswap32(target_fl
->l_pid
);
3719 unlock_user_struct(target_fl
, arg
, 0);
3720 ret
= get_errno(fcntl(fd
, host_cmd
, &fl
));
3722 if (!lock_user_struct(VERIFY_WRITE
, target_fl
, arg
, 0))
3723 return -TARGET_EFAULT
;
3724 target_fl
->l_type
= tswap16(fl
.l_type
);
3725 target_fl
->l_whence
= tswap16(fl
.l_whence
);
3726 target_fl
->l_start
= tswapl(fl
.l_start
);
3727 target_fl
->l_len
= tswapl(fl
.l_len
);
3728 target_fl
->l_pid
= tswap32(fl
.l_pid
);
3729 unlock_user_struct(target_fl
, arg
, 1);
3733 case TARGET_F_SETLK
:
3734 case TARGET_F_SETLKW
:
3735 if (!lock_user_struct(VERIFY_READ
, target_fl
, arg
, 1))
3736 return -TARGET_EFAULT
;
3737 fl
.l_type
= tswap16(target_fl
->l_type
);
3738 fl
.l_whence
= tswap16(target_fl
->l_whence
);
3739 fl
.l_start
= tswapl(target_fl
->l_start
);
3740 fl
.l_len
= tswapl(target_fl
->l_len
);
3741 fl
.l_pid
= tswap32(target_fl
->l_pid
);
3742 unlock_user_struct(target_fl
, arg
, 0);
3743 ret
= get_errno(fcntl(fd
, host_cmd
, &fl
));
3746 case TARGET_F_GETLK64
:
3747 if (!lock_user_struct(VERIFY_READ
, target_fl64
, arg
, 1))
3748 return -TARGET_EFAULT
;
3749 fl64
.l_type
= tswap16(target_fl64
->l_type
) >> 1;
3750 fl64
.l_whence
= tswap16(target_fl64
->l_whence
);
3751 fl64
.l_start
= tswapl(target_fl64
->l_start
);
3752 fl64
.l_len
= tswapl(target_fl64
->l_len
);
3753 fl64
.l_pid
= tswap32(target_fl64
->l_pid
);
3754 unlock_user_struct(target_fl64
, arg
, 0);
3755 ret
= get_errno(fcntl(fd
, host_cmd
, &fl64
));
3757 if (!lock_user_struct(VERIFY_WRITE
, target_fl64
, arg
, 0))
3758 return -TARGET_EFAULT
;
3759 target_fl64
->l_type
= tswap16(fl64
.l_type
) >> 1;
3760 target_fl64
->l_whence
= tswap16(fl64
.l_whence
);
3761 target_fl64
->l_start
= tswapl(fl64
.l_start
);
3762 target_fl64
->l_len
= tswapl(fl64
.l_len
);
3763 target_fl64
->l_pid
= tswap32(fl64
.l_pid
);
3764 unlock_user_struct(target_fl64
, arg
, 1);
3767 case TARGET_F_SETLK64
:
3768 case TARGET_F_SETLKW64
:
3769 if (!lock_user_struct(VERIFY_READ
, target_fl64
, arg
, 1))
3770 return -TARGET_EFAULT
;
3771 fl64
.l_type
= tswap16(target_fl64
->l_type
) >> 1;
3772 fl64
.l_whence
= tswap16(target_fl64
->l_whence
);
3773 fl64
.l_start
= tswapl(target_fl64
->l_start
);
3774 fl64
.l_len
= tswapl(target_fl64
->l_len
);
3775 fl64
.l_pid
= tswap32(target_fl64
->l_pid
);
3776 unlock_user_struct(target_fl64
, arg
, 0);
3777 ret
= get_errno(fcntl(fd
, host_cmd
, &fl64
));
3780 case TARGET_F_GETFL
:
3781 ret
= get_errno(fcntl(fd
, host_cmd
, arg
));
3783 ret
= host_to_target_bitmask(ret
, fcntl_flags_tbl
);
3787 case TARGET_F_SETFL
:
3788 ret
= get_errno(fcntl(fd
, host_cmd
, target_to_host_bitmask(arg
, fcntl_flags_tbl
)));
3791 case TARGET_F_SETOWN
:
3792 case TARGET_F_GETOWN
:
3793 case TARGET_F_SETSIG
:
3794 case TARGET_F_GETSIG
:
3795 case TARGET_F_SETLEASE
:
3796 case TARGET_F_GETLEASE
:
3797 ret
= get_errno(fcntl(fd
, host_cmd
, arg
));
3801 ret
= get_errno(fcntl(fd
, cmd
, arg
));
3809 static inline int high2lowuid(int uid
)
3817 static inline int high2lowgid(int gid
)
3825 static inline int low2highuid(int uid
)
3827 if ((int16_t)uid
== -1)
3833 static inline int low2highgid(int gid
)
3835 if ((int16_t)gid
== -1)
3841 #endif /* USE_UID16 */
3843 void syscall_init(void)
3846 const argtype
*arg_type
;
3850 #define STRUCT(name, ...) thunk_register_struct(STRUCT_ ## name, #name, struct_ ## name ## _def);
3851 #define STRUCT_SPECIAL(name) thunk_register_struct_direct(STRUCT_ ## name, #name, &struct_ ## name ## _def);
3852 #include "syscall_types.h"
3854 #undef STRUCT_SPECIAL
3856 /* we patch the ioctl size if necessary. We rely on the fact that
3857 no ioctl has all the bits at '1' in the size field */
3859 while (ie
->target_cmd
!= 0) {
3860 if (((ie
->target_cmd
>> TARGET_IOC_SIZESHIFT
) & TARGET_IOC_SIZEMASK
) ==
3861 TARGET_IOC_SIZEMASK
) {
3862 arg_type
= ie
->arg_type
;
3863 if (arg_type
[0] != TYPE_PTR
) {
3864 fprintf(stderr
, "cannot patch size for ioctl 0x%x\n",
3869 size
= thunk_type_size(arg_type
, 0);
3870 ie
->target_cmd
= (ie
->target_cmd
&
3871 ~(TARGET_IOC_SIZEMASK
<< TARGET_IOC_SIZESHIFT
)) |
3872 (size
<< TARGET_IOC_SIZESHIFT
);
3875 /* Build target_to_host_errno_table[] table from
3876 * host_to_target_errno_table[]. */
3877 for (i
=0; i
< ERRNO_TABLE_SIZE
; i
++)
3878 target_to_host_errno_table
[host_to_target_errno_table
[i
]] = i
;
3880 /* automatic consistency check if same arch */
3881 #if (defined(__i386__) && defined(TARGET_I386) && defined(TARGET_ABI32)) || \
3882 (defined(__x86_64__) && defined(TARGET_X86_64))
3883 if (unlikely(ie
->target_cmd
!= ie
->host_cmd
)) {
3884 fprintf(stderr
, "ERROR: ioctl(%s): target=0x%x host=0x%x\n",
3885 ie
->name
, ie
->target_cmd
, ie
->host_cmd
);
3892 #if TARGET_ABI_BITS == 32
3893 static inline uint64_t target_offset64(uint32_t word0
, uint32_t word1
)
3895 #ifdef TARGET_WORDS_BIGENDIAN
3896 return ((uint64_t)word0
<< 32) | word1
;
3898 return ((uint64_t)word1
<< 32) | word0
;
3901 #else /* TARGET_ABI_BITS == 32 */
3902 static inline uint64_t target_offset64(uint64_t word0
, uint64_t word1
)
3906 #endif /* TARGET_ABI_BITS != 32 */
3908 #ifdef TARGET_NR_truncate64
3909 static inline abi_long
target_truncate64(void *cpu_env
, const char *arg1
,
3915 if (((CPUARMState
*)cpu_env
)->eabi
)
3921 return get_errno(truncate64(arg1
, target_offset64(arg2
, arg3
)));
3925 #ifdef TARGET_NR_ftruncate64
3926 static inline abi_long
target_ftruncate64(void *cpu_env
, abi_long arg1
,
3932 if (((CPUARMState
*)cpu_env
)->eabi
)
3938 return get_errno(ftruncate64(arg1
, target_offset64(arg2
, arg3
)));
3942 static inline abi_long
target_to_host_timespec(struct timespec
*host_ts
,
3943 abi_ulong target_addr
)
3945 struct target_timespec
*target_ts
;
3947 if (!lock_user_struct(VERIFY_READ
, target_ts
, target_addr
, 1))
3948 return -TARGET_EFAULT
;
3949 host_ts
->tv_sec
= tswapl(target_ts
->tv_sec
);
3950 host_ts
->tv_nsec
= tswapl(target_ts
->tv_nsec
);
3951 unlock_user_struct(target_ts
, target_addr
, 0);
3955 static inline abi_long
host_to_target_timespec(abi_ulong target_addr
,
3956 struct timespec
*host_ts
)
3958 struct target_timespec
*target_ts
;
3960 if (!lock_user_struct(VERIFY_WRITE
, target_ts
, target_addr
, 0))
3961 return -TARGET_EFAULT
;
3962 target_ts
->tv_sec
= tswapl(host_ts
->tv_sec
);
3963 target_ts
->tv_nsec
= tswapl(host_ts
->tv_nsec
);
3964 unlock_user_struct(target_ts
, target_addr
, 1);
3968 #if defined(TARGET_NR_stat64) || defined(TARGET_NR_newfstatat)
3969 static inline abi_long
host_to_target_stat64(void *cpu_env
,
3970 abi_ulong target_addr
,
3971 struct stat
*host_st
)
3974 if (((CPUARMState
*)cpu_env
)->eabi
) {
3975 struct target_eabi_stat64
*target_st
;
3977 if (!lock_user_struct(VERIFY_WRITE
, target_st
, target_addr
, 0))
3978 return -TARGET_EFAULT
;
3979 memset(target_st
, 0, sizeof(struct target_eabi_stat64
));
3980 __put_user(host_st
->st_dev
, &target_st
->st_dev
);
3981 __put_user(host_st
->st_ino
, &target_st
->st_ino
);
3982 #ifdef TARGET_STAT64_HAS_BROKEN_ST_INO
3983 __put_user(host_st
->st_ino
, &target_st
->__st_ino
);
3985 __put_user(host_st
->st_mode
, &target_st
->st_mode
);
3986 __put_user(host_st
->st_nlink
, &target_st
->st_nlink
);
3987 __put_user(host_st
->st_uid
, &target_st
->st_uid
);
3988 __put_user(host_st
->st_gid
, &target_st
->st_gid
);
3989 __put_user(host_st
->st_rdev
, &target_st
->st_rdev
);
3990 __put_user(host_st
->st_size
, &target_st
->st_size
);
3991 __put_user(host_st
->st_blksize
, &target_st
->st_blksize
);
3992 __put_user(host_st
->st_blocks
, &target_st
->st_blocks
);
3993 __put_user(host_st
->st_atime
, &target_st
->target_st_atime
);
3994 __put_user(host_st
->st_mtime
, &target_st
->target_st_mtime
);
3995 __put_user(host_st
->st_ctime
, &target_st
->target_st_ctime
);
3996 unlock_user_struct(target_st
, target_addr
, 1);
4000 #if TARGET_LONG_BITS == 64
4001 struct target_stat
*target_st
;
4003 struct target_stat64
*target_st
;
4006 if (!lock_user_struct(VERIFY_WRITE
, target_st
, target_addr
, 0))
4007 return -TARGET_EFAULT
;
4008 memset(target_st
, 0, sizeof(*target_st
));
4009 __put_user(host_st
->st_dev
, &target_st
->st_dev
);
4010 __put_user(host_st
->st_ino
, &target_st
->st_ino
);
4011 #ifdef TARGET_STAT64_HAS_BROKEN_ST_INO
4012 __put_user(host_st
->st_ino
, &target_st
->__st_ino
);
4014 __put_user(host_st
->st_mode
, &target_st
->st_mode
);
4015 __put_user(host_st
->st_nlink
, &target_st
->st_nlink
);
4016 __put_user(host_st
->st_uid
, &target_st
->st_uid
);
4017 __put_user(host_st
->st_gid
, &target_st
->st_gid
);
4018 __put_user(host_st
->st_rdev
, &target_st
->st_rdev
);
4019 /* XXX: better use of kernel struct */
4020 __put_user(host_st
->st_size
, &target_st
->st_size
);
4021 __put_user(host_st
->st_blksize
, &target_st
->st_blksize
);
4022 __put_user(host_st
->st_blocks
, &target_st
->st_blocks
);
4023 __put_user(host_st
->st_atime
, &target_st
->target_st_atime
);
4024 __put_user(host_st
->st_mtime
, &target_st
->target_st_mtime
);
4025 __put_user(host_st
->st_ctime
, &target_st
->target_st_ctime
);
4026 unlock_user_struct(target_st
, target_addr
, 1);
4033 #if defined(CONFIG_USE_NPTL)
4034 /* ??? Using host futex calls even when target atomic operations
4035 are not really atomic probably breaks things. However implementing
4036 futexes locally would make futexes shared between multiple processes
4037 tricky. However they're probably useless because guest atomic
4038 operations won't work either. */
4039 static int do_futex(target_ulong uaddr
, int op
, int val
, target_ulong timeout
,
4040 target_ulong uaddr2
, int val3
)
4042 struct timespec ts
, *pts
;
4045 /* ??? We assume FUTEX_* constants are the same on both host
4047 #ifdef FUTEX_CMD_MASK
4048 base_op
= op
& FUTEX_CMD_MASK
;
4056 target_to_host_timespec(pts
, timeout
);
4060 return get_errno(sys_futex(g2h(uaddr
), op
, tswap32(val
),
4063 return get_errno(sys_futex(g2h(uaddr
), op
, val
, NULL
, NULL
, 0));
4065 return get_errno(sys_futex(g2h(uaddr
), op
, val
, NULL
, NULL
, 0));
4067 case FUTEX_CMP_REQUEUE
:
4069 /* For FUTEX_REQUEUE, FUTEX_CMP_REQUEUE, and FUTEX_WAKE_OP, the
4070 TIMEOUT parameter is interpreted as a uint32_t by the kernel.
4071 But the prototype takes a `struct timespec *'; insert casts
4072 to satisfy the compiler. We do not need to tswap TIMEOUT
4073 since it's not compared to guest memory. */
4074 pts
= (struct timespec
*)(uintptr_t) timeout
;
4075 return get_errno(sys_futex(g2h(uaddr
), op
, val
, pts
,
4077 (base_op
== FUTEX_CMP_REQUEUE
4081 return -TARGET_ENOSYS
;
4086 /* Map host to target signal numbers for the wait family of syscalls.
4087 Assume all other status bits are the same. */
4088 static int host_to_target_waitstatus(int status
)
4090 if (WIFSIGNALED(status
)) {
4091 return host_to_target_signal(WTERMSIG(status
)) | (status
& ~0x7f);
4093 if (WIFSTOPPED(status
)) {
4094 return (host_to_target_signal(WSTOPSIG(status
)) << 8)
4100 int get_osversion(void)
4102 static int osversion
;
4103 struct new_utsname buf
;
4108 if (qemu_uname_release
&& *qemu_uname_release
) {
4109 s
= qemu_uname_release
;
4111 if (sys_uname(&buf
))
4116 for (i
= 0; i
< 3; i
++) {
4118 while (*s
>= '0' && *s
<= '9') {
4123 tmp
= (tmp
<< 8) + n
;
4131 /* do_syscall() should always have a single exit point at the end so
4132 that actions, such as logging of syscall results, can be performed.
4133 All errnos that do_syscall() returns must be -TARGET_<errcode>. */
4134 abi_long
do_syscall(void *cpu_env
, int num
, abi_long arg1
,
4135 abi_long arg2
, abi_long arg3
, abi_long arg4
,
4136 abi_long arg5
, abi_long arg6
)
4144 gemu_log("syscall %d", num
);
4147 print_syscall(num
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
4150 case TARGET_NR_exit
:
4151 #ifdef CONFIG_USE_NPTL
4152 /* In old applications this may be used to implement _exit(2).
4153 However in threaded applictions it is used for thread termination,
4154 and _exit_group is used for application termination.
4155 Do thread termination if we have more then one thread. */
4156 /* FIXME: This probably breaks if a signal arrives. We should probably
4157 be disabling signals. */
4158 if (first_cpu
->next_cpu
) {
4166 while (p
&& p
!= (CPUState
*)cpu_env
) {
4167 lastp
= &p
->next_cpu
;
4170 /* If we didn't find the CPU for this thread then something is
4174 /* Remove the CPU from the list. */
4175 *lastp
= p
->next_cpu
;
4177 ts
= ((CPUState
*)cpu_env
)->opaque
;
4178 if (ts
->child_tidptr
) {
4179 put_user_u32(0, ts
->child_tidptr
);
4180 sys_futex(g2h(ts
->child_tidptr
), FUTEX_WAKE
, INT_MAX
,
4183 /* TODO: Free CPU state. */
4190 gdb_exit(cpu_env
, arg1
);
4192 ret
= 0; /* avoid warning */
4194 case TARGET_NR_read
:
4198 if (!(p
= lock_user(VERIFY_WRITE
, arg2
, arg3
, 0)))
4200 ret
= get_errno(read(arg1
, p
, arg3
));
4201 unlock_user(p
, arg2
, ret
);
4204 case TARGET_NR_write
:
4205 if (!(p
= lock_user(VERIFY_READ
, arg2
, arg3
, 1)))
4207 ret
= get_errno(write(arg1
, p
, arg3
));
4208 unlock_user(p
, arg2
, 0);
4210 case TARGET_NR_open
:
4211 if (!(p
= lock_user_string(arg1
)))
4213 ret
= get_errno(open(path(p
),
4214 target_to_host_bitmask(arg2
, fcntl_flags_tbl
),
4216 unlock_user(p
, arg1
, 0);
4218 #if defined(TARGET_NR_openat) && defined(__NR_openat)
4219 case TARGET_NR_openat
:
4220 if (!(p
= lock_user_string(arg2
)))
4222 ret
= get_errno(sys_openat(arg1
,
4224 target_to_host_bitmask(arg3
, fcntl_flags_tbl
),
4226 unlock_user(p
, arg2
, 0);
4229 case TARGET_NR_close
:
4230 ret
= get_errno(close(arg1
));
4235 case TARGET_NR_fork
:
4236 ret
= get_errno(do_fork(cpu_env
, SIGCHLD
, 0, 0, 0, 0));
4238 #ifdef TARGET_NR_waitpid
4239 case TARGET_NR_waitpid
:
4242 ret
= get_errno(waitpid(arg1
, &status
, arg3
));
4243 if (!is_error(ret
) && arg2
4244 && put_user_s32(host_to_target_waitstatus(status
), arg2
))
4249 #ifdef TARGET_NR_waitid
4250 case TARGET_NR_waitid
:
4254 ret
= get_errno(waitid(arg1
, arg2
, &info
, arg4
));
4255 if (!is_error(ret
) && arg3
&& info
.si_pid
!= 0) {
4256 if (!(p
= lock_user(VERIFY_WRITE
, arg3
, sizeof(target_siginfo_t
), 0)))
4258 host_to_target_siginfo(p
, &info
);
4259 unlock_user(p
, arg3
, sizeof(target_siginfo_t
));
4264 #ifdef TARGET_NR_creat /* not on alpha */
4265 case TARGET_NR_creat
:
4266 if (!(p
= lock_user_string(arg1
)))
4268 ret
= get_errno(creat(p
, arg2
));
4269 unlock_user(p
, arg1
, 0);
4272 case TARGET_NR_link
:
4275 p
= lock_user_string(arg1
);
4276 p2
= lock_user_string(arg2
);
4278 ret
= -TARGET_EFAULT
;
4280 ret
= get_errno(link(p
, p2
));
4281 unlock_user(p2
, arg2
, 0);
4282 unlock_user(p
, arg1
, 0);
4285 #if defined(TARGET_NR_linkat) && defined(__NR_linkat)
4286 case TARGET_NR_linkat
:
4291 p
= lock_user_string(arg2
);
4292 p2
= lock_user_string(arg4
);
4294 ret
= -TARGET_EFAULT
;
4296 ret
= get_errno(sys_linkat(arg1
, p
, arg3
, p2
, arg5
));
4297 unlock_user(p
, arg2
, 0);
4298 unlock_user(p2
, arg4
, 0);
4302 case TARGET_NR_unlink
:
4303 if (!(p
= lock_user_string(arg1
)))
4305 ret
= get_errno(unlink(p
));
4306 unlock_user(p
, arg1
, 0);
4308 #if defined(TARGET_NR_unlinkat) && defined(__NR_unlinkat)
4309 case TARGET_NR_unlinkat
:
4310 if (!(p
= lock_user_string(arg2
)))
4312 ret
= get_errno(sys_unlinkat(arg1
, p
, arg3
));
4313 unlock_user(p
, arg2
, 0);
4316 case TARGET_NR_execve
:
4318 char **argp
, **envp
;
4321 abi_ulong guest_argp
;
4322 abi_ulong guest_envp
;
4328 for (gp
= guest_argp
; gp
; gp
+= sizeof(abi_ulong
)) {
4329 if (get_user_ual(addr
, gp
))
4337 for (gp
= guest_envp
; gp
; gp
+= sizeof(abi_ulong
)) {
4338 if (get_user_ual(addr
, gp
))
4345 argp
= alloca((argc
+ 1) * sizeof(void *));
4346 envp
= alloca((envc
+ 1) * sizeof(void *));
4348 for (gp
= guest_argp
, q
= argp
; gp
;
4349 gp
+= sizeof(abi_ulong
), q
++) {
4350 if (get_user_ual(addr
, gp
))
4354 if (!(*q
= lock_user_string(addr
)))
4359 for (gp
= guest_envp
, q
= envp
; gp
;
4360 gp
+= sizeof(abi_ulong
), q
++) {
4361 if (get_user_ual(addr
, gp
))
4365 if (!(*q
= lock_user_string(addr
)))
4370 if (!(p
= lock_user_string(arg1
)))
4372 ret
= get_errno(execve(p
, argp
, envp
));
4373 unlock_user(p
, arg1
, 0);
4378 ret
= -TARGET_EFAULT
;
4381 for (gp
= guest_argp
, q
= argp
; *q
;
4382 gp
+= sizeof(abi_ulong
), q
++) {
4383 if (get_user_ual(addr
, gp
)
4386 unlock_user(*q
, addr
, 0);
4388 for (gp
= guest_envp
, q
= envp
; *q
;
4389 gp
+= sizeof(abi_ulong
), q
++) {
4390 if (get_user_ual(addr
, gp
)
4393 unlock_user(*q
, addr
, 0);
4397 case TARGET_NR_chdir
:
4398 if (!(p
= lock_user_string(arg1
)))
4400 ret
= get_errno(chdir(p
));
4401 unlock_user(p
, arg1
, 0);
4403 #ifdef TARGET_NR_time
4404 case TARGET_NR_time
:
4407 ret
= get_errno(time(&host_time
));
4410 && put_user_sal(host_time
, arg1
))
4415 case TARGET_NR_mknod
:
4416 if (!(p
= lock_user_string(arg1
)))
4418 ret
= get_errno(mknod(p
, arg2
, arg3
));
4419 unlock_user(p
, arg1
, 0);
4421 #if defined(TARGET_NR_mknodat) && defined(__NR_mknodat)
4422 case TARGET_NR_mknodat
:
4423 if (!(p
= lock_user_string(arg2
)))
4425 ret
= get_errno(sys_mknodat(arg1
, p
, arg3
, arg4
));
4426 unlock_user(p
, arg2
, 0);
4429 case TARGET_NR_chmod
:
4430 if (!(p
= lock_user_string(arg1
)))
4432 ret
= get_errno(chmod(p
, arg2
));
4433 unlock_user(p
, arg1
, 0);
4435 #ifdef TARGET_NR_break
4436 case TARGET_NR_break
:
4439 #ifdef TARGET_NR_oldstat
4440 case TARGET_NR_oldstat
:
4443 case TARGET_NR_lseek
:
4444 ret
= get_errno(lseek(arg1
, arg2
, arg3
));
4446 #ifdef TARGET_NR_getxpid
4447 case TARGET_NR_getxpid
:
4449 case TARGET_NR_getpid
:
4451 ret
= get_errno(getpid());
4453 case TARGET_NR_mount
:
4455 /* need to look at the data field */
4457 p
= lock_user_string(arg1
);
4458 p2
= lock_user_string(arg2
);
4459 p3
= lock_user_string(arg3
);
4460 if (!p
|| !p2
|| !p3
)
4461 ret
= -TARGET_EFAULT
;
4463 /* FIXME - arg5 should be locked, but it isn't clear how to
4464 * do that since it's not guaranteed to be a NULL-terminated
4467 ret
= get_errno(mount(p
, p2
, p3
, (unsigned long)arg4
, g2h(arg5
)));
4468 unlock_user(p
, arg1
, 0);
4469 unlock_user(p2
, arg2
, 0);
4470 unlock_user(p3
, arg3
, 0);
4473 #ifdef TARGET_NR_umount
4474 case TARGET_NR_umount
:
4475 if (!(p
= lock_user_string(arg1
)))
4477 ret
= get_errno(umount(p
));
4478 unlock_user(p
, arg1
, 0);
4481 #ifdef TARGET_NR_stime /* not on alpha */
4482 case TARGET_NR_stime
:
4485 if (get_user_sal(host_time
, arg1
))
4487 ret
= get_errno(stime(&host_time
));
4491 case TARGET_NR_ptrace
:
4493 #ifdef TARGET_NR_alarm /* not on alpha */
4494 case TARGET_NR_alarm
:
4498 #ifdef TARGET_NR_oldfstat
4499 case TARGET_NR_oldfstat
:
4502 #ifdef TARGET_NR_pause /* not on alpha */
4503 case TARGET_NR_pause
:
4504 ret
= get_errno(pause());
4507 #ifdef TARGET_NR_utime
4508 case TARGET_NR_utime
:
4510 struct utimbuf tbuf
, *host_tbuf
;
4511 struct target_utimbuf
*target_tbuf
;
4513 if (!lock_user_struct(VERIFY_READ
, target_tbuf
, arg2
, 1))
4515 tbuf
.actime
= tswapl(target_tbuf
->actime
);
4516 tbuf
.modtime
= tswapl(target_tbuf
->modtime
);
4517 unlock_user_struct(target_tbuf
, arg2
, 0);
4522 if (!(p
= lock_user_string(arg1
)))
4524 ret
= get_errno(utime(p
, host_tbuf
));
4525 unlock_user(p
, arg1
, 0);
4529 case TARGET_NR_utimes
:
4531 struct timeval
*tvp
, tv
[2];
4533 if (copy_from_user_timeval(&tv
[0], arg2
)
4534 || copy_from_user_timeval(&tv
[1],
4535 arg2
+ sizeof(struct target_timeval
)))
4541 if (!(p
= lock_user_string(arg1
)))
4543 ret
= get_errno(utimes(p
, tvp
));
4544 unlock_user(p
, arg1
, 0);
4547 #if defined(TARGET_NR_futimesat) && defined(__NR_futimesat)
4548 case TARGET_NR_futimesat
:
4550 struct timeval
*tvp
, tv
[2];
4552 if (copy_from_user_timeval(&tv
[0], arg3
)
4553 || copy_from_user_timeval(&tv
[1],
4554 arg3
+ sizeof(struct target_timeval
)))
4560 if (!(p
= lock_user_string(arg2
)))
4562 ret
= get_errno(sys_futimesat(arg1
, path(p
), tvp
));
4563 unlock_user(p
, arg2
, 0);
4567 #ifdef TARGET_NR_stty
4568 case TARGET_NR_stty
:
4571 #ifdef TARGET_NR_gtty
4572 case TARGET_NR_gtty
:
4575 case TARGET_NR_access
:
4576 if (!(p
= lock_user_string(arg1
)))
4578 ret
= get_errno(access(path(p
), arg2
));
4579 unlock_user(p
, arg1
, 0);
4581 #if defined(TARGET_NR_faccessat) && defined(__NR_faccessat)
4582 case TARGET_NR_faccessat
:
4583 if (!(p
= lock_user_string(arg2
)))
4585 ret
= get_errno(sys_faccessat(arg1
, p
, arg3
));
4586 unlock_user(p
, arg2
, 0);
4589 #ifdef TARGET_NR_nice /* not on alpha */
4590 case TARGET_NR_nice
:
4591 ret
= get_errno(nice(arg1
));
4594 #ifdef TARGET_NR_ftime
4595 case TARGET_NR_ftime
:
4598 case TARGET_NR_sync
:
4602 case TARGET_NR_kill
:
4603 ret
= get_errno(kill(arg1
, target_to_host_signal(arg2
)));
4605 case TARGET_NR_rename
:
4608 p
= lock_user_string(arg1
);
4609 p2
= lock_user_string(arg2
);
4611 ret
= -TARGET_EFAULT
;
4613 ret
= get_errno(rename(p
, p2
));
4614 unlock_user(p2
, arg2
, 0);
4615 unlock_user(p
, arg1
, 0);
4618 #if defined(TARGET_NR_renameat) && defined(__NR_renameat)
4619 case TARGET_NR_renameat
:
4622 p
= lock_user_string(arg2
);
4623 p2
= lock_user_string(arg4
);
4625 ret
= -TARGET_EFAULT
;
4627 ret
= get_errno(sys_renameat(arg1
, p
, arg3
, p2
));
4628 unlock_user(p2
, arg4
, 0);
4629 unlock_user(p
, arg2
, 0);
4633 case TARGET_NR_mkdir
:
4634 if (!(p
= lock_user_string(arg1
)))
4636 ret
= get_errno(mkdir(p
, arg2
));
4637 unlock_user(p
, arg1
, 0);
4639 #if defined(TARGET_NR_mkdirat) && defined(__NR_mkdirat)
4640 case TARGET_NR_mkdirat
:
4641 if (!(p
= lock_user_string(arg2
)))
4643 ret
= get_errno(sys_mkdirat(arg1
, p
, arg3
));
4644 unlock_user(p
, arg2
, 0);
4647 case TARGET_NR_rmdir
:
4648 if (!(p
= lock_user_string(arg1
)))
4650 ret
= get_errno(rmdir(p
));
4651 unlock_user(p
, arg1
, 0);
4654 ret
= get_errno(dup(arg1
));
4656 case TARGET_NR_pipe
:
4657 ret
= do_pipe(cpu_env
, arg1
, 0);
4659 #ifdef TARGET_NR_pipe2
4660 case TARGET_NR_pipe2
:
4661 ret
= do_pipe(cpu_env
, arg1
, arg2
);
4664 case TARGET_NR_times
:
4666 struct target_tms
*tmsp
;
4668 ret
= get_errno(times(&tms
));
4670 tmsp
= lock_user(VERIFY_WRITE
, arg1
, sizeof(struct target_tms
), 0);
4673 tmsp
->tms_utime
= tswapl(host_to_target_clock_t(tms
.tms_utime
));
4674 tmsp
->tms_stime
= tswapl(host_to_target_clock_t(tms
.tms_stime
));
4675 tmsp
->tms_cutime
= tswapl(host_to_target_clock_t(tms
.tms_cutime
));
4676 tmsp
->tms_cstime
= tswapl(host_to_target_clock_t(tms
.tms_cstime
));
4679 ret
= host_to_target_clock_t(ret
);
4682 #ifdef TARGET_NR_prof
4683 case TARGET_NR_prof
:
4686 #ifdef TARGET_NR_signal
4687 case TARGET_NR_signal
:
4690 case TARGET_NR_acct
:
4692 ret
= get_errno(acct(NULL
));
4694 if (!(p
= lock_user_string(arg1
)))
4696 ret
= get_errno(acct(path(p
)));
4697 unlock_user(p
, arg1
, 0);
4700 #ifdef TARGET_NR_umount2 /* not on alpha */
4701 case TARGET_NR_umount2
:
4702 if (!(p
= lock_user_string(arg1
)))
4704 ret
= get_errno(umount2(p
, arg2
));
4705 unlock_user(p
, arg1
, 0);
4708 #ifdef TARGET_NR_lock
4709 case TARGET_NR_lock
:
4712 case TARGET_NR_ioctl
:
4713 ret
= do_ioctl(arg1
, arg2
, arg3
);
4715 case TARGET_NR_fcntl
:
4716 ret
= do_fcntl(arg1
, arg2
, arg3
);
4718 #ifdef TARGET_NR_mpx
4722 case TARGET_NR_setpgid
:
4723 ret
= get_errno(setpgid(arg1
, arg2
));
4725 #ifdef TARGET_NR_ulimit
4726 case TARGET_NR_ulimit
:
4729 #ifdef TARGET_NR_oldolduname
4730 case TARGET_NR_oldolduname
:
4733 case TARGET_NR_umask
:
4734 ret
= get_errno(umask(arg1
));
4736 case TARGET_NR_chroot
:
4737 if (!(p
= lock_user_string(arg1
)))
4739 ret
= get_errno(chroot(p
));
4740 unlock_user(p
, arg1
, 0);
4742 case TARGET_NR_ustat
:
4744 case TARGET_NR_dup2
:
4745 ret
= get_errno(dup2(arg1
, arg2
));
4747 #ifdef TARGET_NR_getppid /* not on alpha */
4748 case TARGET_NR_getppid
:
4749 ret
= get_errno(getppid());
4752 case TARGET_NR_getpgrp
:
4753 ret
= get_errno(getpgrp());
4755 case TARGET_NR_setsid
:
4756 ret
= get_errno(setsid());
4758 #ifdef TARGET_NR_sigaction
4759 case TARGET_NR_sigaction
:
4761 #if !defined(TARGET_MIPS)
4762 struct target_old_sigaction
*old_act
;
4763 struct target_sigaction act
, oact
, *pact
;
4765 if (!lock_user_struct(VERIFY_READ
, old_act
, arg2
, 1))
4767 act
._sa_handler
= old_act
->_sa_handler
;
4768 target_siginitset(&act
.sa_mask
, old_act
->sa_mask
);
4769 act
.sa_flags
= old_act
->sa_flags
;
4770 act
.sa_restorer
= old_act
->sa_restorer
;
4771 unlock_user_struct(old_act
, arg2
, 0);
4776 ret
= get_errno(do_sigaction(arg1
, pact
, &oact
));
4777 if (!is_error(ret
) && arg3
) {
4778 if (!lock_user_struct(VERIFY_WRITE
, old_act
, arg3
, 0))
4780 old_act
->_sa_handler
= oact
._sa_handler
;
4781 old_act
->sa_mask
= oact
.sa_mask
.sig
[0];
4782 old_act
->sa_flags
= oact
.sa_flags
;
4783 old_act
->sa_restorer
= oact
.sa_restorer
;
4784 unlock_user_struct(old_act
, arg3
, 1);
4787 struct target_sigaction act
, oact
, *pact
, *old_act
;
4790 if (!lock_user_struct(VERIFY_READ
, old_act
, arg2
, 1))
4792 act
._sa_handler
= old_act
->_sa_handler
;
4793 target_siginitset(&act
.sa_mask
, old_act
->sa_mask
.sig
[0]);
4794 act
.sa_flags
= old_act
->sa_flags
;
4795 unlock_user_struct(old_act
, arg2
, 0);
4801 ret
= get_errno(do_sigaction(arg1
, pact
, &oact
));
4803 if (!is_error(ret
) && arg3
) {
4804 if (!lock_user_struct(VERIFY_WRITE
, old_act
, arg3
, 0))
4806 old_act
->_sa_handler
= oact
._sa_handler
;
4807 old_act
->sa_flags
= oact
.sa_flags
;
4808 old_act
->sa_mask
.sig
[0] = oact
.sa_mask
.sig
[0];
4809 old_act
->sa_mask
.sig
[1] = 0;
4810 old_act
->sa_mask
.sig
[2] = 0;
4811 old_act
->sa_mask
.sig
[3] = 0;
4812 unlock_user_struct(old_act
, arg3
, 1);
4818 case TARGET_NR_rt_sigaction
:
4820 struct target_sigaction
*act
;
4821 struct target_sigaction
*oact
;
4824 if (!lock_user_struct(VERIFY_READ
, act
, arg2
, 1))
4829 if (!lock_user_struct(VERIFY_WRITE
, oact
, arg3
, 0)) {
4830 ret
= -TARGET_EFAULT
;
4831 goto rt_sigaction_fail
;
4835 ret
= get_errno(do_sigaction(arg1
, act
, oact
));
4838 unlock_user_struct(act
, arg2
, 0);
4840 unlock_user_struct(oact
, arg3
, 1);
4843 #ifdef TARGET_NR_sgetmask /* not on alpha */
4844 case TARGET_NR_sgetmask
:
4847 abi_ulong target_set
;
4848 sigprocmask(0, NULL
, &cur_set
);
4849 host_to_target_old_sigset(&target_set
, &cur_set
);
4854 #ifdef TARGET_NR_ssetmask /* not on alpha */
4855 case TARGET_NR_ssetmask
:
4857 sigset_t set
, oset
, cur_set
;
4858 abi_ulong target_set
= arg1
;
4859 sigprocmask(0, NULL
, &cur_set
);
4860 target_to_host_old_sigset(&set
, &target_set
);
4861 sigorset(&set
, &set
, &cur_set
);
4862 sigprocmask(SIG_SETMASK
, &set
, &oset
);
4863 host_to_target_old_sigset(&target_set
, &oset
);
4868 #ifdef TARGET_NR_sigprocmask
4869 case TARGET_NR_sigprocmask
:
4872 sigset_t set
, oldset
, *set_ptr
;
4876 case TARGET_SIG_BLOCK
:
4879 case TARGET_SIG_UNBLOCK
:
4882 case TARGET_SIG_SETMASK
:
4886 ret
= -TARGET_EINVAL
;
4889 if (!(p
= lock_user(VERIFY_READ
, arg2
, sizeof(target_sigset_t
), 1)))
4891 target_to_host_old_sigset(&set
, p
);
4892 unlock_user(p
, arg2
, 0);
4898 ret
= get_errno(sigprocmask(arg1
, set_ptr
, &oldset
));
4899 if (!is_error(ret
) && arg3
) {
4900 if (!(p
= lock_user(VERIFY_WRITE
, arg3
, sizeof(target_sigset_t
), 0)))
4902 host_to_target_old_sigset(p
, &oldset
);
4903 unlock_user(p
, arg3
, sizeof(target_sigset_t
));
4908 case TARGET_NR_rt_sigprocmask
:
4911 sigset_t set
, oldset
, *set_ptr
;
4915 case TARGET_SIG_BLOCK
:
4918 case TARGET_SIG_UNBLOCK
:
4921 case TARGET_SIG_SETMASK
:
4925 ret
= -TARGET_EINVAL
;
4928 if (!(p
= lock_user(VERIFY_READ
, arg2
, sizeof(target_sigset_t
), 1)))
4930 target_to_host_sigset(&set
, p
);
4931 unlock_user(p
, arg2
, 0);
4937 ret
= get_errno(sigprocmask(how
, set_ptr
, &oldset
));
4938 if (!is_error(ret
) && arg3
) {
4939 if (!(p
= lock_user(VERIFY_WRITE
, arg3
, sizeof(target_sigset_t
), 0)))
4941 host_to_target_sigset(p
, &oldset
);
4942 unlock_user(p
, arg3
, sizeof(target_sigset_t
));
4946 #ifdef TARGET_NR_sigpending
4947 case TARGET_NR_sigpending
:
4950 ret
= get_errno(sigpending(&set
));
4951 if (!is_error(ret
)) {
4952 if (!(p
= lock_user(VERIFY_WRITE
, arg1
, sizeof(target_sigset_t
), 0)))
4954 host_to_target_old_sigset(p
, &set
);
4955 unlock_user(p
, arg1
, sizeof(target_sigset_t
));
4960 case TARGET_NR_rt_sigpending
:
4963 ret
= get_errno(sigpending(&set
));
4964 if (!is_error(ret
)) {
4965 if (!(p
= lock_user(VERIFY_WRITE
, arg1
, sizeof(target_sigset_t
), 0)))
4967 host_to_target_sigset(p
, &set
);
4968 unlock_user(p
, arg1
, sizeof(target_sigset_t
));
4972 #ifdef TARGET_NR_sigsuspend
4973 case TARGET_NR_sigsuspend
:
4976 if (!(p
= lock_user(VERIFY_READ
, arg1
, sizeof(target_sigset_t
), 1)))
4978 target_to_host_old_sigset(&set
, p
);
4979 unlock_user(p
, arg1
, 0);
4980 ret
= get_errno(sigsuspend(&set
));
4984 case TARGET_NR_rt_sigsuspend
:
4987 if (!(p
= lock_user(VERIFY_READ
, arg1
, sizeof(target_sigset_t
), 1)))
4989 target_to_host_sigset(&set
, p
);
4990 unlock_user(p
, arg1
, 0);
4991 ret
= get_errno(sigsuspend(&set
));
4994 case TARGET_NR_rt_sigtimedwait
:
4997 struct timespec uts
, *puts
;
5000 if (!(p
= lock_user(VERIFY_READ
, arg1
, sizeof(target_sigset_t
), 1)))
5002 target_to_host_sigset(&set
, p
);
5003 unlock_user(p
, arg1
, 0);
5006 target_to_host_timespec(puts
, arg3
);
5010 ret
= get_errno(sigtimedwait(&set
, &uinfo
, puts
));
5011 if (!is_error(ret
) && arg2
) {
5012 if (!(p
= lock_user(VERIFY_WRITE
, arg2
, sizeof(target_siginfo_t
), 0)))
5014 host_to_target_siginfo(p
, &uinfo
);
5015 unlock_user(p
, arg2
, sizeof(target_siginfo_t
));
5019 case TARGET_NR_rt_sigqueueinfo
:
5022 if (!(p
= lock_user(VERIFY_READ
, arg3
, sizeof(target_sigset_t
), 1)))
5024 target_to_host_siginfo(&uinfo
, p
);
5025 unlock_user(p
, arg1
, 0);
5026 ret
= get_errno(sys_rt_sigqueueinfo(arg1
, arg2
, &uinfo
));
5029 #ifdef TARGET_NR_sigreturn
5030 case TARGET_NR_sigreturn
:
5031 /* NOTE: ret is eax, so not transcoding must be done */
5032 ret
= do_sigreturn(cpu_env
);
5035 case TARGET_NR_rt_sigreturn
:
5036 /* NOTE: ret is eax, so not transcoding must be done */
5037 ret
= do_rt_sigreturn(cpu_env
);
5039 case TARGET_NR_sethostname
:
5040 if (!(p
= lock_user_string(arg1
)))
5042 ret
= get_errno(sethostname(p
, arg2
));
5043 unlock_user(p
, arg1
, 0);
5045 case TARGET_NR_setrlimit
:
5047 /* XXX: convert resource ? */
5048 int resource
= arg1
;
5049 struct target_rlimit
*target_rlim
;
5051 if (!lock_user_struct(VERIFY_READ
, target_rlim
, arg2
, 1))
5053 rlim
.rlim_cur
= tswapl(target_rlim
->rlim_cur
);
5054 rlim
.rlim_max
= tswapl(target_rlim
->rlim_max
);
5055 unlock_user_struct(target_rlim
, arg2
, 0);
5056 ret
= get_errno(setrlimit(resource
, &rlim
));
5059 case TARGET_NR_getrlimit
:
5061 /* XXX: convert resource ? */
5062 int resource
= arg1
;
5063 struct target_rlimit
*target_rlim
;
5066 ret
= get_errno(getrlimit(resource
, &rlim
));
5067 if (!is_error(ret
)) {
5068 if (!lock_user_struct(VERIFY_WRITE
, target_rlim
, arg2
, 0))
5070 target_rlim
->rlim_cur
= tswapl(rlim
.rlim_cur
);
5071 target_rlim
->rlim_max
= tswapl(rlim
.rlim_max
);
5072 unlock_user_struct(target_rlim
, arg2
, 1);
5076 case TARGET_NR_getrusage
:
5078 struct rusage rusage
;
5079 ret
= get_errno(getrusage(arg1
, &rusage
));
5080 if (!is_error(ret
)) {
5081 host_to_target_rusage(arg2
, &rusage
);
5085 case TARGET_NR_gettimeofday
:
5088 ret
= get_errno(gettimeofday(&tv
, NULL
));
5089 if (!is_error(ret
)) {
5090 if (copy_to_user_timeval(arg1
, &tv
))
5095 case TARGET_NR_settimeofday
:
5098 if (copy_from_user_timeval(&tv
, arg1
))
5100 ret
= get_errno(settimeofday(&tv
, NULL
));
5103 #ifdef TARGET_NR_select
5104 case TARGET_NR_select
:
5106 struct target_sel_arg_struct
*sel
;
5107 abi_ulong inp
, outp
, exp
, tvp
;
5110 if (!lock_user_struct(VERIFY_READ
, sel
, arg1
, 1))
5112 nsel
= tswapl(sel
->n
);
5113 inp
= tswapl(sel
->inp
);
5114 outp
= tswapl(sel
->outp
);
5115 exp
= tswapl(sel
->exp
);
5116 tvp
= tswapl(sel
->tvp
);
5117 unlock_user_struct(sel
, arg1
, 0);
5118 ret
= do_select(nsel
, inp
, outp
, exp
, tvp
);
5122 case TARGET_NR_symlink
:
5125 p
= lock_user_string(arg1
);
5126 p2
= lock_user_string(arg2
);
5128 ret
= -TARGET_EFAULT
;
5130 ret
= get_errno(symlink(p
, p2
));
5131 unlock_user(p2
, arg2
, 0);
5132 unlock_user(p
, arg1
, 0);
5135 #if defined(TARGET_NR_symlinkat) && defined(__NR_symlinkat)
5136 case TARGET_NR_symlinkat
:
5139 p
= lock_user_string(arg1
);
5140 p2
= lock_user_string(arg3
);
5142 ret
= -TARGET_EFAULT
;
5144 ret
= get_errno(sys_symlinkat(p
, arg2
, p2
));
5145 unlock_user(p2
, arg3
, 0);
5146 unlock_user(p
, arg1
, 0);
5150 #ifdef TARGET_NR_oldlstat
5151 case TARGET_NR_oldlstat
:
5154 case TARGET_NR_readlink
:
5157 p
= lock_user_string(arg1
);
5158 p2
= lock_user(VERIFY_WRITE
, arg2
, arg3
, 0);
5160 ret
= -TARGET_EFAULT
;
5162 if (strncmp((const char *)p
, "/proc/self/exe", 14) == 0) {
5163 char real
[PATH_MAX
];
5164 temp
= realpath(exec_path
,real
);
5165 ret
= (temp
==NULL
) ? get_errno(-1) : strlen(real
) ;
5166 snprintf((char *)p2
, arg3
, "%s", real
);
5169 ret
= get_errno(readlink(path(p
), p2
, arg3
));
5171 unlock_user(p2
, arg2
, ret
);
5172 unlock_user(p
, arg1
, 0);
5175 #if defined(TARGET_NR_readlinkat) && defined(__NR_readlinkat)
5176 case TARGET_NR_readlinkat
:
5179 p
= lock_user_string(arg2
);
5180 p2
= lock_user(VERIFY_WRITE
, arg3
, arg4
, 0);
5182 ret
= -TARGET_EFAULT
;
5184 ret
= get_errno(sys_readlinkat(arg1
, path(p
), p2
, arg4
));
5185 unlock_user(p2
, arg3
, ret
);
5186 unlock_user(p
, arg2
, 0);
5190 #ifdef TARGET_NR_uselib
5191 case TARGET_NR_uselib
:
5194 #ifdef TARGET_NR_swapon
5195 case TARGET_NR_swapon
:
5196 if (!(p
= lock_user_string(arg1
)))
5198 ret
= get_errno(swapon(p
, arg2
));
5199 unlock_user(p
, arg1
, 0);
5202 case TARGET_NR_reboot
:
5204 #ifdef TARGET_NR_readdir
5205 case TARGET_NR_readdir
:
5208 #ifdef TARGET_NR_mmap
5209 case TARGET_NR_mmap
:
5210 #if (defined(TARGET_I386) && defined(TARGET_ABI32)) || defined(TARGET_ARM) || defined(TARGET_M68K) || defined(TARGET_CRIS) || defined(TARGET_MICROBLAZE)
5213 abi_ulong v1
, v2
, v3
, v4
, v5
, v6
;
5214 if (!(v
= lock_user(VERIFY_READ
, arg1
, 6 * sizeof(abi_ulong
), 1)))
5222 unlock_user(v
, arg1
, 0);
5223 ret
= get_errno(target_mmap(v1
, v2
, v3
,
5224 target_to_host_bitmask(v4
, mmap_flags_tbl
),
5228 ret
= get_errno(target_mmap(arg1
, arg2
, arg3
,
5229 target_to_host_bitmask(arg4
, mmap_flags_tbl
),
5235 #ifdef TARGET_NR_mmap2
5236 case TARGET_NR_mmap2
:
5238 #define MMAP_SHIFT 12
5240 ret
= get_errno(target_mmap(arg1
, arg2
, arg3
,
5241 target_to_host_bitmask(arg4
, mmap_flags_tbl
),
5243 arg6
<< MMAP_SHIFT
));
5246 case TARGET_NR_munmap
:
5247 ret
= get_errno(target_munmap(arg1
, arg2
));
5249 case TARGET_NR_mprotect
:
5250 ret
= get_errno(target_mprotect(arg1
, arg2
, arg3
));
5252 #ifdef TARGET_NR_mremap
5253 case TARGET_NR_mremap
:
5254 ret
= get_errno(target_mremap(arg1
, arg2
, arg3
, arg4
, arg5
));
5257 /* ??? msync/mlock/munlock are broken for softmmu. */
5258 #ifdef TARGET_NR_msync
5259 case TARGET_NR_msync
:
5260 ret
= get_errno(msync(g2h(arg1
), arg2
, arg3
));
5263 #ifdef TARGET_NR_mlock
5264 case TARGET_NR_mlock
:
5265 ret
= get_errno(mlock(g2h(arg1
), arg2
));
5268 #ifdef TARGET_NR_munlock
5269 case TARGET_NR_munlock
:
5270 ret
= get_errno(munlock(g2h(arg1
), arg2
));
5273 #ifdef TARGET_NR_mlockall
5274 case TARGET_NR_mlockall
:
5275 ret
= get_errno(mlockall(arg1
));
5278 #ifdef TARGET_NR_munlockall
5279 case TARGET_NR_munlockall
:
5280 ret
= get_errno(munlockall());
5283 case TARGET_NR_truncate
:
5284 if (!(p
= lock_user_string(arg1
)))
5286 ret
= get_errno(truncate(p
, arg2
));
5287 unlock_user(p
, arg1
, 0);
5289 case TARGET_NR_ftruncate
:
5290 ret
= get_errno(ftruncate(arg1
, arg2
));
5292 case TARGET_NR_fchmod
:
5293 ret
= get_errno(fchmod(arg1
, arg2
));
5295 #if defined(TARGET_NR_fchmodat) && defined(__NR_fchmodat)
5296 case TARGET_NR_fchmodat
:
5297 if (!(p
= lock_user_string(arg2
)))
5299 ret
= get_errno(sys_fchmodat(arg1
, p
, arg3
));
5300 unlock_user(p
, arg2
, 0);
5303 case TARGET_NR_getpriority
:
5304 /* libc does special remapping of the return value of
5305 * sys_getpriority() so it's just easiest to call
5306 * sys_getpriority() directly rather than through libc. */
5307 ret
= sys_getpriority(arg1
, arg2
);
5309 case TARGET_NR_setpriority
:
5310 ret
= get_errno(setpriority(arg1
, arg2
, arg3
));
5312 #ifdef TARGET_NR_profil
5313 case TARGET_NR_profil
:
5316 case TARGET_NR_statfs
:
5317 if (!(p
= lock_user_string(arg1
)))
5319 ret
= get_errno(statfs(path(p
), &stfs
));
5320 unlock_user(p
, arg1
, 0);
5322 if (!is_error(ret
)) {
5323 struct target_statfs
*target_stfs
;
5325 if (!lock_user_struct(VERIFY_WRITE
, target_stfs
, arg2
, 0))
5327 __put_user(stfs
.f_type
, &target_stfs
->f_type
);
5328 __put_user(stfs
.f_bsize
, &target_stfs
->f_bsize
);
5329 __put_user(stfs
.f_blocks
, &target_stfs
->f_blocks
);
5330 __put_user(stfs
.f_bfree
, &target_stfs
->f_bfree
);
5331 __put_user(stfs
.f_bavail
, &target_stfs
->f_bavail
);
5332 __put_user(stfs
.f_files
, &target_stfs
->f_files
);
5333 __put_user(stfs
.f_ffree
, &target_stfs
->f_ffree
);
5334 __put_user(stfs
.f_fsid
.__val
[0], &target_stfs
->f_fsid
.val
[0]);
5335 __put_user(stfs
.f_fsid
.__val
[1], &target_stfs
->f_fsid
.val
[1]);
5336 __put_user(stfs
.f_namelen
, &target_stfs
->f_namelen
);
5337 unlock_user_struct(target_stfs
, arg2
, 1);
5340 case TARGET_NR_fstatfs
:
5341 ret
= get_errno(fstatfs(arg1
, &stfs
));
5342 goto convert_statfs
;
5343 #ifdef TARGET_NR_statfs64
5344 case TARGET_NR_statfs64
:
5345 if (!(p
= lock_user_string(arg1
)))
5347 ret
= get_errno(statfs(path(p
), &stfs
));
5348 unlock_user(p
, arg1
, 0);
5350 if (!is_error(ret
)) {
5351 struct target_statfs64
*target_stfs
;
5353 if (!lock_user_struct(VERIFY_WRITE
, target_stfs
, arg3
, 0))
5355 __put_user(stfs
.f_type
, &target_stfs
->f_type
);
5356 __put_user(stfs
.f_bsize
, &target_stfs
->f_bsize
);
5357 __put_user(stfs
.f_blocks
, &target_stfs
->f_blocks
);
5358 __put_user(stfs
.f_bfree
, &target_stfs
->f_bfree
);
5359 __put_user(stfs
.f_bavail
, &target_stfs
->f_bavail
);
5360 __put_user(stfs
.f_files
, &target_stfs
->f_files
);
5361 __put_user(stfs
.f_ffree
, &target_stfs
->f_ffree
);
5362 __put_user(stfs
.f_fsid
.__val
[0], &target_stfs
->f_fsid
.val
[0]);
5363 __put_user(stfs
.f_fsid
.__val
[1], &target_stfs
->f_fsid
.val
[1]);
5364 __put_user(stfs
.f_namelen
, &target_stfs
->f_namelen
);
5365 unlock_user_struct(target_stfs
, arg3
, 1);
5368 case TARGET_NR_fstatfs64
:
5369 ret
= get_errno(fstatfs(arg1
, &stfs
));
5370 goto convert_statfs64
;
5372 #ifdef TARGET_NR_ioperm
5373 case TARGET_NR_ioperm
:
5376 #ifdef TARGET_NR_socketcall
5377 case TARGET_NR_socketcall
:
5378 ret
= do_socketcall(arg1
, arg2
);
5381 #ifdef TARGET_NR_accept
5382 case TARGET_NR_accept
:
5383 ret
= do_accept(arg1
, arg2
, arg3
);
5386 #ifdef TARGET_NR_bind
5387 case TARGET_NR_bind
:
5388 ret
= do_bind(arg1
, arg2
, arg3
);
5391 #ifdef TARGET_NR_connect
5392 case TARGET_NR_connect
:
5393 ret
= do_connect(arg1
, arg2
, arg3
);
5396 #ifdef TARGET_NR_getpeername
5397 case TARGET_NR_getpeername
:
5398 ret
= do_getpeername(arg1
, arg2
, arg3
);
5401 #ifdef TARGET_NR_getsockname
5402 case TARGET_NR_getsockname
:
5403 ret
= do_getsockname(arg1
, arg2
, arg3
);
5406 #ifdef TARGET_NR_getsockopt
5407 case TARGET_NR_getsockopt
:
5408 ret
= do_getsockopt(arg1
, arg2
, arg3
, arg4
, arg5
);
5411 #ifdef TARGET_NR_listen
5412 case TARGET_NR_listen
:
5413 ret
= get_errno(listen(arg1
, arg2
));
5416 #ifdef TARGET_NR_recv
5417 case TARGET_NR_recv
:
5418 ret
= do_recvfrom(arg1
, arg2
, arg3
, arg4
, 0, 0);
5421 #ifdef TARGET_NR_recvfrom
5422 case TARGET_NR_recvfrom
:
5423 ret
= do_recvfrom(arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
5426 #ifdef TARGET_NR_recvmsg
5427 case TARGET_NR_recvmsg
:
5428 ret
= do_sendrecvmsg(arg1
, arg2
, arg3
, 0);
5431 #ifdef TARGET_NR_send
5432 case TARGET_NR_send
:
5433 ret
= do_sendto(arg1
, arg2
, arg3
, arg4
, 0, 0);
5436 #ifdef TARGET_NR_sendmsg
5437 case TARGET_NR_sendmsg
:
5438 ret
= do_sendrecvmsg(arg1
, arg2
, arg3
, 1);
5441 #ifdef TARGET_NR_sendto
5442 case TARGET_NR_sendto
:
5443 ret
= do_sendto(arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
5446 #ifdef TARGET_NR_shutdown
5447 case TARGET_NR_shutdown
:
5448 ret
= get_errno(shutdown(arg1
, arg2
));
5451 #ifdef TARGET_NR_socket
5452 case TARGET_NR_socket
:
5453 ret
= do_socket(arg1
, arg2
, arg3
);
5456 #ifdef TARGET_NR_socketpair
5457 case TARGET_NR_socketpair
:
5458 ret
= do_socketpair(arg1
, arg2
, arg3
, arg4
);
5461 #ifdef TARGET_NR_setsockopt
5462 case TARGET_NR_setsockopt
:
5463 ret
= do_setsockopt(arg1
, arg2
, arg3
, arg4
, (socklen_t
) arg5
);
5467 case TARGET_NR_syslog
:
5468 if (!(p
= lock_user_string(arg2
)))
5470 ret
= get_errno(sys_syslog((int)arg1
, p
, (int)arg3
));
5471 unlock_user(p
, arg2
, 0);
5474 case TARGET_NR_setitimer
:
5476 struct itimerval value
, ovalue
, *pvalue
;
5480 if (copy_from_user_timeval(&pvalue
->it_interval
, arg2
)
5481 || copy_from_user_timeval(&pvalue
->it_value
,
5482 arg2
+ sizeof(struct target_timeval
)))
5487 ret
= get_errno(setitimer(arg1
, pvalue
, &ovalue
));
5488 if (!is_error(ret
) && arg3
) {
5489 if (copy_to_user_timeval(arg3
,
5490 &ovalue
.it_interval
)
5491 || copy_to_user_timeval(arg3
+ sizeof(struct target_timeval
),
5497 case TARGET_NR_getitimer
:
5499 struct itimerval value
;
5501 ret
= get_errno(getitimer(arg1
, &value
));
5502 if (!is_error(ret
) && arg2
) {
5503 if (copy_to_user_timeval(arg2
,
5505 || copy_to_user_timeval(arg2
+ sizeof(struct target_timeval
),
5511 case TARGET_NR_stat
:
5512 if (!(p
= lock_user_string(arg1
)))
5514 ret
= get_errno(stat(path(p
), &st
));
5515 unlock_user(p
, arg1
, 0);
5517 case TARGET_NR_lstat
:
5518 if (!(p
= lock_user_string(arg1
)))
5520 ret
= get_errno(lstat(path(p
), &st
));
5521 unlock_user(p
, arg1
, 0);
5523 case TARGET_NR_fstat
:
5525 ret
= get_errno(fstat(arg1
, &st
));
5527 if (!is_error(ret
)) {
5528 struct target_stat
*target_st
;
5530 if (!lock_user_struct(VERIFY_WRITE
, target_st
, arg2
, 0))
5532 memset(target_st
, 0, sizeof(*target_st
));
5533 __put_user(st
.st_dev
, &target_st
->st_dev
);
5534 __put_user(st
.st_ino
, &target_st
->st_ino
);
5535 __put_user(st
.st_mode
, &target_st
->st_mode
);
5536 __put_user(st
.st_uid
, &target_st
->st_uid
);
5537 __put_user(st
.st_gid
, &target_st
->st_gid
);
5538 __put_user(st
.st_nlink
, &target_st
->st_nlink
);
5539 __put_user(st
.st_rdev
, &target_st
->st_rdev
);
5540 __put_user(st
.st_size
, &target_st
->st_size
);
5541 __put_user(st
.st_blksize
, &target_st
->st_blksize
);
5542 __put_user(st
.st_blocks
, &target_st
->st_blocks
);
5543 __put_user(st
.st_atime
, &target_st
->target_st_atime
);
5544 __put_user(st
.st_mtime
, &target_st
->target_st_mtime
);
5545 __put_user(st
.st_ctime
, &target_st
->target_st_ctime
);
5546 unlock_user_struct(target_st
, arg2
, 1);
5550 #ifdef TARGET_NR_olduname
5551 case TARGET_NR_olduname
:
5554 #ifdef TARGET_NR_iopl
5555 case TARGET_NR_iopl
:
5558 case TARGET_NR_vhangup
:
5559 ret
= get_errno(vhangup());
5561 #ifdef TARGET_NR_idle
5562 case TARGET_NR_idle
:
5565 #ifdef TARGET_NR_syscall
5566 case TARGET_NR_syscall
:
5567 ret
= do_syscall(cpu_env
,arg1
& 0xffff,arg2
,arg3
,arg4
,arg5
,arg6
,0);
5570 case TARGET_NR_wait4
:
5573 abi_long status_ptr
= arg2
;
5574 struct rusage rusage
, *rusage_ptr
;
5575 abi_ulong target_rusage
= arg4
;
5577 rusage_ptr
= &rusage
;
5580 ret
= get_errno(wait4(arg1
, &status
, arg3
, rusage_ptr
));
5581 if (!is_error(ret
)) {
5583 status
= host_to_target_waitstatus(status
);
5584 if (put_user_s32(status
, status_ptr
))
5588 host_to_target_rusage(target_rusage
, &rusage
);
5592 #ifdef TARGET_NR_swapoff
5593 case TARGET_NR_swapoff
:
5594 if (!(p
= lock_user_string(arg1
)))
5596 ret
= get_errno(swapoff(p
));
5597 unlock_user(p
, arg1
, 0);
5600 case TARGET_NR_sysinfo
:
5602 struct target_sysinfo
*target_value
;
5603 struct sysinfo value
;
5604 ret
= get_errno(sysinfo(&value
));
5605 if (!is_error(ret
) && arg1
)
5607 if (!lock_user_struct(VERIFY_WRITE
, target_value
, arg1
, 0))
5609 __put_user(value
.uptime
, &target_value
->uptime
);
5610 __put_user(value
.loads
[0], &target_value
->loads
[0]);
5611 __put_user(value
.loads
[1], &target_value
->loads
[1]);
5612 __put_user(value
.loads
[2], &target_value
->loads
[2]);
5613 __put_user(value
.totalram
, &target_value
->totalram
);
5614 __put_user(value
.freeram
, &target_value
->freeram
);
5615 __put_user(value
.sharedram
, &target_value
->sharedram
);
5616 __put_user(value
.bufferram
, &target_value
->bufferram
);
5617 __put_user(value
.totalswap
, &target_value
->totalswap
);
5618 __put_user(value
.freeswap
, &target_value
->freeswap
);
5619 __put_user(value
.procs
, &target_value
->procs
);
5620 __put_user(value
.totalhigh
, &target_value
->totalhigh
);
5621 __put_user(value
.freehigh
, &target_value
->freehigh
);
5622 __put_user(value
.mem_unit
, &target_value
->mem_unit
);
5623 unlock_user_struct(target_value
, arg1
, 1);
5627 #ifdef TARGET_NR_ipc
5629 ret
= do_ipc(arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
5632 #ifdef TARGET_NR_semget
5633 case TARGET_NR_semget
:
5634 ret
= get_errno(semget(arg1
, arg2
, arg3
));
5637 #ifdef TARGET_NR_semop
5638 case TARGET_NR_semop
:
5639 ret
= get_errno(do_semop(arg1
, arg2
, arg3
));
5642 #ifdef TARGET_NR_semctl
5643 case TARGET_NR_semctl
:
5644 ret
= do_semctl(arg1
, arg2
, arg3
, (union target_semun
)(abi_ulong
)arg4
);
5647 #ifdef TARGET_NR_msgctl
5648 case TARGET_NR_msgctl
:
5649 ret
= do_msgctl(arg1
, arg2
, arg3
);
5652 #ifdef TARGET_NR_msgget
5653 case TARGET_NR_msgget
:
5654 ret
= get_errno(msgget(arg1
, arg2
));
5657 #ifdef TARGET_NR_msgrcv
5658 case TARGET_NR_msgrcv
:
5659 ret
= do_msgrcv(arg1
, arg2
, arg3
, arg4
, arg5
);
5662 #ifdef TARGET_NR_msgsnd
5663 case TARGET_NR_msgsnd
:
5664 ret
= do_msgsnd(arg1
, arg2
, arg3
, arg4
);
5667 #ifdef TARGET_NR_shmget
5668 case TARGET_NR_shmget
:
5669 ret
= get_errno(shmget(arg1
, arg2
, arg3
));
5672 #ifdef TARGET_NR_shmctl
5673 case TARGET_NR_shmctl
:
5674 ret
= do_shmctl(arg1
, arg2
, arg3
);
5677 #ifdef TARGET_NR_shmat
5678 case TARGET_NR_shmat
:
5679 ret
= do_shmat(arg1
, arg2
, arg3
);
5682 #ifdef TARGET_NR_shmdt
5683 case TARGET_NR_shmdt
:
5684 ret
= do_shmdt(arg1
);
5687 case TARGET_NR_fsync
:
5688 ret
= get_errno(fsync(arg1
));
5690 case TARGET_NR_clone
:
5691 #if defined(TARGET_SH4)
5692 ret
= get_errno(do_fork(cpu_env
, arg1
, arg2
, arg3
, arg5
, arg4
));
5693 #elif defined(TARGET_CRIS)
5694 ret
= get_errno(do_fork(cpu_env
, arg2
, arg1
, arg3
, arg4
, arg5
));
5696 ret
= get_errno(do_fork(cpu_env
, arg1
, arg2
, arg3
, arg4
, arg5
));
5699 #ifdef __NR_exit_group
5700 /* new thread calls */
5701 case TARGET_NR_exit_group
:
5705 gdb_exit(cpu_env
, arg1
);
5706 ret
= get_errno(exit_group(arg1
));
5709 case TARGET_NR_setdomainname
:
5710 if (!(p
= lock_user_string(arg1
)))
5712 ret
= get_errno(setdomainname(p
, arg2
));
5713 unlock_user(p
, arg1
, 0);
5715 case TARGET_NR_uname
:
5716 /* no need to transcode because we use the linux syscall */
5718 struct new_utsname
* buf
;
5720 if (!lock_user_struct(VERIFY_WRITE
, buf
, arg1
, 0))
5722 ret
= get_errno(sys_uname(buf
));
5723 if (!is_error(ret
)) {
5724 /* Overrite the native machine name with whatever is being
5726 strcpy (buf
->machine
, UNAME_MACHINE
);
5727 /* Allow the user to override the reported release. */
5728 if (qemu_uname_release
&& *qemu_uname_release
)
5729 strcpy (buf
->release
, qemu_uname_release
);
5731 unlock_user_struct(buf
, arg1
, 1);
5735 case TARGET_NR_modify_ldt
:
5736 ret
= do_modify_ldt(cpu_env
, arg1
, arg2
, arg3
);
5738 #if !defined(TARGET_X86_64)
5739 case TARGET_NR_vm86old
:
5741 case TARGET_NR_vm86
:
5742 ret
= do_vm86(cpu_env
, arg1
, arg2
);
5746 case TARGET_NR_adjtimex
:
5748 #ifdef TARGET_NR_create_module
5749 case TARGET_NR_create_module
:
5751 case TARGET_NR_init_module
:
5752 case TARGET_NR_delete_module
:
5753 #ifdef TARGET_NR_get_kernel_syms
5754 case TARGET_NR_get_kernel_syms
:
5757 case TARGET_NR_quotactl
:
5759 case TARGET_NR_getpgid
:
5760 ret
= get_errno(getpgid(arg1
));
5762 case TARGET_NR_fchdir
:
5763 ret
= get_errno(fchdir(arg1
));
5765 #ifdef TARGET_NR_bdflush /* not on x86_64 */
5766 case TARGET_NR_bdflush
:
5769 #ifdef TARGET_NR_sysfs
5770 case TARGET_NR_sysfs
:
5773 case TARGET_NR_personality
:
5774 ret
= get_errno(personality(arg1
));
5776 #ifdef TARGET_NR_afs_syscall
5777 case TARGET_NR_afs_syscall
:
5780 #ifdef TARGET_NR__llseek /* Not on alpha */
5781 case TARGET_NR__llseek
:
5783 #if defined (__x86_64__)
5784 ret
= get_errno(lseek(arg1
, ((uint64_t )arg2
<< 32) | arg3
, arg5
));
5785 if (put_user_s64(ret
, arg4
))
5789 ret
= get_errno(_llseek(arg1
, arg2
, arg3
, &res
, arg5
));
5790 if (put_user_s64(res
, arg4
))
5796 case TARGET_NR_getdents
:
5797 #if TARGET_ABI_BITS == 32 && HOST_LONG_BITS == 64
5799 struct target_dirent
*target_dirp
;
5800 struct linux_dirent
*dirp
;
5801 abi_long count
= arg3
;
5803 dirp
= malloc(count
);
5805 ret
= -TARGET_ENOMEM
;
5809 ret
= get_errno(sys_getdents(arg1
, dirp
, count
));
5810 if (!is_error(ret
)) {
5811 struct linux_dirent
*de
;
5812 struct target_dirent
*tde
;
5814 int reclen
, treclen
;
5815 int count1
, tnamelen
;
5819 if (!(target_dirp
= lock_user(VERIFY_WRITE
, arg2
, count
, 0)))
5823 reclen
= de
->d_reclen
;
5824 treclen
= reclen
- (2 * (sizeof(long) - sizeof(abi_long
)));
5825 tde
->d_reclen
= tswap16(treclen
);
5826 tde
->d_ino
= tswapl(de
->d_ino
);
5827 tde
->d_off
= tswapl(de
->d_off
);
5828 tnamelen
= treclen
- (2 * sizeof(abi_long
) + 2);
5831 /* XXX: may not be correct */
5832 pstrcpy(tde
->d_name
, tnamelen
, de
->d_name
);
5833 de
= (struct linux_dirent
*)((char *)de
+ reclen
);
5835 tde
= (struct target_dirent
*)((char *)tde
+ treclen
);
5839 unlock_user(target_dirp
, arg2
, ret
);
5845 struct linux_dirent
*dirp
;
5846 abi_long count
= arg3
;
5848 if (!(dirp
= lock_user(VERIFY_WRITE
, arg2
, count
, 0)))
5850 ret
= get_errno(sys_getdents(arg1
, dirp
, count
));
5851 if (!is_error(ret
)) {
5852 struct linux_dirent
*de
;
5857 reclen
= de
->d_reclen
;
5860 de
->d_reclen
= tswap16(reclen
);
5861 tswapls(&de
->d_ino
);
5862 tswapls(&de
->d_off
);
5863 de
= (struct linux_dirent
*)((char *)de
+ reclen
);
5867 unlock_user(dirp
, arg2
, ret
);
5871 #if defined(TARGET_NR_getdents64) && defined(__NR_getdents64)
5872 case TARGET_NR_getdents64
:
5874 struct linux_dirent64
*dirp
;
5875 abi_long count
= arg3
;
5876 if (!(dirp
= lock_user(VERIFY_WRITE
, arg2
, count
, 0)))
5878 ret
= get_errno(sys_getdents64(arg1
, dirp
, count
));
5879 if (!is_error(ret
)) {
5880 struct linux_dirent64
*de
;
5885 reclen
= de
->d_reclen
;
5888 de
->d_reclen
= tswap16(reclen
);
5889 tswap64s((uint64_t *)&de
->d_ino
);
5890 tswap64s((uint64_t *)&de
->d_off
);
5891 de
= (struct linux_dirent64
*)((char *)de
+ reclen
);
5895 unlock_user(dirp
, arg2
, ret
);
5898 #endif /* TARGET_NR_getdents64 */
5899 #ifdef TARGET_NR__newselect
5900 case TARGET_NR__newselect
:
5901 ret
= do_select(arg1
, arg2
, arg3
, arg4
, arg5
);
5904 #ifdef TARGET_NR_poll
5905 case TARGET_NR_poll
:
5907 struct target_pollfd
*target_pfd
;
5908 unsigned int nfds
= arg2
;
5913 target_pfd
= lock_user(VERIFY_WRITE
, arg1
, sizeof(struct target_pollfd
) * nfds
, 1);
5916 pfd
= alloca(sizeof(struct pollfd
) * nfds
);
5917 for(i
= 0; i
< nfds
; i
++) {
5918 pfd
[i
].fd
= tswap32(target_pfd
[i
].fd
);
5919 pfd
[i
].events
= tswap16(target_pfd
[i
].events
);
5921 ret
= get_errno(poll(pfd
, nfds
, timeout
));
5922 if (!is_error(ret
)) {
5923 for(i
= 0; i
< nfds
; i
++) {
5924 target_pfd
[i
].revents
= tswap16(pfd
[i
].revents
);
5926 ret
+= nfds
* (sizeof(struct target_pollfd
)
5927 - sizeof(struct pollfd
));
5929 unlock_user(target_pfd
, arg1
, ret
);
5933 case TARGET_NR_flock
:
5934 /* NOTE: the flock constant seems to be the same for every
5936 ret
= get_errno(flock(arg1
, arg2
));
5938 case TARGET_NR_readv
:
5943 vec
= alloca(count
* sizeof(struct iovec
));
5944 if (lock_iovec(VERIFY_WRITE
, vec
, arg2
, count
, 0) < 0)
5946 ret
= get_errno(readv(arg1
, vec
, count
));
5947 unlock_iovec(vec
, arg2
, count
, 1);
5950 case TARGET_NR_writev
:
5955 vec
= alloca(count
* sizeof(struct iovec
));
5956 if (lock_iovec(VERIFY_READ
, vec
, arg2
, count
, 1) < 0)
5958 ret
= get_errno(writev(arg1
, vec
, count
));
5959 unlock_iovec(vec
, arg2
, count
, 0);
5962 case TARGET_NR_getsid
:
5963 ret
= get_errno(getsid(arg1
));
5965 #if defined(TARGET_NR_fdatasync) /* Not on alpha (osf_datasync ?) */
5966 case TARGET_NR_fdatasync
:
5967 ret
= get_errno(fdatasync(arg1
));
5970 case TARGET_NR__sysctl
:
5971 /* We don't implement this, but ENOTDIR is always a safe
5973 ret
= -TARGET_ENOTDIR
;
5975 case TARGET_NR_sched_setparam
:
5977 struct sched_param
*target_schp
;
5978 struct sched_param schp
;
5980 if (!lock_user_struct(VERIFY_READ
, target_schp
, arg2
, 1))
5982 schp
.sched_priority
= tswap32(target_schp
->sched_priority
);
5983 unlock_user_struct(target_schp
, arg2
, 0);
5984 ret
= get_errno(sched_setparam(arg1
, &schp
));
5987 case TARGET_NR_sched_getparam
:
5989 struct sched_param
*target_schp
;
5990 struct sched_param schp
;
5991 ret
= get_errno(sched_getparam(arg1
, &schp
));
5992 if (!is_error(ret
)) {
5993 if (!lock_user_struct(VERIFY_WRITE
, target_schp
, arg2
, 0))
5995 target_schp
->sched_priority
= tswap32(schp
.sched_priority
);
5996 unlock_user_struct(target_schp
, arg2
, 1);
6000 case TARGET_NR_sched_setscheduler
:
6002 struct sched_param
*target_schp
;
6003 struct sched_param schp
;
6004 if (!lock_user_struct(VERIFY_READ
, target_schp
, arg3
, 1))
6006 schp
.sched_priority
= tswap32(target_schp
->sched_priority
);
6007 unlock_user_struct(target_schp
, arg3
, 0);
6008 ret
= get_errno(sched_setscheduler(arg1
, arg2
, &schp
));
6011 case TARGET_NR_sched_getscheduler
:
6012 ret
= get_errno(sched_getscheduler(arg1
));
6014 case TARGET_NR_sched_yield
:
6015 ret
= get_errno(sched_yield());
6017 case TARGET_NR_sched_get_priority_max
:
6018 ret
= get_errno(sched_get_priority_max(arg1
));
6020 case TARGET_NR_sched_get_priority_min
:
6021 ret
= get_errno(sched_get_priority_min(arg1
));
6023 case TARGET_NR_sched_rr_get_interval
:
6026 ret
= get_errno(sched_rr_get_interval(arg1
, &ts
));
6027 if (!is_error(ret
)) {
6028 host_to_target_timespec(arg2
, &ts
);
6032 case TARGET_NR_nanosleep
:
6034 struct timespec req
, rem
;
6035 target_to_host_timespec(&req
, arg1
);
6036 ret
= get_errno(nanosleep(&req
, &rem
));
6037 if (is_error(ret
) && arg2
) {
6038 host_to_target_timespec(arg2
, &rem
);
6042 #ifdef TARGET_NR_query_module
6043 case TARGET_NR_query_module
:
6046 #ifdef TARGET_NR_nfsservctl
6047 case TARGET_NR_nfsservctl
:
6050 case TARGET_NR_prctl
:
6053 case PR_GET_PDEATHSIG
:
6056 ret
= get_errno(prctl(arg1
, &deathsig
, arg3
, arg4
, arg5
));
6057 if (!is_error(ret
) && arg2
6058 && put_user_ual(deathsig
, arg2
))
6063 ret
= get_errno(prctl(arg1
, arg2
, arg3
, arg4
, arg5
));
6067 #ifdef TARGET_NR_arch_prctl
6068 case TARGET_NR_arch_prctl
:
6069 #if defined(TARGET_I386) && !defined(TARGET_ABI32)
6070 ret
= do_arch_prctl(cpu_env
, arg1
, arg2
);
6076 #ifdef TARGET_NR_pread
6077 case TARGET_NR_pread
:
6079 if (((CPUARMState
*)cpu_env
)->eabi
)
6082 if (!(p
= lock_user(VERIFY_WRITE
, arg2
, arg3
, 0)))
6084 ret
= get_errno(pread(arg1
, p
, arg3
, arg4
));
6085 unlock_user(p
, arg2
, ret
);
6087 case TARGET_NR_pwrite
:
6089 if (((CPUARMState
*)cpu_env
)->eabi
)
6092 if (!(p
= lock_user(VERIFY_READ
, arg2
, arg3
, 1)))
6094 ret
= get_errno(pwrite(arg1
, p
, arg3
, arg4
));
6095 unlock_user(p
, arg2
, 0);
6098 #ifdef TARGET_NR_pread64
6099 case TARGET_NR_pread64
:
6100 if (!(p
= lock_user(VERIFY_WRITE
, arg2
, arg3
, 0)))
6102 ret
= get_errno(pread64(arg1
, p
, arg3
, target_offset64(arg4
, arg5
)));
6103 unlock_user(p
, arg2
, ret
);
6105 case TARGET_NR_pwrite64
:
6106 if (!(p
= lock_user(VERIFY_READ
, arg2
, arg3
, 1)))
6108 ret
= get_errno(pwrite64(arg1
, p
, arg3
, target_offset64(arg4
, arg5
)));
6109 unlock_user(p
, arg2
, 0);
6112 case TARGET_NR_getcwd
:
6113 if (!(p
= lock_user(VERIFY_WRITE
, arg1
, arg2
, 0)))
6115 ret
= get_errno(sys_getcwd1(p
, arg2
));
6116 unlock_user(p
, arg1
, ret
);
6118 case TARGET_NR_capget
:
6120 case TARGET_NR_capset
:
6122 case TARGET_NR_sigaltstack
:
6123 #if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_MIPS) || \
6124 defined(TARGET_SPARC) || defined(TARGET_PPC) || defined(TARGET_ALPHA) || \
6125 defined(TARGET_M68K)
6126 ret
= do_sigaltstack(arg1
, arg2
, get_sp_from_cpustate((CPUState
*)cpu_env
));
6131 case TARGET_NR_sendfile
:
6133 #ifdef TARGET_NR_getpmsg
6134 case TARGET_NR_getpmsg
:
6137 #ifdef TARGET_NR_putpmsg
6138 case TARGET_NR_putpmsg
:
6141 #ifdef TARGET_NR_vfork
6142 case TARGET_NR_vfork
:
6143 ret
= get_errno(do_fork(cpu_env
, CLONE_VFORK
| CLONE_VM
| SIGCHLD
,
6147 #ifdef TARGET_NR_ugetrlimit
6148 case TARGET_NR_ugetrlimit
:
6151 ret
= get_errno(getrlimit(arg1
, &rlim
));
6152 if (!is_error(ret
)) {
6153 struct target_rlimit
*target_rlim
;
6154 if (!lock_user_struct(VERIFY_WRITE
, target_rlim
, arg2
, 0))
6156 target_rlim
->rlim_cur
= tswapl(rlim
.rlim_cur
);
6157 target_rlim
->rlim_max
= tswapl(rlim
.rlim_max
);
6158 unlock_user_struct(target_rlim
, arg2
, 1);
6163 #ifdef TARGET_NR_truncate64
6164 case TARGET_NR_truncate64
:
6165 if (!(p
= lock_user_string(arg1
)))
6167 ret
= target_truncate64(cpu_env
, p
, arg2
, arg3
, arg4
);
6168 unlock_user(p
, arg1
, 0);
6171 #ifdef TARGET_NR_ftruncate64
6172 case TARGET_NR_ftruncate64
:
6173 ret
= target_ftruncate64(cpu_env
, arg1
, arg2
, arg3
, arg4
);
6176 #ifdef TARGET_NR_stat64
6177 case TARGET_NR_stat64
:
6178 if (!(p
= lock_user_string(arg1
)))
6180 ret
= get_errno(stat(path(p
), &st
));
6181 unlock_user(p
, arg1
, 0);
6183 ret
= host_to_target_stat64(cpu_env
, arg2
, &st
);
6186 #ifdef TARGET_NR_lstat64
6187 case TARGET_NR_lstat64
:
6188 if (!(p
= lock_user_string(arg1
)))
6190 ret
= get_errno(lstat(path(p
), &st
));
6191 unlock_user(p
, arg1
, 0);
6193 ret
= host_to_target_stat64(cpu_env
, arg2
, &st
);
6196 #ifdef TARGET_NR_fstat64
6197 case TARGET_NR_fstat64
:
6198 ret
= get_errno(fstat(arg1
, &st
));
6200 ret
= host_to_target_stat64(cpu_env
, arg2
, &st
);
6203 #if (defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat)) && \
6204 (defined(__NR_fstatat64) || defined(__NR_newfstatat))
6205 #ifdef TARGET_NR_fstatat64
6206 case TARGET_NR_fstatat64
:
6208 #ifdef TARGET_NR_newfstatat
6209 case TARGET_NR_newfstatat
:
6211 if (!(p
= lock_user_string(arg2
)))
6213 #ifdef __NR_fstatat64
6214 ret
= get_errno(sys_fstatat64(arg1
, path(p
), &st
, arg4
));
6216 ret
= get_errno(sys_newfstatat(arg1
, path(p
), &st
, arg4
));
6219 ret
= host_to_target_stat64(cpu_env
, arg3
, &st
);
6223 case TARGET_NR_lchown
:
6224 if (!(p
= lock_user_string(arg1
)))
6226 ret
= get_errno(lchown(p
, low2highuid(arg2
), low2highgid(arg3
)));
6227 unlock_user(p
, arg1
, 0);
6229 case TARGET_NR_getuid
:
6230 ret
= get_errno(high2lowuid(getuid()));
6232 case TARGET_NR_getgid
:
6233 ret
= get_errno(high2lowgid(getgid()));
6235 case TARGET_NR_geteuid
:
6236 ret
= get_errno(high2lowuid(geteuid()));
6238 case TARGET_NR_getegid
:
6239 ret
= get_errno(high2lowgid(getegid()));
6241 case TARGET_NR_setreuid
:
6242 ret
= get_errno(setreuid(low2highuid(arg1
), low2highuid(arg2
)));
6244 case TARGET_NR_setregid
:
6245 ret
= get_errno(setregid(low2highgid(arg1
), low2highgid(arg2
)));
6247 case TARGET_NR_getgroups
:
6249 int gidsetsize
= arg1
;
6250 uint16_t *target_grouplist
;
6254 grouplist
= alloca(gidsetsize
* sizeof(gid_t
));
6255 ret
= get_errno(getgroups(gidsetsize
, grouplist
));
6256 if (gidsetsize
== 0)
6258 if (!is_error(ret
)) {
6259 target_grouplist
= lock_user(VERIFY_WRITE
, arg2
, gidsetsize
* 2, 0);
6260 if (!target_grouplist
)
6262 for(i
= 0;i
< ret
; i
++)
6263 target_grouplist
[i
] = tswap16(grouplist
[i
]);
6264 unlock_user(target_grouplist
, arg2
, gidsetsize
* 2);
6268 case TARGET_NR_setgroups
:
6270 int gidsetsize
= arg1
;
6271 uint16_t *target_grouplist
;
6275 grouplist
= alloca(gidsetsize
* sizeof(gid_t
));
6276 target_grouplist
= lock_user(VERIFY_READ
, arg2
, gidsetsize
* 2, 1);
6277 if (!target_grouplist
) {
6278 ret
= -TARGET_EFAULT
;
6281 for(i
= 0;i
< gidsetsize
; i
++)
6282 grouplist
[i
] = tswap16(target_grouplist
[i
]);
6283 unlock_user(target_grouplist
, arg2
, 0);
6284 ret
= get_errno(setgroups(gidsetsize
, grouplist
));
6287 case TARGET_NR_fchown
:
6288 ret
= get_errno(fchown(arg1
, low2highuid(arg2
), low2highgid(arg3
)));
6290 #if defined(TARGET_NR_fchownat) && defined(__NR_fchownat)
6291 case TARGET_NR_fchownat
:
6292 if (!(p
= lock_user_string(arg2
)))
6294 ret
= get_errno(sys_fchownat(arg1
, p
, low2highuid(arg3
), low2highgid(arg4
), arg5
));
6295 unlock_user(p
, arg2
, 0);
6298 #ifdef TARGET_NR_setresuid
6299 case TARGET_NR_setresuid
:
6300 ret
= get_errno(setresuid(low2highuid(arg1
),
6302 low2highuid(arg3
)));
6305 #ifdef TARGET_NR_getresuid
6306 case TARGET_NR_getresuid
:
6308 uid_t ruid
, euid
, suid
;
6309 ret
= get_errno(getresuid(&ruid
, &euid
, &suid
));
6310 if (!is_error(ret
)) {
6311 if (put_user_u16(high2lowuid(ruid
), arg1
)
6312 || put_user_u16(high2lowuid(euid
), arg2
)
6313 || put_user_u16(high2lowuid(suid
), arg3
))
6319 #ifdef TARGET_NR_getresgid
6320 case TARGET_NR_setresgid
:
6321 ret
= get_errno(setresgid(low2highgid(arg1
),
6323 low2highgid(arg3
)));
6326 #ifdef TARGET_NR_getresgid
6327 case TARGET_NR_getresgid
:
6329 gid_t rgid
, egid
, sgid
;
6330 ret
= get_errno(getresgid(&rgid
, &egid
, &sgid
));
6331 if (!is_error(ret
)) {
6332 if (put_user_u16(high2lowgid(rgid
), arg1
)
6333 || put_user_u16(high2lowgid(egid
), arg2
)
6334 || put_user_u16(high2lowgid(sgid
), arg3
))
6340 case TARGET_NR_chown
:
6341 if (!(p
= lock_user_string(arg1
)))
6343 ret
= get_errno(chown(p
, low2highuid(arg2
), low2highgid(arg3
)));
6344 unlock_user(p
, arg1
, 0);
6346 case TARGET_NR_setuid
:
6347 ret
= get_errno(setuid(low2highuid(arg1
)));
6349 case TARGET_NR_setgid
:
6350 ret
= get_errno(setgid(low2highgid(arg1
)));
6352 case TARGET_NR_setfsuid
:
6353 ret
= get_errno(setfsuid(arg1
));
6355 case TARGET_NR_setfsgid
:
6356 ret
= get_errno(setfsgid(arg1
));
6358 #endif /* USE_UID16 */
6360 #ifdef TARGET_NR_lchown32
6361 case TARGET_NR_lchown32
:
6362 if (!(p
= lock_user_string(arg1
)))
6364 ret
= get_errno(lchown(p
, arg2
, arg3
));
6365 unlock_user(p
, arg1
, 0);
6368 #ifdef TARGET_NR_getuid32
6369 case TARGET_NR_getuid32
:
6370 ret
= get_errno(getuid());
6374 #if defined(TARGET_NR_getxuid) && defined(TARGET_ALPHA)
6375 /* Alpha specific */
6376 case TARGET_NR_getxuid
:
6380 ((CPUAlphaState
*)cpu_env
)->ir
[IR_A4
]=euid
;
6382 ret
= get_errno(getuid());
6385 #if defined(TARGET_NR_getxgid) && defined(TARGET_ALPHA)
6386 /* Alpha specific */
6387 case TARGET_NR_getxgid
:
6391 ((CPUAlphaState
*)cpu_env
)->ir
[IR_A4
]=egid
;
6393 ret
= get_errno(getgid());
6397 #ifdef TARGET_NR_getgid32
6398 case TARGET_NR_getgid32
:
6399 ret
= get_errno(getgid());
6402 #ifdef TARGET_NR_geteuid32
6403 case TARGET_NR_geteuid32
:
6404 ret
= get_errno(geteuid());
6407 #ifdef TARGET_NR_getegid32
6408 case TARGET_NR_getegid32
:
6409 ret
= get_errno(getegid());
6412 #ifdef TARGET_NR_setreuid32
6413 case TARGET_NR_setreuid32
:
6414 ret
= get_errno(setreuid(arg1
, arg2
));
6417 #ifdef TARGET_NR_setregid32
6418 case TARGET_NR_setregid32
:
6419 ret
= get_errno(setregid(arg1
, arg2
));
6422 #ifdef TARGET_NR_getgroups32
6423 case TARGET_NR_getgroups32
:
6425 int gidsetsize
= arg1
;
6426 uint32_t *target_grouplist
;
6430 grouplist
= alloca(gidsetsize
* sizeof(gid_t
));
6431 ret
= get_errno(getgroups(gidsetsize
, grouplist
));
6432 if (gidsetsize
== 0)
6434 if (!is_error(ret
)) {
6435 target_grouplist
= lock_user(VERIFY_WRITE
, arg2
, gidsetsize
* 4, 0);
6436 if (!target_grouplist
) {
6437 ret
= -TARGET_EFAULT
;
6440 for(i
= 0;i
< ret
; i
++)
6441 target_grouplist
[i
] = tswap32(grouplist
[i
]);
6442 unlock_user(target_grouplist
, arg2
, gidsetsize
* 4);
6447 #ifdef TARGET_NR_setgroups32
6448 case TARGET_NR_setgroups32
:
6450 int gidsetsize
= arg1
;
6451 uint32_t *target_grouplist
;
6455 grouplist
= alloca(gidsetsize
* sizeof(gid_t
));
6456 target_grouplist
= lock_user(VERIFY_READ
, arg2
, gidsetsize
* 4, 1);
6457 if (!target_grouplist
) {
6458 ret
= -TARGET_EFAULT
;
6461 for(i
= 0;i
< gidsetsize
; i
++)
6462 grouplist
[i
] = tswap32(target_grouplist
[i
]);
6463 unlock_user(target_grouplist
, arg2
, 0);
6464 ret
= get_errno(setgroups(gidsetsize
, grouplist
));
6468 #ifdef TARGET_NR_fchown32
6469 case TARGET_NR_fchown32
:
6470 ret
= get_errno(fchown(arg1
, arg2
, arg3
));
6473 #ifdef TARGET_NR_setresuid32
6474 case TARGET_NR_setresuid32
:
6475 ret
= get_errno(setresuid(arg1
, arg2
, arg3
));
6478 #ifdef TARGET_NR_getresuid32
6479 case TARGET_NR_getresuid32
:
6481 uid_t ruid
, euid
, suid
;
6482 ret
= get_errno(getresuid(&ruid
, &euid
, &suid
));
6483 if (!is_error(ret
)) {
6484 if (put_user_u32(ruid
, arg1
)
6485 || put_user_u32(euid
, arg2
)
6486 || put_user_u32(suid
, arg3
))
6492 #ifdef TARGET_NR_setresgid32
6493 case TARGET_NR_setresgid32
:
6494 ret
= get_errno(setresgid(arg1
, arg2
, arg3
));
6497 #ifdef TARGET_NR_getresgid32
6498 case TARGET_NR_getresgid32
:
6500 gid_t rgid
, egid
, sgid
;
6501 ret
= get_errno(getresgid(&rgid
, &egid
, &sgid
));
6502 if (!is_error(ret
)) {
6503 if (put_user_u32(rgid
, arg1
)
6504 || put_user_u32(egid
, arg2
)
6505 || put_user_u32(sgid
, arg3
))
6511 #ifdef TARGET_NR_chown32
6512 case TARGET_NR_chown32
:
6513 if (!(p
= lock_user_string(arg1
)))
6515 ret
= get_errno(chown(p
, arg2
, arg3
));
6516 unlock_user(p
, arg1
, 0);
6519 #ifdef TARGET_NR_setuid32
6520 case TARGET_NR_setuid32
:
6521 ret
= get_errno(setuid(arg1
));
6524 #ifdef TARGET_NR_setgid32
6525 case TARGET_NR_setgid32
:
6526 ret
= get_errno(setgid(arg1
));
6529 #ifdef TARGET_NR_setfsuid32
6530 case TARGET_NR_setfsuid32
:
6531 ret
= get_errno(setfsuid(arg1
));
6534 #ifdef TARGET_NR_setfsgid32
6535 case TARGET_NR_setfsgid32
:
6536 ret
= get_errno(setfsgid(arg1
));
6540 case TARGET_NR_pivot_root
:
6542 #ifdef TARGET_NR_mincore
6543 case TARGET_NR_mincore
:
6546 ret
= -TARGET_EFAULT
;
6547 if (!(a
= lock_user(VERIFY_READ
, arg1
,arg2
, 0)))
6549 if (!(p
= lock_user_string(arg3
)))
6551 ret
= get_errno(mincore(a
, arg2
, p
));
6552 unlock_user(p
, arg3
, ret
);
6554 unlock_user(a
, arg1
, 0);
6558 #ifdef TARGET_NR_arm_fadvise64_64
6559 case TARGET_NR_arm_fadvise64_64
:
6562 * arm_fadvise64_64 looks like fadvise64_64 but
6563 * with different argument order
6571 #if defined(TARGET_NR_fadvise64_64) || defined(TARGET_NR_arm_fadvise64_64) || defined(TARGET_NR_fadvise64)
6572 #ifdef TARGET_NR_fadvise64_64
6573 case TARGET_NR_fadvise64_64
:
6575 #ifdef TARGET_NR_fadvise64
6576 case TARGET_NR_fadvise64
:
6580 case 4: arg4
= POSIX_FADV_NOREUSE
+ 1; break; /* make sure it's an invalid value */
6581 case 5: arg4
= POSIX_FADV_NOREUSE
+ 2; break; /* ditto */
6582 case 6: arg4
= POSIX_FADV_DONTNEED
; break;
6583 case 7: arg4
= POSIX_FADV_NOREUSE
; break;
6587 ret
= -posix_fadvise(arg1
, arg2
, arg3
, arg4
);
6590 #ifdef TARGET_NR_madvise
6591 case TARGET_NR_madvise
:
6592 /* A straight passthrough may not be safe because qemu sometimes
6593 turns private flie-backed mappings into anonymous mappings.
6594 This will break MADV_DONTNEED.
6595 This is a hint, so ignoring and returning success is ok. */
6599 #if TARGET_ABI_BITS == 32
6600 case TARGET_NR_fcntl64
:
6604 struct target_flock64
*target_fl
;
6606 struct target_eabi_flock64
*target_efl
;
6609 cmd
= target_to_host_fcntl_cmd(arg2
);
6610 if (cmd
== -TARGET_EINVAL
)
6614 case TARGET_F_GETLK64
:
6616 if (((CPUARMState
*)cpu_env
)->eabi
) {
6617 if (!lock_user_struct(VERIFY_READ
, target_efl
, arg3
, 1))
6619 fl
.l_type
= tswap16(target_efl
->l_type
);
6620 fl
.l_whence
= tswap16(target_efl
->l_whence
);
6621 fl
.l_start
= tswap64(target_efl
->l_start
);
6622 fl
.l_len
= tswap64(target_efl
->l_len
);
6623 fl
.l_pid
= tswap32(target_efl
->l_pid
);
6624 unlock_user_struct(target_efl
, arg3
, 0);
6628 if (!lock_user_struct(VERIFY_READ
, target_fl
, arg3
, 1))
6630 fl
.l_type
= tswap16(target_fl
->l_type
);
6631 fl
.l_whence
= tswap16(target_fl
->l_whence
);
6632 fl
.l_start
= tswap64(target_fl
->l_start
);
6633 fl
.l_len
= tswap64(target_fl
->l_len
);
6634 fl
.l_pid
= tswap32(target_fl
->l_pid
);
6635 unlock_user_struct(target_fl
, arg3
, 0);
6637 ret
= get_errno(fcntl(arg1
, cmd
, &fl
));
6640 if (((CPUARMState
*)cpu_env
)->eabi
) {
6641 if (!lock_user_struct(VERIFY_WRITE
, target_efl
, arg3
, 0))
6643 target_efl
->l_type
= tswap16(fl
.l_type
);
6644 target_efl
->l_whence
= tswap16(fl
.l_whence
);
6645 target_efl
->l_start
= tswap64(fl
.l_start
);
6646 target_efl
->l_len
= tswap64(fl
.l_len
);
6647 target_efl
->l_pid
= tswap32(fl
.l_pid
);
6648 unlock_user_struct(target_efl
, arg3
, 1);
6652 if (!lock_user_struct(VERIFY_WRITE
, target_fl
, arg3
, 0))
6654 target_fl
->l_type
= tswap16(fl
.l_type
);
6655 target_fl
->l_whence
= tswap16(fl
.l_whence
);
6656 target_fl
->l_start
= tswap64(fl
.l_start
);
6657 target_fl
->l_len
= tswap64(fl
.l_len
);
6658 target_fl
->l_pid
= tswap32(fl
.l_pid
);
6659 unlock_user_struct(target_fl
, arg3
, 1);
6664 case TARGET_F_SETLK64
:
6665 case TARGET_F_SETLKW64
:
6667 if (((CPUARMState
*)cpu_env
)->eabi
) {
6668 if (!lock_user_struct(VERIFY_READ
, target_efl
, arg3
, 1))
6670 fl
.l_type
= tswap16(target_efl
->l_type
);
6671 fl
.l_whence
= tswap16(target_efl
->l_whence
);
6672 fl
.l_start
= tswap64(target_efl
->l_start
);
6673 fl
.l_len
= tswap64(target_efl
->l_len
);
6674 fl
.l_pid
= tswap32(target_efl
->l_pid
);
6675 unlock_user_struct(target_efl
, arg3
, 0);
6679 if (!lock_user_struct(VERIFY_READ
, target_fl
, arg3
, 1))
6681 fl
.l_type
= tswap16(target_fl
->l_type
);
6682 fl
.l_whence
= tswap16(target_fl
->l_whence
);
6683 fl
.l_start
= tswap64(target_fl
->l_start
);
6684 fl
.l_len
= tswap64(target_fl
->l_len
);
6685 fl
.l_pid
= tswap32(target_fl
->l_pid
);
6686 unlock_user_struct(target_fl
, arg3
, 0);
6688 ret
= get_errno(fcntl(arg1
, cmd
, &fl
));
6691 ret
= do_fcntl(arg1
, arg2
, arg3
);
6697 #ifdef TARGET_NR_cacheflush
6698 case TARGET_NR_cacheflush
:
6699 /* self-modifying code is handled automatically, so nothing needed */
6703 #ifdef TARGET_NR_security
6704 case TARGET_NR_security
:
6707 #ifdef TARGET_NR_getpagesize
6708 case TARGET_NR_getpagesize
:
6709 ret
= TARGET_PAGE_SIZE
;
6712 case TARGET_NR_gettid
:
6713 ret
= get_errno(gettid());
6715 #ifdef TARGET_NR_readahead
6716 case TARGET_NR_readahead
:
6717 #if TARGET_ABI_BITS == 32
6719 if (((CPUARMState
*)cpu_env
)->eabi
)
6726 ret
= get_errno(readahead(arg1
, ((off64_t
)arg3
<< 32) | arg2
, arg4
));
6728 ret
= get_errno(readahead(arg1
, arg2
, arg3
));
6732 #ifdef TARGET_NR_setxattr
6733 case TARGET_NR_setxattr
:
6734 case TARGET_NR_lsetxattr
:
6735 case TARGET_NR_fsetxattr
:
6736 case TARGET_NR_getxattr
:
6737 case TARGET_NR_lgetxattr
:
6738 case TARGET_NR_fgetxattr
:
6739 case TARGET_NR_listxattr
:
6740 case TARGET_NR_llistxattr
:
6741 case TARGET_NR_flistxattr
:
6742 case TARGET_NR_removexattr
:
6743 case TARGET_NR_lremovexattr
:
6744 case TARGET_NR_fremovexattr
:
6745 ret
= -TARGET_EOPNOTSUPP
;
6748 #ifdef TARGET_NR_set_thread_area
6749 case TARGET_NR_set_thread_area
:
6750 #if defined(TARGET_MIPS)
6751 ((CPUMIPSState
*) cpu_env
)->tls_value
= arg1
;
6754 #elif defined(TARGET_CRIS)
6756 ret
= -TARGET_EINVAL
;
6758 ((CPUCRISState
*) cpu_env
)->pregs
[PR_PID
] = arg1
;
6762 #elif defined(TARGET_I386) && defined(TARGET_ABI32)
6763 ret
= do_set_thread_area(cpu_env
, arg1
);
6766 goto unimplemented_nowarn
;
6769 #ifdef TARGET_NR_get_thread_area
6770 case TARGET_NR_get_thread_area
:
6771 #if defined(TARGET_I386) && defined(TARGET_ABI32)
6772 ret
= do_get_thread_area(cpu_env
, arg1
);
6774 goto unimplemented_nowarn
;
6777 #ifdef TARGET_NR_getdomainname
6778 case TARGET_NR_getdomainname
:
6779 goto unimplemented_nowarn
;
6782 #ifdef TARGET_NR_clock_gettime
6783 case TARGET_NR_clock_gettime
:
6786 ret
= get_errno(clock_gettime(arg1
, &ts
));
6787 if (!is_error(ret
)) {
6788 host_to_target_timespec(arg2
, &ts
);
6793 #ifdef TARGET_NR_clock_getres
6794 case TARGET_NR_clock_getres
:
6797 ret
= get_errno(clock_getres(arg1
, &ts
));
6798 if (!is_error(ret
)) {
6799 host_to_target_timespec(arg2
, &ts
);
6804 #ifdef TARGET_NR_clock_nanosleep
6805 case TARGET_NR_clock_nanosleep
:
6808 target_to_host_timespec(&ts
, arg3
);
6809 ret
= get_errno(clock_nanosleep(arg1
, arg2
, &ts
, arg4
? &ts
: NULL
));
6811 host_to_target_timespec(arg4
, &ts
);
6816 #if defined(TARGET_NR_set_tid_address) && defined(__NR_set_tid_address)
6817 case TARGET_NR_set_tid_address
:
6818 ret
= get_errno(set_tid_address((int *)g2h(arg1
)));
6822 #if defined(TARGET_NR_tkill) && defined(__NR_tkill)
6823 case TARGET_NR_tkill
:
6824 ret
= get_errno(sys_tkill((int)arg1
, target_to_host_signal(arg2
)));
6828 #if defined(TARGET_NR_tgkill) && defined(__NR_tgkill)
6829 case TARGET_NR_tgkill
:
6830 ret
= get_errno(sys_tgkill((int)arg1
, (int)arg2
,
6831 target_to_host_signal(arg3
)));
6835 #ifdef TARGET_NR_set_robust_list
6836 case TARGET_NR_set_robust_list
:
6837 goto unimplemented_nowarn
;
6840 #if defined(TARGET_NR_utimensat) && defined(__NR_utimensat)
6841 case TARGET_NR_utimensat
:
6843 struct timespec
*tsp
, ts
[2];
6847 target_to_host_timespec(ts
, arg3
);
6848 target_to_host_timespec(ts
+1, arg3
+sizeof(struct target_timespec
));
6852 ret
= get_errno(sys_utimensat(arg1
, NULL
, tsp
, arg4
));
6854 if (!(p
= lock_user_string(arg2
))) {
6855 ret
= -TARGET_EFAULT
;
6858 ret
= get_errno(sys_utimensat(arg1
, path(p
), tsp
, arg4
));
6859 unlock_user(p
, arg2
, 0);
6864 #if defined(CONFIG_USE_NPTL)
6865 case TARGET_NR_futex
:
6866 ret
= do_futex(arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
6869 #if defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init)
6870 case TARGET_NR_inotify_init
:
6871 ret
= get_errno(sys_inotify_init());
6874 #if defined(TARGET_NR_inotify_add_watch) && defined(__NR_inotify_add_watch)
6875 case TARGET_NR_inotify_add_watch
:
6876 p
= lock_user_string(arg2
);
6877 ret
= get_errno(sys_inotify_add_watch(arg1
, path(p
), arg3
));
6878 unlock_user(p
, arg2
, 0);
6881 #if defined(TARGET_NR_inotify_rm_watch) && defined(__NR_inotify_rm_watch)
6882 case TARGET_NR_inotify_rm_watch
:
6883 ret
= get_errno(sys_inotify_rm_watch(arg1
, arg2
));
6887 #if defined(TARGET_NR_mq_open) && defined(__NR_mq_open)
6888 case TARGET_NR_mq_open
:
6890 struct mq_attr posix_mq_attr
;
6892 p
= lock_user_string(arg1
- 1);
6894 copy_from_user_mq_attr (&posix_mq_attr
, arg4
);
6895 ret
= get_errno(mq_open(p
, arg2
, arg3
, &posix_mq_attr
));
6896 unlock_user (p
, arg1
, 0);
6900 case TARGET_NR_mq_unlink
:
6901 p
= lock_user_string(arg1
- 1);
6902 ret
= get_errno(mq_unlink(p
));
6903 unlock_user (p
, arg1
, 0);
6906 case TARGET_NR_mq_timedsend
:
6910 p
= lock_user (VERIFY_READ
, arg2
, arg3
, 1);
6912 target_to_host_timespec(&ts
, arg5
);
6913 ret
= get_errno(mq_timedsend(arg1
, p
, arg3
, arg4
, &ts
));
6914 host_to_target_timespec(arg5
, &ts
);
6917 ret
= get_errno(mq_send(arg1
, p
, arg3
, arg4
));
6918 unlock_user (p
, arg2
, arg3
);
6922 case TARGET_NR_mq_timedreceive
:
6927 p
= lock_user (VERIFY_READ
, arg2
, arg3
, 1);
6929 target_to_host_timespec(&ts
, arg5
);
6930 ret
= get_errno(mq_timedreceive(arg1
, p
, arg3
, &prio
, &ts
));
6931 host_to_target_timespec(arg5
, &ts
);
6934 ret
= get_errno(mq_receive(arg1
, p
, arg3
, &prio
));
6935 unlock_user (p
, arg2
, arg3
);
6937 put_user_u32(prio
, arg4
);
6941 /* Not implemented for now... */
6942 /* case TARGET_NR_mq_notify: */
6945 case TARGET_NR_mq_getsetattr
:
6947 struct mq_attr posix_mq_attr_in
, posix_mq_attr_out
;
6950 ret
= mq_getattr(arg1
, &posix_mq_attr_out
);
6951 copy_to_user_mq_attr(arg3
, &posix_mq_attr_out
);
6954 copy_from_user_mq_attr(&posix_mq_attr_in
, arg2
);
6955 ret
|= mq_setattr(arg1
, &posix_mq_attr_in
, &posix_mq_attr_out
);
6962 #ifdef CONFIG_SPLICE
6963 #ifdef TARGET_NR_tee
6966 ret
= get_errno(tee(arg1
,arg2
,arg3
,arg4
));
6970 #ifdef TARGET_NR_splice
6971 case TARGET_NR_splice
:
6973 loff_t loff_in
, loff_out
;
6974 loff_t
*ploff_in
= NULL
, *ploff_out
= NULL
;
6976 get_user_u64(loff_in
, arg2
);
6977 ploff_in
= &loff_in
;
6980 get_user_u64(loff_out
, arg2
);
6981 ploff_out
= &loff_out
;
6983 ret
= get_errno(splice(arg1
, ploff_in
, arg3
, ploff_out
, arg5
, arg6
));
6987 #ifdef TARGET_NR_vmsplice
6988 case TARGET_NR_vmsplice
:
6993 vec
= alloca(count
* sizeof(struct iovec
));
6994 if (lock_iovec(VERIFY_READ
, vec
, arg2
, count
, 1) < 0)
6996 ret
= get_errno(vmsplice(arg1
, vec
, count
, arg4
));
6997 unlock_iovec(vec
, arg2
, count
, 0);
7001 #endif /* CONFIG_SPLICE */
7002 #ifdef CONFIG_EVENTFD
7003 #if defined(TARGET_NR_eventfd)
7004 case TARGET_NR_eventfd
:
7005 ret
= get_errno(eventfd(arg1
, 0));
7008 #if defined(TARGET_NR_eventfd2)
7009 case TARGET_NR_eventfd2
:
7010 ret
= get_errno(eventfd(arg1
, arg2
));
7013 #endif /* CONFIG_EVENTFD */
7016 gemu_log("qemu: Unsupported syscall: %d\n", num
);
7017 #if defined(TARGET_NR_setxattr) || defined(TARGET_NR_get_thread_area) || defined(TARGET_NR_getdomainname) || defined(TARGET_NR_set_robust_list)
7018 unimplemented_nowarn
:
7020 ret
= -TARGET_ENOSYS
;
7025 gemu_log(" = " TARGET_ABI_FMT_ld
"\n", ret
);
7028 print_syscall_ret(num
, ret
);
7031 ret
= -TARGET_EFAULT
;