1 /* $FreeBSD: src/sys/kern/sysv_msg.c,v 1.23.2.5 2002/12/31 08:54:53 maxim Exp $ */
2 /* $DragonFly: src/sys/kern/sysv_msg.c,v 1.3 2003/06/23 17:55:41 dillon Exp $ */
5 * Implementation of SVID messages
7 * Author: Daniel Boulet
9 * Copyright 1993 Daniel Boulet and RTMX Inc.
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 #include "opt_sysvipc.h"
25 #include <sys/param.h>
26 #include <sys/systm.h>
27 #include <sys/sysproto.h>
28 #include <sys/kernel.h>
31 #include <sys/sysent.h>
32 #include <sys/sysctl.h>
33 #include <sys/malloc.h>
36 static MALLOC_DEFINE(M_MSG, "msg", "SVID compatible message queues");
38 static void msginit __P((void *));
43 static void msg_freehdr __P((struct msg *msghdr));
45 /* XXX casting to (sy_call_t *) is bogus, as usual. */
46 static sy_call_t *msgcalls[] = {
47 (sy_call_t *)msgctl, (sy_call_t *)msgget,
48 (sy_call_t *)msgsnd, (sy_call_t *)msgrcv
52 struct msg *msg_next; /* next msg in the chain */
53 long msg_type; /* type of this message */
54 /* >0 -> type of this message */
55 /* 0 -> free header */
56 u_short msg_ts; /* size of this message */
57 short msg_spot; /* location of start of msg in buffer */
62 #define MSGSSZ 8 /* Each segment must be 2^N long */
65 #define MSGSEG 2048 /* must be less than 32767 */
67 #define MSGMAX (MSGSSZ*MSGSEG)
69 #define MSGMNB 2048 /* max # of bytes in a queue */
79 * Based on the configuration parameters described in an SVR2 (yes, two)
80 * config(1m) man page.
82 * Each message is broken up and stored in segments that are msgssz bytes
83 * long. For efficiency reasons, this should be a power of two. Also,
84 * it doesn't make sense if it is less than 8 or greater than about 256.
85 * Consequently, msginit in kern/sysv_msg.c checks that msgssz is a power of
86 * two between 8 and 1024 inclusive (and panic's if it isn't).
88 struct msginfo msginfo = {
89 MSGMAX, /* max chars in a message */
90 MSGMNI, /* # of message queue identifiers */
91 MSGMNB, /* max chars in a queue */
92 MSGTQL, /* max messages in system */
93 MSGSSZ, /* size of a message segment */
94 /* (must be small power of 2 greater than 4) */
95 MSGSEG /* number of message segments */
99 * macros to convert between msqid_ds's and msqid's.
100 * (specific to this implementation)
102 #define MSQID(ix,ds) ((ix) & 0xffff | (((ds).msg_perm.seq << 16) & 0xffff0000))
103 #define MSQID_IX(id) ((id) & 0xffff)
104 #define MSQID_SEQ(id) (((id) >> 16) & 0xffff)
107 * The rest of this file is specific to this particular implementation.
111 short next; /* next segment in buffer */
112 /* -1 -> available */
113 /* 0..(MSGSEG-1) -> index of next segment */
116 #define MSG_LOCKED 01000 /* Is this msqid_ds locked? */
118 static int nfree_msgmaps; /* # of free map entries */
119 static short free_msgmaps; /* head of linked list of free map entries */
120 static struct msg *free_msghdrs;/* list of free msg headers */
121 static char *msgpool; /* MSGMAX byte long msg buffer pool */
122 static struct msgmap *msgmaps; /* MSGSEG msgmap structures */
123 static struct msg *msghdrs; /* MSGTQL msg headers */
124 static struct msqid_ds *msqids; /* MSGMNI msqid_ds struct's */
132 msginfo.msgmax = msginfo.msgseg * msginfo.msgssz;
133 msgpool = malloc(msginfo.msgmax, M_MSG, M_WAITOK);
135 panic("msgpool is NULL");
136 msgmaps = malloc(sizeof(struct msgmap) * msginfo.msgseg, M_MSG, M_WAITOK);
138 panic("msgmaps is NULL");
139 msghdrs = malloc(sizeof(struct msg) * msginfo.msgtql, M_MSG, M_WAITOK);
141 panic("msghdrs is NULL");
142 msqids = malloc(sizeof(struct msqid_ds) * msginfo.msgmni, M_MSG, M_WAITOK);
144 panic("msqids is NULL");
147 * msginfo.msgssz should be a power of two for efficiency reasons.
148 * It is also pretty silly if msginfo.msgssz is less than 8
149 * or greater than about 256 so ...
153 while (i < 1024 && i != msginfo.msgssz)
155 if (i != msginfo.msgssz) {
156 printf("msginfo.msgssz=%d (0x%x)\n", msginfo.msgssz,
158 panic("msginfo.msgssz not a small power of 2");
161 if (msginfo.msgseg > 32767) {
162 printf("msginfo.msgseg=%d\n", msginfo.msgseg);
163 panic("msginfo.msgseg > 32767");
167 panic("msgmaps is NULL");
169 for (i = 0; i < msginfo.msgseg; i++) {
171 msgmaps[i-1].next = i;
172 msgmaps[i].next = -1; /* implies entry is available */
175 nfree_msgmaps = msginfo.msgseg;
178 panic("msghdrs is NULL");
180 for (i = 0; i < msginfo.msgtql; i++) {
181 msghdrs[i].msg_type = 0;
183 msghdrs[i-1].msg_next = &msghdrs[i];
184 msghdrs[i].msg_next = NULL;
186 free_msghdrs = &msghdrs[0];
189 panic("msqids is NULL");
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;
197 SYSINIT(sysv_msg, SI_SUB_SYSV_MSG, SI_ORDER_FIRST, msginit, NULL)
200 * Entry point for all MSG calls
202 * msgsys_args(u_int which, int a2, ...) (VARARGS)
205 msgsys(struct msgsys_args *uap)
207 struct proc *p = curproc;
209 if (!jail_sysvipc_allowed && p->p_ucred->cr_prison != NULL)
212 if (uap->which >= sizeof(msgcalls)/sizeof(msgcalls[0]))
214 return ((*msgcalls[uap->which])(&uap->a2));
218 msg_freehdr(struct msg *msghdr)
220 while (msghdr->msg_ts > 0) {
222 if (msghdr->msg_spot < 0 || msghdr->msg_spot >= msginfo.msgseg)
223 panic("msghdr->msg_spot out of range");
224 next = msgmaps[msghdr->msg_spot].next;
225 msgmaps[msghdr->msg_spot].next = free_msgmaps;
226 free_msgmaps = msghdr->msg_spot;
228 msghdr->msg_spot = next;
229 if (msghdr->msg_ts >= msginfo.msgssz)
230 msghdr->msg_ts -= msginfo.msgssz;
234 if (msghdr->msg_spot != -1)
235 panic("msghdr->msg_spot != -1");
236 msghdr->msg_next = free_msghdrs;
237 free_msghdrs = msghdr;
240 #ifndef _SYS_SYSPROTO_H_
244 struct msqid_ds *buf;
249 msgctl(struct msgctl_args *uap)
251 struct proc *p = curproc;
252 int msqid = uap->msqid;
254 struct msqid_ds *user_msqptr = uap->buf;
256 struct msqid_ds msqbuf;
257 register struct msqid_ds *msqptr;
260 printf("call to msgctl(%d, %d, 0x%x)\n", msqid, cmd, user_msqptr);
263 if (!jail_sysvipc_allowed && p->p_ucred->cr_prison != NULL)
266 msqid = IPCID_TO_IX(msqid);
268 if (msqid < 0 || msqid >= msginfo.msgmni) {
270 printf("msqid (%d) out of range (0<=msqid<%d)\n", msqid,
276 msqptr = &msqids[msqid];
278 if (msqptr->msg_qbytes == 0) {
280 printf("no such msqid\n");
284 if (msqptr->msg_perm.seq != IPCID_TO_SEQ(uap->msqid)) {
286 printf("wrong sequence number\n");
299 if ((eval = ipcperm(p, &msqptr->msg_perm, IPC_M)))
301 /* Free the message headers */
302 msghdr = msqptr->msg_first;
303 while (msghdr != NULL) {
304 struct msg *msghdr_tmp;
306 /* Free the segments of each message */
307 msqptr->msg_cbytes -= msghdr->msg_ts;
310 msghdr = msghdr->msg_next;
311 msg_freehdr(msghdr_tmp);
314 if (msqptr->msg_cbytes != 0)
315 panic("msg_cbytes is screwed up");
316 if (msqptr->msg_qnum != 0)
317 panic("msg_qnum is screwed up");
319 msqptr->msg_qbytes = 0; /* Mark it as free */
321 wakeup((caddr_t)msqptr);
327 if ((eval = ipcperm(p, &msqptr->msg_perm, IPC_M)))
329 if ((eval = copyin(user_msqptr, &msqbuf, sizeof(msqbuf))) != 0)
331 if (msqbuf.msg_qbytes > msqptr->msg_qbytes) {
336 if (msqbuf.msg_qbytes > msginfo.msgmnb) {
338 printf("can't increase msg_qbytes beyond %d (truncating)\n",
341 msqbuf.msg_qbytes = msginfo.msgmnb; /* silently restrict qbytes to system limit */
343 if (msqbuf.msg_qbytes == 0) {
345 printf("can't reduce msg_qbytes to 0\n");
347 return(EINVAL); /* non-standard errno! */
349 msqptr->msg_perm.uid = msqbuf.msg_perm.uid; /* change the owner */
350 msqptr->msg_perm.gid = msqbuf.msg_perm.gid; /* change the owner */
351 msqptr->msg_perm.mode = (msqptr->msg_perm.mode & ~0777) |
352 (msqbuf.msg_perm.mode & 0777);
353 msqptr->msg_qbytes = msqbuf.msg_qbytes;
354 msqptr->msg_ctime = time_second;
358 if ((eval = ipcperm(p, &msqptr->msg_perm, IPC_R))) {
360 printf("requester doesn't have read access\n");
364 eval = copyout((caddr_t)msqptr, user_msqptr,
365 sizeof(struct msqid_ds));
370 printf("invalid command %d\n", cmd);
376 p->p_retval[0] = rval;
380 #ifndef _SYS_SYSPROTO_H_
388 msgget(struct msgget_args *uap)
390 struct proc *p = curproc;
393 int msgflg = uap->msgflg;
394 struct ucred *cred = p->p_ucred;
395 register struct msqid_ds *msqptr = NULL;
398 printf("msgget(0x%x, 0%o)\n", key, msgflg);
401 if (!jail_sysvipc_allowed && p->p_ucred->cr_prison != NULL)
404 if (key != IPC_PRIVATE) {
405 for (msqid = 0; msqid < msginfo.msgmni; msqid++) {
406 msqptr = &msqids[msqid];
407 if (msqptr->msg_qbytes != 0 &&
408 msqptr->msg_perm.key == key)
411 if (msqid < msginfo.msgmni) {
413 printf("found public key\n");
415 if ((msgflg & IPC_CREAT) && (msgflg & IPC_EXCL)) {
417 printf("not exclusive\n");
421 if ((eval = ipcperm(p, &msqptr->msg_perm, msgflg & 0700 ))) {
423 printf("requester doesn't have 0%o access\n",
433 printf("need to allocate the msqid_ds\n");
435 if (key == IPC_PRIVATE || (msgflg & IPC_CREAT)) {
436 for (msqid = 0; msqid < msginfo.msgmni; msqid++) {
438 * Look for an unallocated and unlocked msqid_ds.
439 * msqid_ds's can be locked by msgsnd or msgrcv while
440 * they are copying the message in/out. We can't
441 * re-use the entry until they release it.
443 msqptr = &msqids[msqid];
444 if (msqptr->msg_qbytes == 0 &&
445 (msqptr->msg_perm.mode & MSG_LOCKED) == 0)
448 if (msqid == msginfo.msgmni) {
450 printf("no more msqid_ds's available\n");
455 printf("msqid %d is available\n", msqid);
457 msqptr->msg_perm.key = key;
458 msqptr->msg_perm.cuid = cred->cr_uid;
459 msqptr->msg_perm.uid = cred->cr_uid;
460 msqptr->msg_perm.cgid = cred->cr_gid;
461 msqptr->msg_perm.gid = cred->cr_gid;
462 msqptr->msg_perm.mode = (msgflg & 0777);
463 /* Make sure that the returned msqid is unique */
464 msqptr->msg_perm.seq = (msqptr->msg_perm.seq + 1) & 0x7fff;
465 msqptr->msg_first = NULL;
466 msqptr->msg_last = NULL;
467 msqptr->msg_cbytes = 0;
468 msqptr->msg_qnum = 0;
469 msqptr->msg_qbytes = msginfo.msgmnb;
470 msqptr->msg_lspid = 0;
471 msqptr->msg_lrpid = 0;
472 msqptr->msg_stime = 0;
473 msqptr->msg_rtime = 0;
474 msqptr->msg_ctime = time_second;
477 printf("didn't find it and wasn't asked to create it\n");
483 /* Construct the unique msqid */
484 p->p_retval[0] = IXSEQ_TO_IPCID(msqid, msqptr->msg_perm);
488 #ifndef _SYS_SYSPROTO_H_
498 msgsnd(struct msgsnd_args *uap)
500 struct proc *p = curproc;
501 int msqid = uap->msqid;
502 void *user_msgp = uap->msgp;
503 size_t msgsz = uap->msgsz;
504 int msgflg = uap->msgflg;
505 int segs_needed, eval;
506 register struct msqid_ds *msqptr;
507 register struct msg *msghdr;
511 printf("call to msgsnd(%d, 0x%x, %d, %d)\n", msqid, user_msgp, msgsz,
515 if (!jail_sysvipc_allowed && p->p_ucred->cr_prison != NULL)
518 msqid = IPCID_TO_IX(msqid);
520 if (msqid < 0 || msqid >= msginfo.msgmni) {
522 printf("msqid (%d) out of range (0<=msqid<%d)\n", msqid,
528 msqptr = &msqids[msqid];
529 if (msqptr->msg_qbytes == 0) {
531 printf("no such message queue id\n");
535 if (msqptr->msg_perm.seq != IPCID_TO_SEQ(uap->msqid)) {
537 printf("wrong sequence number\n");
542 if ((eval = ipcperm(p, &msqptr->msg_perm, IPC_W))) {
544 printf("requester doesn't have write access\n");
549 segs_needed = (msgsz + msginfo.msgssz - 1) / msginfo.msgssz;
551 printf("msgsz=%d, msgssz=%d, segs_needed=%d\n", msgsz, msginfo.msgssz,
555 int need_more_resources = 0;
559 * (inside this loop in case msg_qbytes changes while we sleep)
562 if (msgsz > msqptr->msg_qbytes) {
564 printf("msgsz > msqptr->msg_qbytes\n");
569 if (msqptr->msg_perm.mode & MSG_LOCKED) {
571 printf("msqid is locked\n");
573 need_more_resources = 1;
575 if (msgsz + msqptr->msg_cbytes > msqptr->msg_qbytes) {
577 printf("msgsz + msg_cbytes > msg_qbytes\n");
579 need_more_resources = 1;
581 if (segs_needed > nfree_msgmaps) {
583 printf("segs_needed > nfree_msgmaps\n");
585 need_more_resources = 1;
587 if (free_msghdrs == NULL) {
589 printf("no more msghdrs\n");
591 need_more_resources = 1;
594 if (need_more_resources) {
597 if ((msgflg & IPC_NOWAIT) != 0) {
599 printf("need more resources but caller doesn't want to wait\n");
604 if ((msqptr->msg_perm.mode & MSG_LOCKED) != 0) {
606 printf("we don't own the msqid_ds\n");
610 /* Force later arrivals to wait for our
613 printf("we own the msqid_ds\n");
615 msqptr->msg_perm.mode |= MSG_LOCKED;
619 printf("goodnight\n");
621 eval = tsleep((caddr_t)msqptr, (PZERO - 4) | PCATCH,
624 printf("good morning, eval=%d\n", eval);
627 msqptr->msg_perm.mode &= ~MSG_LOCKED;
630 printf("msgsnd: interrupted system call\n");
636 * Make sure that the msq queue still exists
639 if (msqptr->msg_qbytes == 0) {
641 printf("msqid deleted\n");
648 printf("got all the resources that we need\n");
655 * We have the resources that we need.
659 if (msqptr->msg_perm.mode & MSG_LOCKED)
660 panic("msg_perm.mode & MSG_LOCKED");
661 if (segs_needed > nfree_msgmaps)
662 panic("segs_needed > nfree_msgmaps");
663 if (msgsz + msqptr->msg_cbytes > msqptr->msg_qbytes)
664 panic("msgsz + msg_cbytes > msg_qbytes");
665 if (free_msghdrs == NULL)
666 panic("no more msghdrs");
669 * Re-lock the msqid_ds in case we page-fault when copying in the
673 if ((msqptr->msg_perm.mode & MSG_LOCKED) != 0)
674 panic("msqid_ds is already locked");
675 msqptr->msg_perm.mode |= MSG_LOCKED;
678 * Allocate a message header
681 msghdr = free_msghdrs;
682 free_msghdrs = msghdr->msg_next;
683 msghdr->msg_spot = -1;
684 msghdr->msg_ts = msgsz;
687 * Allocate space for the message
690 while (segs_needed > 0) {
691 if (nfree_msgmaps <= 0)
692 panic("not enough msgmaps");
693 if (free_msgmaps == -1)
694 panic("nil free_msgmaps");
697 panic("next too low #1");
698 if (next >= msginfo.msgseg)
699 panic("next out of range #1");
701 printf("allocating segment %d to message\n", next);
703 free_msgmaps = msgmaps[next].next;
705 msgmaps[next].next = msghdr->msg_spot;
706 msghdr->msg_spot = next;
711 * Copy in the message type
714 if ((eval = copyin(user_msgp, &msghdr->msg_type,
715 sizeof(msghdr->msg_type))) != 0) {
717 printf("error %d copying the message type\n", eval);
720 msqptr->msg_perm.mode &= ~MSG_LOCKED;
721 wakeup((caddr_t)msqptr);
724 user_msgp = (char *)user_msgp + sizeof(msghdr->msg_type);
727 * Validate the message type
730 if (msghdr->msg_type < 1) {
732 msqptr->msg_perm.mode &= ~MSG_LOCKED;
733 wakeup((caddr_t)msqptr);
735 printf("mtype (%d) < 1\n", msghdr->msg_type);
741 * Copy in the message body
744 next = msghdr->msg_spot;
747 if (msgsz > msginfo.msgssz)
748 tlen = msginfo.msgssz;
752 panic("next too low #2");
753 if (next >= msginfo.msgseg)
754 panic("next out of range #2");
755 if ((eval = copyin(user_msgp, &msgpool[next * msginfo.msgssz],
758 printf("error %d copying in message segment\n", eval);
761 msqptr->msg_perm.mode &= ~MSG_LOCKED;
762 wakeup((caddr_t)msqptr);
766 user_msgp = (char *)user_msgp + tlen;
767 next = msgmaps[next].next;
770 panic("didn't use all the msg segments");
773 * We've got the message. Unlock the msqid_ds.
776 msqptr->msg_perm.mode &= ~MSG_LOCKED;
779 * Make sure that the msqid_ds is still allocated.
782 if (msqptr->msg_qbytes == 0) {
784 wakeup((caddr_t)msqptr);
789 * Put the message into the queue
792 if (msqptr->msg_first == NULL) {
793 msqptr->msg_first = msghdr;
794 msqptr->msg_last = msghdr;
796 msqptr->msg_last->msg_next = msghdr;
797 msqptr->msg_last = msghdr;
799 msqptr->msg_last->msg_next = NULL;
801 msqptr->msg_cbytes += msghdr->msg_ts;
803 msqptr->msg_lspid = p->p_pid;
804 msqptr->msg_stime = time_second;
806 wakeup((caddr_t)msqptr);
811 #ifndef _SYS_SYSPROTO_H_
822 msgrcv(struct msgrcv_args *uap)
824 struct proc *p = curproc;
825 int msqid = uap->msqid;
826 void *user_msgp = uap->msgp;
827 size_t msgsz = uap->msgsz;
828 long msgtyp = uap->msgtyp;
829 int msgflg = uap->msgflg;
831 register struct msqid_ds *msqptr;
832 register struct msg *msghdr;
837 printf("call to msgrcv(%d, 0x%x, %d, %ld, %d)\n", msqid, user_msgp,
838 msgsz, msgtyp, msgflg);
841 if (!jail_sysvipc_allowed && p->p_ucred->cr_prison != NULL)
844 msqid = IPCID_TO_IX(msqid);
846 if (msqid < 0 || msqid >= msginfo.msgmni) {
848 printf("msqid (%d) out of range (0<=msqid<%d)\n", msqid,
854 msqptr = &msqids[msqid];
855 if (msqptr->msg_qbytes == 0) {
857 printf("no such message queue id\n");
861 if (msqptr->msg_perm.seq != IPCID_TO_SEQ(uap->msqid)) {
863 printf("wrong sequence number\n");
868 if ((eval = ipcperm(p, &msqptr->msg_perm, IPC_R))) {
870 printf("requester doesn't have read access\n");
876 while (msghdr == NULL) {
878 msghdr = msqptr->msg_first;
879 if (msghdr != NULL) {
880 if (msgsz < msghdr->msg_ts &&
881 (msgflg & MSG_NOERROR) == 0) {
883 printf("first message on the queue is too big (want %d, got %d)\n",
884 msgsz, msghdr->msg_ts);
888 if (msqptr->msg_first == msqptr->msg_last) {
889 msqptr->msg_first = NULL;
890 msqptr->msg_last = NULL;
892 msqptr->msg_first = msghdr->msg_next;
893 if (msqptr->msg_first == NULL)
894 panic("msg_first/last screwed up #1");
898 struct msg *previous;
902 prev = &(msqptr->msg_first);
903 while ((msghdr = *prev) != NULL) {
905 * Is this message's type an exact match or is
906 * this message's type less than or equal to
907 * the absolute value of a negative msgtyp?
908 * Note that the second half of this test can
909 * NEVER be true if msgtyp is positive since
910 * msg_type is always positive!
913 if (msgtyp == msghdr->msg_type ||
914 msghdr->msg_type <= -msgtyp) {
916 printf("found message type %d, requested %d\n",
917 msghdr->msg_type, msgtyp);
919 if (msgsz < msghdr->msg_ts &&
920 (msgflg & MSG_NOERROR) == 0) {
922 printf("requested message on the queue is too big (want %d, got %d)\n",
923 msgsz, msghdr->msg_ts);
927 *prev = msghdr->msg_next;
928 if (msghdr == msqptr->msg_last) {
929 if (previous == NULL) {
932 panic("msg_first/last screwed up #2");
940 panic("msg_first/last screwed up #3");
948 prev = &(msghdr->msg_next);
953 * We've either extracted the msghdr for the appropriate
954 * message or there isn't one.
955 * If there is one then bail out of this loop.
962 * Hmph! No message found. Does the user want to wait?
965 if ((msgflg & IPC_NOWAIT) != 0) {
967 printf("no appropriate message found (msgtyp=%d)\n",
970 /* The SVID says to return ENOMSG. */
974 /* Unfortunately, BSD doesn't define that code yet! */
980 * Wait for something to happen
984 printf("msgrcv: goodnight\n");
986 eval = tsleep((caddr_t)msqptr, (PZERO - 4) | PCATCH, "msgwait",
989 printf("msgrcv: good morning (eval=%d)\n", eval);
994 printf("msgsnd: interrupted system call\n");
1000 * Make sure that the msq queue still exists
1003 if (msqptr->msg_qbytes == 0 ||
1004 msqptr->msg_perm.seq != IPCID_TO_SEQ(uap->msqid)) {
1006 printf("msqid deleted\n");
1013 * Return the message to the user.
1015 * First, do the bookkeeping (before we risk being interrupted).
1018 msqptr->msg_cbytes -= msghdr->msg_ts;
1020 msqptr->msg_lrpid = p->p_pid;
1021 msqptr->msg_rtime = time_second;
1024 * Make msgsz the actual amount that we'll be returning.
1025 * Note that this effectively truncates the message if it is too long
1026 * (since msgsz is never increased).
1030 printf("found a message, msgsz=%d, msg_ts=%d\n", msgsz,
1033 if (msgsz > msghdr->msg_ts)
1034 msgsz = msghdr->msg_ts;
1037 * Return the type to the user.
1040 eval = copyout((caddr_t)&(msghdr->msg_type), user_msgp,
1041 sizeof(msghdr->msg_type));
1044 printf("error (%d) copying out message type\n", eval);
1046 msg_freehdr(msghdr);
1047 wakeup((caddr_t)msqptr);
1050 user_msgp = (char *)user_msgp + sizeof(msghdr->msg_type);
1053 * Return the segments to the user
1056 next = msghdr->msg_spot;
1057 for (len = 0; len < msgsz; len += msginfo.msgssz) {
1060 if (msgsz - len > msginfo.msgssz)
1061 tlen = msginfo.msgssz;
1065 panic("next too low #3");
1066 if (next >= msginfo.msgseg)
1067 panic("next out of range #3");
1068 eval = copyout((caddr_t)&msgpool[next * msginfo.msgssz],
1072 printf("error (%d) copying out message segment\n",
1075 msg_freehdr(msghdr);
1076 wakeup((caddr_t)msqptr);
1079 user_msgp = (char *)user_msgp + tlen;
1080 next = msgmaps[next].next;
1084 * Done, return the actual number of bytes copied out.
1087 msg_freehdr(msghdr);
1088 wakeup((caddr_t)msqptr);
1089 p->p_retval[0] = msgsz;
1094 sysctl_msqids(SYSCTL_HANDLER_ARGS)
1097 return (SYSCTL_OUT(req, msqids,
1098 sizeof(struct msqid_ds) * msginfo.msgmni));
1101 TUNABLE_INT("kern.ipc.msgseg", &msginfo.msgseg);
1102 TUNABLE_INT("kern.ipc.msgssz", &msginfo.msgssz);
1103 TUNABLE_INT("kern.ipc.msgmni", &msginfo.msgmni);
1105 SYSCTL_DECL(_kern_ipc);
1106 SYSCTL_INT(_kern_ipc, OID_AUTO, msgmax, CTLFLAG_RD, &msginfo.msgmax, 0, "");
1107 SYSCTL_INT(_kern_ipc, OID_AUTO, msgmni, CTLFLAG_RD, &msginfo.msgmni, 0, "");
1108 SYSCTL_INT(_kern_ipc, OID_AUTO, msgmnb, CTLFLAG_RD, &msginfo.msgmnb, 0, "");
1109 SYSCTL_INT(_kern_ipc, OID_AUTO, msgtql, CTLFLAG_RD, &msginfo.msgtql, 0, "");
1110 SYSCTL_INT(_kern_ipc, OID_AUTO, msgssz, CTLFLAG_RD, &msginfo.msgssz, 0, "");
1111 SYSCTL_INT(_kern_ipc, OID_AUTO, msgseg, CTLFLAG_RD, &msginfo.msgseg, 0, "");
1112 SYSCTL_PROC(_kern_ipc, OID_AUTO, msqids, CTLFLAG_RD,
1113 NULL, 0, sysctl_msqids, "", "Message queue IDs");