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 #if __FreeBSD_version < 800039
33 * Check if there is still an event handler callback
37 /* De-register the device cloning event handler. */
38 EVENTHANDLER_DEREGISTER(dev_clone, eh_tag);
41 /* Stop device cloning. */
42 clone_cleanup(&dtrace_clones);
45 destroy_dev(dtrace_dev);
46 destroy_dev(helper_dev);
49 mutex_enter(&dtrace_provider_lock);
50 mutex_enter(&dtrace_lock);
51 mutex_enter(&cpu_lock);
53 ASSERT(dtrace_opens == 0);
55 if (dtrace_helpers > 0) {
56 mutex_exit(&cpu_lock);
57 mutex_exit(&dtrace_lock);
58 mutex_exit(&dtrace_provider_lock);
62 if (dtrace_unregister((dtrace_provider_id_t)dtrace_provider) != 0) {
63 mutex_exit(&cpu_lock);
64 mutex_exit(&dtrace_lock);
65 mutex_exit(&dtrace_provider_lock);
69 dtrace_provider = NULL;
71 if ((state = dtrace_anon_grab()) != NULL) {
73 * If there were ECBs on this state, the provider should
74 * have not been allowed to detach; assert that there is
77 ASSERT(state->dts_necbs == 0);
78 dtrace_state_destroy(state);
81 bzero(&dtrace_anon, sizeof (dtrace_anon_t));
83 mutex_exit(&cpu_lock);
85 if (dtrace_helptrace_enabled) {
86 kmem_free(dtrace_helptrace_buffer, 0);
87 dtrace_helptrace_buffer = NULL;
90 if (dtrace_probes != NULL) {
91 kmem_free(dtrace_probes, 0);
96 dtrace_hash_destroy(dtrace_bymod);
97 dtrace_hash_destroy(dtrace_byfunc);
98 dtrace_hash_destroy(dtrace_byname);
100 dtrace_byfunc = NULL;
101 dtrace_byname = NULL;
103 kmem_cache_destroy(dtrace_state_cache);
105 delete_unrhdr(dtrace_arena);
107 if (dtrace_toxrange != NULL) {
108 kmem_free(dtrace_toxrange, 0);
109 dtrace_toxrange = NULL;
110 dtrace_toxranges = 0;
111 dtrace_toxranges_max = 0;
114 ASSERT(dtrace_vtime_references == 0);
115 ASSERT(dtrace_opens == 0);
116 ASSERT(dtrace_retained == NULL);
118 mutex_exit(&dtrace_lock);
119 mutex_exit(&dtrace_provider_lock);
121 mutex_destroy(&dtrace_meta_lock);
122 mutex_destroy(&dtrace_provider_lock);
123 mutex_destroy(&dtrace_lock);
125 mutex_destroy(&dtrace_errlock);
129 mutex_destroy(&mod_lock);
131 /* Reset our hook for exceptions. */
132 dtrace_invop_uninit();
135 * Reset our hook for thread switches, but ensure that vtime isn't
138 dtrace_vtime_active = 0;
139 dtrace_vtime_switch_func = NULL;
141 /* Unhook from the trap handler. */
142 dtrace_trap_func = NULL;