Home | History | Annotate | Line # | Download | only in rumpkern
rump.c revision 1.314
      1 /*	$NetBSD: rump.c,v 1.314 2015/01/04 22:11:40 pooka Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2007-2011 Antti Kantee.  All Rights Reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     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  *
     15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
     16  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     18  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     21  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     25  * SUCH DAMAGE.
     26  */
     27 
     28 #include <sys/cdefs.h>
     29 __KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.314 2015/01/04 22:11:40 pooka Exp $");
     30 
     31 #include <sys/systm.h>
     32 #define ELFSIZE ARCH_ELFSIZE
     33 
     34 #include <sys/param.h>
     35 #include <sys/atomic.h>
     36 #include <sys/buf.h>
     37 #include <sys/callout.h>
     38 #include <sys/conf.h>
     39 #include <sys/cpu.h>
     40 #include <sys/device.h>
     41 #include <sys/evcnt.h>
     42 #include <sys/event.h>
     43 #include <sys/exec_elf.h>
     44 #include <sys/filedesc.h>
     45 #include <sys/iostat.h>
     46 #include <sys/kauth.h>
     47 #include <sys/kcpuset.h>
     48 #include <sys/kernel.h>
     49 #include <sys/kmem.h>
     50 #include <sys/kprintf.h>
     51 #include <sys/kthread.h>
     52 #include <sys/ksyms.h>
     53 #include <sys/msgbuf.h>
     54 #include <sys/module.h>
     55 #include <sys/namei.h>
     56 #include <sys/once.h>
     57 #include <sys/percpu.h>
     58 #include <sys/pipe.h>
     59 #include <sys/pool.h>
     60 #include <sys/pserialize.h>
     61 #include <sys/queue.h>
     62 #include <sys/reboot.h>
     63 #include <sys/resourcevar.h>
     64 #include <sys/select.h>
     65 #include <sys/sysctl.h>
     66 #include <sys/syscall.h>
     67 #include <sys/syscallvar.h>
     68 #include <sys/timetc.h>
     69 #include <sys/tty.h>
     70 #include <sys/uidinfo.h>
     71 #include <sys/vmem.h>
     72 #include <sys/xcall.h>
     73 #include <sys/cprng.h>
     74 #include <sys/ktrace.h>
     75 
     76 #include <rump/rumpuser.h>
     77 
     78 #include <secmodel/suser/suser.h>
     79 
     80 #include <prop/proplib.h>
     81 
     82 #include <uvm/uvm_extern.h>
     83 #include <uvm/uvm_readahead.h>
     84 
     85 #include "rump_private.h"
     86 #include "rump_net_private.h"
     87 #include "rump_vfs_private.h"
     88 #include "rump_dev_private.h"
     89 
     90 char machine[] = MACHINE;
     91 
     92 struct proc *initproc;
     93 
     94 struct device rump_rootdev = {
     95 	.dv_class = DV_VIRTUAL
     96 };
     97 
     98 #ifdef RUMP_WITHOUT_THREADS
     99 int rump_threads = 0;
    100 #else
    101 int rump_threads = 1;
    102 #endif
    103 
    104 static void rump_component_addlocal(void);
    105 static struct lwp *bootlwp;
    106 
    107 static char rump_msgbuf[16*1024]; /* 16k should be enough for std rump needs */
    108 
    109 bool rump_ttycomponent = false;
    110 
    111 static void
    112 rump_aiodone_worker(struct work *wk, void *dummy)
    113 {
    114 	struct buf *bp = (struct buf *)wk;
    115 
    116 	KASSERT(&bp->b_work == wk);
    117 	bp->b_iodone(bp);
    118 }
    119 
    120 static int rump_inited;
    121 
    122 void (*rump_vfs_drainbufs)(int) = (void *)nullop;
    123 int  (*rump_vfs_makeonedevnode)(dev_t, const char *,
    124 				devmajor_t, devminor_t) = (void *)nullop;
    125 int  (*rump_vfs_makedevnodes)(dev_t, const char *, char,
    126 			      devmajor_t, devminor_t, int) = (void *)nullop;
    127 
    128 rump_proc_vfs_init_fn rump_proc_vfs_init = (void *)nullop;
    129 rump_proc_vfs_release_fn rump_proc_vfs_release = (void *)nullop;
    130 
    131 static void add_linkedin_modules(const struct modinfo *const *, size_t);
    132 
    133 /*
    134  * Create some sysctl nodes.  why only this you ask.  well, init_sysctl
    135  * is a kitchen sink in need of some gardening.  but i want to use
    136  * others today.  Furthermore, creating a whole kitchen sink full of
    137  * sysctl nodes is a waste of cycles for rump kernel bootstrap.
    138  */
    139 static void
    140 mksysctls(void)
    141 {
    142 
    143 	/* hw.pagesize */
    144 	sysctl_createv(NULL, 0, NULL, NULL,
    145 	    CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    146 	    CTLTYPE_INT, "pagesize",
    147 	    SYSCTL_DESCR("Software page size"),
    148 	    NULL, PAGE_SIZE, NULL, 0,
    149 	    CTL_HW, HW_PAGESIZE, CTL_EOL);
    150 }
    151 
    152 static const struct rumpuser_hyperup hyp = {
    153 	.hyp_schedule		= rump_schedule,
    154 	.hyp_unschedule		= rump_unschedule,
    155 	.hyp_backend_unschedule	= rump_user_unschedule,
    156 	.hyp_backend_schedule	= rump_user_schedule,
    157 	.hyp_lwproc_switch	= rump_lwproc_switch,
    158 	.hyp_lwproc_release	= rump_lwproc_releaselwp,
    159 	.hyp_lwproc_rfork	= rump_sysproxy_hyp_rfork,
    160 	.hyp_lwproc_newlwp	= rump_lwproc_newlwp,
    161 	.hyp_lwproc_curlwp	= rump_lwproc_curlwp,
    162 	.hyp_lwpexit		= rump_sysproxy_hyp_lwpexit,
    163 	.hyp_syscall		= rump_sysproxy_hyp_syscall,
    164 	.hyp_execnotify		= rump_sysproxy_hyp_execnotify,
    165 	.hyp_getpid		= rump_sysproxy_hyp_getpid,
    166 };
    167 
    168 int
    169 rump_daemonize_begin(void)
    170 {
    171 
    172 	if (rump_inited)
    173 		return EALREADY;
    174 
    175 	return rumpuser_daemonize_begin();
    176 }
    177 
    178 int
    179 rump_daemonize_done(int error)
    180 {
    181 
    182 	return rumpuser_daemonize_done(error);
    183 }
    184 
    185 #ifdef RUMP_USE_CTOR
    186 
    187 /* sysctl bootstrap handling */
    188 struct sysctl_boot_chain sysctl_boot_chain \
    189     = LIST_HEAD_INITIALIZER(sysctl_boot_chain);
    190 __link_set_add_text(sysctl_funcs,voidop); /* ensure linkset is non-empty */
    191 
    192 #else /* RUMP_USE_CTOR */
    193 
    194 RUMP_COMPONENT(RUMP_COMPONENT_POSTINIT)
    195 {
    196 	__link_set_decl(rump_components, struct rump_component);
    197 
    198 	/*
    199 	 * Trick compiler into generating references so that statically
    200 	 * linked rump kernels are generated with the link set symbols.
    201 	 */
    202 	asm("" :: "r"(__start_link_set_rump_components));
    203 	asm("" :: "r"(__stop_link_set_rump_components));
    204 }
    205 
    206 #endif /* RUMP_USE_CTOR */
    207 
    208 int
    209 rump_init(void)
    210 {
    211 	char buf[256];
    212 	struct timespec ts;
    213 	int64_t sec;
    214 	long nsec;
    215 	struct lwp *l, *initlwp;
    216 	int i, numcpu;
    217 
    218 	/* not reentrant */
    219 	if (rump_inited)
    220 		return 0;
    221 	else if (rump_inited == -1)
    222 		panic("rump_init: host process restart required");
    223 	else
    224 		rump_inited = 1;
    225 
    226 	/* initialize hypervisor */
    227 	if (rumpuser_init(RUMPUSER_VERSION, &hyp) != 0) {
    228 		rumpuser_dprintf("rumpuser init failed\n");
    229 		return EINVAL;
    230 	}
    231 
    232 	/* init minimal lwp/cpu context */
    233 	rump_lwproc_init();
    234 	l = &lwp0;
    235 	l->l_cpu = l->l_target_cpu = rump_cpu;
    236 	rump_lwproc_curlwp_set(l);
    237 
    238 	/* retrieve env vars which affect the early stage of bootstrap */
    239 	if (rumpuser_getparam("RUMP_THREADS", buf, sizeof(buf)) == 0) {
    240 		rump_threads = *buf != '0';
    241 	}
    242 	if (rumpuser_getparam("RUMP_VERBOSE", buf, sizeof(buf)) == 0) {
    243 		if (*buf != '0')
    244 			boothowto = AB_VERBOSE;
    245 	}
    246 
    247 	if (rumpuser_getparam(RUMPUSER_PARAM_NCPU, buf, sizeof(buf)) != 0)
    248 		panic("mandatory hypervisor configuration (NCPU) missing");
    249 	numcpu = strtoll(buf, NULL, 10);
    250 	if (numcpu < 1) {
    251 		panic("rump kernels are not lightweight enough for \"%d\" CPUs",
    252 		    numcpu);
    253 	}
    254 
    255 	rump_thread_init();
    256 	rump_cpus_bootstrap(&numcpu);
    257 
    258 	rumpuser_clock_gettime(RUMPUSER_CLOCK_RELWALL, &sec, &nsec);
    259 	boottime.tv_sec = sec;
    260 	boottime.tv_nsec = nsec;
    261 
    262 	initmsgbuf(rump_msgbuf, sizeof(rump_msgbuf));
    263 	aprint_verbose("%s%s", copyright, version);
    264 
    265 	rump_intr_init(numcpu);
    266 
    267 	rump_tsleep_init();
    268 
    269 	rumpuser_mutex_init(&rump_giantlock, RUMPUSER_MTX_SPIN);
    270 	ksyms_init();
    271 	uvm_init();
    272 	evcnt_init();
    273 
    274 	kcpuset_sysinit();
    275 	once_init();
    276 	kernconfig_lock_init();
    277 	prop_kern_init();
    278 
    279 	kmem_init();
    280 	kmeminit();
    281 
    282 	uvm_ra_init();
    283 	uao_init();
    284 
    285 	mutex_obj_init();
    286 	callout_startup();
    287 
    288 	kprintf_init();
    289 	pserialize_init();
    290 	loginit();
    291 
    292 	kauth_init();
    293 
    294 	secmodel_init();
    295 	sysctl_init();
    296 	/*
    297 	 * The above call to sysctl_init() only initializes sysctl nodes
    298 	 * from link sets.  Initialize sysctls in case we used ctors.
    299 	 */
    300 #ifdef RUMP_USE_CTOR
    301 	{
    302 		struct sysctl_setup_chain *ssc;
    303 
    304 		LIST_FOREACH(ssc, &sysctl_boot_chain, ssc_entries) {
    305 			ssc->ssc_func(NULL);
    306 		}
    307 	}
    308 #endif /* RUMP_USE_CTOR */
    309 
    310 	rnd_init();
    311 	cprng_init();
    312 	kern_cprng = cprng_strong_create("kernel", IPL_VM,
    313 	    CPRNG_INIT_ANY|CPRNG_REKEY_ANY);
    314 
    315 	rump_hyperentropy_init();
    316 
    317 	procinit();
    318 	proc0_init();
    319 	uid_init();
    320 	chgproccnt(0, 1);
    321 
    322 	l->l_proc = &proc0;
    323 	lwp_update_creds(l);
    324 
    325 	lwpinit_specificdata();
    326 	lwp_initspecific(&lwp0);
    327 
    328 	rump_biglock_init();
    329 
    330 	rump_scheduler_init(numcpu);
    331 	/* revert temporary context and schedule a semireal context */
    332 	rump_lwproc_curlwp_clear(l);
    333 	initproc = &proc0; /* borrow proc0 before we get initproc started */
    334 	rump_schedule();
    335 	bootlwp = curlwp;
    336 
    337 	percpu_init();
    338 	inittimecounter();
    339 	ntp_init();
    340 
    341 #ifdef KTRACE
    342 	ktrinit();
    343 #endif
    344 
    345 	ts = boottime;
    346 	tc_setclock(&ts);
    347 
    348 	extern krwlock_t exec_lock;
    349 	rw_init(&exec_lock);
    350 
    351 	/* we are mostly go.  do per-cpu subsystem init */
    352 	for (i = 0; i < numcpu; i++) {
    353 		struct cpu_info *ci = cpu_lookup(i);
    354 
    355 		/* attach non-bootstrap CPUs */
    356 		if (i > 0) {
    357 			rump_cpu_attach(ci);
    358 			ncpu++;
    359 		}
    360 
    361 		callout_init_cpu(ci);
    362 		softint_init(ci);
    363 		xc_init_cpu(ci);
    364 		pool_cache_cpu_init(ci);
    365 		selsysinit(ci);
    366 		percpu_init_cpu(ci);
    367 
    368 		TAILQ_INIT(&ci->ci_data.cpu_ld_locks);
    369 		__cpu_simple_lock_init(&ci->ci_data.cpu_ld_lock);
    370 
    371 		aprint_verbose("cpu%d at thinair0: rump virtual cpu\n", i);
    372 	}
    373 
    374 	/* Once all CPUs are detected, initialize the per-CPU cprng_fast.  */
    375 	cprng_fast_init();
    376 
    377 	/* CPUs are up.  allow kernel threads to run */
    378 	rump_thread_allow(NULL);
    379 
    380 	rnd_init_softint();
    381 
    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 	procinit_sysctl();
    391 	time_init();
    392 	time_init2();
    393 
    394 	/* start page baroness */
    395 	if (rump_threads) {
    396 		if (kthread_create(PRI_PGDAEMON, KTHREAD_MPSAFE, NULL,
    397 		    uvm_pageout, NULL, &uvm.pagedaemon_lwp, "pdaemon") != 0)
    398 			panic("pagedaemon create failed");
    399 	} else
    400 		uvm.pagedaemon_lwp = NULL; /* doesn't match curlwp */
    401 
    402 	/* process dso's */
    403 	rumpuser_dl_bootstrap(add_linkedin_modules,
    404 	    rump_kernelfsym_load, rump_component_load);
    405 
    406 	rump_component_addlocal();
    407 	rump_component_init(RUMP_COMPONENT_KERN);
    408 
    409 	/* initialize factions, if present */
    410 	rump_component_init(RUMP__FACTION_VFS);
    411 	/* pnbuf_cache is used even without vfs */
    412 	if (rump_component_count(RUMP__FACTION_VFS) == 0) {
    413 		pnbuf_cache = pool_cache_init(MAXPATHLEN, 0, 0, 0, "pnbufpl",
    414 		    NULL, IPL_NONE, NULL, NULL, NULL);
    415 	}
    416 	rump_component_init(RUMP__FACTION_NET);
    417 	rump_component_init(RUMP__FACTION_DEV);
    418 	KASSERT(rump_component_count(RUMP__FACTION_VFS) <= 1
    419 	    && rump_component_count(RUMP__FACTION_NET) <= 1
    420 	    && rump_component_count(RUMP__FACTION_DEV) <= 1);
    421 
    422 	rump_component_init(RUMP_COMPONENT_KERN_VFS);
    423 
    424 	/*
    425 	 * if we initialized the tty component above, the tyttymtx is
    426 	 * now initialized.  otherwise, we need to initialize it.
    427 	 */
    428 	if (!rump_ttycomponent)
    429 		mutex_init(&tty_lock, MUTEX_DEFAULT, IPL_VM);
    430 
    431 	cold = 0;
    432 
    433 	/* aieeeedondest */
    434 	if (rump_threads) {
    435 		if (workqueue_create(&uvm.aiodone_queue, "aiodoned",
    436 		    rump_aiodone_worker, NULL, 0, 0, WQ_MPSAFE))
    437 			panic("aiodoned");
    438 	}
    439 
    440 	sysctl_finalize();
    441 
    442 	module_init_class(MODULE_CLASS_ANY);
    443 
    444 	if (rumpuser_getparam(RUMPUSER_PARAM_HOSTNAME,
    445 	    hostname, MAXHOSTNAMELEN) != 0) {
    446 		panic("mandatory hypervisor configuration (HOSTNAME) missing");
    447 	}
    448 	hostnamelen = strlen(hostname);
    449 
    450 	sigemptyset(&sigcantmask);
    451 
    452 	if (rump_threads)
    453 		vmem_rehash_start();
    454 
    455 	/*
    456 	 * Create init (proc 1), used to attach implicit threads in rump.
    457 	 * (note: must be done after vfsinit to get cwdi)
    458 	 */
    459 	initlwp = rump__lwproc_alloclwp(NULL);
    460 	mutex_enter(proc_lock);
    461 	initproc = proc_find_raw(1);
    462 	mutex_exit(proc_lock);
    463 	if (initproc == NULL)
    464 		panic("where in the world is initproc?");
    465 
    466 	rump_component_init(RUMP_COMPONENT_POSTINIT);
    467 
    468 	/* load syscalls */
    469 	rump_component_init(RUMP_COMPONENT_SYSCALL);
    470 
    471 	/* component inits done */
    472 	bootlwp = NULL;
    473 
    474 	/* open 0/1/2 for init */
    475 	KASSERT(rump_lwproc_curlwp() == NULL);
    476 	rump_lwproc_switch(initlwp);
    477 	rump_consdev_init();
    478 	rump_lwproc_switch(NULL);
    479 
    480 	/* release cpu */
    481 	rump_unschedule();
    482 
    483 	return 0;
    484 }
    485 /* historic compat */
    486 __strong_alias(rump__init,rump_init);
    487 
    488 static int compcounter[RUMP_COMPONENT_MAX];
    489 static int compinited[RUMP_COMPONENT_MAX];
    490 
    491 /*
    492  * Yea, this is O(n^2), but we're only looking at a handful of components.
    493  * Components are always initialized from the thread that called rump_init().
    494  */
    495 static LIST_HEAD(, rump_component) rchead = LIST_HEAD_INITIALIZER(rchead);
    496 
    497 #ifdef RUMP_USE_CTOR
    498 struct modinfo_boot_chain modinfo_boot_chain \
    499     = LIST_HEAD_INITIALIZER(modinfo_boot_chain);
    500 
    501 static void
    502 rump_component_addlocal(void)
    503 {
    504 	struct modinfo_chain *mc;
    505 
    506 	while ((mc = LIST_FIRST(&modinfo_boot_chain)) != NULL) {
    507 		LIST_REMOVE(mc, mc_entries);
    508 		module_builtin_add(&mc->mc_info, 1, false);
    509 	}
    510 }
    511 
    512 #else /* RUMP_USE_CTOR */
    513 
    514 static void
    515 rump_component_addlocal(void)
    516 {
    517 	__link_set_decl(rump_components, struct rump_component);
    518 	struct rump_component *const *rc;
    519 
    520 	__link_set_foreach(rc, rump_components) {
    521 		rump_component_load(*rc);
    522 	}
    523 }
    524 #endif /* RUMP_USE_CTOR */
    525 
    526 void
    527 rump_component_load(const struct rump_component *rc_const)
    528 {
    529 	struct rump_component *rc, *rc_iter;
    530 
    531 	/*
    532 	 * XXX: this is ok since the "const" was removed from the
    533 	 * definition of RUMP_COMPONENT().
    534 	 *
    535 	 * However, to preserve the hypercall interface, the const
    536 	 * remains here.  This can be fixed in the next hypercall revision.
    537 	 */
    538 	rc = __UNCONST(rc_const);
    539 
    540 	KASSERT(!rump_inited || curlwp == bootlwp);
    541 
    542 	LIST_FOREACH(rc_iter, &rchead, rc_entries) {
    543 		if (rc_iter == rc)
    544 			return;
    545 	}
    546 
    547 	LIST_INSERT_HEAD(&rchead, rc, rc_entries);
    548 	KASSERT(rc->rc_type < RUMP_COMPONENT_MAX);
    549 	compcounter[rc->rc_type]++;
    550 }
    551 
    552 int
    553 rump_component_count(enum rump_component_type type)
    554 {
    555 
    556 	KASSERT(curlwp == bootlwp);
    557 	KASSERT(type < RUMP_COMPONENT_MAX);
    558 	return compcounter[type];
    559 }
    560 
    561 void
    562 rump_component_init(enum rump_component_type type)
    563 {
    564 	const struct rump_component *rc, *rc_safe;
    565 
    566 	KASSERT(curlwp == bootlwp);
    567 	KASSERT(!compinited[type]);
    568 	LIST_FOREACH_SAFE(rc, &rchead, rc_entries, rc_safe) {
    569 		if (rc->rc_type == type) {
    570 			rc->rc_init();
    571 			LIST_REMOVE(rc, rc_entries);
    572 		}
    573 	}
    574 	compinited[type] = 1;
    575 }
    576 
    577 /*
    578  * Initialize a module which has already been loaded and linked
    579  * with dlopen(). This is fundamentally the same as a builtin module.
    580  *
    581  * XXX: this interface does not really work in the RUMP_USE_CTOR case,
    582  * but I'm not sure it's anything to cry about.  In feeling blue,
    583  * things could somehow be handled via modinfo_boot_chain.
    584  */
    585 int
    586 rump_module_init(const struct modinfo * const *mip, size_t nmodinfo)
    587 {
    588 
    589 	return module_builtin_add(mip, nmodinfo, true);
    590 }
    591 
    592 /*
    593  * Finish module (flawless victory, fatality!).
    594  */
    595 int
    596 rump_module_fini(const struct modinfo *mi)
    597 {
    598 
    599 	return module_builtin_remove(mi, true);
    600 }
    601 
    602 /*
    603  * Add loaded and linked module to the builtin list.  It will
    604  * later be initialized with module_init_class().
    605  */
    606 
    607 static void
    608 add_linkedin_modules(const struct modinfo * const *mip, size_t nmodinfo)
    609 {
    610 
    611 	module_builtin_add(mip, nmodinfo, false);
    612 }
    613 
    614 int
    615 rump_kernelfsym_load(void *symtab, uint64_t symsize,
    616 	char *strtab, uint64_t strsize)
    617 {
    618 	static int inited = 0;
    619 	Elf64_Ehdr ehdr;
    620 
    621 	if (inited)
    622 		return EBUSY;
    623 	inited = 1;
    624 
    625 	/*
    626 	 * Use 64bit header since it's bigger.  Shouldn't make a
    627 	 * difference, since we're passing in all zeroes anyway.
    628 	 */
    629 	memset(&ehdr, 0, sizeof(ehdr));
    630 	ksyms_addsyms_explicit(&ehdr, symtab, symsize, strtab, strsize);
    631 
    632 	return 0;
    633 }
    634 
    635 int
    636 rump_boot_gethowto()
    637 {
    638 
    639 	return boothowto;
    640 }
    641 
    642 void
    643 rump_boot_sethowto(int howto)
    644 {
    645 
    646 	boothowto = howto;
    647 }
    648 
    649 int
    650 rump_getversion(void)
    651 {
    652 
    653 	return __NetBSD_Version__;
    654 }
    655 /* compat */
    656 __strong_alias(rump_pub_getversion,rump_getversion);
    657 
    658 int
    659 rump_nativeabi_p(void)
    660 {
    661 
    662 #ifdef _RUMP_NATIVE_ABI
    663 	return 1;
    664 #else
    665 	return 0;
    666 #endif
    667 }
    668 
    669 /*
    670  * Note: may be called unscheduled.  Not fully safe since no locking
    671  * of allevents (currently that's not even available).
    672  */
    673 void
    674 rump_printevcnts()
    675 {
    676 	struct evcnt *ev;
    677 
    678 	TAILQ_FOREACH(ev, &allevents, ev_list)
    679 		rumpuser_dprintf("%s / %s: %" PRIu64 "\n",
    680 		    ev->ev_group, ev->ev_name, ev->ev_count);
    681 }
    682 
    683 /*
    684  * If you use this interface ... well ... all bets are off.
    685  * The original purpose is for the p2k fs server library to be
    686  * able to use the same pid/lid for VOPs as the host kernel.
    687  */
    688 void
    689 rump_allbetsareoff_setid(pid_t pid, int lid)
    690 {
    691 	struct lwp *l = curlwp;
    692 	struct proc *p = l->l_proc;
    693 
    694 	l->l_lid = lid;
    695 	p->p_pid = pid;
    696 }
    697 
    698 #include <sys/pserialize.h>
    699 
    700 static void
    701 ipiemu(void *a1, void *a2)
    702 {
    703 
    704 	xc__highpri_intr(NULL);
    705 	pserialize_switchpoint();
    706 }
    707 
    708 void
    709 rump_xc_highpri(struct cpu_info *ci)
    710 {
    711 
    712 	if (ci)
    713 		xc_unicast(0, ipiemu, NULL, NULL, ci);
    714 	else
    715 		xc_broadcast(0, ipiemu, NULL, NULL);
    716 }
    717 
    718 int
    719 rump_syscall(int num, void *data, size_t dlen, register_t *retval)
    720 {
    721 	struct proc *p;
    722 	struct emul *e;
    723 	struct sysent *callp;
    724 	const int *etrans = NULL;
    725 	int rv;
    726 
    727 	rump_schedule();
    728 	p = curproc;
    729 	e = p->p_emul;
    730 #ifndef __HAVE_MINIMAL_EMUL
    731 	KASSERT(num > 0 && num < e->e_nsysent);
    732 #endif
    733 	callp = e->e_sysent + num;
    734 
    735 	rv = sy_invoke(callp, curlwp, data, retval, num);
    736 
    737 	/*
    738 	 * I hope that (!__HAVE_MINIMAL_EMUL || __HAVE_SYSCALL_INTERN) is
    739 	 * an invariant ...
    740 	 */
    741 #if !defined(__HAVE_MINIMAL_EMUL)
    742 	etrans = e->e_errno;
    743 #elif defined(__HAVE_SYSCALL_INTERN)
    744 	etrans = p->p_emuldata;
    745 #endif
    746 
    747 	if (etrans) {
    748 		rv = etrans[rv];
    749 		/*
    750 		 * XXX: small hack since Linux etrans vectors on some
    751 		 * archs contain negative errnos, but rump_syscalls
    752 		 * uses the -1 + errno ABI.  Note that these
    753 		 * negative values are always the result of translation,
    754 		 * otherwise the above translation method would not
    755 		 * work very well.
    756 		 */
    757 		if (rv < 0)
    758 			rv = -rv;
    759 	}
    760 	rump_unschedule();
    761 
    762 	return rv;
    763 }
    764 
    765 void
    766 rump_syscall_boot_establish(const struct rump_onesyscall *calls, size_t ncall)
    767 {
    768 	struct sysent *callp;
    769 	size_t i;
    770 
    771 	for (i = 0; i < ncall; i++) {
    772 		callp = rump_sysent + calls[i].ros_num;
    773 		KASSERT(bootlwp != NULL
    774 		    && callp->sy_call == (sy_call_t *)enosys);
    775 		callp->sy_call = calls[i].ros_handler;
    776 	}
    777 }
    778 
    779 struct rump_boot_etfs *ebstart;
    780 void
    781 rump_boot_etfs_register(struct rump_boot_etfs *eb)
    782 {
    783 
    784 	/*
    785 	 * Could use atomics, but, since caller would need to synchronize
    786 	 * against calling rump_init() anyway, easier to just specify the
    787 	 * interface as "caller serializes".  This solve-by-specification
    788 	 * approach avoids the grey area of using atomics before rump_init()
    789 	 * runs.
    790 	 */
    791 	eb->_eb_next = ebstart;
    792 	eb->eb_status = -1;
    793 	ebstart = eb;
    794 }
    795