The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/bsd/kern/bsd_init.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*
    2  * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved.
    3  *
    4  * @APPLE_LICENSE_HEADER_START@
    5  * 
    6  * Copyright (c) 1999-2003 Apple Computer, Inc.  All Rights Reserved.
    7  * 
    8  * This file contains Original Code and/or Modifications of Original Code
    9  * as defined in and that are subject to the Apple Public Source License
   10  * Version 2.0 (the 'License'). You may not use this file except in
   11  * compliance with the License. Please obtain a copy of the License at
   12  * http://www.opensource.apple.com/apsl/ and read it before using this
   13  * file.
   14  * 
   15  * The Original Code and all software distributed under the License are
   16  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
   17  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
   18  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
   19  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
   20  * Please see the License for the specific language governing rights and
   21  * limitations under the License.
   22  * 
   23  * @APPLE_LICENSE_HEADER_END@
   24  */
   25 /*
   26  * Copyright (c) 1982, 1986, 1989, 1991, 1992, 1993
   27  *      The Regents of the University of California.  All rights reserved.
   28  * (c) UNIX System Laboratories, Inc.
   29  * All or some portions of this file are derived from material licensed
   30  * to the University of California by American Telephone and Telegraph
   31  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
   32  * the permission of UNIX System Laboratories, Inc.
   33  *
   34  * Redistribution and use in source and binary forms, with or without
   35  * modification, are permitted provided that the following conditions
   36  * are met:
   37  * 1. Redistributions of source code must retain the above copyright
   38  *    notice, this list of conditions and the following disclaimer.
   39  * 2. Redistributions in binary form must reproduce the above copyright
   40  *    notice, this list of conditions and the following disclaimer in the
   41  *    documentation and/or other materials provided with the distribution.
   42  * 3. All advertising materials mentioning features or use of this software
   43  *    must display the following acknowledgement:
   44  *      This product includes software developed by the University of
   45  *      California, Berkeley and its contributors.
   46  * 4. 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
   48  *    without specific prior written permission.
   49  *
   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
   52  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   53  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   54  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   55  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   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
   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
   60  * SUCH DAMAGE.
   61  *
   62  *      @(#)init_main.c 8.16 (Berkeley) 5/14/95
   63  */
   64 
   65 /* 
   66  *
   67  * Mach Operating System
   68  * Copyright (c) 1987 Carnegie-Mellon University
   69  * All rights reserved.  The CMU software License Agreement specifies
   70  * the terms and conditions for use and redistribution.
   71  */
   72 
   73 #include <sys/param.h>
   74 #include <sys/filedesc.h>
   75 #include <sys/kernel.h>
   76 #include <sys/mount.h>
   77 #include <sys/proc.h>
   78 #include <sys/systm.h>
   79 #include <sys/vnode.h>
   80 #include <sys/conf.h>
   81 #include <sys/buf.h>
   82 #include <sys/clist.h>
   83 #include <sys/user.h>
   84 #include <sys/time.h>
   85 #include <sys/systm.h>
   86 
   87 #include <sys/kern_audit.h>
   88 
   89 #include <sys/malloc.h>
   90 #include <sys/dkstat.h>
   91 
   92 #include <machine/spl.h>
   93 #include <kern/thread.h>
   94 #include <kern/task.h>
   95 #include <kern/ast.h>
   96 
   97 #include <mach/vm_param.h>
   98 
   99 #include <vm/vm_map.h>
  100 #include <vm/vm_kern.h>
  101 
  102 #include <sys/ux_exception.h>   /* for ux_exception_port */
  103 
  104 #include <sys/reboot.h>
  105 #include <mach/exception_types.h>
  106 #include <dev/busvar.h>                 /* for pseudo_inits */
  107 #include <sys/kdebug.h>
  108 
  109 #include <mach/mach_types.h>
  110 #include <mach/vm_prot.h>
  111 #include <mach/semaphore.h>
  112 #include <mach/sync_policy.h>
  113 #include <kern/clock.h>
  114 #include <mach/kern_return.h>
  115 
  116 #include <mach/shared_memory_server.h>
  117 #include <vm/vm_shared_memory_server.h>
  118 
  119 extern int app_profile;         /* on/off switch for pre-heat cache */
  120 
  121 char    copyright[] =
  122 "Copyright (c) 1982, 1986, 1989, 1991, 1993\n\t"
  123 "The Regents of the University of California. "
  124 "All rights reserved.\n\n";
  125 
  126 extern void     ux_handler();
  127 
  128 /* Components of the first process -- never freed. */
  129 struct  proc proc0;
  130 struct  session session0;
  131 struct  pgrp pgrp0;
  132 struct  pcred cred0;
  133 struct  filedesc filedesc0;
  134 struct  plimit limit0;
  135 struct  pstats pstats0;
  136 struct  sigacts sigacts0;
  137 struct  proc *kernproc, *initproc;
  138 
  139 long tk_cancc;
  140 long tk_nin;
  141 long tk_nout;
  142 long tk_rawcc;
  143 
  144 /* Global variables to make pstat happy. We do swapping differently */
  145 int nswdev, nswap;
  146 int nswapmap;
  147 void *swapmap;
  148 struct swdevt swdevt[1];
  149 
  150 dev_t   rootdev;                /* device of the root */
  151 dev_t   dumpdev;                /* device to take dumps on */
  152 long    dumplo;                 /* offset into dumpdev */
  153 long    hostid;
  154 char    hostname[MAXHOSTNAMELEN];
  155 int             hostnamelen;
  156 char    domainname[MAXDOMNAMELEN];
  157 int             domainnamelen;
  158 char    classichandler[32] = {0};  
  159 long    classichandler_fsid = -1L;
  160 long    classichandler_fileid = -1L;
  161 
  162 char rootdevice[16];    /* hfs device names have at least 9 chars */
  163 struct  timeval boottime;               /* GRODY!  This has to go... */
  164 
  165 #ifdef  KMEMSTATS
  166 struct  kmemstats kmemstats[M_LAST];
  167 #endif
  168 
  169 int     lbolt;                          /* awoken once a second */
  170 struct  vnode *rootvp;
  171 int boothowto = RB_DEBUG;
  172 
  173 #define BSD_PAGABLE_MAP_SIZE    (16 * 512 * 1024)
  174 vm_map_t        bsd_pageable_map;
  175 vm_map_t        mb_map;
  176 semaphore_t execve_semaphore;
  177 
  178 int     cmask = CMASK;
  179 
  180 int parse_bsd_args(void);
  181 extern int bsd_hardclockinit;
  182 extern task_t bsd_init_task;
  183 extern char    init_task_failure_data[];
  184 extern void time_zone_slock_init(void);
  185 
  186 funnel_t *kernel_flock;
  187 funnel_t *network_flock;
  188 int disable_funnel = 0;         /* disables split funnel */
  189 int enable_funnel = 0;          /* disables split funnel */
  190 
  191 /*
  192  * Initialization code.
  193  * Called from cold start routine as
  194  * soon as a stack and segmentation
  195  * have been established.
  196  * Functions:
  197  *      turn on clock
  198  *      hand craft 0th process
  199  *      call all initialization routines
  200  *  hand craft 1st user process
  201  */
  202 
  203 /*
  204  *      Sets the name for the given task.
  205  */
  206 void
  207 proc_name(s, p)
  208         char            *s;
  209         struct proc *p;
  210 {
  211         int             length = strlen(s);
  212 
  213         bcopy(s, p->p_comm,
  214                 length >= sizeof(p->p_comm) ? sizeof(p->p_comm) :
  215                         length + 1);
  216 }
  217 
  218 /* To allow these values to be patched, they're globals here */
  219 #include <machine/vmparam.h>
  220 struct rlimit vm_initial_limit_stack = { DFLSSIZ, MAXSSIZ };
  221 struct rlimit vm_initial_limit_data = { DFLDSIZ, MAXDSIZ };
  222 struct rlimit vm_initial_limit_core = { DFLCSIZ, MAXCSIZ };
  223 
  224 extern thread_t first_thread;
  225 extern thread_act_t     cloneproc(struct proc *, int);
  226 extern int      (*mountroot) __P((void));
  227 extern int      netboot_mountroot();    /* netboot.c */
  228 extern int      netboot_setup(struct proc * p);
  229 
  230 /* hook called after root is mounted XXX temporary hack */
  231 void (*mountroot_post_hook)(void);
  232 
  233 void
  234 bsd_init()
  235 {
  236         register struct proc *p;
  237         extern struct ucred *rootcred;
  238         register int i;
  239         int s;
  240         thread_t        th;
  241         void            lightning_bolt(void );
  242         kern_return_t   ret;
  243         boolean_t funnel_state;
  244         extern void uthread_zone_init();
  245 
  246 
  247         /* split funnel is enabled by default */
  248         PE_parse_boot_arg("dfnl", &disable_funnel);
  249 
  250         kernel_flock = funnel_alloc(KERNEL_FUNNEL);
  251         if (kernel_flock == (funnel_t *)0 ) {
  252                 panic("bsd_init: Failed to allocate kernel funnel");
  253         }
  254         
  255         funnel_state = thread_funnel_set(kernel_flock, TRUE);
  256 
  257         if (!disable_funnel) {
  258                 network_flock = funnel_alloc(NETWORK_FUNNEL);
  259                 if (network_flock == (funnel_t *)0 ) {
  260                         panic("bsd_init: Failed to allocate network funnel");
  261                 }
  262         } else {
  263                 network_flock = kernel_flock;
  264         }
  265 
  266         printf(copyright);
  267 
  268         kmeminit();
  269         
  270         parse_bsd_args();
  271 
  272         bsd_bufferinit();
  273 
  274         /* Initialize the uthread zone */
  275         uthread_zone_init();
  276 
  277         /*
  278          * Initialize process and pgrp structures.
  279          */
  280         procinit();
  281 
  282         kernproc = &proc0;
  283 
  284         p = kernproc;
  285 
  286         /* kernel_task->proc = kernproc; */
  287         set_bsdtask_info(kernel_task,(void *)p);
  288         p->p_pid = 0;
  289 
  290         /* give kernproc a name */
  291         proc_name("kernel_task", p);
  292 
  293         if (current_task() != kernel_task)
  294                 printf("bsd_init: We have a problem, "
  295                                 "current task is not kernel task\n");
  296         
  297         /*
  298          * Create process 0.
  299          */
  300         LIST_INSERT_HEAD(&allproc, p, p_list);
  301         p->p_pgrp = &pgrp0;
  302         LIST_INSERT_HEAD(PGRPHASH(0), &pgrp0, pg_hash);
  303         LIST_INIT(&pgrp0.pg_members);
  304         LIST_INSERT_HEAD(&pgrp0.pg_members, p, p_pglist);
  305 
  306         pgrp0.pg_session = &session0;
  307         session0.s_count = 1;
  308         session0.s_leader = p;
  309 
  310         p->task = kernel_task;
  311         
  312         p->p_stat = SRUN;
  313         p->p_flag = P_INMEM|P_SYSTEM;
  314         p->p_nice = NZERO;
  315         p->p_pptr = p;
  316         lockinit(&p->signal_lock, PVM, "signal", 0, 0);
  317         TAILQ_INIT(&p->p_uthlist);
  318         p->sigwait = FALSE;
  319         p->sigwait_thread = THREAD_NULL;
  320         p->exit_thread = THREAD_NULL;
  321 
  322         /* Create credentials. */
  323         lockinit(&cred0.pc_lock, PLOCK, "proc0 cred", 0, 0);
  324         cred0.p_refcnt = 1;
  325         p->p_cred = &cred0;
  326         p->p_ucred = crget();
  327         p->p_ucred->cr_ngroups = 1;     /* group 0 */
  328         
  329         TAILQ_INIT(&p->aio_activeq);
  330         TAILQ_INIT(&p->aio_doneq);
  331         p->aio_active_count = 0;
  332         p->aio_done_count = 0;
  333 
  334         /* Set the audit info for this process */
  335         audit_proc_init(p);
  336 
  337         /* Create the file descriptor table. */
  338         filedesc0.fd_refcnt = 1+1;      /* +1 so shutdown will not _FREE_ZONE */
  339         p->p_fd = &filedesc0;
  340         filedesc0.fd_cmask = cmask;
  341         filedesc0.fd_knlistsize = -1;
  342         filedesc0.fd_knlist = NULL;
  343         filedesc0.fd_knhash = NULL;
  344         filedesc0.fd_knhashmask = 0;
  345 
  346         /* Create the limits structures. */
  347         p->p_limit = &limit0;
  348         for (i = 0; i < sizeof(p->p_rlimit)/sizeof(p->p_rlimit[0]); i++)
  349                 limit0.pl_rlimit[i].rlim_cur = 
  350                         limit0.pl_rlimit[i].rlim_max = RLIM_INFINITY;
  351         limit0.pl_rlimit[RLIMIT_NOFILE].rlim_cur = NOFILE;
  352         limit0.pl_rlimit[RLIMIT_NPROC].rlim_cur = MAXUPRC;
  353         limit0.pl_rlimit[RLIMIT_NPROC].rlim_max = maxproc;
  354         limit0.pl_rlimit[RLIMIT_STACK] = vm_initial_limit_stack;
  355         limit0.pl_rlimit[RLIMIT_DATA] = vm_initial_limit_data;
  356         limit0.pl_rlimit[RLIMIT_CORE] = vm_initial_limit_core;
  357         limit0.p_refcnt = 1;
  358 
  359         p->p_stats = &pstats0;
  360         p->p_sigacts = &sigacts0;
  361 
  362         /*
  363          * Charge root for one process.
  364          */
  365         (void)chgproccnt(0, 1);
  366 
  367         /*
  368          *      Allocate a kernel submap for pageable memory
  369          *      for temporary copying (execve()).
  370          */
  371         {
  372                 vm_offset_t     min;
  373 
  374                 ret = kmem_suballoc(kernel_map,
  375                                 &min,
  376                                 (vm_size_t)BSD_PAGABLE_MAP_SIZE,
  377                                 TRUE,
  378                                 TRUE,
  379                                 &bsd_pageable_map);
  380                 if (ret != KERN_SUCCESS) 
  381                         panic("bsd_init: Failed to allocate bsd pageable map");
  382         }
  383 
  384         /* Initialize the execve() semaphore */
  385         ret = semaphore_create(kernel_task, &execve_semaphore,
  386                         SYNC_POLICY_FIFO, (BSD_PAGABLE_MAP_SIZE / NCARGS));
  387         if (ret != KERN_SUCCESS)
  388                 panic("bsd_init: Failed to create execve semaphore");
  389 
  390         /*
  391          * Initialize the calendar.
  392          */
  393         IOKitResetTime();
  394 
  395         ubc_init();
  396 
  397         /* Initialize the file systems. */
  398         vfsinit();
  399 
  400         /* Initialize mbuf's. */
  401         mbinit();
  402 
  403         /* Initialize syslog */
  404         log_init();
  405 
  406         /*
  407          * Initializes security event auditing.
  408          * XXX: Should/could this occur later?
  409          */
  410         audit_init();  
  411 
  412         /* Initialize kqueues */
  413         knote_init();
  414 
  415         /* Initialize for async IO */
  416         aio_init();
  417 
  418         /* POSIX Shm and Sem */
  419         pshm_cache_init();
  420         psem_cache_init();
  421         time_zone_slock_init();
  422 
  423         /*
  424          * Initialize protocols.  Block reception of incoming packets
  425          * until everything is ready.
  426          */
  427         s = splimp();
  428         sysctl_register_fixed(); 
  429         sysctl_mib_init();
  430         dlil_init();
  431         socketinit();
  432         domaininit();
  433         splx(s);
  434 
  435         p->p_fd->fd_cdir = NULL;
  436         p->p_fd->fd_rdir = NULL;
  437 
  438 #ifdef GPROF
  439         /* Initialize kernel profiling. */
  440         kmstartup();
  441 #endif
  442 
  443         /* kick off timeout driven events by calling first time */
  444         thread_wakeup(&lbolt);
  445         timeout((void (*)(void *))lightning_bolt, 0, hz);
  446 
  447         bsd_autoconf();
  448 
  449         /*
  450          * We attach the loopback interface *way* down here to ensure
  451          * it happens after autoconf(), otherwise it becomes the
  452          * "primary" interface.
  453          */
  454 #include <loop.h>
  455 #if NLOOP > 0
  456         loopattach();                   /* XXX */
  457 #endif
  458         
  459         /* Register the built-in dlil ethernet interface family */
  460         ether_family_init();
  461 
  462         vnode_pager_bootstrap();
  463 
  464         /* Mount the root file system. */
  465         while( TRUE) {
  466                 int err;
  467 
  468                 setconf();
  469                 /*
  470                  * read the time after clock_initialize_calendar()
  471                  * and before nfs mount
  472                  */
  473                 microtime((struct timeval  *)&time);
  474 
  475                 bsd_hardclockinit = -1; /* start ticking */
  476 
  477                 if (0 == (err = vfs_mountroot()))
  478                         break;
  479                 if (mountroot == netboot_mountroot) {
  480                         printf("cannot mount network root, errno = %d\n", err);
  481                         mountroot = NULL;
  482                         if (0 == (err = vfs_mountroot()))
  483                                 break;
  484                 }
  485                 printf("cannot mount root, errno = %d\n", err);
  486                 boothowto |= RB_ASKNAME;
  487         }
  488 
  489         mountlist.cqh_first->mnt_flag |= MNT_ROOTFS;
  490 
  491         /* Get the vnode for '/'.  Set fdp->fd_fd.fd_cdir to reference it. */
  492         if (VFS_ROOT(mountlist.cqh_first, &rootvnode))
  493                 panic("bsd_init: cannot find root vnode");
  494         VREF(rootvnode);
  495         filedesc0.fd_cdir = rootvnode;
  496         VOP_UNLOCK(rootvnode, 0, p);
  497 
  498         if (mountroot == netboot_mountroot) {
  499                 int err;
  500                 /* post mount setup */
  501                 if (err = netboot_setup(p)) {
  502                         panic("bsd_init: NetBoot could not find root, %d", err);
  503                 }
  504         }
  505         
  506 
  507         /*
  508          * Now can look at time, having had a chance to verify the time
  509          * from the file system.  Reset p->p_rtime as it may have been
  510          * munched in mi_switch() after the time got set.
  511          */
  512         p->p_stats->p_start = boottime = time;
  513         p->p_rtime.tv_sec = p->p_rtime.tv_usec = 0;
  514 
  515 #if DEVFS
  516         {
  517             extern void devfs_kernel_mount(char * str);
  518             
  519             devfs_kernel_mount("/dev");
  520         }
  521 #endif /* DEVFS */
  522         
  523         /* Initialize signal state for process 0. */
  524         siginit(p);
  525 
  526         bsd_utaskbootstrap();
  527 
  528         /* invoke post-root-mount hook */
  529         if (mountroot_post_hook != NULL)
  530                 mountroot_post_hook();
  531         
  532         (void) thread_funnel_set(kernel_flock, funnel_state);
  533 }
  534 
  535 /* Called with kernel funnel held */
  536 void
  537 bsdinit_task(void)
  538 {
  539         struct proc *p = current_proc();
  540         struct uthread *ut;
  541         kern_return_t   kr;
  542         thread_act_t th_act;
  543         shared_region_mapping_t system_region;
  544 
  545         proc_name("init", p);
  546 
  547         ux_handler_init();
  548 
  549         th_act = current_act();
  550         (void) host_set_exception_ports(host_priv_self(),
  551                                         EXC_MASK_ALL & ~(EXC_MASK_SYSCALL |
  552                                                          EXC_MASK_MACH_SYSCALL |
  553                                                          EXC_MASK_RPC_ALERT),
  554                                         ux_exception_port,
  555                                         EXCEPTION_DEFAULT, 0);
  556 
  557         (void) task_set_exception_ports(get_threadtask(th_act),
  558                                         EXC_MASK_ALL & ~(EXC_MASK_SYSCALL |
  559                                                          EXC_MASK_MACH_SYSCALL |
  560                                                          EXC_MASK_RPC_ALERT),
  561                                         ux_exception_port,
  562                                         EXCEPTION_DEFAULT, 0);
  563 
  564 
  565 
  566 
  567         ut = (uthread_t)get_bsdthread_info(th_act);
  568         ut->uu_ar0 = (void *)get_user_regs(th_act);
  569 
  570         bsd_hardclockinit = 1;  /* Start bsd hardclock */
  571         bsd_init_task = get_threadtask(th_act);
  572         init_task_failure_data[0] = 0;
  573         system_region = lookup_default_shared_region(ENV_DEFAULT_ROOT,
  574                                 machine_slot[cpu_number()].cpu_type);
  575         if (system_region == NULL) {
  576                 shared_file_boot_time_init(ENV_DEFAULT_ROOT,
  577                                 machine_slot[cpu_number()].cpu_type);
  578         } else {
  579                 vm_set_shared_region(get_threadtask(th_act), system_region);
  580         }
  581         load_init_program(p);
  582         /* turn on app-profiling i.e. pre-heating */
  583         app_profile = 1;
  584 }
  585 
  586 void
  587 lightning_bolt()
  588 {                       
  589         boolean_t       funnel_state;
  590         extern void klogwakeup(void);
  591 
  592         funnel_state = thread_funnel_set(kernel_flock, TRUE);
  593 
  594         thread_wakeup(&lbolt);
  595         timeout(lightning_bolt,0,hz);
  596         klogwakeup();
  597 
  598         (void) thread_funnel_set(kernel_flock, FALSE);
  599 }
  600 
  601 bsd_autoconf()
  602 {
  603         extern kern_return_t IOKitBSDInit( void );
  604 
  605         kminit();
  606 
  607         /* 
  608          * Early startup for bsd pseudodevices.
  609          */
  610         {
  611             struct pseudo_init *pi;
  612         
  613             for (pi = pseudo_inits; pi->ps_func; pi++)
  614                 (*pi->ps_func) (pi->ps_count);
  615         }
  616 
  617         return( IOKitBSDInit());
  618 }
  619 
  620 
  621 #include <sys/disklabel.h>  /* for MAXPARTITIONS */
  622 
  623 setconf()
  624 {       
  625         extern kern_return_t IOFindBSDRoot( char * rootName,
  626                                 dev_t * root, u_int32_t * flags );
  627         u_int32_t       flags;
  628         kern_return_t   err;
  629 
  630         /*
  631          * calls into IOKit can generate networking registrations
  632          * which needs to be under network funnel. Right thing to do
  633          * here is to drop the funnel alltogether and regrab it afterwards
  634          */
  635         thread_funnel_set(kernel_flock, FALSE);
  636         err = IOFindBSDRoot( rootdevice, &rootdev, &flags );
  637         thread_funnel_set(kernel_flock, TRUE);
  638         if( err) {
  639                 printf("setconf: IOFindBSDRoot returned an error (%d);"
  640                         "setting rootdevice to 'sd0a'.\n", err); /* XXX DEBUG TEMP */
  641                 rootdev = makedev( 6, 0 );
  642                 strcpy( rootdevice, "sd0a" );
  643                 flags = 0;
  644         }
  645 
  646         if( flags & 1 ) {
  647                 /* network device */
  648                 mountroot = netboot_mountroot;
  649         } else {
  650                 /* otherwise have vfs determine root filesystem */
  651                 mountroot = NULL;
  652         }
  653 
  654 }
  655 
  656 bsd_utaskbootstrap()
  657 {
  658         thread_act_t th_act;
  659         struct uthread *ut;
  660 
  661         th_act = cloneproc(kernproc, 0);
  662         initproc = pfind(1);                            
  663         /* Set the launch time for init */
  664         initproc->p_stats->p_start = time;
  665 
  666         ut = (struct uthread *)get_bsdthread_info(th_act);
  667         ut->uu_sigmask = 0;
  668         act_set_astbsd(th_act);
  669         (void) thread_resume(th_act);
  670 }
  671 
  672 parse_bsd_args()
  673 {
  674         extern char init_args[];
  675         char    namep[16];
  676         extern int boothowto;
  677         extern int srv;
  678         extern int ncl;
  679 
  680         int len;
  681 
  682         if (PE_parse_boot_arg("-s", namep)) {
  683                 boothowto |= RB_SINGLE;
  684                 len = strlen(init_args);
  685                 if(len != 0)
  686                         strcat(init_args," -s");
  687                 else
  688                         strcat(init_args,"-s");
  689         }
  690 
  691         if (PE_parse_boot_arg("-b", namep)) {
  692                 boothowto |= RB_NOBOOTRC;
  693                 len = strlen(init_args);
  694                 if(len != 0)
  695                         strcat(init_args," -b");
  696                 else
  697                         strcat(init_args,"-b");
  698         }
  699 
  700         if (PE_parse_boot_arg("-F", namep)) {
  701                 len = strlen(init_args);
  702                 if(len != 0)
  703                         strcat(init_args," -F");
  704                 else
  705                         strcat(init_args,"-F");
  706         }
  707 
  708         if (PE_parse_boot_arg("-v", namep)) {
  709                 len = strlen(init_args);
  710                 if(len != 0)
  711                         strcat(init_args," -v");
  712                 else
  713                         strcat(init_args,"-v");
  714         }
  715 
  716         if (PE_parse_boot_arg("-x", namep)) { /* safe boot */
  717                 len = strlen(init_args);
  718                 if(len != 0)
  719                         strcat(init_args," -x");
  720                 else
  721                         strcat(init_args,"-x");
  722         }
  723 
  724         if (PE_parse_boot_arg("-d", namep)) {
  725                 len = strlen(init_args);
  726                 if(len != 0)
  727                         strcat(init_args," -d");
  728                 else
  729                         strcat(init_args,"-d");
  730         }
  731 
  732         PE_parse_boot_arg("srv", &srv);
  733         PE_parse_boot_arg("ncl", &ncl);
  734         PE_parse_boot_arg("nbuf", &nbuf);
  735 
  736         return 0;
  737 }
  738 
  739 boolean_t
  740 thread_funnel_switch(
  741         int     oldfnl,
  742         int     newfnl)
  743 {
  744         boolean_t       funnel_state_prev;
  745         int curfnl;
  746         funnel_t * curflock;
  747         funnel_t * oldflock;
  748         funnel_t * newflock;
  749         funnel_t * exist_funnel;
  750         extern int disable_funnel;
  751        
  752         
  753                 if (disable_funnel)
  754                         return(TRUE);
  755 
  756         if(oldfnl == newfnl) {
  757             panic("thread_funnel_switch: can't switch to same funnel");
  758         }
  759         
  760         if ((oldfnl != NETWORK_FUNNEL) && (oldfnl != KERNEL_FUNNEL)) {
  761             panic("thread_funnel_switch: invalid oldfunnel");
  762         }
  763         if ((newfnl != NETWORK_FUNNEL) && (newfnl != KERNEL_FUNNEL)) {
  764             panic("thread_funnel_switch: invalid newfunnel");
  765         }
  766         
  767         if((curflock = thread_funnel_get()) == THR_FUNNEL_NULL) {
  768             panic("thread_funnel_switch: no funnel held");
  769         }
  770         
  771         if ((oldfnl == NETWORK_FUNNEL) && (curflock != network_flock))
  772             panic("thread_funnel_switch: network funnel not held");
  773             
  774         if ((oldfnl == KERNEL_FUNNEL) && (curflock != kernel_flock))
  775             panic("thread_funnel_switch: kernel funnel not held");
  776 
  777         if(oldfnl == NETWORK_FUNNEL) {
  778             oldflock = network_flock;
  779             newflock = kernel_flock;
  780         } else {
  781             oldflock = kernel_flock;
  782             newflock = network_flock;
  783         }
  784                 KERNEL_DEBUG(0x603242c | DBG_FUNC_NONE, oldflock, 1, 0, 0, 0);
  785         thread_funnel_set(oldflock, FALSE);
  786                 KERNEL_DEBUG(0x6032428 | DBG_FUNC_NONE, newflock, 1, 0, 0, 0);
  787         thread_funnel_set(newflock, TRUE);
  788                 KERNEL_DEBUG(0x6032434 | DBG_FUNC_NONE, newflock, 1, 0, 0, 0);
  789 
  790         return(TRUE);        
  791 }

Cache object: 7e9e013d8fed66cc2e276f1e5f4f592c


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.