Thu Jan 20 11:17:59 2011 UTC ()
prop_*_copyout takes an object as second parameter, not a pointer to object.


(bouyer)
diff -r1.10 -r1.11 src/common/include/prop/prop_array.h
diff -r1.11 -r1.12 src/common/include/prop/prop_dictionary.h
diff -r1.15 -r1.16 src/common/lib/libprop/prop_kern.c

cvs diff -r1.10 -r1.11 src/common/include/prop/prop_array.h (switch to unified diff)

--- src/common/include/prop/prop_array.h 2011/01/19 20:34:23 1.10
+++ src/common/include/prop/prop_array.h 2011/01/20 11:17:58 1.11
@@ -1,159 +1,159 @@ @@ -1,159 +1,159 @@
1/* $NetBSD: prop_array.h,v 1.10 2011/01/19 20:34:23 bouyer Exp $ */ 1/* $NetBSD: prop_array.h,v 1.11 2011/01/20 11:17:58 bouyer Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2006, 2009 The NetBSD Foundation, Inc. 4 * Copyright (c) 2006, 2009 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe. 8 * by Jason R. Thorpe.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the 16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution. 17 * documentation and/or other materials provided with the distribution.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#ifndef _PROPLIB_PROP_ARRAY_H_ 32#ifndef _PROPLIB_PROP_ARRAY_H_
33#define _PROPLIB_PROP_ARRAY_H_ 33#define _PROPLIB_PROP_ARRAY_H_
34 34
35#include <prop/prop_object.h> 35#include <prop/prop_object.h>
36 36
37typedef struct _prop_array *prop_array_t; 37typedef struct _prop_array *prop_array_t;
38 38
39__BEGIN_DECLS 39__BEGIN_DECLS
40prop_array_t prop_array_create(void); 40prop_array_t prop_array_create(void);
41prop_array_t prop_array_create_with_capacity(unsigned int); 41prop_array_t prop_array_create_with_capacity(unsigned int);
42 42
43prop_array_t prop_array_copy(prop_array_t); 43prop_array_t prop_array_copy(prop_array_t);
44prop_array_t prop_array_copy_mutable(prop_array_t); 44prop_array_t prop_array_copy_mutable(prop_array_t);
45 45
46unsigned int prop_array_capacity(prop_array_t); 46unsigned int prop_array_capacity(prop_array_t);
47unsigned int prop_array_count(prop_array_t); 47unsigned int prop_array_count(prop_array_t);
48bool prop_array_ensure_capacity(prop_array_t, unsigned int); 48bool prop_array_ensure_capacity(prop_array_t, unsigned int);
49 49
50void prop_array_make_immutable(prop_array_t); 50void prop_array_make_immutable(prop_array_t);
51bool prop_array_mutable(prop_array_t); 51bool prop_array_mutable(prop_array_t);
52 52
53prop_object_iterator_t prop_array_iterator(prop_array_t); 53prop_object_iterator_t prop_array_iterator(prop_array_t);
54 54
55prop_object_t prop_array_get(prop_array_t, unsigned int); 55prop_object_t prop_array_get(prop_array_t, unsigned int);
56bool prop_array_set(prop_array_t, unsigned int, prop_object_t); 56bool prop_array_set(prop_array_t, unsigned int, prop_object_t);
57bool prop_array_add(prop_array_t, prop_object_t); 57bool prop_array_add(prop_array_t, prop_object_t);
58void prop_array_remove(prop_array_t, unsigned int); 58void prop_array_remove(prop_array_t, unsigned int);
59 59
60bool prop_array_equals(prop_array_t, prop_array_t); 60bool prop_array_equals(prop_array_t, prop_array_t);
61 61
62char * prop_array_externalize(prop_array_t); 62char * prop_array_externalize(prop_array_t);
63prop_array_t prop_array_internalize(const char *); 63prop_array_t prop_array_internalize(const char *);
64 64
65bool prop_array_externalize_to_file(prop_array_t, const char *); 65bool prop_array_externalize_to_file(prop_array_t, const char *);
66prop_array_t prop_array_internalize_from_file(const char *); 66prop_array_t prop_array_internalize_from_file(const char *);
67 67
68#if defined(__NetBSD__) 68#if defined(__NetBSD__)
69struct plistref; 69struct plistref;
70 70
71#if !defined(_KERNEL) && !defined(_STANDALONE) 71#if !defined(_KERNEL) && !defined(_STANDALONE)
72bool prop_array_externalize_to_pref(prop_array_t, struct plistref *); 72bool prop_array_externalize_to_pref(prop_array_t, struct plistref *);
73int prop_array_send_ioctl(prop_array_t, int, unsigned long); 73int prop_array_send_ioctl(prop_array_t, int, unsigned long);
74int prop_array_recv_ioctl(int, unsigned long, prop_array_t *); 74int prop_array_recv_ioctl(int, unsigned long, prop_array_t *);
75bool prop_array_send_syscall(prop_array_t, struct plistref *); 75bool prop_array_send_syscall(prop_array_t, struct plistref *);
76bool prop_array_recv_syscall(const struct plistref *, 76bool prop_array_recv_syscall(const struct plistref *,
77 prop_array_t *); 77 prop_array_t *);
78#elif defined(_KERNEL) 78#elif defined(_KERNEL)
79int prop_array_copyin(const struct plistref *, prop_array_t *); 79int prop_array_copyin(const struct plistref *, prop_array_t *);
80int prop_array_copyout(struct plistref *, prop_array_t *); 80int prop_array_copyout(struct plistref *, prop_array_t);
81int prop_array_copyin_ioctl(const struct plistref *, const u_long, 81int prop_array_copyin_ioctl(const struct plistref *, const u_long,
82 prop_array_t *); 82 prop_array_t *);
83int prop_array_copyout_ioctl(struct plistref *, const u_long, 83int prop_array_copyout_ioctl(struct plistref *, const u_long,
84 prop_array_t); 84 prop_array_t);
85#endif 85#endif
86#endif /* __NetBSD__ */ 86#endif /* __NetBSD__ */
87 87
88/* 88/*
89 * Utility routines to make it more convenient to work with values 89 * Utility routines to make it more convenient to work with values
90 * stored in dictionaries. 90 * stored in dictionaries.
91 */ 91 */
92bool prop_array_get_bool(prop_array_t, unsigned int, 92bool prop_array_get_bool(prop_array_t, unsigned int,
93 bool *); 93 bool *);
94bool prop_array_set_bool(prop_array_t, unsigned int, 94bool prop_array_set_bool(prop_array_t, unsigned int,
95 bool); 95 bool);
96 96
97bool prop_array_get_int8(prop_array_t, unsigned int, 97bool prop_array_get_int8(prop_array_t, unsigned int,
98 int8_t *); 98 int8_t *);
99bool prop_array_get_uint8(prop_array_t, unsigned int, 99bool prop_array_get_uint8(prop_array_t, unsigned int,
100 uint8_t *); 100 uint8_t *);
101bool prop_array_set_int8(prop_array_t, unsigned int, 101bool prop_array_set_int8(prop_array_t, unsigned int,
102 int8_t); 102 int8_t);
103bool prop_array_set_uint8(prop_array_t, unsigned int, 103bool prop_array_set_uint8(prop_array_t, unsigned int,
104 uint8_t); 104 uint8_t);
105 105
106bool prop_array_get_int16(prop_array_t, unsigned int, 106bool prop_array_get_int16(prop_array_t, unsigned int,
107 int16_t *); 107 int16_t *);
108bool prop_array_get_uint16(prop_array_t, unsigned int, 108bool prop_array_get_uint16(prop_array_t, unsigned int,
109 uint16_t *); 109 uint16_t *);
110bool prop_array_set_int16(prop_array_t, unsigned int, 110bool prop_array_set_int16(prop_array_t, unsigned int,
111 int16_t); 111 int16_t);
112bool prop_array_set_uint16(prop_array_t, unsigned int, 112bool prop_array_set_uint16(prop_array_t, unsigned int,
113 uint16_t); 113 uint16_t);
114 114
115bool prop_array_get_int32(prop_array_t, unsigned int, 115bool prop_array_get_int32(prop_array_t, unsigned int,
116 int32_t *); 116 int32_t *);
117bool prop_array_get_uint32(prop_array_t, unsigned int, 117bool prop_array_get_uint32(prop_array_t, unsigned int,
118 uint32_t *); 118 uint32_t *);
119bool prop_array_set_int32(prop_array_t, unsigned int, 119bool prop_array_set_int32(prop_array_t, unsigned int,
120 int32_t); 120 int32_t);
121bool prop_array_set_uint32(prop_array_t, unsigned int, 121bool prop_array_set_uint32(prop_array_t, unsigned int,
122 uint32_t); 122 uint32_t);
123 123
124bool prop_array_get_int64(prop_array_t, unsigned int, 124bool prop_array_get_int64(prop_array_t, unsigned int,
125 int64_t *); 125 int64_t *);
126bool prop_array_get_uint64(prop_array_t, unsigned int, 126bool prop_array_get_uint64(prop_array_t, unsigned int,
127 uint64_t *); 127 uint64_t *);
128bool prop_array_set_int64(prop_array_t, unsigned int, 128bool prop_array_set_int64(prop_array_t, unsigned int,
129 int64_t); 129 int64_t);
130bool prop_array_set_uint64(prop_array_t, unsigned int, 130bool prop_array_set_uint64(prop_array_t, unsigned int,
131 uint64_t); 131 uint64_t);
132 132
133bool prop_array_add_int8(prop_array_t, int8_t); 133bool prop_array_add_int8(prop_array_t, int8_t);
134bool prop_array_add_uint8(prop_array_t, uint8_t); 134bool prop_array_add_uint8(prop_array_t, uint8_t);
135 135
136bool prop_array_add_int16(prop_array_t, int16_t); 136bool prop_array_add_int16(prop_array_t, int16_t);
137bool prop_array_add_uint16(prop_array_t, uint16_t); 137bool prop_array_add_uint16(prop_array_t, uint16_t);
138 138
139bool prop_array_add_int32(prop_array_t, int32_t); 139bool prop_array_add_int32(prop_array_t, int32_t);
140bool prop_array_add_uint32(prop_array_t, uint32_t); 140bool prop_array_add_uint32(prop_array_t, uint32_t);
141 141
142bool prop_array_add_int64(prop_array_t, int64_t); 142bool prop_array_add_int64(prop_array_t, int64_t);
143bool prop_array_add_uint64(prop_array_t, uint64_t); 143bool prop_array_add_uint64(prop_array_t, uint64_t);
144 144
145bool prop_array_get_cstring(prop_array_t, unsigned int, 145bool prop_array_get_cstring(prop_array_t, unsigned int,
146 char **); 146 char **);
147bool prop_array_set_cstring(prop_array_t, unsigned int, 147bool prop_array_set_cstring(prop_array_t, unsigned int,
148 const char *); 148 const char *);
149 149
150bool prop_array_get_cstring_nocopy(prop_array_t, 150bool prop_array_get_cstring_nocopy(prop_array_t,
151 unsigned int, 151 unsigned int,
152 const char **); 152 const char **);
153bool prop_array_set_cstring_nocopy(prop_array_t, 153bool prop_array_set_cstring_nocopy(prop_array_t,
154 unsigned int, 154 unsigned int,
155 const char *); 155 const char *);
156 156
157__END_DECLS 157__END_DECLS
158 158
159#endif /* _PROPLIB_PROP_ARRAY_H_ */ 159#endif /* _PROPLIB_PROP_ARRAY_H_ */

