4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
29 * Routines for manipulating iidesc_t structures
41 typedef struct iidesc_find {
47 iidesc_new(char *name)
51 ii = xcalloc(sizeof (iidesc_t));
53 ii->ii_name = xstrdup(name);
59 iidesc_hash(int nbuckets, void *arg)
65 return (hash_name(nbuckets, ii->ii_name));
71 iidesc_cmp(void *arg1, void *arg2)
74 iidesc_find_t *find = arg2;
75 iidesc_t *tgt = find->iif_tgt;
77 if (src->ii_type != tgt->ii_type ||
78 !streq(src->ii_name, tgt->ii_name))
87 iidesc_add(hash_t *hash, iidesc_t *new)
94 (void) hash_match(hash, new, iidesc_cmp, &find);
96 if (find.iif_ret != NULL) {
97 iidesc_t *old = find.iif_ret;
99 /* replacing existing one */
100 bcopy(old, &tmp, sizeof (tmp));
101 bcopy(new, old, sizeof (*old));
102 bcopy(&tmp, new, sizeof (*new));
104 iidesc_free(new, NULL);
112 iter_iidescs_by_name(tdata_t *td, char const *name,
113 int (*func)(void *, void *), void *data)
116 bzero(&tmpdesc, sizeof(tmpdesc));
117 tmpdesc.ii_name = xstrdup(name);
118 (void) hash_match(td->td_iihash, &tmpdesc, func, data);
119 free(tmpdesc.ii_name);
123 iidesc_dup(iidesc_t *src)
127 tgt = xmalloc(sizeof (iidesc_t));
128 bcopy(src, tgt, sizeof (iidesc_t));
130 tgt->ii_name = src->ii_name ? xstrdup(src->ii_name) : NULL;
131 tgt->ii_owner = src->ii_owner ? xstrdup(src->ii_owner) : NULL;
134 tgt->ii_args = xmalloc(sizeof (tdesc_t *) * tgt->ii_nargs);
135 bcopy(src->ii_args, tgt->ii_args,
136 sizeof (tdesc_t *) * tgt->ii_nargs);
143 iidesc_dup_rename(iidesc_t *src, char const *name, char const *owner)
145 iidesc_t *tgt = iidesc_dup(src);
149 tgt->ii_name = name ? xstrdup(name) : NULL;
150 tgt->ii_owner = owner ? xstrdup(owner) : NULL;
157 iidesc_free(void *arg, void *private __unused)
170 iidesc_dump(iidesc_t *ii)
172 printf("type: %d name %s\n", ii->ii_type,
173 (ii->ii_name ? ii->ii_name : "(anon)"));
179 iidesc_count_type(void *data, void *private)
182 iitype_t match = (iitype_t)private;
184 return (ii->ii_type == match);
188 iidesc_stats(hash_t *ii)
190 printf("GFun: %5d SFun: %5d GVar: %5d SVar: %5d T %5d SOU: %5d\n",
191 hash_iter(ii, iidesc_count_type, (void *)II_GFUN),
192 hash_iter(ii, iidesc_count_type, (void *)II_SFUN),
193 hash_iter(ii, iidesc_count_type, (void *)II_GVAR),
194 hash_iter(ii, iidesc_count_type, (void *)II_SVAR),
195 hash_iter(ii, iidesc_count_type, (void *)II_TYPE),
196 hash_iter(ii, iidesc_count_type, (void *)II_SOU));