diff options
author | 2006-11-28 11:14:52 +0000 | |
---|---|---|
committer | 2006-11-28 11:14:52 +0000 | |
commit | c5ec4f66a952082010bd6d7554afd688bbe4fe4d (patch) | |
tree | f41dffe4d5eac159d0c1c13c58bb46049de464b4 /sys/kern/kern_malloc.c | |
parent | Turn OVERRIDE_OPTIONS macro into a function, so that we can put (diff) | |
download | wireguard-openbsd-c5ec4f66a952082010bd6d7554afd688bbe4fe4d.tar.xz wireguard-openbsd-c5ec4f66a952082010bd6d7554afd688bbe4fe4d.zip |
Make malloc() print out a warning message when returning NULL due to
M_CANFAIL, idea from miod@, okay deraadt@
Diffstat (limited to 'sys/kern/kern_malloc.c')
-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"); } |