diff options
Diffstat (limited to 'usr/src/lib/libuutil/common/libuutil_impl.h')
-rw-r--r-- | usr/src/lib/libuutil/common/libuutil_impl.h | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/usr/src/lib/libuutil/common/libuutil_impl.h b/usr/src/lib/libuutil/common/libuutil_impl.h index 101671095a..9466e59745 100644 --- a/usr/src/lib/libuutil/common/libuutil_impl.h +++ b/usr/src/lib/libuutil/common/libuutil_impl.h @@ -20,7 +20,7 @@ * CDDL HEADER END */ /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -33,6 +33,7 @@ #include <pthread.h> #include <sys/avl_impl.h> +#include <sys/byteorder.h> #ifdef __cplusplus extern "C" { @@ -52,6 +53,21 @@ struct uu_dprintf { }; /* + * For debugging purposes, libuutil keeps around linked lists of all uu_lists + * and uu_avls, along with pointers to their parents. These can cause false + * negatives when looking for memory leaks, so we encode the pointers by + * storing them with swapped endianness; this is not perfect, but it's about + * the best we can do without wasting a lot of space. + */ +#ifdef _LP64 +#define UU_PTR_ENCODE(ptr) BSWAP_64((uintptr_t)(void *)(ptr)) +#else +#define UU_PTR_ENCODE(ptr) BSWAP_32((uintptr_t)(void *)(ptr)) +#endif + +#define UU_PTR_DECODE(ptr) ((void *)UU_PTR_ENCODE(ptr)) + +/* * uu_list structures */ typedef struct uu_list_node_impl { @@ -70,11 +86,11 @@ struct uu_list_walk { }; struct uu_list { - uu_list_t *ul_next; - uu_list_t *ul_prev; + uintptr_t ul_next_enc; + uintptr_t ul_prev_enc; uu_list_pool_t *ul_pool; - void *ul_parent; + uintptr_t ul_parent_enc; /* encoded parent pointer */ size_t ul_offset; size_t ul_numnodes; uint8_t ul_debug; @@ -85,6 +101,8 @@ struct uu_list { uu_list_walk_t ul_null_walk; /* for robust walkers */ }; +#define UU_LIST_PTR(ptr) ((uu_list_t *)UU_PTR_DECODE(ptr)) + #define UU_LIST_POOL_MAXNAME 64 struct uu_list_pool { @@ -117,11 +135,11 @@ struct uu_avl_walk { }; struct uu_avl { - uu_avl_t *ua_next; - uu_avl_t *ua_prev; + uintptr_t ua_next_enc; + uintptr_t ua_prev_enc; uu_avl_pool_t *ua_pool; - void *ua_parent; + uintptr_t ua_parent_enc; uint8_t ua_debug; uint8_t ua_index; /* mark for uu_avl_index_ts */ @@ -129,6 +147,8 @@ struct uu_avl { uu_avl_walk_t ua_null_walk; }; +#define UU_AVL_PTR(x) ((uu_avl_t *)UU_PTR_DECODE(x)) + #define UU_AVL_POOL_MAXNAME 64 struct uu_avl_pool { |