From: Yu Watanabe Date: Mon, 3 Mar 2025 04:15:34 +0000 (+0900) Subject: missing_syscall: drop unnecessary ifdefs for syscall number X-Git-Tag: v258-rc1~1195^2~26 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1d917ba4211805b9ccf3d70e45b460c34f1e8e14;p=thirdparty%2Fsystemd.git missing_syscall: drop unnecessary ifdefs for syscall number Nowadays, we define syscall numbers for newer syscalls. Hence the conditions are not necessary. This also adds several comments about when syscalls are introduced. --- diff --git a/src/basic/missing_syscall.h b/src/basic/missing_syscall.h index af7aa528c6e..6bf9c0d5ae4 100644 --- a/src/basic/missing_syscall.h +++ b/src/basic/missing_syscall.h @@ -24,13 +24,9 @@ /* ======================================================================= */ #if !HAVE_FCHMODAT2 +/* since kernel v6.6 (78252deb023cf0879256fcfbafe37022c390762b) */ static inline int missing_fchmodat2(int dirfd, const char *path, mode_t mode, int flags) { -# ifdef __NR_fchmodat2 return syscall(__NR_fchmodat2, dirfd, path, mode, flags); -# else - errno = ENOSYS; - return -1; -# endif } # define fchmodat2 missing_fchmodat2 @@ -95,12 +91,16 @@ static inline long missing_keyctl(int cmd, unsigned long arg2, unsigned long arg # define keyctl missing_keyctl } +/* ======================================================================= */ + static inline key_serial_t missing_add_key(const char *type, const char *description, const void *payload, size_t plen, key_serial_t ringid) { return syscall(__NR_add_key, type, description, payload, plen, ringid); # define add_key missing_add_key } +/* ======================================================================= */ + static inline key_serial_t missing_request_key(const char *type, const char *description, const char * callout_info, key_serial_t destringid) { return syscall(__NR_request_key, type, description, callout_info, destringid); @@ -114,12 +114,7 @@ static inline key_serial_t missing_request_key(const char *type, const char *des union bpf_attr; static inline int missing_bpf(int cmd, union bpf_attr *attr, size_t size) { -#ifdef __NR_bpf return (int) syscall(__NR_bpf, cmd, attr, size); -#else - errno = ENOSYS; - return -1; -#endif } # define bpf missing_bpf @@ -138,14 +133,7 @@ enum { static inline long missing_set_mempolicy(int mode, const unsigned long *nodemask, unsigned long maxnode) { - long i; -# if defined __NR_set_mempolicy && __NR_set_mempolicy >= 0 - i = syscall(__NR_set_mempolicy, mode, nodemask, maxnode); -# else - errno = ENOSYS; - i = -1; -# endif - return i; + return syscall(__NR_set_mempolicy, mode, nodemask, maxnode); } # define set_mempolicy missing_set_mempolicy @@ -155,14 +143,7 @@ static inline long missing_set_mempolicy(int mode, const unsigned long *nodemask static inline long missing_get_mempolicy(int *mode, unsigned long *nodemask, unsigned long maxnode, void *addr, unsigned long flags) { - long i; -# if defined __NR_get_mempolicy && __NR_get_mempolicy >= 0 - i = syscall(__NR_get_mempolicy, mode, nodemask, maxnode, addr, flags); -# else - errno = ENOSYS; - i = -1; -# endif - return i; + return syscall(__NR_get_mempolicy, mode, nodemask, maxnode, addr, flags); } # define get_mempolicy missing_get_mempolicy @@ -171,6 +152,7 @@ static inline long missing_get_mempolicy(int *mode, unsigned long *nodemask, /* ======================================================================= */ #if !HAVE_PIDFD_SEND_SIGNAL +/* since kernel v5.1 (3eb39f47934f9d5a3027fe00d906a45fe3a15fad) */ static inline int missing_pidfd_send_signal(int fd, int sig, siginfo_t *info, unsigned flags) { return syscall(__NR_pidfd_send_signal, fd, sig, info, flags); } @@ -178,7 +160,10 @@ static inline int missing_pidfd_send_signal(int fd, int sig, siginfo_t *info, un # define pidfd_send_signal missing_pidfd_send_signal #endif +/* ======================================================================= */ + #if !HAVE_PIDFD_OPEN +/* since kernel v5.3 (7615d9e1780e26e0178c93c55b73309a5dc093d7) */ static inline int missing_pidfd_open(pid_t pid, unsigned flags) { return syscall(__NR_pidfd_open, pid, flags); } @@ -190,11 +175,7 @@ static inline int missing_pidfd_open(pid_t pid, unsigned flags) { #if !HAVE_RT_TGSIGQUEUEINFO static inline int missing_rt_tgsigqueueinfo(pid_t tgid, pid_t tid, int sig, siginfo_t *info) { -# if defined __NR_rt_tgsigqueueinfo && __NR_rt_tgsigqueueinfo >= 0 return syscall(__NR_rt_tgsigqueueinfo, tgid, tid, sig, info); -# else -# error "__NR_rt_tgsigqueueinfo not defined" -# endif } # define rt_tgsigqueueinfo missing_rt_tgsigqueueinfo @@ -203,15 +184,11 @@ static inline int missing_rt_tgsigqueueinfo(pid_t tgid, pid_t tid, int sig, sigi /* ======================================================================= */ #if !HAVE_EXECVEAT +/* since kernel v3.19 (51f39a1f0cea1cacf8c787f652f26dfee9611874) */ static inline int missing_execveat(int dirfd, const char *pathname, char *const argv[], char *const envp[], int flags) { -# if defined __NR_execveat && __NR_execveat >= 0 return syscall(__NR_execveat, dirfd, pathname, argv, envp, flags); -# else - errno = ENOSYS; - return -1; -# endif } # undef AT_EMPTY_PATH @@ -222,8 +199,8 @@ static inline int missing_execveat(int dirfd, const char *pathname, /* ======================================================================= */ #if !HAVE_CLOSE_RANGE +/* since kernel v5.9 (9b4feb630e8e9801603f3cab3a36369e3c1cf88d) */ static inline int missing_close_range(unsigned first_fd, unsigned end_fd, unsigned flags) { -# ifdef __NR_close_range /* Kernel-side the syscall expects fds as unsigned integers (just like close() actually), while * userspace exclusively uses signed integers for fds. glibc chose to expose it 1:1 however, hence we * do so here too, even if we end up passing signed fds to it most of the time. */ @@ -231,10 +208,6 @@ static inline int missing_close_range(unsigned first_fd, unsigned end_fd, unsign first_fd, end_fd, flags); -# else - errno = ENOSYS; - return -1; -# endif } # define close_range missing_close_range @@ -243,6 +216,7 @@ static inline int missing_close_range(unsigned first_fd, unsigned end_fd, unsign /* ======================================================================= */ #if !HAVE_MOUNT_SETATTR +/* since kernel v5.12 (2a1867219c7b27f928e2545782b86daaf9ad50bd) */ #if !HAVE_STRUCT_MOUNT_ATTR struct mount_attr { @@ -314,12 +288,7 @@ static inline int missing_mount_setattr( struct mount_attr *attr, size_t size) { -# if defined __NR_mount_setattr && __NR_mount_setattr >= 0 return syscall(__NR_mount_setattr, dfd, path, flags, attr, size); -# else - errno = ENOSYS; - return -1; -# endif } # define mount_setattr missing_mount_setattr @@ -328,6 +297,7 @@ static inline int missing_mount_setattr( /* ======================================================================= */ #if !HAVE_OPEN_TREE +/* since kernel v5.2 (a07b20004793d8926f78d63eb5980559f7813404, d8076bdb56af5e5918376cd1573a6b0007fc1a89) */ #ifndef OPEN_TREE_CLONE #define OPEN_TREE_CLONE 1 @@ -342,12 +312,7 @@ static inline int missing_open_tree( const char *filename, unsigned flags) { -# if defined __NR_open_tree && __NR_open_tree >= 0 return syscall(__NR_open_tree, dfd, filename, flags); -# else - errno = ENOSYS; - return -1; -# endif } # define open_tree missing_open_tree @@ -360,6 +325,7 @@ static inline int missing_open_tree( #endif #if !HAVE_MOVE_MOUNT +/* since kernel v5.2 (2db154b3ea8e14b04fee23e3fdfd5e9d17fbc6ae, d8076bdb56af5e5918376cd1573a6b0007fc1a89) */ #ifndef MOVE_MOUNT_F_EMPTY_PATH #define MOVE_MOUNT_F_EMPTY_PATH 0x00000004 /* Empty from path permitted */ @@ -376,12 +342,7 @@ static inline int missing_move_mount( const char *to_pathname, unsigned flags) { -# if defined __NR_move_mount && __NR_move_mount >= 0 return syscall(__NR_move_mount, from_dfd, from_pathname, to_dfd, to_pathname, flags); -# else - errno = ENOSYS; - return -1; -# endif } # define move_mount missing_move_mount @@ -390,18 +351,14 @@ static inline int missing_move_mount( /* ======================================================================= */ #if !HAVE_FSOPEN +/* since kernel v5.2 (24dcb3d90a1f67fe08c68a004af37df059d74005, d8076bdb56af5e5918376cd1573a6b0007fc1a89) */ #ifndef FSOPEN_CLOEXEC #define FSOPEN_CLOEXEC 0x00000001 #endif static inline int missing_fsopen(const char *fsname, unsigned flags) { -# if defined __NR_fsopen && __NR_fsopen >= 0 return syscall(__NR_fsopen, fsname, flags); -# else - errno = ENOSYS; - return -1; -# endif } # define fsopen missing_fsopen @@ -410,6 +367,7 @@ static inline int missing_fsopen(const char *fsname, unsigned flags) { /* ======================================================================= */ #if !HAVE_FSCONFIG +/* since kernel v5.2 (ecdab150fddb42fe6a739335257949220033b782, d8076bdb56af5e5918376cd1573a6b0007fc1a89) */ #ifndef FSCONFIG_SET_FLAG #define FSCONFIG_SET_FLAG 0 /* Set parameter, supplying no value */ @@ -428,12 +386,7 @@ static inline int missing_fsopen(const char *fsname, unsigned flags) { #endif static inline int missing_fsconfig(int fd, unsigned cmd, const char *key, const void *value, int aux) { -# if defined __NR_fsconfig && __NR_fsconfig >= 0 return syscall(__NR_fsconfig, fd, cmd, key, value, aux); -# else - errno = ENOSYS; - return -1; -# endif } # define fsconfig missing_fsconfig @@ -442,18 +395,14 @@ static inline int missing_fsconfig(int fd, unsigned cmd, const char *key, const /* ======================================================================= */ #if !HAVE_FSMOUNT +/* since kernel v5.2 for (93766fbd2696c2c4453dd8e1070977e9cd4e6b6d, d8076bdb56af5e5918376cd1573a6b0007fc1a89) */ #ifndef FSMOUNT_CLOEXEC #define FSMOUNT_CLOEXEC 0x00000001 #endif static inline int missing_fsmount(int fd, unsigned flags, unsigned ms_flags) { -# if defined __NR_fsmount && __NR_fsmount >= 0 return syscall(__NR_fsmount, fd, flags, ms_flags); -# else - errno = ENOSYS; - return -1; -# endif } # define fsmount missing_fsmount @@ -462,14 +411,8 @@ static inline int missing_fsmount(int fd, unsigned flags, unsigned ms_flags) { /* ======================================================================= */ #if !HAVE_GETDENTS64 - static inline ssize_t missing_getdents64(int fd, void *buffer, size_t length) { -# if defined __NR_getdents64 && __NR_getdents64 >= 0 return syscall(__NR_getdents64, fd, buffer, length); -# else - errno = ENOSYS; - return -1; -# endif } # define getdents64 missing_getdents64 @@ -478,7 +421,7 @@ static inline ssize_t missing_getdents64(int fd, void *buffer, size_t length) { /* ======================================================================= */ #if !HAVE_SCHED_SETATTR - +/* since kernel 3.14 (e6cfc0295c7d51b008999a8b13a44fb43f8685ea) */ static inline ssize_t missing_sched_setattr(pid_t pid, struct sched_attr *attr, unsigned int flags) { return syscall(__NR_sched_setattr, pid, attr, flags); } @@ -503,14 +446,9 @@ int __clone2(int (*fn)(void *), void *stack_base, size_t stack_size, int flags, /* ======================================================================= */ #if !HAVE_QUOTACTL_FD - +/* since kernel v5.14 (64c2c2c62f92339b176ea24403d8db16db36f9e6) */ static inline int missing_quotactl_fd(int fd, int cmd, int id, void *addr) { -# ifdef __NR_quotactl_fd return syscall(__NR_quotactl_fd, fd, cmd, id, addr); -# else - errno = ENOSYS; - return -1; -# endif } # define quotactl_fd missing_quotactl_fd @@ -519,6 +457,7 @@ static inline int missing_quotactl_fd(int fd, int cmd, int id, void *addr) { /* ======================================================================= */ #if !HAVE_SETXATTRAT +/* since kernel v6.13 (6140be90ec70c39fa844741ca3cc807dd0866394) */ struct xattr_args { _align_(8) uint64_t value; uint32_t size; @@ -526,25 +465,18 @@ struct xattr_args { }; static inline int missing_setxattrat(int fd, const char *path, int at_flags, const char *name, const struct xattr_args *args, size_t size) { -# ifdef __NR_setxattrat return syscall(__NR_setxattrat, fd, path, at_flags, name, args, size); -# else - errno = ENOSYS; - return -1; -# endif } # define setxattrat missing_setxattrat #endif +/* ======================================================================= */ + #if !HAVE_REMOVEXATTRAT +/* since kernel v6.13 (6140be90ec70c39fa844741ca3cc807dd0866394) */ static inline int missing_removexattrat(int fd, const char *path, int at_flags, const char *name) { -# ifdef __NR_removexattrat return syscall(__NR_removexattrat, fd, path, at_flags, name); -# else - errno = ENOSYS; - return -1; -# endif } # define removexattrat missing_removexattrat