1/*- 2 * Copyright (c) 1999 Marcel Moolenaar 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 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. 16 * 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. 27 */ 28 29#include <sys/cdefs.h>
|
30__FBSDID("$FreeBSD: head/sys/compat/linux/linux_mib.c 191972 2009-05-10 18:27:20Z dchagin $");
|
30__FBSDID("$FreeBSD: head/sys/compat/linux/linux_mib.c 192895 2009-05-27 14:11:23Z jamie $"); |
31 32#include <sys/param.h> 33#include <sys/kernel.h> 34#include <sys/systm.h> 35#include <sys/sysctl.h> 36#include <sys/proc.h> 37#include <sys/malloc.h> 38#include <sys/mount.h> 39#include <sys/jail.h> 40#include <sys/lock.h> 41#include <sys/mutex.h> 42#include <sys/sx.h> 43 44#include "opt_compat.h" 45 46#ifdef COMPAT_LINUX32 47#include <machine/../linux32/linux.h> 48#else 49#include <machine/../linux/linux.h> 50#endif 51#include <compat/linux/linux_mib.h> 52 53struct linux_prison { 54 char pr_osname[LINUX_MAX_UTSNAME]; 55 char pr_osrelease[LINUX_MAX_UTSNAME]; 56 int pr_oss_version; 57 int pr_osrel; 58}; 59
|
60static struct linux_prison lprison0 = { 61 .pr_osname = "Linux", 62 .pr_osrelease = "2.6.16", 63 .pr_oss_version = 0x030600, 64 .pr_osrel = 2006016 65}; 66 |
67static unsigned linux_osd_jail_slot; 68 69SYSCTL_NODE(_compat, OID_AUTO, linux, CTLFLAG_RW, 0, 70 "Linux mode"); 71
|
65static struct mtx osname_lock;
66MTX_SYSINIT(linux_osname, &osname_lock, "linux osname", MTX_DEF);
67
68static char linux_osname[LINUX_MAX_UTSNAME] = "Linux";
69
|
72static int 73linux_sysctl_osname(SYSCTL_HANDLER_ARGS) 74{ 75 char osname[LINUX_MAX_UTSNAME]; 76 int error; 77 78 linux_get_osname(req->td, osname); 79 error = sysctl_handle_string(oidp, osname, LINUX_MAX_UTSNAME, req); 80 if (error || req->newptr == NULL) 81 return (error); 82 error = linux_set_osname(req->td, osname); 83 return (error); 84} 85 86SYSCTL_PROC(_compat_linux, OID_AUTO, osname, 87 CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_MPSAFE, 88 0, 0, linux_sysctl_osname, "A", 89 "Linux kernel OS name"); 90
|
89static char linux_osrelease[LINUX_MAX_UTSNAME] = "2.6.16";
90static int linux_osrel = 2006016;
91
|
91static int 92linux_sysctl_osrelease(SYSCTL_HANDLER_ARGS) 93{ 94 char osrelease[LINUX_MAX_UTSNAME]; 95 int error; 96 97 linux_get_osrelease(req->td, osrelease); 98 error = sysctl_handle_string(oidp, osrelease, LINUX_MAX_UTSNAME, req); 99 if (error || req->newptr == NULL) 100 return (error); 101 error = linux_set_osrelease(req->td, osrelease); 102 return (error); 103} 104 105SYSCTL_PROC(_compat_linux, OID_AUTO, osrelease, 106 CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_MPSAFE, 107 0, 0, linux_sysctl_osrelease, "A", 108 "Linux kernel OS release"); 109
|
111static int linux_oss_version = 0x030600;
112
|
110static int 111linux_sysctl_oss_version(SYSCTL_HANDLER_ARGS) 112{ 113 int oss_version; 114 int error; 115 116 oss_version = linux_get_oss_version(req->td); 117 error = sysctl_handle_int(oidp, &oss_version, 0, req); 118 if (error || req->newptr == NULL) 119 return (error); 120 error = linux_set_oss_version(req->td, oss_version); 121 return (error); 122} 123 124SYSCTL_PROC(_compat_linux, OID_AUTO, oss_version, 125 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_MPSAFE, 126 0, 0, linux_sysctl_oss_version, "I", 127 "Linux OSS version"); 128 129/* 130 * Map the osrelease into integer 131 */ 132static int 133linux_map_osrel(char *osrelease, int *osrel) 134{ 135 char *sep, *eosrelease; 136 int len, v0, v1, v2, v; 137 138 len = strlen(osrelease); 139 eosrelease = osrelease + len; 140 v0 = strtol(osrelease, &sep, 10); 141 if (osrelease == sep || sep + 1 >= eosrelease || *sep != '.') 142 return (EINVAL); 143 osrelease = sep + 1; 144 v1 = strtol(osrelease, &sep, 10); 145 if (osrelease == sep || sep + 1 >= eosrelease || *sep != '.') 146 return (EINVAL); 147 osrelease = sep + 1; 148 v2 = strtol(osrelease, &sep, 10); 149 if (osrelease == sep || sep != eosrelease) 150 return (EINVAL); 151 152 v = v0 * 1000000 + v1 * 1000 + v2; 153 if (v < 1000000) 154 return (EINVAL); 155 156 *osrel = v; 157 return (0); 158} 159 160/*
|
164 * Returns holding the prison mutex if return non-NULL.
|
161 * Find a prison with Linux info. 162 * Return the Linux info and the (locked) prison. |
163 */ 164static struct linux_prison *
|
167linux_get_prison(struct thread *td, struct prison **prp)
|
165linux_find_prison(struct prison *spr, struct prison **prp) |
166{ 167 struct prison *pr; 168 struct linux_prison *lpr; 169
|
172 KASSERT(td == curthread, ("linux_get_prison() called on !curthread"));
173 *prp = pr = td->td_ucred->cr_prison;
174 if (pr == NULL || !linux_osd_jail_slot)
175 return (NULL);
176 mtx_lock(&pr->pr_mtx);
177 lpr = osd_jail_get(pr, linux_osd_jail_slot);
178 if (lpr == NULL)
|
170 if (!linux_osd_jail_slot) 171 /* In case osd_register failed. */ 172 spr = &prison0; 173 for (pr = spr;; pr = pr->pr_parent) { 174 mtx_lock(&pr->pr_mtx); 175 lpr = (pr == &prison0) 176 ? &lprison0 177 : osd_jail_get(pr, linux_osd_jail_slot); 178 if (lpr != NULL) 179 break; |
180 mtx_unlock(&pr->pr_mtx);
|
181 } 182 *prp = pr; |
183 return (lpr); 184} 185 186/*
|
184 * Ensure a prison has its own Linux info. The prison should be locked on
185 * entrance and will be locked on exit (though it may get unlocked in the
186 * interrim).
|
187 * Ensure a prison has its own Linux info. If lprp is non-null, point it to 188 * the Linux info and lock the prison. |
189 */ 190static int 191linux_alloc_prison(struct prison *pr, struct linux_prison **lprp) 192{
|
193 struct prison *ppr; |
194 struct linux_prison *lpr, *nlpr; 195 int error; 196 197 /* If this prison already has Linux info, return that. */ 198 error = 0;
|
196 mtx_assert(&pr->pr_mtx, MA_OWNED);
197 lpr = osd_jail_get(pr, linux_osd_jail_slot);
198 if (lpr != NULL)
|
199 lpr = linux_find_prison(pr, &ppr); 200 if (ppr == pr) |
201 goto done; 202 /* 203 * Allocate a new info record. Then check again, in case something 204 * changed during the allocation. 205 */
|
204 mtx_unlock(&pr->pr_mtx);
|
206 mtx_unlock(&ppr->pr_mtx); |
207 nlpr = malloc(sizeof(struct linux_prison), M_PRISON, M_WAITOK);
|
206 mtx_lock(&pr->pr_mtx);
207 lpr = osd_jail_get(pr, linux_osd_jail_slot);
208 if (lpr != NULL) {
|
208 lpr = linux_find_prison(pr, &ppr); 209 if (ppr == pr) { |
210 free(nlpr, M_PRISON); 211 goto done; 212 }
|
213 /* Inherit the initial values from the ancestor. */ 214 mtx_lock(&pr->pr_mtx); |
215 error = osd_jail_set(pr, linux_osd_jail_slot, nlpr);
|
213 if (error)
214 free(nlpr, M_PRISON);
215 else {
|
216 if (error == 0) { 217 bcopy(lpr, nlpr, sizeof(*lpr)); |
218 lpr = nlpr;
|
217 mtx_lock(&osname_lock);
218 strncpy(lpr->pr_osname, linux_osname, LINUX_MAX_UTSNAME);
219 strncpy(lpr->pr_osrelease, linux_osrelease, LINUX_MAX_UTSNAME);
220 lpr->pr_oss_version = linux_oss_version;
221 lpr->pr_osrel = linux_osrel;
222 mtx_unlock(&osname_lock);
|
219 } else { 220 free(nlpr, M_PRISON); 221 lpr = NULL; |
222 }
|
224done:
|
223 mtx_unlock(&ppr->pr_mtx); 224 done: |
225 if (lprp != NULL) 226 *lprp = lpr;
|
227 else 228 mtx_unlock(&pr->pr_mtx); |
229 return (error); 230} 231 232/* 233 * Jail OSD methods for Linux prison data. 234 */ 235static int 236linux_prison_create(void *obj, void *data) 237{
|
236 int error;
|
238 struct prison *pr = obj; 239 struct vfsoptlist *opts = data; 240 241 if (vfs_flagopt(opts, "nolinux", NULL, 0)) 242 return (0); 243 /* 244 * Inherit a prison's initial values from its parent 245 * (different from NULL which also inherits changes). 246 */
|
246 mtx_lock(&pr->pr_mtx);
247 error = linux_alloc_prison(pr, NULL);
248 mtx_unlock(&pr->pr_mtx);
249 return (error);
|
247 return linux_alloc_prison(pr, NULL); |
248} 249 250static int 251linux_prison_check(void *obj __unused, void *data) 252{ 253 struct vfsoptlist *opts = data; 254 char *osname, *osrelease;
|
257 int error, len, oss_version;
|
255 int error, len, osrel, oss_version; |
256 257 /* Check that the parameters are correct. */ 258 (void)vfs_flagopt(opts, "linux", NULL, 0); 259 (void)vfs_flagopt(opts, "nolinux", NULL, 0); 260 error = vfs_getopt(opts, "linux.osname", (void **)&osname, &len); 261 if (error != ENOENT) { 262 if (error != 0) 263 return (error); 264 if (len == 0 || osname[len - 1] != '\0') 265 return (EINVAL); 266 if (len > LINUX_MAX_UTSNAME) { 267 vfs_opterror(opts, "linux.osname too long"); 268 return (ENAMETOOLONG); 269 } 270 } 271 error = vfs_getopt(opts, "linux.osrelease", (void **)&osrelease, &len); 272 if (error != ENOENT) { 273 if (error != 0) 274 return (error); 275 if (len == 0 || osrelease[len - 1] != '\0') 276 return (EINVAL); 277 if (len > LINUX_MAX_UTSNAME) { 278 vfs_opterror(opts, "linux.osrelease too long"); 279 return (ENAMETOOLONG); 280 }
|
281 error = linux_map_osrel(osrelease, &osrel); 282 if (error != 0) { 283 vfs_opterror(opts, "linux.osrelease format error"); 284 return (error); 285 } |
286 } 287 error = vfs_copyopt(opts, "linux.oss_version", &oss_version, 288 sizeof(oss_version)); 289 return (error == ENOENT ? 0 : error); 290} 291 292static int 293linux_prison_set(void *obj, void *data) 294{ 295 struct linux_prison *lpr; 296 struct prison *pr = obj; 297 struct vfsoptlist *opts = data; 298 char *osname, *osrelease; 299 int error, gotversion, len, nolinux, oss_version, yeslinux; 300 301 /* Set the parameters, which should be correct. */ 302 yeslinux = vfs_flagopt(opts, "linux", NULL, 0); 303 nolinux = vfs_flagopt(opts, "nolinux", NULL, 0); 304 error = vfs_getopt(opts, "linux.osname", (void **)&osname, &len); 305 if (error == ENOENT) 306 osname = NULL; 307 else 308 yeslinux = 1; 309 error = vfs_getopt(opts, "linux.osrelease", (void **)&osrelease, &len); 310 if (error == ENOENT) 311 osrelease = NULL; 312 else 313 yeslinux = 1; 314 error = vfs_copyopt(opts, "linux.oss_version", &oss_version, 315 sizeof(oss_version));
|
313 gotversion = error == 0;
|
316 gotversion = (error == 0); |
317 yeslinux |= gotversion; 318 if (nolinux) { 319 /* "nolinux": inherit the parent's Linux info. */ 320 mtx_lock(&pr->pr_mtx); 321 osd_jail_del(pr, linux_osd_jail_slot); 322 mtx_unlock(&pr->pr_mtx); 323 } else if (yeslinux) { 324 /* 325 * "linux" or "linux.*": 326 * the prison gets its own Linux info. 327 */
|
325 mtx_lock(&pr->pr_mtx);
|
328 error = linux_alloc_prison(pr, &lpr); 329 if (error) { 330 mtx_unlock(&pr->pr_mtx); 331 return (error); 332 } 333 if (osrelease) { 334 error = linux_map_osrel(osrelease, &lpr->pr_osrel); 335 if (error) { 336 mtx_unlock(&pr->pr_mtx); 337 return (error); 338 } 339 strlcpy(lpr->pr_osrelease, osrelease, 340 LINUX_MAX_UTSNAME); 341 } 342 if (osname) 343 strlcpy(lpr->pr_osname, osname, LINUX_MAX_UTSNAME); 344 if (gotversion) 345 lpr->pr_oss_version = oss_version; 346 mtx_unlock(&pr->pr_mtx); 347 } 348 return (0); 349} 350 351SYSCTL_JAIL_PARAM_NODE(linux, "Jail Linux parameters"); 352SYSCTL_JAIL_PARAM(, nolinux, CTLTYPE_INT | CTLFLAG_RW, 353 "BN", "Jail w/ no Linux parameters"); 354SYSCTL_JAIL_PARAM_STRING(_linux, osname, CTLFLAG_RW, LINUX_MAX_UTSNAME, 355 "Jail Linux kernel OS name"); 356SYSCTL_JAIL_PARAM_STRING(_linux, osrelease, CTLFLAG_RW, LINUX_MAX_UTSNAME, 357 "Jail Linux kernel OS release"); 358SYSCTL_JAIL_PARAM(_linux, oss_version, CTLTYPE_INT | CTLFLAG_RW, 359 "I", "Jail Linux OSS version"); 360 361static int 362linux_prison_get(void *obj, void *data) 363{ 364 struct linux_prison *lpr;
|
365 struct prison *ppr; |
366 struct prison *pr = obj; 367 struct vfsoptlist *opts = data; 368 int error, i; 369
|
367 mtx_lock(&pr->pr_mtx);
368 /* Tell whether this prison has its own Linux info. */
369 lpr = osd_jail_get(pr, linux_osd_jail_slot);
370 i = lpr != NULL;
|
370 static int version0; 371 372 /* See if this prison is the one with the Linux info. */ 373 lpr = linux_find_prison(pr, &ppr); 374 i = (ppr == pr); |
375 error = vfs_setopt(opts, "linux", &i, sizeof(i)); 376 if (error != 0 && error != ENOENT) 377 goto done; 378 i = !i; 379 error = vfs_setopt(opts, "nolinux", &i, sizeof(i)); 380 if (error != 0 && error != ENOENT) 381 goto done;
|
378 /*
379 * It's kind of bogus to give the root info, but leave it to the caller
380 * to check the above flag.
381 */
382 if (lpr != NULL) {
383 error = vfs_setopts(opts, "linux.osname", lpr->pr_osname);
|
382 if (i) { 383 /* 384 * If this prison is inheriting its Linux info, report 385 * empty/zero parameters. 386 */ 387 error = vfs_setopts(opts, "linux.osname", ""); |
388 if (error != 0 && error != ENOENT) 389 goto done;
|
386 error = vfs_setopts(opts, "linux.osrelease", lpr->pr_osrelease);
|
390 error = vfs_setopts(opts, "linux.osrelease", ""); |
391 if (error != 0 && error != ENOENT) 392 goto done;
|
389 error = vfs_setopt(opts, "linux.oss_version",
390 &lpr->pr_oss_version, sizeof(lpr->pr_oss_version));
|
393 error = vfs_setopt(opts, "linux.oss_version", &version0, 394 sizeof(lpr->pr_oss_version)); |
395 if (error != 0 && error != ENOENT) 396 goto done; 397 } else {
|
394 mtx_lock(&osname_lock);
395 error = vfs_setopts(opts, "linux.osname", linux_osname);
|
398 error = vfs_setopts(opts, "linux.osname", lpr->pr_osname); |
399 if (error != 0 && error != ENOENT) 400 goto done;
|
398 error = vfs_setopts(opts, "linux.osrelease", linux_osrelease);
|
401 error = vfs_setopts(opts, "linux.osrelease", lpr->pr_osrelease); |
402 if (error != 0 && error != ENOENT) 403 goto done; 404 error = vfs_setopt(opts, "linux.oss_version",
|
402 &linux_oss_version, sizeof(linux_oss_version));
|
405 &lpr->pr_oss_version, sizeof(lpr->pr_oss_version)); |
406 if (error != 0 && error != ENOENT) 407 goto done;
|
405 mtx_unlock(&osname_lock);
|
408 } 409 error = 0; 410 411 done:
|
410 mtx_unlock(&pr->pr_mtx);
|
412 mtx_unlock(&ppr->pr_mtx); |
413 return (error); 414} 415 416static void 417linux_prison_destructor(void *data) 418{ 419 420 free(data, M_PRISON); 421} 422 423void 424linux_osd_jail_register(void) 425{ 426 struct prison *pr; 427 osd_method_t methods[PR_MAXMETHOD] = { 428 [PR_METHOD_CREATE] = linux_prison_create, 429 [PR_METHOD_GET] = linux_prison_get, 430 [PR_METHOD_SET] = linux_prison_set, 431 [PR_METHOD_CHECK] = linux_prison_check 432 }; 433 434 linux_osd_jail_slot = 435 osd_jail_register(linux_prison_destructor, methods); 436 if (linux_osd_jail_slot > 0) { 437 /* Copy the system linux info to any current prisons. */ 438 sx_xlock(&allprison_lock);
|
437 TAILQ_FOREACH(pr, &allprison, pr_list) {
438 mtx_lock(&pr->pr_mtx);
|
439 TAILQ_FOREACH(pr, &allprison, pr_list) |
440 (void)linux_alloc_prison(pr, NULL);
|
440 mtx_unlock(&pr->pr_mtx);
441 }
|
441 sx_xunlock(&allprison_lock); 442 } 443} 444 445void 446linux_osd_jail_deregister(void) 447{ 448 449 if (linux_osd_jail_slot) 450 osd_jail_deregister(linux_osd_jail_slot); 451} 452 453void 454linux_get_osname(struct thread *td, char *dst) 455{ 456 struct prison *pr; 457 struct linux_prison *lpr; 458
|
460 lpr = linux_get_prison(td, &pr);
461 if (lpr != NULL) {
462 bcopy(lpr->pr_osname, dst, LINUX_MAX_UTSNAME);
463 mtx_unlock(&pr->pr_mtx);
464 } else {
465 mtx_lock(&osname_lock);
466 bcopy(linux_osname, dst, LINUX_MAX_UTSNAME);
467 mtx_unlock(&osname_lock);
468 }
|
459 lpr = linux_find_prison(td->td_ucred->cr_prison, &pr); 460 bcopy(lpr->pr_osname, dst, LINUX_MAX_UTSNAME); 461 mtx_unlock(&pr->pr_mtx); |
462} 463 464int 465linux_set_osname(struct thread *td, char *osname) 466{ 467 struct prison *pr; 468 struct linux_prison *lpr; 469
|
477 lpr = linux_get_prison(td, &pr);
478 if (lpr != NULL) {
479 strlcpy(lpr->pr_osname, osname, LINUX_MAX_UTSNAME);
480 mtx_unlock(&pr->pr_mtx);
481 } else {
482 mtx_lock(&osname_lock);
483 strcpy(linux_osname, osname);
484 mtx_unlock(&osname_lock);
485 }
486
|
470 lpr = linux_find_prison(td->td_ucred->cr_prison, &pr); 471 strlcpy(lpr->pr_osname, osname, LINUX_MAX_UTSNAME); 472 mtx_unlock(&pr->pr_mtx); |
473 return (0); 474} 475 476void 477linux_get_osrelease(struct thread *td, char *dst) 478{ 479 struct prison *pr; 480 struct linux_prison *lpr; 481
|
496 lpr = linux_get_prison(td, &pr);
497 if (lpr != NULL) {
498 bcopy(lpr->pr_osrelease, dst, LINUX_MAX_UTSNAME);
499 mtx_unlock(&pr->pr_mtx);
500 } else {
501 mtx_lock(&osname_lock);
502 bcopy(linux_osrelease, dst, LINUX_MAX_UTSNAME);
503 mtx_unlock(&osname_lock);
504 }
|
482 lpr = linux_find_prison(td->td_ucred->cr_prison, &pr); 483 bcopy(lpr->pr_osrelease, dst, LINUX_MAX_UTSNAME); 484 mtx_unlock(&pr->pr_mtx); |
485} 486 487int 488linux_kernver(struct thread *td) 489{ 490 struct prison *pr; 491 struct linux_prison *lpr; 492 int osrel; 493
|
514 lpr = linux_get_prison(td, &pr);
515 if (lpr != NULL) {
516 osrel = lpr->pr_osrel;
517 mtx_unlock(&pr->pr_mtx);
518 } else
519 osrel = linux_osrel;
|
494 lpr = linux_find_prison(td->td_ucred->cr_prison, &pr); 495 osrel = lpr->pr_osrel; 496 mtx_unlock(&pr->pr_mtx); |
497 return (osrel); 498} 499 500int 501linux_set_osrelease(struct thread *td, char *osrelease) 502{ 503 struct prison *pr; 504 struct linux_prison *lpr; 505 int error; 506
|
530 lpr = linux_get_prison(td, &pr);
531 if (lpr != NULL) {
532 error = linux_map_osrel(osrelease, &lpr->pr_osrel);
533 if (error) {
534 mtx_unlock(&pr->pr_mtx);
535 return (error);
536 }
|
507 lpr = linux_find_prison(td->td_ucred->cr_prison, &pr); 508 error = linux_map_osrel(osrelease, &lpr->pr_osrel); 509 if (error == 0) |
510 strlcpy(lpr->pr_osrelease, osrelease, LINUX_MAX_UTSNAME);
|
538 mtx_unlock(&pr->pr_mtx);
539 } else {
540 mtx_lock(&osname_lock);
541 error = linux_map_osrel(osrelease, &linux_osrel);
542 if (error) {
543 mtx_unlock(&osname_lock);
544 return (error);
545 }
546 strcpy(linux_osrelease, osrelease);
547 mtx_unlock(&osname_lock);
548 }
549
550 return (0);
|
511 mtx_unlock(&pr->pr_mtx); 512 return (error); |
513} 514 515int 516linux_get_oss_version(struct thread *td) 517{ 518 struct prison *pr; 519 struct linux_prison *lpr; 520 int version; 521
|
560 lpr = linux_get_prison(td, &pr);
561 if (lpr != NULL) {
562 version = lpr->pr_oss_version;
563 mtx_unlock(&pr->pr_mtx);
564 } else
565 version = linux_oss_version;
|
522 lpr = linux_find_prison(td->td_ucred->cr_prison, &pr); 523 version = lpr->pr_oss_version; 524 mtx_unlock(&pr->pr_mtx); |
525 return (version); 526} 527 528int 529linux_set_oss_version(struct thread *td, int oss_version) 530{ 531 struct prison *pr; 532 struct linux_prison *lpr; 533
|
575 lpr = linux_get_prison(td, &pr);
576 if (lpr != NULL) {
577 lpr->pr_oss_version = oss_version;
578 mtx_unlock(&pr->pr_mtx);
579 } else {
580 mtx_lock(&osname_lock);
581 linux_oss_version = oss_version;
582 mtx_unlock(&osname_lock);
583 }
584
|
534 lpr = linux_find_prison(td->td_ucred->cr_prison, &pr); 535 lpr->pr_oss_version = oss_version; 536 mtx_unlock(&pr->pr_mtx); |
537 return (0); 538} 539 540#if defined(DEBUG) || defined(KTR) 541 542u_char linux_debug_map[howmany(LINUX_SYS_MAXSYSCALL, sizeof(u_char))]; 543 544static int 545linux_debug(int syscall, int toggle, int global) 546{ 547 548 if (global) { 549 char c = toggle ? 0 : 0xff; 550 551 memset(linux_debug_map, c, sizeof(linux_debug_map)); 552 return (0); 553 } 554 if (syscall < 0 || syscall >= LINUX_SYS_MAXSYSCALL) 555 return (EINVAL); 556 if (toggle) 557 clrbit(linux_debug_map, syscall); 558 else 559 setbit(linux_debug_map, syscall); 560 return (0); 561} 562 563/* 564 * Usage: sysctl linux.debug=<syscall_nr>.<0/1> 565 * 566 * E.g.: sysctl linux.debug=21.0 567 * 568 * As a special case, syscall "all" will apply to all syscalls globally. 569 */ 570#define LINUX_MAX_DEBUGSTR 16 571static int 572linux_sysctl_debug(SYSCTL_HANDLER_ARGS) 573{ 574 char value[LINUX_MAX_DEBUGSTR], *p; 575 int error, sysc, toggle; 576 int global = 0; 577 578 value[0] = '\0'; 579 error = sysctl_handle_string(oidp, value, LINUX_MAX_DEBUGSTR, req); 580 if (error || req->newptr == NULL) 581 return (error); 582 for (p = value; *p != '\0' && *p != '.'; p++); 583 if (*p == '\0') 584 return (EINVAL); 585 *p++ = '\0'; 586 sysc = strtol(value, NULL, 0); 587 toggle = strtol(p, NULL, 0); 588 if (strcmp(value, "all") == 0) 589 global = 1; 590 error = linux_debug(sysc, toggle, global); 591 return (error); 592} 593 594SYSCTL_PROC(_compat_linux, OID_AUTO, debug, 595 CTLTYPE_STRING | CTLFLAG_RW, 596 0, 0, linux_sysctl_debug, "A", 597 "Linux debugging control"); 598 599#endif /* DEBUG || KTR */
|