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
5*3276Sjhaslam * Common Development and Distribution License (the "License").
6*3276Sjhaslam * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*3276Sjhaslam * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
230Sstevel@tonic-gate * Use is subject to license terms.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
270Sstevel@tonic-gate
280Sstevel@tonic-gate #include <stdlib.h>
290Sstevel@tonic-gate #include <strings.h>
300Sstevel@tonic-gate #include <errno.h>
310Sstevel@tonic-gate #include <unistd.h>
320Sstevel@tonic-gate #include <assert.h>
330Sstevel@tonic-gate
340Sstevel@tonic-gate #include <dt_impl.h>
350Sstevel@tonic-gate #include <dt_printf.h>
360Sstevel@tonic-gate
370Sstevel@tonic-gate static int
dt_epid_add(dtrace_hdl_t * dtp,dtrace_epid_t id)380Sstevel@tonic-gate dt_epid_add(dtrace_hdl_t *dtp, dtrace_epid_t id)
390Sstevel@tonic-gate {
400Sstevel@tonic-gate dtrace_id_t max;
410Sstevel@tonic-gate int rval, i, maxformat;
420Sstevel@tonic-gate dtrace_eprobedesc_t *enabled, *nenabled;
430Sstevel@tonic-gate dtrace_probedesc_t *probe;
440Sstevel@tonic-gate
450Sstevel@tonic-gate while (id >= (max = dtp->dt_maxprobe) || dtp->dt_pdesc == NULL) {
460Sstevel@tonic-gate dtrace_id_t new_max = max ? (max << 1) : 1;
470Sstevel@tonic-gate size_t nsize = new_max * sizeof (void *);
480Sstevel@tonic-gate dtrace_probedesc_t **new_pdesc;
490Sstevel@tonic-gate dtrace_eprobedesc_t **new_edesc;
500Sstevel@tonic-gate
510Sstevel@tonic-gate if ((new_pdesc = malloc(nsize)) == NULL ||
520Sstevel@tonic-gate (new_edesc = malloc(nsize)) == NULL) {
530Sstevel@tonic-gate free(new_pdesc);
540Sstevel@tonic-gate return (dt_set_errno(dtp, EDT_NOMEM));
550Sstevel@tonic-gate }
560Sstevel@tonic-gate
570Sstevel@tonic-gate bzero(new_pdesc, nsize);
580Sstevel@tonic-gate bzero(new_edesc, nsize);
590Sstevel@tonic-gate
600Sstevel@tonic-gate if (dtp->dt_pdesc != NULL) {
610Sstevel@tonic-gate size_t osize = max * sizeof (void *);
620Sstevel@tonic-gate
630Sstevel@tonic-gate bcopy(dtp->dt_pdesc, new_pdesc, osize);
640Sstevel@tonic-gate free(dtp->dt_pdesc);
650Sstevel@tonic-gate
660Sstevel@tonic-gate bcopy(dtp->dt_edesc, new_edesc, osize);
670Sstevel@tonic-gate free(dtp->dt_edesc);
680Sstevel@tonic-gate }
690Sstevel@tonic-gate
700Sstevel@tonic-gate dtp->dt_pdesc = new_pdesc;
710Sstevel@tonic-gate dtp->dt_edesc = new_edesc;
720Sstevel@tonic-gate dtp->dt_maxprobe = new_max;
730Sstevel@tonic-gate }
740Sstevel@tonic-gate
750Sstevel@tonic-gate if (dtp->dt_pdesc[id] != NULL)
760Sstevel@tonic-gate return (0);
770Sstevel@tonic-gate
780Sstevel@tonic-gate if ((enabled = malloc(sizeof (dtrace_eprobedesc_t))) == NULL)
790Sstevel@tonic-gate return (dt_set_errno(dtp, EDT_NOMEM));
800Sstevel@tonic-gate
810Sstevel@tonic-gate bzero(enabled, sizeof (dtrace_eprobedesc_t));
820Sstevel@tonic-gate enabled->dtepd_epid = id;
830Sstevel@tonic-gate enabled->dtepd_nrecs = 1;
840Sstevel@tonic-gate
850Sstevel@tonic-gate if (dt_ioctl(dtp, DTRACEIOC_EPROBE, enabled) == -1) {
860Sstevel@tonic-gate rval = dt_set_errno(dtp, errno);
870Sstevel@tonic-gate free(enabled);
880Sstevel@tonic-gate return (rval);
890Sstevel@tonic-gate }
900Sstevel@tonic-gate
910Sstevel@tonic-gate if (DTRACE_SIZEOF_EPROBEDESC(enabled) != sizeof (*enabled)) {
920Sstevel@tonic-gate /*
930Sstevel@tonic-gate * There must be more than one action. Allocate the
940Sstevel@tonic-gate * appropriate amount of space and try again.
950Sstevel@tonic-gate */
960Sstevel@tonic-gate if ((nenabled =
970Sstevel@tonic-gate malloc(DTRACE_SIZEOF_EPROBEDESC(enabled))) != NULL)
980Sstevel@tonic-gate bcopy(enabled, nenabled, sizeof (*enabled));
990Sstevel@tonic-gate
1000Sstevel@tonic-gate free(enabled);
1010Sstevel@tonic-gate
1020Sstevel@tonic-gate if ((enabled = nenabled) == NULL)
1030Sstevel@tonic-gate return (dt_set_errno(dtp, EDT_NOMEM));
1040Sstevel@tonic-gate
1050Sstevel@tonic-gate rval = dt_ioctl(dtp, DTRACEIOC_EPROBE, enabled);
1060Sstevel@tonic-gate
1070Sstevel@tonic-gate if (rval == -1) {
1080Sstevel@tonic-gate rval = dt_set_errno(dtp, errno);
1090Sstevel@tonic-gate free(enabled);
1100Sstevel@tonic-gate return (rval);
1110Sstevel@tonic-gate }
1120Sstevel@tonic-gate }
1130Sstevel@tonic-gate
1140Sstevel@tonic-gate if ((probe = malloc(sizeof (dtrace_probedesc_t))) == NULL) {
1150Sstevel@tonic-gate free(enabled);
1160Sstevel@tonic-gate return (dt_set_errno(dtp, EDT_NOMEM));
1170Sstevel@tonic-gate }
1180Sstevel@tonic-gate
1190Sstevel@tonic-gate probe->dtpd_id = enabled->dtepd_probeid;
1200Sstevel@tonic-gate
1210Sstevel@tonic-gate if (dt_ioctl(dtp, DTRACEIOC_PROBES, probe) == -1) {
1220Sstevel@tonic-gate rval = dt_set_errno(dtp, errno);
1230Sstevel@tonic-gate goto err;
1240Sstevel@tonic-gate }
1250Sstevel@tonic-gate
1260Sstevel@tonic-gate for (i = 0; i < enabled->dtepd_nrecs; i++) {
1270Sstevel@tonic-gate dtrace_fmtdesc_t fmt;
1280Sstevel@tonic-gate dtrace_recdesc_t *rec = &enabled->dtepd_rec[i];
1290Sstevel@tonic-gate
1300Sstevel@tonic-gate if (!DTRACEACT_ISPRINTFLIKE(rec->dtrd_action))
1310Sstevel@tonic-gate continue;
1320Sstevel@tonic-gate
1330Sstevel@tonic-gate if (rec->dtrd_format == 0)
1340Sstevel@tonic-gate continue;
1350Sstevel@tonic-gate
1360Sstevel@tonic-gate if (rec->dtrd_format <= dtp->dt_maxformat &&
1370Sstevel@tonic-gate dtp->dt_formats[rec->dtrd_format - 1] != NULL)
1380Sstevel@tonic-gate continue;
1390Sstevel@tonic-gate
1400Sstevel@tonic-gate bzero(&fmt, sizeof (fmt));
1410Sstevel@tonic-gate fmt.dtfd_format = rec->dtrd_format;
1420Sstevel@tonic-gate fmt.dtfd_string = NULL;
1430Sstevel@tonic-gate fmt.dtfd_length = 0;
1440Sstevel@tonic-gate
1450Sstevel@tonic-gate if (dt_ioctl(dtp, DTRACEIOC_FORMAT, &fmt) == -1) {
1460Sstevel@tonic-gate rval = dt_set_errno(dtp, errno);
1470Sstevel@tonic-gate goto err;
1480Sstevel@tonic-gate }
1490Sstevel@tonic-gate
1500Sstevel@tonic-gate if ((fmt.dtfd_string = malloc(fmt.dtfd_length)) == NULL) {
1510Sstevel@tonic-gate rval = dt_set_errno(dtp, EDT_NOMEM);
1520Sstevel@tonic-gate goto err;
1530Sstevel@tonic-gate }
1540Sstevel@tonic-gate
1550Sstevel@tonic-gate if (dt_ioctl(dtp, DTRACEIOC_FORMAT, &fmt) == -1) {
1560Sstevel@tonic-gate rval = dt_set_errno(dtp, errno);
1570Sstevel@tonic-gate free(fmt.dtfd_string);
1580Sstevel@tonic-gate goto err;
1590Sstevel@tonic-gate }
1600Sstevel@tonic-gate
1610Sstevel@tonic-gate while (rec->dtrd_format > (maxformat = dtp->dt_maxformat)) {
1620Sstevel@tonic-gate int new_max = maxformat ? (maxformat << 1) : 1;
1630Sstevel@tonic-gate size_t nsize = new_max * sizeof (void *);
1640Sstevel@tonic-gate size_t osize = maxformat * sizeof (void *);
1650Sstevel@tonic-gate void **new_formats = malloc(nsize);
1660Sstevel@tonic-gate
1670Sstevel@tonic-gate if (new_formats == NULL) {
1680Sstevel@tonic-gate rval = dt_set_errno(dtp, EDT_NOMEM);
1690Sstevel@tonic-gate free(fmt.dtfd_string);
1700Sstevel@tonic-gate goto err;
1710Sstevel@tonic-gate }
1720Sstevel@tonic-gate
1730Sstevel@tonic-gate bzero(new_formats, nsize);
1740Sstevel@tonic-gate bcopy(dtp->dt_formats, new_formats, osize);
1750Sstevel@tonic-gate free(dtp->dt_formats);
1760Sstevel@tonic-gate
1770Sstevel@tonic-gate dtp->dt_formats = new_formats;
1780Sstevel@tonic-gate dtp->dt_maxformat = new_max;
1790Sstevel@tonic-gate }
1800Sstevel@tonic-gate
1810Sstevel@tonic-gate dtp->dt_formats[rec->dtrd_format - 1] =
1820Sstevel@tonic-gate rec->dtrd_action == DTRACEACT_PRINTA ?
1830Sstevel@tonic-gate dtrace_printa_create(dtp, fmt.dtfd_string) :
1840Sstevel@tonic-gate dtrace_printf_create(dtp, fmt.dtfd_string);
1850Sstevel@tonic-gate
1860Sstevel@tonic-gate free(fmt.dtfd_string);
1870Sstevel@tonic-gate
1880Sstevel@tonic-gate if (dtp->dt_formats[rec->dtrd_format - 1] == NULL) {
1890Sstevel@tonic-gate rval = -1; /* dt_errno is set for us */
1900Sstevel@tonic-gate goto err;
1910Sstevel@tonic-gate }
1920Sstevel@tonic-gate }
1930Sstevel@tonic-gate
1940Sstevel@tonic-gate dtp->dt_pdesc[id] = probe;
1950Sstevel@tonic-gate dtp->dt_edesc[id] = enabled;
1960Sstevel@tonic-gate
1970Sstevel@tonic-gate return (0);
1980Sstevel@tonic-gate
1990Sstevel@tonic-gate err:
2000Sstevel@tonic-gate /*
2010Sstevel@tonic-gate * If we failed, free our allocated probes. Note that if we failed
2020Sstevel@tonic-gate * while allocating formats, we aren't going to free formats that
2030Sstevel@tonic-gate * we have already allocated. This is okay; these formats are
2040Sstevel@tonic-gate * hanging off of dt_formats and will therefore not be leaked.
2050Sstevel@tonic-gate */
2060Sstevel@tonic-gate free(enabled);
2070Sstevel@tonic-gate free(probe);
2080Sstevel@tonic-gate return (rval);
2090Sstevel@tonic-gate }
2100Sstevel@tonic-gate
2110Sstevel@tonic-gate int
dt_epid_lookup(dtrace_hdl_t * dtp,dtrace_epid_t epid,dtrace_eprobedesc_t ** epdp,dtrace_probedesc_t ** pdp)2120Sstevel@tonic-gate dt_epid_lookup(dtrace_hdl_t *dtp, dtrace_epid_t epid,
2130Sstevel@tonic-gate dtrace_eprobedesc_t **epdp, dtrace_probedesc_t **pdp)
2140Sstevel@tonic-gate {
2150Sstevel@tonic-gate int rval;
2160Sstevel@tonic-gate
2170Sstevel@tonic-gate if (epid >= dtp->dt_maxprobe || dtp->dt_pdesc[epid] == NULL) {
2180Sstevel@tonic-gate if ((rval = dt_epid_add(dtp, epid)) != 0)
2190Sstevel@tonic-gate return (rval);
2200Sstevel@tonic-gate }
2210Sstevel@tonic-gate
2220Sstevel@tonic-gate assert(epid < dtp->dt_maxprobe);
2230Sstevel@tonic-gate assert(dtp->dt_edesc[epid] != NULL);
2240Sstevel@tonic-gate assert(dtp->dt_pdesc[epid] != NULL);
2250Sstevel@tonic-gate *epdp = dtp->dt_edesc[epid];
2260Sstevel@tonic-gate *pdp = dtp->dt_pdesc[epid];
2270Sstevel@tonic-gate
2280Sstevel@tonic-gate return (0);
2290Sstevel@tonic-gate }
2300Sstevel@tonic-gate
2310Sstevel@tonic-gate void
dt_epid_destroy(dtrace_hdl_t * dtp)2320Sstevel@tonic-gate dt_epid_destroy(dtrace_hdl_t *dtp)
2330Sstevel@tonic-gate {
2340Sstevel@tonic-gate size_t i;
2350Sstevel@tonic-gate
2360Sstevel@tonic-gate assert((dtp->dt_pdesc != NULL && dtp->dt_edesc != NULL &&
2370Sstevel@tonic-gate dtp->dt_maxprobe > 0) || (dtp->dt_pdesc == NULL &&
2380Sstevel@tonic-gate dtp->dt_edesc == NULL && dtp->dt_maxprobe == 0));
2390Sstevel@tonic-gate
2400Sstevel@tonic-gate if (dtp->dt_pdesc == NULL)
2410Sstevel@tonic-gate return;
2420Sstevel@tonic-gate
2430Sstevel@tonic-gate for (i = 0; i < dtp->dt_maxprobe; i++) {
2440Sstevel@tonic-gate if (dtp->dt_edesc[i] == NULL) {
2450Sstevel@tonic-gate assert(dtp->dt_pdesc[i] == NULL);
2460Sstevel@tonic-gate continue;
2470Sstevel@tonic-gate }
2480Sstevel@tonic-gate
2490Sstevel@tonic-gate assert(dtp->dt_pdesc[i] != NULL);
2500Sstevel@tonic-gate free(dtp->dt_edesc[i]);
2510Sstevel@tonic-gate free(dtp->dt_pdesc[i]);
2520Sstevel@tonic-gate }
2530Sstevel@tonic-gate
2540Sstevel@tonic-gate free(dtp->dt_pdesc);
2550Sstevel@tonic-gate dtp->dt_pdesc = NULL;
2560Sstevel@tonic-gate
2570Sstevel@tonic-gate free(dtp->dt_edesc);
2580Sstevel@tonic-gate dtp->dt_edesc = NULL;
2590Sstevel@tonic-gate dtp->dt_maxprobe = 0;
2600Sstevel@tonic-gate }
2610Sstevel@tonic-gate
2620Sstevel@tonic-gate void *
dt_format_lookup(dtrace_hdl_t * dtp,int format)2630Sstevel@tonic-gate dt_format_lookup(dtrace_hdl_t *dtp, int format)
2640Sstevel@tonic-gate {
2650Sstevel@tonic-gate if (format == 0 || format > dtp->dt_maxformat)
2660Sstevel@tonic-gate return (NULL);
2670Sstevel@tonic-gate
2680Sstevel@tonic-gate if (dtp->dt_formats == NULL)
2690Sstevel@tonic-gate return (NULL);
2700Sstevel@tonic-gate
2710Sstevel@tonic-gate return (dtp->dt_formats[format - 1]);
2720Sstevel@tonic-gate }
2730Sstevel@tonic-gate
2740Sstevel@tonic-gate void
dt_format_destroy(dtrace_hdl_t * dtp)2750Sstevel@tonic-gate dt_format_destroy(dtrace_hdl_t *dtp)
2760Sstevel@tonic-gate {
2770Sstevel@tonic-gate int i;
2780Sstevel@tonic-gate
2790Sstevel@tonic-gate for (i = 0; i < dtp->dt_maxformat; i++) {
2800Sstevel@tonic-gate if (dtp->dt_formats[i] != NULL)
2810Sstevel@tonic-gate dt_printf_destroy(dtp->dt_formats[i]);
2820Sstevel@tonic-gate }
2830Sstevel@tonic-gate
2840Sstevel@tonic-gate free(dtp->dt_formats);
2850Sstevel@tonic-gate dtp->dt_formats = NULL;
2860Sstevel@tonic-gate }
2870Sstevel@tonic-gate
2880Sstevel@tonic-gate static int
dt_aggid_add(dtrace_hdl_t * dtp,dtrace_aggid_t id)2890Sstevel@tonic-gate dt_aggid_add(dtrace_hdl_t *dtp, dtrace_aggid_t id)
2900Sstevel@tonic-gate {
2910Sstevel@tonic-gate dtrace_id_t max;
2920Sstevel@tonic-gate dtrace_epid_t epid;
2930Sstevel@tonic-gate int rval;
2940Sstevel@tonic-gate
2950Sstevel@tonic-gate while (id >= (max = dtp->dt_maxagg) || dtp->dt_aggdesc == NULL) {
2960Sstevel@tonic-gate dtrace_id_t new_max = max ? (max << 1) : 1;
2970Sstevel@tonic-gate size_t nsize = new_max * sizeof (void *);
2980Sstevel@tonic-gate dtrace_aggdesc_t **new_aggdesc;
2990Sstevel@tonic-gate
3000Sstevel@tonic-gate if ((new_aggdesc = malloc(nsize)) == NULL)
3010Sstevel@tonic-gate return (dt_set_errno(dtp, EDT_NOMEM));
3020Sstevel@tonic-gate
3030Sstevel@tonic-gate bzero(new_aggdesc, nsize);
3040Sstevel@tonic-gate
3050Sstevel@tonic-gate if (dtp->dt_aggdesc != NULL) {
3060Sstevel@tonic-gate bcopy(dtp->dt_aggdesc, new_aggdesc,
3070Sstevel@tonic-gate max * sizeof (void *));
3080Sstevel@tonic-gate free(dtp->dt_aggdesc);
3090Sstevel@tonic-gate }
3100Sstevel@tonic-gate
3110Sstevel@tonic-gate dtp->dt_aggdesc = new_aggdesc;
3120Sstevel@tonic-gate dtp->dt_maxagg = new_max;
3130Sstevel@tonic-gate }
3140Sstevel@tonic-gate
3150Sstevel@tonic-gate if (dtp->dt_aggdesc[id] == NULL) {
3160Sstevel@tonic-gate dtrace_aggdesc_t *agg, *nagg;
3170Sstevel@tonic-gate
3180Sstevel@tonic-gate if ((agg = malloc(sizeof (dtrace_aggdesc_t))) == NULL)
3190Sstevel@tonic-gate return (dt_set_errno(dtp, EDT_NOMEM));
3200Sstevel@tonic-gate
3210Sstevel@tonic-gate bzero(agg, sizeof (dtrace_aggdesc_t));
3220Sstevel@tonic-gate agg->dtagd_id = id;
3230Sstevel@tonic-gate agg->dtagd_nrecs = 1;
3240Sstevel@tonic-gate
3250Sstevel@tonic-gate if (dt_ioctl(dtp, DTRACEIOC_AGGDESC, agg) == -1) {
3260Sstevel@tonic-gate rval = dt_set_errno(dtp, errno);
3270Sstevel@tonic-gate free(agg);
3280Sstevel@tonic-gate return (rval);
3290Sstevel@tonic-gate }
3300Sstevel@tonic-gate
3310Sstevel@tonic-gate if (DTRACE_SIZEOF_AGGDESC(agg) != sizeof (*agg)) {
3320Sstevel@tonic-gate /*
3330Sstevel@tonic-gate * There must be more than one action. Allocate the
3340Sstevel@tonic-gate * appropriate amount of space and try again.
3350Sstevel@tonic-gate */
3360Sstevel@tonic-gate if ((nagg = malloc(DTRACE_SIZEOF_AGGDESC(agg))) != NULL)
3370Sstevel@tonic-gate bcopy(agg, nagg, sizeof (*agg));
3380Sstevel@tonic-gate
3390Sstevel@tonic-gate free(agg);
3400Sstevel@tonic-gate
3410Sstevel@tonic-gate if ((agg = nagg) == NULL)
3420Sstevel@tonic-gate return (dt_set_errno(dtp, EDT_NOMEM));
3430Sstevel@tonic-gate
3440Sstevel@tonic-gate rval = dt_ioctl(dtp, DTRACEIOC_AGGDESC, agg);
3450Sstevel@tonic-gate
3460Sstevel@tonic-gate if (rval == -1) {
3470Sstevel@tonic-gate rval = dt_set_errno(dtp, errno);
3480Sstevel@tonic-gate free(agg);
3490Sstevel@tonic-gate return (rval);
3500Sstevel@tonic-gate }
3510Sstevel@tonic-gate }
3520Sstevel@tonic-gate
3531017Sbmc /*
3541017Sbmc * If we have a uarg, it's a pointer to the compiler-generated
3551017Sbmc * statement; we'll use this value to get the name and
3561017Sbmc * compiler-generated variable ID for the aggregation. If
3571017Sbmc * we're grabbing an anonymous enabling, this pointer value
3581017Sbmc * is obviously meaningless -- and in this case, we can't
3591017Sbmc * provide the compiler-generated aggregation information.
3601017Sbmc */
361*3276Sjhaslam if (dtp->dt_options[DTRACEOPT_GRABANON] == DTRACEOPT_UNSET &&
362*3276Sjhaslam agg->dtagd_rec[0].dtrd_uarg != NULL) {
3630Sstevel@tonic-gate dtrace_stmtdesc_t *sdp;
3640Sstevel@tonic-gate dt_ident_t *aid;
3650Sstevel@tonic-gate
366191Sahl sdp = (dtrace_stmtdesc_t *)(uintptr_t)
367191Sahl agg->dtagd_rec[0].dtrd_uarg;
3680Sstevel@tonic-gate aid = sdp->dtsd_aggdata;
3690Sstevel@tonic-gate agg->dtagd_name = aid->di_name;
3701017Sbmc agg->dtagd_varid = aid->di_id;
3711017Sbmc } else {
3721017Sbmc agg->dtagd_varid = DTRACE_AGGVARIDNONE;
3730Sstevel@tonic-gate }
3740Sstevel@tonic-gate
3750Sstevel@tonic-gate if ((epid = agg->dtagd_epid) >= dtp->dt_maxprobe ||
3760Sstevel@tonic-gate dtp->dt_pdesc[epid] == NULL) {
3770Sstevel@tonic-gate if ((rval = dt_epid_add(dtp, epid)) != 0) {
3780Sstevel@tonic-gate free(agg);
3790Sstevel@tonic-gate return (rval);
3800Sstevel@tonic-gate }
3810Sstevel@tonic-gate }
3820Sstevel@tonic-gate
3830Sstevel@tonic-gate dtp->dt_aggdesc[id] = agg;
3840Sstevel@tonic-gate }
3850Sstevel@tonic-gate
3860Sstevel@tonic-gate return (0);
3870Sstevel@tonic-gate }
3880Sstevel@tonic-gate
3890Sstevel@tonic-gate int
dt_aggid_lookup(dtrace_hdl_t * dtp,dtrace_aggid_t aggid,dtrace_aggdesc_t ** adp)3900Sstevel@tonic-gate dt_aggid_lookup(dtrace_hdl_t *dtp, dtrace_aggid_t aggid,
3910Sstevel@tonic-gate dtrace_aggdesc_t **adp)
3920Sstevel@tonic-gate {
3930Sstevel@tonic-gate int rval;
3940Sstevel@tonic-gate
3950Sstevel@tonic-gate if (aggid >= dtp->dt_maxagg || dtp->dt_aggdesc[aggid] == NULL) {
3960Sstevel@tonic-gate if ((rval = dt_aggid_add(dtp, aggid)) != 0)
3970Sstevel@tonic-gate return (rval);
3980Sstevel@tonic-gate }
3990Sstevel@tonic-gate
4000Sstevel@tonic-gate assert(aggid < dtp->dt_maxagg);
4010Sstevel@tonic-gate assert(dtp->dt_aggdesc[aggid] != NULL);
4020Sstevel@tonic-gate *adp = dtp->dt_aggdesc[aggid];
4030Sstevel@tonic-gate
4040Sstevel@tonic-gate return (0);
4050Sstevel@tonic-gate }
4060Sstevel@tonic-gate
4070Sstevel@tonic-gate void
dt_aggid_destroy(dtrace_hdl_t * dtp)4080Sstevel@tonic-gate dt_aggid_destroy(dtrace_hdl_t *dtp)
4090Sstevel@tonic-gate {
4100Sstevel@tonic-gate size_t i;
4110Sstevel@tonic-gate
4120Sstevel@tonic-gate assert((dtp->dt_aggdesc != NULL && dtp->dt_maxagg != 0) ||
4130Sstevel@tonic-gate (dtp->dt_aggdesc == NULL && dtp->dt_maxagg == 0));
4140Sstevel@tonic-gate
4150Sstevel@tonic-gate if (dtp->dt_aggdesc == NULL)
4160Sstevel@tonic-gate return;
4170Sstevel@tonic-gate
4180Sstevel@tonic-gate for (i = 0; i < dtp->dt_maxagg; i++) {
4190Sstevel@tonic-gate if (dtp->dt_aggdesc[i] != NULL)
4200Sstevel@tonic-gate free(dtp->dt_aggdesc[i]);
4210Sstevel@tonic-gate }
4220Sstevel@tonic-gate
4230Sstevel@tonic-gate free(dtp->dt_aggdesc);
4240Sstevel@tonic-gate dtp->dt_aggdesc = NULL;
4250Sstevel@tonic-gate dtp->dt_maxagg = 0;
4260Sstevel@tonic-gate }
427