Use a single, consistent approach to returning success versus failure in
vm_map_madvise(). Previously, vm_map_madvise() used a traditional Unix- style "return (0);" to indicate success in the common case, but Mach- style return values in the edge cases. Since KERN_SUCCESS equals zero, the only problem with this inconsistency was stylistic. vm_map_madvise() has exactly two callers in the entire source tree, and only one of them cares about the return value. That caller, kern_madvise(), can be simplified if vm_map_madvise() consistently uses Unix-style return values. Since vm_map_madvise() uses the variable modify_map as a Boolean, make it one. Eliminate a redundant error check from kern_madvise(). Add a comment explaining where the check is performed. Explicitly note that exec_release_args_kva() doesn't care about vm_map_madvise()'s return value. Since MADV_FREE is passed as the behavior, the return value will always be zero. Reviewed by: kib, markj MFC after: 7 days
This commit is contained in:
parent
bd586ea432
commit
2d5adeeb3e
@ -1380,7 +1380,7 @@ exec_release_args_kva(struct exec_args_kva *argkva, u_int gen)
|
||||
|
||||
base = argkva->addr;
|
||||
if (argkva->gen != gen) {
|
||||
vm_map_madvise(exec_map, base, base + exec_map_entry_size,
|
||||
(void)vm_map_madvise(exec_map, base, base + exec_map_entry_size,
|
||||
MADV_FREE);
|
||||
argkva->gen = gen;
|
||||
}
|
||||
|
@ -2215,7 +2215,7 @@ vm_map_madvise(
|
||||
int behav)
|
||||
{
|
||||
vm_map_entry_t current, entry;
|
||||
int modify_map = 0;
|
||||
bool modify_map;
|
||||
|
||||
/*
|
||||
* Some madvise calls directly modify the vm_map_entry, in which case
|
||||
@ -2232,19 +2232,20 @@ vm_map_madvise(
|
||||
case MADV_NOCORE:
|
||||
case MADV_CORE:
|
||||
if (start == end)
|
||||
return (KERN_SUCCESS);
|
||||
modify_map = 1;
|
||||
return (0);
|
||||
modify_map = true;
|
||||
vm_map_lock(map);
|
||||
break;
|
||||
case MADV_WILLNEED:
|
||||
case MADV_DONTNEED:
|
||||
case MADV_FREE:
|
||||
if (start == end)
|
||||
return (KERN_SUCCESS);
|
||||
return (0);
|
||||
modify_map = false;
|
||||
vm_map_lock_read(map);
|
||||
break;
|
||||
default:
|
||||
return (KERN_INVALID_ARGUMENT);
|
||||
return (EINVAL);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -682,11 +682,6 @@ kern_madvise(struct thread *td, uintptr_t addr0, size_t len, int behav)
|
||||
PROC_SPROTECT, &flags));
|
||||
}
|
||||
|
||||
/*
|
||||
* Check for illegal behavior
|
||||
*/
|
||||
if (behav < 0 || behav > MADV_CORE)
|
||||
return (EINVAL);
|
||||
/*
|
||||
* Check for illegal addresses. Watch out for address wrap... Note
|
||||
* that VM_*_ADDRESS are not constants due to casts (argh).
|
||||
@ -705,9 +700,10 @@ kern_madvise(struct thread *td, uintptr_t addr0, size_t len, int behav)
|
||||
start = trunc_page(addr);
|
||||
end = round_page(addr + len);
|
||||
|
||||
if (vm_map_madvise(map, start, end, behav))
|
||||
return (EINVAL);
|
||||
return (0);
|
||||
/*
|
||||
* vm_map_madvise() checks for illegal values of behav.
|
||||
*/
|
||||
return (vm_map_madvise(map, start, end, behav));
|
||||
}
|
||||
|
||||
#ifndef _SYS_SYSPROTO_H_
|
||||
|
Loading…
Reference in New Issue
Block a user