summaryrefslogtreecommitdiff
path: root/usr/src/lib/libc
diff options
context:
space:
mode:
authorBryan Cantrill <bryan@joyent.com>2015-08-28 17:45:00 -0700
committerRobert Mustacchi <rm@joyent.com>2015-09-09 14:52:48 -0700
commit1767006bb066ef500b90b432fba79d63d0d09b36 (patch)
treed564b9848c88ffa7d88393e69dca320df8105ebd /usr/src/lib/libc
parentcf6106c8a0d6598b045811f9650d66e07eb332af (diff)
downloadillumos-joyent-1767006bb066ef500b90b432fba79d63d0d09b36.tar.gz
6188 add support for eventfd
Reviewed by: Albert Lee <trisk@omniti.com> Reviewed by: Igor Kozhukhov <ikozhukhov@gmail.com> Reviewed by: Dan McDonald <danmcd@omniti.com> Reviewed by: Gordon Ross <gwr@nexenta.com> Approved by: Richard Lowe <richlowe@richlowe.net>
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-vers7
-rw-r--r--usr/src/lib/libc/port/sys/eventfd.c67
-rw-r--r--usr/src/lib/libc/sparc/Makefile.com1
-rw-r--r--usr/src/lib/libc/sparcv9/Makefile.com1
6 files changed, 78 insertions, 0 deletions
diff --git a/usr/src/lib/libc/amd64/Makefile b/usr/src/lib/libc/amd64/Makefile
index 3d649dfe9d..0c1421bbf2 100644
--- a/usr/src/lib/libc/amd64/Makefile
+++ b/usr/src/lib/libc/amd64/Makefile
@@ -867,6 +867,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 beb568ebf6..9a76280c0a 100644
--- a/usr/src/lib/libc/i386/Makefile.com
+++ b/usr/src/lib/libc/i386/Makefile.com
@@ -903,6 +903,7 @@ PORTSYS= \
chmod.o \
chown.o \
corectl.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 e133407665..c4571ef2f1 100644
--- a/usr/src/lib/libc/port/mapfile-vers
+++ b/usr/src/lib/libc/port/mapfile-vers
@@ -93,6 +93,13 @@ $if _x86 && _ELF64
$add amd64
$endif
+SYMBOL_VERSION ILLUMOS_0.13 { # eventfd
+ protected:
+ eventfd;
+ eventfd_read;
+ eventfd_write;
+} ILLUMOS_0.12;
+
SYMBOL_VERSION ILLUMOS_0.12 { # arc4random and friends
protected:
arc4random;
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..f165491cc1
--- /dev/null
+++ b/usr/src/lib/libc/port/sys/eventfd.c
@@ -0,0 +1,67 @@
+/*
+ * 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) 2015, 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)) {
+ errno = EINVAL;
+ return (-1);
+ }
+
+ 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 2991bb2d4d..3856c5332c 100644
--- a/usr/src/lib/libc/sparc/Makefile.com
+++ b/usr/src/lib/libc/sparc/Makefile.com
@@ -937,6 +937,7 @@ PORTSYS= \
chmod.o \
chown.o \
corectl.o \
+ eventfd.o \
exacctsys.o \
execl.o \
execle.o \
diff --git a/usr/src/lib/libc/sparcv9/Makefile.com b/usr/src/lib/libc/sparcv9/Makefile.com
index 255121cab6..1a65ab7680 100644
--- a/usr/src/lib/libc/sparcv9/Makefile.com
+++ b/usr/src/lib/libc/sparcv9/Makefile.com
@@ -881,6 +881,7 @@ PORTSYS= \
chmod.o \
chown.o \
corectl.o \
+ eventfd.o \
exacctsys.o \
execl.o \
execle.o \