- 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@
This commit is contained in:
bouyer 2011-01-19 20:34:23 +00:00
parent 9b0c6e6540
commit 07247bb748
8 changed files with 221 additions and 17 deletions

View File

@ -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 @@ struct plistref;
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,

View File

@ -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_recv_ioctl(int, unsigned long,
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 *);

View File

@ -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 @@ functions implement the kernel side of a protocol for copying property lists
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 @@ Not supported
.Xr prop_array 3 ,
.Xr prop_dictionary 3 ,
.Xr prop_send_ioctl 3 ,
.Xr prop_send_syscall 3 ,
.Xr proplib 3
.Sh HISTORY
The

View File

@ -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 @@ prop_array_externalize_to_pref(prop_array_t array, struct plistref *prefp)
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 @@ prop_dictionary_externalize_to_pref(prop_dictionary_t dict, struct plistref *pre
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)
@ -221,6 +224,31 @@ prop_dictionary_recv_ioctl(int fd, unsigned long cmd, prop_dictionary_t *dictp)
(prop_object_t *)dictp));
}
/*
* 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
@ -385,8 +413,7 @@ prop_dictionary_copyin_ioctl(const struct plistref *pref, const u_long cmd,
}
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 @@ _prop_object_copyout_ioctl(struct plistref *pref, const u_long cmd,
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);
@ -442,6 +466,36 @@ _prop_object_copyout_ioctl(struct plistref *pref, const u_long cmd,
return (error);
}
/*
* 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 @@ int
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 */

View File

@ -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
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 .

View File

@ -1,4 +1,4 @@
.\" $NetBSD: proplib.3,v 1.6 2009/05/13 22:31:59 wiz Exp $
.\" $NetBSD: proplib.3,v 1.7 2011/01/19 20:34:23 bouyer Exp $
.\"
.\" Copyright (c) 2006 The NetBSD Foundation, Inc.
.\" All rights reserved.
@ -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 @@ released using an iterator-specific release function.
.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

View File

@ -1,4 +1,4 @@
# $NetBSD: mi,v 1.1572 2011/01/18 23:12:37 jruoho Exp $
# $NetBSD: mi,v 1.1573 2011/01/19 20:34:23 bouyer Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@ -7655,8 +7655,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
@ -7718,9 +7720,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
@ -7763,6 +7767,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
@ -13658,8 +13663,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
@ -13721,9 +13728,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
@ -13766,6 +13775,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
@ -19653,8 +19663,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
@ -19716,9 +19728,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
@ -19761,6 +19775,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

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.17 2009/10/10 18:06:54 bad Exp $
# $NetBSD: Makefile,v 1.18 2011/01/19 20:34:24 bouyer Exp $
.include <bsd.own.mk>
@ -31,6 +31,12 @@ MLINKS+= prop_send_ioctl.3 prop_dictionary_send_ioctl.3
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