diff mbox series

[24/28] x32: Implement lseek64 in C

Message ID 20201118195552.2687336-25-adhemerval.zanella@linaro.org
State New
Headers show
Series More Linux syscall refactor | expand

Commit Message

Adhemerval Zanella Nov. 18, 2020, 7:55 p.m. UTC
Checked on x86_64-linux-gnu-x32
---
 sysdeps/unix/sysv/linux/x86_64/x32/lseek.S   | 43 -------------------
 sysdeps/unix/sysv/linux/x86_64/x32/lseek64.S |  1 -
 sysdeps/unix/sysv/linux/x86_64/x32/lseek64.c | 44 ++++++++++++++++++++
 3 files changed, 44 insertions(+), 44 deletions(-)
 delete mode 100644 sysdeps/unix/sysv/linux/x86_64/x32/lseek.S
 delete mode 100644 sysdeps/unix/sysv/linux/x86_64/x32/lseek64.S
 create mode 100644 sysdeps/unix/sysv/linux/x86_64/x32/lseek64.c
diff mbox series

Patch

diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/lseek.S b/sysdeps/unix/sysv/linux/x86_64/x32/lseek.S
deleted file mode 100644
index ca656ba12a..0000000000
--- a/sysdeps/unix/sysv/linux/x86_64/x32/lseek.S
+++ /dev/null
@@ -1,43 +0,0 @@ 
-/* The lseek system call with 64-bit offset.  Linux/x32 version.
-   Copyright (C) 2012-2020 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <https://www.gnu.org/licenses/>.  */
-
-#include <sysdep.h>
-
-/* Return -1LL in a full 64 bits.  */
-#undef SYSCALL_ERROR_HANDLER
-#define SYSCALL_ERROR_HANDLER	\
-0:				\
-	SYSCALL_SET_ERRNO;	\
-	orq $-1, %rax;		\
-	ret;
-
-/* Always use our own error handler.  */
-#undef SYSCALL_ERROR_LABEL
-#define SYSCALL_ERROR_LABEL 0f
-
-PSEUDO (__libc_lseek64, lseek, 3)
-	ret
-PSEUDO_END (__libc_lseek64)
-
-weak_alias (__libc_lseek64, __lseek64)
-libc_hidden_weak (__lseek64)
-weak_alias (__libc_lseek64, lseek64)
-libc_hidden_weak (lseek64)
-weak_alias (__libc_lseek64, __lseek)
-libc_hidden_weak (__lseek)
-weak_alias (__libc_lseek64, lseek)
diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/lseek64.S b/sysdeps/unix/sysv/linux/x86_64/x32/lseek64.S
deleted file mode 100644
index d81e98fb51..0000000000
--- a/sysdeps/unix/sysv/linux/x86_64/x32/lseek64.S
+++ /dev/null
@@ -1 +0,0 @@ 
-/* We don't need a definition since the llseek function is what we need.  */
diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/lseek64.c b/sysdeps/unix/sysv/linux/x86_64/x32/lseek64.c
new file mode 100644
index 0000000000..49c959943b
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/x86_64/x32/lseek64.c
@@ -0,0 +1,44 @@ 
+/* Linux lseek implementation, 64 bits off_t.  x86_64/x32 version.
+   Copyright (C) 2020 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include <unistd.h>
+#include <sysdep.h>
+#include <shlib-compat.h>
+
+static inline off64_t
+__lseek64_syscall (long int name, int fd, off64_t offset, int whence)
+{
+  off64_t resultvar;
+  asm volatile ("syscall\n\t"
+		: "=a" (resultvar)
+		: "0" (name),  "D" (fd), "S" (offset), "d" (whence)
+		: "memory", "cc", "r11", "cx");
+  return resultvar < 0
+	 ? SYSCALL_ERROR_LABEL (INTERNAL_SYSCALL_ERRNO (resultvar))
+	 : resultvar;
+}
+
+#undef INLINE_SYSCALL_CALL
+#define INLINE_SYSCALL_CALL(name, ...) \
+  __lseek64_syscall(__NR_##name, __VA_ARGS__)
+
+/* Disable the llseek compat symbol.  */
+#undef SHLIB_COMPAT
+#define SHLIB_COMPAT(a, b, c) 0
+
+#include <sysdeps/unix/sysv/linux/lseek64.c>