summaryrefslogtreecommitdiff
path: root/sys/kern/kern_malloc.c
diff options
context:
space:
mode:
authorArtur Grabowski <art@cvs.openbsd.org>2000-06-06 20:18:21 +0000
committerArtur Grabowski <art@cvs.openbsd.org>2000-06-06 20:18:21 +0000
commitdf4ef8b8a6e3a5ae6fcf99555606fd2b2d4978ef (patch)
tree0f5fa209150547cbdfcc77975bb096379cc80e98 /sys/kern/kern_malloc.c
parent53362e67cc113df1bdd7eb307573e1532504ad67 (diff)
malloc debugging code. Enabled by option MALLOC_DEBUG.
Make sure you read the docs (malloc(9)) before use.
Diffstat (limited to 'sys/kern/kern_malloc.c')
-rw-r--r--sys/kern/kern_malloc.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c
index 3e1aeb3c0a6..0c0258354ee 100644
--- a/sys/kern/kern_malloc.c
+++ b/sys/kern/kern_malloc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_malloc.c,v 1.19 2000/03/16 22:11:03 art Exp $ */
+/* $OpenBSD: kern_malloc.c,v 1.20 2000/06/06 20:18:20 art Exp $ */
/* $NetBSD: kern_malloc.c,v 1.15.4.2 1996/06/13 17:10:56 cgd Exp $ */
/*
@@ -61,6 +61,12 @@ char *kmembase, *kmemlimit;
char *memname[] = INITKMEMNAMES;
#endif
+#ifdef MALLOC_DEBUG
+extern int debug_malloc __P((unsigned long, int, int, void **));
+extern int debug_free __P((void *, int));
+extern void debug_malloc_init __P((void));
+#endif
+
#ifdef DIAGNOSTIC
/*
* This structure provides a set of masks to catch unaligned frees.
@@ -124,6 +130,12 @@ malloc(size, type, flags)
if (((unsigned long)type) > M_LAST)
panic("malloc - bogus type");
#endif
+
+#ifdef MALLOC_DEBUG
+ if (debug_malloc(size, type, flags, (void **)&va))
+ return ((void *) va);
+#endif
+
indx = BUCKETINDX(size);
kbp = &bucket[indx];
s = splimp();
@@ -319,6 +331,11 @@ free(addr, type)
register struct kmemstats *ksp = &kmemstats[type];
#endif
+#ifdef MALLOC_DEBUG
+ if (debug_free(addr, type))
+ return;
+#endif
+
kup = btokup(addr);
size = 1 << kup->ku_indx;
kbp = &bucket[kup->ku_indx];
@@ -457,4 +474,8 @@ kmeminit()
for (indx = 0; indx < M_LAST; indx++)
kmemstats[indx].ks_limit = npg * PAGE_SIZE * 6 / 10;
#endif
+#ifdef MALLOC_DEBUG
+ debug_malloc_init();
+#endif
}
+