]>
Commit | Line | Data |
---|---|---|
31e31b8a FB |
1 | /* |
2 | * Linux syscalls | |
3 | * | |
4 | * Copyright (c) 2003 Fabrice Bellard | |
5 | * | |
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. | |
10 | * | |
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. | |
15 | * | |
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. | |
19 | */ | |
20 | #include <stdlib.h> | |
21 | #include <stdio.h> | |
22 | #include <stdarg.h> | |
04369ff2 | 23 | #include <string.h> |
31e31b8a FB |
24 | #include <elf.h> |
25 | #include <endian.h> | |
26 | #include <errno.h> | |
27 | #include <unistd.h> | |
28 | #include <fcntl.h> | |
7854b056 | 29 | #include <time.h> |
31e31b8a FB |
30 | #include <sys/types.h> |
31 | #include <sys/wait.h> | |
32 | #include <sys/time.h> | |
33 | #include <sys/stat.h> | |
34 | #include <sys/mount.h> | |
35 | #include <sys/resource.h> | |
36 | #include <sys/mman.h> | |
37 | #include <sys/swap.h> | |
38 | #include <signal.h> | |
39 | #include <sched.h> | |
40 | #include <sys/socket.h> | |
41 | #include <sys/uio.h> | |
9de5e440 | 42 | #include <sys/poll.h> |
32f36bce | 43 | #include <sys/times.h> |
72f03900 | 44 | //#include <sys/user.h> |
7854b056 | 45 | #include <netinet/tcp.h> |
31e31b8a FB |
46 | |
47 | #define termios host_termios | |
48 | #define winsize host_winsize | |
49 | #define termio host_termio | |
04369ff2 FB |
50 | #define sgttyb host_sgttyb /* same as target */ |
51 | #define tchars host_tchars /* same as target */ | |
52 | #define ltchars host_ltchars /* same as target */ | |
31e31b8a FB |
53 | |
54 | #include <linux/termios.h> | |
55 | #include <linux/unistd.h> | |
56 | #include <linux/utsname.h> | |
57 | #include <linux/cdrom.h> | |
58 | #include <linux/hdreg.h> | |
59 | #include <linux/soundcard.h> | |
dab2ed99 | 60 | #include <linux/dirent.h> |
19b84f3c | 61 | #include <linux/kd.h> |
31e31b8a | 62 | |
3ef693a0 | 63 | #include "qemu.h" |
31e31b8a | 64 | |
72f03900 | 65 | //#define DEBUG |
31e31b8a | 66 | |
1a9353d2 FB |
67 | //#include <linux/msdos_fs.h> |
68 | #define VFAT_IOCTL_READDIR_BOTH _IOR('r', 1, struct dirent [2]) | |
69 | #define VFAT_IOCTL_READDIR_SHORT _IOR('r', 2, struct dirent [2]) | |
70 | ||
9de5e440 FB |
71 | void host_to_target_siginfo(target_siginfo_t *tinfo, const siginfo_t *info); |
72 | void target_to_host_siginfo(siginfo_t *info, const target_siginfo_t *tinfo); | |
66fb9763 FB |
73 | long do_sigreturn(CPUX86State *env); |
74 | long do_rt_sigreturn(CPUX86State *env); | |
75 | ||
31e31b8a | 76 | #define __NR_sys_uname __NR_uname |
72f03900 | 77 | #define __NR_sys_getcwd1 __NR_getcwd |
31e31b8a FB |
78 | #define __NR_sys_statfs __NR_statfs |
79 | #define __NR_sys_fstatfs __NR_fstatfs | |
72f03900 | 80 | #define __NR_sys_getdents __NR_getdents |
dab2ed99 | 81 | #define __NR_sys_getdents64 __NR_getdents64 |
66fb9763 | 82 | #define __NR_sys_rt_sigqueueinfo __NR_rt_sigqueueinfo |
31e31b8a | 83 | |
27725c1d | 84 | #if defined(__alpha__) || defined (__ia64__) |
9af9eaaa FB |
85 | #define __NR__llseek __NR_lseek |
86 | #endif | |
87 | ||
72f03900 | 88 | #ifdef __NR_gettid |
31e31b8a | 89 | _syscall0(int, gettid) |
72f03900 FB |
90 | #else |
91 | static int gettid(void) { | |
92 | return -ENOSYS; | |
93 | } | |
94 | #endif | |
31e31b8a | 95 | _syscall1(int,sys_uname,struct new_utsname *,buf) |
72f03900 FB |
96 | _syscall2(int,sys_getcwd1,char *,buf,size_t,size) |
97 | _syscall3(int, sys_getdents, uint, fd, struct dirent *, dirp, uint, count); | |
dab2ed99 | 98 | _syscall3(int, sys_getdents64, uint, fd, struct dirent64 *, dirp, uint, count); |
31e31b8a FB |
99 | _syscall5(int, _llseek, uint, fd, ulong, hi, ulong, lo, |
100 | loff_t *, res, uint, wh); | |
72f03900 FB |
101 | _syscall2(int,sys_statfs,const char *,path,struct kernel_statfs *,buf) |
102 | _syscall2(int,sys_fstatfs,int,fd,struct kernel_statfs *,buf) | |
66fb9763 | 103 | _syscall3(int,sys_rt_sigqueueinfo,int,pid,int,sig,siginfo_t *,uinfo) |
ec86b0fb FB |
104 | #ifdef __NR_exit_group |
105 | _syscall1(int,exit_group,int,error_code) | |
106 | #endif | |
66fb9763 FB |
107 | |
108 | extern int personality(int); | |
9de5e440 FB |
109 | extern int flock(int, int); |
110 | extern int setfsuid(int); | |
111 | extern int setfsgid(int); | |
5cd4393b FB |
112 | extern int setresuid(uid_t, uid_t, uid_t); |
113 | extern int getresuid(uid_t *, uid_t *, uid_t *); | |
114 | extern int setresgid(gid_t, gid_t, gid_t); | |
115 | extern int getresgid(gid_t *, gid_t *, gid_t *); | |
19b84f3c | 116 | extern int setgroups(int, gid_t *); |
31e31b8a FB |
117 | |
118 | static inline long get_errno(long ret) | |
119 | { | |
120 | if (ret == -1) | |
121 | return -errno; | |
122 | else | |
123 | return ret; | |
124 | } | |
125 | ||
126 | static inline int is_error(long ret) | |
127 | { | |
128 | return (unsigned long)ret >= (unsigned long)(-4096); | |
129 | } | |
130 | ||
131 | static char *target_brk; | |
132 | static char *target_original_brk; | |
133 | ||
134 | void target_set_brk(char *new_brk) | |
135 | { | |
136 | target_brk = new_brk; | |
137 | target_original_brk = new_brk; | |
138 | } | |
139 | ||
140 | static long do_brk(char *new_brk) | |
141 | { | |
142 | char *brk_page; | |
143 | long mapped_addr; | |
144 | int new_alloc_size; | |
145 | ||
146 | if (!new_brk) | |
147 | return (long)target_brk; | |
148 | if (new_brk < target_original_brk) | |
149 | return -ENOMEM; | |
150 | ||
54936004 | 151 | brk_page = (char *)HOST_PAGE_ALIGN((unsigned long)target_brk); |
31e31b8a FB |
152 | |
153 | /* If the new brk is less than this, set it and we're done... */ | |
154 | if (new_brk < brk_page) { | |
155 | target_brk = new_brk; | |
156 | return (long)target_brk; | |
157 | } | |
158 | ||
159 | /* We need to allocate more memory after the brk... */ | |
54936004 FB |
160 | new_alloc_size = HOST_PAGE_ALIGN(new_brk - brk_page + 1); |
161 | mapped_addr = get_errno(target_mmap((unsigned long)brk_page, new_alloc_size, | |
162 | PROT_READ|PROT_WRITE, | |
163 | MAP_ANON|MAP_FIXED|MAP_PRIVATE, 0, 0)); | |
31e31b8a FB |
164 | if (is_error(mapped_addr)) { |
165 | return mapped_addr; | |
166 | } else { | |
167 | target_brk = new_brk; | |
168 | return (long)target_brk; | |
169 | } | |
170 | } | |
171 | ||
172 | static inline fd_set *target_to_host_fds(fd_set *fds, | |
173 | target_long *target_fds, int n) | |
174 | { | |
7854b056 | 175 | #if !defined(BSWAP_NEEDED) && !defined(WORDS_BIGENDIAN) |
31e31b8a FB |
176 | return (fd_set *)target_fds; |
177 | #else | |
178 | int i, b; | |
179 | if (target_fds) { | |
180 | FD_ZERO(fds); | |
181 | for(i = 0;i < n; i++) { | |
182 | b = (tswapl(target_fds[i / TARGET_LONG_BITS]) >> | |
183 | (i & (TARGET_LONG_BITS - 1))) & 1; | |
184 | if (b) | |
185 | FD_SET(i, fds); | |
186 | } | |
187 | return fds; | |
188 | } else { | |
189 | return NULL; | |
190 | } | |
191 | #endif | |
192 | } | |
193 | ||
194 | static inline void host_to_target_fds(target_long *target_fds, | |
195 | fd_set *fds, int n) | |
196 | { | |
7854b056 | 197 | #if !defined(BSWAP_NEEDED) && !defined(WORDS_BIGENDIAN) |
31e31b8a FB |
198 | /* nothing to do */ |
199 | #else | |
200 | int i, nw, j, k; | |
201 | target_long v; | |
202 | ||
203 | if (target_fds) { | |
204 | nw = n / TARGET_LONG_BITS; | |
205 | k = 0; | |
206 | for(i = 0;i < nw; i++) { | |
207 | v = 0; | |
208 | for(j = 0; j < TARGET_LONG_BITS; j++) { | |
209 | v |= ((FD_ISSET(k, fds) != 0) << j); | |
210 | k++; | |
211 | } | |
212 | target_fds[i] = tswapl(v); | |
213 | } | |
214 | } | |
215 | #endif | |
216 | } | |
217 | ||
b409186b FB |
218 | static inline void host_to_target_rusage(struct target_rusage *target_rusage, |
219 | const struct rusage *rusage) | |
220 | { | |
221 | target_rusage->ru_utime.tv_sec = tswapl(rusage->ru_utime.tv_sec); | |
222 | target_rusage->ru_utime.tv_usec = tswapl(rusage->ru_utime.tv_usec); | |
223 | target_rusage->ru_stime.tv_sec = tswapl(rusage->ru_stime.tv_sec); | |
224 | target_rusage->ru_stime.tv_usec = tswapl(rusage->ru_stime.tv_usec); | |
225 | target_rusage->ru_maxrss = tswapl(rusage->ru_maxrss); | |
226 | target_rusage->ru_ixrss = tswapl(rusage->ru_ixrss); | |
227 | target_rusage->ru_idrss = tswapl(rusage->ru_idrss); | |
228 | target_rusage->ru_isrss = tswapl(rusage->ru_isrss); | |
229 | target_rusage->ru_minflt = tswapl(rusage->ru_minflt); | |
230 | target_rusage->ru_majflt = tswapl(rusage->ru_majflt); | |
231 | target_rusage->ru_nswap = tswapl(rusage->ru_nswap); | |
232 | target_rusage->ru_inblock = tswapl(rusage->ru_inblock); | |
233 | target_rusage->ru_oublock = tswapl(rusage->ru_oublock); | |
234 | target_rusage->ru_msgsnd = tswapl(rusage->ru_msgsnd); | |
235 | target_rusage->ru_msgrcv = tswapl(rusage->ru_msgrcv); | |
236 | target_rusage->ru_nsignals = tswapl(rusage->ru_nsignals); | |
237 | target_rusage->ru_nvcsw = tswapl(rusage->ru_nvcsw); | |
238 | target_rusage->ru_nivcsw = tswapl(rusage->ru_nivcsw); | |
239 | } | |
240 | ||
66fb9763 | 241 | static inline void target_to_host_timeval(struct timeval *tv, |
5cd4393b | 242 | const struct target_timeval *target_tv) |
31e31b8a | 243 | { |
66fb9763 FB |
244 | tv->tv_sec = tswapl(target_tv->tv_sec); |
245 | tv->tv_usec = tswapl(target_tv->tv_usec); | |
31e31b8a FB |
246 | } |
247 | ||
66fb9763 | 248 | static inline void host_to_target_timeval(struct target_timeval *target_tv, |
5cd4393b | 249 | const struct timeval *tv) |
31e31b8a | 250 | { |
66fb9763 FB |
251 | target_tv->tv_sec = tswapl(tv->tv_sec); |
252 | target_tv->tv_usec = tswapl(tv->tv_usec); | |
31e31b8a FB |
253 | } |
254 | ||
255 | ||
256 | static long do_select(long n, | |
257 | target_long *target_rfds, target_long *target_wfds, | |
258 | target_long *target_efds, struct target_timeval *target_tv) | |
259 | { | |
260 | fd_set rfds, wfds, efds; | |
261 | fd_set *rfds_ptr, *wfds_ptr, *efds_ptr; | |
262 | struct timeval tv, *tv_ptr; | |
263 | long ret; | |
264 | ||
265 | rfds_ptr = target_to_host_fds(&rfds, target_rfds, n); | |
266 | wfds_ptr = target_to_host_fds(&wfds, target_wfds, n); | |
267 | efds_ptr = target_to_host_fds(&efds, target_efds, n); | |
268 | ||
269 | if (target_tv) { | |
5cd4393b | 270 | target_to_host_timeval(&tv, target_tv); |
31e31b8a FB |
271 | tv_ptr = &tv; |
272 | } else { | |
273 | tv_ptr = NULL; | |
274 | } | |
275 | ret = get_errno(select(n, rfds_ptr, wfds_ptr, efds_ptr, tv_ptr)); | |
276 | if (!is_error(ret)) { | |
277 | host_to_target_fds(target_rfds, rfds_ptr, n); | |
278 | host_to_target_fds(target_wfds, wfds_ptr, n); | |
279 | host_to_target_fds(target_efds, efds_ptr, n); | |
280 | ||
281 | if (target_tv) { | |
5cd4393b | 282 | host_to_target_timeval(target_tv, &tv); |
31e31b8a FB |
283 | } |
284 | } | |
285 | return ret; | |
286 | } | |
287 | ||
7854b056 FB |
288 | static inline void target_to_host_sockaddr(struct sockaddr *addr, |
289 | struct target_sockaddr *target_addr, | |
290 | socklen_t len) | |
291 | { | |
292 | memcpy(addr, target_addr, len); | |
293 | addr->sa_family = tswap16(target_addr->sa_family); | |
294 | } | |
295 | ||
296 | static inline void host_to_target_sockaddr(struct target_sockaddr *target_addr, | |
297 | struct sockaddr *addr, | |
298 | socklen_t len) | |
299 | { | |
300 | memcpy(target_addr, addr, len); | |
301 | target_addr->sa_family = tswap16(addr->sa_family); | |
302 | } | |
303 | ||
304 | static inline void target_to_host_cmsg(struct msghdr *msgh, | |
305 | struct target_msghdr *target_msgh) | |
306 | { | |
307 | struct cmsghdr *cmsg = CMSG_FIRSTHDR(msgh); | |
308 | struct target_cmsghdr *target_cmsg = TARGET_CMSG_FIRSTHDR(target_msgh); | |
309 | socklen_t space = 0; | |
310 | ||
311 | while (cmsg && target_cmsg) { | |
312 | void *data = CMSG_DATA(cmsg); | |
313 | void *target_data = TARGET_CMSG_DATA(target_cmsg); | |
314 | ||
315 | int len = tswapl(target_cmsg->cmsg_len) | |
316 | - TARGET_CMSG_ALIGN(sizeof (struct target_cmsghdr)); | |
317 | ||
318 | space += CMSG_SPACE(len); | |
319 | if (space > msgh->msg_controllen) { | |
320 | space -= CMSG_SPACE(len); | |
321 | gemu_log("Host cmsg overflow"); | |
322 | break; | |
323 | } | |
324 | ||
325 | cmsg->cmsg_level = tswap32(target_cmsg->cmsg_level); | |
326 | cmsg->cmsg_type = tswap32(target_cmsg->cmsg_type); | |
327 | cmsg->cmsg_len = CMSG_LEN(len); | |
328 | ||
329 | if (cmsg->cmsg_level != SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS) { | |
330 | gemu_log("Unsupported ancillary data: %d/%d\n", cmsg->cmsg_level, cmsg->cmsg_type); | |
331 | memcpy(data, target_data, len); | |
332 | } else { | |
333 | int *fd = (int *)data; | |
334 | int *target_fd = (int *)target_data; | |
335 | int i, numfds = len / sizeof(int); | |
336 | ||
337 | for (i = 0; i < numfds; i++) | |
338 | fd[i] = tswap32(target_fd[i]); | |
339 | } | |
340 | ||
341 | cmsg = CMSG_NXTHDR(msgh, cmsg); | |
342 | target_cmsg = TARGET_CMSG_NXTHDR(target_msgh, target_cmsg); | |
343 | } | |
344 | ||
345 | msgh->msg_controllen = space; | |
346 | } | |
347 | ||
348 | static inline void host_to_target_cmsg(struct target_msghdr *target_msgh, | |
349 | struct msghdr *msgh) | |
350 | { | |
351 | struct cmsghdr *cmsg = CMSG_FIRSTHDR(msgh); | |
352 | struct target_cmsghdr *target_cmsg = TARGET_CMSG_FIRSTHDR(target_msgh); | |
353 | socklen_t space = 0; | |
354 | ||
355 | while (cmsg && target_cmsg) { | |
356 | void *data = CMSG_DATA(cmsg); | |
357 | void *target_data = TARGET_CMSG_DATA(target_cmsg); | |
358 | ||
359 | int len = cmsg->cmsg_len - CMSG_ALIGN(sizeof (struct cmsghdr)); | |
360 | ||
361 | space += TARGET_CMSG_SPACE(len); | |
362 | if (space > tswapl(target_msgh->msg_controllen)) { | |
363 | space -= TARGET_CMSG_SPACE(len); | |
364 | gemu_log("Target cmsg overflow"); | |
365 | break; | |
366 | } | |
367 | ||
368 | target_cmsg->cmsg_level = tswap32(cmsg->cmsg_level); | |
369 | target_cmsg->cmsg_type = tswap32(cmsg->cmsg_type); | |
370 | target_cmsg->cmsg_len = tswapl(TARGET_CMSG_LEN(len)); | |
371 | ||
372 | if (cmsg->cmsg_level != SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS) { | |
373 | gemu_log("Unsupported ancillary data: %d/%d\n", cmsg->cmsg_level, cmsg->cmsg_type); | |
374 | memcpy(target_data, data, len); | |
375 | } else { | |
376 | int *fd = (int *)data; | |
377 | int *target_fd = (int *)target_data; | |
378 | int i, numfds = len / sizeof(int); | |
379 | ||
380 | for (i = 0; i < numfds; i++) | |
381 | target_fd[i] = tswap32(fd[i]); | |
382 | } | |
383 | ||
384 | cmsg = CMSG_NXTHDR(msgh, cmsg); | |
385 | target_cmsg = TARGET_CMSG_NXTHDR(target_msgh, target_cmsg); | |
386 | } | |
387 | ||
388 | msgh->msg_controllen = tswapl(space); | |
389 | } | |
390 | ||
391 | static long do_setsockopt(int sockfd, int level, int optname, | |
392 | void *optval, socklen_t optlen) | |
393 | { | |
394 | if (level == SOL_TCP) { | |
395 | /* TCP options all take an 'int' value. */ | |
396 | int val; | |
397 | ||
398 | if (optlen < sizeof(uint32_t)) | |
399 | return -EINVAL; | |
400 | ||
401 | val = tswap32(*(uint32_t *)optval); | |
402 | return get_errno(setsockopt(sockfd, level, optname, &val, sizeof(val))); | |
403 | } | |
404 | ||
405 | else if (level != SOL_SOCKET) { | |
406 | gemu_log("Unsupported setsockopt level: %d\n", level); | |
407 | return -ENOSYS; | |
408 | } | |
409 | ||
410 | switch (optname) { | |
411 | /* Options with 'int' argument. */ | |
412 | case SO_DEBUG: | |
413 | case SO_REUSEADDR: | |
414 | case SO_TYPE: | |
415 | case SO_ERROR: | |
416 | case SO_DONTROUTE: | |
417 | case SO_BROADCAST: | |
418 | case SO_SNDBUF: | |
419 | case SO_RCVBUF: | |
420 | case SO_KEEPALIVE: | |
421 | case SO_OOBINLINE: | |
422 | case SO_NO_CHECK: | |
423 | case SO_PRIORITY: | |
424 | case SO_BSDCOMPAT: | |
425 | case SO_PASSCRED: | |
426 | case SO_TIMESTAMP: | |
427 | case SO_RCVLOWAT: | |
428 | case SO_RCVTIMEO: | |
429 | case SO_SNDTIMEO: | |
430 | { | |
431 | int val; | |
432 | if (optlen < sizeof(uint32_t)) | |
433 | return -EINVAL; | |
434 | val = tswap32(*(uint32_t *)optval); | |
435 | return get_errno(setsockopt(sockfd, level, optname, &val, sizeof(val))); | |
436 | } | |
437 | ||
438 | default: | |
439 | gemu_log("Unsupported setsockopt SOL_SOCKET option: %d\n", optname); | |
440 | return -ENOSYS; | |
441 | } | |
442 | } | |
443 | ||
444 | static long do_getsockopt(int sockfd, int level, int optname, | |
445 | void *optval, socklen_t *optlen) | |
446 | { | |
447 | gemu_log("getsockopt not yet supported\n"); | |
448 | return -ENOSYS; | |
449 | } | |
450 | ||
451 | static long do_socketcall(int num, int32_t *vptr) | |
31e31b8a FB |
452 | { |
453 | long ret; | |
454 | ||
455 | switch(num) { | |
456 | case SOCKOP_socket: | |
7854b056 FB |
457 | { |
458 | int domain = tswap32(vptr[0]); | |
459 | int type = tswap32(vptr[1]); | |
460 | int protocol = tswap32(vptr[2]); | |
461 | ||
462 | ret = get_errno(socket(domain, type, protocol)); | |
463 | } | |
31e31b8a FB |
464 | break; |
465 | case SOCKOP_bind: | |
7854b056 FB |
466 | { |
467 | int sockfd = tswap32(vptr[0]); | |
468 | void *target_addr = (void *)tswap32(vptr[1]); | |
469 | socklen_t addrlen = tswap32(vptr[2]); | |
470 | void *addr = alloca(addrlen); | |
471 | ||
472 | target_to_host_sockaddr(addr, target_addr, addrlen); | |
473 | ret = get_errno(bind(sockfd, addr, addrlen)); | |
474 | } | |
31e31b8a FB |
475 | break; |
476 | case SOCKOP_connect: | |
7854b056 FB |
477 | { |
478 | int sockfd = tswap32(vptr[0]); | |
479 | void *target_addr = (void *)tswap32(vptr[1]); | |
480 | socklen_t addrlen = tswap32(vptr[2]); | |
481 | void *addr = alloca(addrlen); | |
482 | ||
483 | target_to_host_sockaddr(addr, target_addr, addrlen); | |
484 | ret = get_errno(connect(sockfd, addr, addrlen)); | |
485 | } | |
31e31b8a FB |
486 | break; |
487 | case SOCKOP_listen: | |
7854b056 FB |
488 | { |
489 | int sockfd = tswap32(vptr[0]); | |
490 | int backlog = tswap32(vptr[1]); | |
491 | ||
492 | ret = get_errno(listen(sockfd, backlog)); | |
493 | } | |
31e31b8a FB |
494 | break; |
495 | case SOCKOP_accept: | |
496 | { | |
7854b056 FB |
497 | int sockfd = tswap32(vptr[0]); |
498 | void *target_addr = (void *)tswap32(vptr[1]); | |
499 | uint32_t *target_addrlen = (void *)tswap32(vptr[2]); | |
500 | socklen_t addrlen = tswap32(*target_addrlen); | |
501 | void *addr = alloca(addrlen); | |
502 | ||
503 | ret = get_errno(accept(sockfd, addr, &addrlen)); | |
504 | if (!is_error(ret)) { | |
505 | host_to_target_sockaddr(target_addr, addr, addrlen); | |
506 | *target_addrlen = tswap32(addrlen); | |
507 | } | |
31e31b8a FB |
508 | } |
509 | break; | |
510 | case SOCKOP_getsockname: | |
511 | { | |
7854b056 FB |
512 | int sockfd = tswap32(vptr[0]); |
513 | void *target_addr = (void *)tswap32(vptr[1]); | |
514 | uint32_t *target_addrlen = (void *)tswap32(vptr[2]); | |
515 | socklen_t addrlen = tswap32(*target_addrlen); | |
516 | void *addr = alloca(addrlen); | |
517 | ||
518 | ret = get_errno(getsockname(sockfd, addr, &addrlen)); | |
519 | if (!is_error(ret)) { | |
520 | host_to_target_sockaddr(target_addr, addr, addrlen); | |
521 | *target_addrlen = tswap32(addrlen); | |
522 | } | |
31e31b8a FB |
523 | } |
524 | break; | |
525 | case SOCKOP_getpeername: | |
526 | { | |
7854b056 FB |
527 | int sockfd = tswap32(vptr[0]); |
528 | void *target_addr = (void *)tswap32(vptr[1]); | |
529 | uint32_t *target_addrlen = (void *)tswap32(vptr[2]); | |
530 | socklen_t addrlen = tswap32(*target_addrlen); | |
531 | void *addr = alloca(addrlen); | |
532 | ||
533 | ret = get_errno(getpeername(sockfd, addr, &addrlen)); | |
534 | if (!is_error(ret)) { | |
535 | host_to_target_sockaddr(target_addr, addr, addrlen); | |
536 | *target_addrlen = tswap32(addrlen); | |
537 | } | |
31e31b8a FB |
538 | } |
539 | break; | |
540 | case SOCKOP_socketpair: | |
541 | { | |
7854b056 FB |
542 | int domain = tswap32(vptr[0]); |
543 | int type = tswap32(vptr[1]); | |
544 | int protocol = tswap32(vptr[2]); | |
545 | int32_t *target_tab = (void *)tswap32(vptr[3]); | |
31e31b8a | 546 | int tab[2]; |
7854b056 FB |
547 | |
548 | ret = get_errno(socketpair(domain, type, protocol, tab)); | |
31e31b8a FB |
549 | if (!is_error(ret)) { |
550 | target_tab[0] = tswap32(tab[0]); | |
551 | target_tab[1] = tswap32(tab[1]); | |
552 | } | |
553 | } | |
554 | break; | |
555 | case SOCKOP_send: | |
7854b056 FB |
556 | { |
557 | int sockfd = tswap32(vptr[0]); | |
558 | void *msg = (void *)tswap32(vptr[1]); | |
559 | size_t len = tswap32(vptr[2]); | |
560 | int flags = tswap32(vptr[3]); | |
561 | ||
562 | ret = get_errno(send(sockfd, msg, len, flags)); | |
563 | } | |
31e31b8a FB |
564 | break; |
565 | case SOCKOP_recv: | |
7854b056 FB |
566 | { |
567 | int sockfd = tswap32(vptr[0]); | |
568 | void *msg = (void *)tswap32(vptr[1]); | |
569 | size_t len = tswap32(vptr[2]); | |
570 | int flags = tswap32(vptr[3]); | |
571 | ||
572 | ret = get_errno(recv(sockfd, msg, len, flags)); | |
573 | } | |
31e31b8a FB |
574 | break; |
575 | case SOCKOP_sendto: | |
7854b056 FB |
576 | { |
577 | int sockfd = tswap32(vptr[0]); | |
578 | void *msg = (void *)tswap32(vptr[1]); | |
579 | size_t len = tswap32(vptr[2]); | |
580 | int flags = tswap32(vptr[3]); | |
581 | void *target_addr = (void *)tswap32(vptr[4]); | |
582 | socklen_t addrlen = tswap32(vptr[5]); | |
583 | void *addr = alloca(addrlen); | |
584 | ||
585 | target_to_host_sockaddr(addr, target_addr, addrlen); | |
586 | ret = get_errno(sendto(sockfd, msg, len, flags, addr, addrlen)); | |
587 | } | |
31e31b8a FB |
588 | break; |
589 | case SOCKOP_recvfrom: | |
590 | { | |
7854b056 FB |
591 | int sockfd = tswap32(vptr[0]); |
592 | void *msg = (void *)tswap32(vptr[1]); | |
593 | size_t len = tswap32(vptr[2]); | |
594 | int flags = tswap32(vptr[3]); | |
595 | void *target_addr = (void *)tswap32(vptr[4]); | |
596 | uint32_t *target_addrlen = (void *)tswap32(vptr[5]); | |
597 | socklen_t addrlen = tswap32(*target_addrlen); | |
598 | void *addr = alloca(addrlen); | |
599 | ||
600 | ret = get_errno(recvfrom(sockfd, msg, len, flags, addr, &addrlen)); | |
601 | if (!is_error(ret)) { | |
602 | host_to_target_sockaddr(target_addr, addr, addrlen); | |
603 | *target_addrlen = tswap32(addrlen); | |
604 | } | |
31e31b8a FB |
605 | } |
606 | break; | |
607 | case SOCKOP_shutdown: | |
7854b056 FB |
608 | { |
609 | int sockfd = tswap32(vptr[0]); | |
610 | int how = tswap32(vptr[1]); | |
611 | ||
612 | ret = get_errno(shutdown(sockfd, how)); | |
613 | } | |
31e31b8a FB |
614 | break; |
615 | case SOCKOP_sendmsg: | |
616 | case SOCKOP_recvmsg: | |
1a9353d2 FB |
617 | { |
618 | int fd; | |
619 | struct target_msghdr *msgp; | |
620 | struct msghdr msg; | |
621 | int flags, count, i; | |
622 | struct iovec *vec; | |
623 | struct target_iovec *target_vec; | |
624 | ||
7854b056 | 625 | msgp = (void *)tswap32(vptr[1]); |
1a9353d2 FB |
626 | msg.msg_name = (void *)tswapl(msgp->msg_name); |
627 | msg.msg_namelen = tswapl(msgp->msg_namelen); | |
7854b056 FB |
628 | msg.msg_controllen = 2 * tswapl(msgp->msg_controllen); |
629 | msg.msg_control = alloca(msg.msg_controllen); | |
1a9353d2 FB |
630 | msg.msg_flags = tswap32(msgp->msg_flags); |
631 | ||
632 | count = tswapl(msgp->msg_iovlen); | |
633 | vec = alloca(count * sizeof(struct iovec)); | |
634 | target_vec = (void *)tswapl(msgp->msg_iov); | |
635 | for(i = 0;i < count; i++) { | |
636 | vec[i].iov_base = (void *)tswapl(target_vec[i].iov_base); | |
637 | vec[i].iov_len = tswapl(target_vec[i].iov_len); | |
638 | } | |
639 | msg.msg_iovlen = count; | |
640 | msg.msg_iov = vec; | |
641 | ||
7854b056 FB |
642 | fd = tswap32(vptr[0]); |
643 | flags = tswap32(vptr[2]); | |
644 | if (num == SOCKOP_sendmsg) { | |
645 | target_to_host_cmsg(&msg, msgp); | |
646 | ret = get_errno(sendmsg(fd, &msg, flags)); | |
647 | } else { | |
648 | ret = get_errno(recvmsg(fd, &msg, flags)); | |
649 | if (!is_error(ret)) | |
650 | host_to_target_cmsg(msgp, &msg); | |
651 | } | |
1a9353d2 FB |
652 | } |
653 | break; | |
31e31b8a | 654 | case SOCKOP_setsockopt: |
7854b056 FB |
655 | { |
656 | int sockfd = tswap32(vptr[0]); | |
657 | int level = tswap32(vptr[1]); | |
658 | int optname = tswap32(vptr[2]); | |
659 | void *optval = (void *)tswap32(vptr[3]); | |
660 | socklen_t optlen = tswap32(vptr[4]); | |
661 | ||
662 | ret = do_setsockopt(sockfd, level, optname, optval, optlen); | |
663 | } | |
664 | break; | |
31e31b8a | 665 | case SOCKOP_getsockopt: |
7854b056 FB |
666 | { |
667 | int sockfd = tswap32(vptr[0]); | |
668 | int level = tswap32(vptr[1]); | |
669 | int optname = tswap32(vptr[2]); | |
670 | void *optval = (void *)tswap32(vptr[3]); | |
671 | uint32_t *target_len = (void *)tswap32(vptr[4]); | |
672 | socklen_t optlen = tswap32(*target_len); | |
673 | ||
674 | ret = do_getsockopt(sockfd, level, optname, optval, &optlen); | |
675 | if (!is_error(ret)) | |
676 | *target_len = tswap32(optlen); | |
677 | } | |
678 | break; | |
31e31b8a FB |
679 | default: |
680 | gemu_log("Unsupported socketcall: %d\n", num); | |
681 | ret = -ENOSYS; | |
682 | break; | |
683 | } | |
684 | return ret; | |
685 | } | |
686 | ||
687 | /* kernel structure types definitions */ | |
688 | #define IFNAMSIZ 16 | |
689 | ||
690 | #define STRUCT(name, list...) STRUCT_ ## name, | |
691 | #define STRUCT_SPECIAL(name) STRUCT_ ## name, | |
692 | enum { | |
693 | #include "syscall_types.h" | |
694 | }; | |
695 | #undef STRUCT | |
696 | #undef STRUCT_SPECIAL | |
697 | ||
698 | #define STRUCT(name, list...) const argtype struct_ ## name ## _def[] = { list, TYPE_NULL }; | |
699 | #define STRUCT_SPECIAL(name) | |
700 | #include "syscall_types.h" | |
701 | #undef STRUCT | |
702 | #undef STRUCT_SPECIAL | |
703 | ||
704 | typedef struct IOCTLEntry { | |
705 | int target_cmd; | |
706 | int host_cmd; | |
707 | const char *name; | |
708 | int access; | |
1a9353d2 | 709 | const argtype arg_type[5]; |
31e31b8a FB |
710 | } IOCTLEntry; |
711 | ||
712 | #define IOC_R 0x0001 | |
713 | #define IOC_W 0x0002 | |
714 | #define IOC_RW (IOC_R | IOC_W) | |
715 | ||
716 | #define MAX_STRUCT_SIZE 4096 | |
717 | ||
718 | const IOCTLEntry ioctl_entries[] = { | |
719 | #define IOCTL(cmd, access, types...) \ | |
720 | { TARGET_ ## cmd, cmd, #cmd, access, { types } }, | |
721 | #include "ioctls.h" | |
722 | { 0, 0, }, | |
723 | }; | |
724 | ||
725 | static long do_ioctl(long fd, long cmd, long arg) | |
726 | { | |
727 | const IOCTLEntry *ie; | |
728 | const argtype *arg_type; | |
729 | long ret; | |
730 | uint8_t buf_temp[MAX_STRUCT_SIZE]; | |
731 | ||
732 | ie = ioctl_entries; | |
733 | for(;;) { | |
734 | if (ie->target_cmd == 0) { | |
735 | gemu_log("Unsupported ioctl: cmd=0x%04lx\n", cmd); | |
736 | return -ENOSYS; | |
737 | } | |
738 | if (ie->target_cmd == cmd) | |
739 | break; | |
740 | ie++; | |
741 | } | |
742 | arg_type = ie->arg_type; | |
9de5e440 | 743 | #if defined(DEBUG) |
72f03900 FB |
744 | gemu_log("ioctl: cmd=0x%04lx (%s)\n", cmd, ie->name); |
745 | #endif | |
31e31b8a FB |
746 | switch(arg_type[0]) { |
747 | case TYPE_NULL: | |
748 | /* no argument */ | |
749 | ret = get_errno(ioctl(fd, ie->host_cmd)); | |
750 | break; | |
751 | case TYPE_PTRVOID: | |
752 | case TYPE_INT: | |
753 | /* int argment */ | |
754 | ret = get_errno(ioctl(fd, ie->host_cmd, arg)); | |
755 | break; | |
756 | case TYPE_PTR: | |
757 | arg_type++; | |
758 | switch(ie->access) { | |
759 | case IOC_R: | |
760 | ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp)); | |
761 | if (!is_error(ret)) { | |
762 | thunk_convert((void *)arg, buf_temp, arg_type, THUNK_TARGET); | |
763 | } | |
764 | break; | |
765 | case IOC_W: | |
766 | thunk_convert(buf_temp, (void *)arg, arg_type, THUNK_HOST); | |
767 | ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp)); | |
768 | break; | |
769 | default: | |
770 | case IOC_RW: | |
771 | thunk_convert(buf_temp, (void *)arg, arg_type, THUNK_HOST); | |
772 | ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp)); | |
773 | if (!is_error(ret)) { | |
774 | thunk_convert((void *)arg, buf_temp, arg_type, THUNK_TARGET); | |
775 | } | |
776 | break; | |
777 | } | |
778 | break; | |
779 | default: | |
780 | gemu_log("Unsupported ioctl type: cmd=0x%04lx type=%d\n", cmd, arg_type[0]); | |
781 | ret = -ENOSYS; | |
782 | break; | |
783 | } | |
784 | return ret; | |
785 | } | |
786 | ||
787 | bitmask_transtbl iflag_tbl[] = { | |
788 | { TARGET_IGNBRK, TARGET_IGNBRK, IGNBRK, IGNBRK }, | |
789 | { TARGET_BRKINT, TARGET_BRKINT, BRKINT, BRKINT }, | |
790 | { TARGET_IGNPAR, TARGET_IGNPAR, IGNPAR, IGNPAR }, | |
791 | { TARGET_PARMRK, TARGET_PARMRK, PARMRK, PARMRK }, | |
792 | { TARGET_INPCK, TARGET_INPCK, INPCK, INPCK }, | |
793 | { TARGET_ISTRIP, TARGET_ISTRIP, ISTRIP, ISTRIP }, | |
794 | { TARGET_INLCR, TARGET_INLCR, INLCR, INLCR }, | |
795 | { TARGET_IGNCR, TARGET_IGNCR, IGNCR, IGNCR }, | |
796 | { TARGET_ICRNL, TARGET_ICRNL, ICRNL, ICRNL }, | |
797 | { TARGET_IUCLC, TARGET_IUCLC, IUCLC, IUCLC }, | |
798 | { TARGET_IXON, TARGET_IXON, IXON, IXON }, | |
799 | { TARGET_IXANY, TARGET_IXANY, IXANY, IXANY }, | |
800 | { TARGET_IXOFF, TARGET_IXOFF, IXOFF, IXOFF }, | |
801 | { TARGET_IMAXBEL, TARGET_IMAXBEL, IMAXBEL, IMAXBEL }, | |
802 | { 0, 0, 0, 0 } | |
803 | }; | |
804 | ||
805 | bitmask_transtbl oflag_tbl[] = { | |
806 | { TARGET_OPOST, TARGET_OPOST, OPOST, OPOST }, | |
807 | { TARGET_OLCUC, TARGET_OLCUC, OLCUC, OLCUC }, | |
808 | { TARGET_ONLCR, TARGET_ONLCR, ONLCR, ONLCR }, | |
809 | { TARGET_OCRNL, TARGET_OCRNL, OCRNL, OCRNL }, | |
810 | { TARGET_ONOCR, TARGET_ONOCR, ONOCR, ONOCR }, | |
811 | { TARGET_ONLRET, TARGET_ONLRET, ONLRET, ONLRET }, | |
812 | { TARGET_OFILL, TARGET_OFILL, OFILL, OFILL }, | |
813 | { TARGET_OFDEL, TARGET_OFDEL, OFDEL, OFDEL }, | |
814 | { TARGET_NLDLY, TARGET_NL0, NLDLY, NL0 }, | |
815 | { TARGET_NLDLY, TARGET_NL1, NLDLY, NL1 }, | |
816 | { TARGET_CRDLY, TARGET_CR0, CRDLY, CR0 }, | |
817 | { TARGET_CRDLY, TARGET_CR1, CRDLY, CR1 }, | |
818 | { TARGET_CRDLY, TARGET_CR2, CRDLY, CR2 }, | |
819 | { TARGET_CRDLY, TARGET_CR3, CRDLY, CR3 }, | |
820 | { TARGET_TABDLY, TARGET_TAB0, TABDLY, TAB0 }, | |
821 | { TARGET_TABDLY, TARGET_TAB1, TABDLY, TAB1 }, | |
822 | { TARGET_TABDLY, TARGET_TAB2, TABDLY, TAB2 }, | |
823 | { TARGET_TABDLY, TARGET_TAB3, TABDLY, TAB3 }, | |
824 | { TARGET_BSDLY, TARGET_BS0, BSDLY, BS0 }, | |
825 | { TARGET_BSDLY, TARGET_BS1, BSDLY, BS1 }, | |
826 | { TARGET_VTDLY, TARGET_VT0, VTDLY, VT0 }, | |
827 | { TARGET_VTDLY, TARGET_VT1, VTDLY, VT1 }, | |
828 | { TARGET_FFDLY, TARGET_FF0, FFDLY, FF0 }, | |
829 | { TARGET_FFDLY, TARGET_FF1, FFDLY, FF1 }, | |
830 | { 0, 0, 0, 0 } | |
831 | }; | |
832 | ||
833 | bitmask_transtbl cflag_tbl[] = { | |
834 | { TARGET_CBAUD, TARGET_B0, CBAUD, B0 }, | |
835 | { TARGET_CBAUD, TARGET_B50, CBAUD, B50 }, | |
836 | { TARGET_CBAUD, TARGET_B75, CBAUD, B75 }, | |
837 | { TARGET_CBAUD, TARGET_B110, CBAUD, B110 }, | |
838 | { TARGET_CBAUD, TARGET_B134, CBAUD, B134 }, | |
839 | { TARGET_CBAUD, TARGET_B150, CBAUD, B150 }, | |
840 | { TARGET_CBAUD, TARGET_B200, CBAUD, B200 }, | |
841 | { TARGET_CBAUD, TARGET_B300, CBAUD, B300 }, | |
842 | { TARGET_CBAUD, TARGET_B600, CBAUD, B600 }, | |
843 | { TARGET_CBAUD, TARGET_B1200, CBAUD, B1200 }, | |
844 | { TARGET_CBAUD, TARGET_B1800, CBAUD, B1800 }, | |
845 | { TARGET_CBAUD, TARGET_B2400, CBAUD, B2400 }, | |
846 | { TARGET_CBAUD, TARGET_B4800, CBAUD, B4800 }, | |
847 | { TARGET_CBAUD, TARGET_B9600, CBAUD, B9600 }, | |
848 | { TARGET_CBAUD, TARGET_B19200, CBAUD, B19200 }, | |
849 | { TARGET_CBAUD, TARGET_B38400, CBAUD, B38400 }, | |
850 | { TARGET_CBAUD, TARGET_B57600, CBAUD, B57600 }, | |
851 | { TARGET_CBAUD, TARGET_B115200, CBAUD, B115200 }, | |
852 | { TARGET_CBAUD, TARGET_B230400, CBAUD, B230400 }, | |
853 | { TARGET_CBAUD, TARGET_B460800, CBAUD, B460800 }, | |
854 | { TARGET_CSIZE, TARGET_CS5, CSIZE, CS5 }, | |
855 | { TARGET_CSIZE, TARGET_CS6, CSIZE, CS6 }, | |
856 | { TARGET_CSIZE, TARGET_CS7, CSIZE, CS7 }, | |
857 | { TARGET_CSIZE, TARGET_CS8, CSIZE, CS8 }, | |
858 | { TARGET_CSTOPB, TARGET_CSTOPB, CSTOPB, CSTOPB }, | |
859 | { TARGET_CREAD, TARGET_CREAD, CREAD, CREAD }, | |
860 | { TARGET_PARENB, TARGET_PARENB, PARENB, PARENB }, | |
861 | { TARGET_PARODD, TARGET_PARODD, PARODD, PARODD }, | |
862 | { TARGET_HUPCL, TARGET_HUPCL, HUPCL, HUPCL }, | |
863 | { TARGET_CLOCAL, TARGET_CLOCAL, CLOCAL, CLOCAL }, | |
864 | { TARGET_CRTSCTS, TARGET_CRTSCTS, CRTSCTS, CRTSCTS }, | |
865 | { 0, 0, 0, 0 } | |
866 | }; | |
867 | ||
868 | bitmask_transtbl lflag_tbl[] = { | |
869 | { TARGET_ISIG, TARGET_ISIG, ISIG, ISIG }, | |
870 | { TARGET_ICANON, TARGET_ICANON, ICANON, ICANON }, | |
871 | { TARGET_XCASE, TARGET_XCASE, XCASE, XCASE }, | |
872 | { TARGET_ECHO, TARGET_ECHO, ECHO, ECHO }, | |
873 | { TARGET_ECHOE, TARGET_ECHOE, ECHOE, ECHOE }, | |
874 | { TARGET_ECHOK, TARGET_ECHOK, ECHOK, ECHOK }, | |
875 | { TARGET_ECHONL, TARGET_ECHONL, ECHONL, ECHONL }, | |
876 | { TARGET_NOFLSH, TARGET_NOFLSH, NOFLSH, NOFLSH }, | |
877 | { TARGET_TOSTOP, TARGET_TOSTOP, TOSTOP, TOSTOP }, | |
878 | { TARGET_ECHOCTL, TARGET_ECHOCTL, ECHOCTL, ECHOCTL }, | |
879 | { TARGET_ECHOPRT, TARGET_ECHOPRT, ECHOPRT, ECHOPRT }, | |
880 | { TARGET_ECHOKE, TARGET_ECHOKE, ECHOKE, ECHOKE }, | |
881 | { TARGET_FLUSHO, TARGET_FLUSHO, FLUSHO, FLUSHO }, | |
882 | { TARGET_PENDIN, TARGET_PENDIN, PENDIN, PENDIN }, | |
883 | { TARGET_IEXTEN, TARGET_IEXTEN, IEXTEN, IEXTEN }, | |
884 | { 0, 0, 0, 0 } | |
885 | }; | |
886 | ||
887 | static void target_to_host_termios (void *dst, const void *src) | |
888 | { | |
889 | struct host_termios *host = dst; | |
890 | const struct target_termios *target = src; | |
891 | ||
892 | host->c_iflag = | |
893 | target_to_host_bitmask(tswap32(target->c_iflag), iflag_tbl); | |
894 | host->c_oflag = | |
895 | target_to_host_bitmask(tswap32(target->c_oflag), oflag_tbl); | |
896 | host->c_cflag = | |
897 | target_to_host_bitmask(tswap32(target->c_cflag), cflag_tbl); | |
898 | host->c_lflag = | |
899 | target_to_host_bitmask(tswap32(target->c_lflag), lflag_tbl); | |
900 | host->c_line = target->c_line; | |
901 | ||
902 | host->c_cc[VINTR] = target->c_cc[TARGET_VINTR]; | |
903 | host->c_cc[VQUIT] = target->c_cc[TARGET_VQUIT]; | |
904 | host->c_cc[VERASE] = target->c_cc[TARGET_VERASE]; | |
905 | host->c_cc[VKILL] = target->c_cc[TARGET_VKILL]; | |
906 | host->c_cc[VEOF] = target->c_cc[TARGET_VEOF]; | |
907 | host->c_cc[VTIME] = target->c_cc[TARGET_VTIME]; | |
908 | host->c_cc[VMIN] = target->c_cc[TARGET_VMIN]; | |
909 | host->c_cc[VSWTC] = target->c_cc[TARGET_VSWTC]; | |
910 | host->c_cc[VSTART] = target->c_cc[TARGET_VSTART]; | |
911 | host->c_cc[VSTOP] = target->c_cc[TARGET_VSTOP]; | |
912 | host->c_cc[VSUSP] = target->c_cc[TARGET_VSUSP]; | |
913 | host->c_cc[VEOL] = target->c_cc[TARGET_VEOL]; | |
914 | host->c_cc[VREPRINT] = target->c_cc[TARGET_VREPRINT]; | |
915 | host->c_cc[VDISCARD] = target->c_cc[TARGET_VDISCARD]; | |
916 | host->c_cc[VWERASE] = target->c_cc[TARGET_VWERASE]; | |
917 | host->c_cc[VLNEXT] = target->c_cc[TARGET_VLNEXT]; | |
918 | host->c_cc[VEOL2] = target->c_cc[TARGET_VEOL2]; | |
919 | } | |
920 | ||
921 | static void host_to_target_termios (void *dst, const void *src) | |
922 | { | |
923 | struct target_termios *target = dst; | |
924 | const struct host_termios *host = src; | |
925 | ||
926 | target->c_iflag = | |
927 | tswap32(host_to_target_bitmask(host->c_iflag, iflag_tbl)); | |
928 | target->c_oflag = | |
929 | tswap32(host_to_target_bitmask(host->c_oflag, oflag_tbl)); | |
930 | target->c_cflag = | |
931 | tswap32(host_to_target_bitmask(host->c_cflag, cflag_tbl)); | |
932 | target->c_lflag = | |
933 | tswap32(host_to_target_bitmask(host->c_lflag, lflag_tbl)); | |
934 | target->c_line = host->c_line; | |
935 | ||
936 | target->c_cc[TARGET_VINTR] = host->c_cc[VINTR]; | |
937 | target->c_cc[TARGET_VQUIT] = host->c_cc[VQUIT]; | |
938 | target->c_cc[TARGET_VERASE] = host->c_cc[VERASE]; | |
939 | target->c_cc[TARGET_VKILL] = host->c_cc[VKILL]; | |
940 | target->c_cc[TARGET_VEOF] = host->c_cc[VEOF]; | |
941 | target->c_cc[TARGET_VTIME] = host->c_cc[VTIME]; | |
942 | target->c_cc[TARGET_VMIN] = host->c_cc[VMIN]; | |
943 | target->c_cc[TARGET_VSWTC] = host->c_cc[VSWTC]; | |
944 | target->c_cc[TARGET_VSTART] = host->c_cc[VSTART]; | |
945 | target->c_cc[TARGET_VSTOP] = host->c_cc[VSTOP]; | |
946 | target->c_cc[TARGET_VSUSP] = host->c_cc[VSUSP]; | |
947 | target->c_cc[TARGET_VEOL] = host->c_cc[VEOL]; | |
948 | target->c_cc[TARGET_VREPRINT] = host->c_cc[VREPRINT]; | |
949 | target->c_cc[TARGET_VDISCARD] = host->c_cc[VDISCARD]; | |
950 | target->c_cc[TARGET_VWERASE] = host->c_cc[VWERASE]; | |
951 | target->c_cc[TARGET_VLNEXT] = host->c_cc[VLNEXT]; | |
952 | target->c_cc[TARGET_VEOL2] = host->c_cc[VEOL2]; | |
953 | } | |
954 | ||
955 | StructEntry struct_termios_def = { | |
956 | .convert = { host_to_target_termios, target_to_host_termios }, | |
957 | .size = { sizeof(struct target_termios), sizeof(struct host_termios) }, | |
958 | .align = { __alignof__(struct target_termios), __alignof__(struct host_termios) }, | |
959 | }; | |
960 | ||
6dbad63e FB |
961 | #ifdef TARGET_I386 |
962 | ||
963 | /* NOTE: there is really one LDT for all the threads */ | |
964 | uint8_t *ldt_table; | |
965 | ||
966 | static int read_ldt(void *ptr, unsigned long bytecount) | |
967 | { | |
968 | int size; | |
969 | ||
970 | if (!ldt_table) | |
971 | return 0; | |
972 | size = TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE; | |
973 | if (size > bytecount) | |
974 | size = bytecount; | |
975 | memcpy(ptr, ldt_table, size); | |
976 | return size; | |
977 | } | |
978 | ||
979 | /* XXX: add locking support */ | |
980 | static int write_ldt(CPUX86State *env, | |
981 | void *ptr, unsigned long bytecount, int oldmode) | |
982 | { | |
983 | struct target_modify_ldt_ldt_s ldt_info; | |
984 | int seg_32bit, contents, read_exec_only, limit_in_pages; | |
985 | int seg_not_present, useable; | |
986 | uint32_t *lp, entry_1, entry_2; | |
987 | ||
988 | if (bytecount != sizeof(ldt_info)) | |
989 | return -EINVAL; | |
990 | memcpy(&ldt_info, ptr, sizeof(ldt_info)); | |
991 | tswap32s(&ldt_info.entry_number); | |
992 | tswapls((long *)&ldt_info.base_addr); | |
993 | tswap32s(&ldt_info.limit); | |
994 | tswap32s(&ldt_info.flags); | |
995 | ||
996 | if (ldt_info.entry_number >= TARGET_LDT_ENTRIES) | |
997 | return -EINVAL; | |
998 | seg_32bit = ldt_info.flags & 1; | |
999 | contents = (ldt_info.flags >> 1) & 3; | |
1000 | read_exec_only = (ldt_info.flags >> 3) & 1; | |
1001 | limit_in_pages = (ldt_info.flags >> 4) & 1; | |
1002 | seg_not_present = (ldt_info.flags >> 5) & 1; | |
1003 | useable = (ldt_info.flags >> 6) & 1; | |
1004 | ||
1005 | if (contents == 3) { | |
1006 | if (oldmode) | |
1007 | return -EINVAL; | |
1008 | if (seg_not_present == 0) | |
1009 | return -EINVAL; | |
1010 | } | |
1011 | /* allocate the LDT */ | |
1012 | if (!ldt_table) { | |
1013 | ldt_table = malloc(TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE); | |
1014 | if (!ldt_table) | |
1015 | return -ENOMEM; | |
1016 | memset(ldt_table, 0, TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE); | |
1017 | env->ldt.base = ldt_table; | |
1018 | env->ldt.limit = 0xffff; | |
1019 | } | |
1020 | ||
1021 | /* NOTE: same code as Linux kernel */ | |
1022 | /* Allow LDTs to be cleared by the user. */ | |
1023 | if (ldt_info.base_addr == 0 && ldt_info.limit == 0) { | |
1024 | if (oldmode || | |
1025 | (contents == 0 && | |
1026 | read_exec_only == 1 && | |
1027 | seg_32bit == 0 && | |
1028 | limit_in_pages == 0 && | |
1029 | seg_not_present == 1 && | |
1030 | useable == 0 )) { | |
1031 | entry_1 = 0; | |
1032 | entry_2 = 0; | |
1033 | goto install; | |
1034 | } | |
1035 | } | |
1036 | ||
1037 | entry_1 = ((ldt_info.base_addr & 0x0000ffff) << 16) | | |
1038 | (ldt_info.limit & 0x0ffff); | |
1039 | entry_2 = (ldt_info.base_addr & 0xff000000) | | |
1040 | ((ldt_info.base_addr & 0x00ff0000) >> 16) | | |
1041 | (ldt_info.limit & 0xf0000) | | |
1042 | ((read_exec_only ^ 1) << 9) | | |
1043 | (contents << 10) | | |
1044 | ((seg_not_present ^ 1) << 15) | | |
1045 | (seg_32bit << 22) | | |
1046 | (limit_in_pages << 23) | | |
1047 | 0x7000; | |
1048 | if (!oldmode) | |
1049 | entry_2 |= (useable << 20); | |
1050 | ||
1051 | /* Install the new entry ... */ | |
1052 | install: | |
1053 | lp = (uint32_t *)(ldt_table + (ldt_info.entry_number << 3)); | |
1054 | lp[0] = tswap32(entry_1); | |
1055 | lp[1] = tswap32(entry_2); | |
1056 | return 0; | |
1057 | } | |
1058 | ||
1059 | /* specific and weird i386 syscalls */ | |
5cd4393b | 1060 | int do_modify_ldt(CPUX86State *env, int func, void *ptr, unsigned long bytecount) |
6dbad63e FB |
1061 | { |
1062 | int ret = -ENOSYS; | |
1063 | ||
1064 | switch (func) { | |
1065 | case 0: | |
1066 | ret = read_ldt(ptr, bytecount); | |
1067 | break; | |
1068 | case 1: | |
1069 | ret = write_ldt(env, ptr, bytecount, 1); | |
1070 | break; | |
1071 | case 0x11: | |
1072 | ret = write_ldt(env, ptr, bytecount, 0); | |
1073 | break; | |
1074 | } | |
1075 | return ret; | |
1076 | } | |
1b6b029e FB |
1077 | |
1078 | /* this stack is the equivalent of the kernel stack associated with a | |
1079 | thread/process */ | |
1080 | #define NEW_STACK_SIZE 8192 | |
1081 | ||
1082 | static int clone_func(void *arg) | |
1083 | { | |
1084 | CPUX86State *env = arg; | |
1085 | cpu_loop(env); | |
1086 | /* never exits */ | |
1087 | return 0; | |
1088 | } | |
1089 | ||
1090 | int do_fork(CPUX86State *env, unsigned int flags, unsigned long newsp) | |
1091 | { | |
1092 | int ret; | |
5cd4393b | 1093 | TaskState *ts; |
1b6b029e FB |
1094 | uint8_t *new_stack; |
1095 | CPUX86State *new_env; | |
1096 | ||
1097 | if (flags & CLONE_VM) { | |
1098 | if (!newsp) | |
1099 | newsp = env->regs[R_ESP]; | |
5cd4393b FB |
1100 | ts = malloc(sizeof(TaskState) + NEW_STACK_SIZE); |
1101 | memset(ts, 0, sizeof(TaskState)); | |
1102 | new_stack = ts->stack; | |
1103 | ts->used = 1; | |
1104 | /* add in task state list */ | |
1105 | ts->next = first_task_state; | |
1106 | first_task_state = ts; | |
1b6b029e FB |
1107 | /* we create a new CPU instance. */ |
1108 | new_env = cpu_x86_init(); | |
1109 | memcpy(new_env, env, sizeof(CPUX86State)); | |
1110 | new_env->regs[R_ESP] = newsp; | |
1111 | new_env->regs[R_EAX] = 0; | |
5cd4393b | 1112 | new_env->opaque = ts; |
27725c1d FB |
1113 | #ifdef __ia64__ |
1114 | ret = clone2(clone_func, new_stack + NEW_STACK_SIZE, flags, new_env); | |
1115 | #else | |
1116 | ret = clone(clone_func, new_stack + NEW_STACK_SIZE, flags, new_env); | |
1117 | #endif | |
1b6b029e FB |
1118 | } else { |
1119 | /* if no CLONE_VM, we consider it is a fork */ | |
1120 | if ((flags & ~CSIGNAL) != 0) | |
1121 | return -EINVAL; | |
1122 | ret = fork(); | |
1123 | } | |
1124 | return ret; | |
1125 | } | |
1126 | ||
6dbad63e FB |
1127 | #endif |
1128 | ||
7775e9ec FB |
1129 | static long do_fcntl(int fd, int cmd, unsigned long arg) |
1130 | { | |
1131 | struct flock fl; | |
1132 | struct target_flock *target_fl = (void *)arg; | |
1133 | long ret; | |
1134 | ||
1135 | switch(cmd) { | |
1136 | case TARGET_F_GETLK: | |
1137 | ret = fcntl(fd, cmd, &fl); | |
1138 | if (ret == 0) { | |
1139 | target_fl->l_type = tswap16(fl.l_type); | |
1140 | target_fl->l_whence = tswap16(fl.l_whence); | |
1141 | target_fl->l_start = tswapl(fl.l_start); | |
1142 | target_fl->l_len = tswapl(fl.l_len); | |
1143 | target_fl->l_pid = tswapl(fl.l_pid); | |
1144 | } | |
1145 | break; | |
1146 | ||
1147 | case TARGET_F_SETLK: | |
1148 | case TARGET_F_SETLKW: | |
1149 | fl.l_type = tswap16(target_fl->l_type); | |
1150 | fl.l_whence = tswap16(target_fl->l_whence); | |
1151 | fl.l_start = tswapl(target_fl->l_start); | |
1152 | fl.l_len = tswapl(target_fl->l_len); | |
1153 | fl.l_pid = tswapl(target_fl->l_pid); | |
1154 | ret = fcntl(fd, cmd, &fl); | |
1155 | break; | |
1156 | ||
1157 | case TARGET_F_GETLK64: | |
1158 | case TARGET_F_SETLK64: | |
1159 | case TARGET_F_SETLKW64: | |
1160 | ret = -1; | |
1161 | errno = EINVAL; | |
1162 | break; | |
1163 | ||
1164 | default: | |
1165 | ret = fcntl(fd, cmd, arg); | |
1166 | break; | |
1167 | } | |
1168 | return ret; | |
1169 | } | |
1170 | ||
1171 | ||
b03c60f3 FB |
1172 | #define high2lowuid(x) (x) |
1173 | #define high2lowgid(x) (x) | |
1174 | #define low2highuid(x) (x) | |
1175 | #define low2highgid(x) (x) | |
1b6b029e | 1176 | |
31e31b8a FB |
1177 | void syscall_init(void) |
1178 | { | |
1179 | #define STRUCT(name, list...) thunk_register_struct(STRUCT_ ## name, #name, struct_ ## name ## _def); | |
1180 | #define STRUCT_SPECIAL(name) thunk_register_struct_direct(STRUCT_ ## name, #name, &struct_ ## name ## _def); | |
1181 | #include "syscall_types.h" | |
1182 | #undef STRUCT | |
1183 | #undef STRUCT_SPECIAL | |
1184 | } | |
1185 | ||
6dbad63e | 1186 | long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3, |
31e31b8a FB |
1187 | long arg4, long arg5, long arg6) |
1188 | { | |
1189 | long ret; | |
1190 | struct stat st; | |
72f03900 | 1191 | struct kernel_statfs *stfs; |
31e31b8a | 1192 | |
72f03900 FB |
1193 | #ifdef DEBUG |
1194 | gemu_log("syscall %d\n", num); | |
1195 | #endif | |
31e31b8a FB |
1196 | switch(num) { |
1197 | case TARGET_NR_exit: | |
7d13299d FB |
1198 | #ifdef HAVE_GPROF |
1199 | _mcleanup(); | |
1200 | #endif | |
1b6b029e | 1201 | /* XXX: should free thread stack and CPU env */ |
31e31b8a FB |
1202 | _exit(arg1); |
1203 | ret = 0; /* avoid warning */ | |
1204 | break; | |
1205 | case TARGET_NR_read: | |
206f0fa7 | 1206 | page_unprotect_range((void *)arg2, arg3); |
31e31b8a FB |
1207 | ret = get_errno(read(arg1, (void *)arg2, arg3)); |
1208 | break; | |
1209 | case TARGET_NR_write: | |
1210 | ret = get_errno(write(arg1, (void *)arg2, arg3)); | |
1211 | break; | |
1212 | case TARGET_NR_open: | |
ec86b0fb | 1213 | ret = get_errno(open(path((const char *)arg1), arg2, arg3)); |
31e31b8a FB |
1214 | break; |
1215 | case TARGET_NR_close: | |
1216 | ret = get_errno(close(arg1)); | |
1217 | break; | |
1218 | case TARGET_NR_brk: | |
1219 | ret = do_brk((char *)arg1); | |
1220 | break; | |
1221 | case TARGET_NR_fork: | |
1b6b029e | 1222 | ret = get_errno(do_fork(cpu_env, SIGCHLD, 0)); |
31e31b8a FB |
1223 | break; |
1224 | case TARGET_NR_waitpid: | |
1225 | { | |
1226 | int *status = (int *)arg2; | |
1227 | ret = get_errno(waitpid(arg1, status, arg3)); | |
1228 | if (!is_error(ret) && status) | |
1229 | tswapls((long *)&status); | |
1230 | } | |
1231 | break; | |
1232 | case TARGET_NR_creat: | |
1233 | ret = get_errno(creat((const char *)arg1, arg2)); | |
1234 | break; | |
1235 | case TARGET_NR_link: | |
1236 | ret = get_errno(link((const char *)arg1, (const char *)arg2)); | |
1237 | break; | |
1238 | case TARGET_NR_unlink: | |
1239 | ret = get_errno(unlink((const char *)arg1)); | |
1240 | break; | |
1241 | case TARGET_NR_execve: | |
7854b056 FB |
1242 | { |
1243 | char **argp, **envp; | |
f7341ff4 | 1244 | int argc, envc; |
7854b056 FB |
1245 | uint32_t *p; |
1246 | char **q; | |
1247 | ||
f7341ff4 | 1248 | argc = 0; |
7854b056 FB |
1249 | for (p = (void *)arg2; *p; p++) |
1250 | argc++; | |
f7341ff4 | 1251 | envc = 0; |
7854b056 FB |
1252 | for (p = (void *)arg3; *p; p++) |
1253 | envc++; | |
1254 | ||
f7341ff4 FB |
1255 | argp = alloca((argc + 1) * sizeof(void *)); |
1256 | envp = alloca((envc + 1) * sizeof(void *)); | |
7854b056 FB |
1257 | |
1258 | for (p = (void *)arg2, q = argp; *p; p++, q++) | |
1259 | *q = (void *)tswap32(*p); | |
f7341ff4 FB |
1260 | *q = NULL; |
1261 | ||
7854b056 FB |
1262 | for (p = (void *)arg3, q = envp; *p; p++, q++) |
1263 | *q = (void *)tswap32(*p); | |
f7341ff4 | 1264 | *q = NULL; |
7854b056 FB |
1265 | |
1266 | ret = get_errno(execve((const char *)arg1, argp, envp)); | |
1267 | } | |
31e31b8a FB |
1268 | break; |
1269 | case TARGET_NR_chdir: | |
1270 | ret = get_errno(chdir((const char *)arg1)); | |
1271 | break; | |
1272 | case TARGET_NR_time: | |
1273 | { | |
1274 | int *time_ptr = (int *)arg1; | |
1275 | ret = get_errno(time((time_t *)time_ptr)); | |
1276 | if (!is_error(ret) && time_ptr) | |
1277 | tswap32s(time_ptr); | |
1278 | } | |
1279 | break; | |
1280 | case TARGET_NR_mknod: | |
1281 | ret = get_errno(mknod((const char *)arg1, arg2, arg3)); | |
1282 | break; | |
1283 | case TARGET_NR_chmod: | |
1284 | ret = get_errno(chmod((const char *)arg1, arg2)); | |
1285 | break; | |
1286 | case TARGET_NR_lchown: | |
1287 | ret = get_errno(chown((const char *)arg1, arg2, arg3)); | |
1288 | break; | |
1289 | case TARGET_NR_break: | |
1290 | goto unimplemented; | |
1291 | case TARGET_NR_oldstat: | |
1292 | goto unimplemented; | |
1293 | case TARGET_NR_lseek: | |
1294 | ret = get_errno(lseek(arg1, arg2, arg3)); | |
1295 | break; | |
1296 | case TARGET_NR_getpid: | |
1297 | ret = get_errno(getpid()); | |
1298 | break; | |
1299 | case TARGET_NR_mount: | |
1300 | /* need to look at the data field */ | |
1301 | goto unimplemented; | |
1302 | case TARGET_NR_umount: | |
1303 | ret = get_errno(umount((const char *)arg1)); | |
1304 | break; | |
1305 | case TARGET_NR_setuid: | |
b03c60f3 | 1306 | ret = get_errno(setuid(low2highuid(arg1))); |
31e31b8a FB |
1307 | break; |
1308 | case TARGET_NR_getuid: | |
1309 | ret = get_errno(getuid()); | |
1310 | break; | |
1311 | case TARGET_NR_stime: | |
1312 | { | |
1313 | int *time_ptr = (int *)arg1; | |
1314 | if (time_ptr) | |
1315 | tswap32s(time_ptr); | |
1316 | ret = get_errno(stime((time_t *)time_ptr)); | |
1317 | } | |
1318 | break; | |
1319 | case TARGET_NR_ptrace: | |
1320 | goto unimplemented; | |
1321 | case TARGET_NR_alarm: | |
1322 | ret = alarm(arg1); | |
1323 | break; | |
1324 | case TARGET_NR_oldfstat: | |
1325 | goto unimplemented; | |
1326 | case TARGET_NR_pause: | |
1327 | ret = get_errno(pause()); | |
1328 | break; | |
1329 | case TARGET_NR_utime: | |
1330 | goto unimplemented; | |
1331 | case TARGET_NR_stty: | |
1332 | goto unimplemented; | |
1333 | case TARGET_NR_gtty: | |
1334 | goto unimplemented; | |
1335 | case TARGET_NR_access: | |
1336 | ret = get_errno(access((const char *)arg1, arg2)); | |
1337 | break; | |
1338 | case TARGET_NR_nice: | |
1339 | ret = get_errno(nice(arg1)); | |
1340 | break; | |
1341 | case TARGET_NR_ftime: | |
1342 | goto unimplemented; | |
1343 | case TARGET_NR_sync: | |
04369ff2 FB |
1344 | sync(); |
1345 | ret = 0; | |
31e31b8a FB |
1346 | break; |
1347 | case TARGET_NR_kill: | |
1348 | ret = get_errno(kill(arg1, arg2)); | |
1349 | break; | |
1350 | case TARGET_NR_rename: | |
1351 | ret = get_errno(rename((const char *)arg1, (const char *)arg2)); | |
1352 | break; | |
1353 | case TARGET_NR_mkdir: | |
1354 | ret = get_errno(mkdir((const char *)arg1, arg2)); | |
1355 | break; | |
1356 | case TARGET_NR_rmdir: | |
1357 | ret = get_errno(rmdir((const char *)arg1)); | |
1358 | break; | |
1359 | case TARGET_NR_dup: | |
1360 | ret = get_errno(dup(arg1)); | |
1361 | break; | |
1362 | case TARGET_NR_pipe: | |
1363 | { | |
1364 | int *pipe_ptr = (int *)arg1; | |
1365 | ret = get_errno(pipe(pipe_ptr)); | |
1366 | if (!is_error(ret)) { | |
1367 | tswap32s(&pipe_ptr[0]); | |
1368 | tswap32s(&pipe_ptr[1]); | |
1369 | } | |
1370 | } | |
1371 | break; | |
1372 | case TARGET_NR_times: | |
32f36bce FB |
1373 | { |
1374 | struct target_tms *tmsp = (void *)arg1; | |
1375 | struct tms tms; | |
1376 | ret = get_errno(times(&tms)); | |
1377 | if (tmsp) { | |
1378 | tmsp->tms_utime = tswapl(tms.tms_utime); | |
1379 | tmsp->tms_stime = tswapl(tms.tms_stime); | |
1380 | tmsp->tms_cutime = tswapl(tms.tms_cutime); | |
1381 | tmsp->tms_cstime = tswapl(tms.tms_cstime); | |
1382 | } | |
1383 | } | |
1384 | break; | |
31e31b8a FB |
1385 | case TARGET_NR_prof: |
1386 | goto unimplemented; | |
1387 | case TARGET_NR_setgid: | |
b03c60f3 | 1388 | ret = get_errno(setgid(low2highgid(arg1))); |
31e31b8a FB |
1389 | break; |
1390 | case TARGET_NR_getgid: | |
1391 | ret = get_errno(getgid()); | |
1392 | break; | |
1393 | case TARGET_NR_signal: | |
1394 | goto unimplemented; | |
1395 | case TARGET_NR_geteuid: | |
1396 | ret = get_errno(geteuid()); | |
1397 | break; | |
1398 | case TARGET_NR_getegid: | |
1399 | ret = get_errno(getegid()); | |
1400 | break; | |
1401 | case TARGET_NR_acct: | |
1402 | goto unimplemented; | |
1403 | case TARGET_NR_umount2: | |
1404 | ret = get_errno(umount2((const char *)arg1, arg2)); | |
1405 | break; | |
1406 | case TARGET_NR_lock: | |
1407 | goto unimplemented; | |
1408 | case TARGET_NR_ioctl: | |
1409 | ret = do_ioctl(arg1, arg2, arg3); | |
1410 | break; | |
1411 | case TARGET_NR_fcntl: | |
7775e9ec | 1412 | ret = get_errno(do_fcntl(arg1, arg2, arg3)); |
31e31b8a FB |
1413 | break; |
1414 | case TARGET_NR_mpx: | |
1415 | goto unimplemented; | |
1416 | case TARGET_NR_setpgid: | |
1417 | ret = get_errno(setpgid(arg1, arg2)); | |
1418 | break; | |
1419 | case TARGET_NR_ulimit: | |
1420 | goto unimplemented; | |
1421 | case TARGET_NR_oldolduname: | |
1422 | goto unimplemented; | |
1423 | case TARGET_NR_umask: | |
1424 | ret = get_errno(umask(arg1)); | |
1425 | break; | |
1426 | case TARGET_NR_chroot: | |
1427 | ret = get_errno(chroot((const char *)arg1)); | |
1428 | break; | |
1429 | case TARGET_NR_ustat: | |
1430 | goto unimplemented; | |
1431 | case TARGET_NR_dup2: | |
1432 | ret = get_errno(dup2(arg1, arg2)); | |
1433 | break; | |
1434 | case TARGET_NR_getppid: | |
1435 | ret = get_errno(getppid()); | |
1436 | break; | |
1437 | case TARGET_NR_getpgrp: | |
1438 | ret = get_errno(getpgrp()); | |
1439 | break; | |
1440 | case TARGET_NR_setsid: | |
1441 | ret = get_errno(setsid()); | |
1442 | break; | |
1443 | case TARGET_NR_sigaction: | |
31e31b8a | 1444 | { |
66fb9763 FB |
1445 | struct target_old_sigaction *old_act = (void *)arg2; |
1446 | struct target_old_sigaction *old_oact = (void *)arg3; | |
1447 | struct target_sigaction act, oact, *pact; | |
1448 | if (old_act) { | |
1449 | act._sa_handler = old_act->_sa_handler; | |
1450 | target_siginitset(&act.sa_mask, old_act->sa_mask); | |
1451 | act.sa_flags = old_act->sa_flags; | |
1452 | act.sa_restorer = old_act->sa_restorer; | |
1453 | pact = &act; | |
1454 | } else { | |
1455 | pact = NULL; | |
1456 | } | |
1457 | ret = get_errno(do_sigaction(arg1, pact, &oact)); | |
1458 | if (!is_error(ret) && old_oact) { | |
1459 | old_oact->_sa_handler = oact._sa_handler; | |
1460 | old_oact->sa_mask = oact.sa_mask.sig[0]; | |
1461 | old_oact->sa_flags = oact.sa_flags; | |
1462 | old_oact->sa_restorer = oact.sa_restorer; | |
1463 | } | |
31e31b8a FB |
1464 | } |
1465 | break; | |
66fb9763 FB |
1466 | case TARGET_NR_rt_sigaction: |
1467 | ret = get_errno(do_sigaction(arg1, (void *)arg2, (void *)arg3)); | |
1468 | break; | |
31e31b8a | 1469 | case TARGET_NR_sgetmask: |
66fb9763 FB |
1470 | { |
1471 | sigset_t cur_set; | |
1472 | target_ulong target_set; | |
1473 | sigprocmask(0, NULL, &cur_set); | |
1474 | host_to_target_old_sigset(&target_set, &cur_set); | |
1475 | ret = target_set; | |
1476 | } | |
1477 | break; | |
31e31b8a | 1478 | case TARGET_NR_ssetmask: |
66fb9763 FB |
1479 | { |
1480 | sigset_t set, oset, cur_set; | |
1481 | target_ulong target_set = arg1; | |
1482 | sigprocmask(0, NULL, &cur_set); | |
1483 | target_to_host_old_sigset(&set, &target_set); | |
1484 | sigorset(&set, &set, &cur_set); | |
1485 | sigprocmask(SIG_SETMASK, &set, &oset); | |
1486 | host_to_target_old_sigset(&target_set, &oset); | |
1487 | ret = target_set; | |
1488 | } | |
1489 | break; | |
1490 | case TARGET_NR_sigprocmask: | |
1491 | { | |
1492 | int how = arg1; | |
1493 | sigset_t set, oldset, *set_ptr; | |
1494 | target_ulong *pset = (void *)arg2, *poldset = (void *)arg3; | |
1495 | ||
1496 | if (pset) { | |
1497 | switch(how) { | |
1498 | case TARGET_SIG_BLOCK: | |
1499 | how = SIG_BLOCK; | |
1500 | break; | |
1501 | case TARGET_SIG_UNBLOCK: | |
1502 | how = SIG_UNBLOCK; | |
1503 | break; | |
1504 | case TARGET_SIG_SETMASK: | |
1505 | how = SIG_SETMASK; | |
1506 | break; | |
1507 | default: | |
1508 | ret = -EINVAL; | |
1509 | goto fail; | |
1510 | } | |
1511 | target_to_host_old_sigset(&set, pset); | |
1512 | set_ptr = &set; | |
1513 | } else { | |
1514 | how = 0; | |
1515 | set_ptr = NULL; | |
1516 | } | |
1517 | ret = get_errno(sigprocmask(arg1, set_ptr, &oldset)); | |
1518 | if (!is_error(ret) && poldset) { | |
1519 | host_to_target_old_sigset(poldset, &oldset); | |
1520 | } | |
1521 | } | |
1522 | break; | |
1523 | case TARGET_NR_rt_sigprocmask: | |
1524 | { | |
1525 | int how = arg1; | |
1526 | sigset_t set, oldset, *set_ptr; | |
1527 | target_sigset_t *pset = (void *)arg2; | |
1528 | target_sigset_t *poldset = (void *)arg3; | |
1529 | ||
1530 | if (pset) { | |
1531 | switch(how) { | |
1532 | case TARGET_SIG_BLOCK: | |
1533 | how = SIG_BLOCK; | |
1534 | break; | |
1535 | case TARGET_SIG_UNBLOCK: | |
1536 | how = SIG_UNBLOCK; | |
1537 | break; | |
1538 | case TARGET_SIG_SETMASK: | |
1539 | how = SIG_SETMASK; | |
1540 | break; | |
1541 | default: | |
1542 | ret = -EINVAL; | |
1543 | goto fail; | |
1544 | } | |
1545 | target_to_host_sigset(&set, pset); | |
1546 | set_ptr = &set; | |
1547 | } else { | |
1548 | how = 0; | |
1549 | set_ptr = NULL; | |
1550 | } | |
1551 | ret = get_errno(sigprocmask(how, set_ptr, &oldset)); | |
1552 | if (!is_error(ret) && poldset) { | |
1553 | host_to_target_sigset(poldset, &oldset); | |
1554 | } | |
1555 | } | |
1556 | break; | |
1557 | case TARGET_NR_sigpending: | |
1558 | { | |
1559 | sigset_t set; | |
1560 | ret = get_errno(sigpending(&set)); | |
1561 | if (!is_error(ret)) { | |
1562 | host_to_target_old_sigset((target_ulong *)arg1, &set); | |
1563 | } | |
1564 | } | |
1565 | break; | |
1566 | case TARGET_NR_rt_sigpending: | |
1567 | { | |
1568 | sigset_t set; | |
1569 | ret = get_errno(sigpending(&set)); | |
1570 | if (!is_error(ret)) { | |
1571 | host_to_target_sigset((target_sigset_t *)arg1, &set); | |
1572 | } | |
1573 | } | |
1574 | break; | |
1575 | case TARGET_NR_sigsuspend: | |
1576 | { | |
1577 | sigset_t set; | |
1578 | target_to_host_old_sigset(&set, (target_ulong *)arg1); | |
1579 | ret = get_errno(sigsuspend(&set)); | |
1580 | } | |
1581 | break; | |
1582 | case TARGET_NR_rt_sigsuspend: | |
1583 | { | |
1584 | sigset_t set; | |
1585 | target_to_host_sigset(&set, (target_sigset_t *)arg1); | |
1586 | ret = get_errno(sigsuspend(&set)); | |
1587 | } | |
1588 | break; | |
1589 | case TARGET_NR_rt_sigtimedwait: | |
1590 | { | |
1591 | target_sigset_t *target_set = (void *)arg1; | |
1592 | target_siginfo_t *target_uinfo = (void *)arg2; | |
1593 | struct target_timespec *target_uts = (void *)arg3; | |
1594 | sigset_t set; | |
1595 | struct timespec uts, *puts; | |
1596 | siginfo_t uinfo; | |
1597 | ||
1598 | target_to_host_sigset(&set, target_set); | |
1599 | if (target_uts) { | |
1600 | puts = &uts; | |
1601 | puts->tv_sec = tswapl(target_uts->tv_sec); | |
1602 | puts->tv_nsec = tswapl(target_uts->tv_nsec); | |
1603 | } else { | |
1604 | puts = NULL; | |
1605 | } | |
1606 | ret = get_errno(sigtimedwait(&set, &uinfo, puts)); | |
1607 | if (!is_error(ret) && target_uinfo) { | |
1608 | host_to_target_siginfo(target_uinfo, &uinfo); | |
1609 | } | |
1610 | } | |
1611 | break; | |
1612 | case TARGET_NR_rt_sigqueueinfo: | |
1613 | { | |
1614 | siginfo_t uinfo; | |
1615 | target_to_host_siginfo(&uinfo, (target_siginfo_t *)arg3); | |
1616 | ret = get_errno(sys_rt_sigqueueinfo(arg1, arg2, &uinfo)); | |
1617 | } | |
1618 | break; | |
1619 | case TARGET_NR_sigreturn: | |
1620 | /* NOTE: ret is eax, so not transcoding must be done */ | |
1621 | ret = do_sigreturn(cpu_env); | |
1622 | break; | |
1623 | case TARGET_NR_rt_sigreturn: | |
1624 | /* NOTE: ret is eax, so not transcoding must be done */ | |
1625 | ret = do_rt_sigreturn(cpu_env); | |
1626 | break; | |
31e31b8a FB |
1627 | case TARGET_NR_setreuid: |
1628 | ret = get_errno(setreuid(arg1, arg2)); | |
1629 | break; | |
1630 | case TARGET_NR_setregid: | |
1631 | ret = get_errno(setregid(arg1, arg2)); | |
1632 | break; | |
31e31b8a FB |
1633 | case TARGET_NR_sethostname: |
1634 | ret = get_errno(sethostname((const char *)arg1, arg2)); | |
1635 | break; | |
1636 | case TARGET_NR_setrlimit: | |
9de5e440 FB |
1637 | { |
1638 | /* XXX: convert resource ? */ | |
1639 | int resource = arg1; | |
1640 | struct target_rlimit *target_rlim = (void *)arg2; | |
1641 | struct rlimit rlim; | |
1642 | rlim.rlim_cur = tswapl(target_rlim->rlim_cur); | |
1643 | rlim.rlim_max = tswapl(target_rlim->rlim_max); | |
1644 | ret = get_errno(setrlimit(resource, &rlim)); | |
1645 | } | |
1646 | break; | |
31e31b8a | 1647 | case TARGET_NR_getrlimit: |
9de5e440 FB |
1648 | { |
1649 | /* XXX: convert resource ? */ | |
1650 | int resource = arg1; | |
1651 | struct target_rlimit *target_rlim = (void *)arg2; | |
1652 | struct rlimit rlim; | |
1653 | ||
1654 | ret = get_errno(getrlimit(resource, &rlim)); | |
1655 | if (!is_error(ret)) { | |
1656 | target_rlim->rlim_cur = tswapl(rlim.rlim_cur); | |
1657 | target_rlim->rlim_max = tswapl(rlim.rlim_max); | |
1658 | } | |
1659 | } | |
1660 | break; | |
31e31b8a | 1661 | case TARGET_NR_getrusage: |
b409186b FB |
1662 | { |
1663 | struct rusage rusage; | |
1664 | struct target_rusage *target_rusage = (void *)arg2; | |
1665 | ret = get_errno(getrusage(arg1, &rusage)); | |
1666 | if (!is_error(ret)) { | |
1667 | host_to_target_rusage(target_rusage, &rusage); | |
1668 | } | |
1669 | } | |
1670 | break; | |
31e31b8a FB |
1671 | case TARGET_NR_gettimeofday: |
1672 | { | |
1673 | struct target_timeval *target_tv = (void *)arg1; | |
1674 | struct timeval tv; | |
1675 | ret = get_errno(gettimeofday(&tv, NULL)); | |
1676 | if (!is_error(ret)) { | |
5cd4393b | 1677 | host_to_target_timeval(target_tv, &tv); |
31e31b8a FB |
1678 | } |
1679 | } | |
1680 | break; | |
1681 | case TARGET_NR_settimeofday: | |
1682 | { | |
1683 | struct target_timeval *target_tv = (void *)arg1; | |
1684 | struct timeval tv; | |
5cd4393b | 1685 | target_to_host_timeval(&tv, target_tv); |
31e31b8a FB |
1686 | ret = get_errno(settimeofday(&tv, NULL)); |
1687 | } | |
1688 | break; | |
1689 | case TARGET_NR_getgroups: | |
19b84f3c FB |
1690 | { |
1691 | int gidsetsize = arg1; | |
1692 | uint16_t *target_grouplist = (void *)arg2; | |
1693 | gid_t *grouplist; | |
1694 | int i; | |
1695 | ||
1696 | grouplist = alloca(gidsetsize * sizeof(gid_t)); | |
1697 | ret = get_errno(getgroups(gidsetsize, grouplist)); | |
1698 | if (!is_error(ret)) { | |
1699 | for(i = 0;i < gidsetsize; i++) | |
1700 | target_grouplist[i] = tswap16(grouplist[i]); | |
1701 | } | |
1702 | } | |
1703 | break; | |
31e31b8a | 1704 | case TARGET_NR_setgroups: |
19b84f3c FB |
1705 | { |
1706 | int gidsetsize = arg1; | |
1707 | uint16_t *target_grouplist = (void *)arg2; | |
1708 | gid_t *grouplist; | |
1709 | int i; | |
1710 | ||
1711 | grouplist = alloca(gidsetsize * sizeof(gid_t)); | |
1712 | for(i = 0;i < gidsetsize; i++) | |
1713 | grouplist[i] = tswap16(target_grouplist[i]); | |
1714 | ret = get_errno(setgroups(gidsetsize, grouplist)); | |
1715 | } | |
1716 | break; | |
31e31b8a FB |
1717 | case TARGET_NR_select: |
1718 | goto unimplemented; | |
1719 | case TARGET_NR_symlink: | |
1720 | ret = get_errno(symlink((const char *)arg1, (const char *)arg2)); | |
1721 | break; | |
1722 | case TARGET_NR_oldlstat: | |
1723 | goto unimplemented; | |
1724 | case TARGET_NR_readlink: | |
ec86b0fb | 1725 | ret = get_errno(readlink(path((const char *)arg1), (char *)arg2, arg3)); |
31e31b8a FB |
1726 | break; |
1727 | case TARGET_NR_uselib: | |
1728 | goto unimplemented; | |
1729 | case TARGET_NR_swapon: | |
1730 | ret = get_errno(swapon((const char *)arg1, arg2)); | |
1731 | break; | |
1732 | case TARGET_NR_reboot: | |
1733 | goto unimplemented; | |
1734 | case TARGET_NR_readdir: | |
1735 | goto unimplemented; | |
1736 | #ifdef TARGET_I386 | |
1737 | case TARGET_NR_mmap: | |
1738 | { | |
1739 | uint32_t v1, v2, v3, v4, v5, v6, *vptr; | |
1740 | vptr = (uint32_t *)arg1; | |
1741 | v1 = tswap32(vptr[0]); | |
1742 | v2 = tswap32(vptr[1]); | |
1743 | v3 = tswap32(vptr[2]); | |
1744 | v4 = tswap32(vptr[3]); | |
1745 | v5 = tswap32(vptr[4]); | |
1746 | v6 = tswap32(vptr[5]); | |
54936004 | 1747 | ret = get_errno(target_mmap(v1, v2, v3, v4, v5, v6)); |
31e31b8a FB |
1748 | } |
1749 | break; | |
1750 | #endif | |
1751 | #ifdef TARGET_I386 | |
1752 | case TARGET_NR_mmap2: | |
1753 | #else | |
1754 | case TARGET_NR_mmap: | |
1755 | #endif | |
54936004 | 1756 | ret = get_errno(target_mmap(arg1, arg2, arg3, arg4, arg5, arg6)); |
31e31b8a FB |
1757 | break; |
1758 | case TARGET_NR_munmap: | |
54936004 | 1759 | ret = get_errno(target_munmap(arg1, arg2)); |
31e31b8a | 1760 | break; |
9de5e440 | 1761 | case TARGET_NR_mprotect: |
54936004 | 1762 | ret = get_errno(target_mprotect(arg1, arg2, arg3)); |
9de5e440 FB |
1763 | break; |
1764 | case TARGET_NR_mremap: | |
54936004 | 1765 | ret = get_errno(target_mremap(arg1, arg2, arg3, arg4, arg5)); |
9de5e440 FB |
1766 | break; |
1767 | case TARGET_NR_msync: | |
1768 | ret = get_errno(msync((void *)arg1, arg2, arg3)); | |
1769 | break; | |
1770 | case TARGET_NR_mlock: | |
1771 | ret = get_errno(mlock((void *)arg1, arg2)); | |
1772 | break; | |
1773 | case TARGET_NR_munlock: | |
1774 | ret = get_errno(munlock((void *)arg1, arg2)); | |
1775 | break; | |
1776 | case TARGET_NR_mlockall: | |
1777 | ret = get_errno(mlockall(arg1)); | |
1778 | break; | |
1779 | case TARGET_NR_munlockall: | |
1780 | ret = get_errno(munlockall()); | |
1781 | break; | |
31e31b8a FB |
1782 | case TARGET_NR_truncate: |
1783 | ret = get_errno(truncate((const char *)arg1, arg2)); | |
1784 | break; | |
1785 | case TARGET_NR_ftruncate: | |
1786 | ret = get_errno(ftruncate(arg1, arg2)); | |
1787 | break; | |
1788 | case TARGET_NR_fchmod: | |
1789 | ret = get_errno(fchmod(arg1, arg2)); | |
1790 | break; | |
1791 | case TARGET_NR_fchown: | |
1792 | ret = get_errno(fchown(arg1, arg2, arg3)); | |
1793 | break; | |
1794 | case TARGET_NR_getpriority: | |
1795 | ret = get_errno(getpriority(arg1, arg2)); | |
1796 | break; | |
1797 | case TARGET_NR_setpriority: | |
1798 | ret = get_errno(setpriority(arg1, arg2, arg3)); | |
1799 | break; | |
1800 | case TARGET_NR_profil: | |
1801 | goto unimplemented; | |
1802 | case TARGET_NR_statfs: | |
1803 | stfs = (void *)arg2; | |
ec86b0fb | 1804 | ret = get_errno(sys_statfs(path((const char *)arg1), stfs)); |
31e31b8a FB |
1805 | convert_statfs: |
1806 | if (!is_error(ret)) { | |
1807 | tswap32s(&stfs->f_type); | |
1808 | tswap32s(&stfs->f_bsize); | |
1809 | tswap32s(&stfs->f_blocks); | |
1810 | tswap32s(&stfs->f_bfree); | |
1811 | tswap32s(&stfs->f_bavail); | |
1812 | tswap32s(&stfs->f_files); | |
1813 | tswap32s(&stfs->f_ffree); | |
1814 | tswap32s(&stfs->f_fsid.val[0]); | |
1815 | tswap32s(&stfs->f_fsid.val[1]); | |
1816 | tswap32s(&stfs->f_namelen); | |
1817 | } | |
1818 | break; | |
1819 | case TARGET_NR_fstatfs: | |
1820 | stfs = (void *)arg2; | |
1821 | ret = get_errno(sys_fstatfs(arg1, stfs)); | |
1822 | goto convert_statfs; | |
1823 | case TARGET_NR_ioperm: | |
1824 | goto unimplemented; | |
1825 | case TARGET_NR_socketcall: | |
7854b056 | 1826 | ret = do_socketcall(arg1, (int32_t *)arg2); |
31e31b8a FB |
1827 | break; |
1828 | case TARGET_NR_syslog: | |
1829 | goto unimplemented; | |
1830 | case TARGET_NR_setitimer: | |
66fb9763 FB |
1831 | { |
1832 | struct target_itimerval *target_value = (void *)arg2; | |
1833 | struct target_itimerval *target_ovalue = (void *)arg3; | |
1834 | struct itimerval value, ovalue, *pvalue; | |
1835 | ||
1836 | if (target_value) { | |
1837 | pvalue = &value; | |
1838 | target_to_host_timeval(&pvalue->it_interval, | |
1839 | &target_value->it_interval); | |
1840 | target_to_host_timeval(&pvalue->it_value, | |
1841 | &target_value->it_value); | |
1842 | } else { | |
1843 | pvalue = NULL; | |
1844 | } | |
1845 | ret = get_errno(setitimer(arg1, pvalue, &ovalue)); | |
1846 | if (!is_error(ret) && target_ovalue) { | |
1847 | host_to_target_timeval(&target_ovalue->it_interval, | |
1848 | &ovalue.it_interval); | |
1849 | host_to_target_timeval(&target_ovalue->it_value, | |
1850 | &ovalue.it_value); | |
1851 | } | |
1852 | } | |
1853 | break; | |
31e31b8a | 1854 | case TARGET_NR_getitimer: |
66fb9763 FB |
1855 | { |
1856 | struct target_itimerval *target_value = (void *)arg2; | |
1857 | struct itimerval value; | |
1858 | ||
1859 | ret = get_errno(getitimer(arg1, &value)); | |
1860 | if (!is_error(ret) && target_value) { | |
1861 | host_to_target_timeval(&target_value->it_interval, | |
1862 | &value.it_interval); | |
1863 | host_to_target_timeval(&target_value->it_value, | |
1864 | &value.it_value); | |
1865 | } | |
1866 | } | |
1867 | break; | |
31e31b8a | 1868 | case TARGET_NR_stat: |
ec86b0fb | 1869 | ret = get_errno(stat(path((const char *)arg1), &st)); |
31e31b8a FB |
1870 | goto do_stat; |
1871 | case TARGET_NR_lstat: | |
ec86b0fb | 1872 | ret = get_errno(lstat(path((const char *)arg1), &st)); |
31e31b8a FB |
1873 | goto do_stat; |
1874 | case TARGET_NR_fstat: | |
1875 | { | |
1876 | ret = get_errno(fstat(arg1, &st)); | |
1877 | do_stat: | |
1878 | if (!is_error(ret)) { | |
1879 | struct target_stat *target_st = (void *)arg2; | |
1880 | target_st->st_dev = tswap16(st.st_dev); | |
1881 | target_st->st_ino = tswapl(st.st_ino); | |
ec86b0fb | 1882 | target_st->st_mode = tswap16(st.st_mode); |
31e31b8a FB |
1883 | target_st->st_nlink = tswap16(st.st_nlink); |
1884 | target_st->st_uid = tswap16(st.st_uid); | |
1885 | target_st->st_gid = tswap16(st.st_gid); | |
1886 | target_st->st_rdev = tswap16(st.st_rdev); | |
1887 | target_st->st_size = tswapl(st.st_size); | |
1888 | target_st->st_blksize = tswapl(st.st_blksize); | |
1889 | target_st->st_blocks = tswapl(st.st_blocks); | |
7854b056 FB |
1890 | target_st->target_st_atime = tswapl(st.st_atime); |
1891 | target_st->target_st_mtime = tswapl(st.st_mtime); | |
1892 | target_st->target_st_ctime = tswapl(st.st_ctime); | |
31e31b8a FB |
1893 | } |
1894 | } | |
1895 | break; | |
1896 | case TARGET_NR_olduname: | |
1897 | goto unimplemented; | |
1898 | case TARGET_NR_iopl: | |
1899 | goto unimplemented; | |
1900 | case TARGET_NR_vhangup: | |
1901 | ret = get_errno(vhangup()); | |
1902 | break; | |
1903 | case TARGET_NR_idle: | |
1904 | goto unimplemented; | |
31e31b8a FB |
1905 | case TARGET_NR_wait4: |
1906 | { | |
1907 | int status; | |
1908 | target_long *status_ptr = (void *)arg2; | |
1909 | struct rusage rusage, *rusage_ptr; | |
1910 | struct target_rusage *target_rusage = (void *)arg4; | |
1911 | if (target_rusage) | |
1912 | rusage_ptr = &rusage; | |
1913 | else | |
1914 | rusage_ptr = NULL; | |
1915 | ret = get_errno(wait4(arg1, &status, arg3, rusage_ptr)); | |
1916 | if (!is_error(ret)) { | |
1917 | if (status_ptr) | |
1918 | *status_ptr = tswap32(status); | |
1919 | if (target_rusage) { | |
b409186b | 1920 | host_to_target_rusage(target_rusage, &rusage); |
31e31b8a FB |
1921 | } |
1922 | } | |
1923 | } | |
1924 | break; | |
1925 | case TARGET_NR_swapoff: | |
1926 | ret = get_errno(swapoff((const char *)arg1)); | |
1927 | break; | |
1928 | case TARGET_NR_sysinfo: | |
1929 | goto unimplemented; | |
1930 | case TARGET_NR_ipc: | |
1931 | goto unimplemented; | |
1932 | case TARGET_NR_fsync: | |
1933 | ret = get_errno(fsync(arg1)); | |
1934 | break; | |
31e31b8a | 1935 | case TARGET_NR_clone: |
1b6b029e FB |
1936 | ret = get_errno(do_fork(cpu_env, arg1, arg2)); |
1937 | break; | |
ec86b0fb FB |
1938 | #ifdef __NR_exit_group |
1939 | /* new thread calls */ | |
1940 | case TARGET_NR_exit_group: | |
1941 | ret = get_errno(exit_group(arg1)); | |
1942 | break; | |
1943 | #endif | |
31e31b8a FB |
1944 | case TARGET_NR_setdomainname: |
1945 | ret = get_errno(setdomainname((const char *)arg1, arg2)); | |
1946 | break; | |
1947 | case TARGET_NR_uname: | |
1948 | /* no need to transcode because we use the linux syscall */ | |
1949 | ret = get_errno(sys_uname((struct new_utsname *)arg1)); | |
1950 | break; | |
6dbad63e | 1951 | #ifdef TARGET_I386 |
31e31b8a | 1952 | case TARGET_NR_modify_ldt: |
5cd4393b FB |
1953 | ret = get_errno(do_modify_ldt(cpu_env, arg1, (void *)arg2, arg3)); |
1954 | break; | |
1955 | case TARGET_NR_vm86old: | |
1956 | goto unimplemented; | |
1957 | case TARGET_NR_vm86: | |
1958 | ret = do_vm86(cpu_env, arg1, (void *)arg2); | |
6dbad63e FB |
1959 | break; |
1960 | #endif | |
31e31b8a FB |
1961 | case TARGET_NR_adjtimex: |
1962 | goto unimplemented; | |
31e31b8a FB |
1963 | case TARGET_NR_create_module: |
1964 | case TARGET_NR_init_module: | |
1965 | case TARGET_NR_delete_module: | |
1966 | case TARGET_NR_get_kernel_syms: | |
1967 | goto unimplemented; | |
1968 | case TARGET_NR_quotactl: | |
1969 | goto unimplemented; | |
1970 | case TARGET_NR_getpgid: | |
1971 | ret = get_errno(getpgid(arg1)); | |
1972 | break; | |
1973 | case TARGET_NR_fchdir: | |
1974 | ret = get_errno(fchdir(arg1)); | |
1975 | break; | |
1976 | case TARGET_NR_bdflush: | |
1977 | goto unimplemented; | |
1978 | case TARGET_NR_sysfs: | |
1979 | goto unimplemented; | |
1980 | case TARGET_NR_personality: | |
1b6b029e | 1981 | ret = get_errno(personality(arg1)); |
31e31b8a FB |
1982 | break; |
1983 | case TARGET_NR_afs_syscall: | |
1984 | goto unimplemented; | |
1985 | case TARGET_NR_setfsuid: | |
9de5e440 FB |
1986 | ret = get_errno(setfsuid(arg1)); |
1987 | break; | |
31e31b8a | 1988 | case TARGET_NR_setfsgid: |
9de5e440 FB |
1989 | ret = get_errno(setfsgid(arg1)); |
1990 | break; | |
31e31b8a FB |
1991 | case TARGET_NR__llseek: |
1992 | { | |
1993 | int64_t res; | |
1994 | ret = get_errno(_llseek(arg1, arg2, arg3, &res, arg5)); | |
1995 | *(int64_t *)arg4 = tswap64(res); | |
1996 | } | |
1997 | break; | |
1998 | case TARGET_NR_getdents: | |
1999 | #if TARGET_LONG_SIZE != 4 | |
2000 | #error not supported | |
2001 | #endif | |
2002 | { | |
2003 | struct dirent *dirp = (void *)arg2; | |
2004 | long count = arg3; | |
dab2ed99 | 2005 | |
72f03900 | 2006 | ret = get_errno(sys_getdents(arg1, dirp, count)); |
31e31b8a FB |
2007 | if (!is_error(ret)) { |
2008 | struct dirent *de; | |
2009 | int len = ret; | |
2010 | int reclen; | |
2011 | de = dirp; | |
2012 | while (len > 0) { | |
8083a3e5 | 2013 | reclen = de->d_reclen; |
31e31b8a FB |
2014 | if (reclen > len) |
2015 | break; | |
8083a3e5 | 2016 | de->d_reclen = tswap16(reclen); |
31e31b8a FB |
2017 | tswapls(&de->d_ino); |
2018 | tswapls(&de->d_off); | |
2019 | de = (struct dirent *)((char *)de + reclen); | |
2020 | len -= reclen; | |
2021 | } | |
2022 | } | |
2023 | } | |
2024 | break; | |
dab2ed99 FB |
2025 | case TARGET_NR_getdents64: |
2026 | { | |
2027 | struct dirent64 *dirp = (void *)arg2; | |
2028 | long count = arg3; | |
2029 | ret = get_errno(sys_getdents64(arg1, dirp, count)); | |
2030 | if (!is_error(ret)) { | |
2031 | struct dirent64 *de; | |
2032 | int len = ret; | |
2033 | int reclen; | |
2034 | de = dirp; | |
2035 | while (len > 0) { | |
8083a3e5 | 2036 | reclen = de->d_reclen; |
dab2ed99 FB |
2037 | if (reclen > len) |
2038 | break; | |
8083a3e5 | 2039 | de->d_reclen = tswap16(reclen); |
dab2ed99 FB |
2040 | tswap64s(&de->d_ino); |
2041 | tswap64s(&de->d_off); | |
2042 | de = (struct dirent64 *)((char *)de + reclen); | |
2043 | len -= reclen; | |
2044 | } | |
2045 | } | |
2046 | } | |
2047 | break; | |
31e31b8a FB |
2048 | case TARGET_NR__newselect: |
2049 | ret = do_select(arg1, (void *)arg2, (void *)arg3, (void *)arg4, | |
2050 | (void *)arg5); | |
2051 | break; | |
9de5e440 FB |
2052 | case TARGET_NR_poll: |
2053 | { | |
2054 | struct target_pollfd *target_pfd = (void *)arg1; | |
2055 | unsigned int nfds = arg2; | |
2056 | int timeout = arg3; | |
2057 | struct pollfd *pfd; | |
7854b056 | 2058 | unsigned int i; |
9de5e440 FB |
2059 | |
2060 | pfd = alloca(sizeof(struct pollfd) * nfds); | |
2061 | for(i = 0; i < nfds; i++) { | |
5cd4393b FB |
2062 | pfd[i].fd = tswap32(target_pfd[i].fd); |
2063 | pfd[i].events = tswap16(target_pfd[i].events); | |
9de5e440 FB |
2064 | } |
2065 | ret = get_errno(poll(pfd, nfds, timeout)); | |
2066 | if (!is_error(ret)) { | |
2067 | for(i = 0; i < nfds; i++) { | |
5cd4393b | 2068 | target_pfd[i].revents = tswap16(pfd[i].revents); |
9de5e440 FB |
2069 | } |
2070 | } | |
2071 | } | |
2072 | break; | |
31e31b8a | 2073 | case TARGET_NR_flock: |
9de5e440 FB |
2074 | /* NOTE: the flock constant seems to be the same for every |
2075 | Linux platform */ | |
2076 | ret = get_errno(flock(arg1, arg2)); | |
31e31b8a FB |
2077 | break; |
2078 | case TARGET_NR_readv: | |
2079 | { | |
2080 | int count = arg3; | |
2081 | int i; | |
2082 | struct iovec *vec; | |
2083 | struct target_iovec *target_vec = (void *)arg2; | |
2084 | ||
2085 | vec = alloca(count * sizeof(struct iovec)); | |
2086 | for(i = 0;i < count; i++) { | |
2087 | vec[i].iov_base = (void *)tswapl(target_vec[i].iov_base); | |
2088 | vec[i].iov_len = tswapl(target_vec[i].iov_len); | |
2089 | } | |
2090 | ret = get_errno(readv(arg1, vec, count)); | |
2091 | } | |
2092 | break; | |
2093 | case TARGET_NR_writev: | |
2094 | { | |
2095 | int count = arg3; | |
2096 | int i; | |
2097 | struct iovec *vec; | |
2098 | struct target_iovec *target_vec = (void *)arg2; | |
2099 | ||
2100 | vec = alloca(count * sizeof(struct iovec)); | |
2101 | for(i = 0;i < count; i++) { | |
2102 | vec[i].iov_base = (void *)tswapl(target_vec[i].iov_base); | |
2103 | vec[i].iov_len = tswapl(target_vec[i].iov_len); | |
2104 | } | |
2105 | ret = get_errno(writev(arg1, vec, count)); | |
2106 | } | |
2107 | break; | |
2108 | case TARGET_NR_getsid: | |
2109 | ret = get_errno(getsid(arg1)); | |
2110 | break; | |
2111 | case TARGET_NR_fdatasync: | |
5cd4393b FB |
2112 | ret = get_errno(fdatasync(arg1)); |
2113 | break; | |
31e31b8a FB |
2114 | case TARGET_NR__sysctl: |
2115 | goto unimplemented; | |
31e31b8a | 2116 | case TARGET_NR_sched_setparam: |
5cd4393b FB |
2117 | { |
2118 | struct sched_param *target_schp = (void *)arg2; | |
2119 | struct sched_param schp; | |
2120 | schp.sched_priority = tswap32(target_schp->sched_priority); | |
2121 | ret = get_errno(sched_setparam(arg1, &schp)); | |
2122 | } | |
2123 | break; | |
31e31b8a | 2124 | case TARGET_NR_sched_getparam: |
5cd4393b FB |
2125 | { |
2126 | struct sched_param *target_schp = (void *)arg2; | |
2127 | struct sched_param schp; | |
2128 | ret = get_errno(sched_getparam(arg1, &schp)); | |
2129 | if (!is_error(ret)) { | |
2130 | target_schp->sched_priority = tswap32(schp.sched_priority); | |
2131 | } | |
2132 | } | |
2133 | break; | |
31e31b8a | 2134 | case TARGET_NR_sched_setscheduler: |
5cd4393b FB |
2135 | { |
2136 | struct sched_param *target_schp = (void *)arg3; | |
2137 | struct sched_param schp; | |
2138 | schp.sched_priority = tswap32(target_schp->sched_priority); | |
2139 | ret = get_errno(sched_setscheduler(arg1, arg2, &schp)); | |
2140 | } | |
2141 | break; | |
31e31b8a | 2142 | case TARGET_NR_sched_getscheduler: |
5cd4393b FB |
2143 | ret = get_errno(sched_getscheduler(arg1)); |
2144 | break; | |
31e31b8a FB |
2145 | case TARGET_NR_sched_yield: |
2146 | ret = get_errno(sched_yield()); | |
2147 | break; | |
2148 | case TARGET_NR_sched_get_priority_max: | |
5cd4393b FB |
2149 | ret = get_errno(sched_get_priority_max(arg1)); |
2150 | break; | |
31e31b8a | 2151 | case TARGET_NR_sched_get_priority_min: |
5cd4393b FB |
2152 | ret = get_errno(sched_get_priority_min(arg1)); |
2153 | break; | |
31e31b8a | 2154 | case TARGET_NR_sched_rr_get_interval: |
5cd4393b FB |
2155 | { |
2156 | struct target_timespec *target_ts = (void *)arg2; | |
2157 | struct timespec ts; | |
2158 | ret = get_errno(sched_rr_get_interval(arg1, &ts)); | |
2159 | if (!is_error(ret)) { | |
2160 | target_ts->tv_sec = tswapl(ts.tv_sec); | |
2161 | target_ts->tv_nsec = tswapl(ts.tv_nsec); | |
2162 | } | |
2163 | } | |
2164 | break; | |
31e31b8a | 2165 | case TARGET_NR_nanosleep: |
1b6b029e FB |
2166 | { |
2167 | struct target_timespec *target_req = (void *)arg1; | |
2168 | struct target_timespec *target_rem = (void *)arg2; | |
2169 | struct timespec req, rem; | |
2170 | req.tv_sec = tswapl(target_req->tv_sec); | |
2171 | req.tv_nsec = tswapl(target_req->tv_nsec); | |
2172 | ret = get_errno(nanosleep(&req, &rem)); | |
2173 | if (target_rem) { | |
2174 | target_rem->tv_sec = tswapl(rem.tv_sec); | |
2175 | target_rem->tv_nsec = tswapl(rem.tv_nsec); | |
2176 | } | |
2177 | } | |
2178 | break; | |
31e31b8a | 2179 | case TARGET_NR_setresuid: |
b03c60f3 FB |
2180 | ret = get_errno(setresuid(low2highuid(arg1), |
2181 | low2highuid(arg2), | |
2182 | low2highuid(arg3))); | |
2183 | break; | |
31e31b8a | 2184 | case TARGET_NR_getresuid: |
b03c60f3 FB |
2185 | { |
2186 | int ruid, euid, suid; | |
2187 | ret = get_errno(getresuid(&ruid, &euid, &suid)); | |
2188 | if (!is_error(ret)) { | |
2189 | *(uint16_t *)arg1 = tswap16(high2lowuid(ruid)); | |
2190 | *(uint16_t *)arg2 = tswap16(high2lowuid(euid)); | |
2191 | *(uint16_t *)arg3 = tswap16(high2lowuid(suid)); | |
2192 | } | |
2193 | } | |
2194 | break; | |
2195 | case TARGET_NR_setresgid: | |
2196 | ret = get_errno(setresgid(low2highgid(arg1), | |
2197 | low2highgid(arg2), | |
2198 | low2highgid(arg3))); | |
2199 | break; | |
2200 | case TARGET_NR_getresgid: | |
2201 | { | |
2202 | int rgid, egid, sgid; | |
2203 | ret = get_errno(getresgid(&rgid, &egid, &sgid)); | |
2204 | if (!is_error(ret)) { | |
2205 | *(uint16_t *)arg1 = high2lowgid(tswap16(rgid)); | |
2206 | *(uint16_t *)arg2 = high2lowgid(tswap16(egid)); | |
2207 | *(uint16_t *)arg3 = high2lowgid(tswap16(sgid)); | |
2208 | } | |
2209 | } | |
2210 | break; | |
31e31b8a | 2211 | case TARGET_NR_query_module: |
5cd4393b | 2212 | goto unimplemented; |
31e31b8a | 2213 | case TARGET_NR_nfsservctl: |
5cd4393b | 2214 | goto unimplemented; |
31e31b8a | 2215 | case TARGET_NR_prctl: |
5cd4393b | 2216 | goto unimplemented; |
31e31b8a | 2217 | case TARGET_NR_pread: |
206f0fa7 FB |
2218 | page_unprotect_range((void *)arg2, arg3); |
2219 | ret = get_errno(pread(arg1, (void *)arg2, arg3, arg4)); | |
2220 | break; | |
31e31b8a | 2221 | case TARGET_NR_pwrite: |
206f0fa7 FB |
2222 | ret = get_errno(pwrite(arg1, (void *)arg2, arg3, arg4)); |
2223 | break; | |
31e31b8a FB |
2224 | case TARGET_NR_chown: |
2225 | ret = get_errno(chown((const char *)arg1, arg2, arg3)); | |
2226 | break; | |
2227 | case TARGET_NR_getcwd: | |
72f03900 | 2228 | ret = get_errno(sys_getcwd1((char *)arg1, arg2)); |
31e31b8a FB |
2229 | break; |
2230 | case TARGET_NR_capget: | |
5cd4393b | 2231 | goto unimplemented; |
31e31b8a | 2232 | case TARGET_NR_capset: |
5cd4393b | 2233 | goto unimplemented; |
31e31b8a | 2234 | case TARGET_NR_sigaltstack: |
5cd4393b | 2235 | goto unimplemented; |
31e31b8a | 2236 | case TARGET_NR_sendfile: |
5cd4393b | 2237 | goto unimplemented; |
31e31b8a | 2238 | case TARGET_NR_getpmsg: |
5cd4393b | 2239 | goto unimplemented; |
31e31b8a | 2240 | case TARGET_NR_putpmsg: |
5cd4393b | 2241 | goto unimplemented; |
31e31b8a | 2242 | case TARGET_NR_vfork: |
1b6b029e | 2243 | ret = get_errno(do_fork(cpu_env, CLONE_VFORK | CLONE_VM | SIGCHLD, 0)); |
31e31b8a FB |
2244 | break; |
2245 | case TARGET_NR_ugetrlimit: | |
728584be FB |
2246 | { |
2247 | struct rlimit rlim; | |
2248 | ret = get_errno(getrlimit(arg1, &rlim)); | |
2249 | if (!is_error(ret)) { | |
2250 | struct target_rlimit *target_rlim = (void *)arg2; | |
2251 | target_rlim->rlim_cur = tswapl(rlim.rlim_cur); | |
2252 | target_rlim->rlim_max = tswapl(rlim.rlim_max); | |
2253 | } | |
2254 | break; | |
2255 | } | |
31e31b8a | 2256 | case TARGET_NR_truncate64: |
5cd4393b | 2257 | goto unimplemented; |
31e31b8a | 2258 | case TARGET_NR_ftruncate64: |
60cd49d5 | 2259 | goto unimplemented; |
31e31b8a | 2260 | case TARGET_NR_stat64: |
ec86b0fb | 2261 | ret = get_errno(stat(path((const char *)arg1), &st)); |
60cd49d5 | 2262 | goto do_stat64; |
31e31b8a | 2263 | case TARGET_NR_lstat64: |
ec86b0fb | 2264 | ret = get_errno(lstat(path((const char *)arg1), &st)); |
60cd49d5 | 2265 | goto do_stat64; |
31e31b8a | 2266 | case TARGET_NR_fstat64: |
60cd49d5 FB |
2267 | { |
2268 | ret = get_errno(fstat(arg1, &st)); | |
2269 | do_stat64: | |
2270 | if (!is_error(ret)) { | |
2271 | struct target_stat64 *target_st = (void *)arg2; | |
ec86b0fb | 2272 | memset(target_st, 0, sizeof(struct target_stat64)); |
60cd49d5 | 2273 | target_st->st_dev = tswap16(st.st_dev); |
728584be | 2274 | target_st->st_ino = tswap64(st.st_ino); |
ec86b0fb FB |
2275 | #ifdef TARGET_STAT64_HAS_BROKEN_ST_INO |
2276 | target_st->__st_ino = tswapl(st.st_ino); | |
2277 | #endif | |
9af9eaaa | 2278 | target_st->st_mode = tswap32(st.st_mode); |
ec86b0fb FB |
2279 | target_st->st_nlink = tswap32(st.st_nlink); |
2280 | target_st->st_uid = tswapl(st.st_uid); | |
2281 | target_st->st_gid = tswapl(st.st_gid); | |
60cd49d5 FB |
2282 | target_st->st_rdev = tswap16(st.st_rdev); |
2283 | /* XXX: better use of kernel struct */ | |
ec86b0fb | 2284 | target_st->st_size = tswap64(st.st_size); |
60cd49d5 FB |
2285 | target_st->st_blksize = tswapl(st.st_blksize); |
2286 | target_st->st_blocks = tswapl(st.st_blocks); | |
7854b056 FB |
2287 | target_st->target_st_atime = tswapl(st.st_atime); |
2288 | target_st->target_st_mtime = tswapl(st.st_mtime); | |
2289 | target_st->target_st_ctime = tswapl(st.st_ctime); | |
60cd49d5 FB |
2290 | } |
2291 | } | |
2292 | break; | |
2293 | ||
31e31b8a | 2294 | case TARGET_NR_lchown32: |
b03c60f3 FB |
2295 | ret = get_errno(lchown((const char *)arg1, arg2, arg3)); |
2296 | break; | |
31e31b8a | 2297 | case TARGET_NR_getuid32: |
b03c60f3 FB |
2298 | ret = get_errno(getuid()); |
2299 | break; | |
31e31b8a | 2300 | case TARGET_NR_getgid32: |
b03c60f3 FB |
2301 | ret = get_errno(getgid()); |
2302 | break; | |
31e31b8a | 2303 | case TARGET_NR_geteuid32: |
b03c60f3 FB |
2304 | ret = get_errno(geteuid()); |
2305 | break; | |
31e31b8a | 2306 | case TARGET_NR_getegid32: |
b03c60f3 FB |
2307 | ret = get_errno(getegid()); |
2308 | break; | |
31e31b8a | 2309 | case TARGET_NR_setreuid32: |
b03c60f3 FB |
2310 | ret = get_errno(setreuid(arg1, arg2)); |
2311 | break; | |
31e31b8a | 2312 | case TARGET_NR_setregid32: |
b03c60f3 FB |
2313 | ret = get_errno(setregid(arg1, arg2)); |
2314 | break; | |
31e31b8a | 2315 | case TARGET_NR_getgroups32: |
b03c60f3 | 2316 | goto unimplemented; |
31e31b8a | 2317 | case TARGET_NR_setgroups32: |
b03c60f3 | 2318 | goto unimplemented; |
31e31b8a | 2319 | case TARGET_NR_fchown32: |
b03c60f3 FB |
2320 | ret = get_errno(fchown(arg1, arg2, arg3)); |
2321 | break; | |
31e31b8a | 2322 | case TARGET_NR_setresuid32: |
b03c60f3 FB |
2323 | ret = get_errno(setresuid(arg1, arg2, arg3)); |
2324 | break; | |
31e31b8a | 2325 | case TARGET_NR_getresuid32: |
b03c60f3 FB |
2326 | { |
2327 | int ruid, euid, suid; | |
2328 | ret = get_errno(getresuid(&ruid, &euid, &suid)); | |
2329 | if (!is_error(ret)) { | |
2330 | *(uint32_t *)arg1 = tswap32(ruid); | |
2331 | *(uint32_t *)arg2 = tswap32(euid); | |
2332 | *(uint32_t *)arg3 = tswap32(suid); | |
2333 | } | |
2334 | } | |
2335 | break; | |
31e31b8a | 2336 | case TARGET_NR_setresgid32: |
b03c60f3 FB |
2337 | ret = get_errno(setresgid(arg1, arg2, arg3)); |
2338 | break; | |
31e31b8a | 2339 | case TARGET_NR_getresgid32: |
b03c60f3 FB |
2340 | { |
2341 | int rgid, egid, sgid; | |
2342 | ret = get_errno(getresgid(&rgid, &egid, &sgid)); | |
2343 | if (!is_error(ret)) { | |
2344 | *(uint32_t *)arg1 = tswap32(rgid); | |
2345 | *(uint32_t *)arg2 = tswap32(egid); | |
2346 | *(uint32_t *)arg3 = tswap32(sgid); | |
2347 | } | |
2348 | } | |
2349 | break; | |
31e31b8a | 2350 | case TARGET_NR_chown32: |
b03c60f3 FB |
2351 | ret = get_errno(chown((const char *)arg1, arg2, arg3)); |
2352 | break; | |
31e31b8a | 2353 | case TARGET_NR_setuid32: |
b03c60f3 FB |
2354 | ret = get_errno(setuid(arg1)); |
2355 | break; | |
31e31b8a | 2356 | case TARGET_NR_setgid32: |
b03c60f3 FB |
2357 | ret = get_errno(setgid(arg1)); |
2358 | break; | |
31e31b8a | 2359 | case TARGET_NR_setfsuid32: |
b03c60f3 FB |
2360 | ret = get_errno(setfsuid(arg1)); |
2361 | break; | |
31e31b8a | 2362 | case TARGET_NR_setfsgid32: |
b03c60f3 FB |
2363 | ret = get_errno(setfsgid(arg1)); |
2364 | break; | |
31e31b8a | 2365 | case TARGET_NR_pivot_root: |
b03c60f3 | 2366 | goto unimplemented; |
31e31b8a | 2367 | case TARGET_NR_mincore: |
b03c60f3 | 2368 | goto unimplemented; |
31e31b8a | 2369 | case TARGET_NR_madvise: |
60cd49d5 FB |
2370 | goto unimplemented; |
2371 | #if TARGET_LONG_BITS == 32 | |
31e31b8a | 2372 | case TARGET_NR_fcntl64: |
77e4672d FB |
2373 | { |
2374 | struct flock64 fl; | |
2375 | struct target_flock64 *target_fl = (void *)arg3; | |
2376 | ||
60cd49d5 FB |
2377 | switch(arg2) { |
2378 | case F_GETLK64: | |
77e4672d FB |
2379 | ret = get_errno(fcntl(arg1, arg2, &fl)); |
2380 | if (ret == 0) { | |
2381 | target_fl->l_type = tswap16(fl.l_type); | |
2382 | target_fl->l_whence = tswap16(fl.l_whence); | |
2383 | target_fl->l_start = tswap64(fl.l_start); | |
2384 | target_fl->l_len = tswap64(fl.l_len); | |
2385 | target_fl->l_pid = tswapl(fl.l_pid); | |
2386 | } | |
2387 | break; | |
2388 | ||
60cd49d5 FB |
2389 | case F_SETLK64: |
2390 | case F_SETLKW64: | |
77e4672d FB |
2391 | fl.l_type = tswap16(target_fl->l_type); |
2392 | fl.l_whence = tswap16(target_fl->l_whence); | |
2393 | fl.l_start = tswap64(target_fl->l_start); | |
2394 | fl.l_len = tswap64(target_fl->l_len); | |
2395 | fl.l_pid = tswapl(target_fl->l_pid); | |
2396 | ret = get_errno(fcntl(arg1, arg2, &fl)); | |
2397 | break; | |
60cd49d5 | 2398 | default: |
7775e9ec | 2399 | ret = get_errno(do_fcntl(arg1, arg2, arg3)); |
60cd49d5 FB |
2400 | break; |
2401 | } | |
77e4672d FB |
2402 | break; |
2403 | } | |
60cd49d5 | 2404 | #endif |
31e31b8a FB |
2405 | case TARGET_NR_security: |
2406 | goto unimplemented; | |
2407 | case TARGET_NR_gettid: | |
2408 | ret = get_errno(gettid()); | |
2409 | break; | |
2410 | case TARGET_NR_readahead: | |
5cd4393b | 2411 | goto unimplemented; |
31e31b8a FB |
2412 | case TARGET_NR_setxattr: |
2413 | case TARGET_NR_lsetxattr: | |
2414 | case TARGET_NR_fsetxattr: | |
2415 | case TARGET_NR_getxattr: | |
2416 | case TARGET_NR_lgetxattr: | |
2417 | case TARGET_NR_fgetxattr: | |
2418 | case TARGET_NR_listxattr: | |
2419 | case TARGET_NR_llistxattr: | |
2420 | case TARGET_NR_flistxattr: | |
2421 | case TARGET_NR_removexattr: | |
2422 | case TARGET_NR_lremovexattr: | |
2423 | case TARGET_NR_fremovexattr: | |
5cd4393b FB |
2424 | goto unimplemented_nowarn; |
2425 | case TARGET_NR_set_thread_area: | |
2426 | case TARGET_NR_get_thread_area: | |
2427 | goto unimplemented_nowarn; | |
31e31b8a FB |
2428 | default: |
2429 | unimplemented: | |
5cd4393b FB |
2430 | gemu_log("qemu: Unsupported syscall: %d\n", num); |
2431 | unimplemented_nowarn: | |
31e31b8a FB |
2432 | ret = -ENOSYS; |
2433 | break; | |
2434 | } | |
2435 | fail: | |
2436 | return ret; | |
2437 | } | |
2438 |