17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5ac448965Sahl * Common Development and Distribution License (the "License"). 6ac448965Sahl * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 21ac448965Sahl 227c478bd9Sstevel@tonic-gate /* 234b499cecSahl * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 26*a386cc11SRobert Mustacchi /* 27*a386cc11SRobert Mustacchi * Copyright (c) 2013, Joyent, Inc. All rights reserved. 28*a386cc11SRobert Mustacchi */ 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #include <sys/types.h> 317c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate #include <assert.h> 347c478bd9Sstevel@tonic-gate #include <limits.h> 357c478bd9Sstevel@tonic-gate #include <strings.h> 367c478bd9Sstevel@tonic-gate #include <stdlib.h> 377c478bd9Sstevel@tonic-gate #include <alloca.h> 387c478bd9Sstevel@tonic-gate #include <unistd.h> 397c478bd9Sstevel@tonic-gate #include <errno.h> 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gate #include <dt_provider.h> 427c478bd9Sstevel@tonic-gate #include <dt_module.h> 437c478bd9Sstevel@tonic-gate #include <dt_string.h> 447c478bd9Sstevel@tonic-gate #include <dt_list.h> 45*a386cc11SRobert Mustacchi #include <dt_pid.h> 46*a386cc11SRobert Mustacchi #include <dtrace.h> 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate static dt_provider_t * 497c478bd9Sstevel@tonic-gate dt_provider_insert(dtrace_hdl_t *dtp, dt_provider_t *pvp, uint_t h) 507c478bd9Sstevel@tonic-gate { 517c478bd9Sstevel@tonic-gate dt_list_append(&dtp->dt_provlist, pvp); 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate pvp->pv_next = dtp->dt_provs[h]; 547c478bd9Sstevel@tonic-gate dtp->dt_provs[h] = pvp; 557c478bd9Sstevel@tonic-gate dtp->dt_nprovs++; 567c478bd9Sstevel@tonic-gate 577c478bd9Sstevel@tonic-gate return (pvp); 587c478bd9Sstevel@tonic-gate } 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate dt_provider_t * 617c478bd9Sstevel@tonic-gate dt_provider_lookup(dtrace_hdl_t *dtp, const char *name) 627c478bd9Sstevel@tonic-gate { 637c478bd9Sstevel@tonic-gate uint_t h = dt_strtab_hash(name, NULL) % dtp->dt_provbuckets; 641a7c1b72Smws dtrace_providerdesc_t desc; 657c478bd9Sstevel@tonic-gate dt_provider_t *pvp; 667c478bd9Sstevel@tonic-gate 677c478bd9Sstevel@tonic-gate for (pvp = dtp->dt_provs[h]; pvp != NULL; pvp = pvp->pv_next) { 687c478bd9Sstevel@tonic-gate if (strcmp(pvp->pv_desc.dtvd_name, name) == 0) 697c478bd9Sstevel@tonic-gate return (pvp); 707c478bd9Sstevel@tonic-gate } 717c478bd9Sstevel@tonic-gate 727c478bd9Sstevel@tonic-gate if (strisglob(name) || name[0] == '\0') { 737c478bd9Sstevel@tonic-gate (void) dt_set_errno(dtp, EDT_NOPROV); 747c478bd9Sstevel@tonic-gate return (NULL); 757c478bd9Sstevel@tonic-gate } 767c478bd9Sstevel@tonic-gate 771a7c1b72Smws bzero(&desc, sizeof (desc)); 781a7c1b72Smws (void) strlcpy(desc.dtvd_name, name, DTRACE_PROVNAMELEN); 797c478bd9Sstevel@tonic-gate 801a7c1b72Smws if (dt_ioctl(dtp, DTRACEIOC_PROVIDER, &desc) == -1) { 817c478bd9Sstevel@tonic-gate (void) dt_set_errno(dtp, errno == ESRCH ? EDT_NOPROV : errno); 827c478bd9Sstevel@tonic-gate return (NULL); 837c478bd9Sstevel@tonic-gate } 847c478bd9Sstevel@tonic-gate 851a7c1b72Smws if ((pvp = dt_provider_create(dtp, name)) == NULL) 861a7c1b72Smws return (NULL); /* dt_errno is set for us */ 871a7c1b72Smws 881a7c1b72Smws bcopy(&desc, &pvp->pv_desc, sizeof (desc)); 897c478bd9Sstevel@tonic-gate pvp->pv_flags |= DT_PROVIDER_IMPL; 907c478bd9Sstevel@tonic-gate return (pvp); 917c478bd9Sstevel@tonic-gate } 927c478bd9Sstevel@tonic-gate 937c478bd9Sstevel@tonic-gate dt_provider_t * 947c478bd9Sstevel@tonic-gate dt_provider_create(dtrace_hdl_t *dtp, const char *name) 957c478bd9Sstevel@tonic-gate { 967c478bd9Sstevel@tonic-gate dt_provider_t *pvp; 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate if ((pvp = dt_zalloc(dtp, sizeof (dt_provider_t))) == NULL) 997c478bd9Sstevel@tonic-gate return (NULL); 1007c478bd9Sstevel@tonic-gate 1017c478bd9Sstevel@tonic-gate (void) strlcpy(pvp->pv_desc.dtvd_name, name, DTRACE_PROVNAMELEN); 1027c478bd9Sstevel@tonic-gate pvp->pv_probes = dt_idhash_create(pvp->pv_desc.dtvd_name, NULL, 0, 0); 1037c478bd9Sstevel@tonic-gate pvp->pv_gen = dtp->dt_gen; 1047c478bd9Sstevel@tonic-gate pvp->pv_hdl = dtp; 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate if (pvp->pv_probes == NULL) { 1077c478bd9Sstevel@tonic-gate dt_free(dtp, pvp); 1087c478bd9Sstevel@tonic-gate (void) dt_set_errno(dtp, EDT_NOMEM); 1097c478bd9Sstevel@tonic-gate return (NULL); 1107c478bd9Sstevel@tonic-gate } 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate pvp->pv_desc.dtvd_attr.dtpa_provider = _dtrace_prvattr; 1137c478bd9Sstevel@tonic-gate pvp->pv_desc.dtvd_attr.dtpa_mod = _dtrace_prvattr; 1147c478bd9Sstevel@tonic-gate pvp->pv_desc.dtvd_attr.dtpa_func = _dtrace_prvattr; 1157c478bd9Sstevel@tonic-gate pvp->pv_desc.dtvd_attr.dtpa_name = _dtrace_prvattr; 1167c478bd9Sstevel@tonic-gate pvp->pv_desc.dtvd_attr.dtpa_args = _dtrace_prvattr; 1177c478bd9Sstevel@tonic-gate 1187c478bd9Sstevel@tonic-gate return (dt_provider_insert(dtp, pvp, 1197c478bd9Sstevel@tonic-gate dt_strtab_hash(name, NULL) % dtp->dt_provbuckets)); 1207c478bd9Sstevel@tonic-gate } 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate void 1237c478bd9Sstevel@tonic-gate dt_provider_destroy(dtrace_hdl_t *dtp, dt_provider_t *pvp) 1247c478bd9Sstevel@tonic-gate { 1257c478bd9Sstevel@tonic-gate dt_provider_t **pp; 1267c478bd9Sstevel@tonic-gate uint_t h; 1277c478bd9Sstevel@tonic-gate 1287c478bd9Sstevel@tonic-gate assert(pvp->pv_hdl == dtp); 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate h = dt_strtab_hash(pvp->pv_desc.dtvd_name, NULL) % dtp->dt_provbuckets; 1317c478bd9Sstevel@tonic-gate pp = &dtp->dt_provs[h]; 1327c478bd9Sstevel@tonic-gate 1337c478bd9Sstevel@tonic-gate while (*pp != NULL && *pp != pvp) 1347c478bd9Sstevel@tonic-gate pp = &(*pp)->pv_next; 1357c478bd9Sstevel@tonic-gate 1367c478bd9Sstevel@tonic-gate assert(*pp != NULL && *pp == pvp); 1377c478bd9Sstevel@tonic-gate *pp = pvp->pv_next; 1387c478bd9Sstevel@tonic-gate 1397c478bd9Sstevel@tonic-gate dt_list_delete(&dtp->dt_provlist, pvp); 1407c478bd9Sstevel@tonic-gate dtp->dt_nprovs--; 1417c478bd9Sstevel@tonic-gate 1427c478bd9Sstevel@tonic-gate if (pvp->pv_probes != NULL) 1437c478bd9Sstevel@tonic-gate dt_idhash_destroy(pvp->pv_probes); 1447c478bd9Sstevel@tonic-gate 1457c478bd9Sstevel@tonic-gate dt_node_link_free(&pvp->pv_nodes); 1461a7c1b72Smws dt_free(dtp, pvp->pv_xrefs); 1477c478bd9Sstevel@tonic-gate dt_free(dtp, pvp); 1487c478bd9Sstevel@tonic-gate } 1497c478bd9Sstevel@tonic-gate 1501a7c1b72Smws int 1511a7c1b72Smws dt_provider_xref(dtrace_hdl_t *dtp, dt_provider_t *pvp, id_t id) 1521a7c1b72Smws { 1531a7c1b72Smws size_t oldsize = BT_SIZEOFMAP(pvp->pv_xrmax); 1541a7c1b72Smws size_t newsize = BT_SIZEOFMAP(dtp->dt_xlatorid); 1551a7c1b72Smws 1561a7c1b72Smws assert(id >= 0 && id < dtp->dt_xlatorid); 1571a7c1b72Smws 1581a7c1b72Smws if (newsize > oldsize) { 1591a7c1b72Smws ulong_t *xrefs = dt_zalloc(dtp, newsize); 1601a7c1b72Smws 1611a7c1b72Smws if (xrefs == NULL) 1621a7c1b72Smws return (-1); 1631a7c1b72Smws 1641a7c1b72Smws bcopy(pvp->pv_xrefs, xrefs, oldsize); 1651a7c1b72Smws dt_free(dtp, pvp->pv_xrefs); 1661a7c1b72Smws 1671a7c1b72Smws pvp->pv_xrefs = xrefs; 1681a7c1b72Smws pvp->pv_xrmax = dtp->dt_xlatorid; 1691a7c1b72Smws } 1701a7c1b72Smws 1711a7c1b72Smws BT_SET(pvp->pv_xrefs, id); 1721a7c1b72Smws return (0); 1731a7c1b72Smws } 1741a7c1b72Smws 1757c478bd9Sstevel@tonic-gate static uint8_t 1767c478bd9Sstevel@tonic-gate dt_probe_argmap(dt_node_t *xnp, dt_node_t *nnp) 1777c478bd9Sstevel@tonic-gate { 1787c478bd9Sstevel@tonic-gate uint8_t i; 1797c478bd9Sstevel@tonic-gate 1807c478bd9Sstevel@tonic-gate for (i = 0; nnp != NULL; i++) { 1817c478bd9Sstevel@tonic-gate if (nnp->dn_string != NULL && 1827c478bd9Sstevel@tonic-gate strcmp(nnp->dn_string, xnp->dn_string) == 0) 1837c478bd9Sstevel@tonic-gate break; 1847c478bd9Sstevel@tonic-gate else 1857c478bd9Sstevel@tonic-gate nnp = nnp->dn_list; 1867c478bd9Sstevel@tonic-gate } 1877c478bd9Sstevel@tonic-gate 1887c478bd9Sstevel@tonic-gate return (i); 1897c478bd9Sstevel@tonic-gate } 1907c478bd9Sstevel@tonic-gate 1917c478bd9Sstevel@tonic-gate static dt_node_t * 1927c478bd9Sstevel@tonic-gate dt_probe_alloc_args(dt_provider_t *pvp, int argc) 1937c478bd9Sstevel@tonic-gate { 1947c478bd9Sstevel@tonic-gate dt_node_t *args = NULL, *pnp = NULL, *dnp; 1957c478bd9Sstevel@tonic-gate int i; 1967c478bd9Sstevel@tonic-gate 1977c478bd9Sstevel@tonic-gate for (i = 0; i < argc; i++, pnp = dnp) { 1987c478bd9Sstevel@tonic-gate if ((dnp = dt_node_xalloc(pvp->pv_hdl, DT_NODE_TYPE)) == NULL) 1997c478bd9Sstevel@tonic-gate return (NULL); 2007c478bd9Sstevel@tonic-gate 2017c478bd9Sstevel@tonic-gate dnp->dn_link = pvp->pv_nodes; 2027c478bd9Sstevel@tonic-gate pvp->pv_nodes = dnp; 2037c478bd9Sstevel@tonic-gate 2047c478bd9Sstevel@tonic-gate if (args == NULL) 2057c478bd9Sstevel@tonic-gate args = dnp; 2067c478bd9Sstevel@tonic-gate else 2077c478bd9Sstevel@tonic-gate pnp->dn_list = dnp; 2087c478bd9Sstevel@tonic-gate } 2097c478bd9Sstevel@tonic-gate 2107c478bd9Sstevel@tonic-gate return (args); 2117c478bd9Sstevel@tonic-gate } 2127c478bd9Sstevel@tonic-gate 2137c478bd9Sstevel@tonic-gate static size_t 2147c478bd9Sstevel@tonic-gate dt_probe_keylen(const dtrace_probedesc_t *pdp) 2157c478bd9Sstevel@tonic-gate { 2167c478bd9Sstevel@tonic-gate return (strlen(pdp->dtpd_mod) + 1 + 2177c478bd9Sstevel@tonic-gate strlen(pdp->dtpd_func) + 1 + strlen(pdp->dtpd_name) + 1); 2187c478bd9Sstevel@tonic-gate } 2197c478bd9Sstevel@tonic-gate 2207c478bd9Sstevel@tonic-gate static char * 2217c478bd9Sstevel@tonic-gate dt_probe_key(const dtrace_probedesc_t *pdp, char *s) 2227c478bd9Sstevel@tonic-gate { 2237c478bd9Sstevel@tonic-gate (void) snprintf(s, INT_MAX, "%s:%s:%s", 2247c478bd9Sstevel@tonic-gate pdp->dtpd_mod, pdp->dtpd_func, pdp->dtpd_name); 2257c478bd9Sstevel@tonic-gate return (s); 2267c478bd9Sstevel@tonic-gate } 2277c478bd9Sstevel@tonic-gate 2287c478bd9Sstevel@tonic-gate /* 2297c478bd9Sstevel@tonic-gate * If a probe was discovered from the kernel, ask dtrace(7D) for a description 2307c478bd9Sstevel@tonic-gate * of each of its arguments, including native and translated types. 2317c478bd9Sstevel@tonic-gate */ 2327c478bd9Sstevel@tonic-gate static dt_probe_t * 2337c478bd9Sstevel@tonic-gate dt_probe_discover(dt_provider_t *pvp, const dtrace_probedesc_t *pdp) 2347c478bd9Sstevel@tonic-gate { 2357c478bd9Sstevel@tonic-gate dtrace_hdl_t *dtp = pvp->pv_hdl; 2367c478bd9Sstevel@tonic-gate char *name = dt_probe_key(pdp, alloca(dt_probe_keylen(pdp))); 2377c478bd9Sstevel@tonic-gate 2387c478bd9Sstevel@tonic-gate dt_node_t *xargs, *nargs; 2397c478bd9Sstevel@tonic-gate dt_ident_t *idp; 2407c478bd9Sstevel@tonic-gate dt_probe_t *prp; 2417c478bd9Sstevel@tonic-gate 2427c478bd9Sstevel@tonic-gate dtrace_typeinfo_t dtt; 2437c478bd9Sstevel@tonic-gate int i, nc, xc; 2447c478bd9Sstevel@tonic-gate 2457c478bd9Sstevel@tonic-gate int adc = _dtrace_argmax; 2467c478bd9Sstevel@tonic-gate dtrace_argdesc_t *adv = alloca(sizeof (dtrace_argdesc_t) * adc); 2477c478bd9Sstevel@tonic-gate dtrace_argdesc_t *adp = adv; 2487c478bd9Sstevel@tonic-gate 2497c478bd9Sstevel@tonic-gate assert(strcmp(pvp->pv_desc.dtvd_name, pdp->dtpd_provider) == 0); 2507c478bd9Sstevel@tonic-gate assert(pdp->dtpd_id != DTRACE_IDNONE); 2517c478bd9Sstevel@tonic-gate 2527c478bd9Sstevel@tonic-gate dt_dprintf("discovering probe %s:%s id=%d\n", 2537c478bd9Sstevel@tonic-gate pvp->pv_desc.dtvd_name, name, pdp->dtpd_id); 2547c478bd9Sstevel@tonic-gate 2557c478bd9Sstevel@tonic-gate for (nc = -1, i = 0; i < adc; i++, adp++) { 2567c478bd9Sstevel@tonic-gate bzero(adp, sizeof (dtrace_argdesc_t)); 2577c478bd9Sstevel@tonic-gate adp->dtargd_ndx = i; 2587c478bd9Sstevel@tonic-gate adp->dtargd_id = pdp->dtpd_id; 2597c478bd9Sstevel@tonic-gate 2607c478bd9Sstevel@tonic-gate if (dt_ioctl(dtp, DTRACEIOC_PROBEARG, adp) != 0) { 2617c478bd9Sstevel@tonic-gate (void) dt_set_errno(dtp, errno); 2627c478bd9Sstevel@tonic-gate return (NULL); 2637c478bd9Sstevel@tonic-gate } 2647c478bd9Sstevel@tonic-gate 2657c478bd9Sstevel@tonic-gate if (adp->dtargd_ndx == DTRACE_ARGNONE) 2667c478bd9Sstevel@tonic-gate break; /* all argument descs have been retrieved */ 2677c478bd9Sstevel@tonic-gate 2687c478bd9Sstevel@tonic-gate nc = MAX(nc, adp->dtargd_mapping); 2697c478bd9Sstevel@tonic-gate } 2707c478bd9Sstevel@tonic-gate 2717c478bd9Sstevel@tonic-gate xc = i; 2727c478bd9Sstevel@tonic-gate nc++; 2737c478bd9Sstevel@tonic-gate 2747c478bd9Sstevel@tonic-gate /* 275*a386cc11SRobert Mustacchi * The pid provider believes in giving the kernel a break. No reason to 276*a386cc11SRobert Mustacchi * give the kernel all the ctf containers that we're keeping ourselves 277*a386cc11SRobert Mustacchi * just to get it back from it. So if we're coming from a pid provider 278*a386cc11SRobert Mustacchi * probe and the kernel gave us no argument information we'll get some 279*a386cc11SRobert Mustacchi * here. If for some crazy reason the kernel knows about our userland 280*a386cc11SRobert Mustacchi * types then we just ignore this. 281*a386cc11SRobert Mustacchi */ 282*a386cc11SRobert Mustacchi if (xc == 0 && nc == 0 && 283*a386cc11SRobert Mustacchi strncmp(pvp->pv_desc.dtvd_name, "pid", 3) == 0) { 284*a386cc11SRobert Mustacchi nc = adc; 285*a386cc11SRobert Mustacchi dt_pid_get_types(dtp, pdp, adv, &nc); 286*a386cc11SRobert Mustacchi xc = nc; 287*a386cc11SRobert Mustacchi } 288*a386cc11SRobert Mustacchi 289*a386cc11SRobert Mustacchi /* 2907c478bd9Sstevel@tonic-gate * Now that we have discovered the number of native and translated 2917c478bd9Sstevel@tonic-gate * arguments from the argument descriptions, allocate a new probe ident 2927c478bd9Sstevel@tonic-gate * and corresponding dt_probe_t and hash it into the provider. 2937c478bd9Sstevel@tonic-gate */ 2947c478bd9Sstevel@tonic-gate xargs = dt_probe_alloc_args(pvp, xc); 2957c478bd9Sstevel@tonic-gate nargs = dt_probe_alloc_args(pvp, nc); 2967c478bd9Sstevel@tonic-gate 2977c478bd9Sstevel@tonic-gate if ((xc != 0 && xargs == NULL) || (nc != 0 && nargs == NULL)) 2987c478bd9Sstevel@tonic-gate return (NULL); /* dt_errno is set for us */ 2997c478bd9Sstevel@tonic-gate 3007c478bd9Sstevel@tonic-gate idp = dt_ident_create(name, DT_IDENT_PROBE, 3017c478bd9Sstevel@tonic-gate DT_IDFLG_ORPHAN, pdp->dtpd_id, _dtrace_defattr, 0, 3027c478bd9Sstevel@tonic-gate &dt_idops_probe, NULL, dtp->dt_gen); 3037c478bd9Sstevel@tonic-gate 3047c478bd9Sstevel@tonic-gate if (idp == NULL) { 3057c478bd9Sstevel@tonic-gate (void) dt_set_errno(dtp, EDT_NOMEM); 3067c478bd9Sstevel@tonic-gate return (NULL); 3077c478bd9Sstevel@tonic-gate } 3087c478bd9Sstevel@tonic-gate 3091a7c1b72Smws if ((prp = dt_probe_create(dtp, idp, 2, 3101a7c1b72Smws nargs, nc, xargs, xc)) == NULL) { 3117c478bd9Sstevel@tonic-gate dt_ident_destroy(idp); 3127c478bd9Sstevel@tonic-gate return (NULL); 3137c478bd9Sstevel@tonic-gate } 3147c478bd9Sstevel@tonic-gate 3157c478bd9Sstevel@tonic-gate dt_probe_declare(pvp, prp); 3167c478bd9Sstevel@tonic-gate 3177c478bd9Sstevel@tonic-gate /* 3187c478bd9Sstevel@tonic-gate * Once our new dt_probe_t is fully constructed, iterate over the 3197c478bd9Sstevel@tonic-gate * cached argument descriptions and assign types to prp->pr_nargv[] 3207c478bd9Sstevel@tonic-gate * and prp->pr_xargv[] and assign mappings to prp->pr_mapping[]. 3217c478bd9Sstevel@tonic-gate */ 3227c478bd9Sstevel@tonic-gate for (adp = adv, i = 0; i < xc; i++, adp++) { 3237c478bd9Sstevel@tonic-gate if (dtrace_type_strcompile(dtp, 3247c478bd9Sstevel@tonic-gate adp->dtargd_native, &dtt) != 0) { 3257c478bd9Sstevel@tonic-gate dt_dprintf("failed to resolve input type %s " 3267c478bd9Sstevel@tonic-gate "for %s:%s arg #%d: %s\n", adp->dtargd_native, 3277c478bd9Sstevel@tonic-gate pvp->pv_desc.dtvd_name, name, i + 1, 3287c478bd9Sstevel@tonic-gate dtrace_errmsg(dtp, dtrace_errno(dtp))); 3297c478bd9Sstevel@tonic-gate 3307c478bd9Sstevel@tonic-gate dtt.dtt_object = NULL; 3317c478bd9Sstevel@tonic-gate dtt.dtt_ctfp = NULL; 3327c478bd9Sstevel@tonic-gate dtt.dtt_type = CTF_ERR; 3337c478bd9Sstevel@tonic-gate } else { 3347c478bd9Sstevel@tonic-gate dt_node_type_assign(prp->pr_nargv[adp->dtargd_mapping], 335*a386cc11SRobert Mustacchi dtt.dtt_ctfp, dtt.dtt_type, 336*a386cc11SRobert Mustacchi dtt.dtt_flags & DTT_FL_USER ? B_TRUE : B_FALSE); 3377c478bd9Sstevel@tonic-gate } 3387c478bd9Sstevel@tonic-gate 3397c478bd9Sstevel@tonic-gate if (dtt.dtt_type != CTF_ERR && (adp->dtargd_xlate[0] == '\0' || 3407c478bd9Sstevel@tonic-gate strcmp(adp->dtargd_native, adp->dtargd_xlate) == 0)) { 3417c478bd9Sstevel@tonic-gate dt_node_type_propagate(prp->pr_nargv[ 3427c478bd9Sstevel@tonic-gate adp->dtargd_mapping], prp->pr_xargv[i]); 3437c478bd9Sstevel@tonic-gate } else if (dtrace_type_strcompile(dtp, 3447c478bd9Sstevel@tonic-gate adp->dtargd_xlate, &dtt) != 0) { 3457c478bd9Sstevel@tonic-gate dt_dprintf("failed to resolve output type %s " 3467c478bd9Sstevel@tonic-gate "for %s:%s arg #%d: %s\n", adp->dtargd_xlate, 3477c478bd9Sstevel@tonic-gate pvp->pv_desc.dtvd_name, name, i + 1, 3487c478bd9Sstevel@tonic-gate dtrace_errmsg(dtp, dtrace_errno(dtp))); 3497c478bd9Sstevel@tonic-gate 3507c478bd9Sstevel@tonic-gate dtt.dtt_object = NULL; 3517c478bd9Sstevel@tonic-gate dtt.dtt_ctfp = NULL; 3527c478bd9Sstevel@tonic-gate dtt.dtt_type = CTF_ERR; 3537c478bd9Sstevel@tonic-gate } else { 3547c478bd9Sstevel@tonic-gate dt_node_type_assign(prp->pr_xargv[i], 355*a386cc11SRobert Mustacchi dtt.dtt_ctfp, dtt.dtt_type, B_FALSE); 3567c478bd9Sstevel@tonic-gate } 3577c478bd9Sstevel@tonic-gate 3587c478bd9Sstevel@tonic-gate prp->pr_mapping[i] = adp->dtargd_mapping; 3597c478bd9Sstevel@tonic-gate prp->pr_argv[i] = dtt; 3607c478bd9Sstevel@tonic-gate } 3617c478bd9Sstevel@tonic-gate 3627c478bd9Sstevel@tonic-gate return (prp); 3637c478bd9Sstevel@tonic-gate } 3647c478bd9Sstevel@tonic-gate 3657c478bd9Sstevel@tonic-gate /* 3667c478bd9Sstevel@tonic-gate * Lookup a probe declaration based on a known provider and full or partially 3677c478bd9Sstevel@tonic-gate * specified module, function, and name. If the probe is not known to us yet, 3687c478bd9Sstevel@tonic-gate * ask dtrace(7D) to match the description and then cache any useful results. 3697c478bd9Sstevel@tonic-gate */ 3707c478bd9Sstevel@tonic-gate dt_probe_t * 3717c478bd9Sstevel@tonic-gate dt_probe_lookup(dt_provider_t *pvp, const char *s) 3727c478bd9Sstevel@tonic-gate { 3737c478bd9Sstevel@tonic-gate dtrace_hdl_t *dtp = pvp->pv_hdl; 3747c478bd9Sstevel@tonic-gate dtrace_probedesc_t pd; 3757c478bd9Sstevel@tonic-gate dt_ident_t *idp; 3767c478bd9Sstevel@tonic-gate size_t keylen; 3777c478bd9Sstevel@tonic-gate char *key; 3787c478bd9Sstevel@tonic-gate 3797c478bd9Sstevel@tonic-gate if (dtrace_str2desc(dtp, DTRACE_PROBESPEC_NAME, s, &pd) != 0) 3807c478bd9Sstevel@tonic-gate return (NULL); /* dt_errno is set for us */ 3817c478bd9Sstevel@tonic-gate 3827c478bd9Sstevel@tonic-gate keylen = dt_probe_keylen(&pd); 3837c478bd9Sstevel@tonic-gate key = dt_probe_key(&pd, alloca(keylen)); 3847c478bd9Sstevel@tonic-gate 3857c478bd9Sstevel@tonic-gate /* 3867c478bd9Sstevel@tonic-gate * If the probe is already declared, then return the dt_probe_t from 3877c478bd9Sstevel@tonic-gate * the existing identifier. This could come from a static declaration 3887c478bd9Sstevel@tonic-gate * or it could have been cached from an earlier call to this function. 3897c478bd9Sstevel@tonic-gate */ 3907c478bd9Sstevel@tonic-gate if ((idp = dt_idhash_lookup(pvp->pv_probes, key)) != NULL) 3917c478bd9Sstevel@tonic-gate return (idp->di_data); 3927c478bd9Sstevel@tonic-gate 3937c478bd9Sstevel@tonic-gate /* 3947c478bd9Sstevel@tonic-gate * If the probe isn't known, use the probe description computed above 3957c478bd9Sstevel@tonic-gate * to ask dtrace(7D) to find the first matching probe. 3967c478bd9Sstevel@tonic-gate */ 3977c478bd9Sstevel@tonic-gate if (dt_ioctl(dtp, DTRACEIOC_PROBEMATCH, &pd) == 0) 3987c478bd9Sstevel@tonic-gate return (dt_probe_discover(pvp, &pd)); 3997c478bd9Sstevel@tonic-gate 4007c478bd9Sstevel@tonic-gate if (errno == ESRCH || errno == EBADF) 4017c478bd9Sstevel@tonic-gate (void) dt_set_errno(dtp, EDT_NOPROBE); 4027c478bd9Sstevel@tonic-gate else 4037c478bd9Sstevel@tonic-gate (void) dt_set_errno(dtp, errno); 4047c478bd9Sstevel@tonic-gate 4057c478bd9Sstevel@tonic-gate return (NULL); 4067c478bd9Sstevel@tonic-gate } 4077c478bd9Sstevel@tonic-gate 4087c478bd9Sstevel@tonic-gate dt_probe_t * 4091a7c1b72Smws dt_probe_create(dtrace_hdl_t *dtp, dt_ident_t *idp, int protoc, 4107c478bd9Sstevel@tonic-gate dt_node_t *nargs, uint_t nargc, dt_node_t *xargs, uint_t xargc) 4117c478bd9Sstevel@tonic-gate { 4127c478bd9Sstevel@tonic-gate dt_module_t *dmp; 4137c478bd9Sstevel@tonic-gate dt_probe_t *prp; 4147c478bd9Sstevel@tonic-gate const char *p; 4157c478bd9Sstevel@tonic-gate uint_t i; 4167c478bd9Sstevel@tonic-gate 4177c478bd9Sstevel@tonic-gate assert(idp->di_kind == DT_IDENT_PROBE); 4187c478bd9Sstevel@tonic-gate assert(idp->di_data == NULL); 4197c478bd9Sstevel@tonic-gate 4201a7c1b72Smws /* 4211a7c1b72Smws * If only a single prototype is given, set xargc/s to nargc/s to 4221a7c1b72Smws * simplify subsequent use. Note that we can have one or both of nargs 4231a7c1b72Smws * and xargs be specified but set to NULL, indicating a void prototype. 4241a7c1b72Smws */ 4251a7c1b72Smws if (protoc < 2) { 4261a7c1b72Smws assert(xargs == NULL); 4271a7c1b72Smws assert(xargc == 0); 4287c478bd9Sstevel@tonic-gate xargs = nargs; 4297c478bd9Sstevel@tonic-gate xargc = nargc; 4307c478bd9Sstevel@tonic-gate } 4317c478bd9Sstevel@tonic-gate 4327c478bd9Sstevel@tonic-gate if ((prp = dt_alloc(dtp, sizeof (dt_probe_t))) == NULL) 4337c478bd9Sstevel@tonic-gate return (NULL); 4347c478bd9Sstevel@tonic-gate 4357c478bd9Sstevel@tonic-gate prp->pr_pvp = NULL; 4367c478bd9Sstevel@tonic-gate prp->pr_ident = idp; 4377c478bd9Sstevel@tonic-gate 4387c478bd9Sstevel@tonic-gate p = strrchr(idp->di_name, ':'); 4397c478bd9Sstevel@tonic-gate assert(p != NULL); 4407c478bd9Sstevel@tonic-gate prp->pr_name = p + 1; 4417c478bd9Sstevel@tonic-gate 4427c478bd9Sstevel@tonic-gate prp->pr_nargs = nargs; 4437c478bd9Sstevel@tonic-gate prp->pr_nargv = dt_alloc(dtp, sizeof (dt_node_t *) * nargc); 4447c478bd9Sstevel@tonic-gate prp->pr_nargc = nargc; 4457c478bd9Sstevel@tonic-gate prp->pr_xargs = xargs; 4467c478bd9Sstevel@tonic-gate prp->pr_xargv = dt_alloc(dtp, sizeof (dt_node_t *) * xargc); 4477c478bd9Sstevel@tonic-gate prp->pr_xargc = xargc; 4487c478bd9Sstevel@tonic-gate prp->pr_mapping = dt_alloc(dtp, sizeof (uint8_t) * xargc); 4497c478bd9Sstevel@tonic-gate prp->pr_inst = NULL; 4507c478bd9Sstevel@tonic-gate prp->pr_argv = dt_alloc(dtp, sizeof (dtrace_typeinfo_t) * xargc); 4517c478bd9Sstevel@tonic-gate prp->pr_argc = xargc; 4527c478bd9Sstevel@tonic-gate 4537c478bd9Sstevel@tonic-gate if ((prp->pr_nargc != 0 && prp->pr_nargv == NULL) || 4547c478bd9Sstevel@tonic-gate (prp->pr_xargc != 0 && prp->pr_xargv == NULL) || 4557c478bd9Sstevel@tonic-gate (prp->pr_xargc != 0 && prp->pr_mapping == NULL) || 4567c478bd9Sstevel@tonic-gate (prp->pr_argc != 0 && prp->pr_argv == NULL)) { 4577c478bd9Sstevel@tonic-gate dt_probe_destroy(prp); 4587c478bd9Sstevel@tonic-gate return (NULL); 4597c478bd9Sstevel@tonic-gate } 4607c478bd9Sstevel@tonic-gate 4617c478bd9Sstevel@tonic-gate for (i = 0; i < xargc; i++, xargs = xargs->dn_list) { 4627c478bd9Sstevel@tonic-gate if (xargs->dn_string != NULL) 4637c478bd9Sstevel@tonic-gate prp->pr_mapping[i] = dt_probe_argmap(xargs, nargs); 4647c478bd9Sstevel@tonic-gate else 4657c478bd9Sstevel@tonic-gate prp->pr_mapping[i] = i; 4667c478bd9Sstevel@tonic-gate 4677c478bd9Sstevel@tonic-gate prp->pr_xargv[i] = xargs; 4687c478bd9Sstevel@tonic-gate 4697c478bd9Sstevel@tonic-gate if ((dmp = dt_module_lookup_by_ctf(dtp, 4707c478bd9Sstevel@tonic-gate xargs->dn_ctfp)) != NULL) 4717c478bd9Sstevel@tonic-gate prp->pr_argv[i].dtt_object = dmp->dm_name; 4727c478bd9Sstevel@tonic-gate else 4737c478bd9Sstevel@tonic-gate prp->pr_argv[i].dtt_object = NULL; 4747c478bd9Sstevel@tonic-gate 4757c478bd9Sstevel@tonic-gate prp->pr_argv[i].dtt_ctfp = xargs->dn_ctfp; 4767c478bd9Sstevel@tonic-gate prp->pr_argv[i].dtt_type = xargs->dn_type; 4777c478bd9Sstevel@tonic-gate } 4787c478bd9Sstevel@tonic-gate 4797c478bd9Sstevel@tonic-gate for (i = 0; i < nargc; i++, nargs = nargs->dn_list) 4807c478bd9Sstevel@tonic-gate prp->pr_nargv[i] = nargs; 4817c478bd9Sstevel@tonic-gate 4827c478bd9Sstevel@tonic-gate idp->di_data = prp; 4837c478bd9Sstevel@tonic-gate return (prp); 4847c478bd9Sstevel@tonic-gate } 4857c478bd9Sstevel@tonic-gate 4867c478bd9Sstevel@tonic-gate void 4877c478bd9Sstevel@tonic-gate dt_probe_declare(dt_provider_t *pvp, dt_probe_t *prp) 4887c478bd9Sstevel@tonic-gate { 4897c478bd9Sstevel@tonic-gate assert(prp->pr_ident->di_kind == DT_IDENT_PROBE); 4907c478bd9Sstevel@tonic-gate assert(prp->pr_ident->di_data == prp); 4917c478bd9Sstevel@tonic-gate assert(prp->pr_pvp == NULL); 4927c478bd9Sstevel@tonic-gate 4937c478bd9Sstevel@tonic-gate if (prp->pr_xargs != prp->pr_nargs) 4947c478bd9Sstevel@tonic-gate pvp->pv_flags &= ~DT_PROVIDER_INTF; 4957c478bd9Sstevel@tonic-gate 4967c478bd9Sstevel@tonic-gate prp->pr_pvp = pvp; 4977c478bd9Sstevel@tonic-gate dt_idhash_xinsert(pvp->pv_probes, prp->pr_ident); 4987c478bd9Sstevel@tonic-gate } 4997c478bd9Sstevel@tonic-gate 5007c478bd9Sstevel@tonic-gate void 5017c478bd9Sstevel@tonic-gate dt_probe_destroy(dt_probe_t *prp) 5027c478bd9Sstevel@tonic-gate { 5037c478bd9Sstevel@tonic-gate dt_probe_instance_t *pip, *pip_next; 5047c478bd9Sstevel@tonic-gate dtrace_hdl_t *dtp; 5057c478bd9Sstevel@tonic-gate 5067c478bd9Sstevel@tonic-gate if (prp->pr_pvp != NULL) 5077c478bd9Sstevel@tonic-gate dtp = prp->pr_pvp->pv_hdl; 5087c478bd9Sstevel@tonic-gate else 5097c478bd9Sstevel@tonic-gate dtp = yypcb->pcb_hdl; 5107c478bd9Sstevel@tonic-gate 5117c478bd9Sstevel@tonic-gate dt_node_list_free(&prp->pr_nargs); 5127c478bd9Sstevel@tonic-gate dt_node_list_free(&prp->pr_xargs); 5137c478bd9Sstevel@tonic-gate 5147c478bd9Sstevel@tonic-gate dt_free(dtp, prp->pr_nargv); 5157c478bd9Sstevel@tonic-gate dt_free(dtp, prp->pr_xargv); 5167c478bd9Sstevel@tonic-gate 5177c478bd9Sstevel@tonic-gate for (pip = prp->pr_inst; pip != NULL; pip = pip_next) { 5187c478bd9Sstevel@tonic-gate pip_next = pip->pi_next; 5197c478bd9Sstevel@tonic-gate dt_free(dtp, pip->pi_offs); 520ac448965Sahl dt_free(dtp, pip->pi_enoffs); 5217c478bd9Sstevel@tonic-gate dt_free(dtp, pip); 5227c478bd9Sstevel@tonic-gate } 5237c478bd9Sstevel@tonic-gate 5247c478bd9Sstevel@tonic-gate dt_free(dtp, prp->pr_mapping); 5257c478bd9Sstevel@tonic-gate dt_free(dtp, prp->pr_argv); 5267c478bd9Sstevel@tonic-gate dt_free(dtp, prp); 5277c478bd9Sstevel@tonic-gate } 5287c478bd9Sstevel@tonic-gate 5297c478bd9Sstevel@tonic-gate int 5307c478bd9Sstevel@tonic-gate dt_probe_define(dt_provider_t *pvp, dt_probe_t *prp, 531ac448965Sahl const char *fname, const char *rname, uint32_t offset, int isenabled) 5327c478bd9Sstevel@tonic-gate { 5337c478bd9Sstevel@tonic-gate dtrace_hdl_t *dtp = pvp->pv_hdl; 5347c478bd9Sstevel@tonic-gate dt_probe_instance_t *pip; 535ac448965Sahl uint32_t **offs; 536ac448965Sahl uint_t *noffs, *maxoffs; 5377c478bd9Sstevel@tonic-gate 5384b499cecSahl assert(fname != NULL); 5394b499cecSahl 5407c478bd9Sstevel@tonic-gate for (pip = prp->pr_inst; pip != NULL; pip = pip->pi_next) { 5414b499cecSahl if (strcmp(pip->pi_fname, fname) == 0 && 5424b499cecSahl ((rname == NULL && pip->pi_rname[0] == '\0') || 5434b499cecSahl (rname != NULL && strcmp(pip->pi_rname, rname)) == 0)) 5447c478bd9Sstevel@tonic-gate break; 5457c478bd9Sstevel@tonic-gate } 5467c478bd9Sstevel@tonic-gate 5477c478bd9Sstevel@tonic-gate if (pip == NULL) { 5484b499cecSahl if ((pip = dt_zalloc(dtp, sizeof (*pip))) == NULL) 5494b499cecSahl return (-1); 5504b499cecSahl 551ac448965Sahl if ((pip->pi_offs = dt_zalloc(dtp, 552ac448965Sahl sizeof (uint32_t))) == NULL) { 553ac448965Sahl dt_free(dtp, pip); 554ac448965Sahl return (-1); 555ac448965Sahl } 556ac448965Sahl 557ac448965Sahl if ((pip->pi_enoffs = dt_zalloc(dtp, 558ac448965Sahl sizeof (uint32_t))) == NULL) { 559ac448965Sahl dt_free(dtp, pip->pi_offs); 5607c478bd9Sstevel@tonic-gate dt_free(dtp, pip); 5617c478bd9Sstevel@tonic-gate return (-1); 5627c478bd9Sstevel@tonic-gate } 5637c478bd9Sstevel@tonic-gate 5647c478bd9Sstevel@tonic-gate (void) strlcpy(pip->pi_fname, fname, sizeof (pip->pi_fname)); 5654b499cecSahl if (rname != NULL) { 5664b499cecSahl if (strlen(rname) + 1 > sizeof (pip->pi_rname)) { 5674b499cecSahl dt_free(dtp, pip->pi_offs); 5684b499cecSahl dt_free(dtp, pip); 5694b499cecSahl return (dt_set_errno(dtp, EDT_COMPILER)); 5704b499cecSahl } 5714b499cecSahl (void) strcpy(pip->pi_rname, rname); 5724b499cecSahl } 573ac448965Sahl 5747c478bd9Sstevel@tonic-gate pip->pi_noffs = 0; 5757c478bd9Sstevel@tonic-gate pip->pi_maxoffs = 1; 576ac448965Sahl pip->pi_nenoffs = 0; 577ac448965Sahl pip->pi_maxenoffs = 1; 578ac448965Sahl 5797c478bd9Sstevel@tonic-gate pip->pi_next = prp->pr_inst; 5807c478bd9Sstevel@tonic-gate 5817c478bd9Sstevel@tonic-gate prp->pr_inst = pip; 5827c478bd9Sstevel@tonic-gate } 5837c478bd9Sstevel@tonic-gate 584ac448965Sahl if (isenabled) { 585ac448965Sahl offs = &pip->pi_enoffs; 586ac448965Sahl noffs = &pip->pi_nenoffs; 587ac448965Sahl maxoffs = &pip->pi_maxenoffs; 588ac448965Sahl } else { 589ac448965Sahl offs = &pip->pi_offs; 590ac448965Sahl noffs = &pip->pi_noffs; 591ac448965Sahl maxoffs = &pip->pi_maxoffs; 592ac448965Sahl } 593ac448965Sahl 594ac448965Sahl if (*noffs == *maxoffs) { 595ac448965Sahl uint_t new_max = *maxoffs * 2; 5967c478bd9Sstevel@tonic-gate uint32_t *new_offs = dt_alloc(dtp, sizeof (uint32_t) * new_max); 5977c478bd9Sstevel@tonic-gate 5987c478bd9Sstevel@tonic-gate if (new_offs == NULL) 5997c478bd9Sstevel@tonic-gate return (-1); 6007c478bd9Sstevel@tonic-gate 601ac448965Sahl bcopy(*offs, new_offs, sizeof (uint32_t) * *maxoffs); 6027c478bd9Sstevel@tonic-gate 603ac448965Sahl dt_free(dtp, *offs); 604ac448965Sahl *maxoffs = new_max; 605ac448965Sahl *offs = new_offs; 6067c478bd9Sstevel@tonic-gate } 6077c478bd9Sstevel@tonic-gate 608ac448965Sahl dt_dprintf("defined probe %s %s:%s %s() +0x%x (%s)\n", 609ac448965Sahl isenabled ? "(is-enabled)" : "", 6104b499cecSahl pvp->pv_desc.dtvd_name, prp->pr_ident->di_name, fname, offset, 6114b499cecSahl rname != NULL ? rname : fname); 6127c478bd9Sstevel@tonic-gate 613ac448965Sahl assert(*noffs < *maxoffs); 614fbe11206Sbmc (*offs)[(*noffs)++] = offset; 6157c478bd9Sstevel@tonic-gate 6167c478bd9Sstevel@tonic-gate return (0); 6177c478bd9Sstevel@tonic-gate } 6187c478bd9Sstevel@tonic-gate 6191a7c1b72Smws /* 6201a7c1b72Smws * Lookup the dynamic translator type tag for the specified probe argument and 6211a7c1b72Smws * assign the type to the specified node. If the type is not yet defined, add 6221a7c1b72Smws * it to the "D" module's type container as a typedef for an unknown type. 6231a7c1b72Smws */ 6241a7c1b72Smws dt_node_t * 6251a7c1b72Smws dt_probe_tag(dt_probe_t *prp, uint_t argn, dt_node_t *dnp) 6261a7c1b72Smws { 6271a7c1b72Smws dtrace_hdl_t *dtp = prp->pr_pvp->pv_hdl; 6281a7c1b72Smws dtrace_typeinfo_t dtt; 6291a7c1b72Smws size_t len; 6301a7c1b72Smws char *tag; 6311a7c1b72Smws 6321a7c1b72Smws len = snprintf(NULL, 0, "__dtrace_%s___%s_arg%u", 6331a7c1b72Smws prp->pr_pvp->pv_desc.dtvd_name, prp->pr_name, argn); 6341a7c1b72Smws 6351a7c1b72Smws tag = alloca(len + 1); 6361a7c1b72Smws 6371a7c1b72Smws (void) snprintf(tag, len + 1, "__dtrace_%s___%s_arg%u", 6381a7c1b72Smws prp->pr_pvp->pv_desc.dtvd_name, prp->pr_name, argn); 6391a7c1b72Smws 6401a7c1b72Smws if (dtrace_lookup_by_type(dtp, DTRACE_OBJ_DDEFS, tag, &dtt) != 0) { 6411a7c1b72Smws dtt.dtt_object = DTRACE_OBJ_DDEFS; 6421a7c1b72Smws dtt.dtt_ctfp = DT_DYN_CTFP(dtp); 6431a7c1b72Smws dtt.dtt_type = ctf_add_typedef(DT_DYN_CTFP(dtp), 6441a7c1b72Smws CTF_ADD_ROOT, tag, DT_DYN_TYPE(dtp)); 6451a7c1b72Smws 6461a7c1b72Smws if (dtt.dtt_type == CTF_ERR || 6471a7c1b72Smws ctf_update(dtt.dtt_ctfp) == CTF_ERR) { 6481a7c1b72Smws xyerror(D_UNKNOWN, "cannot define type %s: %s\n", 6491a7c1b72Smws tag, ctf_errmsg(ctf_errno(dtt.dtt_ctfp))); 6501a7c1b72Smws } 6511a7c1b72Smws } 6521a7c1b72Smws 6531a7c1b72Smws bzero(dnp, sizeof (dt_node_t)); 6541a7c1b72Smws dnp->dn_kind = DT_NODE_TYPE; 6551a7c1b72Smws 656*a386cc11SRobert Mustacchi dt_node_type_assign(dnp, dtt.dtt_ctfp, dtt.dtt_type, B_FALSE); 6571a7c1b72Smws dt_node_attr_assign(dnp, _dtrace_defattr); 6581a7c1b72Smws 6591a7c1b72Smws return (dnp); 6601a7c1b72Smws } 6611a7c1b72Smws 6627c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 6637c478bd9Sstevel@tonic-gate static int 6647c478bd9Sstevel@tonic-gate dt_probe_desc(dtrace_hdl_t *dtp, const dtrace_probedesc_t *pdp, void *arg) 6657c478bd9Sstevel@tonic-gate { 6667c478bd9Sstevel@tonic-gate if (((dtrace_probedesc_t *)arg)->dtpd_id == DTRACE_IDNONE) { 6677c478bd9Sstevel@tonic-gate bcopy(pdp, arg, sizeof (dtrace_probedesc_t)); 6687c478bd9Sstevel@tonic-gate return (0); 6697c478bd9Sstevel@tonic-gate } 6707c478bd9Sstevel@tonic-gate 6717c478bd9Sstevel@tonic-gate return (1); 6727c478bd9Sstevel@tonic-gate } 6737c478bd9Sstevel@tonic-gate 6747c478bd9Sstevel@tonic-gate dt_probe_t * 6757c478bd9Sstevel@tonic-gate dt_probe_info(dtrace_hdl_t *dtp, 6767c478bd9Sstevel@tonic-gate const dtrace_probedesc_t *pdp, dtrace_probeinfo_t *pip) 6777c478bd9Sstevel@tonic-gate { 6787c478bd9Sstevel@tonic-gate int m_is_glob = pdp->dtpd_mod[0] == '\0' || strisglob(pdp->dtpd_mod); 6797c478bd9Sstevel@tonic-gate int f_is_glob = pdp->dtpd_func[0] == '\0' || strisglob(pdp->dtpd_func); 6807c478bd9Sstevel@tonic-gate int n_is_glob = pdp->dtpd_name[0] == '\0' || strisglob(pdp->dtpd_name); 6817c478bd9Sstevel@tonic-gate 6827c478bd9Sstevel@tonic-gate dt_probe_t *prp = NULL; 6837c478bd9Sstevel@tonic-gate const dtrace_pattr_t *pap; 6847c478bd9Sstevel@tonic-gate dt_provider_t *pvp; 6857c478bd9Sstevel@tonic-gate dt_ident_t *idp; 6867c478bd9Sstevel@tonic-gate 6877c478bd9Sstevel@tonic-gate /* 6887c478bd9Sstevel@tonic-gate * Attempt to lookup the probe in our existing cache for this provider. 6897c478bd9Sstevel@tonic-gate * If none is found and an explicit probe ID was specified, discover 6907c478bd9Sstevel@tonic-gate * that specific probe and cache its description and arguments. 6917c478bd9Sstevel@tonic-gate */ 6927c478bd9Sstevel@tonic-gate if ((pvp = dt_provider_lookup(dtp, pdp->dtpd_provider)) != NULL) { 6937c478bd9Sstevel@tonic-gate size_t keylen = dt_probe_keylen(pdp); 6947c478bd9Sstevel@tonic-gate char *key = dt_probe_key(pdp, alloca(keylen)); 6957c478bd9Sstevel@tonic-gate 6967c478bd9Sstevel@tonic-gate if ((idp = dt_idhash_lookup(pvp->pv_probes, key)) != NULL) 6977c478bd9Sstevel@tonic-gate prp = idp->di_data; 6987c478bd9Sstevel@tonic-gate else if (pdp->dtpd_id != DTRACE_IDNONE) 6997c478bd9Sstevel@tonic-gate prp = dt_probe_discover(pvp, pdp); 7007c478bd9Sstevel@tonic-gate } 7017c478bd9Sstevel@tonic-gate 7027c478bd9Sstevel@tonic-gate /* 7037c478bd9Sstevel@tonic-gate * If no probe was found in our cache, convert the caller's partial 7047c478bd9Sstevel@tonic-gate * probe description into a fully-formed matching probe description by 7057c478bd9Sstevel@tonic-gate * iterating over up to at most two probes that match 'pdp'. We then 7067c478bd9Sstevel@tonic-gate * call dt_probe_discover() on the resulting probe identifier. 7077c478bd9Sstevel@tonic-gate */ 7087c478bd9Sstevel@tonic-gate if (prp == NULL) { 7097c478bd9Sstevel@tonic-gate dtrace_probedesc_t pd; 7107c478bd9Sstevel@tonic-gate int m; 7117c478bd9Sstevel@tonic-gate 7127c478bd9Sstevel@tonic-gate bzero(&pd, sizeof (pd)); 7137c478bd9Sstevel@tonic-gate pd.dtpd_id = DTRACE_IDNONE; 7147c478bd9Sstevel@tonic-gate 7157c478bd9Sstevel@tonic-gate /* 7167c478bd9Sstevel@tonic-gate * Call dtrace_probe_iter() to find matching probes. Our 7177c478bd9Sstevel@tonic-gate * dt_probe_desc() callback will produce the following results: 7187c478bd9Sstevel@tonic-gate * 7197c478bd9Sstevel@tonic-gate * m < 0 dtrace_probe_iter() found zero matches (or failed). 7207c478bd9Sstevel@tonic-gate * m > 0 dtrace_probe_iter() found more than one match. 7217c478bd9Sstevel@tonic-gate * m = 0 dtrace_probe_iter() found exactly one match. 7227c478bd9Sstevel@tonic-gate */ 7237c478bd9Sstevel@tonic-gate if ((m = dtrace_probe_iter(dtp, pdp, dt_probe_desc, &pd)) < 0) 7247c478bd9Sstevel@tonic-gate return (NULL); /* dt_errno is set for us */ 7257c478bd9Sstevel@tonic-gate 7267c478bd9Sstevel@tonic-gate if ((pvp = dt_provider_lookup(dtp, pd.dtpd_provider)) == NULL) 7277c478bd9Sstevel@tonic-gate return (NULL); /* dt_errno is set for us */ 7287c478bd9Sstevel@tonic-gate 7297c478bd9Sstevel@tonic-gate /* 7307c478bd9Sstevel@tonic-gate * If more than one probe was matched, then do not report probe 7317c478bd9Sstevel@tonic-gate * information if either of the following conditions is true: 7327c478bd9Sstevel@tonic-gate * 7337c478bd9Sstevel@tonic-gate * (a) The Arguments Data stability of the matched provider is 7347c478bd9Sstevel@tonic-gate * less than Evolving. 7357c478bd9Sstevel@tonic-gate * 7367c478bd9Sstevel@tonic-gate * (b) Any description component that is at least Evolving is 7377c478bd9Sstevel@tonic-gate * empty or is specified using a globbing expression. 7387c478bd9Sstevel@tonic-gate * 7397c478bd9Sstevel@tonic-gate * These conditions imply that providers that provide Evolving 7407c478bd9Sstevel@tonic-gate * or better Arguments Data stability must guarantee that all 7417c478bd9Sstevel@tonic-gate * probes with identical field names in a field of Evolving or 7427c478bd9Sstevel@tonic-gate * better Name stability have identical argument signatures. 7437c478bd9Sstevel@tonic-gate */ 7447c478bd9Sstevel@tonic-gate if (m > 0) { 7457c478bd9Sstevel@tonic-gate if (pvp->pv_desc.dtvd_attr.dtpa_args.dtat_data < 7467c478bd9Sstevel@tonic-gate DTRACE_STABILITY_EVOLVING) { 7477c478bd9Sstevel@tonic-gate (void) dt_set_errno(dtp, EDT_UNSTABLE); 7487c478bd9Sstevel@tonic-gate return (NULL); 7497c478bd9Sstevel@tonic-gate } 7507c478bd9Sstevel@tonic-gate 7517c478bd9Sstevel@tonic-gate 7527c478bd9Sstevel@tonic-gate if (pvp->pv_desc.dtvd_attr.dtpa_mod.dtat_name >= 7537c478bd9Sstevel@tonic-gate DTRACE_STABILITY_EVOLVING && m_is_glob) { 7547c478bd9Sstevel@tonic-gate (void) dt_set_errno(dtp, EDT_UNSTABLE); 7557c478bd9Sstevel@tonic-gate return (NULL); 7567c478bd9Sstevel@tonic-gate } 7577c478bd9Sstevel@tonic-gate 7587c478bd9Sstevel@tonic-gate if (pvp->pv_desc.dtvd_attr.dtpa_func.dtat_name >= 7597c478bd9Sstevel@tonic-gate DTRACE_STABILITY_EVOLVING && f_is_glob) { 7607c478bd9Sstevel@tonic-gate (void) dt_set_errno(dtp, EDT_UNSTABLE); 7617c478bd9Sstevel@tonic-gate return (NULL); 7627c478bd9Sstevel@tonic-gate } 7637c478bd9Sstevel@tonic-gate 7647c478bd9Sstevel@tonic-gate if (pvp->pv_desc.dtvd_attr.dtpa_name.dtat_name >= 7657c478bd9Sstevel@tonic-gate DTRACE_STABILITY_EVOLVING && n_is_glob) { 7667c478bd9Sstevel@tonic-gate (void) dt_set_errno(dtp, EDT_UNSTABLE); 7677c478bd9Sstevel@tonic-gate return (NULL); 7687c478bd9Sstevel@tonic-gate } 7697c478bd9Sstevel@tonic-gate } 7707c478bd9Sstevel@tonic-gate 7711a7c1b72Smws /* 7721a7c1b72Smws * If we matched a probe exported by dtrace(7D), then discover 7731a7c1b72Smws * the real attributes. Otherwise grab the static declaration. 7741a7c1b72Smws */ 7751a7c1b72Smws if (pd.dtpd_id != DTRACE_IDNONE) 7761a7c1b72Smws prp = dt_probe_discover(pvp, &pd); 7771a7c1b72Smws else 7781a7c1b72Smws prp = dt_probe_lookup(pvp, pd.dtpd_name); 7791a7c1b72Smws 7801a7c1b72Smws if (prp == NULL) 7817c478bd9Sstevel@tonic-gate return (NULL); /* dt_errno is set for us */ 7827c478bd9Sstevel@tonic-gate } 7837c478bd9Sstevel@tonic-gate 7847c478bd9Sstevel@tonic-gate assert(pvp != NULL && prp != NULL); 7857c478bd9Sstevel@tonic-gate 7867c478bd9Sstevel@tonic-gate /* 7877c478bd9Sstevel@tonic-gate * Compute the probe description attributes by taking the minimum of 7887c478bd9Sstevel@tonic-gate * the attributes of the specified fields. If no provider is specified 7897c478bd9Sstevel@tonic-gate * or a glob pattern is used for the provider, use Unstable attributes. 7907c478bd9Sstevel@tonic-gate */ 7917c478bd9Sstevel@tonic-gate if (pdp->dtpd_provider[0] == '\0' || strisglob(pdp->dtpd_provider)) 7927c478bd9Sstevel@tonic-gate pap = &_dtrace_prvdesc; 7937c478bd9Sstevel@tonic-gate else 7947c478bd9Sstevel@tonic-gate pap = &pvp->pv_desc.dtvd_attr; 7957c478bd9Sstevel@tonic-gate 7967c478bd9Sstevel@tonic-gate pip->dtp_attr = pap->dtpa_provider; 7977c478bd9Sstevel@tonic-gate 7987c478bd9Sstevel@tonic-gate if (!m_is_glob) 7997c478bd9Sstevel@tonic-gate pip->dtp_attr = dt_attr_min(pip->dtp_attr, pap->dtpa_mod); 8007c478bd9Sstevel@tonic-gate if (!f_is_glob) 8017c478bd9Sstevel@tonic-gate pip->dtp_attr = dt_attr_min(pip->dtp_attr, pap->dtpa_func); 8027c478bd9Sstevel@tonic-gate if (!n_is_glob) 8037c478bd9Sstevel@tonic-gate pip->dtp_attr = dt_attr_min(pip->dtp_attr, pap->dtpa_name); 8047c478bd9Sstevel@tonic-gate 8057c478bd9Sstevel@tonic-gate pip->dtp_arga = pap->dtpa_args; 8067c478bd9Sstevel@tonic-gate pip->dtp_argv = prp->pr_argv; 8077c478bd9Sstevel@tonic-gate pip->dtp_argc = prp->pr_argc; 8087c478bd9Sstevel@tonic-gate 8097c478bd9Sstevel@tonic-gate return (prp); 8107c478bd9Sstevel@tonic-gate } 8117c478bd9Sstevel@tonic-gate 8127c478bd9Sstevel@tonic-gate int 8137c478bd9Sstevel@tonic-gate dtrace_probe_info(dtrace_hdl_t *dtp, 8147c478bd9Sstevel@tonic-gate const dtrace_probedesc_t *pdp, dtrace_probeinfo_t *pip) 8157c478bd9Sstevel@tonic-gate { 8167c478bd9Sstevel@tonic-gate return (dt_probe_info(dtp, pdp, pip) != NULL ? 0 : -1); 8177c478bd9Sstevel@tonic-gate } 8187c478bd9Sstevel@tonic-gate 8197c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 8207c478bd9Sstevel@tonic-gate static int 8217c478bd9Sstevel@tonic-gate dt_probe_iter(dt_idhash_t *ihp, dt_ident_t *idp, dt_probe_iter_t *pit) 8227c478bd9Sstevel@tonic-gate { 8237c478bd9Sstevel@tonic-gate const dt_probe_t *prp = idp->di_data; 8247c478bd9Sstevel@tonic-gate 8257c478bd9Sstevel@tonic-gate if (!dt_gmatch(prp->pr_name, pit->pit_pat)) 8267c478bd9Sstevel@tonic-gate return (0); /* continue on and examine next probe in hash */ 8277c478bd9Sstevel@tonic-gate 8287c478bd9Sstevel@tonic-gate (void) strlcpy(pit->pit_desc.dtpd_name, prp->pr_name, DTRACE_NAMELEN); 8297c478bd9Sstevel@tonic-gate pit->pit_desc.dtpd_id = idp->di_id; 8307c478bd9Sstevel@tonic-gate pit->pit_matches++; 8317c478bd9Sstevel@tonic-gate 8327c478bd9Sstevel@tonic-gate return (pit->pit_func(pit->pit_hdl, &pit->pit_desc, pit->pit_arg)); 8337c478bd9Sstevel@tonic-gate } 8347c478bd9Sstevel@tonic-gate 8357c478bd9Sstevel@tonic-gate int 8367c478bd9Sstevel@tonic-gate dtrace_probe_iter(dtrace_hdl_t *dtp, 8377c478bd9Sstevel@tonic-gate const dtrace_probedesc_t *pdp, dtrace_probe_f *func, void *arg) 8387c478bd9Sstevel@tonic-gate { 8397c478bd9Sstevel@tonic-gate const char *provider = pdp ? pdp->dtpd_provider : NULL; 8407c478bd9Sstevel@tonic-gate dtrace_id_t id = DTRACE_IDNONE; 8417c478bd9Sstevel@tonic-gate 8427c478bd9Sstevel@tonic-gate dtrace_probedesc_t pd; 8437c478bd9Sstevel@tonic-gate dt_probe_iter_t pit; 8447c478bd9Sstevel@tonic-gate int cmd, rv; 8457c478bd9Sstevel@tonic-gate 8467c478bd9Sstevel@tonic-gate bzero(&pit, sizeof (pit)); 8477c478bd9Sstevel@tonic-gate pit.pit_hdl = dtp; 8487c478bd9Sstevel@tonic-gate pit.pit_func = func; 8497c478bd9Sstevel@tonic-gate pit.pit_arg = arg; 8507c478bd9Sstevel@tonic-gate pit.pit_pat = pdp ? pdp->dtpd_name : NULL; 8517c478bd9Sstevel@tonic-gate 8527c478bd9Sstevel@tonic-gate for (pit.pit_pvp = dt_list_next(&dtp->dt_provlist); 8537c478bd9Sstevel@tonic-gate pit.pit_pvp != NULL; pit.pit_pvp = dt_list_next(pit.pit_pvp)) { 8547c478bd9Sstevel@tonic-gate 8557c478bd9Sstevel@tonic-gate if (pit.pit_pvp->pv_flags & DT_PROVIDER_IMPL) 8567c478bd9Sstevel@tonic-gate continue; /* we'll get these later using dt_ioctl() */ 8577c478bd9Sstevel@tonic-gate 8587c478bd9Sstevel@tonic-gate if (!dt_gmatch(pit.pit_pvp->pv_desc.dtvd_name, provider)) 8597c478bd9Sstevel@tonic-gate continue; 8607c478bd9Sstevel@tonic-gate 8617c478bd9Sstevel@tonic-gate (void) strlcpy(pit.pit_desc.dtpd_provider, 8627c478bd9Sstevel@tonic-gate pit.pit_pvp->pv_desc.dtvd_name, DTRACE_PROVNAMELEN); 8637c478bd9Sstevel@tonic-gate 8647c478bd9Sstevel@tonic-gate if ((rv = dt_idhash_iter(pit.pit_pvp->pv_probes, 8657c478bd9Sstevel@tonic-gate (dt_idhash_f *)dt_probe_iter, &pit)) != 0) 8667c478bd9Sstevel@tonic-gate return (rv); 8677c478bd9Sstevel@tonic-gate } 8687c478bd9Sstevel@tonic-gate 8697c478bd9Sstevel@tonic-gate if (pdp != NULL) 8707c478bd9Sstevel@tonic-gate cmd = DTRACEIOC_PROBEMATCH; 8717c478bd9Sstevel@tonic-gate else 8727c478bd9Sstevel@tonic-gate cmd = DTRACEIOC_PROBES; 8737c478bd9Sstevel@tonic-gate 8747c478bd9Sstevel@tonic-gate for (;;) { 8757c478bd9Sstevel@tonic-gate if (pdp != NULL) 8767c478bd9Sstevel@tonic-gate bcopy(pdp, &pd, sizeof (pd)); 8777c478bd9Sstevel@tonic-gate 8787c478bd9Sstevel@tonic-gate pd.dtpd_id = id; 8797c478bd9Sstevel@tonic-gate 8807c478bd9Sstevel@tonic-gate if (dt_ioctl(dtp, cmd, &pd) != 0) 8817c478bd9Sstevel@tonic-gate break; 8827c478bd9Sstevel@tonic-gate else if ((rv = func(dtp, &pd, arg)) != 0) 8837c478bd9Sstevel@tonic-gate return (rv); 8847c478bd9Sstevel@tonic-gate 8857c478bd9Sstevel@tonic-gate pit.pit_matches++; 8867c478bd9Sstevel@tonic-gate id = pd.dtpd_id + 1; 8877c478bd9Sstevel@tonic-gate } 8887c478bd9Sstevel@tonic-gate 8897c478bd9Sstevel@tonic-gate switch (errno) { 8907c478bd9Sstevel@tonic-gate case ESRCH: 8917c478bd9Sstevel@tonic-gate case EBADF: 8927c478bd9Sstevel@tonic-gate return (pit.pit_matches ? 0 : dt_set_errno(dtp, EDT_NOPROBE)); 8937c478bd9Sstevel@tonic-gate case EINVAL: 8947c478bd9Sstevel@tonic-gate return (dt_set_errno(dtp, EDT_BADPGLOB)); 8957c478bd9Sstevel@tonic-gate default: 8967c478bd9Sstevel@tonic-gate return (dt_set_errno(dtp, errno)); 8977c478bd9Sstevel@tonic-gate } 8987c478bd9Sstevel@tonic-gate } 899