[22/28] Linux: implement ioctl in C

Message ID 20201118195552.2687336-23-adhemerval.zanella@linaro.org
State Superseded
Headers
Series More Linux syscall refactor |

Commit Message

Adhemerval Zanella Nov. 18, 2020, 7:55 p.m. UTC
  This avoid variadic function in syscalls.list and the possible mismatch
between the asm syscall macros the required ABI to handle the variadic
argument.

Checked on x86_64-linux-gnu.
---
 sysdeps/unix/syscalls.list      |  1 -
 sysdeps/unix/sysv/linux/ioctl.c | 36 +++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 1 deletion(-)
 create mode 100644 sysdeps/unix/sysv/linux/ioctl.c
  

Patch

diff --git a/sysdeps/unix/syscalls.list b/sysdeps/unix/syscalls.list
index 6d1a2ad441..353afe594f 100644
--- a/sysdeps/unix/syscalls.list
+++ b/sysdeps/unix/syscalls.list
@@ -31,7 +31,6 @@  getrlimit	-	getrlimit	i:ip	__getrlimit	getrlimit
 getsockname	-	getsockname	i:ibN	__getsockname	getsockname
 getsockopt	-	getsockopt	i:iiiBN	getsockopt
 getuid		-	getuid		Ei:	__getuid	getuid
-ioctl		-	ioctl		i:iiI	__ioctl		ioctl
 kill		-	kill		i:ii	__kill		kill
 link		-	link		i:ss	__link		link
 listen		-	listen		i:ii	__listen	listen
diff --git a/sysdeps/unix/sysv/linux/ioctl.c b/sysdeps/unix/sysv/linux/ioctl.c
new file mode 100644
index 0000000000..fe0dc5661e
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/ioctl.c
@@ -0,0 +1,36 @@ 
+/* Control device.  Linux 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 <sys/ioctl.h>
+#include <stdarg.h>
+#include <sysdep.h>
+
+int
+__ioctl (int fd, unsigned long int request, ...)
+{
+  void *arg;
+  va_list va;
+
+  va_start (va, request);
+  arg = va_arg (va, void *);
+  va_end (va);
+
+  return INLINE_SYSCALL_CALL (ioctl, fd, request, arg);
+}
+libc_hidden_def (__ioctl)
+weak_alias (__ioctl, ioctl)