Home | History | Annotate | Line # | Download | only in rumpkern
emul.c revision 1.127
      1 /*	$NetBSD: emul.c,v 1.127 2010/04/17 13:13:45 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: emul.c,v 1.127 2010/04/17 13:13:45 pooka Exp $");
     32 
     33 #include <sys/param.h>
     34 #include <sys/null.h>
     35 #include <sys/vnode.h>
     36 #include <sys/stat.h>
     37 #include <sys/select.h>
     38 #include <sys/syslog.h>
     39 #include <sys/namei.h>
     40 #include <sys/kauth.h>
     41 #include <sys/conf.h>
     42 #include <sys/device.h>
     43 #include <sys/queue.h>
     44 #include <sys/file.h>
     45 #include <sys/filedesc.h>
     46 #include <sys/cpu.h>
     47 #include <sys/kmem.h>
     48 #include <sys/poll.h>
     49 #include <sys/timetc.h>
     50 #include <sys/tprintf.h>
     51 #include <sys/module.h>
     52 #include <sys/tty.h>
     53 #include <sys/reboot.h>
     54 #include <sys/syscallvar.h>
     55 #include <sys/xcall.h>
     56 
     57 #include <dev/cons.h>
     58 
     59 #include <rump/rumpuser.h>
     60 
     61 #include <uvm/uvm_map.h>
     62 
     63 #include "rump_private.h"
     64 
     65 kmutex_t *proc_lock;
     66 struct lwp lwp0;
     67 struct vnode *rootvp;
     68 dev_t rootdev = NODEV;
     69 int physmem = 256*256; /* 256 * 1024*1024 / 4k, PAGE_SIZE not always set */
     70 int doing_shutdown;
     71 const int schedppq = 1;
     72 int hardclock_ticks;
     73 bool mp_online = false;
     74 struct timeval boottime;
     75 int cold = 1;
     76 int boothowto = AB_SILENT;
     77 struct tty *constty;
     78 
     79 char hostname[MAXHOSTNAMELEN];
     80 size_t hostnamelen;
     81 
     82 const char *panicstr;
     83 const char *domainname;
     84 int domainnamelen;
     85 
     86 const struct filterops sig_filtops;
     87 
     88 #define DEVSW_SIZE 255
     89 const struct bdevsw *bdevsw0[DEVSW_SIZE]; /* XXX storage size */
     90 const struct bdevsw **bdevsw = bdevsw0;
     91 const int sys_cdevsws = DEVSW_SIZE;
     92 int max_cdevsws = DEVSW_SIZE;
     93 
     94 const struct cdevsw *cdevsw0[DEVSW_SIZE]; /* XXX storage size */
     95 const struct cdevsw **cdevsw = cdevsw0;
     96 const int sys_bdevsws = DEVSW_SIZE;
     97 int max_bdevsws = DEVSW_SIZE;
     98 
     99 struct devsw_conv devsw_conv0;
    100 struct devsw_conv *devsw_conv = &devsw_conv0;
    101 int max_devsw_convs = 0;
    102 int mem_no = 2;
    103 
    104 struct device *booted_device;
    105 struct device *booted_wedge;
    106 int booted_partition;
    107 
    108 /* XXX: unused */
    109 kmutex_t tty_lock;
    110 krwlock_t exec_lock;
    111 
    112 struct lwplist alllwp = LIST_HEAD_INITIALIZER(alllwp);
    113 
    114 /* sparc doesn't sport constant page size */
    115 #ifdef __sparc__
    116 int nbpg = 4096;
    117 #endif
    118 
    119 struct loadavg averunnable = {
    120 	{ 0 * FSCALE,
    121 	  1 * FSCALE,
    122 	  11 * FSCALE, },
    123 	FSCALE,
    124 };
    125 
    126 struct emul emul_netbsd = {
    127 	.e_name = "netbsd-rump",
    128 	.e_sysent = rump_sysent,
    129 };
    130 
    131 struct proc *
    132 p_find(pid_t pid, uint flags)
    133 {
    134 
    135 	panic("%s: not implemented", __func__);
    136 }
    137 
    138 struct pgrp *
    139 pg_find(pid_t pid, uint flags)
    140 {
    141 
    142 	panic("%s: not implemented", __func__);
    143 }
    144 
    145 void
    146 psignal(struct proc *p, int signo)
    147 {
    148 
    149 	switch (signo) {
    150 	case SIGSYS:
    151 		break;
    152 	default:
    153 		panic("unhandled signal %d\n", signo);
    154 	}
    155 }
    156 
    157 void
    158 pgsignal(struct pgrp *pgrp, int sig, int checktty)
    159 {
    160 
    161 	panic("%s: not implemented", __func__);
    162 }
    163 
    164 void
    165 kpsignal(struct proc *p, ksiginfo_t *ksi, void *data)
    166 {
    167 
    168 	panic("%s: not implemented", __func__);
    169 }
    170 
    171 void
    172 kpgsignal(struct pgrp *pgrp, ksiginfo_t *ksi, void *data, int checkctty)
    173 {
    174 
    175 	panic("%s: not implemented", __func__);
    176 }
    177 
    178 int
    179 pgid_in_session(struct proc *p, pid_t pg_id)
    180 {
    181 
    182 	panic("%s: not implemented", __func__);
    183 }
    184 
    185 int
    186 sigispending(struct lwp *l, int signo)
    187 {
    188 
    189 	return 0;
    190 }
    191 
    192 void
    193 sigpending1(struct lwp *l, sigset_t *ss)
    194 {
    195 
    196 	panic("%s: not implemented", __func__);
    197 }
    198 
    199 int
    200 kpause(const char *wmesg, bool intr, int timeo, kmutex_t *mtx)
    201 {
    202 	extern int hz;
    203 	int rv, error;
    204 	uint64_t sec, nsec;
    205 
    206 	if (mtx)
    207 		mutex_exit(mtx);
    208 
    209 	sec = timeo / hz;
    210 	nsec = (timeo % hz) * (1000000000 / hz);
    211 	rv = rumpuser_nanosleep(&sec, &nsec, &error);
    212 
    213 	if (mtx)
    214 		mutex_enter(mtx);
    215 
    216 	if (rv)
    217 		return error;
    218 
    219 	return 0;
    220 }
    221 
    222 void
    223 lwp_unsleep(lwp_t *l, bool cleanup)
    224 {
    225 
    226 	KASSERT(mutex_owned(l->l_mutex));
    227 
    228 	(*l->l_syncobj->sobj_unsleep)(l, cleanup);
    229 }
    230 
    231 vaddr_t
    232 calc_cache_size(struct vm_map *map, int pct, int va_pct)
    233 {
    234 	paddr_t t;
    235 
    236 	t = (paddr_t)physmem * pct / 100 * PAGE_SIZE;
    237 	if ((vaddr_t)t != t) {
    238 		panic("%s: needs tweak", __func__);
    239 	}
    240 	return t;
    241 }
    242 
    243 void
    244 assert_sleepable(void)
    245 {
    246 
    247 	/* always sleepable, although we should improve this */
    248 }
    249 
    250 int
    251 proc_uidmatch(kauth_cred_t cred, kauth_cred_t target)
    252 {
    253 
    254 	panic("%s: not implemented", __func__);
    255 }
    256 
    257 void
    258 proc_crmod_enter(void)
    259 {
    260 
    261 	panic("%s: not implemented", __func__);
    262 }
    263 
    264 void
    265 proc_crmod_leave(kauth_cred_t c1, kauth_cred_t c2, bool sugid)
    266 {
    267 
    268 	panic("%s: not implemented", __func__);
    269 }
    270 
    271 void
    272 module_init_md(void)
    273 {
    274 
    275 	/*
    276 	 * Nothing for now.  However, we should load the librump
    277 	 * symbol table.
    278 	 */
    279 }
    280 
    281 /* us and them, after all we're only ordinary seconds */
    282 static void
    283 rump_delay(unsigned int us)
    284 {
    285 	uint64_t sec, nsec;
    286 	int error;
    287 
    288 	sec = us / 1000000;
    289 	nsec = (us % 1000000) * 1000;
    290 
    291 	if (__predict_false(sec != 0))
    292 		printf("WARNING: over 1s delay\n");
    293 
    294 	rumpuser_nanosleep(&sec, &nsec, &error);
    295 }
    296 void (*delay_func)(unsigned int) = rump_delay;
    297 
    298 void
    299 proc_sesshold(struct session *ss)
    300 {
    301 
    302 	panic("proc_sesshold() impossible, session %p", ss);
    303 }
    304 
    305 void
    306 proc_sessrele(struct session *ss)
    307 {
    308 
    309 	panic("proc_sessrele() impossible, session %p", ss);
    310 }
    311 
    312 int
    313 proc_vmspace_getref(struct proc *p, struct vmspace **vm)
    314 {
    315 
    316 	/* XXX */
    317 	*vm = p->p_vmspace;
    318 	return 0;
    319 }
    320 
    321 int
    322 ttycheckoutq(struct tty *tp, int wait)
    323 {
    324 
    325 	return 1;
    326 }
    327 
    328 void
    329 cnputc(int c)
    330 {
    331 	int error;
    332 
    333 	rumpuser_putchar(c, &error);
    334 }
    335 
    336 void
    337 cnflush(void)
    338 {
    339 
    340 	/* done */
    341 }
    342 
    343 int
    344 tputchar(int c, int flags, struct tty *tp)
    345 {
    346 
    347 	cnputc(c);
    348 	return 0;
    349 }
    350 
    351 void
    352 cpu_reboot(int howto, char *bootstr)
    353 {
    354 
    355 	rump_reboot(howto);
    356 
    357 	/* this function is __dead, we must exit */
    358 	rumpuser_exit(0);
    359 }
    360 
    361 void
    362 calcru(struct proc *p, struct timeval *up, struct timeval *sp,
    363 	struct timeval *ip, struct timeval *rp)
    364 {
    365 
    366 	panic("%s unimplemented", __func__);
    367 }
    368 
    369 int
    370 sigismasked(struct lwp *l, int sig)
    371 {
    372 
    373 	return 0;
    374 }
    375 
    376 void
    377 sigclearall(struct proc *p, const sigset_t *mask, ksiginfoq_t *kq)
    378 {
    379 
    380 	panic("%s unimplemented", __func__);
    381 }
    382 
    383 void
    384 ksiginfo_queue_drain0(ksiginfoq_t *kq)
    385 {
    386 
    387 	panic("%s unimplemented", __func__);
    388 }
    389