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>
34 #include <sys/mount.h>
35 #include <sys/resource.h>
40 #include <sys/socket.h>
43 //#include <sys/user.h>
44 #include <netinet/tcp.h>
46 #define termios host_termios
47 #define winsize host_winsize
48 #define termio host_termio
49 #define sgttyb host_sgttyb /* same as target */
50 #define tchars host_tchars /* same as target */
51 #define ltchars host_ltchars /* same as target */
53 #include <linux/termios.h>
54 #include <linux/unistd.h>
55 #include <linux/utsname.h>
56 #include <linux/cdrom.h>
57 #include <linux/hdreg.h>
58 #include <linux/soundcard.h>
59 #include <linux/dirent.h>
66 #define PAGE_SIZE 4096
67 #define PAGE_MASK ~(PAGE_SIZE - 1)
70 //#include <linux/msdos_fs.h>
71 #define VFAT_IOCTL_READDIR_BOTH _IOR('r', 1, struct dirent [2])
72 #define VFAT_IOCTL_READDIR_SHORT _IOR('r', 2, struct dirent [2])
74 void host_to_target_siginfo(target_siginfo_t *tinfo, const siginfo_t *info);
75 void target_to_host_siginfo(siginfo_t *info, const target_siginfo_t *tinfo);
76 long do_sigreturn(CPUX86State *env);
77 long do_rt_sigreturn(CPUX86State *env);
79 #define __NR_sys_uname __NR_uname
80 #define __NR_sys_getcwd1 __NR_getcwd
81 #define __NR_sys_statfs __NR_statfs
82 #define __NR_sys_fstatfs __NR_fstatfs
83 #define __NR_sys_getdents __NR_getdents
84 #define __NR_sys_getdents64 __NR_getdents64
85 #define __NR_sys_rt_sigqueueinfo __NR_rt_sigqueueinfo
88 _syscall0(int, gettid)
90 static int gettid(void) {
94 _syscall1(int,sys_uname,struct new_utsname *,buf)
95 _syscall2(int,sys_getcwd1,char *,buf,size_t,size)
96 _syscall3(int, sys_getdents, uint, fd, struct dirent *, dirp, uint, count);
97 _syscall3(int, sys_getdents64, uint, fd, struct dirent64 *, dirp, uint, count);
98 _syscall5(int, _llseek, uint, fd, ulong, hi, ulong, lo,
99 loff_t *, res, uint, wh);
100 _syscall2(int,sys_statfs,const char *,path,struct kernel_statfs *,buf)
101 _syscall2(int,sys_fstatfs,int,fd,struct kernel_statfs *,buf)
102 _syscall3(int,sys_rt_sigqueueinfo,int,pid,int,sig,siginfo_t *,uinfo)
104 extern int personality(int);
105 extern int flock(int, int);
106 extern int setfsuid(int);
107 extern int setfsgid(int);
108 extern int setresuid(uid_t, uid_t, uid_t);
109 extern int getresuid(uid_t *, uid_t *, uid_t *);
110 extern int setresgid(gid_t, gid_t, gid_t);
111 extern int getresgid(gid_t *, gid_t *, gid_t *);
113 static inline long get_errno(long ret)
121 static inline int is_error(long ret)
123 return (unsigned long)ret >= (unsigned long)(-4096);
126 static char *target_brk;
127 static char *target_original_brk;
129 void target_set_brk(char *new_brk)
131 target_brk = new_brk;
132 target_original_brk = new_brk;
135 static long do_brk(char *new_brk)
142 return (long)target_brk;
143 if (new_brk < target_original_brk)
146 brk_page = (char *)(((unsigned long)target_brk + PAGE_SIZE - 1) & PAGE_MASK);
148 /* If the new brk is less than this, set it and we're done... */
149 if (new_brk < brk_page) {
150 target_brk = new_brk;
151 return (long)target_brk;
154 /* We need to allocate more memory after the brk... */
155 new_alloc_size = ((new_brk - brk_page + 1)+(PAGE_SIZE-1)) & PAGE_MASK;
156 mapped_addr = get_errno((long)mmap((caddr_t)brk_page, new_alloc_size,
157 PROT_READ|PROT_WRITE,
158 MAP_ANON|MAP_FIXED|MAP_PRIVATE, 0, 0));
160 if (is_error(mapped_addr)) {
163 target_brk = new_brk;
164 return (long)target_brk;
168 static inline fd_set *target_to_host_fds(fd_set *fds,
169 target_long *target_fds, int n)
171 #if !defined(BSWAP_NEEDED) && !defined(WORDS_BIGENDIAN)
172 return (fd_set *)target_fds;
177 for(i = 0;i < n; i++) {
178 b = (tswapl(target_fds[i / TARGET_LONG_BITS]) >>
179 (i & (TARGET_LONG_BITS - 1))) & 1;
190 static inline void host_to_target_fds(target_long *target_fds,
193 #if !defined(BSWAP_NEEDED) && !defined(WORDS_BIGENDIAN)
200 nw = n / TARGET_LONG_BITS;
202 for(i = 0;i < nw; i++) {
204 for(j = 0; j < TARGET_LONG_BITS; j++) {
205 v |= ((FD_ISSET(k, fds) != 0) << j);
208 target_fds[i] = tswapl(v);
214 static inline void target_to_host_timeval(struct timeval *tv,
215 const struct target_timeval *target_tv)
217 tv->tv_sec = tswapl(target_tv->tv_sec);
218 tv->tv_usec = tswapl(target_tv->tv_usec);
221 static inline void host_to_target_timeval(struct target_timeval *target_tv,
222 const struct timeval *tv)
224 target_tv->tv_sec = tswapl(tv->tv_sec);
225 target_tv->tv_usec = tswapl(tv->tv_usec);
229 static long do_select(long n,
230 target_long *target_rfds, target_long *target_wfds,
231 target_long *target_efds, struct target_timeval *target_tv)
233 fd_set rfds, wfds, efds;
234 fd_set *rfds_ptr, *wfds_ptr, *efds_ptr;
235 struct timeval tv, *tv_ptr;
238 rfds_ptr = target_to_host_fds(&rfds, target_rfds, n);
239 wfds_ptr = target_to_host_fds(&wfds, target_wfds, n);
240 efds_ptr = target_to_host_fds(&efds, target_efds, n);
243 target_to_host_timeval(&tv, target_tv);
248 ret = get_errno(select(n, rfds_ptr, wfds_ptr, efds_ptr, tv_ptr));
249 if (!is_error(ret)) {
250 host_to_target_fds(target_rfds, rfds_ptr, n);
251 host_to_target_fds(target_wfds, wfds_ptr, n);
252 host_to_target_fds(target_efds, efds_ptr, n);
255 host_to_target_timeval(target_tv, &tv);
261 static inline void target_to_host_sockaddr(struct sockaddr *addr,
262 struct target_sockaddr *target_addr,
265 memcpy(addr, target_addr, len);
266 addr->sa_family = tswap16(target_addr->sa_family);
269 static inline void host_to_target_sockaddr(struct target_sockaddr *target_addr,
270 struct sockaddr *addr,
273 memcpy(target_addr, addr, len);
274 target_addr->sa_family = tswap16(addr->sa_family);
277 static inline void target_to_host_cmsg(struct msghdr *msgh,
278 struct target_msghdr *target_msgh)
280 struct cmsghdr *cmsg = CMSG_FIRSTHDR(msgh);
281 struct target_cmsghdr *target_cmsg = TARGET_CMSG_FIRSTHDR(target_msgh);
284 while (cmsg && target_cmsg) {
285 void *data = CMSG_DATA(cmsg);
286 void *target_data = TARGET_CMSG_DATA(target_cmsg);
288 int len = tswapl(target_cmsg->cmsg_len)
289 - TARGET_CMSG_ALIGN(sizeof (struct target_cmsghdr));
291 space += CMSG_SPACE(len);
292 if (space > msgh->msg_controllen) {
293 space -= CMSG_SPACE(len);
294 gemu_log("Host cmsg overflow");
298 cmsg->cmsg_level = tswap32(target_cmsg->cmsg_level);
299 cmsg->cmsg_type = tswap32(target_cmsg->cmsg_type);
300 cmsg->cmsg_len = CMSG_LEN(len);
302 if (cmsg->cmsg_level != SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS) {
303 gemu_log("Unsupported ancillary data: %d/%d\n", cmsg->cmsg_level, cmsg->cmsg_type);
304 memcpy(data, target_data, len);
306 int *fd = (int *)data;
307 int *target_fd = (int *)target_data;
308 int i, numfds = len / sizeof(int);
310 for (i = 0; i < numfds; i++)
311 fd[i] = tswap32(target_fd[i]);
314 cmsg = CMSG_NXTHDR(msgh, cmsg);
315 target_cmsg = TARGET_CMSG_NXTHDR(target_msgh, target_cmsg);
318 msgh->msg_controllen = space;
321 static inline void host_to_target_cmsg(struct target_msghdr *target_msgh,
324 struct cmsghdr *cmsg = CMSG_FIRSTHDR(msgh);
325 struct target_cmsghdr *target_cmsg = TARGET_CMSG_FIRSTHDR(target_msgh);
328 while (cmsg && target_cmsg) {
329 void *data = CMSG_DATA(cmsg);
330 void *target_data = TARGET_CMSG_DATA(target_cmsg);
332 int len = cmsg->cmsg_len - CMSG_ALIGN(sizeof (struct cmsghdr));
334 space += TARGET_CMSG_SPACE(len);
335 if (space > tswapl(target_msgh->msg_controllen)) {
336 space -= TARGET_CMSG_SPACE(len);
337 gemu_log("Target cmsg overflow");
341 target_cmsg->cmsg_level = tswap32(cmsg->cmsg_level);
342 target_cmsg->cmsg_type = tswap32(cmsg->cmsg_type);
343 target_cmsg->cmsg_len = tswapl(TARGET_CMSG_LEN(len));
345 if (cmsg->cmsg_level != SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS) {
346 gemu_log("Unsupported ancillary data: %d/%d\n", cmsg->cmsg_level, cmsg->cmsg_type);
347 memcpy(target_data, data, len);
349 int *fd = (int *)data;
350 int *target_fd = (int *)target_data;
351 int i, numfds = len / sizeof(int);
353 for (i = 0; i < numfds; i++)
354 target_fd[i] = tswap32(fd[i]);
357 cmsg = CMSG_NXTHDR(msgh, cmsg);
358 target_cmsg = TARGET_CMSG_NXTHDR(target_msgh, target_cmsg);
361 msgh->msg_controllen = tswapl(space);
364 static long do_setsockopt(int sockfd, int level, int optname,
365 void *optval, socklen_t optlen)
367 if (level == SOL_TCP) {
368 /* TCP options all take an 'int' value. */
371 if (optlen < sizeof(uint32_t))
374 val = tswap32(*(uint32_t *)optval);
375 return get_errno(setsockopt(sockfd, level, optname, &val, sizeof(val)));
378 else if (level != SOL_SOCKET) {
379 gemu_log("Unsupported setsockopt level: %d\n", level);
384 /* Options with 'int' argument. */
405 if (optlen < sizeof(uint32_t))
407 val = tswap32(*(uint32_t *)optval);
408 return get_errno(setsockopt(sockfd, level, optname, &val, sizeof(val)));
412 gemu_log("Unsupported setsockopt SOL_SOCKET option: %d\n", optname);
417 static long do_getsockopt(int sockfd, int level, int optname,
418 void *optval, socklen_t *optlen)
420 gemu_log("getsockopt not yet supported\n");
424 static long do_socketcall(int num, int32_t *vptr)
431 int domain = tswap32(vptr[0]);
432 int type = tswap32(vptr[1]);
433 int protocol = tswap32(vptr[2]);
435 ret = get_errno(socket(domain, type, protocol));
440 int sockfd = tswap32(vptr[0]);
441 void *target_addr = (void *)tswap32(vptr[1]);
442 socklen_t addrlen = tswap32(vptr[2]);
443 void *addr = alloca(addrlen);
445 target_to_host_sockaddr(addr, target_addr, addrlen);
446 ret = get_errno(bind(sockfd, addr, addrlen));
451 int sockfd = tswap32(vptr[0]);
452 void *target_addr = (void *)tswap32(vptr[1]);
453 socklen_t addrlen = tswap32(vptr[2]);
454 void *addr = alloca(addrlen);
456 target_to_host_sockaddr(addr, target_addr, addrlen);
457 ret = get_errno(connect(sockfd, addr, addrlen));
462 int sockfd = tswap32(vptr[0]);
463 int backlog = tswap32(vptr[1]);
465 ret = get_errno(listen(sockfd, backlog));
470 int sockfd = tswap32(vptr[0]);
471 void *target_addr = (void *)tswap32(vptr[1]);
472 uint32_t *target_addrlen = (void *)tswap32(vptr[2]);
473 socklen_t addrlen = tswap32(*target_addrlen);
474 void *addr = alloca(addrlen);
476 ret = get_errno(accept(sockfd, addr, &addrlen));
477 if (!is_error(ret)) {
478 host_to_target_sockaddr(target_addr, addr, addrlen);
479 *target_addrlen = tswap32(addrlen);
483 case SOCKOP_getsockname:
485 int sockfd = tswap32(vptr[0]);
486 void *target_addr = (void *)tswap32(vptr[1]);
487 uint32_t *target_addrlen = (void *)tswap32(vptr[2]);
488 socklen_t addrlen = tswap32(*target_addrlen);
489 void *addr = alloca(addrlen);
491 ret = get_errno(getsockname(sockfd, addr, &addrlen));
492 if (!is_error(ret)) {
493 host_to_target_sockaddr(target_addr, addr, addrlen);
494 *target_addrlen = tswap32(addrlen);
498 case SOCKOP_getpeername:
500 int sockfd = tswap32(vptr[0]);
501 void *target_addr = (void *)tswap32(vptr[1]);
502 uint32_t *target_addrlen = (void *)tswap32(vptr[2]);
503 socklen_t addrlen = tswap32(*target_addrlen);
504 void *addr = alloca(addrlen);
506 ret = get_errno(getpeername(sockfd, addr, &addrlen));
507 if (!is_error(ret)) {
508 host_to_target_sockaddr(target_addr, addr, addrlen);
509 *target_addrlen = tswap32(addrlen);
513 case SOCKOP_socketpair:
515 int domain = tswap32(vptr[0]);
516 int type = tswap32(vptr[1]);
517 int protocol = tswap32(vptr[2]);
518 int32_t *target_tab = (void *)tswap32(vptr[3]);
521 ret = get_errno(socketpair(domain, type, protocol, tab));
522 if (!is_error(ret)) {
523 target_tab[0] = tswap32(tab[0]);
524 target_tab[1] = tswap32(tab[1]);
530 int sockfd = tswap32(vptr[0]);
531 void *msg = (void *)tswap32(vptr[1]);
532 size_t len = tswap32(vptr[2]);
533 int flags = tswap32(vptr[3]);
535 ret = get_errno(send(sockfd, msg, len, flags));
540 int sockfd = tswap32(vptr[0]);
541 void *msg = (void *)tswap32(vptr[1]);
542 size_t len = tswap32(vptr[2]);
543 int flags = tswap32(vptr[3]);
545 ret = get_errno(recv(sockfd, msg, len, flags));
550 int sockfd = tswap32(vptr[0]);
551 void *msg = (void *)tswap32(vptr[1]);
552 size_t len = tswap32(vptr[2]);
553 int flags = tswap32(vptr[3]);
554 void *target_addr = (void *)tswap32(vptr[4]);
555 socklen_t addrlen = tswap32(vptr[5]);
556 void *addr = alloca(addrlen);
558 target_to_host_sockaddr(addr, target_addr, addrlen);
559 ret = get_errno(sendto(sockfd, msg, len, flags, addr, addrlen));
562 case SOCKOP_recvfrom:
564 int sockfd = tswap32(vptr[0]);
565 void *msg = (void *)tswap32(vptr[1]);
566 size_t len = tswap32(vptr[2]);
567 int flags = tswap32(vptr[3]);
568 void *target_addr = (void *)tswap32(vptr[4]);
569 uint32_t *target_addrlen = (void *)tswap32(vptr[5]);
570 socklen_t addrlen = tswap32(*target_addrlen);
571 void *addr = alloca(addrlen);
573 ret = get_errno(recvfrom(sockfd, msg, len, flags, addr, &addrlen));
574 if (!is_error(ret)) {
575 host_to_target_sockaddr(target_addr, addr, addrlen);
576 *target_addrlen = tswap32(addrlen);
580 case SOCKOP_shutdown:
582 int sockfd = tswap32(vptr[0]);
583 int how = tswap32(vptr[1]);
585 ret = get_errno(shutdown(sockfd, how));
592 struct target_msghdr *msgp;
596 struct target_iovec *target_vec;
598 msgp = (void *)tswap32(vptr[1]);
599 msg.msg_name = (void *)tswapl(msgp->msg_name);
600 msg.msg_namelen = tswapl(msgp->msg_namelen);
601 msg.msg_controllen = 2 * tswapl(msgp->msg_controllen);
602 msg.msg_control = alloca(msg.msg_controllen);
603 msg.msg_flags = tswap32(msgp->msg_flags);
605 count = tswapl(msgp->msg_iovlen);
606 vec = alloca(count * sizeof(struct iovec));
607 target_vec = (void *)tswapl(msgp->msg_iov);
608 for(i = 0;i < count; i++) {
609 vec[i].iov_base = (void *)tswapl(target_vec[i].iov_base);
610 vec[i].iov_len = tswapl(target_vec[i].iov_len);
612 msg.msg_iovlen = count;
615 fd = tswap32(vptr[0]);
616 flags = tswap32(vptr[2]);
617 if (num == SOCKOP_sendmsg) {
618 target_to_host_cmsg(&msg, msgp);
619 ret = get_errno(sendmsg(fd, &msg, flags));
621 ret = get_errno(recvmsg(fd, &msg, flags));
623 host_to_target_cmsg(msgp, &msg);
627 case SOCKOP_setsockopt:
629 int sockfd = tswap32(vptr[0]);
630 int level = tswap32(vptr[1]);
631 int optname = tswap32(vptr[2]);
632 void *optval = (void *)tswap32(vptr[3]);
633 socklen_t optlen = tswap32(vptr[4]);
635 ret = do_setsockopt(sockfd, level, optname, optval, optlen);
638 case SOCKOP_getsockopt:
640 int sockfd = tswap32(vptr[0]);
641 int level = tswap32(vptr[1]);
642 int optname = tswap32(vptr[2]);
643 void *optval = (void *)tswap32(vptr[3]);
644 uint32_t *target_len = (void *)tswap32(vptr[4]);
645 socklen_t optlen = tswap32(*target_len);
647 ret = do_getsockopt(sockfd, level, optname, optval, &optlen);
649 *target_len = tswap32(optlen);
653 gemu_log("Unsupported socketcall: %d\n", num);
660 /* kernel structure types definitions */
663 #define STRUCT(name, list...) STRUCT_ ## name,
664 #define STRUCT_SPECIAL(name) STRUCT_ ## name,
666 #include "syscall_types.h"
669 #undef STRUCT_SPECIAL
671 #define STRUCT(name, list...) const argtype struct_ ## name ## _def[] = { list, TYPE_NULL };
672 #define STRUCT_SPECIAL(name)
673 #include "syscall_types.h"
675 #undef STRUCT_SPECIAL
677 typedef struct IOCTLEntry {
682 const argtype arg_type[5];
687 #define IOC_RW (IOC_R | IOC_W)
689 #define MAX_STRUCT_SIZE 4096
691 const IOCTLEntry ioctl_entries[] = {
692 #define IOCTL(cmd, access, types...) \
693 { TARGET_ ## cmd, cmd, #cmd, access, { types } },
698 static long do_ioctl(long fd, long cmd, long arg)
700 const IOCTLEntry *ie;
701 const argtype *arg_type;
703 uint8_t buf_temp[MAX_STRUCT_SIZE];
707 if (ie->target_cmd == 0) {
708 gemu_log("Unsupported ioctl: cmd=0x%04lx\n", cmd);
711 if (ie->target_cmd == cmd)
715 arg_type = ie->arg_type;
717 gemu_log("ioctl: cmd=0x%04lx (%s)\n", cmd, ie->name);
719 switch(arg_type[0]) {
722 ret = get_errno(ioctl(fd, ie->host_cmd));
727 ret = get_errno(ioctl(fd, ie->host_cmd, arg));
733 ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp));
734 if (!is_error(ret)) {
735 thunk_convert((void *)arg, buf_temp, arg_type, THUNK_TARGET);
739 thunk_convert(buf_temp, (void *)arg, arg_type, THUNK_HOST);
740 ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp));
744 thunk_convert(buf_temp, (void *)arg, arg_type, THUNK_HOST);
745 ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp));
746 if (!is_error(ret)) {
747 thunk_convert((void *)arg, buf_temp, arg_type, THUNK_TARGET);
753 gemu_log("Unsupported ioctl type: cmd=0x%04lx type=%d\n", cmd, arg_type[0]);
760 bitmask_transtbl iflag_tbl[] = {
761 { TARGET_IGNBRK, TARGET_IGNBRK, IGNBRK, IGNBRK },
762 { TARGET_BRKINT, TARGET_BRKINT, BRKINT, BRKINT },
763 { TARGET_IGNPAR, TARGET_IGNPAR, IGNPAR, IGNPAR },
764 { TARGET_PARMRK, TARGET_PARMRK, PARMRK, PARMRK },
765 { TARGET_INPCK, TARGET_INPCK, INPCK, INPCK },
766 { TARGET_ISTRIP, TARGET_ISTRIP, ISTRIP, ISTRIP },
767 { TARGET_INLCR, TARGET_INLCR, INLCR, INLCR },
768 { TARGET_IGNCR, TARGET_IGNCR, IGNCR, IGNCR },
769 { TARGET_ICRNL, TARGET_ICRNL, ICRNL, ICRNL },
770 { TARGET_IUCLC, TARGET_IUCLC, IUCLC, IUCLC },
771 { TARGET_IXON, TARGET_IXON, IXON, IXON },
772 { TARGET_IXANY, TARGET_IXANY, IXANY, IXANY },
773 { TARGET_IXOFF, TARGET_IXOFF, IXOFF, IXOFF },
774 { TARGET_IMAXBEL, TARGET_IMAXBEL, IMAXBEL, IMAXBEL },
778 bitmask_transtbl oflag_tbl[] = {
779 { TARGET_OPOST, TARGET_OPOST, OPOST, OPOST },
780 { TARGET_OLCUC, TARGET_OLCUC, OLCUC, OLCUC },
781 { TARGET_ONLCR, TARGET_ONLCR, ONLCR, ONLCR },
782 { TARGET_OCRNL, TARGET_OCRNL, OCRNL, OCRNL },
783 { TARGET_ONOCR, TARGET_ONOCR, ONOCR, ONOCR },
784 { TARGET_ONLRET, TARGET_ONLRET, ONLRET, ONLRET },
785 { TARGET_OFILL, TARGET_OFILL, OFILL, OFILL },
786 { TARGET_OFDEL, TARGET_OFDEL, OFDEL, OFDEL },
787 { TARGET_NLDLY, TARGET_NL0, NLDLY, NL0 },
788 { TARGET_NLDLY, TARGET_NL1, NLDLY, NL1 },
789 { TARGET_CRDLY, TARGET_CR0, CRDLY, CR0 },
790 { TARGET_CRDLY, TARGET_CR1, CRDLY, CR1 },
791 { TARGET_CRDLY, TARGET_CR2, CRDLY, CR2 },
792 { TARGET_CRDLY, TARGET_CR3, CRDLY, CR3 },
793 { TARGET_TABDLY, TARGET_TAB0, TABDLY, TAB0 },
794 { TARGET_TABDLY, TARGET_TAB1, TABDLY, TAB1 },
795 { TARGET_TABDLY, TARGET_TAB2, TABDLY, TAB2 },
796 { TARGET_TABDLY, TARGET_TAB3, TABDLY, TAB3 },
797 { TARGET_BSDLY, TARGET_BS0, BSDLY, BS0 },
798 { TARGET_BSDLY, TARGET_BS1, BSDLY, BS1 },
799 { TARGET_VTDLY, TARGET_VT0, VTDLY, VT0 },
800 { TARGET_VTDLY, TARGET_VT1, VTDLY, VT1 },
801 { TARGET_FFDLY, TARGET_FF0, FFDLY, FF0 },
802 { TARGET_FFDLY, TARGET_FF1, FFDLY, FF1 },
806 bitmask_transtbl cflag_tbl[] = {
807 { TARGET_CBAUD, TARGET_B0, CBAUD, B0 },
808 { TARGET_CBAUD, TARGET_B50, CBAUD, B50 },
809 { TARGET_CBAUD, TARGET_B75, CBAUD, B75 },
810 { TARGET_CBAUD, TARGET_B110, CBAUD, B110 },
811 { TARGET_CBAUD, TARGET_B134, CBAUD, B134 },
812 { TARGET_CBAUD, TARGET_B150, CBAUD, B150 },
813 { TARGET_CBAUD, TARGET_B200, CBAUD, B200 },
814 { TARGET_CBAUD, TARGET_B300, CBAUD, B300 },
815 { TARGET_CBAUD, TARGET_B600, CBAUD, B600 },
816 { TARGET_CBAUD, TARGET_B1200, CBAUD, B1200 },
817 { TARGET_CBAUD, TARGET_B1800, CBAUD, B1800 },
818 { TARGET_CBAUD, TARGET_B2400, CBAUD, B2400 },
819 { TARGET_CBAUD, TARGET_B4800, CBAUD, B4800 },
820 { TARGET_CBAUD, TARGET_B9600, CBAUD, B9600 },
821 { TARGET_CBAUD, TARGET_B19200, CBAUD, B19200 },
822 { TARGET_CBAUD, TARGET_B38400, CBAUD, B38400 },
823 { TARGET_CBAUD, TARGET_B57600, CBAUD, B57600 },
824 { TARGET_CBAUD, TARGET_B115200, CBAUD, B115200 },
825 { TARGET_CBAUD, TARGET_B230400, CBAUD, B230400 },
826 { TARGET_CBAUD, TARGET_B460800, CBAUD, B460800 },
827 { TARGET_CSIZE, TARGET_CS5, CSIZE, CS5 },
828 { TARGET_CSIZE, TARGET_CS6, CSIZE, CS6 },
829 { TARGET_CSIZE, TARGET_CS7, CSIZE, CS7 },
830 { TARGET_CSIZE, TARGET_CS8, CSIZE, CS8 },
831 { TARGET_CSTOPB, TARGET_CSTOPB, CSTOPB, CSTOPB },
832 { TARGET_CREAD, TARGET_CREAD, CREAD, CREAD },
833 { TARGET_PARENB, TARGET_PARENB, PARENB, PARENB },
834 { TARGET_PARODD, TARGET_PARODD, PARODD, PARODD },
835 { TARGET_HUPCL, TARGET_HUPCL, HUPCL, HUPCL },
836 { TARGET_CLOCAL, TARGET_CLOCAL, CLOCAL, CLOCAL },
837 { TARGET_CRTSCTS, TARGET_CRTSCTS, CRTSCTS, CRTSCTS },
841 bitmask_transtbl lflag_tbl[] = {
842 { TARGET_ISIG, TARGET_ISIG, ISIG, ISIG },
843 { TARGET_ICANON, TARGET_ICANON, ICANON, ICANON },
844 { TARGET_XCASE, TARGET_XCASE, XCASE, XCASE },
845 { TARGET_ECHO, TARGET_ECHO, ECHO, ECHO },
846 { TARGET_ECHOE, TARGET_ECHOE, ECHOE, ECHOE },
847 { TARGET_ECHOK, TARGET_ECHOK, ECHOK, ECHOK },
848 { TARGET_ECHONL, TARGET_ECHONL, ECHONL, ECHONL },
849 { TARGET_NOFLSH, TARGET_NOFLSH, NOFLSH, NOFLSH },
850 { TARGET_TOSTOP, TARGET_TOSTOP, TOSTOP, TOSTOP },
851 { TARGET_ECHOCTL, TARGET_ECHOCTL, ECHOCTL, ECHOCTL },
852 { TARGET_ECHOPRT, TARGET_ECHOPRT, ECHOPRT, ECHOPRT },
853 { TARGET_ECHOKE, TARGET_ECHOKE, ECHOKE, ECHOKE },
854 { TARGET_FLUSHO, TARGET_FLUSHO, FLUSHO, FLUSHO },
855 { TARGET_PENDIN, TARGET_PENDIN, PENDIN, PENDIN },
856 { TARGET_IEXTEN, TARGET_IEXTEN, IEXTEN, IEXTEN },
860 static void target_to_host_termios (void *dst, const void *src)
862 struct host_termios *host = dst;
863 const struct target_termios *target = src;
866 target_to_host_bitmask(tswap32(target->c_iflag), iflag_tbl);
868 target_to_host_bitmask(tswap32(target->c_oflag), oflag_tbl);
870 target_to_host_bitmask(tswap32(target->c_cflag), cflag_tbl);
872 target_to_host_bitmask(tswap32(target->c_lflag), lflag_tbl);
873 host->c_line = target->c_line;
875 host->c_cc[VINTR] = target->c_cc[TARGET_VINTR];
876 host->c_cc[VQUIT] = target->c_cc[TARGET_VQUIT];
877 host->c_cc[VERASE] = target->c_cc[TARGET_VERASE];
878 host->c_cc[VKILL] = target->c_cc[TARGET_VKILL];
879 host->c_cc[VEOF] = target->c_cc[TARGET_VEOF];
880 host->c_cc[VTIME] = target->c_cc[TARGET_VTIME];
881 host->c_cc[VMIN] = target->c_cc[TARGET_VMIN];
882 host->c_cc[VSWTC] = target->c_cc[TARGET_VSWTC];
883 host->c_cc[VSTART] = target->c_cc[TARGET_VSTART];
884 host->c_cc[VSTOP] = target->c_cc[TARGET_VSTOP];
885 host->c_cc[VSUSP] = target->c_cc[TARGET_VSUSP];
886 host->c_cc[VEOL] = target->c_cc[TARGET_VEOL];
887 host->c_cc[VREPRINT] = target->c_cc[TARGET_VREPRINT];
888 host->c_cc[VDISCARD] = target->c_cc[TARGET_VDISCARD];
889 host->c_cc[VWERASE] = target->c_cc[TARGET_VWERASE];
890 host->c_cc[VLNEXT] = target->c_cc[TARGET_VLNEXT];
891 host->c_cc[VEOL2] = target->c_cc[TARGET_VEOL2];
894 static void host_to_target_termios (void *dst, const void *src)
896 struct target_termios *target = dst;
897 const struct host_termios *host = src;
900 tswap32(host_to_target_bitmask(host->c_iflag, iflag_tbl));
902 tswap32(host_to_target_bitmask(host->c_oflag, oflag_tbl));
904 tswap32(host_to_target_bitmask(host->c_cflag, cflag_tbl));
906 tswap32(host_to_target_bitmask(host->c_lflag, lflag_tbl));
907 target->c_line = host->c_line;
909 target->c_cc[TARGET_VINTR] = host->c_cc[VINTR];
910 target->c_cc[TARGET_VQUIT] = host->c_cc[VQUIT];
911 target->c_cc[TARGET_VERASE] = host->c_cc[VERASE];
912 target->c_cc[TARGET_VKILL] = host->c_cc[VKILL];
913 target->c_cc[TARGET_VEOF] = host->c_cc[VEOF];
914 target->c_cc[TARGET_VTIME] = host->c_cc[VTIME];
915 target->c_cc[TARGET_VMIN] = host->c_cc[VMIN];
916 target->c_cc[TARGET_VSWTC] = host->c_cc[VSWTC];
917 target->c_cc[TARGET_VSTART] = host->c_cc[VSTART];
918 target->c_cc[TARGET_VSTOP] = host->c_cc[VSTOP];
919 target->c_cc[TARGET_VSUSP] = host->c_cc[VSUSP];
920 target->c_cc[TARGET_VEOL] = host->c_cc[VEOL];
921 target->c_cc[TARGET_VREPRINT] = host->c_cc[VREPRINT];
922 target->c_cc[TARGET_VDISCARD] = host->c_cc[VDISCARD];
923 target->c_cc[TARGET_VWERASE] = host->c_cc[VWERASE];
924 target->c_cc[TARGET_VLNEXT] = host->c_cc[VLNEXT];
925 target->c_cc[TARGET_VEOL2] = host->c_cc[VEOL2];
928 StructEntry struct_termios_def = {
929 .convert = { host_to_target_termios, target_to_host_termios },
930 .size = { sizeof(struct target_termios), sizeof(struct host_termios) },
931 .align = { __alignof__(struct target_termios), __alignof__(struct host_termios) },
936 /* NOTE: there is really one LDT for all the threads */
939 static int read_ldt(void *ptr, unsigned long bytecount)
945 size = TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE;
946 if (size > bytecount)
948 memcpy(ptr, ldt_table, size);
952 /* XXX: add locking support */
953 static int write_ldt(CPUX86State *env,
954 void *ptr, unsigned long bytecount, int oldmode)
956 struct target_modify_ldt_ldt_s ldt_info;
957 int seg_32bit, contents, read_exec_only, limit_in_pages;
958 int seg_not_present, useable;
959 uint32_t *lp, entry_1, entry_2;
961 if (bytecount != sizeof(ldt_info))
963 memcpy(&ldt_info, ptr, sizeof(ldt_info));
964 tswap32s(&ldt_info.entry_number);
965 tswapls((long *)&ldt_info.base_addr);
966 tswap32s(&ldt_info.limit);
967 tswap32s(&ldt_info.flags);
969 if (ldt_info.entry_number >= TARGET_LDT_ENTRIES)
971 seg_32bit = ldt_info.flags & 1;
972 contents = (ldt_info.flags >> 1) & 3;
973 read_exec_only = (ldt_info.flags >> 3) & 1;
974 limit_in_pages = (ldt_info.flags >> 4) & 1;
975 seg_not_present = (ldt_info.flags >> 5) & 1;
976 useable = (ldt_info.flags >> 6) & 1;
981 if (seg_not_present == 0)
984 /* allocate the LDT */
986 ldt_table = malloc(TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE);
989 memset(ldt_table, 0, TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE);
990 env->ldt.base = ldt_table;
991 env->ldt.limit = 0xffff;
994 /* NOTE: same code as Linux kernel */
995 /* Allow LDTs to be cleared by the user. */
996 if (ldt_info.base_addr == 0 && ldt_info.limit == 0) {
999 read_exec_only == 1 &&
1001 limit_in_pages == 0 &&
1002 seg_not_present == 1 &&
1010 entry_1 = ((ldt_info.base_addr & 0x0000ffff) << 16) |
1011 (ldt_info.limit & 0x0ffff);
1012 entry_2 = (ldt_info.base_addr & 0xff000000) |
1013 ((ldt_info.base_addr & 0x00ff0000) >> 16) |
1014 (ldt_info.limit & 0xf0000) |
1015 ((read_exec_only ^ 1) << 9) |
1017 ((seg_not_present ^ 1) << 15) |
1019 (limit_in_pages << 23) |
1022 entry_2 |= (useable << 20);
1024 /* Install the new entry ... */
1026 lp = (uint32_t *)(ldt_table + (ldt_info.entry_number << 3));
1027 lp[0] = tswap32(entry_1);
1028 lp[1] = tswap32(entry_2);
1032 /* specific and weird i386 syscalls */
1033 int do_modify_ldt(CPUX86State *env, int func, void *ptr, unsigned long bytecount)
1039 ret = read_ldt(ptr, bytecount);
1042 ret = write_ldt(env, ptr, bytecount, 1);
1045 ret = write_ldt(env, ptr, bytecount, 0);
1051 /* vm86 emulation */
1053 #define SAFE_MASK (0xDD5)
1055 int do_vm86(CPUX86State *env, long subfunction,
1056 struct target_vm86plus_struct * target_v86)
1058 TaskState *ts = env->opaque;
1061 switch (subfunction) {
1062 case TARGET_VM86_REQUEST_IRQ:
1063 case TARGET_VM86_FREE_IRQ:
1064 case TARGET_VM86_GET_IRQ_BITS:
1065 case TARGET_VM86_GET_AND_RESET_IRQ:
1066 gemu_log("qemu: unsupported vm86 subfunction (%ld)\n", subfunction);
1069 case TARGET_VM86_PLUS_INSTALL_CHECK:
1070 /* NOTE: on old vm86 stuff this will return the error
1071 from verify_area(), because the subfunction is
1072 interpreted as (invalid) address to vm86_struct.
1073 So the installation check works.
1079 ts->target_v86 = target_v86;
1081 /* save current CPU regs */
1082 ts->vm86_saved_regs.eax = 0; /* default vm86 syscall return code */
1083 ts->vm86_saved_regs.ebx = env->regs[R_EBX];
1084 ts->vm86_saved_regs.ecx = env->regs[R_ECX];
1085 ts->vm86_saved_regs.edx = env->regs[R_EDX];
1086 ts->vm86_saved_regs.esi = env->regs[R_ESI];
1087 ts->vm86_saved_regs.edi = env->regs[R_EDI];
1088 ts->vm86_saved_regs.ebp = env->regs[R_EBP];
1089 ts->vm86_saved_regs.esp = env->regs[R_ESP];
1090 ts->vm86_saved_regs.eflags = env->eflags;
1091 ts->vm86_saved_regs.eip = env->eip;
1092 ts->vm86_saved_regs.cs = env->segs[R_CS];
1093 ts->vm86_saved_regs.ss = env->segs[R_SS];
1094 ts->vm86_saved_regs.ds = env->segs[R_DS];
1095 ts->vm86_saved_regs.es = env->segs[R_ES];
1096 ts->vm86_saved_regs.fs = env->segs[R_FS];
1097 ts->vm86_saved_regs.gs = env->segs[R_GS];
1099 /* build vm86 CPU state */
1100 env->eflags = (env->eflags & ~SAFE_MASK) |
1101 (tswap32(target_v86->regs.eflags) & SAFE_MASK) | VM_MASK;
1103 env->regs[R_EBX] = tswap32(target_v86->regs.ebx);
1104 env->regs[R_ECX] = tswap32(target_v86->regs.ecx);
1105 env->regs[R_EDX] = tswap32(target_v86->regs.edx);
1106 env->regs[R_ESI] = tswap32(target_v86->regs.esi);
1107 env->regs[R_EDI] = tswap32(target_v86->regs.edi);
1108 env->regs[R_EBP] = tswap32(target_v86->regs.ebp);
1109 env->regs[R_ESP] = tswap32(target_v86->regs.esp);
1110 env->eip = tswap32(target_v86->regs.eip);
1111 cpu_x86_load_seg(env, R_CS, tswap16(target_v86->regs.cs));
1112 cpu_x86_load_seg(env, R_SS, tswap16(target_v86->regs.ss));
1113 cpu_x86_load_seg(env, R_DS, tswap16(target_v86->regs.ds));
1114 cpu_x86_load_seg(env, R_ES, tswap16(target_v86->regs.es));
1115 cpu_x86_load_seg(env, R_FS, tswap16(target_v86->regs.fs));
1116 cpu_x86_load_seg(env, R_GS, tswap16(target_v86->regs.gs));
1117 ret = tswap32(target_v86->regs.eax); /* eax will be restored at
1118 the end of the syscall */
1119 /* now the virtual CPU is ready for vm86 execution ! */
1124 /* this stack is the equivalent of the kernel stack associated with a
1126 #define NEW_STACK_SIZE 8192
1128 static int clone_func(void *arg)
1130 CPUX86State *env = arg;
1136 int do_fork(CPUX86State *env, unsigned int flags, unsigned long newsp)
1141 CPUX86State *new_env;
1143 if (flags & CLONE_VM) {
1145 newsp = env->regs[R_ESP];
1146 ts = malloc(sizeof(TaskState) + NEW_STACK_SIZE);
1147 memset(ts, 0, sizeof(TaskState));
1148 new_stack = ts->stack;
1150 /* add in task state list */
1151 ts->next = first_task_state;
1152 first_task_state = ts;
1153 /* we create a new CPU instance. */
1154 new_env = cpu_x86_init();
1155 memcpy(new_env, env, sizeof(CPUX86State));
1156 new_env->regs[R_ESP] = newsp;
1157 new_env->regs[R_EAX] = 0;
1158 new_env->opaque = ts;
1159 ret = clone(clone_func, new_stack + NEW_STACK_SIZE, flags, new_env);
1161 /* if no CLONE_VM, we consider it is a fork */
1162 if ((flags & ~CSIGNAL) != 0)
1171 #define high2lowuid(x) (x)
1172 #define high2lowgid(x) (x)
1173 #define low2highuid(x) (x)
1174 #define low2highgid(x) (x)
1176 void syscall_init(void)
1178 #define STRUCT(name, list...) thunk_register_struct(STRUCT_ ## name, #name, struct_ ## name ## _def);
1179 #define STRUCT_SPECIAL(name) thunk_register_struct_direct(STRUCT_ ## name, #name, &struct_ ## name ## _def);
1180 #include "syscall_types.h"
1182 #undef STRUCT_SPECIAL
1185 long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
1186 long arg4, long arg5, long arg6)
1190 struct kernel_statfs *stfs;
1193 gemu_log("syscall %d\n", num);
1196 case TARGET_NR_exit:
1200 /* XXX: should free thread stack and CPU env */
1202 ret = 0; /* avoid warning */
1204 case TARGET_NR_read:
1205 ret = get_errno(read(arg1, (void *)arg2, arg3));
1207 case TARGET_NR_write:
1208 ret = get_errno(write(arg1, (void *)arg2, arg3));
1210 case TARGET_NR_open:
1211 ret = get_errno(open((const char *)arg1, arg2, arg3));
1213 case TARGET_NR_close:
1214 ret = get_errno(close(arg1));
1217 ret = do_brk((char *)arg1);
1219 case TARGET_NR_fork:
1220 ret = get_errno(do_fork(cpu_env, SIGCHLD, 0));
1222 case TARGET_NR_waitpid:
1224 int *status = (int *)arg2;
1225 ret = get_errno(waitpid(arg1, status, arg3));
1226 if (!is_error(ret) && status)
1227 tswapls((long *)&status);
1230 case TARGET_NR_creat:
1231 ret = get_errno(creat((const char *)arg1, arg2));
1233 case TARGET_NR_link:
1234 ret = get_errno(link((const char *)arg1, (const char *)arg2));
1236 case TARGET_NR_unlink:
1237 ret = get_errno(unlink((const char *)arg1));
1239 case TARGET_NR_execve:
1241 char **argp, **envp;
1242 int argc = 0, envc = 0;
1246 for (p = (void *)arg2; *p; p++)
1248 for (p = (void *)arg3; *p; p++)
1251 argp = alloca(argc * sizeof(void *));
1252 envp = alloca(envc * sizeof(void *));
1254 for (p = (void *)arg2, q = argp; *p; p++, q++)
1255 *q = (void *)tswap32(*p);
1256 for (p = (void *)arg3, q = envp; *p; p++, q++)
1257 *q = (void *)tswap32(*p);
1259 ret = get_errno(execve((const char *)arg1, argp, envp));
1262 case TARGET_NR_chdir:
1263 ret = get_errno(chdir((const char *)arg1));
1265 case TARGET_NR_time:
1267 int *time_ptr = (int *)arg1;
1268 ret = get_errno(time((time_t *)time_ptr));
1269 if (!is_error(ret) && time_ptr)
1273 case TARGET_NR_mknod:
1274 ret = get_errno(mknod((const char *)arg1, arg2, arg3));
1276 case TARGET_NR_chmod:
1277 ret = get_errno(chmod((const char *)arg1, arg2));
1279 case TARGET_NR_lchown:
1280 ret = get_errno(chown((const char *)arg1, arg2, arg3));
1282 case TARGET_NR_break:
1284 case TARGET_NR_oldstat:
1286 case TARGET_NR_lseek:
1287 ret = get_errno(lseek(arg1, arg2, arg3));
1289 case TARGET_NR_getpid:
1290 ret = get_errno(getpid());
1292 case TARGET_NR_mount:
1293 /* need to look at the data field */
1295 case TARGET_NR_umount:
1296 ret = get_errno(umount((const char *)arg1));
1298 case TARGET_NR_setuid:
1299 ret = get_errno(setuid(low2highuid(arg1)));
1301 case TARGET_NR_getuid:
1302 ret = get_errno(getuid());
1304 case TARGET_NR_stime:
1306 int *time_ptr = (int *)arg1;
1309 ret = get_errno(stime((time_t *)time_ptr));
1312 case TARGET_NR_ptrace:
1314 case TARGET_NR_alarm:
1317 case TARGET_NR_oldfstat:
1319 case TARGET_NR_pause:
1320 ret = get_errno(pause());
1322 case TARGET_NR_utime:
1324 case TARGET_NR_stty:
1326 case TARGET_NR_gtty:
1328 case TARGET_NR_access:
1329 ret = get_errno(access((const char *)arg1, arg2));
1331 case TARGET_NR_nice:
1332 ret = get_errno(nice(arg1));
1334 case TARGET_NR_ftime:
1336 case TARGET_NR_sync:
1340 case TARGET_NR_kill:
1341 ret = get_errno(kill(arg1, arg2));
1343 case TARGET_NR_rename:
1344 ret = get_errno(rename((const char *)arg1, (const char *)arg2));
1346 case TARGET_NR_mkdir:
1347 ret = get_errno(mkdir((const char *)arg1, arg2));
1349 case TARGET_NR_rmdir:
1350 ret = get_errno(rmdir((const char *)arg1));
1353 ret = get_errno(dup(arg1));
1355 case TARGET_NR_pipe:
1357 int *pipe_ptr = (int *)arg1;
1358 ret = get_errno(pipe(pipe_ptr));
1359 if (!is_error(ret)) {
1360 tswap32s(&pipe_ptr[0]);
1361 tswap32s(&pipe_ptr[1]);
1365 case TARGET_NR_times:
1367 case TARGET_NR_prof:
1369 case TARGET_NR_setgid:
1370 ret = get_errno(setgid(low2highgid(arg1)));
1372 case TARGET_NR_getgid:
1373 ret = get_errno(getgid());
1375 case TARGET_NR_signal:
1377 case TARGET_NR_geteuid:
1378 ret = get_errno(geteuid());
1380 case TARGET_NR_getegid:
1381 ret = get_errno(getegid());
1383 case TARGET_NR_acct:
1385 case TARGET_NR_umount2:
1386 ret = get_errno(umount2((const char *)arg1, arg2));
1388 case TARGET_NR_lock:
1390 case TARGET_NR_ioctl:
1391 ret = do_ioctl(arg1, arg2, arg3);
1393 case TARGET_NR_fcntl:
1400 ret = get_errno(fcntl(arg1, arg2, arg3));
1406 case TARGET_NR_setpgid:
1407 ret = get_errno(setpgid(arg1, arg2));
1409 case TARGET_NR_ulimit:
1411 case TARGET_NR_oldolduname:
1413 case TARGET_NR_umask:
1414 ret = get_errno(umask(arg1));
1416 case TARGET_NR_chroot:
1417 ret = get_errno(chroot((const char *)arg1));
1419 case TARGET_NR_ustat:
1421 case TARGET_NR_dup2:
1422 ret = get_errno(dup2(arg1, arg2));
1424 case TARGET_NR_getppid:
1425 ret = get_errno(getppid());
1427 case TARGET_NR_getpgrp:
1428 ret = get_errno(getpgrp());
1430 case TARGET_NR_setsid:
1431 ret = get_errno(setsid());
1433 case TARGET_NR_sigaction:
1435 struct target_old_sigaction *old_act = (void *)arg2;
1436 struct target_old_sigaction *old_oact = (void *)arg3;
1437 struct target_sigaction act, oact, *pact;
1439 act._sa_handler = old_act->_sa_handler;
1440 target_siginitset(&act.sa_mask, old_act->sa_mask);
1441 act.sa_flags = old_act->sa_flags;
1442 act.sa_restorer = old_act->sa_restorer;
1447 ret = get_errno(do_sigaction(arg1, pact, &oact));
1448 if (!is_error(ret) && old_oact) {
1449 old_oact->_sa_handler = oact._sa_handler;
1450 old_oact->sa_mask = oact.sa_mask.sig[0];
1451 old_oact->sa_flags = oact.sa_flags;
1452 old_oact->sa_restorer = oact.sa_restorer;
1456 case TARGET_NR_rt_sigaction:
1457 ret = get_errno(do_sigaction(arg1, (void *)arg2, (void *)arg3));
1459 case TARGET_NR_sgetmask:
1462 target_ulong target_set;
1463 sigprocmask(0, NULL, &cur_set);
1464 host_to_target_old_sigset(&target_set, &cur_set);
1468 case TARGET_NR_ssetmask:
1470 sigset_t set, oset, cur_set;
1471 target_ulong target_set = arg1;
1472 sigprocmask(0, NULL, &cur_set);
1473 target_to_host_old_sigset(&set, &target_set);
1474 sigorset(&set, &set, &cur_set);
1475 sigprocmask(SIG_SETMASK, &set, &oset);
1476 host_to_target_old_sigset(&target_set, &oset);
1480 case TARGET_NR_sigprocmask:
1483 sigset_t set, oldset, *set_ptr;
1484 target_ulong *pset = (void *)arg2, *poldset = (void *)arg3;
1488 case TARGET_SIG_BLOCK:
1491 case TARGET_SIG_UNBLOCK:
1494 case TARGET_SIG_SETMASK:
1501 target_to_host_old_sigset(&set, pset);
1507 ret = get_errno(sigprocmask(arg1, set_ptr, &oldset));
1508 if (!is_error(ret) && poldset) {
1509 host_to_target_old_sigset(poldset, &oldset);
1513 case TARGET_NR_rt_sigprocmask:
1516 sigset_t set, oldset, *set_ptr;
1517 target_sigset_t *pset = (void *)arg2;
1518 target_sigset_t *poldset = (void *)arg3;
1522 case TARGET_SIG_BLOCK:
1525 case TARGET_SIG_UNBLOCK:
1528 case TARGET_SIG_SETMASK:
1535 target_to_host_sigset(&set, pset);
1541 ret = get_errno(sigprocmask(how, set_ptr, &oldset));
1542 if (!is_error(ret) && poldset) {
1543 host_to_target_sigset(poldset, &oldset);
1547 case TARGET_NR_sigpending:
1550 ret = get_errno(sigpending(&set));
1551 if (!is_error(ret)) {
1552 host_to_target_old_sigset((target_ulong *)arg1, &set);
1556 case TARGET_NR_rt_sigpending:
1559 ret = get_errno(sigpending(&set));
1560 if (!is_error(ret)) {
1561 host_to_target_sigset((target_sigset_t *)arg1, &set);
1565 case TARGET_NR_sigsuspend:
1568 target_to_host_old_sigset(&set, (target_ulong *)arg1);
1569 ret = get_errno(sigsuspend(&set));
1572 case TARGET_NR_rt_sigsuspend:
1575 target_to_host_sigset(&set, (target_sigset_t *)arg1);
1576 ret = get_errno(sigsuspend(&set));
1579 case TARGET_NR_rt_sigtimedwait:
1581 target_sigset_t *target_set = (void *)arg1;
1582 target_siginfo_t *target_uinfo = (void *)arg2;
1583 struct target_timespec *target_uts = (void *)arg3;
1585 struct timespec uts, *puts;
1588 target_to_host_sigset(&set, target_set);
1591 puts->tv_sec = tswapl(target_uts->tv_sec);
1592 puts->tv_nsec = tswapl(target_uts->tv_nsec);
1596 ret = get_errno(sigtimedwait(&set, &uinfo, puts));
1597 if (!is_error(ret) && target_uinfo) {
1598 host_to_target_siginfo(target_uinfo, &uinfo);
1602 case TARGET_NR_rt_sigqueueinfo:
1605 target_to_host_siginfo(&uinfo, (target_siginfo_t *)arg3);
1606 ret = get_errno(sys_rt_sigqueueinfo(arg1, arg2, &uinfo));
1609 case TARGET_NR_sigreturn:
1610 /* NOTE: ret is eax, so not transcoding must be done */
1611 ret = do_sigreturn(cpu_env);
1613 case TARGET_NR_rt_sigreturn:
1614 /* NOTE: ret is eax, so not transcoding must be done */
1615 ret = do_rt_sigreturn(cpu_env);
1617 case TARGET_NR_setreuid:
1618 ret = get_errno(setreuid(arg1, arg2));
1620 case TARGET_NR_setregid:
1621 ret = get_errno(setregid(arg1, arg2));
1623 case TARGET_NR_sethostname:
1624 ret = get_errno(sethostname((const char *)arg1, arg2));
1626 case TARGET_NR_setrlimit:
1628 /* XXX: convert resource ? */
1629 int resource = arg1;
1630 struct target_rlimit *target_rlim = (void *)arg2;
1632 rlim.rlim_cur = tswapl(target_rlim->rlim_cur);
1633 rlim.rlim_max = tswapl(target_rlim->rlim_max);
1634 ret = get_errno(setrlimit(resource, &rlim));
1637 case TARGET_NR_getrlimit:
1639 /* XXX: convert resource ? */
1640 int resource = arg1;
1641 struct target_rlimit *target_rlim = (void *)arg2;
1644 ret = get_errno(getrlimit(resource, &rlim));
1645 if (!is_error(ret)) {
1646 target_rlim->rlim_cur = tswapl(rlim.rlim_cur);
1647 target_rlim->rlim_max = tswapl(rlim.rlim_max);
1651 case TARGET_NR_getrusage:
1653 case TARGET_NR_gettimeofday:
1655 struct target_timeval *target_tv = (void *)arg1;
1657 ret = get_errno(gettimeofday(&tv, NULL));
1658 if (!is_error(ret)) {
1659 host_to_target_timeval(target_tv, &tv);
1663 case TARGET_NR_settimeofday:
1665 struct target_timeval *target_tv = (void *)arg1;
1667 target_to_host_timeval(&tv, target_tv);
1668 ret = get_errno(settimeofday(&tv, NULL));
1671 case TARGET_NR_getgroups:
1673 case TARGET_NR_setgroups:
1675 case TARGET_NR_select:
1677 case TARGET_NR_symlink:
1678 ret = get_errno(symlink((const char *)arg1, (const char *)arg2));
1680 case TARGET_NR_oldlstat:
1682 case TARGET_NR_readlink:
1683 ret = get_errno(readlink((const char *)arg1, (char *)arg2, arg3));
1685 case TARGET_NR_uselib:
1687 case TARGET_NR_swapon:
1688 ret = get_errno(swapon((const char *)arg1, arg2));
1690 case TARGET_NR_reboot:
1692 case TARGET_NR_readdir:
1695 case TARGET_NR_mmap:
1697 uint32_t v1, v2, v3, v4, v5, v6, *vptr;
1698 vptr = (uint32_t *)arg1;
1699 v1 = tswap32(vptr[0]);
1700 v2 = tswap32(vptr[1]);
1701 v3 = tswap32(vptr[2]);
1702 v4 = tswap32(vptr[3]);
1703 v5 = tswap32(vptr[4]);
1704 v6 = tswap32(vptr[5]);
1705 ret = get_errno((long)mmap((void *)v1, v2, v3, v4, v5, v6));
1710 case TARGET_NR_mmap2:
1712 case TARGET_NR_mmap:
1714 ret = get_errno((long)mmap((void *)arg1, arg2, arg3, arg4, arg5, arg6));
1716 case TARGET_NR_munmap:
1717 ret = get_errno(munmap((void *)arg1, arg2));
1719 case TARGET_NR_mprotect:
1720 ret = get_errno(mprotect((void *)arg1, arg2, arg3));
1722 case TARGET_NR_mremap:
1723 ret = get_errno((long)mremap((void *)arg1, arg2, arg3, arg4));
1725 case TARGET_NR_msync:
1726 ret = get_errno(msync((void *)arg1, arg2, arg3));
1728 case TARGET_NR_mlock:
1729 ret = get_errno(mlock((void *)arg1, arg2));
1731 case TARGET_NR_munlock:
1732 ret = get_errno(munlock((void *)arg1, arg2));
1734 case TARGET_NR_mlockall:
1735 ret = get_errno(mlockall(arg1));
1737 case TARGET_NR_munlockall:
1738 ret = get_errno(munlockall());
1740 case TARGET_NR_truncate:
1741 ret = get_errno(truncate((const char *)arg1, arg2));
1743 case TARGET_NR_ftruncate:
1744 ret = get_errno(ftruncate(arg1, arg2));
1746 case TARGET_NR_fchmod:
1747 ret = get_errno(fchmod(arg1, arg2));
1749 case TARGET_NR_fchown:
1750 ret = get_errno(fchown(arg1, arg2, arg3));
1752 case TARGET_NR_getpriority:
1753 ret = get_errno(getpriority(arg1, arg2));
1755 case TARGET_NR_setpriority:
1756 ret = get_errno(setpriority(arg1, arg2, arg3));
1758 case TARGET_NR_profil:
1760 case TARGET_NR_statfs:
1761 stfs = (void *)arg2;
1762 ret = get_errno(sys_statfs((const char *)arg1, stfs));
1764 if (!is_error(ret)) {
1765 tswap32s(&stfs->f_type);
1766 tswap32s(&stfs->f_bsize);
1767 tswap32s(&stfs->f_blocks);
1768 tswap32s(&stfs->f_bfree);
1769 tswap32s(&stfs->f_bavail);
1770 tswap32s(&stfs->f_files);
1771 tswap32s(&stfs->f_ffree);
1772 tswap32s(&stfs->f_fsid.val[0]);
1773 tswap32s(&stfs->f_fsid.val[1]);
1774 tswap32s(&stfs->f_namelen);
1777 case TARGET_NR_fstatfs:
1778 stfs = (void *)arg2;
1779 ret = get_errno(sys_fstatfs(arg1, stfs));
1780 goto convert_statfs;
1781 case TARGET_NR_ioperm:
1783 case TARGET_NR_socketcall:
1784 ret = do_socketcall(arg1, (int32_t *)arg2);
1786 case TARGET_NR_syslog:
1788 case TARGET_NR_setitimer:
1790 struct target_itimerval *target_value = (void *)arg2;
1791 struct target_itimerval *target_ovalue = (void *)arg3;
1792 struct itimerval value, ovalue, *pvalue;
1796 target_to_host_timeval(&pvalue->it_interval,
1797 &target_value->it_interval);
1798 target_to_host_timeval(&pvalue->it_value,
1799 &target_value->it_value);
1803 ret = get_errno(setitimer(arg1, pvalue, &ovalue));
1804 if (!is_error(ret) && target_ovalue) {
1805 host_to_target_timeval(&target_ovalue->it_interval,
1806 &ovalue.it_interval);
1807 host_to_target_timeval(&target_ovalue->it_value,
1812 case TARGET_NR_getitimer:
1814 struct target_itimerval *target_value = (void *)arg2;
1815 struct itimerval value;
1817 ret = get_errno(getitimer(arg1, &value));
1818 if (!is_error(ret) && target_value) {
1819 host_to_target_timeval(&target_value->it_interval,
1820 &value.it_interval);
1821 host_to_target_timeval(&target_value->it_value,
1826 case TARGET_NR_stat:
1827 ret = get_errno(stat((const char *)arg1, &st));
1829 case TARGET_NR_lstat:
1830 ret = get_errno(lstat((const char *)arg1, &st));
1832 case TARGET_NR_fstat:
1834 ret = get_errno(fstat(arg1, &st));
1836 if (!is_error(ret)) {
1837 struct target_stat *target_st = (void *)arg2;
1838 target_st->st_dev = tswap16(st.st_dev);
1839 target_st->st_ino = tswapl(st.st_ino);
1840 target_st->st_mode = tswap16(st.st_mode);
1841 target_st->st_nlink = tswap16(st.st_nlink);
1842 target_st->st_uid = tswap16(st.st_uid);
1843 target_st->st_gid = tswap16(st.st_gid);
1844 target_st->st_rdev = tswap16(st.st_rdev);
1845 target_st->st_size = tswapl(st.st_size);
1846 target_st->st_blksize = tswapl(st.st_blksize);
1847 target_st->st_blocks = tswapl(st.st_blocks);
1848 target_st->target_st_atime = tswapl(st.st_atime);
1849 target_st->target_st_mtime = tswapl(st.st_mtime);
1850 target_st->target_st_ctime = tswapl(st.st_ctime);
1854 case TARGET_NR_olduname:
1856 case TARGET_NR_iopl:
1858 case TARGET_NR_vhangup:
1859 ret = get_errno(vhangup());
1861 case TARGET_NR_idle:
1863 case TARGET_NR_wait4:
1866 target_long *status_ptr = (void *)arg2;
1867 struct rusage rusage, *rusage_ptr;
1868 struct target_rusage *target_rusage = (void *)arg4;
1870 rusage_ptr = &rusage;
1873 ret = get_errno(wait4(arg1, &status, arg3, rusage_ptr));
1874 if (!is_error(ret)) {
1876 *status_ptr = tswap32(status);
1877 if (target_rusage) {
1878 target_rusage->ru_utime.tv_sec = tswapl(rusage.ru_utime.tv_sec);
1879 target_rusage->ru_utime.tv_usec = tswapl(rusage.ru_utime.tv_usec);
1880 target_rusage->ru_stime.tv_sec = tswapl(rusage.ru_stime.tv_sec);
1881 target_rusage->ru_stime.tv_usec = tswapl(rusage.ru_stime.tv_usec);
1882 target_rusage->ru_maxrss = tswapl(rusage.ru_maxrss);
1883 target_rusage->ru_ixrss = tswapl(rusage.ru_ixrss);
1884 target_rusage->ru_idrss = tswapl(rusage.ru_idrss);
1885 target_rusage->ru_isrss = tswapl(rusage.ru_isrss);
1886 target_rusage->ru_minflt = tswapl(rusage.ru_minflt);
1887 target_rusage->ru_majflt = tswapl(rusage.ru_majflt);
1888 target_rusage->ru_nswap = tswapl(rusage.ru_nswap);
1889 target_rusage->ru_inblock = tswapl(rusage.ru_inblock);
1890 target_rusage->ru_oublock = tswapl(rusage.ru_oublock);
1891 target_rusage->ru_msgsnd = tswapl(rusage.ru_msgsnd);
1892 target_rusage->ru_msgrcv = tswapl(rusage.ru_msgrcv);
1893 target_rusage->ru_nsignals = tswapl(rusage.ru_nsignals);
1894 target_rusage->ru_nvcsw = tswapl(rusage.ru_nvcsw);
1895 target_rusage->ru_nivcsw = tswapl(rusage.ru_nivcsw);
1900 case TARGET_NR_swapoff:
1901 ret = get_errno(swapoff((const char *)arg1));
1903 case TARGET_NR_sysinfo:
1907 case TARGET_NR_fsync:
1908 ret = get_errno(fsync(arg1));
1910 case TARGET_NR_clone:
1911 ret = get_errno(do_fork(cpu_env, arg1, arg2));
1913 case TARGET_NR_setdomainname:
1914 ret = get_errno(setdomainname((const char *)arg1, arg2));
1916 case TARGET_NR_uname:
1917 /* no need to transcode because we use the linux syscall */
1918 ret = get_errno(sys_uname((struct new_utsname *)arg1));
1921 case TARGET_NR_modify_ldt:
1922 ret = get_errno(do_modify_ldt(cpu_env, arg1, (void *)arg2, arg3));
1924 case TARGET_NR_vm86old:
1926 case TARGET_NR_vm86:
1927 ret = do_vm86(cpu_env, arg1, (void *)arg2);
1930 case TARGET_NR_adjtimex:
1932 case TARGET_NR_create_module:
1933 case TARGET_NR_init_module:
1934 case TARGET_NR_delete_module:
1935 case TARGET_NR_get_kernel_syms:
1937 case TARGET_NR_quotactl:
1939 case TARGET_NR_getpgid:
1940 ret = get_errno(getpgid(arg1));
1942 case TARGET_NR_fchdir:
1943 ret = get_errno(fchdir(arg1));
1945 case TARGET_NR_bdflush:
1947 case TARGET_NR_sysfs:
1949 case TARGET_NR_personality:
1950 ret = get_errno(personality(arg1));
1952 case TARGET_NR_afs_syscall:
1954 case TARGET_NR_setfsuid:
1955 ret = get_errno(setfsuid(arg1));
1957 case TARGET_NR_setfsgid:
1958 ret = get_errno(setfsgid(arg1));
1960 case TARGET_NR__llseek:
1963 ret = get_errno(_llseek(arg1, arg2, arg3, &res, arg5));
1964 *(int64_t *)arg4 = tswap64(res);
1967 case TARGET_NR_getdents:
1968 #if TARGET_LONG_SIZE != 4
1969 #error not supported
1972 struct dirent *dirp = (void *)arg2;
1975 ret = get_errno(sys_getdents(arg1, dirp, count));
1976 if (!is_error(ret)) {
1982 reclen = de->d_reclen;
1985 de->d_reclen = tswap16(reclen);
1986 tswapls(&de->d_ino);
1987 tswapls(&de->d_off);
1988 de = (struct dirent *)((char *)de + reclen);
1994 case TARGET_NR_getdents64:
1996 struct dirent64 *dirp = (void *)arg2;
1998 ret = get_errno(sys_getdents64(arg1, dirp, count));
1999 if (!is_error(ret)) {
2000 struct dirent64 *de;
2005 reclen = de->d_reclen;
2008 de->d_reclen = tswap16(reclen);
2009 tswap64s(&de->d_ino);
2010 tswap64s(&de->d_off);
2011 de = (struct dirent64 *)((char *)de + reclen);
2017 case TARGET_NR__newselect:
2018 ret = do_select(arg1, (void *)arg2, (void *)arg3, (void *)arg4,
2021 case TARGET_NR_poll:
2023 struct target_pollfd *target_pfd = (void *)arg1;
2024 unsigned int nfds = arg2;
2029 pfd = alloca(sizeof(struct pollfd) * nfds);
2030 for(i = 0; i < nfds; i++) {
2031 pfd[i].fd = tswap32(target_pfd[i].fd);
2032 pfd[i].events = tswap16(target_pfd[i].events);
2034 ret = get_errno(poll(pfd, nfds, timeout));
2035 if (!is_error(ret)) {
2036 for(i = 0; i < nfds; i++) {
2037 target_pfd[i].revents = tswap16(pfd[i].revents);
2042 case TARGET_NR_flock:
2043 /* NOTE: the flock constant seems to be the same for every
2045 ret = get_errno(flock(arg1, arg2));
2047 case TARGET_NR_readv:
2052 struct target_iovec *target_vec = (void *)arg2;
2054 vec = alloca(count * sizeof(struct iovec));
2055 for(i = 0;i < count; i++) {
2056 vec[i].iov_base = (void *)tswapl(target_vec[i].iov_base);
2057 vec[i].iov_len = tswapl(target_vec[i].iov_len);
2059 ret = get_errno(readv(arg1, vec, count));
2062 case TARGET_NR_writev:
2067 struct target_iovec *target_vec = (void *)arg2;
2069 vec = alloca(count * sizeof(struct iovec));
2070 for(i = 0;i < count; i++) {
2071 vec[i].iov_base = (void *)tswapl(target_vec[i].iov_base);
2072 vec[i].iov_len = tswapl(target_vec[i].iov_len);
2074 ret = get_errno(writev(arg1, vec, count));
2077 case TARGET_NR_getsid:
2078 ret = get_errno(getsid(arg1));
2080 case TARGET_NR_fdatasync:
2081 ret = get_errno(fdatasync(arg1));
2083 case TARGET_NR__sysctl:
2085 case TARGET_NR_sched_setparam:
2087 struct sched_param *target_schp = (void *)arg2;
2088 struct sched_param schp;
2089 schp.sched_priority = tswap32(target_schp->sched_priority);
2090 ret = get_errno(sched_setparam(arg1, &schp));
2093 case TARGET_NR_sched_getparam:
2095 struct sched_param *target_schp = (void *)arg2;
2096 struct sched_param schp;
2097 ret = get_errno(sched_getparam(arg1, &schp));
2098 if (!is_error(ret)) {
2099 target_schp->sched_priority = tswap32(schp.sched_priority);
2103 case TARGET_NR_sched_setscheduler:
2105 struct sched_param *target_schp = (void *)arg3;
2106 struct sched_param schp;
2107 schp.sched_priority = tswap32(target_schp->sched_priority);
2108 ret = get_errno(sched_setscheduler(arg1, arg2, &schp));
2111 case TARGET_NR_sched_getscheduler:
2112 ret = get_errno(sched_getscheduler(arg1));
2114 case TARGET_NR_sched_yield:
2115 ret = get_errno(sched_yield());
2117 case TARGET_NR_sched_get_priority_max:
2118 ret = get_errno(sched_get_priority_max(arg1));
2120 case TARGET_NR_sched_get_priority_min:
2121 ret = get_errno(sched_get_priority_min(arg1));
2123 case TARGET_NR_sched_rr_get_interval:
2125 struct target_timespec *target_ts = (void *)arg2;
2127 ret = get_errno(sched_rr_get_interval(arg1, &ts));
2128 if (!is_error(ret)) {
2129 target_ts->tv_sec = tswapl(ts.tv_sec);
2130 target_ts->tv_nsec = tswapl(ts.tv_nsec);
2134 case TARGET_NR_nanosleep:
2136 struct target_timespec *target_req = (void *)arg1;
2137 struct target_timespec *target_rem = (void *)arg2;
2138 struct timespec req, rem;
2139 req.tv_sec = tswapl(target_req->tv_sec);
2140 req.tv_nsec = tswapl(target_req->tv_nsec);
2141 ret = get_errno(nanosleep(&req, &rem));
2143 target_rem->tv_sec = tswapl(rem.tv_sec);
2144 target_rem->tv_nsec = tswapl(rem.tv_nsec);
2148 case TARGET_NR_setresuid:
2149 ret = get_errno(setresuid(low2highuid(arg1),
2151 low2highuid(arg3)));
2153 case TARGET_NR_getresuid:
2155 int ruid, euid, suid;
2156 ret = get_errno(getresuid(&ruid, &euid, &suid));
2157 if (!is_error(ret)) {
2158 *(uint16_t *)arg1 = tswap16(high2lowuid(ruid));
2159 *(uint16_t *)arg2 = tswap16(high2lowuid(euid));
2160 *(uint16_t *)arg3 = tswap16(high2lowuid(suid));
2164 case TARGET_NR_setresgid:
2165 ret = get_errno(setresgid(low2highgid(arg1),
2167 low2highgid(arg3)));
2169 case TARGET_NR_getresgid:
2171 int rgid, egid, sgid;
2172 ret = get_errno(getresgid(&rgid, &egid, &sgid));
2173 if (!is_error(ret)) {
2174 *(uint16_t *)arg1 = high2lowgid(tswap16(rgid));
2175 *(uint16_t *)arg2 = high2lowgid(tswap16(egid));
2176 *(uint16_t *)arg3 = high2lowgid(tswap16(sgid));
2180 case TARGET_NR_query_module:
2182 case TARGET_NR_nfsservctl:
2184 case TARGET_NR_prctl:
2186 case TARGET_NR_pread:
2188 case TARGET_NR_pwrite:
2190 case TARGET_NR_chown:
2191 ret = get_errno(chown((const char *)arg1, arg2, arg3));
2193 case TARGET_NR_getcwd:
2194 ret = get_errno(sys_getcwd1((char *)arg1, arg2));
2196 case TARGET_NR_capget:
2198 case TARGET_NR_capset:
2200 case TARGET_NR_sigaltstack:
2202 case TARGET_NR_sendfile:
2204 case TARGET_NR_getpmsg:
2206 case TARGET_NR_putpmsg:
2208 case TARGET_NR_vfork:
2209 ret = get_errno(do_fork(cpu_env, CLONE_VFORK | CLONE_VM | SIGCHLD, 0));
2211 case TARGET_NR_ugetrlimit:
2213 case TARGET_NR_truncate64:
2215 case TARGET_NR_ftruncate64:
2217 case TARGET_NR_stat64:
2218 ret = get_errno(stat((const char *)arg1, &st));
2220 case TARGET_NR_lstat64:
2221 ret = get_errno(lstat((const char *)arg1, &st));
2223 case TARGET_NR_fstat64:
2225 ret = get_errno(fstat(arg1, &st));
2227 if (!is_error(ret)) {
2228 struct target_stat64 *target_st = (void *)arg2;
2229 target_st->st_dev = tswap16(st.st_dev);
2230 target_st->st_ino = tswapl(st.st_ino);
2231 target_st->st_mode = tswap16(st.st_mode);
2232 target_st->st_nlink = tswap16(st.st_nlink);
2233 target_st->st_uid = tswap16(st.st_uid);
2234 target_st->st_gid = tswap16(st.st_gid);
2235 target_st->st_rdev = tswap16(st.st_rdev);
2236 /* XXX: better use of kernel struct */
2237 target_st->st_size = tswapl(st.st_size);
2238 target_st->st_blksize = tswapl(st.st_blksize);
2239 target_st->st_blocks = tswapl(st.st_blocks);
2240 target_st->target_st_atime = tswapl(st.st_atime);
2241 target_st->target_st_mtime = tswapl(st.st_mtime);
2242 target_st->target_st_ctime = tswapl(st.st_ctime);
2247 case TARGET_NR_lchown32:
2248 ret = get_errno(lchown((const char *)arg1, arg2, arg3));
2250 case TARGET_NR_getuid32:
2251 ret = get_errno(getuid());
2253 case TARGET_NR_getgid32:
2254 ret = get_errno(getgid());
2256 case TARGET_NR_geteuid32:
2257 ret = get_errno(geteuid());
2259 case TARGET_NR_getegid32:
2260 ret = get_errno(getegid());
2262 case TARGET_NR_setreuid32:
2263 ret = get_errno(setreuid(arg1, arg2));
2265 case TARGET_NR_setregid32:
2266 ret = get_errno(setregid(arg1, arg2));
2268 case TARGET_NR_getgroups32:
2270 case TARGET_NR_setgroups32:
2272 case TARGET_NR_fchown32:
2273 ret = get_errno(fchown(arg1, arg2, arg3));
2275 case TARGET_NR_setresuid32:
2276 ret = get_errno(setresuid(arg1, arg2, arg3));
2278 case TARGET_NR_getresuid32:
2280 int ruid, euid, suid;
2281 ret = get_errno(getresuid(&ruid, &euid, &suid));
2282 if (!is_error(ret)) {
2283 *(uint32_t *)arg1 = tswap32(ruid);
2284 *(uint32_t *)arg2 = tswap32(euid);
2285 *(uint32_t *)arg3 = tswap32(suid);
2289 case TARGET_NR_setresgid32:
2290 ret = get_errno(setresgid(arg1, arg2, arg3));
2292 case TARGET_NR_getresgid32:
2294 int rgid, egid, sgid;
2295 ret = get_errno(getresgid(&rgid, &egid, &sgid));
2296 if (!is_error(ret)) {
2297 *(uint32_t *)arg1 = tswap32(rgid);
2298 *(uint32_t *)arg2 = tswap32(egid);
2299 *(uint32_t *)arg3 = tswap32(sgid);
2303 case TARGET_NR_chown32:
2304 ret = get_errno(chown((const char *)arg1, arg2, arg3));
2306 case TARGET_NR_setuid32:
2307 ret = get_errno(setuid(arg1));
2309 case TARGET_NR_setgid32:
2310 ret = get_errno(setgid(arg1));
2312 case TARGET_NR_setfsuid32:
2313 ret = get_errno(setfsuid(arg1));
2315 case TARGET_NR_setfsgid32:
2316 ret = get_errno(setfsgid(arg1));
2318 case TARGET_NR_pivot_root:
2320 case TARGET_NR_mincore:
2322 case TARGET_NR_madvise:
2324 #if TARGET_LONG_BITS == 32
2325 case TARGET_NR_fcntl64:
2332 ret = get_errno(fcntl(arg1, arg2, arg3));
2337 case TARGET_NR_security:
2339 case TARGET_NR_gettid:
2340 ret = get_errno(gettid());
2342 case TARGET_NR_readahead:
2344 case TARGET_NR_setxattr:
2345 case TARGET_NR_lsetxattr:
2346 case TARGET_NR_fsetxattr:
2347 case TARGET_NR_getxattr:
2348 case TARGET_NR_lgetxattr:
2349 case TARGET_NR_fgetxattr:
2350 case TARGET_NR_listxattr:
2351 case TARGET_NR_llistxattr:
2352 case TARGET_NR_flistxattr:
2353 case TARGET_NR_removexattr:
2354 case TARGET_NR_lremovexattr:
2355 case TARGET_NR_fremovexattr:
2356 goto unimplemented_nowarn;
2357 case TARGET_NR_set_thread_area:
2358 case TARGET_NR_get_thread_area:
2359 goto unimplemented_nowarn;
2362 gemu_log("qemu: Unsupported syscall: %d\n", num);
2363 unimplemented_nowarn: