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.
30 #include <sys/types.h>
36 #include <sys/mount.h>
37 #include <sys/prctl.h>
38 #include <sys/resource.h>
43 #include <sys/socket.h>
46 #include <sys/times.h>
49 #include <sys/statfs.h>
51 #include <sys/sysinfo.h>
52 //#include <sys/user.h>
53 #include <netinet/ip.h>
54 #include <netinet/tcp.h>
56 #define termios host_termios
57 #define winsize host_winsize
58 #define termio host_termio
59 #define sgttyb host_sgttyb /* same as target */
60 #define tchars host_tchars /* same as target */
61 #define ltchars host_ltchars /* same as target */
63 #include <linux/termios.h>
64 #include <linux/unistd.h>
65 #include <linux/utsname.h>
66 #include <linux/cdrom.h>
67 #include <linux/hdreg.h>
68 #include <linux/soundcard.h>
69 #include <linux/dirent.h>
76 #if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_SPARC) \
77 || defined(TARGET_M68K) || defined(TARGET_SH4) || defined(TARGET_CRIS)
78 /* 16 bit uid wrappers emulation */
82 //#include <linux/msdos_fs.h>
83 #define VFAT_IOCTL_READDIR_BOTH _IOR('r', 1, struct dirent [2])
84 #define VFAT_IOCTL_READDIR_SHORT _IOR('r', 2, struct dirent [2])
95 #define _syscall0(type,name) \
98 return syscall(__NR_##name); \
101 #define _syscall1(type,name,type1,arg1) \
102 type name (type1 arg1) \
104 return syscall(__NR_##name, arg1); \
107 #define _syscall2(type,name,type1,arg1,type2,arg2) \
108 type name (type1 arg1,type2 arg2) \
110 return syscall(__NR_##name, arg1, arg2); \
113 #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
114 type name (type1 arg1,type2 arg2,type3 arg3) \
116 return syscall(__NR_##name, arg1, arg2, arg3); \
119 #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
120 type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4) \
122 return syscall(__NR_##name, arg1, arg2, arg3, arg4); \
125 #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
127 type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \
129 return syscall(__NR_##name, arg1, arg2, arg3, arg4, arg5); \
133 #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
134 type5,arg5,type6,arg6) \
135 type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5,type6 arg6) \
137 return syscall(__NR_##name, arg1, arg2, arg3, arg4, arg5, arg6); \
141 #define __NR_sys_uname __NR_uname
142 #define __NR_sys_faccessat __NR_faccessat
143 #define __NR_sys_fchmodat __NR_fchmodat
144 #define __NR_sys_fchownat __NR_fchownat
145 #define __NR_sys_getcwd1 __NR_getcwd
146 #define __NR_sys_getdents __NR_getdents
147 #define __NR_sys_getdents64 __NR_getdents64
148 #define __NR_sys_getpriority __NR_getpriority
149 #define __NR_sys_linkat __NR_linkat
150 #define __NR_sys_mkdirat __NR_mkdirat
151 #define __NR_sys_mknodat __NR_mknodat
152 #define __NR_sys_openat __NR_openat
153 #define __NR_sys_readlinkat __NR_readlinkat
154 #define __NR_sys_renameat __NR_renameat
155 #define __NR_sys_rt_sigqueueinfo __NR_rt_sigqueueinfo
156 #define __NR_sys_symlinkat __NR_symlinkat
157 #define __NR_sys_syslog __NR_syslog
158 #define __NR_sys_tgkill __NR_tgkill
159 #define __NR_sys_tkill __NR_tkill
160 #define __NR_sys_unlinkat __NR_unlinkat
161 #define __NR_sys_utimensat __NR_utimensat
163 #if defined(__alpha__) || defined (__ia64__) || defined(__x86_64__)
164 #define __NR__llseek __NR_lseek
168 _syscall0(int, gettid
)
170 /* This is a replacement for the host gettid() and must return a host
172 static int gettid(void) {
176 _syscall1(int,sys_uname
,struct new_utsname
*,buf
)
177 #if defined(TARGET_NR_faccessat) && defined(__NR_faccessat)
178 _syscall4(int,sys_faccessat
,int,dirfd
,const char *,pathname
,int,mode
,int,flags
)
180 #if defined(TARGET_NR_fchmodat) && defined(__NR_fchmodat)
181 _syscall4(int,sys_fchmodat
,int,dirfd
,const char *,pathname
,
182 mode_t
,mode
,int,flags
)
184 #if defined(TARGET_NR_fchownat) && defined(__NR_fchownat)
185 _syscall5(int,sys_fchownat
,int,dirfd
,const char *,pathname
,
186 uid_t
,owner
,gid_t
,group
,int,flags
)
188 _syscall2(int,sys_getcwd1
,char *,buf
,size_t,size
)
189 _syscall3(int, sys_getdents
, uint
, fd
, struct dirent
*, dirp
, uint
, count
);
190 #if defined(TARGET_NR_getdents64) && defined(__NR_getdents64)
191 _syscall3(int, sys_getdents64
, uint
, fd
, struct dirent64
*, dirp
, uint
, count
);
193 _syscall2(int, sys_getpriority
, int, which
, int, who
);
194 _syscall5(int, _llseek
, uint
, fd
, ulong
, hi
, ulong
, lo
,
195 loff_t
*, res
, uint
, wh
);
196 #if defined(TARGET_NR_linkat) && defined(__NR_linkat)
197 _syscall5(int,sys_linkat
,int,olddirfd
,const char *,oldpath
,
198 int,newdirfd
,const char *,newpath
,int,flags
)
200 #if defined(TARGET_NR_mkdirat) && defined(__NR_mkdirat)
201 _syscall3(int,sys_mkdirat
,int,dirfd
,const char *,pathname
,mode_t
,mode
)
203 #if defined(TARGET_NR_mknodat) && defined(__NR_mknodat)
204 _syscall4(int,sys_mknodat
,int,dirfd
,const char *,pathname
,
205 mode_t
,mode
,dev_t
,dev
)
207 #if defined(TARGET_NR_openat) && defined(__NR_openat)
208 _syscall4(int,sys_openat
,int,dirfd
,const char *,pathname
,int,flags
,mode_t
,mode
)
210 #if defined(TARGET_NR_readlinkat) && defined(__NR_readlinkat)
211 _syscall4(int,sys_readlinkat
,int,dirfd
,const char *,pathname
,
212 char *,buf
,size_t,bufsize
)
214 #if defined(TARGET_NR_renameat) && defined(__NR_renameat)
215 _syscall4(int,sys_renameat
,int,olddirfd
,const char *,oldpath
,
216 int,newdirfd
,const char *,newpath
)
218 _syscall3(int,sys_rt_sigqueueinfo
,int,pid
,int,sig
,siginfo_t
*,uinfo
)
219 #if defined(TARGET_NR_symlinkat) && defined(__NR_symlinkat)
220 _syscall3(int,sys_symlinkat
,const char *,oldpath
,
221 int,newdirfd
,const char *,newpath
)
223 _syscall3(int,sys_syslog
,int,type
,char*,bufp
,int,len
)
224 #if defined(TARGET_NR_tgkill) && defined(__NR_tgkill)
225 _syscall3(int,sys_tgkill
,int,tgid
,int,pid
,int,sig
)
227 #if defined(TARGET_NR_tkill) && defined(__NR_tkill)
228 _syscall2(int,sys_tkill
,int,tid
,int,sig
)
230 #ifdef __NR_exit_group
231 _syscall1(int,exit_group
,int,error_code
)
233 #if defined(TARGET_NR_set_tid_address) && defined(__NR_set_tid_address)
234 _syscall1(int,set_tid_address
,int *,tidptr
)
236 #if defined(TARGET_NR_unlinkat) && defined(__NR_unlinkat)
237 _syscall3(int,sys_unlinkat
,int,dirfd
,const char *,pathname
,int,flags
)
239 #if defined(TARGET_NR_utimensat) && defined(__NR_utimensat)
240 _syscall4(int,sys_utimensat
,int,dirfd
,const char *,pathname
,
241 const struct timespec
*,tsp
,int,flags
)
244 extern int personality(int);
245 extern int flock(int, int);
246 extern int setfsuid(int);
247 extern int setfsgid(int);
248 extern int setresuid(uid_t
, uid_t
, uid_t
);
249 extern int getresuid(uid_t
*, uid_t
*, uid_t
*);
250 extern int setresgid(gid_t
, gid_t
, gid_t
);
251 extern int getresgid(gid_t
*, gid_t
*, gid_t
*);
252 extern int setgroups(int, gid_t
*);
255 * This list is the union of errno values overridden in asm-<arch>/errno.h
256 * minus the errnos that are not actually generic to all archs.
258 static uint16_t host_to_target_errno_table
[1200] = {
259 [EIDRM
] = TARGET_EIDRM
,
260 [ECHRNG
] = TARGET_ECHRNG
,
261 [EL2NSYNC
] = TARGET_EL2NSYNC
,
262 [EL3HLT
] = TARGET_EL3HLT
,
263 [EL3RST
] = TARGET_EL3RST
,
264 [ELNRNG
] = TARGET_ELNRNG
,
265 [EUNATCH
] = TARGET_EUNATCH
,
266 [ENOCSI
] = TARGET_ENOCSI
,
267 [EL2HLT
] = TARGET_EL2HLT
,
268 [EDEADLK
] = TARGET_EDEADLK
,
269 [ENOLCK
] = TARGET_ENOLCK
,
270 [EBADE
] = TARGET_EBADE
,
271 [EBADR
] = TARGET_EBADR
,
272 [EXFULL
] = TARGET_EXFULL
,
273 [ENOANO
] = TARGET_ENOANO
,
274 [EBADRQC
] = TARGET_EBADRQC
,
275 [EBADSLT
] = TARGET_EBADSLT
,
276 [EBFONT
] = TARGET_EBFONT
,
277 [ENOSTR
] = TARGET_ENOSTR
,
278 [ENODATA
] = TARGET_ENODATA
,
279 [ETIME
] = TARGET_ETIME
,
280 [ENOSR
] = TARGET_ENOSR
,
281 [ENONET
] = TARGET_ENONET
,
282 [ENOPKG
] = TARGET_ENOPKG
,
283 [EREMOTE
] = TARGET_EREMOTE
,
284 [ENOLINK
] = TARGET_ENOLINK
,
285 [EADV
] = TARGET_EADV
,
286 [ESRMNT
] = TARGET_ESRMNT
,
287 [ECOMM
] = TARGET_ECOMM
,
288 [EPROTO
] = TARGET_EPROTO
,
289 [EDOTDOT
] = TARGET_EDOTDOT
,
290 [EMULTIHOP
] = TARGET_EMULTIHOP
,
291 [EBADMSG
] = TARGET_EBADMSG
,
292 [ENAMETOOLONG
] = TARGET_ENAMETOOLONG
,
293 [EOVERFLOW
] = TARGET_EOVERFLOW
,
294 [ENOTUNIQ
] = TARGET_ENOTUNIQ
,
295 [EBADFD
] = TARGET_EBADFD
,
296 [EREMCHG
] = TARGET_EREMCHG
,
297 [ELIBACC
] = TARGET_ELIBACC
,
298 [ELIBBAD
] = TARGET_ELIBBAD
,
299 [ELIBSCN
] = TARGET_ELIBSCN
,
300 [ELIBMAX
] = TARGET_ELIBMAX
,
301 [ELIBEXEC
] = TARGET_ELIBEXEC
,
302 [EILSEQ
] = TARGET_EILSEQ
,
303 [ENOSYS
] = TARGET_ENOSYS
,
304 [ELOOP
] = TARGET_ELOOP
,
305 [ERESTART
] = TARGET_ERESTART
,
306 [ESTRPIPE
] = TARGET_ESTRPIPE
,
307 [ENOTEMPTY
] = TARGET_ENOTEMPTY
,
308 [EUSERS
] = TARGET_EUSERS
,
309 [ENOTSOCK
] = TARGET_ENOTSOCK
,
310 [EDESTADDRREQ
] = TARGET_EDESTADDRREQ
,
311 [EMSGSIZE
] = TARGET_EMSGSIZE
,
312 [EPROTOTYPE
] = TARGET_EPROTOTYPE
,
313 [ENOPROTOOPT
] = TARGET_ENOPROTOOPT
,
314 [EPROTONOSUPPORT
] = TARGET_EPROTONOSUPPORT
,
315 [ESOCKTNOSUPPORT
] = TARGET_ESOCKTNOSUPPORT
,
316 [EOPNOTSUPP
] = TARGET_EOPNOTSUPP
,
317 [EPFNOSUPPORT
] = TARGET_EPFNOSUPPORT
,
318 [EAFNOSUPPORT
] = TARGET_EAFNOSUPPORT
,
319 [EADDRINUSE
] = TARGET_EADDRINUSE
,
320 [EADDRNOTAVAIL
] = TARGET_EADDRNOTAVAIL
,
321 [ENETDOWN
] = TARGET_ENETDOWN
,
322 [ENETUNREACH
] = TARGET_ENETUNREACH
,
323 [ENETRESET
] = TARGET_ENETRESET
,
324 [ECONNABORTED
] = TARGET_ECONNABORTED
,
325 [ECONNRESET
] = TARGET_ECONNRESET
,
326 [ENOBUFS
] = TARGET_ENOBUFS
,
327 [EISCONN
] = TARGET_EISCONN
,
328 [ENOTCONN
] = TARGET_ENOTCONN
,
329 [EUCLEAN
] = TARGET_EUCLEAN
,
330 [ENOTNAM
] = TARGET_ENOTNAM
,
331 [ENAVAIL
] = TARGET_ENAVAIL
,
332 [EISNAM
] = TARGET_EISNAM
,
333 [EREMOTEIO
] = TARGET_EREMOTEIO
,
334 [ESHUTDOWN
] = TARGET_ESHUTDOWN
,
335 [ETOOMANYREFS
] = TARGET_ETOOMANYREFS
,
336 [ETIMEDOUT
] = TARGET_ETIMEDOUT
,
337 [ECONNREFUSED
] = TARGET_ECONNREFUSED
,
338 [EHOSTDOWN
] = TARGET_EHOSTDOWN
,
339 [EHOSTUNREACH
] = TARGET_EHOSTUNREACH
,
340 [EALREADY
] = TARGET_EALREADY
,
341 [EINPROGRESS
] = TARGET_EINPROGRESS
,
342 [ESTALE
] = TARGET_ESTALE
,
343 [ECANCELED
] = TARGET_ECANCELED
,
344 [ENOMEDIUM
] = TARGET_ENOMEDIUM
,
345 [EMEDIUMTYPE
] = TARGET_EMEDIUMTYPE
,
347 [ENOKEY
] = TARGET_ENOKEY
,
350 [EKEYEXPIRED
] = TARGET_EKEYEXPIRED
,
353 [EKEYREVOKED
] = TARGET_EKEYREVOKED
,
356 [EKEYREJECTED
] = TARGET_EKEYREJECTED
,
359 [EOWNERDEAD
] = TARGET_EOWNERDEAD
,
361 #ifdef ENOTRECOVERABLE
362 [ENOTRECOVERABLE
] = TARGET_ENOTRECOVERABLE
,
366 static inline int host_to_target_errno(int err
)
368 if(host_to_target_errno_table
[err
])
369 return host_to_target_errno_table
[err
];
373 static inline abi_long
get_errno(abi_long ret
)
376 return -host_to_target_errno(errno
);
381 static inline int is_error(abi_long ret
)
383 return (abi_ulong
)ret
>= (abi_ulong
)(-4096);
386 static abi_ulong target_brk
;
387 static abi_ulong target_original_brk
;
389 void target_set_brk(abi_ulong new_brk
)
391 target_original_brk
= target_brk
= HOST_PAGE_ALIGN(new_brk
);
394 /* do_brk() must return target values and target errnos. */
395 abi_long
do_brk(abi_ulong new_brk
)
398 abi_long mapped_addr
;
403 if (new_brk
< target_original_brk
)
404 return -TARGET_ENOMEM
;
406 brk_page
= HOST_PAGE_ALIGN(target_brk
);
408 /* If the new brk is less than this, set it and we're done... */
409 if (new_brk
< brk_page
) {
410 target_brk
= new_brk
;
414 /* We need to allocate more memory after the brk... */
415 new_alloc_size
= HOST_PAGE_ALIGN(new_brk
- brk_page
+ 1);
416 mapped_addr
= get_errno(target_mmap(brk_page
, new_alloc_size
,
417 PROT_READ
|PROT_WRITE
,
418 MAP_ANON
|MAP_FIXED
|MAP_PRIVATE
, 0, 0));
419 if (is_error(mapped_addr
)) {
422 target_brk
= new_brk
;
427 static inline fd_set
*target_to_host_fds(fd_set
*fds
,
428 abi_long
*target_fds
, int n
)
430 #if !defined(BSWAP_NEEDED) && !defined(WORDS_BIGENDIAN)
431 return (fd_set
*)target_fds
;
436 for(i
= 0;i
< n
; i
++) {
437 b
= (tswapl(target_fds
[i
/ TARGET_ABI_BITS
]) >>
438 (i
& (TARGET_ABI_BITS
- 1))) & 1;
449 static inline void host_to_target_fds(abi_long
*target_fds
,
452 #if !defined(BSWAP_NEEDED) && !defined(WORDS_BIGENDIAN)
459 nw
= (n
+ TARGET_ABI_BITS
- 1) / TARGET_ABI_BITS
;
461 for(i
= 0;i
< nw
; i
++) {
463 for(j
= 0; j
< TARGET_ABI_BITS
; j
++) {
464 v
|= ((FD_ISSET(k
, fds
) != 0) << j
);
467 target_fds
[i
] = tswapl(v
);
473 #if defined(__alpha__)
479 static inline abi_long
host_to_target_clock_t(long ticks
)
481 #if HOST_HZ == TARGET_HZ
484 return ((int64_t)ticks
* TARGET_HZ
) / HOST_HZ
;
488 static inline void host_to_target_rusage(abi_ulong target_addr
,
489 const struct rusage
*rusage
)
491 struct target_rusage
*target_rusage
;
493 lock_user_struct(target_rusage
, target_addr
, 0);
494 target_rusage
->ru_utime
.tv_sec
= tswapl(rusage
->ru_utime
.tv_sec
);
495 target_rusage
->ru_utime
.tv_usec
= tswapl(rusage
->ru_utime
.tv_usec
);
496 target_rusage
->ru_stime
.tv_sec
= tswapl(rusage
->ru_stime
.tv_sec
);
497 target_rusage
->ru_stime
.tv_usec
= tswapl(rusage
->ru_stime
.tv_usec
);
498 target_rusage
->ru_maxrss
= tswapl(rusage
->ru_maxrss
);
499 target_rusage
->ru_ixrss
= tswapl(rusage
->ru_ixrss
);
500 target_rusage
->ru_idrss
= tswapl(rusage
->ru_idrss
);
501 target_rusage
->ru_isrss
= tswapl(rusage
->ru_isrss
);
502 target_rusage
->ru_minflt
= tswapl(rusage
->ru_minflt
);
503 target_rusage
->ru_majflt
= tswapl(rusage
->ru_majflt
);
504 target_rusage
->ru_nswap
= tswapl(rusage
->ru_nswap
);
505 target_rusage
->ru_inblock
= tswapl(rusage
->ru_inblock
);
506 target_rusage
->ru_oublock
= tswapl(rusage
->ru_oublock
);
507 target_rusage
->ru_msgsnd
= tswapl(rusage
->ru_msgsnd
);
508 target_rusage
->ru_msgrcv
= tswapl(rusage
->ru_msgrcv
);
509 target_rusage
->ru_nsignals
= tswapl(rusage
->ru_nsignals
);
510 target_rusage
->ru_nvcsw
= tswapl(rusage
->ru_nvcsw
);
511 target_rusage
->ru_nivcsw
= tswapl(rusage
->ru_nivcsw
);
512 unlock_user_struct(target_rusage
, target_addr
, 1);
515 static inline void target_to_host_timeval(struct timeval
*tv
,
516 abi_ulong target_addr
)
518 struct target_timeval
*target_tv
;
520 lock_user_struct(target_tv
, target_addr
, 1);
521 tv
->tv_sec
= tswapl(target_tv
->tv_sec
);
522 tv
->tv_usec
= tswapl(target_tv
->tv_usec
);
523 unlock_user_struct(target_tv
, target_addr
, 0);
526 static inline void host_to_target_timeval(abi_ulong target_addr
,
527 const struct timeval
*tv
)
529 struct target_timeval
*target_tv
;
531 lock_user_struct(target_tv
, target_addr
, 0);
532 target_tv
->tv_sec
= tswapl(tv
->tv_sec
);
533 target_tv
->tv_usec
= tswapl(tv
->tv_usec
);
534 unlock_user_struct(target_tv
, target_addr
, 1);
538 /* do_select() must return target values and target errnos. */
539 static abi_long
do_select(int n
,
540 abi_ulong rfd_p
, abi_ulong wfd_p
,
541 abi_ulong efd_p
, abi_ulong target_tv
)
543 fd_set rfds
, wfds
, efds
;
544 fd_set
*rfds_ptr
, *wfds_ptr
, *efds_ptr
;
545 abi_long
*target_rfds
, *target_wfds
, *target_efds
;
546 struct timeval tv
, *tv_ptr
;
551 target_rfds
= lock_user(rfd_p
, sizeof(abi_long
) * n
, 1);
552 rfds_ptr
= target_to_host_fds(&rfds
, target_rfds
, n
);
558 target_wfds
= lock_user(wfd_p
, sizeof(abi_long
) * n
, 1);
559 wfds_ptr
= target_to_host_fds(&wfds
, target_wfds
, n
);
565 target_efds
= lock_user(efd_p
, sizeof(abi_long
) * n
, 1);
566 efds_ptr
= target_to_host_fds(&efds
, target_efds
, n
);
573 target_to_host_timeval(&tv
, target_tv
);
578 ret
= get_errno(select(n
, rfds_ptr
, wfds_ptr
, efds_ptr
, tv_ptr
));
582 host_to_target_fds(target_rfds
, rfds_ptr
, n
);
583 host_to_target_fds(target_wfds
, wfds_ptr
, n
);
584 host_to_target_fds(target_efds
, efds_ptr
, n
);
587 host_to_target_timeval(target_tv
, &tv
);
591 unlock_user(target_rfds
, rfd_p
, ok
? sizeof(abi_long
) * n
: 0);
593 unlock_user(target_wfds
, wfd_p
, ok
? sizeof(abi_long
) * n
: 0);
595 unlock_user(target_efds
, efd_p
, ok
? sizeof(abi_long
) * n
: 0);
600 static inline void target_to_host_sockaddr(struct sockaddr
*addr
,
601 abi_ulong target_addr
,
604 struct target_sockaddr
*target_saddr
;
606 target_saddr
= lock_user(target_addr
, len
, 1);
607 memcpy(addr
, target_saddr
, len
);
608 addr
->sa_family
= tswap16(target_saddr
->sa_family
);
609 unlock_user(target_saddr
, target_addr
, 0);
612 static inline void host_to_target_sockaddr(abi_ulong target_addr
,
613 struct sockaddr
*addr
,
616 struct target_sockaddr
*target_saddr
;
618 target_saddr
= lock_user(target_addr
, len
, 0);
619 memcpy(target_saddr
, addr
, len
);
620 target_saddr
->sa_family
= tswap16(addr
->sa_family
);
621 unlock_user(target_saddr
, target_addr
, len
);
624 /* ??? Should this also swap msgh->name? */
625 static inline void target_to_host_cmsg(struct msghdr
*msgh
,
626 struct target_msghdr
*target_msgh
)
628 struct cmsghdr
*cmsg
= CMSG_FIRSTHDR(msgh
);
629 struct target_cmsghdr
*target_cmsg
= TARGET_CMSG_FIRSTHDR(target_msgh
);
632 while (cmsg
&& target_cmsg
) {
633 void *data
= CMSG_DATA(cmsg
);
634 void *target_data
= TARGET_CMSG_DATA(target_cmsg
);
636 int len
= tswapl(target_cmsg
->cmsg_len
)
637 - TARGET_CMSG_ALIGN(sizeof (struct target_cmsghdr
));
639 space
+= CMSG_SPACE(len
);
640 if (space
> msgh
->msg_controllen
) {
641 space
-= CMSG_SPACE(len
);
642 gemu_log("Host cmsg overflow\n");
646 cmsg
->cmsg_level
= tswap32(target_cmsg
->cmsg_level
);
647 cmsg
->cmsg_type
= tswap32(target_cmsg
->cmsg_type
);
648 cmsg
->cmsg_len
= CMSG_LEN(len
);
650 if (cmsg
->cmsg_level
!= TARGET_SOL_SOCKET
|| cmsg
->cmsg_type
!= SCM_RIGHTS
) {
651 gemu_log("Unsupported ancillary data: %d/%d\n", cmsg
->cmsg_level
, cmsg
->cmsg_type
);
652 memcpy(data
, target_data
, len
);
654 int *fd
= (int *)data
;
655 int *target_fd
= (int *)target_data
;
656 int i
, numfds
= len
/ sizeof(int);
658 for (i
= 0; i
< numfds
; i
++)
659 fd
[i
] = tswap32(target_fd
[i
]);
662 cmsg
= CMSG_NXTHDR(msgh
, cmsg
);
663 target_cmsg
= TARGET_CMSG_NXTHDR(target_msgh
, target_cmsg
);
666 msgh
->msg_controllen
= space
;
669 /* ??? Should this also swap msgh->name? */
670 static inline void host_to_target_cmsg(struct target_msghdr
*target_msgh
,
673 struct cmsghdr
*cmsg
= CMSG_FIRSTHDR(msgh
);
674 struct target_cmsghdr
*target_cmsg
= TARGET_CMSG_FIRSTHDR(target_msgh
);
677 while (cmsg
&& target_cmsg
) {
678 void *data
= CMSG_DATA(cmsg
);
679 void *target_data
= TARGET_CMSG_DATA(target_cmsg
);
681 int len
= cmsg
->cmsg_len
- CMSG_ALIGN(sizeof (struct cmsghdr
));
683 space
+= TARGET_CMSG_SPACE(len
);
684 if (space
> tswapl(target_msgh
->msg_controllen
)) {
685 space
-= TARGET_CMSG_SPACE(len
);
686 gemu_log("Target cmsg overflow\n");
690 target_cmsg
->cmsg_level
= tswap32(cmsg
->cmsg_level
);
691 target_cmsg
->cmsg_type
= tswap32(cmsg
->cmsg_type
);
692 target_cmsg
->cmsg_len
= tswapl(TARGET_CMSG_LEN(len
));
694 if (cmsg
->cmsg_level
!= TARGET_SOL_SOCKET
|| cmsg
->cmsg_type
!= SCM_RIGHTS
) {
695 gemu_log("Unsupported ancillary data: %d/%d\n", cmsg
->cmsg_level
, cmsg
->cmsg_type
);
696 memcpy(target_data
, data
, len
);
698 int *fd
= (int *)data
;
699 int *target_fd
= (int *)target_data
;
700 int i
, numfds
= len
/ sizeof(int);
702 for (i
= 0; i
< numfds
; i
++)
703 target_fd
[i
] = tswap32(fd
[i
]);
706 cmsg
= CMSG_NXTHDR(msgh
, cmsg
);
707 target_cmsg
= TARGET_CMSG_NXTHDR(target_msgh
, target_cmsg
);
710 msgh
->msg_controllen
= tswapl(space
);
713 /* do_setsockopt() Must return target values and target errnos. */
714 static abi_long
do_setsockopt(int sockfd
, int level
, int optname
,
715 abi_ulong optval
, socklen_t optlen
)
722 /* TCP options all take an 'int' value. */
723 if (optlen
< sizeof(uint32_t))
724 return -TARGET_EINVAL
;
726 val
= tget32(optval
);
727 ret
= get_errno(setsockopt(sockfd
, level
, optname
, &val
, sizeof(val
)));
734 case IP_ROUTER_ALERT
:
738 case IP_MTU_DISCOVER
:
744 case IP_MULTICAST_TTL
:
745 case IP_MULTICAST_LOOP
:
747 if (optlen
>= sizeof(uint32_t)) {
748 val
= tget32(optval
);
749 } else if (optlen
>= 1) {
752 ret
= get_errno(setsockopt(sockfd
, level
, optname
, &val
, sizeof(val
)));
758 case TARGET_SOL_SOCKET
:
760 /* Options with 'int' argument. */
761 case TARGET_SO_DEBUG
:
764 case TARGET_SO_REUSEADDR
:
765 optname
= SO_REUSEADDR
;
770 case TARGET_SO_ERROR
:
773 case TARGET_SO_DONTROUTE
:
774 optname
= SO_DONTROUTE
;
776 case TARGET_SO_BROADCAST
:
777 optname
= SO_BROADCAST
;
779 case TARGET_SO_SNDBUF
:
782 case TARGET_SO_RCVBUF
:
785 case TARGET_SO_KEEPALIVE
:
786 optname
= SO_KEEPALIVE
;
788 case TARGET_SO_OOBINLINE
:
789 optname
= SO_OOBINLINE
;
791 case TARGET_SO_NO_CHECK
:
792 optname
= SO_NO_CHECK
;
794 case TARGET_SO_PRIORITY
:
795 optname
= SO_PRIORITY
;
798 case TARGET_SO_BSDCOMPAT
:
799 optname
= SO_BSDCOMPAT
;
802 case TARGET_SO_PASSCRED
:
803 optname
= SO_PASSCRED
;
805 case TARGET_SO_TIMESTAMP
:
806 optname
= SO_TIMESTAMP
;
808 case TARGET_SO_RCVLOWAT
:
809 optname
= SO_RCVLOWAT
;
811 case TARGET_SO_RCVTIMEO
:
812 optname
= SO_RCVTIMEO
;
814 case TARGET_SO_SNDTIMEO
:
815 optname
= SO_SNDTIMEO
;
821 if (optlen
< sizeof(uint32_t))
822 return -TARGET_EINVAL
;
824 val
= tget32(optval
);
825 ret
= get_errno(setsockopt(sockfd
, SOL_SOCKET
, optname
, &val
, sizeof(val
)));
829 gemu_log("Unsupported setsockopt level=%d optname=%d \n", level
, optname
);
830 ret
= -TARGET_ENOSYS
;
835 /* do_getsockopt() Must return target values and target errnos. */
836 static abi_long
do_getsockopt(int sockfd
, int level
, int optname
,
837 abi_ulong optval
, abi_ulong optlen
)
843 case TARGET_SOL_SOCKET
:
846 case TARGET_SO_LINGER
:
847 case TARGET_SO_RCVTIMEO
:
848 case TARGET_SO_SNDTIMEO
:
849 case TARGET_SO_PEERCRED
:
850 case TARGET_SO_PEERNAME
:
851 /* These don't just return a single integer */
858 /* TCP options all take an 'int' value. */
860 len
= tget32(optlen
);
862 return -TARGET_EINVAL
;
864 ret
= get_errno(getsockopt(sockfd
, level
, optname
, &val
, &lv
));
881 case IP_ROUTER_ALERT
:
885 case IP_MTU_DISCOVER
:
891 case IP_MULTICAST_TTL
:
892 case IP_MULTICAST_LOOP
:
893 len
= tget32(optlen
);
895 return -TARGET_EINVAL
;
897 ret
= get_errno(getsockopt(sockfd
, level
, optname
, &val
, &lv
));
900 if (len
< sizeof(int) && len
> 0 && val
>= 0 && val
< 255) {
905 if (len
> sizeof(int))
917 gemu_log("getsockopt level=%d optname=%d not yet supported\n",
919 ret
= -TARGET_ENOSYS
;
925 static void lock_iovec(struct iovec
*vec
, abi_ulong target_addr
,
928 struct target_iovec
*target_vec
;
932 target_vec
= lock_user(target_addr
, count
* sizeof(struct target_iovec
), 1);
933 for(i
= 0;i
< count
; i
++) {
934 base
= tswapl(target_vec
[i
].iov_base
);
935 vec
[i
].iov_len
= tswapl(target_vec
[i
].iov_len
);
936 vec
[i
].iov_base
= lock_user(base
, vec
[i
].iov_len
, copy
);
938 unlock_user (target_vec
, target_addr
, 0);
941 static void unlock_iovec(struct iovec
*vec
, abi_ulong target_addr
,
944 struct target_iovec
*target_vec
;
948 target_vec
= lock_user(target_addr
, count
* sizeof(struct target_iovec
), 1);
949 for(i
= 0;i
< count
; i
++) {
950 base
= tswapl(target_vec
[i
].iov_base
);
951 unlock_user(vec
[i
].iov_base
, base
, copy
? vec
[i
].iov_len
: 0);
953 unlock_user (target_vec
, target_addr
, 0);
956 /* do_socket() Must return target values and target errnos. */
957 static abi_long
do_socket(int domain
, int type
, int protocol
)
959 #if defined(TARGET_MIPS)
961 case TARGET_SOCK_DGRAM
:
964 case TARGET_SOCK_STREAM
:
967 case TARGET_SOCK_RAW
:
970 case TARGET_SOCK_RDM
:
973 case TARGET_SOCK_SEQPACKET
:
974 type
= SOCK_SEQPACKET
;
976 case TARGET_SOCK_PACKET
:
981 if (domain
== PF_NETLINK
)
982 return -EAFNOSUPPORT
; /* do not NETLINK socket connections possible */
983 return get_errno(socket(domain
, type
, protocol
));
986 /* do_bind() Must return target values and target errnos. */
987 static abi_long
do_bind(int sockfd
, abi_ulong target_addr
,
990 void *addr
= alloca(addrlen
);
992 target_to_host_sockaddr(addr
, target_addr
, addrlen
);
993 return get_errno(bind(sockfd
, addr
, addrlen
));
996 /* do_connect() Must return target values and target errnos. */
997 static abi_long
do_connect(int sockfd
, abi_ulong target_addr
,
1000 void *addr
= alloca(addrlen
);
1002 target_to_host_sockaddr(addr
, target_addr
, addrlen
);
1003 return get_errno(connect(sockfd
, addr
, addrlen
));
1006 /* do_sendrecvmsg() Must return target values and target errnos. */
1007 static abi_long
do_sendrecvmsg(int fd
, abi_ulong target_msg
,
1008 int flags
, int send
)
1011 struct target_msghdr
*msgp
;
1015 abi_ulong target_vec
;
1017 lock_user_struct(msgp
, target_msg
, 1);
1018 if (msgp
->msg_name
) {
1019 msg
.msg_namelen
= tswap32(msgp
->msg_namelen
);
1020 msg
.msg_name
= alloca(msg
.msg_namelen
);
1021 target_to_host_sockaddr(msg
.msg_name
, tswapl(msgp
->msg_name
),
1024 msg
.msg_name
= NULL
;
1025 msg
.msg_namelen
= 0;
1027 msg
.msg_controllen
= 2 * tswapl(msgp
->msg_controllen
);
1028 msg
.msg_control
= alloca(msg
.msg_controllen
);
1029 msg
.msg_flags
= tswap32(msgp
->msg_flags
);
1031 count
= tswapl(msgp
->msg_iovlen
);
1032 vec
= alloca(count
* sizeof(struct iovec
));
1033 target_vec
= tswapl(msgp
->msg_iov
);
1034 lock_iovec(vec
, target_vec
, count
, send
);
1035 msg
.msg_iovlen
= count
;
1039 target_to_host_cmsg(&msg
, msgp
);
1040 ret
= get_errno(sendmsg(fd
, &msg
, flags
));
1042 ret
= get_errno(recvmsg(fd
, &msg
, flags
));
1044 host_to_target_cmsg(msgp
, &msg
);
1046 unlock_iovec(vec
, target_vec
, count
, !send
);
1050 /* do_accept() Must return target values and target errnos. */
1051 static abi_long
do_accept(int fd
, abi_ulong target_addr
,
1052 abi_ulong target_addrlen
)
1054 socklen_t addrlen
= tget32(target_addrlen
);
1055 void *addr
= alloca(addrlen
);
1058 ret
= get_errno(accept(fd
, addr
, &addrlen
));
1059 if (!is_error(ret
)) {
1060 host_to_target_sockaddr(target_addr
, addr
, addrlen
);
1061 tput32(target_addrlen
, addrlen
);
1066 /* do_getpeername() Must return target values and target errnos. */
1067 static abi_long
do_getpeername(int fd
, abi_ulong target_addr
,
1068 abi_ulong target_addrlen
)
1070 socklen_t addrlen
= tget32(target_addrlen
);
1071 void *addr
= alloca(addrlen
);
1074 ret
= get_errno(getpeername(fd
, addr
, &addrlen
));
1075 if (!is_error(ret
)) {
1076 host_to_target_sockaddr(target_addr
, addr
, addrlen
);
1077 tput32(target_addrlen
, addrlen
);
1082 /* do_getsockname() Must return target values and target errnos. */
1083 static abi_long
do_getsockname(int fd
, abi_ulong target_addr
,
1084 abi_ulong target_addrlen
)
1086 socklen_t addrlen
= tget32(target_addrlen
);
1087 void *addr
= alloca(addrlen
);
1090 ret
= get_errno(getsockname(fd
, addr
, &addrlen
));
1091 if (!is_error(ret
)) {
1092 host_to_target_sockaddr(target_addr
, addr
, addrlen
);
1093 tput32(target_addrlen
, addrlen
);
1098 /* do_socketpair() Must return target values and target errnos. */
1099 static abi_long
do_socketpair(int domain
, int type
, int protocol
,
1100 abi_ulong target_tab
)
1105 ret
= get_errno(socketpair(domain
, type
, protocol
, tab
));
1106 if (!is_error(ret
)) {
1107 tput32(target_tab
, tab
[0]);
1108 tput32(target_tab
+ 4, tab
[1]);
1113 /* do_sendto() Must return target values and target errnos. */
1114 static abi_long
do_sendto(int fd
, abi_ulong msg
, size_t len
, int flags
,
1115 abi_ulong target_addr
, socklen_t addrlen
)
1121 host_msg
= lock_user(msg
, len
, 1);
1123 addr
= alloca(addrlen
);
1124 target_to_host_sockaddr(addr
, target_addr
, addrlen
);
1125 ret
= get_errno(sendto(fd
, host_msg
, len
, flags
, addr
, addrlen
));
1127 ret
= get_errno(send(fd
, host_msg
, len
, flags
));
1129 unlock_user(host_msg
, msg
, 0);
1133 /* do_recvfrom() Must return target values and target errnos. */
1134 static abi_long
do_recvfrom(int fd
, abi_ulong msg
, size_t len
, int flags
,
1135 abi_ulong target_addr
,
1136 abi_ulong target_addrlen
)
1143 host_msg
= lock_user(msg
, len
, 0);
1145 addrlen
= tget32(target_addrlen
);
1146 addr
= alloca(addrlen
);
1147 ret
= get_errno(recvfrom(fd
, host_msg
, len
, flags
, addr
, &addrlen
));
1149 addr
= NULL
; /* To keep compiler quiet. */
1150 ret
= get_errno(recv(fd
, host_msg
, len
, flags
));
1152 if (!is_error(ret
)) {
1154 host_to_target_sockaddr(target_addr
, addr
, addrlen
);
1155 tput32(target_addrlen
, addrlen
);
1157 unlock_user(host_msg
, msg
, len
);
1159 unlock_user(host_msg
, msg
, 0);
1164 #ifdef TARGET_NR_socketcall
1165 /* do_socketcall() Must return target values and target errnos. */
1166 static abi_long
do_socketcall(int num
, abi_ulong vptr
)
1169 const int n
= sizeof(abi_ulong
);
1174 int domain
= tgetl(vptr
);
1175 int type
= tgetl(vptr
+ n
);
1176 int protocol
= tgetl(vptr
+ 2 * n
);
1177 ret
= do_socket(domain
, type
, protocol
);
1182 int sockfd
= tgetl(vptr
);
1183 abi_ulong target_addr
= tgetl(vptr
+ n
);
1184 socklen_t addrlen
= tgetl(vptr
+ 2 * n
);
1185 ret
= do_bind(sockfd
, target_addr
, addrlen
);
1188 case SOCKOP_connect
:
1190 int sockfd
= tgetl(vptr
);
1191 abi_ulong target_addr
= tgetl(vptr
+ n
);
1192 socklen_t addrlen
= tgetl(vptr
+ 2 * n
);
1193 ret
= do_connect(sockfd
, target_addr
, addrlen
);
1198 int sockfd
= tgetl(vptr
);
1199 int backlog
= tgetl(vptr
+ n
);
1200 ret
= get_errno(listen(sockfd
, backlog
));
1205 int sockfd
= tgetl(vptr
);
1206 abi_ulong target_addr
= tgetl(vptr
+ n
);
1207 abi_ulong target_addrlen
= tgetl(vptr
+ 2 * n
);
1208 ret
= do_accept(sockfd
, target_addr
, target_addrlen
);
1211 case SOCKOP_getsockname
:
1213 int sockfd
= tgetl(vptr
);
1214 abi_ulong target_addr
= tgetl(vptr
+ n
);
1215 abi_ulong target_addrlen
= tgetl(vptr
+ 2 * n
);
1216 ret
= do_getsockname(sockfd
, target_addr
, target_addrlen
);
1219 case SOCKOP_getpeername
:
1221 int sockfd
= tgetl(vptr
);
1222 abi_ulong target_addr
= tgetl(vptr
+ n
);
1223 abi_ulong target_addrlen
= tgetl(vptr
+ 2 * n
);
1224 ret
= do_getpeername(sockfd
, target_addr
, target_addrlen
);
1227 case SOCKOP_socketpair
:
1229 int domain
= tgetl(vptr
);
1230 int type
= tgetl(vptr
+ n
);
1231 int protocol
= tgetl(vptr
+ 2 * n
);
1232 abi_ulong tab
= tgetl(vptr
+ 3 * n
);
1233 ret
= do_socketpair(domain
, type
, protocol
, tab
);
1238 int sockfd
= tgetl(vptr
);
1239 abi_ulong msg
= tgetl(vptr
+ n
);
1240 size_t len
= tgetl(vptr
+ 2 * n
);
1241 int flags
= tgetl(vptr
+ 3 * n
);
1242 ret
= do_sendto(sockfd
, msg
, len
, flags
, 0, 0);
1247 int sockfd
= tgetl(vptr
);
1248 abi_ulong msg
= tgetl(vptr
+ n
);
1249 size_t len
= tgetl(vptr
+ 2 * n
);
1250 int flags
= tgetl(vptr
+ 3 * n
);
1251 ret
= do_recvfrom(sockfd
, msg
, len
, flags
, 0, 0);
1256 int sockfd
= tgetl(vptr
);
1257 abi_ulong msg
= tgetl(vptr
+ n
);
1258 size_t len
= tgetl(vptr
+ 2 * n
);
1259 int flags
= tgetl(vptr
+ 3 * n
);
1260 abi_ulong addr
= tgetl(vptr
+ 4 * n
);
1261 socklen_t addrlen
= tgetl(vptr
+ 5 * n
);
1262 ret
= do_sendto(sockfd
, msg
, len
, flags
, addr
, addrlen
);
1265 case SOCKOP_recvfrom
:
1267 int sockfd
= tgetl(vptr
);
1268 abi_ulong msg
= tgetl(vptr
+ n
);
1269 size_t len
= tgetl(vptr
+ 2 * n
);
1270 int flags
= tgetl(vptr
+ 3 * n
);
1271 abi_ulong addr
= tgetl(vptr
+ 4 * n
);
1272 abi_ulong addrlen
= tgetl(vptr
+ 5 * n
);
1273 ret
= do_recvfrom(sockfd
, msg
, len
, flags
, addr
, addrlen
);
1276 case SOCKOP_shutdown
:
1278 int sockfd
= tgetl(vptr
);
1279 int how
= tgetl(vptr
+ n
);
1281 ret
= get_errno(shutdown(sockfd
, how
));
1284 case SOCKOP_sendmsg
:
1285 case SOCKOP_recvmsg
:
1288 abi_ulong target_msg
;
1292 target_msg
= tgetl(vptr
+ n
);
1293 flags
= tgetl(vptr
+ 2 * n
);
1295 ret
= do_sendrecvmsg(fd
, target_msg
, flags
,
1296 (num
== SOCKOP_sendmsg
));
1299 case SOCKOP_setsockopt
:
1301 int sockfd
= tgetl(vptr
);
1302 int level
= tgetl(vptr
+ n
);
1303 int optname
= tgetl(vptr
+ 2 * n
);
1304 abi_ulong optval
= tgetl(vptr
+ 3 * n
);
1305 socklen_t optlen
= tgetl(vptr
+ 4 * n
);
1307 ret
= do_setsockopt(sockfd
, level
, optname
, optval
, optlen
);
1310 case SOCKOP_getsockopt
:
1312 int sockfd
= tgetl(vptr
);
1313 int level
= tgetl(vptr
+ n
);
1314 int optname
= tgetl(vptr
+ 2 * n
);
1315 abi_ulong optval
= tgetl(vptr
+ 3 * n
);
1316 abi_ulong poptlen
= tgetl(vptr
+ 4 * n
);
1318 ret
= do_getsockopt(sockfd
, level
, optname
, optval
, poptlen
);
1322 gemu_log("Unsupported socketcall: %d\n", num
);
1323 ret
= -TARGET_ENOSYS
;
1330 #ifdef TARGET_NR_ipc
1331 #define N_SHM_REGIONS 32
1333 static struct shm_region
{
1336 } shm_regions
[N_SHM_REGIONS
];
1338 struct target_ipc_perm
1345 unsigned short int mode
;
1346 unsigned short int __pad1
;
1347 unsigned short int __seq
;
1348 unsigned short int __pad2
;
1349 abi_ulong __unused1
;
1350 abi_ulong __unused2
;
1353 struct target_semid_ds
1355 struct target_ipc_perm sem_perm
;
1356 abi_ulong sem_otime
;
1357 abi_ulong __unused1
;
1358 abi_ulong sem_ctime
;
1359 abi_ulong __unused2
;
1360 abi_ulong sem_nsems
;
1361 abi_ulong __unused3
;
1362 abi_ulong __unused4
;
1365 static inline void target_to_host_ipc_perm(struct ipc_perm
*host_ip
,
1366 abi_ulong target_addr
)
1368 struct target_ipc_perm
*target_ip
;
1369 struct target_semid_ds
*target_sd
;
1371 lock_user_struct(target_sd
, target_addr
, 1);
1372 target_ip
=&(target_sd
->sem_perm
);
1373 host_ip
->__key
= tswapl(target_ip
->__key
);
1374 host_ip
->uid
= tswapl(target_ip
->uid
);
1375 host_ip
->gid
= tswapl(target_ip
->gid
);
1376 host_ip
->cuid
= tswapl(target_ip
->cuid
);
1377 host_ip
->cgid
= tswapl(target_ip
->cgid
);
1378 host_ip
->mode
= tswapl(target_ip
->mode
);
1379 unlock_user_struct(target_sd
, target_addr
, 0);
1382 static inline void host_to_target_ipc_perm(abi_ulong target_addr
,
1383 struct ipc_perm
*host_ip
)
1385 struct target_ipc_perm
*target_ip
;
1386 struct target_semid_ds
*target_sd
;
1388 lock_user_struct(target_sd
, target_addr
, 0);
1389 target_ip
= &(target_sd
->sem_perm
);
1390 target_ip
->__key
= tswapl(host_ip
->__key
);
1391 target_ip
->uid
= tswapl(host_ip
->uid
);
1392 target_ip
->gid
= tswapl(host_ip
->gid
);
1393 target_ip
->cuid
= tswapl(host_ip
->cuid
);
1394 target_ip
->cgid
= tswapl(host_ip
->cgid
);
1395 target_ip
->mode
= tswapl(host_ip
->mode
);
1396 unlock_user_struct(target_sd
, target_addr
, 1);
1399 static inline void target_to_host_semid_ds(struct semid_ds
*host_sd
,
1400 abi_ulong target_addr
)
1402 struct target_semid_ds
*target_sd
;
1404 lock_user_struct(target_sd
, target_addr
, 1);
1405 target_to_host_ipc_perm(&(host_sd
->sem_perm
),target_addr
);
1406 host_sd
->sem_nsems
= tswapl(target_sd
->sem_nsems
);
1407 host_sd
->sem_otime
= tswapl(target_sd
->sem_otime
);
1408 host_sd
->sem_ctime
= tswapl(target_sd
->sem_ctime
);
1409 unlock_user_struct(target_sd
, target_addr
, 0);
1412 static inline void host_to_target_semid_ds(abi_ulong target_addr
,
1413 struct semid_ds
*host_sd
)
1415 struct target_semid_ds
*target_sd
;
1417 lock_user_struct(target_sd
, target_addr
, 0);
1418 host_to_target_ipc_perm(target_addr
,&(host_sd
->sem_perm
));
1419 target_sd
->sem_nsems
= tswapl(host_sd
->sem_nsems
);
1420 target_sd
->sem_otime
= tswapl(host_sd
->sem_otime
);
1421 target_sd
->sem_ctime
= tswapl(host_sd
->sem_ctime
);
1422 unlock_user_struct(target_sd
, target_addr
, 1);
1427 struct semid_ds
*buf
;
1428 unsigned short *array
;
1431 union target_semun
{
1434 unsigned short int *array
;
1437 static inline void target_to_host_semun(int cmd
,
1438 union semun
*host_su
,
1439 abi_ulong target_addr
,
1440 struct semid_ds
*ds
)
1442 union target_semun
*target_su
;
1447 lock_user_struct(target_su
, target_addr
, 1);
1448 target_to_host_semid_ds(ds
,target_su
->buf
);
1450 unlock_user_struct(target_su
, target_addr
, 0);
1454 lock_user_struct(target_su
, target_addr
, 1);
1455 host_su
->val
= tswapl(target_su
->val
);
1456 unlock_user_struct(target_su
, target_addr
, 0);
1460 lock_user_struct(target_su
, target_addr
, 1);
1461 *host_su
->array
= tswap16(*target_su
->array
);
1462 unlock_user_struct(target_su
, target_addr
, 0);
1465 gemu_log("semun operation not fully supported: %d\n", (int)cmd
);
1469 static inline void host_to_target_semun(int cmd
,
1470 abi_ulong target_addr
,
1471 union semun
*host_su
,
1472 struct semid_ds
*ds
)
1474 union target_semun
*target_su
;
1479 lock_user_struct(target_su
, target_addr
, 0);
1480 host_to_target_semid_ds(target_su
->buf
,ds
);
1481 unlock_user_struct(target_su
, target_addr
, 1);
1485 lock_user_struct(target_su
, target_addr
, 0);
1486 target_su
->val
= tswapl(host_su
->val
);
1487 unlock_user_struct(target_su
, target_addr
, 1);
1491 lock_user_struct(target_su
, target_addr
, 0);
1492 *target_su
->array
= tswap16(*host_su
->array
);
1493 unlock_user_struct(target_su
, target_addr
, 1);
1496 gemu_log("semun operation not fully supported: %d\n", (int)cmd
);
1500 static inline abi_long
do_semctl(int first
, int second
, int third
,
1504 struct semid_ds dsarg
;
1505 int cmd
= third
&0xff;
1510 target_to_host_semun(cmd
,&arg
,ptr
,&dsarg
);
1511 ret
= get_errno(semctl(first
, second
, cmd
, arg
));
1512 host_to_target_semun(cmd
,ptr
,&arg
,&dsarg
);
1515 target_to_host_semun(cmd
,&arg
,ptr
,&dsarg
);
1516 ret
= get_errno(semctl(first
, second
, cmd
, arg
));
1517 host_to_target_semun(cmd
,ptr
,&arg
,&dsarg
);
1520 target_to_host_semun(cmd
,&arg
,ptr
,&dsarg
);
1521 ret
= get_errno(semctl(first
, second
, cmd
, arg
));
1522 host_to_target_semun(cmd
,ptr
,&arg
,&dsarg
);
1525 target_to_host_semun(cmd
,&arg
,ptr
,&dsarg
);
1526 ret
= get_errno(semctl(first
, second
, cmd
, arg
));
1527 host_to_target_semun(cmd
,ptr
,&arg
,&dsarg
);
1530 target_to_host_semun(cmd
,&arg
,ptr
,&dsarg
);
1531 ret
= get_errno(semctl(first
, second
, cmd
, arg
));
1532 host_to_target_semun(cmd
,ptr
,&arg
,&dsarg
);
1535 target_to_host_semun(cmd
,&arg
,ptr
,&dsarg
);
1536 ret
= get_errno(semctl(first
, second
, cmd
, arg
));
1537 host_to_target_semun(cmd
,ptr
,&arg
,&dsarg
);
1540 ret
= get_errno(semctl(first
, second
, cmd
, arg
));
1546 struct target_msqid_ds
1548 struct target_ipc_perm msg_perm
;
1549 abi_ulong msg_stime
;
1550 abi_ulong __unused1
;
1551 abi_ulong msg_rtime
;
1552 abi_ulong __unused2
;
1553 abi_ulong msg_ctime
;
1554 abi_ulong __unused3
;
1555 abi_ulong __msg_cbytes
;
1557 abi_ulong msg_qbytes
;
1558 abi_ulong msg_lspid
;
1559 abi_ulong msg_lrpid
;
1560 abi_ulong __unused4
;
1561 abi_ulong __unused5
;
1564 static inline void target_to_host_msqid_ds(struct msqid_ds
*host_md
,
1565 abi_ulong target_addr
)
1567 struct target_msqid_ds
*target_md
;
1569 lock_user_struct(target_md
, target_addr
, 1);
1570 target_to_host_ipc_perm(&(host_md
->msg_perm
),target_addr
);
1571 host_md
->msg_stime
= tswapl(target_md
->msg_stime
);
1572 host_md
->msg_rtime
= tswapl(target_md
->msg_rtime
);
1573 host_md
->msg_ctime
= tswapl(target_md
->msg_ctime
);
1574 host_md
->__msg_cbytes
= tswapl(target_md
->__msg_cbytes
);
1575 host_md
->msg_qnum
= tswapl(target_md
->msg_qnum
);
1576 host_md
->msg_qbytes
= tswapl(target_md
->msg_qbytes
);
1577 host_md
->msg_lspid
= tswapl(target_md
->msg_lspid
);
1578 host_md
->msg_lrpid
= tswapl(target_md
->msg_lrpid
);
1579 unlock_user_struct(target_md
, target_addr
, 0);
1582 static inline void host_to_target_msqid_ds(abi_ulong target_addr
,
1583 struct msqid_ds
*host_md
)
1585 struct target_msqid_ds
*target_md
;
1587 lock_user_struct(target_md
, target_addr
, 0);
1588 host_to_target_ipc_perm(target_addr
,&(host_md
->msg_perm
));
1589 target_md
->msg_stime
= tswapl(host_md
->msg_stime
);
1590 target_md
->msg_rtime
= tswapl(host_md
->msg_rtime
);
1591 target_md
->msg_ctime
= tswapl(host_md
->msg_ctime
);
1592 target_md
->__msg_cbytes
= tswapl(host_md
->__msg_cbytes
);
1593 target_md
->msg_qnum
= tswapl(host_md
->msg_qnum
);
1594 target_md
->msg_qbytes
= tswapl(host_md
->msg_qbytes
);
1595 target_md
->msg_lspid
= tswapl(host_md
->msg_lspid
);
1596 target_md
->msg_lrpid
= tswapl(host_md
->msg_lrpid
);
1597 unlock_user_struct(target_md
, target_addr
, 1);
1600 static inline abi_long
do_msgctl(int first
, int second
, abi_long ptr
)
1602 struct msqid_ds dsarg
;
1603 int cmd
= second
&0xff;
1608 target_to_host_msqid_ds(&dsarg
,ptr
);
1609 ret
= get_errno(msgctl(first
, cmd
, &dsarg
));
1610 host_to_target_msqid_ds(ptr
,&dsarg
);
1612 ret
= get_errno(msgctl(first
, cmd
, &dsarg
));
1617 struct target_msgbuf
{
1622 static inline abi_long
do_msgsnd(int msqid
, abi_long msgp
,
1623 unsigned int msgsz
, int msgflg
)
1625 struct target_msgbuf
*target_mb
;
1626 struct msgbuf
*host_mb
;
1629 lock_user_struct(target_mb
,msgp
,0);
1630 host_mb
= malloc(msgsz
+sizeof(long));
1631 host_mb
->mtype
= tswapl(target_mb
->mtype
);
1632 memcpy(host_mb
->mtext
,target_mb
->mtext
,msgsz
);
1633 ret
= get_errno(msgsnd(msqid
, host_mb
, msgsz
, msgflg
));
1635 unlock_user_struct(target_mb
, msgp
, 0);
1640 static inline abi_long
do_msgrcv(int msqid
, abi_long msgp
,
1641 unsigned int msgsz
, int msgtype
,
1644 struct target_msgbuf
*target_mb
;
1645 struct msgbuf
*host_mb
;
1648 lock_user_struct(target_mb
, msgp
, 0);
1649 host_mb
= malloc(msgsz
+sizeof(long));
1650 ret
= get_errno(msgrcv(msqid
, host_mb
, msgsz
, 1, msgflg
));
1652 memcpy(target_mb
->mtext
, host_mb
->mtext
, ret
);
1653 target_mb
->mtype
= tswapl(host_mb
->mtype
);
1655 unlock_user_struct(target_mb
, msgp
, 0);
1660 /* ??? This only works with linear mappings. */
1661 /* do_ipc() must return target values and target errnos. */
1662 static abi_long
do_ipc(unsigned int call
, int first
,
1663 int second
, int third
,
1664 abi_long ptr
, abi_long fifth
)
1668 unsigned long raddr
;
1669 struct shmid_ds shm_info
;
1672 version
= call
>> 16;
1677 ret
= get_errno(semop(first
,(struct sembuf
*) ptr
, second
));
1681 ret
= get_errno(semget(first
, second
, third
));
1685 ret
= do_semctl(first
, second
, third
, ptr
);
1688 case IPCOP_semtimedop
:
1689 gemu_log("Unsupported ipc call: %d (version %d)\n", call
, version
);
1690 ret
= -TARGET_ENOSYS
;
1694 ret
= get_errno(msgget(first
, second
));
1698 ret
= do_msgsnd(first
, ptr
, second
, third
);
1702 ret
= do_msgctl(first
, second
, ptr
);
1709 void *__unbounded msgp
;
1713 struct ipc_kludge
*foo
= (struct ipc_kludge
*) ptr
;
1714 struct msgbuf
*msgp
= (struct msgbuf
*) foo
->msgp
;
1716 ret
= do_msgrcv(first
, (long)msgp
, second
, 0, third
);
1722 /* SHM_* flags are the same on all linux platforms */
1723 ret
= get_errno((long) shmat(first
, (void *) ptr
, second
));
1727 /* find out the length of the shared memory segment */
1729 ret
= get_errno(shmctl(first
, IPC_STAT
, &shm_info
));
1730 if (is_error(ret
)) {
1731 /* can't get length, bail out */
1732 shmdt((void *) raddr
);
1735 page_set_flags(raddr
, raddr
+ shm_info
.shm_segsz
,
1736 PAGE_VALID
| PAGE_READ
|
1737 ((second
& SHM_RDONLY
)? 0: PAGE_WRITE
));
1738 for (i
= 0; i
< N_SHM_REGIONS
; ++i
) {
1739 if (shm_regions
[i
].start
== 0) {
1740 shm_regions
[i
].start
= raddr
;
1741 shm_regions
[i
].size
= shm_info
.shm_segsz
;
1745 if (put_user(raddr
, (abi_ulong
*)third
))
1746 return -TARGET_EFAULT
;
1750 for (i
= 0; i
< N_SHM_REGIONS
; ++i
) {
1751 if (shm_regions
[i
].start
== ptr
) {
1752 shm_regions
[i
].start
= 0;
1753 page_set_flags(ptr
, shm_regions
[i
].size
, 0);
1757 ret
= get_errno(shmdt((void *) ptr
));
1761 /* IPC_* flag values are the same on all linux platforms */
1762 ret
= get_errno(shmget(first
, second
, third
));
1765 /* IPC_* and SHM_* command values are the same on all linux platforms */
1771 ret
= get_errno(shmctl(first
, second
, NULL
));
1779 gemu_log("Unsupported ipc call: %d (version %d)\n", call
, version
);
1780 ret
= -TARGET_ENOSYS
;
1787 /* kernel structure types definitions */
1790 #define STRUCT(name, list...) STRUCT_ ## name,
1791 #define STRUCT_SPECIAL(name) STRUCT_ ## name,
1793 #include "syscall_types.h"
1796 #undef STRUCT_SPECIAL
1798 #define STRUCT(name, list...) const argtype struct_ ## name ## _def[] = { list, TYPE_NULL };
1799 #define STRUCT_SPECIAL(name)
1800 #include "syscall_types.h"
1802 #undef STRUCT_SPECIAL
1804 typedef struct IOCTLEntry
{
1805 unsigned int target_cmd
;
1806 unsigned int host_cmd
;
1809 const argtype arg_type
[5];
1812 #define IOC_R 0x0001
1813 #define IOC_W 0x0002
1814 #define IOC_RW (IOC_R | IOC_W)
1816 #define MAX_STRUCT_SIZE 4096
1818 IOCTLEntry ioctl_entries
[] = {
1819 #define IOCTL(cmd, access, types...) \
1820 { TARGET_ ## cmd, cmd, #cmd, access, { types } },
1825 /* ??? Implement proper locking for ioctls. */
1826 /* do_ioctl() Must return target values and target errnos. */
1827 static abi_long
do_ioctl(int fd
, abi_long cmd
, abi_long arg
)
1829 const IOCTLEntry
*ie
;
1830 const argtype
*arg_type
;
1832 uint8_t buf_temp
[MAX_STRUCT_SIZE
];
1838 if (ie
->target_cmd
== 0) {
1839 gemu_log("Unsupported ioctl: cmd=0x%04lx\n", (long)cmd
);
1840 return -TARGET_ENOSYS
;
1842 if (ie
->target_cmd
== cmd
)
1846 arg_type
= ie
->arg_type
;
1848 gemu_log("ioctl: cmd=0x%04lx (%s)\n", (long)cmd
, ie
->name
);
1850 switch(arg_type
[0]) {
1853 ret
= get_errno(ioctl(fd
, ie
->host_cmd
));
1858 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, arg
));
1862 target_size
= thunk_type_size(arg_type
, 0);
1863 switch(ie
->access
) {
1865 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, buf_temp
));
1866 if (!is_error(ret
)) {
1867 argptr
= lock_user(arg
, target_size
, 0);
1868 thunk_convert(argptr
, buf_temp
, arg_type
, THUNK_TARGET
);
1869 unlock_user(argptr
, arg
, target_size
);
1873 argptr
= lock_user(arg
, target_size
, 1);
1874 thunk_convert(buf_temp
, argptr
, arg_type
, THUNK_HOST
);
1875 unlock_user(argptr
, arg
, 0);
1876 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, buf_temp
));
1880 argptr
= lock_user(arg
, target_size
, 1);
1881 thunk_convert(buf_temp
, argptr
, arg_type
, THUNK_HOST
);
1882 unlock_user(argptr
, arg
, 0);
1883 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, buf_temp
));
1884 if (!is_error(ret
)) {
1885 argptr
= lock_user(arg
, target_size
, 0);
1886 thunk_convert(argptr
, buf_temp
, arg_type
, THUNK_TARGET
);
1887 unlock_user(argptr
, arg
, target_size
);
1893 gemu_log("Unsupported ioctl type: cmd=0x%04lx type=%d\n",
1894 (long)cmd
, arg_type
[0]);
1895 ret
= -TARGET_ENOSYS
;
1901 bitmask_transtbl iflag_tbl
[] = {
1902 { TARGET_IGNBRK
, TARGET_IGNBRK
, IGNBRK
, IGNBRK
},
1903 { TARGET_BRKINT
, TARGET_BRKINT
, BRKINT
, BRKINT
},
1904 { TARGET_IGNPAR
, TARGET_IGNPAR
, IGNPAR
, IGNPAR
},
1905 { TARGET_PARMRK
, TARGET_PARMRK
, PARMRK
, PARMRK
},
1906 { TARGET_INPCK
, TARGET_INPCK
, INPCK
, INPCK
},
1907 { TARGET_ISTRIP
, TARGET_ISTRIP
, ISTRIP
, ISTRIP
},
1908 { TARGET_INLCR
, TARGET_INLCR
, INLCR
, INLCR
},
1909 { TARGET_IGNCR
, TARGET_IGNCR
, IGNCR
, IGNCR
},
1910 { TARGET_ICRNL
, TARGET_ICRNL
, ICRNL
, ICRNL
},
1911 { TARGET_IUCLC
, TARGET_IUCLC
, IUCLC
, IUCLC
},
1912 { TARGET_IXON
, TARGET_IXON
, IXON
, IXON
},
1913 { TARGET_IXANY
, TARGET_IXANY
, IXANY
, IXANY
},
1914 { TARGET_IXOFF
, TARGET_IXOFF
, IXOFF
, IXOFF
},
1915 { TARGET_IMAXBEL
, TARGET_IMAXBEL
, IMAXBEL
, IMAXBEL
},
1919 bitmask_transtbl oflag_tbl
[] = {
1920 { TARGET_OPOST
, TARGET_OPOST
, OPOST
, OPOST
},
1921 { TARGET_OLCUC
, TARGET_OLCUC
, OLCUC
, OLCUC
},
1922 { TARGET_ONLCR
, TARGET_ONLCR
, ONLCR
, ONLCR
},
1923 { TARGET_OCRNL
, TARGET_OCRNL
, OCRNL
, OCRNL
},
1924 { TARGET_ONOCR
, TARGET_ONOCR
, ONOCR
, ONOCR
},
1925 { TARGET_ONLRET
, TARGET_ONLRET
, ONLRET
, ONLRET
},
1926 { TARGET_OFILL
, TARGET_OFILL
, OFILL
, OFILL
},
1927 { TARGET_OFDEL
, TARGET_OFDEL
, OFDEL
, OFDEL
},
1928 { TARGET_NLDLY
, TARGET_NL0
, NLDLY
, NL0
},
1929 { TARGET_NLDLY
, TARGET_NL1
, NLDLY
, NL1
},
1930 { TARGET_CRDLY
, TARGET_CR0
, CRDLY
, CR0
},
1931 { TARGET_CRDLY
, TARGET_CR1
, CRDLY
, CR1
},
1932 { TARGET_CRDLY
, TARGET_CR2
, CRDLY
, CR2
},
1933 { TARGET_CRDLY
, TARGET_CR3
, CRDLY
, CR3
},
1934 { TARGET_TABDLY
, TARGET_TAB0
, TABDLY
, TAB0
},
1935 { TARGET_TABDLY
, TARGET_TAB1
, TABDLY
, TAB1
},
1936 { TARGET_TABDLY
, TARGET_TAB2
, TABDLY
, TAB2
},
1937 { TARGET_TABDLY
, TARGET_TAB3
, TABDLY
, TAB3
},
1938 { TARGET_BSDLY
, TARGET_BS0
, BSDLY
, BS0
},
1939 { TARGET_BSDLY
, TARGET_BS1
, BSDLY
, BS1
},
1940 { TARGET_VTDLY
, TARGET_VT0
, VTDLY
, VT0
},
1941 { TARGET_VTDLY
, TARGET_VT1
, VTDLY
, VT1
},
1942 { TARGET_FFDLY
, TARGET_FF0
, FFDLY
, FF0
},
1943 { TARGET_FFDLY
, TARGET_FF1
, FFDLY
, FF1
},
1947 bitmask_transtbl cflag_tbl
[] = {
1948 { TARGET_CBAUD
, TARGET_B0
, CBAUD
, B0
},
1949 { TARGET_CBAUD
, TARGET_B50
, CBAUD
, B50
},
1950 { TARGET_CBAUD
, TARGET_B75
, CBAUD
, B75
},
1951 { TARGET_CBAUD
, TARGET_B110
, CBAUD
, B110
},
1952 { TARGET_CBAUD
, TARGET_B134
, CBAUD
, B134
},
1953 { TARGET_CBAUD
, TARGET_B150
, CBAUD
, B150
},
1954 { TARGET_CBAUD
, TARGET_B200
, CBAUD
, B200
},
1955 { TARGET_CBAUD
, TARGET_B300
, CBAUD
, B300
},
1956 { TARGET_CBAUD
, TARGET_B600
, CBAUD
, B600
},
1957 { TARGET_CBAUD
, TARGET_B1200
, CBAUD
, B1200
},
1958 { TARGET_CBAUD
, TARGET_B1800
, CBAUD
, B1800
},
1959 { TARGET_CBAUD
, TARGET_B2400
, CBAUD
, B2400
},
1960 { TARGET_CBAUD
, TARGET_B4800
, CBAUD
, B4800
},
1961 { TARGET_CBAUD
, TARGET_B9600
, CBAUD
, B9600
},
1962 { TARGET_CBAUD
, TARGET_B19200
, CBAUD
, B19200
},
1963 { TARGET_CBAUD
, TARGET_B38400
, CBAUD
, B38400
},
1964 { TARGET_CBAUD
, TARGET_B57600
, CBAUD
, B57600
},
1965 { TARGET_CBAUD
, TARGET_B115200
, CBAUD
, B115200
},
1966 { TARGET_CBAUD
, TARGET_B230400
, CBAUD
, B230400
},
1967 { TARGET_CBAUD
, TARGET_B460800
, CBAUD
, B460800
},
1968 { TARGET_CSIZE
, TARGET_CS5
, CSIZE
, CS5
},
1969 { TARGET_CSIZE
, TARGET_CS6
, CSIZE
, CS6
},
1970 { TARGET_CSIZE
, TARGET_CS7
, CSIZE
, CS7
},
1971 { TARGET_CSIZE
, TARGET_CS8
, CSIZE
, CS8
},
1972 { TARGET_CSTOPB
, TARGET_CSTOPB
, CSTOPB
, CSTOPB
},
1973 { TARGET_CREAD
, TARGET_CREAD
, CREAD
, CREAD
},
1974 { TARGET_PARENB
, TARGET_PARENB
, PARENB
, PARENB
},
1975 { TARGET_PARODD
, TARGET_PARODD
, PARODD
, PARODD
},
1976 { TARGET_HUPCL
, TARGET_HUPCL
, HUPCL
, HUPCL
},
1977 { TARGET_CLOCAL
, TARGET_CLOCAL
, CLOCAL
, CLOCAL
},
1978 { TARGET_CRTSCTS
, TARGET_CRTSCTS
, CRTSCTS
, CRTSCTS
},
1982 bitmask_transtbl lflag_tbl
[] = {
1983 { TARGET_ISIG
, TARGET_ISIG
, ISIG
, ISIG
},
1984 { TARGET_ICANON
, TARGET_ICANON
, ICANON
, ICANON
},
1985 { TARGET_XCASE
, TARGET_XCASE
, XCASE
, XCASE
},
1986 { TARGET_ECHO
, TARGET_ECHO
, ECHO
, ECHO
},
1987 { TARGET_ECHOE
, TARGET_ECHOE
, ECHOE
, ECHOE
},
1988 { TARGET_ECHOK
, TARGET_ECHOK
, ECHOK
, ECHOK
},
1989 { TARGET_ECHONL
, TARGET_ECHONL
, ECHONL
, ECHONL
},
1990 { TARGET_NOFLSH
, TARGET_NOFLSH
, NOFLSH
, NOFLSH
},
1991 { TARGET_TOSTOP
, TARGET_TOSTOP
, TOSTOP
, TOSTOP
},
1992 { TARGET_ECHOCTL
, TARGET_ECHOCTL
, ECHOCTL
, ECHOCTL
},
1993 { TARGET_ECHOPRT
, TARGET_ECHOPRT
, ECHOPRT
, ECHOPRT
},
1994 { TARGET_ECHOKE
, TARGET_ECHOKE
, ECHOKE
, ECHOKE
},
1995 { TARGET_FLUSHO
, TARGET_FLUSHO
, FLUSHO
, FLUSHO
},
1996 { TARGET_PENDIN
, TARGET_PENDIN
, PENDIN
, PENDIN
},
1997 { TARGET_IEXTEN
, TARGET_IEXTEN
, IEXTEN
, IEXTEN
},
2001 static void target_to_host_termios (void *dst
, const void *src
)
2003 struct host_termios
*host
= dst
;
2004 const struct target_termios
*target
= src
;
2007 target_to_host_bitmask(tswap32(target
->c_iflag
), iflag_tbl
);
2009 target_to_host_bitmask(tswap32(target
->c_oflag
), oflag_tbl
);
2011 target_to_host_bitmask(tswap32(target
->c_cflag
), cflag_tbl
);
2013 target_to_host_bitmask(tswap32(target
->c_lflag
), lflag_tbl
);
2014 host
->c_line
= target
->c_line
;
2016 host
->c_cc
[VINTR
] = target
->c_cc
[TARGET_VINTR
];
2017 host
->c_cc
[VQUIT
] = target
->c_cc
[TARGET_VQUIT
];
2018 host
->c_cc
[VERASE
] = target
->c_cc
[TARGET_VERASE
];
2019 host
->c_cc
[VKILL
] = target
->c_cc
[TARGET_VKILL
];
2020 host
->c_cc
[VEOF
] = target
->c_cc
[TARGET_VEOF
];
2021 host
->c_cc
[VTIME
] = target
->c_cc
[TARGET_VTIME
];
2022 host
->c_cc
[VMIN
] = target
->c_cc
[TARGET_VMIN
];
2023 host
->c_cc
[VSWTC
] = target
->c_cc
[TARGET_VSWTC
];
2024 host
->c_cc
[VSTART
] = target
->c_cc
[TARGET_VSTART
];
2025 host
->c_cc
[VSTOP
] = target
->c_cc
[TARGET_VSTOP
];
2026 host
->c_cc
[VSUSP
] = target
->c_cc
[TARGET_VSUSP
];
2027 host
->c_cc
[VEOL
] = target
->c_cc
[TARGET_VEOL
];
2028 host
->c_cc
[VREPRINT
] = target
->c_cc
[TARGET_VREPRINT
];
2029 host
->c_cc
[VDISCARD
] = target
->c_cc
[TARGET_VDISCARD
];
2030 host
->c_cc
[VWERASE
] = target
->c_cc
[TARGET_VWERASE
];
2031 host
->c_cc
[VLNEXT
] = target
->c_cc
[TARGET_VLNEXT
];
2032 host
->c_cc
[VEOL2
] = target
->c_cc
[TARGET_VEOL2
];
2035 static void host_to_target_termios (void *dst
, const void *src
)
2037 struct target_termios
*target
= dst
;
2038 const struct host_termios
*host
= src
;
2041 tswap32(host_to_target_bitmask(host
->c_iflag
, iflag_tbl
));
2043 tswap32(host_to_target_bitmask(host
->c_oflag
, oflag_tbl
));
2045 tswap32(host_to_target_bitmask(host
->c_cflag
, cflag_tbl
));
2047 tswap32(host_to_target_bitmask(host
->c_lflag
, lflag_tbl
));
2048 target
->c_line
= host
->c_line
;
2050 target
->c_cc
[TARGET_VINTR
] = host
->c_cc
[VINTR
];
2051 target
->c_cc
[TARGET_VQUIT
] = host
->c_cc
[VQUIT
];
2052 target
->c_cc
[TARGET_VERASE
] = host
->c_cc
[VERASE
];
2053 target
->c_cc
[TARGET_VKILL
] = host
->c_cc
[VKILL
];
2054 target
->c_cc
[TARGET_VEOF
] = host
->c_cc
[VEOF
];
2055 target
->c_cc
[TARGET_VTIME
] = host
->c_cc
[VTIME
];
2056 target
->c_cc
[TARGET_VMIN
] = host
->c_cc
[VMIN
];
2057 target
->c_cc
[TARGET_VSWTC
] = host
->c_cc
[VSWTC
];
2058 target
->c_cc
[TARGET_VSTART
] = host
->c_cc
[VSTART
];
2059 target
->c_cc
[TARGET_VSTOP
] = host
->c_cc
[VSTOP
];
2060 target
->c_cc
[TARGET_VSUSP
] = host
->c_cc
[VSUSP
];
2061 target
->c_cc
[TARGET_VEOL
] = host
->c_cc
[VEOL
];
2062 target
->c_cc
[TARGET_VREPRINT
] = host
->c_cc
[VREPRINT
];
2063 target
->c_cc
[TARGET_VDISCARD
] = host
->c_cc
[VDISCARD
];
2064 target
->c_cc
[TARGET_VWERASE
] = host
->c_cc
[VWERASE
];
2065 target
->c_cc
[TARGET_VLNEXT
] = host
->c_cc
[VLNEXT
];
2066 target
->c_cc
[TARGET_VEOL2
] = host
->c_cc
[VEOL2
];
2069 StructEntry struct_termios_def
= {
2070 .convert
= { host_to_target_termios
, target_to_host_termios
},
2071 .size
= { sizeof(struct target_termios
), sizeof(struct host_termios
) },
2072 .align
= { __alignof__(struct target_termios
), __alignof__(struct host_termios
) },
2075 static bitmask_transtbl mmap_flags_tbl
[] = {
2076 { TARGET_MAP_SHARED
, TARGET_MAP_SHARED
, MAP_SHARED
, MAP_SHARED
},
2077 { TARGET_MAP_PRIVATE
, TARGET_MAP_PRIVATE
, MAP_PRIVATE
, MAP_PRIVATE
},
2078 { TARGET_MAP_FIXED
, TARGET_MAP_FIXED
, MAP_FIXED
, MAP_FIXED
},
2079 { TARGET_MAP_ANONYMOUS
, TARGET_MAP_ANONYMOUS
, MAP_ANONYMOUS
, MAP_ANONYMOUS
},
2080 { TARGET_MAP_GROWSDOWN
, TARGET_MAP_GROWSDOWN
, MAP_GROWSDOWN
, MAP_GROWSDOWN
},
2081 { TARGET_MAP_DENYWRITE
, TARGET_MAP_DENYWRITE
, MAP_DENYWRITE
, MAP_DENYWRITE
},
2082 { TARGET_MAP_EXECUTABLE
, TARGET_MAP_EXECUTABLE
, MAP_EXECUTABLE
, MAP_EXECUTABLE
},
2083 { TARGET_MAP_LOCKED
, TARGET_MAP_LOCKED
, MAP_LOCKED
, MAP_LOCKED
},
2087 static bitmask_transtbl fcntl_flags_tbl
[] = {
2088 { TARGET_O_ACCMODE
, TARGET_O_WRONLY
, O_ACCMODE
, O_WRONLY
, },
2089 { TARGET_O_ACCMODE
, TARGET_O_RDWR
, O_ACCMODE
, O_RDWR
, },
2090 { TARGET_O_CREAT
, TARGET_O_CREAT
, O_CREAT
, O_CREAT
, },
2091 { TARGET_O_EXCL
, TARGET_O_EXCL
, O_EXCL
, O_EXCL
, },
2092 { TARGET_O_NOCTTY
, TARGET_O_NOCTTY
, O_NOCTTY
, O_NOCTTY
, },
2093 { TARGET_O_TRUNC
, TARGET_O_TRUNC
, O_TRUNC
, O_TRUNC
, },
2094 { TARGET_O_APPEND
, TARGET_O_APPEND
, O_APPEND
, O_APPEND
, },
2095 { TARGET_O_NONBLOCK
, TARGET_O_NONBLOCK
, O_NONBLOCK
, O_NONBLOCK
, },
2096 { TARGET_O_SYNC
, TARGET_O_SYNC
, O_SYNC
, O_SYNC
, },
2097 { TARGET_FASYNC
, TARGET_FASYNC
, FASYNC
, FASYNC
, },
2098 { TARGET_O_DIRECTORY
, TARGET_O_DIRECTORY
, O_DIRECTORY
, O_DIRECTORY
, },
2099 { TARGET_O_NOFOLLOW
, TARGET_O_NOFOLLOW
, O_NOFOLLOW
, O_NOFOLLOW
, },
2100 { TARGET_O_LARGEFILE
, TARGET_O_LARGEFILE
, O_LARGEFILE
, O_LARGEFILE
, },
2101 #if defined(O_DIRECT)
2102 { TARGET_O_DIRECT
, TARGET_O_DIRECT
, O_DIRECT
, O_DIRECT
, },
2107 #if defined(TARGET_I386)
2109 /* NOTE: there is really one LDT for all the threads */
2112 static int read_ldt(abi_ulong ptr
, unsigned long bytecount
)
2119 size
= TARGET_LDT_ENTRIES
* TARGET_LDT_ENTRY_SIZE
;
2120 if (size
> bytecount
)
2122 p
= lock_user(ptr
, size
, 0);
2123 /* ??? Shoudl this by byteswapped? */
2124 memcpy(p
, ldt_table
, size
);
2125 unlock_user(p
, ptr
, size
);
2129 /* XXX: add locking support */
2130 /* write_ldt() returns host errnos */
2131 static int write_ldt(CPUX86State
*env
,
2132 abi_ulong ptr
, unsigned long bytecount
, int oldmode
)
2134 struct target_modify_ldt_ldt_s ldt_info
;
2135 struct target_modify_ldt_ldt_s
*target_ldt_info
;
2136 int seg_32bit
, contents
, read_exec_only
, limit_in_pages
;
2137 int seg_not_present
, useable
;
2138 uint32_t *lp
, entry_1
, entry_2
;
2140 if (bytecount
!= sizeof(ldt_info
))
2142 lock_user_struct(target_ldt_info
, ptr
, 1);
2143 ldt_info
.entry_number
= tswap32(target_ldt_info
->entry_number
);
2144 ldt_info
.base_addr
= tswapl(target_ldt_info
->base_addr
);
2145 ldt_info
.limit
= tswap32(target_ldt_info
->limit
);
2146 ldt_info
.flags
= tswap32(target_ldt_info
->flags
);
2147 unlock_user_struct(target_ldt_info
, ptr
, 0);
2149 if (ldt_info
.entry_number
>= TARGET_LDT_ENTRIES
)
2151 seg_32bit
= ldt_info
.flags
& 1;
2152 contents
= (ldt_info
.flags
>> 1) & 3;
2153 read_exec_only
= (ldt_info
.flags
>> 3) & 1;
2154 limit_in_pages
= (ldt_info
.flags
>> 4) & 1;
2155 seg_not_present
= (ldt_info
.flags
>> 5) & 1;
2156 useable
= (ldt_info
.flags
>> 6) & 1;
2158 if (contents
== 3) {
2161 if (seg_not_present
== 0)
2164 /* allocate the LDT */
2166 ldt_table
= malloc(TARGET_LDT_ENTRIES
* TARGET_LDT_ENTRY_SIZE
);
2169 memset(ldt_table
, 0, TARGET_LDT_ENTRIES
* TARGET_LDT_ENTRY_SIZE
);
2170 env
->ldt
.base
= h2g(ldt_table
);
2171 env
->ldt
.limit
= 0xffff;
2174 /* NOTE: same code as Linux kernel */
2175 /* Allow LDTs to be cleared by the user. */
2176 if (ldt_info
.base_addr
== 0 && ldt_info
.limit
== 0) {
2179 read_exec_only
== 1 &&
2181 limit_in_pages
== 0 &&
2182 seg_not_present
== 1 &&
2190 entry_1
= ((ldt_info
.base_addr
& 0x0000ffff) << 16) |
2191 (ldt_info
.limit
& 0x0ffff);
2192 entry_2
= (ldt_info
.base_addr
& 0xff000000) |
2193 ((ldt_info
.base_addr
& 0x00ff0000) >> 16) |
2194 (ldt_info
.limit
& 0xf0000) |
2195 ((read_exec_only
^ 1) << 9) |
2197 ((seg_not_present
^ 1) << 15) |
2199 (limit_in_pages
<< 23) |
2202 entry_2
|= (useable
<< 20);
2204 /* Install the new entry ... */
2206 lp
= (uint32_t *)(ldt_table
+ (ldt_info
.entry_number
<< 3));
2207 lp
[0] = tswap32(entry_1
);
2208 lp
[1] = tswap32(entry_2
);
2212 /* specific and weird i386 syscalls */
2213 /* do_modify_ldt() returns host errnos (it is inconsistent with the
2214 other do_*() functions which return target errnos). */
2215 int do_modify_ldt(CPUX86State
*env
, int func
, abi_ulong ptr
, unsigned long bytecount
)
2221 ret
= read_ldt(ptr
, bytecount
);
2224 ret
= write_ldt(env
, ptr
, bytecount
, 1);
2227 ret
= write_ldt(env
, ptr
, bytecount
, 0);
2233 #endif /* defined(TARGET_I386) */
2235 /* this stack is the equivalent of the kernel stack associated with a
2237 #define NEW_STACK_SIZE 8192
2239 static int clone_func(void *arg
)
2241 CPUState
*env
= arg
;
2247 /* do_fork() Must return host values and target errnos (unlike most
2248 do_*() functions). */
2249 int do_fork(CPUState
*env
, unsigned int flags
, abi_ulong newsp
)
2256 if (flags
& CLONE_VM
) {
2257 ts
= malloc(sizeof(TaskState
) + NEW_STACK_SIZE
);
2258 memset(ts
, 0, sizeof(TaskState
));
2259 new_stack
= ts
->stack
;
2261 /* add in task state list */
2262 ts
->next
= first_task_state
;
2263 first_task_state
= ts
;
2264 /* we create a new CPU instance. */
2265 new_env
= cpu_copy(env
);
2266 #if defined(TARGET_I386)
2268 newsp
= env
->regs
[R_ESP
];
2269 new_env
->regs
[R_ESP
] = newsp
;
2270 new_env
->regs
[R_EAX
] = 0;
2271 #elif defined(TARGET_ARM)
2273 newsp
= env
->regs
[13];
2274 new_env
->regs
[13] = newsp
;
2275 new_env
->regs
[0] = 0;
2276 #elif defined(TARGET_SPARC)
2278 newsp
= env
->regwptr
[22];
2279 new_env
->regwptr
[22] = newsp
;
2280 new_env
->regwptr
[0] = 0;
2282 printf ("HELPME: %s:%d\n", __FILE__
, __LINE__
);
2283 #elif defined(TARGET_M68K)
2285 newsp
= env
->aregs
[7];
2286 new_env
->aregs
[7] = newsp
;
2287 new_env
->dregs
[0] = 0;
2288 /* ??? is this sufficient? */
2289 #elif defined(TARGET_MIPS)
2291 newsp
= env
->gpr
[29][env
->current_tc
];
2292 new_env
->gpr
[29][env
->current_tc
] = newsp
;
2293 #elif defined(TARGET_PPC)
2295 newsp
= env
->gpr
[1];
2296 new_env
->gpr
[1] = newsp
;
2299 for (i
= 7; i
< 32; i
++)
2300 new_env
->gpr
[i
] = 0;
2302 #elif defined(TARGET_SH4)
2304 newsp
= env
->gregs
[15];
2305 new_env
->gregs
[15] = newsp
;
2307 #elif defined(TARGET_ALPHA)
2309 newsp
= env
->ir
[30];
2310 new_env
->ir
[30] = newsp
;
2314 for (i
= 7; i
< 30; i
++)
2317 #elif defined(TARGET_CRIS)
2319 newsp
= env
->regs
[14];
2320 new_env
->regs
[14] = newsp
;
2322 #error unsupported target CPU
2324 new_env
->opaque
= ts
;
2326 ret
= __clone2(clone_func
, new_stack
+ NEW_STACK_SIZE
, flags
, new_env
);
2328 ret
= clone(clone_func
, new_stack
+ NEW_STACK_SIZE
, flags
, new_env
);
2331 /* if no CLONE_VM, we consider it is a fork */
2332 if ((flags
& ~CSIGNAL
) != 0)
2339 static abi_long
do_fcntl(int fd
, int cmd
, abi_ulong arg
)
2342 struct target_flock
*target_fl
;
2343 struct flock64 fl64
;
2344 struct target_flock64
*target_fl64
;
2348 case TARGET_F_GETLK
:
2349 lock_user_struct(target_fl
, arg
, 1);
2350 fl
.l_type
= tswap16(target_fl
->l_type
);
2351 fl
.l_whence
= tswap16(target_fl
->l_whence
);
2352 fl
.l_start
= tswapl(target_fl
->l_start
);
2353 fl
.l_len
= tswapl(target_fl
->l_len
);
2354 fl
.l_pid
= tswapl(target_fl
->l_pid
);
2355 unlock_user_struct(target_fl
, arg
, 0);
2356 ret
= fcntl(fd
, cmd
, &fl
);
2358 lock_user_struct(target_fl
, arg
, 0);
2359 target_fl
->l_type
= tswap16(fl
.l_type
);
2360 target_fl
->l_whence
= tswap16(fl
.l_whence
);
2361 target_fl
->l_start
= tswapl(fl
.l_start
);
2362 target_fl
->l_len
= tswapl(fl
.l_len
);
2363 target_fl
->l_pid
= tswapl(fl
.l_pid
);
2364 unlock_user_struct(target_fl
, arg
, 1);
2368 case TARGET_F_SETLK
:
2369 case TARGET_F_SETLKW
:
2370 lock_user_struct(target_fl
, arg
, 1);
2371 fl
.l_type
= tswap16(target_fl
->l_type
);
2372 fl
.l_whence
= tswap16(target_fl
->l_whence
);
2373 fl
.l_start
= tswapl(target_fl
->l_start
);
2374 fl
.l_len
= tswapl(target_fl
->l_len
);
2375 fl
.l_pid
= tswapl(target_fl
->l_pid
);
2376 unlock_user_struct(target_fl
, arg
, 0);
2377 ret
= fcntl(fd
, cmd
, &fl
);
2380 case TARGET_F_GETLK64
:
2381 lock_user_struct(target_fl64
, arg
, 1);
2382 fl64
.l_type
= tswap16(target_fl64
->l_type
) >> 1;
2383 fl64
.l_whence
= tswap16(target_fl64
->l_whence
);
2384 fl64
.l_start
= tswapl(target_fl64
->l_start
);
2385 fl64
.l_len
= tswapl(target_fl64
->l_len
);
2386 fl64
.l_pid
= tswap16(target_fl64
->l_pid
);
2387 unlock_user_struct(target_fl64
, arg
, 0);
2388 ret
= fcntl(fd
, cmd
>> 1, &fl64
);
2390 lock_user_struct(target_fl64
, arg
, 0);
2391 target_fl64
->l_type
= tswap16(fl64
.l_type
) >> 1;
2392 target_fl64
->l_whence
= tswap16(fl64
.l_whence
);
2393 target_fl64
->l_start
= tswapl(fl64
.l_start
);
2394 target_fl64
->l_len
= tswapl(fl64
.l_len
);
2395 target_fl64
->l_pid
= tswapl(fl64
.l_pid
);
2396 unlock_user_struct(target_fl64
, arg
, 1);
2399 case TARGET_F_SETLK64
:
2400 case TARGET_F_SETLKW64
:
2401 lock_user_struct(target_fl64
, arg
, 1);
2402 fl64
.l_type
= tswap16(target_fl64
->l_type
) >> 1;
2403 fl64
.l_whence
= tswap16(target_fl64
->l_whence
);
2404 fl64
.l_start
= tswapl(target_fl64
->l_start
);
2405 fl64
.l_len
= tswapl(target_fl64
->l_len
);
2406 fl64
.l_pid
= tswap16(target_fl64
->l_pid
);
2407 unlock_user_struct(target_fl64
, arg
, 0);
2408 ret
= fcntl(fd
, cmd
>> 1, &fl64
);
2412 ret
= fcntl(fd
, cmd
, arg
);
2413 ret
= host_to_target_bitmask(ret
, fcntl_flags_tbl
);
2417 ret
= fcntl(fd
, cmd
, target_to_host_bitmask(arg
, fcntl_flags_tbl
));
2421 ret
= fcntl(fd
, cmd
, arg
);
2429 static inline int high2lowuid(int uid
)
2437 static inline int high2lowgid(int gid
)
2445 static inline int low2highuid(int uid
)
2447 if ((int16_t)uid
== -1)
2453 static inline int low2highgid(int gid
)
2455 if ((int16_t)gid
== -1)
2461 #endif /* USE_UID16 */
2463 void syscall_init(void)
2466 const argtype
*arg_type
;
2469 #define STRUCT(name, list...) thunk_register_struct(STRUCT_ ## name, #name, struct_ ## name ## _def);
2470 #define STRUCT_SPECIAL(name) thunk_register_struct_direct(STRUCT_ ## name, #name, &struct_ ## name ## _def);
2471 #include "syscall_types.h"
2473 #undef STRUCT_SPECIAL
2475 /* we patch the ioctl size if necessary. We rely on the fact that
2476 no ioctl has all the bits at '1' in the size field */
2478 while (ie
->target_cmd
!= 0) {
2479 if (((ie
->target_cmd
>> TARGET_IOC_SIZESHIFT
) & TARGET_IOC_SIZEMASK
) ==
2480 TARGET_IOC_SIZEMASK
) {
2481 arg_type
= ie
->arg_type
;
2482 if (arg_type
[0] != TYPE_PTR
) {
2483 fprintf(stderr
, "cannot patch size for ioctl 0x%x\n",
2488 size
= thunk_type_size(arg_type
, 0);
2489 ie
->target_cmd
= (ie
->target_cmd
&
2490 ~(TARGET_IOC_SIZEMASK
<< TARGET_IOC_SIZESHIFT
)) |
2491 (size
<< TARGET_IOC_SIZESHIFT
);
2493 /* automatic consistency check if same arch */
2494 #if defined(__i386__) && defined(TARGET_I386)
2495 if (ie
->target_cmd
!= ie
->host_cmd
) {
2496 fprintf(stderr
, "ERROR: ioctl: target=0x%x host=0x%x\n",
2497 ie
->target_cmd
, ie
->host_cmd
);
2504 #if TARGET_ABI_BITS == 32
2505 static inline uint64_t target_offset64(uint32_t word0
, uint32_t word1
)
2507 #ifdef TARGET_WORDS_BIG_ENDIAN
2508 return ((uint64_t)word0
<< 32) | word1
;
2510 return ((uint64_t)word1
<< 32) | word0
;
2513 #else /* TARGET_ABI_BITS == 32 */
2514 static inline uint64_t target_offset64(uint64_t word0
, uint64_t word1
)
2518 #endif /* TARGET_ABI_BITS != 32 */
2520 #ifdef TARGET_NR_truncate64
2521 static inline abi_long
target_truncate64(void *cpu_env
, const char *arg1
,
2527 if (((CPUARMState
*)cpu_env
)->eabi
)
2533 return get_errno(truncate64(arg1
, target_offset64(arg2
, arg3
)));
2537 #ifdef TARGET_NR_ftruncate64
2538 static inline abi_long
target_ftruncate64(void *cpu_env
, abi_long arg1
,
2544 if (((CPUARMState
*)cpu_env
)->eabi
)
2550 return get_errno(ftruncate64(arg1
, target_offset64(arg2
, arg3
)));
2554 static inline void target_to_host_timespec(struct timespec
*host_ts
,
2555 abi_ulong target_addr
)
2557 struct target_timespec
*target_ts
;
2559 lock_user_struct(target_ts
, target_addr
, 1);
2560 host_ts
->tv_sec
= tswapl(target_ts
->tv_sec
);
2561 host_ts
->tv_nsec
= tswapl(target_ts
->tv_nsec
);
2562 unlock_user_struct(target_ts
, target_addr
, 0);
2565 static inline void host_to_target_timespec(abi_ulong target_addr
,
2566 struct timespec
*host_ts
)
2568 struct target_timespec
*target_ts
;
2570 lock_user_struct(target_ts
, target_addr
, 0);
2571 target_ts
->tv_sec
= tswapl(host_ts
->tv_sec
);
2572 target_ts
->tv_nsec
= tswapl(host_ts
->tv_nsec
);
2573 unlock_user_struct(target_ts
, target_addr
, 1);
2576 /* do_syscall() should always have a single exit point at the end so
2577 that actions, such as logging of syscall results, can be performed.
2578 All errnos that do_syscall() returns must be -TARGET_<errcode>. */
2579 abi_long
do_syscall(void *cpu_env
, int num
, abi_long arg1
,
2580 abi_long arg2
, abi_long arg3
, abi_long arg4
,
2581 abi_long arg5
, abi_long arg6
)
2589 gemu_log("syscall %d", num
);
2592 case TARGET_NR_exit
:
2596 gdb_exit(cpu_env
, arg1
);
2597 /* XXX: should free thread stack and CPU env */
2599 ret
= 0; /* avoid warning */
2601 case TARGET_NR_read
:
2602 page_unprotect_range(arg2
, arg3
);
2603 p
= lock_user(arg2
, arg3
, 0);
2604 ret
= get_errno(read(arg1
, p
, arg3
));
2605 unlock_user(p
, arg2
, ret
);
2607 case TARGET_NR_write
:
2608 p
= lock_user(arg2
, arg3
, 1);
2609 ret
= get_errno(write(arg1
, p
, arg3
));
2610 unlock_user(p
, arg2
, 0);
2612 case TARGET_NR_open
:
2613 p
= lock_user_string(arg1
);
2614 ret
= get_errno(open(path(p
),
2615 target_to_host_bitmask(arg2
, fcntl_flags_tbl
),
2617 unlock_user(p
, arg1
, 0);
2619 #if defined(TARGET_NR_openat) && defined(__NR_openat)
2620 case TARGET_NR_openat
:
2622 ret
= -TARGET_EFAULT
;
2625 p
= lock_user_string(arg2
);
2626 if (!access_ok(VERIFY_READ
, p
, 1))
2627 /* Don't "goto fail" so that cleanup can happen. */
2628 ret
= -TARGET_EFAULT
;
2630 ret
= get_errno(sys_openat(arg1
,
2632 target_to_host_bitmask(arg3
, fcntl_flags_tbl
),
2635 unlock_user(p
, arg2
, 0);
2638 case TARGET_NR_close
:
2639 ret
= get_errno(close(arg1
));
2644 case TARGET_NR_fork
:
2645 ret
= get_errno(do_fork(cpu_env
, SIGCHLD
, 0));
2647 #ifdef TARGET_NR_waitpid
2648 case TARGET_NR_waitpid
:
2651 ret
= get_errno(waitpid(arg1
, &status
, arg3
));
2652 if (!is_error(ret
) && arg2
)
2653 tput32(arg2
, status
);
2657 #ifdef TARGET_NR_creat /* not on alpha */
2658 case TARGET_NR_creat
:
2659 p
= lock_user_string(arg1
);
2660 ret
= get_errno(creat(p
, arg2
));
2661 unlock_user(p
, arg1
, 0);
2664 case TARGET_NR_link
:
2667 p
= lock_user_string(arg1
);
2668 p2
= lock_user_string(arg2
);
2669 ret
= get_errno(link(p
, p2
));
2670 unlock_user(p2
, arg2
, 0);
2671 unlock_user(p
, arg1
, 0);
2674 #if defined(TARGET_NR_linkat) && defined(__NR_linkat)
2675 case TARGET_NR_linkat
:
2676 if (!arg2
|| !arg4
) {
2677 ret
= -TARGET_EFAULT
;
2682 p
= lock_user_string(arg2
);
2683 p2
= lock_user_string(arg4
);
2684 if (!access_ok(VERIFY_READ
, p
, 1)
2685 || !access_ok(VERIFY_READ
, p2
, 1))
2686 /* Don't "goto fail" so that cleanup can happen. */
2687 ret
= -TARGET_EFAULT
;
2689 ret
= get_errno(sys_linkat(arg1
, p
, arg3
, p2
, arg5
));
2691 unlock_user(p
, arg2
, 0);
2693 unlock_user(p2
, arg4
, 0);
2697 case TARGET_NR_unlink
:
2698 p
= lock_user_string(arg1
);
2699 ret
= get_errno(unlink(p
));
2700 unlock_user(p
, arg1
, 0);
2702 #if defined(TARGET_NR_unlinkat) && defined(__NR_unlinkat)
2703 case TARGET_NR_unlinkat
:
2705 ret
= -TARGET_EFAULT
;
2708 p
= lock_user_string(arg2
);
2709 if (!access_ok(VERIFY_READ
, p
, 1))
2710 /* Don't "goto fail" so that cleanup can happen. */
2711 ret
= -TARGET_EFAULT
;
2713 ret
= get_errno(sys_unlinkat(arg1
, p
, arg3
));
2715 unlock_user(p
, arg2
, 0);
2718 case TARGET_NR_execve
:
2720 char **argp
, **envp
;
2723 abi_ulong guest_argp
;
2724 abi_ulong guest_envp
;
2730 for (gp
= guest_argp
; tgetl(gp
); gp
++)
2734 for (gp
= guest_envp
; tgetl(gp
); gp
++)
2737 argp
= alloca((argc
+ 1) * sizeof(void *));
2738 envp
= alloca((envc
+ 1) * sizeof(void *));
2740 for (gp
= guest_argp
, q
= argp
; ;
2741 gp
+= sizeof(abi_ulong
), q
++) {
2745 *q
= lock_user_string(addr
);
2749 for (gp
= guest_envp
, q
= envp
; ;
2750 gp
+= sizeof(abi_ulong
), q
++) {
2754 *q
= lock_user_string(addr
);
2758 p
= lock_user_string(arg1
);
2759 ret
= get_errno(execve(p
, argp
, envp
));
2760 unlock_user(p
, arg1
, 0);
2762 for (gp
= guest_argp
, q
= argp
; *q
;
2763 gp
+= sizeof(abi_ulong
), q
++) {
2765 unlock_user(*q
, addr
, 0);
2767 for (gp
= guest_envp
, q
= envp
; *q
;
2768 gp
+= sizeof(abi_ulong
), q
++) {
2770 unlock_user(*q
, addr
, 0);
2774 case TARGET_NR_chdir
:
2775 p
= lock_user_string(arg1
);
2776 ret
= get_errno(chdir(p
));
2777 unlock_user(p
, arg1
, 0);
2779 #ifdef TARGET_NR_time
2780 case TARGET_NR_time
:
2783 ret
= get_errno(time(&host_time
));
2784 if (!is_error(ret
) && arg1
)
2785 tputl(arg1
, host_time
);
2789 case TARGET_NR_mknod
:
2790 p
= lock_user_string(arg1
);
2791 ret
= get_errno(mknod(p
, arg2
, arg3
));
2792 unlock_user(p
, arg1
, 0);
2794 #if defined(TARGET_NR_mknodat) && defined(__NR_mknodat)
2795 case TARGET_NR_mknodat
:
2797 ret
= -TARGET_EFAULT
;
2800 p
= lock_user_string(arg2
);
2801 if (!access_ok(VERIFY_READ
, p
, 1))
2802 /* Don't "goto fail" so that cleanup can happen. */
2803 ret
= -TARGET_EFAULT
;
2805 ret
= get_errno(sys_mknodat(arg1
, p
, arg3
, arg4
));
2807 unlock_user(p
, arg2
, 0);
2810 case TARGET_NR_chmod
:
2811 p
= lock_user_string(arg1
);
2812 ret
= get_errno(chmod(p
, arg2
));
2813 unlock_user(p
, arg1
, 0);
2815 #ifdef TARGET_NR_break
2816 case TARGET_NR_break
:
2819 #ifdef TARGET_NR_oldstat
2820 case TARGET_NR_oldstat
:
2823 case TARGET_NR_lseek
:
2824 ret
= get_errno(lseek(arg1
, arg2
, arg3
));
2826 #ifdef TARGET_NR_getxpid
2827 case TARGET_NR_getxpid
:
2829 case TARGET_NR_getpid
:
2831 ret
= get_errno(getpid());
2833 case TARGET_NR_mount
:
2835 /* need to look at the data field */
2837 p
= lock_user_string(arg1
);
2838 p2
= lock_user_string(arg2
);
2839 p3
= lock_user_string(arg3
);
2840 ret
= get_errno(mount(p
, p2
, p3
, (unsigned long)arg4
, (const void *)arg5
));
2841 unlock_user(p
, arg1
, 0);
2842 unlock_user(p2
, arg2
, 0);
2843 unlock_user(p3
, arg3
, 0);
2846 #ifdef TARGET_NR_umount
2847 case TARGET_NR_umount
:
2848 p
= lock_user_string(arg1
);
2849 ret
= get_errno(umount(p
));
2850 unlock_user(p
, arg1
, 0);
2853 #ifdef TARGET_NR_stime /* not on alpha */
2854 case TARGET_NR_stime
:
2857 host_time
= tgetl(arg1
);
2858 ret
= get_errno(stime(&host_time
));
2862 case TARGET_NR_ptrace
:
2864 #ifdef TARGET_NR_alarm /* not on alpha */
2865 case TARGET_NR_alarm
:
2869 #ifdef TARGET_NR_oldfstat
2870 case TARGET_NR_oldfstat
:
2873 #ifdef TARGET_NR_pause /* not on alpha */
2874 case TARGET_NR_pause
:
2875 ret
= get_errno(pause());
2878 #ifdef TARGET_NR_utime
2879 case TARGET_NR_utime
:
2881 struct utimbuf tbuf
, *host_tbuf
;
2882 struct target_utimbuf
*target_tbuf
;
2884 lock_user_struct(target_tbuf
, arg2
, 1);
2885 tbuf
.actime
= tswapl(target_tbuf
->actime
);
2886 tbuf
.modtime
= tswapl(target_tbuf
->modtime
);
2887 unlock_user_struct(target_tbuf
, arg2
, 0);
2892 p
= lock_user_string(arg1
);
2893 ret
= get_errno(utime(p
, host_tbuf
));
2894 unlock_user(p
, arg1
, 0);
2898 case TARGET_NR_utimes
:
2900 struct timeval
*tvp
, tv
[2];
2902 target_to_host_timeval(&tv
[0], arg2
);
2903 target_to_host_timeval(&tv
[1],
2904 arg2
+ sizeof (struct target_timeval
));
2909 p
= lock_user_string(arg1
);
2910 ret
= get_errno(utimes(p
, tvp
));
2911 unlock_user(p
, arg1
, 0);
2914 #ifdef TARGET_NR_stty
2915 case TARGET_NR_stty
:
2918 #ifdef TARGET_NR_gtty
2919 case TARGET_NR_gtty
:
2922 case TARGET_NR_access
:
2923 p
= lock_user_string(arg1
);
2924 ret
= get_errno(access(p
, arg2
));
2925 unlock_user(p
, arg1
, 0);
2927 #if defined(TARGET_NR_faccessat) && defined(__NR_faccessat)
2928 case TARGET_NR_faccessat
:
2930 ret
= -TARGET_EFAULT
;
2933 p
= lock_user_string(arg2
);
2934 if (!access_ok(VERIFY_READ
, p
, 1))
2935 /* Don't "goto fail" so that cleanup can happen. */
2936 ret
= -TARGET_EFAULT
;
2938 ret
= get_errno(sys_faccessat(arg1
, p
, arg3
, arg4
));
2940 unlock_user(p
, arg2
, 0);
2943 #ifdef TARGET_NR_nice /* not on alpha */
2944 case TARGET_NR_nice
:
2945 ret
= get_errno(nice(arg1
));
2948 #ifdef TARGET_NR_ftime
2949 case TARGET_NR_ftime
:
2952 case TARGET_NR_sync
:
2956 case TARGET_NR_kill
:
2957 ret
= get_errno(kill(arg1
, arg2
));
2959 case TARGET_NR_rename
:
2962 p
= lock_user_string(arg1
);
2963 p2
= lock_user_string(arg2
);
2964 ret
= get_errno(rename(p
, p2
));
2965 unlock_user(p2
, arg2
, 0);
2966 unlock_user(p
, arg1
, 0);
2969 #if defined(TARGET_NR_renameat) && defined(__NR_renameat)
2970 case TARGET_NR_renameat
:
2971 if (!arg2
|| !arg4
) {
2972 ret
= -TARGET_EFAULT
;
2977 p
= lock_user_string(arg2
);
2978 p2
= lock_user_string(arg4
);
2979 if (!access_ok(VERIFY_READ
, p
, 1)
2980 || !access_ok(VERIFY_READ
, p2
, 1))
2981 /* Don't "goto fail" so that cleanup can happen. */
2982 ret
= -TARGET_EFAULT
;
2984 ret
= get_errno(sys_renameat(arg1
, p
, arg3
, p2
));
2986 unlock_user(p2
, arg4
, 0);
2988 unlock_user(p
, arg2
, 0);
2992 case TARGET_NR_mkdir
:
2993 p
= lock_user_string(arg1
);
2994 ret
= get_errno(mkdir(p
, arg2
));
2995 unlock_user(p
, arg1
, 0);
2997 #if defined(TARGET_NR_mkdirat) && defined(__NR_mkdirat)
2998 case TARGET_NR_mkdirat
:
3000 ret
= -TARGET_EFAULT
;
3003 p
= lock_user_string(arg2
);
3004 if (!access_ok(VERIFY_READ
, p
, 1))
3005 /* Don't "goto fail" so that cleanup can happen. */
3006 ret
= -TARGET_EFAULT
;
3008 ret
= get_errno(sys_mkdirat(arg1
, p
, arg3
));
3010 unlock_user(p
, arg2
, 0);
3013 case TARGET_NR_rmdir
:
3014 p
= lock_user_string(arg1
);
3015 ret
= get_errno(rmdir(p
));
3016 unlock_user(p
, arg1
, 0);
3019 ret
= get_errno(dup(arg1
));
3021 case TARGET_NR_pipe
:
3024 ret
= get_errno(pipe(host_pipe
));
3025 if (!is_error(ret
)) {
3026 #if defined(TARGET_MIPS)
3027 CPUMIPSState
*env
= (CPUMIPSState
*)cpu_env
;
3028 env
->gpr
[3][env
->current_tc
] = host_pipe
[1];
3031 tput32(arg1
, host_pipe
[0]);
3032 tput32(arg1
+ 4, host_pipe
[1]);
3037 case TARGET_NR_times
:
3039 struct target_tms
*tmsp
;
3041 ret
= get_errno(times(&tms
));
3043 tmsp
= lock_user(arg1
, sizeof(struct target_tms
), 0);
3044 tmsp
->tms_utime
= tswapl(host_to_target_clock_t(tms
.tms_utime
));
3045 tmsp
->tms_stime
= tswapl(host_to_target_clock_t(tms
.tms_stime
));
3046 tmsp
->tms_cutime
= tswapl(host_to_target_clock_t(tms
.tms_cutime
));
3047 tmsp
->tms_cstime
= tswapl(host_to_target_clock_t(tms
.tms_cstime
));
3050 ret
= host_to_target_clock_t(ret
);
3053 #ifdef TARGET_NR_prof
3054 case TARGET_NR_prof
:
3057 #ifdef TARGET_NR_signal
3058 case TARGET_NR_signal
:
3061 case TARGET_NR_acct
:
3062 p
= lock_user_string(arg1
);
3063 ret
= get_errno(acct(path(p
)));
3064 unlock_user(p
, arg1
, 0);
3066 #ifdef TARGET_NR_umount2 /* not on alpha */
3067 case TARGET_NR_umount2
:
3068 p
= lock_user_string(arg1
);
3069 ret
= get_errno(umount2(p
, arg2
));
3070 unlock_user(p
, arg1
, 0);
3073 #ifdef TARGET_NR_lock
3074 case TARGET_NR_lock
:
3077 case TARGET_NR_ioctl
:
3078 ret
= do_ioctl(arg1
, arg2
, arg3
);
3080 case TARGET_NR_fcntl
:
3081 ret
= get_errno(do_fcntl(arg1
, arg2
, arg3
));
3083 #ifdef TARGET_NR_mpx
3087 case TARGET_NR_setpgid
:
3088 ret
= get_errno(setpgid(arg1
, arg2
));
3090 #ifdef TARGET_NR_ulimit
3091 case TARGET_NR_ulimit
:
3094 #ifdef TARGET_NR_oldolduname
3095 case TARGET_NR_oldolduname
:
3098 case TARGET_NR_umask
:
3099 ret
= get_errno(umask(arg1
));
3101 case TARGET_NR_chroot
:
3102 p
= lock_user_string(arg1
);
3103 ret
= get_errno(chroot(p
));
3104 unlock_user(p
, arg1
, 0);
3106 case TARGET_NR_ustat
:
3108 case TARGET_NR_dup2
:
3109 ret
= get_errno(dup2(arg1
, arg2
));
3111 #ifdef TARGET_NR_getppid /* not on alpha */
3112 case TARGET_NR_getppid
:
3113 ret
= get_errno(getppid());
3116 case TARGET_NR_getpgrp
:
3117 ret
= get_errno(getpgrp());
3119 case TARGET_NR_setsid
:
3120 ret
= get_errno(setsid());
3122 #ifdef TARGET_NR_sigaction
3123 case TARGET_NR_sigaction
:
3125 #if !defined(TARGET_MIPS)
3126 struct target_old_sigaction
*old_act
;
3127 struct target_sigaction act
, oact
, *pact
;
3129 lock_user_struct(old_act
, arg2
, 1);
3130 act
._sa_handler
= old_act
->_sa_handler
;
3131 target_siginitset(&act
.sa_mask
, old_act
->sa_mask
);
3132 act
.sa_flags
= old_act
->sa_flags
;
3133 act
.sa_restorer
= old_act
->sa_restorer
;
3134 unlock_user_struct(old_act
, arg2
, 0);
3139 ret
= get_errno(do_sigaction(arg1
, pact
, &oact
));
3140 if (!is_error(ret
) && arg3
) {
3141 lock_user_struct(old_act
, arg3
, 0);
3142 old_act
->_sa_handler
= oact
._sa_handler
;
3143 old_act
->sa_mask
= oact
.sa_mask
.sig
[0];
3144 old_act
->sa_flags
= oact
.sa_flags
;
3145 old_act
->sa_restorer
= oact
.sa_restorer
;
3146 unlock_user_struct(old_act
, arg3
, 1);
3149 struct target_sigaction act
, oact
, *pact
, *old_act
;
3152 lock_user_struct(old_act
, arg2
, 1);
3153 act
._sa_handler
= old_act
->_sa_handler
;
3154 target_siginitset(&act
.sa_mask
, old_act
->sa_mask
.sig
[0]);
3155 act
.sa_flags
= old_act
->sa_flags
;
3156 unlock_user_struct(old_act
, arg2
, 0);
3162 ret
= get_errno(do_sigaction(arg1
, pact
, &oact
));
3164 if (!is_error(ret
) && arg3
) {
3165 lock_user_struct(old_act
, arg3
, 0);
3166 old_act
->_sa_handler
= oact
._sa_handler
;
3167 old_act
->sa_flags
= oact
.sa_flags
;
3168 old_act
->sa_mask
.sig
[0] = oact
.sa_mask
.sig
[0];
3169 old_act
->sa_mask
.sig
[1] = 0;
3170 old_act
->sa_mask
.sig
[2] = 0;
3171 old_act
->sa_mask
.sig
[3] = 0;
3172 unlock_user_struct(old_act
, arg3
, 1);
3178 case TARGET_NR_rt_sigaction
:
3180 struct target_sigaction
*act
;
3181 struct target_sigaction
*oact
;
3184 lock_user_struct(act
, arg2
, 1);
3188 lock_user_struct(oact
, arg3
, 0);
3191 ret
= get_errno(do_sigaction(arg1
, act
, oact
));
3193 unlock_user_struct(act
, arg2
, 0);
3195 unlock_user_struct(oact
, arg3
, 1);
3198 #ifdef TARGET_NR_sgetmask /* not on alpha */
3199 case TARGET_NR_sgetmask
:
3202 abi_ulong target_set
;
3203 sigprocmask(0, NULL
, &cur_set
);
3204 host_to_target_old_sigset(&target_set
, &cur_set
);
3209 #ifdef TARGET_NR_ssetmask /* not on alpha */
3210 case TARGET_NR_ssetmask
:
3212 sigset_t set
, oset
, cur_set
;
3213 abi_ulong target_set
= arg1
;
3214 sigprocmask(0, NULL
, &cur_set
);
3215 target_to_host_old_sigset(&set
, &target_set
);
3216 sigorset(&set
, &set
, &cur_set
);
3217 sigprocmask(SIG_SETMASK
, &set
, &oset
);
3218 host_to_target_old_sigset(&target_set
, &oset
);
3223 #ifdef TARGET_NR_sigprocmask
3224 case TARGET_NR_sigprocmask
:
3227 sigset_t set
, oldset
, *set_ptr
;
3231 case TARGET_SIG_BLOCK
:
3234 case TARGET_SIG_UNBLOCK
:
3237 case TARGET_SIG_SETMASK
:
3241 ret
= -TARGET_EINVAL
;
3244 p
= lock_user(arg2
, sizeof(target_sigset_t
), 1);
3245 target_to_host_old_sigset(&set
, p
);
3246 unlock_user(p
, arg2
, 0);
3252 ret
= get_errno(sigprocmask(arg1
, set_ptr
, &oldset
));
3253 if (!is_error(ret
) && arg3
) {
3254 p
= lock_user(arg3
, sizeof(target_sigset_t
), 0);
3255 host_to_target_old_sigset(p
, &oldset
);
3256 unlock_user(p
, arg3
, sizeof(target_sigset_t
));
3261 case TARGET_NR_rt_sigprocmask
:
3264 sigset_t set
, oldset
, *set_ptr
;
3268 case TARGET_SIG_BLOCK
:
3271 case TARGET_SIG_UNBLOCK
:
3274 case TARGET_SIG_SETMASK
:
3278 ret
= -TARGET_EINVAL
;
3281 p
= lock_user(arg2
, sizeof(target_sigset_t
), 1);
3282 target_to_host_sigset(&set
, p
);
3283 unlock_user(p
, arg2
, 0);
3289 ret
= get_errno(sigprocmask(how
, set_ptr
, &oldset
));
3290 if (!is_error(ret
) && arg3
) {
3291 p
= lock_user(arg3
, sizeof(target_sigset_t
), 0);
3292 host_to_target_sigset(p
, &oldset
);
3293 unlock_user(p
, arg3
, sizeof(target_sigset_t
));
3297 #ifdef TARGET_NR_sigpending
3298 case TARGET_NR_sigpending
:
3301 ret
= get_errno(sigpending(&set
));
3302 if (!is_error(ret
)) {
3303 p
= lock_user(arg1
, sizeof(target_sigset_t
), 0);
3304 host_to_target_old_sigset(p
, &set
);
3305 unlock_user(p
, arg1
, sizeof(target_sigset_t
));
3310 case TARGET_NR_rt_sigpending
:
3313 ret
= get_errno(sigpending(&set
));
3314 if (!is_error(ret
)) {
3315 p
= lock_user(arg1
, sizeof(target_sigset_t
), 0);
3316 host_to_target_sigset(p
, &set
);
3317 unlock_user(p
, arg1
, sizeof(target_sigset_t
));
3321 #ifdef TARGET_NR_sigsuspend
3322 case TARGET_NR_sigsuspend
:
3325 p
= lock_user(arg1
, sizeof(target_sigset_t
), 1);
3326 target_to_host_old_sigset(&set
, p
);
3327 unlock_user(p
, arg1
, 0);
3328 ret
= get_errno(sigsuspend(&set
));
3332 case TARGET_NR_rt_sigsuspend
:
3335 p
= lock_user(arg1
, sizeof(target_sigset_t
), 1);
3336 target_to_host_sigset(&set
, p
);
3337 unlock_user(p
, arg1
, 0);
3338 ret
= get_errno(sigsuspend(&set
));
3341 case TARGET_NR_rt_sigtimedwait
:
3344 struct timespec uts
, *puts
;
3347 p
= lock_user(arg1
, sizeof(target_sigset_t
), 1);
3348 target_to_host_sigset(&set
, p
);
3349 unlock_user(p
, arg1
, 0);
3352 target_to_host_timespec(puts
, arg3
);
3356 ret
= get_errno(sigtimedwait(&set
, &uinfo
, puts
));
3357 if (!is_error(ret
) && arg2
) {
3358 p
= lock_user(arg2
, sizeof(target_sigset_t
), 0);
3359 host_to_target_siginfo(p
, &uinfo
);
3360 unlock_user(p
, arg2
, sizeof(target_sigset_t
));
3364 case TARGET_NR_rt_sigqueueinfo
:
3367 p
= lock_user(arg3
, sizeof(target_sigset_t
), 1);
3368 target_to_host_siginfo(&uinfo
, p
);
3369 unlock_user(p
, arg1
, 0);
3370 ret
= get_errno(sys_rt_sigqueueinfo(arg1
, arg2
, &uinfo
));
3373 #ifdef TARGET_NR_sigreturn
3374 case TARGET_NR_sigreturn
:
3375 /* NOTE: ret is eax, so not transcoding must be done */
3376 ret
= do_sigreturn(cpu_env
);
3379 case TARGET_NR_rt_sigreturn
:
3380 /* NOTE: ret is eax, so not transcoding must be done */
3381 ret
= do_rt_sigreturn(cpu_env
);
3383 case TARGET_NR_sethostname
:
3384 p
= lock_user_string(arg1
);
3385 ret
= get_errno(sethostname(p
, arg2
));
3386 unlock_user(p
, arg1
, 0);
3388 case TARGET_NR_setrlimit
:
3390 /* XXX: convert resource ? */
3391 int resource
= arg1
;
3392 struct target_rlimit
*target_rlim
;
3394 lock_user_struct(target_rlim
, arg2
, 1);
3395 rlim
.rlim_cur
= tswapl(target_rlim
->rlim_cur
);
3396 rlim
.rlim_max
= tswapl(target_rlim
->rlim_max
);
3397 unlock_user_struct(target_rlim
, arg2
, 0);
3398 ret
= get_errno(setrlimit(resource
, &rlim
));
3401 case TARGET_NR_getrlimit
:
3403 /* XXX: convert resource ? */
3404 int resource
= arg1
;
3405 struct target_rlimit
*target_rlim
;
3408 ret
= get_errno(getrlimit(resource
, &rlim
));
3409 if (!is_error(ret
)) {
3410 lock_user_struct(target_rlim
, arg2
, 0);
3411 rlim
.rlim_cur
= tswapl(target_rlim
->rlim_cur
);
3412 rlim
.rlim_max
= tswapl(target_rlim
->rlim_max
);
3413 unlock_user_struct(target_rlim
, arg2
, 1);
3417 case TARGET_NR_getrusage
:
3419 struct rusage rusage
;
3420 ret
= get_errno(getrusage(arg1
, &rusage
));
3421 if (!is_error(ret
)) {
3422 host_to_target_rusage(arg2
, &rusage
);
3426 case TARGET_NR_gettimeofday
:
3429 ret
= get_errno(gettimeofday(&tv
, NULL
));
3430 if (!is_error(ret
)) {
3431 host_to_target_timeval(arg1
, &tv
);
3435 case TARGET_NR_settimeofday
:
3438 target_to_host_timeval(&tv
, arg1
);
3439 ret
= get_errno(settimeofday(&tv
, NULL
));
3442 #ifdef TARGET_NR_select
3443 case TARGET_NR_select
:
3445 struct target_sel_arg_struct
*sel
;
3446 abi_ulong inp
, outp
, exp
, tvp
;
3449 lock_user_struct(sel
, arg1
, 1);
3450 nsel
= tswapl(sel
->n
);
3451 inp
= tswapl(sel
->inp
);
3452 outp
= tswapl(sel
->outp
);
3453 exp
= tswapl(sel
->exp
);
3454 tvp
= tswapl(sel
->tvp
);
3455 unlock_user_struct(sel
, arg1
, 0);
3456 ret
= do_select(nsel
, inp
, outp
, exp
, tvp
);
3460 case TARGET_NR_symlink
:
3463 p
= lock_user_string(arg1
);
3464 p2
= lock_user_string(arg2
);
3465 ret
= get_errno(symlink(p
, p2
));
3466 unlock_user(p2
, arg2
, 0);
3467 unlock_user(p
, arg1
, 0);
3470 #if defined(TARGET_NR_symlinkat) && defined(__NR_symlinkat)
3471 case TARGET_NR_symlinkat
:
3472 if (!arg1
|| !arg3
) {
3473 ret
= -TARGET_EFAULT
;
3478 p
= lock_user_string(arg1
);
3479 p2
= lock_user_string(arg3
);
3480 if (!access_ok(VERIFY_READ
, p
, 1)
3481 || !access_ok(VERIFY_READ
, p2
, 1))
3482 /* Don't "goto fail" so that cleanup can happen. */
3483 ret
= -TARGET_EFAULT
;
3485 ret
= get_errno(sys_symlinkat(p
, arg2
, p2
));
3487 unlock_user(p2
, arg3
, 0);
3489 unlock_user(p
, arg1
, 0);
3493 #ifdef TARGET_NR_oldlstat
3494 case TARGET_NR_oldlstat
:
3497 case TARGET_NR_readlink
:
3500 p
= lock_user_string(arg1
);
3501 p2
= lock_user(arg2
, arg3
, 0);
3502 ret
= get_errno(readlink(path(p
), p2
, arg3
));
3503 unlock_user(p2
, arg2
, ret
);
3504 unlock_user(p
, arg1
, 0);
3507 #if defined(TARGET_NR_readlinkat) && defined(__NR_readlinkat)
3508 case TARGET_NR_readlinkat
:
3509 if (!arg2
|| !arg3
) {
3510 ret
= -TARGET_EFAULT
;
3515 p
= lock_user_string(arg2
);
3516 p2
= lock_user(arg3
, arg4
, 0);
3517 if (!access_ok(VERIFY_READ
, p
, 1)
3518 || !access_ok(VERIFY_READ
, p2
, 1))
3519 /* Don't "goto fail" so that cleanup can happen. */
3520 ret
= -TARGET_EFAULT
;
3522 ret
= get_errno(sys_readlinkat(arg1
, path(p
), p2
, arg4
));
3524 unlock_user(p2
, arg3
, ret
);
3526 unlock_user(p
, arg2
, 0);
3530 #ifdef TARGET_NR_uselib
3531 case TARGET_NR_uselib
:
3534 #ifdef TARGET_NR_swapon
3535 case TARGET_NR_swapon
:
3536 p
= lock_user_string(arg1
);
3537 ret
= get_errno(swapon(p
, arg2
));
3538 unlock_user(p
, arg1
, 0);
3541 case TARGET_NR_reboot
:
3543 #ifdef TARGET_NR_readdir
3544 case TARGET_NR_readdir
:
3547 #ifdef TARGET_NR_mmap
3548 case TARGET_NR_mmap
:
3549 #if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_M68K) || defined(TARGET_CRIS)
3552 abi_ulong v1
, v2
, v3
, v4
, v5
, v6
;
3553 v
= lock_user(arg1
, 6 * sizeof(abi_ulong
), 1);
3560 unlock_user(v
, arg1
, 0);
3561 ret
= get_errno(target_mmap(v1
, v2
, v3
,
3562 target_to_host_bitmask(v4
, mmap_flags_tbl
),
3566 ret
= get_errno(target_mmap(arg1
, arg2
, arg3
,
3567 target_to_host_bitmask(arg4
, mmap_flags_tbl
),
3573 #ifdef TARGET_NR_mmap2
3574 case TARGET_NR_mmap2
:
3575 #if defined(TARGET_SPARC) || defined(TARGET_MIPS)
3576 #define MMAP_SHIFT 12
3578 #define MMAP_SHIFT TARGET_PAGE_BITS
3580 ret
= get_errno(target_mmap(arg1
, arg2
, arg3
,
3581 target_to_host_bitmask(arg4
, mmap_flags_tbl
),
3583 arg6
<< MMAP_SHIFT
));
3586 case TARGET_NR_munmap
:
3587 ret
= get_errno(target_munmap(arg1
, arg2
));
3589 case TARGET_NR_mprotect
:
3590 ret
= get_errno(target_mprotect(arg1
, arg2
, arg3
));
3592 #ifdef TARGET_NR_mremap
3593 case TARGET_NR_mremap
:
3594 ret
= get_errno(target_mremap(arg1
, arg2
, arg3
, arg4
, arg5
));
3597 /* ??? msync/mlock/munlock are broken for softmmu. */
3598 #ifdef TARGET_NR_msync
3599 case TARGET_NR_msync
:
3600 ret
= get_errno(msync(g2h(arg1
), arg2
, arg3
));
3603 #ifdef TARGET_NR_mlock
3604 case TARGET_NR_mlock
:
3605 ret
= get_errno(mlock(g2h(arg1
), arg2
));
3608 #ifdef TARGET_NR_munlock
3609 case TARGET_NR_munlock
:
3610 ret
= get_errno(munlock(g2h(arg1
), arg2
));
3613 #ifdef TARGET_NR_mlockall
3614 case TARGET_NR_mlockall
:
3615 ret
= get_errno(mlockall(arg1
));
3618 #ifdef TARGET_NR_munlockall
3619 case TARGET_NR_munlockall
:
3620 ret
= get_errno(munlockall());
3623 case TARGET_NR_truncate
:
3624 p
= lock_user_string(arg1
);
3625 ret
= get_errno(truncate(p
, arg2
));
3626 unlock_user(p
, arg1
, 0);
3628 case TARGET_NR_ftruncate
:
3629 ret
= get_errno(ftruncate(arg1
, arg2
));
3631 case TARGET_NR_fchmod
:
3632 ret
= get_errno(fchmod(arg1
, arg2
));
3634 #if defined(TARGET_NR_fchmodat) && defined(__NR_fchmodat)
3635 case TARGET_NR_fchmodat
:
3637 ret
= -TARGET_EFAULT
;
3640 p
= lock_user_string(arg2
);
3641 if (!access_ok(VERIFY_READ
, p
, 1))
3642 /* Don't "goto fail" so that cleanup can happen. */
3643 ret
= -TARGET_EFAULT
;
3645 ret
= get_errno(sys_fchmodat(arg1
, p
, arg3
, arg4
));
3647 unlock_user(p
, arg2
, 0);
3650 case TARGET_NR_getpriority
:
3651 /* libc does special remapping of the return value of
3652 * sys_getpriority() so it's just easiest to call
3653 * sys_getpriority() directly rather than through libc. */
3654 ret
= sys_getpriority(arg1
, arg2
);
3656 case TARGET_NR_setpriority
:
3657 ret
= get_errno(setpriority(arg1
, arg2
, arg3
));
3659 #ifdef TARGET_NR_profil
3660 case TARGET_NR_profil
:
3663 case TARGET_NR_statfs
:
3664 p
= lock_user_string(arg1
);
3665 ret
= get_errno(statfs(path(p
), &stfs
));
3666 unlock_user(p
, arg1
, 0);
3668 if (!is_error(ret
)) {
3669 struct target_statfs
*target_stfs
;
3671 lock_user_struct(target_stfs
, arg2
, 0);
3672 /* ??? put_user is probably wrong. */
3673 put_user(stfs
.f_type
, &target_stfs
->f_type
);
3674 put_user(stfs
.f_bsize
, &target_stfs
->f_bsize
);
3675 put_user(stfs
.f_blocks
, &target_stfs
->f_blocks
);
3676 put_user(stfs
.f_bfree
, &target_stfs
->f_bfree
);
3677 put_user(stfs
.f_bavail
, &target_stfs
->f_bavail
);
3678 put_user(stfs
.f_files
, &target_stfs
->f_files
);
3679 put_user(stfs
.f_ffree
, &target_stfs
->f_ffree
);
3680 put_user(stfs
.f_fsid
.__val
[0], &target_stfs
->f_fsid
.val
[0]);
3681 put_user(stfs
.f_fsid
.__val
[1], &target_stfs
->f_fsid
.val
[1]);
3682 put_user(stfs
.f_namelen
, &target_stfs
->f_namelen
);
3683 unlock_user_struct(target_stfs
, arg2
, 1);
3686 case TARGET_NR_fstatfs
:
3687 ret
= get_errno(fstatfs(arg1
, &stfs
));
3688 goto convert_statfs
;
3689 #ifdef TARGET_NR_statfs64
3690 case TARGET_NR_statfs64
:
3691 p
= lock_user_string(arg1
);
3692 ret
= get_errno(statfs(path(p
), &stfs
));
3693 unlock_user(p
, arg1
, 0);
3695 if (!is_error(ret
)) {
3696 struct target_statfs64
*target_stfs
;
3698 lock_user_struct(target_stfs
, arg3
, 0);
3699 /* ??? put_user is probably wrong. */
3700 put_user(stfs
.f_type
, &target_stfs
->f_type
);
3701 put_user(stfs
.f_bsize
, &target_stfs
->f_bsize
);
3702 put_user(stfs
.f_blocks
, &target_stfs
->f_blocks
);
3703 put_user(stfs
.f_bfree
, &target_stfs
->f_bfree
);
3704 put_user(stfs
.f_bavail
, &target_stfs
->f_bavail
);
3705 put_user(stfs
.f_files
, &target_stfs
->f_files
);
3706 put_user(stfs
.f_ffree
, &target_stfs
->f_ffree
);
3707 put_user(stfs
.f_fsid
.__val
[0], &target_stfs
->f_fsid
.val
[0]);
3708 put_user(stfs
.f_fsid
.__val
[1], &target_stfs
->f_fsid
.val
[1]);
3709 put_user(stfs
.f_namelen
, &target_stfs
->f_namelen
);
3710 unlock_user_struct(target_stfs
, arg3
, 0);
3713 case TARGET_NR_fstatfs64
:
3714 ret
= get_errno(fstatfs(arg1
, &stfs
));
3715 goto convert_statfs64
;
3717 #ifdef TARGET_NR_ioperm
3718 case TARGET_NR_ioperm
:
3721 #ifdef TARGET_NR_socketcall
3722 case TARGET_NR_socketcall
:
3723 ret
= do_socketcall(arg1
, arg2
);
3726 #ifdef TARGET_NR_accept
3727 case TARGET_NR_accept
:
3728 ret
= do_accept(arg1
, arg2
, arg3
);
3731 #ifdef TARGET_NR_bind
3732 case TARGET_NR_bind
:
3733 ret
= do_bind(arg1
, arg2
, arg3
);
3736 #ifdef TARGET_NR_connect
3737 case TARGET_NR_connect
:
3738 ret
= do_connect(arg1
, arg2
, arg3
);
3741 #ifdef TARGET_NR_getpeername
3742 case TARGET_NR_getpeername
:
3743 ret
= do_getpeername(arg1
, arg2
, arg3
);
3746 #ifdef TARGET_NR_getsockname
3747 case TARGET_NR_getsockname
:
3748 ret
= do_getsockname(arg1
, arg2
, arg3
);
3751 #ifdef TARGET_NR_getsockopt
3752 case TARGET_NR_getsockopt
:
3753 ret
= do_getsockopt(arg1
, arg2
, arg3
, arg4
, arg5
);
3756 #ifdef TARGET_NR_listen
3757 case TARGET_NR_listen
:
3758 ret
= get_errno(listen(arg1
, arg2
));
3761 #ifdef TARGET_NR_recv
3762 case TARGET_NR_recv
:
3763 ret
= do_recvfrom(arg1
, arg2
, arg3
, arg4
, 0, 0);
3766 #ifdef TARGET_NR_recvfrom
3767 case TARGET_NR_recvfrom
:
3768 ret
= do_recvfrom(arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
3771 #ifdef TARGET_NR_recvmsg
3772 case TARGET_NR_recvmsg
:
3773 ret
= do_sendrecvmsg(arg1
, arg2
, arg3
, 0);
3776 #ifdef TARGET_NR_send
3777 case TARGET_NR_send
:
3778 ret
= do_sendto(arg1
, arg2
, arg3
, arg4
, 0, 0);
3781 #ifdef TARGET_NR_sendmsg
3782 case TARGET_NR_sendmsg
:
3783 ret
= do_sendrecvmsg(arg1
, arg2
, arg3
, 1);
3786 #ifdef TARGET_NR_sendto
3787 case TARGET_NR_sendto
:
3788 ret
= do_sendto(arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
3791 #ifdef TARGET_NR_shutdown
3792 case TARGET_NR_shutdown
:
3793 ret
= get_errno(shutdown(arg1
, arg2
));
3796 #ifdef TARGET_NR_socket
3797 case TARGET_NR_socket
:
3798 ret
= do_socket(arg1
, arg2
, arg3
);
3801 #ifdef TARGET_NR_socketpair
3802 case TARGET_NR_socketpair
:
3803 ret
= do_socketpair(arg1
, arg2
, arg3
, arg4
);
3806 #ifdef TARGET_NR_setsockopt
3807 case TARGET_NR_setsockopt
:
3808 ret
= do_setsockopt(arg1
, arg2
, arg3
, arg4
, (socklen_t
) arg5
);
3812 case TARGET_NR_syslog
:
3813 p
= lock_user_string(arg2
);
3814 ret
= get_errno(sys_syslog((int)arg1
, p
, (int)arg3
));
3815 unlock_user(p
, arg2
, 0);
3818 case TARGET_NR_setitimer
:
3820 struct itimerval value
, ovalue
, *pvalue
;
3824 target_to_host_timeval(&pvalue
->it_interval
,
3826 target_to_host_timeval(&pvalue
->it_value
,
3827 arg2
+ sizeof(struct target_timeval
));
3831 ret
= get_errno(setitimer(arg1
, pvalue
, &ovalue
));
3832 if (!is_error(ret
) && arg3
) {
3833 host_to_target_timeval(arg3
,
3834 &ovalue
.it_interval
);
3835 host_to_target_timeval(arg3
+ sizeof(struct target_timeval
),
3840 case TARGET_NR_getitimer
:
3842 struct itimerval value
;
3844 ret
= get_errno(getitimer(arg1
, &value
));
3845 if (!is_error(ret
) && arg2
) {
3846 host_to_target_timeval(arg2
,
3847 &value
.it_interval
);
3848 host_to_target_timeval(arg2
+ sizeof(struct target_timeval
),
3853 case TARGET_NR_stat
:
3854 p
= lock_user_string(arg1
);
3855 ret
= get_errno(stat(path(p
), &st
));
3856 unlock_user(p
, arg1
, 0);
3858 case TARGET_NR_lstat
:
3859 p
= lock_user_string(arg1
);
3860 ret
= get_errno(lstat(path(p
), &st
));
3861 unlock_user(p
, arg1
, 0);
3863 case TARGET_NR_fstat
:
3865 ret
= get_errno(fstat(arg1
, &st
));
3867 if (!is_error(ret
)) {
3868 struct target_stat
*target_st
;
3870 lock_user_struct(target_st
, arg2
, 0);
3871 #if defined(TARGET_MIPS) || (defined(TARGET_SPARC64) && !defined(TARGET_ABI32))
3872 target_st
->st_dev
= tswap32(st
.st_dev
);
3874 target_st
->st_dev
= tswap16(st
.st_dev
);
3876 target_st
->st_ino
= tswapl(st
.st_ino
);
3877 #if defined(TARGET_PPC) || defined(TARGET_MIPS)
3878 target_st
->st_mode
= tswapl(st
.st_mode
); /* XXX: check this */
3879 target_st
->st_uid
= tswap32(st
.st_uid
);
3880 target_st
->st_gid
= tswap32(st
.st_gid
);
3881 #elif defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
3882 target_st
->st_mode
= tswap32(st
.st_mode
);
3883 target_st
->st_uid
= tswap32(st
.st_uid
);
3884 target_st
->st_gid
= tswap32(st
.st_gid
);
3886 target_st
->st_mode
= tswap16(st
.st_mode
);
3887 target_st
->st_uid
= tswap16(st
.st_uid
);
3888 target_st
->st_gid
= tswap16(st
.st_gid
);
3890 #if defined(TARGET_MIPS)
3891 /* If this is the same on PPC, then just merge w/ the above ifdef */
3892 target_st
->st_nlink
= tswapl(st
.st_nlink
);
3893 target_st
->st_rdev
= tswapl(st
.st_rdev
);
3894 #elif defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
3895 target_st
->st_nlink
= tswap32(st
.st_nlink
);
3896 target_st
->st_rdev
= tswap32(st
.st_rdev
);
3898 target_st
->st_nlink
= tswap16(st
.st_nlink
);
3899 target_st
->st_rdev
= tswap16(st
.st_rdev
);
3901 target_st
->st_size
= tswapl(st
.st_size
);
3902 target_st
->st_blksize
= tswapl(st
.st_blksize
);
3903 target_st
->st_blocks
= tswapl(st
.st_blocks
);
3904 target_st
->target_st_atime
= tswapl(st
.st_atime
);
3905 target_st
->target_st_mtime
= tswapl(st
.st_mtime
);
3906 target_st
->target_st_ctime
= tswapl(st
.st_ctime
);
3907 unlock_user_struct(target_st
, arg2
, 1);
3911 #ifdef TARGET_NR_olduname
3912 case TARGET_NR_olduname
:
3915 #ifdef TARGET_NR_iopl
3916 case TARGET_NR_iopl
:
3919 case TARGET_NR_vhangup
:
3920 ret
= get_errno(vhangup());
3922 #ifdef TARGET_NR_idle
3923 case TARGET_NR_idle
:
3926 #ifdef TARGET_NR_syscall
3927 case TARGET_NR_syscall
:
3928 ret
= do_syscall(cpu_env
,arg1
& 0xffff,arg2
,arg3
,arg4
,arg5
,arg6
,0);
3931 case TARGET_NR_wait4
:
3934 abi_long status_ptr
= arg2
;
3935 struct rusage rusage
, *rusage_ptr
;
3936 abi_ulong target_rusage
= arg4
;
3938 rusage_ptr
= &rusage
;
3941 ret
= get_errno(wait4(arg1
, &status
, arg3
, rusage_ptr
));
3942 if (!is_error(ret
)) {
3944 tputl(status_ptr
, status
);
3945 if (target_rusage
) {
3946 host_to_target_rusage(target_rusage
, &rusage
);
3951 #ifdef TARGET_NR_swapoff
3952 case TARGET_NR_swapoff
:
3953 p
= lock_user_string(arg1
);
3954 ret
= get_errno(swapoff(p
));
3955 unlock_user(p
, arg1
, 0);
3958 case TARGET_NR_sysinfo
:
3960 struct target_sysinfo
*target_value
;
3961 struct sysinfo value
;
3962 ret
= get_errno(sysinfo(&value
));
3963 if (!is_error(ret
) && arg1
)
3965 /* ??? __put_user is probably wrong. */
3966 lock_user_struct(target_value
, arg1
, 0);
3967 __put_user(value
.uptime
, &target_value
->uptime
);
3968 __put_user(value
.loads
[0], &target_value
->loads
[0]);
3969 __put_user(value
.loads
[1], &target_value
->loads
[1]);
3970 __put_user(value
.loads
[2], &target_value
->loads
[2]);
3971 __put_user(value
.totalram
, &target_value
->totalram
);
3972 __put_user(value
.freeram
, &target_value
->freeram
);
3973 __put_user(value
.sharedram
, &target_value
->sharedram
);
3974 __put_user(value
.bufferram
, &target_value
->bufferram
);
3975 __put_user(value
.totalswap
, &target_value
->totalswap
);
3976 __put_user(value
.freeswap
, &target_value
->freeswap
);
3977 __put_user(value
.procs
, &target_value
->procs
);
3978 __put_user(value
.totalhigh
, &target_value
->totalhigh
);
3979 __put_user(value
.freehigh
, &target_value
->freehigh
);
3980 __put_user(value
.mem_unit
, &target_value
->mem_unit
);
3981 unlock_user_struct(target_value
, arg1
, 1);
3985 #ifdef TARGET_NR_ipc
3987 ret
= do_ipc(arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
3990 case TARGET_NR_fsync
:
3991 ret
= get_errno(fsync(arg1
));
3993 case TARGET_NR_clone
:
3994 ret
= get_errno(do_fork(cpu_env
, arg1
, arg2
));
3996 #ifdef __NR_exit_group
3997 /* new thread calls */
3998 case TARGET_NR_exit_group
:
3999 gdb_exit(cpu_env
, arg1
);
4000 ret
= get_errno(exit_group(arg1
));
4003 case TARGET_NR_setdomainname
:
4004 p
= lock_user_string(arg1
);
4005 ret
= get_errno(setdomainname(p
, arg2
));
4006 unlock_user(p
, arg1
, 0);
4008 case TARGET_NR_uname
:
4009 /* no need to transcode because we use the linux syscall */
4011 struct new_utsname
* buf
;
4013 lock_user_struct(buf
, arg1
, 0);
4014 ret
= get_errno(sys_uname(buf
));
4015 if (!is_error(ret
)) {
4016 /* Overrite the native machine name with whatever is being
4018 strcpy (buf
->machine
, UNAME_MACHINE
);
4019 /* Allow the user to override the reported release. */
4020 if (qemu_uname_release
&& *qemu_uname_release
)
4021 strcpy (buf
->release
, qemu_uname_release
);
4023 unlock_user_struct(buf
, arg1
, 1);
4027 case TARGET_NR_modify_ldt
:
4028 ret
= get_errno(do_modify_ldt(cpu_env
, arg1
, arg2
, arg3
));
4030 #if !defined(TARGET_X86_64)
4031 case TARGET_NR_vm86old
:
4033 case TARGET_NR_vm86
:
4034 ret
= do_vm86(cpu_env
, arg1
, arg2
);
4038 case TARGET_NR_adjtimex
:
4040 #ifdef TARGET_NR_create_module
4041 case TARGET_NR_create_module
:
4043 case TARGET_NR_init_module
:
4044 case TARGET_NR_delete_module
:
4045 #ifdef TARGET_NR_get_kernel_syms
4046 case TARGET_NR_get_kernel_syms
:
4049 case TARGET_NR_quotactl
:
4051 case TARGET_NR_getpgid
:
4052 ret
= get_errno(getpgid(arg1
));
4054 case TARGET_NR_fchdir
:
4055 ret
= get_errno(fchdir(arg1
));
4057 #ifdef TARGET_NR_bdflush /* not on x86_64 */
4058 case TARGET_NR_bdflush
:
4061 #ifdef TARGET_NR_sysfs
4062 case TARGET_NR_sysfs
:
4065 case TARGET_NR_personality
:
4066 ret
= get_errno(personality(arg1
));
4068 #ifdef TARGET_NR_afs_syscall
4069 case TARGET_NR_afs_syscall
:
4072 #ifdef TARGET_NR__llseek /* Not on alpha */
4073 case TARGET_NR__llseek
:
4075 #if defined (__x86_64__)
4076 ret
= get_errno(lseek(arg1
, ((uint64_t )arg2
<< 32) | arg3
, arg5
));
4080 ret
= get_errno(_llseek(arg1
, arg2
, arg3
, &res
, arg5
));
4086 case TARGET_NR_getdents
:
4087 #if TARGET_ABI_BITS != 32
4089 #warning not supported
4090 #elif TARGET_ABI_BITS == 32 && HOST_LONG_BITS == 64
4092 struct target_dirent
*target_dirp
;
4093 struct dirent
*dirp
;
4094 abi_long count
= arg3
;
4096 dirp
= malloc(count
);
4098 ret
= -TARGET_EFAULT
;
4102 ret
= get_errno(sys_getdents(arg1
, dirp
, count
));
4103 if (!is_error(ret
)) {
4105 struct target_dirent
*tde
;
4107 int reclen
, treclen
;
4108 int count1
, tnamelen
;
4112 target_dirp
= lock_user(arg2
, count
, 0);
4115 reclen
= de
->d_reclen
;
4116 treclen
= reclen
- (2 * (sizeof(long) - sizeof(abi_long
)));
4117 tde
->d_reclen
= tswap16(treclen
);
4118 tde
->d_ino
= tswapl(de
->d_ino
);
4119 tde
->d_off
= tswapl(de
->d_off
);
4120 tnamelen
= treclen
- (2 * sizeof(abi_long
) + 2);
4123 /* XXX: may not be correct */
4124 strncpy(tde
->d_name
, de
->d_name
, tnamelen
);
4125 de
= (struct dirent
*)((char *)de
+ reclen
);
4127 tde
= (struct target_dirent
*)((char *)tde
+ treclen
);
4132 unlock_user(target_dirp
, arg2
, ret
);
4137 struct dirent
*dirp
;
4138 abi_long count
= arg3
;
4140 dirp
= lock_user(arg2
, count
, 0);
4141 ret
= get_errno(sys_getdents(arg1
, dirp
, count
));
4142 if (!is_error(ret
)) {
4148 reclen
= de
->d_reclen
;
4151 de
->d_reclen
= tswap16(reclen
);
4152 tswapls(&de
->d_ino
);
4153 tswapls(&de
->d_off
);
4154 de
= (struct dirent
*)((char *)de
+ reclen
);
4158 unlock_user(dirp
, arg2
, ret
);
4162 #if defined(TARGET_NR_getdents64) && defined(__NR_getdents64)
4163 case TARGET_NR_getdents64
:
4165 struct dirent64
*dirp
;
4166 abi_long count
= arg3
;
4167 dirp
= lock_user(arg2
, count
, 0);
4168 ret
= get_errno(sys_getdents64(arg1
, dirp
, count
));
4169 if (!is_error(ret
)) {
4170 struct dirent64
*de
;
4175 reclen
= de
->d_reclen
;
4178 de
->d_reclen
= tswap16(reclen
);
4179 tswap64s(&de
->d_ino
);
4180 tswap64s(&de
->d_off
);
4181 de
= (struct dirent64
*)((char *)de
+ reclen
);
4185 unlock_user(dirp
, arg2
, ret
);
4188 #endif /* TARGET_NR_getdents64 */
4189 #ifdef TARGET_NR__newselect
4190 case TARGET_NR__newselect
:
4191 ret
= do_select(arg1
, arg2
, arg3
, arg4
, arg5
);
4194 #ifdef TARGET_NR_poll
4195 case TARGET_NR_poll
:
4197 struct target_pollfd
*target_pfd
;
4198 unsigned int nfds
= arg2
;
4203 target_pfd
= lock_user(arg1
, sizeof(struct target_pollfd
) * nfds
, 1);
4204 pfd
= alloca(sizeof(struct pollfd
) * nfds
);
4205 for(i
= 0; i
< nfds
; i
++) {
4206 pfd
[i
].fd
= tswap32(target_pfd
[i
].fd
);
4207 pfd
[i
].events
= tswap16(target_pfd
[i
].events
);
4209 ret
= get_errno(poll(pfd
, nfds
, timeout
));
4210 if (!is_error(ret
)) {
4211 for(i
= 0; i
< nfds
; i
++) {
4212 target_pfd
[i
].revents
= tswap16(pfd
[i
].revents
);
4214 ret
+= nfds
* (sizeof(struct target_pollfd
)
4215 - sizeof(struct pollfd
));
4217 unlock_user(target_pfd
, arg1
, ret
);
4221 case TARGET_NR_flock
:
4222 /* NOTE: the flock constant seems to be the same for every
4224 ret
= get_errno(flock(arg1
, arg2
));
4226 case TARGET_NR_readv
:
4231 vec
= alloca(count
* sizeof(struct iovec
));
4232 lock_iovec(vec
, arg2
, count
, 0);
4233 ret
= get_errno(readv(arg1
, vec
, count
));
4234 unlock_iovec(vec
, arg2
, count
, 1);
4237 case TARGET_NR_writev
:
4242 vec
= alloca(count
* sizeof(struct iovec
));
4243 lock_iovec(vec
, arg2
, count
, 1);
4244 ret
= get_errno(writev(arg1
, vec
, count
));
4245 unlock_iovec(vec
, arg2
, count
, 0);
4248 case TARGET_NR_getsid
:
4249 ret
= get_errno(getsid(arg1
));
4251 #if defined(TARGET_NR_fdatasync) /* Not on alpha (osf_datasync ?) */
4252 case TARGET_NR_fdatasync
:
4253 ret
= get_errno(fdatasync(arg1
));
4256 case TARGET_NR__sysctl
:
4257 /* We don't implement this, but ENOTDIR is always a safe
4259 ret
= -TARGET_ENOTDIR
;
4261 case TARGET_NR_sched_setparam
:
4263 struct sched_param
*target_schp
;
4264 struct sched_param schp
;
4266 lock_user_struct(target_schp
, arg2
, 1);
4267 schp
.sched_priority
= tswap32(target_schp
->sched_priority
);
4268 unlock_user_struct(target_schp
, arg2
, 0);
4269 ret
= get_errno(sched_setparam(arg1
, &schp
));
4272 case TARGET_NR_sched_getparam
:
4274 struct sched_param
*target_schp
;
4275 struct sched_param schp
;
4276 ret
= get_errno(sched_getparam(arg1
, &schp
));
4277 if (!is_error(ret
)) {
4278 lock_user_struct(target_schp
, arg2
, 0);
4279 target_schp
->sched_priority
= tswap32(schp
.sched_priority
);
4280 unlock_user_struct(target_schp
, arg2
, 1);
4284 case TARGET_NR_sched_setscheduler
:
4286 struct sched_param
*target_schp
;
4287 struct sched_param schp
;
4288 lock_user_struct(target_schp
, arg3
, 1);
4289 schp
.sched_priority
= tswap32(target_schp
->sched_priority
);
4290 unlock_user_struct(target_schp
, arg3
, 0);
4291 ret
= get_errno(sched_setscheduler(arg1
, arg2
, &schp
));
4294 case TARGET_NR_sched_getscheduler
:
4295 ret
= get_errno(sched_getscheduler(arg1
));
4297 case TARGET_NR_sched_yield
:
4298 ret
= get_errno(sched_yield());
4300 case TARGET_NR_sched_get_priority_max
:
4301 ret
= get_errno(sched_get_priority_max(arg1
));
4303 case TARGET_NR_sched_get_priority_min
:
4304 ret
= get_errno(sched_get_priority_min(arg1
));
4306 case TARGET_NR_sched_rr_get_interval
:
4309 ret
= get_errno(sched_rr_get_interval(arg1
, &ts
));
4310 if (!is_error(ret
)) {
4311 host_to_target_timespec(arg2
, &ts
);
4315 case TARGET_NR_nanosleep
:
4317 struct timespec req
, rem
;
4318 target_to_host_timespec(&req
, arg1
);
4319 ret
= get_errno(nanosleep(&req
, &rem
));
4320 if (is_error(ret
) && arg2
) {
4321 host_to_target_timespec(arg2
, &rem
);
4325 #ifdef TARGET_NR_query_module
4326 case TARGET_NR_query_module
:
4329 #ifdef TARGET_NR_nfsservctl
4330 case TARGET_NR_nfsservctl
:
4333 case TARGET_NR_prctl
:
4336 case PR_GET_PDEATHSIG
:
4339 ret
= get_errno(prctl(arg1
, &deathsig
, arg3
, arg4
, arg5
));
4340 if (!is_error(ret
) && arg2
)
4341 tput32(arg2
, deathsig
);
4345 ret
= get_errno(prctl(arg1
, arg2
, arg3
, arg4
, arg5
));
4349 #ifdef TARGET_NR_pread
4350 case TARGET_NR_pread
:
4351 page_unprotect_range(arg2
, arg3
);
4352 p
= lock_user(arg2
, arg3
, 0);
4353 ret
= get_errno(pread(arg1
, p
, arg3
, arg4
));
4354 unlock_user(p
, arg2
, ret
);
4356 case TARGET_NR_pwrite
:
4357 p
= lock_user(arg2
, arg3
, 1);
4358 ret
= get_errno(pwrite(arg1
, p
, arg3
, arg4
));
4359 unlock_user(p
, arg2
, 0);
4362 case TARGET_NR_getcwd
:
4363 p
= lock_user(arg1
, arg2
, 0);
4364 ret
= get_errno(sys_getcwd1(p
, arg2
));
4365 unlock_user(p
, arg1
, ret
);
4367 case TARGET_NR_capget
:
4369 case TARGET_NR_capset
:
4371 case TARGET_NR_sigaltstack
:
4372 #if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_MIPS) || \
4373 defined(TARGET_SPARC) || defined(TARGET_PPC) || defined(TARGET_ALPHA)
4374 ret
= do_sigaltstack((struct target_sigaltstack
*)arg1
,
4375 (struct target_sigaltstack
*)arg2
,
4376 get_sp_from_cpustate((CPUState
*)cpu_env
));
4381 case TARGET_NR_sendfile
:
4383 #ifdef TARGET_NR_getpmsg
4384 case TARGET_NR_getpmsg
:
4387 #ifdef TARGET_NR_putpmsg
4388 case TARGET_NR_putpmsg
:
4391 #ifdef TARGET_NR_vfork
4392 case TARGET_NR_vfork
:
4393 ret
= get_errno(do_fork(cpu_env
, CLONE_VFORK
| CLONE_VM
| SIGCHLD
, 0));
4396 #ifdef TARGET_NR_ugetrlimit
4397 case TARGET_NR_ugetrlimit
:
4400 ret
= get_errno(getrlimit(arg1
, &rlim
));
4401 if (!is_error(ret
)) {
4402 struct target_rlimit
*target_rlim
;
4403 lock_user_struct(target_rlim
, arg2
, 0);
4404 target_rlim
->rlim_cur
= tswapl(rlim
.rlim_cur
);
4405 target_rlim
->rlim_max
= tswapl(rlim
.rlim_max
);
4406 unlock_user_struct(target_rlim
, arg2
, 1);
4411 #ifdef TARGET_NR_truncate64
4412 case TARGET_NR_truncate64
:
4413 p
= lock_user_string(arg1
);
4414 ret
= target_truncate64(cpu_env
, p
, arg2
, arg3
, arg4
);
4415 unlock_user(p
, arg1
, 0);
4418 #ifdef TARGET_NR_ftruncate64
4419 case TARGET_NR_ftruncate64
:
4420 ret
= target_ftruncate64(cpu_env
, arg1
, arg2
, arg3
, arg4
);
4423 #ifdef TARGET_NR_stat64
4424 case TARGET_NR_stat64
:
4425 p
= lock_user_string(arg1
);
4426 ret
= get_errno(stat(path(p
), &st
));
4427 unlock_user(p
, arg1
, 0);
4430 #ifdef TARGET_NR_lstat64
4431 case TARGET_NR_lstat64
:
4432 p
= lock_user_string(arg1
);
4433 ret
= get_errno(lstat(path(p
), &st
));
4434 unlock_user(p
, arg1
, 0);
4437 #ifdef TARGET_NR_fstat64
4438 case TARGET_NR_fstat64
:
4440 ret
= get_errno(fstat(arg1
, &st
));
4442 if (!is_error(ret
)) {
4444 if (((CPUARMState
*)cpu_env
)->eabi
) {
4445 struct target_eabi_stat64
*target_st
;
4446 lock_user_struct(target_st
, arg2
, 1);
4447 memset(target_st
, 0, sizeof(struct target_eabi_stat64
));
4448 /* put_user is probably wrong. */
4449 put_user(st
.st_dev
, &target_st
->st_dev
);
4450 put_user(st
.st_ino
, &target_st
->st_ino
);
4451 #ifdef TARGET_STAT64_HAS_BROKEN_ST_INO
4452 put_user(st
.st_ino
, &target_st
->__st_ino
);
4454 put_user(st
.st_mode
, &target_st
->st_mode
);
4455 put_user(st
.st_nlink
, &target_st
->st_nlink
);
4456 put_user(st
.st_uid
, &target_st
->st_uid
);
4457 put_user(st
.st_gid
, &target_st
->st_gid
);
4458 put_user(st
.st_rdev
, &target_st
->st_rdev
);
4459 /* XXX: better use of kernel struct */
4460 put_user(st
.st_size
, &target_st
->st_size
);
4461 put_user(st
.st_blksize
, &target_st
->st_blksize
);
4462 put_user(st
.st_blocks
, &target_st
->st_blocks
);
4463 put_user(st
.st_atime
, &target_st
->target_st_atime
);
4464 put_user(st
.st_mtime
, &target_st
->target_st_mtime
);
4465 put_user(st
.st_ctime
, &target_st
->target_st_ctime
);
4466 unlock_user_struct(target_st
, arg2
, 0);
4470 struct target_stat64
*target_st
;
4471 lock_user_struct(target_st
, arg2
, 1);
4472 memset(target_st
, 0, sizeof(struct target_stat64
));
4473 /* ??? put_user is probably wrong. */
4474 put_user(st
.st_dev
, &target_st
->st_dev
);
4475 put_user(st
.st_ino
, &target_st
->st_ino
);
4476 #ifdef TARGET_STAT64_HAS_BROKEN_ST_INO
4477 put_user(st
.st_ino
, &target_st
->__st_ino
);
4479 put_user(st
.st_mode
, &target_st
->st_mode
);
4480 put_user(st
.st_nlink
, &target_st
->st_nlink
);
4481 put_user(st
.st_uid
, &target_st
->st_uid
);
4482 put_user(st
.st_gid
, &target_st
->st_gid
);
4483 put_user(st
.st_rdev
, &target_st
->st_rdev
);
4484 /* XXX: better use of kernel struct */
4485 put_user(st
.st_size
, &target_st
->st_size
);
4486 put_user(st
.st_blksize
, &target_st
->st_blksize
);
4487 put_user(st
.st_blocks
, &target_st
->st_blocks
);
4488 put_user(st
.st_atime
, &target_st
->target_st_atime
);
4489 put_user(st
.st_mtime
, &target_st
->target_st_mtime
);
4490 put_user(st
.st_ctime
, &target_st
->target_st_ctime
);
4491 unlock_user_struct(target_st
, arg2
, 0);
4498 case TARGET_NR_lchown
:
4499 p
= lock_user_string(arg1
);
4500 ret
= get_errno(lchown(p
, low2highuid(arg2
), low2highgid(arg3
)));
4501 unlock_user(p
, arg1
, 0);
4503 case TARGET_NR_getuid
:
4504 ret
= get_errno(high2lowuid(getuid()));
4506 case TARGET_NR_getgid
:
4507 ret
= get_errno(high2lowgid(getgid()));
4509 case TARGET_NR_geteuid
:
4510 ret
= get_errno(high2lowuid(geteuid()));
4512 case TARGET_NR_getegid
:
4513 ret
= get_errno(high2lowgid(getegid()));
4515 case TARGET_NR_setreuid
:
4516 ret
= get_errno(setreuid(low2highuid(arg1
), low2highuid(arg2
)));
4518 case TARGET_NR_setregid
:
4519 ret
= get_errno(setregid(low2highgid(arg1
), low2highgid(arg2
)));
4521 case TARGET_NR_getgroups
:
4523 int gidsetsize
= arg1
;
4524 uint16_t *target_grouplist
;
4528 grouplist
= alloca(gidsetsize
* sizeof(gid_t
));
4529 ret
= get_errno(getgroups(gidsetsize
, grouplist
));
4530 if (!is_error(ret
)) {
4531 target_grouplist
= lock_user(arg2
, gidsetsize
* 2, 0);
4532 for(i
= 0;i
< gidsetsize
; i
++)
4533 target_grouplist
[i
] = tswap16(grouplist
[i
]);
4534 unlock_user(target_grouplist
, arg2
, gidsetsize
* 2);
4538 case TARGET_NR_setgroups
:
4540 int gidsetsize
= arg1
;
4541 uint16_t *target_grouplist
;
4545 grouplist
= alloca(gidsetsize
* sizeof(gid_t
));
4546 target_grouplist
= lock_user(arg2
, gidsetsize
* 2, 1);
4547 for(i
= 0;i
< gidsetsize
; i
++)
4548 grouplist
[i
] = tswap16(target_grouplist
[i
]);
4549 unlock_user(target_grouplist
, arg2
, 0);
4550 ret
= get_errno(setgroups(gidsetsize
, grouplist
));
4553 case TARGET_NR_fchown
:
4554 ret
= get_errno(fchown(arg1
, low2highuid(arg2
), low2highgid(arg3
)));
4556 #if defined(TARGET_NR_fchownat) && defined(__NR_fchownat)
4557 case TARGET_NR_fchownat
:
4559 ret
= -TARGET_EFAULT
;
4562 p
= lock_user_string(arg2
);
4563 if (!access_ok(VERIFY_READ
, p
, 1))
4564 /* Don't "goto fail" so that cleanup can happen. */
4565 ret
= -TARGET_EFAULT
;
4567 ret
= get_errno(sys_fchownat(arg1
, p
, low2highuid(arg3
), low2highgid(arg4
), arg5
));
4569 unlock_user(p
, arg2
, 0);
4572 #ifdef TARGET_NR_setresuid
4573 case TARGET_NR_setresuid
:
4574 ret
= get_errno(setresuid(low2highuid(arg1
),
4576 low2highuid(arg3
)));
4579 #ifdef TARGET_NR_getresuid
4580 case TARGET_NR_getresuid
:
4582 uid_t ruid
, euid
, suid
;
4583 ret
= get_errno(getresuid(&ruid
, &euid
, &suid
));
4584 if (!is_error(ret
)) {
4585 tput16(arg1
, tswap16(high2lowuid(ruid
)));
4586 tput16(arg2
, tswap16(high2lowuid(euid
)));
4587 tput16(arg3
, tswap16(high2lowuid(suid
)));
4592 #ifdef TARGET_NR_getresgid
4593 case TARGET_NR_setresgid
:
4594 ret
= get_errno(setresgid(low2highgid(arg1
),
4596 low2highgid(arg3
)));
4599 #ifdef TARGET_NR_getresgid
4600 case TARGET_NR_getresgid
:
4602 gid_t rgid
, egid
, sgid
;
4603 ret
= get_errno(getresgid(&rgid
, &egid
, &sgid
));
4604 if (!is_error(ret
)) {
4605 tput16(arg1
, tswap16(high2lowgid(rgid
)));
4606 tput16(arg2
, tswap16(high2lowgid(egid
)));
4607 tput16(arg3
, tswap16(high2lowgid(sgid
)));
4612 case TARGET_NR_chown
:
4613 p
= lock_user_string(arg1
);
4614 ret
= get_errno(chown(p
, low2highuid(arg2
), low2highgid(arg3
)));
4615 unlock_user(p
, arg1
, 0);
4617 case TARGET_NR_setuid
:
4618 ret
= get_errno(setuid(low2highuid(arg1
)));
4620 case TARGET_NR_setgid
:
4621 ret
= get_errno(setgid(low2highgid(arg1
)));
4623 case TARGET_NR_setfsuid
:
4624 ret
= get_errno(setfsuid(arg1
));
4626 case TARGET_NR_setfsgid
:
4627 ret
= get_errno(setfsgid(arg1
));
4629 #endif /* USE_UID16 */
4631 #ifdef TARGET_NR_lchown32
4632 case TARGET_NR_lchown32
:
4633 p
= lock_user_string(arg1
);
4634 ret
= get_errno(lchown(p
, arg2
, arg3
));
4635 unlock_user(p
, arg1
, 0);
4638 #ifdef TARGET_NR_getuid32
4639 case TARGET_NR_getuid32
:
4640 ret
= get_errno(getuid());
4643 #ifdef TARGET_NR_getgid32
4644 case TARGET_NR_getgid32
:
4645 ret
= get_errno(getgid());
4648 #ifdef TARGET_NR_geteuid32
4649 case TARGET_NR_geteuid32
:
4650 ret
= get_errno(geteuid());
4653 #ifdef TARGET_NR_getegid32
4654 case TARGET_NR_getegid32
:
4655 ret
= get_errno(getegid());
4658 #ifdef TARGET_NR_setreuid32
4659 case TARGET_NR_setreuid32
:
4660 ret
= get_errno(setreuid(arg1
, arg2
));
4663 #ifdef TARGET_NR_setregid32
4664 case TARGET_NR_setregid32
:
4665 ret
= get_errno(setregid(arg1
, arg2
));
4668 #ifdef TARGET_NR_getgroups32
4669 case TARGET_NR_getgroups32
:
4671 int gidsetsize
= arg1
;
4672 uint32_t *target_grouplist
;
4676 grouplist
= alloca(gidsetsize
* sizeof(gid_t
));
4677 ret
= get_errno(getgroups(gidsetsize
, grouplist
));
4678 if (!is_error(ret
)) {
4679 target_grouplist
= lock_user(arg2
, gidsetsize
* 4, 0);
4680 for(i
= 0;i
< gidsetsize
; i
++)
4681 target_grouplist
[i
] = tswap32(grouplist
[i
]);
4682 unlock_user(target_grouplist
, arg2
, gidsetsize
* 4);
4687 #ifdef TARGET_NR_setgroups32
4688 case TARGET_NR_setgroups32
:
4690 int gidsetsize
= arg1
;
4691 uint32_t *target_grouplist
;
4695 grouplist
= alloca(gidsetsize
* sizeof(gid_t
));
4696 target_grouplist
= lock_user(arg2
, gidsetsize
* 4, 1);
4697 for(i
= 0;i
< gidsetsize
; i
++)
4698 grouplist
[i
] = tswap32(target_grouplist
[i
]);
4699 unlock_user(target_grouplist
, arg2
, 0);
4700 ret
= get_errno(setgroups(gidsetsize
, grouplist
));
4704 #ifdef TARGET_NR_fchown32
4705 case TARGET_NR_fchown32
:
4706 ret
= get_errno(fchown(arg1
, arg2
, arg3
));
4709 #ifdef TARGET_NR_setresuid32
4710 case TARGET_NR_setresuid32
:
4711 ret
= get_errno(setresuid(arg1
, arg2
, arg3
));
4714 #ifdef TARGET_NR_getresuid32
4715 case TARGET_NR_getresuid32
:
4717 uid_t ruid
, euid
, suid
;
4718 ret
= get_errno(getresuid(&ruid
, &euid
, &suid
));
4719 if (!is_error(ret
)) {
4720 tput32(arg1
, tswap32(ruid
));
4721 tput32(arg2
, tswap32(euid
));
4722 tput32(arg3
, tswap32(suid
));
4727 #ifdef TARGET_NR_setresgid32
4728 case TARGET_NR_setresgid32
:
4729 ret
= get_errno(setresgid(arg1
, arg2
, arg3
));
4732 #ifdef TARGET_NR_getresgid32
4733 case TARGET_NR_getresgid32
:
4735 gid_t rgid
, egid
, sgid
;
4736 ret
= get_errno(getresgid(&rgid
, &egid
, &sgid
));
4737 if (!is_error(ret
)) {
4738 tput32(arg1
, tswap32(rgid
));
4739 tput32(arg2
, tswap32(egid
));
4740 tput32(arg3
, tswap32(sgid
));
4745 #ifdef TARGET_NR_chown32
4746 case TARGET_NR_chown32
:
4747 p
= lock_user_string(arg1
);
4748 ret
= get_errno(chown(p
, arg2
, arg3
));
4749 unlock_user(p
, arg1
, 0);
4752 #ifdef TARGET_NR_setuid32
4753 case TARGET_NR_setuid32
:
4754 ret
= get_errno(setuid(arg1
));
4757 #ifdef TARGET_NR_setgid32
4758 case TARGET_NR_setgid32
:
4759 ret
= get_errno(setgid(arg1
));
4762 #ifdef TARGET_NR_setfsuid32
4763 case TARGET_NR_setfsuid32
:
4764 ret
= get_errno(setfsuid(arg1
));
4767 #ifdef TARGET_NR_setfsgid32
4768 case TARGET_NR_setfsgid32
:
4769 ret
= get_errno(setfsgid(arg1
));
4773 case TARGET_NR_pivot_root
:
4775 #ifdef TARGET_NR_mincore
4776 case TARGET_NR_mincore
:
4779 #ifdef TARGET_NR_madvise
4780 case TARGET_NR_madvise
:
4781 /* A straight passthrough may not be safe because qemu sometimes
4782 turns private flie-backed mappings into anonymous mappings.
4783 This will break MADV_DONTNEED.
4784 This is a hint, so ignoring and returning success is ok. */
4788 #if TARGET_ABI_BITS == 32
4789 case TARGET_NR_fcntl64
:
4793 struct target_flock64
*target_fl
;
4795 struct target_eabi_flock64
*target_efl
;
4799 case TARGET_F_GETLK64
:
4802 case TARGET_F_SETLK64
:
4805 case TARGET_F_SETLKW64
:
4814 case TARGET_F_GETLK64
:
4816 if (((CPUARMState
*)cpu_env
)->eabi
) {
4817 lock_user_struct(target_efl
, arg3
, 1);
4818 fl
.l_type
= tswap16(target_efl
->l_type
);
4819 fl
.l_whence
= tswap16(target_efl
->l_whence
);
4820 fl
.l_start
= tswap64(target_efl
->l_start
);
4821 fl
.l_len
= tswap64(target_efl
->l_len
);
4822 fl
.l_pid
= tswapl(target_efl
->l_pid
);
4823 unlock_user_struct(target_efl
, arg3
, 0);
4827 lock_user_struct(target_fl
, arg3
, 1);
4828 fl
.l_type
= tswap16(target_fl
->l_type
);
4829 fl
.l_whence
= tswap16(target_fl
->l_whence
);
4830 fl
.l_start
= tswap64(target_fl
->l_start
);
4831 fl
.l_len
= tswap64(target_fl
->l_len
);
4832 fl
.l_pid
= tswapl(target_fl
->l_pid
);
4833 unlock_user_struct(target_fl
, arg3
, 0);
4835 ret
= get_errno(fcntl(arg1
, cmd
, &fl
));
4838 if (((CPUARMState
*)cpu_env
)->eabi
) {
4839 lock_user_struct(target_efl
, arg3
, 0);
4840 target_efl
->l_type
= tswap16(fl
.l_type
);
4841 target_efl
->l_whence
= tswap16(fl
.l_whence
);
4842 target_efl
->l_start
= tswap64(fl
.l_start
);
4843 target_efl
->l_len
= tswap64(fl
.l_len
);
4844 target_efl
->l_pid
= tswapl(fl
.l_pid
);
4845 unlock_user_struct(target_efl
, arg3
, 1);
4849 lock_user_struct(target_fl
, arg3
, 0);
4850 target_fl
->l_type
= tswap16(fl
.l_type
);
4851 target_fl
->l_whence
= tswap16(fl
.l_whence
);
4852 target_fl
->l_start
= tswap64(fl
.l_start
);
4853 target_fl
->l_len
= tswap64(fl
.l_len
);
4854 target_fl
->l_pid
= tswapl(fl
.l_pid
);
4855 unlock_user_struct(target_fl
, arg3
, 1);
4860 case TARGET_F_SETLK64
:
4861 case TARGET_F_SETLKW64
:
4863 if (((CPUARMState
*)cpu_env
)->eabi
) {
4864 lock_user_struct(target_efl
, arg3
, 1);
4865 fl
.l_type
= tswap16(target_efl
->l_type
);
4866 fl
.l_whence
= tswap16(target_efl
->l_whence
);
4867 fl
.l_start
= tswap64(target_efl
->l_start
);
4868 fl
.l_len
= tswap64(target_efl
->l_len
);
4869 fl
.l_pid
= tswapl(target_efl
->l_pid
);
4870 unlock_user_struct(target_efl
, arg3
, 0);
4874 lock_user_struct(target_fl
, arg3
, 1);
4875 fl
.l_type
= tswap16(target_fl
->l_type
);
4876 fl
.l_whence
= tswap16(target_fl
->l_whence
);
4877 fl
.l_start
= tswap64(target_fl
->l_start
);
4878 fl
.l_len
= tswap64(target_fl
->l_len
);
4879 fl
.l_pid
= tswapl(target_fl
->l_pid
);
4880 unlock_user_struct(target_fl
, arg3
, 0);
4882 ret
= get_errno(fcntl(arg1
, cmd
, &fl
));
4885 ret
= get_errno(do_fcntl(arg1
, cmd
, arg3
));
4891 #ifdef TARGET_NR_cacheflush
4892 case TARGET_NR_cacheflush
:
4893 /* self-modifying code is handled automatically, so nothing needed */
4897 #ifdef TARGET_NR_security
4898 case TARGET_NR_security
:
4901 #ifdef TARGET_NR_getpagesize
4902 case TARGET_NR_getpagesize
:
4903 ret
= TARGET_PAGE_SIZE
;
4906 case TARGET_NR_gettid
:
4907 ret
= get_errno(gettid());
4909 #ifdef TARGET_NR_readahead
4910 case TARGET_NR_readahead
:
4913 #ifdef TARGET_NR_setxattr
4914 case TARGET_NR_setxattr
:
4915 case TARGET_NR_lsetxattr
:
4916 case TARGET_NR_fsetxattr
:
4917 case TARGET_NR_getxattr
:
4918 case TARGET_NR_lgetxattr
:
4919 case TARGET_NR_fgetxattr
:
4920 case TARGET_NR_listxattr
:
4921 case TARGET_NR_llistxattr
:
4922 case TARGET_NR_flistxattr
:
4923 case TARGET_NR_removexattr
:
4924 case TARGET_NR_lremovexattr
:
4925 case TARGET_NR_fremovexattr
:
4926 goto unimplemented_nowarn
;
4928 #ifdef TARGET_NR_set_thread_area
4929 case TARGET_NR_set_thread_area
:
4931 ((CPUMIPSState
*) cpu_env
)->tls_value
= arg1
;
4935 goto unimplemented_nowarn
;
4938 #ifdef TARGET_NR_get_thread_area
4939 case TARGET_NR_get_thread_area
:
4940 goto unimplemented_nowarn
;
4942 #ifdef TARGET_NR_getdomainname
4943 case TARGET_NR_getdomainname
:
4944 goto unimplemented_nowarn
;
4947 #ifdef TARGET_NR_clock_gettime
4948 case TARGET_NR_clock_gettime
:
4951 ret
= get_errno(clock_gettime(arg1
, &ts
));
4952 if (!is_error(ret
)) {
4953 host_to_target_timespec(arg2
, &ts
);
4958 #ifdef TARGET_NR_clock_getres
4959 case TARGET_NR_clock_getres
:
4962 ret
= get_errno(clock_getres(arg1
, &ts
));
4963 if (!is_error(ret
)) {
4964 host_to_target_timespec(arg2
, &ts
);
4970 #if defined(TARGET_NR_set_tid_address) && defined(__NR_set_tid_address)
4971 case TARGET_NR_set_tid_address
:
4972 ret
= get_errno(set_tid_address((int *) arg1
));
4976 #if defined(TARGET_NR_tkill) && defined(__NR_tkill)
4977 case TARGET_NR_tkill
:
4978 ret
= get_errno(sys_tkill((int)arg1
, (int)arg2
));
4982 #if defined(TARGET_NR_tgkill) && defined(__NR_tgkill)
4983 case TARGET_NR_tgkill
:
4984 ret
= get_errno(sys_tgkill((int)arg1
, (int)arg2
, (int)arg3
));
4988 #ifdef TARGET_NR_set_robust_list
4989 case TARGET_NR_set_robust_list
:
4990 goto unimplemented_nowarn
;
4993 #if defined(TARGET_NR_utimensat) && defined(__NR_utimensat)
4994 case TARGET_NR_utimensat
:
4996 struct timespec ts
[2];
4997 target_to_host_timespec(ts
, arg3
);
4998 target_to_host_timespec(ts
+1, arg3
+sizeof(struct target_timespec
));
5000 ret
= get_errno(sys_utimensat(arg1
, NULL
, ts
, arg4
));
5002 p
= lock_user_string(arg2
);
5003 if (!access_ok(VERIFY_READ
, p
, 1))
5004 /* Don't "goto fail" so that cleanup can happen. */
5005 ret
= -TARGET_EFAULT
;
5007 ret
= get_errno(sys_utimensat(arg1
, path(p
), ts
, arg4
));
5009 unlock_user(p
, arg2
, 0);
5017 gemu_log("qemu: Unsupported syscall: %d\n", num
);
5018 #if defined(TARGET_NR_setxattr) || defined(TARGET_NR_get_thread_area) || defined(TARGET_NR_getdomainname) || defined(TARGET_NR_set_robust_list)
5019 unimplemented_nowarn
:
5021 ret
= -TARGET_ENOSYS
;
5026 gemu_log(" = %ld\n", ret
);