Deleted Added
full compact
init_main.c (79224) init_main.c (83366)
1/*
2 * Copyright (c) 1995 Terrence R. Lambert
3 * All rights reserved.
4 *
5 * Copyright (c) 1982, 1986, 1989, 1991, 1992, 1993
6 * The Regents of the University of California. All rights reserved.
7 * (c) UNIX System Laboratories, Inc.
8 * All or some portions of this file are derived from material licensed

--- 25 unchanged lines hidden (view full) ---

34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 * SUCH DAMAGE.
40 *
41 * @(#)init_main.c 8.9 (Berkeley) 1/21/94
1/*
2 * Copyright (c) 1995 Terrence R. Lambert
3 * All rights reserved.
4 *
5 * Copyright (c) 1982, 1986, 1989, 1991, 1992, 1993
6 * The Regents of the University of California. All rights reserved.
7 * (c) UNIX System Laboratories, Inc.
8 * All or some portions of this file are derived from material licensed

--- 25 unchanged lines hidden (view full) ---

34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 * SUCH DAMAGE.
40 *
41 * @(#)init_main.c 8.9 (Berkeley) 1/21/94
42 * $FreeBSD: head/sys/kern/init_main.c 79224 2001-07-04 16:20:28Z dillon $
42 * $FreeBSD: head/sys/kern/init_main.c 83366 2001-09-12 08:38:13Z julian $
43 */
44
45#include "opt_init_path.h"
46
47#include <sys/param.h>
48#include <sys/file.h>
49#include <sys/filedesc.h>
50#include <sys/kernel.h>

--- 27 unchanged lines hidden (view full) ---

78#include <sys/copyright.h>
79
80void mi_startup(void); /* Should be elsewhere */
81
82/* Components of the first process -- never freed. */
83static struct session session0;
84static struct pgrp pgrp0;
85struct proc proc0;
43 */
44
45#include "opt_init_path.h"
46
47#include <sys/param.h>
48#include <sys/file.h>
49#include <sys/filedesc.h>
50#include <sys/kernel.h>

--- 27 unchanged lines hidden (view full) ---

78#include <sys/copyright.h>
79
80void mi_startup(void); /* Should be elsewhere */
81
82/* Components of the first process -- never freed. */
83static struct session session0;
84static struct pgrp pgrp0;
85struct proc proc0;
86struct thread *thread0;
86static struct procsig procsig0;
87static struct filedesc0 filedesc0;
88static struct plimit limit0;
89static struct vmspace vmspace0;
90struct proc *initproc;
91
92int cmask = CMASK;
87static struct procsig procsig0;
88static struct filedesc0 filedesc0;
89static struct plimit limit0;
90static struct vmspace vmspace0;
91struct proc *initproc;
92
93int cmask = CMASK;
93extern struct user *proc0paddr;
94extern int fallback_elf_brand;
95
96struct vnode *rootvp;
97int boothowto = 0; /* initialized so that it can be patched */
98SYSCTL_INT(_debug, OID_AUTO, boothowto, CTLFLAG_RD, &boothowto, 0, "");
99int bootverbose;
100SYSCTL_INT(_debug, OID_AUTO, bootverbose, CTLFLAG_RW, &bootverbose, 0, "");
101

--- 166 unchanged lines hidden (view full) ---

