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_openat __NR_openat
146 #define __NR_sys_rt_sigqueueinfo __NR_rt_sigqueueinfo
147 #define __NR_sys_syslog __NR_syslog
148 #define __NR_sys_tgkill __NR_tgkill
149 #define __NR_sys_tkill __NR_tkill
151 #if defined(__alpha__) || defined (__ia64__) || defined(__x86_64__)
152 #define __NR__llseek __NR_lseek
156 _syscall0(int, gettid)
158 static int gettid(void) {
162 _syscall1(int,sys_uname,struct new_utsname *,buf)
163 _syscall2(int,sys_getcwd1,char *,buf,size_t,size)
164 _syscall3(int, sys_getdents, uint, fd, struct dirent *, dirp, uint, count);
165 #if defined(TARGET_NR_getdents64) && defined(__NR_getdents64)
166 _syscall3(int, sys_getdents64, uint, fd, struct dirent64 *, dirp, uint, count);
168 _syscall5(int, _llseek, uint, fd, ulong, hi, ulong, lo,
169 loff_t *, res, uint, wh);
170 #if defined(TARGET_NR_openat) && defined(__NR_openat)
171 _syscall4(int,sys_openat,int,dirfd,const char *,pathname,int,flags,mode_t,mode)
173 _syscall3(int,sys_rt_sigqueueinfo,int,pid,int,sig,siginfo_t *,uinfo)
174 _syscall3(int,sys_syslog,int,type,char*,bufp,int,len)
175 #if defined(TARGET_NR_tgkill) && defined(__NR_tgkill)
176 _syscall3(int,sys_tgkill,int,tgid,int,pid,int,sig)
178 #if defined(TARGET_NR_tkill) && defined(__NR_tkill)
179 _syscall2(int,sys_tkill,int,tid,int,sig)
181 #ifdef __NR_exit_group
182 _syscall1(int,exit_group,int,error_code)
184 #if defined(TARGET_NR_set_tid_address) && defined(__NR_set_tid_address)
185 _syscall1(int,set_tid_address,int *,tidptr)
188 extern int personality(int);
189 extern int flock(int, int);
190 extern int setfsuid(int);
191 extern int setfsgid(int);
192 extern int setresuid(uid_t, uid_t, uid_t);
193 extern int getresuid(uid_t *, uid_t *, uid_t *);
194 extern int setresgid(gid_t, gid_t, gid_t);
195 extern int getresgid(gid_t *, gid_t *, gid_t *);
196 extern int setgroups(int, gid_t *);
199 * This list is the union of errno values overridden in asm-<arch>/errno.h
200 * minus the errnos that are not actually generic to all archs.
202 static uint16_t host_to_target_errno_table[1200] = {
203 [EIDRM] = TARGET_EIDRM,
204 [ECHRNG] = TARGET_ECHRNG,
205 [EL2NSYNC] = TARGET_EL2NSYNC,
206 [EL3HLT] = TARGET_EL3HLT,
207 [EL3RST] = TARGET_EL3RST,
208 [ELNRNG] = TARGET_ELNRNG,
209 [EUNATCH] = TARGET_EUNATCH,
210 [ENOCSI] = TARGET_ENOCSI,
211 [EL2HLT] = TARGET_EL2HLT,
212 [EDEADLK] = TARGET_EDEADLK,
213 [ENOLCK] = TARGET_ENOLCK,
214 [EBADE] = TARGET_EBADE,
215 [EBADR] = TARGET_EBADR,
216 [EXFULL] = TARGET_EXFULL,
217 [ENOANO] = TARGET_ENOANO,
218 [EBADRQC] = TARGET_EBADRQC,
219 [EBADSLT] = TARGET_EBADSLT,
220 [EBFONT] = TARGET_EBFONT,
221 [ENOSTR] = TARGET_ENOSTR,
222 [ENODATA] = TARGET_ENODATA,
223 [ETIME] = TARGET_ETIME,
224 [ENOSR] = TARGET_ENOSR,
225 [ENONET] = TARGET_ENONET,
226 [ENOPKG] = TARGET_ENOPKG,
227 [EREMOTE] = TARGET_EREMOTE,
228 [ENOLINK] = TARGET_ENOLINK,
229 [EADV] = TARGET_EADV,
230 [ESRMNT] = TARGET_ESRMNT,
231 [ECOMM] = TARGET_ECOMM,
232 [EPROTO] = TARGET_EPROTO,
233 [EDOTDOT] = TARGET_EDOTDOT,
234 [EMULTIHOP] = TARGET_EMULTIHOP,
235 [EBADMSG] = TARGET_EBADMSG,
236 [ENAMETOOLONG] = TARGET_ENAMETOOLONG,
237 [EOVERFLOW] = TARGET_EOVERFLOW,
238 [ENOTUNIQ] = TARGET_ENOTUNIQ,
239 [EBADFD] = TARGET_EBADFD,
240 [EREMCHG] = TARGET_EREMCHG,
241 [ELIBACC] = TARGET_ELIBACC,
242 [ELIBBAD] = TARGET_ELIBBAD,
243 [ELIBSCN] = TARGET_ELIBSCN,
244 [ELIBMAX] = TARGET_ELIBMAX,
245 [ELIBEXEC] = TARGET_ELIBEXEC,
246 [EILSEQ] = TARGET_EILSEQ,
247 [ENOSYS] = TARGET_ENOSYS,
248 [ELOOP] = TARGET_ELOOP,
249 [ERESTART] = TARGET_ERESTART,
250 [ESTRPIPE] = TARGET_ESTRPIPE,
251 [ENOTEMPTY] = TARGET_ENOTEMPTY,
252 [EUSERS] = TARGET_EUSERS,
253 [ENOTSOCK] = TARGET_ENOTSOCK,
254 [EDESTADDRREQ] = TARGET_EDESTADDRREQ,
255 [EMSGSIZE] = TARGET_EMSGSIZE,
256 [EPROTOTYPE] = TARGET_EPROTOTYPE,
257 [ENOPROTOOPT] = TARGET_ENOPROTOOPT,
258 [EPROTONOSUPPORT] = TARGET_EPROTONOSUPPORT,
259 [ESOCKTNOSUPPORT] = TARGET_ESOCKTNOSUPPORT,
260 [EOPNOTSUPP] = TARGET_EOPNOTSUPP,
261 [EPFNOSUPPORT] = TARGET_EPFNOSUPPORT,
262 [EAFNOSUPPORT] = TARGET_EAFNOSUPPORT,
263 [EADDRINUSE] = TARGET_EADDRINUSE,
264 [EADDRNOTAVAIL] = TARGET_EADDRNOTAVAIL,
265 [ENETDOWN] = TARGET_ENETDOWN,
266 [ENETUNREACH] = TARGET_ENETUNREACH,
267 [ENETRESET] = TARGET_ENETRESET,
268 [ECONNABORTED] = TARGET_ECONNABORTED,
269 [ECONNRESET] = TARGET_ECONNRESET,
270 [ENOBUFS] = TARGET_ENOBUFS,
271 [EISCONN] = TARGET_EISCONN,
272 [ENOTCONN] = TARGET_ENOTCONN,
273 [EUCLEAN] = TARGET_EUCLEAN,
274 [ENOTNAM] = TARGET_ENOTNAM,
275 [ENAVAIL] = TARGET_ENAVAIL,
276 [EISNAM] = TARGET_EISNAM,
277 [EREMOTEIO] = TARGET_EREMOTEIO,
278 [ESHUTDOWN] = TARGET_ESHUTDOWN,
279 [ETOOMANYREFS] = TARGET_ETOOMANYREFS,
280 [ETIMEDOUT] = TARGET_ETIMEDOUT,
281 [ECONNREFUSED] = TARGET_ECONNREFUSED,
282 [EHOSTDOWN] = TARGET_EHOSTDOWN,
283 [EHOSTUNREACH] = TARGET_EHOSTUNREACH,
284 [EALREADY] = TARGET_EALREADY,
285 [EINPROGRESS] = TARGET_EINPROGRESS,
286 [ESTALE] = TARGET_ESTALE,
287 [ECANCELED] = TARGET_ECANCELED,
288 [ENOMEDIUM] = TARGET_ENOMEDIUM,
289 [EMEDIUMTYPE] = TARGET_EMEDIUMTYPE,
291 [ENOKEY] = TARGET_ENOKEY,
294 [EKEYEXPIRED] = TARGET_EKEYEXPIRED,
297 [EKEYREVOKED] = TARGET_EKEYREVOKED,
300 [EKEYREJECTED] = TARGET_EKEYREJECTED,
303 [EOWNERDEAD] = TARGET_EOWNERDEAD,
305 #ifdef ENOTRECOVERABLE
306 [ENOTRECOVERABLE] = TARGET_ENOTRECOVERABLE,
310 static inline int host_to_target_errno(int err)
312 if(host_to_target_errno_table[err])
313 return host_to_target_errno_table[err];
317 static inline long get_errno(long ret)
320 return -host_to_target_errno(errno);
325 static inline int is_error(long ret)
327 return (unsigned long)ret >= (unsigned long)(-4096);
330 static target_ulong target_brk;
331 static target_ulong target_original_brk;
333 void target_set_brk(target_ulong new_brk)
335 target_original_brk = target_brk = HOST_PAGE_ALIGN(new_brk);
338 long do_brk(target_ulong new_brk)
340 target_ulong brk_page;
346 if (new_brk < target_original_brk)
349 brk_page = HOST_PAGE_ALIGN(target_brk);
351 /* If the new brk is less than this, set it and we're done... */
352 if (new_brk < brk_page) {
353 target_brk = new_brk;
357 /* We need to allocate more memory after the brk... */
358 new_alloc_size = HOST_PAGE_ALIGN(new_brk - brk_page + 1);
359 mapped_addr = get_errno(target_mmap(brk_page, new_alloc_size,
360 PROT_READ|PROT_WRITE,
361 MAP_ANON|MAP_FIXED|MAP_PRIVATE, 0, 0));
362 if (is_error(mapped_addr)) {
365 target_brk = new_brk;
370 static inline fd_set *target_to_host_fds(fd_set *fds,
371 target_long *target_fds, int n)
373 #if !defined(BSWAP_NEEDED) && !defined(WORDS_BIGENDIAN)
374 return (fd_set *)target_fds;
379 for(i = 0;i < n; i++) {
380 b = (tswapl(target_fds[i / TARGET_LONG_BITS]) >>
381 (i & (TARGET_LONG_BITS - 1))) & 1;
392 static inline void host_to_target_fds(target_long *target_fds,
395 #if !defined(BSWAP_NEEDED) && !defined(WORDS_BIGENDIAN)
402 nw = (n + TARGET_LONG_BITS - 1) / TARGET_LONG_BITS;
404 for(i = 0;i < nw; i++) {
406 for(j = 0; j < TARGET_LONG_BITS; j++) {
407 v |= ((FD_ISSET(k, fds) != 0) << j);
410 target_fds[i] = tswapl(v);
416 #if defined(__alpha__)
422 static inline long host_to_target_clock_t(long ticks)
424 #if HOST_HZ == TARGET_HZ
427 return ((int64_t)ticks * TARGET_HZ) / HOST_HZ;
431 static inline void host_to_target_rusage(target_ulong target_addr,
432 const struct rusage *rusage)
434 struct target_rusage *target_rusage;
436 lock_user_struct(target_rusage, target_addr, 0);
437 target_rusage->ru_utime.tv_sec = tswapl(rusage->ru_utime.tv_sec);
438 target_rusage->ru_utime.tv_usec = tswapl(rusage->ru_utime.tv_usec);
439 target_rusage->ru_stime.tv_sec = tswapl(rusage->ru_stime.tv_sec);
440 target_rusage->ru_stime.tv_usec = tswapl(rusage->ru_stime.tv_usec);
441 target_rusage->ru_maxrss = tswapl(rusage->ru_maxrss);
442 target_rusage->ru_ixrss = tswapl(rusage->ru_ixrss);
443 target_rusage->ru_idrss = tswapl(rusage->ru_idrss);
444 target_rusage->ru_isrss = tswapl(rusage->ru_isrss);
445 target_rusage->ru_minflt = tswapl(rusage->ru_minflt);
446 target_rusage->ru_majflt = tswapl(rusage->ru_majflt);
447 target_rusage->ru_nswap = tswapl(rusage->ru_nswap);
448 target_rusage->ru_inblock = tswapl(rusage->ru_inblock);
449 target_rusage->ru_oublock = tswapl(rusage->ru_oublock);
450 target_rusage->ru_msgsnd = tswapl(rusage->ru_msgsnd);
451 target_rusage->ru_msgrcv = tswapl(rusage->ru_msgrcv);
452 target_rusage->ru_nsignals = tswapl(rusage->ru_nsignals);
453 target_rusage->ru_nvcsw = tswapl(rusage->ru_nvcsw);
454 target_rusage->ru_nivcsw = tswapl(rusage->ru_nivcsw);
455 unlock_user_struct(target_rusage, target_addr, 1);
458 static inline void target_to_host_timeval(struct timeval *tv,
459 target_ulong target_addr)
461 struct target_timeval *target_tv;
463 lock_user_struct(target_tv, target_addr, 1);
464 tv->tv_sec = tswapl(target_tv->tv_sec);
465 tv->tv_usec = tswapl(target_tv->tv_usec);
466 unlock_user_struct(target_tv, target_addr, 0);
469 static inline void host_to_target_timeval(target_ulong target_addr,
470 const struct timeval *tv)
472 struct target_timeval *target_tv;
474 lock_user_struct(target_tv, target_addr, 0);
475 target_tv->tv_sec = tswapl(tv->tv_sec);
476 target_tv->tv_usec = tswapl(tv->tv_usec);
477 unlock_user_struct(target_tv, target_addr, 1);
481 static long do_select(long n,
482 target_ulong rfd_p, target_ulong wfd_p,
483 target_ulong efd_p, target_ulong target_tv)
485 fd_set rfds, wfds, efds;
486 fd_set *rfds_ptr, *wfds_ptr, *efds_ptr;
487 target_long *target_rfds, *target_wfds, *target_efds;
488 struct timeval tv, *tv_ptr;
493 target_rfds = lock_user(rfd_p, sizeof(target_long) * n, 1);
494 rfds_ptr = target_to_host_fds(&rfds, target_rfds, n);
500 target_wfds = lock_user(wfd_p, sizeof(target_long) * n, 1);
501 wfds_ptr = target_to_host_fds(&wfds, target_wfds, n);
507 target_efds = lock_user(efd_p, sizeof(target_long) * n, 1);
508 efds_ptr = target_to_host_fds(&efds, target_efds, n);
515 target_to_host_timeval(&tv, target_tv);
520 ret = get_errno(select(n, rfds_ptr, wfds_ptr, efds_ptr, tv_ptr));
524 host_to_target_fds(target_rfds, rfds_ptr, n);
525 host_to_target_fds(target_wfds, wfds_ptr, n);
526 host_to_target_fds(target_efds, efds_ptr, n);
529 host_to_target_timeval(target_tv, &tv);
533 unlock_user(target_rfds, rfd_p, ok ? sizeof(target_long) * n : 0);
535 unlock_user(target_wfds, wfd_p, ok ? sizeof(target_long) * n : 0);
537 unlock_user(target_efds, efd_p, ok ? sizeof(target_long) * n : 0);
542 static inline void target_to_host_sockaddr(struct sockaddr *addr,
543 target_ulong target_addr,
546 struct target_sockaddr *target_saddr;
548 target_saddr = lock_user(target_addr, len, 1);
549 memcpy(addr, target_saddr, len);
550 addr->sa_family = tswap16(target_saddr->sa_family);
551 unlock_user(target_saddr, target_addr, 0);
554 static inline void host_to_target_sockaddr(target_ulong target_addr,
555 struct sockaddr *addr,
558 struct target_sockaddr *target_saddr;
560 target_saddr = lock_user(target_addr, len, 0);
561 memcpy(target_saddr, addr, len);
562 target_saddr->sa_family = tswap16(addr->sa_family);
563 unlock_user(target_saddr, target_addr, len);
566 /* ??? Should this also swap msgh->name? */
567 static inline void target_to_host_cmsg(struct msghdr *msgh,
568 struct target_msghdr *target_msgh)
570 struct cmsghdr *cmsg = CMSG_FIRSTHDR(msgh);
571 struct target_cmsghdr *target_cmsg = TARGET_CMSG_FIRSTHDR(target_msgh);
574 while (cmsg && target_cmsg) {
575 void *data = CMSG_DATA(cmsg);
576 void *target_data = TARGET_CMSG_DATA(target_cmsg);
578 int len = tswapl(target_cmsg->cmsg_len)
579 - TARGET_CMSG_ALIGN(sizeof (struct target_cmsghdr));
581 space += CMSG_SPACE(len);
582 if (space > msgh->msg_controllen) {
583 space -= CMSG_SPACE(len);
584 gemu_log("Host cmsg overflow\n");
588 cmsg->cmsg_level = tswap32(target_cmsg->cmsg_level);
589 cmsg->cmsg_type = tswap32(target_cmsg->cmsg_type);
590 cmsg->cmsg_len = CMSG_LEN(len);
592 if (cmsg->cmsg_level != TARGET_SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS) {
593 gemu_log("Unsupported ancillary data: %d/%d\n", cmsg->cmsg_level, cmsg->cmsg_type);
594 memcpy(data, target_data, len);
596 int *fd = (int *)data;
597 int *target_fd = (int *)target_data;
598 int i, numfds = len / sizeof(int);
600 for (i = 0; i < numfds; i++)
601 fd[i] = tswap32(target_fd[i]);
604 cmsg = CMSG_NXTHDR(msgh, cmsg);
605 target_cmsg = TARGET_CMSG_NXTHDR(target_msgh, target_cmsg);
608 msgh->msg_controllen = space;
611 /* ??? Should this also swap msgh->name? */
612 static inline void host_to_target_cmsg(struct target_msghdr *target_msgh,
615 struct cmsghdr *cmsg = CMSG_FIRSTHDR(msgh);
616 struct target_cmsghdr *target_cmsg = TARGET_CMSG_FIRSTHDR(target_msgh);
619 while (cmsg && target_cmsg) {
620 void *data = CMSG_DATA(cmsg);
621 void *target_data = TARGET_CMSG_DATA(target_cmsg);
623 int len = cmsg->cmsg_len - CMSG_ALIGN(sizeof (struct cmsghdr));
625 space += TARGET_CMSG_SPACE(len);
626 if (space > tswapl(target_msgh->msg_controllen)) {
627 space -= TARGET_CMSG_SPACE(len);
628 gemu_log("Target cmsg overflow\n");
632 target_cmsg->cmsg_level = tswap32(cmsg->cmsg_level);
633 target_cmsg->cmsg_type = tswap32(cmsg->cmsg_type);
634 target_cmsg->cmsg_len = tswapl(TARGET_CMSG_LEN(len));
636 if (cmsg->cmsg_level != TARGET_SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS) {
637 gemu_log("Unsupported ancillary data: %d/%d\n", cmsg->cmsg_level, cmsg->cmsg_type);
638 memcpy(target_data, data, len);
640 int *fd = (int *)data;
641 int *target_fd = (int *)target_data;
642 int i, numfds = len / sizeof(int);
644 for (i = 0; i < numfds; i++)
645 target_fd[i] = tswap32(fd[i]);
648 cmsg = CMSG_NXTHDR(msgh, cmsg);
649 target_cmsg = TARGET_CMSG_NXTHDR(target_msgh, target_cmsg);
652 msgh->msg_controllen = tswapl(space);
655 static long do_setsockopt(int sockfd, int level, int optname,
656 target_ulong optval, socklen_t optlen)
662 /* TCP options all take an 'int' value. */
663 if (optlen < sizeof(uint32_t))
666 val = tget32(optval);
667 ret = get_errno(setsockopt(sockfd, level, optname, &val, sizeof(val)));
674 case IP_ROUTER_ALERT:
678 case IP_MTU_DISCOVER:
684 case IP_MULTICAST_TTL:
685 case IP_MULTICAST_LOOP:
687 if (optlen >= sizeof(uint32_t)) {
688 val = tget32(optval);
689 } else if (optlen >= 1) {
692 ret = get_errno(setsockopt(sockfd, level, optname, &val, sizeof(val)));
698 case TARGET_SOL_SOCKET:
700 /* Options with 'int' argument. */
701 case TARGET_SO_DEBUG:
704 case TARGET_SO_REUSEADDR:
705 optname = SO_REUSEADDR;
710 case TARGET_SO_ERROR:
713 case TARGET_SO_DONTROUTE:
714 optname = SO_DONTROUTE;
716 case TARGET_SO_BROADCAST:
717 optname = SO_BROADCAST;
719 case TARGET_SO_SNDBUF:
722 case TARGET_SO_RCVBUF:
725 case TARGET_SO_KEEPALIVE:
726 optname = SO_KEEPALIVE;
728 case TARGET_SO_OOBINLINE:
729 optname = SO_OOBINLINE;
731 case TARGET_SO_NO_CHECK:
732 optname = SO_NO_CHECK;
734 case TARGET_SO_PRIORITY:
735 optname = SO_PRIORITY;
738 case TARGET_SO_BSDCOMPAT:
739 optname = SO_BSDCOMPAT;
742 case TARGET_SO_PASSCRED:
743 optname = SO_PASSCRED;
745 case TARGET_SO_TIMESTAMP:
746 optname = SO_TIMESTAMP;
748 case TARGET_SO_RCVLOWAT:
749 optname = SO_RCVLOWAT;
751 case TARGET_SO_RCVTIMEO:
752 optname = SO_RCVTIMEO;
754 case TARGET_SO_SNDTIMEO:
755 optname = SO_SNDTIMEO;
761 if (optlen < sizeof(uint32_t))
764 val = tget32(optval);
765 ret = get_errno(setsockopt(sockfd, SOL_SOCKET, optname, &val, sizeof(val)));
769 gemu_log("Unsupported setsockopt level=%d optname=%d \n", level, optname);
775 static long do_getsockopt(int sockfd, int level, int optname,
776 target_ulong optval, target_ulong optlen)
778 int len, lv, val, ret;
781 case TARGET_SOL_SOCKET:
784 case TARGET_SO_LINGER:
785 case TARGET_SO_RCVTIMEO:
786 case TARGET_SO_SNDTIMEO:
787 case TARGET_SO_PEERCRED:
788 case TARGET_SO_PEERNAME:
789 /* These don't just return a single integer */
796 /* TCP options all take an 'int' value. */
798 len = tget32(optlen);
802 ret = get_errno(getsockopt(sockfd, level, optname, &val, &lv));
819 case IP_ROUTER_ALERT:
823 case IP_MTU_DISCOVER:
829 case IP_MULTICAST_TTL:
830 case IP_MULTICAST_LOOP:
831 len = tget32(optlen);
835 ret = get_errno(getsockopt(sockfd, level, optname, &val, &lv));
838 if (len < sizeof(int) && len > 0 && val >= 0 && val < 255) {
843 if (len > sizeof(int))
855 gemu_log("getsockopt level=%d optname=%d not yet supported\n",
863 static void lock_iovec(struct iovec *vec, target_ulong target_addr,
866 struct target_iovec *target_vec;
870 target_vec = lock_user(target_addr, count * sizeof(struct target_iovec), 1);
871 for(i = 0;i < count; i++) {
872 base = tswapl(target_vec[i].iov_base);
873 vec[i].iov_len = tswapl(target_vec[i].iov_len);
874 vec[i].iov_base = lock_user(base, vec[i].iov_len, copy);
876 unlock_user (target_vec, target_addr, 0);
879 static void unlock_iovec(struct iovec *vec, target_ulong target_addr,
882 struct target_iovec *target_vec;
886 target_vec = lock_user(target_addr, count * sizeof(struct target_iovec), 1);
887 for(i = 0;i < count; i++) {
888 base = tswapl(target_vec[i].iov_base);
889 unlock_user(vec[i].iov_base, base, copy ? vec[i].iov_len : 0);
891 unlock_user (target_vec, target_addr, 0);
894 static long do_socket(int domain, int type, int protocol)
896 #if defined(TARGET_MIPS)
898 case TARGET_SOCK_DGRAM:
901 case TARGET_SOCK_STREAM:
904 case TARGET_SOCK_RAW:
907 case TARGET_SOCK_RDM:
910 case TARGET_SOCK_SEQPACKET:
911 type = SOCK_SEQPACKET;
913 case TARGET_SOCK_PACKET:
918 return get_errno(socket(domain, type, protocol));
921 static long do_bind(int sockfd, target_ulong target_addr,
924 void *addr = alloca(addrlen);
926 target_to_host_sockaddr(addr, target_addr, addrlen);
927 return get_errno(bind(sockfd, addr, addrlen));
930 static long do_connect(int sockfd, target_ulong target_addr,
933 void *addr = alloca(addrlen);
935 target_to_host_sockaddr(addr, target_addr, addrlen);
936 return get_errno(connect(sockfd, addr, addrlen));
939 static long do_sendrecvmsg(int fd, target_ulong target_msg,
943 struct target_msghdr *msgp;
947 target_ulong target_vec;
949 lock_user_struct(msgp, target_msg, 1);
950 if (msgp->msg_name) {
951 msg.msg_namelen = tswap32(msgp->msg_namelen);
952 msg.msg_name = alloca(msg.msg_namelen);
953 target_to_host_sockaddr(msg.msg_name, tswapl(msgp->msg_name),
959 msg.msg_controllen = 2 * tswapl(msgp->msg_controllen);
960 msg.msg_control = alloca(msg.msg_controllen);
961 msg.msg_flags = tswap32(msgp->msg_flags);
963 count = tswapl(msgp->msg_iovlen);
964 vec = alloca(count * sizeof(struct iovec));
965 target_vec = tswapl(msgp->msg_iov);
966 lock_iovec(vec, target_vec, count, send);
967 msg.msg_iovlen = count;
971 target_to_host_cmsg(&msg, msgp);
972 ret = get_errno(sendmsg(fd, &msg, flags));
974 ret = get_errno(recvmsg(fd, &msg, flags));
976 host_to_target_cmsg(msgp, &msg);
978 unlock_iovec(vec, target_vec, count, !send);
982 static long do_accept(int fd, target_ulong target_addr,
983 target_ulong target_addrlen)
985 socklen_t addrlen = tget32(target_addrlen);
986 void *addr = alloca(addrlen);
989 ret = get_errno(accept(fd, addr, &addrlen));
990 if (!is_error(ret)) {
991 host_to_target_sockaddr(target_addr, addr, addrlen);
992 tput32(target_addrlen, addrlen);
997 static long do_getpeername(int fd, target_ulong target_addr,
998 target_ulong target_addrlen)
1000 socklen_t addrlen = tget32(target_addrlen);
1001 void *addr = alloca(addrlen);
1004 ret = get_errno(getpeername(fd, addr, &addrlen));
1005 if (!is_error(ret)) {
1006 host_to_target_sockaddr(target_addr, addr, addrlen);
1007 tput32(target_addrlen, addrlen);
1012 static long do_getsockname(int fd, target_ulong target_addr,
1013 target_ulong target_addrlen)
1015 socklen_t addrlen = tget32(target_addrlen);
1016 void *addr = alloca(addrlen);
1019 ret = get_errno(getsockname(fd, addr, &addrlen));
1020 if (!is_error(ret)) {
1021 host_to_target_sockaddr(target_addr, addr, addrlen);
1022 tput32(target_addrlen, addrlen);
1027 static long do_socketpair(int domain, int type, int protocol,
1028 target_ulong target_tab)
1033 ret = get_errno(socketpair(domain, type, protocol, tab));
1034 if (!is_error(ret)) {
1035 tput32(target_tab, tab[0]);
1036 tput32(target_tab + 4, tab[1]);
1041 static long do_sendto(int fd, target_ulong msg, size_t len, int flags,
1042 target_ulong target_addr, socklen_t addrlen)
1048 host_msg = lock_user(msg, len, 1);
1050 addr = alloca(addrlen);
1051 target_to_host_sockaddr(addr, target_addr, addrlen);
1052 ret = get_errno(sendto(fd, host_msg, len, flags, addr, addrlen));
1054 ret = get_errno(send(fd, host_msg, len, flags));
1056 unlock_user(host_msg, msg, 0);
1060 static long do_recvfrom(int fd, target_ulong msg, size_t len, int flags,
1061 target_ulong target_addr, target_ulong target_addrlen)
1068 host_msg = lock_user(msg, len, 0);
1070 addrlen = tget32(target_addrlen);
1071 addr = alloca(addrlen);
1072 ret = get_errno(recvfrom(fd, host_msg, len, flags, addr, &addrlen));
1074 addr = NULL; /* To keep compiler quiet. */
1075 ret = get_errno(recv(fd, host_msg, len, flags));
1077 if (!is_error(ret)) {
1079 host_to_target_sockaddr(target_addr, addr, addrlen);
1080 tput32(target_addrlen, addrlen);
1082 unlock_user(host_msg, msg, len);
1084 unlock_user(host_msg, msg, 0);
1089 static long do_socketcall(int num, target_ulong vptr)
1092 const int n = sizeof(target_ulong);
1097 int domain = tgetl(vptr);
1098 int type = tgetl(vptr + n);
1099 int protocol = tgetl(vptr + 2 * n);
1100 ret = do_socket(domain, type, protocol);
1105 int sockfd = tgetl(vptr);
1106 target_ulong target_addr = tgetl(vptr + n);
1107 socklen_t addrlen = tgetl(vptr + 2 * n);
1108 ret = do_bind(sockfd, target_addr, addrlen);
1111 case SOCKOP_connect:
1113 int sockfd = tgetl(vptr);
1114 target_ulong target_addr = tgetl(vptr + n);
1115 socklen_t addrlen = tgetl(vptr + 2 * n);
1116 ret = do_connect(sockfd, target_addr, addrlen);
1121 int sockfd = tgetl(vptr);
1122 int backlog = tgetl(vptr + n);
1123 ret = get_errno(listen(sockfd, backlog));
1128 int sockfd = tgetl(vptr);
1129 target_ulong target_addr = tgetl(vptr + n);
1130 target_ulong target_addrlen = tgetl(vptr + 2 * n);
1131 ret = do_accept(sockfd, target_addr, target_addrlen);
1134 case SOCKOP_getsockname:
1136 int sockfd = tgetl(vptr);
1137 target_ulong target_addr = tgetl(vptr + n);
1138 target_ulong target_addrlen = tgetl(vptr + 2 * n);
1139 ret = do_getsockname(sockfd, target_addr, target_addrlen);
1142 case SOCKOP_getpeername:
1144 int sockfd = tgetl(vptr);
1145 target_ulong target_addr = tgetl(vptr + n);
1146 target_ulong target_addrlen = tgetl(vptr + 2 * n);
1147 ret = do_getpeername(sockfd, target_addr, target_addrlen);
1150 case SOCKOP_socketpair:
1152 int domain = tgetl(vptr);
1153 int type = tgetl(vptr + n);
1154 int protocol = tgetl(vptr + 2 * n);
1155 target_ulong tab = tgetl(vptr + 3 * n);
1156 ret = do_socketpair(domain, type, protocol, tab);
1161 int sockfd = tgetl(vptr);
1162 target_ulong msg = tgetl(vptr + n);
1163 size_t len = tgetl(vptr + 2 * n);
1164 int flags = tgetl(vptr + 3 * n);
1165 ret = do_sendto(sockfd, msg, len, flags, 0, 0);
1170 int sockfd = tgetl(vptr);
1171 target_ulong msg = tgetl(vptr + n);
1172 size_t len = tgetl(vptr + 2 * n);
1173 int flags = tgetl(vptr + 3 * n);
1174 ret = do_recvfrom(sockfd, msg, len, flags, 0, 0);
1179 int sockfd = tgetl(vptr);
1180 target_ulong msg = tgetl(vptr + n);
1181 size_t len = tgetl(vptr + 2 * n);
1182 int flags = tgetl(vptr + 3 * n);
1183 target_ulong addr = tgetl(vptr + 4 * n);
1184 socklen_t addrlen = tgetl(vptr + 5 * n);
1185 ret = do_sendto(sockfd, msg, len, flags, addr, addrlen);
1188 case SOCKOP_recvfrom:
1190 int sockfd = tgetl(vptr);
1191 target_ulong msg = tgetl(vptr + n);
1192 size_t len = tgetl(vptr + 2 * n);
1193 int flags = tgetl(vptr + 3 * n);
1194 target_ulong addr = tgetl(vptr + 4 * n);
1195 target_ulong addrlen = tgetl(vptr + 5 * n);
1196 ret = do_recvfrom(sockfd, msg, len, flags, addr, addrlen);
1199 case SOCKOP_shutdown:
1201 int sockfd = tgetl(vptr);
1202 int how = tgetl(vptr + n);
1204 ret = get_errno(shutdown(sockfd, how));
1207 case SOCKOP_sendmsg:
1208 case SOCKOP_recvmsg:
1211 target_ulong target_msg;
1215 target_msg = tgetl(vptr + n);
1216 flags = tgetl(vptr + 2 * n);
1218 ret = do_sendrecvmsg(fd, target_msg, flags,
1219 (num == SOCKOP_sendmsg));
1222 case SOCKOP_setsockopt:
1224 int sockfd = tgetl(vptr);
1225 int level = tgetl(vptr + n);
1226 int optname = tgetl(vptr + 2 * n);
1227 target_ulong optval = tgetl(vptr + 3 * n);
1228 socklen_t optlen = tgetl(vptr + 4 * n);
1230 ret = do_setsockopt(sockfd, level, optname, optval, optlen);
1233 case SOCKOP_getsockopt:
1235 int sockfd = tgetl(vptr);
1236 int level = tgetl(vptr + n);
1237 int optname = tgetl(vptr + 2 * n);
1238 target_ulong optval = tgetl(vptr + 3 * n);
1239 target_ulong poptlen = tgetl(vptr + 4 * n);
1241 ret = do_getsockopt(sockfd, level, optname, optval, poptlen);
1245 gemu_log("Unsupported socketcall: %d\n", num);
1252 #define N_SHM_REGIONS 32
1254 static struct shm_region {
1257 } shm_regions[N_SHM_REGIONS];
1259 struct target_ipc_perm
1266 unsigned short int mode;
1267 unsigned short int __pad1;
1268 unsigned short int __seq;
1269 unsigned short int __pad2;
1270 target_ulong __unused1;
1271 target_ulong __unused2;
1274 struct target_semid_ds
1276 struct target_ipc_perm sem_perm;
1277 target_ulong sem_otime;
1278 target_ulong __unused1;
1279 target_ulong sem_ctime;
1280 target_ulong __unused2;
1281 target_ulong sem_nsems;
1282 target_ulong __unused3;
1283 target_ulong __unused4;
1286 static inline void target_to_host_ipc_perm(struct ipc_perm *host_ip,
1287 target_ulong target_addr)
1289 struct target_ipc_perm *target_ip;
1290 struct target_semid_ds *target_sd;
1292 lock_user_struct(target_sd, target_addr, 1);
1293 target_ip=&(target_sd->sem_perm);
1294 host_ip->__key = tswapl(target_ip->__key);
1295 host_ip->uid = tswapl(target_ip->uid);
1296 host_ip->gid = tswapl(target_ip->gid);
1297 host_ip->cuid = tswapl(target_ip->cuid);
1298 host_ip->cgid = tswapl(target_ip->cgid);
1299 host_ip->mode = tswapl(target_ip->mode);
1300 unlock_user_struct(target_sd, target_addr, 0);
1303 static inline void host_to_target_ipc_perm(target_ulong target_addr,
1304 struct ipc_perm *host_ip)
1306 struct target_ipc_perm *target_ip;
1307 struct target_semid_ds *target_sd;
1309 lock_user_struct(target_sd, target_addr, 0);
1310 target_ip = &(target_sd->sem_perm);
1311 target_ip->__key = tswapl(host_ip->__key);
1312 target_ip->uid = tswapl(host_ip->uid);
1313 target_ip->gid = tswapl(host_ip->gid);
1314 target_ip->cuid = tswapl(host_ip->cuid);
1315 target_ip->cgid = tswapl(host_ip->cgid);
1316 target_ip->mode = tswapl(host_ip->mode);
1317 unlock_user_struct(target_sd, target_addr, 1);
1320 static inline void target_to_host_semid_ds(struct semid_ds *host_sd,
1321 target_ulong target_addr)
1323 struct target_semid_ds *target_sd;
1325 lock_user_struct(target_sd, target_addr, 1);
1326 target_to_host_ipc_perm(&(host_sd->sem_perm),target_addr);
1327 host_sd->sem_nsems = tswapl(target_sd->sem_nsems);
1328 host_sd->sem_otime = tswapl(target_sd->sem_otime);
1329 host_sd->sem_ctime = tswapl(target_sd->sem_ctime);
1330 unlock_user_struct(target_sd, target_addr, 0);
1333 static inline void host_to_target_semid_ds(target_ulong target_addr,
1334 struct semid_ds *host_sd)
1336 struct target_semid_ds *target_sd;
1338 lock_user_struct(target_sd, target_addr, 0);
1339 host_to_target_ipc_perm(target_addr,&(host_sd->sem_perm));
1340 target_sd->sem_nsems = tswapl(host_sd->sem_nsems);
1341 target_sd->sem_otime = tswapl(host_sd->sem_otime);
1342 target_sd->sem_ctime = tswapl(host_sd->sem_ctime);
1343 unlock_user_struct(target_sd, target_addr, 1);
1348 struct semid_ds *buf;
1349 unsigned short *array;
1352 union target_semun {
1355 unsigned short int *array;
1358 static inline void target_to_host_semun(unsigned long cmd,
1359 union semun *host_su,
1360 target_ulong target_addr,
1361 struct semid_ds *ds)
1363 union target_semun *target_su;
1368 lock_user_struct(target_su, target_addr, 1);
1369 target_to_host_semid_ds(ds,target_su->buf);
1371 unlock_user_struct(target_su, target_addr, 0);
1375 lock_user_struct(target_su, target_addr, 1);
1376 host_su->val = tswapl(target_su->val);
1377 unlock_user_struct(target_su, target_addr, 0);
1381 lock_user_struct(target_su, target_addr, 1);
1382 *host_su->array = tswap16(*target_su->array);
1383 unlock_user_struct(target_su, target_addr, 0);
1386 gemu_log("semun operation not fully supported: %d\n", (int)cmd);
1390 static inline void host_to_target_semun(unsigned long cmd,
1391 target_ulong target_addr,
1392 union semun *host_su,
1393 struct semid_ds *ds)
1395 union target_semun *target_su;
1400 lock_user_struct(target_su, target_addr, 0);
1401 host_to_target_semid_ds(target_su->buf,ds);
1402 unlock_user_struct(target_su, target_addr, 1);
1406 lock_user_struct(target_su, target_addr, 0);
1407 target_su->val = tswapl(host_su->val);
1408 unlock_user_struct(target_su, target_addr, 1);
1412 lock_user_struct(target_su, target_addr, 0);
1413 *target_su->array = tswap16(*host_su->array);
1414 unlock_user_struct(target_su, target_addr, 1);
1417 gemu_log("semun operation not fully supported: %d\n", (int)cmd);
1421 static inline long do_semctl(long first, long second, long third, long ptr)
1424 struct semid_ds dsarg;
1425 int cmd = third&0xff;
1430 target_to_host_semun(cmd,&arg,ptr,&dsarg);
1431 ret = get_errno(semctl(first, second, cmd, arg));
1432 host_to_target_semun(cmd,ptr,&arg,&dsarg);
1435 target_to_host_semun(cmd,&arg,ptr,&dsarg);
1436 ret = get_errno(semctl(first, second, cmd, arg));
1437 host_to_target_semun(cmd,ptr,&arg,&dsarg);
1440 target_to_host_semun(cmd,&arg,ptr,&dsarg);
1441 ret = get_errno(semctl(first, second, cmd, arg));
1442 host_to_target_semun(cmd,ptr,&arg,&dsarg);
1445 target_to_host_semun(cmd,&arg,ptr,&dsarg);
1446 ret = get_errno(semctl(first, second, cmd, arg));
1447 host_to_target_semun(cmd,ptr,&arg,&dsarg);
1450 target_to_host_semun(cmd,&arg,ptr,&dsarg);
1451 ret = get_errno(semctl(first, second, cmd, arg));
1452 host_to_target_semun(cmd,ptr,&arg,&dsarg);
1455 target_to_host_semun(cmd,&arg,ptr,&dsarg);
1456 ret = get_errno(semctl(first, second, cmd, arg));
1457 host_to_target_semun(cmd,ptr,&arg,&dsarg);
1460 ret = get_errno(semctl(first, second, cmd, arg));
1466 struct target_msqid_ds
1468 struct target_ipc_perm msg_perm;
1469 target_ulong msg_stime;
1470 target_ulong __unused1;
1471 target_ulong msg_rtime;
1472 target_ulong __unused2;
1473 target_ulong msg_ctime;
1474 target_ulong __unused3;
1475 target_ulong __msg_cbytes;
1476 target_ulong msg_qnum;
1477 target_ulong msg_qbytes;
1478 target_ulong msg_lspid;
1479 target_ulong msg_lrpid;
1480 target_ulong __unused4;
1481 target_ulong __unused5;
1484 static inline void target_to_host_msqid_ds(struct msqid_ds *host_md,
1485 target_ulong target_addr)
1487 struct target_msqid_ds *target_md;
1489 lock_user_struct(target_md, target_addr, 1);
1490 target_to_host_ipc_perm(&(host_md->msg_perm),target_addr);
1491 host_md->msg_stime = tswapl(target_md->msg_stime);
1492 host_md->msg_rtime = tswapl(target_md->msg_rtime);
1493 host_md->msg_ctime = tswapl(target_md->msg_ctime);
1494 host_md->__msg_cbytes = tswapl(target_md->__msg_cbytes);
1495 host_md->msg_qnum = tswapl(target_md->msg_qnum);
1496 host_md->msg_qbytes = tswapl(target_md->msg_qbytes);
1497 host_md->msg_lspid = tswapl(target_md->msg_lspid);
1498 host_md->msg_lrpid = tswapl(target_md->msg_lrpid);
1499 unlock_user_struct(target_md, target_addr, 0);
1502 static inline void host_to_target_msqid_ds(target_ulong target_addr,
1503 struct msqid_ds *host_md)
1505 struct target_msqid_ds *target_md;
1507 lock_user_struct(target_md, target_addr, 0);
1508 host_to_target_ipc_perm(target_addr,&(host_md->msg_perm));
1509 target_md->msg_stime = tswapl(host_md->msg_stime);
1510 target_md->msg_rtime = tswapl(host_md->msg_rtime);
1511 target_md->msg_ctime = tswapl(host_md->msg_ctime);
1512 target_md->__msg_cbytes = tswapl(host_md->__msg_cbytes);
1513 target_md->msg_qnum = tswapl(host_md->msg_qnum);
1514 target_md->msg_qbytes = tswapl(host_md->msg_qbytes);
1515 target_md->msg_lspid = tswapl(host_md->msg_lspid);
1516 target_md->msg_lrpid = tswapl(host_md->msg_lrpid);
1517 unlock_user_struct(target_md, target_addr, 1);
1520 static inline long do_msgctl(long first, long second, long ptr)
1522 struct msqid_ds dsarg;
1523 int cmd = second&0xff;
1528 target_to_host_msqid_ds(&dsarg,ptr);
1529 ret = get_errno(msgctl(first, cmd, &dsarg));
1530 host_to_target_msqid_ds(ptr,&dsarg);
1532 ret = get_errno(msgctl(first, cmd, &dsarg));
1537 struct target_msgbuf {
1542 static inline long do_msgsnd(long msqid, long msgp, long msgsz, long msgflg)
1544 struct target_msgbuf *target_mb;
1545 struct msgbuf *host_mb;
1548 lock_user_struct(target_mb,msgp,0);
1549 host_mb = malloc(msgsz+sizeof(long));
1550 host_mb->mtype = tswapl(target_mb->mtype);
1551 memcpy(host_mb->mtext,target_mb->mtext,msgsz);
1552 ret = get_errno(msgsnd(msqid, host_mb, msgsz, msgflg));
1554 unlock_user_struct(target_mb, msgp, 0);
1559 static inline long do_msgrcv(long msqid, long msgp, long msgsz, long msgtype, long msgflg)
1561 struct target_msgbuf *target_mb;
1562 struct msgbuf *host_mb;
1565 lock_user_struct(target_mb, msgp, 0);
1566 host_mb = malloc(msgsz+sizeof(long));
1567 ret = get_errno(msgrcv(msqid, host_mb, msgsz, 1, msgflg));
1569 memcpy(target_mb->mtext, host_mb->mtext, ret);
1570 target_mb->mtype = tswapl(host_mb->mtype);
1572 unlock_user_struct(target_mb, msgp, 0);
1577 /* ??? This only works with linear mappings. */
1578 static long do_ipc(long call, long first, long second, long third,
1579 long ptr, long fifth)
1583 unsigned long raddr;
1584 struct shmid_ds shm_info;
1587 version = call >> 16;
1592 ret = get_errno(semop(first,(struct sembuf *) ptr, second));
1596 ret = get_errno(semget(first, second, third));
1600 ret = do_semctl(first, second, third, ptr);
1603 case IPCOP_semtimedop:
1604 gemu_log("Unsupported ipc call: %ld (version %d)\n", call, version);
1609 ret = get_errno(msgget(first, second));
1613 ret = do_msgsnd(first, ptr, second, third);
1617 ret = do_msgctl(first, second, ptr);
1624 void *__unbounded msgp;
1628 struct ipc_kludge *foo = (struct ipc_kludge *) ptr;
1629 struct msgbuf *msgp = (struct msgbuf *) foo->msgp;
1631 ret = do_msgrcv(first, (long)msgp, second, 0, third);
1637 /* SHM_* flags are the same on all linux platforms */
1638 ret = get_errno((long) shmat(first, (void *) ptr, second));
1642 /* find out the length of the shared memory segment */
1644 ret = get_errno(shmctl(first, IPC_STAT, &shm_info));
1645 if (is_error(ret)) {
1646 /* can't get length, bail out */
1647 shmdt((void *) raddr);
1650 page_set_flags(raddr, raddr + shm_info.shm_segsz,
1651 PAGE_VALID | PAGE_READ |
1652 ((second & SHM_RDONLY)? 0: PAGE_WRITE));
1653 for (i = 0; i < N_SHM_REGIONS; ++i) {
1654 if (shm_regions[i].start == 0) {
1655 shm_regions[i].start = raddr;
1656 shm_regions[i].size = shm_info.shm_segsz;
1660 if (put_user(raddr, (uint32_t *)third))
1665 for (i = 0; i < N_SHM_REGIONS; ++i) {
1666 if (shm_regions[i].start == ptr) {
1667 shm_regions[i].start = 0;
1668 page_set_flags(ptr, shm_regions[i].size, 0);
1672 ret = get_errno(shmdt((void *) ptr));
1676 /* IPC_* flag values are the same on all linux platforms */
1677 ret = get_errno(shmget(first, second, third));
1680 /* IPC_* and SHM_* command values are the same on all linux platforms */
1686 ret = get_errno(shmctl(first, second, NULL));
1694 gemu_log("Unsupported ipc call: %ld (version %d)\n", call, version);
1701 /* kernel structure types definitions */
1704 #define STRUCT(name, list...) STRUCT_ ## name,
1705 #define STRUCT_SPECIAL(name) STRUCT_ ## name,
1707 #include "syscall_types.h"
1710 #undef STRUCT_SPECIAL
1712 #define STRUCT(name, list...) const argtype struct_ ## name ## _def[] = { list, TYPE_NULL };
1713 #define STRUCT_SPECIAL(name)
1714 #include "syscall_types.h"
1716 #undef STRUCT_SPECIAL
1718 typedef struct IOCTLEntry {
1719 unsigned int target_cmd;
1720 unsigned int host_cmd;
1723 const argtype arg_type[5];
1726 #define IOC_R 0x0001
1727 #define IOC_W 0x0002
1728 #define IOC_RW (IOC_R | IOC_W)
1730 #define MAX_STRUCT_SIZE 4096
1732 IOCTLEntry ioctl_entries[] = {
1733 #define IOCTL(cmd, access, types...) \
1734 { TARGET_ ## cmd, cmd, #cmd, access, { types } },
1739 /* ??? Implement proper locking for ioctls. */
1740 static long do_ioctl(long fd, long cmd, long arg)
1742 const IOCTLEntry *ie;
1743 const argtype *arg_type;
1745 uint8_t buf_temp[MAX_STRUCT_SIZE];
1751 if (ie->target_cmd == 0) {
1752 gemu_log("Unsupported ioctl: cmd=0x%04lx\n", cmd);
1755 if (ie->target_cmd == cmd)
1759 arg_type = ie->arg_type;
1761 gemu_log("ioctl: cmd=0x%04lx (%s)\n", cmd, ie->name);
1763 switch(arg_type[0]) {
1766 ret = get_errno(ioctl(fd, ie->host_cmd));
1771 ret = get_errno(ioctl(fd, ie->host_cmd, arg));
1775 target_size = thunk_type_size(arg_type, 0);
1776 switch(ie->access) {
1778 ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp));
1779 if (!is_error(ret)) {
1780 argptr = lock_user(arg, target_size, 0);
1781 thunk_convert(argptr, buf_temp, arg_type, THUNK_TARGET);
1782 unlock_user(argptr, arg, target_size);
1786 argptr = lock_user(arg, target_size, 1);
1787 thunk_convert(buf_temp, argptr, arg_type, THUNK_HOST);
1788 unlock_user(argptr, arg, 0);
1789 ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp));
1793 argptr = lock_user(arg, target_size, 1);
1794 thunk_convert(buf_temp, argptr, arg_type, THUNK_HOST);
1795 unlock_user(argptr, arg, 0);
1796 ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp));
1797 if (!is_error(ret)) {
1798 argptr = lock_user(arg, target_size, 0);
1799 thunk_convert(argptr, buf_temp, arg_type, THUNK_TARGET);
1800 unlock_user(argptr, arg, target_size);
1806 gemu_log("Unsupported ioctl type: cmd=0x%04lx type=%d\n", cmd, arg_type[0]);
1813 bitmask_transtbl iflag_tbl[] = {
1814 { TARGET_IGNBRK, TARGET_IGNBRK, IGNBRK, IGNBRK },
1815 { TARGET_BRKINT, TARGET_BRKINT, BRKINT, BRKINT },
1816 { TARGET_IGNPAR, TARGET_IGNPAR, IGNPAR, IGNPAR },
1817 { TARGET_PARMRK, TARGET_PARMRK, PARMRK, PARMRK },
1818 { TARGET_INPCK, TARGET_INPCK, INPCK, INPCK },
1819 { TARGET_ISTRIP, TARGET_ISTRIP, ISTRIP, ISTRIP },
1820 { TARGET_INLCR, TARGET_INLCR, INLCR, INLCR },
1821 { TARGET_IGNCR, TARGET_IGNCR, IGNCR, IGNCR },
1822 { TARGET_ICRNL, TARGET_ICRNL, ICRNL, ICRNL },
1823 { TARGET_IUCLC, TARGET_IUCLC, IUCLC, IUCLC },
1824 { TARGET_IXON, TARGET_IXON, IXON, IXON },
1825 { TARGET_IXANY, TARGET_IXANY, IXANY, IXANY },
1826 { TARGET_IXOFF, TARGET_IXOFF, IXOFF, IXOFF },
1827 { TARGET_IMAXBEL, TARGET_IMAXBEL, IMAXBEL, IMAXBEL },
1831 bitmask_transtbl oflag_tbl[] = {
1832 { TARGET_OPOST, TARGET_OPOST, OPOST, OPOST },
1833 { TARGET_OLCUC, TARGET_OLCUC, OLCUC, OLCUC },
1834 { TARGET_ONLCR, TARGET_ONLCR, ONLCR, ONLCR },
1835 { TARGET_OCRNL, TARGET_OCRNL, OCRNL, OCRNL },
1836 { TARGET_ONOCR, TARGET_ONOCR, ONOCR, ONOCR },
1837 { TARGET_ONLRET, TARGET_ONLRET, ONLRET, ONLRET },
1838 { TARGET_OFILL, TARGET_OFILL, OFILL, OFILL },
1839 { TARGET_OFDEL, TARGET_OFDEL, OFDEL, OFDEL },
1840 { TARGET_NLDLY, TARGET_NL0, NLDLY, NL0 },
1841 { TARGET_NLDLY, TARGET_NL1, NLDLY, NL1 },
1842 { TARGET_CRDLY, TARGET_CR0, CRDLY, CR0 },
1843 { TARGET_CRDLY, TARGET_CR1, CRDLY, CR1 },
1844 { TARGET_CRDLY, TARGET_CR2, CRDLY, CR2 },
1845 { TARGET_CRDLY, TARGET_CR3, CRDLY, CR3 },
1846 { TARGET_TABDLY, TARGET_TAB0, TABDLY, TAB0 },
1847 { TARGET_TABDLY, TARGET_TAB1, TABDLY, TAB1 },
1848 { TARGET_TABDLY, TARGET_TAB2, TABDLY, TAB2 },
1849 { TARGET_TABDLY, TARGET_TAB3, TABDLY, TAB3 },
1850 { TARGET_BSDLY, TARGET_BS0, BSDLY, BS0 },
1851 { TARGET_BSDLY, TARGET_BS1, BSDLY, BS1 },
1852 { TARGET_VTDLY, TARGET_VT0, VTDLY, VT0 },
1853 { TARGET_VTDLY, TARGET_VT1, VTDLY, VT1 },
1854 { TARGET_FFDLY, TARGET_FF0, FFDLY, FF0 },
1855 { TARGET_FFDLY, TARGET_FF1, FFDLY, FF1 },
1859 bitmask_transtbl cflag_tbl[] = {
1860 { TARGET_CBAUD, TARGET_B0, CBAUD, B0 },
1861 { TARGET_CBAUD, TARGET_B50, CBAUD, B50 },
1862 { TARGET_CBAUD, TARGET_B75, CBAUD, B75 },
1863 { TARGET_CBAUD, TARGET_B110, CBAUD, B110 },
1864 { TARGET_CBAUD, TARGET_B134, CBAUD, B134 },
1865 { TARGET_CBAUD, TARGET_B150, CBAUD, B150 },
1866 { TARGET_CBAUD, TARGET_B200, CBAUD, B200 },
1867 { TARGET_CBAUD, TARGET_B300, CBAUD, B300 },
1868 { TARGET_CBAUD, TARGET_B600, CBAUD, B600 },
1869 { TARGET_CBAUD, TARGET_B1200, CBAUD, B1200 },
1870 { TARGET_CBAUD, TARGET_B1800, CBAUD, B1800 },
1871 { TARGET_CBAUD, TARGET_B2400, CBAUD, B2400 },
1872 { TARGET_CBAUD, TARGET_B4800, CBAUD, B4800 },
1873 { TARGET_CBAUD, TARGET_B9600, CBAUD, B9600 },
1874 { TARGET_CBAUD, TARGET_B19200, CBAUD, B19200 },
1875 { TARGET_CBAUD, TARGET_B38400, CBAUD, B38400 },
1876 { TARGET_CBAUD, TARGET_B57600, CBAUD, B57600 },
1877 { TARGET_CBAUD, TARGET_B115200, CBAUD, B115200 },
1878 { TARGET_CBAUD, TARGET_B230400, CBAUD, B230400 },
1879 { TARGET_CBAUD, TARGET_B460800, CBAUD, B460800 },
1880 { TARGET_CSIZE, TARGET_CS5, CSIZE, CS5 },
1881 { TARGET_CSIZE, TARGET_CS6, CSIZE, CS6 },
1882 { TARGET_CSIZE, TARGET_CS7, CSIZE, CS7 },
1883 { TARGET_CSIZE, TARGET_CS8, CSIZE, CS8 },
1884 { TARGET_CSTOPB, TARGET_CSTOPB, CSTOPB, CSTOPB },
1885 { TARGET_CREAD, TARGET_CREAD, CREAD, CREAD },
1886 { TARGET_PARENB, TARGET_PARENB, PARENB, PARENB },
1887 { TARGET_PARODD, TARGET_PARODD, PARODD, PARODD },
1888 { TARGET_HUPCL, TARGET_HUPCL, HUPCL, HUPCL },
1889 { TARGET_CLOCAL, TARGET_CLOCAL, CLOCAL, CLOCAL },
1890 { TARGET_CRTSCTS, TARGET_CRTSCTS, CRTSCTS, CRTSCTS },
1894 bitmask_transtbl lflag_tbl[] = {
1895 { TARGET_ISIG, TARGET_ISIG, ISIG, ISIG },
1896 { TARGET_ICANON, TARGET_ICANON, ICANON, ICANON },
1897 { TARGET_XCASE, TARGET_XCASE, XCASE, XCASE },
1898 { TARGET_ECHO, TARGET_ECHO, ECHO, ECHO },
1899 { TARGET_ECHOE, TARGET_ECHOE, ECHOE, ECHOE },
1900 { TARGET_ECHOK, TARGET_ECHOK, ECHOK, ECHOK },
1901 { TARGET_ECHONL, TARGET_ECHONL, ECHONL, ECHONL },
1902 { TARGET_NOFLSH, TARGET_NOFLSH, NOFLSH, NOFLSH },
1903 { TARGET_TOSTOP, TARGET_TOSTOP, TOSTOP, TOSTOP },
1904 { TARGET_ECHOCTL, TARGET_ECHOCTL, ECHOCTL, ECHOCTL },
1905 { TARGET_ECHOPRT, TARGET_ECHOPRT, ECHOPRT, ECHOPRT },
1906 { TARGET_ECHOKE, TARGET_ECHOKE, ECHOKE, ECHOKE },
1907 { TARGET_FLUSHO, TARGET_FLUSHO, FLUSHO, FLUSHO },
1908 { TARGET_PENDIN, TARGET_PENDIN, PENDIN, PENDIN },
1909 { TARGET_IEXTEN, TARGET_IEXTEN, IEXTEN, IEXTEN },
1913 static void target_to_host_termios (void *dst, const void *src)
1915 struct host_termios *host = dst;
1916 const struct target_termios *target = src;
1919 target_to_host_bitmask(tswap32(target->c_iflag), iflag_tbl);
1921 target_to_host_bitmask(tswap32(target->c_oflag), oflag_tbl);
1923 target_to_host_bitmask(tswap32(target->c_cflag), cflag_tbl);
1925 target_to_host_bitmask(tswap32(target->c_lflag), lflag_tbl);
1926 host->c_line = target->c_line;
1928 host->c_cc[VINTR] = target->c_cc[TARGET_VINTR];
1929 host->c_cc[VQUIT] = target->c_cc[TARGET_VQUIT];
1930 host->c_cc[VERASE] = target->c_cc[TARGET_VERASE];
1931 host->c_cc[VKILL] = target->c_cc[TARGET_VKILL];
1932 host->c_cc[VEOF] = target->c_cc[TARGET_VEOF];
1933 host->c_cc[VTIME] = target->c_cc[TARGET_VTIME];
1934 host->c_cc[VMIN] = target->c_cc[TARGET_VMIN];
1935 host->c_cc[VSWTC] = target->c_cc[TARGET_VSWTC];
1936 host->c_cc[VSTART] = target->c_cc[TARGET_VSTART];
1937 host->c_cc[VSTOP] = target->c_cc[TARGET_VSTOP];
1938 host->c_cc[VSUSP] = target->c_cc[TARGET_VSUSP];
1939 host->c_cc[VEOL] = target->c_cc[TARGET_VEOL];
1940 host->c_cc[VREPRINT] = target->c_cc[TARGET_VREPRINT];
1941 host->c_cc[VDISCARD] = target->c_cc[TARGET_VDISCARD];
1942 host->c_cc[VWERASE] = target->c_cc[TARGET_VWERASE];
1943 host->c_cc[VLNEXT] = target->c_cc[TARGET_VLNEXT];
1944 host->c_cc[VEOL2] = target->c_cc[TARGET_VEOL2];
1947 static void host_to_target_termios (void *dst, const void *src)
1949 struct target_termios *target = dst;
1950 const struct host_termios *host = src;
1953 tswap32(host_to_target_bitmask(host->c_iflag, iflag_tbl));
1955 tswap32(host_to_target_bitmask(host->c_oflag, oflag_tbl));
1957 tswap32(host_to_target_bitmask(host->c_cflag, cflag_tbl));
1959 tswap32(host_to_target_bitmask(host->c_lflag, lflag_tbl));
1960 target->c_line = host->c_line;
1962 target->c_cc[TARGET_VINTR] = host->c_cc[VINTR];
1963 target->c_cc[TARGET_VQUIT] = host->c_cc[VQUIT];
1964 target->c_cc[TARGET_VERASE] = host->c_cc[VERASE];
1965 target->c_cc[TARGET_VKILL] = host->c_cc[VKILL];
1966 target->c_cc[TARGET_VEOF] = host->c_cc[VEOF];
1967 target->c_cc[TARGET_VTIME] = host->c_cc[VTIME];
1968 target->c_cc[TARGET_VMIN] = host->c_cc[VMIN];
1969 target->c_cc[TARGET_VSWTC] = host->c_cc[VSWTC];
1970 target->c_cc[TARGET_VSTART] = host->c_cc[VSTART];
1971 target->c_cc[TARGET_VSTOP] = host->c_cc[VSTOP];
1972 target->c_cc[TARGET_VSUSP] = host->c_cc[VSUSP];
1973 target->c_cc[TARGET_VEOL] = host->c_cc[VEOL];
1974 target->c_cc[TARGET_VREPRINT] = host->c_cc[VREPRINT];
1975 target->c_cc[TARGET_VDISCARD] = host->c_cc[VDISCARD];
1976 target->c_cc[TARGET_VWERASE] = host->c_cc[VWERASE];
1977 target->c_cc[TARGET_VLNEXT] = host->c_cc[VLNEXT];
1978 target->c_cc[TARGET_VEOL2] = host->c_cc[VEOL2];
1981 StructEntry struct_termios_def = {
1982 .convert = { host_to_target_termios, target_to_host_termios },
1983 .size = { sizeof(struct target_termios), sizeof(struct host_termios) },
1984 .align = { __alignof__(struct target_termios), __alignof__(struct host_termios) },
1987 static bitmask_transtbl mmap_flags_tbl[] = {
1988 { TARGET_MAP_SHARED, TARGET_MAP_SHARED, MAP_SHARED, MAP_SHARED },
1989 { TARGET_MAP_PRIVATE, TARGET_MAP_PRIVATE, MAP_PRIVATE, MAP_PRIVATE },
1990 { TARGET_MAP_FIXED, TARGET_MAP_FIXED, MAP_FIXED, MAP_FIXED },
1991 { TARGET_MAP_ANONYMOUS, TARGET_MAP_ANONYMOUS, MAP_ANONYMOUS, MAP_ANONYMOUS },
1992 { TARGET_MAP_GROWSDOWN, TARGET_MAP_GROWSDOWN, MAP_GROWSDOWN, MAP_GROWSDOWN },
1993 { TARGET_MAP_DENYWRITE, TARGET_MAP_DENYWRITE, MAP_DENYWRITE, MAP_DENYWRITE },
1994 { TARGET_MAP_EXECUTABLE, TARGET_MAP_EXECUTABLE, MAP_EXECUTABLE, MAP_EXECUTABLE },
1995 { TARGET_MAP_LOCKED, TARGET_MAP_LOCKED, MAP_LOCKED, MAP_LOCKED },
1999 static bitmask_transtbl fcntl_flags_tbl[] = {
2000 { TARGET_O_ACCMODE, TARGET_O_WRONLY, O_ACCMODE, O_WRONLY, },
2001 { TARGET_O_ACCMODE, TARGET_O_RDWR, O_ACCMODE, O_RDWR, },
2002 { TARGET_O_CREAT, TARGET_O_CREAT, O_CREAT, O_CREAT, },
2003 { TARGET_O_EXCL, TARGET_O_EXCL, O_EXCL, O_EXCL, },
2004 { TARGET_O_NOCTTY, TARGET_O_NOCTTY, O_NOCTTY, O_NOCTTY, },
2005 { TARGET_O_TRUNC, TARGET_O_TRUNC, O_TRUNC, O_TRUNC, },
2006 { TARGET_O_APPEND, TARGET_O_APPEND, O_APPEND, O_APPEND, },
2007 { TARGET_O_NONBLOCK, TARGET_O_NONBLOCK, O_NONBLOCK, O_NONBLOCK, },
2008 { TARGET_O_SYNC, TARGET_O_SYNC, O_SYNC, O_SYNC, },
2009 { TARGET_FASYNC, TARGET_FASYNC, FASYNC, FASYNC, },
2010 { TARGET_O_DIRECTORY, TARGET_O_DIRECTORY, O_DIRECTORY, O_DIRECTORY, },
2011 { TARGET_O_NOFOLLOW, TARGET_O_NOFOLLOW, O_NOFOLLOW, O_NOFOLLOW, },
2012 { TARGET_O_LARGEFILE, TARGET_O_LARGEFILE, O_LARGEFILE, O_LARGEFILE, },
2013 #if defined(O_DIRECT)
2014 { TARGET_O_DIRECT, TARGET_O_DIRECT, O_DIRECT, O_DIRECT, },
2019 #if defined(TARGET_I386)
2021 /* NOTE: there is really one LDT for all the threads */
2024 static int read_ldt(target_ulong ptr, unsigned long bytecount)
2031 size = TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE;
2032 if (size > bytecount)
2034 p = lock_user(ptr, size, 0);
2035 /* ??? Shoudl this by byteswapped? */
2036 memcpy(p, ldt_table, size);
2037 unlock_user(p, ptr, size);
2041 /* XXX: add locking support */
2042 static int write_ldt(CPUX86State *env,
2043 target_ulong ptr, unsigned long bytecount, int oldmode)
2045 struct target_modify_ldt_ldt_s ldt_info;
2046 struct target_modify_ldt_ldt_s *target_ldt_info;
2047 int seg_32bit, contents, read_exec_only, limit_in_pages;
2048 int seg_not_present, useable;
2049 uint32_t *lp, entry_1, entry_2;
2051 if (bytecount != sizeof(ldt_info))
2053 lock_user_struct(target_ldt_info, ptr, 1);
2054 ldt_info.entry_number = tswap32(target_ldt_info->entry_number);
2055 ldt_info.base_addr = tswapl(target_ldt_info->base_addr);
2056 ldt_info.limit = tswap32(target_ldt_info->limit);
2057 ldt_info.flags = tswap32(target_ldt_info->flags);
2058 unlock_user_struct(target_ldt_info, ptr, 0);
2060 if (ldt_info.entry_number >= TARGET_LDT_ENTRIES)
2062 seg_32bit = ldt_info.flags & 1;
2063 contents = (ldt_info.flags >> 1) & 3;
2064 read_exec_only = (ldt_info.flags >> 3) & 1;
2065 limit_in_pages = (ldt_info.flags >> 4) & 1;
2066 seg_not_present = (ldt_info.flags >> 5) & 1;
2067 useable = (ldt_info.flags >> 6) & 1;
2069 if (contents == 3) {
2072 if (seg_not_present == 0)
2075 /* allocate the LDT */
2077 ldt_table = malloc(TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE);
2080 memset(ldt_table, 0, TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE);
2081 env->ldt.base = h2g(ldt_table);
2082 env->ldt.limit = 0xffff;
2085 /* NOTE: same code as Linux kernel */
2086 /* Allow LDTs to be cleared by the user. */
2087 if (ldt_info.base_addr == 0 && ldt_info.limit == 0) {
2090 read_exec_only == 1 &&
2092 limit_in_pages == 0 &&
2093 seg_not_present == 1 &&
2101 entry_1 = ((ldt_info.base_addr & 0x0000ffff) << 16) |
2102 (ldt_info.limit & 0x0ffff);
2103 entry_2 = (ldt_info.base_addr & 0xff000000) |
2104 ((ldt_info.base_addr & 0x00ff0000) >> 16) |
2105 (ldt_info.limit & 0xf0000) |
2106 ((read_exec_only ^ 1) << 9) |
2108 ((seg_not_present ^ 1) << 15) |
2110 (limit_in_pages << 23) |
2113 entry_2 |= (useable << 20);
2115 /* Install the new entry ... */
2117 lp = (uint32_t *)(ldt_table + (ldt_info.entry_number << 3));
2118 lp[0] = tswap32(entry_1);
2119 lp[1] = tswap32(entry_2);
2123 /* specific and weird i386 syscalls */
2124 int do_modify_ldt(CPUX86State *env, int func, target_ulong ptr, unsigned long bytecount)
2130 ret = read_ldt(ptr, bytecount);
2133 ret = write_ldt(env, ptr, bytecount, 1);
2136 ret = write_ldt(env, ptr, bytecount, 0);
2142 #endif /* defined(TARGET_I386) */
2144 /* this stack is the equivalent of the kernel stack associated with a
2146 #define NEW_STACK_SIZE 8192
2148 static int clone_func(void *arg)
2150 CPUState *env = arg;
2156 int do_fork(CPUState *env, unsigned int flags, unsigned long newsp)
2163 if (flags & CLONE_VM) {
2164 ts = malloc(sizeof(TaskState) + NEW_STACK_SIZE);
2165 memset(ts, 0, sizeof(TaskState));
2166 new_stack = ts->stack;
2168 /* add in task state list */
2169 ts->next = first_task_state;
2170 first_task_state = ts;
2171 /* we create a new CPU instance. */
2172 new_env = cpu_copy(env);
2173 #if defined(TARGET_I386)
2175 newsp = env->regs[R_ESP];
2176 new_env->regs[R_ESP] = newsp;
2177 new_env->regs[R_EAX] = 0;
2178 #elif defined(TARGET_ARM)
2180 newsp = env->regs[13];
2181 new_env->regs[13] = newsp;
2182 new_env->regs[0] = 0;
2183 #elif defined(TARGET_SPARC)
2185 newsp = env->regwptr[22];
2186 new_env->regwptr[22] = newsp;
2187 new_env->regwptr[0] = 0;
2189 printf ("HELPME: %s:%d\n", __FILE__, __LINE__);
2190 #elif defined(TARGET_M68K)
2192 newsp = env->aregs[7];
2193 new_env->aregs[7] = newsp;
2194 new_env->dregs[0] = 0;
2195 /* ??? is this sufficient? */
2196 #elif defined(TARGET_MIPS)
2198 newsp = env->gpr[29][env->current_tc];
2199 new_env->gpr[29][env->current_tc] = newsp;
2200 #elif defined(TARGET_PPC)
2202 newsp = env->gpr[1];
2203 new_env->gpr[1] = newsp;
2206 for (i = 7; i < 32; i++)
2207 new_env->gpr[i] = 0;
2209 #elif defined(TARGET_SH4)
2211 newsp = env->gregs[15];
2212 new_env->gregs[15] = newsp;
2214 #elif defined(TARGET_ALPHA)
2216 newsp = env->ir[30];
2217 new_env->ir[30] = newsp;
2221 for (i = 7; i < 30; i++)
2225 #error unsupported target CPU
2227 new_env->opaque = ts;
2229 ret = __clone2(clone_func, new_stack + NEW_STACK_SIZE, flags, new_env);
2231 ret = clone(clone_func, new_stack + NEW_STACK_SIZE, flags, new_env);
2234 /* if no CLONE_VM, we consider it is a fork */
2235 if ((flags & ~CSIGNAL) != 0)
2242 static long do_fcntl(int fd, int cmd, target_ulong arg)
2245 struct target_flock *target_fl;
2246 struct flock64 fl64;
2247 struct target_flock64 *target_fl64;
2251 case TARGET_F_GETLK:
2252 lock_user_struct(target_fl, arg, 1);
2253 fl.l_type = tswap16(target_fl->l_type);
2254 fl.l_whence = tswap16(target_fl->l_whence);
2255 fl.l_start = tswapl(target_fl->l_start);
2256 fl.l_len = tswapl(target_fl->l_len);
2257 fl.l_pid = tswapl(target_fl->l_pid);
2258 unlock_user_struct(target_fl, arg, 0);
2259 ret = fcntl(fd, cmd, &fl);
2261 lock_user_struct(target_fl, arg, 0);
2262 target_fl->l_type = tswap16(fl.l_type);
2263 target_fl->l_whence = tswap16(fl.l_whence);
2264 target_fl->l_start = tswapl(fl.l_start);
2265 target_fl->l_len = tswapl(fl.l_len);
2266 target_fl->l_pid = tswapl(fl.l_pid);
2267 unlock_user_struct(target_fl, arg, 1);
2271 case TARGET_F_SETLK:
2272 case TARGET_F_SETLKW:
2273 lock_user_struct(target_fl, arg, 1);
2274 fl.l_type = tswap16(target_fl->l_type);
2275 fl.l_whence = tswap16(target_fl->l_whence);
2276 fl.l_start = tswapl(target_fl->l_start);
2277 fl.l_len = tswapl(target_fl->l_len);
2278 fl.l_pid = tswapl(target_fl->l_pid);
2279 unlock_user_struct(target_fl, arg, 0);
2280 ret = fcntl(fd, cmd, &fl);
2283 case TARGET_F_GETLK64:
2284 lock_user_struct(target_fl64, arg, 1);
2285 fl64.l_type = tswap16(target_fl64->l_type) >> 1;
2286 fl64.l_whence = tswap16(target_fl64->l_whence);
2287 fl64.l_start = tswapl(target_fl64->l_start);
2288 fl64.l_len = tswapl(target_fl64->l_len);
2289 fl64.l_pid = tswap16(target_fl64->l_pid);
2290 unlock_user_struct(target_fl64, arg, 0);
2291 ret = fcntl(fd, cmd >> 1, &fl64);
2293 lock_user_struct(target_fl64, arg, 0);
2294 target_fl64->l_type = tswap16(fl64.l_type) >> 1;
2295 target_fl64->l_whence = tswap16(fl64.l_whence);
2296 target_fl64->l_start = tswapl(fl64.l_start);
2297 target_fl64->l_len = tswapl(fl64.l_len);
2298 target_fl64->l_pid = tswapl(fl64.l_pid);
2299 unlock_user_struct(target_fl64, arg, 1);
2302 case TARGET_F_SETLK64:
2303 case TARGET_F_SETLKW64:
2304 lock_user_struct(target_fl64, arg, 1);
2305 fl64.l_type = tswap16(target_fl64->l_type) >> 1;
2306 fl64.l_whence = tswap16(target_fl64->l_whence);
2307 fl64.l_start = tswapl(target_fl64->l_start);
2308 fl64.l_len = tswapl(target_fl64->l_len);
2309 fl64.l_pid = tswap16(target_fl64->l_pid);
2310 unlock_user_struct(target_fl64, arg, 0);
2311 ret = fcntl(fd, cmd >> 1, &fl64);
2315 ret = fcntl(fd, cmd, arg);
2316 ret = host_to_target_bitmask(ret, fcntl_flags_tbl);
2320 ret = fcntl(fd, cmd, target_to_host_bitmask(arg, fcntl_flags_tbl));
2324 ret = fcntl(fd, cmd, arg);
2332 static inline int high2lowuid(int uid)
2340 static inline int high2lowgid(int gid)
2348 static inline int low2highuid(int uid)
2350 if ((int16_t)uid == -1)
2356 static inline int low2highgid(int gid)
2358 if ((int16_t)gid == -1)
2364 #endif /* USE_UID16 */
2366 void syscall_init(void)
2369 const argtype *arg_type;
2372 #define STRUCT(name, list...) thunk_register_struct(STRUCT_ ## name, #name, struct_ ## name ## _def);
2373 #define STRUCT_SPECIAL(name) thunk_register_struct_direct(STRUCT_ ## name, #name, &struct_ ## name ## _def);
2374 #include "syscall_types.h"
2376 #undef STRUCT_SPECIAL
2378 /* we patch the ioctl size if necessary. We rely on the fact that
2379 no ioctl has all the bits at '1' in the size field */
2381 while (ie->target_cmd != 0) {
2382 if (((ie->target_cmd >> TARGET_IOC_SIZESHIFT) & TARGET_IOC_SIZEMASK) ==
2383 TARGET_IOC_SIZEMASK) {
2384 arg_type = ie->arg_type;
2385 if (arg_type[0] != TYPE_PTR) {
2386 fprintf(stderr, "cannot patch size for ioctl 0x%x\n",
2391 size = thunk_type_size(arg_type, 0);
2392 ie->target_cmd = (ie->target_cmd &
2393 ~(TARGET_IOC_SIZEMASK << TARGET_IOC_SIZESHIFT)) |
2394 (size << TARGET_IOC_SIZESHIFT);
2396 /* automatic consistency check if same arch */
2397 #if defined(__i386__) && defined(TARGET_I386)
2398 if (ie->target_cmd != ie->host_cmd) {
2399 fprintf(stderr, "ERROR: ioctl: target=0x%x host=0x%x\n",
2400 ie->target_cmd, ie->host_cmd);
2407 static inline uint64_t target_offset64(uint32_t word0, uint32_t word1)
2409 #ifdef TARGET_WORDS_BIG_ENDIAN
2410 return ((uint64_t)word0 << 32) | word1;
2412 return ((uint64_t)word1 << 32) | word0;
2416 #ifdef TARGET_NR_truncate64
2417 static inline long target_truncate64(void *cpu_env, const char *arg1,
2418 long arg2, long arg3, long arg4)
2421 if (((CPUARMState *)cpu_env)->eabi)
2427 return get_errno(truncate64(arg1, target_offset64(arg2, arg3)));
2431 #ifdef TARGET_NR_ftruncate64
2432 static inline long target_ftruncate64(void *cpu_env, long arg1, long arg2,
2433 long arg3, long arg4)
2436 if (((CPUARMState *)cpu_env)->eabi)
2442 return get_errno(ftruncate64(arg1, target_offset64(arg2, arg3)));
2446 static inline void target_to_host_timespec(struct timespec *host_ts,
2447 target_ulong target_addr)
2449 struct target_timespec *target_ts;
2451 lock_user_struct(target_ts, target_addr, 1);
2452 host_ts->tv_sec = tswapl(target_ts->tv_sec);
2453 host_ts->tv_nsec = tswapl(target_ts->tv_nsec);
2454 unlock_user_struct(target_ts, target_addr, 0);
2457 static inline void host_to_target_timespec(target_ulong target_addr,
2458 struct timespec *host_ts)
2460 struct target_timespec *target_ts;
2462 lock_user_struct(target_ts, target_addr, 0);
2463 target_ts->tv_sec = tswapl(host_ts->tv_sec);
2464 target_ts->tv_nsec = tswapl(host_ts->tv_nsec);
2465 unlock_user_struct(target_ts, target_addr, 1);
2468 long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
2469 long arg4, long arg5, long arg6)
2477 gemu_log("syscall %d", num);
2480 case TARGET_NR_exit:
2484 gdb_exit(cpu_env, arg1);
2485 /* XXX: should free thread stack and CPU env */
2487 ret = 0; /* avoid warning */
2489 case TARGET_NR_read:
2490 page_unprotect_range(arg2, arg3);
2491 p = lock_user(arg2, arg3, 0);
2492 ret = get_errno(read(arg1, p, arg3));
2493 unlock_user(p, arg2, ret);
2495 case TARGET_NR_write:
2496 p = lock_user(arg2, arg3, 1);
2497 ret = get_errno(write(arg1, p, arg3));
2498 unlock_user(p, arg2, 0);
2500 case TARGET_NR_open:
2501 p = lock_user_string(arg1);
2502 ret = get_errno(open(path(p),
2503 target_to_host_bitmask(arg2, fcntl_flags_tbl),
2505 unlock_user(p, arg1, 0);
2507 #if defined(TARGET_NR_openat) && defined(__NR_openat)
2508 case TARGET_NR_openat:
2513 p = lock_user_string(arg2);
2514 if (!access_ok(VERIFY_READ, p, 1))
2517 ret = get_errno(sys_openat(arg1,
2519 target_to_host_bitmask(arg3, fcntl_flags_tbl),
2522 unlock_user(p, arg2, 0);
2525 case TARGET_NR_close:
2526 ret = get_errno(close(arg1));
2531 case TARGET_NR_fork:
2532 ret = get_errno(do_fork(cpu_env, SIGCHLD, 0));
2534 #ifdef TARGET_NR_waitpid
2535 case TARGET_NR_waitpid:
2538 ret = get_errno(waitpid(arg1, &status, arg3));
2539 if (!is_error(ret) && arg2)
2540 tput32(arg2, status);
2544 #ifdef TARGET_NR_creat /* not on alpha */
2545 case TARGET_NR_creat:
2546 p = lock_user_string(arg1);
2547 ret = get_errno(creat(p, arg2));
2548 unlock_user(p, arg1, 0);
2551 case TARGET_NR_link:
2554 p = lock_user_string(arg1);
2555 p2 = lock_user_string(arg2);
2556 ret = get_errno(link(p, p2));
2557 unlock_user(p2, arg2, 0);
2558 unlock_user(p, arg1, 0);
2561 case TARGET_NR_unlink:
2562 p = lock_user_string(arg1);
2563 ret = get_errno(unlink(p));
2564 unlock_user(p, arg1, 0);
2566 case TARGET_NR_execve:
2568 char **argp, **envp;
2571 target_ulong guest_argp;
2572 target_ulong guest_envp;
2578 for (gp = guest_argp; tgetl(gp); gp++)
2582 for (gp = guest_envp; tgetl(gp); gp++)
2585 argp = alloca((argc + 1) * sizeof(void *));
2586 envp = alloca((envc + 1) * sizeof(void *));
2588 for (gp = guest_argp, q = argp; ;
2589 gp += sizeof(target_ulong), q++) {
2593 *q = lock_user_string(addr);
2597 for (gp = guest_envp, q = envp; ;
2598 gp += sizeof(target_ulong), q++) {
2602 *q = lock_user_string(addr);
2606 p = lock_user_string(arg1);
2607 ret = get_errno(execve(p, argp, envp));
2608 unlock_user(p, arg1, 0);
2610 for (gp = guest_argp, q = argp; *q;
2611 gp += sizeof(target_ulong), q++) {
2613 unlock_user(*q, addr, 0);
2615 for (gp = guest_envp, q = envp; *q;
2616 gp += sizeof(target_ulong), q++) {
2618 unlock_user(*q, addr, 0);
2622 case TARGET_NR_chdir:
2623 p = lock_user_string(arg1);
2624 ret = get_errno(chdir(p));
2625 unlock_user(p, arg1, 0);
2627 #ifdef TARGET_NR_time
2628 case TARGET_NR_time:
2631 ret = get_errno(time(&host_time));
2632 if (!is_error(ret) && arg1)
2633 tputl(arg1, host_time);
2637 case TARGET_NR_mknod:
2638 p = lock_user_string(arg1);
2639 ret = get_errno(mknod(p, arg2, arg3));
2640 unlock_user(p, arg1, 0);
2642 case TARGET_NR_chmod:
2643 p = lock_user_string(arg1);
2644 ret = get_errno(chmod(p, arg2));
2645 unlock_user(p, arg1, 0);
2647 #ifdef TARGET_NR_break
2648 case TARGET_NR_break:
2651 #ifdef TARGET_NR_oldstat
2652 case TARGET_NR_oldstat:
2655 case TARGET_NR_lseek:
2656 ret = get_errno(lseek(arg1, arg2, arg3));
2658 #ifdef TARGET_NR_getxpid
2659 case TARGET_NR_getxpid:
2661 case TARGET_NR_getpid:
2663 ret = get_errno(getpid());
2665 case TARGET_NR_mount:
2667 /* need to look at the data field */
2669 p = lock_user_string(arg1);
2670 p2 = lock_user_string(arg2);
2671 p3 = lock_user_string(arg3);
2672 ret = get_errno(mount(p, p2, p3, (unsigned long)arg4, (const void *)arg5));
2673 unlock_user(p, arg1, 0);
2674 unlock_user(p2, arg2, 0);
2675 unlock_user(p3, arg3, 0);
2678 #ifdef TARGET_NR_umount
2679 case TARGET_NR_umount:
2680 p = lock_user_string(arg1);
2681 ret = get_errno(umount(p));
2682 unlock_user(p, arg1, 0);
2685 #ifdef TARGET_NR_stime /* not on alpha */
2686 case TARGET_NR_stime:
2689 host_time = tgetl(arg1);
2690 ret = get_errno(stime(&host_time));
2694 case TARGET_NR_ptrace:
2696 #ifdef TARGET_NR_alarm /* not on alpha */
2697 case TARGET_NR_alarm:
2701 #ifdef TARGET_NR_oldfstat
2702 case TARGET_NR_oldfstat:
2705 #ifdef TARGET_NR_pause /* not on alpha */
2706 case TARGET_NR_pause:
2707 ret = get_errno(pause());
2710 #ifdef TARGET_NR_utime
2711 case TARGET_NR_utime:
2713 struct utimbuf tbuf, *host_tbuf;
2714 struct target_utimbuf *target_tbuf;
2716 lock_user_struct(target_tbuf, arg2, 1);
2717 tbuf.actime = tswapl(target_tbuf->actime);
2718 tbuf.modtime = tswapl(target_tbuf->modtime);
2719 unlock_user_struct(target_tbuf, arg2, 0);
2724 p = lock_user_string(arg1);
2725 ret = get_errno(utime(p, host_tbuf));
2726 unlock_user(p, arg1, 0);
2730 case TARGET_NR_utimes:
2732 struct timeval *tvp, tv[2];
2734 target_to_host_timeval(&tv[0], arg2);
2735 target_to_host_timeval(&tv[1],
2736 arg2 + sizeof (struct target_timeval));
2741 p = lock_user_string(arg1);
2742 ret = get_errno(utimes(p, tvp));
2743 unlock_user(p, arg1, 0);
2746 #ifdef TARGET_NR_stty
2747 case TARGET_NR_stty:
2750 #ifdef TARGET_NR_gtty
2751 case TARGET_NR_gtty:
2754 case TARGET_NR_access:
2755 p = lock_user_string(arg1);
2756 ret = get_errno(access(p, arg2));
2757 unlock_user(p, arg1, 0);
2759 #ifdef TARGET_NR_nice /* not on alpha */
2760 case TARGET_NR_nice:
2761 ret = get_errno(nice(arg1));
2764 #ifdef TARGET_NR_ftime
2765 case TARGET_NR_ftime:
2768 case TARGET_NR_sync:
2772 case TARGET_NR_kill:
2773 ret = get_errno(kill(arg1, arg2));
2775 case TARGET_NR_rename:
2778 p = lock_user_string(arg1);
2779 p2 = lock_user_string(arg2);
2780 ret = get_errno(rename(p, p2));
2781 unlock_user(p2, arg2, 0);
2782 unlock_user(p, arg1, 0);
2785 case TARGET_NR_mkdir:
2786 p = lock_user_string(arg1);
2787 ret = get_errno(mkdir(p, arg2));
2788 unlock_user(p, arg1, 0);
2790 case TARGET_NR_rmdir:
2791 p = lock_user_string(arg1);
2792 ret = get_errno(rmdir(p));
2793 unlock_user(p, arg1, 0);
2796 ret = get_errno(dup(arg1));
2798 case TARGET_NR_pipe:
2801 ret = get_errno(pipe(host_pipe));
2802 if (!is_error(ret)) {
2803 #if defined(TARGET_MIPS)
2804 CPUMIPSState *env = (CPUMIPSState*)cpu_env;
2805 env->gpr[3][env->current_tc] = host_pipe[1];
2808 tput32(arg1, host_pipe[0]);
2809 tput32(arg1 + 4, host_pipe[1]);
2814 case TARGET_NR_times:
2816 struct target_tms *tmsp;
2818 ret = get_errno(times(&tms));
2820 tmsp = lock_user(arg1, sizeof(struct target_tms), 0);
2821 tmsp->tms_utime = tswapl(host_to_target_clock_t(tms.tms_utime));
2822 tmsp->tms_stime = tswapl(host_to_target_clock_t(tms.tms_stime));
2823 tmsp->tms_cutime = tswapl(host_to_target_clock_t(tms.tms_cutime));
2824 tmsp->tms_cstime = tswapl(host_to_target_clock_t(tms.tms_cstime));
2827 ret = host_to_target_clock_t(ret);
2830 #ifdef TARGET_NR_prof
2831 case TARGET_NR_prof:
2834 #ifdef TARGET_NR_signal
2835 case TARGET_NR_signal:
2838 case TARGET_NR_acct:
2839 p = lock_user_string(arg1);
2840 ret = get_errno(acct(path(p)));
2841 unlock_user(p, arg1, 0);
2843 #ifdef TARGET_NR_umount2 /* not on alpha */
2844 case TARGET_NR_umount2:
2845 p = lock_user_string(arg1);
2846 ret = get_errno(umount2(p, arg2));
2847 unlock_user(p, arg1, 0);
2850 #ifdef TARGET_NR_lock
2851 case TARGET_NR_lock:
2854 case TARGET_NR_ioctl:
2855 ret = do_ioctl(arg1, arg2, arg3);
2857 case TARGET_NR_fcntl:
2858 ret = get_errno(do_fcntl(arg1, arg2, arg3));
2860 #ifdef TARGET_NR_mpx
2864 case TARGET_NR_setpgid:
2865 ret = get_errno(setpgid(arg1, arg2));
2867 #ifdef TARGET_NR_ulimit
2868 case TARGET_NR_ulimit:
2871 #ifdef TARGET_NR_oldolduname
2872 case TARGET_NR_oldolduname:
2875 case TARGET_NR_umask:
2876 ret = get_errno(umask(arg1));
2878 case TARGET_NR_chroot:
2879 p = lock_user_string(arg1);
2880 ret = get_errno(chroot(p));
2881 unlock_user(p, arg1, 0);
2883 case TARGET_NR_ustat:
2885 case TARGET_NR_dup2:
2886 ret = get_errno(dup2(arg1, arg2));
2888 #ifdef TARGET_NR_getppid /* not on alpha */
2889 case TARGET_NR_getppid:
2890 ret = get_errno(getppid());
2893 case TARGET_NR_getpgrp:
2894 ret = get_errno(getpgrp());
2896 case TARGET_NR_setsid:
2897 ret = get_errno(setsid());
2899 #ifdef TARGET_NR_sigaction
2900 case TARGET_NR_sigaction:
2902 #if !defined(TARGET_MIPS)
2903 struct target_old_sigaction *old_act;
2904 struct target_sigaction act, oact, *pact;
2906 lock_user_struct(old_act, arg2, 1);
2907 act._sa_handler = old_act->_sa_handler;
2908 target_siginitset(&act.sa_mask, old_act->sa_mask);
2909 act.sa_flags = old_act->sa_flags;
2910 act.sa_restorer = old_act->sa_restorer;
2911 unlock_user_struct(old_act, arg2, 0);
2916 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_mask = oact.sa_mask.sig[0];
2921 old_act->sa_flags = oact.sa_flags;
2922 old_act->sa_restorer = oact.sa_restorer;
2923 unlock_user_struct(old_act, arg3, 1);
2926 struct target_sigaction act, oact, *pact, *old_act;
2929 lock_user_struct(old_act, arg2, 1);
2930 act._sa_handler = old_act->_sa_handler;
2931 target_siginitset(&act.sa_mask, old_act->sa_mask.sig[0]);
2932 act.sa_flags = old_act->sa_flags;
2933 unlock_user_struct(old_act, arg2, 0);
2939 ret = get_errno(do_sigaction(arg1, pact, &oact));
2941 if (!is_error(ret) && arg3) {
2942 lock_user_struct(old_act, arg3, 0);
2943 old_act->_sa_handler = oact._sa_handler;
2944 old_act->sa_flags = oact.sa_flags;
2945 old_act->sa_mask.sig[0] = oact.sa_mask.sig[0];
2946 old_act->sa_mask.sig[1] = 0;
2947 old_act->sa_mask.sig[2] = 0;
2948 old_act->sa_mask.sig[3] = 0;
2949 unlock_user_struct(old_act, arg3, 1);
2955 case TARGET_NR_rt_sigaction:
2957 struct target_sigaction *act;
2958 struct target_sigaction *oact;
2961 lock_user_struct(act, arg2, 1);
2965 lock_user_struct(oact, arg3, 0);
2968 ret = get_errno(do_sigaction(arg1, act, oact));
2970 unlock_user_struct(act, arg2, 0);
2972 unlock_user_struct(oact, arg3, 1);
2975 #ifdef TARGET_NR_sgetmask /* not on alpha */
2976 case TARGET_NR_sgetmask:
2979 target_ulong target_set;
2980 sigprocmask(0, NULL, &cur_set);
2981 host_to_target_old_sigset(&target_set, &cur_set);
2986 #ifdef TARGET_NR_ssetmask /* not on alpha */
2987 case TARGET_NR_ssetmask:
2989 sigset_t set, oset, cur_set;
2990 target_ulong target_set = arg1;
2991 sigprocmask(0, NULL, &cur_set);
2992 target_to_host_old_sigset(&set, &target_set);
2993 sigorset(&set, &set, &cur_set);
2994 sigprocmask(SIG_SETMASK, &set, &oset);
2995 host_to_target_old_sigset(&target_set, &oset);
3000 #ifdef TARGET_NR_sigprocmask
3001 case TARGET_NR_sigprocmask:
3004 sigset_t set, oldset, *set_ptr;
3008 case TARGET_SIG_BLOCK:
3011 case TARGET_SIG_UNBLOCK:
3014 case TARGET_SIG_SETMASK:
3021 p = lock_user(arg2, sizeof(target_sigset_t), 1);
3022 target_to_host_old_sigset(&set, p);
3023 unlock_user(p, arg2, 0);
3029 ret = get_errno(sigprocmask(arg1, set_ptr, &oldset));
3030 if (!is_error(ret) && arg3) {
3031 p = lock_user(arg3, sizeof(target_sigset_t), 0);
3032 host_to_target_old_sigset(p, &oldset);
3033 unlock_user(p, arg3, sizeof(target_sigset_t));
3038 case TARGET_NR_rt_sigprocmask:
3041 sigset_t set, oldset, *set_ptr;
3045 case TARGET_SIG_BLOCK:
3048 case TARGET_SIG_UNBLOCK:
3051 case TARGET_SIG_SETMASK:
3058 p = lock_user(arg2, sizeof(target_sigset_t), 1);
3059 target_to_host_sigset(&set, p);
3060 unlock_user(p, arg2, 0);
3066 ret = get_errno(sigprocmask(how, set_ptr, &oldset));
3067 if (!is_error(ret) && arg3) {
3068 p = lock_user(arg3, sizeof(target_sigset_t), 0);
3069 host_to_target_sigset(p, &oldset);
3070 unlock_user(p, arg3, sizeof(target_sigset_t));
3074 #ifdef TARGET_NR_sigpending
3075 case TARGET_NR_sigpending:
3078 ret = get_errno(sigpending(&set));
3079 if (!is_error(ret)) {
3080 p = lock_user(arg1, sizeof(target_sigset_t), 0);
3081 host_to_target_old_sigset(p, &set);
3082 unlock_user(p, arg1, sizeof(target_sigset_t));
3087 case TARGET_NR_rt_sigpending:
3090 ret = get_errno(sigpending(&set));
3091 if (!is_error(ret)) {
3092 p = lock_user(arg1, sizeof(target_sigset_t), 0);
3093 host_to_target_sigset(p, &set);
3094 unlock_user(p, arg1, sizeof(target_sigset_t));
3098 #ifdef TARGET_NR_sigsuspend
3099 case TARGET_NR_sigsuspend:
3102 p = lock_user(arg1, sizeof(target_sigset_t), 1);
3103 target_to_host_old_sigset(&set, p);
3104 unlock_user(p, arg1, 0);
3105 ret = get_errno(sigsuspend(&set));
3109 case TARGET_NR_rt_sigsuspend:
3112 p = lock_user(arg1, sizeof(target_sigset_t), 1);
3113 target_to_host_sigset(&set, p);
3114 unlock_user(p, arg1, 0);
3115 ret = get_errno(sigsuspend(&set));
3118 case TARGET_NR_rt_sigtimedwait:
3121 struct timespec uts, *puts;
3124 p = lock_user(arg1, sizeof(target_sigset_t), 1);
3125 target_to_host_sigset(&set, p);
3126 unlock_user(p, arg1, 0);
3129 target_to_host_timespec(puts, arg3);
3133 ret = get_errno(sigtimedwait(&set, &uinfo, puts));
3134 if (!is_error(ret) && arg2) {
3135 p = lock_user(arg2, sizeof(target_sigset_t), 0);
3136 host_to_target_siginfo(p, &uinfo);
3137 unlock_user(p, arg2, sizeof(target_sigset_t));
3141 case TARGET_NR_rt_sigqueueinfo:
3144 p = lock_user(arg3, sizeof(target_sigset_t), 1);
3145 target_to_host_siginfo(&uinfo, p);
3146 unlock_user(p, arg1, 0);
3147 ret = get_errno(sys_rt_sigqueueinfo(arg1, arg2, &uinfo));
3150 #ifdef TARGET_NR_sigreturn
3151 case TARGET_NR_sigreturn:
3152 /* NOTE: ret is eax, so not transcoding must be done */
3153 ret = do_sigreturn(cpu_env);
3156 case TARGET_NR_rt_sigreturn:
3157 /* NOTE: ret is eax, so not transcoding must be done */
3158 ret = do_rt_sigreturn(cpu_env);
3160 case TARGET_NR_sethostname:
3161 p = lock_user_string(arg1);
3162 ret = get_errno(sethostname(p, arg2));
3163 unlock_user(p, arg1, 0);
3165 case TARGET_NR_setrlimit:
3167 /* XXX: convert resource ? */
3168 int resource = arg1;
3169 struct target_rlimit *target_rlim;
3171 lock_user_struct(target_rlim, arg2, 1);
3172 rlim.rlim_cur = tswapl(target_rlim->rlim_cur);
3173 rlim.rlim_max = tswapl(target_rlim->rlim_max);
3174 unlock_user_struct(target_rlim, arg2, 0);
3175 ret = get_errno(setrlimit(resource, &rlim));
3178 case TARGET_NR_getrlimit:
3180 /* XXX: convert resource ? */
3181 int resource = arg1;
3182 struct target_rlimit *target_rlim;
3185 ret = get_errno(getrlimit(resource, &rlim));
3186 if (!is_error(ret)) {
3187 lock_user_struct(target_rlim, arg2, 0);
3188 rlim.rlim_cur = tswapl(target_rlim->rlim_cur);
3189 rlim.rlim_max = tswapl(target_rlim->rlim_max);
3190 unlock_user_struct(target_rlim, arg2, 1);
3194 case TARGET_NR_getrusage:
3196 struct rusage rusage;
3197 ret = get_errno(getrusage(arg1, &rusage));
3198 if (!is_error(ret)) {
3199 host_to_target_rusage(arg2, &rusage);
3203 case TARGET_NR_gettimeofday:
3206 ret = get_errno(gettimeofday(&tv, NULL));
3207 if (!is_error(ret)) {
3208 host_to_target_timeval(arg1, &tv);
3212 case TARGET_NR_settimeofday:
3215 target_to_host_timeval(&tv, arg1);
3216 ret = get_errno(settimeofday(&tv, NULL));
3219 #ifdef TARGET_NR_select
3220 case TARGET_NR_select:
3222 struct target_sel_arg_struct *sel;
3223 target_ulong inp, outp, exp, tvp;
3226 lock_user_struct(sel, arg1, 1);
3227 nsel = tswapl(sel->n);
3228 inp = tswapl(sel->inp);
3229 outp = tswapl(sel->outp);
3230 exp = tswapl(sel->exp);
3231 tvp = tswapl(sel->tvp);
3232 unlock_user_struct(sel, arg1, 0);
3233 ret = do_select(nsel, inp, outp, exp, tvp);
3237 case TARGET_NR_symlink:
3240 p = lock_user_string(arg1);
3241 p2 = lock_user_string(arg2);
3242 ret = get_errno(symlink(p, p2));
3243 unlock_user(p2, arg2, 0);
3244 unlock_user(p, arg1, 0);
3247 #ifdef TARGET_NR_oldlstat
3248 case TARGET_NR_oldlstat:
3251 case TARGET_NR_readlink:
3254 p = lock_user_string(arg1);
3255 p2 = lock_user(arg2, arg3, 0);
3256 ret = get_errno(readlink(path(p), p2, arg3));
3257 unlock_user(p2, arg2, ret);
3258 unlock_user(p, arg1, 0);
3261 #ifdef TARGET_NR_uselib
3262 case TARGET_NR_uselib:
3265 #ifdef TARGET_NR_swapon
3266 case TARGET_NR_swapon:
3267 p = lock_user_string(arg1);
3268 ret = get_errno(swapon(p, arg2));
3269 unlock_user(p, arg1, 0);
3272 case TARGET_NR_reboot:
3274 #ifdef TARGET_NR_readdir
3275 case TARGET_NR_readdir:
3278 #ifdef TARGET_NR_mmap
3279 case TARGET_NR_mmap:
3280 #if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_M68K)
3283 target_ulong v1, v2, v3, v4, v5, v6;
3284 v = lock_user(arg1, 6 * sizeof(target_ulong), 1);
3291 unlock_user(v, arg1, 0);
3292 ret = get_errno(target_mmap(v1, v2, v3,
3293 target_to_host_bitmask(v4, mmap_flags_tbl),
3297 ret = get_errno(target_mmap(arg1, arg2, arg3,
3298 target_to_host_bitmask(arg4, mmap_flags_tbl),
3304 #ifdef TARGET_NR_mmap2
3305 case TARGET_NR_mmap2:
3306 #if defined(TARGET_SPARC) || defined(TARGET_MIPS)
3307 #define MMAP_SHIFT 12
3309 #define MMAP_SHIFT TARGET_PAGE_BITS
3311 ret = get_errno(target_mmap(arg1, arg2, arg3,
3312 target_to_host_bitmask(arg4, mmap_flags_tbl),
3314 arg6 << MMAP_SHIFT));
3317 case TARGET_NR_munmap:
3318 ret = get_errno(target_munmap(arg1, arg2));
3320 case TARGET_NR_mprotect:
3321 ret = get_errno(target_mprotect(arg1, arg2, arg3));
3323 #ifdef TARGET_NR_mremap
3324 case TARGET_NR_mremap:
3325 ret = get_errno(target_mremap(arg1, arg2, arg3, arg4, arg5));
3328 /* ??? msync/mlock/munlock are broken for softmmu. */
3329 #ifdef TARGET_NR_msync
3330 case TARGET_NR_msync:
3331 ret = get_errno(msync(g2h(arg1), arg2, arg3));
3334 #ifdef TARGET_NR_mlock
3335 case TARGET_NR_mlock:
3336 ret = get_errno(mlock(g2h(arg1), arg2));
3339 #ifdef TARGET_NR_munlock
3340 case TARGET_NR_munlock:
3341 ret = get_errno(munlock(g2h(arg1), arg2));
3344 #ifdef TARGET_NR_mlockall
3345 case TARGET_NR_mlockall:
3346 ret = get_errno(mlockall(arg1));
3349 #ifdef TARGET_NR_munlockall
3350 case TARGET_NR_munlockall:
3351 ret = get_errno(munlockall());
3354 case TARGET_NR_truncate:
3355 p = lock_user_string(arg1);
3356 ret = get_errno(truncate(p, arg2));
3357 unlock_user(p, arg1, 0);
3359 case TARGET_NR_ftruncate:
3360 ret = get_errno(ftruncate(arg1, arg2));
3362 case TARGET_NR_fchmod:
3363 ret = get_errno(fchmod(arg1, arg2));
3365 case TARGET_NR_getpriority:
3366 ret = get_errno(getpriority(arg1, arg2));
3368 case TARGET_NR_setpriority:
3369 ret = get_errno(setpriority(arg1, arg2, arg3));
3371 #ifdef TARGET_NR_profil
3372 case TARGET_NR_profil:
3375 case TARGET_NR_statfs:
3376 p = lock_user_string(arg1);
3377 ret = get_errno(statfs(path(p), &stfs));
3378 unlock_user(p, arg1, 0);
3380 if (!is_error(ret)) {
3381 struct target_statfs *target_stfs;
3383 lock_user_struct(target_stfs, arg2, 0);
3384 /* ??? put_user is probably wrong. */
3385 put_user(stfs.f_type, &target_stfs->f_type);
3386 put_user(stfs.f_bsize, &target_stfs->f_bsize);
3387 put_user(stfs.f_blocks, &target_stfs->f_blocks);
3388 put_user(stfs.f_bfree, &target_stfs->f_bfree);
3389 put_user(stfs.f_bavail, &target_stfs->f_bavail);
3390 put_user(stfs.f_files, &target_stfs->f_files);
3391 put_user(stfs.f_ffree, &target_stfs->f_ffree);
3392 put_user(stfs.f_fsid.__val[0], &target_stfs->f_fsid.val[0]);
3393 put_user(stfs.f_fsid.__val[1], &target_stfs->f_fsid.val[1]);
3394 put_user(stfs.f_namelen, &target_stfs->f_namelen);
3395 unlock_user_struct(target_stfs, arg2, 1);
3398 case TARGET_NR_fstatfs:
3399 ret = get_errno(fstatfs(arg1, &stfs));
3400 goto convert_statfs;
3401 #ifdef TARGET_NR_statfs64
3402 case TARGET_NR_statfs64:
3403 p = lock_user_string(arg1);
3404 ret = get_errno(statfs(path(p), &stfs));
3405 unlock_user(p, arg1, 0);
3407 if (!is_error(ret)) {
3408 struct target_statfs64 *target_stfs;
3410 lock_user_struct(target_stfs, arg3, 0);
3411 /* ??? put_user is probably wrong. */
3412 put_user(stfs.f_type, &target_stfs->f_type);
3413 put_user(stfs.f_bsize, &target_stfs->f_bsize);
3414 put_user(stfs.f_blocks, &target_stfs->f_blocks);
3415 put_user(stfs.f_bfree, &target_stfs->f_bfree);
3416 put_user(stfs.f_bavail, &target_stfs->f_bavail);
3417 put_user(stfs.f_files, &target_stfs->f_files);
3418 put_user(stfs.f_ffree, &target_stfs->f_ffree);
3419 put_user(stfs.f_fsid.__val[0], &target_stfs->f_fsid.val[0]);
3420 put_user(stfs.f_fsid.__val[1], &target_stfs->f_fsid.val[1]);
3421 put_user(stfs.f_namelen, &target_stfs->f_namelen);
3422 unlock_user_struct(target_stfs, arg3, 0);
3425 case TARGET_NR_fstatfs64:
3426 ret = get_errno(fstatfs(arg1, &stfs));
3427 goto convert_statfs64;
3429 #ifdef TARGET_NR_ioperm
3430 case TARGET_NR_ioperm:
3433 #ifdef TARGET_NR_socketcall
3434 case TARGET_NR_socketcall:
3435 ret = do_socketcall(arg1, arg2);
3438 #ifdef TARGET_NR_accept
3439 case TARGET_NR_accept:
3440 ret = do_accept(arg1, arg2, arg3);
3443 #ifdef TARGET_NR_bind
3444 case TARGET_NR_bind:
3445 ret = do_bind(arg1, arg2, arg3);
3448 #ifdef TARGET_NR_connect
3449 case TARGET_NR_connect:
3450 ret = do_connect(arg1, arg2, arg3);
3453 #ifdef TARGET_NR_getpeername
3454 case TARGET_NR_getpeername:
3455 ret = do_getpeername(arg1, arg2, arg3);
3458 #ifdef TARGET_NR_getsockname
3459 case TARGET_NR_getsockname:
3460 ret = do_getsockname(arg1, arg2, arg3);
3463 #ifdef TARGET_NR_getsockopt
3464 case TARGET_NR_getsockopt:
3465 ret = do_getsockopt(arg1, arg2, arg3, arg4, arg5);
3468 #ifdef TARGET_NR_listen
3469 case TARGET_NR_listen:
3470 ret = get_errno(listen(arg1, arg2));
3473 #ifdef TARGET_NR_recv
3474 case TARGET_NR_recv:
3475 ret = do_recvfrom(arg1, arg2, arg3, arg4, 0, 0);
3478 #ifdef TARGET_NR_recvfrom
3479 case TARGET_NR_recvfrom:
3480 ret = do_recvfrom(arg1, arg2, arg3, arg4, arg5, arg6);
3483 #ifdef TARGET_NR_recvmsg
3484 case TARGET_NR_recvmsg:
3485 ret = do_sendrecvmsg(arg1, arg2, arg3, 0);
3488 #ifdef TARGET_NR_send
3489 case TARGET_NR_send:
3490 ret = do_sendto(arg1, arg2, arg3, arg4, 0, 0);
3493 #ifdef TARGET_NR_sendmsg
3494 case TARGET_NR_sendmsg:
3495 ret = do_sendrecvmsg(arg1, arg2, arg3, 1);
3498 #ifdef TARGET_NR_sendto
3499 case TARGET_NR_sendto:
3500 ret = do_sendto(arg1, arg2, arg3, arg4, arg5, arg6);
3503 #ifdef TARGET_NR_shutdown
3504 case TARGET_NR_shutdown:
3505 ret = get_errno(shutdown(arg1, arg2));
3508 #ifdef TARGET_NR_socket
3509 case TARGET_NR_socket:
3510 ret = do_socket(arg1, arg2, arg3);
3513 #ifdef TARGET_NR_socketpair
3514 case TARGET_NR_socketpair:
3515 ret = do_socketpair(arg1, arg2, arg3, arg4);
3518 #ifdef TARGET_NR_setsockopt
3519 case TARGET_NR_setsockopt:
3520 ret = do_setsockopt(arg1, arg2, arg3, arg4, (socklen_t) arg5);
3524 case TARGET_NR_syslog:
3525 p = lock_user_string(arg2);
3526 ret = get_errno(sys_syslog((int)arg1, p, (int)arg3));
3527 unlock_user(p, arg2, 0);
3530 case TARGET_NR_setitimer:
3532 struct itimerval value, ovalue, *pvalue;
3536 target_to_host_timeval(&pvalue->it_interval,
3538 target_to_host_timeval(&pvalue->it_value,
3539 arg2 + sizeof(struct target_timeval));
3543 ret = get_errno(setitimer(arg1, pvalue, &ovalue));
3544 if (!is_error(ret) && arg3) {
3545 host_to_target_timeval(arg3,
3546 &ovalue.it_interval);
3547 host_to_target_timeval(arg3 + sizeof(struct target_timeval),
3552 case TARGET_NR_getitimer:
3554 struct itimerval value;
3556 ret = get_errno(getitimer(arg1, &value));
3557 if (!is_error(ret) && arg2) {
3558 host_to_target_timeval(arg2,
3559 &value.it_interval);
3560 host_to_target_timeval(arg2 + sizeof(struct target_timeval),
3565 case TARGET_NR_stat:
3566 p = lock_user_string(arg1);
3567 ret = get_errno(stat(path(p), &st));
3568 unlock_user(p, arg1, 0);
3570 case TARGET_NR_lstat:
3571 p = lock_user_string(arg1);
3572 ret = get_errno(lstat(path(p), &st));
3573 unlock_user(p, arg1, 0);
3575 case TARGET_NR_fstat:
3577 ret = get_errno(fstat(arg1, &st));
3579 if (!is_error(ret)) {
3580 struct target_stat *target_st;
3582 lock_user_struct(target_st, arg2, 0);
3583 #if defined(TARGET_MIPS) || defined(TARGET_SPARC64)
3584 target_st->st_dev = tswap32(st.st_dev);
3586 target_st->st_dev = tswap16(st.st_dev);
3588 target_st->st_ino = tswapl(st.st_ino);
3589 #if defined(TARGET_PPC) || defined(TARGET_MIPS)
3590 target_st->st_mode = tswapl(st.st_mode); /* XXX: check this */
3591 target_st->st_uid = tswap32(st.st_uid);
3592 target_st->st_gid = tswap32(st.st_gid);
3593 #elif defined(TARGET_SPARC64)
3594 target_st->st_mode = tswap32(st.st_mode);
3595 target_st->st_uid = tswap32(st.st_uid);
3596 target_st->st_gid = tswap32(st.st_gid);
3598 target_st->st_mode = tswap16(st.st_mode);
3599 target_st->st_uid = tswap16(st.st_uid);
3600 target_st->st_gid = tswap16(st.st_gid);
3602 #if defined(TARGET_MIPS)
3603 /* If this is the same on PPC, then just merge w/ the above ifdef */
3604 target_st->st_nlink = tswapl(st.st_nlink);
3605 target_st->st_rdev = tswapl(st.st_rdev);
3606 #elif defined(TARGET_SPARC64)
3607 target_st->st_nlink = tswap32(st.st_nlink);
3608 target_st->st_rdev = tswap32(st.st_rdev);
3610 target_st->st_nlink = tswap16(st.st_nlink);
3611 target_st->st_rdev = tswap16(st.st_rdev);
3613 target_st->st_size = tswapl(st.st_size);
3614 target_st->st_blksize = tswapl(st.st_blksize);
3615 target_st->st_blocks = tswapl(st.st_blocks);
3616 target_st->target_st_atime = tswapl(st.st_atime);
3617 target_st->target_st_mtime = tswapl(st.st_mtime);
3618 target_st->target_st_ctime = tswapl(st.st_ctime);
3619 unlock_user_struct(target_st, arg2, 1);
3623 #ifdef TARGET_NR_olduname
3624 case TARGET_NR_olduname:
3627 #ifdef TARGET_NR_iopl
3628 case TARGET_NR_iopl:
3631 case TARGET_NR_vhangup:
3632 ret = get_errno(vhangup());
3634 #ifdef TARGET_NR_idle
3635 case TARGET_NR_idle:
3638 #ifdef TARGET_NR_syscall
3639 case TARGET_NR_syscall:
3640 ret = do_syscall(cpu_env,arg1 & 0xffff,arg2,arg3,arg4,arg5,arg6,0);
3643 case TARGET_NR_wait4:
3646 target_long status_ptr = arg2;
3647 struct rusage rusage, *rusage_ptr;
3648 target_ulong target_rusage = arg4;
3650 rusage_ptr = &rusage;
3653 ret = get_errno(wait4(arg1, &status, arg3, rusage_ptr));
3654 if (!is_error(ret)) {
3656 tputl(status_ptr, status);
3657 if (target_rusage) {
3658 host_to_target_rusage(target_rusage, &rusage);
3663 #ifdef TARGET_NR_swapoff
3664 case TARGET_NR_swapoff:
3665 p = lock_user_string(arg1);
3666 ret = get_errno(swapoff(p));
3667 unlock_user(p, arg1, 0);
3670 case TARGET_NR_sysinfo:
3672 struct target_sysinfo *target_value;
3673 struct sysinfo value;
3674 ret = get_errno(sysinfo(&value));
3675 if (!is_error(ret) && arg1)
3677 /* ??? __put_user is probably wrong. */
3678 lock_user_struct(target_value, arg1, 0);
3679 __put_user(value.uptime, &target_value->uptime);
3680 __put_user(value.loads[0], &target_value->loads[0]);
3681 __put_user(value.loads[1], &target_value->loads[1]);
3682 __put_user(value.loads[2], &target_value->loads[2]);
3683 __put_user(value.totalram, &target_value->totalram);
3684 __put_user(value.freeram, &target_value->freeram);
3685 __put_user(value.sharedram, &target_value->sharedram);
3686 __put_user(value.bufferram, &target_value->bufferram);
3687 __put_user(value.totalswap, &target_value->totalswap);
3688 __put_user(value.freeswap, &target_value->freeswap);
3689 __put_user(value.procs, &target_value->procs);
3690 __put_user(value.totalhigh, &target_value->totalhigh);
3691 __put_user(value.freehigh, &target_value->freehigh);
3692 __put_user(value.mem_unit, &target_value->mem_unit);
3693 unlock_user_struct(target_value, arg1, 1);
3697 #ifdef TARGET_NR_ipc
3699 ret = do_ipc(arg1, arg2, arg3, arg4, arg5, arg6);
3702 case TARGET_NR_fsync:
3703 ret = get_errno(fsync(arg1));
3705 case TARGET_NR_clone:
3706 ret = get_errno(do_fork(cpu_env, arg1, arg2));
3708 #ifdef __NR_exit_group
3709 /* new thread calls */
3710 case TARGET_NR_exit_group:
3711 gdb_exit(cpu_env, arg1);
3712 ret = get_errno(exit_group(arg1));
3715 case TARGET_NR_setdomainname:
3716 p = lock_user_string(arg1);
3717 ret = get_errno(setdomainname(p, arg2));
3718 unlock_user(p, arg1, 0);
3720 case TARGET_NR_uname:
3721 /* no need to transcode because we use the linux syscall */
3723 struct new_utsname * buf;
3725 lock_user_struct(buf, arg1, 0);
3726 ret = get_errno(sys_uname(buf));
3727 if (!is_error(ret)) {
3728 /* Overrite the native machine name with whatever is being
3730 strcpy (buf->machine, UNAME_MACHINE);
3731 /* Allow the user to override the reported release. */
3732 if (qemu_uname_release && *qemu_uname_release)
3733 strcpy (buf->release, qemu_uname_release);
3735 unlock_user_struct(buf, arg1, 1);
3739 case TARGET_NR_modify_ldt:
3740 ret = get_errno(do_modify_ldt(cpu_env, arg1, arg2, arg3));
3742 #if !defined(TARGET_X86_64)
3743 case TARGET_NR_vm86old:
3745 case TARGET_NR_vm86:
3746 ret = do_vm86(cpu_env, arg1, arg2);
3750 case TARGET_NR_adjtimex:
3752 #ifdef TARGET_NR_create_module
3753 case TARGET_NR_create_module:
3755 case TARGET_NR_init_module:
3756 case TARGET_NR_delete_module:
3757 #ifdef TARGET_NR_get_kernel_syms
3758 case TARGET_NR_get_kernel_syms:
3761 case TARGET_NR_quotactl:
3763 case TARGET_NR_getpgid:
3764 ret = get_errno(getpgid(arg1));
3766 case TARGET_NR_fchdir:
3767 ret = get_errno(fchdir(arg1));
3769 #ifdef TARGET_NR_bdflush /* not on x86_64 */
3770 case TARGET_NR_bdflush:
3773 #ifdef TARGET_NR_sysfs
3774 case TARGET_NR_sysfs:
3777 case TARGET_NR_personality:
3778 ret = get_errno(personality(arg1));
3780 #ifdef TARGET_NR_afs_syscall
3781 case TARGET_NR_afs_syscall:
3784 #ifdef TARGET_NR__llseek /* Not on alpha */
3785 case TARGET_NR__llseek:
3787 #if defined (__x86_64__)
3788 ret = get_errno(lseek(arg1, ((uint64_t )arg2 << 32) | arg3, arg5));
3792 ret = get_errno(_llseek(arg1, arg2, arg3, &res, arg5));
3798 case TARGET_NR_getdents:
3799 #if TARGET_LONG_SIZE != 4
3801 #warning not supported
3802 #elif TARGET_LONG_SIZE == 4 && HOST_LONG_SIZE == 8
3804 struct target_dirent *target_dirp;
3805 struct dirent *dirp;
3808 dirp = malloc(count);
3812 ret = get_errno(sys_getdents(arg1, dirp, count));
3813 if (!is_error(ret)) {
3815 struct target_dirent *tde;
3817 int reclen, treclen;
3818 int count1, tnamelen;
3822 target_dirp = lock_user(arg2, count, 0);
3825 reclen = de->d_reclen;
3826 treclen = reclen - (2 * (sizeof(long) - sizeof(target_long)));
3827 tde->d_reclen = tswap16(treclen);
3828 tde->d_ino = tswapl(de->d_ino);
3829 tde->d_off = tswapl(de->d_off);
3830 tnamelen = treclen - (2 * sizeof(target_long) + 2);
3833 /* XXX: may not be correct */
3834 strncpy(tde->d_name, de->d_name, tnamelen);
3835 de = (struct dirent *)((char *)de + reclen);
3837 tde = (struct target_dirent *)((char *)tde + treclen);
3842 unlock_user(target_dirp, arg2, ret);
3847 struct dirent *dirp;
3850 dirp = lock_user(arg2, count, 0);
3851 ret = get_errno(sys_getdents(arg1, dirp, count));
3852 if (!is_error(ret)) {
3858 reclen = de->d_reclen;
3861 de->d_reclen = tswap16(reclen);
3862 tswapls(&de->d_ino);
3863 tswapls(&de->d_off);
3864 de = (struct dirent *)((char *)de + reclen);
3868 unlock_user(dirp, arg2, ret);
3872 #if defined(TARGET_NR_getdents64) && defined(__NR_getdents64)
3873 case TARGET_NR_getdents64:
3875 struct dirent64 *dirp;
3877 dirp = lock_user(arg2, count, 0);
3878 ret = get_errno(sys_getdents64(arg1, dirp, count));
3879 if (!is_error(ret)) {
3880 struct dirent64 *de;
3885 reclen = de->d_reclen;
3888 de->d_reclen = tswap16(reclen);
3889 tswap64s(&de->d_ino);
3890 tswap64s(&de->d_off);
3891 de = (struct dirent64 *)((char *)de + reclen);
3895 unlock_user(dirp, arg2, ret);
3898 #endif /* TARGET_NR_getdents64 */
3899 #ifdef TARGET_NR__newselect
3900 case TARGET_NR__newselect:
3901 ret = do_select(arg1, arg2, arg3, arg4, arg5);
3904 #ifdef TARGET_NR_poll
3905 case TARGET_NR_poll:
3907 struct target_pollfd *target_pfd;
3908 unsigned int nfds = arg2;
3913 target_pfd = lock_user(arg1, sizeof(struct target_pollfd) * nfds, 1);
3914 pfd = alloca(sizeof(struct pollfd) * nfds);
3915 for(i = 0; i < nfds; i++) {
3916 pfd[i].fd = tswap32(target_pfd[i].fd);
3917 pfd[i].events = tswap16(target_pfd[i].events);
3919 ret = get_errno(poll(pfd, nfds, timeout));
3920 if (!is_error(ret)) {
3921 for(i = 0; i < nfds; i++) {
3922 target_pfd[i].revents = tswap16(pfd[i].revents);
3924 ret += nfds * (sizeof(struct target_pollfd)
3925 - sizeof(struct pollfd));
3927 unlock_user(target_pfd, arg1, ret);
3931 case TARGET_NR_flock:
3932 /* NOTE: the flock constant seems to be the same for every
3934 ret = get_errno(flock(arg1, arg2));
3936 case TARGET_NR_readv:
3941 vec = alloca(count * sizeof(struct iovec));
3942 lock_iovec(vec, arg2, count, 0);
3943 ret = get_errno(readv(arg1, vec, count));
3944 unlock_iovec(vec, arg2, count, 1);
3947 case TARGET_NR_writev:
3952 vec = alloca(count * sizeof(struct iovec));
3953 lock_iovec(vec, arg2, count, 1);
3954 ret = get_errno(writev(arg1, vec, count));
3955 unlock_iovec(vec, arg2, count, 0);
3958 case TARGET_NR_getsid:
3959 ret = get_errno(getsid(arg1));
3961 #if defined(TARGET_NR_fdatasync) /* Not on alpha (osf_datasync ?) */
3962 case TARGET_NR_fdatasync:
3963 ret = get_errno(fdatasync(arg1));
3966 case TARGET_NR__sysctl:
3967 /* We don't implement this, but ENODIR is always a safe
3970 case TARGET_NR_sched_setparam:
3972 struct sched_param *target_schp;
3973 struct sched_param schp;
3975 lock_user_struct(target_schp, arg2, 1);
3976 schp.sched_priority = tswap32(target_schp->sched_priority);
3977 unlock_user_struct(target_schp, arg2, 0);
3978 ret = get_errno(sched_setparam(arg1, &schp));
3981 case TARGET_NR_sched_getparam:
3983 struct sched_param *target_schp;
3984 struct sched_param schp;
3985 ret = get_errno(sched_getparam(arg1, &schp));
3986 if (!is_error(ret)) {
3987 lock_user_struct(target_schp, arg2, 0);
3988 target_schp->sched_priority = tswap32(schp.sched_priority);
3989 unlock_user_struct(target_schp, arg2, 1);
3993 case TARGET_NR_sched_setscheduler:
3995 struct sched_param *target_schp;
3996 struct sched_param schp;
3997 lock_user_struct(target_schp, arg3, 1);
3998 schp.sched_priority = tswap32(target_schp->sched_priority);
3999 unlock_user_struct(target_schp, arg3, 0);
4000 ret = get_errno(sched_setscheduler(arg1, arg2, &schp));
4003 case TARGET_NR_sched_getscheduler:
4004 ret = get_errno(sched_getscheduler(arg1));
4006 case TARGET_NR_sched_yield:
4007 ret = get_errno(sched_yield());
4009 case TARGET_NR_sched_get_priority_max:
4010 ret = get_errno(sched_get_priority_max(arg1));
4012 case TARGET_NR_sched_get_priority_min:
4013 ret = get_errno(sched_get_priority_min(arg1));
4015 case TARGET_NR_sched_rr_get_interval:
4018 ret = get_errno(sched_rr_get_interval(arg1, &ts));
4019 if (!is_error(ret)) {
4020 host_to_target_timespec(arg2, &ts);
4024 case TARGET_NR_nanosleep:
4026 struct timespec req, rem;
4027 target_to_host_timespec(&req, arg1);
4028 ret = get_errno(nanosleep(&req, &rem));
4029 if (is_error(ret) && arg2) {
4030 host_to_target_timespec(arg2, &rem);
4034 #ifdef TARGET_NR_query_module
4035 case TARGET_NR_query_module:
4038 #ifdef TARGET_NR_nfsservctl
4039 case TARGET_NR_nfsservctl:
4042 case TARGET_NR_prctl:
4045 case PR_GET_PDEATHSIG:
4048 ret = get_errno(prctl(arg1, &deathsig, arg3, arg4, arg5));
4049 if (!is_error(ret) && arg2)
4050 tput32(arg2, deathsig);
4054 ret = get_errno(prctl(arg1, arg2, arg3, arg4, arg5));
4058 #ifdef TARGET_NR_pread
4059 case TARGET_NR_pread:
4060 page_unprotect_range(arg2, arg3);
4061 p = lock_user(arg2, arg3, 0);
4062 ret = get_errno(pread(arg1, p, arg3, arg4));
4063 unlock_user(p, arg2, ret);
4065 case TARGET_NR_pwrite:
4066 p = lock_user(arg2, arg3, 1);
4067 ret = get_errno(pwrite(arg1, p, arg3, arg4));
4068 unlock_user(p, arg2, 0);
4071 case TARGET_NR_getcwd:
4072 p = lock_user(arg1, arg2, 0);
4073 ret = get_errno(sys_getcwd1(p, arg2));
4074 unlock_user(p, arg1, ret);
4076 case TARGET_NR_capget:
4078 case TARGET_NR_capset:
4080 case TARGET_NR_sigaltstack:
4082 case TARGET_NR_sendfile:
4084 #ifdef TARGET_NR_getpmsg
4085 case TARGET_NR_getpmsg:
4088 #ifdef TARGET_NR_putpmsg
4089 case TARGET_NR_putpmsg:
4092 #ifdef TARGET_NR_vfork
4093 case TARGET_NR_vfork:
4094 ret = get_errno(do_fork(cpu_env, CLONE_VFORK | CLONE_VM | SIGCHLD, 0));
4097 #ifdef TARGET_NR_ugetrlimit
4098 case TARGET_NR_ugetrlimit:
4101 ret = get_errno(getrlimit(arg1, &rlim));
4102 if (!is_error(ret)) {
4103 struct target_rlimit *target_rlim;
4104 lock_user_struct(target_rlim, arg2, 0);
4105 target_rlim->rlim_cur = tswapl(rlim.rlim_cur);
4106 target_rlim->rlim_max = tswapl(rlim.rlim_max);
4107 unlock_user_struct(target_rlim, arg2, 1);
4112 #ifdef TARGET_NR_truncate64
4113 case TARGET_NR_truncate64:
4114 p = lock_user_string(arg1);
4115 ret = target_truncate64(cpu_env, p, arg2, arg3, arg4);
4116 unlock_user(p, arg1, 0);
4119 #ifdef TARGET_NR_ftruncate64
4120 case TARGET_NR_ftruncate64:
4121 ret = target_ftruncate64(cpu_env, arg1, arg2, arg3, arg4);
4124 #ifdef TARGET_NR_stat64
4125 case TARGET_NR_stat64:
4126 p = lock_user_string(arg1);
4127 ret = get_errno(stat(path(p), &st));
4128 unlock_user(p, arg1, 0);
4131 #ifdef TARGET_NR_lstat64
4132 case TARGET_NR_lstat64:
4133 p = lock_user_string(arg1);
4134 ret = get_errno(lstat(path(p), &st));
4135 unlock_user(p, arg1, 0);
4138 #ifdef TARGET_NR_fstat64
4139 case TARGET_NR_fstat64:
4141 ret = get_errno(fstat(arg1, &st));
4143 if (!is_error(ret)) {
4145 if (((CPUARMState *)cpu_env)->eabi) {
4146 struct target_eabi_stat64 *target_st;
4147 lock_user_struct(target_st, arg2, 1);
4148 memset(target_st, 0, sizeof(struct target_eabi_stat64));
4149 /* put_user is probably wrong. */
4150 put_user(st.st_dev, &target_st->st_dev);
4151 put_user(st.st_ino, &target_st->st_ino);
4152 #ifdef TARGET_STAT64_HAS_BROKEN_ST_INO
4153 put_user(st.st_ino, &target_st->__st_ino);
4155 put_user(st.st_mode, &target_st->st_mode);
4156 put_user(st.st_nlink, &target_st->st_nlink);
4157 put_user(st.st_uid, &target_st->st_uid);
4158 put_user(st.st_gid, &target_st->st_gid);
4159 put_user(st.st_rdev, &target_st->st_rdev);
4160 /* XXX: better use of kernel struct */
4161 put_user(st.st_size, &target_st->st_size);
4162 put_user(st.st_blksize, &target_st->st_blksize);
4163 put_user(st.st_blocks, &target_st->st_blocks);
4164 put_user(st.st_atime, &target_st->target_st_atime);
4165 put_user(st.st_mtime, &target_st->target_st_mtime);
4166 put_user(st.st_ctime, &target_st->target_st_ctime);
4167 unlock_user_struct(target_st, arg2, 0);
4171 struct target_stat64 *target_st;
4172 lock_user_struct(target_st, arg2, 1);
4173 memset(target_st, 0, sizeof(struct target_stat64));
4174 /* ??? put_user is probably wrong. */
4175 put_user(st.st_dev, &target_st->st_dev);
4176 put_user(st.st_ino, &target_st->st_ino);
4177 #ifdef TARGET_STAT64_HAS_BROKEN_ST_INO
4178 put_user(st.st_ino, &target_st->__st_ino);
4180 put_user(st.st_mode, &target_st->st_mode);
4181 put_user(st.st_nlink, &target_st->st_nlink);
4182 put_user(st.st_uid, &target_st->st_uid);
4183 put_user(st.st_gid, &target_st->st_gid);
4184 put_user(st.st_rdev, &target_st->st_rdev);
4185 /* XXX: better use of kernel struct */
4186 put_user(st.st_size, &target_st->st_size);
4187 put_user(st.st_blksize, &target_st->st_blksize);
4188 put_user(st.st_blocks, &target_st->st_blocks);
4189 put_user(st.st_atime, &target_st->target_st_atime);
4190 put_user(st.st_mtime, &target_st->target_st_mtime);
4191 put_user(st.st_ctime, &target_st->target_st_ctime);
4192 unlock_user_struct(target_st, arg2, 0);
4199 case TARGET_NR_lchown:
4200 p = lock_user_string(arg1);
4201 ret = get_errno(lchown(p, low2highuid(arg2), low2highgid(arg3)));
4202 unlock_user(p, arg1, 0);
4204 case TARGET_NR_getuid:
4205 ret = get_errno(high2lowuid(getuid()));
4207 case TARGET_NR_getgid:
4208 ret = get_errno(high2lowgid(getgid()));
4210 case TARGET_NR_geteuid:
4211 ret = get_errno(high2lowuid(geteuid()));
4213 case TARGET_NR_getegid:
4214 ret = get_errno(high2lowgid(getegid()));
4216 case TARGET_NR_setreuid:
4217 ret = get_errno(setreuid(low2highuid(arg1), low2highuid(arg2)));
4219 case TARGET_NR_setregid:
4220 ret = get_errno(setregid(low2highgid(arg1), low2highgid(arg2)));
4222 case TARGET_NR_getgroups:
4224 int gidsetsize = arg1;
4225 uint16_t *target_grouplist;
4229 grouplist = alloca(gidsetsize * sizeof(gid_t));
4230 ret = get_errno(getgroups(gidsetsize, grouplist));
4231 if (!is_error(ret)) {
4232 target_grouplist = lock_user(arg2, gidsetsize * 2, 0);
4233 for(i = 0;i < gidsetsize; i++)
4234 target_grouplist[i] = tswap16(grouplist[i]);
4235 unlock_user(target_grouplist, arg2, gidsetsize * 2);
4239 case TARGET_NR_setgroups:
4241 int gidsetsize = arg1;
4242 uint16_t *target_grouplist;
4246 grouplist = alloca(gidsetsize * sizeof(gid_t));
4247 target_grouplist = lock_user(arg2, gidsetsize * 2, 1);
4248 for(i = 0;i < gidsetsize; i++)
4249 grouplist[i] = tswap16(target_grouplist[i]);
4250 unlock_user(target_grouplist, arg2, 0);
4251 ret = get_errno(setgroups(gidsetsize, grouplist));
4254 case TARGET_NR_fchown:
4255 ret = get_errno(fchown(arg1, low2highuid(arg2), low2highgid(arg3)));
4257 #ifdef TARGET_NR_setresuid
4258 case TARGET_NR_setresuid:
4259 ret = get_errno(setresuid(low2highuid(arg1),
4261 low2highuid(arg3)));
4264 #ifdef TARGET_NR_getresuid
4265 case TARGET_NR_getresuid:
4267 uid_t ruid, euid, suid;
4268 ret = get_errno(getresuid(&ruid, &euid, &suid));
4269 if (!is_error(ret)) {
4270 tput16(arg1, tswap16(high2lowuid(ruid)));
4271 tput16(arg2, tswap16(high2lowuid(euid)));
4272 tput16(arg3, tswap16(high2lowuid(suid)));
4277 #ifdef TARGET_NR_getresgid
4278 case TARGET_NR_setresgid:
4279 ret = get_errno(setresgid(low2highgid(arg1),
4281 low2highgid(arg3)));
4284 #ifdef TARGET_NR_getresgid
4285 case TARGET_NR_getresgid:
4287 gid_t rgid, egid, sgid;
4288 ret = get_errno(getresgid(&rgid, &egid, &sgid));
4289 if (!is_error(ret)) {
4290 tput16(arg1, tswap16(high2lowgid(rgid)));
4291 tput16(arg2, tswap16(high2lowgid(egid)));
4292 tput16(arg3, tswap16(high2lowgid(sgid)));
4297 case TARGET_NR_chown:
4298 p = lock_user_string(arg1);
4299 ret = get_errno(chown(p, low2highuid(arg2), low2highgid(arg3)));
4300 unlock_user(p, arg1, 0);
4302 case TARGET_NR_setuid:
4303 ret = get_errno(setuid(low2highuid(arg1)));
4305 case TARGET_NR_setgid:
4306 ret = get_errno(setgid(low2highgid(arg1)));
4308 case TARGET_NR_setfsuid:
4309 ret = get_errno(setfsuid(arg1));
4311 case TARGET_NR_setfsgid:
4312 ret = get_errno(setfsgid(arg1));
4314 #endif /* USE_UID16 */
4316 #ifdef TARGET_NR_lchown32
4317 case TARGET_NR_lchown32:
4318 p = lock_user_string(arg1);
4319 ret = get_errno(lchown(p, arg2, arg3));
4320 unlock_user(p, arg1, 0);
4323 #ifdef TARGET_NR_getuid32
4324 case TARGET_NR_getuid32:
4325 ret = get_errno(getuid());
4328 #ifdef TARGET_NR_getgid32
4329 case TARGET_NR_getgid32:
4330 ret = get_errno(getgid());
4333 #ifdef TARGET_NR_geteuid32
4334 case TARGET_NR_geteuid32:
4335 ret = get_errno(geteuid());
4338 #ifdef TARGET_NR_getegid32
4339 case TARGET_NR_getegid32:
4340 ret = get_errno(getegid());
4343 #ifdef TARGET_NR_setreuid32
4344 case TARGET_NR_setreuid32:
4345 ret = get_errno(setreuid(arg1, arg2));
4348 #ifdef TARGET_NR_setregid32
4349 case TARGET_NR_setregid32:
4350 ret = get_errno(setregid(arg1, arg2));
4353 #ifdef TARGET_NR_getgroups32
4354 case TARGET_NR_getgroups32:
4356 int gidsetsize = arg1;
4357 uint32_t *target_grouplist;
4361 grouplist = alloca(gidsetsize * sizeof(gid_t));
4362 ret = get_errno(getgroups(gidsetsize, grouplist));
4363 if (!is_error(ret)) {
4364 target_grouplist = lock_user(arg2, gidsetsize * 4, 0);
4365 for(i = 0;i < gidsetsize; i++)
4366 target_grouplist[i] = tswap32(grouplist[i]);
4367 unlock_user(target_grouplist, arg2, gidsetsize * 4);
4372 #ifdef TARGET_NR_setgroups32
4373 case TARGET_NR_setgroups32:
4375 int gidsetsize = arg1;
4376 uint32_t *target_grouplist;
4380 grouplist = alloca(gidsetsize * sizeof(gid_t));
4381 target_grouplist = lock_user(arg2, gidsetsize * 4, 1);
4382 for(i = 0;i < gidsetsize; i++)
4383 grouplist[i] = tswap32(target_grouplist[i]);
4384 unlock_user(target_grouplist, arg2, 0);
4385 ret = get_errno(setgroups(gidsetsize, grouplist));
4389 #ifdef TARGET_NR_fchown32
4390 case TARGET_NR_fchown32:
4391 ret = get_errno(fchown(arg1, arg2, arg3));
4394 #ifdef TARGET_NR_setresuid32
4395 case TARGET_NR_setresuid32:
4396 ret = get_errno(setresuid(arg1, arg2, arg3));
4399 #ifdef TARGET_NR_getresuid32
4400 case TARGET_NR_getresuid32:
4402 uid_t ruid, euid, suid;
4403 ret = get_errno(getresuid(&ruid, &euid, &suid));
4404 if (!is_error(ret)) {
4405 tput32(arg1, tswap32(ruid));
4406 tput32(arg2, tswap32(euid));
4407 tput32(arg3, tswap32(suid));
4412 #ifdef TARGET_NR_setresgid32
4413 case TARGET_NR_setresgid32:
4414 ret = get_errno(setresgid(arg1, arg2, arg3));
4417 #ifdef TARGET_NR_getresgid32
4418 case TARGET_NR_getresgid32:
4420 gid_t rgid, egid, sgid;
4421 ret = get_errno(getresgid(&rgid, &egid, &sgid));
4422 if (!is_error(ret)) {
4423 tput32(arg1, tswap32(rgid));
4424 tput32(arg2, tswap32(egid));
4425 tput32(arg3, tswap32(sgid));
4430 #ifdef TARGET_NR_chown32
4431 case TARGET_NR_chown32:
4432 p = lock_user_string(arg1);
4433 ret = get_errno(chown(p, arg2, arg3));
4434 unlock_user(p, arg1, 0);
4437 #ifdef TARGET_NR_setuid32
4438 case TARGET_NR_setuid32:
4439 ret = get_errno(setuid(arg1));
4442 #ifdef TARGET_NR_setgid32
4443 case TARGET_NR_setgid32:
4444 ret = get_errno(setgid(arg1));
4447 #ifdef TARGET_NR_setfsuid32
4448 case TARGET_NR_setfsuid32:
4449 ret = get_errno(setfsuid(arg1));
4452 #ifdef TARGET_NR_setfsgid32
4453 case TARGET_NR_setfsgid32:
4454 ret = get_errno(setfsgid(arg1));
4458 case TARGET_NR_pivot_root:
4460 #ifdef TARGET_NR_mincore
4461 case TARGET_NR_mincore:
4464 #ifdef TARGET_NR_madvise
4465 case TARGET_NR_madvise:
4466 /* A straight passthrough may not be safe because qemu sometimes
4467 turns private flie-backed mappings into anonymous mappings.
4468 This will break MADV_DONTNEED.
4469 This is a hint, so ignoring and returning success is ok. */
4473 #if TARGET_LONG_BITS == 32
4474 case TARGET_NR_fcntl64:
4478 struct target_flock64 *target_fl;
4480 struct target_eabi_flock64 *target_efl;
4484 case TARGET_F_GETLK64:
4487 case TARGET_F_SETLK64:
4490 case TARGET_F_SETLKW64:
4499 case TARGET_F_GETLK64:
4501 if (((CPUARMState *)cpu_env)->eabi) {
4502 lock_user_struct(target_efl, arg3, 1);
4503 fl.l_type = tswap16(target_efl->l_type);
4504 fl.l_whence = tswap16(target_efl->l_whence);
4505 fl.l_start = tswap64(target_efl->l_start);
4506 fl.l_len = tswap64(target_efl->l_len);
4507 fl.l_pid = tswapl(target_efl->l_pid);
4508 unlock_user_struct(target_efl, arg3, 0);
4512 lock_user_struct(target_fl, arg3, 1);
4513 fl.l_type = tswap16(target_fl->l_type);
4514 fl.l_whence = tswap16(target_fl->l_whence);
4515 fl.l_start = tswap64(target_fl->l_start);
4516 fl.l_len = tswap64(target_fl->l_len);
4517 fl.l_pid = tswapl(target_fl->l_pid);
4518 unlock_user_struct(target_fl, arg3, 0);
4520 ret = get_errno(fcntl(arg1, cmd, &fl));
4523 if (((CPUARMState *)cpu_env)->eabi) {
4524 lock_user_struct(target_efl, arg3, 0);
4525 target_efl->l_type = tswap16(fl.l_type);
4526 target_efl->l_whence = tswap16(fl.l_whence);
4527 target_efl->l_start = tswap64(fl.l_start);
4528 target_efl->l_len = tswap64(fl.l_len);
4529 target_efl->l_pid = tswapl(fl.l_pid);
4530 unlock_user_struct(target_efl, arg3, 1);
4534 lock_user_struct(target_fl, arg3, 0);
4535 target_fl->l_type = tswap16(fl.l_type);
4536 target_fl->l_whence = tswap16(fl.l_whence);
4537 target_fl->l_start = tswap64(fl.l_start);
4538 target_fl->l_len = tswap64(fl.l_len);
4539 target_fl->l_pid = tswapl(fl.l_pid);
4540 unlock_user_struct(target_fl, arg3, 1);
4545 case TARGET_F_SETLK64:
4546 case TARGET_F_SETLKW64:
4548 if (((CPUARMState *)cpu_env)->eabi) {
4549 lock_user_struct(target_efl, arg3, 1);
4550 fl.l_type = tswap16(target_efl->l_type);
4551 fl.l_whence = tswap16(target_efl->l_whence);
4552 fl.l_start = tswap64(target_efl->l_start);
4553 fl.l_len = tswap64(target_efl->l_len);
4554 fl.l_pid = tswapl(target_efl->l_pid);
4555 unlock_user_struct(target_efl, arg3, 0);
4559 lock_user_struct(target_fl, arg3, 1);
4560 fl.l_type = tswap16(target_fl->l_type);
4561 fl.l_whence = tswap16(target_fl->l_whence);
4562 fl.l_start = tswap64(target_fl->l_start);
4563 fl.l_len = tswap64(target_fl->l_len);
4564 fl.l_pid = tswapl(target_fl->l_pid);
4565 unlock_user_struct(target_fl, arg3, 0);
4567 ret = get_errno(fcntl(arg1, cmd, &fl));
4570 ret = get_errno(do_fcntl(arg1, cmd, arg3));
4576 #ifdef TARGET_NR_cacheflush
4577 case TARGET_NR_cacheflush:
4578 /* self-modifying code is handled automatically, so nothing needed */
4582 #ifdef TARGET_NR_security
4583 case TARGET_NR_security:
4586 #ifdef TARGET_NR_getpagesize
4587 case TARGET_NR_getpagesize:
4588 ret = TARGET_PAGE_SIZE;
4591 case TARGET_NR_gettid:
4592 ret = get_errno(gettid());
4594 #ifdef TARGET_NR_readahead
4595 case TARGET_NR_readahead:
4598 #ifdef TARGET_NR_setxattr
4599 case TARGET_NR_setxattr:
4600 case TARGET_NR_lsetxattr:
4601 case TARGET_NR_fsetxattr:
4602 case TARGET_NR_getxattr:
4603 case TARGET_NR_lgetxattr:
4604 case TARGET_NR_fgetxattr:
4605 case TARGET_NR_listxattr:
4606 case TARGET_NR_llistxattr:
4607 case TARGET_NR_flistxattr:
4608 case TARGET_NR_removexattr:
4609 case TARGET_NR_lremovexattr:
4610 case TARGET_NR_fremovexattr:
4611 goto unimplemented_nowarn;
4613 #ifdef TARGET_NR_set_thread_area
4614 case TARGET_NR_set_thread_area:
4616 ((CPUMIPSState *) cpu_env)->tls_value = arg1;
4620 goto unimplemented_nowarn;
4623 #ifdef TARGET_NR_get_thread_area
4624 case TARGET_NR_get_thread_area:
4625 goto unimplemented_nowarn;
4627 #ifdef TARGET_NR_getdomainname
4628 case TARGET_NR_getdomainname:
4629 goto unimplemented_nowarn;
4632 #ifdef TARGET_NR_clock_gettime
4633 case TARGET_NR_clock_gettime:
4636 ret = get_errno(clock_gettime(arg1, &ts));
4637 if (!is_error(ret)) {
4638 host_to_target_timespec(arg2, &ts);
4643 #ifdef TARGET_NR_clock_getres
4644 case TARGET_NR_clock_getres:
4647 ret = get_errno(clock_getres(arg1, &ts));
4648 if (!is_error(ret)) {
4649 host_to_target_timespec(arg2, &ts);
4655 #if defined(TARGET_NR_set_tid_address) && defined(__NR_set_tid_address)
4656 case TARGET_NR_set_tid_address:
4657 ret = get_errno(set_tid_address((int *) arg1));
4661 #if defined(TARGET_NR_tkill) && defined(__NR_tkill)
4662 case TARGET_NR_tkill:
4663 ret = get_errno(sys_tkill((int)arg1, (int)arg2));
4667 #if defined(TARGET_NR_tgkill) && defined(__NR_tgkill)
4668 case TARGET_NR_tgkill:
4669 ret = get_errno(sys_tgkill((int)arg1, (int)arg2, (int)arg3));
4673 #ifdef TARGET_NR_set_robust_list
4674 case TARGET_NR_set_robust_list:
4675 goto unimplemented_nowarn;
4680 gemu_log("qemu: Unsupported syscall: %d\n", num);
4681 #if defined(TARGET_NR_setxattr) || defined(TARGET_NR_get_thread_area) || defined(TARGET_NR_getdomainname) || defined(TARGET_NR_set_robust_list)
4682 unimplemented_nowarn:
4689 gemu_log(" = %ld\n", ret);