1*6a72db4aSBryan Cantrill /* 2*6a72db4aSBryan Cantrill * This file and its contents are supplied under the terms of the 3*6a72db4aSBryan Cantrill * Common Development and Distribution License ("CDDL"), version 1.0. 4*6a72db4aSBryan Cantrill * You may only use this file in accordance with the terms of version 5*6a72db4aSBryan Cantrill * 1.0 of the CDDL. 6*6a72db4aSBryan Cantrill * 7*6a72db4aSBryan Cantrill * A full copy of the text of the CDDL should have accompanied this 8*6a72db4aSBryan Cantrill * source. A copy of the CDDL is also available via the Internet at 9*6a72db4aSBryan Cantrill * http://www.illumos.org/license/CDDL. 10*6a72db4aSBryan Cantrill */ 11*6a72db4aSBryan Cantrill 12*6a72db4aSBryan Cantrill /* 13*6a72db4aSBryan Cantrill * Copyright (c) 2015 Joyent, Inc. All rights reserved. 14*6a72db4aSBryan Cantrill */ 15*6a72db4aSBryan Cantrill 16*6a72db4aSBryan Cantrill /* 17*6a72db4aSBryan Cantrill * Header file to support for the timerfd facility. 18*6a72db4aSBryan Cantrill */ 19*6a72db4aSBryan Cantrill 20*6a72db4aSBryan Cantrill #ifndef _SYS_TIMERFD_H 21*6a72db4aSBryan Cantrill #define _SYS_TIMERFD_H 22*6a72db4aSBryan Cantrill 23*6a72db4aSBryan Cantrill #include <sys/types.h> 24*6a72db4aSBryan Cantrill #include <sys/time_impl.h> 25*6a72db4aSBryan Cantrill 26*6a72db4aSBryan Cantrill #ifdef __cplusplus 27*6a72db4aSBryan Cantrill extern "C" { 28*6a72db4aSBryan Cantrill #endif 29*6a72db4aSBryan Cantrill 30*6a72db4aSBryan Cantrill /* 31*6a72db4aSBryan Cantrill * To assure binary compatibility with Linux, these values are fixed at their 32*6a72db4aSBryan Cantrill * Linux equivalents, not their native ones. 33*6a72db4aSBryan Cantrill */ 34*6a72db4aSBryan Cantrill #define TFD_CLOEXEC 02000000 /* LX_O_CLOEXEC */ 35*6a72db4aSBryan Cantrill #define TFD_NONBLOCK 04000 /* LX_O_NONBLOCK */ 36*6a72db4aSBryan Cantrill #define TFD_TIMER_ABSTIME (1 << 0) 37*6a72db4aSBryan Cantrill #define TFD_TIMER_CANCEL_ON_SET (1 << 1) 38*6a72db4aSBryan Cantrill 39*6a72db4aSBryan Cantrill /* 40*6a72db4aSBryan Cantrill * These ioctl values are specific to the native implementation; applications 41*6a72db4aSBryan Cantrill * shouldn't be using them directly, and they should therefore be safe to 42*6a72db4aSBryan Cantrill * change without breaking apps. 43*6a72db4aSBryan Cantrill */ 44*6a72db4aSBryan Cantrill #define TIMERFDIOC (('t' << 24) | ('f' << 16) | ('d' << 8)) 45*6a72db4aSBryan Cantrill #define TIMERFDIOC_CREATE (TIMERFDIOC | 1) /* create timer */ 46*6a72db4aSBryan Cantrill #define TIMERFDIOC_SETTIME (TIMERFDIOC | 2) /* timerfd_settime() */ 47*6a72db4aSBryan Cantrill #define TIMERFDIOC_GETTIME (TIMERFDIOC | 3) /* timerfd_gettime() */ 48*6a72db4aSBryan Cantrill 49*6a72db4aSBryan Cantrill typedef struct timerfd_settime { 50*6a72db4aSBryan Cantrill uint64_t tfd_settime_flags; /* flags (e.g., TFD_TIMER_ABSTIME) */ 51*6a72db4aSBryan Cantrill uint64_t tfd_settime_value; /* pointer to value */ 52*6a72db4aSBryan Cantrill uint64_t tfd_settime_ovalue; /* pointer to old value, if any */ 53*6a72db4aSBryan Cantrill } timerfd_settime_t; 54*6a72db4aSBryan Cantrill 55*6a72db4aSBryan Cantrill #ifndef _KERNEL 56*6a72db4aSBryan Cantrill 57*6a72db4aSBryan Cantrill extern int timerfd_create(int, int); 58*6a72db4aSBryan Cantrill extern int timerfd_settime(int, int, 59*6a72db4aSBryan Cantrill const struct itimerspec *, struct itimerspec *); 60*6a72db4aSBryan Cantrill extern int timerfd_gettime(int, struct itimerspec *); 61*6a72db4aSBryan Cantrill 62*6a72db4aSBryan Cantrill #else 63*6a72db4aSBryan Cantrill 64*6a72db4aSBryan Cantrill #define TIMERFDMNRN_TIMERFD 0 65*6a72db4aSBryan Cantrill #define TIMERFDMNRN_CLONE 1 66*6a72db4aSBryan Cantrill #define TIMERFD_VALMAX (ULLONG_MAX - 1ULL) 67*6a72db4aSBryan Cantrill 68*6a72db4aSBryan Cantrill /* 69*6a72db4aSBryan Cantrill * Fortunately, the values for the Linux clocks that are valid for timerfd 70*6a72db4aSBryan Cantrill * (namely, CLOCK_REALTIME and CLOCK_MONOTONIC) don't overlap with our values 71*6a72db4aSBryan Cantrill * the same. 72*6a72db4aSBryan Cantrill */ 73*6a72db4aSBryan Cantrill #define TIMERFD_MONOTONIC 1 /* Linux value for CLOCK_MONOTONIC */ 74*6a72db4aSBryan Cantrill 75*6a72db4aSBryan Cantrill #endif /* _KERNEL */ 76*6a72db4aSBryan Cantrill 77*6a72db4aSBryan Cantrill #ifdef __cplusplus 78*6a72db4aSBryan Cantrill } 79*6a72db4aSBryan Cantrill #endif 80*6a72db4aSBryan Cantrill 81*6a72db4aSBryan Cantrill #endif /* _SYS_TIMERFD_H */ 82