]> git.saurik.com Git - apple/xnu.git/blame - bsd/kern/bsd_init.c
xnu-2782.10.72.tar.gz
[apple/xnu.git] / bsd / kern / bsd_init.c
CommitLineData
1c79356b 1/*
39236c6e 2 * Copyright (c) 2000-2013 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>
6d2010ae 109#include <mach/mach_host.h>
1c79356b
A
110
111#include <mach/vm_param.h>
112
113#include <vm/vm_map.h>
114#include <vm/vm_kern.h>
115
55e303ae 116#include <sys/ux_exception.h> /* for ux_exception_port */
1c79356b
A
117
118#include <sys/reboot.h>
119#include <mach/exception_types.h>
55e303ae 120#include <dev/busvar.h> /* for pseudo_inits */
1c79356b
A
121#include <sys/kdebug.h>
122
765c9de3
A
123#include <mach/mach_types.h>
124#include <mach/vm_prot.h>
125#include <mach/semaphore.h>
126#include <mach/sync_policy.h>
127#include <kern/clock.h>
128#include <mach/kern_return.h>
2d21ac55
A
129#include <mach/thread_act.h> /* for thread_resume() */
130#include <mach/task.h> /* for task_set_exception_ports() */
131#include <sys/ux_exception.h> /* for ux_handler() */
132#include <sys/ubc_internal.h> /* for ubc_init() */
133#include <sys/mcache.h> /* for mcache_init() */
134#include <sys/mbuf.h> /* for mbinit() */
135#include <sys/event.h> /* for knote_init() */
316670eb 136#include <sys/kern_memorystatus.h> /* for memorystatus_init() */
2d21ac55
A
137#include <sys/aio_kern.h> /* for aio_init() */
138#include <sys/semaphore.h> /* for psem_cache_init() */
139#include <net/dlil.h> /* for dlil_init() */
140#include <net/kpi_protocol.h> /* for proto_kpi_init() */
316670eb 141#include <net/iptap.h> /* for iptap_init() */
2d21ac55
A
142#include <sys/pipe.h> /* for pipeinit() */
143#include <sys/socketvar.h> /* for socketinit() */
144#include <sys/protosw.h> /* for domaininit() */
145#include <kern/sched_prim.h> /* for thread_wakeup() */
146#include <net/if_ether.h> /* for ether_family_init() */
39236c6e 147#include <net/if_gif.h> /* for gif_init() */
2d21ac55
A
148#include <vm/vm_protos.h> /* for vnode_pager_bootstrap() */
149#include <miscfs/devfs/devfsdefs.h> /* for devfs_kernel_mount() */
150#include <mach/host_priv.h> /* for host_set_exception_ports() */
151#include <kern/host.h> /* for host_priv_self() */
152#include <vm/vm_kern.h> /* for kmem_suballoc() */
153#include <sys/semaphore.h> /* for psem_lock_init() */
154#include <sys/msgbuf.h> /* for log_setsize() */
b0d623f7 155#include <sys/tty.h> /* for tty_init() */
39236c6e
A
156#include <sys/proc_uuid_policy.h> /* proc_uuid_policy_init() */
157#include <netinet/flow_divert.h> /* flow_divert_init() */
fe8ab488
A
158#include <net/content_filter.h> /* for cfil_init() */
159#include <net/necp.h> /* for necp_init() */
160#include <net/packet_mangler.h> /* for pkt_mnglr_init() */
b0d623f7 161#include <net/if_utun.h> /* for utun_register_control() */
39236c6e 162#include <net/if_ipsec.h> /* for ipsec_register_control() */
b0d623f7 163#include <net/net_str_id.h> /* for net_str_id_init() */
6d2010ae 164#include <net/netsrc.h> /* for netsrc_init() */
316670eb 165#include <net/ntstat.h> /* for nstat_init() */
fe8ab488 166#include <netinet/tcp_cc.h> /* for tcp_cc_init() */
6d2010ae 167#include <kern/assert.h> /* for assert() */
39236c6e 168#include <sys/kern_overrides.h> /* for init_system_override() */
9bccf70c 169
91447636
A
170#include <net/init.h>
171
2d21ac55
A
172#if CONFIG_MACF
173#include <security/mac_framework.h>
174#include <security/mac_internal.h> /* mac_init_bsd() */
175#include <security/mac_mach_internal.h> /* mac_update_task_label() */
176#endif
177
0c530ab8
A
178#include <machine/exec.h>
179
6d2010ae
A
180#if NFSCLIENT
181#include <sys/netboot.h>
182#endif
183
2d21ac55
A
184#if CONFIG_IMAGEBOOT
185#include <sys/imageboot.h>
186#endif
187
b0d623f7
A
188#if PFLOG
189#include <net/if_pflog.h>
190#endif
191
2d21ac55 192#include <pexpert/pexpert.h>
6d2010ae 193#include <machine/pal_routines.h>
13f56ec4 194#include <console/video_console.h>
2d21ac55
A
195
196void * get_user_regs(thread_t); /* XXX kludge for <machine/thread.h> */
197void IOKitInitializeTime(void); /* XXX */
b0d623f7 198void IOSleep(unsigned int); /* XXX */
2d21ac55 199void loopattach(void); /* XXX */
1c79356b 200
b0d623f7 201const char copyright[] =
55e303ae
A
202"Copyright (c) 1982, 1986, 1989, 1991, 1993\n\t"
203"The Regents of the University of California. "
204"All rights reserved.\n\n";
1c79356b 205
1c79356b
A
206/* Components of the first process -- never freed. */
207struct proc proc0;
208struct session session0;
209struct pgrp pgrp0;
1c79356b
A
210struct filedesc filedesc0;
211struct plimit limit0;
212struct pstats pstats0;
213struct sigacts sigacts0;
2d21ac55
A
214proc_t kernproc;
215proc_t initproc;
1c79356b 216
1c79356b
A
217long tk_cancc;
218long tk_nin;
219long tk_nout;
220long tk_rawcc;
221
91447636 222int lock_trace = 0;
1c79356b
A
223/* Global variables to make pstat happy. We do swapping differently */
224int nswdev, nswap;
225int nswapmap;
226void *swapmap;
227struct swdevt swdevt[1];
228
229dev_t rootdev; /* device of the root */
230dev_t dumpdev; /* device to take dumps on */
231long dumplo; /* offset into dumpdev */
232long hostid;
233char hostname[MAXHOSTNAMELEN];
55e303ae 234int hostnamelen;
1c79356b 235char domainname[MAXDOMNAMELEN];
55e303ae 236int domainnamelen;
1c79356b
A
237
238char rootdevice[16]; /* hfs device names have at least 9 chars */
1c79356b 239
2d21ac55 240#if KMEMSTATS
1c79356b
A
241struct kmemstats kmemstats[M_LAST];
242#endif
243
1c79356b
A
244struct vnode *rootvp;
245int boothowto = RB_DEBUG;
246
cf7d32b8 247extern kern_return_t IOFindBSDRoot(char *, unsigned int, dev_t *, u_int32_t *);
2d21ac55
A
248extern void IOSecureBSDRoot(const char * rootName);
249extern kern_return_t IOKitBSDInit(void );
250extern void kminit(void);
2d21ac55
A
251extern void file_lock_init(void);
252extern void kmeminit(void);
253extern void bsd_bufferinit(void);
316670eb 254extern void throttle_init(void);
fe8ab488
A
255extern void macx_init(void);
256extern void acct_init(void);
2d21ac55 257
6d2010ae 258extern int serverperfmode;
2d21ac55
A
259extern int ncl;
260
1c79356b
A
261vm_map_t bsd_pageable_map;
262vm_map_t mb_map;
b0d623f7 263
6d2010ae
A
264static int bsd_simul_execs;
265static int bsd_pageable_map_size;
266__private_extern__ int execargs_cache_size = 0;
267__private_extern__ int execargs_free_count = 0;
b0d623f7
A
268__private_extern__ vm_offset_t * execargs_cache = NULL;
269
39236c6e 270void bsd_exec_setup(int);
b0d623f7 271
6d2010ae
A
272__private_extern__ int bootarg_vnode_cache_defeat = 0;
273
274/*
275 * Prevent kernel-based ASLR from being used, for testing.
276 */
277#if DEVELOPMENT || DEBUG
278__private_extern__ int bootarg_disable_aslr = 0;
279#endif
1c79356b
A
280
281int cmask = CMASK;
0c530ab8 282extern int customnbuf;
1c79356b 283
39236c6e
A
284void bsd_init(void);
285kern_return_t bsd_autoconf(void);
286void bsd_utaskbootstrap(void);
2d21ac55
A
287
288static void parse_bsd_args(void);
9bccf70c 289extern task_t bsd_init_task;
1c79356b 290extern char init_task_failure_data[];
fe8ab488
A
291#if CONFIG_DEV_KMEM
292extern void dev_kmem_init(void);
293#endif
9bccf70c 294extern void time_zone_slock_init(void);
6d2010ae 295extern void select_wait_queue_init(void);
2d21ac55 296static void process_name(const char *, proc_t);
91447636
A
297
298static void setconf(void);
1c79356b 299
2d21ac55 300#if SYSV_SHM
91447636 301extern void sysv_shm_lock_init(void);
2d21ac55
A
302#endif
303#if SYSV_SEM
91447636 304extern void sysv_sem_lock_init(void);
2d21ac55
A
305#endif
306#if SYSV_MSG
91447636 307extern void sysv_msg_lock_init(void);
2d21ac55 308#endif
0c530ab8 309
6d2010ae
A
310#if CONFIG_MACF
311#if defined (__i386__) || defined (__x86_64__)
312/* MACF policy_check configuration flags; see policy_check.c for details */
313int policy_check_flags = 0;
2d21ac55 314
6d2010ae
A
315extern int check_policy_init(int);
316#endif
317#endif /* CONFIG_MACF */
2d21ac55 318
b0d623f7
A
319/* If we are using CONFIG_DTRACE */
320#if CONFIG_DTRACE
321 extern void dtrace_postinit(void);
322#endif
323
1c79356b
A
324/*
325 * Initialization code.
326 * Called from cold start routine as
327 * soon as a stack and segmentation
328 * have been established.
329 * Functions:
1c79356b
A
330 * turn on clock
331 * hand craft 0th process
332 * call all initialization routines
55e303ae 333 * hand craft 1st user process
1c79356b
A
334 */
335
336/*
337 * Sets the name for the given task.
338 */
91447636 339static void
2d21ac55 340process_name(const char *s, proc_t p)
1c79356b 341{
2d21ac55 342 size_t length = strlen(s);
1c79356b
A
343
344 bcopy(s, p->p_comm,
345 length >= sizeof(p->p_comm) ? sizeof(p->p_comm) :
346 length + 1);
347}
348
1c79356b
A
349/* To allow these values to be patched, they're globals here */
350#include <machine/vmparam.h>
fe8ab488 351struct rlimit vm_initial_limit_stack = { DFLSSIZ, MAXSSIZ - PAGE_MAX_SIZE };
1c79356b
A
352struct rlimit vm_initial_limit_data = { DFLDSIZ, MAXDSIZ };
353struct rlimit vm_initial_limit_core = { DFLCSIZ, MAXCSIZ };
354
fe8ab488 355extern thread_t cloneproc(task_t, coalition_t, proc_t, int, int);
91447636 356extern int (*mountroot)(void);
1c79356b 357
91447636 358lck_grp_t * proc_lck_grp;
b0d623f7
A
359lck_grp_t * proc_slock_grp;
360lck_grp_t * proc_fdmlock_grp;
361lck_grp_t * proc_mlock_grp;
91447636
A
362lck_grp_attr_t * proc_lck_grp_attr;
363lck_attr_t * proc_lck_attr;
2d21ac55
A
364lck_mtx_t * proc_list_mlock;
365lck_mtx_t * proc_klist_mlock;
91447636 366
b0d623f7
A
367extern lck_mtx_t * execargs_cache_lock;
368
9bccf70c
A
369/* hook called after root is mounted XXX temporary hack */
370void (*mountroot_post_hook)(void);
b0d623f7 371void (*unmountroot_pre_hook)(void);
1c79356b 372
91447636
A
373/*
374 * This function is called very early on in the Mach startup, from the
375 * function start_kernel_threads() in osfmk/kern/startup.c. It's called
376 * in the context of the current (startup) task using a call to the
377 * function kernel_thread_create() to jump into start_kernel_threads().
378 * Internally, kernel_thread_create() calls thread_create_internal(),
379 * which calls uthread_alloc(). The function of uthread_alloc() is
380 * normally to allocate a uthread structure, and fill out the uu_sigmask,
2d21ac55
A
381 * uu_context fields. It skips filling these out in the case of the "task"
382 * being "kernel_task", because the order of operation is inverted. To
383 * account for that, we need to manually fill in at least the contents
384 * of the uu_context.vc_ucred field so that the uthread structure can be
385 * used like any other.
91447636 386 */
316670eb 387
1c79356b 388void
2d21ac55 389bsd_init(void)
1c79356b 390{
91447636 391 struct uthread *ut;
2d21ac55 392 unsigned int i;
91447636 393 struct vfs_context context;
1c79356b 394 kern_return_t ret;
91447636 395 struct ucred temp_cred;
6d2010ae
A
396 struct posix_cred temp_pcred;
397#if NFSCLIENT || CONFIG_IMAGEBOOT
398 boolean_t netboot = FALSE;
399#endif
2d21ac55
A
400
401#define bsd_init_kprintf(x...) /* kprintf("bsd_init: " x) */
1c79356b 402
316670eb
A
403 throttle_init();
404
1c79356b 405 printf(copyright);
91447636 406
2d21ac55 407 bsd_init_kprintf("calling kmeminit\n");
1c79356b
A
408 kmeminit();
409
2d21ac55 410 bsd_init_kprintf("calling parse_bsd_args\n");
1c79356b
A
411 parse_bsd_args();
412
fe8ab488
A
413#if CONFIG_DEV_KMEM
414 bsd_init_kprintf("calling dev_kmem_init\n");
415 dev_kmem_init();
416#endif
417
91447636 418 /* Initialize kauth subsystem before instancing the first credential */
2d21ac55 419 bsd_init_kprintf("calling kauth_init\n");
91447636
A
420 kauth_init();
421
422 /* Initialize process and pgrp structures. */
2d21ac55 423 bsd_init_kprintf("calling procinit\n");
1c79356b
A
424 procinit();
425
b0d623f7
A
426 /* Initialize the ttys (MUST be before kminit()/bsd_autoconf()!)*/
427 tty_init();
1c79356b 428
b0d623f7 429 kernproc = &proc0; /* implicitly bzero'ed */
1c79356b
A
430
431 /* kernel_task->proc = kernproc; */
b0d623f7 432 set_bsdtask_info(kernel_task,(void *)kernproc);
1c79356b
A
433
434 /* give kernproc a name */
2d21ac55 435 bsd_init_kprintf("calling process_name\n");
b0d623f7 436 process_name("kernel_task", kernproc);
91447636 437
91447636 438 /* allocate proc lock group attribute and group */
2d21ac55 439 bsd_init_kprintf("calling lck_grp_attr_alloc_init\n");
91447636 440 proc_lck_grp_attr= lck_grp_attr_alloc_init();
91447636 441
b0d623f7 442 proc_lck_grp = lck_grp_alloc_init("proc", proc_lck_grp_attr);
6d2010ae 443#if CONFIG_FINE_LOCK_GROUPS
b0d623f7
A
444 proc_slock_grp = lck_grp_alloc_init("proc-slock", proc_lck_grp_attr);
445 proc_fdmlock_grp = lck_grp_alloc_init("proc-fdmlock", proc_lck_grp_attr);
446 proc_mlock_grp = lck_grp_alloc_init("proc-mlock", proc_lck_grp_attr);
447#endif
91447636
A
448 /* Allocate proc lock attribute */
449 proc_lck_attr = lck_attr_alloc_init();
2d21ac55
A
450#if 0
451#if __PROC_INTERNAL_DEBUG
452 lck_attr_setdebug(proc_lck_attr);
453#endif
454#endif
91447636 455
6d2010ae 456#if CONFIG_FINE_LOCK_GROUPS
b0d623f7
A
457 proc_list_mlock = lck_mtx_alloc_init(proc_mlock_grp, proc_lck_attr);
458 proc_klist_mlock = lck_mtx_alloc_init(proc_mlock_grp, proc_lck_attr);
459 lck_mtx_init(&kernproc->p_mlock, proc_mlock_grp, proc_lck_attr);
460 lck_mtx_init(&kernproc->p_fdmlock, proc_fdmlock_grp, proc_lck_attr);
461 lck_spin_init(&kernproc->p_slock, proc_slock_grp, proc_lck_attr);
6d2010ae
A
462#else
463 proc_list_mlock = lck_mtx_alloc_init(proc_lck_grp, proc_lck_attr);
464 proc_klist_mlock = lck_mtx_alloc_init(proc_lck_grp, proc_lck_attr);
465 lck_mtx_init(&kernproc->p_mlock, proc_lck_grp, proc_lck_attr);
466 lck_mtx_init(&kernproc->p_fdmlock, proc_lck_grp, proc_lck_attr);
467 lck_spin_init(&kernproc->p_slock, proc_lck_grp, proc_lck_attr);
b0d623f7 468#endif
1c79356b 469
6d2010ae 470 assert(bsd_simul_execs != 0);
b0d623f7
A
471 execargs_cache_lock = lck_mtx_alloc_init(proc_lck_grp, proc_lck_attr);
472 execargs_cache_size = bsd_simul_execs;
473 execargs_free_count = bsd_simul_execs;
474 execargs_cache = (vm_offset_t *)kalloc(bsd_simul_execs * sizeof(vm_offset_t));
475 bzero(execargs_cache, bsd_simul_execs * sizeof(vm_offset_t));
476
1c79356b 477 if (current_task() != kernel_task)
9bccf70c
A
478 printf("bsd_init: We have a problem, "
479 "current task is not kernel task\n");
1c79356b 480
2d21ac55 481 bsd_init_kprintf("calling get_bsdthread_info\n");
91447636
A
482 ut = (uthread_t)get_bsdthread_info(current_thread());
483
2d21ac55
A
484#if CONFIG_MACF
485 /*
486 * Initialize the MAC Framework
487 */
488 mac_policy_initbsd();
b0d623f7 489 kernproc->p_mac_enforce = 0;
6d2010ae
A
490
491#if defined (__i386__) || defined (__x86_64__)
492 /*
493 * We currently only support this on i386/x86_64, as that is the
494 * only lock code we have instrumented so far.
495 */
496 check_policy_init(policy_check_flags);
497#endif
2d21ac55
A
498#endif /* MAC */
499
39236c6e
A
500 /* Initialize System Override call */
501 init_system_override();
502
1c79356b
A
503 /*
504 * Create process 0.
505 */
2d21ac55 506 proc_list_lock();
b0d623f7
A
507 LIST_INSERT_HEAD(&allproc, kernproc, p_list);
508 kernproc->p_pgrp = &pgrp0;
1c79356b
A
509 LIST_INSERT_HEAD(PGRPHASH(0), &pgrp0, pg_hash);
510 LIST_INIT(&pgrp0.pg_members);
6d2010ae 511#ifdef CONFIG_FINE_LOCK_GROUPS
b0d623f7 512 lck_mtx_init(&pgrp0.pg_mlock, proc_mlock_grp, proc_lck_attr);
6d2010ae
A
513#else
514 lck_mtx_init(&pgrp0.pg_mlock, proc_lck_grp, proc_lck_attr);
b0d623f7 515#endif
2d21ac55 516 /* There is no other bsd thread this point and is safe without pgrp lock */
b0d623f7
A
517 LIST_INSERT_HEAD(&pgrp0.pg_members, kernproc, p_pglist);
518 kernproc->p_listflag |= P_LIST_INPGRP;
519 kernproc->p_pgrpid = 0;
6d2010ae 520 kernproc->p_uniqueid = 0;
1c79356b
A
521
522 pgrp0.pg_session = &session0;
2d21ac55
A
523 pgrp0.pg_membercnt = 1;
524
1c79356b 525 session0.s_count = 1;
b0d623f7 526 session0.s_leader = kernproc;
2d21ac55 527 session0.s_listflags = 0;
6d2010ae 528#ifdef CONFIG_FINE_LOCK_GROUPS
b0d623f7 529 lck_mtx_init(&session0.s_mlock, proc_mlock_grp, proc_lck_attr);
6d2010ae
A
530#else
531 lck_mtx_init(&session0.s_mlock, proc_lck_grp, proc_lck_attr);
b0d623f7 532#endif
2d21ac55
A
533 LIST_INSERT_HEAD(SESSHASH(0), &session0, s_hash);
534 proc_list_unlock();
535
536#if CONFIG_LCTX
b0d623f7 537 kernproc->p_lctx = NULL;
2d21ac55 538#endif
1c79356b 539
b0d623f7 540 kernproc->task = kernel_task;
1c79356b 541
b0d623f7
A
542 kernproc->p_stat = SRUN;
543 kernproc->p_flag = P_SYSTEM;
6d2010ae
A
544 kernproc->p_lflag = 0;
545 kernproc->p_ladvflag = 0;
546
547#if DEVELOPMENT || DEBUG
548 if (bootarg_disable_aslr)
549 kernproc->p_flag |= P_DISABLE_ASLR;
550#endif
551
b0d623f7
A
552 kernproc->p_nice = NZERO;
553 kernproc->p_pptr = kernproc;
2d21ac55 554
b0d623f7
A
555 TAILQ_INIT(&kernproc->p_uthlist);
556 TAILQ_INSERT_TAIL(&kernproc->p_uthlist, ut, uu_list);
2d21ac55 557
b0d623f7
A
558 kernproc->sigwait = FALSE;
559 kernproc->sigwait_thread = THREAD_NULL;
560 kernproc->exit_thread = THREAD_NULL;
561 kernproc->p_csflags = CS_VALID;
1c79356b 562
91447636
A
563 /*
564 * Create credential. This also Initializes the audit information.
91447636 565 */
2d21ac55 566 bsd_init_kprintf("calling bzero\n");
91447636 567 bzero(&temp_cred, sizeof(temp_cred));
6d2010ae
A
568 bzero(&temp_pcred, sizeof(temp_pcred));
569 temp_pcred.cr_ngroups = 1;
39236c6e
A
570 /* kern_proc, shouldn't call up to DS for group membership */
571 temp_pcred.cr_flags = CRF_NOMEMBERD;
6d2010ae 572 temp_cred.cr_audit.as_aia_p = audit_default_aia_p;
39236c6e 573
2d21ac55 574 bsd_init_kprintf("calling kauth_cred_create\n");
6d2010ae
A
575 /*
576 * We have to label the temp cred before we create from it to
577 * properly set cr_ngroups, or the create will fail.
578 */
579 posix_cred_label(&temp_cred, &temp_pcred);
b0d623f7 580 kernproc->p_ucred = kauth_cred_create(&temp_cred);
91447636 581
6d2010ae
A
582 /* update cred on proc */
583 PROC_UPDATE_CREDS_ONPROC(kernproc);
584
91447636 585 /* give the (already exisiting) initial thread a reference on it */
2d21ac55 586 bsd_init_kprintf("calling kauth_cred_ref\n");
b0d623f7
A
587 kauth_cred_ref(kernproc->p_ucred);
588 ut->uu_context.vc_ucred = kernproc->p_ucred;
2d21ac55
A
589 ut->uu_context.vc_thread = current_thread();
590
b0d623f7
A
591 TAILQ_INIT(&kernproc->p_aio_activeq);
592 TAILQ_INIT(&kernproc->p_aio_doneq);
593 kernproc->p_aio_total_count = 0;
594 kernproc->p_aio_active_count = 0;
55e303ae 595
2d21ac55 596 bsd_init_kprintf("calling file_lock_init\n");
91447636 597 file_lock_init();
1c79356b 598
2d21ac55 599#if CONFIG_MACF
b0d623f7 600 mac_cred_label_associate_kernel(kernproc->p_ucred);
2d21ac55
A
601#endif
602
1c79356b 603 /* Create the file descriptor table. */
b0d623f7 604 kernproc->p_fd = &filedesc0;
1c79356b 605 filedesc0.fd_cmask = cmask;
55e303ae
A
606 filedesc0.fd_knlistsize = -1;
607 filedesc0.fd_knlist = NULL;
608 filedesc0.fd_knhash = NULL;
609 filedesc0.fd_knhashmask = 0;
1c79356b
A
610
611 /* Create the limits structures. */
b0d623f7
A
612 kernproc->p_limit = &limit0;
613 for (i = 0; i < sizeof(kernproc->p_rlimit)/sizeof(kernproc->p_rlimit[0]); i++)
1c79356b
A
614 limit0.pl_rlimit[i].rlim_cur =
615 limit0.pl_rlimit[i].rlim_max = RLIM_INFINITY;
616 limit0.pl_rlimit[RLIMIT_NOFILE].rlim_cur = NOFILE;
0c530ab8 617 limit0.pl_rlimit[RLIMIT_NPROC].rlim_cur = maxprocperuid;
55e303ae 618 limit0.pl_rlimit[RLIMIT_NPROC].rlim_max = maxproc;
1c79356b
A
619 limit0.pl_rlimit[RLIMIT_STACK] = vm_initial_limit_stack;
620 limit0.pl_rlimit[RLIMIT_DATA] = vm_initial_limit_data;
621 limit0.pl_rlimit[RLIMIT_CORE] = vm_initial_limit_core;
2d21ac55 622 limit0.pl_refcnt = 1;
1c79356b 623
b0d623f7
A
624 kernproc->p_stats = &pstats0;
625 kernproc->p_sigacts = &sigacts0;
1c79356b
A
626
627 /*
fe8ab488 628 * Charge root for one process: launchd.
1c79356b 629 */
2d21ac55 630 bsd_init_kprintf("calling chgproccnt\n");
1c79356b
A
631 (void)chgproccnt(0, 1);
632
1c79356b
A
633 /*
634 * Allocate a kernel submap for pageable memory
765c9de3 635 * for temporary copying (execve()).
1c79356b
A
636 */
637 {
2d21ac55 638 vm_offset_t minimum;
1c79356b 639
2d21ac55 640 bsd_init_kprintf("calling kmem_suballoc\n");
6d2010ae 641 assert(bsd_pageable_map_size != 0);
1c79356b 642 ret = kmem_suballoc(kernel_map,
2d21ac55 643 &minimum,
b0d623f7 644 (vm_size_t)bsd_pageable_map_size,
1c79356b 645 TRUE,
91447636 646 VM_FLAGS_ANYWHERE,
1c79356b 647 &bsd_pageable_map);
9bccf70c
A
648 if (ret != KERN_SUCCESS)
649 panic("bsd_init: Failed to allocate bsd pageable map");
765c9de3
A
650 }
651
91447636
A
652 /*
653 * Initialize buffers and hash links for buffers
654 *
655 * SIDE EFFECT: Starts a thread for bcleanbuf_thread(), so must
656 * happen after a credential has been associated with
657 * the kernel task.
658 */
2d21ac55 659 bsd_init_kprintf("calling bsd_bufferinit\n");
91447636
A
660 bsd_bufferinit();
661
765c9de3 662 /* Initialize the execve() semaphore */
2d21ac55 663 bsd_init_kprintf("calling semaphore_create\n");
b0d623f7 664
9bccf70c
A
665 if (ret != KERN_SUCCESS)
666 panic("bsd_init: Failed to create execve semaphore");
1c79356b
A
667
668 /*
0b4e3aa0
A
669 * Initialize the calendar.
670 */
4a3eedf9 671 bsd_init_kprintf("calling IOKitInitializeTime\n");
2d21ac55
A
672 IOKitInitializeTime();
673
2d21ac55 674 bsd_init_kprintf("calling ubc_init\n");
1c79356b
A
675 ubc_init();
676
6d2010ae
A
677 /*
678 * Initialize device-switches.
679 */
680 bsd_init_kprintf("calling devsw_init() \n");
681 devsw_init();
682
1c79356b 683 /* Initialize the file systems. */
2d21ac55 684 bsd_init_kprintf("calling vfsinit\n");
1c79356b
A
685 vfsinit();
686
39236c6e
A
687#if CONFIG_PROC_UUID_POLICY
688 /* Initial proc_uuid_policy subsystem */
689 bsd_init_kprintf("calling proc_uuid_policy_init()\n");
690 proc_uuid_policy_init();
691#endif
692
2d21ac55
A
693#if SOCKETS
694 /* Initialize per-CPU cache allocator */
695 mcache_init();
696
1c79356b 697 /* Initialize mbuf's. */
2d21ac55 698 bsd_init_kprintf("calling mbinit\n");
1c79356b 699 mbinit();
b0d623f7 700 net_str_id_init(); /* for mbuf tags */
2d21ac55 701#endif /* SOCKETS */
1c79356b 702
55e303ae
A
703 /*
704 * Initializes security event auditing.
705 * XXX: Should/could this occur later?
706 */
b0d623f7 707#if CONFIG_AUDIT
2d21ac55
A
708 bsd_init_kprintf("calling audit_init\n");
709 audit_init();
710#endif
55e303ae
A
711
712 /* Initialize kqueues */
2d21ac55 713 bsd_init_kprintf("calling knote_init\n");
55e303ae
A
714 knote_init();
715
716 /* Initialize for async IO */
2d21ac55 717 bsd_init_kprintf("calling aio_init\n");
55e303ae
A
718 aio_init();
719
91447636 720 /* Initialize pipes */
2d21ac55 721 bsd_init_kprintf("calling pipeinit\n");
91447636
A
722 pipeinit();
723
724 /* Initialize SysV shm subsystem locks; the subsystem proper is
725 * initialized through a sysctl.
726 */
2d21ac55
A
727#if SYSV_SHM
728 bsd_init_kprintf("calling sysv_shm_lock_init\n");
91447636 729 sysv_shm_lock_init();
2d21ac55
A
730#endif
731#if SYSV_SEM
732 bsd_init_kprintf("calling sysv_sem_lock_init\n");
91447636 733 sysv_sem_lock_init();
2d21ac55
A
734#endif
735#if SYSV_MSG
736 bsd_init_kprintf("sysv_msg_lock_init\n");
91447636 737 sysv_msg_lock_init();
2d21ac55
A
738#endif
739 bsd_init_kprintf("calling pshm_lock_init\n");
91447636 740 pshm_lock_init();
2d21ac55 741 bsd_init_kprintf("calling psem_lock_init\n");
91447636
A
742 psem_lock_init();
743
2d21ac55 744 pthread_init();
9bccf70c 745 /* POSIX Shm and Sem */
2d21ac55 746 bsd_init_kprintf("calling pshm_cache_init\n");
9bccf70c 747 pshm_cache_init();
2d21ac55 748 bsd_init_kprintf("calling psem_cache_init\n");
9bccf70c 749 psem_cache_init();
2d21ac55 750 bsd_init_kprintf("calling time_zone_slock_init\n");
9bccf70c 751 time_zone_slock_init();
6d2010ae
A
752 bsd_init_kprintf("calling select_wait_queue_init\n");
753 select_wait_queue_init();
1c79356b 754
1c79356b
A
755 /*
756 * Initialize protocols. Block reception of incoming packets
757 * until everything is ready.
758 */
2d21ac55 759 bsd_init_kprintf("calling sysctl_register_fixed\n");
1c79356b 760 sysctl_register_fixed();
2d21ac55 761 bsd_init_kprintf("calling sysctl_mib_init\n");
43866e37 762 sysctl_mib_init();
2d21ac55
A
763#if NETWORKING
764 bsd_init_kprintf("calling dlil_init\n");
1c79356b 765 dlil_init();
2d21ac55 766 bsd_init_kprintf("calling proto_kpi_init\n");
91447636 767 proto_kpi_init();
2d21ac55
A
768#endif /* NETWORKING */
769#if SOCKETS
770 bsd_init_kprintf("calling socketinit\n");
1c79356b 771 socketinit();
2d21ac55 772 bsd_init_kprintf("calling domaininit\n");
1c79356b 773 domaininit();
316670eb 774 iptap_init();
39236c6e
A
775#if FLOW_DIVERT
776 flow_divert_init();
777#endif /* FLOW_DIVERT */
2d21ac55 778#endif /* SOCKETS */
1c79356b 779
b0d623f7
A
780 kernproc->p_fd->fd_cdir = NULL;
781 kernproc->p_fd->fd_rdir = NULL;
1c79356b 782
6d2010ae 783#if CONFIG_FREEZE
316670eb
A
784#ifndef CONFIG_MEMORYSTATUS
785 #error "CONFIG_FREEZE defined without matching CONFIG_MEMORYSTATUS"
786#endif
787 /* Initialise background freezing */
788 bsd_init_kprintf("calling memorystatus_freeze_init\n");
789 memorystatus_freeze_init();
6d2010ae
A
790#endif
791
316670eb 792#if CONFIG_MEMORYSTATUS
d1ecb069 793 /* Initialize kernel memory status notifications */
316670eb
A
794 bsd_init_kprintf("calling memorystatus_init\n");
795 memorystatus_init();
796#endif /* CONFIG_MEMORYSTATUS */
d1ecb069 797
fe8ab488
A
798 bsd_init_kprintf("calling macx_init\n");
799 macx_init();
800
801 bsd_init_kprintf("calling acct_init\n");
802 acct_init();
803
1c79356b
A
804#ifdef GPROF
805 /* Initialize kernel profiling. */
806 kmstartup();
807#endif
808
2d21ac55 809 bsd_init_kprintf("calling bsd_autoconf\n");
1c79356b
A
810 bsd_autoconf();
811
2d21ac55 812#if CONFIG_DTRACE
2d21ac55
A
813 dtrace_postinit();
814#endif
815
1c79356b
A
816 /*
817 * We attach the loopback interface *way* down here to ensure
818 * it happens after autoconf(), otherwise it becomes the
819 * "primary" interface.
820 */
821#include <loop.h>
822#if NLOOP > 0
2d21ac55 823 bsd_init_kprintf("calling loopattach\n");
1c79356b
A
824 loopattach(); /* XXX */
825#endif
39236c6e
A
826#if NGIF
827 /* Initialize gif interface (after lo0) */
828 gif_init();
829#endif
b0d623f7
A
830
831#if PFLOG
832 /* Initialize packet filter log interface */
833 pfloginit();
834#endif /* PFLOG */
835
2d21ac55
A
836#if NETHER > 0
837 /* Register the built-in dlil ethernet interface family */
838 bsd_init_kprintf("calling ether_family_init\n");
9bccf70c 839 ether_family_init();
2d21ac55 840#endif /* ETHER */
1c79356b 841
2d21ac55 842#if NETWORKING
91447636 843 /* Call any kext code that wants to run just after network init */
2d21ac55 844 bsd_init_kprintf("calling net_init_run\n");
91447636 845 net_init_run();
b0d623f7 846
fe8ab488
A
847#if CONTENT_FILTER
848 cfil_init();
849#endif
850
851#if PACKET_MANGLER
852 pkt_mnglr_init();
853#endif
854
855#if NECP
856 /* Initialize Network Extension Control Policies */
857 necp_init();
858#endif
859
b0d623f7
A
860 /* register user tunnel kernel control handler */
861 utun_register_control();
39236c6e
A
862#if IPSEC
863 ipsec_register_control();
864#endif /* IPSEC */
316670eb
A
865 netsrc_init();
866 nstat_init();
fe8ab488 867 tcp_cc_init();
2d21ac55 868#endif /* NETWORKING */
91447636 869
2d21ac55 870 bsd_init_kprintf("calling vnode_pager_bootstrap\n");
1c79356b 871 vnode_pager_bootstrap();
91447636 872
2d21ac55 873 bsd_init_kprintf("calling inittodr\n");
91447636 874 inittodr(0);
1c79356b
A
875
876 /* Mount the root file system. */
877 while( TRUE) {
878 int err;
879
2d21ac55 880 bsd_init_kprintf("calling setconf\n");
1c79356b 881 setconf();
6d2010ae
A
882#if NFSCLIENT
883 netboot = (mountroot == netboot_mountroot);
884#endif
9bccf70c 885
2d21ac55 886 bsd_init_kprintf("vfs_mountroot\n");
1c79356b
A
887 if (0 == (err = vfs_mountroot()))
888 break;
2d21ac55 889 rootdevice[0] = '\0';
91447636 890#if NFSCLIENT
6d2010ae 891 if (netboot) {
b0d623f7
A
892 PE_display_icon( 0, "noroot"); /* XXX a netboot-specific icon would be nicer */
893 vc_progress_set(FALSE, 0);
894 for (i=1; 1; i*=2) {
895 printf("bsd_init: failed to mount network root, error %d, %s\n",
896 err, PE_boot_args());
897 printf("We are hanging here...\n");
898 IOSleep(i*60*1000);
899 }
900 /*NOTREACHED*/
9bccf70c 901 }
91447636 902#endif
1c79356b
A
903 printf("cannot mount root, errno = %d\n", err);
904 boothowto |= RB_ASKNAME;
905 }
906
2d21ac55
A
907 IOSecureBSDRoot(rootdevice);
908
909 context.vc_thread = current_thread();
b0d623f7 910 context.vc_ucred = kernproc->p_ucred;
91447636 911 mountlist.tqh_first->mnt_flag |= MNT_ROOTFS;
1c79356b 912
2d21ac55 913 bsd_init_kprintf("calling VFS_ROOT\n");
1c79356b 914 /* Get the vnode for '/'. Set fdp->fd_fd.fd_cdir to reference it. */
91447636 915 if (VFS_ROOT(mountlist.tqh_first, &rootvnode, &context))
2d21ac55 916 panic("bsd_init: cannot find root vnode: %s", PE_boot_args());
91447636
A
917 rootvnode->v_flag |= VROOT;
918 (void)vnode_ref(rootvnode);
919 (void)vnode_put(rootvnode);
fa4905b1 920 filedesc0.fd_cdir = rootvnode;
9bccf70c 921
91447636 922#if NFSCLIENT
6d2010ae 923 if (netboot) {
9bccf70c 924 int err;
6d2010ae
A
925
926 netboot = TRUE;
9bccf70c 927 /* post mount setup */
2d21ac55 928 if ((err = netboot_setup()) != 0) {
b0d623f7
A
929 PE_display_icon( 0, "noroot"); /* XXX a netboot-specific icon would be nicer */
930 vc_progress_set(FALSE, 0);
931 for (i=1; 1; i*=2) {
932 printf("bsd_init: NetBoot could not find root, error %d: %s\n",
933 err, PE_boot_args());
934 printf("We are hanging here...\n");
935 IOSleep(i*60*1000);
936 }
937 /*NOTREACHED*/
9bccf70c
A
938 }
939 }
91447636 940#endif
1c79356b
A
941
942
2d21ac55
A
943#if CONFIG_IMAGEBOOT
944 /*
945 * See if a system disk image is present. If so, mount it and
946 * switch the root vnode to point to it
947 */
6d2010ae
A
948 if (netboot == FALSE && imageboot_needed()) {
949 /*
950 * An image was found. No turning back: we're booted
951 * with a kernel from the disk image.
952 */
953 imageboot_setup();
2d21ac55
A
954 }
955#endif /* CONFIG_IMAGEBOOT */
956
b0d623f7 957 /* set initial time; all other resource data is already zero'ed */
39236c6e 958 microtime_with_abstime(&kernproc->p_start, &kernproc->p_stats->ps_start);
1c79356b 959
9bccf70c 960#if DEVFS
1c79356b 961 {
2d21ac55
A
962 char mounthere[] = "/dev"; /* !const because of internal casting */
963
964 bsd_init_kprintf("calling devfs_kernel_mount\n");
965 devfs_kernel_mount(mounthere);
1c79356b 966 }
55e303ae 967#endif /* DEVFS */
1c79356b
A
968
969 /* Initialize signal state for process 0. */
2d21ac55 970 bsd_init_kprintf("calling siginit\n");
b0d623f7 971 siginit(kernproc);
1c79356b 972
2d21ac55 973 bsd_init_kprintf("calling bsd_utaskbootstrap\n");
1c79356b
A
974 bsd_utaskbootstrap();
975
b0d623f7
A
976#if defined(__LP64__)
977 kernproc->p_flag |= P_LP64;
b0d623f7 978#endif
6d2010ae
A
979
980 pal_kernel_announce();
981
2d21ac55
A
982 bsd_init_kprintf("calling mountroot_post_hook\n");
983
9bccf70c
A
984 /* invoke post-root-mount hook */
985 if (mountroot_post_hook != NULL)
986 mountroot_post_hook();
2d21ac55
A
987
988#if 0 /* not yet */
b0d623f7 989 consider_zone_gc(FALSE);
2d21ac55 990#endif
b0d623f7 991
2d21ac55 992 bsd_init_kprintf("done\n");
1c79356b
A
993}
994
995void
9bccf70c 996bsdinit_task(void)
1c79356b 997{
2d21ac55 998 proc_t p = current_proc();
1c79356b 999 struct uthread *ut;
2d21ac55 1000 thread_t thread;
1c79356b 1001
91447636 1002 process_name("init", p);
1c79356b
A
1003
1004 ux_handler_init();
1c79356b 1005
2d21ac55 1006 thread = current_thread();
1c79356b 1007 (void) host_set_exception_ports(host_priv_self(),
b0d623f7
A
1008 EXC_MASK_ALL & ~(EXC_MASK_RPC_ALERT),//pilotfish (shark) needs this port
1009 (mach_port_t) ux_exception_port,
2d21ac55
A
1010 EXCEPTION_DEFAULT| MACH_EXCEPTION_CODES,
1011 0);
1c79356b 1012
2d21ac55 1013 ut = (uthread_t)get_bsdthread_info(thread);
1c79356b 1014
2d21ac55 1015 bsd_init_task = get_threadtask(thread);
1c79356b 1016 init_task_failure_data[0] = 0;
2d21ac55
A
1017
1018#if CONFIG_MACF
1019 mac_cred_label_associate_user(p->p_ucred);
2d21ac55 1020#endif
1c79356b 1021 load_init_program(p);
91447636 1022 lock_trace = 1;
1c79356b
A
1023}
1024
2d21ac55
A
1025kern_return_t
1026bsd_autoconf(void)
9bccf70c 1027{
2d21ac55 1028 kprintf("bsd_autoconf: calling kminit\n");
1c79356b
A
1029 kminit();
1030
1031 /*
1032 * Early startup for bsd pseudodevices.
1033 */
1034 {
1035 struct pseudo_init *pi;
1036
1037 for (pi = pseudo_inits; pi->ps_func; pi++)
1038 (*pi->ps_func) (pi->ps_count);
1039 }
1040
9bccf70c 1041 return( IOKitBSDInit());
1c79356b
A
1042}
1043
1044
55e303ae 1045#include <sys/disklabel.h> /* for MAXPARTITIONS */
1c79356b 1046
91447636
A
1047static void
1048setconf(void)
1c79356b 1049{
1c79356b
A
1050 u_int32_t flags;
1051 kern_return_t err;
1052
cf7d32b8 1053 err = IOFindBSDRoot(rootdevice, sizeof(rootdevice), &rootdev, &flags);
1c79356b
A
1054 if( err) {
1055 printf("setconf: IOFindBSDRoot returned an error (%d);"
1056 "setting rootdevice to 'sd0a'.\n", err); /* XXX DEBUG TEMP */
1057 rootdev = makedev( 6, 0 );
2d21ac55 1058 strlcpy(rootdevice, "sd0a", sizeof(rootdevice));
1c79356b
A
1059 flags = 0;
1060 }
1061
91447636 1062#if NFSCLIENT
1c79356b 1063 if( flags & 1 ) {
9bccf70c
A
1064 /* network device */
1065 mountroot = netboot_mountroot;
1c79356b 1066 } else {
91447636 1067#endif
1c79356b
A
1068 /* otherwise have vfs determine root filesystem */
1069 mountroot = NULL;
91447636 1070#if NFSCLIENT
1c79356b 1071 }
91447636 1072#endif
1c79356b
A
1073
1074}
1075
2d21ac55
A
1076void
1077bsd_utaskbootstrap(void)
1c79356b 1078{
2d21ac55 1079 thread_t thread;
9bccf70c 1080 struct uthread *ut;
1c79356b 1081
b0d623f7
A
1082 /*
1083 * Clone the bootstrap process from the kernel process, without
1084 * inheriting either task characteristics or memory from the kernel;
1085 */
fe8ab488 1086 thread = cloneproc(TASK_NULL, COALITION_NULL, kernproc, FALSE, TRUE);
b0d623f7 1087
2d21ac55
A
1088 /* Hold the reference as it will be dropped during shutdown */
1089 initproc = proc_find(1);
1090#if __PROC_INTERNAL_DEBUG
1091 if (initproc == PROC_NULL)
1092 panic("bsd_utaskbootstrap: initproc not set\n");
1093#endif
b0d623f7
A
1094 /*
1095 * Since we aren't going back out the normal way to our parent,
1096 * we have to drop the transition locks explicitly.
1097 */
1098 proc_signalend(initproc, 0);
1099 proc_transend(initproc, 0);
9bccf70c 1100
2d21ac55 1101 ut = (struct uthread *)get_bsdthread_info(thread);
9bccf70c 1102 ut->uu_sigmask = 0;
2d21ac55
A
1103 act_set_astbsd(thread);
1104 (void) thread_resume(thread);
1c79356b
A
1105}
1106
2d21ac55
A
1107static void
1108parse_bsd_args(void)
1c79356b 1109{
2d21ac55
A
1110 char namep[16];
1111 int msgbuf;
1c79356b 1112
39236c6e 1113 if ( PE_parse_boot_argn("-s", namep, sizeof (namep)))
1c79356b 1114 boothowto |= RB_SINGLE;
55e303ae 1115
593a1d5f 1116 if (PE_parse_boot_argn("-b", namep, sizeof (namep)))
1c79356b 1117 boothowto |= RB_NOBOOTRC;
1c79356b 1118
593a1d5f 1119 if (PE_parse_boot_argn("-x", namep, sizeof (namep))) /* safe boot */
2d21ac55 1120 boothowto |= RB_SAFEBOOT;
1c79356b 1121
fe8ab488 1122
6d2010ae
A
1123 /* disable vnode_cache_is_authorized() by setting vnode_cache_defeat */
1124 if (PE_parse_boot_argn("-vnode_cache_defeat", namep, sizeof (namep)))
1125 bootarg_vnode_cache_defeat = 1;
1126
1127#if DEVELOPMENT || DEBUG
1128 if (PE_parse_boot_argn("-disable_aslr", namep, sizeof (namep)))
1129 bootarg_disable_aslr = 1;
1130#endif
1131
593a1d5f 1132 PE_parse_boot_argn("ncl", &ncl, sizeof (ncl));
b0d623f7
A
1133 if (PE_parse_boot_argn("nbuf", &max_nbuf_headers,
1134 sizeof (max_nbuf_headers))) {
0c530ab8 1135 customnbuf = 1;
2d21ac55 1136 }
6d2010ae
A
1137
1138#if CONFIG_MACF
1139#if defined (__i386__) || defined (__x86_64__)
1140 PE_parse_boot_argn("policy_check", &policy_check_flags, sizeof (policy_check_flags));
1141#endif
1142#endif /* CONFIG_MACF */
1c79356b 1143
593a1d5f 1144 if (PE_parse_boot_argn("msgbuf", &msgbuf, sizeof (msgbuf))) {
2d21ac55
A
1145 log_setsize(msgbuf);
1146 }
6d2010ae
A
1147
1148 if (PE_parse_boot_argn("-novfscache", namep, sizeof(namep))) {
1149 nc_disabled = 1;
1150 }
1c79356b
A
1151}
1152
b0d623f7
A
1153void
1154bsd_exec_setup(int scale)
1155{
1156
1157 switch (scale) {
1158 case 0:
1159 case 1:
1160 bsd_simul_execs = BSD_SIMUL_EXECS;
1161 break;
1162 case 2:
1163 case 3:
1164 bsd_simul_execs = 65;
1165 break;
1166 case 4:
1167 case 5:
1168 bsd_simul_execs = 129;
1169 break;
1170 case 6:
1171 case 7:
1172 bsd_simul_execs = 257;
1173 break;
1174 default:
1175 bsd_simul_execs = 513;
1176 break;
1177
1178 }
6d2010ae 1179 bsd_pageable_map_size = (bsd_simul_execs * BSD_PAGEABLE_SIZE_PER_EXEC);
b0d623f7
A
1180}
1181
91447636 1182#if !NFSCLIENT
6d2010ae
A
1183int
1184netboot_root(void);
1185
91447636
A
1186int
1187netboot_root(void)
1c79356b 1188{
91447636 1189 return(0);
1c79356b 1190}
91447636 1191#endif