linux_time.c (1a0fda2b547365c9453523592a445dfe21266d4b) linux_time.c (19e252baebe7a7466b33c27560420b7d95fe294d)
1/* $NetBSD: linux_time.c,v 1.14 2006/05/14 03:40:54 christos Exp $ */
2
3/*-
4 * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Emmanuel Dreyfus.

--- 22 unchanged lines hidden (view full) ---

31
32#include <sys/cdefs.h>
33__FBSDID("$FreeBSD$");
34#if 0
35__KERNEL_RCSID(0, "$NetBSD: linux_time.c,v 1.14 2006/05/14 03:40:54 christos Exp $");
36#endif
37
38#include "opt_compat.h"
1/* $NetBSD: linux_time.c,v 1.14 2006/05/14 03:40:54 christos Exp $ */
2
3/*-
4 * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Emmanuel Dreyfus.

--- 22 unchanged lines hidden (view full) ---

31
32#include <sys/cdefs.h>
33__FBSDID("$FreeBSD$");
34#if 0
35__KERNEL_RCSID(0, "$NetBSD: linux_time.c,v 1.14 2006/05/14 03:40:54 christos Exp $");
36#endif
37
38#include "opt_compat.h"
39#include "opt_kdtrace.h"
39
40#include <sys/param.h>
40
41#include <sys/param.h>
42#include <sys/kernel.h>
41#include <sys/ucred.h>
42#include <sys/mount.h>
43#include <sys/ucred.h>
44#include <sys/mount.h>
45#include <sys/sdt.h>
43#include <sys/signal.h>
44#include <sys/stdint.h>
45#include <sys/syscallsubr.h>
46#include <sys/sysproto.h>
47#include <sys/time.h>
48#include <sys/systm.h>
49#include <sys/proc.h>
50
51#ifdef COMPAT_LINUX32
52#include <machine/../linux32/linux.h>
53#include <machine/../linux32/linux32_proto.h>
54#else
55#include <machine/../linux/linux.h>
56#include <machine/../linux/linux_proto.h>
57#endif
58
46#include <sys/signal.h>
47#include <sys/stdint.h>
48#include <sys/syscallsubr.h>
49#include <sys/sysproto.h>
50#include <sys/time.h>
51#include <sys/systm.h>
52#include <sys/proc.h>
53
54#ifdef COMPAT_LINUX32
55#include <machine/../linux32/linux.h>
56#include <machine/../linux32/linux32_proto.h>
57#else
58#include <machine/../linux/linux.h>
59#include <machine/../linux/linux_proto.h>
60#endif
61
62#include <compat/linux/linux_dtrace.h>
63
64/* DTrace init */
65LIN_SDT_PROVIDER_DECLARE(LINUX_DTRACE);
66
67/**
68 * DTrace probes in this module.
69 */
70LIN_SDT_PROBE_DEFINE2(time, native_to_linux_timespec, entry,
71 "struct l_timespec *", "struct timespec *");
72LIN_SDT_PROBE_DEFINE0(time, native_to_linux_timespec, return);
73LIN_SDT_PROBE_DEFINE2(time, linux_to_native_timespec, entry,
74 "struct timespec *", "struct l_timespec *");
75LIN_SDT_PROBE_DEFINE1(time, linux_to_native_timespec, return, "int");
76LIN_SDT_PROBE_DEFINE2(time, linux_to_native_clockid, entry, "clockid_t *",
77 "clockid_t");
78LIN_SDT_PROBE_DEFINE1(time, linux_to_native_clockid, unsupported_clockid,
79 "clockid_t");
80LIN_SDT_PROBE_DEFINE1(time, linux_to_native_clockid, unknown_clockid,
81 "clockid_t");
82LIN_SDT_PROBE_DEFINE1(time, linux_to_native_clockid, return, "int");
83LIN_SDT_PROBE_DEFINE2(time, linux_clock_gettime, entry, "clockid_t",
84 "struct l_timespec *");
85LIN_SDT_PROBE_DEFINE1(time, linux_clock_gettime, conversion_error, "int");
86LIN_SDT_PROBE_DEFINE1(time, linux_clock_gettime, gettime_error, "int");
87LIN_SDT_PROBE_DEFINE1(time, linux_clock_gettime, copyout_error, "int");
88LIN_SDT_PROBE_DEFINE1(time, linux_clock_gettime, return, "int");
89LIN_SDT_PROBE_DEFINE2(time, linux_clock_settime, entry, "clockid_t",
90 "struct l_timespec *");
91LIN_SDT_PROBE_DEFINE1(time, linux_clock_settime, conversion_error, "int");
92LIN_SDT_PROBE_DEFINE1(time, linux_clock_settime, settime_error, "int");
93LIN_SDT_PROBE_DEFINE1(time, linux_clock_settime, copyin_error, "int");
94LIN_SDT_PROBE_DEFINE1(time, linux_clock_settime, return, "int");
95LIN_SDT_PROBE_DEFINE2(time, linux_clock_getres, entry, "clockid_t",
96 "struct l_timespec *");
97LIN_SDT_PROBE_DEFINE0(time, linux_clock_getres, nullcall);
98LIN_SDT_PROBE_DEFINE1(time, linux_clock_getres, conversion_error, "int");
99LIN_SDT_PROBE_DEFINE1(time, linux_clock_getres, getres_error, "int");
100LIN_SDT_PROBE_DEFINE1(time, linux_clock_getres, copyout_error, "int");
101LIN_SDT_PROBE_DEFINE1(time, linux_clock_getres, return, "int");
102LIN_SDT_PROBE_DEFINE2(time, linux_nanosleep, entry, "const struct l_timespec *",
103 "struct l_timespec *");
104LIN_SDT_PROBE_DEFINE1(time, linux_nanosleep, conversion_error, "int");
105LIN_SDT_PROBE_DEFINE1(time, linux_nanosleep, nanosleep_error, "int");
106LIN_SDT_PROBE_DEFINE1(time, linux_nanosleep, copyout_error, "int");
107LIN_SDT_PROBE_DEFINE1(time, linux_nanosleep, copyin_error, "int");
108LIN_SDT_PROBE_DEFINE1(time, linux_nanosleep, return, "int");
109LIN_SDT_PROBE_DEFINE4(time, linux_clock_nanosleep, entry, "clockid_t", "int",
110 "struct l_timespec *", "struct l_timespec *");
111LIN_SDT_PROBE_DEFINE1(time, linux_clock_nanosleep, conversion_error, "int");
112LIN_SDT_PROBE_DEFINE1(time, linux_clock_nanosleep, nanosleep_error, "int");
113LIN_SDT_PROBE_DEFINE1(time, linux_clock_nanosleep, copyout_error, "int");
114LIN_SDT_PROBE_DEFINE1(time, linux_clock_nanosleep, copyin_error, "int");
115LIN_SDT_PROBE_DEFINE1(time, linux_clock_nanosleep, unsupported_flags, "int");
116LIN_SDT_PROBE_DEFINE1(time, linux_clock_nanosleep, unsupported_clockid, "int");
117LIN_SDT_PROBE_DEFINE1(time, linux_clock_nanosleep, return, "int");
118
59static void native_to_linux_timespec(struct l_timespec *,
60 struct timespec *);
61static int linux_to_native_timespec(struct timespec *,
62 struct l_timespec *);
63static int linux_to_native_clockid(clockid_t *, clockid_t);
64
65static void
66native_to_linux_timespec(struct l_timespec *ltp, struct timespec *ntp)
67{
119static void native_to_linux_timespec(struct l_timespec *,
120 struct timespec *);
121static int linux_to_native_timespec(struct timespec *,
122 struct l_timespec *);
123static int linux_to_native_clockid(clockid_t *, clockid_t);
124
125static void
126native_to_linux_timespec(struct l_timespec *ltp, struct timespec *ntp)
127{
128
129 LIN_SDT_PROBE2(time, native_to_linux_timespec, entry, ltp, ntp);
130
68 ltp->tv_sec = ntp->tv_sec;
69 ltp->tv_nsec = ntp->tv_nsec;
131 ltp->tv_sec = ntp->tv_sec;
132 ltp->tv_nsec = ntp->tv_nsec;
133
134 LIN_SDT_PROBE0(time, native_to_linux_timespec, return);
70}
71
72static int
73linux_to_native_timespec(struct timespec *ntp, struct l_timespec *ltp)
74{
135}
136
137static int
138linux_to_native_timespec(struct timespec *ntp, struct l_timespec *ltp)
139{
75 if (ltp->tv_sec < 0 || ltp->tv_nsec > (l_long)999999999L)
140
141 LIN_SDT_PROBE2(time, linux_to_native_timespec, entry, ntp, ltp);
142
143 if (ltp->tv_sec < 0 || ltp->tv_nsec > (l_long)999999999L) {
144 LIN_SDT_PROBE1(time, linux_to_native_timespec, return, EINVAL);
76 return (EINVAL);
145 return (EINVAL);
146 }
77 ntp->tv_sec = ltp->tv_sec;
78 ntp->tv_nsec = ltp->tv_nsec;
79
147 ntp->tv_sec = ltp->tv_sec;
148 ntp->tv_nsec = ltp->tv_nsec;
149
150 LIN_SDT_PROBE1(time, linux_to_native_timespec, return, 0);
80 return (0);
81}
82
83static int
84linux_to_native_clockid(clockid_t *n, clockid_t l)
85{
151 return (0);
152}
153
154static int
155linux_to_native_clockid(clockid_t *n, clockid_t l)
156{
157
158 LIN_SDT_PROBE2(time, linux_to_native_clockid, entry, n, l);
159
86 switch (l) {
87 case LINUX_CLOCK_REALTIME:
88 *n = CLOCK_REALTIME;
89 break;
90 case LINUX_CLOCK_MONOTONIC:
91 *n = CLOCK_MONOTONIC;
92 break;
93 case LINUX_CLOCK_PROCESS_CPUTIME_ID:
94 case LINUX_CLOCK_THREAD_CPUTIME_ID:
95 case LINUX_CLOCK_REALTIME_HR:
96 case LINUX_CLOCK_MONOTONIC_HR:
160 switch (l) {
161 case LINUX_CLOCK_REALTIME:
162 *n = CLOCK_REALTIME;
163 break;
164 case LINUX_CLOCK_MONOTONIC:
165 *n = CLOCK_MONOTONIC;
166 break;
167 case LINUX_CLOCK_PROCESS_CPUTIME_ID:
168 case LINUX_CLOCK_THREAD_CPUTIME_ID:
169 case LINUX_CLOCK_REALTIME_HR:
170 case LINUX_CLOCK_MONOTONIC_HR:
171 LIN_SDT_PROBE1(time, linux_to_native_clockid,
172 unsupported_clockid, l);
173 LIN_SDT_PROBE1(time, linux_to_native_clockid, return, EINVAL);
174 return (EINVAL);
175 break;
97 default:
176 default:
177 LIN_SDT_PROBE1(time, linux_to_native_clockid,
178 unknown_clockid, l);
179 LIN_SDT_PROBE1(time, linux_to_native_clockid, return, EINVAL);
98 return (EINVAL);
99 break;
100 }
101
180 return (EINVAL);
181 break;
182 }
183
184 LIN_SDT_PROBE1(time, linux_to_native_clockid, return, 0);
102 return (0);
103}
104
105int
106linux_clock_gettime(struct thread *td, struct linux_clock_gettime_args *args)
107{
108 struct l_timespec lts;
109 int error;
110 clockid_t nwhich = 0; /* XXX: GCC */
111 struct timespec tp;
112
185 return (0);
186}
187
188int
189linux_clock_gettime(struct thread *td, struct linux_clock_gettime_args *args)
190{
191 struct l_timespec lts;
192 int error;
193 clockid_t nwhich = 0; /* XXX: GCC */
194 struct timespec tp;
195
196 LIN_SDT_PROBE2(time, linux_clock_gettime, entry, args->which, args->tp);
197
113 error = linux_to_native_clockid(&nwhich, args->which);
198 error = linux_to_native_clockid(&nwhich, args->which);
114 if (error != 0)
199 if (error != 0) {
200 LIN_SDT_PROBE1(time, linux_clock_gettime, conversion_error,
201 error);
202 LIN_SDT_PROBE1(time, linux_clock_gettime, return, error);
115 return (error);
203 return (error);
204 }
116 error = kern_clock_gettime(td, nwhich, &tp);
205 error = kern_clock_gettime(td, nwhich, &tp);
117 if (error != 0)
206 if (error != 0) {
207 LIN_SDT_PROBE1(time, linux_clock_gettime, gettime_error, error);
208 LIN_SDT_PROBE1(time, linux_clock_gettime, return, error);
118 return (error);
209 return (error);
210 }
119 native_to_linux_timespec(&lts, &tp);
120
211 native_to_linux_timespec(&lts, &tp);
212
121 return (copyout(&lts, args->tp, sizeof lts));
213 error = copyout(&lts, args->tp, sizeof lts);
214 if (error != 0)
215 LIN_SDT_PROBE1(time, linux_clock_gettime, copyout_error, error);
216
217 LIN_SDT_PROBE1(time, linux_clock_gettime, return, error);
218 return (error);
122}
123
124int
125linux_clock_settime(struct thread *td, struct linux_clock_settime_args *args)
126{
127 struct timespec ts;
128 struct l_timespec lts;
129 int error;
130 clockid_t nwhich = 0; /* XXX: GCC */
131
219}
220
221int
222linux_clock_settime(struct thread *td, struct linux_clock_settime_args *args)
223{
224 struct timespec ts;
225 struct l_timespec lts;
226 int error;
227 clockid_t nwhich = 0; /* XXX: GCC */
228
229 LIN_SDT_PROBE2(time, linux_clock_settime, entry, args->which, args->tp);
230
132 error = linux_to_native_clockid(&nwhich, args->which);
231 error = linux_to_native_clockid(&nwhich, args->which);
133 if (error != 0)
232 if (error != 0) {
233 LIN_SDT_PROBE1(time, linux_clock_settime, conversion_error,
234 error);
235 LIN_SDT_PROBE1(time, linux_clock_settime, return, error);
134 return (error);
236 return (error);
237 }
135 error = copyin(args->tp, &lts, sizeof lts);
238 error = copyin(args->tp, &lts, sizeof lts);
136 if (error != 0)
239 if (error != 0) {
240 LIN_SDT_PROBE1(time, linux_clock_settime, copyin_error, error);
241 LIN_SDT_PROBE1(time, linux_clock_settime, return, error);
137 return (error);
242 return (error);
243 }
138 error = linux_to_native_timespec(&ts, &lts);
244 error = linux_to_native_timespec(&ts, &lts);
139 if (error != 0)
245 if (error != 0) {
246 LIN_SDT_PROBE1(time, linux_clock_settime, conversion_error,
247 error);
248 LIN_SDT_PROBE1(time, linux_clock_settime, return, error);
140 return (error);
249 return (error);
250 }
141
251
142 return (kern_clock_settime(td, nwhich, &ts));
252 error = kern_clock_settime(td, nwhich, &ts);
253 if (error != 0)
254 LIN_SDT_PROBE1(time, linux_clock_settime, settime_error, error);
255
256 LIN_SDT_PROBE1(time, linux_clock_settime, return, error);
257 return (error);
143}
144
145int
146linux_clock_getres(struct thread *td, struct linux_clock_getres_args *args)
147{
148 struct timespec ts;
149 struct l_timespec lts;
150 int error;
151 clockid_t nwhich = 0; /* XXX: GCC */
152
258}
259
260int
261linux_clock_getres(struct thread *td, struct linux_clock_getres_args *args)
262{
263 struct timespec ts;
264 struct l_timespec lts;
265 int error;
266 clockid_t nwhich = 0; /* XXX: GCC */
267
153 if (args->tp == NULL)
268 LIN_SDT_PROBE2(time, linux_clock_getres, entry, args->which, args->tp);
269
270 if (args->tp == NULL) {
271 LIN_SDT_PROBE0(time, linux_clock_getres, nullcall);
272 LIN_SDT_PROBE1(time, linux_clock_getres, return, 0);
154 return (0);
273 return (0);
274 }
155
156 error = linux_to_native_clockid(&nwhich, args->which);
275
276 error = linux_to_native_clockid(&nwhich, args->which);
157 if (error != 0)
277 if (error != 0) {
278 LIN_SDT_PROBE1(time, linux_clock_getres, conversion_error,
279 error);
280 LIN_SDT_PROBE1(time, linux_clock_getres, return, error);
158 return (error);
281 return (error);
282 }
159 error = kern_clock_getres(td, nwhich, &ts);
283 error = kern_clock_getres(td, nwhich, &ts);
160 if (error != 0)
284 if (error != 0) {
285 LIN_SDT_PROBE1(time, linux_clock_getres, getres_error, error);
286 LIN_SDT_PROBE1(time, linux_clock_getres, return, error);
161 return (error);
287 return (error);
288 }
162 native_to_linux_timespec(&lts, &ts);
163
289 native_to_linux_timespec(&lts, &ts);
290
164 return (copyout(&lts, args->tp, sizeof lts));
291 error = copyout(&lts, args->tp, sizeof lts);
292 if (error != 0)
293 LIN_SDT_PROBE1(time, linux_clock_getres, copyout_error, error);
294
295 LIN_SDT_PROBE1(time, linux_clock_getres, return, error);
296 return (error);
165}
166
167int
168linux_nanosleep(struct thread *td, struct linux_nanosleep_args *args)
169{
170 struct timespec *rmtp;
171 struct l_timespec lrqts, lrmts;
172 struct timespec rqts, rmts;
173 int error;
174
297}
298
299int
300linux_nanosleep(struct thread *td, struct linux_nanosleep_args *args)
301{
302 struct timespec *rmtp;
303 struct l_timespec lrqts, lrmts;
304 struct timespec rqts, rmts;
305 int error;
306
307 LIN_SDT_PROBE2(time, linux_nanosleep, entry, args->rqtp, args->rmtp);
308
175 error = copyin(args->rqtp, &lrqts, sizeof lrqts);
309 error = copyin(args->rqtp, &lrqts, sizeof lrqts);
176 if (error != 0)
310 if (error != 0) {
311 LIN_SDT_PROBE1(time, linux_nanosleep, copyin_error, error);
312 LIN_SDT_PROBE1(time, linux_nanosleep, return, error);
177 return (error);
313 return (error);
314 }
178
179 if (args->rmtp != NULL)
180 rmtp = &rmts;
181 else
182 rmtp = NULL;
183
184 error = linux_to_native_timespec(&rqts, &lrqts);
315
316 if (args->rmtp != NULL)
317 rmtp = &rmts;
318 else
319 rmtp = NULL;
320
321 error = linux_to_native_timespec(&rqts, &lrqts);
185 if (error != 0)
322 if (error != 0) {
323 LIN_SDT_PROBE1(time, linux_nanosleep, conversion_error, error);
324 LIN_SDT_PROBE1(time, linux_nanosleep, return, error);
186 return (error);
325 return (error);
326 }
187 error = kern_nanosleep(td, &rqts, rmtp);
327 error = kern_nanosleep(td, &rqts, rmtp);
188 if (error != 0)
328 if (error != 0) {
329 LIN_SDT_PROBE1(time, linux_nanosleep, nanosleep_error, error);
330 LIN_SDT_PROBE1(time, linux_nanosleep, return, error);
189 return (error);
331 return (error);
332 }
190
191 if (args->rmtp != NULL) {
192 native_to_linux_timespec(&lrmts, rmtp);
193 error = copyout(&lrmts, args->rmtp, sizeof(lrmts));
333
334 if (args->rmtp != NULL) {
335 native_to_linux_timespec(&lrmts, rmtp);
336 error = copyout(&lrmts, args->rmtp, sizeof(lrmts));
194 if (error != 0)
337 if (error != 0) {
338 LIN_SDT_PROBE1(time, linux_nanosleep, copyout_error,
339 error);
340 LIN_SDT_PROBE1(time, linux_nanosleep, return, error);
195 return (error);
341 return (error);
342 }
196 }
197
343 }
344
345 LIN_SDT_PROBE1(time, linux_nanosleep, return, 0);
198 return (0);
199}
200
201int
202linux_clock_nanosleep(struct thread *td, struct linux_clock_nanosleep_args *args)
203{
204 struct timespec *rmtp;
205 struct l_timespec lrqts, lrmts;
206 struct timespec rqts, rmts;
207 int error;
208
346 return (0);
347}
348
349int
350linux_clock_nanosleep(struct thread *td, struct linux_clock_nanosleep_args *args)
351{
352 struct timespec *rmtp;
353 struct l_timespec lrqts, lrmts;
354 struct timespec rqts, rmts;
355 int error;
356
209 if (args->flags != 0)
357 LIN_SDT_PROBE4(time, linux_clock_nanosleep, entry, args->which,
358 args->flags, args->rqtp, args->rmtp);
359
360 if (args->flags != 0) {
361 /* XXX deal with TIMER_ABSTIME */
362 LIN_SDT_PROBE1(time, linux_clock_nanosleep, unsupported_flags,
363 args->flags);
364 LIN_SDT_PROBE1(time, linux_clock_nanosleep, return, EINVAL);
210 return (EINVAL); /* XXX deal with TIMER_ABSTIME */
365 return (EINVAL); /* XXX deal with TIMER_ABSTIME */
366 }
211
367
212 if (args->which != LINUX_CLOCK_REALTIME)
368 if (args->which != LINUX_CLOCK_REALTIME) {
369 LIN_SDT_PROBE1(time, linux_clock_nanosleep, unsupported_clockid,
370 args->which);
371 LIN_SDT_PROBE1(time, linux_clock_nanosleep, return, EINVAL);
213 return (EINVAL);
372 return (EINVAL);
373 }
214
215 error = copyin(args->rqtp, &lrqts, sizeof lrqts);
374
375 error = copyin(args->rqtp, &lrqts, sizeof lrqts);
216 if (error != 0)
376 if (error != 0) {
377 LIN_SDT_PROBE1(time, linux_clock_nanosleep, copyin_error,
378 error);
379 LIN_SDT_PROBE1(time, linux_clock_nanosleep, return, error);
217 return (error);
380 return (error);
381 }
218
219 if (args->rmtp != NULL)
220 rmtp = &rmts;
221 else
222 rmtp = NULL;
223
224 error = linux_to_native_timespec(&rqts, &lrqts);
382
383 if (args->rmtp != NULL)
384 rmtp = &rmts;
385 else
386 rmtp = NULL;
387
388 error = linux_to_native_timespec(&rqts, &lrqts);
225 if (error != 0)
389 if (error != 0) {
390 LIN_SDT_PROBE1(time, linux_clock_nanosleep, conversion_error,
391 error);
392 LIN_SDT_PROBE1(time, linux_clock_nanosleep, return, error);
226 return (error);
393 return (error);
394 }
227 error = kern_nanosleep(td, &rqts, rmtp);
395 error = kern_nanosleep(td, &rqts, rmtp);
228 if (error != 0)
396 if (error != 0) {
397 LIN_SDT_PROBE1(time, linux_clock_nanosleep, nanosleep_error,
398 error);
399 LIN_SDT_PROBE1(time, linux_clock_nanosleep, return, error);
229 return (error);
400 return (error);
401 }
230
231 if (args->rmtp != NULL) {
232 native_to_linux_timespec(&lrmts, rmtp);
233 error = copyout(&lrmts, args->rmtp, sizeof lrmts );
402
403 if (args->rmtp != NULL) {
404 native_to_linux_timespec(&lrmts, rmtp);
405 error = copyout(&lrmts, args->rmtp, sizeof lrmts );
234 if (error != 0)
406 if (error != 0) {
407 LIN_SDT_PROBE1(time, linux_clock_nanosleep,
408 copyout_error, error);
409 LIN_SDT_PROBE1(time, linux_nanosleep, return, error);
235 return (error);
410 return (error);
411 }
236 }
237
412 }
413
414 LIN_SDT_PROBE1(time, linux_clock_nanosleep, return, 0);
238 return (0);
239}
415 return (0);
416}