17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 23*8918dff3Sjwadams * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #ifndef _LIBUUTIL_IMPL_H 287c478bd9Sstevel@tonic-gate #define _LIBUUTIL_IMPL_H 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate #include <libuutil.h> 337c478bd9Sstevel@tonic-gate #include <pthread.h> 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate #include <sys/avl_impl.h> 36*8918dff3Sjwadams #include <sys/byteorder.h> 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate #ifdef __cplusplus 397c478bd9Sstevel@tonic-gate extern "C" { 407c478bd9Sstevel@tonic-gate #endif 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate void uu_set_error(uint_t); 437c478bd9Sstevel@tonic-gate #pragma rarely_called(uu_set_error) 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gate /*PRINTFLIKE1*/ 467c478bd9Sstevel@tonic-gate void uu_panic(const char *format, ...); 477c478bd9Sstevel@tonic-gate #pragma rarely_called(uu_panic) 487c478bd9Sstevel@tonic-gate 497c478bd9Sstevel@tonic-gate struct uu_dprintf { 507c478bd9Sstevel@tonic-gate char *uud_name; 517c478bd9Sstevel@tonic-gate uu_dprintf_severity_t uud_severity; 527c478bd9Sstevel@tonic-gate uint_t uud_flags; 537c478bd9Sstevel@tonic-gate }; 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate /* 56*8918dff3Sjwadams * For debugging purposes, libuutil keeps around linked lists of all uu_lists 57*8918dff3Sjwadams * and uu_avls, along with pointers to their parents. These can cause false 58*8918dff3Sjwadams * negatives when looking for memory leaks, so we encode the pointers by 59*8918dff3Sjwadams * storing them with swapped endianness; this is not perfect, but it's about 60*8918dff3Sjwadams * the best we can do without wasting a lot of space. 61*8918dff3Sjwadams */ 62*8918dff3Sjwadams #ifdef _LP64 63*8918dff3Sjwadams #define UU_PTR_ENCODE(ptr) BSWAP_64((uintptr_t)(void *)(ptr)) 64*8918dff3Sjwadams #else 65*8918dff3Sjwadams #define UU_PTR_ENCODE(ptr) BSWAP_32((uintptr_t)(void *)(ptr)) 66*8918dff3Sjwadams #endif 67*8918dff3Sjwadams 68*8918dff3Sjwadams #define UU_PTR_DECODE(ptr) ((void *)UU_PTR_ENCODE(ptr)) 69*8918dff3Sjwadams 70*8918dff3Sjwadams /* 717c478bd9Sstevel@tonic-gate * uu_list structures 727c478bd9Sstevel@tonic-gate */ 737c478bd9Sstevel@tonic-gate typedef struct uu_list_node_impl { 747c478bd9Sstevel@tonic-gate struct uu_list_node_impl *uln_next; 757c478bd9Sstevel@tonic-gate struct uu_list_node_impl *uln_prev; 767c478bd9Sstevel@tonic-gate } uu_list_node_impl_t; 777c478bd9Sstevel@tonic-gate 787c478bd9Sstevel@tonic-gate struct uu_list_walk { 797c478bd9Sstevel@tonic-gate uu_list_walk_t *ulw_next; 807c478bd9Sstevel@tonic-gate uu_list_walk_t *ulw_prev; 817c478bd9Sstevel@tonic-gate 827c478bd9Sstevel@tonic-gate uu_list_t *ulw_list; 837c478bd9Sstevel@tonic-gate int8_t ulw_dir; 847c478bd9Sstevel@tonic-gate uint8_t ulw_robust; 857c478bd9Sstevel@tonic-gate uu_list_node_impl_t *ulw_next_result; 867c478bd9Sstevel@tonic-gate }; 877c478bd9Sstevel@tonic-gate 887c478bd9Sstevel@tonic-gate struct uu_list { 89*8918dff3Sjwadams uintptr_t ul_next_enc; 90*8918dff3Sjwadams uintptr_t ul_prev_enc; 917c478bd9Sstevel@tonic-gate 927c478bd9Sstevel@tonic-gate uu_list_pool_t *ul_pool; 93*8918dff3Sjwadams uintptr_t ul_parent_enc; /* encoded parent pointer */ 947c478bd9Sstevel@tonic-gate size_t ul_offset; 957c478bd9Sstevel@tonic-gate size_t ul_numnodes; 967c478bd9Sstevel@tonic-gate uint8_t ul_debug; 977c478bd9Sstevel@tonic-gate uint8_t ul_sorted; 987c478bd9Sstevel@tonic-gate uint8_t ul_index; /* mark for uu_list_index_ts */ 997c478bd9Sstevel@tonic-gate 1007c478bd9Sstevel@tonic-gate uu_list_node_impl_t ul_null_node; 1017c478bd9Sstevel@tonic-gate uu_list_walk_t ul_null_walk; /* for robust walkers */ 1027c478bd9Sstevel@tonic-gate }; 1037c478bd9Sstevel@tonic-gate 104*8918dff3Sjwadams #define UU_LIST_PTR(ptr) ((uu_list_t *)UU_PTR_DECODE(ptr)) 105*8918dff3Sjwadams 1067c478bd9Sstevel@tonic-gate #define UU_LIST_POOL_MAXNAME 64 1077c478bd9Sstevel@tonic-gate 1087c478bd9Sstevel@tonic-gate struct uu_list_pool { 1097c478bd9Sstevel@tonic-gate uu_list_pool_t *ulp_next; 1107c478bd9Sstevel@tonic-gate uu_list_pool_t *ulp_prev; 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate char ulp_name[UU_LIST_POOL_MAXNAME]; 1137c478bd9Sstevel@tonic-gate size_t ulp_nodeoffset; 1147c478bd9Sstevel@tonic-gate size_t ulp_objsize; 1157c478bd9Sstevel@tonic-gate uu_compare_fn_t *ulp_cmp; 1167c478bd9Sstevel@tonic-gate uint8_t ulp_debug; 1177c478bd9Sstevel@tonic-gate uint8_t ulp_last_index; 1187c478bd9Sstevel@tonic-gate pthread_mutex_t ulp_lock; /* protects null_list */ 1197c478bd9Sstevel@tonic-gate uu_list_t ulp_null_list; 1207c478bd9Sstevel@tonic-gate }; 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate /* 1237c478bd9Sstevel@tonic-gate * uu_avl structures 1247c478bd9Sstevel@tonic-gate */ 1257c478bd9Sstevel@tonic-gate typedef struct avl_node uu_avl_node_impl_t; 1267c478bd9Sstevel@tonic-gate 1277c478bd9Sstevel@tonic-gate struct uu_avl_walk { 1287c478bd9Sstevel@tonic-gate uu_avl_walk_t *uaw_next; 1297c478bd9Sstevel@tonic-gate uu_avl_walk_t *uaw_prev; 1307c478bd9Sstevel@tonic-gate 1317c478bd9Sstevel@tonic-gate uu_avl_t *uaw_avl; 1327c478bd9Sstevel@tonic-gate void *uaw_next_result; 1337c478bd9Sstevel@tonic-gate int8_t uaw_dir; 1347c478bd9Sstevel@tonic-gate uint8_t uaw_robust; 1357c478bd9Sstevel@tonic-gate }; 1367c478bd9Sstevel@tonic-gate 1377c478bd9Sstevel@tonic-gate struct uu_avl { 138*8918dff3Sjwadams uintptr_t ua_next_enc; 139*8918dff3Sjwadams uintptr_t ua_prev_enc; 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate uu_avl_pool_t *ua_pool; 142*8918dff3Sjwadams uintptr_t ua_parent_enc; 1437c478bd9Sstevel@tonic-gate uint8_t ua_debug; 1447c478bd9Sstevel@tonic-gate uint8_t ua_index; /* mark for uu_avl_index_ts */ 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate struct avl_tree ua_tree; 1477c478bd9Sstevel@tonic-gate uu_avl_walk_t ua_null_walk; 1487c478bd9Sstevel@tonic-gate }; 1497c478bd9Sstevel@tonic-gate 150*8918dff3Sjwadams #define UU_AVL_PTR(x) ((uu_avl_t *)UU_PTR_DECODE(x)) 151*8918dff3Sjwadams 1527c478bd9Sstevel@tonic-gate #define UU_AVL_POOL_MAXNAME 64 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate struct uu_avl_pool { 1557c478bd9Sstevel@tonic-gate uu_avl_pool_t *uap_next; 1567c478bd9Sstevel@tonic-gate uu_avl_pool_t *uap_prev; 1577c478bd9Sstevel@tonic-gate 1587c478bd9Sstevel@tonic-gate char uap_name[UU_AVL_POOL_MAXNAME]; 1597c478bd9Sstevel@tonic-gate size_t uap_nodeoffset; 1607c478bd9Sstevel@tonic-gate size_t uap_objsize; 1617c478bd9Sstevel@tonic-gate uu_compare_fn_t *uap_cmp; 1627c478bd9Sstevel@tonic-gate uint8_t uap_debug; 1637c478bd9Sstevel@tonic-gate uint8_t uap_last_index; 1647c478bd9Sstevel@tonic-gate pthread_mutex_t uap_lock; /* protects null_avl */ 1657c478bd9Sstevel@tonic-gate uu_avl_t uap_null_avl; 1667c478bd9Sstevel@tonic-gate }; 1677c478bd9Sstevel@tonic-gate 1687c478bd9Sstevel@tonic-gate /* 1697c478bd9Sstevel@tonic-gate * atfork() handlers 1707c478bd9Sstevel@tonic-gate */ 1717c478bd9Sstevel@tonic-gate void uu_avl_lockup(void); 1727c478bd9Sstevel@tonic-gate void uu_avl_release(void); 1737c478bd9Sstevel@tonic-gate 1747c478bd9Sstevel@tonic-gate void uu_list_lockup(void); 1757c478bd9Sstevel@tonic-gate void uu_list_release(void); 1767c478bd9Sstevel@tonic-gate 1777c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1787c478bd9Sstevel@tonic-gate } 1797c478bd9Sstevel@tonic-gate #endif 1807c478bd9Sstevel@tonic-gate 1817c478bd9Sstevel@tonic-gate #endif /* _LIBUUTIL_IMPL_H */ 182