FreeBSD virtual memory subsystem code
vm_mmap.c File Reference
#include <sys/cdefs.h>
#include "opt_hwpmc_hooks.h"
#include "opt_vm.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/capsicum.h>
#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/sysproto.h>
#include <sys/elf.h>
#include <sys/filedesc.h>
#include <sys/priv.h>
#include <sys/proc.h>
#include <sys/procctl.h>
#include <sys/racct.h>
#include <sys/resource.h>
#include <sys/resourcevar.h>
#include <sys/rwlock.h>
#include <sys/sysctl.h>
#include <sys/vnode.h>
#include <sys/fcntl.h>
#include <sys/file.h>
#include <sys/mman.h>
#include <sys/mount.h>
#include <sys/conf.h>
#include <sys/stat.h>
#include <sys/syscallsubr.h>
#include <sys/sysent.h>
#include <sys/vmmeter.h>
#include <security/audit/audit.h>
#include <security/mac/mac_framework.h>
#include <vm/vm.h>
#include <vm/vm_param.h>
#include <vm/pmap.h>
#include <vm/vm_map.h>
#include <vm/vm_object.h>
#include <vm/vm_page.h>
#include <vm/vm_pager.h>
#include <vm/vm_pageout.h>
#include <vm/vm_extern.h>
#include <vm/vnode_pager.h>
Include dependency graph for vm_mmap.c:

Go to the source code of this file.

Data Structures

struct  sbrk_args
 
struct  sstk_args
 
struct  mmap_args
 
struct  msync_args
 
struct  munmap_args
 
struct  mprotect_args
 
struct  minherit_args
 
struct  madvise_args
 
struct  mincore_args
 
struct  mlock_args
 
struct  mlockall_args
 
struct  munlockall_args
 
struct  munlock_args
 

Functions

 __FBSDID ("$FreeBSD$")
 
 SYSCTL_INT (_vm, OID_AUTO, old_mlock, CTLFLAG_RWTUN, &old_mlock, 0, "Do not apply RLIMIT_MEMLOCK on mlockall")
 
 SYSCTL_INT (_vm, OID_AUTO, mincore_mapped, CTLFLAG_RWTUN, &mincore_mapped, 0, "mincore reports mappings, not residency")
 
 SYSCTL_INT (_vm, OID_AUTO, imply_prot_max, CTLFLAG_RWTUN, &imply_prot_max, 0, "Imply maximum page protections in mmap() when none are specified")
 
 _Static_assert (MAXPAGESIZES<=4, "MINCORE_SUPER too narrow")
 
int sys_sbrk (struct thread *td, struct sbrk_args *uap)
 
int sys_sstk (struct thread *td, struct sstk_args *uap)
 
int sys_mmap (struct thread *td, struct mmap_args *uap)
 
int kern_mmap_maxprot (struct proc *p, int prot)
 
int kern_mmap (struct thread *td, const struct mmap_req *mrp)
 
int sys_msync (struct thread *td, struct msync_args *uap)
 
int kern_msync (struct thread *td, uintptr_t addr0, size_t size, int flags)
 
int sys_munmap (struct thread *td, struct munmap_args *uap)
 
int kern_munmap (struct thread *td, uintptr_t addr0, size_t size)
 
int sys_mprotect (struct thread *td, struct mprotect_args *uap)
 
int kern_mprotect (struct thread *td, uintptr_t addr0, size_t size, int prot)
 
int sys_minherit (struct thread *td, struct minherit_args *uap)
 
int kern_minherit (struct thread *td, uintptr_t addr0, size_t len, int inherit0)
 
int sys_madvise (struct thread *td, struct madvise_args *uap)
 
int kern_madvise (struct thread *td, uintptr_t addr0, size_t len, int behav)
 
int sys_mincore (struct thread *td, struct mincore_args *uap)
 
int kern_mincore (struct thread *td, uintptr_t addr0, size_t len, char *vec)
 
int sys_mlock (struct thread *td, struct mlock_args *uap)
 
int kern_mlock (struct proc *proc, struct ucred *cred, uintptr_t addr0, size_t len)
 
int sys_mlockall (struct thread *td, struct mlockall_args *uap)
 
int sys_munlockall (struct thread *td, struct munlockall_args *uap)
 
int sys_munlock (struct thread *td, struct munlock_args *uap)
 
