Index: sys/compat/cloudabi/cloudabi_mem.c =================================================================== --- sys/compat/cloudabi/cloudabi_mem.c +++ sys/compat/cloudabi/cloudabi_mem.c @@ -29,8 +29,7 @@ #include #include #include - -#include +#include #include @@ -86,16 +85,16 @@ return (EINVAL); } - return (kern_vm_madvise(td, (vm_offset_t)uap->mapping, - uap->mapping_len, behav)); + return (kern_madvise(td, (uintptr_t)uap->mapping, uap->mapping_len, + behav)); } int cloudabi_sys_mem_lock(struct thread *td, struct cloudabi_sys_mem_lock_args *uap) { - return (vm_mlock(td->td_proc, td->td_ucred, uap->mapping, - uap->mapping_len)); + return (kern_mlock(td->td_proc, td->td_ucred, + __DECONST(uintptr_t, uap->mapping), uap->mapping_len)); } int @@ -119,8 +118,8 @@ if (error != 0) return (error); - return (kern_vm_mmap(td, (vm_offset_t)uap->addr, uap->len, prot, - flags, uap->fd, uap->off)); + return (kern_mmap(td, (uintptr_t)uap->addr, uap->len, prot, flags, + uap->fd, uap->off)); } int @@ -134,8 +133,8 @@ if (error != 0) return (error); - return (kern_vm_mprotect(td, (vm_offset_t)uap->mapping, - uap->mapping_len, prot)); + return (kern_mprotect(td, (uintptr_t)uap->mapping, uap->mapping_len, + prot)); } int @@ -157,8 +156,8 @@ if ((uap->flags & CLOUDABI_MS_INVALIDATE) != 0) flags |= MS_INVALIDATE; - return (kern_vm_msync(td, (vm_offset_t)uap->mapping, - uap->mapping_len, flags)); + return (kern_msync(td, (uintptr_t)uap->mapping, uap->mapping_len, + flags)); } int @@ -166,7 +165,8 @@ struct cloudabi_sys_mem_unlock_args *uap) { - return (kern_vm_munlock(td, (vm_offset_t)uap->mapping, uap->mapping_len)); + return (kern_munlock(td, __DECONST(uintptr_t, uap->mapping), + uap->mapping_len)); } int @@ -174,5 +174,5 @@ struct cloudabi_sys_mem_unmap_args *uap) { - return (kern_vm_munmap(td, (vm_offset_t)uap->mapping, uap->mapping_len)); + return (kern_munmap(td, (uintptr_t)uap->mapping, uap->mapping_len)); } Index: sys/compat/freebsd32/freebsd32_misc.c =================================================================== --- sys/compat/freebsd32/freebsd32_misc.c +++ sys/compat/freebsd32/freebsd32_misc.c @@ -456,8 +456,8 @@ if (i386_read_exec && (prot & PROT_READ) != 0) prot |= PROT_EXEC; #endif - return (kern_vm_mprotect(td, (vm_offset_t)PTRIN(uap->addr), - uap->len, prot)); + return (kern_mprotect(td, (uintptr_t)PTRIN(uap->addr), uap->len, + prot)); } int @@ -471,25 +471,25 @@ prot |= PROT_EXEC; #endif - return (kern_vm_mmap(td, (vm_offset_t)uap->addr, uap->len, prot, + return (kern_mmap(td, (uintptr_t)uap->addr, uap->len, prot, uap->flags, uap->fd, PAIR32TO64(off_t, uap->pos))); } #ifdef COMPAT_FREEBSD6 int -freebsd6_freebsd32_mmap(struct thread *td, struct freebsd6_freebsd32_mmap_args *uap) +freebsd6_freebsd32_mmap(struct thread *td, + struct freebsd6_freebsd32_mmap_args *uap) { - struct freebsd32_mmap_args ap; + int prot; - ap.addr = uap->addr; - ap.len = uap->len; - ap.prot = uap->prot; - ap.flags = uap->flags; - ap.fd = uap->fd; - ap.pos1 = uap->pos1; - ap.pos2 = uap->pos2; + prot = uap->prot; +#if defined(__amd64__) + if (i386_read_exec && (prot & PROT_READ)) + prot |= PROT_EXEC; +#endif - return (freebsd32_mmap(td, &ap)); + return (kern_mmap(td, (uintptr_t)uap->addr, uap->len, prot, + uap->flags, uap->fd, PAIR32TO64(off_t, uap->pos))); } #endif Index: sys/compat/linux/linux_misc.c =================================================================== --- sys/compat/linux/linux_misc.c +++ sys/compat/linux/linux_misc.c @@ -623,7 +623,7 @@ if (args->new_len < args->old_len) { addr = args->addr + args->new_len; len = args->old_len - args->new_len; - error = kern_vm_munmap(td, addr, len); + error = kern_munmap(td, addr, len); } td->td_retval[0] = error ? 0 : (uintptr_t)args->addr; @@ -638,7 +638,7 @@ linux_msync(struct thread *td, struct linux_msync_args *args) { - return (kern_vm_msync(td, args->addr, args->len, + return (kern_msync(td, args->addr, args->len, args->fl & ~LINUX_MS_SYNC)); } Index: sys/compat/linux/linux_mmap.c =================================================================== --- sys/compat/linux/linux_mmap.c +++ sys/compat/linux/linux_mmap.c @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -202,7 +203,7 @@ } } - error = kern_vm_mmap(td, addr, len, prot, bsd_flags, fd, pos); + error = kern_mmap(td, addr, len, prot, bsd_flags, fd, pos); LINUX_CTR2(mmap2, "return: %d (%p)", error, td->td_retval[0]); @@ -216,7 +217,7 @@ #if defined(__amd64__) linux_fixup_prot(td, &prot); #endif - return (kern_vm_mprotect(td, addr, len, prot)); + return (kern_mprotect(td, addr, len, prot)); } #if defined(__amd64__) Index: sys/kern/vfs_aio.c =================================================================== --- sys/kern/vfs_aio.c +++ sys/kern/vfs_aio.c @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include @@ -858,12 +859,9 @@ ("%s: opcode %d", __func__, job->uaiocb.aio_lio_opcode)); aio_switch_vmspace(job); - error = vm_mlock(job->userproc, job->cred, - __DEVOLATILE(void *, cb->aio_buf), cb->aio_nbytes); - if (error) - aio_complete(job, -1, error); - else - aio_complete(job, 0, 0); + error = kern_mlock(job->userproc, job->cred, + __DEVOLATILE(uintptr_t, cb->aio_buf), cb->aio_nbytes); + aio_complete(job, error != 0 ? -1 : 0, error); } static void Index: sys/sys/syscallsubr.h =================================================================== --- sys/sys/syscallsubr.h +++ sys/sys/syscallsubr.h @@ -149,15 +149,24 @@ int kern_lseek(struct thread *td, int fd, off_t offset, int whence); int kern_lutimes(struct thread *td, char *path, enum uio_seg pathseg, struct timeval *tptr, enum uio_seg tptrseg); +int kern_madvise(struct thread *td, uintptr_t addr, size_t len, int behav); int kern_mkdirat(struct thread *td, int fd, char *path, enum uio_seg segflg, int mode); int kern_mkfifoat(struct thread *td, int fd, char *path, enum uio_seg pathseg, int mode); int kern_mknodat(struct thread *td, int fd, char *path, enum uio_seg pathseg, int mode, int 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 size, int prot, + int flags, int fd, off_t pos); int kern_msgctl(struct thread *, int, int, struct msqid_ds *); int kern_msgsnd(struct thread *, int, const void *, size_t, int, long); int kern_msgrcv(struct thread *, int, void *, size_t, long, int, long *); +int kern_msync(struct thread *td, uintptr_t addr, size_t size, int flags); +int kern_mprotect(struct thread *td, uintptr_t addr, size_t size, int prot); +int kern_munlock(struct thread *td, uintptr_t addr, size_t size); +int kern_munmap(struct thread *td, uintptr_t addr, size_t size); int kern_nanosleep(struct thread *td, struct timespec *rqt, struct timespec *rmt); int kern_ogetdirentries(struct thread *td, struct ogetdirentries_args *uap, Index: sys/vm/vm_extern.h =================================================================== --- sys/vm/vm_extern.h +++ sys/vm/vm_extern.h @@ -71,16 +71,6 @@ void kmem_init_zero_region(void); void kmeminit(void); -int kern_vm_mmap(struct thread *td, vm_offset_t addr, vm_size_t size, - int prot, int flags, int fd, off_t pos); -int kern_vm_mprotect(struct thread *td, vm_offset_t addr, vm_size_t size, - vm_prot_t prot); -int kern_vm_msync(struct thread *td, vm_offset_t addr, vm_size_t size, - int flags); -int kern_vm_munlock(struct thread *td, vm_offset_t addr, vm_size_t size); -int kern_vm_munmap(struct thread *td, vm_offset_t addr, vm_size_t size); -int kern_vm_madvise(struct thread *td, vm_offset_t addr, vm_size_t len, - int behav); void swapout_procs(int); int kernacc(void *, int, int); int useracc(void *, int, int); @@ -124,6 +114,5 @@ void vm_imgact_unmap_page(struct sf_buf *sf); void vm_thread_dispose(struct thread *td); int vm_thread_new(struct thread *td, int pages); -int vm_mlock(struct proc *, struct ucred *, const void *, size_t); #endif /* _KERNEL */ #endif /* !_VM_EXTERN_H_ */ Index: sys/vm/vm_mmap.c =================================================================== --- sys/vm/vm_mmap.c +++ sys/vm/vm_mmap.c @@ -107,14 +107,8 @@ }; #endif -/* - * MPSAFE - */ -/* ARGSUSED */ int -sys_sbrk(td, uap) - struct thread *td; - struct sbrk_args *uap; +sys_sbrk(struct thread *td, struct sbrk_args *uap) { /* Not yet implemented */ return (EOPNOTSUPP); @@ -126,14 +120,8 @@ }; #endif -/* - * MPSAFE - */ -/* ARGSUSED */ int -sys_sstk(td, uap) - struct thread *td; - struct sstk_args *uap; +sys_sstk(struct thread *td, struct sstk_args *uap) { /* Not yet implemented */ return (EOPNOTSUPP); @@ -147,11 +135,9 @@ #endif int -ogetpagesize(td, uap) - struct thread *td; - struct getpagesize_args *uap; +ogetpagesize(struct thread *td, struct getpagesize_args *uap) { - /* MP SAFE */ + td->td_retval[0] = PAGE_SIZE; return (0); } @@ -183,30 +169,30 @@ }; #endif -/* - * MPSAFE - */ int sys_mmap(struct thread *td, struct mmap_args *uap) { - return (kern_vm_mmap(td, (vm_offset_t)uap->addr, uap->len, - uap->prot, uap->flags, uap->fd, uap->pos)); + return (kern_mmap(td, (uintptr_t)uap->addr, uap->len, uap->prot, + uap->flags, uap->fd, uap->pos)); } int -kern_vm_mmap(struct thread *td, vm_offset_t addr, vm_size_t size, - int prot, int flags, int fd, off_t pos) +kern_mmap(struct thread *td, uintptr_t addr0, size_t size, int prot, int flags, + int fd, off_t pos) { + struct vmspace *vms; struct file *fp; + vm_offset_t addr; vm_size_t pageoff; vm_prot_t cap_maxprot; int align, error; - struct vmspace *vms = td->td_proc->p_vmspace; cap_rights_t rights; + vms = td->td_proc->p_vmspace; fp = NULL; AUDIT_ARG_FD(fd); + addr = addr0; /* * Ignore old flags that used to be defined but did not do anything. @@ -380,8 +366,8 @@ freebsd6_mmap(struct thread *td, struct freebsd6_mmap_args *uap) { - return (kern_vm_mmap(td, (vm_offset_t)uap->addr, uap->len, - uap->prot, uap->flags, uap->fd, uap->pos)); + return (kern_mmap(td, (uintptr_t)uap->addr, uap->len, uap->prot, + uap->flags, uap->fd, uap->pos)); } #endif @@ -435,8 +421,8 @@ flags |= MAP_PRIVATE; if (uap->flags & OMAP_FIXED) flags |= MAP_FIXED; - return (kern_vm_mmap(td, (vm_offset_t)uap->addr, uap->len, - prot, flags, uap->fd, uap->pos)); + return (kern_mmap(td, (uintptr_t)uap->addr, uap->len, prot, flags, + uap->fd, uap->pos)); } #endif /* COMPAT_43 */ @@ -448,24 +434,22 @@ int flags; }; #endif -/* - * MPSAFE - */ int sys_msync(struct thread *td, struct msync_args *uap) { - return (kern_vm_msync(td, (vm_offset_t)uap->addr, uap->len, - uap->flags)); + return (kern_msync(td, (uintptr_t)uap->addr, uap->len, uap->flags)); } int -kern_vm_msync(struct thread *td, vm_offset_t addr, vm_size_t size, int flags) +kern_msync(struct thread *td, uintptr_t addr0, size_t size, int flags) { + vm_offset_t addr; vm_size_t pageoff; vm_map_t map; int rv; + addr = addr0; pageoff = (addr & PAGE_MASK); addr -= pageoff; size += pageoff; @@ -503,30 +487,29 @@ size_t len; }; #endif -/* - * MPSAFE - */ int sys_munmap(struct thread *td, struct munmap_args *uap) { - return (kern_vm_munmap(td, (vm_offset_t)uap->addr, uap->len)); + return (kern_munmap(td, (uintptr_t)uap->addr, uap->len)); } int -kern_vm_munmap(struct thread *td, vm_offset_t addr, vm_size_t size) +kern_munmap(struct thread *td, uintptr_t addr0, size_t size) { #ifdef HWPMC_HOOKS struct pmckern_map_out pkm; vm_map_entry_t entry; bool pmc_handled; #endif + vm_offset_t addr; vm_size_t pageoff; vm_map_t map; if (size == 0) return (EINVAL); + addr = addr0; pageoff = (addr & PAGE_MASK); addr -= pageoff; size += pageoff; @@ -588,23 +571,20 @@ int prot; }; #endif -/* - * MPSAFE - */ int sys_mprotect(struct thread *td, struct mprotect_args *uap) { - return (kern_vm_mprotect(td, (vm_offset_t)uap->addr, uap->len, - uap->prot)); + return (kern_mprotect(td, (uintptr_t)uap->addr, uap->len, uap->prot)); } int -kern_vm_mprotect(struct thread *td, vm_offset_t addr, vm_size_t size, - vm_prot_t prot) +kern_mprotect(struct thread *td, uintptr_t addr0, size_t size, int prot) { + vm_offset_t addr; vm_size_t pageoff; + addr = addr0; prot = (prot & VM_PROT_ALL); pageoff = (addr & PAGE_MASK); addr -= pageoff; @@ -632,13 +612,8 @@ int inherit; }; #endif -/* - * MPSAFE - */ int -sys_minherit(td, uap) - struct thread *td; - struct minherit_args *uap; +sys_minherit(struct thread *td, struct minherit_args *uap) { vm_offset_t addr; vm_size_t size, pageoff; @@ -673,24 +648,18 @@ }; #endif -/* - * MPSAFE - */ int -sys_madvise(td, uap) - struct thread *td; - struct madvise_args *uap; +sys_madvise(struct thread *td, struct madvise_args *uap) { - return (kern_vm_madvise(td, (vm_offset_t)uap->addr, uap->len, - uap->behav)); + return (kern_madvise(td, (uintptr_t)uap->addr, uap->len, uap->behav)); } int -kern_vm_madvise(struct thread *td, vm_offset_t addr, vm_size_t len, int behav) +kern_madvise(struct thread *td, uintptr_t addr0, size_t len, int behav) { - vm_offset_t start, end; vm_map_t map; + vm_offset_t addr, end, start; int flags; /* @@ -713,6 +682,7 @@ * that VM_*_ADDRESS are not constants due to casts (argh). */ map = &td->td_proc->p_vmspace->vm_map; + addr = addr0; if (addr < vm_map_min(map) || addr + len > vm_map_max(map)) return (EINVAL); if ((addr + len) < addr) @@ -738,13 +708,8 @@ }; #endif -/* - * MPSAFE - */ int -sys_mincore(td, uap) - struct thread *td; - struct mincore_args *uap; +sys_mincore(struct thread *td, struct mincore_args *uap) { vm_offset_t addr, first_addr; vm_offset_t end, cend; @@ -994,20 +959,16 @@ size_t len; }; #endif -/* - * MPSAFE - */ int -sys_mlock(td, uap) - struct thread *td; - struct mlock_args *uap; +sys_mlock(struct thread *td, struct mlock_args *uap) { - return (vm_mlock(td->td_proc, td->td_ucred, uap->addr, uap->len)); + return (kern_mlock(td->td_proc, td->td_ucred, + __DECONST(uintptr_t, uap->addr), uap->len)); } int -vm_mlock(struct proc *proc, struct ucred *cred, const void *addr0, size_t len) +kern_mlock(struct proc *proc, struct ucred *cred, uintptr_t addr0, size_t len) { vm_offset_t addr, end, last, start; vm_size_t npages, size; @@ -1018,7 +979,7 @@ error = priv_check_cred(cred, PRIV_VM_MLOCK, 0); if (error) return (error); - addr = (vm_offset_t)addr0; + addr = addr0; size = len; last = addr + size; start = trunc_page(addr); @@ -1066,13 +1027,8 @@ }; #endif -/* - * MPSAFE - */ int -sys_mlockall(td, uap) - struct thread *td; - struct mlockall_args *uap; +sys_mlockall(struct thread *td, struct mlockall_args *uap) { vm_map_t map; int error; @@ -1143,13 +1099,8 @@ }; #endif -/* - * MPSAFE - */ int -sys_munlockall(td, uap) - struct thread *td; - struct munlockall_args *uap; +sys_munlockall(struct thread *td, struct munlockall_args *uap) { vm_map_t map; int error; @@ -1184,20 +1135,17 @@ size_t len; }; #endif -/* - * MPSAFE - */ int sys_munlock(struct thread *td, struct munlock_args *uap) { - return (kern_vm_munlock(td, (vm_offset_t)uap->addr, uap->len)); + return (kern_munlock(td, (uintptr_t)uap->addr, uap->len)); } int -kern_vm_munlock(struct thread *td, vm_offset_t addr, vm_size_t size) +kern_munlock(struct thread *td, uintptr_t addr0, size_t size) { - vm_offset_t end, last, start; + vm_offset_t addr, end, last, start; #ifdef RACCT vm_map_t map; #endif @@ -1206,6 +1154,7 @@ error = priv_check(td, PRIV_VM_MUNLOCK); if (error) return (error); + addr = addr0; last = addr + size; start = trunc_page(addr); end = round_page(last); @@ -1340,8 +1289,6 @@ /* * vm_mmap_cdev() * - * MPSAFE - * * Helper function for vm_mmap. Perform sanity check specific for mmap * operations on cdevs. */