Home | History | Annotate | Line # | Download | only in rumpkern
emul.c revision 1.128
      1 /*	$NetBSD: emul.c,v 1.128 2010/04/17 16:34:29 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.128 2010/04/17 16:34:29 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 	.e_vm_default_addr = uvm_default_mapaddr,
    130 };
    131 
    132 struct proc *
    133 p_find(pid_t pid, uint flags)
    134 {
    135 
    136 	panic("%s: not implemented", __func__);
    137 }
    138 
    139 struct pgrp *
    140 pg_find(pid_t pid, uint flags)
    141 {
    142 
    143 	panic("%s: not implemented", __func__);
    144 }
    145 
    146 void
    147 psignal(struct proc *p, int signo)
    148 {
    149 
    150 	switch (signo) {
    151 	case SIGSYS:
    152 		break;
    153 	default:
    154 		panic("unhandled signal %d\n", signo);
    155 	}
    156 }
    157 
    158 void
    159 pgsignal(struct pgrp *pgrp, int sig, int checktty)
    160 {
    161 
    162 	panic("%s: not implemented", __func__);
    163 }
    164 
    165 void
    166 kpsignal(struct proc *p, ksiginfo_t *ksi, void *data)
    167 {
    168 
    169 	panic("%s: not implemented", __func__);
    170 }
    171 
    172 void
    173 kpgsignal(struct pgrp *pgrp, ksiginfo_t *ksi, void *data, int checkctty)
    174 {
    175 
    176 	panic("%s: not implemented", __func__);
    177 }
    178 
    179 int
    180 pgid_in_session(struct proc *p, pid_t pg_id)
    181 {
    182 
    183 	panic("%s: not implemented", __func__);
    184 }
    185 
    186 int
    187 sigispending(struct lwp *l, int signo)
    188 {
    189 
    190 	return 0;
    191 }
    192 
    193 void
    194 sigpending1(struct lwp *l, sigset_t *ss)
    195 {
    196 
    197 	panic("%s: not implemented", __func__);
    198 }
    199 
    200 int
    201 kpause(const char *wmesg, bool intr, int timeo, kmutex_t *mtx)
    202 {
    203 	extern int hz;
    204 	int rv, error;
    205 	uint64_t sec, nsec;
    206 
    207 	if (mtx)
    208 		mutex_exit(mtx);
    209 
    210 	sec = timeo / hz;
    211 	nsec = (timeo % hz) * (1000000000 / hz);
    212 	rv = rumpuser_nanosleep(&sec, &nsec, &error);
    213 
    214 	if (mtx)
    215 		mutex_enter(mtx);
    216 
    217 	if (rv)
    218 		return error;
    219 
    220 	return 0;
    221 }
    222 
    223 void
    224 lwp_unsleep(lwp_t *l, bool cleanup)
    225 {
    226 
    227 	KASSERT(mutex_owned(l->l_mutex));
    228 
    229 	(*l->l_syncobj->sobj_unsleep)(l, cleanup);
    230 }
    231 
    232 vaddr_t
    233 calc_cache_size(struct vm_map *map, int pct, int va_pct)
    234 {
    235 	paddr_t t;
    236 
    237 	t = (paddr_t)physmem * pct / 100 * PAGE_SIZE;
    238 	if ((vaddr_t)t != t) {
    239 		panic("%s: needs tweak", __func__);
    240 	}
    241 	return t;
    242 }
    243 
    244 void
    245 assert_sleepable(void)
    246 {
    247 
    248 	/* always sleepable, although we should improve this */
    249 }
    250 
    251 int
    252 proc_uidmatch(kauth_cred_t cred, kauth_cred_t target)
    253 {
    254 
    255 	panic("%s: not implemented", __func__);
    256 }
    257 
    258 void
    259 proc_crmod_enter(void)
    260 {
    261 
    262 	panic("%s: not implemented", __func__);
    263 }
    264 
    265 void
    266 proc_crmod_leave(kauth_cred_t c1, kauth_cred_t c2, bool sugid)
    267 {
    268 
    269 	panic("%s: not implemented", __func__);
    270 }
    271 
    272 void
    273 module_init_md(void)
    274 {
    275 
    276 	/*
    277 	 * Nothing for now.  However, we should load the librump
    278 	 * symbol table.
    279 	 */
    280 }
    281 
    282 /* us and them, after all we're only ordinary seconds */
    283 static void
    284 rump_delay(unsigned int us)
    285 {
    286 	uint64_t sec, nsec;
    287 	int error;
    288 
    289 	sec = us / 1000000;
    290 	nsec = (us % 1000000) * 1000;
    291 
    292 	if (__predict_false(sec != 0))
    293 		printf("WARNING: over 1s delay\n");
    294 
    295 	rumpuser_nanosleep(&sec, &nsec, &error);
    296 }
    297 void (*delay_func)(unsigned int) = rump_delay;
    298 
    299 void
    300 proc_sesshold(struct session *ss)
    301 {
    302 
    303 	panic("proc_sesshold() impossible, session %p", ss);
    304 }
    305 
    306 void
    307 proc_sessrele(struct session *ss)
    308 {
    309 
    310 	panic("proc_sessrele() impossible, session %p", ss);
    311 }
    312 
    313 int
    314 proc_vmspace_getref(struct proc *p, struct vmspace **vm)
    315 {
    316 
    317 	/* XXX */
    318 	*vm = p->p_vmspace;
    319 	return 0;
    320 }
    321 
    322 int
    323 ttycheckoutq(struct tty *tp, int wait)
    324 {
    325 
    326 	return 1;
    327 }
    328 
    329 void
    330 cnputc(int c)
    331 {
    332 	int error;
    333 
    334 	rumpuser_putchar(c, &error);
    335 }
    336 
    337 void
    338 cnflush(void)
    339 {
    340 
    341 	/* done */
    342 }
    343 
    344 int
    345 tputchar(int c, int flags, struct tty *tp)
    346 {
    347 
    348 	cnputc(c);
    349 	return 0;
    350 }
    351 
    352 void
    353 cpu_reboot(int howto, char *bootstr)
    354 {
    355 
    356 	rump_reboot(howto);
    357 
    358 	/* this function is __dead, we must exit */
    359 	rumpuser_exit(0);
    360 }
    361 
    362 void
    363 calcru(struct proc *p, struct timeval *up, struct timeval *sp,
    364 	struct timeval *ip, struct timeval *rp)
    365 {
    366 
    367 	panic("%s unimplemented", __func__);
    368 }
    369 
    370 int
    371 sigismasked(struct lwp *l, int sig)
    372 {
    373 
    374 	return 0;
    375 }
    376 
    377 void
    378 sigclearall(struct proc *p, const sigset_t *mask, ksiginfoq_t *kq)
    379 {
    380 
    381 	panic("%s unimplemented", __func__);
    382 }
    383 
    384 void
    385 ksiginfo_queue_drain0(ksiginfoq_t *kq)
    386 {
    387 
    388 	panic("%s unimplemented", __func__);
    389 }
    390