Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src - Implement prop_{array, dictionary}_copyout(), based on



details:   https://anonhg.NetBSD.org/src/rev/4bba8ca89682
branches:  trunk
changeset: 761058:4bba8ca89682
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Wed Jan 19 20:34:23 2011 +0000

description:
- Implement prop_{array,dictionary}_copyout(), based on
  prop_{array,dictionary}_copyout_ioctl().
- Implement prop_{array,dictionary}_recv_syscall(), which
  takes as parameter the pref we got from kernel and internalize it,
  and unmaps the buffer prop_{array,dictionary}_copyout() mapped for us.
- add a prop_{array,dictionary}_send_syscall() for symetry, which is
  an alias to prop_{array,dictionary}_externalize_to_pref()

Discussed on tech-kern@ and tech-userlevel@

diffstat:

 common/include/prop/prop_array.h       |    6 +-
 common/include/prop/prop_dictionary.h  |    8 ++-
 common/lib/libprop/prop_copyin_ioctl.9 |   19 ++++-
 common/lib/libprop/prop_kern.c         |   69 +++++++++++++++++++--
 common/lib/libprop/prop_send_syscall.3 |  106 +++++++++++++++++++++++++++++++++
 common/lib/libprop/proplib.3           |    5 +-
 distrib/sets/lists/comp/mi             |   17 ++++-
 lib/libprop/Makefile                   |    8 ++-
 8 files changed, 221 insertions(+), 17 deletions(-)

diffs (truncated from 503 to 300 lines):

