FreeBSD kernel kern code
sysv_msg.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/kernel.h>
#include <sys/priv.h>
#include <sys/proc.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/module.h>
#include <sys/msg.h>
#include <sys/racct.h>
#include <sys/syscall.h>
#include <sys/syscallsubr.h>
#include <sys/sysent.h>
#include <sys/sysctl.h>
#include <sys/malloc.h>
#include <sys/jail.h>
#include <security/mac/mac_framework.h>
Include dependency graph for sysv_msg.c:

Go to the source code of this file.

Data Structures

struct  msgmap
 
struct  msgctl_args
 
struct  msgget_args
 
struct  msgsnd_args
 
struct  msgrcv_args
 

Macros

#define DPRINTF(a)   (void)0
 
#define MSGSSZ   8 /* Each segment must be 2^N long */
 
#define MSGSEG   2048 /* must be less than 32767 */
 
#define MSGMAX   (MSGSSZ*MSGSEG)
 
#define MSGMNB   2048 /* max # of bytes in a queue */
 
#define MSGMNI   40
 
#define MSGTQL   40
 
#define MSQID(ix, ds)   ((ix) & 0xffff | (((ds).msg_perm.seq << 16) & 0xffff0000))
 
#define MSQID_IX(id)   ((id) & 0xffff)
 
#define MSQID_SEQ(id)   (((id) >> 16) & 0xffff)
 
#define MSG_LOCKED   01000 /* Is this msqid_ds locked? */
 

Functions

 __FBSDID ("$BSDSUniX$")
 
 FEATURE (sysv_msg,"System V message queues support")
 
static MALLOC_DEFINE (M_MSG,"msg","SVID compatible message queues")
 
static int msginit (void)
 
static int msgunload (void)
 
static int sysvmsg_modload (struct module *, int, void *)
 
static void msg_freehdr (struct msg *msghdr)
 
 DECLARE_MODULE (sysvmsg, sysvmsg_mod, SI_SUB_SYSV_MSG, SI_ORDER_FIRST)
 
 MODULE_VERSION (sysvmsg, 1)
 
int sys_msgctl (struct thread *td, struct msgctl_args *uap)
 
int kern_msgctl (struct thread *td, int msqid, int cmd, struct msqid_ds *msqbuf)
 
int sys_msgget (struct thread *td, struct msgget_args *uap)
 
int kern_msgsnd (struct thread *td, int msqid, const void *msgp, size_t msgsz, int msgflg, long mtype)
 
int sys_msgsnd (struct thread *td, struct msgsnd_args *uap)
 
int kern_msgrcv (struct thread *td, int msqid, void *msgp, size_t msgsz, long msgtyp, int msgflg, long *mtype)
 
int sys_msgrcv (struct thread *td, struct msgrcv_args *uap)
 
static int sysctl_msqids (SYSCTL_HANDLER_ARGS)
 
 SYSCTL_INT (_kern_ipc, OID_AUTO, msgmax, CTLFLAG_RD,&msginfo.msgmax, 0,"Maximum message size")
 
 SYSCTL_INT (_kern_ipc, OID_AUTO, msgmni, CTLFLAG_RDTUN,&msginfo.msgmni, 0,"Number of message queue identifiers")
 
 SYSCTL_INT (_kern_ipc, OID_AUTO, msgmnb, CTLFLAG_RDTUN,&msginfo.msgmnb, 0,"Maximum number of bytes in a queue")
 
 SYSCTL_INT (_kern_ipc, OID_AUTO, msgtql, CTLFLAG_RDTUN,&msginfo.msgtql, 0,"Maximum number of messages in the system")
 
 SYSCTL_INT (_kern_ipc, OID_AUTO, msgssz, CTLFLAG_RDTUN,&msginfo.msgssz, 0,"Size of a message segment")
 
 SYSCTL_INT (_kern_ipc, OID_AUTO, msgseg, CTLFLAG_RDTUN,&msginfo.msgseg, 0,"Number of message segments")
 
 SYSCTL_PROC (_kern_ipc, OID_AUTO, msqids, CTLTYPE_OPAQUE|CTLFLAG_RD, NULL, 0, sysctl_msqids,"","Message queue IDs")
 

Variables

struct msginfo msginfo
 
static int nfree_msgmaps
 
static short free_msgmaps
 
static struct msg * free_msghdrs
 
static char * msgpool
 
static struct msgmapmsgmaps
 
static struct msg * msghdrs
 
static struct msqid_kernel * msqids
 
static struct mtx msq_mtx
 
static struct syscall_helper_data msg_syscalls []
 
static moduledata_t sysvmsg_mod
 

Macro Definition Documentation

#define DPRINTF (   a)    (void)0
#define MSG_LOCKED   01000 /* Is this msqid_ds locked? */

Definition at line 148 of file sysv_msg.c.

Referenced by kern_msgsnd(), msgunload(), and sys_msgget().

