50 #include <sys/cdefs.h>
53 #include "opt_compat.h"
54 #include "opt_sysvipc.h"
56 #include <sys/param.h>
57 #include <sys/systm.h>
58 #include <sys/sysproto.h>
59 #include <sys/kernel.h>
63 #include <sys/mutex.h>
64 #include <sys/module.h>
66 #include <sys/racct.h>
67 #include <sys/syscall.h>
68 #include <sys/syscallsubr.h>
69 #include <sys/sysent.h>
70 #include <sys/sysctl.h>
71 #include <sys/malloc.h>
74 #include <security/mac/mac_framework.h>
76 FEATURE(sysv_msg,
"System V message queues support");
78 static MALLOC_DEFINE(M_MSG,
"msg",
"SVID compatible message queues");
86 #define DPRINTF(a) printf a
88 #define DPRINTF(a) (void)0
99 #define MSGMAX (MSGSSZ*MSGSEG)
134 #define MSQID(ix,ds) ((ix) & 0xffff | (((ds).msg_perm.seq << 16) & 0xffff0000))
135 #define MSQID_IX(id) ((id) & 0xffff)
136 #define MSQID_SEQ(id) (((id) >> 16) & 0xffff)
148 #define MSG_LOCKED 01000
160 SYSCALL_INIT_HELPER(msgctl),
161 SYSCALL_INIT_HELPER(msgget),
162 SYSCALL_INIT_HELPER(msgsnd),
163 SYSCALL_INIT_HELPER(msgrcv),
164 #if defined(COMPAT_FREEBSD4) || defined(COMPAT_FREEBSD5) || \
165 defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD7)
166 SYSCALL_INIT_HELPER(msgsys),
167 SYSCALL_INIT_HELPER_COMPAT(freebsd7_msgctl),
173 #include <compat/compat32bit/compat32bit.h>
174 #include <compat/compat32bit/compat32bit_ipc.h>
175 #include <compat/compat32bit/compat32bit_proto.h>
176 #include <compat/compat32bit/compat32bit_signal.h>
177 #include <compat/compat32bit/compat32bit_syscall.h>
178 #include <compat/compat32bit/compat32bit_util.h>
180 static struct syscall_helper_data msg32_syscalls[] = {
181 SYSCALL32_INIT_HELPER(compat32bit_msgctl),
182 SYSCALL32_INIT_HELPER(compat32bit_msgsnd),
183 SYSCALL32_INIT_HELPER(compat32bit_msgrcv),
184 SYSCALL32_INIT_HELPER_COMPAT(msgget),
185 SYSCALL32_INIT_HELPER(compat32bit_msgsys),
186 #if defined(COMPAT_FREEBSD4) || defined(COMPAT_FREEBSD5) || \
187 defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD7)
188 SYSCALL32_INIT_HELPER(freebsd7_compat32bit_msgctl),
199 TUNABLE_INT_FETCH(
"kern.ipc.msgseg", &
msginfo.msgseg);
200 TUNABLE_INT_FETCH(
"kern.ipc.msgssz", &
msginfo.msgssz);
202 TUNABLE_INT_FETCH(
"kern.ipc.msgmni", &
msginfo.msgmni);
203 TUNABLE_INT_FETCH(
"kern.ipc.msgmnb", &
msginfo.msgmnb);
204 TUNABLE_INT_FETCH(
"kern.ipc.msgtql", &
msginfo.msgtql);
219 while (i < 1024 && i !=
msginfo.msgssz)
224 panic(
"msginfo.msgssz not a small power of 2");
229 panic(
"msginfo.msgseg > 32767");
232 for (i = 0; i <
msginfo.msgseg; i++) {
234 msgmaps[i-1].
next = i;
235 msgmaps[i].
next = -1;
240 for (i = 0; i <
msginfo.msgtql; i++) {
251 for (i = 0; i <
msginfo.msgmni; i++) {
252 msqids[i].u.msg_qbytes = 0;
253 msqids[i].u.msg_perm.seq = 0;
254 msqids[i].u.msg_perm.mode = 0;
256 mac_sysvmsq_init(&
msqids[i]);
265 error = syscall32_helper_register(msg32_syscalls);
275 struct msqid_kernel *msqkptr;
283 syscall32_helper_unregister(msg32_syscalls);
286 for (msqid = 0; msqid <
msginfo.msgmni; msqid++) {
294 if (msqkptr->u.msg_qbytes != 0 ||
302 for (i = 0; i <
msginfo.msgtql; i++)
303 mac_sysvmsg_destroy(&
msghdrs[i]);
304 for (msqid = 0; msqid <
msginfo.msgmni; msqid++)
305 mac_sysvmsq_destroy(&
msqids[msqid]);
308 free(msgmaps, M_MSG);
352 while (msghdr->msg_ts > 0) {
354 if (msghdr->msg_spot < 0 || msghdr->msg_spot >=
msginfo.msgseg)
355 panic(
"msghdr->msg_spot out of range");
356 next = msgmaps[msghdr->msg_spot].
next;
360 msghdr->msg_spot = next;
361 if (msghdr->msg_ts >=
msginfo.msgssz)
362 msghdr->msg_ts -=
msginfo.msgssz;
366 if (msghdr->msg_spot != -1)
367 panic(
"msghdr->msg_spot != -1");
371 mac_sysvmsg_cleanup(msghdr);
375 #ifndef _SYS_SYSPROTO_H_
387 int msqid = uap->
msqid;
389 struct msqid_ds msqbuf;
392 DPRINTF((
"call to msgctl(%d, %d, %p)\n", msqid, cmd, uap->buf));
393 if (cmd == IPC_SET &&
394 (error = copyin(uap->buf, &msqbuf,
sizeof(msqbuf))) != 0)
397 if (cmd == IPC_STAT && error == 0)
398 error = copyout(&msqbuf, uap->buf,
sizeof(
struct msqid_ds));
407 struct msqid_ds *msqbuf;
409 int rval, error, msqix;
410 register struct msqid_kernel *msqkptr;
415 msqix = IPCID_TO_IX(msqid);
417 if (msqix < 0 || msqix >=
msginfo.msgmni) {
418 DPRINTF((
"msqid (%d) out of range (0<=msqid<%d)\n", msqix,
426 if (msqkptr->u.msg_qbytes == 0) {
431 if (msqkptr->u.msg_perm.seq != IPCID_TO_SEQ(msqid)) {
432 DPRINTF((
"wrong sequence number\n"));
437 error = mac_sysvmsq_check_msqctl(td->td_ucred, msqkptr, cmd);
450 if ((error =
ipcperm(td, &msqkptr->u.msg_perm, IPC_M)))
463 for (msghdr = msqkptr->u.msg_first; msghdr != NULL;
464 msghdr = msghdr->msg_next) {
465 error = mac_sysvmsq_check_msgrmid(td->td_ucred, msghdr);
472 racct_sub_cred(msqkptr->cred, RACCT_MSGQQUEUED, msqkptr->u.msg_qnum);
473 racct_sub_cred(msqkptr->cred, RACCT_MSGQSIZE, msqkptr->u.msg_cbytes);
475 msqkptr->cred = NULL;
478 msghdr = msqkptr->u.msg_first;
479 while (msghdr != NULL) {
480 struct msg *msghdr_tmp;
483 msqkptr->u.msg_cbytes -= msghdr->msg_ts;
484 msqkptr->u.msg_qnum--;
486 msghdr = msghdr->msg_next;
490 if (msqkptr->u.msg_cbytes != 0)
491 panic(
"msg_cbytes is screwed up");
492 if (msqkptr->u.msg_qnum != 0)
493 panic(
"msg_qnum is screwed up");
495 msqkptr->u.msg_qbytes = 0;
498 mac_sysvmsq_cleanup(msqkptr);
507 if ((error =
ipcperm(td, &msqkptr->u.msg_perm, IPC_M)))
509 if (msqbuf->msg_qbytes > msqkptr->u.msg_qbytes) {
514 if (msqbuf->msg_qbytes >
msginfo.msgmnb) {
515 DPRINTF((
"can't increase msg_qbytes beyond %d"
516 "(truncating)\n",
msginfo.msgmnb));
517 msqbuf->msg_qbytes =
msginfo.msgmnb;
519 if (msqbuf->msg_qbytes == 0) {
520 DPRINTF((
"can't reduce msg_qbytes to 0\n"));
524 msqkptr->u.msg_perm.uid = msqbuf->msg_perm.uid;
525 msqkptr->u.msg_perm.gid = msqbuf->msg_perm.gid;
526 msqkptr->u.msg_perm.mode = (msqkptr->u.msg_perm.mode & ~0777) |
527 (msqbuf->msg_perm.mode & 0777);
528 msqkptr->u.msg_qbytes = msqbuf->msg_qbytes;
533 if ((error =
ipcperm(td, &msqkptr->u.msg_perm, IPC_R))) {
534 DPRINTF((
"requester doesn't have read access\n"));
537 *msqbuf = msqkptr->u;
541 DPRINTF((
"invalid command %d\n", cmd));
547 td->td_retval[0] = rval;
553 #ifndef _SYS_SYSPROTO_H_
565 int msqid, error = 0;
567 int msgflg = uap->msgflg;
568 struct ucred *cred = td->td_ucred;
569 register struct msqid_kernel *msqkptr = NULL;
571 DPRINTF((
"msgget(0x%x, 0%o)\n", key, msgflg));
577 if (key != IPC_PRIVATE) {
578 for (msqid = 0; msqid <
msginfo.msgmni; msqid++) {
580 if (msqkptr->u.msg_qbytes != 0 &&
581 msqkptr->u.msg_perm.key == key)
585 DPRINTF((
"found public key\n"));
586 if ((msgflg & IPC_CREAT) && (msgflg & IPC_EXCL)) {
591 if ((error =
ipcperm(td, &msqkptr->u.msg_perm,
593 DPRINTF((
"requester doesn't have 0%o access\n",
598 error = mac_sysvmsq_check_msqget(cred, msqkptr);
606 DPRINTF((
"need to allocate the msqid_ds\n"));
607 if (key == IPC_PRIVATE || (msgflg & IPC_CREAT)) {
608 for (msqid = 0; msqid <
msginfo.msgmni; msqid++) {
616 if (msqkptr->u.msg_qbytes == 0 &&
621 DPRINTF((
"no more msqid_ds's available\n"));
626 PROC_LOCK(td->td_proc);
627 error =
racct_add(td->td_proc, RACCT_NMSGQ, 1);
628 PROC_UNLOCK(td->td_proc);
634 DPRINTF((
"msqid %d is available\n", msqid));
635 msqkptr->u.msg_perm.key = key;
636 msqkptr->u.msg_perm.cuid = cred->cr_uid;
637 msqkptr->u.msg_perm.uid = cred->cr_uid;
638 msqkptr->u.msg_perm.cgid = cred->cr_gid;
639 msqkptr->u.msg_perm.gid = cred->cr_gid;
640 msqkptr->u.msg_perm.mode = (msgflg & 0777);
641 msqkptr->cred =
crhold(cred);
643 msqkptr->u.msg_perm.seq = (msqkptr->u.msg_perm.seq + 1) & 0x7fff;
644 msqkptr->u.msg_first = NULL;
645 msqkptr->u.msg_last = NULL;
646 msqkptr->u.msg_cbytes = 0;
647 msqkptr->u.msg_qnum = 0;
648 msqkptr->u.msg_qbytes =
msginfo.msgmnb;
649 msqkptr->u.msg_lspid = 0;
650 msqkptr->u.msg_lrpid = 0;
651 msqkptr->u.msg_stime = 0;
652 msqkptr->u.msg_rtime = 0;
655 mac_sysvmsq_create(cred, msqkptr);
658 DPRINTF((
"didn't find it and wasn't asked to create it\n"));
665 td->td_retval[0] = IXSEQ_TO_IPCID(msqid, msqkptr->u.msg_perm);
671 #ifndef _SYS_SYSPROTO_H_
688 int msqix, segs_needed, error = 0;
689 register struct msqid_kernel *msqkptr;
690 register struct msg *msghdr;
700 msqix = IPCID_TO_IX(msqid);
702 if (msqix < 0 || msqix >=
msginfo.msgmni) {
703 DPRINTF((
"msqid (%d) out of range (0<=msqid<%d)\n", msqix,
710 if (msqkptr->u.msg_qbytes == 0) {
711 DPRINTF((
"no such message queue id\n"));
715 if (msqkptr->u.msg_perm.seq != IPCID_TO_SEQ(msqid)) {
716 DPRINTF((
"wrong sequence number\n"));
721 if ((error =
ipcperm(td, &msqkptr->u.msg_perm, IPC_W))) {
722 DPRINTF((
"requester doesn't have write access\n"));
727 error = mac_sysvmsq_check_msqsnd(td->td_ucred, msqkptr);
733 PROC_LOCK(td->td_proc);
734 if (
racct_add(td->td_proc, RACCT_MSGQQUEUED, 1)) {
735 PROC_UNLOCK(td->td_proc);
740 if (
racct_add(td->td_proc, RACCT_MSGQSIZE, msgsz)) {
741 racct_sub(td->td_proc, RACCT_MSGQQUEUED, 1);
742 PROC_UNLOCK(td->td_proc);
746 PROC_UNLOCK(td->td_proc);
750 DPRINTF((
"msgsz=%zu, msgssz=%d, segs_needed=%d\n", msgsz,
753 int need_more_resources = 0;
760 if (msgsz > msqkptr->u.msg_qbytes) {
761 DPRINTF((
"msgsz > msqkptr->u.msg_qbytes\n"));
767 DPRINTF((
"msqid is locked\n"));
768 need_more_resources = 1;
770 if (msgsz + msqkptr->u.msg_cbytes > msqkptr->u.msg_qbytes) {
771 DPRINTF((
"msgsz + msg_cbytes > msg_qbytes\n"));
772 need_more_resources = 1;
775 DPRINTF((
"segs_needed > nfree_msgmaps\n"));
776 need_more_resources = 1;
779 DPRINTF((
"no more msghdrs\n"));
780 need_more_resources = 1;
783 if (need_more_resources) {
786 if ((msgflg & IPC_NOWAIT) != 0) {
787 DPRINTF((
"need more resources but caller "
788 "doesn't want to wait\n"));
793 if ((msqkptr->u.msg_perm.mode &
MSG_LOCKED) != 0) {
794 DPRINTF((
"we don't own the msqid_ds\n"));
799 DPRINTF((
"we own the msqid_ds\n"));
803 DPRINTF((
"msgsnd: goodnight\n"));
804 error = msleep(msqkptr, &
msq_mtx, (PZERO - 4) | PCATCH,
806 DPRINTF((
"msgsnd: good morning, error=%d\n", error));
809 if (error == EWOULDBLOCK) {
810 DPRINTF((
"msgsnd: timed out\n"));
814 DPRINTF((
"msgsnd: interrupted system call\n"));
823 if (msqkptr->u.msg_qbytes == 0) {
830 DPRINTF((
"got all the resources that we need\n"));
841 panic(
"msg_perm.mode & MSG_LOCKED");
843 panic(
"segs_needed > nfree_msgmaps");
844 if (msgsz + msqkptr->u.msg_cbytes > msqkptr->u.msg_qbytes)
845 panic(
"msgsz + msg_cbytes > msg_qbytes");
847 panic(
"no more msghdrs");
854 if ((msqkptr->u.msg_perm.mode &
MSG_LOCKED) != 0)
855 panic(
"msqid_ds is already locked");
864 msghdr->msg_spot = -1;
865 msghdr->msg_ts = msgsz;
866 msghdr->msg_type = mtype;
873 mac_sysvmsg_create(td->td_ucred, msqkptr, msghdr);
880 while (segs_needed > 0) {
882 panic(
"not enough msgmaps");
884 panic(
"nil free_msgmaps");
887 panic(
"next too low #1");
889 panic(
"next out of range #1");
890 DPRINTF((
"allocating segment %d to message\n", next));
893 msgmaps[next].
next = msghdr->msg_spot;
894 msghdr->msg_spot = next;
902 if (msghdr->msg_type < 1) {
906 DPRINTF((
"mtype (%ld) < 1\n", msghdr->msg_type));
915 next = msghdr->msg_spot;
923 panic(
"next too low #2");
925 panic(
"next out of range #2");
930 DPRINTF((
"error %d copying in message segment\n",
939 msgp = (
const char *)msgp + tlen;
940 next = msgmaps[next].
next;
943 panic(
"didn't use all the msg segments");
955 if (msqkptr->u.msg_qbytes == 0) {
974 error = mac_sysvmsq_check_msgmsq(td->td_ucred, msghdr, msqkptr);
985 if (msqkptr->u.msg_first == NULL) {
986 msqkptr->u.msg_first = msghdr;
987 msqkptr->u.msg_last = msghdr;
989 msqkptr->u.msg_last->msg_next = msghdr;
990 msqkptr->u.msg_last = msghdr;
992 msqkptr->u.msg_last->msg_next = NULL;
994 msqkptr->u.msg_cbytes += msghdr->msg_ts;
995 msqkptr->u.msg_qnum++;
996 msqkptr->u.msg_lspid = td->td_proc->p_pid;
1000 td->td_retval[0] = 0;
1004 PROC_LOCK(td->td_proc);
1005 racct_sub(td->td_proc, RACCT_MSGQQUEUED, 1);
1006 racct_sub(td->td_proc, RACCT_MSGQSIZE, saved_msgsz);
1007 PROC_UNLOCK(td->td_proc);
1023 DPRINTF((
"call to msgsnd(%d, %p, %zu, %d)\n", uap->msqid, uap->msgp,
1024 uap->msgsz, uap->msgflg));
1026 if ((error = copyin(uap->msgp, &mtype,
sizeof(mtype))) != 0) {
1027 DPRINTF((
"error %d copying the message type\n", error));
1031 (
const char *)uap->msgp +
sizeof(mtype),
1032 uap->msgsz, uap->msgflg, mtype));
1035 #ifndef _SYS_SYSPROTO_H_
1055 register struct msqid_kernel *msqkptr;
1056 register struct msg *msghdr;
1057 int msqix, error = 0;
1063 msqix = IPCID_TO_IX(msqid);
1065 if (msqix < 0 || msqix >=
msginfo.msgmni) {
1066 DPRINTF((
"msqid (%d) out of range (0<=msqid<%d)\n", msqix,
1071 msqkptr = &
msqids[msqix];
1073 if (msqkptr->u.msg_qbytes == 0) {
1074 DPRINTF((
"no such message queue id\n"));
1078 if (msqkptr->u.msg_perm.seq != IPCID_TO_SEQ(msqid)) {
1079 DPRINTF((
"wrong sequence number\n"));
1084 if ((error =
ipcperm(td, &msqkptr->u.msg_perm, IPC_R))) {
1085 DPRINTF((
"requester doesn't have read access\n"));
1090 error = mac_sysvmsq_check_msqrcv(td->td_ucred, msqkptr);
1096 while (msghdr == NULL) {
1098 msghdr = msqkptr->u.msg_first;
1099 if (msghdr != NULL) {
1100 if (msgsz < msghdr->msg_ts &&
1101 (msgflg & MSG_NOERROR) == 0) {
1102 DPRINTF((
"first message on the queue "
1103 "is too big (want %zu, got %d)\n",
1104 msgsz, msghdr->msg_ts));
1109 error = mac_sysvmsq_check_msgrcv(td->td_ucred,
1114 if (msqkptr->u.msg_first == msqkptr->u.msg_last) {
1115 msqkptr->u.msg_first = NULL;
1116 msqkptr->u.msg_last = NULL;
1118 msqkptr->u.msg_first = msghdr->msg_next;
1119 if (msqkptr->u.msg_first == NULL)
1120 panic(
"msg_first/last screwed up #1");
1124 struct msg *previous;
1128 prev = &(msqkptr->u.msg_first);
1129 while ((msghdr = *prev) != NULL) {
1139 if (msgtyp == msghdr->msg_type ||
1140 msghdr->msg_type <= -msgtyp) {
1141 DPRINTF((
"found message type %ld, "
1143 msghdr->msg_type, msgtyp));
1144 if (msgsz < msghdr->msg_ts &&
1145 (msgflg & MSG_NOERROR) == 0) {
1147 "on the queue is too big "
1148 "(want %zu, got %hu)\n",
1149 msgsz, msghdr->msg_ts));
1154 error = mac_sysvmsq_check_msgrcv(
1155 td->td_ucred, msghdr);
1159 *prev = msghdr->msg_next;
1160 if (msghdr == msqkptr->u.msg_last) {
1161 if (previous == NULL) {
1163 &msqkptr->u.msg_first)
1164 panic(
"msg_first/last screwed up #2");
1165 msqkptr->u.msg_first =
1167 msqkptr->u.msg_last =
1171 &msqkptr->u.msg_first)
1172 panic(
"msg_first/last screwed up #3");
1173 msqkptr->u.msg_last =
1180 prev = &(msghdr->msg_next);
1197 if ((msgflg & IPC_NOWAIT) != 0) {
1198 DPRINTF((
"no appropriate message found (msgtyp=%ld)\n",
1209 DPRINTF((
"msgrcv: goodnight\n"));
1210 error = msleep(msqkptr, &
msq_mtx, (PZERO - 4) | PCATCH,
1212 DPRINTF((
"msgrcv: good morning (error=%d)\n", error));
1215 DPRINTF((
"msgrcv: interrupted system call\n"));
1224 if (msqkptr->u.msg_qbytes == 0 ||
1225 msqkptr->u.msg_perm.seq != IPCID_TO_SEQ(msqid)) {
1238 msqkptr->u.msg_cbytes -= msghdr->msg_ts;
1239 msqkptr->u.msg_qnum--;
1240 msqkptr->u.msg_lrpid = td->td_proc->p_pid;
1252 DPRINTF((
"found a message, msgsz=%zu, msg_ts=%hu\n", msgsz,
1254 if (msgsz > msghdr->msg_ts)
1255 msgsz = msghdr->msg_ts;
1256 *mtype = msghdr->msg_type;
1262 next = msghdr->msg_spot;
1263 for (len = 0; len < msgsz; len +=
msginfo.msgssz) {
1266 if (msgsz - len >
msginfo.msgssz)
1271 panic(
"next too low #3");
1273 panic(
"next out of range #3");
1278 DPRINTF((
"error (%d) copying out message segment\n",
1284 msgp = (
char *)msgp + tlen;
1285 next = msgmaps[next].
next;
1294 td->td_retval[0] = msgsz;
1308 DPRINTF((
"call to msgrcv(%d, %p, %zu, %ld, %d)\n", uap->msqid,
1309 uap->msgp, uap->msgsz, uap->msgtyp, uap->msgflg));
1312 (
char *)uap->msgp +
sizeof(mtype), uap->msgsz,
1313 uap->msgtyp, uap->msgflg, &mtype)) != 0)
1315 if ((error = copyout(&mtype, uap->msgp,
sizeof(mtype))) != 0)
1316 DPRINTF((
"error %d copying the message type\n", error));
1324 return (SYSCTL_OUT(req,
msqids,
1325 sizeof(
struct msqid_kernel) *
msginfo.msgmni));
1329 "Maximum message size");
1331 "Number of message queue identifiers");
1333 "Maximum number of bytes in a queue");
1335 "Maximum number of messages in the system");
1337 "Size of a message segment");
1339 "Number of message segments");
1345 compat32bit_msgsys(
struct thread *td,
struct compat32bit_msgsys_args *uap)
1348 #if defined(COMPAT_FREEBSD4) || defined(COMPAT_FREEBSD5) || \
1349 defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD7)
1350 switch (uap->which) {
1352 return (freebsd7_compat32bit_msgctl(td,
1353 (
struct freebsd7_compat32bit_msgctl_args *)&uap->a2));
1355 return (compat32bit_msgsnd(td,
1356 (
struct compat32bit_msgsnd_args *)&uap->a2));
1358 return (compat32bit_msgrcv(td,
1359 (
struct compat32bit_msgrcv_args *)&uap->a2));
1361 return (sys_msgsys(td, (
struct msgsys_args *)uap));
1364 return (
nosys(td, NULL));
1368 #if defined(COMPAT_FREEBSD4) || defined(COMPAT_FREEBSD5) || \
1369 defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD7)
1371 freebsd7_compat32bit_msgctl(
struct thread *td,
1372 struct freebsd7_compat32bit_msgctl_args *uap)
1374 struct msqid_ds msqbuf;
1375 struct msqid_ds32_old msqbuf32;
1378 if (uap->cmd == IPC_SET) {
1379 error = copyin(uap->buf, &msqbuf32,
sizeof(msqbuf32));
1382 compat32bit_ipcperm_old_in(&msqbuf32.msg_perm, &msqbuf.msg_perm);
1383 PTRIN_CP(msqbuf32, msqbuf, msg_first);
1384 PTRIN_CP(msqbuf32, msqbuf, msg_last);
1385 CP(msqbuf32, msqbuf, msg_cbytes);
1386 CP(msqbuf32, msqbuf, msg_qnum);
1387 CP(msqbuf32, msqbuf, msg_qbytes);
1388 CP(msqbuf32, msqbuf, msg_lspid);
1389 CP(msqbuf32, msqbuf, msg_lrpid);
1390 CP(msqbuf32, msqbuf, msg_stime);
1391 CP(msqbuf32, msqbuf, msg_rtime);
1392 CP(msqbuf32, msqbuf, msg_ctime);
1394 error =
kern_msgctl(td, uap->msqid, uap->cmd, &msqbuf);
1397 if (uap->cmd == IPC_STAT) {
1398 bzero(&msqbuf32,
sizeof(msqbuf32));
1399 compat32bit_ipcperm_old_out(&msqbuf.msg_perm, &msqbuf32.msg_perm);
1400 PTROUT_CP(msqbuf, msqbuf32, msg_first);
1401 PTROUT_CP(msqbuf, msqbuf32, msg_last);
1402 CP(msqbuf, msqbuf32, msg_cbytes);
1403 CP(msqbuf, msqbuf32, msg_qnum);
1404 CP(msqbuf, msqbuf32, msg_qbytes);
1405 CP(msqbuf, msqbuf32, msg_lspid);
1406 CP(msqbuf, msqbuf32, msg_lrpid);
1407 CP(msqbuf, msqbuf32, msg_stime);
1408 CP(msqbuf, msqbuf32, msg_rtime);
1409 CP(msqbuf, msqbuf32, msg_ctime);
1410 error = copyout(&msqbuf32, uap->buf,
sizeof(
struct msqid_ds32));
1417 compat32bit_msgctl(
struct thread *td,
struct compat32bit_msgctl_args *uap)
1419 struct msqid_ds msqbuf;
1420 struct msqid_ds32 msqbuf32;
1423 if (uap->cmd == IPC_SET) {
1424 error = copyin(uap->buf, &msqbuf32,
sizeof(msqbuf32));
1427 compat32bit_ipcperm_in(&msqbuf32.msg_perm, &msqbuf.msg_perm);
1428 PTRIN_CP(msqbuf32, msqbuf, msg_first);
1429 PTRIN_CP(msqbuf32, msqbuf, msg_last);
1430 CP(msqbuf32, msqbuf, msg_cbytes);
1431 CP(msqbuf32, msqbuf, msg_qnum);
1432 CP(msqbuf32, msqbuf, msg_qbytes);
1433 CP(msqbuf32, msqbuf, msg_lspid);
1434 CP(msqbuf32, msqbuf, msg_lrpid);
1435 CP(msqbuf32, msqbuf, msg_stime);
1436 CP(msqbuf32, msqbuf, msg_rtime);
1437 CP(msqbuf32, msqbuf, msg_ctime);
1439 error =
kern_msgctl(td, uap->msqid, uap->cmd, &msqbuf);
1442 if (uap->cmd == IPC_STAT) {
1443 compat32bit_ipcperm_out(&msqbuf.msg_perm, &msqbuf32.msg_perm);
1444 PTROUT_CP(msqbuf, msqbuf32, msg_first);
1445 PTROUT_CP(msqbuf, msqbuf32, msg_last);
1446 CP(msqbuf, msqbuf32, msg_cbytes);
1447 CP(msqbuf, msqbuf32, msg_qnum);
1448 CP(msqbuf, msqbuf32, msg_qbytes);
1449 CP(msqbuf, msqbuf32, msg_lspid);
1450 CP(msqbuf, msqbuf32, msg_lrpid);
1451 CP(msqbuf, msqbuf32, msg_stime);
1452 CP(msqbuf, msqbuf32, msg_rtime);
1453 CP(msqbuf, msqbuf32, msg_ctime);
1454 error = copyout(&msqbuf32, uap->buf,
sizeof(
struct msqid_ds32));
1460 compat32bit_msgsnd(
struct thread *td,
struct compat32bit_msgsnd_args *uap)
1467 msgp = PTRIN(uap->msgp);
1468 if ((error = copyin(msgp, &mtype32,
sizeof(mtype32))) != 0)
1472 (
const char *)msgp +
sizeof(mtype32),
1473 uap->msgsz, uap->msgflg, mtype));
1477 compat32bit_msgrcv(
struct thread *td,
struct compat32bit_msgrcv_args *uap)
1484 msgp = PTRIN(uap->msgp);
1486 (
char *)msgp +
sizeof(mtype32), uap->msgsz,
1487 uap->msgtyp, uap->msgflg, &mtype)) != 0)
1489 mtype32 = (int32_t)mtype;
1490 return (copyout(&mtype32, msgp,
sizeof(mtype32)));
1494 #if defined(COMPAT_FREEBSD4) || defined(COMPAT_FREEBSD5) || \
1495 defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD7)
1498 static sy_call_t *msgcalls[] = {
1499 (sy_call_t *)freebsd7_msgctl, (sy_call_t *)
sys_msgget,
1523 if (uap->which < 0 ||
1524 uap->which >=
sizeof(msgcalls)/
sizeof(msgcalls[0]))
1526 error = (*msgcalls[uap->which])(td, &uap->a2);
1531 #define CP(src, dst, fld) do { (dst).fld = (src).fld; } while (0)
1534 #ifndef _SYS_SYSPROTO_H_
1535 struct freebsd7_msgctl_args {
1538 struct msqid_ds_old *
buf;
1542 freebsd7_msgctl(td, uap)
1544 struct freebsd7_msgctl_args *uap;
1546 struct msqid_ds_old msqold;
1547 struct msqid_ds msqbuf;
1550 DPRINTF((
"call to freebsd7_msgctl(%d, %d, %p)\n", uap->msqid, uap->cmd,
1552 if (uap->cmd == IPC_SET) {
1553 error = copyin(uap->buf, &msqold,
sizeof(msqold));
1556 ipcperm_old2new(&msqold.msg_perm, &msqbuf.msg_perm);
1557 CP(msqold, msqbuf, msg_first);
1558 CP(msqold, msqbuf, msg_last);
1559 CP(msqold, msqbuf, msg_cbytes);
1560 CP(msqold, msqbuf, msg_qnum);
1561 CP(msqold, msqbuf, msg_qbytes);
1562 CP(msqold, msqbuf, msg_lspid);
1563 CP(msqold, msqbuf, msg_lrpid);
1564 CP(msqold, msqbuf, msg_stime);
1565 CP(msqold, msqbuf, msg_rtime);
1566 CP(msqold, msqbuf, msg_ctime);
1568 error =
kern_msgctl(td, uap->msqid, uap->cmd, &msqbuf);
1571 if (uap->cmd == IPC_STAT) {
1572 bzero(&msqold,
sizeof(msqold));
1573 ipcperm_new2old(&msqbuf.msg_perm, &msqold.msg_perm);
1574 CP(msqbuf, msqold, msg_first);
1575 CP(msqbuf, msqold, msg_last);
1576 CP(msqbuf, msqold, msg_cbytes);
1577 CP(msqbuf, msqold, msg_qnum);
1578 CP(msqbuf, msqold, msg_qbytes);
1579 CP(msqbuf, msqold, msg_lspid);
1580 CP(msqbuf, msqold, msg_lrpid);
1581 CP(msqbuf, msqold, msg_stime);
1582 CP(msqbuf, msqold, msg_rtime);
1583 CP(msqbuf, msqold, msg_ctime);
1584 error = copyout(&msqold, uap->buf,
sizeof(
struct msqid_ds_old));
int prison_allow(struct ucred *cred, unsigned flag)
int syscall_helper_unregister(struct syscall_helper_data *sd)
int ipcperm(struct thread *td, struct ipc_perm *perm, int acc_mode)
int kern_msgrcv(struct thread *td, int msqid, void *msgp, size_t msgsz, long msgtyp, int msgflg, long *mtype)
DECLARE_MODULE(sysvmsg, sysvmsg_mod, SI_SUB_SYSV_MSG, SI_ORDER_FIRST)
volatile time_t time_second
static moduledata_t sysvmsg_mod
int racct_add(struct proc *p, int resource, uint64_t amount)
void racct_sub_cred(struct ucred *cred, int resource, uint64_t amount)
int syscall_helper_register(struct syscall_helper_data *sd)
static struct msgmap * msgmaps
void * malloc(unsigned long size, struct malloc_type *mtp, int flags)
static struct msg * free_msghdrs
void panic(const char *fmt,...)
SYSCTL_INT(_kern_ipc, OID_AUTO, msgmax, CTLFLAG_RD,&msginfo.msgmax, 0,"Maximum message size")
static void msg_freehdr(struct msg *msghdr)
int nosys(struct thread *td, struct nosys_args *args)
static short free_msgmaps
static int sysctl_msqids(SYSCTL_HANDLER_ARGS)
int priv_check(struct thread *td, int priv)
void racct_sub(struct proc *p, int resource, uint64_t amount)
int sys_msgrcv(struct thread *td, struct msgrcv_args *uap)
void crfree(struct ucred *cr)
static struct msqid_kernel * msqids
static struct msg * msghdrs
FEATURE(sysv_msg,"System V message queues support")
struct ucred * crhold(struct ucred *cr)
void free(void *addr, struct malloc_type *mtp)
static struct syscall_helper_data msg_syscalls[]
void mtx_init(struct mtx *m, const char *name, const char *type, int opts)
int kern_msgsnd(struct thread *td, int msqid, const void *msgp, size_t msgsz, int msgflg, long mtype)
int kern_msgctl(struct thread *td, int msqid, int cmd, struct msqid_ds *msqbuf)
static struct mtx msq_mtx
SYSCTL_PROC(_kern_ipc, OID_AUTO, msqids, CTLTYPE_OPAQUE|CTLFLAG_RD, NULL, 0, sysctl_msqids,"","Message queue IDs")
int sys_msgctl(struct thread *td, struct msgctl_args *uap)
void mtx_destroy(struct mtx *m)
static int msgunload(void)
MODULE_VERSION(sysvmsg, 1)
int sys_msgget(struct thread *td, struct msgget_args *uap)
static int sysvmsg_modload(struct module *, int, void *)
static MALLOC_DEFINE(M_MSG,"msg","SVID compatible message queues")
int sys_msgsnd(struct thread *td, struct msgsnd_args *uap)