From 86d2feef9f4df517dd5755b39b993bec0c3e1ea5 Mon Sep 17 00:00:00 2001 From: Raghu Gandham Date: Thu, 15 Jan 2015 11:12:22 -0800 Subject: [PATCH] Modify MIPS64 stat structure to match a generic one in AOSP. The kernel version of the stat structure is used during the syscalls. After the syscall, the kernel stat structure is converted to match the generic one. Eventually we would like the generic stat structure and related syscalls be added to MIPS64 kernel, removing the thunks added to AOSP. Change-Id: I7764e80278c1cc8254754c3531ec2dda7544a8ec --- libc/SYSCALLS.TXT | 4 +- libc/arch-mips64/bionic/stat.cpp | 103 ++++++++++++++++++++++++++ libc/arch-mips64/mips64.mk | 1 + libc/arch-mips64/syscalls/fstat64.S | 28 ------- libc/arch-mips64/syscalls/fstatat64.S | 28 ------- libc/include/sys/stat.h | 4 +- 6 files changed, 108 insertions(+), 60 deletions(-) create mode 100644 libc/arch-mips64/bionic/stat.cpp delete mode 100644 libc/arch-mips64/syscalls/fstat64.S delete mode 100644 libc/arch-mips64/syscalls/fstatat64.S diff --git a/libc/SYSCALLS.TXT b/libc/SYSCALLS.TXT index a648c9fef..0fa2a1e10 100644 --- a/libc/SYSCALLS.TXT +++ b/libc/SYSCALLS.TXT @@ -134,7 +134,7 @@ int faccessat(int, const char*, int, int) all int fchmodat(int, const char*, mode_t, int) all int fchownat(int, const char*, uid_t, gid_t, int) all int fstatat64|fstatat:fstatat64(int, const char*, struct stat*, int) arm,mips,x86 -int fstatat64|fstatat:newfstatat(int, const char*, struct stat*, int) arm64,mips64,x86_64 +int fstatat64|fstatat:newfstatat(int, const char*, struct stat*, int) arm64,x86_64 int linkat(int, const char*, int, const char*, int) all int mkdirat(int, const char*, mode_t) all int mknodat(int, const char*, mode_t, dev_t) all @@ -179,7 +179,7 @@ int __statfs64:statfs64(const char*, size_t, struct statfs*) arm,mips,x86 int statfs64|statfs:statfs(const char*, struct statfs*) arm64,mips64,x86_64 int fstat64|fstat:fstat64(int, struct stat*) arm,mips,x86 -int fstat64|fstat:fstat(int, struct stat*) arm64,mips64,x86_64 +int fstat64|fstat:fstat(int, struct stat*) arm64,x86_64 # file system int chdir(const char*) all diff --git a/libc/arch-mips64/bionic/stat.cpp b/libc/arch-mips64/bionic/stat.cpp new file mode 100644 index 000000000..df63906cb --- /dev/null +++ b/libc/arch-mips64/bionic/stat.cpp @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include +#include +#include + +struct kernel_stat { + unsigned int st_dev; + unsigned int st_pad0[3]; + unsigned long st_ino; + mode_t st_mode; + __u32 st_nlink; + uid_t st_uid; + gid_t st_gid; + unsigned int st_rdev; + unsigned int st_pad1[3]; + __kernel_off_t st_size; + unsigned int _st_atime; + unsigned int st_atime_nsec; + unsigned int _st_mtime; + unsigned int st_mtime_nsec; + unsigned int _st_ctime; + unsigned int st_ctime_nsec; + unsigned int st_blksize; + unsigned int st_pad2; + unsigned long st_blocks; +}; + +void copy_stat(struct stat *st, struct kernel_stat *s) +{ + st->st_dev = static_cast(s->st_dev); + st->st_ino = static_cast(s->st_ino); + st->st_mode = static_cast(s->st_mode); + st->st_nlink = static_cast(s->st_nlink); + st->st_uid = static_cast(s->st_uid); + st->st_gid = static_cast(s->st_gid); + st->st_rdev = static_cast(s->st_rdev); + st->st_size = static_cast(s->st_size); + st->st_blksize = static_cast(s->st_blksize); + st->st_blocks = static_cast(s->st_blocks); + st->st_atim.tv_sec = static_cast(s->_st_atime); + st->st_atim.tv_nsec = static_cast(s->st_atime_nsec); + st->st_mtim.tv_sec = static_cast(s->_st_mtime); + st->st_mtim.tv_nsec = static_cast(s->st_mtime_nsec); + st->st_ctim.tv_sec = static_cast(s->_st_ctime); + st->st_ctim.tv_nsec = static_cast(s->st_ctime_nsec); +} + +int fstat(int fp, struct stat *st) +{ + kernel_stat s; + int ret; + ret = syscall (__NR_fstat, fp, &s); + copy_stat (st, &s); + return ret; +} +__strong_alias(fstat64, fstat); + +int newfstatat(int dirfd, const char *pathname, struct stat *buf, int flags) +{ + kernel_stat s; + int ret; + ret = syscall(__NR_newfstatat, dirfd, pathname, &s, flags); + copy_stat(buf, &s); + return ret; +} + +int fstatat(int dirfd, const char *pathname, struct stat *buf, int flags) +{ + kernel_stat s; + int ret; + ret = syscall(__NR_newfstatat, dirfd, pathname, &s, flags); + copy_stat(buf, &s); + return ret; +} +__strong_alias(fstatat64, fstatat); diff --git a/libc/arch-mips64/mips64.mk b/libc/arch-mips64/mips64.mk index 7990c6977..137639550 100644 --- a/libc/arch-mips64/mips64.mk +++ b/libc/arch-mips64/mips64.mk @@ -52,6 +52,7 @@ libc_bionic_src_files_mips64 += \ arch-mips64/bionic/setjmp.S \ arch-mips64/bionic/syscall.S \ arch-mips64/bionic/vfork.S \ + arch-mips64/bionic/stat.cpp \ libc_crt_target_cflags_mips64 := \ $($(my_2nd_arch_prefix)TARGET_GLOBAL_CFLAGS) \ diff --git a/libc/arch-mips64/syscalls/fstat64.S b/libc/arch-mips64/syscalls/fstat64.S deleted file mode 100644 index a14d51cb6..000000000 --- a/libc/arch-mips64/syscalls/fstat64.S +++ /dev/null @@ -1,28 +0,0 @@ -/* Generated by gensyscalls.py. Do not edit. */ - -#include - -ENTRY(fstat64) - .set push - .set noreorder - li v0, __NR_fstat - syscall - bnez a3, 1f - move a0, v0 - j ra - nop -1: - move t0, ra - bal 2f - nop -2: - .cpsetup ra, t1, 2b - LA t9,__set_errno_internal - .cpreturn - j t9 - move ra, t0 - .set pop -END(fstat64) - - .globl fstat - .equ fstat, fstat64 diff --git a/libc/arch-mips64/syscalls/fstatat64.S b/libc/arch-mips64/syscalls/fstatat64.S deleted file mode 100644 index 7888a432d..000000000 --- a/libc/arch-mips64/syscalls/fstatat64.S +++ /dev/null @@ -1,28 +0,0 @@ -/* Generated by gensyscalls.py. Do not edit. */ - -#include - -ENTRY(fstatat64) - .set push - .set noreorder - li v0, __NR_newfstatat - syscall - bnez a3, 1f - move a0, v0 - j ra - nop -1: - move t0, ra - bal 2f - nop -2: - .cpsetup ra, t1, 2b - LA t9,__set_errno_internal - .cpreturn - j t9 - move ra, t0 - .set pop -END(fstatat64) - - .globl fstatat - .equ fstatat, fstatat64 diff --git a/libc/include/sys/stat.h b/libc/include/sys/stat.h index 7017865bd..eb9bf2e84 100644 --- a/libc/include/sys/stat.h +++ b/libc/include/sys/stat.h @@ -36,7 +36,7 @@ __BEGIN_DECLS -#if defined(__aarch64__) +#if defined(__aarch64__) || (defined(__mips__) && defined(__LP64__)) #define __STAT64_BODY \ dev_t st_dev; \ ino_t st_ino; \ @@ -56,7 +56,7 @@ __BEGIN_DECLS unsigned int __unused4; \ unsigned int __unused5; \ -#elif defined(__mips__) /* and mips64 */ +#elif defined(__mips__) && !defined(__LP64__) #define __STAT64_BODY \ unsigned int st_dev; \ unsigned int __pad0[3]; \