int kern_munlock (struct thread *td, uintptr_t addr0, size_t size)
 
int vm_mmap_vnode (struct thread *td, vm_size_t objsize, vm_prot_t prot, vm_prot_t *maxprotp, int *flagsp, struct vnode *vp, vm_ooffset_t *foffp, vm_object_t *objp, boolean_t *writecounted)
 
int vm_mmap_cdev (struct thread *td, vm_size_t objsize, vm_prot_t prot, vm_prot_t *maxprotp, int *flagsp, struct cdev *cdev, struct cdevsw *dsw, vm_ooffset_t *foff, vm_object_t *objp)
 
int vm_mmap (vm_map_t map, vm_offset_t *addr, vm_size_t size, vm_prot_t prot, vm_prot_t maxprot, int flags, objtype_t handle_type, void *handle, vm_ooffset_t foff)
 
int kern_mmap_racct_check (struct thread *td, vm_map_t map, vm_size_t size)
 
int vm_mmap_object (vm_map_t map, vm_offset_t *addr, vm_size_t size, vm_prot_t prot, vm_prot_t maxprot, int flags, vm_object_t object, vm_ooffset_t foff, boolean_t writecounted, struct thread *td)
 
int vm_mmap_to_errno (int rv)
 

Variables

int old_mlock = 0
 
static int mincore_mapped = 1
 
static int imply_prot_max = 0
 

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ _Static_assert()

_Static_assert ( MAXPAGESIZES<=  4,
"MINCORE_SUPER too narrow"   
)

◆ kern_madvise()

int kern_madvise ( struct thread *  td,
uintptr_t  addr0,
size_t  len,
int  behav 
)

Definition at line 766 of file vm_mmap.c.

References vm_map_madvise(), and vm_map_range_valid().

Referenced by sys_madvise().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ kern_mincore()

◆ kern_minherit()

int kern_minherit ( struct thread *  td,
uintptr_t  addr0,
size_t  len,
int  inherit0 
)

Definition at line 723 of file vm_mmap.c.

References KERN_PROTECTION_FAILURE, KERN_SUCCESS, and vm_map_inherit().

Referenced by sys_minherit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ kern_mlock()

int kern_mlock ( struct proc *  proc,
struct ucred *  cred,
uintptr_t  addr0,
size_t  len 
)

Definition at line 1071 of file vm_mmap.c.

References KERN_INVALID_ARGUMENT, KERN_SUCCESS, vm_map::pmap, pmap_wired_count, vm_map_wire(), VM_MAP_WIRE_NOHOLES, VM_MAP_WIRE_USER, and vm_page_max_user_wired.

Referenced by sys_mlock().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ kern_mmap()

int kern_mmap ( struct thread *  td,
const struct mmap_req *  mrp 
)

Definition at line 206 of file vm_mmap.c.

References kern_mmap_maxprot(), vmspace::vm_daddr, vmspace::vm_map, vm_map_range_valid(), vm_mmap_object(), VM_PROT_NONE, and vmspace::vm_taddr.

Referenced by sys_mmap().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ kern_mmap_maxprot()

int kern_mmap_maxprot ( struct proc *  p,
int  prot 
)

Definition at line 193 of file vm_mmap.c.

References imply_prot_max.

Referenced by kern_mmap().

Here is the caller graph for this function:

◆ kern_mmap_racct_check()

int kern_mmap_racct_check ( struct thread *  td,
vm_map_t  map,
vm_size_t  size 
)

Definition at line 1533 of file vm_mmap.c.

References vm_map::flags, MAP_WIREFUTURE, old_mlock, vm_map::pmap, pmap_wired_count, and vm_map::size.

Referenced by vm_mmap_object().

Here is the caller graph for this function:

◆ kern_mprotect()

int kern_mprotect ( struct thread *  td,
uintptr_t  addr0,
size_t  size,
int  prot 
)

Definition at line 663 of file vm_mmap.c.

References KERN_OUT_OF_BOUNDS, KERN_PROTECTION_FAILURE, KERN_RESOURCE_SHORTAGE, KERN_SUCCESS, vm_map_protect(), VM_MAP_PROTECT_SET_MAXPROT, and VM_MAP_PROTECT_SET_PROT.

Referenced by sys_mprotect().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ kern_msync()

int kern_msync ( struct thread *  td,
uintptr_t  addr0,
size_t  size,
int  flags 
)

