FreeBSD kernel kern code
sysv_sem.c File Reference
#include <sys/cdefs.h>
#include "opt_compat.h"
#include "opt_sysvipc.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/sysproto.h>
#include <sys/eventhandler.h>
#include <sys/kernel.h>
#include <sys/proc.h>
#include <sys/lock.h>
#include <sys/module.h>
#include <sys/mutex.h>
#include <sys/racct.h>
#include <sys/sem.h>
#include <sys/syscall.h>
#include <sys/syscallsubr.h>
#include <sys/sysent.h>
#include <sys/sysctl.h>
#include <sys/uio.h>
#include <sys/malloc.h>
#include <sys/jail.h>
#include <security/mac/mac_framework.h>
Include dependency graph for sysv_sem.c:

Go to the source code of this file.

Data Structures

struct  sem_undo
 
struct  __semctl_args
 
struct  semget_args
 
struct  semop_args
 

Macros

#define DPRINTF(a)
 
#define SEMUNDO_MTX   sem_undo_mtx
 
#define SEMUNDO_LOCK()   mtx_lock(&SEMUNDO_MTX);
 
#define SEMUNDO_UNLOCK()   mtx_unlock(&SEMUNDO_MTX);
 
#define SEMUNDO_LOCKASSERT(how)   mtx_assert(&SEMUNDO_MTX, (how));
 
#define SEMMNI   50 /* # of semaphore identifiers */
 
#define SEMMNS   340 /* # of semaphores in system */
 
#define SEMUME   50 /* max # of undo entries per process */
 
#define SEMMNU   150 /* # of undo structures in system */
 
#define SEMMSL   SEMMNS /* max # of semaphores per id */
 
#define SEMOPM   100 /* max # of operations per semop call */
 
#define SEMVMX   32767 /* semaphore maximum value */
 
#define SEMAEM   16384 /* adjust on exit max value */
 
#define SEM_ALIGN(bytes)   (((bytes) + (sizeof(long) - 1)) & ~(sizeof(long) - 1))
 
#define SEMUSZ   SEM_ALIGN(offsetof(struct sem_undo, un_ent[SEMUME]))
 
#define SEMU(ix)   ((struct sem_undo *)(((intptr_t)semu)+ix * seminfo.semusz))
 
#define SMALL_SOPS   8
 

Functions

 __FBSDID ("$BSDSUniX$")
 
 FEATURE (sysv_sem,"System V semaphores support")
 
static MALLOC_DEFINE (M_SEM,"sem","SVID compatible semaphores")
 
static int seminit (void)
 
static int sysvsem_modload (struct module *, int, void *)
 
static int semunload (void)
 
static void semexit_myhook (void *arg, struct proc *p)
 
static int sysctl_sema (SYSCTL_HANDLER_ARGS)
 
static int semvalid (int semid, struct semid_kernel *semakptr)
 
int __semctl (struct thread *td, struct __semctl_args *uap)
 
int semget (struct thread *td, struct semget_args *uap)
 
int semop (struct thread *td, struct semop_args *uap)
 
static struct sem_undosemu_alloc (struct thread *td)
 
static int semundo_adjust (struct thread *td, struct sem_undo **supptr, int semid, int semseq, int semnum, int adjval)
 
static void semundo_clear (int semid, int semnum)
 
 LIST_HEAD (sem_undo)
 
 SYSCTL_INT (_kern_ipc, OID_AUTO, semmni, CTLFLAG_RDTUN,&seminfo.semmni, 0,"Number of semaphore identifiers")
 
 SYSCTL_INT (_kern_ipc, OID_AUTO, semmns, CTLFLAG_RDTUN,&seminfo.semmns, 0,"Maximum number of semaphores in the system")
 
 SYSCTL_INT (_kern_ipc, OID_AUTO, semmnu, CTLFLAG_RDTUN,&seminfo.semmnu, 0,"Maximum number of undo structures in the system")
 
 SYSCTL_INT (_kern_ipc, OID_AUTO, semmsl, CTLFLAG_RW,&seminfo.semmsl, 0,"Max semaphores per id")
 
 SYSCTL_INT (_kern_ipc, OID_AUTO, semopm, CTLFLAG_RDTUN,&seminfo.semopm, 0,"Max operations per semop call")
 
 SYSCTL_INT (_kern_ipc, OID_AUTO, semume, CTLFLAG_RDTUN,&seminfo.semume, 0,"Max undo entries per process")
 
 SYSCTL_INT (_kern_ipc, OID_AUTO, semusz, CTLFLAG_RDTUN,&seminfo.semusz, 0,"Size in bytes of undo structure")
 
 SYSCTL_INT (_kern_ipc, OID_AUTO, semvmx, CTLFLAG_RW,&seminfo.semvmx, 0,"Semaphore maximum value")
 
 SYSCTL_INT (_kern_ipc, OID_AUTO, semaem, CTLFLAG_RW,&seminfo.semaem, 0,"Adjust on exit max value")
 
 SYSCTL_PROC (_kern_ipc, OID_AUTO, sema, CTLTYPE_OPAQUE|CTLFLAG_RD, NULL, 0, sysctl_sema,"","Semaphore id pool")
 
 DECLARE_MODULE (sysvsem, sysvsem_mod, SI_SUB_SYSV_SEM, SI_ORDER_FIRST)
 
 MODULE_VERSION (sysvsem, 1)
 
