]>
git.saurik.com Git - apple/xnu.git/blob - bsd/kern/sysv_msg.c
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
23 * Implementation of SVID messages
25 * Author: Daniel Boulet
27 * Copyright 1993 Daniel Boulet and RTMX Inc.
29 * This system call was implemented by Daniel Boulet under contract from RTMX.
31 * Redistribution and use in source forms, with and without modification,
32 * are permitted provided that this entire comment appears intact.
34 * Redistribution in binary form may occur without any restrictions.
35 * Obviously, it would be nice if you gave credit where credit is due
36 * but requiring it would be too onerous.
38 * This software is provided ``AS IS'' without any warranties of any kind.
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/sysproto.h>
44 #include <sys/kernel.h>
47 #include <sys/sysent.h>
49 #include <bsm/audit_kernel.h>
51 static void msginit
__P((void *));
52 SYSINIT(sysv_msg
, SI_SUB_SYSV_MSG
, SI_ORDER_FIRST
, msginit
, NULL
)
57 #ifndef _SYS_SYSPROTO_H_
59 int msgctl
__P((struct proc
*p
, struct msgctl_args
*uap
));
61 int msgget
__P((struct proc
*p
, struct msgget_args
*uap
));
63 int msgsnd
__P((struct proc
*p
, struct msgsnd_args
*uap
));
65 int msgrcv
__P((struct proc
*p
, struct msgrcv_args
*uap
));
67 static void msg_freehdr
__P((struct msg
*msghdr
));
69 /* XXX casting to (sy_call_t *) is bogus, as usual. */
70 static sy_call_t
*msgcalls
[] = {
71 (sy_call_t
*)msgctl
, (sy_call_t
*)msgget
,
72 (sy_call_t
*)msgsnd
, (sy_call_t
*)msgrcv
75 static int nfree_msgmaps
; /* # of free map entries */
76 static short free_msgmaps
; /* head of linked list of free map entries */
77 static struct msg
*free_msghdrs
; /* list of free msg headers */
78 char *msgpool
; /* MSGMAX byte long msg buffer pool */
79 struct msgmap
*msgmaps
; /* MSGSEG msgmap structures */
80 struct msg
*msghdrs
; /* MSGTQL msg headers */
81 struct msqid_ds
*msqids
; /* MSGMNI msqid_ds struct's */
90 * msginfo.msgssz should be a power of two for efficiency reasons.
91 * It is also pretty silly if msginfo.msgssz is less than 8
92 * or greater than about 256 so ...
96 while (i
< 1024 && i
!= msginfo
.msgssz
)
98 if (i
!= msginfo
.msgssz
) {
99 printf("msginfo.msgssz=%d (0x%x)\n", msginfo
.msgssz
,
101 panic("msginfo.msgssz not a small power of 2");
104 if (msginfo
.msgseg
> 32767) {
105 printf("msginfo.msgseg=%d\n", msginfo
.msgseg
);
106 panic("msginfo.msgseg > 32767");
110 panic("msgmaps is NULL");
112 for (i
= 0; i
< msginfo
.msgseg
; i
++) {
114 msgmaps
[i
-1].next
= i
;
115 msgmaps
[i
].next
= -1; /* implies entry is available */
118 nfree_msgmaps
= msginfo
.msgseg
;
121 panic("msghdrs is NULL");
123 for (i
= 0; i
< msginfo
.msgtql
; i
++) {
124 msghdrs
[i
].msg_type
= 0;
126 msghdrs
[i
-1].msg_next
= &msghdrs
[i
];
127 msghdrs
[i
].msg_next
= NULL
;
129 free_msghdrs
= &msghdrs
[0];
132 panic("msqids is NULL");
134 for (i
= 0; i
< msginfo
.msgmni
; i
++) {
135 msqids
[i
].msg_qbytes
= 0; /* implies entry is available */
136 msqids
[i
].msg_perm
.seq
= 0; /* reset to a known value */
141 * Entry point for all MSG calls
146 /* XXX actually varargs. */
147 struct msgsys_args
/* {
157 if (uap
->which
>= sizeof(msgcalls
)/sizeof(msgcalls
[0]))
159 return ((*msgcalls
[uap
->which
])(p
, &uap
->a2
));
166 while (msghdr
->msg_ts
> 0) {
168 if (msghdr
->msg_spot
< 0 || msghdr
->msg_spot
>= msginfo
.msgseg
)
169 panic("msghdr->msg_spot out of range");
170 next
= msgmaps
[msghdr
->msg_spot
].next
;
171 msgmaps
[msghdr
->msg_spot
].next
= free_msgmaps
;
172 free_msgmaps
= msghdr
->msg_spot
;
174 msghdr
->msg_spot
= next
;
175 if (msghdr
->msg_ts
>= msginfo
.msgssz
)
176 msghdr
->msg_ts
-= msginfo
.msgssz
;
180 if (msghdr
->msg_spot
!= -1)
181 panic("msghdr->msg_spot != -1");
182 msghdr
->msg_next
= free_msghdrs
;
183 free_msghdrs
= msghdr
;
186 #ifndef _SYS_SYSPROTO_H_
190 struct msqid_ds
*buf
;
197 register struct msgctl_args
*uap
;
199 int msqid
= uap
->msqid
;
201 struct msqid_ds
*user_msqptr
= uap
->buf
;
202 struct ucred
*cred
= p
->p_ucred
;
204 struct msqid_ds msqbuf
;
205 register struct msqid_ds
*msqptr
;
208 printf("call to msgctl(%d, %d, 0x%x)\n", msqid
, cmd
, user_msqptr
);
211 AUDIT_ARG(svipc_cmd
, cmd
);
212 AUDIT_ARG(svipc_id
, msqid
);
213 msqid
= IPCID_TO_IX(msqid
);
215 if (msqid
< 0 || msqid
>= msginfo
.msgmni
) {
217 printf("msqid (%d) out of range (0<=msqid<%d)\n", msqid
,
223 msqptr
= &msqids
[msqid
];
225 if (msqptr
->msg_qbytes
== 0) {
227 printf("no such msqid\n");
231 if (msqptr
->msg_perm
.seq
!= IPCID_TO_SEQ(uap
->msqid
)) {
233 printf("wrong sequence number\n");
246 if ((eval
= ipcperm(cred
, &msqptr
->msg_perm
, IPC_M
)))
248 /* Free the message headers */
249 msghdr
= msqptr
->msg_first
;
250 while (msghdr
!= NULL
) {
251 struct msg
*msghdr_tmp
;
253 /* Free the segments of each message */
254 msqptr
->msg_cbytes
-= msghdr
->msg_ts
;
257 msghdr
= msghdr
->msg_next
;
258 msg_freehdr(msghdr_tmp
);
261 if (msqptr
->msg_cbytes
!= 0)
262 panic("msg_cbytes is messed up");
263 if (msqptr
->msg_qnum
!= 0)
264 panic("msg_qnum is messed up");
266 msqptr
->msg_qbytes
= 0; /* Mark it as free */
268 wakeup((caddr_t
)msqptr
);
274 if ((eval
= ipcperm(cred
, &msqptr
->msg_perm
, IPC_M
)))
276 if ((eval
= copyin(user_msqptr
, &msqbuf
, sizeof(msqbuf
))) != 0)
278 if (msqbuf
.msg_qbytes
> msqptr
->msg_qbytes
) {
279 eval
= suser(cred
, &p
->p_acflag
);
283 if (msqbuf
.msg_qbytes
> msginfo
.msgmnb
) {
285 printf("can't increase msg_qbytes beyond %d (truncating)\n",
288 msqbuf
.msg_qbytes
= msginfo
.msgmnb
; /* silently restrict qbytes to system limit */
290 if (msqbuf
.msg_qbytes
== 0) {
292 printf("can't reduce msg_qbytes to 0\n");
294 return(EINVAL
); /* non-standard errno! */
296 msqptr
->msg_perm
.uid
= msqbuf
.msg_perm
.uid
; /* change the owner */
297 msqptr
->msg_perm
.gid
= msqbuf
.msg_perm
.gid
; /* change the owner */
298 msqptr
->msg_perm
.mode
= (msqptr
->msg_perm
.mode
& ~0777) |
299 (msqbuf
.msg_perm
.mode
& 0777);
300 msqptr
->msg_qbytes
= msqbuf
.msg_qbytes
;
301 msqptr
->msg_ctime
= time_second
;
305 if ((eval
= ipcperm(cred
, &msqptr
->msg_perm
, IPC_R
))) {
307 printf("requester doesn't have read access\n");
311 eval
= copyout((caddr_t
)msqptr
, user_msqptr
,
312 sizeof(struct msqid_ds
));
317 printf("invalid command %d\n", cmd
);
323 p
->p_retval
[0] = rval
;
327 #ifndef _SYS_SYSPROTO_H_
337 register struct msgget_args
*uap
;
341 int msgflg
= uap
->msgflg
;
342 struct ucred
*cred
= p
->p_ucred
;
343 register struct msqid_ds
*msqptr
= NULL
;
346 printf("msgget(0x%x, 0%o)\n", key
, msgflg
);
349 if (key
!= IPC_PRIVATE
) {
350 for (msqid
= 0; msqid
< msginfo
.msgmni
; msqid
++) {
351 msqptr
= &msqids
[msqid
];
352 if (msqptr
->msg_qbytes
!= 0 &&
353 msqptr
->msg_perm
.key
== key
)
356 if (msqid
< msginfo
.msgmni
) {
358 printf("found public key\n");
360 if ((msgflg
& IPC_CREAT
) && (msgflg
& IPC_EXCL
)) {
362 printf("not exclusive\n");
366 if ((eval
= ipcperm(cred
, &msqptr
->msg_perm
, msgflg
& 0700 ))) {
368 printf("requester doesn't have 0%o access\n",
378 printf("need to allocate the msqid_ds\n");
380 if (key
== IPC_PRIVATE
|| (msgflg
& IPC_CREAT
)) {
381 for (msqid
= 0; msqid
< msginfo
.msgmni
; msqid
++) {
383 * Look for an unallocated and unlocked msqid_ds.
384 * msqid_ds's can be locked by msgsnd or msgrcv while
385 * they are copying the message in/out. We can't
386 * re-use the entry until they release it.
388 msqptr
= &msqids
[msqid
];
389 if (msqptr
->msg_qbytes
== 0 &&
390 (msqptr
->msg_perm
.mode
& MSG_LOCKED
) == 0)
393 if (msqid
== msginfo
.msgmni
) {
395 printf("no more msqid_ds's available\n");
400 printf("msqid %d is available\n", msqid
);
402 msqptr
->msg_perm
.key
= key
;
403 msqptr
->msg_perm
.cuid
= cred
->cr_uid
;
404 msqptr
->msg_perm
.uid
= cred
->cr_uid
;
405 msqptr
->msg_perm
.cgid
= cred
->cr_gid
;
406 msqptr
->msg_perm
.gid
= cred
->cr_gid
;
407 msqptr
->msg_perm
.mode
= (msgflg
& 0777);
408 /* Make sure that the returned msqid is unique */
409 msqptr
->msg_perm
.seq
++;
410 msqptr
->msg_first
= NULL
;
411 msqptr
->msg_last
= NULL
;
412 msqptr
->msg_cbytes
= 0;
413 msqptr
->msg_qnum
= 0;
414 msqptr
->msg_qbytes
= msginfo
.msgmnb
;
415 msqptr
->msg_lspid
= 0;
416 msqptr
->msg_lrpid
= 0;
417 msqptr
->msg_stime
= 0;
418 msqptr
->msg_rtime
= 0;
419 msqptr
->msg_ctime
= time_second
;
422 printf("didn't find it and wasn't asked to create it\n");
428 /* Construct the unique msqid */
429 p
->p_retval
[0] = IXSEQ_TO_IPCID(msqid
, msqptr
->msg_perm
);
430 AUDIT_ARG(svipc_id
, p
->p_retval
[0]);
434 #ifndef _SYS_SYSPROTO_H_
446 register struct msgsnd_args
*uap
;
448 int msqid
= uap
->msqid
;
449 void *user_msgp
= uap
->msgp
;
450 size_t msgsz
= uap
->msgsz
;
451 int msgflg
= uap
->msgflg
;
452 int segs_needed
, eval
;
453 struct ucred
*cred
= p
->p_ucred
;
454 register struct msqid_ds
*msqptr
;
455 register struct msg
*msghdr
;
459 printf("call to msgsnd(%d, 0x%x, %d, %d)\n", msqid
, user_msgp
, msgsz
,
463 AUDIT_ARG(svipc_id
, msqid
);
464 msqid
= IPCID_TO_IX(msqid
);
466 if (msqid
< 0 || msqid
>= msginfo
.msgmni
) {
468 printf("msqid (%d) out of range (0<=msqid<%d)\n", msqid
,
474 msqptr
= &msqids
[msqid
];
475 if (msqptr
->msg_qbytes
== 0) {
477 printf("no such message queue id\n");
481 if (msqptr
->msg_perm
.seq
!= IPCID_TO_SEQ(uap
->msqid
)) {
483 printf("wrong sequence number\n");
488 if ((eval
= ipcperm(cred
, &msqptr
->msg_perm
, IPC_W
))) {
490 printf("requester doesn't have write access\n");
495 segs_needed
= (msgsz
+ msginfo
.msgssz
- 1) / msginfo
.msgssz
;
497 printf("msgsz=%d, msgssz=%d, segs_needed=%d\n", msgsz
, msginfo
.msgssz
,
501 int need_more_resources
= 0;
505 * (inside this loop in case msg_qbytes changes while we sleep)
508 if (msgsz
> msqptr
->msg_qbytes
) {
510 printf("msgsz > msqptr->msg_qbytes\n");
515 if (msqptr
->msg_perm
.mode
& MSG_LOCKED
) {
517 printf("msqid is locked\n");
519 need_more_resources
= 1;
521 if (msgsz
+ msqptr
->msg_cbytes
> msqptr
->msg_qbytes
) {
523 printf("msgsz + msg_cbytes > msg_qbytes\n");
525 need_more_resources
= 1;
527 if (segs_needed
> nfree_msgmaps
) {
529 printf("segs_needed > nfree_msgmaps\n");
531 need_more_resources
= 1;
533 if (free_msghdrs
== NULL
) {
535 printf("no more msghdrs\n");
537 need_more_resources
= 1;
540 if (need_more_resources
) {
543 if ((msgflg
& IPC_NOWAIT
) != 0) {
545 printf("need more resources but caller doesn't want to wait\n");
550 if ((msqptr
->msg_perm
.mode
& MSG_LOCKED
) != 0) {
552 printf("we don't own the msqid_ds\n");
556 /* Force later arrivals to wait for our
559 printf("we own the msqid_ds\n");
561 msqptr
->msg_perm
.mode
|= MSG_LOCKED
;
565 printf("goodnight\n");
567 eval
= tsleep((caddr_t
)msqptr
, (PZERO
- 4) | PCATCH
,
570 printf("good morning, eval=%d\n", eval
);
573 msqptr
->msg_perm
.mode
&= ~MSG_LOCKED
;
576 printf("msgsnd: interrupted system call\n");
582 * Make sure that the msq queue still exists
585 if (msqptr
->msg_qbytes
== 0) {
587 printf("msqid deleted\n");
589 /* The SVID says to return EIDRM. */
593 /* Unfortunately, BSD doesn't define that code
601 printf("got all the resources that we need\n");
608 * We have the resources that we need.
612 if (msqptr
->msg_perm
.mode
& MSG_LOCKED
)
613 panic("msg_perm.mode & MSG_LOCKED");
614 if (segs_needed
> nfree_msgmaps
)
615 panic("segs_needed > nfree_msgmaps");
616 if (msgsz
+ msqptr
->msg_cbytes
> msqptr
->msg_qbytes
)
617 panic("msgsz + msg_cbytes > msg_qbytes");
618 if (free_msghdrs
== NULL
)
619 panic("no more msghdrs");
622 * Re-lock the msqid_ds in case we page-fault when copying in the
626 if ((msqptr
->msg_perm
.mode
& MSG_LOCKED
) != 0)
627 panic("msqid_ds is already locked");
628 msqptr
->msg_perm
.mode
|= MSG_LOCKED
;
631 * Allocate a message header
634 msghdr
= free_msghdrs
;
635 free_msghdrs
= msghdr
->msg_next
;
636 msghdr
->msg_spot
= -1;
637 msghdr
->msg_ts
= msgsz
;
640 * Allocate space for the message
643 while (segs_needed
> 0) {
644 if (nfree_msgmaps
<= 0)
645 panic("not enough msgmaps");
646 if (free_msgmaps
== -1)
647 panic("nil free_msgmaps");
650 panic("next too low #1");
651 if (next
>= msginfo
.msgseg
)
652 panic("next out of range #1");
654 printf("allocating segment %d to message\n", next
);
656 free_msgmaps
= msgmaps
[next
].next
;
658 msgmaps
[next
].next
= msghdr
->msg_spot
;
659 msghdr
->msg_spot
= next
;
664 * Copy in the message type
667 if ((eval
= copyin(user_msgp
, &msghdr
->msg_type
,
668 sizeof(msghdr
->msg_type
))) != 0) {
670 printf("error %d copying the message type\n", eval
);
673 msqptr
->msg_perm
.mode
&= ~MSG_LOCKED
;
674 wakeup((caddr_t
)msqptr
);
677 user_msgp
= (char *)user_msgp
+ sizeof(msghdr
->msg_type
);
680 * Validate the message type
683 if (msghdr
->msg_type
< 1) {
685 msqptr
->msg_perm
.mode
&= ~MSG_LOCKED
;
686 wakeup((caddr_t
)msqptr
);
688 printf("mtype (%d) < 1\n", msghdr
->msg_type
);
694 * Copy in the message body
697 next
= msghdr
->msg_spot
;
700 if (msgsz
> msginfo
.msgssz
)
701 tlen
= msginfo
.msgssz
;
705 panic("next too low #2");
706 if (next
>= msginfo
.msgseg
)
707 panic("next out of range #2");
708 if ((eval
= copyin(user_msgp
, &msgpool
[next
* msginfo
.msgssz
],
711 printf("error %d copying in message segment\n", eval
);
714 msqptr
->msg_perm
.mode
&= ~MSG_LOCKED
;
715 wakeup((caddr_t
)msqptr
);
719 user_msgp
= (char *)user_msgp
+ tlen
;
720 next
= msgmaps
[next
].next
;
723 panic("didn't use all the msg segments");
726 * We've got the message. Unlock the msqid_ds.
729 msqptr
->msg_perm
.mode
&= ~MSG_LOCKED
;
732 * Make sure that the msqid_ds is still allocated.
735 if (msqptr
->msg_qbytes
== 0) {
737 wakeup((caddr_t
)msqptr
);
738 /* The SVID says to return EIDRM. */
742 /* Unfortunately, BSD doesn't define that code yet! */
748 * Put the message into the queue
751 if (msqptr
->msg_first
== NULL
) {
752 msqptr
->msg_first
= msghdr
;
753 msqptr
->msg_last
= msghdr
;
755 msqptr
->msg_last
->msg_next
= msghdr
;
756 msqptr
->msg_last
= msghdr
;
758 msqptr
->msg_last
->msg_next
= NULL
;
760 msqptr
->msg_cbytes
+= msghdr
->msg_ts
;
762 msqptr
->msg_lspid
= p
->p_pid
;
763 msqptr
->msg_stime
= time_second
;
765 wakeup((caddr_t
)msqptr
);
770 #ifndef _SYS_SYSPROTO_H_
783 register struct msgrcv_args
*uap
;
785 int msqid
= uap
->msqid
;
786 void *user_msgp
= uap
->msgp
;
787 size_t msgsz
= uap
->msgsz
;
788 long msgtyp
= uap
->msgtyp
;
789 int msgflg
= uap
->msgflg
;
791 struct ucred
*cred
= p
->p_ucred
;
792 register struct msqid_ds
*msqptr
;
793 register struct msg
*msghdr
;
798 printf("call to msgrcv(%d, 0x%x, %d, %ld, %d)\n", msqid
, user_msgp
,
799 msgsz
, msgtyp
, msgflg
);
802 AUDIT_ARG(svipc_id
, msqid
);
803 msqid
= IPCID_TO_IX(msqid
);
805 if (msqid
< 0 || msqid
>= msginfo
.msgmni
) {
807 printf("msqid (%d) out of range (0<=msqid<%d)\n", msqid
,
813 msqptr
= &msqids
[msqid
];
814 if (msqptr
->msg_qbytes
== 0) {
816 printf("no such message queue id\n");
820 if (msqptr
->msg_perm
.seq
!= IPCID_TO_SEQ(uap
->msqid
)) {
822 printf("wrong sequence number\n");
827 if ((eval
= ipcperm(cred
, &msqptr
->msg_perm
, IPC_R
))) {
829 printf("requester doesn't have read access\n");
835 while (msghdr
== NULL
) {
837 msghdr
= msqptr
->msg_first
;
838 if (msghdr
!= NULL
) {
839 if (msgsz
< msghdr
->msg_ts
&&
840 (msgflg
& MSG_NOERROR
) == 0) {
842 printf("first message on the queue is too big (want %d, got %d)\n",
843 msgsz
, msghdr
->msg_ts
);
847 if (msqptr
->msg_first
== msqptr
->msg_last
) {
848 msqptr
->msg_first
= NULL
;
849 msqptr
->msg_last
= NULL
;
851 msqptr
->msg_first
= msghdr
->msg_next
;
852 if (msqptr
->msg_first
== NULL
)
853 panic("msg_first/last messed up #1");
857 struct msg
*previous
;
861 prev
= &(msqptr
->msg_first
);
862 while ((msghdr
= *prev
) != NULL
) {
864 * Is this message's type an exact match or is
865 * this message's type less than or equal to
866 * the absolute value of a negative msgtyp?
867 * Note that the second half of this test can
868 * NEVER be true if msgtyp is positive since
869 * msg_type is always positive!
872 if (msgtyp
== msghdr
->msg_type
||
873 msghdr
->msg_type
<= -msgtyp
) {
875 printf("found message type %d, requested %d\n",
876 msghdr
->msg_type
, msgtyp
);
878 if (msgsz
< msghdr
->msg_ts
&&
879 (msgflg
& MSG_NOERROR
) == 0) {
881 printf("requested message on the queue is too big (want %d, got %d)\n",
882 msgsz
, msghdr
->msg_ts
);
886 *prev
= msghdr
->msg_next
;
887 if (msghdr
== msqptr
->msg_last
) {
888 if (previous
== NULL
) {
891 panic("msg_first/last messed up #2");
899 panic("msg_first/last messed up #3");
907 prev
= &(msghdr
->msg_next
);
912 * We've either extracted the msghdr for the appropriate
913 * message or there isn't one.
914 * If there is one then bail out of this loop.
921 * Hmph! No message found. Does the user want to wait?
924 if ((msgflg
& IPC_NOWAIT
) != 0) {
926 printf("no appropriate message found (msgtyp=%d)\n",
929 /* The SVID says to return ENOMSG. */
933 /* Unfortunately, BSD doesn't define that code yet! */
939 * Wait for something to happen
943 printf("msgrcv: goodnight\n");
945 eval
= tsleep((caddr_t
)msqptr
, (PZERO
- 4) | PCATCH
, "msgwait",
948 printf("msgrcv: good morning (eval=%d)\n", eval
);
953 printf("msgsnd: interrupted system call\n");
959 * Make sure that the msq queue still exists
962 if (msqptr
->msg_qbytes
== 0 ||
963 msqptr
->msg_perm
.seq
!= IPCID_TO_SEQ(uap
->msqid
)) {
965 printf("msqid deleted\n");
967 /* The SVID says to return EIDRM. */
971 /* Unfortunately, BSD doesn't define that code yet! */
978 * Return the message to the user.
980 * First, do the bookkeeping (before we risk being interrupted).
983 msqptr
->msg_cbytes
-= msghdr
->msg_ts
;
985 msqptr
->msg_lrpid
= p
->p_pid
;
986 msqptr
->msg_rtime
= time_second
;
989 * Make msgsz the actual amount that we'll be returning.
990 * Note that this effectively truncates the message if it is too long
991 * (since msgsz is never increased).
995 printf("found a message, msgsz=%d, msg_ts=%d\n", msgsz
,
998 if (msgsz
> msghdr
->msg_ts
)
999 msgsz
= msghdr
->msg_ts
;
1002 * Return the type to the user.
1005 eval
= copyout((caddr_t
)&(msghdr
->msg_type
), user_msgp
,
1006 sizeof(msghdr
->msg_type
));
1009 printf("error (%d) copying out message type\n", eval
);
1011 msg_freehdr(msghdr
);
1012 wakeup((caddr_t
)msqptr
);
1015 user_msgp
= (char *)user_msgp
+ sizeof(msghdr
->msg_type
);
1018 * Return the segments to the user
1021 next
= msghdr
->msg_spot
;
1022 for (len
= 0; len
< msgsz
; len
+= msginfo
.msgssz
) {
1025 if (msgsz
> msginfo
.msgssz
)
1026 tlen
= msginfo
.msgssz
;
1030 panic("next too low #3");
1031 if (next
>= msginfo
.msgseg
)
1032 panic("next out of range #3");
1033 eval
= copyout((caddr_t
)&msgpool
[next
* msginfo
.msgssz
],
1037 printf("error (%d) copying out message segment\n",
1040 msg_freehdr(msghdr
);
1041 wakeup((caddr_t
)msqptr
);
1044 user_msgp
= (char *)user_msgp
+ tlen
;
1045 next
= msgmaps
[next
].next
;
1049 * Done, return the actual number of bytes copied out.
1052 msg_freehdr(msghdr
);
1053 wakeup((caddr_t
)msqptr
);
1054 p
->p_retval
[0] = msgsz
;