summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_malloc.c
diff options
context:
space:
mode:
authorjeff <jeff@FreeBSD.org>2002-05-02 09:07:04 +0000
committerjeff <jeff@FreeBSD.org>2002-05-02 09:07:04 +0000
commit6bfc4bdd9687d28dcbb4ee25d5de86b01147a23d (patch)
treed04d4200ce8e73582726b459fe3a5978841495d0 /sys/kern/kern_malloc.c
parentfb737bd04bbaa01e816c020910e4eb4f70ab02bb (diff)
downloadFreeBSD-src-6bfc4bdd9687d28dcbb4ee25d5de86b01147a23d.zip
FreeBSD-src-6bfc4bdd9687d28dcbb4ee25d5de86b01147a23d.tar.gz
Hide a pointer to the malloc_type bucket at the end of the freed memory. If
this memory is modified after it has been freed we can now report it's previous owner.
Diffstat (limited to 'sys/kern/kern_malloc.c')
-rw-r--r--sys/kern/kern_malloc.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c
index d45518a..5e48278 100644
--- a/sys/kern/kern_malloc.c
+++ b/sys/kern/kern_malloc.c
@@ -229,7 +229,25 @@ free(addr, type)
addr, mem);
if (!(slab->us_flags & UMA_SLAB_MALLOC)) {
+#ifdef INVARIANTS
+ struct malloc_type **mtp = addr;
+#endif
size = slab->us_zone->uz_size;
+#ifdef INVARIANTS
+ /*
+ * Cache a pointer to the malloc_type that most recently freed
+ * this memory here. This way we know who is most likely to
+ * have stepped on it later.
+ *
+ * This code assumes that size is a multiple of 8 bytes for
+ * 64 bit machines
+ */
+ mtp = (struct malloc_type **)
+ ((unsigned long)mtp & ~UMA_ALIGN_PTR);
+ mtp += (size - sizeof(struct malloc_type *)) /
+ sizeof(struct malloc_type *);
+ *mtp = type;
+#endif
uma_zfree_arg(slab->us_zone, addr, slab);
} else {
size = slab->us_size;
@@ -398,7 +416,7 @@ kmeminit(dummy)
kmemzones[indx].kz_zone = uma_zcreate(name, size,
#ifdef INVARIANTS
- trash_ctor, trash_dtor, trash_init, trash_fini,
+ mtrash_ctor, mtrash_dtor, mtrash_init, mtrash_fini,
#else
NULL, NULL, NULL, NULL,
#endif
OpenPOWER on IntegriCloud