Commit c573ff67522c98232748bef44f18faf6ae587fff

Authored by bellard
1 parent 060366c5

stat64 fix - added getpagesize()


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@495 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 51 additions and 17 deletions
linux-user/syscall.c
@@ -239,6 +239,27 @@ extern int setresgid(gid_t, gid_t, gid_t); @@ -239,6 +239,27 @@ extern int setresgid(gid_t, gid_t, gid_t);
239 extern int getresgid(gid_t *, gid_t *, gid_t *); 239 extern int getresgid(gid_t *, gid_t *, gid_t *);
240 extern int setgroups(int, gid_t *); 240 extern int setgroups(int, gid_t *);
241 241
  242 +#define put_user(x,ptr)\
  243 +({\
  244 + int size = sizeof(*ptr);\
  245 + switch(size) {\
  246 + case 1:\
  247 + stb(ptr, (typeof(*ptr))(x));\
  248 + break;\
  249 + case 2:\
  250 + stw(ptr, (typeof(*ptr))(x));\
  251 + break;\
  252 + case 4:\
  253 + stl(ptr, (typeof(*ptr))(x));\
  254 + break;\
  255 + case 8:\
  256 + stq(ptr, (typeof(*ptr))(x));\
  257 + break;\
  258 + default:\
  259 + abort();\
  260 + }\
  261 + 0;\
  262 +})
242 static inline long get_errno(long ret) 263 static inline long get_errno(long ret)
243 { 264 {
244 if (ret == -1) 265 if (ret == -1)
@@ -1415,7 +1436,7 @@ void syscall_init(void) @@ -1415,7 +1436,7 @@ void syscall_init(void)
1415 ie++; 1436 ie++;
1416 } 1437 }
1417 } 1438 }
1418 - 1439 +
1419 long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3, 1440 long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
1420 long arg4, long arg5, long arg6) 1441 long arg4, long arg5, long arg6)
1421 { 1442 {
@@ -1424,7 +1445,7 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3, @@ -1424,7 +1445,7 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
1424 struct kernel_statfs *stfs; 1445 struct kernel_statfs *stfs;
1425 1446
1426 #ifdef DEBUG 1447 #ifdef DEBUG
1427 - gemu_log("syscall %d\n", num); 1448 + gemu_log("syscall %d", num);
1428 #endif 1449 #endif
1429 switch(num) { 1450 switch(num) {
1430 case TARGET_NR_exit: 1451 case TARGET_NR_exit:
@@ -1978,10 +1999,15 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3, @@ -1978,10 +1999,15 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
1978 #endif 1999 #endif
1979 break; 2000 break;
1980 case TARGET_NR_mmap2: 2001 case TARGET_NR_mmap2:
  2002 +#if defined(TARGET_SPARC)
  2003 +#define MMAP_SHIFT 12
  2004 +#else
  2005 +#define MMAP_SHIFT TARGET_PAGE_BITS
  2006 +#endif
1981 ret = get_errno(target_mmap(arg1, arg2, arg3, 2007 ret = get_errno(target_mmap(arg1, arg2, arg3,
1982 target_to_host_bitmask(arg4, mmap_flags_tbl), 2008 target_to_host_bitmask(arg4, mmap_flags_tbl),
1983 arg5, 2009 arg5,
1984 - arg6 << TARGET_PAGE_BITS)); 2010 + arg6 << MMAP_SHIFT));
1985 break; 2011 break;
1986 case TARGET_NR_munmap: 2012 case TARGET_NR_munmap:
1987 ret = get_errno(target_munmap(arg1, arg2)); 2013 ret = get_errno(target_munmap(arg1, arg2));
@@ -2519,23 +2545,23 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3, @@ -2519,23 +2545,23 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
2519 if (!is_error(ret)) { 2545 if (!is_error(ret)) {
2520 struct target_stat64 *target_st = (void *)arg2; 2546 struct target_stat64 *target_st = (void *)arg2;
2521 memset(target_st, 0, sizeof(struct target_stat64)); 2547 memset(target_st, 0, sizeof(struct target_stat64));
2522 - target_st->st_dev = tswap16(st.st_dev);  
2523 - target_st->st_ino = tswap64(st.st_ino); 2548 + put_user(st.st_dev, &target_st->st_dev);
  2549 + put_user(st.st_ino, &target_st->st_ino);
2524 #ifdef TARGET_STAT64_HAS_BROKEN_ST_INO 2550 #ifdef TARGET_STAT64_HAS_BROKEN_ST_INO
2525 - target_st->__st_ino = tswapl(st.st_ino); 2551 + put_user(st.st_ino, &target_st->__st_ino);
2526 #endif 2552 #endif
2527 - target_st->st_mode = tswap32(st.st_mode);  
2528 - target_st->st_nlink = tswap32(st.st_nlink);  
2529 - target_st->st_uid = tswapl(st.st_uid);  
2530 - target_st->st_gid = tswapl(st.st_gid);  
2531 - target_st->st_rdev = tswap16(st.st_rdev); 2553 + put_user(st.st_mode, &target_st->st_mode);
  2554 + put_user(st.st_nlink, &target_st->st_nlink);
  2555 + put_user(st.st_uid, &target_st->st_uid);
  2556 + put_user(st.st_gid, &target_st->st_gid);
  2557 + put_user(st.st_rdev, &target_st->st_rdev);
2532 /* XXX: better use of kernel struct */ 2558 /* XXX: better use of kernel struct */
2533 - target_st->st_size = tswap64(st.st_size);  
2534 - target_st->st_blksize = tswapl(st.st_blksize);  
2535 - target_st->st_blocks = tswapl(st.st_blocks);  
2536 - target_st->target_st_atime = tswapl(st.st_atime);  
2537 - target_st->target_st_mtime = tswapl(st.st_mtime);  
2538 - target_st->target_st_ctime = tswapl(st.st_ctime); 2559 + put_user(st.st_size, &target_st->st_size);
  2560 + put_user(st.st_blksize, &target_st->st_blksize);
  2561 + put_user(st.st_blocks, &target_st->st_blocks);
  2562 + put_user(st.st_atime, &target_st->target_st_atime);
  2563 + put_user(st.st_mtime, &target_st->target_st_mtime);
  2564 + put_user(st.st_ctime, &target_st->target_st_ctime);
2539 } 2565 }
2540 } 2566 }
2541 break; 2567 break;
@@ -2766,6 +2792,11 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3, @@ -2766,6 +2792,11 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
2766 case TARGET_NR_security: 2792 case TARGET_NR_security:
2767 goto unimplemented; 2793 goto unimplemented;
2768 #endif 2794 #endif
  2795 +#ifdef TARGET_NR_getpagesize
  2796 + case TARGET_NR_getpagesize:
  2797 + ret = TARGET_PAGE_SIZE;
  2798 + break;
  2799 +#endif
2769 case TARGET_NR_gettid: 2800 case TARGET_NR_gettid:
2770 ret = get_errno(gettid()); 2801 ret = get_errno(gettid());
2771 break; 2802 break;
@@ -2799,6 +2830,9 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3, @@ -2799,6 +2830,9 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
2799 break; 2830 break;
2800 } 2831 }
2801 fail: 2832 fail:
  2833 +#ifdef DEBUG
  2834 + gemu_log(" = %ld\n", ret);
  2835 +#endif
2802 return ret; 2836 return ret;
2803 } 2837 }
2804 2838