Sun Jan 3 12:51:33 2021 UTC ()
Apply patch, requested by khorben in ticket #1177 (issue solved differently
in -current):

	sys/kern/init_main.c			(apply patch)

PR kern/55906: create the aiodone workqueue before running mountroothooks.


(martin)
diff -r1.504.2.1 -r1.504.2.2 src/sys/kern/init_main.c

cvs diff -r1.504.2.1 -r1.504.2.2 src/sys/kern/init_main.c (switch to unified diff)

--- src/sys/kern/init_main.c 2020/11/14 15:36:11 1.504.2.1
+++ src/sys/kern/init_main.c 2021/01/03 12:51:33 1.504.2.2
@@ -1,1187 +1,1187 @@ @@ -1,1187 +1,1187 @@
1/* $NetBSD: init_main.c,v 1.504.2.1 2020/11/14 15:36:11 martin Exp $ */ 1/* $NetBSD: init_main.c,v 1.504.2.2 2021/01/03 12:51:33 martin 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 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29/* 29/*
30 * Copyright (c) 1982, 1986, 1989, 1991, 1992, 1993 30 * Copyright (c) 1982, 1986, 1989, 1991, 1992, 1993
31 * The Regents of the University of California. All rights reserved. 31 * The Regents of the University of California. All rights reserved.
32 * (c) UNIX System Laboratories, Inc. 32 * (c) UNIX System Laboratories, Inc.
33 * All or some portions of this file are derived from material licensed 33 * All or some portions of this file are derived from material licensed
34 * to the University of California by American Telephone and Telegraph 34 * to the University of California by American Telephone and Telegraph
35 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 35 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
36 * the permission of UNIX System Laboratories, Inc. 36 * the permission of UNIX System Laboratories, Inc.
37 * 37 *
38 * Redistribution and use in source and binary forms, with or without 38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions 39 * modification, are permitted provided that the following conditions
40 * are met: 40 * are met:
41 * 1. Redistributions of source code must retain the above copyright 41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer. 42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright 43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the 44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution. 45 * documentation and/or other materials provided with the distribution.
46 * 3. Neither the name of the University nor the names of its contributors 46 * 3. Neither the name of the University nor the names of its contributors
47 * may be used to endorse or promote products derived from this software 47 * may be used to endorse or promote products derived from this software
48 * without specific prior written permission. 48 * without specific prior written permission.
49 * 49 *
50 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 50 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 51 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 52 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 53 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 54 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 55 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 56 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 57 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 58 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 59 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 * SUCH DAMAGE. 60 * SUCH DAMAGE.
61 * 61 *
62 * @(#)init_main.c 8.16 (Berkeley) 5/14/95 62 * @(#)init_main.c 8.16 (Berkeley) 5/14/95
63 */ 63 */
64 64
65/* 65/*
66 * Copyright (c) 1995 Christopher G. Demetriou. All rights reserved. 66 * Copyright (c) 1995 Christopher G. Demetriou. All rights reserved.
67 * 67 *
68 * Redistribution and use in source and binary forms, with or without 68 * Redistribution and use in source and binary forms, with or without
69 * modification, are permitted provided that the following conditions 69 * modification, are permitted provided that the following conditions
70 * are met: 70 * are met:
71 * 1. Redistributions of source code must retain the above copyright 71 * 1. Redistributions of source code must retain the above copyright
72 * notice, this list of conditions and the following disclaimer. 72 * notice, this list of conditions and the following disclaimer.
73 * 2. Redistributions in binary form must reproduce the above copyright 73 * 2. Redistributions in binary form must reproduce the above copyright
74 * notice, this list of conditions and the following disclaimer in the 74 * notice, this list of conditions and the following disclaimer in the
75 * documentation and/or other materials provided with the distribution. 75 * documentation and/or other materials provided with the distribution.
76 * 3. All advertising materials mentioning features or use of this software 76 * 3. All advertising materials mentioning features or use of this software
77 * must display the following acknowledgement: 77 * must display the following acknowledgement:
78 * This product includes software developed by the University of 78 * This product includes software developed by the University of
79 * California, Berkeley and its contributors. 79 * California, Berkeley and its contributors.
80 * 4. Neither the name of the University nor the names of its contributors 80 * 4. Neither the name of the University nor the names of its contributors
81 * may be used to endorse or promote products derived from this software 81 * may be used to endorse or promote products derived from this software
82 * without specific prior written permission. 82 * without specific prior written permission.
83 * 83 *
84 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 84 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
85 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 85 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
86 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 86 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
87 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 87 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
88 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 88 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
89 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 89 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
90 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 90 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
91 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 91 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
92 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 92 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
93 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 93 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
94 * SUCH DAMAGE. 94 * SUCH DAMAGE.
95 * 95 *
96 * @(#)init_main.c 8.16 (Berkeley) 5/14/95 96 * @(#)init_main.c 8.16 (Berkeley) 5/14/95
97 */ 97 */
98 98
99#include <sys/cdefs.h> 99#include <sys/cdefs.h>
100__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.504.2.1 2020/11/14 15:36:11 martin Exp $"); 100__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.504.2.2 2021/01/03 12:51:33 martin Exp $");
101 101
102#include "opt_ddb.h" 102#include "opt_ddb.h"
103#include "opt_inet.h" 103#include "opt_inet.h"
104#include "opt_ipsec.h" 104#include "opt_ipsec.h"
105#include "opt_modular.h" 105#include "opt_modular.h"
106#include "opt_ntp.h" 106#include "opt_ntp.h"
107#include "opt_pipe.h" 107#include "opt_pipe.h"
108#include "opt_syscall_debug.h" 108#include "opt_syscall_debug.h"
109#include "opt_sysv.h" 109#include "opt_sysv.h"
110#include "opt_fileassoc.h" 110#include "opt_fileassoc.h"
111#include "opt_ktrace.h" 111#include "opt_ktrace.h"
112#include "opt_pax.h" 112#include "opt_pax.h"
113#include "opt_compat_netbsd.h" 113#include "opt_compat_netbsd.h"
114#include "opt_wapbl.h" 114#include "opt_wapbl.h"
115#include "opt_ptrace.h" 115#include "opt_ptrace.h"
116#include "opt_rnd_printf.h" 116#include "opt_rnd_printf.h"
117#include "opt_splash.h" 117#include "opt_splash.h"
118#include "opt_kernhist.h" 118#include "opt_kernhist.h"
119#include "opt_gprof.h" 119#include "opt_gprof.h"
120 120
121#if defined(SPLASHSCREEN) && defined(makeoptions_SPLASHSCREEN_IMAGE) 121#if defined(SPLASHSCREEN) && defined(makeoptions_SPLASHSCREEN_IMAGE)
122extern void *_binary_splash_image_start; 122extern void *_binary_splash_image_start;
123extern void *_binary_splash_image_end; 123extern void *_binary_splash_image_end;
124#endif 124#endif
125 125
126#include "ksyms.h" 126#include "ksyms.h"
127 127
128#include "veriexec.h" 128#include "veriexec.h"
129 129
130#include <sys/param.h> 130#include <sys/param.h>
131#include <sys/acct.h> 131#include <sys/acct.h>
132#include <sys/filedesc.h> 132#include <sys/filedesc.h>
133#include <sys/file.h> 133#include <sys/file.h>
134#include <sys/errno.h> 134#include <sys/errno.h>
135#include <sys/callout.h> 135#include <sys/callout.h>
136#include <sys/cpu.h> 136#include <sys/cpu.h>
137#include <sys/cpufreq.h> 137#include <sys/cpufreq.h>
138#include <sys/spldebug.h> 138#include <sys/spldebug.h>
139#include <sys/kernel.h> 139#include <sys/kernel.h>
140#include <sys/mount.h> 140#include <sys/mount.h>
141#include <sys/proc.h> 141#include <sys/proc.h>
142#include <sys/kthread.h> 142#include <sys/kthread.h>
143#include <sys/resourcevar.h> 143#include <sys/resourcevar.h>
144#include <sys/signalvar.h> 144#include <sys/signalvar.h>
145#include <sys/systm.h> 145#include <sys/systm.h>
146#include <sys/vnode.h> 146#include <sys/vnode.h>
147#include <sys/fstrans.h> 147#include <sys/fstrans.h>
148#include <sys/tty.h> 148#include <sys/tty.h>
149#include <sys/conf.h> 149#include <sys/conf.h>
150#include <sys/disklabel.h> 150#include <sys/disklabel.h>
151#include <sys/buf.h> 151#include <sys/buf.h>
152#include <sys/device.h> 152#include <sys/device.h>
153#include <sys/exec.h> 153#include <sys/exec.h>
154#include <sys/socketvar.h> 154#include <sys/socketvar.h>
155#include <sys/protosw.h> 155#include <sys/protosw.h>
156#include <sys/percpu.h> 156#include <sys/percpu.h>
157#include <sys/pserialize.h> 157#include <sys/pserialize.h>
158#include <sys/pset.h> 158#include <sys/pset.h>
159#include <sys/sysctl.h> 159#include <sys/sysctl.h>
160#include <sys/reboot.h> 160#include <sys/reboot.h>
161#include <sys/event.h> 161#include <sys/event.h>
162#include <sys/mbuf.h> 162#include <sys/mbuf.h>
163#include <sys/sched.h> 163#include <sys/sched.h>
164#include <sys/sleepq.h> 164#include <sys/sleepq.h>
165#include <sys/ipi.h> 165#include <sys/ipi.h>
166#include <sys/iostat.h> 166#include <sys/iostat.h>
167#include <sys/vmem.h> 167#include <sys/vmem.h>
168#include <sys/uuid.h> 168#include <sys/uuid.h>
169#include <sys/extent.h> 169#include <sys/extent.h>
170#include <sys/disk.h> 170#include <sys/disk.h>
171#include <sys/msgbuf.h> 171#include <sys/msgbuf.h>
172#include <sys/module.h> 172#include <sys/module.h>
173#include <sys/event.h> 173#include <sys/event.h>
174#include <sys/lockf.h> 174#include <sys/lockf.h>
175#include <sys/once.h> 175#include <sys/once.h>
176#include <sys/kcpuset.h> 176#include <sys/kcpuset.h>
177#include <sys/ksyms.h> 177#include <sys/ksyms.h>
178#include <sys/uidinfo.h> 178#include <sys/uidinfo.h>
179#include <sys/kprintf.h> 179#include <sys/kprintf.h>
180#include <sys/bufq.h> 180#include <sys/bufq.h>
181#include <sys/threadpool.h> 181#include <sys/threadpool.h>
182#ifdef IPSEC 182#ifdef IPSEC
183#include <netipsec/ipsec.h> 183#include <netipsec/ipsec.h>
184#endif 184#endif
185#include <sys/domain.h> 185#include <sys/domain.h>
186#include <sys/namei.h> 186#include <sys/namei.h>
187#include <sys/rnd.h> 187#include <sys/rnd.h>
188#include <sys/pipe.h> 188#include <sys/pipe.h>
189#if NVERIEXEC > 0 189#if NVERIEXEC > 0
190#include <sys/verified_exec.h> 190#include <sys/verified_exec.h>
191#endif /* NVERIEXEC > 0 */ 191#endif /* NVERIEXEC > 0 */
192#ifdef KTRACE 192#ifdef KTRACE
193#include <sys/ktrace.h> 193#include <sys/ktrace.h>
194#endif 194#endif
195#include <sys/kauth.h> 195#include <sys/kauth.h>
196#include <net80211/ieee80211_netbsd.h> 196#include <net80211/ieee80211_netbsd.h>
197#include <sys/cprng.h> 197#include <sys/cprng.h>
198#include <sys/psref.h> 198#include <sys/psref.h>
199 199
200#include <sys/syscall.h> 200#include <sys/syscall.h>
201#include <sys/syscallargs.h> 201#include <sys/syscallargs.h>
202 202
203#include <sys/pax.h> 203#include <sys/pax.h>
204 204
205#include <secmodel/secmodel.h> 205#include <secmodel/secmodel.h>
206 206
207#include <ufs/ufs/quota.h> 207#include <ufs/ufs/quota.h>
208 208
209#include <miscfs/genfs/genfs.h> 209#include <miscfs/genfs/genfs.h>
210#include <miscfs/specfs/specdev.h> 210#include <miscfs/specfs/specdev.h>
211 211
212#include <sys/cpu.h> 212#include <sys/cpu.h>
213 213
214#include <uvm/uvm.h> /* extern struct uvm uvm */ 214#include <uvm/uvm.h> /* extern struct uvm uvm */
215 215
216#include <dev/cons.h> 216#include <dev/cons.h>
217#include <dev/splash/splash.h> 217#include <dev/splash/splash.h>
218 218
219#include <net/bpf.h> 219#include <net/bpf.h>
220#include <net/if.h> 220#include <net/if.h>
221#include <net/pfil.h> 221#include <net/pfil.h>
222#include <net/raw_cb.h> 222#include <net/raw_cb.h>
223#include <net/if_llatbl.h> 223#include <net/if_llatbl.h>
224 224
225#include <prop/proplib.h> 225#include <prop/proplib.h>
226 226
227#include <sys/userconf.h> 227#include <sys/userconf.h>
228 228
229extern struct lwp lwp0; 229extern struct lwp lwp0;
230extern time_t rootfstime; 230extern time_t rootfstime;
231 231
232#ifndef curlwp 232#ifndef curlwp
233struct lwp *curlwp = &lwp0; 233struct lwp *curlwp = &lwp0;
234#endif 234#endif
235struct proc *initproc; 235struct proc *initproc;
236 236
237struct vnode *rootvp, *swapdev_vp; 237struct vnode *rootvp, *swapdev_vp;
238int boothowto; 238int boothowto;
239int cold __read_mostly = 1; /* still working on startup */ 239int cold __read_mostly = 1; /* still working on startup */
240struct timespec boottime; /* time at system startup - will only follow settime deltas */ 240struct timespec boottime; /* time at system startup - will only follow settime deltas */
241 241
242int start_init_exec; /* semaphore for start_init() */ 242int start_init_exec; /* semaphore for start_init() */
243 243
244cprng_strong_t *kern_cprng; 244cprng_strong_t *kern_cprng;
245 245
246static void check_console(struct lwp *l); 246static void check_console(struct lwp *l);
247static void start_init(void *); 247static void start_init(void *);
248static void configure(void); 248static void configure(void);
249static void configure2(void); 249static void configure2(void);
250static void configure3(void); 250static void configure3(void);
251void main(void); 251void main(void);
252 252
253/* 253/*
254 * System startup; initialize the world, create process 0, mount root 254 * System startup; initialize the world, create process 0, mount root
255 * filesystem, and fork to create init and pagedaemon. Most of the 255 * filesystem, and fork to create init and pagedaemon. Most of the
256 * hard work is done in the lower-level initialization routines including 256 * hard work is done in the lower-level initialization routines including
257 * startup(), which does memory initialization and autoconfiguration. 257 * startup(), which does memory initialization and autoconfiguration.
258 */ 258 */
259void 259void
260main(void) 260main(void)
261{ 261{
262 struct timespec time; 262 struct timespec time;
263 struct lwp *l; 263 struct lwp *l;
264 struct proc *p; 264 struct proc *p;
265 int s, error; 265 int s, error;
266#ifdef NVNODE_IMPLICIT 266#ifdef NVNODE_IMPLICIT
267 int usevnodes; 267 int usevnodes;
268#endif 268#endif
269 CPU_INFO_ITERATOR cii; 269 CPU_INFO_ITERATOR cii;
270 struct cpu_info *ci; 270 struct cpu_info *ci;
271 271
272#ifdef DIAGNOSTIC 272#ifdef DIAGNOSTIC
273 /* 273 /*
274 * Verify that CPU_INFO_FOREACH() knows about the boot CPU 274 * Verify that CPU_INFO_FOREACH() knows about the boot CPU
275 * and only the boot CPU at this point. 275 * and only the boot CPU at this point.
276 */ 276 */
277 int cpucount = 0; 277 int cpucount = 0;
278 for (CPU_INFO_FOREACH(cii, ci)) { 278 for (CPU_INFO_FOREACH(cii, ci)) {
279 KASSERT(ci == curcpu()); 279 KASSERT(ci == curcpu());
280 cpucount++; 280 cpucount++;
281 } 281 }
282 KASSERT(cpucount == 1); 282 KASSERT(cpucount == 1);
283#endif 283#endif
284 284
285 l = &lwp0; 285 l = &lwp0;
286#ifndef LWP0_CPU_INFO 286#ifndef LWP0_CPU_INFO
287 l->l_cpu = curcpu(); 287 l->l_cpu = curcpu();
288#endif 288#endif
289 l->l_pflag |= LP_RUNNING; 289 l->l_pflag |= LP_RUNNING;
290 290
291 /* 291 /*
292 * Attempt to find console and initialize 292 * Attempt to find console and initialize
293 * in case of early panic or other messages. 293 * in case of early panic or other messages.
294 */ 294 */
295 consinit(); 295 consinit();
296 296
297 kernel_lock_init(); 297 kernel_lock_init();
298 once_init(); 298 once_init();
299 299
300 mi_cpu_init(); 300 mi_cpu_init();
301 kernconfig_lock_init(); 301 kernconfig_lock_init();
302 kthread_sysinit(); 302 kthread_sysinit();
303 303
304 /* Initialize the device switch tables. */ 304 /* Initialize the device switch tables. */
305 devsw_init(); 305 devsw_init();
306 306
307 /* Initialize event counters. */ 307 /* Initialize event counters. */
308 evcnt_init(); 308 evcnt_init();
309 309
310 uvm_init(); 310 uvm_init();
311 ubchist_init(); 311 ubchist_init();
312 kcpuset_sysinit(); 312 kcpuset_sysinit();
313 313
314 prop_kern_init(); 314 prop_kern_init();
315 315
316#if ((NKSYMS > 0) || (NDDB > 0) || (NMODULAR > 0)) 316#if ((NKSYMS > 0) || (NDDB > 0) || (NMODULAR > 0))
317 ksyms_init(); 317 ksyms_init();
318#endif 318#endif
319 kprintf_init(); 319 kprintf_init();
320 320
321 percpu_init(); 321 percpu_init();
322 322
323 /* Initialize lock caches. */ 323 /* Initialize lock caches. */
324 mutex_obj_init(); 324 mutex_obj_init();
325 rw_obj_init(); 325 rw_obj_init();
326 326
327 /* Passive serialization. */ 327 /* Passive serialization. */
328 pserialize_init(); 328 pserialize_init();
329 329
330 /* Initialize the extent manager. */ 330 /* Initialize the extent manager. */
331 extent_init(); 331 extent_init();
332 332
333 /* Do machine-dependent initialization. */ 333 /* Do machine-dependent initialization. */
334 cpu_startup(); 334 cpu_startup();
335 335
336 /* Initialize the sysctl subsystem. */ 336 /* Initialize the sysctl subsystem. */
337 sysctl_init(); 337 sysctl_init();
338 338
339 /* Initialize callouts, part 1. */ 339 /* Initialize callouts, part 1. */
340 callout_startup(); 340 callout_startup();
341 341
342 /* Initialize the kernel authorization subsystem. */ 342 /* Initialize the kernel authorization subsystem. */
343 kauth_init(); 343 kauth_init();
344 344
345 secmodel_init(); 345 secmodel_init();
346 346
347 spec_init(); 347 spec_init();
348 348
349 /* 349 /*
350 * Set BPF op vector. Can't do this in bpf attach, since 350 * Set BPF op vector. Can't do this in bpf attach, since
351 * network drivers attach before bpf. 351 * network drivers attach before bpf.
352 */ 352 */
353 bpf_setops(); 353 bpf_setops();
354 354
355 /* Start module system. */ 355 /* Start module system. */
356 module_init(); 356 module_init();
357 357
358 /* 358 /*
359 * Initialize the kernel authorization subsystem and start the 359 * Initialize the kernel authorization subsystem and start the
360 * default security model, if any. We need to do this early 360 * default security model, if any. We need to do this early
361 * enough so that subsystems relying on any of the aforementioned 361 * enough so that subsystems relying on any of the aforementioned
362 * can work properly. Since the security model may dictate the 362 * can work properly. Since the security model may dictate the
363 * credential inheritance policy, it is needed at least before 363 * credential inheritance policy, it is needed at least before
364 * any process is created, specifically proc0. 364 * any process is created, specifically proc0.
365 */ 365 */
366 module_init_class(MODULE_CLASS_SECMODEL); 366 module_init_class(MODULE_CLASS_SECMODEL);
367 367
368 /* Initialize the buffer cache */ 368 /* Initialize the buffer cache */
369 bufinit(); 369 bufinit();
370 biohist_init(); 370 biohist_init();
371 371
372#ifdef KERNHIST 372#ifdef KERNHIST
373 sysctl_kernhist_init(); 373 sysctl_kernhist_init();
374#endif 374#endif
375 375
376 376
377#if defined(SPLASHSCREEN) && defined(SPLASHSCREEN_IMAGE) 377#if defined(SPLASHSCREEN) && defined(SPLASHSCREEN_IMAGE)
378 size_t splash_size = (&_binary_splash_image_end - 378 size_t splash_size = (&_binary_splash_image_end -
379 &_binary_splash_image_start) * sizeof(void *); 379 &_binary_splash_image_start) * sizeof(void *);
380 splash_setimage(&_binary_splash_image_start, splash_size); 380 splash_setimage(&_binary_splash_image_start, splash_size);
381#endif 381#endif
382 382
383 /* Initialize sockets. */ 383 /* Initialize sockets. */
384 soinit(); 384 soinit();
385 385
386 /* 386 /*
387 * The following things must be done before autoconfiguration. 387 * The following things must be done before autoconfiguration.
388 */ 388 */
389 rnd_init(); /* initialize entropy pool */ 389 rnd_init(); /* initialize entropy pool */
390 390
391 cprng_init(); /* initialize cryptographic PRNG */ 391 cprng_init(); /* initialize cryptographic PRNG */
392 392
393 /* Initialize process and pgrp structures. */ 393 /* Initialize process and pgrp structures. */
394 procinit(); 394 procinit();
395 lwpinit(); 395 lwpinit();
396 396
397 /* Must be called after lwpinit (lwpinit_specificdata) */ 397 /* Must be called after lwpinit (lwpinit_specificdata) */
398 psref_init(); 398 psref_init();
399 399
400 /* Initialize signal-related data structures. */ 400 /* Initialize signal-related data structures. */
401 signal_init(); 401 signal_init();
402 402
403 /* Initialize resource management. */ 403 /* Initialize resource management. */
404 resource_init(); 404 resource_init();
405 405
406 /* Create process 0. */ 406 /* Create process 0. */
407 proc0_init(); 407 proc0_init();
408 lwp0_init(); 408 lwp0_init();
409 409
410 /* Disable preemption during boot. */ 410 /* Disable preemption during boot. */
411 kpreempt_disable(); 411 kpreempt_disable();
412 412
413 /* Initialize the threadpool system. */ 413 /* Initialize the threadpool system. */
414 threadpools_init(); 414 threadpools_init();
415 415
416 /* Initialize the UID hash table. */ 416 /* Initialize the UID hash table. */
417 uid_init(); 417 uid_init();
418 418
419 /* Charge root for one process. */ 419 /* Charge root for one process. */
420 (void)chgproccnt(0, 1); 420 (void)chgproccnt(0, 1);
421 421
422 /* Initialize timekeeping. */ 422 /* Initialize timekeeping. */
423 time_init(); 423 time_init();
424 424
425 /* Initialize the run queues, turnstiles and sleep queues. */ 425 /* Initialize the run queues, turnstiles and sleep queues. */
426 sched_rqinit(); 426 sched_rqinit();
427 turnstile_init(); 427 turnstile_init();
428 sleeptab_init(&sleeptab); 428 sleeptab_init(&sleeptab);
429 429
430 sched_init(); 430 sched_init();
431 431
432 /* Initialize processor-sets */ 432 /* Initialize processor-sets */
433 psets_init(); 433 psets_init();
434 434
435 /* Initialize cpufreq(9) */ 435 /* Initialize cpufreq(9) */
436 cpufreq_init(); 436 cpufreq_init();
437 437
438 /* MI initialization of the boot cpu */ 438 /* MI initialization of the boot cpu */
439 error = mi_cpu_attach(curcpu()); 439 error = mi_cpu_attach(curcpu());
440 KASSERT(error == 0); 440 KASSERT(error == 0);
441 441
442 /* Initialize timekeeping, part 2. */ 442 /* Initialize timekeeping, part 2. */
443 time_init2(); 443 time_init2();
444 444
445 /* 445 /*
446 * Initialize mbuf's. Do this now because we might attempt to 446 * Initialize mbuf's. Do this now because we might attempt to
447 * allocate mbufs or mbuf clusters during autoconfiguration. 447 * allocate mbufs or mbuf clusters during autoconfiguration.
448 */ 448 */
449 mbinit(); 449 mbinit();
450 450
451 /* Initialize I/O statistics. */ 451 /* Initialize I/O statistics. */
452 iostat_init(); 452 iostat_init();
453 453
454 /* Initialize the log device. */ 454 /* Initialize the log device. */
455 loginit(); 455 loginit();
456 456
457 /* Second part of module system initialization. */ 457 /* Second part of module system initialization. */
458 module_start_unload_thread(); 458 module_start_unload_thread();
459 459
460 /* Initialize the file systems. */ 460 /* Initialize the file systems. */
461#ifdef NVNODE_IMPLICIT 461#ifdef NVNODE_IMPLICIT
462 /* 462 /*
463 * If maximum number of vnodes in namei vnode cache is not explicitly 463 * If maximum number of vnodes in namei vnode cache is not explicitly
464 * defined in kernel config, adjust the number such as we use roughly 464 * defined in kernel config, adjust the number such as we use roughly
465 * 10% of memory for vnodes and associated data structures in the 465 * 10% of memory for vnodes and associated data structures in the
466 * assumed worst case. Do not provide fewer than NVNODE vnodes. 466 * assumed worst case. Do not provide fewer than NVNODE vnodes.
467 */ 467 */
468 usevnodes = calc_cache_size(vmem_size(kmem_arena, VMEM_FREE|VMEM_ALLOC), 468 usevnodes = calc_cache_size(vmem_size(kmem_arena, VMEM_FREE|VMEM_ALLOC),
469 10, VNODE_KMEM_MAXPCT) / VNODE_COST; 469 10, VNODE_KMEM_MAXPCT) / VNODE_COST;
470 if (usevnodes > desiredvnodes) 470 if (usevnodes > desiredvnodes)
471 desiredvnodes = usevnodes; 471 desiredvnodes = usevnodes;
472#endif /* NVNODE_IMPLICIT */ 472#endif /* NVNODE_IMPLICIT */
473#ifdef MAXFILES_IMPLICIT 473#ifdef MAXFILES_IMPLICIT
474 /* 474 /*
475 * If maximum number of files is not explicitly defined in 475 * If maximum number of files is not explicitly defined in
476 * kernel config, adjust the number so that it is somewhat 476 * kernel config, adjust the number so that it is somewhat
477 * more reasonable on machines with larger memory sizes. 477 * more reasonable on machines with larger memory sizes.
478 * Arbitary numbers are 20,000 files for 16GB RAM or more 478 * Arbitary numbers are 20,000 files for 16GB RAM or more
479 * and 10,000 files for 1GB RAM or more. 479 * and 10,000 files for 1GB RAM or more.
480 * 480 *
481 * XXXtodo: adjust this and other values totally dynamically 481 * XXXtodo: adjust this and other values totally dynamically
482 */ 482 */
483 if (ctob((uint64_t)physmem) >= 16ULL * 1024 * 1024 * 1024) 483 if (ctob((uint64_t)physmem) >= 16ULL * 1024 * 1024 * 1024)
484 maxfiles = MAX(maxfiles, 20000); 484 maxfiles = MAX(maxfiles, 20000);
485 if (ctob((uint64_t)physmem) >= 1024 * 1024 * 1024) 485 if (ctob((uint64_t)physmem) >= 1024 * 1024 * 1024)
486 maxfiles = MAX(maxfiles, 10000); 486 maxfiles = MAX(maxfiles, 10000);
487#endif /* MAXFILES_IMPLICIT */ 487#endif /* MAXFILES_IMPLICIT */
488 488
489 /* Initialize fstrans. */ 489 /* Initialize fstrans. */
490 fstrans_init(); 490 fstrans_init();
491 491
492 vfsinit(); 492 vfsinit();
493 lf_init(); 493 lf_init();
494 494
495 /* Initialize the file descriptor system. */ 495 /* Initialize the file descriptor system. */
496 fd_sys_init(); 496 fd_sys_init();
497 497
498 /* Initialize cwd structures */ 498 /* Initialize cwd structures */
499 cwd_sys_init(); 499 cwd_sys_init();
500 500
501 /* Initialize kqueue. */ 501 /* Initialize kqueue. */
502 kqueue_init(); 502 kqueue_init();
503 503
504 inittimecounter(); 504 inittimecounter();
505 ntp_init(); 505 ntp_init();
506 506
507 /* Initialize tty subsystem. */ 507 /* Initialize tty subsystem. */
508 tty_init(); 508 tty_init();
509 ttyldisc_init(); 509 ttyldisc_init();
510 510
511 /* Initialize the buffer cache, part 2. */ 511 /* Initialize the buffer cache, part 2. */
512 bufinit2(); 512 bufinit2();
513 513
514 /* Initialize the disk wedge subsystem. */ 514 /* Initialize the disk wedge subsystem. */
515 dkwedge_init(); 515 dkwedge_init();
516 516
517 /* Initialize the kernel strong PRNG. */ 517 /* Initialize the kernel strong PRNG. */
518 kern_cprng = cprng_strong_create("kernel", IPL_VM, 518 kern_cprng = cprng_strong_create("kernel", IPL_VM,
519 CPRNG_INIT_ANY|CPRNG_REKEY_ANY); 519 CPRNG_INIT_ANY|CPRNG_REKEY_ANY);
520 520
521 /* Initialize pfil */ 521 /* Initialize pfil */
522 pfil_init(); 522 pfil_init();
523 523
524 /* Initialize interfaces. */ 524 /* Initialize interfaces. */
525 ifinit1(); 525 ifinit1();
526 526
527 spldebug_start(); 527 spldebug_start();
528 528
529 /* Initialize sockets thread(s) */ 529 /* Initialize sockets thread(s) */
530 soinit1(); 530 soinit1();
531 531
532 /* 532 /*
533 * Initialize the bufq strategy sub-system and any built-in 533 * Initialize the bufq strategy sub-system and any built-in
534 * strategy modules - they may be needed by some devices during 534 * strategy modules - they may be needed by some devices during
535 * auto-configuration 535 * auto-configuration
536 */ 536 */
537 bufq_init(); 537 bufq_init();
538 module_init_class(MODULE_CLASS_BUFQ); 538 module_init_class(MODULE_CLASS_BUFQ);
539 539
540 /* Configure the system hardware. This will enable interrupts. */ 540 /* Configure the system hardware. This will enable interrupts. */
541 configure(); 541 configure();
542 542
543 /* Once all CPUs are detected, initialize the per-CPU cprng_fast. */ 543 /* Once all CPUs are detected, initialize the per-CPU cprng_fast. */
544 cprng_fast_init(); 544 cprng_fast_init();
545 545
546 ssp_init(); 546 ssp_init();
547 547
548 ubc_init(); /* must be after autoconfig */ 548 ubc_init(); /* must be after autoconfig */
549 549
550 mm_init(); 550 mm_init();
551 551
552 configure2(); 552 configure2();
553 553
554 ipi_sysinit(); 554 ipi_sysinit();
555 555
556 /* Now timer is working. Enable preemption. */ 556 /* Now timer is working. Enable preemption. */
557 kpreempt_enable(); 557 kpreempt_enable();
558 558
559 /* Get the threads going and into any sleeps before continuing. */ 559 /* Get the threads going and into any sleeps before continuing. */
560 yield(); 560 yield();
561 561
562 /* Enable deferred processing of RNG samples */ 562 /* Enable deferred processing of RNG samples */
563 rnd_init_softint(); 563 rnd_init_softint();
564 564
565#ifdef RND_PRINTF 565#ifdef RND_PRINTF
566 /* Enable periodic injection of console output into entropy pool */ 566 /* Enable periodic injection of console output into entropy pool */
567 kprintf_init_callout(); 567 kprintf_init_callout();
568#endif 568#endif
569 569
570 vmem_rehash_start(); /* must be before exec_init */ 570 vmem_rehash_start(); /* must be before exec_init */
571 571
572 /* Initialize exec structures */ 572 /* Initialize exec structures */
573 exec_init(1); /* seminit calls exithook_establish() */ 573 exec_init(1); /* seminit calls exithook_establish() */
574 574
575#if NVERIEXEC > 0 575#if NVERIEXEC > 0
576 /* 576 /*
577 * Initialise the Veriexec subsystem. 577 * Initialise the Veriexec subsystem.
578 */ 578 */
579 veriexec_init(); 579 veriexec_init();
580#endif /* NVERIEXEC > 0 */ 580#endif /* NVERIEXEC > 0 */
581 581
582 pax_init(); 582 pax_init();
583 583
584#ifdef IPSEC 584#ifdef IPSEC
585 /* Attach network crypto subsystem */ 585 /* Attach network crypto subsystem */
586 ipsec_attach(); 586 ipsec_attach();
587#endif 587#endif
588 588
589 /* 589 /*
590 * Initialize protocols. Block reception of incoming packets 590 * Initialize protocols. Block reception of incoming packets
591 * until everything is ready. 591 * until everything is ready.
592 */ 592 */
593 s = splnet(); 593 s = splnet();
594 ifinit(); 594 ifinit();
595#if defined(INET) || defined(INET6) 595#if defined(INET) || defined(INET6)
596 lltableinit(); 596 lltableinit();
597#endif 597#endif
598 domaininit(true); 598 domaininit(true);
599 ifinit_post(); 599 ifinit_post();
600 if_attachdomain(); 600 if_attachdomain();
601 splx(s); 601 splx(s);
602 602
603#ifdef GPROF 603#ifdef GPROF
604 /* Initialize kernel profiling. */ 604 /* Initialize kernel profiling. */
605 kmstartup(); 605 kmstartup();
606#endif 606#endif
607 607
608 /* Initialize system accounting. */ 608 /* Initialize system accounting. */
609 acct_init(); 609 acct_init();
610 610
611#ifndef PIPE_SOCKETPAIR 611#ifndef PIPE_SOCKETPAIR
612 /* Initialize pipes. */ 612 /* Initialize pipes. */
613 pipe_init(); 613 pipe_init();
614#endif 614#endif
615 615
616#ifdef KTRACE 616#ifdef KTRACE
617 /* Initialize ktrace. */ 617 /* Initialize ktrace. */
618 ktrinit(); 618 ktrinit();
619#endif 619#endif
620 620
621 machdep_init(); 621 machdep_init();
622 622
623 procinit_sysctl(); 623 procinit_sysctl();
624 624
625 scdebug_init(); 625 scdebug_init();
626 626
627 /* 627 /*
628 * Create process 1 (init(8)). We do this now, as Unix has 628 * Create process 1 (init(8)). We do this now, as Unix has
629 * historically had init be process 1, and changing this would 629 * historically had init be process 1, and changing this would
630 * probably upset a lot of people. 630 * probably upset a lot of people.
631 * 631 *
632 * Note that process 1 won't immediately exec init(8), but will 632 * Note that process 1 won't immediately exec init(8), but will
633 * wait for us to inform it that the root file system has been 633 * wait for us to inform it that the root file system has been
634 * mounted. 634 * mounted.
635 */ 635 */
636 if (fork1(l, 0, SIGCHLD, NULL, 0, start_init, NULL, NULL)) 636 if (fork1(l, 0, SIGCHLD, NULL, 0, start_init, NULL, NULL))
637 panic("fork init"); 637 panic("fork init");
638 638
639 /* 639 /*
640 * The initproc variable cannot be initialized in start_init as there 640 * The initproc variable cannot be initialized in start_init as there
641 * is a race between vfs_mountroot and start_init. 641 * is a race between vfs_mountroot and start_init.
642 */ 642 */
643 mutex_enter(proc_lock); 643 mutex_enter(proc_lock);
644 initproc = proc_find_raw(1); 644 initproc = proc_find_raw(1);
645 mutex_exit(proc_lock); 645 mutex_exit(proc_lock);
646 646
647 /* 647 /*
648 * Load any remaining builtin modules, and hand back temporary 648 * Load any remaining builtin modules, and hand back temporary
649 * storage to the VM system. Then require force when loading any 649 * storage to the VM system. Then require force when loading any
650 * remaining un-init'ed built-in modules to avoid later surprises. 650 * remaining un-init'ed built-in modules to avoid later surprises.
651 */ 651 */
652 module_init_class(MODULE_CLASS_ANY); 652 module_init_class(MODULE_CLASS_ANY);
653 module_builtin_require_force(); 653 module_builtin_require_force();
654 654
655 /* 655 /*
656 * Finalize configuration now that all real devices have been 656 * Finalize configuration now that all real devices have been
657 * found. This needs to be done before the root device is 657 * found. This needs to be done before the root device is
658 * selected, since finalization may create the root device. 658 * selected, since finalization may create the root device.
659 */ 659 */
660 config_finalize(); 660 config_finalize();
661 661
662 sysctl_finalize(); 662 sysctl_finalize();
663 663
664 /* 664 /*
665 * Now that autoconfiguration has completed, we can determine 665 * Now that autoconfiguration has completed, we can determine
666 * the root and dump devices. 666 * the root and dump devices.
667 */ 667 */
668 cpu_rootconf(); 668 cpu_rootconf();
669 cpu_dumpconf(); 669 cpu_dumpconf();
670 670
 671 /* Create the aiodone daemon kernel thread. */
 672 if (workqueue_create(&uvm.aiodone_queue, "aiodoned",
 673 uvm_aiodone_worker, NULL, PRI_VM, IPL_NONE, WQ_MPSAFE))
 674 panic("fork aiodoned");
 675
671 /* Mount the root file system. */ 676 /* Mount the root file system. */
672 do { 677 do {
673 domountroothook(root_device); 678 domountroothook(root_device);
674 if ((error = vfs_mountroot())) { 679 if ((error = vfs_mountroot())) {
675 printf("cannot mount root, error = %d\n", error); 680 printf("cannot mount root, error = %d\n", error);
676 boothowto |= RB_ASKNAME; 681 boothowto |= RB_ASKNAME;
677 setroot(root_device, 682 setroot(root_device,
678 (rootdev != NODEV) ? DISKPART(rootdev) : 0); 683 (rootdev != NODEV) ? DISKPART(rootdev) : 0);
679 } 684 }
680 } while (error != 0); 685 } while (error != 0);
681 mountroothook_destroy(); 686 mountroothook_destroy();
682 687
683 configure3(); 688 configure3();
684 689
685 /* 690 /*
686 * Initialise the time-of-day clock, passing the time recorded 691 * Initialise the time-of-day clock, passing the time recorded
687 * in the root filesystem (if any) for use by systems that 692 * in the root filesystem (if any) for use by systems that
688 * don't have a non-volatile time-of-day device. 693 * don't have a non-volatile time-of-day device.
689 */ 694 */
690 inittodr(rootfstime); 695 inittodr(rootfstime);
691 696
692 /* 697 /*
693 * Now can look at time, having had a chance to verify the time 698 * Now can look at time, having had a chance to verify the time
694 * from the file system. Reset l->l_rtime as it may have been 699 * from the file system. Reset l->l_rtime as it may have been
695 * munched in mi_switch() after the time got set. 700 * munched in mi_switch() after the time got set.
696 */ 701 */
697 getnanotime(&time); 702 getnanotime(&time);
698 { 703 {
699 struct timespec ut; 704 struct timespec ut;
700 /* 705 /*
701 * was: 706 * was:
702 * boottime = time; 707 * boottime = time;
703 * but we can do better 708 * but we can do better
704 */ 709 */
705 nanouptime(&ut); 710 nanouptime(&ut);
706 timespecsub(&time, &ut, &boottime); 711 timespecsub(&time, &ut, &boottime);
707 } 712 }
708 713
709 mutex_enter(proc_lock); 714 mutex_enter(proc_lock);
710 LIST_FOREACH(p, &allproc, p_list) { 715 LIST_FOREACH(p, &allproc, p_list) {
711 KASSERT((p->p_flag & PK_MARKER) == 0); 716 KASSERT((p->p_flag & PK_MARKER) == 0);
712 mutex_enter(p->p_lock); 717 mutex_enter(p->p_lock);
713 TIMESPEC_TO_TIMEVAL(&p->p_stats->p_start, &time); 718 TIMESPEC_TO_TIMEVAL(&p->p_stats->p_start, &time);
714 LIST_FOREACH(l, &p->p_lwps, l_sibling) { 719 LIST_FOREACH(l, &p->p_lwps, l_sibling) {
715 lwp_lock(l); 720 lwp_lock(l);
716 memset(&l->l_rtime, 0, sizeof(l->l_rtime)); 721 memset(&l->l_rtime, 0, sizeof(l->l_rtime));
717 lwp_unlock(l); 722 lwp_unlock(l);
718 } 723 }
719 mutex_exit(p->p_lock); 724 mutex_exit(p->p_lock);
720 } 725 }
721 mutex_exit(proc_lock); 726 mutex_exit(proc_lock);
722 binuptime(&curlwp->l_stime); 727 binuptime(&curlwp->l_stime);
723 728
724 for (CPU_INFO_FOREACH(cii, ci)) { 729 for (CPU_INFO_FOREACH(cii, ci)) {
725 ci->ci_schedstate.spc_lastmod = time_second; 730 ci->ci_schedstate.spc_lastmod = time_second;
726 } 731 }
727 732
728 /* Create the pageout daemon kernel thread. */ 733 /* Create the pageout daemon kernel thread. */
729 uvm_swap_init(); 734 uvm_swap_init();
730 if (kthread_create(PRI_PGDAEMON, KTHREAD_MPSAFE, NULL, uvm_pageout, 735 if (kthread_create(PRI_PGDAEMON, KTHREAD_MPSAFE, NULL, uvm_pageout,
731 NULL, NULL, "pgdaemon")) 736 NULL, NULL, "pgdaemon"))
732 panic("fork pagedaemon"); 737 panic("fork pagedaemon");
733 738
734 /* Create the filesystem syncer kernel thread. */ 739 /* Create the filesystem syncer kernel thread. */
735 if (kthread_create(PRI_IOFLUSH, KTHREAD_MPSAFE, NULL, sched_sync, 740 if (kthread_create(PRI_IOFLUSH, KTHREAD_MPSAFE, NULL, sched_sync,
736 NULL, NULL, "ioflush")) 741 NULL, NULL, "ioflush"))
737 panic("fork syncer"); 742 panic("fork syncer");
738 743
739 /* Create the aiodone daemon kernel thread. */ 
740 if (workqueue_create(&uvm.aiodone_queue, "aiodoned", 
741 uvm_aiodone_worker, NULL, PRI_VM, IPL_NONE, WQ_MPSAFE)) 
742 panic("fork aiodoned"); 
743 
744 /* Wait for final configure threads to complete. */ 744 /* Wait for final configure threads to complete. */
745 config_finalize_mountroot(); 745 config_finalize_mountroot();
746 746
747 /* 747 /*
748 * Okay, now we can let init(8) exec! It's off to userland! 748 * Okay, now we can let init(8) exec! It's off to userland!
749 */ 749 */
750 mutex_enter(proc_lock); 750 mutex_enter(proc_lock);
751 start_init_exec = 1; 751 start_init_exec = 1;
752 cv_broadcast(&lbolt); 752 cv_broadcast(&lbolt);
753 mutex_exit(proc_lock); 753 mutex_exit(proc_lock);
754 754
755 /* The scheduler is an infinite loop. */ 755 /* The scheduler is an infinite loop. */
756 uvm_scheduler(); 756 uvm_scheduler();
757 /* NOTREACHED */ 757 /* NOTREACHED */
758} 758}
759 759
760/* 760/*
761 * Configure the system's hardware. 761 * Configure the system's hardware.
762 */ 762 */
763static void 763static void
764configure(void) 764configure(void)
765{ 765{
766 766
767 /* Initialize autoconf data structures. */ 767 /* Initialize autoconf data structures. */
768 config_init_mi(); 768 config_init_mi();
769 /* 769 /*
770 * XXX 770 * XXX
771 * callout_setfunc() requires mutex(9) so it can't be in config_init() 771 * callout_setfunc() requires mutex(9) so it can't be in config_init()
772 * on amiga and atari which use config_init() and autoconf(9) fucntions 772 * on amiga and atari which use config_init() and autoconf(9) fucntions
773 * to initialize console devices. 773 * to initialize console devices.
774 */ 774 */
775 config_twiddle_init(); 775 config_twiddle_init();
776 776
777 pmf_init(); 777 pmf_init();
778 778
779 /* Initialize driver modules */ 779 /* Initialize driver modules */
780 module_init_class(MODULE_CLASS_DRIVER); 780 module_init_class(MODULE_CLASS_DRIVER);
781 781
782 userconf_init(); 782 userconf_init();
783 if (boothowto & RB_USERCONF) 783 if (boothowto & RB_USERCONF)
784 userconf_prompt(); 784 userconf_prompt();
785 785
786 if ((boothowto & (AB_SILENT|AB_VERBOSE)) == AB_SILENT) { 786 if ((boothowto & (AB_SILENT|AB_VERBOSE)) == AB_SILENT) {
787 printf_nolog("Detecting hardware..."); 787 printf_nolog("Detecting hardware...");
788 } 788 }
789 789
790 /* 790 /*
791 * Do the machine-dependent portion of autoconfiguration. This 791 * Do the machine-dependent portion of autoconfiguration. This
792 * sets the configuration machinery here in motion by "finding" 792 * sets the configuration machinery here in motion by "finding"
793 * the root bus. When this function returns, we expect interrupts 793 * the root bus. When this function returns, we expect interrupts
794 * to be enabled. 794 * to be enabled.
795 */ 795 */
796 cpu_configure(); 796 cpu_configure();
797} 797}
798 798
799static void 799static void
800configure2(void) 800configure2(void)
801{ 801{
802 CPU_INFO_ITERATOR cii; 802 CPU_INFO_ITERATOR cii;
803 struct cpu_info *ci; 803 struct cpu_info *ci;
804 int s; 804 int s;
805 805
806 /* 806 /*
807 * Now that we've found all the hardware, start the real time 807 * Now that we've found all the hardware, start the real time
808 * and statistics clocks. 808 * and statistics clocks.
809 */ 809 */
810 initclocks(); 810 initclocks();
811 811
812 cold = 0; /* clocks are running, we're warm now! */ 812 cold = 0; /* clocks are running, we're warm now! */
813 s = splsched(); 813 s = splsched();
814 curcpu()->ci_schedstate.spc_flags |= SPCF_RUNNING; 814 curcpu()->ci_schedstate.spc_flags |= SPCF_RUNNING;
815 splx(s); 815 splx(s);
816 816
817 /* Boot the secondary processors. */ 817 /* Boot the secondary processors. */
818 for (CPU_INFO_FOREACH(cii, ci)) { 818 for (CPU_INFO_FOREACH(cii, ci)) {
819 uvm_cpu_attach(ci); 819 uvm_cpu_attach(ci);
820 } 820 }
821 mp_online = true; 821 mp_online = true;
822#if defined(MULTIPROCESSOR) 822#if defined(MULTIPROCESSOR)
823 cpu_boot_secondary_processors(); 823 cpu_boot_secondary_processors();
824#endif 824#endif
825 825
826 /* Setup the runqueues and scheduler. */ 826 /* Setup the runqueues and scheduler. */
827 runq_init(); 827 runq_init();
828 synch_init(); 828 synch_init();
829 829
830 /* 830 /*
831 * Bus scans can make it appear as if the system has paused, so 831 * Bus scans can make it appear as if the system has paused, so
832 * twiddle constantly while config_interrupts() jobs are running. 832 * twiddle constantly while config_interrupts() jobs are running.
833 */ 833 */
834 config_twiddle_fn(NULL); 834 config_twiddle_fn(NULL);
835 835
836 /* 836 /*
837 * Create threads to call back and finish configuration for 837 * Create threads to call back and finish configuration for
838 * devices that want interrupts enabled. 838 * devices that want interrupts enabled.
839 */ 839 */
840 config_create_interruptthreads(); 840 config_create_interruptthreads();
841} 841}
842 842
843static void 843static void
844configure3(void) 844configure3(void)
845{ 845{
846 846
847 /* 847 /*
848 * Create threads to call back and finish configuration for 848 * Create threads to call back and finish configuration for
849 * devices that want the mounted root file system. 849 * devices that want the mounted root file system.
850 */ 850 */
851 config_create_mountrootthreads(); 851 config_create_mountrootthreads();
852 852
853 /* Get the threads going and into any sleeps before continuing. */ 853 /* Get the threads going and into any sleeps before continuing. */
854 yield(); 854 yield();
855} 855}
856 856
857static void 857static void
858rootconf_handle_wedges(void) 858rootconf_handle_wedges(void)
859{ 859{
860 struct disklabel label; 860 struct disklabel label;
861 struct partition *p; 861 struct partition *p;
862 struct vnode *vp; 862 struct vnode *vp;
863 daddr_t startblk; 863 daddr_t startblk;
864 uint64_t nblks; 864 uint64_t nblks;
865 device_t dev; 865 device_t dev;
866 int error; 866 int error;
867 867
868 if (booted_nblks) { 868 if (booted_nblks) {
869 /* 869 /*
870 * bootloader passed geometry 870 * bootloader passed geometry
871 */ 871 */
872 dev = booted_device; 872 dev = booted_device;
873 startblk = booted_startblk; 873 startblk = booted_startblk;
874 nblks = booted_nblks; 874 nblks = booted_nblks;
875 875
876 /* 876 /*
877 * keep booted_device and booted_partition 877 * keep booted_device and booted_partition
878 * in case the kernel doesn't identify a wedge 878 * in case the kernel doesn't identify a wedge
879 */ 879 */
880 } else { 880 } else {
881 /* 881 /*
882 * bootloader passed partition number 882 * bootloader passed partition number
883 * 883 *
884 * We cannot ask the partition device directly when it is 884 * We cannot ask the partition device directly when it is
885 * covered by a wedge. Instead we look up the geometry in 885 * covered by a wedge. Instead we look up the geometry in
886 * the disklabel. 886 * the disklabel.
887 */ 887 */
888 vp = opendisk(booted_device); 888 vp = opendisk(booted_device);
889 889
890 if (vp == NULL) 890 if (vp == NULL)
891 return; 891 return;
892 892
893 error = VOP_IOCTL(vp, DIOCGDINFO, &label, FREAD, NOCRED); 893 error = VOP_IOCTL(vp, DIOCGDINFO, &label, FREAD, NOCRED);
894 VOP_CLOSE(vp, FREAD, NOCRED); 894 VOP_CLOSE(vp, FREAD, NOCRED);
895 vput(vp); 895 vput(vp);
896 if (error) 896 if (error)
897 return; 897 return;
898 898
899 KASSERT(booted_partition >= 0 899 KASSERT(booted_partition >= 0
900 && booted_partition < MAXPARTITIONS); 900 && booted_partition < MAXPARTITIONS);
901 901
902 p = &label.d_partitions[booted_partition]; 902 p = &label.d_partitions[booted_partition];
903 903
904 dev = booted_device; 904 dev = booted_device;
905 startblk = p->p_offset; 905 startblk = p->p_offset;
906 nblks = p->p_size; 906 nblks = p->p_size;
907 } 907 }
908 908
909 dev = dkwedge_find_partition(dev, startblk, nblks); 909 dev = dkwedge_find_partition(dev, startblk, nblks);
910 if (dev != NULL) { 910 if (dev != NULL) {
911 booted_device = dev; 911 booted_device = dev;
912 booted_partition = 0; 912 booted_partition = 0;
913 } 913 }
914} 914}
915 915
916void 916void
917rootconf(void) 917rootconf(void)
918{ 918{
919 if (booted_device != NULL) 919 if (booted_device != NULL)
920 rootconf_handle_wedges(); 920 rootconf_handle_wedges();
921 921
922 setroot(booted_device, booted_partition); 922 setroot(booted_device, booted_partition);
923} 923}
924 924
925static void 925static void
926check_console(struct lwp *l) 926check_console(struct lwp *l)
927{ 927{
928 struct vnode *vp; 928 struct vnode *vp;
929 int error; 929 int error;
930 930
931 error = namei_simple_kernel("/dev/console", 931 error = namei_simple_kernel("/dev/console",
932 NSM_FOLLOW_NOEMULROOT, &vp); 932 NSM_FOLLOW_NOEMULROOT, &vp);
933 if (error == 0) { 933 if (error == 0) {
934 vrele(vp); 934 vrele(vp);
935 } else if (error == ENOENT) { 935 } else if (error == ENOENT) {
936 if (boothowto & (AB_VERBOSE|AB_DEBUG)) 936 if (boothowto & (AB_VERBOSE|AB_DEBUG))
937 printf("warning: no /dev/console\n"); 937 printf("warning: no /dev/console\n");
938 } else { 938 } else {
939 printf("warning: lookup /dev/console: error %d\n", error); 939 printf("warning: lookup /dev/console: error %d\n", error);
940 } 940 }
941} 941}
942 942
943/* 943/*
944 * List of paths to try when searching for "init". 944 * List of paths to try when searching for "init".
945 */ 945 */
946static const char * const initpaths[] = { 946static const char * const initpaths[] = {
947 "/sbin/init", 947 "/sbin/init",
948 "/sbin/oinit", 948 "/sbin/oinit",
949 "/sbin/init.bak", 949 "/sbin/init.bak",
950 "/rescue/init", 950 "/rescue/init",
951 NULL, 951 NULL,
952}; 952};
953 953
954/* 954/*
955 * Start the initial user process; try exec'ing each pathname in "initpaths". 955 * Start the initial user process; try exec'ing each pathname in "initpaths".
956 * The program is invoked with one argument containing the boot flags. 956 * The program is invoked with one argument containing the boot flags.
957 */ 957 */
958static void 958static void
959start_init(void *arg) 959start_init(void *arg)
960{ 960{
961 struct lwp *l = arg; 961 struct lwp *l = arg;
962 struct proc *p = l->l_proc; 962 struct proc *p = l->l_proc;
963 vaddr_t addr; 963 vaddr_t addr;
964 struct sys_execve_args /* { 964 struct sys_execve_args /* {
965 syscallarg(const char *) path; 965 syscallarg(const char *) path;
966 syscallarg(char * const *) argp; 966 syscallarg(char * const *) argp;
967 syscallarg(char * const *) envp; 967 syscallarg(char * const *) envp;
968 } */ args; 968 } */ args;
969 int options, i, error; 969 int options, i, error;
970 register_t retval[2]; 970 register_t retval[2];
971 char flags[4], *flagsp; 971 char flags[4], *flagsp;
972 const char *path, *slash; 972 const char *path, *slash;
973 char *ucp, **uap, *arg0, *arg1, *argv[3]; 973 char *ucp, **uap, *arg0, *arg1, *argv[3];
974 char ipath[129]; 974 char ipath[129];
975 int ipx, len; 975 int ipx, len;
976 976
977 /* 977 /*
978 * Now in process 1. 978 * Now in process 1.
979 */ 979 */
980 strncpy(p->p_comm, "init", MAXCOMLEN); 980 strncpy(p->p_comm, "init", MAXCOMLEN);
981 981
982 /* 982 /*
983 * Wait for main() to tell us that it's safe to exec. 983 * Wait for main() to tell us that it's safe to exec.
984 */ 984 */
985 mutex_enter(proc_lock); 985 mutex_enter(proc_lock);
986 while (start_init_exec == 0) 986 while (start_init_exec == 0)
987 cv_wait(&lbolt, proc_lock); 987 cv_wait(&lbolt, proc_lock);
988 mutex_exit(proc_lock); 988 mutex_exit(proc_lock);
989 989
990 /* 990 /*
991 * This is not the right way to do this. We really should 991 * This is not the right way to do this. We really should
992 * hand-craft a descriptor onto /dev/console to hand to init, 992 * hand-craft a descriptor onto /dev/console to hand to init,
993 * but that's a _lot_ more work, and the benefit from this easy 993 * but that's a _lot_ more work, and the benefit from this easy
994 * hack makes up for the "good is the enemy of the best" effect. 994 * hack makes up for the "good is the enemy of the best" effect.
995 */ 995 */
996 check_console(l); 996 check_console(l);
997 997
998 /* 998 /*
999 * Need just enough stack to hold the faked-up "execve()" arguments. 999 * Need just enough stack to hold the faked-up "execve()" arguments.
1000 */ 1000 */
1001 addr = (vaddr_t)STACK_ALLOC(USRSTACK, PAGE_SIZE); 1001 addr = (vaddr_t)STACK_ALLOC(USRSTACK, PAGE_SIZE);
1002 if (uvm_map(&p->p_vmspace->vm_map, &addr, PAGE_SIZE, 1002 if (uvm_map(&p->p_vmspace->vm_map, &addr, PAGE_SIZE,
1003 NULL, UVM_UNKNOWN_OFFSET, 0, 1003 NULL, UVM_UNKNOWN_OFFSET, 0,
1004 UVM_MAPFLAG(UVM_PROT_RW, UVM_PROT_RW, UVM_INH_COPY, 1004 UVM_MAPFLAG(UVM_PROT_RW, UVM_PROT_RW, UVM_INH_COPY,
1005 UVM_ADV_NORMAL, 1005 UVM_ADV_NORMAL,
1006 UVM_FLAG_FIXED|UVM_FLAG_OVERLAY|UVM_FLAG_COPYONW)) != 0) 1006 UVM_FLAG_FIXED|UVM_FLAG_OVERLAY|UVM_FLAG_COPYONW)) != 0)
1007 panic("init: couldn't allocate argument space"); 1007 panic("init: couldn't allocate argument space");
1008 p->p_vmspace->vm_maxsaddr = (void *)STACK_MAX(addr, PAGE_SIZE); 1008 p->p_vmspace->vm_maxsaddr = (void *)STACK_MAX(addr, PAGE_SIZE);
1009 1009
1010 ipx = 0; 1010 ipx = 0;
1011 while (1) { 1011 while (1) {
1012 if (boothowto & RB_ASKNAME) { 1012 if (boothowto & RB_ASKNAME) {
1013 printf("init path"); 1013 printf("init path");
1014 if (initpaths[ipx]) 1014 if (initpaths[ipx])
1015 printf(" (default %s)", initpaths[ipx]); 1015 printf(" (default %s)", initpaths[ipx]);
1016 printf(": "); 1016 printf(": ");
1017 len = cngetsn(ipath, sizeof(ipath)-1); 1017 len = cngetsn(ipath, sizeof(ipath)-1);
1018 if (len == 4 && strcmp(ipath, "halt") == 0) { 1018 if (len == 4 && strcmp(ipath, "halt") == 0) {
1019 cpu_reboot(RB_HALT, NULL); 1019 cpu_reboot(RB_HALT, NULL);
1020 } else if (len == 6 && strcmp(ipath, "reboot") == 0) { 1020 } else if (len == 6 && strcmp(ipath, "reboot") == 0) {
1021 cpu_reboot(0, NULL); 1021 cpu_reboot(0, NULL);
1022#if defined(DDB) 1022#if defined(DDB)
1023 } else if (len == 3 && strcmp(ipath, "ddb") == 0) { 1023 } else if (len == 3 && strcmp(ipath, "ddb") == 0) {
1024 console_debugger(); 1024 console_debugger();
1025 continue; 1025 continue;
1026#endif 1026#endif
1027 } else if (len > 0 && ipath[0] == '/') { 1027 } else if (len > 0 && ipath[0] == '/') {
1028 ipath[len] = '\0'; 1028 ipath[len] = '\0';
1029 path = ipath; 1029 path = ipath;
1030 } else if (len == 0 && initpaths[ipx] != NULL) { 1030 } else if (len == 0 && initpaths[ipx] != NULL) {
1031 path = initpaths[ipx++]; 1031 path = initpaths[ipx++];
1032 } else { 1032 } else {
1033 printf("use absolute path, "); 1033 printf("use absolute path, ");
1034#if defined(DDB) 1034#if defined(DDB)
1035 printf("\"ddb\", "); 1035 printf("\"ddb\", ");
1036#endif 1036#endif
1037 printf("\"halt\", or \"reboot\"\n"); 1037 printf("\"halt\", or \"reboot\"\n");
1038 continue; 1038 continue;
1039 } 1039 }
1040 } else { 1040 } else {
1041 if ((path = initpaths[ipx++]) == NULL) { 1041 if ((path = initpaths[ipx++]) == NULL) {
1042 ipx = 0; 1042 ipx = 0;
1043 boothowto |= RB_ASKNAME; 1043 boothowto |= RB_ASKNAME;
1044 continue; 1044 continue;
1045 } 1045 }
1046 } 1046 }
1047 1047
1048 ucp = (char *)USRSTACK; 1048 ucp = (char *)USRSTACK;
1049 1049
1050 /* 1050 /*
1051 * Construct the boot flag argument. 1051 * Construct the boot flag argument.
1052 */ 1052 */
1053 flagsp = flags; 1053 flagsp = flags;
1054 *flagsp++ = '-'; 1054 *flagsp++ = '-';
1055 options = 0; 1055 options = 0;
1056 1056
1057 if (boothowto & RB_SINGLE) { 1057 if (boothowto & RB_SINGLE) {
1058 *flagsp++ = 's'; 1058 *flagsp++ = 's';
1059 options = 1; 1059 options = 1;
1060 } 1060 }
1061#ifdef notyet 1061#ifdef notyet
1062 if (boothowto & RB_FASTBOOT) { 1062 if (boothowto & RB_FASTBOOT) {
1063 *flagsp++ = 'f'; 1063 *flagsp++ = 'f';
1064 options = 1; 1064 options = 1;
1065 } 1065 }
1066#endif 1066#endif
1067 1067
1068 /* 1068 /*
1069 * Move out the flags (arg 1), if necessary. 1069 * Move out the flags (arg 1), if necessary.
1070 */ 1070 */
1071 if (options != 0) { 1071 if (options != 0) {
1072 *flagsp++ = '\0'; 1072 *flagsp++ = '\0';
1073 i = flagsp - flags; 1073 i = flagsp - flags;
1074#ifdef DEBUG 1074#ifdef DEBUG
1075 aprint_normal("init: copying out flags `%s' %d\n", flags, i); 1075 aprint_normal("init: copying out flags `%s' %d\n", flags, i);
1076#endif 1076#endif
1077 arg1 = STACK_ALLOC(ucp, i); 1077 arg1 = STACK_ALLOC(ucp, i);
1078 ucp = STACK_MAX(arg1, i); 1078 ucp = STACK_MAX(arg1, i);
1079 if ((error = copyout((void *)flags, arg1, i)) != 0) 1079 if ((error = copyout((void *)flags, arg1, i)) != 0)
1080 goto copyerr; 1080 goto copyerr;
1081 } else 1081 } else
1082 arg1 = NULL; 1082 arg1 = NULL;
1083 1083
1084 /* 1084 /*
1085 * Move out the file name (also arg 0). 1085 * Move out the file name (also arg 0).
1086 */ 1086 */
1087 i = strlen(path) + 1; 1087 i = strlen(path) + 1;
1088#ifdef DEBUG 1088#ifdef DEBUG
1089 aprint_normal("init: copying out path `%s' %d\n", path, i); 1089 aprint_normal("init: copying out path `%s' %d\n", path, i);
1090#else 1090#else
1091 if (boothowto & RB_ASKNAME || path != initpaths[0]) 1091 if (boothowto & RB_ASKNAME || path != initpaths[0])
1092 printf("init: trying %s\n", path); 1092 printf("init: trying %s\n", path);
1093#endif 1093#endif
1094 arg0 = STACK_ALLOC(ucp, i); 1094 arg0 = STACK_ALLOC(ucp, i);
1095 ucp = STACK_MAX(arg0, i); 1095 ucp = STACK_MAX(arg0, i);
1096 if ((error = copyout(path, arg0, i)) != 0) 1096 if ((error = copyout(path, arg0, i)) != 0)
1097 goto copyerr; 1097 goto copyerr;
1098 1098
1099 /* 1099 /*
1100 * Move out the arg pointers. 1100 * Move out the arg pointers.
1101 */ 1101 */
1102 ucp = (void *)STACK_ALIGN(ucp, STACK_ALIGNBYTES); 1102 ucp = (void *)STACK_ALIGN(ucp, STACK_ALIGNBYTES);
1103 uap = (char **)STACK_ALLOC(ucp, sizeof(argv)); 1103 uap = (char **)STACK_ALLOC(ucp, sizeof(argv));
1104 SCARG(&args, path) = arg0; 1104 SCARG(&args, path) = arg0;
1105 SCARG(&args, argp) = uap; 1105 SCARG(&args, argp) = uap;
1106 SCARG(&args, envp) = NULL; 1106 SCARG(&args, envp) = NULL;
1107 slash = strrchr(path, '/'); 1107 slash = strrchr(path, '/');
1108 1108
1109 argv[0] = slash ? arg0 + (slash + 1 - path) : arg0; 1109 argv[0] = slash ? arg0 + (slash + 1 - path) : arg0;
1110 argv[1] = arg1; 1110 argv[1] = arg1;
1111 argv[2] = NULL; 1111 argv[2] = NULL;
1112 if ((error = copyout(argv, uap, sizeof(argv))) != 0) 1112 if ((error = copyout(argv, uap, sizeof(argv))) != 0)
1113 goto copyerr; 1113 goto copyerr;
1114 1114
1115 /* 1115 /*
1116 * Now try to exec the program. If it can't for any reason 1116 * Now try to exec the program. If it can't for any reason
1117 * other than it doesn't exist, complain. 1117 * other than it doesn't exist, complain.
1118 */ 1118 */
1119 error = sys_execve(l, &args, retval); 1119 error = sys_execve(l, &args, retval);
1120 if (error == 0 || error == EJUSTRETURN) { 1120 if (error == 0 || error == EJUSTRETURN) {
1121 KERNEL_UNLOCK_LAST(l); 1121 KERNEL_UNLOCK_LAST(l);
1122 return; 1122 return;
1123 } 1123 }
1124 printf("exec %s: error %d\n", path, error); 1124 printf("exec %s: error %d\n", path, error);
1125 } 1125 }
1126 printf("init: not found\n"); 1126 printf("init: not found\n");
1127 panic("no init"); 1127 panic("no init");
1128copyerr: 1128copyerr:
1129 panic("copyout %d", error); 1129 panic("copyout %d", error);
1130} 1130}
1131 1131
1132/* 1132/*
1133 * calculate cache size (in bytes) from physmem and vsize. 1133 * calculate cache size (in bytes) from physmem and vsize.
1134 */ 1134 */
1135vaddr_t 1135vaddr_t
1136calc_cache_size(vsize_t vsize, int pct, int va_pct) 1136calc_cache_size(vsize_t vsize, int pct, int va_pct)
1137{ 1137{
1138 paddr_t t; 1138 paddr_t t;
1139 1139
1140 /* XXX should consider competing cache if any */ 1140 /* XXX should consider competing cache if any */
1141 /* XXX should consider submaps */ 1141 /* XXX should consider submaps */
1142 t = (uintmax_t)physmem * pct / 100 * PAGE_SIZE; 1142 t = (uintmax_t)physmem * pct / 100 * PAGE_SIZE;
1143 if (vsize != 0) { 1143 if (vsize != 0) {
1144 vsize = (uintmax_t)vsize * va_pct / 100; 1144 vsize = (uintmax_t)vsize * va_pct / 100;
1145 if (t > vsize) { 1145 if (t > vsize) {
1146 t = vsize; 1146 t = vsize;
1147 } 1147 }
1148 } 1148 }
1149 return t; 1149 return t;
1150} 1150}
1151 1151
1152/* 1152/*
1153 * Print the system start up banner. 1153 * Print the system start up banner.
1154 * 1154 *
1155 * - Print a limited banner if AB_SILENT. 1155 * - Print a limited banner if AB_SILENT.
1156 * - Always send normal banner to the log. 1156 * - Always send normal banner to the log.
1157 */ 1157 */
1158#define MEM_PBUFSIZE sizeof("99999 MB") 1158#define MEM_PBUFSIZE sizeof("99999 MB")
1159 1159
1160void 1160void
1161banner(void) 1161banner(void)
1162{ 1162{
1163 static char notice[] = " Notice: this software is " 1163 static char notice[] = " Notice: this software is "
1164 "protected by copyright"; 1164 "protected by copyright";
1165 char pbuf[81]; 1165 char pbuf[81];
1166 void (*pr)(const char *, ...) __printflike(1, 2); 1166 void (*pr)(const char *, ...) __printflike(1, 2);
1167 int i; 1167 int i;
1168 1168
1169 if ((boothowto & AB_SILENT) != 0) { 1169 if ((boothowto & AB_SILENT) != 0) {
1170 snprintf(pbuf, sizeof(pbuf), "%s %s (%s)", 1170 snprintf(pbuf, sizeof(pbuf), "%s %s (%s)",
1171 ostype, osrelease, kernel_ident); 1171 ostype, osrelease, kernel_ident);
1172 printf_nolog("%s", pbuf); 1172 printf_nolog("%s", pbuf);
1173 for (i = 80 - strlen(pbuf) - sizeof(notice); i > 0; i--) 1173 for (i = 80 - strlen(pbuf) - sizeof(notice); i > 0; i--)
1174 printf(" "); 1174 printf(" ");
1175 printf_nolog("%s\n", notice); 1175 printf_nolog("%s\n", notice);
1176 pr = aprint_normal; 1176 pr = aprint_normal;
1177 } else { 1177 } else {
1178 pr = printf; 1178 pr = printf;
1179 } 1179 }
1180 1180
1181 memset(pbuf, 0, sizeof(pbuf)); 1181 memset(pbuf, 0, sizeof(pbuf));
1182 (*pr)("%s%s", copyright, version); 1182 (*pr)("%s%s", copyright, version);
1183 format_bytes(pbuf, MEM_PBUFSIZE, ctob((uint64_t)physmem)); 1183 format_bytes(pbuf, MEM_PBUFSIZE, ctob((uint64_t)physmem));
1184 (*pr)("total memory = %s\n", pbuf); 1184 (*pr)("total memory = %s\n", pbuf);
1185 format_bytes(pbuf, MEM_PBUFSIZE, ctob((uint64_t)uvmexp.free)); 1185 format_bytes(pbuf, MEM_PBUFSIZE, ctob((uint64_t)uvmexp.free));
1186 (*pr)("avail memory = %s\n", pbuf); 1186 (*pr)("avail memory = %s\n", pbuf);
1187} 1187}