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.12 2003/08/26 21:09:02 rob 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 (void *);
43 static void msg_freehdr (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(int which, int a2, ...) (VARARGS)
205 msgsys(struct msgsys_args *uap)
207 struct proc *p = curproc;
208 unsigned int which = (unsigned int)uap->which;
210 if (!jail_sysvipc_allowed && p->p_ucred->cr_prison != NULL)
213 if (which >= sizeof(msgcalls)/sizeof(msgcalls[0]))
215 bcopy(&uap->a2, &uap->which,
216 sizeof(struct msgsys_args) - offsetof(struct msgsys_args, a2));
217 return ((*msgcalls[which])(uap));
221 msg_freehdr(struct msg *msghdr)
223 while (msghdr->msg_ts > 0) {
225 if (msghdr->msg_spot < 0 || msghdr->msg_spot >= msginfo.msgseg)
226 panic("msghdr->msg_spot out of range");
227 next = msgmaps[msghdr->msg_spot].next;
228 msgmaps[msghdr->msg_spot].next = free_msgmaps;
229 free_msgmaps = msghdr->msg_spot;
231 msghdr->msg_spot = next;
232 if (msghdr->msg_ts >= msginfo.msgssz)
233 msghdr->msg_ts -= msginfo.msgssz;
237 if (msghdr->msg_spot != -1)
238 panic("msghdr->msg_spot != -1");
239 msghdr->msg_next = free_msghdrs;
240 free_msghdrs = msghdr;
244 msgctl(struct msgctl_args *uap)
246 struct thread *td = curthread;
247 struct proc *p = td->td_proc;
248 int msqid = uap->msqid;
250 struct msqid_ds *user_msqptr = uap->buf;
252 struct msqid_ds msqbuf;
253 struct msqid_ds *msqptr;
256 printf("call to msgctl(%d, %d, 0x%x)\n", msqid, cmd, user_msqptr);
259 if (!jail_sysvipc_allowed && p->p_ucred->cr_prison != NULL)
262 msqid = IPCID_TO_IX(msqid);
264 if (msqid < 0 || msqid >= msginfo.msgmni) {
266 printf("msqid (%d) out of range (0<=msqid<%d)\n", msqid,
272 msqptr = &msqids[msqid];
274 if (msqptr->msg_qbytes == 0) {
276 printf("no such msqid\n");
280 if (msqptr->msg_perm.seq != IPCID_TO_SEQ(uap->msqid)) {
282 printf("wrong sequence number\n");
295 if ((eval = ipcperm(p, &msqptr->msg_perm, IPC_M)))
297 /* Free the message headers */
298 msghdr = msqptr->msg_first;
299 while (msghdr != NULL) {
300 struct msg *msghdr_tmp;
302 /* Free the segments of each message */
303 msqptr->msg_cbytes -= msghdr->msg_ts;
306 msghdr = msghdr->msg_next;
307 msg_freehdr(msghdr_tmp);
310 if (msqptr->msg_cbytes != 0)
311 panic("msg_cbytes is screwed up");
312 if (msqptr->msg_qnum != 0)
313 panic("msg_qnum is screwed up");
315 msqptr->msg_qbytes = 0; /* Mark it as free */
317 wakeup((caddr_t)msqptr);
323 if ((eval = ipcperm(p, &msqptr->msg_perm, IPC_M)))
325 if ((eval = copyin(user_msqptr, &msqbuf, sizeof(msqbuf))) != 0)
327 if (msqbuf.msg_qbytes > msqptr->msg_qbytes) {
332 if (msqbuf.msg_qbytes > msginfo.msgmnb) {
334 printf("can't increase msg_qbytes beyond %d (truncating)\n",
337 msqbuf.msg_qbytes = msginfo.msgmnb; /* silently restrict qbytes to system limit */
339 if (msqbuf.msg_qbytes == 0) {
341 printf("can't reduce msg_qbytes to 0\n");
343 return(EINVAL); /* non-standard errno! */
345 msqptr->msg_perm.uid = msqbuf.msg_perm.uid; /* change the owner */
346 msqptr->msg_perm.gid = msqbuf.msg_perm.gid; /* change the owner */
347 msqptr->msg_perm.mode = (msqptr->msg_perm.mode & ~0777) |
348 (msqbuf.msg_perm.mode & 0777);
349 msqptr->msg_qbytes = msqbuf.msg_qbytes;
350 msqptr->msg_ctime = time_second;
354 if ((eval = ipcperm(p, &msqptr->msg_perm, IPC_R))) {
356 printf("requester doesn't have read access\n");
360 eval = copyout((caddr_t)msqptr, user_msqptr,
361 sizeof(struct msqid_ds));
366 printf("invalid command %d\n", cmd);
372 uap->sysmsg_result = rval;
377 msgget(struct msgget_args *uap)
379 struct proc *p = curproc;
382 int msgflg = uap->msgflg;
383 struct ucred *cred = p->p_ucred;
384 struct msqid_ds *msqptr = NULL;
387 printf("msgget(0x%x, 0%o)\n", key, msgflg);
390 if (!jail_sysvipc_allowed && p->p_ucred->cr_prison != NULL)
393 if (key != IPC_PRIVATE) {
394 for (msqid = 0; msqid < msginfo.msgmni; msqid++) {
395 msqptr = &msqids[msqid];
396 if (msqptr->msg_qbytes != 0 &&
397 msqptr->msg_perm.key == key)
400 if (msqid < msginfo.msgmni) {
402 printf("found public key\n");
404 if ((msgflg & IPC_CREAT) && (msgflg & IPC_EXCL)) {
406 printf("not exclusive\n");
410 if ((eval = ipcperm(p, &msqptr->msg_perm, msgflg & 0700 ))) {
412 printf("requester doesn't have 0%o access\n",
422 printf("need to allocate the msqid_ds\n");
424 if (key == IPC_PRIVATE || (msgflg & IPC_CREAT)) {
425 for (msqid = 0; msqid < msginfo.msgmni; msqid++) {
427 * Look for an unallocated and unlocked msqid_ds.
428 * msqid_ds's can be locked by msgsnd or msgrcv while
429 * they are copying the message in/out. We can't
430 * re-use the entry until they release it.
432 msqptr = &msqids[msqid];
433 if (msqptr->msg_qbytes == 0 &&
434 (msqptr->msg_perm.mode & MSG_LOCKED) == 0)
437 if (msqid == msginfo.msgmni) {
439 printf("no more msqid_ds's available\n");
444 printf("msqid %d is available\n", msqid);
446 msqptr->msg_perm.key = key;
447 msqptr->msg_perm.cuid = cred->cr_uid;
448 msqptr->msg_perm.uid = cred->cr_uid;
449 msqptr->msg_perm.cgid = cred->cr_gid;
450 msqptr->msg_perm.gid = cred->cr_gid;
451 msqptr->msg_perm.mode = (msgflg & 0777);
452 /* Make sure that the returned msqid is unique */
453 msqptr->msg_perm.seq = (msqptr->msg_perm.seq + 1) & 0x7fff;
454 msqptr->msg_first = NULL;
455 msqptr->msg_last = NULL;
456 msqptr->msg_cbytes = 0;
457 msqptr->msg_qnum = 0;
458 msqptr->msg_qbytes = msginfo.msgmnb;
459 msqptr->msg_lspid = 0;
460 msqptr->msg_lrpid = 0;
461 msqptr->msg_stime = 0;
462 msqptr->msg_rtime = 0;
463 msqptr->msg_ctime = time_second;
466 printf("didn't find it and wasn't asked to create it\n");
472 /* Construct the unique msqid */
473 uap->sysmsg_result = IXSEQ_TO_IPCID(msqid, msqptr->msg_perm);
478 msgsnd(struct msgsnd_args *uap)
480 struct proc *p = curproc;
481 int msqid = uap->msqid;
482 void *user_msgp = uap->msgp;
483 size_t msgsz = uap->msgsz;
484 int msgflg = uap->msgflg;
485 int segs_needed, eval;
486 struct msqid_ds *msqptr;
491 printf("call to msgsnd(%d, 0x%x, %d, %d)\n", msqid, user_msgp, msgsz,
495 if (!jail_sysvipc_allowed && p->p_ucred->cr_prison != NULL)
498 msqid = IPCID_TO_IX(msqid);
500 if (msqid < 0 || msqid >= msginfo.msgmni) {
502 printf("msqid (%d) out of range (0<=msqid<%d)\n", msqid,
508 msqptr = &msqids[msqid];
509 if (msqptr->msg_qbytes == 0) {
511 printf("no such message queue id\n");
515 if (msqptr->msg_perm.seq != IPCID_TO_SEQ(uap->msqid)) {
517 printf("wrong sequence number\n");
522 if ((eval = ipcperm(p, &msqptr->msg_perm, IPC_W))) {
524 printf("requester doesn't have write access\n");
529 segs_needed = (msgsz + msginfo.msgssz - 1) / msginfo.msgssz;
531 printf("msgsz=%d, msgssz=%d, segs_needed=%d\n", msgsz, msginfo.msgssz,
535 int need_more_resources = 0;
539 * (inside this loop in case msg_qbytes changes while we sleep)
542 if (msgsz > msqptr->msg_qbytes) {
544 printf("msgsz > msqptr->msg_qbytes\n");
549 if (msqptr->msg_perm.mode & MSG_LOCKED) {
551 printf("msqid is locked\n");
553 need_more_resources = 1;
555 if (msgsz + msqptr->msg_cbytes > msqptr->msg_qbytes) {
557 printf("msgsz + msg_cbytes > msg_qbytes\n");
559 need_more_resources = 1;
561 if (segs_needed > nfree_msgmaps) {
563 printf("segs_needed > nfree_msgmaps\n");
565 need_more_resources = 1;
567 if (free_msghdrs == NULL) {
569 printf("no more msghdrs\n");
571 need_more_resources = 1;
574 if (need_more_resources) {
577 if ((msgflg & IPC_NOWAIT) != 0) {
579 printf("need more resources but caller doesn't want to wait\n");
584 if ((msqptr->msg_perm.mode & MSG_LOCKED) != 0) {
586 printf("we don't own the msqid_ds\n");
590 /* Force later arrivals to wait for our
593 printf("we own the msqid_ds\n");
595 msqptr->msg_perm.mode |= MSG_LOCKED;
599 printf("goodnight\n");
601 eval = tsleep((caddr_t)msqptr, PCATCH, "msgwait", 0);
603 printf("good morning, eval=%d\n", eval);
606 msqptr->msg_perm.mode &= ~MSG_LOCKED;
609 printf("msgsnd: interrupted system call\n");
615 * Make sure that the msq queue still exists
618 if (msqptr->msg_qbytes == 0) {
620 printf("msqid deleted\n");
627 printf("got all the resources that we need\n");
634 * We have the resources that we need.
638 if (msqptr->msg_perm.mode & MSG_LOCKED)
639 panic("msg_perm.mode & MSG_LOCKED");
640 if (segs_needed > nfree_msgmaps)
641 panic("segs_needed > nfree_msgmaps");
642 if (msgsz + msqptr->msg_cbytes > msqptr->msg_qbytes)
643 panic("msgsz + msg_cbytes > msg_qbytes");
644 if (free_msghdrs == NULL)
645 panic("no more msghdrs");
648 * Re-lock the msqid_ds in case we page-fault when copying in the
652 if ((msqptr->msg_perm.mode & MSG_LOCKED) != 0)
653 panic("msqid_ds is already locked");
654 msqptr->msg_perm.mode |= MSG_LOCKED;
657 * Allocate a message header
660 msghdr = free_msghdrs;
661 free_msghdrs = msghdr->msg_next;
662 msghdr->msg_spot = -1;
663 msghdr->msg_ts = msgsz;
666 * Allocate space for the message
669 while (segs_needed > 0) {
670 if (nfree_msgmaps <= 0)
671 panic("not enough msgmaps");
672 if (free_msgmaps == -1)
673 panic("nil free_msgmaps");
676 panic("next too low #1");
677 if (next >= msginfo.msgseg)
678 panic("next out of range #1");
680 printf("allocating segment %d to message\n", next);
682 free_msgmaps = msgmaps[next].next;
684 msgmaps[next].next = msghdr->msg_spot;
685 msghdr->msg_spot = next;
690 * Copy in the message type
693 if ((eval = copyin(user_msgp, &msghdr->msg_type,
694 sizeof(msghdr->msg_type))) != 0) {
696 printf("error %d copying the message type\n", eval);
699 msqptr->msg_perm.mode &= ~MSG_LOCKED;
700 wakeup((caddr_t)msqptr);
703 user_msgp = (char *)user_msgp + sizeof(msghdr->msg_type);
706 * Validate the message type
709 if (msghdr->msg_type < 1) {
711 msqptr->msg_perm.mode &= ~MSG_LOCKED;
712 wakeup((caddr_t)msqptr);
714 printf("mtype (%d) < 1\n", msghdr->msg_type);
720 * Copy in the message body
723 next = msghdr->msg_spot;
726 if (msgsz > msginfo.msgssz)
727 tlen = msginfo.msgssz;
731 panic("next too low #2");
732 if (next >= msginfo.msgseg)
733 panic("next out of range #2");
734 if ((eval = copyin(user_msgp, &msgpool[next * msginfo.msgssz],
737 printf("error %d copying in message segment\n", eval);
740 msqptr->msg_perm.mode &= ~MSG_LOCKED;
741 wakeup((caddr_t)msqptr);
745 user_msgp = (char *)user_msgp + tlen;
746 next = msgmaps[next].next;
749 panic("didn't use all the msg segments");
752 * We've got the message. Unlock the msqid_ds.
755 msqptr->msg_perm.mode &= ~MSG_LOCKED;
758 * Make sure that the msqid_ds is still allocated.
761 if (msqptr->msg_qbytes == 0) {
763 wakeup((caddr_t)msqptr);
768 * Put the message into the queue
771 if (msqptr->msg_first == NULL) {
772 msqptr->msg_first = msghdr;
773 msqptr->msg_last = msghdr;
775 msqptr->msg_last->msg_next = msghdr;
776 msqptr->msg_last = msghdr;
778 msqptr->msg_last->msg_next = NULL;
780 msqptr->msg_cbytes += msghdr->msg_ts;
782 msqptr->msg_lspid = p->p_pid;
783 msqptr->msg_stime = time_second;
785 wakeup((caddr_t)msqptr);
786 uap->sysmsg_result = 0;
791 msgrcv(struct msgrcv_args *uap)
793 struct proc *p = curproc;
794 int msqid = uap->msqid;
795 void *user_msgp = uap->msgp;
796 size_t msgsz = uap->msgsz;
797 long msgtyp = uap->msgtyp;
798 int msgflg = uap->msgflg;
800 struct msqid_ds *msqptr;
806 printf("call to msgrcv(%d, 0x%x, %d, %ld, %d)\n", msqid, user_msgp,
807 msgsz, msgtyp, msgflg);
810 if (!jail_sysvipc_allowed && p->p_ucred->cr_prison != NULL)
813 msqid = IPCID_TO_IX(msqid);
815 if (msqid < 0 || msqid >= msginfo.msgmni) {
817 printf("msqid (%d) out of range (0<=msqid<%d)\n", msqid,
823 msqptr = &msqids[msqid];
824 if (msqptr->msg_qbytes == 0) {
826 printf("no such message queue id\n");
830 if (msqptr->msg_perm.seq != IPCID_TO_SEQ(uap->msqid)) {
832 printf("wrong sequence number\n");
837 if ((eval = ipcperm(p, &msqptr->msg_perm, IPC_R))) {
839 printf("requester doesn't have read access\n");
845 while (msghdr == NULL) {
847 msghdr = msqptr->msg_first;
848 if (msghdr != NULL) {
849 if (msgsz < msghdr->msg_ts &&
850 (msgflg & MSG_NOERROR) == 0) {
852 printf("first message on the queue is too big (want %d, got %d)\n",
853 msgsz, msghdr->msg_ts);
857 if (msqptr->msg_first == msqptr->msg_last) {
858 msqptr->msg_first = NULL;
859 msqptr->msg_last = NULL;
861 msqptr->msg_first = msghdr->msg_next;
862 if (msqptr->msg_first == NULL)
863 panic("msg_first/last screwed up #1");
867 struct msg *previous;
871 prev = &(msqptr->msg_first);
872 while ((msghdr = *prev) != NULL) {
874 * Is this message's type an exact match or is
875 * this message's type less than or equal to
876 * the absolute value of a negative msgtyp?
877 * Note that the second half of this test can
878 * NEVER be true if msgtyp is positive since
879 * msg_type is always positive!
882 if (msgtyp == msghdr->msg_type ||
883 msghdr->msg_type <= -msgtyp) {
885 printf("found message type %d, requested %d\n",
886 msghdr->msg_type, msgtyp);
888 if (msgsz < msghdr->msg_ts &&
889 (msgflg & MSG_NOERROR) == 0) {
891 printf("requested message on the queue is too big (want %d, got %d)\n",
892 msgsz, msghdr->msg_ts);
896 *prev = msghdr->msg_next;
897 if (msghdr == msqptr->msg_last) {
898 if (previous == NULL) {
901 panic("msg_first/last screwed up #2");
909 panic("msg_first/last screwed up #3");
917 prev = &(msghdr->msg_next);
922 * We've either extracted the msghdr for the appropriate
923 * message or there isn't one.
924 * If there is one then bail out of this loop.
931 * Hmph! No message found. Does the user want to wait?
934 if ((msgflg & IPC_NOWAIT) != 0) {
936 printf("no appropriate message found (msgtyp=%d)\n",
939 /* The SVID says to return ENOMSG. */
943 /* Unfortunately, BSD doesn't define that code yet! */
949 * Wait for something to happen
953 printf("msgrcv: goodnight\n");
955 eval = tsleep((caddr_t)msqptr, PCATCH, "msgwait", 0);
957 printf("msgrcv: good morning (eval=%d)\n", eval);
962 printf("msgsnd: interrupted system call\n");
968 * Make sure that the msq queue still exists
971 if (msqptr->msg_qbytes == 0 ||
972 msqptr->msg_perm.seq != IPCID_TO_SEQ(uap->msqid)) {
974 printf("msqid deleted\n");
981 * Return the message to the user.
983 * First, do the bookkeeping (before we risk being interrupted).
986 msqptr->msg_cbytes -= msghdr->msg_ts;
988 msqptr->msg_lrpid = p->p_pid;
989 msqptr->msg_rtime = time_second;
992 * Make msgsz the actual amount that we'll be returning.
993 * Note that this effectively truncates the message if it is too long
994 * (since msgsz is never increased).
998 printf("found a message, msgsz=%d, msg_ts=%d\n", msgsz,
1001 if (msgsz > msghdr->msg_ts)
1002 msgsz = msghdr->msg_ts;
1005 * Return the type to the user.
1008 eval = copyout((caddr_t)&(msghdr->msg_type), user_msgp,
1009 sizeof(msghdr->msg_type));
1012 printf("error (%d) copying out message type\n", eval);
1014 msg_freehdr(msghdr);
1015 wakeup((caddr_t)msqptr);
1018 user_msgp = (char *)user_msgp + sizeof(msghdr->msg_type);
1021 * Return the segments to the user
1024 next = msghdr->msg_spot;
1025 for (len = 0; len < msgsz; len += msginfo.msgssz) {
1028 if (msgsz - len > msginfo.msgssz)
1029 tlen = msginfo.msgssz;
1033 panic("next too low #3");
1034 if (next >= msginfo.msgseg)
1035 panic("next out of range #3");
1036 eval = copyout((caddr_t)&msgpool[next * msginfo.msgssz],
1040 printf("error (%d) copying out message segment\n",
1043 msg_freehdr(msghdr);
1044 wakeup((caddr_t)msqptr);
1047 user_msgp = (char *)user_msgp + tlen;
1048 next = msgmaps[next].next;
1052 * Done, return the actual number of bytes copied out.
1055 msg_freehdr(msghdr);
1056 wakeup((caddr_t)msqptr);
1057 uap->sysmsg_result = msgsz;
1062 sysctl_msqids(SYSCTL_HANDLER_ARGS)
1065 return (SYSCTL_OUT(req, msqids,
1066 sizeof(struct msqid_ds) * msginfo.msgmni));
1069 TUNABLE_INT("kern.ipc.msgseg", &msginfo.msgseg);
1070 TUNABLE_INT("kern.ipc.msgssz", &msginfo.msgssz);
1071 TUNABLE_INT("kern.ipc.msgmni", &msginfo.msgmni);
1073 SYSCTL_DECL(_kern_ipc);
1074 SYSCTL_INT(_kern_ipc, OID_AUTO, msgmax, CTLFLAG_RD, &msginfo.msgmax, 0, "");
1075 SYSCTL_INT(_kern_ipc, OID_AUTO, msgmni, CTLFLAG_RD, &msginfo.msgmni, 0, "");
1076 SYSCTL_INT(_kern_ipc, OID_AUTO, msgmnb, CTLFLAG_RD, &msginfo.msgmnb, 0, "");
1077 SYSCTL_INT(_kern_ipc, OID_AUTO, msgtql, CTLFLAG_RD, &msginfo.msgtql, 0, "");
1078 SYSCTL_INT(_kern_ipc, OID_AUTO, msgssz, CTLFLAG_RD, &msginfo.msgssz, 0, "");
1079 SYSCTL_INT(_kern_ipc, OID_AUTO, msgseg, CTLFLAG_RD, &msginfo.msgseg, 0, "");
1080 SYSCTL_PROC(_kern_ipc, OID_AUTO, msqids, CTLFLAG_RD,
1081 NULL, 0, sysctl_msqids, "", "Message queue IDs");