1 1.1 haad /* 2 1.1 haad * CDDL HEADER START 3 1.1 haad * 4 1.1 haad * The contents of this file are subject to the terms of the 5 1.1 haad * Common Development and Distribution License, Version 1.0 only 6 1.1 haad * (the "License"). You may not use this file except in compliance 7 1.1 haad * with the License. 8 1.1 haad * 9 1.1 haad * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 1.1 haad * or http://www.opensolaris.org/os/licensing. 11 1.1 haad * See the License for the specific language governing permissions 12 1.1 haad * and limitations under the License. 13 1.1 haad * 14 1.1 haad * When distributing Covered Code, include this CDDL HEADER in each 15 1.1 haad * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 1.1 haad * If applicable, add the following below this CDDL HEADER, with the 17 1.1 haad * fields enclosed by brackets "[]" replaced with your own identifying 18 1.1 haad * information: Portions Copyright [yyyy] [name of copyright owner] 19 1.1 haad * 20 1.1 haad * CDDL HEADER END 21 1.1 haad */ 22 1.1 haad /* 23 1.1 haad * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 1.1 haad * Use is subject to license terms. 25 1.1 haad */ 26 1.1 haad 27 1.1 haad #ifndef _LIBUUTIL_IMPL_H 28 1.1 haad #define _LIBUUTIL_IMPL_H 29 1.1 haad 30 1.1 haad #pragma ident "%Z%%M% %I% %E% SMI" 31 1.1 haad 32 1.1 haad #include <libuutil.h> 33 1.1 haad #include <pthread.h> 34 1.1 haad 35 1.1 haad #include <sys/avl_impl.h> 36 1.1 haad #include <sys/byteorder.h> 37 1.1 haad 38 1.1 haad #ifdef __cplusplus 39 1.1 haad extern "C" { 40 1.1 haad #endif 41 1.1 haad 42 1.1 haad void uu_set_error(uint_t); 43 1.1 haad #pragma rarely_called(uu_set_error) 44 1.1 haad 45 1.1 haad /*PRINTFLIKE1*/ 46 1.1 haad void uu_panic(const char *format, ...); 47 1.1 haad #pragma rarely_called(uu_panic) 48 1.1 haad 49 1.1 haad struct uu_dprintf { 50 1.1 haad char *uud_name; 51 1.1 haad uu_dprintf_severity_t uud_severity; 52 1.1 haad uint_t uud_flags; 53 1.1 haad }; 54 1.1 haad 55 1.1 haad /* 56 1.1 haad * For debugging purposes, libuutil keeps around linked lists of all uu_lists 57 1.1 haad * and uu_avls, along with pointers to their parents. These can cause false 58 1.1 haad * negatives when looking for memory leaks, so we encode the pointers by 59 1.1 haad * storing them with swapped endianness; this is not perfect, but it's about 60 1.1 haad * the best we can do without wasting a lot of space. 61 1.1 haad */ 62 1.1 haad #ifdef _LP64 63 1.1 haad #define UU_PTR_ENCODE(ptr) BSWAP_64((uintptr_t)(void *)(ptr)) 64 1.1 haad #else 65 1.1 haad #define UU_PTR_ENCODE(ptr) BSWAP_32((uintptr_t)(void *)(ptr)) 66 1.1 haad #endif 67 1.1 haad 68 1.1 haad #define UU_PTR_DECODE(ptr) ((void *)UU_PTR_ENCODE(ptr)) 69 1.1 haad 70 1.1 haad /* 71 1.1 haad * uu_list structures 72 1.1 haad */ 73 1.1 haad typedef struct uu_list_node_impl { 74 1.1 haad struct uu_list_node_impl *uln_next; 75 1.1 haad struct uu_list_node_impl *uln_prev; 76 1.1 haad } uu_list_node_impl_t; 77 1.1 haad 78 1.1 haad struct uu_list_walk { 79 1.1 haad uu_list_walk_t *ulw_next; 80 1.1 haad uu_list_walk_t *ulw_prev; 81 1.1 haad 82 1.1 haad uu_list_t *ulw_list; 83 1.1 haad int8_t ulw_dir; 84 1.1 haad uint8_t ulw_robust; 85 1.1 haad uu_list_node_impl_t *ulw_next_result; 86 1.1 haad }; 87 1.1 haad 88 1.1 haad struct uu_list { 89 1.1 haad uintptr_t ul_next_enc; 90 1.1 haad uintptr_t ul_prev_enc; 91 1.1 haad 92 1.1 haad uu_list_pool_t *ul_pool; 93 1.1 haad uintptr_t ul_parent_enc; /* encoded parent pointer */ 94 1.1 haad size_t ul_offset; 95 1.1 haad size_t ul_numnodes; 96 1.1 haad uint8_t ul_debug; 97 1.1 haad uint8_t ul_sorted; 98 1.1 haad uint8_t ul_index; /* mark for uu_list_index_ts */ 99 1.1 haad 100 1.1 haad uu_list_node_impl_t ul_null_node; 101 1.1 haad uu_list_walk_t ul_null_walk; /* for robust walkers */ 102 1.1 haad }; 103 1.1 haad 104 1.1 haad #define UU_LIST_PTR(ptr) ((uu_list_t *)UU_PTR_DECODE(ptr)) 105 1.1 haad 106 1.1 haad #define UU_LIST_POOL_MAXNAME 64 107 1.1 haad 108 1.1 haad struct uu_list_pool { 109 1.1 haad uu_list_pool_t *ulp_next; 110 1.1 haad uu_list_pool_t *ulp_prev; 111 1.1 haad 112 1.1 haad char ulp_name[UU_LIST_POOL_MAXNAME]; 113 1.1 haad size_t ulp_nodeoffset; 114 1.1 haad size_t ulp_objsize; 115 1.1 haad uu_compare_fn_t *ulp_cmp; 116 1.1 haad uint8_t ulp_debug; 117 1.1 haad uint8_t ulp_last_index; 118 1.1 haad pthread_mutex_t ulp_lock; /* protects null_list */ 119 1.1 haad uu_list_t ulp_null_list; 120 1.1 haad }; 121 1.1 haad 122 1.1 haad /* 123 1.1 haad * uu_avl structures 124 1.1 haad */ 125 1.1 haad typedef struct avl_node uu_avl_node_impl_t; 126 1.1 haad 127 1.1 haad struct uu_avl_walk { 128 1.1 haad uu_avl_walk_t *uaw_next; 129 1.1 haad uu_avl_walk_t *uaw_prev; 130 1.1 haad 131 1.1 haad uu_avl_t *uaw_avl; 132 1.1 haad void *uaw_next_result; 133 1.1 haad int8_t uaw_dir; 134 1.1 haad uint8_t uaw_robust; 135 1.1 haad }; 136 1.1 haad 137 1.1 haad struct uu_avl { 138 1.1 haad uintptr_t ua_next_enc; 139 1.1 haad uintptr_t ua_prev_enc; 140 1.1 haad 141 1.1 haad uu_avl_pool_t *ua_pool; 142 1.1 haad uintptr_t ua_parent_enc; 143 1.1 haad uint8_t ua_debug; 144 1.1 haad uint8_t ua_index; /* mark for uu_avl_index_ts */ 145 1.1 haad 146 1.1 haad struct avl_tree ua_tree; 147 1.1 haad uu_avl_walk_t ua_null_walk; 148 1.1 haad }; 149 1.1 haad 150 1.1 haad #define UU_AVL_PTR(x) ((uu_avl_t *)UU_PTR_DECODE(x)) 151 1.1 haad 152 1.1 haad #define UU_AVL_POOL_MAXNAME 64 153 1.1 haad 154 1.1 haad struct uu_avl_pool { 155 1.1 haad uu_avl_pool_t *uap_next; 156 1.1 haad uu_avl_pool_t *uap_prev; 157 1.1 haad 158 1.1 haad char uap_name[UU_AVL_POOL_MAXNAME]; 159 1.1 haad size_t uap_nodeoffset; 160 1.1 haad size_t uap_objsize; 161 1.1 haad uu_compare_fn_t *uap_cmp; 162 1.1 haad uint8_t uap_debug; 163 1.1 haad uint8_t uap_last_index; 164 1.1 haad pthread_mutex_t uap_lock; /* protects null_avl */ 165 1.1 haad uu_avl_t uap_null_avl; 166 1.1 haad }; 167 1.1 haad 168 1.1 haad /* 169 1.1 haad * atfork() handlers 170 1.1 haad */ 171 1.1 haad void uu_avl_lockup(void); 172 1.1 haad void uu_avl_release(void); 173 1.1 haad 174 1.1 haad void uu_list_lockup(void); 175 1.1 haad void uu_list_release(void); 176 1.1 haad 177 1.1 haad #ifdef __cplusplus 178 1.1 haad } 179 1.1 haad #endif 180 1.1 haad 181 1.1 haad #endif /* _LIBUUTIL_IMPL_H */ 182