FreeBSD kernel kern code
|
#include <sys/cdefs.h>
#include "opt_capsicum.h"
#include "opt_ktrace.h"
#include <sys/param.h>
#include <sys/capsicum.h>
#include <sys/conf.h>
#include <sys/fcntl.h>
#include <sys/file.h>
#include <sys/filedesc.h>
#include <sys/filio.h>
#include <sys/fnv_hash.h>
#include <sys/kernel.h>
#include <sys/limits.h>
#include <sys/uio.h>
#include <sys/signal.h>
#include <sys/jail.h>
#include <sys/ktrace.h>
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/mman.h>
#include <sys/mutex.h>
#include <sys/priv.h>
#include <sys/proc.h>
#include <sys/refcount.h>
#include <sys/resourcevar.h>
#include <sys/rwlock.h>
#include <sys/sbuf.h>
#include <sys/stat.h>
#include <sys/syscallsubr.h>
#include <sys/sysctl.h>
#include <sys/sysproto.h>
#include <sys/systm.h>
#include <sys/sx.h>
#include <sys/time.h>
#include <sys/vmmeter.h>
#include <sys/vnode.h>
#include <sys/unistd.h>
#include <sys/user.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_extern.h>
#include <vm/vm_map.h>
#include <vm/vm_kern.h>
#include <vm/vm_object.h>
#include <vm/vm_page.h>
#include <vm/vm_pageout.h>
#include <vm/vm_pager.h>
#include <vm/swap_pager.h>
Go to the source code of this file.
Data Structures | |
struct | shm_mapping |
Macros | |
#define | SHM_HASH(fnv) (&shm_dictionary[(fnv) & shm_hash]) |
#define | M (1024 * 1024) |
#define | G (1024 * M) |
Functions | |
__FBSDID ("$FreeBSD$") | |
static | MALLOC_DEFINE (M_SHMFD, "shmfd", "shared memory file descriptor") |
static | LIST_HEAD (shm_mapping) |
FEATURE (posix_shm, "POSIX shared memory") | |
static | SYSCTL_NODE (_vm, OID_AUTO, largepages, CTLFLAG_RD|CTLFLAG_MPSAFE, 0, "") |
SYSCTL_INT (_vm_largepages, OID_AUTO, reclaim_tries, CTLFLAG_RWTUN, &largepage_reclaim_tries, 0, "Number of contig reclaims before giving up for default alloc policy") | |
static int | uiomove_object_page (vm_object_t obj, size_t len, struct uio *uio) |
int | uiomove_object (vm_object_t obj, off_t obj_size, struct uio *uio) |
static int | shm_largepage_phys_populate (vm_object_t object, vm_pindex_t pidx, int fault_type, vm_prot_t max_prot, vm_pindex_t *first, vm_pindex_t *last) |
static boolean_t | shm_largepage_phys_haspage (vm_object_t object, vm_pindex_t pindex, int *before, int *after) |
static void | shm_largepage_phys_ctor (vm_object_t object, vm_prot_t prot, vm_ooffset_t foff, struct ucred *cred) |
static void | shm_largepage_phys_dtor (vm_object_t object) |
bool | shm_largepage (struct shmfd *shmfd) |
static int | shm_seek (struct file *fp, off_t offset, int whence, struct thread *td) |
static int | shm_read (struct file *fp, struct uio *uio, struct ucred *active_cred, int flags, struct thread *td) |
static int | shm_write (struct file *fp, struct uio *uio, struct ucred *active_cred, int flags, struct thread *td) |
static int | shm_truncate (struct file *fp, off_t length, struct ucred *active_cred, struct thread *td) |
int | shm_ioctl (struct file *fp, u_long com, void *data, struct ucred *active_cred, struct thread *td) |
static int | shm_stat (struct file *fp, struct stat *sb, struct ucred *active_cred) |
static int | shm_close (struct file *fp, struct thread *td) |
static int | shm_copyin_path (struct thread *td, const char *userpath_in, char **path_out) |
static int | shm_partial_page_invalidate (vm_object_t object, vm_pindex_t idx, int base, int end) |
static int | shm_dotruncate_locked (struct shmfd *shmfd, off_t length, void *rl_cookie) |
static int | shm_dotruncate_largepage (struct shmfd *shmfd, off_t length, void *rl_cookie) |
static int | shm_dotruncate_cookie (struct shmfd *shmfd, off_t length, void *rl_cookie) |
int | shm_dotruncate (struct shmfd *shmfd, off_t length) |
struct shmfd * | shm_alloc (struct ucred *ucred, mode_t mode, bool largepage) |
struct shmfd * | shm_hold (struct shmfd *shmfd) |
void | shm_drop (struct shmfd *shmfd) |
int | shm_access (struct shmfd *shmfd, struct ucred *ucred, int flags) |
static void | shm_init (void *arg) |
SYSINIT (shm_init, SI_SUB_SYSV_SHM, SI_ORDER_ANY, shm_init, NULL) | |
static struct shmfd * | shm_lookup (char *path, Fnv32_t fnv) |
static void | shm_insert (char *path, Fnv32_t fnv, struct shmfd *shmfd) |
static int | shm_remove (char *path, Fnv32_t fnv, struct ucred *ucred) |
int | kern_shm_open2 (struct thread *td, const char *userpath, int flags, mode_t mode, int shmflags, struct filecaps *fcaps, const char *name __unused) |
int | sys_shm_unlink (struct thread *td, struct shm_unlink_args *uap) |
int | sys_shm_rename (struct thread *td, struct shm_rename_args *uap) |
static int | shm_mmap_large (struct shmfd *shmfd, vm_map_t map, vm_offset_t *addr, vm_size_t size, vm_prot_t prot, vm_prot_t max_prot, int flags, vm_ooffset_t foff, struct thread *td) |
static int | shm_mmap (struct file *fp, vm_map_t map, vm_offset_t *addr, vm_size_t objsize, vm_prot_t prot, vm_prot_t cap_maxprot, int flags, vm_ooffset_t foff, struct thread *td) |
static int | shm_chmod (struct file *fp, mode_t mode, struct ucred *active_cred, struct thread *td) |
static int | shm_chown (struct file *fp, uid_t uid, gid_t gid, struct ucred *active_cred, struct thread *td) |
int | shm_map (struct file *fp, size_t size, off_t offset, void **memp) |
int | shm_unmap (struct file *fp, void *mem, size_t size) |
static int | shm_fill_kinfo_locked (struct shmfd *shmfd, struct kinfo_file *kif, bool list) |
static int | shm_fill_kinfo (struct file *fp, struct kinfo_file *kif, struct filedesc *fdp __unused) |
static int | shm_add_seals (struct file *fp, int seals) |
static int | shm_get_seals (struct file *fp, int *seals) |
static int | shm_deallocate (struct shmfd *shmfd, off_t *offset, off_t *length, int flags) |
static int | shm_fspacectl (struct file *fp, int cmd, off_t *offset, off_t *length, int flags, struct ucred *active_cred, struct thread *td) |
static int | shm_fallocate (struct file *fp, off_t offset, off_t len, struct thread *td) |
static int | sysctl_posix_shm_list (SYSCTL_HANDLER_ARGS) |
SYSCTL_PROC (_kern_ipc, OID_AUTO, posix_shm_list, CTLFLAG_RD|CTLFLAG_PRISON|CTLFLAG_MPSAFE|CTLTYPE_OPAQUE, NULL, 0, sysctl_posix_shm_list, "", "POSIX SHM list") | |
int | kern_shm_open (struct thread *td, const char *path, int flags, mode_t mode, struct filecaps *caps) |
int | sys_shm_open2 (struct thread *td, struct shm_open2_args *uap) |
Variables | |
static int | largepage_reclaim_tries = 1 |
static u_long | count_largepages [MAXPAGESIZES] |
static const struct phys_pager_ops | shm_largepage_phys_ops |
#define G (1024 * M) |
#define M (1024 * 1024) |
#define SHM_HASH | ( | fnv | ) | (&shm_dictionary[(fnv) & shm_hash]) |
__FBSDID | ( | "$FreeBSD$" | ) |
FEATURE | ( | posix_shm | , |
"POSIX shared memory" | |||
) |
int kern_shm_open | ( | struct thread * | td, |
const char * | path, | ||
int | flags, | ||
mode_t | mode, | ||
struct filecaps * | caps | ||
) |
Definition at line 2071 of file uipc_shm.c.
References flags, kern_shm_open2(), mode, and path.
int kern_shm_open2 | ( | struct thread * | td, |
const char * | userpath, | ||
int | flags, | ||
mode_t | mode, | ||
int | shmflags, | ||
struct filecaps * | fcaps, | ||
const char *name | __unused | ||
) |
Definition at line 1050 of file uipc_shm.c.
References falloc_caps(), fd, fdclose(), finit(), flags, free(), mode, path, rangelock_unlock(), rangelock_wlock(), shm_access(), shm_alloc(), shm_copyin_path(), shm_dotruncate_locked(), shm_hold(), shm_insert(), and shm_lookup().
Referenced by kern_shm_open(), and sys_shm_open2().
|
static |
Definition at line 115 of file uipc_shm.c.
|
static |
int shm_access | ( | struct shmfd * | shmfd, |
struct ucred * | ucred, | ||
int | flags | ||
) |
Definition at line 935 of file uipc_shm.c.
References accmode, flags, and vaccess().
Referenced by kern_shm_open2(), shm_remove(), and umtx_shm().
|
static |
Definition at line 1841 of file uipc_shm.c.
References rangelock_unlock(), rangelock_wlock(), and shm_largepage().
struct shmfd * shm_alloc | ( | struct ucred * | ucred, |
mode_t | mode, | ||
bool | largepage | ||
) |
Definition at line 873 of file uipc_shm.c.
References malloc(), mode, rangelock_init(), shm_largepage_phys_ops, and vfs_timestamp().
Referenced by kern_shm_open2(), and umtx_shm_create_reg().
|
static |
Definition at line 1637 of file uipc_shm.c.
References mode, and vaccess().
|
static |
Definition at line 1666 of file uipc_shm.c.
References groupmember(), and priv_check_cred().
|
static |
Definition at line 583 of file uipc_shm.c.
References shm_drop().
|
static |
Definition at line 595 of file uipc_shm.c.
References free(), malloc(), and path.
Referenced by kern_shm_open2(), sys_shm_rename(), and sys_shm_unlink().
|
static |
Definition at line 1897 of file uipc_shm.c.
References shm_partial_page_invalidate().
Referenced by shm_fspacectl().
int shm_dotruncate | ( | struct shmfd * | shmfd, |
off_t | length | ||
) |
Definition at line 856 of file uipc_shm.c.
References rangelock_unlock(), rangelock_wlock(), and shm_dotruncate_cookie().
Referenced by shm_truncate(), and umtx_shm_create_reg().
|
static |
Definition at line 843 of file uipc_shm.c.
References shm_dotruncate_largepage(), shm_dotruncate_locked(), and shm_largepage().
Referenced by shm_dotruncate(), shm_fallocate(), and shm_write().
|
static |
Definition at line 750 of file uipc_shm.c.
References count_largepages, flags, largepage_reclaim_tries, and pagesizes.
Referenced by shm_dotruncate_cookie().
|
static |
Definition at line 684 of file uipc_shm.c.
References shm_partial_page_invalidate(), and vfs_timestamp().
Referenced by kern_shm_open2(), and shm_dotruncate_cookie().
void shm_drop | ( | struct shmfd * | shmfd | ) |
Definition at line 916 of file uipc_shm.c.
References free(), and rangelock_destroy().
Referenced by shm_close(), shm_remove(), sys_shm_rename(), and umtx_shm_free_reg().
|
static |
Definition at line 1997 of file uipc_shm.c.
References rangelock_unlock(), rangelock_wlock(), and shm_dotruncate_cookie().
|
static |
Definition at line 1829 of file uipc_shm.c.
References res, and shm_fill_kinfo_locked().
|
static |
Definition at line 1798 of file uipc_shm.c.
References path.
Referenced by shm_fill_kinfo(), and sysctl_posix_shm_list().
|
static |
Definition at line 1958 of file uipc_shm.c.
References flags, rangelock_unlock(), rangelock_wlock(), and shm_deallocate().
|
static |
Definition at line 1887 of file uipc_shm.c.
struct shmfd * shm_hold | ( | struct shmfd * | shmfd | ) |
Definition at line 908 of file uipc_shm.c.
Referenced by kern_shm_open2(), shm_insert(), sys_shm_rename(), and umtx_shm().
|
static |
Definition at line 953 of file uipc_shm.c.
References count_largepages, G, hashinit(), M, name, pagesizes, and snprintf().
|
static |
Definition at line 1006 of file uipc_shm.c.
References malloc(), path, SHM_HASH, shm_hold(), shm_mapping::sm_fnv, shm_mapping::sm_path, and shm_mapping::sm_shmfd.
Referenced by kern_shm_open2(), and sys_shm_rename().
int shm_ioctl | ( | struct file * | fp, |
u_long | com, | ||
void * | data, | ||
struct ucred * | active_cred, | ||
struct thread * | td | ||
) |
Definition at line 487 of file uipc_shm.c.
References data, pagesizes, rangelock_rlock(), rangelock_unlock(), rangelock_wlock(), and shm_largepage().
bool shm_largepage | ( | struct shmfd * | shmfd | ) |
Definition at line 342 of file uipc_shm.c.
Referenced by shm_add_seals(), shm_dotruncate_cookie(), shm_ioctl(), shm_mmap(), and shm_write().
|
static |
Definition at line 312 of file uipc_shm.c.
|
static |
Definition at line 318 of file uipc_shm.c.
References count_largepages, and pagesizes.
|
static |
Definition at line 292 of file uipc_shm.c.
References pagesizes.
|
static |
Definition at line 267 of file uipc_shm.c.
References pagesizes.
|
static |
Definition at line 991 of file uipc_shm.c.
References path, SHM_HASH, shm_mapping::sm_fnv, shm_mapping::sm_path, and shm_mapping::sm_shmfd.
Referenced by kern_shm_open2(), and sys_shm_rename().
int shm_map | ( | struct file * | fp, |
size_t | size, | ||
off_t | offset, | ||
void ** | memp | ||
) |
Definition at line 1700 of file uipc_shm.c.
|
static |
Definition at line 1544 of file uipc_shm.c.
References addr, flags, rangelock_rlock(), rangelock_unlock(), shm_largepage(), shm_mmap_large(), and vfs_timestamp().
|
static |
Definition at line 1435 of file uipc_shm.c.
References addr, flags, lim_max(), mask, and pagesizes.
Referenced by shm_mmap().
|
static |
Definition at line 633 of file uipc_shm.c.
Referenced by shm_deallocate(), and shm_dotruncate_locked().
|
static |
Definition at line 389 of file uipc_shm.c.
References flags, foffset_lock_uio(), foffset_unlock_uio(), rangelock_rlock(), rangelock_unlock(), and uiomove_object().
|
static |
Definition at line 1019 of file uipc_shm.c.
References free(), path, shm_access(), shm_drop(), SHM_HASH, shm_mapping::sm_fnv, shm_mapping::sm_path, and shm_mapping::sm_shmfd.
Referenced by sys_shm_rename(), and sys_shm_unlink().
|
static |
Definition at line 348 of file uipc_shm.c.
References foffset_lock(), and foffset_unlock().
|
static |
Definition at line 541 of file uipc_shm.c.
References pagesizes.
|
static |
Definition at line 469 of file uipc_shm.c.
References shm_dotruncate().
int shm_unmap | ( | struct file * | fp, |
void * | mem, | ||
size_t | size | ||
) |
Definition at line 1758 of file uipc_shm.c.
|
static |
Definition at line 412 of file uipc_shm.c.
References flags, foffset_lock_uio(), foffset_unlock_uio(), rangelock_unlock(), rangelock_wlock(), shm_dotruncate_cookie(), shm_largepage(), and uiomove_object().
int sys_shm_open2 | ( | struct thread * | td, |
struct shm_open2_args * | uap | ||
) |
Definition at line 2089 of file uipc_shm.c.
References kern_shm_open2().
int sys_shm_rename | ( | struct thread * | td, |
struct shm_rename_args * | uap | ||
) |
Definition at line 1287 of file uipc_shm.c.
References flags, free(), shm_copyin_path(), shm_drop(), shm_hold(), shm_insert(), shm_lookup(), and shm_remove().
int sys_shm_unlink | ( | struct thread * | td, |
struct shm_unlink_args * | uap | ||
) |
Definition at line 1266 of file uipc_shm.c.
References free(), path, shm_copyin_path(), and shm_remove().
SYSCTL_INT | ( | _vm_largepages | , |
OID_AUTO | , | ||
reclaim_tries | , | ||
CTLFLAG_RWTUN | , | ||
& | largepage_reclaim_tries, | ||
0 | , | ||
"Number of contig reclaims before giving up for default alloc policy" | |||
) |
|
static |
|
static |
Definition at line 2030 of file uipc_shm.c.
References pack_kinfo(), sbuf_bcat(), sbuf_clear_flags(), sbuf_delete(), sbuf_finish(), sbuf_new_for_sysctl(), shm_fill_kinfo_locked(), and shm_mapping::sm_shmfd.
SYSCTL_PROC | ( | _kern_ipc | , |
OID_AUTO | , | ||
posix_shm_list | , | ||
CTLFLAG_RD|CTLFLAG_PRISON|CTLFLAG_MPSAFE| | CTLTYPE_OPAQUE, | ||
NULL | , | ||
0 | , | ||
sysctl_posix_shm_list | , | ||
"" | , | ||
"POSIX SHM list" | |||
) |
int uiomove_object | ( | vm_object_t | obj, |
off_t | obj_size, | ||
struct uio * | uio | ||
) |
Definition at line 244 of file uipc_shm.c.
References uiomove_object_page().
Referenced by shm_read(), and shm_write().
|
static |
Definition at line 187 of file uipc_shm.c.
References printf(), and uiomove().
Referenced by uiomove_object().
|
static |
Definition at line 264 of file uipc_shm.c.
Referenced by shm_dotruncate_largepage(), shm_init(), and shm_largepage_phys_dtor().
|
static |
Definition at line 181 of file uipc_shm.c.
Referenced by shm_dotruncate_largepage().
|
static |
Definition at line 334 of file uipc_shm.c.
Referenced by shm_alloc().