4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #ifndef _LIBUUTIL_IMPL_H
28 #define _LIBUUTIL_IMPL_H
35 #include <sys/avl_impl.h>
36 #include <sys/byteorder.h>
42 void uu_set_error(uint_t
);
46 void uu_panic(const char *format
, ...);
50 * For debugging purposes, libuutil keeps around linked lists of all uu_lists
51 * and uu_avls, along with pointers to their parents. These can cause false
52 * negatives when looking for memory leaks, so we encode the pointers by
53 * storing them with swapped endianness; this is not perfect, but it's about
54 * the best we can do without wasting a lot of space.
57 #define UU_PTR_ENCODE(ptr) BSWAP_64((uintptr_t)(void *)(ptr))
59 #define UU_PTR_ENCODE(ptr) BSWAP_32((uintptr_t)(void *)(ptr))
62 #define UU_PTR_DECODE(ptr) ((void *)UU_PTR_ENCODE(ptr))
67 typedef struct uu_list_node_impl
{
68 struct uu_list_node_impl
*uln_next
;
69 struct uu_list_node_impl
*uln_prev
;
70 } uu_list_node_impl_t
;
73 uu_list_walk_t
*ulw_next
;
74 uu_list_walk_t
*ulw_prev
;
79 uu_list_node_impl_t
*ulw_next_result
;
83 uintptr_t ul_next_enc
;
84 uintptr_t ul_prev_enc
;
86 uu_list_pool_t
*ul_pool
;
87 uintptr_t ul_parent_enc
; /* encoded parent pointer */
92 uint8_t ul_index
; /* mark for uu_list_index_ts */
94 uu_list_node_impl_t ul_null_node
;
95 uu_list_walk_t ul_null_walk
; /* for robust walkers */
98 #define UU_LIST_PTR(ptr) ((uu_list_t *)UU_PTR_DECODE(ptr))
100 #define UU_LIST_POOL_MAXNAME 64
102 struct uu_list_pool
{
103 uu_list_pool_t
*ulp_next
;
104 uu_list_pool_t
*ulp_prev
;
106 char ulp_name
[UU_LIST_POOL_MAXNAME
];
107 size_t ulp_nodeoffset
;
109 uu_compare_fn_t
*ulp_cmp
;
111 uint8_t ulp_last_index
;
112 pthread_mutex_t ulp_lock
; /* protects null_list */
113 uu_list_t ulp_null_list
;
119 typedef struct avl_node uu_avl_node_impl_t
;
122 uu_avl_walk_t
*uaw_next
;
123 uu_avl_walk_t
*uaw_prev
;
126 void *uaw_next_result
;
132 uintptr_t ua_next_enc
;
133 uintptr_t ua_prev_enc
;
135 uu_avl_pool_t
*ua_pool
;
136 uintptr_t ua_parent_enc
;
138 uint8_t ua_index
; /* mark for uu_avl_index_ts */
140 struct avl_tree ua_tree
;
141 uu_avl_walk_t ua_null_walk
;
144 #define UU_AVL_PTR(x) ((uu_avl_t *)UU_PTR_DECODE(x))
146 #define UU_AVL_POOL_MAXNAME 64
149 uu_avl_pool_t
*uap_next
;
150 uu_avl_pool_t
*uap_prev
;
152 char uap_name
[UU_AVL_POOL_MAXNAME
];
153 size_t uap_nodeoffset
;
155 uu_compare_fn_t
*uap_cmp
;
157 uint8_t uap_last_index
;
158 pthread_mutex_t uap_lock
; /* protects null_avl */
159 uu_avl_t uap_null_avl
;
165 void uu_avl_lockup(void);
166 void uu_avl_release(void);
168 void uu_list_lockup(void);
169 void uu_list_release(void);
175 #endif /* _LIBUUTIL_IMPL_H */