FreeBSD kernel kern code
sysv_msg.c File Reference
#include <sys/cdefs.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/mount.h>
#include <sys/msg.h>
#include <sys/racct.h>
#include <sys/sx.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/audit/audit.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 ("$FreeBSD$")
 
 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 msq_remove (struct msqid_kernel *)
 
static struct prison * msg_find_prison (struct ucred *)
 
static int msq_prison_cansee (struct prison *, struct msqid_kernel *)
 
static int msg_prison_check (void *, void *)
 
static int msg_prison_set (void *, void *)
 
static int msg_prison_get (void *, void *)
 
static int msg_prison_remove (void *, void *)
 
static void msg_prison_cleanup (struct prison *)
 
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|CTLFLAG_MPSAFE, NULL, 0, sysctl_msqids, "", "Array of struct msqid_kernel for each potential message queue")
 
static int msg_prison_remove (void *obj, void *data __unused)
 
 SYSCTL_JAIL_PARAM_SYS_NODE (sysvmsg, CTLFLAG_RW, "SYSV message queues")
 

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 unsigned msg_prison_slot
 
static struct syscall_helper_data msg_syscalls []
 
static moduledata_t sysvmsg_mod
 

Macro Definition Documentation

◆ DPRINTF

#define DPRINTF (   a)    (void)0

Definition at line 105 of file sysv_msg.c.

◆ MSG_LOCKED

#define MSG_LOCKED   01000 /* Is this msqid_ds locked? */

Definition at line 165 of file sysv_msg.c.

◆ MSGMAX

#define MSGMAX   (MSGSSZ*MSGSEG)

Definition at line 116 of file sysv_msg.c.

◆ MSGMNB

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

Definition at line 118 of file sysv_msg.c.

◆ MSGMNI

#define MSGMNI   40

Definition at line 121 of file sysv_msg.c.

◆ MSGSEG

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

Definition at line 114 of file sysv_msg.c.

◆ MSGSSZ

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

Definition at line 111 of file sysv_msg.c.

◆ MSGTQL

#define MSGTQL   40

Definition at line 124 of file sysv_msg.c.

◆ MSQID

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

Definition at line 151 of file sysv_msg.c.

◆ MSQID_IX

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

Definition at line 152 of file sysv_msg.c.

◆ MSQID_SEQ

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

Definition at line 153 of file sysv_msg.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ DECLARE_MODULE()

DECLARE_MODULE ( sysvmsg  ,
sysvmsg_mod  ,
SI_SUB_SYSV_MSG  ,
SI_ORDER_FIRST   
)

◆ FEATURE()

FEATURE ( sysv_msg  ,
"System V message queues support"   
)

◆ kern_msgctl()

int kern_msgctl ( struct thread *  td,
int  msqid,
int  cmd,
struct msqid_ds *  msqbuf 
)

Definition at line 499 of file sysv_msg.c.

References DPRINTF, ipcperm(), msg_find_prison(), msginfo, msq_mtx, msq_prison_cansee(), msq_remove(), msqids, priv_check(), and time_second.

Referenced by sys_msgctl().

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

◆ kern_msgrcv()

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

Definition at line 1139 of file sysv_msg.c.

References DPRINTF, ipcperm(), msg_find_prison(), msg_freehdr(), msginfo, msgmaps, msgpool, msq_mtx, msq_prison_cansee(), msqids, msgmap::next, panic(), time_second, and wakeup().

Referenced by sys_msgrcv().

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

◆ kern_msgsnd()

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

Definition at line 769 of file sysv_msg.c.

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

Referenced by sys_msgsnd().

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

◆ MALLOC_DEFINE()

static MALLOC_DEFINE ( M_MSG  ,
"msg"  ,
"SVID compatible message queues"   
)
static

◆ MODULE_VERSION()

MODULE_VERSION ( sysvmsg  ,
 
)

◆ msg_find_prison()

