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