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