diff -r f5c41e89619d -r 4bba8ca89682 common/include/prop/prop_array.h
--- a/common/include/prop/prop_array.h  Wed Jan 19 19:58:02 2011 +0000
+++ b/common/include/prop/prop_array.h  Wed Jan 19 20:34:23 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: prop_array.h,v 1.9 2009/10/10 21:26:16 bad Exp $    */
+/*     $NetBSD: prop_array.h,v 1.10 2011/01/19 20:34:23 bouyer Exp $    */
 
 /*-
  * Copyright (c) 2006, 2009 The NetBSD Foundation, Inc.
@@ -72,8 +72,12 @@
 bool           prop_array_externalize_to_pref(prop_array_t, struct plistref *);
 int            prop_array_send_ioctl(prop_array_t, int, unsigned long);
 int            prop_array_recv_ioctl(int, unsigned long, prop_array_t *);
+bool           prop_array_send_syscall(prop_array_t, struct plistref *);
+bool           prop_array_recv_syscall(const struct plistref *,
+                                       prop_array_t *);
 #elif defined(_KERNEL)
 int            prop_array_copyin(const struct plistref *, prop_array_t *);
+int            prop_array_copyout(struct plistref *, prop_array_t *);
 int            prop_array_copyin_ioctl(const struct plistref *, const u_long,
                                        prop_array_t *);
 int            prop_array_copyout_ioctl(struct plistref *, const u_long,
diff -r f5c41e89619d -r 4bba8ca89682 common/include/prop/prop_dictionary.h
--- a/common/include/prop/prop_dictionary.h     Wed Jan 19 19:58:02 2011 +0000
+++ b/common/include/prop/prop_dictionary.h     Wed Jan 19 20:34:23 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: prop_dictionary.h,v 1.10 2009/10/10 21:26:16 bad Exp $ */
+/*     $NetBSD: prop_dictionary.h,v 1.11 2011/01/19 20:34:23 bouyer Exp $      */
 
 /*-
  * Copyright (c) 2006, 2009 The NetBSD Foundation, Inc.
@@ -93,9 +93,15 @@
 int            prop_dictionary_sendrecv_ioctl(prop_dictionary_t,
                                               int, unsigned long,
                                               prop_dictionary_t *);
+bool           prop_dictionary_send_syscall(prop_dictionary_t,
+                    struct plistref *);
+bool           prop_dictionary_recv_syscall(const struct plistref *,
+                                          prop_dictionary_t *);
 #elif defined(_KERNEL)
 int            prop_dictionary_copyin(const struct plistref *,
                                       prop_dictionary_t *);
+int            prop_dictionary_copyout(struct plistref *,
+                                      prop_dictionary_t *);
 int            prop_dictionary_copyin_ioctl(const struct plistref *,
                                             const u_long,
                                             prop_dictionary_t *);
diff -r f5c41e89619d -r 4bba8ca89682 common/lib/libprop/prop_copyin_ioctl.9
--- a/common/lib/libprop/prop_copyin_ioctl.9    Wed Jan 19 19:58:02 2011 +0000
+++ b/common/lib/libprop/prop_copyin_ioctl.9    Wed Jan 19 20:34:23 2011 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: prop_copyin_ioctl.9,v 1.7 2009/12/14 05:47:30 dholland Exp $
+.\"    $NetBSD: prop_copyin_ioctl.9,v 1.8 2011/01/19 20:34:23 bouyer Exp $
 .\"
 .\" Copyright (c) 2006, 2009 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -27,16 +27,18 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd October 10, 2009
+.Dd January 17, 2011
 .Dt PROP_COPYIN_IOCTL 9
 .Os
 .Sh NAME
 .Nm prop_array_copyin_ioctl ,
 .Nm prop_array_copyout_ioctl ,
 .Nm prop_array_copyin ,
+.Nm prop_array_copyout ,
 .Nm prop_dictionary_copyin_ioctl ,
 .Nm prop_dictionary_copyout_ioctl ,
 .Nm prop_dictionary_copyin
+.Nm prop_dictionary_copyout
 .Nd Copy property lists to and from kernel space
 .Sh SYNOPSIS
 .In prop/proplib.h
@@ -50,6 +52,9 @@
 .Fn prop_array_copyout_ioctl "struct plistref *pref" \
     "const u_long cmd" "prop_array_t array"
 .Ft int
+.Fn prop_array_copyout "struct plistref *pref" \
+    "prop_array_t array"
+.Ft int
 .Fn prop_dictionary_copyin_ioctl "const struct plistref *pref" \
     "const u_long cmd" "prop_dictionary_t *dictp"
 .Ft int
@@ -58,6 +63,9 @@
 .Ft int
 .Fn prop_dictionary_copyout_ioctl "struct plistref *pref" \
     "const u_long cmd" "prop_dictionary_t dict"
+.Ft int
+.Fn prop_dictionary_copyout "struct plistref *pref" \
+    "prop_dictionary_t dict"
 .Sh DESCRIPTION
 The
 .Nm prop_array_copyin_ioctl ,
@@ -69,9 +77,11 @@
 to and from the kernel using
 .Xr ioctl 2 .
 The functions
-.Nm prop_array_copyin
+.Nm prop_array_copyin ,
+.Nm prop_array_copyout ,
+.Nm prop_dictionary_copyin
 and
-.Nm prop_dictionary_copyin
+.Nm prop_dictionary_copyout
 implement the kernel side of a protocol for copying property lists to the
 kernel as arguments of normal system calls.
 .Pp
@@ -175,6 +185,7 @@
 .Xr prop_array 3 ,
 .Xr prop_dictionary 3 ,
 .Xr prop_send_ioctl 3 ,
+.Xr prop_send_syscall 3 ,
 .Xr proplib 3
 .Sh HISTORY
 The
diff -r f5c41e89619d -r 4bba8ca89682 common/lib/libprop/prop_kern.c
--- a/common/lib/libprop/prop_kern.c    Wed Jan 19 19:58:02 2011 +0000
+++ b/common/lib/libprop/prop_kern.c    Wed Jan 19 20:34:23 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: prop_kern.c,v 1.14 2010/12/14 08:04:14 pooka Exp $     */
+/*     $NetBSD: prop_kern.c,v 1.15 2011/01/19 20:34:23 bouyer Exp $    */
 
 /*-
  * Copyright (c) 2006, 2009 The NetBSD Foundation, Inc.
@@ -90,6 +90,7 @@
                errno = rv;     /* pass up error value in errno */
        return (rv == 0);
 }
+__strong_alias(prop_array_send_syscall, prop_array_externalize_to_pref)
 
 /*
  * prop_dictionary_externalize_to_pref --
@@ -106,6 +107,8 @@
                errno = rv;     /* pass up error value in errno */
        return (rv == 0);
 }
+__strong_alias(prop_dictionary_send_syscall,
+    prop_dictionary_externalize_to_pref)
 
 static int
 _prop_object_send_ioctl(prop_object_t obj, int fd, unsigned long cmd)
