Add pread and pwrite 32bit syscall wrappers for parisc
authorHelge Deller <deller@gmx.de>
Wed, 23 Apr 2014 20:52:53 +0000 (22:52 +0200)
committerBen Hutchings <ben@decadent.org.uk>
Sun, 6 Jan 2019 19:33:01 +0000 (19:33 +0000)
On the hppa arch (32bit userspace and 32 or 64bit kernel), the fstype
program fails to detect the filesystem.  The reason for this failure
is, that fstype calls the pread() syscall, which has on some
architectures with 32bit userspace a different calling syntax.  I
noticed this bug on hppa, but I assume s390 (32bit) and others might
run into similiar issues.

Signed-off-by: Helge Deller <deller@gmx.de>
Gbp-Pq: Name klibc-add-pread-and-pwrite-32bit-syscall-wrappers-for-parisc.patch

usr/include/endian.h
usr/klibc/Kbuild
usr/klibc/SYSCALLS.def
usr/klibc/pread.c [new file with mode: 0644]
usr/klibc/pwrite.c [new file with mode: 0644]

index a6cd6d9bcde47801ea527c97c550dd51691b1770..61cda3a5315127a24038acce4f2c3d762799bd14 100644 (file)
 #define PDP_ENDIAN     __PDP_ENDIAN
 #define BYTE_ORDER     __BYTE_ORDER
 
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+# define __LONG_LONG_PAIR(HI, LO) LO, HI
+#elif __BYTE_ORDER == __BIG_ENDIAN
+# define __LONG_LONG_PAIR(HI, LO) HI, LO
+#endif
+
 #endif                         /* _ENDIAN_H */
index 40d43c7889e55c8fdd3251be30f3f667de494c41..d3e2b9fbc99b15d4426dc88c51d8367f7bad2d68 100644 (file)
@@ -35,6 +35,7 @@ klib-y += vsnprintf.o snprintf.o vsprintf.o sprintf.o \
          siglongjmp.o \
          sigaction.o sigpending.o sigprocmask.o sigsuspend.o \
          pselect.o ppoll.o \
+         pread.o pwrite.o \
          brk.o sbrk.o malloc.o realloc.o zalloc.o calloc.o \
          mmap.o shm_open.o shm_unlink.o \
          memcpy.o memcmp.o memset.o memccpy.o memmem.o memswap.o \
index 41cfa171b0e416363831a2d86e0086064c6fd712..c56e8f997838143c4ab226d13801ba117a5e3b65 100644 (file)
@@ -189,8 +189,10 @@ int fdatasync,fsync::fdatasync(int);
 int readv(int, const struct iovec *, int);
 int writev(int, const struct iovec *, int);
 int ftruncate64,ftruncate::ftruncate(int, off_t);
-ssize_t pread64,pread::pread(int, void *, size_t, off_t);
-ssize_t pwrite64,pwrite::pwrite(int, void *, size_t, off_t);
+<parisc> ssize_t pread64,pread::__pread(int, void *, size_t, off_t);
+<parisc> ssize_t pwrite64,pwrite::__pwrite(int, void *, size_t, off_t);
+<!parisc> ssize_t pread64,pread::pread(int, void *, size_t, off_t);
+<!parisc> ssize_t pwrite64,pwrite::pwrite(int, void *, size_t, off_t);
 int sync_file_range,fdatasync,fsync::sync_file_range(int, off_t, off_t, unsigned int);
 <?> int splice(int, off_t *, int, off_t *, size_t, unsigned int);
 <?> int tee(int, int, size_t, unsigned int);
diff --git a/usr/klibc/pread.c b/usr/klibc/pread.c
new file mode 100644 (file)
index 0000000..0d8c3b1
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * pread.c
+ *
+ * Some architectures need to wrap the system call
+ */
+
+#include <endian.h>
+#include <sys/syscall.h>
+
+#if defined(__hppa__)
+
+#if _BITSIZE == 32
+extern size_t __pread(int, void *, size_t, unsigned int, unsigned int);
+#else
+extern size_t __pread(int, void *, size_t, off_t);
+#endif
+
+size_t pread(int fd, void *buf, size_t count, off_t offset)
+{
+#if _BITSIZE == 32
+       unsigned int hi = offset >> 32;
+       unsigned int lo = (unsigned int) offset;
+       return __pread(fd, buf, count, __LONG_LONG_PAIR(hi, lo));
+#else
+       return __pread(fd, buf, count, offset);
+#endif
+}
+
+#endif
diff --git a/usr/klibc/pwrite.c b/usr/klibc/pwrite.c
new file mode 100644 (file)
index 0000000..691d0e4
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * pwrite.c
+ *
+ * Some architectures need to wrap the system call
+ */
+
+#include <endian.h>
+#include <sys/syscall.h>
+
+#if defined(__hppa__)
+
+#if _BITSIZE == 32
+extern ssize_t __pwrite(int, const void *, size_t, unsigned int, unsigned int);
+#else
+extern ssize_t __pwrite(int, const void *, size_t, off_t);
+#endif
+
+size_t pwrite(int fd, void *buf, size_t count, off_t offset)
+{
+#if _BITSIZE == 32
+       unsigned int hi = offset >> 32;
+       unsigned int lo = (unsigned int) offset;
+       return __pwrite(fd, buf, count, __LONG_LONG_PAIR(hi, lo));
+#else
+       return __pwrite(fd, buf, count, offset);
+#endif
+}
+
+#endif