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/times.h>
45 #include <sys/statfs.h>
47 #include <sys/sysinfo.h>
48 //#include <sys/user.h>
49 #include <netinet/ip.h>
50 #include <netinet/tcp.h>
52 #define termios host_termios
53 #define winsize host_winsize
54 #define termio host_termio
55 #define sgttyb host_sgttyb /* same as target */
56 #define tchars host_tchars /* same as target */
57 #define ltchars host_ltchars /* same as target */
59 #include <linux/termios.h>
60 #include <linux/unistd.h>
61 #include <linux/utsname.h>
62 #include <linux/cdrom.h>
63 #include <linux/hdreg.h>
64 #include <linux/soundcard.h>
65 #include <linux/dirent.h>
72 #if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_SPARC)
73 /* 16 bit uid wrappers emulation */
77 //#include <linux/msdos_fs.h>
78 #define VFAT_IOCTL_READDIR_BOTH _IOR('r', 1, struct dirent [2])
79 #define VFAT_IOCTL_READDIR_SHORT _IOR('r', 2, struct dirent [2])
82 #if defined(__powerpc__)
84 #undef __sc_loadargs_0
85 #undef __sc_loadargs_1
86 #undef __sc_loadargs_2
87 #undef __sc_loadargs_3
88 #undef __sc_loadargs_4
89 #undef __sc_loadargs_5
90 #undef __sc_asm_input_0
91 #undef __sc_asm_input_1
92 #undef __sc_asm_input_2
93 #undef __sc_asm_input_3
94 #undef __sc_asm_input_4
95 #undef __sc_asm_input_5
103 /* need to redefine syscalls as Linux kernel defines are incorrect for
105 /* On powerpc a system call basically clobbers the same registers like a
106 * function call, with the exception of LR (which is needed for the
107 * "sc; bnslr" sequence) and CR (where only CR0.SO is clobbered to signal
108 * an error return status).
111 #define __syscall_nr(nr, type, name, args...) \
112 unsigned long __sc_ret, __sc_err; \
114 register unsigned long __sc_0 __asm__ ("r0"); \
115 register unsigned long __sc_3 __asm__ ("r3"); \
116 register unsigned long __sc_4 __asm__ ("r4"); \
117 register unsigned long __sc_5 __asm__ ("r5"); \
118 register unsigned long __sc_6 __asm__ ("r6"); \
119 register unsigned long __sc_7 __asm__ ("r7"); \
121 __sc_loadargs_##nr(name, args); \
122 __asm__ __volatile__ \
126 "=&r" (__sc_3), "=&r" (__sc_4), \
127 "=&r" (__sc_5), "=&r" (__sc_6), \
129 : __sc_asm_input_##nr \
130 : "cr0", "ctr", "memory", \
131 "r8", "r9", "r10","r11", "r12"); \
135 if (__sc_err & 0x10000000) \
140 return (type) __sc_ret
142 #define __sc_loadargs_0(name, dummy...) \
144 #define __sc_loadargs_1(name, arg1) \
145 __sc_loadargs_0(name); \
146 __sc_3 = (unsigned long) (arg1)
147 #define __sc_loadargs_2(name, arg1, arg2) \
148 __sc_loadargs_1(name, arg1); \
149 __sc_4 = (unsigned long) (arg2)
150 #define __sc_loadargs_3(name, arg1, arg2, arg3) \
151 __sc_loadargs_2(name, arg1, arg2); \
152 __sc_5 = (unsigned long) (arg3)
153 #define __sc_loadargs_4(name, arg1, arg2, arg3, arg4) \
154 __sc_loadargs_3(name, arg1, arg2, arg3); \
155 __sc_6 = (unsigned long) (arg4)
156 #define __sc_loadargs_5(name, arg1, arg2, arg3, arg4, arg5) \
157 __sc_loadargs_4(name, arg1, arg2, arg3, arg4); \
158 __sc_7 = (unsigned long) (arg5)
160 #define __sc_asm_input_0 "0" (__sc_0)
161 #define __sc_asm_input_1 __sc_asm_input_0, "1" (__sc_3)
162 #define __sc_asm_input_2 __sc_asm_input_1, "2" (__sc_4)
163 #define __sc_asm_input_3 __sc_asm_input_2, "3" (__sc_5)
164 #define __sc_asm_input_4 __sc_asm_input_3, "4" (__sc_6)
165 #define __sc_asm_input_5 __sc_asm_input_4, "5" (__sc_7)
167 #define _syscall0(type,name) \
170 __syscall_nr(0, type, name); \
173 #define _syscall1(type,name,type1,arg1) \
174 type name(type1 arg1) \
176 __syscall_nr(1, type, name, arg1); \
179 #define _syscall2(type,name,type1,arg1,type2,arg2) \
180 type name(type1 arg1, type2 arg2) \
182 __syscall_nr(2, type, name, arg1, arg2); \
185 #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
186 type name(type1 arg1, type2 arg2, type3 arg3) \
188 __syscall_nr(3, type, name, arg1, arg2, arg3); \
191 #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
192 type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
194 __syscall_nr(4, type, name, arg1, arg2, arg3, arg4); \
197 #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5) \
198 type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) \
200 __syscall_nr(5, type, name, arg1, arg2, arg3, arg4, arg5); \
204 #define __NR_sys_uname __NR_uname
205 #define __NR_sys_getcwd1 __NR_getcwd
206 #define __NR_sys_getdents __NR_getdents
207 #define __NR_sys_getdents64 __NR_getdents64
208 #define __NR_sys_rt_sigqueueinfo __NR_rt_sigqueueinfo
210 #if defined(__alpha__) || defined (__ia64__) || defined(__x86_64__)
211 #define __NR__llseek __NR_lseek
215 _syscall0(int, gettid
)
217 static int gettid(void) {
221 _syscall1(int,sys_uname
,struct new_utsname
*,buf
)
222 _syscall2(int,sys_getcwd1
,char *,buf
,size_t,size
)
223 _syscall3(int, sys_getdents
, uint
, fd
, struct dirent
*, dirp
, uint
, count
);
224 _syscall3(int, sys_getdents64
, uint
, fd
, struct dirent64
*, dirp
, uint
, count
);
225 _syscall5(int, _llseek
, uint
, fd
, ulong
, hi
, ulong
, lo
,
226 loff_t
*, res
, uint
, wh
);
227 _syscall3(int,sys_rt_sigqueueinfo
,int,pid
,int,sig
,siginfo_t
*,uinfo
)
228 #ifdef __NR_exit_group
229 _syscall1(int,exit_group
,int,error_code
)
232 extern int personality(int);
233 extern int flock(int, int);
234 extern int setfsuid(int);
235 extern int setfsgid(int);
236 extern int setresuid(uid_t
, uid_t
, uid_t
);
237 extern int getresuid(uid_t
*, uid_t
*, uid_t
*);
238 extern int setresgid(gid_t
, gid_t
, gid_t
);
239 extern int getresgid(gid_t
*, gid_t
*, gid_t
*);
240 extern int setgroups(int, gid_t
*);
242 static inline long get_errno(long ret
)
250 static inline int is_error(long ret
)
252 return (unsigned long)ret
>= (unsigned long)(-4096);
255 static target_ulong target_brk
;
256 static target_ulong target_original_brk
;
258 void target_set_brk(target_ulong new_brk
)
260 target_original_brk
= target_brk
= new_brk
;
263 long do_brk(target_ulong new_brk
)
265 target_ulong brk_page
;
271 if (new_brk
< target_original_brk
)
274 brk_page
= HOST_PAGE_ALIGN(target_brk
);
276 /* If the new brk is less than this, set it and we're done... */
277 if (new_brk
< brk_page
) {
278 target_brk
= new_brk
;
282 /* We need to allocate more memory after the brk... */
283 new_alloc_size
= HOST_PAGE_ALIGN(new_brk
- brk_page
+ 1);
284 mapped_addr
= get_errno(target_mmap(brk_page
, new_alloc_size
,
285 PROT_READ
|PROT_WRITE
,
286 MAP_ANON
|MAP_FIXED
|MAP_PRIVATE
, 0, 0));
287 if (is_error(mapped_addr
)) {
290 target_brk
= new_brk
;
295 static inline fd_set
*target_to_host_fds(fd_set
*fds
,
296 target_long
*target_fds
, int n
)
298 #if !defined(BSWAP_NEEDED) && !defined(WORDS_BIGENDIAN)
299 return (fd_set
*)target_fds
;
304 for(i
= 0;i
< n
; i
++) {
305 b
= (tswapl(target_fds
[i
/ TARGET_LONG_BITS
]) >>
306 (i
& (TARGET_LONG_BITS
- 1))) & 1;
317 static inline void host_to_target_fds(target_long
*target_fds
,
320 #if !defined(BSWAP_NEEDED) && !defined(WORDS_BIGENDIAN)
327 nw
= (n
+ TARGET_LONG_BITS
- 1) / TARGET_LONG_BITS
;
329 for(i
= 0;i
< nw
; i
++) {
331 for(j
= 0; j
< TARGET_LONG_BITS
; j
++) {
332 v
|= ((FD_ISSET(k
, fds
) != 0) << j
);
335 target_fds
[i
] = tswapl(v
);
341 #if defined(__alpha__)
347 static inline long host_to_target_clock_t(long ticks
)
349 #if HOST_HZ == TARGET_HZ
352 return ((int64_t)ticks
* TARGET_HZ
) / HOST_HZ
;
356 static inline void host_to_target_rusage(target_ulong target_addr
,
357 const struct rusage
*rusage
)
359 struct target_rusage
*target_rusage
;
361 lock_user_struct(target_rusage
, target_addr
, 0);
362 target_rusage
->ru_utime
.tv_sec
= tswapl(rusage
->ru_utime
.tv_sec
);
363 target_rusage
->ru_utime
.tv_usec
= tswapl(rusage
->ru_utime
.tv_usec
);
364 target_rusage
->ru_stime
.tv_sec
= tswapl(rusage
->ru_stime
.tv_sec
);
365 target_rusage
->ru_stime
.tv_usec
= tswapl(rusage
->ru_stime
.tv_usec
);
366 target_rusage
->ru_maxrss
= tswapl(rusage
->ru_maxrss
);
367 target_rusage
->ru_ixrss
= tswapl(rusage
->ru_ixrss
);
368 target_rusage
->ru_idrss
= tswapl(rusage
->ru_idrss
);
369 target_rusage
->ru_isrss
= tswapl(rusage
->ru_isrss
);
370 target_rusage
->ru_minflt
= tswapl(rusage
->ru_minflt
);
371 target_rusage
->ru_majflt
= tswapl(rusage
->ru_majflt
);
372 target_rusage
->ru_nswap
= tswapl(rusage
->ru_nswap
);
373 target_rusage
->ru_inblock
= tswapl(rusage
->ru_inblock
);
374 target_rusage
->ru_oublock
= tswapl(rusage
->ru_oublock
);
375 target_rusage
->ru_msgsnd
= tswapl(rusage
->ru_msgsnd
);
376 target_rusage
->ru_msgrcv
= tswapl(rusage
->ru_msgrcv
);
377 target_rusage
->ru_nsignals
= tswapl(rusage
->ru_nsignals
);
378 target_rusage
->ru_nvcsw
= tswapl(rusage
->ru_nvcsw
);
379 target_rusage
->ru_nivcsw
= tswapl(rusage
->ru_nivcsw
);
380 unlock_user_struct(target_rusage
, target_addr
, 1);
383 static inline void target_to_host_timeval(struct timeval
*tv
,
384 target_ulong target_addr
)
386 struct target_timeval
*target_tv
;
388 lock_user_struct(target_tv
, target_addr
, 1);
389 tv
->tv_sec
= tswapl(target_tv
->tv_sec
);
390 tv
->tv_usec
= tswapl(target_tv
->tv_usec
);
391 unlock_user_struct(target_tv
, target_addr
, 0);
394 static inline void host_to_target_timeval(target_ulong target_addr
,
395 const struct timeval
*tv
)
397 struct target_timeval
*target_tv
;
399 lock_user_struct(target_tv
, target_addr
, 0);
400 target_tv
->tv_sec
= tswapl(tv
->tv_sec
);
401 target_tv
->tv_usec
= tswapl(tv
->tv_usec
);
402 unlock_user_struct(target_tv
, target_addr
, 1);
406 static long do_select(long n
,
407 target_ulong rfd_p
, target_ulong wfd_p
,
408 target_ulong efd_p
, target_ulong target_tv
)
410 fd_set rfds
, wfds
, efds
;
411 fd_set
*rfds_ptr
, *wfds_ptr
, *efds_ptr
;
412 target_long
*target_rfds
, *target_wfds
, *target_efds
;
413 struct timeval tv
, *tv_ptr
;
418 target_rfds
= lock_user(rfd_p
, sizeof(target_long
) * n
, 1);
419 rfds_ptr
= target_to_host_fds(&rfds
, target_rfds
, n
);
425 target_wfds
= lock_user(wfd_p
, sizeof(target_long
) * n
, 1);
426 wfds_ptr
= target_to_host_fds(&wfds
, target_wfds
, n
);
432 target_efds
= lock_user(efd_p
, sizeof(target_long
) * n
, 1);
433 efds_ptr
= target_to_host_fds(&efds
, target_efds
, n
);
440 target_to_host_timeval(&tv
, target_tv
);
445 ret
= get_errno(select(n
, rfds_ptr
, wfds_ptr
, efds_ptr
, tv_ptr
));
449 host_to_target_fds(target_rfds
, rfds_ptr
, n
);
450 host_to_target_fds(target_wfds
, wfds_ptr
, n
);
451 host_to_target_fds(target_efds
, efds_ptr
, n
);
454 host_to_target_timeval(target_tv
, &tv
);
458 unlock_user(target_rfds
, rfd_p
, ok
? sizeof(target_long
) * n
: 0);
460 unlock_user(target_wfds
, wfd_p
, ok
? sizeof(target_long
) * n
: 0);
462 unlock_user(target_efds
, efd_p
, ok
? sizeof(target_long
) * n
: 0);
467 static inline void target_to_host_sockaddr(struct sockaddr
*addr
,
468 target_ulong target_addr
,
471 struct target_sockaddr
*target_saddr
;
473 target_saddr
= lock_user(target_addr
, len
, 1);
474 memcpy(addr
, target_saddr
, len
);
475 addr
->sa_family
= tswap16(target_saddr
->sa_family
);
476 unlock_user(target_saddr
, target_addr
, 0);
479 static inline void host_to_target_sockaddr(target_ulong target_addr
,
480 struct sockaddr
*addr
,
483 struct target_sockaddr
*target_saddr
;
485 target_saddr
= lock_user(target_addr
, len
, 0);
486 memcpy(target_saddr
, addr
, len
);
487 target_saddr
->sa_family
= tswap16(addr
->sa_family
);
488 unlock_user(target_saddr
, target_addr
, len
);
491 /* ??? Should this also swap msgh->name? */
492 static inline void target_to_host_cmsg(struct msghdr
*msgh
,
493 struct target_msghdr
*target_msgh
)
495 struct cmsghdr
*cmsg
= CMSG_FIRSTHDR(msgh
);
496 struct target_cmsghdr
*target_cmsg
= TARGET_CMSG_FIRSTHDR(target_msgh
);
499 while (cmsg
&& target_cmsg
) {
500 void *data
= CMSG_DATA(cmsg
);
501 void *target_data
= TARGET_CMSG_DATA(target_cmsg
);
503 int len
= tswapl(target_cmsg
->cmsg_len
)
504 - TARGET_CMSG_ALIGN(sizeof (struct target_cmsghdr
));
506 space
+= CMSG_SPACE(len
);
507 if (space
> msgh
->msg_controllen
) {
508 space
-= CMSG_SPACE(len
);
509 gemu_log("Host cmsg overflow\n");
513 cmsg
->cmsg_level
= tswap32(target_cmsg
->cmsg_level
);
514 cmsg
->cmsg_type
= tswap32(target_cmsg
->cmsg_type
);
515 cmsg
->cmsg_len
= CMSG_LEN(len
);
517 if (cmsg
->cmsg_level
!= SOL_SOCKET
|| cmsg
->cmsg_type
!= SCM_RIGHTS
) {
518 gemu_log("Unsupported ancillary data: %d/%d\n", cmsg
->cmsg_level
, cmsg
->cmsg_type
);
519 memcpy(data
, target_data
, len
);
521 int *fd
= (int *)data
;
522 int *target_fd
= (int *)target_data
;
523 int i
, numfds
= len
/ sizeof(int);
525 for (i
= 0; i
< numfds
; i
++)
526 fd
[i
] = tswap32(target_fd
[i
]);
529 cmsg
= CMSG_NXTHDR(msgh
, cmsg
);
530 target_cmsg
= TARGET_CMSG_NXTHDR(target_msgh
, target_cmsg
);
533 msgh
->msg_controllen
= space
;
536 /* ??? Should this also swap msgh->name? */
537 static inline void host_to_target_cmsg(struct target_msghdr
*target_msgh
,
540 struct cmsghdr
*cmsg
= CMSG_FIRSTHDR(msgh
);
541 struct target_cmsghdr
*target_cmsg
= TARGET_CMSG_FIRSTHDR(target_msgh
);
544 while (cmsg
&& target_cmsg
) {
545 void *data
= CMSG_DATA(cmsg
);
546 void *target_data
= TARGET_CMSG_DATA(target_cmsg
);
548 int len
= cmsg
->cmsg_len
- CMSG_ALIGN(sizeof (struct cmsghdr
));
550 space
+= TARGET_CMSG_SPACE(len
);
551 if (space
> tswapl(target_msgh
->msg_controllen
)) {
552 space
-= TARGET_CMSG_SPACE(len
);
553 gemu_log("Target cmsg overflow\n");
557 target_cmsg
->cmsg_level
= tswap32(cmsg
->cmsg_level
);
558 target_cmsg
->cmsg_type
= tswap32(cmsg
->cmsg_type
);
559 target_cmsg
->cmsg_len
= tswapl(TARGET_CMSG_LEN(len
));
561 if (cmsg
->cmsg_level
!= SOL_SOCKET
|| cmsg
->cmsg_type
!= SCM_RIGHTS
) {
562 gemu_log("Unsupported ancillary data: %d/%d\n", cmsg
->cmsg_level
, cmsg
->cmsg_type
);
563 memcpy(target_data
, data
, len
);
565 int *fd
= (int *)data
;
566 int *target_fd
= (int *)target_data
;
567 int i
, numfds
= len
/ sizeof(int);
569 for (i
= 0; i
< numfds
; i
++)
570 target_fd
[i
] = tswap32(fd
[i
]);
573 cmsg
= CMSG_NXTHDR(msgh
, cmsg
);
574 target_cmsg
= TARGET_CMSG_NXTHDR(target_msgh
, target_cmsg
);
577 msgh
->msg_controllen
= tswapl(space
);
580 static long do_setsockopt(int sockfd
, int level
, int optname
,
581 target_ulong optval
, socklen_t optlen
)
587 /* TCP options all take an 'int' value. */
588 if (optlen
< sizeof(uint32_t))
591 val
= tget32(optval
);
592 ret
= get_errno(setsockopt(sockfd
, level
, optname
, &val
, sizeof(val
)));
599 case IP_ROUTER_ALERT
:
603 case IP_MTU_DISCOVER
:
609 case IP_MULTICAST_TTL
:
610 case IP_MULTICAST_LOOP
:
612 if (optlen
>= sizeof(uint32_t)) {
613 val
= tget32(optval
);
614 } else if (optlen
>= 1) {
617 ret
= get_errno(setsockopt(sockfd
, level
, optname
, &val
, sizeof(val
)));
625 /* Options with 'int' argument. */
646 if (optlen
< sizeof(uint32_t))
649 val
= tget32(optval
);
650 ret
= get_errno(setsockopt(sockfd
, level
, optname
, &val
, sizeof(val
)));
658 gemu_log("Unsupported setsockopt level=%d optname=%d \n", level
, optname
);
664 static long do_getsockopt(int sockfd
, int level
, int optname
,
665 target_ulong optval
, target_ulong optlen
)
667 int len
, lv
, val
, ret
;
677 /* These don't just return a single integer */
684 /* TCP options all take an 'int' value. */
686 len
= tget32(optlen
);
690 ret
= get_errno(getsockopt(sockfd
, level
, optname
, &val
, &lv
));
707 case IP_ROUTER_ALERT
:
711 case IP_MTU_DISCOVER
:
717 case IP_MULTICAST_TTL
:
718 case IP_MULTICAST_LOOP
:
719 len
= tget32(optlen
);
723 ret
= get_errno(getsockopt(sockfd
, level
, optname
, &val
, &lv
));
726 if (len
< sizeof(int) && len
> 0 && val
>= 0 && val
< 255) {
731 if (len
> sizeof(int))
743 gemu_log("getsockopt level=%d optname=%d not yet supported\n",
751 static void lock_iovec(struct iovec
*vec
, target_ulong target_addr
,
754 struct target_iovec
*target_vec
;
758 target_vec
= lock_user(target_addr
, count
* sizeof(struct target_iovec
), 1);
759 for(i
= 0;i
< count
; i
++) {
760 base
= tswapl(target_vec
[i
].iov_base
);
761 vec
[i
].iov_len
= tswapl(target_vec
[i
].iov_len
);
762 vec
[i
].iov_base
= lock_user(base
, vec
[i
].iov_len
, copy
);
764 unlock_user (target_vec
, target_addr
, 0);
767 static void unlock_iovec(struct iovec
*vec
, target_ulong target_addr
,
770 struct target_iovec
*target_vec
;
774 target_vec
= lock_user(target_addr
, count
* sizeof(struct target_iovec
), 1);
775 for(i
= 0;i
< count
; i
++) {
776 base
= tswapl(target_vec
[i
].iov_base
);
777 unlock_user(vec
[i
].iov_base
, base
, copy
? vec
[i
].iov_len
: 0);
779 unlock_user (target_vec
, target_addr
, 0);
782 static long do_socketcall(int num
, target_ulong vptr
)
785 const int n
= sizeof(target_ulong
);
790 int domain
= tgetl(vptr
);
791 int type
= tgetl(vptr
+ n
);
792 int protocol
= tgetl(vptr
+ 2 * n
);
794 ret
= get_errno(socket(domain
, type
, protocol
));
799 int sockfd
= tgetl(vptr
);
800 target_ulong target_addr
= tgetl(vptr
+ n
);
801 socklen_t addrlen
= tgetl(vptr
+ 2 * n
);
802 void *addr
= alloca(addrlen
);
804 target_to_host_sockaddr(addr
, target_addr
, addrlen
);
805 ret
= get_errno(bind(sockfd
, addr
, addrlen
));
810 int sockfd
= tgetl(vptr
);
811 target_ulong target_addr
= tgetl(vptr
+ n
);
812 socklen_t addrlen
= tgetl(vptr
+ 2 * n
);
813 void *addr
= alloca(addrlen
);
815 target_to_host_sockaddr(addr
, target_addr
, addrlen
);
816 ret
= get_errno(connect(sockfd
, addr
, addrlen
));
821 int sockfd
= tgetl(vptr
);
822 int backlog
= tgetl(vptr
+ n
);
824 ret
= get_errno(listen(sockfd
, backlog
));
829 int sockfd
= tgetl(vptr
);
830 target_ulong target_addr
= tgetl(vptr
+ n
);
831 target_ulong target_addrlen
= tgetl(vptr
+ 2 * n
);
832 socklen_t addrlen
= tget32(target_addrlen
);
833 void *addr
= alloca(addrlen
);
835 ret
= get_errno(accept(sockfd
, addr
, &addrlen
));
836 if (!is_error(ret
)) {
837 host_to_target_sockaddr(target_addr
, addr
, addrlen
);
838 tput32(target_addrlen
, addrlen
);
842 case SOCKOP_getsockname
:
844 int sockfd
= tgetl(vptr
);
845 target_ulong target_addr
= tgetl(vptr
+ n
);
846 target_ulong target_addrlen
= tgetl(vptr
+ 2 * n
);
847 socklen_t addrlen
= tget32(target_addrlen
);
848 void *addr
= alloca(addrlen
);
850 ret
= get_errno(getsockname(sockfd
, addr
, &addrlen
));
851 if (!is_error(ret
)) {
852 host_to_target_sockaddr(target_addr
, addr
, addrlen
);
853 tput32(target_addrlen
, addrlen
);
857 case SOCKOP_getpeername
:
859 int sockfd
= tgetl(vptr
);
860 target_ulong target_addr
= tgetl(vptr
+ n
);
861 target_ulong target_addrlen
= tgetl(vptr
+ 2 * n
);
862 socklen_t addrlen
= tget32(target_addrlen
);
863 void *addr
= alloca(addrlen
);
865 ret
= get_errno(getpeername(sockfd
, addr
, &addrlen
));
866 if (!is_error(ret
)) {
867 host_to_target_sockaddr(target_addr
, addr
, addrlen
);
868 tput32(target_addrlen
, addrlen
);
872 case SOCKOP_socketpair
:
874 int domain
= tgetl(vptr
);
875 int type
= tgetl(vptr
+ n
);
876 int protocol
= tgetl(vptr
+ 2 * n
);
877 target_ulong target_tab
= tgetl(vptr
+ 3 * n
);
880 ret
= get_errno(socketpair(domain
, type
, protocol
, tab
));
881 if (!is_error(ret
)) {
882 tput32(target_tab
, tab
[0]);
883 tput32(target_tab
+ 4, tab
[1]);
889 int sockfd
= tgetl(vptr
);
890 target_ulong msg
= tgetl(vptr
+ n
);
891 size_t len
= tgetl(vptr
+ 2 * n
);
892 int flags
= tgetl(vptr
+ 3 * n
);
895 host_msg
= lock_user(msg
, len
, 1);
896 ret
= get_errno(send(sockfd
, host_msg
, len
, flags
));
897 unlock_user(host_msg
, msg
, 0);
902 int sockfd
= tgetl(vptr
);
903 target_ulong msg
= tgetl(vptr
+ n
);
904 size_t len
= tgetl(vptr
+ 2 * n
);
905 int flags
= tgetl(vptr
+ 3 * n
);
908 host_msg
= lock_user(msg
, len
, 0);
909 ret
= get_errno(recv(sockfd
, host_msg
, len
, flags
));
910 unlock_user(host_msg
, msg
, ret
);
915 int sockfd
= tgetl(vptr
);
916 target_ulong msg
= tgetl(vptr
+ n
);
917 size_t len
= tgetl(vptr
+ 2 * n
);
918 int flags
= tgetl(vptr
+ 3 * n
);
919 target_ulong target_addr
= tgetl(vptr
+ 4 * n
);
920 socklen_t addrlen
= tgetl(vptr
+ 5 * n
);
921 void *addr
= alloca(addrlen
);
924 host_msg
= lock_user(msg
, len
, 1);
925 target_to_host_sockaddr(addr
, target_addr
, addrlen
);
926 ret
= get_errno(sendto(sockfd
, host_msg
, len
, flags
, addr
, addrlen
));
927 unlock_user(host_msg
, msg
, 0);
930 case SOCKOP_recvfrom
:
932 int sockfd
= tgetl(vptr
);
933 target_ulong msg
= tgetl(vptr
+ n
);
934 size_t len
= tgetl(vptr
+ 2 * n
);
935 int flags
= tgetl(vptr
+ 3 * n
);
936 target_ulong target_addr
= tgetl(vptr
+ 4 * n
);
937 target_ulong target_addrlen
= tgetl(vptr
+ 5 * n
);
938 socklen_t addrlen
= tget32(target_addrlen
);
939 void *addr
= alloca(addrlen
);
942 host_msg
= lock_user(msg
, len
, 0);
943 ret
= get_errno(recvfrom(sockfd
, host_msg
, len
, flags
, addr
, &addrlen
));
944 if (!is_error(ret
)) {
945 host_to_target_sockaddr(target_addr
, addr
, addrlen
);
946 tput32(target_addrlen
, addrlen
);
947 unlock_user(host_msg
, msg
, len
);
949 unlock_user(host_msg
, msg
, 0);
953 case SOCKOP_shutdown
:
955 int sockfd
= tgetl(vptr
);
956 int how
= tgetl(vptr
+ n
);
958 ret
= get_errno(shutdown(sockfd
, how
));
965 target_ulong target_msg
;
966 struct target_msghdr
*msgp
;
970 target_ulong target_vec
;
971 int send
= (num
== SOCKOP_sendmsg
);
973 target_msg
= tgetl(vptr
+ n
);
974 lock_user_struct(msgp
, target_msg
, 1);
975 if (msgp
->msg_name
) {
976 msg
.msg_namelen
= tswap32(msgp
->msg_namelen
);
977 msg
.msg_name
= alloca(msg
.msg_namelen
);
978 target_to_host_sockaddr(msg
.msg_name
, tswapl(msgp
->msg_name
),
984 msg
.msg_controllen
= 2 * tswapl(msgp
->msg_controllen
);
985 msg
.msg_control
= alloca(msg
.msg_controllen
);
986 msg
.msg_flags
= tswap32(msgp
->msg_flags
);
988 count
= tswapl(msgp
->msg_iovlen
);
989 vec
= alloca(count
* sizeof(struct iovec
));
990 target_vec
= tswapl(msgp
->msg_iov
);
991 lock_iovec(vec
, target_vec
, count
, send
);
992 msg
.msg_iovlen
= count
;
996 flags
= tgetl(vptr
+ 2 * n
);
998 target_to_host_cmsg(&msg
, msgp
);
999 ret
= get_errno(sendmsg(fd
, &msg
, flags
));
1001 ret
= get_errno(recvmsg(fd
, &msg
, flags
));
1003 host_to_target_cmsg(msgp
, &msg
);
1005 unlock_iovec(vec
, target_vec
, count
, !send
);
1008 case SOCKOP_setsockopt
:
1010 int sockfd
= tgetl(vptr
);
1011 int level
= tgetl(vptr
+ n
);
1012 int optname
= tgetl(vptr
+ 2 * n
);
1013 target_ulong optval
= tgetl(vptr
+ 3 * n
);
1014 socklen_t optlen
= tgetl(vptr
+ 4 * n
);
1016 ret
= do_setsockopt(sockfd
, level
, optname
, optval
, optlen
);
1019 case SOCKOP_getsockopt
:
1021 int sockfd
= tgetl(vptr
);
1022 int level
= tgetl(vptr
+ n
);
1023 int optname
= tgetl(vptr
+ 2 * n
);
1024 target_ulong optval
= tgetl(vptr
+ 3 * n
);
1025 target_ulong poptlen
= tgetl(vptr
+ 4 * n
);
1027 ret
= do_getsockopt(sockfd
, level
, optname
, optval
, poptlen
);
1031 gemu_log("Unsupported socketcall: %d\n", num
);
1039 #define N_SHM_REGIONS 32
1041 static struct shm_region
{
1044 } shm_regions
[N_SHM_REGIONS
];
1046 /* ??? This only works with linear mappings. */
1047 static long do_ipc(long call
, long first
, long second
, long third
,
1048 long ptr
, long fifth
)
1052 unsigned long raddr
;
1053 struct shmid_ds shm_info
;
1056 version
= call
>> 16;
1061 /* SHM_* flags are the same on all linux platforms */
1062 ret
= get_errno((long) shmat(first
, (void *) ptr
, second
));
1066 /* find out the length of the shared memory segment */
1068 ret
= get_errno(shmctl(first
, IPC_STAT
, &shm_info
));
1069 if (is_error(ret
)) {
1070 /* can't get length, bail out */
1071 shmdt((void *) raddr
);
1074 page_set_flags(raddr
, raddr
+ shm_info
.shm_segsz
,
1075 PAGE_VALID
| PAGE_READ
|
1076 ((second
& SHM_RDONLY
)? 0: PAGE_WRITE
));
1077 for (i
= 0; i
< N_SHM_REGIONS
; ++i
) {
1078 if (shm_regions
[i
].start
== 0) {
1079 shm_regions
[i
].start
= raddr
;
1080 shm_regions
[i
].size
= shm_info
.shm_segsz
;
1084 if (put_user(raddr
, (uint32_t *)third
))
1089 for (i
= 0; i
< N_SHM_REGIONS
; ++i
) {
1090 if (shm_regions
[i
].start
== ptr
) {
1091 shm_regions
[i
].start
= 0;
1092 page_set_flags(ptr
, shm_regions
[i
].size
, 0);
1096 ret
= get_errno(shmdt((void *) ptr
));
1100 /* IPC_* flag values are the same on all linux platforms */
1101 ret
= get_errno(shmget(first
, second
, third
));
1104 /* IPC_* and SHM_* command values are the same on all linux platforms */
1110 ret
= get_errno(shmctl(first
, second
, NULL
));
1118 gemu_log("Unsupported ipc call: %ld (version %d)\n", call
, version
);
1125 /* kernel structure types definitions */
1128 #define STRUCT(name, list...) STRUCT_ ## name,
1129 #define STRUCT_SPECIAL(name) STRUCT_ ## name,
1131 #include "syscall_types.h"
1134 #undef STRUCT_SPECIAL
1136 #define STRUCT(name, list...) const argtype struct_ ## name ## _def[] = { list, TYPE_NULL };
1137 #define STRUCT_SPECIAL(name)
1138 #include "syscall_types.h"
1140 #undef STRUCT_SPECIAL
1142 typedef struct IOCTLEntry
{
1143 unsigned int target_cmd
;
1144 unsigned int host_cmd
;
1147 const argtype arg_type
[5];
1150 #define IOC_R 0x0001
1151 #define IOC_W 0x0002
1152 #define IOC_RW (IOC_R | IOC_W)
1154 #define MAX_STRUCT_SIZE 4096
1156 IOCTLEntry ioctl_entries
[] = {
1157 #define IOCTL(cmd, access, types...) \
1158 { TARGET_ ## cmd, cmd, #cmd, access, { types } },
1163 /* ??? Implement proper locking for ioctls. */
1164 static long do_ioctl(long fd
, long cmd
, long arg
)
1166 const IOCTLEntry
*ie
;
1167 const argtype
*arg_type
;
1169 uint8_t buf_temp
[MAX_STRUCT_SIZE
];
1175 if (ie
->target_cmd
== 0) {
1176 gemu_log("Unsupported ioctl: cmd=0x%04lx\n", cmd
);
1179 if (ie
->target_cmd
== cmd
)
1183 arg_type
= ie
->arg_type
;
1185 gemu_log("ioctl: cmd=0x%04lx (%s)\n", cmd
, ie
->name
);
1187 switch(arg_type
[0]) {
1190 ret
= get_errno(ioctl(fd
, ie
->host_cmd
));
1195 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, arg
));
1199 target_size
= thunk_type_size(arg_type
, 0);
1200 switch(ie
->access
) {
1202 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, buf_temp
));
1203 if (!is_error(ret
)) {
1204 argptr
= lock_user(arg
, target_size
, 0);
1205 thunk_convert(argptr
, buf_temp
, arg_type
, THUNK_TARGET
);
1206 unlock_user(argptr
, arg
, target_size
);
1210 argptr
= lock_user(arg
, target_size
, 1);
1211 thunk_convert(buf_temp
, argptr
, arg_type
, THUNK_HOST
);
1212 unlock_user(argptr
, arg
, 0);
1213 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, buf_temp
));
1217 argptr
= lock_user(arg
, target_size
, 1);
1218 thunk_convert(buf_temp
, argptr
, arg_type
, THUNK_HOST
);
1219 unlock_user(argptr
, arg
, 0);
1220 ret
= get_errno(ioctl(fd
, ie
->host_cmd
, buf_temp
));
1221 if (!is_error(ret
)) {
1222 argptr
= lock_user(arg
, target_size
, 0);
1223 thunk_convert(argptr
, buf_temp
, arg_type
, THUNK_TARGET
);
1224 unlock_user(argptr
, arg
, target_size
);
1230 gemu_log("Unsupported ioctl type: cmd=0x%04lx type=%d\n", cmd
, arg_type
[0]);
1237 bitmask_transtbl iflag_tbl
[] = {
1238 { TARGET_IGNBRK
, TARGET_IGNBRK
, IGNBRK
, IGNBRK
},
1239 { TARGET_BRKINT
, TARGET_BRKINT
, BRKINT
, BRKINT
},
1240 { TARGET_IGNPAR
, TARGET_IGNPAR
, IGNPAR
, IGNPAR
},
1241 { TARGET_PARMRK
, TARGET_PARMRK
, PARMRK
, PARMRK
},
1242 { TARGET_INPCK
, TARGET_INPCK
, INPCK
, INPCK
},
1243 { TARGET_ISTRIP
, TARGET_ISTRIP
, ISTRIP
, ISTRIP
},
1244 { TARGET_INLCR
, TARGET_INLCR
, INLCR
, INLCR
},
1245 { TARGET_IGNCR
, TARGET_IGNCR
, IGNCR
, IGNCR
},
1246 { TARGET_ICRNL
, TARGET_ICRNL
, ICRNL
, ICRNL
},
1247 { TARGET_IUCLC
, TARGET_IUCLC
, IUCLC
, IUCLC
},
1248 { TARGET_IXON
, TARGET_IXON
, IXON
, IXON
},
1249 { TARGET_IXANY
, TARGET_IXANY
, IXANY
, IXANY
},
1250 { TARGET_IXOFF
, TARGET_IXOFF
, IXOFF
, IXOFF
},
1251 { TARGET_IMAXBEL
, TARGET_IMAXBEL
, IMAXBEL
, IMAXBEL
},
1255 bitmask_transtbl oflag_tbl
[] = {
1256 { TARGET_OPOST
, TARGET_OPOST
, OPOST
, OPOST
},
1257 { TARGET_OLCUC
, TARGET_OLCUC
, OLCUC
, OLCUC
},
1258 { TARGET_ONLCR
, TARGET_ONLCR
, ONLCR
, ONLCR
},
1259 { TARGET_OCRNL
, TARGET_OCRNL
, OCRNL
, OCRNL
},
1260 { TARGET_ONOCR
, TARGET_ONOCR
, ONOCR
, ONOCR
},
1261 { TARGET_ONLRET
, TARGET_ONLRET
, ONLRET
, ONLRET
},
1262 { TARGET_OFILL
, TARGET_OFILL
, OFILL
, OFILL
},
1263 { TARGET_OFDEL
, TARGET_OFDEL
, OFDEL
, OFDEL
},
1264 { TARGET_NLDLY
, TARGET_NL0
, NLDLY
, NL0
},
1265 { TARGET_NLDLY
, TARGET_NL1
, NLDLY
, NL1
},
1266 { TARGET_CRDLY
, TARGET_CR0
, CRDLY
, CR0
},
1267 { TARGET_CRDLY
, TARGET_CR1
, CRDLY
, CR1
},
1268 { TARGET_CRDLY
, TARGET_CR2
, CRDLY
, CR2
},
1269 { TARGET_CRDLY
, TARGET_CR3
, CRDLY
, CR3
},
1270 { TARGET_TABDLY
, TARGET_TAB0
, TABDLY
, TAB0
},
1271 { TARGET_TABDLY
, TARGET_TAB1
, TABDLY
, TAB1
},
1272 { TARGET_TABDLY
, TARGET_TAB2
, TABDLY
, TAB2
},
1273 { TARGET_TABDLY
, TARGET_TAB3
, TABDLY
, TAB3
},
1274 { TARGET_BSDLY
, TARGET_BS0
, BSDLY
, BS0
},
1275 { TARGET_BSDLY
, TARGET_BS1
, BSDLY
, BS1
},
1276 { TARGET_VTDLY
, TARGET_VT0
, VTDLY
, VT0
},
1277 { TARGET_VTDLY
, TARGET_VT1
, VTDLY
, VT1
},
1278 { TARGET_FFDLY
, TARGET_FF0
, FFDLY
, FF0
},
1279 { TARGET_FFDLY
, TARGET_FF1
, FFDLY
, FF1
},
1283 bitmask_transtbl cflag_tbl
[] = {
1284 { TARGET_CBAUD
, TARGET_B0
, CBAUD
, B0
},
1285 { TARGET_CBAUD
, TARGET_B50
, CBAUD
, B50
},
1286 { TARGET_CBAUD
, TARGET_B75
, CBAUD
, B75
},
1287 { TARGET_CBAUD
, TARGET_B110
, CBAUD
, B110
},
1288 { TARGET_CBAUD
, TARGET_B134
, CBAUD
, B134
},
1289 { TARGET_CBAUD
, TARGET_B150
, CBAUD
, B150
},
1290 { TARGET_CBAUD
, TARGET_B200
, CBAUD
, B200
},
1291 { TARGET_CBAUD
, TARGET_B300
, CBAUD
, B300
},
1292 { TARGET_CBAUD
, TARGET_B600
, CBAUD
, B600
},
1293 { TARGET_CBAUD
, TARGET_B1200
, CBAUD
, B1200
},
1294 { TARGET_CBAUD
, TARGET_B1800
, CBAUD
, B1800
},
1295 { TARGET_CBAUD
, TARGET_B2400
, CBAUD
, B2400
},
1296 { TARGET_CBAUD
, TARGET_B4800
, CBAUD
, B4800
},
1297 { TARGET_CBAUD
, TARGET_B9600
, CBAUD
, B9600
},
1298 { TARGET_CBAUD
, TARGET_B19200
, CBAUD
, B19200
},
1299 { TARGET_CBAUD
, TARGET_B38400
, CBAUD
, B38400
},
1300 { TARGET_CBAUD
, TARGET_B57600
, CBAUD
, B57600
},
1301 { TARGET_CBAUD
, TARGET_B115200
, CBAUD
, B115200
},
1302 { TARGET_CBAUD
, TARGET_B230400
, CBAUD
, B230400
},
1303 { TARGET_CBAUD
, TARGET_B460800
, CBAUD
, B460800
},
1304 { TARGET_CSIZE
, TARGET_CS5
, CSIZE
, CS5
},
1305 { TARGET_CSIZE
, TARGET_CS6
, CSIZE
, CS6
},
1306 { TARGET_CSIZE
, TARGET_CS7
, CSIZE
, CS7
},
1307 { TARGET_CSIZE
, TARGET_CS8
, CSIZE
, CS8
},
1308 { TARGET_CSTOPB
, TARGET_CSTOPB
, CSTOPB
, CSTOPB
},
1309 { TARGET_CREAD
, TARGET_CREAD
, CREAD
, CREAD
},
1310 { TARGET_PARENB
, TARGET_PARENB
, PARENB
, PARENB
},
1311 { TARGET_PARODD
, TARGET_PARODD
, PARODD
, PARODD
},
1312 { TARGET_HUPCL
, TARGET_HUPCL
, HUPCL
, HUPCL
},
1313 { TARGET_CLOCAL
, TARGET_CLOCAL
, CLOCAL
, CLOCAL
},
1314 { TARGET_CRTSCTS
, TARGET_CRTSCTS
, CRTSCTS
, CRTSCTS
},
1318 bitmask_transtbl lflag_tbl
[] = {
1319 { TARGET_ISIG
, TARGET_ISIG
, ISIG
, ISIG
},
1320 { TARGET_ICANON
, TARGET_ICANON
, ICANON
, ICANON
},
1321 { TARGET_XCASE
, TARGET_XCASE
, XCASE
, XCASE
},
1322 { TARGET_ECHO
, TARGET_ECHO
, ECHO
, ECHO
},
1323 { TARGET_ECHOE
, TARGET_ECHOE
, ECHOE
, ECHOE
},
1324 { TARGET_ECHOK
, TARGET_ECHOK
, ECHOK
, ECHOK
},
1325 { TARGET_ECHONL
, TARGET_ECHONL
, ECHONL
, ECHONL
},
1326 { TARGET_NOFLSH
, TARGET_NOFLSH
, NOFLSH
, NOFLSH
},
1327 { TARGET_TOSTOP
, TARGET_TOSTOP
, TOSTOP
, TOSTOP
},
1328 { TARGET_ECHOCTL
, TARGET_ECHOCTL
, ECHOCTL
, ECHOCTL
},
1329 { TARGET_ECHOPRT
, TARGET_ECHOPRT
, ECHOPRT
, ECHOPRT
},
1330 { TARGET_ECHOKE
, TARGET_ECHOKE
, ECHOKE
, ECHOKE
},
1331 { TARGET_FLUSHO
, TARGET_FLUSHO
, FLUSHO
, FLUSHO
},
1332 { TARGET_PENDIN
, TARGET_PENDIN
, PENDIN
, PENDIN
},
1333 { TARGET_IEXTEN
, TARGET_IEXTEN
, IEXTEN
, IEXTEN
},
1337 static void target_to_host_termios (void *dst
, const void *src
)
1339 struct host_termios
*host
= dst
;
1340 const struct target_termios
*target
= src
;
1343 target_to_host_bitmask(tswap32(target
->c_iflag
), iflag_tbl
);
1345 target_to_host_bitmask(tswap32(target
->c_oflag
), oflag_tbl
);
1347 target_to_host_bitmask(tswap32(target
->c_cflag
), cflag_tbl
);
1349 target_to_host_bitmask(tswap32(target
->c_lflag
), lflag_tbl
);
1350 host
->c_line
= target
->c_line
;
1352 host
->c_cc
[VINTR
] = target
->c_cc
[TARGET_VINTR
];
1353 host
->c_cc
[VQUIT
] = target
->c_cc
[TARGET_VQUIT
];
1354 host
->c_cc
[VERASE
] = target
->c_cc
[TARGET_VERASE
];
1355 host
->c_cc
[VKILL
] = target
->c_cc
[TARGET_VKILL
];
1356 host
->c_cc
[VEOF
] = target
->c_cc
[TARGET_VEOF
];
1357 host
->c_cc
[VTIME
] = target
->c_cc
[TARGET_VTIME
];
1358 host
->c_cc
[VMIN
] = target
->c_cc
[TARGET_VMIN
];
1359 host
->c_cc
[VSWTC
] = target
->c_cc
[TARGET_VSWTC
];
1360 host
->c_cc
[VSTART
] = target
->c_cc
[TARGET_VSTART
];
1361 host
->c_cc
[VSTOP
] = target
->c_cc
[TARGET_VSTOP
];
1362 host
->c_cc
[VSUSP
] = target
->c_cc
[TARGET_VSUSP
];
1363 host
->c_cc
[VEOL
] = target
->c_cc
[TARGET_VEOL
];
1364 host
->c_cc
[VREPRINT
] = target
->c_cc
[TARGET_VREPRINT
];
1365 host
->c_cc
[VDISCARD
] = target
->c_cc
[TARGET_VDISCARD
];
1366 host
->c_cc
[VWERASE
] = target
->c_cc
[TARGET_VWERASE
];
1367 host
->c_cc
[VLNEXT
] = target
->c_cc
[TARGET_VLNEXT
];
1368 host
->c_cc
[VEOL2
] = target
->c_cc
[TARGET_VEOL2
];
1371 static void host_to_target_termios (void *dst
, const void *src
)
1373 struct target_termios
*target
= dst
;
1374 const struct host_termios
*host
= src
;
1377 tswap32(host_to_target_bitmask(host
->c_iflag
, iflag_tbl
));
1379 tswap32(host_to_target_bitmask(host
->c_oflag
, oflag_tbl
));
1381 tswap32(host_to_target_bitmask(host
->c_cflag
, cflag_tbl
));
1383 tswap32(host_to_target_bitmask(host
->c_lflag
, lflag_tbl
));
1384 target
->c_line
= host
->c_line
;
1386 target
->c_cc
[TARGET_VINTR
] = host
->c_cc
[VINTR
];
1387 target
->c_cc
[TARGET_VQUIT
] = host
->c_cc
[VQUIT
];
1388 target
->c_cc
[TARGET_VERASE
] = host
->c_cc
[VERASE
];
1389 target
->c_cc
[TARGET_VKILL
] = host
->c_cc
[VKILL
];
1390 target
->c_cc
[TARGET_VEOF
] = host
->c_cc
[VEOF
];
1391 target
->c_cc
[TARGET_VTIME
] = host
->c_cc
[VTIME
];
1392 target
->c_cc
[TARGET_VMIN
] = host
->c_cc
[VMIN
];
1393 target
->c_cc
[TARGET_VSWTC
] = host
->c_cc
[VSWTC
];
1394 target
->c_cc
[TARGET_VSTART
] = host
->c_cc
[VSTART
];
1395 target
->c_cc
[TARGET_VSTOP
] = host
->c_cc
[VSTOP
];
1396 target
->c_cc
[TARGET_VSUSP
] = host
->c_cc
[VSUSP
];
1397 target
->c_cc
[TARGET_VEOL
] = host
->c_cc
[VEOL
];
1398 target
->c_cc
[TARGET_VREPRINT
] = host
->c_cc
[VREPRINT
];
1399 target
->c_cc
[TARGET_VDISCARD
] = host
->c_cc
[VDISCARD
];
1400 target
->c_cc
[TARGET_VWERASE
] = host
->c_cc
[VWERASE
];
1401 target
->c_cc
[TARGET_VLNEXT
] = host
->c_cc
[VLNEXT
];
1402 target
->c_cc
[TARGET_VEOL2
] = host
->c_cc
[VEOL2
];
1405 StructEntry struct_termios_def
= {
1406 .convert
= { host_to_target_termios
, target_to_host_termios
},
1407 .size
= { sizeof(struct target_termios
), sizeof(struct host_termios
) },
1408 .align
= { __alignof__(struct target_termios
), __alignof__(struct host_termios
) },
1411 static bitmask_transtbl mmap_flags_tbl
[] = {
1412 { TARGET_MAP_SHARED
, TARGET_MAP_SHARED
, MAP_SHARED
, MAP_SHARED
},
1413 { TARGET_MAP_PRIVATE
, TARGET_MAP_PRIVATE
, MAP_PRIVATE
, MAP_PRIVATE
},
1414 { TARGET_MAP_FIXED
, TARGET_MAP_FIXED
, MAP_FIXED
, MAP_FIXED
},
1415 { TARGET_MAP_ANONYMOUS
, TARGET_MAP_ANONYMOUS
, MAP_ANONYMOUS
, MAP_ANONYMOUS
},
1416 { TARGET_MAP_GROWSDOWN
, TARGET_MAP_GROWSDOWN
, MAP_GROWSDOWN
, MAP_GROWSDOWN
},
1417 { TARGET_MAP_DENYWRITE
, TARGET_MAP_DENYWRITE
, MAP_DENYWRITE
, MAP_DENYWRITE
},
1418 { TARGET_MAP_EXECUTABLE
, TARGET_MAP_EXECUTABLE
, MAP_EXECUTABLE
, MAP_EXECUTABLE
},
1419 { TARGET_MAP_LOCKED
, TARGET_MAP_LOCKED
, MAP_LOCKED
, MAP_LOCKED
},
1423 static bitmask_transtbl fcntl_flags_tbl
[] = {
1424 { TARGET_O_ACCMODE
, TARGET_O_WRONLY
, O_ACCMODE
, O_WRONLY
, },
1425 { TARGET_O_ACCMODE
, TARGET_O_RDWR
, O_ACCMODE
, O_RDWR
, },
1426 { TARGET_O_CREAT
, TARGET_O_CREAT
, O_CREAT
, O_CREAT
, },
1427 { TARGET_O_EXCL
, TARGET_O_EXCL
, O_EXCL
, O_EXCL
, },
1428 { TARGET_O_NOCTTY
, TARGET_O_NOCTTY
, O_NOCTTY
, O_NOCTTY
, },
1429 { TARGET_O_TRUNC
, TARGET_O_TRUNC
, O_TRUNC
, O_TRUNC
, },
1430 { TARGET_O_APPEND
, TARGET_O_APPEND
, O_APPEND
, O_APPEND
, },
1431 { TARGET_O_NONBLOCK
, TARGET_O_NONBLOCK
, O_NONBLOCK
, O_NONBLOCK
, },
1432 { TARGET_O_SYNC
, TARGET_O_SYNC
, O_SYNC
, O_SYNC
, },
1433 { TARGET_FASYNC
, TARGET_FASYNC
, FASYNC
, FASYNC
, },
1434 { TARGET_O_DIRECTORY
, TARGET_O_DIRECTORY
, O_DIRECTORY
, O_DIRECTORY
, },
1435 { TARGET_O_NOFOLLOW
, TARGET_O_NOFOLLOW
, O_NOFOLLOW
, O_NOFOLLOW
, },
1436 { TARGET_O_LARGEFILE
, TARGET_O_LARGEFILE
, O_LARGEFILE
, O_LARGEFILE
, },
1437 #if defined(O_DIRECT)
1438 { TARGET_O_DIRECT
, TARGET_O_DIRECT
, O_DIRECT
, O_DIRECT
, },
1443 #if defined(TARGET_I386)
1445 /* NOTE: there is really one LDT for all the threads */
1448 static int read_ldt(target_ulong ptr
, unsigned long bytecount
)
1455 size
= TARGET_LDT_ENTRIES
* TARGET_LDT_ENTRY_SIZE
;
1456 if (size
> bytecount
)
1458 p
= lock_user(ptr
, size
, 0);
1459 /* ??? Shoudl this by byteswapped? */
1460 memcpy(p
, ldt_table
, size
);
1461 unlock_user(p
, ptr
, size
);
1465 /* XXX: add locking support */
1466 static int write_ldt(CPUX86State
*env
,
1467 target_ulong ptr
, unsigned long bytecount
, int oldmode
)
1469 struct target_modify_ldt_ldt_s ldt_info
;
1470 struct target_modify_ldt_ldt_s
*target_ldt_info
;
1471 int seg_32bit
, contents
, read_exec_only
, limit_in_pages
;
1472 int seg_not_present
, useable
;
1473 uint32_t *lp
, entry_1
, entry_2
;
1475 if (bytecount
!= sizeof(ldt_info
))
1477 lock_user_struct(target_ldt_info
, ptr
, 1);
1478 ldt_info
.entry_number
= tswap32(target_ldt_info
->entry_number
);
1479 ldt_info
.base_addr
= tswapl(target_ldt_info
->base_addr
);
1480 ldt_info
.limit
= tswap32(target_ldt_info
->limit
);
1481 ldt_info
.flags
= tswap32(target_ldt_info
->flags
);
1482 unlock_user_struct(target_ldt_info
, ptr
, 0);
1484 if (ldt_info
.entry_number
>= TARGET_LDT_ENTRIES
)
1486 seg_32bit
= ldt_info
.flags
& 1;
1487 contents
= (ldt_info
.flags
>> 1) & 3;
1488 read_exec_only
= (ldt_info
.flags
>> 3) & 1;
1489 limit_in_pages
= (ldt_info
.flags
>> 4) & 1;
1490 seg_not_present
= (ldt_info
.flags
>> 5) & 1;
1491 useable
= (ldt_info
.flags
>> 6) & 1;
1493 if (contents
== 3) {
1496 if (seg_not_present
== 0)
1499 /* allocate the LDT */
1501 ldt_table
= malloc(TARGET_LDT_ENTRIES
* TARGET_LDT_ENTRY_SIZE
);
1504 memset(ldt_table
, 0, TARGET_LDT_ENTRIES
* TARGET_LDT_ENTRY_SIZE
);
1505 env
->ldt
.base
= h2g(ldt_table
);
1506 env
->ldt
.limit
= 0xffff;
1509 /* NOTE: same code as Linux kernel */
1510 /* Allow LDTs to be cleared by the user. */
1511 if (ldt_info
.base_addr
== 0 && ldt_info
.limit
== 0) {
1514 read_exec_only
== 1 &&
1516 limit_in_pages
== 0 &&
1517 seg_not_present
== 1 &&
1525 entry_1
= ((ldt_info
.base_addr
& 0x0000ffff) << 16) |
1526 (ldt_info
.limit
& 0x0ffff);
1527 entry_2
= (ldt_info
.base_addr
& 0xff000000) |
1528 ((ldt_info
.base_addr
& 0x00ff0000) >> 16) |
1529 (ldt_info
.limit
& 0xf0000) |
1530 ((read_exec_only
^ 1) << 9) |
1532 ((seg_not_present
^ 1) << 15) |
1534 (limit_in_pages
<< 23) |
1537 entry_2
|= (useable
<< 20);
1539 /* Install the new entry ... */
1541 lp
= (uint32_t *)(ldt_table
+ (ldt_info
.entry_number
<< 3));
1542 lp
[0] = tswap32(entry_1
);
1543 lp
[1] = tswap32(entry_2
);
1547 /* specific and weird i386 syscalls */
1548 int do_modify_ldt(CPUX86State
*env
, int func
, target_ulong ptr
, unsigned long bytecount
)
1554 ret
= read_ldt(ptr
, bytecount
);
1557 ret
= write_ldt(env
, ptr
, bytecount
, 1);
1560 ret
= write_ldt(env
, ptr
, bytecount
, 0);
1566 #endif /* defined(TARGET_I386) */
1568 /* this stack is the equivalent of the kernel stack associated with a
1570 #define NEW_STACK_SIZE 8192
1572 static int clone_func(void *arg
)
1574 CPUState
*env
= arg
;
1580 int do_fork(CPUState
*env
, unsigned int flags
, unsigned long newsp
)
1587 if (flags
& CLONE_VM
) {
1588 ts
= malloc(sizeof(TaskState
) + NEW_STACK_SIZE
);
1589 memset(ts
, 0, sizeof(TaskState
));
1590 new_stack
= ts
->stack
;
1592 /* add in task state list */
1593 ts
->next
= first_task_state
;
1594 first_task_state
= ts
;
1595 /* we create a new CPU instance. */
1596 new_env
= cpu_init();
1597 memcpy(new_env
, env
, sizeof(CPUState
));
1598 #if defined(TARGET_I386)
1600 newsp
= env
->regs
[R_ESP
];
1601 new_env
->regs
[R_ESP
] = newsp
;
1602 new_env
->regs
[R_EAX
] = 0;
1603 #elif defined(TARGET_ARM)
1605 newsp
= env
->regs
[13];
1606 new_env
->regs
[13] = newsp
;
1607 new_env
->regs
[0] = 0;
1608 #elif defined(TARGET_SPARC)
1609 printf ("HELPME: %s:%d\n", __FILE__
, __LINE__
);
1610 #elif defined(TARGET_MIPS)
1611 printf ("HELPME: %s:%d\n", __FILE__
, __LINE__
);
1612 #elif defined(TARGET_PPC)
1614 newsp
= env
->gpr
[1];
1615 new_env
->gpr
[1] = newsp
;
1618 for (i
= 7; i
< 32; i
++)
1619 new_env
->gpr
[i
] = 0;
1622 #error unsupported target CPU
1624 new_env
->opaque
= ts
;
1626 ret
= clone2(clone_func
, new_stack
+ NEW_STACK_SIZE
, flags
, new_env
);
1628 ret
= clone(clone_func
, new_stack
+ NEW_STACK_SIZE
, flags
, new_env
);
1631 /* if no CLONE_VM, we consider it is a fork */
1632 if ((flags
& ~CSIGNAL
) != 0)
1639 static long do_fcntl(int fd
, int cmd
, target_ulong arg
)
1642 struct target_flock
*target_fl
;
1646 case TARGET_F_GETLK
:
1647 ret
= fcntl(fd
, cmd
, &fl
);
1649 lock_user_struct(target_fl
, arg
, 0);
1650 target_fl
->l_type
= tswap16(fl
.l_type
);
1651 target_fl
->l_whence
= tswap16(fl
.l_whence
);
1652 target_fl
->l_start
= tswapl(fl
.l_start
);
1653 target_fl
->l_len
= tswapl(fl
.l_len
);
1654 target_fl
->l_pid
= tswapl(fl
.l_pid
);
1655 unlock_user_struct(target_fl
, arg
, 1);
1659 case TARGET_F_SETLK
:
1660 case TARGET_F_SETLKW
:
1661 lock_user_struct(target_fl
, arg
, 1);
1662 fl
.l_type
= tswap16(target_fl
->l_type
);
1663 fl
.l_whence
= tswap16(target_fl
->l_whence
);
1664 fl
.l_start
= tswapl(target_fl
->l_start
);
1665 fl
.l_len
= tswapl(target_fl
->l_len
);
1666 fl
.l_pid
= tswapl(target_fl
->l_pid
);
1667 unlock_user_struct(target_fl
, arg
, 0);
1668 ret
= fcntl(fd
, cmd
, &fl
);
1671 case TARGET_F_GETLK64
:
1672 case TARGET_F_SETLK64
:
1673 case TARGET_F_SETLKW64
:
1679 ret
= fcntl(fd
, cmd
, arg
);
1680 ret
= host_to_target_bitmask(ret
, fcntl_flags_tbl
);
1684 ret
= fcntl(fd
, cmd
, target_to_host_bitmask(arg
, fcntl_flags_tbl
));
1688 ret
= fcntl(fd
, cmd
, arg
);
1696 static inline int high2lowuid(int uid
)
1704 static inline int high2lowgid(int gid
)
1712 static inline int low2highuid(int uid
)
1714 if ((int16_t)uid
== -1)
1720 static inline int low2highgid(int gid
)
1722 if ((int16_t)gid
== -1)
1728 #endif /* USE_UID16 */
1730 void syscall_init(void)
1733 const argtype
*arg_type
;
1736 #define STRUCT(name, list...) thunk_register_struct(STRUCT_ ## name, #name, struct_ ## name ## _def);
1737 #define STRUCT_SPECIAL(name) thunk_register_struct_direct(STRUCT_ ## name, #name, &struct_ ## name ## _def);
1738 #include "syscall_types.h"
1740 #undef STRUCT_SPECIAL
1742 /* we patch the ioctl size if necessary. We rely on the fact that
1743 no ioctl has all the bits at '1' in the size field */
1745 while (ie
->target_cmd
!= 0) {
1746 if (((ie
->target_cmd
>> TARGET_IOC_SIZESHIFT
) & TARGET_IOC_SIZEMASK
) ==
1747 TARGET_IOC_SIZEMASK
) {
1748 arg_type
= ie
->arg_type
;
1749 if (arg_type
[0] != TYPE_PTR
) {
1750 fprintf(stderr
, "cannot patch size for ioctl 0x%x\n",
1755 size
= thunk_type_size(arg_type
, 0);
1756 ie
->target_cmd
= (ie
->target_cmd
&
1757 ~(TARGET_IOC_SIZEMASK
<< TARGET_IOC_SIZESHIFT
)) |
1758 (size
<< TARGET_IOC_SIZESHIFT
);
1760 /* automatic consistency check if same arch */
1761 #if defined(__i386__) && defined(TARGET_I386)
1762 if (ie
->target_cmd
!= ie
->host_cmd
) {
1763 fprintf(stderr
, "ERROR: ioctl: target=0x%x host=0x%x\n",
1764 ie
->target_cmd
, ie
->host_cmd
);
1771 static inline uint64_t target_offset64(uint32_t word0
, uint32_t word1
)
1773 #ifdef TARGET_WORDS_BIG_ENDIAN
1774 return ((uint64_t)word0
<< 32) | word1
;
1776 return ((uint64_t)word1
<< 32) | word0
;
1780 #ifdef TARGET_NR_truncate64
1781 static inline long target_truncate64(void *cpu_env
, const char *arg1
,
1782 long arg2
, long arg3
, long arg4
)
1785 if (((CPUARMState
*)cpu_env
)->eabi
)
1791 return get_errno(truncate64(arg1
, target_offset64(arg2
, arg3
)));
1795 #ifdef TARGET_NR_ftruncate64
1796 static inline long target_ftruncate64(void *cpu_env
, long arg1
, long arg2
,
1797 long arg3
, long arg4
)
1800 if (((CPUARMState
*)cpu_env
)->eabi
)
1806 return get_errno(ftruncate64(arg1
, target_offset64(arg2
, arg3
)));
1810 static inline void target_to_host_timespec(struct timespec
*host_ts
,
1811 target_ulong target_addr
)
1813 struct target_timespec
*target_ts
;
1815 lock_user_struct(target_ts
, target_addr
, 1);
1816 host_ts
->tv_sec
= tswapl(target_ts
->tv_sec
);
1817 host_ts
->tv_nsec
= tswapl(target_ts
->tv_nsec
);
1818 unlock_user_struct(target_ts
, target_addr
, 0);
1821 static inline void host_to_target_timespec(target_ulong target_addr
,
1822 struct timespec
*host_ts
)
1824 struct target_timespec
*target_ts
;
1826 lock_user_struct(target_ts
, target_addr
, 0);
1827 target_ts
->tv_sec
= tswapl(host_ts
->tv_sec
);
1828 target_ts
->tv_nsec
= tswapl(host_ts
->tv_nsec
);
1829 unlock_user_struct(target_ts
, target_addr
, 1);
1832 long do_syscall(void *cpu_env
, int num
, long arg1
, long arg2
, long arg3
,
1833 long arg4
, long arg5
, long arg6
)
1841 gemu_log("syscall %d", num
);
1844 case TARGET_NR_exit
:
1848 gdb_exit(cpu_env
, arg1
);
1849 /* XXX: should free thread stack and CPU env */
1851 ret
= 0; /* avoid warning */
1853 case TARGET_NR_read
:
1854 page_unprotect_range(arg2
, arg3
);
1855 p
= lock_user(arg2
, arg3
, 0);
1856 ret
= get_errno(read(arg1
, p
, arg3
));
1857 unlock_user(p
, arg2
, ret
);
1859 case TARGET_NR_write
:
1860 p
= lock_user(arg2
, arg3
, 1);
1861 ret
= get_errno(write(arg1
, p
, arg3
));
1862 unlock_user(p
, arg2
, 0);
1864 case TARGET_NR_open
:
1865 p
= lock_user_string(arg1
);
1866 ret
= get_errno(open(path(p
),
1867 target_to_host_bitmask(arg2
, fcntl_flags_tbl
),
1869 unlock_user(p
, arg1
, 0);
1871 case TARGET_NR_close
:
1872 ret
= get_errno(close(arg1
));
1877 case TARGET_NR_fork
:
1878 ret
= get_errno(do_fork(cpu_env
, SIGCHLD
, 0));
1880 case TARGET_NR_waitpid
:
1883 ret
= get_errno(waitpid(arg1
, &status
, arg3
));
1884 if (!is_error(ret
) && arg2
)
1885 tput32(arg2
, status
);
1888 case TARGET_NR_creat
:
1889 p
= lock_user_string(arg1
);
1890 ret
= get_errno(creat(p
, arg2
));
1891 unlock_user(p
, arg1
, 0);
1893 case TARGET_NR_link
:
1896 p
= lock_user_string(arg1
);
1897 p2
= lock_user_string(arg2
);
1898 ret
= get_errno(link(p
, p2
));
1899 unlock_user(p2
, arg2
, 0);
1900 unlock_user(p
, arg1
, 0);
1903 case TARGET_NR_unlink
:
1904 p
= lock_user_string(arg1
);
1905 ret
= get_errno(unlink(p
));
1906 unlock_user(p
, arg1
, 0);
1908 case TARGET_NR_execve
:
1910 char **argp
, **envp
;
1913 target_ulong guest_argp
;
1914 target_ulong guest_envp
;
1920 for (gp
= guest_argp
; tgetl(gp
); gp
++)
1924 for (gp
= guest_envp
; tgetl(gp
); gp
++)
1927 argp
= alloca((argc
+ 1) * sizeof(void *));
1928 envp
= alloca((envc
+ 1) * sizeof(void *));
1930 for (gp
= guest_argp
, q
= argp
; ;
1931 gp
+= sizeof(target_ulong
), q
++) {
1935 *q
= lock_user_string(addr
);
1939 for (gp
= guest_envp
, q
= envp
; ;
1940 gp
+= sizeof(target_ulong
), q
++) {
1944 *q
= lock_user_string(addr
);
1948 p
= lock_user_string(arg1
);
1949 ret
= get_errno(execve(p
, argp
, envp
));
1950 unlock_user(p
, arg1
, 0);
1952 for (gp
= guest_argp
, q
= argp
; *q
;
1953 gp
+= sizeof(target_ulong
), q
++) {
1955 unlock_user(*q
, addr
, 0);
1957 for (gp
= guest_envp
, q
= envp
; *q
;
1958 gp
+= sizeof(target_ulong
), q
++) {
1960 unlock_user(*q
, addr
, 0);
1964 case TARGET_NR_chdir
:
1965 p
= lock_user_string(arg1
);
1966 ret
= get_errno(chdir(p
));
1967 unlock_user(p
, arg1
, 0);
1969 #ifdef TARGET_NR_time
1970 case TARGET_NR_time
:
1973 ret
= get_errno(time(&host_time
));
1974 if (!is_error(ret
) && arg1
)
1975 tputl(arg1
, host_time
);
1979 case TARGET_NR_mknod
:
1980 p
= lock_user_string(arg1
);
1981 ret
= get_errno(mknod(p
, arg2
, arg3
));
1982 unlock_user(p
, arg1
, 0);
1984 case TARGET_NR_chmod
:
1985 p
= lock_user_string(arg1
);
1986 ret
= get_errno(chmod(p
, arg2
));
1987 unlock_user(p
, arg1
, 0);
1989 #ifdef TARGET_NR_break
1990 case TARGET_NR_break
:
1993 #ifdef TARGET_NR_oldstat
1994 case TARGET_NR_oldstat
:
1997 case TARGET_NR_lseek
:
1998 ret
= get_errno(lseek(arg1
, arg2
, arg3
));
2000 case TARGET_NR_getpid
:
2001 ret
= get_errno(getpid());
2003 case TARGET_NR_mount
:
2004 /* need to look at the data field */
2006 case TARGET_NR_umount
:
2007 p
= lock_user_string(arg1
);
2008 ret
= get_errno(umount(p
));
2009 unlock_user(p
, arg1
, 0);
2011 case TARGET_NR_stime
:
2014 host_time
= tgetl(arg1
);
2015 ret
= get_errno(stime(&host_time
));
2018 case TARGET_NR_ptrace
:
2020 case TARGET_NR_alarm
:
2023 #ifdef TARGET_NR_oldfstat
2024 case TARGET_NR_oldfstat
:
2027 case TARGET_NR_pause
:
2028 ret
= get_errno(pause());
2030 case TARGET_NR_utime
:
2032 struct utimbuf tbuf
, *host_tbuf
;
2033 struct target_utimbuf
*target_tbuf
;
2035 lock_user_struct(target_tbuf
, arg2
, 1);
2036 tbuf
.actime
= tswapl(target_tbuf
->actime
);
2037 tbuf
.modtime
= tswapl(target_tbuf
->modtime
);
2038 unlock_user_struct(target_tbuf
, arg2
, 0);
2043 p
= lock_user_string(arg1
);
2044 ret
= get_errno(utime(p
, host_tbuf
));
2045 unlock_user(p
, arg1
, 0);
2048 case TARGET_NR_utimes
:
2050 struct timeval
*tvp
, tv
[2];
2052 target_to_host_timeval(&tv
[0], arg2
);
2053 target_to_host_timeval(&tv
[1],
2054 arg2
+ sizeof (struct target_timeval
));
2059 p
= lock_user_string(arg1
);
2060 ret
= get_errno(utimes(p
, tvp
));
2061 unlock_user(p
, arg1
, 0);
2064 #ifdef TARGET_NR_stty
2065 case TARGET_NR_stty
:
2068 #ifdef TARGET_NR_gtty
2069 case TARGET_NR_gtty
:
2072 case TARGET_NR_access
:
2073 p
= lock_user_string(arg1
);
2074 ret
= get_errno(access(p
, arg2
));
2075 unlock_user(p
, arg1
, 0);
2077 case TARGET_NR_nice
:
2078 ret
= get_errno(nice(arg1
));
2080 #ifdef TARGET_NR_ftime
2081 case TARGET_NR_ftime
:
2084 case TARGET_NR_sync
:
2088 case TARGET_NR_kill
:
2089 ret
= get_errno(kill(arg1
, arg2
));
2091 case TARGET_NR_rename
:
2094 p
= lock_user_string(arg1
);
2095 p2
= lock_user_string(arg2
);
2096 ret
= get_errno(rename(p
, p2
));
2097 unlock_user(p2
, arg2
, 0);
2098 unlock_user(p
, arg1
, 0);
2101 case TARGET_NR_mkdir
:
2102 p
= lock_user_string(arg1
);
2103 ret
= get_errno(mkdir(p
, arg2
));
2104 unlock_user(p
, arg1
, 0);
2106 case TARGET_NR_rmdir
:
2107 p
= lock_user_string(arg1
);
2108 ret
= get_errno(rmdir(p
));
2109 unlock_user(p
, arg1
, 0);
2112 ret
= get_errno(dup(arg1
));
2114 case TARGET_NR_pipe
:
2117 ret
= get_errno(pipe(host_pipe
));
2118 if (!is_error(ret
)) {
2119 tput32(arg1
, host_pipe
[0]);
2120 tput32(arg1
+ 4, host_pipe
[1]);
2124 case TARGET_NR_times
:
2126 struct target_tms
*tmsp
;
2128 ret
= get_errno(times(&tms
));
2130 tmsp
= lock_user(arg1
, sizeof(struct target_tms
), 0);
2131 tmsp
->tms_utime
= tswapl(host_to_target_clock_t(tms
.tms_utime
));
2132 tmsp
->tms_stime
= tswapl(host_to_target_clock_t(tms
.tms_stime
));
2133 tmsp
->tms_cutime
= tswapl(host_to_target_clock_t(tms
.tms_cutime
));
2134 tmsp
->tms_cstime
= tswapl(host_to_target_clock_t(tms
.tms_cstime
));
2137 ret
= host_to_target_clock_t(ret
);
2140 #ifdef TARGET_NR_prof
2141 case TARGET_NR_prof
:
2144 case TARGET_NR_signal
:
2147 case TARGET_NR_acct
:
2149 case TARGET_NR_umount2
:
2150 p
= lock_user_string(arg1
);
2151 ret
= get_errno(umount2(p
, arg2
));
2152 unlock_user(p
, arg1
, 0);
2154 #ifdef TARGET_NR_lock
2155 case TARGET_NR_lock
:
2158 case TARGET_NR_ioctl
:
2159 ret
= do_ioctl(arg1
, arg2
, arg3
);
2161 case TARGET_NR_fcntl
:
2162 ret
= get_errno(do_fcntl(arg1
, arg2
, arg3
));
2164 #ifdef TARGET_NR_mpx
2168 case TARGET_NR_setpgid
:
2169 ret
= get_errno(setpgid(arg1
, arg2
));
2171 #ifdef TARGET_NR_ulimit
2172 case TARGET_NR_ulimit
:
2175 #ifdef TARGET_NR_oldolduname
2176 case TARGET_NR_oldolduname
:
2179 case TARGET_NR_umask
:
2180 ret
= get_errno(umask(arg1
));
2182 case TARGET_NR_chroot
:
2183 p
= lock_user_string(arg1
);
2184 ret
= get_errno(chroot(p
));
2185 unlock_user(p
, arg1
, 0);
2187 case TARGET_NR_ustat
:
2189 case TARGET_NR_dup2
:
2190 ret
= get_errno(dup2(arg1
, arg2
));
2192 case TARGET_NR_getppid
:
2193 ret
= get_errno(getppid());
2195 case TARGET_NR_getpgrp
:
2196 ret
= get_errno(getpgrp());
2198 case TARGET_NR_setsid
:
2199 ret
= get_errno(setsid());
2201 case TARGET_NR_sigaction
:
2203 struct target_old_sigaction
*old_act
;
2204 struct target_sigaction act
, oact
, *pact
;
2206 lock_user_struct(old_act
, arg2
, 1);
2207 act
._sa_handler
= old_act
->_sa_handler
;
2208 target_siginitset(&act
.sa_mask
, old_act
->sa_mask
);
2209 act
.sa_flags
= old_act
->sa_flags
;
2210 act
.sa_restorer
= old_act
->sa_restorer
;
2211 unlock_user_struct(old_act
, arg2
, 0);
2216 ret
= get_errno(do_sigaction(arg1
, pact
, &oact
));
2217 if (!is_error(ret
) && arg3
) {
2218 lock_user_struct(old_act
, arg3
, 0);
2219 old_act
->_sa_handler
= oact
._sa_handler
;
2220 old_act
->sa_mask
= oact
.sa_mask
.sig
[0];
2221 old_act
->sa_flags
= oact
.sa_flags
;
2222 old_act
->sa_restorer
= oact
.sa_restorer
;
2223 unlock_user_struct(old_act
, arg3
, 1);
2227 case TARGET_NR_rt_sigaction
:
2229 struct target_sigaction
*act
;
2230 struct target_sigaction
*oact
;
2233 lock_user_struct(act
, arg2
, 1);
2237 lock_user_struct(oact
, arg3
, 0);
2240 ret
= get_errno(do_sigaction(arg1
, act
, oact
));
2242 unlock_user_struct(act
, arg2
, 0);
2244 unlock_user_struct(oact
, arg3
, 1);
2247 case TARGET_NR_sgetmask
:
2250 target_ulong target_set
;
2251 sigprocmask(0, NULL
, &cur_set
);
2252 host_to_target_old_sigset(&target_set
, &cur_set
);
2256 case TARGET_NR_ssetmask
:
2258 sigset_t set
, oset
, cur_set
;
2259 target_ulong target_set
= arg1
;
2260 sigprocmask(0, NULL
, &cur_set
);
2261 target_to_host_old_sigset(&set
, &target_set
);
2262 sigorset(&set
, &set
, &cur_set
);
2263 sigprocmask(SIG_SETMASK
, &set
, &oset
);
2264 host_to_target_old_sigset(&target_set
, &oset
);
2268 case TARGET_NR_sigprocmask
:
2271 sigset_t set
, oldset
, *set_ptr
;
2275 case TARGET_SIG_BLOCK
:
2278 case TARGET_SIG_UNBLOCK
:
2281 case TARGET_SIG_SETMASK
:
2288 p
= lock_user(arg2
, sizeof(target_sigset_t
), 1);
2289 target_to_host_old_sigset(&set
, p
);
2290 unlock_user(p
, arg2
, 0);
2296 ret
= get_errno(sigprocmask(arg1
, set_ptr
, &oldset
));
2297 if (!is_error(ret
) && arg3
) {
2298 p
= lock_user(arg3
, sizeof(target_sigset_t
), 0);
2299 host_to_target_old_sigset(p
, &oldset
);
2300 unlock_user(p
, arg3
, sizeof(target_sigset_t
));
2304 case TARGET_NR_rt_sigprocmask
:
2307 sigset_t set
, oldset
, *set_ptr
;
2311 case TARGET_SIG_BLOCK
:
2314 case TARGET_SIG_UNBLOCK
:
2317 case TARGET_SIG_SETMASK
:
2324 p
= lock_user(arg2
, sizeof(target_sigset_t
), 1);
2325 target_to_host_sigset(&set
, p
);
2326 unlock_user(p
, arg2
, 0);
2332 ret
= get_errno(sigprocmask(how
, set_ptr
, &oldset
));
2333 if (!is_error(ret
) && arg3
) {
2334 p
= lock_user(arg3
, sizeof(target_sigset_t
), 0);
2335 host_to_target_sigset(p
, &oldset
);
2336 unlock_user(p
, arg3
, sizeof(target_sigset_t
));
2340 case TARGET_NR_sigpending
:
2343 ret
= get_errno(sigpending(&set
));
2344 if (!is_error(ret
)) {
2345 p
= lock_user(arg1
, sizeof(target_sigset_t
), 0);
2346 host_to_target_old_sigset(p
, &set
);
2347 unlock_user(p
, arg1
, sizeof(target_sigset_t
));
2351 case TARGET_NR_rt_sigpending
:
2354 ret
= get_errno(sigpending(&set
));
2355 if (!is_error(ret
)) {
2356 p
= lock_user(arg1
, sizeof(target_sigset_t
), 0);
2357 host_to_target_sigset(p
, &set
);
2358 unlock_user(p
, arg1
, sizeof(target_sigset_t
));
2362 case TARGET_NR_sigsuspend
:
2365 p
= lock_user(arg1
, sizeof(target_sigset_t
), 1);
2366 target_to_host_old_sigset(&set
, p
);
2367 unlock_user(p
, arg1
, 0);
2368 ret
= get_errno(sigsuspend(&set
));
2371 case TARGET_NR_rt_sigsuspend
:
2374 p
= lock_user(arg1
, sizeof(target_sigset_t
), 1);
2375 target_to_host_sigset(&set
, p
);
2376 unlock_user(p
, arg1
, 0);
2377 ret
= get_errno(sigsuspend(&set
));
2380 case TARGET_NR_rt_sigtimedwait
:
2383 struct timespec uts
, *puts
;
2386 p
= lock_user(arg1
, sizeof(target_sigset_t
), 1);
2387 target_to_host_sigset(&set
, p
);
2388 unlock_user(p
, arg1
, 0);
2391 target_to_host_timespec(puts
, arg3
);
2395 ret
= get_errno(sigtimedwait(&set
, &uinfo
, puts
));
2396 if (!is_error(ret
) && arg2
) {
2397 p
= lock_user(arg2
, sizeof(target_sigset_t
), 0);
2398 host_to_target_siginfo(p
, &uinfo
);
2399 unlock_user(p
, arg2
, sizeof(target_sigset_t
));
2403 case TARGET_NR_rt_sigqueueinfo
:
2406 p
= lock_user(arg3
, sizeof(target_sigset_t
), 1);
2407 target_to_host_siginfo(&uinfo
, p
);
2408 unlock_user(p
, arg1
, 0);
2409 ret
= get_errno(sys_rt_sigqueueinfo(arg1
, arg2
, &uinfo
));
2412 case TARGET_NR_sigreturn
:
2413 /* NOTE: ret is eax, so not transcoding must be done */
2414 ret
= do_sigreturn(cpu_env
);
2416 case TARGET_NR_rt_sigreturn
:
2417 /* NOTE: ret is eax, so not transcoding must be done */
2418 ret
= do_rt_sigreturn(cpu_env
);
2420 case TARGET_NR_sethostname
:
2421 p
= lock_user_string(arg1
);
2422 ret
= get_errno(sethostname(p
, arg2
));
2423 unlock_user(p
, arg1
, 0);
2425 case TARGET_NR_setrlimit
:
2427 /* XXX: convert resource ? */
2428 int resource
= arg1
;
2429 struct target_rlimit
*target_rlim
;
2431 lock_user_struct(target_rlim
, arg2
, 1);
2432 rlim
.rlim_cur
= tswapl(target_rlim
->rlim_cur
);
2433 rlim
.rlim_max
= tswapl(target_rlim
->rlim_max
);
2434 unlock_user_struct(target_rlim
, arg2
, 0);
2435 ret
= get_errno(setrlimit(resource
, &rlim
));
2438 case TARGET_NR_getrlimit
:
2440 /* XXX: convert resource ? */
2441 int resource
= arg1
;
2442 struct target_rlimit
*target_rlim
;
2445 ret
= get_errno(getrlimit(resource
, &rlim
));
2446 if (!is_error(ret
)) {
2447 lock_user_struct(target_rlim
, arg2
, 0);
2448 rlim
.rlim_cur
= tswapl(target_rlim
->rlim_cur
);
2449 rlim
.rlim_max
= tswapl(target_rlim
->rlim_max
);
2450 unlock_user_struct(target_rlim
, arg2
, 1);
2454 case TARGET_NR_getrusage
:
2456 struct rusage rusage
;
2457 ret
= get_errno(getrusage(arg1
, &rusage
));
2458 if (!is_error(ret
)) {
2459 host_to_target_rusage(arg2
, &rusage
);
2463 case TARGET_NR_gettimeofday
:
2466 ret
= get_errno(gettimeofday(&tv
, NULL
));
2467 if (!is_error(ret
)) {
2468 host_to_target_timeval(arg1
, &tv
);
2472 case TARGET_NR_settimeofday
:
2475 target_to_host_timeval(&tv
, arg1
);
2476 ret
= get_errno(settimeofday(&tv
, NULL
));
2479 #ifdef TARGET_NR_select
2480 case TARGET_NR_select
:
2482 struct target_sel_arg_struct
*sel
;
2483 target_ulong inp
, outp
, exp
, tvp
;
2486 lock_user_struct(sel
, arg1
, 1);
2487 nsel
= tswapl(sel
->n
);
2488 inp
= tswapl(sel
->inp
);
2489 outp
= tswapl(sel
->outp
);
2490 exp
= tswapl(sel
->exp
);
2491 tvp
= tswapl(sel
->tvp
);
2492 unlock_user_struct(sel
, arg1
, 0);
2493 ret
= do_select(nsel
, inp
, outp
, exp
, tvp
);
2497 case TARGET_NR_symlink
:
2500 p
= lock_user_string(arg1
);
2501 p2
= lock_user_string(arg2
);
2502 ret
= get_errno(symlink(p
, p2
));
2503 unlock_user(p2
, arg2
, 0);
2504 unlock_user(p
, arg1
, 0);
2507 #ifdef TARGET_NR_oldlstat
2508 case TARGET_NR_oldlstat
:
2511 case TARGET_NR_readlink
:
2514 p
= lock_user_string(arg1
);
2515 p2
= lock_user(arg2
, arg3
, 0);
2516 ret
= get_errno(readlink(path(p
), p2
, arg3
));
2517 unlock_user(p2
, arg2
, ret
);
2518 unlock_user(p
, arg1
, 0);
2521 case TARGET_NR_uselib
:
2523 case TARGET_NR_swapon
:
2524 p
= lock_user_string(arg1
);
2525 ret
= get_errno(swapon(p
, arg2
));
2526 unlock_user(p
, arg1
, 0);
2528 case TARGET_NR_reboot
:
2530 case TARGET_NR_readdir
:
2532 case TARGET_NR_mmap
:
2533 #if defined(TARGET_I386) || defined(TARGET_ARM)
2536 target_ulong v1
, v2
, v3
, v4
, v5
, v6
;
2537 v
= lock_user(arg1
, 6 * sizeof(target_ulong
), 1);
2544 unlock_user(v
, arg1
, 0);
2545 ret
= get_errno(target_mmap(v1
, v2
, v3
,
2546 target_to_host_bitmask(v4
, mmap_flags_tbl
),
2550 ret
= get_errno(target_mmap(arg1
, arg2
, arg3
,
2551 target_to_host_bitmask(arg4
, mmap_flags_tbl
),
2556 #ifdef TARGET_NR_mmap2
2557 case TARGET_NR_mmap2
:
2558 #if defined(TARGET_SPARC)
2559 #define MMAP_SHIFT 12
2561 #define MMAP_SHIFT TARGET_PAGE_BITS
2563 ret
= get_errno(target_mmap(arg1
, arg2
, arg3
,
2564 target_to_host_bitmask(arg4
, mmap_flags_tbl
),
2566 arg6
<< MMAP_SHIFT
));
2569 case TARGET_NR_munmap
:
2570 ret
= get_errno(target_munmap(arg1
, arg2
));
2572 case TARGET_NR_mprotect
:
2573 ret
= get_errno(target_mprotect(arg1
, arg2
, arg3
));
2575 case TARGET_NR_mremap
:
2576 ret
= get_errno(target_mremap(arg1
, arg2
, arg3
, arg4
, arg5
));
2578 /* ??? msync/mlock/munlock are broken for softmmu. */
2579 case TARGET_NR_msync
:
2580 ret
= get_errno(msync(g2h(arg1
), arg2
, arg3
));
2582 case TARGET_NR_mlock
:
2583 ret
= get_errno(mlock(g2h(arg1
), arg2
));
2585 case TARGET_NR_munlock
:
2586 ret
= get_errno(munlock(g2h(arg1
), arg2
));
2588 case TARGET_NR_mlockall
:
2589 ret
= get_errno(mlockall(arg1
));
2591 case TARGET_NR_munlockall
:
2592 ret
= get_errno(munlockall());
2594 case TARGET_NR_truncate
:
2595 p
= lock_user_string(arg1
);
2596 ret
= get_errno(truncate(p
, arg2
));
2597 unlock_user(p
, arg1
, 0);
2599 case TARGET_NR_ftruncate
:
2600 ret
= get_errno(ftruncate(arg1
, arg2
));
2602 case TARGET_NR_fchmod
:
2603 ret
= get_errno(fchmod(arg1
, arg2
));
2605 case TARGET_NR_getpriority
:
2606 ret
= get_errno(getpriority(arg1
, arg2
));
2608 case TARGET_NR_setpriority
:
2609 ret
= get_errno(setpriority(arg1
, arg2
, arg3
));
2611 #ifdef TARGET_NR_profil
2612 case TARGET_NR_profil
:
2615 case TARGET_NR_statfs
:
2616 p
= lock_user_string(arg1
);
2617 ret
= get_errno(statfs(path(p
), &stfs
));
2618 unlock_user(p
, arg1
, 0);
2620 if (!is_error(ret
)) {
2621 struct target_statfs
*target_stfs
;
2623 lock_user_struct(target_stfs
, arg2
, 0);
2624 /* ??? put_user is probably wrong. */
2625 put_user(stfs
.f_type
, &target_stfs
->f_type
);
2626 put_user(stfs
.f_bsize
, &target_stfs
->f_bsize
);
2627 put_user(stfs
.f_blocks
, &target_stfs
->f_blocks
);
2628 put_user(stfs
.f_bfree
, &target_stfs
->f_bfree
);
2629 put_user(stfs
.f_bavail
, &target_stfs
->f_bavail
);
2630 put_user(stfs
.f_files
, &target_stfs
->f_files
);
2631 put_user(stfs
.f_ffree
, &target_stfs
->f_ffree
);
2632 put_user(stfs
.f_fsid
.__val
[0], &target_stfs
->f_fsid
);
2633 put_user(stfs
.f_namelen
, &target_stfs
->f_namelen
);
2634 unlock_user_struct(target_stfs
, arg2
, 1);
2637 case TARGET_NR_fstatfs
:
2638 ret
= get_errno(fstatfs(arg1
, &stfs
));
2639 goto convert_statfs
;
2640 #ifdef TARGET_NR_statfs64
2641 case TARGET_NR_statfs64
:
2642 p
= lock_user_string(arg1
);
2643 ret
= get_errno(statfs(path(p
), &stfs
));
2644 unlock_user(p
, arg1
, 0);
2646 if (!is_error(ret
)) {
2647 struct target_statfs64
*target_stfs
;
2649 lock_user_struct(target_stfs
, arg3
, 0);
2650 /* ??? put_user is probably wrong. */
2651 put_user(stfs
.f_type
, &target_stfs
->f_type
);
2652 put_user(stfs
.f_bsize
, &target_stfs
->f_bsize
);
2653 put_user(stfs
.f_blocks
, &target_stfs
->f_blocks
);
2654 put_user(stfs
.f_bfree
, &target_stfs
->f_bfree
);
2655 put_user(stfs
.f_bavail
, &target_stfs
->f_bavail
);
2656 put_user(stfs
.f_files
, &target_stfs
->f_files
);
2657 put_user(stfs
.f_ffree
, &target_stfs
->f_ffree
);
2658 put_user(stfs
.f_fsid
.__val
[0], &target_stfs
->f_fsid
);
2659 put_user(stfs
.f_namelen
, &target_stfs
->f_namelen
);
2660 unlock_user_struct(target_stfs
, arg3
, 0);
2663 case TARGET_NR_fstatfs64
:
2664 ret
= get_errno(fstatfs(arg1
, &stfs
));
2665 goto convert_statfs64
;
2667 #ifdef TARGET_NR_ioperm
2668 case TARGET_NR_ioperm
:
2671 case TARGET_NR_socketcall
:
2672 ret
= do_socketcall(arg1
, arg2
);
2674 case TARGET_NR_syslog
:
2676 case TARGET_NR_setitimer
:
2678 struct itimerval value
, ovalue
, *pvalue
;
2682 target_to_host_timeval(&pvalue
->it_interval
,
2684 target_to_host_timeval(&pvalue
->it_value
,
2685 arg2
+ sizeof(struct target_timeval
));
2689 ret
= get_errno(setitimer(arg1
, pvalue
, &ovalue
));
2690 if (!is_error(ret
) && arg3
) {
2691 host_to_target_timeval(arg3
,
2692 &ovalue
.it_interval
);
2693 host_to_target_timeval(arg3
+ sizeof(struct target_timeval
),
2698 case TARGET_NR_getitimer
:
2700 struct itimerval value
;
2702 ret
= get_errno(getitimer(arg1
, &value
));
2703 if (!is_error(ret
) && arg2
) {
2704 host_to_target_timeval(arg2
,
2705 &value
.it_interval
);
2706 host_to_target_timeval(arg2
+ sizeof(struct target_timeval
),
2711 case TARGET_NR_stat
:
2712 p
= lock_user_string(arg1
);
2713 ret
= get_errno(stat(path(p
), &st
));
2714 unlock_user(p
, arg1
, 0);
2716 case TARGET_NR_lstat
:
2717 p
= lock_user_string(arg1
);
2718 ret
= get_errno(lstat(path(p
), &st
));
2719 unlock_user(p
, arg1
, 0);
2721 case TARGET_NR_fstat
:
2723 ret
= get_errno(fstat(arg1
, &st
));
2725 if (!is_error(ret
)) {
2726 struct target_stat
*target_st
;
2728 lock_user_struct(target_st
, arg2
, 0);
2729 target_st
->st_dev
= tswap16(st
.st_dev
);
2730 target_st
->st_ino
= tswapl(st
.st_ino
);
2731 #if defined(TARGET_PPC)
2732 target_st
->st_mode
= tswapl(st
.st_mode
); /* XXX: check this */
2733 target_st
->st_uid
= tswap32(st
.st_uid
);
2734 target_st
->st_gid
= tswap32(st
.st_gid
);
2736 target_st
->st_mode
= tswap16(st
.st_mode
);
2737 target_st
->st_uid
= tswap16(st
.st_uid
);
2738 target_st
->st_gid
= tswap16(st
.st_gid
);
2740 target_st
->st_nlink
= tswap16(st
.st_nlink
);
2741 target_st
->st_rdev
= tswap16(st
.st_rdev
);
2742 target_st
->st_size
= tswapl(st
.st_size
);
2743 target_st
->st_blksize
= tswapl(st
.st_blksize
);
2744 target_st
->st_blocks
= tswapl(st
.st_blocks
);
2745 target_st
->target_st_atime
= tswapl(st
.st_atime
);
2746 target_st
->target_st_mtime
= tswapl(st
.st_mtime
);
2747 target_st
->target_st_ctime
= tswapl(st
.st_ctime
);
2748 unlock_user_struct(target_st
, arg2
, 1);
2752 #ifdef TARGET_NR_olduname
2753 case TARGET_NR_olduname
:
2756 #ifdef TARGET_NR_iopl
2757 case TARGET_NR_iopl
:
2760 case TARGET_NR_vhangup
:
2761 ret
= get_errno(vhangup());
2763 #ifdef TARGET_NR_idle
2764 case TARGET_NR_idle
:
2767 #ifdef TARGET_NR_syscall
2768 case TARGET_NR_syscall
:
2769 ret
= do_syscall(cpu_env
,arg1
& 0xffff,arg2
,arg3
,arg4
,arg5
,arg6
,0);
2772 case TARGET_NR_wait4
:
2775 target_long status_ptr
= arg2
;
2776 struct rusage rusage
, *rusage_ptr
;
2777 target_ulong target_rusage
= arg4
;
2779 rusage_ptr
= &rusage
;
2782 ret
= get_errno(wait4(arg1
, &status
, arg3
, rusage_ptr
));
2783 if (!is_error(ret
)) {
2785 tputl(status_ptr
, status
);
2786 if (target_rusage
) {
2787 host_to_target_rusage(target_rusage
, &rusage
);
2792 case TARGET_NR_swapoff
:
2793 p
= lock_user_string(arg1
);
2794 ret
= get_errno(swapoff(p
));
2795 unlock_user(p
, arg1
, 0);
2797 case TARGET_NR_sysinfo
:
2799 struct target_sysinfo
*target_value
;
2800 struct sysinfo value
;
2801 ret
= get_errno(sysinfo(&value
));
2802 if (!is_error(ret
) && arg1
)
2804 /* ??? __put_user is probably wrong. */
2805 lock_user_struct(target_value
, arg1
, 0);
2806 __put_user(value
.uptime
, &target_value
->uptime
);
2807 __put_user(value
.loads
[0], &target_value
->loads
[0]);
2808 __put_user(value
.loads
[1], &target_value
->loads
[1]);
2809 __put_user(value
.loads
[2], &target_value
->loads
[2]);
2810 __put_user(value
.totalram
, &target_value
->totalram
);
2811 __put_user(value
.freeram
, &target_value
->freeram
);
2812 __put_user(value
.sharedram
, &target_value
->sharedram
);
2813 __put_user(value
.bufferram
, &target_value
->bufferram
);
2814 __put_user(value
.totalswap
, &target_value
->totalswap
);
2815 __put_user(value
.freeswap
, &target_value
->freeswap
);
2816 __put_user(value
.procs
, &target_value
->procs
);
2817 __put_user(value
.totalhigh
, &target_value
->totalhigh
);
2818 __put_user(value
.freehigh
, &target_value
->freehigh
);
2819 __put_user(value
.mem_unit
, &target_value
->mem_unit
);
2820 unlock_user_struct(target_value
, arg1
, 1);
2825 ret
= do_ipc(arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
2827 case TARGET_NR_fsync
:
2828 ret
= get_errno(fsync(arg1
));
2830 case TARGET_NR_clone
:
2831 ret
= get_errno(do_fork(cpu_env
, arg1
, arg2
));
2833 #ifdef __NR_exit_group
2834 /* new thread calls */
2835 case TARGET_NR_exit_group
:
2836 gdb_exit(cpu_env
, arg1
);
2837 ret
= get_errno(exit_group(arg1
));
2840 case TARGET_NR_setdomainname
:
2841 p
= lock_user_string(arg1
);
2842 ret
= get_errno(setdomainname(p
, arg2
));
2843 unlock_user(p
, arg1
, 0);
2845 case TARGET_NR_uname
:
2846 /* no need to transcode because we use the linux syscall */
2848 struct new_utsname
* buf
;
2850 lock_user_struct(buf
, arg1
, 0);
2851 ret
= get_errno(sys_uname(buf
));
2852 if (!is_error(ret
)) {
2853 /* Overrite the native machine name with whatever is being
2855 strcpy (buf
->machine
, UNAME_MACHINE
);
2857 unlock_user_struct(buf
, arg1
, 1);
2861 case TARGET_NR_modify_ldt
:
2862 ret
= get_errno(do_modify_ldt(cpu_env
, arg1
, arg2
, arg3
));
2864 case TARGET_NR_vm86old
:
2866 case TARGET_NR_vm86
:
2867 ret
= do_vm86(cpu_env
, arg1
, arg2
);
2870 case TARGET_NR_adjtimex
:
2872 case TARGET_NR_create_module
:
2873 case TARGET_NR_init_module
:
2874 case TARGET_NR_delete_module
:
2875 case TARGET_NR_get_kernel_syms
:
2877 case TARGET_NR_quotactl
:
2879 case TARGET_NR_getpgid
:
2880 ret
= get_errno(getpgid(arg1
));
2882 case TARGET_NR_fchdir
:
2883 ret
= get_errno(fchdir(arg1
));
2885 case TARGET_NR_bdflush
:
2887 case TARGET_NR_sysfs
:
2889 case TARGET_NR_personality
:
2890 ret
= get_errno(personality(arg1
));
2892 case TARGET_NR_afs_syscall
:
2894 case TARGET_NR__llseek
:
2896 #if defined (__x86_64__)
2897 ret
= get_errno(lseek(arg1
, ((uint64_t )arg2
<< 32) | arg3
, arg5
));
2901 ret
= get_errno(_llseek(arg1
, arg2
, arg3
, &res
, arg5
));
2906 case TARGET_NR_getdents
:
2907 #if TARGET_LONG_SIZE != 4
2909 #warning not supported
2910 #elif TARGET_LONG_SIZE == 4 && HOST_LONG_SIZE == 8
2912 struct target_dirent
*target_dirp
;
2913 struct dirent
*dirp
;
2916 dirp
= malloc(count
);
2920 ret
= get_errno(sys_getdents(arg1
, dirp
, count
));
2921 if (!is_error(ret
)) {
2923 struct target_dirent
*tde
;
2925 int reclen
, treclen
;
2926 int count1
, tnamelen
;
2930 target_dirp
= lock_user(arg2
, count
, 0);
2933 reclen
= de
->d_reclen
;
2934 treclen
= reclen
- (2 * (sizeof(long) - sizeof(target_long
)));
2935 tde
->d_reclen
= tswap16(treclen
);
2936 tde
->d_ino
= tswapl(de
->d_ino
);
2937 tde
->d_off
= tswapl(de
->d_off
);
2938 tnamelen
= treclen
- (2 * sizeof(target_long
) + 2);
2941 /* XXX: may not be correct */
2942 strncpy(tde
->d_name
, de
->d_name
, tnamelen
);
2943 de
= (struct dirent
*)((char *)de
+ reclen
);
2945 tde
= (struct dirent
*)((char *)tde
+ treclen
);
2950 unlock_user(target_dirp
, arg2
, ret
);
2955 struct dirent
*dirp
;
2958 dirp
= lock_user(arg2
, count
, 0);
2959 ret
= get_errno(sys_getdents(arg1
, dirp
, count
));
2960 if (!is_error(ret
)) {
2966 reclen
= de
->d_reclen
;
2969 de
->d_reclen
= tswap16(reclen
);
2970 tswapls(&de
->d_ino
);
2971 tswapls(&de
->d_off
);
2972 de
= (struct dirent
*)((char *)de
+ reclen
);
2976 unlock_user(dirp
, arg2
, ret
);
2980 #ifdef TARGET_NR_getdents64
2981 case TARGET_NR_getdents64
:
2983 struct dirent64
*dirp
;
2985 dirp
= lock_user(arg2
, count
, 0);
2986 ret
= get_errno(sys_getdents64(arg1
, dirp
, count
));
2987 if (!is_error(ret
)) {
2988 struct dirent64
*de
;
2993 reclen
= de
->d_reclen
;
2996 de
->d_reclen
= tswap16(reclen
);
2997 tswap64s(&de
->d_ino
);
2998 tswap64s(&de
->d_off
);
2999 de
= (struct dirent64
*)((char *)de
+ reclen
);
3003 unlock_user(dirp
, arg2
, ret
);
3006 #endif /* TARGET_NR_getdents64 */
3007 case TARGET_NR__newselect
:
3008 ret
= do_select(arg1
, arg2
, arg3
, arg4
, arg5
);
3010 case TARGET_NR_poll
:
3012 struct target_pollfd
*target_pfd
;
3013 unsigned int nfds
= arg2
;
3018 target_pfd
= lock_user(arg1
, sizeof(struct target_pollfd
) * nfds
, 1);
3019 pfd
= alloca(sizeof(struct pollfd
) * nfds
);
3020 for(i
= 0; i
< nfds
; i
++) {
3021 pfd
[i
].fd
= tswap32(target_pfd
[i
].fd
);
3022 pfd
[i
].events
= tswap16(target_pfd
[i
].events
);
3024 ret
= get_errno(poll(pfd
, nfds
, timeout
));
3025 if (!is_error(ret
)) {
3026 for(i
= 0; i
< nfds
; i
++) {
3027 target_pfd
[i
].revents
= tswap16(pfd
[i
].revents
);
3029 ret
+= nfds
* (sizeof(struct target_pollfd
)
3030 - sizeof(struct pollfd
));
3032 unlock_user(target_pfd
, arg1
, ret
);
3035 case TARGET_NR_flock
:
3036 /* NOTE: the flock constant seems to be the same for every
3038 ret
= get_errno(flock(arg1
, arg2
));
3040 case TARGET_NR_readv
:
3045 vec
= alloca(count
* sizeof(struct iovec
));
3046 lock_iovec(vec
, arg2
, count
, 0);
3047 ret
= get_errno(readv(arg1
, vec
, count
));
3048 unlock_iovec(vec
, arg2
, count
, 1);
3051 case TARGET_NR_writev
:
3056 vec
= alloca(count
* sizeof(struct iovec
));
3057 lock_iovec(vec
, arg2
, count
, 1);
3058 ret
= get_errno(writev(arg1
, vec
, count
));
3059 unlock_iovec(vec
, arg2
, count
, 0);
3062 case TARGET_NR_getsid
:
3063 ret
= get_errno(getsid(arg1
));
3065 case TARGET_NR_fdatasync
:
3066 ret
= get_errno(fdatasync(arg1
));
3068 case TARGET_NR__sysctl
:
3069 /* We don't implement this, but ENODIR is always a safe
3072 case TARGET_NR_sched_setparam
:
3074 struct sched_param
*target_schp
;
3075 struct sched_param schp
;
3077 lock_user_struct(target_schp
, arg2
, 1);
3078 schp
.sched_priority
= tswap32(target_schp
->sched_priority
);
3079 unlock_user_struct(target_schp
, arg2
, 0);
3080 ret
= get_errno(sched_setparam(arg1
, &schp
));
3083 case TARGET_NR_sched_getparam
:
3085 struct sched_param
*target_schp
;
3086 struct sched_param schp
;
3087 ret
= get_errno(sched_getparam(arg1
, &schp
));
3088 if (!is_error(ret
)) {
3089 lock_user_struct(target_schp
, arg2
, 0);
3090 target_schp
->sched_priority
= tswap32(schp
.sched_priority
);
3091 unlock_user_struct(target_schp
, arg2
, 1);
3095 case TARGET_NR_sched_setscheduler
:
3097 struct sched_param
*target_schp
;
3098 struct sched_param schp
;
3099 lock_user_struct(target_schp
, arg3
, 1);
3100 schp
.sched_priority
= tswap32(target_schp
->sched_priority
);
3101 unlock_user_struct(target_schp
, arg3
, 0);
3102 ret
= get_errno(sched_setscheduler(arg1
, arg2
, &schp
));
3105 case TARGET_NR_sched_getscheduler
:
3106 ret
= get_errno(sched_getscheduler(arg1
));
3108 case TARGET_NR_sched_yield
:
3109 ret
= get_errno(sched_yield());
3111 case TARGET_NR_sched_get_priority_max
:
3112 ret
= get_errno(sched_get_priority_max(arg1
));
3114 case TARGET_NR_sched_get_priority_min
:
3115 ret
= get_errno(sched_get_priority_min(arg1
));
3117 case TARGET_NR_sched_rr_get_interval
:
3120 ret
= get_errno(sched_rr_get_interval(arg1
, &ts
));
3121 if (!is_error(ret
)) {
3122 host_to_target_timespec(arg2
, &ts
);
3126 case TARGET_NR_nanosleep
:
3128 struct timespec req
, rem
;
3129 target_to_host_timespec(&req
, arg1
);
3130 ret
= get_errno(nanosleep(&req
, &rem
));
3131 if (is_error(ret
) && arg2
) {
3132 host_to_target_timespec(arg2
, &rem
);
3136 case TARGET_NR_query_module
:
3138 case TARGET_NR_nfsservctl
:
3140 case TARGET_NR_prctl
:
3142 #ifdef TARGET_NR_pread
3143 case TARGET_NR_pread
:
3144 page_unprotect_range(arg2
, arg3
);
3145 p
= lock_user(arg2
, arg3
, 0);
3146 ret
= get_errno(pread(arg1
, p
, arg3
, arg4
));
3147 unlock_user(p
, arg2
, ret
);
3149 case TARGET_NR_pwrite
:
3150 p
= lock_user(arg2
, arg3
, 1);
3151 ret
= get_errno(pwrite(arg1
, p
, arg3
, arg4
));
3152 unlock_user(p
, arg2
, 0);
3155 case TARGET_NR_getcwd
:
3156 p
= lock_user(arg1
, arg2
, 0);
3157 ret
= get_errno(sys_getcwd1(p
, arg2
));
3158 unlock_user(p
, arg1
, ret
);
3160 case TARGET_NR_capget
:
3162 case TARGET_NR_capset
:
3164 case TARGET_NR_sigaltstack
:
3166 case TARGET_NR_sendfile
:
3168 #ifdef TARGET_NR_getpmsg
3169 case TARGET_NR_getpmsg
:
3172 #ifdef TARGET_NR_putpmsg
3173 case TARGET_NR_putpmsg
:
3176 #ifdef TARGET_NR_vfork
3177 case TARGET_NR_vfork
:
3178 ret
= get_errno(do_fork(cpu_env
, CLONE_VFORK
| CLONE_VM
| SIGCHLD
, 0));
3181 #ifdef TARGET_NR_ugetrlimit
3182 case TARGET_NR_ugetrlimit
:
3185 ret
= get_errno(getrlimit(arg1
, &rlim
));
3186 if (!is_error(ret
)) {
3187 struct target_rlimit
*target_rlim
;
3188 lock_user_struct(target_rlim
, arg2
, 0);
3189 target_rlim
->rlim_cur
= tswapl(rlim
.rlim_cur
);
3190 target_rlim
->rlim_max
= tswapl(rlim
.rlim_max
);
3191 unlock_user_struct(target_rlim
, arg2
, 1);
3196 #ifdef TARGET_NR_truncate64
3197 case TARGET_NR_truncate64
:
3198 p
= lock_user_string(arg1
);
3199 ret
= target_truncate64(cpu_env
, p
, arg2
, arg3
, arg4
);
3200 unlock_user(p
, arg1
, 0);
3203 #ifdef TARGET_NR_ftruncate64
3204 case TARGET_NR_ftruncate64
:
3205 ret
= target_ftruncate64(cpu_env
, arg1
, arg2
, arg3
, arg4
);
3208 #ifdef TARGET_NR_stat64
3209 case TARGET_NR_stat64
:
3210 p
= lock_user_string(arg1
);
3211 ret
= get_errno(stat(path(p
), &st
));
3212 unlock_user(p
, arg1
, 0);
3215 #ifdef TARGET_NR_lstat64
3216 case TARGET_NR_lstat64
:
3217 p
= lock_user_string(arg1
);
3218 ret
= get_errno(lstat(path(p
), &st
));
3219 unlock_user(p
, arg1
, 0);
3222 #ifdef TARGET_NR_fstat64
3223 case TARGET_NR_fstat64
:
3225 ret
= get_errno(fstat(arg1
, &st
));
3227 if (!is_error(ret
)) {
3229 if (((CPUARMState
*)cpu_env
)->eabi
) {
3230 struct target_eabi_stat64
*target_st
;
3231 lock_user_struct(target_st
, arg2
, 1);
3232 memset(target_st
, 0, sizeof(struct target_eabi_stat64
));
3233 /* put_user is probably wrong. */
3234 put_user(st
.st_dev
, &target_st
->st_dev
);
3235 put_user(st
.st_ino
, &target_st
->st_ino
);
3236 #ifdef TARGET_STAT64_HAS_BROKEN_ST_INO
3237 put_user(st
.st_ino
, &target_st
->__st_ino
);
3239 put_user(st
.st_mode
, &target_st
->st_mode
);
3240 put_user(st
.st_nlink
, &target_st
->st_nlink
);
3241 put_user(st
.st_uid
, &target_st
->st_uid
);
3242 put_user(st
.st_gid
, &target_st
->st_gid
);
3243 put_user(st
.st_rdev
, &target_st
->st_rdev
);
3244 /* XXX: better use of kernel struct */
3245 put_user(st
.st_size
, &target_st
->st_size
);
3246 put_user(st
.st_blksize
, &target_st
->st_blksize
);
3247 put_user(st
.st_blocks
, &target_st
->st_blocks
);
3248 put_user(st
.st_atime
, &target_st
->target_st_atime
);
3249 put_user(st
.st_mtime
, &target_st
->target_st_mtime
);
3250 put_user(st
.st_ctime
, &target_st
->target_st_ctime
);
3251 unlock_user_struct(target_st
, arg2
, 0);
3255 struct target_stat64
*target_st
;
3256 lock_user_struct(target_st
, arg2
, 1);
3257 memset(target_st
, 0, sizeof(struct target_stat64
));
3258 /* ??? put_user is probably wrong. */
3259 put_user(st
.st_dev
, &target_st
->st_dev
);
3260 put_user(st
.st_ino
, &target_st
->st_ino
);
3261 #ifdef TARGET_STAT64_HAS_BROKEN_ST_INO
3262 put_user(st
.st_ino
, &target_st
->__st_ino
);
3264 put_user(st
.st_mode
, &target_st
->st_mode
);
3265 put_user(st
.st_nlink
, &target_st
->st_nlink
);
3266 put_user(st
.st_uid
, &target_st
->st_uid
);
3267 put_user(st
.st_gid
, &target_st
->st_gid
);
3268 put_user(st
.st_rdev
, &target_st
->st_rdev
);
3269 /* XXX: better use of kernel struct */
3270 put_user(st
.st_size
, &target_st
->st_size
);
3271 put_user(st
.st_blksize
, &target_st
->st_blksize
);
3272 put_user(st
.st_blocks
, &target_st
->st_blocks
);
3273 put_user(st
.st_atime
, &target_st
->target_st_atime
);
3274 put_user(st
.st_mtime
, &target_st
->target_st_mtime
);
3275 put_user(st
.st_ctime
, &target_st
->target_st_ctime
);
3276 unlock_user_struct(target_st
, arg2
, 0);
3283 case TARGET_NR_lchown
:
3284 p
= lock_user_string(arg1
);
3285 ret
= get_errno(lchown(p
, low2highuid(arg2
), low2highgid(arg3
)));
3286 unlock_user(p
, arg1
, 0);
3288 case TARGET_NR_getuid
:
3289 ret
= get_errno(high2lowuid(getuid()));
3291 case TARGET_NR_getgid
:
3292 ret
= get_errno(high2lowgid(getgid()));
3294 case TARGET_NR_geteuid
:
3295 ret
= get_errno(high2lowuid(geteuid()));
3297 case TARGET_NR_getegid
:
3298 ret
= get_errno(high2lowgid(getegid()));
3300 case TARGET_NR_setreuid
:
3301 ret
= get_errno(setreuid(low2highuid(arg1
), low2highuid(arg2
)));
3303 case TARGET_NR_setregid
:
3304 ret
= get_errno(setregid(low2highgid(arg1
), low2highgid(arg2
)));
3306 case TARGET_NR_getgroups
:
3308 int gidsetsize
= arg1
;
3309 uint16_t *target_grouplist
;
3313 grouplist
= alloca(gidsetsize
* sizeof(gid_t
));
3314 ret
= get_errno(getgroups(gidsetsize
, grouplist
));
3315 if (!is_error(ret
)) {
3316 target_grouplist
= lock_user(arg2
, gidsetsize
* 2, 0);
3317 for(i
= 0;i
< gidsetsize
; i
++)
3318 target_grouplist
[i
] = tswap16(grouplist
[i
]);
3319 unlock_user(target_grouplist
, arg2
, gidsetsize
* 2);
3323 case TARGET_NR_setgroups
:
3325 int gidsetsize
= arg1
;
3326 uint16_t *target_grouplist
;
3330 grouplist
= alloca(gidsetsize
* sizeof(gid_t
));
3331 target_grouplist
= lock_user(arg2
, gidsetsize
* 2, 1);
3332 for(i
= 0;i
< gidsetsize
; i
++)
3333 grouplist
[i
] = tswap16(target_grouplist
[i
]);
3334 unlock_user(target_grouplist
, arg2
, 0);
3335 ret
= get_errno(setgroups(gidsetsize
, grouplist
));
3338 case TARGET_NR_fchown
:
3339 ret
= get_errno(fchown(arg1
, low2highuid(arg2
), low2highgid(arg3
)));
3341 #ifdef TARGET_NR_setresuid
3342 case TARGET_NR_setresuid
:
3343 ret
= get_errno(setresuid(low2highuid(arg1
),
3345 low2highuid(arg3
)));
3348 #ifdef TARGET_NR_getresuid
3349 case TARGET_NR_getresuid
:
3351 uid_t ruid
, euid
, suid
;
3352 ret
= get_errno(getresuid(&ruid
, &euid
, &suid
));
3353 if (!is_error(ret
)) {
3354 tput16(arg1
, tswap16(high2lowuid(ruid
)));
3355 tput16(arg2
, tswap16(high2lowuid(euid
)));
3356 tput16(arg3
, tswap16(high2lowuid(suid
)));
3361 #ifdef TARGET_NR_getresgid
3362 case TARGET_NR_setresgid
:
3363 ret
= get_errno(setresgid(low2highgid(arg1
),
3365 low2highgid(arg3
)));
3368 #ifdef TARGET_NR_getresgid
3369 case TARGET_NR_getresgid
:
3371 gid_t rgid
, egid
, sgid
;
3372 ret
= get_errno(getresgid(&rgid
, &egid
, &sgid
));
3373 if (!is_error(ret
)) {
3374 tput16(arg1
, tswap16(high2lowgid(rgid
)));
3375 tput16(arg2
, tswap16(high2lowgid(egid
)));
3376 tput16(arg3
, tswap16(high2lowgid(sgid
)));
3381 case TARGET_NR_chown
:
3382 p
= lock_user_string(arg1
);
3383 ret
= get_errno(chown(p
, low2highuid(arg2
), low2highgid(arg3
)));
3384 unlock_user(p
, arg1
, 0);
3386 case TARGET_NR_setuid
:
3387 ret
= get_errno(setuid(low2highuid(arg1
)));
3389 case TARGET_NR_setgid
:
3390 ret
= get_errno(setgid(low2highgid(arg1
)));
3392 case TARGET_NR_setfsuid
:
3393 ret
= get_errno(setfsuid(arg1
));
3395 case TARGET_NR_setfsgid
:
3396 ret
= get_errno(setfsgid(arg1
));
3398 #endif /* USE_UID16 */
3400 #ifdef TARGET_NR_lchown32
3401 case TARGET_NR_lchown32
:
3402 p
= lock_user_string(arg1
);
3403 ret
= get_errno(lchown(p
, arg2
, arg3
));
3404 unlock_user(p
, arg1
, 0);
3407 #ifdef TARGET_NR_getuid32
3408 case TARGET_NR_getuid32
:
3409 ret
= get_errno(getuid());
3412 #ifdef TARGET_NR_getgid32
3413 case TARGET_NR_getgid32
:
3414 ret
= get_errno(getgid());
3417 #ifdef TARGET_NR_geteuid32
3418 case TARGET_NR_geteuid32
:
3419 ret
= get_errno(geteuid());
3422 #ifdef TARGET_NR_getegid32
3423 case TARGET_NR_getegid32
:
3424 ret
= get_errno(getegid());
3427 #ifdef TARGET_NR_setreuid32
3428 case TARGET_NR_setreuid32
:
3429 ret
= get_errno(setreuid(arg1
, arg2
));
3432 #ifdef TARGET_NR_setregid32
3433 case TARGET_NR_setregid32
:
3434 ret
= get_errno(setregid(arg1
, arg2
));
3437 #ifdef TARGET_NR_getgroups32
3438 case TARGET_NR_getgroups32
:
3440 int gidsetsize
= arg1
;
3441 uint32_t *target_grouplist
;
3445 grouplist
= alloca(gidsetsize
* sizeof(gid_t
));
3446 ret
= get_errno(getgroups(gidsetsize
, grouplist
));
3447 if (!is_error(ret
)) {
3448 target_grouplist
= lock_user(arg2
, gidsetsize
* 4, 0);
3449 for(i
= 0;i
< gidsetsize
; i
++)
3450 target_grouplist
[i
] = tswap32(grouplist
[i
]);
3451 unlock_user(target_grouplist
, arg2
, gidsetsize
* 4);
3456 #ifdef TARGET_NR_setgroups32
3457 case TARGET_NR_setgroups32
:
3459 int gidsetsize
= arg1
;
3460 uint32_t *target_grouplist
;
3464 grouplist
= alloca(gidsetsize
* sizeof(gid_t
));
3465 target_grouplist
= lock_user(arg2
, gidsetsize
* 4, 1);
3466 for(i
= 0;i
< gidsetsize
; i
++)
3467 grouplist
[i
] = tswap32(target_grouplist
[i
]);
3468 unlock_user(target_grouplist
, arg2
, 0);
3469 ret
= get_errno(setgroups(gidsetsize
, grouplist
));
3473 #ifdef TARGET_NR_fchown32
3474 case TARGET_NR_fchown32
:
3475 ret
= get_errno(fchown(arg1
, arg2
, arg3
));
3478 #ifdef TARGET_NR_setresuid32
3479 case TARGET_NR_setresuid32
:
3480 ret
= get_errno(setresuid(arg1
, arg2
, arg3
));
3483 #ifdef TARGET_NR_getresuid32
3484 case TARGET_NR_getresuid32
:
3486 uid_t ruid
, euid
, suid
;
3487 ret
= get_errno(getresuid(&ruid
, &euid
, &suid
));
3488 if (!is_error(ret
)) {
3489 tput32(arg1
, tswap32(ruid
));
3490 tput32(arg2
, tswap32(euid
));
3491 tput32(arg3
, tswap32(suid
));
3496 #ifdef TARGET_NR_setresgid32
3497 case TARGET_NR_setresgid32
:
3498 ret
= get_errno(setresgid(arg1
, arg2
, arg3
));
3501 #ifdef TARGET_NR_getresgid32
3502 case TARGET_NR_getresgid32
:
3504 gid_t rgid
, egid
, sgid
;
3505 ret
= get_errno(getresgid(&rgid
, &egid
, &sgid
));
3506 if (!is_error(ret
)) {
3507 tput32(arg1
, tswap32(rgid
));
3508 tput32(arg2
, tswap32(egid
));
3509 tput32(arg3
, tswap32(sgid
));
3514 #ifdef TARGET_NR_chown32
3515 case TARGET_NR_chown32
:
3516 p
= lock_user_string(arg1
);
3517 ret
= get_errno(chown(p
, arg2
, arg3
));
3518 unlock_user(p
, arg1
, 0);
3521 #ifdef TARGET_NR_setuid32
3522 case TARGET_NR_setuid32
:
3523 ret
= get_errno(setuid(arg1
));
3526 #ifdef TARGET_NR_setgid32
3527 case TARGET_NR_setgid32
:
3528 ret
= get_errno(setgid(arg1
));
3531 #ifdef TARGET_NR_setfsuid32
3532 case TARGET_NR_setfsuid32
:
3533 ret
= get_errno(setfsuid(arg1
));
3536 #ifdef TARGET_NR_setfsgid32
3537 case TARGET_NR_setfsgid32
:
3538 ret
= get_errno(setfsgid(arg1
));
3542 case TARGET_NR_pivot_root
:
3544 #ifdef TARGET_NR_mincore
3545 case TARGET_NR_mincore
:
3548 #ifdef TARGET_NR_madvise
3549 case TARGET_NR_madvise
:
3552 #if TARGET_LONG_BITS == 32
3553 case TARGET_NR_fcntl64
:
3556 struct target_flock64
*target_fl
;
3558 struct target_eabi_flock64
*target_efl
;
3563 ret
= get_errno(fcntl(arg1
, arg2
, &fl
));
3566 if (((CPUARMState
*)cpu_env
)->eabi
) {
3567 lock_user_struct(target_efl
, arg3
, 0);
3568 target_efl
->l_type
= tswap16(fl
.l_type
);
3569 target_efl
->l_whence
= tswap16(fl
.l_whence
);
3570 target_efl
->l_start
= tswap64(fl
.l_start
);
3571 target_efl
->l_len
= tswap64(fl
.l_len
);
3572 target_efl
->l_pid
= tswapl(fl
.l_pid
);
3573 unlock_user_struct(target_efl
, arg3
, 1);
3577 lock_user_struct(target_fl
, arg3
, 0);
3578 target_fl
->l_type
= tswap16(fl
.l_type
);
3579 target_fl
->l_whence
= tswap16(fl
.l_whence
);
3580 target_fl
->l_start
= tswap64(fl
.l_start
);
3581 target_fl
->l_len
= tswap64(fl
.l_len
);
3582 target_fl
->l_pid
= tswapl(fl
.l_pid
);
3583 unlock_user_struct(target_fl
, arg3
, 1);
3591 if (((CPUARMState
*)cpu_env
)->eabi
) {
3592 lock_user_struct(target_efl
, arg3
, 1);
3593 fl
.l_type
= tswap16(target_efl
->l_type
);
3594 fl
.l_whence
= tswap16(target_efl
->l_whence
);
3595 fl
.l_start
= tswap64(target_efl
->l_start
);
3596 fl
.l_len
= tswap64(target_efl
->l_len
);
3597 fl
.l_pid
= tswapl(target_efl
->l_pid
);
3598 unlock_user_struct(target_efl
, arg3
, 0);
3602 lock_user_struct(target_fl
, arg3
, 1);
3603 fl
.l_type
= tswap16(target_fl
->l_type
);
3604 fl
.l_whence
= tswap16(target_fl
->l_whence
);
3605 fl
.l_start
= tswap64(target_fl
->l_start
);
3606 fl
.l_len
= tswap64(target_fl
->l_len
);
3607 fl
.l_pid
= tswapl(target_fl
->l_pid
);
3608 unlock_user_struct(target_fl
, arg3
, 0);
3610 ret
= get_errno(fcntl(arg1
, arg2
, &fl
));
3613 ret
= get_errno(do_fcntl(arg1
, arg2
, arg3
));
3619 #ifdef TARGET_NR_security
3620 case TARGET_NR_security
:
3623 #ifdef TARGET_NR_getpagesize
3624 case TARGET_NR_getpagesize
:
3625 ret
= TARGET_PAGE_SIZE
;
3628 case TARGET_NR_gettid
:
3629 ret
= get_errno(gettid());
3631 case TARGET_NR_readahead
:
3633 #ifdef TARGET_NR_setxattr
3634 case TARGET_NR_setxattr
:
3635 case TARGET_NR_lsetxattr
:
3636 case TARGET_NR_fsetxattr
:
3637 case TARGET_NR_getxattr
:
3638 case TARGET_NR_lgetxattr
:
3639 case TARGET_NR_fgetxattr
:
3640 case TARGET_NR_listxattr
:
3641 case TARGET_NR_llistxattr
:
3642 case TARGET_NR_flistxattr
:
3643 case TARGET_NR_removexattr
:
3644 case TARGET_NR_lremovexattr
:
3645 case TARGET_NR_fremovexattr
:
3646 goto unimplemented_nowarn
;
3648 #ifdef TARGET_NR_set_thread_area
3649 case TARGET_NR_set_thread_area
:
3650 case TARGET_NR_get_thread_area
:
3651 goto unimplemented_nowarn
;
3655 gemu_log("qemu: Unsupported syscall: %d\n", num
);
3656 #if defined(TARGET_NR_setxattr) || defined(TARGET_NR_set_thread_area)
3657 unimplemented_nowarn
:
3664 gemu_log(" = %ld\n", ret
);