init_task.h 6.0 KB

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