This is the mail archive of the
libc-hacker@sourceware.cygnus.com
mailing list for the glibc project.
ioctl translation preliminary patch
- To: libc-alpha@cygnus.com
- Subject: ioctl translation preliminary patch
- From: Dan Jacobowitz <drow@false.org>
- Date: Wed, 5 Aug 1998 00:15:13 -0400
- Mail-Followup-To: libc-alpha@cygnus.com
All right, I wrote up some code to do this - I've been running it for a
few days now and haven't had a single problem, so I'll submit it. The
symbol versioning is not the way I want it to be, although it makes
only the tiniest performance difference; is it possible to specify
symbol versions in a syscalls.list file? I wanted __syscall_ioctl to
be the ioctl@GLIBC_2.0. Otherwise, of course, sticking a simple
function in ioctl.c would achieve the same end, but I was too far into
the compile when I figured that out to try it. It could use a little
polishing, but it's all there.
Daniel Jacobowitz
dan@debian.org
--- glibc-pre2.1-2.0.95.orig/sysdeps/generic/glob.c
+++ glibc-pre2.1-2.0.95/sysdeps/generic/glob.c
@@ -281,6 +281,13 @@
# undef GLOB_PERIOD
#endif
#include <glob.h>
+
+/* DJ: Ugly hack...Work, damn you. */
+#ifdef __powerpc__
+#undef __stat
+#define __stat(a,b) __xstat(_STAT_VER,a,b)
+#endif
+
static
#if __GNUC__ - 0 >= 2
--- glibc-pre2.1-2.0.95.orig/sysdeps/unix/sysv/linux/syscalls.list
+++ glibc-pre2.1-2.0.95/sysdeps/unix/sysv/linux/syscalls.list
@@ -47,6 +47,7 @@
s_getpriority getpriority getpriority 2 __syscall_getpriority
s_getresgid getresgid getresgid 3 __syscall_getresgid
s_getresuid getresuid getresuid 3 __syscall_getresuid
+s_ioctl ioctl ioctl 3 __syscall_ioctl
s_poll poll poll 3 __syscall_poll
s_pread64 pread64 pread 5 __syscall_pread64
s_ptrace ptrace ptrace 4 __syscall_ptrace
--- glibc-pre2.1-2.0.95.orig/sysdeps/unix/sysv/linux/Versions
+++ glibc-pre2.1-2.0.95/sysdeps/unix/sysv/linux/Versions
@@ -70,6 +70,9 @@
# chown interface change.
chown;
+ # Translate changed ioctl()s.
+ __ioctl; ioctl;
+
# Change in pthread_attr_t.
pthread_attr_init;
--- glibc-pre2.1-2.0.95.orig/sysdeps/unix/sysv/linux/tcgetattr.c
+++ glibc-pre2.1-2.0.95/sysdeps/unix/sysv/linux/tcgetattr.c
@@ -27,6 +27,8 @@
translate it here. */
#include <kernel_termios.h>
+extern int __syscall_ioctl(int __fd, unsigned long int __request, ...);
+
/* Put the state of FD into *TERMIOS_P. */
int
__tcgetattr (fd, termios_p)
@@ -36,7 +38,7 @@
struct __kernel_termios k_termios;
int retval;
- retval = __ioctl (fd, TCGETS, &k_termios);
+ retval = __syscall_ioctl (fd, TCGETS, &k_termios);
termios_p->c_iflag = k_termios.c_iflag;
termios_p->c_oflag = k_termios.c_oflag;
--- glibc-pre2.1-2.0.95.orig/sysdeps/unix/sysv/linux/tcsetattr.c
+++ glibc-pre2.1-2.0.95/sysdeps/unix/sysv/linux/tcsetattr.c
@@ -27,6 +27,7 @@
translate it here. */
#include <kernel_termios.h>
+extern int __syscall_ioctl(int __fd, unsigned long int __request, ...);
/* Set the state of FD to *TERMIOS_P. */
int
@@ -68,5 +69,5 @@
memcpy (&k_termios.c_cc[0], &termios_p->c_cc[0],
__KERNEL_NCCS * sizeof (cc_t));
- return __ioctl (fd, cmd, &k_termios);
+ return __syscall_ioctl (fd, cmd, &k_termios);
}
--- glibc-pre2.1-2.0.95.orig/sysdeps/unix/sysv/linux/ioctl.c
+++ glibc-pre2.1-2.0.95/sysdeps/unix/sysv/linux/ioctl.c
@@ -0,0 +1,82 @@
+/* Copyright (C) 1998 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 Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <stdarg.h>
+#include <sys/syscall.h>
+#include <sys/ioctl.h>
+#include <termios.h>
+
+/*
+ The user-visible size of struct termios has changed. Catch ioctl calls
+ using the new-style struct termios, and translate them to old-style.
+*/
+
+extern int __syscall_ioctl (int fd, unsigned long int request, ...);
+
+int __new_ioctl(int fd, unsigned long int request, ...)
+{
+ void *arg;
+ va_list ap;
+
+ va_start(ap, request);
+ arg = va_arg(ap, void *);
+ va_end(ap);
+
+ switch(request) {
+ case TCGETS:
+ return tcgetattr(fd, (struct termios *)arg);
+ break;
+ case TCSETS:
+ return tcsetattr(fd, TCSANOW, (struct termios *)arg);
+ break;
+ case TCSETSW:
+ return tcsetattr(fd, TCSADRAIN, (struct termios *)arg);
+ break;
+ case TCSETSF:
+ return tcsetattr(fd, TCSAFLUSH, (struct termios *)arg);
+ break;
+ }
+ return __syscall_ioctl(fd, request, arg);
+}
+
+#if 0
+ #if defined HAVE_ELF && defined PIC && defined DO_VERSIONING
+
+ strong_alias (__syscall_ioctl, _syscall_ioctl);
+ symbol_version (__syscall_ioctl, __ioctl, GLIBC_2.0);
+ symbol_version (_syscall_ioctl, ioctl, GLIBC_2.0);
+
+ strong_alias (__new_ioctl, _new_ioctl);
+ default_symbol_version(__new_ioctl, __ioctl, GLIBC_2.1);
+ default_symbol_version(_new_ioctl, ioctl, GLIBC_2.1);
+
+ #else
+ /* No versioning - so use only the 2.1 version. */
+ strong_alias (__new_ioctl, __ioctl);
+ weak_alias(__new_ioctl, ioctl);
+
+ #endif
+#else
+ /* Don't worry about it for now...it introduces no backwards compatability bugs, */
+ /* just a tiny bit of overhead. */
+
+ strong_alias (__new_ioctl, __ioctl);
+ weak_alias(__new_ioctl, ioctl);
+#endif