Changeset View
Changeset View
Standalone View
Standalone View
sys/vm/vm_map.c
Show First 20 Lines • Show All 4,129 Lines • ▼ Show 20 Lines | vm_map_stack_locked(vm_map_t map, vm_offset_t addrbos, vm_size_t max_ssize, | ||||
KASSERT(orient != 0, ("No stack grow direction")); | KASSERT(orient != 0, ("No stack grow direction")); | ||||
KASSERT(orient != (MAP_STACK_GROWS_DOWN | MAP_STACK_GROWS_UP), | KASSERT(orient != (MAP_STACK_GROWS_DOWN | MAP_STACK_GROWS_UP), | ||||
("bi-dir stack")); | ("bi-dir stack")); | ||||
if (addrbos < vm_map_min(map) || | if (addrbos < vm_map_min(map) || | ||||
addrbos + max_ssize > vm_map_max(map) || | addrbos + max_ssize > vm_map_max(map) || | ||||
addrbos + max_ssize <= addrbos) | addrbos + max_ssize <= addrbos) | ||||
return (KERN_INVALID_ADDRESS); | return (KERN_INVALID_ADDRESS); | ||||
sgp = (vm_size_t)stack_guard_page * PAGE_SIZE; | sgp = (curproc->p_flag2 & P2_STKGAP_DISABLE) != 0 ? 0 : | ||||
(vm_size_t)stack_guard_page * PAGE_SIZE; | |||||
if (sgp >= max_ssize) | if (sgp >= max_ssize) | ||||
return (KERN_INVALID_ARGUMENT); | return (KERN_INVALID_ARGUMENT); | ||||
init_ssize = growsize; | init_ssize = growsize; | ||||
if (max_ssize < init_ssize + sgp) | if (max_ssize < init_ssize + sgp) | ||||
init_ssize = max_ssize - sgp; | init_ssize = max_ssize - sgp; | ||||
/* If addr is already mapped, no go */ | /* If addr is already mapped, no go */ | ||||
Show All 34 Lines | vm_map_stack_locked(vm_map_t map, vm_offset_t addrbos, vm_size_t max_ssize, | ||||
KASSERT(new_entry->end == top || new_entry->start == bot, | KASSERT(new_entry->end == top || new_entry->start == bot, | ||||
("Bad entry start/end for new stack entry")); | ("Bad entry start/end for new stack entry")); | ||||
KASSERT((orient & MAP_STACK_GROWS_DOWN) == 0 || | KASSERT((orient & MAP_STACK_GROWS_DOWN) == 0 || | ||||
(new_entry->eflags & MAP_ENTRY_GROWS_DOWN) != 0, | (new_entry->eflags & MAP_ENTRY_GROWS_DOWN) != 0, | ||||
("new entry lacks MAP_ENTRY_GROWS_DOWN")); | ("new entry lacks MAP_ENTRY_GROWS_DOWN")); | ||||
KASSERT((orient & MAP_STACK_GROWS_UP) == 0 || | KASSERT((orient & MAP_STACK_GROWS_UP) == 0 || | ||||
(new_entry->eflags & MAP_ENTRY_GROWS_UP) != 0, | (new_entry->eflags & MAP_ENTRY_GROWS_UP) != 0, | ||||
("new entry lacks MAP_ENTRY_GROWS_UP")); | ("new entry lacks MAP_ENTRY_GROWS_UP")); | ||||
rv = vm_map_insert(map, NULL, 0, gap_bot, gap_top, VM_PROT_NONE, | if (gap_bot != gap_top) { | ||||
VM_PROT_NONE, MAP_CREATE_GUARD | (orient == MAP_STACK_GROWS_DOWN ? | 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)); | MAP_CREATE_STACK_GAP_DN : MAP_CREATE_STACK_GAP_UP)); | ||||
if (rv != KERN_SUCCESS) | if (rv != KERN_SUCCESS) | ||||
(void)vm_map_delete(map, bot, top); | (void)vm_map_delete(map, bot, top); | ||||
} | |||||
dougm: if (gap_bot == gap_top)
return (KERN_SUCCESS);
seems easier than indenting the lines… | |||||
return (rv); | return (rv); | ||||
} | } | ||||
/* | /* | ||||
* Attempts to grow a vm stack entry. Returns KERN_SUCCESS if we | * Attempts to grow a vm stack entry. Returns KERN_SUCCESS if we | ||||
* successfully grow the stack. | * successfully grow the stack. | ||||
*/ | */ | ||||
static int | static int | ||||
Show All 24 Lines | #endif | ||||
* resource limits are applied. | * resource limits are applied. | ||||
*/ | */ | ||||
if (p != initproc && (map != &p->p_vmspace->vm_map || | if (p != initproc && (map != &p->p_vmspace->vm_map || | ||||
p->p_textvp == NULL)) | p->p_textvp == NULL)) | ||||
return (KERN_FAILURE); | return (KERN_FAILURE); | ||||
MPASS(!map->system_map); | MPASS(!map->system_map); | ||||
guard = stack_guard_page * PAGE_SIZE; | guard = (curproc->p_flag2 & P2_STKGAP_DISABLE) != 0 ? 0 : | ||||
stack_guard_page * PAGE_SIZE; | |||||
lmemlim = lim_cur(curthread, RLIMIT_MEMLOCK); | lmemlim = lim_cur(curthread, RLIMIT_MEMLOCK); | ||||
stacklim = lim_cur(curthread, RLIMIT_STACK); | stacklim = lim_cur(curthread, RLIMIT_STACK); | ||||
vmemlim = lim_cur(curthread, RLIMIT_VMEM); | vmemlim = lim_cur(curthread, RLIMIT_VMEM); | ||||
retry: | retry: | ||||
/* If addr is not in a hole for a stack grow area, no need to grow. */ | /* If addr is not in a hole for a stack grow area, no need to grow. */ | ||||
if (gap_entry == NULL && !vm_map_lookup_entry(map, addr, &gap_entry)) | if (gap_entry == NULL && !vm_map_lookup_entry(map, addr, &gap_entry)) | ||||
return (KERN_FAILURE); | return (KERN_FAILURE); | ||||
if ((gap_entry->eflags & MAP_ENTRY_GUARD) == 0) | if ((gap_entry->eflags & MAP_ENTRY_GUARD) == 0) | ||||
▲ Show 20 Lines • Show All 668 Lines • Show Last 20 Lines |
if (gap_bot == gap_top)
seems easier than indenting the lines below.