On Mon, Jan 17, 2011 at 04:33:25PM +0100, Manuel Bouyer wrote: > [sorry for the cross-post, but I can't decide which list is more appropriate > than the other :) ] > > Hello, > so I'm evaluating how to use proplib for the new quotactl(2) I'm working on. > I see there is already provision of function to pass property list between > kernel and userland using ioctl, but there is no equivalent for syscalls. > Should there be ? > For kernel land, prop_{array,dictionary}_copy{in,out} would do it > (prop_{array,dictionary}_copyout is documented but not implemented, > this is easy). > For userland, we probably need a prop_{array,dictionary}_recv_syscall(), > wich takes as parameter the pref we got from kernel, and internalize it. > Parameters would be the pref, and a pointer to the prop_array_t or > prop_dictionary_t that will get the result. What this would do in > addition to call prop_{array,dictionary}_internalize_from_pref() is > to unmap the buffer the kernel mmaped for us. I don't think this details of > the > kernel/userland communication should be exposed outside of the > proplib code. > > For symetry, we probably want a prop_{array,dictionary}_send_syscall() > which is just an alias to prop_{array,dictionary}_externalize_to_pref() > > Comments ?
here is a diff implementing the above -- Manuel Bouyer <bou...@antioche.eu.org> NetBSD: 26 ans d'experience feront toujours la difference --
Index: common/lib/libprop/prop_copyin_ioctl.9 =================================================================== RCS file: /cvsroot/src/common/lib/libprop/prop_copyin_ioctl.9,v retrieving revision 1.7 diff -u -r1.7 prop_copyin_ioctl.9 --- common/lib/libprop/prop_copyin_ioctl.9 14 Dec 2009 05:47:30 -0000 1.7 +++ common/lib/libprop/prop_copyin_ioctl.9 17 Jan 2011 16:58:09 -0000 @@ -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 -and +.Nm prop_array_copyin , +.Nm prop_array_copyout , .Nm prop_dictionary_copyin +and +.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 Index: common/lib/libprop/prop_kern.c =================================================================== RCS file: /cvsroot/src/common/lib/libprop/prop_kern.c,v retrieving revision 1.14 diff -u -r1.14 prop_kern.c --- common/lib/libprop/prop_kern.c 14 Dec 2010 08:04:14 -0000 1.14 +++ common/lib/libprop/prop_kern.c 17 Jan 2011 16:58:09 -0000 @@ -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 */ Index: common/lib/libprop/prop_send_syscall.3 =================================================================== RCS file: common/lib/libprop/prop_send_syscall.3 diff -N common/lib/libprop/prop_send_syscall.3 --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ common/lib/libprop/prop_send_syscall.3 17 Jan 2011 16:58:09 -0000 @@ -0,0 +1,106 @@ +.\" $NetBSD: prop_send_ioctl.3,v 1.5 2008/04/30 13:10:46 martin 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 +The +.Nm prop_array_send_syscall , +.Nm prop_array_recv_syscall , +.Nm prop_dictionary_send_syscall , +and +.Nm prop_dictionary_recv_syscall +functions implement the user space side of a protocol for sending property +lists to and from the kernel using +.Xr syscall 2 . +.Sh RETURN VALUES +If successful, functions return true, false otherwise. +.Sh EXAMPLES +The following +.Pq simplified +example demonstrates using +.Fn prop_dictionary_send_syscall +and +.Fn prop_dictionary_recv_syscall +in an application: +.Bd -literal +void +foo_setprops(prop_dictionary_t dict) +{ + struct pref pref; + + (void) prop_dictionary_send_ioctl(dict, \*[Am]pref); + (void) my_syscall_set(\*[Am]pref); + +} + +prop_dictionary_t +foo_getprops(void) +{ + prop_dictionary_t dict; + struct pref pref; + + (void) my_syscall_get(\*[Am]pref); + if (!prop_dictionary_recv_syscall(\*[Am]pref, \*[Am]dict)) + return (NULL); + + return (dict); +} +.Ed +.Sh SEE ALSO +.Xr prop_array 3 , +.Xr prop_dictionary 3 , +.Xr proplib 3 , +.Xr prop_copyin_ioctl 9 +.Sh HISTORY +The +.Nm proplib +property container object library first appeared in +.Nx 4.0 . Index: common/lib/libprop/proplib.3 =================================================================== RCS file: /cvsroot/src/common/lib/libprop/proplib.3,v retrieving revision 1.6 diff -u -r1.6 proplib.3 --- common/lib/libprop/proplib.3 13 May 2009 22:31:59 -0000 1.6 +++ common/lib/libprop/proplib.3 17 Jan 2011 16:58:09 -0000 @@ -27,7 +27,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd June 21, 2007 +.Dd January 17, 2011 .Dt PROPLIB 3 .Os .Sh NAME @@ -94,6 +94,7 @@ .Xr prop_number 3 , .Xr prop_object 3 , .Xr prop_send_ioctl 3 , +.Xr prop_send_syscall 3 , .Xr prop_string 3 .Sh HISTORY The Index: common/include/prop/prop_array.h =================================================================== RCS file: /cvsroot/src/common/include/prop/prop_array.h,v retrieving revision 1.9 diff -u -r1.9 prop_array.h --- common/include/prop/prop_array.h 10 Oct 2009 21:26:16 -0000 1.9 +++ common/include/prop/prop_array.h 17 Jan 2011 16:58:09 -0000 @@ -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, Index: common/include/prop/prop_dictionary.h =================================================================== RCS file: /cvsroot/src/common/include/prop/prop_dictionary.h,v retrieving revision 1.10 diff -u -r1.10 prop_dictionary.h --- common/include/prop/prop_dictionary.h 10 Oct 2009 21:26:16 -0000 1.10 +++ common/include/prop/prop_dictionary.h 17 Jan 2011 16:58:09 -0000 @@ -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 *); Index: lib/libprop/Makefile =================================================================== RCS file: /cvsroot/src/lib/libprop/Makefile,v retrieving revision 1.17 diff -u -r1.17 Makefile --- lib/libprop/Makefile 10 Oct 2009 18:06:54 -0000 1.17 +++ lib/libprop/Makefile 17 Jan 2011 16:58:09 -0000 @@ -31,6 +31,12 @@ MLINKS+= prop_send_ioctl.3 prop_dictionary_recv_ioctl.3 MLINKS+= prop_send_ioctl.3 prop_dictionary_sendrecv_ioctl.3 +MAN+= prop_send_syscall.3 +MLINKS+= prop_send_syscall.3 prop_array_send_syscall.3 +MLINKS+= prop_send_syscall.3 prop_array_recv_syscall.3 +MLINKS+= prop_send_syscall.3 prop_dictionary_send_syscall.3 +MLINKS+= prop_send_syscall.3 prop_dictionary_recv_syscall.3 + MAN+= prop_dictionary_util.3 MLINKS+= prop_dictionary_util.3 prop_dictionary_get_bool.3 MLINKS+= prop_dictionary_util.3 prop_dictionary_set_bool.3 Index: distrib/sets/lists/comp/mi =================================================================== RCS file: /cvsroot/src/distrib/sets/lists/comp/mi,v retrieving revision 1.1563 diff -u -r1.1563 mi --- distrib/sets/lists/comp/mi 26 Dec 2010 11:31:44 -0000 1.1563 +++ distrib/sets/lists/comp/mi 17 Jan 2011 16:58:09 -0000 @@ -7639,8 +7639,10 @@ ./usr/share/man/cat3/prop_array_make_immutable.0 comp-c-catman .cat ./usr/share/man/cat3/prop_array_mutable.0 comp-c-catman .cat ./usr/share/man/cat3/prop_array_recv_ioctl.0 comp-c-catman .cat +./usr/share/man/cat3/prop_array_recv_syscall.0 comp-c-catman .cat ./usr/share/man/cat3/prop_array_remove.0 comp-c-catman .cat ./usr/share/man/cat3/prop_array_send_ioctl.0 comp-c-catman .cat +./usr/share/man/cat3/prop_array_send_syscall.0 comp-c-catman .cat ./usr/share/man/cat3/prop_array_set.0 comp-c-catman .cat ./usr/share/man/cat3/prop_array_set_bool.0 comp-c-catman .cat ./usr/share/man/cat3/prop_array_set_cstring.0 comp-c-catman .cat @@ -7702,9 +7704,11 @@ ./usr/share/man/cat3/prop_dictionary_make_immutable.0 comp-c-catman .cat ./usr/share/man/cat3/prop_dictionary_mutable.0 comp-c-catman .cat ./usr/share/man/cat3/prop_dictionary_recv_ioctl.0 comp-c-catman .cat +./usr/share/man/cat3/prop_dictionary_recv_syscall.0 comp-c-catman .cat ./usr/share/man/cat3/prop_dictionary_remove.0 comp-c-catman .cat ./usr/share/man/cat3/prop_dictionary_remove_keysym.0 comp-c-catman .cat ./usr/share/man/cat3/prop_dictionary_send_ioctl.0 comp-c-catman .cat +./usr/share/man/cat3/prop_dictionary_send_syscall.0 comp-c-catman .cat ./usr/share/man/cat3/prop_dictionary_sendrecv_ioctl.0 comp-c-catman .cat ./usr/share/man/cat3/prop_dictionary_set.0 comp-c-catman .cat ./usr/share/man/cat3/prop_dictionary_set_bool.0 comp-c-catman .cat @@ -7747,6 +7751,7 @@ ./usr/share/man/cat3/prop_object_retain.0 comp-c-catman .cat ./usr/share/man/cat3/prop_object_type.0 comp-c-catman .cat ./usr/share/man/cat3/prop_send_ioctl.0 comp-c-catman .cat +./usr/share/man/cat3/prop_send_syscall.0 comp-c-catman .cat ./usr/share/man/cat3/prop_string.0 comp-c-catman .cat ./usr/share/man/cat3/prop_string_append.0 comp-c-catman .cat ./usr/share/man/cat3/prop_string_append_cstring.0 comp-c-catman .cat @@ -13638,8 +13643,10 @@ ./usr/share/man/html3/prop_array_make_immutable.html comp-c-htmlman html ./usr/share/man/html3/prop_array_mutable.html comp-c-htmlman html ./usr/share/man/html3/prop_array_recv_ioctl.html comp-c-htmlman html +./usr/share/man/html3/prop_array_recv_syscall.html comp-c-htmlman html ./usr/share/man/html3/prop_array_remove.html comp-c-htmlman html ./usr/share/man/html3/prop_array_send_ioctl.html comp-c-htmlman html +./usr/share/man/html3/prop_array_send_syscall.html comp-c-htmlman html ./usr/share/man/html3/prop_array_set.html comp-c-htmlman html ./usr/share/man/html3/prop_array_set_bool.html comp-c-htmlman html ./usr/share/man/html3/prop_array_set_cstring.html comp-c-htmlman html @@ -13701,9 +13708,11 @@ ./usr/share/man/html3/prop_dictionary_make_immutable.html comp-c-htmlman html ./usr/share/man/html3/prop_dictionary_mutable.html comp-c-htmlman html ./usr/share/man/html3/prop_dictionary_recv_ioctl.html comp-c-htmlman html +./usr/share/man/html3/prop_dictionary_recv_syscall.html comp-c-htmlman html ./usr/share/man/html3/prop_dictionary_remove.html comp-c-htmlman html ./usr/share/man/html3/prop_dictionary_remove_keysym.html comp-c-htmlman html ./usr/share/man/html3/prop_dictionary_send_ioctl.html comp-c-htmlman html +./usr/share/man/html3/prop_dictionary_send_syscall.html comp-c-htmlman html ./usr/share/man/html3/prop_dictionary_sendrecv_ioctl.html comp-c-htmlman html ./usr/share/man/html3/prop_dictionary_set.html comp-c-htmlman html ./usr/share/man/html3/prop_dictionary_set_bool.html comp-c-htmlman html @@ -13746,6 +13755,7 @@ ./usr/share/man/html3/prop_object_retain.html comp-c-htmlman html ./usr/share/man/html3/prop_object_type.html comp-c-htmlman html ./usr/share/man/html3/prop_send_ioctl.html comp-c-htmlman html +./usr/share/man/html3/prop_send_syscall.html comp-c-htmlman html ./usr/share/man/html3/prop_string.html comp-c-htmlman html ./usr/share/man/html3/prop_string_append.html comp-c-htmlman html ./usr/share/man/html3/prop_string_append_cstring.html comp-c-htmlman html @@ -19630,8 +19640,10 @@ ./usr/share/man/man3/prop_array_make_immutable.3 comp-c-man .man ./usr/share/man/man3/prop_array_mutable.3 comp-c-man .man ./usr/share/man/man3/prop_array_recv_ioctl.3 comp-c-man .man +./usr/share/man/man3/prop_array_recv_syscall.3 comp-c-man .man ./usr/share/man/man3/prop_array_remove.3 comp-c-man .man ./usr/share/man/man3/prop_array_send_ioctl.3 comp-c-man .man +./usr/share/man/man3/prop_array_send_syscall.3 comp-c-man .man ./usr/share/man/man3/prop_array_set.3 comp-c-man .man ./usr/share/man/man3/prop_array_set_bool.3 comp-c-man .man ./usr/share/man/man3/prop_array_set_cstring.3 comp-c-man .man @@ -19693,9 +19705,11 @@ ./usr/share/man/man3/prop_dictionary_make_immutable.3 comp-c-man .man ./usr/share/man/man3/prop_dictionary_mutable.3 comp-c-man .man ./usr/share/man/man3/prop_dictionary_recv_ioctl.3 comp-c-man .man +./usr/share/man/man3/prop_dictionary_recv_syscall.3 comp-c-man .man ./usr/share/man/man3/prop_dictionary_remove.3 comp-c-man .man ./usr/share/man/man3/prop_dictionary_remove_keysym.3 comp-c-man .man ./usr/share/man/man3/prop_dictionary_send_ioctl.3 comp-c-man .man +./usr/share/man/man3/prop_dictionary_send_syscall.3 comp-c-man .man ./usr/share/man/man3/prop_dictionary_sendrecv_ioctl.3 comp-c-man .man ./usr/share/man/man3/prop_dictionary_set.3 comp-c-man .man ./usr/share/man/man3/prop_dictionary_set_bool.3 comp-c-man .man @@ -19738,6 +19752,7 @@ ./usr/share/man/man3/prop_object_retain.3 comp-c-man .man ./usr/share/man/man3/prop_object_type.3 comp-c-man .man ./usr/share/man/man3/prop_send_ioctl.3 comp-c-man .man +./usr/share/man/man3/prop_send_syscall.3 comp-c-man .man ./usr/share/man/man3/prop_string.3 comp-c-man .man ./usr/share/man/man3/prop_string_append.3 comp-c-man .man ./usr/share/man/man3/prop_string_append_cstring.3 comp-c-man .man