1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate #include <sys/sysmacros.h> 30*0Sstevel@tonic-gate 31*0Sstevel@tonic-gate #include <strings.h> 32*0Sstevel@tonic-gate #include <unistd.h> 33*0Sstevel@tonic-gate #include <stdarg.h> 34*0Sstevel@tonic-gate #include <stddef.h> 35*0Sstevel@tonic-gate #include <stdlib.h> 36*0Sstevel@tonic-gate #include <stdio.h> 37*0Sstevel@tonic-gate #include <errno.h> 38*0Sstevel@tonic-gate #include <ctype.h> 39*0Sstevel@tonic-gate #include <alloca.h> 40*0Sstevel@tonic-gate #include <assert.h> 41*0Sstevel@tonic-gate #include <libgen.h> 42*0Sstevel@tonic-gate 43*0Sstevel@tonic-gate #include <dt_impl.h> 44*0Sstevel@tonic-gate 45*0Sstevel@tonic-gate static const struct { 46*0Sstevel@tonic-gate size_t dtps_offset; 47*0Sstevel@tonic-gate size_t dtps_len; 48*0Sstevel@tonic-gate } dtrace_probespecs[] = { 49*0Sstevel@tonic-gate { offsetof(dtrace_probedesc_t, dtpd_provider), DTRACE_PROVNAMELEN }, 50*0Sstevel@tonic-gate { offsetof(dtrace_probedesc_t, dtpd_mod), DTRACE_MODNAMELEN }, 51*0Sstevel@tonic-gate { offsetof(dtrace_probedesc_t, dtpd_func), DTRACE_FUNCNAMELEN }, 52*0Sstevel@tonic-gate { offsetof(dtrace_probedesc_t, dtpd_name), DTRACE_NAMELEN } 53*0Sstevel@tonic-gate }; 54*0Sstevel@tonic-gate 55*0Sstevel@tonic-gate int 56*0Sstevel@tonic-gate dtrace_xstr2desc(dtrace_hdl_t *dtp, dtrace_probespec_t spec, 57*0Sstevel@tonic-gate const char *s, int argc, char *const argv[], dtrace_probedesc_t *pdp) 58*0Sstevel@tonic-gate { 59*0Sstevel@tonic-gate size_t off, len, vlen; 60*0Sstevel@tonic-gate const char *p, *q, *v; 61*0Sstevel@tonic-gate 62*0Sstevel@tonic-gate char buf[32]; /* for id_t as %d (see below) */ 63*0Sstevel@tonic-gate 64*0Sstevel@tonic-gate if (spec < DTRACE_PROBESPEC_NONE || spec > DTRACE_PROBESPEC_NAME) 65*0Sstevel@tonic-gate return (dt_set_errno(dtp, EINVAL)); 66*0Sstevel@tonic-gate 67*0Sstevel@tonic-gate bzero(pdp, sizeof (dtrace_probedesc_t)); 68*0Sstevel@tonic-gate p = s + strlen(s) - 1; 69*0Sstevel@tonic-gate 70*0Sstevel@tonic-gate do { 71*0Sstevel@tonic-gate for (len = 0; p >= s && *p != ':'; len++) 72*0Sstevel@tonic-gate p--; /* move backward until we find a delimiter */ 73*0Sstevel@tonic-gate 74*0Sstevel@tonic-gate q = p + 1; 75*0Sstevel@tonic-gate vlen = 0; 76*0Sstevel@tonic-gate 77*0Sstevel@tonic-gate if ((v = strchr(q, '$')) != NULL && v < q + len) { 78*0Sstevel@tonic-gate /* 79*0Sstevel@tonic-gate * Set vlen to the length of the variable name and then 80*0Sstevel@tonic-gate * reset len to the length of the text prior to '$'. If 81*0Sstevel@tonic-gate * the name begins with a digit, interpret it using the 82*0Sstevel@tonic-gate * the argv[] array. Otherwise we look in dt_macros. 83*0Sstevel@tonic-gate * For the moment, all dt_macros variables are of type 84*0Sstevel@tonic-gate * id_t (see dtrace_update() for more details on that). 85*0Sstevel@tonic-gate */ 86*0Sstevel@tonic-gate vlen = (size_t)(q + len - v); 87*0Sstevel@tonic-gate len = (size_t)(v - q); 88*0Sstevel@tonic-gate 89*0Sstevel@tonic-gate /* 90*0Sstevel@tonic-gate * If the variable string begins with $$, skip past the 91*0Sstevel@tonic-gate * leading dollar sign since $ and $$ are equivalent 92*0Sstevel@tonic-gate * macro reference operators in a probe description. 93*0Sstevel@tonic-gate */ 94*0Sstevel@tonic-gate if (vlen > 2 && v[1] == '$') { 95*0Sstevel@tonic-gate vlen--; 96*0Sstevel@tonic-gate v++; 97*0Sstevel@tonic-gate } 98*0Sstevel@tonic-gate 99*0Sstevel@tonic-gate if (isdigit(v[1])) { 100*0Sstevel@tonic-gate char *end; 101*0Sstevel@tonic-gate long i; 102*0Sstevel@tonic-gate 103*0Sstevel@tonic-gate errno = 0; 104*0Sstevel@tonic-gate i = strtol(v + 1, &end, 10); 105*0Sstevel@tonic-gate 106*0Sstevel@tonic-gate if (i < 0 || i >= argc || 107*0Sstevel@tonic-gate errno != 0 || end != v + vlen) 108*0Sstevel@tonic-gate return (dt_set_errno(dtp, EDT_BADSPCV)); 109*0Sstevel@tonic-gate 110*0Sstevel@tonic-gate v = argv[i]; 111*0Sstevel@tonic-gate vlen = strlen(v); 112*0Sstevel@tonic-gate 113*0Sstevel@tonic-gate if (yypcb != NULL && yypcb->pcb_sargv == argv) 114*0Sstevel@tonic-gate yypcb->pcb_sflagv[i] |= DT_IDFLG_REF; 115*0Sstevel@tonic-gate 116*0Sstevel@tonic-gate } else if (vlen > 1) { 117*0Sstevel@tonic-gate char *vstr = alloca(vlen); 118*0Sstevel@tonic-gate dt_ident_t *idp; 119*0Sstevel@tonic-gate 120*0Sstevel@tonic-gate (void) strncpy(vstr, v + 1, vlen - 1); 121*0Sstevel@tonic-gate vstr[vlen - 1] = '\0'; 122*0Sstevel@tonic-gate idp = dt_idhash_lookup(dtp->dt_macros, vstr); 123*0Sstevel@tonic-gate 124*0Sstevel@tonic-gate if (idp == NULL) 125*0Sstevel@tonic-gate return (dt_set_errno(dtp, EDT_BADSPCV)); 126*0Sstevel@tonic-gate 127*0Sstevel@tonic-gate v = buf; 128*0Sstevel@tonic-gate vlen = snprintf(buf, 32, "%d", idp->di_id); 129*0Sstevel@tonic-gate 130*0Sstevel@tonic-gate } else 131*0Sstevel@tonic-gate return (dt_set_errno(dtp, EDT_BADSPCV)); 132*0Sstevel@tonic-gate } 133*0Sstevel@tonic-gate 134*0Sstevel@tonic-gate if (spec == DTRACE_PROBESPEC_NONE) 135*0Sstevel@tonic-gate return (dt_set_errno(dtp, EDT_BADSPEC)); 136*0Sstevel@tonic-gate 137*0Sstevel@tonic-gate if (len + vlen >= dtrace_probespecs[spec].dtps_len) 138*0Sstevel@tonic-gate return (dt_set_errno(dtp, ENAMETOOLONG)); 139*0Sstevel@tonic-gate 140*0Sstevel@tonic-gate off = dtrace_probespecs[spec--].dtps_offset; 141*0Sstevel@tonic-gate bcopy(q, (char *)pdp + off, len); 142*0Sstevel@tonic-gate bcopy(v, (char *)pdp + off + len, vlen); 143*0Sstevel@tonic-gate 144*0Sstevel@tonic-gate } while (--p >= s); 145*0Sstevel@tonic-gate 146*0Sstevel@tonic-gate pdp->dtpd_id = DTRACE_IDNONE; 147*0Sstevel@tonic-gate return (0); 148*0Sstevel@tonic-gate } 149*0Sstevel@tonic-gate 150*0Sstevel@tonic-gate int 151*0Sstevel@tonic-gate dtrace_str2desc(dtrace_hdl_t *dtp, dtrace_probespec_t spec, 152*0Sstevel@tonic-gate const char *s, dtrace_probedesc_t *pdp) 153*0Sstevel@tonic-gate { 154*0Sstevel@tonic-gate return (dtrace_xstr2desc(dtp, spec, s, 0, NULL, pdp)); 155*0Sstevel@tonic-gate } 156*0Sstevel@tonic-gate 157*0Sstevel@tonic-gate int 158*0Sstevel@tonic-gate dtrace_id2desc(dtrace_hdl_t *dtp, dtrace_id_t id, dtrace_probedesc_t *pdp) 159*0Sstevel@tonic-gate { 160*0Sstevel@tonic-gate bzero(pdp, sizeof (dtrace_probedesc_t)); 161*0Sstevel@tonic-gate pdp->dtpd_id = id; 162*0Sstevel@tonic-gate 163*0Sstevel@tonic-gate if (dt_ioctl(dtp, DTRACEIOC_PROBES, pdp) == -1 || 164*0Sstevel@tonic-gate pdp->dtpd_id != id) 165*0Sstevel@tonic-gate return (dt_set_errno(dtp, EDT_BADID)); 166*0Sstevel@tonic-gate 167*0Sstevel@tonic-gate return (0); 168*0Sstevel@tonic-gate } 169*0Sstevel@tonic-gate 170*0Sstevel@tonic-gate char * 171*0Sstevel@tonic-gate dtrace_desc2str(const dtrace_probedesc_t *pdp, char *buf, size_t len) 172*0Sstevel@tonic-gate { 173*0Sstevel@tonic-gate if (pdp->dtpd_id == 0) { 174*0Sstevel@tonic-gate (void) snprintf(buf, len, "%s:%s:%s:%s", pdp->dtpd_provider, 175*0Sstevel@tonic-gate pdp->dtpd_mod, pdp->dtpd_func, pdp->dtpd_name); 176*0Sstevel@tonic-gate } else 177*0Sstevel@tonic-gate (void) snprintf(buf, len, "%u", pdp->dtpd_id); 178*0Sstevel@tonic-gate 179*0Sstevel@tonic-gate return (buf); 180*0Sstevel@tonic-gate } 181*0Sstevel@tonic-gate 182*0Sstevel@tonic-gate char * 183*0Sstevel@tonic-gate dtrace_attr2str(dtrace_attribute_t attr, char *buf, size_t len) 184*0Sstevel@tonic-gate { 185*0Sstevel@tonic-gate const char *name = dtrace_stability_name(attr.dtat_name); 186*0Sstevel@tonic-gate const char *data = dtrace_stability_name(attr.dtat_data); 187*0Sstevel@tonic-gate const char *class = dtrace_class_name(attr.dtat_class); 188*0Sstevel@tonic-gate 189*0Sstevel@tonic-gate if (name == NULL || data == NULL || class == NULL) 190*0Sstevel@tonic-gate return (NULL); /* one or more invalid attributes */ 191*0Sstevel@tonic-gate 192*0Sstevel@tonic-gate (void) snprintf(buf, len, "%s/%s/%s", name, data, class); 193*0Sstevel@tonic-gate return (buf); 194*0Sstevel@tonic-gate } 195*0Sstevel@tonic-gate 196*0Sstevel@tonic-gate static char * 197*0Sstevel@tonic-gate dt_getstrattr(char *p, char **qp) 198*0Sstevel@tonic-gate { 199*0Sstevel@tonic-gate char *q; 200*0Sstevel@tonic-gate 201*0Sstevel@tonic-gate if (*p == '\0') 202*0Sstevel@tonic-gate return (NULL); 203*0Sstevel@tonic-gate 204*0Sstevel@tonic-gate if ((q = strchr(p, '/')) == NULL) 205*0Sstevel@tonic-gate q = p + strlen(p); 206*0Sstevel@tonic-gate else 207*0Sstevel@tonic-gate *q++ = '\0'; 208*0Sstevel@tonic-gate 209*0Sstevel@tonic-gate *qp = q; 210*0Sstevel@tonic-gate return (p); 211*0Sstevel@tonic-gate } 212*0Sstevel@tonic-gate 213*0Sstevel@tonic-gate int 214*0Sstevel@tonic-gate dtrace_str2attr(const char *str, dtrace_attribute_t *attr) 215*0Sstevel@tonic-gate { 216*0Sstevel@tonic-gate dtrace_stability_t s; 217*0Sstevel@tonic-gate dtrace_class_t c; 218*0Sstevel@tonic-gate char *p, *q; 219*0Sstevel@tonic-gate 220*0Sstevel@tonic-gate if (str == NULL || attr == NULL) 221*0Sstevel@tonic-gate return (-1); /* invalid function arguments */ 222*0Sstevel@tonic-gate 223*0Sstevel@tonic-gate *attr = _dtrace_maxattr; 224*0Sstevel@tonic-gate p = alloca(strlen(str) + 1); 225*0Sstevel@tonic-gate (void) strcpy(p, str); 226*0Sstevel@tonic-gate 227*0Sstevel@tonic-gate if ((p = dt_getstrattr(p, &q)) == NULL) 228*0Sstevel@tonic-gate return (0); 229*0Sstevel@tonic-gate 230*0Sstevel@tonic-gate for (s = 0; s <= DTRACE_STABILITY_MAX; s++) { 231*0Sstevel@tonic-gate if (strcasecmp(p, dtrace_stability_name(s)) == 0) { 232*0Sstevel@tonic-gate attr->dtat_name = s; 233*0Sstevel@tonic-gate break; 234*0Sstevel@tonic-gate } 235*0Sstevel@tonic-gate } 236*0Sstevel@tonic-gate 237*0Sstevel@tonic-gate if (s > DTRACE_STABILITY_MAX) 238*0Sstevel@tonic-gate return (-1); 239*0Sstevel@tonic-gate 240*0Sstevel@tonic-gate if ((p = dt_getstrattr(q, &q)) == NULL) 241*0Sstevel@tonic-gate return (0); 242*0Sstevel@tonic-gate 243*0Sstevel@tonic-gate for (s = 0; s <= DTRACE_STABILITY_MAX; s++) { 244*0Sstevel@tonic-gate if (strcasecmp(p, dtrace_stability_name(s)) == 0) { 245*0Sstevel@tonic-gate attr->dtat_data = s; 246*0Sstevel@tonic-gate break; 247*0Sstevel@tonic-gate } 248*0Sstevel@tonic-gate } 249*0Sstevel@tonic-gate 250*0Sstevel@tonic-gate if (s > DTRACE_STABILITY_MAX) 251*0Sstevel@tonic-gate return (-1); 252*0Sstevel@tonic-gate 253*0Sstevel@tonic-gate if ((p = dt_getstrattr(q, &q)) == NULL) 254*0Sstevel@tonic-gate return (0); 255*0Sstevel@tonic-gate 256*0Sstevel@tonic-gate for (c = 0; c <= DTRACE_CLASS_MAX; c++) { 257*0Sstevel@tonic-gate if (strcasecmp(p, dtrace_class_name(c)) == 0) { 258*0Sstevel@tonic-gate attr->dtat_class = c; 259*0Sstevel@tonic-gate break; 260*0Sstevel@tonic-gate } 261*0Sstevel@tonic-gate } 262*0Sstevel@tonic-gate 263*0Sstevel@tonic-gate if (c > DTRACE_CLASS_MAX || (p = dt_getstrattr(q, &q)) != NULL) 264*0Sstevel@tonic-gate return (-1); 265*0Sstevel@tonic-gate 266*0Sstevel@tonic-gate return (0); 267*0Sstevel@tonic-gate } 268*0Sstevel@tonic-gate 269*0Sstevel@tonic-gate const char * 270*0Sstevel@tonic-gate dtrace_stability_name(dtrace_stability_t s) 271*0Sstevel@tonic-gate { 272*0Sstevel@tonic-gate switch (s) { 273*0Sstevel@tonic-gate case DTRACE_STABILITY_INTERNAL: return ("Internal"); 274*0Sstevel@tonic-gate case DTRACE_STABILITY_PRIVATE: return ("Private"); 275*0Sstevel@tonic-gate case DTRACE_STABILITY_OBSOLETE: return ("Obsolete"); 276*0Sstevel@tonic-gate case DTRACE_STABILITY_EXTERNAL: return ("External"); 277*0Sstevel@tonic-gate case DTRACE_STABILITY_UNSTABLE: return ("Unstable"); 278*0Sstevel@tonic-gate case DTRACE_STABILITY_EVOLVING: return ("Evolving"); 279*0Sstevel@tonic-gate case DTRACE_STABILITY_STABLE: return ("Stable"); 280*0Sstevel@tonic-gate case DTRACE_STABILITY_STANDARD: return ("Standard"); 281*0Sstevel@tonic-gate default: return (NULL); 282*0Sstevel@tonic-gate } 283*0Sstevel@tonic-gate } 284*0Sstevel@tonic-gate 285*0Sstevel@tonic-gate const char * 286*0Sstevel@tonic-gate dtrace_class_name(dtrace_class_t c) 287*0Sstevel@tonic-gate { 288*0Sstevel@tonic-gate switch (c) { 289*0Sstevel@tonic-gate case DTRACE_CLASS_UNKNOWN: return ("Unknown"); 290*0Sstevel@tonic-gate case DTRACE_CLASS_CPU: return ("CPU"); 291*0Sstevel@tonic-gate case DTRACE_CLASS_PLATFORM: return ("Platform"); 292*0Sstevel@tonic-gate case DTRACE_CLASS_GROUP: return ("Group"); 293*0Sstevel@tonic-gate case DTRACE_CLASS_ISA: return ("ISA"); 294*0Sstevel@tonic-gate case DTRACE_CLASS_COMMON: return ("Common"); 295*0Sstevel@tonic-gate default: return (NULL); 296*0Sstevel@tonic-gate } 297*0Sstevel@tonic-gate } 298*0Sstevel@tonic-gate 299*0Sstevel@tonic-gate dtrace_attribute_t 300*0Sstevel@tonic-gate dt_attr_min(dtrace_attribute_t a1, dtrace_attribute_t a2) 301*0Sstevel@tonic-gate { 302*0Sstevel@tonic-gate dtrace_attribute_t am; 303*0Sstevel@tonic-gate 304*0Sstevel@tonic-gate am.dtat_name = MIN(a1.dtat_name, a2.dtat_name); 305*0Sstevel@tonic-gate am.dtat_data = MIN(a1.dtat_data, a2.dtat_data); 306*0Sstevel@tonic-gate am.dtat_class = MIN(a1.dtat_class, a2.dtat_class); 307*0Sstevel@tonic-gate 308*0Sstevel@tonic-gate return (am); 309*0Sstevel@tonic-gate } 310*0Sstevel@tonic-gate 311*0Sstevel@tonic-gate dtrace_attribute_t 312*0Sstevel@tonic-gate dt_attr_max(dtrace_attribute_t a1, dtrace_attribute_t a2) 313*0Sstevel@tonic-gate { 314*0Sstevel@tonic-gate dtrace_attribute_t am; 315*0Sstevel@tonic-gate 316*0Sstevel@tonic-gate am.dtat_name = MAX(a1.dtat_name, a2.dtat_name); 317*0Sstevel@tonic-gate am.dtat_data = MAX(a1.dtat_data, a2.dtat_data); 318*0Sstevel@tonic-gate am.dtat_class = MAX(a1.dtat_class, a2.dtat_class); 319*0Sstevel@tonic-gate 320*0Sstevel@tonic-gate return (am); 321*0Sstevel@tonic-gate } 322*0Sstevel@tonic-gate 323*0Sstevel@tonic-gate /* 324*0Sstevel@tonic-gate * Compare two attributes and return an integer value in the following ranges: 325*0Sstevel@tonic-gate * 326*0Sstevel@tonic-gate * <0 if any of a1's attributes are less than a2's attributes 327*0Sstevel@tonic-gate * =0 if all of a1's attributes are equal to a2's attributes 328*0Sstevel@tonic-gate * >0 if all of a1's attributes are greater than or equal to a2's attributes 329*0Sstevel@tonic-gate * 330*0Sstevel@tonic-gate * To implement this function efficiently, we subtract a2's attributes from 331*0Sstevel@tonic-gate * a1's to obtain a negative result if an a1 attribute is less than its a2 332*0Sstevel@tonic-gate * counterpart. We then OR the intermediate results together, relying on the 333*0Sstevel@tonic-gate * twos-complement property that if any result is negative, the bitwise union 334*0Sstevel@tonic-gate * will also be negative since the highest bit will be set in the result. 335*0Sstevel@tonic-gate */ 336*0Sstevel@tonic-gate int 337*0Sstevel@tonic-gate dt_attr_cmp(dtrace_attribute_t a1, dtrace_attribute_t a2) 338*0Sstevel@tonic-gate { 339*0Sstevel@tonic-gate return (((int)a1.dtat_name - a2.dtat_name) | 340*0Sstevel@tonic-gate ((int)a1.dtat_data - a2.dtat_data) | 341*0Sstevel@tonic-gate ((int)a1.dtat_class - a2.dtat_class)); 342*0Sstevel@tonic-gate } 343*0Sstevel@tonic-gate 344*0Sstevel@tonic-gate char * 345*0Sstevel@tonic-gate dt_attr_str(dtrace_attribute_t a, char *buf, size_t len) 346*0Sstevel@tonic-gate { 347*0Sstevel@tonic-gate static const char stability[] = "ipoxuesS"; 348*0Sstevel@tonic-gate static const char class[] = "uCpgIc"; 349*0Sstevel@tonic-gate 350*0Sstevel@tonic-gate if (a.dtat_name < sizeof (stability) && 351*0Sstevel@tonic-gate a.dtat_data < sizeof (stability) && a.dtat_class < sizeof (class)) { 352*0Sstevel@tonic-gate (void) snprintf(buf, len, "[%c/%c/%c]", stability[a.dtat_name], 353*0Sstevel@tonic-gate stability[a.dtat_data], class[a.dtat_class]); 354*0Sstevel@tonic-gate } else { 355*0Sstevel@tonic-gate (void) snprintf(buf, len, "[%u/%u/%u]", 356*0Sstevel@tonic-gate a.dtat_name, a.dtat_data, a.dtat_class); 357*0Sstevel@tonic-gate } 358*0Sstevel@tonic-gate 359*0Sstevel@tonic-gate return (buf); 360*0Sstevel@tonic-gate } 361*0Sstevel@tonic-gate 362*0Sstevel@tonic-gate char * 363*0Sstevel@tonic-gate dt_version_num2str(dt_version_t v, char *buf, size_t len) 364*0Sstevel@tonic-gate { 365*0Sstevel@tonic-gate uint_t M = DT_VERSION_MAJOR(v); 366*0Sstevel@tonic-gate uint_t m = DT_VERSION_MINOR(v); 367*0Sstevel@tonic-gate uint_t u = DT_VERSION_MICRO(v); 368*0Sstevel@tonic-gate 369*0Sstevel@tonic-gate if (u == 0) 370*0Sstevel@tonic-gate (void) snprintf(buf, len, "%u.%u", M, m); 371*0Sstevel@tonic-gate else 372*0Sstevel@tonic-gate (void) snprintf(buf, len, "%u.%u.%u", M, m, u); 373*0Sstevel@tonic-gate 374*0Sstevel@tonic-gate return (buf); 375*0Sstevel@tonic-gate } 376*0Sstevel@tonic-gate 377*0Sstevel@tonic-gate int 378*0Sstevel@tonic-gate dt_version_str2num(const char *s, dt_version_t *vp) 379*0Sstevel@tonic-gate { 380*0Sstevel@tonic-gate int i = 0, n[3] = { 0, 0, 0 }; 381*0Sstevel@tonic-gate char c; 382*0Sstevel@tonic-gate 383*0Sstevel@tonic-gate while ((c = *s++) != '\0') { 384*0Sstevel@tonic-gate if (isdigit(c)) 385*0Sstevel@tonic-gate n[i] = n[i] * 10 + c - '0'; 386*0Sstevel@tonic-gate else if (c != '.' || i++ >= sizeof (n) / sizeof (n[0]) - 1) 387*0Sstevel@tonic-gate return (-1); 388*0Sstevel@tonic-gate } 389*0Sstevel@tonic-gate 390*0Sstevel@tonic-gate if (n[0] > DT_VERSION_MAJMAX || 391*0Sstevel@tonic-gate n[1] > DT_VERSION_MINMAX || 392*0Sstevel@tonic-gate n[2] > DT_VERSION_MICMAX) 393*0Sstevel@tonic-gate return (-1); 394*0Sstevel@tonic-gate 395*0Sstevel@tonic-gate if (vp != NULL) 396*0Sstevel@tonic-gate *vp = DT_VERSION_NUMBER(n[0], n[1], n[2]); 397*0Sstevel@tonic-gate 398*0Sstevel@tonic-gate return (0); 399*0Sstevel@tonic-gate } 400*0Sstevel@tonic-gate 401*0Sstevel@tonic-gate int 402*0Sstevel@tonic-gate dt_version_defined(dt_version_t v) 403*0Sstevel@tonic-gate { 404*0Sstevel@tonic-gate int i; 405*0Sstevel@tonic-gate 406*0Sstevel@tonic-gate for (i = 0; _dtrace_versions[i] != 0; i++) { 407*0Sstevel@tonic-gate if (_dtrace_versions[i] == v) 408*0Sstevel@tonic-gate return (1); 409*0Sstevel@tonic-gate } 410*0Sstevel@tonic-gate 411*0Sstevel@tonic-gate return (0); 412*0Sstevel@tonic-gate } 413*0Sstevel@tonic-gate 414*0Sstevel@tonic-gate char * 415*0Sstevel@tonic-gate dt_cpp_add_arg(dtrace_hdl_t *dtp, const char *str) 416*0Sstevel@tonic-gate { 417*0Sstevel@tonic-gate char *arg; 418*0Sstevel@tonic-gate 419*0Sstevel@tonic-gate if (dtp->dt_cpp_argc == dtp->dt_cpp_args) { 420*0Sstevel@tonic-gate int olds = dtp->dt_cpp_args; 421*0Sstevel@tonic-gate int news = olds * 2; 422*0Sstevel@tonic-gate char **argv = realloc(dtp->dt_cpp_argv, sizeof (char *) * news); 423*0Sstevel@tonic-gate 424*0Sstevel@tonic-gate if (argv == NULL) 425*0Sstevel@tonic-gate return (NULL); 426*0Sstevel@tonic-gate 427*0Sstevel@tonic-gate bzero(&argv[olds], sizeof (char *) * olds); 428*0Sstevel@tonic-gate dtp->dt_cpp_argv = argv; 429*0Sstevel@tonic-gate dtp->dt_cpp_args = news; 430*0Sstevel@tonic-gate } 431*0Sstevel@tonic-gate 432*0Sstevel@tonic-gate if ((arg = strdup(str)) == NULL) 433*0Sstevel@tonic-gate return (NULL); 434*0Sstevel@tonic-gate 435*0Sstevel@tonic-gate assert(dtp->dt_cpp_argc < dtp->dt_cpp_args); 436*0Sstevel@tonic-gate dtp->dt_cpp_argv[dtp->dt_cpp_argc++] = arg; 437*0Sstevel@tonic-gate return (arg); 438*0Sstevel@tonic-gate } 439*0Sstevel@tonic-gate 440*0Sstevel@tonic-gate char * 441*0Sstevel@tonic-gate dt_cpp_pop_arg(dtrace_hdl_t *dtp) 442*0Sstevel@tonic-gate { 443*0Sstevel@tonic-gate char *arg; 444*0Sstevel@tonic-gate 445*0Sstevel@tonic-gate if (dtp->dt_cpp_argc <= 1) 446*0Sstevel@tonic-gate return (NULL); /* dt_cpp_argv[0] cannot be popped */ 447*0Sstevel@tonic-gate 448*0Sstevel@tonic-gate arg = dtp->dt_cpp_argv[--dtp->dt_cpp_argc]; 449*0Sstevel@tonic-gate dtp->dt_cpp_argv[dtp->dt_cpp_argc] = NULL; 450*0Sstevel@tonic-gate 451*0Sstevel@tonic-gate return (arg); 452*0Sstevel@tonic-gate } 453*0Sstevel@tonic-gate 454*0Sstevel@tonic-gate /*PRINTFLIKE1*/ 455*0Sstevel@tonic-gate void 456*0Sstevel@tonic-gate dt_dprintf(const char *format, ...) 457*0Sstevel@tonic-gate { 458*0Sstevel@tonic-gate if (_dtrace_debug) { 459*0Sstevel@tonic-gate va_list alist; 460*0Sstevel@tonic-gate 461*0Sstevel@tonic-gate va_start(alist, format); 462*0Sstevel@tonic-gate (void) fputs("libdtrace DEBUG: ", stderr); 463*0Sstevel@tonic-gate (void) vfprintf(stderr, format, alist); 464*0Sstevel@tonic-gate va_end(alist); 465*0Sstevel@tonic-gate } 466*0Sstevel@tonic-gate } 467*0Sstevel@tonic-gate 468*0Sstevel@tonic-gate int 469*0Sstevel@tonic-gate dt_ioctl(dtrace_hdl_t *dtp, int val, void *arg) 470*0Sstevel@tonic-gate { 471*0Sstevel@tonic-gate const dtrace_vector_t *v = dtp->dt_vector; 472*0Sstevel@tonic-gate 473*0Sstevel@tonic-gate if (v != NULL) 474*0Sstevel@tonic-gate return (v->dtv_ioctl(dtp->dt_varg, val, arg)); 475*0Sstevel@tonic-gate 476*0Sstevel@tonic-gate if (dtp->dt_fd >= 0) 477*0Sstevel@tonic-gate return (ioctl(dtp->dt_fd, val, arg)); 478*0Sstevel@tonic-gate 479*0Sstevel@tonic-gate errno = EBADF; 480*0Sstevel@tonic-gate return (-1); 481*0Sstevel@tonic-gate } 482*0Sstevel@tonic-gate 483*0Sstevel@tonic-gate int 484*0Sstevel@tonic-gate dt_status(dtrace_hdl_t *dtp, processorid_t cpu) 485*0Sstevel@tonic-gate { 486*0Sstevel@tonic-gate const dtrace_vector_t *v = dtp->dt_vector; 487*0Sstevel@tonic-gate 488*0Sstevel@tonic-gate if (v == NULL) 489*0Sstevel@tonic-gate return (p_online(cpu, P_STATUS)); 490*0Sstevel@tonic-gate 491*0Sstevel@tonic-gate return (v->dtv_status(dtp->dt_varg, cpu)); 492*0Sstevel@tonic-gate } 493*0Sstevel@tonic-gate 494*0Sstevel@tonic-gate long 495*0Sstevel@tonic-gate dt_sysconf(dtrace_hdl_t *dtp, int name) 496*0Sstevel@tonic-gate { 497*0Sstevel@tonic-gate const dtrace_vector_t *v = dtp->dt_vector; 498*0Sstevel@tonic-gate 499*0Sstevel@tonic-gate if (v == NULL) 500*0Sstevel@tonic-gate return (sysconf(name)); 501*0Sstevel@tonic-gate 502*0Sstevel@tonic-gate return (v->dtv_sysconf(dtp->dt_varg, name)); 503*0Sstevel@tonic-gate } 504*0Sstevel@tonic-gate 505*0Sstevel@tonic-gate /* 506*0Sstevel@tonic-gate * Wrapper around write(2) to handle partial writes. For maximum safety of 507*0Sstevel@tonic-gate * output files and proper error reporting, we continuing writing in the 508*0Sstevel@tonic-gate * face of partial writes until write(2) fails or 'buf' is completely written. 509*0Sstevel@tonic-gate * We also record any errno in the specified dtrace_hdl_t as well as 'errno'. 510*0Sstevel@tonic-gate */ 511*0Sstevel@tonic-gate ssize_t 512*0Sstevel@tonic-gate dt_write(dtrace_hdl_t *dtp, int fd, const void *buf, size_t n) 513*0Sstevel@tonic-gate { 514*0Sstevel@tonic-gate ssize_t resid = n; 515*0Sstevel@tonic-gate ssize_t len; 516*0Sstevel@tonic-gate 517*0Sstevel@tonic-gate while (resid != 0) { 518*0Sstevel@tonic-gate if ((len = write(fd, buf, resid)) <= 0) 519*0Sstevel@tonic-gate break; 520*0Sstevel@tonic-gate 521*0Sstevel@tonic-gate resid -= len; 522*0Sstevel@tonic-gate buf = (char *)buf + len; 523*0Sstevel@tonic-gate } 524*0Sstevel@tonic-gate 525*0Sstevel@tonic-gate if (resid == n && n != 0) 526*0Sstevel@tonic-gate return (dt_set_errno(dtp, errno)); 527*0Sstevel@tonic-gate 528*0Sstevel@tonic-gate return (n - resid); 529*0Sstevel@tonic-gate } 530*0Sstevel@tonic-gate 531*0Sstevel@tonic-gate /* 532*0Sstevel@tonic-gate * This function handles all output from libdtrace, as well as the 533*0Sstevel@tonic-gate * dtrace_sprintf() case. If we're here due to dtrace_sprintf(), then 534*0Sstevel@tonic-gate * dt_sprintf_buflen will be non-zero; in this case, we sprintf into the 535*0Sstevel@tonic-gate * specified buffer and return. Otherwise, if output is buffered (denoted by 536*0Sstevel@tonic-gate * a NULL fp), we sprintf the desired output into the buffered buffer 537*0Sstevel@tonic-gate * (expanding the buffer if required). If we don't satisfy either of these 538*0Sstevel@tonic-gate * conditions (that is, if we are to actually generate output), then we call 539*0Sstevel@tonic-gate * fprintf with the specified fp. In this case, we need to deal with one of 540*0Sstevel@tonic-gate * the more annoying peculiarities of libc's printf routines: any failed 541*0Sstevel@tonic-gate * write persistently sets an error flag inside the FILE causing every 542*0Sstevel@tonic-gate * subsequent write to fail, but only the caller that initiated the error gets 543*0Sstevel@tonic-gate * the errno. Since libdtrace clients often intercept SIGINT, this case is 544*0Sstevel@tonic-gate * particularly frustrating since we don't want the EINTR on one attempt to 545*0Sstevel@tonic-gate * write to the output file to preclude later attempts to write. This 546*0Sstevel@tonic-gate * function therefore does a clearerr() if any error occurred, and saves the 547*0Sstevel@tonic-gate * errno for the caller inside the specified dtrace_hdl_t. 548*0Sstevel@tonic-gate */ 549*0Sstevel@tonic-gate /*PRINTFLIKE3*/ 550*0Sstevel@tonic-gate int 551*0Sstevel@tonic-gate dt_printf(dtrace_hdl_t *dtp, FILE *fp, const char *format, ...) 552*0Sstevel@tonic-gate { 553*0Sstevel@tonic-gate va_list ap; 554*0Sstevel@tonic-gate int n; 555*0Sstevel@tonic-gate 556*0Sstevel@tonic-gate va_start(ap, format); 557*0Sstevel@tonic-gate 558*0Sstevel@tonic-gate if (dtp->dt_sprintf_buflen != 0) { 559*0Sstevel@tonic-gate int len; 560*0Sstevel@tonic-gate char *buf; 561*0Sstevel@tonic-gate 562*0Sstevel@tonic-gate assert(dtp->dt_sprintf_buf != NULL); 563*0Sstevel@tonic-gate 564*0Sstevel@tonic-gate buf = &dtp->dt_sprintf_buf[len = strlen(dtp->dt_sprintf_buf)]; 565*0Sstevel@tonic-gate len = dtp->dt_sprintf_buflen - len; 566*0Sstevel@tonic-gate assert(len >= 0); 567*0Sstevel@tonic-gate 568*0Sstevel@tonic-gate if ((n = vsnprintf(buf, len, format, ap)) < 0) 569*0Sstevel@tonic-gate n = dt_set_errno(dtp, errno); 570*0Sstevel@tonic-gate 571*0Sstevel@tonic-gate va_end(ap); 572*0Sstevel@tonic-gate 573*0Sstevel@tonic-gate return (n); 574*0Sstevel@tonic-gate } 575*0Sstevel@tonic-gate 576*0Sstevel@tonic-gate if (fp == NULL) { 577*0Sstevel@tonic-gate int needed, rval; 578*0Sstevel@tonic-gate size_t avail; 579*0Sstevel@tonic-gate 580*0Sstevel@tonic-gate /* 581*0Sstevel@tonic-gate * It's not legal to use buffered ouput if there is not a 582*0Sstevel@tonic-gate * handler for buffered output. 583*0Sstevel@tonic-gate */ 584*0Sstevel@tonic-gate if (dtp->dt_bufhdlr == NULL) { 585*0Sstevel@tonic-gate va_end(ap); 586*0Sstevel@tonic-gate return (dt_set_errno(dtp, EDT_NOBUFFERED)); 587*0Sstevel@tonic-gate } 588*0Sstevel@tonic-gate 589*0Sstevel@tonic-gate if (dtp->dt_buffered_buf == NULL) { 590*0Sstevel@tonic-gate assert(dtp->dt_buffered_size == 0); 591*0Sstevel@tonic-gate dtp->dt_buffered_size = 1; 592*0Sstevel@tonic-gate dtp->dt_buffered_buf = malloc(dtp->dt_buffered_size); 593*0Sstevel@tonic-gate 594*0Sstevel@tonic-gate if (dtp->dt_buffered_buf == NULL) { 595*0Sstevel@tonic-gate va_end(ap); 596*0Sstevel@tonic-gate return (dt_set_errno(dtp, EDT_NOMEM)); 597*0Sstevel@tonic-gate } 598*0Sstevel@tonic-gate 599*0Sstevel@tonic-gate dtp->dt_buffered_offs = 0; 600*0Sstevel@tonic-gate dtp->dt_buffered_buf[0] = '\0'; 601*0Sstevel@tonic-gate } 602*0Sstevel@tonic-gate 603*0Sstevel@tonic-gate if ((needed = vsnprintf(NULL, 0, format, ap)) < 0) { 604*0Sstevel@tonic-gate rval = dt_set_errno(dtp, errno); 605*0Sstevel@tonic-gate va_end(ap); 606*0Sstevel@tonic-gate return (rval); 607*0Sstevel@tonic-gate } 608*0Sstevel@tonic-gate 609*0Sstevel@tonic-gate if (needed == 0) { 610*0Sstevel@tonic-gate va_end(ap); 611*0Sstevel@tonic-gate return (0); 612*0Sstevel@tonic-gate } 613*0Sstevel@tonic-gate 614*0Sstevel@tonic-gate for (;;) { 615*0Sstevel@tonic-gate char *newbuf; 616*0Sstevel@tonic-gate 617*0Sstevel@tonic-gate assert(dtp->dt_buffered_offs < dtp->dt_buffered_size); 618*0Sstevel@tonic-gate avail = dtp->dt_buffered_size - dtp->dt_buffered_offs; 619*0Sstevel@tonic-gate 620*0Sstevel@tonic-gate if (needed + 1 < avail) 621*0Sstevel@tonic-gate break; 622*0Sstevel@tonic-gate 623*0Sstevel@tonic-gate if ((newbuf = realloc(dtp->dt_buffered_buf, 624*0Sstevel@tonic-gate dtp->dt_buffered_size << 1)) == NULL) { 625*0Sstevel@tonic-gate va_end(ap); 626*0Sstevel@tonic-gate return (dt_set_errno(dtp, EDT_NOMEM)); 627*0Sstevel@tonic-gate } 628*0Sstevel@tonic-gate 629*0Sstevel@tonic-gate dtp->dt_buffered_buf = newbuf; 630*0Sstevel@tonic-gate dtp->dt_buffered_size <<= 1; 631*0Sstevel@tonic-gate } 632*0Sstevel@tonic-gate 633*0Sstevel@tonic-gate if (vsnprintf(&dtp->dt_buffered_buf[dtp->dt_buffered_offs], 634*0Sstevel@tonic-gate avail, format, ap) < 0) { 635*0Sstevel@tonic-gate rval = dt_set_errno(dtp, errno); 636*0Sstevel@tonic-gate va_end(ap); 637*0Sstevel@tonic-gate return (rval); 638*0Sstevel@tonic-gate } 639*0Sstevel@tonic-gate 640*0Sstevel@tonic-gate dtp->dt_buffered_offs += needed; 641*0Sstevel@tonic-gate assert(dtp->dt_buffered_buf[dtp->dt_buffered_offs] == '\0'); 642*0Sstevel@tonic-gate return (0); 643*0Sstevel@tonic-gate } 644*0Sstevel@tonic-gate 645*0Sstevel@tonic-gate n = vfprintf(fp, format, ap); 646*0Sstevel@tonic-gate va_end(ap); 647*0Sstevel@tonic-gate 648*0Sstevel@tonic-gate if (n < 0) { 649*0Sstevel@tonic-gate clearerr(fp); 650*0Sstevel@tonic-gate return (dt_set_errno(dtp, errno)); 651*0Sstevel@tonic-gate } 652*0Sstevel@tonic-gate 653*0Sstevel@tonic-gate return (n); 654*0Sstevel@tonic-gate } 655*0Sstevel@tonic-gate 656*0Sstevel@tonic-gate int 657*0Sstevel@tonic-gate dt_buffered_flush(dtrace_hdl_t *dtp, dtrace_probedata_t *pdata, 658*0Sstevel@tonic-gate dtrace_recdesc_t *rec, dtrace_aggdata_t *agg) 659*0Sstevel@tonic-gate { 660*0Sstevel@tonic-gate dtrace_bufdata_t data; 661*0Sstevel@tonic-gate 662*0Sstevel@tonic-gate if (dtp->dt_buffered_offs == 0) 663*0Sstevel@tonic-gate return (0); 664*0Sstevel@tonic-gate 665*0Sstevel@tonic-gate data.dtbda_handle = dtp; 666*0Sstevel@tonic-gate data.dtbda_buffered = dtp->dt_buffered_buf; 667*0Sstevel@tonic-gate data.dtbda_probe = pdata; 668*0Sstevel@tonic-gate data.dtbda_recdesc = rec; 669*0Sstevel@tonic-gate data.dtbda_aggdata = agg; 670*0Sstevel@tonic-gate 671*0Sstevel@tonic-gate if ((*dtp->dt_bufhdlr)(&data, dtp->dt_bufarg) == DTRACE_HANDLE_ABORT) 672*0Sstevel@tonic-gate return (dt_set_errno(dtp, EDT_DIRABORT)); 673*0Sstevel@tonic-gate 674*0Sstevel@tonic-gate dtp->dt_buffered_offs = 0; 675*0Sstevel@tonic-gate dtp->dt_buffered_buf[0] = '\0'; 676*0Sstevel@tonic-gate 677*0Sstevel@tonic-gate return (0); 678*0Sstevel@tonic-gate } 679*0Sstevel@tonic-gate 680*0Sstevel@tonic-gate void 681*0Sstevel@tonic-gate dt_buffered_destroy(dtrace_hdl_t *dtp) 682*0Sstevel@tonic-gate { 683*0Sstevel@tonic-gate free(dtp->dt_buffered_buf); 684*0Sstevel@tonic-gate dtp->dt_buffered_buf = NULL; 685*0Sstevel@tonic-gate dtp->dt_buffered_offs = 0; 686*0Sstevel@tonic-gate dtp->dt_buffered_size = 0; 687*0Sstevel@tonic-gate } 688*0Sstevel@tonic-gate 689*0Sstevel@tonic-gate void * 690*0Sstevel@tonic-gate dt_zalloc(dtrace_hdl_t *dtp, size_t size) 691*0Sstevel@tonic-gate { 692*0Sstevel@tonic-gate void *data; 693*0Sstevel@tonic-gate 694*0Sstevel@tonic-gate if ((data = malloc(size)) == NULL) 695*0Sstevel@tonic-gate (void) dt_set_errno(dtp, EDT_NOMEM); 696*0Sstevel@tonic-gate else 697*0Sstevel@tonic-gate bzero(data, size); 698*0Sstevel@tonic-gate 699*0Sstevel@tonic-gate return (data); 700*0Sstevel@tonic-gate } 701*0Sstevel@tonic-gate 702*0Sstevel@tonic-gate void * 703*0Sstevel@tonic-gate dt_alloc(dtrace_hdl_t *dtp, size_t size) 704*0Sstevel@tonic-gate { 705*0Sstevel@tonic-gate void *data; 706*0Sstevel@tonic-gate 707*0Sstevel@tonic-gate if ((data = malloc(size)) == NULL) 708*0Sstevel@tonic-gate (void) dt_set_errno(dtp, EDT_NOMEM); 709*0Sstevel@tonic-gate 710*0Sstevel@tonic-gate return (data); 711*0Sstevel@tonic-gate } 712*0Sstevel@tonic-gate 713*0Sstevel@tonic-gate void 714*0Sstevel@tonic-gate dt_free(dtrace_hdl_t *dtp, void *data) 715*0Sstevel@tonic-gate { 716*0Sstevel@tonic-gate assert(dtp != NULL); /* ensure sane use of this interface */ 717*0Sstevel@tonic-gate free(data); 718*0Sstevel@tonic-gate } 719*0Sstevel@tonic-gate 720*0Sstevel@tonic-gate /* 721*0Sstevel@tonic-gate * dt_gmatch() is similar to gmatch(3GEN) and dtrace(7D) globbing, but also 722*0Sstevel@tonic-gate * implements the behavior that an empty pattern matches any string. 723*0Sstevel@tonic-gate */ 724*0Sstevel@tonic-gate int 725*0Sstevel@tonic-gate dt_gmatch(const char *s, const char *p) 726*0Sstevel@tonic-gate { 727*0Sstevel@tonic-gate return (p == NULL || *p == '\0' || gmatch(s, p)); 728*0Sstevel@tonic-gate } 729*0Sstevel@tonic-gate 730*0Sstevel@tonic-gate char * 731*0Sstevel@tonic-gate dt_basename(char *str) 732*0Sstevel@tonic-gate { 733*0Sstevel@tonic-gate char *last = strrchr(str, '/'); 734*0Sstevel@tonic-gate 735*0Sstevel@tonic-gate if (last == NULL) 736*0Sstevel@tonic-gate return (str); 737*0Sstevel@tonic-gate 738*0Sstevel@tonic-gate return (last + 1); 739*0Sstevel@tonic-gate } 740*0Sstevel@tonic-gate 741*0Sstevel@tonic-gate struct _rwlock; 742*0Sstevel@tonic-gate struct _lwp_mutex; 743*0Sstevel@tonic-gate 744*0Sstevel@tonic-gate int 745*0Sstevel@tonic-gate dt_rw_read_held(pthread_rwlock_t *lock) 746*0Sstevel@tonic-gate { 747*0Sstevel@tonic-gate extern int _rw_read_held(struct _rwlock *); 748*0Sstevel@tonic-gate return (_rw_read_held((struct _rwlock *)lock)); 749*0Sstevel@tonic-gate } 750*0Sstevel@tonic-gate 751*0Sstevel@tonic-gate int 752*0Sstevel@tonic-gate dt_rw_write_held(pthread_rwlock_t *lock) 753*0Sstevel@tonic-gate { 754*0Sstevel@tonic-gate extern int _rw_write_held(struct _rwlock *); 755*0Sstevel@tonic-gate return (_rw_write_held((struct _rwlock *)lock)); 756*0Sstevel@tonic-gate } 757*0Sstevel@tonic-gate 758*0Sstevel@tonic-gate int 759*0Sstevel@tonic-gate dt_mutex_held(pthread_mutex_t *lock) 760*0Sstevel@tonic-gate { 761*0Sstevel@tonic-gate extern int _mutex_held(struct _lwp_mutex *); 762*0Sstevel@tonic-gate return (_mutex_held((struct _lwp_mutex *)lock)); 763*0Sstevel@tonic-gate } 764