Maintain stack alignment in ____longjmp_chk on x86_64
[glibc.git] / sysdeps / unix / sysv / linux / clock_settime.c
blob8c52456fdd46708019149a5aafc38ce45bc946a7
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, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 02111-1307 USA. */
19 #include <errno.h>
20 #include <sysdep.h>
22 #include "kernel-posix-cpu-timers.h"
23 #include <kernel-features.h>
25 #ifndef HAVE_CLOCK_GETRES_VSYSCALL
26 # undef INTERNAL_VSYSCALL
27 # define INTERNAL_VSYSCALL INTERNAL_SYSCALL
28 # undef INLINE_VSYSCALL
29 # define INLINE_VSYSCALL INLINE_SYSCALL
30 #else
31 # include <bits/libc-vdso.h>
32 #endif
34 #if __ASSUME_POSIX_CPU_TIMERS <= 0 && defined __NR_clock_settime
35 extern int __libc_missing_posix_timers attribute_hidden;
36 extern int __libc_missing_posix_cpu_timers attribute_hidden;
38 static int
39 maybe_syscall_settime_cpu (clockid_t clock_id, const struct timespec *tp)
41 int e = EINVAL;
43 if (!__libc_missing_posix_cpu_timers)
45 INTERNAL_SYSCALL_DECL (err);
46 int r = INTERNAL_SYSCALL (clock_settime, err, 2, clock_id, tp);
47 if (!INTERNAL_SYSCALL_ERROR_P (r, err))
48 return 0;
50 e = INTERNAL_SYSCALL_ERRNO (r, err);
51 # ifndef __ASSUME_POSIX_TIMERS
52 if (e == ENOSYS)
54 __libc_missing_posix_timers = 1;
55 __libc_missing_posix_cpu_timers = 1;
56 e = EINVAL;
58 else
59 # endif
61 if (e == EINVAL)
63 /* Check whether the kernel supports CPU clocks at all.
64 If not, record it for the future. */
65 r = INTERNAL_VSYSCALL (clock_getres, err, 2,
66 MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED),
67 NULL);
68 if (INTERNAL_SYSCALL_ERROR_P (r, err))
69 __libc_missing_posix_cpu_timers = 1;
74 return e;
76 #endif
79 #ifdef __ASSUME_POSIX_TIMERS
80 /* This means the REALTIME clock is definitely supported in the
81 kernel. */
82 # define SYSDEP_SETTIME \
83 case CLOCK_REALTIME: \
84 retval = INLINE_SYSCALL (clock_settime, 2, clock_id, tp); \
85 break
86 #elif defined __NR_clock_settime
87 /* Is the syscall known to exist? */
88 extern int __libc_missing_posix_timers attribute_hidden;
90 /* The REALTIME clock might be available. Try the syscall first. */
91 # define SYSDEP_SETTIME \
92 case CLOCK_REALTIME: \
93 case CLOCK_REALTIME_COARSE: \
94 { \
95 int e = EINVAL; \
97 if (!__libc_missing_posix_timers) \
98 { \
99 INTERNAL_SYSCALL_DECL (err); \
100 int r = INTERNAL_SYSCALL (clock_settime, err, 2, clock_id, tp); \
101 if (!INTERNAL_SYSCALL_ERROR_P (r, err)) \
103 retval = 0; \
104 break; \
107 e = INTERNAL_SYSCALL_ERRNO (r, err); \
108 if (e == ENOSYS) \
110 __libc_missing_posix_timers = 1; \
111 e = EINVAL; \
115 /* Fallback code. */ \
116 if (e == EINVAL && clock_id == CLOCK_REALTIME) \
117 HANDLE_REALTIME; \
118 else \
120 __set_errno (e); \
121 retval = -1; \
124 break
125 #endif
127 #ifdef __NR_clock_settime
128 /* We handled the REALTIME clock here. */
129 # define HANDLED_REALTIME 1
130 #endif
132 #if __ASSUME_POSIX_CPU_TIMERS > 0
133 # define HANDLED_CPUTIME 1
134 # define SYSDEP_SETTIME_CPU \
135 retval = INLINE_SYSCALL (clock_settime, 2, clock_id, tp)
136 #elif defined __NR_clock_settime
137 # define SYSDEP_SETTIME_CPU \
138 retval = maybe_syscall_settime_cpu (clock_id, tp); \
139 if (retval == 0) \
140 break; \
141 if (retval != EINVAL || !__libc_missing_posix_cpu_timers) \
143 __set_errno (retval); \
144 retval = -1; \
145 break; \
147 do { } while (0)
148 #endif
150 #include <sysdeps/unix/clock_settime.c>