1#ifndef __LIBOBJ_H 2#define __LIBOBJ_H 3 4#include <stdlib.h> 5 6#include "config.h" 7 8/* Mark library internal functions as hidden */ 9#if defined(HAVE_VISIBILITY_ATTRIBUTE) 10# define hidden __attribute__((visibility("hidden"))) 11#else 12# define hidden /* hidden */ 13#endif 14 15/* Ugly pointer manipulation */ 16 17#ifdef LIBACL_DEBUG 18# define ext2int(T, ext_p) \ 19 ((T##_obj *)__ext2int_and_check(ext_p, T##_MAGIC, #T)) 20#else 21# define ext2int(T, ext_p) \ 22 ((T##_obj *)__ext2int_and_check(ext_p, T##_MAGIC)) 23#endif 24 25#define int2ext(int_p) \ 26 ((int_p) ? &(int_p)->i : NULL) 27#define new_var_obj_p(T, sz) \ 28 ((T##_obj *)__new_var_obj_p(T##_MAGIC, sizeof(T##_obj) + sz)) 29#define realloc_var_obj_p(T, p, sz) \ 30 ((T##_obj *)realloc(p, sizeof(T##_obj) + sz)) 31#define new_obj_p(T) \ 32 new_var_obj_p(T, 0) 33#define new_obj_p_here(T, p) \ 34 __new_obj_p_here(T##_MAGIC, p) 35#define check_obj_p(T, obj_p) \ 36 ((T##_obj *)__check_obj_p((obj_prefix *)(obj_p), T##_MAGIC)) 37#define free_obj_p(obj_p) \ 38 (__free_obj_p((obj_prefix *)(obj_p))) 39 40 41/* prefix for all objects */ 42/* [Note: p_magic is a long rather than int so that this structure */ 43/* does not become padded by the compiler on 64-bit architectures] */ 44 45typedef struct { 46 unsigned long p_magic:16; 47 unsigned long p_flags:16; 48} obj_prefix; 49 50#define pmagic o_prefix.p_magic 51#define pflags o_prefix.p_flags 52 53/* magic object values */ 54#define acl_MAGIC (0x712C) 55#define acl_entry_MAGIC (0x9D6B) 56#define acl_permset_MAGIC (0x1ED5) 57#define qualifier_MAGIC (0x1C27) 58#define string_MAGIC (0xD5F2) 59#define cap_MAGIC (0x6CA8) 60 61/* object flags */ 62#define OBJ_MALLOC_FLAG 1 63 64/* object types */ 65struct string_obj_tag; 66typedef struct string_obj_tag string_obj; 67 68/* string object */ 69struct __string_ext { 70 char s_str[0]; 71}; 72struct string_obj_tag { 73 obj_prefix o_prefix; 74 struct __string_ext i; 75}; 76 77#define sstr i.s_str 78 79/* object creation, destruction, conversion and validation */ 80void *__new_var_obj_p(int magic, size_t size) hidden; 81void __new_obj_p_here(int magic, void *here) hidden; 82void __free_obj_p(obj_prefix *obj_p) hidden; 83obj_prefix *__check_obj_p(obj_prefix *obj_p, int magic) hidden; 84#ifdef LIBACL_DEBUG 85obj_prefix *__ext2int_and_check(void *ext_p, int magic, 86 const char *typename) hidden; 87#else 88obj_prefix *__ext2int_and_check(void *ext_p, int magic) hidden; 89#endif 90 91#endif /* __LIBOBJ_H */ 92