static int semu_try_free (struct sem_undo *suptr)
 
int sys___semctl (struct thread *td, struct __semctl_args *uap)
 
int kern_semctl (struct thread *td, int semid, int semnum, int cmd, union semun *arg, register_t *rval)
 
int sys_semget (struct thread *td, struct semget_args *uap)
 
int sys_semop (struct thread *td, struct semop_args *uap)
 

Variables

static struct mtx sem_mtx
 
static struct mtx sem_undo_mtx
 
static int semtot = 0
 
static struct semid_kernel * sema
 
static struct mtx * sema_mtx
 
static struct sem * sem
 
struct seminfo seminfo
 
static struct syscall_helper_data sem_syscalls []
 
static moduledata_t sysvsem_mod
 

Macro Definition Documentation

#define DPRINTF (   a)

Definition at line 73 of file sysv_sem.c.

Referenced by kern_semctl(), semexit_myhook(), sys_semget(), and sys_semop().

#define SEM_ALIGN (   bytes)    (((bytes) + (sizeof(long) - 1)) & ~(sizeof(long) - 1))

Definition at line 167 of file sysv_sem.c.

#define SEMAEM   16384 /* adjust on exit max value */

Definition at line 160 of file sysv_sem.c.

#define SEMMNI   50 /* # of semaphore identifiers */

Definition at line 139 of file sysv_sem.c.

#define SEMMNS   340 /* # of semaphores in system */

Definition at line 142 of file sysv_sem.c.

#define SEMMNU   150 /* # of undo structures in system */

Definition at line 148 of file sysv_sem.c.

#define SEMMSL   SEMMNS /* max # of semaphores per id */

Definition at line 153 of file sysv_sem.c.

#define SEMOPM   100 /* max # of operations per semop call */

Definition at line 156 of file sysv_sem.c.

#define SEMU (   ix)    ((struct sem_undo *)(((intptr_t)semu)+ix * seminfo.semusz))

Definition at line 175 of file sysv_sem.c.

Referenced by seminit().

#define SEMUME   50 /* max # of undo entries per process */

Definition at line 145 of file sysv_sem.c.

#define SEMUNDO_LOCK ( )    mtx_lock(&SEMUNDO_MTX);
#define SEMUNDO_LOCKASSERT (   how)    mtx_assert(&SEMUNDO_MTX, (how));
#define SEMUNDO_MTX   sem_undo_mtx
#define SEMUNDO_UNLOCK ( )    mtx_unlock(&SEMUNDO_MTX);
#define SEMUSZ   SEM_ALIGN(offsetof(struct sem_undo, un_ent[SEMUME]))

Definition at line 170 of file sysv_sem.c.

#define SEMVMX   32767 /* semaphore maximum value */

Definition at line 159 of file sysv_sem.c.

#define SMALL_SOPS   8

Function Documentation

__FBSDID ( "$BSDSUniX$"  )
int __semctl ( struct thread *  td,
struct __semctl_args uap 
)
DECLARE_MODULE ( sysvsem  ,
sysvsem_mod  ,
SI_SUB_SYSV_SEM  ,
SI_ORDER_FIRST   
)
FEATURE ( sysv_sem  ,
"System V semaphores support"   
)
int kern_semctl ( struct thread *  td,
int  semid,
int  semnum,
int  cmd,
union semun *  arg,
register_t *  rval 
)

Definition at line 579 of file sysv_sem.c.

