summaryrefslogtreecommitdiff
path: root/usr/src/lib/libc
diff options
context:
space:
mode:
authorBryan Cantrill <bryan@joyent.com>2014-12-10 17:02:00 +0000
committerBryan Cantrill <bryan@joyent.com>2014-12-10 17:02:00 +0000
commitbeb6d9b7f121cfc72dac3b54f40f1bb3fd8e04e9 (patch)
treefa8d4599d166605026871495b7da4268ca03f935 /usr/src/lib/libc
parent22a76dcc405e68b51ef58b0b8dbe09439eabaae0 (diff)
downloadillumos-joyent-beb6d9b7f121cfc72dac3b54f40f1bb3fd8e04e9.tar.gz
OS-3625 add support for eventfd
Diffstat (limited to 'usr/src/lib/libc')
-rw-r--r--usr/src/lib/libc/amd64/Makefile1
-rw-r--r--usr/src/lib/libc/i386/Makefile.com1
-rw-r--r--usr/src/lib/libc/port/mapfile-vers3
-rw-r--r--usr/src/lib/libc/port/sys/eventfd.c65
-rw-r--r--usr/src/lib/libc/sparc/Makefile.com1
5 files changed, 71 insertions, 0 deletions
diff --git a/usr/src/lib/libc/amd64/Makefile b/usr/src/lib/libc/amd64/Makefile
index 9a496b0d7e..12fe1429fb 100644
--- a/usr/src/lib/libc/amd64/Makefile
+++ b/usr/src/lib/libc/amd64/Makefile
@@ -858,6 +858,7 @@ PORTSYS= \
execl.o \
execle.o \
execv.o \
+ eventfd.o \
fcntl.o \
getpagesizes.o \
getpeerucred.o \
diff --git a/usr/src/lib/libc/i386/Makefile.com b/usr/src/lib/libc/i386/Makefile.com
index 01f71c334c..b6a9c822c6 100644
--- a/usr/src/lib/libc/i386/Makefile.com
+++ b/usr/src/lib/libc/i386/Makefile.com
@@ -892,6 +892,7 @@ PORTSYS= \
chown.o \
corectl.o \
epoll.o \
+ eventfd.o \
exacctsys.o \
execl.o \
execle.o \
diff --git a/usr/src/lib/libc/port/mapfile-vers b/usr/src/lib/libc/port/mapfile-vers
index 70d37d04be..09db2c67e4 100644
--- a/usr/src/lib/libc/port/mapfile-vers
+++ b/usr/src/lib/libc/port/mapfile-vers
@@ -2815,6 +2815,9 @@ $endif
epoll_pwait;
_errfp;
_errxfp;
+ eventfd;
+ eventfd_read;
+ eventfd_write;
exportfs;
_F_cplx_div;
_F_cplx_div_ix;
diff --git a/usr/src/lib/libc/port/sys/eventfd.c b/usr/src/lib/libc/port/sys/eventfd.c
new file mode 100644
index 0000000000..bd2eba4efa
--- /dev/null
+++ b/usr/src/lib/libc/port/sys/eventfd.c
@@ -0,0 +1,65 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright (c) 2014, Joyent, Inc. All rights reserved.
+ */
+
+#include <sys/eventfd.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <errno.h>
+#include <fcntl.h>
+
+int
+eventfd(unsigned int initval, int flags)
+{
+ int oflags = O_RDWR;
+ uint64_t val = initval;
+ int fd;
+
+ if (flags & ~(EFD_NONBLOCK | EFD_CLOEXEC | EFD_SEMAPHORE))
+ return (EINVAL);
+
+ if (flags & EFD_NONBLOCK)
+ oflags |= O_NONBLOCK;
+
+ if (flags & EFD_CLOEXEC)
+ oflags |= O_CLOEXEC;
+
+ if ((fd = open("/dev/eventfd", oflags)) < 0)
+ return (-1);
+
+ if ((flags & EFD_SEMAPHORE) &&
+ ioctl(fd, EVENTFDIOC_SEMAPHORE, 0) != 0) {
+ (void) close(fd);
+ return (-1);
+ }
+
+ if (write(fd, &val, sizeof (val)) < sizeof (val)) {
+ (void) close(fd);
+ return (-1);
+ }
+
+ return (fd);
+}
+
+int
+eventfd_read(int fd, eventfd_t *valp)
+{
+ return (read(fd, valp, sizeof (*valp)) < sizeof (*valp) ? -1 : 0);
+}
+
+int
+eventfd_write(int fd, eventfd_t val)
+{
+ return (write(fd, &val, sizeof (val)) < sizeof (val) ? -1 : 0);
+}
diff --git a/usr/src/lib/libc/sparc/Makefile.com b/usr/src/lib/libc/sparc/Makefile.com
index 4c5bbcfc96..11ad0b3996 100644
--- a/usr/src/lib/libc/sparc/Makefile.com
+++ b/usr/src/lib/libc/sparc/Makefile.com
@@ -926,6 +926,7 @@ PORTSYS= \
chown.o \
corectl.o \
epoll.o \
+ eventfd.o \
exacctsys.o \
execl.o \
execle.o \