Browse Source

Fix struct stat size mismatch for RV32

pull/12/merge
Andrew Waterman 10 years ago
parent
commit
7016bac5df
  1. 6
      pk/file.c
  2. 17
      pk/frontend.c
  3. 26
      pk/frontend.h
  4. 12
      pk/syscall.c

6
pk/file.c

@ -141,8 +141,10 @@ ssize_t file_pwrite(file_t* f, const void* buf, size_t size, off_t offset)
int file_stat(file_t* f, struct stat* s)
{
populate_mapping(s, sizeof(*s), PROT_WRITE);
return frontend_syscall(SYS_fstat, f->kfd, (uintptr_t)s, 0, 0, 0, 0, 0);
struct frontend_stat buf;
long ret = frontend_syscall(SYS_fstat, f->kfd, (uintptr_t)&buf, 0, 0, 0, 0, 0);
copy_stat(s, &buf);
return ret;
}
int file_truncate(file_t* f, off_t len)

17
pk/frontend.c

@ -51,3 +51,20 @@ void die(int code)
frontend_syscall(SYS_exit, code, 0, 0, 0, 0, 0, 0);
while (1);
}
void copy_stat(struct stat* dest, struct frontend_stat* src)
{
dest->st_dev = src->dev;
dest->st_ino = src->ino;
dest->st_mode = src->mode;
dest->st_nlink = src->nlink;
dest->st_uid = src->uid;
dest->st_gid = src->gid;
dest->st_rdev = src->rdev;
dest->st_size = src->size;
dest->st_blksize = src->blksize;
dest->st_blocks = src->blocks;
dest->st_atime = src->atime;
dest->st_mtime = src->mtime;
dest->st_ctime = src->ctime;
}

26
pk/frontend.h

@ -4,6 +4,7 @@
#define _RISCV_FRONTEND_H
#include <stdint.h>
#include <sys/stat.h>
#ifdef __riscv64
# define TOHOST_CMD(dev, cmd, payload) \
@ -21,4 +22,29 @@ void die(int) __attribute__((noreturn));
long frontend_syscall(long n, long a0, long a1, long a2, long a3, long a4, long a5, long a6);
uint64_t tohost_sync(unsigned dev, unsigned cmd, uint64_t payload);
struct frontend_stat {
uint64_t dev;
uint64_t ino;
uint32_t mode;
uint32_t nlink;
uint32_t uid;
uint32_t gid;
uint64_t rdev;
uint64_t __pad1;
uint64_t size;
uint32_t blksize;
uint32_t __pad2;
uint64_t blocks;
uint64_t atime;
uint64_t __pad3;
uint64_t mtime;
uint64_t __pad4;
uint64_t ctime;
uint64_t __pad5;
uint32_t __unused4;
uint32_t __unused5;
};
void copy_stat(struct stat* dest, struct frontend_stat* src);
#endif

12
pk/syscall.c

@ -212,18 +212,22 @@ ssize_t sys_lseek(int fd, size_t ptr, int dir)
long sys_lstat(const char* name, void* st)
{
struct frontend_stat buf;
size_t name_size = strlen(name)+1;
populate_mapping(st, sizeof(struct stat), PROT_WRITE);
return frontend_syscall(SYS_lstat, (uintptr_t)name, name_size, (uintptr_t)st, 0, 0, 0, 0);
long ret = frontend_syscall(SYS_lstat, (uintptr_t)name, name_size, (uintptr_t)&buf, 0, 0, 0, 0);
copy_stat(st, &buf);
return ret;
}
long sys_fstatat(int dirfd, const char* name, void* st, int flags)
{
int kfd = at_kfd(dirfd);
if (kfd != -1) {
struct frontend_stat buf;
size_t name_size = strlen(name)+1;
populate_mapping(st, sizeof(struct stat), PROT_WRITE);
return frontend_syscall(SYS_fstatat, kfd, (uintptr_t)name, name_size, (uintptr_t)st, flags, 0, 0);
long ret = frontend_syscall(SYS_fstatat, kfd, (uintptr_t)name, name_size, (uintptr_t)&buf, flags, 0, 0);
copy_stat(st, &buf);
return ret;
}
return -EBADF;
}

Loading…
Cancel
Save