resetting manifest requested domain to floor
[platform/upstream/acl.git] / libacl / libobj.h
1 /*
2   Copyright (C) 2000, 2002, 2003  Andreas Gruenbacher <agruen@suse.de>
3
4   This program is free software: you can redistribute it and/or modify it
5   under the terms of the GNU Lesser General Public License as published by
6   the Free Software Foundation, either version 2.1 of the License, or
7   (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   GNU Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public License
15   along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #ifndef __LIBOBJ_H
19 #define __LIBOBJ_H
20
21 #include <stdlib.h>
22
23 #include "config.h"
24
25 /* Mark library internal functions as hidden */
26 #if defined(HAVE_VISIBILITY_ATTRIBUTE)
27 # define hidden __attribute__((visibility("hidden")))
28 #else
29 # define hidden /* hidden */
30 #endif
31
32 /* Ugly pointer manipulation */
33
34 #ifdef LIBACL_DEBUG
35 #  define ext2int(T, ext_p) \
36         ((T##_obj *)__ext2int_and_check(ext_p, T##_MAGIC, #T))
37 #else
38 #  define ext2int(T, ext_p) \
39         ((T##_obj *)__ext2int_and_check(ext_p, T##_MAGIC))
40 #endif
41
42 #define int2ext(int_p) \
43         ((int_p) ? &(int_p)->i : NULL)
44 #define new_var_obj_p(T, sz) \
45         ((T##_obj *)__new_var_obj_p(T##_MAGIC, sizeof(T##_obj) + sz))
46 #define realloc_var_obj_p(T, p, sz) \
47         ((T##_obj *)realloc(p, sizeof(T##_obj) + sz))
48 #define new_obj_p(T) \
49         new_var_obj_p(T, 0)
50 #define new_obj_p_here(T, p) \
51         __new_obj_p_here(T##_MAGIC, p)
52 #define check_obj_p(T, obj_p) \
53         ((T##_obj *)__check_obj_p((obj_prefix *)(obj_p), T##_MAGIC))
54 #define free_obj_p(obj_p) \
55         (__free_obj_p((obj_prefix *)(obj_p)))
56
57
58 /* prefix for all objects */
59 /* [Note: p_magic is a long rather than int so that this structure */
60 /* does not become padded by the compiler on 64-bit architectures] */
61
62 typedef struct {
63         unsigned long           p_magic:16;
64         unsigned long           p_flags:16;
65 } obj_prefix;
66
67 #define pmagic o_prefix.p_magic
68 #define pflags o_prefix.p_flags
69
70 /* magic object values */
71 #define acl_MAGIC               (0x712C)
72 #define acl_entry_MAGIC         (0x9D6B)
73 #define acl_permset_MAGIC       (0x1ED5)
74 #define qualifier_MAGIC         (0x1C27)
75 #define string_MAGIC            (0xD5F2)
76 #define cap_MAGIC               (0x6CA8)
77
78 /* object flags */
79 #define OBJ_MALLOC_FLAG         1
80
81 /* object types */
82 struct string_obj_tag;
83 typedef struct string_obj_tag string_obj;
84
85 /* string object */
86 struct __string_ext {
87         char                    s_str[0];
88 };
89 struct string_obj_tag {
90         obj_prefix              o_prefix;
91         struct __string_ext     i;
92 };
93
94 #define sstr i.s_str
95
96 /* object creation, destruction, conversion and validation */
97 void *__new_var_obj_p(int magic, size_t size) hidden;
98 void __new_obj_p_here(int magic, void *here) hidden;
99 void __free_obj_p(obj_prefix *obj_p) hidden;
100 obj_prefix *__check_obj_p(obj_prefix *obj_p, int magic) hidden;
101 #ifdef LIBACL_DEBUG
102 obj_prefix *__ext2int_and_check(void *ext_p, int magic,
103                                 const char *typename) hidden;
104 #else
105 obj_prefix *__ext2int_and_check(void *ext_p, int magic) hidden;
106 #endif
107
108 #endif /* __LIBOBJ_H */