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.
10 * This system call was implemented by Daniel Boulet under contract from RTMX.
12 * Redistribution and use in source forms, with and without modification,
13 * are permitted provided that this entire comment appears intact.
15 * Redistribution in binary form may occur without any restrictions.
16 * Obviously, it would be nice if you gave credit where credit is due
17 * but requiring it would be too onerous.
19 * This software is provided ``AS IS'' without any warranties of any kind.
22 #include "opt_sysvipc.h"
24 #include <sys/param.h>
25 #include <sys/systm.h>
26 #include <sys/sysproto.h>
27 #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);
46 struct msg *msg_next; /* next msg in the chain */
47 long msg_type; /* type of this message */
48 /* >0 -> type of this message */
49 /* 0 -> free header */
50 u_short msg_ts; /* size of this message */
51 short msg_spot; /* location of start of msg in buffer */
56 #define MSGSSZ 8 /* Each segment must be 2^N long */
59 #define MSGSEG 2048 /* must be less than 32767 */
61 #define MSGMAX (MSGSSZ*MSGSEG)
63 #define MSGMNB 2048 /* max # of bytes in a queue */
73 * Based on the configuration parameters described in an SVR2 (yes, two)
74 * config(1m) man page.
76 * Each message is broken up and stored in segments that are msgssz bytes
77 * long. For efficiency reasons, this should be a power of two. Also,
78 * it doesn't make sense if it is less than 8 or greater than about 256.
79 * Consequently, msginit in kern/sysv_msg.c checks that msgssz is a power of
80 * two between 8 and 1024 inclusive (and panic's if it isn't).
82 struct msginfo msginfo = {
83 MSGMAX, /* max chars in a message */
84 MSGMNI, /* # of message queue identifiers */
85 MSGMNB, /* max chars in a queue */
86 MSGTQL, /* max messages in system */
87 MSGSSZ, /* size of a message segment */
88 /* (must be small power of 2 greater than 4) */
89 MSGSEG /* number of message segments */
93 * macros to convert between msqid_ds's and msqid's.
94 * (specific to this implementation)
96 #define MSQID(ix,ds) ((ix) & 0xffff | (((ds).msg_perm.seq << 16) & 0xffff0000))
97 #define MSQID_IX(id) ((id) & 0xffff)
98 #define MSQID_SEQ(id) (((id) >> 16) & 0xffff)
101 * The rest of this file is specific to this particular implementation.
105 short next; /* next segment in buffer */
106 /* -1 -> available */
107 /* 0..(MSGSEG-1) -> index of next segment */
110 #define MSG_LOCKED 01000 /* Is this msqid_ds locked? */
112 static int nfree_msgmaps; /* # of free map entries */
113 static short free_msgmaps; /* head of linked list of free map entries */
114 static struct msg *free_msghdrs;/* list of free msg headers */
115 static char *msgpool; /* MSGMAX byte long msg buffer pool */
116 static struct msgmap *msgmaps; /* MSGSEG msgmap structures */
117 static struct msg *msghdrs; /* MSGTQL msg headers */
118 static struct msqid_ds *msqids; /* MSGMNI msqid_ds struct's */
119 static struct lwkt_token msg_token = LWKT_TOKEN_INITIALIZER(msg_token);
126 msginfo.msgmax = msginfo.msgseg * msginfo.msgssz;
127 msgpool = kmalloc(msginfo.msgmax, M_MSG, M_WAITOK);
128 msgmaps = kmalloc(sizeof(struct msgmap) * msginfo.msgseg, M_MSG, M_WAITOK);
129 msghdrs = kmalloc(sizeof(struct msg) * msginfo.msgtql, M_MSG, M_WAITOK);
130 msqids = kmalloc(sizeof(struct msqid_ds) * msginfo.msgmni, M_MSG, M_WAITOK);
133 * msginfo.msgssz should be a power of two for efficiency reasons.
134 * It is also pretty silly if msginfo.msgssz is less than 8
135 * or greater than about 256 so ...
139 while (i < 1024 && i != msginfo.msgssz)
141 if (i != msginfo.msgssz) {
142 kprintf("msginfo.msgssz=%d (0x%x)\n", msginfo.msgssz,
144 panic("msginfo.msgssz not a small power of 2");
147 if (msginfo.msgseg > 32767) {
148 kprintf("msginfo.msgseg=%d\n", msginfo.msgseg);
149 panic("msginfo.msgseg > 32767");
152 for (i = 0; i < msginfo.msgseg; i++) {
154 msgmaps[i-1].next = i;
155 msgmaps[i].next = -1; /* implies entry is available */
158 nfree_msgmaps = msginfo.msgseg;
160 for (i = 0; i < msginfo.msgtql; i++) {
161 msghdrs[i].msg_type = 0;
163 msghdrs[i-1].msg_next = &msghdrs[i];
164 msghdrs[i].msg_next = NULL;
166 free_msghdrs = &msghdrs[0];
168 for (i = 0; i < msginfo.msgmni; i++) {
169 msqids[i].msg_qbytes = 0; /* implies entry is available */
170 msqids[i].msg_perm.seq = 0; /* reset to a known value */
171 msqids[i].msg_perm.mode = 0;
174 SYSINIT(sysv_msg, SI_SUB_SYSV_MSG, SI_ORDER_FIRST, msginit, NULL);
177 msg_freehdr(struct msg *msghdr)
179 while (msghdr->msg_ts > 0) {
181 if (msghdr->msg_spot < 0 || msghdr->msg_spot >= msginfo.msgseg)
182 panic("msghdr->msg_spot out of range");
183 next = msgmaps[msghdr->msg_spot].next;
184 msgmaps[msghdr->msg_spot].next = free_msgmaps;
185 free_msgmaps = msghdr->msg_spot;
187 msghdr->msg_spot = next;
188 if (msghdr->msg_ts >= msginfo.msgssz)
189 msghdr->msg_ts -= msginfo.msgssz;
193 if (msghdr->msg_spot != -1)
194 panic("msghdr->msg_spot != -1");
195 msghdr->msg_next = free_msghdrs;
196 free_msghdrs = msghdr;
203 sys_msgctl(struct msgctl_args *uap)
205 struct thread *td = curthread;
206 struct proc *p = td->td_proc;
207 struct prison *pr = p->p_ucred->cr_prison;
208 int msqid = uap->msqid;
210 struct msqid_ds *user_msqptr = uap->buf;
212 struct msqid_ds msqbuf;
213 struct msqid_ds *msqptr;
216 kprintf("call to msgctl(%d, %d, 0x%x)\n", msqid, cmd, user_msqptr);
219 if (pr && !PRISON_CAP_ISSET(pr->pr_caps, PRISON_CAP_SYS_SYSVIPC))
222 lwkt_gettoken(&msg_token);
223 msqid = IPCID_TO_IX(msqid);
225 if (msqid < 0 || msqid >= msginfo.msgmni) {
227 kprintf("msqid (%d) out of range (0<=msqid<%d)\n", msqid,
234 msqptr = &msqids[msqid];
236 if (msqptr->msg_qbytes == 0) {
238 kprintf("no such msqid\n");
243 if (msqptr->msg_perm.seq != IPCID_TO_SEQ(uap->msqid)) {
245 kprintf("wrong sequence number\n");
257 if ((eval = ipcperm(p, &msqptr->msg_perm, IPC_M)) != 0)
259 /* Free the message headers */
260 msghdr = msqptr->msg_first;
261 while (msghdr != NULL) {
262 struct msg *msghdr_tmp;
264 /* Free the segments of each message */
265 msqptr->msg_cbytes -= msghdr->msg_ts;
268 msghdr = msghdr->msg_next;
269 msg_freehdr(msghdr_tmp);
272 if (msqptr->msg_cbytes != 0)
273 panic("msg_cbytes is screwed up");
274 if (msqptr->msg_qnum != 0)
275 panic("msg_qnum is screwed up");
277 msqptr->msg_qbytes = 0; /* Mark it as free */
279 wakeup((caddr_t)msqptr);
285 if ((eval = ipcperm(p, &msqptr->msg_perm, IPC_M)) != 0)
287 if ((eval = copyin(user_msqptr, &msqbuf, sizeof(msqbuf))) != 0)
289 if (msqbuf.msg_qbytes > msqptr->msg_qbytes) {
290 eval = priv_check(td, PRIV_ROOT);
294 if (msqbuf.msg_qbytes > msginfo.msgmnb) {
296 kprintf("can't increase msg_qbytes beyond %d (truncating)\n",
299 msqbuf.msg_qbytes = msginfo.msgmnb; /* silently restrict qbytes to system limit */
301 if (msqbuf.msg_qbytes == 0) {
303 kprintf("can't reduce msg_qbytes to 0\n");
305 eval = EINVAL; /* non-standard errno! */
308 msqptr->msg_perm.uid = msqbuf.msg_perm.uid; /* change the owner */
309 msqptr->msg_perm.gid = msqbuf.msg_perm.gid; /* change the owner */
310 msqptr->msg_perm.mode = (msqptr->msg_perm.mode & ~0777) |
311 (msqbuf.msg_perm.mode & 0777);
312 msqptr->msg_qbytes = msqbuf.msg_qbytes;
313 msqptr->msg_ctime = time_second;
317 if ((eval = ipcperm(p, &msqptr->msg_perm, IPC_R))) {
319 kprintf("requester doesn't have read access\n");
324 eval = copyout(msqptr, user_msqptr, sizeof(struct msqid_ds));
329 kprintf("invalid command %d\n", cmd);
335 lwkt_reltoken(&msg_token);
337 uap->sysmsg_result = rval;
345 sys_msgget(struct msgget_args *uap)
347 struct thread *td = curthread;
348 struct prison *pr = td->td_proc->p_ucred->cr_prison;
351 int msgflg = uap->msgflg;
352 struct ucred *cred = td->td_ucred;
353 struct msqid_ds *msqptr = NULL;
356 kprintf("msgget(0x%x, 0%o)\n", key, msgflg);
358 if (pr && !PRISON_CAP_ISSET(pr->pr_caps, PRISON_CAP_SYS_SYSVIPC))
362 lwkt_gettoken(&msg_token);
364 if (key != IPC_PRIVATE) {
365 for (msqid = 0; msqid < msginfo.msgmni; msqid++) {
366 msqptr = &msqids[msqid];
367 if (msqptr->msg_qbytes != 0 &&
368 msqptr->msg_perm.key == key)
371 if (msqid < msginfo.msgmni) {
373 kprintf("found public key\n");
375 if ((msgflg & IPC_CREAT) && (msgflg & IPC_EXCL)) {
377 kprintf("not exclusive\n");
382 if ((eval = ipcperm(td->td_proc, &msqptr->msg_perm, msgflg & 0700 ))) {
384 kprintf("requester doesn't have 0%o access\n",
394 kprintf("need to allocate the msqid_ds\n");
396 if (key == IPC_PRIVATE || (msgflg & IPC_CREAT)) {
397 for (msqid = 0; msqid < msginfo.msgmni; msqid++) {
399 * Look for an unallocated and unlocked msqid_ds.
400 * msqid_ds's can be locked by msgsnd or msgrcv while
401 * they are copying the message in/out. We can't
402 * re-use the entry until they release it.
404 msqptr = &msqids[msqid];
405 if (msqptr->msg_qbytes == 0 &&
406 (msqptr->msg_perm.mode & MSG_LOCKED) == 0)
409 if (msqid == msginfo.msgmni) {
411 kprintf("no more msqid_ds's available\n");
417 kprintf("msqid %d is available\n", msqid);
419 msqptr->msg_perm.key = key;
420 msqptr->msg_perm.cuid = cred->cr_uid;
421 msqptr->msg_perm.uid = cred->cr_uid;
422 msqptr->msg_perm.cgid = cred->cr_gid;
423 msqptr->msg_perm.gid = cred->cr_gid;
424 msqptr->msg_perm.mode = (msgflg & 0777);
425 /* Make sure that the returned msqid is unique */
426 msqptr->msg_perm.seq = (msqptr->msg_perm.seq + 1) & 0x7fff;
427 msqptr->msg_first = NULL;
428 msqptr->msg_last = NULL;
429 msqptr->msg_cbytes = 0;
430 msqptr->msg_qnum = 0;
431 msqptr->msg_qbytes = msginfo.msgmnb;
432 msqptr->msg_lspid = 0;
433 msqptr->msg_lrpid = 0;
434 msqptr->msg_stime = 0;
435 msqptr->msg_rtime = 0;
436 msqptr->msg_ctime = time_second;
439 kprintf("didn't find it and wasn't asked to create it\n");
445 lwkt_reltoken(&msg_token);
446 /* Construct the unique msqid */
448 uap->sysmsg_result = IXSEQ_TO_IPCID(msqid, msqptr->msg_perm);
456 sys_msgsnd(struct msgsnd_args *uap)
458 struct thread *td = curthread;
459 struct prison *pr = td->td_proc->p_ucred->cr_prison;
460 int msqid = uap->msqid;
461 const void *user_msgp = uap->msgp;
462 size_t msgsz = uap->msgsz;
463 int msgflg = uap->msgflg;
464 int segs_needed, eval;
465 struct msqid_ds *msqptr;
470 kprintf("call to msgsnd(%d, 0x%x, %d, %d)\n", msqid, user_msgp, msgsz,
474 if (pr && !PRISON_CAP_ISSET(pr->pr_caps, PRISON_CAP_SYS_SYSVIPC))
477 lwkt_gettoken(&msg_token);
478 msqid = IPCID_TO_IX(msqid);
480 if (msqid < 0 || msqid >= msginfo.msgmni) {
482 kprintf("msqid (%d) out of range (0<=msqid<%d)\n", msqid,
489 msqptr = &msqids[msqid];
490 if (msqptr->msg_qbytes == 0) {
492 kprintf("no such message queue id\n");
497 if (msqptr->msg_perm.seq != IPCID_TO_SEQ(uap->msqid)) {
499 kprintf("wrong sequence number\n");
505 if ((eval = ipcperm(td->td_proc, &msqptr->msg_perm, IPC_W))) {
507 kprintf("requester doesn't have write access\n");
513 segs_needed = (msgsz + msginfo.msgssz - 1) / msginfo.msgssz;
515 kprintf("msgsz=%d, msgssz=%d, segs_needed=%d\n", msgsz, msginfo.msgssz,
519 int need_more_resources = 0;
523 * (inside this loop in case msg_qbytes changes while we sleep)
526 if (msgsz > msqptr->msg_qbytes) {
528 kprintf("msgsz > msqptr->msg_qbytes\n");
534 if (msqptr->msg_perm.mode & MSG_LOCKED) {
536 kprintf("msqid is locked\n");
538 need_more_resources = 1;
540 if (msgsz + msqptr->msg_cbytes > msqptr->msg_qbytes) {
542 kprintf("msgsz + msg_cbytes > msg_qbytes\n");
544 need_more_resources = 1;
546 if (segs_needed > nfree_msgmaps) {
548 kprintf("segs_needed > nfree_msgmaps\n");
550 need_more_resources = 1;
552 if (free_msghdrs == NULL) {
554 kprintf("no more msghdrs\n");
556 need_more_resources = 1;
559 if (need_more_resources) {
562 if ((msgflg & IPC_NOWAIT) != 0) {
564 kprintf("need more resources but caller doesn't want to wait\n");
570 if ((msqptr->msg_perm.mode & MSG_LOCKED) != 0) {
572 kprintf("we don't own the msqid_ds\n");
576 /* Force later arrivals to wait for our
579 kprintf("we own the msqid_ds\n");
581 msqptr->msg_perm.mode |= MSG_LOCKED;
585 kprintf("goodnight\n");
587 eval = tsleep((caddr_t)msqptr, PCATCH, "msgwait", 0);
589 kprintf("good morning, eval=%d\n", eval);
592 msqptr->msg_perm.mode &= ~MSG_LOCKED;
595 kprintf("msgsnd: interrupted system call\n");
602 * Make sure that the msq queue still exists
605 if (msqptr->msg_qbytes == 0) {
607 kprintf("msqid deleted\n");
615 kprintf("got all the resources that we need\n");
622 * We have the resources that we need.
626 if (msqptr->msg_perm.mode & MSG_LOCKED)
627 panic("msg_perm.mode & MSG_LOCKED");
628 if (segs_needed > nfree_msgmaps)
629 panic("segs_needed > nfree_msgmaps");
630 if (msgsz + msqptr->msg_cbytes > msqptr->msg_qbytes)
631 panic("msgsz + msg_cbytes > msg_qbytes");
632 if (free_msghdrs == NULL)
633 panic("no more msghdrs");
636 * Re-lock the msqid_ds in case we page-fault when copying in the
640 if ((msqptr->msg_perm.mode & MSG_LOCKED) != 0)
641 panic("msqid_ds is already locked");
642 msqptr->msg_perm.mode |= MSG_LOCKED;
645 * Allocate a message header
648 msghdr = free_msghdrs;
649 free_msghdrs = msghdr->msg_next;
650 msghdr->msg_spot = -1;
651 msghdr->msg_ts = msgsz;
654 * Allocate space for the message
657 while (segs_needed > 0) {
658 if (nfree_msgmaps <= 0)
659 panic("not enough msgmaps");
660 if (free_msgmaps == -1)
661 panic("nil free_msgmaps");
664 panic("next too low #1");
665 if (next >= msginfo.msgseg)
666 panic("next out of range #1");
668 kprintf("allocating segment %d to message\n", next);
670 free_msgmaps = msgmaps[next].next;
672 msgmaps[next].next = msghdr->msg_spot;
673 msghdr->msg_spot = next;
678 * Copy in the message type
681 if ((eval = copyin(user_msgp, &msghdr->msg_type,
682 sizeof(msghdr->msg_type))) != 0) {
684 kprintf("error %d copying the message type\n", eval);
687 msqptr->msg_perm.mode &= ~MSG_LOCKED;
688 wakeup((caddr_t)msqptr);
691 user_msgp = (const char *)user_msgp + sizeof(msghdr->msg_type);
694 * Validate the message type
697 if (msghdr->msg_type < 1) {
699 msqptr->msg_perm.mode &= ~MSG_LOCKED;
700 wakeup((caddr_t)msqptr);
702 kprintf("mtype (%d) < 1\n", msghdr->msg_type);
709 * Copy in the message body
712 next = msghdr->msg_spot;
715 if (msgsz > msginfo.msgssz)
716 tlen = msginfo.msgssz;
720 panic("next too low #2");
721 if (next >= msginfo.msgseg)
722 panic("next out of range #2");
723 if ((eval = copyin(user_msgp, &msgpool[next * msginfo.msgssz],
726 kprintf("error %d copying in message segment\n", eval);
729 msqptr->msg_perm.mode &= ~MSG_LOCKED;
730 wakeup((caddr_t)msqptr);
734 user_msgp = (const char *)user_msgp + tlen;
735 next = msgmaps[next].next;
738 panic("didn't use all the msg segments");
741 * We've got the message. Unlock the msqid_ds.
744 msqptr->msg_perm.mode &= ~MSG_LOCKED;
747 * Make sure that the msqid_ds is still allocated.
750 if (msqptr->msg_qbytes == 0) {
752 wakeup((caddr_t)msqptr);
758 * Put the message into the queue
761 if (msqptr->msg_first == NULL) {
762 msqptr->msg_first = msghdr;
763 msqptr->msg_last = msghdr;
765 msqptr->msg_last->msg_next = msghdr;
766 msqptr->msg_last = msghdr;
768 msqptr->msg_last->msg_next = NULL;
770 msqptr->msg_cbytes += msghdr->msg_ts;
772 msqptr->msg_lspid = td->td_proc->p_pid;
773 msqptr->msg_stime = time_second;
775 wakeup((caddr_t)msqptr);
778 lwkt_reltoken(&msg_token);
780 uap->sysmsg_result = 0;
788 sys_msgrcv(struct msgrcv_args *uap)
790 struct thread *td = curthread;
791 struct prison *pr = td->td_proc->p_ucred->cr_prison;
792 int msqid = uap->msqid;
793 void *user_msgp = uap->msgp;
794 size_t msgsz = uap->msgsz;
795 long msgtyp = uap->msgtyp;
796 int msgflg = uap->msgflg;
798 struct msqid_ds *msqptr;
804 kprintf("call to msgrcv(%d, 0x%x, %d, %ld, %d)\n", msqid, user_msgp,
805 msgsz, msgtyp, msgflg);
808 if (pr && !PRISON_CAP_ISSET(pr->pr_caps, PRISON_CAP_SYS_SYSVIPC))
811 lwkt_gettoken(&msg_token);
812 msqid = IPCID_TO_IX(msqid);
814 if (msqid < 0 || msqid >= msginfo.msgmni) {
816 kprintf("msqid (%d) out of range (0<=msqid<%d)\n", msqid,
823 msqptr = &msqids[msqid];
824 if (msqptr->msg_qbytes == 0) {
826 kprintf("no such message queue id\n");
831 if (msqptr->msg_perm.seq != IPCID_TO_SEQ(uap->msqid)) {
833 kprintf("wrong sequence number\n");
839 if ((eval = ipcperm(td->td_proc, &msqptr->msg_perm, IPC_R))) {
841 kprintf("requester doesn't have read access\n");
847 while (msghdr == NULL) {
849 msghdr = msqptr->msg_first;
850 if (msghdr != NULL) {
851 if (msgsz < msghdr->msg_ts &&
852 (msgflg & MSG_NOERROR) == 0) {
854 kprintf("first message on the queue is too big (want %d, got %d)\n",
855 msgsz, msghdr->msg_ts);
860 if (msqptr->msg_first == msqptr->msg_last) {
861 msqptr->msg_first = NULL;
862 msqptr->msg_last = NULL;
864 msqptr->msg_first = msghdr->msg_next;
865 if (msqptr->msg_first == NULL)
866 panic("msg_first/last screwed up #1");
870 struct msg *previous;
874 prev = &(msqptr->msg_first);
875 while ((msghdr = *prev) != NULL) {
877 * Is this message's type an exact match or is
878 * this message's type less than or equal to
879 * the absolute value of a negative msgtyp?
880 * Note that the second half of this test can
881 * NEVER be true if msgtyp is positive since
882 * msg_type is always positive!
885 if (msgtyp == msghdr->msg_type ||
886 msghdr->msg_type <= -msgtyp) {
888 kprintf("found message type %d, requested %d\n",
889 msghdr->msg_type, msgtyp);
891 if (msgsz < msghdr->msg_ts &&
892 (msgflg & MSG_NOERROR) == 0) {
894 kprintf("requested message on the queue is too big (want %d, got %d)\n",
895 msgsz, msghdr->msg_ts);
900 *prev = msghdr->msg_next;
901 if (msghdr == msqptr->msg_last) {
902 if (previous == NULL) {
905 panic("msg_first/last screwed up #2");
913 panic("msg_first/last screwed up #3");
921 prev = &(msghdr->msg_next);
926 * We've either extracted the msghdr for the appropriate
927 * message or there isn't one.
928 * If there is one then bail out of this loop.
935 * Hmph! No message found. Does the user want to wait?
938 if ((msgflg & IPC_NOWAIT) != 0) {
940 kprintf("no appropriate message found (msgtyp=%d)\n",
943 /* The SVID says to return ENOMSG. */
947 /* Unfortunately, BSD doesn't define that code yet! */
954 * Wait for something to happen
958 kprintf("msgrcv: goodnight\n");
960 eval = tsleep((caddr_t)msqptr, PCATCH, "msgwait", 0);
962 kprintf("msgrcv: good morning (eval=%d)\n", eval);
967 kprintf("msgsnd: interrupted system call\n");
974 * Make sure that the msq queue still exists
977 if (msqptr->msg_qbytes == 0 ||
978 msqptr->msg_perm.seq != IPCID_TO_SEQ(uap->msqid)) {
980 kprintf("msqid deleted\n");
988 * Return the message to the user.
990 * First, do the bookkeeping (before we risk being interrupted).
993 msqptr->msg_cbytes -= msghdr->msg_ts;
995 msqptr->msg_lrpid = td->td_proc->p_pid;
996 msqptr->msg_rtime = time_second;
999 * Make msgsz the actual amount that we'll be returning.
1000 * Note that this effectively truncates the message if it is too long
1001 * (since msgsz is never increased).
1005 kprintf("found a message, msgsz=%d, msg_ts=%d\n", msgsz,
1008 if (msgsz > msghdr->msg_ts)
1009 msgsz = msghdr->msg_ts;
1012 * Return the type to the user.
1015 eval = copyout((caddr_t)&(msghdr->msg_type), user_msgp,
1016 sizeof(msghdr->msg_type));
1019 kprintf("error (%d) copying out message type\n", eval);
1021 msg_freehdr(msghdr);
1022 wakeup((caddr_t)msqptr);
1025 user_msgp = (char *)user_msgp + sizeof(msghdr->msg_type);
1028 * Return the segments to the user
1031 next = msghdr->msg_spot;
1032 for (len = 0; len < msgsz; len += msginfo.msgssz) {
1035 if (msgsz - len > msginfo.msgssz)
1036 tlen = msginfo.msgssz;
1040 panic("next too low #3");
1041 if (next >= msginfo.msgseg)
1042 panic("next out of range #3");
1043 eval = copyout((caddr_t)&msgpool[next * msginfo.msgssz],
1047 kprintf("error (%d) copying out message segment\n",
1050 msg_freehdr(msghdr);
1051 wakeup((caddr_t)msqptr);
1054 user_msgp = (char *)user_msgp + tlen;
1055 next = msgmaps[next].next;
1059 * Done, return the actual number of bytes copied out.
1062 msg_freehdr(msghdr);
1063 wakeup((caddr_t)msqptr);
1066 lwkt_reltoken(&msg_token);
1068 uap->sysmsg_result = msgsz;
1073 sysctl_msqids(SYSCTL_HANDLER_ARGS)
1075 return (SYSCTL_OUT(req, msqids,
1076 sizeof(struct msqid_ds) * msginfo.msgmni));
1079 TUNABLE_INT("kern.ipc.msgseg", &msginfo.msgseg);
1080 TUNABLE_INT("kern.ipc.msgssz", &msginfo.msgssz);
1081 TUNABLE_INT("kern.ipc.msgmni", &msginfo.msgmni);
1083 SYSCTL_INT(_kern_ipc, OID_AUTO, msgmax, CTLFLAG_RD, &msginfo.msgmax, 0,
1084 "Max characters in message");
1085 SYSCTL_INT(_kern_ipc, OID_AUTO, msgmni, CTLFLAG_RD, &msginfo.msgmni, 0,
1086 "Max message queue identifiers");
1087 SYSCTL_INT(_kern_ipc, OID_AUTO, msgmnb, CTLFLAG_RD, &msginfo.msgmnb, 0,
1088 "Max characters in message queue");
1089 SYSCTL_INT(_kern_ipc, OID_AUTO, msgtql, CTLFLAG_RD, &msginfo.msgtql, 0,
1090 "Max SVID messages in system");
1091 SYSCTL_INT(_kern_ipc, OID_AUTO, msgssz, CTLFLAG_RD, &msginfo.msgssz, 0,
1092 "Power-of-two size of a message segment");
1093 SYSCTL_INT(_kern_ipc, OID_AUTO, msgseg, CTLFLAG_RD, &msginfo.msgseg, 0,
1094 "Number of message segments");
1095 SYSCTL_PROC(_kern_ipc, OID_AUTO, msqids, CTLFLAG_RD,
1096 NULL, 0, sysctl_msqids, "", "Message queue IDs");