Blame SOURCES/glibc-recvmmsg.patch

b40826
2010-05-21  Andreas Schwab  <schwab@redhat.com>
b40826
b40826
	* sysdeps/unix/sysv/linux/Makefile (sysdep_routines): Add recvmmsg
b40826
	and internal_recvmmsg.
b40826
	* sysdeps/unix/sysv/linux/recvmmsg.c: New file.
b40826
	* sysdeps/unix/sysv/linux/internal_recvmmsg.S: New file.
b40826
	* sysdeps/unix/sysv/linux/socketcall.h (SOCKOP_recvmmsg): Define.
b40826
	* sysdeps/unix/sysv/linux/syscalls.list (recvmmsg): Remove.
b40826
b40826
Index: glibc-2.12-2-gc4ccff1/sysdeps/unix/sysv/linux/Makefile
b40826
===================================================================
b40826
--- glibc-2.12-2-gc4ccff1.orig/sysdeps/unix/sysv/linux/Makefile
b40826
+++ glibc-2.12-2-gc4ccff1/sysdeps/unix/sysv/linux/Makefile
b40826
@@ -12,7 +12,7 @@ CFLAGS-malloc.c += -DMORECORE_CLEARS=2
b40826
 endif
b40826
 
b40826
 ifeq ($(subdir),socket)
b40826
-sysdep_routines += internal_accept4
b40826
+sysdep_routines += internal_accept4 recvmmsg internal_recvmmsg
b40826
 endif
b40826
 
b40826
 ifeq ($(subdir),misc)
b40826
Index: glibc-2.12-2-gc4ccff1/sysdeps/unix/sysv/linux/internal_recvmmsg.S
b40826
===================================================================
b40826
--- /dev/null
b40826
+++ glibc-2.12-2-gc4ccff1/sysdeps/unix/sysv/linux/internal_recvmmsg.S
b40826
@@ -0,0 +1,14 @@
b40826
+#include <kernel-features.h>
b40826
+#include <sys/syscall.h>
b40826
+#if !defined __NR_recvmmsg && defined __NR_socketcall
b40826
+# define socket	recvmmsg
b40826
+# ifdef __ASSUME_RECVMMSG
b40826
+#  define __socket recvmmsg
b40826
+# else
b40826
+#  define __socket __internal_recvmmsg
b40826
+# endif
b40826
+# define NARGS 5
b40826
+# define NEED_CANCELLATION
b40826
+# define NO_WEAK_ALIAS
b40826
+# include <socket.S>
b40826
+#endif
b40826
Index: glibc-2.12-2-gc4ccff1/sysdeps/unix/sysv/linux/kernel-features.h
b40826
===================================================================
b40826
--- glibc-2.12-2-gc4ccff1.orig/sysdeps/unix/sysv/linux/kernel-features.h
b40826
+++ glibc-2.12-2-gc4ccff1/sysdeps/unix/sysv/linux/kernel-features.h
b40826
@@ -547,3 +547,8 @@
b40826
 #if __LINUX_KERNEL_VERSION >= 0x020620
b40826
 # define __ASSUME_F_GETOWN_EX	1
b40826
 #endif