Definition at line 531 of file vm_mmap.c.

References KERN_FAILURE, KERN_INVALID_ADDRESS, KERN_INVALID_ARGUMENT, KERN_SUCCESS, and vm_map_sync().

Referenced by sys_msync().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ kern_munlock()

int kern_munlock ( struct thread *  td,
uintptr_t  addr0,
size_t  size 
)

Definition at line 1252 of file vm_mmap.c.

References KERN_SUCCESS, vm_map::pmap, pmap_wired_count, vm_map_unwire(), VM_MAP_WIRE_NOHOLES, and VM_MAP_WIRE_USER.

Referenced by sys_munlock().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ kern_munmap()

int kern_munmap ( struct thread *  td,
uintptr_t  addr0,
size_t  size 
)

Definition at line 584 of file vm_mmap.c.

References KERN_SUCCESS, vm_map_check_protection(), vm_map_delete(), vm_map_entry_succ(), vm_map_lock, vm_map_lock_downgrade, vm_map_lookup_entry(), vm_map_range_valid(), vm_map_unlock, vm_map_unlock_read, vm_mmap_to_errno(), and VM_PROT_EXECUTE.

Referenced by sys_munmap().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sys_madvise()

int sys_madvise ( struct thread *  td,
struct madvise_args uap 
)

Definition at line 759 of file vm_mmap.c.

References madvise_args::addr, madvise_args::behav, kern_madvise(), and madvise_args::len.

Here is the call graph for this function:

◆ sys_mincore()

int sys_mincore ( struct thread *  td,
struct mincore_args uap 
)

Definition at line 813 of file vm_mmap.c.

References mincore_args::addr, kern_mincore(), mincore_args::len, and mincore_args::vec.

Here is the call graph for this function:

◆ sys_minherit()

int sys_minherit ( struct thread *  td,
struct minherit_args uap 
)

Definition at line 715 of file vm_mmap.c.

References minherit_args::addr, minherit_args::inherit, kern_minherit(), and minherit_args::len.

Here is the call graph for this function:

◆ sys_mlock()

int sys_mlock ( struct thread *  td,
struct mlock_args uap 
)

Definition at line 1063 of file vm_mmap.c.

References mlock_args::addr, kern_mlock(), and mlock_args::len.

Here is the call graph for this function:

◆ sys_mlockall()

int sys_mlockall ( struct thread *  td,
struct mlockall_args uap 
)

◆ sys_mmap()

int sys_mmap ( struct thread *  td,
struct mmap_args uap 
)

Definition at line 179 of file vm_mmap.c.

References mmap_args::addr, mmap_args::fd, mmap_args::flags, kern_mmap(), mmap_args::len, mmap_args::pos, and mmap_args::prot.

Here is the call graph for this function:

◆ sys_mprotect()

int sys_mprotect ( struct thread *  td,
struct mprotect_args uap 
)

Definition at line 656 of file vm_mmap.c.

References mprotect_args::addr, kern_mprotect(), mprotect_args::len, and mprotect_args::prot.

Here is the call graph for this function:

◆ sys_msync()

int sys_msync ( struct thread *  td,
struct msync_args uap 
)

Definition at line 524 of file vm_mmap.c.

References msync_args::addr, msync_args::flags, kern_msync(), and msync_args::len.

Here is the call graph for this function:

◆ sys_munlock()

int sys_munlock ( struct thread *  td,
struct munlock_args uap 
)

Definition at line 1245 of file vm_mmap.c.

References munlock_args::addr, kern_munlock(), and munlock_args::len.

Here is the call graph for this function:

◆ sys_munlockall()

int sys_munlockall ( struct thread *  td,
struct munlockall_args uap 
)

Definition at line 1209 of file vm_mmap.c.

References KERN_SUCCESS, MAP_WIREFUTURE, vm_map_lock, vm_map_max(), vm_map_min(), vm_map_modflags(), vm_map_unlock, vm_map_unwire(), VM_MAP_WIRE_HOLESOK, and VM_MAP_WIRE_USER.

Here is the call graph for this function:

◆ sys_munmap()

int sys_munmap ( struct thread *  td,
struct munmap_args uap 
)

Definition at line 577 of file vm_mmap.c.

References munmap_args::addr, kern_munmap(), and munmap_args::len.

