2 * SPDX-License-Identifier: BSD-2-Clause
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 #include "opt_capsicum.h"
56 #include <sys/param.h>
57 #include <sys/kernel.h>
58 #include <sys/systm.h>
59 #include <sys/limits.h>
60 #include <sys/malloc.h>
62 #include <sys/capsicum.h>
63 #include <sys/dirent.h>
64 #include <sys/event.h>
65 #include <sys/eventhandler.h>
66 #include <sys/fcntl.h>
68 #include <sys/filedesc.h>
71 #include <sys/module.h>
72 #include <sys/mount.h>
73 #include <sys/mqueue.h>
74 #include <sys/mutex.h>
75 #include <sys/namei.h>
76 #include <sys/posix4.h>
80 #include <sys/queue.h>
81 #include <sys/sysproto.h>
83 #include <sys/syscall.h>
84 #include <sys/syscallsubr.h>
85 #include <sys/sysent.h>
87 #include <sys/sysctl.h>
88 #include <sys/taskqueue.h>
89 #include <sys/unistd.h>
91 #include <sys/vnode.h>
92 #include <machine/atomic.h>
94 #include <security/audit/audit.h>
96 FEATURE(p1003_1b_mqueue, "POSIX P1003.1B message queues support");
99 * Limits and constants
101 #define MQFS_NAMELEN NAME_MAX
102 #define MQFS_DELEN (8 + MQFS_NAMELEN)
118 * mqfs_info: describes a mqfs instance
122 struct mqfs_node *mi_root;
123 struct unrhdr *mi_unrhdr;
127 LIST_ENTRY(mqfs_vdata) mv_link;
128 struct mqfs_node *mv_node;
129 struct vnode *mv_vnode;
134 * mqfs_node: describes a node (file or directory) within a mqfs
137 char mn_name[MQFS_NAMELEN+1];
138 struct mqfs_info *mn_info;
139 struct mqfs_node *mn_parent;
140 LIST_HEAD(,mqfs_node) mn_children;
141 LIST_ENTRY(mqfs_node) mn_sibling;
142 LIST_HEAD(,mqfs_vdata) mn_vnodes;
143 const void *mn_pr_root;
149 struct timespec mn_birth;
150 struct timespec mn_ctime;
151 struct timespec mn_atime;
152 struct timespec mn_mtime;
158 #define VTON(vp) (((struct mqfs_vdata *)((vp)->v_data))->mv_node)
159 #define VTOMQ(vp) ((struct mqueue *)(VTON(vp)->mn_data))
160 #define VFSTOMQFS(m) ((struct mqfs_info *)((m)->mnt_data))
161 #define FPTOMQ(fp) ((struct mqueue *)(((struct mqfs_node *) \
162 (fp)->f_data)->mn_data))
164 TAILQ_HEAD(msgq, mqueue_msg);
168 struct mqueue_notifier {
169 LIST_ENTRY(mqueue_notifier) nt_link;
170 struct sigevent nt_sigev;
172 struct proc *nt_proc;
185 struct selinfo mq_rsel;
186 struct selinfo mq_wsel;
187 struct mqueue_notifier *mq_notifier;
194 TAILQ_ENTRY(mqueue_msg) msg_link;
195 unsigned int msg_prio;
196 unsigned int msg_size;
197 /* following real data... */
200 static SYSCTL_NODE(_kern, OID_AUTO, mqueue, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
201 "POSIX real time message queue");
203 static int default_maxmsg = 10;
204 static int default_msgsize = 1024;
206 static int maxmsg = 100;
207 SYSCTL_INT(_kern_mqueue, OID_AUTO, maxmsg, CTLFLAG_RW,
208 &maxmsg, 0, "Default maximum messages in queue");
209 static int maxmsgsize = 16384;
210 SYSCTL_INT(_kern_mqueue, OID_AUTO, maxmsgsize, CTLFLAG_RW,
211 &maxmsgsize, 0, "Default maximum message size");
212 static int maxmq = 100;
213 SYSCTL_INT(_kern_mqueue, OID_AUTO, maxmq, CTLFLAG_RW,
214 &maxmq, 0, "maximum message queues");
215 static int curmq = 0;
216 SYSCTL_INT(_kern_mqueue, OID_AUTO, curmq, CTLFLAG_RW,
217 &curmq, 0, "current message queue number");
218 static int unloadable = 0;
219 static MALLOC_DEFINE(M_MQUEUEDATA, "mqdata", "mqueue data");
221 static eventhandler_tag exit_tag;
223 /* Only one instance per-system */
224 static struct mqfs_info mqfs_data;
225 static uma_zone_t mqnode_zone;
226 static uma_zone_t mqueue_zone;
227 static uma_zone_t mvdata_zone;
228 static uma_zone_t mqnoti_zone;
229 static struct vop_vector mqfs_vnodeops;
230 static struct fileops mqueueops;
231 static unsigned mqfs_osd_jail_slot;
234 * Directory structure construction and manipulation
237 static struct mqfs_node *mqfs_create_dir(struct mqfs_node *parent,
238 const char *name, int namelen, struct ucred *cred, int mode);
239 static struct mqfs_node *mqfs_create_link(struct mqfs_node *parent,
240 const char *name, int namelen, struct ucred *cred, int mode);
243 static struct mqfs_node *mqfs_create_file(struct mqfs_node *parent,
244 const char *name, int namelen, struct ucred *cred, int mode);
245 static int mqfs_destroy(struct mqfs_node *mn);
246 static void mqfs_fileno_alloc(struct mqfs_info *mi, struct mqfs_node *mn);
247 static void mqfs_fileno_free(struct mqfs_info *mi, struct mqfs_node *mn);
248 static int mqfs_allocv(struct mount *mp, struct vnode **vpp, struct mqfs_node *pn);
249 static int mqfs_prison_remove(void *obj, void *data);
252 * Message queue construction and maniplation
254 static struct mqueue *mqueue_alloc(const struct mq_attr *attr);
255 static void mqueue_free(struct mqueue *mq);
256 static int mqueue_send(struct mqueue *mq, const char *msg_ptr,
257 size_t msg_len, unsigned msg_prio, int waitok,
258 const struct timespec *abs_timeout);
259 static int mqueue_receive(struct mqueue *mq, char *msg_ptr,
260 size_t msg_len, unsigned *msg_prio, int waitok,
261 const struct timespec *abs_timeout);
262 static int _mqueue_send(struct mqueue *mq, struct mqueue_msg *msg,
264 static int _mqueue_recv(struct mqueue *mq, struct mqueue_msg **msg,
266 static void mqueue_send_notification(struct mqueue *mq);
267 static void mqueue_fdclose(struct thread *td, int fd, struct file *fp);
268 static void mq_proc_exit(void *arg, struct proc *p);
273 static void filt_mqdetach(struct knote *kn);
274 static int filt_mqread(struct knote *kn, long hint);
275 static int filt_mqwrite(struct knote *kn, long hint);
277 struct filterops mq_rfiltops = {
279 .f_detach = filt_mqdetach,
280 .f_event = filt_mqread,
282 struct filterops mq_wfiltops = {
284 .f_detach = filt_mqdetach,
285 .f_event = filt_mqwrite,
289 * Initialize fileno bitmap
292 mqfs_fileno_init(struct mqfs_info *mi)
296 up = new_unrhdr(1, INT_MAX, NULL);
301 * Tear down fileno bitmap
304 mqfs_fileno_uninit(struct mqfs_info *mi)
309 mi->mi_unrhdr = NULL;
314 * Allocate a file number
317 mqfs_fileno_alloc(struct mqfs_info *mi, struct mqfs_node *mn)
319 /* make sure our parent has a file number */
320 if (mn->mn_parent && !mn->mn_parent->mn_fileno)
321 mqfs_fileno_alloc(mi, mn->mn_parent);
323 switch (mn->mn_type) {
327 case mqfstype_symlink:
328 mn->mn_fileno = alloc_unr(mi->mi_unrhdr);
331 KASSERT(mn->mn_parent != NULL,
332 ("mqfstype_this node has no parent"));
333 mn->mn_fileno = mn->mn_parent->mn_fileno;
335 case mqfstype_parent:
336 KASSERT(mn->mn_parent != NULL,
337 ("mqfstype_parent node has no parent"));
338 if (mn->mn_parent == mi->mi_root) {
339 mn->mn_fileno = mn->mn_parent->mn_fileno;
342 KASSERT(mn->mn_parent->mn_parent != NULL,
343 ("mqfstype_parent node has no grandparent"));
344 mn->mn_fileno = mn->mn_parent->mn_parent->mn_fileno;
348 ("mqfs_fileno_alloc() called for unknown type node: %d",
355 * Release a file number
358 mqfs_fileno_free(struct mqfs_info *mi, struct mqfs_node *mn)
360 switch (mn->mn_type) {
364 case mqfstype_symlink:
365 free_unr(mi->mi_unrhdr, mn->mn_fileno);
368 case mqfstype_parent:
369 /* ignore these, as they don't "own" their file number */
373 ("mqfs_fileno_free() called for unknown type node: %d",
379 static __inline struct mqfs_node *
382 return uma_zalloc(mqnode_zone, M_WAITOK | M_ZERO);
386 mqnode_free(struct mqfs_node *node)
388 uma_zfree(mqnode_zone, node);
392 mqnode_addref(struct mqfs_node *node)
394 atomic_add_int(&node->mn_refcount, 1);
398 mqnode_release(struct mqfs_node *node)
400 struct mqfs_info *mqfs;
403 mqfs = node->mn_info;
404 old = atomic_fetchadd_int(&node->mn_refcount, -1);
405 if (node->mn_type == mqfstype_dir ||
406 node->mn_type == mqfstype_root)
407 exp = 3; /* include . and .. */
411 int locked = sx_xlocked(&mqfs->mi_lock);
413 sx_xlock(&mqfs->mi_lock);
416 sx_xunlock(&mqfs->mi_lock);
421 * Add a node to a directory
424 mqfs_add_node(struct mqfs_node *parent, struct mqfs_node *node)
426 KASSERT(parent != NULL, ("%s(): parent is NULL", __func__));
427 KASSERT(parent->mn_info != NULL,
428 ("%s(): parent has no mn_info", __func__));
429 KASSERT(parent->mn_type == mqfstype_dir ||
430 parent->mn_type == mqfstype_root,
431 ("%s(): parent is not a directory", __func__));
433 node->mn_info = parent->mn_info;
434 node->mn_parent = parent;
435 LIST_INIT(&node->mn_children);
436 LIST_INIT(&node->mn_vnodes);
437 LIST_INSERT_HEAD(&parent->mn_children, node, mn_sibling);
438 mqnode_addref(parent);
442 static struct mqfs_node *
443 mqfs_create_node(const char *name, int namelen, struct ucred *cred, int mode,
446 struct mqfs_node *node;
448 node = mqnode_alloc();
449 strncpy(node->mn_name, name, namelen);
450 node->mn_pr_root = cred->cr_prison->pr_root;
451 node->mn_type = nodetype;
452 node->mn_refcount = 1;
453 vfs_timestamp(&node->mn_birth);
454 node->mn_ctime = node->mn_atime = node->mn_mtime
456 node->mn_uid = cred->cr_uid;
457 node->mn_gid = cred->cr_gid;
458 node->mn_mode = mode;
465 static struct mqfs_node *
466 mqfs_create_file(struct mqfs_node *parent, const char *name, int namelen,
467 struct ucred *cred, int mode)
469 struct mqfs_node *node;
471 node = mqfs_create_node(name, namelen, cred, mode, mqfstype_file);
472 if (mqfs_add_node(parent, node) != 0) {
480 * Add . and .. to a directory
483 mqfs_fixup_dir(struct mqfs_node *parent)
485 struct mqfs_node *dir;
487 dir = mqnode_alloc();
488 dir->mn_name[0] = '.';
489 dir->mn_type = mqfstype_this;
490 dir->mn_refcount = 1;
491 if (mqfs_add_node(parent, dir) != 0) {
496 dir = mqnode_alloc();
497 dir->mn_name[0] = dir->mn_name[1] = '.';
498 dir->mn_type = mqfstype_parent;
499 dir->mn_refcount = 1;
501 if (mqfs_add_node(parent, dir) != 0) {
514 static struct mqfs_node *
515 mqfs_create_dir(struct mqfs_node *parent, const char *name, int namelen,
516 struct ucred *cred, int mode)
518 struct mqfs_node *node;
520 node = mqfs_create_node(name, namelen, cred, mode, mqfstype_dir);
521 if (mqfs_add_node(parent, node) != 0) {
526 if (mqfs_fixup_dir(node) != 0) {
536 static struct mqfs_node *
537 mqfs_create_link(struct mqfs_node *parent, const char *name, int namelen,
538 struct ucred *cred, int mode)
540 struct mqfs_node *node;
542 node = mqfs_create_node(name, namelen, cred, mode, mqfstype_symlink);
543 if (mqfs_add_node(parent, node) != 0) {
553 * Destroy a node or a tree of nodes
556 mqfs_destroy(struct mqfs_node *node)
558 struct mqfs_node *parent;
560 KASSERT(node != NULL,
561 ("%s(): node is NULL", __func__));
562 KASSERT(node->mn_info != NULL,
563 ("%s(): node has no mn_info", __func__));
565 /* destroy children */
566 if (node->mn_type == mqfstype_dir || node->mn_type == mqfstype_root)
567 while (! LIST_EMPTY(&node->mn_children))
568 mqfs_destroy(LIST_FIRST(&node->mn_children));
570 /* unlink from parent */
571 if ((parent = node->mn_parent) != NULL) {
572 KASSERT(parent->mn_info == node->mn_info,
573 ("%s(): parent has different mn_info", __func__));
574 LIST_REMOVE(node, mn_sibling);
577 if (node->mn_fileno != 0)
578 mqfs_fileno_free(node->mn_info, node);
579 if (node->mn_data != NULL)
580 mqueue_free(node->mn_data);
586 * Mount a mqfs instance
589 mqfs_mount(struct mount *mp)
593 if (mp->mnt_flag & MNT_UPDATE)
596 mp->mnt_data = &mqfs_data;
598 mp->mnt_flag |= MNT_LOCAL;
603 vfs_mountedfrom(mp, "mqueue");
604 sbp->f_bsize = PAGE_SIZE;
605 sbp->f_iosize = PAGE_SIZE;
615 * Unmount a mqfs instance
618 mqfs_unmount(struct mount *mp, int mntflags)
622 error = vflush(mp, 0, (mntflags & MNT_FORCE) ? FORCECLOSE : 0,
628 * Return a root vnode
631 mqfs_root(struct mount *mp, int flags, struct vnode **vpp)
633 struct mqfs_info *mqfs;
636 mqfs = VFSTOMQFS(mp);
637 ret = mqfs_allocv(mp, vpp, mqfs->mi_root);
642 * Return filesystem stats
645 mqfs_statfs(struct mount *mp, struct statfs *sbp)
647 /* XXX update statistics */
652 * Initialize a mqfs instance
655 mqfs_init(struct vfsconf *vfc)
657 struct mqfs_node *root;
658 struct mqfs_info *mi;
659 osd_method_t methods[PR_MAXMETHOD] = {
660 [PR_METHOD_REMOVE] = mqfs_prison_remove,
663 mqnode_zone = uma_zcreate("mqnode", sizeof(struct mqfs_node),
664 NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0);
665 mqueue_zone = uma_zcreate("mqueue", sizeof(struct mqueue),
666 NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0);
667 mvdata_zone = uma_zcreate("mvdata",
668 sizeof(struct mqfs_vdata), NULL, NULL, NULL,
669 NULL, UMA_ALIGN_PTR, 0);
670 mqnoti_zone = uma_zcreate("mqnotifier", sizeof(struct mqueue_notifier),
671 NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0);
673 sx_init(&mi->mi_lock, "mqfs lock");
674 /* set up the root diretory */
675 root = mqfs_create_node("/", 1, curthread->td_ucred, 01777,
678 LIST_INIT(&root->mn_children);
679 LIST_INIT(&root->mn_vnodes);
681 mqfs_fileno_init(mi);
682 mqfs_fileno_alloc(mi, root);
683 mqfs_fixup_dir(root);
684 exit_tag = EVENTHANDLER_REGISTER(process_exit, mq_proc_exit, NULL,
685 EVENTHANDLER_PRI_ANY);
686 mq_fdclose = mqueue_fdclose;
687 p31b_setcfg(CTL_P1003_1B_MESSAGE_PASSING, _POSIX_MESSAGE_PASSING);
688 mqfs_osd_jail_slot = osd_jail_register(NULL, methods);
693 * Destroy a mqfs instance
696 mqfs_uninit(struct vfsconf *vfc)
698 struct mqfs_info *mi;
702 osd_jail_deregister(mqfs_osd_jail_slot);
703 EVENTHANDLER_DEREGISTER(process_exit, exit_tag);
705 mqfs_destroy(mi->mi_root);
707 mqfs_fileno_uninit(mi);
708 sx_destroy(&mi->mi_lock);
709 uma_zdestroy(mqnode_zone);
710 uma_zdestroy(mqueue_zone);
711 uma_zdestroy(mvdata_zone);
712 uma_zdestroy(mqnoti_zone);
720 do_recycle(void *context, int pending __unused)
722 struct vnode *vp = (struct vnode *)context;
724 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
734 mqfs_allocv(struct mount *mp, struct vnode **vpp, struct mqfs_node *pn)
736 struct mqfs_vdata *vd;
737 struct mqfs_info *mqfs;
738 struct vnode *newvpp;
743 sx_xlock(&mqfs->mi_lock);
744 LIST_FOREACH(vd, &pn->mn_vnodes, mv_link) {
745 if (vd->mv_vnode->v_mount == mp) {
754 sx_xunlock(&mqfs->mi_lock);
755 error = vget(*vpp, LK_RETRY | LK_EXCLUSIVE);
759 sx_xunlock(&mqfs->mi_lock);
761 error = getnewvnode("mqueue", mp, &mqfs_vnodeops, &newvpp);
764 vn_lock(newvpp, LK_EXCLUSIVE | LK_RETRY);
765 error = insmntque(newvpp, mp);
769 sx_xlock(&mqfs->mi_lock);
771 * Check if it has already been allocated
772 * while we were blocked.
774 LIST_FOREACH(vd, &pn->mn_vnodes, mv_link) {
775 if (vd->mv_vnode->v_mount == mp) {
777 sx_xunlock(&mqfs->mi_lock);
787 vd = uma_zalloc(mvdata_zone, M_WAITOK);
791 TASK_INIT(&vd->mv_task, 0, do_recycle, *vpp);
792 LIST_INSERT_HEAD(&pn->mn_vnodes, vd, mv_link);
794 switch (pn->mn_type) {
796 (*vpp)->v_vflag = VV_ROOT;
800 case mqfstype_parent:
801 (*vpp)->v_type = VDIR;
804 (*vpp)->v_type = VREG;
806 case mqfstype_symlink:
807 (*vpp)->v_type = VLNK;
810 KASSERT(0, ("mqfs_allocf called for null node\n"));
812 panic("%s has unexpected type: %d", pn->mn_name, pn->mn_type);
814 sx_xunlock(&mqfs->mi_lock);
819 * Search a directory entry
821 static struct mqfs_node *
822 mqfs_search(struct mqfs_node *pd, const char *name, int len, struct ucred *cred)
824 struct mqfs_node *pn;
827 sx_assert(&pd->mn_info->mi_lock, SX_LOCKED);
828 pr_root = cred->cr_prison->pr_root;
829 LIST_FOREACH(pn, &pd->mn_children, mn_sibling) {
830 /* Only match names within the same prison root directory */
831 if ((pn->mn_pr_root == NULL || pn->mn_pr_root == pr_root) &&
832 strncmp(pn->mn_name, name, len) == 0 &&
833 pn->mn_name[len] == '\0')
840 * Look up a file or directory.
843 mqfs_lookupx(struct vop_cachedlookup_args *ap)
845 struct componentname *cnp;
846 struct vnode *dvp, **vpp;
847 struct mqfs_node *pd;
848 struct mqfs_node *pn;
849 struct mqfs_info *mqfs;
850 int nameiop, flags, error, namelen;
858 pname = cnp->cn_nameptr;
859 namelen = cnp->cn_namelen;
860 flags = cnp->cn_flags;
861 nameiop = cnp->cn_nameiop;
867 if (dvp->v_type != VDIR)
870 error = VOP_ACCESS(dvp, VEXEC, cnp->cn_cred, td);
874 /* shortcut: check if the name is too long */
875 if (cnp->cn_namelen >= MQFS_NAMELEN)
879 if (namelen == 1 && pname[0] == '.') {
880 if ((flags & ISLASTCN) && nameiop != LOOKUP)
889 if (cnp->cn_flags & ISDOTDOT) {
890 if (dvp->v_vflag & VV_ROOT)
892 if ((flags & ISLASTCN) && nameiop != LOOKUP)
895 KASSERT(pd->mn_parent, ("non-root directory has no parent"));
897 error = mqfs_allocv(dvp->v_mount, vpp, pn);
898 vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY);
903 sx_xlock(&mqfs->mi_lock);
904 pn = mqfs_search(pd, pname, namelen, cnp->cn_cred);
907 sx_xunlock(&mqfs->mi_lock);
912 if (nameiop == DELETE && (flags & ISLASTCN)) {
913 error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred, td);
927 error = mqfs_allocv(dvp->v_mount, vpp, pn);
929 if (error == 0 && cnp->cn_flags & MAKEENTRY)
930 cache_enter(dvp, *vpp, cnp);
936 /* will create a new entry in the directory ? */
937 if ((nameiop == CREATE || nameiop == RENAME) && (flags & LOCKPARENT)
938 && (flags & ISLASTCN)) {
939 error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred, td);
942 return (EJUSTRETURN);
948 struct vop_lookup_args {
949 struct vop_generic_args a_gen;
951 struct vnode **a_vpp;
952 struct componentname *a_cnp;
957 * vnode lookup operation
960 mqfs_lookup(struct vop_cachedlookup_args *ap)
964 rc = mqfs_lookupx(ap);
969 struct vop_create_args {
971 struct vnode **a_vpp;
972 struct componentname *a_cnp;
978 * vnode creation operation
981 mqfs_create(struct vop_create_args *ap)
983 struct mqfs_info *mqfs = VFSTOMQFS(ap->a_dvp->v_mount);
984 struct componentname *cnp = ap->a_cnp;
985 struct mqfs_node *pd;
986 struct mqfs_node *pn;
990 pd = VTON(ap->a_dvp);
991 if (pd->mn_type != mqfstype_root && pd->mn_type != mqfstype_dir)
993 mq = mqueue_alloc(NULL);
996 sx_xlock(&mqfs->mi_lock);
997 pn = mqfs_create_file(pd, cnp->cn_nameptr, cnp->cn_namelen,
998 cnp->cn_cred, ap->a_vap->va_mode);
1000 sx_xunlock(&mqfs->mi_lock);
1004 sx_xunlock(&mqfs->mi_lock);
1005 error = mqfs_allocv(ap->a_dvp->v_mount, ap->a_vpp, pn);
1021 int do_unlink(struct mqfs_node *pn, struct ucred *ucred)
1023 struct mqfs_node *parent;
1024 struct mqfs_vdata *vd;
1027 sx_assert(&pn->mn_info->mi_lock, SX_LOCKED);
1029 if (ucred->cr_uid != pn->mn_uid &&
1030 (error = priv_check_cred(ucred, PRIV_MQ_ADMIN)) != 0)
1032 else if (!pn->mn_deleted) {
1033 parent = pn->mn_parent;
1034 pn->mn_parent = NULL;
1036 LIST_REMOVE(pn, mn_sibling);
1037 LIST_FOREACH(vd, &pn->mn_vnodes, mv_link) {
1038 cache_purge(vd->mv_vnode);
1039 vhold(vd->mv_vnode);
1040 taskqueue_enqueue(taskqueue_thread, &vd->mv_task);
1043 mqnode_release(parent);
1050 struct vop_remove_args {
1051 struct vnode *a_dvp;
1053 struct componentname *a_cnp;
1058 * vnode removal operation
1061 mqfs_remove(struct vop_remove_args *ap)
1063 struct mqfs_info *mqfs = VFSTOMQFS(ap->a_dvp->v_mount);
1064 struct mqfs_node *pn;
1067 if (ap->a_vp->v_type == VDIR)
1069 pn = VTON(ap->a_vp);
1070 sx_xlock(&mqfs->mi_lock);
1071 error = do_unlink(pn, ap->a_cnp->cn_cred);
1072 sx_xunlock(&mqfs->mi_lock);
1077 struct vop_inactive_args {
1079 struct thread *a_td;
1084 mqfs_inactive(struct vop_inactive_args *ap)
1086 struct mqfs_node *pn = VTON(ap->a_vp);
1094 struct vop_reclaim_args {
1095 struct vop_generic_args a_gen;
1101 mqfs_reclaim(struct vop_reclaim_args *ap)
1103 struct mqfs_info *mqfs = VFSTOMQFS(ap->a_vp->v_mount);
1104 struct vnode *vp = ap->a_vp;
1105 struct mqfs_node *pn;
1106 struct mqfs_vdata *vd;
1110 sx_xlock(&mqfs->mi_lock);
1112 LIST_REMOVE(vd, mv_link);
1113 uma_zfree(mvdata_zone, vd);
1115 sx_xunlock(&mqfs->mi_lock);
1120 struct vop_open_args {
1121 struct vop_generic_args a_gen;
1124 struct ucred *a_cred;
1125 struct thread *a_td;
1131 mqfs_open(struct vop_open_args *ap)
1137 struct vop_close_args {
1138 struct vop_generic_args a_gen;
1141 struct ucred *a_cred;
1142 struct thread *a_td;
1147 mqfs_close(struct vop_close_args *ap)
1153 struct vop_access_args {
1154 struct vop_generic_args a_gen;
1156 accmode_t a_accmode;
1157 struct ucred *a_cred;
1158 struct thread *a_td;
1163 * Verify permissions
1166 mqfs_access(struct vop_access_args *ap)
1168 struct vnode *vp = ap->a_vp;
1172 error = VOP_GETATTR(vp, &vattr, ap->a_cred);
1175 error = vaccess(vp->v_type, vattr.va_mode, vattr.va_uid, vattr.va_gid,
1176 ap->a_accmode, ap->a_cred);
1181 struct vop_getattr_args {
1182 struct vop_generic_args a_gen;
1184 struct vattr *a_vap;
1185 struct ucred *a_cred;
1190 * Get file attributes
1193 mqfs_getattr(struct vop_getattr_args *ap)
1195 struct vnode *vp = ap->a_vp;
1196 struct mqfs_node *pn = VTON(vp);
1197 struct vattr *vap = ap->a_vap;
1200 vap->va_type = vp->v_type;
1201 vap->va_mode = pn->mn_mode;
1203 vap->va_uid = pn->mn_uid;
1204 vap->va_gid = pn->mn_gid;
1205 vap->va_fsid = vp->v_mount->mnt_stat.f_fsid.val[0];
1206 vap->va_fileid = pn->mn_fileno;
1208 vap->va_blocksize = PAGE_SIZE;
1209 vap->va_bytes = vap->va_size = 0;
1210 vap->va_atime = pn->mn_atime;
1211 vap->va_mtime = pn->mn_mtime;
1212 vap->va_ctime = pn->mn_ctime;
1213 vap->va_birthtime = pn->mn_birth;
1216 vap->va_rdev = NODEV;
1218 vap->va_filerev = 0;
1223 struct vop_setattr_args {
1224 struct vop_generic_args a_gen;
1226 struct vattr *a_vap;
1227 struct ucred *a_cred;
1234 mqfs_setattr(struct vop_setattr_args *ap)
1236 struct mqfs_node *pn;
1247 if ((vap->va_type != VNON) ||
1248 (vap->va_nlink != VNOVAL) ||
1249 (vap->va_fsid != VNOVAL) ||
1250 (vap->va_fileid != VNOVAL) ||
1251 (vap->va_blocksize != VNOVAL) ||
1252 (vap->va_flags != VNOVAL && vap->va_flags != 0) ||
1253 (vap->va_rdev != VNOVAL) ||
1254 ((int)vap->va_bytes != VNOVAL) ||
1255 (vap->va_gen != VNOVAL)) {
1262 if (vap->va_uid == (uid_t)VNOVAL)
1266 if (vap->va_gid == (gid_t)VNOVAL)
1271 if (uid != pn->mn_uid || gid != pn->mn_gid) {
1273 * To modify the ownership of a file, must possess VADMIN
1276 if ((error = VOP_ACCESS(vp, VADMIN, ap->a_cred, td)))
1280 * XXXRW: Why is there a privilege check here: shouldn't the
1281 * check in VOP_ACCESS() be enough? Also, are the group bits
1282 * below definitely right?
1284 if (((ap->a_cred->cr_uid != pn->mn_uid) || uid != pn->mn_uid ||
1285 (gid != pn->mn_gid && !groupmember(gid, ap->a_cred))) &&
1286 (error = priv_check(td, PRIV_MQ_ADMIN)) != 0)
1293 if (vap->va_mode != (mode_t)VNOVAL) {
1294 if ((ap->a_cred->cr_uid != pn->mn_uid) &&
1295 (error = priv_check(td, PRIV_MQ_ADMIN)))
1297 pn->mn_mode = vap->va_mode;
1301 if (vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL) {
1302 /* See the comment in ufs_vnops::ufs_setattr(). */
1303 if ((error = VOP_ACCESS(vp, VADMIN, ap->a_cred, td)) &&
1304 ((vap->va_vaflags & VA_UTIMES_NULL) == 0 ||
1305 (error = VOP_ACCESS(vp, VWRITE, ap->a_cred, td))))
1307 if (vap->va_atime.tv_sec != VNOVAL) {
1308 pn->mn_atime = vap->va_atime;
1310 if (vap->va_mtime.tv_sec != VNOVAL) {
1311 pn->mn_mtime = vap->va_mtime;
1316 vfs_timestamp(&pn->mn_ctime);
1322 struct vop_read_args {
1323 struct vop_generic_args a_gen;
1327 struct ucred *a_cred;
1335 mqfs_read(struct vop_read_args *ap)
1338 struct vnode *vp = ap->a_vp;
1339 struct uio *uio = ap->a_uio;
1343 if (vp->v_type != VREG)
1347 snprintf(buf, sizeof(buf),
1348 "QSIZE:%-10ld MAXMSG:%-10ld CURMSG:%-10ld MSGSIZE:%-10ld\n",
1353 buf[sizeof(buf)-1] = '\0';
1355 error = uiomove_frombuf(buf, len, uio);
1360 struct vop_readdir_args {
1361 struct vop_generic_args a_gen;
1364 struct ucred *a_cred;
1367 uint64_t **a_cookies;
1372 * Return directory entries.
1375 mqfs_readdir(struct vop_readdir_args *ap)
1378 struct mqfs_info *mi;
1379 struct mqfs_node *pd;
1380 struct mqfs_node *pn;
1381 struct dirent entry;
1383 const void *pr_root;
1384 int *tmp_ncookies = NULL;
1389 mi = VFSTOMQFS(vp->v_mount);
1393 if (vp->v_type != VDIR)
1396 if (uio->uio_offset < 0)
1399 if (ap->a_ncookies != NULL) {
1400 tmp_ncookies = ap->a_ncookies;
1401 *ap->a_ncookies = 0;
1402 ap->a_ncookies = NULL;
1408 pr_root = ap->a_cred->cr_prison->pr_root;
1409 sx_xlock(&mi->mi_lock);
1411 LIST_FOREACH(pn, &pd->mn_children, mn_sibling) {
1412 entry.d_reclen = sizeof(entry);
1415 * Only show names within the same prison root directory
1416 * (or not associated with a prison, e.g. "." and "..").
1418 if (pn->mn_pr_root != NULL && pn->mn_pr_root != pr_root)
1421 mqfs_fileno_alloc(mi, pn);
1422 entry.d_fileno = pn->mn_fileno;
1423 entry.d_off = offset + entry.d_reclen;
1424 for (i = 0; i < MQFS_NAMELEN - 1 && pn->mn_name[i] != '\0'; ++i)
1425 entry.d_name[i] = pn->mn_name[i];
1427 switch (pn->mn_type) {
1431 case mqfstype_parent:
1432 entry.d_type = DT_DIR;
1435 entry.d_type = DT_REG;
1437 case mqfstype_symlink:
1438 entry.d_type = DT_LNK;
1441 panic("%s has unexpected node type: %d", pn->mn_name,
1444 dirent_terminate(&entry);
1445 if (entry.d_reclen > uio->uio_resid)
1447 if (offset >= uio->uio_offset) {
1448 error = vfs_read_dirent(ap, &entry, offset);
1452 offset += entry.d_reclen;
1454 sx_xunlock(&mi->mi_lock);
1456 uio->uio_offset = offset;
1458 if (tmp_ncookies != NULL)
1459 ap->a_ncookies = tmp_ncookies;
1467 struct vop_mkdir_args {
1468 struct vnode *a_dvp;
1469 struvt vnode **a_vpp;
1470 struvt componentname *a_cnp;
1471 struct vattr *a_vap;
1476 * Create a directory.
1479 mqfs_mkdir(struct vop_mkdir_args *ap)
1481 struct mqfs_info *mqfs = VFSTOMQFS(ap->a_dvp->v_mount);
1482 struct componentname *cnp = ap->a_cnp;
1483 struct mqfs_node *pd = VTON(ap->a_dvp);
1484 struct mqfs_node *pn;
1487 if (pd->mn_type != mqfstype_root && pd->mn_type != mqfstype_dir)
1489 sx_xlock(&mqfs->mi_lock);
1490 pn = mqfs_create_dir(pd, cnp->cn_nameptr, cnp->cn_namelen,
1491 ap->a_vap->cn_cred, ap->a_vap->va_mode);
1494 sx_xunlock(&mqfs->mi_lock);
1498 error = mqfs_allocv(ap->a_dvp->v_mount, ap->a_vpp, pn);
1505 struct vop_rmdir_args {
1506 struct vnode *a_dvp;
1508 struct componentname *a_cnp;
1513 * Remove a directory.
1516 mqfs_rmdir(struct vop_rmdir_args *ap)
1518 struct mqfs_info *mqfs = VFSTOMQFS(ap->a_dvp->v_mount);
1519 struct mqfs_node *pn = VTON(ap->a_vp);
1520 struct mqfs_node *pt;
1522 if (pn->mn_type != mqfstype_dir)
1525 sx_xlock(&mqfs->mi_lock);
1526 if (pn->mn_deleted) {
1527 sx_xunlock(&mqfs->mi_lock);
1531 pt = LIST_FIRST(&pn->mn_children);
1532 pt = LIST_NEXT(pt, mn_sibling);
1533 pt = LIST_NEXT(pt, mn_sibling);
1535 sx_xunlock(&mqfs->mi_lock);
1539 pn->mn_parent = NULL;
1541 LIST_REMOVE(pn, mn_sibling);
1544 sx_xunlock(&mqfs->mi_lock);
1545 cache_purge(ap->a_vp);
1552 * See if this prison root is obsolete, and clean up associated queues if it is.
1555 mqfs_prison_remove(void *obj, void *data __unused)
1557 const struct prison *pr = obj;
1559 struct mqfs_node *pn, *tpn;
1560 struct vnode *pr_root;
1562 pr_root = pr->pr_root;
1563 if (pr->pr_parent->pr_root == pr_root)
1565 TAILQ_FOREACH(tpr, &allprison, pr_list) {
1566 if (tpr != pr && tpr->pr_root == pr_root)
1570 * No jails are rooted in this directory anymore,
1571 * so no queues should be either.
1573 sx_xlock(&mqfs_data.mi_lock);
1574 LIST_FOREACH_SAFE(pn, &mqfs_data.mi_root->mn_children,
1576 if (pn->mn_pr_root == pr_root)
1577 (void)do_unlink(pn, curthread->td_ucred);
1579 sx_xunlock(&mqfs_data.mi_lock);
1584 * Allocate a message queue
1586 static struct mqueue *
1587 mqueue_alloc(const struct mq_attr *attr)
1593 mq = uma_zalloc(mqueue_zone, M_WAITOK | M_ZERO);
1594 TAILQ_INIT(&mq->mq_msgq);
1596 mq->mq_maxmsg = attr->mq_maxmsg;
1597 mq->mq_msgsize = attr->mq_msgsize;
1599 mq->mq_maxmsg = default_maxmsg;
1600 mq->mq_msgsize = default_msgsize;
1602 mtx_init(&mq->mq_mutex, "mqueue lock", NULL, MTX_DEF);
1603 knlist_init_mtx(&mq->mq_rsel.si_note, &mq->mq_mutex);
1604 knlist_init_mtx(&mq->mq_wsel.si_note, &mq->mq_mutex);
1605 atomic_add_int(&curmq, 1);
1610 * Destroy a message queue
1613 mqueue_free(struct mqueue *mq)
1615 struct mqueue_msg *msg;
1617 while ((msg = TAILQ_FIRST(&mq->mq_msgq)) != NULL) {
1618 TAILQ_REMOVE(&mq->mq_msgq, msg, msg_link);
1619 free(msg, M_MQUEUEDATA);
1622 mtx_destroy(&mq->mq_mutex);
1623 seldrain(&mq->mq_rsel);
1624 seldrain(&mq->mq_wsel);
1625 knlist_destroy(&mq->mq_rsel.si_note);
1626 knlist_destroy(&mq->mq_wsel.si_note);
1627 uma_zfree(mqueue_zone, mq);
1628 atomic_add_int(&curmq, -1);
1632 * Load a message from user space
1634 static struct mqueue_msg *
1635 mqueue_loadmsg(const char *msg_ptr, size_t msg_size, int msg_prio)
1637 struct mqueue_msg *msg;
1641 len = sizeof(struct mqueue_msg) + msg_size;
1642 msg = malloc(len, M_MQUEUEDATA, M_WAITOK);
1643 error = copyin(msg_ptr, ((char *)msg) + sizeof(struct mqueue_msg),
1646 free(msg, M_MQUEUEDATA);
1649 msg->msg_size = msg_size;
1650 msg->msg_prio = msg_prio;
1656 * Save a message to user space
1659 mqueue_savemsg(struct mqueue_msg *msg, char *msg_ptr, int *msg_prio)
1663 error = copyout(((char *)msg) + sizeof(*msg), msg_ptr,
1665 if (error == 0 && msg_prio != NULL)
1666 error = copyout(&msg->msg_prio, msg_prio, sizeof(int));
1671 * Free a message's memory
1673 static __inline void
1674 mqueue_freemsg(struct mqueue_msg *msg)
1676 free(msg, M_MQUEUEDATA);
1680 * Send a message. if waitok is false, thread will not be
1681 * blocked if there is no data in queue, otherwise, absolute
1682 * time will be checked.
1685 mqueue_send(struct mqueue *mq, const char *msg_ptr,
1686 size_t msg_len, unsigned msg_prio, int waitok,
1687 const struct timespec *abs_timeout)
1689 struct mqueue_msg *msg;
1690 struct timespec ts, ts2;
1694 if (msg_prio >= MQ_PRIO_MAX)
1696 if (msg_len > mq->mq_msgsize)
1698 msg = mqueue_loadmsg(msg_ptr, msg_len, msg_prio);
1702 /* O_NONBLOCK case */
1704 error = _mqueue_send(mq, msg, -1);
1710 /* we allow a null timeout (wait forever) */
1711 if (abs_timeout == NULL) {
1712 error = _mqueue_send(mq, msg, 0);
1718 /* send it before checking time */
1719 error = _mqueue_send(mq, msg, -1);
1723 if (error != EAGAIN)
1726 if (abs_timeout->tv_nsec >= 1000000000 || abs_timeout->tv_nsec < 0) {
1732 timespecsub(abs_timeout, &ts, &ts2);
1733 if (ts2.tv_sec < 0 || (ts2.tv_sec == 0 && ts2.tv_nsec <= 0)) {
1737 TIMESPEC_TO_TIMEVAL(&tv, &ts2);
1738 error = _mqueue_send(mq, msg, tvtohz(&tv));
1739 if (error != ETIMEDOUT)
1745 mqueue_freemsg(msg);
1750 * Common routine to send a message
1753 _mqueue_send(struct mqueue *mq, struct mqueue_msg *msg, int timo)
1755 struct mqueue_msg *msg2;
1758 mtx_lock(&mq->mq_mutex);
1759 while (mq->mq_curmsgs >= mq->mq_maxmsg && error == 0) {
1761 mtx_unlock(&mq->mq_mutex);
1765 error = msleep(&mq->mq_senders, &mq->mq_mutex,
1766 PCATCH, "mqsend", timo);
1768 if (error == EAGAIN)
1771 if (mq->mq_curmsgs >= mq->mq_maxmsg) {
1772 mtx_unlock(&mq->mq_mutex);
1776 if (TAILQ_EMPTY(&mq->mq_msgq)) {
1777 TAILQ_INSERT_HEAD(&mq->mq_msgq, msg, msg_link);
1779 if (msg->msg_prio <= TAILQ_LAST(&mq->mq_msgq, msgq)->msg_prio) {
1780 TAILQ_INSERT_TAIL(&mq->mq_msgq, msg, msg_link);
1782 TAILQ_FOREACH(msg2, &mq->mq_msgq, msg_link) {
1783 if (msg2->msg_prio < msg->msg_prio)
1786 TAILQ_INSERT_BEFORE(msg2, msg, msg_link);
1790 mq->mq_totalbytes += msg->msg_size;
1791 if (mq->mq_receivers)
1792 wakeup_one(&mq->mq_receivers);
1793 else if (mq->mq_notifier != NULL)
1794 mqueue_send_notification(mq);
1795 if (mq->mq_flags & MQ_RSEL) {
1796 mq->mq_flags &= ~MQ_RSEL;
1797 selwakeup(&mq->mq_rsel);
1799 KNOTE_LOCKED(&mq->mq_rsel.si_note, 0);
1800 mtx_unlock(&mq->mq_mutex);
1805 * Send realtime a signal to process which registered itself
1806 * successfully by mq_notify.
1809 mqueue_send_notification(struct mqueue *mq)
1811 struct mqueue_notifier *nt;
1816 mtx_assert(&mq->mq_mutex, MA_OWNED);
1817 nt = mq->mq_notifier;
1818 if (nt->nt_sigev.sigev_notify != SIGEV_NONE) {
1820 error = sigev_findtd(p, &nt->nt_sigev, &td);
1822 mq->mq_notifier = NULL;
1825 if (!KSI_ONQ(&nt->nt_ksi)) {
1826 ksiginfo_set_sigev(&nt->nt_ksi, &nt->nt_sigev);
1827 tdsendsignal(p, td, nt->nt_ksi.ksi_signo, &nt->nt_ksi);
1831 mq->mq_notifier = NULL;
1835 * Get a message. if waitok is false, thread will not be
1836 * blocked if there is no data in queue, otherwise, absolute
1837 * time will be checked.
1840 mqueue_receive(struct mqueue *mq, char *msg_ptr,
1841 size_t msg_len, unsigned *msg_prio, int waitok,
1842 const struct timespec *abs_timeout)
1844 struct mqueue_msg *msg;
1845 struct timespec ts, ts2;
1849 if (msg_len < mq->mq_msgsize)
1852 /* O_NONBLOCK case */
1854 error = _mqueue_recv(mq, &msg, -1);
1860 /* we allow a null timeout (wait forever). */
1861 if (abs_timeout == NULL) {
1862 error = _mqueue_recv(mq, &msg, 0);
1868 /* try to get a message before checking time */
1869 error = _mqueue_recv(mq, &msg, -1);
1873 if (error != EAGAIN)
1876 if (abs_timeout->tv_nsec >= 1000000000 || abs_timeout->tv_nsec < 0) {
1883 timespecsub(abs_timeout, &ts, &ts2);
1884 if (ts2.tv_sec < 0 || (ts2.tv_sec == 0 && ts2.tv_nsec <= 0)) {
1888 TIMESPEC_TO_TIMEVAL(&tv, &ts2);
1889 error = _mqueue_recv(mq, &msg, tvtohz(&tv));
1892 if (error != ETIMEDOUT)
1897 error = mqueue_savemsg(msg, msg_ptr, msg_prio);
1899 curthread->td_retval[0] = msg->msg_size;
1900 curthread->td_retval[1] = 0;
1902 mqueue_freemsg(msg);
1907 * Common routine to receive a message
1910 _mqueue_recv(struct mqueue *mq, struct mqueue_msg **msg, int timo)
1914 mtx_lock(&mq->mq_mutex);
1915 while ((*msg = TAILQ_FIRST(&mq->mq_msgq)) == NULL && error == 0) {
1917 mtx_unlock(&mq->mq_mutex);
1921 error = msleep(&mq->mq_receivers, &mq->mq_mutex,
1922 PCATCH, "mqrecv", timo);
1924 if (error == EAGAIN)
1929 TAILQ_REMOVE(&mq->mq_msgq, *msg, msg_link);
1931 mq->mq_totalbytes -= (*msg)->msg_size;
1933 wakeup_one(&mq->mq_senders);
1934 if (mq->mq_flags & MQ_WSEL) {
1935 mq->mq_flags &= ~MQ_WSEL;
1936 selwakeup(&mq->mq_wsel);
1938 KNOTE_LOCKED(&mq->mq_wsel.si_note, 0);
1940 if (mq->mq_notifier != NULL && mq->mq_receivers == 0 &&
1941 !TAILQ_EMPTY(&mq->mq_msgq)) {
1942 mqueue_send_notification(mq);
1944 mtx_unlock(&mq->mq_mutex);
1948 static __inline struct mqueue_notifier *
1949 notifier_alloc(void)
1951 return (uma_zalloc(mqnoti_zone, M_WAITOK | M_ZERO));
1954 static __inline void
1955 notifier_free(struct mqueue_notifier *p)
1957 uma_zfree(mqnoti_zone, p);
1960 static struct mqueue_notifier *
1961 notifier_search(struct proc *p, int fd)
1963 struct mqueue_notifier *nt;
1965 LIST_FOREACH(nt, &p->p_mqnotifier, nt_link) {
1966 if (nt->nt_ksi.ksi_mqd == fd)
1972 static __inline void
1973 notifier_insert(struct proc *p, struct mqueue_notifier *nt)
1975 LIST_INSERT_HEAD(&p->p_mqnotifier, nt, nt_link);
1978 static __inline void
1979 notifier_delete(struct proc *p, struct mqueue_notifier *nt)
1981 LIST_REMOVE(nt, nt_link);
1986 notifier_remove(struct proc *p, struct mqueue *mq, int fd)
1988 struct mqueue_notifier *nt;
1990 mtx_assert(&mq->mq_mutex, MA_OWNED);
1992 nt = notifier_search(p, fd);
1994 if (mq->mq_notifier == nt)
1995 mq->mq_notifier = NULL;
1996 sigqueue_take(&nt->nt_ksi);
1997 notifier_delete(p, nt);
2003 kern_kmq_open(struct thread *td, const char *upath, int flags, mode_t mode,
2004 const struct mq_attr *attr)
2006 char path[MQFS_NAMELEN + 1];
2007 struct mqfs_node *pn;
2008 struct pwddesc *pdp;
2011 int fd, error, len, cmode;
2013 AUDIT_ARG_FFLAGS(flags);
2014 AUDIT_ARG_MODE(mode);
2016 pdp = td->td_proc->p_pd;
2017 cmode = (((mode & ~pdp->pd_cmask) & ALLPERMS) & ~S_ISTXT);
2019 if ((flags & O_CREAT) != 0 && attr != NULL) {
2020 if (attr->mq_maxmsg <= 0 || attr->mq_maxmsg > maxmsg)
2022 if (attr->mq_msgsize <= 0 || attr->mq_msgsize > maxmsgsize)
2026 error = copyinstr(upath, path, MQFS_NAMELEN + 1, NULL);
2031 * The first character of name must be a slash (/) character
2032 * and the remaining characters of name cannot include any slash
2036 if (len < 2 || path[0] != '/' || strchr(path + 1, '/') != NULL)
2039 * "." and ".." are magic directories, populated on the fly, and cannot
2040 * be opened as queues.
2042 if (strcmp(path, "/.") == 0 || strcmp(path, "/..") == 0)
2044 AUDIT_ARG_UPATH1_CANON(path);
2046 error = falloc(td, &fp, &fd, O_CLOEXEC);
2050 sx_xlock(&mqfs_data.mi_lock);
2051 pn = mqfs_search(mqfs_data.mi_root, path + 1, len - 1, td->td_ucred);
2053 if (!(flags & O_CREAT)) {
2056 mq = mqueue_alloc(attr);
2060 pn = mqfs_create_file(mqfs_data.mi_root,
2061 path + 1, len - 1, td->td_ucred,
2074 if ((flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL)) {
2077 accmode_t accmode = 0;
2083 error = vaccess(VREG, pn->mn_mode, pn->mn_uid,
2084 pn->mn_gid, accmode, td->td_ucred);
2089 sx_xunlock(&mqfs_data.mi_lock);
2090 fdclose(td, fp, fd);
2096 sx_xunlock(&mqfs_data.mi_lock);
2098 finit(fp, flags & (FREAD | FWRITE | O_NONBLOCK), DTYPE_MQUEUE, pn,
2101 td->td_retval[0] = fd;
2107 * Syscall to open a message queue.
2110 sys_kmq_open(struct thread *td, struct kmq_open_args *uap)
2112 struct mq_attr attr;
2115 if ((uap->flags & O_ACCMODE) == O_ACCMODE || uap->flags & O_EXEC)
2117 flags = FFLAGS(uap->flags);
2118 if ((flags & O_CREAT) != 0 && uap->attr != NULL) {
2119 error = copyin(uap->attr, &attr, sizeof(attr));
2123 return (kern_kmq_open(td, uap->path, flags, uap->mode,
2124 uap->attr != NULL ? &attr : NULL));
2128 * Syscall to unlink a message queue.
2131 sys_kmq_unlink(struct thread *td, struct kmq_unlink_args *uap)
2133 char path[MQFS_NAMELEN+1];
2134 struct mqfs_node *pn;
2137 error = copyinstr(uap->path, path, MQFS_NAMELEN + 1, NULL);
2142 if (len < 2 || path[0] != '/' || strchr(path + 1, '/') != NULL)
2144 if (strcmp(path, "/.") == 0 || strcmp(path, "/..") == 0)
2146 AUDIT_ARG_UPATH1_CANON(path);
2148 sx_xlock(&mqfs_data.mi_lock);
2149 pn = mqfs_search(mqfs_data.mi_root, path + 1, len - 1, td->td_ucred);
2151 error = do_unlink(pn, td->td_ucred);
2154 sx_xunlock(&mqfs_data.mi_lock);
2158 typedef int (*_fgetf)(struct thread *, int, cap_rights_t *, struct file **);
2161 * Get message queue by giving file slot
2164 _getmq(struct thread *td, int fd, cap_rights_t *rightsp, _fgetf func,
2165 struct file **fpp, struct mqfs_node **ppn, struct mqueue **pmq)
2167 struct mqfs_node *pn;
2170 error = func(td, fd, rightsp, fpp);
2173 if (&mqueueops != (*fpp)->f_ops) {
2177 pn = (*fpp)->f_data;
2186 getmq(struct thread *td, int fd, struct file **fpp, struct mqfs_node **ppn,
2187 struct mqueue **pmq)
2190 return _getmq(td, fd, &cap_event_rights, fget,
2195 getmq_read(struct thread *td, int fd, struct file **fpp,
2196 struct mqfs_node **ppn, struct mqueue **pmq)
2199 return _getmq(td, fd, &cap_read_rights, fget_read,
2204 getmq_write(struct thread *td, int fd, struct file **fpp,
2205 struct mqfs_node **ppn, struct mqueue **pmq)
2208 return _getmq(td, fd, &cap_write_rights, fget_write,
2213 kern_kmq_setattr(struct thread *td, int mqd, const struct mq_attr *attr,
2214 struct mq_attr *oattr)
2222 if (attr != NULL && (attr->mq_flags & ~O_NONBLOCK) != 0)
2224 error = getmq(td, mqd, &fp, NULL, &mq);
2227 oattr->mq_maxmsg = mq->mq_maxmsg;
2228 oattr->mq_msgsize = mq->mq_msgsize;
2229 oattr->mq_curmsgs = mq->mq_curmsgs;
2232 oflag = flag = fp->f_flag;
2233 flag &= ~O_NONBLOCK;
2234 flag |= (attr->mq_flags & O_NONBLOCK);
2235 } while (atomic_cmpset_int(&fp->f_flag, oflag, flag) == 0);
2238 oattr->mq_flags = (O_NONBLOCK & oflag);
2244 sys_kmq_setattr(struct thread *td, struct kmq_setattr_args *uap)
2246 struct mq_attr attr, oattr;
2249 if (uap->attr != NULL) {
2250 error = copyin(uap->attr, &attr, sizeof(attr));
2254 error = kern_kmq_setattr(td, uap->mqd, uap->attr != NULL ? &attr : NULL,
2256 if (error == 0 && uap->oattr != NULL) {
2257 bzero(oattr.__reserved, sizeof(oattr.__reserved));
2258 error = copyout(&oattr, uap->oattr, sizeof(oattr));
2264 sys_kmq_timedreceive(struct thread *td, struct kmq_timedreceive_args *uap)
2268 struct timespec *abs_timeout, ets;
2272 AUDIT_ARG_FD(uap->mqd);
2273 error = getmq_read(td, uap->mqd, &fp, NULL, &mq);
2276 if (uap->abs_timeout != NULL) {
2277 error = copyin(uap->abs_timeout, &ets, sizeof(ets));
2283 waitok = !(fp->f_flag & O_NONBLOCK);
2284 error = mqueue_receive(mq, uap->msg_ptr, uap->msg_len,
2285 uap->msg_prio, waitok, abs_timeout);
2292 sys_kmq_timedsend(struct thread *td, struct kmq_timedsend_args *uap)
2296 struct timespec *abs_timeout, ets;
2299 AUDIT_ARG_FD(uap->mqd);
2300 error = getmq_write(td, uap->mqd, &fp, NULL, &mq);
2303 if (uap->abs_timeout != NULL) {
2304 error = copyin(uap->abs_timeout, &ets, sizeof(ets));
2310 waitok = !(fp->f_flag & O_NONBLOCK);
2311 error = mqueue_send(mq, uap->msg_ptr, uap->msg_len,
2312 uap->msg_prio, waitok, abs_timeout);
2319 kern_kmq_notify(struct thread *td, int mqd, struct sigevent *sigev)
2321 struct filedesc *fdp;
2324 struct file *fp, *fp2;
2325 struct mqueue_notifier *nt, *newnt = NULL;
2329 if (sigev != NULL) {
2330 if (sigev->sigev_notify != SIGEV_SIGNAL &&
2331 sigev->sigev_notify != SIGEV_THREAD_ID &&
2332 sigev->sigev_notify != SIGEV_NONE)
2334 if ((sigev->sigev_notify == SIGEV_SIGNAL ||
2335 sigev->sigev_notify == SIGEV_THREAD_ID) &&
2336 !_SIG_VALID(sigev->sigev_signo))
2340 fdp = td->td_proc->p_fd;
2341 error = getmq(td, mqd, &fp, NULL, &mq);
2345 FILEDESC_SLOCK(fdp);
2346 fp2 = fget_noref(fdp, mqd);
2348 FILEDESC_SUNLOCK(fdp);
2353 error = cap_check(cap_rights(fdp, mqd), &cap_event_rights);
2355 FILEDESC_SUNLOCK(fdp);
2360 FILEDESC_SUNLOCK(fdp);
2364 mtx_lock(&mq->mq_mutex);
2365 FILEDESC_SUNLOCK(fdp);
2366 if (sigev != NULL) {
2367 if (mq->mq_notifier != NULL) {
2371 nt = notifier_search(p, mqd);
2373 if (newnt == NULL) {
2375 mtx_unlock(&mq->mq_mutex);
2376 newnt = notifier_alloc();
2382 sigqueue_take(&nt->nt_ksi);
2383 if (newnt != NULL) {
2384 notifier_free(newnt);
2390 ksiginfo_init(&nt->nt_ksi);
2391 nt->nt_ksi.ksi_flags |= KSI_INS | KSI_EXT;
2392 nt->nt_ksi.ksi_code = SI_MESGQ;
2394 nt->nt_ksi.ksi_mqd = mqd;
2395 notifier_insert(p, nt);
2397 nt->nt_sigev = *sigev;
2398 mq->mq_notifier = nt;
2401 * if there is no receivers and message queue
2402 * is not empty, we should send notification
2403 * as soon as possible.
2405 if (mq->mq_receivers == 0 &&
2406 !TAILQ_EMPTY(&mq->mq_msgq))
2407 mqueue_send_notification(mq);
2410 notifier_remove(p, mq, mqd);
2412 mtx_unlock(&mq->mq_mutex);
2417 notifier_free(newnt);
2422 sys_kmq_notify(struct thread *td, struct kmq_notify_args *uap)
2424 struct sigevent ev, *evp;
2427 if (uap->sigev == NULL) {
2430 error = copyin(uap->sigev, &ev, sizeof(ev));
2435 return (kern_kmq_notify(td, uap->mqd, evp));
2439 mqueue_fdclose(struct thread *td, int fd, struct file *fp)
2443 struct filedesc *fdp;
2445 fdp = td->td_proc->p_fd;
2446 FILEDESC_LOCK_ASSERT(fdp);
2449 if (fp->f_ops == &mqueueops) {
2451 mtx_lock(&mq->mq_mutex);
2452 notifier_remove(td->td_proc, mq, fd);
2454 /* have to wakeup thread in same process */
2455 if (mq->mq_flags & MQ_RSEL) {
2456 mq->mq_flags &= ~MQ_RSEL;
2457 selwakeup(&mq->mq_rsel);
2459 if (mq->mq_flags & MQ_WSEL) {
2460 mq->mq_flags &= ~MQ_WSEL;
2461 selwakeup(&mq->mq_wsel);
2463 mtx_unlock(&mq->mq_mutex);
2468 mq_proc_exit(void *arg __unused, struct proc *p)
2470 struct filedesc *fdp;
2476 FILEDESC_SLOCK(fdp);
2477 for (i = 0; i < fdp->fd_nfiles; ++i) {
2478 fp = fget_noref(fdp, i);
2479 if (fp != NULL && fp->f_ops == &mqueueops) {
2481 mtx_lock(&mq->mq_mutex);
2482 notifier_remove(p, FPTOMQ(fp), i);
2483 mtx_unlock(&mq->mq_mutex);
2486 FILEDESC_SUNLOCK(fdp);
2487 KASSERT(LIST_EMPTY(&p->p_mqnotifier), ("mq notifiers left"));
2491 mqf_poll(struct file *fp, int events, struct ucred *active_cred,
2494 struct mqueue *mq = FPTOMQ(fp);
2497 mtx_lock(&mq->mq_mutex);
2498 if (events & (POLLIN | POLLRDNORM)) {
2499 if (mq->mq_curmsgs) {
2500 revents |= events & (POLLIN | POLLRDNORM);
2502 mq->mq_flags |= MQ_RSEL;
2503 selrecord(td, &mq->mq_rsel);
2506 if (events & POLLOUT) {
2507 if (mq->mq_curmsgs < mq->mq_maxmsg)
2510 mq->mq_flags |= MQ_WSEL;
2511 selrecord(td, &mq->mq_wsel);
2514 mtx_unlock(&mq->mq_mutex);
2519 mqf_close(struct file *fp, struct thread *td)
2521 struct mqfs_node *pn;
2523 fp->f_ops = &badfileops;
2526 sx_xlock(&mqfs_data.mi_lock);
2528 sx_xunlock(&mqfs_data.mi_lock);
2533 mqf_stat(struct file *fp, struct stat *st, struct ucred *active_cred)
2535 struct mqfs_node *pn = fp->f_data;
2537 bzero(st, sizeof *st);
2538 sx_xlock(&mqfs_data.mi_lock);
2539 st->st_atim = pn->mn_atime;
2540 st->st_mtim = pn->mn_mtime;
2541 st->st_ctim = pn->mn_ctime;
2542 st->st_birthtim = pn->mn_birth;
2543 st->st_uid = pn->mn_uid;
2544 st->st_gid = pn->mn_gid;
2545 st->st_mode = S_IFIFO | pn->mn_mode;
2546 sx_xunlock(&mqfs_data.mi_lock);
2551 mqf_chmod(struct file *fp, mode_t mode, struct ucred *active_cred,
2554 struct mqfs_node *pn;
2559 sx_xlock(&mqfs_data.mi_lock);
2560 error = vaccess(VREG, pn->mn_mode, pn->mn_uid, pn->mn_gid, VADMIN,
2564 pn->mn_mode = mode & ACCESSPERMS;
2566 sx_xunlock(&mqfs_data.mi_lock);
2571 mqf_chown(struct file *fp, uid_t uid, gid_t gid, struct ucred *active_cred,
2574 struct mqfs_node *pn;
2579 sx_xlock(&mqfs_data.mi_lock);
2580 if (uid == (uid_t)-1)
2582 if (gid == (gid_t)-1)
2584 if (((uid != pn->mn_uid && uid != active_cred->cr_uid) ||
2585 (gid != pn->mn_gid && !groupmember(gid, active_cred))) &&
2586 (error = priv_check_cred(active_cred, PRIV_VFS_CHOWN)))
2591 sx_xunlock(&mqfs_data.mi_lock);
2596 mqf_kqfilter(struct file *fp, struct knote *kn)
2598 struct mqueue *mq = FPTOMQ(fp);
2601 if (kn->kn_filter == EVFILT_READ) {
2602 kn->kn_fop = &mq_rfiltops;
2603 knlist_add(&mq->mq_rsel.si_note, kn, 0);
2604 } else if (kn->kn_filter == EVFILT_WRITE) {
2605 kn->kn_fop = &mq_wfiltops;
2606 knlist_add(&mq->mq_wsel.si_note, kn, 0);
2613 filt_mqdetach(struct knote *kn)
2615 struct mqueue *mq = FPTOMQ(kn->kn_fp);
2617 if (kn->kn_filter == EVFILT_READ)
2618 knlist_remove(&mq->mq_rsel.si_note, kn, 0);
2619 else if (kn->kn_filter == EVFILT_WRITE)
2620 knlist_remove(&mq->mq_wsel.si_note, kn, 0);
2622 panic("filt_mqdetach");
2626 filt_mqread(struct knote *kn, long hint)
2628 struct mqueue *mq = FPTOMQ(kn->kn_fp);
2630 mtx_assert(&mq->mq_mutex, MA_OWNED);
2631 return (mq->mq_curmsgs != 0);
2635 filt_mqwrite(struct knote *kn, long hint)
2637 struct mqueue *mq = FPTOMQ(kn->kn_fp);
2639 mtx_assert(&mq->mq_mutex, MA_OWNED);
2640 return (mq->mq_curmsgs < mq->mq_maxmsg);
2644 mqf_fill_kinfo(struct file *fp, struct kinfo_file *kif, struct filedesc *fdp)
2647 kif->kf_type = KF_TYPE_MQUEUE;
2651 static struct fileops mqueueops = {
2652 .fo_read = invfo_rdwr,
2653 .fo_write = invfo_rdwr,
2654 .fo_truncate = invfo_truncate,
2655 .fo_ioctl = invfo_ioctl,
2656 .fo_poll = mqf_poll,
2657 .fo_kqfilter = mqf_kqfilter,
2658 .fo_stat = mqf_stat,
2659 .fo_close = mqf_close,
2660 .fo_chmod = mqf_chmod,
2661 .fo_chown = mqf_chown,
2662 .fo_sendfile = invfo_sendfile,
2663 .fo_fill_kinfo = mqf_fill_kinfo,
2664 .fo_flags = DFLAG_PASSABLE,
2667 static struct vop_vector mqfs_vnodeops = {
2668 .vop_default = &default_vnodeops,
2669 .vop_access = mqfs_access,
2670 .vop_cachedlookup = mqfs_lookup,
2671 .vop_lookup = vfs_cache_lookup,
2672 .vop_reclaim = mqfs_reclaim,
2673 .vop_create = mqfs_create,
2674 .vop_remove = mqfs_remove,
2675 .vop_inactive = mqfs_inactive,
2676 .vop_open = mqfs_open,
2677 .vop_close = mqfs_close,
2678 .vop_getattr = mqfs_getattr,
2679 .vop_setattr = mqfs_setattr,
2680 .vop_read = mqfs_read,
2681 .vop_write = VOP_EOPNOTSUPP,
2682 .vop_readdir = mqfs_readdir,
2683 .vop_mkdir = VOP_EOPNOTSUPP,
2684 .vop_rmdir = VOP_EOPNOTSUPP
2686 VFS_VOP_VECTOR_REGISTER(mqfs_vnodeops);
2688 static struct vfsops mqfs_vfsops = {
2689 .vfs_init = mqfs_init,
2690 .vfs_uninit = mqfs_uninit,
2691 .vfs_mount = mqfs_mount,
2692 .vfs_unmount = mqfs_unmount,
2693 .vfs_root = mqfs_root,
2694 .vfs_statfs = mqfs_statfs,
2697 static struct vfsconf mqueuefs_vfsconf = {
2698 .vfc_version = VFS_VERSION,
2699 .vfc_name = "mqueuefs",
2700 .vfc_vfsops = &mqfs_vfsops,
2702 .vfc_flags = VFCF_SYNTHETIC
2705 static struct syscall_helper_data mq_syscalls[] = {
2706 SYSCALL_INIT_HELPER(kmq_open),
2707 SYSCALL_INIT_HELPER_F(kmq_setattr, SYF_CAPENABLED),
2708 SYSCALL_INIT_HELPER_F(kmq_timedsend, SYF_CAPENABLED),
2709 SYSCALL_INIT_HELPER_F(kmq_timedreceive, SYF_CAPENABLED),
2710 SYSCALL_INIT_HELPER_F(kmq_notify, SYF_CAPENABLED),
2711 SYSCALL_INIT_HELPER(kmq_unlink),
2715 #ifdef COMPAT_FREEBSD32
2716 #include <compat/freebsd32/freebsd32.h>
2717 #include <compat/freebsd32/freebsd32_proto.h>
2718 #include <compat/freebsd32/freebsd32_signal.h>
2719 #include <compat/freebsd32/freebsd32_syscall.h>
2720 #include <compat/freebsd32/freebsd32_util.h>
2723 mq_attr_from32(const struct mq_attr32 *from, struct mq_attr *to)
2726 to->mq_flags = from->mq_flags;
2727 to->mq_maxmsg = from->mq_maxmsg;
2728 to->mq_msgsize = from->mq_msgsize;
2729 to->mq_curmsgs = from->mq_curmsgs;
2733 mq_attr_to32(const struct mq_attr *from, struct mq_attr32 *to)
2736 to->mq_flags = from->mq_flags;
2737 to->mq_maxmsg = from->mq_maxmsg;
2738 to->mq_msgsize = from->mq_msgsize;
2739 to->mq_curmsgs = from->mq_curmsgs;
2743 freebsd32_kmq_open(struct thread *td, struct freebsd32_kmq_open_args *uap)
2745 struct mq_attr attr;
2746 struct mq_attr32 attr32;
2749 if ((uap->flags & O_ACCMODE) == O_ACCMODE || uap->flags & O_EXEC)
2751 flags = FFLAGS(uap->flags);
2752 if ((flags & O_CREAT) != 0 && uap->attr != NULL) {
2753 error = copyin(uap->attr, &attr32, sizeof(attr32));
2756 mq_attr_from32(&attr32, &attr);
2758 return (kern_kmq_open(td, uap->path, flags, uap->mode,
2759 uap->attr != NULL ? &attr : NULL));
2763 freebsd32_kmq_setattr(struct thread *td, struct freebsd32_kmq_setattr_args *uap)
2765 struct mq_attr attr, oattr;
2766 struct mq_attr32 attr32, oattr32;
2769 if (uap->attr != NULL) {
2770 error = copyin(uap->attr, &attr32, sizeof(attr32));
2773 mq_attr_from32(&attr32, &attr);
2775 error = kern_kmq_setattr(td, uap->mqd, uap->attr != NULL ? &attr : NULL,
2777 if (error == 0 && uap->oattr != NULL) {
2778 mq_attr_to32(&oattr, &oattr32);
2779 bzero(oattr32.__reserved, sizeof(oattr32.__reserved));
2780 error = copyout(&oattr32, uap->oattr, sizeof(oattr32));
2786 freebsd32_kmq_timedsend(struct thread *td,
2787 struct freebsd32_kmq_timedsend_args *uap)
2791 struct timespec32 ets32;
2792 struct timespec *abs_timeout, ets;
2796 AUDIT_ARG_FD(uap->mqd);
2797 error = getmq_write(td, uap->mqd, &fp, NULL, &mq);
2800 if (uap->abs_timeout != NULL) {
2801 error = copyin(uap->abs_timeout, &ets32, sizeof(ets32));
2804 CP(ets32, ets, tv_sec);
2805 CP(ets32, ets, tv_nsec);
2809 waitok = !(fp->f_flag & O_NONBLOCK);
2810 error = mqueue_send(mq, uap->msg_ptr, uap->msg_len,
2811 uap->msg_prio, waitok, abs_timeout);
2818 freebsd32_kmq_timedreceive(struct thread *td,
2819 struct freebsd32_kmq_timedreceive_args *uap)
2823 struct timespec32 ets32;
2824 struct timespec *abs_timeout, ets;
2827 AUDIT_ARG_FD(uap->mqd);
2828 error = getmq_read(td, uap->mqd, &fp, NULL, &mq);
2831 if (uap->abs_timeout != NULL) {
2832 error = copyin(uap->abs_timeout, &ets32, sizeof(ets32));
2835 CP(ets32, ets, tv_sec);
2836 CP(ets32, ets, tv_nsec);
2840 waitok = !(fp->f_flag & O_NONBLOCK);
2841 error = mqueue_receive(mq, uap->msg_ptr, uap->msg_len,
2842 uap->msg_prio, waitok, abs_timeout);
2849 freebsd32_kmq_notify(struct thread *td, struct freebsd32_kmq_notify_args *uap)
2851 struct sigevent ev, *evp;
2852 struct sigevent32 ev32;
2855 if (uap->sigev == NULL) {
2858 error = copyin(uap->sigev, &ev32, sizeof(ev32));
2861 error = convert_sigevent32(&ev32, &ev);
2866 return (kern_kmq_notify(td, uap->mqd, evp));
2869 static struct syscall_helper_data mq32_syscalls[] = {
2870 SYSCALL32_INIT_HELPER(freebsd32_kmq_open),
2871 SYSCALL32_INIT_HELPER_F(freebsd32_kmq_setattr, SYF_CAPENABLED),
2872 SYSCALL32_INIT_HELPER_F(freebsd32_kmq_timedsend, SYF_CAPENABLED),
2873 SYSCALL32_INIT_HELPER_F(freebsd32_kmq_timedreceive, SYF_CAPENABLED),
2874 SYSCALL32_INIT_HELPER_F(freebsd32_kmq_notify, SYF_CAPENABLED),
2875 SYSCALL32_INIT_HELPER_COMPAT(kmq_unlink),
2885 error = syscall_helper_register(mq_syscalls, SY_THR_STATIC_KLD);
2888 #ifdef COMPAT_FREEBSD32
2889 error = syscall32_helper_register(mq32_syscalls, SY_THR_STATIC_KLD);
2900 #ifdef COMPAT_FREEBSD32
2901 syscall32_helper_unregister(mq32_syscalls);
2903 syscall_helper_unregister(mq_syscalls);
2908 mq_modload(struct module *module, int cmd, void *arg)
2912 error = vfs_modevent(module, cmd, arg);
2931 static moduledata_t mqueuefs_mod = {
2936 DECLARE_MODULE(mqueuefs, mqueuefs_mod, SI_SUB_VFS, SI_ORDER_MIDDLE);
2937 MODULE_VERSION(mqueuefs, 1);