summaryrefslogtreecommitdiff
path: root/usr/src/lib
diff options
context:
space:
mode:
authorBryan Cantrill <bryan@joyent.com>2015-09-04 08:32:01 -0700
committerRobert Mustacchi <rm@joyent.com>2015-10-16 15:07:22 -0700
commit6a72db4a7fa12c3e0d1c1cf91a07390739fa0fbf (patch)
tree01b80bd94b70941b4bebdf46773bfff1bdbdab3e /usr/src/lib
parentf3bb54f387fc03cf651e19bbee54cc88ee51bb29 (diff)
downloadillumos-joyent-6a72db4a7fa12c3e0d1c1cf91a07390739fa0fbf.tar.gz
6208 add support for timerfd
Reviewed by: Gordon Ross <gwr@nexenta.com> Approved by: Dan McDonald <danmcd@omniti.com>
Diffstat (limited to 'usr/src/lib')
-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/timerfd.c93
-rw-r--r--usr/src/lib/libc/sparc/Makefile.com1
-rw-r--r--usr/src/lib/libc/sparcv9/Makefile.com1
6 files changed, 104 insertions, 0 deletions
diff --git a/usr/src/lib/libc/amd64/Makefile b/usr/src/lib/libc/amd64/Makefile
index b5e54b19fa..dbda6c0c31 100644
--- a/usr/src/lib/libc/amd64/Makefile
+++ b/usr/src/lib/libc/amd64/Makefile
@@ -909,6 +909,7 @@ PORTSYS= \
tasksys.o \
time.o \
time_util.o \
+ timerfd.o \
ucontext.o \
unlink.o \
ustat.o \
diff --git a/usr/src/lib/libc/i386/Makefile.com b/usr/src/lib/libc/i386/Makefile.com
index d7e77502f2..25ba0a2743 100644
--- a/usr/src/lib/libc/i386/Makefile.com
+++ b/usr/src/lib/libc/i386/Makefile.com
@@ -949,6 +949,7 @@ PORTSYS= \
tasksys.o \
time.o \
time_util.o \
+ timerfd.o \
ucontext.o \
unlink.o \
ustat.o \
diff --git a/usr/src/lib/libc/port/mapfile-vers b/usr/src/lib/libc/port/mapfile-vers
index 017c7c31bc..a0e21e250f 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.16 { # timerfd
+ protected:
+ timerfd_create;
+ timerfd_gettime;
+ timerfd_settime;
+} ILLUMOS_0.15;
+
SYMBOL_VERSION ILLUMOS_0.15 { # epoll(3C)
protected:
epoll_create;
diff --git a/usr/src/lib/libc/port/sys/timerfd.c b/usr/src/lib/libc/port/sys/timerfd.c
new file mode 100644
index 0000000000..cb2e17adf7
--- /dev/null
+++ b/usr/src/lib/libc/port/sys/timerfd.c
@@ -0,0 +1,93 @@
+/*
+ * 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/timerfd.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <errno.h>
+#include <fcntl.h>
+
+int
+timerfd_create(int clockid, int flags)
+{
+ int oflags = O_RDWR;
+ int fd;
+
+ if (flags & ~(TFD_NONBLOCK | TFD_CLOEXEC)) {
+ errno = EINVAL;
+ return (-1);
+ }
+
+ if (flags & TFD_NONBLOCK)
+ oflags |= O_NONBLOCK;
+
+ if (flags & TFD_CLOEXEC)
+ oflags |= O_CLOEXEC;
+
+ if ((fd = open("/dev/timerfd", oflags)) < 0)
+ return (-1);
+
+ if (ioctl(fd, TIMERFDIOC_CREATE, clockid) != 0) {
+ (void) close(fd);
+ return (-1);
+ }
+
+ return (fd);
+}
+
+int
+timerfd_settime(int fd, int flags, const struct itimerspec *new_value,
+ struct itimerspec *old_value)
+{
+ timerfd_settime_t st;
+ int rval;
+
+ if (flags & ~(TFD_TIMER_ABSTIME | TFD_TIMER_CANCEL_ON_SET)) {
+ errno = EINVAL;
+ return (-1);
+ }
+
+ st.tfd_settime_flags = flags;
+ st.tfd_settime_value = (uint64_t)(uintptr_t)new_value;
+ st.tfd_settime_ovalue = (uint64_t)(uintptr_t)old_value;
+
+ rval = ioctl(fd, TIMERFDIOC_SETTIME, &st);
+
+ if (rval == -1 && errno == ENOTTY) {
+ /*
+ * Linux has us return EINVAL when the file descriptor is valid
+ * but is not a timerfd file descriptor -- and LTP explicitly
+ * checks this case.
+ */
+ errno = EINVAL;
+ }
+
+ return (rval);
+}
+
+int
+timerfd_gettime(int fd, struct itimerspec *curr_value)
+{
+ int rval = ioctl(fd, TIMERFDIOC_GETTIME, curr_value);
+
+ if (rval == -1 && errno == ENOTTY) {
+ /*
+ * See comment in timerfd_settime(), above.
+ */
+ errno = EINVAL;
+ }
+
+ return (rval);
+}
diff --git a/usr/src/lib/libc/sparc/Makefile.com b/usr/src/lib/libc/sparc/Makefile.com
index dc965fe6ac..94036d831e 100644
--- a/usr/src/lib/libc/sparc/Makefile.com
+++ b/usr/src/lib/libc/sparc/Makefile.com
@@ -983,6 +983,7 @@ PORTSYS= \
tasksys.o \
time.o \
time_util.o \
+ timerfd.o \
ucontext.o \
unlink.o \
ustat.o \
diff --git a/usr/src/lib/libc/sparcv9/Makefile.com b/usr/src/lib/libc/sparcv9/Makefile.com
index 415aaf2be2..2156bad20b 100644
--- a/usr/src/lib/libc/sparcv9/Makefile.com
+++ b/usr/src/lib/libc/sparcv9/Makefile.com
@@ -927,6 +927,7 @@ PORTSYS= \
tasksys.o \
time.o \
time_util.o \
+ timerfd.o \
ucontext.o \
unlink.o \
ustat.o \