summaryrefslogtreecommitdiff
path: root/sys/kern/kern_malloc.c
diff options
context:
space:
mode:
authorRobert Watson <rwatson@FreeBSD.org>2009-04-19 12:41:37 +0000
committerRobert Watson <rwatson@FreeBSD.org>2009-04-19 12:41:37 +0000
commitbb1c7df80f24ca50cc78e206277dbca35b69d5cb (patch)
treee9fa72d568313ed26b10f9d838cb9923b24b884b /sys/kern/kern_malloc.c
parenteb7bba19c56a0edf961c0b09b45e3e52b0f8da12 (diff)
Notes
Diffstat (limited to 'sys/kern/kern_malloc.c')
-rw-r--r--sys/kern/kern_malloc.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c
index 8c627a1639b7..7bb5a8105260 100644
--- a/sys/kern/kern_malloc.c
+++ b/sys/kern/kern_malloc.c
@@ -1,7 +1,7 @@
/*-
* Copyright (c) 1987, 1991, 1993
* The Regents of the University of California.
- * Copyright (c) 2005-2006 Robert N. M. Watson
+ * Copyright (c) 2005-2009 Robert N. M. Watson
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -334,6 +334,7 @@ malloc(unsigned long size, struct malloc_type *mtp, int flags)
#endif
#ifdef INVARIANTS
+ KASSERT(mtp->ks_magic == M_MAGIC, ("malloc: bad malloc type magic"));
/*
* Check that exactly one of M_WAITOK or M_NOWAIT is specified.
*/
@@ -419,6 +420,8 @@ free(void *addr, struct malloc_type *mtp)
uma_slab_t slab;
u_long size;
+ KASSERT(mtp->ks_magic == M_MAGIC, ("free: bad malloc type magic"));
+
/* free(NULL, ...) does nothing */
if (addr == NULL)
return;
@@ -480,6 +483,9 @@ realloc(void *addr, unsigned long size, struct malloc_type *mtp, int flags)
unsigned long alloc;
void *newaddr;
+ KASSERT(mtp->ks_magic == M_MAGIC,
+ ("realloc: bad malloc type magic"));
+
/* realloc(NULL, ...) is equivalent to malloc(...) */
if (addr == NULL)
return (malloc(size, mtp, flags));
@@ -673,6 +679,9 @@ malloc_init(void *data)
KASSERT(cnt.v_page_count != 0, ("malloc_register before vm_init"));
mtp = data;
+ KASSERT(mtp->ks_magic == M_MAGIC,
+ ("malloc_init: bad malloc type magic"));
+
mtip = uma_zalloc(mt_zone, M_WAITOK | M_ZERO);
mtp->ks_handle = mtip;
@@ -694,7 +703,10 @@ malloc_uninit(void *data)
int i;
mtp = data;
+ KASSERT(mtp->ks_magic == M_MAGIC,
+ ("malloc_uninit: bad malloc type magic"));
KASSERT(mtp->ks_handle != NULL, ("malloc_deregister: cookie NULL"));
+
mtx_lock(&malloc_mtx);
mtip = mtp->ks_handle;
mtp->ks_handle = NULL;