static struct prison * msg_find_prison ( struct ucred *  cred)
static

Definition at line 451 of file sysv_msg.c.

References msg_prison_slot, and pr.

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

Here is the caller graph for this function:

◆ msg_freehdr()

static void msg_freehdr ( struct msg *  msghdr)
static

Definition at line 387 of file sysv_msg.c.

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

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

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

◆ msg_prison_check()

static int msg_prison_check ( void *  obj,
void *  data 
)
static

Definition at line 1500 of file sysv_msg.c.

References data, msg_prison_slot, pr, and vfs_copyopt().

Referenced by msginit().

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

◆ msg_prison_cleanup()

static void msg_prison_cleanup ( struct prison *  pr)
static

Definition at line 1656 of file sysv_msg.c.

References msginfo, msq_mtx, msq_remove(), msqids, and pr.

Referenced by msg_prison_remove(), and msg_prison_set().

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

◆ msg_prison_get()

static int msg_prison_get ( void *  obj,
void *  data 
)
static

Definition at line 1622 of file sysv_msg.c.

References data, msg_prison_slot, pr, and vfs_setopt().

Referenced by msginit().

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

◆ msg_prison_remove() [1/2]

static int msg_prison_remove ( void *  ,
void *   
)
static

Referenced by msginit().

Here is the caller graph for this function:

◆ msg_prison_remove() [2/2]

static int msg_prison_remove ( void *  obj,
void *data  __unused 
)
static

Definition at line 1642 of file sysv_msg.c.

References msg_prison_cleanup(), msg_prison_slot, and pr.

Here is the call graph for this function:

◆ msg_prison_set()

static int msg_prison_set ( void *  obj,
void *  data 
)
static

Definition at line 1535 of file sysv_msg.c.

References data, msg_prison_cleanup(), msg_prison_slot, osd_free_reserved(), osd_reserve(), pr, vfs_copyopt(), and vfs_flagopt().

Referenced by msginit().

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

◆ msginit()

static int msginit ( void  )
static

◆ msgunload()

static int msgunload ( void  )
static

Definition at line 316 of file sysv_msg.c.

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

Referenced by sysvmsg_modload().

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

◆ msq_prison_cansee()

static int msq_prison_cansee ( struct prison *  rpr,
struct msqid_kernel *  msqkptr 
)
static

Definition at line 463 of file sysv_msg.c.

References prison_ischild().

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

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

◆ msq_remove()

static void msq_remove ( struct msqid_kernel *  msqkptr)
static

Definition at line 413 of file sysv_msg.c.

References crfree(), msg_freehdr(), panic(), and wakeup().

Referenced by kern_msgctl(), and msg_prison_cleanup().

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

◆ sys_msgctl()

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

Definition at line 481 of file sysv_msg.c.

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

Here is the call graph for this function:

◆ sys_msgget()

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

Definition at line 645 of file sysv_msg.c.

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

Here is the call graph for this function:

◆ sys_msgrcv()

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

Definition at line 1399 of file sysv_msg.c.

References DPRINTF, kern_msgrcv(), msgrcv_args::msgflg, msgrcv_args::msgp, msgrcv_args::msgsz, msgrcv_args::msgtyp, and msgrcv_args::msqid.

Here is the call graph for this function:

◆ sys_msgsnd()

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

Definition at line 1111 of file sysv_msg.c.

References DPRINTF, kern_msgsnd(), msgsnd_args::msgflg, msgsnd_args::msgp, msgsnd_args::msgsz, and msgsnd_args::msqid.

Here is the call graph for this function:

◆ SYSCTL_INT() [1/6]

SYSCTL_INT ( _kern_ipc  ,
OID_AUTO  ,
msgmax  ,
CTLFLAG_RD  ,
&msginfo.  msgmax,
,
"Maximum message size"   
)

◆ SYSCTL_INT() [2/6]

