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]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
27 * Tracking of kernel module loads and unloads
30 #include <kmdb/kmdb_kdi.h>
31 #include <kmdb/kctl/kctl.h>
33 #include <sys/kobj_impl.h>
34 #include <sys/ctf_api.h>
36 static kobj_notify_list_t kctl_mod_notifiers
[] = {
37 { kctl_mod_changed
, KOBJ_NOTIFY_MODLOADED
},
38 { kctl_mod_changed
, KOBJ_NOTIFY_MODUNLOADING
},
43 kctl_mod_decompress(struct modctl
*modp
)
46 struct module
*mp
= modp
->mod_mp
;
49 if ((kmdb_kdi_get_flags() & KMDB_KDI_FL_NOCTF
) || mp
->ctfdata
== NULL
)
52 if ((fp
= ctf_modopen(mp
, &rc
)) == NULL
)
61 kctl_mod_loaded(struct modctl
*modp
)
65 mutex_enter(&mod_lock
);
66 if (modp
->mod_mp
== NULL
) {
67 mutex_exit(&mod_lock
);
71 if ((rc
= kctl_mod_decompress(modp
)) != 0) {
72 cmn_err(CE_WARN
, "failed to decompress CTF data for %s: %s\n",
73 modp
->mod_modname
, ctf_errmsg(rc
));
75 mutex_exit(&mod_lock
);
77 if (!(kmdb_kdi_get_flags() & KMDB_KDI_FL_NOMODS
))
78 kctl_dmod_autoload(modp
->mod_modname
);
83 kctl_mod_changed(uint_t why
, struct modctl
*what
)
85 if (why
== KOBJ_NOTIFY_MODLOADED
)
86 kctl_mod_loaded(what
);
90 * Tell krtld to notify kmdb when modules have been loaded and unloaded
93 kctl_mod_notify_reg(void)
95 kobj_notify_list_t
*kn
;
97 for (kn
= kctl_mod_notifiers
; kn
->kn_func
!= NULL
; kn
++)
98 (void) kobj_notify_add(kn
);
102 kctl_mod_notify_unreg(void)
104 kobj_notify_list_t
*kn
;
106 for (kn
= kctl_mod_notifiers
; kn
->kn_func
!= NULL
; kn
++)
107 (void) kobj_notify_remove(kn
);