* Like kproc_create(), but runs in its own address space. We do this * early to reserve pid 1. Note special case - do not make it * runnable yet, init execution is started when userspace can be served. */
| 789 | * runnable yet, init execution is started when userspace can be served. |
| 790 | */ |
| 791 | static void |
| 792 | create_init(const void *udata __unused) |
| 793 | { |
| 794 | struct fork_req fr; |
| 795 | struct ucred *newcred, *oldcred; |
| 796 | struct thread *td; |
| 797 | int error; |
| 798 | |
| 799 | bzero(&fr, sizeof(fr)); |
| 800 | fr.fr_flags = RFFDG | RFPROC | RFSTOPPED; |
| 801 | fr.fr_procp = &initproc; |
| 802 | error = fork1(&thread0, &fr); |
| 803 | if (error) |
| 804 | panic("cannot fork init: %d\n", error); |
| 805 | KASSERT(initproc->p_pid == 1, ("create_init: initproc->p_pid != 1")); |
| 806 | /* divorce init's credentials from the kernel's */ |
| 807 | newcred = crget(); |
| 808 | sx_xlock(&proctree_lock); |
| 809 | PROC_LOCK(initproc); |
| 810 | initproc->p_flag |= P_SYSTEM | P_INMEM; |
| 811 | initproc->p_treeflag |= P_TREE_REAPER; |
| 812 | oldcred = initproc->p_ucred; |
| 813 | crcopy(newcred, oldcred); |
| 814 | #ifdef MAC |
| 815 | mac_cred_create_init(newcred); |
| 816 | #endif |
| 817 | #ifdef AUDIT |
| 818 | audit_cred_proc1(newcred); |
| 819 | #endif |
| 820 | proc_set_cred(initproc, newcred); |
| 821 | td = FIRST_THREAD_IN_PROC(initproc); |
| 822 | crcowfree(td); |
| 823 | td->td_realucred = crcowget(initproc->p_ucred); |
| 824 | td->td_ucred = td->td_realucred; |
| 825 | PROC_UNLOCK(initproc); |
| 826 | sx_xunlock(&proctree_lock); |
| 827 | crfree(oldcred); |
| 828 | cpu_fork_kthread_handler(FIRST_THREAD_IN_PROC(initproc), |
| 829 | start_init, NULL); |
| 830 | } |
| 831 | SYSINIT(init, SI_SUB_CREATE_INIT, SI_ORDER_FIRST, create_init, NULL); |
| 832 | |
| 833 | /* |
nothing calls this directly
no test coverage detected