10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 70Sstevel@tonic-gate * with the License. 80Sstevel@tonic-gate * 90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 110Sstevel@tonic-gate * See the License for the specific language governing permissions 120Sstevel@tonic-gate * and limitations under the License. 130Sstevel@tonic-gate * 140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 190Sstevel@tonic-gate * 200Sstevel@tonic-gate * CDDL HEADER END 210Sstevel@tonic-gate */ 220Sstevel@tonic-gate /* 23*407Sjwadams * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #ifndef _LIBUUTIL_IMPL_H 280Sstevel@tonic-gate #define _LIBUUTIL_IMPL_H 290Sstevel@tonic-gate 300Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 310Sstevel@tonic-gate 320Sstevel@tonic-gate #include <libuutil.h> 330Sstevel@tonic-gate #include <pthread.h> 340Sstevel@tonic-gate 350Sstevel@tonic-gate #include <sys/avl_impl.h> 36*407Sjwadams #include <sys/byteorder.h> 370Sstevel@tonic-gate 380Sstevel@tonic-gate #ifdef __cplusplus 390Sstevel@tonic-gate extern "C" { 400Sstevel@tonic-gate #endif 410Sstevel@tonic-gate 420Sstevel@tonic-gate void uu_set_error(uint_t); 430Sstevel@tonic-gate #pragma rarely_called(uu_set_error) 440Sstevel@tonic-gate 450Sstevel@tonic-gate /*PRINTFLIKE1*/ 460Sstevel@tonic-gate void uu_panic(const char *format, ...); 470Sstevel@tonic-gate #pragma rarely_called(uu_panic) 480Sstevel@tonic-gate 490Sstevel@tonic-gate struct uu_dprintf { 500Sstevel@tonic-gate char *uud_name; 510Sstevel@tonic-gate uu_dprintf_severity_t uud_severity; 520Sstevel@tonic-gate uint_t uud_flags; 530Sstevel@tonic-gate }; 540Sstevel@tonic-gate 550Sstevel@tonic-gate /* 56*407Sjwadams * For debugging purposes, libuutil keeps around linked lists of all uu_lists 57*407Sjwadams * and uu_avls, along with pointers to their parents. These can cause false 58*407Sjwadams * negatives when looking for memory leaks, so we encode the pointers by 59*407Sjwadams * storing them with swapped endianness; this is not perfect, but it's about 60*407Sjwadams * the best we can do without wasting a lot of space. 61*407Sjwadams */ 62*407Sjwadams #ifdef _LP64 63*407Sjwadams #define UU_PTR_ENCODE(ptr) BSWAP_64((uintptr_t)(void *)(ptr)) 64*407Sjwadams #else 65*407Sjwadams #define UU_PTR_ENCODE(ptr) BSWAP_32((uintptr_t)(void *)(ptr)) 66*407Sjwadams #endif 67*407Sjwadams 68*407Sjwadams #define UU_PTR_DECODE(ptr) ((void *)UU_PTR_ENCODE(ptr)) 69*407Sjwadams 70*407Sjwadams /* 710Sstevel@tonic-gate * uu_list structures 720Sstevel@tonic-gate */ 730Sstevel@tonic-gate typedef struct uu_list_node_impl { 740Sstevel@tonic-gate struct uu_list_node_impl *uln_next; 750Sstevel@tonic-gate struct uu_list_node_impl *uln_prev; 760Sstevel@tonic-gate } uu_list_node_impl_t; 770Sstevel@tonic-gate 780Sstevel@tonic-gate struct uu_list_walk { 790Sstevel@tonic-gate uu_list_walk_t *ulw_next; 800Sstevel@tonic-gate uu_list_walk_t *ulw_prev; 810Sstevel@tonic-gate 820Sstevel@tonic-gate uu_list_t *ulw_list; 830Sstevel@tonic-gate int8_t ulw_dir; 840Sstevel@tonic-gate uint8_t ulw_robust; 850Sstevel@tonic-gate uu_list_node_impl_t *ulw_next_result; 860Sstevel@tonic-gate }; 870Sstevel@tonic-gate 880Sstevel@tonic-gate struct uu_list { 89*407Sjwadams uintptr_t ul_next_enc; 90*407Sjwadams uintptr_t ul_prev_enc; 910Sstevel@tonic-gate 920Sstevel@tonic-gate uu_list_pool_t *ul_pool; 93*407Sjwadams uintptr_t ul_parent_enc; /* encoded parent pointer */ 940Sstevel@tonic-gate size_t ul_offset; 950Sstevel@tonic-gate size_t ul_numnodes; 960Sstevel@tonic-gate uint8_t ul_debug; 970Sstevel@tonic-gate uint8_t ul_sorted; 980Sstevel@tonic-gate uint8_t ul_index; /* mark for uu_list_index_ts */ 990Sstevel@tonic-gate 1000Sstevel@tonic-gate uu_list_node_impl_t ul_null_node; 1010Sstevel@tonic-gate uu_list_walk_t ul_null_walk; /* for robust walkers */ 1020Sstevel@tonic-gate }; 1030Sstevel@tonic-gate 104*407Sjwadams #define UU_LIST_PTR(ptr) ((uu_list_t *)UU_PTR_DECODE(ptr)) 105*407Sjwadams 1060Sstevel@tonic-gate #define UU_LIST_POOL_MAXNAME 64 1070Sstevel@tonic-gate 1080Sstevel@tonic-gate struct uu_list_pool { 1090Sstevel@tonic-gate uu_list_pool_t *ulp_next; 1100Sstevel@tonic-gate uu_list_pool_t *ulp_prev; 1110Sstevel@tonic-gate 1120Sstevel@tonic-gate char ulp_name[UU_LIST_POOL_MAXNAME]; 1130Sstevel@tonic-gate size_t ulp_nodeoffset; 1140Sstevel@tonic-gate size_t ulp_objsize; 1150Sstevel@tonic-gate uu_compare_fn_t *ulp_cmp; 1160Sstevel@tonic-gate uint8_t ulp_debug; 1170Sstevel@tonic-gate uint8_t ulp_last_index; 1180Sstevel@tonic-gate pthread_mutex_t ulp_lock; /* protects null_list */ 1190Sstevel@tonic-gate uu_list_t ulp_null_list; 1200Sstevel@tonic-gate }; 1210Sstevel@tonic-gate 1220Sstevel@tonic-gate /* 1230Sstevel@tonic-gate * uu_avl structures 1240Sstevel@tonic-gate */ 1250Sstevel@tonic-gate typedef struct avl_node uu_avl_node_impl_t; 1260Sstevel@tonic-gate 1270Sstevel@tonic-gate struct uu_avl_walk { 1280Sstevel@tonic-gate uu_avl_walk_t *uaw_next; 1290Sstevel@tonic-gate uu_avl_walk_t *uaw_prev; 1300Sstevel@tonic-gate 1310Sstevel@tonic-gate uu_avl_t *uaw_avl; 1320Sstevel@tonic-gate void *uaw_next_result; 1330Sstevel@tonic-gate int8_t uaw_dir; 1340Sstevel@tonic-gate uint8_t uaw_robust; 1350Sstevel@tonic-gate }; 1360Sstevel@tonic-gate 1370Sstevel@tonic-gate struct uu_avl { 138*407Sjwadams uintptr_t ua_next_enc; 139*407Sjwadams uintptr_t ua_prev_enc; 1400Sstevel@tonic-gate 1410Sstevel@tonic-gate uu_avl_pool_t *ua_pool; 142*407Sjwadams uintptr_t ua_parent_enc; 1430Sstevel@tonic-gate uint8_t ua_debug; 1440Sstevel@tonic-gate uint8_t ua_index; /* mark for uu_avl_index_ts */ 1450Sstevel@tonic-gate 1460Sstevel@tonic-gate struct avl_tree ua_tree; 1470Sstevel@tonic-gate uu_avl_walk_t ua_null_walk; 1480Sstevel@tonic-gate }; 1490Sstevel@tonic-gate 150*407Sjwadams #define UU_AVL_PTR(x) ((uu_avl_t *)UU_PTR_DECODE(x)) 151*407Sjwadams 1520Sstevel@tonic-gate #define UU_AVL_POOL_MAXNAME 64 1530Sstevel@tonic-gate 1540Sstevel@tonic-gate struct uu_avl_pool { 1550Sstevel@tonic-gate uu_avl_pool_t *uap_next; 1560Sstevel@tonic-gate uu_avl_pool_t *uap_prev; 1570Sstevel@tonic-gate 1580Sstevel@tonic-gate char uap_name[UU_AVL_POOL_MAXNAME]; 1590Sstevel@tonic-gate size_t uap_nodeoffset; 1600Sstevel@tonic-gate size_t uap_objsize; 1610Sstevel@tonic-gate uu_compare_fn_t *uap_cmp; 1620Sstevel@tonic-gate uint8_t uap_debug; 1630Sstevel@tonic-gate uint8_t uap_last_index; 1640Sstevel@tonic-gate pthread_mutex_t uap_lock; /* protects null_avl */ 1650Sstevel@tonic-gate uu_avl_t uap_null_avl; 1660Sstevel@tonic-gate }; 1670Sstevel@tonic-gate 1680Sstevel@tonic-gate /* 1690Sstevel@tonic-gate * atfork() handlers 1700Sstevel@tonic-gate */ 1710Sstevel@tonic-gate void uu_avl_lockup(void); 1720Sstevel@tonic-gate void uu_avl_release(void); 1730Sstevel@tonic-gate 1740Sstevel@tonic-gate void uu_list_lockup(void); 1750Sstevel@tonic-gate void uu_list_release(void); 1760Sstevel@tonic-gate 1770Sstevel@tonic-gate #ifdef __cplusplus 1780Sstevel@tonic-gate } 1790Sstevel@tonic-gate #endif 1800Sstevel@tonic-gate 1810Sstevel@tonic-gate #endif /* _LIBUUTIL_IMPL_H */ 182