init_task.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. extern struct files_struct init_files;
  14. extern struct fs_struct init_fs;
  15. #define INIT_SIGNALS(sig) { \
  16. .nr_threads = 1, \
  17. .wait_chldexit = __WAIT_QUEUE_HEAD_INITIALIZER(sig.wait_chldexit),\
  18. .shared_pending = { \
  19. .list = LIST_HEAD_INIT(sig.shared_pending.list), \
  20. .signal = {{0}}}, \
  21. .posix_timers = LIST_HEAD_INIT(sig.posix_timers), \
  22. .cpu_timers = INIT_CPU_TIMERS(sig.cpu_timers), \
  23. .rlim = INIT_RLIMITS, \
  24. .cputimer = { \
  25. .cputime = INIT_CPUTIME, \
  26. .running = 0, \
  27. .lock = __SPIN_LOCK_UNLOCKED(sig.cputimer.lock), \
  28. }, \
  29. }
  30. extern struct nsproxy init_nsproxy;
  31. #define INIT_SIGHAND(sighand) { \
  32. .count = ATOMIC_INIT(1), \
  33. .action = { { { .sa_handler = SIG_DFL, } }, }, \
  34. .siglock = __SPIN_LOCK_UNLOCKED(sighand.siglock), \
  35. .signalfd_wqh = __WAIT_QUEUE_HEAD_INITIALIZER(sighand.signalfd_wqh), \
  36. }
  37. extern struct group_info init_groups;
  38. #define INIT_STRUCT_PID { \
  39. .count = ATOMIC_INIT(1), \
  40. .tasks = { \
  41. { .first = NULL }, \
  42. { .first = NULL }, \
  43. { .first = NULL }, \
  44. }, \
  45. .level = 0, \
  46. .numbers = { { \
  47. .nr = 0, \
  48. .ns = &init_pid_ns, \
  49. .pid_chain = { .next = NULL, .pprev = NULL }, \
  50. }, } \
  51. }
  52. #define INIT_PID_LINK(type) \
  53. { \
  54. .node = { \
  55. .next = NULL, \
  56. .pprev = NULL, \
  57. }, \
  58. .pid = &init_struct_pid, \
  59. }
  60. #ifdef CONFIG_AUDITSYSCALL
  61. #define INIT_IDS \
  62. .loginuid = -1, \
  63. .sessionid = -1,
  64. #else
  65. #define INIT_IDS
  66. #endif
  67. /*
  68. * Because of the reduced scope of CAP_SETPCAP when filesystem
  69. * capabilities are in effect, it is safe to allow CAP_SETPCAP to
  70. * be available in the default configuration.
  71. */
  72. # define CAP_INIT_BSET CAP_FULL_SET
  73. #ifdef CONFIG_TREE_PREEMPT_RCU
  74. #define INIT_TASK_RCU_TREE_PREEMPT() \
  75. .rcu_blocked_node = NULL,
  76. #else
  77. #define INIT_TASK_RCU_TREE_PREEMPT(tsk)
  78. #endif
  79. #ifdef CONFIG_PREEMPT_RCU
  80. #define INIT_TASK_RCU_PREEMPT(tsk) \
  81. .rcu_read_lock_nesting = 0, \
  82. .rcu_read_unlock_special = 0, \
  83. .rcu_node_entry = LIST_HEAD_INIT(tsk.rcu_node_entry), \
  84. INIT_TASK_RCU_TREE_PREEMPT()
  85. #else
  86. #define INIT_TASK_RCU_PREEMPT(tsk)
  87. #endif
  88. extern struct cred init_cred;
  89. #ifdef CONFIG_PERF_EVENTS
  90. # define INIT_PERF_EVENTS(tsk) \
  91. .perf_event_mutex = \
  92. __MUTEX_INITIALIZER(tsk.perf_event_mutex), \
  93. .perf_event_list = LIST_HEAD_INIT(tsk.perf_event_list),
  94. #else
  95. # define INIT_PERF_EVENTS(tsk)
  96. #endif
  97. /*
  98. * INIT_TASK is used to set up the first task table, touch at
  99. * your own risk!. Base=0, limit=0x1fffff (=2MB)
  100. */
  101. #define INIT_TASK(tsk) \
  102. { \
  103. .state = 0, \
  104. .stack = &init_thread_info, \
  105. .usage = ATOMIC_INIT(2), \
  106. .flags = PF_KTHREAD, \
  107. .lock_depth = -1, \
  108. .prio = MAX_PRIO-20, \
  109. .static_prio = MAX_PRIO-20, \
  110. .normal_prio = MAX_PRIO-20, \
  111. .policy = SCHED_NORMAL, \
  112. .cpus_allowed = CPU_MASK_ALL, \
  113. .mm = NULL, \
  114. .active_mm = &init_mm, \
  115. .se = { \
  116. .group_node = LIST_HEAD_INIT(tsk.se.group_node), \
  117. }, \
  118. .rt = { \
  119. .run_list = LIST_HEAD_INIT(tsk.rt.run_list), \
  120. .time_slice = HZ, \
  121. .nr_cpus_allowed = NR_CPUS, \
  122. }, \
  123. .tasks = LIST_HEAD_INIT(tsk.tasks), \
  124. .pushable_tasks = PLIST_NODE_INIT(tsk.pushable_tasks, MAX_PRIO), \
  125. .ptraced = LIST_HEAD_INIT(tsk.ptraced), \
  126. .ptrace_entry = LIST_HEAD_INIT(tsk.ptrace_entry), \
  127. .real_parent = &tsk, \
  128. .parent = &tsk, \
  129. .children = LIST_HEAD_INIT(tsk.children), \
  130. .sibling = LIST_HEAD_INIT(tsk.sibling), \
  131. .group_leader = &tsk, \
  132. RCU_INIT_POINTER(.real_cred, &init_cred), \
  133. RCU_INIT_POINTER(.cred, &init_cred), \
  134. .cred_guard_mutex = \
  135. __MUTEX_INITIALIZER(tsk.cred_guard_mutex), \
  136. .comm = "swapper", \
  137. .thread = INIT_THREAD, \
  138. .fs = &init_fs, \
  139. .files = &init_files, \
  140. .signal = &init_signals, \
  141. .sighand = &init_sighand, \
  142. .nsproxy = &init_nsproxy, \
  143. .pending = { \
  144. .list = LIST_HEAD_INIT(tsk.pending.list), \
  145. .signal = {{0}}}, \
  146. .blocked = {{0}}, \
  147. .alloc_lock = __SPIN_LOCK_UNLOCKED(tsk.alloc_lock), \
  148. .journal_info = NULL, \
  149. .cpu_timers = INIT_CPU_TIMERS(tsk.cpu_timers), \
  150. .fs_excl = ATOMIC_INIT(0), \
  151. .pi_lock = __RAW_SPIN_LOCK_UNLOCKED(tsk.pi_lock), \
  152. .timer_slack_ns = 50000, /* 50 usec default slack */ \
  153. .pids = { \
  154. [PIDTYPE_PID] = INIT_PID_LINK(PIDTYPE_PID), \
  155. [PIDTYPE_PGID] = INIT_PID_LINK(PIDTYPE_PGID), \
  156. [PIDTYPE_SID] = INIT_PID_LINK(PIDTYPE_SID), \
  157. }, \
  158. .thread_group = LIST_HEAD_INIT(tsk.thread_group), \
  159. .dirties = INIT_PROP_LOCAL_SINGLE(dirties), \
  160. INIT_IDS \
  161. INIT_PERF_EVENTS(tsk) \
  162. INIT_TRACE_IRQFLAGS \
  163. INIT_LOCKDEP \
  164. INIT_FTRACE_GRAPH \
  165. INIT_TRACE_RECURSION \
  166. INIT_TASK_RCU_PREEMPT(tsk) \
  167. }
  168. #define INIT_CPU_TIMERS(cpu_timers) \
  169. { \
  170. LIST_HEAD_INIT(cpu_timers[0]), \
  171. LIST_HEAD_INIT(cpu_timers[1]), \
  172. LIST_HEAD_INIT(cpu_timers[2]), \
  173. }
  174. /* Attach to the init_task data structure for proper alignment */
  175. #define __init_task_data __attribute__((__section__(".data..init_task")))
  176. #endif