Home | History | Annotate | Line # | Download | only in rumpkern
rump.c revision 1.165
      1 /*	$NetBSD: rump.c,v 1.165 2010/04/27 23:30:30 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.165 2010/04/27 23:30:30 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/ksyms.h>
     53 #include <sys/msgbuf.h>
     54 #include <sys/module.h>
     55 #include <sys/once.h>
     56 #include <sys/percpu.h>
     57 #include <sys/pipe.h>
     58 #include <sys/pool.h>
     59 #include <sys/queue.h>
     60 #include <sys/reboot.h>
     61 #include <sys/resourcevar.h>
     62 #include <sys/select.h>
     63 #include <sys/sysctl.h>
     64 #include <sys/syscall.h>
     65 #include <sys/timetc.h>
     66 #include <sys/tty.h>
     67 #include <sys/uidinfo.h>
     68 #include <sys/vmem.h>
     69 #include <sys/xcall.h>
     70 
     71 #include <rump/rumpuser.h>
     72 
     73 #include <secmodel/suser/suser.h>
     74 
     75 #include <prop/proplib.h>
     76 
     77 #include <uvm/uvm_readahead.h>
     78 
     79 #include "rump_private.h"
     80 #include "rump_net_private.h"
     81 #include "rump_vfs_private.h"
     82 #include "rump_dev_private.h"
     83 
     84 struct proc proc0;
     85 struct session rump_session = {
     86 	.s_count = 1,
     87 	.s_flags = 0,
     88 	.s_leader = &proc0,
     89 	.s_login = "rumphobo",
     90 	.s_sid = 0,
     91 };
     92 struct pgrp rump_pgrp = {
     93 	.pg_members = LIST_HEAD_INITIALIZER(pg_members),
     94 	.pg_session = &rump_session,
     95 	.pg_jobc = 1,
     96 };
     97 struct pstats rump_stats;
     98 struct plimit rump_limits;
     99 struct filedesc rump_filedesc0;
    100 struct proclist allproc;
    101 char machine[] = MACHINE;
    102 static kauth_cred_t rump_susercred;
    103 
    104 /* pretend the master rump proc is init */
    105 struct proc *initproc = &proc0;
    106 
    107 struct rumpuser_mtx *rump_giantlock;
    108 
    109 struct device rump_rootdev = {
    110 	.dv_class = DV_VIRTUAL
    111 };
    112 
    113 #ifdef RUMP_WITHOUT_THREADS
    114 int rump_threads = 0;
    115 #else
    116 int rump_threads = 1;
    117 #endif
    118 
    119 static char rump_msgbuf[16*1024]; /* 16k should be enough for std rump needs */
    120 
    121 static void
    122 rump_aiodone_worker(struct work *wk, void *dummy)
    123 {
    124 	struct buf *bp = (struct buf *)wk;
    125 
    126 	KASSERT(&bp->b_work == wk);
    127 	bp->b_iodone(bp);
    128 }
    129 
    130 static int rump_inited;
    131 
    132 /*
    133  * Make sure pnbuf_cache is available even without vfs
    134  */
    135 struct pool_cache *pnbuf_cache;
    136 int rump_initpnbufpool(void);
    137 int rump_initpnbufpool(void)
    138 {
    139 
    140         pnbuf_cache = pool_cache_init(MAXPATHLEN, 0, 0, 0, "pnbufpl",
    141 	    NULL, IPL_NONE, NULL, NULL, NULL);
    142 	return EOPNOTSUPP;
    143 }
    144 
    145 int rump__unavailable(void);
    146 int rump__unavailable() {return EOPNOTSUPP;}
    147 __weak_alias(rump_net_init,rump__unavailable);
    148 __weak_alias(rump_vfs_init,rump_initpnbufpool);
    149 __weak_alias(rump_dev_init,rump__unavailable);
    150 
    151 __weak_alias(rump_vfs_fini,rump__unavailable);
    152 
    153 __weak_alias(biodone,rump__unavailable);
    154 __weak_alias(sopoll,rump__unavailable);
    155 
    156 void rump__unavailable_vfs_panic(void);
    157 void rump__unavailable_vfs_panic() {panic("vfs component not available");}
    158 __weak_alias(usermount_common_policy,rump__unavailable_vfs_panic);
    159 
    160 rump_proc_vfs_init_fn rump_proc_vfs_init;
    161 rump_proc_vfs_release_fn rump_proc_vfs_release;
    162 
    163 static void add_linkedin_modules(const struct modinfo *const *, size_t);
    164 
    165 static void __noinline
    166 messthestack(void)
    167 {
    168 	volatile uint32_t mess[64];
    169 	uint64_t d1, d2;
    170 	int i, error;
    171 
    172 	for (i = 0; i < 64; i++) {
    173 		rumpuser_gettime(&d1, &d2, &error);
    174 		mess[i] = d2;
    175 	}
    176 }
    177 
    178 /*
    179  * Create kern.hostname.  why only this you ask.  well, init_sysctl
    180  * is a kitchen sink in need of some gardening.  but i want to use
    181  * kern.hostname today.
    182  */
    183 static void
    184 mksysctls(void)
    185 {
    186 
    187 	sysctl_createv(NULL, 0, NULL, NULL,
    188 	    CTLFLAG_PERMANENT, CTLTYPE_NODE, "kern", NULL,
    189 	    NULL, 0, NULL, 0, CTL_KERN, CTL_EOL);
    190 
    191 	/* XXX: setting hostnamelen is missing */
    192 	sysctl_createv(NULL, 0, NULL, NULL,
    193 	    CTLFLAG_PERMANENT|CTLFLAG_READWRITE, CTLTYPE_STRING, "hostname",
    194 	    SYSCTL_DESCR("System hostname"), NULL, 0,
    195 	    &hostname, MAXHOSTNAMELEN, CTL_KERN, KERN_HOSTNAME, CTL_EOL);
    196 }
    197 
    198 int
    199 rump__init(int rump_version)
    200 {
    201 	char buf[256];
    202 	struct timespec ts;
    203 	uint64_t sec, nsec;
    204 	struct proc *p;
    205 	struct lwp *l;
    206 	int i;
    207 	int error;
    208 
    209 	/* not reentrant */
    210 	if (rump_inited)
    211 		return 0;
    212 	else if (rump_inited == -1)
    213 		panic("rump_init: host process restart required");
    214 	else
    215 		rump_inited = 1;
    216 
    217 	if (rumpuser_getenv("RUMP_VERBOSE", buf, sizeof(buf), &error) == 0) {
    218 		if (*buf != '0')
    219 			boothowto = AB_VERBOSE;
    220 	}
    221 
    222 	/* get our CPUs initialized */
    223 	rump_cpus_bootstrap(1);
    224 
    225 	rumpuser_gettime(&sec, &nsec, &error);
    226 	boottime.tv_sec = sec;
    227 	boottime.tv_nsec = nsec;
    228 
    229 	initmsgbuf(rump_msgbuf, sizeof(rump_msgbuf));
    230 	aprint_verbose("%s%s", copyright, version);
    231 
    232 	/*
    233 	 * Seed arc4random() with a "reasonable" amount of randomness.
    234 	 * Yes, this is a quick kludge which depends on the arc4random
    235 	 * implementation.
    236 	 */
    237 	messthestack();
    238 	arc4random();
    239 
    240 	if (rump_version != RUMP_VERSION) {
    241 		printf("rump version mismatch, %d vs. %d\n",
    242 		    rump_version, RUMP_VERSION);
    243 		return EPROGMISMATCH;
    244 	}
    245 
    246 	if (rumpuser_getenv("RUMP_THREADS", buf, sizeof(buf), &error) == 0) {
    247 		rump_threads = *buf != '0';
    248 	}
    249 	rumpuser_thrinit(rump_user_schedule, rump_user_unschedule,
    250 	    rump_threads);
    251 	rump_intr_init();
    252 
    253 	/* init minimal lwp/cpu context */
    254 	l = &lwp0;
    255 	l->l_lid = 1;
    256 	l->l_cpu = rump_cpu;
    257 	rumpuser_set_curlwp(l);
    258 
    259 	mutex_init(&tty_lock, MUTEX_DEFAULT, IPL_NONE);
    260 	rumpuser_mutex_recursive_init(&rump_giantlock);
    261 	ksyms_init();
    262 	rumpvm_init();
    263 	evcnt_init();
    264 
    265 	once_init();
    266 	prop_kern_init();
    267 
    268 	pool_subsystem_init();
    269 	kmem_init();
    270 
    271 	uvm_ra_init();
    272 
    273 	mutex_obj_init();
    274 	callout_startup();
    275 
    276 	kprintf_init();
    277 	loginit();
    278 
    279 	kauth_init();
    280 	rump_susercred = rump_cred_create(0, 0, 0, NULL);
    281 
    282 	/* init proc0 and rest of lwp0 now that we can allocate memory */
    283 	p = &proc0;
    284 	p->p_stats = &rump_stats;
    285 	p->p_limit = &rump_limits;
    286 	p->p_pgrp = &rump_pgrp;
    287 	p->p_pid = 0;
    288 	p->p_fd = &rump_filedesc0;
    289 	p->p_vmspace = &rump_vmspace;
    290 	p->p_emul = &emul_netbsd;
    291 	p->p_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_NONE);
    292 	l->l_cred = rump_cred_suserget();
    293 	l->l_proc = p;
    294 	LIST_INIT(&allproc);
    295 	LIST_INSERT_HEAD(&allproc, &proc0, p_list);
    296 	proc_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_NONE);
    297 	lwpinit_specificdata();
    298 
    299 	mutex_init(&rump_limits.pl_lock, MUTEX_DEFAULT, IPL_NONE);
    300 	rump_limits.pl_rlimit[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
    301 	rump_limits.pl_rlimit[RLIMIT_NOFILE].rlim_cur = RLIM_INFINITY;
    302 	rump_limits.pl_rlimit[RLIMIT_SBSIZE].rlim_cur = RLIM_INFINITY;
    303 	rump_limits.pl_corename = defcorename;
    304 
    305 	rump_scheduler_init();
    306 	/* revert temporary context and schedule a real context */
    307 	l->l_cpu = NULL;
    308 	rumpuser_set_curlwp(NULL);
    309 	rump_schedule();
    310 
    311 	percpu_init();
    312 	inittimecounter();
    313 	ntp_init();
    314 
    315 	rumpuser_gettime(&sec, &nsec, &error);
    316 	ts.tv_sec = sec;
    317 	ts.tv_nsec = nsec;
    318 	tc_setclock(&ts);
    319 
    320 	/* we are mostly go.  do per-cpu subsystem init */
    321 	for (i = 0; i < ncpu; i++) {
    322 		struct cpu_info *ci = cpu_lookup(i);
    323 
    324 		callout_init_cpu(ci);
    325 		softint_init(ci);
    326 		xc_init_cpu(ci);
    327 		pool_cache_cpu_init(ci);
    328 		selsysinit(ci);
    329 		percpu_init_cpu(ci);
    330 	}
    331 
    332 	sysctl_init();
    333 	kqueue_init();
    334 	iostat_init();
    335 	uid_init();
    336 	fd_sys_init();
    337 	module_init();
    338 	devsw_init();
    339 	pipe_init();
    340 	resource_init();
    341 
    342 	rumpuser_dl_bootstrap(add_linkedin_modules, rump_kernelfsym_load);
    343 
    344 	/* these do nothing if not present */
    345 	rump_vfs_init();
    346 	rump_net_init();
    347 	rump_dev_init();
    348 	cold = 0;
    349 
    350 	/* aieeeedondest */
    351 	if (rump_threads) {
    352 		if (workqueue_create(&uvm.aiodone_queue, "aiodoned",
    353 		    rump_aiodone_worker, NULL, 0, 0, WQ_MPSAFE))
    354 			panic("aiodoned");
    355 	}
    356 
    357 	mksysctls();
    358 	sysctl_finalize();
    359 
    360 	module_init_class(MODULE_CLASS_ANY);
    361 
    362 	rumpuser_gethostname(hostname, MAXHOSTNAMELEN, &error);
    363 	hostnamelen = strlen(hostname);
    364 
    365 	sigemptyset(&sigcantmask);
    366 
    367 	lwp0.l_fd = proc0.p_fd = fd_init(&rump_filedesc0);
    368 
    369 	if (rump_threads)
    370 		vmem_rehash_start();
    371 
    372 	rump_unschedule();
    373 
    374 	return 0;
    375 }
    376 
    377 /* maybe support sys_reboot some day for remote shutdown */
    378 void
    379 rump_reboot(int howto)
    380 {
    381 
    382 	/* dump means we really take the dive here */
    383 	if ((howto & RB_DUMP) || panicstr) {
    384 		rumpuser_exit(RUMPUSER_PANIC);
    385 		/*NOTREACHED*/
    386 	}
    387 
    388 	/* try to sync */
    389 	if (!((howto & RB_NOSYNC) || panicstr)) {
    390 		rump_vfs_fini();
    391 	}
    392 
    393 	/* your wish is my command */
    394 	if (howto & RB_HALT) {
    395 		for (;;) {
    396 			uint64_t sec = 5, nsec = 0;
    397 			int error;
    398 
    399 			rumpuser_nanosleep(&sec, &nsec, &error);
    400 		}
    401 	}
    402 	rump_inited = -1;
    403 }
    404 
    405 struct uio *
    406 rump_uio_setup(void *buf, size_t bufsize, off_t offset, enum rump_uiorw rw)
    407 {
    408 	struct uio *uio;
    409 	enum uio_rw uiorw;
    410 
    411 	switch (rw) {
    412 	case RUMPUIO_READ:
    413 		uiorw = UIO_READ;
    414 		break;
    415 	case RUMPUIO_WRITE:
    416 		uiorw = UIO_WRITE;
    417 		break;
    418 	default:
    419 		panic("%s: invalid rw %d", __func__, rw);
    420 	}
    421 
    422 	uio = kmem_alloc(sizeof(struct uio), KM_SLEEP);
    423 	uio->uio_iov = kmem_alloc(sizeof(struct iovec), KM_SLEEP);
    424 
    425 	uio->uio_iov->iov_base = buf;
    426 	uio->uio_iov->iov_len = bufsize;
    427 
    428 	uio->uio_iovcnt = 1;
    429 	uio->uio_offset = offset;
    430 	uio->uio_resid = bufsize;
    431 	uio->uio_rw = uiorw;
    432 	uio->uio_vmspace = UIO_VMSPACE_SYS;
    433 
    434 	return uio;
    435 }
    436 
    437 size_t
    438 rump_uio_getresid(struct uio *uio)
    439 {
    440 
    441 	return uio->uio_resid;
    442 }
    443 
    444 off_t
    445 rump_uio_getoff(struct uio *uio)
    446 {
    447 
    448 	return uio->uio_offset;
    449 }
    450 
    451 size_t
    452 rump_uio_free(struct uio *uio)
    453 {
    454 	size_t resid;
    455 
    456 	resid = uio->uio_resid;
    457 	kmem_free(uio->uio_iov, sizeof(*uio->uio_iov));
    458 	kmem_free(uio, sizeof(*uio));
    459 
    460 	return resid;
    461 }
    462 
    463 static pid_t nextpid = 1;
    464 struct lwp *
    465 rump_newproc_switch()
    466 {
    467 	struct lwp *l;
    468 	pid_t mypid;
    469 
    470 	mypid = atomic_inc_uint_nv(&nextpid);
    471 	if (__predict_false(mypid == 0))
    472 		mypid = atomic_inc_uint_nv(&nextpid);
    473 
    474 	l = rump_lwp_alloc(mypid, 0);
    475 	rump_lwp_switch(l);
    476 
    477 	return l;
    478 }
    479 
    480 struct lwp *
    481 rump_lwp_alloc_and_switch(pid_t pid, lwpid_t lid)
    482 {
    483 	struct lwp *l;
    484 
    485 	l = rump_lwp_alloc(pid, lid);
    486 	rump_lwp_switch(l);
    487 
    488 	return l;
    489 }
    490 
    491 struct lwp *
    492 rump_lwp_alloc(pid_t pid, lwpid_t lid)
    493 {
    494 	struct lwp *l;
    495 	struct proc *p;
    496 
    497 	l = kmem_zalloc(sizeof(*l), KM_SLEEP);
    498 	if (pid != 0) {
    499 		p = kmem_zalloc(sizeof(*p), KM_SLEEP);
    500 		if (rump_proc_vfs_init)
    501 			rump_proc_vfs_init(p);
    502 		p->p_stats = &rump_stats;
    503 		p->p_limit = lim_copy(&rump_limits);
    504 		p->p_pid = pid;
    505 		p->p_vmspace = &rump_vmspace;
    506 		p->p_emul = &emul_netbsd;
    507 		p->p_fd = fd_init(NULL);
    508 		p->p_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_NONE);
    509 		l->l_cred = rump_cred_suserget();
    510 	} else {
    511 		p = &proc0;
    512 		l->l_cred = rump_susercred;
    513 	}
    514 
    515 	l->l_proc = p;
    516 	l->l_lid = lid;
    517 	l->l_fd = p->p_fd;
    518 	l->l_cpu = NULL;
    519 	lwp_initspecific(l);
    520 	LIST_INSERT_HEAD(&alllwp, l, l_list);
    521 
    522 	return l;
    523 }
    524 
    525 void
    526 rump_lwp_switch(struct lwp *newlwp)
    527 {
    528 	struct lwp *l = curlwp;
    529 
    530 	rumpuser_set_curlwp(NULL);
    531 	newlwp->l_cpu = l->l_cpu;
    532 	newlwp->l_mutex = l->l_mutex;
    533 	l->l_mutex = NULL;
    534 	l->l_cpu = NULL;
    535 	rumpuser_set_curlwp(newlwp);
    536 	if (l->l_flag & LW_WEXIT)
    537 		rump_lwp_free(l);
    538 }
    539 
    540 /* XXX: this has effect only on non-pid0 lwps */
    541 void
    542 rump_lwp_release(struct lwp *l)
    543 {
    544 	struct proc *p;
    545 
    546 	p = l->l_proc;
    547 	if (p->p_pid != 0) {
    548 		mutex_obj_free(p->p_lock);
    549 		fd_free();
    550 		if (rump_proc_vfs_release)
    551 			rump_proc_vfs_release(p);
    552 		rump_cred_put(l->l_cred);
    553 		limfree(p->p_limit);
    554 		kmem_free(p, sizeof(*p));
    555 	}
    556 	KASSERT((l->l_flag & LW_WEXIT) == 0);
    557 	l->l_flag |= LW_WEXIT;
    558 }
    559 
    560 void
    561 rump_lwp_free(struct lwp *l)
    562 {
    563 
    564 	KASSERT(l->l_flag & LW_WEXIT);
    565 	KASSERT(l->l_mutex == NULL);
    566 	if (l->l_name)
    567 		kmem_free(l->l_name, MAXCOMLEN);
    568 	lwp_finispecific(l);
    569 	LIST_REMOVE(l, l_list);
    570 	kmem_free(l, sizeof(*l));
    571 }
    572 
    573 struct lwp *
    574 rump_lwp_curlwp(void)
    575 {
    576 	struct lwp *l = curlwp;
    577 
    578 	if (l->l_flag & LW_WEXIT)
    579 		return NULL;
    580 	return l;
    581 }
    582 
    583 /* rump private.  NEEDS WORK! */
    584 void
    585 rump_set_vmspace(struct vmspace *vm)
    586 {
    587 	struct proc *p = curproc;
    588 
    589 	p->p_vmspace = vm;
    590 }
    591 
    592 kauth_cred_t
    593 rump_cred_create(uid_t uid, gid_t gid, size_t ngroups, gid_t *groups)
    594 {
    595 	kauth_cred_t cred;
    596 	int rv;
    597 
    598 	cred = kauth_cred_alloc();
    599 	kauth_cred_setuid(cred, uid);
    600 	kauth_cred_seteuid(cred, uid);
    601 	kauth_cred_setsvuid(cred, uid);
    602 	kauth_cred_setgid(cred, gid);
    603 	kauth_cred_setgid(cred, gid);
    604 	kauth_cred_setegid(cred, gid);
    605 	kauth_cred_setsvgid(cred, gid);
    606 	rv = kauth_cred_setgroups(cred, groups, ngroups, 0, UIO_SYSSPACE);
    607 	/* oh this is silly.  and by "this" I mean kauth_cred_setgroups() */
    608 	assert(rv == 0);
    609 
    610 	return cred;
    611 }
    612 
    613 void
    614 rump_cred_put(kauth_cred_t cred)
    615 {
    616 
    617 	kauth_cred_free(cred);
    618 }
    619 
    620 kauth_cred_t
    621 rump_cred_suserget(void)
    622 {
    623 
    624 	kauth_cred_hold(rump_susercred);
    625 	return rump_susercred;
    626 }
    627 
    628 /*
    629  * Return the next system lwpid
    630  */
    631 lwpid_t
    632 rump_nextlid(void)
    633 {
    634 	lwpid_t retid;
    635 
    636 	mutex_enter(proc0.p_lock);
    637 	/*
    638 	 * Take next one, don't return 0
    639 	 * XXX: most likely we'll have collisions in case this
    640 	 * wraps around.
    641 	 */
    642 	if (++proc0.p_nlwpid == 0)
    643 		++proc0.p_nlwpid;
    644 	retid = proc0.p_nlwpid;
    645 	mutex_exit(proc0.p_lock);
    646 
    647 	return retid;
    648 }
    649 
    650 static int compcounter[RUMP_COMPONENT_MAX];
    651 
    652 static void
    653 rump_component_init_cb(struct rump_component *rc, int type)
    654 {
    655 
    656 	KASSERT(type < RUMP_COMPONENT_MAX);
    657 	if (rc->rc_type == type) {
    658 		rc->rc_init();
    659 		compcounter[type]++;
    660 	}
    661 }
    662 
    663 int
    664 rump_component_count(enum rump_component_type type)
    665 {
    666 
    667 	KASSERT(type <= RUMP_COMPONENT_MAX);
    668 	return compcounter[type];
    669 }
    670 
    671 void
    672 rump_component_init(enum rump_component_type type)
    673 {
    674 
    675 	rumpuser_dl_component_init(type, rump_component_init_cb);
    676 }
    677 
    678 /*
    679  * Initialize a module which has already been loaded and linked
    680  * with dlopen(). This is fundamentally the same as a builtin module.
    681  */
    682 int
    683 rump_module_init(const struct modinfo * const *mip, size_t nmodinfo)
    684 {
    685 
    686 	return module_builtin_add(mip, nmodinfo, true);
    687 }
    688 
    689 /*
    690  * Finish module (flawless victory, fatality!).
    691  */
    692 int
    693 rump_module_fini(const struct modinfo *mi)
    694 {
    695 
    696 	return module_builtin_remove(mi, true);
    697 }
    698 
    699 /*
    700  * Add loaded and linked module to the builtin list.  It will
    701  * later be initialized with module_init_class().
    702  */
    703 
    704 static void
    705 add_linkedin_modules(const struct modinfo * const *mip, size_t nmodinfo)
    706 {
    707 
    708 	module_builtin_add(mip, nmodinfo, false);
    709 }
    710 
    711 int
    712 rump_kernelfsym_load(void *symtab, uint64_t symsize,
    713 	char *strtab, uint64_t strsize)
    714 {
    715 	static int inited = 0;
    716 	Elf64_Ehdr ehdr;
    717 
    718 	if (inited)
    719 		return EBUSY;
    720 	inited = 1;
    721 
    722 	/*
    723 	 * Use 64bit header since it's bigger.  Shouldn't make a
    724 	 * difference, since we're passing in all zeroes anyway.
    725 	 */
    726 	memset(&ehdr, 0, sizeof(ehdr));
    727 	ksyms_addsyms_explicit(&ehdr, symtab, symsize, strtab, strsize);
    728 
    729 	return 0;
    730 }
    731 
    732 static int
    733 rump_sysproxy_local(int num, void *arg, uint8_t *data, size_t dlen,
    734 	register_t *retval)
    735 {
    736 	struct lwp *l;
    737 	struct sysent *callp;
    738 	int rv;
    739 
    740 	if (__predict_false(num >= SYS_NSYSENT))
    741 		return ENOSYS;
    742 
    743 	callp = rump_sysent + num;
    744 	rump_schedule();
    745 	l = curlwp;
    746 	rv = callp->sy_call(l, (void *)data, retval);
    747 	rump_unschedule();
    748 
    749 	return rv;
    750 }
    751 
    752 int
    753 rump_boot_gethowto()
    754 {
    755 
    756 	return boothowto;
    757 }
    758 
    759 void
    760 rump_boot_sethowto(int howto)
    761 {
    762 
    763 	boothowto = howto;
    764 }
    765 
    766 rump_sysproxy_t rump_sysproxy = rump_sysproxy_local;
    767 void *rump_sysproxy_arg;
    768 
    769 /*
    770  * This whole syscall-via-rpc is still taking form.  For example, it
    771  * may be necessary to set syscalls individually instead of lobbing
    772  * them all to the same place.  So don't think this interface is
    773  * set in stone.
    774  */
    775 int
    776 rump_sysproxy_set(rump_sysproxy_t proxy, void *arg)
    777 {
    778 
    779 	if (rump_sysproxy_arg)
    780 		return EBUSY;
    781 
    782 	rump_sysproxy_arg = arg;
    783 	rump_sysproxy = proxy;
    784 
    785 	return 0;
    786 }
    787 
    788 int
    789 rump_getversion(void)
    790 {
    791 
    792 	return __NetBSD_Version__;
    793 }
    794