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