10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 51677Sdp * Common Development and Distribution License (the "License"). 61677Sdp * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 226878Sbrendan * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 270Sstevel@tonic-gate 280Sstevel@tonic-gate #include <sys/modctl.h> 290Sstevel@tonic-gate #include <sys/sunddi.h> 300Sstevel@tonic-gate #include <sys/dtrace.h> 310Sstevel@tonic-gate #include <sys/kobj.h> 320Sstevel@tonic-gate #include <sys/stat.h> 330Sstevel@tonic-gate #include <sys/conf.h> 340Sstevel@tonic-gate #include <vm/seg_kmem.h> 350Sstevel@tonic-gate #include <sys/stack.h> 366878Sbrendan #include <sys/frame.h> 376878Sbrendan #include <sys/dtrace_impl.h> 386878Sbrendan #include <sys/cmn_err.h> 396878Sbrendan #include <sys/sysmacros.h> 406878Sbrendan #include <sys/privregs.h> 410Sstevel@tonic-gate #include <sys/sdt_impl.h> 420Sstevel@tonic-gate 430Sstevel@tonic-gate #define SDT_PATCHVAL 0xf0 440Sstevel@tonic-gate #define SDT_ADDR2NDX(addr) ((((uintptr_t)(addr)) >> 4) & sdt_probetab_mask) 450Sstevel@tonic-gate #define SDT_PROBETAB_SIZE 0x1000 /* 4k entries -- 16K total */ 460Sstevel@tonic-gate 470Sstevel@tonic-gate static dev_info_t *sdt_devi; 480Sstevel@tonic-gate static int sdt_verbose = 0; 490Sstevel@tonic-gate static sdt_probe_t **sdt_probetab; 500Sstevel@tonic-gate static int sdt_probetab_size; 510Sstevel@tonic-gate static int sdt_probetab_mask; 520Sstevel@tonic-gate 530Sstevel@tonic-gate /*ARGSUSED*/ 540Sstevel@tonic-gate static int 550Sstevel@tonic-gate sdt_invop(uintptr_t addr, uintptr_t *stack, uintptr_t eax) 560Sstevel@tonic-gate { 570Sstevel@tonic-gate uintptr_t stack0, stack1, stack2, stack3, stack4; 580Sstevel@tonic-gate int i = 0; 590Sstevel@tonic-gate sdt_probe_t *sdt = sdt_probetab[SDT_ADDR2NDX(addr)]; 600Sstevel@tonic-gate 610Sstevel@tonic-gate #ifdef __amd64 620Sstevel@tonic-gate /* 630Sstevel@tonic-gate * On amd64, stack[0] contains the dereferenced stack pointer, 640Sstevel@tonic-gate * stack[1] contains savfp, stack[2] contains savpc. We want 650Sstevel@tonic-gate * to step over these entries. 660Sstevel@tonic-gate */ 670Sstevel@tonic-gate i += 3; 680Sstevel@tonic-gate #endif 690Sstevel@tonic-gate 700Sstevel@tonic-gate for (; sdt != NULL; sdt = sdt->sdp_hashnext) { 710Sstevel@tonic-gate if ((uintptr_t)sdt->sdp_patchpoint == addr) { 720Sstevel@tonic-gate /* 730Sstevel@tonic-gate * When accessing the arguments on the stack, we must 740Sstevel@tonic-gate * protect against accessing beyond the stack. We can 750Sstevel@tonic-gate * safely set NOFAULT here -- we know that interrupts 760Sstevel@tonic-gate * are already disabled. 770Sstevel@tonic-gate */ 780Sstevel@tonic-gate DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT); 790Sstevel@tonic-gate stack0 = stack[i++]; 800Sstevel@tonic-gate stack1 = stack[i++]; 810Sstevel@tonic-gate stack2 = stack[i++]; 820Sstevel@tonic-gate stack3 = stack[i++]; 830Sstevel@tonic-gate stack4 = stack[i++]; 840Sstevel@tonic-gate DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT | 850Sstevel@tonic-gate CPU_DTRACE_BADADDR); 860Sstevel@tonic-gate 870Sstevel@tonic-gate dtrace_probe(sdt->sdp_id, stack0, stack1, 880Sstevel@tonic-gate stack2, stack3, stack4); 890Sstevel@tonic-gate 900Sstevel@tonic-gate return (DTRACE_INVOP_NOP); 910Sstevel@tonic-gate } 920Sstevel@tonic-gate } 930Sstevel@tonic-gate 940Sstevel@tonic-gate return (0); 950Sstevel@tonic-gate } 960Sstevel@tonic-gate 970Sstevel@tonic-gate /*ARGSUSED*/ 980Sstevel@tonic-gate static void 990Sstevel@tonic-gate sdt_provide_module(void *arg, struct modctl *ctl) 1000Sstevel@tonic-gate { 1010Sstevel@tonic-gate struct module *mp = ctl->mod_mp; 1020Sstevel@tonic-gate char *modname = ctl->mod_modname; 1030Sstevel@tonic-gate sdt_probedesc_t *sdpd; 1040Sstevel@tonic-gate sdt_probe_t *sdp, *old; 1050Sstevel@tonic-gate sdt_provider_t *prov; 1060Sstevel@tonic-gate int len; 1070Sstevel@tonic-gate 1080Sstevel@tonic-gate /* 1090Sstevel@tonic-gate * One for all, and all for one: if we haven't yet registered all of 1100Sstevel@tonic-gate * our providers, we'll refuse to provide anything. 1110Sstevel@tonic-gate */ 1120Sstevel@tonic-gate for (prov = sdt_providers; prov->sdtp_name != NULL; prov++) { 1130Sstevel@tonic-gate if (prov->sdtp_id == DTRACE_PROVNONE) 1140Sstevel@tonic-gate return; 1150Sstevel@tonic-gate } 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate if (mp->sdt_nprobes != 0 || (sdpd = mp->sdt_probes) == NULL) 1180Sstevel@tonic-gate return; 1190Sstevel@tonic-gate 1200Sstevel@tonic-gate for (sdpd = mp->sdt_probes; sdpd != NULL; sdpd = sdpd->sdpd_next) { 1210Sstevel@tonic-gate char *name = sdpd->sdpd_name, *func, *nname; 1220Sstevel@tonic-gate int i, j; 1230Sstevel@tonic-gate sdt_provider_t *prov; 1240Sstevel@tonic-gate ulong_t offs; 1250Sstevel@tonic-gate dtrace_id_t id; 1260Sstevel@tonic-gate 1270Sstevel@tonic-gate for (prov = sdt_providers; prov->sdtp_prefix != NULL; prov++) { 1280Sstevel@tonic-gate char *prefix = prov->sdtp_prefix; 1290Sstevel@tonic-gate 1300Sstevel@tonic-gate if (strncmp(name, prefix, strlen(prefix)) == 0) { 1310Sstevel@tonic-gate name += strlen(prefix); 1320Sstevel@tonic-gate break; 1330Sstevel@tonic-gate } 1340Sstevel@tonic-gate } 1350Sstevel@tonic-gate 1360Sstevel@tonic-gate nname = kmem_alloc(len = strlen(name) + 1, KM_SLEEP); 1370Sstevel@tonic-gate 1380Sstevel@tonic-gate for (i = 0, j = 0; name[j] != '\0'; i++) { 1390Sstevel@tonic-gate if (name[j] == '_' && name[j + 1] == '_') { 1400Sstevel@tonic-gate nname[i] = '-'; 1410Sstevel@tonic-gate j += 2; 1420Sstevel@tonic-gate } else { 1430Sstevel@tonic-gate nname[i] = name[j++]; 1440Sstevel@tonic-gate } 1450Sstevel@tonic-gate } 1460Sstevel@tonic-gate 1470Sstevel@tonic-gate nname[i] = '\0'; 1480Sstevel@tonic-gate 1490Sstevel@tonic-gate sdp = kmem_zalloc(sizeof (sdt_probe_t), KM_SLEEP); 1500Sstevel@tonic-gate sdp->sdp_loadcnt = ctl->mod_loadcnt; 1510Sstevel@tonic-gate sdp->sdp_ctl = ctl; 1520Sstevel@tonic-gate sdp->sdp_name = nname; 1530Sstevel@tonic-gate sdp->sdp_namelen = len; 1540Sstevel@tonic-gate sdp->sdp_provider = prov; 1550Sstevel@tonic-gate 1560Sstevel@tonic-gate func = kobj_searchsym(mp, sdpd->sdpd_offset, &offs); 1570Sstevel@tonic-gate 1580Sstevel@tonic-gate if (func == NULL) 1590Sstevel@tonic-gate func = "<unknown>"; 1600Sstevel@tonic-gate 1610Sstevel@tonic-gate /* 1620Sstevel@tonic-gate * We have our provider. Now create the probe. 1630Sstevel@tonic-gate */ 1640Sstevel@tonic-gate if ((id = dtrace_probe_lookup(prov->sdtp_id, modname, 1650Sstevel@tonic-gate func, nname)) != DTRACE_IDNONE) { 1660Sstevel@tonic-gate old = dtrace_probe_arg(prov->sdtp_id, id); 1670Sstevel@tonic-gate ASSERT(old != NULL); 1680Sstevel@tonic-gate 1690Sstevel@tonic-gate sdp->sdp_next = old->sdp_next; 1700Sstevel@tonic-gate sdp->sdp_id = id; 1710Sstevel@tonic-gate old->sdp_next = sdp; 1720Sstevel@tonic-gate } else { 1730Sstevel@tonic-gate sdp->sdp_id = dtrace_probe_create(prov->sdtp_id, 1740Sstevel@tonic-gate modname, func, nname, 3, sdp); 1750Sstevel@tonic-gate 1760Sstevel@tonic-gate mp->sdt_nprobes++; 1770Sstevel@tonic-gate } 1780Sstevel@tonic-gate 1790Sstevel@tonic-gate sdp->sdp_hashnext = 1800Sstevel@tonic-gate sdt_probetab[SDT_ADDR2NDX(sdpd->sdpd_offset)]; 1810Sstevel@tonic-gate sdt_probetab[SDT_ADDR2NDX(sdpd->sdpd_offset)] = sdp; 1820Sstevel@tonic-gate 1830Sstevel@tonic-gate sdp->sdp_patchval = SDT_PATCHVAL; 1840Sstevel@tonic-gate sdp->sdp_patchpoint = (uint8_t *)sdpd->sdpd_offset; 1850Sstevel@tonic-gate sdp->sdp_savedval = *sdp->sdp_patchpoint; 1860Sstevel@tonic-gate } 1870Sstevel@tonic-gate } 1880Sstevel@tonic-gate 1890Sstevel@tonic-gate /*ARGSUSED*/ 1900Sstevel@tonic-gate static void 1910Sstevel@tonic-gate sdt_destroy(void *arg, dtrace_id_t id, void *parg) 1920Sstevel@tonic-gate { 1930Sstevel@tonic-gate sdt_probe_t *sdp = parg, *old, *last, *hash; 1940Sstevel@tonic-gate struct modctl *ctl = sdp->sdp_ctl; 1950Sstevel@tonic-gate int ndx; 1960Sstevel@tonic-gate 1970Sstevel@tonic-gate if (ctl != NULL && ctl->mod_loadcnt == sdp->sdp_loadcnt) { 1980Sstevel@tonic-gate if ((ctl->mod_loadcnt == sdp->sdp_loadcnt && 1990Sstevel@tonic-gate ctl->mod_loaded)) { 2000Sstevel@tonic-gate ((struct module *)(ctl->mod_mp))->sdt_nprobes--; 2010Sstevel@tonic-gate } 2020Sstevel@tonic-gate } 2030Sstevel@tonic-gate 2040Sstevel@tonic-gate while (sdp != NULL) { 2050Sstevel@tonic-gate old = sdp; 2060Sstevel@tonic-gate 2070Sstevel@tonic-gate /* 2080Sstevel@tonic-gate * Now we need to remove this probe from the sdt_probetab. 2090Sstevel@tonic-gate */ 2100Sstevel@tonic-gate ndx = SDT_ADDR2NDX(sdp->sdp_patchpoint); 2110Sstevel@tonic-gate last = NULL; 2120Sstevel@tonic-gate hash = sdt_probetab[ndx]; 2130Sstevel@tonic-gate 2140Sstevel@tonic-gate while (hash != sdp) { 2150Sstevel@tonic-gate ASSERT(hash != NULL); 2160Sstevel@tonic-gate last = hash; 2170Sstevel@tonic-gate hash = hash->sdp_hashnext; 2180Sstevel@tonic-gate } 2190Sstevel@tonic-gate 2200Sstevel@tonic-gate if (last != NULL) { 2210Sstevel@tonic-gate last->sdp_hashnext = sdp->sdp_hashnext; 2220Sstevel@tonic-gate } else { 2230Sstevel@tonic-gate sdt_probetab[ndx] = sdp->sdp_hashnext; 2240Sstevel@tonic-gate } 2250Sstevel@tonic-gate 2260Sstevel@tonic-gate kmem_free(sdp->sdp_name, sdp->sdp_namelen); 2270Sstevel@tonic-gate sdp = sdp->sdp_next; 2280Sstevel@tonic-gate kmem_free(old, sizeof (sdt_probe_t)); 2290Sstevel@tonic-gate } 2300Sstevel@tonic-gate } 2310Sstevel@tonic-gate 2320Sstevel@tonic-gate /*ARGSUSED*/ 2330Sstevel@tonic-gate static void 2340Sstevel@tonic-gate sdt_enable(void *arg, dtrace_id_t id, void *parg) 2350Sstevel@tonic-gate { 2360Sstevel@tonic-gate sdt_probe_t *sdp = parg; 2370Sstevel@tonic-gate struct modctl *ctl = sdp->sdp_ctl; 2380Sstevel@tonic-gate 2390Sstevel@tonic-gate ctl->mod_nenabled++; 2400Sstevel@tonic-gate 2410Sstevel@tonic-gate /* 2420Sstevel@tonic-gate * If this module has disappeared since we discovered its probes, 2430Sstevel@tonic-gate * refuse to enable it. 2440Sstevel@tonic-gate */ 2450Sstevel@tonic-gate if (!ctl->mod_loaded) { 2460Sstevel@tonic-gate if (sdt_verbose) { 2470Sstevel@tonic-gate cmn_err(CE_NOTE, "sdt is failing for probe %s " 2480Sstevel@tonic-gate "(module %s unloaded)", 2490Sstevel@tonic-gate sdp->sdp_name, ctl->mod_modname); 2500Sstevel@tonic-gate } 2510Sstevel@tonic-gate goto err; 2520Sstevel@tonic-gate } 2530Sstevel@tonic-gate 2540Sstevel@tonic-gate /* 2550Sstevel@tonic-gate * Now check that our modctl has the expected load count. If it 2560Sstevel@tonic-gate * doesn't, this module must have been unloaded and reloaded -- and 2570Sstevel@tonic-gate * we're not going to touch it. 2580Sstevel@tonic-gate */ 2590Sstevel@tonic-gate if (ctl->mod_loadcnt != sdp->sdp_loadcnt) { 2600Sstevel@tonic-gate if (sdt_verbose) { 2610Sstevel@tonic-gate cmn_err(CE_NOTE, "sdt is failing for probe %s " 2620Sstevel@tonic-gate "(module %s reloaded)", 2630Sstevel@tonic-gate sdp->sdp_name, ctl->mod_modname); 2640Sstevel@tonic-gate } 2650Sstevel@tonic-gate goto err; 2660Sstevel@tonic-gate } 2670Sstevel@tonic-gate 2680Sstevel@tonic-gate while (sdp != NULL) { 2690Sstevel@tonic-gate *sdp->sdp_patchpoint = sdp->sdp_patchval; 2700Sstevel@tonic-gate sdp = sdp->sdp_next; 2710Sstevel@tonic-gate } 2720Sstevel@tonic-gate err: 2730Sstevel@tonic-gate ; 2740Sstevel@tonic-gate } 2750Sstevel@tonic-gate 2760Sstevel@tonic-gate /*ARGSUSED*/ 2770Sstevel@tonic-gate static void 2780Sstevel@tonic-gate sdt_disable(void *arg, dtrace_id_t id, void *parg) 2790Sstevel@tonic-gate { 2800Sstevel@tonic-gate sdt_probe_t *sdp = parg; 2810Sstevel@tonic-gate struct modctl *ctl = sdp->sdp_ctl; 2820Sstevel@tonic-gate 2830Sstevel@tonic-gate ctl->mod_nenabled--; 2840Sstevel@tonic-gate 2850Sstevel@tonic-gate if (!ctl->mod_loaded || ctl->mod_loadcnt != sdp->sdp_loadcnt) 2860Sstevel@tonic-gate goto err; 2870Sstevel@tonic-gate 2880Sstevel@tonic-gate while (sdp != NULL) { 2890Sstevel@tonic-gate *sdp->sdp_patchpoint = sdp->sdp_savedval; 2900Sstevel@tonic-gate sdp = sdp->sdp_next; 2910Sstevel@tonic-gate } 2920Sstevel@tonic-gate 2930Sstevel@tonic-gate err: 2940Sstevel@tonic-gate ; 2950Sstevel@tonic-gate } 2960Sstevel@tonic-gate 2976878Sbrendan /*ARGSUSED*/ 2986878Sbrendan uint64_t 2996878Sbrendan sdt_getarg(void *arg, dtrace_id_t id, void *parg, int argno, int aframes) 3006878Sbrendan { 3016878Sbrendan uintptr_t val; 3026878Sbrendan struct frame *fp = (struct frame *)dtrace_getfp(); 3036878Sbrendan uintptr_t *stack; 3046878Sbrendan int i; 3056878Sbrendan #if defined(__amd64) 3066878Sbrendan /* 3076878Sbrendan * A total of 6 arguments are passed via registers; any argument with 3086878Sbrendan * index of 5 or lower is therefore in a register. 3096878Sbrendan */ 3106878Sbrendan int inreg = 5; 3116878Sbrendan #endif 3126878Sbrendan 3136878Sbrendan for (i = 1; i <= aframes; i++) { 3146878Sbrendan fp = (struct frame *)(fp->fr_savfp); 3156878Sbrendan 3166878Sbrendan if (fp->fr_savpc == (pc_t)dtrace_invop_callsite) { 3176878Sbrendan #if !defined(__amd64) 3186878Sbrendan /* 3196878Sbrendan * If we pass through the invalid op handler, we will 3206878Sbrendan * use the pointer that it passed to the stack as the 3216878Sbrendan * second argument to dtrace_invop() as the pointer to 3226988Sbrendan * the stack. 3236878Sbrendan */ 3246878Sbrendan stack = ((uintptr_t **)&fp[1])[1]; 3256878Sbrendan #else 3266878Sbrendan /* 3276878Sbrendan * In the case of amd64, we will use the pointer to the 3286878Sbrendan * regs structure that was pushed when we took the 3296878Sbrendan * trap. To get this structure, we must increment 3306988Sbrendan * beyond the frame structure. If the argument that 3316988Sbrendan * we're seeking is passed on the stack, we'll pull 3326988Sbrendan * the true stack pointer out of the saved registers 3336988Sbrendan * and decrement our argument by the number of 3346988Sbrendan * arguments passed in registers; if the argument 3356878Sbrendan * we're seeking is passed in regsiters, we can just 3366878Sbrendan * load it directly. 3376878Sbrendan */ 338*6998Sbrendan struct regs *rp = (struct regs *)((uintptr_t)&fp[1] + 339*6998Sbrendan sizeof (uintptr_t)); 3406878Sbrendan 3416878Sbrendan if (argno <= inreg) { 3426878Sbrendan stack = (uintptr_t *)&rp->r_rdi; 3436878Sbrendan } else { 3446878Sbrendan stack = (uintptr_t *)(rp->r_rsp); 345*6998Sbrendan argno -= (inreg + 1); 3466878Sbrendan } 3476878Sbrendan #endif 3486878Sbrendan goto load; 3496878Sbrendan } 3506878Sbrendan } 3516878Sbrendan 3526988Sbrendan /* 3536988Sbrendan * We know that we did not come through a trap to get into 3546988Sbrendan * dtrace_probe() -- the provider simply called dtrace_probe() 3556988Sbrendan * directly. As this is the case, we need to shift the argument 3566988Sbrendan * that we're looking for: the probe ID is the first argument to 3576988Sbrendan * dtrace_probe(), so the argument n will actually be found where 3586988Sbrendan * one would expect to find argument (n + 1). 3596988Sbrendan */ 3606988Sbrendan argno++; 3616988Sbrendan 3626988Sbrendan #if defined(__amd64) 3636988Sbrendan if (argno <= inreg) { 3646988Sbrendan /* 3656988Sbrendan * This shouldn't happen. If the argument is passed in a 3666988Sbrendan * register then it should have been, well, passed in a 3676988Sbrendan * register... 3686988Sbrendan */ 3696988Sbrendan DTRACE_CPUFLAG_SET(CPU_DTRACE_ILLOP); 3706988Sbrendan return (0); 3716988Sbrendan } 3726988Sbrendan 3736988Sbrendan argno -= (inreg + 1); 3746988Sbrendan #endif 3756988Sbrendan stack = (uintptr_t *)&fp[1]; 3766988Sbrendan 3776878Sbrendan load: 3786878Sbrendan DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT); 3796878Sbrendan val = stack[argno]; 3806878Sbrendan DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT); 3816878Sbrendan 3826878Sbrendan return (val); 3836878Sbrendan } 3846878Sbrendan 3850Sstevel@tonic-gate static dtrace_pops_t sdt_pops = { 3860Sstevel@tonic-gate NULL, 3870Sstevel@tonic-gate sdt_provide_module, 3880Sstevel@tonic-gate sdt_enable, 3890Sstevel@tonic-gate sdt_disable, 3900Sstevel@tonic-gate NULL, 3910Sstevel@tonic-gate NULL, 3920Sstevel@tonic-gate sdt_getargdesc, 3936878Sbrendan sdt_getarg, 3940Sstevel@tonic-gate NULL, 3950Sstevel@tonic-gate sdt_destroy 3960Sstevel@tonic-gate }; 3970Sstevel@tonic-gate 3980Sstevel@tonic-gate /*ARGSUSED*/ 3990Sstevel@tonic-gate static int 4000Sstevel@tonic-gate sdt_attach(dev_info_t *devi, ddi_attach_cmd_t cmd) 4010Sstevel@tonic-gate { 4020Sstevel@tonic-gate sdt_provider_t *prov; 4030Sstevel@tonic-gate 4040Sstevel@tonic-gate if (ddi_create_minor_node(devi, "sdt", S_IFCHR, 4050Sstevel@tonic-gate 0, DDI_PSEUDO, NULL) == DDI_FAILURE) { 4060Sstevel@tonic-gate cmn_err(CE_NOTE, "/dev/sdt couldn't create minor node"); 4070Sstevel@tonic-gate ddi_remove_minor_node(devi, NULL); 4080Sstevel@tonic-gate return (DDI_FAILURE); 4090Sstevel@tonic-gate } 4100Sstevel@tonic-gate 4110Sstevel@tonic-gate ddi_report_dev(devi); 4120Sstevel@tonic-gate sdt_devi = devi; 4130Sstevel@tonic-gate 4140Sstevel@tonic-gate if (sdt_probetab_size == 0) 4150Sstevel@tonic-gate sdt_probetab_size = SDT_PROBETAB_SIZE; 4160Sstevel@tonic-gate 4170Sstevel@tonic-gate sdt_probetab_mask = sdt_probetab_size - 1; 4180Sstevel@tonic-gate sdt_probetab = 4190Sstevel@tonic-gate kmem_zalloc(sdt_probetab_size * sizeof (sdt_probe_t *), KM_SLEEP); 4200Sstevel@tonic-gate dtrace_invop_add(sdt_invop); 4210Sstevel@tonic-gate 4220Sstevel@tonic-gate for (prov = sdt_providers; prov->sdtp_name != NULL; prov++) { 4230Sstevel@tonic-gate if (dtrace_register(prov->sdtp_name, prov->sdtp_attr, 4241677Sdp DTRACE_PRIV_KERNEL, NULL, 4250Sstevel@tonic-gate &sdt_pops, prov, &prov->sdtp_id) != 0) { 4260Sstevel@tonic-gate cmn_err(CE_WARN, "failed to register sdt provider %s", 4270Sstevel@tonic-gate prov->sdtp_name); 4280Sstevel@tonic-gate } 4290Sstevel@tonic-gate } 4300Sstevel@tonic-gate 4310Sstevel@tonic-gate return (DDI_SUCCESS); 4320Sstevel@tonic-gate } 4330Sstevel@tonic-gate 4340Sstevel@tonic-gate /*ARGSUSED*/ 4350Sstevel@tonic-gate static int 4360Sstevel@tonic-gate sdt_detach(dev_info_t *dip, ddi_detach_cmd_t cmd) 4370Sstevel@tonic-gate { 4380Sstevel@tonic-gate sdt_provider_t *prov; 4390Sstevel@tonic-gate 4400Sstevel@tonic-gate switch (cmd) { 4410Sstevel@tonic-gate case DDI_DETACH: 4420Sstevel@tonic-gate break; 4430Sstevel@tonic-gate 4440Sstevel@tonic-gate case DDI_SUSPEND: 4450Sstevel@tonic-gate return (DDI_SUCCESS); 4460Sstevel@tonic-gate 4470Sstevel@tonic-gate default: 4480Sstevel@tonic-gate return (DDI_FAILURE); 4490Sstevel@tonic-gate } 4500Sstevel@tonic-gate 4510Sstevel@tonic-gate for (prov = sdt_providers; prov->sdtp_name != NULL; prov++) { 4520Sstevel@tonic-gate if (prov->sdtp_id != DTRACE_PROVNONE) { 4530Sstevel@tonic-gate if (dtrace_unregister(prov->sdtp_id) != 0) 4540Sstevel@tonic-gate return (DDI_FAILURE); 4550Sstevel@tonic-gate 4560Sstevel@tonic-gate prov->sdtp_id = DTRACE_PROVNONE; 4570Sstevel@tonic-gate } 4580Sstevel@tonic-gate } 4590Sstevel@tonic-gate 4600Sstevel@tonic-gate dtrace_invop_remove(sdt_invop); 4610Sstevel@tonic-gate kmem_free(sdt_probetab, sdt_probetab_size * sizeof (sdt_probe_t *)); 4620Sstevel@tonic-gate 4630Sstevel@tonic-gate return (DDI_SUCCESS); 4640Sstevel@tonic-gate } 4650Sstevel@tonic-gate 4660Sstevel@tonic-gate /*ARGSUSED*/ 4670Sstevel@tonic-gate static int 4680Sstevel@tonic-gate sdt_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result) 4690Sstevel@tonic-gate { 4700Sstevel@tonic-gate int error; 4710Sstevel@tonic-gate 4720Sstevel@tonic-gate switch (infocmd) { 4730Sstevel@tonic-gate case DDI_INFO_DEVT2DEVINFO: 4740Sstevel@tonic-gate *result = (void *)sdt_devi; 4750Sstevel@tonic-gate error = DDI_SUCCESS; 4760Sstevel@tonic-gate break; 4770Sstevel@tonic-gate case DDI_INFO_DEVT2INSTANCE: 4780Sstevel@tonic-gate *result = (void *)0; 4790Sstevel@tonic-gate error = DDI_SUCCESS; 4800Sstevel@tonic-gate break; 4810Sstevel@tonic-gate default: 4820Sstevel@tonic-gate error = DDI_FAILURE; 4830Sstevel@tonic-gate } 4840Sstevel@tonic-gate return (error); 4850Sstevel@tonic-gate } 4860Sstevel@tonic-gate 4870Sstevel@tonic-gate /*ARGSUSED*/ 4880Sstevel@tonic-gate static int 4890Sstevel@tonic-gate sdt_open(dev_t *devp, int flag, int otyp, cred_t *cred_p) 4900Sstevel@tonic-gate { 4910Sstevel@tonic-gate return (0); 4920Sstevel@tonic-gate } 4930Sstevel@tonic-gate 4940Sstevel@tonic-gate static struct cb_ops sdt_cb_ops = { 4950Sstevel@tonic-gate sdt_open, /* open */ 4960Sstevel@tonic-gate nodev, /* close */ 4970Sstevel@tonic-gate nulldev, /* strategy */ 4980Sstevel@tonic-gate nulldev, /* print */ 4990Sstevel@tonic-gate nodev, /* dump */ 5000Sstevel@tonic-gate nodev, /* read */ 5010Sstevel@tonic-gate nodev, /* write */ 5020Sstevel@tonic-gate nodev, /* ioctl */ 5030Sstevel@tonic-gate nodev, /* devmap */ 5040Sstevel@tonic-gate nodev, /* mmap */ 5050Sstevel@tonic-gate nodev, /* segmap */ 5060Sstevel@tonic-gate nochpoll, /* poll */ 5070Sstevel@tonic-gate ddi_prop_op, /* cb_prop_op */ 5080Sstevel@tonic-gate 0, /* streamtab */ 5090Sstevel@tonic-gate D_NEW | D_MP /* Driver compatibility flag */ 5100Sstevel@tonic-gate }; 5110Sstevel@tonic-gate 5120Sstevel@tonic-gate static struct dev_ops sdt_ops = { 5130Sstevel@tonic-gate DEVO_REV, /* devo_rev, */ 5140Sstevel@tonic-gate 0, /* refcnt */ 5150Sstevel@tonic-gate sdt_info, /* get_dev_info */ 5160Sstevel@tonic-gate nulldev, /* identify */ 5170Sstevel@tonic-gate nulldev, /* probe */ 5180Sstevel@tonic-gate sdt_attach, /* attach */ 5190Sstevel@tonic-gate sdt_detach, /* detach */ 5200Sstevel@tonic-gate nodev, /* reset */ 5210Sstevel@tonic-gate &sdt_cb_ops, /* driver operations */ 5220Sstevel@tonic-gate NULL, /* bus operations */ 5230Sstevel@tonic-gate nodev /* dev power */ 5240Sstevel@tonic-gate }; 5250Sstevel@tonic-gate 5260Sstevel@tonic-gate /* 5270Sstevel@tonic-gate * Module linkage information for the kernel. 5280Sstevel@tonic-gate */ 5290Sstevel@tonic-gate static struct modldrv modldrv = { 5300Sstevel@tonic-gate &mod_driverops, /* module type (this is a pseudo driver) */ 5310Sstevel@tonic-gate "Statically Defined Tracing", /* name of module */ 5320Sstevel@tonic-gate &sdt_ops, /* driver ops */ 5330Sstevel@tonic-gate }; 5340Sstevel@tonic-gate 5350Sstevel@tonic-gate static struct modlinkage modlinkage = { 5360Sstevel@tonic-gate MODREV_1, 5370Sstevel@tonic-gate (void *)&modldrv, 5380Sstevel@tonic-gate NULL 5390Sstevel@tonic-gate }; 5400Sstevel@tonic-gate 5410Sstevel@tonic-gate int 5420Sstevel@tonic-gate _init(void) 5430Sstevel@tonic-gate { 5440Sstevel@tonic-gate return (mod_install(&modlinkage)); 5450Sstevel@tonic-gate } 5460Sstevel@tonic-gate 5470Sstevel@tonic-gate int 5480Sstevel@tonic-gate _info(struct modinfo *modinfop) 5490Sstevel@tonic-gate { 5500Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 5510Sstevel@tonic-gate } 5520Sstevel@tonic-gate 5530Sstevel@tonic-gate int 5540Sstevel@tonic-gate _fini(void) 5550Sstevel@tonic-gate { 5560Sstevel@tonic-gate return (mod_remove(&modlinkage)); 5570Sstevel@tonic-gate } 558