1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33#include <linux/mm.h>
34#include <linux/interrupt.h>
35#include <linux/slab.h>
36#include <linux/time.h>
37#include <linux/mutex.h>
38
39#include <asm/uaccess.h>
40#include <linux/list.h>
41#include <linux/init.h>
42#include <linux/compiler.h>
43#include <linux/idr.h>
44#include <linux/posix-timers.h>
45#include <linux/syscalls.h>
46#include <linux/wait.h>
47#include <linux/workqueue.h>
48#include <linux/module.h>
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71static struct kmem_cache *posix_timers_cache;
72static struct idr posix_timers_id;
73static DEFINE_SPINLOCK(idr_lock);
74
75
76
77
78
79#if SIGEV_THREAD_ID != (SIGEV_THREAD_ID & \
80 ~(SIGEV_SIGNAL | SIGEV_NONE | SIGEV_THREAD))
81#error "SIGEV_THREAD_ID must not share bit with other SIGEV values!"
82#endif
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134static struct k_clock posix_clocks[MAX_CLOCKS];
135
136
137
138
139static int common_nsleep(const clockid_t, int flags, struct timespec *t,
140 struct timespec __user *rmtp);
141static void common_timer_get(struct k_itimer *, struct itimerspec *);
142static int common_timer_set(struct k_itimer *, int,
143 struct itimerspec *, struct itimerspec *);
144static int common_timer_del(struct k_itimer *timer);
145
146static enum hrtimer_restart posix_timer_fn(struct hrtimer *data);
147
148static struct k_itimer *lock_timer(timer_t timer_id, unsigned long *flags);
149
150static inline void unlock_timer(struct k_itimer *timr, unsigned long flags)
151{
152 spin_unlock_irqrestore(&timr->it_lock, flags);
153}
154
155
156
157
158#define CLOCK_DISPATCH(clock, call, arglist) \
159 ((clock) < 0 ? posix_cpu_##call arglist : \
160 (posix_clocks[clock].call != NULL \
161 ? (*posix_clocks[clock].call) arglist : common_##call arglist))
162
163
164
165
166
167
168
169
170
171static inline int common_clock_getres(const clockid_t which_clock,
172 struct timespec *tp)
173{
174 tp->tv_sec = 0;
175 tp->tv_nsec = posix_clocks[which_clock].res;
176 return 0;
177}
178
179
180
181
182static int common_clock_get(clockid_t which_clock, struct timespec *tp)
183{
184 ktime_get_real_ts(tp);
185 return 0;
186}
187
188static inline int common_clock_set(const clockid_t which_clock,
189 struct timespec *tp)
190{
191 return do_sys_settimeofday(tp, NULL);
192}
193
194static int common_timer_create(struct k_itimer *new_timer)
195{
196 hrtimer_init(&new_timer->it.real.timer, new_timer->it_clock, 0);
197 return 0;
198}
199
200
201
202
203static inline int invalid_clockid(const clockid_t which_clock)
204{
205 if (which_clock < 0)
206 return 0;
207 if ((unsigned) which_clock >= MAX_CLOCKS)
208 return 1;
209 if (posix_clocks[which_clock].clock_getres != NULL)
210 return 0;
211 if (posix_clocks[which_clock].res != 0)
212 return 0;
213 return 1;
214}
215
216
217
218
219static int posix_ktime_get_ts(clockid_t which_clock, struct timespec *tp)
220{
221 ktime_get_ts(tp);
222 return 0;
223}
224
225
226
227
228static __init int init_posix_timers(void)
229{
230 struct k_clock clock_realtime = {
231 .clock_getres = hrtimer_get_res,
232 };
233 struct k_clock clock_monotonic = {
234 .clock_getres = hrtimer_get_res,
235 .clock_get = posix_ktime_get_ts,
236 .clock_set = do_posix_clock_nosettime,
237 };
238
239 register_posix_clock(CLOCK_REALTIME, &clock_realtime);
240 register_posix_clock(CLOCK_MONOTONIC, &clock_monotonic);
241
242 posix_timers_cache = kmem_cache_create("posix_timers_cache",
243 sizeof (struct k_itimer), 0, SLAB_PANIC,
244 NULL);
245 idr_init(&posix_timers_id);
246 return 0;
247}
248
249__initcall(init_posix_timers);
250
251static void schedule_next_timer(struct k_itimer *timr)
252{
253 struct hrtimer *timer = &timr->it.real.timer;
254
255 if (timr->it.real.interval.tv64 == 0)
256 return;
257
258 timr->it_overrun += (unsigned int) hrtimer_forward(timer,
259 timer->base->get_time(),
260 timr->it.real.interval);
261
262 timr->it_overrun_last = timr->it_overrun;
263 timr->it_overrun = -1;
264 ++timr->it_requeue_pending;
265 hrtimer_restart(timer);
266}
267
268
269
270
271
272
273
274
275
276
277
278
279void do_schedule_next_timer(struct siginfo *info)
280{
281 struct k_itimer *timr;
282 unsigned long flags;
283
284 timr = lock_timer(info->si_tid, &flags);
285
286 if (timr && timr->it_requeue_pending == info->si_sys_private) {
287 if (timr->it_clock < 0)
288 posix_cpu_timer_schedule(timr);
289 else
290 schedule_next_timer(timr);
291
292 info->si_overrun += timr->it_overrun_last;
293 }
294
295 if (timr)
296 unlock_timer(timr, flags);
297}
298
299int posix_timer_event(struct k_itimer *timr, int si_private)
300{
301
302
303
304
305
306
307
308
309
310
311
312 timr->sigq->info.si_sys_private = si_private;
313
314 timr->sigq->info.si_signo = timr->it_sigev_signo;
315 timr->sigq->info.si_code = SI_TIMER;
316 timr->sigq->info.si_tid = timr->it_id;
317 timr->sigq->info.si_value = timr->it_sigev_value;
318
319 if (timr->it_sigev_notify & SIGEV_THREAD_ID) {
320 struct task_struct *leader;
321 int ret = send_sigqueue(timr->sigq, timr->it_process, 0);
322
323 if (likely(ret >= 0))
324 return ret;
325
326 timr->it_sigev_notify = SIGEV_SIGNAL;
327 leader = timr->it_process->group_leader;
328 put_task_struct(timr->it_process);
329 timr->it_process = leader;
330 }
331
332 return send_sigqueue(timr->sigq, timr->it_process, 1);
333}
334EXPORT_SYMBOL_GPL(posix_timer_event);
335
336
337
338
339
340
341
342
343static enum hrtimer_restart posix_timer_fn(struct hrtimer *timer)
344{
345 struct k_itimer *timr;
346 unsigned long flags;
347 int si_private = 0;
348 enum hrtimer_restart ret = HRTIMER_NORESTART;
349
350 timr = container_of(timer, struct k_itimer, it.real.timer);
351 spin_lock_irqsave(&timr->it_lock, flags);
352
353 if (timr->it.real.interval.tv64 != 0)
354 si_private = ++timr->it_requeue_pending;
355
356 if (posix_timer_event(timr, si_private)) {
357
358
359
360
361
362 if (timr->it.real.interval.tv64 != 0) {
363 ktime_t now = hrtimer_cb_get_time(timer);
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387#ifdef CONFIG_HIGH_RES_TIMERS
388 {
389 ktime_t kj = ktime_set(0, NSEC_PER_SEC / HZ);
390
391 if (timr->it.real.interval.tv64 < kj.tv64)
392 now = ktime_add(now, kj);
393 }
394#endif
395 timr->it_overrun += (unsigned int)
396 hrtimer_forward(timer, now,
397 timr->it.real.interval);
398 ret = HRTIMER_RESTART;
399 ++timr->it_requeue_pending;
400 }
401 }
402
403 unlock_timer(timr, flags);
404 return ret;
405}
406
407static struct task_struct * good_sigevent(sigevent_t * event)
408{
409 struct task_struct *rtn = current->group_leader;
410
411 if ((event->sigev_notify & SIGEV_THREAD_ID ) &&
412 (!(rtn = find_task_by_vpid(event->sigev_notify_thread_id)) ||
413 !same_thread_group(rtn, current) ||
414 (event->sigev_notify & ~SIGEV_THREAD_ID) != SIGEV_SIGNAL))
415 return NULL;
416
417 if (((event->sigev_notify & ~SIGEV_THREAD_ID) != SIGEV_NONE) &&
418 ((event->sigev_signo <= 0) || (event->sigev_signo > SIGRTMAX)))
419 return NULL;
420
421 return rtn;
422}
423
424void register_posix_clock(const clockid_t clock_id, struct k_clock *new_clock)
425{
426 if ((unsigned) clock_id >= MAX_CLOCKS) {
427 printk("POSIX clock register failed for clock_id %d\n",
428 clock_id);
429 return;
430 }
431
432 posix_clocks[clock_id] = *new_clock;
433}
434EXPORT_SYMBOL_GPL(register_posix_clock);
435
436static struct k_itimer * alloc_posix_timer(void)
437{
438 struct k_itimer *tmr;
439 tmr = kmem_cache_zalloc(posix_timers_cache, GFP_KERNEL);
440 if (!tmr)
441 return tmr;
442 if (unlikely(!(tmr->sigq = sigqueue_alloc()))) {
443 kmem_cache_free(posix_timers_cache, tmr);
444 tmr = NULL;
445 }
446 memset(&tmr->sigq->info, 0, sizeof(siginfo_t));
447 return tmr;
448}
449
450#define IT_ID_SET 1
451#define IT_ID_NOT_SET 0
452static void release_posix_timer(struct k_itimer *tmr, int it_id_set)
453{
454 if (it_id_set) {
455 unsigned long flags;
456 spin_lock_irqsave(&idr_lock, flags);
457 idr_remove(&posix_timers_id, tmr->it_id);
458 spin_unlock_irqrestore(&idr_lock, flags);
459 }
460 sigqueue_free(tmr->sigq);
461 if (unlikely(tmr->it_process) &&
462 tmr->it_sigev_notify == (SIGEV_SIGNAL|SIGEV_THREAD_ID))
463 put_task_struct(tmr->it_process);
464 kmem_cache_free(posix_timers_cache, tmr);
465}
466
467
468
469asmlinkage long
470sys_timer_create(const clockid_t which_clock,
471 struct sigevent __user *timer_event_spec,
472 timer_t __user * created_timer_id)
473{
474 int error = 0;
475 struct k_itimer *new_timer = NULL;
476 int new_timer_id;
477 struct task_struct *process = NULL;
478 unsigned long flags;
479 sigevent_t event;
480 int it_id_set = IT_ID_NOT_SET;
481
482 if (invalid_clockid(which_clock))
483 return -EINVAL;
484
485 new_timer = alloc_posix_timer();
486 if (unlikely(!new_timer))
487 return -EAGAIN;
488
489 spin_lock_init(&new_timer->it_lock);
490 retry:
491 if (unlikely(!idr_pre_get(&posix_timers_id, GFP_KERNEL))) {
492 error = -EAGAIN;
493 goto out;
494 }
495 spin_lock_irq(&idr_lock);
496 error = idr_get_new(&posix_timers_id, (void *) new_timer,
497 &new_timer_id);
498 spin_unlock_irq(&idr_lock);
499 if (error == -EAGAIN)
500 goto retry;
501 else if (error) {
502
503
504
505
506 error = -EAGAIN;
507 goto out;
508 }
509
510 it_id_set = IT_ID_SET;
511 new_timer->it_id = (timer_t) new_timer_id;
512 new_timer->it_clock = which_clock;
513 new_timer->it_overrun = -1;
514 error = CLOCK_DISPATCH(which_clock, timer_create, (new_timer));
515 if (error)
516 goto out;
517
518
519
520
521
522 if (copy_to_user(created_timer_id,
523 &new_timer_id, sizeof (new_timer_id))) {
524 error = -EFAULT;
525 goto out;
526 }
527 if (timer_event_spec) {
528 if (copy_from_user(&event, timer_event_spec, sizeof (event))) {
529 error = -EFAULT;
530 goto out;
531 }
532 new_timer->it_sigev_notify = event.sigev_notify;
533 new_timer->it_sigev_signo = event.sigev_signo;
534 new_timer->it_sigev_value = event.sigev_value;
535
536 read_lock(&tasklist_lock);
537 if ((process = good_sigevent(&event))) {
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553 spin_lock_irqsave(&process->sighand->siglock, flags);
554 if (!(process->flags & PF_EXITING)) {
555 new_timer->it_process = process;
556 list_add(&new_timer->list,
557 &process->signal->posix_timers);
558 if (new_timer->it_sigev_notify == (SIGEV_SIGNAL|SIGEV_THREAD_ID))
559 get_task_struct(process);
560 spin_unlock_irqrestore(&process->sighand->siglock, flags);
561 } else {
562 spin_unlock_irqrestore(&process->sighand->siglock, flags);
563 process = NULL;
564 }
565 }
566 read_unlock(&tasklist_lock);
567 if (!process) {
568 error = -EINVAL;
569 goto out;
570 }
571 } else {
572 new_timer->it_sigev_notify = SIGEV_SIGNAL;
573 new_timer->it_sigev_signo = SIGALRM;
574 new_timer->it_sigev_value.sival_int = new_timer->it_id;
575 process = current->group_leader;
576 spin_lock_irqsave(&process->sighand->siglock, flags);
577 new_timer->it_process = process;
578 list_add(&new_timer->list, &process->signal->posix_timers);
579 spin_unlock_irqrestore(&process->sighand->siglock, flags);
580 }
581
582
583
584
585
586
587
588
589out:
590 if (error)
591 release_posix_timer(new_timer, it_id_set);
592
593 return error;
594}
595
596
597
598
599
600
601
602
603static struct k_itimer * lock_timer(timer_t timer_id, unsigned long *flags)
604{
605 struct k_itimer *timr;
606
607
608
609
610
611
612 spin_lock_irqsave(&idr_lock, *flags);
613 timr = (struct k_itimer *) idr_find(&posix_timers_id, (int) timer_id);
614 if (timr) {
615 spin_lock(&timr->it_lock);
616
617 if ((timr->it_id != timer_id) || !(timr->it_process) ||
618 !same_thread_group(timr->it_process, current)) {
619 spin_unlock(&timr->it_lock);
620 spin_unlock_irqrestore(&idr_lock, *flags);
621 timr = NULL;
622 } else
623 spin_unlock(&idr_lock);
624 } else
625 spin_unlock_irqrestore(&idr_lock, *flags);
626
627 return timr;
628}
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646static void
647common_timer_get(struct k_itimer *timr, struct itimerspec *cur_setting)
648{
649 ktime_t now, remaining, iv;
650 struct hrtimer *timer = &timr->it.real.timer;
651
652 memset(cur_setting, 0, sizeof(struct itimerspec));
653
654 iv = timr->it.real.interval;
655
656
657 if (iv.tv64)
658 cur_setting->it_interval = ktime_to_timespec(iv);
659 else if (!hrtimer_active(timer) &&
660 (timr->it_sigev_notify & ~SIGEV_THREAD_ID) != SIGEV_NONE)
661 return;
662
663 now = timer->base->get_time();
664
665
666
667
668
669
670 if (iv.tv64 && (timr->it_requeue_pending & REQUEUE_PENDING ||
671 (timr->it_sigev_notify & ~SIGEV_THREAD_ID) == SIGEV_NONE))
672 timr->it_overrun += (unsigned int) hrtimer_forward(timer, now, iv);
673
674 remaining = ktime_sub(timer->expires, now);
675
676 if (remaining.tv64 <= 0) {
677
678
679
680
681 if ((timr->it_sigev_notify & ~SIGEV_THREAD_ID) != SIGEV_NONE)
682 cur_setting->it_value.tv_nsec = 1;
683 } else
684 cur_setting->it_value = ktime_to_timespec(remaining);
685}
686
687
688asmlinkage long
689sys_timer_gettime(timer_t timer_id, struct itimerspec __user *setting)
690{
691 struct k_itimer *timr;
692 struct itimerspec cur_setting;
693 unsigned long flags;
694
695 timr = lock_timer(timer_id, &flags);
696 if (!timr)
697 return -EINVAL;
698
699 CLOCK_DISPATCH(timr->it_clock, timer_get, (timr, &cur_setting));
700
701 unlock_timer(timr, flags);
702
703 if (copy_to_user(setting, &cur_setting, sizeof (cur_setting)))
704 return -EFAULT;
705
706 return 0;
707}
708
709
710
711
712
713
714
715
716
717
718asmlinkage long
719sys_timer_getoverrun(timer_t timer_id)
720{
721 struct k_itimer *timr;
722 int overrun;
723 unsigned long flags;
724
725 timr = lock_timer(timer_id, &flags);
726 if (!timr)
727 return -EINVAL;
728
729 overrun = timr->it_overrun_last;
730 unlock_timer(timr, flags);
731
732 return overrun;
733}
734
735
736
737static int
738common_timer_set(struct k_itimer *timr, int flags,
739 struct itimerspec *new_setting, struct itimerspec *old_setting)
740{
741 struct hrtimer *timer = &timr->it.real.timer;
742 enum hrtimer_mode mode;
743
744 if (old_setting)
745 common_timer_get(timr, old_setting);
746
747
748 timr->it.real.interval.tv64 = 0;
749
750
751
752
753 if (hrtimer_try_to_cancel(timer) < 0)
754 return TIMER_RETRY;
755
756 timr->it_requeue_pending = (timr->it_requeue_pending + 2) &
757 ~REQUEUE_PENDING;
758 timr->it_overrun_last = 0;
759
760
761 if (!new_setting->it_value.tv_sec && !new_setting->it_value.tv_nsec)
762 return 0;
763
764 mode = flags & TIMER_ABSTIME ? HRTIMER_MODE_ABS : HRTIMER_MODE_REL;
765 hrtimer_init(&timr->it.real.timer, timr->it_clock, mode);
766 timr->it.real.timer.function = posix_timer_fn;
767
768 timer->expires = timespec_to_ktime(new_setting->it_value);
769
770
771 timr->it.real.interval = timespec_to_ktime(new_setting->it_interval);
772
773
774 if (((timr->it_sigev_notify & ~SIGEV_THREAD_ID) == SIGEV_NONE)) {
775
776 if (mode == HRTIMER_MODE_REL) {
777 timer->expires =
778 ktime_add_safe(timer->expires,
779 timer->base->get_time());
780 }
781 return 0;
782 }
783
784 hrtimer_start(timer, timer->expires, mode);
785 return 0;
786}
787
788
789asmlinkage long
790sys_timer_settime(timer_t timer_id, int flags,
791 const struct itimerspec __user *new_setting,
792 struct itimerspec __user *old_setting)
793{
794 struct k_itimer *timr;
795 struct itimerspec new_spec, old_spec;
796 int error = 0;
797 unsigned long flag;
798 struct itimerspec *rtn = old_setting ? &old_spec : NULL;
799
800 if (!new_setting)
801 return -EINVAL;
802
803 if (copy_from_user(&new_spec, new_setting, sizeof (new_spec)))
804 return -EFAULT;
805
806 if (!timespec_valid(&new_spec.it_interval) ||
807 !timespec_valid(&new_spec.it_value))
808 return -EINVAL;
809retry:
810 timr = lock_timer(timer_id, &flag);
811 if (!timr)
812 return -EINVAL;
813
814 error = CLOCK_DISPATCH(timr->it_clock, timer_set,
815 (timr, flags, &new_spec, rtn));
816
817 unlock_timer(timr, flag);
818 if (error == TIMER_RETRY) {
819 rtn = NULL;
820 goto retry;
821 }
822
823 if (old_setting && !error &&
824 copy_to_user(old_setting, &old_spec, sizeof (old_spec)))
825 error = -EFAULT;
826
827 return error;
828}
829
830static inline int common_timer_del(struct k_itimer *timer)
831{
832 timer->it.real.interval.tv64 = 0;
833
834 if (hrtimer_try_to_cancel(&timer->it.real.timer) < 0)
835 return TIMER_RETRY;
836 return 0;
837}
838
839static inline int timer_delete_hook(struct k_itimer *timer)
840{
841 return CLOCK_DISPATCH(timer->it_clock, timer_del, (timer));
842}
843
844
845asmlinkage long
846sys_timer_delete(timer_t timer_id)
847{
848 struct k_itimer *timer;
849 unsigned long flags;
850
851retry_delete:
852 timer = lock_timer(timer_id, &flags);
853 if (!timer)
854 return -EINVAL;
855
856 if (timer_delete_hook(timer) == TIMER_RETRY) {
857 unlock_timer(timer, flags);
858 goto retry_delete;
859 }
860
861 spin_lock(¤t->sighand->siglock);
862 list_del(&timer->list);
863 spin_unlock(¤t->sighand->siglock);
864
865
866
867
868 if (timer->it_process) {
869 if (timer->it_sigev_notify == (SIGEV_SIGNAL|SIGEV_THREAD_ID))
870 put_task_struct(timer->it_process);
871 timer->it_process = NULL;
872 }
873 unlock_timer(timer, flags);
874 release_posix_timer(timer, IT_ID_SET);
875 return 0;
876}
877
878
879
880
881static void itimer_delete(struct k_itimer *timer)
882{
883 unsigned long flags;
884
885retry_delete:
886 spin_lock_irqsave(&timer->it_lock, flags);
887
888 if (timer_delete_hook(timer) == TIMER_RETRY) {
889 unlock_timer(timer, flags);
890 goto retry_delete;
891 }
892 list_del(&timer->list);
893
894
895
896
897 if (timer->it_process) {
898 if (timer->it_sigev_notify == (SIGEV_SIGNAL|SIGEV_THREAD_ID))
899 put_task_struct(timer->it_process);
900 timer->it_process = NULL;
901 }
902 unlock_timer(timer, flags);
903 release_posix_timer(timer, IT_ID_SET);
904}
905
906
907
908
909
910void exit_itimers(struct signal_struct *sig)
911{
912 struct k_itimer *tmr;
913
914 while (!list_empty(&sig->posix_timers)) {
915 tmr = list_entry(sig->posix_timers.next, struct k_itimer, list);
916 itimer_delete(tmr);
917 }
918}
919
920
921int do_posix_clock_nosettime(const clockid_t clockid, struct timespec *tp)
922{
923 return -EINVAL;
924}
925EXPORT_SYMBOL_GPL(do_posix_clock_nosettime);
926
927int do_posix_clock_nonanosleep(const clockid_t clock, int flags,
928 struct timespec *t, struct timespec __user *r)
929{
930#ifndef ENOTSUP
931 return -EOPNOTSUPP;
932#else
933 return -ENOTSUP;
934#endif
935}
936EXPORT_SYMBOL_GPL(do_posix_clock_nonanosleep);
937
938asmlinkage long sys_clock_settime(const clockid_t which_clock,
939 const struct timespec __user *tp)
940{
941 struct timespec new_tp;
942
943 if (invalid_clockid(which_clock))
944 return -EINVAL;
945 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
946 return -EFAULT;
947
948 return CLOCK_DISPATCH(which_clock, clock_set, (which_clock, &new_tp));
949}
950
951asmlinkage long
952sys_clock_gettime(const clockid_t which_clock, struct timespec __user *tp)
953{
954 struct timespec kernel_tp;
955 int error;
956
957 if (invalid_clockid(which_clock))
958 return -EINVAL;
959 error = CLOCK_DISPATCH(which_clock, clock_get,
960 (which_clock, &kernel_tp));
961 if (!error && copy_to_user(tp, &kernel_tp, sizeof (kernel_tp)))
962 error = -EFAULT;
963
964 return error;
965
966}
967
968asmlinkage long
969sys_clock_getres(const clockid_t which_clock, struct timespec __user *tp)
970{
971 struct timespec rtn_tp;
972 int error;
973
974 if (invalid_clockid(which_clock))
975 return -EINVAL;
976
977 error = CLOCK_DISPATCH(which_clock, clock_getres,
978 (which_clock, &rtn_tp));
979
980 if (!error && tp && copy_to_user(tp, &rtn_tp, sizeof (rtn_tp))) {
981 error = -EFAULT;
982 }
983
984 return error;
985}
986
987
988
989
990static int common_nsleep(const clockid_t which_clock, int flags,
991 struct timespec *tsave, struct timespec __user *rmtp)
992{
993 return hrtimer_nanosleep(tsave, rmtp, flags & TIMER_ABSTIME ?
994 HRTIMER_MODE_ABS : HRTIMER_MODE_REL,
995 which_clock);
996}
997
998asmlinkage long
999sys_clock_nanosleep(const clockid_t which_clock, int flags,
1000 const struct timespec __user *rqtp,
1001 struct timespec __user *rmtp)
1002{
1003 struct timespec t;
1004
1005 if (invalid_clockid(which_clock))
1006 return -EINVAL;
1007
1008 if (copy_from_user(&t, rqtp, sizeof (struct timespec)))
1009 return -EFAULT;
1010
1011 if (!timespec_valid(&t))
1012 return -EINVAL;
1013
1014 return CLOCK_DISPATCH(which_clock, nsleep,
1015 (which_clock, flags, &t, rmtp));
1016}
1017
1018
1019
1020
1021static int common_nsleep_restart(struct restart_block *restart_block)
1022{
1023 return hrtimer_nanosleep_restart(restart_block);
1024}
1025
1026
1027
1028
1029
1030long
1031clock_nanosleep_restart(struct restart_block *restart_block)
1032{
1033 clockid_t which_clock = restart_block->arg0;
1034
1035 return CLOCK_DISPATCH(which_clock, nsleep_restart,
1036 (restart_block));
1037}
1038