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>
30 #include <sys/sysent.h>
31 #include <sys/sysctl.h>
32 #include <sys/malloc.h>
34 static MALLOC_DEFINE(M_MSG, "msg", "SVID compatible message queues");
36 static void msginit __P((void *));
41 static void msg_freehdr __P((struct msg *msghdr));
43 /* XXX casting to (sy_call_t *) is bogus, as usual. */
44 static sy_call_t *msgcalls[] = {
45 (sy_call_t *)msgctl, (sy_call_t *)msgget,
46 (sy_call_t *)msgsnd, (sy_call_t *)msgrcv
50 struct msg *msg_next; /* next msg in the chain */
51 long msg_type; /* type of this message */
52 /* >0 -> type of this message */
53 /* 0 -> free header */
54 u_short msg_ts; /* size of this message */
55 short msg_spot; /* location of start of msg in buffer */
60 #define MSGSSZ 8 /* Each segment must be 2^N long */
63 #define MSGSEG 2048 /* must be less than 32767 */
65 #define MSGMAX (MSGSSZ*MSGSEG)
67 #define MSGMNB 2048 /* max # of bytes in a queue */
77 * Based on the configuration parameters described in an SVR2 (yes, two)
78 * config(1m) man page.
80 * Each message is broken up and stored in segments that are msgssz bytes
81 * long. For efficiency reasons, this should be a power of two. Also,
82 * it doesn't make sense if it is less than 8 or greater than about 256.
83 * Consequently, msginit in kern/sysv_msg.c checks that msgssz is a power of
84 * two between 8 and 1024 inclusive (and panic's if it isn't).
86 struct msginfo msginfo = {
87 MSGMAX, /* max chars in a message */
88 MSGMNI, /* # of message queue identifiers */
89 MSGMNB, /* max chars in a queue */
90 MSGTQL, /* max messages in system */
91 MSGSSZ, /* size of a message segment */
92 /* (must be small power of 2 greater than 4) */
93 MSGSEG /* number of message segments */
97 * macros to convert between msqid_ds's and msqid's.
98 * (specific to this implementation)
100 #define MSQID(ix,ds) ((ix) & 0xffff | (((ds).msg_perm.seq << 16) & 0xffff0000))
101 #define MSQID_IX(id) ((id) & 0xffff)
102 #define MSQID_SEQ(id) (((id) >> 16) & 0xffff)
105 * The rest of this file is specific to this particular implementation.
109 short next; /* next segment in buffer */
110 /* -1 -> available */
111 /* 0..(MSGSEG-1) -> index of next segment */
114 #define MSG_LOCKED 01000 /* Is this msqid_ds locked? */
116 static int nfree_msgmaps; /* # of free map entries */
117 static short free_msgmaps; /* head of linked list of free map entries */
118 static struct msg *free_msghdrs;/* list of free msg headers */
119 static char *msgpool; /* MSGMAX byte long msg buffer pool */
120 static struct msgmap *msgmaps; /* MSGSEG msgmap structures */
121 static struct msg *msghdrs; /* MSGTQL msg headers */
122 static struct msqid_ds *msqids; /* MSGMNI msqid_ds struct's */
130 msgpool = malloc(msginfo.msgmax, M_MSG, M_WAITOK);
132 panic("msgpool is NULL");
133 msgmaps = malloc(sizeof(struct msgmap) * msginfo.msgseg, M_MSG, M_WAITOK);
135 panic("msgmaps is NULL");
136 msghdrs = malloc(sizeof(struct msg) * msginfo.msgtql, M_MSG, M_WAITOK);
138 panic("msghdrs is NULL");
139 msqids = malloc(sizeof(struct msqid_ds) * msginfo.msgmni, M_MSG, M_WAITOK);
141 panic("msqids is NULL");
144 * msginfo.msgssz should be a power of two for efficiency reasons.
145 * It is also pretty silly if msginfo.msgssz is less than 8
146 * or greater than about 256 so ...
150 while (i < 1024 && i != msginfo.msgssz)
152 if (i != msginfo.msgssz) {
153 printf("msginfo.msgssz=%d (0x%x)\n", msginfo.msgssz,
155 panic("msginfo.msgssz not a small power of 2");
158 if (msginfo.msgseg > 32767) {
159 printf("msginfo.msgseg=%d\n", msginfo.msgseg);
160 panic("msginfo.msgseg > 32767");
164 panic("msgmaps is NULL");
166 for (i = 0; i < msginfo.msgseg; i++) {
168 msgmaps[i-1].next = i;
169 msgmaps[i].next = -1; /* implies entry is available */
172 nfree_msgmaps = msginfo.msgseg;
175 panic("msghdrs is NULL");
177 for (i = 0; i < msginfo.msgtql; i++) {
178 msghdrs[i].msg_type = 0;
180 msghdrs[i-1].msg_next = &msghdrs[i];
181 msghdrs[i].msg_next = NULL;
183 free_msghdrs = &msghdrs[0];
186 panic("msqids is NULL");
188 for (i = 0; i < msginfo.msgmni; i++) {
189 msqids[i].msg_qbytes = 0; /* implies entry is available */
190 msqids[i].msg_perm.seq = 0; /* reset to a known value */
193 SYSINIT(sysv_msg, SI_SUB_SYSV_MSG, SI_ORDER_FIRST, msginit, NULL)
196 * Entry point for all MSG calls
201 /* XXX actually varargs. */
202 struct msgsys_args /* {
212 if (uap->which >= sizeof(msgcalls)/sizeof(msgcalls[0]))
214 return ((*msgcalls[uap->which])(p, &uap->a2));
221 while (msghdr->msg_ts > 0) {
223 if (msghdr->msg_spot < 0 || msghdr->msg_spot >= msginfo.msgseg)
224 panic("msghdr->msg_spot out of range");
225 next = msgmaps[msghdr->msg_spot].next;
226 msgmaps[msghdr->msg_spot].next = free_msgmaps;
227 free_msgmaps = msghdr->msg_spot;
229 msghdr->msg_spot = next;
230 if (msghdr->msg_ts >= msginfo.msgssz)
231 msghdr->msg_ts -= msginfo.msgssz;
235 if (msghdr->msg_spot != -1)
236 panic("msghdr->msg_spot != -1");
237 msghdr->msg_next = free_msghdrs;
238 free_msghdrs = msghdr;
241 #ifndef _SYS_SYSPROTO_H_
245 struct msqid_ds *buf;
252 register struct msgctl_args *uap;
254 int msqid = uap->msqid;
256 struct msqid_ds *user_msqptr = uap->buf;
258 struct msqid_ds msqbuf;
259 register struct msqid_ds *msqptr;
262 printf("call to msgctl(%d, %d, 0x%x)\n", msqid, cmd, user_msqptr);
265 msqid = IPCID_TO_IX(msqid);
267 if (msqid < 0 || msqid >= msginfo.msgmni) {
269 printf("msqid (%d) out of range (0<=msqid<%d)\n", msqid,
275 msqptr = &msqids[msqid];
277 if (msqptr->msg_qbytes == 0) {
279 printf("no such msqid\n");
283 if (msqptr->msg_perm.seq != IPCID_TO_SEQ(uap->msqid)) {
285 printf("wrong sequence number\n");
298 if ((eval = ipcperm(p, &msqptr->msg_perm, IPC_M)))
300 /* Free the message headers */
301 msghdr = msqptr->msg_first;
302 while (msghdr != NULL) {
303 struct msg *msghdr_tmp;
305 /* Free the segments of each message */
306 msqptr->msg_cbytes -= msghdr->msg_ts;
309 msghdr = msghdr->msg_next;
310 msg_freehdr(msghdr_tmp);
313 if (msqptr->msg_cbytes != 0)
314 panic("msg_cbytes is screwed up");
315 if (msqptr->msg_qnum != 0)
316 panic("msg_qnum is screwed up");
318 msqptr->msg_qbytes = 0; /* Mark it as free */
320 wakeup((caddr_t)msqptr);
326 if ((eval = ipcperm(p, &msqptr->msg_perm, IPC_M)))
328 if ((eval = copyin(user_msqptr, &msqbuf, sizeof(msqbuf))) != 0)
330 if (msqbuf.msg_qbytes > msqptr->msg_qbytes) {
335 if (msqbuf.msg_qbytes > msginfo.msgmnb) {
337 printf("can't increase msg_qbytes beyond %d (truncating)\n",
340 msqbuf.msg_qbytes = msginfo.msgmnb; /* silently restrict qbytes to system limit */
342 if (msqbuf.msg_qbytes == 0) {
344 printf("can't reduce msg_qbytes to 0\n");
346 return(EINVAL); /* non-standard errno! */
348 msqptr->msg_perm.uid = msqbuf.msg_perm.uid; /* change the owner */
349 msqptr->msg_perm.gid = msqbuf.msg_perm.gid; /* change the owner */
350 msqptr->msg_perm.mode = (msqptr->msg_perm.mode & ~0777) |
351 (msqbuf.msg_perm.mode & 0777);
352 msqptr->msg_qbytes = msqbuf.msg_qbytes;
353 msqptr->msg_ctime = time_second;
357 if ((eval = ipcperm(p, &msqptr->msg_perm, IPC_R))) {
359 printf("requester doesn't have read access\n");
363 eval = copyout((caddr_t)msqptr, user_msqptr,
364 sizeof(struct msqid_ds));
369 printf("invalid command %d\n", cmd);
375 p->p_retval[0] = rval;
379 #ifndef _SYS_SYSPROTO_H_
389 register struct msgget_args *uap;
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 (key != IPC_PRIVATE) {
402 for (msqid = 0; msqid < msginfo.msgmni; msqid++) {
403 msqptr = &msqids[msqid];
404 if (msqptr->msg_qbytes != 0 &&
405 msqptr->msg_perm.key == key)
408 if (msqid < msginfo.msgmni) {
410 printf("found public key\n");
412 if ((msgflg & IPC_CREAT) && (msgflg & IPC_EXCL)) {
414 printf("not exclusive\n");
418 if ((eval = ipcperm(p, &msqptr->msg_perm, msgflg & 0700 ))) {
420 printf("requester doesn't have 0%o access\n",
430 printf("need to allocate the msqid_ds\n");
432 if (key == IPC_PRIVATE || (msgflg & IPC_CREAT)) {
433 for (msqid = 0; msqid < msginfo.msgmni; msqid++) {
435 * Look for an unallocated and unlocked msqid_ds.
436 * msqid_ds's can be locked by msgsnd or msgrcv while
437 * they are copying the message in/out. We can't
438 * re-use the entry until they release it.
440 msqptr = &msqids[msqid];
441 if (msqptr->msg_qbytes == 0 &&
442 (msqptr->msg_perm.mode & MSG_LOCKED) == 0)
445 if (msqid == msginfo.msgmni) {
447 printf("no more msqid_ds's available\n");
452 printf("msqid %d is available\n", msqid);
454 msqptr->msg_perm.key = key;
455 msqptr->msg_perm.cuid = cred->cr_uid;
456 msqptr->msg_perm.uid = cred->cr_uid;
457 msqptr->msg_perm.cgid = cred->cr_gid;
458 msqptr->msg_perm.gid = cred->cr_gid;
459 msqptr->msg_perm.mode = (msgflg & 0777);
460 /* Make sure that the returned msqid is unique */
461 msqptr->msg_perm.seq++;
462 msqptr->msg_first = NULL;
463 msqptr->msg_last = NULL;
464 msqptr->msg_cbytes = 0;
465 msqptr->msg_qnum = 0;
466 msqptr->msg_qbytes = msginfo.msgmnb;
467 msqptr->msg_lspid = 0;
468 msqptr->msg_lrpid = 0;
469 msqptr->msg_stime = 0;
470 msqptr->msg_rtime = 0;
471 msqptr->msg_ctime = time_second;
474 printf("didn't find it and wasn't asked to create it\n");
480 /* Construct the unique msqid */
481 p->p_retval[0] = IXSEQ_TO_IPCID(msqid, msqptr->msg_perm);
485 #ifndef _SYS_SYSPROTO_H_
497 register struct msgsnd_args *uap;
499 int msqid = uap->msqid;
500 void *user_msgp = uap->msgp;
501 size_t msgsz = uap->msgsz;
502 int msgflg = uap->msgflg;
503 int segs_needed, eval;
504 register struct msqid_ds *msqptr;
505 register struct msg *msghdr;
509 printf("call to msgsnd(%d, 0x%x, %d, %d)\n", msqid, user_msgp, msgsz,
513 msqid = IPCID_TO_IX(msqid);
515 if (msqid < 0 || msqid >= msginfo.msgmni) {
517 printf("msqid (%d) out of range (0<=msqid<%d)\n", msqid,
523 msqptr = &msqids[msqid];
524 if (msqptr->msg_qbytes == 0) {
526 printf("no such message queue id\n");
530 if (msqptr->msg_perm.seq != IPCID_TO_SEQ(uap->msqid)) {
532 printf("wrong sequence number\n");
537 if ((eval = ipcperm(p, &msqptr->msg_perm, IPC_W))) {
539 printf("requester doesn't have write access\n");
544 segs_needed = (msgsz + msginfo.msgssz - 1) / msginfo.msgssz;
546 printf("msgsz=%d, msgssz=%d, segs_needed=%d\n", msgsz, msginfo.msgssz,
550 int need_more_resources = 0;
554 * (inside this loop in case msg_qbytes changes while we sleep)
557 if (msgsz > msqptr->msg_qbytes) {
559 printf("msgsz > msqptr->msg_qbytes\n");
564 if (msqptr->msg_perm.mode & MSG_LOCKED) {
566 printf("msqid is locked\n");
568 need_more_resources = 1;
570 if (msgsz + msqptr->msg_cbytes > msqptr->msg_qbytes) {
572 printf("msgsz + msg_cbytes > msg_qbytes\n");
574 need_more_resources = 1;
576 if (segs_needed > nfree_msgmaps) {
578 printf("segs_needed > nfree_msgmaps\n");
580 need_more_resources = 1;
582 if (free_msghdrs == NULL) {
584 printf("no more msghdrs\n");
586 need_more_resources = 1;
589 if (need_more_resources) {
592 if ((msgflg & IPC_NOWAIT) != 0) {
594 printf("need more resources but caller doesn't want to wait\n");
599 if ((msqptr->msg_perm.mode & MSG_LOCKED) != 0) {
601 printf("we don't own the msqid_ds\n");
605 /* Force later arrivals to wait for our
608 printf("we own the msqid_ds\n");
610 msqptr->msg_perm.mode |= MSG_LOCKED;
614 printf("goodnight\n");
616 eval = tsleep((caddr_t)msqptr, (PZERO - 4) | PCATCH,
619 printf("good morning, eval=%d\n", eval);
622 msqptr->msg_perm.mode &= ~MSG_LOCKED;
625 printf("msgsnd: interrupted system call\n");
631 * Make sure that the msq queue still exists
634 if (msqptr->msg_qbytes == 0) {
636 printf("msqid deleted\n");
643 printf("got all the resources that we need\n");
650 * We have the resources that we need.
654 if (msqptr->msg_perm.mode & MSG_LOCKED)
655 panic("msg_perm.mode & MSG_LOCKED");
656 if (segs_needed > nfree_msgmaps)
657 panic("segs_needed > nfree_msgmaps");
658 if (msgsz + msqptr->msg_cbytes > msqptr->msg_qbytes)
659 panic("msgsz + msg_cbytes > msg_qbytes");
660 if (free_msghdrs == NULL)
661 panic("no more msghdrs");
664 * Re-lock the msqid_ds in case we page-fault when copying in the
668 if ((msqptr->msg_perm.mode & MSG_LOCKED) != 0)
669 panic("msqid_ds is already locked");
670 msqptr->msg_perm.mode |= MSG_LOCKED;
673 * Allocate a message header
676 msghdr = free_msghdrs;
677 free_msghdrs = msghdr->msg_next;
678 msghdr->msg_spot = -1;
679 msghdr->msg_ts = msgsz;
682 * Allocate space for the message
685 while (segs_needed > 0) {
686 if (nfree_msgmaps <= 0)
687 panic("not enough msgmaps");
688 if (free_msgmaps == -1)
689 panic("nil free_msgmaps");
692 panic("next too low #1");
693 if (next >= msginfo.msgseg)
694 panic("next out of range #1");
696 printf("allocating segment %d to message\n", next);
698 free_msgmaps = msgmaps[next].next;
700 msgmaps[next].next = msghdr->msg_spot;
701 msghdr->msg_spot = next;
706 * Copy in the message type
709 if ((eval = copyin(user_msgp, &msghdr->msg_type,
710 sizeof(msghdr->msg_type))) != 0) {
712 printf("error %d copying the message type\n", eval);
715 msqptr->msg_perm.mode &= ~MSG_LOCKED;
716 wakeup((caddr_t)msqptr);
719 user_msgp = (char *)user_msgp + sizeof(msghdr->msg_type);
722 * Validate the message type
725 if (msghdr->msg_type < 1) {
727 msqptr->msg_perm.mode &= ~MSG_LOCKED;
728 wakeup((caddr_t)msqptr);
730 printf("mtype (%d) < 1\n", msghdr->msg_type);
736 * Copy in the message body
739 next = msghdr->msg_spot;
742 if (msgsz > msginfo.msgssz)
743 tlen = msginfo.msgssz;
747 panic("next too low #2");
748 if (next >= msginfo.msgseg)
749 panic("next out of range #2");
750 if ((eval = copyin(user_msgp, &msgpool[next * msginfo.msgssz],
753 printf("error %d copying in message segment\n", eval);
756 msqptr->msg_perm.mode &= ~MSG_LOCKED;
757 wakeup((caddr_t)msqptr);
761 user_msgp = (char *)user_msgp + tlen;
762 next = msgmaps[next].next;
765 panic("didn't use all the msg segments");
768 * We've got the message. Unlock the msqid_ds.
771 msqptr->msg_perm.mode &= ~MSG_LOCKED;
774 * Make sure that the msqid_ds is still allocated.
777 if (msqptr->msg_qbytes == 0) {
779 wakeup((caddr_t)msqptr);
784 * Put the message into the queue
787 if (msqptr->msg_first == NULL) {
788 msqptr->msg_first = msghdr;
789 msqptr->msg_last = msghdr;
791 msqptr->msg_last->msg_next = msghdr;
792 msqptr->msg_last = msghdr;
794 msqptr->msg_last->msg_next = NULL;
796 msqptr->msg_cbytes += msghdr->msg_ts;
798 msqptr->msg_lspid = p->p_pid;
799 msqptr->msg_stime = time_second;
801 wakeup((caddr_t)msqptr);
806 #ifndef _SYS_SYSPROTO_H_
819 register struct msgrcv_args *uap;
821 int msqid = uap->msqid;
822 void *user_msgp = uap->msgp;
823 size_t msgsz = uap->msgsz;
824 long msgtyp = uap->msgtyp;
825 int msgflg = uap->msgflg;
827 register struct msqid_ds *msqptr;
828 register struct msg *msghdr;
833 printf("call to msgrcv(%d, 0x%x, %d, %ld, %d)\n", msqid, user_msgp,
834 msgsz, msgtyp, msgflg);
837 msqid = IPCID_TO_IX(msqid);
839 if (msqid < 0 || msqid >= msginfo.msgmni) {
841 printf("msqid (%d) out of range (0<=msqid<%d)\n", msqid,
847 msqptr = &msqids[msqid];
848 if (msqptr->msg_qbytes == 0) {
850 printf("no such message queue id\n");
854 if (msqptr->msg_perm.seq != IPCID_TO_SEQ(uap->msqid)) {
856 printf("wrong sequence number\n");
861 if ((eval = ipcperm(p, &msqptr->msg_perm, IPC_R))) {
863 printf("requester doesn't have read access\n");
869 while (msghdr == NULL) {
871 msghdr = msqptr->msg_first;
872 if (msghdr != NULL) {
873 if (msgsz < msghdr->msg_ts &&
874 (msgflg & MSG_NOERROR) == 0) {
876 printf("first message on the queue is too big (want %d, got %d)\n",
877 msgsz, msghdr->msg_ts);
881 if (msqptr->msg_first == msqptr->msg_last) {
882 msqptr->msg_first = NULL;
883 msqptr->msg_last = NULL;
885 msqptr->msg_first = msghdr->msg_next;
886 if (msqptr->msg_first == NULL)
887 panic("msg_first/last screwed up #1");
891 struct msg *previous;
895 prev = &(msqptr->msg_first);
896 while ((msghdr = *prev) != NULL) {
898 * Is this message's type an exact match or is
899 * this message's type less than or equal to
900 * the absolute value of a negative msgtyp?
901 * Note that the second half of this test can
902 * NEVER be true if msgtyp is positive since
903 * msg_type is always positive!
906 if (msgtyp == msghdr->msg_type ||
907 msghdr->msg_type <= -msgtyp) {
909 printf("found message type %d, requested %d\n",
910 msghdr->msg_type, msgtyp);
912 if (msgsz < msghdr->msg_ts &&
913 (msgflg & MSG_NOERROR) == 0) {
915 printf("requested message on the queue is too big (want %d, got %d)\n",
916 msgsz, msghdr->msg_ts);
920 *prev = msghdr->msg_next;
921 if (msghdr == msqptr->msg_last) {
922 if (previous == NULL) {
925 panic("msg_first/last screwed up #2");
933 panic("msg_first/last screwed up #3");
941 prev = &(msghdr->msg_next);
946 * We've either extracted the msghdr for the appropriate
947 * message or there isn't one.
948 * If there is one then bail out of this loop.
955 * Hmph! No message found. Does the user want to wait?
958 if ((msgflg & IPC_NOWAIT) != 0) {
960 printf("no appropriate message found (msgtyp=%d)\n",
963 /* The SVID says to return ENOMSG. */
967 /* Unfortunately, BSD doesn't define that code yet! */
973 * Wait for something to happen
977 printf("msgrcv: goodnight\n");
979 eval = tsleep((caddr_t)msqptr, (PZERO - 4) | PCATCH, "msgwait",
982 printf("msgrcv: good morning (eval=%d)\n", eval);
987 printf("msgsnd: interrupted system call\n");
993 * Make sure that the msq queue still exists
996 if (msqptr->msg_qbytes == 0 ||
997 msqptr->msg_perm.seq != IPCID_TO_SEQ(uap->msqid)) {
999 printf("msqid deleted\n");
1006 * Return the message to the user.
1008 * First, do the bookkeeping (before we risk being interrupted).
1011 msqptr->msg_cbytes -= msghdr->msg_ts;
1013 msqptr->msg_lrpid = p->p_pid;
1014 msqptr->msg_rtime = time_second;
1017 * Make msgsz the actual amount that we'll be returning.
1018 * Note that this effectively truncates the message if it is too long
1019 * (since msgsz is never increased).
1023 printf("found a message, msgsz=%d, msg_ts=%d\n", msgsz,
1026 if (msgsz > msghdr->msg_ts)
1027 msgsz = msghdr->msg_ts;
1030 * Return the type to the user.
1033 eval = copyout((caddr_t)&(msghdr->msg_type), user_msgp,
1034 sizeof(msghdr->msg_type));
1037 printf("error (%d) copying out message type\n", eval);
1039 msg_freehdr(msghdr);
1040 wakeup((caddr_t)msqptr);
1043 user_msgp = (char *)user_msgp + sizeof(msghdr->msg_type);
1046 * Return the segments to the user
1049 next = msghdr->msg_spot;
1050 for (len = 0; len < msgsz; len += msginfo.msgssz) {
1053 if (msgsz - len > msginfo.msgssz)
1054 tlen = msginfo.msgssz;
1058 panic("next too low #3");
1059 if (next >= msginfo.msgseg)
1060 panic("next out of range #3");
1061 eval = copyout((caddr_t)&msgpool[next * msginfo.msgssz],
1065 printf("error (%d) copying out message segment\n",
1068 msg_freehdr(msghdr);
1069 wakeup((caddr_t)msqptr);
1072 user_msgp = (char *)user_msgp + tlen;
1073 next = msgmaps[next].next;
1077 * Done, return the actual number of bytes copied out.
1080 msg_freehdr(msghdr);
1081 wakeup((caddr_t)msqptr);
1082 p->p_retval[0] = msgsz;