xref: /netbsd-src/sys/compat/linux32/common/linux32_sysctl.c (revision eb961d0e02b7a46a9acfa877b02df48df6637278)
1 /*	$NetBSD: linux32_sysctl.c,v 1.1 2006/02/09 19:18:57 manu Exp $ */
2 
3 /*-
4  * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. All advertising materials mentioning features or use of this software
15  *    must display the following acknowledgement:
16  *	This product includes software developed by Emmanuel Dreyfus
17  * 4. The name of the author may not be used to endorse or promote
18  *    products derived from this software without specific prior written
19  *    permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE THE AUTHOR AND CONTRIBUTORS ``AS IS''
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
25  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  */
33 #include <sys/cdefs.h>
34 __KERNEL_RCSID(0, "$NetBSD: linux32_sysctl.c,v 1.1 2006/02/09 19:18:57 manu Exp $");
35 
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/errno.h>
39 #include <sys/proc.h>
40 #include <sys/mount.h>
41 #include <sys/sysctl.h>
42 #include <sys/sa.h>
43 #include <sys/syscallargs.h>
44 
45 #include <compat/netbsd32/netbsd32.h>
46 
47 #include <compat/linux/common/linux_types.h>
48 #include <compat/linux/common/linux_signal.h>
49 
50 #include <compat/linux/linux_syscallargs.h>
51 
52 #include <compat/linux32/common/linux32_types.h>
53 #include <compat/linux32/common/linux32_signal.h>
54 #include <compat/linux32/common/linux32_sysctl.h>
55 
56 #include <compat/linux32/linux32_syscallargs.h>
57 
58 char linux32_sysname[128] = "Linux";
59 char linux32_release[128] = "2.4.18";
60 char linux32_version[128] = "#0 Wed Feb 20 20:00:02 CET 2002";
61 
62 
63 SYSCTL_SETUP(sysctl_emul_linux32_setup, "sysctl emul.linux32 subtree setup")
64 {
65 
66 	sysctl_createv(clog, 0, NULL, NULL,
67 		       CTLFLAG_PERMANENT,
68 		       CTLTYPE_NODE, "emul", NULL,
69 		       NULL, 0, NULL, 0,
70 		       CTL_EMUL, CTL_EOL);
71 	sysctl_createv(clog, 0, NULL, NULL,
72 		       CTLFLAG_PERMANENT,
73 		       CTLTYPE_NODE, "linux32",
74 		       SYSCTL_DESCR("Linux 32 bit emulation settings"),
75 		       NULL, 0, NULL, 0,
76 		       CTL_EMUL, EMUL_LINUX32, CTL_EOL);
77 	sysctl_createv(clog, 0, NULL, NULL,
78 		       CTLFLAG_PERMANENT,
79 		       CTLTYPE_NODE, "kern",
80 		       SYSCTL_DESCR("Linux 32 bit kernel emulation settings"),
81 		       NULL, 0, NULL, 0,
82 		       CTL_EMUL, EMUL_LINUX32, EMUL_LINUX32_KERN, CTL_EOL);
83 
84 	sysctl_createv(clog, 0, NULL, NULL,
85 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
86 		       CTLTYPE_STRING, "ostype",
87 		       SYSCTL_DESCR("Linux 32 bit operating system type"),
88 		       NULL, 0, linux32_sysname, sizeof(linux32_sysname),
89 		       CTL_EMUL, EMUL_LINUX32, EMUL_LINUX32_KERN,
90 		       EMUL_LINUX32_KERN_OSTYPE, CTL_EOL);
91 	sysctl_createv(clog, 0, NULL, NULL,
92 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
93 		       CTLTYPE_STRING, "osrelease",
94 		       SYSCTL_DESCR("Linux 32 bit operating system release"),
95 		       NULL, 0, linux32_release, sizeof(linux32_release),
96 		       CTL_EMUL, EMUL_LINUX32, EMUL_LINUX32_KERN,
97 		       EMUL_LINUX32_KERN_OSRELEASE, CTL_EOL);
98 	sysctl_createv(clog, 0, NULL, NULL,
99 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
100 		       CTLTYPE_STRING, "osversion",
101 		       SYSCTL_DESCR("Linux 32 bit operating system revision"),
102 		       NULL, 0, linux32_version, sizeof(linux32_version),
103 		       CTL_EMUL, EMUL_LINUX32, EMUL_LINUX32_KERN,
104 		       EMUL_LINUX32_KERN_VERSION, CTL_EOL);
105 }
106 
107 
108 int
109 linux32_sys___sysctl(l, v, retval)
110 	struct lwp *l;
111 	void *v;
112 	register_t *retval;
113 {
114 	struct linux32_sys___sysctl_args /* {
115 		syscallarg(linux32___sysctlp_t) lsp;
116 	} */ *uap = v;
117 	caddr_t sg = stackgap_init(l->l_proc, 0);
118 	struct linux32_sysctl ls32;
119 	struct linux___sysctl ls;
120 	struct linux_sys___sysctl_args ua;
121 	int error;
122 
123 	if ((error = copyin(NETBSD32PTR64(SCARG(uap, lsp)),
124 	    &ls32, sizeof(ls32))) != 0)
125 		return error;
126 
127 	ls.name = NETBSD32PTR64(ls32.name);
128 	ls.nlen = ls32.name;
129 	ls.oldval = NETBSD32PTR64(ls32.oldval);
130 	ls.oldlenp = NETBSD32PTR64(ls32.oldlenp);
131 	ls.newval = NETBSD32PTR64(ls32.newval);
132 	ls.newlen = ls32.newlen;
133 
134 #ifdef DEBUG_LINUX
135 	{
136 		int i = ls.nlen;
137 		int *cp = ls.name;
138 		int val;
139 
140 		printf("linux32_sysctl(%p, %d, %p, %p, %p, %ld) [",
141 		    ls.name, ls.nlen, ls.oldval,
142 		    ls.oldlenp, ls.newval, ls.newlen);
143 		while (i > 0) {
144 			if ((error = copyin(cp, &val, sizeof(val))) != 0)
145 				return error;
146 			printf("%d ", val);
147 			cp++;
148 			i--;
149 		}
150 		printf("]\n");
151 	}
152 #endif
153 
154 	SCARG(&ua, lsp) = stackgap_alloc(l->l_proc, &sg, sizeof(ls));
155 
156 	if ((error = copyout(&ls, SCARG(&ua, lsp), sizeof(ls))) != 0)
157 		return error;
158 
159 	if ((error = linux_sys___sysctl(l, &ua, retval)) != 0)
160 		return error;
161 
162 	if ((error = copyin(SCARG(&ua, lsp), &ls, sizeof(ls))) != 0)
163 		return error;
164 
165 	ls32.name = (netbsd32_intp)(long)ls.name;
166 	ls32.nlen = ls.nlen;
167 	ls32.oldval = (netbsd32_voidp)(long)ls.oldval;
168 	ls32.oldlenp = (netbsd32_size_tp)(long)ls.oldlenp;
169 	ls32.newval = (netbsd32_voidp)(long)ls.newval;
170 	ls32.newlen = (netbsd32_size_t)(long)ls.newlen;
171 
172 	if ((error = copyout(&ls32,
173 	    NETBSD32PTR64(SCARG(uap, lsp)), sizeof(ls32))) != 0)
174 		return error;
175 
176 	return 0;
177 }
178