#define MSGMAX   (MSGSSZ*MSGSEG)

Definition at line 99 of file sysv_msg.c.

#define MSGMNB   2048 /* max # of bytes in a queue */

Definition at line 101 of file sysv_msg.c.

#define MSGMNI   40

Definition at line 104 of file sysv_msg.c.

#define MSGSEG   2048 /* must be less than 32767 */

Definition at line 97 of file sysv_msg.c.

#define MSGSSZ   8 /* Each segment must be 2^N long */

Definition at line 94 of file sysv_msg.c.

#define MSGTQL   40

Definition at line 107 of file sysv_msg.c.

#define MSQID (   ix,
  ds 
)    ((ix) & 0xffff | (((ds).msg_perm.seq << 16) & 0xffff0000))

Definition at line 134 of file sysv_msg.c.

#define MSQID_IX (   id)    ((id) & 0xffff)

Definition at line 135 of file sysv_msg.c.

#define MSQID_SEQ (   id)    (((id) >> 16) & 0xffff)

Definition at line 136 of file sysv_msg.c.

Function Documentation

__FBSDID ( "$BSDSUniX$"  )
DECLARE_MODULE ( sysvmsg  ,
sysvmsg_mod  ,
SI_SUB_SYSV_MSG  ,
SI_ORDER_FIRST   
)
FEATURE ( sysv_msg  ,
"System V message queues support"   
)
int kern_msgctl ( struct thread *  td,
int  msqid,
int  cmd,
struct msqid_ds *  msqbuf 
)

Definition at line 403 of file sysv_msg.c.

References crfree(), DPRINTF, ipcperm(), msg_freehdr(), msginfo, msq_mtx, msqids, panic(), prison_allow(), priv_check(), racct_sub_cred(), time_second, and wakeup().

Referenced by sys_msgctl().

Here is the call graph for this function:

Here is the caller graph for this function:

int kern_msgrcv ( struct thread *  td,
int  msqid,
void *  msgp,
size_t  msgsz,
long  msgtyp,
int  msgflg,
long *  mtype 
)

Definition at line 1045 of file sysv_msg.c.

References DPRINTF, ipcperm(), msg_freehdr(), msginfo, msgpool, msq_mtx, msqids, msgmap::next, panic(), prison_allow(), racct_sub_cred(), time_second, and wakeup().

Referenced by sys_msgrcv().

Here is the call graph for this function:

Here is the caller graph for this function:

int kern_msgsnd ( struct thread *  td,
int  msqid,
const void *  msgp,
size_t  msgsz,
int  msgflg,
long  mtype 
)

Definition at line 680 of file sysv_msg.c.

References DPRINTF, free_msghdrs, free_msgmaps, hz, ipcperm(), msg_freehdr(), MSG_LOCKED, msginfo, msgpool, msq_mtx, msqids, msgmap::next, nfree_msgmaps, panic(), prison_allow(), racct_add(), racct_sub(), time_second, and wakeup().

Referenced by sys_msgsnd().

Here is the call graph for this function:

Here is the caller graph for this function:

static MALLOC_DEFINE ( M_MSG  ,
"msg"  ,
"SVID compatible message queues"   
)
static
MODULE_VERSION ( sysvmsg  ,
 
)
static void msg_freehdr ( struct msg *  msghdr)
static

Definition at line 349 of file sysv_msg.c.

References free_msghdrs, free_msgmaps, msginfo, msgmap::next, nfree_msgmaps, and panic().

Referenced by kern_msgctl(), kern_msgrcv(), and kern_msgsnd().

Here is the call graph for this function:

Here is the caller graph for this function:

static int msginit ( void  )
static

Definition at line 195 of file sysv_msg.c.

References DPRINTF, free_msghdrs, free_msgmaps, malloc(), msg_syscalls, msghdrs, msginfo, msgpool, msq_mtx, msqids, mtx_init(), msgmap::next, nfree_msgmaps, panic(), and syscall_helper_register().

Referenced by sysvmsg_modload().

Here is the call graph for this function:

Here is the caller graph for this function:

static int msgunload ( void  )
static

Definition at line 273 of file sysv_msg.c.

References free(), MSG_LOCKED, msg_syscalls, msghdrs, msginfo, msgpool, msq_mtx, msqids, mtx_destroy(), and syscall_helper_unregister().

Referenced by sysvmsg_modload().

Here is the call graph for this function:

Here is the caller graph for this function:

int sys_msgctl ( struct thread *  td,
struct msgctl_args uap 
)

Definition at line 383 of file sysv_msg.c.

References DPRINTF, kern_msgctl(), and msgctl_args::msqid.

Here is the call graph for this function:

int sys_msgget ( struct thread *  td,
struct msgget_args uap 
)

Definition at line 561 of file sysv_msg.c.

References crhold(), DPRINTF, ipcperm(), msgget_args::key, MSG_LOCKED, msginfo, msq_mtx, msqids, prison_allow(), racct_add(), and time_second.

