FreeBSD kernel kern code
uipc_shm.c File Reference
#include <sys/cdefs.h>
#include "opt_capsicum.h"
#include <sys/param.h>
#include <sys/capability.h>
#include <sys/conf.h>
#include <sys/fcntl.h>
#include <sys/file.h>
#include <sys/filedesc.h>
#include <sys/fnv_hash.h>
#include <sys/kernel.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/stat.h>
#include <sys/sysctl.h>
#include <sys/sysproto.h>
#include <sys/systm.h>
#include <sys/sx.h>
#include <sys/time.h>
#include <sys/vnode.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>
Include dependency graph for uipc_shm.c:

Go to the source code of this file.

Data Structures

struct  shm_mapping
 

Macros

#define SHM_HASH(fnv)   (&shm_dictionary[(fnv) & shm_hash])
 

Functions

 __FBSDID ("$BSDSUniX$")
 
static MALLOC_DEFINE (M_SHMFD,"shmfd","shared memory file descriptor")
 
static LIST_HEAD (shm_mapping)
 
 FEATURE (posix_shm,"POSIX shared memory")
 
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)
 
static int shm_ioctl (struct file *fp, u_long com, void *data, struct ucred *active_cred, struct thread *td)
 
static int shm_poll (struct file *fp, int events, struct ucred *active_cred, struct thread *td)
 
static int shm_kqfilter (struct file *fp, struct knote *kn)
 
static int shm_stat (struct file *fp, struct stat *sb, struct ucred *active_cred, struct thread *td)
 
static int shm_close (struct file *fp, struct thread *td)
 
static int shm_dotruncate (struct shmfd *shmfd, off_t length)
 
static struct shmfd * shm_alloc (struct ucred *ucred, mode_t mode)
 
static struct shmfd * shm_hold (struct shmfd *shmfd)
 
static void shm_drop (struct shmfd *shmfd)
 
static 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 sys_shm_open (struct thread *td, struct shm_open_args *uap)
 
int sys_shm_unlink (struct thread *td, struct shm_unlink_args *uap)
 
int shm_mmap (struct shmfd *shmfd, vm_size_t objsize, vm_ooffset_t foff, vm_object_t *obj)
 
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)
 
void shm_path (struct shmfd *shmfd, char *path, size_t size)
 

Macro Definition Documentation

#define SHM_HASH (   fnv)    (&shm_dictionary[(fnv) & shm_hash])

Referenced by shm_insert(), shm_lookup(), and shm_remove().

Function Documentation

__FBSDID ( "$BSDSUniX$"  )
FEATURE ( posix_shm  ,
"POSIX shared memory"   
)
static LIST_HEAD ( shm_mapping  )
static

Definition at line 95 of file uipc_shm.c.

static MALLOC_DEFINE ( M_SHMFD  ,
"shmfd"  ,
"shared memory file descriptor"   
)
static
static int shm_access ( struct shmfd *  shmfd,
struct ucred *  ucred,
int  flags 
)
static

Definition at line 428 of file uipc_shm.c.

References accmode, and vaccess().

Referenced by shm_remove(), and sys_shm_open().

Here is the call graph for this function:

Here is the caller graph for this function:

static struct shmfd* shm_alloc ( struct ucred *  ucred,
mode_t  mode 
)
static

Definition at line 366 of file uipc_shm.c.

References alloc_unr(), malloc(), mode, and vfs_timestamp().

Referenced by sys_shm_open().

Here is the call graph for this function:

Here is the caller graph for this function:

static int shm_chmod ( struct file *  fp,
mode_t  mode,
struct ucred *  active_cred,
struct thread *  td 
)
static

Definition at line 703 of file uipc_shm.c.

References vaccess().

Here is the call graph for this function:

static int shm_chown ( struct file *  fp,
uid_t  uid,
gid_t  gid,
struct ucred *  active_cred,
struct thread *  td 
)
static

Definition at line 732 of file uipc_shm.c.

References groupmember(), and priv_check_cred().

Here is the call graph for this function:

static int shm_close ( struct file *  fp,
struct thread *  td 
)
static

Definition at line 240 of file uipc_shm.c.

References shm_drop().

Here is the call graph for this function:

static int shm_dotruncate ( struct shmfd *  shmfd,
off_t  length 
)
static

Definition at line 252 of file uipc_shm.c.

References vfs_timestamp().

Referenced by shm_truncate(), and sys_shm_open().

Here is the call graph for this function:

Here is the caller graph for this function:

static void shm_drop ( struct shmfd *  shmfd)
static

Definition at line 409 of file uipc_shm.c.

References free(), and free_unr().

Referenced by shm_close(), and shm_remove().

Here is the call graph for this function:

Here is the caller graph for this function:

static struct shmfd* shm_hold ( struct shmfd *  shmfd)
static

Definition at line 401 of file uipc_shm.c.

Referenced by shm_insert(), and sys_shm_open().

Here is the caller graph for this function:

static void shm_init ( void *  arg)
static

Definition at line 451 of file uipc_shm.c.

References hashinit(), mtx_init(), and new_unrhdr().

Here is the call graph for this function:

static void shm_insert ( char *  path,
Fnv32_t  fnv,
struct shmfd *  shmfd 
)
static

Definition at line 480 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 sys_shm_open().

Here is the call graph for this function:

Here is the caller graph for this function:

static int shm_ioctl ( struct file *  fp,
u_long  com,
void *  data,
struct ucred *  active_cred,
struct thread *  td 
)
static

Definition at line 177 of file uipc_shm.c.

static int shm_kqfilter ( struct file *  fp,
struct knote kn 
)
static

Definition at line 193 of file uipc_shm.c.

static struct shmfd* shm_lookup ( char *  path,
Fnv32_t  fnv 
)
static

Definition at line 465 of file uipc_shm.c.

References SHM_HASH, shm_mapping::sm_fnv, shm_mapping::sm_path, and shm_mapping::sm_shmfd.

Referenced by sys_shm_open().

Here is the caller graph for this function:

int shm_map ( struct file *  fp,
size_t  size,
off_t  offset,
void **  memp 
)

Definition at line 766 of file uipc_shm.c.

int shm_mmap ( struct shmfd *  shmfd,
vm_size_t  objsize,
vm_ooffset_t  foff,
vm_object_t *  obj 
)

Definition at line 682 of file uipc_shm.c.

References vfs_timestamp().

Here is the call graph for this function:

void shm_path ( struct shmfd *  shmfd,
char *  path,
size_t  size 
)

Definition at line 864 of file uipc_shm.c.

Referenced by fill_shm_info().

Here is the caller graph for this function:

static int shm_poll ( struct file *  fp,
int  events,
struct ucred *  active_cred,
struct thread *  td 
)
static

Definition at line 185 of file uipc_shm.c.

static int shm_read ( struct file *  fp,
struct uio *  uio,
struct ucred *  active_cred,
int  flags,
struct thread *  td 
)
static

Definition at line 143 of file uipc_shm.c.

static int shm_remove ( char *  path,
Fnv32_t  fnv,
struct ucred *  ucred 
)
static

Definition at line 493 of file uipc_shm.c.

References free(), shm_access(), shm_drop(), SHM_HASH, shm_mapping::sm_fnv, shm_mapping::sm_path, and shm_mapping::sm_shmfd.

Referenced by sys_shm_unlink().

Here is the call graph for this function:

Here is the caller graph for this function:

static int shm_stat ( struct file *  fp,
struct stat *  sb,
struct ucred *  active_cred,
struct thread *  td 
)
static

Definition at line 200 of file uipc_shm.c.

static int shm_truncate ( struct file *  fp,
off_t  length,
struct ucred *  active_cred,
struct thread *  td 
)
static

Definition at line 159 of file uipc_shm.c.

References shm_dotruncate().

Here is the call graph for this function:

int shm_unmap ( struct file *  fp,
void *  mem,
size_t  size 
)

Definition at line 824 of file uipc_shm.c.

static int shm_write ( struct file *  fp,
struct uio *  uio,
struct ucred *  active_cred,
int  flags,
struct thread *  td 
)
static

Definition at line 151 of file uipc_shm.c.

int sys_shm_open ( struct thread *  td,
struct shm_open_args *  uap 
)

Definition at line 525 of file uipc_shm.c.

References falloc(), fd, fdclose(), finit(), free(), malloc(), path, shm_access(), shm_alloc(), shm_dotruncate(), shm_hold(), shm_insert(), and shm_lookup().

Here is the call graph for this function:

int sys_shm_unlink ( struct thread *  td,
struct shm_unlink_args *  uap 
)

Definition at line 655 of file uipc_shm.c.

References free(), malloc(), path, and shm_remove().

Here is the call graph for this function:

SYSINIT ( shm_init  ,
SI_SUB_SYSV_SHM  ,
SI_ORDER_ANY  ,
shm_init  ,
NULL   
)