SYSCTL_INT ( _kern_ipc  ,
OID_AUTO  ,
msgmnb  ,
CTLFLAG_RDTUN  ,
&msginfo.  msgmnb,
,
"Maximum number of bytes in a queue"   
)

◆ SYSCTL_INT() [3/6]

SYSCTL_INT ( _kern_ipc  ,
OID_AUTO  ,
msgmni  ,
CTLFLAG_RDTUN  ,
&msginfo.  msgmni,
,
"Number of message queue identifiers"   
)

◆ SYSCTL_INT() [4/6]

SYSCTL_INT ( _kern_ipc  ,
OID_AUTO  ,
msgseg  ,
CTLFLAG_RDTUN  ,
&msginfo.  msgseg,
,
"Number of message segments"   
)

◆ SYSCTL_INT() [5/6]

SYSCTL_INT ( _kern_ipc  ,
OID_AUTO  ,
msgssz  ,
CTLFLAG_RDTUN  ,
&msginfo.  msgssz,
,
"Size of a message segment"   
)

◆ SYSCTL_INT() [6/6]

SYSCTL_INT ( _kern_ipc  ,
OID_AUTO  ,
msgtql  ,
CTLFLAG_RDTUN  ,
&msginfo.  msgtql,
,
"Maximum number of messages in the system"   
)

◆ SYSCTL_JAIL_PARAM_SYS_NODE()

SYSCTL_JAIL_PARAM_SYS_NODE ( sysvmsg  ,
CTLFLAG_RW  ,
"SYSV message queues"   
)

◆ sysctl_msqids()

static int sysctl_msqids ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 1417 of file sysv_msg.c.

References msg_find_prison(), msginfo, msq_mtx, msq_prison_cansee(), msqids, and pr.

Here is the call graph for this function:

◆ SYSCTL_PROC()

SYSCTL_PROC ( _kern_ipc  ,
OID_AUTO  ,
msqids  ,
CTLTYPE_OPAQUE|CTLFLAG_RD|  CTLFLAG_MPSAFE,
NULL  ,
,
sysctl_msqids  ,
""  ,
"Array of struct msqid_kernel for each potential message queue"   
)

◆ sysvmsg_modload()

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

Definition at line 355 of file sysv_msg.c.

References msginit(), and msgunload().

Here is the call graph for this function:

Variable Documentation

◆ free_msghdrs

struct msg* free_msghdrs
static

Definition at line 169 of file sysv_msg.c.

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

◆ free_msgmaps

short free_msgmaps
static

Definition at line 168 of file sysv_msg.c.

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

◆ msg_prison_slot

unsigned msg_prison_slot
static

◆ msg_syscalls

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 177 of file sysv_msg.c.

Referenced by msginit(), and msgunload().

◆ msghdrs

struct msg* msghdrs
static

Definition at line 172 of file sysv_msg.c.

Referenced by msginit(), and msgunload().

◆ msginfo

struct msginfo msginfo
Initial value:
= {
}
#define MSGMNI
Definition: sysv_msg.c:121
#define MSGMAX
Definition: sysv_msg.c:116
#define MSGTQL
Definition: sysv_msg.c:124
#define MSGSEG
Definition: sysv_msg.c:114
#define MSGSSZ
Definition: sysv_msg.c:111
#define MSGMNB
Definition: sysv_msg.c:118

Definition at line 137 of file sysv_msg.c.

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

◆ msgmaps

struct msgmap* msgmaps
static

Definition at line 171 of file sysv_msg.c.

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

◆ msgpool

char* msgpool
static

Definition at line 170 of file sysv_msg.c.

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

◆ msq_mtx

struct mtx msq_mtx
static

◆ msqids

struct msqid_kernel* msqids
static

◆ nfree_msgmaps

int nfree_msgmaps
static

Definition at line 167 of file sysv_msg.c.

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

◆ sysvmsg_mod

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

Definition at line 377 of file sysv_msg.c.