]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Add sendmmsg syscall
authorUlrich Drepper <drepper@gmail.com>
Sat, 28 May 2011 05:43:20 +0000 (01:43 -0400)
committerUlrich Drepper <drepper@gmail.com>
Sat, 28 May 2011 05:43:20 +0000 (01:43 -0400)
ChangeLog
NEWS
sysdeps/unix/sysv/linux/Makefile
sysdeps/unix/sysv/linux/Versions
sysdeps/unix/sysv/linux/bits/socket.h
sysdeps/unix/sysv/linux/internal_sendmmsg.S [new file with mode: 0644]
sysdeps/unix/sysv/linux/kernel-features.h
sysdeps/unix/sysv/linux/sendmmsg.c [new file with mode: 0644]

index e3d4ef7125f2839b5b3981701b7a5d6e2e20f874..1f474df77fc2b7658df93569ddaed40d9eca0d27 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2011-05-28  Ulrich Drepper  <drepper@gmail.com>
 
+       * sysdeps/unix/sysv/linux/internal_sendmmsg.S: New file.
+       * sysdeps/unix/sysv/linux/sendmmsg.c: New file.
+       * sysdeps/unix/sysv/linux/Makefile [subdir=socket] (sysdep_routines):
+       Add sendmmsg and internal_sendmmsg.
+       * sysdeps/unix/sysv/linux/Versions [GLIBC_2.14]: Add sendmmsg.
+       * sysdeps/unix/sysv/linux/bits/socket.h: Declare sendmmsg.
+       * sysdeps/unix/sysv/linux/kernel-features.h: Define __ASSUME_SENDMMSG.
+
        * sysdeps/unix/sysv/linux/syscalls.list: Add setns entry.
        * sysdeps/unix/sysv/linux/bits/sched.h: Declare setns.
        * sysdeps/unix/sysv/linux/Versions [GLIBC_2.14]: Add setns.
diff --git a/NEWS b/NEWS
index 90470d3e0fa3f63928d38d5ae07f249a708c44ad..e254fee59aeecc5adad4994caeb48c6e4759a8d5 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -30,7 +30,7 @@ Version 2.14
   Implemented by Ulrich Drepper.
 
 * New Linux interfaces: clock_adjtime, name_to_handle_at, open_by_handle_at,
-  syncfs, setns
+  syncfs, setns, sendmmsg
 
 * New locales: os_RU, bem_ZA, en_ZA, ff_SN, sw_KE, sw_TZ, lb_LU, wae_CH,
   yue_HK, lij_IT, mhr_RU
index 3b4b63f844632fc0ef8961809ad3111db0e56585..05834e3261b8ff82622a6bf1083eb16cf4231993 100644 (file)
@@ -12,7 +12,8 @@ CFLAGS-malloc.c += -DMORECORE_CLEARS=2
 endif
 
 ifeq ($(subdir),socket)
-sysdep_routines += internal_accept4 recvmmsg internal_recvmmsg
+sysdep_routines += internal_accept4 recvmmsg internal_recvmmsg sendmmsg \
+                  internal_sendmmsg
 endif
 
 ifeq ($(subdir),misc)
