-/* $OpenBSD: uvm_addr.c,v 1.16 2016/06/02 18:48:01 tedu Exp $ */
+/* $OpenBSD: uvm_addr.c,v 1.17 2016/07/30 16:37:54 kettenis Exp $ */
/*
* Copyright (c) 2011 Ariane van der Steldt <ariane@stack.nl>
if (low_addr > high_addr)
return ENOMEM;
fspace = high_addr - low_addr;
- if (fspace < sz + before_gap + after_gap)
+ if (fspace < before_gap + after_gap)
+ return ENOMEM;
+ if (fspace - before_gap - after_gap < sz)
return ENOMEM;
/* Calculate lowest address. */
/* Deal with guardpages: search for space with one extra page. */
guard_sz = ((map->flags & VM_MAP_GUARDPAGES) == 0 ? 0 : PAGE_SIZE);
- if (uaddr->uaddr_maxaddr - uaddr->uaddr_minaddr < sz + guard_sz)
+ if (uaddr->uaddr_maxaddr - uaddr->uaddr_minaddr - guard_sz < sz)
return ENOMEM;
return uvm_addr_linsearch(map, uaddr, entry_out, addr_out, 0, sz,
align, offset, 1, uaddr->uaddr_minaddr, uaddr->uaddr_maxaddr - sz,
/* Deal with guardpages: search for space with one extra page. */
guard_sz = ((map->flags & VM_MAP_GUARDPAGES) == 0 ? 0 : PAGE_SIZE);
+ if (uaddr->uaddr_maxaddr - guard_sz < sz)
+ return ENOMEM;
minaddr = uvm_addr_align_forward(uaddr->uaddr_minaddr, align, offset);
maxaddr = uvm_addr_align_backward(uaddr->uaddr_maxaddr - sz - guard_sz,
align, offset);
uaddr = (struct uaddr_bestfit_state *)uaddr_p;
guardsz = ((map->flags & VM_MAP_GUARDPAGES) ? PAGE_SIZE : 0);
+ if (sz + guardsz < sz)
+ return ENOMEM;
/*
* Find smallest item on freelist capable of holding item.