268 */
269/* ARGSUSED*/
270static void
271proc0_init(void *dummy __unused)
272{
273 register struct proc *p;
274 register struct filedesc0 *fdp;
275 register unsigned i;
94extern int fallback_elf_brand;
95
96struct vnode *rootvp;
97int boothowto = 0; /* initialized so that it can be patched */
98SYSCTL_INT(_debug, OID_AUTO, boothowto, CTLFLAG_RD, &boothowto, 0, "");
99int bootverbose;
100SYSCTL_INT(_debug, OID_AUTO, bootverbose, CTLFLAG_RW, &bootverbose, 0, "");
101

--- 166 unchanged lines hidden (view full) ---

268 */
269/* ARGSUSED*/
270static void
271proc0_init(void *dummy __unused)
272{
273 register struct proc *p;
274 register struct filedesc0 *fdp;
275 register unsigned i;
276 struct thread *td;
276
277 GIANT_REQUIRED;
277
278 GIANT_REQUIRED;
278
279 /*
280 * This assumes the proc0 struct has already been linked
281 * using proc_linkup() in the machine specific initialisation
282 * e.g. i386_init()
283 */
279 p = &proc0;
284 p = &proc0;
285 td = thread0;
286 mtx_init(&p->p_mtx, "process lock", MTX_DEF);
280
281 /*
282 * Initialize magic number.
283 */
284 p->p_magic = P_MAGIC;
285
286 /*
287 * Initialize process and pgrp structures.

--- 28 unchanged lines hidden (view full) ---

316 p->p_sysent = &elf_freebsd_sysvec;
317#else
318 p->p_sysent = &aout_sysvec;
319#endif
320
321 p->p_flag = P_SYSTEM;
322 p->p_sflag = PS_INMEM;
323 p->p_stat = SRUN;
287
288 /*
289 * Initialize magic number.
290 */
291 p->p_magic = P_MAGIC;
292
293 /*
294 * Initialize process and pgrp structures.

--- 28 unchanged lines hidden (view full) ---

323 p->p_sysent = &elf_freebsd_sysvec;
324#else
325 p->p_sysent = &aout_sysvec;
326#endif
327
328 p->p_flag = P_SYSTEM;
329 p->p_sflag = PS_INMEM;
330 p->p_stat = SRUN;
324 p->p_nice = NZERO;
325 p->p_pri.pri_class = PRI_TIMESHARE;
326 p->p_pri.pri_level = PVM;
327 p->p_pri.pri_native = PUSER;
328 p->p_pri.pri_user = PUSER;
331 p->p_ksegrp.kg_nice = NZERO;
332 p->p_ksegrp.kg_pri.pri_class = PRI_TIMESHARE;
333 p->p_ksegrp.kg_pri.pri_level = PVM;
334 p->p_ksegrp.kg_pri.pri_native = PUSER;
335 p->p_ksegrp.kg_pri.pri_user = PUSER;
329
330 p->p_peers = 0;
331 p->p_leader = p;
332
333 bcopy("swapper", p->p_comm, sizeof ("swapper"));
334
335 callout_init(&p->p_itcallout, 0);
336
337 p->p_peers = 0;
338 p->p_leader = p;
339
340 bcopy("swapper", p->p_comm, sizeof ("swapper"));
341
342 callout_init(&p->p_itcallout, 0);
336 callout_init(&p->p_slpcallout, 1);
343 callout_init(&td->td_slpcallout, 1);
337
338 /* Create credentials. */
339 p->p_ucred = crget();
340 p->p_ucred->cr_ngroups = 1; /* group 0 */
341 p->p_ucred->cr_uidinfo = uifind(0);
342 p->p_ucred->cr_ruidinfo = uifind(0);
343 p->p_ucred->cr_prison = NULL; /* Don't jail it. */
344

--- 31 unchanged lines hidden (view full) ---

376
377 /* Allocate a prototype map so we have something to fork. */
378 pmap_pinit0(vmspace_pmap(&vmspace0));
379 p->p_vmspace = &vmspace0;
380 vmspace0.vm_refcnt = 1;
381 vm_map_init(&vmspace0.vm_map, round_page(VM_MIN_ADDRESS),
382 trunc_page(VM_MAXUSER_ADDRESS));
383 vmspace0.vm_map.pmap = vmspace_pmap(&vmspace0);
344
345 /* Create credentials. */
346 p->p_ucred = crget();
347 p->p_ucred->cr_ngroups = 1; /* group 0 */
348 p->p_ucred->cr_uidinfo = uifind(0);
349 p->p_ucred->cr_ruidinfo = uifind(0);
350 p->p_ucred->cr_prison = NULL; /* Don't jail it. */
351

--- 31 unchanged lines hidden (view full) ---

383
384 /* Allocate a prototype map so we have something to fork. */
385 pmap_pinit0(vmspace_pmap(&vmspace0));
386 p->p_vmspace = &vmspace0;
387 vmspace0.vm_refcnt = 1;
388 vm_map_init(&vmspace0.vm_map, round_page(VM_MIN_ADDRESS),
389 trunc_page(VM_MAXUSER_ADDRESS));
390 vmspace0.vm_map.pmap = vmspace_pmap(&vmspace0);
384 p->p_addr = proc0paddr; /* XXX */
385
386 /*
387 * We continue to place resource usage info and signal
388 * actions in the user struct so they're pageable.
389 */
391
392 /*
393 * We continue to place resource usage info and signal
394 * actions in the user struct so they're pageable.
395 */
390 p->p_stats = &p->p_addr->u_stats;
391 p->p_sigacts = &p->p_addr->u_sigacts;
396 p->p_stats = &p->p_uarea->u_stats;
397 p->p_sigacts = &p->p_uarea->u_sigacts;
392
393 /*
394 * Charge root for one process.
395 */
396 (void)chgproccnt(p->p_ucred->cr_ruidinfo, 1, 0);
397}
398SYSINIT(p0init, SI_SUB_INTRINSIC, SI_ORDER_FIRST, proc0_init, NULL)
399

--- 62 unchanged lines hidden (view full) ---

462static void
463start_init(void *dummy)
464{
465 vm_offset_t addr;
466 struct execve_args args;
467 int options, error;
468 char *var, *path, *next, *s;
469 char *ucp, **uap, *arg0, *arg1;
398
399 /*
400 * Charge root for one process.
401 */
402 (void)chgproccnt(p->p_ucred->cr_ruidinfo, 1, 0);
403}
404SYSINIT(p0init, SI_SUB_INTRINSIC, SI_ORDER_FIRST, proc0_init, NULL)
405

--- 62 unchanged lines hidden (view full) ---

468static void
469start_init(void *dummy)
470{
471 vm_offset_t addr;
472 struct execve_args args;
473 int options, error;
474 char *var, *path, *next, *s;
475 char *ucp, **uap, *arg0, *arg1;
476 struct thread *td;
470 struct proc *p;
471
472 mtx_lock(&Giant);
473
474 GIANT_REQUIRED;
475
477 struct proc *p;
478
479 mtx_lock(&Giant);
480
481 GIANT_REQUIRED;
482
476 p = curproc;
483 td = curthread;
484 p = td->td_proc;
477
478 /* Get the vnode for '/'. Set p->p_fd->fd_cdir to reference it. */
479 if (VFS_ROOT(TAILQ_FIRST(&mountlist), &rootvnode))
480 panic("cannot find root vnode");
481 p->p_fd->fd_cdir = rootvnode;
482 VREF(p->p_fd->fd_cdir);
483 p->p_fd->fd_rdir = rootvnode;
484 VREF(p->p_fd->fd_rdir);
485
486 /* Get the vnode for '/'. Set p->p_fd->fd_cdir to reference it. */
487 if (VFS_ROOT(TAILQ_FIRST(&mountlist), &rootvnode))
488 panic("cannot find root vnode");
489 p->p_fd->fd_cdir = rootvnode;
490 VREF(p->p_fd->fd_cdir);
491 p->p_fd->fd_rdir = rootvnode;
492 VREF(p->p_fd->fd_rdir);
485 VOP_UNLOCK(rootvnode, 0, p);
493 VOP_UNLOCK(rootvnode, 0, td);
486
487 /*
488 * Need just enough stack to hold the faked-up "execve()" arguments.
489 */
490 addr = trunc_page(USRSTACK - PAGE_SIZE);
491 if (vm_map_find(&p->p_vmspace->vm_map, NULL, 0, &addr, PAGE_SIZE,
492 FALSE, VM_PROT_ALL, VM_PROT_ALL, 0) != 0)
493 panic("init: couldn't allocate argument space");

--- 74 unchanged lines hidden (view full) ---

568
569 /*
570 * Now try to exec the program. If can't for any reason
571 * other than it doesn't exist, complain.
572 *
573 * Otherwise, return via fork_trampoline() all the way
574 * to user mode as init!
575 */
494
495 /*
496 * Need just enough stack to hold the faked-up "execve()" arguments.
497 */
498 addr = trunc_page(USRSTACK - PAGE_SIZE);
499 if (vm_map_find(&p->p_vmspace->vm_map, NULL, 0, &addr, PAGE_SIZE,
500 FALSE, VM_PROT_ALL, VM_PROT_ALL, 0) != 0)
501 panic("init: couldn't allocate argument space");

--- 74 unchanged lines hidden (view full) ---

576
577 /*
578 * Now try to exec the program. If can't for any reason
579 * other than it doesn't exist, complain.
580 *
581 * Otherwise, return via fork_trampoline() all the way
582 * to user mode as init!
583 */
576 if ((error = execve(p, &args)) == 0) {
584 if ((error = execve(td, &args)) == 0) {
577 mtx_unlock(&Giant);
578 return;
579 }
580 if (error != ENOENT)
581 printf("exec %.*s: error %d\n", (int)(next - path),
582 path, error);
583 }
584 printf("init: not found in path %s\n", init_path);

--- 7 unchanged lines hidden (view full) ---

592 * Note special case - do not make it runnable yet. Other work
593 * in progress will change this more.
594 */
595static void
596create_init(const void *udata __unused)
597{
598 int error;
599
585 mtx_unlock(&Giant);
586 return;
587 }
588 if (error != ENOENT)
589 printf("exec %.*s: error %d\n", (int)(next - path),
590 path, error);
591 }
592 printf("init: not found in path %s\n", init_path);

--- 7 unchanged lines hidden (view full) ---

600 * Note special case - do not make it runnable yet. Other work
601 * in progress will change this more.
602 */
603static void
604create_init(const void *udata __unused)
605{
606 int error;
607
600 error = fork1(&proc0, RFFDG | RFPROC | RFSTOPPED, &initproc);
608 error = fork1(thread0, RFFDG | RFPROC | RFSTOPPED, &initproc);
601 if (error)
602 panic("cannot fork init: %d\n", error);
603 PROC_LOCK(initproc);
604 initproc->p_flag |= P_SYSTEM;
605 PROC_UNLOCK(initproc);
606 mtx_lock_spin(&sched_lock);
607 initproc->p_sflag |= PS_INMEM;
608 mtx_unlock_spin(&sched_lock);
609 if (error)
610 panic("cannot fork init: %d\n", error);
611 PROC_LOCK(initproc);
612 initproc->p_flag |= P_SYSTEM;
613 PROC_UNLOCK(initproc);
614 mtx_lock_spin(&sched_lock);
615 initproc->p_sflag |= PS_INMEM;
616 mtx_unlock_spin(&sched_lock);
609 cpu_set_fork_handler(initproc, start_init, NULL);
617 cpu_set_fork_handler(&initproc->p_thread, start_init, NULL);
610}
611SYSINIT(init, SI_SUB_CREATE_INIT, SI_ORDER_FIRST, create_init, NULL)
612
613/*
614 * Make it runnable now.
615 */
616static void
617kick_init(const void *udata __unused)
618{
619
620 mtx_lock_spin(&sched_lock);
621 initproc->p_stat = SRUN;
618}
619SYSINIT(init, SI_SUB_CREATE_INIT, SI_ORDER_FIRST, create_init, NULL)
620
621/*
622 * Make it runnable now.
623 */
624static void
625kick_init(const void *udata __unused)
626{
627
628 mtx_lock_spin(&sched_lock);
629 initproc->p_stat = SRUN;
622 setrunqueue(initproc);
630 setrunqueue(&initproc->p_thread); /* XXXKSE */
623 mtx_unlock_spin(&sched_lock);
624}
625SYSINIT(kickinit, SI_SUB_KTHREAD_INIT, SI_ORDER_FIRST, kick_init, NULL)
631 mtx_unlock_spin(&sched_lock);
632}
633SYSINIT(kickinit, SI_SUB_KTHREAD_INIT, SI_ORDER_FIRST, kick_init, NULL)