cvs diff -r1.11 -r1.12 src/common/include/prop/prop_dictionary.h (switch to unified diff)

--- src/common/include/prop/prop_dictionary.h 2011/01/19 20:34:23 1.11
+++ src/common/include/prop/prop_dictionary.h 2011/01/20 11:17:58 1.12
@@ -1,173 +1,173 @@ @@ -1,173 +1,173 @@
1/* $NetBSD: prop_dictionary.h,v 1.11 2011/01/19 20:34:23 bouyer Exp $ */ 1/* $NetBSD: prop_dictionary.h,v 1.12 2011/01/20 11:17:58 bouyer Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2006, 2009 The NetBSD Foundation, Inc. 4 * Copyright (c) 2006, 2009 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe. 8 * by Jason R. Thorpe.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the 16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution. 17 * documentation and/or other materials provided with the distribution.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#ifndef _PROPLIB_PROP_DICTIONARY_H_ 32#ifndef _PROPLIB_PROP_DICTIONARY_H_
33#define _PROPLIB_PROP_DICTIONARY_H_ 33#define _PROPLIB_PROP_DICTIONARY_H_
34 34
35#include <prop/prop_object.h> 35#include <prop/prop_object.h>
36 36
37typedef struct _prop_dictionary *prop_dictionary_t; 37typedef struct _prop_dictionary *prop_dictionary_t;
38typedef struct _prop_dictionary_keysym *prop_dictionary_keysym_t; 38typedef struct _prop_dictionary_keysym *prop_dictionary_keysym_t;
39 39
40__BEGIN_DECLS 40__BEGIN_DECLS
41prop_dictionary_t prop_dictionary_create(void); 41prop_dictionary_t prop_dictionary_create(void);
42prop_dictionary_t prop_dictionary_create_with_capacity(unsigned int); 42prop_dictionary_t prop_dictionary_create_with_capacity(unsigned int);
43 43
44prop_dictionary_t prop_dictionary_copy(prop_dictionary_t); 44prop_dictionary_t prop_dictionary_copy(prop_dictionary_t);
45prop_dictionary_t prop_dictionary_copy_mutable(prop_dictionary_t); 45prop_dictionary_t prop_dictionary_copy_mutable(prop_dictionary_t);
46 46
47unsigned int prop_dictionary_count(prop_dictionary_t); 47unsigned int prop_dictionary_count(prop_dictionary_t);
48bool prop_dictionary_ensure_capacity(prop_dictionary_t, 48bool prop_dictionary_ensure_capacity(prop_dictionary_t,
49 unsigned int); 49 unsigned int);
50 50
51void prop_dictionary_make_immutable(prop_dictionary_t); 51void prop_dictionary_make_immutable(prop_dictionary_t);
52bool prop_dictionary_mutable(prop_dictionary_t); 52bool prop_dictionary_mutable(prop_dictionary_t);
53 53
54prop_object_iterator_t prop_dictionary_iterator(prop_dictionary_t); 54prop_object_iterator_t prop_dictionary_iterator(prop_dictionary_t);
55prop_array_t prop_dictionary_all_keys(prop_dictionary_t); 55prop_array_t prop_dictionary_all_keys(prop_dictionary_t);
56 56
57prop_object_t prop_dictionary_get(prop_dictionary_t, const char *); 57prop_object_t prop_dictionary_get(prop_dictionary_t, const char *);
58bool prop_dictionary_set(prop_dictionary_t, const char *, 58bool prop_dictionary_set(prop_dictionary_t, const char *,
59 prop_object_t); 59 prop_object_t);
60void prop_dictionary_remove(prop_dictionary_t, const char *); 60void prop_dictionary_remove(prop_dictionary_t, const char *);
61 61
62prop_object_t prop_dictionary_get_keysym(prop_dictionary_t, 62prop_object_t prop_dictionary_get_keysym(prop_dictionary_t,
63 prop_dictionary_keysym_t); 63 prop_dictionary_keysym_t);
64bool prop_dictionary_set_keysym(prop_dictionary_t, 64bool prop_dictionary_set_keysym(prop_dictionary_t,
65 prop_dictionary_keysym_t, 65 prop_dictionary_keysym_t,
66 prop_object_t); 66 prop_object_t);
67void prop_dictionary_remove_keysym(prop_dictionary_t, 67void prop_dictionary_remove_keysym(prop_dictionary_t,
68 prop_dictionary_keysym_t); 68 prop_dictionary_keysym_t);
69 69
70bool prop_dictionary_equals(prop_dictionary_t, prop_dictionary_t); 70bool prop_dictionary_equals(prop_dictionary_t, prop_dictionary_t);
71 71
72char * prop_dictionary_externalize(prop_dictionary_t); 72char * prop_dictionary_externalize(prop_dictionary_t);
73prop_dictionary_t prop_dictionary_internalize(const char *); 73prop_dictionary_t prop_dictionary_internalize(const char *);
74 74
75bool prop_dictionary_externalize_to_file(prop_dictionary_t, 75bool prop_dictionary_externalize_to_file(prop_dictionary_t,
76 const char *); 76 const char *);
77prop_dictionary_t prop_dictionary_internalize_from_file(const char *); 77prop_dictionary_t prop_dictionary_internalize_from_file(const char *);
78 78
79const char * prop_dictionary_keysym_cstring_nocopy(prop_dictionary_keysym_t); 79const char * prop_dictionary_keysym_cstring_nocopy(prop_dictionary_keysym_t);
80 80
81bool prop_dictionary_keysym_equals(prop_dictionary_keysym_t, 81bool prop_dictionary_keysym_equals(prop_dictionary_keysym_t,
82 prop_dictionary_keysym_t); 82 prop_dictionary_keysym_t);
83 83
84#if defined(__NetBSD__) 84#if defined(__NetBSD__)
85struct plistref; 85struct plistref;
86 86
87#if !defined(_KERNEL) && !defined(_STANDALONE) 87#if !defined(_KERNEL) && !defined(_STANDALONE)
88bool prop_dictionary_externalize_to_pref(prop_dictionary_t, struct plistref *); 88bool prop_dictionary_externalize_to_pref(prop_dictionary_t, struct plistref *);
89int prop_dictionary_send_ioctl(prop_dictionary_t, int, 89int prop_dictionary_send_ioctl(prop_dictionary_t, int,
90 unsigned long); 90 unsigned long);
91int prop_dictionary_recv_ioctl(int, unsigned long, 91int prop_dictionary_recv_ioctl(int, unsigned long,
92 prop_dictionary_t *); 92 prop_dictionary_t *);
93int prop_dictionary_sendrecv_ioctl(prop_dictionary_t, 93int prop_dictionary_sendrecv_ioctl(prop_dictionary_t,
94 int, unsigned long, 94 int, unsigned long,
95 prop_dictionary_t *); 95 prop_dictionary_t *);
96bool prop_dictionary_send_syscall(prop_dictionary_t, 96bool prop_dictionary_send_syscall(prop_dictionary_t,
97 struct plistref *); 97 struct plistref *);
98bool prop_dictionary_recv_syscall(const struct plistref *, 98bool prop_dictionary_recv_syscall(const struct plistref *,
99 prop_dictionary_t *); 99 prop_dictionary_t *);
100#elif defined(_KERNEL) 100#elif defined(_KERNEL)
101int prop_dictionary_copyin(const struct plistref *, 101int prop_dictionary_copyin(const struct plistref *,
102 prop_dictionary_t *); 102 prop_dictionary_t *);
103int prop_dictionary_copyout(struct plistref *, 103int prop_dictionary_copyout(struct plistref *,
104 prop_dictionary_t *); 104 prop_dictionary_t);
105int prop_dictionary_copyin_ioctl(const struct plistref *, 105int prop_dictionary_copyin_ioctl(const struct plistref *,
106 const u_long, 106 const u_long,
107 prop_dictionary_t *); 107 prop_dictionary_t *);
108int prop_dictionary_copyout_ioctl(struct plistref *, 108int prop_dictionary_copyout_ioctl(struct plistref *,
109 const u_long, 109 const u_long,
110 prop_dictionary_t); 110 prop_dictionary_t);
111#endif 111#endif
112#endif /* __NetBSD__ */ 112#endif /* __NetBSD__ */
113 113
114/* 114/*
115 * Utility routines to make it more convenient to work with values 115 * Utility routines to make it more convenient to work with values
116 * stored in dictionaries. 116 * stored in dictionaries.
117 */ 117 */
118bool prop_dictionary_get_bool(prop_dictionary_t, const char *, 118bool prop_dictionary_get_bool(prop_dictionary_t, const char *,
119 bool *); 119 bool *);
120bool prop_dictionary_set_bool(prop_dictionary_t, const char *, 120bool prop_dictionary_set_bool(prop_dictionary_t, const char *,
121 bool); 121 bool);
122 122
123bool prop_dictionary_get_int8(prop_dictionary_t, const char *, 123bool prop_dictionary_get_int8(prop_dictionary_t, const char *,
124 int8_t *); 124 int8_t *);
125bool prop_dictionary_get_uint8(prop_dictionary_t, const char *, 125bool prop_dictionary_get_uint8(prop_dictionary_t, const char *,
126 uint8_t *); 126 uint8_t *);
127bool prop_dictionary_set_int8(prop_dictionary_t, const char *, 127bool prop_dictionary_set_int8(prop_dictionary_t, const char *,
128 int8_t); 128 int8_t);
129bool prop_dictionary_set_uint8(prop_dictionary_t, const char *, 129bool prop_dictionary_set_uint8(prop_dictionary_t, const char *,
130 uint8_t); 130 uint8_t);
131 131
132bool prop_dictionary_get_int16(prop_dictionary_t, const char *, 132bool prop_dictionary_get_int16(prop_dictionary_t, const char *,
133 int16_t *); 133 int16_t *);
134bool prop_dictionary_get_uint16(prop_dictionary_t, const char *, 134bool prop_dictionary_get_uint16(prop_dictionary_t, const char *,
135 uint16_t *); 135 uint16_t *);
136bool prop_dictionary_set_int16(prop_dictionary_t, const char *, 136bool prop_dictionary_set_int16(prop_dictionary_t, const char *,
137 int16_t); 137 int16_t);
138bool prop_dictionary_set_uint16(prop_dictionary_t, const char *, 138bool prop_dictionary_set_uint16(prop_dictionary_t, const char *,
139 uint16_t); 139 uint16_t);
140 140
141bool prop_dictionary_get_int32(prop_dictionary_t, const char *, 141bool prop_dictionary_get_int32(prop_dictionary_t, const char *,
142 int32_t *); 142 int32_t *);
143bool prop_dictionary_get_uint32(prop_dictionary_t, const char *, 143bool prop_dictionary_get_uint32(prop_dictionary_t, const char *,
144 uint32_t *); 144 uint32_t *);
145bool prop_dictionary_set_int32(prop_dictionary_t, const char *, 145bool prop_dictionary_set_int32(prop_dictionary_t, const char *,
146 int32_t); 146 int32_t);
147bool prop_dictionary_set_uint32(prop_dictionary_t, const char *, 147bool prop_dictionary_set_uint32(prop_dictionary_t, const char *,
148 uint32_t); 148 uint32_t);
149 149
150bool prop_dictionary_get_int64(prop_dictionary_t, const char *, 150bool prop_dictionary_get_int64(prop_dictionary_t, const char *,
151 int64_t *); 151 int64_t *);
152bool prop_dictionary_get_uint64(prop_dictionary_t, const char *, 152bool prop_dictionary_get_uint64(prop_dictionary_t, const char *,
153 uint64_t *); 153 uint64_t *);
154bool prop_dictionary_set_int64(prop_dictionary_t, const char *, 154bool prop_dictionary_set_int64(prop_dictionary_t, const char *,
155 int64_t); 155 int64_t);
156bool prop_dictionary_set_uint64(prop_dictionary_t, const char *, 156bool prop_dictionary_set_uint64(prop_dictionary_t, const char *,
157 uint64_t); 157 uint64_t);
158 158
159bool prop_dictionary_get_cstring(prop_dictionary_t, const char *, 159bool prop_dictionary_get_cstring(prop_dictionary_t, const char *,
160 char **); 160 char **);
161bool prop_dictionary_set_cstring(prop_dictionary_t, const char *, 161bool prop_dictionary_set_cstring(prop_dictionary_t, const char *,
162 const char *); 162 const char *);
163 163
164bool prop_dictionary_get_cstring_nocopy(prop_dictionary_t, 164bool prop_dictionary_get_cstring_nocopy(prop_dictionary_t,
165 const char *, 165 const char *,
166 const char **); 166 const char **);
167bool prop_dictionary_set_cstring_nocopy(prop_dictionary_t, 167bool prop_dictionary_set_cstring_nocopy(prop_dictionary_t,
168 const char *, 168 const char *,
169 const char *); 169 const char *);
170 170
171__END_DECLS 171__END_DECLS
172 172
173#endif /* _PROPLIB_PROP_DICTIONARY_H_ */ 173#endif /* _PROPLIB_PROP_DICTIONARY_H_ */

