diff options
author | 2004-12-30 08:28:39 +0000 | |
---|---|---|
committer | 2004-12-30 08:28:39 +0000 | |
commit | bbd99cb42b83d484b859f9f826a30df6c2ef310c (patch) | |
tree | 4cb579f132e0a5d80cceb09496ba9b3a6c899a5d /sys/kern/kern_malloc.c | |
parent | Enable udav now it works on alpha. ok dlg@ (diff) | |
download | wireguard-openbsd-bbd99cb42b83d484b859f9f826a30df6c2ef310c.tar.xz wireguard-openbsd-bbd99cb42b83d484b859f9f826a30df6c2ef310c.zip |
Import M_CANFAIL support from NetBSD, removes a nasty panic during low-mem scenarios, instead generating an ENOMEM backfeed, ok tedu@, prodded by many
Diffstat (limited to 'sys/kern/kern_malloc.c')
-rw-r--r-- | sys/kern/kern_malloc.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c index 65a4d81848b..c4825e43e88 100644 --- a/sys/kern/kern_malloc.c +++ b/sys/kern/kern_malloc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_malloc.c,v 1.58 2004/05/23 19:41:23 tedu Exp $ */ +/* $OpenBSD: kern_malloc.c,v 1.59 2004/12/30 08:28:39 niklas Exp $ */ /* $NetBSD: kern_malloc.c,v 1.15.4.2 1996/06/13 17:10:56 cgd Exp $ */ /* @@ -179,8 +179,9 @@ malloc(size, type, flags) allocsize = 1 << indx; npg = btoc(allocsize); va = (caddr_t) uvm_km_kmemalloc(kmem_map, uvmexp.kmem_object, - (vsize_t)ctob(npg), - (flags & M_NOWAIT) ? UVM_KMF_NOWAIT : 0); + (vsize_t)ctob(npg), + ((flags & M_NOWAIT) ? UVM_KMF_NOWAIT : 0) | + ((flags & M_CANFAIL) ? UVM_KMF_CANFAIL : 0)); if (va == NULL) { /* * Kmem_malloc() can return NULL, even if it can @@ -190,10 +191,10 @@ malloc(size, type, flags) * are completely free and which are in buckets * with too many free elements.) */ - if ((flags & M_NOWAIT) == 0) + if ((flags & (M_NOWAIT|M_CANFAIL)) == 0) panic("malloc: out of space in kmem_map"); splx(s); - return ((void *) NULL); + return (NULL); } #ifdef KMEMSTATS kbp->kb_total += kbp->kb_elmpercl; |