• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef SELINUX_INTERNAL_H_
2 #define SELINUX_INTERNAL_H_
3 
4 #include <selinux/selinux.h>
5 #include <pthread.h>
6 
7 
8 extern int require_seusers ;
9 extern int selinux_page_size ;
10 
11 /* Make pthread_once optional */
12 #pragma weak pthread_once
13 #pragma weak pthread_key_create
14 #pragma weak pthread_key_delete
15 #pragma weak pthread_setspecific
16 #pragma weak pthread_getspecific
17 
18 /* Call handler iff the first call.  */
19 #define __selinux_once(ONCE_CONTROL, INIT_FUNCTION)	\
20 	do {						\
21 		if (pthread_once != NULL)		\
22 			pthread_once (&(ONCE_CONTROL), (INIT_FUNCTION));  \
23 		else if ((ONCE_CONTROL) == PTHREAD_ONCE_INIT) {		  \
24 			INIT_FUNCTION ();		\
25 			(ONCE_CONTROL) = 2;		\
26 		}					\
27 	} while (0)
28 
29 /* Pthread key macros */
30 #define __selinux_key_create(KEY, DESTRUCTOR)			\
31 	(pthread_key_create != NULL ? pthread_key_create(KEY, DESTRUCTOR) : -1)
32 
33 #define __selinux_key_delete(KEY)				\
34 	do {							\
35 		if (pthread_key_delete != NULL)			\
36 			pthread_key_delete(KEY);		\
37 	} while (0)
38 
39 #define __selinux_setspecific(KEY, VALUE)			\
40 	do {							\
41 		if (pthread_setspecific != NULL)		\
42 			pthread_setspecific(KEY, VALUE);	\
43 	} while (0)
44 
45 #define __selinux_getspecific(KEY)				\
46 	(pthread_getspecific != NULL ? pthread_getspecific(KEY) : NULL)
47 
48 /* selabel_lookup() is only thread safe if we're compiled with pthreads */
49 
50 #pragma weak pthread_mutex_init
51 #pragma weak pthread_mutex_destroy
52 #pragma weak pthread_mutex_lock
53 #pragma weak pthread_mutex_unlock
54 
55 #define __pthread_mutex_init(LOCK, ATTR) 			\
56 	do {							\
57 		if (pthread_mutex_init != NULL)			\
58 			pthread_mutex_init(LOCK, ATTR);		\
59 	} while (0)
60 
61 #define __pthread_mutex_destroy(LOCK) 				\
62 	do {							\
63 		if (pthread_mutex_destroy != NULL)		\
64 			pthread_mutex_destroy(LOCK);		\
65 	} while (0)
66 
67 #define __pthread_mutex_lock(LOCK) 				\
68 	do {							\
69 		if (pthread_mutex_lock != NULL)			\
70 			pthread_mutex_lock(LOCK);		\
71 	} while (0)
72 
73 #define __pthread_mutex_unlock(LOCK) 				\
74 	do {							\
75 		if (pthread_mutex_unlock != NULL)		\
76 			pthread_mutex_unlock(LOCK);		\
77 	} while (0)
78 
79 #pragma weak pthread_create
80 #pragma weak pthread_join
81 #pragma weak pthread_cond_init
82 #pragma weak pthread_cond_signal
83 #pragma weak pthread_cond_destroy
84 #pragma weak pthread_cond_wait
85 
86 /* check if all functions needed to do parallel operations are available */
87 #define __pthread_supported (					\
88 	pthread_create &&					\
89 	pthread_join &&						\
90 	pthread_cond_init &&					\
91 	pthread_cond_destroy &&					\
92 	pthread_cond_signal &&					\
93 	pthread_cond_wait					\
94 )
95 
96 #define SELINUXDIR "/etc/selinux/"
97 #define SELINUXCONFIG SELINUXDIR "config"
98 
99 extern int has_selinux_config ;
100 
101 #ifndef HAVE_STRLCPY
102 size_t strlcpy(char *dest, const char *src, size_t size);
103 #endif
104 
105 #endif /* SELINUX_INTERNAL_H_ */
106