Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Make mqueue_get public, rearrange mq_open into a helper ...
details: https://anonhg.NetBSD.org/src/rev/fd7e9ba43710
branches: trunk
changeset: 338968:fd7e9ba43710
user: martin <martin%NetBSD.org@localhost>
date: Sat Jun 20 14:41:54 2015 +0000
description:
Make mqueue_get public, rearrange mq_open into a helper function that can
be called from compat code, adapt mqueue_create accordingly.
diffstat:
sys/kern/sys_mqueue.c | 85 ++++++++++++++++++++++++++++++--------------------
sys/sys/mqueue.h | 5 ++-
2 files changed, 55 insertions(+), 35 deletions(-)
diffs (184 lines):
diff -r 8b5f5ffe716f -r fd7e9ba43710 sys/kern/sys_mqueue.c
--- a/sys/kern/sys_mqueue.c Sat Jun 20 07:13:25 2015 +0000
+++ b/sys/kern/sys_mqueue.c Sat Jun 20 14:41:54 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sys_mqueue.c,v 1.37 2014/09/05 09:20:59 matt Exp $ */
+/* $NetBSD: sys_mqueue.c,v 1.38 2015/06/20 14:41:54 martin Exp $ */
/*
* Copyright (c) 2007-2011 Mindaugas Rasiukevicius <rmind at NetBSD org>
@@ -43,7 +43,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_mqueue.c,v 1.37 2014/09/05 09:20:59 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_mqueue.c,v 1.38 2015/06/20 14:41:54 martin Exp $");
#include <sys/param.h>
#include <sys/types.h>
@@ -284,7 +284,7 @@
* => locks the message queue, if found.
* => holds a reference on the file descriptor.
*/
-static int
+int
mqueue_get(mqd_t mqd, int fflag, mqueue_t **mqret)
{
const int fd = (int)mqd;
@@ -422,13 +422,12 @@
}
static int
-mqueue_create(lwp_t *l, char *name, struct mq_attr *uattr, mode_t mode,
+mqueue_create(lwp_t *l, char *name, struct mq_attr *attr, mode_t mode,
int oflag, mqueue_t **mqret)
{
proc_t *p = l->l_proc;
struct cwdinfo *cwdi = p->p_cwdi;
mqueue_t *mq;
- struct mq_attr attr;
u_int i;
/* Pre-check the limit. */
@@ -442,22 +441,13 @@
}
/* Check for mqueue attributes. */
- if (uattr) {
- int error;
-
- error = copyin(uattr, &attr, sizeof(struct mq_attr));
- if (error) {
- return error;
- }
- if (attr.mq_maxmsg <= 0 || attr.mq_maxmsg > mq_max_maxmsg ||
- attr.mq_msgsize <= 0 || attr.mq_msgsize > mq_max_msgsize) {
+ if (attr) {
+ if (attr->mq_maxmsg <= 0 || attr->mq_maxmsg > mq_max_maxmsg ||
+ attr->mq_msgsize <= 0 ||
+ attr->mq_msgsize > mq_max_msgsize) {
return EINVAL;
}
- attr.mq_curmsgs = 0;
- } else {
- memset(&attr, 0, sizeof(struct mq_attr));
- attr.mq_maxmsg = mq_def_maxmsg;
- attr.mq_msgsize = MQ_DEF_MSGSIZE - sizeof(struct mq_msg);
+ attr->mq_curmsgs = 0;
}
/*
@@ -477,7 +467,13 @@
mq->mq_name = name;
mq->mq_refcnt = 1;
- memcpy(&mq->mq_attrib, &attr, sizeof(struct mq_attr));
+ if (attr != NULL) {
+ memcpy(&mq->mq_attrib, attr, sizeof(struct mq_attr));
+ } else {
+ memset(&mq->mq_attrib, 0, sizeof(struct mq_attr));
+ mq->mq_attrib.mq_maxmsg = mq_def_maxmsg;
+ mq->mq_attrib.mq_msgsize = MQ_DEF_MSGSIZE - sizeof(struct mq_msg);
+ }
CTASSERT((O_MASK & (MQ_UNLINKED | MQ_RECEIVE)) == 0);
mq->mq_attrib.mq_flags = (O_MASK & oflag);
@@ -492,28 +488,22 @@
}
/*
- * General mqueue system calls.
+ * Helper function for mq_open() - note that "u_name" is a userland pointer,
+ * while "attr" is a kernel pointer!
*/
-
int
-sys_mq_open(struct lwp *l, const struct sys_mq_open_args *uap,
- register_t *retval)
+mq_handle_open(struct lwp *l, const char *u_name, int oflag, mode_t mode,
+ struct mq_attr *attr, register_t *retval)
{
- /* {
- syscallarg(const char *) name;
- syscallarg(int) oflag;
- syscallarg(mode_t) mode;
- syscallarg(struct mq_attr) attr;
- } */
struct proc *p = l->l_proc;
struct mqueue *mq, *mq_new = NULL;
- int mqd, error, oflag = SCARG(uap, oflag);
+ int mqd, error;
file_t *fp;
char *name;
/* Get the name from the user-space. */
name = kmem_alloc(MQ_NAMELEN, KM_SLEEP);
- error = copyinstr(SCARG(uap, name), name, MQ_NAMELEN - 1, NULL);
+ error = copyinstr(u_name, name, MQ_NAMELEN - 1, NULL);
if (error) {
kmem_free(name, MQ_NAMELEN);
return error;
@@ -531,8 +521,7 @@
if (oflag & O_CREAT) {
/* Create a new message queue. */
- error = mqueue_create(l, name, SCARG(uap, attr),
- SCARG(uap, mode), oflag, &mq_new);
+ error = mqueue_create(l, name, attr, mode, oflag, &mq_new);
if (error) {
goto err;
}
@@ -612,6 +601,34 @@
return error;
}
+/*
+ * General mqueue system calls.
+ */
+
+int
+sys_mq_open(struct lwp *l, const struct sys_mq_open_args *uap,
+ register_t *retval)
+{
+ /* {
+ syscallarg(const char *) name;
+ syscallarg(int) oflag;
+ syscallarg(mode_t) mode;
+ syscallarg(struct mq_attr) attr;
+ } */
+ struct mq_attr *attr = NULL, a;
+ int error;
+
+ if ((SCARG(uap, oflag) & O_CREAT) && (SCARG(uap,attr) != NULL)) {
+ error = copyin(&a, SCARG(uap,attr), sizeof(a));
+ if (error)
+ return error;
+ attr = &a;
+ }
+
+ return mq_handle_open(l, SCARG(uap, name), SCARG(uap, oflag),
+ SCARG(uap, mode), attr, retval);
+}
+
int
sys_mq_close(struct lwp *l, const struct sys_mq_close_args *uap,
register_t *retval)
diff -r 8b5f5ffe716f -r fd7e9ba43710 sys/sys/mqueue.h
--- a/sys/sys/mqueue.h Sat Jun 20 07:13:25 2015 +0000
+++ b/sys/sys/mqueue.h Sat Jun 20 14:41:54 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mqueue.h,v 1.16 2011/11/21 04:36:05 christos Exp $ */
+/* $NetBSD: mqueue.h,v 1.17 2015/06/20 14:41:54 martin Exp $ */
/*
* Copyright (c) 2007-2009 Mindaugas Rasiukevicius <rmind at NetBSD org>
@@ -112,6 +112,9 @@
void mqueue_print_list(void (*pr)(const char *, ...) __printflike(1, 2));
int mq_send1(mqd_t, const char *, size_t, u_int, struct timespec *);
int mq_recv1(mqd_t, void *, size_t, u_int *, struct timespec *, ssize_t *);
+int mqueue_get(mqd_t mqd, int fflag, mqueue_t **mqret);
+int mq_handle_open(struct lwp *l, const char *, int, mode_t,
+ struct mq_attr*, register_t *retval);
#endif /* _KERNEL */
Home |
Main Index |
Thread Index |
Old Index