2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2005 David Xu <davidxu@freebsd.org>
5 * Copyright (c) 2016-2017 Robert N. M. Watson
8 * Portions of this software were developed by BAE Systems, the University of
9 * Cambridge Computer Laboratory, and Memorial University under DARPA/AFRL
10 * contract FA8650-15-C-7558 ("CADETS"), as part of the DARPA Transparent
11 * Computing (TC) research program.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * POSIX message queue implementation.
39 * 1) A mqueue filesystem can be mounted, each message queue appears
40 * in mounted directory, user can change queue's permission and
41 * ownership, or remove a queue. Manually creating a file in the
42 * directory causes a message queue to be created in the kernel with
43 * default message queue attributes applied and same name used, this
44 * method is not advocated since mq_open syscall allows user to specify
45 * different attributes. Also the file system can be mounted multiple
46 * times at different mount points but shows same contents.
48 * 2) Standard POSIX message queue API. The syscalls do not use vfs layer,
49 * but directly operate on internal data structure, this allows user to
50 * use the IPC facility without having to mount mqueue file system.
53 #include <sys/cdefs.h>
54 __FBSDID("$FreeBSD$");
56 #include "opt_capsicum.h"
58 #include <sys/param.h>
59 #include <sys/kernel.h>
60 #include <sys/systm.h>
61 #include <sys/limits.h>
62 #include <sys/malloc.h>
64 #include <sys/capsicum.h>
65 #include <sys/dirent.h>
66 #include <sys/event.h>
67 #include <sys/eventhandler.h>
68 #include <sys/fcntl.h>
70 #include <sys/filedesc.h>
73 #include <sys/module.h>
74 #include <sys/mount.h>
75 #include <sys/mqueue.h>
76 #include <sys/mutex.h>
77 #include <sys/namei.h>
78 #include <sys/posix4.h>
82 #include <sys/queue.h>
83 #include <sys/sysproto.h>
85 #include <sys/syscall.h>
86 #include <sys/syscallsubr.h>
87 #include <sys/sysent.h>
89 #include <sys/sysctl.h>
90 #include <sys/taskqueue.h>
91 #include <sys/unistd.h>
93 #include <sys/vnode.h>
94 #include <machine/atomic.h>
96 #include <security/audit/audit.h>
98 FEATURE(p1003_1b_mqueue, "POSIX P1003.1B message queues support");
101 * Limits and constants
103 #define MQFS_NAMELEN NAME_MAX
104 #define MQFS_DELEN (8 + MQFS_NAMELEN)
120 * mqfs_info: describes a mqfs instance
124 struct mqfs_node *mi_root;
125 struct unrhdr *mi_unrhdr;
129 LIST_ENTRY(mqfs_vdata) mv_link;
130 struct mqfs_node *mv_node;
131 struct vnode *mv_vnode;
136 * mqfs_node: describes a node (file or directory) within a mqfs
139 char mn_name[MQFS_NAMELEN+1];
140 struct mqfs_info *mn_info;
141 struct mqfs_node *mn_parent;
142 LIST_HEAD(,mqfs_node) mn_children;
143 LIST_ENTRY(mqfs_node) mn_sibling;
144 LIST_HEAD(,mqfs_vdata) mn_vnodes;
145 const void *mn_pr_root;
151 struct timespec mn_birth;
152 struct timespec mn_ctime;
153 struct timespec mn_atime;
154 struct timespec mn_mtime;
160 #define VTON(vp) (((struct mqfs_vdata *)((vp)->v_data))->mv_node)
161 #define VTOMQ(vp) ((struct mqueue *)(VTON(vp)->mn_data))
162 #define VFSTOMQFS(m) ((struct mqfs_info *)((m)->mnt_data))
163 #define FPTOMQ(fp) ((struct mqueue *)(((struct mqfs_node *) \
164 (fp)->f_data)->mn_data))
166 TAILQ_HEAD(msgq, mqueue_msg);
170 struct mqueue_notifier {
171 LIST_ENTRY(mqueue_notifier) nt_link;
172 struct sigevent nt_sigev;
174 struct proc *nt_proc;
187 struct selinfo mq_rsel;
188 struct selinfo mq_wsel;
189 struct mqueue_notifier *mq_notifier;
196 TAILQ_ENTRY(mqueue_msg) msg_link;
197 unsigned int msg_prio;
198 unsigned int msg_size;
199 /* following real data... */
202 static SYSCTL_NODE(_kern, OID_AUTO, mqueue, CTLFLAG_RW, 0,
203 "POSIX real time message queue");
205 static int default_maxmsg = 10;
206 static int default_msgsize = 1024;
208 static int maxmsg = 100;
209 SYSCTL_INT(_kern_mqueue, OID_AUTO, maxmsg, CTLFLAG_RW,
210 &maxmsg, 0, "Default maximum messages in queue");
211 static int maxmsgsize = 16384;
212 SYSCTL_INT(_kern_mqueue, OID_AUTO, maxmsgsize, CTLFLAG_RW,
213 &maxmsgsize, 0, "Default maximum message size");
214 static int maxmq = 100;
215 SYSCTL_INT(_kern_mqueue, OID_AUTO, maxmq, CTLFLAG_RW,
216 &maxmq, 0, "maximum message queues");
217 static int curmq = 0;
218 SYSCTL_INT(_kern_mqueue, OID_AUTO, curmq, CTLFLAG_RW,
219 &curmq, 0, "current message queue number");
220 static int unloadable = 0;
221 static MALLOC_DEFINE(M_MQUEUEDATA, "mqdata", "mqueue data");
223 static eventhandler_tag exit_tag;
225 /* Only one instance per-system */
226 static struct mqfs_info mqfs_data;
227 static uma_zone_t mqnode_zone;
228 static uma_zone_t mqueue_zone;
229 static uma_zone_t mvdata_zone;
230 static uma_zone_t mqnoti_zone;
231 static struct vop_vector mqfs_vnodeops;
232 static struct fileops mqueueops;
233 static unsigned mqfs_osd_jail_slot;
236 * Directory structure construction and manipulation
239 static struct mqfs_node *mqfs_create_dir(struct mqfs_node *parent,
240 const char *name, int namelen, struct ucred *cred, int mode);
241 static struct mqfs_node *mqfs_create_link(struct mqfs_node *parent,
242 const char *name, int namelen, struct ucred *cred, int mode);
245 static struct mqfs_node *mqfs_create_file(struct mqfs_node *parent,
246 const char *name, int namelen, struct ucred *cred, int mode);
247 static int mqfs_destroy(struct mqfs_node *mn);
248 static void mqfs_fileno_alloc(struct mqfs_info *mi, struct mqfs_node *mn);
249 static void mqfs_fileno_free(struct mqfs_info *mi, struct mqfs_node *mn);
250 static int mqfs_allocv(struct mount *mp, struct vnode **vpp, struct mqfs_node *pn);
251 static int mqfs_prison_remove(void *obj, void *data);
254 * Message queue construction and maniplation
256 static struct mqueue *mqueue_alloc(const struct mq_attr *attr);
257 static void mqueue_free(struct mqueue *mq);
258 static int mqueue_send(struct mqueue *mq, const char *msg_ptr,
259 size_t msg_len, unsigned msg_prio, int waitok,
260 const struct timespec *abs_timeout);
261 static int mqueue_receive(struct mqueue *mq, char *msg_ptr,
262 size_t msg_len, unsigned *msg_prio, int waitok,
263 const struct timespec *abs_timeout);
264 static int _mqueue_send(struct mqueue *mq, struct mqueue_msg *msg,
266 static int _mqueue_recv(struct mqueue *mq, struct mqueue_msg **msg,
268 static void mqueue_send_notification(struct mqueue *mq);
269 static void mqueue_fdclose(struct thread *td, int fd, struct file *fp);
270 static void mq_proc_exit(void *arg, struct proc *p);
275 static void filt_mqdetach(struct knote *kn);
276 static int filt_mqread(struct knote *kn, long hint);
277 static int filt_mqwrite(struct knote *kn, long hint);
279 struct filterops mq_rfiltops = {
281 .f_detach = filt_mqdetach,
282 .f_event = filt_mqread,
284 struct filterops mq_wfiltops = {
286 .f_detach = filt_mqdetach,
287 .f_event = filt_mqwrite,
291 * Initialize fileno bitmap
294 mqfs_fileno_init(struct mqfs_info *mi)
298 up = new_unrhdr(1, INT_MAX, NULL);
303 * Tear down fileno bitmap
306 mqfs_fileno_uninit(struct mqfs_info *mi)
311 mi->mi_unrhdr = NULL;
316 * Allocate a file number
319 mqfs_fileno_alloc(struct mqfs_info *mi, struct mqfs_node *mn)
321 /* make sure our parent has a file number */
322 if (mn->mn_parent && !mn->mn_parent->mn_fileno)
323 mqfs_fileno_alloc(mi, mn->mn_parent);
325 switch (mn->mn_type) {
329 case mqfstype_symlink:
330 mn->mn_fileno = alloc_unr(mi->mi_unrhdr);
333 KASSERT(mn->mn_parent != NULL,
334 ("mqfstype_this node has no parent"));
335 mn->mn_fileno = mn->mn_parent->mn_fileno;
337 case mqfstype_parent:
338 KASSERT(mn->mn_parent != NULL,
339 ("mqfstype_parent node has no parent"));
340 if (mn->mn_parent == mi->mi_root) {
341 mn->mn_fileno = mn->mn_parent->mn_fileno;
344 KASSERT(mn->mn_parent->mn_parent != NULL,
345 ("mqfstype_parent node has no grandparent"));
346 mn->mn_fileno = mn->mn_parent->mn_parent->mn_fileno;
350 ("mqfs_fileno_alloc() called for unknown type node: %d",
357 * Release a file number
360 mqfs_fileno_free(struct mqfs_info *mi, struct mqfs_node *mn)
362 switch (mn->mn_type) {
366 case mqfstype_symlink:
367 free_unr(mi->mi_unrhdr, mn->mn_fileno);
370 case mqfstype_parent:
371 /* ignore these, as they don't "own" their file number */
375 ("mqfs_fileno_free() called for unknown type node: %d",
381 static __inline struct mqfs_node *
384 return uma_zalloc(mqnode_zone, M_WAITOK | M_ZERO);
388 mqnode_free(struct mqfs_node *node)
390 uma_zfree(mqnode_zone, node);
394 mqnode_addref(struct mqfs_node *node)
396 atomic_add_int(&node->mn_refcount, 1);
400 mqnode_release(struct mqfs_node *node)
402 struct mqfs_info *mqfs;
405 mqfs = node->mn_info;
406 old = atomic_fetchadd_int(&node->mn_refcount, -1);
407 if (node->mn_type == mqfstype_dir ||
408 node->mn_type == mqfstype_root)
409 exp = 3; /* include . and .. */
413 int locked = sx_xlocked(&mqfs->mi_lock);
415 sx_xlock(&mqfs->mi_lock);
418 sx_xunlock(&mqfs->mi_lock);
423 * Add a node to a directory
426 mqfs_add_node(struct mqfs_node *parent, struct mqfs_node *node)
428 KASSERT(parent != NULL, ("%s(): parent is NULL", __func__));
429 KASSERT(parent->mn_info != NULL,
430 ("%s(): parent has no mn_info", __func__));
431 KASSERT(parent->mn_type == mqfstype_dir ||
432 parent->mn_type == mqfstype_root,
433 ("%s(): parent is not a directory", __func__));
435 node->mn_info = parent->mn_info;
436 node->mn_parent = parent;
437 LIST_INIT(&node->mn_children);
438 LIST_INIT(&node->mn_vnodes);
439 LIST_INSERT_HEAD(&parent->mn_children, node, mn_sibling);
440 mqnode_addref(parent);
444 static struct mqfs_node *
445 mqfs_create_node(const char *name, int namelen, struct ucred *cred, int mode,
448 struct mqfs_node *node;
450 node = mqnode_alloc();
451 strncpy(node->mn_name, name, namelen);
452 node->mn_pr_root = cred->cr_prison->pr_root;
453 node->mn_type = nodetype;
454 node->mn_refcount = 1;
455 vfs_timestamp(&node->mn_birth);
456 node->mn_ctime = node->mn_atime = node->mn_mtime
458 node->mn_uid = cred->cr_uid;
459 node->mn_gid = cred->cr_gid;
460 node->mn_mode = mode;
467 static struct mqfs_node *
468 mqfs_create_file(struct mqfs_node *parent, const char *name, int namelen,
469 struct ucred *cred, int mode)
471 struct mqfs_node *node;
473 node = mqfs_create_node(name, namelen, cred, mode, mqfstype_file);
474 if (mqfs_add_node(parent, node) != 0) {
482 * Add . and .. to a directory
485 mqfs_fixup_dir(struct mqfs_node *parent)
487 struct mqfs_node *dir;
489 dir = mqnode_alloc();
490 dir->mn_name[0] = '.';
491 dir->mn_type = mqfstype_this;
492 dir->mn_refcount = 1;
493 if (mqfs_add_node(parent, dir) != 0) {
498 dir = mqnode_alloc();
499 dir->mn_name[0] = dir->mn_name[1] = '.';
500 dir->mn_type = mqfstype_parent;
501 dir->mn_refcount = 1;
503 if (mqfs_add_node(parent, dir) != 0) {
516 static struct mqfs_node *
517 mqfs_create_dir(struct mqfs_node *parent, const char *name, int namelen,
518 struct ucred *cred, int mode)
520 struct mqfs_node *node;
522 node = mqfs_create_node(name, namelen, cred, mode, mqfstype_dir);
523 if (mqfs_add_node(parent, node) != 0) {
528 if (mqfs_fixup_dir(node) != 0) {
538 static struct mqfs_node *
539 mqfs_create_link(struct mqfs_node *parent, const char *name, int namelen,
540 struct ucred *cred, int mode)
542 struct mqfs_node *node;
544 node = mqfs_create_node(name, namelen, cred, mode, mqfstype_symlink);
545 if (mqfs_add_node(parent, node) != 0) {
555 * Destroy a node or a tree of nodes
558 mqfs_destroy(struct mqfs_node *node)
560 struct mqfs_node *parent;
562 KASSERT(node != NULL,
563 ("%s(): node is NULL", __func__));
564 KASSERT(node->mn_info != NULL,
565 ("%s(): node has no mn_info", __func__));
567 /* destroy children */
568 if (node->mn_type == mqfstype_dir || node->mn_type == mqfstype_root)
569 while (! LIST_EMPTY(&node->mn_children))
570 mqfs_destroy(LIST_FIRST(&node->mn_children));
572 /* unlink from parent */
573 if ((parent = node->mn_parent) != NULL) {
574 KASSERT(parent->mn_info == node->mn_info,
575 ("%s(): parent has different mn_info", __func__));
576 LIST_REMOVE(node, mn_sibling);
579 if (node->mn_fileno != 0)
580 mqfs_fileno_free(node->mn_info, node);
581 if (node->mn_data != NULL)
582 mqueue_free(node->mn_data);
588 * Mount a mqfs instance
591 mqfs_mount(struct mount *mp)
595 if (mp->mnt_flag & MNT_UPDATE)
598 mp->mnt_data = &mqfs_data;
600 mp->mnt_flag |= MNT_LOCAL;
605 vfs_mountedfrom(mp, "mqueue");
606 sbp->f_bsize = PAGE_SIZE;
607 sbp->f_iosize = PAGE_SIZE;
617 * Unmount a mqfs instance
620 mqfs_unmount(struct mount *mp, int mntflags)
624 error = vflush(mp, 0, (mntflags & MNT_FORCE) ? FORCECLOSE : 0,
630 * Return a root vnode
633 mqfs_root(struct mount *mp, int flags, struct vnode **vpp)
635 struct mqfs_info *mqfs;
638 mqfs = VFSTOMQFS(mp);
639 ret = mqfs_allocv(mp, vpp, mqfs->mi_root);
644 * Return filesystem stats
647 mqfs_statfs(struct mount *mp, struct statfs *sbp)
649 /* XXX update statistics */
654 * Initialize a mqfs instance
657 mqfs_init(struct vfsconf *vfc)
659 struct mqfs_node *root;
660 struct mqfs_info *mi;
661 osd_method_t methods[PR_MAXMETHOD] = {
662 [PR_METHOD_REMOVE] = mqfs_prison_remove,
665 mqnode_zone = uma_zcreate("mqnode", sizeof(struct mqfs_node),
666 NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0);
667 mqueue_zone = uma_zcreate("mqueue", sizeof(struct mqueue),
668 NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0);
669 mvdata_zone = uma_zcreate("mvdata",
670 sizeof(struct mqfs_vdata), NULL, NULL, NULL,
671 NULL, UMA_ALIGN_PTR, 0);
672 mqnoti_zone = uma_zcreate("mqnotifier", sizeof(struct mqueue_notifier),
673 NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0);
675 sx_init(&mi->mi_lock, "mqfs lock");
676 /* set up the root diretory */
677 root = mqfs_create_node("/", 1, curthread->td_ucred, 01777,
680 LIST_INIT(&root->mn_children);
681 LIST_INIT(&root->mn_vnodes);
683 mqfs_fileno_init(mi);
684 mqfs_fileno_alloc(mi, root);
685 mqfs_fixup_dir(root);
686 exit_tag = EVENTHANDLER_REGISTER(process_exit, mq_proc_exit, NULL,
687 EVENTHANDLER_PRI_ANY);
688 mq_fdclose = mqueue_fdclose;
689 p31b_setcfg(CTL_P1003_1B_MESSAGE_PASSING, _POSIX_MESSAGE_PASSING);
690 mqfs_osd_jail_slot = osd_jail_register(NULL, methods);
695 * Destroy a mqfs instance
698 mqfs_uninit(struct vfsconf *vfc)
700 struct mqfs_info *mi;
704 osd_jail_deregister(mqfs_osd_jail_slot);
705 EVENTHANDLER_DEREGISTER(process_exit, exit_tag);
707 mqfs_destroy(mi->mi_root);
709 mqfs_fileno_uninit(mi);
710 sx_destroy(&mi->mi_lock);
711 uma_zdestroy(mqnode_zone);
712 uma_zdestroy(mqueue_zone);
713 uma_zdestroy(mvdata_zone);
714 uma_zdestroy(mqnoti_zone);
722 do_recycle(void *context, int pending __unused)
724 struct vnode *vp = (struct vnode *)context;
726 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
736 mqfs_allocv(struct mount *mp, struct vnode **vpp, struct mqfs_node *pn)
738 struct mqfs_vdata *vd;
739 struct mqfs_info *mqfs;
740 struct vnode *newvpp;
745 sx_xlock(&mqfs->mi_lock);
746 LIST_FOREACH(vd, &pn->mn_vnodes, mv_link) {
747 if (vd->mv_vnode->v_mount == mp) {
756 sx_xunlock(&mqfs->mi_lock);
757 error = vget(*vpp, LK_RETRY | LK_EXCLUSIVE, curthread);
761 sx_xunlock(&mqfs->mi_lock);
763 error = getnewvnode("mqueue", mp, &mqfs_vnodeops, &newvpp);
766 vn_lock(newvpp, LK_EXCLUSIVE | LK_RETRY);
767 error = insmntque(newvpp, mp);
771 sx_xlock(&mqfs->mi_lock);
773 * Check if it has already been allocated
774 * while we were blocked.
776 LIST_FOREACH(vd, &pn->mn_vnodes, mv_link) {
777 if (vd->mv_vnode->v_mount == mp) {
779 sx_xunlock(&mqfs->mi_lock);
789 vd = uma_zalloc(mvdata_zone, M_WAITOK);
793 TASK_INIT(&vd->mv_task, 0, do_recycle, *vpp);
794 LIST_INSERT_HEAD(&pn->mn_vnodes, vd, mv_link);
796 switch (pn->mn_type) {
798 (*vpp)->v_vflag = VV_ROOT;
802 case mqfstype_parent:
803 (*vpp)->v_type = VDIR;
806 (*vpp)->v_type = VREG;
808 case mqfstype_symlink:
809 (*vpp)->v_type = VLNK;
812 KASSERT(0, ("mqfs_allocf called for null node\n"));
814 panic("%s has unexpected type: %d", pn->mn_name, pn->mn_type);
816 sx_xunlock(&mqfs->mi_lock);
821 * Search a directory entry
823 static struct mqfs_node *
824 mqfs_search(struct mqfs_node *pd, const char *name, int len, struct ucred *cred)
826 struct mqfs_node *pn;
829 sx_assert(&pd->mn_info->mi_lock, SX_LOCKED);
830 pr_root = cred->cr_prison->pr_root;
831 LIST_FOREACH(pn, &pd->mn_children, mn_sibling) {
832 /* Only match names within the same prison root directory */
833 if ((pn->mn_pr_root == NULL || pn->mn_pr_root == pr_root) &&
834 strncmp(pn->mn_name, name, len) == 0 &&
835 pn->mn_name[len] == '\0')
842 * Look up a file or directory.
845 mqfs_lookupx(struct vop_cachedlookup_args *ap)
847 struct componentname *cnp;
848 struct vnode *dvp, **vpp;
849 struct mqfs_node *pd;
850 struct mqfs_node *pn;
851 struct mqfs_info *mqfs;
852 int nameiop, flags, error, namelen;
859 pname = cnp->cn_nameptr;
860 namelen = cnp->cn_namelen;
862 flags = cnp->cn_flags;
863 nameiop = cnp->cn_nameiop;
869 if (dvp->v_type != VDIR)
872 error = VOP_ACCESS(dvp, VEXEC, cnp->cn_cred, cnp->cn_thread);
876 /* shortcut: check if the name is too long */
877 if (cnp->cn_namelen >= MQFS_NAMELEN)
881 if (namelen == 1 && pname[0] == '.') {
882 if ((flags & ISLASTCN) && nameiop != LOOKUP)
891 if (cnp->cn_flags & ISDOTDOT) {
892 if (dvp->v_vflag & VV_ROOT)
894 if ((flags & ISLASTCN) && nameiop != LOOKUP)
897 KASSERT(pd->mn_parent, ("non-root directory has no parent"));
899 error = mqfs_allocv(dvp->v_mount, vpp, pn);
900 vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY);
905 sx_xlock(&mqfs->mi_lock);
906 pn = mqfs_search(pd, pname, namelen, cnp->cn_cred);
909 sx_xunlock(&mqfs->mi_lock);
914 if (nameiop == DELETE && (flags & ISLASTCN)) {
915 error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred, td);
929 error = mqfs_allocv(dvp->v_mount, vpp, pn);
931 if (error == 0 && cnp->cn_flags & MAKEENTRY)
932 cache_enter(dvp, *vpp, cnp);
938 /* will create a new entry in the directory ? */
939 if ((nameiop == CREATE || nameiop == RENAME) && (flags & LOCKPARENT)
940 && (flags & ISLASTCN)) {
941 error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred, td);
944 cnp->cn_flags |= SAVENAME;
945 return (EJUSTRETURN);
951 struct vop_lookup_args {
952 struct vop_generic_args a_gen;
954 struct vnode **a_vpp;
955 struct componentname *a_cnp;
960 * vnode lookup operation
963 mqfs_lookup(struct vop_cachedlookup_args *ap)
967 rc = mqfs_lookupx(ap);
972 struct vop_create_args {
974 struct vnode **a_vpp;
975 struct componentname *a_cnp;
981 * vnode creation operation
984 mqfs_create(struct vop_create_args *ap)
986 struct mqfs_info *mqfs = VFSTOMQFS(ap->a_dvp->v_mount);
987 struct componentname *cnp = ap->a_cnp;
988 struct mqfs_node *pd;
989 struct mqfs_node *pn;
993 pd = VTON(ap->a_dvp);
994 if (pd->mn_type != mqfstype_root && pd->mn_type != mqfstype_dir)
996 mq = mqueue_alloc(NULL);
999 sx_xlock(&mqfs->mi_lock);
1000 if ((cnp->cn_flags & HASBUF) == 0)
1001 panic("%s: no name", __func__);
1002 pn = mqfs_create_file(pd, cnp->cn_nameptr, cnp->cn_namelen,
1003 cnp->cn_cred, ap->a_vap->va_mode);
1005 sx_xunlock(&mqfs->mi_lock);
1009 sx_xunlock(&mqfs->mi_lock);
1010 error = mqfs_allocv(ap->a_dvp->v_mount, ap->a_vpp, pn);
1026 int do_unlink(struct mqfs_node *pn, struct ucred *ucred)
1028 struct mqfs_node *parent;
1029 struct mqfs_vdata *vd;
1032 sx_assert(&pn->mn_info->mi_lock, SX_LOCKED);
1034 if (ucred->cr_uid != pn->mn_uid &&
1035 (error = priv_check_cred(ucred, PRIV_MQ_ADMIN, 0)) != 0)
1037 else if (!pn->mn_deleted) {
1038 parent = pn->mn_parent;
1039 pn->mn_parent = NULL;
1041 LIST_REMOVE(pn, mn_sibling);
1042 LIST_FOREACH(vd, &pn->mn_vnodes, mv_link) {
1043 cache_purge(vd->mv_vnode);
1044 vhold(vd->mv_vnode);
1045 taskqueue_enqueue(taskqueue_thread, &vd->mv_task);
1048 mqnode_release(parent);
1055 struct vop_remove_args {
1056 struct vnode *a_dvp;
1058 struct componentname *a_cnp;
1063 * vnode removal operation
1066 mqfs_remove(struct vop_remove_args *ap)
1068 struct mqfs_info *mqfs = VFSTOMQFS(ap->a_dvp->v_mount);
1069 struct mqfs_node *pn;
1072 if (ap->a_vp->v_type == VDIR)
1074 pn = VTON(ap->a_vp);
1075 sx_xlock(&mqfs->mi_lock);
1076 error = do_unlink(pn, ap->a_cnp->cn_cred);
1077 sx_xunlock(&mqfs->mi_lock);
1082 struct vop_inactive_args {
1084 struct thread *a_td;
1089 mqfs_inactive(struct vop_inactive_args *ap)
1091 struct mqfs_node *pn = VTON(ap->a_vp);
1099 struct vop_reclaim_args {
1100 struct vop_generic_args a_gen;
1102 struct thread *a_td;
1107 mqfs_reclaim(struct vop_reclaim_args *ap)
1109 struct mqfs_info *mqfs = VFSTOMQFS(ap->a_vp->v_mount);
1110 struct vnode *vp = ap->a_vp;
1111 struct mqfs_node *pn;
1112 struct mqfs_vdata *vd;
1116 sx_xlock(&mqfs->mi_lock);
1118 LIST_REMOVE(vd, mv_link);
1119 uma_zfree(mvdata_zone, vd);
1121 sx_xunlock(&mqfs->mi_lock);
1126 struct vop_open_args {
1127 struct vop_generic_args a_gen;
1130 struct ucred *a_cred;
1131 struct thread *a_td;
1137 mqfs_open(struct vop_open_args *ap)
1143 struct vop_close_args {
1144 struct vop_generic_args a_gen;
1147 struct ucred *a_cred;
1148 struct thread *a_td;
1153 mqfs_close(struct vop_close_args *ap)
1159 struct vop_access_args {
1160 struct vop_generic_args a_gen;
1162 accmode_t a_accmode;
1163 struct ucred *a_cred;
1164 struct thread *a_td;
1169 * Verify permissions
1172 mqfs_access(struct vop_access_args *ap)
1174 struct vnode *vp = ap->a_vp;
1178 error = VOP_GETATTR(vp, &vattr, ap->a_cred);
1181 error = vaccess(vp->v_type, vattr.va_mode, vattr.va_uid,
1182 vattr.va_gid, ap->a_accmode, ap->a_cred, NULL);
1187 struct vop_getattr_args {
1188 struct vop_generic_args a_gen;
1190 struct vattr *a_vap;
1191 struct ucred *a_cred;
1196 * Get file attributes
1199 mqfs_getattr(struct vop_getattr_args *ap)
1201 struct vnode *vp = ap->a_vp;
1202 struct mqfs_node *pn = VTON(vp);
1203 struct vattr *vap = ap->a_vap;
1206 vap->va_type = vp->v_type;
1207 vap->va_mode = pn->mn_mode;
1209 vap->va_uid = pn->mn_uid;
1210 vap->va_gid = pn->mn_gid;
1211 vap->va_fsid = vp->v_mount->mnt_stat.f_fsid.val[0];
1212 vap->va_fileid = pn->mn_fileno;
1214 vap->va_blocksize = PAGE_SIZE;
1215 vap->va_bytes = vap->va_size = 0;
1216 vap->va_atime = pn->mn_atime;
1217 vap->va_mtime = pn->mn_mtime;
1218 vap->va_ctime = pn->mn_ctime;
1219 vap->va_birthtime = pn->mn_birth;
1222 vap->va_rdev = NODEV;
1224 vap->va_filerev = 0;
1229 struct vop_setattr_args {
1230 struct vop_generic_args a_gen;
1232 struct vattr *a_vap;
1233 struct ucred *a_cred;
1240 mqfs_setattr(struct vop_setattr_args *ap)
1242 struct mqfs_node *pn;
1253 if ((vap->va_type != VNON) ||
1254 (vap->va_nlink != VNOVAL) ||
1255 (vap->va_fsid != VNOVAL) ||
1256 (vap->va_fileid != VNOVAL) ||
1257 (vap->va_blocksize != VNOVAL) ||
1258 (vap->va_flags != VNOVAL && vap->va_flags != 0) ||
1259 (vap->va_rdev != VNOVAL) ||
1260 ((int)vap->va_bytes != VNOVAL) ||
1261 (vap->va_gen != VNOVAL)) {
1268 if (vap->va_uid == (uid_t)VNOVAL)
1272 if (vap->va_gid == (gid_t)VNOVAL)
1277 if (uid != pn->mn_uid || gid != pn->mn_gid) {
1279 * To modify the ownership of a file, must possess VADMIN
1282 if ((error = VOP_ACCESS(vp, VADMIN, ap->a_cred, td)))
1286 * XXXRW: Why is there a privilege check here: shouldn't the
1287 * check in VOP_ACCESS() be enough? Also, are the group bits
1288 * below definitely right?
1290 if (((ap->a_cred->cr_uid != pn->mn_uid) || uid != pn->mn_uid ||
1291 (gid != pn->mn_gid && !groupmember(gid, ap->a_cred))) &&
1292 (error = priv_check(td, PRIV_MQ_ADMIN)) != 0)
1299 if (vap->va_mode != (mode_t)VNOVAL) {
1300 if ((ap->a_cred->cr_uid != pn->mn_uid) &&
1301 (error = priv_check(td, PRIV_MQ_ADMIN)))
1303 pn->mn_mode = vap->va_mode;
1307 if (vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL) {
1308 /* See the comment in ufs_vnops::ufs_setattr(). */
1309 if ((error = VOP_ACCESS(vp, VADMIN, ap->a_cred, td)) &&
1310 ((vap->va_vaflags & VA_UTIMES_NULL) == 0 ||
1311 (error = VOP_ACCESS(vp, VWRITE, ap->a_cred, td))))
1313 if (vap->va_atime.tv_sec != VNOVAL) {
1314 pn->mn_atime = vap->va_atime;
1316 if (vap->va_mtime.tv_sec != VNOVAL) {
1317 pn->mn_mtime = vap->va_mtime;
1322 vfs_timestamp(&pn->mn_ctime);
1328 struct vop_read_args {
1329 struct vop_generic_args a_gen;
1333 struct ucred *a_cred;
1341 mqfs_read(struct vop_read_args *ap)
1344 struct vnode *vp = ap->a_vp;
1345 struct uio *uio = ap->a_uio;
1349 if (vp->v_type != VREG)
1353 snprintf(buf, sizeof(buf),
1354 "QSIZE:%-10ld MAXMSG:%-10ld CURMSG:%-10ld MSGSIZE:%-10ld\n",
1359 buf[sizeof(buf)-1] = '\0';
1361 error = uiomove_frombuf(buf, len, uio);
1366 struct vop_readdir_args {
1367 struct vop_generic_args a_gen;
1370 struct ucred *a_cred;
1378 * Return directory entries.
1381 mqfs_readdir(struct vop_readdir_args *ap)
1384 struct mqfs_info *mi;
1385 struct mqfs_node *pd;
1386 struct mqfs_node *pn;
1387 struct dirent entry;
1389 const void *pr_root;
1390 int *tmp_ncookies = NULL;
1395 mi = VFSTOMQFS(vp->v_mount);
1399 if (vp->v_type != VDIR)
1402 if (uio->uio_offset < 0)
1405 if (ap->a_ncookies != NULL) {
1406 tmp_ncookies = ap->a_ncookies;
1407 *ap->a_ncookies = 0;
1408 ap->a_ncookies = NULL;
1414 pr_root = ap->a_cred->cr_prison->pr_root;
1415 sx_xlock(&mi->mi_lock);
1417 LIST_FOREACH(pn, &pd->mn_children, mn_sibling) {
1418 entry.d_reclen = sizeof(entry);
1421 * Only show names within the same prison root directory
1422 * (or not associated with a prison, e.g. "." and "..").
1424 if (pn->mn_pr_root != NULL && pn->mn_pr_root != pr_root)
1427 mqfs_fileno_alloc(mi, pn);
1428 entry.d_fileno = pn->mn_fileno;
1429 for (i = 0; i < MQFS_NAMELEN - 1 && pn->mn_name[i] != '\0'; ++i)
1430 entry.d_name[i] = pn->mn_name[i];
1431 entry.d_name[i] = 0;
1433 switch (pn->mn_type) {
1437 case mqfstype_parent:
1438 entry.d_type = DT_DIR;
1441 entry.d_type = DT_REG;
1443 case mqfstype_symlink:
1444 entry.d_type = DT_LNK;
1447 panic("%s has unexpected node type: %d", pn->mn_name,
1450 if (entry.d_reclen > uio->uio_resid)
1452 if (offset >= uio->uio_offset) {
1453 error = vfs_read_dirent(ap, &entry, offset);
1457 offset += entry.d_reclen;
1459 sx_xunlock(&mi->mi_lock);
1461 uio->uio_offset = offset;
1463 if (tmp_ncookies != NULL)
1464 ap->a_ncookies = tmp_ncookies;
1472 struct vop_mkdir_args {
1473 struct vnode *a_dvp;
1474 struvt vnode **a_vpp;
1475 struvt componentname *a_cnp;
1476 struct vattr *a_vap;
1481 * Create a directory.
1484 mqfs_mkdir(struct vop_mkdir_args *ap)
1486 struct mqfs_info *mqfs = VFSTOMQFS(ap->a_dvp->v_mount);
1487 struct componentname *cnp = ap->a_cnp;
1488 struct mqfs_node *pd = VTON(ap->a_dvp);
1489 struct mqfs_node *pn;
1492 if (pd->mn_type != mqfstype_root && pd->mn_type != mqfstype_dir)
1494 sx_xlock(&mqfs->mi_lock);
1495 if ((cnp->cn_flags & HASBUF) == 0)
1496 panic("%s: no name", __func__);
1497 pn = mqfs_create_dir(pd, cnp->cn_nameptr, cnp->cn_namelen,
1498 ap->a_vap->cn_cred, ap->a_vap->va_mode);
1501 sx_xunlock(&mqfs->mi_lock);
1505 error = mqfs_allocv(ap->a_dvp->v_mount, ap->a_vpp, pn);
1512 struct vop_rmdir_args {
1513 struct vnode *a_dvp;
1515 struct componentname *a_cnp;
1520 * Remove a directory.
1523 mqfs_rmdir(struct vop_rmdir_args *ap)
1525 struct mqfs_info *mqfs = VFSTOMQFS(ap->a_dvp->v_mount);
1526 struct mqfs_node *pn = VTON(ap->a_vp);
1527 struct mqfs_node *pt;
1529 if (pn->mn_type != mqfstype_dir)
1532 sx_xlock(&mqfs->mi_lock);
1533 if (pn->mn_deleted) {
1534 sx_xunlock(&mqfs->mi_lock);
1538 pt = LIST_FIRST(&pn->mn_children);
1539 pt = LIST_NEXT(pt, mn_sibling);
1540 pt = LIST_NEXT(pt, mn_sibling);
1542 sx_xunlock(&mqfs->mi_lock);
1546 pn->mn_parent = NULL;
1548 LIST_REMOVE(pn, mn_sibling);
1551 sx_xunlock(&mqfs->mi_lock);
1552 cache_purge(ap->a_vp);
1559 * See if this prison root is obsolete, and clean up associated queues if it is.
1562 mqfs_prison_remove(void *obj, void *data __unused)
1564 const struct prison *pr = obj;
1565 const struct prison *tpr;
1566 struct mqfs_node *pn, *tpn;
1570 TAILQ_FOREACH(tpr, &allprison, pr_list) {
1571 if (tpr->pr_root == pr->pr_root && tpr != pr && tpr->pr_ref > 0)
1576 * No jails are rooted in this directory anymore,
1577 * so no queues should be either.
1579 sx_xlock(&mqfs_data.mi_lock);
1580 LIST_FOREACH_SAFE(pn, &mqfs_data.mi_root->mn_children,
1582 if (pn->mn_pr_root == pr->pr_root)
1583 (void)do_unlink(pn, curthread->td_ucred);
1585 sx_xunlock(&mqfs_data.mi_lock);
1591 * Allocate a message queue
1593 static struct mqueue *
1594 mqueue_alloc(const struct mq_attr *attr)
1600 mq = uma_zalloc(mqueue_zone, M_WAITOK | M_ZERO);
1601 TAILQ_INIT(&mq->mq_msgq);
1603 mq->mq_maxmsg = attr->mq_maxmsg;
1604 mq->mq_msgsize = attr->mq_msgsize;
1606 mq->mq_maxmsg = default_maxmsg;
1607 mq->mq_msgsize = default_msgsize;
1609 mtx_init(&mq->mq_mutex, "mqueue lock", NULL, MTX_DEF);
1610 knlist_init_mtx(&mq->mq_rsel.si_note, &mq->mq_mutex);
1611 knlist_init_mtx(&mq->mq_wsel.si_note, &mq->mq_mutex);
1612 atomic_add_int(&curmq, 1);
1617 * Destroy a message queue
1620 mqueue_free(struct mqueue *mq)
1622 struct mqueue_msg *msg;
1624 while ((msg = TAILQ_FIRST(&mq->mq_msgq)) != NULL) {
1625 TAILQ_REMOVE(&mq->mq_msgq, msg, msg_link);
1626 free(msg, M_MQUEUEDATA);
1629 mtx_destroy(&mq->mq_mutex);
1630 seldrain(&mq->mq_rsel);
1631 seldrain(&mq->mq_wsel);
1632 knlist_destroy(&mq->mq_rsel.si_note);
1633 knlist_destroy(&mq->mq_wsel.si_note);
1634 uma_zfree(mqueue_zone, mq);
1635 atomic_add_int(&curmq, -1);
1639 * Load a message from user space
1641 static struct mqueue_msg *
1642 mqueue_loadmsg(const char *msg_ptr, size_t msg_size, int msg_prio)
1644 struct mqueue_msg *msg;
1648 len = sizeof(struct mqueue_msg) + msg_size;
1649 msg = malloc(len, M_MQUEUEDATA, M_WAITOK);
1650 error = copyin(msg_ptr, ((char *)msg) + sizeof(struct mqueue_msg),
1653 free(msg, M_MQUEUEDATA);
1656 msg->msg_size = msg_size;
1657 msg->msg_prio = msg_prio;
1663 * Save a message to user space
1666 mqueue_savemsg(struct mqueue_msg *msg, char *msg_ptr, int *msg_prio)
1670 error = copyout(((char *)msg) + sizeof(*msg), msg_ptr,
1672 if (error == 0 && msg_prio != NULL)
1673 error = copyout(&msg->msg_prio, msg_prio, sizeof(int));
1678 * Free a message's memory
1680 static __inline void
1681 mqueue_freemsg(struct mqueue_msg *msg)
1683 free(msg, M_MQUEUEDATA);
1687 * Send a message. if waitok is false, thread will not be
1688 * blocked if there is no data in queue, otherwise, absolute
1689 * time will be checked.
1692 mqueue_send(struct mqueue *mq, const char *msg_ptr,
1693 size_t msg_len, unsigned msg_prio, int waitok,
1694 const struct timespec *abs_timeout)
1696 struct mqueue_msg *msg;
1697 struct timespec ts, ts2;
1701 if (msg_prio >= MQ_PRIO_MAX)
1703 if (msg_len > mq->mq_msgsize)
1705 msg = mqueue_loadmsg(msg_ptr, msg_len, msg_prio);
1709 /* O_NONBLOCK case */
1711 error = _mqueue_send(mq, msg, -1);
1717 /* we allow a null timeout (wait forever) */
1718 if (abs_timeout == NULL) {
1719 error = _mqueue_send(mq, msg, 0);
1725 /* send it before checking time */
1726 error = _mqueue_send(mq, msg, -1);
1730 if (error != EAGAIN)
1733 if (abs_timeout->tv_nsec >= 1000000000 || abs_timeout->tv_nsec < 0) {
1739 timespecsub(abs_timeout, &ts, &ts2);
1740 if (ts2.tv_sec < 0 || (ts2.tv_sec == 0 && ts2.tv_nsec <= 0)) {
1744 TIMESPEC_TO_TIMEVAL(&tv, &ts2);
1745 error = _mqueue_send(mq, msg, tvtohz(&tv));
1746 if (error != ETIMEDOUT)
1752 mqueue_freemsg(msg);
1757 * Common routine to send a message
1760 _mqueue_send(struct mqueue *mq, struct mqueue_msg *msg, int timo)
1762 struct mqueue_msg *msg2;
1765 mtx_lock(&mq->mq_mutex);
1766 while (mq->mq_curmsgs >= mq->mq_maxmsg && error == 0) {
1768 mtx_unlock(&mq->mq_mutex);
1772 error = msleep(&mq->mq_senders, &mq->mq_mutex,
1773 PCATCH, "mqsend", timo);
1775 if (error == EAGAIN)
1778 if (mq->mq_curmsgs >= mq->mq_maxmsg) {
1779 mtx_unlock(&mq->mq_mutex);
1783 if (TAILQ_EMPTY(&mq->mq_msgq)) {
1784 TAILQ_INSERT_HEAD(&mq->mq_msgq, msg, msg_link);
1786 if (msg->msg_prio <= TAILQ_LAST(&mq->mq_msgq, msgq)->msg_prio) {
1787 TAILQ_INSERT_TAIL(&mq->mq_msgq, msg, msg_link);
1789 TAILQ_FOREACH(msg2, &mq->mq_msgq, msg_link) {
1790 if (msg2->msg_prio < msg->msg_prio)
1793 TAILQ_INSERT_BEFORE(msg2, msg, msg_link);
1797 mq->mq_totalbytes += msg->msg_size;
1798 if (mq->mq_receivers)
1799 wakeup_one(&mq->mq_receivers);
1800 else if (mq->mq_notifier != NULL)
1801 mqueue_send_notification(mq);
1802 if (mq->mq_flags & MQ_RSEL) {
1803 mq->mq_flags &= ~MQ_RSEL;
1804 selwakeup(&mq->mq_rsel);
1806 KNOTE_LOCKED(&mq->mq_rsel.si_note, 0);
1807 mtx_unlock(&mq->mq_mutex);
1812 * Send realtime a signal to process which registered itself
1813 * successfully by mq_notify.
1816 mqueue_send_notification(struct mqueue *mq)
1818 struct mqueue_notifier *nt;
1823 mtx_assert(&mq->mq_mutex, MA_OWNED);
1824 nt = mq->mq_notifier;
1825 if (nt->nt_sigev.sigev_notify != SIGEV_NONE) {
1827 error = sigev_findtd(p, &nt->nt_sigev, &td);
1829 mq->mq_notifier = NULL;
1832 if (!KSI_ONQ(&nt->nt_ksi)) {
1833 ksiginfo_set_sigev(&nt->nt_ksi, &nt->nt_sigev);
1834 tdsendsignal(p, td, nt->nt_ksi.ksi_signo, &nt->nt_ksi);
1838 mq->mq_notifier = NULL;
1842 * Get a message. if waitok is false, thread will not be
1843 * blocked if there is no data in queue, otherwise, absolute
1844 * time will be checked.
1847 mqueue_receive(struct mqueue *mq, char *msg_ptr,
1848 size_t msg_len, unsigned *msg_prio, int waitok,
1849 const struct timespec *abs_timeout)
1851 struct mqueue_msg *msg;
1852 struct timespec ts, ts2;
1856 if (msg_len < mq->mq_msgsize)
1859 /* O_NONBLOCK case */
1861 error = _mqueue_recv(mq, &msg, -1);
1867 /* we allow a null timeout (wait forever). */
1868 if (abs_timeout == NULL) {
1869 error = _mqueue_recv(mq, &msg, 0);
1875 /* try to get a message before checking time */
1876 error = _mqueue_recv(mq, &msg, -1);
1880 if (error != EAGAIN)
1883 if (abs_timeout->tv_nsec >= 1000000000 || abs_timeout->tv_nsec < 0) {
1890 timespecsub(abs_timeout, &ts, &ts2);
1891 if (ts2.tv_sec < 0 || (ts2.tv_sec == 0 && ts2.tv_nsec <= 0)) {
1895 TIMESPEC_TO_TIMEVAL(&tv, &ts2);
1896 error = _mqueue_recv(mq, &msg, tvtohz(&tv));
1899 if (error != ETIMEDOUT)
1904 error = mqueue_savemsg(msg, msg_ptr, msg_prio);
1906 curthread->td_retval[0] = msg->msg_size;
1907 curthread->td_retval[1] = 0;
1909 mqueue_freemsg(msg);
1914 * Common routine to receive a message
1917 _mqueue_recv(struct mqueue *mq, struct mqueue_msg **msg, int timo)
1921 mtx_lock(&mq->mq_mutex);
1922 while ((*msg = TAILQ_FIRST(&mq->mq_msgq)) == NULL && error == 0) {
1924 mtx_unlock(&mq->mq_mutex);
1928 error = msleep(&mq->mq_receivers, &mq->mq_mutex,
1929 PCATCH, "mqrecv", timo);
1931 if (error == EAGAIN)
1936 TAILQ_REMOVE(&mq->mq_msgq, *msg, msg_link);
1938 mq->mq_totalbytes -= (*msg)->msg_size;
1940 wakeup_one(&mq->mq_senders);
1941 if (mq->mq_flags & MQ_WSEL) {
1942 mq->mq_flags &= ~MQ_WSEL;
1943 selwakeup(&mq->mq_wsel);
1945 KNOTE_LOCKED(&mq->mq_wsel.si_note, 0);
1947 if (mq->mq_notifier != NULL && mq->mq_receivers == 0 &&
1948 !TAILQ_EMPTY(&mq->mq_msgq)) {
1949 mqueue_send_notification(mq);
1951 mtx_unlock(&mq->mq_mutex);
1955 static __inline struct mqueue_notifier *
1956 notifier_alloc(void)
1958 return (uma_zalloc(mqnoti_zone, M_WAITOK | M_ZERO));
1961 static __inline void
1962 notifier_free(struct mqueue_notifier *p)
1964 uma_zfree(mqnoti_zone, p);
1967 static struct mqueue_notifier *
1968 notifier_search(struct proc *p, int fd)
1970 struct mqueue_notifier *nt;
1972 LIST_FOREACH(nt, &p->p_mqnotifier, nt_link) {
1973 if (nt->nt_ksi.ksi_mqd == fd)
1979 static __inline void
1980 notifier_insert(struct proc *p, struct mqueue_notifier *nt)
1982 LIST_INSERT_HEAD(&p->p_mqnotifier, nt, nt_link);
1985 static __inline void
1986 notifier_delete(struct proc *p, struct mqueue_notifier *nt)
1988 LIST_REMOVE(nt, nt_link);
1993 notifier_remove(struct proc *p, struct mqueue *mq, int fd)
1995 struct mqueue_notifier *nt;
1997 mtx_assert(&mq->mq_mutex, MA_OWNED);
1999 nt = notifier_search(p, fd);
2001 if (mq->mq_notifier == nt)
2002 mq->mq_notifier = NULL;
2003 sigqueue_take(&nt->nt_ksi);
2004 notifier_delete(p, nt);
2010 kern_kmq_open(struct thread *td, const char *upath, int flags, mode_t mode,
2011 const struct mq_attr *attr)
2013 char path[MQFS_NAMELEN + 1];
2014 struct mqfs_node *pn;
2015 struct filedesc *fdp;
2018 int fd, error, len, cmode;
2020 AUDIT_ARG_FFLAGS(flags);
2021 AUDIT_ARG_MODE(mode);
2023 fdp = td->td_proc->p_fd;
2024 cmode = (((mode & ~fdp->fd_cmask) & ALLPERMS) & ~S_ISTXT);
2026 if ((flags & O_CREAT) != 0 && attr != NULL) {
2027 if (attr->mq_maxmsg <= 0 || attr->mq_maxmsg > maxmsg)
2029 if (attr->mq_msgsize <= 0 || attr->mq_msgsize > maxmsgsize)
2033 error = copyinstr(upath, path, MQFS_NAMELEN + 1, NULL);
2038 * The first character of name must be a slash (/) character
2039 * and the remaining characters of name cannot include any slash
2043 if (len < 2 || path[0] != '/' || strchr(path + 1, '/') != NULL)
2045 AUDIT_ARG_UPATH1_CANON(path);
2047 error = falloc(td, &fp, &fd, O_CLOEXEC);
2051 sx_xlock(&mqfs_data.mi_lock);
2052 pn = mqfs_search(mqfs_data.mi_root, path + 1, len - 1, td->td_ucred);
2054 if (!(flags & O_CREAT)) {
2057 mq = mqueue_alloc(attr);
2061 pn = mqfs_create_file(mqfs_data.mi_root,
2062 path + 1, len - 1, td->td_ucred,
2075 if ((flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL)) {
2078 accmode_t accmode = 0;
2084 error = vaccess(VREG, pn->mn_mode, pn->mn_uid,
2085 pn->mn_gid, accmode, td->td_ucred, NULL);
2090 sx_xunlock(&mqfs_data.mi_lock);
2091 fdclose(td, fp, fd);
2097 sx_xunlock(&mqfs_data.mi_lock);
2099 finit(fp, flags & (FREAD | FWRITE | O_NONBLOCK), DTYPE_MQUEUE, pn,
2102 td->td_retval[0] = fd;
2108 * Syscall to open a message queue.
2111 sys_kmq_open(struct thread *td, struct kmq_open_args *uap)
2113 struct mq_attr attr;
2116 if ((uap->flags & O_ACCMODE) == O_ACCMODE || uap->flags & O_EXEC)
2118 flags = FFLAGS(uap->flags);
2119 if ((flags & O_CREAT) != 0 && uap->attr != NULL) {
2120 error = copyin(uap->attr, &attr, sizeof(attr));
2124 return (kern_kmq_open(td, uap->path, flags, uap->mode,
2125 uap->attr != NULL ? &attr : NULL));
2129 * Syscall to unlink a message queue.
2132 sys_kmq_unlink(struct thread *td, struct kmq_unlink_args *uap)
2134 char path[MQFS_NAMELEN+1];
2135 struct mqfs_node *pn;
2138 error = copyinstr(uap->path, path, MQFS_NAMELEN + 1, NULL);
2143 if (len < 2 || path[0] != '/' || strchr(path + 1, '/') != NULL)
2145 AUDIT_ARG_UPATH1_CANON(path);
2147 sx_xlock(&mqfs_data.mi_lock);
2148 pn = mqfs_search(mqfs_data.mi_root, path + 1, len - 1, td->td_ucred);
2150 error = do_unlink(pn, td->td_ucred);
2153 sx_xunlock(&mqfs_data.mi_lock);
2157 typedef int (*_fgetf)(struct thread *, int, cap_rights_t *, struct file **);
2160 * Get message queue by giving file slot
2163 _getmq(struct thread *td, int fd, cap_rights_t *rightsp, _fgetf func,
2164 struct file **fpp, struct mqfs_node **ppn, struct mqueue **pmq)
2166 struct mqfs_node *pn;
2169 error = func(td, fd, rightsp, fpp);
2172 if (&mqueueops != (*fpp)->f_ops) {
2176 pn = (*fpp)->f_data;
2185 getmq(struct thread *td, int fd, struct file **fpp, struct mqfs_node **ppn,
2186 struct mqueue **pmq)
2189 return _getmq(td, fd, &cap_event_rights, fget,
2194 getmq_read(struct thread *td, int fd, struct file **fpp,
2195 struct mqfs_node **ppn, struct mqueue **pmq)
2198 return _getmq(td, fd, &cap_read_rights, fget_read,
2203 getmq_write(struct thread *td, int fd, struct file **fpp,
2204 struct mqfs_node **ppn, struct mqueue **pmq)
2207 return _getmq(td, fd, &cap_write_rights, fget_write,
2212 kern_kmq_setattr(struct thread *td, int mqd, const struct mq_attr *attr,
2213 struct mq_attr *oattr)
2221 if (attr != NULL && (attr->mq_flags & ~O_NONBLOCK) != 0)
2223 error = getmq(td, mqd, &fp, NULL, &mq);
2226 oattr->mq_maxmsg = mq->mq_maxmsg;
2227 oattr->mq_msgsize = mq->mq_msgsize;
2228 oattr->mq_curmsgs = mq->mq_curmsgs;
2231 oflag = flag = fp->f_flag;
2232 flag &= ~O_NONBLOCK;
2233 flag |= (attr->mq_flags & O_NONBLOCK);
2234 } while (atomic_cmpset_int(&fp->f_flag, oflag, flag) == 0);
2237 oattr->mq_flags = (O_NONBLOCK & oflag);
2243 sys_kmq_setattr(struct thread *td, struct kmq_setattr_args *uap)
2245 struct mq_attr attr, oattr;
2248 if (uap->attr != NULL) {
2249 error = copyin(uap->attr, &attr, sizeof(attr));
2253 error = kern_kmq_setattr(td, uap->mqd, uap->attr != NULL ? &attr : NULL,
2255 if (error == 0 && uap->oattr != NULL) {
2256 bzero(oattr.__reserved, sizeof(oattr.__reserved));
2257 error = copyout(&oattr, uap->oattr, sizeof(oattr));
2263 sys_kmq_timedreceive(struct thread *td, struct kmq_timedreceive_args *uap)
2267 struct timespec *abs_timeout, ets;
2271 AUDIT_ARG_FD(uap->mqd);
2272 error = getmq_read(td, uap->mqd, &fp, NULL, &mq);
2275 if (uap->abs_timeout != NULL) {
2276 error = copyin(uap->abs_timeout, &ets, sizeof(ets));
2282 waitok = !(fp->f_flag & O_NONBLOCK);
2283 error = mqueue_receive(mq, uap->msg_ptr, uap->msg_len,
2284 uap->msg_prio, waitok, abs_timeout);
2290 sys_kmq_timedsend(struct thread *td, struct kmq_timedsend_args *uap)
2294 struct timespec *abs_timeout, ets;
2297 AUDIT_ARG_FD(uap->mqd);
2298 error = getmq_write(td, uap->mqd, &fp, NULL, &mq);
2301 if (uap->abs_timeout != NULL) {
2302 error = copyin(uap->abs_timeout, &ets, sizeof(ets));
2308 waitok = !(fp->f_flag & O_NONBLOCK);
2309 error = mqueue_send(mq, uap->msg_ptr, uap->msg_len,
2310 uap->msg_prio, waitok, abs_timeout);
2316 kern_kmq_notify(struct thread *td, int mqd, struct sigevent *sigev)
2318 struct filedesc *fdp;
2321 struct file *fp, *fp2;
2322 struct mqueue_notifier *nt, *newnt = NULL;
2326 if (sigev != NULL) {
2327 if (sigev->sigev_notify != SIGEV_SIGNAL &&
2328 sigev->sigev_notify != SIGEV_THREAD_ID &&
2329 sigev->sigev_notify != SIGEV_NONE)
2331 if ((sigev->sigev_notify == SIGEV_SIGNAL ||
2332 sigev->sigev_notify == SIGEV_THREAD_ID) &&
2333 !_SIG_VALID(sigev->sigev_signo))
2337 fdp = td->td_proc->p_fd;
2338 error = getmq(td, mqd, &fp, NULL, &mq);
2342 FILEDESC_SLOCK(fdp);
2343 fp2 = fget_locked(fdp, mqd);
2345 FILEDESC_SUNLOCK(fdp);
2350 error = cap_check(cap_rights(fdp, mqd), &cap_event_rights);
2352 FILEDESC_SUNLOCK(fdp);
2357 FILEDESC_SUNLOCK(fdp);
2361 mtx_lock(&mq->mq_mutex);
2362 FILEDESC_SUNLOCK(fdp);
2363 if (sigev != NULL) {
2364 if (mq->mq_notifier != NULL) {
2368 nt = notifier_search(p, mqd);
2370 if (newnt == NULL) {
2372 mtx_unlock(&mq->mq_mutex);
2373 newnt = notifier_alloc();
2379 sigqueue_take(&nt->nt_ksi);
2380 if (newnt != NULL) {
2381 notifier_free(newnt);
2387 ksiginfo_init(&nt->nt_ksi);
2388 nt->nt_ksi.ksi_flags |= KSI_INS | KSI_EXT;
2389 nt->nt_ksi.ksi_code = SI_MESGQ;
2391 nt->nt_ksi.ksi_mqd = mqd;
2392 notifier_insert(p, nt);
2394 nt->nt_sigev = *sigev;
2395 mq->mq_notifier = nt;
2398 * if there is no receivers and message queue
2399 * is not empty, we should send notification
2400 * as soon as possible.
2402 if (mq->mq_receivers == 0 &&
2403 !TAILQ_EMPTY(&mq->mq_msgq))
2404 mqueue_send_notification(mq);
2407 notifier_remove(p, mq, mqd);
2409 mtx_unlock(&mq->mq_mutex);
2414 notifier_free(newnt);
2419 sys_kmq_notify(struct thread *td, struct kmq_notify_args *uap)
2421 struct sigevent ev, *evp;
2424 if (uap->sigev == NULL) {
2427 error = copyin(uap->sigev, &ev, sizeof(ev));
2432 return (kern_kmq_notify(td, uap->mqd, evp));
2436 mqueue_fdclose(struct thread *td, int fd, struct file *fp)
2440 struct filedesc *fdp;
2442 fdp = td->td_proc->p_fd;
2443 FILEDESC_LOCK_ASSERT(fdp);
2446 if (fp->f_ops == &mqueueops) {
2448 mtx_lock(&mq->mq_mutex);
2449 notifier_remove(td->td_proc, mq, fd);
2451 /* have to wakeup thread in same process */
2452 if (mq->mq_flags & MQ_RSEL) {
2453 mq->mq_flags &= ~MQ_RSEL;
2454 selwakeup(&mq->mq_rsel);
2456 if (mq->mq_flags & MQ_WSEL) {
2457 mq->mq_flags &= ~MQ_WSEL;
2458 selwakeup(&mq->mq_wsel);
2460 mtx_unlock(&mq->mq_mutex);
2465 mq_proc_exit(void *arg __unused, struct proc *p)
2467 struct filedesc *fdp;
2473 FILEDESC_SLOCK(fdp);
2474 for (i = 0; i < fdp->fd_nfiles; ++i) {
2475 fp = fget_locked(fdp, i);
2476 if (fp != NULL && fp->f_ops == &mqueueops) {
2478 mtx_lock(&mq->mq_mutex);
2479 notifier_remove(p, FPTOMQ(fp), i);
2480 mtx_unlock(&mq->mq_mutex);
2483 FILEDESC_SUNLOCK(fdp);
2484 KASSERT(LIST_EMPTY(&p->p_mqnotifier), ("mq notifiers left"));
2488 mqf_poll(struct file *fp, int events, struct ucred *active_cred,
2491 struct mqueue *mq = FPTOMQ(fp);
2494 mtx_lock(&mq->mq_mutex);
2495 if (events & (POLLIN | POLLRDNORM)) {
2496 if (mq->mq_curmsgs) {
2497 revents |= events & (POLLIN | POLLRDNORM);
2499 mq->mq_flags |= MQ_RSEL;
2500 selrecord(td, &mq->mq_rsel);
2503 if (events & POLLOUT) {
2504 if (mq->mq_curmsgs < mq->mq_maxmsg)
2507 mq->mq_flags |= MQ_WSEL;
2508 selrecord(td, &mq->mq_wsel);
2511 mtx_unlock(&mq->mq_mutex);
2516 mqf_close(struct file *fp, struct thread *td)
2518 struct mqfs_node *pn;
2520 fp->f_ops = &badfileops;
2523 sx_xlock(&mqfs_data.mi_lock);
2525 sx_xunlock(&mqfs_data.mi_lock);
2530 mqf_stat(struct file *fp, struct stat *st, struct ucred *active_cred,
2533 struct mqfs_node *pn = fp->f_data;
2535 bzero(st, sizeof *st);
2536 sx_xlock(&mqfs_data.mi_lock);
2537 st->st_atim = pn->mn_atime;
2538 st->st_mtim = pn->mn_mtime;
2539 st->st_ctim = pn->mn_ctime;
2540 st->st_birthtim = pn->mn_birth;
2541 st->st_uid = pn->mn_uid;
2542 st->st_gid = pn->mn_gid;
2543 st->st_mode = S_IFIFO | pn->mn_mode;
2544 sx_xunlock(&mqfs_data.mi_lock);
2549 mqf_chmod(struct file *fp, mode_t mode, struct ucred *active_cred,
2552 struct mqfs_node *pn;
2557 sx_xlock(&mqfs_data.mi_lock);
2558 error = vaccess(VREG, pn->mn_mode, pn->mn_uid, pn->mn_gid, VADMIN,
2562 pn->mn_mode = mode & ACCESSPERMS;
2564 sx_xunlock(&mqfs_data.mi_lock);
2569 mqf_chown(struct file *fp, uid_t uid, gid_t gid, struct ucred *active_cred,
2572 struct mqfs_node *pn;
2577 sx_xlock(&mqfs_data.mi_lock);
2578 if (uid == (uid_t)-1)
2580 if (gid == (gid_t)-1)
2582 if (((uid != pn->mn_uid && uid != active_cred->cr_uid) ||
2583 (gid != pn->mn_gid && !groupmember(gid, active_cred))) &&
2584 (error = priv_check_cred(active_cred, PRIV_VFS_CHOWN, 0)))
2589 sx_xunlock(&mqfs_data.mi_lock);
2594 mqf_kqfilter(struct file *fp, struct knote *kn)
2596 struct mqueue *mq = FPTOMQ(fp);
2599 if (kn->kn_filter == EVFILT_READ) {
2600 kn->kn_fop = &mq_rfiltops;
2601 knlist_add(&mq->mq_rsel.si_note, kn, 0);
2602 } else if (kn->kn_filter == EVFILT_WRITE) {
2603 kn->kn_fop = &mq_wfiltops;
2604 knlist_add(&mq->mq_wsel.si_note, kn, 0);
2611 filt_mqdetach(struct knote *kn)
2613 struct mqueue *mq = FPTOMQ(kn->kn_fp);
2615 if (kn->kn_filter == EVFILT_READ)
2616 knlist_remove(&mq->mq_rsel.si_note, kn, 0);
2617 else if (kn->kn_filter == EVFILT_WRITE)
2618 knlist_remove(&mq->mq_wsel.si_note, kn, 0);
2620 panic("filt_mqdetach");
2624 filt_mqread(struct knote *kn, long hint)
2626 struct mqueue *mq = FPTOMQ(kn->kn_fp);
2628 mtx_assert(&mq->mq_mutex, MA_OWNED);
2629 return (mq->mq_curmsgs != 0);
2633 filt_mqwrite(struct knote *kn, long hint)
2635 struct mqueue *mq = FPTOMQ(kn->kn_fp);
2637 mtx_assert(&mq->mq_mutex, MA_OWNED);
2638 return (mq->mq_curmsgs < mq->mq_maxmsg);
2642 mqf_fill_kinfo(struct file *fp, struct kinfo_file *kif, struct filedesc *fdp)
2645 kif->kf_type = KF_TYPE_MQUEUE;
2649 static struct fileops mqueueops = {
2650 .fo_read = invfo_rdwr,
2651 .fo_write = invfo_rdwr,
2652 .fo_truncate = invfo_truncate,
2653 .fo_ioctl = invfo_ioctl,
2654 .fo_poll = mqf_poll,
2655 .fo_kqfilter = mqf_kqfilter,
2656 .fo_stat = mqf_stat,
2657 .fo_close = mqf_close,
2658 .fo_chmod = mqf_chmod,
2659 .fo_chown = mqf_chown,
2660 .fo_sendfile = invfo_sendfile,
2661 .fo_fill_kinfo = mqf_fill_kinfo,
2664 static struct vop_vector mqfs_vnodeops = {
2665 .vop_default = &default_vnodeops,
2666 .vop_access = mqfs_access,
2667 .vop_cachedlookup = mqfs_lookup,
2668 .vop_lookup = vfs_cache_lookup,
2669 .vop_reclaim = mqfs_reclaim,
2670 .vop_create = mqfs_create,
2671 .vop_remove = mqfs_remove,
2672 .vop_inactive = mqfs_inactive,
2673 .vop_open = mqfs_open,
2674 .vop_close = mqfs_close,
2675 .vop_getattr = mqfs_getattr,
2676 .vop_setattr = mqfs_setattr,
2677 .vop_read = mqfs_read,
2678 .vop_write = VOP_EOPNOTSUPP,
2679 .vop_readdir = mqfs_readdir,
2680 .vop_mkdir = VOP_EOPNOTSUPP,
2681 .vop_rmdir = VOP_EOPNOTSUPP
2684 static struct vfsops mqfs_vfsops = {
2685 .vfs_init = mqfs_init,
2686 .vfs_uninit = mqfs_uninit,
2687 .vfs_mount = mqfs_mount,
2688 .vfs_unmount = mqfs_unmount,
2689 .vfs_root = mqfs_root,
2690 .vfs_statfs = mqfs_statfs,
2693 static struct vfsconf mqueuefs_vfsconf = {
2694 .vfc_version = VFS_VERSION,
2695 .vfc_name = "mqueuefs",
2696 .vfc_vfsops = &mqfs_vfsops,
2698 .vfc_flags = VFCF_SYNTHETIC
2701 static struct syscall_helper_data mq_syscalls[] = {
2702 SYSCALL_INIT_HELPER(kmq_open),
2703 SYSCALL_INIT_HELPER_F(kmq_setattr, SYF_CAPENABLED),
2704 SYSCALL_INIT_HELPER_F(kmq_timedsend, SYF_CAPENABLED),
2705 SYSCALL_INIT_HELPER_F(kmq_timedreceive, SYF_CAPENABLED),
2706 SYSCALL_INIT_HELPER_F(kmq_notify, SYF_CAPENABLED),
2707 SYSCALL_INIT_HELPER(kmq_unlink),
2711 #ifdef COMPAT_FREEBSD32
2712 #include <compat/freebsd32/freebsd32.h>
2713 #include <compat/freebsd32/freebsd32_proto.h>
2714 #include <compat/freebsd32/freebsd32_signal.h>
2715 #include <compat/freebsd32/freebsd32_syscall.h>
2716 #include <compat/freebsd32/freebsd32_util.h>
2719 mq_attr_from32(const struct mq_attr32 *from, struct mq_attr *to)
2722 to->mq_flags = from->mq_flags;
2723 to->mq_maxmsg = from->mq_maxmsg;
2724 to->mq_msgsize = from->mq_msgsize;
2725 to->mq_curmsgs = from->mq_curmsgs;
2729 mq_attr_to32(const struct mq_attr *from, struct mq_attr32 *to)
2732 to->mq_flags = from->mq_flags;
2733 to->mq_maxmsg = from->mq_maxmsg;
2734 to->mq_msgsize = from->mq_msgsize;
2735 to->mq_curmsgs = from->mq_curmsgs;
2739 freebsd32_kmq_open(struct thread *td, struct freebsd32_kmq_open_args *uap)
2741 struct mq_attr attr;
2742 struct mq_attr32 attr32;
2745 if ((uap->flags & O_ACCMODE) == O_ACCMODE || uap->flags & O_EXEC)
2747 flags = FFLAGS(uap->flags);
2748 if ((flags & O_CREAT) != 0 && uap->attr != NULL) {
2749 error = copyin(uap->attr, &attr32, sizeof(attr32));
2752 mq_attr_from32(&attr32, &attr);
2754 return (kern_kmq_open(td, uap->path, flags, uap->mode,
2755 uap->attr != NULL ? &attr : NULL));
2759 freebsd32_kmq_setattr(struct thread *td, struct freebsd32_kmq_setattr_args *uap)
2761 struct mq_attr attr, oattr;
2762 struct mq_attr32 attr32, oattr32;
2765 if (uap->attr != NULL) {
2766 error = copyin(uap->attr, &attr32, sizeof(attr32));
2769 mq_attr_from32(&attr32, &attr);
2771 error = kern_kmq_setattr(td, uap->mqd, uap->attr != NULL ? &attr : NULL,
2773 if (error == 0 && uap->oattr != NULL) {
2774 mq_attr_to32(&oattr, &oattr32);
2775 bzero(oattr32.__reserved, sizeof(oattr32.__reserved));
2776 error = copyout(&oattr32, uap->oattr, sizeof(oattr32));
2782 freebsd32_kmq_timedsend(struct thread *td,
2783 struct freebsd32_kmq_timedsend_args *uap)
2787 struct timespec32 ets32;
2788 struct timespec *abs_timeout, ets;
2792 AUDIT_ARG_FD(uap->mqd);
2793 error = getmq_write(td, uap->mqd, &fp, NULL, &mq);
2796 if (uap->abs_timeout != NULL) {
2797 error = copyin(uap->abs_timeout, &ets32, sizeof(ets32));
2800 CP(ets32, ets, tv_sec);
2801 CP(ets32, ets, tv_nsec);
2805 waitok = !(fp->f_flag & O_NONBLOCK);
2806 error = mqueue_send(mq, uap->msg_ptr, uap->msg_len,
2807 uap->msg_prio, waitok, abs_timeout);
2813 freebsd32_kmq_timedreceive(struct thread *td,
2814 struct freebsd32_kmq_timedreceive_args *uap)
2818 struct timespec32 ets32;
2819 struct timespec *abs_timeout, ets;
2822 AUDIT_ARG_FD(uap->mqd);
2823 error = getmq_read(td, uap->mqd, &fp, NULL, &mq);
2826 if (uap->abs_timeout != NULL) {
2827 error = copyin(uap->abs_timeout, &ets32, sizeof(ets32));
2830 CP(ets32, ets, tv_sec);
2831 CP(ets32, ets, tv_nsec);
2835 waitok = !(fp->f_flag & O_NONBLOCK);
2836 error = mqueue_receive(mq, uap->msg_ptr, uap->msg_len,
2837 uap->msg_prio, waitok, abs_timeout);
2843 freebsd32_kmq_notify(struct thread *td, struct freebsd32_kmq_notify_args *uap)
2845 struct sigevent ev, *evp;
2846 struct sigevent32 ev32;
2849 if (uap->sigev == NULL) {
2852 error = copyin(uap->sigev, &ev32, sizeof(ev32));
2855 error = convert_sigevent32(&ev32, &ev);
2860 return (kern_kmq_notify(td, uap->mqd, evp));
2863 static struct syscall_helper_data mq32_syscalls[] = {
2864 SYSCALL32_INIT_HELPER(freebsd32_kmq_open),
2865 SYSCALL32_INIT_HELPER_F(freebsd32_kmq_setattr, SYF_CAPENABLED),
2866 SYSCALL32_INIT_HELPER_F(freebsd32_kmq_timedsend, SYF_CAPENABLED),
2867 SYSCALL32_INIT_HELPER_F(freebsd32_kmq_timedreceive, SYF_CAPENABLED),
2868 SYSCALL32_INIT_HELPER_F(freebsd32_kmq_notify, SYF_CAPENABLED),
2869 SYSCALL32_INIT_HELPER_COMPAT(kmq_unlink),
2879 error = syscall_helper_register(mq_syscalls, SY_THR_STATIC_KLD);
2882 #ifdef COMPAT_FREEBSD32
2883 error = syscall32_helper_register(mq32_syscalls, SY_THR_STATIC_KLD);
2894 #ifdef COMPAT_FREEBSD32
2895 syscall32_helper_unregister(mq32_syscalls);
2897 syscall_helper_unregister(mq_syscalls);
2902 mq_modload(struct module *module, int cmd, void *arg)
2906 error = vfs_modevent(module, cmd, arg);
2925 static moduledata_t mqueuefs_mod = {
2930 DECLARE_MODULE(mqueuefs, mqueuefs_mod, SI_SUB_VFS, SI_ORDER_MIDDLE);
2931 MODULE_VERSION(mqueuefs, 1);