/src/systemd/src/basic/util.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
2 | | #pragma once |
3 | | |
4 | | #include <stdint.h> |
5 | | |
6 | | #include "macro.h" |
7 | | |
8 | | extern int saved_argc; |
9 | | extern char **saved_argv; |
10 | | |
11 | 0 | static inline void save_argc_argv(int argc, char **argv) { |
12 | 0 |
|
13 | 0 | /* Protect against CVE-2021-4034 style attacks */ |
14 | 0 | assert_se(argc > 0); |
15 | 0 | assert_se(argv); |
16 | 0 | assert_se(argv[0]); |
17 | 0 |
|
18 | 0 | saved_argc = argc; |
19 | 0 | saved_argv = argv; |
20 | 0 | } Unexecuted instantiation: fuzz-link-parser.c:save_argc_argv Unexecuted instantiation: link-config.c:save_argc_argv Unexecuted instantiation: link-config-gperf.c:save_argc_argv |
21 | | |
22 | | bool kexec_loaded(void); |
23 | | |
24 | | int prot_from_flags(int flags) _const_; |
25 | | |
26 | | bool in_initrd(void); |
27 | | void in_initrd_force(bool value); |
28 | | |
29 | | /* Note: log2(0) == log2(1) == 0 here and below. */ |
30 | | |
31 | | #define CONST_LOG2ULL(x) ((x) > 1 ? (unsigned) __builtin_clzll(x) ^ 63U : 0) |
32 | | #define NONCONST_LOG2ULL(x) ({ \ |
33 | | unsigned long long _x = (x); \ |
34 | | _x > 1 ? (unsigned) __builtin_clzll(_x) ^ 63U : 0; \ |
35 | | }) |
36 | | #define LOG2ULL(x) __builtin_choose_expr(__builtin_constant_p(x), CONST_LOG2ULL(x), NONCONST_LOG2ULL(x)) |
37 | | |
38 | 0 | static inline unsigned log2u64(uint64_t x) { |
39 | 0 | #if __SIZEOF_LONG_LONG__ == 8 |
40 | 0 | return LOG2ULL(x); |
41 | 0 | #else |
42 | 0 | # error "Wut?" |
43 | 0 | #endif |
44 | 0 | } Unexecuted instantiation: fuzz-link-parser.c:log2u64 Unexecuted instantiation: link-config.c:log2u64 Unexecuted instantiation: link-config-gperf.c:log2u64 |
45 | | |
46 | 0 | static inline unsigned u32ctz(uint32_t n) { |
47 | 0 | #if __SIZEOF_INT__ == 4 |
48 | 0 | return n != 0 ? __builtin_ctz(n) : 32; |
49 | 0 | #else |
50 | 0 | # error "Wut?" |
51 | 0 | #endif |
52 | 0 | } Unexecuted instantiation: fuzz-link-parser.c:u32ctz Unexecuted instantiation: link-config.c:u32ctz Unexecuted instantiation: link-config-gperf.c:u32ctz |
53 | | |
54 | | #define CONST_LOG2U(x) ((x) > 1 ? __SIZEOF_INT__ * 8 - __builtin_clz(x) - 1 : 0) |
55 | | #define NONCONST_LOG2U(x) ({ \ |
56 | | unsigned _x = (x); \ |
57 | | _x > 1 ? __SIZEOF_INT__ * 8 - __builtin_clz(_x) - 1 : 0; \ |
58 | | }) |
59 | | #define LOG2U(x) __builtin_choose_expr(__builtin_constant_p(x), CONST_LOG2U(x), NONCONST_LOG2U(x)) |
60 | | |
61 | 0 | static inline unsigned log2i(int x) { |
62 | 0 | return LOG2U(x); |
63 | 0 | } Unexecuted instantiation: fuzz-link-parser.c:log2i Unexecuted instantiation: link-config.c:log2i Unexecuted instantiation: link-config-gperf.c:log2i |
64 | | |
65 | 0 | static inline unsigned log2u(unsigned x) { |
66 | 0 | return LOG2U(x); |
67 | 0 | } Unexecuted instantiation: fuzz-link-parser.c:log2u Unexecuted instantiation: link-config.c:log2u Unexecuted instantiation: link-config-gperf.c:log2u |
68 | | |
69 | 0 | static inline unsigned log2u_round_up(unsigned x) { |
70 | 0 | if (x <= 1) |
71 | 0 | return 0; |
72 | 0 |
|
73 | 0 | return log2u(x - 1) + 1; |
74 | 0 | } Unexecuted instantiation: fuzz-link-parser.c:log2u_round_up Unexecuted instantiation: link-config.c:log2u_round_up Unexecuted instantiation: link-config-gperf.c:log2u_round_up |
75 | | |
76 | | int container_get_leader(const char *machine, pid_t *pid); |
77 | | |
78 | | int version(void); |
79 | | |
80 | | void disable_coredumps(void); |