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.
28 #include <sys/types.h>
32 #include <sys/mount.h>
33 #include <sys/resource.h>
38 #include <sys/socket.h>
40 //#include <sys/user.h>
42 #define termios host_termios
43 #define winsize host_winsize
44 #define termio host_termio
46 #include <linux/termios.h>
47 #include <linux/unistd.h>
48 #include <linux/utsname.h>
49 #include <linux/cdrom.h>
50 #include <linux/hdreg.h>
51 #include <linux/soundcard.h>
58 #define PAGE_SIZE 4096
59 #define PAGE_MASK ~(PAGE_SIZE - 1)
65 unsigned short d_reclen
;
66 char d_name
[256]; /* We must not include limits.h! */
69 //#include <linux/msdos_fs.h>
70 #define VFAT_IOCTL_READDIR_BOTH _IOR('r', 1, struct dirent [2])
71 #define VFAT_IOCTL_READDIR_SHORT _IOR('r', 2, struct dirent [2])
73 #include "syscall_defs.h"
77 #include "syscall-i386.h"
80 #define __NR_sys_uname __NR_uname
81 #define __NR_sys_getcwd1 __NR_getcwd
82 #define __NR_sys_statfs __NR_statfs
83 #define __NR_sys_fstatfs __NR_fstatfs
84 #define __NR_sys_getdents __NR_getdents
87 _syscall0(int, gettid
)
89 static int gettid(void) {
93 _syscall1(int,sys_uname
,struct new_utsname
*,buf
)
94 _syscall2(int,sys_getcwd1
,char *,buf
,size_t,size
)
95 _syscall3(int, sys_getdents
, uint
, fd
, struct dirent
*, dirp
, uint
, count
);
96 _syscall5(int, _llseek
, uint
, fd
, ulong
, hi
, ulong
, lo
,
97 loff_t
*, res
, uint
, wh
);
98 _syscall2(int,sys_statfs
,const char *,path
,struct kernel_statfs
*,buf
)
99 _syscall2(int,sys_fstatfs
,int,fd
,struct kernel_statfs
*,buf
)
101 static inline long get_errno(long ret
)
109 static inline int is_error(long ret
)
111 return (unsigned long)ret
>= (unsigned long)(-4096);
114 static char *target_brk
;
115 static char *target_original_brk
;
117 void target_set_brk(char *new_brk
)
119 target_brk
= new_brk
;
120 target_original_brk
= new_brk
;
123 static long do_brk(char *new_brk
)
130 return (long)target_brk
;
131 if (new_brk
< target_original_brk
)
134 brk_page
= (char *)(((unsigned long)target_brk
+ PAGE_SIZE
- 1) & PAGE_MASK
);
136 /* If the new brk is less than this, set it and we're done... */
137 if (new_brk
< brk_page
) {
138 target_brk
= new_brk
;
139 return (long)target_brk
;
142 /* We need to allocate more memory after the brk... */
143 new_alloc_size
= ((new_brk
- brk_page
+ 1)+(PAGE_SIZE
-1)) & PAGE_MASK
;
144 mapped_addr
= get_errno((long)mmap((caddr_t
)brk_page
, new_alloc_size
,
145 PROT_READ
|PROT_WRITE
,
146 MAP_ANON
|MAP_FIXED
|MAP_PRIVATE
, 0, 0));
148 if (is_error(mapped_addr
)) {
151 target_brk
= new_brk
;
152 return (long)target_brk
;
156 static inline fd_set
*target_to_host_fds(fd_set
*fds
,
157 target_long
*target_fds
, int n
)
159 #if !defined(BSWP_NEEDED) && !defined(WORD_BIGENDIAN)
160 return (fd_set
*)target_fds
;
165 for(i
= 0;i
< n
; i
++) {
166 b
= (tswapl(target_fds
[i
/ TARGET_LONG_BITS
]) >>
167 (i
& (TARGET_LONG_BITS
- 1))) & 1;
178 static inline void host_to_target_fds(target_long
*target_fds
,
181 #if !defined(BSWP_NEEDED) && !defined(WORD_BIGENDIAN)
188 nw
= n
/ TARGET_LONG_BITS
;
190 for(i
= 0;i
< nw
; i
++) {
192 for(j
= 0; j
< TARGET_LONG_BITS
; j
++) {
193 v
|= ((FD_ISSET(k
, fds
) != 0) << j
);
196 target_fds
[i
] = tswapl(v
);
202 /* XXX: incorrect for some archs */
203 static void host_to_target_old_sigset(target_ulong
*old_sigset
,
204 const sigset_t
*sigset
)
206 *old_sigset
= tswap32(*(unsigned long *)sigset
& 0xffffffff);
209 static void target_to_host_old_sigset(sigset_t
*sigset
,
210 const target_ulong
*old_sigset
)
213 *(unsigned long *)sigset
= tswapl(*old_sigset
);
217 static long do_select(long n
,
218 target_long
*target_rfds
, target_long
*target_wfds
,
219 target_long
*target_efds
, struct target_timeval
*target_tv
)
221 fd_set rfds
, wfds
, efds
;
222 fd_set
*rfds_ptr
, *wfds_ptr
, *efds_ptr
;
223 struct timeval tv
, *tv_ptr
;
226 rfds_ptr
= target_to_host_fds(&rfds
, target_rfds
, n
);
227 wfds_ptr
= target_to_host_fds(&wfds
, target_wfds
, n
);
228 efds_ptr
= target_to_host_fds(&efds
, target_efds
, n
);
231 tv
.tv_sec
= tswapl(target_tv
->tv_sec
);
232 tv
.tv_usec
= tswapl(target_tv
->tv_usec
);
237 ret
= get_errno(select(n
, rfds_ptr
, wfds_ptr
, efds_ptr
, tv_ptr
));
238 if (!is_error(ret
)) {
239 host_to_target_fds(target_rfds
, rfds_ptr
, n
);
240 host_to_target_fds(target_wfds
, wfds_ptr
, n
);
241 host_to_target_fds(target_efds
, efds_ptr
, n
);
244 target_tv
->tv_sec
= tswapl(tv
.tv_sec
);
245 target_tv
->tv_usec
= tswapl(tv
.tv_usec
);
251 static long do_socketcall(int num
, long *vptr
)
257 ret
= get_errno(socket(vptr
[0], vptr
[1], vptr
[2]));
260 ret
= get_errno(bind(vptr
[0], (struct sockaddr
*)vptr
[1], vptr
[2]));
263 ret
= get_errno(connect(vptr
[0], (struct sockaddr
*)vptr
[1], vptr
[2]));
266 ret
= get_errno(listen(vptr
[0], vptr
[1]));
271 size
= tswap32(*(int32_t *)vptr
[2]);
272 ret
= get_errno(accept(vptr
[0], (struct sockaddr
*)vptr
[1], &size
));
274 *(int32_t *)vptr
[2] = size
;
277 case SOCKOP_getsockname
:
280 size
= tswap32(*(int32_t *)vptr
[2]);
281 ret
= get_errno(getsockname(vptr
[0], (struct sockaddr
*)vptr
[1], &size
));
283 *(int32_t *)vptr
[2] = size
;
286 case SOCKOP_getpeername
:
289 size
= tswap32(*(int32_t *)vptr
[2]);
290 ret
= get_errno(getpeername(vptr
[0], (struct sockaddr
*)vptr
[1], &size
));
292 *(int32_t *)vptr
[2] = size
;
295 case SOCKOP_socketpair
:
298 int32_t *target_tab
= (int32_t *)vptr
[3];
299 ret
= get_errno(socketpair(vptr
[0], vptr
[1], vptr
[2], tab
));
300 if (!is_error(ret
)) {
301 target_tab
[0] = tswap32(tab
[0]);
302 target_tab
[1] = tswap32(tab
[1]);
307 ret
= get_errno(send(vptr
[0], (void *)vptr
[1], vptr
[2], vptr
[3]));
310 ret
= get_errno(recv(vptr
[0], (void *)vptr
[1], vptr
[2], vptr
[3]));
313 ret
= get_errno(sendto(vptr
[0], (void *)vptr
[1], vptr
[2], vptr
[3],
314 (struct sockaddr
*)vptr
[4], vptr
[5]));
316 case SOCKOP_recvfrom
:
319 size
= tswap32(*(int32_t *)vptr
[5]);
320 ret
= get_errno(recvfrom(vptr
[0], (void *)vptr
[1], vptr
[2],
321 vptr
[3], (struct sockaddr
*)vptr
[4], &size
));
323 *(int32_t *)vptr
[5] = size
;
326 case SOCKOP_shutdown
:
327 ret
= get_errno(shutdown(vptr
[0], vptr
[1]));
333 struct target_msghdr
*msgp
;
337 struct target_iovec
*target_vec
;
339 msgp
= (void *)vptr
[1];
340 msg
.msg_name
= (void *)tswapl(msgp
->msg_name
);
341 msg
.msg_namelen
= tswapl(msgp
->msg_namelen
);
342 msg
.msg_control
= (void *)tswapl(msgp
->msg_control
);
343 msg
.msg_controllen
= tswapl(msgp
->msg_controllen
);
344 msg
.msg_flags
= tswap32(msgp
->msg_flags
);
346 count
= tswapl(msgp
->msg_iovlen
);
347 vec
= alloca(count
* sizeof(struct iovec
));
348 target_vec
= (void *)tswapl(msgp
->msg_iov
);
349 for(i
= 0;i
< count
; i
++) {
350 vec
[i
].iov_base
= (void *)tswapl(target_vec
[i
].iov_base
);
351 vec
[i
].iov_len
= tswapl(target_vec
[i
].iov_len
);
353 msg
.msg_iovlen
= count
;
358 if (num
== SOCKOP_sendmsg
)
359 ret
= sendmsg(fd
, &msg
, flags
);
361 ret
= recvmsg(fd
, &msg
, flags
);
362 ret
= get_errno(ret
);
365 case SOCKOP_setsockopt
:
366 case SOCKOP_getsockopt
:
368 gemu_log("Unsupported socketcall: %d\n", num
);
375 /* kernel structure types definitions */
378 #define STRUCT(name, list...) STRUCT_ ## name,
379 #define STRUCT_SPECIAL(name) STRUCT_ ## name,
381 #include "syscall_types.h"
384 #undef STRUCT_SPECIAL
386 #define STRUCT(name, list...) const argtype struct_ ## name ## _def[] = { list, TYPE_NULL };
387 #define STRUCT_SPECIAL(name)
388 #include "syscall_types.h"
390 #undef STRUCT_SPECIAL
392 typedef struct IOCTLEntry
{
397 const argtype arg_type
[5];
402 #define IOC_RW (IOC_R | IOC_W)
404 #define MAX_STRUCT_SIZE 4096
406 const IOCTLEntry ioctl_entries
[] = {
407 #define IOCTL(cmd, access, types...) \
408 { TARGET_ ## cmd, cmd, #cmd, access, { types } },
413 static long do_ioctl(long fd
, long cmd
, long arg
)
415 const IOCTLEntry
*ie
;
416 const argtype
*arg_type
;
418 uint8_t buf_temp
[MAX_STRUCT_SIZE
];
422 if (ie
->target_cmd
== 0) {
423 gemu_log("Unsupported ioctl: cmd=0x%04lx\n", cmd
);
426 if (ie
->target_cmd
== cmd
)
430 arg_type
= ie
->arg_type
;
432 gemu_log("ioctl: cmd=0x%04lx (%s)\n", cmd
, ie
->name
);
434 switch(arg_type
[0]) {
437 ret
= get_errno(ioctl(fd
, ie
->host_cmd
));
442 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, arg
));
448 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, buf_temp
));
449 if (!is_error(ret
)) {
450 thunk_convert((void *)arg
, buf_temp
, arg_type
, THUNK_TARGET
);
454 thunk_convert(buf_temp
, (void *)arg
, arg_type
, THUNK_HOST
);
455 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, buf_temp
));
459 thunk_convert(buf_temp
, (void *)arg
, arg_type
, THUNK_HOST
);
460 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, buf_temp
));
461 if (!is_error(ret
)) {
462 thunk_convert((void *)arg
, buf_temp
, arg_type
, THUNK_TARGET
);
468 gemu_log("Unsupported ioctl type: cmd=0x%04lx type=%d\n", cmd
, arg_type
[0]);
475 bitmask_transtbl iflag_tbl
[] = {
476 { TARGET_IGNBRK
, TARGET_IGNBRK
, IGNBRK
, IGNBRK
},
477 { TARGET_BRKINT
, TARGET_BRKINT
, BRKINT
, BRKINT
},
478 { TARGET_IGNPAR
, TARGET_IGNPAR
, IGNPAR
, IGNPAR
},
479 { TARGET_PARMRK
, TARGET_PARMRK
, PARMRK
, PARMRK
},
480 { TARGET_INPCK
, TARGET_INPCK
, INPCK
, INPCK
},
481 { TARGET_ISTRIP
, TARGET_ISTRIP
, ISTRIP
, ISTRIP
},
482 { TARGET_INLCR
, TARGET_INLCR
, INLCR
, INLCR
},
483 { TARGET_IGNCR
, TARGET_IGNCR
, IGNCR
, IGNCR
},
484 { TARGET_ICRNL
, TARGET_ICRNL
, ICRNL
, ICRNL
},
485 { TARGET_IUCLC
, TARGET_IUCLC
, IUCLC
, IUCLC
},
486 { TARGET_IXON
, TARGET_IXON
, IXON
, IXON
},
487 { TARGET_IXANY
, TARGET_IXANY
, IXANY
, IXANY
},
488 { TARGET_IXOFF
, TARGET_IXOFF
, IXOFF
, IXOFF
},
489 { TARGET_IMAXBEL
, TARGET_IMAXBEL
, IMAXBEL
, IMAXBEL
},
493 bitmask_transtbl oflag_tbl
[] = {
494 { TARGET_OPOST
, TARGET_OPOST
, OPOST
, OPOST
},
495 { TARGET_OLCUC
, TARGET_OLCUC
, OLCUC
, OLCUC
},
496 { TARGET_ONLCR
, TARGET_ONLCR
, ONLCR
, ONLCR
},
497 { TARGET_OCRNL
, TARGET_OCRNL
, OCRNL
, OCRNL
},
498 { TARGET_ONOCR
, TARGET_ONOCR
, ONOCR
, ONOCR
},
499 { TARGET_ONLRET
, TARGET_ONLRET
, ONLRET
, ONLRET
},
500 { TARGET_OFILL
, TARGET_OFILL
, OFILL
, OFILL
},
501 { TARGET_OFDEL
, TARGET_OFDEL
, OFDEL
, OFDEL
},
502 { TARGET_NLDLY
, TARGET_NL0
, NLDLY
, NL0
},
503 { TARGET_NLDLY
, TARGET_NL1
, NLDLY
, NL1
},
504 { TARGET_CRDLY
, TARGET_CR0
, CRDLY
, CR0
},
505 { TARGET_CRDLY
, TARGET_CR1
, CRDLY
, CR1
},
506 { TARGET_CRDLY
, TARGET_CR2
, CRDLY
, CR2
},
507 { TARGET_CRDLY
, TARGET_CR3
, CRDLY
, CR3
},
508 { TARGET_TABDLY
, TARGET_TAB0
, TABDLY
, TAB0
},
509 { TARGET_TABDLY
, TARGET_TAB1
, TABDLY
, TAB1
},
510 { TARGET_TABDLY
, TARGET_TAB2
, TABDLY
, TAB2
},
511 { TARGET_TABDLY
, TARGET_TAB3
, TABDLY
, TAB3
},
512 { TARGET_BSDLY
, TARGET_BS0
, BSDLY
, BS0
},
513 { TARGET_BSDLY
, TARGET_BS1
, BSDLY
, BS1
},
514 { TARGET_VTDLY
, TARGET_VT0
, VTDLY
, VT0
},
515 { TARGET_VTDLY
, TARGET_VT1
, VTDLY
, VT1
},
516 { TARGET_FFDLY
, TARGET_FF0
, FFDLY
, FF0
},
517 { TARGET_FFDLY
, TARGET_FF1
, FFDLY
, FF1
},
521 bitmask_transtbl cflag_tbl
[] = {
522 { TARGET_CBAUD
, TARGET_B0
, CBAUD
, B0
},
523 { TARGET_CBAUD
, TARGET_B50
, CBAUD
, B50
},
524 { TARGET_CBAUD
, TARGET_B75
, CBAUD
, B75
},
525 { TARGET_CBAUD
, TARGET_B110
, CBAUD
, B110
},
526 { TARGET_CBAUD
, TARGET_B134
, CBAUD
, B134
},
527 { TARGET_CBAUD
, TARGET_B150
, CBAUD
, B150
},
528 { TARGET_CBAUD
, TARGET_B200
, CBAUD
, B200
},
529 { TARGET_CBAUD
, TARGET_B300
, CBAUD
, B300
},
530 { TARGET_CBAUD
, TARGET_B600
, CBAUD
, B600
},
531 { TARGET_CBAUD
, TARGET_B1200
, CBAUD
, B1200
},
532 { TARGET_CBAUD
, TARGET_B1800
, CBAUD
, B1800
},
533 { TARGET_CBAUD
, TARGET_B2400
, CBAUD
, B2400
},
534 { TARGET_CBAUD
, TARGET_B4800
, CBAUD
, B4800
},
535 { TARGET_CBAUD
, TARGET_B9600
, CBAUD
, B9600
},
536 { TARGET_CBAUD
, TARGET_B19200
, CBAUD
, B19200
},
537 { TARGET_CBAUD
, TARGET_B38400
, CBAUD
, B38400
},
538 { TARGET_CBAUD
, TARGET_B57600
, CBAUD
, B57600
},
539 { TARGET_CBAUD
, TARGET_B115200
, CBAUD
, B115200
},
540 { TARGET_CBAUD
, TARGET_B230400
, CBAUD
, B230400
},
541 { TARGET_CBAUD
, TARGET_B460800
, CBAUD
, B460800
},
542 { TARGET_CSIZE
, TARGET_CS5
, CSIZE
, CS5
},
543 { TARGET_CSIZE
, TARGET_CS6
, CSIZE
, CS6
},
544 { TARGET_CSIZE
, TARGET_CS7
, CSIZE
, CS7
},
545 { TARGET_CSIZE
, TARGET_CS8
, CSIZE
, CS8
},
546 { TARGET_CSTOPB
, TARGET_CSTOPB
, CSTOPB
, CSTOPB
},
547 { TARGET_CREAD
, TARGET_CREAD
, CREAD
, CREAD
},
548 { TARGET_PARENB
, TARGET_PARENB
, PARENB
, PARENB
},
549 { TARGET_PARODD
, TARGET_PARODD
, PARODD
, PARODD
},
550 { TARGET_HUPCL
, TARGET_HUPCL
, HUPCL
, HUPCL
},
551 { TARGET_CLOCAL
, TARGET_CLOCAL
, CLOCAL
, CLOCAL
},
552 { TARGET_CRTSCTS
, TARGET_CRTSCTS
, CRTSCTS
, CRTSCTS
},
556 bitmask_transtbl lflag_tbl
[] = {
557 { TARGET_ISIG
, TARGET_ISIG
, ISIG
, ISIG
},
558 { TARGET_ICANON
, TARGET_ICANON
, ICANON
, ICANON
},
559 { TARGET_XCASE
, TARGET_XCASE
, XCASE
, XCASE
},
560 { TARGET_ECHO
, TARGET_ECHO
, ECHO
, ECHO
},
561 { TARGET_ECHOE
, TARGET_ECHOE
, ECHOE
, ECHOE
},
562 { TARGET_ECHOK
, TARGET_ECHOK
, ECHOK
, ECHOK
},
563 { TARGET_ECHONL
, TARGET_ECHONL
, ECHONL
, ECHONL
},
564 { TARGET_NOFLSH
, TARGET_NOFLSH
, NOFLSH
, NOFLSH
},
565 { TARGET_TOSTOP
, TARGET_TOSTOP
, TOSTOP
, TOSTOP
},
566 { TARGET_ECHOCTL
, TARGET_ECHOCTL
, ECHOCTL
, ECHOCTL
},
567 { TARGET_ECHOPRT
, TARGET_ECHOPRT
, ECHOPRT
, ECHOPRT
},
568 { TARGET_ECHOKE
, TARGET_ECHOKE
, ECHOKE
, ECHOKE
},
569 { TARGET_FLUSHO
, TARGET_FLUSHO
, FLUSHO
, FLUSHO
},
570 { TARGET_PENDIN
, TARGET_PENDIN
, PENDIN
, PENDIN
},
571 { TARGET_IEXTEN
, TARGET_IEXTEN
, IEXTEN
, IEXTEN
},
575 static void target_to_host_termios (void *dst
, const void *src
)
577 struct host_termios
*host
= dst
;
578 const struct target_termios
*target
= src
;
581 target_to_host_bitmask(tswap32(target
->c_iflag
), iflag_tbl
);
583 target_to_host_bitmask(tswap32(target
->c_oflag
), oflag_tbl
);
585 target_to_host_bitmask(tswap32(target
->c_cflag
), cflag_tbl
);
587 target_to_host_bitmask(tswap32(target
->c_lflag
), lflag_tbl
);
588 host
->c_line
= target
->c_line
;
590 host
->c_cc
[VINTR
] = target
->c_cc
[TARGET_VINTR
];
591 host
->c_cc
[VQUIT
] = target
->c_cc
[TARGET_VQUIT
];
592 host
->c_cc
[VERASE
] = target
->c_cc
[TARGET_VERASE
];
593 host
->c_cc
[VKILL
] = target
->c_cc
[TARGET_VKILL
];
594 host
->c_cc
[VEOF
] = target
->c_cc
[TARGET_VEOF
];
595 host
->c_cc
[VTIME
] = target
->c_cc
[TARGET_VTIME
];
596 host
->c_cc
[VMIN
] = target
->c_cc
[TARGET_VMIN
];
597 host
->c_cc
[VSWTC
] = target
->c_cc
[TARGET_VSWTC
];
598 host
->c_cc
[VSTART
] = target
->c_cc
[TARGET_VSTART
];
599 host
->c_cc
[VSTOP
] = target
->c_cc
[TARGET_VSTOP
];
600 host
->c_cc
[VSUSP
] = target
->c_cc
[TARGET_VSUSP
];
601 host
->c_cc
[VEOL
] = target
->c_cc
[TARGET_VEOL
];
602 host
->c_cc
[VREPRINT
] = target
->c_cc
[TARGET_VREPRINT
];
603 host
->c_cc
[VDISCARD
] = target
->c_cc
[TARGET_VDISCARD
];
604 host
->c_cc
[VWERASE
] = target
->c_cc
[TARGET_VWERASE
];
605 host
->c_cc
[VLNEXT
] = target
->c_cc
[TARGET_VLNEXT
];
606 host
->c_cc
[VEOL2
] = target
->c_cc
[TARGET_VEOL2
];
609 static void host_to_target_termios (void *dst
, const void *src
)
611 struct target_termios
*target
= dst
;
612 const struct host_termios
*host
= src
;
615 tswap32(host_to_target_bitmask(host
->c_iflag
, iflag_tbl
));
617 tswap32(host_to_target_bitmask(host
->c_oflag
, oflag_tbl
));
619 tswap32(host_to_target_bitmask(host
->c_cflag
, cflag_tbl
));
621 tswap32(host_to_target_bitmask(host
->c_lflag
, lflag_tbl
));
622 target
->c_line
= host
->c_line
;
624 target
->c_cc
[TARGET_VINTR
] = host
->c_cc
[VINTR
];
625 target
->c_cc
[TARGET_VQUIT
] = host
->c_cc
[VQUIT
];
626 target
->c_cc
[TARGET_VERASE
] = host
->c_cc
[VERASE
];
627 target
->c_cc
[TARGET_VKILL
] = host
->c_cc
[VKILL
];
628 target
->c_cc
[TARGET_VEOF
] = host
->c_cc
[VEOF
];
629 target
->c_cc
[TARGET_VTIME
] = host
->c_cc
[VTIME
];
630 target
->c_cc
[TARGET_VMIN
] = host
->c_cc
[VMIN
];
631 target
->c_cc
[TARGET_VSWTC
] = host
->c_cc
[VSWTC
];
632 target
->c_cc
[TARGET_VSTART
] = host
->c_cc
[VSTART
];
633 target
->c_cc
[TARGET_VSTOP
] = host
->c_cc
[VSTOP
];
634 target
->c_cc
[TARGET_VSUSP
] = host
->c_cc
[VSUSP
];
635 target
->c_cc
[TARGET_VEOL
] = host
->c_cc
[VEOL
];
636 target
->c_cc
[TARGET_VREPRINT
] = host
->c_cc
[VREPRINT
];
637 target
->c_cc
[TARGET_VDISCARD
] = host
->c_cc
[VDISCARD
];
638 target
->c_cc
[TARGET_VWERASE
] = host
->c_cc
[VWERASE
];
639 target
->c_cc
[TARGET_VLNEXT
] = host
->c_cc
[VLNEXT
];
640 target
->c_cc
[TARGET_VEOL2
] = host
->c_cc
[VEOL2
];
643 StructEntry struct_termios_def
= {
644 .convert
= { host_to_target_termios
, target_to_host_termios
},
645 .size
= { sizeof(struct target_termios
), sizeof(struct host_termios
) },
646 .align
= { __alignof__(struct target_termios
), __alignof__(struct host_termios
) },
651 /* NOTE: there is really one LDT for all the threads */
654 static int read_ldt(void *ptr
, unsigned long bytecount
)
660 size
= TARGET_LDT_ENTRIES
* TARGET_LDT_ENTRY_SIZE
;
661 if (size
> bytecount
)
663 memcpy(ptr
, ldt_table
, size
);
667 /* XXX: add locking support */
668 static int write_ldt(CPUX86State
*env
,
669 void *ptr
, unsigned long bytecount
, int oldmode
)
671 struct target_modify_ldt_ldt_s ldt_info
;
672 int seg_32bit
, contents
, read_exec_only
, limit_in_pages
;
673 int seg_not_present
, useable
;
674 uint32_t *lp
, entry_1
, entry_2
;
676 if (bytecount
!= sizeof(ldt_info
))
678 memcpy(&ldt_info
, ptr
, sizeof(ldt_info
));
679 tswap32s(&ldt_info
.entry_number
);
680 tswapls((long *)&ldt_info
.base_addr
);
681 tswap32s(&ldt_info
.limit
);
682 tswap32s(&ldt_info
.flags
);
684 if (ldt_info
.entry_number
>= TARGET_LDT_ENTRIES
)
686 seg_32bit
= ldt_info
.flags
& 1;
687 contents
= (ldt_info
.flags
>> 1) & 3;
688 read_exec_only
= (ldt_info
.flags
>> 3) & 1;
689 limit_in_pages
= (ldt_info
.flags
>> 4) & 1;
690 seg_not_present
= (ldt_info
.flags
>> 5) & 1;
691 useable
= (ldt_info
.flags
>> 6) & 1;
696 if (seg_not_present
== 0)
699 /* allocate the LDT */
701 ldt_table
= malloc(TARGET_LDT_ENTRIES
* TARGET_LDT_ENTRY_SIZE
);
704 memset(ldt_table
, 0, TARGET_LDT_ENTRIES
* TARGET_LDT_ENTRY_SIZE
);
705 env
->ldt
.base
= ldt_table
;
706 env
->ldt
.limit
= 0xffff;
709 /* NOTE: same code as Linux kernel */
710 /* Allow LDTs to be cleared by the user. */
711 if (ldt_info
.base_addr
== 0 && ldt_info
.limit
== 0) {
714 read_exec_only
== 1 &&
716 limit_in_pages
== 0 &&
717 seg_not_present
== 1 &&
725 entry_1
= ((ldt_info
.base_addr
& 0x0000ffff) << 16) |
726 (ldt_info
.limit
& 0x0ffff);
727 entry_2
= (ldt_info
.base_addr
& 0xff000000) |
728 ((ldt_info
.base_addr
& 0x00ff0000) >> 16) |
729 (ldt_info
.limit
& 0xf0000) |
730 ((read_exec_only
^ 1) << 9) |
732 ((seg_not_present
^ 1) << 15) |
734 (limit_in_pages
<< 23) |
737 entry_2
|= (useable
<< 20);
739 /* Install the new entry ... */
741 lp
= (uint32_t *)(ldt_table
+ (ldt_info
.entry_number
<< 3));
742 lp
[0] = tswap32(entry_1
);
743 lp
[1] = tswap32(entry_2
);
747 /* specific and weird i386 syscalls */
748 int gemu_modify_ldt(CPUX86State
*env
, int func
, void *ptr
, unsigned long bytecount
)
754 ret
= read_ldt(ptr
, bytecount
);
757 ret
= write_ldt(env
, ptr
, bytecount
, 1);
760 ret
= write_ldt(env
, ptr
, bytecount
, 0);
767 void syscall_init(void)
769 #define STRUCT(name, list...) thunk_register_struct(STRUCT_ ## name, #name, struct_ ## name ## _def);
770 #define STRUCT_SPECIAL(name) thunk_register_struct_direct(STRUCT_ ## name, #name, &struct_ ## name ## _def);
771 #include "syscall_types.h"
773 #undef STRUCT_SPECIAL
776 long do_syscall(void *cpu_env
, int num
, long arg1
, long arg2
, long arg3
,
777 long arg4
, long arg5
, long arg6
)
781 struct kernel_statfs
*stfs
;
784 gemu_log("syscall %d\n", num
);
792 ret
= 0; /* avoid warning */
795 ret
= get_errno(read(arg1
, (void *)arg2
, arg3
));
797 case TARGET_NR_write
:
798 ret
= get_errno(write(arg1
, (void *)arg2
, arg3
));
801 ret
= get_errno(open((const char *)arg1
, arg2
, arg3
));
803 case TARGET_NR_close
:
804 ret
= get_errno(close(arg1
));
807 ret
= do_brk((char *)arg1
);
810 ret
= get_errno(fork());
812 case TARGET_NR_waitpid
:
814 int *status
= (int *)arg2
;
815 ret
= get_errno(waitpid(arg1
, status
, arg3
));
816 if (!is_error(ret
) && status
)
817 tswapls((long *)&status
);
820 case TARGET_NR_creat
:
821 ret
= get_errno(creat((const char *)arg1
, arg2
));
824 ret
= get_errno(link((const char *)arg1
, (const char *)arg2
));
826 case TARGET_NR_unlink
:
827 ret
= get_errno(unlink((const char *)arg1
));
829 case TARGET_NR_execve
:
830 ret
= get_errno(execve((const char *)arg1
, (void *)arg2
, (void *)arg3
));
832 case TARGET_NR_chdir
:
833 ret
= get_errno(chdir((const char *)arg1
));
837 int *time_ptr
= (int *)arg1
;
838 ret
= get_errno(time((time_t *)time_ptr
));
839 if (!is_error(ret
) && time_ptr
)
843 case TARGET_NR_mknod
:
844 ret
= get_errno(mknod((const char *)arg1
, arg2
, arg3
));
846 case TARGET_NR_chmod
:
847 ret
= get_errno(chmod((const char *)arg1
, arg2
));
849 case TARGET_NR_lchown
:
850 ret
= get_errno(chown((const char *)arg1
, arg2
, arg3
));
852 case TARGET_NR_break
:
854 case TARGET_NR_oldstat
:
856 case TARGET_NR_lseek
:
857 ret
= get_errno(lseek(arg1
, arg2
, arg3
));
859 case TARGET_NR_getpid
:
860 ret
= get_errno(getpid());
862 case TARGET_NR_mount
:
863 /* need to look at the data field */
865 case TARGET_NR_umount
:
866 ret
= get_errno(umount((const char *)arg1
));
868 case TARGET_NR_setuid
:
869 ret
= get_errno(setuid(arg1
));
871 case TARGET_NR_getuid
:
872 ret
= get_errno(getuid());
874 case TARGET_NR_stime
:
876 int *time_ptr
= (int *)arg1
;
879 ret
= get_errno(stime((time_t *)time_ptr
));
882 case TARGET_NR_ptrace
:
884 case TARGET_NR_alarm
:
887 case TARGET_NR_oldfstat
:
889 case TARGET_NR_pause
:
890 ret
= get_errno(pause());
892 case TARGET_NR_utime
:
898 case TARGET_NR_access
:
899 ret
= get_errno(access((const char *)arg1
, arg2
));
902 ret
= get_errno(nice(arg1
));
904 case TARGET_NR_ftime
:
907 ret
= get_errno(sync());
910 ret
= get_errno(kill(arg1
, arg2
));
912 case TARGET_NR_rename
:
913 ret
= get_errno(rename((const char *)arg1
, (const char *)arg2
));
915 case TARGET_NR_mkdir
:
916 ret
= get_errno(mkdir((const char *)arg1
, arg2
));
918 case TARGET_NR_rmdir
:
919 ret
= get_errno(rmdir((const char *)arg1
));
922 ret
= get_errno(dup(arg1
));
926 int *pipe_ptr
= (int *)arg1
;
927 ret
= get_errno(pipe(pipe_ptr
));
928 if (!is_error(ret
)) {
929 tswap32s(&pipe_ptr
[0]);
930 tswap32s(&pipe_ptr
[1]);
934 case TARGET_NR_times
:
938 case TARGET_NR_setgid
:
939 ret
= get_errno(setgid(arg1
));
941 case TARGET_NR_getgid
:
942 ret
= get_errno(getgid());
944 case TARGET_NR_signal
:
946 case TARGET_NR_geteuid
:
947 ret
= get_errno(geteuid());
949 case TARGET_NR_getegid
:
950 ret
= get_errno(getegid());
954 case TARGET_NR_umount2
:
955 ret
= get_errno(umount2((const char *)arg1
, arg2
));
959 case TARGET_NR_ioctl
:
960 ret
= do_ioctl(arg1
, arg2
, arg3
);
962 case TARGET_NR_fcntl
:
969 ret
= get_errno(fcntl(arg1
, arg2
, arg3
));
975 case TARGET_NR_setpgid
:
976 ret
= get_errno(setpgid(arg1
, arg2
));
978 case TARGET_NR_ulimit
:
980 case TARGET_NR_oldolduname
:
982 case TARGET_NR_umask
:
983 ret
= get_errno(umask(arg1
));
985 case TARGET_NR_chroot
:
986 ret
= get_errno(chroot((const char *)arg1
));
988 case TARGET_NR_ustat
:
991 ret
= get_errno(dup2(arg1
, arg2
));
993 case TARGET_NR_getppid
:
994 ret
= get_errno(getppid());
996 case TARGET_NR_getpgrp
:
997 ret
= get_errno(getpgrp());
999 case TARGET_NR_setsid
:
1000 ret
= get_errno(setsid());
1002 case TARGET_NR_sigaction
:
1011 case TARGET_NR_sgetmask
:
1013 case TARGET_NR_ssetmask
:
1015 case TARGET_NR_setreuid
:
1016 ret
= get_errno(setreuid(arg1
, arg2
));
1018 case TARGET_NR_setregid
:
1019 ret
= get_errno(setregid(arg1
, arg2
));
1021 case TARGET_NR_sigsuspend
:
1023 case TARGET_NR_sigpending
:
1025 case TARGET_NR_sethostname
:
1026 ret
= get_errno(sethostname((const char *)arg1
, arg2
));
1028 case TARGET_NR_setrlimit
:
1030 case TARGET_NR_getrlimit
:
1032 case TARGET_NR_getrusage
:
1034 case TARGET_NR_gettimeofday
:
1036 struct target_timeval
*target_tv
= (void *)arg1
;
1038 ret
= get_errno(gettimeofday(&tv
, NULL
));
1039 if (!is_error(ret
)) {
1040 target_tv
->tv_sec
= tswapl(tv
.tv_sec
);
1041 target_tv
->tv_usec
= tswapl(tv
.tv_usec
);
1045 case TARGET_NR_settimeofday
:
1047 struct target_timeval
*target_tv
= (void *)arg1
;
1049 tv
.tv_sec
= tswapl(target_tv
->tv_sec
);
1050 tv
.tv_usec
= tswapl(target_tv
->tv_usec
);
1051 ret
= get_errno(settimeofday(&tv
, NULL
));
1054 case TARGET_NR_getgroups
:
1056 case TARGET_NR_setgroups
:
1058 case TARGET_NR_select
:
1060 case TARGET_NR_symlink
:
1061 ret
= get_errno(symlink((const char *)arg1
, (const char *)arg2
));
1063 case TARGET_NR_oldlstat
:
1065 case TARGET_NR_readlink
:
1066 ret
= get_errno(readlink((const char *)arg1
, (char *)arg2
, arg3
));
1068 case TARGET_NR_uselib
:
1070 case TARGET_NR_swapon
:
1071 ret
= get_errno(swapon((const char *)arg1
, arg2
));
1073 case TARGET_NR_reboot
:
1075 case TARGET_NR_readdir
:
1078 case TARGET_NR_mmap
:
1080 uint32_t v1
, v2
, v3
, v4
, v5
, v6
, *vptr
;
1081 vptr
= (uint32_t *)arg1
;
1082 v1
= tswap32(vptr
[0]);
1083 v2
= tswap32(vptr
[1]);
1084 v3
= tswap32(vptr
[2]);
1085 v4
= tswap32(vptr
[3]);
1086 v5
= tswap32(vptr
[4]);
1087 v6
= tswap32(vptr
[5]);
1088 ret
= get_errno((long)mmap((void *)v1
, v2
, v3
, v4
, v5
, v6
));
1093 case TARGET_NR_mmap2
:
1095 case TARGET_NR_mmap
:
1097 ret
= get_errno((long)mmap((void *)arg1
, arg2
, arg3
, arg4
, arg5
, arg6
));
1099 case TARGET_NR_munmap
:
1100 ret
= get_errno(munmap((void *)arg1
, arg2
));
1102 case TARGET_NR_truncate
:
1103 ret
= get_errno(truncate((const char *)arg1
, arg2
));
1105 case TARGET_NR_ftruncate
:
1106 ret
= get_errno(ftruncate(arg1
, arg2
));
1108 case TARGET_NR_fchmod
:
1109 ret
= get_errno(fchmod(arg1
, arg2
));
1111 case TARGET_NR_fchown
:
1112 ret
= get_errno(fchown(arg1
, arg2
, arg3
));
1114 case TARGET_NR_getpriority
:
1115 ret
= get_errno(getpriority(arg1
, arg2
));
1117 case TARGET_NR_setpriority
:
1118 ret
= get_errno(setpriority(arg1
, arg2
, arg3
));
1120 case TARGET_NR_profil
:
1122 case TARGET_NR_statfs
:
1123 stfs
= (void *)arg2
;
1124 ret
= get_errno(sys_statfs((const char *)arg1
, stfs
));
1126 if (!is_error(ret
)) {
1127 tswap32s(&stfs
->f_type
);
1128 tswap32s(&stfs
->f_bsize
);
1129 tswap32s(&stfs
->f_blocks
);
1130 tswap32s(&stfs
->f_bfree
);
1131 tswap32s(&stfs
->f_bavail
);
1132 tswap32s(&stfs
->f_files
);
1133 tswap32s(&stfs
->f_ffree
);
1134 tswap32s(&stfs
->f_fsid
.val
[0]);
1135 tswap32s(&stfs
->f_fsid
.val
[1]);
1136 tswap32s(&stfs
->f_namelen
);
1139 case TARGET_NR_fstatfs
:
1140 stfs
= (void *)arg2
;
1141 ret
= get_errno(sys_fstatfs(arg1
, stfs
));
1142 goto convert_statfs
;
1143 case TARGET_NR_ioperm
:
1145 case TARGET_NR_socketcall
:
1146 ret
= do_socketcall(arg1
, (long *)arg2
);
1148 case TARGET_NR_syslog
:
1150 case TARGET_NR_setitimer
:
1152 case TARGET_NR_getitimer
:
1154 case TARGET_NR_stat
:
1155 ret
= get_errno(stat((const char *)arg1
, &st
));
1157 case TARGET_NR_lstat
:
1158 ret
= get_errno(lstat((const char *)arg1
, &st
));
1160 case TARGET_NR_fstat
:
1162 ret
= get_errno(fstat(arg1
, &st
));
1164 if (!is_error(ret
)) {
1165 struct target_stat
*target_st
= (void *)arg2
;
1166 target_st
->st_dev
= tswap16(st
.st_dev
);
1167 target_st
->st_ino
= tswapl(st
.st_ino
);
1168 target_st
->st_mode
= tswap16(st
.st_mode
);
1169 target_st
->st_nlink
= tswap16(st
.st_nlink
);
1170 target_st
->st_uid
= tswap16(st
.st_uid
);
1171 target_st
->st_gid
= tswap16(st
.st_gid
);
1172 target_st
->st_rdev
= tswap16(st
.st_rdev
);
1173 target_st
->st_size
= tswapl(st
.st_size
);
1174 target_st
->st_blksize
= tswapl(st
.st_blksize
);
1175 target_st
->st_blocks
= tswapl(st
.st_blocks
);
1176 target_st
->st_atime
= tswapl(st
.st_atime
);
1177 target_st
->st_mtime
= tswapl(st
.st_mtime
);
1178 target_st
->st_ctime
= tswapl(st
.st_ctime
);
1182 case TARGET_NR_olduname
:
1184 case TARGET_NR_iopl
:
1186 case TARGET_NR_vhangup
:
1187 ret
= get_errno(vhangup());
1189 case TARGET_NR_idle
:
1191 case TARGET_NR_vm86old
:
1193 case TARGET_NR_wait4
:
1196 target_long
*status_ptr
= (void *)arg2
;
1197 struct rusage rusage
, *rusage_ptr
;
1198 struct target_rusage
*target_rusage
= (void *)arg4
;
1200 rusage_ptr
= &rusage
;
1203 ret
= get_errno(wait4(arg1
, &status
, arg3
, rusage_ptr
));
1204 if (!is_error(ret
)) {
1206 *status_ptr
= tswap32(status
);
1207 if (target_rusage
) {
1208 target_rusage
->ru_utime
.tv_sec
= tswapl(rusage
.ru_utime
.tv_sec
);
1209 target_rusage
->ru_utime
.tv_usec
= tswapl(rusage
.ru_utime
.tv_usec
);
1210 target_rusage
->ru_stime
.tv_sec
= tswapl(rusage
.ru_stime
.tv_sec
);
1211 target_rusage
->ru_stime
.tv_usec
= tswapl(rusage
.ru_stime
.tv_usec
);
1212 target_rusage
->ru_maxrss
= tswapl(rusage
.ru_maxrss
);
1213 target_rusage
->ru_ixrss
= tswapl(rusage
.ru_ixrss
);
1214 target_rusage
->ru_idrss
= tswapl(rusage
.ru_idrss
);
1215 target_rusage
->ru_isrss
= tswapl(rusage
.ru_isrss
);
1216 target_rusage
->ru_minflt
= tswapl(rusage
.ru_minflt
);
1217 target_rusage
->ru_majflt
= tswapl(rusage
.ru_majflt
);
1218 target_rusage
->ru_nswap
= tswapl(rusage
.ru_nswap
);
1219 target_rusage
->ru_inblock
= tswapl(rusage
.ru_inblock
);
1220 target_rusage
->ru_oublock
= tswapl(rusage
.ru_oublock
);
1221 target_rusage
->ru_msgsnd
= tswapl(rusage
.ru_msgsnd
);
1222 target_rusage
->ru_msgrcv
= tswapl(rusage
.ru_msgrcv
);
1223 target_rusage
->ru_nsignals
= tswapl(rusage
.ru_nsignals
);
1224 target_rusage
->ru_nvcsw
= tswapl(rusage
.ru_nvcsw
);
1225 target_rusage
->ru_nivcsw
= tswapl(rusage
.ru_nivcsw
);
1230 case TARGET_NR_swapoff
:
1231 ret
= get_errno(swapoff((const char *)arg1
));
1233 case TARGET_NR_sysinfo
:
1237 case TARGET_NR_fsync
:
1238 ret
= get_errno(fsync(arg1
));
1240 case TARGET_NR_sigreturn
:
1242 case TARGET_NR_clone
:
1244 case TARGET_NR_setdomainname
:
1245 ret
= get_errno(setdomainname((const char *)arg1
, arg2
));
1247 case TARGET_NR_uname
:
1248 /* no need to transcode because we use the linux syscall */
1249 ret
= get_errno(sys_uname((struct new_utsname
*)arg1
));
1252 case TARGET_NR_modify_ldt
:
1253 ret
= get_errno(gemu_modify_ldt(cpu_env
, arg1
, (void *)arg2
, arg3
));
1256 case TARGET_NR_adjtimex
:
1258 case TARGET_NR_mprotect
:
1259 ret
= get_errno(mprotect((void *)arg1
, arg2
, arg3
));
1261 case TARGET_NR_sigprocmask
:
1264 sigset_t set
, oldset
, *set_ptr
;
1265 target_ulong
*pset
= (void *)arg2
, *poldset
= (void *)arg3
;
1268 case TARGET_SIG_BLOCK
:
1271 case TARGET_SIG_UNBLOCK
:
1274 case TARGET_SIG_SETMASK
:
1283 target_to_host_old_sigset(&set
, pset
);
1288 ret
= get_errno(sigprocmask(arg1
, set_ptr
, &oldset
));
1289 if (!is_error(ret
) && poldset
) {
1290 host_to_target_old_sigset(poldset
, &oldset
);
1294 case TARGET_NR_create_module
:
1295 case TARGET_NR_init_module
:
1296 case TARGET_NR_delete_module
:
1297 case TARGET_NR_get_kernel_syms
:
1299 case TARGET_NR_quotactl
:
1301 case TARGET_NR_getpgid
:
1302 ret
= get_errno(getpgid(arg1
));
1304 case TARGET_NR_fchdir
:
1305 ret
= get_errno(fchdir(arg1
));
1307 case TARGET_NR_bdflush
:
1309 case TARGET_NR_sysfs
:
1311 case TARGET_NR_personality
:
1312 ret
= get_errno(mprotect((void *)arg1
, arg2
, arg3
));
1314 case TARGET_NR_afs_syscall
:
1316 case TARGET_NR_setfsuid
:
1318 case TARGET_NR_setfsgid
:
1320 case TARGET_NR__llseek
:
1323 ret
= get_errno(_llseek(arg1
, arg2
, arg3
, &res
, arg5
));
1324 *(int64_t *)arg4
= tswap64(res
);
1327 case TARGET_NR_getdents
:
1328 #if TARGET_LONG_SIZE != 4
1329 #error not supported
1332 struct dirent
*dirp
= (void *)arg2
;
1334 ret
= get_errno(sys_getdents(arg1
, dirp
, count
));
1335 if (!is_error(ret
)) {
1341 reclen
= tswap16(de
->d_reclen
);
1344 de
->d_reclen
= reclen
;
1345 tswapls(&de
->d_ino
);
1346 tswapls(&de
->d_off
);
1347 de
= (struct dirent
*)((char *)de
+ reclen
);
1353 case TARGET_NR__newselect
:
1354 ret
= do_select(arg1
, (void *)arg2
, (void *)arg3
, (void *)arg4
,
1357 case TARGET_NR_flock
:
1359 case TARGET_NR_msync
:
1360 ret
= get_errno(msync((void *)arg1
, arg2
, arg3
));
1362 case TARGET_NR_readv
:
1367 struct target_iovec
*target_vec
= (void *)arg2
;
1369 vec
= alloca(count
* sizeof(struct iovec
));
1370 for(i
= 0;i
< count
; i
++) {
1371 vec
[i
].iov_base
= (void *)tswapl(target_vec
[i
].iov_base
);
1372 vec
[i
].iov_len
= tswapl(target_vec
[i
].iov_len
);
1374 ret
= get_errno(readv(arg1
, vec
, count
));
1377 case TARGET_NR_writev
:
1382 struct target_iovec
*target_vec
= (void *)arg2
;
1384 vec
= alloca(count
* sizeof(struct iovec
));
1385 for(i
= 0;i
< count
; i
++) {
1386 vec
[i
].iov_base
= (void *)tswapl(target_vec
[i
].iov_base
);
1387 vec
[i
].iov_len
= tswapl(target_vec
[i
].iov_len
);
1389 ret
= get_errno(writev(arg1
, vec
, count
));
1392 case TARGET_NR_getsid
:
1393 ret
= get_errno(getsid(arg1
));
1395 case TARGET_NR_fdatasync
:
1397 case TARGET_NR__sysctl
:
1399 case TARGET_NR_mlock
:
1400 ret
= get_errno(mlock((void *)arg1
, arg2
));
1402 case TARGET_NR_munlock
:
1403 ret
= get_errno(munlock((void *)arg1
, arg2
));
1405 case TARGET_NR_mlockall
:
1406 ret
= get_errno(mlockall(arg1
));
1408 case TARGET_NR_munlockall
:
1409 ret
= get_errno(munlockall());
1411 case TARGET_NR_sched_setparam
:
1413 case TARGET_NR_sched_getparam
:
1415 case TARGET_NR_sched_setscheduler
:
1417 case TARGET_NR_sched_getscheduler
:
1419 case TARGET_NR_sched_yield
:
1420 ret
= get_errno(sched_yield());
1422 case TARGET_NR_sched_get_priority_max
:
1423 case TARGET_NR_sched_get_priority_min
:
1424 case TARGET_NR_sched_rr_get_interval
:
1425 case TARGET_NR_nanosleep
:
1426 case TARGET_NR_mremap
:
1427 case TARGET_NR_setresuid
:
1428 case TARGET_NR_getresuid
:
1429 case TARGET_NR_vm86
:
1430 case TARGET_NR_query_module
:
1431 case TARGET_NR_poll
:
1432 case TARGET_NR_nfsservctl
:
1433 case TARGET_NR_setresgid
:
1434 case TARGET_NR_getresgid
:
1435 case TARGET_NR_prctl
:
1436 case TARGET_NR_rt_sigreturn
:
1437 case TARGET_NR_rt_sigaction
:
1438 case TARGET_NR_rt_sigprocmask
:
1439 case TARGET_NR_rt_sigpending
:
1440 case TARGET_NR_rt_sigtimedwait
:
1441 case TARGET_NR_rt_sigqueueinfo
:
1442 case TARGET_NR_rt_sigsuspend
:
1443 case TARGET_NR_pread
:
1444 case TARGET_NR_pwrite
:
1446 case TARGET_NR_chown
:
1447 ret
= get_errno(chown((const char *)arg1
, arg2
, arg3
));
1449 case TARGET_NR_getcwd
:
1450 ret
= get_errno(sys_getcwd1((char *)arg1
, arg2
));
1452 case TARGET_NR_capget
:
1453 case TARGET_NR_capset
:
1454 case TARGET_NR_sigaltstack
:
1455 case TARGET_NR_sendfile
:
1456 case TARGET_NR_getpmsg
:
1457 case TARGET_NR_putpmsg
:
1458 case TARGET_NR_vfork
:
1459 ret
= get_errno(vfork());
1461 case TARGET_NR_ugetrlimit
:
1462 case TARGET_NR_truncate64
:
1463 case TARGET_NR_ftruncate64
:
1465 case TARGET_NR_stat64
:
1466 ret
= get_errno(stat((const char *)arg1
, &st
));
1468 case TARGET_NR_lstat64
:
1469 ret
= get_errno(lstat((const char *)arg1
, &st
));
1471 case TARGET_NR_fstat64
:
1473 ret
= get_errno(fstat(arg1
, &st
));
1475 if (!is_error(ret
)) {
1476 struct target_stat64
*target_st
= (void *)arg2
;
1477 target_st
->st_dev
= tswap16(st
.st_dev
);
1478 target_st
->st_ino
= tswapl(st
.st_ino
);
1479 target_st
->st_mode
= tswap16(st
.st_mode
);
1480 target_st
->st_nlink
= tswap16(st
.st_nlink
);
1481 target_st
->st_uid
= tswap16(st
.st_uid
);
1482 target_st
->st_gid
= tswap16(st
.st_gid
);
1483 target_st
->st_rdev
= tswap16(st
.st_rdev
);
1484 /* XXX: better use of kernel struct */
1485 target_st
->st_size
= tswapl(st
.st_size
);
1486 target_st
->st_blksize
= tswapl(st
.st_blksize
);
1487 target_st
->st_blocks
= tswapl(st
.st_blocks
);
1488 target_st
->st_atime
= tswapl(st
.st_atime
);
1489 target_st
->st_mtime
= tswapl(st
.st_mtime
);
1490 target_st
->st_ctime
= tswapl(st
.st_ctime
);
1495 case TARGET_NR_lchown32
:
1496 case TARGET_NR_getuid32
:
1497 case TARGET_NR_getgid32
:
1498 case TARGET_NR_geteuid32
:
1499 case TARGET_NR_getegid32
:
1500 case TARGET_NR_setreuid32
:
1501 case TARGET_NR_setregid32
:
1502 case TARGET_NR_getgroups32
:
1503 case TARGET_NR_setgroups32
:
1504 case TARGET_NR_fchown32
:
1505 case TARGET_NR_setresuid32
:
1506 case TARGET_NR_getresuid32
:
1507 case TARGET_NR_setresgid32
:
1508 case TARGET_NR_getresgid32
:
1509 case TARGET_NR_chown32
:
1510 case TARGET_NR_setuid32
:
1511 case TARGET_NR_setgid32
:
1512 case TARGET_NR_setfsuid32
:
1513 case TARGET_NR_setfsgid32
:
1514 case TARGET_NR_pivot_root
:
1515 case TARGET_NR_mincore
:
1516 case TARGET_NR_madvise
:
1517 case TARGET_NR_getdents64
:
1519 #if TARGET_LONG_BITS == 32
1520 case TARGET_NR_fcntl64
:
1527 ret
= get_errno(fcntl(arg1
, arg2
, arg3
));
1532 case TARGET_NR_security
:
1534 case TARGET_NR_gettid
:
1535 ret
= get_errno(gettid());
1537 case TARGET_NR_readahead
:
1538 case TARGET_NR_setxattr
:
1539 case TARGET_NR_lsetxattr
:
1540 case TARGET_NR_fsetxattr
:
1541 case TARGET_NR_getxattr
:
1542 case TARGET_NR_lgetxattr
:
1543 case TARGET_NR_fgetxattr
:
1544 case TARGET_NR_listxattr
:
1545 case TARGET_NR_llistxattr
:
1546 case TARGET_NR_flistxattr
:
1547 case TARGET_NR_removexattr
:
1548 case TARGET_NR_lremovexattr
:
1549 case TARGET_NR_fremovexattr
:
1553 gemu_log("Unsupported syscall: %d\n", num
);