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.
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include "opt_compat.h"
33 #include "opt_kdtrace.h"
35 #include <sys/param.h>
36 #include <sys/kernel.h>
38 #include <sys/systm.h>
39 #include <sys/sysctl.h>
41 #include <sys/malloc.h>
42 #include <sys/mount.h>
45 #include <sys/mutex.h>
49 #include <machine/../linux32/linux.h>
51 #include <machine/../linux/linux.h>
53 #include <compat/linux/linux_dtrace.h>
54 #include <compat/linux/linux_mib.h>
55 #include <compat/linux/linux_misc.h>
58 LIN_SDT_PROVIDER_DECLARE(LINUX_DTRACE);
61 * DTrace probes in this module.
63 LIN_SDT_PROBE_DEFINE0(mib, linux_sysctl_osname, entry);
64 LIN_SDT_PROBE_DEFINE1(mib, linux_sysctl_osname, sysctl_string_error, "int");
65 LIN_SDT_PROBE_DEFINE1(mib, linux_sysctl_osname, return, "int");
67 LIN_SDT_PROBE_DEFINE0(mib, linux_sysctl_osrelease, entry);
68 LIN_SDT_PROBE_DEFINE1(mib, linux_sysctl_osrelease, sysctl_string_error, "int");
69 LIN_SDT_PROBE_DEFINE1(mib, linux_sysctl_osrelease, return, "int");
70 LIN_SDT_PROBE_DEFINE0(mib, linux_sysctl_oss_version, entry);
71 LIN_SDT_PROBE_DEFINE1(mib, linux_sysctl_oss_version, sysctl_string_error,
73 LIN_SDT_PROBE_DEFINE1(mib, linux_sysctl_oss_version, return, "int");
74 LIN_SDT_PROBE_DEFINE2(mib, linux_map_osrel, entry, "char *", "int *");
75 LIN_SDT_PROBE_DEFINE1(mib, linux_map_osrel, return, "int");
76 LIN_SDT_PROBE_DEFINE2(mib, linux_get_prison, entry, "struct prison *",
78 LIN_SDT_PROBE_DEFINE1(mib, linux_get_prison, return, "struct linux_prison *");
79 LIN_SDT_PROBE_DEFINE2(mib, linux_alloc_prison, entry, "struct prison *",
80 "struct linux_prison **");
81 LIN_SDT_PROBE_DEFINE1(mib, linux_alloc_prison, return, "int");
82 LIN_SDT_PROBE_DEFINE2(mib, linux_prison_create, entry, "void *", "void *");
83 LIN_SDT_PROBE_DEFINE1(mib, linux_prison_create, vfs_copyopt_error, "int");
84 LIN_SDT_PROBE_DEFINE1(mib, linux_prison_create, return, "int");
85 LIN_SDT_PROBE_DEFINE2(mib, linux_prison_check, entry, "void *", "void *");
86 LIN_SDT_PROBE_DEFINE1(mib, linux_prison_check, vfs_copyopt_error, "int");
87 LIN_SDT_PROBE_DEFINE1(mib, linux_prison_check, vfs_getopt_error, "int");
88 LIN_SDT_PROBE_DEFINE1(mib, linux_prison_check, return, "int");
89 LIN_SDT_PROBE_DEFINE2(mib, linux_prison_set, entry, "void *", "void *");
90 LIN_SDT_PROBE_DEFINE1(mib, linux_prison_set, vfs_copyopt_error, "int");
91 LIN_SDT_PROBE_DEFINE1(mib, linux_prison_set, vfs_getopt_error, "int");
92 LIN_SDT_PROBE_DEFINE1(mib, linux_prison_set, return, "int");
93 LIN_SDT_PROBE_DEFINE2(mib, linux_prison_get, entry, "void *", "void *");
94 LIN_SDT_PROBE_DEFINE1(mib, linux_prison_get, vfs_setopt_error, "int");
95 LIN_SDT_PROBE_DEFINE1(mib, linux_prison_get, vfs_setopts_error, "int");
96 LIN_SDT_PROBE_DEFINE1(mib, linux_prison_get, return, "int");
97 LIN_SDT_PROBE_DEFINE1(mib, linux_prison_destructor, entry, "void *");
98 LIN_SDT_PROBE_DEFINE0(mib, linux_prison_destructor, return);
99 LIN_SDT_PROBE_DEFINE0(mib, linux_osd_jail_register, entry);
100 LIN_SDT_PROBE_DEFINE0(mib, linux_osd_jail_register, return);
101 LIN_SDT_PROBE_DEFINE0(mib, linux_osd_jail_deregister, entry);
102 LIN_SDT_PROBE_DEFINE0(mib, linux_osd_jail_deregister, return);
103 LIN_SDT_PROBE_DEFINE2(mib, linux_get_osname, entry, "struct thread *",
105 LIN_SDT_PROBE_DEFINE0(mib, linux_get_osname, return);
106 LIN_SDT_PROBE_DEFINE2(mib, linux_set_osname, entry, "struct thread *",
108 LIN_SDT_PROBE_DEFINE1(mib, linux_set_osname, return, "int");
109 LIN_SDT_PROBE_DEFINE2(mib, linux_get_osrelease, entry, "struct thread *",
111 LIN_SDT_PROBE_DEFINE0(mib, linux_get_osrelease, return);
112 LIN_SDT_PROBE_DEFINE1(mib, linux_kernver, entry, "struct thread *");
113 LIN_SDT_PROBE_DEFINE1(mib, linux_kernver, return, "int");
114 LIN_SDT_PROBE_DEFINE2(mib, linux_set_osrelease, entry, "struct thread *",
116 LIN_SDT_PROBE_DEFINE1(mib, linux_set_osrelease, return, "int");
117 LIN_SDT_PROBE_DEFINE1(mib, linux_get_oss_version, entry, "struct thread *");
118 LIN_SDT_PROBE_DEFINE1(mib, linux_get_oss_version, return, "int");
120 LIN_SDT_PROBE_DEFINE2(mib, linux_set_oss_version, entry, "struct thread *",
122 LIN_SDT_PROBE_DEFINE1(mib, linux_set_oss_version, return, "int");
124 struct linux_prison {
125 char pr_osname[LINUX_MAX_UTSNAME];
126 char pr_osrelease[LINUX_MAX_UTSNAME];
131 static struct linux_prison lprison0 = {
132 .pr_osname = "Linux",
133 .pr_osrelease = "2.6.16",
134 .pr_oss_version = 0x030600,
138 static unsigned linux_osd_jail_slot;
140 static SYSCTL_NODE(_compat, OID_AUTO, linux, CTLFLAG_RW, 0,
143 static int linux_set_osname(struct thread *td, char *osname);
144 static int linux_set_osrelease(struct thread *td, char *osrelease);
145 static int linux_set_oss_version(struct thread *td, int oss_version);
148 linux_sysctl_osname(SYSCTL_HANDLER_ARGS)
150 char osname[LINUX_MAX_UTSNAME];
153 LIN_SDT_PROBE0(mib, linux_sysctl_osname, entry);
155 linux_get_osname(req->td, osname);
156 error = sysctl_handle_string(oidp, osname, LINUX_MAX_UTSNAME, req);
157 if (error != 0 || req->newptr == NULL) {
158 LIN_SDT_PROBE1(mib, linux_sysctl_osname, sysctl_string_error,
160 LIN_SDT_PROBE1(mib, linux_sysctl_osname, return, error);
163 error = linux_set_osname(req->td, osname);
165 LIN_SDT_PROBE1(mib, linux_sysctl_osname, return, error);
169 SYSCTL_PROC(_compat_linux, OID_AUTO, osname,
170 CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_MPSAFE,
171 0, 0, linux_sysctl_osname, "A",
172 "Linux kernel OS name");
175 linux_sysctl_osrelease(SYSCTL_HANDLER_ARGS)
177 char osrelease[LINUX_MAX_UTSNAME];
180 LIN_SDT_PROBE0(mib, linux_sysctl_osrelease, entry);
182 linux_get_osrelease(req->td, osrelease);
183 error = sysctl_handle_string(oidp, osrelease, LINUX_MAX_UTSNAME, req);
184 if (error != 0 || req->newptr == NULL) {
185 LIN_SDT_PROBE1(mib, linux_sysctl_osrelease, sysctl_string_error,
187 LIN_SDT_PROBE1(mib, linux_sysctl_osrelease, return, error);
190 error = linux_set_osrelease(req->td, osrelease);
192 LIN_SDT_PROBE1(mib, linux_sysctl_osrelease, return, error);
196 SYSCTL_PROC(_compat_linux, OID_AUTO, osrelease,
197 CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_MPSAFE,
198 0, 0, linux_sysctl_osrelease, "A",
199 "Linux kernel OS release");
202 linux_sysctl_oss_version(SYSCTL_HANDLER_ARGS)
207 LIN_SDT_PROBE0(mib, linux_sysctl_oss_version, entry);
209 oss_version = linux_get_oss_version(req->td);
210 error = sysctl_handle_int(oidp, &oss_version, 0, req);
211 if (error != 0 || req->newptr == NULL) {
212 LIN_SDT_PROBE1(mib, linux_sysctl_oss_version,
213 sysctl_string_error, error);
214 LIN_SDT_PROBE1(mib, linux_sysctl_oss_version, return, error);
217 error = linux_set_oss_version(req->td, oss_version);
219 LIN_SDT_PROBE1(mib, linux_sysctl_oss_version, return, error);
223 SYSCTL_PROC(_compat_linux, OID_AUTO, oss_version,
224 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_MPSAFE,
225 0, 0, linux_sysctl_oss_version, "I",
226 "Linux OSS version");
229 * Map the osrelease into integer
232 linux_map_osrel(char *osrelease, int *osrel)
234 char *sep, *eosrelease;
235 int len, v0, v1, v2, v;
237 LIN_SDT_PROBE2(mib, linux_map_osrel, entry, osrelease, osrel);
239 len = strlen(osrelease);
240 eosrelease = osrelease + len;
241 v0 = strtol(osrelease, &sep, 10);
242 if (osrelease == sep || sep + 1 >= eosrelease || *sep != '.') {
243 LIN_SDT_PROBE1(mib, linux_map_osrel, return, EINVAL);
247 v1 = strtol(osrelease, &sep, 10);
248 if (osrelease == sep || sep + 1 >= eosrelease || *sep != '.') {
249 LIN_SDT_PROBE1(mib, linux_map_osrel, return, EINVAL);
253 v2 = strtol(osrelease, &sep, 10);
254 if (osrelease == sep || sep != eosrelease) {
255 LIN_SDT_PROBE1(mib, linux_map_osrel, return, EINVAL);
259 v = v0 * 1000000 + v1 * 1000 + v2;
261 LIN_SDT_PROBE1(mib, linux_map_osrel, return, EINVAL);
267 LIN_SDT_PROBE1(mib, linux_map_osrel, return, 0);
272 * Find a prison with Linux info.
273 * Return the Linux info and the (locked) prison.
275 static struct linux_prison *
276 linux_find_prison(struct prison *spr, struct prison **prp)
279 struct linux_prison *lpr;
281 LIN_SDT_PROBE2(mib, linux_get_prison, entry, spr, prp);
283 if (!linux_osd_jail_slot)
284 /* In case osd_register failed. */
286 for (pr = spr;; pr = pr->pr_parent) {
287 mtx_lock(&pr->pr_mtx);
288 lpr = (pr == &prison0)
290 : osd_jail_get(pr, linux_osd_jail_slot);
293 mtx_unlock(&pr->pr_mtx);
297 LIN_SDT_PROBE1(mib, linux_get_prison, return, lpr);
302 * Ensure a prison has its own Linux info. If lprp is non-null, point it to
303 * the Linux info and lock the prison.
306 linux_alloc_prison(struct prison *pr, struct linux_prison **lprp)
309 struct linux_prison *lpr, *nlpr;
312 LIN_SDT_PROBE2(mib, linux_alloc_prison, entry, pr, lprp);
314 /* If this prison already has Linux info, return that. */
316 lpr = linux_find_prison(pr, &ppr);
320 * Allocate a new info record. Then check again, in case something
321 * changed during the allocation.
323 mtx_unlock(&ppr->pr_mtx);
324 nlpr = malloc(sizeof(struct linux_prison), M_PRISON, M_WAITOK);
325 lpr = linux_find_prison(pr, &ppr);
327 free(nlpr, M_PRISON);
330 /* Inherit the initial values from the ancestor. */
331 mtx_lock(&pr->pr_mtx);
332 error = osd_jail_set(pr, linux_osd_jail_slot, nlpr);
334 bcopy(lpr, nlpr, sizeof(*lpr));
337 free(nlpr, M_PRISON);
340 mtx_unlock(&ppr->pr_mtx);
345 mtx_unlock(&pr->pr_mtx);
347 LIN_SDT_PROBE1(mib, linux_alloc_prison, return, error);
352 * Jail OSD methods for Linux prison data.
355 linux_prison_create(void *obj, void *data)
357 struct prison *pr = obj;
358 struct vfsoptlist *opts = data;
361 LIN_SDT_PROBE2(mib, linux_prison_create, entry, obj, data);
363 error = vfs_copyopt(opts, "linux", &jsys, sizeof(jsys));
365 LIN_SDT_PROBE1(mib, linux_prison_create, vfs_copyopt_error,
367 } else if (jsys == JAIL_SYS_INHERIT) {
368 LIN_SDT_PROBE1(mib, linux_prison_create, return, 0);
372 * Inherit a prison's initial values from its parent
373 * (different from JAIL_SYS_INHERIT which also inherits changes).
375 error = linux_alloc_prison(pr, NULL);
377 LIN_SDT_PROBE1(mib, linux_prison_create, return, error);
382 linux_prison_check(void *obj __unused, void *data)
384 struct vfsoptlist *opts = data;
385 char *osname, *osrelease;
386 int error, jsys, len, osrel, oss_version;
388 LIN_SDT_PROBE2(mib, linux_prison_check, entry, obj, data);
390 /* Check that the parameters are correct. */
391 error = vfs_copyopt(opts, "linux", &jsys, sizeof(jsys));
393 LIN_SDT_PROBE1(mib, linux_prison_check, vfs_copyopt_error,
396 if (error != ENOENT) {
398 LIN_SDT_PROBE1(mib, linux_prison_check, return, error);
401 if (jsys != JAIL_SYS_NEW && jsys != JAIL_SYS_INHERIT) {
402 LIN_SDT_PROBE1(mib, linux_prison_check, return, EINVAL);
406 error = vfs_getopt(opts, "linux.osname", (void **)&osname, &len);
408 LIN_SDT_PROBE1(mib, linux_prison_check, vfs_getopt_error,
411 if (error != ENOENT) {
413 LIN_SDT_PROBE1(mib, linux_prison_check, return, error);
416 if (len == 0 || osname[len - 1] != '\0') {
417 LIN_SDT_PROBE1(mib, linux_prison_check, return, EINVAL);
420 if (len > LINUX_MAX_UTSNAME) {
421 vfs_opterror(opts, "linux.osname too long");
422 LIN_SDT_PROBE1(mib, linux_prison_check, return,
424 return (ENAMETOOLONG);
427 error = vfs_getopt(opts, "linux.osrelease", (void **)&osrelease, &len);
429 LIN_SDT_PROBE1(mib, linux_prison_check, vfs_getopt_error,
432 if (error != ENOENT) {
434 LIN_SDT_PROBE1(mib, linux_prison_check, return, error);
437 if (len == 0 || osrelease[len - 1] != '\0') {
438 LIN_SDT_PROBE1(mib, linux_prison_check, return, EINVAL);
441 if (len > LINUX_MAX_UTSNAME) {
442 vfs_opterror(opts, "linux.osrelease too long");
443 LIN_SDT_PROBE1(mib, linux_prison_check, return,
445 return (ENAMETOOLONG);
447 error = linux_map_osrel(osrelease, &osrel);
449 vfs_opterror(opts, "linux.osrelease format error");
450 LIN_SDT_PROBE1(mib, linux_prison_check, return, error);
454 error = vfs_copyopt(opts, "linux.oss_version", &oss_version,
455 sizeof(oss_version));
457 LIN_SDT_PROBE1(mib, linux_prison_check, vfs_copyopt_error, error);
461 LIN_SDT_PROBE1(mib, linux_prison_check, return, error);
466 linux_prison_set(void *obj, void *data)
468 struct linux_prison *lpr;
469 struct prison *pr = obj;
470 struct vfsoptlist *opts = data;
471 char *osname, *osrelease;
472 int error, gotversion, jsys, len, oss_version;
474 LIN_SDT_PROBE2(mib, linux_prison_set, entry, obj, data);
476 /* Set the parameters, which should be correct. */
477 error = vfs_copyopt(opts, "linux", &jsys, sizeof(jsys));
479 LIN_SDT_PROBE1(mib, linux_prison_set, vfs_copyopt_error, error);
482 error = vfs_getopt(opts, "linux.osname", (void **)&osname, &len);
484 LIN_SDT_PROBE1(mib, linux_prison_set, vfs_getopt_error, error);
489 error = vfs_getopt(opts, "linux.osrelease", (void **)&osrelease, &len);
491 LIN_SDT_PROBE1(mib, linux_prison_set, vfs_getopt_error, error);
496 error = vfs_copyopt(opts, "linux.oss_version", &oss_version,
497 sizeof(oss_version));
499 LIN_SDT_PROBE1(mib, linux_prison_set, vfs_copyopt_error, error);
507 case JAIL_SYS_INHERIT:
508 /* "linux=inherit": inherit the parent's Linux info. */
509 mtx_lock(&pr->pr_mtx);
510 osd_jail_del(pr, linux_osd_jail_slot);
511 mtx_unlock(&pr->pr_mtx);
515 * "linux=new" or "linux.*":
516 * the prison gets its own Linux info.
518 error = linux_alloc_prison(pr, &lpr);
520 mtx_unlock(&pr->pr_mtx);
521 LIN_SDT_PROBE1(mib, linux_prison_set, return, error);
525 error = linux_map_osrel(osrelease, &lpr->pr_osrel);
527 mtx_unlock(&pr->pr_mtx);
528 LIN_SDT_PROBE1(mib, linux_prison_set, return,
532 strlcpy(lpr->pr_osrelease, osrelease,
536 strlcpy(lpr->pr_osname, osname, LINUX_MAX_UTSNAME);
538 lpr->pr_oss_version = oss_version;
539 mtx_unlock(&pr->pr_mtx);
542 LIN_SDT_PROBE1(mib, linux_prison_set, return, 0);
546 SYSCTL_JAIL_PARAM_SYS_NODE(linux, CTLFLAG_RW, "Jail Linux parameters");
547 SYSCTL_JAIL_PARAM_STRING(_linux, osname, CTLFLAG_RW, LINUX_MAX_UTSNAME,
548 "Jail Linux kernel OS name");
549 SYSCTL_JAIL_PARAM_STRING(_linux, osrelease, CTLFLAG_RW, LINUX_MAX_UTSNAME,
550 "Jail Linux kernel OS release");
551 SYSCTL_JAIL_PARAM(_linux, oss_version, CTLTYPE_INT | CTLFLAG_RW,
552 "I", "Jail Linux OSS version");
555 linux_prison_get(void *obj, void *data)
557 struct linux_prison *lpr;
559 struct prison *pr = obj;
560 struct vfsoptlist *opts = data;
565 LIN_SDT_PROBE2(mib, linux_prison_get, entry, obj, data);
567 /* See if this prison is the one with the Linux info. */
568 lpr = linux_find_prison(pr, &ppr);
569 i = (ppr == pr) ? JAIL_SYS_NEW : JAIL_SYS_INHERIT;
570 error = vfs_setopt(opts, "linux", &i, sizeof(i));
572 LIN_SDT_PROBE1(mib, linux_prison_get, vfs_setopt_error, error);
577 error = vfs_setopts(opts, "linux.osname", lpr->pr_osname);
579 LIN_SDT_PROBE1(mib, linux_prison_get, vfs_setopts_error,
584 error = vfs_setopts(opts, "linux.osrelease", lpr->pr_osrelease);
586 LIN_SDT_PROBE1(mib, linux_prison_get, vfs_setopts_error,
591 error = vfs_setopt(opts, "linux.oss_version",
592 &lpr->pr_oss_version, sizeof(lpr->pr_oss_version));
594 LIN_SDT_PROBE1(mib, linux_prison_get, vfs_setopt_error,
601 * If this prison is inheriting its Linux info, report
602 * empty/zero parameters.
604 error = vfs_setopts(opts, "linux.osname", "");
606 LIN_SDT_PROBE1(mib, linux_prison_get, vfs_setopts_error,
611 error = vfs_setopts(opts, "linux.osrelease", "");
613 LIN_SDT_PROBE1(mib, linux_prison_get, vfs_setopts_error,
618 error = vfs_setopt(opts, "linux.oss_version", &version0,
619 sizeof(lpr->pr_oss_version));
621 LIN_SDT_PROBE1(mib, linux_prison_get, vfs_setopt_error,
630 mtx_unlock(&ppr->pr_mtx);
632 LIN_SDT_PROBE1(mib, linux_prison_get, return, error);
637 linux_prison_destructor(void *data)
640 LIN_SDT_PROBE1(mib, linux_prison_destructor, entry, data);
641 free(data, M_PRISON);
642 LIN_SDT_PROBE0(mib, linux_prison_destructor, return);
646 linux_osd_jail_register(void)
649 osd_method_t methods[PR_MAXMETHOD] = {
650 [PR_METHOD_CREATE] = linux_prison_create,
651 [PR_METHOD_GET] = linux_prison_get,
652 [PR_METHOD_SET] = linux_prison_set,
653 [PR_METHOD_CHECK] = linux_prison_check
656 LIN_SDT_PROBE0(mib, linux_osd_jail_register, entry);
658 linux_osd_jail_slot =
659 osd_jail_register(linux_prison_destructor, methods);
660 if (linux_osd_jail_slot > 0) {
661 /* Copy the system linux info to any current prisons. */
662 sx_xlock(&allprison_lock);
663 TAILQ_FOREACH(pr, &allprison, pr_list)
664 (void)linux_alloc_prison(pr, NULL);
665 sx_xunlock(&allprison_lock);
668 LIN_SDT_PROBE0(mib, linux_osd_jail_register, return);
672 linux_osd_jail_deregister(void)
675 LIN_SDT_PROBE0(mib, linux_osd_jail_register, entry);
677 if (linux_osd_jail_slot)
678 osd_jail_deregister(linux_osd_jail_slot);
680 LIN_SDT_PROBE0(mib, linux_osd_jail_register, return);
684 linux_get_osname(struct thread *td, char *dst)
687 struct linux_prison *lpr;
689 LIN_SDT_PROBE2(mib, linux_get_osname, entry, td, dst);
691 lpr = linux_find_prison(td->td_ucred->cr_prison, &pr);
692 bcopy(lpr->pr_osname, dst, LINUX_MAX_UTSNAME);
693 mtx_unlock(&pr->pr_mtx);
695 LIN_SDT_PROBE0(mib, linux_get_osname, return);
699 linux_set_osname(struct thread *td, char *osname)
702 struct linux_prison *lpr;
704 LIN_SDT_PROBE2(mib, linux_set_osname, entry, td, osname);
706 lpr = linux_find_prison(td->td_ucred->cr_prison, &pr);
707 strlcpy(lpr->pr_osname, osname, LINUX_MAX_UTSNAME);
708 mtx_unlock(&pr->pr_mtx);
710 LIN_SDT_PROBE1(mib, linux_set_osname, return, 0);
715 linux_get_osrelease(struct thread *td, char *dst)
718 struct linux_prison *lpr;
720 LIN_SDT_PROBE2(mib, linux_get_osrelease, entry, td, dst);
722 lpr = linux_find_prison(td->td_ucred->cr_prison, &pr);
723 bcopy(lpr->pr_osrelease, dst, LINUX_MAX_UTSNAME);
724 mtx_unlock(&pr->pr_mtx);
726 LIN_SDT_PROBE0(mib, linux_get_osrelease, return);
730 linux_kernver(struct thread *td)
733 struct linux_prison *lpr;
736 LIN_SDT_PROBE1(mib, linux_kernver, entry, td);
738 lpr = linux_find_prison(td->td_ucred->cr_prison, &pr);
739 osrel = lpr->pr_osrel;
740 mtx_unlock(&pr->pr_mtx);
742 LIN_SDT_PROBE1(mib, linux_kernver, return, osrel);
747 linux_set_osrelease(struct thread *td, char *osrelease)
750 struct linux_prison *lpr;
753 LIN_SDT_PROBE2(mib, linux_set_osrelease, entry, td, osrelease);
755 lpr = linux_find_prison(td->td_ucred->cr_prison, &pr);
756 error = linux_map_osrel(osrelease, &lpr->pr_osrel);
758 strlcpy(lpr->pr_osrelease, osrelease, LINUX_MAX_UTSNAME);
759 mtx_unlock(&pr->pr_mtx);
761 LIN_SDT_PROBE1(mib, linux_set_osrelease, return, error);
766 linux_get_oss_version(struct thread *td)
769 struct linux_prison *lpr;
772 LIN_SDT_PROBE1(mib, linux_get_oss_version, entry, td);
774 lpr = linux_find_prison(td->td_ucred->cr_prison, &pr);
775 version = lpr->pr_oss_version;
776 mtx_unlock(&pr->pr_mtx);
778 LIN_SDT_PROBE1(mib, linux_get_oss_version, return, version);
783 linux_set_oss_version(struct thread *td, int oss_version)
786 struct linux_prison *lpr;
788 LIN_SDT_PROBE2(mib, linux_set_oss_version, entry, td, oss_version);
790 lpr = linux_find_prison(td->td_ucred->cr_prison, &pr);
791 lpr->pr_oss_version = oss_version;
792 mtx_unlock(&pr->pr_mtx);
794 LIN_SDT_PROBE1(mib, linux_set_oss_version, return, 0);
798 #if defined(DEBUG) || defined(KTR)
799 /* XXX: can be removed when every ldebug(...) and KTR stuff are removed. */
801 u_char linux_debug_map[howmany(LINUX_SYS_MAXSYSCALL, sizeof(u_char))];
804 linux_debug(int syscall, int toggle, int global)
808 char c = toggle ? 0 : 0xff;
810 memset(linux_debug_map, c, sizeof(linux_debug_map));
813 if (syscall < 0 || syscall >= LINUX_SYS_MAXSYSCALL)
816 clrbit(linux_debug_map, syscall);
818 setbit(linux_debug_map, syscall);
823 * Usage: sysctl linux.debug=<syscall_nr>.<0/1>
825 * E.g.: sysctl linux.debug=21.0
827 * As a special case, syscall "all" will apply to all syscalls globally.
829 #define LINUX_MAX_DEBUGSTR 16
831 linux_sysctl_debug(SYSCTL_HANDLER_ARGS)
833 char value[LINUX_MAX_DEBUGSTR], *p;
834 int error, sysc, toggle;
838 error = sysctl_handle_string(oidp, value, LINUX_MAX_DEBUGSTR, req);
839 if (error || req->newptr == NULL)
841 for (p = value; *p != '\0' && *p != '.'; p++);
845 sysc = strtol(value, NULL, 0);
846 toggle = strtol(p, NULL, 0);
847 if (strcmp(value, "all") == 0)
849 error = linux_debug(sysc, toggle, global);
853 SYSCTL_PROC(_compat_linux, OID_AUTO, debug,
854 CTLTYPE_STRING | CTLFLAG_RW,
855 0, 0, linux_sysctl_debug, "A",
856 "Linux debugging control");
858 #endif /* DEBUG || KTR */