MCPcopy Create free account
hub / github.com/F-Stack/f-stack / create_init

Function create_init

freebsd/kern/init_main.c:791–830  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

789 * runnable yet, init execution is started when userspace can be served.
790 */
791static void
792create_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}
831SYSINIT(init, SI_SUB_CREATE_INIT, SI_ORDER_FIRST, create_init, NULL);
832
833/*

Callers

nothing calls this directly

Calls 12

bzeroFunction · 0.85
fork1Function · 0.85
crcopyFunction · 0.85
mac_cred_create_initFunction · 0.85
audit_cred_proc1Function · 0.85
proc_set_credFunction · 0.85
crcowfreeFunction · 0.85
crcowgetFunction · 0.85
panicFunction · 0.70
crgetFunction · 0.70
crfreeFunction · 0.70
cpu_fork_kthread_handlerFunction · 0.50

Tested by

no test coverage detected