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