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