References count, crfree(), DPRINTF, free(), ipcperm(), malloc(), prison_allow(), racct_sub_cred(), sem, sem_mtx, sema, sema_mtx, semtot, semundo_clear(), SEMUNDO_LOCK, SEMUNDO_UNLOCK, semvalid(), time_second, and wakeup().

Referenced by sys___semctl().

Here is the call graph for this function:

Here is the caller graph for this function:

LIST_HEAD ( sem_undo  )

Definition at line 103 of file sysv_sem.c.

static MALLOC_DEFINE ( M_SEM  ,
"sem"  ,
"SVID compatible semaphores"   
)
static
MODULE_VERSION ( sysvsem  ,
 
)
static void semexit_myhook ( void *  arg,
struct proc *  p 
)
static

Definition at line 1294 of file sysv_sem.c.

References DPRINTF, panic(), sema, sema_mtx, SEMUNDO_LOCK, SEMUNDO_UNLOCK, sem_undo::un_ent, and wakeup().

Referenced by seminit().

Here is the call graph for this function:

Here is the caller graph for this function:

int semget ( struct thread *  td,
struct semget_args uap 
)
static int seminit ( void  )
static

Definition at line 248 of file sysv_sem.c.

References malloc(), mtx_init(), sem, sem_mtx, sem_undo_mtx, sema, sema_mtx, semexit_myhook(), SEMU, and syscall_helper_register().

Referenced by sysvsem_modload().

Here is the call graph for this function:

Here is the caller graph for this function:

int semop ( struct thread *  td,
struct semop_args uap 
)
static struct sem_undo * semu_alloc ( struct thread *  td)
static

Definition at line 369 of file sysv_sem.c.

References SEMUNDO_LOCKASSERT.

Referenced by semundo_adjust().

Here is the caller graph for this function:

static int semu_try_free ( struct sem_undo suptr)
static

Definition at line 384 of file sysv_sem.c.

References SEMUNDO_LOCKASSERT.

Referenced by semundo_adjust(), and semundo_clear().

Here is the caller graph for this function:

static int semundo_adjust ( struct thread *  td,
struct sem_undo **  supptr,
int  semid,
int  semseq,
int  semnum,
int  adjval 
)
static

Definition at line 401 of file sysv_sem.c.

References semu_alloc(), semu_try_free(), SEMUNDO_LOCKASSERT, and sem_undo::un_ent.

Referenced by sys_semop().

Here is the call graph for this function:

Here is the caller graph for this function:

static void semundo_clear ( int  semid,
int  semnum 
)
static

Definition at line 474 of file sysv_sem.c.

References semu_try_free(), SEMUNDO_LOCKASSERT, and sem_undo::un_ent.

Referenced by kern_semctl().

Here is the call graph for this function:

Here is the caller graph for this function:

static int semunload ( void  )
static

Definition at line 303 of file sysv_sem.c.

References free(), mtx_destroy(), sem, sem_mtx, sem_undo_mtx, sema, sema_mtx, semtot, and syscall_helper_unregister().

Referenced by sysvsem_modload().

Here is the call graph for this function:

Here is the caller graph for this function:

static int semvalid ( int  semid,
struct semid_kernel *  semakptr 
)
static

Definition at line 502 of file sysv_sem.c.

Referenced by kern_semctl().

Here is the caller graph for this function:

int sys___semctl ( struct thread *  td,
struct __semctl_args uap 
)

Definition at line 521 of file sysv_sem.c.

References __semctl_args::arg, __semctl_args::cmd, kern_semctl(), __semctl_args::semid, and __semctl_args::semnum.

Here is the call graph for this function:

int sys_semget ( struct thread *  td,
struct semget_args uap 
)

Definition at line 859 of file sysv_sem.c.

References crhold(), DPRINTF, ipcperm(), semget_args::key, semget_args::nsems, prison_allow(), racct_add(), sem, sem_mtx, sema, sema_mtx, semget_args::semflg, semtot, and time_second.

Here is the call graph for this function:

