diff options
author | Adhemerval Zanella <adhemerval.zanella@linaro.org> | 2020-07-18 08:20:46 -0300 |
---|---|---|
committer | Adhemerval Zanella <adhemerval.zanella@linaro.org> | 2020-10-09 17:02:06 -0300 |
commit | 6073bae64ccf27d6ebf5e49592a715801e14a5ba (patch) | |
tree | dfcd07c7eb2ac8f058ba303b87347c848c7b747d /sysdeps/unix/sysv/linux/fstatat.c | |
parent | 30f1c7439489bf756a45e349d69be1826e0c9bd8 (diff) | |
download | glibc-6073bae64ccf27d6ebf5e49592a715801e14a5ba.tar.gz glibc-6073bae64ccf27d6ebf5e49592a715801e14a5ba.tar.xz glibc-6073bae64ccf27d6ebf5e49592a715801e14a5ba.zip |
linux: Disentangle fstatat from fxstatat
It implements all the required syscall for the all Linux kABIS on fstatat{64} instead of calling fxstatat{64}. On non-LFS implementation, it handles 3 cases: 1. New kABIs which uses generic pre 64-bit time Linux ABI (csky and nios): it issues __NR_fstat64 plus handle the overflow on st_ino, st_size, or st_blocks. 2. Old KABIs with old non-LFS support (arm, i386, hppa, m68k, microblaze, mips32, s390, sh, powerpc, and sparc32): it issues __NR_fstatat64 and convert the result to struct stat. 3. 64-bit kABI outliers (mips64 and mips64-n32): it issues __NR_newfstatat and convert the result to struct stat. The generic LFS implementation handles multiple cases: 1. XSTAT_IS_XSTAT64 being 1: 1.1. 64-bit kABI (aarch64, ia64, powerpc64*, s390x, riscv64, and x86_64): it issues __NR_newfstatat. 1.2. 64-bit kABI outlier (alpha): it issues __NR_fstatat64. 1.3. 64-bit kABI outlier where struct stat64 does not match kernel one (sparc64): it issues __NR_fstatat64 and convert the result to struct stat64. 1.4. 32-bit kABI with default 64-bit time_t (arc, riscv32): it issues __NR_statx and convert the result to struct stat64. 2. Old ABIs with XSTAT_IS_XSTAT64 being 0: 2.1. All kABIs with non-LFS support (arm, csky, i386, hppa, m68k, microblaze, nios2, sh, powerpc32, and sparc32): it issues __NR_fstatat64. 2.2. 64-bit kABI outliers (mips64 and mips64-n32): it issues __NR_newfstatat and convert the result to struct stat64. It allows to remove all the hidden definitions from the {f,l}xstat{64} (some are still kept because Hurd requires it). Checked with a build for all affected ABIs. I also checked on x86_64, i686, powerpc, powerpc64le, sparcv9, sparc64, s390, and s390x. Reviewed-by: Lukasz Majewski <lukma@denx.de>
Diffstat (limited to 'sysdeps/unix/sysv/linux/fstatat.c')
-rw-r--r-- | sysdeps/unix/sysv/linux/fstatat.c | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/sysdeps/unix/sysv/linux/fstatat.c b/sysdeps/unix/sysv/linux/fstatat.c index 457496605c..c7fcfaf277 100644 --- a/sysdeps/unix/sysv/linux/fstatat.c +++ b/sysdeps/unix/sysv/linux/fstatat.c @@ -18,12 +18,64 @@ #include <sys/stat.h> #include <kernel_stat.h> +#include <sysdep.h> #if !XSTAT_IS_XSTAT64 +# include <kstat_cp.h> + int __fstatat (int fd, const char *file, struct stat *buf, int flag) { - return __fxstatat (_STAT_VER, fd, file, buf, flag); +# if STAT_IS_KERNEL_STAT + /* New kABIs which uses generic pre 64-bit time Linux ABI, e.g. + csky, nios2 */ + int r = INLINE_SYSCALL_CALL (fstatat64, fd, file, buf, flag); + if (r == 0 && (buf->__st_ino_pad != 0 + || buf->__st_size_pad != 0 + || buf->__st_blocks_pad != 0)) + return INLINE_SYSCALL_ERROR_RETURN_VALUE (EOVERFLOW); + return r; +# else +# ifdef __NR_fstatat64 + /* Old KABIs with old non-LFS support, e.g. arm, i386, hppa, m68k, mips32, + microblaze, s390, sh, powerpc, and sparc. */ + struct stat64 st64; + int r = INLINE_SYSCALL_CALL (fstatat64, fd, file, &st64, flag); + if (r == 0) + { + if (! in_ino_t_range (st64.st_ino) + || ! in_off_t_range (st64.st_size) + || ! in_blkcnt_t_range (st64.st_blocks)) + return INLINE_SYSCALL_ERROR_RETURN_VALUE (EOVERFLOW); + + /* Clear internal pad and reserved fields. */ + memset (buf, 0, sizeof (*buf)); + + buf->st_dev = st64.st_dev, + buf->st_ino = st64.st_ino; + buf->st_mode = st64.st_mode; + buf->st_nlink = st64.st_nlink; + buf->st_uid = st64.st_uid; + buf->st_gid = st64.st_gid; + buf->st_rdev = st64.st_rdev; + buf->st_size = st64.st_size; + buf->st_blksize = st64.st_blksize; + buf->st_blocks = st64.st_blocks; + buf->st_atim.tv_sec = st64.st_atim.tv_sec; + buf->st_atim.tv_nsec = st64.st_atim.tv_nsec; + buf->st_mtim.tv_sec = st64.st_mtim.tv_sec; + buf->st_mtim.tv_nsec = st64.st_mtim.tv_nsec; + buf->st_ctim.tv_sec = st64.st_ctim.tv_sec; + buf->st_ctim.tv_nsec = st64.st_ctim.tv_nsec; + } + return r; +# else + /* 64-bit kabi outlier, e.g. mips64 and mips64-n32. */ + struct kernel_stat kst; + int r = INLINE_SYSCALL_CALL (newfstatat, fd, file, &kst, flag); + return r ?: __cp_kstat_stat (&kst, buf); +# endif /* __nr_fstatat64 */ +# endif /* STAT_IS_KERNEL_STAT */ } weak_alias (__fstatat, fstatat) |