7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 #pragma ident "%Z%%M% %I% %E% SMI"
28
29 #include <mdb/mdb_param.h>
30 #include <mdb/mdb_modapi.h>
31
32 #include <sys/fs/ufs_inode.h>
33 #include <sys/kmem_impl.h>
34 #include <sys/vmem_impl.h>
35 #include <sys/modctl.h>
36 #include <sys/kobj.h>
37 #include <sys/kobj_impl.h>
38 #include <vm/seg_vn.h>
39 #include <vm/as.h>
40 #include <vm/seg_map.h>
41 #include <mdb/mdb_ctf.h>
42
43 #include "kmem.h"
44 #include "leaky_impl.h"
45
46 /*
47 * This file defines the genunix target for leaky.c. There are three types
48 * of buffers in the kernel's heap: TYPE_VMEM, for kmem_oversize allocations,
261 char name[MODMAXNAMELEN];
262
263 if (m->mod_mp == NULL)
264 return (WALK_NEXT);
265
266 if (mdb_vread(&mod, sizeof (mod), (uintptr_t)m->mod_mp) == -1) {
267 mdb_warn("couldn't read modctl %p's module", addr);
268 return (WALK_NEXT);
269 }
270
271 if (mdb_readstr(name, sizeof (name), (uintptr_t)m->mod_modname) == -1)
272 (void) mdb_snprintf(name, sizeof (name), "0x%p", addr);
273
274 leaky_grep((uintptr_t)m->mod_mp, sizeof (struct module));
275 leaky_grep((uintptr_t)mod.data, mod.data_size);
276 leaky_grep((uintptr_t)mod.bss, mod.bss_size);
277
278 return (WALK_NEXT);
279 }
280
281 static int
282 leaky_thread(uintptr_t addr, const kthread_t *t, unsigned long *pagesize)
283 {
284 uintptr_t size, base = (uintptr_t)t->t_stkbase;
285 uintptr_t stk = (uintptr_t)t->t_stk;
286
287 /*
288 * If this thread isn't in memory, we can't look at its stack. This
289 * may result in false positives, so we print a warning.
290 */
291 if (!(t->t_schedflag & TS_LOAD)) {
292 mdb_printf("findleaks: thread %p's stack swapped out; "
293 "false positives possible\n", addr);
294 return (WALK_NEXT);
295 }
296
297 if (t->t_state != TS_FREE)
298 leaky_grep(base, stk - base);
299
300 /*
301 * There is always gunk hanging out between t_stk and the page
302 * boundary. If this thread structure wasn't kmem allocated,
303 * this will include the thread structure itself. If the thread
304 * _is_ kmem allocated, we'll be able to get to it via allthreads.
305 */
306 size = *pagesize - (stk & (*pagesize - 1));
307
308 leaky_grep(stk, size);
309
310 return (WALK_NEXT);
311 }
312
313 /*ARGSUSED*/
314 static int
315 leaky_kstat(uintptr_t addr, vmem_seg_t *seg, void *ignored)
|
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 #include <mdb/mdb_param.h>
28 #include <mdb/mdb_modapi.h>
29
30 #include <sys/fs/ufs_inode.h>
31 #include <sys/kmem_impl.h>
32 #include <sys/vmem_impl.h>
33 #include <sys/modctl.h>
34 #include <sys/kobj.h>
35 #include <sys/kobj_impl.h>
36 #include <vm/seg_vn.h>
37 #include <vm/as.h>
38 #include <vm/seg_map.h>
39 #include <mdb/mdb_ctf.h>
40
41 #include "kmem.h"
42 #include "leaky_impl.h"
43
44 /*
45 * This file defines the genunix target for leaky.c. There are three types
46 * of buffers in the kernel's heap: TYPE_VMEM, for kmem_oversize allocations,
259 char name[MODMAXNAMELEN];
260
261 if (m->mod_mp == NULL)
262 return (WALK_NEXT);
263
264 if (mdb_vread(&mod, sizeof (mod), (uintptr_t)m->mod_mp) == -1) {
265 mdb_warn("couldn't read modctl %p's module", addr);
266 return (WALK_NEXT);
267 }
268
269 if (mdb_readstr(name, sizeof (name), (uintptr_t)m->mod_modname) == -1)
270 (void) mdb_snprintf(name, sizeof (name), "0x%p", addr);
271
272 leaky_grep((uintptr_t)m->mod_mp, sizeof (struct module));
273 leaky_grep((uintptr_t)mod.data, mod.data_size);
274 leaky_grep((uintptr_t)mod.bss, mod.bss_size);
275
276 return (WALK_NEXT);
277 }
278
279 /*ARGSUSED*/
280 static int
281 leaky_thread(uintptr_t addr, const kthread_t *t, unsigned long *pagesize)
282 {
283 uintptr_t size, base = (uintptr_t)t->t_stkbase;
284 uintptr_t stk = (uintptr_t)t->t_stk;
285
286 if (t->t_state != TS_FREE)
287 leaky_grep(base, stk - base);
288
289 /*
290 * There is always gunk hanging out between t_stk and the page
291 * boundary. If this thread structure wasn't kmem allocated,
292 * this will include the thread structure itself. If the thread
293 * _is_ kmem allocated, we'll be able to get to it via allthreads.
294 */
295 size = *pagesize - (stk & (*pagesize - 1));
296
297 leaky_grep(stk, size);
298
299 return (WALK_NEXT);
300 }
301
302 /*ARGSUSED*/
303 static int
304 leaky_kstat(uintptr_t addr, vmem_seg_t *seg, void *ignored)
|