FreeBSD kernel kern code
uipc_sem.c File Reference
#include <sys/cdefs.h>
#include "opt_compat.h"
#include "opt_posix.h"
#include <sys/param.h>
#include <sys/capability.h>
#include <sys/condvar.h>
#include <sys/fcntl.h>
#include <sys/file.h>
#include <sys/filedesc.h>
#include <sys/fnv_hash.h>
#include <sys/kernel.h>
#include <sys/ksem.h>
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/module.h>
#include <sys/mutex.h>
#include <sys/priv.h>
#include <sys/proc.h>
#include <sys/posix4.h>
#include <sys/_semaphore.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/syscallsubr.h>
#include <sys/sysctl.h>
#include <sys/sysent.h>
#include <sys/sysproto.h>
#include <sys/systm.h>
#include <sys/sx.h>
#include <sys/vnode.h>
#include <security/mac/mac_framework.h>
Include dependency graph for uipc_sem.c:

Go to the source code of this file.

Data Structures

struct  ksem_mapping
 
struct  ksem_init_args
 
struct  ksem_open_args
 
struct  ksem_unlink_args
 
struct  ksem_close_args
 
struct  ksem_post_args
 
struct  ksem_wait_args
 
struct  ksem_timedwait_args
 
struct  ksem_trywait_args
 
struct  ksem_getvalue_args
 
struct  ksem_destroy_args
 

Macros

#define SEM_MAX   30
 
#define DP(x)
 
#define KSEM_HASH(fnv)   (&ksem_dictionary[(fnv) & ksem_hash])
 

Functions

 __FBSDID ("$BSDSUniX$")
 
 FEATURE (p1003_1b_semaphores,"POSIX P1003.1B semaphores support")
 
static MALLOC_DEFINE (M_KSEM,"ksem","semaphore file descriptor")
 
static LIST_HEAD (ksem_mapping)
 
 FEATURE (posix_sem,"POSIX semaphores")
 
static int ksem_read (struct file *fp, struct uio *uio, struct ucred *active_cred, int flags, struct thread *td)
 
static int ksem_write (struct file *fp, struct uio *uio, struct ucred *active_cred, int flags, struct thread *td)
 
static int ksem_truncate (struct file *fp, off_t length, struct ucred *active_cred, struct thread *td)
 
static int ksem_ioctl (struct file *fp, u_long com, void *data, struct ucred *active_cred, struct thread *td)
 
static int ksem_poll (struct file *fp, int events, struct ucred *active_cred, struct thread *td)
 
static int ksem_kqfilter (struct file *fp, struct knote *kn)
 
static int ksem_stat (struct file *fp, struct stat *sb, struct ucred *active_cred, struct thread *td)
 
static int ksem_chmod (struct file *fp, mode_t mode, struct ucred *active_cred, struct thread *td)
 
static int ksem_chown (struct file *fp, uid_t uid, gid_t gid, struct ucred *active_cred, struct thread *td)
 
static int ksem_closef (struct file *fp, struct thread *td)
 
static struct ksem * ksem_alloc (struct ucred *ucred, mode_t mode, unsigned int value)
 
static struct ksem * ksem_hold (struct ksem *ks)
 
static void ksem_drop (struct ksem *ks)
 
static int ksem_access (struct ksem *ks, struct ucred *ucred)
 
static struct ksem * ksem_lookup (char *path, Fnv32_t fnv)
 
static void ksem_insert (char *path, Fnv32_t fnv, struct ksem *ks)
 
static int ksem_remove (char *path, Fnv32_t fnv, struct ucred *ucred)
 
static void ksem_info_impl (struct ksem *ks, char *path, size_t size, uint32_t *value)
 
static int ksem_create_copyout_semid (struct thread *td, semid_t *semidp, int fd, int compat32)
 
static int ksem_create (struct thread *td, const char *name, semid_t *semidp, mode_t mode, unsigned int value, int flags, int compat32)
 
