]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
libc-wrapper: introduce a tiny libc wrapper
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 21 Jun 2025 11:29:51 +0000 (20:29 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 11 Jul 2025 04:05:46 +0000 (13:05 +0900)
Then, move syscall definitions to the wrapper, and prototypes are moved
to relevant headers.

This also adds checks for add_key() and request_key(), as one day
glibc may be going to add some of them separatedly.

The check for fspick in meson.build is dropped, as it is currently
unused in our code.

This also moves
- basic/missing_bpf.h -> include/override/linux/bpf.h,
- basic/missing_keyctl.h -> include/override/linux/keyctl.h.

68 files changed:
meson.build
src/basic/fd-util.c
src/basic/fs-util.c
src/basic/keyring-util.c
src/basic/keyring-util.h
src/basic/missing_syscall.h [deleted file]
src/basic/pidfd-util.h
src/basic/process-util.c
src/basic/signal-util.c
src/basic/xattr-util.c
src/core/bpf-devices.c
src/core/exec-invoke.c
src/core/meson.build
src/home/homework-fscrypt.c
src/home/homework-luks.c
src/home/homework-password-cache.c
src/home/homework.c
src/home/homework.h
src/include/override/linux/bpf.h [moved from src/basic/missing_bpf.h with 90% similarity]
src/include/override/linux/keyctl.h [moved from src/basic/missing_keyctl.h with 90% similarity]
src/include/override/sched.h
src/include/override/signal.h [new file with mode: 0644]
src/include/override/sys/bpf.h [new file with mode: 0644]
src/include/override/sys/ioprio.h [new file with mode: 0644]
src/include/override/sys/kcmp.h [new file with mode: 0644]
src/include/override/sys/keyctl.h [new file with mode: 0644]
src/include/override/sys/mempolicy.h [new file with mode: 0644]
src/include/override/sys/mount.h
src/include/override/sys/pidfd.h
src/include/override/sys/quota.h [new file with mode: 0644]
src/include/override/sys/stat.h [new file with mode: 0644]
src/include/override/sys/xattr.h
src/include/override/unistd.h [new file with mode: 0644]
src/libc/bpf.c [new file with mode: 0644]
src/libc/ioprio.c [new file with mode: 0644]
src/libc/kcmp.c [new file with mode: 0644]
src/libc/keyctl.c [new file with mode: 0644]
src/libc/mempolicy.c [new file with mode: 0644]
src/libc/meson.build [new file with mode: 0644]
src/libc/mount.c [new file with mode: 0644]
src/libc/pidfd.c [new file with mode: 0644]
src/libc/quota.c [new file with mode: 0644]
src/libc/sched.c [new file with mode: 0644]
src/libc/signal.c [new file with mode: 0644]
src/libc/stat.c [new file with mode: 0644]
src/libc/unistd.c [new file with mode: 0644]
src/libc/xattr.c [new file with mode: 0644]
src/libsystemd/meson.build
src/libsystemd/sd-id128/sd-id128.c
src/login/pam_systemd_loadkey.c
src/login/user-runtime-dir.c
src/nspawn/nspawn.c
src/nsresourced/nsresourcework.c
src/repart/meson.build
src/shared/ask-password-api.c
src/shared/bpf-program.c
src/shared/ioprio-util.h
src/shared/meson.build
src/shared/mount-util.c
src/shared/numa-util.c
src/shared/numa-util.h
src/shared/quota-util.c
src/shared/switch-root.c
src/shutdown/meson.build
src/sysusers/meson.build
src/test/meson.build
src/test/test-seccomp.c
src/tmpfiles/meson.build

index b97fe3aa414234dc840601b73f01892b580d36e6..f5362ece8a70c0c56d576925e8c1b5b6d8a48293 100644 (file)
@@ -580,7 +580,6 @@ foreach ident : [
         ['fsconfig',          '''#include <sys/mount.h>'''],    # since glibc-2.36
         ['fsmount',           '''#include <sys/mount.h>'''],    # since glibc-2.36
         ['fsopen',            '''#include <sys/mount.h>'''],    # since glibc-2.36
-        ['fspick',            '''#include <sys/mount.h>'''],    # since glibc-2.36
         ['mount_setattr',     '''#include <sys/mount.h>'''],    # since glibc-2.36
         ['move_mount',        '''#include <sys/mount.h>'''],    # since glibc-2.36
         ['open_tree',         '''#include <sys/mount.h>'''],    # since glibc-2.36
@@ -591,15 +590,17 @@ foreach ident : [
         ['ioprio_get',        '''#include <sched.h>'''],        # no known header declares ioprio_get
         ['ioprio_set',        '''#include <sched.h>'''],        # no known header declares ioprio_set
         ['rt_tgsigqueueinfo', '''#include <signal.h>'''],       # no known header declares rt_tgsigqueueinfo
+        ['open_tree_attr',    '''#include <sys/mount.h>'''],    # no known header declares open_tree_attr
         ['quotactl_fd',       '''#include <sys/quota.h>'''],    # no known header declares quotactl_fd
         ['fchmodat2',         '''#include <sys/stat.h>'''],     # no known header declares fchmodat2
         ['bpf',               '''#include <sys/syscall.h>'''],  # no known header declares bpf
         ['kcmp',              '''#include <sys/syscall.h>'''],  # no known header declares kcmp
         ['keyctl',            '''#include <sys/syscall.h>'''],  # no known header declares keyctl
-        ['pivot_root',        '''#include <sys/syscall.h>'''],  # no known header declares pivot_root
+        ['add_key',           '''#include <sys/syscall.h>'''],  # no known header declares add_key
+        ['request_key',       '''#include <sys/syscall.h>'''],  # no known header declares request_key
         ['setxattrat',        '''#include <sys/xattr.h>'''],    # no known header declares setxattrat
         ['removexattrat',     '''#include <sys/xattr.h>'''],    # no known header declares removexattrat
-        ['open_tree_attr',    '''#include <sys/mount.h>'''],    # no known header declares open_tree_attr
+        ['pivot_root',        '''#include <unistd.h>'''],       # no known header declares pivot_root
 ]
 
         have = cc.has_function(ident[0], prefix : ident[1], args : '-D_GNU_SOURCE')
@@ -2057,6 +2058,7 @@ includes = [libsystemd_includes, include_directories('src/shared')]
 subdir('po')
 subdir('catalog')
 subdir('src/include')
+subdir('src/libc')
 subdir('src/fundamental')
 subdir('src/basic')
 subdir('src/libsystemd')
@@ -2072,7 +2074,8 @@ libsystemd = shared_library(
                      # Make sure our library is never deleted from memory, so that our open logging fds don't leak on dlopen/dlclose cycles.
                      '-z', 'nodelete',
                      '-Wl,--version-script=' + libsystemd_sym_path],
-        link_with : [libbasic_static],
+        link_with : [libc_wrapper_static,
+                     libbasic_static],
         link_whole : [libsystemd_static],
         dependencies : [librt,
                         threads,
@@ -2085,6 +2088,7 @@ libsystemd = shared_library(
 if static_libsystemd != 'false'
         install_libsystemd_static = static_library(
                 'systemd',
+                libc_wrapper_sources,
                 libsystemd_sources,
                 basic_sources,
                 fundamental_sources,
@@ -2130,6 +2134,7 @@ libudev = shared_library(
 if static_libudev != 'false'
         install_libudev_static = static_library(
                 'udev',
+                libc_wrapper_sources,
                 basic_sources,
                 fundamental_sources,
                 shared_sources,
@@ -2234,6 +2239,7 @@ nss_template = {
         # Note that we link NSS modules with '-z nodelete' so that mempools never get orphaned
         'link_args' : ['-z', 'nodelete'],
         'link_with' : [
+                libc_wrapper_static,
                 libsystemd_static,
                 libshared_static,
                 libbasic_static,
index 9cfaf8a84957b106ec520eebbb7f509d7c7cd172..a6118b4247a2a97ec96f36c2489c1d6b0cb018fc 100644 (file)
@@ -2,8 +2,8 @@
 
 #include <fcntl.h>
 #include <linux/fs.h>
-#include <linux/kcmp.h>
 #include <sys/ioctl.h>
+#include <sys/kcmp.h>
 #include <sys/resource.h>
 #include <sys/stat.h>
 #include <unistd.h>
@@ -16,7 +16,6 @@
 #include "format-util.h"
 #include "fs-util.h"
 #include "log.h"
-#include "missing_syscall.h"
 #include "mountpoint-util.h"
 #include "parse-util.h"
 #include "path-util.h"
index 3a3b09776a3df7ae8783e4e231128c4b80703315..9fb6f5d0b82d8eb884d585c134c4e46c8ef4f662 100644 (file)
@@ -16,7 +16,6 @@
 #include "label.h"
 #include "lock-util.h"
 #include "log.h"
-#include "missing_syscall.h"
 #include "mkdir.h"
 #include "path-util.h"
 #include "process-util.h"
index 6bfc5e38f62bcfbaacdf4844a6b93d2a6033cc23..4158537bd460fb8162776d3f4b9c0a3cdda5a5c4 100644 (file)
@@ -3,7 +3,6 @@
 #include "alloc-util.h"
 #include "keyring-util.h"
 #include "log.h"
-#include "missing_syscall.h"
 
 int keyring_read(key_serial_t serial, void **ret, size_t *ret_size) {
         size_t bufsize = 100;
index a949f8907e1d69f8c473325b16eae939f480f24a..b8a36a9ad6f311a0d14b9db55e7ec1d6fece110d 100644 (file)
@@ -1,8 +1,9 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
+#include <sys/keyctl.h>         /* IWYU pragma: export */
+
 #include "forward.h"
-#include "missing_keyctl.h"
 
 /* Like TAKE_PTR() but for key_serial_t, resetting them to -1 */
 #define TAKE_KEY_SERIAL(key_serial) TAKE_GENERIC(key_serial, key_serial_t, -1)
diff --git a/src/basic/missing_syscall.h b/src/basic/missing_syscall.h
deleted file mode 100644 (file)
index 994bda9..0000000
+++ /dev/null
@@ -1,244 +0,0 @@
-/* SPDX-License-Identifier: LGPL-2.1-or-later */
-#pragma once
-
-/* Missing glibc definitions to access certain kernel APIs */
-
-#include <linux/mempolicy.h>
-#include <sched.h>
-#include <signal.h>
-#include <sys/syscall.h>
-#include <sys/xattr.h>
-#include <unistd.h>
-
-#include "forward.h"
-#include "missing_keyctl.h"
-
-/* ======================================================================= */
-
-#if !HAVE_FCHMODAT2
-/* since kernel v6.6 (78252deb023cf0879256fcfbafe37022c390762b) */
-static inline int missing_fchmodat2(int dirfd, const char *path, mode_t mode, int flags) {
-        return syscall(__NR_fchmodat2, dirfd, path, mode, flags);
-}
-
-#  define fchmodat2 missing_fchmodat2
-#endif
-
-/* ======================================================================= */
-
-#if !HAVE_PIVOT_ROOT
-static inline int missing_pivot_root(const char *new_root, const char *put_old) {
-        return syscall(__NR_pivot_root, new_root, put_old);
-}
-
-#  define pivot_root missing_pivot_root
-#endif
-
-/* ======================================================================= */
-
-#if !HAVE_IOPRIO_GET
-static inline int missing_ioprio_get(int which, int who) {
-        return syscall(__NR_ioprio_get, which, who);
-}
-
-#  define ioprio_get missing_ioprio_get
-#endif
-
-/* ======================================================================= */
-
-#if !HAVE_IOPRIO_SET
-static inline int missing_ioprio_set(int which, int who, int ioprio) {
-        return syscall(__NR_ioprio_set, which, who, ioprio);
-}
-
-#  define ioprio_set missing_ioprio_set
-#endif
-
-/* ======================================================================= */
-
-#if !HAVE_KCMP
-static inline int missing_kcmp(pid_t pid1, pid_t pid2, int type, unsigned long idx1, unsigned long idx2) {
-        return syscall(__NR_kcmp, pid1, pid2, type, idx1, idx2);
-}
-
-#  define kcmp missing_kcmp
-#endif
-
-/* ======================================================================= */
-
-#if !HAVE_KEYCTL
-static inline long missing_keyctl(int cmd, unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5) {
-        return syscall(__NR_keyctl, cmd, arg2, arg3, arg4, arg5);
-
-#  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);
-
-#  define request_key missing_request_key
-}
-#endif
-
-/* ======================================================================= */
-
-#if !HAVE_BPF
-union bpf_attr;
-
-static inline int missing_bpf(int cmd, union bpf_attr *attr, size_t size) {
-        return (int) syscall(__NR_bpf, cmd, attr, size);
-}
-
-#  define bpf missing_bpf
-#endif
-
-/* ======================================================================= */
-
-#if !HAVE_SET_MEMPOLICY
-static inline long missing_set_mempolicy(int mode, const unsigned long *nodemask,
-                           unsigned long maxnode) {
-        return syscall(__NR_set_mempolicy, mode, nodemask, maxnode);
-}
-
-#  define set_mempolicy missing_set_mempolicy
-#endif
-
-#if !HAVE_GET_MEMPOLICY
-static inline long missing_get_mempolicy(int *mode, unsigned long *nodemask,
-                           unsigned long maxnode, void *addr,
-                           unsigned long flags) {
-        return syscall(__NR_get_mempolicy, mode, nodemask, maxnode, addr, flags);
-}
-
-#  define get_mempolicy missing_get_mempolicy
-#endif
-
-/* ======================================================================= */
-
-#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);
-}
-
-#  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);
-}
-
-#  define pidfd_open missing_pidfd_open
-#endif
-
-/* ======================================================================= */
-
-#if !HAVE_RT_TGSIGQUEUEINFO
-static inline int missing_rt_tgsigqueueinfo(pid_t tgid, pid_t tid, int sig, siginfo_t *info) {
-        return syscall(__NR_rt_tgsigqueueinfo, tgid, tid, sig, info);
-}
-
-#  define rt_tgsigqueueinfo missing_rt_tgsigqueueinfo
-#endif
-
-/* ======================================================================= */
-
-#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) {
-        return syscall(__NR_execveat, dirfd, pathname, argv, envp, flags);
-}
-
-#  define execveat missing_execveat
-#endif
-
-/* ======================================================================= */
-
-#if !HAVE_CLOSE_RANGE
-/* since kernel v5.9 (9b4feb630e8e9801603f3cab3a36369e3c1cf88d) */
-static inline int missing_close_range(unsigned first_fd, unsigned end_fd, unsigned flags) {
-        /* 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. */
-        return syscall(__NR_close_range,
-                       first_fd,
-                       end_fd,
-                       flags);
-}
-
-#  define close_range missing_close_range
-#endif
-
-/* ======================================================================= */
-
-#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);
-}
-
-#  define sched_setattr missing_sched_setattr
-#endif
-
-/* ======================================================================= */
-
-/* glibc does not provide clone() on ia64, only clone2(). Not only that, but it also doesn't provide a
- * prototype, only the symbol in the shared library (it provides a prototype for clone(), but not the
- * symbol in the shared library). */
-#if defined(__ia64__)
-int __clone2(int (*fn)(void *), void *stack_base, size_t stack_size, int flags, void *arg);
-#define HAVE_CLONE 0
-#else
-/* We know that everywhere else clone() is available, so we don't bother with a meson check (that takes time
- * at build time) and just define it. Once the kernel drops ia64 support, we can drop this too. */
-#define HAVE_CLONE 1
-#endif
-
-/* ======================================================================= */
-
-#if !HAVE_QUOTACTL_FD
-/* since kernel v5.14 (64c2c2c62f92339b176ea24403d8db16db36f9e6) */
-static inline int missing_quotactl_fd(int fd, int cmd, int id, void *addr) {
-        return syscall(__NR_quotactl_fd, fd, cmd, id, addr);
-}
-
-#  define quotactl_fd missing_quotactl_fd
-#endif
-
-/* ======================================================================= */
-
-#if !HAVE_SETXATTRAT
-/* since kernel v6.13 (6140be90ec70c39fa844741ca3cc807dd0866394) */
-static inline int missing_setxattrat(int fd, const char *path, int at_flags, const char *name, const struct xattr_args *args, size_t size) {
-        return syscall(__NR_setxattrat, fd, path, at_flags, name, args, size);
-}
-
-#  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) {
-        return syscall(__NR_removexattrat, fd, path, at_flags, name);
-}
-
-#  define removexattrat missing_removexattrat
-#endif
index 0cc247ced16372eafe9532e63eac4a7e06f62907..811d40dce9effee1fe5ed98fbef4d9ee1b53c60a 100644 (file)
@@ -4,7 +4,6 @@
 #include <sys/pidfd.h>          /* IWYU pragma: export */
 
 #include "forward.h"
-#include "missing_syscall.h"    /* IWYU pragma: export */
 
 int pidfd_get_namespace(int fd, unsigned long ns_type_cmd);
 
index 1d341aa0a7e937a19c12c993bb9f2493fa850e48..de9784381668521ef8028723e8d80bf553f71776 100644 (file)
@@ -34,7 +34,6 @@
 #include "locale-util.h"
 #include "log.h"
 #include "memory-util.h"
-#include "missing_syscall.h"
 #include "mountpoint-util.h"
 #include "namespace-util.h"
 #include "nulstr-util.h"
index 5a14046f017c3d4001d449ab3512b3832ff00a3f..459328a3c722a0a8ddec2d4579d04a01046b8c28 100644 (file)
@@ -4,7 +4,6 @@
 #include <unistd.h>
 
 #include "errno-util.h"
-#include "missing_syscall.h"
 #include "parse-util.h"
 #include "signal-util.h"
 #include "stdio-util.h"
index 15072add7809dc5680a3449e9f18084085094315..1bde725d1a7f40160524d90731c589a55bed7f04 100644 (file)
@@ -8,7 +8,6 @@
 #include "errno-util.h"
 #include "fd-util.h"
 #include "fs-util.h"
-#include "missing_syscall.h"
 #include "nulstr-util.h"
 #include "parse-util.h"
 #include "sparse-endian.h"
index 7e6a1d15a4e86a8cb0c1085839acef1eb8346eb9..ef8ba3d57230d65ef51cbae9850401b20eeac93d 100644 (file)
@@ -1,6 +1,7 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
 #include <fnmatch.h>
+#include <linux/bpf.h>
 #include <linux/bpf_insn.h>
 #include <sys/stat.h>
 
@@ -12,7 +13,6 @@
 #include "fd-util.h"
 #include "fileio.h"
 #include "log.h"
-#include "missing_bpf.h"
 #include "nulstr-util.h"
 #include "parse-util.h"
 #include "path-util.h"
index 3853aef4afcd61d86c1939b95b7bd453065116c8..771308848a90f79096e7ba6c6b45e05d54b76cbe 100644 (file)
@@ -1,13 +1,14 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
 #include <grp.h>
-#include <linux/ioprio.h>
 #include <linux/prctl.h>
 #include <linux/sched.h>
 #include <linux/securebits.h>
 #include <poll.h>
 #include <sys/eventfd.h>
 #include <sys/ioctl.h>
+#include <sys/ioprio.h>
+#include <sys/keyctl.h>
 #include <sys/mount.h>
 #include <sys/prctl.h>
 #include <sys/statvfs.h>
@@ -54,7 +55,6 @@
 #include "journal-send.h"
 #include "manager.h"
 #include "memfd-util.h"
-#include "missing_syscall.h"
 #include "mkdir-label.h"
 #include "mount-util.h"
 #include "namespace-util.h"
index 067ecee30321ecd22b8e53b8fc295d761f8126f4..991c3bb0d19c8493e2df40a505261c078b30d041 100644 (file)
@@ -181,6 +181,7 @@ executor_libs = get_option('link-executor-shared') ? \
                 libcore,
                 libshared,
         ] : [
+                libc_wrapper_static,
                 libcore_static,
                 libshared_static,
                 libbasic_static,
index 8a3bb27655a8d711760faebf50df4a2cccc8a3af..bfcfb6774f0343cc4fa3374285531efc706b4bcd 100644 (file)
@@ -22,8 +22,6 @@
 #include "keyring-util.h"
 #include "log.h"
 #include "memory-util.h"
-#include "missing_keyctl.h"
-#include "missing_syscall.h"
 #include "mkdir.h"
 #include "mount-util.h"
 #include "nulstr-util.h"
index 326f941312e599a84720f8aa59ffb899237be6a4..5c6bd280880bc871966f6891aa5a5be9062dbf71 100644 (file)
@@ -46,7 +46,6 @@
 #include "loop-util.h"
 #include "memory-util.h"
 #include "missing_magic.h"
-#include "missing_syscall.h"
 #include "mkdir.h"
 #include "mkfs-util.h"
 #include "openssl-util.h"
index cd497b46e7b0029782171806b3d270d0d22c4b3b..fb205153bcedb948448a3fd7624ee258994b2062 100644 (file)
@@ -4,7 +4,6 @@
 #include "homework-password-cache.h"
 #include "keyring-util.h"
 #include "log.h"
-#include "missing_syscall.h"
 #include "string-util.h"
 #include "user-record.h"
 
index 57a7b773447544a166dfbbd44c34f097f33498f9..1056d27b8b45d4bc9035af89080895f30e9160c1 100644 (file)
@@ -36,7 +36,6 @@
 #include "main-func.h"
 #include "memory-util.h"
 #include "missing_magic.h"
-#include "missing_syscall.h"
 #include "mount-util.h"
 #include "path-util.h"
 #include "recovery-key.h"
index abd1c482da80bd022299efdc7b0292776deaa621..2060d15827e04398c16e61fe3473db5a77f2263a 100644 (file)
@@ -2,11 +2,11 @@
 #pragma once
 
 #include <linux/fscrypt.h>
+#include <sys/keyctl.h>
 
 #include "sd-id128.h"
 
 #include "homework-forward.h"
-#include "missing_keyctl.h"
 #include "user-record-util.h"
 
 typedef struct HomeSetup {
similarity index 90%
rename from src/basic/missing_bpf.h
rename to src/include/override/linux/bpf.h
index 968bcdfb2d7203cc9434909f46c95f41a214c09d..f33c748fde2a15ded6fa9e640435e167c20488f4 100644 (file)
@@ -1,7 +1,7 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
-#include <linux/bpf.h> /* IWYU pragma: export */
+#include_next <linux/bpf.h>     /* IWYU pragma: export */
 
 /* defined in linux/filter.h */
 /* Unconditional jumps, goto pc + off16 */
similarity index 90%
rename from src/basic/missing_keyctl.h
rename to src/include/override/linux/keyctl.h
index 8a9c82b9b45f65d2bcc1254dd54083adf5bb425e..1f0988371a23b5c3ff106e2404ebe677001c4c8f 100644 (file)
@@ -1,9 +1,9 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
-#include <linux/keyctl.h> /* IWYU pragma: export */
+#include_next <linux/keyctl.h>  /* IWYU pragma: export */
 
-#include "forward.h"
+#include <stdint.h>
 
 /* From linux/key.h */
 #ifndef KEY_POS_VIEW
@@ -42,5 +42,5 @@ typedef int32_t key_serial_t;
 #  define KEY_OTH_SETATTR 0x00000020
 #  define KEY_OTH_ALL     0x0000003f
 #else
-assert_cc(KEY_OTH_ALL == 0x0000003f);
+static_assert(KEY_OTH_ALL == 0x0000003f, "");
 #endif
index 41c830e26b5569f14af681ed7d4422ee8dad099b..f2748b1608e69a364c5cb0d217bfd5676aa01aed 100644 (file)
@@ -35,3 +35,22 @@ static_assert(PF_KTHREAD == 0x00200000, "");
 #else
 static_assert(TASK_COMM_LEN == 16, "");
 #endif
+
+/* glibc does not provide clone() on ia64, only clone2(). Not only that, but it also doesn't provide a
+ * prototype, only the symbol in the shared library (it provides a prototype for clone(), but not the
+ * symbol in the shared library). */
+#if defined(__ia64__)
+int __clone2(int (*fn)(void *), void *stack_base, size_t stack_size, int flags, void *arg);
+#define HAVE_CLONE 0
+#else
+/* We know that everywhere else clone() is available, so we don't bother with a meson check (that takes time
+ * at build time) and just define it. Once the kernel drops ia64 support, we can drop this too. */
+#define HAVE_CLONE 1
+#endif
+
+/* Defined since glibc-2.41.
+ * Supported since kernel 3.14 (e6cfc0295c7d51b008999a8b13a44fb43f8685ea). */
+#if !HAVE_SCHED_SETATTR
+int missing_sched_setattr(pid_t pid, struct sched_attr *attr, unsigned flags);
+#  define sched_setattr missing_sched_setattr
+#endif
diff --git a/src/include/override/signal.h b/src/include/override/signal.h
new file mode 100644 (file)
index 0000000..83aa18d
--- /dev/null
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#pragma once
+
+#include_next <signal.h>
+
+#if !HAVE_RT_TGSIGQUEUEINFO
+int missing_rt_tgsigqueueinfo(pid_t tgid, pid_t tid, int sig, siginfo_t *info);
+#  define rt_tgsigqueueinfo missing_rt_tgsigqueueinfo
+#endif
diff --git a/src/include/override/sys/bpf.h b/src/include/override/sys/bpf.h
new file mode 100644 (file)
index 0000000..56e1466
--- /dev/null
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#pragma once
+
+#include <linux/bpf.h>          /* IWYU pragma: export */
+#include <stddef.h>
+
+/* Supported since kernel v3.18 (749730ce42a2121e1c88350d69478bff3994b10a). */
+#if !HAVE_BPF
+int missing_bpf(int cmd, union bpf_attr *attr, size_t size);
+#  define bpf missing_bpf
+#endif
diff --git a/src/include/override/sys/ioprio.h b/src/include/override/sys/ioprio.h
new file mode 100644 (file)
index 0000000..c361eba
--- /dev/null
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#pragma once
+
+#include <linux/ioprio.h>       /* IWYU pragma: export */
+
+#if !HAVE_IOPRIO_GET
+int missing_ioprio_get(int which, int who);
+#  define ioprio_get missing_ioprio_get
+#endif
+
+#if !HAVE_IOPRIO_SET
+int missing_ioprio_set(int which, int who, int ioprio);
+#  define ioprio_set missing_ioprio_set
+#endif
diff --git a/src/include/override/sys/kcmp.h b/src/include/override/sys/kcmp.h
new file mode 100644 (file)
index 0000000..4e47825
--- /dev/null
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#pragma once
+
+#include <linux/kcmp.h>         /* IWYU pragma: export */
+#include <sys/types.h>
+
+/* Supported since kernel v3.5 (d97b46a64674a267bc41c9e16132ee2a98c3347d). */
+#if !HAVE_KCMP
+int missing_kcmp(pid_t pid1, pid_t pid2, int type, unsigned long idx1, unsigned long idx2);
+#  define kcmp missing_kcmp
+#endif
diff --git a/src/include/override/sys/keyctl.h b/src/include/override/sys/keyctl.h
new file mode 100644 (file)
index 0000000..88c9c40
--- /dev/null
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#pragma once
+
+#include <linux/keyctl.h>       /* IWYU pragma: export */
+#include <stddef.h>
+
+#if !HAVE_KEYCTL
+long missing_keyctl(int cmd, unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5);
+#  define keyctl missing_keyctl
+#endif
+
+#if !HAVE_ADD_KEY
+key_serial_t missing_add_key(const char *type, const char *description, const void *payload, size_t plen, key_serial_t ringid);
+#  define add_key missing_add_key
+#endif
+
+#if !HAVE_REQUEST_KEY
+key_serial_t missing_request_key(const char *type, const char *description, const char *callout_info, key_serial_t destringid);
+#  define request_key missing_request_key
+#endif
diff --git a/src/include/override/sys/mempolicy.h b/src/include/override/sys/mempolicy.h
new file mode 100644 (file)
index 0000000..9858f28
--- /dev/null
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#pragma once
+
+#include <linux/mempolicy.h>    /* IWYU pragma: export */
+
+#if !HAVE_SET_MEMPOLICY
+int missing_set_mempolicy(int mode, const unsigned long *nodemask, unsigned long maxnode);
+#  define set_mempolicy missing_set_mempolicy
+#endif
+
+#if !HAVE_GET_MEMPOLICY
+int missing_get_mempolicy(int *mode, unsigned long *nodemask, unsigned long maxnode, void *addr, unsigned long flags);
+#  define get_mempolicy missing_get_mempolicy
+#endif
index 050c23cc6ab177144a55a3c79ed4afc727e495c8..33a843b8f4a153573e1508e33984e3ac6af6b4f4 100644 (file)
@@ -8,8 +8,6 @@
 #include <stddef.h>
 #include <stdint.h>
 #include <sys/ioctl.h>
-#include <sys/syscall.h>
-#include <unistd.h>
 
 /* Since glibc-2.37 (774058d72942249f71d74e7f2b639f77184160a6), sys/mount.h includes linux/mount.h, and
  * we can safely include both headers in the same source file. However, we cannot do that with older glibc.
@@ -41,67 +39,56 @@ extern int umount2(const char *__special_file, int __flags) __THROW;
 
 /* Open the filesystem referenced by FS_NAME so it can be configured for
    mouting.  */
+/* Defined since glibc-2.36.
+ * Supported since kernel v5.2 (24dcb3d90a1f67fe08c68a004af37df059d74005). */
 #if HAVE_FSOPEN
 extern int fsopen(const char *__fs_name, unsigned int __flags) __THROW;
 #else
-static inline int missing_fsopen(const char *fsname, unsigned flags) {
-        return syscall(__NR_fsopen, fsname, flags);
-}
+int missing_fsopen(const char *fsname, unsigned flags);
 #  define fsopen missing_fsopen
 #endif
 
 /* Create a mount representation for the FD created by fsopen using
    FLAGS with ATTR_FLAGS describing how the mount is to be performed.  */
+/* Defined since glibc-2.36.
+ * Supported since kernel v5.2 (93766fbd2696c2c4453dd8e1070977e9cd4e6b6d). */
 #if HAVE_FSMOUNT
 extern int fsmount(int __fd, unsigned int __flags, unsigned int __ms_flags) __THROW;
 #else
-static inline int missing_fsmount(int fd, unsigned flags, unsigned ms_flags) {
-        return syscall(__NR_fsmount, fd, flags, ms_flags);
-}
+int missing_fsmount(int fd, unsigned flags, unsigned ms_flags);
 #  define fsmount missing_fsmount
 #endif
 
 /* Add the mounted FROM_DFD referenced by FROM_PATHNAME filesystem returned
    by fsmount in the hierarchy in the place TO_DFD reference by TO_PATHNAME
    using FLAGS.  */
+/* Defined since glibc-2.36.
+ * Supported since kernel v5.2 (2db154b3ea8e14b04fee23e3fdfd5e9d17fbc6ae). */
 #if HAVE_MOVE_MOUNT
 extern int move_mount(int __from_dfd, const char *__from_pathname, int __to_dfd, const char *__to_pathname, unsigned int flags) __THROW;
 #else
-static inline int missing_move_mount(
-                int from_dfd,
-                const char *from_pathname,
-                int to_dfd,
-                const char *to_pathname,
-                unsigned flags) {
-
-        return syscall(__NR_move_mount, from_dfd, from_pathname, to_dfd, to_pathname, flags);
-}
+int missing_move_mount(int from_dfd, const char *from_pathname, int to_dfd, const char *to_pathname, unsigned flags);
 #  define move_mount missing_move_mount
 #endif
 
 /* Set parameters and trigger CMD action on the FD context.  KEY, VALUE,
    and AUX are used depending ng of the CMD.  */
+/* Defined since glibc-2.36.
+ * Supported since kernel v5.2 (ecdab150fddb42fe6a739335257949220033b782). */
 #if HAVE_FSCONFIG
 extern int fsconfig(int __fd, unsigned int __cmd, const char *__key, const void *__value, int __aux) __THROW;
 #else
-static inline int missing_fsconfig(int fd, unsigned cmd, const char *key, const void *value, int aux) {
-        return syscall(__NR_fsconfig, fd, cmd, key, value, aux);
-}
+int missing_fsconfig(int fd, unsigned cmd, const char *key, const void *value, int aux);
 #  define fsconfig missing_fsconfig
 #endif
 
-/* Equivalent of fopen for an existing mount point.  */
-#if HAVE_FSPICK
-extern int fspick(int __dfd, const char *__path, unsigned int __flags) __THROW;
-#endif
-
 /* Open the mount point FILENAME in directory DFD using FLAGS.  */
+/* Defined since glibc-2.36.
+ * Supported since kernel v5.2 (a07b20004793d8926f78d63eb5980559f7813404). */
 #if HAVE_OPEN_TREE
 extern int open_tree(int __dfd, const char *__filename, unsigned int __flags) __THROW;
 #else
-static inline int missing_open_tree(int dfd, const char *filename, unsigned flags) {
-        return syscall(__NR_open_tree, dfd, filename, flags);
-}
+int missing_open_tree(int dfd, const char *filename, unsigned flags);
 #  define open_tree missing_open_tree
 #endif
 
@@ -110,21 +97,20 @@ static inline int missing_open_tree(int dfd, const char *filename, unsigned flag
    directory referred to by the file descriptor dirfd.  Otherwise if DFD is
    the special value AT_FDCWD then PATH is interpreted relative to the current
    working directory of the calling process.  */
+/* Defined since glibc-2.36.
+ * Supported since kernel v5.12 (2a1867219c7b27f928e2545782b86daaf9ad50bd). */
 #if HAVE_MOUNT_SETATTR
 extern int mount_setattr(int __dfd, const char *__path, unsigned int __flags, struct mount_attr *__uattr, size_t __usize) __THROW;
 #else
-static inline int missing_mount_setattr(int dfd, const char *path, unsigned flags, struct mount_attr *attr, size_t size) {
-        return syscall(__NR_mount_setattr, dfd, path, flags, attr, size);
-}
+int missing_mount_setattr(int dfd, const char *path, unsigned flags, struct mount_attr *attr, size_t size);
 #  define mount_setattr missing_mount_setattr
 #endif
 
+/* Not defined in glibc yet as of glibc-2.41.
+ * Supported since kernel v6.15 (c4a16820d90199409c9bf01c4f794e1e9e8d8fd8). */
 #if HAVE_OPEN_TREE_ATTR
 extern int open_tree_attr(int __dfd, const char *__filename, unsigned int __flags, struct mount_attr *__uattr, size_t __usize) __THROW;
 #else
-static inline int missing_open_tree_attr(int dfd, const char *filename, unsigned int flags, struct mount_attr *attr, size_t size) {
-        return syscall(__NR_open_tree_attr, dfd, filename, flags, attr, size);
-}
-
+int missing_open_tree_attr(int dfd, const char *filename, unsigned int flags, struct mount_attr *attr, size_t size);
 #  define open_tree_attr missing_open_tree_attr
 #endif
index de13144524bae1417f82eaf5345a7c0b32a07999..69eb2eaff973863692424ace6af2d317cad9fe57 100644 (file)
@@ -1,14 +1,29 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
-#include <linux/types.h>
-#include <sys/ioctl.h>
-
 /* since glibc-2.36 */
 #if HAVE_PIDFD_OPEN
 #include_next <sys/pidfd.h>
 #endif
 
+#include <linux/types.h>
+#include <signal.h>
+#include <sys/ioctl.h>
+
+/* Defined since glibc-2.36.
+ * Supported since kernel v5.3 (7615d9e1780e26e0178c93c55b73309a5dc093d7). */
+#if !HAVE_PIDFD_OPEN
+int missing_pidfd_open(pid_t pid, unsigned flags);
+#  define pidfd_open missing_pidfd_open
+#endif
+
+/* Defined since glibc-2.36.
+ * Supported since kernel v5.1 (3eb39f47934f9d5a3027fe00d906a45fe3a15fad). */
+#if !HAVE_PIDFD_SEND_SIGNAL
+int missing_pidfd_send_signal(int fd, int sig, siginfo_t *info, unsigned flags);
+#  define pidfd_send_signal missing_pidfd_send_signal
+#endif
+
 /* since glibc-2.41 */
 #ifndef PIDFS_IOCTL_MAGIC
 #  define PIDFS_IOCTL_MAGIC 0xFF
diff --git a/src/include/override/sys/quota.h b/src/include/override/sys/quota.h
new file mode 100644 (file)
index 0000000..481dbab
--- /dev/null
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#pragma once
+
+#include_next <sys/quota.h>
+
+/* Supported since kernel v5.14 (64c2c2c62f92339b176ea24403d8db16db36f9e6). */
+#if !HAVE_QUOTACTL_FD
+int missing_quotactl_fd(int fd, int cmd, int id, void *addr);
+#  define quotactl_fd missing_quotactl_fd
+#endif
diff --git a/src/include/override/sys/stat.h b/src/include/override/sys/stat.h
new file mode 100644 (file)
index 0000000..37793cf
--- /dev/null
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#pragma once
+
+#include_next <sys/stat.h>
+
+/* Supported since kernel v6.6 (78252deb023cf0879256fcfbafe37022c390762b). */
+#if !HAVE_FCHMODAT2
+int missing_fchmodat2(int dirfd, const char *path, mode_t mode, int flags);
+#  define fchmodat2 missing_fchmodat2
+#endif
index 96534832ce6c6ea594db2c3e0b62f01117f36cfe..711c5387c1879443d81fcf4795f3afcfae0b09d2 100644 (file)
@@ -6,3 +6,15 @@
 #include <linux/xattr.h>
 
 #include_next <sys/xattr.h>
+
+/* Supported since kernel v6.13 (6140be90ec70c39fa844741ca3cc807dd0866394). */
+#if !HAVE_SETXATTRAT
+int missing_setxattrat(int fd, const char *path, int at_flags, const char *name, const struct xattr_args *args, size_t size);
+#  define setxattrat missing_setxattrat
+#endif
+
+/* Supported since kernel v6.13 (6140be90ec70c39fa844741ca3cc807dd0866394). */
+#if !HAVE_REMOVEXATTRAT
+int missing_removexattrat(int fd, const char *path, int at_flags, const char *name);
+#  define removexattrat missing_removexattrat
+#endif
diff --git a/src/include/override/unistd.h b/src/include/override/unistd.h
new file mode 100644 (file)
index 0000000..d381f06
--- /dev/null
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#pragma once
+
+#include_next <unistd.h>
+
+/* Defined since glibc-2.34.
+ * Supported since kernel v5.9 (9b4feb630e8e9801603f3cab3a36369e3c1cf88d). */
+#if !HAVE_CLOSE_RANGE
+int missing_close_range(unsigned first_fd, unsigned end_fd, unsigned flags);
+#  define close_range missing_close_range
+#endif
+
+/* Defined since glibc-2.34.
+ * Supported since kernel v3.19 (51f39a1f0cea1cacf8c787f652f26dfee9611874). */
+#if !HAVE_EXECVEAT
+int missing_execveat(int dirfd, const char *pathname, char * const argv[], char * const envp[], int flags);
+#  define execveat missing_execveat
+#endif
+
+#if !HAVE_PIVOT_ROOT
+int missing_pivot_root(const char *new_root, const char *put_old);
+#  define pivot_root missing_pivot_root
+#endif
diff --git a/src/libc/bpf.c b/src/libc/bpf.c
new file mode 100644 (file)
index 0000000..4a7498e
--- /dev/null
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include <sys/bpf.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+
+#if !HAVE_BPF
+int missing_bpf(int cmd, union bpf_attr *attr, size_t size) {
+        return syscall(__NR_bpf, cmd, attr, size);
+}
+#endif
diff --git a/src/libc/ioprio.c b/src/libc/ioprio.c
new file mode 100644 (file)
index 0000000..5bb6404
--- /dev/null
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include <sys/ioprio.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+
+#if !HAVE_IOPRIO_GET
+int missing_ioprio_get(int which, int who) {
+        return syscall(__NR_ioprio_get, which, who);
+}
+#endif
+
+#if !HAVE_IOPRIO_SET
+int missing_ioprio_set(int which, int who, int ioprio) {
+        return syscall(__NR_ioprio_set, which, who, ioprio);
+}
+#endif
diff --git a/src/libc/kcmp.c b/src/libc/kcmp.c
new file mode 100644 (file)
index 0000000..aafff99
--- /dev/null
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include <sys/kcmp.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+
+#if !HAVE_KCMP
+int missing_kcmp(pid_t pid1, pid_t pid2, int type, unsigned long idx1, unsigned long idx2) {
+        return syscall(__NR_kcmp, pid1, pid2, type, idx1, idx2);
+}
+#endif
diff --git a/src/libc/keyctl.c b/src/libc/keyctl.c
new file mode 100644 (file)
index 0000000..af4bca8
--- /dev/null
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include <sys/keyctl.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+
+#if !HAVE_KEYCTL
+long missing_keyctl(int cmd, unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5) {
+        return syscall(__NR_keyctl, cmd, arg2, arg3, arg4, arg5);
+}
+#endif
+
+#if !HAVE_ADD_KEY
+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);
+}
+#endif
+
+#if !HAVE_REQUEST_KEY
+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);
+}
+#endif
diff --git a/src/libc/mempolicy.c b/src/libc/mempolicy.c
new file mode 100644 (file)
index 0000000..77b0e1a
--- /dev/null
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include <sys/mempolicy.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+
+#if !HAVE_SET_MEMPOLICY
+int missing_set_mempolicy(int mode, const unsigned long *nodemask, unsigned long maxnode) {
+        return syscall(__NR_set_mempolicy, mode, nodemask, maxnode);
+}
+#endif
+
+#if !HAVE_GET_MEMPOLICY
+int missing_get_mempolicy(int *mode, unsigned long *nodemask, unsigned long maxnode, void *addr, unsigned long flags) {
+        return syscall(__NR_get_mempolicy, mode, nodemask, maxnode, addr, flags);
+}
+#endif
diff --git a/src/libc/meson.build b/src/libc/meson.build
new file mode 100644 (file)
index 0000000..eeee98c
--- /dev/null
@@ -0,0 +1,28 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+libc_wrapper_sources = files(
+        'bpf.c',
+        'ioprio.c',
+        'kcmp.c',
+        'keyctl.c',
+        'mempolicy.c',
+        'mount.c',
+        'pidfd.c',
+        'quota.c',
+        'sched.c',
+        'signal.c',
+        'stat.c',
+        'unistd.c',
+        'xattr.c',
+)
+
+sources += libc_wrapper_sources
+
+libc_wrapper_static = static_library(
+        'c-wrapper',
+        libc_wrapper_sources,
+        include_directories : system_includes,
+        implicit_include_directories : false,
+        dependencies : [userspace],
+        c_args : ['-fvisibility=default'],
+        build_by_default : false)
diff --git a/src/libc/mount.c b/src/libc/mount.c
new file mode 100644 (file)
index 0000000..1d324ef
--- /dev/null
@@ -0,0 +1,47 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include <sys/mount.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+
+#if !HAVE_FSOPEN
+int missing_fsopen(const char *fsname, unsigned flags) {
+        return syscall(__NR_fsopen, fsname, flags);
+}
+#endif
+
+#if !HAVE_FSMOUNT
+int missing_fsmount(int fd, unsigned flags, unsigned ms_flags) {
+        return syscall(__NR_fsmount, fd, flags, ms_flags);
+}
+#endif
+
+#if !HAVE_MOVE_MOUNT
+int missing_move_mount(int from_dfd, const char *from_pathname, int to_dfd, const char *to_pathname, unsigned flags) {
+        return syscall(__NR_move_mount, from_dfd, from_pathname, to_dfd, to_pathname, flags);
+}
+#endif
+
+#if !HAVE_FSCONFIG
+int missing_fsconfig(int fd, unsigned cmd, const char *key, const void *value, int aux) {
+        return syscall(__NR_fsconfig, fd, cmd, key, value, aux);
+}
+#endif
+
+#if !HAVE_OPEN_TREE
+int missing_open_tree(int dfd, const char *filename, unsigned flags) {
+        return syscall(__NR_open_tree, dfd, filename, flags);
+}
+#endif
+
+#if !HAVE_MOUNT_SETATTR
+int missing_mount_setattr(int dfd, const char *path, unsigned flags, struct mount_attr *attr, size_t size) {
+        return syscall(__NR_mount_setattr, dfd, path, flags, attr, size);
+}
+#endif
+
+#if !HAVE_OPEN_TREE_ATTR
+int missing_open_tree_attr(int dfd, const char *filename, unsigned int flags, struct mount_attr *attr, size_t size) {
+        return syscall(__NR_open_tree_attr, dfd, filename, flags, attr, size);
+}
+#endif
diff --git a/src/libc/pidfd.c b/src/libc/pidfd.c
new file mode 100644 (file)
index 0000000..a779e34
--- /dev/null
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include <sys/pidfd.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+
+#if !HAVE_PIDFD_OPEN
+int missing_pidfd_open(pid_t pid, unsigned flags) {
+        return syscall(__NR_pidfd_open, pid, flags);
+}
+#endif
+
+#if !HAVE_PIDFD_SEND_SIGNAL
+int missing_pidfd_send_signal(int fd, int sig, siginfo_t *info, unsigned flags) {
+        return syscall(__NR_pidfd_send_signal, fd, sig, info, flags);
+}
+#endif
diff --git a/src/libc/quota.c b/src/libc/quota.c
new file mode 100644 (file)
index 0000000..19695df
--- /dev/null
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include <sys/quota.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+
+#if !HAVE_QUOTACTL_FD
+int missing_quotactl_fd(int fd, int cmd, int id, void *addr) {
+        return syscall(__NR_quotactl_fd, fd, cmd, id, addr);
+}
+#endif
diff --git a/src/libc/sched.c b/src/libc/sched.c
new file mode 100644 (file)
index 0000000..cf17526
--- /dev/null
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include <sched.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+
+#if !HAVE_SCHED_SETATTR
+int missing_sched_setattr(pid_t pid, struct sched_attr *attr, unsigned flags) {
+        return syscall(__NR_sched_setattr, pid, attr, flags);
+}
+#endif
diff --git a/src/libc/signal.c b/src/libc/signal.c
new file mode 100644 (file)
index 0000000..1908331
--- /dev/null
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include <signal.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+
+#if !HAVE_RT_TGSIGQUEUEINFO
+int missing_rt_tgsigqueueinfo(pid_t tgid, pid_t tid, int sig, siginfo_t *info) {
+        return syscall(__NR_rt_tgsigqueueinfo, tgid, tid, sig, info);
+}
+#endif
diff --git a/src/libc/stat.c b/src/libc/stat.c
new file mode 100644 (file)
index 0000000..b283005
--- /dev/null
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include <sys/stat.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+
+#if !HAVE_FCHMODAT2
+int missing_fchmodat2(int dirfd, const char *path, mode_t mode, int flags) {
+        return syscall(__NR_fchmodat2, dirfd, path, mode, flags);
+}
+#endif
diff --git a/src/libc/unistd.c b/src/libc/unistd.c
new file mode 100644 (file)
index 0000000..99777b3
--- /dev/null
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include <sys/syscall.h>
+#include <unistd.h>
+
+#if !HAVE_CLOSE_RANGE
+int missing_close_range(unsigned first_fd, unsigned end_fd, unsigned flags) {
+        /* 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. */
+        return syscall(__NR_close_range, first_fd, end_fd, flags);
+}
+#endif
+
+#if !HAVE_EXECVEAT
+int missing_execveat(int dirfd, const char *pathname, char * const argv[], char * const envp[], int flags) {
+        return syscall(__NR_execveat, dirfd, pathname, argv, envp, flags);
+}
+#endif
+
+#if !HAVE_PIVOT_ROOT
+int missing_pivot_root(const char *new_root, const char *put_old) {
+        return syscall(__NR_pivot_root, new_root, put_old);
+}
+#endif
diff --git a/src/libc/xattr.c b/src/libc/xattr.c
new file mode 100644 (file)
index 0000000..68fa97a
--- /dev/null
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include <sys/syscall.h>
+#include <sys/xattr.h>
+#include <unistd.h>
+
+#if !HAVE_SETXATTRAT
+int missing_setxattrat(int fd, const char *path, int at_flags, const char *name, const struct xattr_args *args, size_t size) {
+        return syscall(__NR_setxattrat, fd, path, at_flags, name, args, size);
+}
+#endif
+
+#if !HAVE_REMOVEXATTRAT
+int missing_removexattrat(int fd, const char *path, int at_flags, const char *name) {
+        return syscall(__NR_removexattrat, fd, path, at_flags, name);
+}
+#endif
index 52c6cea3c58310597526a823d4644ded5da67e26..fa483836fa5edf0ac1f226e25f012923f41e47a8 100644 (file)
@@ -147,7 +147,8 @@ libsystemd_static = static_library(
         include_directories : libsystemd_includes,
         implicit_include_directories : false,
         c_args : libsystemd_c_args,
-        link_with : [libbasic_static],
+        link_with : [libc_wrapper_static,
+                     libbasic_static],
         dependencies : [threads,
                         libm,
                         librt,
index 54fab9284a7c22c3d8437a1b3c5c32ebdbeed7f9..d3838ba2458c93e55ca08aade79ab2dbc26d8ab7 100644 (file)
@@ -13,7 +13,6 @@
 #include "hmac.h"
 #include "id128-util.h"
 #include "keyring-util.h"
-#include "missing_syscall.h"
 #include "path-util.h"
 #include "random-util.h"
 #include "stat-util.h"
index b1a9aed234538707a3884511cc21b5be358f3dc1..36b4b22552589f7c2a34ef2a78b5299b4164cfaa 100644 (file)
@@ -7,7 +7,6 @@
 #include <security/pam_modutil.h>
 
 #include "keyring-util.h"
-#include "missing_syscall.h"
 #include "nulstr-util.h"
 #include "pam-util.h"
 #include "string-util.h"
index 77498081ea2db779c19dd9180a89dc71be7e6136..30ff2f47c54385fb36a2b3ea0667d846e89a7ae4 100644 (file)
@@ -16,7 +16,6 @@
 #include "log.h"
 #include "main-func.h"
 #include "missing_magic.h"
-#include "missing_syscall.h"
 #include "mkdir-label.h"
 #include "mount-util.h"
 #include "mountpoint-util.h"
index dfca74b05edb4d62a8a35edd586a4ebc94853923..4ccfab8a88c3e591bfff75b0a1e78f0f1d066ce0 100644 (file)
@@ -6,6 +6,7 @@
 #include <stdlib.h>
 #include <sys/file.h>
 #include <sys/ioctl.h>
+#include <sys/keyctl.h>
 #include <sys/mount.h>
 #include <sys/personality.h>
 #include <sys/prctl.h>
@@ -66,8 +67,6 @@
 #include "loopback-setup.h"
 #include "machine-credential.h"
 #include "main-func.h"
-#include "missing_keyctl.h"
-#include "missing_syscall.h"
 #include "mkdir.h"
 #include "mount-util.h"
 #include "mountpoint-util.h"
index 236d4d4acd1c284cbf3fd51400389a9e60446bee..5f99eae4f9013d5946a79d3773b95ff524b33b0c 100644 (file)
@@ -31,7 +31,6 @@
 #include "json-util.h"
 #include "main-func.h"
 #include "missing_magic.h"
-#include "missing_syscall.h"
 #include "mountpoint-util.h"
 #include "namespace-util.h"
 #include "netlink-util.h"
index 369410bab8d635419b0d56579f0071269facaabe..eda4a0a212dd88cf8818fe1d5f7e84660974c7d5 100644 (file)
@@ -26,6 +26,7 @@ executables += [
                 'sources' : files('repart.c'),
                 'c_args' : '-DSTANDALONE',
                 'link_with' : [
+                        libc_wrapper_static,
                         libbasic_static,
                         libshared_fdisk,
                         libshared_static,
index 256605ac8a0bfb120c5dad8eb3aa2ae8d047176f..dd6b8abc654236a7a1f77951a880a8a882674b54 100644 (file)
@@ -23,7 +23,6 @@
 #include "iovec-util.h"
 #include "keyring-util.h"
 #include "log.h"
-#include "missing_syscall.h"
 #include "nulstr-util.h"
 #include "parse-util.h"
 #include "path-lookup.h"
index 5c4bea60c6b1ba987554f6f4488779aa74162db6..f920051832185e3db78812bad34fdc0be11116d6 100644 (file)
@@ -3,6 +3,7 @@
 #include <fcntl.h>
 #include <linux/bpf.h>
 #include <linux/bpf_insn.h>
+#include <sys/bpf.h>
 #include <unistd.h>
 
 #include "alloc-util.h"
@@ -14,7 +15,6 @@
 #include "fdset.h"
 #include "log.h"
 #include "memory-util.h"
-#include "missing_syscall.h"
 #include "parse-util.h"
 #include "path-util.h"
 #include "serialize.h"
index 0873d8ef616738cb4f4d1df970cfbbb921d39277..468f178cd01f59df1fade11238a1a9bab85a35eb 100644 (file)
@@ -1,7 +1,7 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
-#include <linux/ioprio.h>       /* IWYU pragma: export */
+#include <sys/ioprio.h>         /* IWYU pragma: export */
 
 #include "forward.h"
 
index dc509eeb281600d2aaac31fa879da2f5fc8e29fa..2a49a5e9b88cc72c81690a405803f7883177a16d 100644 (file)
@@ -360,7 +360,8 @@ libshared = shared_library(
         link_args : ['-shared',
                      '-Wl,--version-script=' + libshared_sym_path],
         link_depends : libshared_sym_path,
-        link_whole : [libshared_static,
+        link_whole : [libc_wrapper_static,
+                      libshared_static,
                       libbasic_static,
                       libsystemd_static],
         dependencies : [libshared_deps,
index 3d10a050919dc1c327586ac56b9a695fc582c213..830ebe1c87aed12f8e708df0d92ca0334b3b0fe4 100644 (file)
@@ -19,7 +19,6 @@
 #include "hashmap.h"
 #include "libmount-util.h"
 #include "log.h"
-#include "missing_syscall.h"
 #include "mkdir-label.h"
 #include "mount-util.h"
 #include "mountpoint-util.h"
index 8c18c582270ecd077cd200a5d42f8b85cb434f46..c011c4381d4222ce4e66dc677222b45a1e23154d 100644 (file)
@@ -8,7 +8,6 @@
 #include "fd-util.h"
 #include "fileio.h"
 #include "log.h"
-#include "missing_syscall.h"
 #include "numa-util.h"
 #include "parse-util.h"
 #include "stdio-util.h"
index 571d0d1354f27c36b0f8d27f86426a803ae54c12..1c3482a5908819105e8c333efba593f5d26542d9 100644 (file)
@@ -1,9 +1,10 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
+#include <sys/mempolicy.h>
+
 #include "cpu-set-util.h"
 #include "forward.h"
-#include "missing_syscall.h"
 
 static inline bool mpol_is_valid(int t) {
         return t >= MPOL_DEFAULT && t <= MPOL_LOCAL;
index 06f27e85f25a911f93ae8717f80fdb587602b845..265d5029717ea513e994ba18576572abee7c615d 100644 (file)
@@ -8,7 +8,6 @@
 #include "chattr-util.h"
 #include "device-util.h"
 #include "errno-util.h"
-#include "missing_syscall.h"
 #include "quota-util.h"
 
 int quotactl_fd_with_fallback(int fd, int cmd, int id, void *addr) {
index 288280c3d19cdb08f8b3b18cb74eb8c9deb47c91..d5f34c5d37d4e47920f095af4ec0b79319fc2f0d 100644 (file)
@@ -11,7 +11,6 @@
 #include "errno-util.h"
 #include "fd-util.h"
 #include "log.h"
-#include "missing_syscall.h"
 #include "mkdir-label.h"
 #include "mount-util.h"
 #include "mountpoint-util.h"
index c67d19abcc573e46b22463fd19a8b91de9902484..4893ea62e3681063b04598811b6e6d1f77176b19 100644 (file)
@@ -23,6 +23,7 @@ executables += [
                 'sources' : systemd_shutdown_sources + systemd_shutdown_extract_sources,
                 'c_args' : '-DSTANDALONE',
                 'link_with' : [
+                        libc_wrapper_static,
                         libbasic_static,
                         libshared_static,
                         libsystemd_static,
index 88494d8cfce1866f63632a90bd0c4756fc9f26ca..e2e82889e77848d88f366df6bdb67e12d63a9914 100644 (file)
@@ -17,6 +17,7 @@ executables += [
                 'sources' : files('sysusers.c'),
                 'c_args' : '-DSTANDALONE',
                 'link_with' : [
+                        libc_wrapper_static,
                         libbasic_static,
                         libshared_static,
                         libsystemd_static,
index c0c2a4e90552e7b750f0960803fa1e935ea8f904..5284dc13156f35e7e2b7aabd4fe804cd674d9d2e 100644 (file)
@@ -289,7 +289,10 @@ executables += [
                 # only static linking apart from libdl, to make sure that the
                 # module is linked to all libraries that it uses.
                 'sources' : files('test-dlopen.c'),
-                'link_with' : libbasic_static,
+                'link_with' : [
+                        libc_wrapper_static,
+                        libbasic_static,
+                ],
                 'dependencies' : libdl,
                 'install' : false,
                 'type' : 'manual',
@@ -426,7 +429,10 @@ executables += [
         },
         test_template + {
                 'sources' : files('test-sizeof.c'),
-                'link_with' : libbasic_static,
+                'link_with' : [
+                        libc_wrapper_static,
+                        libbasic_static,
+                ],
         },
         test_template + {
                 'sources' : files('test-time-util.c'),
@@ -594,6 +600,7 @@ executables += [
         test_template + {
                 'sources' : files('../libsystemd/sd-device/test-sd-device-thread.c'),
                 'link_with' : [
+                        libc_wrapper_static,
                         libbasic_static,
                         libsystemd,
                 ],
@@ -602,6 +609,7 @@ executables += [
         test_template + {
                 'sources' : files('../libudev/test-udev-device-thread.c'),
                 'link_with' : [
+                        libc_wrapper_static,
                         libbasic_static,
                         libudev,
                 ],
index 7199b2fb33bdb08b49a21d3f259057efdcb4e86e..a1230ec27ca06438470113dfd5cc27b4c114d6d5 100644 (file)
@@ -21,7 +21,6 @@
 #include "fileio.h"
 #include "fs-util.h"
 #include "memory-util.h"
-#include "missing_syscall.h"
 #include "nsflags.h"
 #include "nulstr-util.h"
 #include "process-util.h"
index 404f265f918b52ccc67cd7c5be62875d387bed44..a973d16f5c260d5298c176add53fea23997684b7 100644 (file)
@@ -25,6 +25,7 @@ executables += [
                 'sources' : systemd_tmpfiles_sources + systemd_tmpfiles_extract_sources,
                 'c_args' : '-DSTANDALONE',
                 'link_with' : [
+                        libc_wrapper_static,
                         libbasic_static,
                         libshared_static,
                         libsystemd_static,