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 50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 70Sstevel@tonic-gate * with the License. 80Sstevel@tonic-gate * 90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 110Sstevel@tonic-gate * See the License for the specific language governing permissions 120Sstevel@tonic-gate * and limitations under the License. 130Sstevel@tonic-gate * 140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 190Sstevel@tonic-gate * 200Sstevel@tonic-gate * CDDL HEADER END 210Sstevel@tonic-gate */ 220Sstevel@tonic-gate /* 23*1239Sahl * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 280Sstevel@tonic-gate 290Sstevel@tonic-gate #include <sys/types.h> 300Sstevel@tonic-gate #include <sys/sysmacros.h> 310Sstevel@tonic-gate 320Sstevel@tonic-gate #include <assert.h> 330Sstevel@tonic-gate #include <limits.h> 340Sstevel@tonic-gate #include <strings.h> 350Sstevel@tonic-gate #include <stdlib.h> 360Sstevel@tonic-gate #include <alloca.h> 370Sstevel@tonic-gate #include <unistd.h> 380Sstevel@tonic-gate #include <errno.h> 390Sstevel@tonic-gate 400Sstevel@tonic-gate #include <dt_provider.h> 410Sstevel@tonic-gate #include <dt_module.h> 420Sstevel@tonic-gate #include <dt_string.h> 430Sstevel@tonic-gate #include <dt_list.h> 440Sstevel@tonic-gate 450Sstevel@tonic-gate static dt_provider_t * 460Sstevel@tonic-gate dt_provider_insert(dtrace_hdl_t *dtp, dt_provider_t *pvp, uint_t h) 470Sstevel@tonic-gate { 480Sstevel@tonic-gate dt_list_append(&dtp->dt_provlist, pvp); 490Sstevel@tonic-gate 500Sstevel@tonic-gate pvp->pv_next = dtp->dt_provs[h]; 510Sstevel@tonic-gate dtp->dt_provs[h] = pvp; 520Sstevel@tonic-gate dtp->dt_nprovs++; 530Sstevel@tonic-gate 540Sstevel@tonic-gate return (pvp); 550Sstevel@tonic-gate } 560Sstevel@tonic-gate 570Sstevel@tonic-gate dt_provider_t * 580Sstevel@tonic-gate dt_provider_lookup(dtrace_hdl_t *dtp, const char *name) 590Sstevel@tonic-gate { 600Sstevel@tonic-gate uint_t h = dt_strtab_hash(name, NULL) % dtp->dt_provbuckets; 61265Smws dtrace_providerdesc_t desc; 620Sstevel@tonic-gate dt_provider_t *pvp; 630Sstevel@tonic-gate 640Sstevel@tonic-gate for (pvp = dtp->dt_provs[h]; pvp != NULL; pvp = pvp->pv_next) { 650Sstevel@tonic-gate if (strcmp(pvp->pv_desc.dtvd_name, name) == 0) 660Sstevel@tonic-gate return (pvp); 670Sstevel@tonic-gate } 680Sstevel@tonic-gate 690Sstevel@tonic-gate if (strisglob(name) || name[0] == '\0') { 700Sstevel@tonic-gate (void) dt_set_errno(dtp, EDT_NOPROV); 710Sstevel@tonic-gate return (NULL); 720Sstevel@tonic-gate } 730Sstevel@tonic-gate 74265Smws bzero(&desc, sizeof (desc)); 75265Smws (void) strlcpy(desc.dtvd_name, name, DTRACE_PROVNAMELEN); 76265Smws 77265Smws if (dt_ioctl(dtp, DTRACEIOC_PROVIDER, &desc) == -1) { 78265Smws (void) dt_set_errno(dtp, errno == ESRCH ? EDT_NOPROV : errno); 79265Smws return (NULL); 80265Smws } 81265Smws 820Sstevel@tonic-gate if ((pvp = dt_provider_create(dtp, name)) == NULL) 830Sstevel@tonic-gate return (NULL); /* dt_errno is set for us */ 840Sstevel@tonic-gate 85265Smws bcopy(&desc, &pvp->pv_desc, sizeof (desc)); 860Sstevel@tonic-gate pvp->pv_flags |= DT_PROVIDER_IMPL; 870Sstevel@tonic-gate return (pvp); 880Sstevel@tonic-gate } 890Sstevel@tonic-gate 900Sstevel@tonic-gate dt_provider_t * 910Sstevel@tonic-gate dt_provider_create(dtrace_hdl_t *dtp, const char *name) 920Sstevel@tonic-gate { 930Sstevel@tonic-gate dt_provider_t *pvp; 940Sstevel@tonic-gate 950Sstevel@tonic-gate if ((pvp = dt_zalloc(dtp, sizeof (dt_provider_t))) == NULL) 960Sstevel@tonic-gate return (NULL); 970Sstevel@tonic-gate 980Sstevel@tonic-gate (void) strlcpy(pvp->pv_desc.dtvd_name, name, DTRACE_PROVNAMELEN); 990Sstevel@tonic-gate pvp->pv_probes = dt_idhash_create(pvp->pv_desc.dtvd_name, NULL, 0, 0); 1000Sstevel@tonic-gate pvp->pv_gen = dtp->dt_gen; 1010Sstevel@tonic-gate pvp->pv_hdl = dtp; 1020Sstevel@tonic-gate 1030Sstevel@tonic-gate if (pvp->pv_probes == NULL) { 1040Sstevel@tonic-gate dt_free(dtp, pvp); 1050Sstevel@tonic-gate (void) dt_set_errno(dtp, EDT_NOMEM); 1060Sstevel@tonic-gate return (NULL); 1070Sstevel@tonic-gate } 1080Sstevel@tonic-gate 1090Sstevel@tonic-gate pvp->pv_desc.dtvd_attr.dtpa_provider = _dtrace_prvattr; 1100Sstevel@tonic-gate pvp->pv_desc.dtvd_attr.dtpa_mod = _dtrace_prvattr; 1110Sstevel@tonic-gate pvp->pv_desc.dtvd_attr.dtpa_func = _dtrace_prvattr; 1120Sstevel@tonic-gate pvp->pv_desc.dtvd_attr.dtpa_name = _dtrace_prvattr; 1130Sstevel@tonic-gate pvp->pv_desc.dtvd_attr.dtpa_args = _dtrace_prvattr; 1140Sstevel@tonic-gate 1150Sstevel@tonic-gate return (dt_provider_insert(dtp, pvp, 1160Sstevel@tonic-gate dt_strtab_hash(name, NULL) % dtp->dt_provbuckets)); 1170Sstevel@tonic-gate } 1180Sstevel@tonic-gate 1190Sstevel@tonic-gate void 1200Sstevel@tonic-gate dt_provider_destroy(dtrace_hdl_t *dtp, dt_provider_t *pvp) 1210Sstevel@tonic-gate { 1220Sstevel@tonic-gate dt_provider_t **pp; 1230Sstevel@tonic-gate uint_t h; 1240Sstevel@tonic-gate 1250Sstevel@tonic-gate assert(pvp->pv_hdl == dtp); 1260Sstevel@tonic-gate 1270Sstevel@tonic-gate h = dt_strtab_hash(pvp->pv_desc.dtvd_name, NULL) % dtp->dt_provbuckets; 1280Sstevel@tonic-gate pp = &dtp->dt_provs[h]; 1290Sstevel@tonic-gate 1300Sstevel@tonic-gate while (*pp != NULL && *pp != pvp) 1310Sstevel@tonic-gate pp = &(*pp)->pv_next; 1320Sstevel@tonic-gate 1330Sstevel@tonic-gate assert(*pp != NULL && *pp == pvp); 1340Sstevel@tonic-gate *pp = pvp->pv_next; 1350Sstevel@tonic-gate 1360Sstevel@tonic-gate dt_list_delete(&dtp->dt_provlist, pvp); 1370Sstevel@tonic-gate dtp->dt_nprovs--; 1380Sstevel@tonic-gate 1390Sstevel@tonic-gate if (pvp->pv_probes != NULL) 1400Sstevel@tonic-gate dt_idhash_destroy(pvp->pv_probes); 1410Sstevel@tonic-gate 1420Sstevel@tonic-gate dt_node_link_free(&pvp->pv_nodes); 143265Smws dt_free(dtp, pvp->pv_xrefs); 1440Sstevel@tonic-gate dt_free(dtp, pvp); 1450Sstevel@tonic-gate } 1460Sstevel@tonic-gate 147265Smws int 148265Smws dt_provider_xref(dtrace_hdl_t *dtp, dt_provider_t *pvp, id_t id) 149265Smws { 150265Smws size_t oldsize = BT_SIZEOFMAP(pvp->pv_xrmax); 151265Smws size_t newsize = BT_SIZEOFMAP(dtp->dt_xlatorid); 152265Smws 153265Smws assert(id >= 0 && id < dtp->dt_xlatorid); 154265Smws 155265Smws if (newsize > oldsize) { 156265Smws ulong_t *xrefs = dt_zalloc(dtp, newsize); 157265Smws 158265Smws if (xrefs == NULL) 159265Smws return (-1); 160265Smws 161265Smws bcopy(pvp->pv_xrefs, xrefs, oldsize); 162265Smws dt_free(dtp, pvp->pv_xrefs); 163265Smws 164265Smws pvp->pv_xrefs = xrefs; 165265Smws pvp->pv_xrmax = dtp->dt_xlatorid; 166265Smws } 167265Smws 168265Smws BT_SET(pvp->pv_xrefs, id); 169265Smws return (0); 170265Smws } 171265Smws 1720Sstevel@tonic-gate static uint8_t 1730Sstevel@tonic-gate dt_probe_argmap(dt_node_t *xnp, dt_node_t *nnp) 1740Sstevel@tonic-gate { 1750Sstevel@tonic-gate uint8_t i; 1760Sstevel@tonic-gate 1770Sstevel@tonic-gate for (i = 0; nnp != NULL; i++) { 1780Sstevel@tonic-gate if (nnp->dn_string != NULL && 1790Sstevel@tonic-gate strcmp(nnp->dn_string, xnp->dn_string) == 0) 1800Sstevel@tonic-gate break; 1810Sstevel@tonic-gate else 1820Sstevel@tonic-gate nnp = nnp->dn_list; 1830Sstevel@tonic-gate } 1840Sstevel@tonic-gate 1850Sstevel@tonic-gate return (i); 1860Sstevel@tonic-gate } 1870Sstevel@tonic-gate 1880Sstevel@tonic-gate static dt_node_t * 1890Sstevel@tonic-gate dt_probe_alloc_args(dt_provider_t *pvp, int argc) 1900Sstevel@tonic-gate { 1910Sstevel@tonic-gate dt_node_t *args = NULL, *pnp = NULL, *dnp; 1920Sstevel@tonic-gate int i; 1930Sstevel@tonic-gate 1940Sstevel@tonic-gate for (i = 0; i < argc; i++, pnp = dnp) { 1950Sstevel@tonic-gate if ((dnp = dt_node_xalloc(pvp->pv_hdl, DT_NODE_TYPE)) == NULL) 1960Sstevel@tonic-gate return (NULL); 1970Sstevel@tonic-gate 1980Sstevel@tonic-gate dnp->dn_link = pvp->pv_nodes; 1990Sstevel@tonic-gate pvp->pv_nodes = dnp; 2000Sstevel@tonic-gate 2010Sstevel@tonic-gate if (args == NULL) 2020Sstevel@tonic-gate args = dnp; 2030Sstevel@tonic-gate else 2040Sstevel@tonic-gate pnp->dn_list = dnp; 2050Sstevel@tonic-gate } 2060Sstevel@tonic-gate 2070Sstevel@tonic-gate return (args); 2080Sstevel@tonic-gate } 2090Sstevel@tonic-gate 2100Sstevel@tonic-gate static size_t 2110Sstevel@tonic-gate dt_probe_keylen(const dtrace_probedesc_t *pdp) 2120Sstevel@tonic-gate { 2130Sstevel@tonic-gate return (strlen(pdp->dtpd_mod) + 1 + 2140Sstevel@tonic-gate strlen(pdp->dtpd_func) + 1 + strlen(pdp->dtpd_name) + 1); 2150Sstevel@tonic-gate } 2160Sstevel@tonic-gate 2170Sstevel@tonic-gate static char * 2180Sstevel@tonic-gate dt_probe_key(const dtrace_probedesc_t *pdp, char *s) 2190Sstevel@tonic-gate { 2200Sstevel@tonic-gate (void) snprintf(s, INT_MAX, "%s:%s:%s", 2210Sstevel@tonic-gate pdp->dtpd_mod, pdp->dtpd_func, pdp->dtpd_name); 2220Sstevel@tonic-gate return (s); 2230Sstevel@tonic-gate } 2240Sstevel@tonic-gate 2250Sstevel@tonic-gate /* 2260Sstevel@tonic-gate * If a probe was discovered from the kernel, ask dtrace(7D) for a description 2270Sstevel@tonic-gate * of each of its arguments, including native and translated types. 2280Sstevel@tonic-gate */ 2290Sstevel@tonic-gate static dt_probe_t * 2300Sstevel@tonic-gate dt_probe_discover(dt_provider_t *pvp, const dtrace_probedesc_t *pdp) 2310Sstevel@tonic-gate { 2320Sstevel@tonic-gate dtrace_hdl_t *dtp = pvp->pv_hdl; 2330Sstevel@tonic-gate char *name = dt_probe_key(pdp, alloca(dt_probe_keylen(pdp))); 2340Sstevel@tonic-gate 2350Sstevel@tonic-gate dt_node_t *xargs, *nargs; 2360Sstevel@tonic-gate dt_ident_t *idp; 2370Sstevel@tonic-gate dt_probe_t *prp; 2380Sstevel@tonic-gate 2390Sstevel@tonic-gate dtrace_typeinfo_t dtt; 2400Sstevel@tonic-gate int i, nc, xc; 2410Sstevel@tonic-gate 2420Sstevel@tonic-gate int adc = _dtrace_argmax; 2430Sstevel@tonic-gate dtrace_argdesc_t *adv = alloca(sizeof (dtrace_argdesc_t) * adc); 2440Sstevel@tonic-gate dtrace_argdesc_t *adp = adv; 2450Sstevel@tonic-gate 2460Sstevel@tonic-gate assert(strcmp(pvp->pv_desc.dtvd_name, pdp->dtpd_provider) == 0); 2470Sstevel@tonic-gate assert(pdp->dtpd_id != DTRACE_IDNONE); 2480Sstevel@tonic-gate 2490Sstevel@tonic-gate dt_dprintf("discovering probe %s:%s id=%d\n", 2500Sstevel@tonic-gate pvp->pv_desc.dtvd_name, name, pdp->dtpd_id); 2510Sstevel@tonic-gate 2520Sstevel@tonic-gate for (nc = -1, i = 0; i < adc; i++, adp++) { 2530Sstevel@tonic-gate bzero(adp, sizeof (dtrace_argdesc_t)); 2540Sstevel@tonic-gate adp->dtargd_ndx = i; 2550Sstevel@tonic-gate adp->dtargd_id = pdp->dtpd_id; 2560Sstevel@tonic-gate 2570Sstevel@tonic-gate if (dt_ioctl(dtp, DTRACEIOC_PROBEARG, adp) != 0) { 2580Sstevel@tonic-gate (void) dt_set_errno(dtp, errno); 2590Sstevel@tonic-gate return (NULL); 2600Sstevel@tonic-gate } 2610Sstevel@tonic-gate 2620Sstevel@tonic-gate if (adp->dtargd_ndx == DTRACE_ARGNONE) 2630Sstevel@tonic-gate break; /* all argument descs have been retrieved */ 2640Sstevel@tonic-gate 2650Sstevel@tonic-gate nc = MAX(nc, adp->dtargd_mapping); 2660Sstevel@tonic-gate } 2670Sstevel@tonic-gate 2680Sstevel@tonic-gate xc = i; 2690Sstevel@tonic-gate nc++; 2700Sstevel@tonic-gate 2710Sstevel@tonic-gate /* 2720Sstevel@tonic-gate * Now that we have discovered the number of native and translated 2730Sstevel@tonic-gate * arguments from the argument descriptions, allocate a new probe ident 2740Sstevel@tonic-gate * and corresponding dt_probe_t and hash it into the provider. 2750Sstevel@tonic-gate */ 2760Sstevel@tonic-gate xargs = dt_probe_alloc_args(pvp, xc); 2770Sstevel@tonic-gate nargs = dt_probe_alloc_args(pvp, nc); 2780Sstevel@tonic-gate 2790Sstevel@tonic-gate if ((xc != 0 && xargs == NULL) || (nc != 0 && nargs == NULL)) 2800Sstevel@tonic-gate return (NULL); /* dt_errno is set for us */ 2810Sstevel@tonic-gate 2820Sstevel@tonic-gate idp = dt_ident_create(name, DT_IDENT_PROBE, 2830Sstevel@tonic-gate DT_IDFLG_ORPHAN, pdp->dtpd_id, _dtrace_defattr, 0, 2840Sstevel@tonic-gate &dt_idops_probe, NULL, dtp->dt_gen); 2850Sstevel@tonic-gate 2860Sstevel@tonic-gate if (idp == NULL) { 2870Sstevel@tonic-gate (void) dt_set_errno(dtp, EDT_NOMEM); 2880Sstevel@tonic-gate return (NULL); 2890Sstevel@tonic-gate } 2900Sstevel@tonic-gate 291265Smws if ((prp = dt_probe_create(dtp, idp, 2, 292265Smws nargs, nc, xargs, xc)) == NULL) { 2930Sstevel@tonic-gate dt_ident_destroy(idp); 2940Sstevel@tonic-gate return (NULL); 2950Sstevel@tonic-gate } 2960Sstevel@tonic-gate 2970Sstevel@tonic-gate dt_probe_declare(pvp, prp); 2980Sstevel@tonic-gate 2990Sstevel@tonic-gate /* 3000Sstevel@tonic-gate * Once our new dt_probe_t is fully constructed, iterate over the 3010Sstevel@tonic-gate * cached argument descriptions and assign types to prp->pr_nargv[] 3020Sstevel@tonic-gate * and prp->pr_xargv[] and assign mappings to prp->pr_mapping[]. 3030Sstevel@tonic-gate */ 3040Sstevel@tonic-gate for (adp = adv, i = 0; i < xc; i++, adp++) { 3050Sstevel@tonic-gate if (dtrace_type_strcompile(dtp, 3060Sstevel@tonic-gate adp->dtargd_native, &dtt) != 0) { 3070Sstevel@tonic-gate dt_dprintf("failed to resolve input type %s " 3080Sstevel@tonic-gate "for %s:%s arg #%d: %s\n", adp->dtargd_native, 3090Sstevel@tonic-gate pvp->pv_desc.dtvd_name, name, i + 1, 3100Sstevel@tonic-gate dtrace_errmsg(dtp, dtrace_errno(dtp))); 3110Sstevel@tonic-gate 3120Sstevel@tonic-gate dtt.dtt_object = NULL; 3130Sstevel@tonic-gate dtt.dtt_ctfp = NULL; 3140Sstevel@tonic-gate dtt.dtt_type = CTF_ERR; 3150Sstevel@tonic-gate } else { 3160Sstevel@tonic-gate dt_node_type_assign(prp->pr_nargv[adp->dtargd_mapping], 3170Sstevel@tonic-gate dtt.dtt_ctfp, dtt.dtt_type); 3180Sstevel@tonic-gate } 3190Sstevel@tonic-gate 3200Sstevel@tonic-gate if (dtt.dtt_type != CTF_ERR && (adp->dtargd_xlate[0] == '\0' || 3210Sstevel@tonic-gate strcmp(adp->dtargd_native, adp->dtargd_xlate) == 0)) { 3220Sstevel@tonic-gate dt_node_type_propagate(prp->pr_nargv[ 3230Sstevel@tonic-gate adp->dtargd_mapping], prp->pr_xargv[i]); 3240Sstevel@tonic-gate } else if (dtrace_type_strcompile(dtp, 3250Sstevel@tonic-gate adp->dtargd_xlate, &dtt) != 0) { 3260Sstevel@tonic-gate dt_dprintf("failed to resolve output type %s " 3270Sstevel@tonic-gate "for %s:%s arg #%d: %s\n", adp->dtargd_xlate, 3280Sstevel@tonic-gate pvp->pv_desc.dtvd_name, name, i + 1, 3290Sstevel@tonic-gate dtrace_errmsg(dtp, dtrace_errno(dtp))); 3300Sstevel@tonic-gate 3310Sstevel@tonic-gate dtt.dtt_object = NULL; 3320Sstevel@tonic-gate dtt.dtt_ctfp = NULL; 3330Sstevel@tonic-gate dtt.dtt_type = CTF_ERR; 3340Sstevel@tonic-gate } else { 3350Sstevel@tonic-gate dt_node_type_assign(prp->pr_xargv[i], 3360Sstevel@tonic-gate dtt.dtt_ctfp, dtt.dtt_type); 3370Sstevel@tonic-gate } 3380Sstevel@tonic-gate 3390Sstevel@tonic-gate prp->pr_mapping[i] = adp->dtargd_mapping; 3400Sstevel@tonic-gate prp->pr_argv[i] = dtt; 3410Sstevel@tonic-gate } 3420Sstevel@tonic-gate 3430Sstevel@tonic-gate return (prp); 3440Sstevel@tonic-gate } 3450Sstevel@tonic-gate 3460Sstevel@tonic-gate /* 3470Sstevel@tonic-gate * Lookup a probe declaration based on a known provider and full or partially 3480Sstevel@tonic-gate * specified module, function, and name. If the probe is not known to us yet, 3490Sstevel@tonic-gate * ask dtrace(7D) to match the description and then cache any useful results. 3500Sstevel@tonic-gate */ 3510Sstevel@tonic-gate dt_probe_t * 3520Sstevel@tonic-gate dt_probe_lookup(dt_provider_t *pvp, const char *s) 3530Sstevel@tonic-gate { 3540Sstevel@tonic-gate dtrace_hdl_t *dtp = pvp->pv_hdl; 3550Sstevel@tonic-gate dtrace_probedesc_t pd; 3560Sstevel@tonic-gate dt_ident_t *idp; 3570Sstevel@tonic-gate size_t keylen; 3580Sstevel@tonic-gate char *key; 3590Sstevel@tonic-gate 3600Sstevel@tonic-gate if (dtrace_str2desc(dtp, DTRACE_PROBESPEC_NAME, s, &pd) != 0) 3610Sstevel@tonic-gate return (NULL); /* dt_errno is set for us */ 3620Sstevel@tonic-gate 3630Sstevel@tonic-gate keylen = dt_probe_keylen(&pd); 3640Sstevel@tonic-gate key = dt_probe_key(&pd, alloca(keylen)); 3650Sstevel@tonic-gate 3660Sstevel@tonic-gate /* 3670Sstevel@tonic-gate * If the probe is already declared, then return the dt_probe_t from 3680Sstevel@tonic-gate * the existing identifier. This could come from a static declaration 3690Sstevel@tonic-gate * or it could have been cached from an earlier call to this function. 3700Sstevel@tonic-gate */ 3710Sstevel@tonic-gate if ((idp = dt_idhash_lookup(pvp->pv_probes, key)) != NULL) 3720Sstevel@tonic-gate return (idp->di_data); 3730Sstevel@tonic-gate 3740Sstevel@tonic-gate /* 3750Sstevel@tonic-gate * If the probe isn't known, use the probe description computed above 3760Sstevel@tonic-gate * to ask dtrace(7D) to find the first matching probe. 3770Sstevel@tonic-gate */ 3780Sstevel@tonic-gate if (dt_ioctl(dtp, DTRACEIOC_PROBEMATCH, &pd) == 0) 3790Sstevel@tonic-gate return (dt_probe_discover(pvp, &pd)); 3800Sstevel@tonic-gate 3810Sstevel@tonic-gate if (errno == ESRCH || errno == EBADF) 3820Sstevel@tonic-gate (void) dt_set_errno(dtp, EDT_NOPROBE); 3830Sstevel@tonic-gate else 3840Sstevel@tonic-gate (void) dt_set_errno(dtp, errno); 3850Sstevel@tonic-gate 3860Sstevel@tonic-gate return (NULL); 3870Sstevel@tonic-gate } 3880Sstevel@tonic-gate 3890Sstevel@tonic-gate dt_probe_t * 390265Smws dt_probe_create(dtrace_hdl_t *dtp, dt_ident_t *idp, int protoc, 3910Sstevel@tonic-gate dt_node_t *nargs, uint_t nargc, dt_node_t *xargs, uint_t xargc) 3920Sstevel@tonic-gate { 3930Sstevel@tonic-gate dt_module_t *dmp; 3940Sstevel@tonic-gate dt_probe_t *prp; 3950Sstevel@tonic-gate const char *p; 3960Sstevel@tonic-gate uint_t i; 3970Sstevel@tonic-gate 3980Sstevel@tonic-gate assert(idp->di_kind == DT_IDENT_PROBE); 3990Sstevel@tonic-gate assert(idp->di_data == NULL); 4000Sstevel@tonic-gate 401265Smws /* 402265Smws * If only a single prototype is given, set xargc/s to nargc/s to 403265Smws * simplify subsequent use. Note that we can have one or both of nargs 404265Smws * and xargs be specified but set to NULL, indicating a void prototype. 405265Smws */ 406265Smws if (protoc < 2) { 407265Smws assert(xargs == NULL); 408265Smws assert(xargc == 0); 4090Sstevel@tonic-gate xargs = nargs; 4100Sstevel@tonic-gate xargc = nargc; 4110Sstevel@tonic-gate } 4120Sstevel@tonic-gate 4130Sstevel@tonic-gate if ((prp = dt_alloc(dtp, sizeof (dt_probe_t))) == NULL) 4140Sstevel@tonic-gate return (NULL); 4150Sstevel@tonic-gate 4160Sstevel@tonic-gate prp->pr_pvp = NULL; 4170Sstevel@tonic-gate prp->pr_ident = idp; 4180Sstevel@tonic-gate 4190Sstevel@tonic-gate p = strrchr(idp->di_name, ':'); 4200Sstevel@tonic-gate assert(p != NULL); 4210Sstevel@tonic-gate prp->pr_name = p + 1; 4220Sstevel@tonic-gate 4230Sstevel@tonic-gate prp->pr_nargs = nargs; 4240Sstevel@tonic-gate prp->pr_nargv = dt_alloc(dtp, sizeof (dt_node_t *) * nargc); 4250Sstevel@tonic-gate prp->pr_nargc = nargc; 4260Sstevel@tonic-gate prp->pr_xargs = xargs; 4270Sstevel@tonic-gate prp->pr_xargv = dt_alloc(dtp, sizeof (dt_node_t *) * xargc); 4280Sstevel@tonic-gate prp->pr_xargc = xargc; 4290Sstevel@tonic-gate prp->pr_mapping = dt_alloc(dtp, sizeof (uint8_t) * xargc); 4300Sstevel@tonic-gate prp->pr_inst = NULL; 4310Sstevel@tonic-gate prp->pr_argv = dt_alloc(dtp, sizeof (dtrace_typeinfo_t) * xargc); 4320Sstevel@tonic-gate prp->pr_argc = xargc; 4330Sstevel@tonic-gate 4340Sstevel@tonic-gate if ((prp->pr_nargc != 0 && prp->pr_nargv == NULL) || 4350Sstevel@tonic-gate (prp->pr_xargc != 0 && prp->pr_xargv == NULL) || 4360Sstevel@tonic-gate (prp->pr_xargc != 0 && prp->pr_mapping == NULL) || 4370Sstevel@tonic-gate (prp->pr_argc != 0 && prp->pr_argv == NULL)) { 4380Sstevel@tonic-gate dt_probe_destroy(prp); 4390Sstevel@tonic-gate return (NULL); 4400Sstevel@tonic-gate } 4410Sstevel@tonic-gate 4420Sstevel@tonic-gate for (i = 0; i < xargc; i++, xargs = xargs->dn_list) { 4430Sstevel@tonic-gate if (xargs->dn_string != NULL) 4440Sstevel@tonic-gate prp->pr_mapping[i] = dt_probe_argmap(xargs, nargs); 4450Sstevel@tonic-gate else 4460Sstevel@tonic-gate prp->pr_mapping[i] = i; 4470Sstevel@tonic-gate 4480Sstevel@tonic-gate prp->pr_xargv[i] = xargs; 4490Sstevel@tonic-gate 4500Sstevel@tonic-gate if ((dmp = dt_module_lookup_by_ctf(dtp, 4510Sstevel@tonic-gate xargs->dn_ctfp)) != NULL) 4520Sstevel@tonic-gate prp->pr_argv[i].dtt_object = dmp->dm_name; 4530Sstevel@tonic-gate else 4540Sstevel@tonic-gate prp->pr_argv[i].dtt_object = NULL; 4550Sstevel@tonic-gate 4560Sstevel@tonic-gate prp->pr_argv[i].dtt_ctfp = xargs->dn_ctfp; 4570Sstevel@tonic-gate prp->pr_argv[i].dtt_type = xargs->dn_type; 4580Sstevel@tonic-gate } 4590Sstevel@tonic-gate 4600Sstevel@tonic-gate for (i = 0; i < nargc; i++, nargs = nargs->dn_list) 4610Sstevel@tonic-gate prp->pr_nargv[i] = nargs; 4620Sstevel@tonic-gate 4630Sstevel@tonic-gate idp->di_data = prp; 4640Sstevel@tonic-gate return (prp); 4650Sstevel@tonic-gate } 4660Sstevel@tonic-gate 4670Sstevel@tonic-gate void 4680Sstevel@tonic-gate dt_probe_declare(dt_provider_t *pvp, dt_probe_t *prp) 4690Sstevel@tonic-gate { 4700Sstevel@tonic-gate assert(prp->pr_ident->di_kind == DT_IDENT_PROBE); 4710Sstevel@tonic-gate assert(prp->pr_ident->di_data == prp); 4720Sstevel@tonic-gate assert(prp->pr_pvp == NULL); 4730Sstevel@tonic-gate 4740Sstevel@tonic-gate if (prp->pr_xargs != prp->pr_nargs) 4750Sstevel@tonic-gate pvp->pv_flags &= ~DT_PROVIDER_INTF; 4760Sstevel@tonic-gate 4770Sstevel@tonic-gate prp->pr_pvp = pvp; 4780Sstevel@tonic-gate dt_idhash_xinsert(pvp->pv_probes, prp->pr_ident); 4790Sstevel@tonic-gate } 4800Sstevel@tonic-gate 4810Sstevel@tonic-gate void 4820Sstevel@tonic-gate dt_probe_destroy(dt_probe_t *prp) 4830Sstevel@tonic-gate { 4840Sstevel@tonic-gate dt_probe_instance_t *pip, *pip_next; 4850Sstevel@tonic-gate dtrace_hdl_t *dtp; 4860Sstevel@tonic-gate 4870Sstevel@tonic-gate if (prp->pr_pvp != NULL) 4880Sstevel@tonic-gate dtp = prp->pr_pvp->pv_hdl; 4890Sstevel@tonic-gate else 4900Sstevel@tonic-gate dtp = yypcb->pcb_hdl; 4910Sstevel@tonic-gate 4920Sstevel@tonic-gate dt_node_list_free(&prp->pr_nargs); 4930Sstevel@tonic-gate dt_node_list_free(&prp->pr_xargs); 4940Sstevel@tonic-gate 4950Sstevel@tonic-gate dt_free(dtp, prp->pr_nargv); 4960Sstevel@tonic-gate dt_free(dtp, prp->pr_xargv); 4970Sstevel@tonic-gate 4980Sstevel@tonic-gate for (pip = prp->pr_inst; pip != NULL; pip = pip_next) { 4990Sstevel@tonic-gate pip_next = pip->pi_next; 5000Sstevel@tonic-gate dt_free(dtp, pip->pi_offs); 5010Sstevel@tonic-gate dt_free(dtp, pip); 5020Sstevel@tonic-gate } 5030Sstevel@tonic-gate 5040Sstevel@tonic-gate dt_free(dtp, prp->pr_mapping); 5050Sstevel@tonic-gate dt_free(dtp, prp->pr_argv); 5060Sstevel@tonic-gate dt_free(dtp, prp); 5070Sstevel@tonic-gate } 5080Sstevel@tonic-gate 5090Sstevel@tonic-gate int 5100Sstevel@tonic-gate dt_probe_define(dt_provider_t *pvp, dt_probe_t *prp, 511*1239Sahl const char *fname, const char *rname, uint32_t offset) 5120Sstevel@tonic-gate { 5130Sstevel@tonic-gate dtrace_hdl_t *dtp = pvp->pv_hdl; 5140Sstevel@tonic-gate dt_probe_instance_t *pip; 5150Sstevel@tonic-gate 516*1239Sahl assert(fname != NULL); 517*1239Sahl 5180Sstevel@tonic-gate for (pip = prp->pr_inst; pip != NULL; pip = pip->pi_next) { 519*1239Sahl if (strcmp(pip->pi_fname, fname) == 0 && 520*1239Sahl ((rname == NULL && pip->pi_rname[0] == '\0') || 521*1239Sahl (rname != NULL && strcmp(pip->pi_rname, rname)) == 0)) 5220Sstevel@tonic-gate break; 5230Sstevel@tonic-gate } 5240Sstevel@tonic-gate 5250Sstevel@tonic-gate if (pip == NULL) { 526*1239Sahl if ((pip = dt_zalloc(dtp, sizeof (*pip))) == NULL) 527*1239Sahl return (-1); 528*1239Sahl 529*1239Sahl if ((pip->pi_offs = dt_alloc(dtp, sizeof (uint32_t))) == NULL) { 5300Sstevel@tonic-gate dt_free(dtp, pip); 5310Sstevel@tonic-gate return (-1); 5320Sstevel@tonic-gate } 5330Sstevel@tonic-gate 5340Sstevel@tonic-gate (void) strlcpy(pip->pi_fname, fname, sizeof (pip->pi_fname)); 535*1239Sahl if (rname != NULL) { 536*1239Sahl if (strlen(rname) + 1 > sizeof (pip->pi_rname)) { 537*1239Sahl dt_free(dtp, pip->pi_offs); 538*1239Sahl dt_free(dtp, pip); 539*1239Sahl return (dt_set_errno(dtp, EDT_COMPILER)); 540*1239Sahl } 541*1239Sahl (void) strcpy(pip->pi_rname, rname); 542*1239Sahl } 5430Sstevel@tonic-gate pip->pi_noffs = 0; 5440Sstevel@tonic-gate pip->pi_maxoffs = 1; 5450Sstevel@tonic-gate pip->pi_next = prp->pr_inst; 5460Sstevel@tonic-gate 5470Sstevel@tonic-gate prp->pr_inst = pip; 5480Sstevel@tonic-gate } 5490Sstevel@tonic-gate 5500Sstevel@tonic-gate if (pip->pi_noffs == pip->pi_maxoffs) { 5510Sstevel@tonic-gate uint_t new_max = pip->pi_maxoffs * 2; 5520Sstevel@tonic-gate uint32_t *new_offs = dt_alloc(dtp, sizeof (uint32_t) * new_max); 5530Sstevel@tonic-gate 5540Sstevel@tonic-gate if (new_offs == NULL) 5550Sstevel@tonic-gate return (-1); 5560Sstevel@tonic-gate 5570Sstevel@tonic-gate bcopy(pip->pi_offs, new_offs, 5580Sstevel@tonic-gate sizeof (uint32_t) * pip->pi_maxoffs); 5590Sstevel@tonic-gate 5600Sstevel@tonic-gate dt_free(dtp, pip->pi_offs); 5610Sstevel@tonic-gate pip->pi_maxoffs = new_max; 5620Sstevel@tonic-gate pip->pi_offs = new_offs; 5630Sstevel@tonic-gate } 5640Sstevel@tonic-gate 565*1239Sahl dt_dprintf("defined probe %s:%s %s() +0x%x (%s)\n", 566*1239Sahl pvp->pv_desc.dtvd_name, prp->pr_ident->di_name, fname, offset, 567*1239Sahl rname != NULL ? rname : fname); 5680Sstevel@tonic-gate 5690Sstevel@tonic-gate assert(pip->pi_noffs < pip->pi_maxoffs); 5700Sstevel@tonic-gate pip->pi_offs[pip->pi_noffs++] = offset; 5710Sstevel@tonic-gate 5720Sstevel@tonic-gate return (0); 5730Sstevel@tonic-gate } 5740Sstevel@tonic-gate 575265Smws /* 576265Smws * Lookup the dynamic translator type tag for the specified probe argument and 577265Smws * assign the type to the specified node. If the type is not yet defined, add 578265Smws * it to the "D" module's type container as a typedef for an unknown type. 579265Smws */ 580265Smws dt_node_t * 581265Smws dt_probe_tag(dt_probe_t *prp, uint_t argn, dt_node_t *dnp) 582265Smws { 583265Smws dtrace_hdl_t *dtp = prp->pr_pvp->pv_hdl; 584265Smws dtrace_typeinfo_t dtt; 585265Smws size_t len; 586265Smws char *tag; 587265Smws 588265Smws len = snprintf(NULL, 0, "__dtrace_%s___%s_arg%u", 589265Smws prp->pr_pvp->pv_desc.dtvd_name, prp->pr_name, argn); 590265Smws 591265Smws tag = alloca(len + 1); 592265Smws 593265Smws (void) snprintf(tag, len + 1, "__dtrace_%s___%s_arg%u", 594265Smws prp->pr_pvp->pv_desc.dtvd_name, prp->pr_name, argn); 595265Smws 596265Smws if (dtrace_lookup_by_type(dtp, DTRACE_OBJ_DDEFS, tag, &dtt) != 0) { 597265Smws dtt.dtt_object = DTRACE_OBJ_DDEFS; 598265Smws dtt.dtt_ctfp = DT_DYN_CTFP(dtp); 599265Smws dtt.dtt_type = ctf_add_typedef(DT_DYN_CTFP(dtp), 600265Smws CTF_ADD_ROOT, tag, DT_DYN_TYPE(dtp)); 601265Smws 602265Smws if (dtt.dtt_type == CTF_ERR || 603265Smws ctf_update(dtt.dtt_ctfp) == CTF_ERR) { 604265Smws xyerror(D_UNKNOWN, "cannot define type %s: %s\n", 605265Smws tag, ctf_errmsg(ctf_errno(dtt.dtt_ctfp))); 606265Smws } 607265Smws } 608265Smws 609265Smws bzero(dnp, sizeof (dt_node_t)); 610265Smws dnp->dn_kind = DT_NODE_TYPE; 611265Smws 612265Smws dt_node_type_assign(dnp, dtt.dtt_ctfp, dtt.dtt_type); 613265Smws dt_node_attr_assign(dnp, _dtrace_defattr); 614265Smws 615265Smws return (dnp); 616265Smws } 617265Smws 6180Sstevel@tonic-gate /*ARGSUSED*/ 6190Sstevel@tonic-gate static int 6200Sstevel@tonic-gate dt_probe_desc(dtrace_hdl_t *dtp, const dtrace_probedesc_t *pdp, void *arg) 6210Sstevel@tonic-gate { 6220Sstevel@tonic-gate if (((dtrace_probedesc_t *)arg)->dtpd_id == DTRACE_IDNONE) { 6230Sstevel@tonic-gate bcopy(pdp, arg, sizeof (dtrace_probedesc_t)); 6240Sstevel@tonic-gate return (0); 6250Sstevel@tonic-gate } 6260Sstevel@tonic-gate 6270Sstevel@tonic-gate return (1); 6280Sstevel@tonic-gate } 6290Sstevel@tonic-gate 6300Sstevel@tonic-gate dt_probe_t * 6310Sstevel@tonic-gate dt_probe_info(dtrace_hdl_t *dtp, 6320Sstevel@tonic-gate const dtrace_probedesc_t *pdp, dtrace_probeinfo_t *pip) 6330Sstevel@tonic-gate { 6340Sstevel@tonic-gate int m_is_glob = pdp->dtpd_mod[0] == '\0' || strisglob(pdp->dtpd_mod); 6350Sstevel@tonic-gate int f_is_glob = pdp->dtpd_func[0] == '\0' || strisglob(pdp->dtpd_func); 6360Sstevel@tonic-gate int n_is_glob = pdp->dtpd_name[0] == '\0' || strisglob(pdp->dtpd_name); 6370Sstevel@tonic-gate 6380Sstevel@tonic-gate dt_probe_t *prp = NULL; 6390Sstevel@tonic-gate const dtrace_pattr_t *pap; 6400Sstevel@tonic-gate dt_provider_t *pvp; 6410Sstevel@tonic-gate dt_ident_t *idp; 6420Sstevel@tonic-gate 6430Sstevel@tonic-gate /* 6440Sstevel@tonic-gate * Attempt to lookup the probe in our existing cache for this provider. 6450Sstevel@tonic-gate * If none is found and an explicit probe ID was specified, discover 6460Sstevel@tonic-gate * that specific probe and cache its description and arguments. 6470Sstevel@tonic-gate */ 6480Sstevel@tonic-gate if ((pvp = dt_provider_lookup(dtp, pdp->dtpd_provider)) != NULL) { 6490Sstevel@tonic-gate size_t keylen = dt_probe_keylen(pdp); 6500Sstevel@tonic-gate char *key = dt_probe_key(pdp, alloca(keylen)); 6510Sstevel@tonic-gate 6520Sstevel@tonic-gate if ((idp = dt_idhash_lookup(pvp->pv_probes, key)) != NULL) 6530Sstevel@tonic-gate prp = idp->di_data; 6540Sstevel@tonic-gate else if (pdp->dtpd_id != DTRACE_IDNONE) 6550Sstevel@tonic-gate prp = dt_probe_discover(pvp, pdp); 6560Sstevel@tonic-gate } 6570Sstevel@tonic-gate 6580Sstevel@tonic-gate /* 6590Sstevel@tonic-gate * If no probe was found in our cache, convert the caller's partial 6600Sstevel@tonic-gate * probe description into a fully-formed matching probe description by 6610Sstevel@tonic-gate * iterating over up to at most two probes that match 'pdp'. We then 6620Sstevel@tonic-gate * call dt_probe_discover() on the resulting probe identifier. 6630Sstevel@tonic-gate */ 6640Sstevel@tonic-gate if (prp == NULL) { 6650Sstevel@tonic-gate dtrace_probedesc_t pd; 6660Sstevel@tonic-gate int m; 6670Sstevel@tonic-gate 6680Sstevel@tonic-gate bzero(&pd, sizeof (pd)); 6690Sstevel@tonic-gate pd.dtpd_id = DTRACE_IDNONE; 6700Sstevel@tonic-gate 6710Sstevel@tonic-gate /* 6720Sstevel@tonic-gate * Call dtrace_probe_iter() to find matching probes. Our 6730Sstevel@tonic-gate * dt_probe_desc() callback will produce the following results: 6740Sstevel@tonic-gate * 6750Sstevel@tonic-gate * m < 0 dtrace_probe_iter() found zero matches (or failed). 6760Sstevel@tonic-gate * m > 0 dtrace_probe_iter() found more than one match. 6770Sstevel@tonic-gate * m = 0 dtrace_probe_iter() found exactly one match. 6780Sstevel@tonic-gate */ 6790Sstevel@tonic-gate if ((m = dtrace_probe_iter(dtp, pdp, dt_probe_desc, &pd)) < 0) 6800Sstevel@tonic-gate return (NULL); /* dt_errno is set for us */ 6810Sstevel@tonic-gate 6820Sstevel@tonic-gate if ((pvp = dt_provider_lookup(dtp, pd.dtpd_provider)) == NULL) 6830Sstevel@tonic-gate return (NULL); /* dt_errno is set for us */ 6840Sstevel@tonic-gate 6850Sstevel@tonic-gate /* 6860Sstevel@tonic-gate * If more than one probe was matched, then do not report probe 6870Sstevel@tonic-gate * information if either of the following conditions is true: 6880Sstevel@tonic-gate * 6890Sstevel@tonic-gate * (a) The Arguments Data stability of the matched provider is 6900Sstevel@tonic-gate * less than Evolving. 6910Sstevel@tonic-gate * 6920Sstevel@tonic-gate * (b) Any description component that is at least Evolving is 6930Sstevel@tonic-gate * empty or is specified using a globbing expression. 6940Sstevel@tonic-gate * 6950Sstevel@tonic-gate * These conditions imply that providers that provide Evolving 6960Sstevel@tonic-gate * or better Arguments Data stability must guarantee that all 6970Sstevel@tonic-gate * probes with identical field names in a field of Evolving or 6980Sstevel@tonic-gate * better Name stability have identical argument signatures. 6990Sstevel@tonic-gate */ 7000Sstevel@tonic-gate if (m > 0) { 7010Sstevel@tonic-gate if (pvp->pv_desc.dtvd_attr.dtpa_args.dtat_data < 7020Sstevel@tonic-gate DTRACE_STABILITY_EVOLVING) { 7030Sstevel@tonic-gate (void) dt_set_errno(dtp, EDT_UNSTABLE); 7040Sstevel@tonic-gate return (NULL); 7050Sstevel@tonic-gate } 7060Sstevel@tonic-gate 7070Sstevel@tonic-gate 7080Sstevel@tonic-gate if (pvp->pv_desc.dtvd_attr.dtpa_mod.dtat_name >= 7090Sstevel@tonic-gate DTRACE_STABILITY_EVOLVING && m_is_glob) { 7100Sstevel@tonic-gate (void) dt_set_errno(dtp, EDT_UNSTABLE); 7110Sstevel@tonic-gate return (NULL); 7120Sstevel@tonic-gate } 7130Sstevel@tonic-gate 7140Sstevel@tonic-gate if (pvp->pv_desc.dtvd_attr.dtpa_func.dtat_name >= 7150Sstevel@tonic-gate DTRACE_STABILITY_EVOLVING && f_is_glob) { 7160Sstevel@tonic-gate (void) dt_set_errno(dtp, EDT_UNSTABLE); 7170Sstevel@tonic-gate return (NULL); 7180Sstevel@tonic-gate } 7190Sstevel@tonic-gate 7200Sstevel@tonic-gate if (pvp->pv_desc.dtvd_attr.dtpa_name.dtat_name >= 7210Sstevel@tonic-gate DTRACE_STABILITY_EVOLVING && n_is_glob) { 7220Sstevel@tonic-gate (void) dt_set_errno(dtp, EDT_UNSTABLE); 7230Sstevel@tonic-gate return (NULL); 7240Sstevel@tonic-gate } 7250Sstevel@tonic-gate } 7260Sstevel@tonic-gate 727265Smws /* 728265Smws * If we matched a probe exported by dtrace(7D), then discover 729265Smws * the real attributes. Otherwise grab the static declaration. 730265Smws */ 731265Smws if (pd.dtpd_id != DTRACE_IDNONE) 732265Smws prp = dt_probe_discover(pvp, &pd); 733265Smws else 734265Smws prp = dt_probe_lookup(pvp, pd.dtpd_name); 735265Smws 736265Smws if (prp == NULL) 7370Sstevel@tonic-gate return (NULL); /* dt_errno is set for us */ 7380Sstevel@tonic-gate } 7390Sstevel@tonic-gate 7400Sstevel@tonic-gate assert(pvp != NULL && prp != NULL); 7410Sstevel@tonic-gate 7420Sstevel@tonic-gate /* 7430Sstevel@tonic-gate * Compute the probe description attributes by taking the minimum of 7440Sstevel@tonic-gate * the attributes of the specified fields. If no provider is specified 7450Sstevel@tonic-gate * or a glob pattern is used for the provider, use Unstable attributes. 7460Sstevel@tonic-gate */ 7470Sstevel@tonic-gate if (pdp->dtpd_provider[0] == '\0' || strisglob(pdp->dtpd_provider)) 7480Sstevel@tonic-gate pap = &_dtrace_prvdesc; 7490Sstevel@tonic-gate else 7500Sstevel@tonic-gate pap = &pvp->pv_desc.dtvd_attr; 7510Sstevel@tonic-gate 7520Sstevel@tonic-gate pip->dtp_attr = pap->dtpa_provider; 7530Sstevel@tonic-gate 7540Sstevel@tonic-gate if (!m_is_glob) 7550Sstevel@tonic-gate pip->dtp_attr = dt_attr_min(pip->dtp_attr, pap->dtpa_mod); 7560Sstevel@tonic-gate if (!f_is_glob) 7570Sstevel@tonic-gate pip->dtp_attr = dt_attr_min(pip->dtp_attr, pap->dtpa_func); 7580Sstevel@tonic-gate if (!n_is_glob) 7590Sstevel@tonic-gate pip->dtp_attr = dt_attr_min(pip->dtp_attr, pap->dtpa_name); 7600Sstevel@tonic-gate 7610Sstevel@tonic-gate pip->dtp_arga = pap->dtpa_args; 7620Sstevel@tonic-gate pip->dtp_argv = prp->pr_argv; 7630Sstevel@tonic-gate pip->dtp_argc = prp->pr_argc; 7640Sstevel@tonic-gate 7650Sstevel@tonic-gate return (prp); 7660Sstevel@tonic-gate } 7670Sstevel@tonic-gate 7680Sstevel@tonic-gate int 7690Sstevel@tonic-gate dtrace_probe_info(dtrace_hdl_t *dtp, 7700Sstevel@tonic-gate const dtrace_probedesc_t *pdp, dtrace_probeinfo_t *pip) 7710Sstevel@tonic-gate { 7720Sstevel@tonic-gate return (dt_probe_info(dtp, pdp, pip) != NULL ? 0 : -1); 7730Sstevel@tonic-gate } 7740Sstevel@tonic-gate 7750Sstevel@tonic-gate /*ARGSUSED*/ 7760Sstevel@tonic-gate static int 7770Sstevel@tonic-gate dt_probe_iter(dt_idhash_t *ihp, dt_ident_t *idp, dt_probe_iter_t *pit) 7780Sstevel@tonic-gate { 7790Sstevel@tonic-gate const dt_probe_t *prp = idp->di_data; 7800Sstevel@tonic-gate 7810Sstevel@tonic-gate if (!dt_gmatch(prp->pr_name, pit->pit_pat)) 7820Sstevel@tonic-gate return (0); /* continue on and examine next probe in hash */ 7830Sstevel@tonic-gate 7840Sstevel@tonic-gate (void) strlcpy(pit->pit_desc.dtpd_name, prp->pr_name, DTRACE_NAMELEN); 7850Sstevel@tonic-gate pit->pit_desc.dtpd_id = idp->di_id; 7860Sstevel@tonic-gate pit->pit_matches++; 7870Sstevel@tonic-gate 7880Sstevel@tonic-gate return (pit->pit_func(pit->pit_hdl, &pit->pit_desc, pit->pit_arg)); 7890Sstevel@tonic-gate } 7900Sstevel@tonic-gate 7910Sstevel@tonic-gate int 7920Sstevel@tonic-gate dtrace_probe_iter(dtrace_hdl_t *dtp, 7930Sstevel@tonic-gate const dtrace_probedesc_t *pdp, dtrace_probe_f *func, void *arg) 7940Sstevel@tonic-gate { 7950Sstevel@tonic-gate const char *provider = pdp ? pdp->dtpd_provider : NULL; 7960Sstevel@tonic-gate dtrace_id_t id = DTRACE_IDNONE; 7970Sstevel@tonic-gate 7980Sstevel@tonic-gate dtrace_probedesc_t pd; 7990Sstevel@tonic-gate dt_probe_iter_t pit; 8000Sstevel@tonic-gate int cmd, rv; 8010Sstevel@tonic-gate 8020Sstevel@tonic-gate bzero(&pit, sizeof (pit)); 8030Sstevel@tonic-gate pit.pit_hdl = dtp; 8040Sstevel@tonic-gate pit.pit_func = func; 8050Sstevel@tonic-gate pit.pit_arg = arg; 8060Sstevel@tonic-gate pit.pit_pat = pdp ? pdp->dtpd_name : NULL; 8070Sstevel@tonic-gate 8080Sstevel@tonic-gate for (pit.pit_pvp = dt_list_next(&dtp->dt_provlist); 8090Sstevel@tonic-gate pit.pit_pvp != NULL; pit.pit_pvp = dt_list_next(pit.pit_pvp)) { 8100Sstevel@tonic-gate 8110Sstevel@tonic-gate if (pit.pit_pvp->pv_flags & DT_PROVIDER_IMPL) 8120Sstevel@tonic-gate continue; /* we'll get these later using dt_ioctl() */ 8130Sstevel@tonic-gate 8140Sstevel@tonic-gate if (!dt_gmatch(pit.pit_pvp->pv_desc.dtvd_name, provider)) 8150Sstevel@tonic-gate continue; 8160Sstevel@tonic-gate 8170Sstevel@tonic-gate (void) strlcpy(pit.pit_desc.dtpd_provider, 8180Sstevel@tonic-gate pit.pit_pvp->pv_desc.dtvd_name, DTRACE_PROVNAMELEN); 8190Sstevel@tonic-gate 8200Sstevel@tonic-gate if ((rv = dt_idhash_iter(pit.pit_pvp->pv_probes, 8210Sstevel@tonic-gate (dt_idhash_f *)dt_probe_iter, &pit)) != 0) 8220Sstevel@tonic-gate return (rv); 8230Sstevel@tonic-gate } 8240Sstevel@tonic-gate 8250Sstevel@tonic-gate if (pdp != NULL) 8260Sstevel@tonic-gate cmd = DTRACEIOC_PROBEMATCH; 8270Sstevel@tonic-gate else 8280Sstevel@tonic-gate cmd = DTRACEIOC_PROBES; 8290Sstevel@tonic-gate 8300Sstevel@tonic-gate for (;;) { 8310Sstevel@tonic-gate if (pdp != NULL) 8320Sstevel@tonic-gate bcopy(pdp, &pd, sizeof (pd)); 8330Sstevel@tonic-gate 8340Sstevel@tonic-gate pd.dtpd_id = id; 8350Sstevel@tonic-gate 8360Sstevel@tonic-gate if (dt_ioctl(dtp, cmd, &pd) != 0) 8370Sstevel@tonic-gate break; 8380Sstevel@tonic-gate else if ((rv = func(dtp, &pd, arg)) != 0) 8390Sstevel@tonic-gate return (rv); 8400Sstevel@tonic-gate 8410Sstevel@tonic-gate pit.pit_matches++; 8420Sstevel@tonic-gate id = pd.dtpd_id + 1; 8430Sstevel@tonic-gate } 8440Sstevel@tonic-gate 8450Sstevel@tonic-gate switch (errno) { 8460Sstevel@tonic-gate case ESRCH: 8470Sstevel@tonic-gate case EBADF: 8480Sstevel@tonic-gate return (pit.pit_matches ? 0 : dt_set_errno(dtp, EDT_NOPROBE)); 8490Sstevel@tonic-gate case EINVAL: 8500Sstevel@tonic-gate return (dt_set_errno(dtp, EDT_BADPGLOB)); 8510Sstevel@tonic-gate default: 8520Sstevel@tonic-gate return (dt_set_errno(dtp, errno)); 8530Sstevel@tonic-gate } 8540Sstevel@tonic-gate } 855