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