1168404Spjd/* 2168404Spjd * CDDL HEADER START 3168404Spjd * 4168404Spjd * The contents of this file are subject to the terms of the 5168404Spjd * Common Development and Distribution License, Version 1.0 only 6168404Spjd * (the "License"). You may not use this file except in compliance 7168404Spjd * with the License. 8168404Spjd * 9168404Spjd * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10168404Spjd * or http://www.opensolaris.org/os/licensing. 11168404Spjd * See the License for the specific language governing permissions 12168404Spjd * and limitations under the License. 13168404Spjd * 14168404Spjd * When distributing Covered Code, include this CDDL HEADER in each 15168404Spjd * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16168404Spjd * If applicable, add the following below this CDDL HEADER, with the 17168404Spjd * fields enclosed by brackets "[]" replaced with your own identifying 18168404Spjd * information: Portions Copyright [yyyy] [name of copyright owner] 19168404Spjd * 20168404Spjd * CDDL HEADER END 21168404Spjd */ 22168404Spjd/* 23168404Spjd * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24168404Spjd * Use is subject to license terms. 25168404Spjd */ 26168404Spjd 27168404Spjd#ifndef _LIBUUTIL_IMPL_H 28168404Spjd#define _LIBUUTIL_IMPL_H 29168404Spjd 30168404Spjd#pragma ident "%Z%%M% %I% %E% SMI" 31168404Spjd 32168404Spjd#include <libuutil.h> 33168404Spjd#include <pthread.h> 34168404Spjd 35168404Spjd#include <sys/avl_impl.h> 36168404Spjd#include <sys/byteorder.h> 37168404Spjd 38168404Spjd#ifdef __cplusplus 39168404Spjdextern "C" { 40168404Spjd#endif 41168404Spjd 42168404Spjdvoid uu_set_error(uint_t); 43168404Spjd#pragma rarely_called(uu_set_error) 44168404Spjd 45168404Spjd/*PRINTFLIKE1*/ 46168404Spjdvoid uu_panic(const char *format, ...); 47168404Spjd#pragma rarely_called(uu_panic) 48168404Spjd 49168404Spjdstruct uu_dprintf { 50168404Spjd char *uud_name; 51168404Spjd uu_dprintf_severity_t uud_severity; 52168404Spjd uint_t uud_flags; 53168404Spjd}; 54168404Spjd 55168404Spjd/* 56168404Spjd * For debugging purposes, libuutil keeps around linked lists of all uu_lists 57168404Spjd * and uu_avls, along with pointers to their parents. These can cause false 58168404Spjd * negatives when looking for memory leaks, so we encode the pointers by 59168404Spjd * storing them with swapped endianness; this is not perfect, but it's about 60168404Spjd * the best we can do without wasting a lot of space. 61168404Spjd */ 62168404Spjd#ifdef _LP64 63168404Spjd#define UU_PTR_ENCODE(ptr) BSWAP_64((uintptr_t)(void *)(ptr)) 64168404Spjd#else 65168404Spjd#define UU_PTR_ENCODE(ptr) BSWAP_32((uintptr_t)(void *)(ptr)) 66168404Spjd#endif 67168404Spjd 68168404Spjd#define UU_PTR_DECODE(ptr) ((void *)UU_PTR_ENCODE(ptr)) 69168404Spjd 70168404Spjd/* 71168404Spjd * uu_list structures 72168404Spjd */ 73168404Spjdtypedef struct uu_list_node_impl { 74168404Spjd struct uu_list_node_impl *uln_next; 75168404Spjd struct uu_list_node_impl *uln_prev; 76168404Spjd} uu_list_node_impl_t; 77168404Spjd 78168404Spjdstruct uu_list_walk { 79168404Spjd uu_list_walk_t *ulw_next; 80168404Spjd uu_list_walk_t *ulw_prev; 81168404Spjd 82168404Spjd uu_list_t *ulw_list; 83168404Spjd int8_t ulw_dir; 84168404Spjd uint8_t ulw_robust; 85168404Spjd uu_list_node_impl_t *ulw_next_result; 86168404Spjd}; 87168404Spjd 88168404Spjdstruct uu_list { 89168404Spjd uintptr_t ul_next_enc; 90168404Spjd uintptr_t ul_prev_enc; 91168404Spjd 92168404Spjd uu_list_pool_t *ul_pool; 93168404Spjd uintptr_t ul_parent_enc; /* encoded parent pointer */ 94168404Spjd size_t ul_offset; 95168404Spjd size_t ul_numnodes; 96168404Spjd uint8_t ul_debug; 97168404Spjd uint8_t ul_sorted; 98168404Spjd uint8_t ul_index; /* mark for uu_list_index_ts */ 99168404Spjd 100168404Spjd uu_list_node_impl_t ul_null_node; 101168404Spjd uu_list_walk_t ul_null_walk; /* for robust walkers */ 102168404Spjd}; 103168404Spjd 104168404Spjd#define UU_LIST_PTR(ptr) ((uu_list_t *)UU_PTR_DECODE(ptr)) 105168404Spjd 106168404Spjd#define UU_LIST_POOL_MAXNAME 64 107168404Spjd 108168404Spjdstruct uu_list_pool { 109168404Spjd uu_list_pool_t *ulp_next; 110168404Spjd uu_list_pool_t *ulp_prev; 111168404Spjd 112168404Spjd char ulp_name[UU_LIST_POOL_MAXNAME]; 113168404Spjd size_t ulp_nodeoffset; 114168404Spjd size_t ulp_objsize; 115168404Spjd uu_compare_fn_t *ulp_cmp; 116168404Spjd uint8_t ulp_debug; 117168404Spjd uint8_t ulp_last_index; 118168404Spjd pthread_mutex_t ulp_lock; /* protects null_list */ 119168404Spjd uu_list_t ulp_null_list; 120168404Spjd}; 121168404Spjd 122168404Spjd/* 123168404Spjd * uu_avl structures 124168404Spjd */ 125168404Spjdtypedef struct avl_node uu_avl_node_impl_t; 126168404Spjd 127168404Spjdstruct uu_avl_walk { 128168404Spjd uu_avl_walk_t *uaw_next; 129168404Spjd uu_avl_walk_t *uaw_prev; 130168404Spjd 131168404Spjd uu_avl_t *uaw_avl; 132168404Spjd void *uaw_next_result; 133168404Spjd int8_t uaw_dir; 134168404Spjd uint8_t uaw_robust; 135168404Spjd}; 136168404Spjd 137168404Spjdstruct uu_avl { 138168404Spjd uintptr_t ua_next_enc; 139168404Spjd uintptr_t ua_prev_enc; 140168404Spjd 141168404Spjd uu_avl_pool_t *ua_pool; 142168404Spjd uintptr_t ua_parent_enc; 143168404Spjd uint8_t ua_debug; 144168404Spjd uint8_t ua_index; /* mark for uu_avl_index_ts */ 145168404Spjd 146168404Spjd struct avl_tree ua_tree; 147168404Spjd uu_avl_walk_t ua_null_walk; 148168404Spjd}; 149168404Spjd 150168404Spjd#define UU_AVL_PTR(x) ((uu_avl_t *)UU_PTR_DECODE(x)) 151168404Spjd 152168404Spjd#define UU_AVL_POOL_MAXNAME 64 153168404Spjd 154168404Spjdstruct uu_avl_pool { 155168404Spjd uu_avl_pool_t *uap_next; 156168404Spjd uu_avl_pool_t *uap_prev; 157168404Spjd 158168404Spjd char uap_name[UU_AVL_POOL_MAXNAME]; 159168404Spjd size_t uap_nodeoffset; 160168404Spjd size_t uap_objsize; 161168404Spjd uu_compare_fn_t *uap_cmp; 162168404Spjd uint8_t uap_debug; 163168404Spjd uint8_t uap_last_index; 164168404Spjd pthread_mutex_t uap_lock; /* protects null_avl */ 165168404Spjd uu_avl_t uap_null_avl; 166168404Spjd}; 167168404Spjd 168168404Spjd/* 169168404Spjd * atfork() handlers 170168404Spjd */ 171168404Spjdvoid uu_avl_lockup(void); 172168404Spjdvoid uu_avl_release(void); 173168404Spjd 174168404Spjdvoid uu_list_lockup(void); 175168404Spjdvoid uu_list_release(void); 176168404Spjd 177168404Spjd#ifdef __cplusplus 178168404Spjd} 179168404Spjd#endif 180168404Spjd 181168404Spjd#endif /* _LIBUUTIL_IMPL_H */ 182