static int ksem_get (struct thread *td, semid_t id, cap_rights_t rights, struct file **fpp)
 
int sys_ksem_init (struct thread *td, struct ksem_init_args *uap)
 
int sys_ksem_open (struct thread *td, struct ksem_open_args *uap)
 
int sys_ksem_unlink (struct thread *td, struct ksem_unlink_args *uap)
 
int sys_ksem_close (struct thread *td, struct ksem_close_args *uap)
 
int sys_ksem_post (struct thread *td, struct ksem_post_args *uap)
 
int sys_ksem_wait (struct thread *td, struct ksem_wait_args *uap)
 
int sys_ksem_timedwait (struct thread *td, struct ksem_timedwait_args *uap)
 
int sys_ksem_trywait (struct thread *td, struct ksem_trywait_args *uap)
 
static int kern_sem_wait (struct thread *td, semid_t id, int tryflag, struct timespec *abstime)
 
int sys_ksem_getvalue (struct thread *td, struct ksem_getvalue_args *uap)
 
int sys_ksem_destroy (struct thread *td, struct ksem_destroy_args *uap)
 
static int ksem_module_init (void)
 
static void ksem_module_destroy (void)
 
static int sem_modload (struct module *module, int cmd, void *arg)
 
 DECLARE_MODULE (sem, sem_mod, SI_SUB_SYSV_SEM, SI_ORDER_FIRST)
 
 MODULE_VERSION (sem, 1)
 

Variables

static struct syscall_helper_data ksem_syscalls []
 
static moduledata_t sem_mod
 

Macro Definition Documentation

#define DP (   x)

Definition at line 85 of file uipc_sem.c.

Referenced by kern_sem_wait(), and sys_ksem_open().

#define KSEM_HASH (   fnv)    (&ksem_dictionary[(fnv) & ksem_hash])
#define SEM_MAX   30

Definition at line 79 of file uipc_sem.c.

Referenced by ksem_module_init().

Function Documentation

__FBSDID ( "$BSDSUniX$"  )
DECLARE_MODULE ( sem  ,
sem_mod  ,
SI_SUB_SYSV_SEM  ,
SI_ORDER_FIRST   
)
FEATURE ( p1003_1b_semaphores  ,
"POSIX P1003.1B semaphores support"   
)
FEATURE ( posix_sem  ,
"POSIX semaphores"   
)
static int kern_sem_wait ( struct thread *  td,
semid_t  id,
int  tryflag,
struct timespec *  abstime 
)
static

Definition at line 806 of file uipc_sem.c.

References DP, getnanotime(), ksem_get(), tvtohz(), and vfs_timestamp().

Referenced by sys_ksem_timedwait(), sys_ksem_trywait(), and sys_ksem_wait().

Here is the call graph for this function:

Here is the caller graph for this function:

static int ksem_access ( struct ksem *  ks,
struct ucred *  ucred 
)
static

Definition at line 369 of file uipc_sem.c.

References priv_check_cred(), and vaccess().

Referenced by ksem_create(), and ksem_remove().

Here is the call graph for this function:

Here is the caller graph for this function:

static struct ksem* ksem_alloc ( struct ucred *  ucred,
mode_t  mode,
unsigned int  value 
)
static

Definition at line 312 of file uipc_sem.c.

References cv_init(), malloc(), mode, p31b_getcfg(), value, and vfs_timestamp().

Referenced by ksem_create().

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 241 of file uipc_sem.c.

References vaccess().

Here is the call graph for this function:

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

Definition at line 266 of file uipc_sem.c.

References groupmember(), and priv_check_cred().

Here is the call graph for this function:

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

Definition at line 296 of file uipc_sem.c.

References ksem_drop().

Here is the call graph for this function:

static int ksem_create ( struct thread *  td,
const char *  name,
semid_t *  semidp,
mode_t  mode,
unsigned int  value,
int  flags,
int  compat32 
)
static

Definition at line 488 of file uipc_sem.c.