Here is the call graph for this function:

◆ sys_sbrk()

int sys_sbrk ( struct thread *  td,
struct sbrk_args uap 
)

Definition at line 124 of file vm_mmap.c.

◆ sys_sstk()

int sys_sstk ( struct thread *  td,
struct sstk_args uap 
)

Definition at line 137 of file vm_mmap.c.

◆ SYSCTL_INT() [1/3]

SYSCTL_INT ( _vm  ,
OID_AUTO  ,
imply_prot_max  ,
CTLFLAG_RWTUN  ,
imply_prot_max,
,
"Imply maximum page protections in mmap() when none are specified"   
)

◆ SYSCTL_INT() [2/3]

SYSCTL_INT ( _vm  ,
OID_AUTO  ,
mincore_mapped  ,
CTLFLAG_RWTUN  ,
mincore_mapped,
,
"mincore reports  mappings,
not residency"   
)

◆ SYSCTL_INT() [3/3]

SYSCTL_INT ( _vm  ,
OID_AUTO  ,
old_mlock  ,
CTLFLAG_RWTUN  ,
old_mlock,
,
"Do not apply RLIMIT_MEMLOCK on mlockall"   
)

◆ vm_mmap()

int vm_mmap ( vm_map_t  map,
vm_offset_t *  addr,
vm_size_t  size,
vm_prot_t  prot,
vm_prot_t  maxprot,
int  flags,
objtype_t  handle_type,
void *  handle,
vm_ooffset_t  foff 
)

Definition at line 1466 of file vm_mmap.c.

References OBJT_DEFAULT, OBJT_DEVICE, OBJT_VNODE, vm_mmap_cdev(), vm_mmap_object(), vm_mmap_vnode(), vm_object_deallocate(), and vm_pager_release_writecount().

Here is the call graph for this function:

◆ vm_mmap_cdev()

int vm_mmap_cdev ( struct thread *  td,
vm_size_t  objsize,
vm_prot_t  prot,
vm_prot_t maxprotp,
int *  flagsp,
struct cdev *  cdev,
struct cdevsw *  dsw,
vm_ooffset_t *  foff,
vm_object_t objp 
)

Definition at line 1404 of file vm_mmap.c.

References OBJT_DEVICE, vm_pager_allocate(), VM_PROT_ALL, and VM_PROT_WRITE.

Referenced by vm_mmap().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vm_mmap_object()

int vm_mmap_object ( vm_map_t  map,
vm_offset_t *  addr,
vm_size_t  size,
vm_prot_t  prot,
vm_prot_t  maxprot,
int  flags,
vm_object_t  object,
vm_ooffset_t  foff,
boolean_t  writecounted,
struct thread *  td 
)

◆ vm_mmap_to_errno()

int vm_mmap_to_errno ( int  rv)

Definition at line 1685 of file vm_mmap.c.

References KERN_INVALID_ADDRESS, KERN_NO_SPACE, KERN_PROTECTION_FAILURE, and KERN_SUCCESS.

Referenced by kern_munmap(), vm_map_madvise(), and vm_mmap_object().

Here is the caller graph for this function:

◆ vm_mmap_vnode()

int vm_mmap_vnode ( struct thread *  td,
vm_size_t  objsize,
vm_prot_t  prot,
vm_prot_t maxprotp,
int *  flagsp,
struct vnode *  vp,
vm_ooffset_t *  foffp,
vm_object_t objp,
boolean_t *  writecounted 
)

Definition at line 1290 of file vm_mmap.c.

References OBJ_COLORED, OBJ_SWAP, OBJT_DEFAULT, OBJT_VNODE, vm_object_color(), vm_object_reference(), VM_OBJECT_WLOCK, VM_OBJECT_WUNLOCK, vm_pager_allocate(), vm_pager_update_writecount(), and VM_PROT_WRITE.

Referenced by vm_mmap().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ imply_prot_max

int imply_prot_max = 0
static

Definition at line 107 of file vm_mmap.c.

Referenced by kern_mmap_maxprot().

◆ mincore_mapped

int mincore_mapped = 1
static

Definition at line 104 of file vm_mmap.c.

Referenced by kern_mincore().

◆ old_mlock

int old_mlock = 0

Definition at line 101 of file vm_mmap.c.

Referenced by kern_break(), kern_mmap_racct_check(), and sys_mlockall().