From ebb3c19cfd2ea6ace882acdade4388760bbd15e6 Mon Sep 17 00:00:00 2001 From: Mark Seaborn Date: Sun, 14 Jun 2009 14:29:40 +0100 Subject: [PATCH] fstat(): Fix to convert between the NaCl and glibc struct layouts We need NaCl's st_ino value to come out correctly because Python uses it to determine whether an extension module is the same as a previously-loaded module, which doesn't work if st_ino is always zero. --- sysdeps/nacl/fxstat.c | 36 +++++++++++++++++-- sysdeps/nacl/fxstat64.c | 33 ++++++++++++++++-- sysdeps/nacl/nacl_stat.h | 91 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 156 insertions(+), 4 deletions(-) create mode 100644 sysdeps/nacl/nacl_stat.h diff --git a/sysdeps/nacl/fxstat.c b/sysdeps/nacl/fxstat.c index f3724a0193..4deabc6f49 100644 --- a/sysdeps/nacl/fxstat.c +++ b/sysdeps/nacl/fxstat.c @@ -3,18 +3,50 @@ #include #include +#include +#include #include int __fxstat(int vers, int fd, struct stat *buf) { - int (*nacl_fstat)(int fd, struct stat *buf) = + int (*nacl_fstat)(int fd, struct nacl_abi_stat *buf) = NACL_SYSCALL_ADDR(NACL_sys_fstat); - int result = nacl_fstat(fd, buf); + + struct nacl_abi_stat nacl_buf; + int result = nacl_fstat(fd, &nacl_buf); if (result < 0) { errno = -result; return -1; } + buf->st_dev = nacl_buf.nacl_abi_st_dev; +#ifdef _HAVE_STAT___PAD1 + buf->__pad1 = 0; +#endif + buf->st_ino = nacl_buf.nacl_abi_st_ino; + buf->st_mode = nacl_buf.nacl_abi_st_mode; + buf->st_nlink = nacl_buf.nacl_abi_st_nlink; + buf->st_uid = nacl_buf.nacl_abi_st_uid; + buf->st_gid = nacl_buf.nacl_abi_st_gid; + buf->st_rdev = nacl_buf.nacl_abi_st_rdev; +#ifdef _HAVE_STAT___PAD2 + buf->__pad2 = 0; +#endif + buf->st_size = nacl_buf.nacl_abi_st_size; + buf->st_blksize = nacl_buf.nacl_abi_st_blksize; + buf->st_blocks = nacl_buf.nacl_abi_st_blocks; + buf->st_atim.tv_sec = nacl_buf.nacl_abi_st_atime; + buf->st_atim.tv_nsec = 0; + buf->st_mtim.tv_sec = nacl_buf.nacl_abi_st_mtime; + buf->st_mtim.tv_nsec = 0; + buf->st_ctim.tv_sec = nacl_buf.nacl_abi_st_ctime; + buf->st_ctim.tv_nsec = 0; +#ifdef _HAVE_STAT___UNUSED4 + buf->__unused4 = 0; +#endif +#ifdef _HAVE_STAT___UNUSED5 + buf->__unused5 = 0; +#endif return result; } hidden_def (__fxstat) diff --git a/sysdeps/nacl/fxstat64.c b/sysdeps/nacl/fxstat64.c index 27614c39c7..5405231e7c 100644 --- a/sysdeps/nacl/fxstat64.c +++ b/sysdeps/nacl/fxstat64.c @@ -3,18 +3,47 @@ #include #include +#include +#include #include int __fxstat64(int vers, int fd, struct stat64 *buf) { - int (*nacl_fstat)(int fd, struct stat64 *buf) = + int (*nacl_fstat)(int fd, struct nacl_abi_stat *buf) = NACL_SYSCALL_ADDR(NACL_sys_fstat); - int result = nacl_fstat(fd, buf); + + struct nacl_abi_stat nacl_buf; + int result = nacl_fstat(fd, &nacl_buf); if (result < 0) { errno = -result; return -1; } + buf->st_dev = nacl_buf.nacl_abi_st_dev; +#ifdef _HAVE_STAT64___PAD1 + buf->__pad1 = 0; +#endif +#ifdef _HAVE_STAT64___ST_INO + buf->__st_ino = nacl_buf.nacl_abi_st_ino; +#endif + buf->st_mode = nacl_buf.nacl_abi_st_mode; + buf->st_nlink = nacl_buf.nacl_abi_st_nlink; + buf->st_uid = nacl_buf.nacl_abi_st_uid; + buf->st_gid = nacl_buf.nacl_abi_st_gid; + buf->st_rdev = nacl_buf.nacl_abi_st_rdev; +#ifdef _HAVE_STAT64___PAD2 + buf->__pad2 = 0; +#endif + buf->st_size = nacl_buf.nacl_abi_st_size; + buf->st_blksize = nacl_buf.nacl_abi_st_blksize; + buf->st_blocks = nacl_buf.nacl_abi_st_blocks; + buf->st_atim.tv_sec = nacl_buf.nacl_abi_st_atime; + buf->st_atim.tv_nsec = 0; + buf->st_mtim.tv_sec = nacl_buf.nacl_abi_st_mtime; + buf->st_mtim.tv_nsec = 0; + buf->st_ctim.tv_sec = nacl_buf.nacl_abi_st_ctime; + buf->st_ctim.tv_nsec = 0; + buf->st_ino = nacl_buf.nacl_abi_st_ino; return result; } hidden_def (__fxstat64) diff --git a/sysdeps/nacl/nacl_stat.h b/sysdeps/nacl/nacl_stat.h new file mode 100644 index 0000000000..94f8873f90 --- /dev/null +++ b/sysdeps/nacl/nacl_stat.h @@ -0,0 +1,91 @@ + +#ifndef _NACL_STAT_H +#define _NACL_STAT_H + + +/* From service_runtime/include/machine/_types.h */ + +#include + +#ifndef nacl_abi___dev_t_defined +#define nacl_abi___dev_t_defined +typedef int64_t nacl_abi___dev_t; +typedef nacl_abi___dev_t nacl_abi_dev_t; +#endif + +#ifndef nacl_abi___ino_t_defined +#define nacl_abi___ino_t_defined +typedef unsigned long nacl_abi___ino_t; +typedef nacl_abi___ino_t nacl_abi_ino_t; +#endif + +#ifndef nacl_abi___mode_t_defined +#define nacl_abi___mode_t_defined +typedef uint32_t nacl_abi___mode_t; +typedef nacl_abi___mode_t nacl_abi_mode_t; +#endif + +#ifndef nacl_abi___nlink_t_defined +#define nacl_abi___nlink_t_defined +typedef unsigned int nacl_abi___nlink_t; +typedef nacl_abi___nlink_t nacl_abi_nlink_t; +#endif + +#ifndef nacl_abi___uid_t_defined +#define nacl_abi___uid_t_defined +typedef uint32_t nacl_abi___uid_t; +typedef nacl_abi___uid_t nacl_abi_uid_t; +#endif + +#ifndef nacl_abi___gid_t_defined +#define nacl_abi___gid_t_defined +typedef uint32_t nacl_abi___gid_t; +typedef nacl_abi___gid_t nacl_abi_gid_t; +#endif + +#ifndef nacl_abi___off_t_defined +#define nacl_abi___off_t_defined +typedef long int nacl_abi__off_t; +typedef nacl_abi__off_t nacl_abi_off_t; +#endif + +#ifndef nacl_abi___blksize_t_defined +#define nacl_abi___blksize_t_defined +typedef long int nacl_abi___blksize_t; +typedef nacl_abi___blksize_t nacl_abi_blksize_t; +#endif + +#ifndef nacl_abi___blkcnt_t_defined +#define nacl_abi___blkcnt_t_defined +typedef long int nacl_abi___blkcnt_t; +typedef nacl_abi___blkcnt_t nacl_abi_blkcnt_t; +#endif + +#ifndef nacl_abi___time_t_defined +#define nacl_abi___time_t_defined +typedef int32_t nacl_abi___time_t; +typedef nacl_abi___time_t nacl_abi_time_t; +#endif + + +/* From service_runtime/fs/fs.h */ + +struct nacl_abi_stat { /* must be renamed when ABI is exported */ + nacl_abi_dev_t nacl_abi_st_dev; /* not implemented */ + nacl_abi_ino_t nacl_abi_st_ino; /* not implemented */ + nacl_abi_mode_t nacl_abi_st_mode; /* partially implemented. */ + nacl_abi_nlink_t nacl_abi_st_nlink; /* link count */ + nacl_abi_uid_t nacl_abi_st_uid; /* not implemented */ + nacl_abi_gid_t nacl_abi_st_gid; /* not implemented */ + int __padding; /* needed to align st_rdev */ + nacl_abi_dev_t nacl_abi_st_rdev; /* not implemented */ + nacl_abi_off_t nacl_abi_st_size; /* object size */ + nacl_abi_blksize_t nacl_abi_st_blksize; /* not implemented */ + nacl_abi_blkcnt_t nacl_abi_st_blocks; /* not implemented */ + nacl_abi_time_t nacl_abi_st_atime; /* access time */ + nacl_abi_time_t nacl_abi_st_mtime; /* modification time */ + nacl_abi_time_t nacl_abi_st_ctime; /* inode change time */ +}; + + +#endif -- 2.11.4.GIT