Home | History | Annotate | Line # | Download | only in rumpkern
rump.c revision 1.214
      1 /*	$NetBSD: rump.c,v 1.214 2011/01/02 12:52:25 pooka Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2007 Antti Kantee.  All Rights Reserved.
      5  *
      6  * Development of this software was supported by Google Summer of Code.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above copyright
     14  *    notice, this list of conditions and the following disclaimer in the
     15  *    documentation and/or other materials provided with the distribution.
     16  *
     17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
     18  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     20  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     23  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     27  * SUCH DAMAGE.
     28  */
     29 
     30 #include <sys/cdefs.h>
     31 __KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.214 2011/01/02 12:52:25 pooka Exp $");
     32 
     33 #include <sys/systm.h>
     34 #define ELFSIZE ARCH_ELFSIZE
     35 
     36 #include <sys/param.h>
     37 #include <sys/atomic.h>
     38 #include <sys/buf.h>
     39 #include <sys/callout.h>
     40 #include <sys/conf.h>
     41 #include <sys/cpu.h>
     42 #include <sys/device.h>
     43 #include <sys/evcnt.h>
     44 #include <sys/event.h>
     45 #include <sys/exec_elf.h>
     46 #include <sys/filedesc.h>
     47 #include <sys/iostat.h>
     48 #include <sys/kauth.h>
     49 #include <sys/kernel.h>
     50 #include <sys/kmem.h>
     51 #include <sys/kprintf.h>
     52 #include <sys/kthread.h>
     53 #include <sys/ksyms.h>
     54 #include <sys/msgbuf.h>
     55 #include <sys/module.h>
     56 #include <sys/once.h>
     57 #include <sys/percpu.h>
     58 #include <sys/pipe.h>
     59 #include <sys/pool.h>
     60 #include <sys/queue.h>
     61 #include <sys/reboot.h>
     62 #include <sys/resourcevar.h>
     63 #include <sys/select.h>
     64 #include <sys/sysctl.h>
     65 #include <sys/syscall.h>
     66 #include <sys/syscallvar.h>
     67 #include <sys/timetc.h>
     68 #include <sys/tty.h>
     69 #include <sys/uidinfo.h>
     70 #include <sys/vmem.h>
     71 #include <sys/xcall.h>
     72 
     73 #include <rump/rumpuser.h>
     74 
     75 #include <secmodel/suser/suser.h>
     76 
     77 #include <prop/proplib.h>
     78 
     79 #include <uvm/uvm_extern.h>
     80 #include <uvm/uvm_readahead.h>
     81 
     82 #include "rump_private.h"
     83 #include "rump_net_private.h"
     84 #include "rump_vfs_private.h"
     85 #include "rump_dev_private.h"
     86 
     87 char machine[] = MACHINE;
     88 
     89 struct proc *initproc;
     90 
     91 struct device rump_rootdev = {
     92 	.dv_class = DV_VIRTUAL
     93 };
     94 
     95 #ifdef RUMP_WITHOUT_THREADS
     96 int rump_threads = 0;
     97 #else
     98 int rump_threads = 1;
     99 #endif
    100 
    101 static int rump_proxy_syscall(int, void *, register_t *);
    102 static int rump_proxy_rfork(void *, int);
    103 
    104 static char rump_msgbuf[16*1024]; /* 16k should be enough for std rump needs */
    105 
    106 static void
    107 rump_aiodone_worker(struct work *wk, void *dummy)
    108 {
    109 	struct buf *bp = (struct buf *)wk;
    110 
    111 	KASSERT(&bp->b_work == wk);
    112 	bp->b_iodone(bp);
    113 }
    114 
    115 static int rump_inited;
    116 
    117 /*
    118  * Make sure pnbuf_cache is available even without vfs
    119  */
    120 struct pool_cache *pnbuf_cache;
    121 int rump_initpnbufpool(void);
    122 int rump_initpnbufpool(void)
    123 {
    124 
    125         pnbuf_cache = pool_cache_init(MAXPATHLEN, 0, 0, 0, "pnbufpl",
    126 	    NULL, IPL_NONE, NULL, NULL, NULL);
    127 	return EOPNOTSUPP;
    128 }
    129 
    130 int rump__unavailable(void);
    131 int rump__unavailable() {return EOPNOTSUPP;}
    132 __weak_alias(rump_net_init,rump__unavailable);
    133 __weak_alias(rump_vfs_init,rump_initpnbufpool);
    134 __weak_alias(rump_dev_init,rump__unavailable);
    135 
    136 __weak_alias(rump_vfs_fini,rump__unavailable);
    137 
    138 __weak_alias(biodone,rump__unavailable);
    139 __weak_alias(sopoll,rump__unavailable);
    140 
    141 __weak_alias(rump_vfs_drainbufs,rump__unavailable);
    142 
    143 void rump__unavailable_vfs_panic(void);
    144 void rump__unavailable_vfs_panic() {panic("vfs component not available");}
    145 __weak_alias(usermount_common_policy,rump__unavailable_vfs_panic);
    146 
    147 /* easier to write vfs-less clients */
    148 __weak_alias(rump_pub_etfs_register,rump__unavailable);
    149 __weak_alias(rump_pub_etfs_remove,rump__unavailable);
    150 
    151 rump_proc_vfs_init_fn rump_proc_vfs_init;
    152 rump_proc_vfs_release_fn rump_proc_vfs_release;
    153 
    154 static void add_linkedin_modules(const struct modinfo *const *, size_t);
    155 
    156 static void __noinline
    157 messthestack(void)
    158 {
    159 	volatile uint32_t mess[64];
    160 	uint64_t d1, d2;
    161 	int i, error;
    162 
    163 	for (i = 0; i < 64; i++) {
    164 		rumpuser_gettime(&d1, &d2, &error);
    165 		mess[i] = d2;
    166 	}
    167 }
    168 
    169 /*
    170  * Create kern.hostname.  why only this you ask.  well, init_sysctl
    171  * is a kitchen sink in need of some gardening.  but i want to use
    172  * kern.hostname today.
    173  */
    174 static void
    175 mksysctls(void)
    176 {
    177 
    178 	sysctl_createv(NULL, 0, NULL, NULL,
    179 	    CTLFLAG_PERMANENT, CTLTYPE_NODE, "kern", NULL,
    180 	    NULL, 0, NULL, 0, CTL_KERN, CTL_EOL);
    181 
    182 	/* XXX: setting hostnamelen is missing */
    183 	sysctl_createv(NULL, 0, NULL, NULL,
    184 	    CTLFLAG_PERMANENT|CTLFLAG_READWRITE, CTLTYPE_STRING, "hostname",
    185 	    SYSCTL_DESCR("System hostname"), NULL, 0,
    186 	    &hostname, MAXHOSTNAMELEN, CTL_KERN, KERN_HOSTNAME, CTL_EOL);
    187 }
    188 
    189 /* there's no convenient kernel entry point for this, so just craft out own */
    190 static pid_t
    191 spgetpid(void)
    192 {
    193 
    194 	return curproc->p_pid;
    195 }
    196 
    197 static const struct rumpuser_sp_ops spops = {
    198 	.spop_schedule		= rump_schedule,
    199 	.spop_unschedule	= rump_unschedule,
    200 	.spop_lwproc_switch	= rump_lwproc_switch,
    201 	.spop_lwproc_release	= rump_lwproc_releaselwp,
    202 	.spop_lwproc_rfork	= rump_proxy_rfork,
    203 	.spop_lwproc_newlwp	= rump_lwproc_newlwp,
    204 	.spop_lwproc_curlwp	= rump_lwproc_curlwp,
    205 	.spop_syscall		= rump_proxy_syscall,
    206 	.spop_getpid		= spgetpid,
    207 };
    208 
    209 int
    210 rump_daemonize_begin(void)
    211 {
    212 
    213 	if (rump_inited)
    214 		return EALREADY;
    215 
    216 	return rumpuser_daemonize_begin();
    217 }
    218 
    219 int
    220 rump_daemonize_done(int error)
    221 {
    222 
    223 	return rumpuser_daemonize_done(error);
    224 }
    225 
    226 int
    227 rump__init(int rump_version)
    228 {
    229 	char buf[256];
    230 	struct timespec ts;
    231 	uint64_t sec, nsec;
    232 	struct lwp *l;
    233 	int i, numcpu;
    234 	int error;
    235 
    236 	/* not reentrant */
    237 	if (rump_inited)
    238 		return 0;
    239 	else if (rump_inited == -1)
    240 		panic("rump_init: host process restart required");
    241 	else
    242 		rump_inited = 1;
    243 
    244 	if (rumpuser_getversion() != RUMPUSER_VERSION) {
    245 		/* let's hope the ABI of rumpuser_dprintf is the same ;) */
    246 		rumpuser_dprintf("rumpuser version mismatch: %d vs. %d\n",
    247 		    rumpuser_getversion(), RUMPUSER_VERSION);
    248 		return EPROGMISMATCH;
    249 	}
    250 
    251 	if (rumpuser_getenv("RUMP_VERBOSE", buf, sizeof(buf), &error) == 0) {
    252 		if (*buf != '0')
    253 			boothowto = AB_VERBOSE;
    254 	}
    255 
    256 	if (rumpuser_getenv("RUMP_NCPU", buf, sizeof(buf), &error) == 0)
    257 		error = 0;
    258 	/* non-x86 is missing CPU_INFO_FOREACH() support */
    259 #ifdef RUMP_SMP
    260 	if (error == 0) {
    261 		numcpu = strtoll(buf, NULL, 10);
    262 		if (numcpu < 1)
    263 			numcpu = 1;
    264 	} else {
    265 		numcpu = rumpuser_getnhostcpu();
    266 	}
    267 #else
    268 	if (error == 0)
    269 		printf("NCPU limited to 1 on this machine architecture\n");
    270 	numcpu = 1;
    271 #endif
    272 	rump_cpus_bootstrap(&numcpu);
    273 
    274 	rumpuser_gettime(&sec, &nsec, &error);
    275 	boottime.tv_sec = sec;
    276 	boottime.tv_nsec = nsec;
    277 
    278 	initmsgbuf(rump_msgbuf, sizeof(rump_msgbuf));
    279 	aprint_verbose("%s%s", copyright, version);
    280 
    281 	/*
    282 	 * Seed arc4random() with a "reasonable" amount of randomness.
    283 	 * Yes, this is a quick kludge which depends on the arc4random
    284 	 * implementation.
    285 	 */
    286 	messthestack();
    287 	arc4random();
    288 
    289 	if (rump_version != RUMP_VERSION) {
    290 		printf("rump version mismatch, %d vs. %d\n",
    291 		    rump_version, RUMP_VERSION);
    292 		return EPROGMISMATCH;
    293 	}
    294 
    295 	if (rumpuser_getenv("RUMP_THREADS", buf, sizeof(buf), &error) == 0) {
    296 		rump_threads = *buf != '0';
    297 	}
    298 	rumpuser_thrinit(rump_user_schedule, rump_user_unschedule,
    299 	    rump_threads);
    300 	rump_intr_init(numcpu);
    301 	rump_tsleep_init();
    302 
    303 	/* init minimal lwp/cpu context */
    304 	l = &lwp0;
    305 	l->l_lid = 1;
    306 	l->l_cpu = l->l_target_cpu = rump_cpu;
    307 	l->l_fd = &filedesc0;
    308 	rumpuser_set_curlwp(l);
    309 
    310 	mutex_init(&tty_lock, MUTEX_DEFAULT, IPL_NONE);
    311 	rumpuser_mutex_init(&rump_giantlock);
    312 	ksyms_init();
    313 	uvm_init();
    314 	evcnt_init();
    315 
    316 	once_init();
    317 	kernconfig_lock_init();
    318 	prop_kern_init();
    319 
    320 	pool_subsystem_init();
    321 	kmem_init();
    322 
    323 	uvm_ra_init();
    324 	uao_init();
    325 
    326 	mutex_obj_init();
    327 	callout_startup();
    328 
    329 	kprintf_init();
    330 	loginit();
    331 
    332 	kauth_init();
    333 
    334 	procinit();
    335 	proc0_init();
    336 	uid_init();
    337 	chgproccnt(0, 1);
    338 
    339 	l->l_proc = &proc0;
    340 	lwp_update_creds(l);
    341 
    342 	lwpinit_specificdata();
    343 	lwp_initspecific(&lwp0);
    344 
    345 	rump_scheduler_init(numcpu);
    346 	/* revert temporary context and schedule a semireal context */
    347 	l->l_cpu = NULL;
    348 	rumpuser_set_curlwp(NULL);
    349 	initproc = &proc0; /* borrow proc0 before we get initproc started */
    350 	rump_schedule();
    351 
    352 	percpu_init();
    353 	inittimecounter();
    354 	ntp_init();
    355 
    356 	rumpuser_gettime(&sec, &nsec, &error);
    357 	ts.tv_sec = sec;
    358 	ts.tv_nsec = nsec;
    359 	tc_setclock(&ts);
    360 
    361 	/* we are mostly go.  do per-cpu subsystem init */
    362 	for (i = 0; i < numcpu; i++) {
    363 		struct cpu_info *ci = cpu_lookup(i);
    364 
    365 		/* attach non-bootstrap CPUs */
    366 		if (i > 0) {
    367 			rump_cpu_attach(ci);
    368 			ncpu++;
    369 		}
    370 
    371 		callout_init_cpu(ci);
    372 		softint_init(ci);
    373 		xc_init_cpu(ci);
    374 		pool_cache_cpu_init(ci);
    375 		selsysinit(ci);
    376 		percpu_init_cpu(ci);
    377 
    378 		aprint_verbose("cpu%d at thinair0: rump virtual cpu\n", i);
    379 	}
    380 
    381 	sysctl_init();
    382 	mksysctls();
    383 	kqueue_init();
    384 	iostat_init();
    385 	fd_sys_init();
    386 	module_init();
    387 	devsw_init();
    388 	pipe_init();
    389 	resource_init();
    390 
    391 	/* start page baroness */
    392 	if (rump_threads) {
    393 		if (kthread_create(PRI_PGDAEMON, KTHREAD_MPSAFE, NULL,
    394 		    uvm_pageout, NULL, &uvm.pagedaemon_lwp, "pdaemon") != 0)
    395 			panic("pagedaemon create failed");
    396 	} else
    397 		uvm.pagedaemon_lwp = NULL; /* doesn't match curlwp */
    398 
    399 	/* process dso's */
    400 	rumpuser_dl_bootstrap(add_linkedin_modules, rump_kernelfsym_load);
    401 
    402 	rump_component_init(RUMP_COMPONENT_KERN);
    403 
    404 	/* these do nothing if not present */
    405 	rump_vfs_init();
    406 	rump_net_init();
    407 	rump_dev_init();
    408 
    409 	rump_component_init(RUMP_COMPONENT_KERN_VFS);
    410 
    411 	cold = 0;
    412 
    413 	/* aieeeedondest */
    414 	if (rump_threads) {
    415 		if (workqueue_create(&uvm.aiodone_queue, "aiodoned",
    416 		    rump_aiodone_worker, NULL, 0, 0, WQ_MPSAFE))
    417 			panic("aiodoned");
    418 	}
    419 
    420 	sysctl_finalize();
    421 
    422 	module_init_class(MODULE_CLASS_ANY);
    423 
    424 	rumpuser_gethostname(hostname, MAXHOSTNAMELEN, &error);
    425 	hostnamelen = strlen(hostname);
    426 
    427 	sigemptyset(&sigcantmask);
    428 
    429 	if (rump_threads)
    430 		vmem_rehash_start();
    431 
    432 	/*
    433 	 * Create init, used to attach implicit threads in rump.
    434 	 * (note: must be done after vfsinit to get cwdi)
    435 	 */
    436 	(void)rump__lwproc_alloclwp(NULL); /* dummy thread for initproc */
    437 	mutex_enter(proc_lock);
    438 	initproc = proc_find_raw(1);
    439 	mutex_exit(proc_lock);
    440 	if (initproc == NULL)
    441 		panic("where in the world is initproc?");
    442 
    443 	/*
    444 	 * Adjust syscall vector in case factions were dlopen()'d
    445 	 * before calling rump_init().
    446 	 * (modules will handle dynamic syscalls the usual way)
    447 	 *
    448 	 * Note: this will adjust the function vectors of
    449 	 * syscalls which use a funcalias (getpid etc.), but
    450 	 * it makes no difference.
    451 	 */
    452 	for (i = 0; i < SYS_NSYSENT; i++) {
    453 		void *sym;
    454 
    455 		if (rump_sysent[i].sy_flags & SYCALL_NOSYS ||
    456 		    *syscallnames[i] == '#' ||
    457 		    rump_sysent[i].sy_call == sys_nomodule)
    458 			continue;
    459 
    460 		/* if present, adjust symbol value */
    461 		sprintf(buf, "rumpns_sys_%s", syscallnames[i]);
    462 		if ((sym = rumpuser_dl_globalsym(buf)) != NULL
    463 		    && sym != rump_sysent[i].sy_call) {
    464 #if 0
    465 			rumpuser_dprintf("adjusting %s: %p (old %p)\n",
    466 			    syscallnames[i], sym, rump_sysent[i].sy_call);
    467 #endif
    468 			rump_sysent[i].sy_call = sym;
    469 		}
    470 	}
    471 
    472 	/* release cpu */
    473 	rump_unschedule();
    474 
    475 	return 0;
    476 }
    477 
    478 int
    479 rump_init_server(const char *url)
    480 {
    481 
    482 	return rumpuser_sp_init(url, &spops, ostype, osrelease, MACHINE);
    483 }
    484 
    485 void
    486 cpu_reboot(int howto, char *bootstr)
    487 {
    488 	int ruhow = 0;
    489 
    490 	printf("rump kernel halting...\n");
    491 	rumpuser_sp_fini();
    492 
    493 	/* dump means we really take the dive here */
    494 	if ((howto & RB_DUMP) || panicstr) {
    495 		ruhow = RUMPUSER_PANIC;
    496 		goto out;
    497 	}
    498 
    499 	/* try to sync */
    500 	if (!((howto & RB_NOSYNC) || panicstr)) {
    501 		rump_vfs_fini();
    502 	}
    503 
    504 	/* your wish is my command */
    505 	if (howto & RB_HALT) {
    506 		printf("rump kernel halted\n");
    507 		for (;;) {
    508 			uint64_t sec = 5, nsec = 0;
    509 			int error;
    510 
    511 			rumpuser_nanosleep(&sec, &nsec, &error);
    512 		}
    513 	}
    514 
    515 	/* this function is __dead, we must exit */
    516  out:
    517 	printf("halted\n");
    518 	rumpuser_exit(ruhow);
    519 }
    520 
    521 struct uio *
    522 rump_uio_setup(void *buf, size_t bufsize, off_t offset, enum rump_uiorw rw)
    523 {
    524 	struct uio *uio;
    525 	enum uio_rw uiorw;
    526 
    527 	switch (rw) {
    528 	case RUMPUIO_READ:
    529 		uiorw = UIO_READ;
    530 		break;
    531 	case RUMPUIO_WRITE:
    532 		uiorw = UIO_WRITE;
    533 		break;
    534 	default:
    535 		panic("%s: invalid rw %d", __func__, rw);
    536 	}
    537 
    538 	uio = kmem_alloc(sizeof(struct uio), KM_SLEEP);
    539 	uio->uio_iov = kmem_alloc(sizeof(struct iovec), KM_SLEEP);
    540 
    541 	uio->uio_iov->iov_base = buf;
    542 	uio->uio_iov->iov_len = bufsize;
    543 
    544 	uio->uio_iovcnt = 1;
    545 	uio->uio_offset = offset;
    546 	uio->uio_resid = bufsize;
    547 	uio->uio_rw = uiorw;
    548 	UIO_SETUP_SYSSPACE(uio);
    549 
    550 	return uio;
    551 }
    552 
    553 size_t
    554 rump_uio_getresid(struct uio *uio)
    555 {
    556 
    557 	return uio->uio_resid;
    558 }
    559 
    560 off_t
    561 rump_uio_getoff(struct uio *uio)
    562 {
    563 
    564 	return uio->uio_offset;
    565 }
    566 
    567 size_t
    568 rump_uio_free(struct uio *uio)
    569 {
    570 	size_t resid;
    571 
    572 	resid = uio->uio_resid;
    573 	kmem_free(uio->uio_iov, sizeof(*uio->uio_iov));
    574 	kmem_free(uio, sizeof(*uio));
    575 
    576 	return resid;
    577 }
    578 
    579 kauth_cred_t
    580 rump_cred_create(uid_t uid, gid_t gid, size_t ngroups, gid_t *groups)
    581 {
    582 	kauth_cred_t cred;
    583 	int rv;
    584 
    585 	cred = kauth_cred_alloc();
    586 	kauth_cred_setuid(cred, uid);
    587 	kauth_cred_seteuid(cred, uid);
    588 	kauth_cred_setsvuid(cred, uid);
    589 	kauth_cred_setgid(cred, gid);
    590 	kauth_cred_setgid(cred, gid);
    591 	kauth_cred_setegid(cred, gid);
    592 	kauth_cred_setsvgid(cred, gid);
    593 	rv = kauth_cred_setgroups(cred, groups, ngroups, 0, UIO_SYSSPACE);
    594 	/* oh this is silly.  and by "this" I mean kauth_cred_setgroups() */
    595 	assert(rv == 0);
    596 
    597 	return cred;
    598 }
    599 
    600 void
    601 rump_cred_put(kauth_cred_t cred)
    602 {
    603 
    604 	kauth_cred_free(cred);
    605 }
    606 
    607 static int compcounter[RUMP_COMPONENT_MAX];
    608 
    609 static void
    610 rump_component_init_cb(struct rump_component *rc, int type)
    611 {
    612 
    613 	KASSERT(type < RUMP_COMPONENT_MAX);
    614 	if (rc->rc_type == type) {
    615 		rc->rc_init();
    616 		compcounter[type]++;
    617 	}
    618 }
    619 
    620 int
    621 rump_component_count(enum rump_component_type type)
    622 {
    623 
    624 	KASSERT(type <= RUMP_COMPONENT_MAX);
    625 	return compcounter[type];
    626 }
    627 
    628 void
    629 rump_component_init(enum rump_component_type type)
    630 {
    631 
    632 	rumpuser_dl_component_init(type, rump_component_init_cb);
    633 }
    634 
    635 /*
    636  * Initialize a module which has already been loaded and linked
    637  * with dlopen(). This is fundamentally the same as a builtin module.
    638  */
    639 int
    640 rump_module_init(const struct modinfo * const *mip, size_t nmodinfo)
    641 {
    642 
    643 	return module_builtin_add(mip, nmodinfo, true);
    644 }
    645 
    646 /*
    647  * Finish module (flawless victory, fatality!).
    648  */
    649 int
    650 rump_module_fini(const struct modinfo *mi)
    651 {
    652 
    653 	return module_builtin_remove(mi, true);
    654 }
    655 
    656 /*
    657  * Add loaded and linked module to the builtin list.  It will
    658  * later be initialized with module_init_class().
    659  */
    660 
    661 static void
    662 add_linkedin_modules(const struct modinfo * const *mip, size_t nmodinfo)
    663 {
    664 
    665 	module_builtin_add(mip, nmodinfo, false);
    666 }
    667 
    668 int
    669 rump_kernelfsym_load(void *symtab, uint64_t symsize,
    670 	char *strtab, uint64_t strsize)
    671 {
    672 	static int inited = 0;
    673 	Elf64_Ehdr ehdr;
    674 
    675 	if (inited)
    676 		return EBUSY;
    677 	inited = 1;
    678 
    679 	/*
    680 	 * Use 64bit header since it's bigger.  Shouldn't make a
    681 	 * difference, since we're passing in all zeroes anyway.
    682 	 */
    683 	memset(&ehdr, 0, sizeof(ehdr));
    684 	ksyms_addsyms_explicit(&ehdr, symtab, symsize, strtab, strsize);
    685 
    686 	return 0;
    687 }
    688 
    689 static int
    690 rump_proxy_syscall(int num, void *arg, register_t *retval)
    691 {
    692 	struct lwp *l;
    693 	struct sysent *callp;
    694 	int rv;
    695 
    696 	if (__predict_false(num >= SYS_NSYSENT))
    697 		return ENOSYS;
    698 
    699 	callp = rump_sysent + num;
    700 	l = curlwp;
    701 	rv = sy_call(callp, l, (void *)arg, retval);
    702 
    703 	return rv;
    704 }
    705 
    706 static int
    707 rump_proxy_rfork(void *priv, int flags)
    708 {
    709 	struct vmspace *newspace;
    710 	int error;
    711 
    712 	if ((error = rump_lwproc_rfork(flags)) != 0)
    713 		return error;
    714 
    715 	/*
    716 	 * Since it's a proxy proc, adjust the vmspace.
    717 	 * Refcount will eternally be 1.
    718 	 */
    719 	newspace = kmem_alloc(sizeof(*newspace), KM_SLEEP);
    720 	newspace->vm_refcnt = 1;
    721 	newspace->vm_map.pmap = priv;
    722 	KASSERT(curproc->p_vmspace == vmspace_kernel());
    723 	curproc->p_vmspace = newspace;
    724 
    725 	return 0;
    726 }
    727 
    728 int
    729 rump_boot_gethowto()
    730 {
    731 
    732 	return boothowto;
    733 }
    734 
    735 void
    736 rump_boot_sethowto(int howto)
    737 {
    738 
    739 	boothowto = howto;
    740 }
    741 
    742 int
    743 rump_getversion(void)
    744 {
    745 
    746 	return __NetBSD_Version__;
    747 }
    748 
    749 /*
    750  * Note: may be called unscheduled.  Not fully safe since no locking
    751  * of allevents (currently that's not even available).
    752  */
    753 void
    754 rump_printevcnts()
    755 {
    756 	struct evcnt *ev;
    757 
    758 	TAILQ_FOREACH(ev, &allevents, ev_list)
    759 		rumpuser_dprintf("%s / %s: %" PRIu64 "\n",
    760 		    ev->ev_group, ev->ev_name, ev->ev_count);
    761 }
    762 
    763 /*
    764  * If you use this interface ... well ... all bets are off.
    765  * The original purpose is for the p2k fs server library to be
    766  * able to use the same pid/lid for VOPs as the host kernel.
    767  */
    768 void
    769 rump_allbetsareoff_setid(pid_t pid, int lid)
    770 {
    771 	struct lwp *l = curlwp;
    772 	struct proc *p = l->l_proc;
    773 
    774 	l->l_lid = lid;
    775 	p->p_pid = pid;
    776 }
    777