Gentoo Archives: gentoo-commits

From: "Anthony G. Basile (blueness)" <blueness@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo commit in src/patchsets/uclibc/0.9.33.2: 24_all_pread64_pwrite64.patch
Date: Fri, 29 May 2015 19:33:56
Message-Id: 20150529193347.45DFEA09@oystercatcher.gentoo.org
1 blueness 15/05/29 19:33:47
2
3 Added: 24_all_pread64_pwrite64.patch
4 Log:
5 Fix pread64() and pwrite64() when __WORDSIZE != 32. Bug #548950.
6
7 Revision Changes Path
8 1.1 src/patchsets/uclibc/0.9.33.2/24_all_pread64_pwrite64.patch
9
10 file : http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/uclibc/0.9.33.2/24_all_pread64_pwrite64.patch?rev=1.1&view=markup
11 plain: http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/uclibc/0.9.33.2/24_all_pread64_pwrite64.patch?rev=1.1&content-type=text/plain
12
13 Index: 24_all_pread64_pwrite64.patch
14 ===================================================================
15 From 0aaf783f8d0c2748aee458ecd5b846be595c3068 Mon Sep 17 00:00:00 2001
16 From: "Anthony G. Basile" <blueness@g.o>
17 Date: Sat, 9 May 2015 12:43:05 -0400
18 Subject: [PATCH] common/pread_write.c: backport fix for 64-bit handling of
19 pread/pwrite
20
21 Commit 458076d fixed the pread/pwrite syscalls for 64-bit ports on the
22 master branch, but the fix was not backported to the 0.9.33 branch. This
23 patch backports the fix which is critical for e2fsprogs-1.42.12 and above.
24 The introduction of pread64()/pwrite64() in e2fsprogs' commit f00948a
25 broke fsck.ext3 and fsck.ext4 on uclibc-0.9.33, leading to potential
26 data corrupton. See
27
28 https://bugs.gentoo.org/show_bug.cgi?id=548950
29
30 http://git.kernel.org/cgit/fs/ext2/e2fsprogs.git/commit/?id=f00948ad1df100c7d616ef6fbf7609329a2e4001
31
32 Signed-off-by: Anthony G. Basile <blueness@g.o>
33 Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@×××××.com>
34 ---
35 libc/sysdeps/linux/common/pread_write.c | 120 +++++++++++++++++++-------------
36 1 file changed, 71 insertions(+), 49 deletions(-)
37
38 diff --git a/libc/sysdeps/linux/common/pread_write.c b/libc/sysdeps/linux/common/pread_write.c
39 index 924509e..51d76a1 100644
40 --- a/libc/sysdeps/linux/common/pread_write.c
41 +++ b/libc/sysdeps/linux/common/pread_write.c
42 @@ -28,87 +28,109 @@
43 #define LIBC_CANCEL_HANDLED() /* Nothing. */
44 #endif
45
46 -extern __typeof(pread) __libc_pread;
47 -extern __typeof(pwrite) __libc_pwrite;
48 -#ifdef __UCLIBC_HAS_LFS__
49 -extern __typeof(pread64) __libc_pread64;
50 -extern __typeof(pwrite64) __libc_pwrite64;
51 -#endif
52 -
53 -#ifdef __NR_pread64 /* Newer kernels renamed but it's the same. */
54 +#ifdef __NR_pread64
55 # undef __NR_pread
56 # define __NR_pread __NR_pread64
57 #endif
58 +#ifdef __NR_pwrite64
59 +# undef __NR_pwrite
60 +# define __NR_pwrite __NR_pwrite64
61 +#endif
62
63 -#include <bits/kernel_types.h>
64 -
65 -# define __NR___syscall_pread __NR_pread
66 +#ifndef MY_PREAD
67 +# ifdef __NR_pread
68 +# define __NR___syscall_pread __NR_pread
69 +# if defined(__UCLIBC_SYSCALL_ALIGN_64BIT__)
70 +static _syscall6(ssize_t, __syscall_pread, int, fd, void *, buf,
71 + size_t, count, int, dummy, off_t, offset_hi, off_t, offset_lo)
72 +# define MY_PREAD(fd, buf, count, offset) __syscall_pread(fd, buf, count, 0, OFF_HI_LO(offset))
73 +# define MY_PREAD64(fd, buf, count, offset) __syscall_pread(fd, buf, count, 0, OFF64_HI_LO(offset))
74 +# elif __WORDSIZE == 32
75 +static _syscall5(ssize_t, __syscall_pread, int, fd, void *, buf,
76 + size_t, count, off_t, offset_hi, off_t, offset_lo)
77 +# define MY_PREAD(fd, buf, count, offset) __syscall_pread(fd, buf, count, OFF_HI_LO(offset))
78 +# define MY_PREAD64(fd, buf, count, offset) __syscall_pread(fd, buf, count, OFF64_HI_LO(offset))
79 +# else
80 +static _syscall4(ssize_t, __syscall_pread, int, fd, void *, buf,
81 + size_t, count, off_t, offset)
82 +# define MY_PREAD(fd, buf, count, offset) __syscall_pread(fd, buf, count, offset)
83 +# define MY_PREAD64(fd, buf, count, offset) __syscall_pread(fd, buf, count, offset)
84 +# endif
85 +# endif
86 +#endif
87
88 -#if defined(__UCLIBC_SYSCALL_ALIGN_64BIT__)
89 -static __inline__ _syscall6(ssize_t, __syscall_pread, int, fd, void *, buf,
90 - size_t, count, int, dummy, off_t, offset_hi, off_t, offset_lo)
91 -# define __syscall_pread(fd, buf, count, ...) __syscall_pread(fd, buf, count, 0, __VA_ARGS__)
92 -#else
93 -static __inline__ _syscall5(ssize_t, __syscall_pread, int, fd, void *, buf,
94 - size_t, count, off_t, offset_hi, off_t, offset_lo)
95 +#ifndef MY_PWRITE
96 +# ifdef __NR_pwrite
97 +# define __NR___syscall_pwrite __NR_pwrite
98 +# if defined(__UCLIBC_SYSCALL_ALIGN_64BIT__)
99 +static _syscall6(ssize_t, __syscall_pwrite, int, fd, const void *, buf,
100 + size_t, count, int, dummy, off_t, offset_hi, off_t, offset_lo)
101 +# define MY_PWRITE(fd, buf, count, offset) __syscall_pwrite(fd, buf, count, 0, OFF_HI_LO(offset))
102 +# define MY_PWRITE64(fd, buf, count, offset) __syscall_pwrite(fd, buf, count, 0, OFF64_HI_LO(offset))
103 +# elif __WORDSIZE == 32
104 +static _syscall5(ssize_t, __syscall_pwrite, int, fd, const void *, buf,
105 + size_t, count, off_t, offset_hi, off_t, offset_lo)
106 +# define MY_PWRITE(fd, buf, count, offset) __syscall_pwrite(fd, buf, count, OFF_HI_LO(offset))
107 +# define MY_PWRITE64(fd, buf, count, offset) __syscall_pwrite(fd, buf, count, OFF64_HI_LO(offset))
108 +# else
109 +static _syscall4(ssize_t, __syscall_pwrite, int, fd, const void *, buf,
110 + size_t, count, off_t, offset)
111 +# define MY_PWRITE(fd, buf, count, offset) __syscall_pwrite(fd, buf, count, offset)
112 +# define MY_PWRITE64(fd, buf, count, offset) __syscall_pwrite(fd, buf, count, offset)
113 +# endif
114 +# endif
115 #endif
116
117 ssize_t __libc_pread(int fd, void *buf, size_t count, off_t offset)
118 {
119 int oldtype = LIBC_CANCEL_ASYNC ();
120 - int result = __syscall_pread(fd, buf, count, __LONG_LONG_PAIR(offset >> 31, offset));
121 + int result = MY_PREAD(fd, buf, count, offset);
122 LIBC_CANCEL_RESET (oldtype);
123 return result;
124
125 }
126 weak_alias(__libc_pread,pread)
127
128 -# ifdef __UCLIBC_HAS_LFS__
129 -ssize_t __libc_pread64(int fd, void *buf, size_t count, off64_t offset)
130 +ssize_t __libc_pwrite(int fd, const void *buf, size_t count, off_t offset)
131 {
132 - uint32_t low = offset & 0xffffffff;
133 - uint32_t high = offset >> 32;
134 int oldtype = LIBC_CANCEL_ASYNC ();
135 - int result = __syscall_pread(fd, buf, count, __LONG_LONG_PAIR(high, low));
136 + int result = MY_PWRITE(fd, buf, count, offset);
137 LIBC_CANCEL_RESET (oldtype);
138 return result;
139 }
140 -weak_alias(__libc_pread64,pread64)
141 -# endif /* __UCLIBC_HAS_LFS__ */
142 -
143 -#ifdef __NR_pwrite64 /* Newer kernels renamed but it's the same. */
144 -# undef __NR_pwrite
145 -# define __NR_pwrite __NR_pwrite64
146 -#endif
147 -
148 -# define __NR___syscall_pwrite __NR_pwrite
149 -#if defined(__UCLIBC_SYSCALL_ALIGN_64BIT__)
150 -static __inline__ _syscall6(ssize_t, __syscall_pwrite, int, fd, const void *, buf,
151 - size_t, count, int, dummy, off_t, offset_hi, off_t, offset_lo)
152 -# define __syscall_pwrite(fd, buf, count, ...) __syscall_pwrite(fd, buf, count, 0, __VA_ARGS__)
153 -#else
154 -static __inline__ _syscall5(ssize_t, __syscall_pwrite, int, fd, const void *, buf,
155 - size_t, count, off_t, offset_hi, off_t, offset_lo)
156 -#endif
157 +weak_alias(__libc_pwrite,pwrite)
158
159 -ssize_t __libc_pwrite(int fd, const void *buf, size_t count, off_t offset)
160 +#ifdef __UCLIBC_HAS_LFS__
161 +# if __WORDSIZE == 32
162 +ssize_t __libc_pread64(int fd, void *buf, size_t count, off64_t offset)
163 {
164 int oldtype = LIBC_CANCEL_ASYNC ();
165 - int result = __syscall_pwrite(fd, buf, count, __LONG_LONG_PAIR(offset >> 31, offset));
166 + int result = MY_PREAD64(fd, buf, count, offset);
167 LIBC_CANCEL_RESET (oldtype);
168 return result;
169 }
170 -weak_alias(__libc_pwrite,pwrite)
171 +weak_alias(__libc_pread64,pread64)
172
173 -# ifdef __UCLIBC_HAS_LFS__
174 ssize_t __libc_pwrite64(int fd, const void *buf, size_t count, off64_t offset)
175 {
176 - uint32_t low = offset & 0xffffffff;
177 - uint32_t high = offset >> 32;
178 int oldtype = LIBC_CANCEL_ASYNC ();
179 - int result = __syscall_pwrite(fd, buf, count, __LONG_LONG_PAIR(high, low));
180 + int result = MY_PWRITE64(fd, buf, count, offset);
181 LIBC_CANCEL_RESET (oldtype);
182 return result;
183 }
184 weak_alias(__libc_pwrite64,pwrite64)
185 -# endif /* __UCLIBC_HAS_LFS__ */
186 +
187 +# else
188 +# ifdef __LINUXTHREADS_OLD__
189 +weak_alias(pread,pread64)
190 +weak_alias(pwrite,pwrite64)
191 +extern __typeof(pread64) __libc_pread64;
192 +extern __typeof(pwrite64) __libc_pwrite4;
193 +strong_alias(pread64,__libc_pread64)
194 +strong_alias(pwrite64,__libc_write64)
195 +# else
196 +strong_alias_untyped(pread,pread64)
197 +strong_alias_untyped(pwrite,pwrite64)
198 +# endif
199 +# endif
200 +#endif
201 --
202 2.3.6