diff --git a/sys/vm/vm_map.c b/sys/vm/vm_map.c index 656858e2885d..50fc1b9bad75 100644 --- a/sys/vm/vm_map.c +++ b/sys/vm/vm_map.c @@ -2375,6 +2375,13 @@ vm_map_stack (vm_map_t map, vm_offset_t addrbos, vm_size_t max_ssize, return (KERN_NO_SPACE); } + /* If we would blow our VMEM resource limit, no go */ + if (map->size + init_ssize > + curthread->td_proc->p_rlimit[RLIMIT_VMEM].rlim_cur) { + vm_map_unlock(map); + return (KERN_NO_SPACE); + } + /* If we can't accomodate max_ssize in the current mapping, * no go. However, we need to be aware that subsequent user * mappings might map into the space we have reserved for @@ -2518,6 +2525,13 @@ vm_map_growstack (struct proc *p, vm_offset_t addr) ctob(vm->vm_ssize); } + /* If we would blow our VMEM resource limit, no go */ + if (map->size + grow_amount > + curthread->td_proc->p_rlimit[RLIMIT_VMEM].rlim_cur) { + vm_map_unlock_read(map); + return (KERN_NO_SPACE); + } + if (vm_map_lock_upgrade(map)) goto Retry;