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 static int gettid(void) {
174 _syscall1(int,sys_uname
,struct new_utsname
*,buf
)
175 #if defined(TARGET_NR_faccessat) && defined(__NR_faccessat)
176 _syscall4(int,sys_faccessat
,int,dirfd
,const char *,pathname
,int,mode
,int,flags
)
178 #if defined(TARGET_NR_fchmodat) && defined(__NR_fchmodat)
179 _syscall4(int,sys_fchmodat
,int,dirfd
,const char *,pathname
,
180 mode_t
,mode
,int,flags
)
182 #if defined(TARGET_NR_fchownat) && defined(__NR_fchownat)
183 _syscall5(int,sys_fchownat
,int,dirfd
,const char *,pathname
,
184 uid_t
,owner
,gid_t
,group
,int,flags
)
186 _syscall2(int,sys_getcwd1
,char *,buf
,size_t,size
)
187 _syscall3(int, sys_getdents
, uint
, fd
, struct dirent
*, dirp
, uint
, count
);
188 #if defined(TARGET_NR_getdents64) && defined(__NR_getdents64)
189 _syscall3(int, sys_getdents64
, uint
, fd
, struct dirent64
*, dirp
, uint
, count
);
191 _syscall2(int, sys_getpriority
, int, which
, int, who
);
192 _syscall5(int, _llseek
, uint
, fd
, ulong
, hi
, ulong
, lo
,
193 loff_t
*, res
, uint
, wh
);
194 #if defined(TARGET_NR_linkat) && defined(__NR_linkat)
195 _syscall5(int,sys_linkat
,int,olddirfd
,const char *,oldpath
,
196 int,newdirfd
,const char *,newpath
,int,flags
)
198 #if defined(TARGET_NR_mkdirat) && defined(__NR_mkdirat)
199 _syscall3(int,sys_mkdirat
,int,dirfd
,const char *,pathname
,mode_t
,mode
)
201 #if defined(TARGET_NR_mknodat) && defined(__NR_mknodat)
202 _syscall4(int,sys_mknodat
,int,dirfd
,const char *,pathname
,
203 mode_t
,mode
,dev_t
,dev
)
205 #if defined(TARGET_NR_openat) && defined(__NR_openat)
206 _syscall4(int,sys_openat
,int,dirfd
,const char *,pathname
,int,flags
,mode_t
,mode
)
208 #if defined(TARGET_NR_readlinkat) && defined(__NR_readlinkat)
209 _syscall4(int,sys_readlinkat
,int,dirfd
,const char *,pathname
,
210 char *,buf
,size_t,bufsize
)
212 #if defined(TARGET_NR_renameat) && defined(__NR_renameat)
213 _syscall4(int,sys_renameat
,int,olddirfd
,const char *,oldpath
,
214 int,newdirfd
,const char *,newpath
)
216 _syscall3(int,sys_rt_sigqueueinfo
,int,pid
,int,sig
,siginfo_t
*,uinfo
)
217 #if defined(TARGET_NR_symlinkat) && defined(__NR_symlinkat)
218 _syscall3(int,sys_symlinkat
,const char *,oldpath
,
219 int,newdirfd
,const char *,newpath
)
221 _syscall3(int,sys_syslog
,int,type
,char*,bufp
,int,len
)
222 #if defined(TARGET_NR_tgkill) && defined(__NR_tgkill)
223 _syscall3(int,sys_tgkill
,int,tgid
,int,pid
,int,sig
)
225 #if defined(TARGET_NR_tkill) && defined(__NR_tkill)
226 _syscall2(int,sys_tkill
,int,tid
,int,sig
)
228 #ifdef __NR_exit_group
229 _syscall1(int,exit_group
,int,error_code
)
231 #if defined(TARGET_NR_set_tid_address) && defined(__NR_set_tid_address)
232 _syscall1(int,set_tid_address
,int *,tidptr
)
234 #if defined(TARGET_NR_unlinkat) && defined(__NR_unlinkat)
235 _syscall3(int,sys_unlinkat
,int,dirfd
,const char *,pathname
,int,flags
)
237 #if defined(TARGET_NR_utimensat) && defined(__NR_utimensat)
238 _syscall4(int,sys_utimensat
,int,dirfd
,const char *,pathname
,
239 const struct timespec
*,tsp
,int,flags
)
242 extern int personality(int);
243 extern int flock(int, int);
244 extern int setfsuid(int);
245 extern int setfsgid(int);
246 extern int setresuid(uid_t
, uid_t
, uid_t
);
247 extern int getresuid(uid_t
*, uid_t
*, uid_t
*);
248 extern int setresgid(gid_t
, gid_t
, gid_t
);
249 extern int getresgid(gid_t
*, gid_t
*, gid_t
*);
250 extern int setgroups(int, gid_t
*);
253 * This list is the union of errno values overridden in asm-<arch>/errno.h
254 * minus the errnos that are not actually generic to all archs.
256 static uint16_t host_to_target_errno_table
[1200] = {
257 [EIDRM
] = TARGET_EIDRM
,
258 [ECHRNG
] = TARGET_ECHRNG
,
259 [EL2NSYNC
] = TARGET_EL2NSYNC
,
260 [EL3HLT
] = TARGET_EL3HLT
,
261 [EL3RST
] = TARGET_EL3RST
,
262 [ELNRNG
] = TARGET_ELNRNG
,
263 [EUNATCH
] = TARGET_EUNATCH
,
264 [ENOCSI
] = TARGET_ENOCSI
,
265 [EL2HLT
] = TARGET_EL2HLT
,
266 [EDEADLK
] = TARGET_EDEADLK
,
267 [ENOLCK
] = TARGET_ENOLCK
,
268 [EBADE
] = TARGET_EBADE
,
269 [EBADR
] = TARGET_EBADR
,
270 [EXFULL
] = TARGET_EXFULL
,
271 [ENOANO
] = TARGET_ENOANO
,
272 [EBADRQC
] = TARGET_EBADRQC
,
273 [EBADSLT
] = TARGET_EBADSLT
,
274 [EBFONT
] = TARGET_EBFONT
,
275 [ENOSTR
] = TARGET_ENOSTR
,
276 [ENODATA
] = TARGET_ENODATA
,
277 [ETIME
] = TARGET_ETIME
,
278 [ENOSR
] = TARGET_ENOSR
,
279 [ENONET
] = TARGET_ENONET
,
280 [ENOPKG
] = TARGET_ENOPKG
,
281 [EREMOTE
] = TARGET_EREMOTE
,
282 [ENOLINK
] = TARGET_ENOLINK
,
283 [EADV
] = TARGET_EADV
,
284 [ESRMNT
] = TARGET_ESRMNT
,
285 [ECOMM
] = TARGET_ECOMM
,
286 [EPROTO
] = TARGET_EPROTO
,
287 [EDOTDOT
] = TARGET_EDOTDOT
,
288 [EMULTIHOP
] = TARGET_EMULTIHOP
,
289 [EBADMSG
] = TARGET_EBADMSG
,
290 [ENAMETOOLONG
] = TARGET_ENAMETOOLONG
,
291 [EOVERFLOW
] = TARGET_EOVERFLOW
,
292 [ENOTUNIQ
] = TARGET_ENOTUNIQ
,
293 [EBADFD
] = TARGET_EBADFD
,
294 [EREMCHG
] = TARGET_EREMCHG
,
295 [ELIBACC
] = TARGET_ELIBACC
,
296 [ELIBBAD
] = TARGET_ELIBBAD
,
297 [ELIBSCN
] = TARGET_ELIBSCN
,
298 [ELIBMAX
] = TARGET_ELIBMAX
,
299 [ELIBEXEC
] = TARGET_ELIBEXEC
,
300 [EILSEQ
] = TARGET_EILSEQ
,
301 [ENOSYS
] = TARGET_ENOSYS
,
302 [ELOOP
] = TARGET_ELOOP
,
303 [ERESTART
] = TARGET_ERESTART
,
304 [ESTRPIPE
] = TARGET_ESTRPIPE
,
305 [ENOTEMPTY
] = TARGET_ENOTEMPTY
,
306 [EUSERS
] = TARGET_EUSERS
,
307 [ENOTSOCK
] = TARGET_ENOTSOCK
,
308 [EDESTADDRREQ
] = TARGET_EDESTADDRREQ
,
309 [EMSGSIZE
] = TARGET_EMSGSIZE
,
310 [EPROTOTYPE
] = TARGET_EPROTOTYPE
,
311 [ENOPROTOOPT
] = TARGET_ENOPROTOOPT
,
312 [EPROTONOSUPPORT
] = TARGET_EPROTONOSUPPORT
,
313 [ESOCKTNOSUPPORT
] = TARGET_ESOCKTNOSUPPORT
,
314 [EOPNOTSUPP
] = TARGET_EOPNOTSUPP
,
315 [EPFNOSUPPORT
] = TARGET_EPFNOSUPPORT
,
316 [EAFNOSUPPORT
] = TARGET_EAFNOSUPPORT
,
317 [EADDRINUSE
] = TARGET_EADDRINUSE
,
318 [EADDRNOTAVAIL
] = TARGET_EADDRNOTAVAIL
,
319 [ENETDOWN
] = TARGET_ENETDOWN
,
320 [ENETUNREACH
] = TARGET_ENETUNREACH
,
321 [ENETRESET
] = TARGET_ENETRESET
,
322 [ECONNABORTED
] = TARGET_ECONNABORTED
,
323 [ECONNRESET
] = TARGET_ECONNRESET
,
324 [ENOBUFS
] = TARGET_ENOBUFS
,
325 [EISCONN
] = TARGET_EISCONN
,
326 [ENOTCONN
] = TARGET_ENOTCONN
,
327 [EUCLEAN
] = TARGET_EUCLEAN
,
328 [ENOTNAM
] = TARGET_ENOTNAM
,
329 [ENAVAIL
] = TARGET_ENAVAIL
,
330 [EISNAM
] = TARGET_EISNAM
,
331 [EREMOTEIO
] = TARGET_EREMOTEIO
,
332 [ESHUTDOWN
] = TARGET_ESHUTDOWN
,
333 [ETOOMANYREFS
] = TARGET_ETOOMANYREFS
,
334 [ETIMEDOUT
] = TARGET_ETIMEDOUT
,
335 [ECONNREFUSED
] = TARGET_ECONNREFUSED
,
336 [EHOSTDOWN
] = TARGET_EHOSTDOWN
,
337 [EHOSTUNREACH
] = TARGET_EHOSTUNREACH
,
338 [EALREADY
] = TARGET_EALREADY
,
339 [EINPROGRESS
] = TARGET_EINPROGRESS
,
340 [ESTALE
] = TARGET_ESTALE
,
341 [ECANCELED
] = TARGET_ECANCELED
,
342 [ENOMEDIUM
] = TARGET_ENOMEDIUM
,
343 [EMEDIUMTYPE
] = TARGET_EMEDIUMTYPE
,
345 [ENOKEY
] = TARGET_ENOKEY
,
348 [EKEYEXPIRED
] = TARGET_EKEYEXPIRED
,
351 [EKEYREVOKED
] = TARGET_EKEYREVOKED
,
354 [EKEYREJECTED
] = TARGET_EKEYREJECTED
,
357 [EOWNERDEAD
] = TARGET_EOWNERDEAD
,
359 #ifdef ENOTRECOVERABLE
360 [ENOTRECOVERABLE
] = TARGET_ENOTRECOVERABLE
,
364 static inline int host_to_target_errno(int err
)
366 if(host_to_target_errno_table
[err
])
367 return host_to_target_errno_table
[err
];
371 static inline abi_long
get_errno(abi_long ret
)
374 return -host_to_target_errno(errno
);
379 static inline int is_error(abi_long ret
)
381 return (abi_ulong
)ret
>= (abi_ulong
)(-4096);
384 static abi_ulong target_brk
;
385 static abi_ulong target_original_brk
;
387 void target_set_brk(abi_ulong new_brk
)
389 target_original_brk
= target_brk
= HOST_PAGE_ALIGN(new_brk
);
392 abi_long
do_brk(abi_ulong new_brk
)
395 abi_long mapped_addr
;
400 if (new_brk
< target_original_brk
)
403 brk_page
= HOST_PAGE_ALIGN(target_brk
);
405 /* If the new brk is less than this, set it and we're done... */
406 if (new_brk
< brk_page
) {
407 target_brk
= new_brk
;
411 /* We need to allocate more memory after the brk... */
412 new_alloc_size
= HOST_PAGE_ALIGN(new_brk
- brk_page
+ 1);
413 mapped_addr
= get_errno(target_mmap(brk_page
, new_alloc_size
,
414 PROT_READ
|PROT_WRITE
,
415 MAP_ANON
|MAP_FIXED
|MAP_PRIVATE
, 0, 0));
416 if (is_error(mapped_addr
)) {
419 target_brk
= new_brk
;
424 static inline fd_set
*target_to_host_fds(fd_set
*fds
,
425 abi_long
*target_fds
, int n
)
427 #if !defined(BSWAP_NEEDED) && !defined(WORDS_BIGENDIAN)
428 return (fd_set
*)target_fds
;
433 for(i
= 0;i
< n
; i
++) {
434 b
= (tswapl(target_fds
[i
/ TARGET_ABI_BITS
]) >>
435 (i
& (TARGET_ABI_BITS
- 1))) & 1;
446 static inline void host_to_target_fds(abi_long
*target_fds
,
449 #if !defined(BSWAP_NEEDED) && !defined(WORDS_BIGENDIAN)
456 nw
= (n
+ TARGET_ABI_BITS
- 1) / TARGET_ABI_BITS
;
458 for(i
= 0;i
< nw
; i
++) {
460 for(j
= 0; j
< TARGET_ABI_BITS
; j
++) {
461 v
|= ((FD_ISSET(k
, fds
) != 0) << j
);
464 target_fds
[i
] = tswapl(v
);
470 #if defined(__alpha__)
476 static inline abi_long
host_to_target_clock_t(long ticks
)
478 #if HOST_HZ == TARGET_HZ
481 return ((int64_t)ticks
* TARGET_HZ
) / HOST_HZ
;
485 static inline void host_to_target_rusage(abi_ulong target_addr
,
486 const struct rusage
*rusage
)
488 struct target_rusage
*target_rusage
;
490 lock_user_struct(target_rusage
, target_addr
, 0);
491 target_rusage
->ru_utime
.tv_sec
= tswapl(rusage
->ru_utime
.tv_sec
);
492 target_rusage
->ru_utime
.tv_usec
= tswapl(rusage
->ru_utime
.tv_usec
);
493 target_rusage
->ru_stime
.tv_sec
= tswapl(rusage
->ru_stime
.tv_sec
);
494 target_rusage
->ru_stime
.tv_usec
= tswapl(rusage
->ru_stime
.tv_usec
);
495 target_rusage
->ru_maxrss
= tswapl(rusage
->ru_maxrss
);
496 target_rusage
->ru_ixrss
= tswapl(rusage
->ru_ixrss
);
497 target_rusage
->ru_idrss
= tswapl(rusage
->ru_idrss
);
498 target_rusage
->ru_isrss
= tswapl(rusage
->ru_isrss
);
499 target_rusage
->ru_minflt
= tswapl(rusage
->ru_minflt
);
500 target_rusage
->ru_majflt
= tswapl(rusage
->ru_majflt
);
501 target_rusage
->ru_nswap
= tswapl(rusage
->ru_nswap
);
502 target_rusage
->ru_inblock
= tswapl(rusage
->ru_inblock
);
503 target_rusage
->ru_oublock
= tswapl(rusage
->ru_oublock
);
504 target_rusage
->ru_msgsnd
= tswapl(rusage
->ru_msgsnd
);
505 target_rusage
->ru_msgrcv
= tswapl(rusage
->ru_msgrcv
);
506 target_rusage
->ru_nsignals
= tswapl(rusage
->ru_nsignals
);
507 target_rusage
->ru_nvcsw
= tswapl(rusage
->ru_nvcsw
);
508 target_rusage
->ru_nivcsw
= tswapl(rusage
->ru_nivcsw
);
509 unlock_user_struct(target_rusage
, target_addr
, 1);
512 static inline void target_to_host_timeval(struct timeval
*tv
,
513 abi_ulong target_addr
)
515 struct target_timeval
*target_tv
;
517 lock_user_struct(target_tv
, target_addr
, 1);
518 tv
->tv_sec
= tswapl(target_tv
->tv_sec
);
519 tv
->tv_usec
= tswapl(target_tv
->tv_usec
);
520 unlock_user_struct(target_tv
, target_addr
, 0);
523 static inline void host_to_target_timeval(abi_ulong target_addr
,
524 const struct timeval
*tv
)
526 struct target_timeval
*target_tv
;
528 lock_user_struct(target_tv
, target_addr
, 0);
529 target_tv
->tv_sec
= tswapl(tv
->tv_sec
);
530 target_tv
->tv_usec
= tswapl(tv
->tv_usec
);
531 unlock_user_struct(target_tv
, target_addr
, 1);
535 static abi_long
do_select(int n
,
536 abi_ulong rfd_p
, abi_ulong wfd_p
,
537 abi_ulong efd_p
, abi_ulong target_tv
)
539 fd_set rfds
, wfds
, efds
;
540 fd_set
*rfds_ptr
, *wfds_ptr
, *efds_ptr
;
541 abi_long
*target_rfds
, *target_wfds
, *target_efds
;
542 struct timeval tv
, *tv_ptr
;
547 target_rfds
= lock_user(rfd_p
, sizeof(abi_long
) * n
, 1);
548 rfds_ptr
= target_to_host_fds(&rfds
, target_rfds
, n
);
554 target_wfds
= lock_user(wfd_p
, sizeof(abi_long
) * n
, 1);
555 wfds_ptr
= target_to_host_fds(&wfds
, target_wfds
, n
);
561 target_efds
= lock_user(efd_p
, sizeof(abi_long
) * n
, 1);
562 efds_ptr
= target_to_host_fds(&efds
, target_efds
, n
);
569 target_to_host_timeval(&tv
, target_tv
);
574 ret
= get_errno(select(n
, rfds_ptr
, wfds_ptr
, efds_ptr
, tv_ptr
));
578 host_to_target_fds(target_rfds
, rfds_ptr
, n
);
579 host_to_target_fds(target_wfds
, wfds_ptr
, n
);
580 host_to_target_fds(target_efds
, efds_ptr
, n
);
583 host_to_target_timeval(target_tv
, &tv
);
587 unlock_user(target_rfds
, rfd_p
, ok
? sizeof(abi_long
) * n
: 0);
589 unlock_user(target_wfds
, wfd_p
, ok
? sizeof(abi_long
) * n
: 0);
591 unlock_user(target_efds
, efd_p
, ok
? sizeof(abi_long
) * n
: 0);
596 static inline void target_to_host_sockaddr(struct sockaddr
*addr
,
597 abi_ulong target_addr
,
600 struct target_sockaddr
*target_saddr
;
602 target_saddr
= lock_user(target_addr
, len
, 1);
603 memcpy(addr
, target_saddr
, len
);
604 addr
->sa_family
= tswap16(target_saddr
->sa_family
);
605 unlock_user(target_saddr
, target_addr
, 0);
608 static inline void host_to_target_sockaddr(abi_ulong target_addr
,
609 struct sockaddr
*addr
,
612 struct target_sockaddr
*target_saddr
;
614 target_saddr
= lock_user(target_addr
, len
, 0);
615 memcpy(target_saddr
, addr
, len
);
616 target_saddr
->sa_family
= tswap16(addr
->sa_family
);
617 unlock_user(target_saddr
, target_addr
, len
);
620 /* ??? Should this also swap msgh->name? */
621 static inline void target_to_host_cmsg(struct msghdr
*msgh
,
622 struct target_msghdr
*target_msgh
)
624 struct cmsghdr
*cmsg
= CMSG_FIRSTHDR(msgh
);
625 struct target_cmsghdr
*target_cmsg
= TARGET_CMSG_FIRSTHDR(target_msgh
);
628 while (cmsg
&& target_cmsg
) {
629 void *data
= CMSG_DATA(cmsg
);
630 void *target_data
= TARGET_CMSG_DATA(target_cmsg
);
632 int len
= tswapl(target_cmsg
->cmsg_len
)
633 - TARGET_CMSG_ALIGN(sizeof (struct target_cmsghdr
));
635 space
+= CMSG_SPACE(len
);
636 if (space
> msgh
->msg_controllen
) {
637 space
-= CMSG_SPACE(len
);
638 gemu_log("Host cmsg overflow\n");
642 cmsg
->cmsg_level
= tswap32(target_cmsg
->cmsg_level
);
643 cmsg
->cmsg_type
= tswap32(target_cmsg
->cmsg_type
);
644 cmsg
->cmsg_len
= CMSG_LEN(len
);
646 if (cmsg
->cmsg_level
!= TARGET_SOL_SOCKET
|| cmsg
->cmsg_type
!= SCM_RIGHTS
) {
647 gemu_log("Unsupported ancillary data: %d/%d\n", cmsg
->cmsg_level
, cmsg
->cmsg_type
);
648 memcpy(data
, target_data
, len
);
650 int *fd
= (int *)data
;
651 int *target_fd
= (int *)target_data
;
652 int i
, numfds
= len
/ sizeof(int);
654 for (i
= 0; i
< numfds
; i
++)
655 fd
[i
] = tswap32(target_fd
[i
]);
658 cmsg
= CMSG_NXTHDR(msgh
, cmsg
);
659 target_cmsg
= TARGET_CMSG_NXTHDR(target_msgh
, target_cmsg
);
662 msgh
->msg_controllen
= space
;
665 /* ??? Should this also swap msgh->name? */
666 static inline void host_to_target_cmsg(struct target_msghdr
*target_msgh
,
669 struct cmsghdr
*cmsg
= CMSG_FIRSTHDR(msgh
);
670 struct target_cmsghdr
*target_cmsg
= TARGET_CMSG_FIRSTHDR(target_msgh
);
673 while (cmsg
&& target_cmsg
) {
674 void *data
= CMSG_DATA(cmsg
);
675 void *target_data
= TARGET_CMSG_DATA(target_cmsg
);
677 int len
= cmsg
->cmsg_len
- CMSG_ALIGN(sizeof (struct cmsghdr
));
679 space
+= TARGET_CMSG_SPACE(len
);
680 if (space
> tswapl(target_msgh
->msg_controllen
)) {
681 space
-= TARGET_CMSG_SPACE(len
);
682 gemu_log("Target cmsg overflow\n");
686 target_cmsg
->cmsg_level
= tswap32(cmsg
->cmsg_level
);
687 target_cmsg
->cmsg_type
= tswap32(cmsg
->cmsg_type
);
688 target_cmsg
->cmsg_len
= tswapl(TARGET_CMSG_LEN(len
));
690 if (cmsg
->cmsg_level
!= TARGET_SOL_SOCKET
|| cmsg
->cmsg_type
!= SCM_RIGHTS
) {
691 gemu_log("Unsupported ancillary data: %d/%d\n", cmsg
->cmsg_level
, cmsg
->cmsg_type
);
692 memcpy(target_data
, data
, len
);
694 int *fd
= (int *)data
;
695 int *target_fd
= (int *)target_data
;
696 int i
, numfds
= len
/ sizeof(int);
698 for (i
= 0; i
< numfds
; i
++)
699 target_fd
[i
] = tswap32(fd
[i
]);
702 cmsg
= CMSG_NXTHDR(msgh
, cmsg
);
703 target_cmsg
= TARGET_CMSG_NXTHDR(target_msgh
, target_cmsg
);
706 msgh
->msg_controllen
= tswapl(space
);
709 static abi_long
do_setsockopt(int sockfd
, int level
, int optname
,
710 abi_ulong optval
, socklen_t optlen
)
717 /* TCP options all take an 'int' value. */
718 if (optlen
< sizeof(uint32_t))
721 val
= tget32(optval
);
722 ret
= get_errno(setsockopt(sockfd
, level
, optname
, &val
, sizeof(val
)));
729 case IP_ROUTER_ALERT
:
733 case IP_MTU_DISCOVER
:
739 case IP_MULTICAST_TTL
:
740 case IP_MULTICAST_LOOP
:
742 if (optlen
>= sizeof(uint32_t)) {
743 val
= tget32(optval
);
744 } else if (optlen
>= 1) {
747 ret
= get_errno(setsockopt(sockfd
, level
, optname
, &val
, sizeof(val
)));
753 case TARGET_SOL_SOCKET
:
755 /* Options with 'int' argument. */
756 case TARGET_SO_DEBUG
:
759 case TARGET_SO_REUSEADDR
:
760 optname
= SO_REUSEADDR
;
765 case TARGET_SO_ERROR
:
768 case TARGET_SO_DONTROUTE
:
769 optname
= SO_DONTROUTE
;
771 case TARGET_SO_BROADCAST
:
772 optname
= SO_BROADCAST
;
774 case TARGET_SO_SNDBUF
:
777 case TARGET_SO_RCVBUF
:
780 case TARGET_SO_KEEPALIVE
:
781 optname
= SO_KEEPALIVE
;
783 case TARGET_SO_OOBINLINE
:
784 optname
= SO_OOBINLINE
;
786 case TARGET_SO_NO_CHECK
:
787 optname
= SO_NO_CHECK
;
789 case TARGET_SO_PRIORITY
:
790 optname
= SO_PRIORITY
;
793 case TARGET_SO_BSDCOMPAT
:
794 optname
= SO_BSDCOMPAT
;
797 case TARGET_SO_PASSCRED
:
798 optname
= SO_PASSCRED
;
800 case TARGET_SO_TIMESTAMP
:
801 optname
= SO_TIMESTAMP
;
803 case TARGET_SO_RCVLOWAT
:
804 optname
= SO_RCVLOWAT
;
806 case TARGET_SO_RCVTIMEO
:
807 optname
= SO_RCVTIMEO
;
809 case TARGET_SO_SNDTIMEO
:
810 optname
= SO_SNDTIMEO
;
816 if (optlen
< sizeof(uint32_t))
819 val
= tget32(optval
);
820 ret
= get_errno(setsockopt(sockfd
, SOL_SOCKET
, optname
, &val
, sizeof(val
)));
824 gemu_log("Unsupported setsockopt level=%d optname=%d \n", level
, optname
);
830 static abi_long
do_getsockopt(int sockfd
, int level
, int optname
,
831 abi_ulong optval
, abi_ulong optlen
)
837 case TARGET_SOL_SOCKET
:
840 case TARGET_SO_LINGER
:
841 case TARGET_SO_RCVTIMEO
:
842 case TARGET_SO_SNDTIMEO
:
843 case TARGET_SO_PEERCRED
:
844 case TARGET_SO_PEERNAME
:
845 /* These don't just return a single integer */
852 /* TCP options all take an 'int' value. */
854 len
= tget32(optlen
);
858 ret
= get_errno(getsockopt(sockfd
, level
, optname
, &val
, &lv
));
875 case IP_ROUTER_ALERT
:
879 case IP_MTU_DISCOVER
:
885 case IP_MULTICAST_TTL
:
886 case IP_MULTICAST_LOOP
:
887 len
= tget32(optlen
);
891 ret
= get_errno(getsockopt(sockfd
, level
, optname
, &val
, &lv
));
894 if (len
< sizeof(int) && len
> 0 && val
>= 0 && val
< 255) {
899 if (len
> sizeof(int))
911 gemu_log("getsockopt level=%d optname=%d not yet supported\n",
919 static void lock_iovec(struct iovec
*vec
, abi_ulong target_addr
,
922 struct target_iovec
*target_vec
;
926 target_vec
= lock_user(target_addr
, count
* sizeof(struct target_iovec
), 1);
927 for(i
= 0;i
< count
; i
++) {
928 base
= tswapl(target_vec
[i
].iov_base
);
929 vec
[i
].iov_len
= tswapl(target_vec
[i
].iov_len
);
930 vec
[i
].iov_base
= lock_user(base
, vec
[i
].iov_len
, copy
);
932 unlock_user (target_vec
, target_addr
, 0);
935 static void unlock_iovec(struct iovec
*vec
, abi_ulong target_addr
,
938 struct target_iovec
*target_vec
;
942 target_vec
= lock_user(target_addr
, count
* sizeof(struct target_iovec
), 1);
943 for(i
= 0;i
< count
; i
++) {
944 base
= tswapl(target_vec
[i
].iov_base
);
945 unlock_user(vec
[i
].iov_base
, base
, copy
? vec
[i
].iov_len
: 0);
947 unlock_user (target_vec
, target_addr
, 0);
950 static abi_long
do_socket(int domain
, int type
, int protocol
)
952 #if defined(TARGET_MIPS)
954 case TARGET_SOCK_DGRAM
:
957 case TARGET_SOCK_STREAM
:
960 case TARGET_SOCK_RAW
:
963 case TARGET_SOCK_RDM
:
966 case TARGET_SOCK_SEQPACKET
:
967 type
= SOCK_SEQPACKET
;
969 case TARGET_SOCK_PACKET
:
974 return get_errno(socket(domain
, type
, protocol
));
977 static abi_long
do_bind(int sockfd
, abi_ulong target_addr
,
980 void *addr
= alloca(addrlen
);
982 target_to_host_sockaddr(addr
, target_addr
, addrlen
);
983 return get_errno(bind(sockfd
, addr
, addrlen
));
986 static abi_long
do_connect(int sockfd
, abi_ulong target_addr
,
989 void *addr
= alloca(addrlen
);
991 target_to_host_sockaddr(addr
, target_addr
, addrlen
);
992 return get_errno(connect(sockfd
, addr
, addrlen
));
995 static abi_long
do_sendrecvmsg(int fd
, abi_ulong target_msg
,
999 struct target_msghdr
*msgp
;
1003 abi_ulong target_vec
;
1005 lock_user_struct(msgp
, target_msg
, 1);
1006 if (msgp
->msg_name
) {
1007 msg
.msg_namelen
= tswap32(msgp
->msg_namelen
);
1008 msg
.msg_name
= alloca(msg
.msg_namelen
);
1009 target_to_host_sockaddr(msg
.msg_name
, tswapl(msgp
->msg_name
),
1012 msg
.msg_name
= NULL
;
1013 msg
.msg_namelen
= 0;
1015 msg
.msg_controllen
= 2 * tswapl(msgp
->msg_controllen
);
1016 msg
.msg_control
= alloca(msg
.msg_controllen
);
1017 msg
.msg_flags
= tswap32(msgp
->msg_flags
);
1019 count
= tswapl(msgp
->msg_iovlen
);
1020 vec
= alloca(count
* sizeof(struct iovec
));
1021 target_vec
= tswapl(msgp
->msg_iov
);
1022 lock_iovec(vec
, target_vec
, count
, send
);
1023 msg
.msg_iovlen
= count
;
1027 target_to_host_cmsg(&msg
, msgp
);
1028 ret
= get_errno(sendmsg(fd
, &msg
, flags
));
1030 ret
= get_errno(recvmsg(fd
, &msg
, flags
));
1032 host_to_target_cmsg(msgp
, &msg
);
1034 unlock_iovec(vec
, target_vec
, count
, !send
);
1038 static abi_long
do_accept(int fd
, abi_ulong target_addr
,
1039 abi_ulong target_addrlen
)
1041 socklen_t addrlen
= tget32(target_addrlen
);
1042 void *addr
= alloca(addrlen
);
1045 ret
= get_errno(accept(fd
, addr
, &addrlen
));
1046 if (!is_error(ret
)) {
1047 host_to_target_sockaddr(target_addr
, addr
, addrlen
);
1048 tput32(target_addrlen
, addrlen
);
1053 static abi_long
do_getpeername(int fd
, abi_ulong target_addr
,
1054 abi_ulong target_addrlen
)
1056 socklen_t addrlen
= tget32(target_addrlen
);
1057 void *addr
= alloca(addrlen
);
1060 ret
= get_errno(getpeername(fd
, addr
, &addrlen
));
1061 if (!is_error(ret
)) {
1062 host_to_target_sockaddr(target_addr
, addr
, addrlen
);
1063 tput32(target_addrlen
, addrlen
);
1068 static abi_long
do_getsockname(int fd
, abi_ulong target_addr
,
1069 abi_ulong target_addrlen
)
1071 socklen_t addrlen
= tget32(target_addrlen
);
1072 void *addr
= alloca(addrlen
);
1075 ret
= get_errno(getsockname(fd
, addr
, &addrlen
));
1076 if (!is_error(ret
)) {
1077 host_to_target_sockaddr(target_addr
, addr
, addrlen
);
1078 tput32(target_addrlen
, addrlen
);
1083 static abi_long
do_socketpair(int domain
, int type
, int protocol
,
1084 abi_ulong target_tab
)
1089 ret
= get_errno(socketpair(domain
, type
, protocol
, tab
));
1090 if (!is_error(ret
)) {
1091 tput32(target_tab
, tab
[0]);
1092 tput32(target_tab
+ 4, tab
[1]);
1097 static abi_long
do_sendto(int fd
, abi_ulong msg
, size_t len
, int flags
,
1098 abi_ulong target_addr
, socklen_t addrlen
)
1104 host_msg
= lock_user(msg
, len
, 1);
1106 addr
= alloca(addrlen
);
1107 target_to_host_sockaddr(addr
, target_addr
, addrlen
);
1108 ret
= get_errno(sendto(fd
, host_msg
, len
, flags
, addr
, addrlen
));
1110 ret
= get_errno(send(fd
, host_msg
, len
, flags
));
1112 unlock_user(host_msg
, msg
, 0);
1116 static abi_long
do_recvfrom(int fd
, abi_ulong msg
, size_t len
, int flags
,
1117 abi_ulong target_addr
,
1118 abi_ulong target_addrlen
)
1125 host_msg
= lock_user(msg
, len
, 0);
1127 addrlen
= tget32(target_addrlen
);
1128 addr
= alloca(addrlen
);
1129 ret
= get_errno(recvfrom(fd
, host_msg
, len
, flags
, addr
, &addrlen
));
1131 addr
= NULL
; /* To keep compiler quiet. */
1132 ret
= get_errno(recv(fd
, host_msg
, len
, flags
));
1134 if (!is_error(ret
)) {
1136 host_to_target_sockaddr(target_addr
, addr
, addrlen
);
1137 tput32(target_addrlen
, addrlen
);
1139 unlock_user(host_msg
, msg
, len
);
1141 unlock_user(host_msg
, msg
, 0);
1146 #ifdef TARGET_NR_socketcall
1147 static abi_long
do_socketcall(int num
, abi_ulong vptr
)
1150 const int n
= sizeof(abi_ulong
);
1155 int domain
= tgetl(vptr
);
1156 int type
= tgetl(vptr
+ n
);
1157 int protocol
= tgetl(vptr
+ 2 * n
);
1158 ret
= do_socket(domain
, type
, protocol
);
1163 int sockfd
= tgetl(vptr
);
1164 abi_ulong target_addr
= tgetl(vptr
+ n
);
1165 socklen_t addrlen
= tgetl(vptr
+ 2 * n
);
1166 ret
= do_bind(sockfd
, target_addr
, addrlen
);
1169 case SOCKOP_connect
:
1171 int sockfd
= tgetl(vptr
);
1172 abi_ulong target_addr
= tgetl(vptr
+ n
);
1173 socklen_t addrlen
= tgetl(vptr
+ 2 * n
);
1174 ret
= do_connect(sockfd
, target_addr
, addrlen
);
1179 int sockfd
= tgetl(vptr
);
1180 int backlog
= tgetl(vptr
+ n
);
1181 ret
= get_errno(listen(sockfd
, backlog
));
1186 int sockfd
= tgetl(vptr
);
1187 abi_ulong target_addr
= tgetl(vptr
+ n
);
1188 abi_ulong target_addrlen
= tgetl(vptr
+ 2 * n
);
1189 ret
= do_accept(sockfd
, target_addr
, target_addrlen
);
1192 case SOCKOP_getsockname
:
1194 int sockfd
= tgetl(vptr
);
1195 abi_ulong target_addr
= tgetl(vptr
+ n
);
1196 abi_ulong target_addrlen
= tgetl(vptr
+ 2 * n
);
1197 ret
= do_getsockname(sockfd
, target_addr
, target_addrlen
);
1200 case SOCKOP_getpeername
:
1202 int sockfd
= tgetl(vptr
);
1203 abi_ulong target_addr
= tgetl(vptr
+ n
);
1204 abi_ulong target_addrlen
= tgetl(vptr
+ 2 * n
);
1205 ret
= do_getpeername(sockfd
, target_addr
, target_addrlen
);
1208 case SOCKOP_socketpair
:
1210 int domain
= tgetl(vptr
);
1211 int type
= tgetl(vptr
+ n
);
1212 int protocol
= tgetl(vptr
+ 2 * n
);
1213 abi_ulong tab
= tgetl(vptr
+ 3 * n
);
1214 ret
= do_socketpair(domain
, type
, protocol
, tab
);
1219 int sockfd
= tgetl(vptr
);
1220 abi_ulong msg
= tgetl(vptr
+ n
);
1221 size_t len
= tgetl(vptr
+ 2 * n
);
1222 int flags
= tgetl(vptr
+ 3 * n
);
1223 ret
= do_sendto(sockfd
, msg
, len
, flags
, 0, 0);
1228 int sockfd
= tgetl(vptr
);
1229 abi_ulong msg
= tgetl(vptr
+ n
);
1230 size_t len
= tgetl(vptr
+ 2 * n
);
1231 int flags
= tgetl(vptr
+ 3 * n
);
1232 ret
= do_recvfrom(sockfd
, msg
, len
, flags
, 0, 0);
1237 int sockfd
= tgetl(vptr
);
1238 abi_ulong msg
= tgetl(vptr
+ n
);
1239 size_t len
= tgetl(vptr
+ 2 * n
);
1240 int flags
= tgetl(vptr
+ 3 * n
);
1241 abi_ulong addr
= tgetl(vptr
+ 4 * n
);
1242 socklen_t addrlen
= tgetl(vptr
+ 5 * n
);
1243 ret
= do_sendto(sockfd
, msg
, len
, flags
, addr
, addrlen
);
1246 case SOCKOP_recvfrom
:
1248 int sockfd
= tgetl(vptr
);
1249 abi_ulong msg
= tgetl(vptr
+ n
);
1250 size_t len
= tgetl(vptr
+ 2 * n
);
1251 int flags
= tgetl(vptr
+ 3 * n
);
1252 abi_ulong addr
= tgetl(vptr
+ 4 * n
);
1253 abi_ulong addrlen
= tgetl(vptr
+ 5 * n
);
1254 ret
= do_recvfrom(sockfd
, msg
, len
, flags
, addr
, addrlen
);
1257 case SOCKOP_shutdown
:
1259 int sockfd
= tgetl(vptr
);
1260 int how
= tgetl(vptr
+ n
);
1262 ret
= get_errno(shutdown(sockfd
, how
));
1265 case SOCKOP_sendmsg
:
1266 case SOCKOP_recvmsg
:
1269 abi_ulong target_msg
;
1273 target_msg
= tgetl(vptr
+ n
);
1274 flags
= tgetl(vptr
+ 2 * n
);
1276 ret
= do_sendrecvmsg(fd
, target_msg
, flags
,
1277 (num
== SOCKOP_sendmsg
));
1280 case SOCKOP_setsockopt
:
1282 int sockfd
= tgetl(vptr
);
1283 int level
= tgetl(vptr
+ n
);
1284 int optname
= tgetl(vptr
+ 2 * n
);
1285 abi_ulong optval
= tgetl(vptr
+ 3 * n
);
1286 socklen_t optlen
= tgetl(vptr
+ 4 * n
);
1288 ret
= do_setsockopt(sockfd
, level
, optname
, optval
, optlen
);
1291 case SOCKOP_getsockopt
:
1293 int sockfd
= tgetl(vptr
);
1294 int level
= tgetl(vptr
+ n
);
1295 int optname
= tgetl(vptr
+ 2 * n
);
1296 abi_ulong optval
= tgetl(vptr
+ 3 * n
);
1297 abi_ulong poptlen
= tgetl(vptr
+ 4 * n
);
1299 ret
= do_getsockopt(sockfd
, level
, optname
, optval
, poptlen
);
1303 gemu_log("Unsupported socketcall: %d\n", num
);
1311 #ifdef TARGET_NR_ipc
1312 #define N_SHM_REGIONS 32
1314 static struct shm_region
{
1317 } shm_regions
[N_SHM_REGIONS
];
1319 struct target_ipc_perm
1326 unsigned short int mode
;
1327 unsigned short int __pad1
;
1328 unsigned short int __seq
;
1329 unsigned short int __pad2
;
1330 abi_ulong __unused1
;
1331 abi_ulong __unused2
;
1334 struct target_semid_ds
1336 struct target_ipc_perm sem_perm
;
1337 abi_ulong sem_otime
;
1338 abi_ulong __unused1
;
1339 abi_ulong sem_ctime
;
1340 abi_ulong __unused2
;
1341 abi_ulong sem_nsems
;
1342 abi_ulong __unused3
;
1343 abi_ulong __unused4
;
1346 static inline void target_to_host_ipc_perm(struct ipc_perm
*host_ip
,
1347 abi_ulong target_addr
)
1349 struct target_ipc_perm
*target_ip
;
1350 struct target_semid_ds
*target_sd
;
1352 lock_user_struct(target_sd
, target_addr
, 1);
1353 target_ip
=&(target_sd
->sem_perm
);
1354 host_ip
->__key
= tswapl(target_ip
->__key
);
1355 host_ip
->uid
= tswapl(target_ip
->uid
);
1356 host_ip
->gid
= tswapl(target_ip
->gid
);
1357 host_ip
->cuid
= tswapl(target_ip
->cuid
);
1358 host_ip
->cgid
= tswapl(target_ip
->cgid
);
1359 host_ip
->mode
= tswapl(target_ip
->mode
);
1360 unlock_user_struct(target_sd
, target_addr
, 0);
1363 static inline void host_to_target_ipc_perm(abi_ulong target_addr
,
1364 struct ipc_perm
*host_ip
)
1366 struct target_ipc_perm
*target_ip
;
1367 struct target_semid_ds
*target_sd
;
1369 lock_user_struct(target_sd
, target_addr
, 0);
1370 target_ip
= &(target_sd
->sem_perm
);
1371 target_ip
->__key
= tswapl(host_ip
->__key
);
1372 target_ip
->uid
= tswapl(host_ip
->uid
);
1373 target_ip
->gid
= tswapl(host_ip
->gid
);
1374 target_ip
->cuid
= tswapl(host_ip
->cuid
);
1375 target_ip
->cgid
= tswapl(host_ip
->cgid
);
1376 target_ip
->mode
= tswapl(host_ip
->mode
);
1377 unlock_user_struct(target_sd
, target_addr
, 1);
1380 static inline void target_to_host_semid_ds(struct semid_ds
*host_sd
,
1381 abi_ulong target_addr
)
1383 struct target_semid_ds
*target_sd
;
1385 lock_user_struct(target_sd
, target_addr
, 1);
1386 target_to_host_ipc_perm(&(host_sd
->sem_perm
),target_addr
);
1387 host_sd
->sem_nsems
= tswapl(target_sd
->sem_nsems
);
1388 host_sd
->sem_otime
= tswapl(target_sd
->sem_otime
);
1389 host_sd
->sem_ctime
= tswapl(target_sd
->sem_ctime
);
1390 unlock_user_struct(target_sd
, target_addr
, 0);
1393 static inline void host_to_target_semid_ds(abi_ulong target_addr
,
1394 struct semid_ds
*host_sd
)
1396 struct target_semid_ds
*target_sd
;
1398 lock_user_struct(target_sd
, target_addr
, 0);
1399 host_to_target_ipc_perm(target_addr
,&(host_sd
->sem_perm
));
1400 target_sd
->sem_nsems
= tswapl(host_sd
->sem_nsems
);
1401 target_sd
->sem_otime
= tswapl(host_sd
->sem_otime
);
1402 target_sd
->sem_ctime
= tswapl(host_sd
->sem_ctime
);
1403 unlock_user_struct(target_sd
, target_addr
, 1);
1408 struct semid_ds
*buf
;
1409 unsigned short *array
;
1412 union target_semun
{
1415 unsigned short int *array
;
1418 static inline void target_to_host_semun(int cmd
,
1419 union semun
*host_su
,
1420 abi_ulong target_addr
,
1421 struct semid_ds
*ds
)
1423 union target_semun
*target_su
;
1428 lock_user_struct(target_su
, target_addr
, 1);
1429 target_to_host_semid_ds(ds
,target_su
->buf
);
1431 unlock_user_struct(target_su
, target_addr
, 0);
1435 lock_user_struct(target_su
, target_addr
, 1);
1436 host_su
->val
= tswapl(target_su
->val
);
1437 unlock_user_struct(target_su
, target_addr
, 0);
1441 lock_user_struct(target_su
, target_addr
, 1);
1442 *host_su
->array
= tswap16(*target_su
->array
);
1443 unlock_user_struct(target_su
, target_addr
, 0);
1446 gemu_log("semun operation not fully supported: %d\n", (int)cmd
);
1450 static inline void host_to_target_semun(int cmd
,
1451 abi_ulong target_addr
,
1452 union semun
*host_su
,
1453 struct semid_ds
*ds
)
1455 union target_semun
*target_su
;
1460 lock_user_struct(target_su
, target_addr
, 0);
1461 host_to_target_semid_ds(target_su
->buf
,ds
);
1462 unlock_user_struct(target_su
, target_addr
, 1);
1466 lock_user_struct(target_su
, target_addr
, 0);
1467 target_su
->val
= tswapl(host_su
->val
);
1468 unlock_user_struct(target_su
, target_addr
, 1);
1472 lock_user_struct(target_su
, target_addr
, 0);
1473 *target_su
->array
= tswap16(*host_su
->array
);
1474 unlock_user_struct(target_su
, target_addr
, 1);
1477 gemu_log("semun operation not fully supported: %d\n", (int)cmd
);
1481 static inline abi_long
do_semctl(int first
, int second
, int third
,
1485 struct semid_ds dsarg
;
1486 int cmd
= third
&0xff;
1491 target_to_host_semun(cmd
,&arg
,ptr
,&dsarg
);
1492 ret
= get_errno(semctl(first
, second
, cmd
, arg
));
1493 host_to_target_semun(cmd
,ptr
,&arg
,&dsarg
);
1496 target_to_host_semun(cmd
,&arg
,ptr
,&dsarg
);
1497 ret
= get_errno(semctl(first
, second
, cmd
, arg
));
1498 host_to_target_semun(cmd
,ptr
,&arg
,&dsarg
);
1501 target_to_host_semun(cmd
,&arg
,ptr
,&dsarg
);
1502 ret
= get_errno(semctl(first
, second
, cmd
, arg
));
1503 host_to_target_semun(cmd
,ptr
,&arg
,&dsarg
);
1506 target_to_host_semun(cmd
,&arg
,ptr
,&dsarg
);
1507 ret
= get_errno(semctl(first
, second
, cmd
, arg
));
1508 host_to_target_semun(cmd
,ptr
,&arg
,&dsarg
);
1511 target_to_host_semun(cmd
,&arg
,ptr
,&dsarg
);
1512 ret
= get_errno(semctl(first
, second
, cmd
, arg
));
1513 host_to_target_semun(cmd
,ptr
,&arg
,&dsarg
);
1516 target_to_host_semun(cmd
,&arg
,ptr
,&dsarg
);
1517 ret
= get_errno(semctl(first
, second
, cmd
, arg
));
1518 host_to_target_semun(cmd
,ptr
,&arg
,&dsarg
);
1521 ret
= get_errno(semctl(first
, second
, cmd
, arg
));
1527 struct target_msqid_ds
1529 struct target_ipc_perm msg_perm
;
1530 abi_ulong msg_stime
;
1531 abi_ulong __unused1
;
1532 abi_ulong msg_rtime
;
1533 abi_ulong __unused2
;
1534 abi_ulong msg_ctime
;
1535 abi_ulong __unused3
;
1536 abi_ulong __msg_cbytes
;
1538 abi_ulong msg_qbytes
;
1539 abi_ulong msg_lspid
;
1540 abi_ulong msg_lrpid
;
1541 abi_ulong __unused4
;
1542 abi_ulong __unused5
;
1545 static inline void target_to_host_msqid_ds(struct msqid_ds
*host_md
,
1546 abi_ulong target_addr
)
1548 struct target_msqid_ds
*target_md
;
1550 lock_user_struct(target_md
, target_addr
, 1);
1551 target_to_host_ipc_perm(&(host_md
->msg_perm
),target_addr
);
1552 host_md
->msg_stime
= tswapl(target_md
->msg_stime
);
1553 host_md
->msg_rtime
= tswapl(target_md
->msg_rtime
);
1554 host_md
->msg_ctime
= tswapl(target_md
->msg_ctime
);
1555 host_md
->__msg_cbytes
= tswapl(target_md
->__msg_cbytes
);
1556 host_md
->msg_qnum
= tswapl(target_md
->msg_qnum
);
1557 host_md
->msg_qbytes
= tswapl(target_md
->msg_qbytes
);
1558 host_md
->msg_lspid
= tswapl(target_md
->msg_lspid
);
1559 host_md
->msg_lrpid
= tswapl(target_md
->msg_lrpid
);
1560 unlock_user_struct(target_md
, target_addr
, 0);
1563 static inline void host_to_target_msqid_ds(abi_ulong target_addr
,
1564 struct msqid_ds
*host_md
)
1566 struct target_msqid_ds
*target_md
;
1568 lock_user_struct(target_md
, target_addr
, 0);
1569 host_to_target_ipc_perm(target_addr
,&(host_md
->msg_perm
));
1570 target_md
->msg_stime
= tswapl(host_md
->msg_stime
);
1571 target_md
->msg_rtime
= tswapl(host_md
->msg_rtime
);
1572 target_md
->msg_ctime
= tswapl(host_md
->msg_ctime
);
1573 target_md
->__msg_cbytes
= tswapl(host_md
->__msg_cbytes
);
1574 target_md
->msg_qnum
= tswapl(host_md
->msg_qnum
);
1575 target_md
->msg_qbytes
= tswapl(host_md
->msg_qbytes
);
1576 target_md
->msg_lspid
= tswapl(host_md
->msg_lspid
);
1577 target_md
->msg_lrpid
= tswapl(host_md
->msg_lrpid
);
1578 unlock_user_struct(target_md
, target_addr
, 1);
1581 static inline abi_long
do_msgctl(int first
, int second
, abi_long ptr
)
1583 struct msqid_ds dsarg
;
1584 int cmd
= second
&0xff;
1589 target_to_host_msqid_ds(&dsarg
,ptr
);
1590 ret
= get_errno(msgctl(first
, cmd
, &dsarg
));
1591 host_to_target_msqid_ds(ptr
,&dsarg
);
1593 ret
= get_errno(msgctl(first
, cmd
, &dsarg
));
1598 struct target_msgbuf
{
1603 static inline abi_long
do_msgsnd(int msqid
, abi_long msgp
,
1604 unsigned int msgsz
, int msgflg
)
1606 struct target_msgbuf
*target_mb
;
1607 struct msgbuf
*host_mb
;
1610 lock_user_struct(target_mb
,msgp
,0);
1611 host_mb
= malloc(msgsz
+sizeof(long));
1612 host_mb
->mtype
= tswapl(target_mb
->mtype
);
1613 memcpy(host_mb
->mtext
,target_mb
->mtext
,msgsz
);
1614 ret
= get_errno(msgsnd(msqid
, host_mb
, msgsz
, msgflg
));
1616 unlock_user_struct(target_mb
, msgp
, 0);
1621 static inline abi_long
do_msgrcv(int msqid
, abi_long msgp
,
1622 unsigned int msgsz
, int msgtype
,
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 ret
= get_errno(msgrcv(msqid
, host_mb
, msgsz
, 1, msgflg
));
1633 memcpy(target_mb
->mtext
, host_mb
->mtext
, ret
);
1634 target_mb
->mtype
= tswapl(host_mb
->mtype
);
1636 unlock_user_struct(target_mb
, msgp
, 0);
1641 /* ??? This only works with linear mappings. */
1642 static abi_long
do_ipc(unsigned int call
, int first
,
1643 int second
, int third
,
1644 abi_long ptr
, abi_long fifth
)
1648 unsigned long raddr
;
1649 struct shmid_ds shm_info
;
1652 version
= call
>> 16;
1657 ret
= get_errno(semop(first
,(struct sembuf
*) ptr
, second
));
1661 ret
= get_errno(semget(first
, second
, third
));
1665 ret
= do_semctl(first
, second
, third
, ptr
);
1668 case IPCOP_semtimedop
:
1669 gemu_log("Unsupported ipc call: %d (version %d)\n", call
, version
);
1674 ret
= get_errno(msgget(first
, second
));
1678 ret
= do_msgsnd(first
, ptr
, second
, third
);
1682 ret
= do_msgctl(first
, second
, ptr
);
1689 void *__unbounded msgp
;
1693 struct ipc_kludge
*foo
= (struct ipc_kludge
*) ptr
;
1694 struct msgbuf
*msgp
= (struct msgbuf
*) foo
->msgp
;
1696 ret
= do_msgrcv(first
, (long)msgp
, second
, 0, third
);
1702 /* SHM_* flags are the same on all linux platforms */
1703 ret
= get_errno((long) shmat(first
, (void *) ptr
, second
));
1707 /* find out the length of the shared memory segment */
1709 ret
= get_errno(shmctl(first
, IPC_STAT
, &shm_info
));
1710 if (is_error(ret
)) {
1711 /* can't get length, bail out */
1712 shmdt((void *) raddr
);
1715 page_set_flags(raddr
, raddr
+ shm_info
.shm_segsz
,
1716 PAGE_VALID
| PAGE_READ
|
1717 ((second
& SHM_RDONLY
)? 0: PAGE_WRITE
));
1718 for (i
= 0; i
< N_SHM_REGIONS
; ++i
) {
1719 if (shm_regions
[i
].start
== 0) {
1720 shm_regions
[i
].start
= raddr
;
1721 shm_regions
[i
].size
= shm_info
.shm_segsz
;
1725 if (put_user(raddr
, (abi_ulong
*)third
))
1730 for (i
= 0; i
< N_SHM_REGIONS
; ++i
) {
1731 if (shm_regions
[i
].start
== ptr
) {
1732 shm_regions
[i
].start
= 0;
1733 page_set_flags(ptr
, shm_regions
[i
].size
, 0);
1737 ret
= get_errno(shmdt((void *) ptr
));
1741 /* IPC_* flag values are the same on all linux platforms */
1742 ret
= get_errno(shmget(first
, second
, third
));
1745 /* IPC_* and SHM_* command values are the same on all linux platforms */
1751 ret
= get_errno(shmctl(first
, second
, NULL
));
1759 gemu_log("Unsupported ipc call: %d (version %d)\n", call
, version
);
1767 /* kernel structure types definitions */
1770 #define STRUCT(name, list...) STRUCT_ ## name,
1771 #define STRUCT_SPECIAL(name) STRUCT_ ## name,
1773 #include "syscall_types.h"
1776 #undef STRUCT_SPECIAL
1778 #define STRUCT(name, list...) const argtype struct_ ## name ## _def[] = { list, TYPE_NULL };
1779 #define STRUCT_SPECIAL(name)
1780 #include "syscall_types.h"
1782 #undef STRUCT_SPECIAL
1784 typedef struct IOCTLEntry
{
1785 unsigned int target_cmd
;
1786 unsigned int host_cmd
;
1789 const argtype arg_type
[5];
1792 #define IOC_R 0x0001
1793 #define IOC_W 0x0002
1794 #define IOC_RW (IOC_R | IOC_W)
1796 #define MAX_STRUCT_SIZE 4096
1798 IOCTLEntry ioctl_entries
[] = {
1799 #define IOCTL(cmd, access, types...) \
1800 { TARGET_ ## cmd, cmd, #cmd, access, { types } },
1805 /* ??? Implement proper locking for ioctls. */
1806 static abi_long
do_ioctl(int fd
, abi_long cmd
, abi_long arg
)
1808 const IOCTLEntry
*ie
;
1809 const argtype
*arg_type
;
1811 uint8_t buf_temp
[MAX_STRUCT_SIZE
];
1817 if (ie
->target_cmd
== 0) {
1818 gemu_log("Unsupported ioctl: cmd=0x%04lx\n", (long)cmd
);
1821 if (ie
->target_cmd
== cmd
)
1825 arg_type
= ie
->arg_type
;
1827 gemu_log("ioctl: cmd=0x%04lx (%s)\n", (long)cmd
, ie
->name
);
1829 switch(arg_type
[0]) {
1832 ret
= get_errno(ioctl(fd
, ie
->host_cmd
));
1837 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, arg
));
1841 target_size
= thunk_type_size(arg_type
, 0);
1842 switch(ie
->access
) {
1844 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, buf_temp
));
1845 if (!is_error(ret
)) {
1846 argptr
= lock_user(arg
, target_size
, 0);
1847 thunk_convert(argptr
, buf_temp
, arg_type
, THUNK_TARGET
);
1848 unlock_user(argptr
, arg
, target_size
);
1852 argptr
= lock_user(arg
, target_size
, 1);
1853 thunk_convert(buf_temp
, argptr
, arg_type
, THUNK_HOST
);
1854 unlock_user(argptr
, arg
, 0);
1855 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, buf_temp
));
1859 argptr
= lock_user(arg
, target_size
, 1);
1860 thunk_convert(buf_temp
, argptr
, arg_type
, THUNK_HOST
);
1861 unlock_user(argptr
, arg
, 0);
1862 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, buf_temp
));
1863 if (!is_error(ret
)) {
1864 argptr
= lock_user(arg
, target_size
, 0);
1865 thunk_convert(argptr
, buf_temp
, arg_type
, THUNK_TARGET
);
1866 unlock_user(argptr
, arg
, target_size
);
1872 gemu_log("Unsupported ioctl type: cmd=0x%04lx type=%d\n",
1873 (long)cmd
, arg_type
[0]);
1880 bitmask_transtbl iflag_tbl
[] = {
1881 { TARGET_IGNBRK
, TARGET_IGNBRK
, IGNBRK
, IGNBRK
},
1882 { TARGET_BRKINT
, TARGET_BRKINT
, BRKINT
, BRKINT
},
1883 { TARGET_IGNPAR
, TARGET_IGNPAR
, IGNPAR
, IGNPAR
},
1884 { TARGET_PARMRK
, TARGET_PARMRK
, PARMRK
, PARMRK
},
1885 { TARGET_INPCK
, TARGET_INPCK
, INPCK
, INPCK
},
1886 { TARGET_ISTRIP
, TARGET_ISTRIP
, ISTRIP
, ISTRIP
},
1887 { TARGET_INLCR
, TARGET_INLCR
, INLCR
, INLCR
},
1888 { TARGET_IGNCR
, TARGET_IGNCR
, IGNCR
, IGNCR
},
1889 { TARGET_ICRNL
, TARGET_ICRNL
, ICRNL
, ICRNL
},
1890 { TARGET_IUCLC
, TARGET_IUCLC
, IUCLC
, IUCLC
},
1891 { TARGET_IXON
, TARGET_IXON
, IXON
, IXON
},
1892 { TARGET_IXANY
, TARGET_IXANY
, IXANY
, IXANY
},
1893 { TARGET_IXOFF
, TARGET_IXOFF
, IXOFF
, IXOFF
},
1894 { TARGET_IMAXBEL
, TARGET_IMAXBEL
, IMAXBEL
, IMAXBEL
},
1898 bitmask_transtbl oflag_tbl
[] = {
1899 { TARGET_OPOST
, TARGET_OPOST
, OPOST
, OPOST
},
1900 { TARGET_OLCUC
, TARGET_OLCUC
, OLCUC
, OLCUC
},
1901 { TARGET_ONLCR
, TARGET_ONLCR
, ONLCR
, ONLCR
},
1902 { TARGET_OCRNL
, TARGET_OCRNL
, OCRNL
, OCRNL
},
1903 { TARGET_ONOCR
, TARGET_ONOCR
, ONOCR
, ONOCR
},
1904 { TARGET_ONLRET
, TARGET_ONLRET
, ONLRET
, ONLRET
},
1905 { TARGET_OFILL
, TARGET_OFILL
, OFILL
, OFILL
},
1906 { TARGET_OFDEL
, TARGET_OFDEL
, OFDEL
, OFDEL
},
1907 { TARGET_NLDLY
, TARGET_NL0
, NLDLY
, NL0
},
1908 { TARGET_NLDLY
, TARGET_NL1
, NLDLY
, NL1
},
1909 { TARGET_CRDLY
, TARGET_CR0
, CRDLY
, CR0
},
1910 { TARGET_CRDLY
, TARGET_CR1
, CRDLY
, CR1
},
1911 { TARGET_CRDLY
, TARGET_CR2
, CRDLY
, CR2
},
1912 { TARGET_CRDLY
, TARGET_CR3
, CRDLY
, CR3
},
1913 { TARGET_TABDLY
, TARGET_TAB0
, TABDLY
, TAB0
},
1914 { TARGET_TABDLY
, TARGET_TAB1
, TABDLY
, TAB1
},
1915 { TARGET_TABDLY
, TARGET_TAB2
, TABDLY
, TAB2
},
1916 { TARGET_TABDLY
, TARGET_TAB3
, TABDLY
, TAB3
},
1917 { TARGET_BSDLY
, TARGET_BS0
, BSDLY
, BS0
},
1918 { TARGET_BSDLY
, TARGET_BS1
, BSDLY
, BS1
},
1919 { TARGET_VTDLY
, TARGET_VT0
, VTDLY
, VT0
},
1920 { TARGET_VTDLY
, TARGET_VT1
, VTDLY
, VT1
},
1921 { TARGET_FFDLY
, TARGET_FF0
, FFDLY
, FF0
},
1922 { TARGET_FFDLY
, TARGET_FF1
, FFDLY
, FF1
},
1926 bitmask_transtbl cflag_tbl
[] = {
1927 { TARGET_CBAUD
, TARGET_B0
, CBAUD
, B0
},
1928 { TARGET_CBAUD
, TARGET_B50
, CBAUD
, B50
},
1929 { TARGET_CBAUD
, TARGET_B75
, CBAUD
, B75
},
1930 { TARGET_CBAUD
, TARGET_B110
, CBAUD
, B110
},
1931 { TARGET_CBAUD
, TARGET_B134
, CBAUD
, B134
},
1932 { TARGET_CBAUD
, TARGET_B150
, CBAUD
, B150
},
1933 { TARGET_CBAUD
, TARGET_B200
, CBAUD
, B200
},
1934 { TARGET_CBAUD
, TARGET_B300
, CBAUD
, B300
},
1935 { TARGET_CBAUD
, TARGET_B600
, CBAUD
, B600
},
1936 { TARGET_CBAUD
, TARGET_B1200
, CBAUD
, B1200
},
1937 { TARGET_CBAUD
, TARGET_B1800
, CBAUD
, B1800
},
1938 { TARGET_CBAUD
, TARGET_B2400
, CBAUD
, B2400
},
1939 { TARGET_CBAUD
, TARGET_B4800
, CBAUD
, B4800
},
1940 { TARGET_CBAUD
, TARGET_B9600
, CBAUD
, B9600
},
1941 { TARGET_CBAUD
, TARGET_B19200
, CBAUD
, B19200
},
1942 { TARGET_CBAUD
, TARGET_B38400
, CBAUD
, B38400
},
1943 { TARGET_CBAUD
, TARGET_B57600
, CBAUD
, B57600
},
1944 { TARGET_CBAUD
, TARGET_B115200
, CBAUD
, B115200
},
1945 { TARGET_CBAUD
, TARGET_B230400
, CBAUD
, B230400
},
1946 { TARGET_CBAUD
, TARGET_B460800
, CBAUD
, B460800
},
1947 { TARGET_CSIZE
, TARGET_CS5
, CSIZE
, CS5
},
1948 { TARGET_CSIZE
, TARGET_CS6
, CSIZE
, CS6
},
1949 { TARGET_CSIZE
, TARGET_CS7
, CSIZE
, CS7
},
1950 { TARGET_CSIZE
, TARGET_CS8
, CSIZE
, CS8
},
1951 { TARGET_CSTOPB
, TARGET_CSTOPB
, CSTOPB
, CSTOPB
},
1952 { TARGET_CREAD
, TARGET_CREAD
, CREAD
, CREAD
},
1953 { TARGET_PARENB
, TARGET_PARENB
, PARENB
, PARENB
},
1954 { TARGET_PARODD
, TARGET_PARODD
, PARODD
, PARODD
},
1955 { TARGET_HUPCL
, TARGET_HUPCL
, HUPCL
, HUPCL
},
1956 { TARGET_CLOCAL
, TARGET_CLOCAL
, CLOCAL
, CLOCAL
},
1957 { TARGET_CRTSCTS
, TARGET_CRTSCTS
, CRTSCTS
, CRTSCTS
},
1961 bitmask_transtbl lflag_tbl
[] = {
1962 { TARGET_ISIG
, TARGET_ISIG
, ISIG
, ISIG
},
1963 { TARGET_ICANON
, TARGET_ICANON
, ICANON
, ICANON
},
1964 { TARGET_XCASE
, TARGET_XCASE
, XCASE
, XCASE
},
1965 { TARGET_ECHO
, TARGET_ECHO
, ECHO
, ECHO
},
1966 { TARGET_ECHOE
, TARGET_ECHOE
, ECHOE
, ECHOE
},
1967 { TARGET_ECHOK
, TARGET_ECHOK
, ECHOK
, ECHOK
},
1968 { TARGET_ECHONL
, TARGET_ECHONL
, ECHONL
, ECHONL
},
1969 { TARGET_NOFLSH
, TARGET_NOFLSH
, NOFLSH
, NOFLSH
},
1970 { TARGET_TOSTOP
, TARGET_TOSTOP
, TOSTOP
, TOSTOP
},
1971 { TARGET_ECHOCTL
, TARGET_ECHOCTL
, ECHOCTL
, ECHOCTL
},
1972 { TARGET_ECHOPRT
, TARGET_ECHOPRT
, ECHOPRT
, ECHOPRT
},
1973 { TARGET_ECHOKE
, TARGET_ECHOKE
, ECHOKE
, ECHOKE
},
1974 { TARGET_FLUSHO
, TARGET_FLUSHO
, FLUSHO
, FLUSHO
},
1975 { TARGET_PENDIN
, TARGET_PENDIN
, PENDIN
, PENDIN
},
1976 { TARGET_IEXTEN
, TARGET_IEXTEN
, IEXTEN
, IEXTEN
},
1980 static void target_to_host_termios (void *dst
, const void *src
)
1982 struct host_termios
*host
= dst
;
1983 const struct target_termios
*target
= src
;
1986 target_to_host_bitmask(tswap32(target
->c_iflag
), iflag_tbl
);
1988 target_to_host_bitmask(tswap32(target
->c_oflag
), oflag_tbl
);
1990 target_to_host_bitmask(tswap32(target
->c_cflag
), cflag_tbl
);
1992 target_to_host_bitmask(tswap32(target
->c_lflag
), lflag_tbl
);
1993 host
->c_line
= target
->c_line
;
1995 host
->c_cc
[VINTR
] = target
->c_cc
[TARGET_VINTR
];
1996 host
->c_cc
[VQUIT
] = target
->c_cc
[TARGET_VQUIT
];
1997 host
->c_cc
[VERASE
] = target
->c_cc
[TARGET_VERASE
];
1998 host
->c_cc
[VKILL
] = target
->c_cc
[TARGET_VKILL
];
1999 host
->c_cc
[VEOF
] = target
->c_cc
[TARGET_VEOF
];
2000 host
->c_cc
[VTIME
] = target
->c_cc
[TARGET_VTIME
];
2001 host
->c_cc
[VMIN
] = target
->c_cc
[TARGET_VMIN
];
2002 host
->c_cc
[VSWTC
] = target
->c_cc
[TARGET_VSWTC
];
2003 host
->c_cc
[VSTART
] = target
->c_cc
[TARGET_VSTART
];
2004 host
->c_cc
[VSTOP
] = target
->c_cc
[TARGET_VSTOP
];
2005 host
->c_cc
[VSUSP
] = target
->c_cc
[TARGET_VSUSP
];
2006 host
->c_cc
[VEOL
] = target
->c_cc
[TARGET_VEOL
];
2007 host
->c_cc
[VREPRINT
] = target
->c_cc
[TARGET_VREPRINT
];
2008 host
->c_cc
[VDISCARD
] = target
->c_cc
[TARGET_VDISCARD
];
2009 host
->c_cc
[VWERASE
] = target
->c_cc
[TARGET_VWERASE
];
2010 host
->c_cc
[VLNEXT
] = target
->c_cc
[TARGET_VLNEXT
];
2011 host
->c_cc
[VEOL2
] = target
->c_cc
[TARGET_VEOL2
];
2014 static void host_to_target_termios (void *dst
, const void *src
)
2016 struct target_termios
*target
= dst
;
2017 const struct host_termios
*host
= src
;
2020 tswap32(host_to_target_bitmask(host
->c_iflag
, iflag_tbl
));
2022 tswap32(host_to_target_bitmask(host
->c_oflag
, oflag_tbl
));
2024 tswap32(host_to_target_bitmask(host
->c_cflag
, cflag_tbl
));
2026 tswap32(host_to_target_bitmask(host
->c_lflag
, lflag_tbl
));
2027 target
->c_line
= host
->c_line
;
2029 target
->c_cc
[TARGET_VINTR
] = host
->c_cc
[VINTR
];
2030 target
->c_cc
[TARGET_VQUIT
] = host
->c_cc
[VQUIT
];
2031 target
->c_cc
[TARGET_VERASE
] = host
->c_cc
[VERASE
];
2032 target
->c_cc
[TARGET_VKILL
] = host
->c_cc
[VKILL
];
2033 target
->c_cc
[TARGET_VEOF
] = host
->c_cc
[VEOF
];
2034 target
->c_cc
[TARGET_VTIME
] = host
->c_cc
[VTIME
];
2035 target
->c_cc
[TARGET_VMIN
] = host
->c_cc
[VMIN
];
2036 target
->c_cc
[TARGET_VSWTC
] = host
->c_cc
[VSWTC
];
2037 target
->c_cc
[TARGET_VSTART
] = host
->c_cc
[VSTART
];
2038 target
->c_cc
[TARGET_VSTOP
] = host
->c_cc
[VSTOP
];
2039 target
->c_cc
[TARGET_VSUSP
] = host
->c_cc
[VSUSP
];
2040 target
->c_cc
[TARGET_VEOL
] = host
->c_cc
[VEOL
];
2041 target
->c_cc
[TARGET_VREPRINT
] = host
->c_cc
[VREPRINT
];
2042 target
->c_cc
[TARGET_VDISCARD
] = host
->c_cc
[VDISCARD
];
2043 target
->c_cc
[TARGET_VWERASE
] = host
->c_cc
[VWERASE
];
2044 target
->c_cc
[TARGET_VLNEXT
] = host
->c_cc
[VLNEXT
];
2045 target
->c_cc
[TARGET_VEOL2
] = host
->c_cc
[VEOL2
];
2048 StructEntry struct_termios_def
= {
2049 .convert
= { host_to_target_termios
, target_to_host_termios
},
2050 .size
= { sizeof(struct target_termios
), sizeof(struct host_termios
) },
2051 .align
= { __alignof__(struct target_termios
), __alignof__(struct host_termios
) },
2054 static bitmask_transtbl mmap_flags_tbl
[] = {
2055 { TARGET_MAP_SHARED
, TARGET_MAP_SHARED
, MAP_SHARED
, MAP_SHARED
},
2056 { TARGET_MAP_PRIVATE
, TARGET_MAP_PRIVATE
, MAP_PRIVATE
, MAP_PRIVATE
},
2057 { TARGET_MAP_FIXED
, TARGET_MAP_FIXED
, MAP_FIXED
, MAP_FIXED
},
2058 { TARGET_MAP_ANONYMOUS
, TARGET_MAP_ANONYMOUS
, MAP_ANONYMOUS
, MAP_ANONYMOUS
},
2059 { TARGET_MAP_GROWSDOWN
, TARGET_MAP_GROWSDOWN
, MAP_GROWSDOWN
, MAP_GROWSDOWN
},
2060 { TARGET_MAP_DENYWRITE
, TARGET_MAP_DENYWRITE
, MAP_DENYWRITE
, MAP_DENYWRITE
},
2061 { TARGET_MAP_EXECUTABLE
, TARGET_MAP_EXECUTABLE
, MAP_EXECUTABLE
, MAP_EXECUTABLE
},
2062 { TARGET_MAP_LOCKED
, TARGET_MAP_LOCKED
, MAP_LOCKED
, MAP_LOCKED
},
2066 static bitmask_transtbl fcntl_flags_tbl
[] = {
2067 { TARGET_O_ACCMODE
, TARGET_O_WRONLY
, O_ACCMODE
, O_WRONLY
, },
2068 { TARGET_O_ACCMODE
, TARGET_O_RDWR
, O_ACCMODE
, O_RDWR
, },
2069 { TARGET_O_CREAT
, TARGET_O_CREAT
, O_CREAT
, O_CREAT
, },
2070 { TARGET_O_EXCL
, TARGET_O_EXCL
, O_EXCL
, O_EXCL
, },
2071 { TARGET_O_NOCTTY
, TARGET_O_NOCTTY
, O_NOCTTY
, O_NOCTTY
, },
2072 { TARGET_O_TRUNC
, TARGET_O_TRUNC
, O_TRUNC
, O_TRUNC
, },
2073 { TARGET_O_APPEND
, TARGET_O_APPEND
, O_APPEND
, O_APPEND
, },
2074 { TARGET_O_NONBLOCK
, TARGET_O_NONBLOCK
, O_NONBLOCK
, O_NONBLOCK
, },
2075 { TARGET_O_SYNC
, TARGET_O_SYNC
, O_SYNC
, O_SYNC
, },
2076 { TARGET_FASYNC
, TARGET_FASYNC
, FASYNC
, FASYNC
, },
2077 { TARGET_O_DIRECTORY
, TARGET_O_DIRECTORY
, O_DIRECTORY
, O_DIRECTORY
, },
2078 { TARGET_O_NOFOLLOW
, TARGET_O_NOFOLLOW
, O_NOFOLLOW
, O_NOFOLLOW
, },
2079 { TARGET_O_LARGEFILE
, TARGET_O_LARGEFILE
, O_LARGEFILE
, O_LARGEFILE
, },
2080 #if defined(O_DIRECT)
2081 { TARGET_O_DIRECT
, TARGET_O_DIRECT
, O_DIRECT
, O_DIRECT
, },
2086 #if defined(TARGET_I386)
2088 /* NOTE: there is really one LDT for all the threads */
2091 static int read_ldt(abi_ulong ptr
, unsigned long bytecount
)
2098 size
= TARGET_LDT_ENTRIES
* TARGET_LDT_ENTRY_SIZE
;
2099 if (size
> bytecount
)
2101 p
= lock_user(ptr
, size
, 0);
2102 /* ??? Shoudl this by byteswapped? */
2103 memcpy(p
, ldt_table
, size
);
2104 unlock_user(p
, ptr
, size
);
2108 /* XXX: add locking support */
2109 static int write_ldt(CPUX86State
*env
,
2110 abi_ulong ptr
, unsigned long bytecount
, int oldmode
)
2112 struct target_modify_ldt_ldt_s ldt_info
;
2113 struct target_modify_ldt_ldt_s
*target_ldt_info
;
2114 int seg_32bit
, contents
, read_exec_only
, limit_in_pages
;
2115 int seg_not_present
, useable
;
2116 uint32_t *lp
, entry_1
, entry_2
;
2118 if (bytecount
!= sizeof(ldt_info
))
2120 lock_user_struct(target_ldt_info
, ptr
, 1);
2121 ldt_info
.entry_number
= tswap32(target_ldt_info
->entry_number
);
2122 ldt_info
.base_addr
= tswapl(target_ldt_info
->base_addr
);
2123 ldt_info
.limit
= tswap32(target_ldt_info
->limit
);
2124 ldt_info
.flags
= tswap32(target_ldt_info
->flags
);
2125 unlock_user_struct(target_ldt_info
, ptr
, 0);
2127 if (ldt_info
.entry_number
>= TARGET_LDT_ENTRIES
)
2129 seg_32bit
= ldt_info
.flags
& 1;
2130 contents
= (ldt_info
.flags
>> 1) & 3;
2131 read_exec_only
= (ldt_info
.flags
>> 3) & 1;
2132 limit_in_pages
= (ldt_info
.flags
>> 4) & 1;
2133 seg_not_present
= (ldt_info
.flags
>> 5) & 1;
2134 useable
= (ldt_info
.flags
>> 6) & 1;
2136 if (contents
== 3) {
2139 if (seg_not_present
== 0)
2142 /* allocate the LDT */
2144 ldt_table
= malloc(TARGET_LDT_ENTRIES
* TARGET_LDT_ENTRY_SIZE
);
2147 memset(ldt_table
, 0, TARGET_LDT_ENTRIES
* TARGET_LDT_ENTRY_SIZE
);
2148 env
->ldt
.base
= h2g(ldt_table
);
2149 env
->ldt
.limit
= 0xffff;
2152 /* NOTE: same code as Linux kernel */
2153 /* Allow LDTs to be cleared by the user. */
2154 if (ldt_info
.base_addr
== 0 && ldt_info
.limit
== 0) {
2157 read_exec_only
== 1 &&
2159 limit_in_pages
== 0 &&
2160 seg_not_present
== 1 &&
2168 entry_1
= ((ldt_info
.base_addr
& 0x0000ffff) << 16) |
2169 (ldt_info
.limit
& 0x0ffff);
2170 entry_2
= (ldt_info
.base_addr
& 0xff000000) |
2171 ((ldt_info
.base_addr
& 0x00ff0000) >> 16) |
2172 (ldt_info
.limit
& 0xf0000) |
2173 ((read_exec_only
^ 1) << 9) |
2175 ((seg_not_present
^ 1) << 15) |
2177 (limit_in_pages
<< 23) |
2180 entry_2
|= (useable
<< 20);
2182 /* Install the new entry ... */
2184 lp
= (uint32_t *)(ldt_table
+ (ldt_info
.entry_number
<< 3));
2185 lp
[0] = tswap32(entry_1
);
2186 lp
[1] = tswap32(entry_2
);
2190 /* specific and weird i386 syscalls */
2191 int do_modify_ldt(CPUX86State
*env
, int func
, abi_ulong ptr
, unsigned long bytecount
)
2197 ret
= read_ldt(ptr
, bytecount
);
2200 ret
= write_ldt(env
, ptr
, bytecount
, 1);
2203 ret
= write_ldt(env
, ptr
, bytecount
, 0);
2209 #endif /* defined(TARGET_I386) */
2211 /* this stack is the equivalent of the kernel stack associated with a
2213 #define NEW_STACK_SIZE 8192
2215 static int clone_func(void *arg
)
2217 CPUState
*env
= arg
;
2223 int do_fork(CPUState
*env
, unsigned int flags
, abi_ulong newsp
)
2230 if (flags
& CLONE_VM
) {
2231 ts
= malloc(sizeof(TaskState
) + NEW_STACK_SIZE
);
2232 memset(ts
, 0, sizeof(TaskState
));
2233 new_stack
= ts
->stack
;
2235 /* add in task state list */
2236 ts
->next
= first_task_state
;
2237 first_task_state
= ts
;
2238 /* we create a new CPU instance. */
2239 new_env
= cpu_copy(env
);
2240 #if defined(TARGET_I386)
2242 newsp
= env
->regs
[R_ESP
];
2243 new_env
->regs
[R_ESP
] = newsp
;
2244 new_env
->regs
[R_EAX
] = 0;
2245 #elif defined(TARGET_ARM)
2247 newsp
= env
->regs
[13];
2248 new_env
->regs
[13] = newsp
;
2249 new_env
->regs
[0] = 0;
2250 #elif defined(TARGET_SPARC)
2252 newsp
= env
->regwptr
[22];
2253 new_env
->regwptr
[22] = newsp
;
2254 new_env
->regwptr
[0] = 0;
2256 printf ("HELPME: %s:%d\n", __FILE__
, __LINE__
);
2257 #elif defined(TARGET_M68K)
2259 newsp
= env
->aregs
[7];
2260 new_env
->aregs
[7] = newsp
;
2261 new_env
->dregs
[0] = 0;
2262 /* ??? is this sufficient? */
2263 #elif defined(TARGET_MIPS)
2265 newsp
= env
->gpr
[29][env
->current_tc
];
2266 new_env
->gpr
[29][env
->current_tc
] = newsp
;
2267 #elif defined(TARGET_PPC)
2269 newsp
= env
->gpr
[1];
2270 new_env
->gpr
[1] = newsp
;
2273 for (i
= 7; i
< 32; i
++)
2274 new_env
->gpr
[i
] = 0;
2276 #elif defined(TARGET_SH4)
2278 newsp
= env
->gregs
[15];
2279 new_env
->gregs
[15] = newsp
;
2281 #elif defined(TARGET_ALPHA)
2283 newsp
= env
->ir
[30];
2284 new_env
->ir
[30] = newsp
;
2288 for (i
= 7; i
< 30; i
++)
2291 #elif defined(TARGET_CRIS)
2293 newsp
= env
->regs
[14];
2294 new_env
->regs
[14] = newsp
;
2296 #error unsupported target CPU
2298 new_env
->opaque
= ts
;
2300 ret
= __clone2(clone_func
, new_stack
+ NEW_STACK_SIZE
, flags
, new_env
);
2302 ret
= clone(clone_func
, new_stack
+ NEW_STACK_SIZE
, flags
, new_env
);
2305 /* if no CLONE_VM, we consider it is a fork */
2306 if ((flags
& ~CSIGNAL
) != 0)
2313 static abi_long
do_fcntl(int fd
, int cmd
, abi_ulong arg
)
2316 struct target_flock
*target_fl
;
2317 struct flock64 fl64
;
2318 struct target_flock64
*target_fl64
;
2322 case TARGET_F_GETLK
:
2323 lock_user_struct(target_fl
, arg
, 1);
2324 fl
.l_type
= tswap16(target_fl
->l_type
);
2325 fl
.l_whence
= tswap16(target_fl
->l_whence
);
2326 fl
.l_start
= tswapl(target_fl
->l_start
);
2327 fl
.l_len
= tswapl(target_fl
->l_len
);
2328 fl
.l_pid
= tswapl(target_fl
->l_pid
);
2329 unlock_user_struct(target_fl
, arg
, 0);
2330 ret
= fcntl(fd
, cmd
, &fl
);
2332 lock_user_struct(target_fl
, arg
, 0);
2333 target_fl
->l_type
= tswap16(fl
.l_type
);
2334 target_fl
->l_whence
= tswap16(fl
.l_whence
);
2335 target_fl
->l_start
= tswapl(fl
.l_start
);
2336 target_fl
->l_len
= tswapl(fl
.l_len
);
2337 target_fl
->l_pid
= tswapl(fl
.l_pid
);
2338 unlock_user_struct(target_fl
, arg
, 1);
2342 case TARGET_F_SETLK
:
2343 case TARGET_F_SETLKW
:
2344 lock_user_struct(target_fl
, arg
, 1);
2345 fl
.l_type
= tswap16(target_fl
->l_type
);
2346 fl
.l_whence
= tswap16(target_fl
->l_whence
);
2347 fl
.l_start
= tswapl(target_fl
->l_start
);
2348 fl
.l_len
= tswapl(target_fl
->l_len
);
2349 fl
.l_pid
= tswapl(target_fl
->l_pid
);
2350 unlock_user_struct(target_fl
, arg
, 0);
2351 ret
= fcntl(fd
, cmd
, &fl
);
2354 case TARGET_F_GETLK64
:
2355 lock_user_struct(target_fl64
, arg
, 1);
2356 fl64
.l_type
= tswap16(target_fl64
->l_type
) >> 1;
2357 fl64
.l_whence
= tswap16(target_fl64
->l_whence
);
2358 fl64
.l_start
= tswapl(target_fl64
->l_start
);
2359 fl64
.l_len
= tswapl(target_fl64
->l_len
);
2360 fl64
.l_pid
= tswap16(target_fl64
->l_pid
);
2361 unlock_user_struct(target_fl64
, arg
, 0);
2362 ret
= fcntl(fd
, cmd
>> 1, &fl64
);
2364 lock_user_struct(target_fl64
, arg
, 0);
2365 target_fl64
->l_type
= tswap16(fl64
.l_type
) >> 1;
2366 target_fl64
->l_whence
= tswap16(fl64
.l_whence
);
2367 target_fl64
->l_start
= tswapl(fl64
.l_start
);
2368 target_fl64
->l_len
= tswapl(fl64
.l_len
);
2369 target_fl64
->l_pid
= tswapl(fl64
.l_pid
);
2370 unlock_user_struct(target_fl64
, arg
, 1);
2373 case TARGET_F_SETLK64
:
2374 case TARGET_F_SETLKW64
:
2375 lock_user_struct(target_fl64
, arg
, 1);
2376 fl64
.l_type
= tswap16(target_fl64
->l_type
) >> 1;
2377 fl64
.l_whence
= tswap16(target_fl64
->l_whence
);
2378 fl64
.l_start
= tswapl(target_fl64
->l_start
);
2379 fl64
.l_len
= tswapl(target_fl64
->l_len
);
2380 fl64
.l_pid
= tswap16(target_fl64
->l_pid
);
2381 unlock_user_struct(target_fl64
, arg
, 0);
2382 ret
= fcntl(fd
, cmd
>> 1, &fl64
);
2386 ret
= fcntl(fd
, cmd
, arg
);
2387 ret
= host_to_target_bitmask(ret
, fcntl_flags_tbl
);
2391 ret
= fcntl(fd
, cmd
, target_to_host_bitmask(arg
, fcntl_flags_tbl
));
2395 ret
= fcntl(fd
, cmd
, arg
);
2403 static inline int high2lowuid(int uid
)
2411 static inline int high2lowgid(int gid
)
2419 static inline int low2highuid(int uid
)
2421 if ((int16_t)uid
== -1)
2427 static inline int low2highgid(int gid
)
2429 if ((int16_t)gid
== -1)
2435 #endif /* USE_UID16 */
2437 void syscall_init(void)
2440 const argtype
*arg_type
;
2443 #define STRUCT(name, list...) thunk_register_struct(STRUCT_ ## name, #name, struct_ ## name ## _def);
2444 #define STRUCT_SPECIAL(name) thunk_register_struct_direct(STRUCT_ ## name, #name, &struct_ ## name ## _def);
2445 #include "syscall_types.h"
2447 #undef STRUCT_SPECIAL
2449 /* we patch the ioctl size if necessary. We rely on the fact that
2450 no ioctl has all the bits at '1' in the size field */
2452 while (ie
->target_cmd
!= 0) {
2453 if (((ie
->target_cmd
>> TARGET_IOC_SIZESHIFT
) & TARGET_IOC_SIZEMASK
) ==
2454 TARGET_IOC_SIZEMASK
) {
2455 arg_type
= ie
->arg_type
;
2456 if (arg_type
[0] != TYPE_PTR
) {
2457 fprintf(stderr
, "cannot patch size for ioctl 0x%x\n",
2462 size
= thunk_type_size(arg_type
, 0);
2463 ie
->target_cmd
= (ie
->target_cmd
&
2464 ~(TARGET_IOC_SIZEMASK
<< TARGET_IOC_SIZESHIFT
)) |
2465 (size
<< TARGET_IOC_SIZESHIFT
);
2467 /* automatic consistency check if same arch */
2468 #if defined(__i386__) && defined(TARGET_I386)
2469 if (ie
->target_cmd
!= ie
->host_cmd
) {
2470 fprintf(stderr
, "ERROR: ioctl: target=0x%x host=0x%x\n",
2471 ie
->target_cmd
, ie
->host_cmd
);
2478 #if TARGET_ABI_BITS == 32
2479 static inline uint64_t target_offset64(uint32_t word0
, uint32_t word1
)
2481 #ifdef TARGET_WORDS_BIG_ENDIAN
2482 return ((uint64_t)word0
<< 32) | word1
;
2484 return ((uint64_t)word1
<< 32) | word0
;
2487 #else /* TARGET_ABI_BITS == 32 */
2488 static inline uint64_t target_offset64(uint64_t word0
, uint64_t word1
)
2492 #endif /* TARGET_ABI_BITS != 32 */
2494 #ifdef TARGET_NR_truncate64
2495 static inline abi_long
target_truncate64(void *cpu_env
, const char *arg1
,
2501 if (((CPUARMState
*)cpu_env
)->eabi
)
2507 return get_errno(truncate64(arg1
, target_offset64(arg2
, arg3
)));
2511 #ifdef TARGET_NR_ftruncate64
2512 static inline abi_long
target_ftruncate64(void *cpu_env
, abi_long arg1
,
2518 if (((CPUARMState
*)cpu_env
)->eabi
)
2524 return get_errno(ftruncate64(arg1
, target_offset64(arg2
, arg3
)));
2528 static inline void target_to_host_timespec(struct timespec
*host_ts
,
2529 abi_ulong target_addr
)
2531 struct target_timespec
*target_ts
;
2533 lock_user_struct(target_ts
, target_addr
, 1);
2534 host_ts
->tv_sec
= tswapl(target_ts
->tv_sec
);
2535 host_ts
->tv_nsec
= tswapl(target_ts
->tv_nsec
);
2536 unlock_user_struct(target_ts
, target_addr
, 0);
2539 static inline void host_to_target_timespec(abi_ulong target_addr
,
2540 struct timespec
*host_ts
)
2542 struct target_timespec
*target_ts
;
2544 lock_user_struct(target_ts
, target_addr
, 0);
2545 target_ts
->tv_sec
= tswapl(host_ts
->tv_sec
);
2546 target_ts
->tv_nsec
= tswapl(host_ts
->tv_nsec
);
2547 unlock_user_struct(target_ts
, target_addr
, 1);
2550 abi_long
do_syscall(void *cpu_env
, int num
, abi_long arg1
,
2551 abi_long arg2
, abi_long arg3
, abi_long arg4
,
2552 abi_long arg5
, abi_long arg6
)
2560 gemu_log("syscall %d", num
);
2563 case TARGET_NR_exit
:
2567 gdb_exit(cpu_env
, arg1
);
2568 /* XXX: should free thread stack and CPU env */
2570 ret
= 0; /* avoid warning */
2572 case TARGET_NR_read
:
2573 page_unprotect_range(arg2
, arg3
);
2574 p
= lock_user(arg2
, arg3
, 0);
2575 ret
= get_errno(read(arg1
, p
, arg3
));
2576 unlock_user(p
, arg2
, ret
);
2578 case TARGET_NR_write
:
2579 p
= lock_user(arg2
, arg3
, 1);
2580 ret
= get_errno(write(arg1
, p
, arg3
));
2581 unlock_user(p
, arg2
, 0);
2583 case TARGET_NR_open
:
2584 p
= lock_user_string(arg1
);
2585 ret
= get_errno(open(path(p
),
2586 target_to_host_bitmask(arg2
, fcntl_flags_tbl
),
2588 unlock_user(p
, arg1
, 0);
2590 #if defined(TARGET_NR_openat) && defined(__NR_openat)
2591 case TARGET_NR_openat
:
2596 p
= lock_user_string(arg2
);
2597 if (!access_ok(VERIFY_READ
, p
, 1))
2600 ret
= get_errno(sys_openat(arg1
,
2602 target_to_host_bitmask(arg3
, fcntl_flags_tbl
),
2605 unlock_user(p
, arg2
, 0);
2608 case TARGET_NR_close
:
2609 ret
= get_errno(close(arg1
));
2614 case TARGET_NR_fork
:
2615 ret
= get_errno(do_fork(cpu_env
, SIGCHLD
, 0));
2617 #ifdef TARGET_NR_waitpid
2618 case TARGET_NR_waitpid
:
2621 ret
= get_errno(waitpid(arg1
, &status
, arg3
));
2622 if (!is_error(ret
) && arg2
)
2623 tput32(arg2
, status
);
2627 #ifdef TARGET_NR_creat /* not on alpha */
2628 case TARGET_NR_creat
:
2629 p
= lock_user_string(arg1
);
2630 ret
= get_errno(creat(p
, arg2
));
2631 unlock_user(p
, arg1
, 0);
2634 case TARGET_NR_link
:
2637 p
= lock_user_string(arg1
);
2638 p2
= lock_user_string(arg2
);
2639 ret
= get_errno(link(p
, p2
));
2640 unlock_user(p2
, arg2
, 0);
2641 unlock_user(p
, arg1
, 0);
2644 #if defined(TARGET_NR_linkat) && defined(__NR_linkat)
2645 case TARGET_NR_linkat
:
2646 if (!arg2
|| !arg4
) {
2652 p
= lock_user_string(arg2
);
2653 p2
= lock_user_string(arg4
);
2654 if (!access_ok(VERIFY_READ
, p
, 1)
2655 || !access_ok(VERIFY_READ
, p2
, 1))
2658 ret
= get_errno(sys_linkat(arg1
, p
, arg3
, p2
, arg5
));
2660 unlock_user(p
, arg2
, 0);
2662 unlock_user(p2
, arg4
, 0);
2666 case TARGET_NR_unlink
:
2667 p
= lock_user_string(arg1
);
2668 ret
= get_errno(unlink(p
));
2669 unlock_user(p
, arg1
, 0);
2671 #if defined(TARGET_NR_unlinkat) && defined(__NR_unlinkat)
2672 case TARGET_NR_unlinkat
:
2677 p
= lock_user_string(arg2
);
2678 if (!access_ok(VERIFY_READ
, p
, 1))
2681 ret
= get_errno(sys_unlinkat(arg1
, p
, arg3
));
2683 unlock_user(p
, arg2
, 0);
2686 case TARGET_NR_execve
:
2688 char **argp
, **envp
;
2691 abi_ulong guest_argp
;
2692 abi_ulong guest_envp
;
2698 for (gp
= guest_argp
; tgetl(gp
); gp
++)
2702 for (gp
= guest_envp
; tgetl(gp
); gp
++)
2705 argp
= alloca((argc
+ 1) * sizeof(void *));
2706 envp
= alloca((envc
+ 1) * sizeof(void *));
2708 for (gp
= guest_argp
, q
= argp
; ;
2709 gp
+= sizeof(abi_ulong
), q
++) {
2713 *q
= lock_user_string(addr
);
2717 for (gp
= guest_envp
, q
= envp
; ;
2718 gp
+= sizeof(abi_ulong
), q
++) {
2722 *q
= lock_user_string(addr
);
2726 p
= lock_user_string(arg1
);
2727 ret
= get_errno(execve(p
, argp
, envp
));
2728 unlock_user(p
, arg1
, 0);
2730 for (gp
= guest_argp
, q
= argp
; *q
;
2731 gp
+= sizeof(abi_ulong
), q
++) {
2733 unlock_user(*q
, addr
, 0);
2735 for (gp
= guest_envp
, q
= envp
; *q
;
2736 gp
+= sizeof(abi_ulong
), q
++) {
2738 unlock_user(*q
, addr
, 0);
2742 case TARGET_NR_chdir
:
2743 p
= lock_user_string(arg1
);
2744 ret
= get_errno(chdir(p
));
2745 unlock_user(p
, arg1
, 0);
2747 #ifdef TARGET_NR_time
2748 case TARGET_NR_time
:
2751 ret
= get_errno(time(&host_time
));
2752 if (!is_error(ret
) && arg1
)
2753 tputl(arg1
, host_time
);
2757 case TARGET_NR_mknod
:
2758 p
= lock_user_string(arg1
);
2759 ret
= get_errno(mknod(p
, arg2
, arg3
));
2760 unlock_user(p
, arg1
, 0);
2762 #if defined(TARGET_NR_mknodat) && defined(__NR_mknodat)
2763 case TARGET_NR_mknodat
:
2768 p
= lock_user_string(arg2
);
2769 if (!access_ok(VERIFY_READ
, p
, 1))
2772 ret
= get_errno(sys_mknodat(arg1
, p
, arg3
, arg4
));
2774 unlock_user(p
, arg2
, 0);
2777 case TARGET_NR_chmod
:
2778 p
= lock_user_string(arg1
);
2779 ret
= get_errno(chmod(p
, arg2
));
2780 unlock_user(p
, arg1
, 0);
2782 #ifdef TARGET_NR_break
2783 case TARGET_NR_break
:
2786 #ifdef TARGET_NR_oldstat
2787 case TARGET_NR_oldstat
:
2790 case TARGET_NR_lseek
:
2791 ret
= get_errno(lseek(arg1
, arg2
, arg3
));
2793 #ifdef TARGET_NR_getxpid
2794 case TARGET_NR_getxpid
:
2796 case TARGET_NR_getpid
:
2798 ret
= get_errno(getpid());
2800 case TARGET_NR_mount
:
2802 /* need to look at the data field */
2804 p
= lock_user_string(arg1
);
2805 p2
= lock_user_string(arg2
);
2806 p3
= lock_user_string(arg3
);
2807 ret
= get_errno(mount(p
, p2
, p3
, (unsigned long)arg4
, (const void *)arg5
));
2808 unlock_user(p
, arg1
, 0);
2809 unlock_user(p2
, arg2
, 0);
2810 unlock_user(p3
, arg3
, 0);
2813 #ifdef TARGET_NR_umount
2814 case TARGET_NR_umount
:
2815 p
= lock_user_string(arg1
);
2816 ret
= get_errno(umount(p
));
2817 unlock_user(p
, arg1
, 0);
2820 #ifdef TARGET_NR_stime /* not on alpha */
2821 case TARGET_NR_stime
:
2824 host_time
= tgetl(arg1
);
2825 ret
= get_errno(stime(&host_time
));
2829 case TARGET_NR_ptrace
:
2831 #ifdef TARGET_NR_alarm /* not on alpha */
2832 case TARGET_NR_alarm
:
2836 #ifdef TARGET_NR_oldfstat
2837 case TARGET_NR_oldfstat
:
2840 #ifdef TARGET_NR_pause /* not on alpha */
2841 case TARGET_NR_pause
:
2842 ret
= get_errno(pause());
2845 #ifdef TARGET_NR_utime
2846 case TARGET_NR_utime
:
2848 struct utimbuf tbuf
, *host_tbuf
;
2849 struct target_utimbuf
*target_tbuf
;
2851 lock_user_struct(target_tbuf
, arg2
, 1);
2852 tbuf
.actime
= tswapl(target_tbuf
->actime
);
2853 tbuf
.modtime
= tswapl(target_tbuf
->modtime
);
2854 unlock_user_struct(target_tbuf
, arg2
, 0);
2859 p
= lock_user_string(arg1
);
2860 ret
= get_errno(utime(p
, host_tbuf
));
2861 unlock_user(p
, arg1
, 0);
2865 case TARGET_NR_utimes
:
2867 struct timeval
*tvp
, tv
[2];
2869 target_to_host_timeval(&tv
[0], arg2
);
2870 target_to_host_timeval(&tv
[1],
2871 arg2
+ sizeof (struct target_timeval
));
2876 p
= lock_user_string(arg1
);
2877 ret
= get_errno(utimes(p
, tvp
));
2878 unlock_user(p
, arg1
, 0);
2881 #ifdef TARGET_NR_stty
2882 case TARGET_NR_stty
:
2885 #ifdef TARGET_NR_gtty
2886 case TARGET_NR_gtty
:
2889 case TARGET_NR_access
:
2890 p
= lock_user_string(arg1
);
2891 ret
= get_errno(access(p
, arg2
));
2892 unlock_user(p
, arg1
, 0);
2894 #if defined(TARGET_NR_faccessat) && defined(__NR_faccessat)
2895 case TARGET_NR_faccessat
:
2900 p
= lock_user_string(arg2
);
2901 if (!access_ok(VERIFY_READ
, p
, 1))
2904 ret
= get_errno(sys_faccessat(arg1
, p
, arg3
, arg4
));
2906 unlock_user(p
, arg2
, 0);
2909 #ifdef TARGET_NR_nice /* not on alpha */
2910 case TARGET_NR_nice
:
2911 ret
= get_errno(nice(arg1
));
2914 #ifdef TARGET_NR_ftime
2915 case TARGET_NR_ftime
:
2918 case TARGET_NR_sync
:
2922 case TARGET_NR_kill
:
2923 ret
= get_errno(kill(arg1
, arg2
));
2925 case TARGET_NR_rename
:
2928 p
= lock_user_string(arg1
);
2929 p2
= lock_user_string(arg2
);
2930 ret
= get_errno(rename(p
, p2
));
2931 unlock_user(p2
, arg2
, 0);
2932 unlock_user(p
, arg1
, 0);
2935 #if defined(TARGET_NR_renameat) && defined(__NR_renameat)
2936 case TARGET_NR_renameat
:
2937 if (!arg2
|| !arg4
) {
2943 p
= lock_user_string(arg2
);
2944 p2
= lock_user_string(arg4
);
2945 if (!access_ok(VERIFY_READ
, p
, 1)
2946 || !access_ok(VERIFY_READ
, p2
, 1))
2949 ret
= get_errno(sys_renameat(arg1
, p
, arg3
, p2
));
2951 unlock_user(p2
, arg4
, 0);
2953 unlock_user(p
, arg2
, 0);
2957 case TARGET_NR_mkdir
:
2958 p
= lock_user_string(arg1
);
2959 ret
= get_errno(mkdir(p
, arg2
));
2960 unlock_user(p
, arg1
, 0);
2962 #if defined(TARGET_NR_mkdirat) && defined(__NR_mkdirat)
2963 case TARGET_NR_mkdirat
:
2968 p
= lock_user_string(arg2
);
2969 if (!access_ok(VERIFY_READ
, p
, 1))
2972 ret
= get_errno(sys_mkdirat(arg1
, p
, arg3
));
2974 unlock_user(p
, arg2
, 0);
2977 case TARGET_NR_rmdir
:
2978 p
= lock_user_string(arg1
);
2979 ret
= get_errno(rmdir(p
));
2980 unlock_user(p
, arg1
, 0);
2983 ret
= get_errno(dup(arg1
));
2985 case TARGET_NR_pipe
:
2988 ret
= get_errno(pipe(host_pipe
));
2989 if (!is_error(ret
)) {
2990 #if defined(TARGET_MIPS)
2991 CPUMIPSState
*env
= (CPUMIPSState
*)cpu_env
;
2992 env
->gpr
[3][env
->current_tc
] = host_pipe
[1];
2995 tput32(arg1
, host_pipe
[0]);
2996 tput32(arg1
+ 4, host_pipe
[1]);
3001 case TARGET_NR_times
:
3003 struct target_tms
*tmsp
;
3005 ret
= get_errno(times(&tms
));
3007 tmsp
= lock_user(arg1
, sizeof(struct target_tms
), 0);
3008 tmsp
->tms_utime
= tswapl(host_to_target_clock_t(tms
.tms_utime
));
3009 tmsp
->tms_stime
= tswapl(host_to_target_clock_t(tms
.tms_stime
));
3010 tmsp
->tms_cutime
= tswapl(host_to_target_clock_t(tms
.tms_cutime
));
3011 tmsp
->tms_cstime
= tswapl(host_to_target_clock_t(tms
.tms_cstime
));
3014 ret
= host_to_target_clock_t(ret
);
3017 #ifdef TARGET_NR_prof
3018 case TARGET_NR_prof
:
3021 #ifdef TARGET_NR_signal
3022 case TARGET_NR_signal
:
3025 case TARGET_NR_acct
:
3026 p
= lock_user_string(arg1
);
3027 ret
= get_errno(acct(path(p
)));
3028 unlock_user(p
, arg1
, 0);
3030 #ifdef TARGET_NR_umount2 /* not on alpha */
3031 case TARGET_NR_umount2
:
3032 p
= lock_user_string(arg1
);
3033 ret
= get_errno(umount2(p
, arg2
));
3034 unlock_user(p
, arg1
, 0);
3037 #ifdef TARGET_NR_lock
3038 case TARGET_NR_lock
:
3041 case TARGET_NR_ioctl
:
3042 ret
= do_ioctl(arg1
, arg2
, arg3
);
3044 case TARGET_NR_fcntl
:
3045 ret
= get_errno(do_fcntl(arg1
, arg2
, arg3
));
3047 #ifdef TARGET_NR_mpx
3051 case TARGET_NR_setpgid
:
3052 ret
= get_errno(setpgid(arg1
, arg2
));
3054 #ifdef TARGET_NR_ulimit
3055 case TARGET_NR_ulimit
:
3058 #ifdef TARGET_NR_oldolduname
3059 case TARGET_NR_oldolduname
:
3062 case TARGET_NR_umask
:
3063 ret
= get_errno(umask(arg1
));
3065 case TARGET_NR_chroot
:
3066 p
= lock_user_string(arg1
);
3067 ret
= get_errno(chroot(p
));
3068 unlock_user(p
, arg1
, 0);
3070 case TARGET_NR_ustat
:
3072 case TARGET_NR_dup2
:
3073 ret
= get_errno(dup2(arg1
, arg2
));
3075 #ifdef TARGET_NR_getppid /* not on alpha */
3076 case TARGET_NR_getppid
:
3077 ret
= get_errno(getppid());
3080 case TARGET_NR_getpgrp
:
3081 ret
= get_errno(getpgrp());
3083 case TARGET_NR_setsid
:
3084 ret
= get_errno(setsid());
3086 #ifdef TARGET_NR_sigaction
3087 case TARGET_NR_sigaction
:
3089 #if !defined(TARGET_MIPS)
3090 struct target_old_sigaction
*old_act
;
3091 struct target_sigaction act
, oact
, *pact
;
3093 lock_user_struct(old_act
, arg2
, 1);
3094 act
._sa_handler
= old_act
->_sa_handler
;
3095 target_siginitset(&act
.sa_mask
, old_act
->sa_mask
);
3096 act
.sa_flags
= old_act
->sa_flags
;
3097 act
.sa_restorer
= old_act
->sa_restorer
;
3098 unlock_user_struct(old_act
, arg2
, 0);
3103 ret
= get_errno(do_sigaction(arg1
, pact
, &oact
));
3104 if (!is_error(ret
) && arg3
) {
3105 lock_user_struct(old_act
, arg3
, 0);
3106 old_act
->_sa_handler
= oact
._sa_handler
;
3107 old_act
->sa_mask
= oact
.sa_mask
.sig
[0];
3108 old_act
->sa_flags
= oact
.sa_flags
;
3109 old_act
->sa_restorer
= oact
.sa_restorer
;
3110 unlock_user_struct(old_act
, arg3
, 1);
3113 struct target_sigaction act
, oact
, *pact
, *old_act
;
3116 lock_user_struct(old_act
, arg2
, 1);
3117 act
._sa_handler
= old_act
->_sa_handler
;
3118 target_siginitset(&act
.sa_mask
, old_act
->sa_mask
.sig
[0]);
3119 act
.sa_flags
= old_act
->sa_flags
;
3120 unlock_user_struct(old_act
, arg2
, 0);
3126 ret
= get_errno(do_sigaction(arg1
, pact
, &oact
));
3128 if (!is_error(ret
) && arg3
) {
3129 lock_user_struct(old_act
, arg3
, 0);
3130 old_act
->_sa_handler
= oact
._sa_handler
;
3131 old_act
->sa_flags
= oact
.sa_flags
;
3132 old_act
->sa_mask
.sig
[0] = oact
.sa_mask
.sig
[0];
3133 old_act
->sa_mask
.sig
[1] = 0;
3134 old_act
->sa_mask
.sig
[2] = 0;
3135 old_act
->sa_mask
.sig
[3] = 0;
3136 unlock_user_struct(old_act
, arg3
, 1);
3142 case TARGET_NR_rt_sigaction
:
3144 struct target_sigaction
*act
;
3145 struct target_sigaction
*oact
;
3148 lock_user_struct(act
, arg2
, 1);
3152 lock_user_struct(oact
, arg3
, 0);
3155 ret
= get_errno(do_sigaction(arg1
, act
, oact
));
3157 unlock_user_struct(act
, arg2
, 0);
3159 unlock_user_struct(oact
, arg3
, 1);
3162 #ifdef TARGET_NR_sgetmask /* not on alpha */
3163 case TARGET_NR_sgetmask
:
3166 abi_ulong target_set
;
3167 sigprocmask(0, NULL
, &cur_set
);
3168 host_to_target_old_sigset(&target_set
, &cur_set
);
3173 #ifdef TARGET_NR_ssetmask /* not on alpha */
3174 case TARGET_NR_ssetmask
:
3176 sigset_t set
, oset
, cur_set
;
3177 abi_ulong target_set
= arg1
;
3178 sigprocmask(0, NULL
, &cur_set
);
3179 target_to_host_old_sigset(&set
, &target_set
);
3180 sigorset(&set
, &set
, &cur_set
);
3181 sigprocmask(SIG_SETMASK
, &set
, &oset
);
3182 host_to_target_old_sigset(&target_set
, &oset
);
3187 #ifdef TARGET_NR_sigprocmask
3188 case TARGET_NR_sigprocmask
:
3191 sigset_t set
, oldset
, *set_ptr
;
3195 case TARGET_SIG_BLOCK
:
3198 case TARGET_SIG_UNBLOCK
:
3201 case TARGET_SIG_SETMASK
:
3208 p
= lock_user(arg2
, sizeof(target_sigset_t
), 1);
3209 target_to_host_old_sigset(&set
, p
);
3210 unlock_user(p
, arg2
, 0);
3216 ret
= get_errno(sigprocmask(arg1
, set_ptr
, &oldset
));
3217 if (!is_error(ret
) && arg3
) {
3218 p
= lock_user(arg3
, sizeof(target_sigset_t
), 0);
3219 host_to_target_old_sigset(p
, &oldset
);
3220 unlock_user(p
, arg3
, sizeof(target_sigset_t
));
3225 case TARGET_NR_rt_sigprocmask
:
3228 sigset_t set
, oldset
, *set_ptr
;
3232 case TARGET_SIG_BLOCK
:
3235 case TARGET_SIG_UNBLOCK
:
3238 case TARGET_SIG_SETMASK
:
3245 p
= lock_user(arg2
, sizeof(target_sigset_t
), 1);
3246 target_to_host_sigset(&set
, p
);
3247 unlock_user(p
, arg2
, 0);
3253 ret
= get_errno(sigprocmask(how
, set_ptr
, &oldset
));
3254 if (!is_error(ret
) && arg3
) {
3255 p
= lock_user(arg3
, sizeof(target_sigset_t
), 0);
3256 host_to_target_sigset(p
, &oldset
);
3257 unlock_user(p
, arg3
, sizeof(target_sigset_t
));
3261 #ifdef TARGET_NR_sigpending
3262 case TARGET_NR_sigpending
:
3265 ret
= get_errno(sigpending(&set
));
3266 if (!is_error(ret
)) {
3267 p
= lock_user(arg1
, sizeof(target_sigset_t
), 0);
3268 host_to_target_old_sigset(p
, &set
);
3269 unlock_user(p
, arg1
, sizeof(target_sigset_t
));
3274 case TARGET_NR_rt_sigpending
:
3277 ret
= get_errno(sigpending(&set
));
3278 if (!is_error(ret
)) {
3279 p
= lock_user(arg1
, sizeof(target_sigset_t
), 0);
3280 host_to_target_sigset(p
, &set
);
3281 unlock_user(p
, arg1
, sizeof(target_sigset_t
));
3285 #ifdef TARGET_NR_sigsuspend
3286 case TARGET_NR_sigsuspend
:
3289 p
= lock_user(arg1
, sizeof(target_sigset_t
), 1);
3290 target_to_host_old_sigset(&set
, p
);
3291 unlock_user(p
, arg1
, 0);
3292 ret
= get_errno(sigsuspend(&set
));
3296 case TARGET_NR_rt_sigsuspend
:
3299 p
= lock_user(arg1
, sizeof(target_sigset_t
), 1);
3300 target_to_host_sigset(&set
, p
);
3301 unlock_user(p
, arg1
, 0);
3302 ret
= get_errno(sigsuspend(&set
));
3305 case TARGET_NR_rt_sigtimedwait
:
3308 struct timespec uts
, *puts
;
3311 p
= lock_user(arg1
, sizeof(target_sigset_t
), 1);
3312 target_to_host_sigset(&set
, p
);
3313 unlock_user(p
, arg1
, 0);
3316 target_to_host_timespec(puts
, arg3
);
3320 ret
= get_errno(sigtimedwait(&set
, &uinfo
, puts
));
3321 if (!is_error(ret
) && arg2
) {
3322 p
= lock_user(arg2
, sizeof(target_sigset_t
), 0);
3323 host_to_target_siginfo(p
, &uinfo
);
3324 unlock_user(p
, arg2
, sizeof(target_sigset_t
));
3328 case TARGET_NR_rt_sigqueueinfo
:
3331 p
= lock_user(arg3
, sizeof(target_sigset_t
), 1);
3332 target_to_host_siginfo(&uinfo
, p
);
3333 unlock_user(p
, arg1
, 0);
3334 ret
= get_errno(sys_rt_sigqueueinfo(arg1
, arg2
, &uinfo
));
3337 #ifdef TARGET_NR_sigreturn
3338 case TARGET_NR_sigreturn
:
3339 /* NOTE: ret is eax, so not transcoding must be done */
3340 ret
= do_sigreturn(cpu_env
);
3343 case TARGET_NR_rt_sigreturn
:
3344 /* NOTE: ret is eax, so not transcoding must be done */
3345 ret
= do_rt_sigreturn(cpu_env
);
3347 case TARGET_NR_sethostname
:
3348 p
= lock_user_string(arg1
);
3349 ret
= get_errno(sethostname(p
, arg2
));
3350 unlock_user(p
, arg1
, 0);
3352 case TARGET_NR_setrlimit
:
3354 /* XXX: convert resource ? */
3355 int resource
= arg1
;
3356 struct target_rlimit
*target_rlim
;
3358 lock_user_struct(target_rlim
, arg2
, 1);
3359 rlim
.rlim_cur
= tswapl(target_rlim
->rlim_cur
);
3360 rlim
.rlim_max
= tswapl(target_rlim
->rlim_max
);
3361 unlock_user_struct(target_rlim
, arg2
, 0);
3362 ret
= get_errno(setrlimit(resource
, &rlim
));
3365 case TARGET_NR_getrlimit
:
3367 /* XXX: convert resource ? */
3368 int resource
= arg1
;
3369 struct target_rlimit
*target_rlim
;
3372 ret
= get_errno(getrlimit(resource
, &rlim
));
3373 if (!is_error(ret
)) {
3374 lock_user_struct(target_rlim
, arg2
, 0);
3375 rlim
.rlim_cur
= tswapl(target_rlim
->rlim_cur
);
3376 rlim
.rlim_max
= tswapl(target_rlim
->rlim_max
);
3377 unlock_user_struct(target_rlim
, arg2
, 1);
3381 case TARGET_NR_getrusage
:
3383 struct rusage rusage
;
3384 ret
= get_errno(getrusage(arg1
, &rusage
));
3385 if (!is_error(ret
)) {
3386 host_to_target_rusage(arg2
, &rusage
);
3390 case TARGET_NR_gettimeofday
:
3393 ret
= get_errno(gettimeofday(&tv
, NULL
));
3394 if (!is_error(ret
)) {
3395 host_to_target_timeval(arg1
, &tv
);
3399 case TARGET_NR_settimeofday
:
3402 target_to_host_timeval(&tv
, arg1
);
3403 ret
= get_errno(settimeofday(&tv
, NULL
));
3406 #ifdef TARGET_NR_select
3407 case TARGET_NR_select
:
3409 struct target_sel_arg_struct
*sel
;
3410 abi_ulong inp
, outp
, exp
, tvp
;
3413 lock_user_struct(sel
, arg1
, 1);
3414 nsel
= tswapl(sel
->n
);
3415 inp
= tswapl(sel
->inp
);
3416 outp
= tswapl(sel
->outp
);
3417 exp
= tswapl(sel
->exp
);
3418 tvp
= tswapl(sel
->tvp
);
3419 unlock_user_struct(sel
, arg1
, 0);
3420 ret
= do_select(nsel
, inp
, outp
, exp
, tvp
);
3424 case TARGET_NR_symlink
:
3427 p
= lock_user_string(arg1
);
3428 p2
= lock_user_string(arg2
);
3429 ret
= get_errno(symlink(p
, p2
));
3430 unlock_user(p2
, arg2
, 0);
3431 unlock_user(p
, arg1
, 0);
3434 #if defined(TARGET_NR_symlinkat) && defined(__NR_symlinkat)
3435 case TARGET_NR_symlinkat
:
3436 if (!arg1
|| !arg3
) {
3442 p
= lock_user_string(arg1
);
3443 p2
= lock_user_string(arg3
);
3444 if (!access_ok(VERIFY_READ
, p
, 1)
3445 || !access_ok(VERIFY_READ
, p2
, 1))
3448 ret
= get_errno(sys_symlinkat(p
, arg2
, p2
));
3450 unlock_user(p2
, arg3
, 0);
3452 unlock_user(p
, arg1
, 0);
3456 #ifdef TARGET_NR_oldlstat
3457 case TARGET_NR_oldlstat
:
3460 case TARGET_NR_readlink
:
3463 p
= lock_user_string(arg1
);
3464 p2
= lock_user(arg2
, arg3
, 0);
3465 ret
= get_errno(readlink(path(p
), p2
, arg3
));
3466 unlock_user(p2
, arg2
, ret
);
3467 unlock_user(p
, arg1
, 0);
3470 #if defined(TARGET_NR_readlinkat) && defined(__NR_readlinkat)
3471 case TARGET_NR_readlinkat
:
3472 if (!arg2
|| !arg3
) {
3478 p
= lock_user_string(arg2
);
3479 p2
= lock_user(arg3
, arg4
, 0);
3480 if (!access_ok(VERIFY_READ
, p
, 1)
3481 || !access_ok(VERIFY_READ
, p2
, 1))
3484 ret
= get_errno(sys_readlinkat(arg1
, path(p
), p2
, arg4
));
3486 unlock_user(p2
, arg3
, ret
);
3488 unlock_user(p
, arg2
, 0);
3492 #ifdef TARGET_NR_uselib
3493 case TARGET_NR_uselib
:
3496 #ifdef TARGET_NR_swapon
3497 case TARGET_NR_swapon
:
3498 p
= lock_user_string(arg1
);
3499 ret
= get_errno(swapon(p
, arg2
));
3500 unlock_user(p
, arg1
, 0);
3503 case TARGET_NR_reboot
:
3505 #ifdef TARGET_NR_readdir
3506 case TARGET_NR_readdir
:
3509 #ifdef TARGET_NR_mmap
3510 case TARGET_NR_mmap
:
3511 #if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_M68K) || defined(TARGET_CRIS)
3514 abi_ulong v1
, v2
, v3
, v4
, v5
, v6
;
3515 v
= lock_user(arg1
, 6 * sizeof(abi_ulong
), 1);
3522 unlock_user(v
, arg1
, 0);
3523 ret
= get_errno(target_mmap(v1
, v2
, v3
,
3524 target_to_host_bitmask(v4
, mmap_flags_tbl
),
3528 ret
= get_errno(target_mmap(arg1
, arg2
, arg3
,
3529 target_to_host_bitmask(arg4
, mmap_flags_tbl
),
3535 #ifdef TARGET_NR_mmap2
3536 case TARGET_NR_mmap2
:
3537 #if defined(TARGET_SPARC) || defined(TARGET_MIPS)
3538 #define MMAP_SHIFT 12
3540 #define MMAP_SHIFT TARGET_PAGE_BITS
3542 ret
= get_errno(target_mmap(arg1
, arg2
, arg3
,
3543 target_to_host_bitmask(arg4
, mmap_flags_tbl
),
3545 arg6
<< MMAP_SHIFT
));
3548 case TARGET_NR_munmap
:
3549 ret
= get_errno(target_munmap(arg1
, arg2
));
3551 case TARGET_NR_mprotect
:
3552 ret
= get_errno(target_mprotect(arg1
, arg2
, arg3
));
3554 #ifdef TARGET_NR_mremap
3555 case TARGET_NR_mremap
:
3556 ret
= get_errno(target_mremap(arg1
, arg2
, arg3
, arg4
, arg5
));
3559 /* ??? msync/mlock/munlock are broken for softmmu. */
3560 #ifdef TARGET_NR_msync
3561 case TARGET_NR_msync
:
3562 ret
= get_errno(msync(g2h(arg1
), arg2
, arg3
));
3565 #ifdef TARGET_NR_mlock
3566 case TARGET_NR_mlock
:
3567 ret
= get_errno(mlock(g2h(arg1
), arg2
));
3570 #ifdef TARGET_NR_munlock
3571 case TARGET_NR_munlock
:
3572 ret
= get_errno(munlock(g2h(arg1
), arg2
));
3575 #ifdef TARGET_NR_mlockall
3576 case TARGET_NR_mlockall
:
3577 ret
= get_errno(mlockall(arg1
));
3580 #ifdef TARGET_NR_munlockall
3581 case TARGET_NR_munlockall
:
3582 ret
= get_errno(munlockall());
3585 case TARGET_NR_truncate
:
3586 p
= lock_user_string(arg1
);
3587 ret
= get_errno(truncate(p
, arg2
));
3588 unlock_user(p
, arg1
, 0);
3590 case TARGET_NR_ftruncate
:
3591 ret
= get_errno(ftruncate(arg1
, arg2
));
3593 case TARGET_NR_fchmod
:
3594 ret
= get_errno(fchmod(arg1
, arg2
));
3596 #if defined(TARGET_NR_fchmodat) && defined(__NR_fchmodat)
3597 case TARGET_NR_fchmodat
:
3602 p
= lock_user_string(arg2
);
3603 if (!access_ok(VERIFY_READ
, p
, 1))
3606 ret
= get_errno(sys_fchmodat(arg1
, p
, arg3
, arg4
));
3608 unlock_user(p
, arg2
, 0);
3611 case TARGET_NR_getpriority
:
3612 /* libc does special remapping of the return value of
3613 * sys_getpriority() so it's just easiest to call
3614 * sys_getpriority() directly rather than through libc. */
3615 ret
= sys_getpriority(arg1
, arg2
);
3617 case TARGET_NR_setpriority
:
3618 ret
= get_errno(setpriority(arg1
, arg2
, arg3
));
3620 #ifdef TARGET_NR_profil
3621 case TARGET_NR_profil
:
3624 case TARGET_NR_statfs
:
3625 p
= lock_user_string(arg1
);
3626 ret
= get_errno(statfs(path(p
), &stfs
));
3627 unlock_user(p
, arg1
, 0);
3629 if (!is_error(ret
)) {
3630 struct target_statfs
*target_stfs
;
3632 lock_user_struct(target_stfs
, arg2
, 0);
3633 /* ??? put_user is probably wrong. */
3634 put_user(stfs
.f_type
, &target_stfs
->f_type
);
3635 put_user(stfs
.f_bsize
, &target_stfs
->f_bsize
);
3636 put_user(stfs
.f_blocks
, &target_stfs
->f_blocks
);
3637 put_user(stfs
.f_bfree
, &target_stfs
->f_bfree
);
3638 put_user(stfs
.f_bavail
, &target_stfs
->f_bavail
);
3639 put_user(stfs
.f_files
, &target_stfs
->f_files
);
3640 put_user(stfs
.f_ffree
, &target_stfs
->f_ffree
);
3641 put_user(stfs
.f_fsid
.__val
[0], &target_stfs
->f_fsid
.val
[0]);
3642 put_user(stfs
.f_fsid
.__val
[1], &target_stfs
->f_fsid
.val
[1]);
3643 put_user(stfs
.f_namelen
, &target_stfs
->f_namelen
);
3644 unlock_user_struct(target_stfs
, arg2
, 1);
3647 case TARGET_NR_fstatfs
:
3648 ret
= get_errno(fstatfs(arg1
, &stfs
));
3649 goto convert_statfs
;
3650 #ifdef TARGET_NR_statfs64
3651 case TARGET_NR_statfs64
:
3652 p
= lock_user_string(arg1
);
3653 ret
= get_errno(statfs(path(p
), &stfs
));
3654 unlock_user(p
, arg1
, 0);
3656 if (!is_error(ret
)) {
3657 struct target_statfs64
*target_stfs
;
3659 lock_user_struct(target_stfs
, arg3
, 0);
3660 /* ??? put_user is probably wrong. */
3661 put_user(stfs
.f_type
, &target_stfs
->f_type
);
3662 put_user(stfs
.f_bsize
, &target_stfs
->f_bsize
);
3663 put_user(stfs
.f_blocks
, &target_stfs
->f_blocks
);
3664 put_user(stfs
.f_bfree
, &target_stfs
->f_bfree
);
3665 put_user(stfs
.f_bavail
, &target_stfs
->f_bavail
);
3666 put_user(stfs
.f_files
, &target_stfs
->f_files
);
3667 put_user(stfs
.f_ffree
, &target_stfs
->f_ffree
);
3668 put_user(stfs
.f_fsid
.__val
[0], &target_stfs
->f_fsid
.val
[0]);
3669 put_user(stfs
.f_fsid
.__val
[1], &target_stfs
->f_fsid
.val
[1]);
3670 put_user(stfs
.f_namelen
, &target_stfs
->f_namelen
);
3671 unlock_user_struct(target_stfs
, arg3
, 0);
3674 case TARGET_NR_fstatfs64
:
3675 ret
= get_errno(fstatfs(arg1
, &stfs
));
3676 goto convert_statfs64
;
3678 #ifdef TARGET_NR_ioperm
3679 case TARGET_NR_ioperm
:
3682 #ifdef TARGET_NR_socketcall
3683 case TARGET_NR_socketcall
:
3684 ret
= do_socketcall(arg1
, arg2
);
3687 #ifdef TARGET_NR_accept
3688 case TARGET_NR_accept
:
3689 ret
= do_accept(arg1
, arg2
, arg3
);
3692 #ifdef TARGET_NR_bind
3693 case TARGET_NR_bind
:
3694 ret
= do_bind(arg1
, arg2
, arg3
);
3697 #ifdef TARGET_NR_connect
3698 case TARGET_NR_connect
:
3699 ret
= do_connect(arg1
, arg2
, arg3
);
3702 #ifdef TARGET_NR_getpeername
3703 case TARGET_NR_getpeername
:
3704 ret
= do_getpeername(arg1
, arg2
, arg3
);
3707 #ifdef TARGET_NR_getsockname
3708 case TARGET_NR_getsockname
:
3709 ret
= do_getsockname(arg1
, arg2
, arg3
);
3712 #ifdef TARGET_NR_getsockopt
3713 case TARGET_NR_getsockopt
:
3714 ret
= do_getsockopt(arg1
, arg2
, arg3
, arg4
, arg5
);
3717 #ifdef TARGET_NR_listen
3718 case TARGET_NR_listen
:
3719 ret
= get_errno(listen(arg1
, arg2
));
3722 #ifdef TARGET_NR_recv
3723 case TARGET_NR_recv
:
3724 ret
= do_recvfrom(arg1
, arg2
, arg3
, arg4
, 0, 0);
3727 #ifdef TARGET_NR_recvfrom
3728 case TARGET_NR_recvfrom
:
3729 ret
= do_recvfrom(arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
3732 #ifdef TARGET_NR_recvmsg
3733 case TARGET_NR_recvmsg
:
3734 ret
= do_sendrecvmsg(arg1
, arg2
, arg3
, 0);
3737 #ifdef TARGET_NR_send
3738 case TARGET_NR_send
:
3739 ret
= do_sendto(arg1
, arg2
, arg3
, arg4
, 0, 0);
3742 #ifdef TARGET_NR_sendmsg
3743 case TARGET_NR_sendmsg
:
3744 ret
= do_sendrecvmsg(arg1
, arg2
, arg3
, 1);
3747 #ifdef TARGET_NR_sendto
3748 case TARGET_NR_sendto
:
3749 ret
= do_sendto(arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
3752 #ifdef TARGET_NR_shutdown
3753 case TARGET_NR_shutdown
:
3754 ret
= get_errno(shutdown(arg1
, arg2
));
3757 #ifdef TARGET_NR_socket
3758 case TARGET_NR_socket
:
3759 ret
= do_socket(arg1
, arg2
, arg3
);
3762 #ifdef TARGET_NR_socketpair
3763 case TARGET_NR_socketpair
:
3764 ret
= do_socketpair(arg1
, arg2
, arg3
, arg4
);
3767 #ifdef TARGET_NR_setsockopt
3768 case TARGET_NR_setsockopt
:
3769 ret
= do_setsockopt(arg1
, arg2
, arg3
, arg4
, (socklen_t
) arg5
);
3773 case TARGET_NR_syslog
:
3774 p
= lock_user_string(arg2
);
3775 ret
= get_errno(sys_syslog((int)arg1
, p
, (int)arg3
));
3776 unlock_user(p
, arg2
, 0);
3779 case TARGET_NR_setitimer
:
3781 struct itimerval value
, ovalue
, *pvalue
;
3785 target_to_host_timeval(&pvalue
->it_interval
,
3787 target_to_host_timeval(&pvalue
->it_value
,
3788 arg2
+ sizeof(struct target_timeval
));
3792 ret
= get_errno(setitimer(arg1
, pvalue
, &ovalue
));
3793 if (!is_error(ret
) && arg3
) {
3794 host_to_target_timeval(arg3
,
3795 &ovalue
.it_interval
);
3796 host_to_target_timeval(arg3
+ sizeof(struct target_timeval
),
3801 case TARGET_NR_getitimer
:
3803 struct itimerval value
;
3805 ret
= get_errno(getitimer(arg1
, &value
));
3806 if (!is_error(ret
) && arg2
) {
3807 host_to_target_timeval(arg2
,
3808 &value
.it_interval
);
3809 host_to_target_timeval(arg2
+ sizeof(struct target_timeval
),
3814 case TARGET_NR_stat
:
3815 p
= lock_user_string(arg1
);
3816 ret
= get_errno(stat(path(p
), &st
));
3817 unlock_user(p
, arg1
, 0);
3819 case TARGET_NR_lstat
:
3820 p
= lock_user_string(arg1
);
3821 ret
= get_errno(lstat(path(p
), &st
));
3822 unlock_user(p
, arg1
, 0);
3824 case TARGET_NR_fstat
:
3826 ret
= get_errno(fstat(arg1
, &st
));
3828 if (!is_error(ret
)) {
3829 struct target_stat
*target_st
;
3831 lock_user_struct(target_st
, arg2
, 0);
3832 #if defined(TARGET_MIPS) || (defined(TARGET_SPARC64) && !defined(TARGET_ABI32))
3833 target_st
->st_dev
= tswap32(st
.st_dev
);
3835 target_st
->st_dev
= tswap16(st
.st_dev
);
3837 target_st
->st_ino
= tswapl(st
.st_ino
);
3838 #if defined(TARGET_PPC) || defined(TARGET_MIPS)
3839 target_st
->st_mode
= tswapl(st
.st_mode
); /* XXX: check this */
3840 target_st
->st_uid
= tswap32(st
.st_uid
);
3841 target_st
->st_gid
= tswap32(st
.st_gid
);
3842 #elif defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
3843 target_st
->st_mode
= tswap32(st
.st_mode
);
3844 target_st
->st_uid
= tswap32(st
.st_uid
);
3845 target_st
->st_gid
= tswap32(st
.st_gid
);
3847 target_st
->st_mode
= tswap16(st
.st_mode
);
3848 target_st
->st_uid
= tswap16(st
.st_uid
);
3849 target_st
->st_gid
= tswap16(st
.st_gid
);
3851 #if defined(TARGET_MIPS)
3852 /* If this is the same on PPC, then just merge w/ the above ifdef */
3853 target_st
->st_nlink
= tswapl(st
.st_nlink
);
3854 target_st
->st_rdev
= tswapl(st
.st_rdev
);
3855 #elif defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
3856 target_st
->st_nlink
= tswap32(st
.st_nlink
);
3857 target_st
->st_rdev
= tswap32(st
.st_rdev
);
3859 target_st
->st_nlink
= tswap16(st
.st_nlink
);
3860 target_st
->st_rdev
= tswap16(st
.st_rdev
);
3862 target_st
->st_size
= tswapl(st
.st_size
);
3863 target_st
->st_blksize
= tswapl(st
.st_blksize
);
3864 target_st
->st_blocks
= tswapl(st
.st_blocks
);
3865 target_st
->target_st_atime
= tswapl(st
.st_atime
);
3866 target_st
->target_st_mtime
= tswapl(st
.st_mtime
);
3867 target_st
->target_st_ctime
= tswapl(st
.st_ctime
);
3868 unlock_user_struct(target_st
, arg2
, 1);
3872 #ifdef TARGET_NR_olduname
3873 case TARGET_NR_olduname
:
3876 #ifdef TARGET_NR_iopl
3877 case TARGET_NR_iopl
:
3880 case TARGET_NR_vhangup
:
3881 ret
= get_errno(vhangup());
3883 #ifdef TARGET_NR_idle
3884 case TARGET_NR_idle
:
3887 #ifdef TARGET_NR_syscall
3888 case TARGET_NR_syscall
:
3889 ret
= do_syscall(cpu_env
,arg1
& 0xffff,arg2
,arg3
,arg4
,arg5
,arg6
,0);
3892 case TARGET_NR_wait4
:
3895 abi_long status_ptr
= arg2
;
3896 struct rusage rusage
, *rusage_ptr
;
3897 abi_ulong target_rusage
= arg4
;
3899 rusage_ptr
= &rusage
;
3902 ret
= get_errno(wait4(arg1
, &status
, arg3
, rusage_ptr
));
3903 if (!is_error(ret
)) {
3905 tputl(status_ptr
, status
);
3906 if (target_rusage
) {
3907 host_to_target_rusage(target_rusage
, &rusage
);
3912 #ifdef TARGET_NR_swapoff
3913 case TARGET_NR_swapoff
:
3914 p
= lock_user_string(arg1
);
3915 ret
= get_errno(swapoff(p
));
3916 unlock_user(p
, arg1
, 0);
3919 case TARGET_NR_sysinfo
:
3921 struct target_sysinfo
*target_value
;
3922 struct sysinfo value
;
3923 ret
= get_errno(sysinfo(&value
));
3924 if (!is_error(ret
) && arg1
)
3926 /* ??? __put_user is probably wrong. */
3927 lock_user_struct(target_value
, arg1
, 0);
3928 __put_user(value
.uptime
, &target_value
->uptime
);
3929 __put_user(value
.loads
[0], &target_value
->loads
[0]);
3930 __put_user(value
.loads
[1], &target_value
->loads
[1]);
3931 __put_user(value
.loads
[2], &target_value
->loads
[2]);
3932 __put_user(value
.totalram
, &target_value
->totalram
);
3933 __put_user(value
.freeram
, &target_value
->freeram
);
3934 __put_user(value
.sharedram
, &target_value
->sharedram
);
3935 __put_user(value
.bufferram
, &target_value
->bufferram
);
3936 __put_user(value
.totalswap
, &target_value
->totalswap
);
3937 __put_user(value
.freeswap
, &target_value
->freeswap
);
3938 __put_user(value
.procs
, &target_value
->procs
);
3939 __put_user(value
.totalhigh
, &target_value
->totalhigh
);
3940 __put_user(value
.freehigh
, &target_value
->freehigh
);
3941 __put_user(value
.mem_unit
, &target_value
->mem_unit
);
3942 unlock_user_struct(target_value
, arg1
, 1);
3946 #ifdef TARGET_NR_ipc
3948 ret
= do_ipc(arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
3951 case TARGET_NR_fsync
:
3952 ret
= get_errno(fsync(arg1
));
3954 case TARGET_NR_clone
:
3955 ret
= get_errno(do_fork(cpu_env
, arg1
, arg2
));
3957 #ifdef __NR_exit_group
3958 /* new thread calls */
3959 case TARGET_NR_exit_group
:
3960 gdb_exit(cpu_env
, arg1
);
3961 ret
= get_errno(exit_group(arg1
));
3964 case TARGET_NR_setdomainname
:
3965 p
= lock_user_string(arg1
);
3966 ret
= get_errno(setdomainname(p
, arg2
));
3967 unlock_user(p
, arg1
, 0);
3969 case TARGET_NR_uname
:
3970 /* no need to transcode because we use the linux syscall */
3972 struct new_utsname
* buf
;
3974 lock_user_struct(buf
, arg1
, 0);
3975 ret
= get_errno(sys_uname(buf
));
3976 if (!is_error(ret
)) {
3977 /* Overrite the native machine name with whatever is being
3979 strcpy (buf
->machine
, UNAME_MACHINE
);
3980 /* Allow the user to override the reported release. */
3981 if (qemu_uname_release
&& *qemu_uname_release
)
3982 strcpy (buf
->release
, qemu_uname_release
);
3984 unlock_user_struct(buf
, arg1
, 1);
3988 case TARGET_NR_modify_ldt
:
3989 ret
= get_errno(do_modify_ldt(cpu_env
, arg1
, arg2
, arg3
));
3991 #if !defined(TARGET_X86_64)
3992 case TARGET_NR_vm86old
:
3994 case TARGET_NR_vm86
:
3995 ret
= do_vm86(cpu_env
, arg1
, arg2
);
3999 case TARGET_NR_adjtimex
:
4001 #ifdef TARGET_NR_create_module
4002 case TARGET_NR_create_module
:
4004 case TARGET_NR_init_module
:
4005 case TARGET_NR_delete_module
:
4006 #ifdef TARGET_NR_get_kernel_syms
4007 case TARGET_NR_get_kernel_syms
:
4010 case TARGET_NR_quotactl
:
4012 case TARGET_NR_getpgid
:
4013 ret
= get_errno(getpgid(arg1
));
4015 case TARGET_NR_fchdir
:
4016 ret
= get_errno(fchdir(arg1
));
4018 #ifdef TARGET_NR_bdflush /* not on x86_64 */
4019 case TARGET_NR_bdflush
:
4022 #ifdef TARGET_NR_sysfs
4023 case TARGET_NR_sysfs
:
4026 case TARGET_NR_personality
:
4027 ret
= get_errno(personality(arg1
));
4029 #ifdef TARGET_NR_afs_syscall
4030 case TARGET_NR_afs_syscall
:
4033 #ifdef TARGET_NR__llseek /* Not on alpha */
4034 case TARGET_NR__llseek
:
4036 #if defined (__x86_64__)
4037 ret
= get_errno(lseek(arg1
, ((uint64_t )arg2
<< 32) | arg3
, arg5
));
4041 ret
= get_errno(_llseek(arg1
, arg2
, arg3
, &res
, arg5
));
4047 case TARGET_NR_getdents
:
4048 #if TARGET_ABI_BITS != 32
4050 #warning not supported
4051 #elif TARGET_ABI_BITS == 32 && HOST_LONG_BITS == 64
4053 struct target_dirent
*target_dirp
;
4054 struct dirent
*dirp
;
4055 abi_long count
= arg3
;
4057 dirp
= malloc(count
);
4061 ret
= get_errno(sys_getdents(arg1
, dirp
, count
));
4062 if (!is_error(ret
)) {
4064 struct target_dirent
*tde
;
4066 int reclen
, treclen
;
4067 int count1
, tnamelen
;
4071 target_dirp
= lock_user(arg2
, count
, 0);
4074 reclen
= de
->d_reclen
;
4075 treclen
= reclen
- (2 * (sizeof(long) - sizeof(abi_long
)));
4076 tde
->d_reclen
= tswap16(treclen
);
4077 tde
->d_ino
= tswapl(de
->d_ino
);
4078 tde
->d_off
= tswapl(de
->d_off
);
4079 tnamelen
= treclen
- (2 * sizeof(abi_long
) + 2);
4082 /* XXX: may not be correct */
4083 strncpy(tde
->d_name
, de
->d_name
, tnamelen
);
4084 de
= (struct dirent
*)((char *)de
+ reclen
);
4086 tde
= (struct target_dirent
*)((char *)tde
+ treclen
);
4091 unlock_user(target_dirp
, arg2
, ret
);
4096 struct dirent
*dirp
;
4097 abi_long count
= arg3
;
4099 dirp
= lock_user(arg2
, count
, 0);
4100 ret
= get_errno(sys_getdents(arg1
, dirp
, count
));
4101 if (!is_error(ret
)) {
4107 reclen
= de
->d_reclen
;
4110 de
->d_reclen
= tswap16(reclen
);
4111 tswapls(&de
->d_ino
);
4112 tswapls(&de
->d_off
);
4113 de
= (struct dirent
*)((char *)de
+ reclen
);
4117 unlock_user(dirp
, arg2
, ret
);
4121 #if defined(TARGET_NR_getdents64) && defined(__NR_getdents64)
4122 case TARGET_NR_getdents64
:
4124 struct dirent64
*dirp
;
4125 abi_long count
= arg3
;
4126 dirp
= lock_user(arg2
, count
, 0);
4127 ret
= get_errno(sys_getdents64(arg1
, dirp
, count
));
4128 if (!is_error(ret
)) {
4129 struct dirent64
*de
;
4134 reclen
= de
->d_reclen
;
4137 de
->d_reclen
= tswap16(reclen
);
4138 tswap64s(&de
->d_ino
);
4139 tswap64s(&de
->d_off
);
4140 de
= (struct dirent64
*)((char *)de
+ reclen
);
4144 unlock_user(dirp
, arg2
, ret
);
4147 #endif /* TARGET_NR_getdents64 */
4148 #ifdef TARGET_NR__newselect
4149 case TARGET_NR__newselect
:
4150 ret
= do_select(arg1
, arg2
, arg3
, arg4
, arg5
);
4153 #ifdef TARGET_NR_poll
4154 case TARGET_NR_poll
:
4156 struct target_pollfd
*target_pfd
;
4157 unsigned int nfds
= arg2
;
4162 target_pfd
= lock_user(arg1
, sizeof(struct target_pollfd
) * nfds
, 1);
4163 pfd
= alloca(sizeof(struct pollfd
) * nfds
);
4164 for(i
= 0; i
< nfds
; i
++) {
4165 pfd
[i
].fd
= tswap32(target_pfd
[i
].fd
);
4166 pfd
[i
].events
= tswap16(target_pfd
[i
].events
);
4168 ret
= get_errno(poll(pfd
, nfds
, timeout
));
4169 if (!is_error(ret
)) {
4170 for(i
= 0; i
< nfds
; i
++) {
4171 target_pfd
[i
].revents
= tswap16(pfd
[i
].revents
);
4173 ret
+= nfds
* (sizeof(struct target_pollfd
)
4174 - sizeof(struct pollfd
));
4176 unlock_user(target_pfd
, arg1
, ret
);
4180 case TARGET_NR_flock
:
4181 /* NOTE: the flock constant seems to be the same for every
4183 ret
= get_errno(flock(arg1
, arg2
));
4185 case TARGET_NR_readv
:
4190 vec
= alloca(count
* sizeof(struct iovec
));
4191 lock_iovec(vec
, arg2
, count
, 0);
4192 ret
= get_errno(readv(arg1
, vec
, count
));
4193 unlock_iovec(vec
, arg2
, count
, 1);
4196 case TARGET_NR_writev
:
4201 vec
= alloca(count
* sizeof(struct iovec
));
4202 lock_iovec(vec
, arg2
, count
, 1);
4203 ret
= get_errno(writev(arg1
, vec
, count
));
4204 unlock_iovec(vec
, arg2
, count
, 0);
4207 case TARGET_NR_getsid
:
4208 ret
= get_errno(getsid(arg1
));
4210 #if defined(TARGET_NR_fdatasync) /* Not on alpha (osf_datasync ?) */
4211 case TARGET_NR_fdatasync
:
4212 ret
= get_errno(fdatasync(arg1
));
4215 case TARGET_NR__sysctl
:
4216 /* We don't implement this, but ENODIR is always a safe
4219 case TARGET_NR_sched_setparam
:
4221 struct sched_param
*target_schp
;
4222 struct sched_param schp
;
4224 lock_user_struct(target_schp
, arg2
, 1);
4225 schp
.sched_priority
= tswap32(target_schp
->sched_priority
);
4226 unlock_user_struct(target_schp
, arg2
, 0);
4227 ret
= get_errno(sched_setparam(arg1
, &schp
));
4230 case TARGET_NR_sched_getparam
:
4232 struct sched_param
*target_schp
;
4233 struct sched_param schp
;
4234 ret
= get_errno(sched_getparam(arg1
, &schp
));
4235 if (!is_error(ret
)) {
4236 lock_user_struct(target_schp
, arg2
, 0);
4237 target_schp
->sched_priority
= tswap32(schp
.sched_priority
);
4238 unlock_user_struct(target_schp
, arg2
, 1);
4242 case TARGET_NR_sched_setscheduler
:
4244 struct sched_param
*target_schp
;
4245 struct sched_param schp
;
4246 lock_user_struct(target_schp
, arg3
, 1);
4247 schp
.sched_priority
= tswap32(target_schp
->sched_priority
);
4248 unlock_user_struct(target_schp
, arg3
, 0);
4249 ret
= get_errno(sched_setscheduler(arg1
, arg2
, &schp
));
4252 case TARGET_NR_sched_getscheduler
:
4253 ret
= get_errno(sched_getscheduler(arg1
));
4255 case TARGET_NR_sched_yield
:
4256 ret
= get_errno(sched_yield());
4258 case TARGET_NR_sched_get_priority_max
:
4259 ret
= get_errno(sched_get_priority_max(arg1
));
4261 case TARGET_NR_sched_get_priority_min
:
4262 ret
= get_errno(sched_get_priority_min(arg1
));
4264 case TARGET_NR_sched_rr_get_interval
:
4267 ret
= get_errno(sched_rr_get_interval(arg1
, &ts
));
4268 if (!is_error(ret
)) {
4269 host_to_target_timespec(arg2
, &ts
);
4273 case TARGET_NR_nanosleep
:
4275 struct timespec req
, rem
;
4276 target_to_host_timespec(&req
, arg1
);
4277 ret
= get_errno(nanosleep(&req
, &rem
));
4278 if (is_error(ret
) && arg2
) {
4279 host_to_target_timespec(arg2
, &rem
);
4283 #ifdef TARGET_NR_query_module
4284 case TARGET_NR_query_module
:
4287 #ifdef TARGET_NR_nfsservctl
4288 case TARGET_NR_nfsservctl
:
4291 case TARGET_NR_prctl
:
4294 case PR_GET_PDEATHSIG
:
4297 ret
= get_errno(prctl(arg1
, &deathsig
, arg3
, arg4
, arg5
));
4298 if (!is_error(ret
) && arg2
)
4299 tput32(arg2
, deathsig
);
4303 ret
= get_errno(prctl(arg1
, arg2
, arg3
, arg4
, arg5
));
4307 #ifdef TARGET_NR_pread
4308 case TARGET_NR_pread
:
4309 page_unprotect_range(arg2
, arg3
);
4310 p
= lock_user(arg2
, arg3
, 0);
4311 ret
= get_errno(pread(arg1
, p
, arg3
, arg4
));
4312 unlock_user(p
, arg2
, ret
);
4314 case TARGET_NR_pwrite
:
4315 p
= lock_user(arg2
, arg3
, 1);
4316 ret
= get_errno(pwrite(arg1
, p
, arg3
, arg4
));
4317 unlock_user(p
, arg2
, 0);
4320 case TARGET_NR_getcwd
:
4321 p
= lock_user(arg1
, arg2
, 0);
4322 ret
= get_errno(sys_getcwd1(p
, arg2
));
4323 unlock_user(p
, arg1
, ret
);
4325 case TARGET_NR_capget
:
4327 case TARGET_NR_capset
:
4329 case TARGET_NR_sigaltstack
:
4330 #if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_MIPS) || \
4331 defined(TARGET_SPARC) || defined(TARGET_PPC) || defined(TARGET_ALPHA)
4332 ret
= do_sigaltstack((struct target_sigaltstack
*)arg1
,
4333 (struct target_sigaltstack
*)arg2
,
4334 get_sp_from_cpustate((CPUState
*)cpu_env
));
4339 case TARGET_NR_sendfile
:
4341 #ifdef TARGET_NR_getpmsg
4342 case TARGET_NR_getpmsg
:
4345 #ifdef TARGET_NR_putpmsg
4346 case TARGET_NR_putpmsg
:
4349 #ifdef TARGET_NR_vfork
4350 case TARGET_NR_vfork
:
4351 ret
= get_errno(do_fork(cpu_env
, CLONE_VFORK
| CLONE_VM
| SIGCHLD
, 0));
4354 #ifdef TARGET_NR_ugetrlimit
4355 case TARGET_NR_ugetrlimit
:
4358 ret
= get_errno(getrlimit(arg1
, &rlim
));
4359 if (!is_error(ret
)) {
4360 struct target_rlimit
*target_rlim
;
4361 lock_user_struct(target_rlim
, arg2
, 0);
4362 target_rlim
->rlim_cur
= tswapl(rlim
.rlim_cur
);
4363 target_rlim
->rlim_max
= tswapl(rlim
.rlim_max
);
4364 unlock_user_struct(target_rlim
, arg2
, 1);
4369 #ifdef TARGET_NR_truncate64
4370 case TARGET_NR_truncate64
:
4371 p
= lock_user_string(arg1
);
4372 ret
= target_truncate64(cpu_env
, p
, arg2
, arg3
, arg4
);
4373 unlock_user(p
, arg1
, 0);
4376 #ifdef TARGET_NR_ftruncate64
4377 case TARGET_NR_ftruncate64
:
4378 ret
= target_ftruncate64(cpu_env
, arg1
, arg2
, arg3
, arg4
);
4381 #ifdef TARGET_NR_stat64
4382 case TARGET_NR_stat64
:
4383 p
= lock_user_string(arg1
);
4384 ret
= get_errno(stat(path(p
), &st
));
4385 unlock_user(p
, arg1
, 0);
4388 #ifdef TARGET_NR_lstat64
4389 case TARGET_NR_lstat64
:
4390 p
= lock_user_string(arg1
);
4391 ret
= get_errno(lstat(path(p
), &st
));
4392 unlock_user(p
, arg1
, 0);
4395 #ifdef TARGET_NR_fstat64
4396 case TARGET_NR_fstat64
:
4398 ret
= get_errno(fstat(arg1
, &st
));
4400 if (!is_error(ret
)) {
4402 if (((CPUARMState
*)cpu_env
)->eabi
) {
4403 struct target_eabi_stat64
*target_st
;
4404 lock_user_struct(target_st
, arg2
, 1);
4405 memset(target_st
, 0, sizeof(struct target_eabi_stat64
));
4406 /* put_user is probably wrong. */
4407 put_user(st
.st_dev
, &target_st
->st_dev
);
4408 put_user(st
.st_ino
, &target_st
->st_ino
);
4409 #ifdef TARGET_STAT64_HAS_BROKEN_ST_INO
4410 put_user(st
.st_ino
, &target_st
->__st_ino
);
4412 put_user(st
.st_mode
, &target_st
->st_mode
);
4413 put_user(st
.st_nlink
, &target_st
->st_nlink
);
4414 put_user(st
.st_uid
, &target_st
->st_uid
);
4415 put_user(st
.st_gid
, &target_st
->st_gid
);
4416 put_user(st
.st_rdev
, &target_st
->st_rdev
);
4417 /* XXX: better use of kernel struct */
4418 put_user(st
.st_size
, &target_st
->st_size
);
4419 put_user(st
.st_blksize
, &target_st
->st_blksize
);
4420 put_user(st
.st_blocks
, &target_st
->st_blocks
);
4421 put_user(st
.st_atime
, &target_st
->target_st_atime
);
4422 put_user(st
.st_mtime
, &target_st
->target_st_mtime
);
4423 put_user(st
.st_ctime
, &target_st
->target_st_ctime
);
4424 unlock_user_struct(target_st
, arg2
, 0);
4428 struct target_stat64
*target_st
;
4429 lock_user_struct(target_st
, arg2
, 1);
4430 memset(target_st
, 0, sizeof(struct target_stat64
));
4431 /* ??? put_user is probably wrong. */
4432 put_user(st
.st_dev
, &target_st
->st_dev
);
4433 put_user(st
.st_ino
, &target_st
->st_ino
);
4434 #ifdef TARGET_STAT64_HAS_BROKEN_ST_INO
4435 put_user(st
.st_ino
, &target_st
->__st_ino
);
4437 put_user(st
.st_mode
, &target_st
->st_mode
);
4438 put_user(st
.st_nlink
, &target_st
->st_nlink
);
4439 put_user(st
.st_uid
, &target_st
->st_uid
);
4440 put_user(st
.st_gid
, &target_st
->st_gid
);
4441 put_user(st
.st_rdev
, &target_st
->st_rdev
);
4442 /* XXX: better use of kernel struct */
4443 put_user(st
.st_size
, &target_st
->st_size
);
4444 put_user(st
.st_blksize
, &target_st
->st_blksize
);
4445 put_user(st
.st_blocks
, &target_st
->st_blocks
);
4446 put_user(st
.st_atime
, &target_st
->target_st_atime
);
4447 put_user(st
.st_mtime
, &target_st
->target_st_mtime
);
4448 put_user(st
.st_ctime
, &target_st
->target_st_ctime
);
4449 unlock_user_struct(target_st
, arg2
, 0);
4456 case TARGET_NR_lchown
:
4457 p
= lock_user_string(arg1
);
4458 ret
= get_errno(lchown(p
, low2highuid(arg2
), low2highgid(arg3
)));
4459 unlock_user(p
, arg1
, 0);
4461 case TARGET_NR_getuid
:
4462 ret
= get_errno(high2lowuid(getuid()));
4464 case TARGET_NR_getgid
:
4465 ret
= get_errno(high2lowgid(getgid()));
4467 case TARGET_NR_geteuid
:
4468 ret
= get_errno(high2lowuid(geteuid()));
4470 case TARGET_NR_getegid
:
4471 ret
= get_errno(high2lowgid(getegid()));
4473 case TARGET_NR_setreuid
:
4474 ret
= get_errno(setreuid(low2highuid(arg1
), low2highuid(arg2
)));
4476 case TARGET_NR_setregid
:
4477 ret
= get_errno(setregid(low2highgid(arg1
), low2highgid(arg2
)));
4479 case TARGET_NR_getgroups
:
4481 int gidsetsize
= arg1
;
4482 uint16_t *target_grouplist
;
4486 grouplist
= alloca(gidsetsize
* sizeof(gid_t
));
4487 ret
= get_errno(getgroups(gidsetsize
, grouplist
));
4488 if (!is_error(ret
)) {
4489 target_grouplist
= lock_user(arg2
, gidsetsize
* 2, 0);
4490 for(i
= 0;i
< gidsetsize
; i
++)
4491 target_grouplist
[i
] = tswap16(grouplist
[i
]);
4492 unlock_user(target_grouplist
, arg2
, gidsetsize
* 2);
4496 case TARGET_NR_setgroups
:
4498 int gidsetsize
= arg1
;
4499 uint16_t *target_grouplist
;
4503 grouplist
= alloca(gidsetsize
* sizeof(gid_t
));
4504 target_grouplist
= lock_user(arg2
, gidsetsize
* 2, 1);
4505 for(i
= 0;i
< gidsetsize
; i
++)
4506 grouplist
[i
] = tswap16(target_grouplist
[i
]);
4507 unlock_user(target_grouplist
, arg2
, 0);
4508 ret
= get_errno(setgroups(gidsetsize
, grouplist
));
4511 case TARGET_NR_fchown
:
4512 ret
= get_errno(fchown(arg1
, low2highuid(arg2
), low2highgid(arg3
)));
4514 #if defined(TARGET_NR_fchownat) && defined(__NR_fchownat)
4515 case TARGET_NR_fchownat
:
4520 p
= lock_user_string(arg2
);
4521 if (!access_ok(VERIFY_READ
, p
, 1))
4524 ret
= get_errno(sys_fchownat(arg1
, p
, low2highuid(arg3
), low2highgid(arg4
), arg5
));
4526 unlock_user(p
, arg2
, 0);
4529 #ifdef TARGET_NR_setresuid
4530 case TARGET_NR_setresuid
:
4531 ret
= get_errno(setresuid(low2highuid(arg1
),
4533 low2highuid(arg3
)));
4536 #ifdef TARGET_NR_getresuid
4537 case TARGET_NR_getresuid
:
4539 uid_t ruid
, euid
, suid
;
4540 ret
= get_errno(getresuid(&ruid
, &euid
, &suid
));
4541 if (!is_error(ret
)) {
4542 tput16(arg1
, tswap16(high2lowuid(ruid
)));
4543 tput16(arg2
, tswap16(high2lowuid(euid
)));
4544 tput16(arg3
, tswap16(high2lowuid(suid
)));
4549 #ifdef TARGET_NR_getresgid
4550 case TARGET_NR_setresgid
:
4551 ret
= get_errno(setresgid(low2highgid(arg1
),
4553 low2highgid(arg3
)));
4556 #ifdef TARGET_NR_getresgid
4557 case TARGET_NR_getresgid
:
4559 gid_t rgid
, egid
, sgid
;
4560 ret
= get_errno(getresgid(&rgid
, &egid
, &sgid
));
4561 if (!is_error(ret
)) {
4562 tput16(arg1
, tswap16(high2lowgid(rgid
)));
4563 tput16(arg2
, tswap16(high2lowgid(egid
)));
4564 tput16(arg3
, tswap16(high2lowgid(sgid
)));
4569 case TARGET_NR_chown
:
4570 p
= lock_user_string(arg1
);
4571 ret
= get_errno(chown(p
, low2highuid(arg2
), low2highgid(arg3
)));
4572 unlock_user(p
, arg1
, 0);
4574 case TARGET_NR_setuid
:
4575 ret
= get_errno(setuid(low2highuid(arg1
)));
4577 case TARGET_NR_setgid
:
4578 ret
= get_errno(setgid(low2highgid(arg1
)));
4580 case TARGET_NR_setfsuid
:
4581 ret
= get_errno(setfsuid(arg1
));
4583 case TARGET_NR_setfsgid
:
4584 ret
= get_errno(setfsgid(arg1
));
4586 #endif /* USE_UID16 */
4588 #ifdef TARGET_NR_lchown32
4589 case TARGET_NR_lchown32
:
4590 p
= lock_user_string(arg1
);
4591 ret
= get_errno(lchown(p
, arg2
, arg3
));
4592 unlock_user(p
, arg1
, 0);
4595 #ifdef TARGET_NR_getuid32
4596 case TARGET_NR_getuid32
:
4597 ret
= get_errno(getuid());
4600 #ifdef TARGET_NR_getgid32
4601 case TARGET_NR_getgid32
:
4602 ret
= get_errno(getgid());
4605 #ifdef TARGET_NR_geteuid32
4606 case TARGET_NR_geteuid32
:
4607 ret
= get_errno(geteuid());
4610 #ifdef TARGET_NR_getegid32
4611 case TARGET_NR_getegid32
:
4612 ret
= get_errno(getegid());
4615 #ifdef TARGET_NR_setreuid32
4616 case TARGET_NR_setreuid32
:
4617 ret
= get_errno(setreuid(arg1
, arg2
));
4620 #ifdef TARGET_NR_setregid32
4621 case TARGET_NR_setregid32
:
4622 ret
= get_errno(setregid(arg1
, arg2
));
4625 #ifdef TARGET_NR_getgroups32
4626 case TARGET_NR_getgroups32
:
4628 int gidsetsize
= arg1
;
4629 uint32_t *target_grouplist
;
4633 grouplist
= alloca(gidsetsize
* sizeof(gid_t
));
4634 ret
= get_errno(getgroups(gidsetsize
, grouplist
));
4635 if (!is_error(ret
)) {
4636 target_grouplist
= lock_user(arg2
, gidsetsize
* 4, 0);
4637 for(i
= 0;i
< gidsetsize
; i
++)
4638 target_grouplist
[i
] = tswap32(grouplist
[i
]);
4639 unlock_user(target_grouplist
, arg2
, gidsetsize
* 4);
4644 #ifdef TARGET_NR_setgroups32
4645 case TARGET_NR_setgroups32
:
4647 int gidsetsize
= arg1
;
4648 uint32_t *target_grouplist
;
4652 grouplist
= alloca(gidsetsize
* sizeof(gid_t
));
4653 target_grouplist
= lock_user(arg2
, gidsetsize
* 4, 1);
4654 for(i
= 0;i
< gidsetsize
; i
++)
4655 grouplist
[i
] = tswap32(target_grouplist
[i
]);
4656 unlock_user(target_grouplist
, arg2
, 0);
4657 ret
= get_errno(setgroups(gidsetsize
, grouplist
));
4661 #ifdef TARGET_NR_fchown32
4662 case TARGET_NR_fchown32
:
4663 ret
= get_errno(fchown(arg1
, arg2
, arg3
));
4666 #ifdef TARGET_NR_setresuid32
4667 case TARGET_NR_setresuid32
:
4668 ret
= get_errno(setresuid(arg1
, arg2
, arg3
));
4671 #ifdef TARGET_NR_getresuid32
4672 case TARGET_NR_getresuid32
:
4674 uid_t ruid
, euid
, suid
;
4675 ret
= get_errno(getresuid(&ruid
, &euid
, &suid
));
4676 if (!is_error(ret
)) {
4677 tput32(arg1
, tswap32(ruid
));
4678 tput32(arg2
, tswap32(euid
));
4679 tput32(arg3
, tswap32(suid
));
4684 #ifdef TARGET_NR_setresgid32
4685 case TARGET_NR_setresgid32
:
4686 ret
= get_errno(setresgid(arg1
, arg2
, arg3
));
4689 #ifdef TARGET_NR_getresgid32
4690 case TARGET_NR_getresgid32
:
4692 gid_t rgid
, egid
, sgid
;
4693 ret
= get_errno(getresgid(&rgid
, &egid
, &sgid
));
4694 if (!is_error(ret
)) {
4695 tput32(arg1
, tswap32(rgid
));
4696 tput32(arg2
, tswap32(egid
));
4697 tput32(arg3
, tswap32(sgid
));
4702 #ifdef TARGET_NR_chown32
4703 case TARGET_NR_chown32
:
4704 p
= lock_user_string(arg1
);
4705 ret
= get_errno(chown(p
, arg2
, arg3
));
4706 unlock_user(p
, arg1
, 0);
4709 #ifdef TARGET_NR_setuid32
4710 case TARGET_NR_setuid32
:
4711 ret
= get_errno(setuid(arg1
));
4714 #ifdef TARGET_NR_setgid32
4715 case TARGET_NR_setgid32
:
4716 ret
= get_errno(setgid(arg1
));
4719 #ifdef TARGET_NR_setfsuid32
4720 case TARGET_NR_setfsuid32
:
4721 ret
= get_errno(setfsuid(arg1
));
4724 #ifdef TARGET_NR_setfsgid32
4725 case TARGET_NR_setfsgid32
:
4726 ret
= get_errno(setfsgid(arg1
));
4730 case TARGET_NR_pivot_root
:
4732 #ifdef TARGET_NR_mincore
4733 case TARGET_NR_mincore
:
4736 #ifdef TARGET_NR_madvise
4737 case TARGET_NR_madvise
:
4738 /* A straight passthrough may not be safe because qemu sometimes
4739 turns private flie-backed mappings into anonymous mappings.
4740 This will break MADV_DONTNEED.
4741 This is a hint, so ignoring and returning success is ok. */
4745 #if TARGET_ABI_BITS == 32
4746 case TARGET_NR_fcntl64
:
4750 struct target_flock64
*target_fl
;
4752 struct target_eabi_flock64
*target_efl
;
4756 case TARGET_F_GETLK64
:
4759 case TARGET_F_SETLK64
:
4762 case TARGET_F_SETLKW64
:
4771 case TARGET_F_GETLK64
:
4773 if (((CPUARMState
*)cpu_env
)->eabi
) {
4774 lock_user_struct(target_efl
, arg3
, 1);
4775 fl
.l_type
= tswap16(target_efl
->l_type
);
4776 fl
.l_whence
= tswap16(target_efl
->l_whence
);
4777 fl
.l_start
= tswap64(target_efl
->l_start
);
4778 fl
.l_len
= tswap64(target_efl
->l_len
);
4779 fl
.l_pid
= tswapl(target_efl
->l_pid
);
4780 unlock_user_struct(target_efl
, arg3
, 0);
4784 lock_user_struct(target_fl
, arg3
, 1);
4785 fl
.l_type
= tswap16(target_fl
->l_type
);
4786 fl
.l_whence
= tswap16(target_fl
->l_whence
);
4787 fl
.l_start
= tswap64(target_fl
->l_start
);
4788 fl
.l_len
= tswap64(target_fl
->l_len
);
4789 fl
.l_pid
= tswapl(target_fl
->l_pid
);
4790 unlock_user_struct(target_fl
, arg3
, 0);
4792 ret
= get_errno(fcntl(arg1
, cmd
, &fl
));
4795 if (((CPUARMState
*)cpu_env
)->eabi
) {
4796 lock_user_struct(target_efl
, arg3
, 0);
4797 target_efl
->l_type
= tswap16(fl
.l_type
);
4798 target_efl
->l_whence
= tswap16(fl
.l_whence
);
4799 target_efl
->l_start
= tswap64(fl
.l_start
);
4800 target_efl
->l_len
= tswap64(fl
.l_len
);
4801 target_efl
->l_pid
= tswapl(fl
.l_pid
);
4802 unlock_user_struct(target_efl
, arg3
, 1);
4806 lock_user_struct(target_fl
, arg3
, 0);
4807 target_fl
->l_type
= tswap16(fl
.l_type
);
4808 target_fl
->l_whence
= tswap16(fl
.l_whence
);
4809 target_fl
->l_start
= tswap64(fl
.l_start
);
4810 target_fl
->l_len
= tswap64(fl
.l_len
);
4811 target_fl
->l_pid
= tswapl(fl
.l_pid
);
4812 unlock_user_struct(target_fl
, arg3
, 1);
4817 case TARGET_F_SETLK64
:
4818 case TARGET_F_SETLKW64
:
4820 if (((CPUARMState
*)cpu_env
)->eabi
) {
4821 lock_user_struct(target_efl
, arg3
, 1);
4822 fl
.l_type
= tswap16(target_efl
->l_type
);
4823 fl
.l_whence
= tswap16(target_efl
->l_whence
);
4824 fl
.l_start
= tswap64(target_efl
->l_start
);
4825 fl
.l_len
= tswap64(target_efl
->l_len
);
4826 fl
.l_pid
= tswapl(target_efl
->l_pid
);
4827 unlock_user_struct(target_efl
, arg3
, 0);
4831 lock_user_struct(target_fl
, arg3
, 1);
4832 fl
.l_type
= tswap16(target_fl
->l_type
);
4833 fl
.l_whence
= tswap16(target_fl
->l_whence
);
4834 fl
.l_start
= tswap64(target_fl
->l_start
);
4835 fl
.l_len
= tswap64(target_fl
->l_len
);
4836 fl
.l_pid
= tswapl(target_fl
->l_pid
);
4837 unlock_user_struct(target_fl
, arg3
, 0);
4839 ret
= get_errno(fcntl(arg1
, cmd
, &fl
));
4842 ret
= get_errno(do_fcntl(arg1
, cmd
, arg3
));
4848 #ifdef TARGET_NR_cacheflush
4849 case TARGET_NR_cacheflush
:
4850 /* self-modifying code is handled automatically, so nothing needed */
4854 #ifdef TARGET_NR_security
4855 case TARGET_NR_security
:
4858 #ifdef TARGET_NR_getpagesize
4859 case TARGET_NR_getpagesize
:
4860 ret
= TARGET_PAGE_SIZE
;
4863 case TARGET_NR_gettid
:
4864 ret
= get_errno(gettid());
4866 #ifdef TARGET_NR_readahead
4867 case TARGET_NR_readahead
:
4870 #ifdef TARGET_NR_setxattr
4871 case TARGET_NR_setxattr
:
4872 case TARGET_NR_lsetxattr
:
4873 case TARGET_NR_fsetxattr
:
4874 case TARGET_NR_getxattr
:
4875 case TARGET_NR_lgetxattr
:
4876 case TARGET_NR_fgetxattr
:
4877 case TARGET_NR_listxattr
:
4878 case TARGET_NR_llistxattr
:
4879 case TARGET_NR_flistxattr
:
4880 case TARGET_NR_removexattr
:
4881 case TARGET_NR_lremovexattr
:
4882 case TARGET_NR_fremovexattr
:
4883 goto unimplemented_nowarn
;
4885 #ifdef TARGET_NR_set_thread_area
4886 case TARGET_NR_set_thread_area
:
4888 ((CPUMIPSState
*) cpu_env
)->tls_value
= arg1
;
4892 goto unimplemented_nowarn
;
4895 #ifdef TARGET_NR_get_thread_area
4896 case TARGET_NR_get_thread_area
:
4897 goto unimplemented_nowarn
;
4899 #ifdef TARGET_NR_getdomainname
4900 case TARGET_NR_getdomainname
:
4901 goto unimplemented_nowarn
;
4904 #ifdef TARGET_NR_clock_gettime
4905 case TARGET_NR_clock_gettime
:
4908 ret
= get_errno(clock_gettime(arg1
, &ts
));
4909 if (!is_error(ret
)) {
4910 host_to_target_timespec(arg2
, &ts
);
4915 #ifdef TARGET_NR_clock_getres
4916 case TARGET_NR_clock_getres
:
4919 ret
= get_errno(clock_getres(arg1
, &ts
));
4920 if (!is_error(ret
)) {
4921 host_to_target_timespec(arg2
, &ts
);
4927 #if defined(TARGET_NR_set_tid_address) && defined(__NR_set_tid_address)
4928 case TARGET_NR_set_tid_address
:
4929 ret
= get_errno(set_tid_address((int *) arg1
));
4933 #if defined(TARGET_NR_tkill) && defined(__NR_tkill)
4934 case TARGET_NR_tkill
:
4935 ret
= get_errno(sys_tkill((int)arg1
, (int)arg2
));
4939 #if defined(TARGET_NR_tgkill) && defined(__NR_tgkill)
4940 case TARGET_NR_tgkill
:
4941 ret
= get_errno(sys_tgkill((int)arg1
, (int)arg2
, (int)arg3
));
4945 #ifdef TARGET_NR_set_robust_list
4946 case TARGET_NR_set_robust_list
:
4947 goto unimplemented_nowarn
;
4950 #if defined(TARGET_NR_utimensat) && defined(__NR_utimensat)
4951 case TARGET_NR_utimensat
:
4953 struct timespec ts
[2];
4954 target_to_host_timespec(ts
, arg3
);
4955 target_to_host_timespec(ts
+1, arg3
+sizeof(struct target_timespec
));
4957 ret
= get_errno(sys_utimensat(arg1
, NULL
, ts
, arg4
));
4959 p
= lock_user_string(arg2
);
4960 if (!access_ok(VERIFY_READ
, p
, 1))
4963 ret
= get_errno(sys_utimensat(arg1
, path(p
), ts
, arg4
));
4965 unlock_user(p
, arg2
, 0);
4973 gemu_log("qemu: Unsupported syscall: %d\n", num
);
4974 #if defined(TARGET_NR_setxattr) || defined(TARGET_NR_get_thread_area) || defined(TARGET_NR_getdomainname) || defined(TARGET_NR_set_robust_list)
4975 unimplemented_nowarn
:
4982 gemu_log(" = %ld\n", ret
);