1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-25 11:37:56 +00:00

Make stack grow use the same gap as stack create.

Store stack_guard_page * PAGE_SIZE into the gap->next_read field at
the time of the stack creation.  This makes the used guard size
consistent between stack creation and stack grow time.

Suggested by:	alc
Reviewed by:	alc, markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D21384
This commit is contained in:
Konstantin Belousov 2019-08-24 14:29:13 +00:00
parent a3965ba248
commit a7751d328a
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=351453

View File

@ -4189,8 +4189,20 @@ vm_map_stack_locked(vm_map_t map, vm_offset_t addrbos, vm_size_t max_ssize,
rv = vm_map_insert(map, NULL, 0, gap_bot, gap_top, VM_PROT_NONE,
VM_PROT_NONE, MAP_CREATE_GUARD | (orient == MAP_STACK_GROWS_DOWN ?
MAP_CREATE_STACK_GAP_DN : MAP_CREATE_STACK_GAP_UP));
if (rv != KERN_SUCCESS)
if (rv == KERN_SUCCESS) {
/*
* Gap can never successfully handle a fault, so
* read-ahead logic is never used for it. Re-use
* next_read of the gap entry to store
* stack_guard_page for vm_map_growstack().
*/
if (orient == MAP_STACK_GROWS_DOWN)
new_entry->prev->next_read = sgp;
else
new_entry->next->next_read = sgp;
} else {
(void)vm_map_delete(map, bot, top);
}
return (rv);
}
@ -4231,7 +4243,6 @@ vm_map_growstack(vm_map_t map, vm_offset_t addr, vm_map_entry_t gap_entry)
MPASS(!map->system_map);
guard = stack_guard_page * PAGE_SIZE;
lmemlim = lim_cur(curthread, RLIMIT_MEMLOCK);
stacklim = lim_cur(curthread, RLIMIT_STACK);
vmemlim = lim_cur(curthread, RLIMIT_VMEM);
@ -4258,6 +4269,7 @@ vm_map_growstack(vm_map_t map, vm_offset_t addr, vm_map_entry_t gap_entry)
} else {
return (KERN_FAILURE);
}
guard = gap_entry->next_read;
max_grow = gap_entry->end - gap_entry->start;
if (guard > max_grow)
return (KERN_NO_SPACE);