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.2 2003/06/17 04:28: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
205 /* XXX actually varargs. */
206 struct msgsys_args /* {
216 if (!jail_sysvipc_allowed && p->p_prison != NULL)
219 if (uap->which >= sizeof(msgcalls)/sizeof(msgcalls[0]))
221 return ((*msgcalls[uap->which])(p, &uap->a2));
228 while (msghdr->msg_ts > 0) {
230 if (msghdr->msg_spot < 0 || msghdr->msg_spot >= msginfo.msgseg)
231 panic("msghdr->msg_spot out of range");
232 next = msgmaps[msghdr->msg_spot].next;
233 msgmaps[msghdr->msg_spot].next = free_msgmaps;
234 free_msgmaps = msghdr->msg_spot;
236 msghdr->msg_spot = next;
237 if (msghdr->msg_ts >= msginfo.msgssz)
238 msghdr->msg_ts -= msginfo.msgssz;
242 if (msghdr->msg_spot != -1)
243 panic("msghdr->msg_spot != -1");
244 msghdr->msg_next = free_msghdrs;
245 free_msghdrs = msghdr;
248 #ifndef _SYS_SYSPROTO_H_
252 struct msqid_ds *buf;
259 register struct msgctl_args *uap;
261 int msqid = uap->msqid;
263 struct msqid_ds *user_msqptr = uap->buf;
265 struct msqid_ds msqbuf;
266 register struct msqid_ds *msqptr;
269 printf("call to msgctl(%d, %d, 0x%x)\n", msqid, cmd, user_msqptr);
272 if (!jail_sysvipc_allowed && p->p_prison != NULL)
275 msqid = IPCID_TO_IX(msqid);
277 if (msqid < 0 || msqid >= msginfo.msgmni) {
279 printf("msqid (%d) out of range (0<=msqid<%d)\n", msqid,
285 msqptr = &msqids[msqid];
287 if (msqptr->msg_qbytes == 0) {
289 printf("no such msqid\n");
293 if (msqptr->msg_perm.seq != IPCID_TO_SEQ(uap->msqid)) {
295 printf("wrong sequence number\n");
308 if ((eval = ipcperm(p, &msqptr->msg_perm, IPC_M)))
310 /* Free the message headers */
311 msghdr = msqptr->msg_first;
312 while (msghdr != NULL) {
313 struct msg *msghdr_tmp;
315 /* Free the segments of each message */
316 msqptr->msg_cbytes -= msghdr->msg_ts;
319 msghdr = msghdr->msg_next;
320 msg_freehdr(msghdr_tmp);
323 if (msqptr->msg_cbytes != 0)
324 panic("msg_cbytes is screwed up");
325 if (msqptr->msg_qnum != 0)
326 panic("msg_qnum is screwed up");
328 msqptr->msg_qbytes = 0; /* Mark it as free */
330 wakeup((caddr_t)msqptr);
336 if ((eval = ipcperm(p, &msqptr->msg_perm, IPC_M)))
338 if ((eval = copyin(user_msqptr, &msqbuf, sizeof(msqbuf))) != 0)
340 if (msqbuf.msg_qbytes > msqptr->msg_qbytes) {
345 if (msqbuf.msg_qbytes > msginfo.msgmnb) {
347 printf("can't increase msg_qbytes beyond %d (truncating)\n",
350 msqbuf.msg_qbytes = msginfo.msgmnb; /* silently restrict qbytes to system limit */
352 if (msqbuf.msg_qbytes == 0) {
354 printf("can't reduce msg_qbytes to 0\n");
356 return(EINVAL); /* non-standard errno! */
358 msqptr->msg_perm.uid = msqbuf.msg_perm.uid; /* change the owner */
359 msqptr->msg_perm.gid = msqbuf.msg_perm.gid; /* change the owner */
360 msqptr->msg_perm.mode = (msqptr->msg_perm.mode & ~0777) |
361 (msqbuf.msg_perm.mode & 0777);
362 msqptr->msg_qbytes = msqbuf.msg_qbytes;
363 msqptr->msg_ctime = time_second;
367 if ((eval = ipcperm(p, &msqptr->msg_perm, IPC_R))) {
369 printf("requester doesn't have read access\n");
373 eval = copyout((caddr_t)msqptr, user_msqptr,
374 sizeof(struct msqid_ds));
379 printf("invalid command %d\n", cmd);
385 p->p_retval[0] = rval;
389 #ifndef _SYS_SYSPROTO_H_
399 register struct msgget_args *uap;
403 int msgflg = uap->msgflg;
404 struct ucred *cred = p->p_ucred;
405 register struct msqid_ds *msqptr = NULL;
408 printf("msgget(0x%x, 0%o)\n", key, msgflg);
411 if (!jail_sysvipc_allowed && p->p_prison != NULL)
414 if (key != IPC_PRIVATE) {
415 for (msqid = 0; msqid < msginfo.msgmni; msqid++) {
416 msqptr = &msqids[msqid];
417 if (msqptr->msg_qbytes != 0 &&
418 msqptr->msg_perm.key == key)
421 if (msqid < msginfo.msgmni) {
423 printf("found public key\n");
425 if ((msgflg & IPC_CREAT) && (msgflg & IPC_EXCL)) {
427 printf("not exclusive\n");
431 if ((eval = ipcperm(p, &msqptr->msg_perm, msgflg & 0700 ))) {
433 printf("requester doesn't have 0%o access\n",
443 printf("need to allocate the msqid_ds\n");
445 if (key == IPC_PRIVATE || (msgflg & IPC_CREAT)) {
446 for (msqid = 0; msqid < msginfo.msgmni; msqid++) {
448 * Look for an unallocated and unlocked msqid_ds.
449 * msqid_ds's can be locked by msgsnd or msgrcv while
450 * they are copying the message in/out. We can't
451 * re-use the entry until they release it.
453 msqptr = &msqids[msqid];
454 if (msqptr->msg_qbytes == 0 &&
455 (msqptr->msg_perm.mode & MSG_LOCKED) == 0)
458 if (msqid == msginfo.msgmni) {
460 printf("no more msqid_ds's available\n");
465 printf("msqid %d is available\n", msqid);
467 msqptr->msg_perm.key = key;
468 msqptr->msg_perm.cuid = cred->cr_uid;
469 msqptr->msg_perm.uid = cred->cr_uid;
470 msqptr->msg_perm.cgid = cred->cr_gid;
471 msqptr->msg_perm.gid = cred->cr_gid;
472 msqptr->msg_perm.mode = (msgflg & 0777);
473 /* Make sure that the returned msqid is unique */
474 msqptr->msg_perm.seq = (msqptr->msg_perm.seq + 1) & 0x7fff;
475 msqptr->msg_first = NULL;
476 msqptr->msg_last = NULL;
477 msqptr->msg_cbytes = 0;
478 msqptr->msg_qnum = 0;
479 msqptr->msg_qbytes = msginfo.msgmnb;
480 msqptr->msg_lspid = 0;
481 msqptr->msg_lrpid = 0;
482 msqptr->msg_stime = 0;
483 msqptr->msg_rtime = 0;
484 msqptr->msg_ctime = time_second;
487 printf("didn't find it and wasn't asked to create it\n");
493 /* Construct the unique msqid */
494 p->p_retval[0] = IXSEQ_TO_IPCID(msqid, msqptr->msg_perm);
498 #ifndef _SYS_SYSPROTO_H_
510 register struct msgsnd_args *uap;
512 int msqid = uap->msqid;
513 void *user_msgp = uap->msgp;
514 size_t msgsz = uap->msgsz;
515 int msgflg = uap->msgflg;
516 int segs_needed, eval;
517 register struct msqid_ds *msqptr;
518 register struct msg *msghdr;
522 printf("call to msgsnd(%d, 0x%x, %d, %d)\n", msqid, user_msgp, msgsz,
526 if (!jail_sysvipc_allowed && p->p_prison != NULL)
529 msqid = IPCID_TO_IX(msqid);
531 if (msqid < 0 || msqid >= msginfo.msgmni) {
533 printf("msqid (%d) out of range (0<=msqid<%d)\n", msqid,
539 msqptr = &msqids[msqid];
540 if (msqptr->msg_qbytes == 0) {
542 printf("no such message queue id\n");
546 if (msqptr->msg_perm.seq != IPCID_TO_SEQ(uap->msqid)) {
548 printf("wrong sequence number\n");
553 if ((eval = ipcperm(p, &msqptr->msg_perm, IPC_W))) {
555 printf("requester doesn't have write access\n");
560 segs_needed = (msgsz + msginfo.msgssz - 1) / msginfo.msgssz;
562 printf("msgsz=%d, msgssz=%d, segs_needed=%d\n", msgsz, msginfo.msgssz,
566 int need_more_resources = 0;
570 * (inside this loop in case msg_qbytes changes while we sleep)
573 if (msgsz > msqptr->msg_qbytes) {
575 printf("msgsz > msqptr->msg_qbytes\n");
580 if (msqptr->msg_perm.mode & MSG_LOCKED) {
582 printf("msqid is locked\n");
584 need_more_resources = 1;
586 if (msgsz + msqptr->msg_cbytes > msqptr->msg_qbytes) {
588 printf("msgsz + msg_cbytes > msg_qbytes\n");
590 need_more_resources = 1;
592 if (segs_needed > nfree_msgmaps) {
594 printf("segs_needed > nfree_msgmaps\n");
596 need_more_resources = 1;
598 if (free_msghdrs == NULL) {
600 printf("no more msghdrs\n");
602 need_more_resources = 1;
605 if (need_more_resources) {
608 if ((msgflg & IPC_NOWAIT) != 0) {
610 printf("need more resources but caller doesn't want to wait\n");
615 if ((msqptr->msg_perm.mode & MSG_LOCKED) != 0) {
617 printf("we don't own the msqid_ds\n");
621 /* Force later arrivals to wait for our
624 printf("we own the msqid_ds\n");
626 msqptr->msg_perm.mode |= MSG_LOCKED;
630 printf("goodnight\n");
632 eval = tsleep((caddr_t)msqptr, (PZERO - 4) | PCATCH,
635 printf("good morning, eval=%d\n", eval);
638 msqptr->msg_perm.mode &= ~MSG_LOCKED;
641 printf("msgsnd: interrupted system call\n");
647 * Make sure that the msq queue still exists
650 if (msqptr->msg_qbytes == 0) {
652 printf("msqid deleted\n");
659 printf("got all the resources that we need\n");
666 * We have the resources that we need.
670 if (msqptr->msg_perm.mode & MSG_LOCKED)
671 panic("msg_perm.mode & MSG_LOCKED");
672 if (segs_needed > nfree_msgmaps)
673 panic("segs_needed > nfree_msgmaps");
674 if (msgsz + msqptr->msg_cbytes > msqptr->msg_qbytes)
675 panic("msgsz + msg_cbytes > msg_qbytes");
676 if (free_msghdrs == NULL)
677 panic("no more msghdrs");
680 * Re-lock the msqid_ds in case we page-fault when copying in the
684 if ((msqptr->msg_perm.mode & MSG_LOCKED) != 0)
685 panic("msqid_ds is already locked");
686 msqptr->msg_perm.mode |= MSG_LOCKED;
689 * Allocate a message header
692 msghdr = free_msghdrs;
693 free_msghdrs = msghdr->msg_next;
694 msghdr->msg_spot = -1;
695 msghdr->msg_ts = msgsz;
698 * Allocate space for the message
701 while (segs_needed > 0) {
702 if (nfree_msgmaps <= 0)
703 panic("not enough msgmaps");
704 if (free_msgmaps == -1)
705 panic("nil free_msgmaps");
708 panic("next too low #1");
709 if (next >= msginfo.msgseg)
710 panic("next out of range #1");
712 printf("allocating segment %d to message\n", next);
714 free_msgmaps = msgmaps[next].next;
716 msgmaps[next].next = msghdr->msg_spot;
717 msghdr->msg_spot = next;
722 * Copy in the message type
725 if ((eval = copyin(user_msgp, &msghdr->msg_type,
726 sizeof(msghdr->msg_type))) != 0) {
728 printf("error %d copying the message type\n", eval);
731 msqptr->msg_perm.mode &= ~MSG_LOCKED;
732 wakeup((caddr_t)msqptr);
735 user_msgp = (char *)user_msgp + sizeof(msghdr->msg_type);
738 * Validate the message type
741 if (msghdr->msg_type < 1) {
743 msqptr->msg_perm.mode &= ~MSG_LOCKED;
744 wakeup((caddr_t)msqptr);
746 printf("mtype (%d) < 1\n", msghdr->msg_type);
752 * Copy in the message body
755 next = msghdr->msg_spot;
758 if (msgsz > msginfo.msgssz)
759 tlen = msginfo.msgssz;
763 panic("next too low #2");
764 if (next >= msginfo.msgseg)
765 panic("next out of range #2");
766 if ((eval = copyin(user_msgp, &msgpool[next * msginfo.msgssz],
769 printf("error %d copying in message segment\n", eval);
772 msqptr->msg_perm.mode &= ~MSG_LOCKED;
773 wakeup((caddr_t)msqptr);
777 user_msgp = (char *)user_msgp + tlen;
778 next = msgmaps[next].next;
781 panic("didn't use all the msg segments");
784 * We've got the message. Unlock the msqid_ds.
787 msqptr->msg_perm.mode &= ~MSG_LOCKED;
790 * Make sure that the msqid_ds is still allocated.
793 if (msqptr->msg_qbytes == 0) {
795 wakeup((caddr_t)msqptr);
800 * Put the message into the queue
803 if (msqptr->msg_first == NULL) {
804 msqptr->msg_first = msghdr;
805 msqptr->msg_last = msghdr;
807 msqptr->msg_last->msg_next = msghdr;
808 msqptr->msg_last = msghdr;
810 msqptr->msg_last->msg_next = NULL;
812 msqptr->msg_cbytes += msghdr->msg_ts;
814 msqptr->msg_lspid = p->p_pid;
815 msqptr->msg_stime = time_second;
817 wakeup((caddr_t)msqptr);
822 #ifndef _SYS_SYSPROTO_H_
835 register struct msgrcv_args *uap;
837 int msqid = uap->msqid;
838 void *user_msgp = uap->msgp;
839 size_t msgsz = uap->msgsz;
840 long msgtyp = uap->msgtyp;
841 int msgflg = uap->msgflg;
843 register struct msqid_ds *msqptr;
844 register struct msg *msghdr;
849 printf("call to msgrcv(%d, 0x%x, %d, %ld, %d)\n", msqid, user_msgp,
850 msgsz, msgtyp, msgflg);
853 if (!jail_sysvipc_allowed && p->p_prison != NULL)
856 msqid = IPCID_TO_IX(msqid);
858 if (msqid < 0 || msqid >= msginfo.msgmni) {
860 printf("msqid (%d) out of range (0<=msqid<%d)\n", msqid,
866 msqptr = &msqids[msqid];
867 if (msqptr->msg_qbytes == 0) {
869 printf("no such message queue id\n");
873 if (msqptr->msg_perm.seq != IPCID_TO_SEQ(uap->msqid)) {
875 printf("wrong sequence number\n");
880 if ((eval = ipcperm(p, &msqptr->msg_perm, IPC_R))) {
882 printf("requester doesn't have read access\n");
888 while (msghdr == NULL) {
890 msghdr = msqptr->msg_first;
891 if (msghdr != NULL) {
892 if (msgsz < msghdr->msg_ts &&
893 (msgflg & MSG_NOERROR) == 0) {
895 printf("first message on the queue is too big (want %d, got %d)\n",
896 msgsz, msghdr->msg_ts);
900 if (msqptr->msg_first == msqptr->msg_last) {
901 msqptr->msg_first = NULL;
902 msqptr->msg_last = NULL;
904 msqptr->msg_first = msghdr->msg_next;
905 if (msqptr->msg_first == NULL)
906 panic("msg_first/last screwed up #1");
910 struct msg *previous;
914 prev = &(msqptr->msg_first);
915 while ((msghdr = *prev) != NULL) {
917 * Is this message's type an exact match or is
918 * this message's type less than or equal to
919 * the absolute value of a negative msgtyp?
920 * Note that the second half of this test can
921 * NEVER be true if msgtyp is positive since
922 * msg_type is always positive!
925 if (msgtyp == msghdr->msg_type ||
926 msghdr->msg_type <= -msgtyp) {
928 printf("found message type %d, requested %d\n",
929 msghdr->msg_type, msgtyp);
931 if (msgsz < msghdr->msg_ts &&
932 (msgflg & MSG_NOERROR) == 0) {
934 printf("requested message on the queue is too big (want %d, got %d)\n",
935 msgsz, msghdr->msg_ts);
939 *prev = msghdr->msg_next;
940 if (msghdr == msqptr->msg_last) {
941 if (previous == NULL) {
944 panic("msg_first/last screwed up #2");
952 panic("msg_first/last screwed up #3");
960 prev = &(msghdr->msg_next);
965 * We've either extracted the msghdr for the appropriate
966 * message or there isn't one.
967 * If there is one then bail out of this loop.
974 * Hmph! No message found. Does the user want to wait?
977 if ((msgflg & IPC_NOWAIT) != 0) {
979 printf("no appropriate message found (msgtyp=%d)\n",
982 /* The SVID says to return ENOMSG. */
986 /* Unfortunately, BSD doesn't define that code yet! */
992 * Wait for something to happen
996 printf("msgrcv: goodnight\n");
998 eval = tsleep((caddr_t)msqptr, (PZERO - 4) | PCATCH, "msgwait",
1001 printf("msgrcv: good morning (eval=%d)\n", eval);
1006 printf("msgsnd: interrupted system call\n");
1012 * Make sure that the msq queue still exists
1015 if (msqptr->msg_qbytes == 0 ||
1016 msqptr->msg_perm.seq != IPCID_TO_SEQ(uap->msqid)) {
1018 printf("msqid deleted\n");
1025 * Return the message to the user.
1027 * First, do the bookkeeping (before we risk being interrupted).
1030 msqptr->msg_cbytes -= msghdr->msg_ts;
1032 msqptr->msg_lrpid = p->p_pid;
1033 msqptr->msg_rtime = time_second;
1036 * Make msgsz the actual amount that we'll be returning.
1037 * Note that this effectively truncates the message if it is too long
1038 * (since msgsz is never increased).
1042 printf("found a message, msgsz=%d, msg_ts=%d\n", msgsz,
1045 if (msgsz > msghdr->msg_ts)
1046 msgsz = msghdr->msg_ts;
1049 * Return the type to the user.
1052 eval = copyout((caddr_t)&(msghdr->msg_type), user_msgp,
1053 sizeof(msghdr->msg_type));
1056 printf("error (%d) copying out message type\n", eval);
1058 msg_freehdr(msghdr);
1059 wakeup((caddr_t)msqptr);
1062 user_msgp = (char *)user_msgp + sizeof(msghdr->msg_type);
1065 * Return the segments to the user
1068 next = msghdr->msg_spot;
1069 for (len = 0; len < msgsz; len += msginfo.msgssz) {
1072 if (msgsz - len > msginfo.msgssz)
1073 tlen = msginfo.msgssz;
1077 panic("next too low #3");
1078 if (next >= msginfo.msgseg)
1079 panic("next out of range #3");
1080 eval = copyout((caddr_t)&msgpool[next * msginfo.msgssz],
1084 printf("error (%d) copying out message segment\n",
1087 msg_freehdr(msghdr);
1088 wakeup((caddr_t)msqptr);
1091 user_msgp = (char *)user_msgp + tlen;
1092 next = msgmaps[next].next;
1096 * Done, return the actual number of bytes copied out.
1099 msg_freehdr(msghdr);
1100 wakeup((caddr_t)msqptr);
1101 p->p_retval[0] = msgsz;
1106 sysctl_msqids(SYSCTL_HANDLER_ARGS)
1109 return (SYSCTL_OUT(req, msqids,
1110 sizeof(struct msqid_ds) * msginfo.msgmni));
1113 TUNABLE_INT("kern.ipc.msgseg", &msginfo.msgseg);
1114 TUNABLE_INT("kern.ipc.msgssz", &msginfo.msgssz);
1115 TUNABLE_INT("kern.ipc.msgmni", &msginfo.msgmni);
1117 SYSCTL_DECL(_kern_ipc);
1118 SYSCTL_INT(_kern_ipc, OID_AUTO, msgmax, CTLFLAG_RD, &msginfo.msgmax, 0, "");
1119 SYSCTL_INT(_kern_ipc, OID_AUTO, msgmni, CTLFLAG_RD, &msginfo.msgmni, 0, "");
1120 SYSCTL_INT(_kern_ipc, OID_AUTO, msgmnb, CTLFLAG_RD, &msginfo.msgmnb, 0, "");
1121 SYSCTL_INT(_kern_ipc, OID_AUTO, msgtql, CTLFLAG_RD, &msginfo.msgtql, 0, "");
1122 SYSCTL_INT(_kern_ipc, OID_AUTO, msgssz, CTLFLAG_RD, &msginfo.msgssz, 0, "");
1123 SYSCTL_INT(_kern_ipc, OID_AUTO, msgseg, CTLFLAG_RD, &msginfo.msgseg, 0, "");
1124 SYSCTL_PROC(_kern_ipc, OID_AUTO, msqids, CTLFLAG_RD,
1125 NULL, 0, sysctl_msqids, "", "Message queue IDs");