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.
29 #include <sys/types.h>
33 #include <sys/mount.h>
34 #include <sys/resource.h>
39 #include <sys/socket.h>
41 //#include <sys/user.h>
43 #define termios host_termios
44 #define winsize host_winsize
45 #define termio host_termio
46 #define sgttyb host_sgttyb /* same as target */
47 #define tchars host_tchars /* same as target */
48 #define ltchars host_ltchars /* same as target */
50 #include <linux/termios.h>
51 #include <linux/unistd.h>
52 #include <linux/utsname.h>
53 #include <linux/cdrom.h>
54 #include <linux/hdreg.h>
55 #include <linux/soundcard.h>
56 #include <linux/dirent.h>
63 #define PAGE_SIZE 4096
64 #define PAGE_MASK ~(PAGE_SIZE - 1)
67 //#include <linux/msdos_fs.h>
68 #define VFAT_IOCTL_READDIR_BOTH _IOR('r', 1, struct dirent [2])
69 #define VFAT_IOCTL_READDIR_SHORT _IOR('r', 2, struct dirent [2])
71 #include "syscall_defs.h"
75 #include "syscall-i386.h"
78 void host_to_target_siginfo(target_siginfo_t
*tinfo
, siginfo_t
*info
);
79 void target_to_host_siginfo(siginfo_t
*info
, target_siginfo_t
*tinfo
);
80 long do_sigreturn(CPUX86State
*env
);
81 long do_rt_sigreturn(CPUX86State
*env
);
83 #define __NR_sys_uname __NR_uname
84 #define __NR_sys_getcwd1 __NR_getcwd
85 #define __NR_sys_statfs __NR_statfs
86 #define __NR_sys_fstatfs __NR_fstatfs
87 #define __NR_sys_getdents __NR_getdents
88 #define __NR_sys_getdents64 __NR_getdents64
89 #define __NR_sys_rt_sigqueueinfo __NR_rt_sigqueueinfo
92 _syscall0(int, gettid
)
94 static int gettid(void) {
98 _syscall1(int,sys_uname
,struct new_utsname
*,buf
)
99 _syscall2(int,sys_getcwd1
,char *,buf
,size_t,size
)
100 _syscall3(int, sys_getdents
, uint
, fd
, struct dirent
*, dirp
, uint
, count
);
101 _syscall3(int, sys_getdents64
, uint
, fd
, struct dirent64
*, dirp
, uint
, count
);
102 _syscall5(int, _llseek
, uint
, fd
, ulong
, hi
, ulong
, lo
,
103 loff_t
*, res
, uint
, wh
);
104 _syscall2(int,sys_statfs
,const char *,path
,struct kernel_statfs
*,buf
)
105 _syscall2(int,sys_fstatfs
,int,fd
,struct kernel_statfs
*,buf
)
106 _syscall3(int,sys_rt_sigqueueinfo
,int,pid
,int,sig
,siginfo_t
*,uinfo
)
108 extern int personality(int);
110 static inline long get_errno(long ret
)
118 static inline int is_error(long ret
)
120 return (unsigned long)ret
>= (unsigned long)(-4096);
123 static char *target_brk
;
124 static char *target_original_brk
;
126 void target_set_brk(char *new_brk
)
128 target_brk
= new_brk
;
129 target_original_brk
= new_brk
;
132 static long do_brk(char *new_brk
)
139 return (long)target_brk
;
140 if (new_brk
< target_original_brk
)
143 brk_page
= (char *)(((unsigned long)target_brk
+ PAGE_SIZE
- 1) & PAGE_MASK
);
145 /* If the new brk is less than this, set it and we're done... */
146 if (new_brk
< brk_page
) {
147 target_brk
= new_brk
;
148 return (long)target_brk
;
151 /* We need to allocate more memory after the brk... */
152 new_alloc_size
= ((new_brk
- brk_page
+ 1)+(PAGE_SIZE
-1)) & PAGE_MASK
;
153 mapped_addr
= get_errno((long)mmap((caddr_t
)brk_page
, new_alloc_size
,
154 PROT_READ
|PROT_WRITE
,
155 MAP_ANON
|MAP_FIXED
|MAP_PRIVATE
, 0, 0));
157 if (is_error(mapped_addr
)) {
160 target_brk
= new_brk
;
161 return (long)target_brk
;
165 static inline fd_set
*target_to_host_fds(fd_set
*fds
,
166 target_long
*target_fds
, int n
)
168 #if !defined(BSWP_NEEDED) && !defined(WORD_BIGENDIAN)
169 return (fd_set
*)target_fds
;
174 for(i
= 0;i
< n
; i
++) {
175 b
= (tswapl(target_fds
[i
/ TARGET_LONG_BITS
]) >>
176 (i
& (TARGET_LONG_BITS
- 1))) & 1;
187 static inline void host_to_target_fds(target_long
*target_fds
,
190 #if !defined(BSWP_NEEDED) && !defined(WORD_BIGENDIAN)
197 nw
= n
/ TARGET_LONG_BITS
;
199 for(i
= 0;i
< nw
; i
++) {
201 for(j
= 0; j
< TARGET_LONG_BITS
; j
++) {
202 v
|= ((FD_ISSET(k
, fds
) != 0) << j
);
205 target_fds
[i
] = tswapl(v
);
211 static inline void target_to_host_timeval(struct timeval
*tv
,
212 struct target_timeval
*target_tv
)
214 tv
->tv_sec
= tswapl(target_tv
->tv_sec
);
215 tv
->tv_usec
= tswapl(target_tv
->tv_usec
);
218 static inline void host_to_target_timeval(struct target_timeval
*target_tv
,
221 target_tv
->tv_sec
= tswapl(tv
->tv_sec
);
222 target_tv
->tv_usec
= tswapl(tv
->tv_usec
);
226 static long do_select(long n
,
227 target_long
*target_rfds
, target_long
*target_wfds
,
228 target_long
*target_efds
, struct target_timeval
*target_tv
)
230 fd_set rfds
, wfds
, efds
;
231 fd_set
*rfds_ptr
, *wfds_ptr
, *efds_ptr
;
232 struct timeval tv
, *tv_ptr
;
235 rfds_ptr
= target_to_host_fds(&rfds
, target_rfds
, n
);
236 wfds_ptr
= target_to_host_fds(&wfds
, target_wfds
, n
);
237 efds_ptr
= target_to_host_fds(&efds
, target_efds
, n
);
240 tv
.tv_sec
= tswapl(target_tv
->tv_sec
);
241 tv
.tv_usec
= tswapl(target_tv
->tv_usec
);
246 ret
= get_errno(select(n
, rfds_ptr
, wfds_ptr
, efds_ptr
, tv_ptr
));
247 if (!is_error(ret
)) {
248 host_to_target_fds(target_rfds
, rfds_ptr
, n
);
249 host_to_target_fds(target_wfds
, wfds_ptr
, n
);
250 host_to_target_fds(target_efds
, efds_ptr
, n
);
253 target_tv
->tv_sec
= tswapl(tv
.tv_sec
);
254 target_tv
->tv_usec
= tswapl(tv
.tv_usec
);
260 static long do_socketcall(int num
, long *vptr
)
266 ret
= get_errno(socket(vptr
[0], vptr
[1], vptr
[2]));
269 ret
= get_errno(bind(vptr
[0], (struct sockaddr
*)vptr
[1], vptr
[2]));
272 ret
= get_errno(connect(vptr
[0], (struct sockaddr
*)vptr
[1], vptr
[2]));
275 ret
= get_errno(listen(vptr
[0], vptr
[1]));
280 size
= tswap32(*(int32_t *)vptr
[2]);
281 ret
= get_errno(accept(vptr
[0], (struct sockaddr
*)vptr
[1], &size
));
283 *(int32_t *)vptr
[2] = size
;
286 case SOCKOP_getsockname
:
289 size
= tswap32(*(int32_t *)vptr
[2]);
290 ret
= get_errno(getsockname(vptr
[0], (struct sockaddr
*)vptr
[1], &size
));
292 *(int32_t *)vptr
[2] = size
;
295 case SOCKOP_getpeername
:
298 size
= tswap32(*(int32_t *)vptr
[2]);
299 ret
= get_errno(getpeername(vptr
[0], (struct sockaddr
*)vptr
[1], &size
));
301 *(int32_t *)vptr
[2] = size
;
304 case SOCKOP_socketpair
:
307 int32_t *target_tab
= (int32_t *)vptr
[3];
308 ret
= get_errno(socketpair(vptr
[0], vptr
[1], vptr
[2], tab
));
309 if (!is_error(ret
)) {
310 target_tab
[0] = tswap32(tab
[0]);
311 target_tab
[1] = tswap32(tab
[1]);
316 ret
= get_errno(send(vptr
[0], (void *)vptr
[1], vptr
[2], vptr
[3]));
319 ret
= get_errno(recv(vptr
[0], (void *)vptr
[1], vptr
[2], vptr
[3]));
322 ret
= get_errno(sendto(vptr
[0], (void *)vptr
[1], vptr
[2], vptr
[3],
323 (struct sockaddr
*)vptr
[4], vptr
[5]));
325 case SOCKOP_recvfrom
:
328 size
= tswap32(*(int32_t *)vptr
[5]);
329 ret
= get_errno(recvfrom(vptr
[0], (void *)vptr
[1], vptr
[2],
330 vptr
[3], (struct sockaddr
*)vptr
[4], &size
));
332 *(int32_t *)vptr
[5] = size
;
335 case SOCKOP_shutdown
:
336 ret
= get_errno(shutdown(vptr
[0], vptr
[1]));
342 struct target_msghdr
*msgp
;
346 struct target_iovec
*target_vec
;
348 msgp
= (void *)vptr
[1];
349 msg
.msg_name
= (void *)tswapl(msgp
->msg_name
);
350 msg
.msg_namelen
= tswapl(msgp
->msg_namelen
);
351 msg
.msg_control
= (void *)tswapl(msgp
->msg_control
);
352 msg
.msg_controllen
= tswapl(msgp
->msg_controllen
);
353 msg
.msg_flags
= tswap32(msgp
->msg_flags
);
355 count
= tswapl(msgp
->msg_iovlen
);
356 vec
= alloca(count
* sizeof(struct iovec
));
357 target_vec
= (void *)tswapl(msgp
->msg_iov
);
358 for(i
= 0;i
< count
; i
++) {
359 vec
[i
].iov_base
= (void *)tswapl(target_vec
[i
].iov_base
);
360 vec
[i
].iov_len
= tswapl(target_vec
[i
].iov_len
);
362 msg
.msg_iovlen
= count
;
367 if (num
== SOCKOP_sendmsg
)
368 ret
= sendmsg(fd
, &msg
, flags
);
370 ret
= recvmsg(fd
, &msg
, flags
);
371 ret
= get_errno(ret
);
374 case SOCKOP_setsockopt
:
375 case SOCKOP_getsockopt
:
377 gemu_log("Unsupported socketcall: %d\n", num
);
384 /* kernel structure types definitions */
387 #define STRUCT(name, list...) STRUCT_ ## name,
388 #define STRUCT_SPECIAL(name) STRUCT_ ## name,
390 #include "syscall_types.h"
393 #undef STRUCT_SPECIAL
395 #define STRUCT(name, list...) const argtype struct_ ## name ## _def[] = { list, TYPE_NULL };
396 #define STRUCT_SPECIAL(name)
397 #include "syscall_types.h"
399 #undef STRUCT_SPECIAL
401 typedef struct IOCTLEntry
{
406 const argtype arg_type
[5];
411 #define IOC_RW (IOC_R | IOC_W)
413 #define MAX_STRUCT_SIZE 4096
415 const IOCTLEntry ioctl_entries
[] = {
416 #define IOCTL(cmd, access, types...) \
417 { TARGET_ ## cmd, cmd, #cmd, access, { types } },
422 static long do_ioctl(long fd
, long cmd
, long arg
)
424 const IOCTLEntry
*ie
;
425 const argtype
*arg_type
;
427 uint8_t buf_temp
[MAX_STRUCT_SIZE
];
431 if (ie
->target_cmd
== 0) {
432 gemu_log("Unsupported ioctl: cmd=0x%04lx\n", cmd
);
435 if (ie
->target_cmd
== cmd
)
439 arg_type
= ie
->arg_type
;
441 gemu_log("ioctl: cmd=0x%04lx (%s)\n", cmd
, ie
->name
);
443 switch(arg_type
[0]) {
446 ret
= get_errno(ioctl(fd
, ie
->host_cmd
));
451 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, arg
));
457 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, buf_temp
));
458 if (!is_error(ret
)) {
459 thunk_convert((void *)arg
, buf_temp
, arg_type
, THUNK_TARGET
);
463 thunk_convert(buf_temp
, (void *)arg
, arg_type
, THUNK_HOST
);
464 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, buf_temp
));
468 thunk_convert(buf_temp
, (void *)arg
, arg_type
, THUNK_HOST
);
469 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, buf_temp
));
470 if (!is_error(ret
)) {
471 thunk_convert((void *)arg
, buf_temp
, arg_type
, THUNK_TARGET
);
477 gemu_log("Unsupported ioctl type: cmd=0x%04lx type=%d\n", cmd
, arg_type
[0]);
484 bitmask_transtbl iflag_tbl
[] = {
485 { TARGET_IGNBRK
, TARGET_IGNBRK
, IGNBRK
, IGNBRK
},
486 { TARGET_BRKINT
, TARGET_BRKINT
, BRKINT
, BRKINT
},
487 { TARGET_IGNPAR
, TARGET_IGNPAR
, IGNPAR
, IGNPAR
},
488 { TARGET_PARMRK
, TARGET_PARMRK
, PARMRK
, PARMRK
},
489 { TARGET_INPCK
, TARGET_INPCK
, INPCK
, INPCK
},
490 { TARGET_ISTRIP
, TARGET_ISTRIP
, ISTRIP
, ISTRIP
},
491 { TARGET_INLCR
, TARGET_INLCR
, INLCR
, INLCR
},
492 { TARGET_IGNCR
, TARGET_IGNCR
, IGNCR
, IGNCR
},
493 { TARGET_ICRNL
, TARGET_ICRNL
, ICRNL
, ICRNL
},
494 { TARGET_IUCLC
, TARGET_IUCLC
, IUCLC
, IUCLC
},
495 { TARGET_IXON
, TARGET_IXON
, IXON
, IXON
},
496 { TARGET_IXANY
, TARGET_IXANY
, IXANY
, IXANY
},
497 { TARGET_IXOFF
, TARGET_IXOFF
, IXOFF
, IXOFF
},
498 { TARGET_IMAXBEL
, TARGET_IMAXBEL
, IMAXBEL
, IMAXBEL
},
502 bitmask_transtbl oflag_tbl
[] = {
503 { TARGET_OPOST
, TARGET_OPOST
, OPOST
, OPOST
},
504 { TARGET_OLCUC
, TARGET_OLCUC
, OLCUC
, OLCUC
},
505 { TARGET_ONLCR
, TARGET_ONLCR
, ONLCR
, ONLCR
},
506 { TARGET_OCRNL
, TARGET_OCRNL
, OCRNL
, OCRNL
},
507 { TARGET_ONOCR
, TARGET_ONOCR
, ONOCR
, ONOCR
},
508 { TARGET_ONLRET
, TARGET_ONLRET
, ONLRET
, ONLRET
},
509 { TARGET_OFILL
, TARGET_OFILL
, OFILL
, OFILL
},
510 { TARGET_OFDEL
, TARGET_OFDEL
, OFDEL
, OFDEL
},
511 { TARGET_NLDLY
, TARGET_NL0
, NLDLY
, NL0
},
512 { TARGET_NLDLY
, TARGET_NL1
, NLDLY
, NL1
},
513 { TARGET_CRDLY
, TARGET_CR0
, CRDLY
, CR0
},
514 { TARGET_CRDLY
, TARGET_CR1
, CRDLY
, CR1
},
515 { TARGET_CRDLY
, TARGET_CR2
, CRDLY
, CR2
},
516 { TARGET_CRDLY
, TARGET_CR3
, CRDLY
, CR3
},
517 { TARGET_TABDLY
, TARGET_TAB0
, TABDLY
, TAB0
},
518 { TARGET_TABDLY
, TARGET_TAB1
, TABDLY
, TAB1
},
519 { TARGET_TABDLY
, TARGET_TAB2
, TABDLY
, TAB2
},
520 { TARGET_TABDLY
, TARGET_TAB3
, TABDLY
, TAB3
},
521 { TARGET_BSDLY
, TARGET_BS0
, BSDLY
, BS0
},
522 { TARGET_BSDLY
, TARGET_BS1
, BSDLY
, BS1
},
523 { TARGET_VTDLY
, TARGET_VT0
, VTDLY
, VT0
},
524 { TARGET_VTDLY
, TARGET_VT1
, VTDLY
, VT1
},
525 { TARGET_FFDLY
, TARGET_FF0
, FFDLY
, FF0
},
526 { TARGET_FFDLY
, TARGET_FF1
, FFDLY
, FF1
},
530 bitmask_transtbl cflag_tbl
[] = {
531 { TARGET_CBAUD
, TARGET_B0
, CBAUD
, B0
},
532 { TARGET_CBAUD
, TARGET_B50
, CBAUD
, B50
},
533 { TARGET_CBAUD
, TARGET_B75
, CBAUD
, B75
},
534 { TARGET_CBAUD
, TARGET_B110
, CBAUD
, B110
},
535 { TARGET_CBAUD
, TARGET_B134
, CBAUD
, B134
},
536 { TARGET_CBAUD
, TARGET_B150
, CBAUD
, B150
},
537 { TARGET_CBAUD
, TARGET_B200
, CBAUD
, B200
},
538 { TARGET_CBAUD
, TARGET_B300
, CBAUD
, B300
},
539 { TARGET_CBAUD
, TARGET_B600
, CBAUD
, B600
},
540 { TARGET_CBAUD
, TARGET_B1200
, CBAUD
, B1200
},
541 { TARGET_CBAUD
, TARGET_B1800
, CBAUD
, B1800
},
542 { TARGET_CBAUD
, TARGET_B2400
, CBAUD
, B2400
},
543 { TARGET_CBAUD
, TARGET_B4800
, CBAUD
, B4800
},
544 { TARGET_CBAUD
, TARGET_B9600
, CBAUD
, B9600
},
545 { TARGET_CBAUD
, TARGET_B19200
, CBAUD
, B19200
},
546 { TARGET_CBAUD
, TARGET_B38400
, CBAUD
, B38400
},
547 { TARGET_CBAUD
, TARGET_B57600
, CBAUD
, B57600
},
548 { TARGET_CBAUD
, TARGET_B115200
, CBAUD
, B115200
},
549 { TARGET_CBAUD
, TARGET_B230400
, CBAUD
, B230400
},
550 { TARGET_CBAUD
, TARGET_B460800
, CBAUD
, B460800
},
551 { TARGET_CSIZE
, TARGET_CS5
, CSIZE
, CS5
},
552 { TARGET_CSIZE
, TARGET_CS6
, CSIZE
, CS6
},
553 { TARGET_CSIZE
, TARGET_CS7
, CSIZE
, CS7
},
554 { TARGET_CSIZE
, TARGET_CS8
, CSIZE
, CS8
},
555 { TARGET_CSTOPB
, TARGET_CSTOPB
, CSTOPB
, CSTOPB
},
556 { TARGET_CREAD
, TARGET_CREAD
, CREAD
, CREAD
},
557 { TARGET_PARENB
, TARGET_PARENB
, PARENB
, PARENB
},
558 { TARGET_PARODD
, TARGET_PARODD
, PARODD
, PARODD
},
559 { TARGET_HUPCL
, TARGET_HUPCL
, HUPCL
, HUPCL
},
560 { TARGET_CLOCAL
, TARGET_CLOCAL
, CLOCAL
, CLOCAL
},
561 { TARGET_CRTSCTS
, TARGET_CRTSCTS
, CRTSCTS
, CRTSCTS
},
565 bitmask_transtbl lflag_tbl
[] = {
566 { TARGET_ISIG
, TARGET_ISIG
, ISIG
, ISIG
},
567 { TARGET_ICANON
, TARGET_ICANON
, ICANON
, ICANON
},
568 { TARGET_XCASE
, TARGET_XCASE
, XCASE
, XCASE
},
569 { TARGET_ECHO
, TARGET_ECHO
, ECHO
, ECHO
},
570 { TARGET_ECHOE
, TARGET_ECHOE
, ECHOE
, ECHOE
},
571 { TARGET_ECHOK
, TARGET_ECHOK
, ECHOK
, ECHOK
},
572 { TARGET_ECHONL
, TARGET_ECHONL
, ECHONL
, ECHONL
},
573 { TARGET_NOFLSH
, TARGET_NOFLSH
, NOFLSH
, NOFLSH
},
574 { TARGET_TOSTOP
, TARGET_TOSTOP
, TOSTOP
, TOSTOP
},
575 { TARGET_ECHOCTL
, TARGET_ECHOCTL
, ECHOCTL
, ECHOCTL
},
576 { TARGET_ECHOPRT
, TARGET_ECHOPRT
, ECHOPRT
, ECHOPRT
},
577 { TARGET_ECHOKE
, TARGET_ECHOKE
, ECHOKE
, ECHOKE
},
578 { TARGET_FLUSHO
, TARGET_FLUSHO
, FLUSHO
, FLUSHO
},
579 { TARGET_PENDIN
, TARGET_PENDIN
, PENDIN
, PENDIN
},
580 { TARGET_IEXTEN
, TARGET_IEXTEN
, IEXTEN
, IEXTEN
},
584 static void target_to_host_termios (void *dst
, const void *src
)
586 struct host_termios
*host
= dst
;
587 const struct target_termios
*target
= src
;
590 target_to_host_bitmask(tswap32(target
->c_iflag
), iflag_tbl
);
592 target_to_host_bitmask(tswap32(target
->c_oflag
), oflag_tbl
);
594 target_to_host_bitmask(tswap32(target
->c_cflag
), cflag_tbl
);
596 target_to_host_bitmask(tswap32(target
->c_lflag
), lflag_tbl
);
597 host
->c_line
= target
->c_line
;
599 host
->c_cc
[VINTR
] = target
->c_cc
[TARGET_VINTR
];
600 host
->c_cc
[VQUIT
] = target
->c_cc
[TARGET_VQUIT
];
601 host
->c_cc
[VERASE
] = target
->c_cc
[TARGET_VERASE
];
602 host
->c_cc
[VKILL
] = target
->c_cc
[TARGET_VKILL
];
603 host
->c_cc
[VEOF
] = target
->c_cc
[TARGET_VEOF
];
604 host
->c_cc
[VTIME
] = target
->c_cc
[TARGET_VTIME
];
605 host
->c_cc
[VMIN
] = target
->c_cc
[TARGET_VMIN
];
606 host
->c_cc
[VSWTC
] = target
->c_cc
[TARGET_VSWTC
];
607 host
->c_cc
[VSTART
] = target
->c_cc
[TARGET_VSTART
];
608 host
->c_cc
[VSTOP
] = target
->c_cc
[TARGET_VSTOP
];
609 host
->c_cc
[VSUSP
] = target
->c_cc
[TARGET_VSUSP
];
610 host
->c_cc
[VEOL
] = target
->c_cc
[TARGET_VEOL
];
611 host
->c_cc
[VREPRINT
] = target
->c_cc
[TARGET_VREPRINT
];
612 host
->c_cc
[VDISCARD
] = target
->c_cc
[TARGET_VDISCARD
];
613 host
->c_cc
[VWERASE
] = target
->c_cc
[TARGET_VWERASE
];
614 host
->c_cc
[VLNEXT
] = target
->c_cc
[TARGET_VLNEXT
];
615 host
->c_cc
[VEOL2
] = target
->c_cc
[TARGET_VEOL2
];
618 static void host_to_target_termios (void *dst
, const void *src
)
620 struct target_termios
*target
= dst
;
621 const struct host_termios
*host
= src
;
624 tswap32(host_to_target_bitmask(host
->c_iflag
, iflag_tbl
));
626 tswap32(host_to_target_bitmask(host
->c_oflag
, oflag_tbl
));
628 tswap32(host_to_target_bitmask(host
->c_cflag
, cflag_tbl
));
630 tswap32(host_to_target_bitmask(host
->c_lflag
, lflag_tbl
));
631 target
->c_line
= host
->c_line
;
633 target
->c_cc
[TARGET_VINTR
] = host
->c_cc
[VINTR
];
634 target
->c_cc
[TARGET_VQUIT
] = host
->c_cc
[VQUIT
];
635 target
->c_cc
[TARGET_VERASE
] = host
->c_cc
[VERASE
];
636 target
->c_cc
[TARGET_VKILL
] = host
->c_cc
[VKILL
];
637 target
->c_cc
[TARGET_VEOF
] = host
->c_cc
[VEOF
];
638 target
->c_cc
[TARGET_VTIME
] = host
->c_cc
[VTIME
];
639 target
->c_cc
[TARGET_VMIN
] = host
->c_cc
[VMIN
];
640 target
->c_cc
[TARGET_VSWTC
] = host
->c_cc
[VSWTC
];
641 target
->c_cc
[TARGET_VSTART
] = host
->c_cc
[VSTART
];
642 target
->c_cc
[TARGET_VSTOP
] = host
->c_cc
[VSTOP
];
643 target
->c_cc
[TARGET_VSUSP
] = host
->c_cc
[VSUSP
];
644 target
->c_cc
[TARGET_VEOL
] = host
->c_cc
[VEOL
];
645 target
->c_cc
[TARGET_VREPRINT
] = host
->c_cc
[VREPRINT
];
646 target
->c_cc
[TARGET_VDISCARD
] = host
->c_cc
[VDISCARD
];
647 target
->c_cc
[TARGET_VWERASE
] = host
->c_cc
[VWERASE
];
648 target
->c_cc
[TARGET_VLNEXT
] = host
->c_cc
[VLNEXT
];
649 target
->c_cc
[TARGET_VEOL2
] = host
->c_cc
[VEOL2
];
652 StructEntry struct_termios_def
= {
653 .convert
= { host_to_target_termios
, target_to_host_termios
},
654 .size
= { sizeof(struct target_termios
), sizeof(struct host_termios
) },
655 .align
= { __alignof__(struct target_termios
), __alignof__(struct host_termios
) },
660 /* NOTE: there is really one LDT for all the threads */
663 static int read_ldt(void *ptr
, unsigned long bytecount
)
669 size
= TARGET_LDT_ENTRIES
* TARGET_LDT_ENTRY_SIZE
;
670 if (size
> bytecount
)
672 memcpy(ptr
, ldt_table
, size
);
676 /* XXX: add locking support */
677 static int write_ldt(CPUX86State
*env
,
678 void *ptr
, unsigned long bytecount
, int oldmode
)
680 struct target_modify_ldt_ldt_s ldt_info
;
681 int seg_32bit
, contents
, read_exec_only
, limit_in_pages
;
682 int seg_not_present
, useable
;
683 uint32_t *lp
, entry_1
, entry_2
;
685 if (bytecount
!= sizeof(ldt_info
))
687 memcpy(&ldt_info
, ptr
, sizeof(ldt_info
));
688 tswap32s(&ldt_info
.entry_number
);
689 tswapls((long *)&ldt_info
.base_addr
);
690 tswap32s(&ldt_info
.limit
);
691 tswap32s(&ldt_info
.flags
);
693 if (ldt_info
.entry_number
>= TARGET_LDT_ENTRIES
)
695 seg_32bit
= ldt_info
.flags
& 1;
696 contents
= (ldt_info
.flags
>> 1) & 3;
697 read_exec_only
= (ldt_info
.flags
>> 3) & 1;
698 limit_in_pages
= (ldt_info
.flags
>> 4) & 1;
699 seg_not_present
= (ldt_info
.flags
>> 5) & 1;
700 useable
= (ldt_info
.flags
>> 6) & 1;
705 if (seg_not_present
== 0)
708 /* allocate the LDT */
710 ldt_table
= malloc(TARGET_LDT_ENTRIES
* TARGET_LDT_ENTRY_SIZE
);
713 memset(ldt_table
, 0, TARGET_LDT_ENTRIES
* TARGET_LDT_ENTRY_SIZE
);
714 env
->ldt
.base
= ldt_table
;
715 env
->ldt
.limit
= 0xffff;
718 /* NOTE: same code as Linux kernel */
719 /* Allow LDTs to be cleared by the user. */
720 if (ldt_info
.base_addr
== 0 && ldt_info
.limit
== 0) {
723 read_exec_only
== 1 &&
725 limit_in_pages
== 0 &&
726 seg_not_present
== 1 &&
734 entry_1
= ((ldt_info
.base_addr
& 0x0000ffff) << 16) |
735 (ldt_info
.limit
& 0x0ffff);
736 entry_2
= (ldt_info
.base_addr
& 0xff000000) |
737 ((ldt_info
.base_addr
& 0x00ff0000) >> 16) |
738 (ldt_info
.limit
& 0xf0000) |
739 ((read_exec_only
^ 1) << 9) |
741 ((seg_not_present
^ 1) << 15) |
743 (limit_in_pages
<< 23) |
746 entry_2
|= (useable
<< 20);
748 /* Install the new entry ... */
750 lp
= (uint32_t *)(ldt_table
+ (ldt_info
.entry_number
<< 3));
751 lp
[0] = tswap32(entry_1
);
752 lp
[1] = tswap32(entry_2
);
756 /* specific and weird i386 syscalls */
757 int gemu_modify_ldt(CPUX86State
*env
, int func
, void *ptr
, unsigned long bytecount
)
763 ret
= read_ldt(ptr
, bytecount
);
766 ret
= write_ldt(env
, ptr
, bytecount
, 1);
769 ret
= write_ldt(env
, ptr
, bytecount
, 0);
775 /* this stack is the equivalent of the kernel stack associated with a
777 #define NEW_STACK_SIZE 8192
779 static int clone_func(void *arg
)
781 CPUX86State
*env
= arg
;
787 int do_fork(CPUX86State
*env
, unsigned int flags
, unsigned long newsp
)
791 CPUX86State
*new_env
;
793 if (flags
& CLONE_VM
) {
795 newsp
= env
->regs
[R_ESP
];
796 new_stack
= malloc(NEW_STACK_SIZE
);
798 /* we create a new CPU instance. */
799 new_env
= cpu_x86_init();
800 memcpy(new_env
, env
, sizeof(CPUX86State
));
801 new_env
->regs
[R_ESP
] = newsp
;
802 new_env
->regs
[R_EAX
] = 0;
803 ret
= clone(clone_func
, new_stack
+ NEW_STACK_SIZE
, flags
, new_env
);
805 /* if no CLONE_VM, we consider it is a fork */
806 if ((flags
& ~CSIGNAL
) != 0)
816 void syscall_init(void)
818 #define STRUCT(name, list...) thunk_register_struct(STRUCT_ ## name, #name, struct_ ## name ## _def);
819 #define STRUCT_SPECIAL(name) thunk_register_struct_direct(STRUCT_ ## name, #name, &struct_ ## name ## _def);
820 #include "syscall_types.h"
822 #undef STRUCT_SPECIAL
825 long do_syscall(void *cpu_env
, int num
, long arg1
, long arg2
, long arg3
,
826 long arg4
, long arg5
, long arg6
)
830 struct kernel_statfs
*stfs
;
833 gemu_log("syscall %d\n", num
);
840 /* XXX: should free thread stack and CPU env */
842 ret
= 0; /* avoid warning */
845 ret
= get_errno(read(arg1
, (void *)arg2
, arg3
));
847 case TARGET_NR_write
:
848 ret
= get_errno(write(arg1
, (void *)arg2
, arg3
));
851 ret
= get_errno(open((const char *)arg1
, arg2
, arg3
));
853 case TARGET_NR_close
:
854 ret
= get_errno(close(arg1
));
857 ret
= do_brk((char *)arg1
);
860 ret
= get_errno(do_fork(cpu_env
, SIGCHLD
, 0));
862 case TARGET_NR_waitpid
:
864 int *status
= (int *)arg2
;
865 ret
= get_errno(waitpid(arg1
, status
, arg3
));
866 if (!is_error(ret
) && status
)
867 tswapls((long *)&status
);
870 case TARGET_NR_creat
:
871 ret
= get_errno(creat((const char *)arg1
, arg2
));
874 ret
= get_errno(link((const char *)arg1
, (const char *)arg2
));
876 case TARGET_NR_unlink
:
877 ret
= get_errno(unlink((const char *)arg1
));
879 case TARGET_NR_execve
:
880 ret
= get_errno(execve((const char *)arg1
, (void *)arg2
, (void *)arg3
));
882 case TARGET_NR_chdir
:
883 ret
= get_errno(chdir((const char *)arg1
));
887 int *time_ptr
= (int *)arg1
;
888 ret
= get_errno(time((time_t *)time_ptr
));
889 if (!is_error(ret
) && time_ptr
)
893 case TARGET_NR_mknod
:
894 ret
= get_errno(mknod((const char *)arg1
, arg2
, arg3
));
896 case TARGET_NR_chmod
:
897 ret
= get_errno(chmod((const char *)arg1
, arg2
));
899 case TARGET_NR_lchown
:
900 ret
= get_errno(chown((const char *)arg1
, arg2
, arg3
));
902 case TARGET_NR_break
:
904 case TARGET_NR_oldstat
:
906 case TARGET_NR_lseek
:
907 ret
= get_errno(lseek(arg1
, arg2
, arg3
));
909 case TARGET_NR_getpid
:
910 ret
= get_errno(getpid());
912 case TARGET_NR_mount
:
913 /* need to look at the data field */
915 case TARGET_NR_umount
:
916 ret
= get_errno(umount((const char *)arg1
));
918 case TARGET_NR_setuid
:
919 ret
= get_errno(setuid(arg1
));
921 case TARGET_NR_getuid
:
922 ret
= get_errno(getuid());
924 case TARGET_NR_stime
:
926 int *time_ptr
= (int *)arg1
;
929 ret
= get_errno(stime((time_t *)time_ptr
));
932 case TARGET_NR_ptrace
:
934 case TARGET_NR_alarm
:
937 case TARGET_NR_oldfstat
:
939 case TARGET_NR_pause
:
940 ret
= get_errno(pause());
942 case TARGET_NR_utime
:
948 case TARGET_NR_access
:
949 ret
= get_errno(access((const char *)arg1
, arg2
));
952 ret
= get_errno(nice(arg1
));
954 case TARGET_NR_ftime
:
961 ret
= get_errno(kill(arg1
, arg2
));
963 case TARGET_NR_rename
:
964 ret
= get_errno(rename((const char *)arg1
, (const char *)arg2
));
966 case TARGET_NR_mkdir
:
967 ret
= get_errno(mkdir((const char *)arg1
, arg2
));
969 case TARGET_NR_rmdir
:
970 ret
= get_errno(rmdir((const char *)arg1
));
973 ret
= get_errno(dup(arg1
));
977 int *pipe_ptr
= (int *)arg1
;
978 ret
= get_errno(pipe(pipe_ptr
));
979 if (!is_error(ret
)) {
980 tswap32s(&pipe_ptr
[0]);
981 tswap32s(&pipe_ptr
[1]);
985 case TARGET_NR_times
:
989 case TARGET_NR_setgid
:
990 ret
= get_errno(setgid(arg1
));
992 case TARGET_NR_getgid
:
993 ret
= get_errno(getgid());
995 case TARGET_NR_signal
:
997 case TARGET_NR_geteuid
:
998 ret
= get_errno(geteuid());
1000 case TARGET_NR_getegid
:
1001 ret
= get_errno(getegid());
1003 case TARGET_NR_acct
:
1005 case TARGET_NR_umount2
:
1006 ret
= get_errno(umount2((const char *)arg1
, arg2
));
1008 case TARGET_NR_lock
:
1010 case TARGET_NR_ioctl
:
1011 ret
= do_ioctl(arg1
, arg2
, arg3
);
1013 case TARGET_NR_fcntl
:
1020 ret
= get_errno(fcntl(arg1
, arg2
, arg3
));
1026 case TARGET_NR_setpgid
:
1027 ret
= get_errno(setpgid(arg1
, arg2
));
1029 case TARGET_NR_ulimit
:
1031 case TARGET_NR_oldolduname
:
1033 case TARGET_NR_umask
:
1034 ret
= get_errno(umask(arg1
));
1036 case TARGET_NR_chroot
:
1037 ret
= get_errno(chroot((const char *)arg1
));
1039 case TARGET_NR_ustat
:
1041 case TARGET_NR_dup2
:
1042 ret
= get_errno(dup2(arg1
, arg2
));
1044 case TARGET_NR_getppid
:
1045 ret
= get_errno(getppid());
1047 case TARGET_NR_getpgrp
:
1048 ret
= get_errno(getpgrp());
1050 case TARGET_NR_setsid
:
1051 ret
= get_errno(setsid());
1053 case TARGET_NR_sigaction
:
1055 struct target_old_sigaction
*old_act
= (void *)arg2
;
1056 struct target_old_sigaction
*old_oact
= (void *)arg3
;
1057 struct target_sigaction act
, oact
, *pact
;
1059 act
._sa_handler
= old_act
->_sa_handler
;
1060 target_siginitset(&act
.sa_mask
, old_act
->sa_mask
);
1061 act
.sa_flags
= old_act
->sa_flags
;
1062 act
.sa_restorer
= old_act
->sa_restorer
;
1067 ret
= get_errno(do_sigaction(arg1
, pact
, &oact
));
1068 if (!is_error(ret
) && old_oact
) {
1069 old_oact
->_sa_handler
= oact
._sa_handler
;
1070 old_oact
->sa_mask
= oact
.sa_mask
.sig
[0];
1071 old_oact
->sa_flags
= oact
.sa_flags
;
1072 old_oact
->sa_restorer
= oact
.sa_restorer
;
1076 case TARGET_NR_rt_sigaction
:
1077 ret
= get_errno(do_sigaction(arg1
, (void *)arg2
, (void *)arg3
));
1079 case TARGET_NR_sgetmask
:
1082 target_ulong target_set
;
1083 sigprocmask(0, NULL
, &cur_set
);
1084 host_to_target_old_sigset(&target_set
, &cur_set
);
1088 case TARGET_NR_ssetmask
:
1090 sigset_t set
, oset
, cur_set
;
1091 target_ulong target_set
= arg1
;
1092 sigprocmask(0, NULL
, &cur_set
);
1093 target_to_host_old_sigset(&set
, &target_set
);
1094 sigorset(&set
, &set
, &cur_set
);
1095 sigprocmask(SIG_SETMASK
, &set
, &oset
);
1096 host_to_target_old_sigset(&target_set
, &oset
);
1100 case TARGET_NR_sigprocmask
:
1103 sigset_t set
, oldset
, *set_ptr
;
1104 target_ulong
*pset
= (void *)arg2
, *poldset
= (void *)arg3
;
1108 case TARGET_SIG_BLOCK
:
1111 case TARGET_SIG_UNBLOCK
:
1114 case TARGET_SIG_SETMASK
:
1121 target_to_host_old_sigset(&set
, pset
);
1127 ret
= get_errno(sigprocmask(arg1
, set_ptr
, &oldset
));
1128 if (!is_error(ret
) && poldset
) {
1129 host_to_target_old_sigset(poldset
, &oldset
);
1133 case TARGET_NR_rt_sigprocmask
:
1136 sigset_t set
, oldset
, *set_ptr
;
1137 target_sigset_t
*pset
= (void *)arg2
;
1138 target_sigset_t
*poldset
= (void *)arg3
;
1142 case TARGET_SIG_BLOCK
:
1145 case TARGET_SIG_UNBLOCK
:
1148 case TARGET_SIG_SETMASK
:
1155 target_to_host_sigset(&set
, pset
);
1161 ret
= get_errno(sigprocmask(how
, set_ptr
, &oldset
));
1162 if (!is_error(ret
) && poldset
) {
1163 host_to_target_sigset(poldset
, &oldset
);
1167 case TARGET_NR_sigpending
:
1170 ret
= get_errno(sigpending(&set
));
1171 if (!is_error(ret
)) {
1172 host_to_target_old_sigset((target_ulong
*)arg1
, &set
);
1176 case TARGET_NR_rt_sigpending
:
1179 ret
= get_errno(sigpending(&set
));
1180 if (!is_error(ret
)) {
1181 host_to_target_sigset((target_sigset_t
*)arg1
, &set
);
1185 case TARGET_NR_sigsuspend
:
1188 target_to_host_old_sigset(&set
, (target_ulong
*)arg1
);
1189 ret
= get_errno(sigsuspend(&set
));
1192 case TARGET_NR_rt_sigsuspend
:
1195 target_to_host_sigset(&set
, (target_sigset_t
*)arg1
);
1196 ret
= get_errno(sigsuspend(&set
));
1199 case TARGET_NR_rt_sigtimedwait
:
1201 target_sigset_t
*target_set
= (void *)arg1
;
1202 target_siginfo_t
*target_uinfo
= (void *)arg2
;
1203 struct target_timespec
*target_uts
= (void *)arg3
;
1205 struct timespec uts
, *puts
;
1208 target_to_host_sigset(&set
, target_set
);
1211 puts
->tv_sec
= tswapl(target_uts
->tv_sec
);
1212 puts
->tv_nsec
= tswapl(target_uts
->tv_nsec
);
1216 ret
= get_errno(sigtimedwait(&set
, &uinfo
, puts
));
1217 if (!is_error(ret
) && target_uinfo
) {
1218 host_to_target_siginfo(target_uinfo
, &uinfo
);
1222 case TARGET_NR_rt_sigqueueinfo
:
1225 target_to_host_siginfo(&uinfo
, (target_siginfo_t
*)arg3
);
1226 ret
= get_errno(sys_rt_sigqueueinfo(arg1
, arg2
, &uinfo
));
1229 case TARGET_NR_sigreturn
:
1230 /* NOTE: ret is eax, so not transcoding must be done */
1231 ret
= do_sigreturn(cpu_env
);
1233 case TARGET_NR_rt_sigreturn
:
1234 /* NOTE: ret is eax, so not transcoding must be done */
1235 ret
= do_rt_sigreturn(cpu_env
);
1237 case TARGET_NR_setreuid
:
1238 ret
= get_errno(setreuid(arg1
, arg2
));
1240 case TARGET_NR_setregid
:
1241 ret
= get_errno(setregid(arg1
, arg2
));
1243 case TARGET_NR_sethostname
:
1244 ret
= get_errno(sethostname((const char *)arg1
, arg2
));
1246 case TARGET_NR_setrlimit
:
1248 case TARGET_NR_getrlimit
:
1250 case TARGET_NR_getrusage
:
1252 case TARGET_NR_gettimeofday
:
1254 struct target_timeval
*target_tv
= (void *)arg1
;
1256 ret
= get_errno(gettimeofday(&tv
, NULL
));
1257 if (!is_error(ret
)) {
1258 target_tv
->tv_sec
= tswapl(tv
.tv_sec
);
1259 target_tv
->tv_usec
= tswapl(tv
.tv_usec
);
1263 case TARGET_NR_settimeofday
:
1265 struct target_timeval
*target_tv
= (void *)arg1
;
1267 tv
.tv_sec
= tswapl(target_tv
->tv_sec
);
1268 tv
.tv_usec
= tswapl(target_tv
->tv_usec
);
1269 ret
= get_errno(settimeofday(&tv
, NULL
));
1272 case TARGET_NR_getgroups
:
1274 case TARGET_NR_setgroups
:
1276 case TARGET_NR_select
:
1278 case TARGET_NR_symlink
:
1279 ret
= get_errno(symlink((const char *)arg1
, (const char *)arg2
));
1281 case TARGET_NR_oldlstat
:
1283 case TARGET_NR_readlink
:
1284 ret
= get_errno(readlink((const char *)arg1
, (char *)arg2
, arg3
));
1286 case TARGET_NR_uselib
:
1288 case TARGET_NR_swapon
:
1289 ret
= get_errno(swapon((const char *)arg1
, arg2
));
1291 case TARGET_NR_reboot
:
1293 case TARGET_NR_readdir
:
1296 case TARGET_NR_mmap
:
1298 uint32_t v1
, v2
, v3
, v4
, v5
, v6
, *vptr
;
1299 vptr
= (uint32_t *)arg1
;
1300 v1
= tswap32(vptr
[0]);
1301 v2
= tswap32(vptr
[1]);
1302 v3
= tswap32(vptr
[2]);
1303 v4
= tswap32(vptr
[3]);
1304 v5
= tswap32(vptr
[4]);
1305 v6
= tswap32(vptr
[5]);
1306 ret
= get_errno((long)mmap((void *)v1
, v2
, v3
, v4
, v5
, v6
));
1311 case TARGET_NR_mmap2
:
1313 case TARGET_NR_mmap
:
1315 ret
= get_errno((long)mmap((void *)arg1
, arg2
, arg3
, arg4
, arg5
, arg6
));
1317 case TARGET_NR_munmap
:
1318 ret
= get_errno(munmap((void *)arg1
, arg2
));
1320 case TARGET_NR_truncate
:
1321 ret
= get_errno(truncate((const char *)arg1
, arg2
));
1323 case TARGET_NR_ftruncate
:
1324 ret
= get_errno(ftruncate(arg1
, arg2
));
1326 case TARGET_NR_fchmod
:
1327 ret
= get_errno(fchmod(arg1
, arg2
));
1329 case TARGET_NR_fchown
:
1330 ret
= get_errno(fchown(arg1
, arg2
, arg3
));
1332 case TARGET_NR_getpriority
:
1333 ret
= get_errno(getpriority(arg1
, arg2
));
1335 case TARGET_NR_setpriority
:
1336 ret
= get_errno(setpriority(arg1
, arg2
, arg3
));
1338 case TARGET_NR_profil
:
1340 case TARGET_NR_statfs
:
1341 stfs
= (void *)arg2
;
1342 ret
= get_errno(sys_statfs((const char *)arg1
, stfs
));
1344 if (!is_error(ret
)) {
1345 tswap32s(&stfs
->f_type
);
1346 tswap32s(&stfs
->f_bsize
);
1347 tswap32s(&stfs
->f_blocks
);
1348 tswap32s(&stfs
->f_bfree
);
1349 tswap32s(&stfs
->f_bavail
);
1350 tswap32s(&stfs
->f_files
);
1351 tswap32s(&stfs
->f_ffree
);
1352 tswap32s(&stfs
->f_fsid
.val
[0]);
1353 tswap32s(&stfs
->f_fsid
.val
[1]);
1354 tswap32s(&stfs
->f_namelen
);
1357 case TARGET_NR_fstatfs
:
1358 stfs
= (void *)arg2
;
1359 ret
= get_errno(sys_fstatfs(arg1
, stfs
));
1360 goto convert_statfs
;
1361 case TARGET_NR_ioperm
:
1363 case TARGET_NR_socketcall
:
1364 ret
= do_socketcall(arg1
, (long *)arg2
);
1366 case TARGET_NR_syslog
:
1368 case TARGET_NR_setitimer
:
1370 struct target_itimerval
*target_value
= (void *)arg2
;
1371 struct target_itimerval
*target_ovalue
= (void *)arg3
;
1372 struct itimerval value
, ovalue
, *pvalue
;
1376 target_to_host_timeval(&pvalue
->it_interval
,
1377 &target_value
->it_interval
);
1378 target_to_host_timeval(&pvalue
->it_value
,
1379 &target_value
->it_value
);
1383 ret
= get_errno(setitimer(arg1
, pvalue
, &ovalue
));
1384 if (!is_error(ret
) && target_ovalue
) {
1385 host_to_target_timeval(&target_ovalue
->it_interval
,
1386 &ovalue
.it_interval
);
1387 host_to_target_timeval(&target_ovalue
->it_value
,
1392 case TARGET_NR_getitimer
:
1394 struct target_itimerval
*target_value
= (void *)arg2
;
1395 struct itimerval value
;
1397 ret
= get_errno(getitimer(arg1
, &value
));
1398 if (!is_error(ret
) && target_value
) {
1399 host_to_target_timeval(&target_value
->it_interval
,
1400 &value
.it_interval
);
1401 host_to_target_timeval(&target_value
->it_value
,
1406 case TARGET_NR_stat
:
1407 ret
= get_errno(stat((const char *)arg1
, &st
));
1409 case TARGET_NR_lstat
:
1410 ret
= get_errno(lstat((const char *)arg1
, &st
));
1412 case TARGET_NR_fstat
:
1414 ret
= get_errno(fstat(arg1
, &st
));
1416 if (!is_error(ret
)) {
1417 struct target_stat
*target_st
= (void *)arg2
;
1418 target_st
->st_dev
= tswap16(st
.st_dev
);
1419 target_st
->st_ino
= tswapl(st
.st_ino
);
1420 target_st
->st_mode
= tswap16(st
.st_mode
);
1421 target_st
->st_nlink
= tswap16(st
.st_nlink
);
1422 target_st
->st_uid
= tswap16(st
.st_uid
);
1423 target_st
->st_gid
= tswap16(st
.st_gid
);
1424 target_st
->st_rdev
= tswap16(st
.st_rdev
);
1425 target_st
->st_size
= tswapl(st
.st_size
);
1426 target_st
->st_blksize
= tswapl(st
.st_blksize
);
1427 target_st
->st_blocks
= tswapl(st
.st_blocks
);
1428 target_st
->st_atime
= tswapl(st
.st_atime
);
1429 target_st
->st_mtime
= tswapl(st
.st_mtime
);
1430 target_st
->st_ctime
= tswapl(st
.st_ctime
);
1434 case TARGET_NR_olduname
:
1436 case TARGET_NR_iopl
:
1438 case TARGET_NR_vhangup
:
1439 ret
= get_errno(vhangup());
1441 case TARGET_NR_idle
:
1443 case TARGET_NR_vm86old
:
1445 case TARGET_NR_wait4
:
1448 target_long
*status_ptr
= (void *)arg2
;
1449 struct rusage rusage
, *rusage_ptr
;
1450 struct target_rusage
*target_rusage
= (void *)arg4
;
1452 rusage_ptr
= &rusage
;
1455 ret
= get_errno(wait4(arg1
, &status
, arg3
, rusage_ptr
));
1456 if (!is_error(ret
)) {
1458 *status_ptr
= tswap32(status
);
1459 if (target_rusage
) {
1460 target_rusage
->ru_utime
.tv_sec
= tswapl(rusage
.ru_utime
.tv_sec
);
1461 target_rusage
->ru_utime
.tv_usec
= tswapl(rusage
.ru_utime
.tv_usec
);
1462 target_rusage
->ru_stime
.tv_sec
= tswapl(rusage
.ru_stime
.tv_sec
);
1463 target_rusage
->ru_stime
.tv_usec
= tswapl(rusage
.ru_stime
.tv_usec
);
1464 target_rusage
->ru_maxrss
= tswapl(rusage
.ru_maxrss
);
1465 target_rusage
->ru_ixrss
= tswapl(rusage
.ru_ixrss
);
1466 target_rusage
->ru_idrss
= tswapl(rusage
.ru_idrss
);
1467 target_rusage
->ru_isrss
= tswapl(rusage
.ru_isrss
);
1468 target_rusage
->ru_minflt
= tswapl(rusage
.ru_minflt
);
1469 target_rusage
->ru_majflt
= tswapl(rusage
.ru_majflt
);
1470 target_rusage
->ru_nswap
= tswapl(rusage
.ru_nswap
);
1471 target_rusage
->ru_inblock
= tswapl(rusage
.ru_inblock
);
1472 target_rusage
->ru_oublock
= tswapl(rusage
.ru_oublock
);
1473 target_rusage
->ru_msgsnd
= tswapl(rusage
.ru_msgsnd
);
1474 target_rusage
->ru_msgrcv
= tswapl(rusage
.ru_msgrcv
);
1475 target_rusage
->ru_nsignals
= tswapl(rusage
.ru_nsignals
);
1476 target_rusage
->ru_nvcsw
= tswapl(rusage
.ru_nvcsw
);
1477 target_rusage
->ru_nivcsw
= tswapl(rusage
.ru_nivcsw
);
1482 case TARGET_NR_swapoff
:
1483 ret
= get_errno(swapoff((const char *)arg1
));
1485 case TARGET_NR_sysinfo
:
1489 case TARGET_NR_fsync
:
1490 ret
= get_errno(fsync(arg1
));
1492 case TARGET_NR_clone
:
1493 ret
= get_errno(do_fork(cpu_env
, arg1
, arg2
));
1495 case TARGET_NR_setdomainname
:
1496 ret
= get_errno(setdomainname((const char *)arg1
, arg2
));
1498 case TARGET_NR_uname
:
1499 /* no need to transcode because we use the linux syscall */
1500 ret
= get_errno(sys_uname((struct new_utsname
*)arg1
));
1503 case TARGET_NR_modify_ldt
:
1504 ret
= get_errno(gemu_modify_ldt(cpu_env
, arg1
, (void *)arg2
, arg3
));
1507 case TARGET_NR_adjtimex
:
1509 case TARGET_NR_mprotect
:
1510 ret
= get_errno(mprotect((void *)arg1
, arg2
, arg3
));
1512 case TARGET_NR_create_module
:
1513 case TARGET_NR_init_module
:
1514 case TARGET_NR_delete_module
:
1515 case TARGET_NR_get_kernel_syms
:
1517 case TARGET_NR_quotactl
:
1519 case TARGET_NR_getpgid
:
1520 ret
= get_errno(getpgid(arg1
));
1522 case TARGET_NR_fchdir
:
1523 ret
= get_errno(fchdir(arg1
));
1525 case TARGET_NR_bdflush
:
1527 case TARGET_NR_sysfs
:
1529 case TARGET_NR_personality
:
1530 ret
= get_errno(personality(arg1
));
1532 case TARGET_NR_afs_syscall
:
1534 case TARGET_NR_setfsuid
:
1536 case TARGET_NR_setfsgid
:
1538 case TARGET_NR__llseek
:
1541 ret
= get_errno(_llseek(arg1
, arg2
, arg3
, &res
, arg5
));
1542 *(int64_t *)arg4
= tswap64(res
);
1545 case TARGET_NR_getdents
:
1546 #if TARGET_LONG_SIZE != 4
1547 #error not supported
1550 struct dirent
*dirp
= (void *)arg2
;
1553 ret
= get_errno(sys_getdents(arg1
, dirp
, count
));
1554 if (!is_error(ret
)) {
1560 reclen
= tswap16(de
->d_reclen
);
1563 de
->d_reclen
= reclen
;
1564 tswapls(&de
->d_ino
);
1565 tswapls(&de
->d_off
);
1566 de
= (struct dirent
*)((char *)de
+ reclen
);
1572 case TARGET_NR_getdents64
:
1574 struct dirent64
*dirp
= (void *)arg2
;
1576 ret
= get_errno(sys_getdents64(arg1
, dirp
, count
));
1577 if (!is_error(ret
)) {
1578 struct dirent64
*de
;
1583 reclen
= tswap16(de
->d_reclen
);
1586 de
->d_reclen
= reclen
;
1587 tswap64s(&de
->d_ino
);
1588 tswap64s(&de
->d_off
);
1589 de
= (struct dirent64
*)((char *)de
+ reclen
);
1595 case TARGET_NR__newselect
:
1596 ret
= do_select(arg1
, (void *)arg2
, (void *)arg3
, (void *)arg4
,
1599 case TARGET_NR_flock
:
1601 case TARGET_NR_msync
:
1602 ret
= get_errno(msync((void *)arg1
, arg2
, arg3
));
1604 case TARGET_NR_readv
:
1609 struct target_iovec
*target_vec
= (void *)arg2
;
1611 vec
= alloca(count
* sizeof(struct iovec
));
1612 for(i
= 0;i
< count
; i
++) {
1613 vec
[i
].iov_base
= (void *)tswapl(target_vec
[i
].iov_base
);
1614 vec
[i
].iov_len
= tswapl(target_vec
[i
].iov_len
);
1616 ret
= get_errno(readv(arg1
, vec
, count
));
1619 case TARGET_NR_writev
:
1624 struct target_iovec
*target_vec
= (void *)arg2
;
1626 vec
= alloca(count
* sizeof(struct iovec
));
1627 for(i
= 0;i
< count
; i
++) {
1628 vec
[i
].iov_base
= (void *)tswapl(target_vec
[i
].iov_base
);
1629 vec
[i
].iov_len
= tswapl(target_vec
[i
].iov_len
);
1631 ret
= get_errno(writev(arg1
, vec
, count
));
1634 case TARGET_NR_getsid
:
1635 ret
= get_errno(getsid(arg1
));
1637 case TARGET_NR_fdatasync
:
1639 case TARGET_NR__sysctl
:
1641 case TARGET_NR_mlock
:
1642 ret
= get_errno(mlock((void *)arg1
, arg2
));
1644 case TARGET_NR_munlock
:
1645 ret
= get_errno(munlock((void *)arg1
, arg2
));
1647 case TARGET_NR_mlockall
:
1648 ret
= get_errno(mlockall(arg1
));
1650 case TARGET_NR_munlockall
:
1651 ret
= get_errno(munlockall());
1653 case TARGET_NR_sched_setparam
:
1655 case TARGET_NR_sched_getparam
:
1657 case TARGET_NR_sched_setscheduler
:
1659 case TARGET_NR_sched_getscheduler
:
1661 case TARGET_NR_sched_yield
:
1662 ret
= get_errno(sched_yield());
1664 case TARGET_NR_sched_get_priority_max
:
1665 case TARGET_NR_sched_get_priority_min
:
1666 case TARGET_NR_sched_rr_get_interval
:
1669 case TARGET_NR_nanosleep
:
1671 struct target_timespec
*target_req
= (void *)arg1
;
1672 struct target_timespec
*target_rem
= (void *)arg2
;
1673 struct timespec req
, rem
;
1674 req
.tv_sec
= tswapl(target_req
->tv_sec
);
1675 req
.tv_nsec
= tswapl(target_req
->tv_nsec
);
1676 ret
= get_errno(nanosleep(&req
, &rem
));
1678 target_rem
->tv_sec
= tswapl(rem
.tv_sec
);
1679 target_rem
->tv_nsec
= tswapl(rem
.tv_nsec
);
1684 case TARGET_NR_mremap
:
1685 case TARGET_NR_setresuid
:
1686 case TARGET_NR_getresuid
:
1687 case TARGET_NR_vm86
:
1688 case TARGET_NR_query_module
:
1689 case TARGET_NR_poll
:
1690 case TARGET_NR_nfsservctl
:
1691 case TARGET_NR_setresgid
:
1692 case TARGET_NR_getresgid
:
1693 case TARGET_NR_prctl
:
1694 case TARGET_NR_pread
:
1695 case TARGET_NR_pwrite
:
1697 case TARGET_NR_chown
:
1698 ret
= get_errno(chown((const char *)arg1
, arg2
, arg3
));
1700 case TARGET_NR_getcwd
:
1701 ret
= get_errno(sys_getcwd1((char *)arg1
, arg2
));
1703 case TARGET_NR_capget
:
1704 case TARGET_NR_capset
:
1705 case TARGET_NR_sigaltstack
:
1706 case TARGET_NR_sendfile
:
1707 case TARGET_NR_getpmsg
:
1708 case TARGET_NR_putpmsg
:
1709 case TARGET_NR_vfork
:
1710 ret
= get_errno(do_fork(cpu_env
, CLONE_VFORK
| CLONE_VM
| SIGCHLD
, 0));
1712 case TARGET_NR_ugetrlimit
:
1713 case TARGET_NR_truncate64
:
1714 case TARGET_NR_ftruncate64
:
1716 case TARGET_NR_stat64
:
1717 ret
= get_errno(stat((const char *)arg1
, &st
));
1719 case TARGET_NR_lstat64
:
1720 ret
= get_errno(lstat((const char *)arg1
, &st
));
1722 case TARGET_NR_fstat64
:
1724 ret
= get_errno(fstat(arg1
, &st
));
1726 if (!is_error(ret
)) {
1727 struct target_stat64
*target_st
= (void *)arg2
;
1728 target_st
->st_dev
= tswap16(st
.st_dev
);
1729 target_st
->st_ino
= tswapl(st
.st_ino
);
1730 target_st
->st_mode
= tswap16(st
.st_mode
);
1731 target_st
->st_nlink
= tswap16(st
.st_nlink
);
1732 target_st
->st_uid
= tswap16(st
.st_uid
);
1733 target_st
->st_gid
= tswap16(st
.st_gid
);
1734 target_st
->st_rdev
= tswap16(st
.st_rdev
);
1735 /* XXX: better use of kernel struct */
1736 target_st
->st_size
= tswapl(st
.st_size
);
1737 target_st
->st_blksize
= tswapl(st
.st_blksize
);
1738 target_st
->st_blocks
= tswapl(st
.st_blocks
);
1739 target_st
->st_atime
= tswapl(st
.st_atime
);
1740 target_st
->st_mtime
= tswapl(st
.st_mtime
);
1741 target_st
->st_ctime
= tswapl(st
.st_ctime
);
1746 case TARGET_NR_lchown32
:
1747 case TARGET_NR_getuid32
:
1748 case TARGET_NR_getgid32
:
1749 case TARGET_NR_geteuid32
:
1750 case TARGET_NR_getegid32
:
1751 case TARGET_NR_setreuid32
:
1752 case TARGET_NR_setregid32
:
1753 case TARGET_NR_getgroups32
:
1754 case TARGET_NR_setgroups32
:
1755 case TARGET_NR_fchown32
:
1756 case TARGET_NR_setresuid32
:
1757 case TARGET_NR_getresuid32
:
1758 case TARGET_NR_setresgid32
:
1759 case TARGET_NR_getresgid32
:
1760 case TARGET_NR_chown32
:
1761 case TARGET_NR_setuid32
:
1762 case TARGET_NR_setgid32
:
1763 case TARGET_NR_setfsuid32
:
1764 case TARGET_NR_setfsgid32
:
1765 case TARGET_NR_pivot_root
:
1766 case TARGET_NR_mincore
:
1767 case TARGET_NR_madvise
:
1769 #if TARGET_LONG_BITS == 32
1770 case TARGET_NR_fcntl64
:
1777 ret
= get_errno(fcntl(arg1
, arg2
, arg3
));
1782 case TARGET_NR_security
:
1784 case TARGET_NR_gettid
:
1785 ret
= get_errno(gettid());
1787 case TARGET_NR_readahead
:
1788 case TARGET_NR_setxattr
:
1789 case TARGET_NR_lsetxattr
:
1790 case TARGET_NR_fsetxattr
:
1791 case TARGET_NR_getxattr
:
1792 case TARGET_NR_lgetxattr
:
1793 case TARGET_NR_fgetxattr
:
1794 case TARGET_NR_listxattr
:
1795 case TARGET_NR_llistxattr
:
1796 case TARGET_NR_flistxattr
:
1797 case TARGET_NR_removexattr
:
1798 case TARGET_NR_lremovexattr
:
1799 case TARGET_NR_fremovexattr
:
1803 gemu_log("Unsupported syscall: %d\n", num
);