cvs diff -r1.15 -r1.16 src/common/lib/libprop/prop_kern.c (switch to unified diff)

--- src/common/lib/libprop/prop_kern.c 2011/01/19 20:34:23 1.15
+++ src/common/lib/libprop/prop_kern.c 2011/01/20 11:17:58 1.16
@@ -1,523 +1,523 @@ @@ -1,523 +1,523 @@
1/* $NetBSD: prop_kern.c,v 1.15 2011/01/19 20:34:23 bouyer Exp $ */ 1/* $NetBSD: prop_kern.c,v 1.16 2011/01/20 11:17:58 bouyer Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2006, 2009 The NetBSD Foundation, Inc. 4 * Copyright (c) 2006, 2009 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe. 8 * by Jason R. Thorpe.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the 16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution. 17 * documentation and/or other materials provided with the distribution.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#if defined(__NetBSD__) 32#if defined(__NetBSD__)
33 33
34#include <sys/types.h> 34#include <sys/types.h>
35#include <sys/ioctl.h> 35#include <sys/ioctl.h>
36 36
37#include <prop/proplib.h> 37#include <prop/proplib.h>
38 38
39#if !defined(_KERNEL) && !defined(_STANDALONE) 39#if !defined(_KERNEL) && !defined(_STANDALONE)
40#include <sys/mman.h> 40#include <sys/mman.h>
41#include <errno.h> 41#include <errno.h>
42#include <string.h> 42#include <string.h>
43#include <stdlib.h> 43#include <stdlib.h>
44#include <stdio.h> 44#include <stdio.h>
45 45
46#ifdef RUMP_ACTION 46#ifdef RUMP_ACTION
47#include <rump/rump_syscalls.h> 47#include <rump/rump_syscalls.h>
48#define ioctl(a,b,c) rump_sys_ioctl(a,b,c) 48#define ioctl(a,b,c) rump_sys_ioctl(a,b,c)
49#endif 49#endif
50 50
51static int 51static int
52_prop_object_externalize_to_pref(prop_object_t obj, struct plistref *pref, char **bufp) 52_prop_object_externalize_to_pref(prop_object_t obj, struct plistref *pref, char **bufp)
53{ 53{
54 char *buf; 54 char *buf;
55 55
56 switch (prop_object_type(obj)) { 56 switch (prop_object_type(obj)) {
57 case PROP_TYPE_DICTIONARY: 57 case PROP_TYPE_DICTIONARY:
58 buf = prop_dictionary_externalize(obj); 58 buf = prop_dictionary_externalize(obj);
59 break; 59 break;
60 case PROP_TYPE_ARRAY: 60 case PROP_TYPE_ARRAY:
61 buf = prop_array_externalize(obj); 61 buf = prop_array_externalize(obj);
62 break; 62 break;
63 default: 63 default:
64 return (ENOTSUP); 64 return (ENOTSUP);
65 } 65 }
66 if (buf == NULL) { 66 if (buf == NULL) {
67 /* Assume we ran out of memory. */ 67 /* Assume we ran out of memory. */
68 return (ENOMEM); 68 return (ENOMEM);
69 } 69 }
70 pref->pref_plist = buf; 70 pref->pref_plist = buf;
71 pref->pref_len = strlen(buf) + 1; 71 pref->pref_len = strlen(buf) + 1;
72 72
73 *bufp = buf; 73 *bufp = buf;
74 74
75 return (0); 75 return (0);
76} 76}
77 77
78/* 78/*
79 * prop_array_externalize_to_pref -- 79 * prop_array_externalize_to_pref --
80 * Externalize an array into a plistref for sending to the kernel. 80 * Externalize an array into a plistref for sending to the kernel.
81 */ 81 */
82bool 82bool
83prop_array_externalize_to_pref(prop_array_t array, struct plistref *prefp) 83prop_array_externalize_to_pref(prop_array_t array, struct plistref *prefp)
84{ 84{
85 char *buf; 85 char *buf;
86 int rv; 86 int rv;
87 87
88 rv = _prop_object_externalize_to_pref(array, prefp, &buf); 88 rv = _prop_object_externalize_to_pref(array, prefp, &buf);
89 if (rv != 0) 89 if (rv != 0)
90 errno = rv; /* pass up error value in errno */ 90 errno = rv; /* pass up error value in errno */
91 return (rv == 0); 91 return (rv == 0);
92} 92}
93__strong_alias(prop_array_send_syscall, prop_array_externalize_to_pref) 93__strong_alias(prop_array_send_syscall, prop_array_externalize_to_pref)
94 94
95/* 95/*
96 * prop_dictionary_externalize_to_pref -- 96 * prop_dictionary_externalize_to_pref --
97 * Externalize an dictionary into a plistref for sending to the kernel. 97 * Externalize an dictionary into a plistref for sending to the kernel.
98 */ 98 */
99bool 99bool
100prop_dictionary_externalize_to_pref(prop_dictionary_t dict, struct plistref *prefp) 100prop_dictionary_externalize_to_pref(prop_dictionary_t dict, struct plistref *prefp)
101{ 101{
102 char *buf; 102 char *buf;
103 int rv; 103 int rv;
104 104
105 rv = _prop_object_externalize_to_pref(dict, prefp, &buf); 105 rv = _prop_object_externalize_to_pref(dict, prefp, &buf);
106 if (rv != 0) 106 if (rv != 0)
107 errno = rv; /* pass up error value in errno */ 107 errno = rv; /* pass up error value in errno */
108 return (rv == 0); 108 return (rv == 0);
109} 109}
110__strong_alias(prop_dictionary_send_syscall, 110__strong_alias(prop_dictionary_send_syscall,
111 prop_dictionary_externalize_to_pref) 111 prop_dictionary_externalize_to_pref)
112 112
113static int 113static int
114_prop_object_send_ioctl(prop_object_t obj, int fd, unsigned long cmd) 114_prop_object_send_ioctl(prop_object_t obj, int fd, unsigned long cmd)
115{ 115{
116 struct plistref pref; 116 struct plistref pref;
117 char *buf; 117 char *buf;
118 int error; 118 int error;
119 119
120 error = _prop_object_externalize_to_pref(obj, &pref, &buf); 120 error = _prop_object_externalize_to_pref(obj, &pref, &buf);
121 if (error) 121 if (error)
122 return (error); 122 return (error);
123 123
124 if (ioctl(fd, cmd, &pref) == -1) 124 if (ioctl(fd, cmd, &pref) == -1)
125 error = errno; 125 error = errno;
126 else 126 else
127 error = 0; 127 error = 0;
128  128
129 free(buf); 129 free(buf);
130 130
131 return (error); 131 return (error);
132} 132}
133 133
134/* 134/*
135 * prop_array_send_ioctl -- 135 * prop_array_send_ioctl --
136 * Send an array to the kernel using the specified ioctl. 136 * Send an array to the kernel using the specified ioctl.
137 */ 137 */
138int 138int
139prop_array_send_ioctl(prop_array_t array, int fd, unsigned long cmd) 139prop_array_send_ioctl(prop_array_t array, int fd, unsigned long cmd)
140{ 140{
141 141
142 return (_prop_object_send_ioctl(array, fd, cmd)); 142 return (_prop_object_send_ioctl(array, fd, cmd));
143} 143}
144 144
145/* 145/*
146 * prop_dictionary_send_ioctl -- 146 * prop_dictionary_send_ioctl --
147 * Send a dictionary to the kernel using the specified ioctl. 147 * Send a dictionary to the kernel using the specified ioctl.
148 */ 148 */
149int 149int
150prop_dictionary_send_ioctl(prop_dictionary_t dict, int fd, unsigned long cmd) 150prop_dictionary_send_ioctl(prop_dictionary_t dict, int fd, unsigned long cmd)
151{ 151{
152 152
153 return (_prop_object_send_ioctl(dict, fd, cmd)); 153 return (_prop_object_send_ioctl(dict, fd, cmd));
154} 154}
155 155
156static int 156static int
157_prop_object_internalize_from_pref(const struct plistref *pref, prop_type_t type, 157_prop_object_internalize_from_pref(const struct plistref *pref, prop_type_t type,
158 prop_object_t *objp) 158 prop_object_t *objp)
159{ 159{
160 prop_object_t obj = NULL; 160 prop_object_t obj = NULL;
161 char *buf; 161 char *buf;
162 int error = 0; 162 int error = 0;
163 163
164 if (pref->pref_len == 0) { 164 if (pref->pref_len == 0) {
165 /* 165 /*
166 * This should never happen; we should always get the XML 166 * This should never happen; we should always get the XML
167 * for an empty dictionary if it's really empty. 167 * for an empty dictionary if it's really empty.
168 */ 168 */
169 error = EIO; 169 error = EIO;
170 goto out; 170 goto out;
171 } else { 171 } else {
172 buf = pref->pref_plist; 172 buf = pref->pref_plist;
173 buf[pref->pref_len - 1] = '\0'; /* extra insurance */ 173 buf[pref->pref_len - 1] = '\0'; /* extra insurance */
174 switch (type) { 174 switch (type) {
175 case PROP_TYPE_DICTIONARY: 175 case PROP_TYPE_DICTIONARY:
176 obj = prop_dictionary_internalize(buf); 176 obj = prop_dictionary_internalize(buf);
177 break; 177 break;
178 case PROP_TYPE_ARRAY: 178 case PROP_TYPE_ARRAY:
179 obj = prop_array_internalize(buf); 179 obj = prop_array_internalize(buf);
180 break; 180 break;
181 default: 181 default:
182 error = ENOTSUP; 182 error = ENOTSUP;
183 } 183 }
184 (void) munmap(buf, pref->pref_len); 184 (void) munmap(buf, pref->pref_len);
185 if (obj == NULL && error == 0) 185 if (obj == NULL && error == 0)
186 error = EIO; 186 error = EIO;
187 } 187 }
188 188
189 out: 189 out:
190 if (error == 0) 190 if (error == 0)
191 *objp = obj; 191 *objp = obj;
192 return (error); 192 return (error);
193} 193}
194 194
195/* 195/*
196 * prop_array_recv_ioctl -- 196 * prop_array_recv_ioctl --
197 * Receive an array from the kernel using the specified ioctl. 197 * Receive an array from the kernel using the specified ioctl.
198 */ 198 */
199int 199int
200prop_array_recv_ioctl(int fd, unsigned long cmd, prop_array_t *arrayp) 200prop_array_recv_ioctl(int fd, unsigned long cmd, prop_array_t *arrayp)
201{ 201{
202 struct plistref pref; 202 struct plistref pref;
203 203
204 if (ioctl(fd, cmd, &pref) == -1) 204 if (ioctl(fd, cmd, &pref) == -1)
205 return (errno); 205 return (errno);
206  206
207 return (_prop_object_internalize_from_pref(&pref, PROP_TYPE_ARRAY, 207 return (_prop_object_internalize_from_pref(&pref, PROP_TYPE_ARRAY,
208 (prop_object_t *)arrayp)); 208 (prop_object_t *)arrayp));
209} 209}
210 210
211/* 211/*
212 * prop_dictionary_recv_ioctl -- 212 * prop_dictionary_recv_ioctl --
213 * Receive a dictionary from the kernel using the specified ioctl. 213 * Receive a dictionary from the kernel using the specified ioctl.
214 */ 214 */
215int 215int
216prop_dictionary_recv_ioctl(int fd, unsigned long cmd, prop_dictionary_t *dictp) 216prop_dictionary_recv_ioctl(int fd, unsigned long cmd, prop_dictionary_t *dictp)
217{ 217{
218 struct plistref pref; 218 struct plistref pref;
219 219
220 if (ioctl(fd, cmd, &pref) == -1) 220 if (ioctl(fd, cmd, &pref) == -1)
221 return (errno); 221 return (errno);
222 222
223 return (_prop_object_internalize_from_pref(&pref, PROP_TYPE_DICTIONARY, 223 return (_prop_object_internalize_from_pref(&pref, PROP_TYPE_DICTIONARY,
224 (prop_object_t *)dictp)); 224 (prop_object_t *)dictp));
225} 225}
226 226
227/* 227/*
228 * prop_array_recv_syscall -- 228 * prop_array_recv_syscall --
229 * Receive an array from the kernel as pref. 229 * Receive an array from the kernel as pref.
230 * Pref's buf is freed on exit 230 * Pref's buf is freed on exit
231 */ 231 */
232bool 232bool
233prop_array_recv_syscall(const struct plistref *pref, prop_array_t *arrayp) 233prop_array_recv_syscall(const struct plistref *pref, prop_array_t *arrayp)
234{ 234{
235 return (_prop_object_internalize_from_pref(pref, PROP_TYPE_ARRAY, 235 return (_prop_object_internalize_from_pref(pref, PROP_TYPE_ARRAY,
236 (prop_object_t *)arrayp)); 236 (prop_object_t *)arrayp));
237} 237}
238 238
239/* 239/*
240 * prop_dictionary_recv_syscall -- 240 * prop_dictionary_recv_syscall --
241 * Receive a dictionary from the kernel as pref. 241 * Receive a dictionary from the kernel as pref.
242 * Pref's buf is freed on exit 242 * Pref's buf is freed on exit
243 */ 243 */
244bool 244bool
245prop_dictionary_recv_syscall(const struct plistref *pref, 245prop_dictionary_recv_syscall(const struct plistref *pref,
246 prop_dictionary_t *dictp) 246 prop_dictionary_t *dictp)
247{ 247{
248 return (_prop_object_internalize_from_pref(pref, PROP_TYPE_DICTIONARY, 248 return (_prop_object_internalize_from_pref(pref, PROP_TYPE_DICTIONARY,
249 (prop_object_t *)dictp)); 249 (prop_object_t *)dictp));
250} 250}
251 251
252/* 252/*
253 * prop_dictionary_sendrecv_ioctl -- 253 * prop_dictionary_sendrecv_ioctl --
254 * Combination send/receive a dictionary to/from the kernel using 254 * Combination send/receive a dictionary to/from the kernel using
255 * the specified ioctl. 255 * the specified ioctl.
256 */ 256 */
257int 257int
258prop_dictionary_sendrecv_ioctl(prop_dictionary_t dict, int fd, 258prop_dictionary_sendrecv_ioctl(prop_dictionary_t dict, int fd,
259 unsigned long cmd, prop_dictionary_t *dictp) 259 unsigned long cmd, prop_dictionary_t *dictp)
260{ 260{
261 struct plistref pref; 261 struct plistref pref;
262 char *buf; 262 char *buf;
263 int error; 263 int error;
264 264
265 error = _prop_object_externalize_to_pref(dict, &pref, &buf); 265 error = _prop_object_externalize_to_pref(dict, &pref, &buf);
266 if (error) 266 if (error)
267 return (error); 267 return (error);
268 268
269 if (ioctl(fd, cmd, &pref) == -1) 269 if (ioctl(fd, cmd, &pref) == -1)
270 error = errno; 270 error = errno;
271 else 271 else
272 error = 0; 272 error = 0;
273  273
274 free(buf); 274 free(buf);
275 275
276 if (error) 276 if (error)
277 return (error); 277 return (error);
278 278
279 return (_prop_object_internalize_from_pref(&pref, PROP_TYPE_DICTIONARY, 279 return (_prop_object_internalize_from_pref(&pref, PROP_TYPE_DICTIONARY,
280 (prop_object_t *)dictp)); 280 (prop_object_t *)dictp));
281} 281}
282#endif /* !_KERNEL && !_STANDALONE */ 282#endif /* !_KERNEL && !_STANDALONE */
283 283
284#if defined(_KERNEL) 284#if defined(_KERNEL)
285#include <sys/param.h> 285#include <sys/param.h>
286#include <sys/mman.h> 286#include <sys/mman.h>
287#include <sys/errno.h> 287#include <sys/errno.h>
288#include <sys/malloc.h> 288#include <sys/malloc.h>
289#include <sys/systm.h> 289#include <sys/systm.h>
290#include <sys/proc.h> 290#include <sys/proc.h>
291#include <sys/resource.h> 291#include <sys/resource.h>
292#include <sys/pool.h> 292#include <sys/pool.h>
293 293
294#include <uvm/uvm.h> 294#include <uvm/uvm.h>
295 295
296#include "prop_object_impl.h" 296#include "prop_object_impl.h"
297 297
298/* Arbitrary limit ioctl input to 64KB */ 298/* Arbitrary limit ioctl input to 64KB */
299unsigned int prop_object_copyin_limit = 65536; 299unsigned int prop_object_copyin_limit = 65536;
300 300
301/* initialize proplib for use in the kernel */ 301/* initialize proplib for use in the kernel */
302void 302void
303prop_kern_init(void) 303prop_kern_init(void)
304{ 304{
305 __link_set_decl(prop_linkpools, struct prop_pool_init); 305 __link_set_decl(prop_linkpools, struct prop_pool_init);
306 struct prop_pool_init * const *pi; 306 struct prop_pool_init * const *pi;
307 307
308 __link_set_foreach(pi, prop_linkpools) 308 __link_set_foreach(pi, prop_linkpools)
309 pool_init((*pi)->pp, (*pi)->size, 0, 0, 0, (*pi)->wchan, 309 pool_init((*pi)->pp, (*pi)->size, 0, 0, 0, (*pi)->wchan,
310 &pool_allocator_nointr, IPL_NONE); 310 &pool_allocator_nointr, IPL_NONE);
311} 311}
312 312
313static int 313static int
314_prop_object_copyin(const struct plistref *pref, const prop_type_t type, 314_prop_object_copyin(const struct plistref *pref, const prop_type_t type,
315 prop_object_t *objp) 315 prop_object_t *objp)
316{ 316{
317 prop_object_t obj = NULL; 317 prop_object_t obj = NULL;
318 char *buf; 318 char *buf;
319 int error; 319 int error;
320 320
321 /* 321 /*
322 * Allocate an extra byte so we can guarantee NUL-termination. 322 * Allocate an extra byte so we can guarantee NUL-termination.
323 * 323 *
324 * Allow malloc to fail in case pmap would be exhausted. 324 * Allow malloc to fail in case pmap would be exhausted.
325 */ 325 */
326 buf = malloc(pref->pref_len + 1, M_TEMP, M_WAITOK | M_CANFAIL); 326 buf = malloc(pref->pref_len + 1, M_TEMP, M_WAITOK | M_CANFAIL);
327 if (buf == NULL) 327 if (buf == NULL)
328 return (ENOMEM); 328 return (ENOMEM);
329 error = copyin(pref->pref_plist, buf, pref->pref_len); 329 error = copyin(pref->pref_plist, buf, pref->pref_len);
330 if (error) { 330 if (error) {
331 free(buf, M_TEMP); 331 free(buf, M_TEMP);
332 return (error); 332 return (error);
333 } 333 }
334 buf[pref->pref_len] = '\0'; 334 buf[pref->pref_len] = '\0';
335 335
336 switch (type) { 336 switch (type) {
337 case PROP_TYPE_ARRAY: 337 case PROP_TYPE_ARRAY:
338 obj = prop_array_internalize(buf); 338 obj = prop_array_internalize(buf);
339 break; 339 break;
340 case PROP_TYPE_DICTIONARY: 340 case PROP_TYPE_DICTIONARY:
341 obj = prop_dictionary_internalize(buf); 341 obj = prop_dictionary_internalize(buf);
342 break; 342 break;
343 default: 343 default:
344 error = ENOTSUP; 344 error = ENOTSUP;
345 } 345 }
346 346
347 free(buf, M_TEMP); 347 free(buf, M_TEMP);
348 if (obj == NULL) { 348 if (obj == NULL) {
349 if (error == 0) 349 if (error == 0)
350 error = EIO; 350 error = EIO;
351 } else { 351 } else {
352 *objp = obj; 352 *objp = obj;
353 } 353 }
354 return (error); 354 return (error);
355} 355}
356 356
357 357
358static int 358static int
359_prop_object_copyin_ioctl(const struct plistref *pref, const prop_type_t type, 359_prop_object_copyin_ioctl(const struct plistref *pref, const prop_type_t type,
360 const u_long cmd, prop_object_t *objp) 360 const u_long cmd, prop_object_t *objp)
361{ 361{
362 if ((cmd & IOC_IN) == 0) 362 if ((cmd & IOC_IN) == 0)
363 return (EFAULT); 363 return (EFAULT);
364 364
365 return _prop_object_copyin(pref, type, objp); 365 return _prop_object_copyin(pref, type, objp);
366} 366}
367 367
368/* 368/*
369 * prop_array_copyin -- 369 * prop_array_copyin --
370 * Copy in an array passed as a syscall arg. 370 * Copy in an array passed as a syscall arg.
371 */ 371 */
372int 372int
373prop_array_copyin(const struct plistref *pref, prop_array_t *arrayp) 373prop_array_copyin(const struct plistref *pref, prop_array_t *arrayp)
374{ 374{
375 return (_prop_object_copyin(pref, PROP_TYPE_ARRAY, 375 return (_prop_object_copyin(pref, PROP_TYPE_ARRAY,
376 (prop_object_t *)arrayp)); 376 (prop_object_t *)arrayp));
377} 377}
378 378
379/* 379/*
380 * prop_dictionary_copyin -- 380 * prop_dictionary_copyin --
381 * Copy in a dictionary passed as a syscall arg. 381 * Copy in a dictionary passed as a syscall arg.
382 */ 382 */
383int 383int
384prop_dictionary_copyin(const struct plistref *pref, prop_dictionary_t *dictp) 384prop_dictionary_copyin(const struct plistref *pref, prop_dictionary_t *dictp)
385{ 385{
386 return (_prop_object_copyin(pref, PROP_TYPE_DICTIONARY, 386 return (_prop_object_copyin(pref, PROP_TYPE_DICTIONARY,
387 (prop_object_t *)dictp)); 387 (prop_object_t *)dictp));
388} 388}
389 389
390 390
391/* 391/*
392 * prop_array_copyin_ioctl -- 392 * prop_array_copyin_ioctl --
393 * Copy in an array send with an ioctl. 393 * Copy in an array send with an ioctl.
394 */ 394 */
395int 395int
396prop_array_copyin_ioctl(const struct plistref *pref, const u_long cmd, 396prop_array_copyin_ioctl(const struct plistref *pref, const u_long cmd,
397 prop_array_t *arrayp) 397 prop_array_t *arrayp)
398{ 398{
399 return (_prop_object_copyin_ioctl(pref, PROP_TYPE_ARRAY, 399 return (_prop_object_copyin_ioctl(pref, PROP_TYPE_ARRAY,
400 cmd, (prop_object_t *)arrayp)); 400 cmd, (prop_object_t *)arrayp));
401} 401}
402 402
403/* 403/*
404 * prop_dictionary_copyin_ioctl -- 404 * prop_dictionary_copyin_ioctl --
405 * Copy in a dictionary sent with an ioctl. 405 * Copy in a dictionary sent with an ioctl.
406 */ 406 */
407int 407int
408prop_dictionary_copyin_ioctl(const struct plistref *pref, const u_long cmd, 408prop_dictionary_copyin_ioctl(const struct plistref *pref, const u_long cmd,
409 prop_dictionary_t *dictp) 409 prop_dictionary_t *dictp)
410{ 410{
411 return (_prop_object_copyin_ioctl(pref, PROP_TYPE_DICTIONARY, 411 return (_prop_object_copyin_ioctl(pref, PROP_TYPE_DICTIONARY,
412 cmd, (prop_object_t *)dictp)); 412 cmd, (prop_object_t *)dictp));
413} 413}
414 414
415static int 415static int
416_prop_object_copyout(struct plistref *pref, prop_object_t obj) 416_prop_object_copyout(struct plistref *pref, prop_object_t obj)
417{ 417{
418 struct lwp *l = curlwp; /* XXX */ 418 struct lwp *l = curlwp; /* XXX */
419 struct proc *p = l->l_proc; 419 struct proc *p = l->l_proc;
420 char *buf; 420 char *buf;
421 size_t len, rlen; 421 size_t len, rlen;
422 int error = 0; 422 int error = 0;
423 vaddr_t uaddr; 423 vaddr_t uaddr;
424 424
425 switch (prop_object_type(obj)) { 425 switch (prop_object_type(obj)) {
426 case PROP_TYPE_ARRAY: 426 case PROP_TYPE_ARRAY:
427 buf = prop_array_externalize(obj); 427 buf = prop_array_externalize(obj);
428 break; 428 break;
429 case PROP_TYPE_DICTIONARY: 429 case PROP_TYPE_DICTIONARY:
430 buf = prop_dictionary_externalize(obj); 430 buf = prop_dictionary_externalize(obj);
431 break; 431 break;
432 default: 432 default:
433 return (ENOTSUP); 433 return (ENOTSUP);
434 } 434 }
435 if (buf == NULL) 435 if (buf == NULL)
436 return (ENOMEM); 436 return (ENOMEM);
437 437
438 len = strlen(buf) + 1; 438 len = strlen(buf) + 1;
439 rlen = round_page(len); 439 rlen = round_page(len);
440 440
441 /* 441 /*
442 * See sys_mmap() in sys/uvm/uvm_mmap.c. 442 * See sys_mmap() in sys/uvm/uvm_mmap.c.
443 * Let's act as if we were calling mmap(0, ...) 443 * Let's act as if we were calling mmap(0, ...)
444 */ 444 */
445 uaddr = p->p_emul->e_vm_default_addr(p, 445 uaddr = p->p_emul->e_vm_default_addr(p,
446 (vaddr_t)p->p_vmspace->vm_daddr, rlen); 446 (vaddr_t)p->p_vmspace->vm_daddr, rlen);
447 447
448 error = uvm_mmap(&p->p_vmspace->vm_map, 448 error = uvm_mmap(&p->p_vmspace->vm_map,
449 &uaddr, rlen, 449 &uaddr, rlen,
450 VM_PROT_READ|VM_PROT_WRITE, 450 VM_PROT_READ|VM_PROT_WRITE,
451 VM_PROT_READ|VM_PROT_WRITE, 451 VM_PROT_READ|VM_PROT_WRITE,
452 MAP_PRIVATE|MAP_ANON, 452 MAP_PRIVATE|MAP_ANON,
453 NULL, 0, 453 NULL, 0,
454 p->p_rlimit[RLIMIT_MEMLOCK].rlim_cur); 454 p->p_rlimit[RLIMIT_MEMLOCK].rlim_cur);
455  455
456 if (error == 0) { 456 if (error == 0) {
457 error = copyout(buf, (char *)uaddr, len); 457 error = copyout(buf, (char *)uaddr, len);
458 if (error == 0) { 458 if (error == 0) {
459 pref->pref_plist = (char *)uaddr; 459 pref->pref_plist = (char *)uaddr;
460 pref->pref_len = len; 460 pref->pref_len = len;
461 } 461 }
462 } 462 }
463 463
464 free(buf, M_TEMP); 464 free(buf, M_TEMP);
465 465
466 return (error); 466 return (error);
467} 467}
468 468
469/* 469/*
470 * prop_array_copyout -- 470 * prop_array_copyout --
471 * Copy out an array to a syscall arg. 471 * Copy out an array to a syscall arg.
472 */ 472 */
473int 473int
474prop_array_copyout(struct plistref *pref, prop_array_t *arrayp) 474prop_array_copyout(struct plistref *pref, prop_array_t array)
475{ 475{
476 return (_prop_object_copyout(pref, (prop_object_t *)arrayp)); 476 return (_prop_object_copyout(pref, array));
477} 477}
478 478
479/* 479/*
480 * prop_dictionary_copyout -- 480 * prop_dictionary_copyout --
481 * Copy out a dictionary to a syscall arg. 481 * Copy out a dictionary to a syscall arg.
482 */ 482 */
483int 483int
484prop_dictionary_copyout(struct plistref *pref, prop_dictionary_t *dictp) 484prop_dictionary_copyout(struct plistref *pref, prop_dictionary_t dict)
485{ 485{
486 return (_prop_object_copyout(pref, (prop_object_t *)dictp)); 486 return (_prop_object_copyout(pref, dict));
487} 487}
488 488
489static int 489static int
490_prop_object_copyout_ioctl(struct plistref *pref, const u_long cmd, 490_prop_object_copyout_ioctl(struct plistref *pref, const u_long cmd,
491 prop_object_t obj) 491 prop_object_t obj)
492{ 492{
493 if ((cmd & IOC_OUT) == 0) 493 if ((cmd & IOC_OUT) == 0)
494 return (EFAULT); 494 return (EFAULT);
495 return _prop_object_copyout(pref, obj); 495 return _prop_object_copyout(pref, obj);
496} 496}
497 497
498 498
499/* 499/*
500 * prop_array_copyout_ioctl -- 500 * prop_array_copyout_ioctl --
501 * Copy out an array being received with an ioctl. 501 * Copy out an array being received with an ioctl.
502 */ 502 */
503int 503int
504prop_array_copyout_ioctl(struct plistref *pref, const u_long cmd, 504prop_array_copyout_ioctl(struct plistref *pref, const u_long cmd,
505 prop_array_t array) 505 prop_array_t array)
506{ 506{
507 return (_prop_object_copyout_ioctl(pref, cmd, array)); 507 return (_prop_object_copyout_ioctl(pref, cmd, array));
508} 508}
509 509
510/* 510/*
511 * prop_dictionary_copyout_ioctl -- 511 * prop_dictionary_copyout_ioctl --
512 * Copy out a dictionary being received with an ioctl. 512 * Copy out a dictionary being received with an ioctl.
513 */ 513 */
514int 514int
515prop_dictionary_copyout_ioctl(struct plistref *pref, const u_long cmd, 515prop_dictionary_copyout_ioctl(struct plistref *pref, const u_long cmd,
516 prop_dictionary_t dict) 516 prop_dictionary_t dict)
517{ 517{
518 return ( 518 return (
519 _prop_object_copyout_ioctl(pref, cmd, dict)); 519 _prop_object_copyout_ioctl(pref, cmd, dict));
520} 520}
521#endif /* _KERNEL */ 521#endif /* _KERNEL */
522 522
523#endif /* __NetBSD__ */ 523#endif /* __NetBSD__ */