4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
28 dtrace_state_t *state;
31 destroy_dev(dtrace_dev);
32 destroy_dev(helper_dev);
34 mutex_enter(&dtrace_provider_lock);
35 mutex_enter(&dtrace_lock);
36 mutex_enter(&cpu_lock);
38 ASSERT(dtrace_opens == 0);
40 if (dtrace_helpers > 0) {
41 mutex_exit(&cpu_lock);
42 mutex_exit(&dtrace_lock);
43 mutex_exit(&dtrace_provider_lock);
47 if (dtrace_unregister((dtrace_provider_id_t)dtrace_provider) != 0) {
48 mutex_exit(&cpu_lock);
49 mutex_exit(&dtrace_lock);
50 mutex_exit(&dtrace_provider_lock);
54 dtrace_provider = NULL;
55 EVENTHANDLER_DEREGISTER(kld_load, dtrace_kld_load_tag);
56 EVENTHANDLER_DEREGISTER(kld_unload_try, dtrace_kld_unload_try_tag);
58 if ((state = dtrace_anon_grab()) != NULL) {
60 * If there were ECBs on this state, the provider should
61 * have not been allowed to detach; assert that there is
64 ASSERT(state->dts_necbs == 0);
65 dtrace_state_destroy(state);
68 bzero(&dtrace_anon, sizeof (dtrace_anon_t));
70 mutex_exit(&cpu_lock);
72 if (dtrace_probes != NULL) {
73 kmem_free(dtrace_probes, 0);
78 dtrace_hash_destroy(dtrace_bymod);
79 dtrace_hash_destroy(dtrace_byfunc);
80 dtrace_hash_destroy(dtrace_byname);
85 kmem_cache_destroy(dtrace_state_cache);
87 delete_unrhdr(dtrace_arena);
89 if (dtrace_toxrange != NULL) {
90 kmem_free(dtrace_toxrange, 0);
91 dtrace_toxrange = NULL;
93 dtrace_toxranges_max = 0;
96 ASSERT(dtrace_vtime_references == 0);
97 ASSERT(dtrace_opens == 0);
98 ASSERT(dtrace_retained == NULL);
100 mutex_exit(&dtrace_lock);
101 mutex_exit(&dtrace_provider_lock);
103 mutex_destroy(&dtrace_meta_lock);
104 mutex_destroy(&dtrace_provider_lock);
105 mutex_destroy(&dtrace_lock);
107 mutex_destroy(&dtrace_errlock);
110 taskq_destroy(dtrace_taskq);
112 /* Reset our hook for exceptions. */
113 dtrace_invop_uninit();
116 * Reset our hook for thread switches, but ensure that vtime isn't
119 dtrace_vtime_active = 0;
120 dtrace_vtime_switch_func = NULL;
122 /* Unhook from the trap handler. */
123 dtrace_trap_func = NULL;