1 | /* Auxiliary definitions for 64-bit time_t support. |
2 | Copyright (C) 2020-2021 Free Software Foundation, Inc. |
3 | This file is part of the GNU C Library. |
4 | |
5 | The GNU C Library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Lesser General Public |
7 | License as published by the Free Software Foundation; either |
8 | version 2.1 of the License, or (at your option) any later version. |
9 | |
10 | The GNU C Library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Lesser General Public License for more details. |
14 | |
15 | You should have received a copy of the GNU Lesser General Public |
16 | License along with the GNU C Library; if not, see |
17 | <https://www.gnu.org/licenses/>. */ |
18 | |
19 | #include <stdbool.h> |
20 | #include <atomic.h> |
21 | |
22 | /* These helper functions are used to optimize the 64-bit time_t support on |
23 | configurations that requires support for 32-bit time_t fallback |
24 | (!__ASSUME_TIME64_SYSCALLS). The idea is once the kernel advertises that |
25 | it does not have 64-bit time_t support, glibc will stop to try issue the |
26 | 64-bit time_t syscall altogether. |
27 | |
28 | For instance: |
29 | |
30 | #ifndef __NR_symbol_time64 |
31 | # define __NR_symbol_time64 __NR_symbol |
32 | #endif |
33 | int r; |
34 | if (supports_time64 ()) |
35 | { |
36 | r = INLINE_SYSCALL_CALL (symbol, ...); |
37 | if (r == 0 || errno != ENOSYS) |
38 | return r; |
39 | |
40 | mark_time64_unsupported (); |
41 | } |
42 | #ifndef __ASSUME_TIME64_SYSCALLS |
43 | <32-bit fallback syscall> |
44 | #endif |
45 | return r; |
46 | |
47 | On configuration with default 64-bit time_t this optimization should be |
48 | optimized away by the compiler resulting in no overhead. */ |
49 | |
50 | #ifndef __ASSUME_TIME64_SYSCALLS |
51 | extern int __time64_support attribute_hidden; |
52 | #endif |
53 | |
54 | static inline bool |
55 | supports_time64 (void) |
56 | { |
57 | #ifdef __ASSUME_TIME64_SYSCALLS |
58 | return true; |
59 | #else |
60 | return atomic_load_relaxed (&__time64_support) != 0; |
61 | #endif |
62 | } |
63 | |
64 | static inline void |
65 | mark_time64_unsupported (void) |
66 | { |
67 | #ifndef __ASSUME_TIME64_SYSCALLS |
68 | atomic_store_relaxed (&__time64_support, 0); |
69 | #endif |
70 | } |
71 | |