1/* Private definitions for libsepol. */ 2 3/* Endian conversion for reading and writing binary policies */ 4 5#include <sepol/policydb/policydb.h> 6 7 8#ifdef DARWIN 9#include <sys/types.h> 10#include <machine/endian.h> 11#else 12#include <byteswap.h> 13#include <endian.h> 14#endif 15 16#include <errno.h> 17#include <dso.h> 18 19#ifdef DARWIN 20#define __BYTE_ORDER BYTE_ORDER 21#define __LITTLE_ENDIAN LITTLE_ENDIAN 22#endif 23 24#if __BYTE_ORDER == __LITTLE_ENDIAN 25#define cpu_to_le16(x) (x) 26#define le16_to_cpu(x) (x) 27#define cpu_to_le32(x) (x) 28#define le32_to_cpu(x) (x) 29#define cpu_to_le64(x) (x) 30#define le64_to_cpu(x) (x) 31#else 32#define cpu_to_le16(x) bswap_16(x) 33#define le16_to_cpu(x) bswap_16(x) 34#define cpu_to_le32(x) bswap_32(x) 35#define le32_to_cpu(x) bswap_32(x) 36#define cpu_to_le64(x) bswap_64(x) 37#define le64_to_cpu(x) bswap_64(x) 38#endif 39 40#undef min 41#define min(a,b) (((a) < (b)) ? (a) : (b)) 42 43#undef max 44#define max(a,b) ((a) >= (b) ? (a) : (b)) 45 46#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0])) 47 48/* Policy compatibility information. */ 49struct policydb_compat_info { 50 unsigned int type; 51 unsigned int version; 52 unsigned int sym_num; 53 unsigned int ocon_num; 54 unsigned int target_platform; 55}; 56 57extern struct policydb_compat_info *policydb_lookup_compat(unsigned int version, 58 unsigned int type, 59 unsigned int target_platform); 60 61/* Reading from a policy "file". */ 62extern int next_entry(void *buf, struct policy_file *fp, size_t bytes) hidden; 63extern size_t put_entry(const void *ptr, size_t size, size_t n, 64 struct policy_file *fp) hidden; 65