2 * Copyright (c) 1999 Marcel Moolenaar
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer
10 * in this position and unchanged.
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. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * $FreeBSD: src/sys/compat/linux/linux_mib.c,v 1.7.2.2 2001/11/05 19:08:22 marcel Exp $
29 * $DragonFly: src/sys/emulation/linux/linux_mib.c,v 1.2 2003/06/17 04:28:19 dillon Exp $
32 #include <sys/param.h>
33 #include <sys/kernel.h>
34 #include <sys/systm.h>
35 #include <sys/sysctl.h>
37 #include <sys/malloc.h>
40 #include <machine/../linux/linux.h>
41 #include <compat/linux/linux_mib.h>
44 char pr_osname[LINUX_MAX_UTSNAME];
45 char pr_osrelease[LINUX_MAX_UTSNAME];
49 SYSCTL_NODE(_compat, OID_AUTO, linux, CTLFLAG_RW, 0,
52 static char linux_osname[LINUX_MAX_UTSNAME] = "Linux";
55 linux_sysctl_osname(SYSCTL_HANDLER_ARGS)
57 char osname[LINUX_MAX_UTSNAME];
60 strcpy(osname, linux_get_osname(req->p));
61 error = sysctl_handle_string(oidp, osname, LINUX_MAX_UTSNAME, req);
62 if (error || req->newptr == NULL)
64 error = linux_set_osname(req->p, osname);
68 SYSCTL_PROC(_compat_linux, OID_AUTO, osname,
69 CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_PRISON,
70 0, 0, linux_sysctl_osname, "A",
71 "Linux kernel OS name");
73 static char linux_osrelease[LINUX_MAX_UTSNAME] = "2.4.2";
76 linux_sysctl_osrelease(SYSCTL_HANDLER_ARGS)
78 char osrelease[LINUX_MAX_UTSNAME];
81 strcpy(osrelease, linux_get_osrelease(req->p));
82 error = sysctl_handle_string(oidp, osrelease, LINUX_MAX_UTSNAME, req);
83 if (error || req->newptr == NULL)
85 error = linux_set_osrelease(req->p, osrelease);
89 SYSCTL_PROC(_compat_linux, OID_AUTO, osrelease,
90 CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_PRISON,
91 0, 0, linux_sysctl_osrelease, "A",
92 "Linux kernel OS release");
94 static int linux_oss_version = 0x030600;
97 linux_sysctl_oss_version(SYSCTL_HANDLER_ARGS)
102 oss_version = linux_get_oss_version(req->p);
103 error = sysctl_handle_int(oidp, &oss_version, 0, req);
104 if (error || req->newptr == NULL)
106 error = linux_set_oss_version(req->p, oss_version);
110 SYSCTL_PROC(_compat_linux, OID_AUTO, oss_version,
111 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_PRISON,
112 0, 0, linux_sysctl_oss_version, "I",
113 "Linux OSS version");
115 static struct linux_prison *
116 get_prison(struct proc *p)
118 register struct prison *pr;
119 register struct linux_prison *lpr;
125 if (pr->pr_linux == NULL) {
126 MALLOC(lpr, struct linux_prison *, sizeof *lpr,
127 M_PRISON, M_WAITOK|M_ZERO);
131 return (pr->pr_linux);
138 register struct prison *pr;
139 register struct linux_prison *lpr;
142 if (pr != NULL && pr->pr_linux != NULL) {
144 if (lpr->pr_osname[0])
145 return (lpr->pr_osname);
148 return (linux_osname);
152 linux_set_osname(p, osname)
156 register struct linux_prison *lpr;
160 strcpy(lpr->pr_osname, osname);
162 strcpy(linux_osname, osname);
168 linux_get_osrelease(p)
171 register struct prison *pr;
172 register struct linux_prison *lpr;
175 if (pr != NULL && pr->pr_linux != NULL) {
177 if (lpr->pr_osrelease[0])
178 return (lpr->pr_osrelease);
181 return (linux_osrelease);
185 linux_set_osrelease(p, osrelease)
189 register struct linux_prison *lpr;
193 strcpy(lpr->pr_osrelease, osrelease);
195 strcpy(linux_osrelease, osrelease);
201 linux_get_oss_version(p)
204 register struct prison *pr;
205 register struct linux_prison *lpr;
208 if (pr != NULL && pr->pr_linux != NULL) {
210 if (lpr->pr_oss_version)
211 return (lpr->pr_oss_version);
214 return (linux_oss_version);
218 linux_set_oss_version(p, oss_version)
222 register struct linux_prison *lpr;
226 lpr->pr_oss_version = oss_version;
228 linux_oss_version = oss_version;
235 u_char linux_debug_map[howmany(LINUX_SYS_MAXSYSCALL, sizeof(u_char))];
238 linux_debug(int syscall, int toggle, int global)
242 char c = toggle ? 0 : 0xff;
244 memset(linux_debug_map, c, sizeof(linux_debug_map));
247 if (syscall < 0 || syscall >= LINUX_SYS_MAXSYSCALL)
250 clrbit(linux_debug_map, syscall);
252 setbit(linux_debug_map, syscall);
257 * Usage: sysctl -w linux.debug=<syscall_nr>.<0/1>
259 * E.g.: sysctl -w linux.debug=21.0
261 * As a special case, syscall "all" will apply to all syscalls globally.
263 #define LINUX_MAX_DEBUGSTR 16
265 linux_sysctl_debug(SYSCTL_HANDLER_ARGS)
267 char value[LINUX_MAX_DEBUGSTR], *p;
268 int error, sysc, toggle;
272 error = sysctl_handle_string(oidp, value, LINUX_MAX_DEBUGSTR, req);
273 if (error || req->newptr == NULL)
275 for (p = value; *p != '\0' && *p != '.'; p++);
279 sysc = strtol(value, NULL, 0);
280 toggle = strtol(p, NULL, 0);
281 if (strcmp(value, "all") == 0)
283 error = linux_debug(sysc, toggle, global);
287 SYSCTL_PROC(_compat_linux, OID_AUTO, debug,
288 CTLTYPE_STRING | CTLFLAG_RW,
289 0, 0, linux_sysctl_debug, "A",
290 "Linux debugging control");