Add sendmmsg syscall

This commit is contained in:
Ulrich Drepper 2011-05-28 01:43:20 -04:00
parent ce67228d57
commit f1f929d74a
8 changed files with 136 additions and 3 deletions

View File

@ -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.

2
NEWS
View File

@ -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

View 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)

View File

@ -160,6 +160,8 @@ libc {
name_to_handle_at; open_by_handle_at;
setns;
sendmmsg;
}
GLIBC_PRIVATE {
# functions used in other libraries

View 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 */

View File

@ -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

View File

@ -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

View File

@ -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