Blame SOURCES/glibc-recvmmsg.patch

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