1 /* Copyright (C) 2003, 2004, 2006, 2010 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
21 #include "kernel-posix-cpu-timers.h"
22 #include <kernel-features.h>
24 #ifndef HAVE_CLOCK_GETRES_VSYSCALL
25 # undef INTERNAL_VSYSCALL
26 # define INTERNAL_VSYSCALL INTERNAL_SYSCALL
27 # undef INLINE_VSYSCALL
28 # define INLINE_VSYSCALL INLINE_SYSCALL
30 # include <bits/libc-vdso.h>
33 #if __ASSUME_POSIX_CPU_TIMERS <= 0 && defined __NR_clock_settime
34 extern int __libc_missing_posix_timers attribute_hidden
;
35 extern int __libc_missing_posix_cpu_timers attribute_hidden
;
38 maybe_syscall_settime_cpu (clockid_t clock_id
, const struct timespec
*tp
)
42 if (!__libc_missing_posix_cpu_timers
)
44 INTERNAL_SYSCALL_DECL (err
);
45 int r
= INTERNAL_SYSCALL (clock_settime
, err
, 2, clock_id
, tp
);
46 if (!INTERNAL_SYSCALL_ERROR_P (r
, err
))
49 e
= INTERNAL_SYSCALL_ERRNO (r
, err
);
50 # ifndef __ASSUME_POSIX_TIMERS
53 __libc_missing_posix_timers
= 1;
54 __libc_missing_posix_cpu_timers
= 1;
62 /* Check whether the kernel supports CPU clocks at all.
63 If not, record it for the future. */
64 r
= INTERNAL_VSYSCALL (clock_getres
, err
, 2,
65 MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED
),
67 if (INTERNAL_SYSCALL_ERROR_P (r
, err
))
68 __libc_missing_posix_cpu_timers
= 1;
78 #ifdef __ASSUME_POSIX_TIMERS
79 /* This means the REALTIME clock is definitely supported in the
81 # define SYSDEP_SETTIME \
82 case CLOCK_REALTIME: \
83 retval = INLINE_SYSCALL (clock_settime, 2, clock_id, tp); \
85 #elif defined __NR_clock_settime
86 /* Is the syscall known to exist? */
87 extern int __libc_missing_posix_timers attribute_hidden
;
89 /* The REALTIME clock might be available. Try the syscall first. */
90 # define SYSDEP_SETTIME \
91 case CLOCK_REALTIME: \
92 case CLOCK_REALTIME_COARSE: \
96 if (!__libc_missing_posix_timers) \
98 INTERNAL_SYSCALL_DECL (err); \
99 int r = INTERNAL_SYSCALL (clock_settime, err, 2, clock_id, tp); \
100 if (!INTERNAL_SYSCALL_ERROR_P (r, err)) \
106 e = INTERNAL_SYSCALL_ERRNO (r, err); \
109 __libc_missing_posix_timers = 1; \
114 /* Fallback code. */ \
115 if (e == EINVAL && clock_id == CLOCK_REALTIME) \
126 #ifdef __NR_clock_settime
127 /* We handled the REALTIME clock here. */
128 # define HANDLED_REALTIME 1
131 #if __ASSUME_POSIX_CPU_TIMERS > 0
132 # define HANDLED_CPUTIME 1
133 # define SYSDEP_SETTIME_CPU \
134 retval = INLINE_SYSCALL (clock_settime, 2, clock_id, tp)
135 #elif defined __NR_clock_settime
136 # define SYSDEP_SETTIME_CPU \
137 retval = maybe_syscall_settime_cpu (clock_id, tp); \
140 if (retval != EINVAL || !__libc_missing_posix_cpu_timers) \
142 __set_errno (retval); \
149 #include <sysdeps/unix/clock_settime.c>