diff options
author | 2004-06-20 01:04:28 +0000 | |
---|---|---|
committer | 2004-06-20 01:04:28 +0000 | |
commit | 808b8ed520c76191c575bb9e6b561200f8e579e2 (patch) | |
tree | 15fada9af721f8cdeb339deddf88aa0cfc7de83c /sys/kern/kern_malloc_debug.c | |
parent | undo mbuf cluster breakage that causes free'ed packets to show up on the (diff) | |
download | wireguard-openbsd-808b8ed520c76191c575bb9e6b561200f8e579e2.tar.xz wireguard-openbsd-808b8ed520c76191c575bb9e6b561200f8e579e2.zip |
Fix inversed logic in handling the "nowait/waitok" flags. Bugs in two places
in malloc_debug.
Also, add an assert-like function to sprinkle in code you're debugging at the
moment. Those asserts are _not_ supposed to be ever comitted, just use them
while debugging.
beck@ ok
Diffstat (limited to 'sys/kern/kern_malloc_debug.c')
-rw-r--r-- | sys/kern/kern_malloc_debug.c | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/sys/kern/kern_malloc_debug.c b/sys/kern/kern_malloc_debug.c index 544d9f56fa9..dcd39cfeb49 100644 --- a/sys/kern/kern_malloc_debug.c +++ b/sys/kern/kern_malloc_debug.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_malloc_debug.c,v 1.22 2003/06/03 01:27:31 art Exp $ */ +/* $OpenBSD: kern_malloc_debug.c,v 1.23 2004/06/20 01:04:28 art Exp $ */ /* * Copyright (c) 1999, 2000 Artur Grabowski <art@openbsd.org> @@ -109,7 +109,7 @@ int debug_malloc(unsigned long size, int type, int flags, void **addr) { struct debug_malloc_entry *md = NULL; - int s, wait = flags & M_NOWAIT; + int s, wait = (flags & M_NOWAIT) == 0; /* Careful not to compare unsigned long to int -1 */ if (((type != debug_malloc_type && debug_malloc_type != 0) || @@ -241,7 +241,7 @@ debug_malloc_allocate_free(int wait) return; va = uvm_km_kmemalloc(kmem_map, uvmexp.kmem_object, PAGE_SIZE * 2, - UVM_KMF_VALLOC | (wait ? UVM_KMF_NOWAIT : 0)); + UVM_KMF_VALLOC | (wait ? 0: UVM_KMF_NOWAIT)); if (va == 0) { pool_put(&debug_malloc_pool, md); return; @@ -284,6 +284,24 @@ debug_malloc_print(void) } void +debug_malloc_assert_allocated(void *addr, const char *func) +{ + struct debug_malloc_entry *md; + vaddr_t va = (vaddr_t)addr; + + TAILQ_FOREACH(md, &debug_malloc_freelist, md_list) { + if (va >= md->md_va && + va < md->md_va + 2 * PAGE_SIZE) + panic("debug_malloc: (%s): %p - freed", func, addr); + } + TAILQ_FOREACH(md, &debug_malloc_usedlist, md_list) { + if (va >= md->md_va + PAGE_SIZE && + va < md->md_va + 2 * PAGE_SIZE) + panic("debug_malloc: (%s): %p - overflow", func, addr); + } +} + +void debug_malloc_printit(int (*pr)(const char *, ...), vaddr_t addr) { struct debug_malloc_entry *md; |