]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/missing_syscall.h
ec62602989dfbfca1fe76b5d0eea748b68adb470
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
4 /* Missing glibc definitions to access certain kernel APIs */
6 #include <linux/mempolicy.h>
8 #include <sys/syscall.h>
13 #include <asm/sgidefs.h>
17 #include "missing_keyctl.h"
18 #include "missing_sched.h"
19 #include "missing_syscall_def.h"
21 /* ======================================================================= */
24 /* since kernel v6.6 (78252deb023cf0879256fcfbafe37022c390762b) */
25 static inline int missing_fchmodat2(int dirfd
, const char *path
, mode_t mode
, int flags
) {
26 return syscall(__NR_fchmodat2
, dirfd
, path
, mode
, flags
);
29 # define fchmodat2 missing_fchmodat2
32 /* ======================================================================= */
35 static inline int missing_pivot_root(const char *new_root
, const char *put_old
) {
36 return syscall(__NR_pivot_root
, new_root
, put_old
);
39 # define pivot_root missing_pivot_root
42 /* ======================================================================= */
45 static inline int missing_ioprio_get(int which
, int who
) {
46 return syscall(__NR_ioprio_get
, which
, who
);
49 # define ioprio_get missing_ioprio_get
52 /* ======================================================================= */
55 static inline int missing_ioprio_set(int which
, int who
, int ioprio
) {
56 return syscall(__NR_ioprio_set
, which
, who
, ioprio
);
59 # define ioprio_set missing_ioprio_set
62 /* ======================================================================= */
65 static inline int missing_kcmp(pid_t pid1
, pid_t pid2
, int type
, unsigned long idx1
, unsigned long idx2
) {
66 return syscall(__NR_kcmp
, pid1
, pid2
, type
, idx1
, idx2
);
69 # define kcmp missing_kcmp
72 /* ======================================================================= */
75 static inline long missing_keyctl(int cmd
, unsigned long arg2
, unsigned long arg3
, unsigned long arg4
, unsigned long arg5
) {
76 return syscall(__NR_keyctl
, cmd
, arg2
, arg3
, arg4
, arg5
);
78 # define keyctl missing_keyctl
81 /* ======================================================================= */
83 static inline key_serial_t
missing_add_key(const char *type
, const char *description
, const void *payload
, size_t plen
, key_serial_t ringid
) {
84 return syscall(__NR_add_key
, type
, description
, payload
, plen
, ringid
);
86 # define add_key missing_add_key
89 /* ======================================================================= */
91 static inline key_serial_t
missing_request_key(const char *type
, const char *description
, const char * callout_info
, key_serial_t destringid
) {
92 return syscall(__NR_request_key
, type
, description
, callout_info
, destringid
);
94 # define request_key missing_request_key
98 /* ======================================================================= */
103 static inline int missing_bpf(int cmd
, union bpf_attr
*attr
, size_t size
) {
104 return (int) syscall(__NR_bpf
, cmd
, attr
, size
);
107 # define bpf missing_bpf
110 /* ======================================================================= */
112 #if !HAVE_SET_MEMPOLICY
113 static inline long missing_set_mempolicy(int mode
, const unsigned long *nodemask
,
114 unsigned long maxnode
) {
115 return syscall(__NR_set_mempolicy
, mode
, nodemask
, maxnode
);
118 # define set_mempolicy missing_set_mempolicy
121 #if !HAVE_GET_MEMPOLICY
122 static inline long missing_get_mempolicy(int *mode
, unsigned long *nodemask
,
123 unsigned long maxnode
, void *addr
,
124 unsigned long flags
) {
125 return syscall(__NR_get_mempolicy
, mode
, nodemask
, maxnode
, addr
, flags
);
128 # define get_mempolicy missing_get_mempolicy
131 /* ======================================================================= */
133 #if !HAVE_PIDFD_SEND_SIGNAL
134 /* since kernel v5.1 (3eb39f47934f9d5a3027fe00d906a45fe3a15fad) */
135 static inline int missing_pidfd_send_signal(int fd
, int sig
, siginfo_t
*info
, unsigned flags
) {
136 return syscall(__NR_pidfd_send_signal
, fd
, sig
, info
, flags
);
139 # define pidfd_send_signal missing_pidfd_send_signal
142 /* ======================================================================= */
145 /* since kernel v5.3 (7615d9e1780e26e0178c93c55b73309a5dc093d7) */
146 static inline int missing_pidfd_open(pid_t pid
, unsigned flags
) {
147 return syscall(__NR_pidfd_open
, pid
, flags
);
150 # define pidfd_open missing_pidfd_open
153 /* ======================================================================= */
155 #if !HAVE_RT_TGSIGQUEUEINFO
156 static inline int missing_rt_tgsigqueueinfo(pid_t tgid
, pid_t tid
, int sig
, siginfo_t
*info
) {
157 return syscall(__NR_rt_tgsigqueueinfo
, tgid
, tid
, sig
, info
);
160 # define rt_tgsigqueueinfo missing_rt_tgsigqueueinfo
163 /* ======================================================================= */
166 /* since kernel v3.19 (51f39a1f0cea1cacf8c787f652f26dfee9611874) */
167 static inline int missing_execveat(int dirfd
, const char *pathname
,
168 char *const argv
[], char *const envp
[],
170 return syscall(__NR_execveat
, dirfd
, pathname
, argv
, envp
, flags
);
173 # define execveat missing_execveat
176 /* ======================================================================= */
178 #if !HAVE_CLOSE_RANGE
179 /* since kernel v5.9 (9b4feb630e8e9801603f3cab3a36369e3c1cf88d) */
180 static inline int missing_close_range(unsigned first_fd
, unsigned end_fd
, unsigned flags
) {
181 /* Kernel-side the syscall expects fds as unsigned integers (just like close() actually), while
182 * userspace exclusively uses signed integers for fds. glibc chose to expose it 1:1 however, hence we
183 * do so here too, even if we end up passing signed fds to it most of the time. */
184 return syscall(__NR_close_range
,
190 # define close_range missing_close_range
193 /* ======================================================================= */
195 #if !HAVE_SCHED_SETATTR
196 /* since kernel 3.14 (e6cfc0295c7d51b008999a8b13a44fb43f8685ea) */
197 static inline ssize_t
missing_sched_setattr(pid_t pid
, struct sched_attr
*attr
, unsigned int flags
) {
198 return syscall(__NR_sched_setattr
, pid
, attr
, flags
);
201 # define sched_setattr missing_sched_setattr
204 /* ======================================================================= */
206 /* glibc does not provide clone() on ia64, only clone2(). Not only that, but it also doesn't provide a
207 * prototype, only the symbol in the shared library (it provides a prototype for clone(), but not the
208 * symbol in the shared library). */
209 #if defined(__ia64__)
210 int __clone2(int (*fn
)(void *), void *stack_base
, size_t stack_size
, int flags
, void *arg
);
213 /* We know that everywhere else clone() is available, so we don't bother with a meson check (that takes time
214 * at build time) and just define it. Once the kernel drops ia64 support, we can drop this too. */
218 /* ======================================================================= */
220 #if !HAVE_QUOTACTL_FD
221 /* since kernel v5.14 (64c2c2c62f92339b176ea24403d8db16db36f9e6) */
222 static inline int missing_quotactl_fd(int fd
, int cmd
, int id
, void *addr
) {
223 return syscall(__NR_quotactl_fd
, fd
, cmd
, id
, addr
);
226 # define quotactl_fd missing_quotactl_fd
229 /* ======================================================================= */
232 /* since kernel v6.13 (6140be90ec70c39fa844741ca3cc807dd0866394) */
233 static inline int missing_setxattrat(int fd
, const char *path
, int at_flags
, const char *name
, const struct xattr_args
*args
, size_t size
) {
234 return syscall(__NR_setxattrat
, fd
, path
, at_flags
, name
, args
, size
);
237 # define setxattrat missing_setxattrat
240 /* ======================================================================= */
242 #if !HAVE_REMOVEXATTRAT
243 /* since kernel v6.13 (6140be90ec70c39fa844741ca3cc807dd0866394) */
244 static inline int missing_removexattrat(int fd
, const char *path
, int at_flags
, const char *name
) {
245 return syscall(__NR_removexattrat
, fd
, path
, at_flags
, name
);
248 # define removexattrat missing_removexattrat