@@ -222,6 +225,31 @@
 }
 
 /*
+ * prop_array_recv_syscall --
+ *     Receive an array from the kernel as pref.
+ *     Pref's buf is freed on exit
+ */
+bool
+prop_array_recv_syscall(const struct plistref *pref, prop_array_t *arrayp)
+{
+       return (_prop_object_internalize_from_pref(pref, PROP_TYPE_ARRAY,
+                                        (prop_object_t *)arrayp));
+}
+
+/*
+ * prop_dictionary_recv_syscall --
+ *     Receive a dictionary from the kernel as pref.
+ *     Pref's buf is freed on exit
+ */
+bool
+prop_dictionary_recv_syscall(const struct plistref *pref,
+    prop_dictionary_t *dictp)
+{
+       return (_prop_object_internalize_from_pref(pref, PROP_TYPE_DICTIONARY,
+                                        (prop_object_t *)dictp));
+}
+
+/*
  * prop_dictionary_sendrecv_ioctl --
  *     Combination send/receive a dictionary to/from the kernel using
  *     the specified ioctl.
@@ -385,8 +413,7 @@
 }
 
 static int
-_prop_object_copyout_ioctl(struct plistref *pref, const u_long cmd,
-                          prop_object_t obj)
+_prop_object_copyout(struct plistref *pref, prop_object_t obj)
 {
        struct lwp *l = curlwp;         /* XXX */
        struct proc *p = l->l_proc;
@@ -395,9 +422,6 @@
        int error = 0;
        vaddr_t uaddr;
 
-       if ((cmd & IOC_OUT) == 0)
-               return (EFAULT);
-
        switch (prop_object_type(obj)) {
        case PROP_TYPE_ARRAY:
                buf = prop_array_externalize(obj);
@@ -443,6 +467,36 @@
 }
 
 /*
+ * prop_array_copyout --
+ *     Copy out an array to a syscall arg.
+ */
+int
+prop_array_copyout(struct plistref *pref, prop_array_t *arrayp)
+{
+       return (_prop_object_copyout(pref, (prop_object_t *)arrayp));
+}
+
+/*
+ * prop_dictionary_copyout --
+ *     Copy out a dictionary to a syscall arg.
+ */
+int
+prop_dictionary_copyout(struct plistref *pref, prop_dictionary_t *dictp)
+{
+       return (_prop_object_copyout(pref, (prop_object_t *)dictp));
+}
+
+static int
+_prop_object_copyout_ioctl(struct plistref *pref, const u_long cmd,
+                          prop_object_t obj)
+{
+       if ((cmd & IOC_OUT) == 0)
+               return (EFAULT);
+       return _prop_object_copyout(pref, obj);
+}
+
+
+/*
  * prop_array_copyout_ioctl --
  *     Copy out an array being received with an ioctl.
  */
@@ -461,7 +515,8 @@
 prop_dictionary_copyout_ioctl(struct plistref *pref, const u_long cmd,
                              prop_dictionary_t dict)
 {
-       return (_prop_object_copyout_ioctl(pref, cmd, dict));
+       return (
+           _prop_object_copyout_ioctl(pref, cmd, dict));
 }
 #endif /* _KERNEL */
 
diff -r f5c41e89619d -r 4bba8ca89682 common/lib/libprop/prop_send_syscall.3
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/common/lib/libprop/prop_send_syscall.3    Wed Jan 19 20:34:23 2011 +0000
@@ -0,0 +1,106 @@
+.\"    $NetBSD: prop_send_syscall.3,v 1.1 2011/01/19 20:34:23 bouyer Exp $
+.\"
+.\" Copyright (c) 2006 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This code is derived from software contributed to The NetBSD Foundation
+.\" by Jason R. Thorpe.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd January 17, 2011
+.Dt PROP_SEND_SYCALL 3
+.Os
+.Sh NAME
+.Nm prop_array_send_syscall ,
+.Nm prop_array_recv_syscall ,
+.Nm prop_dictionary_send_syscall ,
+.Nm prop_dictionary_recv_syscall ,
+.Nd Helper to send and receive propertly lists to and from the kernel using
+syscall
+.Sh SYNOPSIS
+.In prop/proplib.h
+.Ft bool
+.Fn prop_array_send_syscall "prop_array_t array" "struct plistref *prefp"
+.Ft bool
+.Fn prop_array_recv_syscall "const struct plistref *prefp" \
+    "prop_array_t *arrayp"
+.Ft bool
+.Fn prop_dictionary_send_syscall "prop_dictionary_t dict" \
+    "struct plistref *prefp"
+.Ft bool
+.Fn prop_dictionary_recv_syscall "const struct plistref *prefp" \
+    "prop_dictionary_t *dictp"
+.Sh DESCRIPTION



Home | Main Index | Thread Index | Old Index