]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/compat/linux/linux_time.c
Print out unsupported futex operation message only once for the process.
[FreeBSD/FreeBSD.git] / sys / compat / linux / linux_time.c
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.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
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
40 #include <sys/param.h>
41 #include <sys/kernel.h>
42 #include <sys/lock.h>
43 #include <sys/ucred.h>
44 #include <sys/mount.h>
45 #include <sys/mutex.h>
46 #include <sys/resourcevar.h>
47 #include <sys/sdt.h>
48 #include <sys/signal.h>
49 #include <sys/stdint.h>
50 #include <sys/syscallsubr.h>
51 #include <sys/sysproto.h>
52 #include <sys/time.h>
53 #include <sys/systm.h>
54 #include <sys/proc.h>
55
56 #ifdef COMPAT_LINUX32
57 #include <machine/../linux32/linux.h>
58 #include <machine/../linux32/linux32_proto.h>
59 #else
60 #include <machine/../linux/linux.h>
61 #include <machine/../linux/linux_proto.h>
62 #endif
63
64 #include <compat/linux/linux_dtrace.h>
65 #include <compat/linux/linux_timer.h>
66
67 /* DTrace init */
68 LIN_SDT_PROVIDER_DECLARE(LINUX_DTRACE);
69
70 /**
71  * DTrace probes in this module.
72  */
73 LIN_SDT_PROBE_DEFINE2(time, native_to_linux_timespec, entry,
74     "struct l_timespec *", "struct timespec *");
75 LIN_SDT_PROBE_DEFINE0(time, native_to_linux_timespec, return);
76 LIN_SDT_PROBE_DEFINE2(time, linux_to_native_timespec, entry,
77     "struct timespec *", "struct l_timespec *");
78 LIN_SDT_PROBE_DEFINE1(time, linux_to_native_timespec, return, "int");
79 LIN_SDT_PROBE_DEFINE2(time, linux_to_native_clockid, entry, "clockid_t *",
80     "clockid_t");
81 LIN_SDT_PROBE_DEFINE1(time, linux_to_native_clockid, unsupported_clockid,
82     "clockid_t");
83 LIN_SDT_PROBE_DEFINE1(time, linux_to_native_clockid, unknown_clockid,
84     "clockid_t");
85 LIN_SDT_PROBE_DEFINE1(time, linux_to_native_clockid, return, "int");
86 LIN_SDT_PROBE_DEFINE2(time, linux_clock_gettime, entry, "clockid_t",
87     "struct l_timespec *");
88 LIN_SDT_PROBE_DEFINE1(time, linux_clock_gettime, conversion_error, "int");
89 LIN_SDT_PROBE_DEFINE1(time, linux_clock_gettime, gettime_error, "int");
90 LIN_SDT_PROBE_DEFINE1(time, linux_clock_gettime, copyout_error, "int");
91 LIN_SDT_PROBE_DEFINE1(time, linux_clock_gettime, return, "int");
92 LIN_SDT_PROBE_DEFINE2(time, linux_clock_settime, entry, "clockid_t",
93     "struct l_timespec *");
94 LIN_SDT_PROBE_DEFINE1(time, linux_clock_settime, conversion_error, "int");
95 LIN_SDT_PROBE_DEFINE1(time, linux_clock_settime, settime_error, "int");
96 LIN_SDT_PROBE_DEFINE1(time, linux_clock_settime, copyin_error, "int");
97 LIN_SDT_PROBE_DEFINE1(time, linux_clock_settime, return, "int");
98 LIN_SDT_PROBE_DEFINE2(time, linux_clock_getres, entry, "clockid_t",
99     "struct l_timespec *");
100 LIN_SDT_PROBE_DEFINE0(time, linux_clock_getres, nullcall);
101 LIN_SDT_PROBE_DEFINE1(time, linux_clock_getres, conversion_error, "int");
102 LIN_SDT_PROBE_DEFINE1(time, linux_clock_getres, getres_error, "int");
103 LIN_SDT_PROBE_DEFINE1(time, linux_clock_getres, copyout_error, "int");
104 LIN_SDT_PROBE_DEFINE1(time, linux_clock_getres, return, "int");
105 LIN_SDT_PROBE_DEFINE2(time, linux_nanosleep, entry, "const struct l_timespec *",
106     "struct l_timespec *");
107 LIN_SDT_PROBE_DEFINE1(time, linux_nanosleep, conversion_error, "int");
108 LIN_SDT_PROBE_DEFINE1(time, linux_nanosleep, nanosleep_error, "int");
109 LIN_SDT_PROBE_DEFINE1(time, linux_nanosleep, copyout_error, "int");
110 LIN_SDT_PROBE_DEFINE1(time, linux_nanosleep, copyin_error, "int");
111 LIN_SDT_PROBE_DEFINE1(time, linux_nanosleep, return, "int");
112 LIN_SDT_PROBE_DEFINE4(time, linux_clock_nanosleep, entry, "clockid_t", "int",
113     "struct l_timespec *", "struct l_timespec *");
114 LIN_SDT_PROBE_DEFINE1(time, linux_clock_nanosleep, conversion_error, "int");
115 LIN_SDT_PROBE_DEFINE1(time, linux_clock_nanosleep, nanosleep_error, "int");
116 LIN_SDT_PROBE_DEFINE1(time, linux_clock_nanosleep, copyout_error, "int");
117 LIN_SDT_PROBE_DEFINE1(time, linux_clock_nanosleep, copyin_error, "int");
118 LIN_SDT_PROBE_DEFINE1(time, linux_clock_nanosleep, unsupported_flags, "int");
119 LIN_SDT_PROBE_DEFINE1(time, linux_clock_nanosleep, unsupported_clockid, "int");
120 LIN_SDT_PROBE_DEFINE1(time, linux_clock_nanosleep, return, "int");
121
122 static void native_to_linux_timespec(struct l_timespec *,
123                                      struct timespec *);
124 static int linux_to_native_timespec(struct timespec *,
125                                      struct l_timespec *);
126 static int linux_to_native_clockid(clockid_t *, clockid_t);
127
128 static void
129 native_to_linux_timespec(struct l_timespec *ltp, struct timespec *ntp)
130 {
131
132         LIN_SDT_PROBE2(time, native_to_linux_timespec, entry, ltp, ntp);
133
134         ltp->tv_sec = ntp->tv_sec;
135         ltp->tv_nsec = ntp->tv_nsec;
136
137         LIN_SDT_PROBE0(time, native_to_linux_timespec, return);
138 }
139
140 static int
141 linux_to_native_timespec(struct timespec *ntp, struct l_timespec *ltp)
142 {
143
144         LIN_SDT_PROBE2(time, linux_to_native_timespec, entry, ntp, ltp);
145
146         if (ltp->tv_sec < 0 || ltp->tv_nsec > (l_long)999999999L) {
147                 LIN_SDT_PROBE1(time, linux_to_native_timespec, return, EINVAL);
148                 return (EINVAL);
149         }
150         ntp->tv_sec = ltp->tv_sec;
151         ntp->tv_nsec = ltp->tv_nsec;
152
153         LIN_SDT_PROBE1(time, linux_to_native_timespec, return, 0);
154         return (0);
155 }
156
157 static int
158 linux_to_native_clockid(clockid_t *n, clockid_t l)
159 {
160
161         LIN_SDT_PROBE2(time, linux_to_native_clockid, entry, n, l);
162
163         if (l < 0) {
164                 /* cpu-clock */
165                 if ((l & LINUX_CLOCKFD_MASK) == LINUX_CLOCKFD)
166                         return (EINVAL);
167                 if (LINUX_CPUCLOCK_WHICH(l) >= LINUX_CPUCLOCK_MAX)
168                         return (EINVAL);
169
170                 if (LINUX_CPUCLOCK_PERTHREAD(l))
171                         *n = CLOCK_THREAD_CPUTIME_ID;
172                 else
173                         *n = CLOCK_PROCESS_CPUTIME_ID;
174                 return (0);
175         }
176
177         switch (l) {
178         case LINUX_CLOCK_REALTIME:
179                 *n = CLOCK_REALTIME;
180                 break;
181         case LINUX_CLOCK_MONOTONIC:
182                 *n = CLOCK_MONOTONIC;
183                 break;
184         case LINUX_CLOCK_REALTIME_COARSE:
185                 *n = CLOCK_REALTIME_FAST;
186                 break;
187         case LINUX_CLOCK_MONOTONIC_COARSE:
188                 *n = CLOCK_MONOTONIC_FAST;
189                 break;
190         case LINUX_CLOCK_MONOTONIC_RAW:
191         case LINUX_CLOCK_BOOTTIME:
192         case LINUX_CLOCK_REALTIME_ALARM:
193         case LINUX_CLOCK_BOOTTIME_ALARM:
194         case LINUX_CLOCK_SGI_CYCLE:
195         case LINUX_CLOCK_TAI:
196                 LIN_SDT_PROBE1(time, linux_to_native_clockid,
197                     unsupported_clockid, l);
198                 LIN_SDT_PROBE1(time, linux_to_native_clockid, return, EINVAL);
199                 return (EINVAL);
200         default:
201                 LIN_SDT_PROBE1(time, linux_to_native_clockid,
202                     unknown_clockid, l);
203                 LIN_SDT_PROBE1(time, linux_to_native_clockid, return, EINVAL);
204                 return (EINVAL);
205         }
206
207         LIN_SDT_PROBE1(time, linux_to_native_clockid, return, 0);
208         return (0);
209 }
210
211 int
212 linux_clock_gettime(struct thread *td, struct linux_clock_gettime_args *args)
213 {
214         struct l_timespec lts;
215         struct timespec tp;
216         struct rusage ru;
217         struct thread *targettd;
218         struct proc *p;
219         int error, clockwhich;
220         clockid_t nwhich = 0;   /* XXX: GCC */
221         pid_t pid;
222         lwpid_t tid;
223
224         LIN_SDT_PROBE2(time, linux_clock_gettime, entry, args->which, args->tp);
225
226         error = linux_to_native_clockid(&nwhich, args->which);
227         if (error != 0) {
228                 LIN_SDT_PROBE1(time, linux_clock_gettime, conversion_error,
229                     error);
230                 LIN_SDT_PROBE1(time, linux_clock_gettime, return, error);
231                 return (error);
232         }
233
234         switch (nwhich) {
235         case CLOCK_PROCESS_CPUTIME_ID:
236                 clockwhich = LINUX_CPUCLOCK_WHICH(args->which);
237                 pid = LINUX_CPUCLOCK_ID(args->which);
238                 if (pid == 0) {
239                         p = td->td_proc;
240                         PROC_LOCK(p);
241                 } else {
242                         error = pget(pid, PGET_CANSEE, &p);
243                         if (error != 0)
244                                 return (EINVAL);
245                 }
246                 switch (clockwhich) {
247                 case LINUX_CPUCLOCK_PROF:
248                         PROC_STATLOCK(p);
249                         calcru(p, &ru.ru_utime, &ru.ru_stime);
250                         PROC_STATUNLOCK(p);
251                         PROC_UNLOCK(p);
252                         timevaladd(&ru.ru_utime, &ru.ru_stime);
253                         TIMEVAL_TO_TIMESPEC(&ru.ru_utime, &tp);
254                         break;
255                 case LINUX_CPUCLOCK_VIRT:
256                         PROC_STATLOCK(p);
257                         calcru(p, &ru.ru_utime, &ru.ru_stime);
258                         PROC_STATUNLOCK(p);
259                         PROC_UNLOCK(p);
260                         TIMEVAL_TO_TIMESPEC(&ru.ru_utime, &tp);
261                         break;
262                 case LINUX_CPUCLOCK_SCHED:
263                         PROC_UNLOCK(p);
264                         error = kern_clock_getcpuclockid2(td, pid,
265                             CPUCLOCK_WHICH_PID, &nwhich);
266                         if (error != 0)
267                                 return (EINVAL);
268                         error = kern_clock_gettime(td, nwhich, &tp);
269                         break;
270                 default:
271                         PROC_UNLOCK(p);
272                         return (EINVAL);
273                 }
274
275                 break;
276
277         case CLOCK_THREAD_CPUTIME_ID:
278                 clockwhich = LINUX_CPUCLOCK_WHICH(args->which);
279                 p = td->td_proc;
280                 tid = LINUX_CPUCLOCK_ID(args->which);
281                 if (tid == 0) {
282                         targettd = td;
283                         PROC_LOCK(p);
284                 } else {
285                         targettd = tdfind(tid, p->p_pid);
286                         if (targettd == NULL)
287                                 return (EINVAL);
288                 }
289                 switch (clockwhich) {
290                 case LINUX_CPUCLOCK_PROF:
291                         PROC_STATLOCK(p);
292                         thread_lock(targettd);
293                         rufetchtd(targettd, &ru);
294                         thread_unlock(targettd);
295                         PROC_STATUNLOCK(p);
296                         PROC_UNLOCK(p);
297                         timevaladd(&ru.ru_utime, &ru.ru_stime);
298                         TIMEVAL_TO_TIMESPEC(&ru.ru_utime, &tp);
299                         break;
300                 case LINUX_CPUCLOCK_VIRT:
301                         PROC_STATLOCK(p);
302                         thread_lock(targettd);
303                         rufetchtd(targettd, &ru);
304                         thread_unlock(targettd);
305                         PROC_STATUNLOCK(p);
306                         PROC_UNLOCK(p);
307                         TIMEVAL_TO_TIMESPEC(&ru.ru_utime, &tp);
308                         break;
309                 case LINUX_CPUCLOCK_SCHED:
310                         error = kern_clock_getcpuclockid2(td, tid,
311                             CPUCLOCK_WHICH_TID, &nwhich);
312                         PROC_UNLOCK(p);
313                         if (error != 0)
314                                 return (EINVAL);
315                         error = kern_clock_gettime(td, nwhich, &tp);
316                         break;
317                 default:
318                         PROC_UNLOCK(p);
319                         return (EINVAL);
320                 }
321                 break;
322
323         default:
324                 error = kern_clock_gettime(td, nwhich, &tp);
325                 break;
326         }
327         if (error != 0) {
328                 LIN_SDT_PROBE1(time, linux_clock_gettime, gettime_error, error);
329                 LIN_SDT_PROBE1(time, linux_clock_gettime, return, error);
330                 return (error);
331         }
332         native_to_linux_timespec(&lts, &tp);
333
334         error = copyout(&lts, args->tp, sizeof lts);
335         if (error != 0)
336                 LIN_SDT_PROBE1(time, linux_clock_gettime, copyout_error, error);
337
338         LIN_SDT_PROBE1(time, linux_clock_gettime, return, error);
339         return (error);
340 }
341
342 int
343 linux_clock_settime(struct thread *td, struct linux_clock_settime_args *args)
344 {
345         struct timespec ts;
346         struct l_timespec lts;
347         int error;
348         clockid_t nwhich = 0;   /* XXX: GCC */
349
350         LIN_SDT_PROBE2(time, linux_clock_settime, entry, args->which, args->tp);
351
352         error = linux_to_native_clockid(&nwhich, args->which);
353         if (error != 0) {
354                 LIN_SDT_PROBE1(time, linux_clock_settime, conversion_error,
355                     error);
356                 LIN_SDT_PROBE1(time, linux_clock_settime, return, error);
357                 return (error);
358         }
359         error = copyin(args->tp, &lts, sizeof lts);
360         if (error != 0) {
361                 LIN_SDT_PROBE1(time, linux_clock_settime, copyin_error, error);
362                 LIN_SDT_PROBE1(time, linux_clock_settime, return, error);
363                 return (error);
364         }
365         error = linux_to_native_timespec(&ts, &lts);
366         if (error != 0) {
367                 LIN_SDT_PROBE1(time, linux_clock_settime, conversion_error,
368                     error);
369                 LIN_SDT_PROBE1(time, linux_clock_settime, return, error);
370                 return (error);
371         }
372
373         error = kern_clock_settime(td, nwhich, &ts);
374         if (error != 0)
375                 LIN_SDT_PROBE1(time, linux_clock_settime, settime_error, error);
376
377         LIN_SDT_PROBE1(time, linux_clock_settime, return, error);
378         return (error);
379 }
380
381 int
382 linux_clock_getres(struct thread *td, struct linux_clock_getres_args *args)
383 {
384         struct proc *p;
385         struct timespec ts;
386         struct l_timespec lts;
387         int error, clockwhich;
388         clockid_t nwhich = 0;   /* XXX: GCC */
389         pid_t pid;
390         lwpid_t tid;
391
392         LIN_SDT_PROBE2(time, linux_clock_getres, entry, args->which, args->tp);
393
394         error = linux_to_native_clockid(&nwhich, args->which);
395         if (error != 0) {
396                 LIN_SDT_PROBE1(time, linux_clock_getres, conversion_error,
397                     error);
398                 LIN_SDT_PROBE1(time, linux_clock_getres, return, error);
399                 return (error);
400         }
401
402         /*
403          * Check user supplied clock id in case of per-process 
404          * or thread-specific cpu-time clock.
405          */
406         switch (nwhich) {
407         case CLOCK_THREAD_CPUTIME_ID:
408                 tid = LINUX_CPUCLOCK_ID(args->which);
409                 if (tid != 0) {
410                         p = td->td_proc;
411                         if (tdfind(tid, p->p_pid) == NULL)
412                                 return (ESRCH);
413                         PROC_UNLOCK(p);
414                 }
415                 break;
416         case CLOCK_PROCESS_CPUTIME_ID:
417                 pid = LINUX_CPUCLOCK_ID(args->which);
418                 if (pid != 0) {
419                         error = pget(pid, PGET_CANSEE, &p);
420                         if (error != 0)
421                                 return (EINVAL);
422                         PROC_UNLOCK(p);
423                 }
424                 break;
425         }
426
427         if (args->tp == NULL) {
428                 LIN_SDT_PROBE0(time, linux_clock_getres, nullcall);
429                 LIN_SDT_PROBE1(time, linux_clock_getres, return, 0);
430                 return (0);
431         }
432
433         switch (nwhich) {
434         case CLOCK_THREAD_CPUTIME_ID:
435         case CLOCK_PROCESS_CPUTIME_ID:
436                 clockwhich = LINUX_CPUCLOCK_WHICH(args->which);
437                 switch (clockwhich) {
438                 case LINUX_CPUCLOCK_PROF:
439                         nwhich = CLOCK_PROF;
440                         break;
441                 case LINUX_CPUCLOCK_VIRT:
442                         nwhich = CLOCK_VIRTUAL;
443                         break;
444                 case LINUX_CPUCLOCK_SCHED:
445                         break;
446                 default:
447                         return (EINVAL);
448                 }
449                 break;
450
451         default:
452                 break;
453         }
454         error = kern_clock_getres(td, nwhich, &ts);
455         if (error != 0) {
456                 LIN_SDT_PROBE1(time, linux_clock_getres, getres_error, error);
457                 LIN_SDT_PROBE1(time, linux_clock_getres, return, error);
458                 return (error);
459         }
460         native_to_linux_timespec(&lts, &ts);
461
462         error = copyout(&lts, args->tp, sizeof lts);
463         if (error != 0)
464                 LIN_SDT_PROBE1(time, linux_clock_getres, copyout_error, error);
465
466         LIN_SDT_PROBE1(time, linux_clock_getres, return, error);
467         return (error);
468 }
469
470 int
471 linux_nanosleep(struct thread *td, struct linux_nanosleep_args *args)
472 {
473         struct timespec *rmtp;
474         struct l_timespec lrqts, lrmts;
475         struct timespec rqts, rmts;
476         int error;
477
478         LIN_SDT_PROBE2(time, linux_nanosleep, entry, args->rqtp, args->rmtp);
479
480         error = copyin(args->rqtp, &lrqts, sizeof lrqts);
481         if (error != 0) {
482                 LIN_SDT_PROBE1(time, linux_nanosleep, copyin_error, error);
483                 LIN_SDT_PROBE1(time, linux_nanosleep, return, error);
484                 return (error);
485         }
486
487         if (args->rmtp != NULL)
488                 rmtp = &rmts;
489         else
490                 rmtp = NULL;
491
492         error = linux_to_native_timespec(&rqts, &lrqts);
493         if (error != 0) {
494                 LIN_SDT_PROBE1(time, linux_nanosleep, conversion_error, error);
495                 LIN_SDT_PROBE1(time, linux_nanosleep, return, error);
496                 return (error);
497         }
498         error = kern_nanosleep(td, &rqts, rmtp);
499         if (error != 0) {
500                 LIN_SDT_PROBE1(time, linux_nanosleep, nanosleep_error, error);
501                 LIN_SDT_PROBE1(time, linux_nanosleep, return, error);
502                 return (error);
503         }
504
505         if (args->rmtp != NULL) {
506                 native_to_linux_timespec(&lrmts, rmtp);
507                 error = copyout(&lrmts, args->rmtp, sizeof(lrmts));
508                 if (error != 0) {
509                         LIN_SDT_PROBE1(time, linux_nanosleep, copyout_error,
510                             error);
511                         LIN_SDT_PROBE1(time, linux_nanosleep, return, error);
512                         return (error);
513                 }
514         }
515
516         LIN_SDT_PROBE1(time, linux_nanosleep, return, 0);
517         return (0);
518 }
519
520 int
521 linux_clock_nanosleep(struct thread *td, struct linux_clock_nanosleep_args *args)
522 {
523         struct timespec *rmtp;
524         struct l_timespec lrqts, lrmts;
525         struct timespec rqts, rmts;
526         int error;
527
528         LIN_SDT_PROBE4(time, linux_clock_nanosleep, entry, args->which,
529             args->flags, args->rqtp, args->rmtp);
530
531         if (args->flags != 0) {
532                 /* XXX deal with TIMER_ABSTIME */
533                 LIN_SDT_PROBE1(time, linux_clock_nanosleep, unsupported_flags,
534                     args->flags);
535                 LIN_SDT_PROBE1(time, linux_clock_nanosleep, return, EINVAL);
536                 return (EINVAL);        /* XXX deal with TIMER_ABSTIME */
537         }
538
539         if (args->which != LINUX_CLOCK_REALTIME) {
540                 LIN_SDT_PROBE1(time, linux_clock_nanosleep, unsupported_clockid,
541                     args->which);
542                 LIN_SDT_PROBE1(time, linux_clock_nanosleep, return, EINVAL);
543                 return (EINVAL);
544         }
545
546         error = copyin(args->rqtp, &lrqts, sizeof lrqts);
547         if (error != 0) {
548                 LIN_SDT_PROBE1(time, linux_clock_nanosleep, copyin_error,
549                     error);
550                 LIN_SDT_PROBE1(time, linux_clock_nanosleep, return, error);
551                 return (error);
552         }
553
554         if (args->rmtp != NULL)
555                 rmtp = &rmts;
556         else
557                 rmtp = NULL;
558
559         error = linux_to_native_timespec(&rqts, &lrqts);
560         if (error != 0) {
561                 LIN_SDT_PROBE1(time, linux_clock_nanosleep, conversion_error,
562                     error);
563                 LIN_SDT_PROBE1(time, linux_clock_nanosleep, return, error);
564                 return (error);
565         }
566         error = kern_nanosleep(td, &rqts, rmtp);
567         if (error != 0) {
568                 LIN_SDT_PROBE1(time, linux_clock_nanosleep, nanosleep_error,
569                     error);
570                 LIN_SDT_PROBE1(time, linux_clock_nanosleep, return, error);
571                 return (error);
572         }
573
574         if (args->rmtp != NULL) {
575                 native_to_linux_timespec(&lrmts, rmtp);
576                 error = copyout(&lrmts, args->rmtp, sizeof lrmts );
577                 if (error != 0) {
578                         LIN_SDT_PROBE1(time, linux_clock_nanosleep,
579                             copyout_error, error);
580                         LIN_SDT_PROBE1(time, linux_nanosleep, return, error);
581                         return (error);
582                 }
583         }
584
585         LIN_SDT_PROBE1(time, linux_clock_nanosleep, return, 0);
586         return (0);
587 }