linux32_sysctl.c revision 1.14 1 1.14 chs /* $NetBSD: linux32_sysctl.c,v 1.14 2013/11/18 01:36:49 chs Exp $ */
2 1.1 manu
3 1.1 manu /*-
4 1.1 manu * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved.
5 1.1 manu *
6 1.1 manu * Redistribution and use in source and binary forms, with or without
7 1.1 manu * modification, are permitted provided that the following conditions
8 1.1 manu * are met:
9 1.1 manu * 1. Redistributions of source code must retain the above copyright
10 1.1 manu * notice, this list of conditions and the following disclaimer.
11 1.1 manu * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 manu * notice, this list of conditions and the following disclaimer in the
13 1.1 manu * documentation and/or other materials provided with the distribution.
14 1.1 manu * 3. All advertising materials mentioning features or use of this software
15 1.1 manu * must display the following acknowledgement:
16 1.1 manu * This product includes software developed by Emmanuel Dreyfus
17 1.1 manu * 4. The name of the author may not be used to endorse or promote
18 1.1 manu * products derived from this software without specific prior written
19 1.1 manu * permission.
20 1.1 manu *
21 1.1 manu * THIS SOFTWARE IS PROVIDED BY THE THE AUTHOR AND CONTRIBUTORS ``AS IS''
22 1.1 manu * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 1.1 manu * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 1.1 manu * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
25 1.1 manu * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 1.1 manu * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 1.1 manu * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 1.1 manu * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 1.1 manu * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 1.1 manu * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 1.1 manu * POSSIBILITY OF SUCH DAMAGE.
32 1.1 manu */
33 1.1 manu #include <sys/cdefs.h>
34 1.14 chs __KERNEL_RCSID(0, "$NetBSD: linux32_sysctl.c,v 1.14 2013/11/18 01:36:49 chs Exp $");
35 1.1 manu
36 1.1 manu #include <sys/param.h>
37 1.1 manu #include <sys/systm.h>
38 1.1 manu #include <sys/errno.h>
39 1.1 manu #include <sys/proc.h>
40 1.1 manu #include <sys/mount.h>
41 1.1 manu #include <sys/sysctl.h>
42 1.1 manu #include <sys/syscallargs.h>
43 1.3 manu #include <sys/ktrace.h>
44 1.1 manu
45 1.1 manu #include <compat/netbsd32/netbsd32.h>
46 1.1 manu
47 1.1 manu #include <compat/linux/common/linux_types.h>
48 1.1 manu #include <compat/linux/common/linux_signal.h>
49 1.2 manu #include <compat/linux/common/linux_sysctl.h>
50 1.11 ad #include <compat/linux/common/linux_ipc.h>
51 1.11 ad #include <compat/linux/common/linux_sem.h>
52 1.1 manu #include <compat/linux/linux_syscallargs.h>
53 1.1 manu
54 1.1 manu #include <compat/linux32/common/linux32_types.h>
55 1.1 manu #include <compat/linux32/common/linux32_signal.h>
56 1.1 manu #include <compat/linux32/common/linux32_sysctl.h>
57 1.1 manu #include <compat/linux32/linux32_syscallargs.h>
58 1.1 manu
59 1.1 manu char linux32_sysname[128] = "Linux";
60 1.14 chs char linux32_release[128] = "3.11.6";
61 1.14 chs char linux32_version[128] = "#1 SMP PREEMPT Thu Oct 24 16:23:02 UTC 2013";
62 1.1 manu
63 1.11 ad struct sysctlnode linux32_sysctl_root = {
64 1.11 ad .sysctl_flags = SYSCTL_VERSION|
65 1.11 ad CTLFLAG_ROOT|CTLTYPE_NODE|CTLFLAG_READWRITE,
66 1.11 ad .sysctl_num = 0,
67 1.11 ad .sysctl_name = "(linux32_root)",
68 1.11 ad sysc_init_field(_sysctl_size, sizeof(struct sysctlnode)),
69 1.11 ad };
70 1.11 ad
71 1.11 ad static struct sysctllog *linux32_clog1;
72 1.11 ad static struct sysctllog *linux32_clog2;
73 1.1 manu
74 1.11 ad void
75 1.11 ad linux32_sysctl_fini(void)
76 1.1 manu {
77 1.1 manu
78 1.11 ad sysctl_teardown(&linux32_clog2);
79 1.11 ad sysctl_teardown(&linux32_clog1);
80 1.11 ad sysctl_free(&linux32_sysctl_root);
81 1.11 ad }
82 1.11 ad
83 1.11 ad void
84 1.11 ad linux32_sysctl_init(void)
85 1.11 ad {
86 1.11 ad const struct sysctlnode *node = &linux32_sysctl_root;
87 1.11 ad
88 1.11 ad sysctl_createv(&linux32_clog1, 0, NULL, NULL,
89 1.1 manu CTLFLAG_PERMANENT,
90 1.1 manu CTLTYPE_NODE, "emul", NULL,
91 1.1 manu NULL, 0, NULL, 0,
92 1.1 manu CTL_EMUL, CTL_EOL);
93 1.11 ad sysctl_createv(&linux32_clog1, 0, NULL, NULL,
94 1.1 manu CTLFLAG_PERMANENT,
95 1.1 manu CTLTYPE_NODE, "linux32",
96 1.1 manu SYSCTL_DESCR("Linux 32 bit emulation settings"),
97 1.1 manu NULL, 0, NULL, 0,
98 1.1 manu CTL_EMUL, EMUL_LINUX32, CTL_EOL);
99 1.11 ad sysctl_createv(&linux32_clog1, 0, NULL, NULL,
100 1.1 manu CTLFLAG_PERMANENT,
101 1.1 manu CTLTYPE_NODE, "kern",
102 1.1 manu SYSCTL_DESCR("Linux 32 bit kernel emulation settings"),
103 1.1 manu NULL, 0, NULL, 0,
104 1.1 manu CTL_EMUL, EMUL_LINUX32, EMUL_LINUX32_KERN, CTL_EOL);
105 1.1 manu
106 1.11 ad sysctl_createv(&linux32_clog1, 0, NULL, NULL,
107 1.1 manu CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
108 1.1 manu CTLTYPE_STRING, "ostype",
109 1.1 manu SYSCTL_DESCR("Linux 32 bit operating system type"),
110 1.1 manu NULL, 0, linux32_sysname, sizeof(linux32_sysname),
111 1.1 manu CTL_EMUL, EMUL_LINUX32, EMUL_LINUX32_KERN,
112 1.1 manu EMUL_LINUX32_KERN_OSTYPE, CTL_EOL);
113 1.11 ad sysctl_createv(&linux32_clog1, 0, NULL, NULL,
114 1.1 manu CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
115 1.1 manu CTLTYPE_STRING, "osrelease",
116 1.1 manu SYSCTL_DESCR("Linux 32 bit operating system release"),
117 1.1 manu NULL, 0, linux32_release, sizeof(linux32_release),
118 1.1 manu CTL_EMUL, EMUL_LINUX32, EMUL_LINUX32_KERN,
119 1.1 manu EMUL_LINUX32_KERN_OSRELEASE, CTL_EOL);
120 1.11 ad sysctl_createv(&linux32_clog1, 0, NULL, NULL,
121 1.1 manu CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
122 1.1 manu CTLTYPE_STRING, "osversion",
123 1.1 manu SYSCTL_DESCR("Linux 32 bit operating system revision"),
124 1.1 manu NULL, 0, linux32_version, sizeof(linux32_version),
125 1.1 manu CTL_EMUL, EMUL_LINUX32, EMUL_LINUX32_KERN,
126 1.1 manu EMUL_LINUX32_KERN_VERSION, CTL_EOL);
127 1.2 manu
128 1.11 ad sysctl_createv(&linux32_clog2, 0, &node, &node,
129 1.2 manu CTLFLAG_PERMANENT,
130 1.2 manu CTLTYPE_NODE, "kern", NULL,
131 1.2 manu NULL, 0, NULL, 0,
132 1.2 manu LINUX_CTL_KERN, CTL_EOL);
133 1.2 manu
134 1.11 ad sysctl_createv(&linux32_clog2, 0, &node, NULL,
135 1.2 manu CTLFLAG_PERMANENT,
136 1.2 manu CTLTYPE_STRING, "ostype", NULL,
137 1.2 manu NULL, 0, linux32_sysname, sizeof(linux32_sysname),
138 1.2 manu LINUX_KERN_OSTYPE, CTL_EOL);
139 1.11 ad sysctl_createv(&linux32_clog2, 0, &node, NULL,
140 1.2 manu CTLFLAG_PERMANENT,
141 1.2 manu CTLTYPE_STRING, "osrelease", NULL,
142 1.2 manu NULL, 0, linux32_release, sizeof(linux32_release),
143 1.2 manu LINUX_KERN_OSRELEASE, CTL_EOL);
144 1.11 ad sysctl_createv(&linux32_clog2, 0, &node, NULL,
145 1.2 manu CTLFLAG_PERMANENT,
146 1.2 manu CTLTYPE_STRING, "version", NULL,
147 1.2 manu NULL, 0, linux32_version, sizeof(linux32_version),
148 1.2 manu LINUX_KERN_VERSION, CTL_EOL);
149 1.2 manu
150 1.2 manu linux32_sysctl_root.sysctl_flags &= ~CTLFLAG_READWRITE;
151 1.2 manu }
152 1.1 manu
153 1.1 manu int
154 1.8 dsl linux32_sys___sysctl(struct lwp *l, const struct linux32_sys___sysctl_args *uap, register_t *retval)
155 1.1 manu {
156 1.8 dsl /* {
157 1.1 manu syscallarg(linux32___sysctlp_t) lsp;
158 1.8 dsl } */
159 1.1 manu struct linux32_sysctl ls32;
160 1.2 manu int name[CTL_MAXNAME];
161 1.2 manu size_t savelen;
162 1.2 manu netbsd32_size_t oldlen32;
163 1.2 manu size_t oldlen;
164 1.1 manu int error;
165 1.1 manu
166 1.2 manu /*
167 1.2 manu * Read sysctl arguments
168 1.2 manu */
169 1.5 dsl if ((error = copyin(SCARG_P32(uap, lsp), &ls32, sizeof(ls32))) != 0)
170 1.1 manu return error;
171 1.1 manu
172 1.2 manu /*
173 1.2 manu * Read oldlen
174 1.2 manu */
175 1.2 manu if (NETBSD32PTR64(ls32.oldlenp) != NULL) {
176 1.2 manu if ((error = copyin(NETBSD32PTR64(ls32.oldlenp),
177 1.2 manu &oldlen32, sizeof(oldlen32))) != 0)
178 1.2 manu return error;
179 1.2 manu } else {
180 1.2 manu oldlen32 = 0;
181 1.2 manu }
182 1.2 manu
183 1.2 manu savelen = (size_t)oldlen32;
184 1.2 manu
185 1.2 manu /*
186 1.2 manu * Sanity check nlen
187 1.2 manu */
188 1.2 manu if ((ls32.nlen > CTL_MAXNAME) || (ls32.nlen < 1))
189 1.12 njoly return ENOTDIR;
190 1.2 manu
191 1.2 manu /*
192 1.2 manu * Read the sysctl name
193 1.2 manu */
194 1.2 manu if ((error = copyin(NETBSD32PTR64(ls32.name), &name,
195 1.2 manu ls32.nlen * sizeof(int))) != 0)
196 1.2 manu return error;
197 1.1 manu
198 1.6 ad ktrmib(name, ls32.nlen);
199 1.2 manu /*
200 1.2 manu * First try linux32 tree, then linux tree
201 1.2 manu */
202 1.2 manu oldlen = (size_t)oldlen32;
203 1.9 ad sysctl_lock(NETBSD32PTR64(ls32.newval) != NULL);
204 1.2 manu error = sysctl_dispatch(name, ls32.nlen,
205 1.2 manu NETBSD32PTR64(ls32.oldval), &oldlen,
206 1.2 manu NETBSD32PTR64(ls32.newval), ls32.newlen,
207 1.2 manu name, l, &linux32_sysctl_root);
208 1.2 manu oldlen32 = (netbsd32_size_t)oldlen;
209 1.9 ad sysctl_unlock();
210 1.2 manu
211 1.2 manu /*
212 1.2 manu * Check for oldlen overflow (not likely, but who knows...)
213 1.2 manu */
214 1.2 manu if (oldlen != oldlen32) {
215 1.2 manu #ifdef DEBUG_LINUX
216 1.2 manu printf("%s: oldlen32 = %d, oldlen = %ld\n",
217 1.2 manu __func__, oldlen32, oldlen);
218 1.2 manu #endif
219 1.2 manu return EINVAL;
220 1.2 manu }
221 1.1 manu
222 1.2 manu /*
223 1.2 manu * set caller's oldlen, even if we got an error
224 1.2 manu */
225 1.2 manu if (NETBSD32PTR64(ls32.oldlenp)) {
226 1.2 manu int nerror;
227 1.1 manu
228 1.2 manu nerror = copyout(&oldlen32,
229 1.2 manu NETBSD32PTR64(ls32.oldlenp), sizeof(oldlen32));
230 1.1 manu
231 1.2 manu if (error == 0)
232 1.2 manu error = nerror;
233 1.2 manu }
234 1.1 manu
235 1.2 manu /*
236 1.2 manu * oldlen was too short
237 1.2 manu */
238 1.2 manu if ((error == 0) &&
239 1.2 manu (NETBSD32PTR64(ls32.oldval) != NULL) &&
240 1.2 manu (savelen < oldlen32))
241 1.2 manu error = ENOMEM;
242 1.1 manu
243 1.2 manu return error;
244 1.1 manu }
245