sysv_msg.c (cb1f0db9dbf89ed25f16308c33a721e7ed6ba531) sysv_msg.c (78525ce3185cb7196d629f4b1ec2fa2a5039129b)
1/* $FreeBSD$ */
2
3/*
4 * Implementation of SVID messages
5 *
6 * Author: Daniel Boulet
7 *
8 * Copyright 1993 Daniel Boulet and RTMX Inc.

--- 13 unchanged lines hidden (view full) ---

22#include "opt_sysvipc.h"
23
24#include <sys/param.h>
25#include <sys/systm.h>
26#include <sys/sysproto.h>
27#include <sys/kernel.h>
28#include <sys/proc.h>
29#include <sys/msg.h>
1/* $FreeBSD$ */
2
3/*
4 * Implementation of SVID messages
5 *
6 * Author: Daniel Boulet
7 *
8 * Copyright 1993 Daniel Boulet and RTMX Inc.

--- 13 unchanged lines hidden (view full) ---

22#include "opt_sysvipc.h"
23
24#include <sys/param.h>
25#include <sys/systm.h>
26#include <sys/sysproto.h>
27#include <sys/kernel.h>
28#include <sys/proc.h>
29#include <sys/msg.h>
30#include <sys/syscall.h>
30#include <sys/sysent.h>
31#include <sys/sysctl.h>
32#include <sys/malloc.h>
33#include <sys/jail.h>
34
35static MALLOC_DEFINE(M_MSG, "msg", "SVID compatible message queues");
36
31#include <sys/sysent.h>
32#include <sys/sysctl.h>
33#include <sys/malloc.h>
34#include <sys/jail.h>
35
36static MALLOC_DEFINE(M_MSG, "msg", "SVID compatible message queues");
37
37static void msginit __P((void *));
38static void msginit __P((void));
39static int msgunload __P((void));
40static int sysvmsg_modload __P((struct module *, int, void *));
38
39#define MSG_DEBUG
40#undef MSG_DEBUG_OK
41
42static void msg_freehdr __P((struct msg *msghdr));
43
44/* XXX casting to (sy_call_t *) is bogus, as usual. */
45static sy_call_t *msgcalls[] = {

--- 72 unchanged lines hidden (view full) ---

118static short free_msgmaps; /* head of linked list of free map entries */
119static struct msg *free_msghdrs;/* list of free msg headers */
120static char *msgpool; /* MSGMAX byte long msg buffer pool */
121static struct msgmap *msgmaps; /* MSGSEG msgmap structures */
122static struct msg *msghdrs; /* MSGTQL msg headers */
123static struct msqid_ds *msqids; /* MSGMNI msqid_ds struct's */
124
125static void
41
42#define MSG_DEBUG
43#undef MSG_DEBUG_OK
44
45static void msg_freehdr __P((struct msg *msghdr));
46
47/* XXX casting to (sy_call_t *) is bogus, as usual. */
48static sy_call_t *msgcalls[] = {

--- 72 unchanged lines hidden (view full) ---

121static short free_msgmaps; /* head of linked list of free map entries */
122static struct msg *free_msghdrs;/* list of free msg headers */
123static char *msgpool; /* MSGMAX byte long msg buffer pool */
124static struct msgmap *msgmaps; /* MSGSEG msgmap structures */
125static struct msg *msghdrs; /* MSGTQL msg headers */
126static struct msqid_ds *msqids; /* MSGMNI msqid_ds struct's */
127
128static void
126msginit(dummy)
127 void *dummy;
129msginit()
128{
129 register int i;
130
131 msgpool = malloc(msginfo.msgmax, M_MSG, M_WAITOK);
132 if (msgpool == NULL)
133 panic("msgpool is NULL");
134 msgmaps = malloc(sizeof(struct msgmap) * msginfo.msgseg, M_MSG, M_WAITOK);
135 if (msgmaps == NULL)

--- 51 unchanged lines hidden (view full) ---

187 panic("msqids is NULL");
188
189 for (i = 0; i < msginfo.msgmni; i++) {
190 msqids[i].msg_qbytes = 0; /* implies entry is available */
191 msqids[i].msg_perm.seq = 0; /* reset to a known value */
192 msqids[i].msg_perm.mode = 0;
193 }
194}
130{
131 register int i;
132
133 msgpool = malloc(msginfo.msgmax, M_MSG, M_WAITOK);
134 if (msgpool == NULL)
135 panic("msgpool is NULL");
136 msgmaps = malloc(sizeof(struct msgmap) * msginfo.msgseg, M_MSG, M_WAITOK);
137 if (msgmaps == NULL)

--- 51 unchanged lines hidden (view full) ---

189 panic("msqids is NULL");
190
191 for (i = 0; i < msginfo.msgmni; i++) {
192 msqids[i].msg_qbytes = 0; /* implies entry is available */
193 msqids[i].msg_perm.seq = 0; /* reset to a known value */
194 msqids[i].msg_perm.mode = 0;
195 }
196}
195SYSINIT(sysv_msg, SI_SUB_SYSV_MSG, SI_ORDER_FIRST, msginit, NULL)
196
197
198static int
199msgunload()
200{
201 struct msqid_ds *msqptr;
202 int msqid;
203
204 for (msqid = 0; msqid < msginfo.msgmni; msqid++) {
205 /*
206 * Look for an unallocated and unlocked msqid_ds.
207 * msqid_ds's can be locked by msgsnd or msgrcv while
208 * they are copying the message in/out. We can't
209 * re-use the entry until they release it.
210 */
211 msqptr = &msqids[msqid];
212 if (msqptr->msg_qbytes != 0 ||
213 (msqptr->msg_perm.mode & MSG_LOCKED) != 0)
214 break;
215 }
216 if (msqid != msginfo.msgmni)
217 return (EBUSY);
218
219 free(msgpool, M_MSG);
220 free(msgmaps, M_MSG);
221 free(msghdrs, M_MSG);
222 free(msqids, M_MSG);
223 return (0);
224}
225
226
227static int
228sysvmsg_modload(struct module *module, int cmd, void *arg)
229{
230 int error = 0;
231
232 switch (cmd) {
233 case MOD_LOAD:
234 msginit();
235 break;
236 case MOD_UNLOAD:
237 error = msgunload();
238 break;
239 case MOD_SHUTDOWN:
240 break;
241 default:
242 error = EINVAL;
243 break;
244 }
245 return (error);
246}
247
248static moduledata_t sysvmsg_moduledata = {
249 "sysvmsg_mod",
250 &sysvmsg_modload,
251 NULL
252};
253
254SYSCALL_MODULE_HELPER(msgctl, 3);
255SYSCALL_MODULE_HELPER(msgget, 2);
256SYSCALL_MODULE_HELPER(msgsnd, 4);
257SYSCALL_MODULE_HELPER(msgrcv, 5);
258
259DECLARE_MODULE(sysvmsg_mod, sysvmsg_moduledata,
260 SI_SUB_SYSV_MSG, SI_ORDER_FIRST);
261
197/*
198 * Entry point for all MSG calls
199 */
200int
201msgsys(p, uap)
202 struct proc *p;
203 /* XXX actually varargs. */
204 struct msgsys_args /* {

--- 897 unchanged lines hidden ---
262/*
263 * Entry point for all MSG calls
264 */
265int
266msgsys(p, uap)
267 struct proc *p;
268 /* XXX actually varargs. */
269 struct msgsys_args /* {

--- 897 unchanged lines hidden ---