aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--NEWS2
-rw-r--r--sysdeps/unix/sysv/linux/Makefile3
-rw-r--r--sysdeps/unix/sysv/linux/Versions2
-rw-r--r--sysdeps/unix/sysv/linux/bits/socket.h9
-rw-r--r--sysdeps/unix/sysv/linux/internal_sendmmsg.S14
-rw-r--r--sysdeps/unix/sysv/linux/kernel-features.h5
-rw-r--r--sysdeps/unix/sysv/linux/sendmmsg.c96
8 files changed, 136 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index e3d4ef7..1f474df 100644
--- 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 90470d3..e254fee 100644
--- 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
diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
index 3b4b63f..05834e3 100644
--- a/sysdeps/unix/sysv/linux/Makefile
+++ b/sysdeps/unix/sysv/linux/Makefile
@@ -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)
diff --git a/sysdeps/unix/sysv/linux/Versions b/sysdeps/unix/sysv/linux/Versions
index 984bc4f..3a3e8e8 100644
--- a/sysdeps/unix/sysv/linux/Versions
+++ b/sysdeps/unix/sysv/linux/Versions
@@ -160,6 +160,8 @@ libc {
name_to_handle_at; open_by_handle_at;
setns;
+
+ sendmmsg;
}
GLIBC_PRIVATE {
# functions used in other libraries
diff --git a/sysdeps/unix/sysv/linux/bits/socket.h b/sysdeps/unix/sysv/linux/bits/socket.h
index 6373757..96d9fed 100644
--- a/sysdeps/unix/sysv/linux/bits/socket.h
+++ b/sysdeps/unix/sysv/linux/bits/socket.h
@@ -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
index 0000000..f5152c9
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/internal_sendmmsg.S
@@ -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
diff --git a/sysdeps/unix/sysv/linux/kernel-features.h b/sysdeps/unix/sysv/linux/kernel-features.h
index d78f101..d91f581 100644
--- a/sysdeps/unix/sysv/linux/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/kernel-features.h
@@ -541,3 +541,8 @@
#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
index 0000000..d809987
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/sendmmsg.c
@@ -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