Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern Enable KMEM_SIZE on DIAGNOSTIC. It will catch memor...



details:   https://anonhg.NetBSD.org/src/rev/3117d596010b
branches:  trunk
changeset: 796885:3117d596010b
user:      maxv <maxv%NetBSD.org@localhost>
date:      Mon Jun 23 17:43:42 2014 +0000

description:
Enable KMEM_SIZE on DIAGNOSTIC. It will catch memory corruption bugs due to a
different size given to kmem_alloc() and kmem_free(), with no performance
impact.

diffstat:

 sys/kern/subr_kmem.c |  12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

diffs (43 lines):

diff -r d8b7aff29d7e -r 3117d596010b sys/kern/subr_kmem.c
--- a/sys/kern/subr_kmem.c      Mon Jun 23 17:32:05 2014 +0000
+++ b/sys/kern/subr_kmem.c      Mon Jun 23 17:43:42 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: subr_kmem.c,v 1.52 2014/06/22 17:36:42 maxv Exp $      */
+/*     $NetBSD: subr_kmem.c,v 1.53 2014/06/23 17:43:42 maxv Exp $      */
 
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -60,7 +60,8 @@
  */
 
 /*
- * This allocator has some debug features enabled with "option DEBUG".
+ * This allocator has some debug features enabled with "option DEBUG" and
+ * "option DIAGNOSTIC".
  *
  * KMEM_POISON
  *     Try to detect modify-after-free bugs.
@@ -102,7 +103,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_kmem.c,v 1.52 2014/06/22 17:36:42 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_kmem.c,v 1.53 2014/06/23 17:43:42 maxv Exp $");
 
 #include <sys/param.h>
 #include <sys/callback.h>
@@ -178,10 +179,13 @@
 static pool_cache_t kmem_cache_big[KMEM_CACHE_BIG_COUNT] __cacheline_aligned;
 static size_t kmem_cache_big_maxidx __read_mostly;
 
+#if defined(DIAGNOSTIC) && defined(_HARDKERNEL)
+#define KMEM_SIZE
+#endif /* defined(DIAGNOSTIC) */
+
 #if defined(DEBUG) && defined(_HARDKERNEL)
 #define        KMEM_POISON
 #define        KMEM_REDZONE
-#define        KMEM_SIZE
 #define        KMEM_GUARD
 #endif /* defined(DEBUG) */
 



Home | Main Index | Thread Index | Old Index