Mark Kettenis wrote: > > From: "Ted Unangst" <[email protected]> > > Date: Fri, 29 Jul 2016 18:38:20 -0400 > > > > I'm a little confused about the following. > > > > > @@ -520,7 +522,7 @@ uaddr_lin_select(struct vm_map *map, str > > > /* 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, > > > @@ -582,6 +584,8 @@ uaddr_rnd_select(struct vm_map *map, str > > > /* 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); > > > > This one especially. Shouldn't there be a minaddr check? It seems weird to > > compare addresses against sizes. > > Not really that weird. All I'm checking here is that > (uaddr->uaddr_maxaddr - sz - guard_sz) won't underflow because sz is > too large. And that is to prevent that maxaddr becomes larger than > uaddr->uaddr_maxaddr wen the alignment is applied two lines down.
We don't want that to underflow minaddr either, no? Ah, but we check for that just below. strange way of doing things, but such is the way of things.
