Path: blob/main/sys/cddl/dev/dtrace/dtrace_unload.c
48255 views
/*1* CDDL HEADER START2*3* The contents of this file are subject to the terms of the4* Common Development and Distribution License (the "License").5* You may not use this file except in compliance with the License.6*7* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE8* or http://www.opensolaris.org/os/licensing.9* See the License for the specific language governing permissions10* and limitations under the License.11*12* When distributing Covered Code, include this CDDL HEADER in each13* file and include the License file at usr/src/OPENSOLARIS.LICENSE.14* If applicable, add the following below this CDDL HEADER, with the15* fields enclosed by brackets "[]" replaced with your own identifying16* information: Portions Copyright [yyyy] [name of copyright owner]17*18* CDDL HEADER END19*20*/2122static int23dtrace_unload(void)24{25dtrace_state_t *state;26int error = 0;2728destroy_dev(dtrace_dev);29destroy_dev(helper_dev);3031mutex_enter(&dtrace_provider_lock);32mutex_enter(&dtrace_lock);33mutex_enter(&cpu_lock);3435ASSERT(dtrace_opens == 0);3637if (dtrace_helpers > 0) {38mutex_exit(&cpu_lock);39mutex_exit(&dtrace_lock);40mutex_exit(&dtrace_provider_lock);41return (EBUSY);42}4344if (dtrace_unregister((dtrace_provider_id_t)dtrace_provider) != 0) {45mutex_exit(&cpu_lock);46mutex_exit(&dtrace_lock);47mutex_exit(&dtrace_provider_lock);48return (EBUSY);49}5051dtrace_provider = NULL;52EVENTHANDLER_DEREGISTER(kld_load, dtrace_kld_load_tag);53EVENTHANDLER_DEREGISTER(kld_unload_try, dtrace_kld_unload_try_tag);5455if ((state = dtrace_anon_grab()) != NULL) {56/*57* If there were ECBs on this state, the provider should58* have not been allowed to detach; assert that there is59* none.60*/61ASSERT(state->dts_necbs == 0);62dtrace_state_destroy(state);63}6465bzero(&dtrace_anon, sizeof (dtrace_anon_t));6667mutex_exit(&cpu_lock);6869if (dtrace_probes != NULL) {70kmem_free(dtrace_probes, 0);71dtrace_probes = NULL;72dtrace_nprobes = 0;73}7475dtrace_hash_destroy(dtrace_bymod);76dtrace_hash_destroy(dtrace_byfunc);77dtrace_hash_destroy(dtrace_byname);78dtrace_bymod = NULL;79dtrace_byfunc = NULL;80dtrace_byname = NULL;8182kmem_cache_destroy(dtrace_state_cache);8384delete_unrhdr(dtrace_arena);8586if (dtrace_toxrange != NULL) {87kmem_free(dtrace_toxrange, 0);88dtrace_toxrange = NULL;89dtrace_toxranges = 0;90dtrace_toxranges_max = 0;91}9293ASSERT(dtrace_vtime_references == 0);94ASSERT(dtrace_opens == 0);95ASSERT(dtrace_retained == NULL);9697mutex_exit(&dtrace_lock);98mutex_exit(&dtrace_provider_lock);99100mutex_destroy(&dtrace_meta_lock);101mutex_destroy(&dtrace_provider_lock);102mutex_destroy(&dtrace_lock);103#ifdef DEBUG104mutex_destroy(&dtrace_errlock);105#endif106107taskq_destroy(dtrace_taskq);108109/* Reset our hook for exceptions. */110dtrace_invop_uninit();111112/*113* Reset our hook for thread switches, but ensure that vtime isn't114* active first.115*/116dtrace_vtime_active = 0;117dtrace_vtime_switch_func = NULL;118119/* Unhook from the trap handler. */120dtrace_trap_func = NULL;121122return (error);123}124125126