Commit 7854b05654b49c2197faef358e3ec1a7559797b9

Authored by bellard
1 parent 500dab07

endian fixes by Ulrich weigand


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@64 c046a42c-6fe2-441c-8c8c-71466251a162
linux-user/syscall.c
... ... @@ -26,6 +26,7 @@
26 26 #include <errno.h>
27 27 #include <unistd.h>
28 28 #include <fcntl.h>
  29 +#include <time.h>
29 30 #include <sys/types.h>
30 31 #include <sys/wait.h>
31 32 #include <sys/time.h>
... ... @@ -40,6 +41,7 @@
40 41 #include <sys/uio.h>
41 42 #include <sys/poll.h>
42 43 //#include <sys/user.h>
  44 +#include <netinet/tcp.h>
43 45  
44 46 #define termios host_termios
45 47 #define winsize host_winsize
... ... @@ -166,7 +168,7 @@ static long do_brk(char *new_brk)
166 168 static inline fd_set *target_to_host_fds(fd_set *fds,
167 169 target_long *target_fds, int n)
168 170 {
169   -#if !defined(BSWP_NEEDED) && !defined(WORD_BIGENDIAN)
  171 +#if !defined(BSWAP_NEEDED) && !defined(WORDS_BIGENDIAN)
170 172 return (fd_set *)target_fds;
171 173 #else
172 174 int i, b;
... ... @@ -188,7 +190,7 @@ static inline fd_set *target_to_host_fds(fd_set *fds,
188 190 static inline void host_to_target_fds(target_long *target_fds,
189 191 fd_set *fds, int n)
190 192 {
191   -#if !defined(BSWP_NEEDED) && !defined(WORD_BIGENDIAN)
  193 +#if !defined(BSWAP_NEEDED) && !defined(WORDS_BIGENDIAN)
192 194 /* nothing to do */
193 195 #else
194 196 int i, nw, j, k;
... ... @@ -256,55 +258,267 @@ static long do_select(long n,
256 258 return ret;
257 259 }
258 260  
259   -static long do_socketcall(int num, long *vptr)
  261 +static inline void target_to_host_sockaddr(struct sockaddr *addr,
  262 + struct target_sockaddr *target_addr,
  263 + socklen_t len)
  264 +{
  265 + memcpy(addr, target_addr, len);
  266 + addr->sa_family = tswap16(target_addr->sa_family);
  267 +}
  268 +
  269 +static inline void host_to_target_sockaddr(struct target_sockaddr *target_addr,
  270 + struct sockaddr *addr,
  271 + socklen_t len)
  272 +{
  273 + memcpy(target_addr, addr, len);
  274 + target_addr->sa_family = tswap16(addr->sa_family);
  275 +}
  276 +
  277 +static inline void target_to_host_cmsg(struct msghdr *msgh,
  278 + struct target_msghdr *target_msgh)
  279 +{
  280 + struct cmsghdr *cmsg = CMSG_FIRSTHDR(msgh);
  281 + struct target_cmsghdr *target_cmsg = TARGET_CMSG_FIRSTHDR(target_msgh);
  282 + socklen_t space = 0;
  283 +
  284 + while (cmsg && target_cmsg) {
  285 + void *data = CMSG_DATA(cmsg);
  286 + void *target_data = TARGET_CMSG_DATA(target_cmsg);
  287 +
  288 + int len = tswapl(target_cmsg->cmsg_len)
  289 + - TARGET_CMSG_ALIGN(sizeof (struct target_cmsghdr));
  290 +
  291 + space += CMSG_SPACE(len);
  292 + if (space > msgh->msg_controllen) {
  293 + space -= CMSG_SPACE(len);
  294 + gemu_log("Host cmsg overflow");
  295 + break;
  296 + }
  297 +
  298 + cmsg->cmsg_level = tswap32(target_cmsg->cmsg_level);
  299 + cmsg->cmsg_type = tswap32(target_cmsg->cmsg_type);
  300 + cmsg->cmsg_len = CMSG_LEN(len);
  301 +
  302 + if (cmsg->cmsg_level != SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS) {
  303 + gemu_log("Unsupported ancillary data: %d/%d\n", cmsg->cmsg_level, cmsg->cmsg_type);
  304 + memcpy(data, target_data, len);
  305 + } else {
  306 + int *fd = (int *)data;
  307 + int *target_fd = (int *)target_data;
  308 + int i, numfds = len / sizeof(int);
  309 +
  310 + for (i = 0; i < numfds; i++)
  311 + fd[i] = tswap32(target_fd[i]);
  312 + }
  313 +
  314 + cmsg = CMSG_NXTHDR(msgh, cmsg);
  315 + target_cmsg = TARGET_CMSG_NXTHDR(target_msgh, target_cmsg);
  316 + }
  317 +
  318 + msgh->msg_controllen = space;
  319 +}
  320 +
  321 +static inline void host_to_target_cmsg(struct target_msghdr *target_msgh,
  322 + struct msghdr *msgh)
  323 +{
  324 + struct cmsghdr *cmsg = CMSG_FIRSTHDR(msgh);
  325 + struct target_cmsghdr *target_cmsg = TARGET_CMSG_FIRSTHDR(target_msgh);
  326 + socklen_t space = 0;
  327 +
  328 + while (cmsg && target_cmsg) {
  329 + void *data = CMSG_DATA(cmsg);
  330 + void *target_data = TARGET_CMSG_DATA(target_cmsg);
  331 +
  332 + int len = cmsg->cmsg_len - CMSG_ALIGN(sizeof (struct cmsghdr));
  333 +
  334 + space += TARGET_CMSG_SPACE(len);
  335 + if (space > tswapl(target_msgh->msg_controllen)) {
  336 + space -= TARGET_CMSG_SPACE(len);
  337 + gemu_log("Target cmsg overflow");
  338 + break;
  339 + }
  340 +
  341 + target_cmsg->cmsg_level = tswap32(cmsg->cmsg_level);
  342 + target_cmsg->cmsg_type = tswap32(cmsg->cmsg_type);
  343 + target_cmsg->cmsg_len = tswapl(TARGET_CMSG_LEN(len));
  344 +
  345 + if (cmsg->cmsg_level != SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS) {
  346 + gemu_log("Unsupported ancillary data: %d/%d\n", cmsg->cmsg_level, cmsg->cmsg_type);
  347 + memcpy(target_data, data, len);
  348 + } else {
  349 + int *fd = (int *)data;
  350 + int *target_fd = (int *)target_data;
  351 + int i, numfds = len / sizeof(int);
  352 +
  353 + for (i = 0; i < numfds; i++)
  354 + target_fd[i] = tswap32(fd[i]);
  355 + }
  356 +
  357 + cmsg = CMSG_NXTHDR(msgh, cmsg);
  358 + target_cmsg = TARGET_CMSG_NXTHDR(target_msgh, target_cmsg);
  359 + }
  360 +
  361 + msgh->msg_controllen = tswapl(space);
  362 +}
  363 +
  364 +static long do_setsockopt(int sockfd, int level, int optname,
  365 + void *optval, socklen_t optlen)
  366 +{
  367 + if (level == SOL_TCP) {
  368 + /* TCP options all take an 'int' value. */
  369 + int val;
  370 +
  371 + if (optlen < sizeof(uint32_t))
  372 + return -EINVAL;
  373 +
  374 + val = tswap32(*(uint32_t *)optval);
  375 + return get_errno(setsockopt(sockfd, level, optname, &val, sizeof(val)));
  376 + }
  377 +
  378 + else if (level != SOL_SOCKET) {
  379 + gemu_log("Unsupported setsockopt level: %d\n", level);
  380 + return -ENOSYS;
  381 + }
  382 +
  383 + switch (optname) {
  384 + /* Options with 'int' argument. */
  385 + case SO_DEBUG:
  386 + case SO_REUSEADDR:
  387 + case SO_TYPE:
  388 + case SO_ERROR:
  389 + case SO_DONTROUTE:
  390 + case SO_BROADCAST:
  391 + case SO_SNDBUF:
  392 + case SO_RCVBUF:
  393 + case SO_KEEPALIVE:
  394 + case SO_OOBINLINE:
  395 + case SO_NO_CHECK:
  396 + case SO_PRIORITY:
  397 + case SO_BSDCOMPAT:
  398 + case SO_PASSCRED:
  399 + case SO_TIMESTAMP:
  400 + case SO_RCVLOWAT:
  401 + case SO_RCVTIMEO:
  402 + case SO_SNDTIMEO:
  403 + {
  404 + int val;
  405 + if (optlen < sizeof(uint32_t))
  406 + return -EINVAL;
  407 + val = tswap32(*(uint32_t *)optval);
  408 + return get_errno(setsockopt(sockfd, level, optname, &val, sizeof(val)));
  409 + }
  410 +
  411 + default:
  412 + gemu_log("Unsupported setsockopt SOL_SOCKET option: %d\n", optname);
  413 + return -ENOSYS;
  414 + }
  415 +}
  416 +
  417 +static long do_getsockopt(int sockfd, int level, int optname,
  418 + void *optval, socklen_t *optlen)
  419 +{
  420 + gemu_log("getsockopt not yet supported\n");
  421 + return -ENOSYS;
  422 +}
  423 +
  424 +static long do_socketcall(int num, int32_t *vptr)
260 425 {
261 426 long ret;
262 427  
263 428 switch(num) {
264 429 case SOCKOP_socket:
265   - ret = get_errno(socket(vptr[0], vptr[1], vptr[2]));
  430 + {
  431 + int domain = tswap32(vptr[0]);
  432 + int type = tswap32(vptr[1]);
  433 + int protocol = tswap32(vptr[2]);
  434 +
  435 + ret = get_errno(socket(domain, type, protocol));
  436 + }
266 437 break;
267 438 case SOCKOP_bind:
268   - ret = get_errno(bind(vptr[0], (struct sockaddr *)vptr[1], vptr[2]));
  439 + {
  440 + int sockfd = tswap32(vptr[0]);
  441 + void *target_addr = (void *)tswap32(vptr[1]);
  442 + socklen_t addrlen = tswap32(vptr[2]);
  443 + void *addr = alloca(addrlen);
  444 +
  445 + target_to_host_sockaddr(addr, target_addr, addrlen);
  446 + ret = get_errno(bind(sockfd, addr, addrlen));
  447 + }
269 448 break;
270 449 case SOCKOP_connect:
271   - ret = get_errno(connect(vptr[0], (struct sockaddr *)vptr[1], vptr[2]));
  450 + {
  451 + int sockfd = tswap32(vptr[0]);
  452 + void *target_addr = (void *)tswap32(vptr[1]);
  453 + socklen_t addrlen = tswap32(vptr[2]);
  454 + void *addr = alloca(addrlen);
  455 +
  456 + target_to_host_sockaddr(addr, target_addr, addrlen);
  457 + ret = get_errno(connect(sockfd, addr, addrlen));
  458 + }
272 459 break;
273 460 case SOCKOP_listen:
274   - ret = get_errno(listen(vptr[0], vptr[1]));
  461 + {
  462 + int sockfd = tswap32(vptr[0]);
  463 + int backlog = tswap32(vptr[1]);
  464 +
  465 + ret = get_errno(listen(sockfd, backlog));
  466 + }
275 467 break;
276 468 case SOCKOP_accept:
277 469 {
278   - socklen_t size;
279   - size = tswap32(*(int32_t *)vptr[2]);
280   - ret = get_errno(accept(vptr[0], (struct sockaddr *)vptr[1], &size));
281   - if (!is_error(ret))
282   - *(int32_t *)vptr[2] = size;
  470 + int sockfd = tswap32(vptr[0]);
  471 + void *target_addr = (void *)tswap32(vptr[1]);
  472 + uint32_t *target_addrlen = (void *)tswap32(vptr[2]);
  473 + socklen_t addrlen = tswap32(*target_addrlen);
  474 + void *addr = alloca(addrlen);
  475 +
  476 + ret = get_errno(accept(sockfd, addr, &addrlen));
  477 + if (!is_error(ret)) {
  478 + host_to_target_sockaddr(target_addr, addr, addrlen);
  479 + *target_addrlen = tswap32(addrlen);
  480 + }
283 481 }
284 482 break;
285 483 case SOCKOP_getsockname:
286 484 {
287   - socklen_t size;
288   - size = tswap32(*(int32_t *)vptr[2]);
289   - ret = get_errno(getsockname(vptr[0], (struct sockaddr *)vptr[1], &size));
290   - if (!is_error(ret))
291   - *(int32_t *)vptr[2] = size;
  485 + int sockfd = tswap32(vptr[0]);
  486 + void *target_addr = (void *)tswap32(vptr[1]);
  487 + uint32_t *target_addrlen = (void *)tswap32(vptr[2]);
  488 + socklen_t addrlen = tswap32(*target_addrlen);
  489 + void *addr = alloca(addrlen);
  490 +
  491 + ret = get_errno(getsockname(sockfd, addr, &addrlen));
  492 + if (!is_error(ret)) {
  493 + host_to_target_sockaddr(target_addr, addr, addrlen);
  494 + *target_addrlen = tswap32(addrlen);
  495 + }
292 496 }
293 497 break;
294 498 case SOCKOP_getpeername:
295 499 {
296   - socklen_t size;
297   - size = tswap32(*(int32_t *)vptr[2]);
298   - ret = get_errno(getpeername(vptr[0], (struct sockaddr *)vptr[1], &size));
299   - if (!is_error(ret))
300   - *(int32_t *)vptr[2] = size;
  500 + int sockfd = tswap32(vptr[0]);
  501 + void *target_addr = (void *)tswap32(vptr[1]);
  502 + uint32_t *target_addrlen = (void *)tswap32(vptr[2]);
  503 + socklen_t addrlen = tswap32(*target_addrlen);
  504 + void *addr = alloca(addrlen);
  505 +
  506 + ret = get_errno(getpeername(sockfd, addr, &addrlen));
  507 + if (!is_error(ret)) {
  508 + host_to_target_sockaddr(target_addr, addr, addrlen);
  509 + *target_addrlen = tswap32(addrlen);
  510 + }
301 511 }
302 512 break;
303 513 case SOCKOP_socketpair:
304 514 {
  515 + int domain = tswap32(vptr[0]);
  516 + int type = tswap32(vptr[1]);
  517 + int protocol = tswap32(vptr[2]);
  518 + int32_t *target_tab = (void *)tswap32(vptr[3]);
305 519 int tab[2];
306   - int32_t *target_tab = (int32_t *)vptr[3];
307   - ret = get_errno(socketpair(vptr[0], vptr[1], vptr[2], tab));
  520 +
  521 + ret = get_errno(socketpair(domain, type, protocol, tab));
308 522 if (!is_error(ret)) {
309 523 target_tab[0] = tswap32(tab[0]);
310 524 target_tab[1] = tswap32(tab[1]);
... ... @@ -312,27 +526,64 @@ static long do_socketcall(int num, long *vptr)
312 526 }
313 527 break;
314 528 case SOCKOP_send:
315   - ret = get_errno(send(vptr[0], (void *)vptr[1], vptr[2], vptr[3]));
  529 + {
  530 + int sockfd = tswap32(vptr[0]);
  531 + void *msg = (void *)tswap32(vptr[1]);
  532 + size_t len = tswap32(vptr[2]);
  533 + int flags = tswap32(vptr[3]);
  534 +
  535 + ret = get_errno(send(sockfd, msg, len, flags));
  536 + }
316 537 break;
317 538 case SOCKOP_recv:
318   - ret = get_errno(recv(vptr[0], (void *)vptr[1], vptr[2], vptr[3]));
  539 + {
  540 + int sockfd = tswap32(vptr[0]);
  541 + void *msg = (void *)tswap32(vptr[1]);
  542 + size_t len = tswap32(vptr[2]);
  543 + int flags = tswap32(vptr[3]);
  544 +
  545 + ret = get_errno(recv(sockfd, msg, len, flags));
  546 + }
319 547 break;
320 548 case SOCKOP_sendto:
321   - ret = get_errno(sendto(vptr[0], (void *)vptr[1], vptr[2], vptr[3],
322   - (struct sockaddr *)vptr[4], vptr[5]));
  549 + {
  550 + int sockfd = tswap32(vptr[0]);
  551 + void *msg = (void *)tswap32(vptr[1]);
  552 + size_t len = tswap32(vptr[2]);
  553 + int flags = tswap32(vptr[3]);
  554 + void *target_addr = (void *)tswap32(vptr[4]);
  555 + socklen_t addrlen = tswap32(vptr[5]);
  556 + void *addr = alloca(addrlen);
  557 +
  558 + target_to_host_sockaddr(addr, target_addr, addrlen);
  559 + ret = get_errno(sendto(sockfd, msg, len, flags, addr, addrlen));
  560 + }
323 561 break;
324 562 case SOCKOP_recvfrom:
325 563 {
326   - socklen_t size;
327   - size = tswap32(*(int32_t *)vptr[5]);
328   - ret = get_errno(recvfrom(vptr[0], (void *)vptr[1], vptr[2],
329   - vptr[3], (struct sockaddr *)vptr[4], &size));
330   - if (!is_error(ret))
331   - *(int32_t *)vptr[5] = size;
  564 + int sockfd = tswap32(vptr[0]);
  565 + void *msg = (void *)tswap32(vptr[1]);
  566 + size_t len = tswap32(vptr[2]);
  567 + int flags = tswap32(vptr[3]);
  568 + void *target_addr = (void *)tswap32(vptr[4]);
  569 + uint32_t *target_addrlen = (void *)tswap32(vptr[5]);
  570 + socklen_t addrlen = tswap32(*target_addrlen);
  571 + void *addr = alloca(addrlen);
  572 +
  573 + ret = get_errno(recvfrom(sockfd, msg, len, flags, addr, &addrlen));
  574 + if (!is_error(ret)) {
  575 + host_to_target_sockaddr(target_addr, addr, addrlen);
  576 + *target_addrlen = tswap32(addrlen);
  577 + }
332 578 }
333 579 break;
334 580 case SOCKOP_shutdown:
335   - ret = get_errno(shutdown(vptr[0], vptr[1]));
  581 + {
  582 + int sockfd = tswap32(vptr[0]);
  583 + int how = tswap32(vptr[1]);
  584 +
  585 + ret = get_errno(shutdown(sockfd, how));
  586 + }
336 587 break;
337 588 case SOCKOP_sendmsg:
338 589 case SOCKOP_recvmsg:
... ... @@ -344,11 +595,11 @@ static long do_socketcall(int num, long *vptr)
344 595 struct iovec *vec;
345 596 struct target_iovec *target_vec;
346 597  
347   - msgp = (void *)vptr[1];
  598 + msgp = (void *)tswap32(vptr[1]);
348 599 msg.msg_name = (void *)tswapl(msgp->msg_name);
349 600 msg.msg_namelen = tswapl(msgp->msg_namelen);
350   - msg.msg_control = (void *)tswapl(msgp->msg_control);
351   - msg.msg_controllen = tswapl(msgp->msg_controllen);
  601 + msg.msg_controllen = 2 * tswapl(msgp->msg_controllen);
  602 + msg.msg_control = alloca(msg.msg_controllen);
352 603 msg.msg_flags = tswap32(msgp->msg_flags);
353 604  
354 605 count = tswapl(msgp->msg_iovlen);
... ... @@ -361,17 +612,43 @@ static long do_socketcall(int num, long *vptr)
361 612 msg.msg_iovlen = count;
362 613 msg.msg_iov = vec;
363 614  
364   - fd = vptr[0];
365   - flags = vptr[2];
366   - if (num == SOCKOP_sendmsg)
367   - ret = sendmsg(fd, &msg, flags);
368   - else
369   - ret = recvmsg(fd, &msg, flags);
370   - ret = get_errno(ret);
  615 + fd = tswap32(vptr[0]);
  616 + flags = tswap32(vptr[2]);
  617 + if (num == SOCKOP_sendmsg) {
  618 + target_to_host_cmsg(&msg, msgp);
  619 + ret = get_errno(sendmsg(fd, &msg, flags));
  620 + } else {
  621 + ret = get_errno(recvmsg(fd, &msg, flags));
  622 + if (!is_error(ret))
  623 + host_to_target_cmsg(msgp, &msg);
  624 + }
371 625 }
372 626 break;
373 627 case SOCKOP_setsockopt:
  628 + {
  629 + int sockfd = tswap32(vptr[0]);
  630 + int level = tswap32(vptr[1]);
  631 + int optname = tswap32(vptr[2]);
  632 + void *optval = (void *)tswap32(vptr[3]);
  633 + socklen_t optlen = tswap32(vptr[4]);
  634 +
  635 + ret = do_setsockopt(sockfd, level, optname, optval, optlen);
  636 + }
  637 + break;
374 638 case SOCKOP_getsockopt:
  639 + {
  640 + int sockfd = tswap32(vptr[0]);
  641 + int level = tswap32(vptr[1]);
  642 + int optname = tswap32(vptr[2]);
  643 + void *optval = (void *)tswap32(vptr[3]);
  644 + uint32_t *target_len = (void *)tswap32(vptr[4]);
  645 + socklen_t optlen = tswap32(*target_len);
  646 +
  647 + ret = do_getsockopt(sockfd, level, optname, optval, &optlen);
  648 + if (!is_error(ret))
  649 + *target_len = tswap32(optlen);
  650 + }
  651 + break;
375 652 default:
376 653 gemu_log("Unsupported socketcall: %d\n", num);
377 654 ret = -ENOSYS;
... ... @@ -960,7 +1237,27 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
960 1237 ret = get_errno(unlink((const char *)arg1));
961 1238 break;
962 1239 case TARGET_NR_execve:
963   - ret = get_errno(execve((const char *)arg1, (void *)arg2, (void *)arg3));
  1240 + {
  1241 + char **argp, **envp;
  1242 + int argc = 0, envc = 0;
  1243 + uint32_t *p;
  1244 + char **q;
  1245 +
  1246 + for (p = (void *)arg2; *p; p++)
  1247 + argc++;
  1248 + for (p = (void *)arg3; *p; p++)
  1249 + envc++;
  1250 +
  1251 + argp = alloca(argc * sizeof(void *));
  1252 + envp = alloca(envc * sizeof(void *));
  1253 +
  1254 + for (p = (void *)arg2, q = argp; *p; p++, q++)
  1255 + *q = (void *)tswap32(*p);
  1256 + for (p = (void *)arg3, q = envp; *p; p++, q++)
  1257 + *q = (void *)tswap32(*p);
  1258 +
  1259 + ret = get_errno(execve((const char *)arg1, argp, envp));
  1260 + }
964 1261 break;
965 1262 case TARGET_NR_chdir:
966 1263 ret = get_errno(chdir((const char *)arg1));
... ... @@ -1484,7 +1781,7 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
1484 1781 case TARGET_NR_ioperm:
1485 1782 goto unimplemented;
1486 1783 case TARGET_NR_socketcall:
1487   - ret = do_socketcall(arg1, (long *)arg2);
  1784 + ret = do_socketcall(arg1, (int32_t *)arg2);
1488 1785 break;
1489 1786 case TARGET_NR_syslog:
1490 1787 goto unimplemented;
... ... @@ -1548,9 +1845,9 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
1548 1845 target_st->st_size = tswapl(st.st_size);
1549 1846 target_st->st_blksize = tswapl(st.st_blksize);
1550 1847 target_st->st_blocks = tswapl(st.st_blocks);
1551   - target_st->st_atime = tswapl(st.st_atime);
1552   - target_st->st_mtime = tswapl(st.st_mtime);
1553   - target_st->st_ctime = tswapl(st.st_ctime);
  1848 + target_st->target_st_atime = tswapl(st.st_atime);
  1849 + target_st->target_st_mtime = tswapl(st.st_mtime);
  1850 + target_st->target_st_ctime = tswapl(st.st_ctime);
1554 1851 }
1555 1852 }
1556 1853 break;
... ... @@ -1727,7 +2024,7 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
1727 2024 unsigned int nfds = arg2;
1728 2025 int timeout = arg3;
1729 2026 struct pollfd *pfd;
1730   - int i;
  2027 + unsigned int i;
1731 2028  
1732 2029 pfd = alloca(sizeof(struct pollfd) * nfds);
1733 2030 for(i = 0; i < nfds; i++) {
... ... @@ -1940,9 +2237,9 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
1940 2237 target_st->st_size = tswapl(st.st_size);
1941 2238 target_st->st_blksize = tswapl(st.st_blksize);
1942 2239 target_st->st_blocks = tswapl(st.st_blocks);
1943   - target_st->st_atime = tswapl(st.st_atime);
1944   - target_st->st_mtime = tswapl(st.st_mtime);
1945   - target_st->st_ctime = tswapl(st.st_ctime);
  2240 + target_st->target_st_atime = tswapl(st.st_atime);
  2241 + target_st->target_st_mtime = tswapl(st.st_mtime);
  2242 + target_st->target_st_ctime = tswapl(st.st_ctime);
1946 2243 }
1947 2244 }
1948 2245 break;
... ...
linux-user/syscall_defs.h
... ... @@ -19,6 +19,11 @@
19 19 #define SOCKOP_sendmsg 16
20 20 #define SOCKOP_recvmsg 17
21 21  
  22 +struct target_sockaddr {
  23 + uint16_t sa_family;
  24 + uint8_t sa_data[14];
  25 +};
  26 +
22 27 struct target_timeval {
23 28 target_long tv_sec;
24 29 target_long tv_usec;
... ... @@ -49,6 +54,43 @@ struct target_msghdr {
49 54 unsigned int msg_flags;
50 55 };
51 56  
  57 +struct target_cmsghdr {
  58 + target_long cmsg_len;
  59 + int cmsg_level;
  60 + int cmsg_type;
  61 +};
  62 +
  63 +#define TARGET_CMSG_DATA(cmsg) ((unsigned char *) ((struct target_cmsghdr *) (cmsg) + 1))
  64 +#define TARGET_CMSG_NXTHDR(mhdr, cmsg) __target_cmsg_nxthdr (mhdr, cmsg)
  65 +#define TARGET_CMSG_FIRSTHDR(mhdr) \
  66 + ((size_t) tswapl((mhdr)->msg_controllen) >= sizeof (struct target_cmsghdr) \
  67 + ? (struct target_cmsghdr *) tswapl((mhdr)->msg_control) : (struct target_cmsghdr *) NULL)
  68 +#define TARGET_CMSG_ALIGN(len) (((len) + sizeof (target_long) - 1) \
  69 + & (size_t) ~(sizeof (target_long) - 1))
  70 +#define TARGET_CMSG_SPACE(len) (TARGET_CMSG_ALIGN (len) \
  71 + + TARGET_CMSG_ALIGN (sizeof (struct target_cmsghdr)))
  72 +#define TARGET_CMSG_LEN(len) (TARGET_CMSG_ALIGN (sizeof (struct target_cmsghdr)) + (len))
  73 +
  74 +static __inline__ struct target_cmsghdr *
  75 +__target_cmsg_nxthdr (struct target_msghdr *__mhdr, struct target_cmsghdr *__cmsg)
  76 +{
  77 + if (tswapl(__cmsg->cmsg_len) < sizeof (struct target_cmsghdr))
  78 + /* The kernel header does this so there may be a reason. */
  79 + return 0;
  80 +
  81 + __cmsg = (struct target_cmsghdr *) ((unsigned char *) __cmsg
  82 + + TARGET_CMSG_ALIGN (tswapl(__cmsg->cmsg_len)));
  83 + if ((unsigned char *) (__cmsg + 1) > ((unsigned char *) tswapl(__mhdr->msg_control)
  84 + + tswapl(__mhdr->msg_controllen))
  85 + || ((unsigned char *) __cmsg + TARGET_CMSG_ALIGN (tswapl(__cmsg->cmsg_len))
  86 + > ((unsigned char *) tswapl(__mhdr->msg_control)
  87 + + tswapl(__mhdr->msg_controllen))))
  88 + /* No more entries. */
  89 + return 0;
  90 + return __cmsg;
  91 +}
  92 +
  93 +
52 94 struct target_rusage {
53 95 struct target_timeval ru_utime; /* user time used */
54 96 struct target_timeval ru_stime; /* system time used */
... ...
syscall-i386.h
... ... @@ -285,11 +285,11 @@ struct target_stat {
285 285 target_ulong st_size;
286 286 target_ulong st_blksize;
287 287 target_ulong st_blocks;
288   - target_ulong st_atime;
  288 + target_ulong target_st_atime;
289 289 target_ulong __unused1;
290   - target_ulong st_mtime;
  290 + target_ulong target_st_mtime;
291 291 target_ulong __unused2;
292   - target_ulong st_ctime;
  292 + target_ulong target_st_ctime;
293 293 target_ulong __unused3;
294 294 target_ulong __unused4;
295 295 target_ulong __unused5;
... ... @@ -320,13 +320,13 @@ struct target_stat64 {
320 320 target_ulong st_blocks; /* Number 512-byte blocks allocated. */
321 321 target_ulong __pad4; /* future possible st_blocks high bits */
322 322  
323   - target_ulong st_atime;
  323 + target_ulong target_st_atime;
324 324 target_ulong __pad5;
325 325  
326   - target_ulong st_mtime;
  326 + target_ulong target_st_mtime;
327 327 target_ulong __pad6;
328 328  
329   - target_ulong st_ctime;
  329 + target_ulong target_st_ctime;
330 330 target_ulong __pad7; /* will be high 32 bits of ctime someday */
331 331  
332 332 unsigned long long st_ino;
... ...