[PATCH] Fix mips readahead, posix_fadvise, posix_fadvise64
Atsushi Nemoto
anemo at mba.ocn.ne.jp
Fri May 25 08:33:29 PDT 2007
Current MIPS readahead(), posix_fadvise(), posix_fadvise64() do not
match with kernel on all ABIs.
On O32 ABI, a padding is needed before a long long argument.
On N32/N64, a long long argument should be passed via a single register.
libc/sysdeps/linux/mips/Makefile.arch | 3 +
libc/sysdeps/linux/mips/posix_fadvise.c | 39 +++++++++++++++++++++++++
libc/sysdeps/linux/mips/posix_fadvise64.c | 43 ++++++++++++++++++++++++++++
libc/sysdeps/linux/mips/readahead.c | 38 ++++++++++++++++++++++++
4 files changed, 122 insertions(+), 1 deletion(-)
-------------- next part --------------
diff -urNp -x '*~' uClibc-0.9.29.org/libc/sysdeps/linux/mips/Makefile.arch uClibc-0.9.29/libc/sysdeps/linux/mips/Makefile.arch
--- uClibc-0.9.29.org/libc/sysdeps/linux/mips/Makefile.arch 2005-11-19 15:59:23.000000000 +0900
+++ uClibc-0.9.29/libc/sysdeps/linux/mips/Makefile.arch 2007-05-25 11:02:12.000000000 +0900
@@ -7,7 +7,8 @@
CSRC := \
__longjmp.c brk.c setjmp_aux.c mmap.c __syscall_error.c \
- cacheflush.c pread_write.c sysmips.c _test_and_set.c sigaction.c
+ cacheflush.c pread_write.c sysmips.c _test_and_set.c sigaction.c \
+ readahead.c posix_fadvise.c posix_fadvise64.c
SSRC := bsd-_setjmp.S bsd-setjmp.S setjmp.S clone.S syscall.S pipe.S
diff -urNp -x '*~' uClibc-0.9.29.org/libc/sysdeps/linux/mips/posix_fadvise.c uClibc-0.9.29/libc/sysdeps/linux/mips/posix_fadvise.c
--- uClibc-0.9.29.org/libc/sysdeps/linux/mips/posix_fadvise.c 1970-01-01 09:00:00.000000000 +0900
+++ uClibc-0.9.29/libc/sysdeps/linux/mips/posix_fadvise.c 2007-05-25 11:49:08.000000000 +0900
@@ -0,0 +1,39 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * posix_fadvise() for MIPS uClibc
+ * http://www.opengroup.org/onlinepubs/009695399/functions/posix_fadvise.html
+ *
+ * Copyright (C) 2000-2006 Erik Andersen <andersen at uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include <features.h>
+#include <unistd.h>
+#include <errno.h>
+#include <endian.h>
+#include <stdint.h>
+#include <sys/types.h>
+#include <sys/syscall.h>
+#include <fcntl.h>
+
+int posix_fadvise(int fd, off_t offset, off_t len, int advice)
+{
+/* MIPS kernel only has NR_fadvise64 which acts as NR_fadvise64_64 */
+#ifdef __NR_fadvise64
+ INTERNAL_SYSCALL_DECL(err);
+# if _MIPS_SIM == _ABIO32
+ int ret = INTERNAL_SYSCALL(fadvise64, err, 7, fd, 0,
+ __LONG_LONG_PAIR ((long) (offset >> 31), (long) offset),
+ __LONG_LONG_PAIR ((long) (len >> 31), (long) len),
+ advice);
+# else /* N32 || N64 */
+ int ret = INTERNAL_SYSCALL(fadvise64, err, 4, fd, offset, len, advice);
+# endif
+ if (INTERNAL_SYSCALL_ERROR_P (ret, err))
+ return INTERNAL_SYSCALL_ERRNO (ret, err);
+ return 0;
+#else
+ return ENOSYS;
+#endif
+}
diff -urNp -x '*~' uClibc-0.9.29.org/libc/sysdeps/linux/mips/posix_fadvise64.c uClibc-0.9.29/libc/sysdeps/linux/mips/posix_fadvise64.c
--- uClibc-0.9.29.org/libc/sysdeps/linux/mips/posix_fadvise64.c 1970-01-01 09:00:00.000000000 +0900
+++ uClibc-0.9.29/libc/sysdeps/linux/mips/posix_fadvise64.c 2007-05-25 11:42:10.000000000 +0900
@@ -0,0 +1,43 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * posix_fadvise64() for MIPS uClibc
+ * http://www.opengroup.org/onlinepubs/009695399/functions/posix_fadvise.html
+ *
+ * Copyright (C) 2000-2006 Erik Andersen <andersen at uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include <features.h>
+#include <unistd.h>
+#include <errno.h>
+#include <endian.h>
+#include <stdint.h>
+#include <sys/types.h>
+#include <sys/syscall.h>
+#include <fcntl.h>
+
+#ifdef __UCLIBC_HAS_LFS__
+
+int posix_fadvise64(int fd, __off64_t offset, __off64_t len, int advice)
+{
+/* MIPS kernel only has NR_fadvise64 which acts as NR_fadvise64_64 */
+#ifdef __NR_fadvise64
+ INTERNAL_SYSCALL_DECL(err);
+# if _MIPS_SIM == _MIPS_SIM_ABI32
+ int ret = INTERNAL_SYSCALL(fadvise64, err, 7, fd, 0,
+ __LONG_LONG_PAIR ((long) (offset >> 32), (long) offset),
+ __LONG_LONG_PAIR ((long) (len >> 32), (long) len),
+ advice);
+# else /* N32 || N64 */
+ int ret = INTERNAL_SYSCALL(fadvise64, err, 4, fd, offset, len, advice);
+# endif
+ if (INTERNAL_SYSCALL_ERROR_P (ret, err))
+ return INTERNAL_SYSCALL_ERRNO (ret, err);
+ return 0;
+#else
+ return ENOSYS;
+#endif
+}
+
+#endif /* __UCLIBC_HAS_LFS__ */
diff -urNp -x '*~' uClibc-0.9.29.org/libc/sysdeps/linux/mips/readahead.c uClibc-0.9.29/libc/sysdeps/linux/mips/readahead.c
--- uClibc-0.9.29.org/libc/sysdeps/linux/mips/readahead.c 1970-01-01 09:00:00.000000000 +0900
+++ uClibc-0.9.29/libc/sysdeps/linux/mips/readahead.c 2007-05-25 11:44:47.000000000 +0900
@@ -0,0 +1,38 @@
+/* Provide kernel hint to read ahead.
+ Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/syscall.h>
+
+#ifdef __NR_readahead
+
+ssize_t readahead(int fd, off64_t offset, size_t count)
+{
+# if _MIPS_SIM == _ABIO32
+ return INLINE_SYSCALL (readahead, 5, fd, 0,
+ __LONG_LONG_PAIR ((off_t) (offset >> 32), (off_t) offset),
+ count);
+# else /* N32 || N64 */
+ return INLINE_SYSCALL (readahead, 3, fd, offset, count);
+# endif
+}
+
+#endif
More information about the uClibc
mailing list