Codebase list libuv1 / 08d6ad9
Simplify iovec_rw patch Luca Bruno 8 years ago
1 changed file(s) with 10 addition(s) and 86 deletion(s). Raw diff Collapse all Expand all
0 From a3935e79cd42143cc843044dd1bbba0072ed2bc3 Mon Sep 17 00:00:00 2001
1 From: Ben Wijen <ben@wijen.net>
2 Date: Wed, 19 Aug 2015 21:04:15 +0200
3 Subject: [PATCH] Use __ASSUME_PREADV/__ASSUME_PWRITEV Fix syscalls with 64 bit
4 offsets on 32 bit targets.
5
6 Fixes: #473
7
8 Signed-off-by: Ben Wijen <ben@wijen.net>
9 ---
10 src/unix/fs.c | 13 ++++++-------
11 src/unix/linux-syscalls.c | 17 +++++++++++++++++
12 2 files changed, 23 insertions(+), 7 deletions(-)
13
14 --- a/src/unix/fs.c
15 +++ b/src/unix/fs.c
16 @@ -49,9 +49,8 @@
17 defined(__FreeBSD__) || \
18 defined(__OpenBSD__) || \
19 defined(__NetBSD__)
20 -# define HAVE_PREADV 1
21 -#else
22 -# define HAVE_PREADV 0
23 +# define __ASSUME_PWRITEV
24 +# define __ASSUME_PREADV
25 #endif
26
27 #if defined(__linux__) || defined(__sun)
28 @@ -252,7 +251,7 @@
29
30
31 static ssize_t uv__fs_read(uv_fs_t* req) {
32 -#if defined(__linux__)
33 +#if defined(__linux__) && !defined(__ASSUME_PREADV)
34 static int no_preadv;
35 #endif
36 ssize_t result;
37 @@ -277,7 +276,7 @@
38 goto done;
39 }
40
41 -#if HAVE_PREADV
42 +#if __ASSUME_PREADV
43 result = preadv(req->file, (struct iovec*) req->bufs, req->nbufs, req->off);
44 #else
45 # if defined(__linux__)
46 @@ -615,7 +614,7 @@
47
48
49 static ssize_t uv__fs_write(uv_fs_t* req) {
50 -#if defined(__linux__)
51 +#if defined(__linux__) && !defined(__ASSUME_PWRITEV)
52 static int no_pwritev;
53 #endif
54 ssize_t r;
55 @@ -639,7 +638,7 @@
56 r = pwrite(req->file, req->bufs[0].base, req->bufs[0].len, req->off);
57 goto done;
58 }
59 -#if HAVE_PREADV
60 +#if __ASSUME_PWRITEV
61 r = pwritev(req->file, (struct iovec*) req->bufs, req->nbufs, req->off);
62 #else
63 # if defined(__linux__)
0 Description: iovec preadv/pwrite syscall fix
1 Author: Luca Bruno <lucab@debian.org.org>
2 Last-Update: 2015-09-22
3 Forwarded: not yet
644 --- a/src/unix/linux-syscalls.c
655 +++ b/src/unix/linux-syscalls.c
66 @@ -26,6 +26,7 @@
67 #include <sys/syscall.h>
68 #include <sys/types.h>
69 #include <errno.h>
70 +#include <endian.h>
71
72 #if defined(__has_feature)
73 # if __has_feature(memory_sanitizer)
74 @@ -439,7 +440,15 @@
6 @@ -439,7 +439,11 @@
757
768 ssize_t uv__preadv(int fd, const struct iovec *iov, int iovcnt, off_t offset) {
779 #if defined(__NR_preadv)
78 +# if _FILE_OFFSET_BITS == 64 && __WORDSIZE == 32
79 +# if __BYTE_ORDER == __BIG_ENDIAN
80 + return syscall(__NR_preadv, fd, iov, iovcnt, offset>>32, offset);
81 +# else
82 + return syscall(__NR_preadv, fd, iov, iovcnt, offset, offset>>32);
83 +# endif
10 +# if defined(_BSD_SOURCE) && (defined(__hppa__) || defined(__mips__) || defined(__powerpc__))
11 + return preadv(fd, iov, iovcnt, offset);
8412 +# else
8513 return syscall(__NR_preadv, fd, iov, iovcnt, offset);
8614 +# endif
8715 #else
8816 return errno = ENOSYS, -1;
8917 #endif
90 @@ -448,7 +457,15 @@
18 @@ -448,7 +452,11 @@
9119
9220 ssize_t uv__pwritev(int fd, const struct iovec *iov, int iovcnt, off_t offset) {
9321 #if defined(__NR_pwritev)
94 +# if _FILE_OFFSET_BITS == 64 && __WORDSIZE == 32
95 +# if __BYTE_ORDER == __BIG_ENDIAN
96 + return syscall(__NR_pwritev, fd, iov, iovcnt, offset>>32, offset);
97 +# else
98 + return syscall(__NR_pwritev, fd, iov, iovcnt, offset, offset>>32);
99 +# endif
22 +# if defined(_BSD_SOURCE) && (defined(__hppa__) || defined(__mips__) || defined(__powerpc__))
23 + return pwritev(fd, iov, iovcnt, offset);
10024 +# else
10125 return syscall(__NR_pwritev, fd, iov, iovcnt, offset);
10226 +# endif