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)
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_getcwd1 __NR_getcwd
143 #define __NR_sys_getdents __NR_getdents
144 #define __NR_sys_getdents64 __NR_getdents64
145 #define __NR_sys_rt_sigqueueinfo __NR_rt_sigqueueinfo
146 #define __NR_sys_syslog __NR_syslog
147 #define __NR_sys_tgkill __NR_tgkill
148 #define __NR_sys_tkill __NR_tkill
150 #if defined(__alpha__) || defined (__ia64__) || defined(__x86_64__)
151 #define __NR__llseek __NR_lseek
155 _syscall0(int, gettid)
157 static int gettid(void) {
161 _syscall1(int,sys_uname,struct new_utsname *,buf)
162 _syscall2(int,sys_getcwd1,char *,buf,size_t,size)
163 _syscall3(int, sys_getdents, uint, fd, struct dirent *, dirp, uint, count);
164 _syscall3(int, sys_getdents64, uint, fd, struct dirent64 *, dirp, uint, count);
165 _syscall5(int, _llseek, uint, fd, ulong, hi, ulong, lo,
166 loff_t *, res, uint, wh);
167 _syscall3(int,sys_rt_sigqueueinfo,int,pid,int,sig,siginfo_t *,uinfo)
168 _syscall3(int,sys_syslog,int,type,char*,bufp,int,len)
169 #ifdef TARGET_NR_tgkill
170 _syscall3(int,sys_tgkill,int,tgid,int,pid,int,sig)
172 #ifdef TARGET_NR_tkill
173 _syscall2(int,sys_tkill,int,tid,int,sig)
175 #ifdef __NR_exit_group
176 _syscall1(int,exit_group,int,error_code)
178 #if defined(TARGET_NR_set_tid_address) && defined(__NR_set_tid_address)
179 _syscall1(int,set_tid_address,int *,tidptr)
182 extern int personality(int);
183 extern int flock(int, int);
184 extern int setfsuid(int);
185 extern int setfsgid(int);
186 extern int setresuid(uid_t, uid_t, uid_t);
187 extern int getresuid(uid_t *, uid_t *, uid_t *);
188 extern int setresgid(gid_t, gid_t, gid_t);
189 extern int getresgid(gid_t *, gid_t *, gid_t *);
190 extern int setgroups(int, gid_t *);
193 * This list is the union of errno values overridden in asm-<arch>/errno.h
194 * minus the errnos that are not actually generic to all archs.
196 static uint16_t host_to_target_errno_table[1200] = {
197 [EIDRM] = TARGET_EIDRM,
198 [ECHRNG] = TARGET_ECHRNG,
199 [EL2NSYNC] = TARGET_EL2NSYNC,
200 [EL3HLT] = TARGET_EL3HLT,
201 [EL3RST] = TARGET_EL3RST,
202 [ELNRNG] = TARGET_ELNRNG,
203 [EUNATCH] = TARGET_EUNATCH,
204 [ENOCSI] = TARGET_ENOCSI,
205 [EL2HLT] = TARGET_EL2HLT,
206 [EDEADLK] = TARGET_EDEADLK,
207 [ENOLCK] = TARGET_ENOLCK,
208 [EBADE] = TARGET_EBADE,
209 [EBADR] = TARGET_EBADR,
210 [EXFULL] = TARGET_EXFULL,
211 [ENOANO] = TARGET_ENOANO,
212 [EBADRQC] = TARGET_EBADRQC,
213 [EBADSLT] = TARGET_EBADSLT,
214 [EBFONT] = TARGET_EBFONT,
215 [ENOSTR] = TARGET_ENOSTR,
216 [ENODATA] = TARGET_ENODATA,
217 [ETIME] = TARGET_ETIME,
218 [ENOSR] = TARGET_ENOSR,
219 [ENONET] = TARGET_ENONET,
220 [ENOPKG] = TARGET_ENOPKG,
221 [EREMOTE] = TARGET_EREMOTE,
222 [ENOLINK] = TARGET_ENOLINK,
223 [EADV] = TARGET_EADV,
224 [ESRMNT] = TARGET_ESRMNT,
225 [ECOMM] = TARGET_ECOMM,
226 [EPROTO] = TARGET_EPROTO,
227 [EDOTDOT] = TARGET_EDOTDOT,
228 [EMULTIHOP] = TARGET_EMULTIHOP,
229 [EBADMSG] = TARGET_EBADMSG,
230 [ENAMETOOLONG] = TARGET_ENAMETOOLONG,
231 [EOVERFLOW] = TARGET_EOVERFLOW,
232 [ENOTUNIQ] = TARGET_ENOTUNIQ,
233 [EBADFD] = TARGET_EBADFD,
234 [EREMCHG] = TARGET_EREMCHG,
235 [ELIBACC] = TARGET_ELIBACC,
236 [ELIBBAD] = TARGET_ELIBBAD,
237 [ELIBSCN] = TARGET_ELIBSCN,
238 [ELIBMAX] = TARGET_ELIBMAX,
239 [ELIBEXEC] = TARGET_ELIBEXEC,
240 [EILSEQ] = TARGET_EILSEQ,
241 [ENOSYS] = TARGET_ENOSYS,
242 [ELOOP] = TARGET_ELOOP,
243 [ERESTART] = TARGET_ERESTART,
244 [ESTRPIPE] = TARGET_ESTRPIPE,
245 [ENOTEMPTY] = TARGET_ENOTEMPTY,
246 [EUSERS] = TARGET_EUSERS,
247 [ENOTSOCK] = TARGET_ENOTSOCK,
248 [EDESTADDRREQ] = TARGET_EDESTADDRREQ,
249 [EMSGSIZE] = TARGET_EMSGSIZE,
250 [EPROTOTYPE] = TARGET_EPROTOTYPE,
251 [ENOPROTOOPT] = TARGET_ENOPROTOOPT,
252 [EPROTONOSUPPORT] = TARGET_EPROTONOSUPPORT,
253 [ESOCKTNOSUPPORT] = TARGET_ESOCKTNOSUPPORT,
254 [EOPNOTSUPP] = TARGET_EOPNOTSUPP,
255 [EPFNOSUPPORT] = TARGET_EPFNOSUPPORT,
256 [EAFNOSUPPORT] = TARGET_EAFNOSUPPORT,
257 [EADDRINUSE] = TARGET_EADDRINUSE,
258 [EADDRNOTAVAIL] = TARGET_EADDRNOTAVAIL,
259 [ENETDOWN] = TARGET_ENETDOWN,
260 [ENETUNREACH] = TARGET_ENETUNREACH,
261 [ENETRESET] = TARGET_ENETRESET,
262 [ECONNABORTED] = TARGET_ECONNABORTED,
263 [ECONNRESET] = TARGET_ECONNRESET,
264 [ENOBUFS] = TARGET_ENOBUFS,
265 [EISCONN] = TARGET_EISCONN,
266 [ENOTCONN] = TARGET_ENOTCONN,
267 [EUCLEAN] = TARGET_EUCLEAN,
268 [ENOTNAM] = TARGET_ENOTNAM,
269 [ENAVAIL] = TARGET_ENAVAIL,
270 [EISNAM] = TARGET_EISNAM,
271 [EREMOTEIO] = TARGET_EREMOTEIO,
272 [ESHUTDOWN] = TARGET_ESHUTDOWN,
273 [ETOOMANYREFS] = TARGET_ETOOMANYREFS,
274 [ETIMEDOUT] = TARGET_ETIMEDOUT,
275 [ECONNREFUSED] = TARGET_ECONNREFUSED,
276 [EHOSTDOWN] = TARGET_EHOSTDOWN,
277 [EHOSTUNREACH] = TARGET_EHOSTUNREACH,
278 [EALREADY] = TARGET_EALREADY,
279 [EINPROGRESS] = TARGET_EINPROGRESS,
280 [ESTALE] = TARGET_ESTALE,
281 [ECANCELED] = TARGET_ECANCELED,
282 [ENOMEDIUM] = TARGET_ENOMEDIUM,
283 [EMEDIUMTYPE] = TARGET_EMEDIUMTYPE,
285 [ENOKEY] = TARGET_ENOKEY,
288 [EKEYEXPIRED] = TARGET_EKEYEXPIRED,
291 [EKEYREVOKED] = TARGET_EKEYREVOKED,
294 [EKEYREJECTED] = TARGET_EKEYREJECTED,
297 [EOWNERDEAD] = TARGET_EOWNERDEAD,
299 #ifdef ENOTRECOVERABLE
300 [ENOTRECOVERABLE] = TARGET_ENOTRECOVERABLE,
304 static inline int host_to_target_errno(int err)
306 if(host_to_target_errno_table[err])
307 return host_to_target_errno_table[err];
311 static inline long get_errno(long ret)
314 return -host_to_target_errno(errno);
319 static inline int is_error(long ret)
321 return (unsigned long)ret >= (unsigned long)(-4096);
324 static target_ulong target_brk;
325 static target_ulong target_original_brk;
327 void target_set_brk(target_ulong new_brk)
329 target_original_brk = target_brk = HOST_PAGE_ALIGN(new_brk);
332 long do_brk(target_ulong new_brk)
334 target_ulong brk_page;
340 if (new_brk < target_original_brk)
343 brk_page = HOST_PAGE_ALIGN(target_brk);
345 /* If the new brk is less than this, set it and we're done... */
346 if (new_brk < brk_page) {
347 target_brk = new_brk;
351 /* We need to allocate more memory after the brk... */
352 new_alloc_size = HOST_PAGE_ALIGN(new_brk - brk_page + 1);
353 mapped_addr = get_errno(target_mmap(brk_page, new_alloc_size,
354 PROT_READ|PROT_WRITE,
355 MAP_ANON|MAP_FIXED|MAP_PRIVATE, 0, 0));
356 if (is_error(mapped_addr)) {
359 target_brk = new_brk;
364 static inline fd_set *target_to_host_fds(fd_set *fds,
365 target_long *target_fds, int n)
367 #if !defined(BSWAP_NEEDED) && !defined(WORDS_BIGENDIAN)
368 return (fd_set *)target_fds;
373 for(i = 0;i < n; i++) {
374 b = (tswapl(target_fds[i / TARGET_LONG_BITS]) >>
375 (i & (TARGET_LONG_BITS - 1))) & 1;
386 static inline void host_to_target_fds(target_long *target_fds,
389 #if !defined(BSWAP_NEEDED) && !defined(WORDS_BIGENDIAN)
396 nw = (n + TARGET_LONG_BITS - 1) / TARGET_LONG_BITS;
398 for(i = 0;i < nw; i++) {
400 for(j = 0; j < TARGET_LONG_BITS; j++) {
401 v |= ((FD_ISSET(k, fds) != 0) << j);
404 target_fds[i] = tswapl(v);
410 #if defined(__alpha__)
416 static inline long host_to_target_clock_t(long ticks)
418 #if HOST_HZ == TARGET_HZ
421 return ((int64_t)ticks * TARGET_HZ) / HOST_HZ;
425 static inline void host_to_target_rusage(target_ulong target_addr,
426 const struct rusage *rusage)
428 struct target_rusage *target_rusage;
430 lock_user_struct(target_rusage, target_addr, 0);
431 target_rusage->ru_utime.tv_sec = tswapl(rusage->ru_utime.tv_sec);
432 target_rusage->ru_utime.tv_usec = tswapl(rusage->ru_utime.tv_usec);
433 target_rusage->ru_stime.tv_sec = tswapl(rusage->ru_stime.tv_sec);
434 target_rusage->ru_stime.tv_usec = tswapl(rusage->ru_stime.tv_usec);
435 target_rusage->ru_maxrss = tswapl(rusage->ru_maxrss);
436 target_rusage->ru_ixrss = tswapl(rusage->ru_ixrss);
437 target_rusage->ru_idrss = tswapl(rusage->ru_idrss);
438 target_rusage->ru_isrss = tswapl(rusage->ru_isrss);
439 target_rusage->ru_minflt = tswapl(rusage->ru_minflt);
440 target_rusage->ru_majflt = tswapl(rusage->ru_majflt);
441 target_rusage->ru_nswap = tswapl(rusage->ru_nswap);
442 target_rusage->ru_inblock = tswapl(rusage->ru_inblock);
443 target_rusage->ru_oublock = tswapl(rusage->ru_oublock);
444 target_rusage->ru_msgsnd = tswapl(rusage->ru_msgsnd);
445 target_rusage->ru_msgrcv = tswapl(rusage->ru_msgrcv);
446 target_rusage->ru_nsignals = tswapl(rusage->ru_nsignals);
447 target_rusage->ru_nvcsw = tswapl(rusage->ru_nvcsw);
448 target_rusage->ru_nivcsw = tswapl(rusage->ru_nivcsw);
449 unlock_user_struct(target_rusage, target_addr, 1);
452 static inline void target_to_host_timeval(struct timeval *tv,
453 target_ulong target_addr)
455 struct target_timeval *target_tv;
457 lock_user_struct(target_tv, target_addr, 1);
458 tv->tv_sec = tswapl(target_tv->tv_sec);
459 tv->tv_usec = tswapl(target_tv->tv_usec);
460 unlock_user_struct(target_tv, target_addr, 0);
463 static inline void host_to_target_timeval(target_ulong target_addr,
464 const struct timeval *tv)
466 struct target_timeval *target_tv;
468 lock_user_struct(target_tv, target_addr, 0);
469 target_tv->tv_sec = tswapl(tv->tv_sec);
470 target_tv->tv_usec = tswapl(tv->tv_usec);
471 unlock_user_struct(target_tv, target_addr, 1);
475 static long do_select(long n,
476 target_ulong rfd_p, target_ulong wfd_p,
477 target_ulong efd_p, target_ulong target_tv)
479 fd_set rfds, wfds, efds;
480 fd_set *rfds_ptr, *wfds_ptr, *efds_ptr;
481 target_long *target_rfds, *target_wfds, *target_efds;
482 struct timeval tv, *tv_ptr;
487 target_rfds = lock_user(rfd_p, sizeof(target_long) * n, 1);
488 rfds_ptr = target_to_host_fds(&rfds, target_rfds, n);
494 target_wfds = lock_user(wfd_p, sizeof(target_long) * n, 1);
495 wfds_ptr = target_to_host_fds(&wfds, target_wfds, n);
501 target_efds = lock_user(efd_p, sizeof(target_long) * n, 1);
502 efds_ptr = target_to_host_fds(&efds, target_efds, n);
509 target_to_host_timeval(&tv, target_tv);
514 ret = get_errno(select(n, rfds_ptr, wfds_ptr, efds_ptr, tv_ptr));
518 host_to_target_fds(target_rfds, rfds_ptr, n);
519 host_to_target_fds(target_wfds, wfds_ptr, n);
520 host_to_target_fds(target_efds, efds_ptr, n);
523 host_to_target_timeval(target_tv, &tv);
527 unlock_user(target_rfds, rfd_p, ok ? sizeof(target_long) * n : 0);
529 unlock_user(target_wfds, wfd_p, ok ? sizeof(target_long) * n : 0);
531 unlock_user(target_efds, efd_p, ok ? sizeof(target_long) * n : 0);
536 static inline void target_to_host_sockaddr(struct sockaddr *addr,
537 target_ulong target_addr,
540 struct target_sockaddr *target_saddr;
542 target_saddr = lock_user(target_addr, len, 1);
543 memcpy(addr, target_saddr, len);
544 addr->sa_family = tswap16(target_saddr->sa_family);
545 unlock_user(target_saddr, target_addr, 0);
548 static inline void host_to_target_sockaddr(target_ulong target_addr,
549 struct sockaddr *addr,
552 struct target_sockaddr *target_saddr;
554 target_saddr = lock_user(target_addr, len, 0);
555 memcpy(target_saddr, addr, len);
556 target_saddr->sa_family = tswap16(addr->sa_family);
557 unlock_user(target_saddr, target_addr, len);
560 /* ??? Should this also swap msgh->name? */
561 static inline void target_to_host_cmsg(struct msghdr *msgh,
562 struct target_msghdr *target_msgh)
564 struct cmsghdr *cmsg = CMSG_FIRSTHDR(msgh);
565 struct target_cmsghdr *target_cmsg = TARGET_CMSG_FIRSTHDR(target_msgh);
568 while (cmsg && target_cmsg) {
569 void *data = CMSG_DATA(cmsg);
570 void *target_data = TARGET_CMSG_DATA(target_cmsg);
572 int len = tswapl(target_cmsg->cmsg_len)
573 - TARGET_CMSG_ALIGN(sizeof (struct target_cmsghdr));
575 space += CMSG_SPACE(len);
576 if (space > msgh->msg_controllen) {
577 space -= CMSG_SPACE(len);
578 gemu_log("Host cmsg overflow\n");
582 cmsg->cmsg_level = tswap32(target_cmsg->cmsg_level);
583 cmsg->cmsg_type = tswap32(target_cmsg->cmsg_type);
584 cmsg->cmsg_len = CMSG_LEN(len);
586 if (cmsg->cmsg_level != TARGET_SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS) {
587 gemu_log("Unsupported ancillary data: %d/%d\n", cmsg->cmsg_level, cmsg->cmsg_type);
588 memcpy(data, target_data, len);
590 int *fd = (int *)data;
591 int *target_fd = (int *)target_data;
592 int i, numfds = len / sizeof(int);
594 for (i = 0; i < numfds; i++)
595 fd[i] = tswap32(target_fd[i]);
598 cmsg = CMSG_NXTHDR(msgh, cmsg);
599 target_cmsg = TARGET_CMSG_NXTHDR(target_msgh, target_cmsg);
602 msgh->msg_controllen = space;
605 /* ??? Should this also swap msgh->name? */
606 static inline void host_to_target_cmsg(struct target_msghdr *target_msgh,
609 struct cmsghdr *cmsg = CMSG_FIRSTHDR(msgh);
610 struct target_cmsghdr *target_cmsg = TARGET_CMSG_FIRSTHDR(target_msgh);
613 while (cmsg && target_cmsg) {
614 void *data = CMSG_DATA(cmsg);
615 void *target_data = TARGET_CMSG_DATA(target_cmsg);
617 int len = cmsg->cmsg_len - CMSG_ALIGN(sizeof (struct cmsghdr));
619 space += TARGET_CMSG_SPACE(len);
620 if (space > tswapl(target_msgh->msg_controllen)) {
621 space -= TARGET_CMSG_SPACE(len);
622 gemu_log("Target cmsg overflow\n");
626 target_cmsg->cmsg_level = tswap32(cmsg->cmsg_level);
627 target_cmsg->cmsg_type = tswap32(cmsg->cmsg_type);
628 target_cmsg->cmsg_len = tswapl(TARGET_CMSG_LEN(len));
630 if (cmsg->cmsg_level != TARGET_SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS) {
631 gemu_log("Unsupported ancillary data: %d/%d\n", cmsg->cmsg_level, cmsg->cmsg_type);
632 memcpy(target_data, data, len);
634 int *fd = (int *)data;
635 int *target_fd = (int *)target_data;
636 int i, numfds = len / sizeof(int);
638 for (i = 0; i < numfds; i++)
639 target_fd[i] = tswap32(fd[i]);
642 cmsg = CMSG_NXTHDR(msgh, cmsg);
643 target_cmsg = TARGET_CMSG_NXTHDR(target_msgh, target_cmsg);
646 msgh->msg_controllen = tswapl(space);
649 static long do_setsockopt(int sockfd, int level, int optname,
650 target_ulong optval, socklen_t optlen)
656 /* TCP options all take an 'int' value. */
657 if (optlen < sizeof(uint32_t))
660 val = tget32(optval);
661 ret = get_errno(setsockopt(sockfd, level, optname, &val, sizeof(val)));
668 case IP_ROUTER_ALERT:
672 case IP_MTU_DISCOVER:
678 case IP_MULTICAST_TTL:
679 case IP_MULTICAST_LOOP:
681 if (optlen >= sizeof(uint32_t)) {
682 val = tget32(optval);
683 } else if (optlen >= 1) {
686 ret = get_errno(setsockopt(sockfd, level, optname, &val, sizeof(val)));
692 case TARGET_SOL_SOCKET:
694 /* Options with 'int' argument. */
695 case TARGET_SO_DEBUG:
698 case TARGET_SO_REUSEADDR:
699 optname = SO_REUSEADDR;
704 case TARGET_SO_ERROR:
707 case TARGET_SO_DONTROUTE:
708 optname = SO_DONTROUTE;
710 case TARGET_SO_BROADCAST:
711 optname = SO_BROADCAST;
713 case TARGET_SO_SNDBUF:
716 case TARGET_SO_RCVBUF:
719 case TARGET_SO_KEEPALIVE:
720 optname = SO_KEEPALIVE;
722 case TARGET_SO_OOBINLINE:
723 optname = SO_OOBINLINE;
725 case TARGET_SO_NO_CHECK:
726 optname = SO_NO_CHECK;
728 case TARGET_SO_PRIORITY:
729 optname = SO_PRIORITY;
732 case TARGET_SO_BSDCOMPAT:
733 optname = SO_BSDCOMPAT;
736 case TARGET_SO_PASSCRED:
737 optname = SO_PASSCRED;
739 case TARGET_SO_TIMESTAMP:
740 optname = SO_TIMESTAMP;
742 case TARGET_SO_RCVLOWAT:
743 optname = SO_RCVLOWAT;
745 case TARGET_SO_RCVTIMEO:
746 optname = SO_RCVTIMEO;
748 case TARGET_SO_SNDTIMEO:
749 optname = SO_SNDTIMEO;
755 if (optlen < sizeof(uint32_t))
758 val = tget32(optval);
759 ret = get_errno(setsockopt(sockfd, SOL_SOCKET, optname, &val, sizeof(val)));
763 gemu_log("Unsupported setsockopt level=%d optname=%d \n", level, optname);
769 static long do_getsockopt(int sockfd, int level, int optname,
770 target_ulong optval, target_ulong optlen)
772 int len, lv, val, ret;
775 case TARGET_SOL_SOCKET:
778 case TARGET_SO_LINGER:
779 case TARGET_SO_RCVTIMEO:
780 case TARGET_SO_SNDTIMEO:
781 case TARGET_SO_PEERCRED:
782 case TARGET_SO_PEERNAME:
783 /* These don't just return a single integer */
790 /* TCP options all take an 'int' value. */
792 len = tget32(optlen);
796 ret = get_errno(getsockopt(sockfd, level, optname, &val, &lv));
813 case IP_ROUTER_ALERT:
817 case IP_MTU_DISCOVER:
823 case IP_MULTICAST_TTL:
824 case IP_MULTICAST_LOOP:
825 len = tget32(optlen);
829 ret = get_errno(getsockopt(sockfd, level, optname, &val, &lv));
832 if (len < sizeof(int) && len > 0 && val >= 0 && val < 255) {
837 if (len > sizeof(int))
849 gemu_log("getsockopt level=%d optname=%d not yet supported\n",
857 static void lock_iovec(struct iovec *vec, target_ulong target_addr,
860 struct target_iovec *target_vec;
864 target_vec = lock_user(target_addr, count * sizeof(struct target_iovec), 1);
865 for(i = 0;i < count; i++) {
866 base = tswapl(target_vec[i].iov_base);
867 vec[i].iov_len = tswapl(target_vec[i].iov_len);
868 vec[i].iov_base = lock_user(base, vec[i].iov_len, copy);
870 unlock_user (target_vec, target_addr, 0);
873 static void unlock_iovec(struct iovec *vec, target_ulong target_addr,
876 struct target_iovec *target_vec;
880 target_vec = lock_user(target_addr, count * sizeof(struct target_iovec), 1);
881 for(i = 0;i < count; i++) {
882 base = tswapl(target_vec[i].iov_base);
883 unlock_user(vec[i].iov_base, base, copy ? vec[i].iov_len : 0);
885 unlock_user (target_vec, target_addr, 0);
888 static long do_socket(int domain, int type, int protocol)
890 #if defined(TARGET_MIPS)
892 case TARGET_SOCK_DGRAM:
895 case TARGET_SOCK_STREAM:
898 case TARGET_SOCK_RAW:
901 case TARGET_SOCK_RDM:
904 case TARGET_SOCK_SEQPACKET:
905 type = SOCK_SEQPACKET;
907 case TARGET_SOCK_PACKET:
912 return get_errno(socket(domain, type, protocol));
915 static long do_bind(int sockfd, target_ulong target_addr,
918 void *addr = alloca(addrlen);
920 target_to_host_sockaddr(addr, target_addr, addrlen);
921 return get_errno(bind(sockfd, addr, addrlen));
924 static long do_connect(int sockfd, target_ulong target_addr,
927 void *addr = alloca(addrlen);
929 target_to_host_sockaddr(addr, target_addr, addrlen);
930 return get_errno(connect(sockfd, addr, addrlen));
933 static long do_sendrecvmsg(int fd, target_ulong target_msg,
937 struct target_msghdr *msgp;
941 target_ulong target_vec;
943 lock_user_struct(msgp, target_msg, 1);
944 if (msgp->msg_name) {
945 msg.msg_namelen = tswap32(msgp->msg_namelen);
946 msg.msg_name = alloca(msg.msg_namelen);
947 target_to_host_sockaddr(msg.msg_name, tswapl(msgp->msg_name),
953 msg.msg_controllen = 2 * tswapl(msgp->msg_controllen);
954 msg.msg_control = alloca(msg.msg_controllen);
955 msg.msg_flags = tswap32(msgp->msg_flags);
957 count = tswapl(msgp->msg_iovlen);
958 vec = alloca(count * sizeof(struct iovec));
959 target_vec = tswapl(msgp->msg_iov);
960 lock_iovec(vec, target_vec, count, send);
961 msg.msg_iovlen = count;
965 target_to_host_cmsg(&msg, msgp);
966 ret = get_errno(sendmsg(fd, &msg, flags));
968 ret = get_errno(recvmsg(fd, &msg, flags));
970 host_to_target_cmsg(msgp, &msg);
972 unlock_iovec(vec, target_vec, count, !send);
976 static long do_accept(int fd, target_ulong target_addr,
977 target_ulong target_addrlen)
979 socklen_t addrlen = tget32(target_addrlen);
980 void *addr = alloca(addrlen);
983 ret = get_errno(accept(fd, addr, &addrlen));
984 if (!is_error(ret)) {
985 host_to_target_sockaddr(target_addr, addr, addrlen);
986 tput32(target_addrlen, addrlen);
991 static long do_getpeername(int fd, target_ulong target_addr,
992 target_ulong target_addrlen)
994 socklen_t addrlen = tget32(target_addrlen);
995 void *addr = alloca(addrlen);
998 ret = get_errno(getpeername(fd, addr, &addrlen));
999 if (!is_error(ret)) {
1000 host_to_target_sockaddr(target_addr, addr, addrlen);
1001 tput32(target_addrlen, addrlen);
1006 static long do_getsockname(int fd, target_ulong target_addr,
1007 target_ulong target_addrlen)
1009 socklen_t addrlen = tget32(target_addrlen);
1010 void *addr = alloca(addrlen);
1013 ret = get_errno(getsockname(fd, addr, &addrlen));
1014 if (!is_error(ret)) {
1015 host_to_target_sockaddr(target_addr, addr, addrlen);
1016 tput32(target_addrlen, addrlen);
1021 static long do_socketpair(int domain, int type, int protocol,
1022 target_ulong target_tab)
1027 ret = get_errno(socketpair(domain, type, protocol, tab));
1028 if (!is_error(ret)) {
1029 tput32(target_tab, tab[0]);
1030 tput32(target_tab + 4, tab[1]);
1035 static long do_sendto(int fd, target_ulong msg, size_t len, int flags,
1036 target_ulong target_addr, socklen_t addrlen)
1042 host_msg = lock_user(msg, len, 1);
1044 addr = alloca(addrlen);
1045 target_to_host_sockaddr(addr, target_addr, addrlen);
1046 ret = get_errno(sendto(fd, host_msg, len, flags, addr, addrlen));
1048 ret = get_errno(send(fd, host_msg, len, flags));
1050 unlock_user(host_msg, msg, 0);
1054 static long do_recvfrom(int fd, target_ulong msg, size_t len, int flags,
1055 target_ulong target_addr, target_ulong target_addrlen)
1062 host_msg = lock_user(msg, len, 0);
1064 addrlen = tget32(target_addrlen);
1065 addr = alloca(addrlen);
1066 ret = get_errno(recvfrom(fd, host_msg, len, flags, addr, &addrlen));
1068 addr = NULL; /* To keep compiler quiet. */
1069 ret = get_errno(recv(fd, host_msg, len, flags));
1071 if (!is_error(ret)) {
1073 host_to_target_sockaddr(target_addr, addr, addrlen);
1074 tput32(target_addrlen, addrlen);
1076 unlock_user(host_msg, msg, len);
1078 unlock_user(host_msg, msg, 0);
1083 static long do_socketcall(int num, target_ulong vptr)
1086 const int n = sizeof(target_ulong);
1091 int domain = tgetl(vptr);
1092 int type = tgetl(vptr + n);
1093 int protocol = tgetl(vptr + 2 * n);
1094 ret = do_socket(domain, type, protocol);
1099 int sockfd = tgetl(vptr);
1100 target_ulong target_addr = tgetl(vptr + n);
1101 socklen_t addrlen = tgetl(vptr + 2 * n);
1102 ret = do_bind(sockfd, target_addr, addrlen);
1105 case SOCKOP_connect:
1107 int sockfd = tgetl(vptr);
1108 target_ulong target_addr = tgetl(vptr + n);
1109 socklen_t addrlen = tgetl(vptr + 2 * n);
1110 ret = do_connect(sockfd, target_addr, addrlen);
1115 int sockfd = tgetl(vptr);
1116 int backlog = tgetl(vptr + n);
1117 ret = get_errno(listen(sockfd, backlog));
1122 int sockfd = tgetl(vptr);
1123 target_ulong target_addr = tgetl(vptr + n);
1124 target_ulong target_addrlen = tgetl(vptr + 2 * n);
1125 ret = do_accept(sockfd, target_addr, target_addrlen);
1128 case SOCKOP_getsockname:
1130 int sockfd = tgetl(vptr);
1131 target_ulong target_addr = tgetl(vptr + n);
1132 target_ulong target_addrlen = tgetl(vptr + 2 * n);
1133 ret = do_getsockname(sockfd, target_addr, target_addrlen);
1136 case SOCKOP_getpeername:
1138 int sockfd = tgetl(vptr);
1139 target_ulong target_addr = tgetl(vptr + n);
1140 target_ulong target_addrlen = tgetl(vptr + 2 * n);
1141 ret = do_getpeername(sockfd, target_addr, target_addrlen);
1144 case SOCKOP_socketpair:
1146 int domain = tgetl(vptr);
1147 int type = tgetl(vptr + n);
1148 int protocol = tgetl(vptr + 2 * n);
1149 target_ulong tab = tgetl(vptr + 3 * n);
1150 ret = do_socketpair(domain, type, protocol, tab);
1155 int sockfd = tgetl(vptr);
1156 target_ulong msg = tgetl(vptr + n);
1157 size_t len = tgetl(vptr + 2 * n);
1158 int flags = tgetl(vptr + 3 * n);
1159 ret = do_sendto(sockfd, msg, len, flags, 0, 0);
1164 int sockfd = tgetl(vptr);
1165 target_ulong msg = tgetl(vptr + n);
1166 size_t len = tgetl(vptr + 2 * n);
1167 int flags = tgetl(vptr + 3 * n);
1168 ret = do_recvfrom(sockfd, msg, len, flags, 0, 0);
1173 int sockfd = tgetl(vptr);
1174 target_ulong msg = tgetl(vptr + n);
1175 size_t len = tgetl(vptr + 2 * n);
1176 int flags = tgetl(vptr + 3 * n);
1177 target_ulong addr = tgetl(vptr + 4 * n);
1178 socklen_t addrlen = tgetl(vptr + 5 * n);
1179 ret = do_sendto(sockfd, msg, len, flags, addr, addrlen);
1182 case SOCKOP_recvfrom:
1184 int sockfd = tgetl(vptr);
1185 target_ulong msg = tgetl(vptr + n);
1186 size_t len = tgetl(vptr + 2 * n);
1187 int flags = tgetl(vptr + 3 * n);
1188 target_ulong addr = tgetl(vptr + 4 * n);
1189 target_ulong addrlen = tgetl(vptr + 5 * n);
1190 ret = do_recvfrom(sockfd, msg, len, flags, addr, addrlen);
1193 case SOCKOP_shutdown:
1195 int sockfd = tgetl(vptr);
1196 int how = tgetl(vptr + n);
1198 ret = get_errno(shutdown(sockfd, how));
1201 case SOCKOP_sendmsg:
1202 case SOCKOP_recvmsg:
1205 target_ulong target_msg;
1209 target_msg = tgetl(vptr + n);
1210 flags = tgetl(vptr + 2 * n);
1212 ret = do_sendrecvmsg(fd, target_msg, flags,
1213 (num == SOCKOP_sendmsg));
1216 case SOCKOP_setsockopt:
1218 int sockfd = tgetl(vptr);
1219 int level = tgetl(vptr + n);
1220 int optname = tgetl(vptr + 2 * n);
1221 target_ulong optval = tgetl(vptr + 3 * n);
1222 socklen_t optlen = tgetl(vptr + 4 * n);
1224 ret = do_setsockopt(sockfd, level, optname, optval, optlen);
1227 case SOCKOP_getsockopt:
1229 int sockfd = tgetl(vptr);
1230 int level = tgetl(vptr + n);
1231 int optname = tgetl(vptr + 2 * n);
1232 target_ulong optval = tgetl(vptr + 3 * n);
1233 target_ulong poptlen = tgetl(vptr + 4 * n);
1235 ret = do_getsockopt(sockfd, level, optname, optval, poptlen);
1239 gemu_log("Unsupported socketcall: %d\n", num);
1246 #define N_SHM_REGIONS 32
1248 static struct shm_region {
1251 } shm_regions[N_SHM_REGIONS];
1253 struct target_ipc_perm
1260 unsigned short int mode;
1261 unsigned short int __pad1;
1262 unsigned short int __seq;
1263 unsigned short int __pad2;
1264 target_ulong __unused1;
1265 target_ulong __unused2;
1268 struct target_semid_ds
1270 struct target_ipc_perm sem_perm;
1271 target_ulong sem_otime;
1272 target_ulong __unused1;
1273 target_ulong sem_ctime;
1274 target_ulong __unused2;
1275 target_ulong sem_nsems;
1276 target_ulong __unused3;
1277 target_ulong __unused4;
1280 static inline void target_to_host_ipc_perm(struct ipc_perm *host_ip,
1281 target_ulong target_addr)
1283 struct target_ipc_perm *target_ip;
1284 struct target_semid_ds *target_sd;
1286 lock_user_struct(target_sd, target_addr, 1);
1287 target_ip=&(target_sd->sem_perm);
1288 host_ip->__key = tswapl(target_ip->__key);
1289 host_ip->uid = tswapl(target_ip->uid);
1290 host_ip->gid = tswapl(target_ip->gid);
1291 host_ip->cuid = tswapl(target_ip->cuid);
1292 host_ip->cgid = tswapl(target_ip->cgid);
1293 host_ip->mode = tswapl(target_ip->mode);
1294 unlock_user_struct(target_sd, target_addr, 0);
1297 static inline void host_to_target_ipc_perm(target_ulong target_addr,
1298 struct ipc_perm *host_ip)
1300 struct target_ipc_perm *target_ip;
1301 struct target_semid_ds *target_sd;
1303 lock_user_struct(target_sd, target_addr, 0);
1304 target_ip = &(target_sd->sem_perm);
1305 target_ip->__key = tswapl(host_ip->__key);
1306 target_ip->uid = tswapl(host_ip->uid);
1307 target_ip->gid = tswapl(host_ip->gid);
1308 target_ip->cuid = tswapl(host_ip->cuid);
1309 target_ip->cgid = tswapl(host_ip->cgid);
1310 target_ip->mode = tswapl(host_ip->mode);
1311 unlock_user_struct(target_sd, target_addr, 1);
1314 static inline void target_to_host_semid_ds(struct semid_ds *host_sd,
1315 target_ulong target_addr)
1317 struct target_semid_ds *target_sd;
1319 lock_user_struct(target_sd, target_addr, 1);
1320 target_to_host_ipc_perm(&(host_sd->sem_perm),target_addr);
1321 host_sd->sem_nsems = tswapl(target_sd->sem_nsems);
1322 host_sd->sem_otime = tswapl(target_sd->sem_otime);
1323 host_sd->sem_ctime = tswapl(target_sd->sem_ctime);
1324 unlock_user_struct(target_sd, target_addr, 0);
1327 static inline void host_to_target_semid_ds(target_ulong target_addr,
1328 struct semid_ds *host_sd)
1330 struct target_semid_ds *target_sd;
1332 lock_user_struct(target_sd, target_addr, 0);
1333 host_to_target_ipc_perm(target_addr,&(host_sd->sem_perm));
1334 target_sd->sem_nsems = tswapl(host_sd->sem_nsems);
1335 target_sd->sem_otime = tswapl(host_sd->sem_otime);
1336 target_sd->sem_ctime = tswapl(host_sd->sem_ctime);
1337 unlock_user_struct(target_sd, target_addr, 1);
1342 struct semid_ds *buf;
1343 unsigned short *array;
1346 union target_semun {
1349 unsigned short int *array;
1352 static inline void target_to_host_semun(unsigned long cmd,
1353 union semun *host_su,
1354 target_ulong target_addr,
1355 struct semid_ds *ds)
1357 union target_semun *target_su;
1362 lock_user_struct(target_su, target_addr, 1);
1363 target_to_host_semid_ds(ds,target_su->buf);
1365 unlock_user_struct(target_su, target_addr, 0);
1369 lock_user_struct(target_su, target_addr, 1);
1370 host_su->val = tswapl(target_su->val);
1371 unlock_user_struct(target_su, target_addr, 0);
1375 lock_user_struct(target_su, target_addr, 1);
1376 *host_su->array = tswap16(*target_su->array);
1377 unlock_user_struct(target_su, target_addr, 0);
1380 gemu_log("semun operation not fully supported: %d\n", (int)cmd);
1384 static inline void host_to_target_semun(unsigned long cmd,
1385 target_ulong target_addr,
1386 union semun *host_su,
1387 struct semid_ds *ds)
1389 union target_semun *target_su;
1394 lock_user_struct(target_su, target_addr, 0);
1395 host_to_target_semid_ds(target_su->buf,ds);
1396 unlock_user_struct(target_su, target_addr, 1);
1400 lock_user_struct(target_su, target_addr, 0);
1401 target_su->val = tswapl(host_su->val);
1402 unlock_user_struct(target_su, target_addr, 1);
1406 lock_user_struct(target_su, target_addr, 0);
1407 *target_su->array = tswap16(*host_su->array);
1408 unlock_user_struct(target_su, target_addr, 1);
1411 gemu_log("semun operation not fully supported: %d\n", (int)cmd);
1415 static inline long do_semctl(long first, long second, long third, long ptr)
1418 struct semid_ds dsarg;
1419 int cmd = third&0xff;
1424 target_to_host_semun(cmd,&arg,ptr,&dsarg);
1425 ret = get_errno(semctl(first, second, cmd, arg));
1426 host_to_target_semun(cmd,ptr,&arg,&dsarg);
1429 target_to_host_semun(cmd,&arg,ptr,&dsarg);
1430 ret = get_errno(semctl(first, second, cmd, arg));
1431 host_to_target_semun(cmd,ptr,&arg,&dsarg);
1434 target_to_host_semun(cmd,&arg,ptr,&dsarg);
1435 ret = get_errno(semctl(first, second, cmd, arg));
1436 host_to_target_semun(cmd,ptr,&arg,&dsarg);
1439 target_to_host_semun(cmd,&arg,ptr,&dsarg);
1440 ret = get_errno(semctl(first, second, cmd, arg));
1441 host_to_target_semun(cmd,ptr,&arg,&dsarg);
1444 target_to_host_semun(cmd,&arg,ptr,&dsarg);
1445 ret = get_errno(semctl(first, second, cmd, arg));
1446 host_to_target_semun(cmd,ptr,&arg,&dsarg);
1449 target_to_host_semun(cmd,&arg,ptr,&dsarg);
1450 ret = get_errno(semctl(first, second, cmd, arg));
1451 host_to_target_semun(cmd,ptr,&arg,&dsarg);
1454 ret = get_errno(semctl(first, second, cmd, arg));
1460 struct target_msqid_ds
1462 struct target_ipc_perm msg_perm;
1463 target_ulong msg_stime;
1464 target_ulong __unused1;
1465 target_ulong msg_rtime;
1466 target_ulong __unused2;
1467 target_ulong msg_ctime;
1468 target_ulong __unused3;
1469 target_ulong __msg_cbytes;
1470 target_ulong msg_qnum;
1471 target_ulong msg_qbytes;
1472 target_ulong msg_lspid;
1473 target_ulong msg_lrpid;
1474 target_ulong __unused4;
1475 target_ulong __unused5;
1478 static inline void target_to_host_msqid_ds(struct msqid_ds *host_md,
1479 target_ulong target_addr)
1481 struct target_msqid_ds *target_md;
1483 lock_user_struct(target_md, target_addr, 1);
1484 target_to_host_ipc_perm(&(host_md->msg_perm),target_addr);
1485 host_md->msg_stime = tswapl(target_md->msg_stime);
1486 host_md->msg_rtime = tswapl(target_md->msg_rtime);
1487 host_md->msg_ctime = tswapl(target_md->msg_ctime);
1488 host_md->__msg_cbytes = tswapl(target_md->__msg_cbytes);
1489 host_md->msg_qnum = tswapl(target_md->msg_qnum);
1490 host_md->msg_qbytes = tswapl(target_md->msg_qbytes);
1491 host_md->msg_lspid = tswapl(target_md->msg_lspid);
1492 host_md->msg_lrpid = tswapl(target_md->msg_lrpid);
1493 unlock_user_struct(target_md, target_addr, 0);
1496 static inline void host_to_target_msqid_ds(target_ulong target_addr,
1497 struct msqid_ds *host_md)
1499 struct target_msqid_ds *target_md;
1501 lock_user_struct(target_md, target_addr, 0);
1502 host_to_target_ipc_perm(target_addr,&(host_md->msg_perm));
1503 target_md->msg_stime = tswapl(host_md->msg_stime);
1504 target_md->msg_rtime = tswapl(host_md->msg_rtime);
1505 target_md->msg_ctime = tswapl(host_md->msg_ctime);
1506 target_md->__msg_cbytes = tswapl(host_md->__msg_cbytes);
1507 target_md->msg_qnum = tswapl(host_md->msg_qnum);
1508 target_md->msg_qbytes = tswapl(host_md->msg_qbytes);
1509 target_md->msg_lspid = tswapl(host_md->msg_lspid);
1510 target_md->msg_lrpid = tswapl(host_md->msg_lrpid);
1511 unlock_user_struct(target_md, target_addr, 1);
1514 static inline long do_msgctl(long first, long second, long ptr)
1516 struct msqid_ds dsarg;
1517 int cmd = second&0xff;
1522 target_to_host_msqid_ds(&dsarg,ptr);
1523 ret = get_errno(msgctl(first, cmd, &dsarg));
1524 host_to_target_msqid_ds(ptr,&dsarg);
1526 ret = get_errno(msgctl(first, cmd, &dsarg));
1531 struct target_msgbuf {
1536 static inline long do_msgsnd(long msqid, long msgp, long msgsz, long msgflg)
1538 struct target_msgbuf *target_mb;
1539 struct msgbuf *host_mb;
1542 lock_user_struct(target_mb,msgp,0);
1543 host_mb = malloc(msgsz+sizeof(long));
1544 host_mb->mtype = tswapl(target_mb->mtype);
1545 memcpy(host_mb->mtext,target_mb->mtext,msgsz);
1546 ret = get_errno(msgsnd(msqid, host_mb, msgsz, msgflg));
1548 unlock_user_struct(target_mb, msgp, 0);
1553 static inline long do_msgrcv(long msqid, long msgp, long msgsz, long msgtype, long msgflg)
1555 struct target_msgbuf *target_mb;
1556 struct msgbuf *host_mb;
1559 lock_user_struct(target_mb, msgp, 0);
1560 host_mb = malloc(msgsz+sizeof(long));
1561 ret = get_errno(msgrcv(msqid, host_mb, msgsz, 1, msgflg));
1563 memcpy(target_mb->mtext, host_mb->mtext, ret);
1564 target_mb->mtype = tswapl(host_mb->mtype);
1566 unlock_user_struct(target_mb, msgp, 0);
1571 /* ??? This only works with linear mappings. */
1572 static long do_ipc(long call, long first, long second, long third,
1573 long ptr, long fifth)
1577 unsigned long raddr;
1578 struct shmid_ds shm_info;
1581 version = call >> 16;
1586 ret = get_errno(semop(first,(struct sembuf *) ptr, second));
1590 ret = get_errno(semget(first, second, third));
1594 ret = do_semctl(first, second, third, ptr);
1597 case IPCOP_semtimedop:
1598 gemu_log("Unsupported ipc call: %ld (version %d)\n", call, version);
1603 ret = get_errno(msgget(first, second));
1607 ret = do_msgsnd(first, ptr, second, third);
1611 ret = do_msgctl(first, second, ptr);
1618 void *__unbounded msgp;
1622 struct ipc_kludge *foo = (struct ipc_kludge *) ptr;
1623 struct msgbuf *msgp = (struct msgbuf *) foo->msgp;
1625 ret = do_msgrcv(first, (long)msgp, second, 0, third);
1631 /* SHM_* flags are the same on all linux platforms */
1632 ret = get_errno((long) shmat(first, (void *) ptr, second));
1636 /* find out the length of the shared memory segment */
1638 ret = get_errno(shmctl(first, IPC_STAT, &shm_info));
1639 if (is_error(ret)) {
1640 /* can't get length, bail out */
1641 shmdt((void *) raddr);
1644 page_set_flags(raddr, raddr + shm_info.shm_segsz,
1645 PAGE_VALID | PAGE_READ |
1646 ((second & SHM_RDONLY)? 0: PAGE_WRITE));
1647 for (i = 0; i < N_SHM_REGIONS; ++i) {
1648 if (shm_regions[i].start == 0) {
1649 shm_regions[i].start = raddr;
1650 shm_regions[i].size = shm_info.shm_segsz;
1654 if (put_user(raddr, (uint32_t *)third))
1659 for (i = 0; i < N_SHM_REGIONS; ++i) {
1660 if (shm_regions[i].start == ptr) {
1661 shm_regions[i].start = 0;
1662 page_set_flags(ptr, shm_regions[i].size, 0);
1666 ret = get_errno(shmdt((void *) ptr));
1670 /* IPC_* flag values are the same on all linux platforms */
1671 ret = get_errno(shmget(first, second, third));
1674 /* IPC_* and SHM_* command values are the same on all linux platforms */
1680 ret = get_errno(shmctl(first, second, NULL));
1688 gemu_log("Unsupported ipc call: %ld (version %d)\n", call, version);
1695 /* kernel structure types definitions */
1698 #define STRUCT(name, list...) STRUCT_ ## name,
1699 #define STRUCT_SPECIAL(name) STRUCT_ ## name,
1701 #include "syscall_types.h"
1704 #undef STRUCT_SPECIAL
1706 #define STRUCT(name, list...) const argtype struct_ ## name ## _def[] = { list, TYPE_NULL };
1707 #define STRUCT_SPECIAL(name)
1708 #include "syscall_types.h"
1710 #undef STRUCT_SPECIAL
1712 typedef struct IOCTLEntry {
1713 unsigned int target_cmd;
1714 unsigned int host_cmd;
1717 const argtype arg_type[5];
1720 #define IOC_R 0x0001
1721 #define IOC_W 0x0002
1722 #define IOC_RW (IOC_R | IOC_W)
1724 #define MAX_STRUCT_SIZE 4096
1726 IOCTLEntry ioctl_entries[] = {
1727 #define IOCTL(cmd, access, types...) \
1728 { TARGET_ ## cmd, cmd, #cmd, access, { types } },
1733 /* ??? Implement proper locking for ioctls. */
1734 static long do_ioctl(long fd, long cmd, long arg)
1736 const IOCTLEntry *ie;
1737 const argtype *arg_type;
1739 uint8_t buf_temp[MAX_STRUCT_SIZE];
1745 if (ie->target_cmd == 0) {
1746 gemu_log("Unsupported ioctl: cmd=0x%04lx\n", cmd);
1749 if (ie->target_cmd == cmd)
1753 arg_type = ie->arg_type;
1755 gemu_log("ioctl: cmd=0x%04lx (%s)\n", cmd, ie->name);
1757 switch(arg_type[0]) {
1760 ret = get_errno(ioctl(fd, ie->host_cmd));
1765 ret = get_errno(ioctl(fd, ie->host_cmd, arg));
1769 target_size = thunk_type_size(arg_type, 0);
1770 switch(ie->access) {
1772 ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp));
1773 if (!is_error(ret)) {
1774 argptr = lock_user(arg, target_size, 0);
1775 thunk_convert(argptr, buf_temp, arg_type, THUNK_TARGET);
1776 unlock_user(argptr, arg, target_size);
1780 argptr = lock_user(arg, target_size, 1);
1781 thunk_convert(buf_temp, argptr, arg_type, THUNK_HOST);
1782 unlock_user(argptr, arg, 0);
1783 ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp));
1787 argptr = lock_user(arg, target_size, 1);
1788 thunk_convert(buf_temp, argptr, arg_type, THUNK_HOST);
1789 unlock_user(argptr, arg, 0);
1790 ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp));
1791 if (!is_error(ret)) {
1792 argptr = lock_user(arg, target_size, 0);
1793 thunk_convert(argptr, buf_temp, arg_type, THUNK_TARGET);
1794 unlock_user(argptr, arg, target_size);
1800 gemu_log("Unsupported ioctl type: cmd=0x%04lx type=%d\n", cmd, arg_type[0]);
1807 bitmask_transtbl iflag_tbl[] = {
1808 { TARGET_IGNBRK, TARGET_IGNBRK, IGNBRK, IGNBRK },
1809 { TARGET_BRKINT, TARGET_BRKINT, BRKINT, BRKINT },
1810 { TARGET_IGNPAR, TARGET_IGNPAR, IGNPAR, IGNPAR },
1811 { TARGET_PARMRK, TARGET_PARMRK, PARMRK, PARMRK },
1812 { TARGET_INPCK, TARGET_INPCK, INPCK, INPCK },
1813 { TARGET_ISTRIP, TARGET_ISTRIP, ISTRIP, ISTRIP },
1814 { TARGET_INLCR, TARGET_INLCR, INLCR, INLCR },
1815 { TARGET_IGNCR, TARGET_IGNCR, IGNCR, IGNCR },
1816 { TARGET_ICRNL, TARGET_ICRNL, ICRNL, ICRNL },
1817 { TARGET_IUCLC, TARGET_IUCLC, IUCLC, IUCLC },
1818 { TARGET_IXON, TARGET_IXON, IXON, IXON },
1819 { TARGET_IXANY, TARGET_IXANY, IXANY, IXANY },
1820 { TARGET_IXOFF, TARGET_IXOFF, IXOFF, IXOFF },
1821 { TARGET_IMAXBEL, TARGET_IMAXBEL, IMAXBEL, IMAXBEL },
1825 bitmask_transtbl oflag_tbl[] = {
1826 { TARGET_OPOST, TARGET_OPOST, OPOST, OPOST },
1827 { TARGET_OLCUC, TARGET_OLCUC, OLCUC, OLCUC },
1828 { TARGET_ONLCR, TARGET_ONLCR, ONLCR, ONLCR },
1829 { TARGET_OCRNL, TARGET_OCRNL, OCRNL, OCRNL },
1830 { TARGET_ONOCR, TARGET_ONOCR, ONOCR, ONOCR },
1831 { TARGET_ONLRET, TARGET_ONLRET, ONLRET, ONLRET },
1832 { TARGET_OFILL, TARGET_OFILL, OFILL, OFILL },
1833 { TARGET_OFDEL, TARGET_OFDEL, OFDEL, OFDEL },
1834 { TARGET_NLDLY, TARGET_NL0, NLDLY, NL0 },
1835 { TARGET_NLDLY, TARGET_NL1, NLDLY, NL1 },
1836 { TARGET_CRDLY, TARGET_CR0, CRDLY, CR0 },
1837 { TARGET_CRDLY, TARGET_CR1, CRDLY, CR1 },
1838 { TARGET_CRDLY, TARGET_CR2, CRDLY, CR2 },
1839 { TARGET_CRDLY, TARGET_CR3, CRDLY, CR3 },
1840 { TARGET_TABDLY, TARGET_TAB0, TABDLY, TAB0 },
1841 { TARGET_TABDLY, TARGET_TAB1, TABDLY, TAB1 },
1842 { TARGET_TABDLY, TARGET_TAB2, TABDLY, TAB2 },
1843 { TARGET_TABDLY, TARGET_TAB3, TABDLY, TAB3 },
1844 { TARGET_BSDLY, TARGET_BS0, BSDLY, BS0 },
1845 { TARGET_BSDLY, TARGET_BS1, BSDLY, BS1 },
1846 { TARGET_VTDLY, TARGET_VT0, VTDLY, VT0 },
1847 { TARGET_VTDLY, TARGET_VT1, VTDLY, VT1 },
1848 { TARGET_FFDLY, TARGET_FF0, FFDLY, FF0 },
1849 { TARGET_FFDLY, TARGET_FF1, FFDLY, FF1 },
1853 bitmask_transtbl cflag_tbl[] = {
1854 { TARGET_CBAUD, TARGET_B0, CBAUD, B0 },
1855 { TARGET_CBAUD, TARGET_B50, CBAUD, B50 },
1856 { TARGET_CBAUD, TARGET_B75, CBAUD, B75 },
1857 { TARGET_CBAUD, TARGET_B110, CBAUD, B110 },
1858 { TARGET_CBAUD, TARGET_B134, CBAUD, B134 },
1859 { TARGET_CBAUD, TARGET_B150, CBAUD, B150 },
1860 { TARGET_CBAUD, TARGET_B200, CBAUD, B200 },
1861 { TARGET_CBAUD, TARGET_B300, CBAUD, B300 },
1862 { TARGET_CBAUD, TARGET_B600, CBAUD, B600 },
1863 { TARGET_CBAUD, TARGET_B1200, CBAUD, B1200 },
1864 { TARGET_CBAUD, TARGET_B1800, CBAUD, B1800 },
1865 { TARGET_CBAUD, TARGET_B2400, CBAUD, B2400 },
1866 { TARGET_CBAUD, TARGET_B4800, CBAUD, B4800 },
1867 { TARGET_CBAUD, TARGET_B9600, CBAUD, B9600 },
1868 { TARGET_CBAUD, TARGET_B19200, CBAUD, B19200 },
1869 { TARGET_CBAUD, TARGET_B38400, CBAUD, B38400 },
1870 { TARGET_CBAUD, TARGET_B57600, CBAUD, B57600 },
1871 { TARGET_CBAUD, TARGET_B115200, CBAUD, B115200 },
1872 { TARGET_CBAUD, TARGET_B230400, CBAUD, B230400 },
1873 { TARGET_CBAUD, TARGET_B460800, CBAUD, B460800 },
1874 { TARGET_CSIZE, TARGET_CS5, CSIZE, CS5 },
1875 { TARGET_CSIZE, TARGET_CS6, CSIZE, CS6 },
1876 { TARGET_CSIZE, TARGET_CS7, CSIZE, CS7 },
1877 { TARGET_CSIZE, TARGET_CS8, CSIZE, CS8 },
1878 { TARGET_CSTOPB, TARGET_CSTOPB, CSTOPB, CSTOPB },
1879 { TARGET_CREAD, TARGET_CREAD, CREAD, CREAD },
1880 { TARGET_PARENB, TARGET_PARENB, PARENB, PARENB },
1881 { TARGET_PARODD, TARGET_PARODD, PARODD, PARODD },
1882 { TARGET_HUPCL, TARGET_HUPCL, HUPCL, HUPCL },
1883 { TARGET_CLOCAL, TARGET_CLOCAL, CLOCAL, CLOCAL },
1884 { TARGET_CRTSCTS, TARGET_CRTSCTS, CRTSCTS, CRTSCTS },
1888 bitmask_transtbl lflag_tbl[] = {
1889 { TARGET_ISIG, TARGET_ISIG, ISIG, ISIG },
1890 { TARGET_ICANON, TARGET_ICANON, ICANON, ICANON },
1891 { TARGET_XCASE, TARGET_XCASE, XCASE, XCASE },
1892 { TARGET_ECHO, TARGET_ECHO, ECHO, ECHO },
1893 { TARGET_ECHOE, TARGET_ECHOE, ECHOE, ECHOE },
1894 { TARGET_ECHOK, TARGET_ECHOK, ECHOK, ECHOK },
1895 { TARGET_ECHONL, TARGET_ECHONL, ECHONL, ECHONL },
1896 { TARGET_NOFLSH, TARGET_NOFLSH, NOFLSH, NOFLSH },
1897 { TARGET_TOSTOP, TARGET_TOSTOP, TOSTOP, TOSTOP },
1898 { TARGET_ECHOCTL, TARGET_ECHOCTL, ECHOCTL, ECHOCTL },
1899 { TARGET_ECHOPRT, TARGET_ECHOPRT, ECHOPRT, ECHOPRT },
1900 { TARGET_ECHOKE, TARGET_ECHOKE, ECHOKE, ECHOKE },
1901 { TARGET_FLUSHO, TARGET_FLUSHO, FLUSHO, FLUSHO },
1902 { TARGET_PENDIN, TARGET_PENDIN, PENDIN, PENDIN },
1903 { TARGET_IEXTEN, TARGET_IEXTEN, IEXTEN, IEXTEN },
1907 static void target_to_host_termios (void *dst, const void *src)
1909 struct host_termios *host = dst;
1910 const struct target_termios *target = src;
1913 target_to_host_bitmask(tswap32(target->c_iflag), iflag_tbl);
1915 target_to_host_bitmask(tswap32(target->c_oflag), oflag_tbl);
1917 target_to_host_bitmask(tswap32(target->c_cflag), cflag_tbl);
1919 target_to_host_bitmask(tswap32(target->c_lflag), lflag_tbl);
1920 host->c_line = target->c_line;
1922 host->c_cc[VINTR] = target->c_cc[TARGET_VINTR];
1923 host->c_cc[VQUIT] = target->c_cc[TARGET_VQUIT];
1924 host->c_cc[VERASE] = target->c_cc[TARGET_VERASE];
1925 host->c_cc[VKILL] = target->c_cc[TARGET_VKILL];
1926 host->c_cc[VEOF] = target->c_cc[TARGET_VEOF];
1927 host->c_cc[VTIME] = target->c_cc[TARGET_VTIME];
1928 host->c_cc[VMIN] = target->c_cc[TARGET_VMIN];
1929 host->c_cc[VSWTC] = target->c_cc[TARGET_VSWTC];
1930 host->c_cc[VSTART] = target->c_cc[TARGET_VSTART];
1931 host->c_cc[VSTOP] = target->c_cc[TARGET_VSTOP];
1932 host->c_cc[VSUSP] = target->c_cc[TARGET_VSUSP];
1933 host->c_cc[VEOL] = target->c_cc[TARGET_VEOL];
1934 host->c_cc[VREPRINT] = target->c_cc[TARGET_VREPRINT];
1935 host->c_cc[VDISCARD] = target->c_cc[TARGET_VDISCARD];
1936 host->c_cc[VWERASE] = target->c_cc[TARGET_VWERASE];
1937 host->c_cc[VLNEXT] = target->c_cc[TARGET_VLNEXT];
1938 host->c_cc[VEOL2] = target->c_cc[TARGET_VEOL2];
1941 static void host_to_target_termios (void *dst, const void *src)
1943 struct target_termios *target = dst;
1944 const struct host_termios *host = src;
1947 tswap32(host_to_target_bitmask(host->c_iflag, iflag_tbl));
1949 tswap32(host_to_target_bitmask(host->c_oflag, oflag_tbl));
1951 tswap32(host_to_target_bitmask(host->c_cflag, cflag_tbl));
1953 tswap32(host_to_target_bitmask(host->c_lflag, lflag_tbl));
1954 target->c_line = host->c_line;
1956 target->c_cc[TARGET_VINTR] = host->c_cc[VINTR];
1957 target->c_cc[TARGET_VQUIT] = host->c_cc[VQUIT];
1958 target->c_cc[TARGET_VERASE] = host->c_cc[VERASE];
1959 target->c_cc[TARGET_VKILL] = host->c_cc[VKILL];
1960 target->c_cc[TARGET_VEOF] = host->c_cc[VEOF];
1961 target->c_cc[TARGET_VTIME] = host->c_cc[VTIME];
1962 target->c_cc[TARGET_VMIN] = host->c_cc[VMIN];
1963 target->c_cc[TARGET_VSWTC] = host->c_cc[VSWTC];
1964 target->c_cc[TARGET_VSTART] = host->c_cc[VSTART];
1965 target->c_cc[TARGET_VSTOP] = host->c_cc[VSTOP];
1966 target->c_cc[TARGET_VSUSP] = host->c_cc[VSUSP];
1967 target->c_cc[TARGET_VEOL] = host->c_cc[VEOL];
1968 target->c_cc[TARGET_VREPRINT] = host->c_cc[VREPRINT];
1969 target->c_cc[TARGET_VDISCARD] = host->c_cc[VDISCARD];
1970 target->c_cc[TARGET_VWERASE] = host->c_cc[VWERASE];
1971 target->c_cc[TARGET_VLNEXT] = host->c_cc[VLNEXT];
1972 target->c_cc[TARGET_VEOL2] = host->c_cc[VEOL2];
1975 StructEntry struct_termios_def = {
1976 .convert = { host_to_target_termios, target_to_host_termios },
1977 .size = { sizeof(struct target_termios), sizeof(struct host_termios) },
1978 .align = { __alignof__(struct target_termios), __alignof__(struct host_termios) },
1981 static bitmask_transtbl mmap_flags_tbl[] = {
1982 { TARGET_MAP_SHARED, TARGET_MAP_SHARED, MAP_SHARED, MAP_SHARED },
1983 { TARGET_MAP_PRIVATE, TARGET_MAP_PRIVATE, MAP_PRIVATE, MAP_PRIVATE },
1984 { TARGET_MAP_FIXED, TARGET_MAP_FIXED, MAP_FIXED, MAP_FIXED },
1985 { TARGET_MAP_ANONYMOUS, TARGET_MAP_ANONYMOUS, MAP_ANONYMOUS, MAP_ANONYMOUS },
1986 { TARGET_MAP_GROWSDOWN, TARGET_MAP_GROWSDOWN, MAP_GROWSDOWN, MAP_GROWSDOWN },
1987 { TARGET_MAP_DENYWRITE, TARGET_MAP_DENYWRITE, MAP_DENYWRITE, MAP_DENYWRITE },
1988 { TARGET_MAP_EXECUTABLE, TARGET_MAP_EXECUTABLE, MAP_EXECUTABLE, MAP_EXECUTABLE },
1989 { TARGET_MAP_LOCKED, TARGET_MAP_LOCKED, MAP_LOCKED, MAP_LOCKED },
1993 static bitmask_transtbl fcntl_flags_tbl[] = {
1994 { TARGET_O_ACCMODE, TARGET_O_WRONLY, O_ACCMODE, O_WRONLY, },
1995 { TARGET_O_ACCMODE, TARGET_O_RDWR, O_ACCMODE, O_RDWR, },
1996 { TARGET_O_CREAT, TARGET_O_CREAT, O_CREAT, O_CREAT, },
1997 { TARGET_O_EXCL, TARGET_O_EXCL, O_EXCL, O_EXCL, },
1998 { TARGET_O_NOCTTY, TARGET_O_NOCTTY, O_NOCTTY, O_NOCTTY, },
1999 { TARGET_O_TRUNC, TARGET_O_TRUNC, O_TRUNC, O_TRUNC, },
2000 { TARGET_O_APPEND, TARGET_O_APPEND, O_APPEND, O_APPEND, },
2001 { TARGET_O_NONBLOCK, TARGET_O_NONBLOCK, O_NONBLOCK, O_NONBLOCK, },
2002 { TARGET_O_SYNC, TARGET_O_SYNC, O_SYNC, O_SYNC, },
2003 { TARGET_FASYNC, TARGET_FASYNC, FASYNC, FASYNC, },
2004 { TARGET_O_DIRECTORY, TARGET_O_DIRECTORY, O_DIRECTORY, O_DIRECTORY, },
2005 { TARGET_O_NOFOLLOW, TARGET_O_NOFOLLOW, O_NOFOLLOW, O_NOFOLLOW, },
2006 { TARGET_O_LARGEFILE, TARGET_O_LARGEFILE, O_LARGEFILE, O_LARGEFILE, },
2007 #if defined(O_DIRECT)
2008 { TARGET_O_DIRECT, TARGET_O_DIRECT, O_DIRECT, O_DIRECT, },
2013 #if defined(TARGET_I386)
2015 /* NOTE: there is really one LDT for all the threads */
2018 static int read_ldt(target_ulong ptr, unsigned long bytecount)
2025 size = TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE;
2026 if (size > bytecount)
2028 p = lock_user(ptr, size, 0);
2029 /* ??? Shoudl this by byteswapped? */
2030 memcpy(p, ldt_table, size);
2031 unlock_user(p, ptr, size);
2035 /* XXX: add locking support */
2036 static int write_ldt(CPUX86State *env,
2037 target_ulong ptr, unsigned long bytecount, int oldmode)
2039 struct target_modify_ldt_ldt_s ldt_info;
2040 struct target_modify_ldt_ldt_s *target_ldt_info;
2041 int seg_32bit, contents, read_exec_only, limit_in_pages;
2042 int seg_not_present, useable;
2043 uint32_t *lp, entry_1, entry_2;
2045 if (bytecount != sizeof(ldt_info))
2047 lock_user_struct(target_ldt_info, ptr, 1);
2048 ldt_info.entry_number = tswap32(target_ldt_info->entry_number);
2049 ldt_info.base_addr = tswapl(target_ldt_info->base_addr);
2050 ldt_info.limit = tswap32(target_ldt_info->limit);
2051 ldt_info.flags = tswap32(target_ldt_info->flags);
2052 unlock_user_struct(target_ldt_info, ptr, 0);
2054 if (ldt_info.entry_number >= TARGET_LDT_ENTRIES)
2056 seg_32bit = ldt_info.flags & 1;
2057 contents = (ldt_info.flags >> 1) & 3;
2058 read_exec_only = (ldt_info.flags >> 3) & 1;
2059 limit_in_pages = (ldt_info.flags >> 4) & 1;
2060 seg_not_present = (ldt_info.flags >> 5) & 1;
2061 useable = (ldt_info.flags >> 6) & 1;
2063 if (contents == 3) {
2066 if (seg_not_present == 0)
2069 /* allocate the LDT */
2071 ldt_table = malloc(TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE);
2074 memset(ldt_table, 0, TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE);
2075 env->ldt.base = h2g(ldt_table);
2076 env->ldt.limit = 0xffff;
2079 /* NOTE: same code as Linux kernel */
2080 /* Allow LDTs to be cleared by the user. */
2081 if (ldt_info.base_addr == 0 && ldt_info.limit == 0) {
2084 read_exec_only == 1 &&
2086 limit_in_pages == 0 &&
2087 seg_not_present == 1 &&
2095 entry_1 = ((ldt_info.base_addr & 0x0000ffff) << 16) |
2096 (ldt_info.limit & 0x0ffff);
2097 entry_2 = (ldt_info.base_addr & 0xff000000) |
2098 ((ldt_info.base_addr & 0x00ff0000) >> 16) |
2099 (ldt_info.limit & 0xf0000) |
2100 ((read_exec_only ^ 1) << 9) |
2102 ((seg_not_present ^ 1) << 15) |
2104 (limit_in_pages << 23) |
2107 entry_2 |= (useable << 20);
2109 /* Install the new entry ... */
2111 lp = (uint32_t *)(ldt_table + (ldt_info.entry_number << 3));
2112 lp[0] = tswap32(entry_1);
2113 lp[1] = tswap32(entry_2);
2117 /* specific and weird i386 syscalls */
2118 int do_modify_ldt(CPUX86State *env, int func, target_ulong ptr, unsigned long bytecount)
2124 ret = read_ldt(ptr, bytecount);
2127 ret = write_ldt(env, ptr, bytecount, 1);
2130 ret = write_ldt(env, ptr, bytecount, 0);
2136 #endif /* defined(TARGET_I386) */
2138 /* this stack is the equivalent of the kernel stack associated with a
2140 #define NEW_STACK_SIZE 8192
2142 static int clone_func(void *arg)
2144 CPUState *env = arg;
2150 int do_fork(CPUState *env, unsigned int flags, unsigned long newsp)
2157 if (flags & CLONE_VM) {
2158 ts = malloc(sizeof(TaskState) + NEW_STACK_SIZE);
2159 memset(ts, 0, sizeof(TaskState));
2160 new_stack = ts->stack;
2162 /* add in task state list */
2163 ts->next = first_task_state;
2164 first_task_state = ts;
2165 /* we create a new CPU instance. */
2166 new_env = cpu_copy(env);
2167 #if defined(TARGET_I386)
2169 newsp = env->regs[R_ESP];
2170 new_env->regs[R_ESP] = newsp;
2171 new_env->regs[R_EAX] = 0;
2172 #elif defined(TARGET_ARM)
2174 newsp = env->regs[13];
2175 new_env->regs[13] = newsp;
2176 new_env->regs[0] = 0;
2177 #elif defined(TARGET_SPARC)
2179 newsp = env->regwptr[22];
2180 new_env->regwptr[22] = newsp;
2181 new_env->regwptr[0] = 0;
2183 printf ("HELPME: %s:%d\n", __FILE__, __LINE__);
2184 #elif defined(TARGET_M68K)
2186 newsp = env->aregs[7];
2187 new_env->aregs[7] = newsp;
2188 new_env->dregs[0] = 0;
2189 /* ??? is this sufficient? */
2190 #elif defined(TARGET_MIPS)
2192 newsp = env->gpr[29][env->current_tc];
2193 new_env->gpr[29][env->current_tc] = newsp;
2194 #elif defined(TARGET_PPC)
2196 newsp = env->gpr[1];
2197 new_env->gpr[1] = newsp;
2200 for (i = 7; i < 32; i++)
2201 new_env->gpr[i] = 0;
2203 #elif defined(TARGET_SH4)
2205 newsp = env->gregs[15];
2206 new_env->gregs[15] = newsp;
2208 #elif defined(TARGET_ALPHA)
2210 newsp = env->ir[30];
2211 new_env->ir[30] = newsp;
2215 for (i = 7; i < 30; i++)
2219 #error unsupported target CPU
2221 new_env->opaque = ts;
2223 ret = __clone2(clone_func, new_stack + NEW_STACK_SIZE, flags, new_env);
2225 ret = clone(clone_func, new_stack + NEW_STACK_SIZE, flags, new_env);
2228 /* if no CLONE_VM, we consider it is a fork */
2229 if ((flags & ~CSIGNAL) != 0)
2236 static long do_fcntl(int fd, int cmd, target_ulong arg)
2239 struct target_flock *target_fl;
2240 struct flock64 fl64;
2241 struct target_flock64 *target_fl64;
2245 case TARGET_F_GETLK:
2246 lock_user_struct(target_fl, arg, 1);
2247 fl.l_type = tswap16(target_fl->l_type);
2248 fl.l_whence = tswap16(target_fl->l_whence);
2249 fl.l_start = tswapl(target_fl->l_start);
2250 fl.l_len = tswapl(target_fl->l_len);
2251 fl.l_pid = tswapl(target_fl->l_pid);
2252 unlock_user_struct(target_fl, arg, 0);
2253 ret = fcntl(fd, cmd, &fl);
2255 lock_user_struct(target_fl, arg, 0);
2256 target_fl->l_type = tswap16(fl.l_type);
2257 target_fl->l_whence = tswap16(fl.l_whence);
2258 target_fl->l_start = tswapl(fl.l_start);
2259 target_fl->l_len = tswapl(fl.l_len);
2260 target_fl->l_pid = tswapl(fl.l_pid);
2261 unlock_user_struct(target_fl, arg, 1);
2265 case TARGET_F_SETLK:
2266 case TARGET_F_SETLKW:
2267 lock_user_struct(target_fl, arg, 1);
2268 fl.l_type = tswap16(target_fl->l_type);
2269 fl.l_whence = tswap16(target_fl->l_whence);
2270 fl.l_start = tswapl(target_fl->l_start);
2271 fl.l_len = tswapl(target_fl->l_len);
2272 fl.l_pid = tswapl(target_fl->l_pid);
2273 unlock_user_struct(target_fl, arg, 0);
2274 ret = fcntl(fd, cmd, &fl);
2277 case TARGET_F_GETLK64:
2278 lock_user_struct(target_fl64, arg, 1);
2279 fl64.l_type = tswap16(target_fl64->l_type) >> 1;
2280 fl64.l_whence = tswap16(target_fl64->l_whence);
2281 fl64.l_start = tswapl(target_fl64->l_start);
2282 fl64.l_len = tswapl(target_fl64->l_len);
2283 fl64.l_pid = tswap16(target_fl64->l_pid);
2284 unlock_user_struct(target_fl64, arg, 0);
2285 ret = fcntl(fd, cmd >> 1, &fl64);
2287 lock_user_struct(target_fl64, arg, 0);
2288 target_fl64->l_type = tswap16(fl64.l_type) >> 1;
2289 target_fl64->l_whence = tswap16(fl64.l_whence);
2290 target_fl64->l_start = tswapl(fl64.l_start);
2291 target_fl64->l_len = tswapl(fl64.l_len);
2292 target_fl64->l_pid = tswapl(fl64.l_pid);
2293 unlock_user_struct(target_fl64, arg, 1);
2296 case TARGET_F_SETLK64:
2297 case TARGET_F_SETLKW64:
2298 lock_user_struct(target_fl64, arg, 1);
2299 fl64.l_type = tswap16(target_fl64->l_type) >> 1;
2300 fl64.l_whence = tswap16(target_fl64->l_whence);
2301 fl64.l_start = tswapl(target_fl64->l_start);
2302 fl64.l_len = tswapl(target_fl64->l_len);
2303 fl64.l_pid = tswap16(target_fl64->l_pid);
2304 unlock_user_struct(target_fl64, arg, 0);
2305 ret = fcntl(fd, cmd >> 1, &fl64);
2309 ret = fcntl(fd, cmd, arg);
2310 ret = host_to_target_bitmask(ret, fcntl_flags_tbl);
2314 ret = fcntl(fd, cmd, target_to_host_bitmask(arg, fcntl_flags_tbl));
2318 ret = fcntl(fd, cmd, arg);
2326 static inline int high2lowuid(int uid)
2334 static inline int high2lowgid(int gid)
2342 static inline int low2highuid(int uid)
2344 if ((int16_t)uid == -1)
2350 static inline int low2highgid(int gid)
2352 if ((int16_t)gid == -1)
2358 #endif /* USE_UID16 */
2360 void syscall_init(void)
2363 const argtype *arg_type;
2366 #define STRUCT(name, list...) thunk_register_struct(STRUCT_ ## name, #name, struct_ ## name ## _def);
2367 #define STRUCT_SPECIAL(name) thunk_register_struct_direct(STRUCT_ ## name, #name, &struct_ ## name ## _def);
2368 #include "syscall_types.h"
2370 #undef STRUCT_SPECIAL
2372 /* we patch the ioctl size if necessary. We rely on the fact that
2373 no ioctl has all the bits at '1' in the size field */
2375 while (ie->target_cmd != 0) {
2376 if (((ie->target_cmd >> TARGET_IOC_SIZESHIFT) & TARGET_IOC_SIZEMASK) ==
2377 TARGET_IOC_SIZEMASK) {
2378 arg_type = ie->arg_type;
2379 if (arg_type[0] != TYPE_PTR) {
2380 fprintf(stderr, "cannot patch size for ioctl 0x%x\n",
2385 size = thunk_type_size(arg_type, 0);
2386 ie->target_cmd = (ie->target_cmd &
2387 ~(TARGET_IOC_SIZEMASK << TARGET_IOC_SIZESHIFT)) |
2388 (size << TARGET_IOC_SIZESHIFT);
2390 /* automatic consistency check if same arch */
2391 #if defined(__i386__) && defined(TARGET_I386)
2392 if (ie->target_cmd != ie->host_cmd) {
2393 fprintf(stderr, "ERROR: ioctl: target=0x%x host=0x%x\n",
2394 ie->target_cmd, ie->host_cmd);
2401 static inline uint64_t target_offset64(uint32_t word0, uint32_t word1)
2403 #ifdef TARGET_WORDS_BIG_ENDIAN
2404 return ((uint64_t)word0 << 32) | word1;
2406 return ((uint64_t)word1 << 32) | word0;
2410 #ifdef TARGET_NR_truncate64
2411 static inline long target_truncate64(void *cpu_env, const char *arg1,
2412 long arg2, long arg3, long arg4)
2415 if (((CPUARMState *)cpu_env)->eabi)
2421 return get_errno(truncate64(arg1, target_offset64(arg2, arg3)));
2425 #ifdef TARGET_NR_ftruncate64
2426 static inline long target_ftruncate64(void *cpu_env, long arg1, long arg2,
2427 long arg3, long arg4)
2430 if (((CPUARMState *)cpu_env)->eabi)
2436 return get_errno(ftruncate64(arg1, target_offset64(arg2, arg3)));
2440 static inline void target_to_host_timespec(struct timespec *host_ts,
2441 target_ulong target_addr)
2443 struct target_timespec *target_ts;
2445 lock_user_struct(target_ts, target_addr, 1);
2446 host_ts->tv_sec = tswapl(target_ts->tv_sec);
2447 host_ts->tv_nsec = tswapl(target_ts->tv_nsec);
2448 unlock_user_struct(target_ts, target_addr, 0);
2451 static inline void host_to_target_timespec(target_ulong target_addr,
2452 struct timespec *host_ts)
2454 struct target_timespec *target_ts;
2456 lock_user_struct(target_ts, target_addr, 0);
2457 target_ts->tv_sec = tswapl(host_ts->tv_sec);
2458 target_ts->tv_nsec = tswapl(host_ts->tv_nsec);
2459 unlock_user_struct(target_ts, target_addr, 1);
2462 long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
2463 long arg4, long arg5, long arg6)
2471 gemu_log("syscall %d", num);
2474 case TARGET_NR_exit:
2478 gdb_exit(cpu_env, arg1);
2479 /* XXX: should free thread stack and CPU env */
2481 ret = 0; /* avoid warning */
2483 case TARGET_NR_read:
2484 page_unprotect_range(arg2, arg3);
2485 p = lock_user(arg2, arg3, 0);
2486 ret = get_errno(read(arg1, p, arg3));
2487 unlock_user(p, arg2, ret);
2489 case TARGET_NR_write:
2490 p = lock_user(arg2, arg3, 1);
2491 ret = get_errno(write(arg1, p, arg3));
2492 unlock_user(p, arg2, 0);
2494 case TARGET_NR_open:
2495 p = lock_user_string(arg1);
2496 ret = get_errno(open(path(p),
2497 target_to_host_bitmask(arg2, fcntl_flags_tbl),
2499 unlock_user(p, arg1, 0);
2501 case TARGET_NR_close:
2502 ret = get_errno(close(arg1));
2507 case TARGET_NR_fork:
2508 ret = get_errno(do_fork(cpu_env, SIGCHLD, 0));
2510 #ifdef TARGET_NR_waitpid
2511 case TARGET_NR_waitpid:
2514 ret = get_errno(waitpid(arg1, &status, arg3));
2515 if (!is_error(ret) && arg2)
2516 tput32(arg2, status);
2520 #ifdef TARGET_NR_creat /* not on alpha */
2521 case TARGET_NR_creat:
2522 p = lock_user_string(arg1);
2523 ret = get_errno(creat(p, arg2));
2524 unlock_user(p, arg1, 0);
2527 case TARGET_NR_link:
2530 p = lock_user_string(arg1);
2531 p2 = lock_user_string(arg2);
2532 ret = get_errno(link(p, p2));
2533 unlock_user(p2, arg2, 0);
2534 unlock_user(p, arg1, 0);
2537 case TARGET_NR_unlink:
2538 p = lock_user_string(arg1);
2539 ret = get_errno(unlink(p));
2540 unlock_user(p, arg1, 0);
2542 case TARGET_NR_execve:
2544 char **argp, **envp;
2547 target_ulong guest_argp;
2548 target_ulong guest_envp;
2554 for (gp = guest_argp; tgetl(gp); gp++)
2558 for (gp = guest_envp; tgetl(gp); gp++)
2561 argp = alloca((argc + 1) * sizeof(void *));
2562 envp = alloca((envc + 1) * sizeof(void *));
2564 for (gp = guest_argp, q = argp; ;
2565 gp += sizeof(target_ulong), q++) {
2569 *q = lock_user_string(addr);
2573 for (gp = guest_envp, q = envp; ;
2574 gp += sizeof(target_ulong), q++) {
2578 *q = lock_user_string(addr);
2582 p = lock_user_string(arg1);
2583 ret = get_errno(execve(p, argp, envp));
2584 unlock_user(p, arg1, 0);
2586 for (gp = guest_argp, q = argp; *q;
2587 gp += sizeof(target_ulong), q++) {
2589 unlock_user(*q, addr, 0);
2591 for (gp = guest_envp, q = envp; *q;
2592 gp += sizeof(target_ulong), q++) {
2594 unlock_user(*q, addr, 0);
2598 case TARGET_NR_chdir:
2599 p = lock_user_string(arg1);
2600 ret = get_errno(chdir(p));
2601 unlock_user(p, arg1, 0);
2603 #ifdef TARGET_NR_time
2604 case TARGET_NR_time:
2607 ret = get_errno(time(&host_time));
2608 if (!is_error(ret) && arg1)
2609 tputl(arg1, host_time);
2613 case TARGET_NR_mknod:
2614 p = lock_user_string(arg1);
2615 ret = get_errno(mknod(p, arg2, arg3));
2616 unlock_user(p, arg1, 0);
2618 case TARGET_NR_chmod:
2619 p = lock_user_string(arg1);
2620 ret = get_errno(chmod(p, arg2));
2621 unlock_user(p, arg1, 0);
2623 #ifdef TARGET_NR_break
2624 case TARGET_NR_break:
2627 #ifdef TARGET_NR_oldstat
2628 case TARGET_NR_oldstat:
2631 case TARGET_NR_lseek:
2632 ret = get_errno(lseek(arg1, arg2, arg3));
2634 #ifdef TARGET_NR_getxpid
2635 case TARGET_NR_getxpid:
2637 case TARGET_NR_getpid:
2639 ret = get_errno(getpid());
2641 case TARGET_NR_mount:
2643 /* need to look at the data field */
2645 p = lock_user_string(arg1);
2646 p2 = lock_user_string(arg2);
2647 p3 = lock_user_string(arg3);
2648 ret = get_errno(mount(p, p2, p3, (unsigned long)arg4, (const void *)arg5));
2649 unlock_user(p, arg1, 0);
2650 unlock_user(p2, arg2, 0);
2651 unlock_user(p3, arg3, 0);
2654 #ifdef TARGET_NR_umount
2655 case TARGET_NR_umount:
2656 p = lock_user_string(arg1);
2657 ret = get_errno(umount(p));
2658 unlock_user(p, arg1, 0);
2661 #ifdef TARGET_NR_stime /* not on alpha */
2662 case TARGET_NR_stime:
2665 host_time = tgetl(arg1);
2666 ret = get_errno(stime(&host_time));
2670 case TARGET_NR_ptrace:
2672 #ifdef TARGET_NR_alarm /* not on alpha */
2673 case TARGET_NR_alarm:
2677 #ifdef TARGET_NR_oldfstat
2678 case TARGET_NR_oldfstat:
2681 #ifdef TARGET_NR_pause /* not on alpha */
2682 case TARGET_NR_pause:
2683 ret = get_errno(pause());
2686 #ifdef TARGET_NR_utime
2687 case TARGET_NR_utime:
2689 struct utimbuf tbuf, *host_tbuf;
2690 struct target_utimbuf *target_tbuf;
2692 lock_user_struct(target_tbuf, arg2, 1);
2693 tbuf.actime = tswapl(target_tbuf->actime);
2694 tbuf.modtime = tswapl(target_tbuf->modtime);
2695 unlock_user_struct(target_tbuf, arg2, 0);
2700 p = lock_user_string(arg1);
2701 ret = get_errno(utime(p, host_tbuf));
2702 unlock_user(p, arg1, 0);
2706 case TARGET_NR_utimes:
2708 struct timeval *tvp, tv[2];
2710 target_to_host_timeval(&tv[0], arg2);
2711 target_to_host_timeval(&tv[1],
2712 arg2 + sizeof (struct target_timeval));
2717 p = lock_user_string(arg1);
2718 ret = get_errno(utimes(p, tvp));
2719 unlock_user(p, arg1, 0);
2722 #ifdef TARGET_NR_stty
2723 case TARGET_NR_stty:
2726 #ifdef TARGET_NR_gtty
2727 case TARGET_NR_gtty:
2730 case TARGET_NR_access:
2731 p = lock_user_string(arg1);
2732 ret = get_errno(access(p, arg2));
2733 unlock_user(p, arg1, 0);
2735 #ifdef TARGET_NR_nice /* not on alpha */
2736 case TARGET_NR_nice:
2737 ret = get_errno(nice(arg1));
2740 #ifdef TARGET_NR_ftime
2741 case TARGET_NR_ftime:
2744 case TARGET_NR_sync:
2748 case TARGET_NR_kill:
2749 ret = get_errno(kill(arg1, arg2));
2751 case TARGET_NR_rename:
2754 p = lock_user_string(arg1);
2755 p2 = lock_user_string(arg2);
2756 ret = get_errno(rename(p, p2));
2757 unlock_user(p2, arg2, 0);
2758 unlock_user(p, arg1, 0);
2761 case TARGET_NR_mkdir:
2762 p = lock_user_string(arg1);
2763 ret = get_errno(mkdir(p, arg2));
2764 unlock_user(p, arg1, 0);
2766 case TARGET_NR_rmdir:
2767 p = lock_user_string(arg1);
2768 ret = get_errno(rmdir(p));
2769 unlock_user(p, arg1, 0);
2772 ret = get_errno(dup(arg1));
2774 case TARGET_NR_pipe:
2777 ret = get_errno(pipe(host_pipe));
2778 if (!is_error(ret)) {
2779 #if defined(TARGET_MIPS)
2780 CPUMIPSState *env = (CPUMIPSState*)cpu_env;
2781 env->gpr[3][env->current_tc] = host_pipe[1];
2784 tput32(arg1, host_pipe[0]);
2785 tput32(arg1 + 4, host_pipe[1]);
2790 case TARGET_NR_times:
2792 struct target_tms *tmsp;
2794 ret = get_errno(times(&tms));
2796 tmsp = lock_user(arg1, sizeof(struct target_tms), 0);
2797 tmsp->tms_utime = tswapl(host_to_target_clock_t(tms.tms_utime));
2798 tmsp->tms_stime = tswapl(host_to_target_clock_t(tms.tms_stime));
2799 tmsp->tms_cutime = tswapl(host_to_target_clock_t(tms.tms_cutime));
2800 tmsp->tms_cstime = tswapl(host_to_target_clock_t(tms.tms_cstime));
2803 ret = host_to_target_clock_t(ret);
2806 #ifdef TARGET_NR_prof
2807 case TARGET_NR_prof:
2810 #ifdef TARGET_NR_signal
2811 case TARGET_NR_signal:
2814 case TARGET_NR_acct:
2815 p = lock_user_string(arg1);
2816 ret = get_errno(acct(path(p)));
2817 unlock_user(p, arg1, 0);
2819 #ifdef TARGET_NR_umount2 /* not on alpha */
2820 case TARGET_NR_umount2:
2821 p = lock_user_string(arg1);
2822 ret = get_errno(umount2(p, arg2));
2823 unlock_user(p, arg1, 0);
2826 #ifdef TARGET_NR_lock
2827 case TARGET_NR_lock:
2830 case TARGET_NR_ioctl:
2831 ret = do_ioctl(arg1, arg2, arg3);
2833 case TARGET_NR_fcntl:
2834 ret = get_errno(do_fcntl(arg1, arg2, arg3));
2836 #ifdef TARGET_NR_mpx
2840 case TARGET_NR_setpgid:
2841 ret = get_errno(setpgid(arg1, arg2));
2843 #ifdef TARGET_NR_ulimit
2844 case TARGET_NR_ulimit:
2847 #ifdef TARGET_NR_oldolduname
2848 case TARGET_NR_oldolduname:
2851 case TARGET_NR_umask:
2852 ret = get_errno(umask(arg1));
2854 case TARGET_NR_chroot:
2855 p = lock_user_string(arg1);
2856 ret = get_errno(chroot(p));
2857 unlock_user(p, arg1, 0);
2859 case TARGET_NR_ustat:
2861 case TARGET_NR_dup2:
2862 ret = get_errno(dup2(arg1, arg2));
2864 #ifdef TARGET_NR_getppid /* not on alpha */
2865 case TARGET_NR_getppid:
2866 ret = get_errno(getppid());
2869 case TARGET_NR_getpgrp:
2870 ret = get_errno(getpgrp());
2872 case TARGET_NR_setsid:
2873 ret = get_errno(setsid());
2875 #ifdef TARGET_NR_sigaction
2876 case TARGET_NR_sigaction:
2878 #if !defined(TARGET_MIPS)
2879 struct target_old_sigaction *old_act;
2880 struct target_sigaction act, oact, *pact;
2882 lock_user_struct(old_act, arg2, 1);
2883 act._sa_handler = old_act->_sa_handler;
2884 target_siginitset(&act.sa_mask, old_act->sa_mask);
2885 act.sa_flags = old_act->sa_flags;
2886 act.sa_restorer = old_act->sa_restorer;
2887 unlock_user_struct(old_act, arg2, 0);
2892 ret = get_errno(do_sigaction(arg1, pact, &oact));
2893 if (!is_error(ret) && arg3) {
2894 lock_user_struct(old_act, arg3, 0);
2895 old_act->_sa_handler = oact._sa_handler;
2896 old_act->sa_mask = oact.sa_mask.sig[0];
2897 old_act->sa_flags = oact.sa_flags;
2898 old_act->sa_restorer = oact.sa_restorer;
2899 unlock_user_struct(old_act, arg3, 1);
2902 struct target_sigaction act, oact, *pact, *old_act;
2905 lock_user_struct(old_act, arg2, 1);
2906 act._sa_handler = old_act->_sa_handler;
2907 target_siginitset(&act.sa_mask, old_act->sa_mask.sig[0]);
2908 act.sa_flags = old_act->sa_flags;
2909 unlock_user_struct(old_act, arg2, 0);
2915 ret = get_errno(do_sigaction(arg1, pact, &oact));
2917 if (!is_error(ret) && arg3) {
2918 lock_user_struct(old_act, arg3, 0);
2919 old_act->_sa_handler = oact._sa_handler;
2920 old_act->sa_flags = oact.sa_flags;
2921 old_act->sa_mask.sig[0] = oact.sa_mask.sig[0];
2922 old_act->sa_mask.sig[1] = 0;
2923 old_act->sa_mask.sig[2] = 0;
2924 old_act->sa_mask.sig[3] = 0;
2925 unlock_user_struct(old_act, arg3, 1);
2931 case TARGET_NR_rt_sigaction:
2933 struct target_sigaction *act;
2934 struct target_sigaction *oact;
2937 lock_user_struct(act, arg2, 1);
2941 lock_user_struct(oact, arg3, 0);
2944 ret = get_errno(do_sigaction(arg1, act, oact));
2946 unlock_user_struct(act, arg2, 0);
2948 unlock_user_struct(oact, arg3, 1);
2951 #ifdef TARGET_NR_sgetmask /* not on alpha */
2952 case TARGET_NR_sgetmask:
2955 target_ulong target_set;
2956 sigprocmask(0, NULL, &cur_set);
2957 host_to_target_old_sigset(&target_set, &cur_set);
2962 #ifdef TARGET_NR_ssetmask /* not on alpha */
2963 case TARGET_NR_ssetmask:
2965 sigset_t set, oset, cur_set;
2966 target_ulong target_set = arg1;
2967 sigprocmask(0, NULL, &cur_set);
2968 target_to_host_old_sigset(&set, &target_set);
2969 sigorset(&set, &set, &cur_set);
2970 sigprocmask(SIG_SETMASK, &set, &oset);
2971 host_to_target_old_sigset(&target_set, &oset);
2976 #ifdef TARGET_NR_sigprocmask
2977 case TARGET_NR_sigprocmask:
2980 sigset_t set, oldset, *set_ptr;
2984 case TARGET_SIG_BLOCK:
2987 case TARGET_SIG_UNBLOCK:
2990 case TARGET_SIG_SETMASK:
2997 p = lock_user(arg2, sizeof(target_sigset_t), 1);
2998 target_to_host_old_sigset(&set, p);
2999 unlock_user(p, arg2, 0);
3005 ret = get_errno(sigprocmask(arg1, set_ptr, &oldset));
3006 if (!is_error(ret) && arg3) {
3007 p = lock_user(arg3, sizeof(target_sigset_t), 0);
3008 host_to_target_old_sigset(p, &oldset);
3009 unlock_user(p, arg3, sizeof(target_sigset_t));
3014 case TARGET_NR_rt_sigprocmask:
3017 sigset_t set, oldset, *set_ptr;
3021 case TARGET_SIG_BLOCK:
3024 case TARGET_SIG_UNBLOCK:
3027 case TARGET_SIG_SETMASK:
3034 p = lock_user(arg2, sizeof(target_sigset_t), 1);
3035 target_to_host_sigset(&set, p);
3036 unlock_user(p, arg2, 0);
3042 ret = get_errno(sigprocmask(how, set_ptr, &oldset));
3043 if (!is_error(ret) && arg3) {
3044 p = lock_user(arg3, sizeof(target_sigset_t), 0);
3045 host_to_target_sigset(p, &oldset);
3046 unlock_user(p, arg3, sizeof(target_sigset_t));
3050 #ifdef TARGET_NR_sigpending
3051 case TARGET_NR_sigpending:
3054 ret = get_errno(sigpending(&set));
3055 if (!is_error(ret)) {
3056 p = lock_user(arg1, sizeof(target_sigset_t), 0);
3057 host_to_target_old_sigset(p, &set);
3058 unlock_user(p, arg1, sizeof(target_sigset_t));
3063 case TARGET_NR_rt_sigpending:
3066 ret = get_errno(sigpending(&set));
3067 if (!is_error(ret)) {
3068 p = lock_user(arg1, sizeof(target_sigset_t), 0);
3069 host_to_target_sigset(p, &set);
3070 unlock_user(p, arg1, sizeof(target_sigset_t));
3074 #ifdef TARGET_NR_sigsuspend
3075 case TARGET_NR_sigsuspend:
3078 p = lock_user(arg1, sizeof(target_sigset_t), 1);
3079 target_to_host_old_sigset(&set, p);
3080 unlock_user(p, arg1, 0);
3081 ret = get_errno(sigsuspend(&set));
3085 case TARGET_NR_rt_sigsuspend:
3088 p = lock_user(arg1, sizeof(target_sigset_t), 1);
3089 target_to_host_sigset(&set, p);
3090 unlock_user(p, arg1, 0);
3091 ret = get_errno(sigsuspend(&set));
3094 case TARGET_NR_rt_sigtimedwait:
3097 struct timespec uts, *puts;
3100 p = lock_user(arg1, sizeof(target_sigset_t), 1);
3101 target_to_host_sigset(&set, p);
3102 unlock_user(p, arg1, 0);
3105 target_to_host_timespec(puts, arg3);
3109 ret = get_errno(sigtimedwait(&set, &uinfo, puts));
3110 if (!is_error(ret) && arg2) {
3111 p = lock_user(arg2, sizeof(target_sigset_t), 0);
3112 host_to_target_siginfo(p, &uinfo);
3113 unlock_user(p, arg2, sizeof(target_sigset_t));
3117 case TARGET_NR_rt_sigqueueinfo:
3120 p = lock_user(arg3, sizeof(target_sigset_t), 1);
3121 target_to_host_siginfo(&uinfo, p);
3122 unlock_user(p, arg1, 0);
3123 ret = get_errno(sys_rt_sigqueueinfo(arg1, arg2, &uinfo));
3126 #ifdef TARGET_NR_sigreturn
3127 case TARGET_NR_sigreturn:
3128 /* NOTE: ret is eax, so not transcoding must be done */
3129 ret = do_sigreturn(cpu_env);
3132 case TARGET_NR_rt_sigreturn:
3133 /* NOTE: ret is eax, so not transcoding must be done */
3134 ret = do_rt_sigreturn(cpu_env);
3136 case TARGET_NR_sethostname:
3137 p = lock_user_string(arg1);
3138 ret = get_errno(sethostname(p, arg2));
3139 unlock_user(p, arg1, 0);
3141 case TARGET_NR_setrlimit:
3143 /* XXX: convert resource ? */
3144 int resource = arg1;
3145 struct target_rlimit *target_rlim;
3147 lock_user_struct(target_rlim, arg2, 1);
3148 rlim.rlim_cur = tswapl(target_rlim->rlim_cur);
3149 rlim.rlim_max = tswapl(target_rlim->rlim_max);
3150 unlock_user_struct(target_rlim, arg2, 0);
3151 ret = get_errno(setrlimit(resource, &rlim));
3154 case TARGET_NR_getrlimit:
3156 /* XXX: convert resource ? */
3157 int resource = arg1;
3158 struct target_rlimit *target_rlim;
3161 ret = get_errno(getrlimit(resource, &rlim));
3162 if (!is_error(ret)) {
3163 lock_user_struct(target_rlim, arg2, 0);
3164 rlim.rlim_cur = tswapl(target_rlim->rlim_cur);
3165 rlim.rlim_max = tswapl(target_rlim->rlim_max);
3166 unlock_user_struct(target_rlim, arg2, 1);
3170 case TARGET_NR_getrusage:
3172 struct rusage rusage;
3173 ret = get_errno(getrusage(arg1, &rusage));
3174 if (!is_error(ret)) {
3175 host_to_target_rusage(arg2, &rusage);
3179 case TARGET_NR_gettimeofday:
3182 ret = get_errno(gettimeofday(&tv, NULL));
3183 if (!is_error(ret)) {
3184 host_to_target_timeval(arg1, &tv);
3188 case TARGET_NR_settimeofday:
3191 target_to_host_timeval(&tv, arg1);
3192 ret = get_errno(settimeofday(&tv, NULL));
3195 #ifdef TARGET_NR_select
3196 case TARGET_NR_select:
3198 struct target_sel_arg_struct *sel;
3199 target_ulong inp, outp, exp, tvp;
3202 lock_user_struct(sel, arg1, 1);
3203 nsel = tswapl(sel->n);
3204 inp = tswapl(sel->inp);
3205 outp = tswapl(sel->outp);
3206 exp = tswapl(sel->exp);
3207 tvp = tswapl(sel->tvp);
3208 unlock_user_struct(sel, arg1, 0);
3209 ret = do_select(nsel, inp, outp, exp, tvp);
3213 case TARGET_NR_symlink:
3216 p = lock_user_string(arg1);
3217 p2 = lock_user_string(arg2);
3218 ret = get_errno(symlink(p, p2));
3219 unlock_user(p2, arg2, 0);
3220 unlock_user(p, arg1, 0);
3223 #ifdef TARGET_NR_oldlstat
3224 case TARGET_NR_oldlstat:
3227 case TARGET_NR_readlink:
3230 p = lock_user_string(arg1);
3231 p2 = lock_user(arg2, arg3, 0);
3232 ret = get_errno(readlink(path(p), p2, arg3));
3233 unlock_user(p2, arg2, ret);
3234 unlock_user(p, arg1, 0);
3237 #ifdef TARGET_NR_uselib
3238 case TARGET_NR_uselib:
3241 #ifdef TARGET_NR_swapon
3242 case TARGET_NR_swapon:
3243 p = lock_user_string(arg1);
3244 ret = get_errno(swapon(p, arg2));
3245 unlock_user(p, arg1, 0);
3248 case TARGET_NR_reboot:
3250 #ifdef TARGET_NR_readdir
3251 case TARGET_NR_readdir:
3254 #ifdef TARGET_NR_mmap
3255 case TARGET_NR_mmap:
3256 #if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_M68K)
3259 target_ulong v1, v2, v3, v4, v5, v6;
3260 v = lock_user(arg1, 6 * sizeof(target_ulong), 1);
3267 unlock_user(v, arg1, 0);
3268 ret = get_errno(target_mmap(v1, v2, v3,
3269 target_to_host_bitmask(v4, mmap_flags_tbl),
3273 ret = get_errno(target_mmap(arg1, arg2, arg3,
3274 target_to_host_bitmask(arg4, mmap_flags_tbl),
3280 #ifdef TARGET_NR_mmap2
3281 case TARGET_NR_mmap2:
3282 #if defined(TARGET_SPARC) || defined(TARGET_MIPS)
3283 #define MMAP_SHIFT 12
3285 #define MMAP_SHIFT TARGET_PAGE_BITS
3287 ret = get_errno(target_mmap(arg1, arg2, arg3,
3288 target_to_host_bitmask(arg4, mmap_flags_tbl),
3290 arg6 << MMAP_SHIFT));
3293 case TARGET_NR_munmap:
3294 ret = get_errno(target_munmap(arg1, arg2));
3296 case TARGET_NR_mprotect:
3297 ret = get_errno(target_mprotect(arg1, arg2, arg3));
3299 #ifdef TARGET_NR_mremap
3300 case TARGET_NR_mremap:
3301 ret = get_errno(target_mremap(arg1, arg2, arg3, arg4, arg5));
3304 /* ??? msync/mlock/munlock are broken for softmmu. */
3305 #ifdef TARGET_NR_msync
3306 case TARGET_NR_msync:
3307 ret = get_errno(msync(g2h(arg1), arg2, arg3));
3310 #ifdef TARGET_NR_mlock
3311 case TARGET_NR_mlock:
3312 ret = get_errno(mlock(g2h(arg1), arg2));
3315 #ifdef TARGET_NR_munlock
3316 case TARGET_NR_munlock:
3317 ret = get_errno(munlock(g2h(arg1), arg2));
3320 #ifdef TARGET_NR_mlockall
3321 case TARGET_NR_mlockall:
3322 ret = get_errno(mlockall(arg1));
3325 #ifdef TARGET_NR_munlockall
3326 case TARGET_NR_munlockall:
3327 ret = get_errno(munlockall());
3330 case TARGET_NR_truncate:
3331 p = lock_user_string(arg1);
3332 ret = get_errno(truncate(p, arg2));
3333 unlock_user(p, arg1, 0);
3335 case TARGET_NR_ftruncate:
3336 ret = get_errno(ftruncate(arg1, arg2));
3338 case TARGET_NR_fchmod:
3339 ret = get_errno(fchmod(arg1, arg2));
3341 case TARGET_NR_getpriority:
3342 ret = get_errno(getpriority(arg1, arg2));
3344 case TARGET_NR_setpriority:
3345 ret = get_errno(setpriority(arg1, arg2, arg3));
3347 #ifdef TARGET_NR_profil
3348 case TARGET_NR_profil:
3351 case TARGET_NR_statfs:
3352 p = lock_user_string(arg1);
3353 ret = get_errno(statfs(path(p), &stfs));
3354 unlock_user(p, arg1, 0);
3356 if (!is_error(ret)) {
3357 struct target_statfs *target_stfs;
3359 lock_user_struct(target_stfs, arg2, 0);
3360 /* ??? put_user is probably wrong. */
3361 put_user(stfs.f_type, &target_stfs->f_type);
3362 put_user(stfs.f_bsize, &target_stfs->f_bsize);
3363 put_user(stfs.f_blocks, &target_stfs->f_blocks);
3364 put_user(stfs.f_bfree, &target_stfs->f_bfree);
3365 put_user(stfs.f_bavail, &target_stfs->f_bavail);
3366 put_user(stfs.f_files, &target_stfs->f_files);
3367 put_user(stfs.f_ffree, &target_stfs->f_ffree);
3368 put_user(stfs.f_fsid.__val[0], &target_stfs->f_fsid.val[0]);
3369 put_user(stfs.f_fsid.__val[1], &target_stfs->f_fsid.val[1]);
3370 put_user(stfs.f_namelen, &target_stfs->f_namelen);
3371 unlock_user_struct(target_stfs, arg2, 1);
3374 case TARGET_NR_fstatfs:
3375 ret = get_errno(fstatfs(arg1, &stfs));
3376 goto convert_statfs;
3377 #ifdef TARGET_NR_statfs64
3378 case TARGET_NR_statfs64:
3379 p = lock_user_string(arg1);
3380 ret = get_errno(statfs(path(p), &stfs));
3381 unlock_user(p, arg1, 0);
3383 if (!is_error(ret)) {
3384 struct target_statfs64 *target_stfs;
3386 lock_user_struct(target_stfs, arg3, 0);
3387 /* ??? put_user is probably wrong. */
3388 put_user(stfs.f_type, &target_stfs->f_type);
3389 put_user(stfs.f_bsize, &target_stfs->f_bsize);
3390 put_user(stfs.f_blocks, &target_stfs->f_blocks);
3391 put_user(stfs.f_bfree, &target_stfs->f_bfree);
3392 put_user(stfs.f_bavail, &target_stfs->f_bavail);
3393 put_user(stfs.f_files, &target_stfs->f_files);
3394 put_user(stfs.f_ffree, &target_stfs->f_ffree);
3395 put_user(stfs.f_fsid.__val[0], &target_stfs->f_fsid.val[0]);
3396 put_user(stfs.f_fsid.__val[1], &target_stfs->f_fsid.val[1]);
3397 put_user(stfs.f_namelen, &target_stfs->f_namelen);
3398 unlock_user_struct(target_stfs, arg3, 0);
3401 case TARGET_NR_fstatfs64:
3402 ret = get_errno(fstatfs(arg1, &stfs));
3403 goto convert_statfs64;
3405 #ifdef TARGET_NR_ioperm
3406 case TARGET_NR_ioperm:
3409 #ifdef TARGET_NR_socketcall
3410 case TARGET_NR_socketcall:
3411 ret = do_socketcall(arg1, arg2);
3414 #ifdef TARGET_NR_accept
3415 case TARGET_NR_accept:
3416 ret = do_accept(arg1, arg2, arg3);
3419 #ifdef TARGET_NR_bind
3420 case TARGET_NR_bind:
3421 ret = do_bind(arg1, arg2, arg3);
3424 #ifdef TARGET_NR_connect
3425 case TARGET_NR_connect:
3426 ret = do_connect(arg1, arg2, arg3);
3429 #ifdef TARGET_NR_getpeername
3430 case TARGET_NR_getpeername:
3431 ret = do_getpeername(arg1, arg2, arg3);
3434 #ifdef TARGET_NR_getsockname
3435 case TARGET_NR_getsockname:
3436 ret = do_getsockname(arg1, arg2, arg3);
3439 #ifdef TARGET_NR_getsockopt
3440 case TARGET_NR_getsockopt:
3441 ret = do_getsockopt(arg1, arg2, arg3, arg4, arg5);
3444 #ifdef TARGET_NR_listen
3445 case TARGET_NR_listen:
3446 ret = get_errno(listen(arg1, arg2));
3449 #ifdef TARGET_NR_recv
3450 case TARGET_NR_recv:
3451 ret = do_recvfrom(arg1, arg2, arg3, arg4, 0, 0);
3454 #ifdef TARGET_NR_recvfrom
3455 case TARGET_NR_recvfrom:
3456 ret = do_recvfrom(arg1, arg2, arg3, arg4, arg5, arg6);
3459 #ifdef TARGET_NR_recvmsg
3460 case TARGET_NR_recvmsg:
3461 ret = do_sendrecvmsg(arg1, arg2, arg3, 0);
3464 #ifdef TARGET_NR_send
3465 case TARGET_NR_send:
3466 ret = do_sendto(arg1, arg2, arg3, arg4, 0, 0);
3469 #ifdef TARGET_NR_sendmsg
3470 case TARGET_NR_sendmsg:
3471 ret = do_sendrecvmsg(arg1, arg2, arg3, 1);
3474 #ifdef TARGET_NR_sendto
3475 case TARGET_NR_sendto:
3476 ret = do_sendto(arg1, arg2, arg3, arg4, arg5, arg6);
3479 #ifdef TARGET_NR_shutdown
3480 case TARGET_NR_shutdown:
3481 ret = get_errno(shutdown(arg1, arg2));
3484 #ifdef TARGET_NR_socket
3485 case TARGET_NR_socket:
3486 ret = do_socket(arg1, arg2, arg3);
3489 #ifdef TARGET_NR_socketpair
3490 case TARGET_NR_socketpair:
3491 ret = do_socketpair(arg1, arg2, arg3, arg4);
3494 #ifdef TARGET_NR_setsockopt
3495 case TARGET_NR_setsockopt:
3496 ret = do_setsockopt(arg1, arg2, arg3, arg4, (socklen_t) arg5);
3500 case TARGET_NR_syslog:
3501 p = lock_user_string(arg2);
3502 ret = get_errno(sys_syslog((int)arg1, p, (int)arg3));
3503 unlock_user(p, arg2, 0);
3506 case TARGET_NR_setitimer:
3508 struct itimerval value, ovalue, *pvalue;
3512 target_to_host_timeval(&pvalue->it_interval,
3514 target_to_host_timeval(&pvalue->it_value,
3515 arg2 + sizeof(struct target_timeval));
3519 ret = get_errno(setitimer(arg1, pvalue, &ovalue));
3520 if (!is_error(ret) && arg3) {
3521 host_to_target_timeval(arg3,
3522 &ovalue.it_interval);
3523 host_to_target_timeval(arg3 + sizeof(struct target_timeval),
3528 case TARGET_NR_getitimer:
3530 struct itimerval value;
3532 ret = get_errno(getitimer(arg1, &value));
3533 if (!is_error(ret) && arg2) {
3534 host_to_target_timeval(arg2,
3535 &value.it_interval);
3536 host_to_target_timeval(arg2 + sizeof(struct target_timeval),
3541 case TARGET_NR_stat:
3542 p = lock_user_string(arg1);
3543 ret = get_errno(stat(path(p), &st));
3544 unlock_user(p, arg1, 0);
3546 case TARGET_NR_lstat:
3547 p = lock_user_string(arg1);
3548 ret = get_errno(lstat(path(p), &st));
3549 unlock_user(p, arg1, 0);
3551 case TARGET_NR_fstat:
3553 ret = get_errno(fstat(arg1, &st));
3555 if (!is_error(ret)) {
3556 struct target_stat *target_st;
3558 lock_user_struct(target_st, arg2, 0);
3559 #if defined(TARGET_MIPS) || defined(TARGET_SPARC64)
3560 target_st->st_dev = tswap32(st.st_dev);
3562 target_st->st_dev = tswap16(st.st_dev);
3564 target_st->st_ino = tswapl(st.st_ino);
3565 #if defined(TARGET_PPC) || defined(TARGET_MIPS)
3566 target_st->st_mode = tswapl(st.st_mode); /* XXX: check this */
3567 target_st->st_uid = tswap32(st.st_uid);
3568 target_st->st_gid = tswap32(st.st_gid);
3569 #elif defined(TARGET_SPARC64)
3570 target_st->st_mode = tswap32(st.st_mode);
3571 target_st->st_uid = tswap32(st.st_uid);
3572 target_st->st_gid = tswap32(st.st_gid);
3574 target_st->st_mode = tswap16(st.st_mode);
3575 target_st->st_uid = tswap16(st.st_uid);
3576 target_st->st_gid = tswap16(st.st_gid);
3578 #if defined(TARGET_MIPS)
3579 /* If this is the same on PPC, then just merge w/ the above ifdef */
3580 target_st->st_nlink = tswapl(st.st_nlink);
3581 target_st->st_rdev = tswapl(st.st_rdev);
3582 #elif defined(TARGET_SPARC64)
3583 target_st->st_nlink = tswap32(st.st_nlink);
3584 target_st->st_rdev = tswap32(st.st_rdev);
3586 target_st->st_nlink = tswap16(st.st_nlink);
3587 target_st->st_rdev = tswap16(st.st_rdev);
3589 target_st->st_size = tswapl(st.st_size);
3590 target_st->st_blksize = tswapl(st.st_blksize);
3591 target_st->st_blocks = tswapl(st.st_blocks);
3592 target_st->target_st_atime = tswapl(st.st_atime);
3593 target_st->target_st_mtime = tswapl(st.st_mtime);
3594 target_st->target_st_ctime = tswapl(st.st_ctime);
3595 unlock_user_struct(target_st, arg2, 1);
3599 #ifdef TARGET_NR_olduname
3600 case TARGET_NR_olduname:
3603 #ifdef TARGET_NR_iopl
3604 case TARGET_NR_iopl:
3607 case TARGET_NR_vhangup:
3608 ret = get_errno(vhangup());
3610 #ifdef TARGET_NR_idle
3611 case TARGET_NR_idle:
3614 #ifdef TARGET_NR_syscall
3615 case TARGET_NR_syscall:
3616 ret = do_syscall(cpu_env,arg1 & 0xffff,arg2,arg3,arg4,arg5,arg6,0);
3619 case TARGET_NR_wait4:
3622 target_long status_ptr = arg2;
3623 struct rusage rusage, *rusage_ptr;
3624 target_ulong target_rusage = arg4;
3626 rusage_ptr = &rusage;
3629 ret = get_errno(wait4(arg1, &status, arg3, rusage_ptr));
3630 if (!is_error(ret)) {
3632 tputl(status_ptr, status);
3633 if (target_rusage) {
3634 host_to_target_rusage(target_rusage, &rusage);
3639 #ifdef TARGET_NR_swapoff
3640 case TARGET_NR_swapoff:
3641 p = lock_user_string(arg1);
3642 ret = get_errno(swapoff(p));
3643 unlock_user(p, arg1, 0);
3646 case TARGET_NR_sysinfo:
3648 struct target_sysinfo *target_value;
3649 struct sysinfo value;
3650 ret = get_errno(sysinfo(&value));
3651 if (!is_error(ret) && arg1)
3653 /* ??? __put_user is probably wrong. */
3654 lock_user_struct(target_value, arg1, 0);
3655 __put_user(value.uptime, &target_value->uptime);
3656 __put_user(value.loads[0], &target_value->loads[0]);
3657 __put_user(value.loads[1], &target_value->loads[1]);
3658 __put_user(value.loads[2], &target_value->loads[2]);
3659 __put_user(value.totalram, &target_value->totalram);
3660 __put_user(value.freeram, &target_value->freeram);
3661 __put_user(value.sharedram, &target_value->sharedram);
3662 __put_user(value.bufferram, &target_value->bufferram);
3663 __put_user(value.totalswap, &target_value->totalswap);
3664 __put_user(value.freeswap, &target_value->freeswap);
3665 __put_user(value.procs, &target_value->procs);
3666 __put_user(value.totalhigh, &target_value->totalhigh);
3667 __put_user(value.freehigh, &target_value->freehigh);
3668 __put_user(value.mem_unit, &target_value->mem_unit);
3669 unlock_user_struct(target_value, arg1, 1);
3673 #ifdef TARGET_NR_ipc
3675 ret = do_ipc(arg1, arg2, arg3, arg4, arg5, arg6);
3678 case TARGET_NR_fsync:
3679 ret = get_errno(fsync(arg1));
3681 case TARGET_NR_clone:
3682 ret = get_errno(do_fork(cpu_env, arg1, arg2));
3684 #ifdef __NR_exit_group
3685 /* new thread calls */
3686 case TARGET_NR_exit_group:
3687 gdb_exit(cpu_env, arg1);
3688 ret = get_errno(exit_group(arg1));
3691 case TARGET_NR_setdomainname:
3692 p = lock_user_string(arg1);
3693 ret = get_errno(setdomainname(p, arg2));
3694 unlock_user(p, arg1, 0);
3696 case TARGET_NR_uname:
3697 /* no need to transcode because we use the linux syscall */
3699 struct new_utsname * buf;
3701 lock_user_struct(buf, arg1, 0);
3702 ret = get_errno(sys_uname(buf));
3703 if (!is_error(ret)) {
3704 /* Overrite the native machine name with whatever is being
3706 strcpy (buf->machine, UNAME_MACHINE);
3707 /* Allow the user to override the reported release. */
3708 if (qemu_uname_release && *qemu_uname_release)
3709 strcpy (buf->release, qemu_uname_release);
3711 unlock_user_struct(buf, arg1, 1);
3715 case TARGET_NR_modify_ldt:
3716 ret = get_errno(do_modify_ldt(cpu_env, arg1, arg2, arg3));
3718 #if !defined(TARGET_X86_64)
3719 case TARGET_NR_vm86old:
3721 case TARGET_NR_vm86:
3722 ret = do_vm86(cpu_env, arg1, arg2);
3726 case TARGET_NR_adjtimex:
3728 #ifdef TARGET_NR_create_module
3729 case TARGET_NR_create_module:
3731 case TARGET_NR_init_module:
3732 case TARGET_NR_delete_module:
3733 #ifdef TARGET_NR_get_kernel_syms
3734 case TARGET_NR_get_kernel_syms:
3737 case TARGET_NR_quotactl:
3739 case TARGET_NR_getpgid:
3740 ret = get_errno(getpgid(arg1));
3742 case TARGET_NR_fchdir:
3743 ret = get_errno(fchdir(arg1));
3745 #ifdef TARGET_NR_bdflush /* not on x86_64 */
3746 case TARGET_NR_bdflush:
3749 #ifdef TARGET_NR_sysfs
3750 case TARGET_NR_sysfs:
3753 case TARGET_NR_personality:
3754 ret = get_errno(personality(arg1));
3756 #ifdef TARGET_NR_afs_syscall
3757 case TARGET_NR_afs_syscall:
3760 #ifdef TARGET_NR__llseek /* Not on alpha */
3761 case TARGET_NR__llseek:
3763 #if defined (__x86_64__)
3764 ret = get_errno(lseek(arg1, ((uint64_t )arg2 << 32) | arg3, arg5));
3768 ret = get_errno(_llseek(arg1, arg2, arg3, &res, arg5));
3774 case TARGET_NR_getdents:
3775 #if TARGET_LONG_SIZE != 4
3777 #warning not supported
3778 #elif TARGET_LONG_SIZE == 4 && HOST_LONG_SIZE == 8
3780 struct target_dirent *target_dirp;
3781 struct dirent *dirp;
3784 dirp = malloc(count);
3788 ret = get_errno(sys_getdents(arg1, dirp, count));
3789 if (!is_error(ret)) {
3791 struct target_dirent *tde;
3793 int reclen, treclen;
3794 int count1, tnamelen;
3798 target_dirp = lock_user(arg2, count, 0);
3801 reclen = de->d_reclen;
3802 treclen = reclen - (2 * (sizeof(long) - sizeof(target_long)));
3803 tde->d_reclen = tswap16(treclen);
3804 tde->d_ino = tswapl(de->d_ino);
3805 tde->d_off = tswapl(de->d_off);
3806 tnamelen = treclen - (2 * sizeof(target_long) + 2);
3809 /* XXX: may not be correct */
3810 strncpy(tde->d_name, de->d_name, tnamelen);
3811 de = (struct dirent *)((char *)de + reclen);
3813 tde = (struct target_dirent *)((char *)tde + treclen);
3818 unlock_user(target_dirp, arg2, ret);
3823 struct dirent *dirp;
3826 dirp = lock_user(arg2, count, 0);
3827 ret = get_errno(sys_getdents(arg1, dirp, count));
3828 if (!is_error(ret)) {
3834 reclen = de->d_reclen;
3837 de->d_reclen = tswap16(reclen);
3838 tswapls(&de->d_ino);
3839 tswapls(&de->d_off);
3840 de = (struct dirent *)((char *)de + reclen);
3844 unlock_user(dirp, arg2, ret);
3848 #ifdef TARGET_NR_getdents64
3849 case TARGET_NR_getdents64:
3851 struct dirent64 *dirp;
3853 dirp = lock_user(arg2, count, 0);
3854 ret = get_errno(sys_getdents64(arg1, dirp, count));
3855 if (!is_error(ret)) {
3856 struct dirent64 *de;
3861 reclen = de->d_reclen;
3864 de->d_reclen = tswap16(reclen);
3865 tswap64s(&de->d_ino);
3866 tswap64s(&de->d_off);
3867 de = (struct dirent64 *)((char *)de + reclen);
3871 unlock_user(dirp, arg2, ret);
3874 #endif /* TARGET_NR_getdents64 */
3875 #ifdef TARGET_NR__newselect
3876 case TARGET_NR__newselect:
3877 ret = do_select(arg1, arg2, arg3, arg4, arg5);
3880 #ifdef TARGET_NR_poll
3881 case TARGET_NR_poll:
3883 struct target_pollfd *target_pfd;
3884 unsigned int nfds = arg2;
3889 target_pfd = lock_user(arg1, sizeof(struct target_pollfd) * nfds, 1);
3890 pfd = alloca(sizeof(struct pollfd) * nfds);
3891 for(i = 0; i < nfds; i++) {
3892 pfd[i].fd = tswap32(target_pfd[i].fd);
3893 pfd[i].events = tswap16(target_pfd[i].events);
3895 ret = get_errno(poll(pfd, nfds, timeout));
3896 if (!is_error(ret)) {
3897 for(i = 0; i < nfds; i++) {
3898 target_pfd[i].revents = tswap16(pfd[i].revents);
3900 ret += nfds * (sizeof(struct target_pollfd)
3901 - sizeof(struct pollfd));
3903 unlock_user(target_pfd, arg1, ret);
3907 case TARGET_NR_flock:
3908 /* NOTE: the flock constant seems to be the same for every
3910 ret = get_errno(flock(arg1, arg2));
3912 case TARGET_NR_readv:
3917 vec = alloca(count * sizeof(struct iovec));
3918 lock_iovec(vec, arg2, count, 0);
3919 ret = get_errno(readv(arg1, vec, count));
3920 unlock_iovec(vec, arg2, count, 1);
3923 case TARGET_NR_writev:
3928 vec = alloca(count * sizeof(struct iovec));
3929 lock_iovec(vec, arg2, count, 1);
3930 ret = get_errno(writev(arg1, vec, count));
3931 unlock_iovec(vec, arg2, count, 0);
3934 case TARGET_NR_getsid:
3935 ret = get_errno(getsid(arg1));
3937 #if defined(TARGET_NR_fdatasync) /* Not on alpha (osf_datasync ?) */
3938 case TARGET_NR_fdatasync:
3939 ret = get_errno(fdatasync(arg1));
3942 case TARGET_NR__sysctl:
3943 /* We don't implement this, but ENODIR is always a safe
3946 case TARGET_NR_sched_setparam:
3948 struct sched_param *target_schp;
3949 struct sched_param schp;
3951 lock_user_struct(target_schp, arg2, 1);
3952 schp.sched_priority = tswap32(target_schp->sched_priority);
3953 unlock_user_struct(target_schp, arg2, 0);
3954 ret = get_errno(sched_setparam(arg1, &schp));
3957 case TARGET_NR_sched_getparam:
3959 struct sched_param *target_schp;
3960 struct sched_param schp;
3961 ret = get_errno(sched_getparam(arg1, &schp));
3962 if (!is_error(ret)) {
3963 lock_user_struct(target_schp, arg2, 0);
3964 target_schp->sched_priority = tswap32(schp.sched_priority);
3965 unlock_user_struct(target_schp, arg2, 1);
3969 case TARGET_NR_sched_setscheduler:
3971 struct sched_param *target_schp;
3972 struct sched_param schp;
3973 lock_user_struct(target_schp, arg3, 1);
3974 schp.sched_priority = tswap32(target_schp->sched_priority);
3975 unlock_user_struct(target_schp, arg3, 0);
3976 ret = get_errno(sched_setscheduler(arg1, arg2, &schp));
3979 case TARGET_NR_sched_getscheduler:
3980 ret = get_errno(sched_getscheduler(arg1));
3982 case TARGET_NR_sched_yield:
3983 ret = get_errno(sched_yield());
3985 case TARGET_NR_sched_get_priority_max:
3986 ret = get_errno(sched_get_priority_max(arg1));
3988 case TARGET_NR_sched_get_priority_min:
3989 ret = get_errno(sched_get_priority_min(arg1));
3991 case TARGET_NR_sched_rr_get_interval:
3994 ret = get_errno(sched_rr_get_interval(arg1, &ts));
3995 if (!is_error(ret)) {
3996 host_to_target_timespec(arg2, &ts);
4000 case TARGET_NR_nanosleep:
4002 struct timespec req, rem;
4003 target_to_host_timespec(&req, arg1);
4004 ret = get_errno(nanosleep(&req, &rem));
4005 if (is_error(ret) && arg2) {
4006 host_to_target_timespec(arg2, &rem);
4010 #ifdef TARGET_NR_query_module
4011 case TARGET_NR_query_module:
4014 #ifdef TARGET_NR_nfsservctl
4015 case TARGET_NR_nfsservctl:
4018 case TARGET_NR_prctl:
4021 case PR_GET_PDEATHSIG:
4024 ret = get_errno(prctl(arg1, &deathsig, arg3, arg4, arg5));
4025 if (!is_error(ret) && arg2)
4026 tput32(arg2, deathsig);
4030 ret = get_errno(prctl(arg1, arg2, arg3, arg4, arg5));
4034 #ifdef TARGET_NR_pread
4035 case TARGET_NR_pread:
4036 page_unprotect_range(arg2, arg3);
4037 p = lock_user(arg2, arg3, 0);
4038 ret = get_errno(pread(arg1, p, arg3, arg4));
4039 unlock_user(p, arg2, ret);
4041 case TARGET_NR_pwrite:
4042 p = lock_user(arg2, arg3, 1);
4043 ret = get_errno(pwrite(arg1, p, arg3, arg4));
4044 unlock_user(p, arg2, 0);
4047 case TARGET_NR_getcwd:
4048 p = lock_user(arg1, arg2, 0);
4049 ret = get_errno(sys_getcwd1(p, arg2));
4050 unlock_user(p, arg1, ret);
4052 case TARGET_NR_capget:
4054 case TARGET_NR_capset:
4056 case TARGET_NR_sigaltstack:
4058 case TARGET_NR_sendfile:
4060 #ifdef TARGET_NR_getpmsg
4061 case TARGET_NR_getpmsg:
4064 #ifdef TARGET_NR_putpmsg
4065 case TARGET_NR_putpmsg:
4068 #ifdef TARGET_NR_vfork
4069 case TARGET_NR_vfork:
4070 ret = get_errno(do_fork(cpu_env, CLONE_VFORK | CLONE_VM | SIGCHLD, 0));
4073 #ifdef TARGET_NR_ugetrlimit
4074 case TARGET_NR_ugetrlimit:
4077 ret = get_errno(getrlimit(arg1, &rlim));
4078 if (!is_error(ret)) {
4079 struct target_rlimit *target_rlim;
4080 lock_user_struct(target_rlim, arg2, 0);
4081 target_rlim->rlim_cur = tswapl(rlim.rlim_cur);
4082 target_rlim->rlim_max = tswapl(rlim.rlim_max);
4083 unlock_user_struct(target_rlim, arg2, 1);
4088 #ifdef TARGET_NR_truncate64
4089 case TARGET_NR_truncate64:
4090 p = lock_user_string(arg1);
4091 ret = target_truncate64(cpu_env, p, arg2, arg3, arg4);
4092 unlock_user(p, arg1, 0);
4095 #ifdef TARGET_NR_ftruncate64
4096 case TARGET_NR_ftruncate64:
4097 ret = target_ftruncate64(cpu_env, arg1, arg2, arg3, arg4);
4100 #ifdef TARGET_NR_stat64
4101 case TARGET_NR_stat64:
4102 p = lock_user_string(arg1);
4103 ret = get_errno(stat(path(p), &st));
4104 unlock_user(p, arg1, 0);
4107 #ifdef TARGET_NR_lstat64
4108 case TARGET_NR_lstat64:
4109 p = lock_user_string(arg1);
4110 ret = get_errno(lstat(path(p), &st));
4111 unlock_user(p, arg1, 0);
4114 #ifdef TARGET_NR_fstat64
4115 case TARGET_NR_fstat64:
4117 ret = get_errno(fstat(arg1, &st));
4119 if (!is_error(ret)) {
4121 if (((CPUARMState *)cpu_env)->eabi) {
4122 struct target_eabi_stat64 *target_st;
4123 lock_user_struct(target_st, arg2, 1);
4124 memset(target_st, 0, sizeof(struct target_eabi_stat64));
4125 /* put_user is probably wrong. */
4126 put_user(st.st_dev, &target_st->st_dev);
4127 put_user(st.st_ino, &target_st->st_ino);
4128 #ifdef TARGET_STAT64_HAS_BROKEN_ST_INO
4129 put_user(st.st_ino, &target_st->__st_ino);
4131 put_user(st.st_mode, &target_st->st_mode);
4132 put_user(st.st_nlink, &target_st->st_nlink);
4133 put_user(st.st_uid, &target_st->st_uid);
4134 put_user(st.st_gid, &target_st->st_gid);
4135 put_user(st.st_rdev, &target_st->st_rdev);
4136 /* XXX: better use of kernel struct */
4137 put_user(st.st_size, &target_st->st_size);
4138 put_user(st.st_blksize, &target_st->st_blksize);
4139 put_user(st.st_blocks, &target_st->st_blocks);
4140 put_user(st.st_atime, &target_st->target_st_atime);
4141 put_user(st.st_mtime, &target_st->target_st_mtime);
4142 put_user(st.st_ctime, &target_st->target_st_ctime);
4143 unlock_user_struct(target_st, arg2, 0);
4147 struct target_stat64 *target_st;
4148 lock_user_struct(target_st, arg2, 1);
4149 memset(target_st, 0, sizeof(struct target_stat64));
4150 /* ??? put_user is probably wrong. */
4151 put_user(st.st_dev, &target_st->st_dev);
4152 put_user(st.st_ino, &target_st->st_ino);
4153 #ifdef TARGET_STAT64_HAS_BROKEN_ST_INO
4154 put_user(st.st_ino, &target_st->__st_ino);
4156 put_user(st.st_mode, &target_st->st_mode);
4157 put_user(st.st_nlink, &target_st->st_nlink);
4158 put_user(st.st_uid, &target_st->st_uid);
4159 put_user(st.st_gid, &target_st->st_gid);
4160 put_user(st.st_rdev, &target_st->st_rdev);
4161 /* XXX: better use of kernel struct */
4162 put_user(st.st_size, &target_st->st_size);
4163 put_user(st.st_blksize, &target_st->st_blksize);
4164 put_user(st.st_blocks, &target_st->st_blocks);
4165 put_user(st.st_atime, &target_st->target_st_atime);
4166 put_user(st.st_mtime, &target_st->target_st_mtime);
4167 put_user(st.st_ctime, &target_st->target_st_ctime);
4168 unlock_user_struct(target_st, arg2, 0);
4175 case TARGET_NR_lchown:
4176 p = lock_user_string(arg1);
4177 ret = get_errno(lchown(p, low2highuid(arg2), low2highgid(arg3)));
4178 unlock_user(p, arg1, 0);
4180 case TARGET_NR_getuid:
4181 ret = get_errno(high2lowuid(getuid()));
4183 case TARGET_NR_getgid:
4184 ret = get_errno(high2lowgid(getgid()));
4186 case TARGET_NR_geteuid:
4187 ret = get_errno(high2lowuid(geteuid()));
4189 case TARGET_NR_getegid:
4190 ret = get_errno(high2lowgid(getegid()));
4192 case TARGET_NR_setreuid:
4193 ret = get_errno(setreuid(low2highuid(arg1), low2highuid(arg2)));
4195 case TARGET_NR_setregid:
4196 ret = get_errno(setregid(low2highgid(arg1), low2highgid(arg2)));
4198 case TARGET_NR_getgroups:
4200 int gidsetsize = arg1;
4201 uint16_t *target_grouplist;
4205 grouplist = alloca(gidsetsize * sizeof(gid_t));
4206 ret = get_errno(getgroups(gidsetsize, grouplist));
4207 if (!is_error(ret)) {
4208 target_grouplist = lock_user(arg2, gidsetsize * 2, 0);
4209 for(i = 0;i < gidsetsize; i++)
4210 target_grouplist[i] = tswap16(grouplist[i]);
4211 unlock_user(target_grouplist, arg2, gidsetsize * 2);
4215 case TARGET_NR_setgroups:
4217 int gidsetsize = arg1;
4218 uint16_t *target_grouplist;
4222 grouplist = alloca(gidsetsize * sizeof(gid_t));
4223 target_grouplist = lock_user(arg2, gidsetsize * 2, 1);
4224 for(i = 0;i < gidsetsize; i++)
4225 grouplist[i] = tswap16(target_grouplist[i]);
4226 unlock_user(target_grouplist, arg2, 0);
4227 ret = get_errno(setgroups(gidsetsize, grouplist));
4230 case TARGET_NR_fchown:
4231 ret = get_errno(fchown(arg1, low2highuid(arg2), low2highgid(arg3)));
4233 #ifdef TARGET_NR_setresuid
4234 case TARGET_NR_setresuid:
4235 ret = get_errno(setresuid(low2highuid(arg1),
4237 low2highuid(arg3)));
4240 #ifdef TARGET_NR_getresuid
4241 case TARGET_NR_getresuid:
4243 uid_t ruid, euid, suid;
4244 ret = get_errno(getresuid(&ruid, &euid, &suid));
4245 if (!is_error(ret)) {
4246 tput16(arg1, tswap16(high2lowuid(ruid)));
4247 tput16(arg2, tswap16(high2lowuid(euid)));
4248 tput16(arg3, tswap16(high2lowuid(suid)));
4253 #ifdef TARGET_NR_getresgid
4254 case TARGET_NR_setresgid:
4255 ret = get_errno(setresgid(low2highgid(arg1),
4257 low2highgid(arg3)));
4260 #ifdef TARGET_NR_getresgid
4261 case TARGET_NR_getresgid:
4263 gid_t rgid, egid, sgid;
4264 ret = get_errno(getresgid(&rgid, &egid, &sgid));
4265 if (!is_error(ret)) {
4266 tput16(arg1, tswap16(high2lowgid(rgid)));
4267 tput16(arg2, tswap16(high2lowgid(egid)));
4268 tput16(arg3, tswap16(high2lowgid(sgid)));
4273 case TARGET_NR_chown:
4274 p = lock_user_string(arg1);
4275 ret = get_errno(chown(p, low2highuid(arg2), low2highgid(arg3)));
4276 unlock_user(p, arg1, 0);
4278 case TARGET_NR_setuid:
4279 ret = get_errno(setuid(low2highuid(arg1)));
4281 case TARGET_NR_setgid:
4282 ret = get_errno(setgid(low2highgid(arg1)));
4284 case TARGET_NR_setfsuid:
4285 ret = get_errno(setfsuid(arg1));
4287 case TARGET_NR_setfsgid:
4288 ret = get_errno(setfsgid(arg1));
4290 #endif /* USE_UID16 */
4292 #ifdef TARGET_NR_lchown32
4293 case TARGET_NR_lchown32:
4294 p = lock_user_string(arg1);
4295 ret = get_errno(lchown(p, arg2, arg3));
4296 unlock_user(p, arg1, 0);
4299 #ifdef TARGET_NR_getuid32
4300 case TARGET_NR_getuid32:
4301 ret = get_errno(getuid());
4304 #ifdef TARGET_NR_getgid32
4305 case TARGET_NR_getgid32:
4306 ret = get_errno(getgid());
4309 #ifdef TARGET_NR_geteuid32
4310 case TARGET_NR_geteuid32:
4311 ret = get_errno(geteuid());
4314 #ifdef TARGET_NR_getegid32
4315 case TARGET_NR_getegid32:
4316 ret = get_errno(getegid());
4319 #ifdef TARGET_NR_setreuid32
4320 case TARGET_NR_setreuid32:
4321 ret = get_errno(setreuid(arg1, arg2));
4324 #ifdef TARGET_NR_setregid32
4325 case TARGET_NR_setregid32:
4326 ret = get_errno(setregid(arg1, arg2));
4329 #ifdef TARGET_NR_getgroups32
4330 case TARGET_NR_getgroups32:
4332 int gidsetsize = arg1;
4333 uint32_t *target_grouplist;
4337 grouplist = alloca(gidsetsize * sizeof(gid_t));
4338 ret = get_errno(getgroups(gidsetsize, grouplist));
4339 if (!is_error(ret)) {
4340 target_grouplist = lock_user(arg2, gidsetsize * 4, 0);
4341 for(i = 0;i < gidsetsize; i++)
4342 target_grouplist[i] = tswap32(grouplist[i]);
4343 unlock_user(target_grouplist, arg2, gidsetsize * 4);
4348 #ifdef TARGET_NR_setgroups32
4349 case TARGET_NR_setgroups32:
4351 int gidsetsize = arg1;
4352 uint32_t *target_grouplist;
4356 grouplist = alloca(gidsetsize * sizeof(gid_t));
4357 target_grouplist = lock_user(arg2, gidsetsize * 4, 1);
4358 for(i = 0;i < gidsetsize; i++)
4359 grouplist[i] = tswap32(target_grouplist[i]);
4360 unlock_user(target_grouplist, arg2, 0);
4361 ret = get_errno(setgroups(gidsetsize, grouplist));
4365 #ifdef TARGET_NR_fchown32
4366 case TARGET_NR_fchown32:
4367 ret = get_errno(fchown(arg1, arg2, arg3));
4370 #ifdef TARGET_NR_setresuid32
4371 case TARGET_NR_setresuid32:
4372 ret = get_errno(setresuid(arg1, arg2, arg3));
4375 #ifdef TARGET_NR_getresuid32
4376 case TARGET_NR_getresuid32:
4378 uid_t ruid, euid, suid;
4379 ret = get_errno(getresuid(&ruid, &euid, &suid));
4380 if (!is_error(ret)) {
4381 tput32(arg1, tswap32(ruid));
4382 tput32(arg2, tswap32(euid));
4383 tput32(arg3, tswap32(suid));
4388 #ifdef TARGET_NR_setresgid32
4389 case TARGET_NR_setresgid32:
4390 ret = get_errno(setresgid(arg1, arg2, arg3));
4393 #ifdef TARGET_NR_getresgid32
4394 case TARGET_NR_getresgid32:
4396 gid_t rgid, egid, sgid;
4397 ret = get_errno(getresgid(&rgid, &egid, &sgid));
4398 if (!is_error(ret)) {
4399 tput32(arg1, tswap32(rgid));
4400 tput32(arg2, tswap32(egid));
4401 tput32(arg3, tswap32(sgid));
4406 #ifdef TARGET_NR_chown32
4407 case TARGET_NR_chown32:
4408 p = lock_user_string(arg1);
4409 ret = get_errno(chown(p, arg2, arg3));
4410 unlock_user(p, arg1, 0);
4413 #ifdef TARGET_NR_setuid32
4414 case TARGET_NR_setuid32:
4415 ret = get_errno(setuid(arg1));
4418 #ifdef TARGET_NR_setgid32
4419 case TARGET_NR_setgid32:
4420 ret = get_errno(setgid(arg1));
4423 #ifdef TARGET_NR_setfsuid32
4424 case TARGET_NR_setfsuid32:
4425 ret = get_errno(setfsuid(arg1));
4428 #ifdef TARGET_NR_setfsgid32
4429 case TARGET_NR_setfsgid32:
4430 ret = get_errno(setfsgid(arg1));
4434 case TARGET_NR_pivot_root:
4436 #ifdef TARGET_NR_mincore
4437 case TARGET_NR_mincore:
4440 #ifdef TARGET_NR_madvise
4441 case TARGET_NR_madvise:
4442 /* A straight passthrough may not be safe because qemu sometimes
4443 turns private flie-backed mappings into anonymous mappings.
4444 This will break MADV_DONTNEED.
4445 This is a hint, so ignoring and returning success is ok. */
4449 #if TARGET_LONG_BITS == 32
4450 case TARGET_NR_fcntl64:
4454 struct target_flock64 *target_fl;
4456 struct target_eabi_flock64 *target_efl;
4460 case TARGET_F_GETLK64:
4463 case TARGET_F_SETLK64:
4466 case TARGET_F_SETLKW64:
4475 case TARGET_F_GETLK64:
4477 if (((CPUARMState *)cpu_env)->eabi) {
4478 lock_user_struct(target_efl, arg3, 1);
4479 fl.l_type = tswap16(target_efl->l_type);
4480 fl.l_whence = tswap16(target_efl->l_whence);
4481 fl.l_start = tswap64(target_efl->l_start);
4482 fl.l_len = tswap64(target_efl->l_len);
4483 fl.l_pid = tswapl(target_efl->l_pid);
4484 unlock_user_struct(target_efl, arg3, 0);
4488 lock_user_struct(target_fl, arg3, 1);
4489 fl.l_type = tswap16(target_fl->l_type);
4490 fl.l_whence = tswap16(target_fl->l_whence);
4491 fl.l_start = tswap64(target_fl->l_start);
4492 fl.l_len = tswap64(target_fl->l_len);
4493 fl.l_pid = tswapl(target_fl->l_pid);
4494 unlock_user_struct(target_fl, arg3, 0);
4496 ret = get_errno(fcntl(arg1, cmd, &fl));
4499 if (((CPUARMState *)cpu_env)->eabi) {
4500 lock_user_struct(target_efl, arg3, 0);
4501 target_efl->l_type = tswap16(fl.l_type);
4502 target_efl->l_whence = tswap16(fl.l_whence);
4503 target_efl->l_start = tswap64(fl.l_start);
4504 target_efl->l_len = tswap64(fl.l_len);
4505 target_efl->l_pid = tswapl(fl.l_pid);
4506 unlock_user_struct(target_efl, arg3, 1);
4510 lock_user_struct(target_fl, arg3, 0);
4511 target_fl->l_type = tswap16(fl.l_type);
4512 target_fl->l_whence = tswap16(fl.l_whence);
4513 target_fl->l_start = tswap64(fl.l_start);
4514 target_fl->l_len = tswap64(fl.l_len);
4515 target_fl->l_pid = tswapl(fl.l_pid);
4516 unlock_user_struct(target_fl, arg3, 1);
4521 case TARGET_F_SETLK64:
4522 case TARGET_F_SETLKW64:
4524 if (((CPUARMState *)cpu_env)->eabi) {
4525 lock_user_struct(target_efl, arg3, 1);
4526 fl.l_type = tswap16(target_efl->l_type);
4527 fl.l_whence = tswap16(target_efl->l_whence);
4528 fl.l_start = tswap64(target_efl->l_start);
4529 fl.l_len = tswap64(target_efl->l_len);
4530 fl.l_pid = tswapl(target_efl->l_pid);
4531 unlock_user_struct(target_efl, arg3, 0);
4535 lock_user_struct(target_fl, arg3, 1);
4536 fl.l_type = tswap16(target_fl->l_type);
4537 fl.l_whence = tswap16(target_fl->l_whence);
4538 fl.l_start = tswap64(target_fl->l_start);
4539 fl.l_len = tswap64(target_fl->l_len);
4540 fl.l_pid = tswapl(target_fl->l_pid);
4541 unlock_user_struct(target_fl, arg3, 0);
4543 ret = get_errno(fcntl(arg1, cmd, &fl));
4546 ret = get_errno(do_fcntl(arg1, cmd, arg3));
4552 #ifdef TARGET_NR_cacheflush
4553 case TARGET_NR_cacheflush:
4554 /* self-modifying code is handled automatically, so nothing needed */
4558 #ifdef TARGET_NR_security
4559 case TARGET_NR_security:
4562 #ifdef TARGET_NR_getpagesize
4563 case TARGET_NR_getpagesize:
4564 ret = TARGET_PAGE_SIZE;
4567 case TARGET_NR_gettid:
4568 ret = get_errno(gettid());
4570 #ifdef TARGET_NR_readahead
4571 case TARGET_NR_readahead:
4574 #ifdef TARGET_NR_setxattr
4575 case TARGET_NR_setxattr:
4576 case TARGET_NR_lsetxattr:
4577 case TARGET_NR_fsetxattr:
4578 case TARGET_NR_getxattr:
4579 case TARGET_NR_lgetxattr:
4580 case TARGET_NR_fgetxattr:
4581 case TARGET_NR_listxattr:
4582 case TARGET_NR_llistxattr:
4583 case TARGET_NR_flistxattr:
4584 case TARGET_NR_removexattr:
4585 case TARGET_NR_lremovexattr:
4586 case TARGET_NR_fremovexattr:
4587 goto unimplemented_nowarn;
4589 #ifdef TARGET_NR_set_thread_area
4590 case TARGET_NR_set_thread_area:
4592 ((CPUMIPSState *) cpu_env)->tls_value = arg1;
4596 goto unimplemented_nowarn;
4599 #ifdef TARGET_NR_get_thread_area
4600 case TARGET_NR_get_thread_area:
4601 goto unimplemented_nowarn;
4603 #ifdef TARGET_NR_getdomainname
4604 case TARGET_NR_getdomainname:
4605 goto unimplemented_nowarn;
4608 #ifdef TARGET_NR_clock_gettime
4609 case TARGET_NR_clock_gettime:
4612 ret = get_errno(clock_gettime(arg1, &ts));
4613 if (!is_error(ret)) {
4614 host_to_target_timespec(arg2, &ts);
4619 #ifdef TARGET_NR_clock_getres
4620 case TARGET_NR_clock_getres:
4623 ret = get_errno(clock_getres(arg1, &ts));
4624 if (!is_error(ret)) {
4625 host_to_target_timespec(arg2, &ts);
4631 #if defined(TARGET_NR_set_tid_address) && defined(__NR_set_tid_address)
4632 case TARGET_NR_set_tid_address:
4633 ret = get_errno(set_tid_address((int *) arg1));
4637 #ifdef TARGET_NR_tkill
4638 case TARGET_NR_tkill:
4639 ret = get_errno(sys_tkill((int)arg1, (int)arg2));
4643 #ifdef TARGET_NR_tgkill
4644 case TARGET_NR_tgkill:
4645 ret = get_errno(sys_tgkill((int)arg1, (int)arg2, (int)arg3));
4649 #ifdef TARGET_NR_set_robust_list
4650 case TARGET_NR_set_robust_list:
4651 goto unimplemented_nowarn;
4656 gemu_log("qemu: Unsupported syscall: %d\n", num);
4657 #if defined(TARGET_NR_setxattr) || defined(TARGET_NR_get_thread_area) || defined(TARGET_NR_getdomainname) || defined(TARGET_NR_set_robust_list)
4658 unimplemented_nowarn:
4665 gemu_log(" = %ld\n", ret);