Rename kern_mmap_req to kern_mmap

Replace all uses of kern_mmap with kern_mmap_req move the old kern_mmap.
Reand rename kern_mmap_req to kern_mmap                                .

The helper saved some code churn initially, but having multiple
interfaces is sub-optimal.

Obtained from:	CheriBSD
Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D28292
This commit is contained in:
Brooks Davis 2021-01-23 00:08:59 +00:00
parent bfc99943b0
commit 7a1591c1b6
5 changed files with 52 additions and 35 deletions

View File

@ -110,8 +110,14 @@ cloudabi_sys_mem_map(struct thread *td, struct cloudabi_sys_mem_map_args *uap)
if (error != 0)
return (error);
return (kern_mmap(td, (uintptr_t)uap->addr, uap->len, prot, flags,
uap->fd, uap->off));
return (kern_mmap(td, &(struct mmap_req){
.mr_hint = (uintptr_t)uap->addr,
.mr_len = uap->len,
.mr_prot = prot,
.mr_flags = flags,
.mr_fd = uap->fd,
.mr_pos = uap->off,
}));
}
int

View File

@ -502,8 +502,14 @@ freebsd32_mmap(struct thread *td, struct freebsd32_mmap_args *uap)
prot |= PROT_EXEC;
#endif
return (kern_mmap(td, (uintptr_t)uap->addr, uap->len, prot,
uap->flags, uap->fd, PAIR32TO64(off_t, uap->pos)));
return (kern_mmap(td, &(struct mmap_req){
.mr_hint = (uintptr_t)uap->addr,
.mr_len = uap->len,
.mr_prot = prot,
.mr_flags = uap->flags,
.mr_fd = uap->fd,
.mr_pos = PAIR32TO64(off_t, uap->pos),
}));
}
#ifdef COMPAT_FREEBSD6
@ -519,8 +525,14 @@ freebsd6_freebsd32_mmap(struct thread *td,
prot |= PROT_EXEC;
#endif
return (kern_mmap(td, (uintptr_t)uap->addr, uap->len, prot,
uap->flags, uap->fd, PAIR32TO64(off_t, uap->pos)));
return (kern_mmap(td, &(struct mmap_req){
.mr_hint = (uintptr_t)uap->addr,
.mr_len = uap->len,
.mr_prot = prot,
.mr_flags = uap->flags,
.mr_fd = uap->fd,
.mr_pos = PAIR32TO64(off_t, uap->pos),
}));
}
#endif

View File

@ -217,12 +217,12 @@ linux_mmap_common(struct thread *td, uintptr_t addr, size_t len, int prot,
(bsd_flags & MAP_EXCL) == 0) {
mr_fixed = mr;
mr_fixed.mr_flags |= MAP_FIXED | MAP_EXCL;
error = kern_mmap_req(td, &mr_fixed);
error = kern_mmap(td, &mr_fixed);
if (error == 0)
goto out;
}
error = kern_mmap_req(td, &mr);
error = kern_mmap(td, &mr);
out:
LINUX_CTR2(mmap2, "return: %d (%p)", error, td->td_retval[0]);

View File

@ -201,12 +201,10 @@ int kern_mknodat(struct thread *td, int fd, const char *path,
enum uio_seg pathseg, int mode, dev_t dev);
int kern_mlock(struct proc *proc, struct ucred *cred, uintptr_t addr,
size_t len);
int kern_mmap(struct thread *td, uintptr_t addr, size_t len, int prot,
int flags, int fd, off_t pos);
int kern_mmap(struct thread *td, const struct mmap_req *mrp);
int kern_mmap_racct_check(struct thread *td, struct vm_map *map,
vm_size_t size);
int kern_mmap_maxprot(struct proc *p, int prot);
int kern_mmap_req(struct thread *td, const struct mmap_req *mrp);
int kern_mprotect(struct thread *td, uintptr_t addr, size_t size, int prot);
int kern_msgctl(struct thread *, int, int, struct msqid_ds *);
int kern_msgrcv(struct thread *, int, void *, size_t, long, int, long *);

View File

@ -179,8 +179,14 @@ int
sys_mmap(struct thread *td, struct mmap_args *uap)
{
return (kern_mmap(td, (uintptr_t)uap->addr, uap->len, uap->prot,
uap->flags, uap->fd, uap->pos));
return (kern_mmap(td, &(struct mmap_req){
.mr_hint = (uintptr_t)uap->addr,
.mr_len = uap->len,
.mr_prot = uap->prot,
.mr_flags = uap->flags,
.mr_fd = uap->fd,
.mr_pos = uap->pos,
}));
}
int
@ -197,23 +203,7 @@ kern_mmap_maxprot(struct proc *p, int prot)
}
int
kern_mmap(struct thread *td, uintptr_t addr0, size_t len, int prot, int flags,
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_req(td, &mr));
}
int
kern_mmap_req(struct thread *td, const struct mmap_req *mrp)
kern_mmap(struct thread *td, const struct mmap_req *mrp)
{
struct vmspace *vms;
struct file *fp;
@ -442,9 +432,14 @@ kern_mmap_req(struct thread *td, const struct mmap_req *mrp)
int
freebsd6_mmap(struct thread *td, struct freebsd6_mmap_args *uap)
{
return (kern_mmap(td, (uintptr_t)uap->addr, uap->len, uap->prot,
uap->flags, uap->fd, uap->pos));
return (kern_mmap(td, &(struct mmap_req){
.mr_hint = (uintptr_t)uap->addr,
.mr_len = uap->len,
.mr_prot = uap->prot,
.mr_flags = uap->flags,
.mr_fd = uap->fd,
.mr_pos = uap->pos,
}));
}
#endif
@ -496,8 +491,14 @@ ommap(struct thread *td, struct ommap_args *uap)
flags |= MAP_PRIVATE;
if (uap->flags & OMAP_FIXED)
flags |= MAP_FIXED;
return (kern_mmap(td, (uintptr_t)uap->addr, uap->len, prot, flags,
uap->fd, uap->pos));
return (kern_mmap(td, &(struct mmap_req){
.mr_hint = (uintptr_t)uap->addr,
.mr_len = uap->len,
.mr_prot = prot,
.mr_flags = flags,
.mr_fd = uap->fd,
.mr_pos = uap->pos,
}));
}
#endif /* COMPAT_43 */