1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate #include <sys/modctl.h> 30*7c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 31*7c478bd9Sstevel@tonic-gate #include <sys/dtrace.h> 32*7c478bd9Sstevel@tonic-gate #include <sys/kobj.h> 33*7c478bd9Sstevel@tonic-gate #include <sys/stat.h> 34*7c478bd9Sstevel@tonic-gate #include <sys/conf.h> 35*7c478bd9Sstevel@tonic-gate #include <vm/seg_kmem.h> 36*7c478bd9Sstevel@tonic-gate #include <sys/stack.h> 37*7c478bd9Sstevel@tonic-gate #include <sys/sdt_impl.h> 38*7c478bd9Sstevel@tonic-gate 39*7c478bd9Sstevel@tonic-gate #define SDT_PATCHVAL 0xf0 40*7c478bd9Sstevel@tonic-gate #define SDT_ADDR2NDX(addr) ((((uintptr_t)(addr)) >> 4) & sdt_probetab_mask) 41*7c478bd9Sstevel@tonic-gate #define SDT_PROBETAB_SIZE 0x1000 /* 4k entries -- 16K total */ 42*7c478bd9Sstevel@tonic-gate 43*7c478bd9Sstevel@tonic-gate static dev_info_t *sdt_devi; 44*7c478bd9Sstevel@tonic-gate static int sdt_verbose = 0; 45*7c478bd9Sstevel@tonic-gate static sdt_probe_t **sdt_probetab; 46*7c478bd9Sstevel@tonic-gate static int sdt_probetab_size; 47*7c478bd9Sstevel@tonic-gate static int sdt_probetab_mask; 48*7c478bd9Sstevel@tonic-gate 49*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 50*7c478bd9Sstevel@tonic-gate static int 51*7c478bd9Sstevel@tonic-gate sdt_invop(uintptr_t addr, uintptr_t *stack, uintptr_t eax) 52*7c478bd9Sstevel@tonic-gate { 53*7c478bd9Sstevel@tonic-gate uintptr_t stack0, stack1, stack2, stack3, stack4; 54*7c478bd9Sstevel@tonic-gate int i = 0; 55*7c478bd9Sstevel@tonic-gate sdt_probe_t *sdt = sdt_probetab[SDT_ADDR2NDX(addr)]; 56*7c478bd9Sstevel@tonic-gate 57*7c478bd9Sstevel@tonic-gate #ifdef __amd64 58*7c478bd9Sstevel@tonic-gate /* 59*7c478bd9Sstevel@tonic-gate * On amd64, stack[0] contains the dereferenced stack pointer, 60*7c478bd9Sstevel@tonic-gate * stack[1] contains savfp, stack[2] contains savpc. We want 61*7c478bd9Sstevel@tonic-gate * to step over these entries. 62*7c478bd9Sstevel@tonic-gate */ 63*7c478bd9Sstevel@tonic-gate i += 3; 64*7c478bd9Sstevel@tonic-gate #endif 65*7c478bd9Sstevel@tonic-gate 66*7c478bd9Sstevel@tonic-gate for (; sdt != NULL; sdt = sdt->sdp_hashnext) { 67*7c478bd9Sstevel@tonic-gate if ((uintptr_t)sdt->sdp_patchpoint == addr) { 68*7c478bd9Sstevel@tonic-gate /* 69*7c478bd9Sstevel@tonic-gate * When accessing the arguments on the stack, we must 70*7c478bd9Sstevel@tonic-gate * protect against accessing beyond the stack. We can 71*7c478bd9Sstevel@tonic-gate * safely set NOFAULT here -- we know that interrupts 72*7c478bd9Sstevel@tonic-gate * are already disabled. 73*7c478bd9Sstevel@tonic-gate */ 74*7c478bd9Sstevel@tonic-gate DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT); 75*7c478bd9Sstevel@tonic-gate stack0 = stack[i++]; 76*7c478bd9Sstevel@tonic-gate stack1 = stack[i++]; 77*7c478bd9Sstevel@tonic-gate stack2 = stack[i++]; 78*7c478bd9Sstevel@tonic-gate stack3 = stack[i++]; 79*7c478bd9Sstevel@tonic-gate stack4 = stack[i++]; 80*7c478bd9Sstevel@tonic-gate DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT | 81*7c478bd9Sstevel@tonic-gate CPU_DTRACE_BADADDR); 82*7c478bd9Sstevel@tonic-gate 83*7c478bd9Sstevel@tonic-gate dtrace_probe(sdt->sdp_id, stack0, stack1, 84*7c478bd9Sstevel@tonic-gate stack2, stack3, stack4); 85*7c478bd9Sstevel@tonic-gate 86*7c478bd9Sstevel@tonic-gate return (DTRACE_INVOP_NOP); 87*7c478bd9Sstevel@tonic-gate } 88*7c478bd9Sstevel@tonic-gate } 89*7c478bd9Sstevel@tonic-gate 90*7c478bd9Sstevel@tonic-gate return (0); 91*7c478bd9Sstevel@tonic-gate } 92*7c478bd9Sstevel@tonic-gate 93*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 94*7c478bd9Sstevel@tonic-gate static void 95*7c478bd9Sstevel@tonic-gate sdt_provide_module(void *arg, struct modctl *ctl) 96*7c478bd9Sstevel@tonic-gate { 97*7c478bd9Sstevel@tonic-gate struct module *mp = ctl->mod_mp; 98*7c478bd9Sstevel@tonic-gate char *modname = ctl->mod_modname; 99*7c478bd9Sstevel@tonic-gate sdt_probedesc_t *sdpd; 100*7c478bd9Sstevel@tonic-gate sdt_probe_t *sdp, *old; 101*7c478bd9Sstevel@tonic-gate sdt_provider_t *prov; 102*7c478bd9Sstevel@tonic-gate int len; 103*7c478bd9Sstevel@tonic-gate 104*7c478bd9Sstevel@tonic-gate /* 105*7c478bd9Sstevel@tonic-gate * One for all, and all for one: if we haven't yet registered all of 106*7c478bd9Sstevel@tonic-gate * our providers, we'll refuse to provide anything. 107*7c478bd9Sstevel@tonic-gate */ 108*7c478bd9Sstevel@tonic-gate for (prov = sdt_providers; prov->sdtp_name != NULL; prov++) { 109*7c478bd9Sstevel@tonic-gate if (prov->sdtp_id == DTRACE_PROVNONE) 110*7c478bd9Sstevel@tonic-gate return; 111*7c478bd9Sstevel@tonic-gate } 112*7c478bd9Sstevel@tonic-gate 113*7c478bd9Sstevel@tonic-gate if (mp->sdt_nprobes != 0 || (sdpd = mp->sdt_probes) == NULL) 114*7c478bd9Sstevel@tonic-gate return; 115*7c478bd9Sstevel@tonic-gate 116*7c478bd9Sstevel@tonic-gate for (sdpd = mp->sdt_probes; sdpd != NULL; sdpd = sdpd->sdpd_next) { 117*7c478bd9Sstevel@tonic-gate char *name = sdpd->sdpd_name, *func, *nname; 118*7c478bd9Sstevel@tonic-gate int i, j; 119*7c478bd9Sstevel@tonic-gate sdt_provider_t *prov; 120*7c478bd9Sstevel@tonic-gate ulong_t offs; 121*7c478bd9Sstevel@tonic-gate dtrace_id_t id; 122*7c478bd9Sstevel@tonic-gate 123*7c478bd9Sstevel@tonic-gate for (prov = sdt_providers; prov->sdtp_prefix != NULL; prov++) { 124*7c478bd9Sstevel@tonic-gate char *prefix = prov->sdtp_prefix; 125*7c478bd9Sstevel@tonic-gate 126*7c478bd9Sstevel@tonic-gate if (strncmp(name, prefix, strlen(prefix)) == 0) { 127*7c478bd9Sstevel@tonic-gate name += strlen(prefix); 128*7c478bd9Sstevel@tonic-gate break; 129*7c478bd9Sstevel@tonic-gate } 130*7c478bd9Sstevel@tonic-gate } 131*7c478bd9Sstevel@tonic-gate 132*7c478bd9Sstevel@tonic-gate nname = kmem_alloc(len = strlen(name) + 1, KM_SLEEP); 133*7c478bd9Sstevel@tonic-gate 134*7c478bd9Sstevel@tonic-gate for (i = 0, j = 0; name[j] != '\0'; i++) { 135*7c478bd9Sstevel@tonic-gate if (name[j] == '_' && name[j + 1] == '_') { 136*7c478bd9Sstevel@tonic-gate nname[i] = '-'; 137*7c478bd9Sstevel@tonic-gate j += 2; 138*7c478bd9Sstevel@tonic-gate } else { 139*7c478bd9Sstevel@tonic-gate nname[i] = name[j++]; 140*7c478bd9Sstevel@tonic-gate } 141*7c478bd9Sstevel@tonic-gate } 142*7c478bd9Sstevel@tonic-gate 143*7c478bd9Sstevel@tonic-gate nname[i] = '\0'; 144*7c478bd9Sstevel@tonic-gate 145*7c478bd9Sstevel@tonic-gate sdp = kmem_zalloc(sizeof (sdt_probe_t), KM_SLEEP); 146*7c478bd9Sstevel@tonic-gate sdp->sdp_loadcnt = ctl->mod_loadcnt; 147*7c478bd9Sstevel@tonic-gate sdp->sdp_ctl = ctl; 148*7c478bd9Sstevel@tonic-gate sdp->sdp_name = nname; 149*7c478bd9Sstevel@tonic-gate sdp->sdp_namelen = len; 150*7c478bd9Sstevel@tonic-gate sdp->sdp_provider = prov; 151*7c478bd9Sstevel@tonic-gate 152*7c478bd9Sstevel@tonic-gate func = kobj_searchsym(mp, sdpd->sdpd_offset, &offs); 153*7c478bd9Sstevel@tonic-gate 154*7c478bd9Sstevel@tonic-gate if (func == NULL) 155*7c478bd9Sstevel@tonic-gate func = "<unknown>"; 156*7c478bd9Sstevel@tonic-gate 157*7c478bd9Sstevel@tonic-gate /* 158*7c478bd9Sstevel@tonic-gate * We have our provider. Now create the probe. 159*7c478bd9Sstevel@tonic-gate */ 160*7c478bd9Sstevel@tonic-gate if ((id = dtrace_probe_lookup(prov->sdtp_id, modname, 161*7c478bd9Sstevel@tonic-gate func, nname)) != DTRACE_IDNONE) { 162*7c478bd9Sstevel@tonic-gate old = dtrace_probe_arg(prov->sdtp_id, id); 163*7c478bd9Sstevel@tonic-gate ASSERT(old != NULL); 164*7c478bd9Sstevel@tonic-gate 165*7c478bd9Sstevel@tonic-gate sdp->sdp_next = old->sdp_next; 166*7c478bd9Sstevel@tonic-gate sdp->sdp_id = id; 167*7c478bd9Sstevel@tonic-gate old->sdp_next = sdp; 168*7c478bd9Sstevel@tonic-gate } else { 169*7c478bd9Sstevel@tonic-gate sdp->sdp_id = dtrace_probe_create(prov->sdtp_id, 170*7c478bd9Sstevel@tonic-gate modname, func, nname, 3, sdp); 171*7c478bd9Sstevel@tonic-gate 172*7c478bd9Sstevel@tonic-gate mp->sdt_nprobes++; 173*7c478bd9Sstevel@tonic-gate } 174*7c478bd9Sstevel@tonic-gate 175*7c478bd9Sstevel@tonic-gate sdp->sdp_hashnext = 176*7c478bd9Sstevel@tonic-gate sdt_probetab[SDT_ADDR2NDX(sdpd->sdpd_offset)]; 177*7c478bd9Sstevel@tonic-gate sdt_probetab[SDT_ADDR2NDX(sdpd->sdpd_offset)] = sdp; 178*7c478bd9Sstevel@tonic-gate 179*7c478bd9Sstevel@tonic-gate sdp->sdp_patchval = SDT_PATCHVAL; 180*7c478bd9Sstevel@tonic-gate sdp->sdp_patchpoint = (uint8_t *)sdpd->sdpd_offset; 181*7c478bd9Sstevel@tonic-gate sdp->sdp_savedval = *sdp->sdp_patchpoint; 182*7c478bd9Sstevel@tonic-gate } 183*7c478bd9Sstevel@tonic-gate } 184*7c478bd9Sstevel@tonic-gate 185*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 186*7c478bd9Sstevel@tonic-gate static void 187*7c478bd9Sstevel@tonic-gate sdt_destroy(void *arg, dtrace_id_t id, void *parg) 188*7c478bd9Sstevel@tonic-gate { 189*7c478bd9Sstevel@tonic-gate sdt_probe_t *sdp = parg, *old, *last, *hash; 190*7c478bd9Sstevel@tonic-gate struct modctl *ctl = sdp->sdp_ctl; 191*7c478bd9Sstevel@tonic-gate int ndx; 192*7c478bd9Sstevel@tonic-gate 193*7c478bd9Sstevel@tonic-gate if (ctl != NULL && ctl->mod_loadcnt == sdp->sdp_loadcnt) { 194*7c478bd9Sstevel@tonic-gate if ((ctl->mod_loadcnt == sdp->sdp_loadcnt && 195*7c478bd9Sstevel@tonic-gate ctl->mod_loaded)) { 196*7c478bd9Sstevel@tonic-gate ((struct module *)(ctl->mod_mp))->sdt_nprobes--; 197*7c478bd9Sstevel@tonic-gate } 198*7c478bd9Sstevel@tonic-gate } 199*7c478bd9Sstevel@tonic-gate 200*7c478bd9Sstevel@tonic-gate while (sdp != NULL) { 201*7c478bd9Sstevel@tonic-gate old = sdp; 202*7c478bd9Sstevel@tonic-gate 203*7c478bd9Sstevel@tonic-gate /* 204*7c478bd9Sstevel@tonic-gate * Now we need to remove this probe from the sdt_probetab. 205*7c478bd9Sstevel@tonic-gate */ 206*7c478bd9Sstevel@tonic-gate ndx = SDT_ADDR2NDX(sdp->sdp_patchpoint); 207*7c478bd9Sstevel@tonic-gate last = NULL; 208*7c478bd9Sstevel@tonic-gate hash = sdt_probetab[ndx]; 209*7c478bd9Sstevel@tonic-gate 210*7c478bd9Sstevel@tonic-gate while (hash != sdp) { 211*7c478bd9Sstevel@tonic-gate ASSERT(hash != NULL); 212*7c478bd9Sstevel@tonic-gate last = hash; 213*7c478bd9Sstevel@tonic-gate hash = hash->sdp_hashnext; 214*7c478bd9Sstevel@tonic-gate } 215*7c478bd9Sstevel@tonic-gate 216*7c478bd9Sstevel@tonic-gate if (last != NULL) { 217*7c478bd9Sstevel@tonic-gate last->sdp_hashnext = sdp->sdp_hashnext; 218*7c478bd9Sstevel@tonic-gate } else { 219*7c478bd9Sstevel@tonic-gate sdt_probetab[ndx] = sdp->sdp_hashnext; 220*7c478bd9Sstevel@tonic-gate } 221*7c478bd9Sstevel@tonic-gate 222*7c478bd9Sstevel@tonic-gate kmem_free(sdp->sdp_name, sdp->sdp_namelen); 223*7c478bd9Sstevel@tonic-gate sdp = sdp->sdp_next; 224*7c478bd9Sstevel@tonic-gate kmem_free(old, sizeof (sdt_probe_t)); 225*7c478bd9Sstevel@tonic-gate } 226*7c478bd9Sstevel@tonic-gate } 227*7c478bd9Sstevel@tonic-gate 228*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 229*7c478bd9Sstevel@tonic-gate static void 230*7c478bd9Sstevel@tonic-gate sdt_enable(void *arg, dtrace_id_t id, void *parg) 231*7c478bd9Sstevel@tonic-gate { 232*7c478bd9Sstevel@tonic-gate sdt_probe_t *sdp = parg; 233*7c478bd9Sstevel@tonic-gate struct modctl *ctl = sdp->sdp_ctl; 234*7c478bd9Sstevel@tonic-gate 235*7c478bd9Sstevel@tonic-gate ctl->mod_nenabled++; 236*7c478bd9Sstevel@tonic-gate 237*7c478bd9Sstevel@tonic-gate /* 238*7c478bd9Sstevel@tonic-gate * If this module has disappeared since we discovered its probes, 239*7c478bd9Sstevel@tonic-gate * refuse to enable it. 240*7c478bd9Sstevel@tonic-gate */ 241*7c478bd9Sstevel@tonic-gate if (!ctl->mod_loaded) { 242*7c478bd9Sstevel@tonic-gate if (sdt_verbose) { 243*7c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "sdt is failing for probe %s " 244*7c478bd9Sstevel@tonic-gate "(module %s unloaded)", 245*7c478bd9Sstevel@tonic-gate sdp->sdp_name, ctl->mod_modname); 246*7c478bd9Sstevel@tonic-gate } 247*7c478bd9Sstevel@tonic-gate goto err; 248*7c478bd9Sstevel@tonic-gate } 249*7c478bd9Sstevel@tonic-gate 250*7c478bd9Sstevel@tonic-gate /* 251*7c478bd9Sstevel@tonic-gate * Now check that our modctl has the expected load count. If it 252*7c478bd9Sstevel@tonic-gate * doesn't, this module must have been unloaded and reloaded -- and 253*7c478bd9Sstevel@tonic-gate * we're not going to touch it. 254*7c478bd9Sstevel@tonic-gate */ 255*7c478bd9Sstevel@tonic-gate if (ctl->mod_loadcnt != sdp->sdp_loadcnt) { 256*7c478bd9Sstevel@tonic-gate if (sdt_verbose) { 257*7c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "sdt is failing for probe %s " 258*7c478bd9Sstevel@tonic-gate "(module %s reloaded)", 259*7c478bd9Sstevel@tonic-gate sdp->sdp_name, ctl->mod_modname); 260*7c478bd9Sstevel@tonic-gate } 261*7c478bd9Sstevel@tonic-gate goto err; 262*7c478bd9Sstevel@tonic-gate } 263*7c478bd9Sstevel@tonic-gate 264*7c478bd9Sstevel@tonic-gate while (sdp != NULL) { 265*7c478bd9Sstevel@tonic-gate *sdp->sdp_patchpoint = sdp->sdp_patchval; 266*7c478bd9Sstevel@tonic-gate sdp = sdp->sdp_next; 267*7c478bd9Sstevel@tonic-gate } 268*7c478bd9Sstevel@tonic-gate err: 269*7c478bd9Sstevel@tonic-gate ; 270*7c478bd9Sstevel@tonic-gate } 271*7c478bd9Sstevel@tonic-gate 272*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 273*7c478bd9Sstevel@tonic-gate static void 274*7c478bd9Sstevel@tonic-gate sdt_disable(void *arg, dtrace_id_t id, void *parg) 275*7c478bd9Sstevel@tonic-gate { 276*7c478bd9Sstevel@tonic-gate sdt_probe_t *sdp = parg; 277*7c478bd9Sstevel@tonic-gate struct modctl *ctl = sdp->sdp_ctl; 278*7c478bd9Sstevel@tonic-gate 279*7c478bd9Sstevel@tonic-gate ctl->mod_nenabled--; 280*7c478bd9Sstevel@tonic-gate 281*7c478bd9Sstevel@tonic-gate if (!ctl->mod_loaded || ctl->mod_loadcnt != sdp->sdp_loadcnt) 282*7c478bd9Sstevel@tonic-gate goto err; 283*7c478bd9Sstevel@tonic-gate 284*7c478bd9Sstevel@tonic-gate while (sdp != NULL) { 285*7c478bd9Sstevel@tonic-gate *sdp->sdp_patchpoint = sdp->sdp_savedval; 286*7c478bd9Sstevel@tonic-gate sdp = sdp->sdp_next; 287*7c478bd9Sstevel@tonic-gate } 288*7c478bd9Sstevel@tonic-gate 289*7c478bd9Sstevel@tonic-gate err: 290*7c478bd9Sstevel@tonic-gate ; 291*7c478bd9Sstevel@tonic-gate } 292*7c478bd9Sstevel@tonic-gate 293*7c478bd9Sstevel@tonic-gate static dtrace_pops_t sdt_pops = { 294*7c478bd9Sstevel@tonic-gate NULL, 295*7c478bd9Sstevel@tonic-gate sdt_provide_module, 296*7c478bd9Sstevel@tonic-gate sdt_enable, 297*7c478bd9Sstevel@tonic-gate sdt_disable, 298*7c478bd9Sstevel@tonic-gate NULL, 299*7c478bd9Sstevel@tonic-gate NULL, 300*7c478bd9Sstevel@tonic-gate sdt_getargdesc, 301*7c478bd9Sstevel@tonic-gate NULL, 302*7c478bd9Sstevel@tonic-gate NULL, 303*7c478bd9Sstevel@tonic-gate sdt_destroy 304*7c478bd9Sstevel@tonic-gate }; 305*7c478bd9Sstevel@tonic-gate 306*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 307*7c478bd9Sstevel@tonic-gate static int 308*7c478bd9Sstevel@tonic-gate sdt_attach(dev_info_t *devi, ddi_attach_cmd_t cmd) 309*7c478bd9Sstevel@tonic-gate { 310*7c478bd9Sstevel@tonic-gate sdt_provider_t *prov; 311*7c478bd9Sstevel@tonic-gate 312*7c478bd9Sstevel@tonic-gate if (ddi_create_minor_node(devi, "sdt", S_IFCHR, 313*7c478bd9Sstevel@tonic-gate 0, DDI_PSEUDO, NULL) == DDI_FAILURE) { 314*7c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "/dev/sdt couldn't create minor node"); 315*7c478bd9Sstevel@tonic-gate ddi_remove_minor_node(devi, NULL); 316*7c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 317*7c478bd9Sstevel@tonic-gate } 318*7c478bd9Sstevel@tonic-gate 319*7c478bd9Sstevel@tonic-gate ddi_report_dev(devi); 320*7c478bd9Sstevel@tonic-gate sdt_devi = devi; 321*7c478bd9Sstevel@tonic-gate 322*7c478bd9Sstevel@tonic-gate if (sdt_probetab_size == 0) 323*7c478bd9Sstevel@tonic-gate sdt_probetab_size = SDT_PROBETAB_SIZE; 324*7c478bd9Sstevel@tonic-gate 325*7c478bd9Sstevel@tonic-gate sdt_probetab_mask = sdt_probetab_size - 1; 326*7c478bd9Sstevel@tonic-gate sdt_probetab = 327*7c478bd9Sstevel@tonic-gate kmem_zalloc(sdt_probetab_size * sizeof (sdt_probe_t *), KM_SLEEP); 328*7c478bd9Sstevel@tonic-gate dtrace_invop_add(sdt_invop); 329*7c478bd9Sstevel@tonic-gate 330*7c478bd9Sstevel@tonic-gate for (prov = sdt_providers; prov->sdtp_name != NULL; prov++) { 331*7c478bd9Sstevel@tonic-gate if (dtrace_register(prov->sdtp_name, prov->sdtp_attr, 332*7c478bd9Sstevel@tonic-gate DTRACE_PRIV_KERNEL, 0, 333*7c478bd9Sstevel@tonic-gate &sdt_pops, prov, &prov->sdtp_id) != 0) { 334*7c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "failed to register sdt provider %s", 335*7c478bd9Sstevel@tonic-gate prov->sdtp_name); 336*7c478bd9Sstevel@tonic-gate } 337*7c478bd9Sstevel@tonic-gate } 338*7c478bd9Sstevel@tonic-gate 339*7c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 340*7c478bd9Sstevel@tonic-gate } 341*7c478bd9Sstevel@tonic-gate 342*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 343*7c478bd9Sstevel@tonic-gate static int 344*7c478bd9Sstevel@tonic-gate sdt_detach(dev_info_t *dip, ddi_detach_cmd_t cmd) 345*7c478bd9Sstevel@tonic-gate { 346*7c478bd9Sstevel@tonic-gate sdt_provider_t *prov; 347*7c478bd9Sstevel@tonic-gate 348*7c478bd9Sstevel@tonic-gate switch (cmd) { 349*7c478bd9Sstevel@tonic-gate case DDI_DETACH: 350*7c478bd9Sstevel@tonic-gate break; 351*7c478bd9Sstevel@tonic-gate 352*7c478bd9Sstevel@tonic-gate case DDI_SUSPEND: 353*7c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 354*7c478bd9Sstevel@tonic-gate 355*7c478bd9Sstevel@tonic-gate default: 356*7c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 357*7c478bd9Sstevel@tonic-gate } 358*7c478bd9Sstevel@tonic-gate 359*7c478bd9Sstevel@tonic-gate for (prov = sdt_providers; prov->sdtp_name != NULL; prov++) { 360*7c478bd9Sstevel@tonic-gate if (prov->sdtp_id != DTRACE_PROVNONE) { 361*7c478bd9Sstevel@tonic-gate if (dtrace_unregister(prov->sdtp_id) != 0) 362*7c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 363*7c478bd9Sstevel@tonic-gate 364*7c478bd9Sstevel@tonic-gate prov->sdtp_id = DTRACE_PROVNONE; 365*7c478bd9Sstevel@tonic-gate } 366*7c478bd9Sstevel@tonic-gate } 367*7c478bd9Sstevel@tonic-gate 368*7c478bd9Sstevel@tonic-gate dtrace_invop_remove(sdt_invop); 369*7c478bd9Sstevel@tonic-gate kmem_free(sdt_probetab, sdt_probetab_size * sizeof (sdt_probe_t *)); 370*7c478bd9Sstevel@tonic-gate 371*7c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 372*7c478bd9Sstevel@tonic-gate } 373*7c478bd9Sstevel@tonic-gate 374*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 375*7c478bd9Sstevel@tonic-gate static int 376*7c478bd9Sstevel@tonic-gate sdt_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result) 377*7c478bd9Sstevel@tonic-gate { 378*7c478bd9Sstevel@tonic-gate int error; 379*7c478bd9Sstevel@tonic-gate 380*7c478bd9Sstevel@tonic-gate switch (infocmd) { 381*7c478bd9Sstevel@tonic-gate case DDI_INFO_DEVT2DEVINFO: 382*7c478bd9Sstevel@tonic-gate *result = (void *)sdt_devi; 383*7c478bd9Sstevel@tonic-gate error = DDI_SUCCESS; 384*7c478bd9Sstevel@tonic-gate break; 385*7c478bd9Sstevel@tonic-gate case DDI_INFO_DEVT2INSTANCE: 386*7c478bd9Sstevel@tonic-gate *result = (void *)0; 387*7c478bd9Sstevel@tonic-gate error = DDI_SUCCESS; 388*7c478bd9Sstevel@tonic-gate break; 389*7c478bd9Sstevel@tonic-gate default: 390*7c478bd9Sstevel@tonic-gate error = DDI_FAILURE; 391*7c478bd9Sstevel@tonic-gate } 392*7c478bd9Sstevel@tonic-gate return (error); 393*7c478bd9Sstevel@tonic-gate } 394*7c478bd9Sstevel@tonic-gate 395*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 396*7c478bd9Sstevel@tonic-gate static int 397*7c478bd9Sstevel@tonic-gate sdt_open(dev_t *devp, int flag, int otyp, cred_t *cred_p) 398*7c478bd9Sstevel@tonic-gate { 399*7c478bd9Sstevel@tonic-gate return (0); 400*7c478bd9Sstevel@tonic-gate } 401*7c478bd9Sstevel@tonic-gate 402*7c478bd9Sstevel@tonic-gate static struct cb_ops sdt_cb_ops = { 403*7c478bd9Sstevel@tonic-gate sdt_open, /* open */ 404*7c478bd9Sstevel@tonic-gate nodev, /* close */ 405*7c478bd9Sstevel@tonic-gate nulldev, /* strategy */ 406*7c478bd9Sstevel@tonic-gate nulldev, /* print */ 407*7c478bd9Sstevel@tonic-gate nodev, /* dump */ 408*7c478bd9Sstevel@tonic-gate nodev, /* read */ 409*7c478bd9Sstevel@tonic-gate nodev, /* write */ 410*7c478bd9Sstevel@tonic-gate nodev, /* ioctl */ 411*7c478bd9Sstevel@tonic-gate nodev, /* devmap */ 412*7c478bd9Sstevel@tonic-gate nodev, /* mmap */ 413*7c478bd9Sstevel@tonic-gate nodev, /* segmap */ 414*7c478bd9Sstevel@tonic-gate nochpoll, /* poll */ 415*7c478bd9Sstevel@tonic-gate ddi_prop_op, /* cb_prop_op */ 416*7c478bd9Sstevel@tonic-gate 0, /* streamtab */ 417*7c478bd9Sstevel@tonic-gate D_NEW | D_MP /* Driver compatibility flag */ 418*7c478bd9Sstevel@tonic-gate }; 419*7c478bd9Sstevel@tonic-gate 420*7c478bd9Sstevel@tonic-gate static struct dev_ops sdt_ops = { 421*7c478bd9Sstevel@tonic-gate DEVO_REV, /* devo_rev, */ 422*7c478bd9Sstevel@tonic-gate 0, /* refcnt */ 423*7c478bd9Sstevel@tonic-gate sdt_info, /* get_dev_info */ 424*7c478bd9Sstevel@tonic-gate nulldev, /* identify */ 425*7c478bd9Sstevel@tonic-gate nulldev, /* probe */ 426*7c478bd9Sstevel@tonic-gate sdt_attach, /* attach */ 427*7c478bd9Sstevel@tonic-gate sdt_detach, /* detach */ 428*7c478bd9Sstevel@tonic-gate nodev, /* reset */ 429*7c478bd9Sstevel@tonic-gate &sdt_cb_ops, /* driver operations */ 430*7c478bd9Sstevel@tonic-gate NULL, /* bus operations */ 431*7c478bd9Sstevel@tonic-gate nodev /* dev power */ 432*7c478bd9Sstevel@tonic-gate }; 433*7c478bd9Sstevel@tonic-gate 434*7c478bd9Sstevel@tonic-gate /* 435*7c478bd9Sstevel@tonic-gate * Module linkage information for the kernel. 436*7c478bd9Sstevel@tonic-gate */ 437*7c478bd9Sstevel@tonic-gate static struct modldrv modldrv = { 438*7c478bd9Sstevel@tonic-gate &mod_driverops, /* module type (this is a pseudo driver) */ 439*7c478bd9Sstevel@tonic-gate "Statically Defined Tracing", /* name of module */ 440*7c478bd9Sstevel@tonic-gate &sdt_ops, /* driver ops */ 441*7c478bd9Sstevel@tonic-gate }; 442*7c478bd9Sstevel@tonic-gate 443*7c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = { 444*7c478bd9Sstevel@tonic-gate MODREV_1, 445*7c478bd9Sstevel@tonic-gate (void *)&modldrv, 446*7c478bd9Sstevel@tonic-gate NULL 447*7c478bd9Sstevel@tonic-gate }; 448*7c478bd9Sstevel@tonic-gate 449*7c478bd9Sstevel@tonic-gate int 450*7c478bd9Sstevel@tonic-gate _init(void) 451*7c478bd9Sstevel@tonic-gate { 452*7c478bd9Sstevel@tonic-gate return (mod_install(&modlinkage)); 453*7c478bd9Sstevel@tonic-gate } 454*7c478bd9Sstevel@tonic-gate 455*7c478bd9Sstevel@tonic-gate int 456*7c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop) 457*7c478bd9Sstevel@tonic-gate { 458*7c478bd9Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 459*7c478bd9Sstevel@tonic-gate } 460*7c478bd9Sstevel@tonic-gate 461*7c478bd9Sstevel@tonic-gate int 462*7c478bd9Sstevel@tonic-gate _fini(void) 463*7c478bd9Sstevel@tonic-gate { 464*7c478bd9Sstevel@tonic-gate return (mod_remove(&modlinkage)); 465*7c478bd9Sstevel@tonic-gate } 466