Changeset View
Changeset View
Standalone View
Standalone View
sys/kern/init_main.c
Show First 20 Lines • Show All 147 Lines • ▼ Show 20 Lines | |||||
FEATURE(invariants, "Kernel compiled with INVARIANTS, may affect performance"); | FEATURE(invariants, "Kernel compiled with INVARIANTS, may affect performance"); | ||||
#endif | #endif | ||||
/* | /* | ||||
* This ensures that there is at least one entry so that the sysinit_set | * This ensures that there is at least one entry so that the sysinit_set | ||||
* symbol is not undefined. A sybsystem ID of SI_SUB_DUMMY is never | * symbol is not undefined. A sybsystem ID of SI_SUB_DUMMY is never | ||||
* executed. | * executed. | ||||
*/ | */ | ||||
SYSINIT(placeholder, SI_SUB_DUMMY, SI_ORDER_ANY, NULL, NULL); | static void | ||||
placeholder(void) | |||||
{ | |||||
} | |||||
SYSINIT(placeholder, SI_SUB_DUMMY, SI_ORDER_ANY, placeholder); | |||||
/* | /* | ||||
* The sysinit table itself. Items are checked off as the are run. | * The sysinit table itself. Items are checked off as the are run. | ||||
* If we want to register new sysinit types, add them to newsysinit. | * If we want to register new sysinit types, add them to newsysinit. | ||||
*/ | */ | ||||
SET_DECLARE(sysinit_set, struct sysinit); | SET_DECLARE(sysinit_set, struct sysinit); | ||||
struct sysinit **sysinit, **sysinit_end; | struct sysinit **sysinit, **sysinit_end; | ||||
struct sysinit **newsysinit, **newsysinit_end; | struct sysinit **newsysinit, **newsysinit_end; | ||||
▲ Show 20 Lines • Show All 189 Lines • ▼ Show 20 Lines | |||||
static void | static void | ||||
print_caddr_t(void *data) | print_caddr_t(void *data) | ||||
{ | { | ||||
printf("%s", (char *)data); | printf("%s", (char *)data); | ||||
} | } | ||||
static void | static void | ||||
print_version(void *data __unused) | print_version(void) | ||||
{ | { | ||||
int len; | int len; | ||||
/* Strip a trailing newline from version. */ | /* Strip a trailing newline from version. */ | ||||
len = strlen(version); | len = strlen(version); | ||||
while (len > 0 && version[len - 1] == '\n') | while (len > 0 && version[len - 1] == '\n') | ||||
len--; | len--; | ||||
printf("%.*s %s\n", len, version, machine); | printf("%.*s %s\n", len, version, machine); | ||||
printf("%s\n", compiler_version); | printf("%s\n", compiler_version); | ||||
} | } | ||||
SYSINIT(announce, SI_SUB_COPYRIGHT, SI_ORDER_FIRST, print_caddr_t, | SYSINIT(announce, SI_SUB_COPYRIGHT, SI_ORDER_FIRST, print_caddr_t, | ||||
copyright); | copyright); | ||||
SYSINIT(trademark, SI_SUB_COPYRIGHT, SI_ORDER_SECOND, print_caddr_t, | SYSINIT(trademark, SI_SUB_COPYRIGHT, SI_ORDER_SECOND, print_caddr_t, | ||||
trademark); | trademark); | ||||
SYSINIT(version, SI_SUB_COPYRIGHT, SI_ORDER_THIRD, print_version, NULL); | SYSINIT(version, SI_SUB_COPYRIGHT, SI_ORDER_THIRD, print_version); | ||||
#ifdef WITNESS | #ifdef WITNESS | ||||
static char wit_warn[] = | static char wit_warn[] = | ||||
"WARNING: WITNESS option enabled, expect reduced performance.\n"; | "WARNING: WITNESS option enabled, expect reduced performance.\n"; | ||||
SYSINIT(witwarn, SI_SUB_COPYRIGHT, SI_ORDER_FOURTH, | SYSINIT(witwarn, SI_SUB_COPYRIGHT, SI_ORDER_FOURTH, | ||||
print_caddr_t, wit_warn); | print_caddr_t, wit_warn); | ||||
SYSINIT(witwarn2, SI_SUB_LAST, SI_ORDER_FOURTH, | SYSINIT(witwarn2, SI_SUB_LAST, SI_ORDER_FOURTH, | ||||
print_caddr_t, wit_warn); | print_caddr_t, wit_warn); | ||||
▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | |||||
/* | /* | ||||
* The two following SYSINIT's are proc0 specific glue code. I am not | * The two following SYSINIT's are proc0 specific glue code. I am not | ||||
* convinced that they can not be safely combined, but their order of | * convinced that they can not be safely combined, but their order of | ||||
* operation has been maintained as the same as the original init_main.c | * operation has been maintained as the same as the original init_main.c | ||||
* for right now. | * for right now. | ||||
*/ | */ | ||||
/* ARGSUSED*/ | /* ARGSUSED*/ | ||||
static void | static void | ||||
proc0_init(void *dummy __unused) | proc0_init(void) | ||||
{ | { | ||||
struct proc *p; | struct proc *p; | ||||
struct thread *td; | struct thread *td; | ||||
struct ucred *newcred; | struct ucred *newcred; | ||||
struct uidinfo tmpuinfo; | struct uidinfo tmpuinfo; | ||||
struct loginclass tmplc = { | struct loginclass tmplc = { | ||||
.lc_name = "", | .lc_name = "", | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 167 Lines • ▼ Show 20 Lines | #endif | ||||
/* | /* | ||||
* Charge root for one process. | * Charge root for one process. | ||||
*/ | */ | ||||
(void)chgproccnt(p->p_ucred->cr_ruidinfo, 1, 0); | (void)chgproccnt(p->p_ucred->cr_ruidinfo, 1, 0); | ||||
PROC_LOCK(p); | PROC_LOCK(p); | ||||
racct_add_force(p, RACCT_NPROC, 1); | racct_add_force(p, RACCT_NPROC, 1); | ||||
PROC_UNLOCK(p); | PROC_UNLOCK(p); | ||||
} | } | ||||
SYSINIT(p0init, SI_SUB_INTRINSIC, SI_ORDER_FIRST, proc0_init, NULL); | SYSINIT(p0init, SI_SUB_INTRINSIC, SI_ORDER_FIRST, proc0_init); | ||||
/* ARGSUSED*/ | /* ARGSUSED*/ | ||||
static void | static void | ||||
proc0_post(void *dummy __unused) | proc0_post(void) | ||||
{ | { | ||||
struct proc *p; | struct proc *p; | ||||
struct rusage ru; | struct rusage ru; | ||||
struct thread *td; | struct thread *td; | ||||
/* | /* | ||||
* Now we can look at the time, having had a chance to verify the | * Now we can look at the time, having had a chance to verify the | ||||
* time from the filesystem. Pretend that proc0 started now. | * time from the filesystem. Pretend that proc0 started now. | ||||
Show All 17 Lines | FOREACH_THREAD_IN_PROC(p, td) { | ||||
td->td_runtime = 0; | td->td_runtime = 0; | ||||
} | } | ||||
PROC_UNLOCK(p); | PROC_UNLOCK(p); | ||||
} | } | ||||
sx_sunlock(&allproc_lock); | sx_sunlock(&allproc_lock); | ||||
PCPU_SET(switchtime, cpu_ticks()); | PCPU_SET(switchtime, cpu_ticks()); | ||||
PCPU_SET(switchticks, ticks); | PCPU_SET(switchticks, ticks); | ||||
} | } | ||||
SYSINIT(p0post, SI_SUB_INTRINSIC_POST, SI_ORDER_FIRST, proc0_post, NULL); | SYSINIT(p0post, SI_SUB_INTRINSIC_POST, SI_ORDER_FIRST, proc0_post); | ||||
/* | /* | ||||
*************************************************************************** | *************************************************************************** | ||||
**** | **** | ||||
**** The following SYSINIT's and glue code should be moved to the | **** The following SYSINIT's and glue code should be moved to the | ||||
**** respective files on a per subsystem basis. | **** respective files on a per subsystem basis. | ||||
**** | **** | ||||
*************************************************************************** | *************************************************************************** | ||||
▲ Show 20 Lines • Show All 111 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
/* | /* | ||||
* Like kproc_create(), but runs in its own address space. We do this | * 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 | * early to reserve pid 1. Note special case - do not make it | ||||
* runnable yet, init execution is started when userspace can be served. | * runnable yet, init execution is started when userspace can be served. | ||||
*/ | */ | ||||
static void | static void | ||||
create_init(const void *udata __unused) | create_init(void) | ||||
{ | { | ||||
struct fork_req fr; | struct fork_req fr; | ||||
struct ucred *newcred, *oldcred; | struct ucred *newcred, *oldcred; | ||||
struct thread *td; | struct thread *td; | ||||
int error; | int error; | ||||
bzero(&fr, sizeof(fr)); | bzero(&fr, sizeof(fr)); | ||||
fr.fr_flags = RFFDG | RFPROC | RFSTOPPED; | fr.fr_flags = RFFDG | RFPROC | RFSTOPPED; | ||||
Show All 22 Lines | #endif | ||||
td->td_realucred = crcowget(initproc->p_ucred); | td->td_realucred = crcowget(initproc->p_ucred); | ||||
td->td_ucred = td->td_realucred; | td->td_ucred = td->td_realucred; | ||||
PROC_UNLOCK(initproc); | PROC_UNLOCK(initproc); | ||||
sx_xunlock(&proctree_lock); | sx_xunlock(&proctree_lock); | ||||
crfree(oldcred); | crfree(oldcred); | ||||
cpu_fork_kthread_handler(FIRST_THREAD_IN_PROC(initproc), | cpu_fork_kthread_handler(FIRST_THREAD_IN_PROC(initproc), | ||||
start_init, NULL); | start_init, NULL); | ||||
} | } | ||||
SYSINIT(init, SI_SUB_CREATE_INIT, SI_ORDER_FIRST, create_init, NULL); | SYSINIT(init, SI_SUB_CREATE_INIT, SI_ORDER_FIRST, create_init); | ||||
/* | /* | ||||
* Make it runnable now. | * Make it runnable now. | ||||
*/ | */ | ||||
static void | static void | ||||
kick_init(const void *udata __unused) | kick_init(void) | ||||
{ | { | ||||
struct thread *td; | struct thread *td; | ||||
td = FIRST_THREAD_IN_PROC(initproc); | td = FIRST_THREAD_IN_PROC(initproc); | ||||
thread_lock(td); | thread_lock(td); | ||||
TD_SET_CAN_RUN(td); | TD_SET_CAN_RUN(td); | ||||
sched_add(td, SRQ_BORING); | sched_add(td, SRQ_BORING); | ||||
} | } | ||||
SYSINIT(kickinit, SI_SUB_KTHREAD_INIT, SI_ORDER_MIDDLE, kick_init, NULL); | SYSINIT(kickinit, SI_SUB_KTHREAD_INIT, SI_ORDER_MIDDLE, kick_init); | ||||
/* | /* | ||||
* DDB(4). | * DDB(4). | ||||
*/ | */ | ||||
#ifdef DDB | #ifdef DDB | ||||
static void | static void | ||||
db_show_print_syinit(struct sysinit *sip, bool ddb) | db_show_print_syinit(struct sysinit *sip, bool ddb) | ||||
{ | { | ||||
Show All 40 Lines |