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