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