This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] fallocate: pass off_t in register pair correctly for 64-bit off_t
- From: Yury Norov <ynorov at caviumnetworks dot com>
- To: <libc-alpha at sourceware dot org>
- Cc: <cmetcalf at tilera dot com>, <pinskia at gmail dot com>, <cmetcalf at mellanox dot com>, <joseph at codesourcery dot com>, Yury Norov <ynorov at caviumnetworks dot com>
- Date: Fri, 24 Jun 2016 08:43:15 +0300
- Subject: [PATCH] fallocate: pass off_t in register pair correctly for 64-bit off_t
- Authentication-results: sourceware.org; auth=none
- Authentication-results: spf=none (sender IP is ) smtp dot mailfrom=Yuri dot Norov at caviumnetworks dot com;
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:99
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))
#else
#define CREATE_OFF_PAIR(val) ((val) >> 32, (val))
#endif
If 2nd option is looking more appropriated, I can prepare the patch for all
affected syscalls.
Signed-off-by: Yury Norov <ynorov@caviumnetworks.com>
---
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
<http://www.gnu.org/licenses/>. */
+#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
}
+
+#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;
#endif
}
+
+#ifdef __OFF_T_MATCHES_OFF64_T
+weak_alias(fallocate64, fallocate)
+#endif
--
2.7.4