.. | .. |
---|
10 | 10 | */ |
---|
11 | 11 | |
---|
12 | 12 | #include <linux/time64.h> |
---|
13 | | - |
---|
14 | 13 | #include <linux/timex.h> |
---|
15 | 14 | |
---|
16 | 15 | #include <vdso/time32.h> |
---|
17 | 16 | |
---|
18 | | -#define TIME_T_MAX (time_t)((1UL << ((sizeof(time_t) << 3) - 1)) - 1) |
---|
| 17 | +struct old_itimerspec32 { |
---|
| 18 | + struct old_timespec32 it_interval; |
---|
| 19 | + struct old_timespec32 it_value; |
---|
| 20 | +}; |
---|
19 | 21 | |
---|
20 | | -#if __BITS_PER_LONG == 64 |
---|
| 22 | +struct old_utimbuf32 { |
---|
| 23 | + old_time32_t actime; |
---|
| 24 | + old_time32_t modtime; |
---|
| 25 | +}; |
---|
21 | 26 | |
---|
22 | | -/* timespec64 is defined as timespec here */ |
---|
23 | | -static inline struct timespec timespec64_to_timespec(const struct timespec64 ts64) |
---|
24 | | -{ |
---|
25 | | - return *(const struct timespec *)&ts64; |
---|
26 | | -} |
---|
| 27 | +struct old_timex32 { |
---|
| 28 | + u32 modes; |
---|
| 29 | + s32 offset; |
---|
| 30 | + s32 freq; |
---|
| 31 | + s32 maxerror; |
---|
| 32 | + s32 esterror; |
---|
| 33 | + s32 status; |
---|
| 34 | + s32 constant; |
---|
| 35 | + s32 precision; |
---|
| 36 | + s32 tolerance; |
---|
| 37 | + struct old_timeval32 time; |
---|
| 38 | + s32 tick; |
---|
| 39 | + s32 ppsfreq; |
---|
| 40 | + s32 jitter; |
---|
| 41 | + s32 shift; |
---|
| 42 | + s32 stabil; |
---|
| 43 | + s32 jitcnt; |
---|
| 44 | + s32 calcnt; |
---|
| 45 | + s32 errcnt; |
---|
| 46 | + s32 stbcnt; |
---|
| 47 | + s32 tai; |
---|
27 | 48 | |
---|
28 | | -static inline struct timespec64 timespec_to_timespec64(const struct timespec ts) |
---|
29 | | -{ |
---|
30 | | - return *(const struct timespec64 *)&ts; |
---|
31 | | -} |
---|
| 49 | + s32:32; s32:32; s32:32; s32:32; |
---|
| 50 | + s32:32; s32:32; s32:32; s32:32; |
---|
| 51 | + s32:32; s32:32; s32:32; |
---|
| 52 | +}; |
---|
32 | 53 | |
---|
33 | | -#else |
---|
34 | | -static inline struct timespec timespec64_to_timespec(const struct timespec64 ts64) |
---|
35 | | -{ |
---|
36 | | - struct timespec ret; |
---|
37 | | - |
---|
38 | | - ret.tv_sec = (time_t)ts64.tv_sec; |
---|
39 | | - ret.tv_nsec = ts64.tv_nsec; |
---|
40 | | - return ret; |
---|
41 | | -} |
---|
42 | | - |
---|
43 | | -static inline struct timespec64 timespec_to_timespec64(const struct timespec ts) |
---|
44 | | -{ |
---|
45 | | - struct timespec64 ret; |
---|
46 | | - |
---|
47 | | - ret.tv_sec = ts.tv_sec; |
---|
48 | | - ret.tv_nsec = ts.tv_nsec; |
---|
49 | | - return ret; |
---|
50 | | -} |
---|
51 | | -#endif |
---|
52 | | - |
---|
53 | | -static inline int timespec_equal(const struct timespec *a, |
---|
54 | | - const struct timespec *b) |
---|
55 | | -{ |
---|
56 | | - return (a->tv_sec == b->tv_sec) && (a->tv_nsec == b->tv_nsec); |
---|
57 | | -} |
---|
58 | | - |
---|
59 | | -/* |
---|
60 | | - * lhs < rhs: return <0 |
---|
61 | | - * lhs == rhs: return 0 |
---|
62 | | - * lhs > rhs: return >0 |
---|
63 | | - */ |
---|
64 | | -static inline int timespec_compare(const struct timespec *lhs, const struct timespec *rhs) |
---|
65 | | -{ |
---|
66 | | - if (lhs->tv_sec < rhs->tv_sec) |
---|
67 | | - return -1; |
---|
68 | | - if (lhs->tv_sec > rhs->tv_sec) |
---|
69 | | - return 1; |
---|
70 | | - return lhs->tv_nsec - rhs->tv_nsec; |
---|
71 | | -} |
---|
72 | | - |
---|
73 | | -extern void set_normalized_timespec(struct timespec *ts, time_t sec, s64 nsec); |
---|
74 | | - |
---|
75 | | -static inline struct timespec timespec_add(struct timespec lhs, |
---|
76 | | - struct timespec rhs) |
---|
77 | | -{ |
---|
78 | | - struct timespec ts_delta; |
---|
79 | | - |
---|
80 | | - set_normalized_timespec(&ts_delta, lhs.tv_sec + rhs.tv_sec, |
---|
81 | | - lhs.tv_nsec + rhs.tv_nsec); |
---|
82 | | - return ts_delta; |
---|
83 | | -} |
---|
84 | | - |
---|
85 | | -/* |
---|
86 | | - * sub = lhs - rhs, in normalized form |
---|
87 | | - */ |
---|
88 | | -static inline struct timespec timespec_sub(struct timespec lhs, |
---|
89 | | - struct timespec rhs) |
---|
90 | | -{ |
---|
91 | | - struct timespec ts_delta; |
---|
92 | | - |
---|
93 | | - set_normalized_timespec(&ts_delta, lhs.tv_sec - rhs.tv_sec, |
---|
94 | | - lhs.tv_nsec - rhs.tv_nsec); |
---|
95 | | - return ts_delta; |
---|
96 | | -} |
---|
97 | | - |
---|
98 | | -/* |
---|
99 | | - * Returns true if the timespec is norm, false if denorm: |
---|
100 | | - */ |
---|
101 | | -static inline bool timespec_valid(const struct timespec *ts) |
---|
102 | | -{ |
---|
103 | | - /* Dates before 1970 are bogus */ |
---|
104 | | - if (ts->tv_sec < 0) |
---|
105 | | - return false; |
---|
106 | | - /* Can't have more nanoseconds then a second */ |
---|
107 | | - if ((unsigned long)ts->tv_nsec >= NSEC_PER_SEC) |
---|
108 | | - return false; |
---|
109 | | - return true; |
---|
110 | | -} |
---|
111 | | - |
---|
112 | | -static inline bool timespec_valid_strict(const struct timespec *ts) |
---|
113 | | -{ |
---|
114 | | - if (!timespec_valid(ts)) |
---|
115 | | - return false; |
---|
116 | | - /* Disallow values that could overflow ktime_t */ |
---|
117 | | - if ((unsigned long long)ts->tv_sec >= KTIME_SEC_MAX) |
---|
118 | | - return false; |
---|
119 | | - return true; |
---|
120 | | -} |
---|
| 54 | +extern int get_old_timespec32(struct timespec64 *, const void __user *); |
---|
| 55 | +extern int put_old_timespec32(const struct timespec64 *, void __user *); |
---|
| 56 | +extern int get_old_itimerspec32(struct itimerspec64 *its, |
---|
| 57 | + const struct old_itimerspec32 __user *uits); |
---|
| 58 | +extern int put_old_itimerspec32(const struct itimerspec64 *its, |
---|
| 59 | + struct old_itimerspec32 __user *uits); |
---|
| 60 | +struct __kernel_timex; |
---|
| 61 | +int get_old_timex32(struct __kernel_timex *, const struct old_timex32 __user *); |
---|
| 62 | +int put_old_timex32(struct old_timex32 __user *, const struct __kernel_timex *); |
---|
121 | 63 | |
---|
122 | 64 | /** |
---|
123 | | - * timespec_to_ns - Convert timespec to nanoseconds |
---|
124 | | - * @ts: pointer to the timespec variable to be converted |
---|
125 | | - * |
---|
126 | | - * Returns the scalar nanosecond representation of the timespec |
---|
127 | | - * parameter. |
---|
128 | | - */ |
---|
129 | | -static inline s64 timespec_to_ns(const struct timespec *ts) |
---|
130 | | -{ |
---|
131 | | - return ((s64) ts->tv_sec * NSEC_PER_SEC) + ts->tv_nsec; |
---|
132 | | -} |
---|
133 | | - |
---|
134 | | -/** |
---|
135 | | - * ns_to_timespec - Convert nanoseconds to timespec |
---|
136 | | - * @nsec: the nanoseconds value to be converted |
---|
137 | | - * |
---|
138 | | - * Returns the timespec representation of the nsec parameter. |
---|
139 | | - */ |
---|
140 | | -extern struct timespec ns_to_timespec(const s64 nsec); |
---|
141 | | - |
---|
142 | | -/** |
---|
143 | | - * timespec_add_ns - Adds nanoseconds to a timespec |
---|
144 | | - * @a: pointer to timespec to be incremented |
---|
145 | | - * @ns: unsigned nanoseconds value to be added |
---|
146 | | - * |
---|
147 | | - * This must always be inlined because its used from the x86-64 vdso, |
---|
148 | | - * which cannot call other kernel functions. |
---|
149 | | - */ |
---|
150 | | -static __always_inline void timespec_add_ns(struct timespec *a, u64 ns) |
---|
151 | | -{ |
---|
152 | | - a->tv_sec += __iter_div_u64_rem(a->tv_nsec + ns, NSEC_PER_SEC, &ns); |
---|
153 | | - a->tv_nsec = ns; |
---|
154 | | -} |
---|
155 | | - |
---|
156 | | -/** |
---|
157 | | - * time_to_tm - converts the calendar time to local broken-down time |
---|
158 | | - * |
---|
159 | | - * @totalsecs the number of seconds elapsed since 00:00:00 on January 1, 1970, |
---|
160 | | - * Coordinated Universal Time (UTC). |
---|
161 | | - * @offset offset seconds adding to totalsecs. |
---|
162 | | - * @result pointer to struct tm variable to receive broken-down time |
---|
163 | | - */ |
---|
164 | | -static inline void time_to_tm(time_t totalsecs, int offset, struct tm *result) |
---|
165 | | -{ |
---|
166 | | - time64_to_tm(totalsecs, offset, result); |
---|
167 | | -} |
---|
168 | | - |
---|
169 | | -static inline unsigned long mktime(const unsigned int year, |
---|
170 | | - const unsigned int mon, const unsigned int day, |
---|
171 | | - const unsigned int hour, const unsigned int min, |
---|
172 | | - const unsigned int sec) |
---|
173 | | -{ |
---|
174 | | - return mktime64(year, mon, day, hour, min, sec); |
---|
175 | | -} |
---|
176 | | - |
---|
177 | | -static inline bool timeval_valid(const struct timeval *tv) |
---|
178 | | -{ |
---|
179 | | - /* Dates before 1970 are bogus */ |
---|
180 | | - if (tv->tv_sec < 0) |
---|
181 | | - return false; |
---|
182 | | - |
---|
183 | | - /* Can't have more microseconds then a second */ |
---|
184 | | - if (tv->tv_usec < 0 || tv->tv_usec >= USEC_PER_SEC) |
---|
185 | | - return false; |
---|
186 | | - |
---|
187 | | - return true; |
---|
188 | | -} |
---|
189 | | - |
---|
190 | | -extern struct timespec timespec_trunc(struct timespec t, unsigned int gran); |
---|
191 | | - |
---|
192 | | -/** |
---|
193 | | - * timeval_to_ns - Convert timeval to nanoseconds |
---|
194 | | - * @ts: pointer to the timeval variable to be converted |
---|
195 | | - * |
---|
196 | | - * Returns the scalar nanosecond representation of the timeval |
---|
197 | | - * parameter. |
---|
198 | | - */ |
---|
199 | | -static inline s64 timeval_to_ns(const struct timeval *tv) |
---|
200 | | -{ |
---|
201 | | - return ((s64) tv->tv_sec * NSEC_PER_SEC) + |
---|
202 | | - tv->tv_usec * NSEC_PER_USEC; |
---|
203 | | -} |
---|
204 | | - |
---|
205 | | -/** |
---|
206 | | - * ns_to_timeval - Convert nanoseconds to timeval |
---|
| 65 | + * ns_to_kernel_old_timeval - Convert nanoseconds to timeval |
---|
207 | 66 | * @nsec: the nanoseconds value to be converted |
---|
208 | 67 | * |
---|
209 | 68 | * Returns the timeval representation of the nsec parameter. |
---|
210 | 69 | */ |
---|
211 | | -extern struct timeval ns_to_timeval(const s64 nsec); |
---|
212 | 70 | extern struct __kernel_old_timeval ns_to_kernel_old_timeval(s64 nsec); |
---|
213 | | - |
---|
214 | | -/* |
---|
215 | | - * New aliases for compat time functions. These will be used to replace |
---|
216 | | - * the compat code so it can be shared between 32-bit and 64-bit builds |
---|
217 | | - * both of which provide compatibility with old 32-bit tasks. |
---|
218 | | - */ |
---|
219 | | -#define old_itimerspec32 compat_itimerspec |
---|
220 | | -#define ns_to_old_timeval32 ns_to_compat_timeval |
---|
221 | | -#define get_old_itimerspec32 get_compat_itimerspec64 |
---|
222 | | -#define put_old_itimerspec32 put_compat_itimerspec64 |
---|
223 | | -#define get_old_timespec32 compat_get_timespec64 |
---|
224 | | -#define put_old_timespec32 compat_put_timespec64 |
---|
225 | 71 | |
---|
226 | 72 | #endif |
---|