]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/missing.h
missing: move prctl related entries to missing_prctl.h
[thirdparty/systemd.git] / src / basic / missing.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 /* Missing glibc definitions to access certain kernel APIs */
5
6 #include <errno.h>
7 #include <fcntl.h>
8 #include <inttypes.h>
9 #include <linux/audit.h>
10 #include <linux/capability.h>
11 #include <linux/falloc.h>
12 #include <linux/oom.h>
13 #include <net/ethernet.h>
14 #include <stdlib.h>
15 #include <sys/resource.h>
16 #include <sys/socket.h>
17 #include <sys/syscall.h>
18 #include <uchar.h>
19 #include <unistd.h>
20
21 #if HAVE_AUDIT
22 #include <libaudit.h>
23 #endif
24
25 #ifdef ARCH_MIPS
26 #include <asm/sgidefs.h>
27 #endif
28
29 #if HAVE_LINUX_VM_SOCKETS_H
30 #include <linux/vm_sockets.h>
31 #else
32 #define VMADDR_CID_ANY -1U
33 struct sockaddr_vm {
34 unsigned short svm_family;
35 unsigned short svm_reserved1;
36 unsigned int svm_port;
37 unsigned int svm_cid;
38 unsigned char svm_zero[sizeof(struct sockaddr) -
39 sizeof(unsigned short) -
40 sizeof(unsigned short) -
41 sizeof(unsigned int) -
42 sizeof(unsigned int)];
43 };
44 #endif /* !HAVE_LINUX_VM_SOCKETS_H */
45
46 #ifndef RLIMIT_RTTIME
47 #define RLIMIT_RTTIME 15
48 #endif
49
50 /* If RLIMIT_RTTIME is not defined, then we cannot use RLIMIT_NLIMITS as is */
51 #define _RLIMIT_MAX (RLIMIT_RTTIME+1 > RLIMIT_NLIMITS ? RLIMIT_RTTIME+1 : RLIMIT_NLIMITS)
52
53 #ifndef F_LINUX_SPECIFIC_BASE
54 #define F_LINUX_SPECIFIC_BASE 1024
55 #endif
56
57 #ifndef F_SETPIPE_SZ
58 #define F_SETPIPE_SZ (F_LINUX_SPECIFIC_BASE + 7)
59 #endif
60
61 #ifndef F_GETPIPE_SZ
62 #define F_GETPIPE_SZ (F_LINUX_SPECIFIC_BASE + 8)
63 #endif
64
65 #ifndef F_ADD_SEALS
66 #define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9)
67 #define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10)
68
69 #define F_SEAL_SEAL 0x0001 /* prevent further seals from being set */
70 #define F_SEAL_SHRINK 0x0002 /* prevent file from shrinking */
71 #define F_SEAL_GROW 0x0004 /* prevent file from growing */
72 #define F_SEAL_WRITE 0x0008 /* prevent writes */
73 #endif
74
75 #ifndef F_OFD_GETLK
76 #define F_OFD_GETLK 36
77 #define F_OFD_SETLK 37
78 #define F_OFD_SETLKW 38
79 #endif
80
81 #ifndef MFD_ALLOW_SEALING
82 #define MFD_ALLOW_SEALING 0x0002U
83 #endif
84
85 #ifndef MFD_CLOEXEC
86 #define MFD_CLOEXEC 0x0001U
87 #endif
88
89 #ifndef IP_FREEBIND
90 #define IP_FREEBIND 15
91 #endif
92
93 #ifndef OOM_SCORE_ADJ_MIN
94 #define OOM_SCORE_ADJ_MIN (-1000)
95 #endif
96
97 #ifndef OOM_SCORE_ADJ_MAX
98 #define OOM_SCORE_ADJ_MAX 1000
99 #endif
100
101 #ifndef AUDIT_SERVICE_START
102 #define AUDIT_SERVICE_START 1130 /* Service (daemon) start */
103 #endif
104
105 #ifndef AUDIT_SERVICE_STOP
106 #define AUDIT_SERVICE_STOP 1131 /* Service (daemon) stop */
107 #endif
108
109 #ifndef TIOCVHANGUP
110 #define TIOCVHANGUP 0x5437
111 #endif
112
113 #ifndef IP_TRANSPARENT
114 #define IP_TRANSPARENT 19
115 #endif
116
117 #ifndef SOL_NETLINK
118 #define SOL_NETLINK 270
119 #endif
120
121 #ifndef NETLINK_LIST_MEMBERSHIPS
122 #define NETLINK_LIST_MEMBERSHIPS 9
123 #endif
124
125 #ifndef SOL_SCTP
126 #define SOL_SCTP 132
127 #endif
128
129 #ifndef GRND_NONBLOCK
130 #define GRND_NONBLOCK 0x0001
131 #endif
132
133 #ifndef GRND_RANDOM
134 #define GRND_RANDOM 0x0002
135 #endif
136
137 #ifndef FS_NOCOW_FL
138 #define FS_NOCOW_FL 0x00800000
139 #endif
140
141 #ifndef CLONE_NEWCGROUP
142 #define CLONE_NEWCGROUP 0x02000000
143 #endif
144
145 #ifndef MS_MOVE
146 #define MS_MOVE 8192
147 #endif
148
149 #ifndef MS_REC
150 #define MS_REC 16384
151 #endif
152
153 #ifndef MS_PRIVATE
154 #define MS_PRIVATE (1<<18)
155 #endif
156
157 #ifndef MS_REC
158 #define MS_REC (1<<19)
159 #endif
160
161 #ifndef MS_SHARED
162 #define MS_SHARED (1<<20)
163 #endif
164
165 #ifndef MS_RELATIME
166 #define MS_RELATIME (1<<21)
167 #endif
168
169 #ifndef MS_KERNMOUNT
170 #define MS_KERNMOUNT (1<<22)
171 #endif
172
173 #ifndef MS_I_VERSION
174 #define MS_I_VERSION (1<<23)
175 #endif
176
177 #ifndef MS_STRICTATIME
178 #define MS_STRICTATIME (1<<24)
179 #endif
180
181 #ifndef MS_LAZYTIME
182 #define MS_LAZYTIME (1<<25)
183 #endif
184
185 #ifndef SCM_SECURITY
186 #define SCM_SECURITY 0x03
187 #endif
188
189 #ifndef DM_DEFERRED_REMOVE
190 #define DM_DEFERRED_REMOVE (1 << 17)
191 #endif
192
193 #ifndef MAX_HANDLE_SZ
194 #define MAX_HANDLE_SZ 128
195 #endif
196
197 #if ! HAVE_SECURE_GETENV
198 # if HAVE___SECURE_GETENV
199 # define secure_getenv __secure_getenv
200 # else
201 # error "neither secure_getenv nor __secure_getenv are available"
202 # endif
203 #endif
204
205 #ifndef CIFS_MAGIC_NUMBER
206 # define CIFS_MAGIC_NUMBER 0xFF534D42
207 #endif
208
209 #ifndef TFD_TIMER_CANCEL_ON_SET
210 # define TFD_TIMER_CANCEL_ON_SET (1 << 1)
211 #endif
212
213 #ifndef SO_REUSEPORT
214 # define SO_REUSEPORT 15
215 #endif
216
217 #ifndef SO_PEERGROUPS
218 # define SO_PEERGROUPS 59
219 #endif
220
221 #ifndef DRM_IOCTL_SET_MASTER
222 # define DRM_IOCTL_SET_MASTER _IO('d', 0x1e)
223 #endif
224
225 #ifndef DRM_IOCTL_DROP_MASTER
226 # define DRM_IOCTL_DROP_MASTER _IO('d', 0x1f)
227 #endif
228
229 /* The precise definition of __O_TMPFILE is arch specific; use the
230 * values defined by the kernel (note: some are hexa, some are octal,
231 * duplicated as-is from the kernel definitions):
232 * - alpha, parisc, sparc: each has a specific value;
233 * - others: they use the "generic" value.
234 */
235
236 #ifndef __O_TMPFILE
237 #if defined(__alpha__)
238 #define __O_TMPFILE 0100000000
239 #elif defined(__parisc__) || defined(__hppa__)
240 #define __O_TMPFILE 0400000000
241 #elif defined(__sparc__) || defined(__sparc64__)
242 #define __O_TMPFILE 0x2000000
243 #else
244 #define __O_TMPFILE 020000000
245 #endif
246 #endif
247
248 /* a horrid kludge trying to make sure that this will fail on old kernels */
249 #ifndef O_TMPFILE
250 #define O_TMPFILE (__O_TMPFILE | O_DIRECTORY)
251 #endif
252
253 #ifndef BPF_XOR
254 #define BPF_XOR 0xa0
255 #endif
256
257 /* Note that LOOPBACK_IFINDEX is currently not exported by the
258 * kernel/glibc, but hardcoded internally by the kernel. However, as
259 * it is exported to userspace indirectly via rtnetlink and the
260 * ioctls, and made use of widely we define it here too, in a way that
261 * is compatible with the kernel's internal definition. */
262 #ifndef LOOPBACK_IFINDEX
263 #define LOOPBACK_IFINDEX 1
264 #endif
265
266 #ifndef MAX_AUDIT_MESSAGE_LENGTH
267 #define MAX_AUDIT_MESSAGE_LENGTH 8970
268 #endif
269
270 #ifndef AUDIT_NLGRP_MAX
271 #define AUDIT_NLGRP_READLOG 1
272 #endif
273
274 #ifndef CAP_MAC_OVERRIDE
275 #define CAP_MAC_OVERRIDE 32
276 #endif
277
278 #ifndef CAP_MAC_ADMIN
279 #define CAP_MAC_ADMIN 33
280 #endif
281
282 #ifndef CAP_SYSLOG
283 #define CAP_SYSLOG 34
284 #endif
285
286 #ifndef CAP_WAKE_ALARM
287 #define CAP_WAKE_ALARM 35
288 #endif
289
290 #ifndef CAP_BLOCK_SUSPEND
291 #define CAP_BLOCK_SUSPEND 36
292 #endif
293
294 #ifndef CAP_AUDIT_READ
295 #define CAP_AUDIT_READ 37
296 #endif
297
298 #ifndef RENAME_NOREPLACE
299 #define RENAME_NOREPLACE (1 << 0)
300 #endif
301
302 #ifndef KCMP_FILE
303 #define KCMP_FILE 0
304 #endif
305
306 #if !HAVE_CHAR32_T
307 #define char32_t uint32_t
308 #endif
309
310 #if !HAVE_CHAR16_T
311 #define char16_t uint16_t
312 #endif
313
314 #ifndef ETHERTYPE_LLDP
315 #define ETHERTYPE_LLDP 0x88cc
316 #endif
317
318 #ifndef SOL_ALG
319 #define SOL_ALG 279
320 #endif
321
322 #ifndef AF_VSOCK
323 #define AF_VSOCK 40
324 #endif
325
326 #ifndef EXT4_IOC_RESIZE_FS
327 # define EXT4_IOC_RESIZE_FS _IOW('f', 16, __u64)
328 #endif
329
330 #ifndef NS_GET_NSTYPE
331 #define NS_GET_NSTYPE _IO(0xb7, 0x3)
332 #endif
333
334 #ifndef FALLOC_FL_KEEP_SIZE
335 #define FALLOC_FL_KEEP_SIZE 0x01
336 #endif
337
338 #ifndef FALLOC_FL_PUNCH_HOLE
339 #define FALLOC_FL_PUNCH_HOLE 0x02
340 #endif
341
342 #ifndef PF_KTHREAD
343 #define PF_KTHREAD 0x00200000
344 #endif
345
346 /* The maximum thread/process name length including trailing NUL byte. This mimics the kernel definition of the same
347 * name, which we need in userspace at various places but is not defined in userspace currently, neither under this
348 * name nor any other. */
349 #ifndef TASK_COMM_LEN
350 #define TASK_COMM_LEN 16
351 #endif
352
353 #include "missing_btrfs_tree.h"
354 #include "missing_input.h"
355 #include "missing_magic.h"
356 #include "missing_network.h"
357 #include "missing_prctl.h"
358
359 #include "missing_syscall.h"