Skip to content
This repository has been archived by the owner on Apr 13, 2019. It is now read-only.

Commit

Permalink
linux-uxer/riscv - fix stat on riscv32 linux-user
Browse files Browse the repository at this point in the history
riscv32 linux ABI is unique in that it has a 64-bit stat
structure on 32-bit vs seperate stat and stat64 syscalls.

Test program:

  #include <stdlib.h>

  int
  main (void)
  {
    int fd = open ("tmp.file", O_CREAT|O_RDWR, S_IRWXU);
    if (fd == -1) {
      perror ("open failed");
      exit (1);
    }
    struct stat buf;
    int result = fstat (fd, &buf);
    if (result == -1) {
      perror ("fstat failed");
      exit (1);
    }
    printf ("S_ISREG (buf.st_mode) = %d\n", S_ISREG (buf.st_mode));
    return 0;
  }

Expected results:

  $ riscv32-unknown-linux-gnu-gcc -O2 stat.c -o stat
  $ qemu-riscv32 stat
  S_ISREG (buf.st_mode) = 1

Signed-off-by: Michael Clark <mjc@sifive.com>
  • Loading branch information
Michael Clark committed Oct 1, 2018
1 parent 2b5e1a7 commit 6b6f93c
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions linux-user/syscall_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1873,8 +1873,33 @@ struct target_stat64 {
abi_ulong __unused5;
};

#elif defined(TARGET_RISCV)

struct target_stat {
uint64_t st_dev;
uint64_t st_ino;
unsigned int st_mode;
unsigned int st_nlink;
unsigned int st_uid;
unsigned int st_gid;
uint64_t st_rdev;
uint64_t __pad1;
int64_t st_size;
int st_blksize;
int __pad2;
int64_t st_blocks;
int target_st_atime;
unsigned int target_st_atime_nsec;
int target_st_mtime;
unsigned int target_st_mtime_nsec;
int target_st_ctime;
unsigned int target_st_ctime_nsec;
unsigned int __unused4;
unsigned int __unused5;
};

#elif defined(TARGET_OPENRISC) || defined(TARGET_TILEGX) || \
defined(TARGET_NIOS2) || defined(TARGET_RISCV)
defined(TARGET_NIOS2)

/* These are the asm-generic versions of the stat and stat64 structures */

Expand All @@ -1901,7 +1926,6 @@ struct target_stat {
unsigned int __unused5;
};

#if !defined(TARGET_RISCV64)
#define TARGET_HAS_STRUCT_STAT64
struct target_stat64 {
uint64_t st_dev;
Expand All @@ -1925,7 +1949,6 @@ struct target_stat64 {
unsigned int __unused4;
unsigned int __unused5;
};
#endif

#elif defined(TARGET_HPPA)

Expand Down

0 comments on commit 6b6f93c

Please sign in to comment.