FreeBSD kernel kern code
uipc_sem.c File Reference
#include <sys/cdefs.h>
#include "opt_posix.h"
#include <sys/param.h>
#include <sys/capsicum.h>
#include <sys/condvar.h>
#include <sys/fcntl.h>
#include <sys/file.h>
#include <sys/filedesc.h>
#include <sys/fnv_hash.h>
#include <sys/jail.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/user.h>
#include <sys/vnode.h>
#include <security/audit/audit.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 ("$FreeBSD$")
 
 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_stat (struct file *fp, struct stat *sb, struct ucred *active_cred)
 
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 int ksem_fill_kinfo (struct file *fp, struct kinfo_file *kif, struct filedesc *fdp)
 
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 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 *rightsp, 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

◆ DP

#define DP (   x)

Definition at line 94 of file uipc_sem.c.

◆ KSEM_HASH

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

◆ SEM_MAX

#define SEM_MAX   30

Definition at line 88 of file uipc_sem.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ DECLARE_MODULE()

DECLARE_MODULE ( sem  ,
sem_mod  ,
SI_SUB_SYSV_SEM  ,
SI_ORDER_FIRST   
)

◆ FEATURE() [1/2]

FEATURE ( p1003_1b_semaphores  ,
"POSIX P1003.1B semaphores support"   
)

◆ FEATURE() [2/2]

FEATURE ( posix_sem  ,
"POSIX semaphores"   
)

◆ kern_sem_wait()

static int kern_sem_wait ( struct thread *  td,
semid_t  id,
int  tryflag,
struct timespec *  abstime 
)
static

Definition at line 807 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:

◆ ksem_access()

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

Definition at line 359 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:

◆ ksem_alloc()

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

Definition at line 302 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:

◆ ksem_chmod()

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

Definition at line 199 of file uipc_sem.c.

References mode, and vaccess().

Here is the call graph for this function:

◆ ksem_chown()

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

Definition at line 224 of file uipc_sem.c.

References groupmember(), and priv_check_cred().

Here is the call graph for this function:

◆ ksem_closef()

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

Definition at line 254 of file uipc_sem.c.

References ksem_drop().

Here is the call graph for this function:

◆ ksem_create()

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 464 of file uipc_sem.c.

References fd, fdclose(), finit(), flags, free(), ksem_access(), ksem_alloc(), ksem_create_copyout_semid(), ksem_hold(), ksem_insert(), ksem_lookup(), malloc(), mode, name, path, and value.

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:

◆ ksem_create_copyout_semid()

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

Definition at line 434 of file uipc_sem.c.

References fd.

Referenced by ksem_create().

Here is the caller graph for this function:

◆ ksem_drop()

static void ksem_drop ( struct ksem *  ks)
static

Definition at line 339 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:

◆ ksem_fill_kinfo()

static int ksem_fill_kinfo ( struct file *  fp,
struct kinfo_file *  kif,
struct filedesc *  fdp 
)
static

Definition at line 266 of file uipc_sem.c.

References path.

◆ ksem_get()

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

Definition at line 591 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:

◆ ksem_hold()

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

Definition at line 331 of file uipc_sem.c.

Referenced by ksem_create(), and ksem_insert().

Here is the caller graph for this function:

◆ ksem_insert()

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

Definition at line 391 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:

◆ ksem_lookup()

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

Definition at line 376 of file uipc_sem.c.

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

Referenced by ksem_create().

Here is the caller graph for this function:

◆ ksem_module_destroy()

static void ksem_module_destroy ( void  )
static

Definition at line 1053 of file uipc_sem.c.

References hashdestroy(), ksem_syscalls, 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:

◆ ksem_module_init()

static int ksem_module_init ( void  )
static

Definition at line 1029 of file uipc_sem.c.

References hashinit(), ksem_syscalls, 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:

◆ ksem_remove()

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

Definition at line 404 of file uipc_sem.c.

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

Referenced by sys_ksem_unlink().

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

◆ ksem_stat()

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

Definition at line 164 of file uipc_sem.c.

◆ LIST_HEAD()

static LIST_HEAD ( ksem_mapping  )
static

Definition at line 105 of file uipc_sem.c.

◆ MALLOC_DEFINE()

static MALLOC_DEFINE ( M_KSEM  ,
"ksem"  ,
"semaphore file descriptor"   
)
static

◆ MODULE_VERSION()

MODULE_VERSION ( sem  ,
 
)

◆ sem_modload()

static int sem_modload ( struct module module,
int  cmd,
void *  arg 
)
static

Definition at line 1071 of file uipc_sem.c.

References ksem_module_destroy(), and ksem_module_init().

Here is the call graph for this function:

◆ sys_ksem_close()

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

Definition at line 691 of file uipc_sem.c.

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

Here is the call graph for this function:

◆ sys_ksem_destroy()

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

Definition at line 917 of file uipc_sem.c.

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

Here is the call graph for this function:

◆ sys_ksem_getvalue()

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

Definition at line 880 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:

◆ sys_ksem_init()

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

Definition at line 622 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:

◆ sys_ksem_open()

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

Definition at line 639 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:

◆ sys_ksem_post()

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

Definition at line 718 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:

◆ sys_ksem_timedwait()

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

Definition at line 772 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:

◆ sys_ksem_trywait()

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

Definition at line 800 of file uipc_sem.c.

References ksem_trywait_args::id, and kern_sem_wait().

Here is the call graph for this function:

◆ sys_ksem_unlink()

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

Definition at line 656 of file uipc_sem.c.

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

Here is the call graph for this function:

◆ sys_ksem_wait()

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

Definition at line 759 of file uipc_sem.c.

References ksem_wait_args::id, and kern_sem_wait().

Here is the call graph for this function:

Variable Documentation

◆ ksem_syscalls

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 948 of file uipc_sem.c.

Referenced by ksem_module_destroy(), and ksem_module_init().

◆ sem_mod

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

Definition at line 1103 of file uipc_sem.c.