diff mbox

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

Message ID 1466746995-25982-1-git-send-email-ynorov@caviumnetworks.com
State New
Headers show

Commit Message

Yury Norov June 24, 2016, 5:43 a.m. UTC
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(+)

-- 
2.7.4
diff mbox

Patch

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