2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright (c) 2004, 2005, Oracle and/or its affiliates. All rights reserved.
2N/A */
2N/A
2N/A#ifndef _LIBUUTIL_IMPL_H
2N/A#define _LIBUUTIL_IMPL_H
2N/A
2N/A#include <libuutil.h>
2N/A#include <pthread.h>
2N/A
2N/A#include <sys/avl_impl.h>
2N/A#include <sys/byteorder.h>
2N/A
2N/A#ifdef __cplusplus
2N/Aextern "C" {
2N/A#endif
2N/A
2N/Avoid uu_set_error(uint_t);
2N/A#pragma rarely_called(uu_set_error)
2N/A
2N/A/*PRINTFLIKE1*/
2N/Avoid uu_panic(const char *format, ...);
2N/A#pragma rarely_called(uu_panic)
2N/A
2N/Astruct uu_dprintf {
2N/A char *uud_name;
2N/A uu_dprintf_severity_t uud_severity;
2N/A uint_t uud_flags;
2N/A};
2N/A
2N/A/*
2N/A * For debugging purposes, libuutil keeps around linked lists of all uu_lists
2N/A * and uu_avls, along with pointers to their parents. These can cause false
2N/A * negatives when looking for memory leaks, so we encode the pointers by
2N/A * storing them with swapped endianness; this is not perfect, but it's about
2N/A * the best we can do without wasting a lot of space.
2N/A */
2N/A#ifdef _LP64
2N/A#define UU_PTR_ENCODE(ptr) BSWAP_64((uintptr_t)(void *)(ptr))
2N/A#else
2N/A#define UU_PTR_ENCODE(ptr) BSWAP_32((uintptr_t)(void *)(ptr))
2N/A#endif
2N/A
2N/A#define UU_PTR_DECODE(ptr) ((void *)UU_PTR_ENCODE(ptr))
2N/A
2N/A/*
2N/A * uu_list structures
2N/A */
2N/Atypedef struct uu_list_node_impl {
2N/A struct uu_list_node_impl *uln_next;
2N/A struct uu_list_node_impl *uln_prev;
2N/A} uu_list_node_impl_t;
2N/A
2N/Astruct uu_list_walk {
2N/A uu_list_walk_t *ulw_next;
2N/A uu_list_walk_t *ulw_prev;
2N/A
2N/A uu_list_t *ulw_list;
2N/A int8_t ulw_dir;
2N/A uint8_t ulw_robust;
2N/A uu_list_node_impl_t *ulw_next_result;
2N/A};
2N/A
2N/Astruct uu_list {
2N/A uintptr_t ul_next_enc;
2N/A uintptr_t ul_prev_enc;
2N/A
2N/A uu_list_pool_t *ul_pool;
2N/A uintptr_t ul_parent_enc; /* encoded parent pointer */
2N/A size_t ul_offset;
2N/A size_t ul_numnodes;
2N/A uint8_t ul_debug;
2N/A uint8_t ul_sorted;
2N/A uint8_t ul_index; /* mark for uu_list_index_ts */
2N/A
2N/A uu_list_node_impl_t ul_null_node;
2N/A uu_list_walk_t ul_null_walk; /* for robust walkers */
2N/A};
2N/A
2N/A#define UU_LIST_PTR(ptr) ((uu_list_t *)UU_PTR_DECODE(ptr))
2N/A
2N/A#define UU_LIST_POOL_MAXNAME 64
2N/A
2N/Astruct uu_list_pool {
2N/A uu_list_pool_t *ulp_next;
2N/A uu_list_pool_t *ulp_prev;
2N/A
2N/A char ulp_name[UU_LIST_POOL_MAXNAME];
2N/A size_t ulp_nodeoffset;
2N/A size_t ulp_objsize;
2N/A uu_compare_fn_t *ulp_cmp;
2N/A uint8_t ulp_debug;
2N/A uint8_t ulp_last_index;
2N/A pthread_mutex_t ulp_lock; /* protects null_list */
2N/A uu_list_t ulp_null_list;
2N/A};
2N/A
2N/A/*
2N/A * uu_avl structures
2N/A */
2N/Atypedef struct avl_node uu_avl_node_impl_t;
2N/A
2N/Astruct uu_avl_walk {
2N/A uu_avl_walk_t *uaw_next;
2N/A uu_avl_walk_t *uaw_prev;
2N/A
2N/A uu_avl_t *uaw_avl;
2N/A void *uaw_next_result;
2N/A int8_t uaw_dir;
2N/A uint8_t uaw_robust;
2N/A};
2N/A
2N/Astruct uu_avl {
2N/A uintptr_t ua_next_enc;
2N/A uintptr_t ua_prev_enc;
2N/A
2N/A uu_avl_pool_t *ua_pool;
2N/A uintptr_t ua_parent_enc;
2N/A uint8_t ua_debug;
2N/A uint8_t ua_index; /* mark for uu_avl_index_ts */
2N/A
2N/A struct avl_tree ua_tree;
2N/A uu_avl_walk_t ua_null_walk;
2N/A};
2N/A
2N/A#define UU_AVL_PTR(x) ((uu_avl_t *)UU_PTR_DECODE(x))
2N/A
2N/A#define UU_AVL_POOL_MAXNAME 64
2N/A
2N/Astruct uu_avl_pool {
2N/A uu_avl_pool_t *uap_next;
2N/A uu_avl_pool_t *uap_prev;
2N/A
2N/A char uap_name[UU_AVL_POOL_MAXNAME];
2N/A size_t uap_nodeoffset;
2N/A size_t uap_objsize;
2N/A uu_compare_fn_t *uap_cmp;
2N/A uint8_t uap_debug;
2N/A uint8_t uap_last_index;
2N/A pthread_mutex_t uap_lock; /* protects null_avl */
2N/A uu_avl_t uap_null_avl;
2N/A};
2N/A
2N/A/*
2N/A * atfork() handlers
2N/A */
2N/Avoid uu_avl_lockup(void);
2N/Avoid uu_avl_release(void);
2N/A
2N/Avoid uu_list_lockup(void);
2N/Avoid uu_list_release(void);
2N/A
2N/A#ifdef __cplusplus
2N/A}
2N/A#endif
2N/A
2N/A#endif /* _LIBUUTIL_IMPL_H */