index 984bc4faf47ff224c8d67dfd9d7ba2fea3b2ebdf..3a3e8e8c2b641ec11f441c0cd43547f44f1afcc2 100644 (file)
@@ -160,6 +160,8 @@ libc {
     name_to_handle_at; open_by_handle_at;
 
     setns;
+
+    sendmmsg;
   }
   GLIBC_PRIVATE {
     # functions used in other libraries
index 637375791d17b82d0022ae3e0ec3750f472e1631..96d9fed0343ca6a820b850e61d9b0d1095398895 100644 (file)
@@ -421,7 +421,7 @@ struct linger
 
 __BEGIN_DECLS
 
-/* Receive a message as described by MESSAGE from socket FD.
+/* Receive up to VLEN messages as described by VMESSAGES from socket FD.
    Returns the number of bytes read or -1 for errors.
 
    This function is a cancellation point and therefore not marked with
@@ -430,6 +430,13 @@ extern int recvmmsg (int __fd, struct mmsghdr *__vmessages,
                     unsigned int __vlen, int __flags,
                     __const struct timespec *__tmo);
 
+/* Send a VLEN messages as described by VMESSAGES to socket FD.
+   Return the number of datagrams successfully written or -1 for errors.
+This function is a cancellation point and therefore not marked with
+   __THROW.  */
+extern int sendmmsg (int __fd, struct mmsghdr *__vmessages,
+                    unsigned int __vlen, int __flags);
+
 __END_DECLS
 
 #endif /* bits/socket.h */
diff --git a/sysdeps/unix/sysv/linux/internal_sendmmsg.S b/sysdeps/unix/sysv/linux/internal_sendmmsg.S
new file mode 100644 (file)
index 0000000..f5152c9
--- /dev/null
@@ -0,0 +1,14 @@
+#include <kernel-features.h>
+#include <sys/syscall.h>
+#if !defined __NR_sendmmsg && defined __NR_socketcall
+# define socket        sendmmsg
+# ifdef __ASSUME_SENDMMSG
+#  define __socket sendmmsg
+# else
+#  define __socket __internal_sendmmsg
+# endif
+# define NARGS 4
+# define NEED_CANCELLATION
+# define NO_WEAK_ALIAS
+# include <socket.S>
+#endif
index d78f1015d309ba6f6b19027a42619deb368fedf5..d91f581a9536fe0f4a9ca59366a5259572a70db3 100644 (file)
 #if __LINUX_KERNEL_VERSION >= 0x020624
 # define __ASSUME_PRLIMIT64    1
 #endif
+
+/* sendmmsg is available in 2.6.39.  */
+#if __LINUX_KERNEL_VERSION >= 0x020627
+# define __ASSUME_SENDMMSG     1
+#endif
diff --git a/sysdeps/unix/sysv/linux/sendmmsg.c b/sysdeps/unix/sysv/linux/sendmmsg.c
new file mode 100644 (file)
index 0000000..d809987
--- /dev/null
@@ -0,0 +1,96 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@gmail.com>, 2011.
+
+   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, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <errno.h>
+#include <sys/socket.h>
+
+#include <sysdep-cancel.h>
+#include <sys/syscall.h>
+#include <kernel-features.h>
+
+
+#ifdef __NR_sendmmsg
+int
+sendmmsg (int fd, struct mmsghdr *vmessages, unsigned int vlen, int flags)
+{
+  if (SINGLE_THREAD_P)
+    return INLINE_SYSCALL (sendmmsg, 4, fd, vmessages, vlen, flags);
+
+  int oldtype = LIBC_CANCEL_ASYNC ();
+
+  int result = INLINE_SYSCALL (sendmmsg, 4, fd, vmessages, vlen, flags);
+
+  LIBC_CANCEL_RESET (oldtype);
+
+  return result;
+}
+#elif defined __NR_socketcall
+# ifndef __ASSUME_SENDMMSG
+extern int __internal_sendmmsg (int fd, struct mmsghdr *vmessages,
+                               unsigned int vlen, int flags)
+     attribute_hidden;
+
+static int have_sendmmsg;
+
+int
+sendmmsg (int fd, struct mmsghdr *vmessages, unsigned int vlen, int flags)
+{
+  if (__builtin_expect (have_sendmmsg >= 0, 1))
+    {
+      int ret = __internal_sendmmsg (fd, vmessages, vlen, flags);
+      /* The kernel returns -EINVAL for unknown socket operations.
+        We need to convert that error to an ENOSYS error.  */
+      if (__builtin_expect (ret < 0, 0)
+         && have_sendmmsg == 0
+         && errno == EINVAL)
+       {
+         /* Try another call, this time with an invalid file
+            descriptor and all other parameters cleared.  This call
+            will not cause any harm and it will return
+            immediately.  */
+         ret = __internal_sendmmsg (-1, 0, 0, 0);
+         if (errno == EINVAL)
+           {
+             have_sendmmsg = -1;
+             __set_errno (ENOSYS);
+           }
+         else
+           {
+             have_sendmmsg = 1;
+             __set_errno (EINVAL);
+           }
+         return -1;
+       }
+      return ret;
+    }
+  __set_errno (ENOSYS);
+  return -1;
+}
+# else
+/* When __ASSUME_SENDMMSG sendmmsg is defined in internal_sendmmsg.S.  */
+# endif
+#else
+int
+sendmmsg (int fd, struct mmsghdr *vmessages, unsigned int vlen, int flags)
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+stub_warning (sendmmsg)
+#endif