References falloc(), fd, fdclose(), finit(), free(), ksem_access(), ksem_alloc(), ksem_create_copyout_semid(), ksem_hold(), ksem_insert(), ksem_lookup(), malloc(), and path.

Referenced by sys_ksem_init(), and sys_ksem_open().

Here is the call graph for this function:

Here is the caller graph for this function:

static int ksem_create_copyout_semid ( struct thread *  td,
semid_t *  semidp,
int  fd,
int  compat32 
)
static

Definition at line 458 of file uipc_sem.c.

References fd.

Referenced by ksem_create().

Here is the caller graph for this function:

static void ksem_drop ( struct ksem *  ks)
static

Definition at line 349 of file uipc_sem.c.

References cv_destroy(), and free().

Referenced by ksem_closef(), and ksem_remove().

Here is the call graph for this function:

Here is the caller graph for this function:

static int ksem_get ( struct thread *  td,
semid_t  id,
cap_rights_t  rights,
struct file **  fpp 
)
static

Definition at line 602 of file uipc_sem.c.

References fget().

Referenced by kern_sem_wait(), sys_ksem_close(), sys_ksem_destroy(), sys_ksem_getvalue(), and sys_ksem_post().

Here is the call graph for this function:

Here is the caller graph for this function:

static struct ksem* ksem_hold ( struct ksem *  ks)
static

Definition at line 341 of file uipc_sem.c.

Referenced by ksem_create(), and ksem_insert().

Here is the caller graph for this function:

static void ksem_info_impl ( struct ksem *  ks,
char *  path,
size_t  size,
uint32_t *  value 
)
static

Definition at line 444 of file uipc_sem.c.

Referenced by ksem_module_init().

Here is the caller graph for this function:

static void ksem_insert ( char *  path,
Fnv32_t  fnv,
struct ksem *  ks 
)
static

Definition at line 401 of file uipc_sem.c.

References ksem_mapping::km_fnv, ksem_mapping::km_ksem, ksem_mapping::km_path, KSEM_HASH, ksem_hold(), malloc(), and path.

Referenced by ksem_create().

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 182 of file uipc_sem.c.

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

Definition at line 198 of file uipc_sem.c.

static struct ksem* ksem_lookup ( char *  path,
Fnv32_t  fnv 
)
static

Definition at line 386 of file uipc_sem.c.

References ksem_mapping::km_fnv, ksem_mapping::km_ksem, ksem_mapping::km_path, and KSEM_HASH.

Referenced by ksem_create().

Here is the caller graph for this function:

static void ksem_module_destroy ( void  )
static

Definition at line 1046 of file uipc_sem.c.

References hashdestroy(), ksem_info, mtx_destroy(), p31b_setcfg(), p31b_unsetcfg(), sx_destroy(), and syscall_helper_unregister().

Referenced by sem_modload().

Here is the call graph for this function:

Here is the caller graph for this function:

static int ksem_module_init ( void  )
static

Definition at line 1021 of file uipc_sem.c.

References hashinit(), ksem_info, ksem_info_impl(), mtx_init(), p31b_setcfg(), SEM_MAX, and syscall_helper_register().

Referenced by sem_modload().

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 190 of file uipc_sem.c.

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

Definition at line 158 of file uipc_sem.c.

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

Definition at line 414 of file uipc_sem.c.

References free(), ksem_mapping::km_fnv, ksem_mapping::km_ksem, ksem_mapping::km_path, ksem_access(), ksem_drop(), and KSEM_HASH.

Referenced by sys_ksem_unlink().

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 205 of file uipc_sem.c.

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

Definition at line 174 of file uipc_sem.c.

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

Definition at line 166 of file uipc_sem.c.

static LIST_HEAD ( ksem_mapping  )
static

Definition at line 96 of file uipc_sem.c.

static MALLOC_DEFINE ( M_KSEM  ,
"ksem"  ,
"semaphore file descriptor"   
)
static
MODULE_VERSION ( sem  ,
 
)
static int sem_modload ( struct module module,
int  cmd,
void *  arg 
)
static

