/src/dbus-broker/src/util/misc.h
Line | Count | Source |
1 | | #pragma once |
2 | | |
3 | | /* SPDX-License-Identifier: GPL-3.0-or-later */ |
4 | | /* SPDX-FileCopyrightText: D-Bus Broker Developers */ |
5 | | |
6 | | /* |
7 | | * Miscellaneous Helpers |
8 | | */ |
9 | | |
10 | | #include <c-stdaux.h> |
11 | | #include <stdlib.h> |
12 | | |
13 | 0 | #define MISC_MFD_CLOEXEC 0x0001U |
14 | 0 | #define MISC_MFD_ALLOW_SEALING 0x0002U |
15 | | #define MISC_MFD_HUGETLB 0x0004U |
16 | 0 | #define MISC_MFD_NOEXEC_SEAL 0x0008U |
17 | 0 | #define MISC_MFD_EXEC 0x0010U |
18 | | |
19 | 0 | #define MISC_F_SEAL_SEAL 0x0001U |
20 | 0 | #define MISC_F_SEAL_SHRINK 0x0002U |
21 | 0 | #define MISC_F_SEAL_GROW 0x0004U |
22 | 0 | #define MISC_F_SEAL_WRITE 0x0008U |
23 | | #define MISC_F_SEAL_FUTURE_WRITE 0x0010U |
24 | | #define MISC_F_SEAL_EXEC 0x0020U |
25 | | |
26 | | int misc_memfd(const char *name, unsigned int uflags, unsigned int useals); |
27 | | int misc_memfd_add_seals(int fd, unsigned int seals); |
28 | | int misc_memfd_get_seals(int fd, unsigned int *sealsp); |
29 | | |
30 | | uint64_t util_umul64_saturating(uint64_t a, uint64_t b); |
31 | | unsigned int util_z2u_saturating(size_t v); |
32 | | unsigned int util_t2u_saturating(uint64_t v); |
33 | | int util_drop_permissions(uint32_t uid, uint32_t gid); |
34 | | int util_bump_nofile(void); |
35 | | |
36 | | void util_peak_update(size_t *peak, size_t update); |
37 | | |
38 | | /** |
39 | | * misc_vfreep() - Cleanup helper for NULL-terminated arrays of allocations |
40 | | * v: Pointer to the array of allocated objects (i.e., `void ***p`) |
41 | | * |
42 | | * This interprets `v` as `void ***`, assuming it points to an array of |
43 | | * allocated objects. `v` must not be NULL. |
44 | | * |
45 | | * If `*v` is NULL, this is a no-op. Otherwise, `*v` is iterated as array of |
46 | | * pointers, terminated by a NULL entry. All entries are passed to free(), with |
47 | | * a final call to `*v` itself. |
48 | | */ |
49 | 0 | static inline void misc_vfreep(void *v) { |
50 | 0 | void ***p = v; |
51 | 0 | size_t i; |
52 | 0 |
|
53 | 0 | if (*p) { |
54 | 0 | for (i = 0; (*p)[i]; ++i) |
55 | 0 | free((*p)[i]); |
56 | 0 | free(*p); |
57 | 0 | } |
58 | 0 | } Unexecuted instantiation: log.c:misc_vfreep Unexecuted instantiation: misc.c:misc_vfreep |