1 /* $FreeBSD: src/sys/kern/sysv_msg.c,v 1.23.2.5 2002/12/31 08:54:53 maxim Exp $ */
4 * Implementation of SVID messages
6 * Author: Daniel Boulet
8 * Copyright 1993 Daniel Boulet and RTMX Inc.
9 * Copyright (c) 2013 Larisa Grigore <larisagrigore@gmail.com>
11 * This system call was implemented by Daniel Boulet under contract from RTMX.
13 * Redistribution and use in source forms, with and without modification,
14 * are permitted provided that this entire comment appears intact.
16 * Redistribution in binary form may occur without any restrictions.
17 * Obviously, it would be nice if you gave credit where credit is due
18 * but requiring it would be too onerous.
20 * This software is provided ``AS IS'' without any warranties of any kind.
23 #ifndef _SYSVIPC_MSG_H_
24 #define _SYSVIPC_MSG_H_
27 #include "sysvipc_lock.h"
28 #include "sysvipc_lock_generic.h"
31 short msg_next; /* next msg in the chain */
32 long msg_type; /* type of this message */
33 /* >0 -> type of this message */
34 /* 0 -> free header */
35 u_short msg_ts; /* size of this message */
36 short msg_spot; /* location of start of msg in buffer */
39 /* Intarnal structure defined to keep compatbility with
40 * th kernel implementation.
42 struct msqid_ds_internal {
43 struct ipc_perm msg_perm; /* msg queue permission bits */
45 struct msg *msg_first;
52 u_long msg_cbytes; /* number of bytes in use on the queue */
53 u_long msg_qnum; /* number of msgs in the queue */
54 u_long msg_qbytes; /* max # of bytes on the queue */
55 pid_t msg_lspid; /* pid of last msgsnd() */
56 pid_t msg_lrpid; /* pid of last msgrcv() */
57 time_t msg_stime; /* time of last msgsnd() */
59 time_t msg_rtime; /* time of last msgrcv() */
61 time_t msg_ctime; /* time of last msgctl() */
67 #define MSGSSZ 8 /* Each segment must be 2^N long */
70 #define MSGSEG 256 /* must be calculated such that all
71 structure fits in PAGE_SIZE. */
73 #define MSGMAX (MSGSSZ*MSGSEG)
75 #define MSGMNB 2048 /* max # of bytes in a queue */
84 /* Each message is broken up and stored in segments that are msgssz bytes
85 * long. For efficiency reasons, this should be a power of two. Also,
86 * it doesn't make sense if it is less than 8 or greater than about 256.
87 * Consequently, msginit in kern/sysv_msg.c checks that msgssz is a power of
88 * two between 8 and 1024 inclusive (and panic's if it isn't).
91 int msgmax, /* max chars in a message */
92 msgmni, /* max message queue identifiers */
93 msgmnb, /* max chars in a queue */
94 msgtql, /* max messages in system */
95 msgssz, /* size of a message segment (see notes above) */
96 msgseg; /* number of message segments */
100 short next; /* next segment in buffer */
101 /* -1 -> available */
102 /* 0..(MSGSEG-1) -> index of next segment */
107 struct sysv_rwlock rwlock;
109 struct sysv_mutex mutex;
111 struct msqid_ds_internal ds;
113 int nfree_msgmaps; /* # of free map entries */
114 short free_msgmaps; /* head of linked list of free map entries */
115 short free_msghdrs;/* list of free msg headers */
116 struct msg msghdrs[MSGTQL]; /* MSGTQL msg headers */
117 struct msgmap msgmaps[MSGSEG]; /* MSGSEG msgmap structures */
118 char msgpool[MSGMAX]; /* MSGMAX byte long msg buffer pool */
121 int sysvipc_msgctl(int, int, struct msqid_ds *);
122 int sysvipc_msgget(key_t, int);
123 int sysvipc_msgsnd(int, const void *, size_t, int);
124 int sysvipc_msgrcv(int, void *, size_t, long, int);
126 #endif /* !_SYSVIPC_MSG_H_ */