xref: /freebsd/sys/compat/linux/linux_time.h (revision d0b2dbfa)
1 /*-
2  * Copyright (c) 2014 Bjoern A. Zeeb
3  * All rights reserved.
4  *
5  * This software was developed by SRI International and the University of
6  * Cambridge Computer Laboratory under DARPA/AFRL contract FA8750-11-C-0249
7  * ("MRC2"), as part of the DARPA MRC research programme.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  */
30 
31 #ifndef	_LINUX_TIME_H
32 #define	_LINUX_TIME_H
33 
34 #ifndef	__LINUX_ARCH_SIGEV_PREAMBLE_SIZE
35 #define	__LINUX_ARCH_SIGEV_PREAMBLE_SIZE	\
36 	(sizeof(l_int) * 2 + sizeof(l_sigval_t))
37 #endif
38 
39 #define	LINUX_SIGEV_MAX_SIZE			64
40 #define	LINUX_SIGEV_PAD_SIZE			\
41 	((LINUX_SIGEV_MAX_SIZE - __LINUX_ARCH_SIGEV_PREAMBLE_SIZE) / \
42 	sizeof(l_int))
43 
44 #define	LINUX_CLOCK_REALTIME			0
45 #define	LINUX_CLOCK_MONOTONIC			1
46 #define	LINUX_CLOCK_PROCESS_CPUTIME_ID		2
47 #define	LINUX_CLOCK_THREAD_CPUTIME_ID		3
48 #define	LINUX_CLOCK_MONOTONIC_RAW		4
49 #define	LINUX_CLOCK_REALTIME_COARSE		5
50 #define	LINUX_CLOCK_MONOTONIC_COARSE		6
51 #define	LINUX_CLOCK_BOOTTIME			7
52 #define	LINUX_CLOCK_REALTIME_ALARM		8
53 #define	LINUX_CLOCK_BOOTTIME_ALARM		9
54 #define	LINUX_CLOCK_SGI_CYCLE			10
55 #define	LINUX_CLOCK_TAI				11
56 
57 #define	LINUX_CPUCLOCK_PERTHREAD_MASK		4
58 #define	LINUX_CPUCLOCK_MASK			3
59 #define	LINUX_CPUCLOCK_WHICH(clock)		\
60 	((clock) & (clockid_t) LINUX_CPUCLOCK_MASK)
61 #define	LINUX_CPUCLOCK_PROF			0
62 #define	LINUX_CPUCLOCK_VIRT			1
63 #define	LINUX_CPUCLOCK_SCHED			2
64 #define	LINUX_CPUCLOCK_MAX			3
65 #define	LINUX_CLOCKFD				LINUX_CPUCLOCK_MAX
66 #define	LINUX_CLOCKFD_MASK			\
67 	(LINUX_CPUCLOCK_PERTHREAD_MASK|LINUX_CPUCLOCK_MASK)
68 
69 #define	LINUX_CPUCLOCK_ID(clock)		((pid_t) ~((clock) >> 3))
70 #define	LINUX_CPUCLOCK_PERTHREAD(clock)		\
71 	(((clock) & (clockid_t) LINUX_CPUCLOCK_PERTHREAD_MASK) != 0)
72 
73 #define	LINUX_TIMER_ABSTIME			0x01
74 
75 #define	L_SIGEV_SIGNAL				0
76 #define	L_SIGEV_NONE				1
77 #define	L_SIGEV_THREAD				2
78 #define	L_SIGEV_THREAD_ID			4
79 
80 struct l_sigevent {
81 	l_sigval_t sigev_value;
82 	l_int sigev_signo;
83 	l_int sigev_notify;
84 	union {
85 		l_int _pad[LINUX_SIGEV_PAD_SIZE];
86 		l_int _tid;
87 		struct {
88 			l_uintptr_t _function;
89 			l_uintptr_t _attribute;
90 		} _l_sigev_thread;
91 	} _l_sigev_un;
92 }
93 #if defined(__amd64__) && defined(COMPAT_LINUX32)
94 __packed
95 #endif
96 ;
97 
98 struct l_itimerspec {
99 	struct l_timespec it_interval;
100 	struct l_timespec it_value;
101 };
102 
103 #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
104 struct l_itimerspec64 {
105 	struct l_timespec64 it_interval;
106 	struct l_timespec64 it_value;
107 };
108 #endif
109 
110 int native_to_linux_timespec(struct l_timespec *,
111 				     struct timespec *);
112 int linux_to_native_timespec(struct timespec *,
113 				     struct l_timespec *);
114 int linux_put_timespec(struct timespec *,
115 				     struct l_timespec *);
116 int linux_get_timespec(struct timespec *,
117 				     const struct l_timespec *);
118 #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
119 int native_to_linux_timespec64(struct l_timespec64 *,
120 				     struct timespec *);
121 int linux_to_native_timespec64(struct timespec *,
122 				     struct l_timespec64 *);
123 int linux_put_timespec64(struct timespec *,
124 				     struct l_timespec64 *);
125 int linux_get_timespec64(struct timespec *,
126 				    const  struct l_timespec64 *);
127 #endif
128 int linux_to_native_clockid(clockid_t *, clockid_t);
129 int native_to_linux_itimerspec(struct l_itimerspec *,
130 				     struct itimerspec *);
131 int linux_to_native_itimerspec(struct itimerspec *,
132 				     struct l_itimerspec *);
133 #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
134 int native_to_linux_itimerspec64(struct l_itimerspec64 *,
135 				     struct itimerspec *);
136 int linux_to_native_itimerspec64(struct itimerspec *,
137 				     struct l_itimerspec64 *);
138 #endif
139 
140 int linux_to_native_timerflags(int *, int);
141 
142 #endif	/* _LINUX_TIME_H */
143