xref: /netbsd-src/common/lib/libprop/prop_copyin_ioctl.9 (revision 656b88f2b5e4877c738a92c7d949d612b2739a06)
1.\"	$NetBSD: prop_copyin_ioctl.9,v 1.15 2017/03/07 19:10:07 njoly Exp $
2.\"
3.\" Copyright (c) 2006, 2009 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Jason R. Thorpe.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in the
16.\" documentation and/or other materials provided with the distribution.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28.\" POSSIBILITY OF SUCH DAMAGE.
29.\"
30.Dd January 29, 2017
31.Dt PROP_COPYIN_IOCTL 9
32.Os
33.Sh NAME
34.Nm prop_array_copyin ,
35.Nm prop_array_copyin_size ,
36.Nm prop_array_copyin_ioctl ,
37.Nm prop_array_copyin_ioctl_size ,
38.Nm prop_array_copyout ,
39.Nm prop_array_copyout_ioctl ,
40.Nm prop_dictionary_copyin ,
41.Nm prop_dictionary_copyin_size ,
42.Nm prop_dictionary_copyin_ioctl ,
43.Nm prop_dictionary_copyin_ioctl_size ,
44.Nm prop_dictionary_copyout ,
45.Nm prop_dictionary_copyout_ioctl
46.Nd Copy property lists to and from kernel space
47.Sh SYNOPSIS
48.In prop/proplib.h
49.Ft int
50.Fn prop_array_copyin "const struct plistref *pref" \
51    "prop_array_t *arrayp"
52.Ft int
53.Fn prop_array_copyin_size "const struct plistref *pref" \
54    "prop_array_t *arrayp" "size_t lim"
55.Ft int
56.Fn prop_array_copyin_ioctl "const struct plistref *pref" \
57    "const u_long cmd" "prop_array_t *arrayp"
58.Ft int
59.Fn prop_array_copyin_ioctl_size "const struct plistref *pref" \
60    "const u_long cmd" "prop_array_t *arrayp" "size_t lim"
61.Ft int
62.Fn prop_array_copyout "struct plistref *pref" \
63    "prop_array_t array"
64.Ft int
65.Fn prop_array_copyout_ioctl "struct plistref *pref" \
66    "const u_long cmd" "prop_array_t array"
67.Ft int
68.Fn prop_dictionary_copyin "const struct plistref *pref" \
69    "prop_dictionary_t *dictp"
70.Ft int
71.Fn prop_dictionary_copyin_size "const struct plistref *pref" \
72    "prop_dictionary_t *dictp" "size_t lim"
73.Ft int
74.Fn prop_dictionary_copyin_ioctl "const struct plistref *pref" \
75    "const u_long cmd" "prop_dictionary_t *dictp"
76.Ft int
77.Fn prop_dictionary_copyin_ioctl_size "const struct plistref *pref" \
78    "const u_long cmd" "prop_dictionary_t *dictp" "size_t lim"
79.Ft int
80.Fn prop_dictionary_copyout "struct plistref *pref" \
81    "prop_dictionary_t dict"
82.Ft int
83.Fn prop_dictionary_copyout_ioctl "struct plistref *pref" \
84    "const u_long cmd" "prop_dictionary_t dict"
85.Sh DESCRIPTION
86The
87.Nm prop_array_copyin_ioctl ,
88.Nm prop_array_copyin_ioctl_size ,
89.Nm prop_array_copyout_ioctl ,
90.Nm prop_dictionary_copyin_ioctl ,
91.Nm prop_dictionary_copyin_ioctl_size ,
92and
93.Nm prop_dictionary_copyout_ioctl
94functions implement the kernel side of a protocol for copying property lists
95to and from the kernel using
96.Xr ioctl 2 .
97The functions
98.Nm prop_array_copyin ,
99.Nm prop_array_copyin_size ,
100.Nm prop_array_copyout ,
101.Nm prop_dictionary_copyin ,
102.Nm prop_dictionary_copyin_size ,
103and
104.Nm prop_dictionary_copyout
105implement the kernel side of a protocol for copying property lists to the
106kernel as arguments of normal system calls.
107.Pp
108A kernel routine receiving or returning a property list will be passed a
109pointer to a
110.Vt struct plistref .
111This structure encapsulates the reference to the property list in externalized
112form.
113.Pp
114The functions
115.Nm prop_array_copyin_size ,
116.Nm prop_array_copyin_ioctl_size ,
117.Nm prop_dictionary_copyin_size ,
118and
119.Nm prop_dictionary_copyin_ioctl_size
120take an explicit limit argument
121.Ar lim
122while
123.Nm prop_array_copyin ,
124.Nm prop_array_copyin_ioctl ,
125.Nm prop_dictionary_copyin ,
126and
127.Nm prop_dictionary_copyin_ioctl
128have an implicit size limit of 128KB.
129Attempts to transfer objects larger than the limit result in an
130.Er E2BIG
131return value.
132.Sh RETURN VALUES
133If successful, functions return zero.
134Otherwise, an error number will be returned to indicate the error.
135.Sh EXAMPLES
136The following
137.Pq simplified
138example demonstrates using
139.Fn prop_dictionary_copyin_ioctl
140and
141.Fn prop_dictionary_copyout_ioctl
142in an ioctl routine:
143.Bd -literal
144extern prop_dictionary_t fooprops;
145
146int
147fooioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct lwp *l)
148{
149    prop_dictionary_t dict, odict;
150    int error;
151
152    switch (cmd) {
153    case FOOSETPROPS: {
154	const struct plistref *pref = (const struct plistref *) data;
155	error = prop_dictionary_copyin_ioctl(pref, cmd, \*[Am]dict);
156	if (error)
157		return (error);
158	odict = fooprops;
159	fooprops = dict;
160	prop_object_release(odict);
161	break;
162      }
163
164    case FOOGETPROPS: {
165	struct plistref *pref = (struct plistref *) data;
166	error = prop_dictionary_copyout_ioctl(pref, cmd, fooprops);
167	break;
168      }
169
170    default:
171	return (EPASSTHROUGH);
172    }
173    return (error);
174}
175.Ed
176.Pp
177The following
178.Pq simplified
179example demonstrates using
180.Fn prop_array_copyin
181in a routine:
182.Bd -literal
183int
184foocopyin(const struct plistref *pref))
185{
186    prop_array_t array;
187    int error;
188
189    error = prop_array_copyin(pref, \*[Am]array);
190    if (error)
191	    return (error);
192    ...
193}
194.Ed
195.Sh ERRORS
196.Fn prop_array_copyin_ioctl
197and
198.Fn prop_dictionary_copyin_ioctl
199will fail if:
200.Bl -tag -width Er
201.It Bq Er E2BIG
202The object being copied is larger than an arbitrarily established limit
203(currently set to 128Kbytes).
204.It Bq Er EFAULT
205Bad address
206.It Bq Er EIO
207Input/output error
208.It Bq Er ENOMEM
209Cannot allocate memory
210.It Bq Er ENOTSUP
211Not supported
212.El
213.Pp
214.Fn prop_array_copyout_ioctl
215and
216.Fn prop_dictionary_copyout_ioctl
217will fail if:
218.Bl -tag -width Er
219.It Bq Er EFAULT
220Bad address
221.It Bq Er ENOMEM
222Cannot allocate memory
223.It Bq Er ENOTSUP
224Not supported
225.El
226.Sh SEE ALSO
227.Xr prop_array 3 ,
228.Xr prop_dictionary 3 ,
229.Xr prop_send_ioctl 3 ,
230.Xr prop_send_syscall 3 ,
231.Xr proplib 3
232.Sh HISTORY
233The
234.Nm proplib
235property container object library first appeared in
236.Nx 4.0 .
237