Here is the call graph for this function:

int sys_msgrcv ( struct thread *  td,
struct msgrcv_args uap 
)

Definition at line 1301 of file sysv_msg.c.

References DPRINTF, and kern_msgrcv().

Here is the call graph for this function:

int sys_msgsnd ( struct thread *  td,
struct msgsnd_args uap 
)

Definition at line 1016 of file sysv_msg.c.

References DPRINTF, and kern_msgsnd().

Here is the call graph for this function:

SYSCTL_INT ( _kern_ipc  ,
OID_AUTO  ,
msgmax  ,
CTLFLAG_RD  ,
&msginfo.  msgmax,
,
"Maximum message size"   
)
SYSCTL_INT ( _kern_ipc  ,
OID_AUTO  ,
msgmni  ,
CTLFLAG_RDTUN  ,
&msginfo.  msgmni,
,
"Number of message queue identifiers"   
)
SYSCTL_INT ( _kern_ipc  ,
OID_AUTO  ,
msgmnb  ,
CTLFLAG_RDTUN  ,
&msginfo.  msgmnb,
,
"Maximum number of bytes in a queue"   
)
SYSCTL_INT ( _kern_ipc  ,
OID_AUTO  ,
msgtql  ,
CTLFLAG_RDTUN  ,
&msginfo.  msgtql,
,
"Maximum number of messages in the system"   
)
SYSCTL_INT ( _kern_ipc  ,
OID_AUTO  ,
msgssz  ,
CTLFLAG_RDTUN  ,
&msginfo.  msgssz,
,
"Size of a message segment"   
)
SYSCTL_INT ( _kern_ipc  ,
OID_AUTO  ,
msgseg  ,
CTLFLAG_RDTUN  ,
&msginfo.  msgseg,
,
"Number of message segments"   
)
static int sysctl_msqids ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 1321 of file sysv_msg.c.

References msginfo, and msqids.

SYSCTL_PROC ( _kern_ipc  ,
OID_AUTO  ,
msqids  ,
CTLTYPE_OPAQUE|  CTLFLAG_RD,
NULL  ,
,
sysctl_msqids  ,
""  ,
"Message queue IDs"   
)
static int sysvmsg_modload ( struct module module,
int  cmd,
void *  arg 
)
static

Definition at line 317 of file sysv_msg.c.

References msginit(), and msgunload().

Here is the call graph for this function:

Variable Documentation

struct msg* free_msghdrs
static

Definition at line 152 of file sysv_msg.c.

Referenced by kern_msgsnd(), msg_freehdr(), and msginit().

short free_msgmaps
static

Definition at line 151 of file sysv_msg.c.

Referenced by kern_msgsnd(), msg_freehdr(), and msginit().

struct syscall_helper_data msg_syscalls[]
static
Initial value:
= {
SYSCALL_INIT_HELPER(msgctl),
SYSCALL_INIT_HELPER(msgget),
SYSCALL_INIT_HELPER(msgsnd),
SYSCALL_INIT_HELPER(msgrcv),
SYSCALL_INIT_LAST
}

Definition at line 159 of file sysv_msg.c.

Referenced by msginit(), and msgunload().

struct msg* msghdrs
static

Definition at line 155 of file sysv_msg.c.

Referenced by msginit(), and msgunload().

struct msginfo msginfo
Initial value:
= {
}
#define MSGMAX
Definition: sysv_msg.c:99
#define MSGMNB
Definition: sysv_msg.c:101
#define MSGMNI
Definition: sysv_msg.c:104
#define MSGTQL
Definition: sysv_msg.c:107
#define MSGSSZ
Definition: sysv_msg.c:94
#define MSGSEG
Definition: sysv_msg.c:97

Definition at line 120 of file sysv_msg.c.

Referenced by kern_msgctl(), kern_msgrcv(), kern_msgsnd(), msg_freehdr(), msginit(), msgunload(), sys_msgget(), and sysctl_msqids().

struct msgmap* msgmaps
static

Definition at line 154 of file sysv_msg.c.

char* msgpool
static

Definition at line 153 of file sysv_msg.c.

Referenced by kern_msgrcv(), kern_msgsnd(), msginit(), and msgunload().

struct mtx msq_mtx
static

Definition at line 157 of file sysv_msg.c.

Referenced by kern_msgctl(), kern_msgrcv(), kern_msgsnd(), msginit(), msgunload(), and sys_msgget().

struct msqid_kernel* msqids
static
int nfree_msgmaps
static

Definition at line 150 of file sysv_msg.c.

Referenced by kern_msgsnd(), msg_freehdr(), and msginit().

moduledata_t sysvmsg_mod
static
Initial value:
= {
"sysvmsg",
NULL
}
static int sysvmsg_modload(struct module *, int, void *)
Definition: sysv_msg.c:317

Definition at line 339 of file sysv_msg.c.