Author: rwatson Date: Sun Apr 19 12:41:37 2009 New Revision: 191268 URL: http://svn.freebsd.org/changeset/base/191268
Log: struct malloc_type has had a 'magic' field statically initialized to M_MAGIC by MALLOC_DEFINE() for a long time; add assertions that malloc_type's passed to malloc(), free(), etc have that magic set. MFC after: 2 weeks Modified: head/sys/kern/kern_malloc.c Modified: head/sys/kern/kern_malloc.c ============================================================================== --- head/sys/kern/kern_malloc.c Sun Apr 19 11:20:57 2009 (r191267) +++ head/sys/kern/kern_malloc.c Sun Apr 19 12:41:37 2009 (r191268) @@ -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 #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, 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; _______________________________________________ svn-src-all@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/svn-src-all To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"