Definition at line 1065 of file uipc_sem.c.

References ksem_module_destroy(), and ksem_module_init().

Here is the call graph for this function:

int sys_ksem_close ( struct thread *  td,
struct ksem_close_args uap 
)

Definition at line 694 of file uipc_sem.c.

References ksem_close_args::id, kern_close(), and ksem_get().

Here is the call graph for this function:

int sys_ksem_destroy ( struct thread *  td,
struct ksem_destroy_args uap 
)

Definition at line 910 of file uipc_sem.c.

References ksem_destroy_args::id, kern_close(), and ksem_get().

Here is the call graph for this function:

int sys_ksem_getvalue ( struct thread *  td,
struct ksem_getvalue_args uap 
)

Definition at line 876 of file uipc_sem.c.

References ksem_getvalue_args::id, ksem_get(), ksem_getvalue_args::val, and vfs_timestamp().

Here is the call graph for this function:

int sys_ksem_init ( struct thread *  td,
struct ksem_init_args uap 
)

Definition at line 632 of file uipc_sem.c.

References ksem_init_args::idp, ksem_create(), and ksem_init_args::value.

Here is the call graph for this function:

int sys_ksem_open ( struct thread *  td,
struct ksem_open_args uap 
)

Definition at line 649 of file uipc_sem.c.

References DP, ksem_open_args::idp, ksem_create(), ksem_open_args::mode, ksem_open_args::name, ksem_open_args::oflag, and ksem_open_args::value.

Here is the call graph for this function:

int sys_ksem_post ( struct thread *  td,
struct ksem_post_args uap 
)

Definition at line 720 of file uipc_sem.c.

References cv_signal(), ksem_post_args::id, ksem_get(), and vfs_timestamp().

Here is the call graph for this function:

int sys_ksem_timedwait ( struct thread *  td,
struct ksem_timedwait_args uap 
)

Definition at line 771 of file uipc_sem.c.

References ksem_timedwait_args::abstime, ksem_timedwait_args::id, kern_sem_wait(), and ts.

Here is the call graph for this function:

int sys_ksem_trywait ( struct thread *  td,
struct ksem_trywait_args uap 
)

Definition at line 799 of file uipc_sem.c.

References ksem_trywait_args::id, and kern_sem_wait().

Here is the call graph for this function:

int sys_ksem_unlink ( struct thread *  td,
struct ksem_unlink_args uap 
)

Definition at line 666 of file uipc_sem.c.

References free(), ksem_remove(), malloc(), ksem_unlink_args::name, and path.

Here is the call graph for this function:

int sys_ksem_wait ( struct thread *  td,
struct ksem_wait_args uap 
)

Definition at line 758 of file uipc_sem.c.

References ksem_wait_args::id, and kern_sem_wait().

Here is the call graph for this function:

Variable Documentation

struct syscall_helper_data ksem_syscalls[]
static
Initial value:
= {
SYSCALL_INIT_HELPER(ksem_init),
SYSCALL_INIT_HELPER(ksem_open),
SYSCALL_INIT_HELPER(ksem_unlink),
SYSCALL_INIT_HELPER(ksem_close),
SYSCALL_INIT_HELPER(ksem_post),
SYSCALL_INIT_HELPER(ksem_wait),
SYSCALL_INIT_HELPER(ksem_timedwait),
SYSCALL_INIT_HELPER(ksem_trywait),
SYSCALL_INIT_HELPER(ksem_getvalue),
SYSCALL_INIT_HELPER(ksem_destroy),
SYSCALL_INIT_LAST
}

Definition at line 940 of file uipc_sem.c.

moduledata_t sem_mod
static
Initial value:
= {
"sem",
NULL
}
static int sem_modload(struct module *module, int cmd, void *arg)
Definition: uipc_sem.c:1065

Definition at line 1097 of file uipc_sem.c.