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 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; |
86struct thread *thread0; |
87static struct procsig procsig0; 88static struct filedesc0 filedesc0; 89static struct plimit limit0; 90static struct vmspace vmspace0; 91struct proc *initproc; 92 93int cmask = CMASK; |
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; |
277 278 GIANT_REQUIRED; |
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 */ |
284 p = &proc0; |
285 td = thread0; 286 mtx_init(&p->p_mtx, "process lock", MTX_DEF); |
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; |
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; |
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); |
343 callout_init(&td->td_slpcallout, 1); |
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); |
391 392 /* 393 * We continue to place resource usage info and signal 394 * actions in the user struct so they're pageable. 395 */ |
396 p->p_stats = &p->p_uarea->u_stats; 397 p->p_sigacts = &p->p_uarea->u_sigacts; |
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; |
477 struct proc *p; 478 479 mtx_lock(&Giant); 480 481 GIANT_REQUIRED; 482 |
483 td = curthread; 484 p = td->td_proc; |
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); |
493 VOP_UNLOCK(rootvnode, 0, td); |
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 */ |
584 if ((error = execve(td, &args)) == 0) { |
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 |
608 error = fork1(thread0, RFFDG | RFPROC | RFSTOPPED, &initproc); |
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); |
617 cpu_set_fork_handler(&initproc->p_thread, start_init, NULL); |
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; |
630 setrunqueue(&initproc->p_thread); /* XXXKSE */ |
631 mtx_unlock_spin(&sched_lock); 632} 633SYSINIT(kickinit, SI_SUB_KTHREAD_INIT, SI_ORDER_FIRST, kick_init, NULL) |