emul.c revision 1.63.2.2 1 1.63.2.2 christos /* $NetBSD: emul.c,v 1.63.2.2 2008/12/28 22:22:12 christos Exp $ */
2 1.63.2.2 christos
3 1.63.2.2 christos /*
4 1.63.2.2 christos * Copyright (c) 2007 Antti Kantee. All Rights Reserved.
5 1.63.2.2 christos *
6 1.63.2.2 christos * Development of this software was supported by Google Summer of Code.
7 1.63.2.2 christos *
8 1.63.2.2 christos * Redistribution and use in source and binary forms, with or without
9 1.63.2.2 christos * modification, are permitted provided that the following conditions
10 1.63.2.2 christos * are met:
11 1.63.2.2 christos * 1. Redistributions of source code must retain the above copyright
12 1.63.2.2 christos * notice, this list of conditions and the following disclaimer.
13 1.63.2.2 christos * 2. Redistributions in binary form must reproduce the above copyright
14 1.63.2.2 christos * notice, this list of conditions and the following disclaimer in the
15 1.63.2.2 christos * documentation and/or other materials provided with the distribution.
16 1.63.2.2 christos *
17 1.63.2.2 christos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
18 1.63.2.2 christos * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 1.63.2.2 christos * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 1.63.2.2 christos * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 1.63.2.2 christos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 1.63.2.2 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 1.63.2.2 christos * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 1.63.2.2 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 1.63.2.2 christos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 1.63.2.2 christos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 1.63.2.2 christos * SUCH DAMAGE.
28 1.63.2.2 christos */
29 1.63.2.2 christos
30 1.63.2.2 christos #include <sys/cdefs.h>
31 1.63.2.2 christos __KERNEL_RCSID(0, "$NetBSD: emul.c,v 1.63.2.2 2008/12/28 22:22:12 christos Exp $");
32 1.63.2.2 christos
33 1.63.2.2 christos #define malloc(a,b,c) __wrap_malloc(a,b,c)
34 1.63.2.2 christos
35 1.63.2.2 christos #include <sys/param.h>
36 1.63.2.2 christos #include <sys/malloc.h>
37 1.63.2.2 christos #include <sys/null.h>
38 1.63.2.2 christos #include <sys/vnode.h>
39 1.63.2.2 christos #include <sys/stat.h>
40 1.63.2.2 christos #include <sys/select.h>
41 1.63.2.2 christos #include <sys/syslog.h>
42 1.63.2.2 christos #include <sys/namei.h>
43 1.63.2.2 christos #include <sys/kauth.h>
44 1.63.2.2 christos #include <sys/conf.h>
45 1.63.2.2 christos #include <sys/device.h>
46 1.63.2.2 christos #include <sys/queue.h>
47 1.63.2.2 christos #include <sys/file.h>
48 1.63.2.2 christos #include <sys/filedesc.h>
49 1.63.2.2 christos #include <sys/kthread.h>
50 1.63.2.2 christos #include <sys/cpu.h>
51 1.63.2.2 christos #include <sys/kmem.h>
52 1.63.2.2 christos #include <sys/poll.h>
53 1.63.2.2 christos #include <sys/tprintf.h>
54 1.63.2.2 christos #include <sys/timetc.h>
55 1.63.2.2 christos
56 1.63.2.2 christos #include <machine/bswap.h>
57 1.63.2.2 christos #include <machine/stdarg.h>
58 1.63.2.2 christos
59 1.63.2.2 christos #include <rump/rumpuser.h>
60 1.63.2.2 christos
61 1.63.2.2 christos #include <uvm/uvm_map.h>
62 1.63.2.2 christos
63 1.63.2.2 christos #include "rump_private.h"
64 1.63.2.2 christos
65 1.63.2.2 christos time_t time_second = 1;
66 1.63.2.2 christos
67 1.63.2.2 christos kmutex_t *proc_lock;
68 1.63.2.2 christos struct lwp lwp0;
69 1.63.2.2 christos struct vnode *rootvp;
70 1.63.2.2 christos struct device *root_device;
71 1.63.2.2 christos dev_t rootdev;
72 1.63.2.2 christos int physmem = 256*256; /* 256 * 1024*1024 / 4k, PAGE_SIZE not always set */
73 1.63.2.2 christos int doing_shutdown;
74 1.63.2.2 christos int ncpu = 1;
75 1.63.2.2 christos const int schedppq = 1;
76 1.63.2.2 christos int hardclock_ticks;
77 1.63.2.2 christos bool mp_online = false;
78 1.63.2.2 christos struct vm_map *mb_map;
79 1.63.2.2 christos struct timeval boottime;
80 1.63.2.2 christos
81 1.63.2.2 christos char hostname[MAXHOSTNAMELEN];
82 1.63.2.2 christos size_t hostnamelen;
83 1.63.2.2 christos
84 1.63.2.2 christos u_long bufmem_valimit;
85 1.63.2.2 christos u_long bufmem_hiwater;
86 1.63.2.2 christos u_long bufmem_lowater;
87 1.63.2.2 christos u_long bufmem;
88 1.63.2.2 christos u_int nbuf;
89 1.63.2.2 christos
90 1.63.2.2 christos const char *panicstr;
91 1.63.2.2 christos const char ostype[] = "NetBSD";
92 1.63.2.2 christos const char osrelease[] = "999"; /* paradroid 4evah */
93 1.63.2.2 christos const char kernel_ident[] = "RUMP-ROAST";
94 1.63.2.2 christos const char *domainname;
95 1.63.2.2 christos int domainnamelen;
96 1.63.2.2 christos
97 1.63.2.2 christos const struct filterops seltrue_filtops;
98 1.63.2.2 christos
99 1.63.2.2 christos void
100 1.63.2.2 christos panic(const char *fmt, ...)
101 1.63.2.2 christos {
102 1.63.2.2 christos va_list ap;
103 1.63.2.2 christos
104 1.63.2.2 christos va_start(ap, fmt);
105 1.63.2.2 christos printf("panic: ");
106 1.63.2.2 christos vprintf(fmt, ap);
107 1.63.2.2 christos va_end(ap);
108 1.63.2.2 christos printf("\n");
109 1.63.2.2 christos abort();
110 1.63.2.2 christos }
111 1.63.2.2 christos
112 1.63.2.2 christos void
113 1.63.2.2 christos log(int level, const char *fmt, ...)
114 1.63.2.2 christos {
115 1.63.2.2 christos va_list ap;
116 1.63.2.2 christos
117 1.63.2.2 christos va_start(ap, fmt);
118 1.63.2.2 christos vprintf(fmt, ap);
119 1.63.2.2 christos va_end(ap);
120 1.63.2.2 christos }
121 1.63.2.2 christos
122 1.63.2.2 christos void
123 1.63.2.2 christos vlog(int level, const char *fmt, va_list ap)
124 1.63.2.2 christos {
125 1.63.2.2 christos
126 1.63.2.2 christos vprintf(fmt, ap);
127 1.63.2.2 christos }
128 1.63.2.2 christos
129 1.63.2.2 christos void
130 1.63.2.2 christos uprintf(const char *fmt, ...)
131 1.63.2.2 christos {
132 1.63.2.2 christos va_list ap;
133 1.63.2.2 christos
134 1.63.2.2 christos va_start(ap, fmt);
135 1.63.2.2 christos vprintf(fmt, ap);
136 1.63.2.2 christos va_end(ap);
137 1.63.2.2 christos }
138 1.63.2.2 christos
139 1.63.2.2 christos /* relegate this to regular printf */
140 1.63.2.2 christos tpr_t
141 1.63.2.2 christos tprintf_open(struct proc *p)
142 1.63.2.2 christos {
143 1.63.2.2 christos
144 1.63.2.2 christos return (tpr_t)0x111;
145 1.63.2.2 christos }
146 1.63.2.2 christos
147 1.63.2.2 christos void
148 1.63.2.2 christos tprintf(tpr_t tpr, const char *fmt, ...)
149 1.63.2.2 christos {
150 1.63.2.2 christos va_list ap;
151 1.63.2.2 christos
152 1.63.2.2 christos va_start(ap, fmt);
153 1.63.2.2 christos vprintf(fmt, ap);
154 1.63.2.2 christos va_end(ap);
155 1.63.2.2 christos }
156 1.63.2.2 christos
157 1.63.2.2 christos void
158 1.63.2.2 christos tprintf_close(tpr_t tpr)
159 1.63.2.2 christos {
160 1.63.2.2 christos
161 1.63.2.2 christos }
162 1.63.2.2 christos
163 1.63.2.2 christos void
164 1.63.2.2 christos printf_nolog(const char *fmt, ...)
165 1.63.2.2 christos {
166 1.63.2.2 christos va_list ap;
167 1.63.2.2 christos
168 1.63.2.2 christos va_start(ap, fmt);
169 1.63.2.2 christos vprintf(fmt, ap);
170 1.63.2.2 christos va_end(ap);
171 1.63.2.2 christos }
172 1.63.2.2 christos
173 1.63.2.2 christos void
174 1.63.2.2 christos aprint_normal(const char *fmt, ...)
175 1.63.2.2 christos {
176 1.63.2.2 christos va_list ap;
177 1.63.2.2 christos
178 1.63.2.2 christos va_start(ap, fmt);
179 1.63.2.2 christos vprintf(fmt, ap);
180 1.63.2.2 christos va_end(ap);
181 1.63.2.2 christos }
182 1.63.2.2 christos
183 1.63.2.2 christos int
184 1.63.2.2 christos copyin(const void *uaddr, void *kaddr, size_t len)
185 1.63.2.2 christos {
186 1.63.2.2 christos
187 1.63.2.2 christos memcpy(kaddr, uaddr, len);
188 1.63.2.2 christos return 0;
189 1.63.2.2 christos }
190 1.63.2.2 christos
191 1.63.2.2 christos int
192 1.63.2.2 christos copyout(const void *kaddr, void *uaddr, size_t len)
193 1.63.2.2 christos {
194 1.63.2.2 christos
195 1.63.2.2 christos memcpy(uaddr, kaddr, len);
196 1.63.2.2 christos return 0;
197 1.63.2.2 christos }
198 1.63.2.2 christos
199 1.63.2.2 christos int
200 1.63.2.2 christos copystr(const void *kfaddr, void *kdaddr, size_t len, size_t *done)
201 1.63.2.2 christos {
202 1.63.2.2 christos
203 1.63.2.2 christos return copyinstr(kfaddr, kdaddr, len, done);
204 1.63.2.2 christos }
205 1.63.2.2 christos
206 1.63.2.2 christos int
207 1.63.2.2 christos copyinstr(const void *uaddr, void *kaddr, size_t len, size_t *done)
208 1.63.2.2 christos {
209 1.63.2.2 christos
210 1.63.2.2 christos strlcpy(kaddr, uaddr, len);
211 1.63.2.2 christos if (done)
212 1.63.2.2 christos *done = strlen(kaddr)+1; /* includes termination */
213 1.63.2.2 christos return 0;
214 1.63.2.2 christos }
215 1.63.2.2 christos
216 1.63.2.2 christos int
217 1.63.2.2 christos copyin_vmspace(struct vmspace *vm, const void *uaddr, void *kaddr, size_t len)
218 1.63.2.2 christos {
219 1.63.2.2 christos
220 1.63.2.2 christos return copyin(uaddr, kaddr, len);
221 1.63.2.2 christos }
222 1.63.2.2 christos
223 1.63.2.2 christos int
224 1.63.2.2 christos copyout_vmspace(struct vmspace *vm, const void *kaddr, void *uaddr, size_t len)
225 1.63.2.2 christos {
226 1.63.2.2 christos
227 1.63.2.2 christos return copyout(kaddr, uaddr, len);
228 1.63.2.2 christos }
229 1.63.2.2 christos
230 1.63.2.2 christos int
231 1.63.2.2 christos kcopy(const void *src, void *dst, size_t len)
232 1.63.2.2 christos {
233 1.63.2.2 christos
234 1.63.2.2 christos memcpy(dst, src, len);
235 1.63.2.2 christos return 0;
236 1.63.2.2 christos }
237 1.63.2.2 christos
238 1.63.2.2 christos int
239 1.63.2.2 christos uiomove(void *buf, size_t n, struct uio *uio)
240 1.63.2.2 christos {
241 1.63.2.2 christos struct iovec *iov;
242 1.63.2.2 christos uint8_t *b = buf;
243 1.63.2.2 christos size_t cnt;
244 1.63.2.2 christos
245 1.63.2.2 christos if (uio->uio_vmspace != UIO_VMSPACE_SYS)
246 1.63.2.2 christos panic("%s: vmspace != UIO_VMSPACE_SYS", __func__);
247 1.63.2.2 christos
248 1.63.2.2 christos while (n && uio->uio_resid) {
249 1.63.2.2 christos iov = uio->uio_iov;
250 1.63.2.2 christos cnt = iov->iov_len;
251 1.63.2.2 christos if (cnt == 0) {
252 1.63.2.2 christos uio->uio_iov++;
253 1.63.2.2 christos uio->uio_iovcnt--;
254 1.63.2.2 christos continue;
255 1.63.2.2 christos }
256 1.63.2.2 christos if (cnt > n)
257 1.63.2.2 christos cnt = n;
258 1.63.2.2 christos
259 1.63.2.2 christos if (uio->uio_rw == UIO_READ)
260 1.63.2.2 christos memcpy(iov->iov_base, b, cnt);
261 1.63.2.2 christos else
262 1.63.2.2 christos memcpy(b, iov->iov_base, cnt);
263 1.63.2.2 christos
264 1.63.2.2 christos iov->iov_base = (uint8_t *)iov->iov_base + cnt;
265 1.63.2.2 christos iov->iov_len -= cnt;
266 1.63.2.2 christos b += cnt;
267 1.63.2.2 christos uio->uio_resid -= cnt;
268 1.63.2.2 christos uio->uio_offset += cnt;
269 1.63.2.2 christos n -= cnt;
270 1.63.2.2 christos }
271 1.63.2.2 christos
272 1.63.2.2 christos return 0;
273 1.63.2.2 christos }
274 1.63.2.2 christos
275 1.63.2.2 christos void
276 1.63.2.2 christos uio_setup_sysspace(struct uio *uio)
277 1.63.2.2 christos {
278 1.63.2.2 christos
279 1.63.2.2 christos uio->uio_vmspace = UIO_VMSPACE_SYS;
280 1.63.2.2 christos }
281 1.63.2.2 christos
282 1.63.2.2 christos const struct bdevsw *
283 1.63.2.2 christos bdevsw_lookup(dev_t dev)
284 1.63.2.2 christos {
285 1.63.2.2 christos
286 1.63.2.2 christos return (const struct bdevsw *)1;
287 1.63.2.2 christos }
288 1.63.2.2 christos
289 1.63.2.2 christos devclass_t
290 1.63.2.2 christos device_class(device_t dev)
291 1.63.2.2 christos {
292 1.63.2.2 christos
293 1.63.2.2 christos if (dev != root_device)
294 1.63.2.2 christos panic("%s: dev != root_device not supported", __func__);
295 1.63.2.2 christos
296 1.63.2.2 christos return DV_DISK;
297 1.63.2.2 christos }
298 1.63.2.2 christos
299 1.63.2.2 christos void
300 1.63.2.2 christos getmicrouptime(struct timeval *tvp)
301 1.63.2.2 christos {
302 1.63.2.2 christos int error;
303 1.63.2.2 christos
304 1.63.2.2 christos rumpuser_gettimeofday(tvp, &error);
305 1.63.2.2 christos }
306 1.63.2.2 christos
307 1.63.2.2 christos void
308 1.63.2.2 christos malloc_type_attach(struct malloc_type *type)
309 1.63.2.2 christos {
310 1.63.2.2 christos
311 1.63.2.2 christos return;
312 1.63.2.2 christos }
313 1.63.2.2 christos
314 1.63.2.2 christos void
315 1.63.2.2 christos malloc_type_detach(struct malloc_type *type)
316 1.63.2.2 christos {
317 1.63.2.2 christos
318 1.63.2.2 christos return;
319 1.63.2.2 christos }
320 1.63.2.2 christos
321 1.63.2.2 christos void *
322 1.63.2.2 christos __wrap_malloc(unsigned long size, struct malloc_type *type, int flags)
323 1.63.2.2 christos {
324 1.63.2.2 christos void *rv;
325 1.63.2.2 christos
326 1.63.2.2 christos rv = rumpuser_malloc(size, (flags & (M_CANFAIL | M_NOWAIT)) != 0);
327 1.63.2.2 christos if (rv && flags & M_ZERO)
328 1.63.2.2 christos memset(rv, 0, size);
329 1.63.2.2 christos
330 1.63.2.2 christos return rv;
331 1.63.2.2 christos }
332 1.63.2.2 christos
333 1.63.2.2 christos void
334 1.63.2.2 christos nanotime(struct timespec *ts)
335 1.63.2.2 christos {
336 1.63.2.2 christos struct timeval tv;
337 1.63.2.2 christos int error;
338 1.63.2.2 christos
339 1.63.2.2 christos rumpuser_gettimeofday(&tv, &error);
340 1.63.2.2 christos TIMEVAL_TO_TIMESPEC(&tv, ts);
341 1.63.2.2 christos }
342 1.63.2.2 christos
343 1.63.2.2 christos /* hooray for mick, so what if I do */
344 1.63.2.2 christos void
345 1.63.2.2 christos getnanotime(struct timespec *ts)
346 1.63.2.2 christos {
347 1.63.2.2 christos
348 1.63.2.2 christos nanotime(ts);
349 1.63.2.2 christos }
350 1.63.2.2 christos
351 1.63.2.2 christos void
352 1.63.2.2 christos microtime(struct timeval *tv)
353 1.63.2.2 christos {
354 1.63.2.2 christos int error;
355 1.63.2.2 christos
356 1.63.2.2 christos rumpuser_gettimeofday(tv, &error);
357 1.63.2.2 christos }
358 1.63.2.2 christos
359 1.63.2.2 christos void
360 1.63.2.2 christos getmicrotime(struct timeval *tv)
361 1.63.2.2 christos {
362 1.63.2.2 christos int error;
363 1.63.2.2 christos
364 1.63.2.2 christos rumpuser_gettimeofday(tv, &error);
365 1.63.2.2 christos }
366 1.63.2.2 christos
367 1.63.2.2 christos void
368 1.63.2.2 christos bdev_strategy(struct buf *bp)
369 1.63.2.2 christos {
370 1.63.2.2 christos
371 1.63.2.2 christos panic("%s: not supported", __func__);
372 1.63.2.2 christos }
373 1.63.2.2 christos
374 1.63.2.2 christos int
375 1.63.2.2 christos bdev_type(dev_t dev)
376 1.63.2.2 christos {
377 1.63.2.2 christos
378 1.63.2.2 christos return D_DISK;
379 1.63.2.2 christos }
380 1.63.2.2 christos
381 1.63.2.2 christos struct kthdesc {
382 1.63.2.2 christos void (*f)(void *);
383 1.63.2.2 christos void *arg;
384 1.63.2.2 christos struct lwp *mylwp;
385 1.63.2.2 christos bool mpsafe;
386 1.63.2.2 christos };
387 1.63.2.2 christos
388 1.63.2.2 christos static void *
389 1.63.2.2 christos threadbouncer(void *arg)
390 1.63.2.2 christos {
391 1.63.2.2 christos struct kthdesc *k = arg;
392 1.63.2.2 christos void (*f)(void *);
393 1.63.2.2 christos void *thrarg;
394 1.63.2.2 christos
395 1.63.2.2 christos f = k->f;
396 1.63.2.2 christos thrarg = k->arg;
397 1.63.2.2 christos rumpuser_set_curlwp(k->mylwp);
398 1.63.2.2 christos kmem_free(k, sizeof(struct kthdesc));
399 1.63.2.2 christos
400 1.63.2.2 christos if (!k->mpsafe)
401 1.63.2.2 christos KERNEL_LOCK(1, NULL);
402 1.63.2.2 christos f(thrarg);
403 1.63.2.2 christos panic("unreachable, should kthread_exit()");
404 1.63.2.2 christos }
405 1.63.2.2 christos
406 1.63.2.2 christos int
407 1.63.2.2 christos kthread_create(pri_t pri, int flags, struct cpu_info *ci,
408 1.63.2.2 christos void (*func)(void *), void *arg, lwp_t **newlp, const char *fmt, ...)
409 1.63.2.2 christos {
410 1.63.2.2 christos char thrstore[MAXCOMLEN];
411 1.63.2.2 christos const char *thrname = NULL;
412 1.63.2.2 christos va_list ap;
413 1.63.2.2 christos struct kthdesc *k;
414 1.63.2.2 christos struct lwp *l;
415 1.63.2.2 christos int rv;
416 1.63.2.2 christos
417 1.63.2.2 christos /*
418 1.63.2.2 christos * We don't want a module unload thread.
419 1.63.2.2 christos * (XXX: yes, this is a kludge too, and the kernel should
420 1.63.2.2 christos * have a more flexible method for configuring which threads
421 1.63.2.2 christos * we want).
422 1.63.2.2 christos */
423 1.63.2.2 christos if (strcmp(fmt, "modunload") == 0) {
424 1.63.2.2 christos return 0;
425 1.63.2.2 christos }
426 1.63.2.2 christos
427 1.63.2.2 christos if (!rump_threads) {
428 1.63.2.2 christos /* fake them */
429 1.63.2.2 christos if (strcmp(fmt, "vrele") == 0) {
430 1.63.2.2 christos printf("rump warning: threads not enabled, not starting"
431 1.63.2.2 christos " vrele thread\n");
432 1.63.2.2 christos return 0;
433 1.63.2.2 christos } else if (strcmp(fmt, "cachegc") == 0) {
434 1.63.2.2 christos printf("rump warning: threads not enabled, not starting"
435 1.63.2.2 christos " namecache g/c thread\n");
436 1.63.2.2 christos return 0;
437 1.63.2.2 christos } else
438 1.63.2.2 christos panic("threads not available, setenv RUMP_THREADS 1");
439 1.63.2.2 christos }
440 1.63.2.2 christos
441 1.63.2.2 christos KASSERT(fmt != NULL);
442 1.63.2.2 christos if (ci != NULL)
443 1.63.2.2 christos panic("%s: bounded threads not supported", __func__);
444 1.63.2.2 christos
445 1.63.2.2 christos k = kmem_alloc(sizeof(struct kthdesc), KM_SLEEP);
446 1.63.2.2 christos k->f = func;
447 1.63.2.2 christos k->arg = arg;
448 1.63.2.2 christos k->mylwp = l = rump_setup_curlwp(0, rump_nextlid(), 0);
449 1.63.2.2 christos k->mpsafe = flags & KTHREAD_MPSAFE;
450 1.63.2.2 christos if (fmt) {
451 1.63.2.2 christos va_start(ap, fmt);
452 1.63.2.2 christos vsnprintf(thrstore, sizeof(thrname), fmt, ap);
453 1.63.2.2 christos va_end(ap);
454 1.63.2.2 christos thrname = thrstore;
455 1.63.2.2 christos }
456 1.63.2.2 christos rv = rumpuser_thread_create(threadbouncer, k, thrname);
457 1.63.2.2 christos if (rv)
458 1.63.2.2 christos return rv;
459 1.63.2.2 christos
460 1.63.2.2 christos if (newlp)
461 1.63.2.2 christos *newlp = l;
462 1.63.2.2 christos return 0;
463 1.63.2.2 christos }
464 1.63.2.2 christos
465 1.63.2.2 christos void
466 1.63.2.2 christos kthread_exit(int ecode)
467 1.63.2.2 christos {
468 1.63.2.2 christos
469 1.63.2.2 christos panic("FIXME: kthread_exit() does not support mpsafe locking");
470 1.63.2.2 christos rumpuser_thread_exit();
471 1.63.2.2 christos }
472 1.63.2.2 christos
473 1.63.2.2 christos struct proc *
474 1.63.2.2 christos p_find(pid_t pid, uint flags)
475 1.63.2.2 christos {
476 1.63.2.2 christos
477 1.63.2.2 christos panic("%s: not implemented", __func__);
478 1.63.2.2 christos }
479 1.63.2.2 christos
480 1.63.2.2 christos struct pgrp *
481 1.63.2.2 christos pg_find(pid_t pid, uint flags)
482 1.63.2.2 christos {
483 1.63.2.2 christos
484 1.63.2.2 christos panic("%s: not implemented", __func__);
485 1.63.2.2 christos }
486 1.63.2.2 christos
487 1.63.2.2 christos void
488 1.63.2.2 christos psignal(struct proc *p, int signo)
489 1.63.2.2 christos {
490 1.63.2.2 christos
491 1.63.2.2 christos switch (signo) {
492 1.63.2.2 christos case SIGSYS:
493 1.63.2.2 christos break;
494 1.63.2.2 christos default:
495 1.63.2.2 christos panic("unhandled signal %d", signo);
496 1.63.2.2 christos }
497 1.63.2.2 christos }
498 1.63.2.2 christos
499 1.63.2.2 christos void
500 1.63.2.2 christos kpsignal(struct proc *p, ksiginfo_t *ksi, void *data)
501 1.63.2.2 christos {
502 1.63.2.2 christos
503 1.63.2.2 christos panic("%s: not implemented", __func__);
504 1.63.2.2 christos }
505 1.63.2.2 christos
506 1.63.2.2 christos void
507 1.63.2.2 christos kpgsignal(struct pgrp *pgrp, ksiginfo_t *ksi, void *data, int checkctty)
508 1.63.2.2 christos {
509 1.63.2.2 christos
510 1.63.2.2 christos panic("%s: not implemented", __func__);
511 1.63.2.2 christos }
512 1.63.2.2 christos
513 1.63.2.2 christos int
514 1.63.2.2 christos pgid_in_session(struct proc *p, pid_t pg_id)
515 1.63.2.2 christos {
516 1.63.2.2 christos
517 1.63.2.2 christos panic("%s: not implemented", __func__);
518 1.63.2.2 christos }
519 1.63.2.2 christos
520 1.63.2.2 christos int
521 1.63.2.2 christos sigispending(struct lwp *l, int signo)
522 1.63.2.2 christos {
523 1.63.2.2 christos
524 1.63.2.2 christos return 0;
525 1.63.2.2 christos }
526 1.63.2.2 christos
527 1.63.2.2 christos void
528 1.63.2.2 christos sigpending1(struct lwp *l, sigset_t *ss)
529 1.63.2.2 christos {
530 1.63.2.2 christos
531 1.63.2.2 christos panic("%s: not implemented", __func__);
532 1.63.2.2 christos }
533 1.63.2.2 christos
534 1.63.2.2 christos void
535 1.63.2.2 christos knote_fdclose(int fd)
536 1.63.2.2 christos {
537 1.63.2.2 christos
538 1.63.2.2 christos /* since we don't add knotes, we don't have to remove them */
539 1.63.2.2 christos }
540 1.63.2.2 christos
541 1.63.2.2 christos int
542 1.63.2.2 christos seltrue_kqfilter(dev_t dev, struct knote *kn)
543 1.63.2.2 christos {
544 1.63.2.2 christos
545 1.63.2.2 christos panic("%s: not implemented", __func__);
546 1.63.2.2 christos }
547 1.63.2.2 christos
548 1.63.2.2 christos int
549 1.63.2.2 christos kpause(const char *wmesg, bool intr, int timeo, kmutex_t *mtx)
550 1.63.2.2 christos {
551 1.63.2.2 christos extern int hz;
552 1.63.2.2 christos int rv, error;
553 1.63.2.2 christos struct timespec time;
554 1.63.2.2 christos
555 1.63.2.2 christos if (mtx)
556 1.63.2.2 christos mutex_exit(mtx);
557 1.63.2.2 christos
558 1.63.2.2 christos time.tv_sec = timeo / hz;
559 1.63.2.2 christos time.tv_nsec = (timeo % hz) * (1000000000 / hz);
560 1.63.2.2 christos
561 1.63.2.2 christos rv = rumpuser_nanosleep(&time, NULL, &error);
562 1.63.2.2 christos
563 1.63.2.2 christos if (mtx)
564 1.63.2.2 christos mutex_enter(mtx);
565 1.63.2.2 christos
566 1.63.2.2 christos if (rv)
567 1.63.2.2 christos return error;
568 1.63.2.2 christos
569 1.63.2.2 christos return 0;
570 1.63.2.2 christos }
571 1.63.2.2 christos
572 1.63.2.2 christos void
573 1.63.2.2 christos suspendsched()
574 1.63.2.2 christos {
575 1.63.2.2 christos
576 1.63.2.2 christos panic("%s: not implemented", __func__);
577 1.63.2.2 christos }
578 1.63.2.2 christos
579 1.63.2.2 christos u_int
580 1.63.2.2 christos lwp_unsleep(lwp_t *l, bool cleanup)
581 1.63.2.2 christos {
582 1.63.2.2 christos
583 1.63.2.2 christos KASSERT(mutex_owned(l->l_mutex));
584 1.63.2.2 christos
585 1.63.2.2 christos return (*l->l_syncobj->sobj_unsleep)(l, cleanup);
586 1.63.2.2 christos }
587 1.63.2.2 christos
588 1.63.2.2 christos vaddr_t
589 1.63.2.2 christos calc_cache_size(struct vm_map *map, int pct, int va_pct)
590 1.63.2.2 christos {
591 1.63.2.2 christos paddr_t t;
592 1.63.2.2 christos
593 1.63.2.2 christos t = (paddr_t)physmem * pct / 100 * PAGE_SIZE;
594 1.63.2.2 christos if ((vaddr_t)t != t) {
595 1.63.2.2 christos panic("%s: needs tweak", __func__);
596 1.63.2.2 christos }
597 1.63.2.2 christos return t;
598 1.63.2.2 christos }
599 1.63.2.2 christos
600 1.63.2.2 christos int
601 1.63.2.2 christos seltrue(dev_t dev, int events, struct lwp *l)
602 1.63.2.2 christos {
603 1.63.2.2 christos return (events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM));
604 1.63.2.2 christos }
605 1.63.2.2 christos
606 1.63.2.2 christos void
607 1.63.2.2 christos selrecord(lwp_t *selector, struct selinfo *sip)
608 1.63.2.2 christos {
609 1.63.2.2 christos }
610 1.63.2.2 christos
611 1.63.2.2 christos void
612 1.63.2.2 christos selinit(struct selinfo *sip)
613 1.63.2.2 christos {
614 1.63.2.2 christos }
615 1.63.2.2 christos
616 1.63.2.2 christos void
617 1.63.2.2 christos selnotify(struct selinfo *sip, int events, long knhint)
618 1.63.2.2 christos {
619 1.63.2.2 christos }
620 1.63.2.2 christos
621 1.63.2.2 christos void
622 1.63.2.2 christos seldestroy(struct selinfo *sip)
623 1.63.2.2 christos {
624 1.63.2.2 christos }
625 1.63.2.2 christos
626 1.63.2.2 christos const char *
627 1.63.2.2 christos device_xname(device_t dv)
628 1.63.2.2 christos {
629 1.63.2.2 christos return "bogus0";
630 1.63.2.2 christos }
631 1.63.2.2 christos
632 1.63.2.2 christos void
633 1.63.2.2 christos assert_sleepable(void)
634 1.63.2.2 christos {
635 1.63.2.2 christos
636 1.63.2.2 christos /* always sleepable, although we should improve this */
637 1.63.2.2 christos }
638 1.63.2.2 christos
639 1.63.2.2 christos int
640 1.63.2.2 christos devsw_attach(const char *devname, const struct bdevsw *bdev, int *bmajor,
641 1.63.2.2 christos const struct cdevsw *cdev, int *cmajor)
642 1.63.2.2 christos {
643 1.63.2.2 christos
644 1.63.2.2 christos panic("%s: not implemented", __func__);
645 1.63.2.2 christos }
646 1.63.2.2 christos
647 1.63.2.2 christos int
648 1.63.2.2 christos devsw_detach(const struct bdevsw *bdev, const struct cdevsw *cdev)
649 1.63.2.2 christos {
650 1.63.2.2 christos
651 1.63.2.2 christos panic("%s: not implemented", __func__);
652 1.63.2.2 christos }
653 1.63.2.2 christos
654 1.63.2.2 christos void
655 1.63.2.2 christos tc_setclock(const struct timespec *ts)
656 1.63.2.2 christos {
657 1.63.2.2 christos
658 1.63.2.2 christos panic("%s: not implemented", __func__);
659 1.63.2.2 christos }
660 1.63.2.2 christos
661 1.63.2.2 christos void
662 1.63.2.2 christos proc_crmod_enter()
663 1.63.2.2 christos {
664 1.63.2.2 christos
665 1.63.2.2 christos panic("%s: not implemented", __func__);
666 1.63.2.2 christos }
667 1.63.2.2 christos
668 1.63.2.2 christos void
669 1.63.2.2 christos proc_crmod_leave(kauth_cred_t c1, kauth_cred_t c2, bool sugid)
670 1.63.2.2 christos {
671 1.63.2.2 christos
672 1.63.2.2 christos panic("%s: not implemented", __func__);
673 1.63.2.2 christos }
674 1.63.2.2 christos
675 1.63.2.2 christos /*
676 1.63.2.2 christos * Byteswap is in slightly bad taste linked directly against libc.
677 1.63.2.2 christos * In case our machine uses namespace-renamed symbols, provide
678 1.63.2.2 christos * an escape route. We really should be including libkern, but
679 1.63.2.2 christos * leave that to a later date.
680 1.63.2.2 christos */
681 1.63.2.2 christos #ifdef __BSWAP_RENAME
682 1.63.2.2 christos #undef bswap16
683 1.63.2.2 christos #undef bswap32
684 1.63.2.2 christos uint16_t __bswap16(uint16_t);
685 1.63.2.2 christos uint32_t __bswap32(uint32_t);
686 1.63.2.2 christos
687 1.63.2.2 christos uint16_t
688 1.63.2.2 christos bswap16(uint16_t v)
689 1.63.2.2 christos {
690 1.63.2.2 christos
691 1.63.2.2 christos return __bswap16(v);
692 1.63.2.2 christos }
693 1.63.2.2 christos
694 1.63.2.2 christos uint32_t
695 1.63.2.2 christos bswap32(uint32_t v)
696 1.63.2.2 christos {
697 1.63.2.2 christos
698 1.63.2.2 christos return __bswap32(v);
699 1.63.2.2 christos }
700 1.63.2.2 christos #endif /* __BSWAP_RENAME */
701