int sys_semop ( struct thread *  td,
struct semop_args uap 
)
SYSCTL_INT ( _kern_ipc  ,
OID_AUTO  ,
semmni  ,
CTLFLAG_RDTUN  ,
&seminfo.  semmni,
,
"Number of semaphore identifiers"   
)
SYSCTL_INT ( _kern_ipc  ,
OID_AUTO  ,
semmns  ,
CTLFLAG_RDTUN  ,
&seminfo.  semmns,
,
"Maximum number of semaphores in the system"   
)
SYSCTL_INT ( _kern_ipc  ,
OID_AUTO  ,
semmnu  ,
CTLFLAG_RDTUN  ,
&seminfo.  semmnu,
,
"Maximum number of undo structures in the system"   
)
SYSCTL_INT ( _kern_ipc  ,
OID_AUTO  ,
semmsl  ,
CTLFLAG_RW  ,
&seminfo.  semmsl,
,
"Max semaphores per id"   
)
SYSCTL_INT ( _kern_ipc  ,
OID_AUTO  ,
semopm  ,
CTLFLAG_RDTUN  ,
&seminfo.  semopm,
,
"Max operations per semop call"   
)
SYSCTL_INT ( _kern_ipc  ,
OID_AUTO  ,
semume  ,
CTLFLAG_RDTUN  ,
&seminfo.  semume,
,
"Max undo entries per process"   
)
SYSCTL_INT ( _kern_ipc  ,
OID_AUTO  ,
semusz  ,
CTLFLAG_RDTUN  ,
&seminfo.  semusz,
,
"Size in bytes of undo structure"   
)
SYSCTL_INT ( _kern_ipc  ,
OID_AUTO  ,
semvmx  ,
CTLFLAG_RW  ,
&seminfo.  semvmx,
,
"Semaphore maximum value  
)
SYSCTL_INT ( _kern_ipc  ,
OID_AUTO  ,
semaem  ,
CTLFLAG_RW  ,
&seminfo.  semaem,
,
"Adjust on exit max value  
)
SYSCTL_PROC ( _kern_ipc  ,
OID_AUTO  ,
sema  ,
CTLTYPE_OPAQUE|  CTLFLAG_RD,
NULL  ,
,
sysctl_sema  ,
""  ,
"Semaphore id pool"   
)
static int sysctl_sema ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 1373 of file sysv_sem.c.

References sema.

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

Definition at line 332 of file sysv_sem.c.

References seminit(), and semunload().

Here is the call graph for this function:

Variable Documentation

struct sem* sem
static

Definition at line 102 of file sysv_sem.c.

Referenced by kern_semctl(), seminit(), semunload(), sys_semget(), and sys_semop().

struct mtx sem_mtx
static

Definition at line 97 of file sysv_sem.c.

Referenced by kern_semctl(), seminit(), semunload(), and sys_semget().

struct syscall_helper_data sem_syscalls[]
static
Initial value:
= {
SYSCALL_INIT_HELPER(__semctl),
SYSCALL_INIT_HELPER(semget),
SYSCALL_INIT_HELPER(semop),
SYSCALL_INIT_LAST
}
int semop(struct thread *td, struct semop_args *uap)
int __semctl(struct thread *td, struct __semctl_args *uap)
int semget(struct thread *td, struct semget_args *uap)

Definition at line 214 of file sysv_sem.c.

struct mtx sem_undo_mtx
static

Definition at line 98 of file sysv_sem.c.

Referenced by seminit(), and semunload().

struct semid_kernel* sema
static
struct mtx* sema_mtx
static

Definition at line 101 of file sysv_sem.c.

Referenced by kern_semctl(), semexit_myhook(), seminit(), semunload(), sys_semget(), and sys_semop().

struct seminfo seminfo
Initial value:
= {
}
#define SEMMNU
Definition: sysv_sem.c:148
#define SEMMSL
Definition: sysv_sem.c:153
#define SEMUSZ
Definition: sysv_sem.c:170
#define SEMAEM
Definition: sysv_sem.c:160
#define SEMVMX
Definition: sysv_sem.c:159
#define SEMUME
Definition: sysv_sem.c:145
#define SEMOPM
Definition: sysv_sem.c:156
#define SEMMNI
Definition: sysv_sem.c:139
#define SEMMNS
Definition: sysv_sem.c:142

Definition at line 181 of file sysv_sem.c.

int semtot = 0
static

Definition at line 99 of file sysv_sem.c.

Referenced by kern_semctl(), semunload(), and sys_semget().

moduledata_t sysvsem_mod
static
Initial value:
= {
"sysvsem",
NULL
}
static int sysvsem_modload(struct module *, int, void *)
Definition: sysv_sem.c:332

Definition at line 354 of file sysv_sem.c.