linux32_sysctl.c revision 1.1 1 1.1 manu /* $NetBSD: linux32_sysctl.c,v 1.1 2006/02/09 19:18:57 manu 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.1 manu __KERNEL_RCSID(0, "$NetBSD: linux32_sysctl.c,v 1.1 2006/02/09 19:18:57 manu 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/sa.h>
43 1.1 manu #include <sys/syscallargs.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.1 manu
50 1.1 manu #include <compat/linux/linux_syscallargs.h>
51 1.1 manu
52 1.1 manu #include <compat/linux32/common/linux32_types.h>
53 1.1 manu #include <compat/linux32/common/linux32_signal.h>
54 1.1 manu #include <compat/linux32/common/linux32_sysctl.h>
55 1.1 manu
56 1.1 manu #include <compat/linux32/linux32_syscallargs.h>
57 1.1 manu
58 1.1 manu char linux32_sysname[128] = "Linux";
59 1.1 manu char linux32_release[128] = "2.4.18";
60 1.1 manu char linux32_version[128] = "#0 Wed Feb 20 20:00:02 CET 2002";
61 1.1 manu
62 1.1 manu
63 1.1 manu SYSCTL_SETUP(sysctl_emul_linux32_setup, "sysctl emul.linux32 subtree setup")
64 1.1 manu {
65 1.1 manu
66 1.1 manu sysctl_createv(clog, 0, NULL, NULL,
67 1.1 manu CTLFLAG_PERMANENT,
68 1.1 manu CTLTYPE_NODE, "emul", NULL,
69 1.1 manu NULL, 0, NULL, 0,
70 1.1 manu CTL_EMUL, CTL_EOL);
71 1.1 manu sysctl_createv(clog, 0, NULL, NULL,
72 1.1 manu CTLFLAG_PERMANENT,
73 1.1 manu CTLTYPE_NODE, "linux32",
74 1.1 manu SYSCTL_DESCR("Linux 32 bit emulation settings"),
75 1.1 manu NULL, 0, NULL, 0,
76 1.1 manu CTL_EMUL, EMUL_LINUX32, CTL_EOL);
77 1.1 manu sysctl_createv(clog, 0, NULL, NULL,
78 1.1 manu CTLFLAG_PERMANENT,
79 1.1 manu CTLTYPE_NODE, "kern",
80 1.1 manu SYSCTL_DESCR("Linux 32 bit kernel emulation settings"),
81 1.1 manu NULL, 0, NULL, 0,
82 1.1 manu CTL_EMUL, EMUL_LINUX32, EMUL_LINUX32_KERN, CTL_EOL);
83 1.1 manu
84 1.1 manu sysctl_createv(clog, 0, NULL, NULL,
85 1.1 manu CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
86 1.1 manu CTLTYPE_STRING, "ostype",
87 1.1 manu SYSCTL_DESCR("Linux 32 bit operating system type"),
88 1.1 manu NULL, 0, linux32_sysname, sizeof(linux32_sysname),
89 1.1 manu CTL_EMUL, EMUL_LINUX32, EMUL_LINUX32_KERN,
90 1.1 manu EMUL_LINUX32_KERN_OSTYPE, CTL_EOL);
91 1.1 manu sysctl_createv(clog, 0, NULL, NULL,
92 1.1 manu CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
93 1.1 manu CTLTYPE_STRING, "osrelease",
94 1.1 manu SYSCTL_DESCR("Linux 32 bit operating system release"),
95 1.1 manu NULL, 0, linux32_release, sizeof(linux32_release),
96 1.1 manu CTL_EMUL, EMUL_LINUX32, EMUL_LINUX32_KERN,
97 1.1 manu EMUL_LINUX32_KERN_OSRELEASE, CTL_EOL);
98 1.1 manu sysctl_createv(clog, 0, NULL, NULL,
99 1.1 manu CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
100 1.1 manu CTLTYPE_STRING, "osversion",
101 1.1 manu SYSCTL_DESCR("Linux 32 bit operating system revision"),
102 1.1 manu NULL, 0, linux32_version, sizeof(linux32_version),
103 1.1 manu CTL_EMUL, EMUL_LINUX32, EMUL_LINUX32_KERN,
104 1.1 manu EMUL_LINUX32_KERN_VERSION, CTL_EOL);
105 1.1 manu }
106 1.1 manu
107 1.1 manu
108 1.1 manu int
109 1.1 manu linux32_sys___sysctl(l, v, retval)
110 1.1 manu struct lwp *l;
111 1.1 manu void *v;
112 1.1 manu register_t *retval;
113 1.1 manu {
114 1.1 manu struct linux32_sys___sysctl_args /* {
115 1.1 manu syscallarg(linux32___sysctlp_t) lsp;
116 1.1 manu } */ *uap = v;
117 1.1 manu caddr_t sg = stackgap_init(l->l_proc, 0);
118 1.1 manu struct linux32_sysctl ls32;
119 1.1 manu struct linux___sysctl ls;
120 1.1 manu struct linux_sys___sysctl_args ua;
121 1.1 manu int error;
122 1.1 manu
123 1.1 manu if ((error = copyin(NETBSD32PTR64(SCARG(uap, lsp)),
124 1.1 manu &ls32, sizeof(ls32))) != 0)
125 1.1 manu return error;
126 1.1 manu
127 1.1 manu ls.name = NETBSD32PTR64(ls32.name);
128 1.1 manu ls.nlen = ls32.name;
129 1.1 manu ls.oldval = NETBSD32PTR64(ls32.oldval);
130 1.1 manu ls.oldlenp = NETBSD32PTR64(ls32.oldlenp);
131 1.1 manu ls.newval = NETBSD32PTR64(ls32.newval);
132 1.1 manu ls.newlen = ls32.newlen;
133 1.1 manu
134 1.1 manu #ifdef DEBUG_LINUX
135 1.1 manu {
136 1.1 manu int i = ls.nlen;
137 1.1 manu int *cp = ls.name;
138 1.1 manu int val;
139 1.1 manu
140 1.1 manu printf("linux32_sysctl(%p, %d, %p, %p, %p, %ld) [",
141 1.1 manu ls.name, ls.nlen, ls.oldval,
142 1.1 manu ls.oldlenp, ls.newval, ls.newlen);
143 1.1 manu while (i > 0) {
144 1.1 manu if ((error = copyin(cp, &val, sizeof(val))) != 0)
145 1.1 manu return error;
146 1.1 manu printf("%d ", val);
147 1.1 manu cp++;
148 1.1 manu i--;
149 1.1 manu }
150 1.1 manu printf("]\n");
151 1.1 manu }
152 1.1 manu #endif
153 1.1 manu
154 1.1 manu SCARG(&ua, lsp) = stackgap_alloc(l->l_proc, &sg, sizeof(ls));
155 1.1 manu
156 1.1 manu if ((error = copyout(&ls, SCARG(&ua, lsp), sizeof(ls))) != 0)
157 1.1 manu return error;
158 1.1 manu
159 1.1 manu if ((error = linux_sys___sysctl(l, &ua, retval)) != 0)
160 1.1 manu return error;
161 1.1 manu
162 1.1 manu if ((error = copyin(SCARG(&ua, lsp), &ls, sizeof(ls))) != 0)
163 1.1 manu return error;
164 1.1 manu
165 1.1 manu ls32.name = (netbsd32_intp)(long)ls.name;
166 1.1 manu ls32.nlen = ls.nlen;
167 1.1 manu ls32.oldval = (netbsd32_voidp)(long)ls.oldval;
168 1.1 manu ls32.oldlenp = (netbsd32_size_tp)(long)ls.oldlenp;
169 1.1 manu ls32.newval = (netbsd32_voidp)(long)ls.newval;
170 1.1 manu ls32.newlen = (netbsd32_size_t)(long)ls.newlen;
171 1.1 manu
172 1.1 manu if ((error = copyout(&ls32,
173 1.1 manu NETBSD32PTR64(SCARG(uap, lsp)), sizeof(ls32))) != 0)
174 1.1 manu return error;
175 1.1 manu
176 1.1 manu return 0;
177 1.1 manu }
178