linux/include/linux/init_task.h
<<
>>
Prefs
   1#ifndef _LINUX__INIT_TASK_H
   2#define _LINUX__INIT_TASK_H
   3
   4#include <linux/rcupdate.h>
   5#include <linux/irqflags.h>
   6#include <linux/utsname.h>
   7#include <linux/lockdep.h>
   8#include <linux/ftrace.h>
   9#include <linux/ipc.h>
  10#include <linux/pid_namespace.h>
  11#include <linux/user_namespace.h>
  12#include <linux/securebits.h>
  13#include <linux/seqlock.h>
  14#include <linux/rbtree.h>
  15#include <net/net_namespace.h>
  16#include <linux/sched/rt.h>
  17
  18#ifdef CONFIG_SMP
  19# define INIT_PUSHABLE_TASKS(tsk)                                       \
  20        .pushable_tasks = PLIST_NODE_INIT(tsk.pushable_tasks, MAX_PRIO),
  21#else
  22# define INIT_PUSHABLE_TASKS(tsk)
  23#endif
  24
  25extern struct files_struct init_files;
  26extern struct fs_struct init_fs;
  27
  28#ifdef CONFIG_CGROUPS
  29#define INIT_GROUP_RWSEM(sig)                                           \
  30        .group_rwsem = __RWSEM_INITIALIZER(sig.group_rwsem),
  31#else
  32#define INIT_GROUP_RWSEM(sig)
  33#endif
  34
  35#ifdef CONFIG_CPUSETS
  36#define INIT_CPUSET_SEQ(tsk)                                                    \
  37        .mems_allowed_seq = SEQCNT_ZERO(tsk.mems_allowed_seq),
  38#else
  39#define INIT_CPUSET_SEQ(tsk)
  40#endif
  41
  42#ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
  43#define INIT_PREV_CPUTIME(x)    .prev_cputime = {                       \
  44        .lock = __RAW_SPIN_LOCK_UNLOCKED(x.prev_cputime.lock),          \
  45},
  46#else
  47#define INIT_PREV_CPUTIME(x)
  48#endif
  49
  50#define INIT_SIGNALS(sig) {                                             \
  51        .nr_threads     = 1,                                            \
  52        .thread_head    = LIST_HEAD_INIT(init_task.thread_node),        \
  53        .wait_chldexit  = __WAIT_QUEUE_HEAD_INITIALIZER(sig.wait_chldexit),\
  54        .shared_pending = {                                             \
  55                .list = LIST_HEAD_INIT(sig.shared_pending.list),        \
  56                .signal =  {{0}}},                                      \
  57        .posix_timers    = LIST_HEAD_INIT(sig.posix_timers),            \
  58        .cpu_timers     = INIT_CPU_TIMERS(sig.cpu_timers),              \
  59        .rlim           = INIT_RLIMITS,                                 \
  60        .cputimer       = {                                             \
  61                .cputime = INIT_CPUTIME,                                \
  62                .running = 0,                                           \
  63                .lock = __RAW_SPIN_LOCK_UNLOCKED(sig.cputimer.lock),    \
  64        },                                                              \
  65        INIT_PREV_CPUTIME(sig)                                          \
  66        .cred_guard_mutex =                                             \
  67                 __MUTEX_INITIALIZER(sig.cred_guard_mutex),             \
  68        INIT_GROUP_RWSEM(sig)                                           \
  69}
  70
  71extern struct nsproxy init_nsproxy;
  72
  73#define INIT_SIGHAND(sighand) {                                         \
  74        .count          = ATOMIC_INIT(1),                               \
  75        .action         = { { { .sa_handler = SIG_DFL, } }, },          \
  76        .siglock        = __SPIN_LOCK_UNLOCKED(sighand.siglock),        \
  77        .signalfd_wqh   = __WAIT_QUEUE_HEAD_INITIALIZER(sighand.signalfd_wqh),  \
  78}
  79
  80extern struct group_info init_groups;
  81
  82#define INIT_STRUCT_PID {                                               \
  83        .count          = ATOMIC_INIT(1),                               \
  84        .tasks          = {                                             \
  85                { .first = NULL },                                      \
  86                { .first = NULL },                                      \
  87                { .first = NULL },                                      \
  88        },                                                              \
  89        .level          = 0,                                            \
  90        .numbers        = { {                                           \
  91                .nr             = 0,                                    \
  92                .ns             = &init_pid_ns,                         \
  93                .pid_chain      = { .next = NULL, .pprev = NULL },      \
  94        }, }                                                            \
  95}
  96
  97#define INIT_PID_LINK(type)                                     \
  98{                                                               \
  99        .node = {                                               \
 100                .next = NULL,                                   \
 101                .pprev = NULL,                                  \
 102        },                                                      \
 103        .pid = &init_struct_pid,                                \
 104}
 105
 106#ifdef CONFIG_AUDITSYSCALL
 107#define INIT_IDS \
 108        .loginuid = INVALID_UID, \
 109        .sessionid = (unsigned int)-1,
 110#else
 111#define INIT_IDS
 112#endif
 113
 114#ifdef CONFIG_RCU_BOOST
 115#define INIT_TASK_RCU_BOOST()                                           \
 116        .rcu_boost_mutex = NULL,
 117#else
 118#define INIT_TASK_RCU_BOOST()
 119#endif
 120#ifdef CONFIG_TREE_PREEMPT_RCU
 121#define INIT_TASK_RCU_TREE_PREEMPT()                                    \
 122        .rcu_blocked_node = NULL,
 123#else
 124#define INIT_TASK_RCU_TREE_PREEMPT(tsk)
 125#endif
 126#ifdef CONFIG_PREEMPT_RCU
 127#define INIT_TASK_RCU_PREEMPT(tsk)                                      \
 128        .rcu_read_lock_nesting = 0,                                     \
 129        .rcu_read_unlock_special = 0,                                   \
 130        .rcu_node_entry = LIST_HEAD_INIT(tsk.rcu_node_entry),           \
 131        INIT_TASK_RCU_TREE_PREEMPT()                                    \
 132        INIT_TASK_RCU_BOOST()
 133#else
 134#define INIT_TASK_RCU_PREEMPT(tsk)
 135#endif
 136
 137extern struct cred init_cred;
 138
 139extern struct task_group root_task_group;
 140
 141#ifdef CONFIG_CGROUP_SCHED
 142# define INIT_CGROUP_SCHED(tsk)                                         \
 143        .sched_task_group = &root_task_group,
 144#else
 145# define INIT_CGROUP_SCHED(tsk)
 146#endif
 147
 148#ifdef CONFIG_PERF_EVENTS
 149# define INIT_PERF_EVENTS(tsk)                                          \
 150        .perf_event_mutex =                                             \
 151                 __MUTEX_INITIALIZER(tsk.perf_event_mutex),             \
 152        .perf_event_list = LIST_HEAD_INIT(tsk.perf_event_list),
 153#else
 154# define INIT_PERF_EVENTS(tsk)
 155#endif
 156
 157#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
 158# define INIT_VTIME(tsk)                                                \
 159        .vtime.seqlock = __SEQLOCK_UNLOCKED(tsk.vtime_seqlock), \
 160        .vtime.starttime = 0,                           \
 161        .vtime.state = VTIME_SYS,
 162#else
 163# define INIT_VTIME(tsk)
 164#endif
 165
 166#define INIT_TASK_COMM "swapper"
 167
 168#ifdef CONFIG_RT_MUTEXES
 169# define INIT_RT_MUTEXES(tsk)                                           \
 170        .pi_waiters = RB_ROOT,                                          \
 171        .pi_waiters_leftmost = NULL,
 172#else
 173# define INIT_RT_MUTEXES(tsk)
 174#endif
 175
 176/*
 177 *  INIT_TASK is used to set up the first task table, touch at
 178 * your own risk!. Base=0, limit=0x1fffff (=2MB)
 179 */
 180#define INIT_TASK(tsk)  \
 181{                                                                       \
 182        .state          = 0,                                            \
 183        .stack          = &init_thread_info,                            \
 184        .usage          = ATOMIC_INIT(2),                               \
 185        .flags          = PF_KTHREAD,                                   \
 186        .prio           = MAX_PRIO-20,                                  \
 187        .static_prio    = MAX_PRIO-20,                                  \
 188        .normal_prio    = MAX_PRIO-20,                                  \
 189        .policy         = SCHED_NORMAL,                                 \
 190        .cpus_allowed   = CPU_MASK_ALL,                                 \
 191        .nr_cpus_allowed= NR_CPUS,                                      \
 192        .mm             = NULL,                                         \
 193        .active_mm      = &init_mm,                                     \
 194        .se             = {                                             \
 195                .group_node     = LIST_HEAD_INIT(tsk.se.group_node),    \
 196        },                                                              \
 197        .rt             = {                                             \
 198                .run_list       = LIST_HEAD_INIT(tsk.rt.run_list),      \
 199                .time_slice     = RR_TIMESLICE,                         \
 200        },                                                              \
 201        .tasks          = LIST_HEAD_INIT(tsk.tasks),                    \
 202        INIT_PUSHABLE_TASKS(tsk)                                        \
 203        INIT_CGROUP_SCHED(tsk)                                          \
 204        .ptraced        = LIST_HEAD_INIT(tsk.ptraced),                  \
 205        .ptrace_entry   = LIST_HEAD_INIT(tsk.ptrace_entry),             \
 206        .real_parent    = &tsk,                                         \
 207        .parent         = &tsk,                                         \
 208        .children       = LIST_HEAD_INIT(tsk.children),                 \
 209        .sibling        = LIST_HEAD_INIT(tsk.sibling),                  \
 210        .group_leader   = &tsk,                                         \
 211        RCU_POINTER_INITIALIZER(real_cred, &init_cred),                 \
 212        RCU_POINTER_INITIALIZER(cred, &init_cred),                      \
 213        .comm           = INIT_TASK_COMM,                               \
 214        .thread         = INIT_THREAD,                                  \
 215        .fs             = &init_fs,                                     \
 216        .files          = &init_files,                                  \
 217        .signal         = &init_signals,                                \
 218        .sighand        = &init_sighand,                                \
 219        .nsproxy        = &init_nsproxy,                                \
 220        .pending        = {                                             \
 221                .list = LIST_HEAD_INIT(tsk.pending.list),               \
 222                .signal = {{0}}},                                       \
 223        .blocked        = {{0}},                                        \
 224        .alloc_lock     = __SPIN_LOCK_UNLOCKED(tsk.alloc_lock),         \
 225        .journal_info   = NULL,                                         \
 226        .cpu_timers     = INIT_CPU_TIMERS(tsk.cpu_timers),              \
 227        .pi_lock        = __RAW_SPIN_LOCK_UNLOCKED(tsk.pi_lock),        \
 228        .timer_slack_ns = 50000, /* 50 usec default slack */            \
 229        .pids = {                                                       \
 230                [PIDTYPE_PID]  = INIT_PID_LINK(PIDTYPE_PID),            \
 231                [PIDTYPE_PGID] = INIT_PID_LINK(PIDTYPE_PGID),           \
 232                [PIDTYPE_SID]  = INIT_PID_LINK(PIDTYPE_SID),            \
 233        },                                                              \
 234        .thread_group   = LIST_HEAD_INIT(tsk.thread_group),             \
 235        .thread_node    = LIST_HEAD_INIT(init_signals.thread_head),     \
 236        INIT_IDS                                                        \
 237        INIT_PERF_EVENTS(tsk)                                           \
 238        INIT_TRACE_IRQFLAGS                                             \
 239        INIT_LOCKDEP                                                    \
 240        INIT_FTRACE_GRAPH                                               \
 241        INIT_TRACE_RECURSION                                            \
 242        INIT_TASK_RCU_PREEMPT(tsk)                                      \
 243        INIT_CPUSET_SEQ(tsk)                                            \
 244        INIT_RT_MUTEXES(tsk)                                            \
 245        INIT_PREV_CPUTIME(tsk)                                          \
 246        INIT_VTIME(tsk)                                                 \
 247}
 248
 249
 250#define INIT_CPU_TIMERS(cpu_timers)                                     \
 251{                                                                       \
 252        LIST_HEAD_INIT(cpu_timers[0]),                                  \
 253        LIST_HEAD_INIT(cpu_timers[1]),                                  \
 254        LIST_HEAD_INIT(cpu_timers[2]),                                  \
 255}
 256
 257/* Attach to the init_task data structure for proper alignment */
 258#define __init_task_data __attribute__((__section__(".data..init_task")))
 259
 260
 261#endif
 262