Module Name: src
Committed By: maxv
Date: Tue Jul 22 07:38:41 UTC 2014
Modified Files:
src/sys/kern: subr_kmem.c
Log Message:
Enable KMEM_REDZONE on DIAGNOSTIC. It will try to catch overflows.
No comment on tech-kern@
To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/sys/kern/subr_kmem.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/kern/subr_kmem.c
diff -u src/sys/kern/subr_kmem.c:1.59 src/sys/kern/subr_kmem.c:1.60
--- src/sys/kern/subr_kmem.c:1.59 Thu Jul 3 08:43:49 2014
+++ src/sys/kern/subr_kmem.c Tue Jul 22 07:38:41 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_kmem.c,v 1.59 2014/07/03 08:43:49 maxv Exp $ */
+/* $NetBSD: subr_kmem.c,v 1.60 2014/07/22 07:38:41 maxv Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -65,13 +65,23 @@
* Prefix each allocations with a fixed-sized, aligned header and record
* the exact user-requested allocation size in it. When freeing, compare
* it with kmem_free's "size" argument.
- */
-
-/*
+ *
* KMEM_REDZONE: detect overrun bugs.
* Add a 2-byte pattern (allocate one more memory chunk if needed) at the
* end of each allocated buffer. Check this pattern on kmem_free.
*
+ * These options are enabled on DIAGNOSTIC.
+ *
+ * |CHUNK|CHUNK|CHUNK|CHUNK|CHUNK|CHUNK|CHUNK|CHUNK|CHUNK|CHUNK|CHUNK|
+ * +-----+-----+-----+-----+-----+-----+-----+-----+-----+---+-+--+--+
+ * |/////| | | | | | | | | |*|**|UU|
+ * |/HSZ/| | | | | | | | | |*|**|UU|
+ * |/////| | | | | | | | | |*|**|UU|
+ * +-----+-----+-----+-----+-----+-----+-----+-----+-----+---+-+--+--+
+ * |Size | Buffer usable by the caller (requested size) |RedZ|Unused\
+ */
+
+/*
* KMEM_POISON: detect modify-after-free bugs.
* Fill freed (in the sense of kmem_free) memory with a garbage pattern.
* Check the pattern on allocation.
@@ -90,7 +100,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_kmem.c,v 1.59 2014/07/03 08:43:49 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_kmem.c,v 1.60 2014/07/22 07:38:41 maxv Exp $");
#include <sys/param.h>
#include <sys/callback.h>
@@ -168,11 +178,11 @@ static size_t kmem_cache_big_maxidx __re
#if defined(DIAGNOSTIC) && defined(_HARDKERNEL)
#define KMEM_SIZE
+#define KMEM_REDZONE
#endif /* defined(DIAGNOSTIC) */
#if defined(DEBUG) && defined(_HARDKERNEL)
#define KMEM_POISON
-#define KMEM_REDZONE
#define KMEM_GUARD
#endif /* defined(DEBUG) */