[c5c522c] | 1 | From: Helge Deller <deller@gmx.de> |
---|
| 2 | Subject: [klibc] Add pread and pwrite 32bit syscall wrappers for parisc |
---|
| 3 | Date: Wed, 23 Apr 2014 22:52:53 +0200 |
---|
| 4 | Bug-Debian: https://bugs.debian.org/745660 |
---|
| 5 | Forwarded: http://www.zytor.com/pipermail/klibc/2016-January/003880.html |
---|
| 6 | |
---|
| 7 | On the hppa arch (32bit userspace and 32 or 64bit kernel), the fstype |
---|
| 8 | program fails to detect the filesystem. The reason for this failure |
---|
| 9 | is, that fstype calls the pread() syscall, which has on some |
---|
| 10 | architectures with 32bit userspace a different calling syntax. I |
---|
| 11 | noticed this bug on hppa, but I assume s390 (32bit) and others might |
---|
| 12 | run into similiar issues. |
---|
| 13 | |
---|
| 14 | Signed-off-by: Helge Deller <deller@gmx.de> |
---|
| 15 | --- |
---|
| 16 | --- a/usr/include/endian.h |
---|
| 17 | +++ b/usr/include/endian.h |
---|
| 18 | @@ -12,4 +12,10 @@ |
---|
| 19 | #define PDP_ENDIAN __PDP_ENDIAN |
---|
| 20 | #define BYTE_ORDER __BYTE_ORDER |
---|
| 21 | |
---|
| 22 | +#if __BYTE_ORDER == __LITTLE_ENDIAN |
---|
| 23 | +# define __LONG_LONG_PAIR(HI, LO) LO, HI |
---|
| 24 | +#elif __BYTE_ORDER == __BIG_ENDIAN |
---|
| 25 | +# define __LONG_LONG_PAIR(HI, LO) HI, LO |
---|
| 26 | +#endif |
---|
| 27 | + |
---|
| 28 | #endif /* _ENDIAN_H */ |
---|
| 29 | --- a/usr/klibc/Kbuild |
---|
| 30 | +++ b/usr/klibc/Kbuild |
---|
| 31 | @@ -35,6 +35,7 @@ klib-y += vsnprintf.o snprintf.o vsprint |
---|
| 32 | siglongjmp.o \ |
---|
| 33 | sigaction.o sigpending.o sigprocmask.o sigsuspend.o \ |
---|
| 34 | pselect.o ppoll.o \ |
---|
| 35 | + pread.o pwrite.o \ |
---|
| 36 | brk.o sbrk.o malloc.o realloc.o zalloc.o calloc.o \ |
---|
| 37 | mmap.o shm_open.o shm_unlink.o \ |
---|
| 38 | memcpy.o memcmp.o memset.o memccpy.o memmem.o memswap.o \ |
---|
| 39 | --- /dev/null |
---|
| 40 | +++ b/usr/klibc/pread.c |
---|
| 41 | @@ -0,0 +1,29 @@ |
---|
| 42 | +/* |
---|
| 43 | + * pread.c |
---|
| 44 | + * |
---|
| 45 | + * Some architectures need to wrap the system call |
---|
| 46 | + */ |
---|
| 47 | + |
---|
| 48 | +#include <endian.h> |
---|
| 49 | +#include <sys/syscall.h> |
---|
| 50 | + |
---|
| 51 | +#if defined(__hppa__) |
---|
| 52 | + |
---|
| 53 | +#if _BITSIZE == 32 |
---|
| 54 | +extern size_t __pread(int, void *, size_t, unsigned int, unsigned int); |
---|
| 55 | +#else |
---|
| 56 | +extern size_t __pread(int, void *, size_t, off_t); |
---|
| 57 | +#endif |
---|
| 58 | + |
---|
| 59 | +size_t pread(int fd, void *buf, size_t count, off_t offset) |
---|
| 60 | +{ |
---|
| 61 | +#if _BITSIZE == 32 |
---|
| 62 | + unsigned int hi = offset >> 32; |
---|
| 63 | + unsigned int lo = (unsigned int) offset; |
---|
| 64 | + return __pread(fd, buf, count, __LONG_LONG_PAIR(hi, lo)); |
---|
| 65 | +#else |
---|
| 66 | + return __pread(fd, buf, count, offset); |
---|
| 67 | +#endif |
---|
| 68 | +} |
---|
| 69 | + |
---|
| 70 | +#endif |
---|
| 71 | --- /dev/null |
---|
| 72 | +++ b/usr/klibc/pwrite.c |
---|
| 73 | @@ -0,0 +1,29 @@ |
---|
| 74 | +/* |
---|
| 75 | + * pwrite.c |
---|
| 76 | + * |
---|
| 77 | + * Some architectures need to wrap the system call |
---|
| 78 | + */ |
---|
| 79 | + |
---|
| 80 | +#include <endian.h> |
---|
| 81 | +#include <sys/syscall.h> |
---|
| 82 | + |
---|
| 83 | +#if defined(__hppa__) |
---|
| 84 | + |
---|
| 85 | +#if _BITSIZE == 32 |
---|
| 86 | +extern ssize_t __pwrite(int, const void *, size_t, unsigned int, unsigned int); |
---|
| 87 | +#else |
---|
| 88 | +extern ssize_t __pwrite(int, const void *, size_t, off_t); |
---|
| 89 | +#endif |
---|
| 90 | + |
---|
| 91 | +size_t pwrite(int fd, void *buf, size_t count, off_t offset) |
---|
| 92 | +{ |
---|
| 93 | +#if _BITSIZE == 32 |
---|
| 94 | + unsigned int hi = offset >> 32; |
---|
| 95 | + unsigned int lo = (unsigned int) offset; |
---|
| 96 | + return __pwrite(fd, buf, count, __LONG_LONG_PAIR(hi, lo)); |
---|
| 97 | +#else |
---|
| 98 | + return __pwrite(fd, buf, count, offset); |
---|
| 99 | +#endif |
---|
| 100 | +} |
---|
| 101 | + |
---|
| 102 | +#endif |
---|
| 103 | --- a/usr/klibc/SYSCALLS.def |
---|
| 104 | +++ b/usr/klibc/SYSCALLS.def |
---|
| 105 | @@ -189,8 +189,10 @@ int fdatasync,fsync::fdatasync(int); |
---|
| 106 | int readv(int, const struct iovec *, int); |
---|
| 107 | int writev(int, const struct iovec *, int); |
---|
| 108 | int ftruncate64,ftruncate::ftruncate(int, off_t); |
---|
| 109 | -ssize_t pread64,pread::pread(int, void *, size_t, off_t); |
---|
| 110 | -ssize_t pwrite64,pwrite::pwrite(int, void *, size_t, off_t); |
---|
| 111 | +<parisc> ssize_t pread64,pread::__pread(int, void *, size_t, off_t); |
---|
| 112 | +<parisc> ssize_t pwrite64,pwrite::__pwrite(int, void *, size_t, off_t); |
---|
| 113 | +<!parisc> ssize_t pread64,pread::pread(int, void *, size_t, off_t); |
---|
| 114 | +<!parisc> ssize_t pwrite64,pwrite::pwrite(int, void *, size_t, off_t); |
---|
| 115 | int sync_file_range,fdatasync,fsync::sync_file_range(int, off_t, off_t, unsigned int); |
---|
| 116 | <?> int splice(int, off_t *, int, off_t *, size_t, unsigned int); |
---|
| 117 | <?> int tee(int, int, size_t, unsigned int); |
---|