Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 #include <linux/init_task.h>
0003 #include <linux/export.h>
0004 #include <linux/mqueue.h>
0005 #include <linux/sched.h>
0006 #include <linux/sched/sysctl.h>
0007 #include <linux/sched/rt.h>
0008 #include <linux/sched/task.h>
0009 #include <linux/init.h>
0010 #include <linux/fs.h>
0011 #include <linux/mm.h>
0012 #include <linux/audit.h>
0013 #include <linux/numa.h>
0014 #include <linux/scs.h>
0015 
0016 #include <linux/uaccess.h>
0017 
0018 static struct signal_struct init_signals = {
0019     .nr_threads = 1,
0020     .thread_head    = LIST_HEAD_INIT(init_task.thread_node),
0021     .wait_chldexit  = __WAIT_QUEUE_HEAD_INITIALIZER(init_signals.wait_chldexit),
0022     .shared_pending = {
0023         .list = LIST_HEAD_INIT(init_signals.shared_pending.list),
0024         .signal =  {{0}}
0025     },
0026     .multiprocess   = HLIST_HEAD_INIT,
0027     .rlim       = INIT_RLIMITS,
0028     .cred_guard_mutex = __MUTEX_INITIALIZER(init_signals.cred_guard_mutex),
0029     .exec_update_lock = __RWSEM_INITIALIZER(init_signals.exec_update_lock),
0030 #ifdef CONFIG_POSIX_TIMERS
0031     .posix_timers = LIST_HEAD_INIT(init_signals.posix_timers),
0032     .cputimer   = {
0033         .cputime_atomic = INIT_CPUTIME_ATOMIC,
0034     },
0035 #endif
0036     INIT_CPU_TIMERS(init_signals)
0037     .pids = {
0038         [PIDTYPE_PID]   = &init_struct_pid,
0039         [PIDTYPE_TGID]  = &init_struct_pid,
0040         [PIDTYPE_PGID]  = &init_struct_pid,
0041         [PIDTYPE_SID]   = &init_struct_pid,
0042     },
0043     INIT_PREV_CPUTIME(init_signals)
0044 };
0045 
0046 static struct sighand_struct init_sighand = {
0047     .count      = REFCOUNT_INIT(1),
0048     .action     = { { { .sa_handler = SIG_DFL, } }, },
0049     .siglock    = __SPIN_LOCK_UNLOCKED(init_sighand.siglock),
0050     .signalfd_wqh   = __WAIT_QUEUE_HEAD_INITIALIZER(init_sighand.signalfd_wqh),
0051 };
0052 
0053 #ifdef CONFIG_SHADOW_CALL_STACK
0054 unsigned long init_shadow_call_stack[SCS_SIZE / sizeof(long)]
0055         __init_task_data = {
0056     [(SCS_SIZE / sizeof(long)) - 1] = SCS_END_MAGIC
0057 };
0058 #endif
0059 
0060 /*
0061  * Set up the first task table, touch at your own risk!. Base=0,
0062  * limit=0x1fffff (=2MB)
0063  */
0064 struct task_struct init_task
0065 #ifdef CONFIG_ARCH_TASK_STRUCT_ON_STACK
0066     __init_task_data
0067 #endif
0068     __aligned(L1_CACHE_BYTES)
0069 = {
0070 #ifdef CONFIG_THREAD_INFO_IN_TASK
0071     .thread_info    = INIT_THREAD_INFO(init_task),
0072     .stack_refcount = REFCOUNT_INIT(1),
0073 #endif
0074     .__state    = 0,
0075     .stack      = init_stack,
0076     .usage      = REFCOUNT_INIT(2),
0077     .flags      = PF_KTHREAD,
0078     .prio       = MAX_PRIO - 20,
0079     .static_prio    = MAX_PRIO - 20,
0080     .normal_prio    = MAX_PRIO - 20,
0081     .policy     = SCHED_NORMAL,
0082     .cpus_ptr   = &init_task.cpus_mask,
0083     .user_cpus_ptr  = NULL,
0084     .cpus_mask  = CPU_MASK_ALL,
0085     .nr_cpus_allowed= NR_CPUS,
0086     .mm     = NULL,
0087     .active_mm  = &init_mm,
0088     .restart_block  = {
0089         .fn = do_no_restart_syscall,
0090     },
0091     .se     = {
0092         .group_node     = LIST_HEAD_INIT(init_task.se.group_node),
0093     },
0094     .rt     = {
0095         .run_list   = LIST_HEAD_INIT(init_task.rt.run_list),
0096         .time_slice = RR_TIMESLICE,
0097     },
0098     .tasks      = LIST_HEAD_INIT(init_task.tasks),
0099 #ifdef CONFIG_SMP
0100     .pushable_tasks = PLIST_NODE_INIT(init_task.pushable_tasks, MAX_PRIO),
0101 #endif
0102 #ifdef CONFIG_CGROUP_SCHED
0103     .sched_task_group = &root_task_group,
0104 #endif
0105     .ptraced    = LIST_HEAD_INIT(init_task.ptraced),
0106     .ptrace_entry   = LIST_HEAD_INIT(init_task.ptrace_entry),
0107     .real_parent    = &init_task,
0108     .parent     = &init_task,
0109     .children   = LIST_HEAD_INIT(init_task.children),
0110     .sibling    = LIST_HEAD_INIT(init_task.sibling),
0111     .group_leader   = &init_task,
0112     RCU_POINTER_INITIALIZER(real_cred, &init_cred),
0113     RCU_POINTER_INITIALIZER(cred, &init_cred),
0114     .comm       = INIT_TASK_COMM,
0115     .thread     = INIT_THREAD,
0116     .fs     = &init_fs,
0117     .files      = &init_files,
0118 #ifdef CONFIG_IO_URING
0119     .io_uring   = NULL,
0120 #endif
0121     .signal     = &init_signals,
0122     .sighand    = &init_sighand,
0123     .nsproxy    = &init_nsproxy,
0124     .pending    = {
0125         .list = LIST_HEAD_INIT(init_task.pending.list),
0126         .signal = {{0}}
0127     },
0128     .blocked    = {{0}},
0129     .alloc_lock = __SPIN_LOCK_UNLOCKED(init_task.alloc_lock),
0130     .journal_info   = NULL,
0131     INIT_CPU_TIMERS(init_task)
0132     .pi_lock    = __RAW_SPIN_LOCK_UNLOCKED(init_task.pi_lock),
0133     .timer_slack_ns = 50000, /* 50 usec default slack */
0134     .thread_pid = &init_struct_pid,
0135     .thread_group   = LIST_HEAD_INIT(init_task.thread_group),
0136     .thread_node    = LIST_HEAD_INIT(init_signals.thread_head),
0137 #ifdef CONFIG_AUDIT
0138     .loginuid   = INVALID_UID,
0139     .sessionid  = AUDIT_SID_UNSET,
0140 #endif
0141 #ifdef CONFIG_PERF_EVENTS
0142     .perf_event_mutex = __MUTEX_INITIALIZER(init_task.perf_event_mutex),
0143     .perf_event_list = LIST_HEAD_INIT(init_task.perf_event_list),
0144 #endif
0145 #ifdef CONFIG_PREEMPT_RCU
0146     .rcu_read_lock_nesting = 0,
0147     .rcu_read_unlock_special.s = 0,
0148     .rcu_node_entry = LIST_HEAD_INIT(init_task.rcu_node_entry),
0149     .rcu_blocked_node = NULL,
0150 #endif
0151 #ifdef CONFIG_TASKS_RCU
0152     .rcu_tasks_holdout = false,
0153     .rcu_tasks_holdout_list = LIST_HEAD_INIT(init_task.rcu_tasks_holdout_list),
0154     .rcu_tasks_idle_cpu = -1,
0155 #endif
0156 #ifdef CONFIG_TASKS_TRACE_RCU
0157     .trc_reader_nesting = 0,
0158     .trc_reader_special.s = 0,
0159     .trc_holdout_list = LIST_HEAD_INIT(init_task.trc_holdout_list),
0160     .trc_blkd_node = LIST_HEAD_INIT(init_task.trc_blkd_node),
0161 #endif
0162 #ifdef CONFIG_CPUSETS
0163     .mems_allowed_seq = SEQCNT_SPINLOCK_ZERO(init_task.mems_allowed_seq,
0164                          &init_task.alloc_lock),
0165 #endif
0166 #ifdef CONFIG_RT_MUTEXES
0167     .pi_waiters = RB_ROOT_CACHED,
0168     .pi_top_task    = NULL,
0169 #endif
0170     INIT_PREV_CPUTIME(init_task)
0171 #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
0172     .vtime.seqcount = SEQCNT_ZERO(init_task.vtime_seqcount),
0173     .vtime.starttime = 0,
0174     .vtime.state    = VTIME_SYS,
0175 #endif
0176 #ifdef CONFIG_NUMA_BALANCING
0177     .numa_preferred_nid = NUMA_NO_NODE,
0178     .numa_group = NULL,
0179     .numa_faults    = NULL,
0180 #endif
0181 #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)
0182     .kasan_depth    = 1,
0183 #endif
0184 #ifdef CONFIG_KCSAN
0185     .kcsan_ctx = {
0186         .scoped_accesses    = {LIST_POISON1, NULL},
0187     },
0188 #endif
0189 #ifdef CONFIG_TRACE_IRQFLAGS
0190     .softirqs_enabled = 1,
0191 #endif
0192 #ifdef CONFIG_LOCKDEP
0193     .lockdep_depth = 0, /* no locks held yet */
0194     .curr_chain_key = INITIAL_CHAIN_KEY,
0195     .lockdep_recursion = 0,
0196 #endif
0197 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
0198     .ret_stack      = NULL,
0199     .tracing_graph_pause    = ATOMIC_INIT(0),
0200 #endif
0201 #if defined(CONFIG_TRACING) && defined(CONFIG_PREEMPTION)
0202     .trace_recursion = 0,
0203 #endif
0204 #ifdef CONFIG_LIVEPATCH
0205     .patch_state    = KLP_UNDEFINED,
0206 #endif
0207 #ifdef CONFIG_SECURITY
0208     .security   = NULL,
0209 #endif
0210 #ifdef CONFIG_SECCOMP_FILTER
0211     .seccomp    = { .filter_count = ATOMIC_INIT(0) },
0212 #endif
0213 };
0214 EXPORT_SYMBOL(init_task);
0215 
0216 /*
0217  * Initial thread structure. Alignment of this is handled by a special
0218  * linker map entry.
0219  */
0220 #ifndef CONFIG_THREAD_INFO_IN_TASK
0221 struct thread_info init_thread_info __init_thread_info = INIT_THREAD_INFO(init_task);
0222 #endif