diff options
author | Pedro Martelletto <pedro@cvs.openbsd.org> | 2006-11-28 11:14:53 +0000 |
---|---|---|
committer | Pedro Martelletto <pedro@cvs.openbsd.org> | 2006-11-28 11:14:53 +0000 |
commit | 2d7ef055d3b5fdb604899868caeced2b797bbcfb (patch) | |
tree | 462c24368b60dffddafffc61807d6a3418380d46 | |
parent | 463487bb60a7b8bd22348240a0e858c346aa4e82 (diff) |
Make malloc() print out a warning message when returning NULL due to
M_CANFAIL, idea from miod@, okay deraadt@
-rw-r--r-- | sys/kern/kern_malloc.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c index 3652ec639d3..b577c483de4 100644 --- a/sys/kern/kern_malloc.c +++ b/sys/kern/kern_malloc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_malloc.c,v 1.64 2006/11/22 18:59:50 thib Exp $ */ +/* $OpenBSD: kern_malloc.c,v 1.65 2006/11/28 11:14:52 pedro Exp $ */ /* $NetBSD: kern_malloc.c,v 1.15.4.2 1996/06/13 17:10:56 cgd Exp $ */ /* @@ -38,6 +38,7 @@ #include <sys/malloc.h> #include <sys/systm.h> #include <sys/sysctl.h> +#include <sys/time.h> #include <uvm/uvm_extern.h> @@ -122,6 +123,11 @@ struct freelist { }; #endif /* DIAGNOSTIC */ +#ifndef SMALL_KERNEL +struct timeval malloc_errintvl = { 5, 0 }; +struct timeval malloc_lasterr; +#endif + /* * Allocate a block of memory */ @@ -152,9 +158,14 @@ malloc(unsigned long size, int type, int flags) #endif if (size > 65535 * PAGE_SIZE) { - if (flags & M_CANFAIL) + if (flags & M_CANFAIL) { +#ifndef SMALL_KERNEL + if (ratecheck(&malloc_lasterr, &malloc_errintvl)) + printf("malloc(): allocation too large, " + "type = %d, size = %lu\n", type, size); +#endif return (NULL); - else + } else panic("malloc: allocation too large"); } |