Просмотр исходного кода

mips: fix fallocate() 64-bit argument passing on n32

The generic fallocate64() (libc/sysdeps/linux/common/fallocate64.c) passes
the 64-bit offset and length as o32-style register pairs (OFF64_HI_LO) for
every __WORDSIZE == 32 target.  n32 is ILP32 but has 64-bit registers and
passes a 64-bit value whole, like n64, so the split mangled the arguments
and fallocate()/posix_fallocate() failed on n32 (tst-fallocate,
tst-posix_fallocate).

Add a mips fallocate64.c override (mirroring the existing
posix_fadvise64.c): split into pairs only for _ABIO32, pass each 64-bit
argument whole on n32.  Verified on qemu-system-mips64 (mips64-be-n32,
kernel 4.19.56): tst-fallocate and tst-posix_fallocate now pass; o32 and
n64 are unchanged.

Signed-off-by: Ramin Moussavi <ramin.moussavi@yacoub.de>
ramin 4 дней назад
Родитель
Сommit
c4a85efd42
2 измененных файлов с 44 добавлено и 1 удалено
  1. 2 1
      libc/sysdeps/linux/mips/Makefile.arch
  2. 42 0
      libc/sysdeps/linux/mips/fallocate64.c

+ 2 - 1
libc/sysdeps/linux/mips/Makefile.arch

@@ -7,7 +7,8 @@
 
 CSRC-y := \
 	__longjmp.c  brk.c setjmp_aux.c \
-	pread_write.c sigaction.c _test_and_set.c
+	pread_write.c sigaction.c _test_and_set.c \
+	fallocate64.c
 
 SSRC-y := bsd-_setjmp.S bsd-setjmp.S setjmp.S syscall.S pipe.S syscall_error.S \
 	  vfork.S clone.S

+ 42 - 0
libc/sysdeps/linux/mips/fallocate64.c

@@ -0,0 +1,42 @@
+/*
+ * fallocate64() for MIPS uClibc
+ *
+ * Copyright (C) 2026 Ramin Moussavi <ramin.moussavi@yacoub.de>
+ *
+ * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB in this tarball.
+ */
+
+#include <_lfs_64.h>
+#include <sys/syscall.h>
+#include <bits/wordsize.h>
+
+#if defined __NR_fallocate && __WORDSIZE == 32
+# include <fcntl.h>
+# include <endian.h>
+# include <errno.h>
+# include <sgidefs.h>
+
+extern __typeof(fallocate64) __libc_fallocate64 attribute_hidden;
+int attribute_hidden __libc_fallocate64(int fd, int mode, __off64_t offset,
+		__off64_t len)
+{
+	int ret;
+	INTERNAL_SYSCALL_DECL(err);
+# if _MIPS_SIM == _ABIO32
+	/* o32 splits each 64-bit argument into a register pair.  */
+	ret = (int) (INTERNAL_SYSCALL(fallocate, err, 6, fd, mode,
+		OFF64_HI_LO (offset), OFF64_HI_LO (len)));
+# else /* N32: 64-bit registers, pass each 64-bit argument whole.  */
+	ret = (int) (INTERNAL_SYSCALL(fallocate, err, 4, fd, mode, offset, len));
+# endif
+	if (unlikely(INTERNAL_SYSCALL_ERROR_P (ret, err))) {
+		__set_errno(INTERNAL_SYSCALL_ERRNO (ret, err));
+		ret = -1;
+	}
+	return ret;
+}
+
+# if defined __UCLIBC_LINUX_SPECIFIC__ && defined __USE_GNU
+strong_alias(__libc_fallocate64,fallocate64)
+# endif
+#endif