diff options
author | Artur Grabowski <art@cvs.openbsd.org> | 2004-06-20 01:04:29 +0000 |
---|---|---|
committer | Artur Grabowski <art@cvs.openbsd.org> | 2004-06-20 01:04:29 +0000 |
commit | 2830f155af93d3ddafe76e19b4bdbdf18cd9c58e (patch) | |
tree | 532b513fd5130ce53f8f5c00538f4b8ea5f94e86 /sys | |
parent | f66bc73ff05092ed9e54264aa81e2803763e095e (diff) |
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')
-rw-r--r-- | sys/kern/kern_malloc_debug.c | 24 | ||||
-rw-r--r-- | sys/sys/malloc.h | 5 |
2 files changed, 25 insertions, 4 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; diff --git a/sys/sys/malloc.h b/sys/sys/malloc.h index 8e6b0390e07..ce09678777c 100644 --- a/sys/sys/malloc.h +++ b/sys/sys/malloc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: malloc.h,v 1.71 2004/05/14 04:00:33 tedu Exp $ */ +/* $OpenBSD: malloc.h,v 1.72 2004/06/20 01:04:28 art Exp $ */ /* $NetBSD: malloc.h,v 1.39 1998/07/12 19:52:01 augustss Exp $ */ /* @@ -437,6 +437,9 @@ size_t malloc_roundup(size_t); int debug_malloc(unsigned long, int, int, void **); int debug_free(void *, int); void debug_malloc_init(void); +void debug_malloc_assert_allocated(void *, const char *); +#define DEBUG_MALLOC_ASSERT_ALLOCATED(addr) \ + debug_malloc_assert_allocated(addr, __func__) void debug_malloc_print(void); void debug_malloc_printit(int (*)(const char *, ...), vaddr_t); |