Attach implicit threads to initproc instead of proc0. This way applications which alter, by purpose or by accident, the uid in an implicit thread are don't affect kernel threads. from discussion with njolydiff -r1.206 -r1.207 src/sys/kern/kern_descrip.c
(pooka)
--- src/sys/kern/kern_descrip.c 2010/09/01 15:15:18 1.206
+++ src/sys/kern/kern_descrip.c 2010/10/29 15:32:23 1.207
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: kern_descrip.c,v 1.206 2010/09/01 15:15:18 pooka Exp $ */ | 1 | /* $NetBSD: kern_descrip.c,v 1.207 2010/10/29 15:32:23 pooka Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to The NetBSD Foundation | 7 | * This code is derived from software contributed to The NetBSD Foundation | |
8 | * by Andrew Doran. | 8 | * by Andrew Doran. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -60,27 +60,27 @@ | @@ -60,27 +60,27 @@ | |||
60 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 60 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
61 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 61 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
62 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 62 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
63 | * SUCH DAMAGE. | 63 | * SUCH DAMAGE. | |
64 | * | 64 | * | |
65 | * @(#)kern_descrip.c 8.8 (Berkeley) 2/14/95 | 65 | * @(#)kern_descrip.c 8.8 (Berkeley) 2/14/95 | |
66 | */ | 66 | */ | |
67 | 67 | |||
68 | /* | 68 | /* | |
69 | * File descriptor management. | 69 | * File descriptor management. | |
70 | */ | 70 | */ | |
71 | 71 | |||
72 | #include <sys/cdefs.h> | 72 | #include <sys/cdefs.h> | |
73 | __KERNEL_RCSID(0, "$NetBSD: kern_descrip.c,v 1.206 2010/09/01 15:15:18 pooka Exp $"); | 73 | __KERNEL_RCSID(0, "$NetBSD: kern_descrip.c,v 1.207 2010/10/29 15:32:23 pooka Exp $"); | |
74 | 74 | |||
75 | #include <sys/param.h> | 75 | #include <sys/param.h> | |
76 | #include <sys/systm.h> | 76 | #include <sys/systm.h> | |
77 | #include <sys/filedesc.h> | 77 | #include <sys/filedesc.h> | |
78 | #include <sys/kernel.h> | 78 | #include <sys/kernel.h> | |
79 | #include <sys/proc.h> | 79 | #include <sys/proc.h> | |
80 | #include <sys/file.h> | 80 | #include <sys/file.h> | |
81 | #include <sys/socket.h> | 81 | #include <sys/socket.h> | |
82 | #include <sys/socketvar.h> | 82 | #include <sys/socketvar.h> | |
83 | #include <sys/stat.h> | 83 | #include <sys/stat.h> | |
84 | #include <sys/ioctl.h> | 84 | #include <sys/ioctl.h> | |
85 | #include <sys/fcntl.h> | 85 | #include <sys/fcntl.h> | |
86 | #include <sys/pool.h> | 86 | #include <sys/pool.h> | |
@@ -1329,27 +1329,26 @@ fd_share(struct proc *p2) | @@ -1329,27 +1329,26 @@ fd_share(struct proc *p2) | |||
1329 | fdp = curlwp->l_fd; | 1329 | fdp = curlwp->l_fd; | |
1330 | p2->p_fd = fdp; | 1330 | p2->p_fd = fdp; | |
1331 | atomic_inc_uint(&fdp->fd_refcnt); | 1331 | atomic_inc_uint(&fdp->fd_refcnt); | |
1332 | } | 1332 | } | |
1333 | 1333 | |||
1334 | /* | 1334 | /* | |
1335 | * Acquire a hold on a filedesc structure. | 1335 | * Acquire a hold on a filedesc structure. | |
1336 | */ | 1336 | */ | |
1337 | void | 1337 | void | |
1338 | fd_hold(lwp_t *l) | 1338 | fd_hold(lwp_t *l) | |
1339 | { | 1339 | { | |
1340 | filedesc_t *fdp = l->l_fd; | 1340 | filedesc_t *fdp = l->l_fd; | |
1341 | 1341 | |||
1342 | KASSERT(fdp == curlwp->l_fd || fdp == lwp0.l_fd); | |||
1343 | atomic_inc_uint(&fdp->fd_refcnt); | 1342 | atomic_inc_uint(&fdp->fd_refcnt); | |
1344 | } | 1343 | } | |
1345 | 1344 | |||
1346 | /* | 1345 | /* | |
1347 | * Copy a filedesc structure. | 1346 | * Copy a filedesc structure. | |
1348 | */ | 1347 | */ | |
1349 | filedesc_t * | 1348 | filedesc_t * | |
1350 | fd_copy(void) | 1349 | fd_copy(void) | |
1351 | { | 1350 | { | |
1352 | filedesc_t *newfdp, *fdp; | 1351 | filedesc_t *newfdp, *fdp; | |
1353 | fdfile_t *ff, **ffp, **nffp, *ff2; | 1352 | fdfile_t *ff, **ffp, **nffp, *ff2; | |
1354 | int i, j, numfiles, lastfile, newlast; | 1353 | int i, j, numfiles, lastfile, newlast; | |
1355 | file_t *fp; | 1354 | file_t *fp; |
--- src/sys/rump/librump/rumpkern/lwproc.c 2010/09/01 21:16:56 1.2
+++ src/sys/rump/librump/rumpkern/lwproc.c 2010/10/29 15:32:24 1.3
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: lwproc.c,v 1.2 2010/09/01 21:16:56 pooka Exp $ */ | 1 | /* $NetBSD: lwproc.c,v 1.3 2010/10/29 15:32:24 pooka Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2010 Antti Kantee. All Rights Reserved. | 4 | * Copyright (c) 2010 Antti Kantee. All Rights Reserved. | |
5 | * | 5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | 6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions | 7 | * modification, are permitted provided that the following conditions | |
8 | * are met: | 8 | * are met: | |
9 | * 1. Redistributions of source code must retain the above copyright | 9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | 10 | * notice, this list of conditions and the following disclaimer. | |
11 | * 2. Redistributions in binary form must reproduce the above copyright | 11 | * 2. Redistributions in binary form must reproduce the above copyright | |
12 | * notice, this list of conditions and the following disclaimer in the | 12 | * notice, this list of conditions and the following disclaimer in the | |
13 | * documentation and/or other materials provided with the distribution. | 13 | * documentation and/or other materials provided with the distribution. | |
14 | * | 14 | * | |
@@ -16,27 +16,27 @@ | @@ -16,27 +16,27 @@ | |||
16 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 16 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
18 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | 18 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | |
19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
25 | * SUCH DAMAGE. | 25 | * SUCH DAMAGE. | |
26 | */ | 26 | */ | |
27 | 27 | |||
28 | #include <sys/cdefs.h> | 28 | #include <sys/cdefs.h> | |
29 | __KERNEL_RCSID(0, "$NetBSD: lwproc.c,v 1.2 2010/09/01 21:16:56 pooka Exp $"); | 29 | __KERNEL_RCSID(0, "$NetBSD: lwproc.c,v 1.3 2010/10/29 15:32:24 pooka Exp $"); | |
30 | 30 | |||
31 | #include <sys/param.h> | 31 | #include <sys/param.h> | |
32 | #include <sys/atomic.h> | 32 | #include <sys/atomic.h> | |
33 | #include <sys/filedesc.h> | 33 | #include <sys/filedesc.h> | |
34 | #include <sys/kauth.h> | 34 | #include <sys/kauth.h> | |
35 | #include <sys/kmem.h> | 35 | #include <sys/kmem.h> | |
36 | #include <sys/lwp.h> | 36 | #include <sys/lwp.h> | |
37 | #include <sys/pool.h> | 37 | #include <sys/pool.h> | |
38 | #include <sys/proc.h> | 38 | #include <sys/proc.h> | |
39 | #include <sys/queue.h> | 39 | #include <sys/queue.h> | |
40 | #include <sys/resourcevar.h> | 40 | #include <sys/resourcevar.h> | |
41 | #include <sys/uidinfo.h> | 41 | #include <sys/uidinfo.h> | |
42 | 42 | |||
@@ -212,36 +212,40 @@ lwproc_makelwp(struct proc *p, struct lw | @@ -212,36 +212,40 @@ lwproc_makelwp(struct proc *p, struct lw | |||
212 | } | 212 | } | |
213 | 213 | |||
214 | /* filedesc already has refcount 1 when process is created */ | 214 | /* filedesc already has refcount 1 when process is created */ | |
215 | if (!procmake) { | 215 | if (!procmake) { | |
216 | fd_hold(l); | 216 | fd_hold(l); | |
217 | } | 217 | } | |
218 | 218 | |||
219 | mutex_enter(proc_lock); | 219 | mutex_enter(proc_lock); | |
220 | LIST_INSERT_HEAD(&alllwp, l, l_list); | 220 | LIST_INSERT_HEAD(&alllwp, l, l_list); | |
221 | mutex_exit(proc_lock); | 221 | mutex_exit(proc_lock); | |
222 | } | 222 | } | |
223 | 223 | |||
224 | struct lwp * | 224 | struct lwp * | |
225 | rump__lwproc_allockernlwp(void) | 225 | rump__lwproc_alloclwp(struct proc *p) | |
226 | { | 226 | { | |
227 | struct proc *p; | |||
228 | struct lwp *l; | 227 | struct lwp *l; | |
228 | bool newproc = false; | |||
229 | ||||
230 | if (p == NULL) { | |||
231 | p = lwproc_newproc(&proc0); | |||
232 | newproc = true; | |||
233 | } | |||
229 | 234 | |||
230 | l = kmem_zalloc(sizeof(*l), KM_SLEEP); | 235 | l = kmem_zalloc(sizeof(*l), KM_SLEEP); | |
231 | 236 | |||
232 | p = &proc0; | |||
233 | mutex_enter(p->p_lock); | 237 | mutex_enter(p->p_lock); | |
234 | lwproc_makelwp(p, l, false, false); | 238 | lwproc_makelwp(p, l, false, newproc); | |
235 | 239 | |||
236 | return l; | 240 | return l; | |
237 | } | 241 | } | |
238 | 242 | |||
239 | int | 243 | int | |
240 | rump_lwproc_newlwp(pid_t pid) | 244 | rump_lwproc_newlwp(pid_t pid) | |
241 | { | 245 | { | |
242 | struct proc *p; | 246 | struct proc *p; | |
243 | struct lwp *l; | 247 | struct lwp *l; | |
244 | 248 | |||
245 | l = kmem_zalloc(sizeof(*l), KM_SLEEP); | 249 | l = kmem_zalloc(sizeof(*l), KM_SLEEP); | |
246 | mutex_enter(proc_lock); | 250 | mutex_enter(proc_lock); | |
247 | p = proc_find_raw(pid); | 251 | p = proc_find_raw(pid); |
--- src/sys/rump/librump/rumpkern/rump.c 2010/10/28 11:30:07 1.192
+++ src/sys/rump/librump/rumpkern/rump.c 2010/10/29 15:32:24 1.193
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: rump.c,v 1.192 2010/10/28 11:30:07 pooka Exp $ */ | 1 | /* $NetBSD: rump.c,v 1.193 2010/10/29 15:32:24 pooka Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2007 Antti Kantee. All Rights Reserved. | 4 | * Copyright (c) 2007 Antti Kantee. All Rights Reserved. | |
5 | * | 5 | * | |
6 | * Development of this software was supported by Google Summer of Code. | 6 | * Development of this software was supported by Google Summer of Code. | |
7 | * | 7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | 8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions | 9 | * modification, are permitted provided that the following conditions | |
10 | * are met: | 10 | * are met: | |
11 | * 1. Redistributions of source code must retain the above copyright | 11 | * 1. Redistributions of source code must retain the above copyright | |
12 | * notice, this list of conditions and the following disclaimer. | 12 | * notice, this list of conditions and the following disclaimer. | |
13 | * 2. Redistributions in binary form must reproduce the above copyright | 13 | * 2. Redistributions in binary form must reproduce the above copyright | |
14 | * notice, this list of conditions and the following disclaimer in the | 14 | * notice, this list of conditions and the following disclaimer in the | |
@@ -18,27 +18,27 @@ | @@ -18,27 +18,27 @@ | |||
18 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 18 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
19 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 19 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
20 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | 20 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | |
21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
23 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 23 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 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 | 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 | 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
27 | * SUCH DAMAGE. | 27 | * SUCH DAMAGE. | |
28 | */ | 28 | */ | |
29 | 29 | |||
30 | #include <sys/cdefs.h> | 30 | #include <sys/cdefs.h> | |
31 | __KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.192 2010/10/28 11:30:07 pooka Exp $"); | 31 | __KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.193 2010/10/29 15:32:24 pooka Exp $"); | |
32 | 32 | |||
33 | #include <sys/systm.h> | 33 | #include <sys/systm.h> | |
34 | #define ELFSIZE ARCH_ELFSIZE | 34 | #define ELFSIZE ARCH_ELFSIZE | |
35 | 35 | |||
36 | #include <sys/param.h> | 36 | #include <sys/param.h> | |
37 | #include <sys/atomic.h> | 37 | #include <sys/atomic.h> | |
38 | #include <sys/buf.h> | 38 | #include <sys/buf.h> | |
39 | #include <sys/callout.h> | 39 | #include <sys/callout.h> | |
40 | #include <sys/conf.h> | 40 | #include <sys/conf.h> | |
41 | #include <sys/cpu.h> | 41 | #include <sys/cpu.h> | |
42 | #include <sys/device.h> | 42 | #include <sys/device.h> | |
43 | #include <sys/evcnt.h> | 43 | #include <sys/evcnt.h> | |
44 | #include <sys/event.h> | 44 | #include <sys/event.h> | |
@@ -76,28 +76,27 @@ __KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.1 | @@ -76,28 +76,27 @@ __KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.1 | |||
76 | 76 | |||
77 | #include <prop/proplib.h> | 77 | #include <prop/proplib.h> | |
78 | 78 | |||
79 | #include <uvm/uvm_extern.h> | 79 | #include <uvm/uvm_extern.h> | |
80 | #include <uvm/uvm_readahead.h> | 80 | #include <uvm/uvm_readahead.h> | |
81 | 81 | |||
82 | #include "rump_private.h" | 82 | #include "rump_private.h" | |
83 | #include "rump_net_private.h" | 83 | #include "rump_net_private.h" | |
84 | #include "rump_vfs_private.h" | 84 | #include "rump_vfs_private.h" | |
85 | #include "rump_dev_private.h" | 85 | #include "rump_dev_private.h" | |
86 | 86 | |||
87 | char machine[] = MACHINE; | 87 | char machine[] = MACHINE; | |
88 | 88 | |||
89 | /* pretend the master rump proc is init */ | 89 | struct proc *initproc; | |
90 | struct proc *initproc = &proc0; | |||
91 | 90 | |||
92 | struct rumpuser_mtx *rump_giantlock; | 91 | struct rumpuser_mtx *rump_giantlock; | |
93 | 92 | |||
94 | struct device rump_rootdev = { | 93 | struct device rump_rootdev = { | |
95 | .dv_class = DV_VIRTUAL | 94 | .dv_class = DV_VIRTUAL | |
96 | }; | 95 | }; | |
97 | 96 | |||
98 | #ifdef RUMP_WITHOUT_THREADS | 97 | #ifdef RUMP_WITHOUT_THREADS | |
99 | int rump_threads = 0; | 98 | int rump_threads = 0; | |
100 | #else | 99 | #else | |
101 | int rump_threads = 1; | 100 | int rump_threads = 1; | |
102 | #endif | 101 | #endif | |
103 | 102 | |||
@@ -312,29 +311,30 @@ rump__init(int rump_version) | @@ -312,29 +311,30 @@ rump__init(int rump_version) | |||
312 | 311 | |||
313 | procinit(); | 312 | procinit(); | |
314 | proc0_init(); | 313 | proc0_init(); | |
315 | uid_init(); | 314 | uid_init(); | |
316 | chgproccnt(0, 1); | 315 | chgproccnt(0, 1); | |
317 | 316 | |||
318 | l->l_proc = &proc0; | 317 | l->l_proc = &proc0; | |
319 | lwp_update_creds(l); | 318 | lwp_update_creds(l); | |
320 | 319 | |||
321 | lwpinit_specificdata(); | 320 | lwpinit_specificdata(); | |
322 | lwp_initspecific(&lwp0); | 321 | lwp_initspecific(&lwp0); | |
323 | 322 | |||
324 | rump_scheduler_init(numcpu); | 323 | rump_scheduler_init(numcpu); | |
325 | /* revert temporary context and schedule a real context */ | 324 | /* revert temporary context and schedule a semireal context */ | |
326 | l->l_cpu = NULL; | 325 | l->l_cpu = NULL; | |
327 | rumpuser_set_curlwp(NULL); | 326 | rumpuser_set_curlwp(NULL); | |
327 | initproc = &proc0; /* borrow proc0 before we get initproc started */ | |||
328 | rump_schedule(); | 328 | rump_schedule(); | |
329 | 329 | |||
330 | percpu_init(); | 330 | percpu_init(); | |
331 | inittimecounter(); | 331 | inittimecounter(); | |
332 | ntp_init(); | 332 | ntp_init(); | |
333 | 333 | |||
334 | rumpuser_gettime(&sec, &nsec, &error); | 334 | rumpuser_gettime(&sec, &nsec, &error); | |
335 | ts.tv_sec = sec; | 335 | ts.tv_sec = sec; | |
336 | ts.tv_nsec = nsec; | 336 | ts.tv_nsec = nsec; | |
337 | tc_setclock(&ts); | 337 | tc_setclock(&ts); | |
338 | 338 | |||
339 | /* we are mostly go. do per-cpu subsystem init */ | 339 | /* we are mostly go. do per-cpu subsystem init */ | |
340 | for (i = 0; i < numcpu; i++) { | 340 | for (i = 0; i < numcpu; i++) { | |
@@ -397,26 +397,38 @@ rump__init(int rump_version) | @@ -397,26 +397,38 @@ rump__init(int rump_version) | |||
397 | 397 | |||
398 | sysctl_finalize(); | 398 | sysctl_finalize(); | |
399 | 399 | |||
400 | module_init_class(MODULE_CLASS_ANY); | 400 | module_init_class(MODULE_CLASS_ANY); | |
401 | 401 | |||
402 | rumpuser_gethostname(hostname, MAXHOSTNAMELEN, &error); | 402 | rumpuser_gethostname(hostname, MAXHOSTNAMELEN, &error); | |
403 | hostnamelen = strlen(hostname); | 403 | hostnamelen = strlen(hostname); | |
404 | 404 | |||
405 | sigemptyset(&sigcantmask); | 405 | sigemptyset(&sigcantmask); | |
406 | 406 | |||
407 | if (rump_threads) | 407 | if (rump_threads) | |
408 | vmem_rehash_start(); | 408 | vmem_rehash_start(); | |
409 | 409 | |||
410 | /* | |||
411 | * Create init, used to attach implicit threads in rump. | |||
412 | * (note: must be done after vfsinit to get cwdi) | |||
413 | */ | |||
414 | (void)rump__lwproc_alloclwp(NULL); /* dummy thread for initproc */ | |||
415 | mutex_enter(proc_lock); | |||
416 | initproc = proc_find_raw(1); | |||
417 | mutex_exit(proc_lock); | |||
418 | if (initproc == NULL) | |||
419 | panic("where in the world is initproc?"); | |||
420 | ||||
421 | /* release cpu */ | |||
410 | rump_unschedule(); | 422 | rump_unschedule(); | |
411 | 423 | |||
412 | return 0; | 424 | return 0; | |
413 | } | 425 | } | |
414 | 426 | |||
415 | /* maybe support sys_reboot some day for remote shutdown */ | 427 | /* maybe support sys_reboot some day for remote shutdown */ | |
416 | void | 428 | void | |
417 | rump_reboot(int howto) | 429 | rump_reboot(int howto) | |
418 | { | 430 | { | |
419 | 431 | |||
420 | /* dump means we really take the dive here */ | 432 | /* dump means we really take the dive here */ | |
421 | if ((howto & RB_DUMP) || panicstr) { | 433 | if ((howto & RB_DUMP) || panicstr) { | |
422 | rumpuser_exit(RUMPUSER_PANIC); | 434 | rumpuser_exit(RUMPUSER_PANIC); |
--- src/sys/rump/librump/rumpkern/rump_private.h 2010/10/27 20:44:49 1.59
+++ src/sys/rump/librump/rumpkern/rump_private.h 2010/10/29 15:32:24 1.60
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: rump_private.h,v 1.59 2010/10/27 20:44:49 pooka Exp $ */ | 1 | /* $NetBSD: rump_private.h,v 1.60 2010/10/29 15:32:24 pooka Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2007 Antti Kantee. All Rights Reserved. | 4 | * Copyright (c) 2007 Antti Kantee. All Rights Reserved. | |
5 | * | 5 | * | |
6 | * Development of this software was supported by Google Summer of Code. | 6 | * Development of this software was supported by Google Summer of Code. | |
7 | * | 7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | 8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions | 9 | * modification, are permitted provided that the following conditions | |
10 | * are met: | 10 | * are met: | |
11 | * 1. Redistributions of source code must retain the above copyright | 11 | * 1. Redistributions of source code must retain the above copyright | |
12 | * notice, this list of conditions and the following disclaimer. | 12 | * notice, this list of conditions and the following disclaimer. | |
13 | * 2. Redistributions in binary form must reproduce the above copyright | 13 | * 2. Redistributions in binary form must reproduce the above copyright | |
14 | * notice, this list of conditions and the following disclaimer in the | 14 | * notice, this list of conditions and the following disclaimer in the | |
@@ -95,27 +95,27 @@ int rump_component_count(enum rump_comp | @@ -95,27 +95,27 @@ int rump_component_count(enum rump_comp | |||
95 | 95 | |||
96 | void rump_gettime(struct timespec *); | 96 | void rump_gettime(struct timespec *); | |
97 | void rump_getuptime(struct timespec *); | 97 | void rump_getuptime(struct timespec *); | |
98 | 98 | |||
99 | void rump_set_vmspace(struct vmspace *); | 99 | void rump_set_vmspace(struct vmspace *); | |
100 | 100 | |||
101 | typedef void (*rump_proc_vfs_init_fn)(struct proc *); | 101 | typedef void (*rump_proc_vfs_init_fn)(struct proc *); | |
102 | typedef void (*rump_proc_vfs_release_fn)(struct proc *); | 102 | typedef void (*rump_proc_vfs_release_fn)(struct proc *); | |
103 | extern rump_proc_vfs_init_fn rump_proc_vfs_init; | 103 | extern rump_proc_vfs_init_fn rump_proc_vfs_init; | |
104 | extern rump_proc_vfs_release_fn rump_proc_vfs_release; | 104 | extern rump_proc_vfs_release_fn rump_proc_vfs_release; | |
105 | 105 | |||
106 | extern struct cpu_info *rump_cpu; | 106 | extern struct cpu_info *rump_cpu; | |
107 | 107 | |||
108 | struct lwp * rump__lwproc_allockernlwp(void); | 108 | struct lwp * rump__lwproc_alloclwp(struct proc *); | |
109 | 109 | |||
110 | void rump_cpus_bootstrap(int); | 110 | void rump_cpus_bootstrap(int); | |
111 | void rump_scheduler_init(int); | 111 | void rump_scheduler_init(int); | |
112 | void rump_schedule(void); | 112 | void rump_schedule(void); | |
113 | void rump_unschedule(void); | 113 | void rump_unschedule(void); | |
114 | void rump_schedule_cpu(struct lwp *); | 114 | void rump_schedule_cpu(struct lwp *); | |
115 | void rump_schedule_cpu_interlock(struct lwp *, void *); | 115 | void rump_schedule_cpu_interlock(struct lwp *, void *); | |
116 | void rump_unschedule_cpu(struct lwp *); | 116 | void rump_unschedule_cpu(struct lwp *); | |
117 | void rump_unschedule_cpu_interlock(struct lwp *, void *); | 117 | void rump_unschedule_cpu_interlock(struct lwp *, void *); | |
118 | void rump_unschedule_cpu1(struct lwp *, void *); | 118 | void rump_unschedule_cpu1(struct lwp *, void *); | |
119 | 119 | |||
120 | void rump_schedlock_cv_wait(struct rumpuser_cv *); | 120 | void rump_schedlock_cv_wait(struct rumpuser_cv *); | |
121 | int rump_schedlock_cv_timedwait(struct rumpuser_cv *, | 121 | int rump_schedlock_cv_timedwait(struct rumpuser_cv *, |
--- src/sys/rump/librump/rumpkern/scheduler.c 2010/09/07 07:59:48 1.20
+++ src/sys/rump/librump/rumpkern/scheduler.c 2010/10/29 15:32:24 1.21
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: scheduler.c,v 1.20 2010/09/07 07:59:48 pooka Exp $ */ | 1 | /* $NetBSD: scheduler.c,v 1.21 2010/10/29 15:32:24 pooka Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2010 Antti Kantee. All Rights Reserved. | 4 | * Copyright (c) 2010 Antti Kantee. All Rights Reserved. | |
5 | * | 5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | 6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions | 7 | * modification, are permitted provided that the following conditions | |
8 | * are met: | 8 | * are met: | |
9 | * 1. Redistributions of source code must retain the above copyright | 9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | 10 | * notice, this list of conditions and the following disclaimer. | |
11 | * 2. Redistributions in binary form must reproduce the above copyright | 11 | * 2. Redistributions in binary form must reproduce the above copyright | |
12 | * notice, this list of conditions and the following disclaimer in the | 12 | * notice, this list of conditions and the following disclaimer in the | |
13 | * documentation and/or other materials provided with the distribution. | 13 | * documentation and/or other materials provided with the distribution. | |
14 | * | 14 | * | |
@@ -16,27 +16,27 @@ | @@ -16,27 +16,27 @@ | |||
16 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 16 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
18 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | 18 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | |
19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
25 | * SUCH DAMAGE. | 25 | * SUCH DAMAGE. | |
26 | */ | 26 | */ | |
27 | 27 | |||
28 | #include <sys/cdefs.h> | 28 | #include <sys/cdefs.h> | |
29 | __KERNEL_RCSID(0, "$NetBSD: scheduler.c,v 1.20 2010/09/07 07:59:48 pooka Exp $"); | 29 | __KERNEL_RCSID(0, "$NetBSD: scheduler.c,v 1.21 2010/10/29 15:32:24 pooka Exp $"); | |
30 | 30 | |||
31 | #include <sys/param.h> | 31 | #include <sys/param.h> | |
32 | #include <sys/atomic.h> | 32 | #include <sys/atomic.h> | |
33 | #include <sys/cpu.h> | 33 | #include <sys/cpu.h> | |
34 | #include <sys/kmem.h> | 34 | #include <sys/kmem.h> | |
35 | #include <sys/mutex.h> | 35 | #include <sys/mutex.h> | |
36 | #include <sys/namei.h> | 36 | #include <sys/namei.h> | |
37 | #include <sys/queue.h> | 37 | #include <sys/queue.h> | |
38 | #include <sys/select.h> | 38 | #include <sys/select.h> | |
39 | #include <sys/systm.h> | 39 | #include <sys/systm.h> | |
40 | 40 | |||
41 | #include <rump/rumpuser.h> | 41 | #include <rump/rumpuser.h> | |
42 | 42 | |||
@@ -226,27 +226,27 @@ rump_schedule() | @@ -226,27 +226,27 @@ rump_schedule() | |||
226 | * start a real thread. | 226 | * start a real thread. | |
227 | */ | 227 | */ | |
228 | if (__predict_true((l = rumpuser_get_curlwp()) != NULL)) { | 228 | if (__predict_true((l = rumpuser_get_curlwp()) != NULL)) { | |
229 | rump_schedule_cpu(l); | 229 | rump_schedule_cpu(l); | |
230 | LWP_CACHE_CREDS(l, l->l_proc); | 230 | LWP_CACHE_CREDS(l, l->l_proc); | |
231 | } else { | 231 | } else { | |
232 | lwp0busy(); | 232 | lwp0busy(); | |
233 | 233 | |||
234 | /* schedule cpu and use lwp0 */ | 234 | /* schedule cpu and use lwp0 */ | |
235 | rump_schedule_cpu(&lwp0); | 235 | rump_schedule_cpu(&lwp0); | |
236 | rumpuser_set_curlwp(&lwp0); | 236 | rumpuser_set_curlwp(&lwp0); | |
237 | 237 | |||
238 | /* allocate thread, switch to it, and release lwp0 */ | 238 | /* allocate thread, switch to it, and release lwp0 */ | |
239 | l = rump__lwproc_allockernlwp(); | 239 | l = rump__lwproc_alloclwp(initproc); | |
240 | rump_lwproc_switch(l); | 240 | rump_lwproc_switch(l); | |
241 | lwp0rele(); | 241 | lwp0rele(); | |
242 | 242 | |||
243 | /* | 243 | /* | |
244 | * mark new thread dead-on-unschedule. this | 244 | * mark new thread dead-on-unschedule. this | |
245 | * means that we'll be running with l_refcnt == 0. | 245 | * means that we'll be running with l_refcnt == 0. | |
246 | * relax, it's fine. | 246 | * relax, it's fine. | |
247 | */ | 247 | */ | |
248 | rump_lwproc_releaselwp(); | 248 | rump_lwproc_releaselwp(); | |
249 | } | 249 | } | |
250 | } | 250 | } | |
251 | 251 | |||
252 | void | 252 | void |
--- src/sys/rump/librump/rumpkern/threads.c 2010/09/01 19:37:59 1.12
+++ src/sys/rump/librump/rumpkern/threads.c 2010/10/29 15:32:24 1.13
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: threads.c,v 1.12 2010/09/01 19:37:59 pooka Exp $ */ | 1 | /* $NetBSD: threads.c,v 1.13 2010/10/29 15:32:24 pooka Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2007-2009 Antti Kantee. All Rights Reserved. | 4 | * Copyright (c) 2007-2009 Antti Kantee. All Rights Reserved. | |
5 | * | 5 | * | |
6 | * Development of this software was supported by | 6 | * Development of this software was supported by | |
7 | * The Finnish Cultural Foundation. | 7 | * The Finnish Cultural Foundation. | |
8 | * | 8 | * | |
9 | * Redistribution and use in source and binary forms, with or without | 9 | * Redistribution and use in source and binary forms, with or without | |
10 | * modification, are permitted provided that the following conditions | 10 | * modification, are permitted provided that the following conditions | |
11 | * are met: | 11 | * are met: | |
12 | * 1. Redistributions of source code must retain the above copyright | 12 | * 1. Redistributions of source code must retain the above copyright | |
13 | * notice, this list of conditions and the following disclaimer. | 13 | * notice, this list of conditions and the following disclaimer. | |
14 | * 2. Redistributions in binary form must reproduce the above copyright | 14 | * 2. Redistributions in binary form must reproduce the above copyright | |
@@ -19,27 +19,27 @@ | @@ -19,27 +19,27 @@ | |||
19 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 19 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
21 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | 21 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | |
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
28 | * SUCH DAMAGE. | 28 | * SUCH DAMAGE. | |
29 | */ | 29 | */ | |
30 | 30 | |||
31 | #include <sys/cdefs.h> | 31 | #include <sys/cdefs.h> | |
32 | __KERNEL_RCSID(0, "$NetBSD: threads.c,v 1.12 2010/09/01 19:37:59 pooka Exp $"); | 32 | __KERNEL_RCSID(0, "$NetBSD: threads.c,v 1.13 2010/10/29 15:32:24 pooka Exp $"); | |
33 | 33 | |||
34 | #include <sys/param.h> | 34 | #include <sys/param.h> | |
35 | #include <sys/atomic.h> | 35 | #include <sys/atomic.h> | |
36 | #include <sys/kmem.h> | 36 | #include <sys/kmem.h> | |
37 | #include <sys/kthread.h> | 37 | #include <sys/kthread.h> | |
38 | #include <sys/malloc.h> | 38 | #include <sys/malloc.h> | |
39 | #include <sys/systm.h> | 39 | #include <sys/systm.h> | |
40 | 40 | |||
41 | #include <machine/stdarg.h> | 41 | #include <machine/stdarg.h> | |
42 | 42 | |||
43 | #include <rump/rumpuser.h> | 43 | #include <rump/rumpuser.h> | |
44 | 44 | |||
45 | #include "rump_private.h" | 45 | #include "rump_private.h" | |
@@ -129,27 +129,27 @@ kthread_create(pri_t pri, int flags, str | @@ -129,27 +129,27 @@ kthread_create(pri_t pri, int flags, str | |||
129 | return 0; | 129 | return 0; | |
130 | } else if (strncmp(thrstore, "xcall", sizeof("xcall")-1) == 0) { | 130 | } else if (strncmp(thrstore, "xcall", sizeof("xcall")-1) == 0) { | |
131 | printf("rump warning: threads not enabled, CPU xcall" | 131 | printf("rump warning: threads not enabled, CPU xcall" | |
132 | " not functional\n"); | 132 | " not functional\n"); | |
133 | return 0; | 133 | return 0; | |
134 | } else | 134 | } else | |
135 | panic("threads not available, setenv RUMP_THREADS 1"); | 135 | panic("threads not available, setenv RUMP_THREADS 1"); | |
136 | } | 136 | } | |
137 | KASSERT(fmt != NULL); | 137 | KASSERT(fmt != NULL); | |
138 | 138 | |||
139 | k = malloc(sizeof(*k), M_TEMP, M_WAITOK); | 139 | k = malloc(sizeof(*k), M_TEMP, M_WAITOK); | |
140 | k->f = func; | 140 | k->f = func; | |
141 | k->arg = arg; | 141 | k->arg = arg; | |
142 | k->mylwp = l = rump__lwproc_allockernlwp(); | 142 | k->mylwp = l = rump__lwproc_alloclwp(&proc0); | |
143 | l->l_flag |= LW_SYSTEM; | 143 | l->l_flag |= LW_SYSTEM; | |
144 | if (flags & KTHREAD_MPSAFE) | 144 | if (flags & KTHREAD_MPSAFE) | |
145 | l->l_pflag |= LP_MPSAFE; | 145 | l->l_pflag |= LP_MPSAFE; | |
146 | if (flags & KTHREAD_INTR) | 146 | if (flags & KTHREAD_INTR) | |
147 | l->l_pflag |= LP_INTR; | 147 | l->l_pflag |= LP_INTR; | |
148 | if (ci) { | 148 | if (ci) { | |
149 | l->l_pflag |= LP_BOUND; | 149 | l->l_pflag |= LP_BOUND; | |
150 | l->l_target_cpu = ci; | 150 | l->l_target_cpu = ci; | |
151 | } | 151 | } | |
152 | if (thrname) { | 152 | if (thrname) { | |
153 | l->l_name = kmem_alloc(MAXCOMLEN, KM_SLEEP); | 153 | l->l_name = kmem_alloc(MAXCOMLEN, KM_SLEEP); | |
154 | strlcpy(l->l_name, thrname, MAXCOMLEN); | 154 | strlcpy(l->l_name, thrname, MAXCOMLEN); | |
155 | } | 155 | } |