1*2d543d20SAndroid Build Coastguard Worker /* 2*2d543d20SAndroid Build Coastguard Worker * Copyright 2011 Tresys Technology, LLC. All rights reserved. 3*2d543d20SAndroid Build Coastguard Worker * 4*2d543d20SAndroid Build Coastguard Worker * Redistribution and use in source and binary forms, with or without 5*2d543d20SAndroid Build Coastguard Worker * modification, are permitted provided that the following conditions are met: 6*2d543d20SAndroid Build Coastguard Worker * 7*2d543d20SAndroid Build Coastguard Worker * 1. Redistributions of source code must retain the above copyright notice, 8*2d543d20SAndroid Build Coastguard Worker * this list of conditions and the following disclaimer. 9*2d543d20SAndroid Build Coastguard Worker * 10*2d543d20SAndroid Build Coastguard Worker * 2. Redistributions in binary form must reproduce the above copyright notice, 11*2d543d20SAndroid Build Coastguard Worker * this list of conditions and the following disclaimer in the documentation 12*2d543d20SAndroid Build Coastguard Worker * and/or other materials provided with the distribution. 13*2d543d20SAndroid Build Coastguard Worker * 14*2d543d20SAndroid Build Coastguard Worker * THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS 15*2d543d20SAndroid Build Coastguard Worker * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 16*2d543d20SAndroid Build Coastguard Worker * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 17*2d543d20SAndroid Build Coastguard Worker * EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 18*2d543d20SAndroid Build Coastguard Worker * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 19*2d543d20SAndroid Build Coastguard Worker * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20*2d543d20SAndroid Build Coastguard Worker * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 21*2d543d20SAndroid Build Coastguard Worker * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 22*2d543d20SAndroid Build Coastguard Worker * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 23*2d543d20SAndroid Build Coastguard Worker * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24*2d543d20SAndroid Build Coastguard Worker * 25*2d543d20SAndroid Build Coastguard Worker * The views and conclusions contained in the software and documentation are those 26*2d543d20SAndroid Build Coastguard Worker * of the authors and should not be interpreted as representing official policies, 27*2d543d20SAndroid Build Coastguard Worker * either expressed or implied, of Tresys Technology, LLC. 28*2d543d20SAndroid Build Coastguard Worker */ 29*2d543d20SAndroid Build Coastguard Worker 30*2d543d20SAndroid Build Coastguard Worker #ifndef __CIL_SYMTAB_H_ 31*2d543d20SAndroid Build Coastguard Worker #define __CIL_SYMTAB_H_ 32*2d543d20SAndroid Build Coastguard Worker 33*2d543d20SAndroid Build Coastguard Worker #include <sepol/policydb/symtab.h> 34*2d543d20SAndroid Build Coastguard Worker #include <sepol/policydb/hashtab.h> 35*2d543d20SAndroid Build Coastguard Worker 36*2d543d20SAndroid Build Coastguard Worker #include "cil_tree.h" 37*2d543d20SAndroid Build Coastguard Worker 38*2d543d20SAndroid Build Coastguard Worker struct cil_symtab_datum { 39*2d543d20SAndroid Build Coastguard Worker struct cil_list *nodes; 40*2d543d20SAndroid Build Coastguard Worker char *name; 41*2d543d20SAndroid Build Coastguard Worker char *fqn; 42*2d543d20SAndroid Build Coastguard Worker symtab_t *symtab; 43*2d543d20SAndroid Build Coastguard Worker }; 44*2d543d20SAndroid Build Coastguard Worker 45*2d543d20SAndroid Build Coastguard Worker #define DATUM(d) ((struct cil_symtab_datum *)(d)) 46*2d543d20SAndroid Build Coastguard Worker #define NODE(n) ((struct cil_tree_node *)(DATUM(n)->nodes->head->data)) 47*2d543d20SAndroid Build Coastguard Worker #define FLAVOR(f) (NODE(f)->flavor) 48*2d543d20SAndroid Build Coastguard Worker 49*2d543d20SAndroid Build Coastguard Worker struct cil_complex_symtab_key { 50*2d543d20SAndroid Build Coastguard Worker intptr_t key1; 51*2d543d20SAndroid Build Coastguard Worker intptr_t key2; 52*2d543d20SAndroid Build Coastguard Worker intptr_t key3; 53*2d543d20SAndroid Build Coastguard Worker intptr_t key4; 54*2d543d20SAndroid Build Coastguard Worker }; 55*2d543d20SAndroid Build Coastguard Worker 56*2d543d20SAndroid Build Coastguard Worker struct cil_complex_symtab_datum { 57*2d543d20SAndroid Build Coastguard Worker void *data; 58*2d543d20SAndroid Build Coastguard Worker }; 59*2d543d20SAndroid Build Coastguard Worker 60*2d543d20SAndroid Build Coastguard Worker struct cil_complex_symtab_node { 61*2d543d20SAndroid Build Coastguard Worker struct cil_complex_symtab_key *ckey; 62*2d543d20SAndroid Build Coastguard Worker struct cil_complex_symtab_datum *datum; 63*2d543d20SAndroid Build Coastguard Worker struct cil_complex_symtab_node *next; 64*2d543d20SAndroid Build Coastguard Worker }; 65*2d543d20SAndroid Build Coastguard Worker 66*2d543d20SAndroid Build Coastguard Worker struct cil_complex_symtab { 67*2d543d20SAndroid Build Coastguard Worker struct cil_complex_symtab_node **htable; 68*2d543d20SAndroid Build Coastguard Worker uint32_t nelems; 69*2d543d20SAndroid Build Coastguard Worker uint32_t nslots; 70*2d543d20SAndroid Build Coastguard Worker uint32_t mask; 71*2d543d20SAndroid Build Coastguard Worker }; 72*2d543d20SAndroid Build Coastguard Worker 73*2d543d20SAndroid Build Coastguard Worker void cil_symtab_init(symtab_t *symtab, unsigned int size); 74*2d543d20SAndroid Build Coastguard Worker void cil_symtab_datum_init(struct cil_symtab_datum *datum); 75*2d543d20SAndroid Build Coastguard Worker void cil_symtab_datum_destroy(struct cil_symtab_datum *datum); 76*2d543d20SAndroid Build Coastguard Worker void cil_symtab_datum_remove_node(struct cil_symtab_datum *datum, struct cil_tree_node *node); 77*2d543d20SAndroid Build Coastguard Worker int cil_symtab_insert(symtab_t *symtab, hashtab_key_t key, struct cil_symtab_datum *datum, struct cil_tree_node *node); 78*2d543d20SAndroid Build Coastguard Worker void cil_symtab_remove_datum(struct cil_symtab_datum *datum); 79*2d543d20SAndroid Build Coastguard Worker int cil_symtab_get_datum(symtab_t *symtab, char *key, struct cil_symtab_datum **datum); 80*2d543d20SAndroid Build Coastguard Worker int cil_symtab_map(symtab_t *symtab, 81*2d543d20SAndroid Build Coastguard Worker int (*apply) (hashtab_key_t k, hashtab_datum_t d, void *args), 82*2d543d20SAndroid Build Coastguard Worker void *args); 83*2d543d20SAndroid Build Coastguard Worker void cil_symtab_destroy(symtab_t *symtab); 84*2d543d20SAndroid Build Coastguard Worker void cil_complex_symtab_init(struct cil_complex_symtab *symtab, unsigned int size); 85*2d543d20SAndroid Build Coastguard Worker int cil_complex_symtab_insert(struct cil_complex_symtab *symtab, struct cil_complex_symtab_key *ckey, struct cil_complex_symtab_datum *datum); 86*2d543d20SAndroid Build Coastguard Worker void cil_complex_symtab_search(struct cil_complex_symtab *symtab, struct cil_complex_symtab_key *ckey, struct cil_complex_symtab_datum **out); 87*2d543d20SAndroid Build Coastguard Worker void cil_complex_symtab_destroy(struct cil_complex_symtab *symtab); 88*2d543d20SAndroid Build Coastguard Worker 89*2d543d20SAndroid Build Coastguard Worker #endif 90