[PATCH 0.9.33 5/7] add cancellation to generic pread_write

Natanael Copa natanael.copa at gmail.com
Wed Aug 29 09:19:02 UTC 2012


From: "Peter S. Mazinger" <ps.m at gmx.net>

Prepare the file to be used in all arch specific files

Signed-off-by: Peter S. Mazinger <ps.m at gmx.net>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop at gmail.com>
(cherry picked from commit 61198b43ee8a639544622d0e666b972418c9c383)
---
 libc/sysdeps/linux/common/pread_write.c | 100 ++++++++++++++++----------------
 1 file changed, 51 insertions(+), 49 deletions(-)

diff --git a/libc/sysdeps/linux/common/pread_write.c b/libc/sysdeps/linux/common/pread_write.c
index 48fe7dd..3d04bb7 100644
--- a/libc/sysdeps/linux/common/pread_write.c
+++ b/libc/sysdeps/linux/common/pread_write.c
@@ -15,71 +15,73 @@
 
 #include <sys/syscall.h>
 #include <unistd.h>
-#include <stdint.h>
 #include <endian.h>
+#include <bits/wordsize.h>
+#include <cancel.h>
 
-extern __typeof(pread) __libc_pread;
-extern __typeof(pwrite) __libc_pwrite;
-#ifdef __UCLIBC_HAS_LFS__
-extern __typeof(pread64) __libc_pread64;
-extern __typeof(pwrite64) __libc_pwrite64;
-#endif
-
-#ifdef __NR_pread64             /* Newer kernels renamed but it's the same.  */
+#ifdef __NR_pread64
 # undef __NR_pread
 # define __NR_pread __NR_pread64
 #endif
+#ifdef __NR_pwrite64
+# undef __NR_pwrite
+# define __NR_pwrite __NR_pwrite64
+#endif
 
-#include <bits/kernel_types.h>
-
-#ifdef __NR_pread
+#ifndef MY_PREAD
+# ifdef __NR_pread
+#  define __NR___syscall_pread __NR_pread
+static _syscall5(ssize_t, __syscall_pread, int, fd, void *, buf,
+		 size_t, count, off_t, offset_hi, off_t, offset_lo)
+#  define MY_PREAD(fd, buf, count, offset) __syscall_pread(fd, buf, count, OFF_HI_LO(offset))
+#  define MY_PREAD64(fd, buf, count, offset) __syscall_pread(fd, buf, count, OFF64_HI_LO(offset))
+#endif
 
-# define __NR___syscall_pread __NR_pread
-static __inline__ _syscall5(ssize_t, __syscall_pread, int, fd, void *, buf,
-		size_t, count, off_t, offset_hi, off_t, offset_lo)
+#ifndef MY_PWRITE
+# ifdef __NR_pwrite
+#  define __NR___syscall_pwrite __NR_pwrite
+static _syscall5(ssize_t, __syscall_pwrite, int, fd, const void *, buf,
+		 size_t, count, off_t, offset_hi, off_t, offset_lo)
+#  define MY_PWRITE(fd, buf, count, offset) __syscall_pwrite(fd, buf, count, OFF_HI_LO(offset))
+#  define MY_PWRITE64(fd, buf, count, offset) __syscall_pwrite(fd, buf, count, OFF64_HI_LO(offset))
+#endif
 
-ssize_t __libc_pread(int fd, void *buf, size_t count, off_t offset)
+static ssize_t __NC(pread)(int fd, void *buf, size_t count, off_t offset)
 {
-	return __syscall_pread(fd, buf, count, __LONG_LONG_PAIR(offset >> 31, offset));
+	return MY_PREAD(fd, buf, count, offset);
 }
-weak_alias(__libc_pread,pread)
+CANCELLABLE_SYSCALL(ssize_t, pread, (int fd, void *buf, size_t count, off_t offset),
+		    (fd, buf, count, offset))
 
-# ifdef __UCLIBC_HAS_LFS__
-ssize_t __libc_pread64(int fd, void *buf, size_t count, off64_t offset)
+static ssize_t __NC(pwrite)(int fd, const void *buf, size_t count, off_t offset)
 {
-	uint32_t low = offset & 0xffffffff;
-	uint32_t high = offset >> 32;
-	return __syscall_pread(fd, buf, count, __LONG_LONG_PAIR(high, low));
+	return MY_PWRITE(fd, buf, count, offset);
 }
-weak_alias(__libc_pread64,pread64)
-# endif /* __UCLIBC_HAS_LFS__  */
+CANCELLABLE_SYSCALL(ssize_t, pwrite, (int fd, const void *buf, size_t count, off_t offset),
+		    (fd, buf, count, offset))
 
-#endif /* __NR_pread */
-
-#ifdef __NR_pwrite64             /* Newer kernels renamed but it's the same.  */
-# undef __NR_pwrite
-# define __NR_pwrite __NR_pwrite64
-#endif
-
-#ifdef __NR_pwrite
-
-# define __NR___syscall_pwrite __NR_pwrite
-static __inline__ _syscall5(ssize_t, __syscall_pwrite, int, fd, const void *, buf,
-		size_t, count, off_t, offset_hi, off_t, offset_lo)
-
-ssize_t __libc_pwrite(int fd, const void *buf, size_t count, off_t offset)
+#ifdef __UCLIBC_HAS_LFS__
+# if __WORDSIZE == 32
+static ssize_t __NC(pread64)(int fd, void *buf, size_t count, off64_t offset)
 {
-	return __syscall_pwrite(fd, buf, count, __LONG_LONG_PAIR(offset >> 31, offset));
+	return MY_PREAD64(fd, buf, count, offset);
 }
-weak_alias(__libc_pwrite,pwrite)
+CANCELLABLE_SYSCALL(ssize_t, pread64, (int fd, void *buf, size_t count, off64_t offset),
+		    (fd, buf, count, offset))
 
-# ifdef __UCLIBC_HAS_LFS__
-ssize_t __libc_pwrite64(int fd, const void *buf, size_t count, off64_t offset)
+static ssize_t __NC(pwrite64)(int fd, const void *buf, size_t count, off64_t offset)
 {
-	uint32_t low = offset & 0xffffffff;
-	uint32_t high = offset >> 32;
-	return __syscall_pwrite(fd, buf, count, __LONG_LONG_PAIR(high, low));
+	return MY_PWRITE64(fd, buf, count, offset);
 }
-weak_alias(__libc_pwrite64,pwrite64)
-# endif /* __UCLIBC_HAS_LFS__  */
-#endif /* __NR_pwrite */
+CANCELLABLE_SYSCALL(ssize_t, pwrite64, (int fd, const void *buf, size_t count, off64_t offset),
+		    (fd, buf, count, offset))
+# else
+#  ifdef __LINUXTHREADS_OLD__
+weak_alias(pread,pread64)
+weak_alias(pwrite,pwrite64)
+#  else
+strong_alias_untyped(pread,pread64)
+strong_alias_untyped(pwrite,pwrite64)
+#  endif
+# endif
+#endif
-- 
1.7.12



More information about the uClibc mailing list