aboutsummaryrefslogtreecommitdiffstats
path: root/arch/um/os-Linux/file.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/um/os-Linux/file.c')
-rw-r--r--arch/um/os-Linux/file.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/arch/um/os-Linux/file.c b/arch/um/os-Linux/file.c
index f25b110d4e70..91f23035be08 100644
--- a/arch/um/os-Linux/file.c
+++ b/arch/um/os-Linux/file.c
@@ -15,6 +15,7 @@
15#include <sys/sysmacros.h> 15#include <sys/sysmacros.h>
16#include <sys/un.h> 16#include <sys/un.h>
17#include <sys/types.h> 17#include <sys/types.h>
18#include <sys/eventfd.h>
18#include <os.h> 19#include <os.h>
19 20
20static void copy_stat(struct uml_stat *dst, const struct stat64 *src) 21static void copy_stat(struct uml_stat *dst, const struct stat64 *src)
@@ -620,3 +621,46 @@ int os_falloc_punch(int fd, unsigned long long offset, int len)
620 return n; 621 return n;
621} 622}
622 623
624int os_eventfd(unsigned int initval, int flags)
625{
626 int fd = eventfd(initval, flags);
627
628 if (fd < 0)
629 return -errno;
630 return fd;
631}
632
633int os_sendmsg_fds(int fd, const void *buf, unsigned int len, const int *fds,
634 unsigned int fds_num)
635{
636 struct iovec iov = {
637 .iov_base = (void *) buf,
638 .iov_len = len,
639 };
640 union {
641 char control[CMSG_SPACE(sizeof(*fds) * OS_SENDMSG_MAX_FDS)];
642 struct cmsghdr align;
643 } u;
644 unsigned int fds_size = sizeof(*fds) * fds_num;
645 struct msghdr msg = {
646 .msg_iov = &iov,
647 .msg_iovlen = 1,
648 .msg_control = u.control,
649 .msg_controllen = CMSG_SPACE(fds_size),
650 };
651 struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msg);
652 int err;
653
654 if (fds_num > OS_SENDMSG_MAX_FDS)
655 return -EINVAL;
656 memset(u.control, 0, sizeof(u.control));
657 cmsg->cmsg_level = SOL_SOCKET;
658 cmsg->cmsg_type = SCM_RIGHTS;
659 cmsg->cmsg_len = CMSG_LEN(fds_size);
660 memcpy(CMSG_DATA(cmsg), fds, fds_size);
661 err = sendmsg(fd, &msg, 0);
662
663 if (err < 0)
664 return -errno;
665 return err;
666}