]> git.saurik.com Git - apple/xnu.git/blame - bsd/kern/bsd_init.c
xnu-1504.15.3.tar.gz
[apple/xnu.git] / bsd / kern / bsd_init.c
CommitLineData
1c79356b 1/*
b0d623f7 2 * Copyright (c) 2000-2009 Apple Inc. All rights reserved.
5d5c5d0d 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 5 *
2d21ac55
A
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
8f6c56a5 14 *
2d21ac55
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
8f6c56a5 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
b0d623f7
A
27 *
28 *
1c79356b
A
29 * Copyright (c) 1982, 1986, 1989, 1991, 1992, 1993
30 * The Regents of the University of California. All rights reserved.
31 * (c) UNIX System Laboratories, Inc.
32 * All or some portions of this file are derived from material licensed
33 * to the University of California by American Telephone and Telegraph
34 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
35 * the permission of UNIX System Laboratories, Inc.
36 *
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
39 * are met:
40 * 1. Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * 2. Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in the
44 * documentation and/or other materials provided with the distribution.
45 * 3. All advertising materials mentioning features or use of this software
46 * must display the following acknowledgement:
47 * This product includes software developed by the University of
48 * California, Berkeley and its contributors.
49 * 4. Neither the name of the University nor the names of its contributors
50 * may be used to endorse or promote products derived from this software
51 * without specific prior written permission.
52 *
53 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
54 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
55 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
56 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
57 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
58 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
59 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
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
62 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63 * SUCH DAMAGE.
64 *
65 * @(#)init_main.c 8.16 (Berkeley) 5/14/95
66 */
67
68/*
69 *
70 * Mach Operating System
71 * Copyright (c) 1987 Carnegie-Mellon University
72 * All rights reserved. The CMU software License Agreement specifies
73 * the terms and conditions for use and redistribution.
74 */
2d21ac55
A
75/*
76 * NOTICE: This file was modified by McAfee Research in 2004 to introduce
77 * support for mandatory and extensible security protections. This notice
78 * is included in support of clause 2.2 (b) of the Apple Public License,
79 * Version 2.0.
80 */
1c79356b
A
81
82#include <sys/param.h>
83#include <sys/filedesc.h>
84#include <sys/kernel.h>
91447636
A
85#include <sys/mount_internal.h>
86#include <sys/proc_internal.h>
87#include <sys/kauth.h>
1c79356b 88#include <sys/systm.h>
91447636 89#include <sys/vnode_internal.h>
1c79356b 90#include <sys/conf.h>
91447636 91#include <sys/buf_internal.h>
1c79356b
A
92#include <sys/clist.h>
93#include <sys/user.h>
55e303ae
A
94#include <sys/time.h>
95#include <sys/systm.h>
91447636 96#include <sys/mman.h>
55e303ae 97
b0d623f7 98#include <security/audit/audit.h>
1c79356b
A
99
100#include <sys/malloc.h>
101#include <sys/dkstat.h>
2d21ac55 102#include <sys/codesign.h>
1c79356b 103
91447636 104#include <kern/startup.h>
1c79356b
A
105#include <kern/thread.h>
106#include <kern/task.h>
107#include <kern/ast.h>
b0d623f7 108#include <kern/kalloc.h>
1c79356b
A
109
110#include <mach/vm_param.h>
111
112#include <vm/vm_map.h>
113#include <vm/vm_kern.h>
114
55e303ae 115#include <sys/ux_exception.h> /* for ux_exception_port */
1c79356b
A
116
117#include <sys/reboot.h>
118#include <mach/exception_types.h>
55e303ae 119#include <dev/busvar.h> /* for pseudo_inits */
1c79356b
A
120#include <sys/kdebug.h>
121
765c9de3
A
122#include <mach/mach_types.h>
123#include <mach/vm_prot.h>
124#include <mach/semaphore.h>
125#include <mach/sync_policy.h>
126#include <kern/clock.h>
127#include <mach/kern_return.h>
2d21ac55
A
128#include <mach/thread_act.h> /* for thread_resume() */
129#include <mach/task.h> /* for task_set_exception_ports() */
130#include <sys/ux_exception.h> /* for ux_handler() */
131#include <sys/ubc_internal.h> /* for ubc_init() */
132#include <sys/mcache.h> /* for mcache_init() */
133#include <sys/mbuf.h> /* for mbinit() */
134#include <sys/event.h> /* for knote_init() */
135#include <sys/aio_kern.h> /* for aio_init() */
136#include <sys/semaphore.h> /* for psem_cache_init() */
137#include <net/dlil.h> /* for dlil_init() */
138#include <net/kpi_protocol.h> /* for proto_kpi_init() */
139#include <sys/pipe.h> /* for pipeinit() */
140#include <sys/socketvar.h> /* for socketinit() */
141#include <sys/protosw.h> /* for domaininit() */
142#include <kern/sched_prim.h> /* for thread_wakeup() */
143#include <net/if_ether.h> /* for ether_family_init() */
144#include <vm/vm_protos.h> /* for vnode_pager_bootstrap() */
145#include <miscfs/devfs/devfsdefs.h> /* for devfs_kernel_mount() */
146#include <mach/host_priv.h> /* for host_set_exception_ports() */
147#include <kern/host.h> /* for host_priv_self() */
148#include <vm/vm_kern.h> /* for kmem_suballoc() */
149#include <sys/semaphore.h> /* for psem_lock_init() */
150#include <sys/msgbuf.h> /* for log_setsize() */
b0d623f7
A
151#include <sys/tty.h> /* for tty_init() */
152#include <net/if_utun.h> /* for utun_register_control() */
153#include <net/net_str_id.h> /* for net_str_id_init() */
9bccf70c 154
91447636
A
155#include <net/init.h>
156
2d21ac55
A
157#if CONFIG_MACF
158#include <security/mac_framework.h>
159#include <security/mac_internal.h> /* mac_init_bsd() */
160#include <security/mac_mach_internal.h> /* mac_update_task_label() */
161#endif
162
0c530ab8
A
163#include <machine/exec.h>
164
2d21ac55
A
165#if CONFIG_IMAGEBOOT
166#include <sys/imageboot.h>
167#endif
168
b0d623f7
A
169#if PFLOG
170#include <net/if_pflog.h>
171#endif
172
2d21ac55
A
173#include <pexpert/pexpert.h>
174
175void * get_user_regs(thread_t); /* XXX kludge for <machine/thread.h> */
176void IOKitInitializeTime(void); /* XXX */
b0d623f7 177void IOSleep(unsigned int); /* XXX */
2d21ac55 178void loopattach(void); /* XXX */
b0d623f7 179void vc_progress_set(boolean_t, uint32_t); /* XXX */
1c79356b 180
b0d623f7 181const char copyright[] =
55e303ae
A
182"Copyright (c) 1982, 1986, 1989, 1991, 1993\n\t"
183"The Regents of the University of California. "
184"All rights reserved.\n\n";
1c79356b 185
1c79356b
A
186/* Components of the first process -- never freed. */
187struct proc proc0;
188struct session session0;
189struct pgrp pgrp0;
1c79356b
A
190struct filedesc filedesc0;
191struct plimit limit0;
192struct pstats pstats0;
193struct sigacts sigacts0;
2d21ac55
A
194proc_t kernproc;
195proc_t initproc;
1c79356b 196
1c79356b
A
197long tk_cancc;
198long tk_nin;
199long tk_nout;
200long tk_rawcc;
201
91447636 202int lock_trace = 0;
1c79356b
A
203/* Global variables to make pstat happy. We do swapping differently */
204int nswdev, nswap;
205int nswapmap;
206void *swapmap;
207struct swdevt swdevt[1];
208
209dev_t rootdev; /* device of the root */
210dev_t dumpdev; /* device to take dumps on */
211long dumplo; /* offset into dumpdev */
212long hostid;
213char hostname[MAXHOSTNAMELEN];
55e303ae 214int hostnamelen;
1c79356b 215char domainname[MAXDOMNAMELEN];
55e303ae 216int domainnamelen;
b0d623f7 217#if defined(__i386__) || defined(__x86_64__)
0c530ab8
A
218struct exec_archhandler exec_archhandler_ppc = {
219 .path = "/usr/libexec/oah/translate",
220};
b0d623f7 221const char * const kRosettaStandIn_str = "/usr/libexec/oah/RosettaNonGrata";
0c530ab8
A
222#else /* __i386__ */
223struct exec_archhandler exec_archhandler_ppc;
224#endif /* __i386__ */
1c79356b
A
225
226char rootdevice[16]; /* hfs device names have at least 9 chars */
1c79356b 227
2d21ac55 228#if KMEMSTATS
1c79356b
A
229struct kmemstats kmemstats[M_LAST];
230#endif
231
232int lbolt; /* awoken once a second */
233struct vnode *rootvp;
234int boothowto = RB_DEBUG;
235
2d21ac55 236void lightning_bolt(void *);
cf7d32b8 237extern kern_return_t IOFindBSDRoot(char *, unsigned int, dev_t *, u_int32_t *);
2d21ac55
A
238extern void IOSecureBSDRoot(const char * rootName);
239extern kern_return_t IOKitBSDInit(void );
240extern void kminit(void);
241extern void klogwakeup(void);
242extern void file_lock_init(void);
243extern void kmeminit(void);
244extern void bsd_bufferinit(void);
245
246extern int srv;
247extern int ncl;
248
1c79356b
A
249vm_map_t bsd_pageable_map;
250vm_map_t mb_map;
b0d623f7
A
251
252static int bsd_simul_execs = BSD_SIMUL_EXECS;
253static int bsd_pageable_map_size = BSD_PAGABLE_MAP_SIZE;
254__private_extern__ int execargs_cache_size = BSD_SIMUL_EXECS;
255__private_extern__ int execargs_free_count = BSD_SIMUL_EXECS;
256__private_extern__ vm_offset_t * execargs_cache = NULL;
257
258void bsd_exec_setup(int);
259
260/*
261 * Set to disable grading 64 bit Mach-o binaries as executable, for testing;
262 * Intel only.
263 */
264__private_extern__ int bootarg_no64exec = 0;
1c79356b
A
265
266int cmask = CMASK;
0c530ab8 267extern int customnbuf;
1c79356b 268
2d21ac55 269void bsd_init(void) __attribute__((section("__TEXT, initcode")));
2d21ac55
A
270kern_return_t bsd_autoconf(void) __attribute__((section("__TEXT, initcode")));
271void bsd_utaskbootstrap(void) __attribute__((section("__TEXT, initcode")));
272
273static void parse_bsd_args(void);
9bccf70c 274extern task_t bsd_init_task;
1c79356b 275extern char init_task_failure_data[];
9bccf70c 276extern void time_zone_slock_init(void);
2d21ac55 277static void process_name(const char *, proc_t);
91447636
A
278
279static void setconf(void);
1c79356b 280
55e303ae 281funnel_t *kernel_flock;
91447636 282
2d21ac55 283#if SYSV_SHM
91447636 284extern void sysv_shm_lock_init(void);
2d21ac55
A
285#endif
286#if SYSV_SEM
91447636 287extern void sysv_sem_lock_init(void);
2d21ac55
A
288#endif
289#if SYSV_MSG
91447636 290extern void sysv_msg_lock_init(void);
2d21ac55
A
291#endif
292extern void pthread_init(void);
0c530ab8
A
293
294/* kmem access not enabled by default; can be changed with boot-args */
295int setup_kmem = 0;
296
2d21ac55
A
297/* size of kernel trace buffer, disabled by default */
298unsigned int new_nkdbufs = 0;
299
300/* mach leak logging */
301int log_leaks = 0;
302int turn_on_log_leaks = 0;
303
304extern void stackshot_lock_init(void);
1c79356b 305
b0d623f7
A
306
307/* If we are using CONFIG_DTRACE */
308#if CONFIG_DTRACE
309 extern void dtrace_postinit(void);
310#endif
311
312
1c79356b
A
313/*
314 * Initialization code.
315 * Called from cold start routine as
316 * soon as a stack and segmentation
317 * have been established.
318 * Functions:
1c79356b
A
319 * turn on clock
320 * hand craft 0th process
321 * call all initialization routines
55e303ae 322 * hand craft 1st user process
1c79356b
A
323 */
324
325/*
326 * Sets the name for the given task.
327 */
91447636 328static void
2d21ac55 329process_name(const char *s, proc_t p)
1c79356b 330{
2d21ac55 331 size_t length = strlen(s);
1c79356b
A
332
333 bcopy(s, p->p_comm,
334 length >= sizeof(p->p_comm) ? sizeof(p->p_comm) :
335 length + 1);
336}
337
1c79356b
A
338/* To allow these values to be patched, they're globals here */
339#include <machine/vmparam.h>
2d21ac55 340struct rlimit vm_initial_limit_stack = { DFLSSIZ, MAXSSIZ - PAGE_SIZE };
1c79356b
A
341struct rlimit vm_initial_limit_data = { DFLDSIZ, MAXDSIZ };
342struct rlimit vm_initial_limit_core = { DFLCSIZ, MAXCSIZ };
343
b0d623f7 344extern thread_t cloneproc(task_t, proc_t, int);
91447636 345extern int (*mountroot)(void);
2d21ac55
A
346extern int netboot_mountroot(void); /* netboot.c */
347extern int netboot_setup(void);
1c79356b 348
91447636 349lck_grp_t * proc_lck_grp;
b0d623f7
A
350lck_grp_t * proc_slock_grp;
351lck_grp_t * proc_fdmlock_grp;
352lck_grp_t * proc_mlock_grp;
91447636
A
353lck_grp_attr_t * proc_lck_grp_attr;
354lck_attr_t * proc_lck_attr;
2d21ac55
A
355lck_mtx_t * proc_list_mlock;
356lck_mtx_t * proc_klist_mlock;
91447636 357
b0d623f7
A
358extern lck_mtx_t * execargs_cache_lock;
359
9bccf70c
A
360/* hook called after root is mounted XXX temporary hack */
361void (*mountroot_post_hook)(void);
b0d623f7 362void (*unmountroot_pre_hook)(void);
1c79356b 363
91447636
A
364/*
365 * This function is called very early on in the Mach startup, from the
366 * function start_kernel_threads() in osfmk/kern/startup.c. It's called
367 * in the context of the current (startup) task using a call to the
368 * function kernel_thread_create() to jump into start_kernel_threads().
369 * Internally, kernel_thread_create() calls thread_create_internal(),
370 * which calls uthread_alloc(). The function of uthread_alloc() is
371 * normally to allocate a uthread structure, and fill out the uu_sigmask,
2d21ac55
A
372 * uu_context fields. It skips filling these out in the case of the "task"
373 * being "kernel_task", because the order of operation is inverted. To
374 * account for that, we need to manually fill in at least the contents
375 * of the uu_context.vc_ucred field so that the uthread structure can be
376 * used like any other.
91447636 377 */
1c79356b 378void
2d21ac55 379bsd_init(void)
1c79356b 380{
91447636 381 struct uthread *ut;
2d21ac55 382 unsigned int i;
b0d623f7 383#if __i386__ || __x86_64__
0c530ab8 384 int error;
2d21ac55 385#endif
91447636 386 struct vfs_context context;
1c79356b 387 kern_return_t ret;
91447636 388 struct ucred temp_cred;
2d21ac55
A
389
390#define bsd_init_kprintf(x...) /* kprintf("bsd_init: " x) */
1c79356b
A
391
392 kernel_flock = funnel_alloc(KERNEL_FUNNEL);
393 if (kernel_flock == (funnel_t *)0 ) {
9bccf70c 394 panic("bsd_init: Failed to allocate kernel funnel");
1c79356b
A
395 }
396
1c79356b 397 printf(copyright);
91447636 398
2d21ac55 399 bsd_init_kprintf("calling kmeminit\n");
1c79356b
A
400 kmeminit();
401
2d21ac55 402 bsd_init_kprintf("calling parse_bsd_args\n");
1c79356b
A
403 parse_bsd_args();
404
91447636 405 /* Initialize kauth subsystem before instancing the first credential */
2d21ac55 406 bsd_init_kprintf("calling kauth_init\n");
91447636
A
407 kauth_init();
408
409 /* Initialize process and pgrp structures. */
2d21ac55 410 bsd_init_kprintf("calling procinit\n");
1c79356b
A
411 procinit();
412
b0d623f7
A
413 /* Initialize the ttys (MUST be before kminit()/bsd_autoconf()!)*/
414 tty_init();
1c79356b 415
b0d623f7 416 kernproc = &proc0; /* implicitly bzero'ed */
1c79356b
A
417
418 /* kernel_task->proc = kernproc; */
b0d623f7 419 set_bsdtask_info(kernel_task,(void *)kernproc);
1c79356b
A
420
421 /* give kernproc a name */
2d21ac55 422 bsd_init_kprintf("calling process_name\n");
b0d623f7 423 process_name("kernel_task", kernproc);
91447636 424
91447636 425 /* allocate proc lock group attribute and group */
2d21ac55 426 bsd_init_kprintf("calling lck_grp_attr_alloc_init\n");
91447636 427 proc_lck_grp_attr= lck_grp_attr_alloc_init();
91447636 428
b0d623f7
A
429 proc_lck_grp = lck_grp_alloc_init("proc", proc_lck_grp_attr);
430#ifndef CONFIG_EMBEDDED
431 proc_slock_grp = lck_grp_alloc_init("proc-slock", proc_lck_grp_attr);
432 proc_fdmlock_grp = lck_grp_alloc_init("proc-fdmlock", proc_lck_grp_attr);
433 proc_mlock_grp = lck_grp_alloc_init("proc-mlock", proc_lck_grp_attr);
434#endif
91447636
A
435 /* Allocate proc lock attribute */
436 proc_lck_attr = lck_attr_alloc_init();
2d21ac55
A
437#if 0
438#if __PROC_INTERNAL_DEBUG
439 lck_attr_setdebug(proc_lck_attr);
440#endif
441#endif
91447636 442
b0d623f7 443#ifdef CONFIG_EMBEDDED
2d21ac55
A
444 proc_list_mlock = lck_mtx_alloc_init(proc_lck_grp, proc_lck_attr);
445 proc_klist_mlock = lck_mtx_alloc_init(proc_lck_grp, proc_lck_attr);
b0d623f7
A
446 lck_mtx_init(&kernproc->p_mlock, proc_lck_grp, proc_lck_attr);
447 lck_mtx_init(&kernproc->p_fdmlock, proc_lck_grp, proc_lck_attr);
448 lck_spin_init(&kernproc->p_slock, proc_lck_grp, proc_lck_attr);
449#else
450 proc_list_mlock = lck_mtx_alloc_init(proc_mlock_grp, proc_lck_attr);
451 proc_klist_mlock = lck_mtx_alloc_init(proc_mlock_grp, proc_lck_attr);
452 lck_mtx_init(&kernproc->p_mlock, proc_mlock_grp, proc_lck_attr);
453 lck_mtx_init(&kernproc->p_fdmlock, proc_fdmlock_grp, proc_lck_attr);
454 lck_spin_init(&kernproc->p_slock, proc_slock_grp, proc_lck_attr);
455#endif
1c79356b 456
b0d623f7
A
457 execargs_cache_lock = lck_mtx_alloc_init(proc_lck_grp, proc_lck_attr);
458 execargs_cache_size = bsd_simul_execs;
459 execargs_free_count = bsd_simul_execs;
460 execargs_cache = (vm_offset_t *)kalloc(bsd_simul_execs * sizeof(vm_offset_t));
461 bzero(execargs_cache, bsd_simul_execs * sizeof(vm_offset_t));
462
1c79356b 463 if (current_task() != kernel_task)
9bccf70c
A
464 printf("bsd_init: We have a problem, "
465 "current task is not kernel task\n");
1c79356b 466
2d21ac55 467 bsd_init_kprintf("calling get_bsdthread_info\n");
91447636
A
468 ut = (uthread_t)get_bsdthread_info(current_thread());
469
2d21ac55
A
470#if CONFIG_MACF
471 /*
472 * Initialize the MAC Framework
473 */
474 mac_policy_initbsd();
b0d623f7 475 kernproc->p_mac_enforce = 0;
2d21ac55
A
476#endif /* MAC */
477
1c79356b
A
478 /*
479 * Create process 0.
480 */
2d21ac55 481 proc_list_lock();
b0d623f7
A
482 LIST_INSERT_HEAD(&allproc, kernproc, p_list);
483 kernproc->p_pgrp = &pgrp0;
1c79356b
A
484 LIST_INSERT_HEAD(PGRPHASH(0), &pgrp0, pg_hash);
485 LIST_INIT(&pgrp0.pg_members);
b0d623f7
A
486#ifdef CONFIG_EMBEDDED
487 lck_mtx_init(&pgrp0.pg_mlock, proc_lck_grp, proc_lck_attr);
488#else
489 lck_mtx_init(&pgrp0.pg_mlock, proc_mlock_grp, proc_lck_attr);
490#endif
2d21ac55 491 /* There is no other bsd thread this point and is safe without pgrp lock */
b0d623f7
A
492 LIST_INSERT_HEAD(&pgrp0.pg_members, kernproc, p_pglist);
493 kernproc->p_listflag |= P_LIST_INPGRP;
494 kernproc->p_pgrpid = 0;
1c79356b
A
495
496 pgrp0.pg_session = &session0;
2d21ac55
A
497 pgrp0.pg_membercnt = 1;
498
1c79356b 499 session0.s_count = 1;
b0d623f7 500 session0.s_leader = kernproc;
2d21ac55 501 session0.s_listflags = 0;
b0d623f7 502#ifdef CONFIG_EMBEDDED
2d21ac55 503 lck_mtx_init(&session0.s_mlock, proc_lck_grp, proc_lck_attr);
b0d623f7
A
504#else
505 lck_mtx_init(&session0.s_mlock, proc_mlock_grp, proc_lck_attr);
506#endif
2d21ac55
A
507 LIST_INSERT_HEAD(SESSHASH(0), &session0, s_hash);
508 proc_list_unlock();
509
510#if CONFIG_LCTX
b0d623f7 511 kernproc->p_lctx = NULL;
2d21ac55 512#endif
1c79356b 513
b0d623f7 514 kernproc->task = kernel_task;
1c79356b 515
b0d623f7
A
516 kernproc->p_stat = SRUN;
517 kernproc->p_flag = P_SYSTEM;
518 kernproc->p_nice = NZERO;
519 kernproc->p_pptr = kernproc;
2d21ac55 520
b0d623f7
A
521 TAILQ_INIT(&kernproc->p_uthlist);
522 TAILQ_INSERT_TAIL(&kernproc->p_uthlist, ut, uu_list);
2d21ac55 523
b0d623f7
A
524 kernproc->sigwait = FALSE;
525 kernproc->sigwait_thread = THREAD_NULL;
526 kernproc->exit_thread = THREAD_NULL;
527 kernproc->p_csflags = CS_VALID;
1c79356b 528
91447636
A
529 /*
530 * Create credential. This also Initializes the audit information.
91447636 531 */
2d21ac55 532 bsd_init_kprintf("calling bzero\n");
91447636
A
533 bzero(&temp_cred, sizeof(temp_cred));
534 temp_cred.cr_ngroups = 1;
535
b0d623f7
A
536 temp_cred.cr_audit.as_aia_p = &audit_default_aia;
537 /* XXX the following will go away with cr_au */
538 temp_cred.cr_au.ai_auid = AU_DEFAUDITID;
539
2d21ac55 540 bsd_init_kprintf("calling kauth_cred_create\n");
b0d623f7 541 kernproc->p_ucred = kauth_cred_create(&temp_cred);
91447636
A
542
543 /* give the (already exisiting) initial thread a reference on it */
2d21ac55 544 bsd_init_kprintf("calling kauth_cred_ref\n");
b0d623f7
A
545 kauth_cred_ref(kernproc->p_ucred);
546 ut->uu_context.vc_ucred = kernproc->p_ucred;
2d21ac55
A
547 ut->uu_context.vc_thread = current_thread();
548
b0d623f7
A
549 TAILQ_INIT(&kernproc->p_aio_activeq);
550 TAILQ_INIT(&kernproc->p_aio_doneq);
551 kernproc->p_aio_total_count = 0;
552 kernproc->p_aio_active_count = 0;
55e303ae 553
2d21ac55 554 bsd_init_kprintf("calling file_lock_init\n");
91447636 555 file_lock_init();
1c79356b 556
2d21ac55 557#if CONFIG_MACF
b0d623f7
A
558 mac_cred_label_associate_kernel(kernproc->p_ucred);
559 mac_task_label_update_cred (kernproc->p_ucred, (struct task *) kernproc->task);
2d21ac55
A
560#endif
561
1c79356b
A
562 /* Create the file descriptor table. */
563 filedesc0.fd_refcnt = 1+1; /* +1 so shutdown will not _FREE_ZONE */
b0d623f7 564 kernproc->p_fd = &filedesc0;
1c79356b 565 filedesc0.fd_cmask = cmask;
55e303ae
A
566 filedesc0.fd_knlistsize = -1;
567 filedesc0.fd_knlist = NULL;
568 filedesc0.fd_knhash = NULL;
569 filedesc0.fd_knhashmask = 0;
1c79356b
A
570
571 /* Create the limits structures. */
b0d623f7
A
572 kernproc->p_limit = &limit0;
573 for (i = 0; i < sizeof(kernproc->p_rlimit)/sizeof(kernproc->p_rlimit[0]); i++)
1c79356b
A
574 limit0.pl_rlimit[i].rlim_cur =
575 limit0.pl_rlimit[i].rlim_max = RLIM_INFINITY;
576 limit0.pl_rlimit[RLIMIT_NOFILE].rlim_cur = NOFILE;
0c530ab8 577 limit0.pl_rlimit[RLIMIT_NPROC].rlim_cur = maxprocperuid;
55e303ae 578 limit0.pl_rlimit[RLIMIT_NPROC].rlim_max = maxproc;
1c79356b
A
579 limit0.pl_rlimit[RLIMIT_STACK] = vm_initial_limit_stack;
580 limit0.pl_rlimit[RLIMIT_DATA] = vm_initial_limit_data;
581 limit0.pl_rlimit[RLIMIT_CORE] = vm_initial_limit_core;
2d21ac55 582 limit0.pl_refcnt = 1;
1c79356b 583
b0d623f7
A
584 kernproc->p_stats = &pstats0;
585 kernproc->p_sigacts = &sigacts0;
1c79356b
A
586
587 /*
91447636 588 * Charge root for two processes: init and mach_init.
1c79356b 589 */
2d21ac55 590 bsd_init_kprintf("calling chgproccnt\n");
1c79356b
A
591 (void)chgproccnt(0, 1);
592
1c79356b
A
593 /*
594 * Allocate a kernel submap for pageable memory
765c9de3 595 * for temporary copying (execve()).
1c79356b
A
596 */
597 {
2d21ac55 598 vm_offset_t minimum;
1c79356b 599
2d21ac55 600 bsd_init_kprintf("calling kmem_suballoc\n");
1c79356b 601 ret = kmem_suballoc(kernel_map,
2d21ac55 602 &minimum,
b0d623f7 603 (vm_size_t)bsd_pageable_map_size,
1c79356b 604 TRUE,
91447636 605 VM_FLAGS_ANYWHERE,
1c79356b 606 &bsd_pageable_map);
9bccf70c
A
607 if (ret != KERN_SUCCESS)
608 panic("bsd_init: Failed to allocate bsd pageable map");
765c9de3
A
609 }
610
91447636
A
611 /*
612 * Initialize buffers and hash links for buffers
613 *
614 * SIDE EFFECT: Starts a thread for bcleanbuf_thread(), so must
615 * happen after a credential has been associated with
616 * the kernel task.
617 */
2d21ac55 618 bsd_init_kprintf("calling bsd_bufferinit\n");
91447636
A
619 bsd_bufferinit();
620
765c9de3 621 /* Initialize the execve() semaphore */
2d21ac55 622 bsd_init_kprintf("calling semaphore_create\n");
b0d623f7 623
9bccf70c
A
624 if (ret != KERN_SUCCESS)
625 panic("bsd_init: Failed to create execve semaphore");
1c79356b
A
626
627 /*
0b4e3aa0
A
628 * Initialize the calendar.
629 */
4a3eedf9 630 bsd_init_kprintf("calling IOKitInitializeTime\n");
2d21ac55
A
631 IOKitInitializeTime();
632
633 if (turn_on_log_leaks && !new_nkdbufs)
634 new_nkdbufs = 200000;
635 start_kern_tracing(new_nkdbufs);
636 if (turn_on_log_leaks)
637 log_leaks = 1;
1c79356b 638
2d21ac55 639 bsd_init_kprintf("calling ubc_init\n");
1c79356b
A
640 ubc_init();
641
642 /* Initialize the file systems. */
2d21ac55 643 bsd_init_kprintf("calling vfsinit\n");
1c79356b
A
644 vfsinit();
645
2d21ac55
A
646#if SOCKETS
647 /* Initialize per-CPU cache allocator */
648 mcache_init();
649
1c79356b 650 /* Initialize mbuf's. */
2d21ac55 651 bsd_init_kprintf("calling mbinit\n");
1c79356b 652 mbinit();
b0d623f7 653 net_str_id_init(); /* for mbuf tags */
2d21ac55 654#endif /* SOCKETS */
1c79356b 655
55e303ae
A
656 /*
657 * Initializes security event auditing.
658 * XXX: Should/could this occur later?
659 */
b0d623f7 660#if CONFIG_AUDIT
2d21ac55
A
661 bsd_init_kprintf("calling audit_init\n");
662 audit_init();
663#endif
55e303ae
A
664
665 /* Initialize kqueues */
2d21ac55 666 bsd_init_kprintf("calling knote_init\n");
55e303ae
A
667 knote_init();
668
669 /* Initialize for async IO */
2d21ac55 670 bsd_init_kprintf("calling aio_init\n");
55e303ae
A
671 aio_init();
672
91447636 673 /* Initialize pipes */
2d21ac55 674 bsd_init_kprintf("calling pipeinit\n");
91447636
A
675 pipeinit();
676
677 /* Initialize SysV shm subsystem locks; the subsystem proper is
678 * initialized through a sysctl.
679 */
2d21ac55
A
680#if SYSV_SHM
681 bsd_init_kprintf("calling sysv_shm_lock_init\n");
91447636 682 sysv_shm_lock_init();
2d21ac55
A
683#endif
684#if SYSV_SEM
685 bsd_init_kprintf("calling sysv_sem_lock_init\n");
91447636 686 sysv_sem_lock_init();
2d21ac55
A
687#endif
688#if SYSV_MSG
689 bsd_init_kprintf("sysv_msg_lock_init\n");
91447636 690 sysv_msg_lock_init();
2d21ac55
A
691#endif
692 bsd_init_kprintf("calling pshm_lock_init\n");
91447636 693 pshm_lock_init();
2d21ac55 694 bsd_init_kprintf("calling psem_lock_init\n");
91447636
A
695 psem_lock_init();
696
2d21ac55 697 pthread_init();
9bccf70c 698 /* POSIX Shm and Sem */
2d21ac55 699 bsd_init_kprintf("calling pshm_cache_init\n");
9bccf70c 700 pshm_cache_init();
2d21ac55 701 bsd_init_kprintf("calling psem_cache_init\n");
9bccf70c 702 psem_cache_init();
2d21ac55 703 bsd_init_kprintf("calling time_zone_slock_init\n");
9bccf70c 704 time_zone_slock_init();
1c79356b 705
0c530ab8
A
706 /* Stack snapshot facility lock */
707 stackshot_lock_init();
1c79356b
A
708 /*
709 * Initialize protocols. Block reception of incoming packets
710 * until everything is ready.
711 */
2d21ac55 712 bsd_init_kprintf("calling sysctl_register_fixed\n");
1c79356b 713 sysctl_register_fixed();
2d21ac55 714 bsd_init_kprintf("calling sysctl_mib_init\n");
43866e37 715 sysctl_mib_init();
2d21ac55
A
716#if NETWORKING
717 bsd_init_kprintf("calling dlil_init\n");
1c79356b 718 dlil_init();
2d21ac55 719 bsd_init_kprintf("calling proto_kpi_init\n");
91447636 720 proto_kpi_init();
2d21ac55
A
721#endif /* NETWORKING */
722#if SOCKETS
723 bsd_init_kprintf("calling socketinit\n");
1c79356b 724 socketinit();
2d21ac55 725 bsd_init_kprintf("calling domaininit\n");
1c79356b 726 domaininit();
2d21ac55 727#endif /* SOCKETS */
1c79356b 728
b0d623f7
A
729 kernproc->p_fd->fd_cdir = NULL;
730 kernproc->p_fd->fd_rdir = NULL;
1c79356b 731
d1ecb069
A
732#if CONFIG_EMBEDDED
733 /* Initialize kernel memory status notifications */
734 bsd_init_kprintf("calling kern_memorystatus_init\n");
735 kern_memorystatus_init();
736#endif
737
1c79356b
A
738#ifdef GPROF
739 /* Initialize kernel profiling. */
740 kmstartup();
741#endif
742
743 /* kick off timeout driven events by calling first time */
744 thread_wakeup(&lbolt);
2d21ac55 745 timeout(lightning_bolt, 0, hz);
1c79356b 746
2d21ac55 747 bsd_init_kprintf("calling bsd_autoconf\n");
1c79356b
A
748 bsd_autoconf();
749
2d21ac55 750#if CONFIG_DTRACE
2d21ac55
A
751 dtrace_postinit();
752#endif
753
1c79356b
A
754 /*
755 * We attach the loopback interface *way* down here to ensure
756 * it happens after autoconf(), otherwise it becomes the
757 * "primary" interface.
758 */
759#include <loop.h>
760#if NLOOP > 0
2d21ac55 761 bsd_init_kprintf("calling loopattach\n");
1c79356b
A
762 loopattach(); /* XXX */
763#endif
b0d623f7
A
764
765#if PFLOG
766 /* Initialize packet filter log interface */
767 pfloginit();
768#endif /* PFLOG */
769
2d21ac55
A
770#if NETHER > 0
771 /* Register the built-in dlil ethernet interface family */
772 bsd_init_kprintf("calling ether_family_init\n");
9bccf70c 773 ether_family_init();
2d21ac55 774#endif /* ETHER */
1c79356b 775
2d21ac55 776#if NETWORKING
91447636 777 /* Call any kext code that wants to run just after network init */
2d21ac55 778 bsd_init_kprintf("calling net_init_run\n");
91447636 779 net_init_run();
b0d623f7
A
780
781 /* register user tunnel kernel control handler */
782 utun_register_control();
2d21ac55 783#endif /* NETWORKING */
91447636 784
2d21ac55 785 bsd_init_kprintf("calling vnode_pager_bootstrap\n");
1c79356b 786 vnode_pager_bootstrap();
91447636
A
787#if 0
788 /* XXX Hack for early debug stop */
789 printf("\nabout to sleep for 10 seconds\n");
790 IOSleep( 10 * 1000 );
791 /* Debugger("hello"); */
792#endif
793
2d21ac55 794 bsd_init_kprintf("calling inittodr\n");
91447636 795 inittodr(0);
1c79356b 796
2d21ac55
A
797#if CONFIG_EMBEDDED
798 {
799 /* print out early VM statistics */
800 kern_return_t kr1;
801 vm_statistics_data_t stat;
802 mach_msg_type_number_t count;
803
804 count = HOST_VM_INFO_COUNT;
805 kr1 = host_statistics(host_self(),
806 HOST_VM_INFO,
807 (host_info_t)&stat,
808 &count);
809 kprintf("Mach Virtual Memory Statistics (page size of 4096) bytes\n"
810 "Pages free:\t\t\t%u.\n"
811 "Pages active:\t\t\t%u.\n"
812 "Pages inactive:\t\t\t%u.\n"
813 "Pages wired down:\t\t%u.\n"
814 "\"Translation faults\":\t\t%u.\n"
815 "Pages copy-on-write:\t\t%u.\n"
816 "Pages zero filled:\t\t%u.\n"
817 "Pages reactivated:\t\t%u.\n"
818 "Pageins:\t\t\t%u.\n"
b0d623f7 819 "Pageouts:\t\t\t%u.\n"
2d21ac55
A
820 "Object cache: %u hits of %u lookups (%d%% hit rate)\n",
821
822 stat.free_count,
823 stat.active_count,
824 stat.inactive_count,
825 stat.wire_count,
826 stat.faults,
827 stat.cow_faults,
828 stat.zero_fill_count,
829 stat.reactivations,
830 stat.pageins,
831 stat.pageouts,
832 stat.hits,
833 stat.lookups,
834 (stat.hits == 0) ? 100 :
835 ((stat.lookups * 100) / stat.hits));
836 }
837#endif /* CONFIG_EMBEDDED */
838
1c79356b
A
839 /* Mount the root file system. */
840 while( TRUE) {
841 int err;
842
2d21ac55 843 bsd_init_kprintf("calling setconf\n");
1c79356b 844 setconf();
9bccf70c 845
2d21ac55 846 bsd_init_kprintf("vfs_mountroot\n");
1c79356b
A
847 if (0 == (err = vfs_mountroot()))
848 break;
2d21ac55 849 rootdevice[0] = '\0';
91447636 850#if NFSCLIENT
9bccf70c 851 if (mountroot == netboot_mountroot) {
b0d623f7
A
852 PE_display_icon( 0, "noroot"); /* XXX a netboot-specific icon would be nicer */
853 vc_progress_set(FALSE, 0);
854 for (i=1; 1; i*=2) {
855 printf("bsd_init: failed to mount network root, error %d, %s\n",
856 err, PE_boot_args());
857 printf("We are hanging here...\n");
858 IOSleep(i*60*1000);
859 }
860 /*NOTREACHED*/
9bccf70c 861 }
91447636 862#endif
1c79356b
A
863 printf("cannot mount root, errno = %d\n", err);
864 boothowto |= RB_ASKNAME;
865 }
866
2d21ac55
A
867 IOSecureBSDRoot(rootdevice);
868
869 context.vc_thread = current_thread();
b0d623f7 870 context.vc_ucred = kernproc->p_ucred;
91447636 871 mountlist.tqh_first->mnt_flag |= MNT_ROOTFS;
1c79356b 872
2d21ac55 873 bsd_init_kprintf("calling VFS_ROOT\n");
1c79356b 874 /* Get the vnode for '/'. Set fdp->fd_fd.fd_cdir to reference it. */
91447636 875 if (VFS_ROOT(mountlist.tqh_first, &rootvnode, &context))
2d21ac55 876 panic("bsd_init: cannot find root vnode: %s", PE_boot_args());
91447636
A
877 rootvnode->v_flag |= VROOT;
878 (void)vnode_ref(rootvnode);
879 (void)vnode_put(rootvnode);
fa4905b1 880 filedesc0.fd_cdir = rootvnode;
9bccf70c 881
91447636 882#if NFSCLIENT
9bccf70c
A
883 if (mountroot == netboot_mountroot) {
884 int err;
885 /* post mount setup */
2d21ac55 886 if ((err = netboot_setup()) != 0) {
b0d623f7
A
887 PE_display_icon( 0, "noroot"); /* XXX a netboot-specific icon would be nicer */
888 vc_progress_set(FALSE, 0);
889 for (i=1; 1; i*=2) {
890 printf("bsd_init: NetBoot could not find root, error %d: %s\n",
891 err, PE_boot_args());
892 printf("We are hanging here...\n");
893 IOSleep(i*60*1000);
894 }
895 /*NOTREACHED*/
9bccf70c
A
896 }
897 }
91447636 898#endif
1c79356b
A
899
900
2d21ac55
A
901#if CONFIG_IMAGEBOOT
902 /*
903 * See if a system disk image is present. If so, mount it and
904 * switch the root vnode to point to it
905 */
906
907 if(imageboot_needed()) {
908 int err;
909
910 /* An image was found */
911 if((err = imageboot_setup())) {
912 /*
913 * this is not fatal. Keep trying to root
914 * off the original media
915 */
916 printf("%s: imageboot could not find root, %d\n",
917 __FUNCTION__, err);
918 }
919 }
920#endif /* CONFIG_IMAGEBOOT */
921
b0d623f7
A
922 /* set initial time; all other resource data is already zero'ed */
923 microtime(&kernproc->p_start);
924 kernproc->p_stats->p_start = kernproc->p_start; /* for compat */
1c79356b 925
9bccf70c 926#if DEVFS
1c79356b 927 {
2d21ac55
A
928 char mounthere[] = "/dev"; /* !const because of internal casting */
929
930 bsd_init_kprintf("calling devfs_kernel_mount\n");
931 devfs_kernel_mount(mounthere);
1c79356b 932 }
55e303ae 933#endif /* DEVFS */
1c79356b
A
934
935 /* Initialize signal state for process 0. */
2d21ac55 936 bsd_init_kprintf("calling siginit\n");
b0d623f7 937 siginit(kernproc);
1c79356b 938
2d21ac55 939 bsd_init_kprintf("calling bsd_utaskbootstrap\n");
1c79356b
A
940 bsd_utaskbootstrap();
941
b0d623f7
A
942#if defined(__LP64__)
943 kernproc->p_flag |= P_LP64;
944 printf("Kernel is LP64\n");
945#endif
946#if __i386__ || __x86_64__
2d21ac55 947 /* this should be done after the root filesystem is mounted */
b0d623f7
A
948 error = set_archhandler(kernproc, CPU_TYPE_POWERPC);
949 // 10/30/08 - gab: <rdar://problem/6324501>
950 // if default 'translate' can't be found, see if the understudy is available
951 if (ENOENT == error) {
952 strlcpy(exec_archhandler_ppc.path, kRosettaStandIn_str, MAXPATHLEN);
953 error = set_archhandler(kernproc, CPU_TYPE_POWERPC);
954 }
2d21ac55 955 if (error) /* XXX make more generic */
0c530ab8
A
956 exec_archhandler_ppc.path[0] = 0;
957#endif
2d21ac55
A
958
959 bsd_init_kprintf("calling mountroot_post_hook\n");
960
9bccf70c
A
961 /* invoke post-root-mount hook */
962 if (mountroot_post_hook != NULL)
963 mountroot_post_hook();
2d21ac55
A
964
965#if 0 /* not yet */
b0d623f7 966 consider_zone_gc(FALSE);
2d21ac55 967#endif
b0d623f7 968
2d21ac55 969 bsd_init_kprintf("done\n");
1c79356b
A
970}
971
9bccf70c 972/* Called with kernel funnel held */
1c79356b 973void
9bccf70c 974bsdinit_task(void)
1c79356b 975{
2d21ac55 976 proc_t p = current_proc();
1c79356b 977 struct uthread *ut;
2d21ac55 978 thread_t thread;
1c79356b 979
91447636 980 process_name("init", p);
1c79356b
A
981
982 ux_handler_init();
1c79356b 983
2d21ac55 984 thread = current_thread();
1c79356b 985 (void) host_set_exception_ports(host_priv_self(),
b0d623f7
A
986 EXC_MASK_ALL & ~(EXC_MASK_RPC_ALERT),//pilotfish (shark) needs this port
987 (mach_port_t) ux_exception_port,
2d21ac55
A
988 EXCEPTION_DEFAULT| MACH_EXCEPTION_CODES,
989 0);
1c79356b 990
2d21ac55 991 ut = (uthread_t)get_bsdthread_info(thread);
1c79356b 992
2d21ac55 993 bsd_init_task = get_threadtask(thread);
1c79356b 994 init_task_failure_data[0] = 0;
2d21ac55
A
995
996#if CONFIG_MACF
997 mac_cred_label_associate_user(p->p_ucred);
998 mac_task_label_update_cred (p->p_ucred, (struct task *) p->task);
999#endif
1c79356b 1000 load_init_program(p);
91447636 1001 lock_trace = 1;
1c79356b
A
1002}
1003
1004void
2d21ac55 1005lightning_bolt(__unused void *dummy)
1c79356b
A
1006{
1007 boolean_t funnel_state;
1c79356b
A
1008
1009 funnel_state = thread_funnel_set(kernel_flock, TRUE);
1010
1011 thread_wakeup(&lbolt);
1012 timeout(lightning_bolt,0,hz);
1013 klogwakeup();
1014
1015 (void) thread_funnel_set(kernel_flock, FALSE);
1016}
1017
2d21ac55
A
1018kern_return_t
1019bsd_autoconf(void)
9bccf70c 1020{
2d21ac55 1021 kprintf("bsd_autoconf: calling kminit\n");
1c79356b
A
1022 kminit();
1023
1024 /*
1025 * Early startup for bsd pseudodevices.
1026 */
1027 {
1028 struct pseudo_init *pi;
1029
1030 for (pi = pseudo_inits; pi->ps_func; pi++)
1031 (*pi->ps_func) (pi->ps_count);
1032 }
1033
9bccf70c 1034 return( IOKitBSDInit());
1c79356b
A
1035}
1036
1037
55e303ae 1038#include <sys/disklabel.h> /* for MAXPARTITIONS */
1c79356b 1039
91447636
A
1040static void
1041setconf(void)
1c79356b 1042{
1c79356b
A
1043 u_int32_t flags;
1044 kern_return_t err;
1045
1046 /*
1047 * calls into IOKit can generate networking registrations
1048 * which needs to be under network funnel. Right thing to do
1049 * here is to drop the funnel alltogether and regrab it afterwards
1050 */
cf7d32b8 1051 err = IOFindBSDRoot(rootdevice, sizeof(rootdevice), &rootdev, &flags);
1c79356b
A
1052 if( err) {
1053 printf("setconf: IOFindBSDRoot returned an error (%d);"
1054 "setting rootdevice to 'sd0a'.\n", err); /* XXX DEBUG TEMP */
1055 rootdev = makedev( 6, 0 );
2d21ac55 1056 strlcpy(rootdevice, "sd0a", sizeof(rootdevice));
1c79356b
A
1057 flags = 0;
1058 }
1059
91447636 1060#if NFSCLIENT
1c79356b 1061 if( flags & 1 ) {
9bccf70c
A
1062 /* network device */
1063 mountroot = netboot_mountroot;
1c79356b 1064 } else {
91447636 1065#endif
1c79356b
A
1066 /* otherwise have vfs determine root filesystem */
1067 mountroot = NULL;
91447636 1068#if NFSCLIENT
1c79356b 1069 }
91447636 1070#endif
1c79356b
A
1071
1072}
1073
2d21ac55
A
1074void
1075bsd_utaskbootstrap(void)
1c79356b 1076{
2d21ac55 1077 thread_t thread;
9bccf70c 1078 struct uthread *ut;
1c79356b 1079
b0d623f7
A
1080 /*
1081 * Clone the bootstrap process from the kernel process, without
1082 * inheriting either task characteristics or memory from the kernel;
1083 */
1084 thread = cloneproc(TASK_NULL, kernproc, FALSE);
1085
2d21ac55
A
1086 /* Hold the reference as it will be dropped during shutdown */
1087 initproc = proc_find(1);
1088#if __PROC_INTERNAL_DEBUG
1089 if (initproc == PROC_NULL)
1090 panic("bsd_utaskbootstrap: initproc not set\n");
1091#endif
b0d623f7
A
1092 /*
1093 * Since we aren't going back out the normal way to our parent,
1094 * we have to drop the transition locks explicitly.
1095 */
1096 proc_signalend(initproc, 0);
1097 proc_transend(initproc, 0);
9bccf70c 1098
2d21ac55 1099 ut = (struct uthread *)get_bsdthread_info(thread);
9bccf70c 1100 ut->uu_sigmask = 0;
2d21ac55
A
1101 act_set_astbsd(thread);
1102 (void) thread_resume(thread);
1c79356b
A
1103}
1104
2d21ac55
A
1105static void
1106parse_bsd_args(void)
1c79356b 1107{
2d21ac55
A
1108 char namep[16];
1109 int msgbuf;
1c79356b 1110
593a1d5f 1111 if (PE_parse_boot_argn("-s", namep, sizeof (namep)))
1c79356b 1112 boothowto |= RB_SINGLE;
55e303ae 1113
593a1d5f 1114 if (PE_parse_boot_argn("-b", namep, sizeof (namep)))
1c79356b 1115 boothowto |= RB_NOBOOTRC;
1c79356b 1116
593a1d5f 1117 if (PE_parse_boot_argn("-x", namep, sizeof (namep))) /* safe boot */
2d21ac55 1118 boothowto |= RB_SAFEBOOT;
1c79356b 1119
593a1d5f 1120 if (PE_parse_boot_argn("-l", namep, sizeof (namep))) /* leaks logging */
2d21ac55 1121 turn_on_log_leaks = 1;
55e303ae 1122
b0d623f7
A
1123 /* disable 64 bit grading */
1124 if (PE_parse_boot_argn("-no64exec", namep, sizeof (namep)))
1125 bootarg_no64exec = 1;
1126
593a1d5f 1127 PE_parse_boot_argn("ncl", &ncl, sizeof (ncl));
b0d623f7
A
1128 if (PE_parse_boot_argn("nbuf", &max_nbuf_headers,
1129 sizeof (max_nbuf_headers))) {
0c530ab8 1130 customnbuf = 1;
2d21ac55 1131 }
4a3eedf9 1132#if !defined(SECURE_KERNEL)
593a1d5f 1133 PE_parse_boot_argn("kmem", &setup_kmem, sizeof (setup_kmem));
4a3eedf9 1134#endif
593a1d5f 1135 PE_parse_boot_argn("trace", &new_nkdbufs, sizeof (new_nkdbufs));
1c79356b 1136
593a1d5f 1137 if (PE_parse_boot_argn("msgbuf", &msgbuf, sizeof (msgbuf))) {
2d21ac55
A
1138 log_setsize(msgbuf);
1139 }
1c79356b
A
1140}
1141
b0d623f7
A
1142void
1143bsd_exec_setup(int scale)
1144{
1145
1146 switch (scale) {
1147 case 0:
1148 case 1:
1149 bsd_simul_execs = BSD_SIMUL_EXECS;
1150 break;
1151 case 2:
1152 case 3:
1153 bsd_simul_execs = 65;
1154 break;
1155 case 4:
1156 case 5:
1157 bsd_simul_execs = 129;
1158 break;
1159 case 6:
1160 case 7:
1161 bsd_simul_execs = 257;
1162 break;
1163 default:
1164 bsd_simul_execs = 513;
1165 break;
1166
1167 }
1168 bsd_pageable_map_size = (bsd_simul_execs * (NCARGS + PAGE_SIZE));
1169}
1170
91447636
A
1171#if !NFSCLIENT
1172int
1173netboot_root(void)
1c79356b 1174{
91447636 1175 return(0);
1c79356b 1176}
91447636 1177#endif