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, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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>
47 #include <sys/times.h>
50 #include <sys/statfs.h>
52 #include <sys/sysinfo.h>
53 //#include <sys/user.h>
54 #include <netinet/ip.h>
55 #include <netinet/tcp.h>
57 #define termios host_termios
58 #define winsize host_winsize
59 #define termio host_termio
60 #define sgttyb host_sgttyb /* same as target */
61 #define tchars host_tchars /* same as target */
62 #define ltchars host_ltchars /* same as target */
64 #include <linux/termios.h>
65 #include <linux/unistd.h>
66 #include <linux/utsname.h>
67 #include <linux/cdrom.h>
68 #include <linux/hdreg.h>
69 #include <linux/soundcard.h>
70 #include <linux/dirent.h>
72 #include "linux_loop.h"
75 #include "qemu-common.h"
78 #include <linux/futex.h>
79 #define CLONE_NPTL_FLAGS2 (CLONE_SETTLS | \
80 CLONE_PARENT_SETTID | CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID)
82 /* XXX: Hardcode the above values. */
83 #define CLONE_NPTL_FLAGS2 0
88 #if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_SPARC) \
89 || defined(TARGET_M68K) || defined(TARGET_SH4) || defined(TARGET_CRIS)
90 /* 16 bit uid wrappers emulation */
94 //#include <linux/msdos_fs.h>
95 #define VFAT_IOCTL_READDIR_BOTH _IOR('r', 1, struct dirent [2])
96 #define VFAT_IOCTL_READDIR_SHORT _IOR('r', 2, struct dirent [2])
107 #define _syscall0(type,name) \
110 return syscall(__NR_##name); \
113 #define _syscall1(type,name,type1,arg1) \
114 type name (type1 arg1) \
116 return syscall(__NR_##name, arg1); \
119 #define _syscall2(type,name,type1,arg1,type2,arg2) \
120 type name (type1 arg1,type2 arg2) \
122 return syscall(__NR_##name, arg1, arg2); \
125 #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
126 type name (type1 arg1,type2 arg2,type3 arg3) \
128 return syscall(__NR_##name, arg1, arg2, arg3); \
131 #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
132 type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4) \
134 return syscall(__NR_##name, arg1, arg2, arg3, arg4); \
137 #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
139 type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \
141 return syscall(__NR_##name, arg1, arg2, arg3, arg4, arg5); \
145 #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
146 type5,arg5,type6,arg6) \
147 type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5,type6 arg6) \
149 return syscall(__NR_##name, arg1, arg2, arg3, arg4, arg5, arg6); \
153 #define __NR_sys_uname __NR_uname
154 #define __NR_sys_faccessat __NR_faccessat
155 #define __NR_sys_fchmodat __NR_fchmodat
156 #define __NR_sys_fchownat __NR_fchownat
157 #define __NR_sys_getcwd1 __NR_getcwd
158 #define __NR_sys_getdents __NR_getdents
159 #define __NR_sys_getdents64 __NR_getdents64
160 #define __NR_sys_getpriority __NR_getpriority
161 #define __NR_sys_linkat __NR_linkat
162 #define __NR_sys_mkdirat __NR_mkdirat
163 #define __NR_sys_mknodat __NR_mknodat
164 #define __NR_sys_openat __NR_openat
165 #define __NR_sys_readlinkat __NR_readlinkat
166 #define __NR_sys_renameat __NR_renameat
167 #define __NR_sys_rt_sigqueueinfo __NR_rt_sigqueueinfo
168 #define __NR_sys_symlinkat __NR_symlinkat
169 #define __NR_sys_syslog __NR_syslog
170 #define __NR_sys_tgkill __NR_tgkill
171 #define __NR_sys_tkill __NR_tkill
172 #define __NR_sys_unlinkat __NR_unlinkat
173 #define __NR_sys_utimensat __NR_utimensat
174 #define __NR_sys_futex __NR_futex
176 #if defined(__alpha__) || defined (__ia64__) || defined(__x86_64__)
177 #define __NR__llseek __NR_lseek
181 _syscall0(int, gettid
)
183 /* This is a replacement for the host gettid() and must return a host
185 static int gettid(void) {
189 _syscall1(int,sys_uname
,struct new_utsname
*,buf
)
190 #if defined(TARGET_NR_faccessat) && defined(__NR_faccessat)
191 _syscall4(int,sys_faccessat
,int,dirfd
,const char *,pathname
,int,mode
,int,flags
)
193 #if defined(TARGET_NR_fchmodat) && defined(__NR_fchmodat)
194 _syscall4(int,sys_fchmodat
,int,dirfd
,const char *,pathname
,
195 mode_t
,mode
,int,flags
)
197 #if defined(TARGET_NR_fchownat) && defined(__NR_fchownat)
198 _syscall5(int,sys_fchownat
,int,dirfd
,const char *,pathname
,
199 uid_t
,owner
,gid_t
,group
,int,flags
)
201 _syscall2(int,sys_getcwd1
,char *,buf
,size_t,size
)
202 _syscall3(int, sys_getdents
, uint
, fd
, struct dirent
*, dirp
, uint
, count
);
203 #if defined(TARGET_NR_getdents64) && defined(__NR_getdents64)
204 _syscall3(int, sys_getdents64
, uint
, fd
, struct dirent64
*, dirp
, uint
, count
);
206 _syscall2(int, sys_getpriority
, int, which
, int, who
);
207 _syscall5(int, _llseek
, uint
, fd
, ulong
, hi
, ulong
, lo
,
208 loff_t
*, res
, uint
, wh
);
209 #if defined(TARGET_NR_linkat) && defined(__NR_linkat)
210 _syscall5(int,sys_linkat
,int,olddirfd
,const char *,oldpath
,
211 int,newdirfd
,const char *,newpath
,int,flags
)
213 #if defined(TARGET_NR_mkdirat) && defined(__NR_mkdirat)
214 _syscall3(int,sys_mkdirat
,int,dirfd
,const char *,pathname
,mode_t
,mode
)
216 #if defined(TARGET_NR_mknodat) && defined(__NR_mknodat)
217 _syscall4(int,sys_mknodat
,int,dirfd
,const char *,pathname
,
218 mode_t
,mode
,dev_t
,dev
)
220 #if defined(TARGET_NR_openat) && defined(__NR_openat)
221 _syscall4(int,sys_openat
,int,dirfd
,const char *,pathname
,int,flags
,mode_t
,mode
)
223 #if defined(TARGET_NR_readlinkat) && defined(__NR_readlinkat)
224 _syscall4(int,sys_readlinkat
,int,dirfd
,const char *,pathname
,
225 char *,buf
,size_t,bufsize
)
227 #if defined(TARGET_NR_renameat) && defined(__NR_renameat)
228 _syscall4(int,sys_renameat
,int,olddirfd
,const char *,oldpath
,
229 int,newdirfd
,const char *,newpath
)
231 _syscall3(int,sys_rt_sigqueueinfo
,int,pid
,int,sig
,siginfo_t
*,uinfo
)
232 #if defined(TARGET_NR_symlinkat) && defined(__NR_symlinkat)
233 _syscall3(int,sys_symlinkat
,const char *,oldpath
,
234 int,newdirfd
,const char *,newpath
)
236 _syscall3(int,sys_syslog
,int,type
,char*,bufp
,int,len
)
237 #if defined(TARGET_NR_tgkill) && defined(__NR_tgkill)
238 _syscall3(int,sys_tgkill
,int,tgid
,int,pid
,int,sig
)
240 #if defined(TARGET_NR_tkill) && defined(__NR_tkill)
241 _syscall2(int,sys_tkill
,int,tid
,int,sig
)
243 #ifdef __NR_exit_group
244 _syscall1(int,exit_group
,int,error_code
)
246 #if defined(TARGET_NR_set_tid_address) && defined(__NR_set_tid_address)
247 _syscall1(int,set_tid_address
,int *,tidptr
)
249 #if defined(TARGET_NR_unlinkat) && defined(__NR_unlinkat)
250 _syscall3(int,sys_unlinkat
,int,dirfd
,const char *,pathname
,int,flags
)
252 #if defined(TARGET_NR_utimensat) && defined(__NR_utimensat)
253 _syscall4(int,sys_utimensat
,int,dirfd
,const char *,pathname
,
254 const struct timespec
*,tsp
,int,flags
)
256 #if defined(TARGET_NR_futex) && defined(__NR_futex)
257 _syscall6(int,sys_futex
,int *,uaddr
,int,op
,int,val
,
258 const struct timespec
*,timeout
,int *,uaddr2
,int,val3
)
262 extern int personality(int);
263 extern int flock(int, int);
264 extern int setfsuid(int);
265 extern int setfsgid(int);
266 extern int setresuid(uid_t
, uid_t
, uid_t
);
267 extern int getresuid(uid_t
*, uid_t
*, uid_t
*);
268 extern int setresgid(gid_t
, gid_t
, gid_t
);
269 extern int getresgid(gid_t
*, gid_t
*, gid_t
*);
270 extern int setgroups(int, gid_t
*);
272 #define ERRNO_TABLE_SIZE 1200
274 /* target_to_host_errno_table[] is initialized from
275 * host_to_target_errno_table[] in syscall_init(). */
276 static uint16_t target_to_host_errno_table
[ERRNO_TABLE_SIZE
] = {
280 * This list is the union of errno values overridden in asm-<arch>/errno.h
281 * minus the errnos that are not actually generic to all archs.
283 static uint16_t host_to_target_errno_table
[ERRNO_TABLE_SIZE
] = {
284 [EIDRM
] = TARGET_EIDRM
,
285 [ECHRNG
] = TARGET_ECHRNG
,
286 [EL2NSYNC
] = TARGET_EL2NSYNC
,
287 [EL3HLT
] = TARGET_EL3HLT
,
288 [EL3RST
] = TARGET_EL3RST
,
289 [ELNRNG
] = TARGET_ELNRNG
,
290 [EUNATCH
] = TARGET_EUNATCH
,
291 [ENOCSI
] = TARGET_ENOCSI
,
292 [EL2HLT
] = TARGET_EL2HLT
,
293 [EDEADLK
] = TARGET_EDEADLK
,
294 [ENOLCK
] = TARGET_ENOLCK
,
295 [EBADE
] = TARGET_EBADE
,
296 [EBADR
] = TARGET_EBADR
,
297 [EXFULL
] = TARGET_EXFULL
,
298 [ENOANO
] = TARGET_ENOANO
,
299 [EBADRQC
] = TARGET_EBADRQC
,
300 [EBADSLT
] = TARGET_EBADSLT
,
301 [EBFONT
] = TARGET_EBFONT
,
302 [ENOSTR
] = TARGET_ENOSTR
,
303 [ENODATA
] = TARGET_ENODATA
,
304 [ETIME
] = TARGET_ETIME
,
305 [ENOSR
] = TARGET_ENOSR
,
306 [ENONET
] = TARGET_ENONET
,
307 [ENOPKG
] = TARGET_ENOPKG
,
308 [EREMOTE
] = TARGET_EREMOTE
,
309 [ENOLINK
] = TARGET_ENOLINK
,
310 [EADV
] = TARGET_EADV
,
311 [ESRMNT
] = TARGET_ESRMNT
,
312 [ECOMM
] = TARGET_ECOMM
,
313 [EPROTO
] = TARGET_EPROTO
,
314 [EDOTDOT
] = TARGET_EDOTDOT
,
315 [EMULTIHOP
] = TARGET_EMULTIHOP
,
316 [EBADMSG
] = TARGET_EBADMSG
,
317 [ENAMETOOLONG
] = TARGET_ENAMETOOLONG
,
318 [EOVERFLOW
] = TARGET_EOVERFLOW
,
319 [ENOTUNIQ
] = TARGET_ENOTUNIQ
,
320 [EBADFD
] = TARGET_EBADFD
,
321 [EREMCHG
] = TARGET_EREMCHG
,
322 [ELIBACC
] = TARGET_ELIBACC
,
323 [ELIBBAD
] = TARGET_ELIBBAD
,
324 [ELIBSCN
] = TARGET_ELIBSCN
,
325 [ELIBMAX
] = TARGET_ELIBMAX
,
326 [ELIBEXEC
] = TARGET_ELIBEXEC
,
327 [EILSEQ
] = TARGET_EILSEQ
,
328 [ENOSYS
] = TARGET_ENOSYS
,
329 [ELOOP
] = TARGET_ELOOP
,
330 [ERESTART
] = TARGET_ERESTART
,
331 [ESTRPIPE
] = TARGET_ESTRPIPE
,
332 [ENOTEMPTY
] = TARGET_ENOTEMPTY
,
333 [EUSERS
] = TARGET_EUSERS
,
334 [ENOTSOCK
] = TARGET_ENOTSOCK
,
335 [EDESTADDRREQ
] = TARGET_EDESTADDRREQ
,
336 [EMSGSIZE
] = TARGET_EMSGSIZE
,
337 [EPROTOTYPE
] = TARGET_EPROTOTYPE
,
338 [ENOPROTOOPT
] = TARGET_ENOPROTOOPT
,
339 [EPROTONOSUPPORT
] = TARGET_EPROTONOSUPPORT
,
340 [ESOCKTNOSUPPORT
] = TARGET_ESOCKTNOSUPPORT
,
341 [EOPNOTSUPP
] = TARGET_EOPNOTSUPP
,
342 [EPFNOSUPPORT
] = TARGET_EPFNOSUPPORT
,
343 [EAFNOSUPPORT
] = TARGET_EAFNOSUPPORT
,
344 [EADDRINUSE
] = TARGET_EADDRINUSE
,
345 [EADDRNOTAVAIL
] = TARGET_EADDRNOTAVAIL
,
346 [ENETDOWN
] = TARGET_ENETDOWN
,
347 [ENETUNREACH
] = TARGET_ENETUNREACH
,
348 [ENETRESET
] = TARGET_ENETRESET
,
349 [ECONNABORTED
] = TARGET_ECONNABORTED
,
350 [ECONNRESET
] = TARGET_ECONNRESET
,
351 [ENOBUFS
] = TARGET_ENOBUFS
,
352 [EISCONN
] = TARGET_EISCONN
,
353 [ENOTCONN
] = TARGET_ENOTCONN
,
354 [EUCLEAN
] = TARGET_EUCLEAN
,
355 [ENOTNAM
] = TARGET_ENOTNAM
,
356 [ENAVAIL
] = TARGET_ENAVAIL
,
357 [EISNAM
] = TARGET_EISNAM
,
358 [EREMOTEIO
] = TARGET_EREMOTEIO
,
359 [ESHUTDOWN
] = TARGET_ESHUTDOWN
,
360 [ETOOMANYREFS
] = TARGET_ETOOMANYREFS
,
361 [ETIMEDOUT
] = TARGET_ETIMEDOUT
,
362 [ECONNREFUSED
] = TARGET_ECONNREFUSED
,
363 [EHOSTDOWN
] = TARGET_EHOSTDOWN
,
364 [EHOSTUNREACH
] = TARGET_EHOSTUNREACH
,
365 [EALREADY
] = TARGET_EALREADY
,
366 [EINPROGRESS
] = TARGET_EINPROGRESS
,
367 [ESTALE
] = TARGET_ESTALE
,
368 [ECANCELED
] = TARGET_ECANCELED
,
369 [ENOMEDIUM
] = TARGET_ENOMEDIUM
,
370 [EMEDIUMTYPE
] = TARGET_EMEDIUMTYPE
,
372 [ENOKEY
] = TARGET_ENOKEY
,
375 [EKEYEXPIRED
] = TARGET_EKEYEXPIRED
,
378 [EKEYREVOKED
] = TARGET_EKEYREVOKED
,
381 [EKEYREJECTED
] = TARGET_EKEYREJECTED
,
384 [EOWNERDEAD
] = TARGET_EOWNERDEAD
,
386 #ifdef ENOTRECOVERABLE
387 [ENOTRECOVERABLE
] = TARGET_ENOTRECOVERABLE
,
391 static inline int host_to_target_errno(int err
)
393 if(host_to_target_errno_table
[err
])
394 return host_to_target_errno_table
[err
];
398 static inline int target_to_host_errno(int err
)
400 if (target_to_host_errno_table
[err
])
401 return target_to_host_errno_table
[err
];
405 static inline abi_long
get_errno(abi_long ret
)
408 return -host_to_target_errno(errno
);
413 static inline int is_error(abi_long ret
)
415 return (abi_ulong
)ret
>= (abi_ulong
)(-4096);
418 char *target_strerror(int err
)
420 return strerror(target_to_host_errno(err
));
423 static abi_ulong target_brk
;
424 static abi_ulong target_original_brk
;
426 void target_set_brk(abi_ulong new_brk
)
428 target_original_brk
= target_brk
= HOST_PAGE_ALIGN(new_brk
);
431 /* do_brk() must return target values and target errnos. */
432 abi_long
do_brk(abi_ulong new_brk
)
435 abi_long mapped_addr
;
440 if (new_brk
< target_original_brk
)
443 brk_page
= HOST_PAGE_ALIGN(target_brk
);
445 /* If the new brk is less than this, set it and we're done... */
446 if (new_brk
< brk_page
) {
447 target_brk
= new_brk
;
451 /* We need to allocate more memory after the brk... */
452 new_alloc_size
= HOST_PAGE_ALIGN(new_brk
- brk_page
+ 1);
453 mapped_addr
= get_errno(target_mmap(brk_page
, new_alloc_size
,
454 PROT_READ
|PROT_WRITE
,
455 MAP_ANON
|MAP_FIXED
|MAP_PRIVATE
, 0, 0));
457 if (!is_error(mapped_addr
))
458 target_brk
= new_brk
;
463 static inline abi_long
copy_from_user_fdset(fd_set
*fds
,
464 abi_ulong target_fds_addr
,
468 abi_ulong b
, *target_fds
;
470 nw
= (n
+ TARGET_ABI_BITS
- 1) / TARGET_ABI_BITS
;
471 if (!(target_fds
= lock_user(VERIFY_READ
,
473 sizeof(abi_ulong
) * nw
,
475 return -TARGET_EFAULT
;
479 for (i
= 0; i
< nw
; i
++) {
480 /* grab the abi_ulong */
481 __get_user(b
, &target_fds
[i
]);
482 for (j
= 0; j
< TARGET_ABI_BITS
; j
++) {
483 /* check the bit inside the abi_ulong */
490 unlock_user(target_fds
, target_fds_addr
, 0);
495 static inline abi_long
copy_to_user_fdset(abi_ulong target_fds_addr
,
501 abi_ulong
*target_fds
;
503 nw
= (n
+ TARGET_ABI_BITS
- 1) / TARGET_ABI_BITS
;
504 if (!(target_fds
= lock_user(VERIFY_WRITE
,
506 sizeof(abi_ulong
) * nw
,
508 return -TARGET_EFAULT
;
511 for (i
= 0; i
< nw
; i
++) {
513 for (j
= 0; j
< TARGET_ABI_BITS
; j
++) {
514 v
|= ((FD_ISSET(k
, fds
) != 0) << j
);
517 __put_user(v
, &target_fds
[i
]);
520 unlock_user(target_fds
, target_fds_addr
, sizeof(abi_ulong
) * nw
);
525 #if defined(__alpha__)
531 static inline abi_long
host_to_target_clock_t(long ticks
)
533 #if HOST_HZ == TARGET_HZ
536 return ((int64_t)ticks
* TARGET_HZ
) / HOST_HZ
;
540 static inline abi_long
host_to_target_rusage(abi_ulong target_addr
,
541 const struct rusage
*rusage
)
543 struct target_rusage
*target_rusage
;
545 if (!lock_user_struct(VERIFY_WRITE
, target_rusage
, target_addr
, 0))
546 return -TARGET_EFAULT
;
547 target_rusage
->ru_utime
.tv_sec
= tswapl(rusage
->ru_utime
.tv_sec
);
548 target_rusage
->ru_utime
.tv_usec
= tswapl(rusage
->ru_utime
.tv_usec
);
549 target_rusage
->ru_stime
.tv_sec
= tswapl(rusage
->ru_stime
.tv_sec
);
550 target_rusage
->ru_stime
.tv_usec
= tswapl(rusage
->ru_stime
.tv_usec
);
551 target_rusage
->ru_maxrss
= tswapl(rusage
->ru_maxrss
);
552 target_rusage
->ru_ixrss
= tswapl(rusage
->ru_ixrss
);
553 target_rusage
->ru_idrss
= tswapl(rusage
->ru_idrss
);
554 target_rusage
->ru_isrss
= tswapl(rusage
->ru_isrss
);
555 target_rusage
->ru_minflt
= tswapl(rusage
->ru_minflt
);
556 target_rusage
->ru_majflt
= tswapl(rusage
->ru_majflt
);
557 target_rusage
->ru_nswap
= tswapl(rusage
->ru_nswap
);
558 target_rusage
->ru_inblock
= tswapl(rusage
->ru_inblock
);
559 target_rusage
->ru_oublock
= tswapl(rusage
->ru_oublock
);
560 target_rusage
->ru_msgsnd
= tswapl(rusage
->ru_msgsnd
);
561 target_rusage
->ru_msgrcv
= tswapl(rusage
->ru_msgrcv
);
562 target_rusage
->ru_nsignals
= tswapl(rusage
->ru_nsignals
);
563 target_rusage
->ru_nvcsw
= tswapl(rusage
->ru_nvcsw
);
564 target_rusage
->ru_nivcsw
= tswapl(rusage
->ru_nivcsw
);
565 unlock_user_struct(target_rusage
, target_addr
, 1);
570 static inline abi_long
copy_from_user_timeval(struct timeval
*tv
,
571 abi_ulong target_tv_addr
)
573 struct target_timeval
*target_tv
;
575 if (!lock_user_struct(VERIFY_READ
, target_tv
, target_tv_addr
, 1))
576 return -TARGET_EFAULT
;
578 __get_user(tv
->tv_sec
, &target_tv
->tv_sec
);
579 __get_user(tv
->tv_usec
, &target_tv
->tv_usec
);
581 unlock_user_struct(target_tv
, target_tv_addr
, 0);
586 static inline abi_long
copy_to_user_timeval(abi_ulong target_tv_addr
,
587 const struct timeval
*tv
)
589 struct target_timeval
*target_tv
;
591 if (!lock_user_struct(VERIFY_WRITE
, target_tv
, target_tv_addr
, 0))
592 return -TARGET_EFAULT
;
594 __put_user(tv
->tv_sec
, &target_tv
->tv_sec
);
595 __put_user(tv
->tv_usec
, &target_tv
->tv_usec
);
597 unlock_user_struct(target_tv
, target_tv_addr
, 1);
603 /* do_select() must return target values and target errnos. */
604 static abi_long
do_select(int n
,
605 abi_ulong rfd_addr
, abi_ulong wfd_addr
,
606 abi_ulong efd_addr
, abi_ulong target_tv_addr
)
608 fd_set rfds
, wfds
, efds
;
609 fd_set
*rfds_ptr
, *wfds_ptr
, *efds_ptr
;
610 struct timeval tv
, *tv_ptr
;
614 if (copy_from_user_fdset(&rfds
, rfd_addr
, n
))
615 return -TARGET_EFAULT
;
621 if (copy_from_user_fdset(&wfds
, wfd_addr
, n
))
622 return -TARGET_EFAULT
;
628 if (copy_from_user_fdset(&efds
, efd_addr
, n
))
629 return -TARGET_EFAULT
;
635 if (target_tv_addr
) {
636 if (copy_from_user_timeval(&tv
, target_tv_addr
))
637 return -TARGET_EFAULT
;
643 ret
= get_errno(select(n
, rfds_ptr
, wfds_ptr
, efds_ptr
, tv_ptr
));
645 if (!is_error(ret
)) {
646 if (rfd_addr
&& copy_to_user_fdset(rfd_addr
, &rfds
, n
))
647 return -TARGET_EFAULT
;
648 if (wfd_addr
&& copy_to_user_fdset(wfd_addr
, &wfds
, n
))
649 return -TARGET_EFAULT
;
650 if (efd_addr
&& copy_to_user_fdset(efd_addr
, &efds
, n
))
651 return -TARGET_EFAULT
;
653 if (target_tv_addr
&& copy_to_user_timeval(target_tv_addr
, &tv
))
654 return -TARGET_EFAULT
;
660 static inline abi_long
target_to_host_sockaddr(struct sockaddr
*addr
,
661 abi_ulong target_addr
,
664 struct target_sockaddr
*target_saddr
;
666 target_saddr
= lock_user(VERIFY_READ
, target_addr
, len
, 1);
668 return -TARGET_EFAULT
;
669 memcpy(addr
, target_saddr
, len
);
670 addr
->sa_family
= tswap16(target_saddr
->sa_family
);
671 unlock_user(target_saddr
, target_addr
, 0);
676 static inline abi_long
host_to_target_sockaddr(abi_ulong target_addr
,
677 struct sockaddr
*addr
,
680 struct target_sockaddr
*target_saddr
;
682 target_saddr
= lock_user(VERIFY_WRITE
, target_addr
, len
, 0);
684 return -TARGET_EFAULT
;
685 memcpy(target_saddr
, addr
, len
);
686 target_saddr
->sa_family
= tswap16(addr
->sa_family
);
687 unlock_user(target_saddr
, target_addr
, len
);
692 /* ??? Should this also swap msgh->name? */
693 static inline abi_long
target_to_host_cmsg(struct msghdr
*msgh
,
694 struct target_msghdr
*target_msgh
)
696 struct cmsghdr
*cmsg
= CMSG_FIRSTHDR(msgh
);
697 abi_long msg_controllen
;
698 abi_ulong target_cmsg_addr
;
699 struct target_cmsghdr
*target_cmsg
;
702 msg_controllen
= tswapl(target_msgh
->msg_controllen
);
703 if (msg_controllen
< sizeof (struct target_cmsghdr
))
705 target_cmsg_addr
= tswapl(target_msgh
->msg_control
);
706 target_cmsg
= lock_user(VERIFY_READ
, target_cmsg_addr
, msg_controllen
, 1);
708 return -TARGET_EFAULT
;
710 while (cmsg
&& target_cmsg
) {
711 void *data
= CMSG_DATA(cmsg
);
712 void *target_data
= TARGET_CMSG_DATA(target_cmsg
);
714 int len
= tswapl(target_cmsg
->cmsg_len
)
715 - TARGET_CMSG_ALIGN(sizeof (struct target_cmsghdr
));
717 space
+= CMSG_SPACE(len
);
718 if (space
> msgh
->msg_controllen
) {
719 space
-= CMSG_SPACE(len
);
720 gemu_log("Host cmsg overflow\n");
724 cmsg
->cmsg_level
= tswap32(target_cmsg
->cmsg_level
);
725 cmsg
->cmsg_type
= tswap32(target_cmsg
->cmsg_type
);
726 cmsg
->cmsg_len
= CMSG_LEN(len
);
728 if (cmsg
->cmsg_level
!= TARGET_SOL_SOCKET
|| cmsg
->cmsg_type
!= SCM_RIGHTS
) {
729 gemu_log("Unsupported ancillary data: %d/%d\n", cmsg
->cmsg_level
, cmsg
->cmsg_type
);
730 memcpy(data
, target_data
, len
);
732 int *fd
= (int *)data
;
733 int *target_fd
= (int *)target_data
;
734 int i
, numfds
= len
/ sizeof(int);
736 for (i
= 0; i
< numfds
; i
++)
737 fd
[i
] = tswap32(target_fd
[i
]);
740 cmsg
= CMSG_NXTHDR(msgh
, cmsg
);
741 target_cmsg
= TARGET_CMSG_NXTHDR(target_msgh
, target_cmsg
);
743 unlock_user(target_cmsg
, target_cmsg_addr
, 0);
745 msgh
->msg_controllen
= space
;
749 /* ??? Should this also swap msgh->name? */
750 static inline abi_long
host_to_target_cmsg(struct target_msghdr
*target_msgh
,
753 struct cmsghdr
*cmsg
= CMSG_FIRSTHDR(msgh
);
754 abi_long msg_controllen
;
755 abi_ulong target_cmsg_addr
;
756 struct target_cmsghdr
*target_cmsg
;
759 msg_controllen
= tswapl(target_msgh
->msg_controllen
);
760 if (msg_controllen
< sizeof (struct target_cmsghdr
))
762 target_cmsg_addr
= tswapl(target_msgh
->msg_control
);
763 target_cmsg
= lock_user(VERIFY_WRITE
, target_cmsg_addr
, msg_controllen
, 0);
765 return -TARGET_EFAULT
;
767 while (cmsg
&& target_cmsg
) {
768 void *data
= CMSG_DATA(cmsg
);
769 void *target_data
= TARGET_CMSG_DATA(target_cmsg
);
771 int len
= cmsg
->cmsg_len
- CMSG_ALIGN(sizeof (struct cmsghdr
));
773 space
+= TARGET_CMSG_SPACE(len
);
774 if (space
> msg_controllen
) {
775 space
-= TARGET_CMSG_SPACE(len
);
776 gemu_log("Target cmsg overflow\n");
780 target_cmsg
->cmsg_level
= tswap32(cmsg
->cmsg_level
);
781 target_cmsg
->cmsg_type
= tswap32(cmsg
->cmsg_type
);
782 target_cmsg
->cmsg_len
= tswapl(TARGET_CMSG_LEN(len
));
784 if (cmsg
->cmsg_level
!= TARGET_SOL_SOCKET
|| cmsg
->cmsg_type
!= SCM_RIGHTS
) {
785 gemu_log("Unsupported ancillary data: %d/%d\n", cmsg
->cmsg_level
, cmsg
->cmsg_type
);
786 memcpy(target_data
, data
, len
);
788 int *fd
= (int *)data
;
789 int *target_fd
= (int *)target_data
;
790 int i
, numfds
= len
/ sizeof(int);
792 for (i
= 0; i
< numfds
; i
++)
793 target_fd
[i
] = tswap32(fd
[i
]);
796 cmsg
= CMSG_NXTHDR(msgh
, cmsg
);
797 target_cmsg
= TARGET_CMSG_NXTHDR(target_msgh
, target_cmsg
);
799 unlock_user(target_cmsg
, target_cmsg_addr
, space
);
801 target_msgh
->msg_controllen
= tswapl(space
);
805 /* do_setsockopt() Must return target values and target errnos. */
806 static abi_long
do_setsockopt(int sockfd
, int level
, int optname
,
807 abi_ulong optval_addr
, socklen_t optlen
)
814 /* TCP options all take an 'int' value. */
815 if (optlen
< sizeof(uint32_t))
816 return -TARGET_EINVAL
;
818 if (get_user_u32(val
, optval_addr
))
819 return -TARGET_EFAULT
;
820 ret
= get_errno(setsockopt(sockfd
, level
, optname
, &val
, sizeof(val
)));
827 case IP_ROUTER_ALERT
:
831 case IP_MTU_DISCOVER
:
837 case IP_MULTICAST_TTL
:
838 case IP_MULTICAST_LOOP
:
840 if (optlen
>= sizeof(uint32_t)) {
841 if (get_user_u32(val
, optval_addr
))
842 return -TARGET_EFAULT
;
843 } else if (optlen
>= 1) {
844 if (get_user_u8(val
, optval_addr
))
845 return -TARGET_EFAULT
;
847 ret
= get_errno(setsockopt(sockfd
, level
, optname
, &val
, sizeof(val
)));
853 case TARGET_SOL_SOCKET
:
855 /* Options with 'int' argument. */
856 case TARGET_SO_DEBUG
:
859 case TARGET_SO_REUSEADDR
:
860 optname
= SO_REUSEADDR
;
865 case TARGET_SO_ERROR
:
868 case TARGET_SO_DONTROUTE
:
869 optname
= SO_DONTROUTE
;
871 case TARGET_SO_BROADCAST
:
872 optname
= SO_BROADCAST
;
874 case TARGET_SO_SNDBUF
:
877 case TARGET_SO_RCVBUF
:
880 case TARGET_SO_KEEPALIVE
:
881 optname
= SO_KEEPALIVE
;
883 case TARGET_SO_OOBINLINE
:
884 optname
= SO_OOBINLINE
;
886 case TARGET_SO_NO_CHECK
:
887 optname
= SO_NO_CHECK
;
889 case TARGET_SO_PRIORITY
:
890 optname
= SO_PRIORITY
;
893 case TARGET_SO_BSDCOMPAT
:
894 optname
= SO_BSDCOMPAT
;
897 case TARGET_SO_PASSCRED
:
898 optname
= SO_PASSCRED
;
900 case TARGET_SO_TIMESTAMP
:
901 optname
= SO_TIMESTAMP
;
903 case TARGET_SO_RCVLOWAT
:
904 optname
= SO_RCVLOWAT
;
906 case TARGET_SO_RCVTIMEO
:
907 optname
= SO_RCVTIMEO
;
909 case TARGET_SO_SNDTIMEO
:
910 optname
= SO_SNDTIMEO
;
916 if (optlen
< sizeof(uint32_t))
917 return -TARGET_EINVAL
;
919 if (get_user_u32(val
, optval_addr
))
920 return -TARGET_EFAULT
;
921 ret
= get_errno(setsockopt(sockfd
, SOL_SOCKET
, optname
, &val
, sizeof(val
)));
925 gemu_log("Unsupported setsockopt level=%d optname=%d \n", level
, optname
);
926 ret
= -TARGET_ENOPROTOOPT
;
931 /* do_getsockopt() Must return target values and target errnos. */
932 static abi_long
do_getsockopt(int sockfd
, int level
, int optname
,
933 abi_ulong optval_addr
, abi_ulong optlen
)
939 case TARGET_SOL_SOCKET
:
942 case TARGET_SO_LINGER
:
943 case TARGET_SO_RCVTIMEO
:
944 case TARGET_SO_SNDTIMEO
:
945 case TARGET_SO_PEERCRED
:
946 case TARGET_SO_PEERNAME
:
947 /* These don't just return a single integer */
954 /* TCP options all take an 'int' value. */
956 if (get_user_u32(len
, optlen
))
957 return -TARGET_EFAULT
;
959 return -TARGET_EINVAL
;
961 ret
= get_errno(getsockopt(sockfd
, level
, optname
, &val
, &lv
));
968 if (put_user_u32(val
, optval_addr
))
969 return -TARGET_EFAULT
;
971 if (put_user_u8(val
, optval_addr
))
972 return -TARGET_EFAULT
;
974 if (put_user_u32(len
, optlen
))
975 return -TARGET_EFAULT
;
982 case IP_ROUTER_ALERT
:
986 case IP_MTU_DISCOVER
:
992 case IP_MULTICAST_TTL
:
993 case IP_MULTICAST_LOOP
:
994 if (get_user_u32(len
, optlen
))
995 return -TARGET_EFAULT
;
997 return -TARGET_EINVAL
;
999 ret
= get_errno(getsockopt(sockfd
, level
, optname
, &val
, &lv
));
1002 if (len
< sizeof(int) && len
> 0 && val
>= 0 && val
< 255) {
1004 if (put_user_u32(len
, optlen
)
1005 || put_user_u8(val
, optval_addr
))
1006 return -TARGET_EFAULT
;
1008 if (len
> sizeof(int))
1010 if (put_user_u32(len
, optlen
)
1011 || put_user_u32(val
, optval_addr
))
1012 return -TARGET_EFAULT
;
1016 ret
= -TARGET_ENOPROTOOPT
;
1022 gemu_log("getsockopt level=%d optname=%d not yet supported\n",
1024 ret
= -TARGET_EOPNOTSUPP
;
1031 * lock_iovec()/unlock_iovec() have a return code of 0 for success where
1032 * other lock functions have a return code of 0 for failure.
1034 static abi_long
lock_iovec(int type
, struct iovec
*vec
, abi_ulong target_addr
,
1035 int count
, int copy
)
1037 struct target_iovec
*target_vec
;
1041 target_vec
= lock_user(VERIFY_READ
, target_addr
, count
* sizeof(struct target_iovec
), 1);
1043 return -TARGET_EFAULT
;
1044 for(i
= 0;i
< count
; i
++) {
1045 base
= tswapl(target_vec
[i
].iov_base
);
1046 vec
[i
].iov_len
= tswapl(target_vec
[i
].iov_len
);
1047 if (vec
[i
].iov_len
!= 0) {
1048 vec
[i
].iov_base
= lock_user(type
, base
, vec
[i
].iov_len
, copy
);
1049 if (!vec
[i
].iov_base
&& vec
[i
].iov_len
)
1052 /* zero length pointer is ignored */
1053 vec
[i
].iov_base
= NULL
;
1056 unlock_user (target_vec
, target_addr
, 0);
1059 /* failure - unwind locks */
1060 for (j
= 0; j
< i
; j
++) {
1061 base
= tswapl(target_vec
[j
].iov_base
);
1062 unlock_user(vec
[j
].iov_base
, base
, 0);
1064 unlock_user (target_vec
, target_addr
, 0);
1065 return -TARGET_EFAULT
;
1068 static abi_long
unlock_iovec(struct iovec
*vec
, abi_ulong target_addr
,
1069 int count
, int copy
)
1071 struct target_iovec
*target_vec
;
1075 target_vec
= lock_user(VERIFY_READ
, target_addr
, count
* sizeof(struct target_iovec
), 1);
1077 return -TARGET_EFAULT
;
1078 for(i
= 0;i
< count
; i
++) {
1079 base
= tswapl(target_vec
[i
].iov_base
);
1080 unlock_user(vec
[i
].iov_base
, base
, copy
? vec
[i
].iov_len
: 0);
1082 unlock_user (target_vec
, target_addr
, 0);
1087 /* do_socket() Must return target values and target errnos. */
1088 static abi_long
do_socket(int domain
, int type
, int protocol
)
1090 #if defined(TARGET_MIPS)
1092 case TARGET_SOCK_DGRAM
:
1095 case TARGET_SOCK_STREAM
:
1098 case TARGET_SOCK_RAW
:
1101 case TARGET_SOCK_RDM
:
1104 case TARGET_SOCK_SEQPACKET
:
1105 type
= SOCK_SEQPACKET
;
1107 case TARGET_SOCK_PACKET
:
1112 if (domain
== PF_NETLINK
)
1113 return -EAFNOSUPPORT
; /* do not NETLINK socket connections possible */
1114 return get_errno(socket(domain
, type
, protocol
));
1117 /* do_bind() Must return target values and target errnos. */
1118 static abi_long
do_bind(int sockfd
, abi_ulong target_addr
,
1121 void *addr
= alloca(addrlen
);
1123 target_to_host_sockaddr(addr
, target_addr
, addrlen
);
1124 return get_errno(bind(sockfd
, addr
, addrlen
));
1127 /* do_connect() Must return target values and target errnos. */
1128 static abi_long
do_connect(int sockfd
, abi_ulong target_addr
,
1131 void *addr
= alloca(addrlen
);
1133 target_to_host_sockaddr(addr
, target_addr
, addrlen
);
1134 return get_errno(connect(sockfd
, addr
, addrlen
));
1137 /* do_sendrecvmsg() Must return target values and target errnos. */
1138 static abi_long
do_sendrecvmsg(int fd
, abi_ulong target_msg
,
1139 int flags
, int send
)
1142 struct target_msghdr
*msgp
;
1146 abi_ulong target_vec
;
1149 if (!lock_user_struct(send
? VERIFY_READ
: VERIFY_WRITE
,
1153 return -TARGET_EFAULT
;
1154 if (msgp
->msg_name
) {
1155 msg
.msg_namelen
= tswap32(msgp
->msg_namelen
);
1156 msg
.msg_name
= alloca(msg
.msg_namelen
);
1157 target_to_host_sockaddr(msg
.msg_name
, tswapl(msgp
->msg_name
),
1160 msg
.msg_name
= NULL
;
1161 msg
.msg_namelen
= 0;
1163 msg
.msg_controllen
= 2 * tswapl(msgp
->msg_controllen
);
1164 msg
.msg_control
= alloca(msg
.msg_controllen
);
1165 msg
.msg_flags
= tswap32(msgp
->msg_flags
);
1167 count
= tswapl(msgp
->msg_iovlen
);
1168 vec
= alloca(count
* sizeof(struct iovec
));
1169 target_vec
= tswapl(msgp
->msg_iov
);
1170 lock_iovec(send
? VERIFY_READ
: VERIFY_WRITE
, vec
, target_vec
, count
, send
);
1171 msg
.msg_iovlen
= count
;
1175 ret
= target_to_host_cmsg(&msg
, msgp
);
1177 ret
= get_errno(sendmsg(fd
, &msg
, flags
));
1179 ret
= get_errno(recvmsg(fd
, &msg
, flags
));
1181 ret
= host_to_target_cmsg(msgp
, &msg
);
1183 unlock_iovec(vec
, target_vec
, count
, !send
);
1184 unlock_user_struct(msgp
, target_msg
, send
? 0 : 1);
1188 /* do_accept() Must return target values and target errnos. */
1189 static abi_long
do_accept(int fd
, abi_ulong target_addr
,
1190 abi_ulong target_addrlen_addr
)
1196 if (get_user_u32(addrlen
, target_addrlen_addr
))
1197 return -TARGET_EFAULT
;
1199 addr
= alloca(addrlen
);
1201 ret
= get_errno(accept(fd
, addr
, &addrlen
));
1202 if (!is_error(ret
)) {
1203 host_to_target_sockaddr(target_addr
, addr
, addrlen
);
1204 if (put_user_u32(addrlen
, target_addrlen_addr
))
1205 ret
= -TARGET_EFAULT
;
1210 /* do_getpeername() Must return target values and target errnos. */
1211 static abi_long
do_getpeername(int fd
, abi_ulong target_addr
,
1212 abi_ulong target_addrlen_addr
)
1218 if (get_user_u32(addrlen
, target_addrlen_addr
))
1219 return -TARGET_EFAULT
;
1221 addr
= alloca(addrlen
);
1223 ret
= get_errno(getpeername(fd
, addr
, &addrlen
));
1224 if (!is_error(ret
)) {
1225 host_to_target_sockaddr(target_addr
, addr
, addrlen
);
1226 if (put_user_u32(addrlen
, target_addrlen_addr
))
1227 ret
= -TARGET_EFAULT
;
1232 /* do_getsockname() Must return target values and target errnos. */
1233 static abi_long
do_getsockname(int fd
, abi_ulong target_addr
,
1234 abi_ulong target_addrlen_addr
)
1240 if (get_user_u32(addrlen
, target_addrlen_addr
))
1241 return -TARGET_EFAULT
;
1243 addr
= alloca(addrlen
);
1245 ret
= get_errno(getsockname(fd
, addr
, &addrlen
));
1246 if (!is_error(ret
)) {
1247 host_to_target_sockaddr(target_addr
, addr
, addrlen
);
1248 if (put_user_u32(addrlen
, target_addrlen_addr
))
1249 ret
= -TARGET_EFAULT
;
1254 /* do_socketpair() Must return target values and target errnos. */
1255 static abi_long
do_socketpair(int domain
, int type
, int protocol
,
1256 abi_ulong target_tab_addr
)
1261 ret
= get_errno(socketpair(domain
, type
, protocol
, tab
));
1262 if (!is_error(ret
)) {
1263 if (put_user_s32(tab
[0], target_tab_addr
)
1264 || put_user_s32(tab
[1], target_tab_addr
+ sizeof(tab
[0])))
1265 ret
= -TARGET_EFAULT
;
1270 /* do_sendto() Must return target values and target errnos. */
1271 static abi_long
do_sendto(int fd
, abi_ulong msg
, size_t len
, int flags
,
1272 abi_ulong target_addr
, socklen_t addrlen
)
1278 host_msg
= lock_user(VERIFY_READ
, msg
, len
, 1);
1280 return -TARGET_EFAULT
;
1282 addr
= alloca(addrlen
);
1283 target_to_host_sockaddr(addr
, target_addr
, addrlen
);
1284 ret
= get_errno(sendto(fd
, host_msg
, len
, flags
, addr
, addrlen
));
1286 ret
= get_errno(send(fd
, host_msg
, len
, flags
));
1288 unlock_user(host_msg
, msg
, 0);
1292 /* do_recvfrom() Must return target values and target errnos. */
1293 static abi_long
do_recvfrom(int fd
, abi_ulong msg
, size_t len
, int flags
,
1294 abi_ulong target_addr
,
1295 abi_ulong target_addrlen
)
1302 host_msg
= lock_user(VERIFY_WRITE
, msg
, len
, 0);
1304 return -TARGET_EFAULT
;
1306 if (get_user_u32(addrlen
, target_addrlen
)) {
1307 ret
= -TARGET_EFAULT
;
1310 addr
= alloca(addrlen
);
1311 ret
= get_errno(recvfrom(fd
, host_msg
, len
, flags
, addr
, &addrlen
));
1313 addr
= NULL
; /* To keep compiler quiet. */
1314 ret
= get_errno(recv(fd
, host_msg
, len
, flags
));
1316 if (!is_error(ret
)) {
1318 host_to_target_sockaddr(target_addr
, addr
, addrlen
);
1319 if (put_user_u32(addrlen
, target_addrlen
)) {
1320 ret
= -TARGET_EFAULT
;
1324 unlock_user(host_msg
, msg
, len
);
1327 unlock_user(host_msg
, msg
, 0);
1332 #ifdef TARGET_NR_socketcall
1333 /* do_socketcall() Must return target values and target errnos. */
1334 static abi_long
do_socketcall(int num
, abi_ulong vptr
)
1337 const int n
= sizeof(abi_ulong
);
1342 int domain
, type
, protocol
;
1344 if (get_user_s32(domain
, vptr
)
1345 || get_user_s32(type
, vptr
+ n
)
1346 || get_user_s32(protocol
, vptr
+ 2 * n
))
1347 return -TARGET_EFAULT
;
1349 ret
= do_socket(domain
, type
, protocol
);
1355 abi_ulong target_addr
;
1358 if (get_user_s32(sockfd
, vptr
)
1359 || get_user_ual(target_addr
, vptr
+ n
)
1360 || get_user_u32(addrlen
, vptr
+ 2 * n
))
1361 return -TARGET_EFAULT
;
1363 ret
= do_bind(sockfd
, target_addr
, addrlen
);
1366 case SOCKOP_connect
:
1369 abi_ulong target_addr
;
1372 if (get_user_s32(sockfd
, vptr
)
1373 || get_user_ual(target_addr
, vptr
+ n
)
1374 || get_user_u32(addrlen
, vptr
+ 2 * n
))
1375 return -TARGET_EFAULT
;
1377 ret
= do_connect(sockfd
, target_addr
, addrlen
);
1382 int sockfd
, backlog
;
1384 if (get_user_s32(sockfd
, vptr
)
1385 || get_user_s32(backlog
, vptr
+ n
))
1386 return -TARGET_EFAULT
;
1388 ret
= get_errno(listen(sockfd
, backlog
));
1394 abi_ulong target_addr
, target_addrlen
;
1396 if (get_user_s32(sockfd
, vptr
)
1397 || get_user_ual(target_addr
, vptr
+ n
)
1398 || get_user_u32(target_addrlen
, vptr
+ 2 * n
))
1399 return -TARGET_EFAULT
;
1401 ret
= do_accept(sockfd
, target_addr
, target_addrlen
);
1404 case SOCKOP_getsockname
:
1407 abi_ulong target_addr
, target_addrlen
;
1409 if (get_user_s32(sockfd
, vptr
)
1410 || get_user_ual(target_addr
, vptr
+ n
)
1411 || get_user_u32(target_addrlen
, vptr
+ 2 * n
))
1412 return -TARGET_EFAULT
;
1414 ret
= do_getsockname(sockfd
, target_addr
, target_addrlen
);
1417 case SOCKOP_getpeername
:
1420 abi_ulong target_addr
, target_addrlen
;
1422 if (get_user_s32(sockfd
, vptr
)
1423 || get_user_ual(target_addr
, vptr
+ n
)
1424 || get_user_u32(target_addrlen
, vptr
+ 2 * n
))
1425 return -TARGET_EFAULT
;
1427 ret
= do_getpeername(sockfd
, target_addr
, target_addrlen
);
1430 case SOCKOP_socketpair
:
1432 int domain
, type
, protocol
;
1435 if (get_user_s32(domain
, vptr
)
1436 || get_user_s32(type
, vptr
+ n
)
1437 || get_user_s32(protocol
, vptr
+ 2 * n
)
1438 || get_user_ual(tab
, vptr
+ 3 * n
))
1439 return -TARGET_EFAULT
;
1441 ret
= do_socketpair(domain
, type
, protocol
, tab
);
1451 if (get_user_s32(sockfd
, vptr
)
1452 || get_user_ual(msg
, vptr
+ n
)
1453 || get_user_ual(len
, vptr
+ 2 * n
)
1454 || get_user_s32(flags
, vptr
+ 3 * n
))
1455 return -TARGET_EFAULT
;
1457 ret
= do_sendto(sockfd
, msg
, len
, flags
, 0, 0);
1467 if (get_user_s32(sockfd
, vptr
)
1468 || get_user_ual(msg
, vptr
+ n
)
1469 || get_user_ual(len
, vptr
+ 2 * n
)
1470 || get_user_s32(flags
, vptr
+ 3 * n
))
1471 return -TARGET_EFAULT
;
1473 ret
= do_recvfrom(sockfd
, msg
, len
, flags
, 0, 0);
1485 if (get_user_s32(sockfd
, vptr
)
1486 || get_user_ual(msg
, vptr
+ n
)
1487 || get_user_ual(len
, vptr
+ 2 * n
)
1488 || get_user_s32(flags
, vptr
+ 3 * n
)
1489 || get_user_ual(addr
, vptr
+ 4 * n
)
1490 || get_user_u32(addrlen
, vptr
+ 5 * n
))
1491 return -TARGET_EFAULT
;
1493 ret
= do_sendto(sockfd
, msg
, len
, flags
, addr
, addrlen
);
1496 case SOCKOP_recvfrom
:
1505 if (get_user_s32(sockfd
, vptr
)
1506 || get_user_ual(msg
, vptr
+ n
)
1507 || get_user_ual(len
, vptr
+ 2 * n
)
1508 || get_user_s32(flags
, vptr
+ 3 * n
)
1509 || get_user_ual(addr
, vptr
+ 4 * n
)
1510 || get_user_u32(addrlen
, vptr
+ 5 * n
))
1511 return -TARGET_EFAULT
;
1513 ret
= do_recvfrom(sockfd
, msg
, len
, flags
, addr
, addrlen
);
1516 case SOCKOP_shutdown
:
1520 if (get_user_s32(sockfd
, vptr
)
1521 || get_user_s32(how
, vptr
+ n
))
1522 return -TARGET_EFAULT
;
1524 ret
= get_errno(shutdown(sockfd
, how
));
1527 case SOCKOP_sendmsg
:
1528 case SOCKOP_recvmsg
:
1531 abi_ulong target_msg
;
1534 if (get_user_s32(fd
, vptr
)
1535 || get_user_ual(target_msg
, vptr
+ n
)
1536 || get_user_s32(flags
, vptr
+ 2 * n
))
1537 return -TARGET_EFAULT
;
1539 ret
= do_sendrecvmsg(fd
, target_msg
, flags
,
1540 (num
== SOCKOP_sendmsg
));
1543 case SOCKOP_setsockopt
:
1551 if (get_user_s32(sockfd
, vptr
)
1552 || get_user_s32(level
, vptr
+ n
)
1553 || get_user_s32(optname
, vptr
+ 2 * n
)
1554 || get_user_ual(optval
, vptr
+ 3 * n
)
1555 || get_user_u32(optlen
, vptr
+ 4 * n
))
1556 return -TARGET_EFAULT
;
1558 ret
= do_setsockopt(sockfd
, level
, optname
, optval
, optlen
);
1561 case SOCKOP_getsockopt
:
1569 if (get_user_s32(sockfd
, vptr
)
1570 || get_user_s32(level
, vptr
+ n
)
1571 || get_user_s32(optname
, vptr
+ 2 * n
)
1572 || get_user_ual(optval
, vptr
+ 3 * n
)
1573 || get_user_u32(optlen
, vptr
+ 4 * n
))
1574 return -TARGET_EFAULT
;
1576 ret
= do_getsockopt(sockfd
, level
, optname
, optval
, optlen
);
1580 gemu_log("Unsupported socketcall: %d\n", num
);
1581 ret
= -TARGET_ENOSYS
;
1588 #ifdef TARGET_NR_ipc
1589 #define N_SHM_REGIONS 32
1591 static struct shm_region
{
1594 } shm_regions
[N_SHM_REGIONS
];
1596 struct target_ipc_perm
1603 unsigned short int mode
;
1604 unsigned short int __pad1
;
1605 unsigned short int __seq
;
1606 unsigned short int __pad2
;
1607 abi_ulong __unused1
;
1608 abi_ulong __unused2
;
1611 struct target_semid_ds
1613 struct target_ipc_perm sem_perm
;
1614 abi_ulong sem_otime
;
1615 abi_ulong __unused1
;
1616 abi_ulong sem_ctime
;
1617 abi_ulong __unused2
;
1618 abi_ulong sem_nsems
;
1619 abi_ulong __unused3
;
1620 abi_ulong __unused4
;
1623 static inline abi_long
target_to_host_ipc_perm(struct ipc_perm
*host_ip
,
1624 abi_ulong target_addr
)
1626 struct target_ipc_perm
*target_ip
;
1627 struct target_semid_ds
*target_sd
;
1629 if (!lock_user_struct(VERIFY_READ
, target_sd
, target_addr
, 1))
1630 return -TARGET_EFAULT
;
1631 target_ip
=&(target_sd
->sem_perm
);
1632 host_ip
->__key
= tswapl(target_ip
->__key
);
1633 host_ip
->uid
= tswapl(target_ip
->uid
);
1634 host_ip
->gid
= tswapl(target_ip
->gid
);
1635 host_ip
->cuid
= tswapl(target_ip
->cuid
);
1636 host_ip
->cgid
= tswapl(target_ip
->cgid
);
1637 host_ip
->mode
= tswapl(target_ip
->mode
);
1638 unlock_user_struct(target_sd
, target_addr
, 0);
1642 static inline abi_long
host_to_target_ipc_perm(abi_ulong target_addr
,
1643 struct ipc_perm
*host_ip
)
1645 struct target_ipc_perm
*target_ip
;
1646 struct target_semid_ds
*target_sd
;
1648 if (!lock_user_struct(VERIFY_WRITE
, target_sd
, target_addr
, 0))
1649 return -TARGET_EFAULT
;
1650 target_ip
= &(target_sd
->sem_perm
);
1651 target_ip
->__key
= tswapl(host_ip
->__key
);
1652 target_ip
->uid
= tswapl(host_ip
->uid
);
1653 target_ip
->gid
= tswapl(host_ip
->gid
);
1654 target_ip
->cuid
= tswapl(host_ip
->cuid
);
1655 target_ip
->cgid
= tswapl(host_ip
->cgid
);
1656 target_ip
->mode
= tswapl(host_ip
->mode
);
1657 unlock_user_struct(target_sd
, target_addr
, 1);
1661 static inline abi_long
target_to_host_semid_ds(struct semid_ds
*host_sd
,
1662 abi_ulong target_addr
)
1664 struct target_semid_ds
*target_sd
;
1666 if (!lock_user_struct(VERIFY_READ
, target_sd
, target_addr
, 1))
1667 return -TARGET_EFAULT
;
1668 target_to_host_ipc_perm(&(host_sd
->sem_perm
),target_addr
);
1669 host_sd
->sem_nsems
= tswapl(target_sd
->sem_nsems
);
1670 host_sd
->sem_otime
= tswapl(target_sd
->sem_otime
);
1671 host_sd
->sem_ctime
= tswapl(target_sd
->sem_ctime
);
1672 unlock_user_struct(target_sd
, target_addr
, 0);
1676 static inline abi_long
host_to_target_semid_ds(abi_ulong target_addr
,
1677 struct semid_ds
*host_sd
)
1679 struct target_semid_ds
*target_sd
;
1681 if (!lock_user_struct(VERIFY_WRITE
, target_sd
, target_addr
, 0))
1682 return -TARGET_EFAULT
;
1683 host_to_target_ipc_perm(target_addr
,&(host_sd
->sem_perm
));
1684 target_sd
->sem_nsems
= tswapl(host_sd
->sem_nsems
);
1685 target_sd
->sem_otime
= tswapl(host_sd
->sem_otime
);
1686 target_sd
->sem_ctime
= tswapl(host_sd
->sem_ctime
);
1687 unlock_user_struct(target_sd
, target_addr
, 1);
1693 struct semid_ds
*buf
;
1694 unsigned short *array
;
1697 union target_semun
{
1700 unsigned short int *array
;
1703 static inline abi_long
target_to_host_semun(int cmd
,
1704 union semun
*host_su
,
1705 abi_ulong target_addr
,
1706 struct semid_ds
*ds
)
1708 union target_semun
*target_su
;
1713 if (!lock_user_struct(VERIFY_READ
, target_su
, target_addr
, 1))
1714 return -TARGET_EFAULT
;
1715 target_to_host_semid_ds(ds
,target_su
->buf
);
1717 unlock_user_struct(target_su
, target_addr
, 0);
1721 if (!lock_user_struct(VERIFY_READ
, target_su
, target_addr
, 1))
1722 return -TARGET_EFAULT
;
1723 host_su
->val
= tswapl(target_su
->val
);
1724 unlock_user_struct(target_su
, target_addr
, 0);
1728 if (!lock_user_struct(VERIFY_READ
, target_su
, target_addr
, 1))
1729 return -TARGET_EFAULT
;
1730 *host_su
->array
= tswap16(*target_su
->array
);
1731 unlock_user_struct(target_su
, target_addr
, 0);
1734 gemu_log("semun operation not fully supported: %d\n", (int)cmd
);
1739 static inline abi_long
host_to_target_semun(int cmd
,
1740 abi_ulong target_addr
,
1741 union semun
*host_su
,
1742 struct semid_ds
*ds
)
1744 union target_semun
*target_su
;
1749 if (lock_user_struct(VERIFY_WRITE
, target_su
, target_addr
, 0))
1750 return -TARGET_EFAULT
;
1751 host_to_target_semid_ds(target_su
->buf
,ds
);
1752 unlock_user_struct(target_su
, target_addr
, 1);
1756 if (lock_user_struct(VERIFY_WRITE
, target_su
, target_addr
, 0))
1757 return -TARGET_EFAULT
;
1758 target_su
->val
= tswapl(host_su
->val
);
1759 unlock_user_struct(target_su
, target_addr
, 1);
1763 if (lock_user_struct(VERIFY_WRITE
, target_su
, target_addr
, 0))
1764 return -TARGET_EFAULT
;
1765 *target_su
->array
= tswap16(*host_su
->array
);
1766 unlock_user_struct(target_su
, target_addr
, 1);
1769 gemu_log("semun operation not fully supported: %d\n", (int)cmd
);
1774 static inline abi_long
do_semctl(int first
, int second
, int third
,
1778 struct semid_ds dsarg
;
1779 int cmd
= third
&0xff;
1784 target_to_host_semun(cmd
,&arg
,ptr
,&dsarg
);
1785 ret
= get_errno(semctl(first
, second
, cmd
, arg
));
1786 host_to_target_semun(cmd
,ptr
,&arg
,&dsarg
);
1789 target_to_host_semun(cmd
,&arg
,ptr
,&dsarg
);
1790 ret
= get_errno(semctl(first
, second
, cmd
, arg
));
1791 host_to_target_semun(cmd
,ptr
,&arg
,&dsarg
);
1794 target_to_host_semun(cmd
,&arg
,ptr
,&dsarg
);
1795 ret
= get_errno(semctl(first
, second
, cmd
, arg
));
1796 host_to_target_semun(cmd
,ptr
,&arg
,&dsarg
);
1799 target_to_host_semun(cmd
,&arg
,ptr
,&dsarg
);
1800 ret
= get_errno(semctl(first
, second
, cmd
, arg
));
1801 host_to_target_semun(cmd
,ptr
,&arg
,&dsarg
);
1804 target_to_host_semun(cmd
,&arg
,ptr
,&dsarg
);
1805 ret
= get_errno(semctl(first
, second
, cmd
, arg
));
1806 host_to_target_semun(cmd
,ptr
,&arg
,&dsarg
);
1809 target_to_host_semun(cmd
,&arg
,ptr
,&dsarg
);
1810 ret
= get_errno(semctl(first
, second
, cmd
, arg
));
1811 host_to_target_semun(cmd
,ptr
,&arg
,&dsarg
);
1814 ret
= get_errno(semctl(first
, second
, cmd
, arg
));
1820 struct target_msqid_ds
1822 struct target_ipc_perm msg_perm
;
1823 abi_ulong msg_stime
;
1824 abi_ulong __unused1
;
1825 abi_ulong msg_rtime
;
1826 abi_ulong __unused2
;
1827 abi_ulong msg_ctime
;
1828 abi_ulong __unused3
;
1829 abi_ulong __msg_cbytes
;
1831 abi_ulong msg_qbytes
;
1832 abi_ulong msg_lspid
;
1833 abi_ulong msg_lrpid
;
1834 abi_ulong __unused4
;
1835 abi_ulong __unused5
;
1838 static inline abi_long
target_to_host_msqid_ds(struct msqid_ds
*host_md
,
1839 abi_ulong target_addr
)
1841 struct target_msqid_ds
*target_md
;
1843 if (!lock_user_struct(VERIFY_READ
, target_md
, target_addr
, 1))
1844 return -TARGET_EFAULT
;
1845 target_to_host_ipc_perm(&(host_md
->msg_perm
),target_addr
);
1846 host_md
->msg_stime
= tswapl(target_md
->msg_stime
);
1847 host_md
->msg_rtime
= tswapl(target_md
->msg_rtime
);
1848 host_md
->msg_ctime
= tswapl(target_md
->msg_ctime
);
1849 host_md
->__msg_cbytes
= tswapl(target_md
->__msg_cbytes
);
1850 host_md
->msg_qnum
= tswapl(target_md
->msg_qnum
);
1851 host_md
->msg_qbytes
= tswapl(target_md
->msg_qbytes
);
1852 host_md
->msg_lspid
= tswapl(target_md
->msg_lspid
);
1853 host_md
->msg_lrpid
= tswapl(target_md
->msg_lrpid
);
1854 unlock_user_struct(target_md
, target_addr
, 0);
1858 static inline abi_long
host_to_target_msqid_ds(abi_ulong target_addr
,
1859 struct msqid_ds
*host_md
)
1861 struct target_msqid_ds
*target_md
;
1863 if (!lock_user_struct(VERIFY_WRITE
, target_md
, target_addr
, 0))
1864 return -TARGET_EFAULT
;
1865 host_to_target_ipc_perm(target_addr
,&(host_md
->msg_perm
));
1866 target_md
->msg_stime
= tswapl(host_md
->msg_stime
);
1867 target_md
->msg_rtime
= tswapl(host_md
->msg_rtime
);
1868 target_md
->msg_ctime
= tswapl(host_md
->msg_ctime
);
1869 target_md
->__msg_cbytes
= tswapl(host_md
->__msg_cbytes
);
1870 target_md
->msg_qnum
= tswapl(host_md
->msg_qnum
);
1871 target_md
->msg_qbytes
= tswapl(host_md
->msg_qbytes
);
1872 target_md
->msg_lspid
= tswapl(host_md
->msg_lspid
);
1873 target_md
->msg_lrpid
= tswapl(host_md
->msg_lrpid
);
1874 unlock_user_struct(target_md
, target_addr
, 1);
1878 static inline abi_long
do_msgctl(int first
, int second
, abi_long ptr
)
1880 struct msqid_ds dsarg
;
1881 int cmd
= second
&0xff;
1886 target_to_host_msqid_ds(&dsarg
,ptr
);
1887 ret
= get_errno(msgctl(first
, cmd
, &dsarg
));
1888 host_to_target_msqid_ds(ptr
,&dsarg
);
1890 ret
= get_errno(msgctl(first
, cmd
, &dsarg
));
1895 struct target_msgbuf
{
1900 static inline abi_long
do_msgsnd(int msqid
, abi_long msgp
,
1901 unsigned int msgsz
, int msgflg
)
1903 struct target_msgbuf
*target_mb
;
1904 struct msgbuf
*host_mb
;
1907 if (!lock_user_struct(VERIFY_READ
, target_mb
, msgp
, 0))
1908 return -TARGET_EFAULT
;
1909 host_mb
= malloc(msgsz
+sizeof(long));
1910 host_mb
->mtype
= tswapl(target_mb
->mtype
);
1911 memcpy(host_mb
->mtext
,target_mb
->mtext
,msgsz
);
1912 ret
= get_errno(msgsnd(msqid
, host_mb
, msgsz
, msgflg
));
1914 unlock_user_struct(target_mb
, msgp
, 0);
1919 static inline abi_long
do_msgrcv(int msqid
, abi_long msgp
,
1920 unsigned int msgsz
, int msgtype
,
1923 struct target_msgbuf
*target_mb
;
1925 struct msgbuf
*host_mb
;
1928 if (!lock_user_struct(VERIFY_WRITE
, target_mb
, msgp
, 0))
1929 return -TARGET_EFAULT
;
1930 host_mb
= malloc(msgsz
+sizeof(long));
1931 ret
= get_errno(msgrcv(msqid
, host_mb
, msgsz
, 1, msgflg
));
1933 abi_ulong target_mtext_addr
= msgp
+ sizeof(abi_ulong
);
1934 target_mtext
= lock_user(VERIFY_WRITE
, target_mtext_addr
, ret
, 0);
1935 if (!target_mtext
) {
1936 ret
= -TARGET_EFAULT
;
1939 memcpy(target_mb
->mtext
, host_mb
->mtext
, ret
);
1940 unlock_user(target_mtext
, target_mtext_addr
, ret
);
1942 target_mb
->mtype
= tswapl(host_mb
->mtype
);
1947 unlock_user_struct(target_mb
, msgp
, 1);
1951 /* ??? This only works with linear mappings. */
1952 /* do_ipc() must return target values and target errnos. */
1953 static abi_long
do_ipc(unsigned int call
, int first
,
1954 int second
, int third
,
1955 abi_long ptr
, abi_long fifth
)
1959 struct shmid_ds shm_info
;
1962 version
= call
>> 16;
1967 ret
= get_errno(semop(first
,(struct sembuf
*)g2h(ptr
), second
));
1971 ret
= get_errno(semget(first
, second
, third
));
1975 ret
= do_semctl(first
, second
, third
, ptr
);
1978 case IPCOP_semtimedop
:
1979 gemu_log("Unsupported ipc call: %d (version %d)\n", call
, version
);
1980 ret
= -TARGET_ENOSYS
;
1984 ret
= get_errno(msgget(first
, second
));
1988 ret
= do_msgsnd(first
, ptr
, second
, third
);
1992 ret
= do_msgctl(first
, second
, ptr
);
1997 /* XXX: this code is not correct */
2000 void *__unbounded msgp
;
2004 struct ipc_kludge
*foo
= (struct ipc_kludge
*)g2h(ptr
);
2005 struct msgbuf
*msgp
= (struct msgbuf
*) foo
->msgp
;
2007 ret
= do_msgrcv(first
, (long)msgp
, second
, 0, third
);
2016 /* SHM_* flags are the same on all linux platforms */
2017 host_addr
= shmat(first
, (void *)g2h(ptr
), second
);
2018 if (host_addr
== (void *)-1) {
2019 ret
= get_errno((long)host_addr
);
2022 raddr
= h2g((unsigned long)host_addr
);
2023 /* find out the length of the shared memory segment */
2025 ret
= get_errno(shmctl(first
, IPC_STAT
, &shm_info
));
2026 if (is_error(ret
)) {
2027 /* can't get length, bail out */
2031 page_set_flags(raddr
, raddr
+ shm_info
.shm_segsz
,
2032 PAGE_VALID
| PAGE_READ
|
2033 ((second
& SHM_RDONLY
)? 0: PAGE_WRITE
));
2034 for (i
= 0; i
< N_SHM_REGIONS
; ++i
) {
2035 if (shm_regions
[i
].start
== 0) {
2036 shm_regions
[i
].start
= raddr
;
2037 shm_regions
[i
].size
= shm_info
.shm_segsz
;
2041 if (put_user_ual(raddr
, third
))
2042 return -TARGET_EFAULT
;
2047 for (i
= 0; i
< N_SHM_REGIONS
; ++i
) {
2048 if (shm_regions
[i
].start
== ptr
) {
2049 shm_regions
[i
].start
= 0;
2050 page_set_flags(ptr
, shm_regions
[i
].size
, 0);
2054 ret
= get_errno(shmdt((void *)g2h(ptr
)));
2058 /* IPC_* flag values are the same on all linux platforms */
2059 ret
= get_errno(shmget(first
, second
, third
));
2062 /* IPC_* and SHM_* command values are the same on all linux platforms */
2068 ret
= get_errno(shmctl(first
, second
, NULL
));
2076 gemu_log("Unsupported ipc call: %d (version %d)\n", call
, version
);
2077 ret
= -TARGET_ENOSYS
;
2084 /* kernel structure types definitions */
2087 #define STRUCT(name, list...) STRUCT_ ## name,
2088 #define STRUCT_SPECIAL(name) STRUCT_ ## name,
2090 #include "syscall_types.h"
2093 #undef STRUCT_SPECIAL
2095 #define STRUCT(name, list...) const argtype struct_ ## name ## _def[] = { list, TYPE_NULL };
2096 #define STRUCT_SPECIAL(name)
2097 #include "syscall_types.h"
2099 #undef STRUCT_SPECIAL
2101 typedef struct IOCTLEntry
{
2102 unsigned int target_cmd
;
2103 unsigned int host_cmd
;
2106 const argtype arg_type
[5];
2109 #define IOC_R 0x0001
2110 #define IOC_W 0x0002
2111 #define IOC_RW (IOC_R | IOC_W)
2113 #define MAX_STRUCT_SIZE 4096
2115 IOCTLEntry ioctl_entries
[] = {
2116 #define IOCTL(cmd, access, types...) \
2117 { TARGET_ ## cmd, cmd, #cmd, access, { types } },
2122 /* ??? Implement proper locking for ioctls. */
2123 /* do_ioctl() Must return target values and target errnos. */
2124 static abi_long
do_ioctl(int fd
, abi_long cmd
, abi_long arg
)
2126 const IOCTLEntry
*ie
;
2127 const argtype
*arg_type
;
2129 uint8_t buf_temp
[MAX_STRUCT_SIZE
];
2135 if (ie
->target_cmd
== 0) {
2136 gemu_log("Unsupported ioctl: cmd=0x%04lx\n", (long)cmd
);
2137 return -TARGET_ENOSYS
;
2139 if (ie
->target_cmd
== cmd
)
2143 arg_type
= ie
->arg_type
;
2145 gemu_log("ioctl: cmd=0x%04lx (%s)\n", (long)cmd
, ie
->name
);
2147 switch(arg_type
[0]) {
2150 ret
= get_errno(ioctl(fd
, ie
->host_cmd
));
2155 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, arg
));
2159 target_size
= thunk_type_size(arg_type
, 0);
2160 switch(ie
->access
) {
2162 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, buf_temp
));
2163 if (!is_error(ret
)) {
2164 argptr
= lock_user(VERIFY_WRITE
, arg
, target_size
, 0);
2166 return -TARGET_EFAULT
;
2167 thunk_convert(argptr
, buf_temp
, arg_type
, THUNK_TARGET
);
2168 unlock_user(argptr
, arg
, target_size
);
2172 argptr
= lock_user(VERIFY_READ
, arg
, target_size
, 1);
2174 return -TARGET_EFAULT
;
2175 thunk_convert(buf_temp
, argptr
, arg_type
, THUNK_HOST
);
2176 unlock_user(argptr
, arg
, 0);
2177 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, buf_temp
));
2181 argptr
= lock_user(VERIFY_READ
, arg
, target_size
, 1);
2183 return -TARGET_EFAULT
;
2184 thunk_convert(buf_temp
, argptr
, arg_type
, THUNK_HOST
);
2185 unlock_user(argptr
, arg
, 0);
2186 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, buf_temp
));
2187 if (!is_error(ret
)) {
2188 argptr
= lock_user(VERIFY_WRITE
, arg
, target_size
, 0);
2190 return -TARGET_EFAULT
;
2191 thunk_convert(argptr
, buf_temp
, arg_type
, THUNK_TARGET
);
2192 unlock_user(argptr
, arg
, target_size
);
2198 gemu_log("Unsupported ioctl type: cmd=0x%04lx type=%d\n",
2199 (long)cmd
, arg_type
[0]);
2200 ret
= -TARGET_ENOSYS
;
2206 bitmask_transtbl iflag_tbl
[] = {
2207 { TARGET_IGNBRK
, TARGET_IGNBRK
, IGNBRK
, IGNBRK
},
2208 { TARGET_BRKINT
, TARGET_BRKINT
, BRKINT
, BRKINT
},
2209 { TARGET_IGNPAR
, TARGET_IGNPAR
, IGNPAR
, IGNPAR
},
2210 { TARGET_PARMRK
, TARGET_PARMRK
, PARMRK
, PARMRK
},
2211 { TARGET_INPCK
, TARGET_INPCK
, INPCK
, INPCK
},
2212 { TARGET_ISTRIP
, TARGET_ISTRIP
, ISTRIP
, ISTRIP
},
2213 { TARGET_INLCR
, TARGET_INLCR
, INLCR
, INLCR
},
2214 { TARGET_IGNCR
, TARGET_IGNCR
, IGNCR
, IGNCR
},
2215 { TARGET_ICRNL
, TARGET_ICRNL
, ICRNL
, ICRNL
},
2216 { TARGET_IUCLC
, TARGET_IUCLC
, IUCLC
, IUCLC
},
2217 { TARGET_IXON
, TARGET_IXON
, IXON
, IXON
},
2218 { TARGET_IXANY
, TARGET_IXANY
, IXANY
, IXANY
},
2219 { TARGET_IXOFF
, TARGET_IXOFF
, IXOFF
, IXOFF
},
2220 { TARGET_IMAXBEL
, TARGET_IMAXBEL
, IMAXBEL
, IMAXBEL
},
2224 bitmask_transtbl oflag_tbl
[] = {
2225 { TARGET_OPOST
, TARGET_OPOST
, OPOST
, OPOST
},
2226 { TARGET_OLCUC
, TARGET_OLCUC
, OLCUC
, OLCUC
},
2227 { TARGET_ONLCR
, TARGET_ONLCR
, ONLCR
, ONLCR
},
2228 { TARGET_OCRNL
, TARGET_OCRNL
, OCRNL
, OCRNL
},
2229 { TARGET_ONOCR
, TARGET_ONOCR
, ONOCR
, ONOCR
},
2230 { TARGET_ONLRET
, TARGET_ONLRET
, ONLRET
, ONLRET
},
2231 { TARGET_OFILL
, TARGET_OFILL
, OFILL
, OFILL
},
2232 { TARGET_OFDEL
, TARGET_OFDEL
, OFDEL
, OFDEL
},
2233 { TARGET_NLDLY
, TARGET_NL0
, NLDLY
, NL0
},
2234 { TARGET_NLDLY
, TARGET_NL1
, NLDLY
, NL1
},
2235 { TARGET_CRDLY
, TARGET_CR0
, CRDLY
, CR0
},
2236 { TARGET_CRDLY
, TARGET_CR1
, CRDLY
, CR1
},
2237 { TARGET_CRDLY
, TARGET_CR2
, CRDLY
, CR2
},
2238 { TARGET_CRDLY
, TARGET_CR3
, CRDLY
, CR3
},
2239 { TARGET_TABDLY
, TARGET_TAB0
, TABDLY
, TAB0
},
2240 { TARGET_TABDLY
, TARGET_TAB1
, TABDLY
, TAB1
},
2241 { TARGET_TABDLY
, TARGET_TAB2
, TABDLY
, TAB2
},
2242 { TARGET_TABDLY
, TARGET_TAB3
, TABDLY
, TAB3
},
2243 { TARGET_BSDLY
, TARGET_BS0
, BSDLY
, BS0
},
2244 { TARGET_BSDLY
, TARGET_BS1
, BSDLY
, BS1
},
2245 { TARGET_VTDLY
, TARGET_VT0
, VTDLY
, VT0
},
2246 { TARGET_VTDLY
, TARGET_VT1
, VTDLY
, VT1
},
2247 { TARGET_FFDLY
, TARGET_FF0
, FFDLY
, FF0
},
2248 { TARGET_FFDLY
, TARGET_FF1
, FFDLY
, FF1
},
2252 bitmask_transtbl cflag_tbl
[] = {
2253 { TARGET_CBAUD
, TARGET_B0
, CBAUD
, B0
},
2254 { TARGET_CBAUD
, TARGET_B50
, CBAUD
, B50
},
2255 { TARGET_CBAUD
, TARGET_B75
, CBAUD
, B75
},
2256 { TARGET_CBAUD
, TARGET_B110
, CBAUD
, B110
},
2257 { TARGET_CBAUD
, TARGET_B134
, CBAUD
, B134
},
2258 { TARGET_CBAUD
, TARGET_B150
, CBAUD
, B150
},
2259 { TARGET_CBAUD
, TARGET_B200
, CBAUD
, B200
},
2260 { TARGET_CBAUD
, TARGET_B300
, CBAUD
, B300
},
2261 { TARGET_CBAUD
, TARGET_B600
, CBAUD
, B600
},
2262 { TARGET_CBAUD
, TARGET_B1200
, CBAUD
, B1200
},
2263 { TARGET_CBAUD
, TARGET_B1800
, CBAUD
, B1800
},
2264 { TARGET_CBAUD
, TARGET_B2400
, CBAUD
, B2400
},
2265 { TARGET_CBAUD
, TARGET_B4800
, CBAUD
, B4800
},
2266 { TARGET_CBAUD
, TARGET_B9600
, CBAUD
, B9600
},
2267 { TARGET_CBAUD
, TARGET_B19200
, CBAUD
, B19200
},
2268 { TARGET_CBAUD
, TARGET_B38400
, CBAUD
, B38400
},
2269 { TARGET_CBAUD
, TARGET_B57600
, CBAUD
, B57600
},
2270 { TARGET_CBAUD
, TARGET_B115200
, CBAUD
, B115200
},
2271 { TARGET_CBAUD
, TARGET_B230400
, CBAUD
, B230400
},
2272 { TARGET_CBAUD
, TARGET_B460800
, CBAUD
, B460800
},
2273 { TARGET_CSIZE
, TARGET_CS5
, CSIZE
, CS5
},
2274 { TARGET_CSIZE
, TARGET_CS6
, CSIZE
, CS6
},
2275 { TARGET_CSIZE
, TARGET_CS7
, CSIZE
, CS7
},
2276 { TARGET_CSIZE
, TARGET_CS8
, CSIZE
, CS8
},
2277 { TARGET_CSTOPB
, TARGET_CSTOPB
, CSTOPB
, CSTOPB
},
2278 { TARGET_CREAD
, TARGET_CREAD
, CREAD
, CREAD
},
2279 { TARGET_PARENB
, TARGET_PARENB
, PARENB
, PARENB
},
2280 { TARGET_PARODD
, TARGET_PARODD
, PARODD
, PARODD
},
2281 { TARGET_HUPCL
, TARGET_HUPCL
, HUPCL
, HUPCL
},
2282 { TARGET_CLOCAL
, TARGET_CLOCAL
, CLOCAL
, CLOCAL
},
2283 { TARGET_CRTSCTS
, TARGET_CRTSCTS
, CRTSCTS
, CRTSCTS
},
2287 bitmask_transtbl lflag_tbl
[] = {
2288 { TARGET_ISIG
, TARGET_ISIG
, ISIG
, ISIG
},
2289 { TARGET_ICANON
, TARGET_ICANON
, ICANON
, ICANON
},
2290 { TARGET_XCASE
, TARGET_XCASE
, XCASE
, XCASE
},
2291 { TARGET_ECHO
, TARGET_ECHO
, ECHO
, ECHO
},
2292 { TARGET_ECHOE
, TARGET_ECHOE
, ECHOE
, ECHOE
},
2293 { TARGET_ECHOK
, TARGET_ECHOK
, ECHOK
, ECHOK
},
2294 { TARGET_ECHONL
, TARGET_ECHONL
, ECHONL
, ECHONL
},
2295 { TARGET_NOFLSH
, TARGET_NOFLSH
, NOFLSH
, NOFLSH
},
2296 { TARGET_TOSTOP
, TARGET_TOSTOP
, TOSTOP
, TOSTOP
},
2297 { TARGET_ECHOCTL
, TARGET_ECHOCTL
, ECHOCTL
, ECHOCTL
},
2298 { TARGET_ECHOPRT
, TARGET_ECHOPRT
, ECHOPRT
, ECHOPRT
},
2299 { TARGET_ECHOKE
, TARGET_ECHOKE
, ECHOKE
, ECHOKE
},
2300 { TARGET_FLUSHO
, TARGET_FLUSHO
, FLUSHO
, FLUSHO
},
2301 { TARGET_PENDIN
, TARGET_PENDIN
, PENDIN
, PENDIN
},
2302 { TARGET_IEXTEN
, TARGET_IEXTEN
, IEXTEN
, IEXTEN
},
2306 static void target_to_host_termios (void *dst
, const void *src
)
2308 struct host_termios
*host
= dst
;
2309 const struct target_termios
*target
= src
;
2312 target_to_host_bitmask(tswap32(target
->c_iflag
), iflag_tbl
);
2314 target_to_host_bitmask(tswap32(target
->c_oflag
), oflag_tbl
);
2316 target_to_host_bitmask(tswap32(target
->c_cflag
), cflag_tbl
);
2318 target_to_host_bitmask(tswap32(target
->c_lflag
), lflag_tbl
);
2319 host
->c_line
= target
->c_line
;
2321 host
->c_cc
[VINTR
] = target
->c_cc
[TARGET_VINTR
];
2322 host
->c_cc
[VQUIT
] = target
->c_cc
[TARGET_VQUIT
];
2323 host
->c_cc
[VERASE
] = target
->c_cc
[TARGET_VERASE
];
2324 host
->c_cc
[VKILL
] = target
->c_cc
[TARGET_VKILL
];
2325 host
->c_cc
[VEOF
] = target
->c_cc
[TARGET_VEOF
];
2326 host
->c_cc
[VTIME
] = target
->c_cc
[TARGET_VTIME
];
2327 host
->c_cc
[VMIN
] = target
->c_cc
[TARGET_VMIN
];
2328 host
->c_cc
[VSWTC
] = target
->c_cc
[TARGET_VSWTC
];
2329 host
->c_cc
[VSTART
] = target
->c_cc
[TARGET_VSTART
];
2330 host
->c_cc
[VSTOP
] = target
->c_cc
[TARGET_VSTOP
];
2331 host
->c_cc
[VSUSP
] = target
->c_cc
[TARGET_VSUSP
];
2332 host
->c_cc
[VEOL
] = target
->c_cc
[TARGET_VEOL
];
2333 host
->c_cc
[VREPRINT
] = target
->c_cc
[TARGET_VREPRINT
];
2334 host
->c_cc
[VDISCARD
] = target
->c_cc
[TARGET_VDISCARD
];
2335 host
->c_cc
[VWERASE
] = target
->c_cc
[TARGET_VWERASE
];
2336 host
->c_cc
[VLNEXT
] = target
->c_cc
[TARGET_VLNEXT
];
2337 host
->c_cc
[VEOL2
] = target
->c_cc
[TARGET_VEOL2
];
2340 static void host_to_target_termios (void *dst
, const void *src
)
2342 struct target_termios
*target
= dst
;
2343 const struct host_termios
*host
= src
;
2346 tswap32(host_to_target_bitmask(host
->c_iflag
, iflag_tbl
));
2348 tswap32(host_to_target_bitmask(host
->c_oflag
, oflag_tbl
));
2350 tswap32(host_to_target_bitmask(host
->c_cflag
, cflag_tbl
));
2352 tswap32(host_to_target_bitmask(host
->c_lflag
, lflag_tbl
));
2353 target
->c_line
= host
->c_line
;
2355 target
->c_cc
[TARGET_VINTR
] = host
->c_cc
[VINTR
];
2356 target
->c_cc
[TARGET_VQUIT
] = host
->c_cc
[VQUIT
];
2357 target
->c_cc
[TARGET_VERASE
] = host
->c_cc
[VERASE
];
2358 target
->c_cc
[TARGET_VKILL
] = host
->c_cc
[VKILL
];
2359 target
->c_cc
[TARGET_VEOF
] = host
->c_cc
[VEOF
];
2360 target
->c_cc
[TARGET_VTIME
] = host
->c_cc
[VTIME
];
2361 target
->c_cc
[TARGET_VMIN
] = host
->c_cc
[VMIN
];
2362 target
->c_cc
[TARGET_VSWTC
] = host
->c_cc
[VSWTC
];
2363 target
->c_cc
[TARGET_VSTART
] = host
->c_cc
[VSTART
];
2364 target
->c_cc
[TARGET_VSTOP
] = host
->c_cc
[VSTOP
];
2365 target
->c_cc
[TARGET_VSUSP
] = host
->c_cc
[VSUSP
];
2366 target
->c_cc
[TARGET_VEOL
] = host
->c_cc
[VEOL
];
2367 target
->c_cc
[TARGET_VREPRINT
] = host
->c_cc
[VREPRINT
];
2368 target
->c_cc
[TARGET_VDISCARD
] = host
->c_cc
[VDISCARD
];
2369 target
->c_cc
[TARGET_VWERASE
] = host
->c_cc
[VWERASE
];
2370 target
->c_cc
[TARGET_VLNEXT
] = host
->c_cc
[VLNEXT
];
2371 target
->c_cc
[TARGET_VEOL2
] = host
->c_cc
[VEOL2
];
2374 StructEntry struct_termios_def
= {
2375 .convert
= { host_to_target_termios
, target_to_host_termios
},
2376 .size
= { sizeof(struct target_termios
), sizeof(struct host_termios
) },
2377 .align
= { __alignof__(struct target_termios
), __alignof__(struct host_termios
) },
2380 static bitmask_transtbl mmap_flags_tbl
[] = {
2381 { TARGET_MAP_SHARED
, TARGET_MAP_SHARED
, MAP_SHARED
, MAP_SHARED
},
2382 { TARGET_MAP_PRIVATE
, TARGET_MAP_PRIVATE
, MAP_PRIVATE
, MAP_PRIVATE
},
2383 { TARGET_MAP_FIXED
, TARGET_MAP_FIXED
, MAP_FIXED
, MAP_FIXED
},
2384 { TARGET_MAP_ANONYMOUS
, TARGET_MAP_ANONYMOUS
, MAP_ANONYMOUS
, MAP_ANONYMOUS
},
2385 { TARGET_MAP_GROWSDOWN
, TARGET_MAP_GROWSDOWN
, MAP_GROWSDOWN
, MAP_GROWSDOWN
},
2386 { TARGET_MAP_DENYWRITE
, TARGET_MAP_DENYWRITE
, MAP_DENYWRITE
, MAP_DENYWRITE
},
2387 { TARGET_MAP_EXECUTABLE
, TARGET_MAP_EXECUTABLE
, MAP_EXECUTABLE
, MAP_EXECUTABLE
},
2388 { TARGET_MAP_LOCKED
, TARGET_MAP_LOCKED
, MAP_LOCKED
, MAP_LOCKED
},
2392 static bitmask_transtbl fcntl_flags_tbl
[] = {
2393 { TARGET_O_ACCMODE
, TARGET_O_WRONLY
, O_ACCMODE
, O_WRONLY
, },
2394 { TARGET_O_ACCMODE
, TARGET_O_RDWR
, O_ACCMODE
, O_RDWR
, },
2395 { TARGET_O_CREAT
, TARGET_O_CREAT
, O_CREAT
, O_CREAT
, },
2396 { TARGET_O_EXCL
, TARGET_O_EXCL
, O_EXCL
, O_EXCL
, },
2397 { TARGET_O_NOCTTY
, TARGET_O_NOCTTY
, O_NOCTTY
, O_NOCTTY
, },
2398 { TARGET_O_TRUNC
, TARGET_O_TRUNC
, O_TRUNC
, O_TRUNC
, },
2399 { TARGET_O_APPEND
, TARGET_O_APPEND
, O_APPEND
, O_APPEND
, },
2400 { TARGET_O_NONBLOCK
, TARGET_O_NONBLOCK
, O_NONBLOCK
, O_NONBLOCK
, },
2401 { TARGET_O_SYNC
, TARGET_O_SYNC
, O_SYNC
, O_SYNC
, },
2402 { TARGET_FASYNC
, TARGET_FASYNC
, FASYNC
, FASYNC
, },
2403 { TARGET_O_DIRECTORY
, TARGET_O_DIRECTORY
, O_DIRECTORY
, O_DIRECTORY
, },
2404 { TARGET_O_NOFOLLOW
, TARGET_O_NOFOLLOW
, O_NOFOLLOW
, O_NOFOLLOW
, },
2405 { TARGET_O_LARGEFILE
, TARGET_O_LARGEFILE
, O_LARGEFILE
, O_LARGEFILE
, },
2406 #if defined(O_DIRECT)
2407 { TARGET_O_DIRECT
, TARGET_O_DIRECT
, O_DIRECT
, O_DIRECT
, },
2412 #if defined(TARGET_I386)
2414 /* NOTE: there is really one LDT for all the threads */
2417 static abi_long
read_ldt(abi_ulong ptr
, unsigned long bytecount
)
2424 size
= TARGET_LDT_ENTRIES
* TARGET_LDT_ENTRY_SIZE
;
2425 if (size
> bytecount
)
2427 p
= lock_user(VERIFY_WRITE
, ptr
, size
, 0);
2429 return -TARGET_EFAULT
;
2430 /* ??? Should this by byteswapped? */
2431 memcpy(p
, ldt_table
, size
);
2432 unlock_user(p
, ptr
, size
);
2436 /* XXX: add locking support */
2437 static abi_long
write_ldt(CPUX86State
*env
,
2438 abi_ulong ptr
, unsigned long bytecount
, int oldmode
)
2440 struct target_modify_ldt_ldt_s ldt_info
;
2441 struct target_modify_ldt_ldt_s
*target_ldt_info
;
2442 int seg_32bit
, contents
, read_exec_only
, limit_in_pages
;
2443 int seg_not_present
, useable
, lm
;
2444 uint32_t *lp
, entry_1
, entry_2
;
2446 if (bytecount
!= sizeof(ldt_info
))
2447 return -TARGET_EINVAL
;
2448 if (!lock_user_struct(VERIFY_READ
, target_ldt_info
, ptr
, 1))
2449 return -TARGET_EFAULT
;
2450 ldt_info
.entry_number
= tswap32(target_ldt_info
->entry_number
);
2451 ldt_info
.base_addr
= tswapl(target_ldt_info
->base_addr
);
2452 ldt_info
.limit
= tswap32(target_ldt_info
->limit
);
2453 ldt_info
.flags
= tswap32(target_ldt_info
->flags
);
2454 unlock_user_struct(target_ldt_info
, ptr
, 0);
2456 if (ldt_info
.entry_number
>= TARGET_LDT_ENTRIES
)
2457 return -TARGET_EINVAL
;
2458 seg_32bit
= ldt_info
.flags
& 1;
2459 contents
= (ldt_info
.flags
>> 1) & 3;
2460 read_exec_only
= (ldt_info
.flags
>> 3) & 1;
2461 limit_in_pages
= (ldt_info
.flags
>> 4) & 1;
2462 seg_not_present
= (ldt_info
.flags
>> 5) & 1;
2463 useable
= (ldt_info
.flags
>> 6) & 1;
2467 lm
= (ldt_info
.flags
>> 7) & 1;
2469 if (contents
== 3) {
2471 return -TARGET_EINVAL
;
2472 if (seg_not_present
== 0)
2473 return -TARGET_EINVAL
;
2475 /* allocate the LDT */
2477 ldt_table
= malloc(TARGET_LDT_ENTRIES
* TARGET_LDT_ENTRY_SIZE
);
2479 return -TARGET_ENOMEM
;
2480 memset(ldt_table
, 0, TARGET_LDT_ENTRIES
* TARGET_LDT_ENTRY_SIZE
);
2481 env
->ldt
.base
= h2g((unsigned long)ldt_table
);
2482 env
->ldt
.limit
= 0xffff;
2485 /* NOTE: same code as Linux kernel */
2486 /* Allow LDTs to be cleared by the user. */
2487 if (ldt_info
.base_addr
== 0 && ldt_info
.limit
== 0) {
2490 read_exec_only
== 1 &&
2492 limit_in_pages
== 0 &&
2493 seg_not_present
== 1 &&
2501 entry_1
= ((ldt_info
.base_addr
& 0x0000ffff) << 16) |
2502 (ldt_info
.limit
& 0x0ffff);
2503 entry_2
= (ldt_info
.base_addr
& 0xff000000) |
2504 ((ldt_info
.base_addr
& 0x00ff0000) >> 16) |
2505 (ldt_info
.limit
& 0xf0000) |
2506 ((read_exec_only
^ 1) << 9) |
2508 ((seg_not_present
^ 1) << 15) |
2510 (limit_in_pages
<< 23) |
2514 entry_2
|= (useable
<< 20);
2516 /* Install the new entry ... */
2518 lp
= (uint32_t *)(ldt_table
+ (ldt_info
.entry_number
<< 3));
2519 lp
[0] = tswap32(entry_1
);
2520 lp
[1] = tswap32(entry_2
);
2524 /* specific and weird i386 syscalls */
2525 abi_long
do_modify_ldt(CPUX86State
*env
, int func
, abi_ulong ptr
,
2526 unsigned long bytecount
)
2532 ret
= read_ldt(ptr
, bytecount
);
2535 ret
= write_ldt(env
, ptr
, bytecount
, 1);
2538 ret
= write_ldt(env
, ptr
, bytecount
, 0);
2541 ret
= -TARGET_ENOSYS
;
2547 abi_long
do_set_thread_area(CPUX86State
*env
, abi_ulong ptr
)
2549 uint64_t *gdt_table
= g2h(env
->gdt
.base
);
2550 struct target_modify_ldt_ldt_s ldt_info
;
2551 struct target_modify_ldt_ldt_s
*target_ldt_info
;
2552 int seg_32bit
, contents
, read_exec_only
, limit_in_pages
;
2553 int seg_not_present
, useable
, lm
;
2554 uint32_t *lp
, entry_1
, entry_2
;
2557 lock_user_struct(VERIFY_WRITE
, target_ldt_info
, ptr
, 1);
2558 if (!target_ldt_info
)
2559 return -TARGET_EFAULT
;
2560 ldt_info
.entry_number
= tswap32(target_ldt_info
->entry_number
);
2561 ldt_info
.base_addr
= tswapl(target_ldt_info
->base_addr
);
2562 ldt_info
.limit
= tswap32(target_ldt_info
->limit
);
2563 ldt_info
.flags
= tswap32(target_ldt_info
->flags
);
2564 if (ldt_info
.entry_number
== -1) {
2565 for (i
=TARGET_GDT_ENTRY_TLS_MIN
; i
<=TARGET_GDT_ENTRY_TLS_MAX
; i
++) {
2566 if (gdt_table
[i
] == 0) {
2567 ldt_info
.entry_number
= i
;
2568 target_ldt_info
->entry_number
= tswap32(i
);
2573 unlock_user_struct(target_ldt_info
, ptr
, 1);
2575 if (ldt_info
.entry_number
< TARGET_GDT_ENTRY_TLS_MIN
||
2576 ldt_info
.entry_number
> TARGET_GDT_ENTRY_TLS_MAX
)
2577 return -TARGET_EINVAL
;
2578 seg_32bit
= ldt_info
.flags
& 1;
2579 contents
= (ldt_info
.flags
>> 1) & 3;
2580 read_exec_only
= (ldt_info
.flags
>> 3) & 1;
2581 limit_in_pages
= (ldt_info
.flags
>> 4) & 1;
2582 seg_not_present
= (ldt_info
.flags
>> 5) & 1;
2583 useable
= (ldt_info
.flags
>> 6) & 1;
2587 lm
= (ldt_info
.flags
>> 7) & 1;
2590 if (contents
== 3) {
2591 if (seg_not_present
== 0)
2592 return -TARGET_EINVAL
;
2595 /* NOTE: same code as Linux kernel */
2596 /* Allow LDTs to be cleared by the user. */
2597 if (ldt_info
.base_addr
== 0 && ldt_info
.limit
== 0) {
2598 if ((contents
== 0 &&
2599 read_exec_only
== 1 &&
2601 limit_in_pages
== 0 &&
2602 seg_not_present
== 1 &&
2610 entry_1
= ((ldt_info
.base_addr
& 0x0000ffff) << 16) |
2611 (ldt_info
.limit
& 0x0ffff);
2612 entry_2
= (ldt_info
.base_addr
& 0xff000000) |
2613 ((ldt_info
.base_addr
& 0x00ff0000) >> 16) |
2614 (ldt_info
.limit
& 0xf0000) |
2615 ((read_exec_only
^ 1) << 9) |
2617 ((seg_not_present
^ 1) << 15) |
2619 (limit_in_pages
<< 23) |
2624 /* Install the new entry ... */
2626 lp
= (uint32_t *)(gdt_table
+ ldt_info
.entry_number
);
2627 lp
[0] = tswap32(entry_1
);
2628 lp
[1] = tswap32(entry_2
);
2632 abi_long
do_get_thread_area(CPUX86State
*env
, abi_ulong ptr
)
2634 struct target_modify_ldt_ldt_s
*target_ldt_info
;
2635 uint64_t *gdt_table
= g2h(env
->gdt
.base
);
2636 uint32_t base_addr
, limit
, flags
;
2637 int seg_32bit
, contents
, read_exec_only
, limit_in_pages
, idx
;
2638 int seg_not_present
, useable
, lm
;
2639 uint32_t *lp
, entry_1
, entry_2
;
2641 lock_user_struct(VERIFY_WRITE
, target_ldt_info
, ptr
, 1);
2642 if (!target_ldt_info
)
2643 return -TARGET_EFAULT
;
2644 idx
= tswap32(target_ldt_info
->entry_number
);
2645 if (idx
< TARGET_GDT_ENTRY_TLS_MIN
||
2646 idx
> TARGET_GDT_ENTRY_TLS_MAX
) {
2647 unlock_user_struct(target_ldt_info
, ptr
, 1);
2648 return -TARGET_EINVAL
;
2650 lp
= (uint32_t *)(gdt_table
+ idx
);
2651 entry_1
= tswap32(lp
[0]);
2652 entry_2
= tswap32(lp
[1]);
2654 read_exec_only
= ((entry_2
>> 9) & 1) ^ 1;
2655 contents
= (entry_2
>> 10) & 3;
2656 seg_not_present
= ((entry_2
>> 15) & 1) ^ 1;
2657 seg_32bit
= (entry_2
>> 22) & 1;
2658 limit_in_pages
= (entry_2
>> 23) & 1;
2659 useable
= (entry_2
>> 20) & 1;
2663 lm
= (entry_2
>> 21) & 1;
2665 flags
= (seg_32bit
<< 0) | (contents
<< 1) |
2666 (read_exec_only
<< 3) | (limit_in_pages
<< 4) |
2667 (seg_not_present
<< 5) | (useable
<< 6) | (lm
<< 7);
2668 limit
= (entry_1
& 0xffff) | (entry_2
& 0xf0000);
2669 base_addr
= (entry_1
>> 16) |
2670 (entry_2
& 0xff000000) |
2671 ((entry_2
& 0xff) << 16);
2672 target_ldt_info
->base_addr
= tswapl(base_addr
);
2673 target_ldt_info
->limit
= tswap32(limit
);
2674 target_ldt_info
->flags
= tswap32(flags
);
2675 unlock_user_struct(target_ldt_info
, ptr
, 1);
2679 #ifndef TARGET_ABI32
2680 abi_long
do_arch_prctl(CPUX86State
*env
, int code
, abi_ulong addr
)
2687 case TARGET_ARCH_SET_GS
:
2688 case TARGET_ARCH_SET_FS
:
2689 if (code
== TARGET_ARCH_SET_GS
)
2693 cpu_x86_load_seg(env
, idx
, 0);
2694 env
->segs
[idx
].base
= addr
;
2696 case TARGET_ARCH_GET_GS
:
2697 case TARGET_ARCH_GET_FS
:
2698 if (code
== TARGET_ARCH_GET_GS
)
2702 val
= env
->segs
[idx
].base
;
2703 if (put_user(val
, addr
, abi_ulong
))
2704 return -TARGET_EFAULT
;
2707 ret
= -TARGET_EINVAL
;
2714 #endif /* defined(TARGET_I386) */
2716 #if defined(USE_NPTL)
2718 #define NEW_STACK_SIZE PTHREAD_STACK_MIN
2720 static pthread_mutex_t clone_lock
= PTHREAD_MUTEX_INITIALIZER
;
2723 pthread_mutex_t mutex
;
2724 pthread_cond_t cond
;
2727 abi_ulong child_tidptr
;
2728 abi_ulong parent_tidptr
;
2732 static void *clone_func(void *arg
)
2734 new_thread_info
*info
= arg
;
2739 info
->tid
= gettid();
2740 if (info
->child_tidptr
)
2741 put_user_u32(info
->tid
, info
->child_tidptr
);
2742 if (info
->parent_tidptr
)
2743 put_user_u32(info
->tid
, info
->parent_tidptr
);
2744 /* Enable signals. */
2745 sigprocmask(SIG_SETMASK
, &info
->sigmask
, NULL
);
2746 /* Signal to the parent that we're ready. */
2747 pthread_mutex_lock(&info
->mutex
);
2748 pthread_cond_broadcast(&info
->cond
);
2749 pthread_mutex_unlock(&info
->mutex
);
2750 /* Wait until the parent has finshed initializing the tls state. */
2751 pthread_mutex_lock(&clone_lock
);
2752 pthread_mutex_unlock(&clone_lock
);
2758 /* this stack is the equivalent of the kernel stack associated with a
2760 #define NEW_STACK_SIZE 8192
2762 static int clone_func(void *arg
)
2764 CPUState
*env
= arg
;
2771 /* do_fork() Must return host values and target errnos (unlike most
2772 do_*() functions). */
2773 static int do_fork(CPUState
*env
, unsigned int flags
, abi_ulong newsp
,
2774 abi_ulong parent_tidptr
, target_ulong newtls
,
2775 abi_ulong child_tidptr
)
2781 #if defined(USE_NPTL)
2782 unsigned int nptl_flags
;
2786 if (flags
& CLONE_VM
) {
2787 #if defined(USE_NPTL)
2788 new_thread_info info
;
2789 pthread_attr_t attr
;
2791 ts
= qemu_mallocz(sizeof(TaskState
) + NEW_STACK_SIZE
);
2792 init_task_state(ts
);
2793 new_stack
= ts
->stack
;
2794 /* we create a new CPU instance. */
2795 new_env
= cpu_copy(env
);
2796 /* Init regs that differ from the parent. */
2797 cpu_clone_regs(new_env
, newsp
);
2798 new_env
->opaque
= ts
;
2799 #if defined(USE_NPTL)
2801 flags
&= ~CLONE_NPTL_FLAGS2
;
2803 /* TODO: Implement CLONE_CHILD_CLEARTID. */
2804 if (nptl_flags
& CLONE_SETTLS
)
2805 cpu_set_tls (new_env
, newtls
);
2807 /* Grab a mutex so that thread setup appears atomic. */
2808 pthread_mutex_lock(&clone_lock
);
2810 memset(&info
, 0, sizeof(info
));
2811 pthread_mutex_init(&info
.mutex
, NULL
);
2812 pthread_mutex_lock(&info
.mutex
);
2813 pthread_cond_init(&info
.cond
, NULL
);
2815 if (nptl_flags
& CLONE_CHILD_SETTID
)
2816 info
.child_tidptr
= child_tidptr
;
2817 if (nptl_flags
& CLONE_PARENT_SETTID
)
2818 info
.parent_tidptr
= parent_tidptr
;
2820 ret
= pthread_attr_init(&attr
);
2821 ret
= pthread_attr_setstack(&attr
, new_stack
, NEW_STACK_SIZE
);
2822 /* It is not safe to deliver signals until the child has finished
2823 initializing, so temporarily block all signals. */
2824 sigfillset(&sigmask
);
2825 sigprocmask(SIG_BLOCK
, &sigmask
, &info
.sigmask
);
2827 ret
= pthread_create(&info
.thread
, &attr
, clone_func
, &info
);
2829 sigprocmask(SIG_SETMASK
, &info
.sigmask
, NULL
);
2830 pthread_attr_destroy(&attr
);
2832 /* Wait for the child to initialize. */
2833 pthread_cond_wait(&info
.cond
, &info
.mutex
);
2835 if (flags
& CLONE_PARENT_SETTID
)
2836 put_user_u32(ret
, parent_tidptr
);
2840 pthread_mutex_unlock(&info
.mutex
);
2841 pthread_cond_destroy(&info
.cond
);
2842 pthread_mutex_destroy(&info
.mutex
);
2843 pthread_mutex_unlock(&clone_lock
);
2845 if (flags
& CLONE_NPTL_FLAGS2
)
2847 /* This is probably going to die very quickly, but do it anyway. */
2849 ret
= __clone2(clone_func
, new_stack
+ NEW_STACK_SIZE
, flags
, new_env
);
2851 ret
= clone(clone_func
, new_stack
+ NEW_STACK_SIZE
, flags
, new_env
);
2855 /* if no CLONE_VM, we consider it is a fork */
2856 if ((flags
& ~(CSIGNAL
| CLONE_NPTL_FLAGS2
)) != 0)
2860 #if defined(USE_NPTL)
2861 /* There is a race condition here. The parent process could
2862 theoretically read the TID in the child process before the child
2863 tid is set. This would require using either ptrace
2864 (not implemented) or having *_tidptr to point at a shared memory
2865 mapping. We can't repeat the spinlock hack used above because
2866 the child process gets its own copy of the lock. */
2868 cpu_clone_regs(env
, newsp
);
2870 /* Child Process. */
2871 if (flags
& CLONE_CHILD_SETTID
)
2872 put_user_u32(gettid(), child_tidptr
);
2873 if (flags
& CLONE_PARENT_SETTID
)
2874 put_user_u32(gettid(), parent_tidptr
);
2875 ts
= (TaskState
*)env
->opaque
;
2876 if (flags
& CLONE_SETTLS
)
2877 cpu_set_tls (env
, newtls
);
2878 /* TODO: Implement CLONE_CHILD_CLEARTID. */
2884 cpu_clone_regs(env
, newsp
);
2891 static abi_long
do_fcntl(int fd
, int cmd
, abi_ulong arg
)
2894 struct target_flock
*target_fl
;
2895 struct flock64 fl64
;
2896 struct target_flock64
*target_fl64
;
2900 case TARGET_F_GETLK
:
2901 if (!lock_user_struct(VERIFY_READ
, target_fl
, arg
, 1))
2902 return -TARGET_EFAULT
;
2903 fl
.l_type
= tswap16(target_fl
->l_type
);
2904 fl
.l_whence
= tswap16(target_fl
->l_whence
);
2905 fl
.l_start
= tswapl(target_fl
->l_start
);
2906 fl
.l_len
= tswapl(target_fl
->l_len
);
2907 fl
.l_pid
= tswapl(target_fl
->l_pid
);
2908 unlock_user_struct(target_fl
, arg
, 0);
2909 ret
= get_errno(fcntl(fd
, cmd
, &fl
));
2911 if (!lock_user_struct(VERIFY_WRITE
, target_fl
, arg
, 0))
2912 return -TARGET_EFAULT
;
2913 target_fl
->l_type
= tswap16(fl
.l_type
);
2914 target_fl
->l_whence
= tswap16(fl
.l_whence
);
2915 target_fl
->l_start
= tswapl(fl
.l_start
);
2916 target_fl
->l_len
= tswapl(fl
.l_len
);
2917 target_fl
->l_pid
= tswapl(fl
.l_pid
);
2918 unlock_user_struct(target_fl
, arg
, 1);
2922 case TARGET_F_SETLK
:
2923 case TARGET_F_SETLKW
:
2924 if (!lock_user_struct(VERIFY_READ
, target_fl
, arg
, 1))
2925 return -TARGET_EFAULT
;
2926 fl
.l_type
= tswap16(target_fl
->l_type
);
2927 fl
.l_whence
= tswap16(target_fl
->l_whence
);
2928 fl
.l_start
= tswapl(target_fl
->l_start
);
2929 fl
.l_len
= tswapl(target_fl
->l_len
);
2930 fl
.l_pid
= tswapl(target_fl
->l_pid
);
2931 unlock_user_struct(target_fl
, arg
, 0);
2932 ret
= get_errno(fcntl(fd
, cmd
, &fl
));
2935 case TARGET_F_GETLK64
:
2936 if (!lock_user_struct(VERIFY_READ
, target_fl64
, arg
, 1))
2937 return -TARGET_EFAULT
;
2938 fl64
.l_type
= tswap16(target_fl64
->l_type
) >> 1;
2939 fl64
.l_whence
= tswap16(target_fl64
->l_whence
);
2940 fl64
.l_start
= tswapl(target_fl64
->l_start
);
2941 fl64
.l_len
= tswapl(target_fl64
->l_len
);
2942 fl64
.l_pid
= tswap16(target_fl64
->l_pid
);
2943 unlock_user_struct(target_fl64
, arg
, 0);
2944 ret
= get_errno(fcntl(fd
, cmd
>> 1, &fl64
));
2946 if (!lock_user_struct(VERIFY_WRITE
, target_fl64
, arg
, 0))
2947 return -TARGET_EFAULT
;
2948 target_fl64
->l_type
= tswap16(fl64
.l_type
) >> 1;
2949 target_fl64
->l_whence
= tswap16(fl64
.l_whence
);
2950 target_fl64
->l_start
= tswapl(fl64
.l_start
);
2951 target_fl64
->l_len
= tswapl(fl64
.l_len
);
2952 target_fl64
->l_pid
= tswapl(fl64
.l_pid
);
2953 unlock_user_struct(target_fl64
, arg
, 1);
2956 case TARGET_F_SETLK64
:
2957 case TARGET_F_SETLKW64
:
2958 if (!lock_user_struct(VERIFY_READ
, target_fl64
, arg
, 1))
2959 return -TARGET_EFAULT
;
2960 fl64
.l_type
= tswap16(target_fl64
->l_type
) >> 1;
2961 fl64
.l_whence
= tswap16(target_fl64
->l_whence
);
2962 fl64
.l_start
= tswapl(target_fl64
->l_start
);
2963 fl64
.l_len
= tswapl(target_fl64
->l_len
);
2964 fl64
.l_pid
= tswap16(target_fl64
->l_pid
);
2965 unlock_user_struct(target_fl64
, arg
, 0);
2966 ret
= get_errno(fcntl(fd
, cmd
>> 1, &fl64
));
2970 ret
= get_errno(fcntl(fd
, cmd
, arg
));
2972 ret
= host_to_target_bitmask(ret
, fcntl_flags_tbl
);
2977 ret
= get_errno(fcntl(fd
, cmd
, target_to_host_bitmask(arg
, fcntl_flags_tbl
)));
2981 ret
= get_errno(fcntl(fd
, cmd
, arg
));
2989 static inline int high2lowuid(int uid
)
2997 static inline int high2lowgid(int gid
)
3005 static inline int low2highuid(int uid
)
3007 if ((int16_t)uid
== -1)
3013 static inline int low2highgid(int gid
)
3015 if ((int16_t)gid
== -1)
3021 #endif /* USE_UID16 */
3023 void syscall_init(void)
3026 const argtype
*arg_type
;
3030 #define STRUCT(name, list...) thunk_register_struct(STRUCT_ ## name, #name, struct_ ## name ## _def);
3031 #define STRUCT_SPECIAL(name) thunk_register_struct_direct(STRUCT_ ## name, #name, &struct_ ## name ## _def);
3032 #include "syscall_types.h"
3034 #undef STRUCT_SPECIAL
3036 /* we patch the ioctl size if necessary. We rely on the fact that
3037 no ioctl has all the bits at '1' in the size field */
3039 while (ie
->target_cmd
!= 0) {
3040 if (((ie
->target_cmd
>> TARGET_IOC_SIZESHIFT
) & TARGET_IOC_SIZEMASK
) ==
3041 TARGET_IOC_SIZEMASK
) {
3042 arg_type
= ie
->arg_type
;
3043 if (arg_type
[0] != TYPE_PTR
) {
3044 fprintf(stderr
, "cannot patch size for ioctl 0x%x\n",
3049 size
= thunk_type_size(arg_type
, 0);
3050 ie
->target_cmd
= (ie
->target_cmd
&
3051 ~(TARGET_IOC_SIZEMASK
<< TARGET_IOC_SIZESHIFT
)) |
3052 (size
<< TARGET_IOC_SIZESHIFT
);
3055 /* Build target_to_host_errno_table[] table from
3056 * host_to_target_errno_table[]. */
3057 for (i
=0; i
< ERRNO_TABLE_SIZE
; i
++)
3058 target_to_host_errno_table
[host_to_target_errno_table
[i
]] = i
;
3060 /* automatic consistency check if same arch */
3061 #if defined(__i386__) && defined(TARGET_I386) && defined(TARGET_ABI32)
3062 if (ie
->target_cmd
!= ie
->host_cmd
) {
3063 fprintf(stderr
, "ERROR: ioctl: target=0x%x host=0x%x\n",
3064 ie
->target_cmd
, ie
->host_cmd
);
3071 #if TARGET_ABI_BITS == 32
3072 static inline uint64_t target_offset64(uint32_t word0
, uint32_t word1
)
3074 #ifdef TARGET_WORDS_BIGENDIAN
3075 return ((uint64_t)word0
<< 32) | word1
;
3077 return ((uint64_t)word1
<< 32) | word0
;
3080 #else /* TARGET_ABI_BITS == 32 */
3081 static inline uint64_t target_offset64(uint64_t word0
, uint64_t word1
)
3085 #endif /* TARGET_ABI_BITS != 32 */
3087 #ifdef TARGET_NR_truncate64
3088 static inline abi_long
target_truncate64(void *cpu_env
, const char *arg1
,
3094 if (((CPUARMState
*)cpu_env
)->eabi
)
3100 return get_errno(truncate64(arg1
, target_offset64(arg2
, arg3
)));
3104 #ifdef TARGET_NR_ftruncate64
3105 static inline abi_long
target_ftruncate64(void *cpu_env
, abi_long arg1
,
3111 if (((CPUARMState
*)cpu_env
)->eabi
)
3117 return get_errno(ftruncate64(arg1
, target_offset64(arg2
, arg3
)));
3121 static inline abi_long
target_to_host_timespec(struct timespec
*host_ts
,
3122 abi_ulong target_addr
)
3124 struct target_timespec
*target_ts
;
3126 if (!lock_user_struct(VERIFY_READ
, target_ts
, target_addr
, 1))
3127 return -TARGET_EFAULT
;
3128 host_ts
->tv_sec
= tswapl(target_ts
->tv_sec
);
3129 host_ts
->tv_nsec
= tswapl(target_ts
->tv_nsec
);
3130 unlock_user_struct(target_ts
, target_addr
, 0);
3134 static inline abi_long
host_to_target_timespec(abi_ulong target_addr
,
3135 struct timespec
*host_ts
)
3137 struct target_timespec
*target_ts
;
3139 if (!lock_user_struct(VERIFY_WRITE
, target_ts
, target_addr
, 0))
3140 return -TARGET_EFAULT
;
3141 target_ts
->tv_sec
= tswapl(host_ts
->tv_sec
);
3142 target_ts
->tv_nsec
= tswapl(host_ts
->tv_nsec
);
3143 unlock_user_struct(target_ts
, target_addr
, 1);
3147 #if defined(USE_NPTL)
3148 /* ??? Using host futex calls even when target atomic operations
3149 are not really atomic probably breaks things. However implementing
3150 futexes locally would make futexes shared between multiple processes
3151 tricky. However they're probably useless because guest atomic
3152 operations won't work either. */
3153 int do_futex(target_ulong uaddr
, int op
, int val
, target_ulong timeout
,
3154 target_ulong uaddr2
, int val3
)
3156 struct timespec ts
, *pts
;
3158 /* ??? We assume FUTEX_* constants are the same on both host
3164 target_to_host_timespec(pts
, timeout
);
3168 return get_errno(sys_futex(g2h(uaddr
), FUTEX_WAIT
, tswap32(val
),
3171 return get_errno(sys_futex(g2h(uaddr
), FUTEX_WAKE
, val
, NULL
, NULL
, 0));
3173 return get_errno(sys_futex(g2h(uaddr
), FUTEX_FD
, val
, NULL
, NULL
, 0));
3175 return get_errno(sys_futex(g2h(uaddr
), FUTEX_REQUEUE
, val
,
3176 NULL
, g2h(uaddr2
), 0));
3177 case FUTEX_CMP_REQUEUE
:
3178 return get_errno(sys_futex(g2h(uaddr
), FUTEX_CMP_REQUEUE
, val
,
3179 NULL
, g2h(uaddr2
), tswap32(val3
)));
3181 return -TARGET_ENOSYS
;
3186 int get_osversion(void)
3188 static int osversion
;
3189 struct new_utsname buf
;
3194 if (qemu_uname_release
&& *qemu_uname_release
) {
3195 s
= qemu_uname_release
;
3197 if (sys_uname(&buf
))
3202 for (i
= 0; i
< 3; i
++) {
3204 while (*s
>= '0' && *s
<= '9') {
3209 tmp
= (tmp
<< 8) + n
;
3217 /* do_syscall() should always have a single exit point at the end so
3218 that actions, such as logging of syscall results, can be performed.
3219 All errnos that do_syscall() returns must be -TARGET_<errcode>. */
3220 abi_long
do_syscall(void *cpu_env
, int num
, abi_long arg1
,
3221 abi_long arg2
, abi_long arg3
, abi_long arg4
,
3222 abi_long arg5
, abi_long arg6
)
3230 gemu_log("syscall %d", num
);
3233 print_syscall(num
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
3236 case TARGET_NR_exit
:
3240 gdb_exit(cpu_env
, arg1
);
3241 /* XXX: should free thread stack and CPU env */
3243 ret
= 0; /* avoid warning */
3245 case TARGET_NR_read
:
3246 if (!(p
= lock_user(VERIFY_WRITE
, arg2
, arg3
, 0)))
3248 ret
= get_errno(read(arg1
, p
, arg3
));
3249 unlock_user(p
, arg2
, ret
);
3251 case TARGET_NR_write
:
3252 if (!(p
= lock_user(VERIFY_READ
, arg2
, arg3
, 1)))
3254 ret
= get_errno(write(arg1
, p
, arg3
));
3255 unlock_user(p
, arg2
, 0);
3257 case TARGET_NR_open
:
3258 if (!(p
= lock_user_string(arg1
)))
3260 ret
= get_errno(open(path(p
),
3261 target_to_host_bitmask(arg2
, fcntl_flags_tbl
),
3263 unlock_user(p
, arg1
, 0);
3265 #if defined(TARGET_NR_openat) && defined(__NR_openat)
3266 case TARGET_NR_openat
:
3267 if (!(p
= lock_user_string(arg2
)))
3269 ret
= get_errno(sys_openat(arg1
,
3271 target_to_host_bitmask(arg3
, fcntl_flags_tbl
),
3273 unlock_user(p
, arg2
, 0);
3276 case TARGET_NR_close
:
3277 ret
= get_errno(close(arg1
));
3282 case TARGET_NR_fork
:
3283 ret
= get_errno(do_fork(cpu_env
, SIGCHLD
, 0, 0, 0, 0));
3285 #ifdef TARGET_NR_waitpid
3286 case TARGET_NR_waitpid
:
3289 ret
= get_errno(waitpid(arg1
, &status
, arg3
));
3290 if (!is_error(ret
) && arg2
3291 && put_user_s32(status
, arg2
))
3296 #ifdef TARGET_NR_waitid
3297 case TARGET_NR_waitid
:
3301 ret
= get_errno(waitid(arg1
, arg2
, &info
, arg4
));
3302 if (!is_error(ret
) && arg3
&& info
.si_pid
!= 0) {
3303 if (!(p
= lock_user(VERIFY_WRITE
, arg3
, sizeof(target_siginfo_t
), 0)))
3305 host_to_target_siginfo(p
, &info
);
3306 unlock_user(p
, arg3
, sizeof(target_siginfo_t
));
3311 #ifdef TARGET_NR_creat /* not on alpha */
3312 case TARGET_NR_creat
:
3313 if (!(p
= lock_user_string(arg1
)))
3315 ret
= get_errno(creat(p
, arg2
));
3316 unlock_user(p
, arg1
, 0);
3319 case TARGET_NR_link
:
3322 p
= lock_user_string(arg1
);
3323 p2
= lock_user_string(arg2
);
3325 ret
= -TARGET_EFAULT
;
3327 ret
= get_errno(link(p
, p2
));
3328 unlock_user(p2
, arg2
, 0);
3329 unlock_user(p
, arg1
, 0);
3332 #if defined(TARGET_NR_linkat) && defined(__NR_linkat)
3333 case TARGET_NR_linkat
:
3338 p
= lock_user_string(arg2
);
3339 p2
= lock_user_string(arg4
);
3341 ret
= -TARGET_EFAULT
;
3343 ret
= get_errno(sys_linkat(arg1
, p
, arg3
, p2
, arg5
));
3344 unlock_user(p
, arg2
, 0);
3345 unlock_user(p2
, arg4
, 0);
3349 case TARGET_NR_unlink
:
3350 if (!(p
= lock_user_string(arg1
)))
3352 ret
= get_errno(unlink(p
));
3353 unlock_user(p
, arg1
, 0);
3355 #if defined(TARGET_NR_unlinkat) && defined(__NR_unlinkat)
3356 case TARGET_NR_unlinkat
:
3357 if (!(p
= lock_user_string(arg2
)))
3359 ret
= get_errno(sys_unlinkat(arg1
, p
, arg3
));
3360 unlock_user(p
, arg2
, 0);
3363 case TARGET_NR_execve
:
3365 char **argp
, **envp
;
3368 abi_ulong guest_argp
;
3369 abi_ulong guest_envp
;
3375 for (gp
= guest_argp
; gp
; gp
+= sizeof(abi_ulong
)) {
3376 if (get_user_ual(addr
, gp
))
3384 for (gp
= guest_envp
; gp
; gp
+= sizeof(abi_ulong
)) {
3385 if (get_user_ual(addr
, gp
))
3392 argp
= alloca((argc
+ 1) * sizeof(void *));
3393 envp
= alloca((envc
+ 1) * sizeof(void *));
3395 for (gp
= guest_argp
, q
= argp
; gp
;
3396 gp
+= sizeof(abi_ulong
), q
++) {
3397 if (get_user_ual(addr
, gp
))
3401 if (!(*q
= lock_user_string(addr
)))
3406 for (gp
= guest_envp
, q
= envp
; gp
;
3407 gp
+= sizeof(abi_ulong
), q
++) {
3408 if (get_user_ual(addr
, gp
))
3412 if (!(*q
= lock_user_string(addr
)))
3417 if (!(p
= lock_user_string(arg1
)))
3419 ret
= get_errno(execve(p
, argp
, envp
));
3420 unlock_user(p
, arg1
, 0);
3425 ret
= -TARGET_EFAULT
;
3428 for (gp
= guest_argp
, q
= argp
; *q
;
3429 gp
+= sizeof(abi_ulong
), q
++) {
3430 if (get_user_ual(addr
, gp
)
3433 unlock_user(*q
, addr
, 0);
3435 for (gp
= guest_envp
, q
= envp
; *q
;
3436 gp
+= sizeof(abi_ulong
), q
++) {
3437 if (get_user_ual(addr
, gp
)
3440 unlock_user(*q
, addr
, 0);
3444 case TARGET_NR_chdir
:
3445 if (!(p
= lock_user_string(arg1
)))
3447 ret
= get_errno(chdir(p
));
3448 unlock_user(p
, arg1
, 0);
3450 #ifdef TARGET_NR_time
3451 case TARGET_NR_time
:
3454 ret
= get_errno(time(&host_time
));
3457 && put_user_sal(host_time
, arg1
))
3462 case TARGET_NR_mknod
:
3463 if (!(p
= lock_user_string(arg1
)))
3465 ret
= get_errno(mknod(p
, arg2
, arg3
));
3466 unlock_user(p
, arg1
, 0);
3468 #if defined(TARGET_NR_mknodat) && defined(__NR_mknodat)
3469 case TARGET_NR_mknodat
:
3470 if (!(p
= lock_user_string(arg2
)))
3472 ret
= get_errno(sys_mknodat(arg1
, p
, arg3
, arg4
));
3473 unlock_user(p
, arg2
, 0);
3476 case TARGET_NR_chmod
:
3477 if (!(p
= lock_user_string(arg1
)))
3479 ret
= get_errno(chmod(p
, arg2
));
3480 unlock_user(p
, arg1
, 0);
3482 #ifdef TARGET_NR_break
3483 case TARGET_NR_break
:
3486 #ifdef TARGET_NR_oldstat
3487 case TARGET_NR_oldstat
:
3490 case TARGET_NR_lseek
:
3491 ret
= get_errno(lseek(arg1
, arg2
, arg3
));
3493 #ifdef TARGET_NR_getxpid
3494 case TARGET_NR_getxpid
:
3496 case TARGET_NR_getpid
:
3498 ret
= get_errno(getpid());
3500 case TARGET_NR_mount
:
3502 /* need to look at the data field */
3504 p
= lock_user_string(arg1
);
3505 p2
= lock_user_string(arg2
);
3506 p3
= lock_user_string(arg3
);
3507 if (!p
|| !p2
|| !p3
)
3508 ret
= -TARGET_EFAULT
;
3510 /* FIXME - arg5 should be locked, but it isn't clear how to
3511 * do that since it's not guaranteed to be a NULL-terminated
3514 ret
= get_errno(mount(p
, p2
, p3
, (unsigned long)arg4
, g2h(arg5
)));
3515 unlock_user(p
, arg1
, 0);
3516 unlock_user(p2
, arg2
, 0);
3517 unlock_user(p3
, arg3
, 0);
3520 #ifdef TARGET_NR_umount
3521 case TARGET_NR_umount
:
3522 if (!(p
= lock_user_string(arg1
)))
3524 ret
= get_errno(umount(p
));
3525 unlock_user(p
, arg1
, 0);
3528 #ifdef TARGET_NR_stime /* not on alpha */
3529 case TARGET_NR_stime
:
3532 if (get_user_sal(host_time
, arg1
))
3534 ret
= get_errno(stime(&host_time
));
3538 case TARGET_NR_ptrace
:
3540 #ifdef TARGET_NR_alarm /* not on alpha */
3541 case TARGET_NR_alarm
:
3545 #ifdef TARGET_NR_oldfstat
3546 case TARGET_NR_oldfstat
:
3549 #ifdef TARGET_NR_pause /* not on alpha */
3550 case TARGET_NR_pause
:
3551 ret
= get_errno(pause());
3554 #ifdef TARGET_NR_utime
3555 case TARGET_NR_utime
:
3557 struct utimbuf tbuf
, *host_tbuf
;
3558 struct target_utimbuf
*target_tbuf
;
3560 if (!lock_user_struct(VERIFY_READ
, target_tbuf
, arg2
, 1))
3562 tbuf
.actime
= tswapl(target_tbuf
->actime
);
3563 tbuf
.modtime
= tswapl(target_tbuf
->modtime
);
3564 unlock_user_struct(target_tbuf
, arg2
, 0);
3569 if (!(p
= lock_user_string(arg1
)))
3571 ret
= get_errno(utime(p
, host_tbuf
));
3572 unlock_user(p
, arg1
, 0);
3576 case TARGET_NR_utimes
:
3578 struct timeval
*tvp
, tv
[2];
3580 if (copy_from_user_timeval(&tv
[0], arg2
)
3581 || copy_from_user_timeval(&tv
[1],
3582 arg2
+ sizeof(struct target_timeval
)))
3588 if (!(p
= lock_user_string(arg1
)))
3590 ret
= get_errno(utimes(p
, tvp
));
3591 unlock_user(p
, arg1
, 0);
3594 #ifdef TARGET_NR_stty
3595 case TARGET_NR_stty
:
3598 #ifdef TARGET_NR_gtty
3599 case TARGET_NR_gtty
:
3602 case TARGET_NR_access
:
3603 if (!(p
= lock_user_string(arg1
)))
3605 ret
= get_errno(access(p
, arg2
));
3606 unlock_user(p
, arg1
, 0);
3608 #if defined(TARGET_NR_faccessat) && defined(__NR_faccessat)
3609 case TARGET_NR_faccessat
:
3610 if (!(p
= lock_user_string(arg2
)))
3612 ret
= get_errno(sys_faccessat(arg1
, p
, arg3
, arg4
));
3613 unlock_user(p
, arg2
, 0);
3616 #ifdef TARGET_NR_nice /* not on alpha */
3617 case TARGET_NR_nice
:
3618 ret
= get_errno(nice(arg1
));
3621 #ifdef TARGET_NR_ftime
3622 case TARGET_NR_ftime
:
3625 case TARGET_NR_sync
:
3629 case TARGET_NR_kill
:
3630 ret
= get_errno(kill(arg1
, target_to_host_signal(arg2
)));
3632 case TARGET_NR_rename
:
3635 p
= lock_user_string(arg1
);
3636 p2
= lock_user_string(arg2
);
3638 ret
= -TARGET_EFAULT
;
3640 ret
= get_errno(rename(p
, p2
));
3641 unlock_user(p2
, arg2
, 0);
3642 unlock_user(p
, arg1
, 0);
3645 #if defined(TARGET_NR_renameat) && defined(__NR_renameat)
3646 case TARGET_NR_renameat
:
3649 p
= lock_user_string(arg2
);
3650 p2
= lock_user_string(arg4
);
3652 ret
= -TARGET_EFAULT
;
3654 ret
= get_errno(sys_renameat(arg1
, p
, arg3
, p2
));
3655 unlock_user(p2
, arg4
, 0);
3656 unlock_user(p
, arg2
, 0);
3660 case TARGET_NR_mkdir
:
3661 if (!(p
= lock_user_string(arg1
)))
3663 ret
= get_errno(mkdir(p
, arg2
));
3664 unlock_user(p
, arg1
, 0);
3666 #if defined(TARGET_NR_mkdirat) && defined(__NR_mkdirat)
3667 case TARGET_NR_mkdirat
:
3668 if (!(p
= lock_user_string(arg2
)))
3670 ret
= get_errno(sys_mkdirat(arg1
, p
, arg3
));
3671 unlock_user(p
, arg2
, 0);
3674 case TARGET_NR_rmdir
:
3675 if (!(p
= lock_user_string(arg1
)))
3677 ret
= get_errno(rmdir(p
));
3678 unlock_user(p
, arg1
, 0);
3681 ret
= get_errno(dup(arg1
));
3683 case TARGET_NR_pipe
:
3686 ret
= get_errno(pipe(host_pipe
));
3687 if (!is_error(ret
)) {
3688 #if defined(TARGET_MIPS)
3689 CPUMIPSState
*env
= (CPUMIPSState
*)cpu_env
;
3690 env
->active_tc
.gpr
[3] = host_pipe
[1];
3692 #elif defined(TARGET_SH4)
3693 ((CPUSH4State
*)cpu_env
)->gregs
[1] = host_pipe
[1];
3696 if (put_user_s32(host_pipe
[0], arg1
)
3697 || put_user_s32(host_pipe
[1], arg1
+ sizeof(host_pipe
[0])))
3703 case TARGET_NR_times
:
3705 struct target_tms
*tmsp
;
3707 ret
= get_errno(times(&tms
));
3709 tmsp
= lock_user(VERIFY_WRITE
, arg1
, sizeof(struct target_tms
), 0);
3712 tmsp
->tms_utime
= tswapl(host_to_target_clock_t(tms
.tms_utime
));
3713 tmsp
->tms_stime
= tswapl(host_to_target_clock_t(tms
.tms_stime
));
3714 tmsp
->tms_cutime
= tswapl(host_to_target_clock_t(tms
.tms_cutime
));
3715 tmsp
->tms_cstime
= tswapl(host_to_target_clock_t(tms
.tms_cstime
));
3718 ret
= host_to_target_clock_t(ret
);
3721 #ifdef TARGET_NR_prof
3722 case TARGET_NR_prof
:
3725 #ifdef TARGET_NR_signal
3726 case TARGET_NR_signal
:
3729 case TARGET_NR_acct
:
3730 if (!(p
= lock_user_string(arg1
)))
3732 ret
= get_errno(acct(path(p
)));
3733 unlock_user(p
, arg1
, 0);
3735 #ifdef TARGET_NR_umount2 /* not on alpha */
3736 case TARGET_NR_umount2
:
3737 if (!(p
= lock_user_string(arg1
)))
3739 ret
= get_errno(umount2(p
, arg2
));
3740 unlock_user(p
, arg1
, 0);
3743 #ifdef TARGET_NR_lock
3744 case TARGET_NR_lock
:
3747 case TARGET_NR_ioctl
:
3748 ret
= do_ioctl(arg1
, arg2
, arg3
);
3750 case TARGET_NR_fcntl
:
3751 ret
= do_fcntl(arg1
, arg2
, arg3
);
3753 #ifdef TARGET_NR_mpx
3757 case TARGET_NR_setpgid
:
3758 ret
= get_errno(setpgid(arg1
, arg2
));
3760 #ifdef TARGET_NR_ulimit
3761 case TARGET_NR_ulimit
:
3764 #ifdef TARGET_NR_oldolduname
3765 case TARGET_NR_oldolduname
:
3768 case TARGET_NR_umask
:
3769 ret
= get_errno(umask(arg1
));
3771 case TARGET_NR_chroot
:
3772 if (!(p
= lock_user_string(arg1
)))
3774 ret
= get_errno(chroot(p
));
3775 unlock_user(p
, arg1
, 0);
3777 case TARGET_NR_ustat
:
3779 case TARGET_NR_dup2
:
3780 ret
= get_errno(dup2(arg1
, arg2
));
3782 #ifdef TARGET_NR_getppid /* not on alpha */
3783 case TARGET_NR_getppid
:
3784 ret
= get_errno(getppid());
3787 case TARGET_NR_getpgrp
:
3788 ret
= get_errno(getpgrp());
3790 case TARGET_NR_setsid
:
3791 ret
= get_errno(setsid());
3793 #ifdef TARGET_NR_sigaction
3794 case TARGET_NR_sigaction
:
3796 #if !defined(TARGET_MIPS)
3797 struct target_old_sigaction
*old_act
;
3798 struct target_sigaction act
, oact
, *pact
;
3800 if (!lock_user_struct(VERIFY_READ
, old_act
, arg2
, 1))
3802 act
._sa_handler
= old_act
->_sa_handler
;
3803 target_siginitset(&act
.sa_mask
, old_act
->sa_mask
);
3804 act
.sa_flags
= old_act
->sa_flags
;
3805 act
.sa_restorer
= old_act
->sa_restorer
;
3806 unlock_user_struct(old_act
, arg2
, 0);
3811 ret
= get_errno(do_sigaction(arg1
, pact
, &oact
));
3812 if (!is_error(ret
) && arg3
) {
3813 if (!lock_user_struct(VERIFY_WRITE
, old_act
, arg3
, 0))
3815 old_act
->_sa_handler
= oact
._sa_handler
;
3816 old_act
->sa_mask
= oact
.sa_mask
.sig
[0];
3817 old_act
->sa_flags
= oact
.sa_flags
;
3818 old_act
->sa_restorer
= oact
.sa_restorer
;
3819 unlock_user_struct(old_act
, arg3
, 1);
3822 struct target_sigaction act
, oact
, *pact
, *old_act
;
3825 if (!lock_user_struct(VERIFY_READ
, old_act
, arg2
, 1))
3827 act
._sa_handler
= old_act
->_sa_handler
;
3828 target_siginitset(&act
.sa_mask
, old_act
->sa_mask
.sig
[0]);
3829 act
.sa_flags
= old_act
->sa_flags
;
3830 unlock_user_struct(old_act
, arg2
, 0);
3836 ret
= get_errno(do_sigaction(arg1
, pact
, &oact
));
3838 if (!is_error(ret
) && arg3
) {
3839 if (!lock_user_struct(VERIFY_WRITE
, old_act
, arg3
, 0))
3841 old_act
->_sa_handler
= oact
._sa_handler
;
3842 old_act
->sa_flags
= oact
.sa_flags
;
3843 old_act
->sa_mask
.sig
[0] = oact
.sa_mask
.sig
[0];
3844 old_act
->sa_mask
.sig
[1] = 0;
3845 old_act
->sa_mask
.sig
[2] = 0;
3846 old_act
->sa_mask
.sig
[3] = 0;
3847 unlock_user_struct(old_act
, arg3
, 1);
3853 case TARGET_NR_rt_sigaction
:
3855 struct target_sigaction
*act
;
3856 struct target_sigaction
*oact
;
3859 if (!lock_user_struct(VERIFY_READ
, act
, arg2
, 1))
3864 if (!lock_user_struct(VERIFY_WRITE
, oact
, arg3
, 0)) {
3865 ret
= -TARGET_EFAULT
;
3866 goto rt_sigaction_fail
;
3870 ret
= get_errno(do_sigaction(arg1
, act
, oact
));
3873 unlock_user_struct(act
, arg2
, 0);
3875 unlock_user_struct(oact
, arg3
, 1);
3878 #ifdef TARGET_NR_sgetmask /* not on alpha */
3879 case TARGET_NR_sgetmask
:
3882 abi_ulong target_set
;
3883 sigprocmask(0, NULL
, &cur_set
);
3884 host_to_target_old_sigset(&target_set
, &cur_set
);
3889 #ifdef TARGET_NR_ssetmask /* not on alpha */
3890 case TARGET_NR_ssetmask
:
3892 sigset_t set
, oset
, cur_set
;
3893 abi_ulong target_set
= arg1
;
3894 sigprocmask(0, NULL
, &cur_set
);
3895 target_to_host_old_sigset(&set
, &target_set
);
3896 sigorset(&set
, &set
, &cur_set
);
3897 sigprocmask(SIG_SETMASK
, &set
, &oset
);
3898 host_to_target_old_sigset(&target_set
, &oset
);
3903 #ifdef TARGET_NR_sigprocmask
3904 case TARGET_NR_sigprocmask
:
3907 sigset_t set
, oldset
, *set_ptr
;
3911 case TARGET_SIG_BLOCK
:
3914 case TARGET_SIG_UNBLOCK
:
3917 case TARGET_SIG_SETMASK
:
3921 ret
= -TARGET_EINVAL
;
3924 if (!(p
= lock_user(VERIFY_READ
, arg2
, sizeof(target_sigset_t
), 1)))
3926 target_to_host_old_sigset(&set
, p
);
3927 unlock_user(p
, arg2
, 0);
3933 ret
= get_errno(sigprocmask(arg1
, set_ptr
, &oldset
));
3934 if (!is_error(ret
) && arg3
) {
3935 if (!(p
= lock_user(VERIFY_WRITE
, arg3
, sizeof(target_sigset_t
), 0)))
3937 host_to_target_old_sigset(p
, &oldset
);
3938 unlock_user(p
, arg3
, sizeof(target_sigset_t
));
3943 case TARGET_NR_rt_sigprocmask
:
3946 sigset_t set
, oldset
, *set_ptr
;
3950 case TARGET_SIG_BLOCK
:
3953 case TARGET_SIG_UNBLOCK
:
3956 case TARGET_SIG_SETMASK
:
3960 ret
= -TARGET_EINVAL
;
3963 if (!(p
= lock_user(VERIFY_READ
, arg2
, sizeof(target_sigset_t
), 1)))
3965 target_to_host_sigset(&set
, p
);
3966 unlock_user(p
, arg2
, 0);
3972 ret
= get_errno(sigprocmask(how
, set_ptr
, &oldset
));
3973 if (!is_error(ret
) && arg3
) {
3974 if (!(p
= lock_user(VERIFY_WRITE
, arg3
, sizeof(target_sigset_t
), 0)))
3976 host_to_target_sigset(p
, &oldset
);
3977 unlock_user(p
, arg3
, sizeof(target_sigset_t
));
3981 #ifdef TARGET_NR_sigpending
3982 case TARGET_NR_sigpending
:
3985 ret
= get_errno(sigpending(&set
));
3986 if (!is_error(ret
)) {
3987 if (!(p
= lock_user(VERIFY_WRITE
, arg1
, sizeof(target_sigset_t
), 0)))
3989 host_to_target_old_sigset(p
, &set
);
3990 unlock_user(p
, arg1
, sizeof(target_sigset_t
));
3995 case TARGET_NR_rt_sigpending
:
3998 ret
= get_errno(sigpending(&set
));
3999 if (!is_error(ret
)) {
4000 if (!(p
= lock_user(VERIFY_WRITE
, arg1
, sizeof(target_sigset_t
), 0)))
4002 host_to_target_sigset(p
, &set
);
4003 unlock_user(p
, arg1
, sizeof(target_sigset_t
));
4007 #ifdef TARGET_NR_sigsuspend
4008 case TARGET_NR_sigsuspend
:
4011 if (!(p
= lock_user(VERIFY_READ
, arg1
, sizeof(target_sigset_t
), 1)))
4013 target_to_host_old_sigset(&set
, p
);
4014 unlock_user(p
, arg1
, 0);
4015 ret
= get_errno(sigsuspend(&set
));
4019 case TARGET_NR_rt_sigsuspend
:
4022 if (!(p
= lock_user(VERIFY_READ
, arg1
, sizeof(target_sigset_t
), 1)))
4024 target_to_host_sigset(&set
, p
);
4025 unlock_user(p
, arg1
, 0);
4026 ret
= get_errno(sigsuspend(&set
));
4029 case TARGET_NR_rt_sigtimedwait
:
4032 struct timespec uts
, *puts
;
4035 if (!(p
= lock_user(VERIFY_READ
, arg1
, sizeof(target_sigset_t
), 1)))
4037 target_to_host_sigset(&set
, p
);
4038 unlock_user(p
, arg1
, 0);
4041 target_to_host_timespec(puts
, arg3
);
4045 ret
= get_errno(sigtimedwait(&set
, &uinfo
, puts
));
4046 if (!is_error(ret
) && arg2
) {
4047 if (!(p
= lock_user(VERIFY_WRITE
, arg2
, sizeof(target_siginfo_t
), 0)))
4049 host_to_target_siginfo(p
, &uinfo
);
4050 unlock_user(p
, arg2
, sizeof(target_siginfo_t
));
4054 case TARGET_NR_rt_sigqueueinfo
:
4057 if (!(p
= lock_user(VERIFY_READ
, arg3
, sizeof(target_sigset_t
), 1)))
4059 target_to_host_siginfo(&uinfo
, p
);
4060 unlock_user(p
, arg1
, 0);
4061 ret
= get_errno(sys_rt_sigqueueinfo(arg1
, arg2
, &uinfo
));
4064 #ifdef TARGET_NR_sigreturn
4065 case TARGET_NR_sigreturn
:
4066 /* NOTE: ret is eax, so not transcoding must be done */
4067 ret
= do_sigreturn(cpu_env
);
4070 case TARGET_NR_rt_sigreturn
:
4071 /* NOTE: ret is eax, so not transcoding must be done */
4072 ret
= do_rt_sigreturn(cpu_env
);
4074 case TARGET_NR_sethostname
:
4075 if (!(p
= lock_user_string(arg1
)))
4077 ret
= get_errno(sethostname(p
, arg2
));
4078 unlock_user(p
, arg1
, 0);
4080 case TARGET_NR_setrlimit
:
4082 /* XXX: convert resource ? */
4083 int resource
= arg1
;
4084 struct target_rlimit
*target_rlim
;
4086 if (!lock_user_struct(VERIFY_READ
, target_rlim
, arg2
, 1))
4088 rlim
.rlim_cur
= tswapl(target_rlim
->rlim_cur
);
4089 rlim
.rlim_max
= tswapl(target_rlim
->rlim_max
);
4090 unlock_user_struct(target_rlim
, arg2
, 0);
4091 ret
= get_errno(setrlimit(resource
, &rlim
));
4094 case TARGET_NR_getrlimit
:
4096 /* XXX: convert resource ? */
4097 int resource
= arg1
;
4098 struct target_rlimit
*target_rlim
;
4101 ret
= get_errno(getrlimit(resource
, &rlim
));
4102 if (!is_error(ret
)) {
4103 if (!lock_user_struct(VERIFY_WRITE
, target_rlim
, arg2
, 0))
4105 rlim
.rlim_cur
= tswapl(target_rlim
->rlim_cur
);
4106 rlim
.rlim_max
= tswapl(target_rlim
->rlim_max
);
4107 unlock_user_struct(target_rlim
, arg2
, 1);
4111 case TARGET_NR_getrusage
:
4113 struct rusage rusage
;
4114 ret
= get_errno(getrusage(arg1
, &rusage
));
4115 if (!is_error(ret
)) {
4116 host_to_target_rusage(arg2
, &rusage
);
4120 case TARGET_NR_gettimeofday
:
4123 ret
= get_errno(gettimeofday(&tv
, NULL
));
4124 if (!is_error(ret
)) {
4125 if (copy_to_user_timeval(arg1
, &tv
))
4130 case TARGET_NR_settimeofday
:
4133 if (copy_from_user_timeval(&tv
, arg1
))
4135 ret
= get_errno(settimeofday(&tv
, NULL
));
4138 #ifdef TARGET_NR_select
4139 case TARGET_NR_select
:
4141 struct target_sel_arg_struct
*sel
;
4142 abi_ulong inp
, outp
, exp
, tvp
;
4145 if (!lock_user_struct(VERIFY_READ
, sel
, arg1
, 1))
4147 nsel
= tswapl(sel
->n
);
4148 inp
= tswapl(sel
->inp
);
4149 outp
= tswapl(sel
->outp
);
4150 exp
= tswapl(sel
->exp
);
4151 tvp
= tswapl(sel
->tvp
);
4152 unlock_user_struct(sel
, arg1
, 0);
4153 ret
= do_select(nsel
, inp
, outp
, exp
, tvp
);
4157 case TARGET_NR_symlink
:
4160 p
= lock_user_string(arg1
);
4161 p2
= lock_user_string(arg2
);
4163 ret
= -TARGET_EFAULT
;
4165 ret
= get_errno(symlink(p
, p2
));
4166 unlock_user(p2
, arg2
, 0);
4167 unlock_user(p
, arg1
, 0);
4170 #if defined(TARGET_NR_symlinkat) && defined(__NR_symlinkat)
4171 case TARGET_NR_symlinkat
:
4174 p
= lock_user_string(arg1
);
4175 p2
= lock_user_string(arg3
);
4177 ret
= -TARGET_EFAULT
;
4179 ret
= get_errno(sys_symlinkat(p
, arg2
, p2
));
4180 unlock_user(p2
, arg3
, 0);
4181 unlock_user(p
, arg1
, 0);
4185 #ifdef TARGET_NR_oldlstat
4186 case TARGET_NR_oldlstat
:
4189 case TARGET_NR_readlink
:
4192 p
= lock_user_string(arg1
);
4193 p2
= lock_user(VERIFY_WRITE
, arg2
, arg3
, 0);
4195 ret
= -TARGET_EFAULT
;
4197 ret
= get_errno(readlink(path(p
), p2
, arg3
));
4198 unlock_user(p2
, arg2
, ret
);
4199 unlock_user(p
, arg1
, 0);
4202 #if defined(TARGET_NR_readlinkat) && defined(__NR_readlinkat)
4203 case TARGET_NR_readlinkat
:
4206 p
= lock_user_string(arg2
);
4207 p2
= lock_user(VERIFY_WRITE
, arg3
, arg4
, 0);
4209 ret
= -TARGET_EFAULT
;
4211 ret
= get_errno(sys_readlinkat(arg1
, path(p
), p2
, arg4
));
4212 unlock_user(p2
, arg3
, ret
);
4213 unlock_user(p
, arg2
, 0);
4217 #ifdef TARGET_NR_uselib
4218 case TARGET_NR_uselib
:
4221 #ifdef TARGET_NR_swapon
4222 case TARGET_NR_swapon
:
4223 if (!(p
= lock_user_string(arg1
)))
4225 ret
= get_errno(swapon(p
, arg2
));
4226 unlock_user(p
, arg1
, 0);
4229 case TARGET_NR_reboot
:
4231 #ifdef TARGET_NR_readdir
4232 case TARGET_NR_readdir
:
4235 #ifdef TARGET_NR_mmap
4236 case TARGET_NR_mmap
:
4237 #if (defined(TARGET_I386) && defined(TARGET_ABI32)) || defined(TARGET_ARM) || defined(TARGET_M68K) || defined(TARGET_CRIS)
4240 abi_ulong v1
, v2
, v3
, v4
, v5
, v6
;
4241 if (!(v
= lock_user(VERIFY_READ
, arg1
, 6 * sizeof(abi_ulong
), 1)))
4249 unlock_user(v
, arg1
, 0);
4250 ret
= get_errno(target_mmap(v1
, v2
, v3
,
4251 target_to_host_bitmask(v4
, mmap_flags_tbl
),
4255 ret
= get_errno(target_mmap(arg1
, arg2
, arg3
,
4256 target_to_host_bitmask(arg4
, mmap_flags_tbl
),
4262 #ifdef TARGET_NR_mmap2
4263 case TARGET_NR_mmap2
:
4265 #define MMAP_SHIFT 12
4267 ret
= get_errno(target_mmap(arg1
, arg2
, arg3
,
4268 target_to_host_bitmask(arg4
, mmap_flags_tbl
),
4270 arg6
<< MMAP_SHIFT
));
4273 case TARGET_NR_munmap
:
4274 ret
= get_errno(target_munmap(arg1
, arg2
));
4276 case TARGET_NR_mprotect
:
4277 ret
= get_errno(target_mprotect(arg1
, arg2
, arg3
));
4279 #ifdef TARGET_NR_mremap
4280 case TARGET_NR_mremap
:
4281 ret
= get_errno(target_mremap(arg1
, arg2
, arg3
, arg4
, arg5
));
4284 /* ??? msync/mlock/munlock are broken for softmmu. */
4285 #ifdef TARGET_NR_msync
4286 case TARGET_NR_msync
:
4287 ret
= get_errno(msync(g2h(arg1
), arg2
, arg3
));
4290 #ifdef TARGET_NR_mlock
4291 case TARGET_NR_mlock
:
4292 ret
= get_errno(mlock(g2h(arg1
), arg2
));
4295 #ifdef TARGET_NR_munlock
4296 case TARGET_NR_munlock
:
4297 ret
= get_errno(munlock(g2h(arg1
), arg2
));
4300 #ifdef TARGET_NR_mlockall
4301 case TARGET_NR_mlockall
:
4302 ret
= get_errno(mlockall(arg1
));
4305 #ifdef TARGET_NR_munlockall
4306 case TARGET_NR_munlockall
:
4307 ret
= get_errno(munlockall());
4310 case TARGET_NR_truncate
:
4311 if (!(p
= lock_user_string(arg1
)))
4313 ret
= get_errno(truncate(p
, arg2
));
4314 unlock_user(p
, arg1
, 0);
4316 case TARGET_NR_ftruncate
:
4317 ret
= get_errno(ftruncate(arg1
, arg2
));
4319 case TARGET_NR_fchmod
:
4320 ret
= get_errno(fchmod(arg1
, arg2
));
4322 #if defined(TARGET_NR_fchmodat) && defined(__NR_fchmodat)
4323 case TARGET_NR_fchmodat
:
4324 if (!(p
= lock_user_string(arg2
)))
4326 ret
= get_errno(sys_fchmodat(arg1
, p
, arg3
, arg4
));
4327 unlock_user(p
, arg2
, 0);
4330 case TARGET_NR_getpriority
:
4331 /* libc does special remapping of the return value of
4332 * sys_getpriority() so it's just easiest to call
4333 * sys_getpriority() directly rather than through libc. */
4334 ret
= sys_getpriority(arg1
, arg2
);
4336 case TARGET_NR_setpriority
:
4337 ret
= get_errno(setpriority(arg1
, arg2
, arg3
));
4339 #ifdef TARGET_NR_profil
4340 case TARGET_NR_profil
:
4343 case TARGET_NR_statfs
:
4344 if (!(p
= lock_user_string(arg1
)))
4346 ret
= get_errno(statfs(path(p
), &stfs
));
4347 unlock_user(p
, arg1
, 0);
4349 if (!is_error(ret
)) {
4350 struct target_statfs
*target_stfs
;
4352 if (!lock_user_struct(VERIFY_WRITE
, target_stfs
, arg2
, 0))
4354 __put_user(stfs
.f_type
, &target_stfs
->f_type
);
4355 __put_user(stfs
.f_bsize
, &target_stfs
->f_bsize
);
4356 __put_user(stfs
.f_blocks
, &target_stfs
->f_blocks
);
4357 __put_user(stfs
.f_bfree
, &target_stfs
->f_bfree
);
4358 __put_user(stfs
.f_bavail
, &target_stfs
->f_bavail
);
4359 __put_user(stfs
.f_files
, &target_stfs
->f_files
);
4360 __put_user(stfs
.f_ffree
, &target_stfs
->f_ffree
);
4361 __put_user(stfs
.f_fsid
.__val
[0], &target_stfs
->f_fsid
.val
[0]);
4362 __put_user(stfs
.f_fsid
.__val
[1], &target_stfs
->f_fsid
.val
[1]);
4363 __put_user(stfs
.f_namelen
, &target_stfs
->f_namelen
);
4364 unlock_user_struct(target_stfs
, arg2
, 1);
4367 case TARGET_NR_fstatfs
:
4368 ret
= get_errno(fstatfs(arg1
, &stfs
));
4369 goto convert_statfs
;
4370 #ifdef TARGET_NR_statfs64
4371 case TARGET_NR_statfs64
:
4372 if (!(p
= lock_user_string(arg1
)))
4374 ret
= get_errno(statfs(path(p
), &stfs
));
4375 unlock_user(p
, arg1
, 0);
4377 if (!is_error(ret
)) {
4378 struct target_statfs64
*target_stfs
;
4380 if (!lock_user_struct(VERIFY_WRITE
, target_stfs
, arg3
, 0))
4382 __put_user(stfs
.f_type
, &target_stfs
->f_type
);
4383 __put_user(stfs
.f_bsize
, &target_stfs
->f_bsize
);
4384 __put_user(stfs
.f_blocks
, &target_stfs
->f_blocks
);
4385 __put_user(stfs
.f_bfree
, &target_stfs
->f_bfree
);
4386 __put_user(stfs
.f_bavail
, &target_stfs
->f_bavail
);
4387 __put_user(stfs
.f_files
, &target_stfs
->f_files
);
4388 __put_user(stfs
.f_ffree
, &target_stfs
->f_ffree
);
4389 __put_user(stfs
.f_fsid
.__val
[0], &target_stfs
->f_fsid
.val
[0]);
4390 __put_user(stfs
.f_fsid
.__val
[1], &target_stfs
->f_fsid
.val
[1]);
4391 __put_user(stfs
.f_namelen
, &target_stfs
->f_namelen
);
4392 unlock_user_struct(target_stfs
, arg3
, 1);
4395 case TARGET_NR_fstatfs64
:
4396 ret
= get_errno(fstatfs(arg1
, &stfs
));
4397 goto convert_statfs64
;
4399 #ifdef TARGET_NR_ioperm
4400 case TARGET_NR_ioperm
:
4403 #ifdef TARGET_NR_socketcall
4404 case TARGET_NR_socketcall
:
4405 ret
= do_socketcall(arg1
, arg2
);
4408 #ifdef TARGET_NR_accept
4409 case TARGET_NR_accept
:
4410 ret
= do_accept(arg1
, arg2
, arg3
);
4413 #ifdef TARGET_NR_bind
4414 case TARGET_NR_bind
:
4415 ret
= do_bind(arg1
, arg2
, arg3
);
4418 #ifdef TARGET_NR_connect
4419 case TARGET_NR_connect
:
4420 ret
= do_connect(arg1
, arg2
, arg3
);
4423 #ifdef TARGET_NR_getpeername
4424 case TARGET_NR_getpeername
:
4425 ret
= do_getpeername(arg1
, arg2
, arg3
);
4428 #ifdef TARGET_NR_getsockname
4429 case TARGET_NR_getsockname
:
4430 ret
= do_getsockname(arg1
, arg2
, arg3
);
4433 #ifdef TARGET_NR_getsockopt
4434 case TARGET_NR_getsockopt
:
4435 ret
= do_getsockopt(arg1
, arg2
, arg3
, arg4
, arg5
);
4438 #ifdef TARGET_NR_listen
4439 case TARGET_NR_listen
:
4440 ret
= get_errno(listen(arg1
, arg2
));
4443 #ifdef TARGET_NR_recv
4444 case TARGET_NR_recv
:
4445 ret
= do_recvfrom(arg1
, arg2
, arg3
, arg4
, 0, 0);
4448 #ifdef TARGET_NR_recvfrom
4449 case TARGET_NR_recvfrom
:
4450 ret
= do_recvfrom(arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
4453 #ifdef TARGET_NR_recvmsg
4454 case TARGET_NR_recvmsg
:
4455 ret
= do_sendrecvmsg(arg1
, arg2
, arg3
, 0);
4458 #ifdef TARGET_NR_send
4459 case TARGET_NR_send
:
4460 ret
= do_sendto(arg1
, arg2
, arg3
, arg4
, 0, 0);
4463 #ifdef TARGET_NR_sendmsg
4464 case TARGET_NR_sendmsg
:
4465 ret
= do_sendrecvmsg(arg1
, arg2
, arg3
, 1);
4468 #ifdef TARGET_NR_sendto
4469 case TARGET_NR_sendto
:
4470 ret
= do_sendto(arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
4473 #ifdef TARGET_NR_shutdown
4474 case TARGET_NR_shutdown
:
4475 ret
= get_errno(shutdown(arg1
, arg2
));
4478 #ifdef TARGET_NR_socket
4479 case TARGET_NR_socket
:
4480 ret
= do_socket(arg1
, arg2
, arg3
);
4483 #ifdef TARGET_NR_socketpair
4484 case TARGET_NR_socketpair
:
4485 ret
= do_socketpair(arg1
, arg2
, arg3
, arg4
);
4488 #ifdef TARGET_NR_setsockopt
4489 case TARGET_NR_setsockopt
:
4490 ret
= do_setsockopt(arg1
, arg2
, arg3
, arg4
, (socklen_t
) arg5
);
4494 case TARGET_NR_syslog
:
4495 if (!(p
= lock_user_string(arg2
)))
4497 ret
= get_errno(sys_syslog((int)arg1
, p
, (int)arg3
));
4498 unlock_user(p
, arg2
, 0);
4501 case TARGET_NR_setitimer
:
4503 struct itimerval value
, ovalue
, *pvalue
;
4507 if (copy_from_user_timeval(&pvalue
->it_interval
, arg2
)
4508 || copy_from_user_timeval(&pvalue
->it_value
,
4509 arg2
+ sizeof(struct target_timeval
)))
4514 ret
= get_errno(setitimer(arg1
, pvalue
, &ovalue
));
4515 if (!is_error(ret
) && arg3
) {
4516 if (copy_to_user_timeval(arg3
,
4517 &ovalue
.it_interval
)
4518 || copy_to_user_timeval(arg3
+ sizeof(struct target_timeval
),
4524 case TARGET_NR_getitimer
:
4526 struct itimerval value
;
4528 ret
= get_errno(getitimer(arg1
, &value
));
4529 if (!is_error(ret
) && arg2
) {
4530 if (copy_to_user_timeval(arg2
,
4532 || copy_to_user_timeval(arg2
+ sizeof(struct target_timeval
),
4538 case TARGET_NR_stat
:
4539 if (!(p
= lock_user_string(arg1
)))
4541 ret
= get_errno(stat(path(p
), &st
));
4542 unlock_user(p
, arg1
, 0);
4544 case TARGET_NR_lstat
:
4545 if (!(p
= lock_user_string(arg1
)))
4547 ret
= get_errno(lstat(path(p
), &st
));
4548 unlock_user(p
, arg1
, 0);
4550 case TARGET_NR_fstat
:
4552 ret
= get_errno(fstat(arg1
, &st
));
4554 if (!is_error(ret
)) {
4555 struct target_stat
*target_st
;
4557 if (!lock_user_struct(VERIFY_WRITE
, target_st
, arg2
, 0))
4559 __put_user(st
.st_dev
, &target_st
->st_dev
);
4560 __put_user(st
.st_ino
, &target_st
->st_ino
);
4561 __put_user(st
.st_mode
, &target_st
->st_mode
);
4562 __put_user(st
.st_uid
, &target_st
->st_uid
);
4563 __put_user(st
.st_gid
, &target_st
->st_gid
);
4564 __put_user(st
.st_nlink
, &target_st
->st_nlink
);
4565 __put_user(st
.st_rdev
, &target_st
->st_rdev
);
4566 __put_user(st
.st_size
, &target_st
->st_size
);
4567 __put_user(st
.st_blksize
, &target_st
->st_blksize
);
4568 __put_user(st
.st_blocks
, &target_st
->st_blocks
);
4569 __put_user(st
.st_atime
, &target_st
->target_st_atime
);
4570 __put_user(st
.st_mtime
, &target_st
->target_st_mtime
);
4571 __put_user(st
.st_ctime
, &target_st
->target_st_ctime
);
4572 unlock_user_struct(target_st
, arg2
, 1);
4576 #ifdef TARGET_NR_olduname
4577 case TARGET_NR_olduname
:
4580 #ifdef TARGET_NR_iopl
4581 case TARGET_NR_iopl
:
4584 case TARGET_NR_vhangup
:
4585 ret
= get_errno(vhangup());
4587 #ifdef TARGET_NR_idle
4588 case TARGET_NR_idle
:
4591 #ifdef TARGET_NR_syscall
4592 case TARGET_NR_syscall
:
4593 ret
= do_syscall(cpu_env
,arg1
& 0xffff,arg2
,arg3
,arg4
,arg5
,arg6
,0);
4596 case TARGET_NR_wait4
:
4599 abi_long status_ptr
= arg2
;
4600 struct rusage rusage
, *rusage_ptr
;
4601 abi_ulong target_rusage
= arg4
;
4603 rusage_ptr
= &rusage
;
4606 ret
= get_errno(wait4(arg1
, &status
, arg3
, rusage_ptr
));
4607 if (!is_error(ret
)) {
4609 if (put_user_s32(status
, status_ptr
))
4613 host_to_target_rusage(target_rusage
, &rusage
);
4617 #ifdef TARGET_NR_swapoff
4618 case TARGET_NR_swapoff
:
4619 if (!(p
= lock_user_string(arg1
)))
4621 ret
= get_errno(swapoff(p
));
4622 unlock_user(p
, arg1
, 0);
4625 case TARGET_NR_sysinfo
:
4627 struct target_sysinfo
*target_value
;
4628 struct sysinfo value
;
4629 ret
= get_errno(sysinfo(&value
));
4630 if (!is_error(ret
) && arg1
)
4632 if (!lock_user_struct(VERIFY_WRITE
, target_value
, arg1
, 0))
4634 __put_user(value
.uptime
, &target_value
->uptime
);
4635 __put_user(value
.loads
[0], &target_value
->loads
[0]);
4636 __put_user(value
.loads
[1], &target_value
->loads
[1]);
4637 __put_user(value
.loads
[2], &target_value
->loads
[2]);
4638 __put_user(value
.totalram
, &target_value
->totalram
);
4639 __put_user(value
.freeram
, &target_value
->freeram
);
4640 __put_user(value
.sharedram
, &target_value
->sharedram
);
4641 __put_user(value
.bufferram
, &target_value
->bufferram
);
4642 __put_user(value
.totalswap
, &target_value
->totalswap
);
4643 __put_user(value
.freeswap
, &target_value
->freeswap
);
4644 __put_user(value
.procs
, &target_value
->procs
);
4645 __put_user(value
.totalhigh
, &target_value
->totalhigh
);
4646 __put_user(value
.freehigh
, &target_value
->freehigh
);
4647 __put_user(value
.mem_unit
, &target_value
->mem_unit
);
4648 unlock_user_struct(target_value
, arg1
, 1);
4652 #ifdef TARGET_NR_ipc
4654 ret
= do_ipc(arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
4657 case TARGET_NR_fsync
:
4658 ret
= get_errno(fsync(arg1
));
4660 case TARGET_NR_clone
:
4661 ret
= get_errno(do_fork(cpu_env
, arg1
, arg2
, arg3
, arg4
, arg5
));
4663 #ifdef __NR_exit_group
4664 /* new thread calls */
4665 case TARGET_NR_exit_group
:
4666 gdb_exit(cpu_env
, arg1
);
4667 ret
= get_errno(exit_group(arg1
));
4670 case TARGET_NR_setdomainname
:
4671 if (!(p
= lock_user_string(arg1
)))
4673 ret
= get_errno(setdomainname(p
, arg2
));
4674 unlock_user(p
, arg1
, 0);
4676 case TARGET_NR_uname
:
4677 /* no need to transcode because we use the linux syscall */
4679 struct new_utsname
* buf
;
4681 if (!lock_user_struct(VERIFY_WRITE
, buf
, arg1
, 0))
4683 ret
= get_errno(sys_uname(buf
));
4684 if (!is_error(ret
)) {
4685 /* Overrite the native machine name with whatever is being
4687 strcpy (buf
->machine
, UNAME_MACHINE
);
4688 /* Allow the user to override the reported release. */
4689 if (qemu_uname_release
&& *qemu_uname_release
)
4690 strcpy (buf
->release
, qemu_uname_release
);
4692 unlock_user_struct(buf
, arg1
, 1);
4696 case TARGET_NR_modify_ldt
:
4697 ret
= do_modify_ldt(cpu_env
, arg1
, arg2
, arg3
);
4699 #if !defined(TARGET_X86_64)
4700 case TARGET_NR_vm86old
:
4702 case TARGET_NR_vm86
:
4703 ret
= do_vm86(cpu_env
, arg1
, arg2
);
4707 case TARGET_NR_adjtimex
:
4709 #ifdef TARGET_NR_create_module
4710 case TARGET_NR_create_module
:
4712 case TARGET_NR_init_module
:
4713 case TARGET_NR_delete_module
:
4714 #ifdef TARGET_NR_get_kernel_syms
4715 case TARGET_NR_get_kernel_syms
:
4718 case TARGET_NR_quotactl
:
4720 case TARGET_NR_getpgid
:
4721 ret
= get_errno(getpgid(arg1
));
4723 case TARGET_NR_fchdir
:
4724 ret
= get_errno(fchdir(arg1
));
4726 #ifdef TARGET_NR_bdflush /* not on x86_64 */
4727 case TARGET_NR_bdflush
:
4730 #ifdef TARGET_NR_sysfs
4731 case TARGET_NR_sysfs
:
4734 case TARGET_NR_personality
:
4735 ret
= get_errno(personality(arg1
));
4737 #ifdef TARGET_NR_afs_syscall
4738 case TARGET_NR_afs_syscall
:
4741 #ifdef TARGET_NR__llseek /* Not on alpha */
4742 case TARGET_NR__llseek
:
4744 #if defined (__x86_64__)
4745 ret
= get_errno(lseek(arg1
, ((uint64_t )arg2
<< 32) | arg3
, arg5
));
4746 if (put_user_s64(ret
, arg4
))
4750 ret
= get_errno(_llseek(arg1
, arg2
, arg3
, &res
, arg5
));
4751 if (put_user_s64(res
, arg4
))
4757 case TARGET_NR_getdents
:
4758 #if TARGET_ABI_BITS != 32
4760 #elif TARGET_ABI_BITS == 32 && HOST_LONG_BITS == 64
4762 struct target_dirent
*target_dirp
;
4763 struct dirent
*dirp
;
4764 abi_long count
= arg3
;
4766 dirp
= malloc(count
);
4768 ret
= -TARGET_ENOMEM
;
4772 ret
= get_errno(sys_getdents(arg1
, dirp
, count
));
4773 if (!is_error(ret
)) {
4775 struct target_dirent
*tde
;
4777 int reclen
, treclen
;
4778 int count1
, tnamelen
;
4782 if (!(target_dirp
= lock_user(VERIFY_WRITE
, arg2
, count
, 0)))
4786 reclen
= de
->d_reclen
;
4787 treclen
= reclen
- (2 * (sizeof(long) - sizeof(abi_long
)));
4788 tde
->d_reclen
= tswap16(treclen
);
4789 tde
->d_ino
= tswapl(de
->d_ino
);
4790 tde
->d_off
= tswapl(de
->d_off
);
4791 tnamelen
= treclen
- (2 * sizeof(abi_long
) + 2);
4794 /* XXX: may not be correct */
4795 strncpy(tde
->d_name
, de
->d_name
, tnamelen
);
4796 de
= (struct dirent
*)((char *)de
+ reclen
);
4798 tde
= (struct target_dirent
*)((char *)tde
+ treclen
);
4802 unlock_user(target_dirp
, arg2
, ret
);
4808 struct dirent
*dirp
;
4809 abi_long count
= arg3
;
4811 if (!(dirp
= lock_user(VERIFY_WRITE
, arg2
, count
, 0)))
4813 ret
= get_errno(sys_getdents(arg1
, dirp
, count
));
4814 if (!is_error(ret
)) {
4820 reclen
= de
->d_reclen
;
4823 de
->d_reclen
= tswap16(reclen
);
4824 tswapls(&de
->d_ino
);
4825 tswapls(&de
->d_off
);
4826 de
= (struct dirent
*)((char *)de
+ reclen
);
4830 unlock_user(dirp
, arg2
, ret
);
4834 #if defined(TARGET_NR_getdents64) && defined(__NR_getdents64)
4835 case TARGET_NR_getdents64
:
4837 struct dirent64
*dirp
;
4838 abi_long count
= arg3
;
4839 if (!(dirp
= lock_user(VERIFY_WRITE
, arg2
, count
, 0)))
4841 ret
= get_errno(sys_getdents64(arg1
, dirp
, count
));
4842 if (!is_error(ret
)) {
4843 struct dirent64
*de
;
4848 reclen
= de
->d_reclen
;
4851 de
->d_reclen
= tswap16(reclen
);
4852 tswap64s((uint64_t *)&de
->d_ino
);
4853 tswap64s((uint64_t *)&de
->d_off
);
4854 de
= (struct dirent64
*)((char *)de
+ reclen
);
4858 unlock_user(dirp
, arg2
, ret
);
4861 #endif /* TARGET_NR_getdents64 */
4862 #ifdef TARGET_NR__newselect
4863 case TARGET_NR__newselect
:
4864 ret
= do_select(arg1
, arg2
, arg3
, arg4
, arg5
);
4867 #ifdef TARGET_NR_poll
4868 case TARGET_NR_poll
:
4870 struct target_pollfd
*target_pfd
;
4871 unsigned int nfds
= arg2
;
4876 target_pfd
= lock_user(VERIFY_WRITE
, arg1
, sizeof(struct target_pollfd
) * nfds
, 1);
4879 pfd
= alloca(sizeof(struct pollfd
) * nfds
);
4880 for(i
= 0; i
< nfds
; i
++) {
4881 pfd
[i
].fd
= tswap32(target_pfd
[i
].fd
);
4882 pfd
[i
].events
= tswap16(target_pfd
[i
].events
);
4884 ret
= get_errno(poll(pfd
, nfds
, timeout
));
4885 if (!is_error(ret
)) {
4886 for(i
= 0; i
< nfds
; i
++) {
4887 target_pfd
[i
].revents
= tswap16(pfd
[i
].revents
);
4889 ret
+= nfds
* (sizeof(struct target_pollfd
)
4890 - sizeof(struct pollfd
));
4892 unlock_user(target_pfd
, arg1
, ret
);
4896 case TARGET_NR_flock
:
4897 /* NOTE: the flock constant seems to be the same for every
4899 ret
= get_errno(flock(arg1
, arg2
));
4901 case TARGET_NR_readv
:
4906 vec
= alloca(count
* sizeof(struct iovec
));
4907 if (lock_iovec(VERIFY_WRITE
, vec
, arg2
, count
, 0) < 0)
4909 ret
= get_errno(readv(arg1
, vec
, count
));
4910 unlock_iovec(vec
, arg2
, count
, 1);
4913 case TARGET_NR_writev
:
4918 vec
= alloca(count
* sizeof(struct iovec
));
4919 if (lock_iovec(VERIFY_READ
, vec
, arg2
, count
, 1) < 0)
4921 ret
= get_errno(writev(arg1
, vec
, count
));
4922 unlock_iovec(vec
, arg2
, count
, 0);
4925 case TARGET_NR_getsid
:
4926 ret
= get_errno(getsid(arg1
));
4928 #if defined(TARGET_NR_fdatasync) /* Not on alpha (osf_datasync ?) */
4929 case TARGET_NR_fdatasync
:
4930 ret
= get_errno(fdatasync(arg1
));
4933 case TARGET_NR__sysctl
:
4934 /* We don't implement this, but ENOTDIR is always a safe
4936 ret
= -TARGET_ENOTDIR
;
4938 case TARGET_NR_sched_setparam
:
4940 struct sched_param
*target_schp
;
4941 struct sched_param schp
;
4943 if (!lock_user_struct(VERIFY_READ
, target_schp
, arg2
, 1))
4945 schp
.sched_priority
= tswap32(target_schp
->sched_priority
);
4946 unlock_user_struct(target_schp
, arg2
, 0);
4947 ret
= get_errno(sched_setparam(arg1
, &schp
));
4950 case TARGET_NR_sched_getparam
:
4952 struct sched_param
*target_schp
;
4953 struct sched_param schp
;
4954 ret
= get_errno(sched_getparam(arg1
, &schp
));
4955 if (!is_error(ret
)) {
4956 if (!lock_user_struct(VERIFY_WRITE
, target_schp
, arg2
, 0))
4958 target_schp
->sched_priority
= tswap32(schp
.sched_priority
);
4959 unlock_user_struct(target_schp
, arg2
, 1);
4963 case TARGET_NR_sched_setscheduler
:
4965 struct sched_param
*target_schp
;
4966 struct sched_param schp
;
4967 if (!lock_user_struct(VERIFY_READ
, target_schp
, arg3
, 1))
4969 schp
.sched_priority
= tswap32(target_schp
->sched_priority
);
4970 unlock_user_struct(target_schp
, arg3
, 0);
4971 ret
= get_errno(sched_setscheduler(arg1
, arg2
, &schp
));
4974 case TARGET_NR_sched_getscheduler
:
4975 ret
= get_errno(sched_getscheduler(arg1
));
4977 case TARGET_NR_sched_yield
:
4978 ret
= get_errno(sched_yield());
4980 case TARGET_NR_sched_get_priority_max
:
4981 ret
= get_errno(sched_get_priority_max(arg1
));
4983 case TARGET_NR_sched_get_priority_min
:
4984 ret
= get_errno(sched_get_priority_min(arg1
));
4986 case TARGET_NR_sched_rr_get_interval
:
4989 ret
= get_errno(sched_rr_get_interval(arg1
, &ts
));
4990 if (!is_error(ret
)) {
4991 host_to_target_timespec(arg2
, &ts
);
4995 case TARGET_NR_nanosleep
:
4997 struct timespec req
, rem
;
4998 target_to_host_timespec(&req
, arg1
);
4999 ret
= get_errno(nanosleep(&req
, &rem
));
5000 if (is_error(ret
) && arg2
) {
5001 host_to_target_timespec(arg2
, &rem
);
5005 #ifdef TARGET_NR_query_module
5006 case TARGET_NR_query_module
:
5009 #ifdef TARGET_NR_nfsservctl
5010 case TARGET_NR_nfsservctl
:
5013 case TARGET_NR_prctl
:
5016 case PR_GET_PDEATHSIG
:
5019 ret
= get_errno(prctl(arg1
, &deathsig
, arg3
, arg4
, arg5
));
5020 if (!is_error(ret
) && arg2
5021 && put_user_ual(deathsig
, arg2
))
5026 ret
= get_errno(prctl(arg1
, arg2
, arg3
, arg4
, arg5
));
5030 #ifdef TARGET_NR_arch_prctl
5031 case TARGET_NR_arch_prctl
:
5032 #if defined(TARGET_I386) && !defined(TARGET_ABI32)
5033 ret
= do_arch_prctl(cpu_env
, arg1
, arg2
);
5039 #ifdef TARGET_NR_pread
5040 case TARGET_NR_pread
:
5041 if (!(p
= lock_user(VERIFY_WRITE
, arg2
, arg3
, 0)))
5043 ret
= get_errno(pread(arg1
, p
, arg3
, arg4
));
5044 unlock_user(p
, arg2
, ret
);
5046 case TARGET_NR_pwrite
:
5047 if (!(p
= lock_user(VERIFY_READ
, arg2
, arg3
, 1)))
5049 ret
= get_errno(pwrite(arg1
, p
, arg3
, arg4
));
5050 unlock_user(p
, arg2
, 0);
5053 #ifdef TARGET_NR_pread64
5054 case TARGET_NR_pread64
:
5055 if (!(p
= lock_user(VERIFY_WRITE
, arg2
, arg3
, 0)))
5057 ret
= get_errno(pread64(arg1
, p
, arg3
, target_offset64(arg4
, arg5
)));
5058 unlock_user(p
, arg2
, ret
);
5060 case TARGET_NR_pwrite64
:
5061 if (!(p
= lock_user(VERIFY_READ
, arg2
, arg3
, 1)))
5063 ret
= get_errno(pwrite64(arg1
, p
, arg3
, target_offset64(arg4
, arg5
)));
5064 unlock_user(p
, arg2
, 0);
5067 case TARGET_NR_getcwd
:
5068 if (!(p
= lock_user(VERIFY_WRITE
, arg1
, arg2
, 0)))
5070 ret
= get_errno(sys_getcwd1(p
, arg2
));
5071 unlock_user(p
, arg1
, ret
);
5073 case TARGET_NR_capget
:
5075 case TARGET_NR_capset
:
5077 case TARGET_NR_sigaltstack
:
5078 #if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_MIPS) || \
5079 defined(TARGET_SPARC) || defined(TARGET_PPC) || defined(TARGET_ALPHA)
5080 ret
= do_sigaltstack(arg1
, arg2
, get_sp_from_cpustate((CPUState
*)cpu_env
));
5085 case TARGET_NR_sendfile
:
5087 #ifdef TARGET_NR_getpmsg
5088 case TARGET_NR_getpmsg
:
5091 #ifdef TARGET_NR_putpmsg
5092 case TARGET_NR_putpmsg
:
5095 #ifdef TARGET_NR_vfork
5096 case TARGET_NR_vfork
:
5097 ret
= get_errno(do_fork(cpu_env
, CLONE_VFORK
| CLONE_VM
| SIGCHLD
,
5101 #ifdef TARGET_NR_ugetrlimit
5102 case TARGET_NR_ugetrlimit
:
5105 ret
= get_errno(getrlimit(arg1
, &rlim
));
5106 if (!is_error(ret
)) {
5107 struct target_rlimit
*target_rlim
;
5108 if (!lock_user_struct(VERIFY_WRITE
, target_rlim
, arg2
, 0))
5110 target_rlim
->rlim_cur
= tswapl(rlim
.rlim_cur
);
5111 target_rlim
->rlim_max
= tswapl(rlim
.rlim_max
);
5112 unlock_user_struct(target_rlim
, arg2
, 1);
5117 #ifdef TARGET_NR_truncate64
5118 case TARGET_NR_truncate64
:
5119 if (!(p
= lock_user_string(arg1
)))
5121 ret
= target_truncate64(cpu_env
, p
, arg2
, arg3
, arg4
);
5122 unlock_user(p
, arg1
, 0);
5125 #ifdef TARGET_NR_ftruncate64
5126 case TARGET_NR_ftruncate64
:
5127 ret
= target_ftruncate64(cpu_env
, arg1
, arg2
, arg3
, arg4
);
5130 #ifdef TARGET_NR_stat64
5131 case TARGET_NR_stat64
:
5132 if (!(p
= lock_user_string(arg1
)))
5134 ret
= get_errno(stat(path(p
), &st
));
5135 unlock_user(p
, arg1
, 0);
5138 #ifdef TARGET_NR_lstat64
5139 case TARGET_NR_lstat64
:
5140 if (!(p
= lock_user_string(arg1
)))
5142 ret
= get_errno(lstat(path(p
), &st
));
5143 unlock_user(p
, arg1
, 0);
5146 #ifdef TARGET_NR_fstat64
5147 case TARGET_NR_fstat64
:
5149 ret
= get_errno(fstat(arg1
, &st
));
5151 if (!is_error(ret
)) {
5153 if (((CPUARMState
*)cpu_env
)->eabi
) {
5154 struct target_eabi_stat64
*target_st
;
5156 if (!lock_user_struct(VERIFY_WRITE
, target_st
, arg2
, 0))
5158 memset(target_st
, 0, sizeof(struct target_eabi_stat64
));
5159 __put_user(st
.st_dev
, &target_st
->st_dev
);
5160 __put_user(st
.st_ino
, &target_st
->st_ino
);
5161 #ifdef TARGET_STAT64_HAS_BROKEN_ST_INO
5162 __put_user(st
.st_ino
, &target_st
->__st_ino
);
5164 __put_user(st
.st_mode
, &target_st
->st_mode
);
5165 __put_user(st
.st_nlink
, &target_st
->st_nlink
);
5166 __put_user(st
.st_uid
, &target_st
->st_uid
);
5167 __put_user(st
.st_gid
, &target_st
->st_gid
);
5168 __put_user(st
.st_rdev
, &target_st
->st_rdev
);
5169 __put_user(st
.st_size
, &target_st
->st_size
);
5170 __put_user(st
.st_blksize
, &target_st
->st_blksize
);
5171 __put_user(st
.st_blocks
, &target_st
->st_blocks
);
5172 __put_user(st
.st_atime
, &target_st
->target_st_atime
);
5173 __put_user(st
.st_mtime
, &target_st
->target_st_mtime
);
5174 __put_user(st
.st_ctime
, &target_st
->target_st_ctime
);
5175 unlock_user_struct(target_st
, arg2
, 1);
5179 struct target_stat64
*target_st
;
5181 if (!lock_user_struct(VERIFY_WRITE
, target_st
, arg2
, 0))
5183 memset(target_st
, 0, sizeof(struct target_stat64
));
5184 __put_user(st
.st_dev
, &target_st
->st_dev
);
5185 __put_user(st
.st_ino
, &target_st
->st_ino
);
5186 #ifdef TARGET_STAT64_HAS_BROKEN_ST_INO
5187 __put_user(st
.st_ino
, &target_st
->__st_ino
);
5189 __put_user(st
.st_mode
, &target_st
->st_mode
);
5190 __put_user(st
.st_nlink
, &target_st
->st_nlink
);
5191 __put_user(st
.st_uid
, &target_st
->st_uid
);
5192 __put_user(st
.st_gid
, &target_st
->st_gid
);
5193 __put_user(st
.st_rdev
, &target_st
->st_rdev
);
5194 /* XXX: better use of kernel struct */
5195 __put_user(st
.st_size
, &target_st
->st_size
);
5196 __put_user(st
.st_blksize
, &target_st
->st_blksize
);
5197 __put_user(st
.st_blocks
, &target_st
->st_blocks
);
5198 __put_user(st
.st_atime
, &target_st
->target_st_atime
);
5199 __put_user(st
.st_mtime
, &target_st
->target_st_mtime
);
5200 __put_user(st
.st_ctime
, &target_st
->target_st_ctime
);
5201 unlock_user_struct(target_st
, arg2
, 1);
5208 case TARGET_NR_lchown
:
5209 if (!(p
= lock_user_string(arg1
)))
5211 ret
= get_errno(lchown(p
, low2highuid(arg2
), low2highgid(arg3
)));
5212 unlock_user(p
, arg1
, 0);
5214 case TARGET_NR_getuid
:
5215 ret
= get_errno(high2lowuid(getuid()));
5217 case TARGET_NR_getgid
:
5218 ret
= get_errno(high2lowgid(getgid()));
5220 case TARGET_NR_geteuid
:
5221 ret
= get_errno(high2lowuid(geteuid()));
5223 case TARGET_NR_getegid
:
5224 ret
= get_errno(high2lowgid(getegid()));
5226 case TARGET_NR_setreuid
:
5227 ret
= get_errno(setreuid(low2highuid(arg1
), low2highuid(arg2
)));
5229 case TARGET_NR_setregid
:
5230 ret
= get_errno(setregid(low2highgid(arg1
), low2highgid(arg2
)));
5232 case TARGET_NR_getgroups
:
5234 int gidsetsize
= arg1
;
5235 uint16_t *target_grouplist
;
5239 grouplist
= alloca(gidsetsize
* sizeof(gid_t
));
5240 ret
= get_errno(getgroups(gidsetsize
, grouplist
));
5241 if (!is_error(ret
)) {
5242 target_grouplist
= lock_user(VERIFY_WRITE
, arg2
, gidsetsize
* 2, 0);
5243 if (!target_grouplist
)
5245 for(i
= 0;i
< gidsetsize
; i
++)
5246 target_grouplist
[i
] = tswap16(grouplist
[i
]);
5247 unlock_user(target_grouplist
, arg2
, gidsetsize
* 2);
5251 case TARGET_NR_setgroups
:
5253 int gidsetsize
= arg1
;
5254 uint16_t *target_grouplist
;
5258 grouplist
= alloca(gidsetsize
* sizeof(gid_t
));
5259 target_grouplist
= lock_user(VERIFY_READ
, arg2
, gidsetsize
* 2, 1);
5260 if (!target_grouplist
) {
5261 ret
= -TARGET_EFAULT
;
5264 for(i
= 0;i
< gidsetsize
; i
++)
5265 grouplist
[i
] = tswap16(target_grouplist
[i
]);
5266 unlock_user(target_grouplist
, arg2
, 0);
5267 ret
= get_errno(setgroups(gidsetsize
, grouplist
));
5270 case TARGET_NR_fchown
:
5271 ret
= get_errno(fchown(arg1
, low2highuid(arg2
), low2highgid(arg3
)));
5273 #if defined(TARGET_NR_fchownat) && defined(__NR_fchownat)
5274 case TARGET_NR_fchownat
:
5275 if (!(p
= lock_user_string(arg2
)))
5277 ret
= get_errno(sys_fchownat(arg1
, p
, low2highuid(arg3
), low2highgid(arg4
), arg5
));
5278 unlock_user(p
, arg2
, 0);
5281 #ifdef TARGET_NR_setresuid
5282 case TARGET_NR_setresuid
:
5283 ret
= get_errno(setresuid(low2highuid(arg1
),
5285 low2highuid(arg3
)));
5288 #ifdef TARGET_NR_getresuid
5289 case TARGET_NR_getresuid
:
5291 uid_t ruid
, euid
, suid
;
5292 ret
= get_errno(getresuid(&ruid
, &euid
, &suid
));
5293 if (!is_error(ret
)) {
5294 if (put_user_u16(high2lowuid(ruid
), arg1
)
5295 || put_user_u16(high2lowuid(euid
), arg2
)
5296 || put_user_u16(high2lowuid(suid
), arg3
))
5302 #ifdef TARGET_NR_getresgid
5303 case TARGET_NR_setresgid
:
5304 ret
= get_errno(setresgid(low2highgid(arg1
),
5306 low2highgid(arg3
)));
5309 #ifdef TARGET_NR_getresgid
5310 case TARGET_NR_getresgid
:
5312 gid_t rgid
, egid
, sgid
;
5313 ret
= get_errno(getresgid(&rgid
, &egid
, &sgid
));
5314 if (!is_error(ret
)) {
5315 if (put_user_u16(high2lowgid(rgid
), arg1
)
5316 || put_user_u16(high2lowgid(egid
), arg2
)
5317 || put_user_u16(high2lowgid(sgid
), arg3
))
5323 case TARGET_NR_chown
:
5324 if (!(p
= lock_user_string(arg1
)))
5326 ret
= get_errno(chown(p
, low2highuid(arg2
), low2highgid(arg3
)));
5327 unlock_user(p
, arg1
, 0);
5329 case TARGET_NR_setuid
:
5330 ret
= get_errno(setuid(low2highuid(arg1
)));
5332 case TARGET_NR_setgid
:
5333 ret
= get_errno(setgid(low2highgid(arg1
)));
5335 case TARGET_NR_setfsuid
:
5336 ret
= get_errno(setfsuid(arg1
));
5338 case TARGET_NR_setfsgid
:
5339 ret
= get_errno(setfsgid(arg1
));
5341 #endif /* USE_UID16 */
5343 #ifdef TARGET_NR_lchown32
5344 case TARGET_NR_lchown32
:
5345 if (!(p
= lock_user_string(arg1
)))
5347 ret
= get_errno(lchown(p
, arg2
, arg3
));
5348 unlock_user(p
, arg1
, 0);
5351 #ifdef TARGET_NR_getuid32
5352 case TARGET_NR_getuid32
:
5353 ret
= get_errno(getuid());
5356 #ifdef TARGET_NR_getgid32
5357 case TARGET_NR_getgid32
:
5358 ret
= get_errno(getgid());
5361 #ifdef TARGET_NR_geteuid32
5362 case TARGET_NR_geteuid32
:
5363 ret
= get_errno(geteuid());
5366 #ifdef TARGET_NR_getegid32
5367 case TARGET_NR_getegid32
:
5368 ret
= get_errno(getegid());
5371 #ifdef TARGET_NR_setreuid32
5372 case TARGET_NR_setreuid32
:
5373 ret
= get_errno(setreuid(arg1
, arg2
));
5376 #ifdef TARGET_NR_setregid32
5377 case TARGET_NR_setregid32
:
5378 ret
= get_errno(setregid(arg1
, arg2
));
5381 #ifdef TARGET_NR_getgroups32
5382 case TARGET_NR_getgroups32
:
5384 int gidsetsize
= arg1
;
5385 uint32_t *target_grouplist
;
5389 grouplist
= alloca(gidsetsize
* sizeof(gid_t
));
5390 ret
= get_errno(getgroups(gidsetsize
, grouplist
));
5391 if (!is_error(ret
)) {
5392 target_grouplist
= lock_user(VERIFY_WRITE
, arg2
, gidsetsize
* 4, 0);
5393 if (!target_grouplist
) {
5394 ret
= -TARGET_EFAULT
;
5397 for(i
= 0;i
< gidsetsize
; i
++)
5398 target_grouplist
[i
] = tswap32(grouplist
[i
]);
5399 unlock_user(target_grouplist
, arg2
, gidsetsize
* 4);
5404 #ifdef TARGET_NR_setgroups32
5405 case TARGET_NR_setgroups32
:
5407 int gidsetsize
= arg1
;
5408 uint32_t *target_grouplist
;
5412 grouplist
= alloca(gidsetsize
* sizeof(gid_t
));
5413 target_grouplist
= lock_user(VERIFY_READ
, arg2
, gidsetsize
* 4, 1);
5414 if (!target_grouplist
) {
5415 ret
= -TARGET_EFAULT
;
5418 for(i
= 0;i
< gidsetsize
; i
++)
5419 grouplist
[i
] = tswap32(target_grouplist
[i
]);
5420 unlock_user(target_grouplist
, arg2
, 0);
5421 ret
= get_errno(setgroups(gidsetsize
, grouplist
));
5425 #ifdef TARGET_NR_fchown32
5426 case TARGET_NR_fchown32
:
5427 ret
= get_errno(fchown(arg1
, arg2
, arg3
));
5430 #ifdef TARGET_NR_setresuid32
5431 case TARGET_NR_setresuid32
:
5432 ret
= get_errno(setresuid(arg1
, arg2
, arg3
));
5435 #ifdef TARGET_NR_getresuid32
5436 case TARGET_NR_getresuid32
:
5438 uid_t ruid
, euid
, suid
;
5439 ret
= get_errno(getresuid(&ruid
, &euid
, &suid
));
5440 if (!is_error(ret
)) {
5441 if (put_user_u32(ruid
, arg1
)
5442 || put_user_u32(euid
, arg2
)
5443 || put_user_u32(suid
, arg3
))
5449 #ifdef TARGET_NR_setresgid32
5450 case TARGET_NR_setresgid32
:
5451 ret
= get_errno(setresgid(arg1
, arg2
, arg3
));
5454 #ifdef TARGET_NR_getresgid32
5455 case TARGET_NR_getresgid32
:
5457 gid_t rgid
, egid
, sgid
;
5458 ret
= get_errno(getresgid(&rgid
, &egid
, &sgid
));
5459 if (!is_error(ret
)) {
5460 if (put_user_u32(rgid
, arg1
)
5461 || put_user_u32(egid
, arg2
)
5462 || put_user_u32(sgid
, arg3
))
5468 #ifdef TARGET_NR_chown32
5469 case TARGET_NR_chown32
:
5470 if (!(p
= lock_user_string(arg1
)))
5472 ret
= get_errno(chown(p
, arg2
, arg3
));
5473 unlock_user(p
, arg1
, 0);
5476 #ifdef TARGET_NR_setuid32
5477 case TARGET_NR_setuid32
:
5478 ret
= get_errno(setuid(arg1
));
5481 #ifdef TARGET_NR_setgid32
5482 case TARGET_NR_setgid32
:
5483 ret
= get_errno(setgid(arg1
));
5486 #ifdef TARGET_NR_setfsuid32
5487 case TARGET_NR_setfsuid32
:
5488 ret
= get_errno(setfsuid(arg1
));
5491 #ifdef TARGET_NR_setfsgid32
5492 case TARGET_NR_setfsgid32
:
5493 ret
= get_errno(setfsgid(arg1
));
5497 case TARGET_NR_pivot_root
:
5499 #ifdef TARGET_NR_mincore
5500 case TARGET_NR_mincore
:
5503 #ifdef TARGET_NR_madvise
5504 case TARGET_NR_madvise
:
5505 /* A straight passthrough may not be safe because qemu sometimes
5506 turns private flie-backed mappings into anonymous mappings.
5507 This will break MADV_DONTNEED.
5508 This is a hint, so ignoring and returning success is ok. */
5512 #if TARGET_ABI_BITS == 32
5513 case TARGET_NR_fcntl64
:
5517 struct target_flock64
*target_fl
;
5519 struct target_eabi_flock64
*target_efl
;
5523 case TARGET_F_GETLK64
:
5526 case TARGET_F_SETLK64
:
5529 case TARGET_F_SETLKW64
:
5538 case TARGET_F_GETLK64
:
5540 if (((CPUARMState
*)cpu_env
)->eabi
) {
5541 if (!lock_user_struct(VERIFY_READ
, target_efl
, arg3
, 1))
5543 fl
.l_type
= tswap16(target_efl
->l_type
);
5544 fl
.l_whence
= tswap16(target_efl
->l_whence
);
5545 fl
.l_start
= tswap64(target_efl
->l_start
);
5546 fl
.l_len
= tswap64(target_efl
->l_len
);
5547 fl
.l_pid
= tswapl(target_efl
->l_pid
);
5548 unlock_user_struct(target_efl
, arg3
, 0);
5552 if (!lock_user_struct(VERIFY_READ
, target_fl
, arg3
, 1))
5554 fl
.l_type
= tswap16(target_fl
->l_type
);
5555 fl
.l_whence
= tswap16(target_fl
->l_whence
);
5556 fl
.l_start
= tswap64(target_fl
->l_start
);
5557 fl
.l_len
= tswap64(target_fl
->l_len
);
5558 fl
.l_pid
= tswapl(target_fl
->l_pid
);
5559 unlock_user_struct(target_fl
, arg3
, 0);
5561 ret
= get_errno(fcntl(arg1
, cmd
, &fl
));
5564 if (((CPUARMState
*)cpu_env
)->eabi
) {
5565 if (!lock_user_struct(VERIFY_WRITE
, target_efl
, arg3
, 0))
5567 target_efl
->l_type
= tswap16(fl
.l_type
);
5568 target_efl
->l_whence
= tswap16(fl
.l_whence
);
5569 target_efl
->l_start
= tswap64(fl
.l_start
);
5570 target_efl
->l_len
= tswap64(fl
.l_len
);
5571 target_efl
->l_pid
= tswapl(fl
.l_pid
);
5572 unlock_user_struct(target_efl
, arg3
, 1);
5576 if (!lock_user_struct(VERIFY_WRITE
, target_fl
, arg3
, 0))
5578 target_fl
->l_type
= tswap16(fl
.l_type
);
5579 target_fl
->l_whence
= tswap16(fl
.l_whence
);
5580 target_fl
->l_start
= tswap64(fl
.l_start
);
5581 target_fl
->l_len
= tswap64(fl
.l_len
);
5582 target_fl
->l_pid
= tswapl(fl
.l_pid
);
5583 unlock_user_struct(target_fl
, arg3
, 1);
5588 case TARGET_F_SETLK64
:
5589 case TARGET_F_SETLKW64
:
5591 if (((CPUARMState
*)cpu_env
)->eabi
) {
5592 if (!lock_user_struct(VERIFY_READ
, target_efl
, arg3
, 1))
5594 fl
.l_type
= tswap16(target_efl
->l_type
);
5595 fl
.l_whence
= tswap16(target_efl
->l_whence
);
5596 fl
.l_start
= tswap64(target_efl
->l_start
);
5597 fl
.l_len
= tswap64(target_efl
->l_len
);
5598 fl
.l_pid
= tswapl(target_efl
->l_pid
);
5599 unlock_user_struct(target_efl
, arg3
, 0);
5603 if (!lock_user_struct(VERIFY_READ
, target_fl
, arg3
, 1))
5605 fl
.l_type
= tswap16(target_fl
->l_type
);
5606 fl
.l_whence
= tswap16(target_fl
->l_whence
);
5607 fl
.l_start
= tswap64(target_fl
->l_start
);
5608 fl
.l_len
= tswap64(target_fl
->l_len
);
5609 fl
.l_pid
= tswapl(target_fl
->l_pid
);
5610 unlock_user_struct(target_fl
, arg3
, 0);
5612 ret
= get_errno(fcntl(arg1
, cmd
, &fl
));
5615 ret
= do_fcntl(arg1
, cmd
, arg3
);
5621 #ifdef TARGET_NR_cacheflush
5622 case TARGET_NR_cacheflush
:
5623 /* self-modifying code is handled automatically, so nothing needed */
5627 #ifdef TARGET_NR_security
5628 case TARGET_NR_security
:
5631 #ifdef TARGET_NR_getpagesize
5632 case TARGET_NR_getpagesize
:
5633 ret
= TARGET_PAGE_SIZE
;
5636 case TARGET_NR_gettid
:
5637 ret
= get_errno(gettid());
5639 #ifdef TARGET_NR_readahead
5640 case TARGET_NR_readahead
:
5643 #ifdef TARGET_NR_setxattr
5644 case TARGET_NR_setxattr
:
5645 case TARGET_NR_lsetxattr
:
5646 case TARGET_NR_fsetxattr
:
5647 case TARGET_NR_getxattr
:
5648 case TARGET_NR_lgetxattr
:
5649 case TARGET_NR_fgetxattr
:
5650 case TARGET_NR_listxattr
:
5651 case TARGET_NR_llistxattr
:
5652 case TARGET_NR_flistxattr
:
5653 case TARGET_NR_removexattr
:
5654 case TARGET_NR_lremovexattr
:
5655 case TARGET_NR_fremovexattr
:
5656 goto unimplemented_nowarn
;
5658 #ifdef TARGET_NR_set_thread_area
5659 case TARGET_NR_set_thread_area
:
5660 #if defined(TARGET_MIPS)
5661 ((CPUMIPSState
*) cpu_env
)->tls_value
= arg1
;
5664 #elif defined(TARGET_I386) && defined(TARGET_ABI32)
5665 ret
= do_set_thread_area(cpu_env
, arg1
);
5668 goto unimplemented_nowarn
;
5671 #ifdef TARGET_NR_get_thread_area
5672 case TARGET_NR_get_thread_area
:
5673 #if defined(TARGET_I386) && defined(TARGET_ABI32)
5674 ret
= do_get_thread_area(cpu_env
, arg1
);
5676 goto unimplemented_nowarn
;
5679 #ifdef TARGET_NR_getdomainname
5680 case TARGET_NR_getdomainname
:
5681 goto unimplemented_nowarn
;
5684 #ifdef TARGET_NR_clock_gettime
5685 case TARGET_NR_clock_gettime
:
5688 ret
= get_errno(clock_gettime(arg1
, &ts
));
5689 if (!is_error(ret
)) {
5690 host_to_target_timespec(arg2
, &ts
);
5695 #ifdef TARGET_NR_clock_getres
5696 case TARGET_NR_clock_getres
:
5699 ret
= get_errno(clock_getres(arg1
, &ts
));
5700 if (!is_error(ret
)) {
5701 host_to_target_timespec(arg2
, &ts
);
5706 #ifdef TARGET_NR_clock_nanosleep
5707 case TARGET_NR_clock_nanosleep
:
5710 target_to_host_timespec(&ts
, arg3
);
5711 ret
= get_errno(clock_nanosleep(arg1
, arg2
, &ts
, arg4
? &ts
: NULL
));
5713 host_to_target_timespec(arg4
, &ts
);
5718 #if defined(TARGET_NR_set_tid_address) && defined(__NR_set_tid_address)
5719 case TARGET_NR_set_tid_address
:
5720 ret
= get_errno(set_tid_address((int *)g2h(arg1
)));
5724 #if defined(TARGET_NR_tkill) && defined(__NR_tkill)
5725 case TARGET_NR_tkill
:
5726 ret
= get_errno(sys_tkill((int)arg1
, target_to_host_signal(arg2
)));
5730 #if defined(TARGET_NR_tgkill) && defined(__NR_tgkill)
5731 case TARGET_NR_tgkill
:
5732 ret
= get_errno(sys_tgkill((int)arg1
, (int)arg2
,
5733 target_to_host_signal(arg3
)));
5737 #ifdef TARGET_NR_set_robust_list
5738 case TARGET_NR_set_robust_list
:
5739 goto unimplemented_nowarn
;
5742 #if defined(TARGET_NR_utimensat) && defined(__NR_utimensat)
5743 case TARGET_NR_utimensat
:
5745 struct timespec ts
[2];
5746 target_to_host_timespec(ts
, arg3
);
5747 target_to_host_timespec(ts
+1, arg3
+sizeof(struct target_timespec
));
5749 ret
= get_errno(sys_utimensat(arg1
, NULL
, ts
, arg4
));
5751 if (!(p
= lock_user_string(arg2
))) {
5752 ret
= -TARGET_EFAULT
;
5755 ret
= get_errno(sys_utimensat(arg1
, path(p
), ts
, arg4
));
5756 unlock_user(p
, arg2
, 0);
5761 #if defined(USE_NPTL)
5762 case TARGET_NR_futex
:
5763 ret
= do_futex(arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
5769 gemu_log("qemu: Unsupported syscall: %d\n", num
);
5770 #if defined(TARGET_NR_setxattr) || defined(TARGET_NR_get_thread_area) || defined(TARGET_NR_getdomainname) || defined(TARGET_NR_set_robust_list)
5771 unimplemented_nowarn
:
5773 ret
= -TARGET_ENOSYS
;
5778 gemu_log(" = %ld\n", ret
);
5781 print_syscall_ret(num
, ret
);
5784 ret
= -TARGET_EFAULT
;