| 1 | /* Set flags signalling availability of kernel features based on given |
| 2 | kernel version number. |
| 3 | Copyright (C) 1999-2026 Free Software Foundation, Inc. |
| 4 | This file is part of the GNU C Library. |
| 5 | |
| 6 | The GNU C Library is free software; you can redistribute it and/or |
| 7 | modify it under the terms of the GNU Lesser General Public |
| 8 | License as published by the Free Software Foundation; either |
| 9 | version 2.1 of the License, or (at your option) any later version. |
| 10 | |
| 11 | The GNU C Library is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | Lesser General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU Lesser General Public |
| 17 | License along with the GNU C Library; if not, see |
| 18 | <https://www.gnu.org/licenses/>. */ |
| 19 | |
| 20 | /* This file must not contain any C code. At least it must be protected |
| 21 | to allow using the file also in assembler files. */ |
| 22 | |
| 23 | #ifndef _LINUX_KERNEL_FEATURES_H |
| 24 | #define _LINUX_KERNEL_FEATURES_H 1 |
| 25 | |
| 26 | #include <bits/wordsize.h> |
| 27 | |
| 28 | #ifndef __LINUX_KERNEL_VERSION |
| 29 | /* We assume the worst; all kernels should be supported. */ |
| 30 | # define __LINUX_KERNEL_VERSION	0 |
| 31 | #endif |
| 32 | |
| 33 | /* We assume for __LINUX_KERNEL_VERSION the same encoding used in |
| 34 | linux/version.h. I.e., the major, minor, and subminor all get a |
| 35 | byte with the major number being in the highest byte. This means |
| 36 | we can do numeric comparisons. |
| 37 | |
| 38 | In the following we will define certain symbols depending on |
| 39 | whether the describes kernel feature is available in the kernel |
| 40 | version given by __LINUX_KERNEL_VERSION. We are not always exactly |
| 41 | recording the correct versions in which the features were |
| 42 | introduced. If somebody cares these values can afterwards be |
| 43 | corrected. */ |
| 44 | |
| 45 | /* The statfs64 syscalls are available in 2.5.74 (but not for alpha). */ |
| 46 | #define __ASSUME_STATFS64	1 |
| 47 | |
| 48 | /* pselect/ppoll were introduced just after 2.6.16-rc1. On x86_64 and |
| 49 | SH this appeared first in 2.6.19-rc1. */ |
| 50 | #define __ASSUME_PSELECT	1 |
| 51 | |
| 52 | /* Support for inter-process robust mutexes was added in 2.6.17 (but |
| 53 | some architectures lack futex_atomic_cmpxchg_inatomic in some |
| 54 | configurations). */ |
| 55 | #define __ASSUME_SET_ROBUST_LIST	1 |
| 56 | |
| 57 | /* The termios2 interface was introduced across all architectures except |
| 58 | Alpha in kernel 2.6.22. */ |
| 59 | #define __ASSUME_TERMIOS2	1 |
| 60 | |
| 61 | /* Support for various CLOEXEC and NONBLOCK flags was added in |
| 62 | 2.6.27. */ |
| 63 | #define __ASSUME_IN_NONBLOCK	1 |
| 64 | |
| 65 | /* Support for preadv and pwritev was added in 2.6.30. */ |
| 66 | #define __ASSUME_PREADV	1 |
| 67 | #define __ASSUME_PWRITEV	1 |
| 68 | |
| 69 | /* Support for sendmmsg functionality was added in 3.0. */ |
| 70 | #define __ASSUME_SENDMMSG	1 |
| 71 | |
| 72 | /* On most architectures, most socket syscalls are supported for all |
| 73 | supported kernel versions, but on some socketcall architectures |
| 74 | separate syscalls were only added later. */ |
| 75 | #define __ASSUME_SENDMSG_SYSCALL	1 |
| 76 | #define __ASSUME_RECVMSG_SYSCALL	1 |
| 77 | #define __ASSUME_ACCEPT_SYSCALL		1 |
| 78 | #define __ASSUME_CONNECT_SYSCALL	1 |
| 79 | #define __ASSUME_RECVFROM_SYSCALL	1 |
| 80 | #define __ASSUME_SENDTO_SYSCALL		1 |
| 81 | #define __ASSUME_ACCEPT4_SYSCALL	1 |
| 82 | #define __ASSUME_RECVMMSG_SYSCALL	1 |
| 83 | #define __ASSUME_SENDMMSG_SYSCALL	1 |
| 84 | #define __ASSUME_GETSOCKOPT_SYSCALL	1 |
| 85 | #define __ASSUME_SETSOCKOPT_SYSCALL	1 |
| 86 | #define __ASSUME_BIND_SYSCALL		1 |
| 87 | #define __ASSUME_SOCKET_SYSCALL		1 |
| 88 | #define __ASSUME_SOCKETPAIR_SYSCALL	1 |
| 89 | #define __ASSUME_LISTEN_SYSCALL		1 |
| 90 | #define __ASSUME_SHUTDOWN_SYSCALL	1 |
| 91 | #define __ASSUME_GETSOCKNAME_SYSCALL	1 |
| 92 | #define __ASSUME_GETPEERNAME_SYSCALL	1 |
| 93 | |
| 94 | /* Support for SysV IPC through wired syscalls. All supported architectures |
| 95 | either support ipc syscall and/or all the ipc correspondent syscalls. */ |
| 96 | #define __ASSUME_DIRECT_SYSVIPC_SYSCALLS	1 |
| 97 | /* The generic default __IPC_64 value is 0x0, however some architectures |
| 98 | require a different value of 0x100. */ |
| 99 | #define __ASSUME_SYSVIPC_DEFAULT_IPC_64		1 |
| 100 | |
| 101 | /* All supported architectures reserve a 32-bit for MODE field in sysvipc |
| 102 | ipc_perm. However, some kernel ABI interfaces still expect a 16-bit |
| 103 | field. This is only an issue if arch-defined IPC_PERM padding is on a |
| 104 | wrong position regarding endianness. In this case, the IPC control |
| 105 | routines (msgctl, semctl, and semtctl) requires to shift the value to |
| 106 | correct place. |
| 107 | The ABIs that requires it define __ASSUME_SYSVIPC_BROKEN_MODE_T. */ |
| 108 | |
| 109 | /* Support for p{read,write}v2 was added in 4.6. However Linux default |
| 110 | implementation does not assume the __ASSUME_* and instead use a fallback |
| 111 | implementation based on p{read,write}v and returning an error for |
| 112 | non supported flags. */ |
| 113 | |
| 114 | /* Support for the renameat2 system call was added in kernel 3.15. */ |
| 115 | #if __LINUX_KERNEL_VERSION >= 0x030F00 |
| 116 | # define __ASSUME_RENAMEAT2 |
| 117 | #endif |
| 118 | |
| 119 | /* Support for the execveat syscall was added in 3.19. */ |
| 120 | #if __LINUX_KERNEL_VERSION >= 0x031300 |
| 121 | # define __ASSUME_EXECVEAT	1 |
| 122 | #endif |
| 123 | |
| 124 | #if __LINUX_KERNEL_VERSION >= 0x040400 |
| 125 | # define __ASSUME_MLOCK2 1 |
| 126 | #endif |
| 127 | |
| 128 | /* Support for statx was added in kernel 4.11. */ |
| 129 | #if __LINUX_KERNEL_VERSION >= 0x040B00 |
| 130 | # define __ASSUME_STATX 1 |
| 131 | #endif |
| 132 | |
| 133 | /* Support for clone call used on fork. The signature varies across the |
| 134 | architectures with current 4 different variants: |
| 135 | |
| 136 | 1. long int clone (unsigned long flags, unsigned long newsp, |
| 137 | 		 int *parent_tidptr, unsigned long tls, |
| 138 | 		 int *child_tidptr) |
| 139 | |
| 140 | 2. long int clone (unsigned long newsp, unsigned long clone_flags, |
| 141 | 		 int *parent_tidptr, int * child_tidptr, |
| 142 | 		 unsigned long tls) |
| 143 | |
| 144 | 3. long int clone (unsigned long flags, unsigned long newsp, |
| 145 | 		 int stack_size, int *parent_tidptr, |
| 146 | 		 int *child_tidptr, unsigned long tls) |
| 147 | |
| 148 | 4. long int clone (unsigned long flags, unsigned long newsp, |
| 149 | 		 int *parent_tidptr, int *child_tidptr, |
| 150 | 		 unsigned long tls) |
| 151 | |
| 152 | The fourth variant is intended to be used as the default for newer ports, |
| 153 | |
| 154 | The macros names to define the variant used for the architecture is |
| 155 | similar to kernel: |
| 156 | |
| 157 | - __ASSUME_CLONE_BACKWARDS: for variant 1. |
| 158 | - __ASSUME_CLONE_BACKWARDS2: for variant 2 (s390x). |
| 159 | - __ASSUME_CLONE_BACKWARDS3: for variant 3 (microblaze). |
| 160 | - __ASSUME_CLONE_DEFAULT: for variant 4. |
| 161 | */ |
| 162 | |
| 163 | #define __ASSUME_CLONE_DEFAULT 1 |
| 164 | |
| 165 | /* Support for 64-bit time_t in the system call interface. When this |
| 166 | flag is set, the kernel provides a version of each of these system |
| 167 | calls that accepts 64-bit time_t: |
| 168 | |
| 169 | clock_adjtime(64) |
| 170 | clock_gettime(64) |
| 171 | clock_settime(64) |
| 172 | clock_getres(_time64) |
| 173 | clock_nanosleep(_time64) |
| 174 | futex(_time64) |
| 175 | mq_timedreceive(_time64) |
| 176 | mq_timedsend(_time64) |
| 177 | ppoll(_time64) |
| 178 | pselect6(_time64) |
| 179 | rt_sigtimedwait(_time64) |
| 180 | sched_rr_get_interval(_time64) |
| 181 | timer_gettime(64) |
| 182 | timer_settime(64) |
| 183 | timerfd_gettime(64) |
| 184 | timerfd_settime(64) |
| 185 | utimensat(_time64) |
| 186 | |
| 187 | On architectures where time_t has historically been 64 bits, |
| 188 | only the 64-bit version of each system call exists, and there |
| 189 | are no suffixes on the __NR_ constants. |
| 190 | |
| 191 | On architectures where time_t has historically been 32 bits, |
| 192 | both 32-bit and 64-bit versions of each system call may exist, |
| 193 | depending on the kernel version. When the 64-bit version exists, |
| 194 | there is a '64' or '_time64' suffix on the name of its __NR_ |
| 195 | constant, as shown above. |
| 196 | |
| 197 | This flag is always set for Linux 5.1 and later. Prior to that |
| 198 | version, it is set only for some CPU architectures and ABIs: |
| 199 | |
| 200 | - __WORDSIZE == 64 - all supported architectures where pointers |
| 201 | are 64 bits also have always had 64-bit time_t. |
| 202 | |
| 203 | - __WORDSIZE == 32 && __SYSCALL_WORDSIZE == 64 - this describes |
| 204 | only one supported configuration, x86's 'x32' subarchitecture, |
| 205 | where pointers are 32 bits but time_t has always been 64 bits. |
| 206 | |
| 207 | __ASSUME_TIME64_SYSCALLS being set does not mean __TIMESIZE is 64, |
| 208 | and __TIMESIZE equal to 64 does not mean __ASSUME_TIME64_SYSCALLS |
| 209 | is set. All four cases are possible. */ |
| 210 | |
| 211 | #if __LINUX_KERNEL_VERSION >= 0x050100 \ |
| 212 | || __WORDSIZE == 64 \ |
| 213 | || (defined __SYSCALL_WORDSIZE && __SYSCALL_WORDSIZE == 64) |
| 214 | # define __ASSUME_TIME64_SYSCALLS 1 |
| 215 | #endif |
| 216 | |
| 217 | /* Linux waitid prior kernel 5.4 does not support waiting for the current |
| 218 | process group. */ |
| 219 | #if __LINUX_KERNEL_VERSION >= 0x050400 |
| 220 | # define __ASSUME_WAITID_PID0_P_PGID |
| 221 | #endif |
| 222 | |
| 223 | /* The faccessat2 system call was introduced across all architectures |
| 224 | in Linux 5.8. */ |
| 225 | #if __LINUX_KERNEL_VERSION >= 0x050800 |
| 226 | # define __ASSUME_FACCESSAT2 1 |
| 227 | #else |
| 228 | # define __ASSUME_FACCESSAT2 0 |
| 229 | #endif |
| 230 | |
| 231 | /* The close_range system call was introduced across all architectures |
| 232 | in Linux 5.9. */ |
| 233 | #if __LINUX_KERNEL_VERSION >= 0x050900 |
| 234 | # define __ASSUME_CLOSE_RANGE 1 |
| 235 | #else |
| 236 | # define __ASSUME_CLOSE_RANGE 0 |
| 237 | #endif |
| 238 | |
| 239 | /* The FUTEX_LOCK_PI2 operation was introduced across all architectures in Linux |
| 240 | 5.14. */ |
| 241 | #if __LINUX_KERNEL_VERSION >= 0x050e00 |
| 242 | # define __ASSUME_FUTEX_LOCK_PI2 1 |
| 243 | #else |
| 244 | # define __ASSUME_FUTEX_LOCK_PI2 0 |
| 245 | #endif |
| 246 | |
| 247 | /* The clone3 system call was introduced across on most architectures in |
| 248 | Linux 5.3. Not all ports implements it, so it should be used along |
| 249 | HAVE_CLONE3_WRAPPER define. */ |
| 250 | #if __LINUX_KERNEL_VERSION >= 0x050300 |
| 251 | # define __ASSUME_CLONE3 1 |
| 252 | #else |
| 253 | # define __ASSUME_CLONE3 0 |
| 254 | #endif |
| 255 | |
| 256 | /* The fchmodat2 system call was introduced across all architectures |
| 257 | in Linux 6.6. */ |
| 258 | #if __LINUX_KERNEL_VERSION >= 0x060600 |
| 259 | # define __ASSUME_FCHMODAT2 1 |
| 260 | #else |
| 261 | # define __ASSUME_FCHMODAT2 0 |
| 262 | #endif |
| 263 | |
| 264 | /* The mseal system call was introduced across all architectures in Linux 6.10 |
| 265 | (although only supported on 64-bit CPUs). */ |
| 266 | /* zig patch: don't assume kernel version */ |
| 267 | #define __ASSUME_MSEAL 0 |
| 268 | |
| 269 | /* The PIDFD_GET_INFO ioctl was introduced across all architectures in Linux |
| 270 | 6.13. */ |
| 271 | /* zig patch: don't assume kernel version */ |
| 272 | #define __ASSUME_PIDFD_GET_INFO 0 |
| 273 | |
| 274 | #endif /* kernel-features.h */ |