Changeset View
Changeset View
Standalone View
Standalone View
sys/vm/vm_mmap.c
Show First 20 Lines • Show All 193 Lines • ▼ Show 20 Lines | if (((p->p_flag2 & P2_PROTMAX_ENABLE) != 0 || imply_prot_max) && | ||||
return (prot); | return (prot); | ||||
return (_PROT_ALL); | return (_PROT_ALL); | ||||
} | } | ||||
int | int | ||||
kern_mmap(struct thread *td, uintptr_t addr0, size_t len, int prot, int flags, | kern_mmap(struct thread *td, uintptr_t addr0, size_t len, int prot, int flags, | ||||
int fd, off_t pos) | int fd, off_t pos) | ||||
{ | { | ||||
struct mmap_req mr = { | |||||
.mr_hint = addr0, | |||||
.mr_len = len, | |||||
.mr_prot = prot, | |||||
.mr_flags = flags, | |||||
.mr_fd = fd, | |||||
.mr_pos = pos | |||||
}; | |||||
return (kern_mmap_fpcheck(td, addr0, len, prot, flags, fd, pos, NULL)); | return (kern_mmap_req(td, &mr)); | ||||
} | } | ||||
/* | |||||
* When mmap'ing a file, check_fp_fn may be used for the caller to do any | |||||
* last-minute validation based on the referenced file in a non-racy way. | |||||
*/ | |||||
int | int | ||||
kern_mmap_fpcheck(struct thread *td, uintptr_t addr0, size_t len, int prot, | kern_mmap_req(struct thread *td, const struct mmap_req *mrp) | ||||
int flags, int fd, off_t pos, mmap_check_fp_fn check_fp_fn) | |||||
{ | { | ||||
struct vmspace *vms; | struct vmspace *vms; | ||||
struct file *fp; | struct file *fp; | ||||
struct proc *p; | struct proc *p; | ||||
off_t pos; | |||||
vm_offset_t addr; | vm_offset_t addr; | ||||
vm_size_t pageoff, size; | vm_size_t len, pageoff, size; | ||||
vm_prot_t cap_maxprot; | vm_prot_t cap_maxprot; | ||||
int align, error, max_prot; | int align, error, fd, flags, max_prot, prot; | ||||
cap_rights_t rights; | cap_rights_t rights; | ||||
mmap_check_fp_fn check_fp_fn; | |||||
addr = mrp->mr_hint; | |||||
len = mrp->mr_len; | |||||
prot = mrp->mr_prot; | |||||
flags = mrp->mr_flags; | |||||
fd = mrp->mr_fd; | |||||
pos = mrp->mr_pos; | |||||
check_fp_fn = mrp->mr_check_fp_fn; | |||||
if ((prot & ~(_PROT_ALL | PROT_MAX(_PROT_ALL))) != 0) | if ((prot & ~(_PROT_ALL | PROT_MAX(_PROT_ALL))) != 0) | ||||
return (EINVAL); | return (EINVAL); | ||||
max_prot = PROT_MAX_EXTRACT(prot); | max_prot = PROT_MAX_EXTRACT(prot); | ||||
prot = PROT_EXTRACT(prot); | prot = PROT_EXTRACT(prot); | ||||
if (max_prot != 0 && (max_prot & prot) != prot) | if (max_prot != 0 && (max_prot & prot) != prot) | ||||
return (EINVAL); | return (EINVAL); | ||||
p = td->td_proc; | p = td->td_proc; | ||||
/* | /* | ||||
* Always honor PROT_MAX if set. If not, default to all | * Always honor PROT_MAX if set. If not, default to all | ||||
* permissions unless we're implying maximum permissions. | * permissions unless we're implying maximum permissions. | ||||
*/ | */ | ||||
if (max_prot == 0) | if (max_prot == 0) | ||||
max_prot = kern_mmap_maxprot(p, prot); | max_prot = kern_mmap_maxprot(p, prot); | ||||
vms = p->p_vmspace; | vms = p->p_vmspace; | ||||
fp = NULL; | fp = NULL; | ||||
AUDIT_ARG_FD(fd); | AUDIT_ARG_FD(fd); | ||||
addr = addr0; | |||||
/* | /* | ||||
* Ignore old flags that used to be defined but did not do anything. | * Ignore old flags that used to be defined but did not do anything. | ||||
*/ | */ | ||||
flags &= ~(MAP_RESERVED0020 | MAP_RESERVED0040); | flags &= ~(MAP_RESERVED0020 | MAP_RESERVED0040); | ||||
/* | /* | ||||
* Enforce the constraints. | * Enforce the constraints. | ||||
▲ Show 20 Lines • Show All 1,411 Lines • Show Last 20 Lines |