b40826
+
b40826
+/* Support for the recvmmsg syscall was added in 2.6.33.  */
b40826
+#if __LINUX_KERNEL_VERSION >= 0x020621
b40826
+# define __ASSUME_RECVMMSG	1
b40826
+#endif
b40826
Index: glibc-2.12-2-gc4ccff1/sysdeps/unix/sysv/linux/recvmmsg.c
b40826
===================================================================
b40826
--- /dev/null
b40826
+++ glibc-2.12-2-gc4ccff1/sysdeps/unix/sysv/linux/recvmmsg.c
b40826
@@ -0,0 +1,100 @@
b40826
+/* Copyright (C) 2010 Free Software Foundation, Inc.
b40826
+   This file is part of the GNU C Library.
b40826
+   Contributed by Andreas Schwab <schwab@redhat.com>, 2010.
b40826
+
b40826
+   The GNU C Library is free software; you can redistribute it and/or
b40826
+   modify it under the terms of the GNU Lesser General Public
b40826
+   License as published by the Free Software Foundation; either
b40826
+   version 2.1 of the License, or (at your option) any later version.
b40826
+
b40826
+   The GNU C Library is distributed in the hope that it will be useful,
b40826
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
b40826
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
b40826
+   Lesser General Public License for more details.
b40826
+
b40826
+   You should have received a copy of the GNU Lesser General Public
b40826
+   License along with the GNU C Library; if not, write to the Free
b40826
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
b40826
+   02111-1307 USA.  */
b40826
+
b40826
+#include <errno.h>
b40826
+#include <sys/socket.h>
b40826
+
b40826
+#include <sysdep-cancel.h>
b40826
+#include <sys/syscall.h>
b40826
+#include <kernel-features.h>
b40826
+
b40826
+
b40826
+#ifdef __NR_recvmmsg
b40826
+int
b40826
+recvmmsg (int fd, struct mmsghdr *vmessages, unsigned int vlen, int flags,
b40826
+	  const struct timespec *tmo)
b40826
+{
b40826
+  if (SINGLE_THREAD_P)
b40826
+    return INLINE_SYSCALL (recvmmsg, 5, fd, vmessages, vlen, flags, tmo);
b40826
+
b40826
+  int oldtype = LIBC_CANCEL_ASYNC ();
b40826
+
b40826
+  int result = INLINE_SYSCALL (recvmmsg, 5, fd, vmessages, vlen, flags, tmo);
b40826
+
b40826
+  LIBC_CANCEL_RESET (oldtype);
b40826
+
b40826
+  return result;
b40826
+}
b40826
+#elif defined __NR_socketcall
b40826
+# ifndef __ASSUME_RECVMMSG
b40826
+extern int __internal_recvmmsg (int fd, struct mmsghdr *vmessages,
b40826
+				unsigned int vlen, int flags,
b40826
+				const struct timespec *tmo)
b40826
+     attribute_hidden;
b40826
+
b40826
+static int have_recvmmsg;
b40826
+
b40826
+int
b40826
+recvmmsg (int fd, struct mmsghdr *vmessages, unsigned int vlen, int flags,
b40826
+	  const struct timespec *tmo)
b40826
+{
b40826
+  if (__builtin_expect (have_recvmmsg >= 0, 1))
b40826
+    {
b40826
+      int ret = __internal_recvmmsg (fd, vmessages, vlen, flags, tmo);
b40826
+      /* The kernel returns -EINVAL for unknown socket operations.
b40826
+	 We need to convert that error to an ENOSYS error.  */
b40826
+      if (__builtin_expect (ret < 0, 0)
b40826
+	  && have_recvmmsg == 0
b40826
+	  && errno == EINVAL)
b40826
+	{
b40826
+	  /* Try another call, this time with an invalid file
b40826
+	     descriptor and all other parameters cleared.  This call
b40826
+	     will not cause any harm and it will return
b40826
+	     immediately.  */
b40826
+	  ret = __internal_recvmmsg (-1, 0, 0, 0, 0);
b40826
+	  if (errno == EINVAL)
b40826
+	    {
b40826
+	      have_recvmmsg = -1;
b40826
+	      __set_errno (ENOSYS);
b40826
+	    }
b40826
+	  else
b40826
+	    {
b40826
+	      have_recvmmsg = 1;
b40826
+	      __set_errno (EINVAL);
b40826
+	    }
b40826
+	  return -1;
b40826
+	}
b40826
+      return ret;
b40826
+    }
b40826
+  __set_errno (ENOSYS);
b40826
+  return -1;
b40826
+}
b40826
+# else
b40826
+/* When __ASSUME_RECVMMSG recvmmsg is defined in internal_recvmmsg.S.  */
b40826
+# endif
b40826
+#else
b40826
+int
b40826
+recvmmsg (int fd, struct mmsghdr *vmessages, unsigned int vlen, int flags,
b40826
+	  const struct timespec *tmo)
b40826
+{
b40826
+  __set_errno (ENOSYS);
b40826
+  return -1;
b40826
+}
b40826
+stub_warning (recvmmsg)
b40826
+#endif
b40826
Index: glibc-2.12-2-gc4ccff1/sysdeps/unix/sysv/linux/socketcall.h
b40826
===================================================================
b40826
--- glibc-2.12-2-gc4ccff1.orig/sysdeps/unix/sysv/linux/socketcall.h
b40826
+++ glibc-2.12-2-gc4ccff1/sysdeps/unix/sysv/linux/socketcall.h
b40826
@@ -44,5 +44,6 @@
b40826
 #define SOCKOP_sendmsg		16
b40826
 #define SOCKOP_recvmsg		17
b40826
 #define SOCKOP_accept4		18
b40826
+#define SOCKOP_recvmmsg		19
b40826
 
b40826
 #endif /* sys/socketcall.h */
b40826
Index: glibc-2.12-2-gc4ccff1/sysdeps/unix/sysv/linux/syscalls.list
b40826
===================================================================
b40826
--- glibc-2.12-2-gc4ccff1.orig/sysdeps/unix/sysv/linux/syscalls.list
b40826
+++ glibc-2.12-2-gc4ccff1/sysdeps/unix/sysv/linux/syscalls.list
b40826
@@ -53,7 +53,6 @@ prctl		EXTRA	prctl		i:iiiii	__prctl		prc
b40826
 putpmsg		-	putpmsg		i:ippii	putpmsg
b40826
 query_module	EXTRA	query_module	i:sipip	query_module
b40826
 quotactl	EXTRA	quotactl	i:isip	quotactl
b40826
-recvmmsg	EXTRA	recvmmsg	Ci:ipiip	recvmmsg
b40826
 remap_file_pages -	remap_file_pages i:piiii	__remap_file_pages remap_file_pages
b40826
 sched_getp	-	sched_getparam	i:ip	__sched_getparam	sched_getparam
b40826
 sched_gets	-	sched_getscheduler	i:i	__sched_getscheduler	sched_getscheduler