18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci#include <linux/init_task.h>
38c2ecf20Sopenharmony_ci#include <linux/export.h>
48c2ecf20Sopenharmony_ci#include <linux/mqueue.h>
58c2ecf20Sopenharmony_ci#include <linux/sched.h>
68c2ecf20Sopenharmony_ci#include <linux/sched/sysctl.h>
78c2ecf20Sopenharmony_ci#include <linux/sched/rt.h>
88c2ecf20Sopenharmony_ci#include <linux/sched/task.h>
98c2ecf20Sopenharmony_ci#include <linux/init.h>
108c2ecf20Sopenharmony_ci#include <linux/fs.h>
118c2ecf20Sopenharmony_ci#include <linux/mm.h>
128c2ecf20Sopenharmony_ci#include <linux/audit.h>
138c2ecf20Sopenharmony_ci#include <linux/numa.h>
148c2ecf20Sopenharmony_ci#include <linux/scs.h>
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#include <linux/uaccess.h>
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_cistatic struct signal_struct init_signals = {
198c2ecf20Sopenharmony_ci	.nr_threads	= 1,
208c2ecf20Sopenharmony_ci	.thread_head	= LIST_HEAD_INIT(init_task.thread_node),
218c2ecf20Sopenharmony_ci	.wait_chldexit	= __WAIT_QUEUE_HEAD_INITIALIZER(init_signals.wait_chldexit),
228c2ecf20Sopenharmony_ci	.shared_pending	= {
238c2ecf20Sopenharmony_ci		.list = LIST_HEAD_INIT(init_signals.shared_pending.list),
248c2ecf20Sopenharmony_ci		.signal =  {{0}}
258c2ecf20Sopenharmony_ci	},
268c2ecf20Sopenharmony_ci	.multiprocess	= HLIST_HEAD_INIT,
278c2ecf20Sopenharmony_ci	.rlim		= INIT_RLIMITS,
288c2ecf20Sopenharmony_ci	.cred_guard_mutex = __MUTEX_INITIALIZER(init_signals.cred_guard_mutex),
298c2ecf20Sopenharmony_ci	.exec_update_lock = __RWSEM_INITIALIZER(init_signals.exec_update_lock),
308c2ecf20Sopenharmony_ci#ifdef CONFIG_POSIX_TIMERS
318c2ecf20Sopenharmony_ci	.posix_timers = LIST_HEAD_INIT(init_signals.posix_timers),
328c2ecf20Sopenharmony_ci	.cputimer	= {
338c2ecf20Sopenharmony_ci		.cputime_atomic	= INIT_CPUTIME_ATOMIC,
348c2ecf20Sopenharmony_ci	},
358c2ecf20Sopenharmony_ci#endif
368c2ecf20Sopenharmony_ci	INIT_CPU_TIMERS(init_signals)
378c2ecf20Sopenharmony_ci	.pids = {
388c2ecf20Sopenharmony_ci		[PIDTYPE_PID]	= &init_struct_pid,
398c2ecf20Sopenharmony_ci		[PIDTYPE_TGID]	= &init_struct_pid,
408c2ecf20Sopenharmony_ci		[PIDTYPE_PGID]	= &init_struct_pid,
418c2ecf20Sopenharmony_ci		[PIDTYPE_SID]	= &init_struct_pid,
428c2ecf20Sopenharmony_ci	},
438c2ecf20Sopenharmony_ci	INIT_PREV_CPUTIME(init_signals)
448c2ecf20Sopenharmony_ci};
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_cistatic struct sighand_struct init_sighand = {
478c2ecf20Sopenharmony_ci	.count		= REFCOUNT_INIT(1),
488c2ecf20Sopenharmony_ci	.action		= { { { .sa_handler = SIG_DFL, } }, },
498c2ecf20Sopenharmony_ci	.siglock	= __SPIN_LOCK_UNLOCKED(init_sighand.siglock),
508c2ecf20Sopenharmony_ci	.signalfd_wqh	= __WAIT_QUEUE_HEAD_INITIALIZER(init_sighand.signalfd_wqh),
518c2ecf20Sopenharmony_ci};
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci#ifdef CONFIG_SHADOW_CALL_STACK
548c2ecf20Sopenharmony_ciunsigned long init_shadow_call_stack[SCS_SIZE / sizeof(long)]
558c2ecf20Sopenharmony_ci		__init_task_data = {
568c2ecf20Sopenharmony_ci	[(SCS_SIZE / sizeof(long)) - 1] = SCS_END_MAGIC
578c2ecf20Sopenharmony_ci};
588c2ecf20Sopenharmony_ci#endif
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci/*
618c2ecf20Sopenharmony_ci * Set up the first task table, touch at your own risk!. Base=0,
628c2ecf20Sopenharmony_ci * limit=0x1fffff (=2MB)
638c2ecf20Sopenharmony_ci */
648c2ecf20Sopenharmony_cistruct task_struct init_task
658c2ecf20Sopenharmony_ci#ifdef CONFIG_ARCH_TASK_STRUCT_ON_STACK
668c2ecf20Sopenharmony_ci	__init_task_data
678c2ecf20Sopenharmony_ci#endif
688c2ecf20Sopenharmony_ci	__aligned(L1_CACHE_BYTES)
698c2ecf20Sopenharmony_ci= {
708c2ecf20Sopenharmony_ci#ifdef CONFIG_THREAD_INFO_IN_TASK
718c2ecf20Sopenharmony_ci	.thread_info	= INIT_THREAD_INFO(init_task),
728c2ecf20Sopenharmony_ci	.stack_refcount	= REFCOUNT_INIT(1),
738c2ecf20Sopenharmony_ci#endif
748c2ecf20Sopenharmony_ci	.state		= 0,
758c2ecf20Sopenharmony_ci	.stack		= init_stack,
768c2ecf20Sopenharmony_ci	.usage		= REFCOUNT_INIT(2),
778c2ecf20Sopenharmony_ci	.flags		= PF_KTHREAD,
788c2ecf20Sopenharmony_ci	.prio		= MAX_PRIO - 20,
798c2ecf20Sopenharmony_ci	.static_prio	= MAX_PRIO - 20,
808c2ecf20Sopenharmony_ci	.normal_prio	= MAX_PRIO - 20,
818c2ecf20Sopenharmony_ci#ifdef CONFIG_SCHED_LATENCY_NICE
828c2ecf20Sopenharmony_ci	.latency_prio	= NICE_WIDTH - 20,
838c2ecf20Sopenharmony_ci#endif
848c2ecf20Sopenharmony_ci	.policy		= SCHED_NORMAL,
858c2ecf20Sopenharmony_ci	.cpus_ptr	= &init_task.cpus_mask,
868c2ecf20Sopenharmony_ci	.cpus_mask	= CPU_MASK_ALL,
878c2ecf20Sopenharmony_ci	.nr_cpus_allowed= NR_CPUS,
888c2ecf20Sopenharmony_ci	.mm		= NULL,
898c2ecf20Sopenharmony_ci	.active_mm	= &init_mm,
908c2ecf20Sopenharmony_ci	.restart_block	= {
918c2ecf20Sopenharmony_ci		.fn = do_no_restart_syscall,
928c2ecf20Sopenharmony_ci	},
938c2ecf20Sopenharmony_ci	.se		= {
948c2ecf20Sopenharmony_ci		.group_node 	= LIST_HEAD_INIT(init_task.se.group_node),
958c2ecf20Sopenharmony_ci	},
968c2ecf20Sopenharmony_ci	.rt		= {
978c2ecf20Sopenharmony_ci		.run_list	= LIST_HEAD_INIT(init_task.rt.run_list),
988c2ecf20Sopenharmony_ci		.time_slice	= RR_TIMESLICE,
998c2ecf20Sopenharmony_ci	},
1008c2ecf20Sopenharmony_ci	.tasks		= LIST_HEAD_INIT(init_task.tasks),
1018c2ecf20Sopenharmony_ci#ifdef CONFIG_SMP
1028c2ecf20Sopenharmony_ci	.pushable_tasks	= PLIST_NODE_INIT(init_task.pushable_tasks, MAX_PRIO),
1038c2ecf20Sopenharmony_ci#endif
1048c2ecf20Sopenharmony_ci#ifdef CONFIG_CGROUP_SCHED
1058c2ecf20Sopenharmony_ci	.sched_task_group = &root_task_group,
1068c2ecf20Sopenharmony_ci#endif
1078c2ecf20Sopenharmony_ci	.ptraced	= LIST_HEAD_INIT(init_task.ptraced),
1088c2ecf20Sopenharmony_ci	.ptrace_entry	= LIST_HEAD_INIT(init_task.ptrace_entry),
1098c2ecf20Sopenharmony_ci	.real_parent	= &init_task,
1108c2ecf20Sopenharmony_ci	.parent		= &init_task,
1118c2ecf20Sopenharmony_ci	.children	= LIST_HEAD_INIT(init_task.children),
1128c2ecf20Sopenharmony_ci	.sibling	= LIST_HEAD_INIT(init_task.sibling),
1138c2ecf20Sopenharmony_ci	.group_leader	= &init_task,
1148c2ecf20Sopenharmony_ci	RCU_POINTER_INITIALIZER(real_cred, &init_cred),
1158c2ecf20Sopenharmony_ci	RCU_POINTER_INITIALIZER(cred, &init_cred),
1168c2ecf20Sopenharmony_ci	.comm		= INIT_TASK_COMM,
1178c2ecf20Sopenharmony_ci	.thread		= INIT_THREAD,
1188c2ecf20Sopenharmony_ci	.fs		= &init_fs,
1198c2ecf20Sopenharmony_ci	.files		= &init_files,
1208c2ecf20Sopenharmony_ci#ifdef CONFIG_IO_URING
1218c2ecf20Sopenharmony_ci	.io_uring	= NULL,
1228c2ecf20Sopenharmony_ci#endif
1238c2ecf20Sopenharmony_ci	.signal		= &init_signals,
1248c2ecf20Sopenharmony_ci	.sighand	= &init_sighand,
1258c2ecf20Sopenharmony_ci	.nsproxy	= &init_nsproxy,
1268c2ecf20Sopenharmony_ci	.pending	= {
1278c2ecf20Sopenharmony_ci		.list = LIST_HEAD_INIT(init_task.pending.list),
1288c2ecf20Sopenharmony_ci		.signal = {{0}}
1298c2ecf20Sopenharmony_ci	},
1308c2ecf20Sopenharmony_ci	.blocked	= {{0}},
1318c2ecf20Sopenharmony_ci	.alloc_lock	= __SPIN_LOCK_UNLOCKED(init_task.alloc_lock),
1328c2ecf20Sopenharmony_ci	.journal_info	= NULL,
1338c2ecf20Sopenharmony_ci	INIT_CPU_TIMERS(init_task)
1348c2ecf20Sopenharmony_ci	.pi_lock	= __RAW_SPIN_LOCK_UNLOCKED(init_task.pi_lock),
1358c2ecf20Sopenharmony_ci	.timer_slack_ns = 50000, /* 50 usec default slack */
1368c2ecf20Sopenharmony_ci	.thread_pid	= &init_struct_pid,
1378c2ecf20Sopenharmony_ci	.thread_group	= LIST_HEAD_INIT(init_task.thread_group),
1388c2ecf20Sopenharmony_ci	.thread_node	= LIST_HEAD_INIT(init_signals.thread_head),
1398c2ecf20Sopenharmony_ci#ifdef CONFIG_AUDIT
1408c2ecf20Sopenharmony_ci	.loginuid	= INVALID_UID,
1418c2ecf20Sopenharmony_ci	.sessionid	= AUDIT_SID_UNSET,
1428c2ecf20Sopenharmony_ci#endif
1438c2ecf20Sopenharmony_ci#ifdef CONFIG_PERF_EVENTS
1448c2ecf20Sopenharmony_ci	.perf_event_mutex = __MUTEX_INITIALIZER(init_task.perf_event_mutex),
1458c2ecf20Sopenharmony_ci	.perf_event_list = LIST_HEAD_INIT(init_task.perf_event_list),
1468c2ecf20Sopenharmony_ci#endif
1478c2ecf20Sopenharmony_ci#ifdef CONFIG_PREEMPT_RCU
1488c2ecf20Sopenharmony_ci	.rcu_read_lock_nesting = 0,
1498c2ecf20Sopenharmony_ci	.rcu_read_unlock_special.s = 0,
1508c2ecf20Sopenharmony_ci	.rcu_node_entry = LIST_HEAD_INIT(init_task.rcu_node_entry),
1518c2ecf20Sopenharmony_ci	.rcu_blocked_node = NULL,
1528c2ecf20Sopenharmony_ci#endif
1538c2ecf20Sopenharmony_ci#ifdef CONFIG_TASKS_RCU
1548c2ecf20Sopenharmony_ci	.rcu_tasks_holdout = false,
1558c2ecf20Sopenharmony_ci	.rcu_tasks_holdout_list = LIST_HEAD_INIT(init_task.rcu_tasks_holdout_list),
1568c2ecf20Sopenharmony_ci	.rcu_tasks_idle_cpu = -1,
1578c2ecf20Sopenharmony_ci#endif
1588c2ecf20Sopenharmony_ci#ifdef CONFIG_TASKS_TRACE_RCU
1598c2ecf20Sopenharmony_ci	.trc_reader_nesting = 0,
1608c2ecf20Sopenharmony_ci	.trc_reader_special.s = 0,
1618c2ecf20Sopenharmony_ci	.trc_holdout_list = LIST_HEAD_INIT(init_task.trc_holdout_list),
1628c2ecf20Sopenharmony_ci#endif
1638c2ecf20Sopenharmony_ci#ifdef CONFIG_CPUSETS
1648c2ecf20Sopenharmony_ci	.mems_allowed_seq = SEQCNT_SPINLOCK_ZERO(init_task.mems_allowed_seq,
1658c2ecf20Sopenharmony_ci						 &init_task.alloc_lock),
1668c2ecf20Sopenharmony_ci#endif
1678c2ecf20Sopenharmony_ci#ifdef CONFIG_RT_MUTEXES
1688c2ecf20Sopenharmony_ci	.pi_waiters	= RB_ROOT_CACHED,
1698c2ecf20Sopenharmony_ci	.pi_top_task	= NULL,
1708c2ecf20Sopenharmony_ci#endif
1718c2ecf20Sopenharmony_ci	INIT_PREV_CPUTIME(init_task)
1728c2ecf20Sopenharmony_ci#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
1738c2ecf20Sopenharmony_ci	.vtime.seqcount	= SEQCNT_ZERO(init_task.vtime_seqcount),
1748c2ecf20Sopenharmony_ci	.vtime.starttime = 0,
1758c2ecf20Sopenharmony_ci	.vtime.state	= VTIME_SYS,
1768c2ecf20Sopenharmony_ci#endif
1778c2ecf20Sopenharmony_ci#ifdef CONFIG_NUMA_BALANCING
1788c2ecf20Sopenharmony_ci	.numa_preferred_nid = NUMA_NO_NODE,
1798c2ecf20Sopenharmony_ci	.numa_group	= NULL,
1808c2ecf20Sopenharmony_ci	.numa_faults	= NULL,
1818c2ecf20Sopenharmony_ci#endif
1828c2ecf20Sopenharmony_ci#ifdef CONFIG_KASAN
1838c2ecf20Sopenharmony_ci	.kasan_depth	= 1,
1848c2ecf20Sopenharmony_ci#endif
1858c2ecf20Sopenharmony_ci#ifdef CONFIG_KCSAN
1868c2ecf20Sopenharmony_ci	.kcsan_ctx = {
1878c2ecf20Sopenharmony_ci		.disable_count		= 0,
1888c2ecf20Sopenharmony_ci		.atomic_next		= 0,
1898c2ecf20Sopenharmony_ci		.atomic_nest_count	= 0,
1908c2ecf20Sopenharmony_ci		.in_flat_atomic		= false,
1918c2ecf20Sopenharmony_ci		.access_mask		= 0,
1928c2ecf20Sopenharmony_ci		.scoped_accesses	= {LIST_POISON1, NULL},
1938c2ecf20Sopenharmony_ci	},
1948c2ecf20Sopenharmony_ci#endif
1958c2ecf20Sopenharmony_ci#ifdef CONFIG_TRACE_IRQFLAGS
1968c2ecf20Sopenharmony_ci	.softirqs_enabled = 1,
1978c2ecf20Sopenharmony_ci#endif
1988c2ecf20Sopenharmony_ci#ifdef CONFIG_LOCKDEP
1998c2ecf20Sopenharmony_ci	.lockdep_depth = 0, /* no locks held yet */
2008c2ecf20Sopenharmony_ci	.curr_chain_key = INITIAL_CHAIN_KEY,
2018c2ecf20Sopenharmony_ci	.lockdep_recursion = 0,
2028c2ecf20Sopenharmony_ci#endif
2038c2ecf20Sopenharmony_ci#ifdef CONFIG_FUNCTION_GRAPH_TRACER
2048c2ecf20Sopenharmony_ci	.ret_stack		= NULL,
2058c2ecf20Sopenharmony_ci	.tracing_graph_pause	= ATOMIC_INIT(0),
2068c2ecf20Sopenharmony_ci#endif
2078c2ecf20Sopenharmony_ci#if defined(CONFIG_TRACING) && defined(CONFIG_PREEMPTION)
2088c2ecf20Sopenharmony_ci	.trace_recursion = 0,
2098c2ecf20Sopenharmony_ci#endif
2108c2ecf20Sopenharmony_ci#ifdef CONFIG_LIVEPATCH
2118c2ecf20Sopenharmony_ci	.patch_state	= KLP_UNDEFINED,
2128c2ecf20Sopenharmony_ci#endif
2138c2ecf20Sopenharmony_ci#ifdef CONFIG_SECURITY
2148c2ecf20Sopenharmony_ci	.security	= NULL,
2158c2ecf20Sopenharmony_ci#endif
2168c2ecf20Sopenharmony_ci#ifdef CONFIG_SECCOMP_FILTER
2178c2ecf20Sopenharmony_ci	.seccomp	= { .filter_count = ATOMIC_INIT(0) },
2188c2ecf20Sopenharmony_ci#endif
2198c2ecf20Sopenharmony_ci};
2208c2ecf20Sopenharmony_ciEXPORT_SYMBOL(init_task);
2218c2ecf20Sopenharmony_ci
2228c2ecf20Sopenharmony_ci/*
2238c2ecf20Sopenharmony_ci * Initial thread structure. Alignment of this is handled by a special
2248c2ecf20Sopenharmony_ci * linker map entry.
2258c2ecf20Sopenharmony_ci */
2268c2ecf20Sopenharmony_ci#ifndef CONFIG_THREAD_INFO_IN_TASK
2278c2ecf20Sopenharmony_cistruct thread_info init_thread_info __init_thread_info = INIT_THREAD_INFO(init_task);
2288c2ecf20Sopenharmony_ci#endif
229