1 /* $NetBSD: emul.c,v 1.114 2009/12/25 01:56:43 elad Exp $ */
4 * Copyright (c) 2007 Antti Kantee. All Rights Reserved.
6 * Development of this software was supported by Google Summer of Code.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
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.
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
30 #include <sys/cdefs.h>
31 __KERNEL_RCSID(0, "$NetBSD: emul.c,v 1.114 2009/12/25 01:56:43 elad Exp $");
33 #include <sys/param.h>
35 #include <sys/vnode.h>
37 #include <sys/select.h>
38 #include <sys/syslog.h>
39 #include <sys/namei.h>
40 #include <sys/kauth.h>
42 #include <sys/device.h>
43 #include <sys/queue.h>
45 #include <sys/filedesc.h>
49 #include <sys/timetc.h>
50 #include <sys/tprintf.h>
51 #include <sys/module.h>
53 #include <sys/reboot.h>
54 #include <sys/syscallvar.h>
55 #include <sys/xcall.h>
59 #include <rump/rumpuser.h>
61 #include <uvm/uvm_map.h>
63 #include "rump_private.h"
65 time_t time_second
= 1;
71 int physmem
= 256*256; /* 256 * 1024*1024 / 4k, PAGE_SIZE not always set */
73 const int schedppq
= 1;
75 bool mp_online
= false;
76 struct vm_map
*mb_map
;
77 struct timeval boottime
;
78 struct emul emul_netbsd
;
80 int boothowto
= AB_SILENT
;
83 char hostname
[MAXHOSTNAMELEN
];
87 const char *domainname
;
90 const struct filterops sig_filtops
;
92 #define DEVSW_SIZE 255
93 const struct bdevsw
*bdevsw0
[DEVSW_SIZE
]; /* XXX storage size */
94 const struct bdevsw
**bdevsw
= bdevsw0
;
95 const int sys_cdevsws
= DEVSW_SIZE
;
96 int max_cdevsws
= DEVSW_SIZE
;
98 const struct cdevsw
*cdevsw0
[DEVSW_SIZE
]; /* XXX storage size */
99 const struct cdevsw
**cdevsw
= cdevsw0
;
100 const int sys_bdevsws
= DEVSW_SIZE
;
101 int max_bdevsws
= DEVSW_SIZE
;
103 struct devsw_conv devsw_conv0
;
104 struct devsw_conv
*devsw_conv
= &devsw_conv0
;
105 int max_devsw_convs
= 0;
108 struct device
*booted_device
;
109 struct device
*booted_wedge
;
110 int booted_partition
;
114 kmutex_t sysctl_file_marker_lock
;
116 /* sparc doesn't sport constant page size */
122 device_class(device_t dev
)
125 return dev
->dv_class
;
129 getnanouptime(struct timespec
*ts
)
136 getmicrouptime(struct timeval
*tv
)
141 TIMESPEC_TO_TIMEVAL(tv
, &ts
);
145 gettime(struct timespec
*ts
)
150 rumpuser_gettime(&sec
, &nsec
, &error
);
156 nanotime(struct timespec
*ts
)
166 /* hooray for mick, so what if I do */
168 getnanotime(struct timespec
*ts
)
175 microtime(struct timeval
*tv
)
181 TIMESPEC_TO_TIMEVAL(tv
, &ts
);
184 TIMESPEC_TO_TIMEVAL(tv
, &ts
);
189 getmicrotime(struct timeval
*tv
)
196 p_find(pid_t pid
, uint flags
)
199 panic("%s: not implemented", __func__
);
203 pg_find(pid_t pid
, uint flags
)
206 panic("%s: not implemented", __func__
);
210 psignal(struct proc
*p
, int signo
)
217 panic("unhandled signal %d\n", signo
);
222 kpsignal(struct proc
*p
, ksiginfo_t
*ksi
, void *data
)
225 panic("%s: not implemented", __func__
);
229 kpgsignal(struct pgrp
*pgrp
, ksiginfo_t
*ksi
, void *data
, int checkctty
)
232 panic("%s: not implemented", __func__
);
236 pgid_in_session(struct proc
*p
, pid_t pg_id
)
239 panic("%s: not implemented", __func__
);
243 sigispending(struct lwp
*l
, int signo
)
250 sigpending1(struct lwp
*l
, sigset_t
*ss
)
253 panic("%s: not implemented", __func__
);
257 kpause(const char *wmesg
, bool intr
, int timeo
, kmutex_t
*mtx
)
267 nsec
= (timeo
% hz
) * (1000000000 / hz
);
268 rv
= rumpuser_nanosleep(&sec
, &nsec
, &error
);
283 /* we don't control scheduling currently, can't do anything now */
287 lwp_unsleep(lwp_t
*l
, bool cleanup
)
290 KASSERT(mutex_owned(l
->l_mutex
));
292 (*l
->l_syncobj
->sobj_unsleep
)(l
, cleanup
);
296 calc_cache_size(struct vm_map
*map
, int pct
, int va_pct
)
300 t
= (paddr_t
)physmem
* pct
/ 100 * PAGE_SIZE
;
301 if ((vaddr_t
)t
!= t
) {
302 panic("%s: needs tweak", __func__
);
308 device_xname(device_t dv
)
314 assert_sleepable(void)
317 /* always sleepable, although we should improve this */
321 tc_setclock(const struct timespec
*ts
)
324 panic("%s: not implemented", __func__
);
328 proc_uidmatch(kauth_cred_t cred
, kauth_cred_t target
)
331 panic("%s: not implemented", __func__
);
335 proc_crmod_enter(void)
338 panic("%s: not implemented", __func__
);
342 proc_crmod_leave(kauth_cred_t c1
, kauth_cred_t c2
, bool sugid
)
345 panic("%s: not implemented", __func__
);
353 * Nothing for now. However, we should load the librump
358 /* us and them, after all we're only ordinary seconds */
360 rump_delay(unsigned int us
)
366 nsec
= (us
% 1000000) * 1000;
368 if (__predict_false(sec
!= 0))
369 printf("WARNING: over 1s delay\n");
371 rumpuser_nanosleep(&sec
, &nsec
, &error
);
373 void (*delay_func
)(unsigned int) = rump_delay
;
376 kpreempt_disable(void)
380 KPREEMPT_DISABLE(curlwp
);
384 kpreempt_enable(void)
387 /* try to make sure kpreempt_disable() is only used from panic() */
388 panic("kpreempt not supported");
392 proc_sesshold(struct session
*ss
)
395 panic("proc_sesshold() impossible, session %p", ss
);
399 proc_sessrele(struct session
*ss
)
402 panic("proc_sessrele() impossible, session %p", ss
);
406 proc_vmspace_getref(struct proc
*p
, struct vmspace
**vm
)
415 ttycheckoutq(struct tty
*tp
, int wait
)
426 rumpuser_putchar(c
, &error
);
437 tputchar(int c
, int flags
, struct tty
*tp
)
445 cpu_reboot(int howto
, char *bootstr
)
450 /* this function is __dead, we must exit */
455 pmf_device_register1(struct device
*dev
,
456 bool (*suspend
)(device_t
, pmf_qual_t
),
457 bool (*resume
)(device_t
, pmf_qual_t
),
458 bool (*shutdown
)(device_t
, int))
465 pmf_device_deregister(struct device
*dev
)
472 syscall_establish(const struct emul
*em
, const struct syscall_package
*sp
)
474 extern struct sysent rump_sysent
[];
477 KASSERT(em
== NULL
|| em
== &emul_netbsd
);
479 for (i
= 0; sp
[i
].sp_call
; i
++)
480 rump_sysent
[sp
[i
].sp_code
].sy_call
= sp
[i
].sp_call
;
486 syscall_disestablish(const struct emul
*em
, const struct syscall_package
*sp
)