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>
57 LIN_SDT_PROVIDER_DECLARE(LINUX_DTRACE);
60 * DTrace probes in this module.
62 LIN_SDT_PROBE_DEFINE0(mib, linux_sysctl_osname, entry);
63 LIN_SDT_PROBE_DEFINE1(mib, linux_sysctl_osname, sysctl_string_error, "int");
64 LIN_SDT_PROBE_DEFINE1(mib, linux_sysctl_osname, return, "int");
66 LIN_SDT_PROBE_DEFINE0(mib, linux_sysctl_osrelease, entry);
67 LIN_SDT_PROBE_DEFINE1(mib, linux_sysctl_osrelease, sysctl_string_error, "int");
68 LIN_SDT_PROBE_DEFINE1(mib, linux_sysctl_osrelease, return, "int");
69 LIN_SDT_PROBE_DEFINE0(mib, linux_sysctl_oss_version, entry);
70 LIN_SDT_PROBE_DEFINE1(mib, linux_sysctl_oss_version, sysctl_string_error,
72 LIN_SDT_PROBE_DEFINE1(mib, linux_sysctl_oss_version, return, "int");
73 LIN_SDT_PROBE_DEFINE2(mib, linux_map_osrel, entry, "char *", "int *");
74 LIN_SDT_PROBE_DEFINE1(mib, linux_map_osrel, return, "int");
75 LIN_SDT_PROBE_DEFINE2(mib, linux_get_prison, entry, "struct prison *",
77 LIN_SDT_PROBE_DEFINE1(mib, linux_get_prison, return, "struct linux_prison *");
78 LIN_SDT_PROBE_DEFINE2(mib, linux_alloc_prison, entry, "struct prison *",
79 "struct linux_prison **");
80 LIN_SDT_PROBE_DEFINE1(mib, linux_alloc_prison, return, "int");
81 LIN_SDT_PROBE_DEFINE2(mib, linux_prison_create, entry, "void *", "void *");
82 LIN_SDT_PROBE_DEFINE1(mib, linux_prison_create, vfs_copyopt_error, "int");
83 LIN_SDT_PROBE_DEFINE1(mib, linux_prison_create, return, "int");
84 LIN_SDT_PROBE_DEFINE2(mib, linux_prison_check, entry, "void *", "void *");
85 LIN_SDT_PROBE_DEFINE1(mib, linux_prison_check, vfs_copyopt_error, "int");
86 LIN_SDT_PROBE_DEFINE1(mib, linux_prison_check, vfs_getopt_error, "int");
87 LIN_SDT_PROBE_DEFINE1(mib, linux_prison_check, return, "int");
88 LIN_SDT_PROBE_DEFINE2(mib, linux_prison_set, entry, "void *", "void *");
89 LIN_SDT_PROBE_DEFINE1(mib, linux_prison_set, vfs_copyopt_error, "int");
90 LIN_SDT_PROBE_DEFINE1(mib, linux_prison_set, vfs_getopt_error, "int");
91 LIN_SDT_PROBE_DEFINE1(mib, linux_prison_set, return, "int");
92 LIN_SDT_PROBE_DEFINE2(mib, linux_prison_get, entry, "void *", "void *");
93 LIN_SDT_PROBE_DEFINE1(mib, linux_prison_get, vfs_setopt_error, "int");
94 LIN_SDT_PROBE_DEFINE1(mib, linux_prison_get, vfs_setopts_error, "int");
95 LIN_SDT_PROBE_DEFINE1(mib, linux_prison_get, return, "int");
96 LIN_SDT_PROBE_DEFINE1(mib, linux_prison_destructor, entry, "void *");
97 LIN_SDT_PROBE_DEFINE0(mib, linux_prison_destructor, return);
98 LIN_SDT_PROBE_DEFINE0(mib, linux_osd_jail_register, entry);
99 LIN_SDT_PROBE_DEFINE0(mib, linux_osd_jail_register, return);
100 LIN_SDT_PROBE_DEFINE0(mib, linux_osd_jail_deregister, entry);
101 LIN_SDT_PROBE_DEFINE0(mib, linux_osd_jail_deregister, return);
102 LIN_SDT_PROBE_DEFINE2(mib, linux_get_osname, entry, "struct thread *",
104 LIN_SDT_PROBE_DEFINE0(mib, linux_get_osname, return);
105 LIN_SDT_PROBE_DEFINE2(mib, linux_set_osname, entry, "struct thread *",
107 LIN_SDT_PROBE_DEFINE1(mib, linux_set_osname, return, "int");
108 LIN_SDT_PROBE_DEFINE2(mib, linux_get_osrelease, entry, "struct thread *",
110 LIN_SDT_PROBE_DEFINE0(mib, linux_get_osrelease, return);
111 LIN_SDT_PROBE_DEFINE1(mib, linux_kernver, entry, "struct thread *");
112 LIN_SDT_PROBE_DEFINE1(mib, linux_kernver, return, "int");
113 LIN_SDT_PROBE_DEFINE2(mib, linux_set_osrelease, entry, "struct thread *",
115 LIN_SDT_PROBE_DEFINE1(mib, linux_set_osrelease, return, "int");
116 LIN_SDT_PROBE_DEFINE1(mib, linux_get_oss_version, entry, "struct thread *");
117 LIN_SDT_PROBE_DEFINE1(mib, linux_get_oss_version, return, "int");
119 LIN_SDT_PROBE_DEFINE2(mib, linux_set_oss_version, entry, "struct thread *",
121 LIN_SDT_PROBE_DEFINE1(mib, linux_set_oss_version, return, "int");
123 struct linux_prison {
124 char pr_osname[LINUX_MAX_UTSNAME];
125 char pr_osrelease[LINUX_MAX_UTSNAME];
130 static struct linux_prison lprison0 = {
131 .pr_osname = "Linux",
132 .pr_osrelease = "2.6.16",
133 .pr_oss_version = 0x030600,
137 static unsigned linux_osd_jail_slot;
139 static SYSCTL_NODE(_compat, OID_AUTO, linux, CTLFLAG_RW, 0,
142 static int linux_set_osname(struct thread *td, char *osname);
143 static int linux_set_osrelease(struct thread *td, char *osrelease);
144 static int linux_set_oss_version(struct thread *td, int oss_version);
147 linux_sysctl_osname(SYSCTL_HANDLER_ARGS)
149 char osname[LINUX_MAX_UTSNAME];
152 LIN_SDT_PROBE0(mib, linux_sysctl_osname, entry);
154 linux_get_osname(req->td, osname);
155 error = sysctl_handle_string(oidp, osname, LINUX_MAX_UTSNAME, req);
156 if (error != 0 || req->newptr == NULL) {
157 LIN_SDT_PROBE1(mib, linux_sysctl_osname, sysctl_string_error,
159 LIN_SDT_PROBE1(mib, linux_sysctl_osname, return, error);
162 error = linux_set_osname(req->td, osname);
164 LIN_SDT_PROBE1(mib, linux_sysctl_osname, return, error);
168 SYSCTL_PROC(_compat_linux, OID_AUTO, osname,
169 CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_MPSAFE,
170 0, 0, linux_sysctl_osname, "A",
171 "Linux kernel OS name");
174 linux_sysctl_osrelease(SYSCTL_HANDLER_ARGS)
176 char osrelease[LINUX_MAX_UTSNAME];
179 LIN_SDT_PROBE0(mib, linux_sysctl_osrelease, entry);
181 linux_get_osrelease(req->td, osrelease);
182 error = sysctl_handle_string(oidp, osrelease, LINUX_MAX_UTSNAME, req);
183 if (error != 0 || req->newptr == NULL) {
184 LIN_SDT_PROBE1(mib, linux_sysctl_osrelease, sysctl_string_error,
186 LIN_SDT_PROBE1(mib, linux_sysctl_osrelease, return, error);
189 error = linux_set_osrelease(req->td, osrelease);
191 LIN_SDT_PROBE1(mib, linux_sysctl_osrelease, return, error);
195 SYSCTL_PROC(_compat_linux, OID_AUTO, osrelease,
196 CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_MPSAFE,
197 0, 0, linux_sysctl_osrelease, "A",
198 "Linux kernel OS release");
201 linux_sysctl_oss_version(SYSCTL_HANDLER_ARGS)
206 LIN_SDT_PROBE0(mib, linux_sysctl_oss_version, entry);
208 oss_version = linux_get_oss_version(req->td);
209 error = sysctl_handle_int(oidp, &oss_version, 0, req);
210 if (error != 0 || req->newptr == NULL) {
211 LIN_SDT_PROBE1(mib, linux_sysctl_oss_version,
212 sysctl_string_error, error);
213 LIN_SDT_PROBE1(mib, linux_sysctl_oss_version, return, error);
216 error = linux_set_oss_version(req->td, oss_version);
218 LIN_SDT_PROBE1(mib, linux_sysctl_oss_version, return, error);
222 SYSCTL_PROC(_compat_linux, OID_AUTO, oss_version,
223 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_MPSAFE,
224 0, 0, linux_sysctl_oss_version, "I",
225 "Linux OSS version");
228 * Map the osrelease into integer
231 linux_map_osrel(char *osrelease, int *osrel)
233 char *sep, *eosrelease;
234 int len, v0, v1, v2, v;
236 LIN_SDT_PROBE2(mib, linux_map_osrel, entry, osrelease, osrel);
238 len = strlen(osrelease);
239 eosrelease = osrelease + len;
240 v0 = strtol(osrelease, &sep, 10);
241 if (osrelease == sep || sep + 1 >= eosrelease || *sep != '.') {
242 LIN_SDT_PROBE1(mib, linux_map_osrel, return, EINVAL);
246 v1 = strtol(osrelease, &sep, 10);
247 if (osrelease == sep || sep + 1 >= eosrelease || *sep != '.') {
248 LIN_SDT_PROBE1(mib, linux_map_osrel, return, EINVAL);
252 v2 = strtol(osrelease, &sep, 10);
253 if (osrelease == sep || sep != eosrelease) {
254 LIN_SDT_PROBE1(mib, linux_map_osrel, return, EINVAL);
258 v = v0 * 1000000 + v1 * 1000 + v2;
260 LIN_SDT_PROBE1(mib, linux_map_osrel, return, EINVAL);
266 LIN_SDT_PROBE1(mib, linux_map_osrel, return, 0);
271 * Find a prison with Linux info.
272 * Return the Linux info and the (locked) prison.
274 static struct linux_prison *
275 linux_find_prison(struct prison *spr, struct prison **prp)
278 struct linux_prison *lpr;
280 LIN_SDT_PROBE2(mib, linux_get_prison, entry, spr, prp);
282 if (!linux_osd_jail_slot)
283 /* In case osd_register failed. */
285 for (pr = spr;; pr = pr->pr_parent) {
286 mtx_lock(&pr->pr_mtx);
287 lpr = (pr == &prison0)
289 : osd_jail_get(pr, linux_osd_jail_slot);
292 mtx_unlock(&pr->pr_mtx);
296 LIN_SDT_PROBE1(mib, linux_get_prison, return, lpr);
301 * Ensure a prison has its own Linux info. If lprp is non-null, point it to
302 * the Linux info and lock the prison.
305 linux_alloc_prison(struct prison *pr, struct linux_prison **lprp)
308 struct linux_prison *lpr, *nlpr;
311 LIN_SDT_PROBE2(mib, linux_alloc_prison, entry, pr, lprp);
313 /* If this prison already has Linux info, return that. */
315 lpr = linux_find_prison(pr, &ppr);
319 * Allocate a new info record. Then check again, in case something
320 * changed during the allocation.
322 mtx_unlock(&ppr->pr_mtx);
323 nlpr = malloc(sizeof(struct linux_prison), M_PRISON, M_WAITOK);
324 lpr = linux_find_prison(pr, &ppr);
326 free(nlpr, M_PRISON);
329 /* Inherit the initial values from the ancestor. */
330 mtx_lock(&pr->pr_mtx);
331 error = osd_jail_set(pr, linux_osd_jail_slot, nlpr);
333 bcopy(lpr, nlpr, sizeof(*lpr));
336 free(nlpr, M_PRISON);
339 mtx_unlock(&ppr->pr_mtx);
344 mtx_unlock(&pr->pr_mtx);
346 LIN_SDT_PROBE1(mib, linux_alloc_prison, return, error);
351 * Jail OSD methods for Linux prison data.
354 linux_prison_create(void *obj, void *data)
356 struct prison *pr = obj;
357 struct vfsoptlist *opts = data;
360 LIN_SDT_PROBE2(mib, linux_prison_create, entry, obj, data);
362 error = vfs_copyopt(opts, "linux", &jsys, sizeof(jsys));
364 LIN_SDT_PROBE1(mib, linux_prison_create, vfs_copyopt_error,
366 } else if (jsys == JAIL_SYS_INHERIT) {
367 LIN_SDT_PROBE1(mib, linux_prison_create, return, 0);
371 * Inherit a prison's initial values from its parent
372 * (different from JAIL_SYS_INHERIT which also inherits changes).
374 error = linux_alloc_prison(pr, NULL);
376 LIN_SDT_PROBE1(mib, linux_prison_create, return, error);
381 linux_prison_check(void *obj __unused, void *data)
383 struct vfsoptlist *opts = data;
384 char *osname, *osrelease;
385 int error, jsys, len, osrel, oss_version;
387 LIN_SDT_PROBE2(mib, linux_prison_check, entry, obj, data);
389 /* Check that the parameters are correct. */
390 error = vfs_copyopt(opts, "linux", &jsys, sizeof(jsys));
392 LIN_SDT_PROBE1(mib, linux_prison_check, vfs_copyopt_error,
395 if (error != ENOENT) {
397 LIN_SDT_PROBE1(mib, linux_prison_check, return, error);
400 if (jsys != JAIL_SYS_NEW && jsys != JAIL_SYS_INHERIT) {
401 LIN_SDT_PROBE1(mib, linux_prison_check, return, EINVAL);
405 error = vfs_getopt(opts, "linux.osname", (void **)&osname, &len);
407 LIN_SDT_PROBE1(mib, linux_prison_check, vfs_getopt_error,
410 if (error != ENOENT) {
412 LIN_SDT_PROBE1(mib, linux_prison_check, return, error);
415 if (len == 0 || osname[len - 1] != '\0') {
416 LIN_SDT_PROBE1(mib, linux_prison_check, return, EINVAL);
419 if (len > LINUX_MAX_UTSNAME) {
420 vfs_opterror(opts, "linux.osname too long");
421 LIN_SDT_PROBE1(mib, linux_prison_check, return,
423 return (ENAMETOOLONG);
426 error = vfs_getopt(opts, "linux.osrelease", (void **)&osrelease, &len);
428 LIN_SDT_PROBE1(mib, linux_prison_check, vfs_getopt_error,
431 if (error != ENOENT) {
433 LIN_SDT_PROBE1(mib, linux_prison_check, return, error);
436 if (len == 0 || osrelease[len - 1] != '\0') {
437 LIN_SDT_PROBE1(mib, linux_prison_check, return, EINVAL);
440 if (len > LINUX_MAX_UTSNAME) {
441 vfs_opterror(opts, "linux.osrelease too long");
442 LIN_SDT_PROBE1(mib, linux_prison_check, return,
444 return (ENAMETOOLONG);
446 error = linux_map_osrel(osrelease, &osrel);
448 vfs_opterror(opts, "linux.osrelease format error");
449 LIN_SDT_PROBE1(mib, linux_prison_check, return, error);
453 error = vfs_copyopt(opts, "linux.oss_version", &oss_version,
454 sizeof(oss_version));
456 LIN_SDT_PROBE1(mib, linux_prison_check, vfs_copyopt_error, error);
460 LIN_SDT_PROBE1(mib, linux_prison_check, return, error);
465 linux_prison_set(void *obj, void *data)
467 struct linux_prison *lpr;
468 struct prison *pr = obj;
469 struct vfsoptlist *opts = data;
470 char *osname, *osrelease;
471 int error, gotversion, jsys, len, oss_version;
473 LIN_SDT_PROBE2(mib, linux_prison_set, entry, obj, data);
475 /* Set the parameters, which should be correct. */
476 error = vfs_copyopt(opts, "linux", &jsys, sizeof(jsys));
478 LIN_SDT_PROBE1(mib, linux_prison_set, vfs_copyopt_error, error);
481 error = vfs_getopt(opts, "linux.osname", (void **)&osname, &len);
483 LIN_SDT_PROBE1(mib, linux_prison_set, vfs_getopt_error, error);
488 error = vfs_getopt(opts, "linux.osrelease", (void **)&osrelease, &len);
490 LIN_SDT_PROBE1(mib, linux_prison_set, vfs_getopt_error, error);
495 error = vfs_copyopt(opts, "linux.oss_version", &oss_version,
496 sizeof(oss_version));
498 LIN_SDT_PROBE1(mib, linux_prison_set, vfs_copyopt_error, error);
506 case JAIL_SYS_INHERIT:
507 /* "linux=inherit": inherit the parent's Linux info. */
508 mtx_lock(&pr->pr_mtx);
509 osd_jail_del(pr, linux_osd_jail_slot);
510 mtx_unlock(&pr->pr_mtx);
514 * "linux=new" or "linux.*":
515 * the prison gets its own Linux info.
517 error = linux_alloc_prison(pr, &lpr);
519 mtx_unlock(&pr->pr_mtx);
520 LIN_SDT_PROBE1(mib, linux_prison_set, return, error);
524 error = linux_map_osrel(osrelease, &lpr->pr_osrel);
526 mtx_unlock(&pr->pr_mtx);
527 LIN_SDT_PROBE1(mib, linux_prison_set, return,
531 strlcpy(lpr->pr_osrelease, osrelease,
535 strlcpy(lpr->pr_osname, osname, LINUX_MAX_UTSNAME);
537 lpr->pr_oss_version = oss_version;
538 mtx_unlock(&pr->pr_mtx);
541 LIN_SDT_PROBE1(mib, linux_prison_set, return, 0);
545 SYSCTL_JAIL_PARAM_SYS_NODE(linux, CTLFLAG_RW, "Jail Linux parameters");
546 SYSCTL_JAIL_PARAM_STRING(_linux, osname, CTLFLAG_RW, LINUX_MAX_UTSNAME,
547 "Jail Linux kernel OS name");
548 SYSCTL_JAIL_PARAM_STRING(_linux, osrelease, CTLFLAG_RW, LINUX_MAX_UTSNAME,
549 "Jail Linux kernel OS release");
550 SYSCTL_JAIL_PARAM(_linux, oss_version, CTLTYPE_INT | CTLFLAG_RW,
551 "I", "Jail Linux OSS version");
554 linux_prison_get(void *obj, void *data)
556 struct linux_prison *lpr;
558 struct prison *pr = obj;
559 struct vfsoptlist *opts = data;
564 LIN_SDT_PROBE2(mib, linux_prison_get, entry, obj, data);
566 /* See if this prison is the one with the Linux info. */
567 lpr = linux_find_prison(pr, &ppr);
568 i = (ppr == pr) ? JAIL_SYS_NEW : JAIL_SYS_INHERIT;
569 error = vfs_setopt(opts, "linux", &i, sizeof(i));
571 LIN_SDT_PROBE1(mib, linux_prison_get, vfs_setopt_error, error);
576 error = vfs_setopts(opts, "linux.osname", lpr->pr_osname);
578 LIN_SDT_PROBE1(mib, linux_prison_get, vfs_setopts_error,
583 error = vfs_setopts(opts, "linux.osrelease", lpr->pr_osrelease);
585 LIN_SDT_PROBE1(mib, linux_prison_get, vfs_setopts_error,
590 error = vfs_setopt(opts, "linux.oss_version",
591 &lpr->pr_oss_version, sizeof(lpr->pr_oss_version));
593 LIN_SDT_PROBE1(mib, linux_prison_get, vfs_setopt_error,
600 * If this prison is inheriting its Linux info, report
601 * empty/zero parameters.
603 error = vfs_setopts(opts, "linux.osname", "");
605 LIN_SDT_PROBE1(mib, linux_prison_get, vfs_setopts_error,
610 error = vfs_setopts(opts, "linux.osrelease", "");
612 LIN_SDT_PROBE1(mib, linux_prison_get, vfs_setopts_error,
617 error = vfs_setopt(opts, "linux.oss_version", &version0,
618 sizeof(lpr->pr_oss_version));
620 LIN_SDT_PROBE1(mib, linux_prison_get, vfs_setopt_error,
629 mtx_unlock(&ppr->pr_mtx);
631 LIN_SDT_PROBE1(mib, linux_prison_get, return, error);
636 linux_prison_destructor(void *data)
639 LIN_SDT_PROBE1(mib, linux_prison_destructor, entry, data);
640 free(data, M_PRISON);
641 LIN_SDT_PROBE0(mib, linux_prison_destructor, return);
645 linux_osd_jail_register(void)
648 osd_method_t methods[PR_MAXMETHOD] = {
649 [PR_METHOD_CREATE] = linux_prison_create,
650 [PR_METHOD_GET] = linux_prison_get,
651 [PR_METHOD_SET] = linux_prison_set,
652 [PR_METHOD_CHECK] = linux_prison_check
655 LIN_SDT_PROBE0(mib, linux_osd_jail_register, entry);
657 linux_osd_jail_slot =
658 osd_jail_register(linux_prison_destructor, methods);
659 if (linux_osd_jail_slot > 0) {
660 /* Copy the system linux info to any current prisons. */
661 sx_xlock(&allprison_lock);
662 TAILQ_FOREACH(pr, &allprison, pr_list)
663 (void)linux_alloc_prison(pr, NULL);
664 sx_xunlock(&allprison_lock);
667 LIN_SDT_PROBE0(mib, linux_osd_jail_register, return);
671 linux_osd_jail_deregister(void)
674 LIN_SDT_PROBE0(mib, linux_osd_jail_register, entry);
676 if (linux_osd_jail_slot)
677 osd_jail_deregister(linux_osd_jail_slot);
679 LIN_SDT_PROBE0(mib, linux_osd_jail_register, return);
683 linux_get_osname(struct thread *td, char *dst)
686 struct linux_prison *lpr;
688 LIN_SDT_PROBE2(mib, linux_get_osname, entry, td, dst);
690 lpr = linux_find_prison(td->td_ucred->cr_prison, &pr);
691 bcopy(lpr->pr_osname, dst, LINUX_MAX_UTSNAME);
692 mtx_unlock(&pr->pr_mtx);
694 LIN_SDT_PROBE0(mib, linux_get_osname, return);
698 linux_set_osname(struct thread *td, char *osname)
701 struct linux_prison *lpr;
703 LIN_SDT_PROBE2(mib, linux_set_osname, entry, td, osname);
705 lpr = linux_find_prison(td->td_ucred->cr_prison, &pr);
706 strlcpy(lpr->pr_osname, osname, LINUX_MAX_UTSNAME);
707 mtx_unlock(&pr->pr_mtx);
709 LIN_SDT_PROBE1(mib, linux_set_osname, return, 0);
714 linux_get_osrelease(struct thread *td, char *dst)
717 struct linux_prison *lpr;
719 LIN_SDT_PROBE2(mib, linux_get_osrelease, entry, td, dst);
721 lpr = linux_find_prison(td->td_ucred->cr_prison, &pr);
722 bcopy(lpr->pr_osrelease, dst, LINUX_MAX_UTSNAME);
723 mtx_unlock(&pr->pr_mtx);
725 LIN_SDT_PROBE0(mib, linux_get_osrelease, return);
729 linux_kernver(struct thread *td)
732 struct linux_prison *lpr;
735 LIN_SDT_PROBE1(mib, linux_kernver, entry, td);
737 lpr = linux_find_prison(td->td_ucred->cr_prison, &pr);
738 osrel = lpr->pr_osrel;
739 mtx_unlock(&pr->pr_mtx);
741 LIN_SDT_PROBE1(mib, linux_kernver, return, osrel);
746 linux_set_osrelease(struct thread *td, char *osrelease)
749 struct linux_prison *lpr;
752 LIN_SDT_PROBE2(mib, linux_set_osrelease, entry, td, osrelease);
754 lpr = linux_find_prison(td->td_ucred->cr_prison, &pr);
755 error = linux_map_osrel(osrelease, &lpr->pr_osrel);
757 strlcpy(lpr->pr_osrelease, osrelease, LINUX_MAX_UTSNAME);
758 mtx_unlock(&pr->pr_mtx);
760 LIN_SDT_PROBE1(mib, linux_set_osrelease, return, error);
765 linux_get_oss_version(struct thread *td)
768 struct linux_prison *lpr;
771 LIN_SDT_PROBE1(mib, linux_get_oss_version, entry, td);
773 lpr = linux_find_prison(td->td_ucred->cr_prison, &pr);
774 version = lpr->pr_oss_version;
775 mtx_unlock(&pr->pr_mtx);
777 LIN_SDT_PROBE1(mib, linux_get_oss_version, return, version);
782 linux_set_oss_version(struct thread *td, int oss_version)
785 struct linux_prison *lpr;
787 LIN_SDT_PROBE2(mib, linux_set_oss_version, entry, td, oss_version);
789 lpr = linux_find_prison(td->td_ucred->cr_prison, &pr);
790 lpr->pr_oss_version = oss_version;
791 mtx_unlock(&pr->pr_mtx);
793 LIN_SDT_PROBE1(mib, linux_set_oss_version, return, 0);
797 #if defined(DEBUG) || defined(KTR)
798 /* XXX: can be removed when every ldebug(...) and KTR stuff are removed. */
800 u_char linux_debug_map[howmany(LINUX_SYS_MAXSYSCALL, sizeof(u_char))];
803 linux_debug(int syscall, int toggle, int global)
807 char c = toggle ? 0 : 0xff;
809 memset(linux_debug_map, c, sizeof(linux_debug_map));
812 if (syscall < 0 || syscall >= LINUX_SYS_MAXSYSCALL)
815 clrbit(linux_debug_map, syscall);
817 setbit(linux_debug_map, syscall);
822 * Usage: sysctl linux.debug=<syscall_nr>.<0/1>
824 * E.g.: sysctl linux.debug=21.0
826 * As a special case, syscall "all" will apply to all syscalls globally.
828 #define LINUX_MAX_DEBUGSTR 16
830 linux_sysctl_debug(SYSCTL_HANDLER_ARGS)
832 char value[LINUX_MAX_DEBUGSTR], *p;
833 int error, sysc, toggle;
837 error = sysctl_handle_string(oidp, value, LINUX_MAX_DEBUGSTR, req);
838 if (error || req->newptr == NULL)
840 for (p = value; *p != '\0' && *p != '.'; p++);
844 sysc = strtol(value, NULL, 0);
845 toggle = strtol(p, NULL, 0);
846 if (strcmp(value, "all") == 0)
848 error = linux_debug(sysc, toggle, global);
852 SYSCTL_PROC(_compat_linux, OID_AUTO, debug,
853 CTLTYPE_STRING | CTLFLAG_RW,
854 0, 0, linux_sysctl_debug, "A",
855 "Linux debugging control");
857 #endif /* DEBUG || KTR */