/src/selinux/libselinux/src/selinux_internal.h
Line | Count | Source |
1 | | #ifndef SELINUX_INTERNAL_H_ |
2 | | #define SELINUX_INTERNAL_H_ |
3 | | |
4 | | #include <selinux/selinux.h> |
5 | | #include <errno.h> |
6 | | #include <pthread.h> |
7 | | #include <stdio.h> |
8 | | |
9 | | extern int require_seusers; |
10 | | extern size_t selinux_page_size; |
11 | | |
12 | | /* Make pthread_once optional */ |
13 | | #pragma weak pthread_once |
14 | | #pragma weak pthread_key_create |
15 | | #pragma weak pthread_key_delete |
16 | | #pragma weak pthread_setspecific |
17 | | #pragma weak pthread_getspecific |
18 | | |
19 | | /* Call handler iff the first call. */ |
20 | | #define __selinux_once(ONCE_CONTROL, INIT_FUNCTION) \ |
21 | 268k | do { \ |
22 | 268k | if (pthread_once != NULL) \ |
23 | 268k | pthread_once(&(ONCE_CONTROL), (INIT_FUNCTION)); \ |
24 | 268k | else if ((ONCE_CONTROL) == PTHREAD_ONCE_INIT) { \ |
25 | 0 | INIT_FUNCTION(); \ |
26 | 0 | (ONCE_CONTROL) = 2; \ |
27 | 0 | } \ |
28 | 268k | } while (0) |
29 | | |
30 | | /* Pthread key macros */ |
31 | | #define __selinux_key_create(KEY, DESTRUCTOR) \ |
32 | 2 | (pthread_key_create != NULL ? pthread_key_create(KEY, DESTRUCTOR) : -1) |
33 | | |
34 | | #define __selinux_key_delete(KEY) \ |
35 | 0 | do { \ |
36 | 0 | if (pthread_key_delete != NULL) \ |
37 | 0 | pthread_key_delete(KEY); \ |
38 | 0 | } while (0) |
39 | | |
40 | | #define __selinux_setspecific(KEY, VALUE) \ |
41 | 2 | do { \ |
42 | 2 | if (pthread_setspecific != NULL) \ |
43 | 2 | pthread_setspecific(KEY, VALUE); \ |
44 | 2 | } while (0) |
45 | | |
46 | | #define __selinux_getspecific(KEY) \ |
47 | 257k | (pthread_getspecific != NULL ? pthread_getspecific(KEY) : NULL) |
48 | | |
49 | | /* selabel_lookup() is only thread safe if we're compiled with pthreads */ |
50 | | |
51 | | #pragma weak pthread_mutex_init |
52 | | #pragma weak pthread_mutex_destroy |
53 | | #pragma weak pthread_mutex_lock |
54 | | #pragma weak pthread_mutex_unlock |
55 | | |
56 | | #define __pthread_mutex_init(LOCK, ATTR) \ |
57 | 12.8k | do { \ |
58 | 12.8k | if (pthread_mutex_init != NULL) \ |
59 | 12.8k | pthread_mutex_init(LOCK, ATTR); \ |
60 | 12.8k | } while (0) |
61 | | |
62 | | #define __pthread_mutex_destroy(LOCK) \ |
63 | 3.24M | do { \ |
64 | 3.24M | if (pthread_mutex_destroy != NULL) \ |
65 | 3.24M | pthread_mutex_destroy(LOCK); \ |
66 | 3.24M | } while (0) |
67 | | |
68 | | #define __pthread_mutex_lock(LOCK) \ |
69 | 3.22M | do { \ |
70 | 3.22M | if (pthread_mutex_lock != NULL) \ |
71 | 3.22M | pthread_mutex_lock(LOCK); \ |
72 | 3.22M | } while (0) |
73 | | |
74 | | #define __pthread_mutex_unlock(LOCK) \ |
75 | 3.22M | do { \ |
76 | 3.22M | if (pthread_mutex_unlock != NULL) \ |
77 | 3.22M | pthread_mutex_unlock(LOCK); \ |
78 | 3.22M | } while (0) |
79 | | |
80 | | #pragma weak pthread_create |
81 | | #pragma weak pthread_join |
82 | | #pragma weak pthread_cond_init |
83 | | #pragma weak pthread_cond_signal |
84 | | #pragma weak pthread_cond_destroy |
85 | | #pragma weak pthread_cond_wait |
86 | | |
87 | | /* check if all functions needed to do parallel operations are available */ |
88 | | #define __pthread_supported \ |
89 | | (pthread_create && pthread_join && pthread_cond_init && \ |
90 | | pthread_cond_destroy && pthread_cond_signal && pthread_cond_wait) |
91 | | |
92 | 4 | #define SELINUXDIR "/etc/selinux/" |
93 | 4 | #define SELINUXCONFIG SELINUXDIR "config" |
94 | | |
95 | | extern int has_selinux_config; |
96 | | |
97 | | #ifndef HAVE_STRLCPY |
98 | | size_t strlcpy(char *dest, const char *src, size_t size); |
99 | | #endif |
100 | | |
101 | | #ifndef HAVE_REALLOCARRAY |
102 | | void *reallocarray(void *ptr, size_t nmemb, size_t size); |
103 | | #endif |
104 | | |
105 | | /* Use to ignore intentional unsigned under- and overflows while running under UBSAN. */ |
106 | | #if defined(__clang__) && defined(__clang_major__) && (__clang_major__ >= 4) |
107 | | #if (__clang_major__ >= 12) |
108 | | #define ignore_unsigned_overflow_ \ |
109 | | __attribute__((no_sanitize("unsigned-integer-overflow", \ |
110 | | "unsigned-shift-base"))) |
111 | | #else |
112 | | #define ignore_unsigned_overflow_ \ |
113 | | __attribute__((no_sanitize("unsigned-integer-overflow"))) |
114 | | #endif |
115 | | #else |
116 | | #define ignore_unsigned_overflow_ |
117 | | #endif |
118 | | |
119 | | /* Ignore usage of deprecated declaration */ |
120 | | #ifdef __clang__ |
121 | | #define IGNORE_DEPRECATED_DECLARATION_BEGIN \ |
122 | | _Pragma("clang diagnostic push") _Pragma( \ |
123 | | "clang diagnostic ignored \"-Wdeprecated-declarations\"") |
124 | | #define IGNORE_DEPRECATED_DECLARATION_END _Pragma("clang diagnostic pop") |
125 | | #elif defined __GNUC__ |
126 | | #define IGNORE_DEPRECATED_DECLARATION_BEGIN \ |
127 | | _Pragma("GCC diagnostic push") _Pragma( \ |
128 | | "GCC diagnostic ignored \"-Wdeprecated-declarations\"") |
129 | | #define IGNORE_DEPRECATED_DECLARATION_END _Pragma("GCC diagnostic pop") |
130 | | #else |
131 | | #define IGNORE_DEPRECATED_DECLARATION_BEGIN |
132 | | #define IGNORE_DEPRECATED_DECLARATION_END |
133 | | #endif |
134 | | |
135 | | static inline void fclose_errno_safe(FILE *stream) |
136 | 0 | { |
137 | 0 | int saved_errno; |
138 | |
|
139 | 0 | saved_errno = errno; |
140 | 0 | (void)fclose(stream); |
141 | 0 | errno = saved_errno; |
142 | 0 | } Unexecuted instantiation: selabel_file_compiled-fuzzer.c:fclose_errno_safe Unexecuted instantiation: callbacks.c:fclose_errno_safe Unexecuted instantiation: check_context.c:fclose_errno_safe Unexecuted instantiation: freecon.c:fclose_errno_safe Unexecuted instantiation: init.c:fclose_errno_safe Unexecuted instantiation: label_file.c:fclose_errno_safe Unexecuted instantiation: matchpathcon.c:fclose_errno_safe Unexecuted instantiation: regex.c:fclose_errno_safe Unexecuted instantiation: selinux_config.c:fclose_errno_safe Unexecuted instantiation: setrans_client.c:fclose_errno_safe Unexecuted instantiation: seusers.c:fclose_errno_safe Unexecuted instantiation: sha1.c:fclose_errno_safe Unexecuted instantiation: canonicalize_context.c:fclose_errno_safe Unexecuted instantiation: enabled.c:fclose_errno_safe Unexecuted instantiation: label.c:fclose_errno_safe Unexecuted instantiation: label_db.c:fclose_errno_safe Unexecuted instantiation: label_media.c:fclose_errno_safe Unexecuted instantiation: label_x.c:fclose_errno_safe Unexecuted instantiation: lgetfilecon.c:fclose_errno_safe Unexecuted instantiation: lsetfilecon.c:fclose_errno_safe Unexecuted instantiation: policyvers.c:fclose_errno_safe Unexecuted instantiation: selinux_internal.c:fclose_errno_safe Unexecuted instantiation: selabel_file_text-fuzzer.c:fclose_errno_safe |
143 | | |
144 | | #ifdef __GNUC__ |
145 | 517k | #define likely(x) __builtin_expect(!!(x), 1) |
146 | 114k | #define unlikely(x) __builtin_expect(!!(x), 0) |
147 | | #else |
148 | | #define likely(x) (x) |
149 | | #define unlikely(x) (x) |
150 | | #endif /* __GNUC__ */ |
151 | | |
152 | 12.5M | #define spaceship_cmp(a, b) (((a) > (b)) - ((a) < (b))) |
153 | | |
154 | | static inline void selinux_reset_errno(int *saved_errno) |
155 | 4 | { |
156 | 4 | errno = *saved_errno; |
157 | 4 | } Unexecuted instantiation: selabel_file_compiled-fuzzer.c:selinux_reset_errno Unexecuted instantiation: callbacks.c:selinux_reset_errno Unexecuted instantiation: check_context.c:selinux_reset_errno Unexecuted instantiation: freecon.c:selinux_reset_errno init.c:selinux_reset_errno Line | Count | Source | 155 | 4 | { | 156 | | errno = *saved_errno; | 157 | 4 | } |
Unexecuted instantiation: label_file.c:selinux_reset_errno Unexecuted instantiation: matchpathcon.c:selinux_reset_errno Unexecuted instantiation: regex.c:selinux_reset_errno Unexecuted instantiation: selinux_config.c:selinux_reset_errno Unexecuted instantiation: setrans_client.c:selinux_reset_errno Unexecuted instantiation: seusers.c:selinux_reset_errno Unexecuted instantiation: sha1.c:selinux_reset_errno Unexecuted instantiation: canonicalize_context.c:selinux_reset_errno Unexecuted instantiation: enabled.c:selinux_reset_errno Unexecuted instantiation: label.c:selinux_reset_errno Unexecuted instantiation: label_db.c:selinux_reset_errno Unexecuted instantiation: label_media.c:selinux_reset_errno Unexecuted instantiation: label_x.c:selinux_reset_errno Unexecuted instantiation: lgetfilecon.c:selinux_reset_errno Unexecuted instantiation: lsetfilecon.c:selinux_reset_errno Unexecuted instantiation: policyvers.c:selinux_reset_errno Unexecuted instantiation: selinux_internal.c:selinux_reset_errno Unexecuted instantiation: selabel_file_text-fuzzer.c:selinux_reset_errno |
158 | | |
159 | | #define SELINUX_PROTECT_ERRNO \ |
160 | 4 | __attribute__((__cleanup__(selinux_reset_errno))) \ |
161 | 4 | __attribute__((__unused__)) int _saved_errno = errno |
162 | | |
163 | | #endif /* SELINUX_INTERNAL_H_ */ |