dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / mdb / common / kmdb / kctl / kctl_mod.c
blob8a66af6a7ff8f4c5a2a73dcac6f7fffb71b24160
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
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>
32 #include <sys/kobj.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 },
39 { NULL, 0 }
42 int
43 kctl_mod_decompress(struct modctl *modp)
45 ctf_file_t *fp;
46 struct module *mp = modp->mod_mp;
47 int rc;
49 if ((kmdb_kdi_get_flags() & KMDB_KDI_FL_NOCTF) || mp->ctfdata == NULL)
50 return (0);
52 if ((fp = ctf_modopen(mp, &rc)) == NULL)
53 return (rc);
55 ctf_close(fp);
57 return (0);
60 void
61 kctl_mod_loaded(struct modctl *modp)
63 int rc;
65 mutex_enter(&mod_lock);
66 if (modp->mod_mp == NULL) {
67 mutex_exit(&mod_lock);
68 return;
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);
81 /*ARGSUSED*/
82 void
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
92 void
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);
101 void
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);