1 /* $NetBSD: linux32_sysctl.c,v 1.11 2008/11/19 18:36:04 ad Exp $ */
4 * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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
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.
33 #include <sys/cdefs.h>
34 __KERNEL_RCSID(0, "$NetBSD: linux32_sysctl.c,v 1.11 2008/11/19 18:36:04 ad Exp $");
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/errno.h>
40 #include <sys/mount.h>
41 #include <sys/sysctl.h>
42 #include <sys/syscallargs.h>
43 #include <sys/ktrace.h>
45 #include <compat/netbsd32/netbsd32.h>
47 #include <compat/linux/common/linux_types.h>
48 #include <compat/linux/common/linux_signal.h>
49 #include <compat/linux/common/linux_sysctl.h>
50 #include <compat/linux/common/linux_ipc.h>
51 #include <compat/linux/common/linux_sem.h>
52 #include <compat/linux/linux_syscallargs.h>
54 #include <compat/linux32/common/linux32_types.h>
55 #include <compat/linux32/common/linux32_signal.h>
56 #include <compat/linux32/common/linux32_sysctl.h>
57 #include <compat/linux32/linux32_syscallargs.h>
59 char linux32_sysname
[128] = "Linux";
60 char linux32_release
[128] = "2.4.18";
61 char linux32_version
[128] = "#0 Wed Feb 20 20:00:02 CET 2002";
63 struct sysctlnode linux32_sysctl_root
= {
64 .sysctl_flags
= SYSCTL_VERSION
|
65 CTLFLAG_ROOT
|CTLTYPE_NODE
|CTLFLAG_READWRITE
,
67 .sysctl_name
= "(linux32_root)",
68 sysc_init_field(_sysctl_size
, sizeof(struct sysctlnode
)),
71 static struct sysctllog
*linux32_clog1
;
72 static struct sysctllog
*linux32_clog2
;
75 linux32_sysctl_fini(void)
78 sysctl_teardown(&linux32_clog2
);
79 sysctl_teardown(&linux32_clog1
);
80 sysctl_free(&linux32_sysctl_root
);
84 linux32_sysctl_init(void)
86 const struct sysctlnode
*node
= &linux32_sysctl_root
;
88 sysctl_createv(&linux32_clog1
, 0, NULL
, NULL
,
90 CTLTYPE_NODE
, "emul", NULL
,
93 sysctl_createv(&linux32_clog1
, 0, NULL
, NULL
,
95 CTLTYPE_NODE
, "linux32",
96 SYSCTL_DESCR("Linux 32 bit emulation settings"),
98 CTL_EMUL
, EMUL_LINUX32
, CTL_EOL
);
99 sysctl_createv(&linux32_clog1
, 0, NULL
, NULL
,
101 CTLTYPE_NODE
, "kern",
102 SYSCTL_DESCR("Linux 32 bit kernel emulation settings"),
104 CTL_EMUL
, EMUL_LINUX32
, EMUL_LINUX32_KERN
, CTL_EOL
);
106 sysctl_createv(&linux32_clog1
, 0, NULL
, NULL
,
107 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
108 CTLTYPE_STRING
, "ostype",
109 SYSCTL_DESCR("Linux 32 bit operating system type"),
110 NULL
, 0, linux32_sysname
, sizeof(linux32_sysname
),
111 CTL_EMUL
, EMUL_LINUX32
, EMUL_LINUX32_KERN
,
112 EMUL_LINUX32_KERN_OSTYPE
, CTL_EOL
);
113 sysctl_createv(&linux32_clog1
, 0, NULL
, NULL
,
114 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
115 CTLTYPE_STRING
, "osrelease",
116 SYSCTL_DESCR("Linux 32 bit operating system release"),
117 NULL
, 0, linux32_release
, sizeof(linux32_release
),
118 CTL_EMUL
, EMUL_LINUX32
, EMUL_LINUX32_KERN
,
119 EMUL_LINUX32_KERN_OSRELEASE
, CTL_EOL
);
120 sysctl_createv(&linux32_clog1
, 0, NULL
, NULL
,
121 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
122 CTLTYPE_STRING
, "osversion",
123 SYSCTL_DESCR("Linux 32 bit operating system revision"),
124 NULL
, 0, linux32_version
, sizeof(linux32_version
),
125 CTL_EMUL
, EMUL_LINUX32
, EMUL_LINUX32_KERN
,
126 EMUL_LINUX32_KERN_VERSION
, CTL_EOL
);
128 sysctl_createv(&linux32_clog2
, 0, &node
, &node
,
130 CTLTYPE_NODE
, "kern", NULL
,
132 LINUX_CTL_KERN
, CTL_EOL
);
134 sysctl_createv(&linux32_clog2
, 0, &node
, NULL
,
136 CTLTYPE_STRING
, "ostype", NULL
,
137 NULL
, 0, linux32_sysname
, sizeof(linux32_sysname
),
138 LINUX_KERN_OSTYPE
, CTL_EOL
);
139 sysctl_createv(&linux32_clog2
, 0, &node
, NULL
,
141 CTLTYPE_STRING
, "osrelease", NULL
,
142 NULL
, 0, linux32_release
, sizeof(linux32_release
),
143 LINUX_KERN_OSRELEASE
, CTL_EOL
);
144 sysctl_createv(&linux32_clog2
, 0, &node
, NULL
,
146 CTLTYPE_STRING
, "version", NULL
,
147 NULL
, 0, linux32_version
, sizeof(linux32_version
),
148 LINUX_KERN_VERSION
, CTL_EOL
);
150 linux32_sysctl_root
.sysctl_flags
&= ~CTLFLAG_READWRITE
;
154 linux32_sys___sysctl(struct lwp
*l
, const struct linux32_sys___sysctl_args
*uap
, register_t
*retval
)
157 syscallarg(linux32___sysctlp_t) lsp;
159 struct linux32_sysctl ls32
;
160 int name
[CTL_MAXNAME
];
162 netbsd32_size_t oldlen32
;
167 * Read sysctl arguments
169 if ((error
= copyin(SCARG_P32(uap
, lsp
), &ls32
, sizeof(ls32
))) != 0)
175 if (NETBSD32PTR64(ls32
.oldlenp
) != NULL
) {
176 if ((error
= copyin(NETBSD32PTR64(ls32
.oldlenp
),
177 &oldlen32
, sizeof(oldlen32
))) != 0)
183 savelen
= (size_t)oldlen32
;
188 if ((ls32
.nlen
> CTL_MAXNAME
) || (ls32
.nlen
< 1))
192 * Read the sysctl name
194 if ((error
= copyin(NETBSD32PTR64(ls32
.name
), &name
,
195 ls32
.nlen
* sizeof(int))) != 0)
198 ktrmib(name
, ls32
.nlen
);
200 * First try linux32 tree, then linux tree
202 oldlen
= (size_t)oldlen32
;
203 sysctl_lock(NETBSD32PTR64(ls32
.newval
) != NULL
);
204 error
= sysctl_dispatch(name
, ls32
.nlen
,
205 NETBSD32PTR64(ls32
.oldval
), &oldlen
,
206 NETBSD32PTR64(ls32
.newval
), ls32
.newlen
,
207 name
, l
, &linux32_sysctl_root
);
208 oldlen32
= (netbsd32_size_t
)oldlen
;
212 * Check for oldlen overflow (not likely, but who knows...)
214 if (oldlen
!= oldlen32
) {
216 printf("%s: oldlen32 = %d, oldlen = %ld\n",
217 __func__
, oldlen32
, oldlen
);
223 * set caller's oldlen, even if we got an error
225 if (NETBSD32PTR64(ls32
.oldlenp
)) {
228 nerror
= copyout(&oldlen32
,
229 NETBSD32PTR64(ls32
.oldlenp
), sizeof(oldlen32
));
236 * oldlen was too short
239 (NETBSD32PTR64(ls32
.oldval
) != NULL
) &&
240 (savelen
< oldlen32
))