191eaf3e1SJohn Birrell /* 291eaf3e1SJohn Birrell * CDDL HEADER START 391eaf3e1SJohn Birrell * 491eaf3e1SJohn Birrell * The contents of this file are subject to the terms of the 591eaf3e1SJohn Birrell * Common Development and Distribution License (the "License"). 691eaf3e1SJohn Birrell * You may not use this file except in compliance with the License. 791eaf3e1SJohn Birrell * 891eaf3e1SJohn Birrell * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 991eaf3e1SJohn Birrell * or http://www.opensolaris.org/os/licensing. 1091eaf3e1SJohn Birrell * See the License for the specific language governing permissions 1191eaf3e1SJohn Birrell * and limitations under the License. 1291eaf3e1SJohn Birrell * 1391eaf3e1SJohn Birrell * When distributing Covered Code, include this CDDL HEADER in each 1491eaf3e1SJohn Birrell * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 1591eaf3e1SJohn Birrell * If applicable, add the following below this CDDL HEADER, with the 1691eaf3e1SJohn Birrell * fields enclosed by brackets "[]" replaced with your own identifying 1791eaf3e1SJohn Birrell * information: Portions Copyright [yyyy] [name of copyright owner] 1891eaf3e1SJohn Birrell * 1991eaf3e1SJohn Birrell * CDDL HEADER END 2091eaf3e1SJohn Birrell * 2191eaf3e1SJohn Birrell * Portions Copyright 2006-2008 John Birrell jb@freebsd.org 2291eaf3e1SJohn Birrell * 2391eaf3e1SJohn Birrell * $FreeBSD$ 2491eaf3e1SJohn Birrell * 2591eaf3e1SJohn Birrell */ 2691eaf3e1SJohn Birrell 279c06d5a0SMark Johnston /* 289c06d5a0SMark Johnston * This file contains a reimplementation of the statically-defined tracing (SDT) 299c06d5a0SMark Johnston * framework for DTrace. Probes and SDT providers are defined using the macros 309c06d5a0SMark Johnston * in sys/sdt.h, which append all the needed structures to linker sets. When 319c06d5a0SMark Johnston * this module is loaded, it iterates over all of the loaded modules and 329c06d5a0SMark Johnston * registers probes and providers with the DTrace framework based on the 339c06d5a0SMark Johnston * contents of these linker sets. 349c06d5a0SMark Johnston * 359c06d5a0SMark Johnston * A list of SDT providers is maintained here since a provider may span multiple 369c06d5a0SMark Johnston * modules. When a kernel module is unloaded, a provider defined in that module 379c06d5a0SMark Johnston * is unregistered only if no other modules refer to it. The DTrace framework is 389c06d5a0SMark Johnston * responsible for destroying individual probes when a kernel module is 399c06d5a0SMark Johnston * unloaded; in particular, probes may not span multiple kernel modules. 409c06d5a0SMark Johnston */ 419c06d5a0SMark Johnston 4291eaf3e1SJohn Birrell #include <sys/cdefs.h> 4391eaf3e1SJohn Birrell #include <sys/param.h> 4491eaf3e1SJohn Birrell #include <sys/systm.h> 458776669bSMark Johnston 4691eaf3e1SJohn Birrell #include <sys/conf.h> 478776669bSMark Johnston #include <sys/eventhandler.h> 4891eaf3e1SJohn Birrell #include <sys/kernel.h> 4991eaf3e1SJohn Birrell #include <sys/limits.h> 5091eaf3e1SJohn Birrell #include <sys/linker.h> 518776669bSMark Johnston #include <sys/linker_set.h> 528776669bSMark Johnston #include <sys/lock.h> 5332cd0147SMark Johnston #include <sys/lockstat.h> 548776669bSMark Johnston #include <sys/malloc.h> 5591eaf3e1SJohn Birrell #include <sys/module.h> 5691eaf3e1SJohn Birrell #include <sys/mutex.h> 578776669bSMark Johnston #include <sys/queue.h> 5891eaf3e1SJohn Birrell #include <sys/sdt.h> 5991eaf3e1SJohn Birrell 608776669bSMark Johnston #include <sys/dtrace.h> 618776669bSMark Johnston #include <sys/dtrace_bsd.h> 6291eaf3e1SJohn Birrell 638776669bSMark Johnston /* DTrace methods. */ 6491eaf3e1SJohn Birrell static void sdt_getargdesc(void *, dtrace_id_t, void *, dtrace_argdesc_t *); 6591eaf3e1SJohn Birrell static void sdt_provide_probes(void *, dtrace_probedesc_t *); 6691eaf3e1SJohn Birrell static void sdt_destroy(void *, dtrace_id_t, void *); 6791eaf3e1SJohn Birrell static void sdt_enable(void *, dtrace_id_t, void *); 6891eaf3e1SJohn Birrell static void sdt_disable(void *, dtrace_id_t, void *); 698776669bSMark Johnston 709c06d5a0SMark Johnston static void sdt_load(void); 719c06d5a0SMark Johnston static int sdt_unload(void); 728776669bSMark Johnston static void sdt_create_provider(struct sdt_provider *); 738776669bSMark Johnston static void sdt_create_probe(struct sdt_probe *); 7412ede07aSMark Johnston static void sdt_kld_load(void *, struct linker_file *); 7529f4e216SMark Johnston static void sdt_kld_unload_try(void *, struct linker_file *, int *); 768776669bSMark Johnston 778776669bSMark Johnston static MALLOC_DEFINE(M_SDT, "SDT", "DTrace SDT providers"); 7891eaf3e1SJohn Birrell 7991eaf3e1SJohn Birrell static dtrace_pattr_t sdt_attr = { 8091eaf3e1SJohn Birrell { DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON }, 8191eaf3e1SJohn Birrell { DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN }, 8291eaf3e1SJohn Birrell { DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_ISA }, 8391eaf3e1SJohn Birrell { DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON }, 8491eaf3e1SJohn Birrell { DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_ISA }, 8591eaf3e1SJohn Birrell }; 8691eaf3e1SJohn Birrell 8791eaf3e1SJohn Birrell static dtrace_pops_t sdt_pops = { 8891eaf3e1SJohn Birrell sdt_provide_probes, 8991eaf3e1SJohn Birrell NULL, 9091eaf3e1SJohn Birrell sdt_enable, 9191eaf3e1SJohn Birrell sdt_disable, 9291eaf3e1SJohn Birrell NULL, 9391eaf3e1SJohn Birrell NULL, 9491eaf3e1SJohn Birrell sdt_getargdesc, 9591eaf3e1SJohn Birrell NULL, 9691eaf3e1SJohn Birrell NULL, 978776669bSMark Johnston sdt_destroy, 9891eaf3e1SJohn Birrell }; 9991eaf3e1SJohn Birrell 1008776669bSMark Johnston static TAILQ_HEAD(, sdt_provider) sdt_prov_list; 10191eaf3e1SJohn Birrell 10212ede07aSMark Johnston eventhandler_tag sdt_kld_load_tag; 10329f4e216SMark Johnston eventhandler_tag sdt_kld_unload_try_tag; 10491eaf3e1SJohn Birrell 10591eaf3e1SJohn Birrell static void 1068776669bSMark Johnston sdt_create_provider(struct sdt_provider *prov) 10791eaf3e1SJohn Birrell { 1088776669bSMark Johnston struct sdt_provider *curr, *newprov; 10991eaf3e1SJohn Birrell 1108776669bSMark Johnston TAILQ_FOREACH(curr, &sdt_prov_list, prov_entry) 1118776669bSMark Johnston if (strcmp(prov->name, curr->name) == 0) { 1128776669bSMark Johnston /* The provider has already been defined. */ 1138776669bSMark Johnston curr->sdt_refs++; 11491eaf3e1SJohn Birrell return; 11591eaf3e1SJohn Birrell } 11691eaf3e1SJohn Birrell 1178776669bSMark Johnston /* 1188776669bSMark Johnston * Make a copy of prov so that we don't lose fields if its module is 1198776669bSMark Johnston * unloaded but the provider isn't destroyed. This could happen with 1208776669bSMark Johnston * a provider that spans multiple modules. 1218776669bSMark Johnston */ 1228776669bSMark Johnston newprov = malloc(sizeof(*newprov), M_SDT, M_WAITOK | M_ZERO); 1238776669bSMark Johnston newprov->name = strdup(prov->name, M_SDT); 1248776669bSMark Johnston prov->sdt_refs = newprov->sdt_refs = 1; 1258776669bSMark Johnston 1268776669bSMark Johnston TAILQ_INSERT_TAIL(&sdt_prov_list, newprov, prov_entry); 1278776669bSMark Johnston 1288776669bSMark Johnston (void)dtrace_register(newprov->name, &sdt_attr, DTRACE_PRIV_USER, NULL, 1298776669bSMark Johnston &sdt_pops, NULL, (dtrace_provider_id_t *)&newprov->id); 1308776669bSMark Johnston prov->id = newprov->id; 1318776669bSMark Johnston } 1328776669bSMark Johnston 1338776669bSMark Johnston static void 1348776669bSMark Johnston sdt_create_probe(struct sdt_probe *probe) 13591eaf3e1SJohn Birrell { 1368776669bSMark Johnston struct sdt_provider *prov; 1378776669bSMark Johnston char mod[DTRACE_MODNAMELEN]; 1388776669bSMark Johnston char func[DTRACE_FUNCNAMELEN]; 1398776669bSMark Johnston char name[DTRACE_NAMELEN]; 140d9fae5abSAndriy Gapon const char *from; 141d9fae5abSAndriy Gapon char *to; 1428776669bSMark Johnston size_t len; 1438776669bSMark Johnston 144*09999d92SAndriy Gapon if (probe->version != (int)sizeof(*probe)) { 145*09999d92SAndriy Gapon printf("ignoring probe %p, version %u expected %u\n", 146*09999d92SAndriy Gapon probe, probe->version, (int)sizeof(*probe)); 147*09999d92SAndriy Gapon return; 148*09999d92SAndriy Gapon } 149*09999d92SAndriy Gapon 1508776669bSMark Johnston TAILQ_FOREACH(prov, &sdt_prov_list, prov_entry) 1518776669bSMark Johnston if (strcmp(prov->name, probe->prov->name) == 0) 1528776669bSMark Johnston break; 1538776669bSMark Johnston 1548776669bSMark Johnston KASSERT(prov != NULL, ("probe defined without a provider")); 1558776669bSMark Johnston 1568776669bSMark Johnston /* If no module name was specified, use the module filename. */ 1578776669bSMark Johnston if (*probe->mod == 0) { 1588776669bSMark Johnston len = strlcpy(mod, probe->sdtp_lf->filename, sizeof(mod)); 1598776669bSMark Johnston if (len > 3 && strcmp(mod + len - 3, ".ko") == 0) 1608776669bSMark Johnston mod[len - 3] = '\0'; 1618776669bSMark Johnston } else 1628776669bSMark Johnston strlcpy(mod, probe->mod, sizeof(mod)); 16391eaf3e1SJohn Birrell 16491eaf3e1SJohn Birrell /* 16591eaf3e1SJohn Birrell * Unfortunately this is necessary because the Solaris DTrace 16691eaf3e1SJohn Birrell * code mixes consts and non-consts with casts to override 16791eaf3e1SJohn Birrell * the incompatibilies. On FreeBSD, we use strict warnings 1688776669bSMark Johnston * in the C compiler, so we have to respect const vs non-const. 16991eaf3e1SJohn Birrell */ 17091eaf3e1SJohn Birrell strlcpy(func, probe->func, sizeof(func)); 171d9fae5abSAndriy Gapon 172d9fae5abSAndriy Gapon from = probe->name; 173d9fae5abSAndriy Gapon to = name; 174d9fae5abSAndriy Gapon for (len = 0; len < (sizeof(name) - 1) && *from != '\0'; 175d9fae5abSAndriy Gapon len++, from++, to++) { 176d9fae5abSAndriy Gapon if (from[0] == '_' && from[1] == '_') { 177d9fae5abSAndriy Gapon *to = '-'; 178d9fae5abSAndriy Gapon from++; 179d9fae5abSAndriy Gapon } else 180d9fae5abSAndriy Gapon *to = *from; 181d9fae5abSAndriy Gapon } 182d9fae5abSAndriy Gapon *to = '\0'; 18391eaf3e1SJohn Birrell 1848776669bSMark Johnston if (dtrace_probe_lookup(prov->id, mod, func, name) != DTRACE_IDNONE) 1858776669bSMark Johnston return; 18691eaf3e1SJohn Birrell 1878776669bSMark Johnston (void)dtrace_probe_create(prov->id, mod, func, name, 1, probe); 18891eaf3e1SJohn Birrell } 18991eaf3e1SJohn Birrell 1909c06d5a0SMark Johnston /* 1919c06d5a0SMark Johnston * Probes are created through the SDT module load/unload hook, so this function 1929c06d5a0SMark Johnston * has nothing to do. It only exists because the DTrace provider framework 1939c06d5a0SMark Johnston * requires one of provide_probes and provide_module to be defined. 1949c06d5a0SMark Johnston */ 19591eaf3e1SJohn Birrell static void 19691eaf3e1SJohn Birrell sdt_provide_probes(void *arg, dtrace_probedesc_t *desc) 19791eaf3e1SJohn Birrell { 1988776669bSMark Johnston } 19991eaf3e1SJohn Birrell 2008776669bSMark Johnston static void 2018776669bSMark Johnston sdt_enable(void *arg __unused, dtrace_id_t id, void *parg) 2028776669bSMark Johnston { 2038776669bSMark Johnston struct sdt_probe *probe = parg; 2048776669bSMark Johnston 2058776669bSMark Johnston probe->id = id; 2068776669bSMark Johnston probe->sdtp_lf->nenabled++; 20732cd0147SMark Johnston if (strcmp(probe->prov->name, "lockstat") == 0) 20832cd0147SMark Johnston lockstat_enabled++; 2098776669bSMark Johnston } 2108776669bSMark Johnston 2118776669bSMark Johnston static void 2128776669bSMark Johnston sdt_disable(void *arg __unused, dtrace_id_t id, void *parg) 2138776669bSMark Johnston { 2148776669bSMark Johnston struct sdt_probe *probe = parg; 2158776669bSMark Johnston 2168776669bSMark Johnston KASSERT(probe->sdtp_lf->nenabled > 0, ("no probes enabled")); 2178776669bSMark Johnston 21832cd0147SMark Johnston if (strcmp(probe->prov->name, "lockstat") == 0) 21932cd0147SMark Johnston lockstat_enabled--; 2208776669bSMark Johnston probe->id = 0; 2218776669bSMark Johnston probe->sdtp_lf->nenabled--; 2228776669bSMark Johnston } 2238776669bSMark Johnston 2248776669bSMark Johnston static void 2258776669bSMark Johnston sdt_getargdesc(void *arg, dtrace_id_t id, void *parg, dtrace_argdesc_t *desc) 2268776669bSMark Johnston { 2278776669bSMark Johnston struct sdt_argtype *argtype; 2288776669bSMark Johnston struct sdt_probe *probe = parg; 2298776669bSMark Johnston 2309c06d5a0SMark Johnston if (desc->dtargd_ndx >= probe->n_args) { 2319c06d5a0SMark Johnston desc->dtargd_ndx = DTRACE_ARGNONE; 2329c06d5a0SMark Johnston return; 2339c06d5a0SMark Johnston } 2349c06d5a0SMark Johnston 2358776669bSMark Johnston TAILQ_FOREACH(argtype, &probe->argtype_list, argtype_entry) { 2368776669bSMark Johnston if (desc->dtargd_ndx == argtype->ndx) { 2378776669bSMark Johnston desc->dtargd_mapping = desc->dtargd_ndx; 2389c06d5a0SMark Johnston if (argtype->type == NULL) { 2399c06d5a0SMark Johnston desc->dtargd_native[0] = '\0'; 2409c06d5a0SMark Johnston desc->dtargd_xlate[0] = '\0'; 2419c06d5a0SMark Johnston continue; 2429c06d5a0SMark Johnston } 2438776669bSMark Johnston strlcpy(desc->dtargd_native, argtype->type, 2448776669bSMark Johnston sizeof(desc->dtargd_native)); 2457bc992c0SMark Johnston if (argtype->xtype != NULL) 2469c06d5a0SMark Johnston strlcpy(desc->dtargd_xlate, argtype->xtype, 2477bc992c0SMark Johnston sizeof(desc->dtargd_xlate)); 2488776669bSMark Johnston } 2498776669bSMark Johnston } 25091eaf3e1SJohn Birrell } 25191eaf3e1SJohn Birrell 25291eaf3e1SJohn Birrell static void 25391eaf3e1SJohn Birrell sdt_destroy(void *arg, dtrace_id_t id, void *parg) 25491eaf3e1SJohn Birrell { 2558776669bSMark Johnston } 2568776669bSMark Johnston 2578776669bSMark Johnston /* 2588776669bSMark Johnston * Called from the kernel linker when a module is loaded, before 2598776669bSMark Johnston * dtrace_module_loaded() is called. This is done so that it's possible to 2609c06d5a0SMark Johnston * register new providers when modules are loaded. The DTrace framework 2619c06d5a0SMark Johnston * explicitly disallows calling into the framework from the provide_module 2629c06d5a0SMark Johnston * provider method, so we cannot do this there. 2638776669bSMark Johnston */ 2648776669bSMark Johnston static void 26512ede07aSMark Johnston sdt_kld_load(void *arg __unused, struct linker_file *lf) 2668776669bSMark Johnston { 2678776669bSMark Johnston struct sdt_provider **prov, **begin, **end; 2688776669bSMark Johnston struct sdt_probe **probe, **p_begin, **p_end; 2698776669bSMark Johnston struct sdt_argtype **argtype, **a_begin, **a_end; 2708776669bSMark Johnston 2719338d208SMark Johnston if (linker_file_lookup_set(lf, "sdt_providers_set", &begin, &end, 2729338d208SMark Johnston NULL) == 0) { 2738776669bSMark Johnston for (prov = begin; prov < end; prov++) 2748776669bSMark Johnston sdt_create_provider(*prov); 2759338d208SMark Johnston } 2768776669bSMark Johnston 2778776669bSMark Johnston if (linker_file_lookup_set(lf, "sdt_probes_set", &p_begin, &p_end, 2789338d208SMark Johnston NULL) == 0) { 2798776669bSMark Johnston for (probe = p_begin; probe < p_end; probe++) { 2808776669bSMark Johnston (*probe)->sdtp_lf = lf; 2818776669bSMark Johnston sdt_create_probe(*probe); 2828776669bSMark Johnston TAILQ_INIT(&(*probe)->argtype_list); 2838776669bSMark Johnston } 2849338d208SMark Johnston } 2858776669bSMark Johnston 2868776669bSMark Johnston if (linker_file_lookup_set(lf, "sdt_argtypes_set", &a_begin, &a_end, 2879338d208SMark Johnston NULL) == 0) { 2888776669bSMark Johnston for (argtype = a_begin; argtype < a_end; argtype++) { 2898776669bSMark Johnston (*argtype)->probe->n_args++; 2909338d208SMark Johnston TAILQ_INSERT_TAIL(&(*argtype)->probe->argtype_list, 2919338d208SMark Johnston *argtype, argtype_entry); 2929338d208SMark Johnston } 2938776669bSMark Johnston } 29491eaf3e1SJohn Birrell } 29591eaf3e1SJohn Birrell 29691eaf3e1SJohn Birrell static void 2979c06d5a0SMark Johnston sdt_kld_unload_try(void *arg __unused, struct linker_file *lf, int *error) 29891eaf3e1SJohn Birrell { 2998776669bSMark Johnston struct sdt_provider *prov, **curr, **begin, **end, *tmp; 30091eaf3e1SJohn Birrell 3018776669bSMark Johnston if (*error != 0) 3028776669bSMark Johnston /* We already have an error, so don't do anything. */ 3038776669bSMark Johnston return; 3049c06d5a0SMark Johnston else if (linker_file_lookup_set(lf, "sdt_providers_set", &begin, &end, 3059c06d5a0SMark Johnston NULL)) 30612ede07aSMark Johnston /* No DTrace providers are declared in this file. */ 3078776669bSMark Johnston return; 3088776669bSMark Johnston 3098776669bSMark Johnston /* 31012ede07aSMark Johnston * Go through all the providers declared in this linker file and 31112ede07aSMark Johnston * unregister any that aren't declared in another loaded file. 3128776669bSMark Johnston */ 3138776669bSMark Johnston for (curr = begin; curr < end; curr++) { 3148776669bSMark Johnston TAILQ_FOREACH_SAFE(prov, &sdt_prov_list, prov_entry, tmp) { 3159c06d5a0SMark Johnston if (strcmp(prov->name, (*curr)->name) != 0) 3169c06d5a0SMark Johnston continue; 3179c06d5a0SMark Johnston 3188776669bSMark Johnston if (prov->sdt_refs == 1) { 3199c06d5a0SMark Johnston if (dtrace_unregister(prov->id) != 0) { 3209c06d5a0SMark Johnston *error = 1; 3219c06d5a0SMark Johnston return; 3229c06d5a0SMark Johnston } 3239c06d5a0SMark Johnston TAILQ_REMOVE(&sdt_prov_list, prov, prov_entry); 3248776669bSMark Johnston free(prov->name, M_SDT); 3258776669bSMark Johnston free(prov, M_SDT); 3268776669bSMark Johnston } else 3278776669bSMark Johnston prov->sdt_refs--; 3288776669bSMark Johnston break; 32991eaf3e1SJohn Birrell } 3308776669bSMark Johnston } 3318776669bSMark Johnston } 33291eaf3e1SJohn Birrell 33391eaf3e1SJohn Birrell static int 3348776669bSMark Johnston sdt_linker_file_cb(linker_file_t lf, void *arg __unused) 33591eaf3e1SJohn Birrell { 3368776669bSMark Johnston 33712ede07aSMark Johnston sdt_kld_load(NULL, lf); 3388776669bSMark Johnston 3398776669bSMark Johnston return (0); 34091eaf3e1SJohn Birrell } 34191eaf3e1SJohn Birrell 34291eaf3e1SJohn Birrell static void 3439c06d5a0SMark Johnston sdt_load() 34491eaf3e1SJohn Birrell { 3458776669bSMark Johnston 3468776669bSMark Johnston TAILQ_INIT(&sdt_prov_list); 3478776669bSMark Johnston 34891eaf3e1SJohn Birrell sdt_probe_func = dtrace_probe; 34991eaf3e1SJohn Birrell 35012ede07aSMark Johnston sdt_kld_load_tag = EVENTHANDLER_REGISTER(kld_load, sdt_kld_load, NULL, 3518776669bSMark Johnston EVENTHANDLER_PRI_ANY); 35229f4e216SMark Johnston sdt_kld_unload_try_tag = EVENTHANDLER_REGISTER(kld_unload_try, 35329f4e216SMark Johnston sdt_kld_unload_try, NULL, EVENTHANDLER_PRI_ANY); 3548776669bSMark Johnston 35512ede07aSMark Johnston /* Pick up probes from the kernel and already-loaded linker files. */ 3568776669bSMark Johnston linker_file_foreach(sdt_linker_file_cb, NULL); 35791eaf3e1SJohn Birrell } 35891eaf3e1SJohn Birrell 35991eaf3e1SJohn Birrell static int 3609c06d5a0SMark Johnston sdt_unload() 36191eaf3e1SJohn Birrell { 3628776669bSMark Johnston struct sdt_provider *prov, *tmp; 3639c06d5a0SMark Johnston int ret; 36491eaf3e1SJohn Birrell 36512ede07aSMark Johnston EVENTHANDLER_DEREGISTER(kld_load, sdt_kld_load_tag); 36629f4e216SMark Johnston EVENTHANDLER_DEREGISTER(kld_unload_try, sdt_kld_unload_try_tag); 36791eaf3e1SJohn Birrell 36891eaf3e1SJohn Birrell sdt_probe_func = sdt_probe_stub; 36991eaf3e1SJohn Birrell 3708776669bSMark Johnston TAILQ_FOREACH_SAFE(prov, &sdt_prov_list, prov_entry, tmp) { 3719c06d5a0SMark Johnston ret = dtrace_unregister(prov->id); 3729c06d5a0SMark Johnston if (ret != 0) 3739c06d5a0SMark Johnston return (ret); 3748776669bSMark Johnston TAILQ_REMOVE(&sdt_prov_list, prov, prov_entry); 3758776669bSMark Johnston free(prov->name, M_SDT); 3768776669bSMark Johnston free(prov, M_SDT); 3778776669bSMark Johnston } 37891eaf3e1SJohn Birrell 3798776669bSMark Johnston return (0); 38091eaf3e1SJohn Birrell } 38191eaf3e1SJohn Birrell 38291eaf3e1SJohn Birrell static int 38391eaf3e1SJohn Birrell sdt_modevent(module_t mod __unused, int type, void *data __unused) 38491eaf3e1SJohn Birrell { 38591eaf3e1SJohn Birrell int error = 0; 38691eaf3e1SJohn Birrell 38791eaf3e1SJohn Birrell switch (type) { 38891eaf3e1SJohn Birrell case MOD_LOAD: 3899c06d5a0SMark Johnston sdt_load(); 39091eaf3e1SJohn Birrell break; 39191eaf3e1SJohn Birrell 39291eaf3e1SJohn Birrell case MOD_UNLOAD: 3939c06d5a0SMark Johnston error = sdt_unload(); 39491eaf3e1SJohn Birrell break; 39591eaf3e1SJohn Birrell 39691eaf3e1SJohn Birrell case MOD_SHUTDOWN: 39791eaf3e1SJohn Birrell break; 39891eaf3e1SJohn Birrell 39991eaf3e1SJohn Birrell default: 40091eaf3e1SJohn Birrell error = EOPNOTSUPP; 40191eaf3e1SJohn Birrell break; 40291eaf3e1SJohn Birrell } 40391eaf3e1SJohn Birrell 40491eaf3e1SJohn Birrell return (error); 40591eaf3e1SJohn Birrell } 40691eaf3e1SJohn Birrell 40791eaf3e1SJohn Birrell DEV_MODULE(sdt, sdt_modevent, NULL); 40891eaf3e1SJohn Birrell MODULE_VERSION(sdt, 1); 40991eaf3e1SJohn Birrell MODULE_DEPEND(sdt, dtrace, 1, 1, 1); 41091eaf3e1SJohn Birrell MODULE_DEPEND(sdt, opensolaris, 1, 1, 1); 411