This is the mail archive of the mailing list for the glibc project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] fallocate: pass off_t in register pair correctly for 64-bit off_t

sysdeps/unix/sysv/linux/fallocate.c contains wide-spreaded hack for creating
register pair from 32-bit signed value:
	LONG_LONG_PAIR (val >> 31, val)

It works well for off_t if it is 32-bit lenght. Modern ABIs requres 64-bit off_t,
so this hack doesn't work for them. In this patch, fallocate handler is taken from
fallocate64.c, depending on __OFF_T_MATCHES_OFF64_T.

The other option to fix it is to introduce macro that creates the pair correctly
for both 32- and 64-bit off_t, like this:

#ifndef	__OFF_T_MATCHES_OFF64_T
#define CREATE_OFF_PAIR(val)	((val) < 0 ? (-1) : 0 , (val))
#define CREATE_OFF_PAIR(val)	((val) >> 32, (val))

If 2nd option is looking more appropriated, I can prepare the patch for all
affected syscalls.

Signed-off-by: Yury Norov <>
 sysdeps/unix/sysv/linux/fallocate.c   | 3 +++
 sysdeps/unix/sysv/linux/fallocate64.c | 4 ++++
 2 files changed, 7 insertions(+)

diff --git a/sysdeps/unix/sysv/linux/fallocate.c b/sysdeps/unix/sysv/linux/fallocate.c
index 6a58a5f..8a7149f 100644
--- a/sysdeps/unix/sysv/linux/fallocate.c
+++ b/sysdeps/unix/sysv/linux/fallocate.c
@@ -15,6 +15,7 @@
    License along with the GNU C Library; if not, see
    <>.  */
+#ifndef	__OFF_T_MATCHES_OFF64_T
 #include <errno.h>
 #include <fcntl.h>
 #include <sysdep-cancel.h>
@@ -33,3 +34,5 @@ fallocate (int fd, int mode, __off_t offset, __off_t len)
   return -1;
+#endif /* __OFF_T_MATCHES_OFF64_T */
diff --git a/sysdeps/unix/sysv/linux/fallocate64.c b/sysdeps/unix/sysv/linux/fallocate64.c
index 8e76d6f..f4f73d5 100644
--- a/sysdeps/unix/sysv/linux/fallocate64.c
+++ b/sysdeps/unix/sysv/linux/fallocate64.c
@@ -35,3 +35,7 @@ fallocate64 (int fd, int mode, __off64_t offset, __off64_t len)
   return -1;
+#ifdef __OFF_T_MATCHES_OFF64_T
+weak_alias(fallocate64, fallocate)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]