Module Name: src Committed By: maxv Date: Wed Jun 25 16:35:13 UTC 2014
Modified Files: src/sys/kern: subr_kmem.c Log Message: 1) Make clear that we want the space allocated for the KMEM_SIZE header to be aligned, by using kmem_roundup_size(). There's no functional difference with the current MAX(). 2) If there isn't enough space in the page padding for the red zone, allocate one more page, not just 2 bytes. We only poison 1 or 2 bytes in this page, depending on the space left in the previous page. That way 'allocsz' is properly aligned. Again, there's no functional difference since the shift already handles it correctly. To generate a diff of this commit: cvs rdiff -u -r1.55 -r1.56 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.55 src/sys/kern/subr_kmem.c:1.56 --- src/sys/kern/subr_kmem.c:1.55 Wed Jun 25 16:05:22 2014 +++ src/sys/kern/subr_kmem.c Wed Jun 25 16:35:12 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_kmem.c,v 1.55 2014/06/25 16:05:22 maxv Exp $ */ +/* $NetBSD: subr_kmem.c,v 1.56 2014/06/25 16:35:12 maxv Exp $ */ /*- * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -69,7 +69,7 @@ /* * KMEM_REDZONE: detect overrun bugs. - * Add a 2-byte pattern (allocate some more bytes if needed) at the end + * Add a 2-byte pattern (allocate one more page if needed) at the end * of each allocated buffer. Check this pattern on kmem_free. * * KMEM_POISON: detect modify-after-free bugs. @@ -90,7 +90,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: subr_kmem.c,v 1.55 2014/06/25 16:05:22 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_kmem.c,v 1.56 2014/06/25 16:35:12 maxv Exp $"); #include <sys/param.h> #include <sys/callback.h> @@ -196,7 +196,7 @@ static void kmem_redzone_check(void *p, #endif /* defined(KMEM_REDZONE) */ #if defined(KMEM_SIZE) -#define SIZE_SIZE (MAX(KMEM_ALIGN, sizeof(size_t))) +#define SIZE_SIZE kmem_roundup_size(sizeof(size_t)) static void kmem_size_set(void *, size_t); static void kmem_size_check(void *, size_t); #else @@ -244,8 +244,8 @@ kmem_intr_alloc(size_t requested_size, k #ifdef KMEM_REDZONE if (size - requested_size < REDZONE_SIZE) { /* If there isn't enough space in the page padding, - * allocate two more bytes for the red zone. */ - allocsz += REDZONE_SIZE; + * allocate one more page for the red zone. */ + allocsz += kmem_roundup_size(REDZONE_SIZE); } #endif @@ -322,7 +322,7 @@ kmem_intr_free(void *p, size_t requested #ifdef KMEM_REDZONE if (size - requested_size < REDZONE_SIZE) { - allocsz += REDZONE_SIZE; + allocsz += kmem_roundup_size(REDZONE_SIZE); } #endif